* tar xzf utvpn-src-unix-v101-7101-public-2010.06.27.tar.gz
authormitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Fri, 15 Jun 2012 04:39:43 +0000 (04:39 +0000)
committermitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Fri, 15 Jun 2012 04:39:43 +0000 (04:39 +0000)
git-svn-id: https://lab.mitty.jp/svn/lab/vendor@146 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

216 files changed:
utvpn/utvpn-unix-v101-7101-public/License-ja.txt [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/UT-VPN_Developers_Guide.pdf [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/UT-VPN_Startup_Guide_for_UNIX.pdf [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/configure [new file with mode: 0755]
utvpn/utvpn-unix-v101-7101-public/makefiles/freebsd_32bit_ja.mak [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/makefiles/freebsd_64bit_ja.mak [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/makefiles/linux_32bit_ja.mak [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/makefiles/linux_64bit_ja.mak [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/makefiles/macos_32bit_ja.mak [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/makefiles/macos_64bit_ja.mak [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/makefiles/solaris_32bit_ja.mak [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/makefiles/solaris_64bit_ja.mak [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Account.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Account.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Admin.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Admin.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Bridge.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Bridge.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/BridgeUnix.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/BridgeUnix.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/BridgeWin32.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/BridgeWin32.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/CM.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/CM.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/CMInner.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Cedar.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Cedar.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/CedarPch.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/CedarPch.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/CedarType.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Client.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Client.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Command.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Command.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Connection.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Connection.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Console.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Console.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Database.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Database.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Hub.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Hub.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Layer3.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Layer3.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Link.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Link.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Listener.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Listener.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Logging.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Logging.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/NM.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/NM.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/NMInner.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Nat.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Nat.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/NullLan.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/NullLan.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Protocol.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Protocol.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Remote.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Remote.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/SM.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/SM.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/SMInner.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Sam.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Sam.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/SecureNAT.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/SecureNAT.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Server.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Server.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Session.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Session.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/TcpIp.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/TcpIp.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/UT.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/UT.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLan.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLan.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLanUnix.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLanUnix.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLanWin32.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLanWin32.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Virtual.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Virtual.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Win32Html.cpp [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/Win32Html.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/WinJumpList.cpp [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/WinUi.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Cedar/WinUi.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Ham/Ham.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Ham/Ham.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Cfg.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Cfg.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Encrypt.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Encrypt.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/FileIO.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/FileIO.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Internat.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Internat.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Kernel.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Kernel.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/MayaType.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Mayaqua.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Mayaqua.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Memory.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Memory.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Microsoft.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Microsoft.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Network.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Network.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/OS.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/OS.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Object.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Object.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Pack.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Pack.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Secure.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Secure.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Str.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Str.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Table.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Table.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Tick64.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Tick64.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Tracking.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Tracking.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/TunTap.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Unix.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Unix.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Win32.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Win32.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/cryptoki.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/aes.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/asn1.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/asn1_mac.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/asn1t.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/bio.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/blowfish.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/bn.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/buffer.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/cast.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/comp.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/conf.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/conf_api.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/crypto.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/des.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/des_old.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/dh.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/dsa.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/dso.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/dtls1.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/e_os2.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ebcdic.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ec.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ecdh.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ecdsa.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/engine.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/err.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/evp.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/fips.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/fips_rand.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/hmac.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/idea.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/krb5_asn.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/kssl.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/lhash.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/md2.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/md4.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/md5.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/mdc2.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/obj_mac.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/objects.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ocsp.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/opensslconf.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/opensslv.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ossl_typ.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pem.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pem2.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pkcs12.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pkcs7.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pq_compat.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pqueue.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rand.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rc2.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rc4.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rc5.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ripemd.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rsa.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/safestack.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/sha.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ssl.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ssl2.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ssl23.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ssl3.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/stack.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/store.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/symhacks.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/tls1.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/tmdiff.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/txt_db.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ui.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ui_compat.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/x509.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/x509_vfy.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/x509v3.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/pkcs11.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/pkcs11f.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/pkcs11t.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/zlib/zconf.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/zlib/zlib.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/Sen/Sen.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/utvpnclient/utvpnclient.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/utvpnclient/utvpnclient.h [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/utvpncmd/utvpncmd.c [new file with mode: 0644]
utvpn/utvpn-unix-v101-7101-public/src/utvpnserver/utvpnserver.c [new file with mode: 0644]

diff --git a/utvpn/utvpn-unix-v101-7101-public/License-ja.txt b/utvpn/utvpn-unix-v101-7101-public/License-ja.txt
new file mode 100644 (file)
index 0000000..3016998
--- /dev/null
@@ -0,0 +1,485 @@
+SoftEther UT-VPN Software\r
+\r
+Copyright (C) 2004-2010 SoftEther Corporation.\r
+Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+Copyright (C) 2003-2010 Daiyuu Nobori.\r
+All Rights Reserved.\r
+http://utvpn.tsukuba.ac.jp/\r
+\r
+This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.\r
+\r
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License version 2 along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+\r
+このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示を除去することはできません。改変した著作物を配布する場合は、改変実施者の著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+\r
+この SoftEther UT-VPN オープンソース・プロジェクトは、日本国のソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ ) および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって ホストされています。\r
+本プログラムの配布者は、本プログラムを、業としての利用以外のため、および、試験または研究のために利用が行われることを想定して配布しています。\r
+SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ にあります。\r
+本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコードの改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出していただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付してください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリースに組み込みさせていただきます。\r
+\r
+GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+\r
+本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社 (SoftEther Corporation) およびその他の著作権保持者が保有しています。ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意ください。\r
+\r
+上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+---\r
+\r
+                    GNU GENERAL PUBLIC LICENSE\r
+                       Version 2, June 1991\r
+\r
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,\r
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r
+ Everyone is permitted to copy and distribute verbatim copies\r
+ of this license document, but changing it is not allowed.\r
+\r
+                            Preamble\r
+\r
+  The licenses for most software are designed to take away your\r
+freedom to share and change it.  By contrast, the GNU General Public\r
+License is intended to guarantee your freedom to share and change free\r
+software--to make sure the software is free for all its users.  This\r
+General Public License applies to most of the Free Software\r
+Foundation's software and to any other program whose authors commit to\r
+using it.  (Some other Free Software Foundation software is covered by\r
+the GNU Lesser General Public License instead.)  You can apply it to\r
+your programs, too.\r
+\r
+  When we speak of free software, we are referring to freedom, not\r
+price.  Our General Public Licenses are designed to make sure that you\r
+have the freedom to distribute copies of free software (and charge for\r
+this service if you wish), that you receive source code or can get it\r
+if you want it, that you can change the software or use pieces of it\r
+in new free programs; and that you know you can do these things.\r
+\r
+  To protect your rights, we need to make restrictions that forbid\r
+anyone to deny you these rights or to ask you to surrender the rights.\r
+These restrictions translate to certain responsibilities for you if you\r
+distribute copies of the software, or if you modify it.\r
+\r
+  For example, if you distribute copies of such a program, whether\r
+gratis or for a fee, you must give the recipients all the rights that\r
+you have.  You must make sure that they, too, receive or can get the\r
+source code.  And you must show them these terms so they know their\r
+rights.\r
+\r
+  We protect your rights with two steps: (1) copyright the software, and\r
+(2) offer you this license which gives you legal permission to copy,\r
+distribute and/or modify the software.\r
+\r
+  Also, for each author's protection and ours, we want to make certain\r
+that everyone understands that there is no warranty for this free\r
+software.  If the software is modified by someone else and passed on, we\r
+want its recipients to know that what they have is not the original, so\r
+that any problems introduced by others will not reflect on the original\r
+authors' reputations.\r
+\r
+  Finally, any free program is threatened constantly by software\r
+patents.  We wish to avoid the danger that redistributors of a free\r
+program will individually obtain patent licenses, in effect making the\r
+program proprietary.  To prevent this, we have made it clear that any\r
+patent must be licensed for everyone's free use or not licensed at all.\r
+\r
+  The precise terms and conditions for copying, distribution and\r
+modification follow.\r
+\r
+                    GNU GENERAL PUBLIC LICENSE\r
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\r
+\r
+  0. This License applies to any program or other work which contains\r
+a notice placed by the copyright holder saying it may be distributed\r
+under the terms of this General Public License.  The "Program", below,\r
+refers to any such program or work, and a "work based on the Program"\r
+means either the Program or any derivative work under copyright law:\r
+that is to say, a work containing the Program or a portion of it,\r
+either verbatim or with modifications and/or translated into another\r
+language.  (Hereinafter, translation is included without limitation in\r
+the term "modification".)  Each licensee is addressed as "you".\r
+\r
+Activities other than copying, distribution and modification are not\r
+covered by this License; they are outside its scope.  The act of\r
+running the Program is not restricted, and the output from the Program\r
+is covered only if its contents constitute a work based on the\r
+Program (independent of having been made by running the Program).\r
+Whether that is true depends on what the Program does.\r
+\r
+  1. You may copy and distribute verbatim copies of the Program's\r
+source code as you receive it, in any medium, provided that you\r
+conspicuously and appropriately publish on each copy an appropriate\r
+copyright notice and disclaimer of warranty; keep intact all the\r
+notices that refer to this License and to the absence of any warranty;\r
+and give any other recipients of the Program a copy of this License\r
+along with the Program.\r
+\r
+You may charge a fee for the physical act of transferring a copy, and\r
+you may at your option offer warranty protection in exchange for a fee.\r
+\r
+  2. You may modify your copy or copies of the Program or any portion\r
+of it, thus forming a work based on the Program, and copy and\r
+distribute such modifications or work under the terms of Section 1\r
+above, provided that you also meet all of these conditions:\r
+\r
+    a) You must cause the modified files to carry prominent notices\r
+    stating that you changed the files and the date of any change.\r
+\r
+    b) You must cause any work that you distribute or publish, that in\r
+    whole or in part contains or is derived from the Program or any\r
+    part thereof, to be licensed as a whole at no charge to all third\r
+    parties under the terms of this License.\r
+\r
+    c) If the modified program normally reads commands interactively\r
+    when run, you must cause it, when started running for such\r
+    interactive use in the most ordinary way, to print or display an\r
+    announcement including an appropriate copyright notice and a\r
+    notice that there is no warranty (or else, saying that you provide\r
+    a warranty) and that users may redistribute the program under\r
+    these conditions, and telling the user how to view a copy of this\r
+    License.  (Exception: if the Program itself is interactive but\r
+    does not normally print such an announcement, your work based on\r
+    the Program is not required to print an announcement.)\r
+\r
+These requirements apply to the modified work as a whole.  If\r
+identifiable sections of that work are not derived from the Program,\r
+and can be reasonably considered independent and separate works in\r
+themselves, then this License, and its terms, do not apply to those\r
+sections when you distribute them as separate works.  But when you\r
+distribute the same sections as part of a whole which is a work based\r
+on the Program, the distribution of the whole must be on the terms of\r
+this License, whose permissions for other licensees extend to the\r
+entire whole, and thus to each and every part regardless of who wrote it.\r
+\r
+Thus, it is not the intent of this section to claim rights or contest\r
+your rights to work written entirely by you; rather, the intent is to\r
+exercise the right to control the distribution of derivative or\r
+collective works based on the Program.\r
+\r
+In addition, mere aggregation of another work not based on the Program\r
+with the Program (or with a work based on the Program) on a volume of\r
+a storage or distribution medium does not bring the other work under\r
+the scope of this License.\r
+\r
+  3. You may copy and distribute the Program (or a work based on it,\r
+under Section 2) in object code or executable form under the terms of\r
+Sections 1 and 2 above provided that you also do one of the following:\r
+\r
+    a) Accompany it with the complete corresponding machine-readable\r
+    source code, which must be distributed under the terms of Sections\r
+    1 and 2 above on a medium customarily used for software interchange; or,\r
+\r
+    b) Accompany it with a written offer, valid for at least three\r
+    years, to give any third party, for a charge no more than your\r
+    cost of physically performing source distribution, a complete\r
+    machine-readable copy of the corresponding source code, to be\r
+    distributed under the terms of Sections 1 and 2 above on a medium\r
+    customarily used for software interchange; or,\r
+\r
+    c) Accompany it with the information you received as to the offer\r
+    to distribute corresponding source code.  (This alternative is\r
+    allowed only for noncommercial distribution and only if you\r
+    received the program in object code or executable form with such\r
+    an offer, in accord with Subsection b above.)\r
+\r
+The source code for a work means the preferred form of the work for\r
+making modifications to it.  For an executable work, complete source\r
+code means all the source code for all modules it contains, plus any\r
+associated interface definition files, plus the scripts used to\r
+control compilation and installation of the executable.  However, as a\r
+special exception, the source code distributed need not include\r
+anything that is normally distributed (in either source or binary\r
+form) with the major components (compiler, kernel, and so on) of the\r
+operating system on which the executable runs, unless that component\r
+itself accompanies the executable.\r
+\r
+If distribution of executable or object code is made by offering\r
+access to copy from a designated place, then offering equivalent\r
+access to copy the source code from the same place counts as\r
+distribution of the source code, even though third parties are not\r
+compelled to copy the source along with the object code.\r
+\r
+  4. You may not copy, modify, sublicense, or distribute the Program\r
+except as expressly provided under this License.  Any attempt\r
+otherwise to copy, modify, sublicense or distribute the Program is\r
+void, and will automatically terminate your rights under this License.\r
+However, parties who have received copies, or rights, from you under\r
+this License will not have their licenses terminated so long as such\r
+parties remain in full compliance.\r
+\r
+  5. You are not required to accept this License, since you have not\r
+signed it.  However, nothing else grants you permission to modify or\r
+distribute the Program or its derivative works.  These actions are\r
+prohibited by law if you do not accept this License.  Therefore, by\r
+modifying or distributing the Program (or any work based on the\r
+Program), you indicate your acceptance of this License to do so, and\r
+all its terms and conditions for copying, distributing or modifying\r
+the Program or works based on it.\r
+\r
+  6. Each time you redistribute the Program (or any work based on the\r
+Program), the recipient automatically receives a license from the\r
+original licensor to copy, distribute or modify the Program subject to\r
+these terms and conditions.  You may not impose any further\r
+restrictions on the recipients' exercise of the rights granted herein.\r
+You are not responsible for enforcing compliance by third parties to\r
+this License.\r
+\r
+  7. If, as a consequence of a court judgment or allegation of patent\r
+infringement or for any other reason (not limited to patent issues),\r
+conditions are imposed on you (whether by court order, agreement or\r
+otherwise) that contradict the conditions of this License, they do not\r
+excuse you from the conditions of this License.  If you cannot\r
+distribute so as to satisfy simultaneously your obligations under this\r
+License and any other pertinent obligations, then as a consequence you\r
+may not distribute the Program at all.  For example, if a patent\r
+license would not permit royalty-free redistribution of the Program by\r
+all those who receive copies directly or indirectly through you, then\r
+the only way you could satisfy both it and this License would be to\r
+refrain entirely from distribution of the Program.\r
+\r
+If any portion of this section is held invalid or unenforceable under\r
+any particular circumstance, the balance of the section is intended to\r
+apply and the section as a whole is intended to apply in other\r
+circumstances.\r
+\r
+It is not the purpose of this section to induce you to infringe any\r
+patents or other property right claims or to contest validity of any\r
+such claims; this section has the sole purpose of protecting the\r
+integrity of the free software distribution system, which is\r
+implemented by public license practices.  Many people have made\r
+generous contributions to the wide range of software distributed\r
+through that system in reliance on consistent application of that\r
+system; it is up to the author/donor to decide if he or she is willing\r
+to distribute software through any other system and a licensee cannot\r
+impose that choice.\r
+\r
+This section is intended to make thoroughly clear what is believed to\r
+be a consequence of the rest of this License.\r
+\r
+  8. If the distribution and/or use of the Program is restricted in\r
+certain countries either by patents or by copyrighted interfaces, the\r
+original copyright holder who places the Program under this License\r
+may add an explicit geographical distribution limitation excluding\r
+those countries, so that distribution is permitted only in or among\r
+countries not thus excluded.  In such case, this License incorporates\r
+the limitation as if written in the body of this License.\r
+\r
+  9. The Free Software Foundation may publish revised and/or new versions\r
+of the General Public License from time to time.  Such new versions will\r
+be similar in spirit to the present version, but may differ in detail to\r
+address new problems or concerns.\r
+\r
+Each version is given a distinguishing version number.  If the Program\r
+specifies a version number of this License which applies to it and "any\r
+later version", you have the option of following the terms and conditions\r
+either of that version or of any later version published by the Free\r
+Software Foundation.  If the Program does not specify a version number of\r
+this License, you may choose any version ever published by the Free Software\r
+Foundation.\r
+\r
+  10. If you wish to incorporate parts of the Program into other free\r
+programs whose distribution conditions are different, write to the author\r
+to ask for permission.  For software which is copyrighted by the Free\r
+Software Foundation, write to the Free Software Foundation; we sometimes\r
+make exceptions for this.  Our decision will be guided by the two goals\r
+of preserving the free status of all derivatives of our free software and\r
+of promoting the sharing and reuse of software generally.\r
+\r
+                            NO WARRANTY\r
+\r
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\r
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\r
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\r
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\r
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\r
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\r
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\r
+REPAIR OR CORRECTION.\r
+\r
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\r
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\r
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\r
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\r
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\r
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\r
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\r
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\r
+POSSIBILITY OF SUCH DAMAGES.\r
+\r
+                     END OF TERMS AND CONDITIONS\r
+\r
+===========================================================================\r
+\r
+* OpenSSL および zlib に関する注意\r
+\r
+SoftEther UT-VPN のすべてのソースコードのうち先頭部分に GPL を適用する旨の宣言が明記されているものには GPL が適用されます。ただし、SoftEther UT-VPN のソースコードと共に openssl ディレクトリ内のファイルが配布されている場合は、そのディレクトリ内に適用されるプログラム (OpenSSL) には OpenSSL のライセンス規定が適用されます。同様に zlib ディレクトリに適用されるプログラム (zlib) には zlib のライセンス規定が適用されます。これら 2 種類のプログラムのライセンス規定には、宣伝条項があるため、GPL が適用できません。\r
+\r
+あなたがもし SoftEther UT-VPN のソースコードに含まれる OpenSSL のソースコードを再配布したい場合、または SoftEther UT-VPN の一部としてリンクされた OpenSSL のバイナリコードを再配布したい場合は、あなたは、OpenSSL のライセンス規定に違反しないようにするために、以下の文字列をプログラムに関連するマテリアルに記載することを推奨します。\r
+\r
+--- (1) ---\r
+\r
+  LICENSE ISSUES\r
+  ==============\r
+\r
+  The OpenSSL toolkit stays under a dual license, i.e. both the conditions of\r
+  the OpenSSL License and the original SSLeay license apply to the toolkit.\r
+  See below for the actual license texts. Actually both licenses are BSD-style\r
+  Open Source licenses. In case of any license issues related to OpenSSL\r
+  please contact openssl-core@openssl.org.\r
+\r
+  OpenSSL License\r
+  ---------------\r
+\r
+/* ====================================================================\r
+ * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+ Original SSLeay License\r
+ -----------------------\r
+\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+-----------\r
+\r
+また、あなたがもし SoftEther UT-VPN のソースコードに含まれる zlib のソースコードを再配布したい場合は、あなたは、zlib のライセンス規定に違反しないようにするために、以下の文字列をソースコード中に記載することを推奨します。\r
+\r
+--- (2) ---\r
+Copyright notice:\r
+\r
+ (C) 1995-2004 Jean-loup Gailly and Mark Adler\r
+\r
+  This software is provided 'as-is', without any express or implied\r
+  warranty.  In no event will the authors be held liable for any damages\r
+  arising from the use of this software.\r
+\r
+  Permission is granted to anyone to use this software for any purpose,\r
+  including commercial applications, and to alter it and redistribute it\r
+  freely, subject to the following restrictions:\r
+\r
+  1. The origin of this software must not be misrepresented; you must not\r
+     claim that you wrote the original software. If you use this software\r
+     in a product, an acknowledgment in the product documentation would be\r
+     appreciated but is not required.\r
+  2. Altered source versions must be plainly marked as such, and must not be\r
+     misrepresented as being the original software.\r
+  3. This notice may not be removed or altered from any source distribution.\r
+\r
+  Jean-loup Gailly        Mark Adler\r
+  jloup@gzip.org          madler@alumni.caltech.edu\r
+-----------\r
+\r
+あなたがもし SoftEther UT-VPN またはその派生物のバイナリコードを OpenSSL を含んだ形で配布または販売する場合は、SoftEther UT-VPN のライセンス規定により、GPL を適用して配布する義務があります。この際は、上記 (1) の文字列と共に配布または販売することを推奨します。そうしなければ、あなたは OpenSSL の著作権者から訴えられる可能性があります。\r
+SoftEther UT-VPN プロジェクトで公式に配布する OpenSSL を含んだバイナリコードは、OpenSSL のライセンス規定を遵守するために、必ず (1) の文字列と共に配布しています。\r
+\r
+\r
+* 商標に関する注意\r
+\r
+SoftEther, PacketiX は日本国やその他の国における SoftEther Corporation の商標です。あなたが SoftEther UT-VPN の派生ソフトウェアやサービスを配布・販売する場合において、SoftEther または PacketiX の名称を使用したい場合は、事前に SoftEther Corporation による書面による許諾が必要です。\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/UT-VPN_Developers_Guide.pdf b/utvpn/utvpn-unix-v101-7101-public/UT-VPN_Developers_Guide.pdf
new file mode 100644 (file)
index 0000000..5792be6
Binary files /dev/null and b/utvpn/utvpn-unix-v101-7101-public/UT-VPN_Developers_Guide.pdf differ
diff --git a/utvpn/utvpn-unix-v101-7101-public/UT-VPN_Startup_Guide_for_UNIX.pdf b/utvpn/utvpn-unix-v101-7101-public/UT-VPN_Startup_Guide_for_UNIX.pdf
new file mode 100644 (file)
index 0000000..6f4e38d
Binary files /dev/null and b/utvpn/utvpn-unix-v101-7101-public/UT-VPN_Startup_Guide_for_UNIX.pdf differ
diff --git a/utvpn/utvpn-unix-v101-7101-public/configure b/utvpn/utvpn-unix-v101-7101-public/configure
new file mode 100755 (executable)
index 0000000..51cd7e2
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+echo '-------------------------------------------------------------'
+echo 'SoftEther UT-VPN for Unix'
+echo
+echo 'Copyright (C) 2004-2010 SoftEther Corporation.'
+echo 'Copyright (C) 2004-2010 University of Tsukuba, Japan.'
+echo 'Copyright (C) 2003-2010 Daiyuu Nobori. All Rights Reserved.'
+echo
+echo 'This program is free software; you can redistribute it and/or'
+echo 'modify it under the terms of the GNU General Public License'
+echo 'version 2 as published by the Free Software Foundation.'
+echo '-------------------------------------------------------------'
+echo
+
+echo 'Please select your Operating System below:'
+echo ' 1: Linux'
+echo ' 2: FreeBSD'
+echo ' 3: Solaris'
+echo ' 4: Mac OS X'
+echo
+echo 'Which is your operating system (1-4): '
+read TMP
+echo
+OS=""
+if test "$TMP" = "1"
+then
+       OS="linux"
+fi
+if test "$TMP" = "2"
+then
+       OS="freebsd"
+fi
+if test "$TMP" = "3"
+then
+       OS="solaris"
+fi
+if test "$TMP" = "4"
+then
+       OS="macos"
+fi
+
+if test "$OS" = ""
+then
+       echo "Wrong number."
+       exit 1
+fi
+
+echo 'Please select your CPU Bits below:'
+echo ' 1: 32-bit'
+echo ' 2: 64-bit'
+echo
+echo 'Which is the bits of your CPU (1-2): '
+read TMP
+echo
+CPU=""
+if test "$TMP" = "1"
+then
+       CPU="32bit"
+fi
+if test "$TMP" = "2"
+then
+       CPU="64bit"
+fi
+
+if test "$CPU" = ""
+then
+       echo "Wrong number."
+       exit 1
+fi
+
+LANGUAGE="ja"
+
+cp makefiles/${OS}_${CPU}_${LANGUAGE}.mak Makefile
+
+echo "Makefile is generated. Please execute 'make' to build UT-VPN."
+
diff --git a/utvpn/utvpn-unix-v101-7101-public/makefiles/freebsd_32bit_ja.mak b/utvpn/utvpn-unix-v101-7101-public/makefiles/freebsd_32bit_ja.mak
new file mode 100644 (file)
index 0000000..ca9cf5b
--- /dev/null
@@ -0,0 +1,353 @@
+# SoftEther UT-VPN SourceCode
+# 
+# Copyright (C) 2004-2010 SoftEther Corporation.
+# Copyright (C) 2004-2010 University of Tsukuba, Japan.
+# Copyright (C) 2003-2010 Daiyuu Nobori.
+# All Rights Reserved.
+# 
+# http://utvpn.tsukuba.ac.jp/
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License version 2
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# 
+# Platform: os=FreeBSD, bits=32bit, language=Japanese
+
+# Variables
+CC=gcc
+
+OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_BSD -DBRIDGE_BPF -DNO_VLAN -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char
+
+OPTIONS_LINK_DEBUG=-g -fsigned-char -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz
+
+OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_BSD -DBRIDGE_BPF -DNO_VLAN -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char
+
+OPTIONS_LINK_RELEASE=-O2 -fsigned-char -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz
+
+INSTALL_BINDIR=/usr/bin/
+INSTALL_UTVPNSERVER_DIR=/usr/utvpnserver/
+INSTALL_UTVPNCLIENT_DIR=/usr/utvpnclient/
+INSTALL_UTVPNCMD_DIR=/usr/utvpncmd/
+
+ifeq ($(DEBUG),YES)
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_DEBUG)
+       OPTIONS_LINK=$(OPTIONS_LINK_DEBUG)
+else
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_RELEASE)
+       OPTIONS_LINK=$(OPTIONS_LINK_RELEASE)
+endif
+
+# Files
+HEADERS_MAYAQUA=src/Mayaqua/Cfg.h src/Mayaqua/cryptoki.h src/Mayaqua/Encrypt.h src/Mayaqua/FileIO.h src/Mayaqua/Internat.h src/Mayaqua/Kernel.h src/Mayaqua/Mayaqua.h src/Mayaqua/MayaType.h src/Mayaqua/Memory.h src/Mayaqua/Microsoft.h src/Mayaqua/Network.h src/Mayaqua/Object.h src/Mayaqua/openssl/aes.h src/Mayaqua/openssl/asn1.h src/Mayaqua/openssl/asn1_mac.h src/Mayaqua/openssl/asn1t.h src/Mayaqua/openssl/bio.h src/Mayaqua/openssl/blowfish.h src/Mayaqua/openssl/bn.h src/Mayaqua/openssl/buffer.h src/Mayaqua/openssl/cast.h src/Mayaqua/openssl/comp.h src/Mayaqua/openssl/conf.h src/Mayaqua/openssl/conf_api.h src/Mayaqua/openssl/crypto.h src/Mayaqua/openssl/des.h src/Mayaqua/openssl/des_old.h src/Mayaqua/openssl/dh.h src/Mayaqua/openssl/dsa.h src/Mayaqua/openssl/dso.h src/Mayaqua/openssl/dtls1.h src/Mayaqua/openssl/e_os2.h src/Mayaqua/openssl/ebcdic.h src/Mayaqua/openssl/ec.h src/Mayaqua/openssl/ecdh.h src/Mayaqua/openssl/ecdsa.h src/Mayaqua/openssl/engine.h src/Mayaqua/openssl/err.h src/Mayaqua/openssl/evp.h src/Mayaqua/openssl/fips.h src/Mayaqua/openssl/fips_rand.h src/Mayaqua/openssl/hmac.h src/Mayaqua/openssl/idea.h src/Mayaqua/openssl/krb5_asn.h src/Mayaqua/openssl/kssl.h src/Mayaqua/openssl/lhash.h src/Mayaqua/openssl/md2.h src/Mayaqua/openssl/md4.h src/Mayaqua/openssl/md5.h src/Mayaqua/openssl/mdc2.h src/Mayaqua/openssl/obj_mac.h src/Mayaqua/openssl/objects.h src/Mayaqua/openssl/ocsp.h src/Mayaqua/openssl/opensslconf.h src/Mayaqua/openssl/opensslv.h src/Mayaqua/openssl/ossl_typ.h src/Mayaqua/openssl/pem.h src/Mayaqua/openssl/pem2.h src/Mayaqua/openssl/pkcs12.h src/Mayaqua/openssl/pkcs7.h src/Mayaqua/openssl/pq_compat.h src/Mayaqua/openssl/pqueue.h src/Mayaqua/openssl/rand.h src/Mayaqua/openssl/rc2.h src/Mayaqua/openssl/rc4.h src/Mayaqua/openssl/rc5.h src/Mayaqua/openssl/ripemd.h src/Mayaqua/openssl/rsa.h src/Mayaqua/openssl/safestack.h src/Mayaqua/openssl/sha.h src/Mayaqua/openssl/ssl.h src/Mayaqua/openssl/ssl2.h src/Mayaqua/openssl/ssl23.h src/Mayaqua/openssl/ssl3.h src/Mayaqua/openssl/stack.h src/Mayaqua/openssl/store.h src/Mayaqua/openssl/symhacks.h src/Mayaqua/openssl/tls1.h src/Mayaqua/openssl/tmdiff.h src/Mayaqua/openssl/txt_db.h src/Mayaqua/openssl/ui.h src/Mayaqua/openssl/ui_compat.h src/Mayaqua/openssl/x509.h src/Mayaqua/openssl/x509_vfy.h src/Mayaqua/openssl/x509v3.h src/Mayaqua/OS.h src/Mayaqua/Pack.h src/Mayaqua/pkcs11.h src/Mayaqua/pkcs11f.h src/Mayaqua/pkcs11t.h src/Mayaqua/Secure.h src/Mayaqua/Str.h src/Mayaqua/Table.h src/Mayaqua/Tick64.h src/Mayaqua/Tracking.h src/Mayaqua/TunTap.h src/Mayaqua/Unix.h src/Mayaqua/Win32.h src/Mayaqua/zlib/zconf.h src/Mayaqua/zlib/zlib.h
+HEADERS_CEDAR=src/Cedar/Account.h src/Cedar/Admin.h src/Cedar/Bridge.h src/Cedar/BridgeUnix.h src/Cedar/BridgeWin32.h src/Cedar/Cedar.h src/Cedar/CedarPch.h src/Cedar/CedarType.h src/Cedar/Client.h src/Cedar/CM.h src/Cedar/CMInner.h src/Cedar/Command.h src/Cedar/Connection.h src/Cedar/Console.h src/Cedar/Database.h src/Cedar/Hub.h src/Cedar/Layer3.h src/Cedar/Link.h src/Cedar/Listener.h src/Cedar/Logging.h src/Cedar/Nat.h src/Cedar/NM.h src/Cedar/NMInner.h src/Cedar/NullLan.h src/Cedar/Protocol.h src/Cedar/Remote.h src/Cedar/Sam.h src/Cedar/SecureNAT.h src/Cedar/Server.h src/Cedar/Session.h src/Cedar/SM.h src/Cedar/SMInner.h src/Cedar/TcpIp.h src/Cedar/UT.h src/Cedar/Virtual.h src/Cedar/VLan.h src/Cedar/VLanUnix.h src/Cedar/VLanWin32.h src/Cedar/Win32Html.h src/Cedar/WinUi.h
+OBJECTS_MAYAQUA=tmp/objs/Mayaqua/Cfg.o tmp/objs/Mayaqua/Encrypt.o tmp/objs/Mayaqua/FileIO.o tmp/objs/Mayaqua/Internat.o tmp/objs/Mayaqua/Kernel.o tmp/objs/Mayaqua/Mayaqua.o tmp/objs/Mayaqua/Memory.o tmp/objs/Mayaqua/Microsoft.o tmp/objs/Mayaqua/Network.o tmp/objs/Mayaqua/Object.o tmp/objs/Mayaqua/OS.o tmp/objs/Mayaqua/Pack.o tmp/objs/Mayaqua/Secure.o tmp/objs/Mayaqua/Str.o tmp/objs/Mayaqua/Table.o tmp/objs/Mayaqua/Tick64.o tmp/objs/Mayaqua/Tracking.o tmp/objs/Mayaqua/Unix.o tmp/objs/Mayaqua/Win32.o
+OBJECTS_CEDAR=tmp/objs/Cedar/Account.o tmp/objs/Cedar/Admin.o tmp/objs/Cedar/Bridge.o tmp/objs/Cedar/BridgeUnix.o tmp/objs/Cedar/BridgeWin32.o tmp/objs/Cedar/Cedar.o tmp/objs/Cedar/CedarPch.o tmp/objs/Cedar/Client.o tmp/objs/Cedar/CM.o tmp/objs/Cedar/Command.o tmp/objs/Cedar/Connection.o tmp/objs/Cedar/Console.o tmp/objs/Cedar/Database.o tmp/objs/Cedar/Hub.o tmp/objs/Cedar/Layer3.o tmp/objs/Cedar/Link.o tmp/objs/Cedar/Listener.o tmp/objs/Cedar/Logging.o tmp/objs/Cedar/Nat.o tmp/objs/Cedar/NM.o tmp/objs/Cedar/NullLan.o tmp/objs/Cedar/Protocol.o tmp/objs/Cedar/Remote.o tmp/objs/Cedar/Sam.o tmp/objs/Cedar/SecureNAT.o tmp/objs/Cedar/Server.o tmp/objs/Cedar/Session.o tmp/objs/Cedar/SM.o tmp/objs/Cedar/TcpIp.o tmp/objs/Cedar/UT.o tmp/objs/Cedar/Virtual.o tmp/objs/Cedar/VLan.o tmp/objs/Cedar/VLanUnix.o tmp/objs/Cedar/VLanWin32.o tmp/objs/Cedar/WinUi.o
+
+# Build Action
+default:       build
+
+build: $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) output/ham/ham output/utvpnserver/utvpnserver output/utvpnclient/utvpnclient output/utvpncmd/utvpncmd
+
+# Mayaqua Kernel Code
+tmp/objs/Mayaqua/Cfg.o: src/Mayaqua/Cfg.c $(HEADERS_MAYAQUA)
+       @mkdir -p tmp/
+       @mkdir -p tmp/objs/
+       @mkdir -p tmp/objs/Mayaqua/
+       @mkdir -p tmp/objs/Cedar/
+       @mkdir -p tmp/as/
+       @mkdir -p output/
+       @mkdir -p output/ham/
+       @mkdir -p output/utvpnserver/
+       @mkdir -p output/utvpnclient/
+       @mkdir -p output/utvpncmd/
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Cfg.c -o tmp/objs/Mayaqua/Cfg.o
+
+tmp/objs/Mayaqua/Encrypt.o: src/Mayaqua/Encrypt.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Encrypt.c -o tmp/objs/Mayaqua/Encrypt.o
+
+tmp/objs/Mayaqua/FileIO.o: src/Mayaqua/FileIO.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/FileIO.c -o tmp/objs/Mayaqua/FileIO.o
+
+tmp/objs/Mayaqua/Internat.o: src/Mayaqua/Internat.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Internat.c -o tmp/objs/Mayaqua/Internat.o
+
+tmp/objs/Mayaqua/Kernel.o: src/Mayaqua/Kernel.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Kernel.c -o tmp/objs/Mayaqua/Kernel.o
+
+tmp/objs/Mayaqua/Mayaqua.o: src/Mayaqua/Mayaqua.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Mayaqua.c -o tmp/objs/Mayaqua/Mayaqua.o
+
+tmp/objs/Mayaqua/Memory.o: src/Mayaqua/Memory.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Memory.c -o tmp/objs/Mayaqua/Memory.o
+
+tmp/objs/Mayaqua/Microsoft.o: src/Mayaqua/Microsoft.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Microsoft.c -o tmp/objs/Mayaqua/Microsoft.o
+
+tmp/objs/Mayaqua/Network.o: src/Mayaqua/Network.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Network.c -o tmp/objs/Mayaqua/Network.o
+
+tmp/objs/Mayaqua/Object.o: src/Mayaqua/Object.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Object.c -o tmp/objs/Mayaqua/Object.o
+
+tmp/objs/Mayaqua/OS.o: src/Mayaqua/OS.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/OS.c -o tmp/objs/Mayaqua/OS.o
+
+tmp/objs/Mayaqua/Pack.o: src/Mayaqua/Pack.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Pack.c -o tmp/objs/Mayaqua/Pack.o
+
+tmp/objs/Mayaqua/Secure.o: src/Mayaqua/Secure.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Secure.c -o tmp/objs/Mayaqua/Secure.o
+
+tmp/objs/Mayaqua/Str.o: src/Mayaqua/Str.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Str.c -o tmp/objs/Mayaqua/Str.o
+
+tmp/objs/Mayaqua/Table.o: src/Mayaqua/Table.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Table.c -o tmp/objs/Mayaqua/Table.o
+
+tmp/objs/Mayaqua/Tick64.o: src/Mayaqua/Tick64.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tick64.c -o tmp/objs/Mayaqua/Tick64.o
+
+tmp/objs/Mayaqua/Tracking.o: src/Mayaqua/Tracking.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tracking.c -o tmp/objs/Mayaqua/Tracking.o
+
+tmp/objs/Mayaqua/Unix.o: src/Mayaqua/Unix.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Unix.c -o tmp/objs/Mayaqua/Unix.o
+
+tmp/objs/Mayaqua/Win32.o: src/Mayaqua/Win32.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Win32.c -o tmp/objs/Mayaqua/Win32.o
+
+# Cedar Communication Module Code
+tmp/objs/Cedar/Account.o: src/Cedar/Account.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Account.c -o tmp/objs/Cedar/Account.o
+
+tmp/objs/Cedar/Admin.o: src/Cedar/Admin.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Admin.c -o tmp/objs/Cedar/Admin.o
+
+tmp/objs/Cedar/Bridge.o: src/Cedar/Bridge.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) src/Cedar/BridgeUnix.c
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Bridge.c -o tmp/objs/Cedar/Bridge.o
+
+tmp/objs/Cedar/BridgeUnix.o: src/Cedar/BridgeUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeUnix.c -o tmp/objs/Cedar/BridgeUnix.o
+
+tmp/objs/Cedar/BridgeWin32.o: src/Cedar/BridgeWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeWin32.c -o tmp/objs/Cedar/BridgeWin32.o
+
+tmp/objs/Cedar/Cedar.o: src/Cedar/Cedar.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Cedar.c -o tmp/objs/Cedar/Cedar.o
+
+tmp/objs/Cedar/CedarPch.o: src/Cedar/CedarPch.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CedarPch.c -o tmp/objs/Cedar/CedarPch.o
+
+tmp/objs/Cedar/Client.o: src/Cedar/Client.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Client.c -o tmp/objs/Cedar/Client.o
+
+tmp/objs/Cedar/CM.o: src/Cedar/CM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CM.c -o tmp/objs/Cedar/CM.o
+
+tmp/objs/Cedar/Command.o: src/Cedar/Command.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Command.c -o tmp/objs/Cedar/Command.o
+
+tmp/objs/Cedar/Connection.o: src/Cedar/Connection.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Connection.c -o tmp/objs/Cedar/Connection.o
+
+tmp/objs/Cedar/Console.o: src/Cedar/Console.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Console.c -o tmp/objs/Cedar/Console.o
+
+tmp/objs/Cedar/Database.o: src/Cedar/Database.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Database.c -o tmp/objs/Cedar/Database.o
+
+tmp/objs/Cedar/Hub.o: src/Cedar/Hub.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Hub.c -o tmp/objs/Cedar/Hub.o
+
+tmp/objs/Cedar/Layer3.o: src/Cedar/Layer3.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Layer3.c -o tmp/objs/Cedar/Layer3.o
+
+tmp/objs/Cedar/Link.o: src/Cedar/Link.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Link.c -o tmp/objs/Cedar/Link.o
+
+tmp/objs/Cedar/Listener.o: src/Cedar/Listener.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Listener.c -o tmp/objs/Cedar/Listener.o
+
+tmp/objs/Cedar/Logging.o: src/Cedar/Logging.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Logging.c -o tmp/objs/Cedar/Logging.o
+
+tmp/objs/Cedar/Nat.o: src/Cedar/Nat.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Nat.c -o tmp/objs/Cedar/Nat.o
+
+tmp/objs/Cedar/NM.o: src/Cedar/NM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NM.c -o tmp/objs/Cedar/NM.o
+
+tmp/objs/Cedar/NullLan.o: src/Cedar/NullLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NullLan.c -o tmp/objs/Cedar/NullLan.o
+
+tmp/objs/Cedar/Protocol.o: src/Cedar/Protocol.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Protocol.c -o tmp/objs/Cedar/Protocol.o
+
+tmp/objs/Cedar/Remote.o: src/Cedar/Remote.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Remote.c -o tmp/objs/Cedar/Remote.o
+
+tmp/objs/Cedar/Sam.o: src/Cedar/Sam.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Sam.c -o tmp/objs/Cedar/Sam.o
+
+tmp/objs/Cedar/SecureNAT.o: src/Cedar/SecureNAT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SecureNAT.c -o tmp/objs/Cedar/SecureNAT.o
+
+tmp/objs/Cedar/Server.o: src/Cedar/Server.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Server.c -o tmp/objs/Cedar/Server.o
+
+tmp/objs/Cedar/Session.o: src/Cedar/Session.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Session.c -o tmp/objs/Cedar/Session.o
+
+tmp/objs/Cedar/SM.o: src/Cedar/SM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SM.c -o tmp/objs/Cedar/SM.o
+
+tmp/objs/Cedar/TcpIp.o: src/Cedar/TcpIp.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/TcpIp.c -o tmp/objs/Cedar/TcpIp.o
+
+tmp/objs/Cedar/UT.o: src/Cedar/UT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/UT.c -o tmp/objs/Cedar/UT.o
+
+tmp/objs/Cedar/Virtual.o: src/Cedar/Virtual.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Virtual.c -o tmp/objs/Cedar/Virtual.o
+
+tmp/objs/Cedar/VLan.o: src/Cedar/VLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLan.c -o tmp/objs/Cedar/VLan.o
+
+tmp/objs/Cedar/VLanUnix.o: src/Cedar/VLanUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanUnix.c -o tmp/objs/Cedar/VLanUnix.o
+
+tmp/objs/Cedar/VLanWin32.o: src/Cedar/VLanWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanWin32.c -o tmp/objs/Cedar/VLanWin32.o
+
+tmp/objs/Cedar/WinUi.o: src/Cedar/WinUi.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/WinUi.c -o tmp/objs/Cedar/WinUi.o
+
+# Ham
+output/ham/ham: tmp/as/Ham.a output/ham/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/Ham.a $(OPTIONS_LINK) -o output/ham/ham
+
+tmp/as/Ham.a: tmp/objs/Ham.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/Ham.a
+       ar r tmp/as/Ham.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/Ham.o
+       ranlib tmp/as/Ham.a
+
+output/ham/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/ham/hamcore.utvpn
+
+tmp/objs/Ham.o: src/Ham/Ham.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Ham/Ham.c -o tmp/objs/Ham.o
+
+# utvpnserver
+output/utvpnserver/utvpnserver: tmp/as/utvpnserver.a output/utvpnserver/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnserver.a $(OPTIONS_LINK) -o output/utvpnserver/utvpnserver
+
+tmp/as/utvpnserver.a: tmp/objs/utvpnserver.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnserver.a
+       ar r tmp/as/utvpnserver.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnserver.o
+       ranlib tmp/as/utvpnserver.a
+
+output/utvpnserver/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnserver/hamcore.utvpn
+
+tmp/objs/utvpnserver.o: src/utvpnserver/utvpnserver.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnserver/utvpnserver.c -o tmp/objs/utvpnserver.o
+
+# utvpnclient
+output/utvpnclient/utvpnclient: tmp/as/utvpnclient.a output/utvpnclient/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnclient.a $(OPTIONS_LINK) -o output/utvpnclient/utvpnclient
+
+tmp/as/utvpnclient.a: tmp/objs/utvpnclient.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnclient.a
+       ar r tmp/as/utvpnclient.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnclient.o
+       ranlib tmp/as/utvpnclient.a
+
+output/utvpnclient/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnclient/hamcore.utvpn
+
+tmp/objs/utvpnclient.o: src/utvpnclient/utvpnclient.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnclient/utvpnclient.c -o tmp/objs/utvpnclient.o
+
+# utvpncmd
+output/utvpncmd/utvpncmd: tmp/as/utvpncmd.a output/utvpncmd/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpncmd.a $(OPTIONS_LINK) -o output/utvpncmd/utvpncmd
+
+tmp/as/utvpncmd.a: tmp/objs/utvpncmd.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpncmd.a
+       ar r tmp/as/utvpncmd.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpncmd.o
+       ranlib tmp/as/utvpncmd.a
+
+output/utvpncmd/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpncmd/hamcore.utvpn
+
+tmp/objs/utvpncmd.o: src/utvpncmd/utvpncmd.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpncmd/utvpncmd.c -o tmp/objs/utvpncmd.o
+
+# Install
+install: $(INSTALL_BINDIR)utvpnserver $(INSTALL_BINDIR)utvpnclient $(INSTALL_BINDIR)utvpncmd
+       @echo
+       @echo "--------------------------------------------------------------------"
+       @echo "Installation completed successfully."
+       @echo
+       @echo "Please execute 'utvpnserver start' to run UT-VPN Server Background Service."
+       @echo "Or please execute 'utvpnclient start' to run UT-VPN Client Background Service."
+       @echo "And please execute 'utvpncmd' to run UT-VPN Command-Line Utility to configure UT-Server or UT-VPN Client."
+       @echo "--------------------------------------------------------------------"
+       @echo
+
+$(INSTALL_BINDIR)utvpnserver: output/utvpnserver/hamcore.utvpn output/utvpnserver/utvpnserver
+       @mkdir -p $(INSTALL_UTVPNSERVER_DIR)
+       cp output/utvpnserver/hamcore.utvpn $(INSTALL_UTVPNSERVER_DIR)hamcore.utvpn
+       cp output/utvpnserver/utvpnserver $(INSTALL_UTVPNSERVER_DIR)utvpnserver
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnserver
+       echo $(INSTALL_UTVPNSERVER_DIR)utvpnserver '"$$@"' >> $(INSTALL_BINDIR)utvpnserver
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnserver
+       chmod 755 $(INSTALL_BINDIR)utvpnserver
+
+$(INSTALL_BINDIR)utvpnclient: output/utvpnclient/hamcore.utvpn output/utvpnclient/utvpnclient
+       @mkdir -p $(INSTALL_UTVPNCLIENT_DIR)
+       cp output/utvpnclient/hamcore.utvpn $(INSTALL_UTVPNCLIENT_DIR)hamcore.utvpn
+       cp output/utvpnclient/utvpnclient $(INSTALL_UTVPNCLIENT_DIR)utvpnclient
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnclient
+       echo $(INSTALL_UTVPNCLIENT_DIR)utvpnclient '"$$@"' >> $(INSTALL_BINDIR)utvpnclient
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnclient
+       chmod 755 $(INSTALL_BINDIR)utvpnclient
+
+$(INSTALL_BINDIR)utvpncmd: output/utvpncmd/hamcore.utvpn output/utvpncmd/utvpncmd
+       @mkdir -p $(INSTALL_UTVPNCMD_DIR)
+       cp output/utvpncmd/hamcore.utvpn $(INSTALL_UTVPNCMD_DIR)hamcore.utvpn
+       cp output/utvpncmd/utvpncmd $(INSTALL_UTVPNCMD_DIR)utvpncmd
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpncmd
+       echo $(INSTALL_UTVPNCMD_DIR)utvpncmd '"$$@"' >> $(INSTALL_BINDIR)utvpncmd
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpncmd
+       chmod 755 $(INSTALL_BINDIR)utvpncmd
+
+# Clean
+clean:
+       -rm -f $(OBJECTS_MAYAQUA)
+       -rm -f $(OBJECTS_CEDAR)
+       -rm -f tmp/objs/Ham.o
+       -rm -f tmp/as/Ham.a
+       -rm -f output/ham/ham
+       -rm -f tmp/objs/utvpnserver.o
+       -rm -f tmp/as/utvpnserver.a
+       -rm -f output/utvpnserver/utvpnserver
+       -rm -f tmp/objs/utvpnclient.o
+       -rm -f tmp/as/utvpnclient.a
+       -rm -f output/utvpnclient/utvpnclient
+       -rm -f tmp/objs/utvpncmd.o
+       -rm -f tmp/as/utvpncmd.a
+       -rm -f output/utvpncmd/utvpncmd
+
+# Help Strings
+help:
+       @echo "make [DEBUG=YES]"
+
diff --git a/utvpn/utvpn-unix-v101-7101-public/makefiles/freebsd_64bit_ja.mak b/utvpn/utvpn-unix-v101-7101-public/makefiles/freebsd_64bit_ja.mak
new file mode 100644 (file)
index 0000000..8f685f3
--- /dev/null
@@ -0,0 +1,353 @@
+# SoftEther UT-VPN SourceCode
+# 
+# Copyright (C) 2004-2010 SoftEther Corporation.
+# Copyright (C) 2004-2010 University of Tsukuba, Japan.
+# Copyright (C) 2003-2010 Daiyuu Nobori.
+# All Rights Reserved.
+# 
+# http://utvpn.tsukuba.ac.jp/
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License version 2
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# 
+# Platform: os=FreeBSD, bits=64bit, language=Japanese
+
+# Variables
+CC=gcc
+
+OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_BSD -DBRIDGE_BPF -DNO_VLAN -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char -m64
+
+OPTIONS_LINK_DEBUG=-g -fsigned-char -m64 -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz
+
+OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_BSD -DBRIDGE_BPF -DNO_VLAN -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char -m64
+
+OPTIONS_LINK_RELEASE=-O2 -fsigned-char -m64 -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz
+
+INSTALL_BINDIR=/usr/bin/
+INSTALL_UTVPNSERVER_DIR=/usr/utvpnserver/
+INSTALL_UTVPNCLIENT_DIR=/usr/utvpnclient/
+INSTALL_UTVPNCMD_DIR=/usr/utvpncmd/
+
+ifeq ($(DEBUG),YES)
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_DEBUG)
+       OPTIONS_LINK=$(OPTIONS_LINK_DEBUG)
+else
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_RELEASE)
+       OPTIONS_LINK=$(OPTIONS_LINK_RELEASE)
+endif
+
+# Files
+HEADERS_MAYAQUA=src/Mayaqua/Cfg.h src/Mayaqua/cryptoki.h src/Mayaqua/Encrypt.h src/Mayaqua/FileIO.h src/Mayaqua/Internat.h src/Mayaqua/Kernel.h src/Mayaqua/Mayaqua.h src/Mayaqua/MayaType.h src/Mayaqua/Memory.h src/Mayaqua/Microsoft.h src/Mayaqua/Network.h src/Mayaqua/Object.h src/Mayaqua/openssl/aes.h src/Mayaqua/openssl/asn1.h src/Mayaqua/openssl/asn1_mac.h src/Mayaqua/openssl/asn1t.h src/Mayaqua/openssl/bio.h src/Mayaqua/openssl/blowfish.h src/Mayaqua/openssl/bn.h src/Mayaqua/openssl/buffer.h src/Mayaqua/openssl/cast.h src/Mayaqua/openssl/comp.h src/Mayaqua/openssl/conf.h src/Mayaqua/openssl/conf_api.h src/Mayaqua/openssl/crypto.h src/Mayaqua/openssl/des.h src/Mayaqua/openssl/des_old.h src/Mayaqua/openssl/dh.h src/Mayaqua/openssl/dsa.h src/Mayaqua/openssl/dso.h src/Mayaqua/openssl/dtls1.h src/Mayaqua/openssl/e_os2.h src/Mayaqua/openssl/ebcdic.h src/Mayaqua/openssl/ec.h src/Mayaqua/openssl/ecdh.h src/Mayaqua/openssl/ecdsa.h src/Mayaqua/openssl/engine.h src/Mayaqua/openssl/err.h src/Mayaqua/openssl/evp.h src/Mayaqua/openssl/fips.h src/Mayaqua/openssl/fips_rand.h src/Mayaqua/openssl/hmac.h src/Mayaqua/openssl/idea.h src/Mayaqua/openssl/krb5_asn.h src/Mayaqua/openssl/kssl.h src/Mayaqua/openssl/lhash.h src/Mayaqua/openssl/md2.h src/Mayaqua/openssl/md4.h src/Mayaqua/openssl/md5.h src/Mayaqua/openssl/mdc2.h src/Mayaqua/openssl/obj_mac.h src/Mayaqua/openssl/objects.h src/Mayaqua/openssl/ocsp.h src/Mayaqua/openssl/opensslconf.h src/Mayaqua/openssl/opensslv.h src/Mayaqua/openssl/ossl_typ.h src/Mayaqua/openssl/pem.h src/Mayaqua/openssl/pem2.h src/Mayaqua/openssl/pkcs12.h src/Mayaqua/openssl/pkcs7.h src/Mayaqua/openssl/pq_compat.h src/Mayaqua/openssl/pqueue.h src/Mayaqua/openssl/rand.h src/Mayaqua/openssl/rc2.h src/Mayaqua/openssl/rc4.h src/Mayaqua/openssl/rc5.h src/Mayaqua/openssl/ripemd.h src/Mayaqua/openssl/rsa.h src/Mayaqua/openssl/safestack.h src/Mayaqua/openssl/sha.h src/Mayaqua/openssl/ssl.h src/Mayaqua/openssl/ssl2.h src/Mayaqua/openssl/ssl23.h src/Mayaqua/openssl/ssl3.h src/Mayaqua/openssl/stack.h src/Mayaqua/openssl/store.h src/Mayaqua/openssl/symhacks.h src/Mayaqua/openssl/tls1.h src/Mayaqua/openssl/tmdiff.h src/Mayaqua/openssl/txt_db.h src/Mayaqua/openssl/ui.h src/Mayaqua/openssl/ui_compat.h src/Mayaqua/openssl/x509.h src/Mayaqua/openssl/x509_vfy.h src/Mayaqua/openssl/x509v3.h src/Mayaqua/OS.h src/Mayaqua/Pack.h src/Mayaqua/pkcs11.h src/Mayaqua/pkcs11f.h src/Mayaqua/pkcs11t.h src/Mayaqua/Secure.h src/Mayaqua/Str.h src/Mayaqua/Table.h src/Mayaqua/Tick64.h src/Mayaqua/Tracking.h src/Mayaqua/TunTap.h src/Mayaqua/Unix.h src/Mayaqua/Win32.h src/Mayaqua/zlib/zconf.h src/Mayaqua/zlib/zlib.h
+HEADERS_CEDAR=src/Cedar/Account.h src/Cedar/Admin.h src/Cedar/Bridge.h src/Cedar/BridgeUnix.h src/Cedar/BridgeWin32.h src/Cedar/Cedar.h src/Cedar/CedarPch.h src/Cedar/CedarType.h src/Cedar/Client.h src/Cedar/CM.h src/Cedar/CMInner.h src/Cedar/Command.h src/Cedar/Connection.h src/Cedar/Console.h src/Cedar/Database.h src/Cedar/Hub.h src/Cedar/Layer3.h src/Cedar/Link.h src/Cedar/Listener.h src/Cedar/Logging.h src/Cedar/Nat.h src/Cedar/NM.h src/Cedar/NMInner.h src/Cedar/NullLan.h src/Cedar/Protocol.h src/Cedar/Remote.h src/Cedar/Sam.h src/Cedar/SecureNAT.h src/Cedar/Server.h src/Cedar/Session.h src/Cedar/SM.h src/Cedar/SMInner.h src/Cedar/TcpIp.h src/Cedar/UT.h src/Cedar/Virtual.h src/Cedar/VLan.h src/Cedar/VLanUnix.h src/Cedar/VLanWin32.h src/Cedar/Win32Html.h src/Cedar/WinUi.h
+OBJECTS_MAYAQUA=tmp/objs/Mayaqua/Cfg.o tmp/objs/Mayaqua/Encrypt.o tmp/objs/Mayaqua/FileIO.o tmp/objs/Mayaqua/Internat.o tmp/objs/Mayaqua/Kernel.o tmp/objs/Mayaqua/Mayaqua.o tmp/objs/Mayaqua/Memory.o tmp/objs/Mayaqua/Microsoft.o tmp/objs/Mayaqua/Network.o tmp/objs/Mayaqua/Object.o tmp/objs/Mayaqua/OS.o tmp/objs/Mayaqua/Pack.o tmp/objs/Mayaqua/Secure.o tmp/objs/Mayaqua/Str.o tmp/objs/Mayaqua/Table.o tmp/objs/Mayaqua/Tick64.o tmp/objs/Mayaqua/Tracking.o tmp/objs/Mayaqua/Unix.o tmp/objs/Mayaqua/Win32.o
+OBJECTS_CEDAR=tmp/objs/Cedar/Account.o tmp/objs/Cedar/Admin.o tmp/objs/Cedar/Bridge.o tmp/objs/Cedar/BridgeUnix.o tmp/objs/Cedar/BridgeWin32.o tmp/objs/Cedar/Cedar.o tmp/objs/Cedar/CedarPch.o tmp/objs/Cedar/Client.o tmp/objs/Cedar/CM.o tmp/objs/Cedar/Command.o tmp/objs/Cedar/Connection.o tmp/objs/Cedar/Console.o tmp/objs/Cedar/Database.o tmp/objs/Cedar/Hub.o tmp/objs/Cedar/Layer3.o tmp/objs/Cedar/Link.o tmp/objs/Cedar/Listener.o tmp/objs/Cedar/Logging.o tmp/objs/Cedar/Nat.o tmp/objs/Cedar/NM.o tmp/objs/Cedar/NullLan.o tmp/objs/Cedar/Protocol.o tmp/objs/Cedar/Remote.o tmp/objs/Cedar/Sam.o tmp/objs/Cedar/SecureNAT.o tmp/objs/Cedar/Server.o tmp/objs/Cedar/Session.o tmp/objs/Cedar/SM.o tmp/objs/Cedar/TcpIp.o tmp/objs/Cedar/UT.o tmp/objs/Cedar/Virtual.o tmp/objs/Cedar/VLan.o tmp/objs/Cedar/VLanUnix.o tmp/objs/Cedar/VLanWin32.o tmp/objs/Cedar/WinUi.o
+
+# Build Action
+default:       build
+
+build: $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) output/ham/ham output/utvpnserver/utvpnserver output/utvpnclient/utvpnclient output/utvpncmd/utvpncmd
+
+# Mayaqua Kernel Code
+tmp/objs/Mayaqua/Cfg.o: src/Mayaqua/Cfg.c $(HEADERS_MAYAQUA)
+       @mkdir -p tmp/
+       @mkdir -p tmp/objs/
+       @mkdir -p tmp/objs/Mayaqua/
+       @mkdir -p tmp/objs/Cedar/
+       @mkdir -p tmp/as/
+       @mkdir -p output/
+       @mkdir -p output/ham/
+       @mkdir -p output/utvpnserver/
+       @mkdir -p output/utvpnclient/
+       @mkdir -p output/utvpncmd/
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Cfg.c -o tmp/objs/Mayaqua/Cfg.o
+
+tmp/objs/Mayaqua/Encrypt.o: src/Mayaqua/Encrypt.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Encrypt.c -o tmp/objs/Mayaqua/Encrypt.o
+
+tmp/objs/Mayaqua/FileIO.o: src/Mayaqua/FileIO.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/FileIO.c -o tmp/objs/Mayaqua/FileIO.o
+
+tmp/objs/Mayaqua/Internat.o: src/Mayaqua/Internat.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Internat.c -o tmp/objs/Mayaqua/Internat.o
+
+tmp/objs/Mayaqua/Kernel.o: src/Mayaqua/Kernel.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Kernel.c -o tmp/objs/Mayaqua/Kernel.o
+
+tmp/objs/Mayaqua/Mayaqua.o: src/Mayaqua/Mayaqua.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Mayaqua.c -o tmp/objs/Mayaqua/Mayaqua.o
+
+tmp/objs/Mayaqua/Memory.o: src/Mayaqua/Memory.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Memory.c -o tmp/objs/Mayaqua/Memory.o
+
+tmp/objs/Mayaqua/Microsoft.o: src/Mayaqua/Microsoft.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Microsoft.c -o tmp/objs/Mayaqua/Microsoft.o
+
+tmp/objs/Mayaqua/Network.o: src/Mayaqua/Network.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Network.c -o tmp/objs/Mayaqua/Network.o
+
+tmp/objs/Mayaqua/Object.o: src/Mayaqua/Object.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Object.c -o tmp/objs/Mayaqua/Object.o
+
+tmp/objs/Mayaqua/OS.o: src/Mayaqua/OS.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/OS.c -o tmp/objs/Mayaqua/OS.o
+
+tmp/objs/Mayaqua/Pack.o: src/Mayaqua/Pack.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Pack.c -o tmp/objs/Mayaqua/Pack.o
+
+tmp/objs/Mayaqua/Secure.o: src/Mayaqua/Secure.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Secure.c -o tmp/objs/Mayaqua/Secure.o
+
+tmp/objs/Mayaqua/Str.o: src/Mayaqua/Str.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Str.c -o tmp/objs/Mayaqua/Str.o
+
+tmp/objs/Mayaqua/Table.o: src/Mayaqua/Table.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Table.c -o tmp/objs/Mayaqua/Table.o
+
+tmp/objs/Mayaqua/Tick64.o: src/Mayaqua/Tick64.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tick64.c -o tmp/objs/Mayaqua/Tick64.o
+
+tmp/objs/Mayaqua/Tracking.o: src/Mayaqua/Tracking.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tracking.c -o tmp/objs/Mayaqua/Tracking.o
+
+tmp/objs/Mayaqua/Unix.o: src/Mayaqua/Unix.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Unix.c -o tmp/objs/Mayaqua/Unix.o
+
+tmp/objs/Mayaqua/Win32.o: src/Mayaqua/Win32.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Win32.c -o tmp/objs/Mayaqua/Win32.o
+
+# Cedar Communication Module Code
+tmp/objs/Cedar/Account.o: src/Cedar/Account.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Account.c -o tmp/objs/Cedar/Account.o
+
+tmp/objs/Cedar/Admin.o: src/Cedar/Admin.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Admin.c -o tmp/objs/Cedar/Admin.o
+
+tmp/objs/Cedar/Bridge.o: src/Cedar/Bridge.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) src/Cedar/BridgeUnix.c
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Bridge.c -o tmp/objs/Cedar/Bridge.o
+
+tmp/objs/Cedar/BridgeUnix.o: src/Cedar/BridgeUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeUnix.c -o tmp/objs/Cedar/BridgeUnix.o
+
+tmp/objs/Cedar/BridgeWin32.o: src/Cedar/BridgeWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeWin32.c -o tmp/objs/Cedar/BridgeWin32.o
+
+tmp/objs/Cedar/Cedar.o: src/Cedar/Cedar.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Cedar.c -o tmp/objs/Cedar/Cedar.o
+
+tmp/objs/Cedar/CedarPch.o: src/Cedar/CedarPch.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CedarPch.c -o tmp/objs/Cedar/CedarPch.o
+
+tmp/objs/Cedar/Client.o: src/Cedar/Client.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Client.c -o tmp/objs/Cedar/Client.o
+
+tmp/objs/Cedar/CM.o: src/Cedar/CM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CM.c -o tmp/objs/Cedar/CM.o
+
+tmp/objs/Cedar/Command.o: src/Cedar/Command.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Command.c -o tmp/objs/Cedar/Command.o
+
+tmp/objs/Cedar/Connection.o: src/Cedar/Connection.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Connection.c -o tmp/objs/Cedar/Connection.o
+
+tmp/objs/Cedar/Console.o: src/Cedar/Console.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Console.c -o tmp/objs/Cedar/Console.o
+
+tmp/objs/Cedar/Database.o: src/Cedar/Database.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Database.c -o tmp/objs/Cedar/Database.o
+
+tmp/objs/Cedar/Hub.o: src/Cedar/Hub.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Hub.c -o tmp/objs/Cedar/Hub.o
+
+tmp/objs/Cedar/Layer3.o: src/Cedar/Layer3.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Layer3.c -o tmp/objs/Cedar/Layer3.o
+
+tmp/objs/Cedar/Link.o: src/Cedar/Link.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Link.c -o tmp/objs/Cedar/Link.o
+
+tmp/objs/Cedar/Listener.o: src/Cedar/Listener.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Listener.c -o tmp/objs/Cedar/Listener.o
+
+tmp/objs/Cedar/Logging.o: src/Cedar/Logging.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Logging.c -o tmp/objs/Cedar/Logging.o
+
+tmp/objs/Cedar/Nat.o: src/Cedar/Nat.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Nat.c -o tmp/objs/Cedar/Nat.o
+
+tmp/objs/Cedar/NM.o: src/Cedar/NM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NM.c -o tmp/objs/Cedar/NM.o
+
+tmp/objs/Cedar/NullLan.o: src/Cedar/NullLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NullLan.c -o tmp/objs/Cedar/NullLan.o
+
+tmp/objs/Cedar/Protocol.o: src/Cedar/Protocol.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Protocol.c -o tmp/objs/Cedar/Protocol.o
+
+tmp/objs/Cedar/Remote.o: src/Cedar/Remote.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Remote.c -o tmp/objs/Cedar/Remote.o
+
+tmp/objs/Cedar/Sam.o: src/Cedar/Sam.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Sam.c -o tmp/objs/Cedar/Sam.o
+
+tmp/objs/Cedar/SecureNAT.o: src/Cedar/SecureNAT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SecureNAT.c -o tmp/objs/Cedar/SecureNAT.o
+
+tmp/objs/Cedar/Server.o: src/Cedar/Server.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Server.c -o tmp/objs/Cedar/Server.o
+
+tmp/objs/Cedar/Session.o: src/Cedar/Session.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Session.c -o tmp/objs/Cedar/Session.o
+
+tmp/objs/Cedar/SM.o: src/Cedar/SM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SM.c -o tmp/objs/Cedar/SM.o
+
+tmp/objs/Cedar/TcpIp.o: src/Cedar/TcpIp.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/TcpIp.c -o tmp/objs/Cedar/TcpIp.o
+
+tmp/objs/Cedar/UT.o: src/Cedar/UT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/UT.c -o tmp/objs/Cedar/UT.o
+
+tmp/objs/Cedar/Virtual.o: src/Cedar/Virtual.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Virtual.c -o tmp/objs/Cedar/Virtual.o
+
+tmp/objs/Cedar/VLan.o: src/Cedar/VLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLan.c -o tmp/objs/Cedar/VLan.o
+
+tmp/objs/Cedar/VLanUnix.o: src/Cedar/VLanUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanUnix.c -o tmp/objs/Cedar/VLanUnix.o
+
+tmp/objs/Cedar/VLanWin32.o: src/Cedar/VLanWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanWin32.c -o tmp/objs/Cedar/VLanWin32.o
+
+tmp/objs/Cedar/WinUi.o: src/Cedar/WinUi.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/WinUi.c -o tmp/objs/Cedar/WinUi.o
+
+# Ham
+output/ham/ham: tmp/as/Ham.a output/ham/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/Ham.a $(OPTIONS_LINK) -o output/ham/ham
+
+tmp/as/Ham.a: tmp/objs/Ham.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/Ham.a
+       ar r tmp/as/Ham.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/Ham.o
+       ranlib tmp/as/Ham.a
+
+output/ham/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/ham/hamcore.utvpn
+
+tmp/objs/Ham.o: src/Ham/Ham.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Ham/Ham.c -o tmp/objs/Ham.o
+
+# utvpnserver
+output/utvpnserver/utvpnserver: tmp/as/utvpnserver.a output/utvpnserver/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnserver.a $(OPTIONS_LINK) -o output/utvpnserver/utvpnserver
+
+tmp/as/utvpnserver.a: tmp/objs/utvpnserver.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnserver.a
+       ar r tmp/as/utvpnserver.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnserver.o
+       ranlib tmp/as/utvpnserver.a
+
+output/utvpnserver/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnserver/hamcore.utvpn
+
+tmp/objs/utvpnserver.o: src/utvpnserver/utvpnserver.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnserver/utvpnserver.c -o tmp/objs/utvpnserver.o
+
+# utvpnclient
+output/utvpnclient/utvpnclient: tmp/as/utvpnclient.a output/utvpnclient/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnclient.a $(OPTIONS_LINK) -o output/utvpnclient/utvpnclient
+
+tmp/as/utvpnclient.a: tmp/objs/utvpnclient.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnclient.a
+       ar r tmp/as/utvpnclient.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnclient.o
+       ranlib tmp/as/utvpnclient.a
+
+output/utvpnclient/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnclient/hamcore.utvpn
+
+tmp/objs/utvpnclient.o: src/utvpnclient/utvpnclient.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnclient/utvpnclient.c -o tmp/objs/utvpnclient.o
+
+# utvpncmd
+output/utvpncmd/utvpncmd: tmp/as/utvpncmd.a output/utvpncmd/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpncmd.a $(OPTIONS_LINK) -o output/utvpncmd/utvpncmd
+
+tmp/as/utvpncmd.a: tmp/objs/utvpncmd.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpncmd.a
+       ar r tmp/as/utvpncmd.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpncmd.o
+       ranlib tmp/as/utvpncmd.a
+
+output/utvpncmd/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpncmd/hamcore.utvpn
+
+tmp/objs/utvpncmd.o: src/utvpncmd/utvpncmd.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpncmd/utvpncmd.c -o tmp/objs/utvpncmd.o
+
+# Install
+install: $(INSTALL_BINDIR)utvpnserver $(INSTALL_BINDIR)utvpnclient $(INSTALL_BINDIR)utvpncmd
+       @echo
+       @echo "--------------------------------------------------------------------"
+       @echo "Installation completed successfully."
+       @echo
+       @echo "Please execute 'utvpnserver start' to run UT-VPN Server Background Service."
+       @echo "Or please execute 'utvpnclient start' to run UT-VPN Client Background Service."
+       @echo "And please execute 'utvpncmd' to run UT-VPN Command-Line Utility to configure UT-Server or UT-VPN Client."
+       @echo "--------------------------------------------------------------------"
+       @echo
+
+$(INSTALL_BINDIR)utvpnserver: output/utvpnserver/hamcore.utvpn output/utvpnserver/utvpnserver
+       @mkdir -p $(INSTALL_UTVPNSERVER_DIR)
+       cp output/utvpnserver/hamcore.utvpn $(INSTALL_UTVPNSERVER_DIR)hamcore.utvpn
+       cp output/utvpnserver/utvpnserver $(INSTALL_UTVPNSERVER_DIR)utvpnserver
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnserver
+       echo $(INSTALL_UTVPNSERVER_DIR)utvpnserver '"$$@"' >> $(INSTALL_BINDIR)utvpnserver
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnserver
+       chmod 755 $(INSTALL_BINDIR)utvpnserver
+
+$(INSTALL_BINDIR)utvpnclient: output/utvpnclient/hamcore.utvpn output/utvpnclient/utvpnclient
+       @mkdir -p $(INSTALL_UTVPNCLIENT_DIR)
+       cp output/utvpnclient/hamcore.utvpn $(INSTALL_UTVPNCLIENT_DIR)hamcore.utvpn
+       cp output/utvpnclient/utvpnclient $(INSTALL_UTVPNCLIENT_DIR)utvpnclient
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnclient
+       echo $(INSTALL_UTVPNCLIENT_DIR)utvpnclient '"$$@"' >> $(INSTALL_BINDIR)utvpnclient
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnclient
+       chmod 755 $(INSTALL_BINDIR)utvpnclient
+
+$(INSTALL_BINDIR)utvpncmd: output/utvpncmd/hamcore.utvpn output/utvpncmd/utvpncmd
+       @mkdir -p $(INSTALL_UTVPNCMD_DIR)
+       cp output/utvpncmd/hamcore.utvpn $(INSTALL_UTVPNCMD_DIR)hamcore.utvpn
+       cp output/utvpncmd/utvpncmd $(INSTALL_UTVPNCMD_DIR)utvpncmd
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpncmd
+       echo $(INSTALL_UTVPNCMD_DIR)utvpncmd '"$$@"' >> $(INSTALL_BINDIR)utvpncmd
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpncmd
+       chmod 755 $(INSTALL_BINDIR)utvpncmd
+
+# Clean
+clean:
+       -rm -f $(OBJECTS_MAYAQUA)
+       -rm -f $(OBJECTS_CEDAR)
+       -rm -f tmp/objs/Ham.o
+       -rm -f tmp/as/Ham.a
+       -rm -f output/ham/ham
+       -rm -f tmp/objs/utvpnserver.o
+       -rm -f tmp/as/utvpnserver.a
+       -rm -f output/utvpnserver/utvpnserver
+       -rm -f tmp/objs/utvpnclient.o
+       -rm -f tmp/as/utvpnclient.a
+       -rm -f output/utvpnclient/utvpnclient
+       -rm -f tmp/objs/utvpncmd.o
+       -rm -f tmp/as/utvpncmd.a
+       -rm -f output/utvpncmd/utvpncmd
+
+# Help Strings
+help:
+       @echo "make [DEBUG=YES]"
+
diff --git a/utvpn/utvpn-unix-v101-7101-public/makefiles/linux_32bit_ja.mak b/utvpn/utvpn-unix-v101-7101-public/makefiles/linux_32bit_ja.mak
new file mode 100644 (file)
index 0000000..32e076f
--- /dev/null
@@ -0,0 +1,353 @@
+# SoftEther UT-VPN SourceCode
+# 
+# Copyright (C) 2004-2010 SoftEther Corporation.
+# Copyright (C) 2004-2010 University of Tsukuba, Japan.
+# Copyright (C) 2003-2010 Daiyuu Nobori.
+# All Rights Reserved.
+# 
+# http://utvpn.tsukuba.ac.jp/
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License version 2
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# 
+# Platform: os=Linux, bits=32bit, language=Japanese
+
+# Variables
+CC=gcc
+
+OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_LINUX -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char
+
+OPTIONS_LINK_DEBUG=-g -fsigned-char -lm -ldl -lrt -lpthread -lssl -lcrypto -lreadline -lncurses -lz
+
+OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_LINUX -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char
+
+OPTIONS_LINK_RELEASE=-O2 -fsigned-char -lm -ldl -lrt -lpthread -lssl -lcrypto -lreadline -lncurses -lz
+
+INSTALL_BINDIR=/usr/bin/
+INSTALL_UTVPNSERVER_DIR=/usr/utvpnserver/
+INSTALL_UTVPNCLIENT_DIR=/usr/utvpnclient/
+INSTALL_UTVPNCMD_DIR=/usr/utvpncmd/
+
+ifeq ($(DEBUG),YES)
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_DEBUG)
+       OPTIONS_LINK=$(OPTIONS_LINK_DEBUG)
+else
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_RELEASE)
+       OPTIONS_LINK=$(OPTIONS_LINK_RELEASE)
+endif
+
+# Files
+HEADERS_MAYAQUA=src/Mayaqua/Cfg.h src/Mayaqua/cryptoki.h src/Mayaqua/Encrypt.h src/Mayaqua/FileIO.h src/Mayaqua/Internat.h src/Mayaqua/Kernel.h src/Mayaqua/Mayaqua.h src/Mayaqua/MayaType.h src/Mayaqua/Memory.h src/Mayaqua/Microsoft.h src/Mayaqua/Network.h src/Mayaqua/Object.h src/Mayaqua/openssl/aes.h src/Mayaqua/openssl/asn1.h src/Mayaqua/openssl/asn1_mac.h src/Mayaqua/openssl/asn1t.h src/Mayaqua/openssl/bio.h src/Mayaqua/openssl/blowfish.h src/Mayaqua/openssl/bn.h src/Mayaqua/openssl/buffer.h src/Mayaqua/openssl/cast.h src/Mayaqua/openssl/comp.h src/Mayaqua/openssl/conf.h src/Mayaqua/openssl/conf_api.h src/Mayaqua/openssl/crypto.h src/Mayaqua/openssl/des.h src/Mayaqua/openssl/des_old.h src/Mayaqua/openssl/dh.h src/Mayaqua/openssl/dsa.h src/Mayaqua/openssl/dso.h src/Mayaqua/openssl/dtls1.h src/Mayaqua/openssl/e_os2.h src/Mayaqua/openssl/ebcdic.h src/Mayaqua/openssl/ec.h src/Mayaqua/openssl/ecdh.h src/Mayaqua/openssl/ecdsa.h src/Mayaqua/openssl/engine.h src/Mayaqua/openssl/err.h src/Mayaqua/openssl/evp.h src/Mayaqua/openssl/fips.h src/Mayaqua/openssl/fips_rand.h src/Mayaqua/openssl/hmac.h src/Mayaqua/openssl/idea.h src/Mayaqua/openssl/krb5_asn.h src/Mayaqua/openssl/kssl.h src/Mayaqua/openssl/lhash.h src/Mayaqua/openssl/md2.h src/Mayaqua/openssl/md4.h src/Mayaqua/openssl/md5.h src/Mayaqua/openssl/mdc2.h src/Mayaqua/openssl/obj_mac.h src/Mayaqua/openssl/objects.h src/Mayaqua/openssl/ocsp.h src/Mayaqua/openssl/opensslconf.h src/Mayaqua/openssl/opensslv.h src/Mayaqua/openssl/ossl_typ.h src/Mayaqua/openssl/pem.h src/Mayaqua/openssl/pem2.h src/Mayaqua/openssl/pkcs12.h src/Mayaqua/openssl/pkcs7.h src/Mayaqua/openssl/pq_compat.h src/Mayaqua/openssl/pqueue.h src/Mayaqua/openssl/rand.h src/Mayaqua/openssl/rc2.h src/Mayaqua/openssl/rc4.h src/Mayaqua/openssl/rc5.h src/Mayaqua/openssl/ripemd.h src/Mayaqua/openssl/rsa.h src/Mayaqua/openssl/safestack.h src/Mayaqua/openssl/sha.h src/Mayaqua/openssl/ssl.h src/Mayaqua/openssl/ssl2.h src/Mayaqua/openssl/ssl23.h src/Mayaqua/openssl/ssl3.h src/Mayaqua/openssl/stack.h src/Mayaqua/openssl/store.h src/Mayaqua/openssl/symhacks.h src/Mayaqua/openssl/tls1.h src/Mayaqua/openssl/tmdiff.h src/Mayaqua/openssl/txt_db.h src/Mayaqua/openssl/ui.h src/Mayaqua/openssl/ui_compat.h src/Mayaqua/openssl/x509.h src/Mayaqua/openssl/x509_vfy.h src/Mayaqua/openssl/x509v3.h src/Mayaqua/OS.h src/Mayaqua/Pack.h src/Mayaqua/pkcs11.h src/Mayaqua/pkcs11f.h src/Mayaqua/pkcs11t.h src/Mayaqua/Secure.h src/Mayaqua/Str.h src/Mayaqua/Table.h src/Mayaqua/Tick64.h src/Mayaqua/Tracking.h src/Mayaqua/TunTap.h src/Mayaqua/Unix.h src/Mayaqua/Win32.h src/Mayaqua/zlib/zconf.h src/Mayaqua/zlib/zlib.h
+HEADERS_CEDAR=src/Cedar/Account.h src/Cedar/Admin.h src/Cedar/Bridge.h src/Cedar/BridgeUnix.h src/Cedar/BridgeWin32.h src/Cedar/Cedar.h src/Cedar/CedarPch.h src/Cedar/CedarType.h src/Cedar/Client.h src/Cedar/CM.h src/Cedar/CMInner.h src/Cedar/Command.h src/Cedar/Connection.h src/Cedar/Console.h src/Cedar/Database.h src/Cedar/Hub.h src/Cedar/Layer3.h src/Cedar/Link.h src/Cedar/Listener.h src/Cedar/Logging.h src/Cedar/Nat.h src/Cedar/NM.h src/Cedar/NMInner.h src/Cedar/NullLan.h src/Cedar/Protocol.h src/Cedar/Remote.h src/Cedar/Sam.h src/Cedar/SecureNAT.h src/Cedar/Server.h src/Cedar/Session.h src/Cedar/SM.h src/Cedar/SMInner.h src/Cedar/TcpIp.h src/Cedar/UT.h src/Cedar/Virtual.h src/Cedar/VLan.h src/Cedar/VLanUnix.h src/Cedar/VLanWin32.h src/Cedar/Win32Html.h src/Cedar/WinUi.h
+OBJECTS_MAYAQUA=tmp/objs/Mayaqua/Cfg.o tmp/objs/Mayaqua/Encrypt.o tmp/objs/Mayaqua/FileIO.o tmp/objs/Mayaqua/Internat.o tmp/objs/Mayaqua/Kernel.o tmp/objs/Mayaqua/Mayaqua.o tmp/objs/Mayaqua/Memory.o tmp/objs/Mayaqua/Microsoft.o tmp/objs/Mayaqua/Network.o tmp/objs/Mayaqua/Object.o tmp/objs/Mayaqua/OS.o tmp/objs/Mayaqua/Pack.o tmp/objs/Mayaqua/Secure.o tmp/objs/Mayaqua/Str.o tmp/objs/Mayaqua/Table.o tmp/objs/Mayaqua/Tick64.o tmp/objs/Mayaqua/Tracking.o tmp/objs/Mayaqua/Unix.o tmp/objs/Mayaqua/Win32.o
+OBJECTS_CEDAR=tmp/objs/Cedar/Account.o tmp/objs/Cedar/Admin.o tmp/objs/Cedar/Bridge.o tmp/objs/Cedar/BridgeUnix.o tmp/objs/Cedar/BridgeWin32.o tmp/objs/Cedar/Cedar.o tmp/objs/Cedar/CedarPch.o tmp/objs/Cedar/Client.o tmp/objs/Cedar/CM.o tmp/objs/Cedar/Command.o tmp/objs/Cedar/Connection.o tmp/objs/Cedar/Console.o tmp/objs/Cedar/Database.o tmp/objs/Cedar/Hub.o tmp/objs/Cedar/Layer3.o tmp/objs/Cedar/Link.o tmp/objs/Cedar/Listener.o tmp/objs/Cedar/Logging.o tmp/objs/Cedar/Nat.o tmp/objs/Cedar/NM.o tmp/objs/Cedar/NullLan.o tmp/objs/Cedar/Protocol.o tmp/objs/Cedar/Remote.o tmp/objs/Cedar/Sam.o tmp/objs/Cedar/SecureNAT.o tmp/objs/Cedar/Server.o tmp/objs/Cedar/Session.o tmp/objs/Cedar/SM.o tmp/objs/Cedar/TcpIp.o tmp/objs/Cedar/UT.o tmp/objs/Cedar/Virtual.o tmp/objs/Cedar/VLan.o tmp/objs/Cedar/VLanUnix.o tmp/objs/Cedar/VLanWin32.o tmp/objs/Cedar/WinUi.o
+
+# Build Action
+default:       build
+
+build: $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) output/ham/ham output/utvpnserver/utvpnserver output/utvpnclient/utvpnclient output/utvpncmd/utvpncmd
+
+# Mayaqua Kernel Code
+tmp/objs/Mayaqua/Cfg.o: src/Mayaqua/Cfg.c $(HEADERS_MAYAQUA)
+       @mkdir -p tmp/
+       @mkdir -p tmp/objs/
+       @mkdir -p tmp/objs/Mayaqua/
+       @mkdir -p tmp/objs/Cedar/
+       @mkdir -p tmp/as/
+       @mkdir -p output/
+       @mkdir -p output/ham/
+       @mkdir -p output/utvpnserver/
+       @mkdir -p output/utvpnclient/
+       @mkdir -p output/utvpncmd/
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Cfg.c -o tmp/objs/Mayaqua/Cfg.o
+
+tmp/objs/Mayaqua/Encrypt.o: src/Mayaqua/Encrypt.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Encrypt.c -o tmp/objs/Mayaqua/Encrypt.o
+
+tmp/objs/Mayaqua/FileIO.o: src/Mayaqua/FileIO.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/FileIO.c -o tmp/objs/Mayaqua/FileIO.o
+
+tmp/objs/Mayaqua/Internat.o: src/Mayaqua/Internat.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Internat.c -o tmp/objs/Mayaqua/Internat.o
+
+tmp/objs/Mayaqua/Kernel.o: src/Mayaqua/Kernel.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Kernel.c -o tmp/objs/Mayaqua/Kernel.o
+
+tmp/objs/Mayaqua/Mayaqua.o: src/Mayaqua/Mayaqua.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Mayaqua.c -o tmp/objs/Mayaqua/Mayaqua.o
+
+tmp/objs/Mayaqua/Memory.o: src/Mayaqua/Memory.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Memory.c -o tmp/objs/Mayaqua/Memory.o
+
+tmp/objs/Mayaqua/Microsoft.o: src/Mayaqua/Microsoft.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Microsoft.c -o tmp/objs/Mayaqua/Microsoft.o
+
+tmp/objs/Mayaqua/Network.o: src/Mayaqua/Network.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Network.c -o tmp/objs/Mayaqua/Network.o
+
+tmp/objs/Mayaqua/Object.o: src/Mayaqua/Object.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Object.c -o tmp/objs/Mayaqua/Object.o
+
+tmp/objs/Mayaqua/OS.o: src/Mayaqua/OS.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/OS.c -o tmp/objs/Mayaqua/OS.o
+
+tmp/objs/Mayaqua/Pack.o: src/Mayaqua/Pack.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Pack.c -o tmp/objs/Mayaqua/Pack.o
+
+tmp/objs/Mayaqua/Secure.o: src/Mayaqua/Secure.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Secure.c -o tmp/objs/Mayaqua/Secure.o
+
+tmp/objs/Mayaqua/Str.o: src/Mayaqua/Str.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Str.c -o tmp/objs/Mayaqua/Str.o
+
+tmp/objs/Mayaqua/Table.o: src/Mayaqua/Table.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Table.c -o tmp/objs/Mayaqua/Table.o
+
+tmp/objs/Mayaqua/Tick64.o: src/Mayaqua/Tick64.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tick64.c -o tmp/objs/Mayaqua/Tick64.o
+
+tmp/objs/Mayaqua/Tracking.o: src/Mayaqua/Tracking.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tracking.c -o tmp/objs/Mayaqua/Tracking.o
+
+tmp/objs/Mayaqua/Unix.o: src/Mayaqua/Unix.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Unix.c -o tmp/objs/Mayaqua/Unix.o
+
+tmp/objs/Mayaqua/Win32.o: src/Mayaqua/Win32.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Win32.c -o tmp/objs/Mayaqua/Win32.o
+
+# Cedar Communication Module Code
+tmp/objs/Cedar/Account.o: src/Cedar/Account.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Account.c -o tmp/objs/Cedar/Account.o
+
+tmp/objs/Cedar/Admin.o: src/Cedar/Admin.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Admin.c -o tmp/objs/Cedar/Admin.o
+
+tmp/objs/Cedar/Bridge.o: src/Cedar/Bridge.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) src/Cedar/BridgeUnix.c
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Bridge.c -o tmp/objs/Cedar/Bridge.o
+
+tmp/objs/Cedar/BridgeUnix.o: src/Cedar/BridgeUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeUnix.c -o tmp/objs/Cedar/BridgeUnix.o
+
+tmp/objs/Cedar/BridgeWin32.o: src/Cedar/BridgeWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeWin32.c -o tmp/objs/Cedar/BridgeWin32.o
+
+tmp/objs/Cedar/Cedar.o: src/Cedar/Cedar.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Cedar.c -o tmp/objs/Cedar/Cedar.o
+
+tmp/objs/Cedar/CedarPch.o: src/Cedar/CedarPch.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CedarPch.c -o tmp/objs/Cedar/CedarPch.o
+
+tmp/objs/Cedar/Client.o: src/Cedar/Client.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Client.c -o tmp/objs/Cedar/Client.o
+
+tmp/objs/Cedar/CM.o: src/Cedar/CM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CM.c -o tmp/objs/Cedar/CM.o
+
+tmp/objs/Cedar/Command.o: src/Cedar/Command.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Command.c -o tmp/objs/Cedar/Command.o
+
+tmp/objs/Cedar/Connection.o: src/Cedar/Connection.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Connection.c -o tmp/objs/Cedar/Connection.o
+
+tmp/objs/Cedar/Console.o: src/Cedar/Console.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Console.c -o tmp/objs/Cedar/Console.o
+
+tmp/objs/Cedar/Database.o: src/Cedar/Database.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Database.c -o tmp/objs/Cedar/Database.o
+
+tmp/objs/Cedar/Hub.o: src/Cedar/Hub.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Hub.c -o tmp/objs/Cedar/Hub.o
+
+tmp/objs/Cedar/Layer3.o: src/Cedar/Layer3.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Layer3.c -o tmp/objs/Cedar/Layer3.o
+
+tmp/objs/Cedar/Link.o: src/Cedar/Link.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Link.c -o tmp/objs/Cedar/Link.o
+
+tmp/objs/Cedar/Listener.o: src/Cedar/Listener.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Listener.c -o tmp/objs/Cedar/Listener.o
+
+tmp/objs/Cedar/Logging.o: src/Cedar/Logging.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Logging.c -o tmp/objs/Cedar/Logging.o
+
+tmp/objs/Cedar/Nat.o: src/Cedar/Nat.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Nat.c -o tmp/objs/Cedar/Nat.o
+
+tmp/objs/Cedar/NM.o: src/Cedar/NM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NM.c -o tmp/objs/Cedar/NM.o
+
+tmp/objs/Cedar/NullLan.o: src/Cedar/NullLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NullLan.c -o tmp/objs/Cedar/NullLan.o
+
+tmp/objs/Cedar/Protocol.o: src/Cedar/Protocol.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Protocol.c -o tmp/objs/Cedar/Protocol.o
+
+tmp/objs/Cedar/Remote.o: src/Cedar/Remote.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Remote.c -o tmp/objs/Cedar/Remote.o
+
+tmp/objs/Cedar/Sam.o: src/Cedar/Sam.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Sam.c -o tmp/objs/Cedar/Sam.o
+
+tmp/objs/Cedar/SecureNAT.o: src/Cedar/SecureNAT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SecureNAT.c -o tmp/objs/Cedar/SecureNAT.o
+
+tmp/objs/Cedar/Server.o: src/Cedar/Server.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Server.c -o tmp/objs/Cedar/Server.o
+
+tmp/objs/Cedar/Session.o: src/Cedar/Session.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Session.c -o tmp/objs/Cedar/Session.o
+
+tmp/objs/Cedar/SM.o: src/Cedar/SM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SM.c -o tmp/objs/Cedar/SM.o
+
+tmp/objs/Cedar/TcpIp.o: src/Cedar/TcpIp.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/TcpIp.c -o tmp/objs/Cedar/TcpIp.o
+
+tmp/objs/Cedar/UT.o: src/Cedar/UT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/UT.c -o tmp/objs/Cedar/UT.o
+
+tmp/objs/Cedar/Virtual.o: src/Cedar/Virtual.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Virtual.c -o tmp/objs/Cedar/Virtual.o
+
+tmp/objs/Cedar/VLan.o: src/Cedar/VLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLan.c -o tmp/objs/Cedar/VLan.o
+
+tmp/objs/Cedar/VLanUnix.o: src/Cedar/VLanUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanUnix.c -o tmp/objs/Cedar/VLanUnix.o
+
+tmp/objs/Cedar/VLanWin32.o: src/Cedar/VLanWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanWin32.c -o tmp/objs/Cedar/VLanWin32.o
+
+tmp/objs/Cedar/WinUi.o: src/Cedar/WinUi.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/WinUi.c -o tmp/objs/Cedar/WinUi.o
+
+# Ham
+output/ham/ham: tmp/as/Ham.a output/ham/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/Ham.a $(OPTIONS_LINK) -o output/ham/ham
+
+tmp/as/Ham.a: tmp/objs/Ham.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/Ham.a
+       ar r tmp/as/Ham.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/Ham.o
+       ranlib tmp/as/Ham.a
+
+output/ham/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/ham/hamcore.utvpn
+
+tmp/objs/Ham.o: src/Ham/Ham.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Ham/Ham.c -o tmp/objs/Ham.o
+
+# utvpnserver
+output/utvpnserver/utvpnserver: tmp/as/utvpnserver.a output/utvpnserver/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnserver.a $(OPTIONS_LINK) -o output/utvpnserver/utvpnserver
+
+tmp/as/utvpnserver.a: tmp/objs/utvpnserver.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnserver.a
+       ar r tmp/as/utvpnserver.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnserver.o
+       ranlib tmp/as/utvpnserver.a
+
+output/utvpnserver/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnserver/hamcore.utvpn
+
+tmp/objs/utvpnserver.o: src/utvpnserver/utvpnserver.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnserver/utvpnserver.c -o tmp/objs/utvpnserver.o
+
+# utvpnclient
+output/utvpnclient/utvpnclient: tmp/as/utvpnclient.a output/utvpnclient/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnclient.a $(OPTIONS_LINK) -o output/utvpnclient/utvpnclient
+
+tmp/as/utvpnclient.a: tmp/objs/utvpnclient.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnclient.a
+       ar r tmp/as/utvpnclient.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnclient.o
+       ranlib tmp/as/utvpnclient.a
+
+output/utvpnclient/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnclient/hamcore.utvpn
+
+tmp/objs/utvpnclient.o: src/utvpnclient/utvpnclient.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnclient/utvpnclient.c -o tmp/objs/utvpnclient.o
+
+# utvpncmd
+output/utvpncmd/utvpncmd: tmp/as/utvpncmd.a output/utvpncmd/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpncmd.a $(OPTIONS_LINK) -o output/utvpncmd/utvpncmd
+
+tmp/as/utvpncmd.a: tmp/objs/utvpncmd.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpncmd.a
+       ar r tmp/as/utvpncmd.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpncmd.o
+       ranlib tmp/as/utvpncmd.a
+
+output/utvpncmd/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpncmd/hamcore.utvpn
+
+tmp/objs/utvpncmd.o: src/utvpncmd/utvpncmd.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpncmd/utvpncmd.c -o tmp/objs/utvpncmd.o
+
+# Install
+install: $(INSTALL_BINDIR)utvpnserver $(INSTALL_BINDIR)utvpnclient $(INSTALL_BINDIR)utvpncmd
+       @echo
+       @echo "--------------------------------------------------------------------"
+       @echo "Installation completed successfully."
+       @echo
+       @echo "Please execute 'utvpnserver start' to run UT-VPN Server Background Service."
+       @echo "Or please execute 'utvpnclient start' to run UT-VPN Client Background Service."
+       @echo "And please execute 'utvpncmd' to run UT-VPN Command-Line Utility to configure UT-Server or UT-VPN Client."
+       @echo "--------------------------------------------------------------------"
+       @echo
+
+$(INSTALL_BINDIR)utvpnserver: output/utvpnserver/hamcore.utvpn output/utvpnserver/utvpnserver
+       @mkdir -p $(INSTALL_UTVPNSERVER_DIR)
+       cp output/utvpnserver/hamcore.utvpn $(INSTALL_UTVPNSERVER_DIR)hamcore.utvpn
+       cp output/utvpnserver/utvpnserver $(INSTALL_UTVPNSERVER_DIR)utvpnserver
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnserver
+       echo $(INSTALL_UTVPNSERVER_DIR)utvpnserver '"$$@"' >> $(INSTALL_BINDIR)utvpnserver
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnserver
+       chmod 755 $(INSTALL_BINDIR)utvpnserver
+
+$(INSTALL_BINDIR)utvpnclient: output/utvpnclient/hamcore.utvpn output/utvpnclient/utvpnclient
+       @mkdir -p $(INSTALL_UTVPNCLIENT_DIR)
+       cp output/utvpnclient/hamcore.utvpn $(INSTALL_UTVPNCLIENT_DIR)hamcore.utvpn
+       cp output/utvpnclient/utvpnclient $(INSTALL_UTVPNCLIENT_DIR)utvpnclient
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnclient
+       echo $(INSTALL_UTVPNCLIENT_DIR)utvpnclient '"$$@"' >> $(INSTALL_BINDIR)utvpnclient
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnclient
+       chmod 755 $(INSTALL_BINDIR)utvpnclient
+
+$(INSTALL_BINDIR)utvpncmd: output/utvpncmd/hamcore.utvpn output/utvpncmd/utvpncmd
+       @mkdir -p $(INSTALL_UTVPNCMD_DIR)
+       cp output/utvpncmd/hamcore.utvpn $(INSTALL_UTVPNCMD_DIR)hamcore.utvpn
+       cp output/utvpncmd/utvpncmd $(INSTALL_UTVPNCMD_DIR)utvpncmd
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpncmd
+       echo $(INSTALL_UTVPNCMD_DIR)utvpncmd '"$$@"' >> $(INSTALL_BINDIR)utvpncmd
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpncmd
+       chmod 755 $(INSTALL_BINDIR)utvpncmd
+
+# Clean
+clean:
+       -rm -f $(OBJECTS_MAYAQUA)
+       -rm -f $(OBJECTS_CEDAR)
+       -rm -f tmp/objs/Ham.o
+       -rm -f tmp/as/Ham.a
+       -rm -f output/ham/ham
+       -rm -f tmp/objs/utvpnserver.o
+       -rm -f tmp/as/utvpnserver.a
+       -rm -f output/utvpnserver/utvpnserver
+       -rm -f tmp/objs/utvpnclient.o
+       -rm -f tmp/as/utvpnclient.a
+       -rm -f output/utvpnclient/utvpnclient
+       -rm -f tmp/objs/utvpncmd.o
+       -rm -f tmp/as/utvpncmd.a
+       -rm -f output/utvpncmd/utvpncmd
+
+# Help Strings
+help:
+       @echo "make [DEBUG=YES]"
+
diff --git a/utvpn/utvpn-unix-v101-7101-public/makefiles/linux_64bit_ja.mak b/utvpn/utvpn-unix-v101-7101-public/makefiles/linux_64bit_ja.mak
new file mode 100644 (file)
index 0000000..0dfbc62
--- /dev/null
@@ -0,0 +1,353 @@
+# SoftEther UT-VPN SourceCode
+# 
+# Copyright (C) 2004-2010 SoftEther Corporation.
+# Copyright (C) 2004-2010 University of Tsukuba, Japan.
+# Copyright (C) 2003-2010 Daiyuu Nobori.
+# All Rights Reserved.
+# 
+# http://utvpn.tsukuba.ac.jp/
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License version 2
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# 
+# Platform: os=Linux, bits=64bit, language=Japanese
+
+# Variables
+CC=gcc
+
+OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_LINUX -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char -m64
+
+OPTIONS_LINK_DEBUG=-g -fsigned-char -m64 -lm -ldl -lrt -lpthread -lssl -lcrypto -lreadline -lncurses -lz
+
+OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_LINUX -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char -m64
+
+OPTIONS_LINK_RELEASE=-O2 -fsigned-char -m64 -lm -ldl -lrt -lpthread -lssl -lcrypto -lreadline -lncurses -lz
+
+INSTALL_BINDIR=/usr/bin/
+INSTALL_UTVPNSERVER_DIR=/usr/utvpnserver/
+INSTALL_UTVPNCLIENT_DIR=/usr/utvpnclient/
+INSTALL_UTVPNCMD_DIR=/usr/utvpncmd/
+
+ifeq ($(DEBUG),YES)
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_DEBUG)
+       OPTIONS_LINK=$(OPTIONS_LINK_DEBUG)
+else
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_RELEASE)
+       OPTIONS_LINK=$(OPTIONS_LINK_RELEASE)
+endif
+
+# Files
+HEADERS_MAYAQUA=src/Mayaqua/Cfg.h src/Mayaqua/cryptoki.h src/Mayaqua/Encrypt.h src/Mayaqua/FileIO.h src/Mayaqua/Internat.h src/Mayaqua/Kernel.h src/Mayaqua/Mayaqua.h src/Mayaqua/MayaType.h src/Mayaqua/Memory.h src/Mayaqua/Microsoft.h src/Mayaqua/Network.h src/Mayaqua/Object.h src/Mayaqua/openssl/aes.h src/Mayaqua/openssl/asn1.h src/Mayaqua/openssl/asn1_mac.h src/Mayaqua/openssl/asn1t.h src/Mayaqua/openssl/bio.h src/Mayaqua/openssl/blowfish.h src/Mayaqua/openssl/bn.h src/Mayaqua/openssl/buffer.h src/Mayaqua/openssl/cast.h src/Mayaqua/openssl/comp.h src/Mayaqua/openssl/conf.h src/Mayaqua/openssl/conf_api.h src/Mayaqua/openssl/crypto.h src/Mayaqua/openssl/des.h src/Mayaqua/openssl/des_old.h src/Mayaqua/openssl/dh.h src/Mayaqua/openssl/dsa.h src/Mayaqua/openssl/dso.h src/Mayaqua/openssl/dtls1.h src/Mayaqua/openssl/e_os2.h src/Mayaqua/openssl/ebcdic.h src/Mayaqua/openssl/ec.h src/Mayaqua/openssl/ecdh.h src/Mayaqua/openssl/ecdsa.h src/Mayaqua/openssl/engine.h src/Mayaqua/openssl/err.h src/Mayaqua/openssl/evp.h src/Mayaqua/openssl/fips.h src/Mayaqua/openssl/fips_rand.h src/Mayaqua/openssl/hmac.h src/Mayaqua/openssl/idea.h src/Mayaqua/openssl/krb5_asn.h src/Mayaqua/openssl/kssl.h src/Mayaqua/openssl/lhash.h src/Mayaqua/openssl/md2.h src/Mayaqua/openssl/md4.h src/Mayaqua/openssl/md5.h src/Mayaqua/openssl/mdc2.h src/Mayaqua/openssl/obj_mac.h src/Mayaqua/openssl/objects.h src/Mayaqua/openssl/ocsp.h src/Mayaqua/openssl/opensslconf.h src/Mayaqua/openssl/opensslv.h src/Mayaqua/openssl/ossl_typ.h src/Mayaqua/openssl/pem.h src/Mayaqua/openssl/pem2.h src/Mayaqua/openssl/pkcs12.h src/Mayaqua/openssl/pkcs7.h src/Mayaqua/openssl/pq_compat.h src/Mayaqua/openssl/pqueue.h src/Mayaqua/openssl/rand.h src/Mayaqua/openssl/rc2.h src/Mayaqua/openssl/rc4.h src/Mayaqua/openssl/rc5.h src/Mayaqua/openssl/ripemd.h src/Mayaqua/openssl/rsa.h src/Mayaqua/openssl/safestack.h src/Mayaqua/openssl/sha.h src/Mayaqua/openssl/ssl.h src/Mayaqua/openssl/ssl2.h src/Mayaqua/openssl/ssl23.h src/Mayaqua/openssl/ssl3.h src/Mayaqua/openssl/stack.h src/Mayaqua/openssl/store.h src/Mayaqua/openssl/symhacks.h src/Mayaqua/openssl/tls1.h src/Mayaqua/openssl/tmdiff.h src/Mayaqua/openssl/txt_db.h src/Mayaqua/openssl/ui.h src/Mayaqua/openssl/ui_compat.h src/Mayaqua/openssl/x509.h src/Mayaqua/openssl/x509_vfy.h src/Mayaqua/openssl/x509v3.h src/Mayaqua/OS.h src/Mayaqua/Pack.h src/Mayaqua/pkcs11.h src/Mayaqua/pkcs11f.h src/Mayaqua/pkcs11t.h src/Mayaqua/Secure.h src/Mayaqua/Str.h src/Mayaqua/Table.h src/Mayaqua/Tick64.h src/Mayaqua/Tracking.h src/Mayaqua/TunTap.h src/Mayaqua/Unix.h src/Mayaqua/Win32.h src/Mayaqua/zlib/zconf.h src/Mayaqua/zlib/zlib.h
+HEADERS_CEDAR=src/Cedar/Account.h src/Cedar/Admin.h src/Cedar/Bridge.h src/Cedar/BridgeUnix.h src/Cedar/BridgeWin32.h src/Cedar/Cedar.h src/Cedar/CedarPch.h src/Cedar/CedarType.h src/Cedar/Client.h src/Cedar/CM.h src/Cedar/CMInner.h src/Cedar/Command.h src/Cedar/Connection.h src/Cedar/Console.h src/Cedar/Database.h src/Cedar/Hub.h src/Cedar/Layer3.h src/Cedar/Link.h src/Cedar/Listener.h src/Cedar/Logging.h src/Cedar/Nat.h src/Cedar/NM.h src/Cedar/NMInner.h src/Cedar/NullLan.h src/Cedar/Protocol.h src/Cedar/Remote.h src/Cedar/Sam.h src/Cedar/SecureNAT.h src/Cedar/Server.h src/Cedar/Session.h src/Cedar/SM.h src/Cedar/SMInner.h src/Cedar/TcpIp.h src/Cedar/UT.h src/Cedar/Virtual.h src/Cedar/VLan.h src/Cedar/VLanUnix.h src/Cedar/VLanWin32.h src/Cedar/Win32Html.h src/Cedar/WinUi.h
+OBJECTS_MAYAQUA=tmp/objs/Mayaqua/Cfg.o tmp/objs/Mayaqua/Encrypt.o tmp/objs/Mayaqua/FileIO.o tmp/objs/Mayaqua/Internat.o tmp/objs/Mayaqua/Kernel.o tmp/objs/Mayaqua/Mayaqua.o tmp/objs/Mayaqua/Memory.o tmp/objs/Mayaqua/Microsoft.o tmp/objs/Mayaqua/Network.o tmp/objs/Mayaqua/Object.o tmp/objs/Mayaqua/OS.o tmp/objs/Mayaqua/Pack.o tmp/objs/Mayaqua/Secure.o tmp/objs/Mayaqua/Str.o tmp/objs/Mayaqua/Table.o tmp/objs/Mayaqua/Tick64.o tmp/objs/Mayaqua/Tracking.o tmp/objs/Mayaqua/Unix.o tmp/objs/Mayaqua/Win32.o
+OBJECTS_CEDAR=tmp/objs/Cedar/Account.o tmp/objs/Cedar/Admin.o tmp/objs/Cedar/Bridge.o tmp/objs/Cedar/BridgeUnix.o tmp/objs/Cedar/BridgeWin32.o tmp/objs/Cedar/Cedar.o tmp/objs/Cedar/CedarPch.o tmp/objs/Cedar/Client.o tmp/objs/Cedar/CM.o tmp/objs/Cedar/Command.o tmp/objs/Cedar/Connection.o tmp/objs/Cedar/Console.o tmp/objs/Cedar/Database.o tmp/objs/Cedar/Hub.o tmp/objs/Cedar/Layer3.o tmp/objs/Cedar/Link.o tmp/objs/Cedar/Listener.o tmp/objs/Cedar/Logging.o tmp/objs/Cedar/Nat.o tmp/objs/Cedar/NM.o tmp/objs/Cedar/NullLan.o tmp/objs/Cedar/Protocol.o tmp/objs/Cedar/Remote.o tmp/objs/Cedar/Sam.o tmp/objs/Cedar/SecureNAT.o tmp/objs/Cedar/Server.o tmp/objs/Cedar/Session.o tmp/objs/Cedar/SM.o tmp/objs/Cedar/TcpIp.o tmp/objs/Cedar/UT.o tmp/objs/Cedar/Virtual.o tmp/objs/Cedar/VLan.o tmp/objs/Cedar/VLanUnix.o tmp/objs/Cedar/VLanWin32.o tmp/objs/Cedar/WinUi.o
+
+# Build Action
+default:       build
+
+build: $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) output/ham/ham output/utvpnserver/utvpnserver output/utvpnclient/utvpnclient output/utvpncmd/utvpncmd
+
+# Mayaqua Kernel Code
+tmp/objs/Mayaqua/Cfg.o: src/Mayaqua/Cfg.c $(HEADERS_MAYAQUA)
+       @mkdir -p tmp/
+       @mkdir -p tmp/objs/
+       @mkdir -p tmp/objs/Mayaqua/
+       @mkdir -p tmp/objs/Cedar/
+       @mkdir -p tmp/as/
+       @mkdir -p output/
+       @mkdir -p output/ham/
+       @mkdir -p output/utvpnserver/
+       @mkdir -p output/utvpnclient/
+       @mkdir -p output/utvpncmd/
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Cfg.c -o tmp/objs/Mayaqua/Cfg.o
+
+tmp/objs/Mayaqua/Encrypt.o: src/Mayaqua/Encrypt.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Encrypt.c -o tmp/objs/Mayaqua/Encrypt.o
+
+tmp/objs/Mayaqua/FileIO.o: src/Mayaqua/FileIO.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/FileIO.c -o tmp/objs/Mayaqua/FileIO.o
+
+tmp/objs/Mayaqua/Internat.o: src/Mayaqua/Internat.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Internat.c -o tmp/objs/Mayaqua/Internat.o
+
+tmp/objs/Mayaqua/Kernel.o: src/Mayaqua/Kernel.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Kernel.c -o tmp/objs/Mayaqua/Kernel.o
+
+tmp/objs/Mayaqua/Mayaqua.o: src/Mayaqua/Mayaqua.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Mayaqua.c -o tmp/objs/Mayaqua/Mayaqua.o
+
+tmp/objs/Mayaqua/Memory.o: src/Mayaqua/Memory.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Memory.c -o tmp/objs/Mayaqua/Memory.o
+
+tmp/objs/Mayaqua/Microsoft.o: src/Mayaqua/Microsoft.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Microsoft.c -o tmp/objs/Mayaqua/Microsoft.o
+
+tmp/objs/Mayaqua/Network.o: src/Mayaqua/Network.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Network.c -o tmp/objs/Mayaqua/Network.o
+
+tmp/objs/Mayaqua/Object.o: src/Mayaqua/Object.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Object.c -o tmp/objs/Mayaqua/Object.o
+
+tmp/objs/Mayaqua/OS.o: src/Mayaqua/OS.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/OS.c -o tmp/objs/Mayaqua/OS.o
+
+tmp/objs/Mayaqua/Pack.o: src/Mayaqua/Pack.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Pack.c -o tmp/objs/Mayaqua/Pack.o
+
+tmp/objs/Mayaqua/Secure.o: src/Mayaqua/Secure.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Secure.c -o tmp/objs/Mayaqua/Secure.o
+
+tmp/objs/Mayaqua/Str.o: src/Mayaqua/Str.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Str.c -o tmp/objs/Mayaqua/Str.o
+
+tmp/objs/Mayaqua/Table.o: src/Mayaqua/Table.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Table.c -o tmp/objs/Mayaqua/Table.o
+
+tmp/objs/Mayaqua/Tick64.o: src/Mayaqua/Tick64.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tick64.c -o tmp/objs/Mayaqua/Tick64.o
+
+tmp/objs/Mayaqua/Tracking.o: src/Mayaqua/Tracking.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tracking.c -o tmp/objs/Mayaqua/Tracking.o
+
+tmp/objs/Mayaqua/Unix.o: src/Mayaqua/Unix.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Unix.c -o tmp/objs/Mayaqua/Unix.o
+
+tmp/objs/Mayaqua/Win32.o: src/Mayaqua/Win32.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Win32.c -o tmp/objs/Mayaqua/Win32.o
+
+# Cedar Communication Module Code
+tmp/objs/Cedar/Account.o: src/Cedar/Account.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Account.c -o tmp/objs/Cedar/Account.o
+
+tmp/objs/Cedar/Admin.o: src/Cedar/Admin.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Admin.c -o tmp/objs/Cedar/Admin.o
+
+tmp/objs/Cedar/Bridge.o: src/Cedar/Bridge.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) src/Cedar/BridgeUnix.c
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Bridge.c -o tmp/objs/Cedar/Bridge.o
+
+tmp/objs/Cedar/BridgeUnix.o: src/Cedar/BridgeUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeUnix.c -o tmp/objs/Cedar/BridgeUnix.o
+
+tmp/objs/Cedar/BridgeWin32.o: src/Cedar/BridgeWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeWin32.c -o tmp/objs/Cedar/BridgeWin32.o
+
+tmp/objs/Cedar/Cedar.o: src/Cedar/Cedar.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Cedar.c -o tmp/objs/Cedar/Cedar.o
+
+tmp/objs/Cedar/CedarPch.o: src/Cedar/CedarPch.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CedarPch.c -o tmp/objs/Cedar/CedarPch.o
+
+tmp/objs/Cedar/Client.o: src/Cedar/Client.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Client.c -o tmp/objs/Cedar/Client.o
+
+tmp/objs/Cedar/CM.o: src/Cedar/CM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CM.c -o tmp/objs/Cedar/CM.o
+
+tmp/objs/Cedar/Command.o: src/Cedar/Command.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Command.c -o tmp/objs/Cedar/Command.o
+
+tmp/objs/Cedar/Connection.o: src/Cedar/Connection.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Connection.c -o tmp/objs/Cedar/Connection.o
+
+tmp/objs/Cedar/Console.o: src/Cedar/Console.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Console.c -o tmp/objs/Cedar/Console.o
+
+tmp/objs/Cedar/Database.o: src/Cedar/Database.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Database.c -o tmp/objs/Cedar/Database.o
+
+tmp/objs/Cedar/Hub.o: src/Cedar/Hub.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Hub.c -o tmp/objs/Cedar/Hub.o
+
+tmp/objs/Cedar/Layer3.o: src/Cedar/Layer3.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Layer3.c -o tmp/objs/Cedar/Layer3.o
+
+tmp/objs/Cedar/Link.o: src/Cedar/Link.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Link.c -o tmp/objs/Cedar/Link.o
+
+tmp/objs/Cedar/Listener.o: src/Cedar/Listener.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Listener.c -o tmp/objs/Cedar/Listener.o
+
+tmp/objs/Cedar/Logging.o: src/Cedar/Logging.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Logging.c -o tmp/objs/Cedar/Logging.o
+
+tmp/objs/Cedar/Nat.o: src/Cedar/Nat.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Nat.c -o tmp/objs/Cedar/Nat.o
+
+tmp/objs/Cedar/NM.o: src/Cedar/NM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NM.c -o tmp/objs/Cedar/NM.o
+
+tmp/objs/Cedar/NullLan.o: src/Cedar/NullLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NullLan.c -o tmp/objs/Cedar/NullLan.o
+
+tmp/objs/Cedar/Protocol.o: src/Cedar/Protocol.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Protocol.c -o tmp/objs/Cedar/Protocol.o
+
+tmp/objs/Cedar/Remote.o: src/Cedar/Remote.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Remote.c -o tmp/objs/Cedar/Remote.o
+
+tmp/objs/Cedar/Sam.o: src/Cedar/Sam.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Sam.c -o tmp/objs/Cedar/Sam.o
+
+tmp/objs/Cedar/SecureNAT.o: src/Cedar/SecureNAT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SecureNAT.c -o tmp/objs/Cedar/SecureNAT.o
+
+tmp/objs/Cedar/Server.o: src/Cedar/Server.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Server.c -o tmp/objs/Cedar/Server.o
+
+tmp/objs/Cedar/Session.o: src/Cedar/Session.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Session.c -o tmp/objs/Cedar/Session.o
+
+tmp/objs/Cedar/SM.o: src/Cedar/SM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SM.c -o tmp/objs/Cedar/SM.o
+
+tmp/objs/Cedar/TcpIp.o: src/Cedar/TcpIp.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/TcpIp.c -o tmp/objs/Cedar/TcpIp.o
+
+tmp/objs/Cedar/UT.o: src/Cedar/UT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/UT.c -o tmp/objs/Cedar/UT.o
+
+tmp/objs/Cedar/Virtual.o: src/Cedar/Virtual.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Virtual.c -o tmp/objs/Cedar/Virtual.o
+
+tmp/objs/Cedar/VLan.o: src/Cedar/VLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLan.c -o tmp/objs/Cedar/VLan.o
+
+tmp/objs/Cedar/VLanUnix.o: src/Cedar/VLanUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanUnix.c -o tmp/objs/Cedar/VLanUnix.o
+
+tmp/objs/Cedar/VLanWin32.o: src/Cedar/VLanWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanWin32.c -o tmp/objs/Cedar/VLanWin32.o
+
+tmp/objs/Cedar/WinUi.o: src/Cedar/WinUi.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/WinUi.c -o tmp/objs/Cedar/WinUi.o
+
+# Ham
+output/ham/ham: tmp/as/Ham.a output/ham/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/Ham.a $(OPTIONS_LINK) -o output/ham/ham
+
+tmp/as/Ham.a: tmp/objs/Ham.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/Ham.a
+       ar r tmp/as/Ham.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/Ham.o
+       ranlib tmp/as/Ham.a
+
+output/ham/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/ham/hamcore.utvpn
+
+tmp/objs/Ham.o: src/Ham/Ham.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Ham/Ham.c -o tmp/objs/Ham.o
+
+# utvpnserver
+output/utvpnserver/utvpnserver: tmp/as/utvpnserver.a output/utvpnserver/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnserver.a $(OPTIONS_LINK) -o output/utvpnserver/utvpnserver
+
+tmp/as/utvpnserver.a: tmp/objs/utvpnserver.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnserver.a
+       ar r tmp/as/utvpnserver.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnserver.o
+       ranlib tmp/as/utvpnserver.a
+
+output/utvpnserver/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnserver/hamcore.utvpn
+
+tmp/objs/utvpnserver.o: src/utvpnserver/utvpnserver.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnserver/utvpnserver.c -o tmp/objs/utvpnserver.o
+
+# utvpnclient
+output/utvpnclient/utvpnclient: tmp/as/utvpnclient.a output/utvpnclient/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnclient.a $(OPTIONS_LINK) -o output/utvpnclient/utvpnclient
+
+tmp/as/utvpnclient.a: tmp/objs/utvpnclient.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnclient.a
+       ar r tmp/as/utvpnclient.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnclient.o
+       ranlib tmp/as/utvpnclient.a
+
+output/utvpnclient/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnclient/hamcore.utvpn
+
+tmp/objs/utvpnclient.o: src/utvpnclient/utvpnclient.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnclient/utvpnclient.c -o tmp/objs/utvpnclient.o
+
+# utvpncmd
+output/utvpncmd/utvpncmd: tmp/as/utvpncmd.a output/utvpncmd/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpncmd.a $(OPTIONS_LINK) -o output/utvpncmd/utvpncmd
+
+tmp/as/utvpncmd.a: tmp/objs/utvpncmd.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpncmd.a
+       ar r tmp/as/utvpncmd.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpncmd.o
+       ranlib tmp/as/utvpncmd.a
+
+output/utvpncmd/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpncmd/hamcore.utvpn
+
+tmp/objs/utvpncmd.o: src/utvpncmd/utvpncmd.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpncmd/utvpncmd.c -o tmp/objs/utvpncmd.o
+
+# Install
+install: $(INSTALL_BINDIR)utvpnserver $(INSTALL_BINDIR)utvpnclient $(INSTALL_BINDIR)utvpncmd
+       @echo
+       @echo "--------------------------------------------------------------------"
+       @echo "Installation completed successfully."
+       @echo
+       @echo "Please execute 'utvpnserver start' to run UT-VPN Server Background Service."
+       @echo "Or please execute 'utvpnclient start' to run UT-VPN Client Background Service."
+       @echo "And please execute 'utvpncmd' to run UT-VPN Command-Line Utility to configure UT-Server or UT-VPN Client."
+       @echo "--------------------------------------------------------------------"
+       @echo
+
+$(INSTALL_BINDIR)utvpnserver: output/utvpnserver/hamcore.utvpn output/utvpnserver/utvpnserver
+       @mkdir -p $(INSTALL_UTVPNSERVER_DIR)
+       cp output/utvpnserver/hamcore.utvpn $(INSTALL_UTVPNSERVER_DIR)hamcore.utvpn
+       cp output/utvpnserver/utvpnserver $(INSTALL_UTVPNSERVER_DIR)utvpnserver
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnserver
+       echo $(INSTALL_UTVPNSERVER_DIR)utvpnserver '"$$@"' >> $(INSTALL_BINDIR)utvpnserver
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnserver
+       chmod 755 $(INSTALL_BINDIR)utvpnserver
+
+$(INSTALL_BINDIR)utvpnclient: output/utvpnclient/hamcore.utvpn output/utvpnclient/utvpnclient
+       @mkdir -p $(INSTALL_UTVPNCLIENT_DIR)
+       cp output/utvpnclient/hamcore.utvpn $(INSTALL_UTVPNCLIENT_DIR)hamcore.utvpn
+       cp output/utvpnclient/utvpnclient $(INSTALL_UTVPNCLIENT_DIR)utvpnclient
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnclient
+       echo $(INSTALL_UTVPNCLIENT_DIR)utvpnclient '"$$@"' >> $(INSTALL_BINDIR)utvpnclient
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnclient
+       chmod 755 $(INSTALL_BINDIR)utvpnclient
+
+$(INSTALL_BINDIR)utvpncmd: output/utvpncmd/hamcore.utvpn output/utvpncmd/utvpncmd
+       @mkdir -p $(INSTALL_UTVPNCMD_DIR)
+       cp output/utvpncmd/hamcore.utvpn $(INSTALL_UTVPNCMD_DIR)hamcore.utvpn
+       cp output/utvpncmd/utvpncmd $(INSTALL_UTVPNCMD_DIR)utvpncmd
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpncmd
+       echo $(INSTALL_UTVPNCMD_DIR)utvpncmd '"$$@"' >> $(INSTALL_BINDIR)utvpncmd
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpncmd
+       chmod 755 $(INSTALL_BINDIR)utvpncmd
+
+# Clean
+clean:
+       -rm -f $(OBJECTS_MAYAQUA)
+       -rm -f $(OBJECTS_CEDAR)
+       -rm -f tmp/objs/Ham.o
+       -rm -f tmp/as/Ham.a
+       -rm -f output/ham/ham
+       -rm -f tmp/objs/utvpnserver.o
+       -rm -f tmp/as/utvpnserver.a
+       -rm -f output/utvpnserver/utvpnserver
+       -rm -f tmp/objs/utvpnclient.o
+       -rm -f tmp/as/utvpnclient.a
+       -rm -f output/utvpnclient/utvpnclient
+       -rm -f tmp/objs/utvpncmd.o
+       -rm -f tmp/as/utvpncmd.a
+       -rm -f output/utvpncmd/utvpncmd
+
+# Help Strings
+help:
+       @echo "make [DEBUG=YES]"
+
diff --git a/utvpn/utvpn-unix-v101-7101-public/makefiles/macos_32bit_ja.mak b/utvpn/utvpn-unix-v101-7101-public/makefiles/macos_32bit_ja.mak
new file mode 100644 (file)
index 0000000..a5aa8e2
--- /dev/null
@@ -0,0 +1,353 @@
+# SoftEther UT-VPN SourceCode
+# 
+# Copyright (C) 2004-2010 SoftEther Corporation.
+# Copyright (C) 2004-2010 University of Tsukuba, Japan.
+# Copyright (C) 2003-2010 Daiyuu Nobori.
+# All Rights Reserved.
+# 
+# http://utvpn.tsukuba.ac.jp/
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License version 2
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# 
+# Platform: os=Mac OS X, bits=32bit, language=Japanese
+
+# Variables
+CC=gcc
+
+OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_MACOS -DNO_VLAN -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char
+
+OPTIONS_LINK_DEBUG=-g -fsigned-char -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz
+
+OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_MACOS -DNO_VLAN -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char
+
+OPTIONS_LINK_RELEASE=-O2 -fsigned-char -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz
+
+INSTALL_BINDIR=/usr/bin/
+INSTALL_UTVPNSERVER_DIR=/usr/utvpnserver/
+INSTALL_UTVPNCLIENT_DIR=/usr/utvpnclient/
+INSTALL_UTVPNCMD_DIR=/usr/utvpncmd/
+
+ifeq ($(DEBUG),YES)
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_DEBUG)
+       OPTIONS_LINK=$(OPTIONS_LINK_DEBUG)
+else
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_RELEASE)
+       OPTIONS_LINK=$(OPTIONS_LINK_RELEASE)
+endif
+
+# Files
+HEADERS_MAYAQUA=src/Mayaqua/Cfg.h src/Mayaqua/cryptoki.h src/Mayaqua/Encrypt.h src/Mayaqua/FileIO.h src/Mayaqua/Internat.h src/Mayaqua/Kernel.h src/Mayaqua/Mayaqua.h src/Mayaqua/MayaType.h src/Mayaqua/Memory.h src/Mayaqua/Microsoft.h src/Mayaqua/Network.h src/Mayaqua/Object.h src/Mayaqua/openssl/aes.h src/Mayaqua/openssl/asn1.h src/Mayaqua/openssl/asn1_mac.h src/Mayaqua/openssl/asn1t.h src/Mayaqua/openssl/bio.h src/Mayaqua/openssl/blowfish.h src/Mayaqua/openssl/bn.h src/Mayaqua/openssl/buffer.h src/Mayaqua/openssl/cast.h src/Mayaqua/openssl/comp.h src/Mayaqua/openssl/conf.h src/Mayaqua/openssl/conf_api.h src/Mayaqua/openssl/crypto.h src/Mayaqua/openssl/des.h src/Mayaqua/openssl/des_old.h src/Mayaqua/openssl/dh.h src/Mayaqua/openssl/dsa.h src/Mayaqua/openssl/dso.h src/Mayaqua/openssl/dtls1.h src/Mayaqua/openssl/e_os2.h src/Mayaqua/openssl/ebcdic.h src/Mayaqua/openssl/ec.h src/Mayaqua/openssl/ecdh.h src/Mayaqua/openssl/ecdsa.h src/Mayaqua/openssl/engine.h src/Mayaqua/openssl/err.h src/Mayaqua/openssl/evp.h src/Mayaqua/openssl/fips.h src/Mayaqua/openssl/fips_rand.h src/Mayaqua/openssl/hmac.h src/Mayaqua/openssl/idea.h src/Mayaqua/openssl/krb5_asn.h src/Mayaqua/openssl/kssl.h src/Mayaqua/openssl/lhash.h src/Mayaqua/openssl/md2.h src/Mayaqua/openssl/md4.h src/Mayaqua/openssl/md5.h src/Mayaqua/openssl/mdc2.h src/Mayaqua/openssl/obj_mac.h src/Mayaqua/openssl/objects.h src/Mayaqua/openssl/ocsp.h src/Mayaqua/openssl/opensslconf.h src/Mayaqua/openssl/opensslv.h src/Mayaqua/openssl/ossl_typ.h src/Mayaqua/openssl/pem.h src/Mayaqua/openssl/pem2.h src/Mayaqua/openssl/pkcs12.h src/Mayaqua/openssl/pkcs7.h src/Mayaqua/openssl/pq_compat.h src/Mayaqua/openssl/pqueue.h src/Mayaqua/openssl/rand.h src/Mayaqua/openssl/rc2.h src/Mayaqua/openssl/rc4.h src/Mayaqua/openssl/rc5.h src/Mayaqua/openssl/ripemd.h src/Mayaqua/openssl/rsa.h src/Mayaqua/openssl/safestack.h src/Mayaqua/openssl/sha.h src/Mayaqua/openssl/ssl.h src/Mayaqua/openssl/ssl2.h src/Mayaqua/openssl/ssl23.h src/Mayaqua/openssl/ssl3.h src/Mayaqua/openssl/stack.h src/Mayaqua/openssl/store.h src/Mayaqua/openssl/symhacks.h src/Mayaqua/openssl/tls1.h src/Mayaqua/openssl/tmdiff.h src/Mayaqua/openssl/txt_db.h src/Mayaqua/openssl/ui.h src/Mayaqua/openssl/ui_compat.h src/Mayaqua/openssl/x509.h src/Mayaqua/openssl/x509_vfy.h src/Mayaqua/openssl/x509v3.h src/Mayaqua/OS.h src/Mayaqua/Pack.h src/Mayaqua/pkcs11.h src/Mayaqua/pkcs11f.h src/Mayaqua/pkcs11t.h src/Mayaqua/Secure.h src/Mayaqua/Str.h src/Mayaqua/Table.h src/Mayaqua/Tick64.h src/Mayaqua/Tracking.h src/Mayaqua/TunTap.h src/Mayaqua/Unix.h src/Mayaqua/Win32.h src/Mayaqua/zlib/zconf.h src/Mayaqua/zlib/zlib.h
+HEADERS_CEDAR=src/Cedar/Account.h src/Cedar/Admin.h src/Cedar/Bridge.h src/Cedar/BridgeUnix.h src/Cedar/BridgeWin32.h src/Cedar/Cedar.h src/Cedar/CedarPch.h src/Cedar/CedarType.h src/Cedar/Client.h src/Cedar/CM.h src/Cedar/CMInner.h src/Cedar/Command.h src/Cedar/Connection.h src/Cedar/Console.h src/Cedar/Database.h src/Cedar/Hub.h src/Cedar/Layer3.h src/Cedar/Link.h src/Cedar/Listener.h src/Cedar/Logging.h src/Cedar/Nat.h src/Cedar/NM.h src/Cedar/NMInner.h src/Cedar/NullLan.h src/Cedar/Protocol.h src/Cedar/Remote.h src/Cedar/Sam.h src/Cedar/SecureNAT.h src/Cedar/Server.h src/Cedar/Session.h src/Cedar/SM.h src/Cedar/SMInner.h src/Cedar/TcpIp.h src/Cedar/UT.h src/Cedar/Virtual.h src/Cedar/VLan.h src/Cedar/VLanUnix.h src/Cedar/VLanWin32.h src/Cedar/Win32Html.h src/Cedar/WinUi.h
+OBJECTS_MAYAQUA=tmp/objs/Mayaqua/Cfg.o tmp/objs/Mayaqua/Encrypt.o tmp/objs/Mayaqua/FileIO.o tmp/objs/Mayaqua/Internat.o tmp/objs/Mayaqua/Kernel.o tmp/objs/Mayaqua/Mayaqua.o tmp/objs/Mayaqua/Memory.o tmp/objs/Mayaqua/Microsoft.o tmp/objs/Mayaqua/Network.o tmp/objs/Mayaqua/Object.o tmp/objs/Mayaqua/OS.o tmp/objs/Mayaqua/Pack.o tmp/objs/Mayaqua/Secure.o tmp/objs/Mayaqua/Str.o tmp/objs/Mayaqua/Table.o tmp/objs/Mayaqua/Tick64.o tmp/objs/Mayaqua/Tracking.o tmp/objs/Mayaqua/Unix.o tmp/objs/Mayaqua/Win32.o
+OBJECTS_CEDAR=tmp/objs/Cedar/Account.o tmp/objs/Cedar/Admin.o tmp/objs/Cedar/Bridge.o tmp/objs/Cedar/BridgeUnix.o tmp/objs/Cedar/BridgeWin32.o tmp/objs/Cedar/Cedar.o tmp/objs/Cedar/CedarPch.o tmp/objs/Cedar/Client.o tmp/objs/Cedar/CM.o tmp/objs/Cedar/Command.o tmp/objs/Cedar/Connection.o tmp/objs/Cedar/Console.o tmp/objs/Cedar/Database.o tmp/objs/Cedar/Hub.o tmp/objs/Cedar/Layer3.o tmp/objs/Cedar/Link.o tmp/objs/Cedar/Listener.o tmp/objs/Cedar/Logging.o tmp/objs/Cedar/Nat.o tmp/objs/Cedar/NM.o tmp/objs/Cedar/NullLan.o tmp/objs/Cedar/Protocol.o tmp/objs/Cedar/Remote.o tmp/objs/Cedar/Sam.o tmp/objs/Cedar/SecureNAT.o tmp/objs/Cedar/Server.o tmp/objs/Cedar/Session.o tmp/objs/Cedar/SM.o tmp/objs/Cedar/TcpIp.o tmp/objs/Cedar/UT.o tmp/objs/Cedar/Virtual.o tmp/objs/Cedar/VLan.o tmp/objs/Cedar/VLanUnix.o tmp/objs/Cedar/VLanWin32.o tmp/objs/Cedar/WinUi.o
+
+# Build Action
+default:       build
+
+build: $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) output/ham/ham output/utvpnserver/utvpnserver output/utvpnclient/utvpnclient output/utvpncmd/utvpncmd
+
+# Mayaqua Kernel Code
+tmp/objs/Mayaqua/Cfg.o: src/Mayaqua/Cfg.c $(HEADERS_MAYAQUA)
+       @mkdir -p tmp/
+       @mkdir -p tmp/objs/
+       @mkdir -p tmp/objs/Mayaqua/
+       @mkdir -p tmp/objs/Cedar/
+       @mkdir -p tmp/as/
+       @mkdir -p output/
+       @mkdir -p output/ham/
+       @mkdir -p output/utvpnserver/
+       @mkdir -p output/utvpnclient/
+       @mkdir -p output/utvpncmd/
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Cfg.c -o tmp/objs/Mayaqua/Cfg.o
+
+tmp/objs/Mayaqua/Encrypt.o: src/Mayaqua/Encrypt.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Encrypt.c -o tmp/objs/Mayaqua/Encrypt.o
+
+tmp/objs/Mayaqua/FileIO.o: src/Mayaqua/FileIO.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/FileIO.c -o tmp/objs/Mayaqua/FileIO.o
+
+tmp/objs/Mayaqua/Internat.o: src/Mayaqua/Internat.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Internat.c -o tmp/objs/Mayaqua/Internat.o
+
+tmp/objs/Mayaqua/Kernel.o: src/Mayaqua/Kernel.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Kernel.c -o tmp/objs/Mayaqua/Kernel.o
+
+tmp/objs/Mayaqua/Mayaqua.o: src/Mayaqua/Mayaqua.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Mayaqua.c -o tmp/objs/Mayaqua/Mayaqua.o
+
+tmp/objs/Mayaqua/Memory.o: src/Mayaqua/Memory.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Memory.c -o tmp/objs/Mayaqua/Memory.o
+
+tmp/objs/Mayaqua/Microsoft.o: src/Mayaqua/Microsoft.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Microsoft.c -o tmp/objs/Mayaqua/Microsoft.o
+
+tmp/objs/Mayaqua/Network.o: src/Mayaqua/Network.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Network.c -o tmp/objs/Mayaqua/Network.o
+
+tmp/objs/Mayaqua/Object.o: src/Mayaqua/Object.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Object.c -o tmp/objs/Mayaqua/Object.o
+
+tmp/objs/Mayaqua/OS.o: src/Mayaqua/OS.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/OS.c -o tmp/objs/Mayaqua/OS.o
+
+tmp/objs/Mayaqua/Pack.o: src/Mayaqua/Pack.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Pack.c -o tmp/objs/Mayaqua/Pack.o
+
+tmp/objs/Mayaqua/Secure.o: src/Mayaqua/Secure.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Secure.c -o tmp/objs/Mayaqua/Secure.o
+
+tmp/objs/Mayaqua/Str.o: src/Mayaqua/Str.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Str.c -o tmp/objs/Mayaqua/Str.o
+
+tmp/objs/Mayaqua/Table.o: src/Mayaqua/Table.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Table.c -o tmp/objs/Mayaqua/Table.o
+
+tmp/objs/Mayaqua/Tick64.o: src/Mayaqua/Tick64.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tick64.c -o tmp/objs/Mayaqua/Tick64.o
+
+tmp/objs/Mayaqua/Tracking.o: src/Mayaqua/Tracking.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tracking.c -o tmp/objs/Mayaqua/Tracking.o
+
+tmp/objs/Mayaqua/Unix.o: src/Mayaqua/Unix.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Unix.c -o tmp/objs/Mayaqua/Unix.o
+
+tmp/objs/Mayaqua/Win32.o: src/Mayaqua/Win32.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Win32.c -o tmp/objs/Mayaqua/Win32.o
+
+# Cedar Communication Module Code
+tmp/objs/Cedar/Account.o: src/Cedar/Account.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Account.c -o tmp/objs/Cedar/Account.o
+
+tmp/objs/Cedar/Admin.o: src/Cedar/Admin.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Admin.c -o tmp/objs/Cedar/Admin.o
+
+tmp/objs/Cedar/Bridge.o: src/Cedar/Bridge.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) src/Cedar/BridgeUnix.c
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Bridge.c -o tmp/objs/Cedar/Bridge.o
+
+tmp/objs/Cedar/BridgeUnix.o: src/Cedar/BridgeUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeUnix.c -o tmp/objs/Cedar/BridgeUnix.o
+
+tmp/objs/Cedar/BridgeWin32.o: src/Cedar/BridgeWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeWin32.c -o tmp/objs/Cedar/BridgeWin32.o
+
+tmp/objs/Cedar/Cedar.o: src/Cedar/Cedar.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Cedar.c -o tmp/objs/Cedar/Cedar.o
+
+tmp/objs/Cedar/CedarPch.o: src/Cedar/CedarPch.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CedarPch.c -o tmp/objs/Cedar/CedarPch.o
+
+tmp/objs/Cedar/Client.o: src/Cedar/Client.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Client.c -o tmp/objs/Cedar/Client.o
+
+tmp/objs/Cedar/CM.o: src/Cedar/CM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CM.c -o tmp/objs/Cedar/CM.o
+
+tmp/objs/Cedar/Command.o: src/Cedar/Command.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Command.c -o tmp/objs/Cedar/Command.o
+
+tmp/objs/Cedar/Connection.o: src/Cedar/Connection.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Connection.c -o tmp/objs/Cedar/Connection.o
+
+tmp/objs/Cedar/Console.o: src/Cedar/Console.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Console.c -o tmp/objs/Cedar/Console.o
+
+tmp/objs/Cedar/Database.o: src/Cedar/Database.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Database.c -o tmp/objs/Cedar/Database.o
+
+tmp/objs/Cedar/Hub.o: src/Cedar/Hub.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Hub.c -o tmp/objs/Cedar/Hub.o
+
+tmp/objs/Cedar/Layer3.o: src/Cedar/Layer3.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Layer3.c -o tmp/objs/Cedar/Layer3.o
+
+tmp/objs/Cedar/Link.o: src/Cedar/Link.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Link.c -o tmp/objs/Cedar/Link.o
+
+tmp/objs/Cedar/Listener.o: src/Cedar/Listener.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Listener.c -o tmp/objs/Cedar/Listener.o
+
+tmp/objs/Cedar/Logging.o: src/Cedar/Logging.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Logging.c -o tmp/objs/Cedar/Logging.o
+
+tmp/objs/Cedar/Nat.o: src/Cedar/Nat.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Nat.c -o tmp/objs/Cedar/Nat.o
+
+tmp/objs/Cedar/NM.o: src/Cedar/NM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NM.c -o tmp/objs/Cedar/NM.o
+
+tmp/objs/Cedar/NullLan.o: src/Cedar/NullLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NullLan.c -o tmp/objs/Cedar/NullLan.o
+
+tmp/objs/Cedar/Protocol.o: src/Cedar/Protocol.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Protocol.c -o tmp/objs/Cedar/Protocol.o
+
+tmp/objs/Cedar/Remote.o: src/Cedar/Remote.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Remote.c -o tmp/objs/Cedar/Remote.o
+
+tmp/objs/Cedar/Sam.o: src/Cedar/Sam.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Sam.c -o tmp/objs/Cedar/Sam.o
+
+tmp/objs/Cedar/SecureNAT.o: src/Cedar/SecureNAT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SecureNAT.c -o tmp/objs/Cedar/SecureNAT.o
+
+tmp/objs/Cedar/Server.o: src/Cedar/Server.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Server.c -o tmp/objs/Cedar/Server.o
+
+tmp/objs/Cedar/Session.o: src/Cedar/Session.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Session.c -o tmp/objs/Cedar/Session.o
+
+tmp/objs/Cedar/SM.o: src/Cedar/SM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SM.c -o tmp/objs/Cedar/SM.o
+
+tmp/objs/Cedar/TcpIp.o: src/Cedar/TcpIp.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/TcpIp.c -o tmp/objs/Cedar/TcpIp.o
+
+tmp/objs/Cedar/UT.o: src/Cedar/UT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/UT.c -o tmp/objs/Cedar/UT.o
+
+tmp/objs/Cedar/Virtual.o: src/Cedar/Virtual.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Virtual.c -o tmp/objs/Cedar/Virtual.o
+
+tmp/objs/Cedar/VLan.o: src/Cedar/VLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLan.c -o tmp/objs/Cedar/VLan.o
+
+tmp/objs/Cedar/VLanUnix.o: src/Cedar/VLanUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanUnix.c -o tmp/objs/Cedar/VLanUnix.o
+
+tmp/objs/Cedar/VLanWin32.o: src/Cedar/VLanWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanWin32.c -o tmp/objs/Cedar/VLanWin32.o
+
+tmp/objs/Cedar/WinUi.o: src/Cedar/WinUi.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/WinUi.c -o tmp/objs/Cedar/WinUi.o
+
+# Ham
+output/ham/ham: tmp/as/Ham.a output/ham/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/Ham.a $(OPTIONS_LINK) -o output/ham/ham
+
+tmp/as/Ham.a: tmp/objs/Ham.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/Ham.a
+       ar r tmp/as/Ham.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/Ham.o
+       ranlib tmp/as/Ham.a
+
+output/ham/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/ham/hamcore.utvpn
+
+tmp/objs/Ham.o: src/Ham/Ham.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Ham/Ham.c -o tmp/objs/Ham.o
+
+# utvpnserver
+output/utvpnserver/utvpnserver: tmp/as/utvpnserver.a output/utvpnserver/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnserver.a $(OPTIONS_LINK) -o output/utvpnserver/utvpnserver
+
+tmp/as/utvpnserver.a: tmp/objs/utvpnserver.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnserver.a
+       ar r tmp/as/utvpnserver.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnserver.o
+       ranlib tmp/as/utvpnserver.a
+
+output/utvpnserver/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnserver/hamcore.utvpn
+
+tmp/objs/utvpnserver.o: src/utvpnserver/utvpnserver.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnserver/utvpnserver.c -o tmp/objs/utvpnserver.o
+
+# utvpnclient
+output/utvpnclient/utvpnclient: tmp/as/utvpnclient.a output/utvpnclient/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnclient.a $(OPTIONS_LINK) -o output/utvpnclient/utvpnclient
+
+tmp/as/utvpnclient.a: tmp/objs/utvpnclient.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnclient.a
+       ar r tmp/as/utvpnclient.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnclient.o
+       ranlib tmp/as/utvpnclient.a
+
+output/utvpnclient/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnclient/hamcore.utvpn
+
+tmp/objs/utvpnclient.o: src/utvpnclient/utvpnclient.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnclient/utvpnclient.c -o tmp/objs/utvpnclient.o
+
+# utvpncmd
+output/utvpncmd/utvpncmd: tmp/as/utvpncmd.a output/utvpncmd/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpncmd.a $(OPTIONS_LINK) -o output/utvpncmd/utvpncmd
+
+tmp/as/utvpncmd.a: tmp/objs/utvpncmd.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpncmd.a
+       ar r tmp/as/utvpncmd.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpncmd.o
+       ranlib tmp/as/utvpncmd.a
+
+output/utvpncmd/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpncmd/hamcore.utvpn
+
+tmp/objs/utvpncmd.o: src/utvpncmd/utvpncmd.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpncmd/utvpncmd.c -o tmp/objs/utvpncmd.o
+
+# Install
+install: $(INSTALL_BINDIR)utvpnserver $(INSTALL_BINDIR)utvpnclient $(INSTALL_BINDIR)utvpncmd
+       @echo
+       @echo "--------------------------------------------------------------------"
+       @echo "Installation completed successfully."
+       @echo
+       @echo "Please execute 'utvpnserver start' to run UT-VPN Server Background Service."
+       @echo "Or please execute 'utvpnclient start' to run UT-VPN Client Background Service."
+       @echo "And please execute 'utvpncmd' to run UT-VPN Command-Line Utility to configure UT-Server or UT-VPN Client."
+       @echo "--------------------------------------------------------------------"
+       @echo
+
+$(INSTALL_BINDIR)utvpnserver: output/utvpnserver/hamcore.utvpn output/utvpnserver/utvpnserver
+       @mkdir -p $(INSTALL_UTVPNSERVER_DIR)
+       cp output/utvpnserver/hamcore.utvpn $(INSTALL_UTVPNSERVER_DIR)hamcore.utvpn
+       cp output/utvpnserver/utvpnserver $(INSTALL_UTVPNSERVER_DIR)utvpnserver
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnserver
+       echo $(INSTALL_UTVPNSERVER_DIR)utvpnserver '"$$@"' >> $(INSTALL_BINDIR)utvpnserver
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnserver
+       chmod 755 $(INSTALL_BINDIR)utvpnserver
+
+$(INSTALL_BINDIR)utvpnclient: output/utvpnclient/hamcore.utvpn output/utvpnclient/utvpnclient
+       @mkdir -p $(INSTALL_UTVPNCLIENT_DIR)
+       cp output/utvpnclient/hamcore.utvpn $(INSTALL_UTVPNCLIENT_DIR)hamcore.utvpn
+       cp output/utvpnclient/utvpnclient $(INSTALL_UTVPNCLIENT_DIR)utvpnclient
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnclient
+       echo $(INSTALL_UTVPNCLIENT_DIR)utvpnclient '"$$@"' >> $(INSTALL_BINDIR)utvpnclient
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnclient
+       chmod 755 $(INSTALL_BINDIR)utvpnclient
+
+$(INSTALL_BINDIR)utvpncmd: output/utvpncmd/hamcore.utvpn output/utvpncmd/utvpncmd
+       @mkdir -p $(INSTALL_UTVPNCMD_DIR)
+       cp output/utvpncmd/hamcore.utvpn $(INSTALL_UTVPNCMD_DIR)hamcore.utvpn
+       cp output/utvpncmd/utvpncmd $(INSTALL_UTVPNCMD_DIR)utvpncmd
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpncmd
+       echo $(INSTALL_UTVPNCMD_DIR)utvpncmd '"$$@"' >> $(INSTALL_BINDIR)utvpncmd
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpncmd
+       chmod 755 $(INSTALL_BINDIR)utvpncmd
+
+# Clean
+clean:
+       -rm -f $(OBJECTS_MAYAQUA)
+       -rm -f $(OBJECTS_CEDAR)
+       -rm -f tmp/objs/Ham.o
+       -rm -f tmp/as/Ham.a
+       -rm -f output/ham/ham
+       -rm -f tmp/objs/utvpnserver.o
+       -rm -f tmp/as/utvpnserver.a
+       -rm -f output/utvpnserver/utvpnserver
+       -rm -f tmp/objs/utvpnclient.o
+       -rm -f tmp/as/utvpnclient.a
+       -rm -f output/utvpnclient/utvpnclient
+       -rm -f tmp/objs/utvpncmd.o
+       -rm -f tmp/as/utvpncmd.a
+       -rm -f output/utvpncmd/utvpncmd
+
+# Help Strings
+help:
+       @echo "make [DEBUG=YES]"
+
diff --git a/utvpn/utvpn-unix-v101-7101-public/makefiles/macos_64bit_ja.mak b/utvpn/utvpn-unix-v101-7101-public/makefiles/macos_64bit_ja.mak
new file mode 100644 (file)
index 0000000..91f3bcf
--- /dev/null
@@ -0,0 +1,353 @@
+# SoftEther UT-VPN SourceCode
+# 
+# Copyright (C) 2004-2010 SoftEther Corporation.
+# Copyright (C) 2004-2010 University of Tsukuba, Japan.
+# Copyright (C) 2003-2010 Daiyuu Nobori.
+# All Rights Reserved.
+# 
+# http://utvpn.tsukuba.ac.jp/
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License version 2
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# 
+# Platform: os=Mac OS X, bits=64bit, language=Japanese
+
+# Variables
+CC=gcc
+
+OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_MACOS -DNO_VLAN -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char -m64
+
+OPTIONS_LINK_DEBUG=-g -fsigned-char -m64 -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz
+
+OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_MACOS -DNO_VLAN -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char -m64
+
+OPTIONS_LINK_RELEASE=-O2 -fsigned-char -m64 -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz
+
+INSTALL_BINDIR=/usr/bin/
+INSTALL_UTVPNSERVER_DIR=/usr/utvpnserver/
+INSTALL_UTVPNCLIENT_DIR=/usr/utvpnclient/
+INSTALL_UTVPNCMD_DIR=/usr/utvpncmd/
+
+ifeq ($(DEBUG),YES)
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_DEBUG)
+       OPTIONS_LINK=$(OPTIONS_LINK_DEBUG)
+else
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_RELEASE)
+       OPTIONS_LINK=$(OPTIONS_LINK_RELEASE)
+endif
+
+# Files
+HEADERS_MAYAQUA=src/Mayaqua/Cfg.h src/Mayaqua/cryptoki.h src/Mayaqua/Encrypt.h src/Mayaqua/FileIO.h src/Mayaqua/Internat.h src/Mayaqua/Kernel.h src/Mayaqua/Mayaqua.h src/Mayaqua/MayaType.h src/Mayaqua/Memory.h src/Mayaqua/Microsoft.h src/Mayaqua/Network.h src/Mayaqua/Object.h src/Mayaqua/openssl/aes.h src/Mayaqua/openssl/asn1.h src/Mayaqua/openssl/asn1_mac.h src/Mayaqua/openssl/asn1t.h src/Mayaqua/openssl/bio.h src/Mayaqua/openssl/blowfish.h src/Mayaqua/openssl/bn.h src/Mayaqua/openssl/buffer.h src/Mayaqua/openssl/cast.h src/Mayaqua/openssl/comp.h src/Mayaqua/openssl/conf.h src/Mayaqua/openssl/conf_api.h src/Mayaqua/openssl/crypto.h src/Mayaqua/openssl/des.h src/Mayaqua/openssl/des_old.h src/Mayaqua/openssl/dh.h src/Mayaqua/openssl/dsa.h src/Mayaqua/openssl/dso.h src/Mayaqua/openssl/dtls1.h src/Mayaqua/openssl/e_os2.h src/Mayaqua/openssl/ebcdic.h src/Mayaqua/openssl/ec.h src/Mayaqua/openssl/ecdh.h src/Mayaqua/openssl/ecdsa.h src/Mayaqua/openssl/engine.h src/Mayaqua/openssl/err.h src/Mayaqua/openssl/evp.h src/Mayaqua/openssl/fips.h src/Mayaqua/openssl/fips_rand.h src/Mayaqua/openssl/hmac.h src/Mayaqua/openssl/idea.h src/Mayaqua/openssl/krb5_asn.h src/Mayaqua/openssl/kssl.h src/Mayaqua/openssl/lhash.h src/Mayaqua/openssl/md2.h src/Mayaqua/openssl/md4.h src/Mayaqua/openssl/md5.h src/Mayaqua/openssl/mdc2.h src/Mayaqua/openssl/obj_mac.h src/Mayaqua/openssl/objects.h src/Mayaqua/openssl/ocsp.h src/Mayaqua/openssl/opensslconf.h src/Mayaqua/openssl/opensslv.h src/Mayaqua/openssl/ossl_typ.h src/Mayaqua/openssl/pem.h src/Mayaqua/openssl/pem2.h src/Mayaqua/openssl/pkcs12.h src/Mayaqua/openssl/pkcs7.h src/Mayaqua/openssl/pq_compat.h src/Mayaqua/openssl/pqueue.h src/Mayaqua/openssl/rand.h src/Mayaqua/openssl/rc2.h src/Mayaqua/openssl/rc4.h src/Mayaqua/openssl/rc5.h src/Mayaqua/openssl/ripemd.h src/Mayaqua/openssl/rsa.h src/Mayaqua/openssl/safestack.h src/Mayaqua/openssl/sha.h src/Mayaqua/openssl/ssl.h src/Mayaqua/openssl/ssl2.h src/Mayaqua/openssl/ssl23.h src/Mayaqua/openssl/ssl3.h src/Mayaqua/openssl/stack.h src/Mayaqua/openssl/store.h src/Mayaqua/openssl/symhacks.h src/Mayaqua/openssl/tls1.h src/Mayaqua/openssl/tmdiff.h src/Mayaqua/openssl/txt_db.h src/Mayaqua/openssl/ui.h src/Mayaqua/openssl/ui_compat.h src/Mayaqua/openssl/x509.h src/Mayaqua/openssl/x509_vfy.h src/Mayaqua/openssl/x509v3.h src/Mayaqua/OS.h src/Mayaqua/Pack.h src/Mayaqua/pkcs11.h src/Mayaqua/pkcs11f.h src/Mayaqua/pkcs11t.h src/Mayaqua/Secure.h src/Mayaqua/Str.h src/Mayaqua/Table.h src/Mayaqua/Tick64.h src/Mayaqua/Tracking.h src/Mayaqua/TunTap.h src/Mayaqua/Unix.h src/Mayaqua/Win32.h src/Mayaqua/zlib/zconf.h src/Mayaqua/zlib/zlib.h
+HEADERS_CEDAR=src/Cedar/Account.h src/Cedar/Admin.h src/Cedar/Bridge.h src/Cedar/BridgeUnix.h src/Cedar/BridgeWin32.h src/Cedar/Cedar.h src/Cedar/CedarPch.h src/Cedar/CedarType.h src/Cedar/Client.h src/Cedar/CM.h src/Cedar/CMInner.h src/Cedar/Command.h src/Cedar/Connection.h src/Cedar/Console.h src/Cedar/Database.h src/Cedar/Hub.h src/Cedar/Layer3.h src/Cedar/Link.h src/Cedar/Listener.h src/Cedar/Logging.h src/Cedar/Nat.h src/Cedar/NM.h src/Cedar/NMInner.h src/Cedar/NullLan.h src/Cedar/Protocol.h src/Cedar/Remote.h src/Cedar/Sam.h src/Cedar/SecureNAT.h src/Cedar/Server.h src/Cedar/Session.h src/Cedar/SM.h src/Cedar/SMInner.h src/Cedar/TcpIp.h src/Cedar/UT.h src/Cedar/Virtual.h src/Cedar/VLan.h src/Cedar/VLanUnix.h src/Cedar/VLanWin32.h src/Cedar/Win32Html.h src/Cedar/WinUi.h
+OBJECTS_MAYAQUA=tmp/objs/Mayaqua/Cfg.o tmp/objs/Mayaqua/Encrypt.o tmp/objs/Mayaqua/FileIO.o tmp/objs/Mayaqua/Internat.o tmp/objs/Mayaqua/Kernel.o tmp/objs/Mayaqua/Mayaqua.o tmp/objs/Mayaqua/Memory.o tmp/objs/Mayaqua/Microsoft.o tmp/objs/Mayaqua/Network.o tmp/objs/Mayaqua/Object.o tmp/objs/Mayaqua/OS.o tmp/objs/Mayaqua/Pack.o tmp/objs/Mayaqua/Secure.o tmp/objs/Mayaqua/Str.o tmp/objs/Mayaqua/Table.o tmp/objs/Mayaqua/Tick64.o tmp/objs/Mayaqua/Tracking.o tmp/objs/Mayaqua/Unix.o tmp/objs/Mayaqua/Win32.o
+OBJECTS_CEDAR=tmp/objs/Cedar/Account.o tmp/objs/Cedar/Admin.o tmp/objs/Cedar/Bridge.o tmp/objs/Cedar/BridgeUnix.o tmp/objs/Cedar/BridgeWin32.o tmp/objs/Cedar/Cedar.o tmp/objs/Cedar/CedarPch.o tmp/objs/Cedar/Client.o tmp/objs/Cedar/CM.o tmp/objs/Cedar/Command.o tmp/objs/Cedar/Connection.o tmp/objs/Cedar/Console.o tmp/objs/Cedar/Database.o tmp/objs/Cedar/Hub.o tmp/objs/Cedar/Layer3.o tmp/objs/Cedar/Link.o tmp/objs/Cedar/Listener.o tmp/objs/Cedar/Logging.o tmp/objs/Cedar/Nat.o tmp/objs/Cedar/NM.o tmp/objs/Cedar/NullLan.o tmp/objs/Cedar/Protocol.o tmp/objs/Cedar/Remote.o tmp/objs/Cedar/Sam.o tmp/objs/Cedar/SecureNAT.o tmp/objs/Cedar/Server.o tmp/objs/Cedar/Session.o tmp/objs/Cedar/SM.o tmp/objs/Cedar/TcpIp.o tmp/objs/Cedar/UT.o tmp/objs/Cedar/Virtual.o tmp/objs/Cedar/VLan.o tmp/objs/Cedar/VLanUnix.o tmp/objs/Cedar/VLanWin32.o tmp/objs/Cedar/WinUi.o
+
+# Build Action
+default:       build
+
+build: $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) output/ham/ham output/utvpnserver/utvpnserver output/utvpnclient/utvpnclient output/utvpncmd/utvpncmd
+
+# Mayaqua Kernel Code
+tmp/objs/Mayaqua/Cfg.o: src/Mayaqua/Cfg.c $(HEADERS_MAYAQUA)
+       @mkdir -p tmp/
+       @mkdir -p tmp/objs/
+       @mkdir -p tmp/objs/Mayaqua/
+       @mkdir -p tmp/objs/Cedar/
+       @mkdir -p tmp/as/
+       @mkdir -p output/
+       @mkdir -p output/ham/
+       @mkdir -p output/utvpnserver/
+       @mkdir -p output/utvpnclient/
+       @mkdir -p output/utvpncmd/
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Cfg.c -o tmp/objs/Mayaqua/Cfg.o
+
+tmp/objs/Mayaqua/Encrypt.o: src/Mayaqua/Encrypt.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Encrypt.c -o tmp/objs/Mayaqua/Encrypt.o
+
+tmp/objs/Mayaqua/FileIO.o: src/Mayaqua/FileIO.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/FileIO.c -o tmp/objs/Mayaqua/FileIO.o
+
+tmp/objs/Mayaqua/Internat.o: src/Mayaqua/Internat.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Internat.c -o tmp/objs/Mayaqua/Internat.o
+
+tmp/objs/Mayaqua/Kernel.o: src/Mayaqua/Kernel.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Kernel.c -o tmp/objs/Mayaqua/Kernel.o
+
+tmp/objs/Mayaqua/Mayaqua.o: src/Mayaqua/Mayaqua.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Mayaqua.c -o tmp/objs/Mayaqua/Mayaqua.o
+
+tmp/objs/Mayaqua/Memory.o: src/Mayaqua/Memory.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Memory.c -o tmp/objs/Mayaqua/Memory.o
+
+tmp/objs/Mayaqua/Microsoft.o: src/Mayaqua/Microsoft.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Microsoft.c -o tmp/objs/Mayaqua/Microsoft.o
+
+tmp/objs/Mayaqua/Network.o: src/Mayaqua/Network.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Network.c -o tmp/objs/Mayaqua/Network.o
+
+tmp/objs/Mayaqua/Object.o: src/Mayaqua/Object.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Object.c -o tmp/objs/Mayaqua/Object.o
+
+tmp/objs/Mayaqua/OS.o: src/Mayaqua/OS.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/OS.c -o tmp/objs/Mayaqua/OS.o
+
+tmp/objs/Mayaqua/Pack.o: src/Mayaqua/Pack.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Pack.c -o tmp/objs/Mayaqua/Pack.o
+
+tmp/objs/Mayaqua/Secure.o: src/Mayaqua/Secure.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Secure.c -o tmp/objs/Mayaqua/Secure.o
+
+tmp/objs/Mayaqua/Str.o: src/Mayaqua/Str.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Str.c -o tmp/objs/Mayaqua/Str.o
+
+tmp/objs/Mayaqua/Table.o: src/Mayaqua/Table.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Table.c -o tmp/objs/Mayaqua/Table.o
+
+tmp/objs/Mayaqua/Tick64.o: src/Mayaqua/Tick64.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tick64.c -o tmp/objs/Mayaqua/Tick64.o
+
+tmp/objs/Mayaqua/Tracking.o: src/Mayaqua/Tracking.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tracking.c -o tmp/objs/Mayaqua/Tracking.o
+
+tmp/objs/Mayaqua/Unix.o: src/Mayaqua/Unix.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Unix.c -o tmp/objs/Mayaqua/Unix.o
+
+tmp/objs/Mayaqua/Win32.o: src/Mayaqua/Win32.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Win32.c -o tmp/objs/Mayaqua/Win32.o
+
+# Cedar Communication Module Code
+tmp/objs/Cedar/Account.o: src/Cedar/Account.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Account.c -o tmp/objs/Cedar/Account.o
+
+tmp/objs/Cedar/Admin.o: src/Cedar/Admin.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Admin.c -o tmp/objs/Cedar/Admin.o
+
+tmp/objs/Cedar/Bridge.o: src/Cedar/Bridge.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) src/Cedar/BridgeUnix.c
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Bridge.c -o tmp/objs/Cedar/Bridge.o
+
+tmp/objs/Cedar/BridgeUnix.o: src/Cedar/BridgeUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeUnix.c -o tmp/objs/Cedar/BridgeUnix.o
+
+tmp/objs/Cedar/BridgeWin32.o: src/Cedar/BridgeWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeWin32.c -o tmp/objs/Cedar/BridgeWin32.o
+
+tmp/objs/Cedar/Cedar.o: src/Cedar/Cedar.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Cedar.c -o tmp/objs/Cedar/Cedar.o
+
+tmp/objs/Cedar/CedarPch.o: src/Cedar/CedarPch.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CedarPch.c -o tmp/objs/Cedar/CedarPch.o
+
+tmp/objs/Cedar/Client.o: src/Cedar/Client.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Client.c -o tmp/objs/Cedar/Client.o
+
+tmp/objs/Cedar/CM.o: src/Cedar/CM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CM.c -o tmp/objs/Cedar/CM.o
+
+tmp/objs/Cedar/Command.o: src/Cedar/Command.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Command.c -o tmp/objs/Cedar/Command.o
+
+tmp/objs/Cedar/Connection.o: src/Cedar/Connection.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Connection.c -o tmp/objs/Cedar/Connection.o
+
+tmp/objs/Cedar/Console.o: src/Cedar/Console.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Console.c -o tmp/objs/Cedar/Console.o
+
+tmp/objs/Cedar/Database.o: src/Cedar/Database.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Database.c -o tmp/objs/Cedar/Database.o
+
+tmp/objs/Cedar/Hub.o: src/Cedar/Hub.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Hub.c -o tmp/objs/Cedar/Hub.o
+
+tmp/objs/Cedar/Layer3.o: src/Cedar/Layer3.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Layer3.c -o tmp/objs/Cedar/Layer3.o
+
+tmp/objs/Cedar/Link.o: src/Cedar/Link.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Link.c -o tmp/objs/Cedar/Link.o
+
+tmp/objs/Cedar/Listener.o: src/Cedar/Listener.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Listener.c -o tmp/objs/Cedar/Listener.o
+
+tmp/objs/Cedar/Logging.o: src/Cedar/Logging.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Logging.c -o tmp/objs/Cedar/Logging.o
+
+tmp/objs/Cedar/Nat.o: src/Cedar/Nat.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Nat.c -o tmp/objs/Cedar/Nat.o
+
+tmp/objs/Cedar/NM.o: src/Cedar/NM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NM.c -o tmp/objs/Cedar/NM.o
+
+tmp/objs/Cedar/NullLan.o: src/Cedar/NullLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NullLan.c -o tmp/objs/Cedar/NullLan.o
+
+tmp/objs/Cedar/Protocol.o: src/Cedar/Protocol.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Protocol.c -o tmp/objs/Cedar/Protocol.o
+
+tmp/objs/Cedar/Remote.o: src/Cedar/Remote.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Remote.c -o tmp/objs/Cedar/Remote.o
+
+tmp/objs/Cedar/Sam.o: src/Cedar/Sam.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Sam.c -o tmp/objs/Cedar/Sam.o
+
+tmp/objs/Cedar/SecureNAT.o: src/Cedar/SecureNAT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SecureNAT.c -o tmp/objs/Cedar/SecureNAT.o
+
+tmp/objs/Cedar/Server.o: src/Cedar/Server.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Server.c -o tmp/objs/Cedar/Server.o
+
+tmp/objs/Cedar/Session.o: src/Cedar/Session.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Session.c -o tmp/objs/Cedar/Session.o
+
+tmp/objs/Cedar/SM.o: src/Cedar/SM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SM.c -o tmp/objs/Cedar/SM.o
+
+tmp/objs/Cedar/TcpIp.o: src/Cedar/TcpIp.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/TcpIp.c -o tmp/objs/Cedar/TcpIp.o
+
+tmp/objs/Cedar/UT.o: src/Cedar/UT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/UT.c -o tmp/objs/Cedar/UT.o
+
+tmp/objs/Cedar/Virtual.o: src/Cedar/Virtual.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Virtual.c -o tmp/objs/Cedar/Virtual.o
+
+tmp/objs/Cedar/VLan.o: src/Cedar/VLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLan.c -o tmp/objs/Cedar/VLan.o
+
+tmp/objs/Cedar/VLanUnix.o: src/Cedar/VLanUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanUnix.c -o tmp/objs/Cedar/VLanUnix.o
+
+tmp/objs/Cedar/VLanWin32.o: src/Cedar/VLanWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanWin32.c -o tmp/objs/Cedar/VLanWin32.o
+
+tmp/objs/Cedar/WinUi.o: src/Cedar/WinUi.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/WinUi.c -o tmp/objs/Cedar/WinUi.o
+
+# Ham
+output/ham/ham: tmp/as/Ham.a output/ham/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/Ham.a $(OPTIONS_LINK) -o output/ham/ham
+
+tmp/as/Ham.a: tmp/objs/Ham.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/Ham.a
+       ar r tmp/as/Ham.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/Ham.o
+       ranlib tmp/as/Ham.a
+
+output/ham/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/ham/hamcore.utvpn
+
+tmp/objs/Ham.o: src/Ham/Ham.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Ham/Ham.c -o tmp/objs/Ham.o
+
+# utvpnserver
+output/utvpnserver/utvpnserver: tmp/as/utvpnserver.a output/utvpnserver/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnserver.a $(OPTIONS_LINK) -o output/utvpnserver/utvpnserver
+
+tmp/as/utvpnserver.a: tmp/objs/utvpnserver.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnserver.a
+       ar r tmp/as/utvpnserver.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnserver.o
+       ranlib tmp/as/utvpnserver.a
+
+output/utvpnserver/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnserver/hamcore.utvpn
+
+tmp/objs/utvpnserver.o: src/utvpnserver/utvpnserver.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnserver/utvpnserver.c -o tmp/objs/utvpnserver.o
+
+# utvpnclient
+output/utvpnclient/utvpnclient: tmp/as/utvpnclient.a output/utvpnclient/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnclient.a $(OPTIONS_LINK) -o output/utvpnclient/utvpnclient
+
+tmp/as/utvpnclient.a: tmp/objs/utvpnclient.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnclient.a
+       ar r tmp/as/utvpnclient.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnclient.o
+       ranlib tmp/as/utvpnclient.a
+
+output/utvpnclient/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnclient/hamcore.utvpn
+
+tmp/objs/utvpnclient.o: src/utvpnclient/utvpnclient.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnclient/utvpnclient.c -o tmp/objs/utvpnclient.o
+
+# utvpncmd
+output/utvpncmd/utvpncmd: tmp/as/utvpncmd.a output/utvpncmd/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpncmd.a $(OPTIONS_LINK) -o output/utvpncmd/utvpncmd
+
+tmp/as/utvpncmd.a: tmp/objs/utvpncmd.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpncmd.a
+       ar r tmp/as/utvpncmd.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpncmd.o
+       ranlib tmp/as/utvpncmd.a
+
+output/utvpncmd/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpncmd/hamcore.utvpn
+
+tmp/objs/utvpncmd.o: src/utvpncmd/utvpncmd.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpncmd/utvpncmd.c -o tmp/objs/utvpncmd.o
+
+# Install
+install: $(INSTALL_BINDIR)utvpnserver $(INSTALL_BINDIR)utvpnclient $(INSTALL_BINDIR)utvpncmd
+       @echo
+       @echo "--------------------------------------------------------------------"
+       @echo "Installation completed successfully."
+       @echo
+       @echo "Please execute 'utvpnserver start' to run UT-VPN Server Background Service."
+       @echo "Or please execute 'utvpnclient start' to run UT-VPN Client Background Service."
+       @echo "And please execute 'utvpncmd' to run UT-VPN Command-Line Utility to configure UT-Server or UT-VPN Client."
+       @echo "--------------------------------------------------------------------"
+       @echo
+
+$(INSTALL_BINDIR)utvpnserver: output/utvpnserver/hamcore.utvpn output/utvpnserver/utvpnserver
+       @mkdir -p $(INSTALL_UTVPNSERVER_DIR)
+       cp output/utvpnserver/hamcore.utvpn $(INSTALL_UTVPNSERVER_DIR)hamcore.utvpn
+       cp output/utvpnserver/utvpnserver $(INSTALL_UTVPNSERVER_DIR)utvpnserver
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnserver
+       echo $(INSTALL_UTVPNSERVER_DIR)utvpnserver '"$$@"' >> $(INSTALL_BINDIR)utvpnserver
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnserver
+       chmod 755 $(INSTALL_BINDIR)utvpnserver
+
+$(INSTALL_BINDIR)utvpnclient: output/utvpnclient/hamcore.utvpn output/utvpnclient/utvpnclient
+       @mkdir -p $(INSTALL_UTVPNCLIENT_DIR)
+       cp output/utvpnclient/hamcore.utvpn $(INSTALL_UTVPNCLIENT_DIR)hamcore.utvpn
+       cp output/utvpnclient/utvpnclient $(INSTALL_UTVPNCLIENT_DIR)utvpnclient
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnclient
+       echo $(INSTALL_UTVPNCLIENT_DIR)utvpnclient '"$$@"' >> $(INSTALL_BINDIR)utvpnclient
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnclient
+       chmod 755 $(INSTALL_BINDIR)utvpnclient
+
+$(INSTALL_BINDIR)utvpncmd: output/utvpncmd/hamcore.utvpn output/utvpncmd/utvpncmd
+       @mkdir -p $(INSTALL_UTVPNCMD_DIR)
+       cp output/utvpncmd/hamcore.utvpn $(INSTALL_UTVPNCMD_DIR)hamcore.utvpn
+       cp output/utvpncmd/utvpncmd $(INSTALL_UTVPNCMD_DIR)utvpncmd
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpncmd
+       echo $(INSTALL_UTVPNCMD_DIR)utvpncmd '"$$@"' >> $(INSTALL_BINDIR)utvpncmd
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpncmd
+       chmod 755 $(INSTALL_BINDIR)utvpncmd
+
+# Clean
+clean:
+       -rm -f $(OBJECTS_MAYAQUA)
+       -rm -f $(OBJECTS_CEDAR)
+       -rm -f tmp/objs/Ham.o
+       -rm -f tmp/as/Ham.a
+       -rm -f output/ham/ham
+       -rm -f tmp/objs/utvpnserver.o
+       -rm -f tmp/as/utvpnserver.a
+       -rm -f output/utvpnserver/utvpnserver
+       -rm -f tmp/objs/utvpnclient.o
+       -rm -f tmp/as/utvpnclient.a
+       -rm -f output/utvpnclient/utvpnclient
+       -rm -f tmp/objs/utvpncmd.o
+       -rm -f tmp/as/utvpncmd.a
+       -rm -f output/utvpncmd/utvpncmd
+
+# Help Strings
+help:
+       @echo "make [DEBUG=YES]"
+
diff --git a/utvpn/utvpn-unix-v101-7101-public/makefiles/solaris_32bit_ja.mak b/utvpn/utvpn-unix-v101-7101-public/makefiles/solaris_32bit_ja.mak
new file mode 100644 (file)
index 0000000..ad2c62f
--- /dev/null
@@ -0,0 +1,353 @@
+# SoftEther UT-VPN SourceCode
+# 
+# Copyright (C) 2004-2010 SoftEther Corporation.
+# Copyright (C) 2004-2010 University of Tsukuba, Japan.
+# Copyright (C) 2003-2010 Daiyuu Nobori.
+# All Rights Reserved.
+# 
+# http://utvpn.tsukuba.ac.jp/
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License version 2
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# 
+# Platform: os=Solaris, bits=32bit, language=Japanese
+
+# Variables
+CC=gcc
+
+OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_SOLARIS -DNO_VLAN -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char
+
+OPTIONS_LINK_DEBUG=-g -fsigned-char -lm -lrt -lnsl -lsocket -ldl -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz
+
+OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_SOLARIS -DNO_VLAN -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char
+
+OPTIONS_LINK_RELEASE=-O2 -fsigned-char -lm -lrt -lnsl -lsocket -ldl -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz
+
+INSTALL_BINDIR=/usr/bin/
+INSTALL_UTVPNSERVER_DIR=/usr/utvpnserver/
+INSTALL_UTVPNCLIENT_DIR=/usr/utvpnclient/
+INSTALL_UTVPNCMD_DIR=/usr/utvpncmd/
+
+ifeq ($(DEBUG),YES)
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_DEBUG)
+       OPTIONS_LINK=$(OPTIONS_LINK_DEBUG)
+else
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_RELEASE)
+       OPTIONS_LINK=$(OPTIONS_LINK_RELEASE)
+endif
+
+# Files
+HEADERS_MAYAQUA=src/Mayaqua/Cfg.h src/Mayaqua/cryptoki.h src/Mayaqua/Encrypt.h src/Mayaqua/FileIO.h src/Mayaqua/Internat.h src/Mayaqua/Kernel.h src/Mayaqua/Mayaqua.h src/Mayaqua/MayaType.h src/Mayaqua/Memory.h src/Mayaqua/Microsoft.h src/Mayaqua/Network.h src/Mayaqua/Object.h src/Mayaqua/openssl/aes.h src/Mayaqua/openssl/asn1.h src/Mayaqua/openssl/asn1_mac.h src/Mayaqua/openssl/asn1t.h src/Mayaqua/openssl/bio.h src/Mayaqua/openssl/blowfish.h src/Mayaqua/openssl/bn.h src/Mayaqua/openssl/buffer.h src/Mayaqua/openssl/cast.h src/Mayaqua/openssl/comp.h src/Mayaqua/openssl/conf.h src/Mayaqua/openssl/conf_api.h src/Mayaqua/openssl/crypto.h src/Mayaqua/openssl/des.h src/Mayaqua/openssl/des_old.h src/Mayaqua/openssl/dh.h src/Mayaqua/openssl/dsa.h src/Mayaqua/openssl/dso.h src/Mayaqua/openssl/dtls1.h src/Mayaqua/openssl/e_os2.h src/Mayaqua/openssl/ebcdic.h src/Mayaqua/openssl/ec.h src/Mayaqua/openssl/ecdh.h src/Mayaqua/openssl/ecdsa.h src/Mayaqua/openssl/engine.h src/Mayaqua/openssl/err.h src/Mayaqua/openssl/evp.h src/Mayaqua/openssl/fips.h src/Mayaqua/openssl/fips_rand.h src/Mayaqua/openssl/hmac.h src/Mayaqua/openssl/idea.h src/Mayaqua/openssl/krb5_asn.h src/Mayaqua/openssl/kssl.h src/Mayaqua/openssl/lhash.h src/Mayaqua/openssl/md2.h src/Mayaqua/openssl/md4.h src/Mayaqua/openssl/md5.h src/Mayaqua/openssl/mdc2.h src/Mayaqua/openssl/obj_mac.h src/Mayaqua/openssl/objects.h src/Mayaqua/openssl/ocsp.h src/Mayaqua/openssl/opensslconf.h src/Mayaqua/openssl/opensslv.h src/Mayaqua/openssl/ossl_typ.h src/Mayaqua/openssl/pem.h src/Mayaqua/openssl/pem2.h src/Mayaqua/openssl/pkcs12.h src/Mayaqua/openssl/pkcs7.h src/Mayaqua/openssl/pq_compat.h src/Mayaqua/openssl/pqueue.h src/Mayaqua/openssl/rand.h src/Mayaqua/openssl/rc2.h src/Mayaqua/openssl/rc4.h src/Mayaqua/openssl/rc5.h src/Mayaqua/openssl/ripemd.h src/Mayaqua/openssl/rsa.h src/Mayaqua/openssl/safestack.h src/Mayaqua/openssl/sha.h src/Mayaqua/openssl/ssl.h src/Mayaqua/openssl/ssl2.h src/Mayaqua/openssl/ssl23.h src/Mayaqua/openssl/ssl3.h src/Mayaqua/openssl/stack.h src/Mayaqua/openssl/store.h src/Mayaqua/openssl/symhacks.h src/Mayaqua/openssl/tls1.h src/Mayaqua/openssl/tmdiff.h src/Mayaqua/openssl/txt_db.h src/Mayaqua/openssl/ui.h src/Mayaqua/openssl/ui_compat.h src/Mayaqua/openssl/x509.h src/Mayaqua/openssl/x509_vfy.h src/Mayaqua/openssl/x509v3.h src/Mayaqua/OS.h src/Mayaqua/Pack.h src/Mayaqua/pkcs11.h src/Mayaqua/pkcs11f.h src/Mayaqua/pkcs11t.h src/Mayaqua/Secure.h src/Mayaqua/Str.h src/Mayaqua/Table.h src/Mayaqua/Tick64.h src/Mayaqua/Tracking.h src/Mayaqua/TunTap.h src/Mayaqua/Unix.h src/Mayaqua/Win32.h src/Mayaqua/zlib/zconf.h src/Mayaqua/zlib/zlib.h
+HEADERS_CEDAR=src/Cedar/Account.h src/Cedar/Admin.h src/Cedar/Bridge.h src/Cedar/BridgeUnix.h src/Cedar/BridgeWin32.h src/Cedar/Cedar.h src/Cedar/CedarPch.h src/Cedar/CedarType.h src/Cedar/Client.h src/Cedar/CM.h src/Cedar/CMInner.h src/Cedar/Command.h src/Cedar/Connection.h src/Cedar/Console.h src/Cedar/Database.h src/Cedar/Hub.h src/Cedar/Layer3.h src/Cedar/Link.h src/Cedar/Listener.h src/Cedar/Logging.h src/Cedar/Nat.h src/Cedar/NM.h src/Cedar/NMInner.h src/Cedar/NullLan.h src/Cedar/Protocol.h src/Cedar/Remote.h src/Cedar/Sam.h src/Cedar/SecureNAT.h src/Cedar/Server.h src/Cedar/Session.h src/Cedar/SM.h src/Cedar/SMInner.h src/Cedar/TcpIp.h src/Cedar/UT.h src/Cedar/Virtual.h src/Cedar/VLan.h src/Cedar/VLanUnix.h src/Cedar/VLanWin32.h src/Cedar/Win32Html.h src/Cedar/WinUi.h
+OBJECTS_MAYAQUA=tmp/objs/Mayaqua/Cfg.o tmp/objs/Mayaqua/Encrypt.o tmp/objs/Mayaqua/FileIO.o tmp/objs/Mayaqua/Internat.o tmp/objs/Mayaqua/Kernel.o tmp/objs/Mayaqua/Mayaqua.o tmp/objs/Mayaqua/Memory.o tmp/objs/Mayaqua/Microsoft.o tmp/objs/Mayaqua/Network.o tmp/objs/Mayaqua/Object.o tmp/objs/Mayaqua/OS.o tmp/objs/Mayaqua/Pack.o tmp/objs/Mayaqua/Secure.o tmp/objs/Mayaqua/Str.o tmp/objs/Mayaqua/Table.o tmp/objs/Mayaqua/Tick64.o tmp/objs/Mayaqua/Tracking.o tmp/objs/Mayaqua/Unix.o tmp/objs/Mayaqua/Win32.o
+OBJECTS_CEDAR=tmp/objs/Cedar/Account.o tmp/objs/Cedar/Admin.o tmp/objs/Cedar/Bridge.o tmp/objs/Cedar/BridgeUnix.o tmp/objs/Cedar/BridgeWin32.o tmp/objs/Cedar/Cedar.o tmp/objs/Cedar/CedarPch.o tmp/objs/Cedar/Client.o tmp/objs/Cedar/CM.o tmp/objs/Cedar/Command.o tmp/objs/Cedar/Connection.o tmp/objs/Cedar/Console.o tmp/objs/Cedar/Database.o tmp/objs/Cedar/Hub.o tmp/objs/Cedar/Layer3.o tmp/objs/Cedar/Link.o tmp/objs/Cedar/Listener.o tmp/objs/Cedar/Logging.o tmp/objs/Cedar/Nat.o tmp/objs/Cedar/NM.o tmp/objs/Cedar/NullLan.o tmp/objs/Cedar/Protocol.o tmp/objs/Cedar/Remote.o tmp/objs/Cedar/Sam.o tmp/objs/Cedar/SecureNAT.o tmp/objs/Cedar/Server.o tmp/objs/Cedar/Session.o tmp/objs/Cedar/SM.o tmp/objs/Cedar/TcpIp.o tmp/objs/Cedar/UT.o tmp/objs/Cedar/Virtual.o tmp/objs/Cedar/VLan.o tmp/objs/Cedar/VLanUnix.o tmp/objs/Cedar/VLanWin32.o tmp/objs/Cedar/WinUi.o
+
+# Build Action
+default:       build
+
+build: $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) output/ham/ham output/utvpnserver/utvpnserver output/utvpnclient/utvpnclient output/utvpncmd/utvpncmd
+
+# Mayaqua Kernel Code
+tmp/objs/Mayaqua/Cfg.o: src/Mayaqua/Cfg.c $(HEADERS_MAYAQUA)
+       @mkdir -p tmp/
+       @mkdir -p tmp/objs/
+       @mkdir -p tmp/objs/Mayaqua/
+       @mkdir -p tmp/objs/Cedar/
+       @mkdir -p tmp/as/
+       @mkdir -p output/
+       @mkdir -p output/ham/
+       @mkdir -p output/utvpnserver/
+       @mkdir -p output/utvpnclient/
+       @mkdir -p output/utvpncmd/
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Cfg.c -o tmp/objs/Mayaqua/Cfg.o
+
+tmp/objs/Mayaqua/Encrypt.o: src/Mayaqua/Encrypt.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Encrypt.c -o tmp/objs/Mayaqua/Encrypt.o
+
+tmp/objs/Mayaqua/FileIO.o: src/Mayaqua/FileIO.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/FileIO.c -o tmp/objs/Mayaqua/FileIO.o
+
+tmp/objs/Mayaqua/Internat.o: src/Mayaqua/Internat.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Internat.c -o tmp/objs/Mayaqua/Internat.o
+
+tmp/objs/Mayaqua/Kernel.o: src/Mayaqua/Kernel.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Kernel.c -o tmp/objs/Mayaqua/Kernel.o
+
+tmp/objs/Mayaqua/Mayaqua.o: src/Mayaqua/Mayaqua.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Mayaqua.c -o tmp/objs/Mayaqua/Mayaqua.o
+
+tmp/objs/Mayaqua/Memory.o: src/Mayaqua/Memory.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Memory.c -o tmp/objs/Mayaqua/Memory.o
+
+tmp/objs/Mayaqua/Microsoft.o: src/Mayaqua/Microsoft.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Microsoft.c -o tmp/objs/Mayaqua/Microsoft.o
+
+tmp/objs/Mayaqua/Network.o: src/Mayaqua/Network.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Network.c -o tmp/objs/Mayaqua/Network.o
+
+tmp/objs/Mayaqua/Object.o: src/Mayaqua/Object.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Object.c -o tmp/objs/Mayaqua/Object.o
+
+tmp/objs/Mayaqua/OS.o: src/Mayaqua/OS.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/OS.c -o tmp/objs/Mayaqua/OS.o
+
+tmp/objs/Mayaqua/Pack.o: src/Mayaqua/Pack.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Pack.c -o tmp/objs/Mayaqua/Pack.o
+
+tmp/objs/Mayaqua/Secure.o: src/Mayaqua/Secure.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Secure.c -o tmp/objs/Mayaqua/Secure.o
+
+tmp/objs/Mayaqua/Str.o: src/Mayaqua/Str.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Str.c -o tmp/objs/Mayaqua/Str.o
+
+tmp/objs/Mayaqua/Table.o: src/Mayaqua/Table.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Table.c -o tmp/objs/Mayaqua/Table.o
+
+tmp/objs/Mayaqua/Tick64.o: src/Mayaqua/Tick64.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tick64.c -o tmp/objs/Mayaqua/Tick64.o
+
+tmp/objs/Mayaqua/Tracking.o: src/Mayaqua/Tracking.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tracking.c -o tmp/objs/Mayaqua/Tracking.o
+
+tmp/objs/Mayaqua/Unix.o: src/Mayaqua/Unix.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Unix.c -o tmp/objs/Mayaqua/Unix.o
+
+tmp/objs/Mayaqua/Win32.o: src/Mayaqua/Win32.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Win32.c -o tmp/objs/Mayaqua/Win32.o
+
+# Cedar Communication Module Code
+tmp/objs/Cedar/Account.o: src/Cedar/Account.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Account.c -o tmp/objs/Cedar/Account.o
+
+tmp/objs/Cedar/Admin.o: src/Cedar/Admin.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Admin.c -o tmp/objs/Cedar/Admin.o
+
+tmp/objs/Cedar/Bridge.o: src/Cedar/Bridge.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) src/Cedar/BridgeUnix.c
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Bridge.c -o tmp/objs/Cedar/Bridge.o
+
+tmp/objs/Cedar/BridgeUnix.o: src/Cedar/BridgeUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeUnix.c -o tmp/objs/Cedar/BridgeUnix.o
+
+tmp/objs/Cedar/BridgeWin32.o: src/Cedar/BridgeWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeWin32.c -o tmp/objs/Cedar/BridgeWin32.o
+
+tmp/objs/Cedar/Cedar.o: src/Cedar/Cedar.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Cedar.c -o tmp/objs/Cedar/Cedar.o
+
+tmp/objs/Cedar/CedarPch.o: src/Cedar/CedarPch.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CedarPch.c -o tmp/objs/Cedar/CedarPch.o
+
+tmp/objs/Cedar/Client.o: src/Cedar/Client.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Client.c -o tmp/objs/Cedar/Client.o
+
+tmp/objs/Cedar/CM.o: src/Cedar/CM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CM.c -o tmp/objs/Cedar/CM.o
+
+tmp/objs/Cedar/Command.o: src/Cedar/Command.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Command.c -o tmp/objs/Cedar/Command.o
+
+tmp/objs/Cedar/Connection.o: src/Cedar/Connection.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Connection.c -o tmp/objs/Cedar/Connection.o
+
+tmp/objs/Cedar/Console.o: src/Cedar/Console.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Console.c -o tmp/objs/Cedar/Console.o
+
+tmp/objs/Cedar/Database.o: src/Cedar/Database.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Database.c -o tmp/objs/Cedar/Database.o
+
+tmp/objs/Cedar/Hub.o: src/Cedar/Hub.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Hub.c -o tmp/objs/Cedar/Hub.o
+
+tmp/objs/Cedar/Layer3.o: src/Cedar/Layer3.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Layer3.c -o tmp/objs/Cedar/Layer3.o
+
+tmp/objs/Cedar/Link.o: src/Cedar/Link.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Link.c -o tmp/objs/Cedar/Link.o
+
+tmp/objs/Cedar/Listener.o: src/Cedar/Listener.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Listener.c -o tmp/objs/Cedar/Listener.o
+
+tmp/objs/Cedar/Logging.o: src/Cedar/Logging.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Logging.c -o tmp/objs/Cedar/Logging.o
+
+tmp/objs/Cedar/Nat.o: src/Cedar/Nat.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Nat.c -o tmp/objs/Cedar/Nat.o
+
+tmp/objs/Cedar/NM.o: src/Cedar/NM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NM.c -o tmp/objs/Cedar/NM.o
+
+tmp/objs/Cedar/NullLan.o: src/Cedar/NullLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NullLan.c -o tmp/objs/Cedar/NullLan.o
+
+tmp/objs/Cedar/Protocol.o: src/Cedar/Protocol.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Protocol.c -o tmp/objs/Cedar/Protocol.o
+
+tmp/objs/Cedar/Remote.o: src/Cedar/Remote.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Remote.c -o tmp/objs/Cedar/Remote.o
+
+tmp/objs/Cedar/Sam.o: src/Cedar/Sam.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Sam.c -o tmp/objs/Cedar/Sam.o
+
+tmp/objs/Cedar/SecureNAT.o: src/Cedar/SecureNAT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SecureNAT.c -o tmp/objs/Cedar/SecureNAT.o
+
+tmp/objs/Cedar/Server.o: src/Cedar/Server.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Server.c -o tmp/objs/Cedar/Server.o
+
+tmp/objs/Cedar/Session.o: src/Cedar/Session.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Session.c -o tmp/objs/Cedar/Session.o
+
+tmp/objs/Cedar/SM.o: src/Cedar/SM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SM.c -o tmp/objs/Cedar/SM.o
+
+tmp/objs/Cedar/TcpIp.o: src/Cedar/TcpIp.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/TcpIp.c -o tmp/objs/Cedar/TcpIp.o
+
+tmp/objs/Cedar/UT.o: src/Cedar/UT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/UT.c -o tmp/objs/Cedar/UT.o
+
+tmp/objs/Cedar/Virtual.o: src/Cedar/Virtual.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Virtual.c -o tmp/objs/Cedar/Virtual.o
+
+tmp/objs/Cedar/VLan.o: src/Cedar/VLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLan.c -o tmp/objs/Cedar/VLan.o
+
+tmp/objs/Cedar/VLanUnix.o: src/Cedar/VLanUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanUnix.c -o tmp/objs/Cedar/VLanUnix.o
+
+tmp/objs/Cedar/VLanWin32.o: src/Cedar/VLanWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanWin32.c -o tmp/objs/Cedar/VLanWin32.o
+
+tmp/objs/Cedar/WinUi.o: src/Cedar/WinUi.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/WinUi.c -o tmp/objs/Cedar/WinUi.o
+
+# Ham
+output/ham/ham: tmp/as/Ham.a output/ham/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/Ham.a $(OPTIONS_LINK) -o output/ham/ham
+
+tmp/as/Ham.a: tmp/objs/Ham.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/Ham.a
+       ar r tmp/as/Ham.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/Ham.o
+       ranlib tmp/as/Ham.a
+
+output/ham/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/ham/hamcore.utvpn
+
+tmp/objs/Ham.o: src/Ham/Ham.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Ham/Ham.c -o tmp/objs/Ham.o
+
+# utvpnserver
+output/utvpnserver/utvpnserver: tmp/as/utvpnserver.a output/utvpnserver/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnserver.a $(OPTIONS_LINK) -o output/utvpnserver/utvpnserver
+
+tmp/as/utvpnserver.a: tmp/objs/utvpnserver.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnserver.a
+       ar r tmp/as/utvpnserver.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnserver.o
+       ranlib tmp/as/utvpnserver.a
+
+output/utvpnserver/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnserver/hamcore.utvpn
+
+tmp/objs/utvpnserver.o: src/utvpnserver/utvpnserver.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnserver/utvpnserver.c -o tmp/objs/utvpnserver.o
+
+# utvpnclient
+output/utvpnclient/utvpnclient: tmp/as/utvpnclient.a output/utvpnclient/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnclient.a $(OPTIONS_LINK) -o output/utvpnclient/utvpnclient
+
+tmp/as/utvpnclient.a: tmp/objs/utvpnclient.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnclient.a
+       ar r tmp/as/utvpnclient.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnclient.o
+       ranlib tmp/as/utvpnclient.a
+
+output/utvpnclient/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnclient/hamcore.utvpn
+
+tmp/objs/utvpnclient.o: src/utvpnclient/utvpnclient.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnclient/utvpnclient.c -o tmp/objs/utvpnclient.o
+
+# utvpncmd
+output/utvpncmd/utvpncmd: tmp/as/utvpncmd.a output/utvpncmd/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpncmd.a $(OPTIONS_LINK) -o output/utvpncmd/utvpncmd
+
+tmp/as/utvpncmd.a: tmp/objs/utvpncmd.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpncmd.a
+       ar r tmp/as/utvpncmd.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpncmd.o
+       ranlib tmp/as/utvpncmd.a
+
+output/utvpncmd/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpncmd/hamcore.utvpn
+
+tmp/objs/utvpncmd.o: src/utvpncmd/utvpncmd.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpncmd/utvpncmd.c -o tmp/objs/utvpncmd.o
+
+# Install
+install: $(INSTALL_BINDIR)utvpnserver $(INSTALL_BINDIR)utvpnclient $(INSTALL_BINDIR)utvpncmd
+       @echo
+       @echo "--------------------------------------------------------------------"
+       @echo "Installation completed successfully."
+       @echo
+       @echo "Please execute 'utvpnserver start' to run UT-VPN Server Background Service."
+       @echo "Or please execute 'utvpnclient start' to run UT-VPN Client Background Service."
+       @echo "And please execute 'utvpncmd' to run UT-VPN Command-Line Utility to configure UT-Server or UT-VPN Client."
+       @echo "--------------------------------------------------------------------"
+       @echo
+
+$(INSTALL_BINDIR)utvpnserver: output/utvpnserver/hamcore.utvpn output/utvpnserver/utvpnserver
+       @mkdir -p $(INSTALL_UTVPNSERVER_DIR)
+       cp output/utvpnserver/hamcore.utvpn $(INSTALL_UTVPNSERVER_DIR)hamcore.utvpn
+       cp output/utvpnserver/utvpnserver $(INSTALL_UTVPNSERVER_DIR)utvpnserver
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnserver
+       echo $(INSTALL_UTVPNSERVER_DIR)utvpnserver '"$$@"' >> $(INSTALL_BINDIR)utvpnserver
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnserver
+       chmod 755 $(INSTALL_BINDIR)utvpnserver
+
+$(INSTALL_BINDIR)utvpnclient: output/utvpnclient/hamcore.utvpn output/utvpnclient/utvpnclient
+       @mkdir -p $(INSTALL_UTVPNCLIENT_DIR)
+       cp output/utvpnclient/hamcore.utvpn $(INSTALL_UTVPNCLIENT_DIR)hamcore.utvpn
+       cp output/utvpnclient/utvpnclient $(INSTALL_UTVPNCLIENT_DIR)utvpnclient
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnclient
+       echo $(INSTALL_UTVPNCLIENT_DIR)utvpnclient '"$$@"' >> $(INSTALL_BINDIR)utvpnclient
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnclient
+       chmod 755 $(INSTALL_BINDIR)utvpnclient
+
+$(INSTALL_BINDIR)utvpncmd: output/utvpncmd/hamcore.utvpn output/utvpncmd/utvpncmd
+       @mkdir -p $(INSTALL_UTVPNCMD_DIR)
+       cp output/utvpncmd/hamcore.utvpn $(INSTALL_UTVPNCMD_DIR)hamcore.utvpn
+       cp output/utvpncmd/utvpncmd $(INSTALL_UTVPNCMD_DIR)utvpncmd
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpncmd
+       echo $(INSTALL_UTVPNCMD_DIR)utvpncmd '"$$@"' >> $(INSTALL_BINDIR)utvpncmd
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpncmd
+       chmod 755 $(INSTALL_BINDIR)utvpncmd
+
+# Clean
+clean:
+       -rm -f $(OBJECTS_MAYAQUA)
+       -rm -f $(OBJECTS_CEDAR)
+       -rm -f tmp/objs/Ham.o
+       -rm -f tmp/as/Ham.a
+       -rm -f output/ham/ham
+       -rm -f tmp/objs/utvpnserver.o
+       -rm -f tmp/as/utvpnserver.a
+       -rm -f output/utvpnserver/utvpnserver
+       -rm -f tmp/objs/utvpnclient.o
+       -rm -f tmp/as/utvpnclient.a
+       -rm -f output/utvpnclient/utvpnclient
+       -rm -f tmp/objs/utvpncmd.o
+       -rm -f tmp/as/utvpncmd.a
+       -rm -f output/utvpncmd/utvpncmd
+
+# Help Strings
+help:
+       @echo "make [DEBUG=YES]"
+
diff --git a/utvpn/utvpn-unix-v101-7101-public/makefiles/solaris_64bit_ja.mak b/utvpn/utvpn-unix-v101-7101-public/makefiles/solaris_64bit_ja.mak
new file mode 100644 (file)
index 0000000..b3def06
--- /dev/null
@@ -0,0 +1,353 @@
+# SoftEther UT-VPN SourceCode
+# 
+# Copyright (C) 2004-2010 SoftEther Corporation.
+# Copyright (C) 2004-2010 University of Tsukuba, Japan.
+# Copyright (C) 2003-2010 Daiyuu Nobori.
+# All Rights Reserved.
+# 
+# http://utvpn.tsukuba.ac.jp/
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License version 2
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# 
+# Platform: os=Solaris, bits=64bit, language=Japanese
+
+# Variables
+CC=gcc
+
+OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_SOLARIS -DNO_VLAN -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char -m64
+
+OPTIONS_LINK_DEBUG=-g -fsigned-char -m64 -lm -lrt -lnsl -lsocket -ldl -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz
+
+OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_SOLARIS -DNO_VLAN -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char -m64
+
+OPTIONS_LINK_RELEASE=-O2 -fsigned-char -m64 -lm -lrt -lnsl -lsocket -ldl -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz
+
+INSTALL_BINDIR=/usr/bin/
+INSTALL_UTVPNSERVER_DIR=/usr/utvpnserver/
+INSTALL_UTVPNCLIENT_DIR=/usr/utvpnclient/
+INSTALL_UTVPNCMD_DIR=/usr/utvpncmd/
+
+ifeq ($(DEBUG),YES)
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_DEBUG)
+       OPTIONS_LINK=$(OPTIONS_LINK_DEBUG)
+else
+       OPTIONS_COMPILE=$(OPTIONS_COMPILE_RELEASE)
+       OPTIONS_LINK=$(OPTIONS_LINK_RELEASE)
+endif
+
+# Files
+HEADERS_MAYAQUA=src/Mayaqua/Cfg.h src/Mayaqua/cryptoki.h src/Mayaqua/Encrypt.h src/Mayaqua/FileIO.h src/Mayaqua/Internat.h src/Mayaqua/Kernel.h src/Mayaqua/Mayaqua.h src/Mayaqua/MayaType.h src/Mayaqua/Memory.h src/Mayaqua/Microsoft.h src/Mayaqua/Network.h src/Mayaqua/Object.h src/Mayaqua/openssl/aes.h src/Mayaqua/openssl/asn1.h src/Mayaqua/openssl/asn1_mac.h src/Mayaqua/openssl/asn1t.h src/Mayaqua/openssl/bio.h src/Mayaqua/openssl/blowfish.h src/Mayaqua/openssl/bn.h src/Mayaqua/openssl/buffer.h src/Mayaqua/openssl/cast.h src/Mayaqua/openssl/comp.h src/Mayaqua/openssl/conf.h src/Mayaqua/openssl/conf_api.h src/Mayaqua/openssl/crypto.h src/Mayaqua/openssl/des.h src/Mayaqua/openssl/des_old.h src/Mayaqua/openssl/dh.h src/Mayaqua/openssl/dsa.h src/Mayaqua/openssl/dso.h src/Mayaqua/openssl/dtls1.h src/Mayaqua/openssl/e_os2.h src/Mayaqua/openssl/ebcdic.h src/Mayaqua/openssl/ec.h src/Mayaqua/openssl/ecdh.h src/Mayaqua/openssl/ecdsa.h src/Mayaqua/openssl/engine.h src/Mayaqua/openssl/err.h src/Mayaqua/openssl/evp.h src/Mayaqua/openssl/fips.h src/Mayaqua/openssl/fips_rand.h src/Mayaqua/openssl/hmac.h src/Mayaqua/openssl/idea.h src/Mayaqua/openssl/krb5_asn.h src/Mayaqua/openssl/kssl.h src/Mayaqua/openssl/lhash.h src/Mayaqua/openssl/md2.h src/Mayaqua/openssl/md4.h src/Mayaqua/openssl/md5.h src/Mayaqua/openssl/mdc2.h src/Mayaqua/openssl/obj_mac.h src/Mayaqua/openssl/objects.h src/Mayaqua/openssl/ocsp.h src/Mayaqua/openssl/opensslconf.h src/Mayaqua/openssl/opensslv.h src/Mayaqua/openssl/ossl_typ.h src/Mayaqua/openssl/pem.h src/Mayaqua/openssl/pem2.h src/Mayaqua/openssl/pkcs12.h src/Mayaqua/openssl/pkcs7.h src/Mayaqua/openssl/pq_compat.h src/Mayaqua/openssl/pqueue.h src/Mayaqua/openssl/rand.h src/Mayaqua/openssl/rc2.h src/Mayaqua/openssl/rc4.h src/Mayaqua/openssl/rc5.h src/Mayaqua/openssl/ripemd.h src/Mayaqua/openssl/rsa.h src/Mayaqua/openssl/safestack.h src/Mayaqua/openssl/sha.h src/Mayaqua/openssl/ssl.h src/Mayaqua/openssl/ssl2.h src/Mayaqua/openssl/ssl23.h src/Mayaqua/openssl/ssl3.h src/Mayaqua/openssl/stack.h src/Mayaqua/openssl/store.h src/Mayaqua/openssl/symhacks.h src/Mayaqua/openssl/tls1.h src/Mayaqua/openssl/tmdiff.h src/Mayaqua/openssl/txt_db.h src/Mayaqua/openssl/ui.h src/Mayaqua/openssl/ui_compat.h src/Mayaqua/openssl/x509.h src/Mayaqua/openssl/x509_vfy.h src/Mayaqua/openssl/x509v3.h src/Mayaqua/OS.h src/Mayaqua/Pack.h src/Mayaqua/pkcs11.h src/Mayaqua/pkcs11f.h src/Mayaqua/pkcs11t.h src/Mayaqua/Secure.h src/Mayaqua/Str.h src/Mayaqua/Table.h src/Mayaqua/Tick64.h src/Mayaqua/Tracking.h src/Mayaqua/TunTap.h src/Mayaqua/Unix.h src/Mayaqua/Win32.h src/Mayaqua/zlib/zconf.h src/Mayaqua/zlib/zlib.h
+HEADERS_CEDAR=src/Cedar/Account.h src/Cedar/Admin.h src/Cedar/Bridge.h src/Cedar/BridgeUnix.h src/Cedar/BridgeWin32.h src/Cedar/Cedar.h src/Cedar/CedarPch.h src/Cedar/CedarType.h src/Cedar/Client.h src/Cedar/CM.h src/Cedar/CMInner.h src/Cedar/Command.h src/Cedar/Connection.h src/Cedar/Console.h src/Cedar/Database.h src/Cedar/Hub.h src/Cedar/Layer3.h src/Cedar/Link.h src/Cedar/Listener.h src/Cedar/Logging.h src/Cedar/Nat.h src/Cedar/NM.h src/Cedar/NMInner.h src/Cedar/NullLan.h src/Cedar/Protocol.h src/Cedar/Remote.h src/Cedar/Sam.h src/Cedar/SecureNAT.h src/Cedar/Server.h src/Cedar/Session.h src/Cedar/SM.h src/Cedar/SMInner.h src/Cedar/TcpIp.h src/Cedar/UT.h src/Cedar/Virtual.h src/Cedar/VLan.h src/Cedar/VLanUnix.h src/Cedar/VLanWin32.h src/Cedar/Win32Html.h src/Cedar/WinUi.h
+OBJECTS_MAYAQUA=tmp/objs/Mayaqua/Cfg.o tmp/objs/Mayaqua/Encrypt.o tmp/objs/Mayaqua/FileIO.o tmp/objs/Mayaqua/Internat.o tmp/objs/Mayaqua/Kernel.o tmp/objs/Mayaqua/Mayaqua.o tmp/objs/Mayaqua/Memory.o tmp/objs/Mayaqua/Microsoft.o tmp/objs/Mayaqua/Network.o tmp/objs/Mayaqua/Object.o tmp/objs/Mayaqua/OS.o tmp/objs/Mayaqua/Pack.o tmp/objs/Mayaqua/Secure.o tmp/objs/Mayaqua/Str.o tmp/objs/Mayaqua/Table.o tmp/objs/Mayaqua/Tick64.o tmp/objs/Mayaqua/Tracking.o tmp/objs/Mayaqua/Unix.o tmp/objs/Mayaqua/Win32.o
+OBJECTS_CEDAR=tmp/objs/Cedar/Account.o tmp/objs/Cedar/Admin.o tmp/objs/Cedar/Bridge.o tmp/objs/Cedar/BridgeUnix.o tmp/objs/Cedar/BridgeWin32.o tmp/objs/Cedar/Cedar.o tmp/objs/Cedar/CedarPch.o tmp/objs/Cedar/Client.o tmp/objs/Cedar/CM.o tmp/objs/Cedar/Command.o tmp/objs/Cedar/Connection.o tmp/objs/Cedar/Console.o tmp/objs/Cedar/Database.o tmp/objs/Cedar/Hub.o tmp/objs/Cedar/Layer3.o tmp/objs/Cedar/Link.o tmp/objs/Cedar/Listener.o tmp/objs/Cedar/Logging.o tmp/objs/Cedar/Nat.o tmp/objs/Cedar/NM.o tmp/objs/Cedar/NullLan.o tmp/objs/Cedar/Protocol.o tmp/objs/Cedar/Remote.o tmp/objs/Cedar/Sam.o tmp/objs/Cedar/SecureNAT.o tmp/objs/Cedar/Server.o tmp/objs/Cedar/Session.o tmp/objs/Cedar/SM.o tmp/objs/Cedar/TcpIp.o tmp/objs/Cedar/UT.o tmp/objs/Cedar/Virtual.o tmp/objs/Cedar/VLan.o tmp/objs/Cedar/VLanUnix.o tmp/objs/Cedar/VLanWin32.o tmp/objs/Cedar/WinUi.o
+
+# Build Action
+default:       build
+
+build: $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) output/ham/ham output/utvpnserver/utvpnserver output/utvpnclient/utvpnclient output/utvpncmd/utvpncmd
+
+# Mayaqua Kernel Code
+tmp/objs/Mayaqua/Cfg.o: src/Mayaqua/Cfg.c $(HEADERS_MAYAQUA)
+       @mkdir -p tmp/
+       @mkdir -p tmp/objs/
+       @mkdir -p tmp/objs/Mayaqua/
+       @mkdir -p tmp/objs/Cedar/
+       @mkdir -p tmp/as/
+       @mkdir -p output/
+       @mkdir -p output/ham/
+       @mkdir -p output/utvpnserver/
+       @mkdir -p output/utvpnclient/
+       @mkdir -p output/utvpncmd/
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Cfg.c -o tmp/objs/Mayaqua/Cfg.o
+
+tmp/objs/Mayaqua/Encrypt.o: src/Mayaqua/Encrypt.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Encrypt.c -o tmp/objs/Mayaqua/Encrypt.o
+
+tmp/objs/Mayaqua/FileIO.o: src/Mayaqua/FileIO.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/FileIO.c -o tmp/objs/Mayaqua/FileIO.o
+
+tmp/objs/Mayaqua/Internat.o: src/Mayaqua/Internat.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Internat.c -o tmp/objs/Mayaqua/Internat.o
+
+tmp/objs/Mayaqua/Kernel.o: src/Mayaqua/Kernel.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Kernel.c -o tmp/objs/Mayaqua/Kernel.o
+
+tmp/objs/Mayaqua/Mayaqua.o: src/Mayaqua/Mayaqua.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Mayaqua.c -o tmp/objs/Mayaqua/Mayaqua.o
+
+tmp/objs/Mayaqua/Memory.o: src/Mayaqua/Memory.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Memory.c -o tmp/objs/Mayaqua/Memory.o
+
+tmp/objs/Mayaqua/Microsoft.o: src/Mayaqua/Microsoft.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Microsoft.c -o tmp/objs/Mayaqua/Microsoft.o
+
+tmp/objs/Mayaqua/Network.o: src/Mayaqua/Network.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Network.c -o tmp/objs/Mayaqua/Network.o
+
+tmp/objs/Mayaqua/Object.o: src/Mayaqua/Object.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Object.c -o tmp/objs/Mayaqua/Object.o
+
+tmp/objs/Mayaqua/OS.o: src/Mayaqua/OS.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/OS.c -o tmp/objs/Mayaqua/OS.o
+
+tmp/objs/Mayaqua/Pack.o: src/Mayaqua/Pack.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Pack.c -o tmp/objs/Mayaqua/Pack.o
+
+tmp/objs/Mayaqua/Secure.o: src/Mayaqua/Secure.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Secure.c -o tmp/objs/Mayaqua/Secure.o
+
+tmp/objs/Mayaqua/Str.o: src/Mayaqua/Str.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Str.c -o tmp/objs/Mayaqua/Str.o
+
+tmp/objs/Mayaqua/Table.o: src/Mayaqua/Table.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Table.c -o tmp/objs/Mayaqua/Table.o
+
+tmp/objs/Mayaqua/Tick64.o: src/Mayaqua/Tick64.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tick64.c -o tmp/objs/Mayaqua/Tick64.o
+
+tmp/objs/Mayaqua/Tracking.o: src/Mayaqua/Tracking.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Tracking.c -o tmp/objs/Mayaqua/Tracking.o
+
+tmp/objs/Mayaqua/Unix.o: src/Mayaqua/Unix.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Unix.c -o tmp/objs/Mayaqua/Unix.o
+
+tmp/objs/Mayaqua/Win32.o: src/Mayaqua/Win32.c $(HEADERS_MAYAQUA)
+       $(CC) $(OPTIONS_COMPILE) -c src/Mayaqua/Win32.c -o tmp/objs/Mayaqua/Win32.o
+
+# Cedar Communication Module Code
+tmp/objs/Cedar/Account.o: src/Cedar/Account.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Account.c -o tmp/objs/Cedar/Account.o
+
+tmp/objs/Cedar/Admin.o: src/Cedar/Admin.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Admin.c -o tmp/objs/Cedar/Admin.o
+
+tmp/objs/Cedar/Bridge.o: src/Cedar/Bridge.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) src/Cedar/BridgeUnix.c
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Bridge.c -o tmp/objs/Cedar/Bridge.o
+
+tmp/objs/Cedar/BridgeUnix.o: src/Cedar/BridgeUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeUnix.c -o tmp/objs/Cedar/BridgeUnix.o
+
+tmp/objs/Cedar/BridgeWin32.o: src/Cedar/BridgeWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/BridgeWin32.c -o tmp/objs/Cedar/BridgeWin32.o
+
+tmp/objs/Cedar/Cedar.o: src/Cedar/Cedar.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Cedar.c -o tmp/objs/Cedar/Cedar.o
+
+tmp/objs/Cedar/CedarPch.o: src/Cedar/CedarPch.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CedarPch.c -o tmp/objs/Cedar/CedarPch.o
+
+tmp/objs/Cedar/Client.o: src/Cedar/Client.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Client.c -o tmp/objs/Cedar/Client.o
+
+tmp/objs/Cedar/CM.o: src/Cedar/CM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/CM.c -o tmp/objs/Cedar/CM.o
+
+tmp/objs/Cedar/Command.o: src/Cedar/Command.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Command.c -o tmp/objs/Cedar/Command.o
+
+tmp/objs/Cedar/Connection.o: src/Cedar/Connection.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Connection.c -o tmp/objs/Cedar/Connection.o
+
+tmp/objs/Cedar/Console.o: src/Cedar/Console.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Console.c -o tmp/objs/Cedar/Console.o
+
+tmp/objs/Cedar/Database.o: src/Cedar/Database.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Database.c -o tmp/objs/Cedar/Database.o
+
+tmp/objs/Cedar/Hub.o: src/Cedar/Hub.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Hub.c -o tmp/objs/Cedar/Hub.o
+
+tmp/objs/Cedar/Layer3.o: src/Cedar/Layer3.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Layer3.c -o tmp/objs/Cedar/Layer3.o
+
+tmp/objs/Cedar/Link.o: src/Cedar/Link.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Link.c -o tmp/objs/Cedar/Link.o
+
+tmp/objs/Cedar/Listener.o: src/Cedar/Listener.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Listener.c -o tmp/objs/Cedar/Listener.o
+
+tmp/objs/Cedar/Logging.o: src/Cedar/Logging.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Logging.c -o tmp/objs/Cedar/Logging.o
+
+tmp/objs/Cedar/Nat.o: src/Cedar/Nat.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Nat.c -o tmp/objs/Cedar/Nat.o
+
+tmp/objs/Cedar/NM.o: src/Cedar/NM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NM.c -o tmp/objs/Cedar/NM.o
+
+tmp/objs/Cedar/NullLan.o: src/Cedar/NullLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/NullLan.c -o tmp/objs/Cedar/NullLan.o
+
+tmp/objs/Cedar/Protocol.o: src/Cedar/Protocol.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Protocol.c -o tmp/objs/Cedar/Protocol.o
+
+tmp/objs/Cedar/Remote.o: src/Cedar/Remote.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Remote.c -o tmp/objs/Cedar/Remote.o
+
+tmp/objs/Cedar/Sam.o: src/Cedar/Sam.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Sam.c -o tmp/objs/Cedar/Sam.o
+
+tmp/objs/Cedar/SecureNAT.o: src/Cedar/SecureNAT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SecureNAT.c -o tmp/objs/Cedar/SecureNAT.o
+
+tmp/objs/Cedar/Server.o: src/Cedar/Server.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Server.c -o tmp/objs/Cedar/Server.o
+
+tmp/objs/Cedar/Session.o: src/Cedar/Session.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Session.c -o tmp/objs/Cedar/Session.o
+
+tmp/objs/Cedar/SM.o: src/Cedar/SM.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/SM.c -o tmp/objs/Cedar/SM.o
+
+tmp/objs/Cedar/TcpIp.o: src/Cedar/TcpIp.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/TcpIp.c -o tmp/objs/Cedar/TcpIp.o
+
+tmp/objs/Cedar/UT.o: src/Cedar/UT.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/UT.c -o tmp/objs/Cedar/UT.o
+
+tmp/objs/Cedar/Virtual.o: src/Cedar/Virtual.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/Virtual.c -o tmp/objs/Cedar/Virtual.o
+
+tmp/objs/Cedar/VLan.o: src/Cedar/VLan.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLan.c -o tmp/objs/Cedar/VLan.o
+
+tmp/objs/Cedar/VLanUnix.o: src/Cedar/VLanUnix.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanUnix.c -o tmp/objs/Cedar/VLanUnix.o
+
+tmp/objs/Cedar/VLanWin32.o: src/Cedar/VLanWin32.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/VLanWin32.c -o tmp/objs/Cedar/VLanWin32.o
+
+tmp/objs/Cedar/WinUi.o: src/Cedar/WinUi.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Cedar/WinUi.c -o tmp/objs/Cedar/WinUi.o
+
+# Ham
+output/ham/ham: tmp/as/Ham.a output/ham/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/Ham.a $(OPTIONS_LINK) -o output/ham/ham
+
+tmp/as/Ham.a: tmp/objs/Ham.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/Ham.a
+       ar r tmp/as/Ham.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/Ham.o
+       ranlib tmp/as/Ham.a
+
+output/ham/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/ham/hamcore.utvpn
+
+tmp/objs/Ham.o: src/Ham/Ham.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/Ham/Ham.c -o tmp/objs/Ham.o
+
+# utvpnserver
+output/utvpnserver/utvpnserver: tmp/as/utvpnserver.a output/utvpnserver/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnserver.a $(OPTIONS_LINK) -o output/utvpnserver/utvpnserver
+
+tmp/as/utvpnserver.a: tmp/objs/utvpnserver.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnserver.a
+       ar r tmp/as/utvpnserver.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnserver.o
+       ranlib tmp/as/utvpnserver.a
+
+output/utvpnserver/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnserver/hamcore.utvpn
+
+tmp/objs/utvpnserver.o: src/utvpnserver/utvpnserver.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnserver/utvpnserver.c -o tmp/objs/utvpnserver.o
+
+# utvpnclient
+output/utvpnclient/utvpnclient: tmp/as/utvpnclient.a output/utvpnclient/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpnclient.a $(OPTIONS_LINK) -o output/utvpnclient/utvpnclient
+
+tmp/as/utvpnclient.a: tmp/objs/utvpnclient.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpnclient.a
+       ar r tmp/as/utvpnclient.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpnclient.o
+       ranlib tmp/as/utvpnclient.a
+
+output/utvpnclient/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpnclient/hamcore.utvpn
+
+tmp/objs/utvpnclient.o: src/utvpnclient/utvpnclient.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpnclient/utvpnclient.c -o tmp/objs/utvpnclient.o
+
+# utvpncmd
+output/utvpncmd/utvpncmd: tmp/as/utvpncmd.a output/utvpncmd/hamcore.utvpn $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) tmp/as/utvpncmd.a $(OPTIONS_LINK) -o output/utvpncmd/utvpncmd
+
+tmp/as/utvpncmd.a: tmp/objs/utvpncmd.o $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       rm -f tmp/as/utvpncmd.a
+       ar r tmp/as/utvpncmd.a $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) tmp/objs/utvpncmd.o
+       ranlib tmp/as/utvpncmd.a
+
+output/utvpncmd/hamcore.utvpn: src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
+       cp src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn output/utvpncmd/hamcore.utvpn
+
+tmp/objs/utvpncmd.o: src/utvpncmd/utvpncmd.c $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)
+       $(CC) $(OPTIONS_COMPILE) -c src/utvpncmd/utvpncmd.c -o tmp/objs/utvpncmd.o
+
+# Install
+install: $(INSTALL_BINDIR)utvpnserver $(INSTALL_BINDIR)utvpnclient $(INSTALL_BINDIR)utvpncmd
+       @echo
+       @echo "--------------------------------------------------------------------"
+       @echo "Installation completed successfully."
+       @echo
+       @echo "Please execute 'utvpnserver start' to run UT-VPN Server Background Service."
+       @echo "Or please execute 'utvpnclient start' to run UT-VPN Client Background Service."
+       @echo "And please execute 'utvpncmd' to run UT-VPN Command-Line Utility to configure UT-Server or UT-VPN Client."
+       @echo "--------------------------------------------------------------------"
+       @echo
+
+$(INSTALL_BINDIR)utvpnserver: output/utvpnserver/hamcore.utvpn output/utvpnserver/utvpnserver
+       @mkdir -p $(INSTALL_UTVPNSERVER_DIR)
+       cp output/utvpnserver/hamcore.utvpn $(INSTALL_UTVPNSERVER_DIR)hamcore.utvpn
+       cp output/utvpnserver/utvpnserver $(INSTALL_UTVPNSERVER_DIR)utvpnserver
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnserver
+       echo $(INSTALL_UTVPNSERVER_DIR)utvpnserver '"$$@"' >> $(INSTALL_BINDIR)utvpnserver
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnserver
+       chmod 755 $(INSTALL_BINDIR)utvpnserver
+
+$(INSTALL_BINDIR)utvpnclient: output/utvpnclient/hamcore.utvpn output/utvpnclient/utvpnclient
+       @mkdir -p $(INSTALL_UTVPNCLIENT_DIR)
+       cp output/utvpnclient/hamcore.utvpn $(INSTALL_UTVPNCLIENT_DIR)hamcore.utvpn
+       cp output/utvpnclient/utvpnclient $(INSTALL_UTVPNCLIENT_DIR)utvpnclient
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpnclient
+       echo $(INSTALL_UTVPNCLIENT_DIR)utvpnclient '"$$@"' >> $(INSTALL_BINDIR)utvpnclient
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpnclient
+       chmod 755 $(INSTALL_BINDIR)utvpnclient
+
+$(INSTALL_BINDIR)utvpncmd: output/utvpncmd/hamcore.utvpn output/utvpncmd/utvpncmd
+       @mkdir -p $(INSTALL_UTVPNCMD_DIR)
+       cp output/utvpncmd/hamcore.utvpn $(INSTALL_UTVPNCMD_DIR)hamcore.utvpn
+       cp output/utvpncmd/utvpncmd $(INSTALL_UTVPNCMD_DIR)utvpncmd
+       echo "#!/bin/sh" > $(INSTALL_BINDIR)utvpncmd
+       echo $(INSTALL_UTVPNCMD_DIR)utvpncmd '"$$@"' >> $(INSTALL_BINDIR)utvpncmd
+       echo 'exit $$?' >> $(INSTALL_BINDIR)utvpncmd
+       chmod 755 $(INSTALL_BINDIR)utvpncmd
+
+# Clean
+clean:
+       -rm -f $(OBJECTS_MAYAQUA)
+       -rm -f $(OBJECTS_CEDAR)
+       -rm -f tmp/objs/Ham.o
+       -rm -f tmp/as/Ham.a
+       -rm -f output/ham/ham
+       -rm -f tmp/objs/utvpnserver.o
+       -rm -f tmp/as/utvpnserver.a
+       -rm -f output/utvpnserver/utvpnserver
+       -rm -f tmp/objs/utvpnclient.o
+       -rm -f tmp/as/utvpnclient.a
+       -rm -f output/utvpnclient/utvpnclient
+       -rm -f tmp/objs/utvpncmd.o
+       -rm -f tmp/as/utvpncmd.a
+       -rm -f output/utvpncmd/utvpncmd
+
+# Help Strings
+help:
+       @echo "make [DEBUG=YES]"
+
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Account.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Account.c
new file mode 100644 (file)
index 0000000..054df00
--- /dev/null
@@ -0,0 +1,1390 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Account.c\r
+// アカウントマネージャ\r
+\r
+#include "CedarPch.h"\r
+\r
+// ポリシー項目\r
+POLICY_ITEM policy_item[] =\r
+{\r
+//  番号,   数値,   省略可能, 最小, 最大, デフォルト, 単位文字列\r
+// Ver 2.0\r
+       {0,             false,  false,  0,      0,      0,              NULL},                  // Access\r
+       {1,             false,  false,  0,      0,      0,              NULL},                  // DHCPFilter\r
+       {2,             false,  false,  0,      0,      0,              NULL},                  // DHCPNoServer\r
+       {3,             false,  false,  0,      0,      0,              NULL},                  // DHCPForce\r
+       {4,             false,  false,  0,      0,      0,              NULL},                  // NoBridge\r
+       {5,             false,  false,  0,      0,      0,              NULL},                  // NoRouting\r
+       {6,             false,  false,  0,      0,      0,              NULL},                  // CheckMac\r
+       {7,             false,  false,  0,      0,      0,              NULL},                  // CheckIP\r
+       {8,             false,  false,  0,      0,      0,              NULL},                  // ArpDhcpOnly\r
+       {9,             false,  false,  0,      0,      0,              NULL},                  // PrivacyFilter\r
+       {10,    false,  false,  0,      0,      0,              NULL},                  // NoServer\r
+       {11,    false,  false,  0,      0,      0,              NULL},                  // NoBroadcastLimiter\r
+       {12,    false,  false,  0,      0,      0,              NULL},                  // MonitorPort\r
+       {13,    true,   false,  1,      32,     32,             "POL_INT_COUNT"},       // MaxConnection\r
+       {14,    true,   false,  5,      60,     20,             "POL_INT_SEC"}, // TimeOut\r
+       {15,    true,   true,   1,      65535,  0,      "POL_INT_COUNT"},       // MaxMac\r
+       {16,    true,   true,   1,      65535,  0,      "POL_INT_COUNT"},       // MaxIP\r
+       {17,    true,   true,   1,      4294967295UL,   0,      "POL_INT_BPS"}, // MaxUpload\r
+       {18,    true,   true,   1,      4294967295UL,   0,      "POL_INT_BPS"}, // MaxDownload\r
+       {19,    false,  false,  0,      0,      0,              NULL},                  // FixPassword\r
+       {20,    true,   true,   1,      65535,  0,      "POL_INT_COUNT"},       // MultiLogins\r
+       {21,    false,  false,  0,      0,      0,              NULL},                  // NoQoS\r
+// Ver 3.0\r
+       {22,    false,  false,  0,      0,      0,              NULL},                  // RSandRAFilter\r
+       {23,    false,  false,  0,      0,      0,              NULL},                  // RAFilter\r
+       {24,    false,  false,  0,      0,      0,              NULL},                  // DHCPv6Filter\r
+       {25,    false,  false,  0,      0,      0,              NULL},                  // DHCPv6NoServer\r
+       {26,    false,  false,  0,      0,      0,              NULL},                  // NoRoutingV6\r
+       {27,    false,  false,  0,      0,      0,              NULL},                  // CheckIPv6\r
+       {28,    false,  false,  0,      0,      0,              NULL},                  // NoServerV6\r
+       {29,    true,   true,   1,      65535,  0,      "POL_INT_COUNT"},       // MaxIPv6\r
+       {30,    false,  false,  0,      0,      0,              NULL},                  // NoSavePassword\r
+       {31,    true,   true,   1,      4294967295UL,   0,      "POL_INT_SEC"}, // AutoDisconnect\r
+       {32,    false,  false,  0,      0,      0,              NULL},                  // FilterIPv4\r
+       {33,    false,  false,  0,      0,      0,              NULL},                  // FilterIPv6\r
+       {34,    false,  false,  0,      0,      0,              NULL},                  // FilterNonIP\r
+       {35,    false,  false,  0,      0,      0,              NULL},                  // NoIPv6DefaultRouterInRA\r
+       {36,    false,  false,  0,      0,      0,              NULL},                  // NoIPv6DefaultRouterInRAWhenIPv6\r
+       {37,    true,   true,   1,      4095,   0,      "POL_INT_VLAN"},        // VLanId\r
+};\r
+\r
+// ポリシー名を正規化する\r
+char *NormalizePolicyName(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return PolicyIdToStr(PolicyStrToId(name));\r
+}\r
+\r
+// ポリシーの値をフォーマット\r
+void FormatPolicyValue(wchar_t *str, UINT size, UINT id, UINT value)\r
+{\r
+       POLICY_ITEM *p;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = GetPolicyItem(id);\r
+\r
+       if (p->TypeInt == false)\r
+       {\r
+               // bool 型\r
+               if (value == 0)\r
+               {\r
+                       UniStrCpy(str, size, L"No");\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(str, size, L"Yes");\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // int 型\r
+               if (value == 0 && p->AllowZero)\r
+               {\r
+                       UniStrCpy(str, size, _UU("CMD_NO_SETTINGS"));\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(str, size, _UU(p->FormatStr), value);\r
+               }\r
+       }\r
+}\r
+\r
+// ポリシーとして設定可能な値の範囲を説明する文字列を取得\r
+void GetPolicyValueRangeStr(wchar_t *str, UINT size, UINT id)\r
+{\r
+       POLICY_ITEM *p;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = GetPolicyItem(id);\r
+\r
+       if (p->TypeInt == false)\r
+       {\r
+               // bool 型\r
+               UniStrCpy(str, size, _UU("CMD_PolicyList_Range_Bool"));\r
+       }\r
+       else\r
+       {\r
+               wchar_t *tag;\r
+               wchar_t tmp1[256], tmp2[256];\r
+\r
+               // int 型\r
+               if (p->AllowZero)\r
+               {\r
+                       tag = _UU("CMD_PolicyList_Range_Int_2");\r
+               }\r
+               else\r
+               {\r
+                       tag = _UU("CMD_PolicyList_Range_Int_1");\r
+               }\r
+\r
+               UniFormat(tmp1, sizeof(tmp1), _UU(p->FormatStr), p->MinValue);\r
+               UniFormat(tmp2, sizeof(tmp2), _UU(p->FormatStr), p->MaxValue);\r
+\r
+               UniFormat(str, size, tag, tmp1, tmp2);\r
+       }\r
+}\r
+\r
+// ポリシーアイテムの取得\r
+POLICY_ITEM *GetPolicyItem(UINT id)\r
+{\r
+       return &policy_item[id];\r
+}\r
+\r
+// 指定されたポリシーがカスケード接続でサポートされているかどうか\r
+bool PolicyIsSupportedForCascade(UINT i)\r
+{\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       if (i == 0 || i == 4 || i == 5 || i == 9 || i == 12 || i == 13 ||\r
+               i == 14 || i == 19 || i == 20 || i == 21 || i == 26 || i == 30 || i == 31 || i == 36)\r
+       {\r
+               // これらの項目はカスケード接続でサポートされていない\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ID をポリシーの名前に変換\r
+char *PolicyIdToStr(UINT i)\r
+{\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       switch (i)\r
+       {\r
+       // Ver 2.0\r
+       case 0:         return "Access";\r
+       case 1:         return "DHCPFilter";\r
+       case 2:         return "DHCPNoServer";\r
+       case 3:         return "DHCPForce";\r
+       case 4:         return "NoBridge";\r
+       case 5:         return "NoRouting";\r
+       case 6:         return "CheckMac";\r
+       case 7:         return "CheckIP";\r
+       case 8:         return "ArpDhcpOnly";\r
+       case 9:         return "PrivacyFilter";\r
+       case 10:        return "NoServer";\r
+       case 11:        return "NoBroadcastLimiter";\r
+       case 12:        return "MonitorPort";\r
+       case 13:        return "MaxConnection";\r
+       case 14:        return "TimeOut";\r
+       case 15:        return "MaxMac";\r
+       case 16:        return "MaxIP";\r
+       case 17:        return "MaxUpload";\r
+       case 18:        return "MaxDownload";\r
+       case 19:        return "FixPassword";\r
+       case 20:        return "MultiLogins";\r
+       case 21:        return "NoQoS";\r
+\r
+       // Ver 3.0\r
+       case 22:        return "RSandRAFilter";\r
+       case 23:        return "RAFilter";\r
+       case 24:        return "DHCPv6Filter";\r
+       case 25:        return "DHCPv6NoServer";\r
+       case 26:        return "NoRoutingV6";\r
+       case 27:        return "CheckIPv6";\r
+       case 28:        return "NoServerV6";\r
+       case 29:        return "MaxIPv6";\r
+       case 30:        return "NoSavePassword";\r
+       case 31:        return "AutoDisconnect";\r
+       case 32:        return "FilterIPv4";\r
+       case 33:        return "FilterIPv6";\r
+       case 34:        return "FilterNonIP";\r
+       case 35:        return "NoIPv6DefaultRouterInRA";\r
+       case 36:        return "NoIPv6DefaultRouterInRAWhenIPv6";\r
+       case 37:        return "VLanId";\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// ポリシーの名前を ID に変換\r
+UINT PolicyStrToId(char *name)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       for (i = 0;i < NUM_POLICY_ITEM;i++)\r
+       {\r
+               if (StartWith(PolicyIdToStr(i), name))\r
+               {\r
+                       return i;\r
+               }\r
+       }\r
+\r
+       return INFINITE;\r
+}\r
+\r
+// ポリシーの総数を取得\r
+UINT PolicyNum()\r
+{\r
+       return NUM_POLICY_ITEM;\r
+}\r
+\r
+// 指定した名前をアカウント名として使用できるかどうか確認する\r
+bool IsUserName(char *name)\r
+{\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), name);\r
+       name = tmp;\r
+\r
+       Trim(name);\r
+\r
+       if (StrLen(name) == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(name, "*") == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (IsSafeStr(name) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(name, LINK_USER_NAME) == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StartWith(name, L3_USERNAME))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(name, LINK_USER_NAME_PRINT) == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(name, SNAT_USER_NAME) == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(name, SNAT_USER_NAME_PRINT) == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(name, BRIDGE_USER_NAME) == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(name, BRIDGE_USER_NAME_PRINT) == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(name, ADMINISTRATOR_USERNAME) == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ポリシーのタイトルを取得する\r
+wchar_t *GetPolicyTitle(UINT id)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       Format(tmp, sizeof(tmp), "POL_%u", id);\r
+\r
+       return _UU(tmp);\r
+}\r
+\r
+// ポリシーの説明を取得する\r
+wchar_t *GetPolicyDescription(UINT id)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       Format(tmp, sizeof(tmp), "POL_EX_%u", id);\r
+\r
+       return _UU(tmp);\r
+}\r
+\r
+// ポリシーデータのクローン\r
+POLICY *ClonePolicy(POLICY *policy)\r
+{\r
+       POLICY *ret;\r
+       // 引数チェック\r
+       if (policy == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(POLICY));\r
+       Copy(ret, policy, sizeof(POLICY));\r
+\r
+       return ret;\r
+}\r
+\r
+// ポリシーを上書きする (古いバージョンを上書きする場合は新しいバージョンのデータは残す)\r
+void OverwritePolicy(POLICY **target, POLICY *p)\r
+{\r
+       // 引数チェック\r
+       if (target == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (p == NULL)\r
+       {\r
+               // ポリシー消去\r
+               if (*target != NULL)\r
+               {\r
+                       Free(*target);\r
+                       *target = NULL;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (p->Ver3)\r
+               {\r
+                       // Ver 3\r
+                       if (*target != NULL)\r
+                       {\r
+                               Free(*target);\r
+                               *target = NULL;\r
+                       }\r
+\r
+                       *target = ClonePolicy(p);\r
+               }\r
+               else\r
+               {\r
+                       // Ver 2\r
+                       if (*target == NULL)\r
+                       {\r
+                               *target = ClonePolicy(p);\r
+                       }\r
+                       else\r
+                       {\r
+                               Copy(*target, p, NUM_POLICY_ITEM_FOR_VER2 * sizeof(UINT));\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// ユーザーポリシーの設定\r
+void SetUserPolicy(USER *u, POLICY *policy)\r
+{\r
+       // 引数チェック\r
+       if (u == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(u->lock);\r
+       {\r
+               OverwritePolicy(&u->Policy, policy);\r
+       }\r
+       Unlock(u->lock);\r
+}\r
+\r
+// ユーザーポリシーの取得\r
+POLICY *GetUserPolicy(USER *u)\r
+{\r
+       POLICY *ret;\r
+       // 引数チェック\r
+       if (u == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Lock(u->lock);\r
+       {\r
+               if (u->Policy == NULL)\r
+               {\r
+                       ret = NULL;\r
+               }\r
+               else\r
+               {\r
+                       ret = ClonePolicy(u->Policy);\r
+               }\r
+       }\r
+       Unlock(u->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// グループポリシーの設定\r
+void SetGroupPolicy(USERGROUP *g, POLICY *policy)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(g->lock);\r
+       {\r
+               OverwritePolicy(&g->Policy, policy);\r
+       }\r
+       Unlock(g->lock);\r
+}\r
+\r
+// グループポリシーの取得\r
+POLICY *GetGroupPolicy(USERGROUP *g)\r
+{\r
+       POLICY *ret;\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Lock(g->lock);\r
+       {\r
+               if (g->Policy == NULL)\r
+               {\r
+                       ret = NULL;\r
+               }\r
+               else\r
+               {\r
+                       ret = ClonePolicy(g->Policy);\r
+               }\r
+       }\r
+       Unlock(g->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// デフォルトのポリシーを返す\r
+POLICY *GetDefaultPolicy()\r
+{\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       static POLICY def_policy =\r
+       {\r
+               true,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               32,\r
+               20,\r
+               0,\r
+               0,\r
+               0,\r
+               0,\r
+               false,\r
+               0,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               0,\r
+               false,\r
+               0,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+               false,\r
+       };\r
+\r
+       return &def_policy;\r
+}\r
+\r
+// NT 認証データの作成\r
+void *NewNTAuthData(wchar_t *username)\r
+{\r
+       AUTHNT *a;\r
+       // 引数チェック\r
+       a = ZeroMallocEx(sizeof(AUTHNT), true);\r
+       a->NtUsername = CopyUniStr(username);\r
+\r
+       return a;\r
+}\r
+\r
+// Radius 認証データの作成\r
+void *NewRadiusAuthData(wchar_t *username)\r
+{\r
+       AUTHRADIUS *a;\r
+       // 引数チェック\r
+       a = ZeroMallocEx(sizeof(AUTHRADIUS), true);\r
+       a->RadiusUsername = CopyUniStr(username);\r
+\r
+       return a;\r
+}\r
+\r
+// ルート証明書による認証データの作成\r
+void *NewRootCertAuthData(X_SERIAL *serial, wchar_t *common_name)\r
+{\r
+       AUTHROOTCERT *a;\r
+\r
+       a = ZeroMallocEx(sizeof(AUTHROOTCERT), true);\r
+       if (common_name != NULL && UniIsEmptyStr(common_name) == false)\r
+       {\r
+               a->CommonName = CopyUniStr(common_name);\r
+       }\r
+       if (serial != NULL && serial->size >= 1)\r
+       {\r
+               a->Serial = CloneXSerial(serial);\r
+       }\r
+\r
+       return a;\r
+}\r
+\r
+// ユーザー証明書認証データの作成\r
+void *NewUserCertAuthData(X *x)\r
+{\r
+       AUTHUSERCERT *a;\r
+\r
+       a = ZeroMalloc(sizeof(AUTHUSERCERT));\r
+       a->UserX = CloneX(x);\r
+\r
+       return a;\r
+}\r
+\r
+// パスワードのハッシュ\r
+void HashPassword(void *dst, char *username, char *password)\r
+{\r
+       BUF *b;\r
+       char *username_upper;\r
+       // 引数チェック\r
+       if (dst == NULL || username == NULL || password == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = NewBuf();\r
+       username_upper = CopyStr(username);\r
+       StrUpper(username_upper);\r
+       WriteBuf(b, password, StrLen(password));\r
+       WriteBuf(b, username_upper, StrLen(username_upper));\r
+       Hash(dst, b->Buf, b->Size, true);\r
+\r
+       FreeBuf(b);\r
+       Free(username_upper);\r
+}\r
+\r
+// パスワード認証データの作成\r
+void *NewPasswordAuthData(char *username, char *password)\r
+{\r
+       AUTHPASSWORD *pw;\r
+       // 引数チェック\r
+       if (username == NULL || password == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       pw = ZeroMalloc(sizeof(AUTHPASSWORD));\r
+       HashPassword(pw->HashedKey, username, password);\r
+\r
+       return pw;\r
+}\r
+void *NewPasswordAuthDataRaw(UCHAR *hashed_password)\r
+{\r
+       AUTHPASSWORD *pw;\r
+       // 引数チェック\r
+       if (hashed_password == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       pw = ZeroMalloc(sizeof(AUTHPASSWORD));\r
+       Copy(pw->HashedKey, hashed_password, SHA1_SIZE);\r
+\r
+       return pw;\r
+}\r
+\r
+// ユーザーの認証データのコピー\r
+void *CopyAuthData(void *authdata, UINT authtype)\r
+{\r
+       AUTHPASSWORD *pw = (AUTHPASSWORD *)authdata;\r
+       AUTHUSERCERT *usercert = (AUTHUSERCERT *)authdata;\r
+       AUTHROOTCERT *rootcert = (AUTHROOTCERT *)authdata;\r
+       AUTHRADIUS *radius = (AUTHRADIUS *)authdata;\r
+       AUTHNT *nt = (AUTHNT *)authdata;\r
+       // 引数チェック\r
+       if (authdata == NULL || authtype == AUTHTYPE_ANONYMOUS)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       switch (authtype)\r
+       {\r
+       case AUTHTYPE_PASSWORD:\r
+               {\r
+                       AUTHPASSWORD *ret = ZeroMalloc(sizeof(AUTHPASSWORD));\r
+                       Copy(ret, pw, sizeof(AUTHPASSWORD));\r
+                       return ret;\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_USERCERT:\r
+               {\r
+                       AUTHUSERCERT *ret = ZeroMalloc(sizeof(AUTHUSERCERT));\r
+                       ret->UserX = CloneX(usercert->UserX);\r
+                       return ret;\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_ROOTCERT:\r
+               {\r
+                       AUTHROOTCERT *ret = ZeroMalloc(sizeof(AUTHROOTCERT));\r
+                       ret->CommonName = CopyUniStr(rootcert->CommonName);\r
+                       ret->Serial = CloneXSerial(rootcert->Serial);\r
+                       return ret;\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_RADIUS:\r
+               {\r
+                       AUTHRADIUS *ret = ZeroMalloc(sizeof(AUTHRADIUS));\r
+                       ret->RadiusUsername = UniCopyStr(radius->RadiusUsername);\r
+                       return ret;\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_NT:\r
+               {\r
+                       AUTHNT *ret = ZeroMalloc(sizeof(AUTHNT));\r
+                       ret->NtUsername = UniCopyStr(nt->NtUsername);\r
+                       return ret;\r
+               }\r
+               break;\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// ユーザーの認証データのセット\r
+void SetUserAuthData(USER *u, UINT authtype, void *authdata)\r
+{\r
+       // 引数チェック\r
+       if (u == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (authtype != AUTHTYPE_ANONYMOUS && authdata == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(u->lock);\r
+       {\r
+               if (u->AuthType != AUTHTYPE_ANONYMOUS)\r
+               {\r
+                       // 現在の認証データの解放\r
+                       FreeAuthData(u->AuthType, u->AuthData);\r
+               }\r
+               // 新しい認証データの設定\r
+               u->AuthType = authtype;\r
+               u->AuthData = authdata;\r
+       }\r
+       Unlock(u->lock);\r
+}\r
+\r
+// グループのトラフィックデータを加算\r
+void AddGroupTraffic(USERGROUP *g, TRAFFIC *diff)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL || diff == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(g->lock);\r
+       {\r
+               AddTraffic(g->Traffic, diff);\r
+       }\r
+       Unlock(g->lock);\r
+}\r
+\r
+// ユーザーのトラフィックデータを加算\r
+void AddUserTraffic(USER *u, TRAFFIC *diff)\r
+{\r
+       // 引数チェック\r
+       if (u == NULL || diff == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(u->lock);\r
+       {\r
+               AddTraffic(u->Traffic, diff);\r
+       }\r
+       Unlock(u->lock);\r
+}\r
+\r
+// グループのトラフィック情報をセット\r
+void SetGroupTraffic(USERGROUP *g, TRAFFIC *t)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(g->lock);\r
+       {\r
+               if (t != NULL)\r
+               {\r
+                       Copy(g->Traffic, t, sizeof(TRAFFIC));\r
+               }\r
+               else\r
+               {\r
+                       Zero(g->Traffic, sizeof(TRAFFIC));\r
+               }\r
+       }\r
+       Unlock(g->lock);\r
+}\r
+\r
+// ユーザーのトラフィック情報をセット\r
+void SetUserTraffic(USER *u, TRAFFIC *t)\r
+{\r
+       // 引数チェック\r
+       if (u == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(u->lock);\r
+       {\r
+               if (t != NULL)\r
+               {\r
+                       Copy(u->Traffic, t, sizeof(TRAFFIC));\r
+               }\r
+               else\r
+               {\r
+                       Zero(u->Traffic, sizeof(TRAFFIC));\r
+               }\r
+       }\r
+       Unlock(u->lock);\r
+}\r
+\r
+// ユーザーをグループに所属させる\r
+void JoinUserToGroup(USER *u, USERGROUP *g)\r
+{\r
+       // 引数チェック\r
+       if (u == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (g != NULL)\r
+       {\r
+               // 参加\r
+               Lock(u->lock);\r
+               {\r
+                       Lock(g->lock);\r
+                       {\r
+                               if (u->Group != NULL)\r
+                               {\r
+                                       // まずユーザーをグループから外す\r
+                                       ReleaseGroup(u->Group);\r
+                                       u->Group = NULL;\r
+                                       Free(u->GroupName);\r
+                                       u->GroupName = NULL;\r
+                               }\r
+                               // ユーザーをグループに追加する\r
+                               u->GroupName = CopyStr(g->Name);\r
+                               u->Group = g;\r
+                               AddRef(g->ref);\r
+                       }\r
+                       Unlock(g->lock);\r
+               }\r
+               Unlock(u->lock);\r
+       }\r
+       else\r
+       {\r
+               // 脱退\r
+               Lock(u->lock);\r
+               {\r
+                       if (u->Group != NULL)\r
+                       {\r
+                               // ユーザーをグループから外す\r
+                               ReleaseGroup(u->Group);\r
+                               u->Group = NULL;\r
+                               Free(u->GroupName);\r
+                               u->GroupName = NULL;\r
+                       }\r
+               }\r
+               Unlock(u->lock);\r
+       }\r
+}\r
+\r
+// グループ名チェック\r
+bool AcIsGroup(HUB *h, char *name)\r
+{\r
+       USERGROUP *g;\r
+       // 引数チェック\r
+       if (h == NULL || name == NULL || NO_ACCOUNT_DB(h))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       g = AcGetGroup(h, name);\r
+       if (g == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       ReleaseGroup(g);\r
+\r
+       return true;\r
+}\r
+\r
+// ユーザー名チェック\r
+bool AcIsUser(HUB *h, char *name)\r
+{\r
+       USER *u;\r
+       // 引数チェック\r
+       if (h == NULL || name == NULL || NO_ACCOUNT_DB(h))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       u = AcGetUser(h, name);\r
+       if (u == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       ReleaseUser(u);\r
+\r
+       return true;\r
+}\r
+\r
+// グループの取得\r
+USERGROUP *AcGetGroup(HUB *h, char *name)\r
+{\r
+       USERGROUP *g, t;\r
+       // 引数チェック\r
+       if (h == NULL || name == NULL || NO_ACCOUNT_DB(h))\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t.Name = name;\r
+       g = Search(h->HubDb->GroupList, &t);\r
+       if (g == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       AddRef(g->ref);\r
+\r
+       return g;\r
+}\r
+\r
+// ユーザーの取得\r
+USER *AcGetUser(HUB *h, char *name)\r
+{\r
+       USER *u, t;\r
+       // 引数チェック\r
+       if (h == NULL || name == NULL || NO_ACCOUNT_DB(h))\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t.Name = name;\r
+       u = Search(h->HubDb->UserList, &t);\r
+       if (u == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       AddRef(u->ref);\r
+\r
+       return u;\r
+}\r
+\r
+// ユーザーの削除\r
+bool AcDeleteUser(HUB *h, char *name)\r
+{\r
+       USER *u;\r
+       // 引数チェック\r
+       if (h == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       u = AcGetUser(h, name);\r
+       if (u == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (Delete(h->HubDb->UserList, u))\r
+       {\r
+               ReleaseUser(u);\r
+       }\r
+\r
+       ReleaseUser(u);\r
+\r
+       return true;\r
+}\r
+\r
+// グループの削除\r
+bool AcDeleteGroup(HUB *h, char *name)\r
+{\r
+       USERGROUP *g;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (h == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       g = AcGetGroup(h, name);\r
+       if (g == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (Delete(h->HubDb->GroupList, g))\r
+       {\r
+               ReleaseGroup(g);\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(h->HubDb->UserList);i++)\r
+       {\r
+               USER *u = LIST_DATA(h->HubDb->UserList, i);\r
+               Lock(u->lock);\r
+               {\r
+                       if (u->Group == g)\r
+                       {\r
+                               JoinUserToGroup(u, NULL);\r
+                       }\r
+               }\r
+               Unlock(u->lock);\r
+       }\r
+\r
+       ReleaseGroup(g);\r
+\r
+       return true;\r
+}\r
+\r
+// グループの追加\r
+bool AcAddGroup(HUB *h, USERGROUP *g)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL || g == NULL || NO_ACCOUNT_DB(h))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (LIST_NUM(h->HubDb->GroupList) >= MAX_GROUPS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (AcIsGroup(h, g->Name) != false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Insert(h->HubDb->GroupList, g);\r
+       AddRef(g->ref);\r
+\r
+       return true;\r
+}\r
+\r
+// ユーザーの追加\r
+bool AcAddUser(HUB *h, USER *u)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL || u == NULL || NO_ACCOUNT_DB(h))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (LIST_NUM(h->HubDb->UserList) >= MAX_USERS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (AcIsUser(h, u->Name) != false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Insert(h->HubDb->UserList, u);\r
+       AddRef(u->ref);\r
+\r
+       return true;\r
+}\r
+\r
+// ユーザーの解放\r
+void ReleaseUser(USER *u)\r
+{\r
+       // 引数チェック\r
+       if (u == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(u->ref) == 0)\r
+       {\r
+               CleanupUser(u);\r
+       }\r
+}\r
+\r
+// ユーザーのクリーンアップ\r
+void CleanupUser(USER *u)\r
+{\r
+       // 引数チェック\r
+       if (u == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DeleteLock(u->lock);\r
+       Free(u->Name);\r
+       Free(u->RealName);\r
+       Free(u->Note);\r
+       Free(u->GroupName);\r
+       if (u->Group != NULL)\r
+       {\r
+               ReleaseGroup(u->Group);\r
+       }\r
+\r
+       // 認証データの解放\r
+       FreeAuthData(u->AuthType, u->AuthData);\r
+\r
+       if (u->Policy)\r
+       {\r
+               // ポリシー解放\r
+               Free(u->Policy);\r
+       }\r
+\r
+       FreeTraffic(u->Traffic);\r
+\r
+       Free(u);\r
+}\r
+\r
+// 認証データの解放\r
+void FreeAuthData(UINT authtype, void *authdata)\r
+{\r
+       AUTHPASSWORD *pw = (AUTHPASSWORD *)authdata;\r
+       AUTHUSERCERT *uc = (AUTHUSERCERT *)authdata;\r
+       AUTHROOTCERT *rc = (AUTHROOTCERT *)authdata;\r
+       AUTHRADIUS *rd = (AUTHRADIUS *)authdata;\r
+       AUTHNT *nt = (AUTHNT *)authdata;\r
+       // 引数チェック\r
+       if (authtype == AUTHTYPE_ANONYMOUS || authdata == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       switch (authtype)\r
+       {\r
+       case AUTHTYPE_PASSWORD:\r
+               // パスワード認証\r
+               // 何も解放しない\r
+               break;\r
+\r
+       case AUTHTYPE_USERCERT:\r
+               // ユーザー証明書\r
+               FreeX(uc->UserX);\r
+               break;\r
+\r
+       case AUTHTYPE_ROOTCERT:\r
+               // ルート証明書\r
+               if (rc->Serial != NULL)\r
+               {\r
+                       FreeXSerial(rc->Serial);\r
+               }\r
+               if (rc->CommonName != NULL)\r
+               {\r
+                       Free(rc->CommonName);\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_RADIUS:\r
+               // Radius 認証\r
+               Free(rd->RadiusUsername);\r
+               break;\r
+\r
+       case AUTHTYPE_NT:\r
+               // Windows NT 認証\r
+               Free(nt->NtUsername);\r
+               break;\r
+       }\r
+\r
+       Free(authdata);\r
+}\r
+\r
+// ユーザーの作成\r
+USER *NewUser(char *name, wchar_t *realname, wchar_t *note, UINT authtype, void *authdata)\r
+{\r
+       USER *u;\r
+       // 引数チェック\r
+       if (name == NULL || realname == NULL || note == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (authtype != AUTHTYPE_ANONYMOUS && authdata == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       u = ZeroMalloc(sizeof(USER));\r
+       u->lock = NewLock();\r
+       u->ref = NewRef();\r
+       u->Name = CopyStr(name);\r
+       u->RealName = CopyUniStr(realname);\r
+       u->Note = CopyUniStr(note);\r
+       u->GroupName = NULL;\r
+       u->Group = NULL;\r
+       u->AuthType = authtype;\r
+       u->AuthData = authdata;\r
+       u->CreatedTime = SystemTime64();\r
+       u->UpdatedTime = SystemTime64();\r
+\r
+       u->Policy = NULL;\r
+       u->Traffic = NewTraffic();\r
+\r
+       return u;\r
+}\r
+\r
+// グループの解放\r
+void ReleaseGroup(USERGROUP *g)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(g->ref) == 0)\r
+       {\r
+               CleanupGroup(g);\r
+       }\r
+}\r
+\r
+// グループのクリーンアップ\r
+void CleanupGroup(USERGROUP *g)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(g->Name);\r
+       Free(g->RealName);\r
+       Free(g->Note);\r
+\r
+       if (g->Policy)\r
+       {\r
+               // ポリシー解放\r
+               Free(g->Policy);\r
+       }\r
+\r
+\r
+       FreeTraffic(g->Traffic);\r
+\r
+       DeleteLock(g->lock);\r
+       Free(g);\r
+}\r
+\r
+// 新しいグループを作成\r
+USERGROUP *NewGroup(char *name, wchar_t *realname, wchar_t *note)\r
+{\r
+       USERGROUP *g;\r
+       // 引数チェック\r
+       if (name == NULL || realname == NULL || note == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       g = ZeroMalloc(sizeof(USERGROUP));\r
+       g->lock = NewLock();\r
+       g->ref = NewRef();\r
+       g->Name = CopyStr(name);\r
+       g->RealName = CopyUniStr(realname);\r
+       g->Note = CopyUniStr(note);\r
+       g->Policy = NULL;\r
+       g->Traffic = NewTraffic();\r
+\r
+       return g;\r
+}\r
+\r
+// HUB のアカウントデータベースのロック\r
+void AcLock(HUB *h)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (NO_ACCOUNT_DB(h))\r
+       {\r
+               return;\r
+       }\r
+\r
+       // グループとユーザーをロック\r
+       LockList(h->HubDb->GroupList);\r
+       LockList(h->HubDb->UserList);\r
+}\r
+\r
+// HUB のアカウントデータベースのロック解除\r
+void AcUnlock(HUB *h)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (NO_ACCOUNT_DB(h))\r
+       {\r
+               return;\r
+       }\r
+\r
+       // グループとユーザーをロック解除\r
+       UnlockList(h->HubDb->UserList);\r
+       UnlockList(h->HubDb->GroupList);\r
+}\r
+\r
+// グループ名比較関数\r
+int CompareGroupName(void *p1, void *p2)\r
+{\r
+       USERGROUP *g1, *g2;\r
+       // 引数チェック\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       g1 = *(USERGROUP **)p1;\r
+       g2 = *(USERGROUP **)p2;\r
+       if (g1 == NULL || g2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCmpi(g1->Name, g2->Name);\r
+}\r
+\r
+// ユーザー名比較関数\r
+int CompareUserName(void *p1, void *p2)\r
+{\r
+       USER *u1, *u2;\r
+       // 引数チェック\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       u1 = *(USER **)p1;\r
+       u2 = *(USER **)p2;\r
+       if (u1 == NULL || u2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCmpi(u1->Name, u2->Name);\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Account.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Account.h
new file mode 100644 (file)
index 0000000..e610ea4
--- /dev/null
@@ -0,0 +1,285 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Account.h\r
+// Account.c のヘッダ\r
+\r
+#ifndef        ACCOUNT_H\r
+#define        ACCOUNT_H\r
+\r
+// ポリシー項目\r
+struct POLICY_ITEM\r
+{\r
+       UINT Index;\r
+       bool TypeInt;\r
+       bool AllowZero;\r
+       UINT MinValue;\r
+       UINT MaxValue;\r
+       UINT DefaultValue;\r
+       char *FormatStr;\r
+};\r
+\r
+// ポリシー\r
+struct POLICY\r
+{\r
+       // ポリシー Ver 2.0\r
+       bool Access;                                    // アクセスを許可\r
+       bool DHCPFilter;                                // DHCP パケットをフィルタリング (IPv4)\r
+       bool DHCPNoServer;                              // DHCP サーバーの動作を禁止 (IPv4)\r
+       bool DHCPForce;                                 // DHCP が割り当てた IP アドレスを強制 (IPv4)\r
+       bool NoBridge;                                  // ブリッジを禁止\r
+       bool NoRouting;                                 // ルータ動作を禁止 (IPv4)\r
+       bool CheckMac;                                  // MAC アドレスの重複を禁止\r
+       bool CheckIP;                                   // IP アドレスの重複を禁止 (IPv4)\r
+       bool ArpDhcpOnly;                               // ARP・DHCP・ICMPv6 以外のブロードキャストを禁止\r
+       bool PrivacyFilter;                             // プライバシーフィルタモード\r
+       bool NoServer;                                  // TCP/IP サーバーとしての動作を禁止 (IPv4)\r
+       bool NoBroadcastLimiter;                // ブロードキャスト数を制限しない\r
+       bool MonitorPort;                               // モニタリングモードを許可\r
+       UINT MaxConnection;                             // TCP コネクション数の最大値\r
+       UINT TimeOut;                                   // 通信タイムアウト時間\r
+       UINT MaxMac;                                    // MAC アドレスの上限数\r
+       UINT MaxIP;                                             // IP アドレスの上限数 (IPv4)\r
+       UINT MaxUpload;                                 // アップロード帯域幅\r
+       UINT MaxDownload;                               // ダウンロード帯域幅\r
+       bool FixPassword;                               // ユーザーはパスワードを変更できない\r
+       UINT MultiLogins;                               // 多重ログイン制限数\r
+       bool NoQoS;                                             // VoIP / QoS 対応機能の使用を禁止\r
+\r
+       // ポリシー Ver 3.0\r
+       bool RSandRAFilter;                             // ルータ要請/広告パケットをフィルタリング (IPv6)\r
+       bool RAFilter;                                  // ルータ広告パケットをフィルタリング (IPv6)\r
+       bool DHCPv6Filter;                              // DHCP パケットをフィルタリング (IPv6)\r
+       bool DHCPv6NoServer;                    // DHCP サーバーの動作を禁止 (IPv6)\r
+       bool NoRoutingV6;                               // ルータ動作を禁止 (IPv6)\r
+       bool CheckIPv6;                                 // IP アドレスの重複を禁止 (IPv6)\r
+       bool NoServerV6;                                // TCP/IP サーバーとしての動作を禁止 (IPv6)\r
+       UINT MaxIPv6;                                   // IP アドレスの上限数 (IPv6)\r
+       bool NoSavePassword;                    // VPN Client でパスワードの保存を禁止\r
+       UINT AutoDisconnect;                    // VPN Client を一定時間で自動切断\r
+       bool FilterIPv4;                                // IPv4 パケットをすべてフィルタリング\r
+       bool FilterIPv6;                                // IPv6 パケットをすべてフィルタリング\r
+       bool FilterNonIP;                               // 非 IP パケットをすべてフィルタリング\r
+       bool NoIPv6DefaultRouterInRA;   // IPv6 ルータ広告からデフォルトルータ指定を削除\r
+       bool NoIPv6DefaultRouterInRAWhenIPv6;   // IPv6 ルータ広告からデフォルトルータ指定を削除 (IPv6 接続時有効化)\r
+       UINT VLanId;                                    // VLAN ID を指定\r
+\r
+       bool Ver3;                                              // ポリシーのバージョンが 3.0 以降かどうか\r
+};\r
+\r
+// グループ\r
+struct USERGROUP\r
+{\r
+       LOCK *lock;                                             // ロック\r
+       REF *ref;                                               // 参照カウンタ\r
+       char *Name;                                             // グループ名\r
+       wchar_t *RealName;                              // 表示名\r
+       wchar_t *Note;                                  // メモ\r
+       POLICY *Policy;                                 // ポリシー\r
+       TRAFFIC *Traffic;                               // トラフィックデータ\r
+};\r
+\r
+// ユーザー\r
+struct USER\r
+{\r
+       LOCK *lock;                                             // ロック\r
+       REF *ref;                                               // 参照カウンタ\r
+       char *Name;                                             // ユーザー名\r
+       wchar_t *RealName;                              // 本名\r
+       wchar_t *Note;                                  // メモ\r
+       char *GroupName;                                // グループ名\r
+       USERGROUP *Group;                               // グループ\r
+       UINT AuthType;                                  // 認証の種類\r
+       void *AuthData;                                 // 認証データ\r
+       UINT64 CreatedTime;                             // 作成日時\r
+       UINT64 UpdatedTime;                             // 更新日時\r
+       UINT64 ExpireTime;                              // 有効期限\r
+       UINT64 LastLoginTime;                   // 最終ログイン時刻\r
+       UINT NumLogin;                                  // ログイン回数の合計\r
+       POLICY *Policy;                                 // ポリシー\r
+       TRAFFIC *Traffic;                               // トラフィックデータ\r
+};\r
+\r
+// パスワード認証データ\r
+struct AUTHPASSWORD\r
+{\r
+       UCHAR HashedKey[SHA1_SIZE];             // ハッシュされたパスワード\r
+};\r
+\r
+// ユーザー証明書認証データ\r
+struct AUTHUSERCERT\r
+{\r
+       X *UserX;                                               // ユーザーの X509 証明書\r
+};\r
+\r
+// ルート証明機関認証データ\r
+struct AUTHROOTCERT\r
+{\r
+       X_SERIAL *Serial;                               // シリアル番号\r
+       wchar_t *CommonName;                    // CommonName\r
+};\r
+\r
+// Radius 認証データ\r
+struct AUTHRADIUS\r
+{\r
+       wchar_t *RadiusUsername;                // Radius 上でのユーザー名\r
+};\r
+\r
+// Windows NT 認証データ\r
+struct AUTHNT\r
+{\r
+       wchar_t *NtUsername;                    // NT 上でのユーザー名\r
+};\r
+\r
+\r
+\r
+// マクロ\r
+#define        POLICY_CURRENT_VERSION          3\r
+#define        NUM_POLICY_ITEM         ((sizeof(POLICY) / sizeof(UINT)) - 1)\r
+#define        NUM_POLICY_ITEM_FOR_VER2        22\r
+#define        NUM_POLICY_ITEM_FOR_VER3        38\r
+\r
+#define        IS_POLICY_FOR_VER2(index)       (((index) >= 0) && ((index) < NUM_POLICY_ITEM_FOR_VER2))\r
+#define        IS_POLICY_FOR_VER3(index)       (((index) >= 0) && ((index) < NUM_POLICY_ITEM_FOR_VER3))\r
+\r
+#define        IS_POLICY_FOR_CURRENT_VER(index, ver)   ((ver) >= 3 ? IS_POLICY_FOR_VER3(index) : IS_POLICY_FOR_VER2(index))\r
+\r
+#define        POLICY_BOOL(p, i)       (((bool *)(p))[(i)])\r
+#define        POLICY_INT(p, i)        (((UINT *)(p))[(i)])\r
+\r
+extern POLICY_ITEM policy_item[];\r
+\r
+\r
+\r
+\r
+// 関数プロトタイプ\r
+int CompareUserName(void *p1, void *p2);\r
+int CompareGroupName(void *p1, void *p2);\r
+void AcLock(HUB *h);\r
+void AcUnlock(HUB *h);\r
+USERGROUP *NewGroup(char *name, wchar_t *realname, wchar_t *note);\r
+void ReleaseGroup(USERGROUP *g);\r
+void CleanupGroup(USERGROUP *g);\r
+USER *NewUser(char *name, wchar_t *realname, wchar_t *note, UINT authtype, void *authdata);\r
+void ReleaseUser(USER *u);\r
+void CleanupUser(USER *u);\r
+void FreeAuthData(UINT authtype, void *authdata);\r
+bool AcAddUser(HUB *h, USER *u);\r
+bool AcAddGroup(HUB *h, USERGROUP *g);\r
+USER *AcGetUser(HUB *h, char *name);\r
+USERGROUP *AcGetGroup(HUB *h, char *name);\r
+bool AcIsUser(HUB *h, char *name);\r
+bool AcIsGroup(HUB *h, char *name);\r
+bool AcDeleteUser(HUB *h, char *name);\r
+bool AcDeleteGroup(HUB *h, char *name);\r
+void JoinUserToGroup(USER *u, USERGROUP *g);\r
+void SetUserTraffic(USER *u, TRAFFIC *t);\r
+void SetGroupTraffic(USERGROUP *g, TRAFFIC *t);\r
+void AddUserTraffic(USER *u, TRAFFIC *diff);\r
+void AddGroupTraffic(USERGROUP *g, TRAFFIC *diff);\r
+void SetUserAuthData(USER *u, UINT authtype, void *authdata);\r
+void *NewPasswordAuthData(char *username, char *password);\r
+void *NewPasswordAuthDataRaw(UCHAR *hashed_password);\r
+void *NewUserCertAuthData(X *x);\r
+void *NewRootCertAuthData(X_SERIAL *serial, wchar_t *common_name);\r
+void *NewRadiusAuthData(wchar_t *username);\r
+void *NewNTAuthData(wchar_t *username);\r
+void HashPassword(void *dst, char *username, char *password);\r
+POLICY *GetDefaultPolicy();\r
+POLICY *ClonePolicy(POLICY *policy);\r
+void SetUserPolicy(USER *u, POLICY *policy);\r
+void OverwritePolicy(POLICY **target, POLICY *p);\r
+POLICY *GetUserPolicy(USER *u);\r
+void SetGroupPolicy(USERGROUP *g, POLICY *policy);\r
+POLICY *GetGroupPolicy(USERGROUP *g);\r
+wchar_t *GetPolicyTitle(UINT id);\r
+wchar_t *GetPolicyDescription(UINT id);\r
+bool IsUserName(char *name);\r
+void *CopyAuthData(void *authdata, UINT authtype);\r
+UINT PolicyNum();\r
+bool PolicyIsSupportedForCascade(UINT i);\r
+UINT PolicyStrToId(char *name);\r
+char *PolicyIdToStr(UINT i);\r
+POLICY_ITEM *GetPolicyItem(UINT id);\r
+void GetPolicyValueRangeStr(wchar_t *str, UINT size, UINT id);\r
+void FormatPolicyValue(wchar_t *str, UINT size, UINT id, UINT value);\r
+char *NormalizePolicyName(char *name);\r
+\r
+\r
+#endif // ACCOUNT_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Admin.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Admin.c
new file mode 100644 (file)
index 0000000..50e8a14
--- /dev/null
@@ -0,0 +1,12320 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Admin.c\r
+// 管理用 RPC モジュール\r
+\r
+#include "CedarPch.h"\r
+\r
+// RPC 関数関係マクロ\r
+// このあたりは急いで実装したのでコードがあまり美しくない。\r
+// 本当は Sun RPC のプリプロセッサのようにきれいな処理方法を採用したがったが\r
+// とりあえず今はマクロの羅列になっている。\r
+#define        DECLARE_RPC_EX(rpc_name, data_type, function, in_rpc, out_rpc, free_rpc)                \\r
+       else if (StrCmpi(name, rpc_name) == 0)                                                          \\r
+       {                                                                                                                                       \\r
+               data_type *t;                                                                                                   \\r
+               t = ZeroMalloc(sizeof(data_type));                                                              \\r
+               in_rpc(t, p);                                                                                                   \\r
+               err = function(a, t);                                                                                   \\r
+               if (err == ERR_NO_ERROR)                                                                                \\r
+               {                                                                                                                               \\r
+                       out_rpc(ret, t);                                                                                        \\r
+               }                                                                                                                               \\r
+               free_rpc(t);                                                                                                    \\r
+               Free(t);                                                                                                                \\r
+               ok = true;                                                                                                              \\r
+       }\r
+#define        DECLARE_RPC(rpc_name, data_type, function, in_rpc, out_rpc)             \\r
+       else if (StrCmpi(name, rpc_name) == 0)                                                          \\r
+       {                                                                                                                                       \\r
+               data_type *t;                                                                                                   \\r
+               t = ZeroMalloc(sizeof(data_type));                                                              \\r
+               in_rpc(t, p);                                                                                                   \\r
+               err = function(a, t);                                                                                   \\r
+               if (err == ERR_NO_ERROR)                                                                                \\r
+               {                                                                                                                               \\r
+                       out_rpc(ret, t);                                                                                        \\r
+               }                                                                                                                               \\r
+               Free(t);                                                                                                                \\r
+               ok = true;                                                                                                              \\r
+       }\r
+#define        DECLARE_SC_EX(rpc_name, data_type, function, in_rpc, out_rpc, free_rpc) \\r
+       UINT function(RPC *r, data_type *t)                                                                     \\r
+       {                                                                                                                                       \\r
+               PACK *p, *ret;                                                                                                  \\r
+               UINT err;                                                                                                               \\r
+               if (r == NULL || t == NULL)                                                                             \\r
+               {                                                                                                                               \\r
+                       return ERR_INTERNAL_ERROR;                                                                      \\r
+               }                                                                                                                               \\r
+               p = NewPack();                                                                                                  \\r
+               out_rpc(p, t);                                                                                                  \\r
+               free_rpc(t);                                                                                                    \\r
+               Zero(t, sizeof(data_type));                                                                             \\r
+               ret = AdminCall(r, rpc_name, p);                                                                \\r
+               err = GetErrorFromPack(ret);                                                                    \\r
+               if (err == ERR_NO_ERROR)                                                                                \\r
+               {                                                                                                                               \\r
+                       in_rpc(t, ret);                                                                                         \\r
+               }                                                                                                                               \\r
+               FreePack(ret);                                                                                                  \\r
+               return err;                                                                                                             \\r
+       }\r
+#define        DECLARE_SC(rpc_name, data_type, function, in_rpc, out_rpc)              \\r
+       UINT function(RPC *r, data_type *t)                                                                     \\r
+       {                                                                                                                                       \\r
+               PACK *p, *ret;                                                                                                  \\r
+               UINT err;                                                                                                               \\r
+               if (r == NULL || t == NULL)                                                                             \\r
+               {                                                                                                                               \\r
+                       return ERR_INTERNAL_ERROR;                                                                      \\r
+               }                                                                                                                               \\r
+               p = NewPack();                                                                                                  \\r
+               out_rpc(p, t);                                                                                                  \\r
+               ret = AdminCall(r, rpc_name, p);                                                                \\r
+               err = GetErrorFromPack(ret);                                                                    \\r
+               if (err == ERR_NO_ERROR)                                                                                \\r
+               {                                                                                                                               \\r
+                       in_rpc(t, ret);                                                                                         \\r
+               }                                                                                                                               \\r
+               FreePack(ret);                                                                                                  \\r
+               return err;                                                                                                             \\r
+       }\r
+#define        CHECK_RIGHT                                                                                                             \\r
+       if (a->ServerAdmin == false && (t->HubName == NULL || StrCmpi(a->HubName, t->HubName) != 0))    \\r
+               return ERR_NOT_ENOUGH_RIGHT;    \\r
+       if (IsEmptyStr(t->HubName))                     \\r
+               return ERR_INVALID_PARAMETER;\r
+#define        SERVER_ADMIN_ONLY                                                                                               \\r
+       if (a->ServerAdmin == false)                                                                            \\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+#define        NO_SUPPORT_FOR_BRIDGE                                                                                   \\r
+       if (a->Server->Cedar->Bridge)                                                                           \\r
+               return ERR_NOT_SUPPORTED;\r
+\r
+// サーバーの Caps を取得 (取得できない場合はビルド番号から判別)\r
+CAPSLIST *ScGetCapsEx(RPC *rpc)\r
+{\r
+       RPC_SERVER_INFO info;\r
+       CAPSLIST *t;\r
+       bool is_bridge = false;\r
+       // 引数チェック\r
+       if (rpc == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       ScGetServerInfo(rpc, &info);\r
+\r
+       t = ZeroMalloc(sizeof(CAPSLIST));\r
+\r
+       // RPC で Caps を取得してみる\r
+       if (ScGetCaps(rpc, t) != ERR_NO_ERROR)\r
+       {\r
+               UINT build;\r
+\r
+               Free(t);\r
+               t = NewCapsList();\r
+\r
+               // 取得に失敗したのでビルド番号を取得する\r
+               // (ものすごく古いバージョンの VPN Server のための対応コード)\r
+               build = info.ServerBuildInt;\r
+\r
+               is_bridge = (SearchStrEx(info.ServerProductName, "bridge", 0, false) == INFINITE) ? false : true;\r
+\r
+               AddCapsInt(t, "i_max_packet_size", 1514);\r
+\r
+               if (is_bridge == false)\r
+               {\r
+                       AddCapsInt(t, "i_max_hubs", 4096);\r
+                       AddCapsInt(t, "i_max_sessions", 4096);\r
+\r
+                       if (info.ServerType != SERVER_TYPE_FARM_MEMBER)\r
+                       {\r
+                               AddCapsInt(t, "i_max_users_per_hub", 10000);\r
+                               AddCapsInt(t, "i_max_groups_per_hub", 10000);\r
+                               AddCapsInt(t, "i_max_access_lists", 4096);\r
+                       }\r
+                       else\r
+                       {\r
+                               AddCapsInt(t, "i_max_users_per_hub", 0);\r
+                               AddCapsInt(t, "i_max_groups_per_hub", 0);\r
+                               AddCapsInt(t, "i_max_access_lists", 0);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       AddCapsInt(t, "i_max_hubs", 0);\r
+                       AddCapsInt(t, "i_max_sessions", 0);\r
+                       AddCapsInt(t, "i_max_users_per_hub", 0);\r
+                       AddCapsInt(t, "i_max_groups_per_hub", 0);\r
+                       AddCapsInt(t, "i_max_access_lists", 0);\r
+               }\r
+\r
+               AddCapsInt(t, "i_max_mac_tables", 10000);\r
+               AddCapsInt(t, "i_max_ip_tables", 10000);\r
+\r
+               if (info.ServerType == SERVER_TYPE_STANDALONE)\r
+               {\r
+                       AddCapsBool(t, "b_support_securenat", (build >= 3600) ? true : false);\r
+                       AddCapsInt(t, "i_max_secnat_tables", 4096);\r
+               }\r
+               else\r
+               {\r
+                       AddCapsBool(t, "b_support_securenat", false);\r
+                       AddCapsInt(t, "i_max_secnat_tables", 0);\r
+               }\r
+\r
+               if (is_bridge)\r
+               {\r
+                       AddCapsBool(t, "b_bridge", true);\r
+               }\r
+               else if (info.ServerType == SERVER_TYPE_STANDALONE)\r
+               {\r
+                       AddCapsBool(t, "b_standalone", true);\r
+               }\r
+               else if (info.ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+               {\r
+                       AddCapsBool(t, "b_cluster_controller", true);\r
+               }\r
+               else\r
+               {\r
+                       AddCapsBool(t, "b_cluster_member", true);\r
+               }\r
+\r
+               AddCapsBool(t, "b_support_config_hub", info.ServerType != SERVER_TYPE_FARM_MEMBER &&\r
+                       is_bridge == false);\r
+\r
+               AddCapsBool(t, "b_vpn_client_connect", is_bridge == false ? true : false);\r
+\r
+               AddCapsBool(t, "b_support_radius", info.ServerType != SERVER_TYPE_FARM_MEMBER &&\r
+                       is_bridge == false);\r
+\r
+               if (build >= 3600)\r
+               {\r
+                       RPC_BRIDGE_SUPPORT b;\r
+                       Zero(&b, sizeof(b));\r
+                       if (ScGetBridgeSupport(rpc, &b) == ERR_NO_ERROR)\r
+                       {\r
+                               AddCapsBool(t, "b_local_bridge", b.IsBridgeSupportedOs);\r
+                               AddCapsBool(t, "b_must_install_pcap", b.IsWinPcapNeeded);\r
+                       }\r
+                       else\r
+                       {\r
+                               AddCapsBool(t, "b_local_bridge", false);\r
+                               AddCapsBool(t, "b_must_install_pcap", false);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       AddCapsBool(t, "b_local_bridge", false);\r
+                       AddCapsBool(t, "b_must_install_pcap", false);\r
+               }\r
+\r
+               AddCapsBool(t, "b_tap_supported", false);\r
+\r
+               if (info.ServerType == SERVER_TYPE_STANDALONE)\r
+               {\r
+                       AddCapsBool(t, "b_support_cascade", true);\r
+               }\r
+               else\r
+               {\r
+                       AddCapsBool(t, "b_support_cascade", false);\r
+               }\r
+\r
+               AddCapsBool(t, "b_support_cascade_cert", false);\r
+               AddCapsBool(t, "b_support_config_log", info.ServerType != SERVER_TYPE_FARM_MEMBER);\r
+               AddCapsBool(t, "b_support_autodelete", false);\r
+       }\r
+       else\r
+       {\r
+               // 成功した場合\r
+               if (info.ServerBuildInt <= 4350)\r
+               {\r
+                       if (is_bridge == false)\r
+                       {\r
+                               // Build 4300 以下では必ず b_support_cluster が true\r
+                               CAPS *caps = GetCaps(t, "b_support_cluster");\r
+                               if (caps == NULL)\r
+                               {\r
+                                       AddCapsBool(t, "b_support_cluster", true);\r
+                               }\r
+                               else\r
+                               {\r
+                                       caps->Value = 1;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (true)\r
+       {\r
+               TOKEN_LIST *names;\r
+\r
+               // サーバー側に存在しない Caps の一覧を false として登録\r
+               names = GetTableNameStartWith("CT_b_");\r
+               if (names != NULL)\r
+               {\r
+                       UINT i;\r
+                       for (i = 0;i < names->NumTokens;i++)\r
+                       {\r
+                               char *name = names->Token[i] + 3;\r
+\r
+                               if (GetCaps(t, name) == NULL)\r
+                               {\r
+                                       AddCapsBool(t, name, false);\r
+                               }\r
+                       }\r
+\r
+                       FreeToken(names);\r
+               }\r
+       }\r
+\r
+       FreeRpcServerInfo(&info);\r
+\r
+       return t;\r
+}\r
+\r
+// 管理用 RPC 関数ディスパッチルーチン\r
+PACK *AdminDispatch(RPC *rpc, char *name, PACK *p)\r
+{\r
+       ADMIN *a;\r
+       PACK *ret;\r
+       UINT err;\r
+       SERVER *server = NULL;\r
+       CEDAR *cedar = NULL;\r
+       bool ok = false;\r
+       // 引数チェック\r
+       if (rpc == NULL || name == NULL || p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = NewPack();\r
+       err = ERR_NO_ERROR;\r
+\r
+       // 管理構造体\r
+       a = (ADMIN *)rpc->Param;\r
+       if (a == NULL)\r
+       {\r
+               FreePack(ret);\r
+               return NULL;\r
+       }\r
+\r
+       server = a->Server;\r
+\r
+       if (server != NULL)\r
+       {\r
+               cedar = server->Cedar;\r
+       }\r
+\r
+       Lock(cedar->CedarSuperLock);\r
+\r
+       if (true)\r
+       {\r
+               char tmp[MAX_PATH];\r
+               char ip[MAX_PATH];\r
+               UINT rpc_id = 0;\r
+\r
+               StrCpy(ip, sizeof(ip), "Unknown");\r
+\r
+               if (rpc->Sock != NULL)\r
+               {\r
+                       IPToStr(ip, sizeof(ip), &rpc->Sock->RemoteIP);\r
+                       rpc_id = rpc->Sock->socket;\r
+               }\r
+\r
+               Format(tmp, sizeof(tmp), "RPC: RPC-%u (%s): Entering RPC [%s]...",\r
+                       rpc_id, ip, name);\r
+\r
+               SiDebugLog(a->Server, tmp);\r
+       }\r
+\r
+       if (0) {}\r
+\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       // 本当は Sun RPC のプリプロセッサのようにきれいな処理方法を採用したがったが\r
+       // とりあえず今はマクロの羅列になっている。\r
+\r
+       // RPC 関数定義: ここから\r
+       DECLARE_RPC_EX("Test", RPC_TEST, StTest, InRpcTest, OutRpcTest, FreeRpcTest)\r
+       DECLARE_RPC_EX("GetServerInfo", RPC_SERVER_INFO, StGetServerInfo, InRpcServerInfo, OutRpcServerInfo, FreeRpcServerInfo)\r
+       DECLARE_RPC("GetServerStatus", RPC_SERVER_STATUS, StGetServerStatus, InRpcServerStatus, OutRpcServerStatus)\r
+       DECLARE_RPC("CreateListener", RPC_LISTENER, StCreateListener, InRpcListener, OutRpcListener)\r
+       DECLARE_RPC_EX("EnumListener", RPC_LISTENER_LIST, StEnumListener, InRpcListenerList, OutRpcListenerList, FreeRpcListenerList)\r
+       DECLARE_RPC("DeleteListener", RPC_LISTENER, StDeleteListener, InRpcListener, OutRpcListener)\r
+       DECLARE_RPC("EnableListener", RPC_LISTENER, StEnableListener, InRpcListener, OutRpcListener)\r
+       DECLARE_RPC("SetServerPassword", RPC_SET_PASSWORD, StSetServerPassword, InRpcSetPassword, OutRpcSetPassword)\r
+       DECLARE_RPC_EX("SetFarmSetting", RPC_FARM, StSetFarmSetting, InRpcFarm, OutRpcFarm, FreeRpcFarm)\r
+       DECLARE_RPC_EX("GetFarmSetting", RPC_FARM, StGetFarmSetting, InRpcFarm, OutRpcFarm, FreeRpcFarm)\r
+       DECLARE_RPC_EX("GetFarmInfo", RPC_FARM_INFO, StGetFarmInfo, InRpcFarmInfo, OutRpcFarmInfo, FreeRpcFarmInfo)\r
+       DECLARE_RPC_EX("EnumFarmMember", RPC_ENUM_FARM, StEnumFarmMember, InRpcEnumFarm, OutRpcEnumFarm, FreeRpcEnumFarm)\r
+       DECLARE_RPC("GetFarmConnectionStatus", RPC_FARM_CONNECTION_STATUS, StGetFarmConnectionStatus, InRpcFarmConnectionStatus, OutRpcFarmConnectionStatus)\r
+       DECLARE_RPC_EX("SetServerCert", RPC_KEY_PAIR, StSetServerCert, InRpcKeyPair, OutRpcKeyPair, FreeRpcKeyPair)\r
+       DECLARE_RPC_EX("GetServerCert", RPC_KEY_PAIR, StGetServerCert, InRpcKeyPair, OutRpcKeyPair, FreeRpcKeyPair)\r
+       DECLARE_RPC_EX("GetServerCipher", RPC_STR, StGetServerCipher, InRpcStr, OutRpcStr, FreeRpcStr)\r
+       DECLARE_RPC_EX("SetServerCipher", RPC_STR, StSetServerCipher, InRpcStr, OutRpcStr, FreeRpcStr)\r
+       DECLARE_RPC("CreateHub", RPC_CREATE_HUB, StCreateHub, InRpcCreateHub, OutRpcCreateHub)\r
+       DECLARE_RPC("SetHub", RPC_CREATE_HUB, StSetHub, InRpcCreateHub, OutRpcCreateHub)\r
+       DECLARE_RPC("GetHub", RPC_CREATE_HUB, StGetHub, InRpcCreateHub, OutRpcCreateHub)\r
+       DECLARE_RPC_EX("EnumHub", RPC_ENUM_HUB, StEnumHub, InRpcEnumHub, OutRpcEnumHub, FreeRpcEnumHub)\r
+       DECLARE_RPC("DeleteHub", RPC_DELETE_HUB, StDeleteHub, InRpcDeleteHub, OutRpcDeleteHub)\r
+       DECLARE_RPC("GetHubRadius", RPC_RADIUS, StGetHubRadius, InRpcRadius, OutRpcRadius)\r
+       DECLARE_RPC("SetHubRadius", RPC_RADIUS, StSetHubRadius, InRpcRadius, OutRpcRadius)\r
+       DECLARE_RPC_EX("EnumConnection", RPC_ENUM_CONNECTION, StEnumConnection, InRpcEnumConnection, OutRpcEnumConnection, FreeRpcEnumConnetion)\r
+       DECLARE_RPC("DisconnectConnection", RPC_DISCONNECT_CONNECTION, StDisconnectConnection, InRpcDisconnectConnection, OutRpcDisconnectConnection)\r
+       DECLARE_RPC("GetConnectionInfo", RPC_CONNECTION_INFO, StGetConnectionInfo, InRpcConnectionInfo, OutRpcConnectionInfo)\r
+       DECLARE_RPC("SetHubOnline", RPC_SET_HUB_ONLINE, StSetHubOnline, InRpcSetHubOnline, OutRpcSetHubOnline)\r
+       DECLARE_RPC("GetHubStatus", RPC_HUB_STATUS, StGetHubStatus, InRpcHubStatus, OutRpcHubStatus)\r
+       DECLARE_RPC("SetHubLog", RPC_HUB_LOG, StSetHubLog, InRpcHubLog, OutRpcHubLog)\r
+       DECLARE_RPC("GetHubLog", RPC_HUB_LOG, StGetHubLog, InRpcHubLog, OutRpcHubLog)\r
+       DECLARE_RPC_EX("AddCa", RPC_HUB_ADD_CA, StAddCa, InRpcHubAddCa, OutRpcHubAddCa, FreeRpcHubAddCa)\r
+       DECLARE_RPC_EX("EnumCa", RPC_HUB_ENUM_CA, StEnumCa, InRpcHubEnumCa, OutRpcHubEnumCa, FreeRpcHubEnumCa)\r
+       DECLARE_RPC_EX("GetCa", RPC_HUB_GET_CA, StGetCa, InRpcHubGetCa, OutRpcHubGetCa, FreeRpcHubGetCa)\r
+       DECLARE_RPC("DeleteCa", RPC_HUB_DELETE_CA, StDeleteCa, InRpcHubDeleteCa, OutRpcHubDeleteCa)\r
+       DECLARE_RPC("SetLinkOnline", RPC_LINK, StSetLinkOnline, InRpcLink, OutRpcLink)\r
+       DECLARE_RPC("SetLinkOffline", RPC_LINK, StSetLinkOffline, InRpcLink, OutRpcLink)\r
+       DECLARE_RPC("DeleteLink", RPC_LINK, StDeleteLink, InRpcLink, OutRpcLink)\r
+       DECLARE_RPC("RenameLink", RPC_RENAME_LINK, StRenameLink, InRpcRenameLink, OutRpcRenameLink)\r
+       DECLARE_RPC_EX("CreateLink", RPC_CREATE_LINK, StCreateLink, InRpcCreateLink, OutRpcCreateLink, FreeRpcCreateLink)\r
+       DECLARE_RPC_EX("GetLink", RPC_CREATE_LINK, StGetLink, InRpcCreateLink, OutRpcCreateLink, FreeRpcCreateLink)\r
+       DECLARE_RPC_EX("SetLink", RPC_CREATE_LINK, StSetLink, InRpcCreateLink, OutRpcCreateLink, FreeRpcCreateLink)\r
+       DECLARE_RPC_EX("EnumLink", RPC_ENUM_LINK, StEnumLink, InRpcEnumLink, OutRpcEnumLink, FreeRpcEnumLink)\r
+       DECLARE_RPC_EX("GetLinkStatus", RPC_LINK_STATUS, StGetLinkStatus, InRpcLinkStatus, OutRpcLinkStatus, FreeRpcLinkStatus)\r
+       DECLARE_RPC("AddAccess", RPC_ADD_ACCESS, StAddAccess, InRpcAddAccess, OutRpcAddAccess)\r
+       DECLARE_RPC("DeleteAccess", RPC_DELETE_ACCESS, StDeleteAccess, InRpcDeleteAccess, OutRpcDeleteAccess)\r
+       DECLARE_RPC_EX("EnumAccess", RPC_ENUM_ACCESS_LIST, StEnumAccess, InRpcEnumAccessList, OutRpcEnumAccessList, FreeRpcEnumAccessList)\r
+       DECLARE_RPC_EX("SetAccessList", RPC_ENUM_ACCESS_LIST, StSetAccessList, InRpcEnumAccessList, OutRpcEnumAccessList, FreeRpcEnumAccessList)\r
+       DECLARE_RPC_EX("CreateUser", RPC_SET_USER, StCreateUser, InRpcSetUser, OutRpcSetUser, FreeRpcSetUser)\r
+       DECLARE_RPC_EX("SetUser", RPC_SET_USER, StSetUser, InRpcSetUser, OutRpcSetUser, FreeRpcSetUser)\r
+       DECLARE_RPC_EX("GetUser", RPC_SET_USER, StGetUser, InRpcSetUser, OutRpcSetUser, FreeRpcSetUser)\r
+       DECLARE_RPC("DeleteUser", RPC_DELETE_USER, StDeleteUser, InRpcDeleteUser, OutRpcDeleteUser)\r
+       DECLARE_RPC_EX("EnumUser", RPC_ENUM_USER, StEnumUser, InRpcEnumUser, OutRpcEnumUser, FreeRpcEnumUser)\r
+       DECLARE_RPC_EX("CreateGroup", RPC_SET_GROUP, StCreateGroup, InRpcSetGroup, OutRpcSetGroup, FreeRpcSetGroup)\r
+       DECLARE_RPC_EX("SetGroup", RPC_SET_GROUP, StSetGroup, InRpcSetGroup, OutRpcSetGroup, FreeRpcSetGroup)\r
+       DECLARE_RPC_EX("GetGroup", RPC_SET_GROUP, StGetGroup, InRpcSetGroup, OutRpcSetGroup, FreeRpcSetGroup)\r
+       DECLARE_RPC("DeleteGroup", RPC_DELETE_USER, StDeleteGroup, InRpcDeleteUser, OutRpcDeleteUser)\r
+       DECLARE_RPC_EX("EnumGroup", RPC_ENUM_GROUP, StEnumGroup, InRpcEnumGroup, OutRpcEnumGroup, FreeRpcEnumGroup)\r
+       DECLARE_RPC_EX("EnumSession", RPC_ENUM_SESSION, StEnumSession, InRpcEnumSession, OutRpcEnumSession, FreeRpcEnumSession)\r
+       DECLARE_RPC_EX("GetSessionStatus", RPC_SESSION_STATUS, StGetSessionStatus, InRpcSessionStatus, OutRpcSessionStatus, FreeRpcSessionStatus)\r
+       DECLARE_RPC("DeleteSession", RPC_DELETE_SESSION, StDeleteSession, InRpcDeleteSession, OutRpcDeleteSession)\r
+       DECLARE_RPC_EX("EnumMacTable", RPC_ENUM_MAC_TABLE, StEnumMacTable, InRpcEnumMacTable, OutRpcEnumMacTable, FreeRpcEnumMacTable)\r
+       DECLARE_RPC("DeleteMacTable", RPC_DELETE_TABLE, StDeleteMacTable, InRpcDeleteTable, OutRpcDeleteTable)\r
+       DECLARE_RPC_EX("EnumIpTable", RPC_ENUM_IP_TABLE, StEnumIpTable, InRpcEnumIpTable, OutRpcEnumIpTable, FreeRpcEnumIpTable)\r
+       DECLARE_RPC("DeleteIpTable", RPC_DELETE_TABLE, StDeleteIpTable, InRpcDeleteTable, OutRpcDeleteTable)\r
+       DECLARE_RPC("SetKeep", RPC_KEEP, StSetKeep, InRpcKeep, OutRpcKeep)\r
+       DECLARE_RPC("GetKeep", RPC_KEEP, StGetKeep, InRpcKeep, OutRpcKeep)\r
+       DECLARE_RPC("EnableSecureNAT", RPC_HUB, StEnableSecureNAT, InRpcHub, OutRpcHub)\r
+       DECLARE_RPC("DisableSecureNAT", RPC_HUB, StDisableSecureNAT, InRpcHub, OutRpcHub)\r
+       DECLARE_RPC("SetSecureNATOption", VH_OPTION, StSetSecureNATOption, InVhOption, OutVhOption)\r
+       DECLARE_RPC("GetSecureNATOption", VH_OPTION, StGetSecureNATOption, InVhOption, OutVhOption)\r
+       DECLARE_RPC_EX("EnumNAT", RPC_ENUM_NAT, StEnumNAT, InRpcEnumNat, OutRpcEnumNat, FreeRpcEnumNat)\r
+       DECLARE_RPC_EX("EnumDHCP", RPC_ENUM_DHCP, StEnumDHCP, InRpcEnumDhcp, OutRpcEnumDhcp, FreeRpcEnumDhcp)\r
+       DECLARE_RPC("GetSecureNATStatus", RPC_NAT_STATUS, StGetSecureNATStatus, InRpcNatStatus, OutRpcNatStatus)\r
+       DECLARE_RPC_EX("EnumEthernet", RPC_ENUM_ETH, StEnumEthernet, InRpcEnumEth, OutRpcEnumEth, FreeRpcEnumEth)\r
+       DECLARE_RPC("AddLocalBridge", RPC_LOCALBRIDGE, StAddLocalBridge, InRpcLocalBridge, OutRpcLocalBridge)\r
+       DECLARE_RPC("DeleteLocalBridge", RPC_LOCALBRIDGE, StDeleteLocalBridge, InRpcLocalBridge, OutRpcLocalBridge)\r
+       DECLARE_RPC_EX("EnumLocalBridge", RPC_ENUM_LOCALBRIDGE, StEnumLocalBridge, InRpcEnumLocalBridge, OutRpcEnumLocalBridge, FreeRpcEnumLocalBridge)\r
+       DECLARE_RPC("GetBridgeSupport", RPC_BRIDGE_SUPPORT, StGetBridgeSupport, InRpcBridgeSupport, OutRpcBridgeSupport)\r
+       DECLARE_RPC("RebootServer", RPC_TEST, StRebootServer, InRpcTest, OutRpcTest)\r
+       DECLARE_RPC_EX("GetCaps", CAPSLIST, StGetCaps, InRpcCapsList, OutRpcCapsList, FreeRpcCapsList)\r
+       DECLARE_RPC_EX("GetConfig", RPC_CONFIG, StGetConfig, InRpcConfig, OutRpcConfig, FreeRpcConfig)\r
+       DECLARE_RPC_EX("SetConfig", RPC_CONFIG, StSetConfig, InRpcConfig, OutRpcConfig, FreeRpcConfig)\r
+       DECLARE_RPC_EX("GetDefaultHubAdminOptions", RPC_ADMIN_OPTION, StGetDefaultHubAdminOptions, InRpcAdminOption, OutRpcAdminOption, FreeRpcAdminOption)\r
+       DECLARE_RPC_EX("GetHubAdminOptions", RPC_ADMIN_OPTION, StGetHubAdminOptions, InRpcAdminOption, OutRpcAdminOption, FreeRpcAdminOption)\r
+       DECLARE_RPC_EX("SetHubAdminOptions", RPC_ADMIN_OPTION, StSetHubAdminOptions, InRpcAdminOption, OutRpcAdminOption, FreeRpcAdminOption)\r
+       DECLARE_RPC_EX("GetHubExtOptions", RPC_ADMIN_OPTION, StGetHubExtOptions, InRpcAdminOption, OutRpcAdminOption, FreeRpcAdminOption)\r
+       DECLARE_RPC_EX("SetHubExtOptions", RPC_ADMIN_OPTION, StSetHubExtOptions, InRpcAdminOption, OutRpcAdminOption, FreeRpcAdminOption)\r
+       DECLARE_RPC("AddL3Switch", RPC_L3SW, StAddL3Switch, InRpcL3Sw, OutRpcL3Sw)\r
+       DECLARE_RPC("DelL3Switch", RPC_L3SW, StDelL3Switch, InRpcL3Sw, OutRpcL3Sw)\r
+       DECLARE_RPC_EX("EnumL3Switch", RPC_ENUM_L3SW, StEnumL3Switch, InRpcEnumL3Sw, OutRpcEnumL3Sw, FreeRpcEnumL3Sw)\r
+       DECLARE_RPC("StartL3Switch", RPC_L3SW, StStartL3Switch, InRpcL3Sw, OutRpcL3Sw)\r
+       DECLARE_RPC("StopL3Switch", RPC_L3SW, StStopL3Switch, InRpcL3Sw, OutRpcL3Sw)\r
+       DECLARE_RPC("AddL3If", RPC_L3IF, StAddL3If, InRpcL3If, OutRpcL3If)\r
+       DECLARE_RPC("DelL3If", RPC_L3IF, StDelL3If, InRpcL3If, OutRpcL3If)\r
+       DECLARE_RPC_EX("EnumL3If", RPC_ENUM_L3IF, StEnumL3If, InRpcEnumL3If, OutRpcEnumL3If, FreeRpcEnumL3If)\r
+       DECLARE_RPC("AddL3Table", RPC_L3TABLE, StAddL3Table, InRpcL3Table, OutRpcL3Table)\r
+       DECLARE_RPC("DelL3Table", RPC_L3TABLE, StDelL3Table, InRpcL3Table, OutRpcL3Table)\r
+       DECLARE_RPC_EX("EnumL3Table", RPC_ENUM_L3TABLE, StEnumL3Table, InRpcEnumL3Table, OutRpcEnumL3Table, FreeRpcEnumL3Table)\r
+       DECLARE_RPC_EX("EnumCrl", RPC_ENUM_CRL, StEnumCrl, InRpcEnumCrl, OutRpcEnumCrl, FreeRpcEnumCrl)\r
+       DECLARE_RPC_EX("AddCrl", RPC_CRL, StAddCrl, InRpcCrl, OutRpcCrl, FreeRpcCrl)\r
+       DECLARE_RPC_EX("DelCrl", RPC_CRL, StDelCrl, InRpcCrl, OutRpcCrl, FreeRpcCrl)\r
+       DECLARE_RPC_EX("GetCrl", RPC_CRL, StGetCrl, InRpcCrl, OutRpcCrl, FreeRpcCrl)\r
+       DECLARE_RPC_EX("SetCrl", RPC_CRL, StSetCrl, InRpcCrl, OutRpcCrl, FreeRpcCrl)\r
+       DECLARE_RPC_EX("SetAcList", RPC_AC_LIST, StSetAcList, InRpcAcList, OutRpcAcList, FreeRpcAcList)\r
+       DECLARE_RPC_EX("GetAcList", RPC_AC_LIST, StGetAcList, InRpcAcList, OutRpcAcList, FreeRpcAcList)\r
+       DECLARE_RPC_EX("EnumLogFile", RPC_ENUM_LOG_FILE, StEnumLogFile, InRpcEnumLogFile, OutRpcEnumLogFile, FreeRpcEnumLogFile)\r
+       DECLARE_RPC_EX("ReadLogFile", RPC_READ_LOG_FILE, StReadLogFile, InRpcReadLogFile, OutRpcReadLogFile, FreeRpcReadLogFile)\r
+       DECLARE_RPC("AddLicenseKey", RPC_TEST, StAddLicenseKey, InRpcTest, OutRpcTest)\r
+       DECLARE_RPC("DelLicenseKey", RPC_TEST, StDelLicenseKey, InRpcTest, OutRpcTest)\r
+       DECLARE_RPC_EX("EnumLicenseKey", RPC_ENUM_LICENSE_KEY, StEnumLicenseKey, InRpcEnumLicenseKey, OutRpcEnumLicenseKey, FreeRpcEnumLicenseKey)\r
+       DECLARE_RPC("GetLicenseStatus", RPC_LICENSE_STATUS, StGetLicenseStatus, InRpcLicenseStatus, OutRpcLicenseStatus)\r
+       DECLARE_RPC("SetSysLog", SYSLOG_SETTING, StSetSysLog, InRpcSysLogSetting, OutRpcSysLogSetting)\r
+       DECLARE_RPC("GetSysLog", SYSLOG_SETTING, StGetSysLog, InRpcSysLogSetting, OutRpcSysLogSetting)\r
+       DECLARE_RPC_EX("EnumEthVLan", RPC_ENUM_ETH_VLAN, StEnumEthVLan, InRpcEnumEthVLan, OutRpcEnumEthVLan, FreeRpcEnumEthVLan)\r
+       DECLARE_RPC("SetEnableEthVLan", RPC_TEST, StSetEnableEthVLan, InRpcTest, OutRpcTest)\r
+       DECLARE_RPC_EX("SetHubMsg", RPC_MSG, StSetHubMsg, InRpcMsg, OutRpcMsg, FreeRpcMsg)\r
+       DECLARE_RPC_EX("GetHubMsg", RPC_MSG, StGetHubMsg, InRpcMsg, OutRpcMsg, FreeRpcMsg)\r
+       DECLARE_RPC("Crash", RPC_TEST, StCrash, InRpcTest, OutRpcTest)\r
+       DECLARE_RPC_EX("GetAdminMsg", RPC_MSG, StGetAdminMsg, InRpcMsg, OutRpcMsg, FreeRpcMsg)\r
+       DECLARE_RPC("Flush", RPC_TEST, StFlush, InRpcTest, OutRpcTest)\r
+       DECLARE_RPC("Debug", RPC_TEST, StDebug, InRpcTest, OutRpcTest)\r
+       // RPC 関数定義: ここまで\r
+\r
+       if (ok == false)\r
+       {\r
+               err = ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       if (err != ERR_NO_ERROR)\r
+       {\r
+               PackAddInt(ret, "error", err);\r
+       }\r
+\r
+       if (true)\r
+       {\r
+               char tmp[MAX_PATH];\r
+               char ip[MAX_PATH];\r
+               UINT rpc_id = 0;\r
+\r
+               StrCpy(ip, sizeof(ip), "Unknown");\r
+\r
+               if (rpc->Sock != NULL)\r
+               {\r
+                       IPToStr(ip, sizeof(ip), &rpc->Sock->RemoteIP);\r
+                       rpc_id = rpc->Sock->socket;\r
+               }\r
+\r
+               Format(tmp, sizeof(tmp), "RPC: RPC-%u (%s): Leaving RPC [%s] (Error: %u).",\r
+                       rpc_id, ip, name, err);\r
+\r
+               SiDebugLog(a->Server, tmp);\r
+       }\r
+\r
+       Unlock(cedar->CedarSuperLock);\r
+\r
+       return ret;\r
+}\r
+\r
+// このあたりは急いで実装したのでコードがあまり美しくない。\r
+// 本当は Sun RPC のプリプロセッサのようにきれいな処理方法を採用したがったが\r
+// とりあえず今はマクロの羅列になっている。\r
+\r
+// RPC 呼び出し関数定義: ここから\r
+DECLARE_SC_EX("Test", RPC_TEST, ScTest, InRpcTest, OutRpcTest, FreeRpcTest)\r
+DECLARE_SC_EX("GetServerInfo", RPC_SERVER_INFO, ScGetServerInfo, InRpcServerInfo, OutRpcServerInfo, FreeRpcServerInfo)\r
+DECLARE_SC("GetServerStatus", RPC_SERVER_STATUS, ScGetServerStatus, InRpcServerStatus, OutRpcServerStatus)\r
+DECLARE_SC("CreateListener", RPC_LISTENER, ScCreateListener, InRpcListener, OutRpcListener)\r
+DECLARE_SC_EX("EnumListener", RPC_LISTENER_LIST, ScEnumListener, InRpcListenerList, OutRpcListenerList, FreeRpcListenerList)\r
+DECLARE_SC("DeleteListener", RPC_LISTENER, ScDeleteListener, InRpcListener, OutRpcListener)\r
+DECLARE_SC("EnableListener", RPC_LISTENER, ScEnableListener, InRpcListener, OutRpcListener)\r
+DECLARE_SC("SetServerPassword", RPC_SET_PASSWORD, ScSetServerPassword, InRpcSetPassword, OutRpcSetPassword)\r
+DECLARE_SC_EX("SetFarmSetting", RPC_FARM, ScSetFarmSetting, InRpcFarm, OutRpcFarm, FreeRpcFarm)\r
+DECLARE_SC_EX("GetFarmSetting", RPC_FARM, ScGetFarmSetting, InRpcFarm, OutRpcFarm, FreeRpcFarm)\r
+DECLARE_SC_EX("GetFarmInfo", RPC_FARM_INFO, ScGetFarmInfo, InRpcFarmInfo, OutRpcFarmInfo, FreeRpcFarmInfo)\r
+DECLARE_SC_EX("EnumFarmMember", RPC_ENUM_FARM, ScEnumFarmMember, InRpcEnumFarm, OutRpcEnumFarm, FreeRpcEnumFarm)\r
+DECLARE_SC("GetFarmConnectionStatus", RPC_FARM_CONNECTION_STATUS, ScGetFarmConnectionStatus, InRpcFarmConnectionStatus, OutRpcFarmConnectionStatus)\r
+DECLARE_SC_EX("SetServerCert", RPC_KEY_PAIR, ScSetServerCert, InRpcKeyPair, OutRpcKeyPair, FreeRpcKeyPair)\r
+DECLARE_SC_EX("GetServerCert", RPC_KEY_PAIR, ScGetServerCert, InRpcKeyPair, OutRpcKeyPair, FreeRpcKeyPair)\r
+DECLARE_SC_EX("GetServerCipher", RPC_STR, ScGetServerCipher, InRpcStr, OutRpcStr, FreeRpcStr)\r
+DECLARE_SC_EX("SetServerCipher", RPC_STR, ScSetServerCipher, InRpcStr, OutRpcStr, FreeRpcStr)\r
+DECLARE_SC("CreateHub", RPC_CREATE_HUB, ScCreateHub, InRpcCreateHub, OutRpcCreateHub)\r
+DECLARE_SC("SetHub", RPC_CREATE_HUB, ScSetHub, InRpcCreateHub, OutRpcCreateHub)\r
+DECLARE_SC("GetHub", RPC_CREATE_HUB, ScGetHub, InRpcCreateHub, OutRpcCreateHub)\r
+DECLARE_SC_EX("EnumHub", RPC_ENUM_HUB, ScEnumHub, InRpcEnumHub, OutRpcEnumHub, FreeRpcEnumHub)\r
+DECLARE_SC("DeleteHub", RPC_DELETE_HUB, ScDeleteHub, InRpcDeleteHub, OutRpcDeleteHub)\r
+DECLARE_SC("GetHubRadius", RPC_RADIUS, ScGetHubRadius, InRpcRadius, OutRpcRadius)\r
+DECLARE_SC("SetHubRadius", RPC_RADIUS, ScSetHubRadius, InRpcRadius, OutRpcRadius)\r
+DECLARE_SC_EX("EnumConnection", RPC_ENUM_CONNECTION, ScEnumConnection, InRpcEnumConnection, OutRpcEnumConnection, FreeRpcEnumConnetion)\r
+DECLARE_SC("DisconnectConnection", RPC_DISCONNECT_CONNECTION, ScDisconnectConnection, InRpcDisconnectConnection, OutRpcDisconnectConnection)\r
+DECLARE_SC("GetConnectionInfo", RPC_CONNECTION_INFO, ScGetConnectionInfo, InRpcConnectionInfo, OutRpcConnectionInfo)\r
+DECLARE_SC("SetHubOnline", RPC_SET_HUB_ONLINE, ScSetHubOnline, InRpcSetHubOnline, OutRpcSetHubOnline)\r
+DECLARE_SC("GetHubStatus", RPC_HUB_STATUS, ScGetHubStatus, InRpcHubStatus, OutRpcHubStatus)\r
+DECLARE_SC("SetHubLog", RPC_HUB_LOG, ScSetHubLog, InRpcHubLog, OutRpcHubLog)\r
+DECLARE_SC("GetHubLog", RPC_HUB_LOG, ScGetHubLog, InRpcHubLog, OutRpcHubLog)\r
+DECLARE_SC_EX("AddCa", RPC_HUB_ADD_CA, ScAddCa, InRpcHubAddCa, OutRpcHubAddCa, FreeRpcHubAddCa)\r
+DECLARE_SC_EX("EnumCa", RPC_HUB_ENUM_CA, ScEnumCa, InRpcHubEnumCa, OutRpcHubEnumCa, FreeRpcHubEnumCa)\r
+DECLARE_SC_EX("GetCa", RPC_HUB_GET_CA, ScGetCa, InRpcHubGetCa, OutRpcHubGetCa, FreeRpcHubGetCa)\r
+DECLARE_SC("DeleteCa", RPC_HUB_DELETE_CA, ScDeleteCa, InRpcHubDeleteCa, OutRpcHubDeleteCa)\r
+DECLARE_SC_EX("CreateLink", RPC_CREATE_LINK, ScCreateLink, InRpcCreateLink, OutRpcCreateLink, FreeRpcCreateLink)\r
+DECLARE_SC_EX("GetLink", RPC_CREATE_LINK, ScGetLink, InRpcCreateLink, OutRpcCreateLink, FreeRpcCreateLink)\r
+DECLARE_SC_EX("SetLink", RPC_CREATE_LINK, ScSetLink, InRpcCreateLink, OutRpcCreateLink, FreeRpcCreateLink)\r
+DECLARE_SC_EX("EnumLink", RPC_ENUM_LINK, ScEnumLink, InRpcEnumLink, OutRpcEnumLink, FreeRpcEnumLink)\r
+DECLARE_SC_EX("GetLinkStatus", RPC_LINK_STATUS, ScGetLinkStatus, InRpcLinkStatus, OutRpcLinkStatus, FreeRpcLinkStatus)\r
+DECLARE_SC("SetLinkOnline", RPC_LINK, ScSetLinkOnline, InRpcLink, OutRpcLink)\r
+DECLARE_SC("SetLinkOffline", RPC_LINK, ScSetLinkOffline, InRpcLink, OutRpcLink)\r
+DECLARE_SC("DeleteLink", RPC_LINK, ScDeleteLink, InRpcLink, OutRpcLink)\r
+DECLARE_SC("RenameLink", RPC_RENAME_LINK, ScRenameLink, InRpcRenameLink, OutRpcRenameLink)\r
+DECLARE_SC("AddAccess", RPC_ADD_ACCESS, ScAddAccess, InRpcAddAccess, OutRpcAddAccess)\r
+DECLARE_SC("DeleteAccess", RPC_DELETE_ACCESS, ScDeleteAccess, InRpcDeleteAccess, OutRpcDeleteAccess)\r
+DECLARE_SC_EX("EnumAccess", RPC_ENUM_ACCESS_LIST, ScEnumAccess, InRpcEnumAccessList, OutRpcEnumAccessList, FreeRpcEnumAccessList)\r
+DECLARE_SC_EX("SetAccessList", RPC_ENUM_ACCESS_LIST, ScSetAccessList, InRpcEnumAccessList, OutRpcEnumAccessList, FreeRpcEnumAccessList)\r
+DECLARE_SC_EX("CreateUser", RPC_SET_USER, ScCreateUser, InRpcSetUser, OutRpcSetUser, FreeRpcSetUser)\r
+DECLARE_SC_EX("SetUser", RPC_SET_USER, ScSetUser, InRpcSetUser, OutRpcSetUser, FreeRpcSetUser)\r
+DECLARE_SC_EX("GetUser", RPC_SET_USER, ScGetUser, InRpcSetUser, OutRpcSetUser, FreeRpcSetUser)\r
+DECLARE_SC("DeleteUser", RPC_DELETE_USER, ScDeleteUser, InRpcDeleteUser, OutRpcDeleteUser)\r
+DECLARE_SC_EX("EnumUser", RPC_ENUM_USER, ScEnumUser, InRpcEnumUser, OutRpcEnumUser, FreeRpcEnumUser)\r
+DECLARE_SC_EX("CreateGroup", RPC_SET_GROUP, ScCreateGroup, InRpcSetGroup, OutRpcSetGroup, FreeRpcSetGroup)\r
+DECLARE_SC_EX("SetGroup", RPC_SET_GROUP, ScSetGroup, InRpcSetGroup, OutRpcSetGroup, FreeRpcSetGroup)\r
+DECLARE_SC_EX("GetGroup", RPC_SET_GROUP, ScGetGroup, InRpcSetGroup, OutRpcSetGroup, FreeRpcSetGroup)\r
+DECLARE_SC("DeleteGroup", RPC_DELETE_USER, ScDeleteGroup, InRpcDeleteUser, OutRpcDeleteUser)\r
+DECLARE_SC_EX("EnumGroup", RPC_ENUM_GROUP, ScEnumGroup, InRpcEnumGroup, OutRpcEnumGroup, FreeRpcEnumGroup)\r
+DECLARE_SC_EX("EnumSession", RPC_ENUM_SESSION, ScEnumSession, InRpcEnumSession, OutRpcEnumSession, FreeRpcEnumSession)\r
+DECLARE_SC_EX("GetSessionStatus", RPC_SESSION_STATUS, ScGetSessionStatus, InRpcSessionStatus, OutRpcSessionStatus, FreeRpcSessionStatus)\r
+DECLARE_SC("DeleteSession", RPC_DELETE_SESSION, ScDeleteSession, InRpcDeleteSession, OutRpcDeleteSession)\r
+DECLARE_SC_EX("EnumMacTable", RPC_ENUM_MAC_TABLE, ScEnumMacTable, InRpcEnumMacTable, OutRpcEnumMacTable, FreeRpcEnumMacTable)\r
+DECLARE_SC("DeleteMacTable", RPC_DELETE_TABLE, ScDeleteMacTable, InRpcDeleteTable, OutRpcDeleteTable)\r
+DECLARE_SC_EX("EnumIpTable", RPC_ENUM_IP_TABLE, ScEnumIpTable, InRpcEnumIpTable, OutRpcEnumIpTable, FreeRpcEnumIpTable)\r
+DECLARE_SC("DeleteIpTable", RPC_DELETE_TABLE, ScDeleteIpTable, InRpcDeleteTable, OutRpcDeleteTable)\r
+DECLARE_SC("SetKeep", RPC_KEEP, ScSetKeep, InRpcKeep, OutRpcKeep)\r
+DECLARE_SC("GetKeep", RPC_KEEP, ScGetKeep, InRpcKeep, OutRpcKeep)\r
+DECLARE_SC("EnableSecureNAT", RPC_HUB, ScEnableSecureNAT, InRpcHub, OutRpcHub)\r
+DECLARE_SC("DisableSecureNAT", RPC_HUB, ScDisableSecureNAT, InRpcHub, OutRpcHub)\r
+DECLARE_SC("SetSecureNATOption", VH_OPTION, ScSetSecureNATOption, InVhOption, OutVhOption)\r
+DECLARE_SC("GetSecureNATOption", VH_OPTION, ScGetSecureNATOption, InVhOption, OutVhOption)\r
+DECLARE_SC_EX("EnumNAT", RPC_ENUM_NAT, ScEnumNAT, InRpcEnumNat, OutRpcEnumNat, FreeRpcEnumNat)\r
+DECLARE_SC_EX("EnumDHCP", RPC_ENUM_DHCP, ScEnumDHCP, InRpcEnumDhcp, OutRpcEnumDhcp, FreeRpcEnumDhcp)\r
+DECLARE_SC("GetSecureNATStatus", RPC_NAT_STATUS, ScGetSecureNATStatus, InRpcNatStatus, OutRpcNatStatus)\r
+DECLARE_SC_EX("EnumEthernet", RPC_ENUM_ETH, ScEnumEthernet, InRpcEnumEth, OutRpcEnumEth, FreeRpcEnumEth)\r
+DECLARE_SC("AddLocalBridge", RPC_LOCALBRIDGE, ScAddLocalBridge, InRpcLocalBridge, OutRpcLocalBridge)\r
+DECLARE_SC("DeleteLocalBridge", RPC_LOCALBRIDGE, ScDeleteLocalBridge, InRpcLocalBridge, OutRpcLocalBridge)\r
+DECLARE_SC_EX("EnumLocalBridge", RPC_ENUM_LOCALBRIDGE, ScEnumLocalBridge, InRpcEnumLocalBridge, OutRpcEnumLocalBridge, FreeRpcEnumLocalBridge)\r
+DECLARE_SC("GetBridgeSupport", RPC_BRIDGE_SUPPORT, ScGetBridgeSupport, InRpcBridgeSupport, OutRpcBridgeSupport)\r
+DECLARE_SC("RebootServer", RPC_TEST, ScRebootServer, InRpcTest, OutRpcTest)\r
+DECLARE_SC_EX("GetCaps", CAPSLIST, ScGetCaps, InRpcCapsList, OutRpcCapsList, FreeRpcCapsList)\r
+DECLARE_SC_EX("GetConfig", RPC_CONFIG, ScGetConfig, InRpcConfig, OutRpcConfig, FreeRpcConfig)\r
+DECLARE_SC_EX("SetConfig", RPC_CONFIG, ScSetConfig, InRpcConfig, OutRpcConfig, FreeRpcConfig)\r
+DECLARE_SC_EX("GetHubAdminOptions", RPC_ADMIN_OPTION, ScGetHubAdminOptions, InRpcAdminOption, OutRpcAdminOption, FreeRpcAdminOption)\r
+DECLARE_SC_EX("SetHubAdminOptions", RPC_ADMIN_OPTION, ScSetHubAdminOptions, InRpcAdminOption, OutRpcAdminOption, FreeRpcAdminOption)\r
+DECLARE_SC_EX("GetHubExtOptions", RPC_ADMIN_OPTION, ScGetHubExtOptions, InRpcAdminOption, OutRpcAdminOption, FreeRpcAdminOption)\r
+DECLARE_SC_EX("SetHubExtOptions", RPC_ADMIN_OPTION, ScSetHubExtOptions, InRpcAdminOption, OutRpcAdminOption, FreeRpcAdminOption)\r
+DECLARE_SC_EX("GetDefaultHubAdminOptions", RPC_ADMIN_OPTION, ScGetDefaultHubAdminOptions, InRpcAdminOption, OutRpcAdminOption, FreeRpcAdminOption)\r
+DECLARE_SC("AddL3Switch", RPC_L3SW, ScAddL3Switch, InRpcL3Sw, OutRpcL3Sw)\r
+DECLARE_SC("DelL3Switch", RPC_L3SW, ScDelL3Switch, InRpcL3Sw, OutRpcL3Sw)\r
+DECLARE_SC_EX("EnumL3Switch", RPC_ENUM_L3SW, ScEnumL3Switch, InRpcEnumL3Sw, OutRpcEnumL3Sw, FreeRpcEnumL3Sw)\r
+DECLARE_SC("StartL3Switch", RPC_L3SW, ScStartL3Switch, InRpcL3Sw, OutRpcL3Sw)\r
+DECLARE_SC("StopL3Switch", RPC_L3SW, ScStopL3Switch, InRpcL3Sw, OutRpcL3Sw)\r
+DECLARE_SC("AddL3If", RPC_L3IF, ScAddL3If, InRpcL3If, OutRpcL3If)\r
+DECLARE_SC("DelL3If", RPC_L3IF, ScDelL3If, InRpcL3If, OutRpcL3If)\r
+DECLARE_SC_EX("EnumL3If", RPC_ENUM_L3IF, ScEnumL3If, InRpcEnumL3If, OutRpcEnumL3If, FreeRpcEnumL3If)\r
+DECLARE_SC("AddL3Table", RPC_L3TABLE, ScAddL3Table, InRpcL3Table, OutRpcL3Table)\r
+DECLARE_SC("DelL3Table", RPC_L3TABLE, ScDelL3Table, InRpcL3Table, OutRpcL3Table)\r
+DECLARE_SC_EX("EnumL3Table", RPC_ENUM_L3TABLE, ScEnumL3Table, InRpcEnumL3Table, OutRpcEnumL3Table, FreeRpcEnumL3Table)\r
+DECLARE_SC_EX("EnumCrl", RPC_ENUM_CRL, ScEnumCrl, InRpcEnumCrl, OutRpcEnumCrl, FreeRpcEnumCrl)\r
+DECLARE_SC_EX("AddCrl", RPC_CRL, ScAddCrl, InRpcCrl, OutRpcCrl, FreeRpcCrl)\r
+DECLARE_SC_EX("DelCrl", RPC_CRL, ScDelCrl, InRpcCrl, OutRpcCrl, FreeRpcCrl)\r
+DECLARE_SC_EX("GetCrl", RPC_CRL, ScGetCrl, InRpcCrl, OutRpcCrl, FreeRpcCrl)\r
+DECLARE_SC_EX("SetCrl", RPC_CRL, ScSetCrl, InRpcCrl, OutRpcCrl, FreeRpcCrl)\r
+DECLARE_SC_EX("SetAcList", RPC_AC_LIST, ScSetAcList, InRpcAcList, OutRpcAcList, FreeRpcAcList)\r
+DECLARE_SC_EX("GetAcList", RPC_AC_LIST, ScGetAcList, InRpcAcList, OutRpcAcList, FreeRpcAcList)\r
+DECLARE_SC_EX("EnumLogFile", RPC_ENUM_LOG_FILE, ScEnumLogFile, InRpcEnumLogFile, OutRpcEnumLogFile, FreeRpcEnumLogFile)\r
+DECLARE_SC_EX("ReadLogFile", RPC_READ_LOG_FILE, ScReadLogFile, InRpcReadLogFile, OutRpcReadLogFile, FreeRpcReadLogFile)\r
+DECLARE_SC("AddLicenseKey", RPC_TEST, ScAddLicenseKey, InRpcTest, OutRpcTest)\r
+DECLARE_SC("DelLicenseKey", RPC_TEST, ScDelLicenseKey, InRpcTest, OutRpcTest)\r
+DECLARE_SC_EX("EnumLicenseKey", RPC_ENUM_LICENSE_KEY, ScEnumLicenseKey, InRpcEnumLicenseKey, OutRpcEnumLicenseKey, FreeRpcEnumLicenseKey)\r
+DECLARE_SC("GetLicenseStatus", RPC_LICENSE_STATUS, ScGetLicenseStatus, InRpcLicenseStatus, OutRpcLicenseStatus)\r
+DECLARE_SC("SetSysLog", SYSLOG_SETTING, ScSetSysLog, InRpcSysLogSetting, OutRpcSysLogSetting)\r
+DECLARE_SC("GetSysLog", SYSLOG_SETTING, ScGetSysLog, InRpcSysLogSetting, OutRpcSysLogSetting)\r
+DECLARE_SC_EX("EnumEthVLan", RPC_ENUM_ETH_VLAN, ScEnumEthVLan, InRpcEnumEthVLan, OutRpcEnumEthVLan, FreeRpcEnumEthVLan)\r
+DECLARE_SC("SetEnableEthVLan", RPC_TEST, ScSetEnableEthVLan, InRpcTest, OutRpcTest)\r
+DECLARE_SC_EX("SetHubMsg", RPC_MSG, ScSetHubMsg, InRpcMsg, OutRpcMsg, FreeRpcMsg)\r
+DECLARE_SC_EX("GetHubMsg", RPC_MSG, ScGetHubMsg, InRpcMsg, OutRpcMsg, FreeRpcMsg)\r
+DECLARE_SC("Crash", RPC_TEST, ScCrash, InRpcTest, OutRpcTest)\r
+DECLARE_SC_EX("GetAdminMsg", RPC_MSG, ScGetAdminMsg, InRpcMsg, OutRpcMsg, FreeRpcMsg)\r
+DECLARE_SC("Flush", RPC_TEST, ScFlush, InRpcTest, OutRpcTest)\r
+DECLARE_SC("Debug", RPC_TEST, ScDebug, InRpcTest, OutRpcTest)\r
+// RPC 呼び出し関数定義: ここまで\r
+\r
+\r
+// メッセージを設定\r
+UINT StSetHubMsg(ADMIN *a, RPC_MSG *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+       if (UniStrLen(t->Msg) > HUB_MAXMSG_LEN)\r
+       {\r
+               return ERR_MEMORY_NOT_ENOUGH;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       h = GetHub(c, hubname);\r
+\r
+       if (h == NULL)\r
+       {\r
+               ret = ERR_HUB_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_msg") != 0)\r
+               {\r
+                       ret = ERR_NOT_ENOUGH_RIGHT;\r
+               }\r
+               else\r
+               {\r
+                       SetHubMsg(h, t->Msg);\r
+               }\r
+\r
+               ReleaseHub(h);\r
+       }\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// メッセージを取得\r
+UINT StGetHubMsg(ADMIN *a, RPC_MSG *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+       if (UniStrLen(t->Msg) > HUB_MAXMSG_LEN)\r
+       {\r
+               return ERR_MEMORY_NOT_ENOUGH;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       FreeRpcMsg(t);\r
+       Zero(t, sizeof(t));\r
+\r
+       h = GetHub(c, hubname);\r
+\r
+       if (h == NULL)\r
+       {\r
+               ret = ERR_HUB_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               t->Msg = GetHubMsg(h);\r
+\r
+               ReleaseHub(h);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// デバッグ機能を実行する\r
+UINT StDebug(ADMIN *a, RPC_TEST *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_TEST t2;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       Zero(&t2, sizeof(t2));\r
+\r
+       ret = SiDebug(s, &t2, t->IntValue, t->StrValue);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               Copy(t, &t2, sizeof(RPC_TEST));\r
+       }\r
+       else\r
+       {\r
+               Zero(t, sizeof(RPC_TEST));\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 設定ファイルをフラッシュする\r
+UINT StFlush(ADMIN *a, RPC_TEST *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       UINT size;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       size = SiWriteConfigurationFile(s);\r
+\r
+       t->IntValue = size;\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// クラッシュさせる (システム管理者だけが実行できる緊急時用コード)\r
+UINT StCrash(ADMIN *a, RPC_TEST *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+#ifdef OS_WIN32\r
+       MsSetEnableMinidump(false);\r
+#endif // OS_WIN32\r
+\r
+       CrashNow();\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// 管理者向けメッセージを取得する\r
+UINT StGetAdminMsg(ADMIN *a, RPC_MSG *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_WINVER server_ver;\r
+       RPC_WINVER client_ver;\r
+       wchar_t winver_msg_client[3800];\r
+       wchar_t winver_msg_server[3800];\r
+       wchar_t *utvpn_msg;\r
+       UINT tmpsize;\r
+       wchar_t *tmp;\r
+\r
+       FreeRpcMsg(t);\r
+       Zero(t, sizeof(RPC_MSG));\r
+\r
+       // Windows バージョンチェック\r
+       GetWinVer(&server_ver);\r
+       Copy(&client_ver, &a->ClientWinVer, sizeof(RPC_WINVER));\r
+\r
+       Zero(winver_msg_client, sizeof(winver_msg_client));\r
+       Zero(winver_msg_server, sizeof(winver_msg_server));\r
+\r
+       utvpn_msg = _UU("UTVPN_MSG");\r
+\r
+       if (IsSupportedWinVer(&client_ver) == false)\r
+       {\r
+               SYSTEMTIME st;\r
+\r
+               LocalTime(&st);\r
+\r
+               UniFormat(winver_msg_client, sizeof(winver_msg_client), _UU("WINVER_ERROR_FORMAT"),\r
+                       _UU("WINVER_ERROR_PC_LOCAL"),\r
+                       client_ver.Title,\r
+                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                       SUPPORTED_WINDOWS_LIST,\r
+                       _UU("WINVER_ERROR_PC_LOCAL"),\r
+                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                       st.wYear, st.wMonth);\r
+       }\r
+\r
+       if (IsSupportedWinVer(&server_ver) == false)\r
+       {\r
+               SYSTEMTIME st;\r
+\r
+               LocalTime(&st);\r
+\r
+               UniFormat(winver_msg_server, sizeof(winver_msg_server), _UU("WINVER_ERROR_FORMAT"),\r
+                       _UU("WINVER_ERROR_PC_REMOTE"),\r
+                       server_ver.Title,\r
+                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                       SUPPORTED_WINDOWS_LIST,\r
+                       _UU("WINVER_ERROR_PC_REMOTE"),\r
+                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                       st.wYear, st.wMonth);\r
+       }\r
+\r
+       tmpsize = UniStrSize(winver_msg_client) + UniStrSize(winver_msg_server) + UniStrSize(utvpn_msg) + 100;\r
+\r
+       tmp = ZeroMalloc(tmpsize);\r
+       UniStrCat(tmp, tmpsize, utvpn_msg);\r
+       UniStrCat(tmp, tmpsize, winver_msg_client);\r
+       UniStrCat(tmp, tmpsize, winver_msg_server);\r
+\r
+       t->Msg = tmp;\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// VLAN 透過設定一覧の取得\r
+UINT StEnumEthVLan(ADMIN *a, RPC_ENUM_ETH_VLAN *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+#ifdef OS_WIN32\r
+       if (GetServerCapsBool(s, "b_support_eth_vlan") == false)\r
+       {\r
+               ret = ERR_NOT_SUPPORTED;\r
+       }\r
+       else\r
+       {\r
+               FreeRpcEnumEthVLan(t);\r
+               Zero(t, sizeof(RPC_ENUM_ETH_VLAN));\r
+\r
+               if (EnumEthVLanWin32(t) == false)\r
+               {\r
+                       ret = ERR_INTERNAL_ERROR;\r
+               }\r
+       }\r
+#else  // OS_WIN32\r
+       ret = ERR_NOT_SUPPORTED;\r
+#endif // OS_WIN32\r
+\r
+       return ret;\r
+}\r
+\r
+// VLAN 透過設定の設定\r
+UINT StSetEnableEthVLan(ADMIN *a, RPC_TEST *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+#ifdef OS_WIN32\r
+       if (GetServerCapsBool(s, "b_support_eth_vlan") == false)\r
+       {\r
+               ret = ERR_NOT_SUPPORTED;\r
+       }\r
+       else if (MsIsAdmin() == false)\r
+       {\r
+               ret = ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+       else\r
+       {\r
+               if (SetVLanEnableStatus(t->StrValue, MAKEBOOL(t->IntValue)) == false)\r
+               {\r
+                       ret = ERR_INTERNAL_ERROR;\r
+               }\r
+       }\r
+#else  // OS_WIN32\r
+       ret = ERR_NOT_SUPPORTED;\r
+#endif // OS_WIN32\r
+\r
+       return ret;\r
+}\r
+\r
+// ライセンス状態の取得\r
+// (ソフトイーサ社の製品 PacketiX VPN の管理に使えるように互換性を残している)\r
+UINT StGetLicenseStatus(ADMIN *a, RPC_LICENSE_STATUS *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       LICENSE_SYSTEM *ls = s->LicenseSystem;\r
+       LICENSE_STATUS status;\r
+\r
+       if (ls == NULL)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       Zero(t, sizeof(RPC_LICENSE_STATUS));\r
+\r
+       // 現在のライセンスステータスを取得\r
+       LiParseCurrentLicenseStatus(ls, &status);\r
+\r
+       t->EditionId = status.Edition;\r
+       StrCpy(t->EditionStr, sizeof(t->EditionStr), status.EditionStr);\r
+       t->SystemId = status.SystemId;\r
+       t->SystemExpires = status.Expires;\r
+       t->NumClientConnectLicense = status.NumClientLicense;\r
+       t->NumBridgeConnectLicense = status.NumBridgeLicense;\r
+       t->NumUserCreationLicense = status.NumUserLicense;\r
+       t->SubscriptionExpires = status.SubscriptionExpires;\r
+       t->IsSubscriptionExpired = status.IsSubscriptionExpired;\r
+       t->NeedSubscription = status.NeedSubscription;\r
+       t->AllowEnterpriseFunction = status.AllowEnterpriseFunction;\r
+       t->ReleaseDate = c->BuiltDate;\r
+\r
+       return ret;\r
+}\r
+\r
+// ライセンスキーの列挙\r
+// (ソフトイーサ社の製品 PacketiX VPN の管理に使えるように互換性を残している)\r
+UINT StEnumLicenseKey(ADMIN *a, RPC_ENUM_LICENSE_KEY *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       LICENSE_SYSTEM *ls = s->LicenseSystem;\r
+\r
+       if (ls == NULL)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       FreeRpcEnumLicenseKey(t);\r
+       Zero(t, sizeof(RPC_ENUM_LICENSE_KEY));\r
+\r
+       LockList(ls->LicenseList);\r
+       {\r
+               UINT i;\r
+\r
+               t->NumItem = LIST_NUM(ls->LicenseList);\r
+               t->Items = ZeroMalloc(sizeof(RPC_ENUM_LICENSE_KEY_ITEM) * t->NumItem);\r
+\r
+               for (i = 0;i < t->NumItem;i++)\r
+               {\r
+                       RPC_ENUM_LICENSE_KEY_ITEM *k = &t->Items[i];\r
+                       LICENSE *e = LIST_DATA(ls->LicenseList, i);\r
+\r
+                       k->Id = e->Id;\r
+                       k->Expires = e->Expires;\r
+                       StrCpy(k->LicenseId, sizeof(k->LicenseId), e->LicenseIdStr);\r
+                       StrCpy(k->LicenseKey, sizeof(k->LicenseKey), e->LicenseKeyStr);\r
+                       StrCpy(k->LicenseName, sizeof(k->LicenseName), e->Name);\r
+                       k->Status = e->Status;\r
+                       k->ProductId = e->ProductId;\r
+                       k->SystemId = e->SystemId;\r
+                       k->SerialId = e->SerialId;\r
+               }\r
+       }\r
+       UnlockList(ls->LicenseList);\r
+\r
+       return ret;\r
+}\r
+\r
+// ライセンスキーの追加\r
+// (ソフトイーサ社の製品 PacketiX VPN の管理に使えるように互換性を残している)\r
+UINT StAddLicenseKey(ADMIN *a, RPC_TEST *t)\r
+{\r
+       return ERR_NOT_SUPPORTED;\r
+}\r
+\r
+// ライセンスキーの削除\r
+// (ソフトイーサ社の製品 PacketiX VPN の管理に使えるように互換性を残している)\r
+UINT StDelLicenseKey(ADMIN *a, RPC_TEST *t)\r
+{\r
+       return ERR_NOT_SUPPORTED;\r
+}\r
+\r
+// ログファイルのダウンロード\r
+BUF *DownloadFileFromServer(RPC *r, char *server_name, char *filepath, UINT total_size, DOWNLOAD_PROC *proc, void *param)\r
+{\r
+       UINT offset;\r
+       BUF *buf;\r
+       // 引数チェック\r
+       if (r == NULL || filepath == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (server_name == NULL)\r
+       {\r
+               server_name = "";\r
+       }\r
+\r
+       offset = 0;\r
+\r
+       buf = NewBuf();\r
+\r
+       while (true)\r
+       {\r
+               DOWNLOAD_PROGRESS g;\r
+               RPC_READ_LOG_FILE t;\r
+               UINT ret;\r
+\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.FilePath, sizeof(t.FilePath), filepath);\r
+               t.Offset = offset;\r
+               StrCpy(t.ServerName, sizeof(t.ServerName), server_name);\r
+\r
+               ret = ScReadLogFile(r, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // 失敗\r
+                       FreeRpcReadLogFile(&t);\r
+                       FreeBuf(buf);\r
+                       return NULL;\r
+               }\r
+\r
+               if (t.Buffer == NULL)\r
+               {\r
+                       // 最後まで読み込んだ\r
+                       break;\r
+               }\r
+\r
+               // 現在の状況を更新\r
+               offset += t.Buffer->Size;\r
+               Zero(&g, sizeof(g));\r
+               g.Param = param;\r
+               g.CurrentSize = offset;\r
+               g.TotalSize = MAX(total_size, offset);\r
+               g.ProgressPercent = (UINT)(MAKESURE((UINT64)g.CurrentSize * 100ULL / (UINT64)(MAX(g.TotalSize, 1)), 0, 100ULL));\r
+\r
+               WriteBuf(buf, t.Buffer->Buf, t.Buffer->Size);\r
+\r
+               FreeRpcReadLogFile(&t);\r
+\r
+               if (proc != NULL)\r
+               {\r
+                       if (proc(&g) == false)\r
+                       {\r
+                               // ユーザーキャンセル\r
+                               FreeBuf(buf);\r
+                               return NULL;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (buf->Size == 0)\r
+       {\r
+               // ダウンロード失敗\r
+               FreeBuf(buf);\r
+               return NULL;\r
+       }\r
+\r
+       return buf;\r
+}\r
+\r
+// ログファイルの読み込み\r
+UINT StReadLogFile(ADMIN *a, RPC_READ_LOG_FILE *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       char logfilename[MAX_PATH];\r
+       char servername[MAX_HOST_NAME_LEN + 1];\r
+       UINT offset;\r
+       bool local = true;\r
+\r
+       if (IsEmptyStr(t->FilePath))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       StrCpy(logfilename, sizeof(logfilename), t->FilePath);\r
+       StrCpy(servername, sizeof(servername), t->ServerName);\r
+       offset = t->Offset;\r
+\r
+       if (s->ServerType != SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               GetMachineName(servername, sizeof(servername));\r
+       }\r
+\r
+       // ログファイルを読み込む権限があるかどうか検査する\r
+       if (a->LogFileList == NULL)\r
+       {\r
+               // キャッシュ無し\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+       if (CheckLogFileNameFromEnumList(a->LogFileList, logfilename, servername) == false)\r
+       {\r
+               // そのようなファイルは列挙リストに無い\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+\r
+       FreeRpcReadLogFile(t);\r
+       Zero(t, sizeof(RPC_READ_LOG_FILE));\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               UINT i;\r
+\r
+               // 要求されたファイルのサーバー名がクラスタメンバのホスト名\r
+               // と一致した場合はリモートサーバー上にファイルが存在するのでそれを読み込む\r
+               LockList(s->FarmMemberList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                       {\r
+                               FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+\r
+                               if (f->Me == false)\r
+                               {\r
+                                       if (StrCmpi(f->hostname, servername) == 0)\r
+                                       {\r
+                                               RPC_READ_LOG_FILE tt;\r
+\r
+                                               Zero(&tt, sizeof(tt));\r
+                                               local = false;\r
+\r
+                                               StrCpy(tt.ServerName, sizeof(tt.ServerName), servername);\r
+                                               StrCpy(tt.FilePath, sizeof(tt.FilePath), logfilename);\r
+                                               tt.Offset = offset;\r
+\r
+                                               if (SiCallReadLogFile(s, f, &tt))\r
+                                               {\r
+                                                       if (tt.Buffer != NULL && tt.Buffer->Size > 0)\r
+                                                       {\r
+                                                               t->Buffer = NewBuf();\r
+                                                               WriteBuf(t->Buffer, tt.Buffer->Buf, tt.Buffer->Size);\r
+                                                       }\r
+                                               }\r
+\r
+                                               FreeRpcReadLogFile(&tt);\r
+\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(s->FarmMemberList);\r
+       }\r
+\r
+       // ローカルファイルの読み込み\r
+       if (local)\r
+       {\r
+               SiReadLocalLogFile(s, logfilename, offset, t);\r
+       }\r
+\r
+       if (offset == 0)\r
+       {\r
+               ALog(a, NULL, "LA_READ_LOG_FILE", servername, logfilename);\r
+       }\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// ログファイルの列挙\r
+UINT StEnumLogFile(ADMIN *a, RPC_ENUM_LOG_FILE *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT i;\r
+       bool no_access = false;\r
+\r
+       HUB *h;\r
+\r
+       if (a->ServerAdmin == false)\r
+       {\r
+               h = GetHub(c, a->HubName);\r
+\r
+               if (a->ServerAdmin == false && GetHubAdminOption(h, "no_read_log_file") != 0)\r
+               {\r
+                       no_access = true;\r
+               }\r
+\r
+               ReleaseHub(h);\r
+       }\r
+       else\r
+       {\r
+               if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+               {\r
+                       // クラスタコントローラで管理者がログファイルの一覧を取得する\r
+                       // と高負荷になるため制限している\r
+                       return ERR_NOT_SUPPORTED;\r
+               }\r
+       }\r
+\r
+       if (no_access)\r
+       {\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       FreeRpcEnumLogFile(t);\r
+       Zero(t, sizeof(RPC_ENUM_LOG_FILE));\r
+\r
+       // ローカルのログファイルを列挙する\r
+       SiEnumLocalLogFileList(s, a->ServerAdmin ? NULL : a->HubName, t);\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               UINT i;\r
+               LIST *tt_list = NewListFast(NULL);\r
+\r
+               LockList(s->FarmMemberList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                       {\r
+                               FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+\r
+                               if (f->Me == false)\r
+                               {\r
+                                       // 他のメンバ上のログファイルを列挙する\r
+                                       RPC_ENUM_LOG_FILE *tt;\r
+                                       tt = ZeroMalloc(sizeof(RPC_ENUM_LOG_FILE));\r
+\r
+                                       if (SiCallEnumLogFileList(s, f, tt, a->ServerAdmin ? "" : a->HubName))\r
+                                       {\r
+                                               UINT i;\r
+                                               for (i = 0;i < tt->NumItem;i++)\r
+                                               {\r
+                                                       RPC_ENUM_LOG_FILE_ITEM *e = &tt->Items[i];\r
+\r
+                                                       StrCpy(e->ServerName, sizeof(e->ServerName), f->hostname);\r
+                                               }\r
+\r
+                                               Add(tt_list, tt);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               Free(tt);\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(s->FarmMemberList);\r
+\r
+               for (i = 0;i < LIST_NUM(tt_list);i++)\r
+               {\r
+                       RPC_ENUM_LOG_FILE *tt = LIST_DATA(tt_list, i);\r
+\r
+                       AdjoinRpcEnumLogFile(t, tt);\r
+                       FreeRpcEnumLogFile(tt);\r
+\r
+                       Free(tt);\r
+               }\r
+\r
+               ReleaseList(tt_list);\r
+       }\r
+\r
+       // RPC セッションに最後に列挙したログファイル一覧をキャッシュする\r
+       if (a->LogFileList != NULL)\r
+       {\r
+               FreeEnumLogFile(a->LogFileList);\r
+       }\r
+\r
+       a->LogFileList = NewListFast(CmpLogFile);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_LOG_FILE_ITEM *e = &t->Items[i];\r
+               LOG_FILE *f = ZeroMalloc(sizeof(LOG_FILE));\r
+\r
+               f->FileSize = e->FileSize;\r
+               f->UpdatedTime = e->UpdatedTime;\r
+               StrCpy(f->Path, sizeof(f->Path), e->FilePath);\r
+               StrCpy(f->ServerName, sizeof(f->ServerName), e->ServerName);\r
+\r
+               Insert(a->LogFileList, f);\r
+       }\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+\r
+// AC リストの取得\r
+UINT StGetAcList(ADMIN *a, RPC_AC_LIST *t)\r
+{\r
+       return ERR_NOT_SUPPORTED;\r
+}\r
+\r
+// AC リストの設定\r
+UINT StSetAcList(ADMIN *a, RPC_AC_LIST *t)\r
+{\r
+       return ERR_NOT_SUPPORTED;\r
+}\r
+\r
+// CRL の設定\r
+UINT StSetCrl(ADMIN *a, RPC_CRL *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       UINT key;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       key = t->Key;\r
+\r
+       h = GetHub(c, hubname);\r
+\r
+       if (h == NULL)\r
+       {\r
+               ret = ERR_HUB_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_crl_list") != 0)\r
+               {\r
+                       ret = ERR_NOT_ENOUGH_RIGHT;\r
+               }\r
+               else\r
+               {\r
+                       if (h->HubDb == NULL)\r
+                       {\r
+                               ret = ERR_NOT_SUPPORTED;\r
+                       }\r
+                       else\r
+                       {\r
+                               LockList(h->HubDb->CrlList);\r
+                               {\r
+                                       CRL *crl = ListKeyToPointer(h->HubDb->CrlList, t->Key);\r
+\r
+                                       if (crl == NULL)\r
+                                       {\r
+                                               ret = ERR_INTERNAL_ERROR;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               CRL *new_crl = CopyCrl(t->Crl);\r
+                                               if (ReplaceListPointer(h->HubDb->CrlList, crl, new_crl))\r
+                                               {\r
+                                                       ALog(a, h, "LA_ADD_CRL");\r
+                                                       FreeCrl(crl);\r
+\r
+                                                       IncrementServerConfigRevision(s);\r
+                                               }\r
+                                       }\r
+                               }\r
+                               UnlockList(h->HubDb->CrlList);\r
+                       }\r
+               }\r
+\r
+               ReleaseHub(h);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// CRL の取得\r
+UINT StGetCrl(ADMIN *a, RPC_CRL *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       UINT key;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       key = t->Key;\r
+\r
+       FreeRpcCrl(t);\r
+       Zero(t, sizeof(RPC_CRL));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+       t->Key = key;\r
+\r
+       h = GetHub(c, hubname);\r
+\r
+       if (h == NULL)\r
+       {\r
+               ret = ERR_HUB_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               if (h->HubDb == NULL)\r
+               {\r
+                       ret = ERR_NOT_SUPPORTED;\r
+               }\r
+               else\r
+               {\r
+                       LockList(h->HubDb->CrlList);\r
+                       {\r
+                               CRL *crl = ListKeyToPointer(h->HubDb->CrlList, t->Key);\r
+\r
+                               if (crl == NULL)\r
+                               {\r
+                                       ret = ERR_INTERNAL_ERROR;\r
+                               }\r
+                               else\r
+                               {\r
+                                       t->Crl = CopyCrl(crl);\r
+                               }\r
+                       }\r
+                       UnlockList(h->HubDb->CrlList);\r
+               }\r
+\r
+               ReleaseHub(h);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// CRL の削除\r
+UINT StDelCrl(ADMIN *a, RPC_CRL *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       h = GetHub(c, hubname);\r
+\r
+       if (h == NULL)\r
+       {\r
+               ret = ERR_HUB_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_crl_list") != 0)\r
+               {\r
+                       ret = ERR_NOT_ENOUGH_RIGHT;\r
+               }\r
+               else\r
+               {\r
+                       if (h->HubDb == NULL)\r
+                       {\r
+                               ret = ERR_NOT_SUPPORTED;\r
+                       }\r
+                       else\r
+                       {\r
+                               LockList(h->HubDb->CrlList);\r
+                               {\r
+                                       CRL *crl = ListKeyToPointer(h->HubDb->CrlList, t->Key);\r
+\r
+                                       if (crl == NULL)\r
+                                       {\r
+                                               ret = ERR_INTERNAL_ERROR;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               ALog(a, h, "LA_DEL_CRL");\r
+                                               FreeCrl(crl);\r
+                                               Delete(h->HubDb->CrlList, crl);\r
+                                       }\r
+                               }\r
+                               UnlockList(h->HubDb->CrlList);\r
+                       }\r
+               }\r
+\r
+               ReleaseHub(h);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// CRL の追加\r
+UINT StAddCrl(ADMIN *a, RPC_CRL *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+\r
+       if (c->Bridge)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       h = GetHub(c, hubname);\r
+\r
+       if (h == NULL)\r
+       {\r
+               ret = ERR_HUB_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_crl_list") != 0)\r
+               {\r
+                       ret = ERR_NOT_ENOUGH_RIGHT;\r
+               }\r
+               else\r
+               {\r
+                       if (h->HubDb == NULL)\r
+                       {\r
+                               ret = ERR_NOT_SUPPORTED;\r
+                       }\r
+                       else\r
+                       {\r
+                               LockList(h->HubDb->CrlList);\r
+                               {\r
+                                       if (LIST_NUM(h->HubDb->CrlList) < MAX_HUB_CRLS)\r
+                                       {\r
+                                               CRL *crl = CopyCrl(t->Crl);\r
+\r
+                                               Insert(h->HubDb->CrlList, crl);\r
+\r
+                                               ALog(a, h, "LA_SET_CRL");\r
+\r
+                                               IncrementServerConfigRevision(s);\r
+                                       }\r
+                               }\r
+                               UnlockList(h->HubDb->CrlList);\r
+                       }\r
+               }\r
+\r
+               ReleaseHub(h);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// CRL の列挙\r
+UINT StEnumCrl(ADMIN *a, RPC_ENUM_CRL *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       FreeRpcEnumCrl(t);\r
+       Zero(t, sizeof(RPC_ENUM_CRL));\r
+\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+       h = GetHub(c, hubname);\r
+\r
+       if (h == NULL)\r
+       {\r
+               ret = ERR_HUB_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               if (h->HubDb == NULL)\r
+               {\r
+                       ret = ERR_NOT_SUPPORTED;\r
+               }\r
+               else\r
+               {\r
+                       LockList(h->HubDb->CrlList);\r
+                       {\r
+                               UINT i;\r
+\r
+                               t->NumItem = LIST_NUM(h->HubDb->CrlList);\r
+                               t->Items = ZeroMalloc(sizeof(RPC_ENUM_CRL_ITEM) * t->NumItem);\r
+\r
+                               for (i = 0;i < LIST_NUM(h->HubDb->CrlList);i++)\r
+                               {\r
+                                       CRL *crl = LIST_DATA(h->HubDb->CrlList, i);\r
+                                       wchar_t *info = GenerateCrlStr(crl);\r
+\r
+                                       UniStrCpy(t->Items[i].CrlInfo, sizeof(t->Items[i].CrlInfo), info);\r
+                                       Free(info);\r
+\r
+                                       t->Items[i].Key = POINTER_TO_KEY(crl);\r
+                               }\r
+                       }\r
+                       UnlockList(h->HubDb->CrlList);\r
+               }\r
+\r
+               ReleaseHub(h);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ルーティングテーブルの列挙\r
+UINT StEnumL3Table(ADMIN *a, RPC_ENUM_L3TABLE *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       L3SW *sw;\r
+       char name[MAX_HUBNAME_LEN + 1];\r
+\r
+       if (IsEmptyStr(t->Name))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       StrCpy(name, sizeof(name), t->Name);\r
+       FreeRpcEnumL3Table(t);\r
+       Zero(t, sizeof(RPC_ENUM_L3TABLE));\r
+       StrCpy(t->Name, sizeof(t->Name), name);\r
+\r
+       sw = L3GetSw(c, t->Name);\r
+\r
+       if (sw == NULL)\r
+       {\r
+               ret = ERR_LAYER3_SW_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+\r
+               Lock(sw->lock);\r
+               {\r
+                       t->NumItem = LIST_NUM(sw->TableList);\r
+                       t->Items = ZeroMalloc(sizeof(RPC_L3TABLE) * t->NumItem);\r
+\r
+                       for (i = 0;i < t->NumItem;i++)\r
+                       {\r
+                               L3TABLE *tbl = LIST_DATA(sw->TableList, i);\r
+                               RPC_L3TABLE *e = &t->Items[i];\r
+\r
+                               StrCpy(e->Name, sizeof(e->Name), name);\r
+                               e->NetworkAddress = tbl->NetworkAddress;\r
+                               e->SubnetMask = tbl->SubnetMask;\r
+                               e->GatewayAddress = tbl->GatewayAddress;\r
+                               e->Metric = tbl->Metric;\r
+                       }\r
+               }\r
+               Unlock(sw->lock);\r
+\r
+               ReleaseL3Sw(sw);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ルーティングテーブルの削除\r
+UINT StDelL3Table(ADMIN *a, RPC_L3TABLE *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       L3SW *sw;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       sw = L3GetSw(c, t->Name);\r
+\r
+       if (sw == NULL)\r
+       {\r
+               ret = ERR_LAYER3_SW_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               L3TABLE tbl;\r
+\r
+               Zero(&tbl, sizeof(tbl));\r
+               tbl.NetworkAddress = t->NetworkAddress;\r
+               tbl.SubnetMask = t->SubnetMask;\r
+               tbl.GatewayAddress = t->GatewayAddress;\r
+               tbl.Metric = t->Metric;\r
+\r
+               if (L3DelTable(sw, &tbl) == false)\r
+               {\r
+                       ret = ERR_LAYER3_TABLE_DEL_FAILED;\r
+               }\r
+               else\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+                       IPToStr32(tmp, sizeof(tmp), tbl.NetworkAddress);\r
+                       ALog(a, NULL, "LA_DEL_L3_TABLE", tmp, t->Name);\r
+\r
+                       IncrementServerConfigRevision(s);\r
+               }\r
+\r
+               ReleaseL3Sw(sw);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ルーティングテーブルの追加\r
+UINT StAddL3Table(ADMIN *a, RPC_L3TABLE *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       L3SW *sw;\r
+\r
+       if (IsNetworkAddress32(t->NetworkAddress, t->SubnetMask) == false ||\r
+               IsHostIPAddress32(t->GatewayAddress) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       sw = L3GetSw(c, t->Name);\r
+\r
+       if (sw == NULL)\r
+       {\r
+               ret = ERR_LAYER3_SW_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               L3TABLE tbl;\r
+\r
+               Zero(&tbl, sizeof(tbl));\r
+               tbl.NetworkAddress = t->NetworkAddress;\r
+               tbl.SubnetMask = t->SubnetMask;\r
+               tbl.GatewayAddress = t->GatewayAddress;\r
+               tbl.Metric = t->Metric;\r
+\r
+               if (L3AddTable(sw, &tbl) == false)\r
+               {\r
+                       ret = ERR_LAYER3_TABLE_ADD_FAILED;\r
+               }\r
+               else\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+                       IPToStr32(tmp, sizeof(tmp), tbl.NetworkAddress);\r
+                       ALog(a, NULL, "LA_ADD_L3_TABLE", tmp, t->Name);\r
+\r
+                       IncrementServerConfigRevision(s);\r
+               }\r
+\r
+               ReleaseL3Sw(sw);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// インターフェイスの列挙\r
+UINT StEnumL3If(ADMIN *a, RPC_ENUM_L3IF *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       L3SW *sw;\r
+       char name[MAX_HUBNAME_LEN + 1];\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       StrCpy(name, sizeof(name), t->Name);\r
+\r
+       FreeRpcEnumL3If(t);\r
+       Zero(t, sizeof(RPC_ENUM_L3IF));\r
+\r
+       StrCpy(t->Name, sizeof(t->Name), name);\r
+\r
+       sw = L3GetSw(c, t->Name);\r
+\r
+       if (sw == NULL)\r
+       {\r
+               ret = ERR_LAYER3_SW_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               Lock(sw->lock);\r
+               {\r
+                       UINT i;\r
+\r
+                       t->NumItem = LIST_NUM(sw->IfList);\r
+                       t->Items = ZeroMalloc(sizeof(RPC_L3IF) * t->NumItem);\r
+\r
+                       for (i = 0;i < t->NumItem;i++)\r
+                       {\r
+                               L3IF *f = LIST_DATA(sw->IfList, i);\r
+                               RPC_L3IF *e = &t->Items[i];\r
+\r
+                               StrCpy(e->Name, sizeof(e->Name), sw->Name);\r
+                               StrCpy(e->HubName, sizeof(e->HubName), f->HubName);\r
+                               e->IpAddress = f->IpAddress;\r
+                               e->SubnetMask = f->SubnetMask;\r
+                       }\r
+               }\r
+               Unlock(sw->lock);\r
+\r
+               ReleaseL3Sw(sw);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// インターフェイスの削除\r
+UINT StDelL3If(ADMIN *a, RPC_L3IF *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       L3SW *sw;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       sw = L3GetSw(c, t->Name);\r
+\r
+       if (sw == NULL)\r
+       {\r
+               ret = ERR_LAYER3_SW_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               if (L3DelIf(sw, t->HubName) == false)\r
+               {\r
+                       ret = ERR_LAYER3_IF_DEL_FAILED;\r
+               }\r
+               else\r
+               {\r
+                       ALog(a, NULL, "LA_DEL_L3_IF", t->HubName, t->Name);\r
+\r
+                       IncrementServerConfigRevision(s);\r
+               }\r
+               ReleaseL3Sw(sw);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// インターフェイスの追加\r
+UINT StAddL3If(ADMIN *a, RPC_L3IF *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       L3SW *sw;\r
+\r
+       if (IsSubnetMask32(t->SubnetMask) == false || IsHostIPAddress32(t->IpAddress) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+       if ((t->IpAddress & (~t->SubnetMask)) == 0)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       sw = L3GetSw(c, t->Name);\r
+\r
+       if (sw == NULL)\r
+       {\r
+               ret = ERR_LAYER3_SW_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               Lock(sw->lock);\r
+               {\r
+                       if (L3SearchIf(sw, t->HubName) != NULL)\r
+                       {\r
+                               // すでに存在する\r
+                               ret = ERR_LAYER3_IF_EXISTS;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (L3AddIf(sw, t->HubName, t->IpAddress, t->SubnetMask) == false)\r
+                               {\r
+                                       ret = ERR_LAYER3_IF_ADD_FAILED;\r
+                               }\r
+                               else\r
+                               {\r
+                                       ALog(a, NULL, "LA_ADD_L3_IF", t->HubName, t->Name);\r
+\r
+                                       IncrementServerConfigRevision(s);\r
+                               }\r
+                       }\r
+               }\r
+               Unlock(sw->lock);\r
+               ReleaseL3Sw(sw);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// Layer-3 スイッチの停止\r
+UINT StStopL3Switch(ADMIN *a, RPC_L3SW *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       L3SW *sw;\r
+\r
+       if (IsEmptyStr(t->Name))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       sw = L3GetSw(c, t->Name);\r
+\r
+       if (sw == NULL)\r
+       {\r
+               ret = ERR_LAYER3_SW_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               L3SwStop(sw);\r
+               ALog(a, NULL, "LA_STOP_L3_SW", sw->Name);\r
+               ReleaseL3Sw(sw);\r
+\r
+               IncrementServerConfigRevision(s);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// Layer-3 スイッチの開始\r
+UINT StStartL3Switch(ADMIN *a, RPC_L3SW *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       L3SW *sw;\r
+\r
+       if (IsEmptyStr(t->Name))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       sw = L3GetSw(c, t->Name);\r
+\r
+       if (sw == NULL)\r
+       {\r
+               ret = ERR_LAYER3_SW_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               Lock(sw->lock);\r
+               {\r
+                       // 登録されているインターフェイス数を検査する\r
+                       if (LIST_NUM(sw->IfList) >= 1)\r
+                       {\r
+                               L3SwStart(sw);\r
+\r
+                               ALog(a, NULL, "LA_START_L3_SW", sw->Name);\r
+\r
+                               IncrementServerConfigRevision(s);\r
+                       }\r
+                       else\r
+                       {\r
+                               ret = ERR_LAYER3_CANT_START_SWITCH;\r
+                       }\r
+               }\r
+               Unlock(sw->lock);\r
+\r
+               ReleaseL3Sw(sw);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// Layer-3 スイッチの列挙\r
+UINT StEnumL3Switch(ADMIN *a, RPC_ENUM_L3SW *t)\r
+{\r
+       UINT i;\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       FreeRpcEnumL3Sw(t);\r
+       Zero(t, sizeof(RPC_ENUM_L3SW));\r
+\r
+       LockList(c->L3SwList);\r
+       {\r
+               t->NumItem = LIST_NUM(c->L3SwList);\r
+               t->Items = ZeroMalloc(sizeof(RPC_ENUM_L3SW_ITEM) * t->NumItem);\r
+               for (i = 0;i < LIST_NUM(c->L3SwList);i++)\r
+               {\r
+                       L3SW *sw = LIST_DATA(c->L3SwList, i);\r
+                       RPC_ENUM_L3SW_ITEM *e = &t->Items[i];\r
+\r
+                       Lock(sw->lock);\r
+                       {\r
+                               StrCpy(e->Name, sizeof(e->Name), sw->Name);\r
+                               e->NumInterfaces = LIST_NUM(sw->IfList);\r
+                               e->NumTables = LIST_NUM(sw->TableList);\r
+                               e->Active = sw->Active;\r
+                               e->Online = sw->Online;\r
+                       }\r
+                       Unlock(sw->lock);\r
+               }\r
+       }\r
+       UnlockList(c->L3SwList);\r
+\r
+       return ret;\r
+}\r
+\r
+// Layer-3 スイッチの削除\r
+UINT StDelL3Switch(ADMIN *a, RPC_L3SW *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       if (IsEmptyStr(t->Name))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       if (L3DelSw(c, t->Name) == false)\r
+       {\r
+               ret = ERR_LAYER3_SW_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               ALog(a, NULL, "LA_DEL_L3_SW", t->Name);\r
+\r
+               IncrementServerConfigRevision(s);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// Layer-3 スイッチの追加\r
+UINT StAddL3Switch(ADMIN *a, RPC_L3SW *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       L3SW *sw;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       if (IsEmptyStr(t->Name))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (IsSafeStr(t->Name) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       // 重複チェック\r
+       sw = L3GetSw(c, t->Name);\r
+       if (sw != NULL)\r
+       {\r
+               // すでに存在する\r
+               ReleaseL3Sw(sw);\r
+               ret = ERR_LAYER3_SW_EXISTS;\r
+       }\r
+       else\r
+       {\r
+               LockList(c->L3SwList);\r
+               {\r
+                       if (LIST_NUM(c->L3SwList) >= GetServerCapsInt(s, "i_max_l3_sw"))\r
+                       {\r
+                               // これ以上作成できない\r
+                               sw = NULL;\r
+                       }\r
+                       else\r
+                       {\r
+                               // 作成する\r
+                               sw = L3AddSw(c, t->Name);\r
+\r
+                               if (sw != NULL)\r
+                               {\r
+                                       ALog(a, NULL, "LA_ADD_L3_SW", t->Name);\r
+\r
+                                       IncrementServerConfigRevision(s);\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(c->L3SwList);\r
+\r
+               if (sw == NULL)\r
+               {\r
+                       // 失敗\r
+                       ret = ERR_INTERNAL_ERROR;\r
+               }\r
+               else\r
+               {\r
+                       // 成功\r
+                       ReleaseL3Sw(sw);\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 HUB の拡張オプションを設定する\r
+UINT StSetHubExtOptions(ADMIN *a, RPC_ADMIN_OPTION *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+\r
+       bool not_server_admin = false;\r
+\r
+       if (t->NumItem > MAX_HUB_ADMIN_OPTIONS)\r
+       {\r
+               return ERR_TOO_MANT_ITEMS;\r
+       }\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       if (a->ServerAdmin == false)\r
+       {\r
+               not_server_admin = true;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (GetHubAdminOption(h, "deny_hub_admin_change_ext_option") && not_server_admin)\r
+       {\r
+               // 十分な管理権限が無い\r
+               ReleaseHub(h);\r
+\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       // 設定の実行\r
+       Lock(h->lock);\r
+       {\r
+               DataToHubOptionStruct(h->Option, t);\r
+       }\r
+       Unlock(h->lock);\r
+\r
+       ALog(a, NULL, "LA_SET_HUB_EXT_OPTION", h->Name);\r
+\r
+       h->CurrentVersion++;\r
+       SiHubUpdateProc(h);\r
+\r
+       ReleaseHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// 仮想 HUB の拡張オプションを取得する\r
+UINT StGetHubExtOptions(ADMIN *a, RPC_ADMIN_OPTION *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       FreeRpcAdminOption(t);\r
+       Zero(t, sizeof(RPC_ADMIN_OPTION));\r
+\r
+       StrCpy(t->HubName, sizeof(t->HubName), h->Name);\r
+\r
+       // 設定の取得\r
+       Lock(h->lock);\r
+       {\r
+               HubOptionStructToData(t, h->Option, h->Name);\r
+       }\r
+       Unlock(h->lock);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// 仮想 HUB の管理オプションを設定する\r
+UINT StSetHubAdminOptions(ADMIN *a, RPC_ADMIN_OPTION *t)\r
+{\r
+       UINT i;\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+\r
+       bool not_server_admin = false;\r
+\r
+       if (t->NumItem > MAX_HUB_ADMIN_OPTIONS)\r
+       {\r
+               return ERR_TOO_MANT_ITEMS;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       if (a->ServerAdmin == false)\r
+       {\r
+               not_server_admin = true;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (GetHubAdminOption(h, "allow_hub_admin_change_option") == false\r
+               && not_server_admin)\r
+       {\r
+               // 十分な管理権限が無い\r
+               ReleaseHub(h);\r
+\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       LockList(h->AdminOptionList);\r
+       {\r
+               DeleteAllHubAdminOption(h, false);\r
+\r
+               for (i = 0;i < t->NumItem;i++)\r
+               {\r
+                       ADMIN_OPTION *e = &t->Items[i];\r
+                       ADMIN_OPTION *a = ZeroMalloc(sizeof(ADMIN_OPTION));\r
+\r
+                       StrCpy(a->Name, sizeof(a->Name), e->Name);\r
+                       a->Value = e->Value;\r
+\r
+                       Insert(h->AdminOptionList, a);\r
+               }\r
+\r
+               AddHubAdminOptionsDefaults(h, false);\r
+       }\r
+       UnlockList(h->AdminOptionList);\r
+\r
+       ALog(a, NULL, "LA_SET_HUB_ADMIN_OPTION", h->Name);\r
+\r
+       h->CurrentVersion++;\r
+       SiHubUpdateProc(h);\r
+\r
+       ReleaseHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// 仮想 HUB の管理オプションを取得する\r
+UINT StGetHubAdminOptions(ADMIN *a, RPC_ADMIN_OPTION *t)\r
+{\r
+       UINT i;\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       FreeRpcAdminOption(t);\r
+       Zero(t, sizeof(RPC_ADMIN_OPTION));\r
+\r
+       StrCpy(t->HubName, sizeof(t->HubName), h->Name);\r
+\r
+       LockList(h->AdminOptionList);\r
+       {\r
+               t->NumItem = LIST_NUM(h->AdminOptionList);\r
+               t->Items = ZeroMalloc(sizeof(ADMIN_OPTION) * t->NumItem);\r
+\r
+               for (i = 0;i < t->NumItem;i++)\r
+               {\r
+                       ADMIN_OPTION *a = LIST_DATA(h->AdminOptionList, i);\r
+                       ADMIN_OPTION *e = &t->Items[i];\r
+\r
+                       StrCpy(e->Name, sizeof(e->Name), a->Name);\r
+                       e->Value = a->Value;\r
+               }\r
+       }\r
+       UnlockList(h->AdminOptionList);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// デフォルトの管理オプションの一覧を取得する\r
+UINT StGetDefaultHubAdminOptions(ADMIN *a, RPC_ADMIN_OPTION *t)\r
+{\r
+       UINT i;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (a->Server->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       FreeRpcAdminOption(t);\r
+       Zero(t, sizeof(RPC_ADMIN_OPTION));\r
+\r
+       t->NumItem = num_admin_options;\r
+       t->Items = ZeroMalloc(sizeof(ADMIN_OPTION) * t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               ADMIN_OPTION *a = &t->Items[i];\r
+\r
+               StrCpy(a->Name, sizeof(a->Name), admin_options[i].Name);\r
+               a->Value = admin_options[i].Value;\r
+       }\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// config の取得\r
+UINT StGetConfig(ADMIN *a, RPC_CONFIG *t)\r
+{\r
+       SERVER *s;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       FreeRpcConfig(t);\r
+       Zero(t, sizeof(RPC_CONFIG));\r
+\r
+       s = a->Server;\r
+\r
+       ALog(a, NULL, "LA_GET_CONFIG");\r
+\r
+       if (s->CfgRw != NULL)\r
+       {\r
+               FOLDER *f = SiWriteConfigurationToCfg(s);\r
+               BUF *b = CfgFolderToBuf(f, true);\r
+\r
+               StrCpy(t->FileName, sizeof(t->FileName), s->CfgRw->FileName + (s->CfgRw->FileName[0] == '@' ? 1 : 0));\r
+\r
+               t->FileData = ZeroMalloc(b->Size + 1);\r
+               Copy(t->FileData, b->Buf, b->Size);\r
+\r
+               CfgDeleteFolder(f);\r
+               FreeBuf(b);\r
+\r
+               return ERR_NO_ERROR;\r
+       }\r
+       else\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+}\r
+\r
+// config の設定\r
+UINT StSetConfig(ADMIN *a, RPC_CONFIG *t)\r
+{\r
+       SERVER *s;\r
+       IO *o;\r
+       char filename[MAX_PATH];\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       s = a->Server;\r
+       if (s->CfgRw == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       // 新しい Config ファイルに書き込む\r
+       Format(filename, sizeof(filename), "%s.new", s->CfgRw->FileName);\r
+\r
+       o = FileCreate(filename);\r
+\r
+       FileWrite(o, t->FileData, StrLen(t->FileData));\r
+\r
+       FileClose(o);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       ALog(a, NULL, "LA_SET_CONFIG");\r
+\r
+       // サーバーを再起動する\r
+       SiRebootServer(s->Cedar->Bridge);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// Caps の取得\r
+UINT StGetCaps(ADMIN *a, CAPSLIST *t)\r
+{\r
+       FreeRpcCapsList(t);\r
+       Zero(t, sizeof(CAPSLIST));\r
+\r
+       GetServerCapsMain(a->Server, t);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// サーバーの再起動\r
+UINT StRebootServer(ADMIN *a, RPC_TEST *t)\r
+{\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       ALog(a, NULL, "LA_REBOOT_SERVER");\r
+\r
+       SiRebootServerEx(a->Server->Cedar->Bridge, t->IntValue);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// ローカルブリッジのサポート情報の取得\r
+UINT StGetBridgeSupport(ADMIN *a, RPC_BRIDGE_SUPPORT *t)\r
+{\r
+       Zero(t, sizeof(RPC_BRIDGE_SUPPORT));\r
+\r
+       t->IsBridgeSupportedOs = IsBridgeSupported();\r
+       t->IsWinPcapNeeded = IsNeedWinPcap();\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// Ethernet デバイスの列挙\r
+UINT StEnumEthernet(ADMIN *a, RPC_ENUM_ETH *t)\r
+{\r
+       TOKEN_LIST *o;\r
+       UINT i;\r
+       char tmp[MAX_SIZE];\r
+       bool unix_support = false;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+#ifdef OS_UNIX\r
+       unix_support = EthIsInterfaceDescriptionSupportedUnix();\r
+#endif // OS_UNIX\r
+\r
+       o = GetEthList();\r
+\r
+       FreeRpcEnumEth(t);\r
+       Zero(t, sizeof(RPC_ENUM_ETH));\r
+\r
+       t->NumItem = o->NumTokens;\r
+       t->Items = ZeroMalloc(sizeof(RPC_ENUM_ETH_ITEM) * t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_ETH_ITEM *e = &t->Items[i];\r
+\r
+               StrCpy(e->DeviceName, sizeof(e->DeviceName), o->Token[i]);\r
+\r
+               StrCpy(tmp, sizeof(tmp), e->DeviceName);\r
+\r
+#ifdef OS_WIN32\r
+               GetEthNetworkConnectionName(e->NetworkConnectionName, sizeof(e->NetworkConnectionName), e->DeviceName);\r
+#else\r
+               if (unix_support == false)\r
+               {\r
+                       StrCpy(tmp, sizeof(tmp), "");\r
+               }\r
+               else\r
+               {\r
+                       if (EthGetInterfaceDescriptionUnix(e->DeviceName, tmp, sizeof(tmp)) == false)\r
+                       {\r
+                               StrCpy(tmp, sizeof(tmp), e->DeviceName);\r
+                       }\r
+               }\r
+\r
+               StrToUni(e->NetworkConnectionName, sizeof(e->NetworkConnectionName), tmp);\r
+#endif\r
+       }\r
+\r
+       FreeToken(o);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// ローカルブリッジの追加\r
+UINT StAddLocalBridge(ADMIN *a, RPC_LOCALBRIDGE *t)\r
+{\r
+       if (IsEmptyStr(t->DeviceName) || IsEmptyStr(t->HubName))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       if (IsEthSupported() == false)\r
+       {\r
+               return ERR_LOCAL_BRIDGE_UNSUPPORTED;\r
+       }\r
+\r
+       ALog(a, NULL, "LA_ADD_BRIDGE", t->HubName, t->DeviceName);\r
+\r
+       AddLocalBridge(a->Server->Cedar, t->HubName, t->DeviceName, false, false, t->TapMode, NULL, false);\r
+\r
+       IncrementServerConfigRevision(a->Server);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// ローカルブリッジの削除\r
+UINT StDeleteLocalBridge(ADMIN *a, RPC_LOCALBRIDGE *t)\r
+{\r
+       if (IsEmptyStr(t->DeviceName) || IsEmptyStr(t->HubName))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       ALog(a, NULL, "LA_DELETE_BRIDGE", t->HubName, t->DeviceName);\r
+\r
+       if (DeleteLocalBridge(a->Server->Cedar, t->HubName, t->DeviceName) == false)\r
+       {\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+\r
+       IncrementServerConfigRevision(a->Server);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// ローカルブリッジの列挙\r
+UINT StEnumLocalBridge(ADMIN *a, RPC_ENUM_LOCALBRIDGE *t)\r
+{\r
+       UINT i;\r
+       CEDAR *c;\r
+\r
+       if (IsEthSupported() == false)\r
+       {\r
+               return ERR_LOCAL_BRIDGE_UNSUPPORTED;\r
+       }\r
+\r
+       FreeRpcEnumLocalBridge(t);\r
+       Zero(t, sizeof(RPC_ENUM_LOCALBRIDGE));\r
+\r
+       c = a->Server->Cedar;\r
+\r
+       LockList(c->LocalBridgeList);\r
+       {\r
+               t->NumItem = LIST_NUM(c->LocalBridgeList);\r
+               t->Items = ZeroMalloc(sizeof(RPC_LOCALBRIDGE) * t->NumItem);\r
+\r
+               for (i = 0;i < t->NumItem;i++)\r
+               {\r
+                       RPC_LOCALBRIDGE *e = &t->Items[i];\r
+                       LOCALBRIDGE *br = LIST_DATA(c->LocalBridgeList, i);\r
+\r
+                       if (br->Bridge == false)\r
+                       {\r
+                               e->Online = e->Active = false;\r
+                       }\r
+                       else\r
+                       {\r
+                               e->Online = true;\r
+                               if (br->Bridge->Active)\r
+                               {\r
+                                       e->Active = true;\r
+                               }\r
+                               else\r
+                               {\r
+                                       e->Active = false;\r
+                               }\r
+                       }\r
+                       StrCpy(e->DeviceName, sizeof(e->DeviceName), br->DeviceName);\r
+                       StrCpy(e->HubName, sizeof(e->HubName), br->HubName);\r
+\r
+                       e->TapMode = br->TapMode;\r
+               }\r
+       }\r
+       UnlockList(c->LocalBridgeList);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// syslog 設定の書き込み\r
+UINT StSetSysLog(ADMIN *a, SYSLOG_SETTING *t)\r
+{\r
+       return ERR_NOT_SUPPORTED;\r
+}\r
+\r
+// syslog 設定の読み込み\r
+UINT StGetSysLog(ADMIN *a, SYSLOG_SETTING *t)\r
+{\r
+       return ERR_NOT_SUPPORTED;\r
+}\r
+\r
+// KEEP の設定\r
+UINT StSetKeep(ADMIN *a, RPC_KEEP *t)\r
+{\r
+       SERVER *s = a->Server;\r
+\r
+       if (t->UseKeepConnect)\r
+       {\r
+               if (IsEmptyStr(t->KeepConnectHost) ||\r
+                       t->KeepConnectPort == 0 ||\r
+                       t->KeepConnectPort >= 65536)\r
+               {\r
+                       return ERR_INVALID_PARAMETER;\r
+               }\r
+       }\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       Lock(s->Keep->lock);\r
+       {\r
+               KEEP *keep = s->Keep;\r
+               keep->Enable = t->UseKeepConnect;\r
+               keep->Server = true;\r
+               StrCpy(keep->ServerName, sizeof(keep->ServerName), t->KeepConnectHost);\r
+               keep->ServerPort = t->KeepConnectPort;\r
+               keep->UdpMode = t->KeepConnectProtocol;\r
+               keep->Interval = t->KeepConnectInterval * 1000;\r
+               if (keep->Interval < 5000)\r
+               {\r
+                       keep->Interval = 5000;\r
+               }\r
+               else if (keep->Interval > 600000)\r
+               {\r
+                       keep->Interval = 600000;\r
+               }\r
+       }\r
+       Unlock(s->Keep->lock);\r
+\r
+       ALog(a, NULL, "LA_SET_KEEP");\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// KEEP の取得\r
+UINT StGetKeep(ADMIN *a, RPC_KEEP *t)\r
+{\r
+       SERVER *s = a->Server;\r
+\r
+       Zero(t, sizeof(RPC_KEEP));\r
+\r
+       Lock(s->Keep->lock);\r
+       {\r
+               KEEP *k = s->Keep;\r
+               t->UseKeepConnect = k->Enable;\r
+               StrCpy(t->KeepConnectHost, sizeof(t->KeepConnectHost), k->ServerName);\r
+               t->KeepConnectPort = k->ServerPort;\r
+               t->KeepConnectProtocol = k->UdpMode;\r
+               t->KeepConnectInterval = k->Interval / 1000;\r
+       }\r
+       Unlock(s->Keep->lock);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// IP テーブルの削除\r
+UINT StDeleteIpTable(ADMIN *a, RPC_DELETE_TABLE *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_delete_iptable") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       LockList(h->IpTable);\r
+       {\r
+               if (IsInListKey(h->IpTable, t->Key))\r
+               {\r
+                       IP_TABLE_ENTRY *e = ListKeyToPointer(h->IpTable, t->Key);\r
+                       Free(e);\r
+                       Delete(h->IpTable, e);\r
+               }\r
+               else\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+       }\r
+       UnlockList(h->IpTable);\r
+\r
+       if (ret == ERR_OBJECT_NOT_FOUND)\r
+       {\r
+               if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+               {\r
+                       UINT i;\r
+                       LockList(s->FarmMemberList);\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                               {\r
+                                       FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                                       if (f->Me == false)\r
+                                       {\r
+                                               SiCallDeleteIpTable(s, f, t->HubName, t->Key);\r
+                                               ret = ERR_NO_ERROR;\r
+                                       }\r
+                               }\r
+                       }\r
+                       UnlockList(s->FarmMemberList);\r
+               }\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// ローカル IP テーブルの列挙\r
+UINT SiEnumIpTable(SERVER *s, char *hubname, RPC_ENUM_IP_TABLE *t)\r
+{\r
+       CEDAR *c;\r
+       UINT i;\r
+       HUB *h = NULL;\r
+       // 引数チェック\r
+       if (s == NULL || hubname == NULL || t == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       c = s->Cedar;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, hubname);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+       LockList(h->IpTable);\r
+       {\r
+               t->NumIpTable = LIST_NUM(h->IpTable);\r
+               t->IpTables = ZeroMalloc(sizeof(RPC_ENUM_IP_TABLE_ITEM) * t->NumIpTable);\r
+\r
+               for (i = 0;i < t->NumIpTable;i++)\r
+               {\r
+                       RPC_ENUM_IP_TABLE_ITEM *e = &t->IpTables[i];\r
+                       IP_TABLE_ENTRY *table = LIST_DATA(h->IpTable, i);\r
+\r
+                       e->Key = POINTER_TO_KEY(table);\r
+                       StrCpy(e->SessionName, sizeof(e->SessionName), table->Session->Name);\r
+                       e->Ip = IPToUINT(&table->Ip);\r
+                       Copy(&e->IpV6, &table->Ip, sizeof(IP));\r
+                       e->DhcpAllocated = table->DhcpAllocated;\r
+                       e->CreatedTime = TickToTime(table->CreatedTime);\r
+                       e->UpdatedTime = TickToTime(table->UpdatedTime);\r
+\r
+                       GetMachineName(e->RemoteHostname, sizeof(e->RemoteHostname));\r
+               }\r
+       }\r
+       UnlockList(h->IpTable);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// IP テーブルの列挙\r
+UINT StEnumIpTable(ADMIN *a, RPC_ENUM_IP_TABLE *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       UINT i;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       // ローカルの列挙\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       FreeRpcEnumIpTable(t);\r
+       Zero(t, sizeof(RPC_ENUM_IP_TABLE));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+       ret = SiEnumIpTable(s, hubname, t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               return ret;\r
+       }\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               // リモートの列挙\r
+               LockList(s->FarmMemberList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                       {\r
+                               FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                               if (f->Me == false)\r
+                               {\r
+                                       RPC_ENUM_IP_TABLE tmp;\r
+\r
+                                       Zero(&tmp, sizeof(tmp));\r
+\r
+                                       SiCallEnumIpTable(s, f, hubname, &tmp);\r
+\r
+                                       AdjoinRpcEnumIpTable(t, &tmp);\r
+                                       FreeRpcEnumIpTable(&tmp);\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(s->FarmMemberList);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// MAC テーブルの削除\r
+UINT StDeleteMacTable(ADMIN *a, RPC_DELETE_TABLE *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_delete_mactable") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       LockList(h->MacTable);\r
+       {\r
+               if (IsInListKey(h->MacTable, t->Key))\r
+               {\r
+                       MAC_TABLE_ENTRY *e = ListKeyToPointer(h->MacTable, t->Key);\r
+                       Free(e);\r
+                       Delete(h->MacTable, e);\r
+               }\r
+               else\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+       }\r
+       UnlockList(h->MacTable);\r
+\r
+       if (ret == ERR_OBJECT_NOT_FOUND)\r
+       {\r
+               if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+               {\r
+                       UINT i;\r
+                       LockList(s->FarmMemberList);\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                               {\r
+                                       FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                                       if (f->Me == false)\r
+                                       {\r
+                                               SiCallDeleteMacTable(s, f, t->HubName, t->Key);\r
+                                               ret = ERR_NO_ERROR;\r
+                                       }\r
+                               }\r
+                       }\r
+                       UnlockList(s->FarmMemberList);\r
+               }\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// ローカル MAC テーブルの列挙\r
+UINT SiEnumMacTable(SERVER *s, char *hubname, RPC_ENUM_MAC_TABLE *t)\r
+{\r
+       CEDAR *c;\r
+       UINT i;\r
+       HUB *h = NULL;\r
+       // 引数チェック\r
+       if (s == NULL || hubname == NULL || t == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       c = s->Cedar;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, hubname);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+       LockList(h->MacTable);\r
+       {\r
+               t->NumMacTable = LIST_NUM(h->MacTable);\r
+               t->MacTables = ZeroMalloc(sizeof(RPC_ENUM_MAC_TABLE_ITEM) * t->NumMacTable);\r
+\r
+               for (i = 0;i < t->NumMacTable;i++)\r
+               {\r
+                       RPC_ENUM_MAC_TABLE_ITEM *e = &t->MacTables[i];\r
+                       MAC_TABLE_ENTRY *mac = LIST_DATA(h->MacTable, i);\r
+\r
+                       e->Key = POINTER_TO_KEY(mac);\r
+                       StrCpy(e->SessionName, sizeof(e->SessionName), mac->Session->Name);\r
+                       Copy(e->MacAddress, mac->MacAddress, sizeof(e->MacAddress));\r
+                       e->CreatedTime = TickToTime(mac->CreatedTime);\r
+                       e->UpdatedTime = TickToTime(mac->UpdatedTime);\r
+                       e->VlanId = mac->VlanId;\r
+\r
+                       GetMachineName(e->RemoteHostname, sizeof(e->RemoteHostname));\r
+               }\r
+       }\r
+       UnlockList(h->MacTable);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// MAC テーブルの列挙\r
+UINT StEnumMacTable(ADMIN *a, RPC_ENUM_MAC_TABLE *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       UINT i;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       // ローカルの MAC テーブルを列挙する\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       FreeRpcEnumMacTable(t);\r
+       Zero(t, sizeof(RPC_ENUM_MAC_TABLE));\r
+\r
+       ret = SiEnumMacTable(s, hubname, t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               return ret;\r
+       }\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               // リモートの MAC テーブルを列挙する\r
+               LockList(s->FarmMemberList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                       {\r
+                               FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                               if (f->Me == false)\r
+                               {\r
+                                       RPC_ENUM_MAC_TABLE tmp;\r
+\r
+                                       Zero(&tmp, sizeof(tmp));\r
+\r
+                                       SiCallEnumMacTable(s, f, hubname, &tmp);\r
+\r
+                                       AdjoinRpcEnumMacTable(t, &tmp);\r
+                                       FreeRpcEnumMacTable(&tmp);\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(s->FarmMemberList);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// セッションの削除\r
+UINT StDeleteSession(ADMIN *a, RPC_DELETE_SESSION *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       char name[MAX_SESSION_NAME_LEN + 1];\r
+       SESSION *sess;\r
+\r
+       if (IsEmptyStr(t->Name))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       StrCpy(name, sizeof(name), t->Name);\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_disconnect_session") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       sess = GetSessionByName(h, name);\r
+\r
+       if (sess == NULL)\r
+       {\r
+               if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+               {\r
+                       // ファームコントローラ\r
+                       UINT i;\r
+                       LockList(s->FarmMemberList);\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                               {\r
+                                       FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                                       if (f->Me == false)\r
+                                       {\r
+                                               // 切断を試行\r
+                                               SiCallDeleteSession(s, f, t->HubName, t->Name);\r
+                                       }\r
+                               }\r
+                       }\r
+                       UnlockList(s->FarmMemberList);\r
+               }\r
+               else\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (sess->LinkModeServer)\r
+               {\r
+                       ret = ERR_LINK_CANT_DISCONNECT;\r
+               }\r
+               else if (sess->SecureNATMode)\r
+               {\r
+                       ret = ERR_SNAT_CANT_DISCONNECT;\r
+               }\r
+               else if (sess->BridgeMode)\r
+               {\r
+                       ret = ERR_BRIDGE_CANT_DISCONNECT;\r
+               }\r
+               else if (sess->L3SwitchMode)\r
+               {\r
+                       ret = ERR_LAYER3_CANT_DISCONNECT;\r
+               }\r
+               else\r
+               {\r
+                       StopSession(sess);\r
+               }\r
+               ReleaseSession(sess);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               ALog(a, h, "LA_DELETE_SESSION", t->Name);\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// セッション状態の取得\r
+UINT StGetSessionStatus(ADMIN *a, RPC_SESSION_STATUS *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       char name[MAX_SESSION_NAME_LEN + 1];\r
+       SESSION *sess;\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       StrCpy(name, sizeof(name), t->Name);\r
+\r
+       if (IsEmptyStr(t->Name))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_query_session") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       FreeRpcSessionStatus(t);\r
+       Zero(t, sizeof(RPC_SESSION_STATUS));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+       StrCpy(t->Name, sizeof(t->Name), name);\r
+\r
+       sess = GetSessionByName(h, t->Name);\r
+\r
+       if (sess == NULL)\r
+       {\r
+               if (s->ServerType != SERVER_TYPE_FARM_CONTROLLER)\r
+               {\r
+                       // セッションが見つからない\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+               else\r
+               {\r
+                       UINT i;\r
+                       // 自分以外のメンバのセッションも検索してみる\r
+                       LockList(s->FarmMemberList);\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                               {\r
+                                       FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                                       if (f->Me == false)\r
+                                       {\r
+                                               RPC_SESSION_STATUS tmp;\r
+                                               Zero(&tmp, sizeof(tmp));\r
+                                               StrCpy(tmp.HubName, sizeof(tmp.HubName), t->HubName);\r
+                                               StrCpy(tmp.Name, sizeof(tmp.Name), t->Name);\r
+\r
+                                               if (SiCallGetSessionStatus(s, f, &tmp))\r
+                                               {\r
+                                                       if (StrLen(tmp.HubName) != 0)\r
+                                                       {\r
+                                                               // セッション情報の取得に成功した\r
+                                                               Copy(t, &tmp, sizeof(RPC_SESSION_STATUS));\r
+                                                               break;\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               FreeRpcSessionStatus(&tmp);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               if (i == LIST_NUM(s->FarmMemberList))\r
+                               {\r
+                                       // 結局見つからない\r
+                                       ret = ERR_OBJECT_NOT_FOUND;\r
+                               }\r
+                       }\r
+                       UnlockList(s->FarmMemberList);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               SESSION *s = sess;\r
+\r
+               Lock(s->lock);\r
+               {\r
+                       StrCpy(t->Username, sizeof(t->Username), s->Username);\r
+                       StrCpy(t->RealUsername, sizeof(t->RealUsername), s->UserNameReal);\r
+                       StrCpy(t->GroupName, sizeof(t->GroupName), s->GroupName);\r
+                       Copy(&t->NodeInfo, &s->NodeInfo, sizeof(NODE_INFO));\r
+\r
+                       if (s->Connection != NULL)\r
+                       {\r
+                               t->ClientIp = IPToUINT(&s->Connection->ClientIp);\r
+                               if (IsIP6(&s->Connection->ClientIp))\r
+                               {\r
+                                       Copy(&t->ClientIp6, &s->Connection->ClientIp.ipv6_addr, sizeof(t->ClientIp6));\r
+                               }\r
+\r
+                               StrCpy(t->ClientHostName, sizeof(t->ClientHostName), s->Connection->ClientHostname);\r
+                       }\r
+               }\r
+               Unlock(s->lock);\r
+\r
+               CiGetSessionStatus(&t->Status, s);\r
+\r
+               ReleaseSession(s);\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// セッションの列挙メイン\r
+void SiEnumSessionMain(SERVER *s, RPC_ENUM_SESSION *t)\r
+{\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       UINT ret = ERR_NO_ERROR;\r
+       UINT num;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       FreeRpcEnumSession(t);\r
+       Zero(t, sizeof(RPC_ENUM_SESSION));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+       // ローカルセッションの列挙\r
+       num = 0;\r
+       SiEnumLocalSession(s, hubname, t);\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               // リモートセッションの列挙\r
+               LockList(s->FarmMemberList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                       {\r
+                               FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                               if (f->Me == false)\r
+                               {\r
+                                       RPC_ENUM_SESSION tmp;\r
+\r
+                                       Zero(&tmp, sizeof(tmp));\r
+\r
+                                       SiCallEnumSession(s, f, hubname, &tmp);\r
+\r
+                                       AdjoinRpcEnumSession(t, &tmp);\r
+                                       FreeRpcEnumSession(&tmp);\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(s->FarmMemberList);\r
+       }\r
+}\r
+\r
+// セッションの列挙\r
+UINT StEnumSession(ADMIN *a, RPC_ENUM_SESSION *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_enum_session") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       SiEnumSessionMain(s, t);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// グループの列挙\r
+UINT StEnumGroup(ADMIN *a, RPC_ENUM_GROUP *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       CHECK_RIGHT;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       AcLock(h);\r
+       {\r
+               UINT i, j;\r
+\r
+               FreeRpcEnumGroup(t);\r
+               Zero(t, sizeof(RPC_ENUM_GROUP));\r
+               StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+               t->NumGroup = LIST_NUM(h->HubDb->GroupList);\r
+               t->Groups = ZeroMalloc(sizeof(RPC_ENUM_GROUP_ITEM) * t->NumGroup);\r
+\r
+               for (i = 0;i < t->NumGroup;i++)\r
+               {\r
+                       RPC_ENUM_GROUP_ITEM *e = &t->Groups[i];\r
+                       USERGROUP *g = LIST_DATA(h->HubDb->GroupList, i);\r
+\r
+                       Lock(g->lock);\r
+                       {\r
+                               StrCpy(e->Name, sizeof(e->Name), g->Name);\r
+                               UniStrCpy(e->Realname, sizeof(e->Realname), g->RealName);\r
+                               UniStrCpy(e->Note, sizeof(e->Note), g->Note);\r
+                               if (g->Policy != NULL)\r
+                               {\r
+                                       if (g->Policy->Access == false)\r
+                                       {\r
+                                               e->DenyAccess = true;\r
+                                       }\r
+                               }\r
+                       }\r
+                       Unlock(g->lock);\r
+\r
+                       e->NumUsers = 0;\r
+\r
+\r
+                       LockList(h->HubDb->UserList);\r
+                       {\r
+                               for (j = 0;j < LIST_NUM(h->HubDb->UserList);j++)\r
+                               {\r
+                                       USER *u = LIST_DATA(h->HubDb->UserList, j);\r
+\r
+                                       Lock(u->lock);\r
+                                       {\r
+                                               if (u->Group == g)\r
+                                               {\r
+                                                       e->NumUsers++;\r
+                                               }\r
+                                       }\r
+                                       Unlock(u->lock);\r
+                               }\r
+                       }\r
+                       UnlockList(h->HubDb->UserList);\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// グループの削除\r
+UINT StDeleteGroup(ADMIN *a, RPC_DELETE_USER *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       if (IsEmptyStr(t->Name) || IsSafeStr(t->Name) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_groups") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       AcLock(h);\r
+       {\r
+               if (AcDeleteGroup(h, t->Name) == false)\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               ALog(a, h, "LA_DELETE_GROUP", t->Name);\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// グループの取得\r
+UINT StGetGroup(ADMIN *a, RPC_SET_GROUP *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+\r
+       if (IsEmptyStr(t->Name) || IsSafeStr(t->Name) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       AcLock(h);\r
+       {\r
+               USERGROUP *g = AcGetGroup(h, t->Name);\r
+\r
+               if (g == NULL)\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+               else\r
+               {\r
+                       FreeRpcSetGroup(t);\r
+                       Zero(t, sizeof(RPC_SET_GROUP));\r
+\r
+                       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+                       Lock(g->lock);\r
+                       {\r
+                               StrCpy(t->Name, sizeof(t->Name), g->Name);\r
+                               UniStrCpy(t->Realname, sizeof(t->Realname), g->RealName);\r
+                               UniStrCpy(t->Note, sizeof(t->Note), g->Note);\r
+                               Copy(&t->Traffic, g->Traffic, sizeof(TRAFFIC));\r
+                       }\r
+                       Unlock(g->lock);\r
+\r
+                       t->Policy = GetGroupPolicy(g);\r
+\r
+                       ReleaseGroup(g);\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// グループの設定\r
+UINT StSetGroup(ADMIN *a, RPC_SET_GROUP *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       if (IsEmptyStr(t->Name) || IsSafeStr(t->Name) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_groups") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       AcLock(h);\r
+       {\r
+               USERGROUP *g = AcGetGroup(h, t->Name);\r
+               if (g == NULL)\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+               else\r
+               {\r
+                       Lock(g->lock);\r
+                       {\r
+                               Free(g->RealName);\r
+                               Free(g->Note);\r
+                               g->RealName = UniCopyStr(t->Realname);\r
+                               g->Note = UniCopyStr(t->Note);\r
+                       }\r
+                       Unlock(g->lock);\r
+\r
+                       SetGroupPolicy(g, t->Policy);\r
+\r
+                       ReleaseGroup(g);\r
+\r
+                       ALog(a, h, "LA_SET_GROUP", t->Name);\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       ReleaseHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// グループの作成\r
+UINT StCreateGroup(ADMIN *a, RPC_SET_GROUP *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       if (IsEmptyStr(t->Name) || IsSafeStr(t->Name) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_groups") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       AcLock(h);\r
+       {\r
+               if (AcIsGroup(h, t->Name))\r
+               {\r
+                       ret = ERR_GROUP_ALREADY_EXISTS;\r
+               }\r
+               else\r
+               {\r
+                       USERGROUP *g = NewGroup(t->Name, t->Realname, t->Note);\r
+                       SetGroupPolicy(g, t->Policy);\r
+\r
+                       if ((LIST_NUM(h->HubDb->GroupList) >= GetServerCapsInt(a->Server, "i_max_users_per_hub")) ||\r
+                               ((GetHubAdminOption(h, "max_groups") != 0) && (LIST_NUM(h->HubDb->GroupList) >= GetHubAdminOption(h, "max_groups"))))\r
+                       {\r
+                               ret = ERR_TOO_MANY_GROUP;\r
+                       }\r
+                       else\r
+                       {\r
+                               AcAddGroup(h, g);\r
+                       }\r
+\r
+                       ReleaseGroup(g);\r
+\r
+                       ALog(a, h, "LA_CREATE_GROUP", t->Name);\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       ReleaseHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザーの列挙\r
+UINT StEnumUser(ADMIN *a, RPC_ENUM_USER *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       UINT i, num;\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       FreeRpcEnumUser(t);\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       Zero(t, sizeof(RPC_ENUM_USER));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+       LockList(h->HubDb->UserList);\r
+       {\r
+               num = LIST_NUM(h->HubDb->UserList);\r
+\r
+               t->NumUser = num;\r
+               t->Users = ZeroMalloc(sizeof(RPC_ENUM_USER_ITEM) * num);\r
+\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       USER *u = LIST_DATA(h->HubDb->UserList, i);\r
+\r
+                       Lock(u->lock);\r
+                       {\r
+                               RPC_ENUM_USER_ITEM *e = &t->Users[i];\r
+\r
+                               StrCpy(e->Name, sizeof(e->Name), u->Name);\r
+                               StrCpy(e->GroupName, sizeof(e->GroupName), u->GroupName);\r
+                               UniStrCpy(e->Realname, sizeof(e->Realname), u->RealName);\r
+                               UniStrCpy(e->Note, sizeof(e->Note), u->Note);\r
+                               e->AuthType = u->AuthType;\r
+                               e->LastLoginTime = u->LastLoginTime;\r
+                               e->NumLogin = u->NumLogin;\r
+\r
+                               if (u->Policy != NULL)\r
+                               {\r
+                                       e->DenyAccess = u->Policy->Access ? false : true;\r
+                               }\r
+                       }\r
+                       Unlock(u->lock);\r
+               }\r
+       }\r
+       UnlockList(h->HubDb->UserList);\r
+\r
+       ReleaseHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// ユーザーの削除\r
+UINT StDeleteUser(ADMIN *a, RPC_DELETE_USER *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       if (IsEmptyStr(t->Name) || IsUserName(t->Name) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_users") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       ALog(a, h, "LA_DELETE_USER", t->Name);\r
+\r
+       AcLock(h);\r
+       {\r
+               if (AcDeleteUser(h, t->Name) == false)\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       ReleaseHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザーの取得\r
+UINT StGetUser(ADMIN *a, RPC_SET_USER *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+       USER *u = NULL;\r
+       USERGROUP *g = NULL;\r
+       char name[MAX_USERNAME_LEN + 1];\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       StrCpy(name, sizeof(name), t->Name);\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       if (IsEmptyStr(t->Name) || IsUserName(t->Name) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       FreeRpcSetUser(t);\r
+       Zero(t, sizeof(RPC_SET_USER));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+       StrCpy(t->Name, sizeof(t->Name), name);\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, hubname);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       AcLock(h);\r
+       {\r
+               u = AcGetUser(h, name);\r
+               if (u == NULL)\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+               else\r
+               {\r
+                       Lock(u->lock);\r
+                       {\r
+                               StrCpy(t->GroupName, sizeof(t->GroupName), u->GroupName);\r
+                               UniStrCpy(t->Realname, sizeof(t->Realname), u->RealName);\r
+                               UniStrCpy(t->Note, sizeof(t->Note), u->Note);\r
+                               t->CreatedTime = u->CreatedTime;\r
+                               t->UpdatedTime = u->UpdatedTime;\r
+                               t->ExpireTime = u->ExpireTime;\r
+\r
+                               t->AuthType = u->AuthType;\r
+                               t->AuthData = CopyAuthData(u->AuthData, t->AuthType);\r
+                               t->NumLogin = u->NumLogin;\r
+                               Copy(&t->Traffic, u->Traffic, sizeof(TRAFFIC));\r
+                               if (u->Policy != NULL)\r
+                               {\r
+                                       t->Policy = ClonePolicy(u->Policy);\r
+                               }\r
+                       }\r
+                       Unlock(u->lock);\r
+\r
+                       ReleaseUser(u);\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザーの設定\r
+UINT StSetUser(ADMIN *a, RPC_SET_USER *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+       USER *u = NULL;\r
+       USERGROUP *g = NULL;\r
+\r
+       if (IsEmptyStr(t->Name) || IsUserName(t->Name) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       if (StrCmpi(t->Name, "*") == 0)\r
+       {\r
+               if (t->AuthType != AUTHTYPE_RADIUS && t->AuthType != AUTHTYPE_NT)\r
+               {\r
+                       return ERR_INVALID_PARAMETER;\r
+               }\r
+       }\r
+\r
+       if (t->AuthType == AUTHTYPE_RADIUS ||\r
+               t->AuthType == AUTHTYPE_ROOTCERT ||\r
+               t->AuthType == AUTHTYPE_USERCERT ||\r
+               t->AuthType == AUTHTYPE_NT)\r
+       {\r
+               return ERR_UTVPN_NOT_SUPPORT_THIS_AUTH;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_users") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       AcLock(h);\r
+       {\r
+               u = AcGetUser(h, t->Name);\r
+               if (u == NULL)\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+               else\r
+               {\r
+                       Lock(u->lock);\r
+                       {\r
+                               if (StrLen(t->GroupName) != 0)\r
+                               {\r
+                                       g = AcGetGroup(h, t->GroupName);\r
+\r
+                                       if (g != NULL)\r
+                                       {\r
+                                               JoinUserToGroup(u, g);\r
+                                               ReleaseGroup(g);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               ret = ERR_GROUP_NOT_FOUND;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       JoinUserToGroup(u, NULL);\r
+                               }\r
+\r
+                               if (ret != ERR_GROUP_NOT_FOUND)\r
+                               {\r
+                                       Free(u->RealName);\r
+                                       Free(u->Note);\r
+                                       u->RealName = UniCopyStr(t->Realname);\r
+                                       u->Note = UniCopyStr(t->Note);\r
+                                       SetUserAuthData(u, t->AuthType, CopyAuthData(t->AuthData, t->AuthType));\r
+                                       u->ExpireTime = t->ExpireTime;\r
+                                       u->UpdatedTime = SystemTime64();\r
+\r
+                                       SetUserPolicy(u, t->Policy);\r
+                               }\r
+                       }\r
+                       Unlock(u->lock);\r
+\r
+                       IncrementServerConfigRevision(s);\r
+\r
+                       ReleaseUser(u);\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               ALog(a, h, "LA_SET_USER", t->Name);\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザーの作成\r
+UINT StCreateUser(ADMIN *a, RPC_SET_USER *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+       UINT ret = ERR_NO_ERROR;\r
+       USER *u;\r
+       USERGROUP *g = NULL;\r
+\r
+       if (IsEmptyStr(t->Name) || IsUserName(t->Name) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       if (t->AuthType == AUTHTYPE_RADIUS ||\r
+               t->AuthType == AUTHTYPE_ROOTCERT ||\r
+               t->AuthType == AUTHTYPE_USERCERT ||\r
+               t->AuthType == AUTHTYPE_NT)\r
+       {\r
+               return ERR_UTVPN_NOT_SUPPORT_THIS_AUTH;\r
+       }\r
+\r
+       if (IsUserName(t->Name) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (StrCmpi(t->Name, "*") == 0)\r
+       {\r
+               if (t->AuthType != AUTHTYPE_RADIUS && t->AuthType != AUTHTYPE_NT)\r
+               {\r
+                       return ERR_INVALID_PARAMETER;\r
+               }\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_users") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       u = NewUser(t->Name, t->Realname, t->Note, t->AuthType, CopyAuthData(t->AuthData, t->AuthType));\r
+       if (u == NULL)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       u->ExpireTime = t->ExpireTime;\r
+\r
+       SetUserPolicy(u, t->Policy);\r
+\r
+       AcLock(h);\r
+       {\r
+               if ((LIST_NUM(h->HubDb->UserList) >= GetServerCapsInt(a->Server, "i_max_users_per_hub")) ||\r
+                       ((GetHubAdminOption(h, "max_users") != 0) && (LIST_NUM(h->HubDb->UserList) >= GetHubAdminOption(h, "max_users"))))\r
+               {\r
+                       ret = ERR_TOO_MANY_USER;\r
+               }\r
+               else if (SiTooManyUserObjectsInServer(s, false))\r
+               {\r
+                       ret = ERR_TOO_MANY_USERS_CREATED;\r
+                       ALog(a, h, "ERR_128");\r
+               }\r
+               else if (AcIsUser(h, t->Name))\r
+               {\r
+                       ret = ERR_USER_ALREADY_EXISTS;\r
+               }\r
+               else\r
+               {\r
+                       if (StrLen(t->GroupName) != 0)\r
+                       {\r
+                               g = AcGetGroup(h, t->GroupName);\r
+                               if (g == NULL)\r
+                               {\r
+                                       ret = ERR_GROUP_NOT_FOUND;\r
+                               }\r
+                       }\r
+\r
+                       if (ret != ERR_GROUP_NOT_FOUND)\r
+                       {\r
+                               if (g != NULL)\r
+                               {\r
+                                       JoinUserToGroup(u, g);\r
+                                       ReleaseGroup(g);\r
+                               }\r
+\r
+                               AcAddUser(h, u);\r
+                               ALog(a, h, "LA_CREATE_USER", t->Name);\r
+\r
+                               IncrementServerConfigRevision(s);\r
+                       }\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       ReleaseUser(u);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// アクセスリストの列挙\r
+UINT StEnumAccess(ADMIN *a, RPC_ENUM_ACCESS_LIST *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT i;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       FreeRpcEnumAccessList(t);\r
+       Zero(t, sizeof(RPC_ENUM_ACCESS_LIST));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+       LockList(h->AccessList);\r
+       {\r
+               t->NumAccess = LIST_NUM(h->AccessList);\r
+               t->Accesses = ZeroMalloc(sizeof(ACCESS) * t->NumAccess);\r
+\r
+               for (i = 0;i < LIST_NUM(h->AccessList);i++)\r
+               {\r
+                       ACCESS *a = &t->Accesses[i];\r
+                       Copy(a, LIST_DATA(h->AccessList, i), sizeof(ACCESS));\r
+               }\r
+       }\r
+       UnlockList(h->AccessList);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// アクセスリストの削除\r
+UINT StDeleteAccess(ADMIN *a, RPC_DELETE_ACCESS *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT i;\r
+       bool exists;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_access_list") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       exists = false;\r
+\r
+       LockList(h->AccessList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(h->AccessList);i++)\r
+               {\r
+                       ACCESS *access = LIST_DATA(h->AccessList, i);\r
+\r
+                       if (access->Id == t->Id)\r
+                       {\r
+                               Free(access);\r
+                               Delete(h->AccessList, access);\r
+                               exists = true;\r
+\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(h->AccessList);\r
+\r
+       if (exists == false)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+\r
+       ALog(a, h, "LA_DELETE_ACCESS");\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// アクセスリストの設定\r
+UINT StSetAccessList(ADMIN *a, RPC_ENUM_ACCESS_LIST *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT i;\r
+       bool no_jitter = false;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       if (t->NumAccess > GetServerCapsInt(a->Server, "i_max_access_lists"))\r
+       {\r
+               return ERR_TOO_MANY_ACCESS_LIST;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       no_jitter = GetHubAdminOption(h, "no_delay_jitter_packet_loss");\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_access_list") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "max_accesslists") != 0 &&\r
+               t->NumAccess > GetHubAdminOption(h, "max_accesslists"))\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_TOO_MANY_ACCESS_LIST;\r
+       }\r
+\r
+       LockList(h->AccessList);\r
+       {\r
+               UINT i;\r
+\r
+               // 古いバージョンのクライアントで対応できない形式のアクセスリストがすでに\r
+               // 存在しないかどうかチェックする\r
+               if (a->ClientBuild < 6560)\r
+               {\r
+                       for (i = 0;i < LIST_NUM(h->AccessList);i++)\r
+                       {\r
+                               ACCESS *access = LIST_DATA(h->AccessList, i);\r
+                               if (access->IsIPv6 ||\r
+                                       access->Jitter != 0 || access->Loss != 0 || access->Delay != 0)\r
+                               {\r
+                                       ret = ERR_VERSION_INVALID;\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (ret == ERR_NO_ERROR)\r
+               {\r
+                       // すべて削除\r
+                       for (i = 0;i < LIST_NUM(h->AccessList);i++)\r
+                       {\r
+                               ACCESS *access = LIST_DATA(h->AccessList, i);\r
+                               Free(access);\r
+                       }\r
+\r
+                       DeleteAll(h->AccessList);\r
+               }\r
+       }\r
+       UnlockList(h->AccessList);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               ALog(a, h, "LA_SET_ACCESS_LIST", t->NumAccess);\r
+\r
+               // すべてのアクセスリストを追加\r
+               for (i = 0;i < t->NumAccess;i++)\r
+               {\r
+                       ACCESS *a = &t->Accesses[i];\r
+\r
+                       if (no_jitter)\r
+                       {\r
+                               a->Jitter = a->Loss = a->Delay = 0;\r
+                       }\r
+\r
+                       AddAccessList(h, a);\r
+               }\r
+\r
+               IncrementServerConfigRevision(s);\r
+\r
+               h->CurrentVersion++;\r
+               SiHubUpdateProc(h);\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// アクセスリストの追加\r
+UINT StAddAccess(ADMIN *a, RPC_ADD_ACCESS *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       bool no_jitter = false;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       no_jitter = GetHubAdminOption(h, "no_delay_jitter_packet_loss");\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_access_list") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       if ((LIST_NUM(h->AccessList) >= GetServerCapsInt(a->Server, "i_max_access_lists") ||\r
+               (GetHubAdminOption(h, "max_accesslists") != 0) && (LIST_NUM(h->AccessList) >= GetHubAdminOption(h, "max_accesslists"))))\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_TOO_MANY_ACCESS_LIST;\r
+       }\r
+\r
+       ALog(a, h, "LA_ADD_ACCESS");\r
+\r
+       if (no_jitter)\r
+       {\r
+               t->Access.Jitter = t->Access.Delay = t->Access.Loss = 0;\r
+       }\r
+\r
+       AddAccessList(h, &t->Access);\r
+\r
+       h->CurrentVersion++;\r
+       SiHubUpdateProc(h);\r
+\r
+       ReleaseHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// リンクの名前を変更する\r
+UINT StRenameLink(ADMIN *a, RPC_RENAME_LINK *t)\r
+{\r
+       UINT i;\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       LINK *k;\r
+       bool exists = false;\r
+\r
+       if (UniIsEmptyStr(t->OldAccountName) || UniIsEmptyStr(t->NewAccountName))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       if (UniStrCmpi(t->NewAccountName, t->OldAccountName) == 0)\r
+       {\r
+               // 古い名前と新しい名前が同一\r
+               return ERR_NO_ERROR;\r
+       }\r
+\r
+       h = GetHub(c, t->HubName);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_cascade") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       k = NULL;\r
+\r
+       // リンクを検索する\r
+       LockList(h->LinkList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(h->LinkList);i++)\r
+               {\r
+                       LINK *kk = LIST_DATA(h->LinkList, i);\r
+                       Lock(kk->lock);\r
+                       {\r
+                               if (UniStrCmpi(kk->Option->AccountName, t->OldAccountName) == 0)\r
+                               {\r
+                                       k = kk;\r
+                                       AddRef(kk->ref);\r
+                               }\r
+                       }\r
+                       Unlock(kk->lock);\r
+\r
+                       if (k != NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               exists = false;\r
+\r
+               if (k != NULL)\r
+               {\r
+                       // 新しい名前がすでに存在しているリンクの名前と重複するかどうか検査\r
+                       for (i = 0;i < LIST_NUM(h->LinkList);i++)\r
+                       {\r
+                               LINK *kk = LIST_DATA(h->LinkList, i);\r
+                               Lock(kk->lock);\r
+                               {\r
+                                       if (UniStrCmpi(kk->Option->AccountName, t->NewAccountName) == 0)\r
+                                       {\r
+                                               // 重複した\r
+                                               exists = true;\r
+                                       }\r
+                               }\r
+                               Unlock(kk->lock);\r
+                       }\r
+\r
+                       if (exists)\r
+                       {\r
+                               // すでに同一の名前が存在している\r
+                               ret = ERR_LINK_ALREADY_EXISTS;\r
+                       }\r
+                       else\r
+                       {\r
+                               // 変更作業を実施する\r
+                               UniStrCpy(k->Option->AccountName, sizeof(k->Option->AccountName), t->NewAccountName);\r
+\r
+                               ALog(a, h, "LA_RENAME_LINK", t->OldAccountName, t->NewAccountName);\r
+\r
+                               IncrementServerConfigRevision(s);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(h->LinkList);\r
+\r
+       if (k == NULL)\r
+       {\r
+               // リンクが見つからない\r
+               ReleaseHub(h);\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+\r
+       ReleaseLink(k);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// リンクを削除する\r
+UINT StDeleteLink(ADMIN *a, RPC_LINK *t)\r
+{\r
+       UINT i;\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       wchar_t accountname[MAX_ACCOUNT_NAME_LEN + 1];\r
+       LINK *k;\r
+\r
+       if (UniIsEmptyStr(t->AccountName))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_cascade") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       UniStrCpy(accountname, sizeof(accountname), t->AccountName);\r
+       k = NULL;\r
+\r
+       // リンクを検索する\r
+       LockList(h->LinkList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(h->LinkList);i++)\r
+               {\r
+                       LINK *kk = LIST_DATA(h->LinkList, i);\r
+                       Lock(kk->lock);\r
+                       {\r
+                               if (UniStrCmpi(kk->Option->AccountName, accountname) == 0)\r
+                               {\r
+                                       k = kk;\r
+                                       AddRef(kk->ref);\r
+                               }\r
+                       }\r
+                       Unlock(kk->lock);\r
+\r
+                       if (k != NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(h->LinkList);\r
+\r
+       if (k == NULL)\r
+       {\r
+               // リンクが見つからない\r
+               ReleaseHub(h);\r
+\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+\r
+       ALog(a, h, "LA_DELETE_LINK", t->AccountName);\r
+\r
+       SetLinkOffline(k);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       DelLink(h, k);\r
+\r
+       ReleaseLink(k);\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// リンクをオフラインにする\r
+UINT StSetLinkOffline(ADMIN *a, RPC_LINK *t)\r
+{\r
+       UINT i;\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       wchar_t accountname[MAX_ACCOUNT_NAME_LEN + 1];\r
+       LINK *k;\r
+\r
+       if (UniIsEmptyStr(t->AccountName))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_cascade") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       UniStrCpy(accountname, sizeof(accountname), t->AccountName);\r
+       k = NULL;\r
+\r
+       // リンクを検索する\r
+       LockList(h->LinkList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(h->LinkList);i++)\r
+               {\r
+                       LINK *kk = LIST_DATA(h->LinkList, i);\r
+                       Lock(kk->lock);\r
+                       {\r
+                               if (UniStrCmpi(kk->Option->AccountName, accountname) == 0)\r
+                               {\r
+                                       k = kk;\r
+                                       AddRef(kk->ref);\r
+                               }\r
+                       }\r
+                       Unlock(kk->lock);\r
+\r
+                       if (k != NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(h->LinkList);\r
+\r
+       if (k == NULL)\r
+       {\r
+               // リンクが見つからない\r
+               ReleaseHub(h);\r
+\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+\r
+       ALog(a, h, "LA_SET_LINK_OFFLINE", t->AccountName);\r
+\r
+       SetLinkOffline(k);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       ReleaseLink(k);\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// リンクをオンラインにする\r
+UINT StSetLinkOnline(ADMIN *a, RPC_LINK *t)\r
+{\r
+       UINT i;\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       wchar_t accountname[MAX_ACCOUNT_NAME_LEN + 1];\r
+       LINK *k;\r
+\r
+       if (UniIsEmptyStr(t->AccountName))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_cascade") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       UniStrCpy(accountname, sizeof(accountname), t->AccountName);\r
+       k = NULL;\r
+\r
+       // リンクを検索する\r
+       LockList(h->LinkList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(h->LinkList);i++)\r
+               {\r
+                       LINK *kk = LIST_DATA(h->LinkList, i);\r
+                       Lock(kk->lock);\r
+                       {\r
+                               if (UniStrCmpi(kk->Option->AccountName, accountname) == 0)\r
+                               {\r
+                                       k = kk;\r
+                                       AddRef(kk->ref);\r
+                               }\r
+                       }\r
+                       Unlock(kk->lock);\r
+\r
+                       if (k != NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(h->LinkList);\r
+\r
+       if (k == NULL)\r
+       {\r
+               // リンクが見つからない\r
+               ReleaseHub(h);\r
+\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+\r
+       ALog(a, h, "LA_SET_LINK_ONLINE", t->AccountName);\r
+\r
+       SetLinkOnline(k);\r
+\r
+       ReleaseLink(k);\r
+       ReleaseHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// リンク状態の取得\r
+UINT StGetLinkStatus(ADMIN *a, RPC_LINK_STATUS *t)\r
+{\r
+       UINT i;\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       wchar_t accountname[MAX_ACCOUNT_NAME_LEN + 1];\r
+       LINK *k;\r
+       SESSION *sess;\r
+\r
+       if (UniIsEmptyStr(t->AccountName))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       UniStrCpy(accountname, sizeof(accountname), t->AccountName);\r
+       FreeRpcLinkStatus(t);\r
+       Zero(t, sizeof(RPC_LINK_STATUS));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+       UniStrCpy(t->AccountName, sizeof(t->AccountName), accountname);\r
+\r
+       k = NULL;\r
+\r
+       // リンクを検索する\r
+       LockList(h->LinkList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(h->LinkList);i++)\r
+               {\r
+                       LINK *kk = LIST_DATA(h->LinkList, i);\r
+                       Lock(kk->lock);\r
+                       {\r
+                               if (UniStrCmpi(kk->Option->AccountName, accountname) == 0)\r
+                               {\r
+                                       k = kk;\r
+                                       AddRef(kk->ref);\r
+                               }\r
+                       }\r
+                       Unlock(kk->lock);\r
+\r
+                       if (k != NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(h->LinkList);\r
+\r
+       if (k == NULL)\r
+       {\r
+               // リンクが見つからない\r
+               ReleaseHub(h);\r
+\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+\r
+       // セッションからステータス情報を取得する\r
+       Lock(k->lock);\r
+       {\r
+               sess = k->ClientSession;\r
+               if (sess != NULL)\r
+               {\r
+                       AddRef(sess->ref);\r
+               }\r
+       }\r
+       Unlock(k->lock);\r
+\r
+       if (sess != NULL && k->Offline == false)\r
+       {\r
+               CiGetSessionStatus(&t->Status, sess);\r
+       }\r
+       else\r
+       {\r
+               ret = ERR_LINK_IS_OFFLINE;\r
+       }\r
+       ReleaseSession(sess);\r
+\r
+       ReleaseLink(k);\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// リンクの列挙\r
+UINT StEnumLink(ADMIN *a, RPC_ENUM_LINK *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       UINT i;\r
+\r
+       if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       FreeRpcEnumLink(t);\r
+       Zero(t, sizeof(RPC_ENUM_LINK));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+       LockList(h->LinkList);\r
+       {\r
+               t->NumLink = LIST_NUM(h->LinkList);\r
+               t->Links = ZeroMalloc(sizeof(RPC_ENUM_LINK_ITEM) * t->NumLink);\r
+\r
+               for (i = 0;i < LIST_NUM(h->LinkList);i++)\r
+               {\r
+                       LINK *k = LIST_DATA(h->LinkList, i);\r
+                       RPC_ENUM_LINK_ITEM *e = &t->Links[i];\r
+\r
+                       Lock(k->lock);\r
+                       {\r
+                               UniStrCpy(e->AccountName, sizeof(e->AccountName), k->Option->AccountName);\r
+                               StrCpy(e->Hostname, sizeof(e->Hostname), k->Option->Hostname);\r
+                               StrCpy(e->HubName, sizeof(e->HubName), k->Option->HubName);\r
+                               e->Online = k->Offline ? false : true;\r
+\r
+                               if (e->Online)\r
+                               {\r
+                                       if (k->ClientSession != NULL)\r
+                                       {\r
+                                               e->ConnectedTime = TickToTime(k->ClientSession->CurrentConnectionEstablishTime);\r
+                                               e->Connected = (k->ClientSession->ClientStatus == CLIENT_STATUS_ESTABLISHED);\r
+                                               e->LastError = k->ClientSession->Err;\r
+                                       }\r
+                               }\r
+                       }\r
+                       Unlock(k->lock);\r
+               }\r
+       }\r
+       UnlockList(h->LinkList);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// リンクの取得\r
+UINT StGetLink(ADMIN *a, RPC_CREATE_LINK *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       UINT i;\r
+       char hubname[MAX_SIZE];\r
+       LINK *k;\r
+\r
+       if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               return ERR_LINK_CANT_CREATE_ON_FARM;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       k = NULL;\r
+\r
+       // リンクを検索する\r
+       LockList(h->LinkList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(h->LinkList);i++)\r
+               {\r
+                       LINK *kk = LIST_DATA(h->LinkList, i);\r
+                       Lock(kk->lock);\r
+                       {\r
+                               if (UniStrCmpi(kk->Option->AccountName, t->ClientOption->AccountName) == 0)\r
+                               {\r
+                                       k = kk;\r
+                                       AddRef(kk->ref);\r
+                               }\r
+                       }\r
+                       Unlock(kk->lock);\r
+\r
+                       if (k != NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(h->LinkList);\r
+\r
+       if (k == NULL)\r
+       {\r
+               // 見つからなかった\r
+               ReleaseHub(h);\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       FreeRpcCreateLink(t);\r
+       Zero(t, sizeof(t));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+       Lock(k->lock);\r
+       {\r
+               // 設定の取得\r
+               t->Online = k->Offline ? false : true;\r
+               t->ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               Copy(t->ClientOption, k->Option, sizeof(CLIENT_OPTION));\r
+               t->ClientAuth = CopyClientAuth(k->Auth);\r
+               Copy(&t->Policy, k->Policy, sizeof(POLICY));\r
+\r
+               t->CheckServerCert = k->CheckServerCert;\r
+               t->ServerCert = CloneX(k->ServerCert);\r
+       }\r
+       Unlock(k->lock);\r
+\r
+       ReleaseLink(k);\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// リンクの設定\r
+UINT StSetLink(ADMIN *a, RPC_CREATE_LINK *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       UINT i;\r
+       LINK *k;\r
+\r
+       if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               return ERR_LINK_CANT_CREATE_ON_FARM;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_cascade") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       k = NULL;\r
+\r
+       // リンクを検索する\r
+       LockList(h->LinkList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(h->LinkList);i++)\r
+               {\r
+                       LINK *kk = LIST_DATA(h->LinkList, i);\r
+                       Lock(kk->lock);\r
+                       {\r
+                               if (UniStrCmpi(kk->Option->AccountName, t->ClientOption->AccountName) == 0)\r
+                               {\r
+                                       k = kk;\r
+                                       AddRef(kk->ref);\r
+                               }\r
+                       }\r
+                       Unlock(kk->lock);\r
+\r
+                       if (k != NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(h->LinkList);\r
+\r
+       if (k == NULL)\r
+       {\r
+               // 見つからなかった\r
+               ReleaseHub(h);\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+\r
+       ALog(a, h, "LA_SET_LINK", t->ClientOption->AccountName);\r
+\r
+       Lock(k->lock);\r
+       {\r
+               // 設定の更新\r
+               if (k->ServerCert != NULL)\r
+               {\r
+                       FreeX(k->ServerCert);\r
+                       k->ServerCert = NULL;\r
+               }\r
+\r
+               Copy(k->Option, t->ClientOption, sizeof(CLIENT_OPTION));\r
+               StrCpy(k->Option->DeviceName, sizeof(k->Option->DeviceName), LINK_DEVICE_NAME);\r
+               k->Option->NumRetry = INFINITE;\r
+               k->Option->RetryInterval = 10;\r
+               k->Option->NoRoutingTracking = true;\r
+               CiFreeClientAuth(k->Auth);\r
+               k->Auth = CopyClientAuth(t->ClientAuth);\r
+\r
+               if (t->Policy.Ver3 == false)\r
+               {\r
+                       Copy(k->Policy, &t->Policy, sizeof(UINT) * NUM_POLICY_ITEM_FOR_VER2);\r
+               }\r
+               else\r
+               {\r
+                       Copy(k->Policy, &t->Policy, sizeof(POLICY));\r
+               }\r
+\r
+               k->Option->RequireBridgeRoutingMode = true;     // ブリッジ / ルーティングモード有効\r
+               k->Option->RequireMonitorMode = false;  // モニタモード無効\r
+\r
+               k->CheckServerCert = t->CheckServerCert;\r
+               k->ServerCert = CloneX(t->ServerCert);\r
+       }\r
+       Unlock(k->lock);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       ReleaseLink(k);\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// リンクの作成\r
+UINT StCreateLink(ADMIN *a, RPC_CREATE_LINK *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       UINT i;\r
+       LINK *k;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               return ERR_LINK_CANT_CREATE_ON_FARM;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_cascade") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       k = NULL;\r
+\r
+       // 既に同じ名前のリンクが存在しないかどうか調べる\r
+       LockList(h->LinkList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(h->LinkList);i++)\r
+               {\r
+                       LINK *kk = LIST_DATA(h->LinkList, i);\r
+                       Lock(kk->lock);\r
+                       {\r
+                               if (UniStrCmpi(kk->Option->AccountName, t->ClientOption->AccountName) == 0)\r
+                               {\r
+                                       k = kk;\r
+                                       AddRef(kk->ref);\r
+                               }\r
+                       }\r
+                       Unlock(kk->lock);\r
+\r
+                       if (k != NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(h->LinkList);\r
+\r
+       if (k != NULL)\r
+       {\r
+               // すでに同じ名前のリンクが存在する\r
+               ReleaseLink(k);\r
+               ReleaseHub(h);\r
+               return ERR_LINK_ALREADY_EXISTS;\r
+       }\r
+\r
+       ALog(a, h, "LA_CREATE_LINK", t->ClientOption->AccountName);\r
+\r
+       // リンクの作成\r
+       k = NewLink(c, h, t->ClientOption, t->ClientAuth, &t->Policy);\r
+\r
+       if (k == NULL)\r
+       {\r
+               // 作成失敗\r
+               ret = ERR_INTERNAL_ERROR;\r
+       }\r
+       else\r
+       {\r
+               // サーバー証明書検証設定\r
+               k->CheckServerCert = t->CheckServerCert;\r
+               k->ServerCert = CloneX(t->ServerCert);\r
+\r
+               // オフラインにしておく\r
+               k->Offline = false;\r
+               SetLinkOffline(k);\r
+               ReleaseLink(k);\r
+\r
+               IncrementServerConfigRevision(s);\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// HUB の CA を削除\r
+UINT StDeleteCa(ADMIN *a, RPC_HUB_DELETE_CA *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_cert_list") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       LockList(h->HubDb->RootCertList);\r
+       {\r
+               if (IsInListKey(h->HubDb->RootCertList, t->Key))\r
+               {\r
+                       X *x = ListKeyToPointer(h->HubDb->RootCertList, t->Key);\r
+                       Delete(h->HubDb->RootCertList, x);\r
+                       FreeX(x);\r
+\r
+                       ALog(a, h, "LA_DELETE_CA");\r
+\r
+                       IncrementServerConfigRevision(s);\r
+               }\r
+               else\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+       }\r
+       UnlockList(h->HubDb->RootCertList);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// HUB の CA を取得\r
+UINT StGetCa(ADMIN *a, RPC_HUB_GET_CA *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       UINT key;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+       key = t->Key;\r
+\r
+       FreeRpcHubGetCa(t);\r
+       Zero(t, sizeof(RPC_HUB_GET_CA));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       LockList(h->HubDb->RootCertList);\r
+       {\r
+               if (IsInListKey(h->HubDb->RootCertList, key))\r
+               {\r
+                       X *x = ListKeyToPointer(h->HubDb->RootCertList, key);\r
+\r
+                       t->Cert = CloneX(x);\r
+               }\r
+               else\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+       }\r
+       UnlockList(h->HubDb->RootCertList);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// HUB の CA を列挙\r
+UINT StEnumCa(ADMIN *a, RPC_HUB_ENUM_CA *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       UINT i;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       FreeRpcHubEnumCa(t);\r
+       Zero(t, sizeof(RPC_HUB_ENUM_CA));\r
+\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, hubname);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_HUB_ENUM_CA));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+\r
+       if (h->HubDb->RootCertList != NULL)\r
+       {\r
+               LockList(h->HubDb->RootCertList);\r
+               {\r
+                       t->NumCa = LIST_NUM(h->HubDb->RootCertList);\r
+                       t->Ca = ZeroMalloc(sizeof(RPC_HUB_ENUM_CA_ITEM) * t->NumCa);\r
+\r
+                       for (i = 0;i < t->NumCa;i++)\r
+                       {\r
+                               RPC_HUB_ENUM_CA_ITEM *e = &t->Ca[i];\r
+                               X *x = LIST_DATA(h->HubDb->RootCertList, i);\r
+\r
+                               e->Key = POINTER_TO_KEY(x);\r
+                               GetAllNameFromNameEx(e->SubjectName, sizeof(e->SubjectName), x->subject_name);\r
+                               GetAllNameFromNameEx(e->IssuerName, sizeof(e->IssuerName), x->issuer_name);\r
+                               e->Expires = x->notAfter;\r
+                       }\r
+               }\r
+               UnlockList(h->HubDb->RootCertList);\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// HUB へ CA を追加\r
+UINT StAddCa(ADMIN *a, RPC_HUB_ADD_CA *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       if (c->Bridge)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       if (t->Cert == NULL)\r
+       {\r
+               ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (t->Cert->is_compatible_bit == false)\r
+       {\r
+               return ERR_NOT_RSA_1024;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_cert_list") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       ALog(a, h, "LA_ADD_CA");\r
+\r
+       AddRootCert(h, t->Cert);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// HUB ログ設定の取得\r
+UINT StGetHubLog(ADMIN *a, RPC_HUB_LOG *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       GetHubLogSetting(h, &t->LogSetting);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// HUB ログ設定の設定\r
+UINT StSetHubLog(ADMIN *a, RPC_HUB_LOG *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_log_config") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       ALog(a, h, "LA_SET_HUB_LOG");\r
+\r
+       SetHubLogSettingEx(h, &t->LogSetting,\r
+               (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_log_switch_type") != 0));\r
+\r
+       h->CurrentVersion++;\r
+       SiHubUpdateProc(h);\r
+\r
+       ReleaseHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// HUB 状態の取得\r
+UINT StGetHubStatus(ADMIN *a, RPC_HUB_STATUS *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_HUB_STATUS));\r
+\r
+       Lock(h->lock);\r
+       {\r
+               StrCpy(t->HubName, sizeof(t->HubName), h->Name);\r
+               t->HubType = h->Type;\r
+               t->Online = h->Offline ? false : true;\r
+               t->NumSessions = LIST_NUM(h->SessionList);\r
+               t->NumSessionsClient = Count(h->NumSessionsClient);\r
+               t->NumSessionsBridge = Count(h->NumSessionsBridge);\r
+               t->NumAccessLists = LIST_NUM(h->AccessList);\r
+\r
+               if (h->HubDb != NULL)\r
+               {\r
+                       t->NumUsers = LIST_NUM(h->HubDb->UserList);\r
+                       t->NumGroups = LIST_NUM(h->HubDb->GroupList);\r
+               }\r
+\r
+               t->NumMacTables = LIST_NUM(h->MacTable);\r
+               t->NumIpTables = LIST_NUM(h->IpTable);\r
+\r
+               Lock(h->TrafficLock);\r
+               {\r
+                       Copy(&t->Traffic, h->Traffic, sizeof(TRAFFIC));\r
+               }\r
+               Unlock(h->TrafficLock);\r
+\r
+               t->NumLogin = h->NumLogin;\r
+               t->LastCommTime = h->LastCommTime;\r
+               t->LastLoginTime = h->LastLoginTime;\r
+               t->CreatedTime = h->CreatedTime;\r
+       }\r
+       Unlock(h->lock);\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               UINT i;\r
+               LockList(s->FarmMemberList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                       {\r
+                               UINT k;\r
+                               FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+\r
+                               if (f->Me == false)\r
+                               {\r
+                                       LockList(f->HubList);\r
+                                       {\r
+                                               for (k = 0;k < LIST_NUM(f->HubList);k++)\r
+                                               {\r
+                                                       HUB_LIST *h = LIST_DATA(f->HubList, k);\r
+\r
+                                                       if (StrCmpi(h->Name, t->HubName) == 0)\r
+                                                       {\r
+                                                               t->NumSessions += h->NumSessions;\r
+                                                               t->NumSessionsClient += h->NumSessionsClient;\r
+                                                               t->NumSessionsBridge += h->NumSessionsBridge;\r
+                                                               t->NumMacTables += h->NumMacTables;\r
+                                                               t->NumIpTables += h->NumIpTables;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       UnlockList(f->HubList);\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(s->FarmMemberList);\r
+       }\r
+\r
+       if (h->Type != HUB_TYPE_FARM_STATIC)\r
+       {\r
+               t->SecureNATEnabled = h->EnableSecureNAT;\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// HUB の SecureNAT を有効にする\r
+UINT StEnableSecureNAT(ADMIN *a, RPC_HUB *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (h->Type == HUB_TYPE_FARM_STATIC || GetServerCapsBool(s, "b_support_securenat") == false)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_securenat") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       ALog(a, h, "LA_ENABLE_SNAT");\r
+\r
+       EnableSecureNAT(h, true);\r
+\r
+       h->CurrentVersion++;\r
+       SiHubUpdateProc(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// HUB の SecureNAT を無効にする\r
+UINT StDisableSecureNAT(ADMIN *a, RPC_HUB *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (h->Type == HUB_TYPE_FARM_STATIC || GetServerCapsBool(s, "b_support_securenat") == false)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_securenat") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       ALog(a, h, "LA_DISABLE_SNAT");\r
+\r
+       EnableSecureNAT(h, false);\r
+\r
+       h->CurrentVersion++;\r
+       SiHubUpdateProc(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// NAT エントリの列挙\r
+UINT StEnumNAT(ADMIN *a, RPC_ENUM_NAT *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       UINT i;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (h->Type == HUB_TYPE_FARM_STATIC || GetServerCapsBool(s, "b_support_securenat") == false)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       Lock(h->lock_online);\r
+       {\r
+               if (h->SecureNAT == NULL)\r
+               {\r
+                       ret = ERR_SNAT_NOT_RUNNING;\r
+               }\r
+               else\r
+               {\r
+                       NtEnumNatList(h->SecureNAT->Nat, t);\r
+               }\r
+       }\r
+       Unlock(h->lock_online);\r
+\r
+       if (h->Type == HUB_TYPE_FARM_DYNAMIC)\r
+       {\r
+               if (ret == ERR_SNAT_NOT_RUNNING)\r
+               {\r
+                       // リモートの SecureNAT の状態取得\r
+                       LockList(s->FarmMemberList);\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                               {\r
+                                       FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                                       if (f->Me == false)\r
+                                       {\r
+                                               RPC_ENUM_NAT tmp;\r
+\r
+                                               Zero(&tmp, sizeof(tmp));\r
+\r
+                                               SiCallEnumNat(s, f, hubname, &tmp);\r
+\r
+                                               if (tmp.NumItem >= 1)\r
+                                               {\r
+                                                       FreeRpcEnumNat(t);\r
+                                                       Copy(t, &tmp, sizeof(RPC_ENUM_NAT));\r
+                                                       ret = ERR_NO_ERROR;\r
+                                                       break;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       FreeRpcEnumNat(&tmp);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       UnlockList(s->FarmMemberList);\r
+               }\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       ret = ERR_NO_ERROR;\r
+\r
+       return ret;\r
+}\r
+\r
+// SecureNAT の状態の取得\r
+UINT StGetSecureNATStatus(ADMIN *a, RPC_NAT_STATUS *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       UINT i;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (h->Type == HUB_TYPE_FARM_STATIC || GetServerCapsBool(s, "b_support_securenat") == false)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       Lock(h->lock_online);\r
+       {\r
+               if (h->SecureNAT == NULL)\r
+               {\r
+                       ret = ERR_SNAT_NOT_RUNNING;\r
+               }\r
+               else\r
+               {\r
+                       NtGetStatus(h->SecureNAT->Nat, t);\r
+               }\r
+       }\r
+       Unlock(h->lock_online);\r
+\r
+       if (h->Type == HUB_TYPE_FARM_DYNAMIC)\r
+       {\r
+               if (ret == ERR_SNAT_NOT_RUNNING)\r
+               {\r
+                       // リモートの SecureNAT の状態取得\r
+                       LockList(s->FarmMemberList);\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                               {\r
+                                       FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                                       if (f->Me == false)\r
+                                       {\r
+                                               RPC_NAT_STATUS tmp;\r
+\r
+                                               Zero(&tmp, sizeof(tmp));\r
+\r
+                                               SiCallGetNatStatus(s, f, hubname, &tmp);\r
+\r
+                                               if (tmp.NumDhcpClients == 0 && tmp.NumTcpSessions == 0 && tmp.NumUdpSessions == 0)\r
+                                               {\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       Copy(t, &tmp, sizeof(RPC_NAT_STATUS));\r
+                                                       ret = ERR_NO_ERROR;\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       UnlockList(s->FarmMemberList);\r
+               }\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       ret = ERR_NO_ERROR;\r
+\r
+       return ret;\r
+}\r
+\r
+// DHCP エントリの列挙\r
+UINT StEnumDHCP(ADMIN *a, RPC_ENUM_DHCP *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       UINT i;\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (h->Type == HUB_TYPE_FARM_STATIC || GetServerCapsBool(s, "b_support_securenat") == false)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       Lock(h->lock_online);\r
+       {\r
+               if (h->SecureNAT == NULL)\r
+               {\r
+                       ret = ERR_SNAT_NOT_RUNNING;\r
+               }\r
+               else\r
+               {\r
+                       NtEnumDhcpList(h->SecureNAT->Nat, t);\r
+               }\r
+       }\r
+       Unlock(h->lock_online);\r
+\r
+       if (h->Type == HUB_TYPE_FARM_DYNAMIC)\r
+       {\r
+               if (ret == ERR_SNAT_NOT_RUNNING)\r
+               {\r
+                       // リモートの DHCP の状態取得\r
+                       LockList(s->FarmMemberList);\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                               {\r
+                                       FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                                       if (f->Me == false)\r
+                                       {\r
+                                               RPC_ENUM_DHCP tmp;\r
+\r
+                                               Zero(&tmp, sizeof(tmp));\r
+\r
+                                               SiCallEnumDhcp(s, f, hubname, &tmp);\r
+\r
+                                               if (tmp.NumItem >= 1)\r
+                                               {\r
+                                                       FreeRpcEnumDhcp(t);\r
+                                                       Copy(t, &tmp, sizeof(RPC_ENUM_DHCP));\r
+                                                       ret = ERR_NO_ERROR;\r
+                                                       break;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       FreeRpcEnumDhcp(&tmp);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       UnlockList(s->FarmMemberList);\r
+               }\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       ret = ERR_NO_ERROR;\r
+\r
+       return ret;\r
+}\r
+\r
+// SecureNATOption を設定する\r
+UINT StSetSecureNATOption(ADMIN *a, VH_OPTION *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+\r
+       if (IsZero(t->MacAddress, sizeof(t->MacAddress)) ||\r
+               IsHostIPAddress4(&t->Ip) == false ||\r
+               IsSubnetMask4(&t->Mask) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+       if ((IPToUINT(&t->Ip) & (~(IPToUINT(&t->Mask)))) == 0)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (h->Type == HUB_TYPE_FARM_STATIC || GetServerCapsBool(s, "b_support_securenat") == false)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && GetHubAdminOption(h, "no_securenat") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       if (h->SecureNATOption->UseNat == false && t->UseNat)\r
+       {\r
+               if (a->ServerAdmin == false && GetHubAdminOption(h, "no_securenat_enablenat") != 0)\r
+               {\r
+                       ReleaseHub(h);\r
+                       return ERR_NOT_ENOUGH_RIGHT;\r
+               }\r
+       }\r
+\r
+       if (h->SecureNATOption->UseDhcp == false && t->UseDhcp)\r
+       {\r
+               if (a->ServerAdmin == false && GetHubAdminOption(h, "no_securenat_enabledhcp") != 0)\r
+               {\r
+                       ReleaseHub(h);\r
+                       return ERR_NOT_ENOUGH_RIGHT;\r
+               }\r
+       }\r
+\r
+       Copy(h->SecureNATOption, t, sizeof(VH_OPTION));\r
+\r
+       if (h->Type != HUB_TYPE_STANDALONE && h->Cedar != NULL && h->Cedar->Server != NULL &&\r
+               h->Cedar->Server->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               NiClearUnsupportedVhOptionForDynamicHub(h->SecureNATOption, false);\r
+       }\r
+\r
+       Lock(h->lock_online);\r
+       {\r
+               if (h->SecureNAT != NULL)\r
+               {\r
+                       SetVirtualHostOption(h->SecureNAT->Nat->Virtual, t);\r
+               }\r
+       }\r
+       Unlock(h->lock_online);\r
+\r
+       ALog(a, h, "LA_SET_SNAT_OPTION");\r
+\r
+       h->CurrentVersion++;\r
+       SiHubUpdateProc(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// SecureNATOption を取得する\r
+UINT StGetSecureNATOption(ADMIN *a, VH_OPTION *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+\r
+       StrCpy(hubname, sizeof(hubname), t->HubName);\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (h->Type == HUB_TYPE_FARM_STATIC || GetServerCapsBool(s, "b_support_securenat") == false)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       Zero(t, sizeof(VH_OPTION));\r
+       StrCpy(t->HubName, sizeof(t->HubName), hubname);\r
+       Copy(t, h->SecureNATOption, sizeof(VH_OPTION));\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// HUB をオンラインまたはオフラインにする\r
+UINT StSetHubOnline(ADMIN *a, RPC_SET_HUB_ONLINE *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && t->Online && GetHubAdminOption(h, "no_online") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       if (a->ServerAdmin == false && t->Online == false && GetHubAdminOption(h, "no_offline") != 0)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_ENOUGH_RIGHT;\r
+       }\r
+\r
+       if (t->Online)\r
+       {\r
+               ALog(a, h, "LA_SET_HUB_ONLINE");\r
+               SetHubOnline(h);\r
+       }\r
+       else\r
+       {\r
+               ALog(a, h, "LA_SET_HUB_OFFLINE");\r
+               SetHubOffline(h);\r
+       }\r
+\r
+       h->CurrentVersion++;\r
+       SiHubUpdateProc(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// コネクション情報の取得\r
+UINT StGetConnectionInfo(ADMIN *a, RPC_CONNECTION_INFO *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       CONNECTION *connection;\r
+       char name[MAX_CONNECTION_NAME_LEN + 1];\r
+\r
+       if (IsEmptyStr(t->Name))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       LockList(c->ConnectionList);\r
+       {\r
+               CONNECTION tt;\r
+               Zero(&tt, sizeof(tt));\r
+               tt.Name = t->Name;\r
+               StrCpy(name, sizeof(name), t->Name);\r
+\r
+               connection = Search(c->ConnectionList, &tt);\r
+\r
+               if (connection != NULL)\r
+               {\r
+                       AddRef(connection->ref);\r
+               }\r
+       }\r
+       UnlockList(c->ConnectionList);\r
+\r
+       if (connection == NULL)\r
+       {\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_CONNECTION_INFO));\r
+       StrCpy(t->Name, sizeof(t->Name), name);\r
+\r
+       Lock(connection->lock);\r
+       {\r
+               SOCK *s = connection->FirstSock;\r
+\r
+               if (s != NULL)\r
+               {\r
+                       t->Ip = IPToUINT(&s->RemoteIP);\r
+                       t->Port = s->RemotePort;\r
+                       StrCpy(t->Hostname, sizeof(t->Hostname), s->RemoteHostname);\r
+               }\r
+\r
+               StrCpy(t->Name, sizeof(t->Name), connection->Name);\r
+               t->ConnectedTime = TickToTime(connection->ConnectedTick);\r
+               t->Type = connection->Type;\r
+\r
+               StrCpy(t->ServerStr, sizeof(t->ServerStr), connection->ServerStr);\r
+               StrCpy(t->ClientStr, sizeof(t->ClientStr), connection->ClientStr);\r
+               t->ServerVer = connection->ServerVer;\r
+               t->ServerBuild = connection->ServerBuild;\r
+               t->ClientVer = connection->ClientVer;\r
+               t->ClientBuild = connection->ClientBuild;\r
+       }\r
+       Unlock(connection->lock);\r
+\r
+       ReleaseConnection(connection);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// コネクションの切断\r
+UINT StDisconnectConnection(ADMIN *a, RPC_DISCONNECT_CONNECTION *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       CONNECTION *connection;\r
+\r
+       if (IsEmptyStr(t->Name))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       LockList(c->ConnectionList);\r
+       {\r
+               CONNECTION tt;\r
+               Zero(&tt, sizeof(tt));\r
+               tt.Name = t->Name;\r
+\r
+               connection = Search(c->ConnectionList, &tt);\r
+               if (connection != NULL)\r
+               {\r
+                       AddRef(connection->ref);\r
+               }\r
+       }\r
+       UnlockList(c->ConnectionList);\r
+\r
+       if (connection == NULL)\r
+       {\r
+               return ERR_OBJECT_NOT_FOUND;\r
+       }\r
+\r
+       StopConnection(connection, true);\r
+\r
+       ReleaseConnection(connection);\r
+\r
+       ALog(a, NULL, "LA_DISCONNECT_CONN", t->Name);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// コネクションの列挙\r
+UINT StEnumConnection(ADMIN *a, RPC_ENUM_CONNECTION *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       FreeRpcEnumConnetion(t);\r
+       Zero(t, sizeof(RPC_ENUM_CONNECTION));\r
+\r
+       LockList(c->ConnectionList);\r
+       {\r
+               UINT i;\r
+               t->NumConnection = LIST_NUM(c->ConnectionList);\r
+               t->Connections = ZeroMalloc(sizeof(RPC_ENUM_CONNECTION_ITEM) * t->NumConnection);\r
+               \r
+               for (i = 0;i < t->NumConnection;i++)\r
+               {\r
+                       RPC_ENUM_CONNECTION_ITEM *e = &t->Connections[i];\r
+                       CONNECTION *connection = LIST_DATA(c->ConnectionList, i);\r
+\r
+                       Lock(connection->lock);\r
+                       {\r
+                               SOCK *s = connection->FirstSock;\r
+\r
+                               if (s != NULL)\r
+                               {\r
+                                       e->Ip = IPToUINT(&s->RemoteIP);\r
+                                       e->Port = s->RemotePort;\r
+                                       StrCpy(e->Hostname, sizeof(e->Hostname), s->RemoteHostname);\r
+                               }\r
+\r
+                               StrCpy(e->Name, sizeof(e->Name), connection->Name);\r
+                               e->ConnectedTime = TickToTime(connection->ConnectedTick);\r
+                               e->Type = connection->Type;\r
+                       }\r
+                       Unlock(connection->lock);\r
+               }\r
+       }\r
+       UnlockList(c->ConnectionList);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// HUB の Radius オプションの設定\r
+UINT StSetHubRadius(ADMIN *a, RPC_RADIUS *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       SetRadiusServerEx(h, t->RadiusServerName, t->RadiusPort, t->RadiusSecret, t->RadiusRetryInterval);\r
+\r
+       ALog(a, h, "LA_SET_HUB_RADIUS");\r
+\r
+       ReleaseHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// HUB の Radius オプションの取得\r
+UINT StGetHubRadius(ADMIN *a, RPC_RADIUS *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+\r
+       CHECK_RIGHT;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       Zero(t, sizeof(t));\r
+       GetRadiusServerEx(h, t->RadiusServerName, sizeof(t->RadiusServerName),\r
+               &t->RadiusPort, t->RadiusSecret, sizeof(t->RadiusSecret), &t->RadiusRetryInterval);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// HUB の削除\r
+UINT StDeleteHub(ADMIN *a, RPC_DELETE_HUB *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       if (IsEmptyStr(t->HubName) || IsSafeStr(t->HubName) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       StopHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       DelHub(c, h);\r
+       ReleaseHub(h);\r
+\r
+       ALog(a, NULL, "LA_DELETE_HUB", t->HubName);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// HUB の列挙\r
+UINT StEnumHub(ADMIN *a, RPC_ENUM_HUB *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h = NULL;\r
+\r
+       FreeRpcEnumHub(t);\r
+\r
+       Zero(t, sizeof(RPC_ENUM_HUB));\r
+\r
+       LockHubList(c);\r
+       {\r
+               UINT i, num, j;\r
+\r
+               num = 0;\r
+\r
+               for (i = 0;i < LIST_NUM(c->HubList);i++)\r
+               {\r
+                       HUB *h = LIST_DATA(c->HubList, i);\r
+\r
+                       Lock(h->lock);\r
+\r
+                       if (a->ServerAdmin == false &&\r
+                               h->Option != NULL &&\r
+                               StrCmpi(h->Name, a->HubName) != 0)\r
+                       {\r
+                               // 列挙を許可しない\r
+                       }\r
+                       else\r
+                       {\r
+                               // 列挙を許可する\r
+                               num++;\r
+                       }\r
+               }\r
+\r
+               t->NumHub = num;\r
+\r
+               t->Hubs = ZeroMalloc(sizeof(RPC_ENUM_HUB_ITEM) * num);\r
+\r
+               i = 0;\r
+               for (j = 0;j < LIST_NUM(c->HubList);j++)\r
+               {\r
+                       HUB *h = LIST_DATA(c->HubList, j);\r
+\r
+                       if (a->ServerAdmin == false &&\r
+                               h->Option != NULL &&\r
+                               StrCmpi(h->Name, a->HubName) != 0)\r
+                       {\r
+                               // 列挙許可しない\r
+                       }\r
+                       else\r
+                       {\r
+                               // 列挙許可\r
+                               RPC_ENUM_HUB_ITEM *e = &t->Hubs[i++];\r
+\r
+                               StrCpy(e->HubName, sizeof(e->HubName), h->Name);\r
+                               e->Online = h->Offline ? false : true;\r
+                               e->HubType = h->Type;\r
+\r
+                               e->NumSessions = LIST_NUM(h->SessionList);\r
+\r
+                               LockList(h->MacTable);\r
+                               {\r
+                                       e->NumMacTables = LIST_NUM(h->MacTable);\r
+                               }\r
+                               UnlockList(h->MacTable);\r
+\r
+                               LockList(h->IpTable);\r
+                               {\r
+                                       e->NumIpTables = LIST_NUM(h->IpTable);\r
+                               }\r
+                               UnlockList(h->IpTable);\r
+\r
+                               if (h->HubDb != NULL)\r
+                               {\r
+                                       LockList(h->HubDb->UserList);\r
+                                       {\r
+                                               e->NumUsers = LIST_NUM(h->HubDb->UserList);\r
+                                       }\r
+                                       UnlockList(h->HubDb->UserList);\r
+\r
+                                       LockList(h->HubDb->GroupList);\r
+                                       {\r
+                                               e->NumGroups = LIST_NUM(h->HubDb->GroupList);\r
+                                       }\r
+                                       UnlockList(h->HubDb->GroupList);\r
+                               }\r
+\r
+                               e->LastCommTime = h->LastCommTime;\r
+                               e->LastLoginTime = h->LastLoginTime;\r
+                               e->NumLogin = h->NumLogin;\r
+                               e->CreatedTime = h->CreatedTime;\r
+                       }\r
+\r
+                       Unlock(h->lock);\r
+               }\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               UINT i, j, k;\r
+               LockList(s->FarmMemberList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                       {\r
+                               FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+\r
+                               LockList(f->HubList);\r
+                               {\r
+                                       if (f->Me == false)\r
+                                       {\r
+                                               for (j = 0;j < LIST_NUM(f->HubList);j++)\r
+                                               {\r
+                                                       HUB_LIST *o = LIST_DATA(f->HubList, j);\r
+\r
+                                                       for (k = 0;k < t->NumHub;k++)\r
+                                                       {\r
+                                                               RPC_ENUM_HUB_ITEM *e = &t->Hubs[k];\r
+\r
+                                                               if (StrCmpi(e->HubName, o->Name) == 0)\r
+                                                               {\r
+                                                                       e->NumIpTables += o->NumIpTables;\r
+                                                                       e->NumMacTables += o->NumMacTables;\r
+                                                                       e->NumSessions += o->NumSessions;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                               UnlockList(f->HubList);\r
+                       }\r
+               }\r
+               UnlockList(s->FarmMemberList);\r
+       }\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// HUB 設定を取得する\r
+UINT StGetHub(ADMIN *a, RPC_CREATE_HUB *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT ret = ERR_NO_ERROR;\r
+       HUB *h;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       if (IsEmptyStr(t->HubName) || IsSafeStr(t->HubName) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+       CHECK_RIGHT;\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       Zero(t, sizeof(RPC_CREATE_HUB));\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       Lock(h->lock);\r
+       {\r
+               StrCpy(t->HubName, sizeof(t->HubName), h->Name);\r
+               t->Online = h->Offline ? false : true;\r
+               t->HubOption.MaxSession = h->Option->MaxSession;\r
+               t->HubOption.NoEnum = h->Option->NoEnum;\r
+               t->HubType = h->Type;\r
+       }\r
+       Unlock(h->lock);\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// HUB 設定を更新する\r
+UINT StSetHub(ADMIN *a, RPC_CREATE_HUB *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       if (IsEmptyStr(t->HubName) || IsSafeStr(t->HubName) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       CHECK_RIGHT;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       if (s->ServerType == SERVER_TYPE_STANDALONE)\r
+       {\r
+               if (t->HubType != HUB_TYPE_STANDALONE)\r
+               {\r
+                       return ERR_INVALID_PARAMETER;\r
+               }\r
+       }\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               if (t->HubType == HUB_TYPE_STANDALONE)\r
+               {\r
+                       return ERR_INVALID_PARAMETER;\r
+               }\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               h = GetHub(c, t->HubName);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return ERR_HUB_NOT_FOUND;\r
+       }\r
+\r
+       if (h->Type != t->HubType)\r
+       {\r
+               ReleaseHub(h);\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       if (IsZero(t->HashedPassword, sizeof(t->HashedPassword)) == false &&\r
+               IsZero(t->SecurePassword, sizeof(t->SecurePassword)) == false)\r
+       {\r
+               if (a->ServerAdmin == false && GetHubAdminOption(h, "no_change_admin_password") != 0)\r
+               {\r
+                       ReleaseHub(h);\r
+                       return ERR_NOT_ENOUGH_RIGHT;\r
+               }\r
+       }\r
+\r
+       // 設定しようとしているパスワードが空白かどうか調べる\r
+       {\r
+               UCHAR hash1[SHA1_SIZE], hash2[SHA1_SIZE];\r
+               HashPassword(hash1, ADMINISTRATOR_USERNAME, "");\r
+               Hash(hash2, "", 0, true);\r
+\r
+               if (Cmp(t->HashedPassword, hash2, SHA1_SIZE) == 0 || Cmp(t->SecurePassword, hash1, SHA1_SIZE) == 0)\r
+               {\r
+                       if (a->ServerAdmin == false && a->Rpc->Sock->RemoteIP.addr[0] != 127)\r
+                       {\r
+                               // ローカル以外から仮想 NUB 管理者モードで接続中に\r
+                               // 仮想 HUB のパスワードを空白に設定しようとすると拒否する\r
+                               ReleaseHub(h);\r
+                               return ERR_INVALID_PARAMETER;\r
+                       }\r
+               }\r
+       }\r
+\r
+       Lock(h->lock);\r
+       {\r
+               if (a->ServerAdmin == false && h->Type != t->HubType)\r
+               {\r
+                       ret = ERR_NOT_ENOUGH_RIGHT;\r
+               }\r
+               else\r
+               {\r
+                       h->Type = t->HubType;\r
+                       h->Option->MaxSession = t->HubOption.MaxSession;\r
+                       h->Option->NoEnum = t->HubOption.NoEnum;\r
+                       if (IsZero(t->HashedPassword, sizeof(t->HashedPassword)) == false &&\r
+                               IsZero(t->SecurePassword, sizeof(t->SecurePassword)) == false)\r
+                       {\r
+                               Copy(h->HashedPassword, t->HashedPassword, SHA1_SIZE);\r
+                               Copy(h->SecurePassword, t->SecurePassword, SHA1_SIZE);\r
+                       }\r
+               }\r
+       }\r
+       Unlock(h->lock);\r
+\r
+       if (t->Online)\r
+       {\r
+               if (a->ServerAdmin || GetHubAdminOption(h, "no_online") == 0)\r
+               {\r
+                       SetHubOnline(h);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (a->ServerAdmin || GetHubAdminOption(h, "no_offline") == 0)\r
+               {\r
+                       SetHubOffline(h);\r
+               }\r
+       }\r
+\r
+       if (h->Type == HUB_TYPE_FARM_STATIC)\r
+       {\r
+               EnableSecureNAT(h, false);\r
+       }\r
+\r
+       h->CurrentVersion++;\r
+       SiHubUpdateProc(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       ALog(a, h, "LA_SET_HUB");\r
+\r
+       ReleaseHub(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// HUB を作成する\r
+UINT StCreateHub(ADMIN *a, RPC_CREATE_HUB *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       HUB *h;\r
+       HUB_OPTION o;\r
+       UINT current_hub_num;\r
+       bool b;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       if (IsEmptyStr(t->HubName) || IsSafeStr(t->HubName) == false)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       Trim(t->HubName);\r
+       if (StrLen(t->HubName) == 0)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+       if (StartWith(t->HubName, ".") || EndWith(t->HubName, "."))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       if (s->ServerType == SERVER_TYPE_STANDALONE)\r
+       {\r
+               if (t->HubType != HUB_TYPE_STANDALONE)\r
+               {\r
+                       return ERR_INVALID_PARAMETER;\r
+               }\r
+       }\r
+       else if (t->HubType != HUB_TYPE_FARM_DYNAMIC && t->HubType != HUB_TYPE_FARM_STATIC)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // HUB の作成\r
+       Zero(&o, sizeof(o));\r
+       o.MaxSession = t->HubOption.MaxSession;\r
+       o.NoEnum = t->HubOption.NoEnum;\r
+       o.ManageOnlyPrivateIP = true;\r
+       o.ManageOnlyLocalUnicastIPv6 = true;\r
+       o.NoMacAddressLog = true;\r
+       o.NoIPv6DefaultRouterInRAWhenIPv6 = true;\r
+\r
+       LockList(c->HubList);\r
+       {\r
+               current_hub_num = LIST_NUM(c->HubList);\r
+       }\r
+       UnlockList(c->HubList);\r
+\r
+       if (current_hub_num > GetServerCapsInt(a->Server, "i_max_hubs"))\r
+       {\r
+               return ERR_TOO_MANY_HUBS;\r
+       }\r
+\r
+       LockList(c->HubList);\r
+       {\r
+               b = IsHub(c, t->HubName);\r
+       }\r
+       UnlockList(c->HubList);\r
+\r
+       if (b)\r
+       {\r
+               return ERR_HUB_ALREADY_EXISTS;\r
+       }\r
+\r
+       ALog(a, NULL, "LA_CREATE_HUB", t->HubName);\r
+\r
+       h = NewHub(c, t->HubName, &o);\r
+       Copy(h->HashedPassword, t->HashedPassword, SHA1_SIZE);\r
+       Copy(h->SecurePassword, t->SecurePassword, SHA1_SIZE);\r
+\r
+       h->Type = t->HubType;\r
+\r
+       AddHub(c, h);\r
+\r
+       if (t->Online)\r
+       {\r
+               h->Offline = true;\r
+               SetHubOnline(h);\r
+       }\r
+       else\r
+       {\r
+               h->Offline = false;\r
+               SetHubOffline(h);\r
+       }\r
+\r
+       h->CreatedTime = SystemTime64();\r
+\r
+       ReleaseHub(h);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// 暗号化アルゴリズムを設定する\r
+UINT StSetServerCipher(ADMIN *a, RPC_STR *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+\r
+       if (IsEmptyStr(t->String))\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       StrUpper(t->String);\r
+\r
+       if (CheckCipherListName(t->String) == false)\r
+       {\r
+               return ERR_CIPHER_NOT_SUPPORTED;\r
+       }\r
+       else\r
+       {\r
+               ALog(a, NULL, "LA_SET_SERVER_CIPHER", t->String);\r
+       }\r
+\r
+       Lock(c->lock);\r
+       {\r
+               SetCedarCipherList(c, t->String);\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// 暗号化アルゴリズムを取得する\r
+UINT StGetServerCipher(ADMIN *a, RPC_STR *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+\r
+       FreeRpcStr(t);\r
+       Zero(t, sizeof(RPC_STR));\r
+\r
+       Lock(c->lock);\r
+       {\r
+               t->String = CopyStr(c->CipherList);\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// サーバー証明書を取得する\r
+UINT StGetServerCert(ADMIN *a, RPC_KEY_PAIR *t)\r
+{\r
+       bool admin;\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+\r
+       admin = a->ServerAdmin;\r
+\r
+       FreeRpcKeyPair(t);\r
+       Zero(t, sizeof(RPC_KEY_PAIR));\r
+\r
+       Lock(c->lock);\r
+       {\r
+               t->Cert = CloneX(c->ServerX);\r
+               if (admin)\r
+               {\r
+                       t->Key = CloneK(c->ServerK);\r
+               }\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// サーバー証明書を設定する\r
+UINT StSetServerCert(ADMIN *a, RPC_KEY_PAIR *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       if (t->Cert == NULL || t->Key == NULL)\r
+       {\r
+               return ERR_PROTOCOL_ERROR;\r
+       }\r
+\r
+       if (t->Cert->is_compatible_bit == false)\r
+       {\r
+               return ERR_NOT_RSA_1024;\r
+       }\r
+\r
+       if (CheckXandK(t->Cert, t->Key) == false)\r
+       {\r
+               return ERR_PROTOCOL_ERROR;\r
+       }\r
+\r
+       SetCedarCert(c, t->Cert, t->Key);\r
+\r
+       ALog(a, NULL, "LA_SET_SERVER_CERT");\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// サーバーファームコントローラへの接続状態を取得する\r
+UINT StGetFarmConnectionStatus(ADMIN *a, RPC_FARM_CONNECTION_STATUS *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       FARM_CONTROLLER *fc;\r
+\r
+       if (s->ServerType != SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return ERR_NOT_FARM_MEMBER;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_FARM_CONNECTION_STATUS));\r
+\r
+       fc = s->FarmController;\r
+\r
+       Lock(fc->lock);\r
+       {\r
+               if (fc->Sock != NULL)\r
+               {\r
+                       t->Ip = IPToUINT(&fc->Sock->RemoteIP);\r
+                       t->Port = fc->Sock->RemotePort;\r
+               }\r
+\r
+               t->Online = fc->Online;\r
+               t->LastError = ERR_NO_ERROR;\r
+\r
+               if (t->Online == false)\r
+               {\r
+                       t->LastError = fc->LastError;\r
+               }\r
+               else\r
+               {\r
+                       t->CurrentConnectedTime = fc->CurrentConnectedTime;\r
+               }\r
+\r
+               t->StartedTime = fc->StartedTime;\r
+               t->FirstConnectedTime = fc->FirstConnectedTime;\r
+\r
+               t->NumConnected = fc->NumConnected;\r
+               t->NumTry = fc->NumTry;\r
+               t->NumFailed = fc->NumFailed;\r
+       }\r
+       Unlock(fc->lock);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// サーバーファームメンバ列挙\r
+UINT StEnumFarmMember(ADMIN *a, RPC_ENUM_FARM *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       CEDAR *c = s->Cedar;\r
+       UINT i;\r
+\r
+       FreeRpcEnumFarm(t);\r
+       Zero(t, sizeof(RPC_ENUM_FARM));\r
+\r
+       if (s->ServerType != SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_FARM));\r
+\r
+       LockList(s->FarmMemberList);\r
+       {\r
+               t->NumFarm = LIST_NUM(s->FarmMemberList);\r
+               t->Farms = ZeroMalloc(sizeof(RPC_ENUM_FARM_ITEM) * t->NumFarm);\r
+\r
+               for (i = 0;i < t->NumFarm;i++)\r
+               {\r
+                       FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                       RPC_ENUM_FARM_ITEM *e = &t->Farms[i];\r
+\r
+                       e->Id = POINTER_TO_KEY(f);\r
+                       e->Controller = f->Me;\r
+\r
+                       if (e->Controller)\r
+                       {\r
+                               e->ConnectedTime = TickToTime(c->CreatedTick);\r
+                               e->Ip = 0x0100007f;\r
+                               GetMachineName(e->Hostname, sizeof(e->Hostname));\r
+                               e->Point = f->Point;\r
+                               e->NumSessions = Count(c->CurrentSessions);\r
+                               e->NumTcpConnections = Count(c->CurrentTcpConnections);\r
+\r
+                               e->AssignedBridgeLicense = Count(c->AssignedBridgeLicense);\r
+                               e->AssignedClientLicense = Count(c->AssignedClientLicense);\r
+                       }\r
+                       else\r
+                       {\r
+                               e->ConnectedTime = f->ConnectedTime;\r
+                               e->Ip = f->Ip;\r
+                               StrCpy(e->Hostname, sizeof(e->Hostname), f->hostname);\r
+                               e->Point = f->Point;\r
+                               e->NumSessions = f->NumSessions;\r
+                               e->NumTcpConnections = f->NumTcpConnections;\r
+\r
+                               e->AssignedBridgeLicense = f->AssignedBridgeLicense;\r
+                               e->AssignedClientLicense = f->AssignedClientLicense;\r
+                       }\r
+                       e->NumHubs = LIST_NUM(f->HubList);\r
+               }\r
+       }\r
+       UnlockList(s->FarmMemberList);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// サーバーファームメンバ情報の取得\r
+UINT StGetFarmInfo(ADMIN *a, RPC_FARM_INFO *t)\r
+{\r
+       SERVER *s = a->Server;\r
+       UINT id = t->Id;\r
+       UINT i;\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       FreeRpcFarmInfo(t);\r
+       Zero(t, sizeof(RPC_FARM_INFO));\r
+\r
+       if (s->ServerType != SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               return ERR_NOT_FARM_CONTROLLER;\r
+       }\r
+\r
+       LockList(s->FarmMemberList);\r
+       {\r
+               if (IsInListKey(s->FarmMemberList, id))\r
+               {\r
+                       FARM_MEMBER *f = ListKeyToPointer(s->FarmMemberList, id);\r
+\r
+                       t->Id = id;\r
+                       t->Controller = f->Me;\r
+                       t->Weight = f->Weight;\r
+\r
+                       LockList(f->HubList);\r
+                       {\r
+                               t->NumFarmHub = LIST_NUM(f->HubList);\r
+                               t->FarmHubs = ZeroMalloc(sizeof(RPC_FARM_HUB) * t->NumFarmHub);\r
+\r
+                               for (i = 0;i < t->NumFarmHub;i++)\r
+                               {\r
+                                       RPC_FARM_HUB *h = &t->FarmHubs[i];\r
+                                       HUB_LIST *hh = LIST_DATA(f->HubList, i);\r
+\r
+                                       h->DynamicHub = hh->DynamicHub;\r
+                                       StrCpy(h->HubName, sizeof(h->HubName), hh->Name);\r
+                               }\r
+                       }\r
+                       UnlockList(f->HubList);\r
+\r
+                       if (t->Controller)\r
+                       {\r
+                               t->ConnectedTime = TickToTime(s->Cedar->CreatedTick);\r
+                               t->Ip = 0x0100007f;\r
+                               GetMachineName(t->Hostname, sizeof(t->Hostname));\r
+                               t->Point = f->Point;\r
+\r
+                               LockList(s->ServerListenerList);\r
+                               {\r
+                                       UINT i, n;\r
+                                       t->NumPort = 0;\r
+                                       for (i = 0;i < LIST_NUM(s->ServerListenerList);i++)\r
+                                       {\r
+                                               SERVER_LISTENER *o = LIST_DATA(s->ServerListenerList, i);\r
+                                               if (o->Enabled)\r
+                                               {\r
+                                                       t->NumPort++;\r
+                                               }\r
+                                       }\r
+                                       t->Ports = ZeroMalloc(sizeof(UINT) * t->NumPort);\r
+                                       n = 0;\r
+                                       for (i = 0;i < LIST_NUM(s->ServerListenerList);i++)\r
+                                       {\r
+                                               SERVER_LISTENER *o = LIST_DATA(s->ServerListenerList, i);\r
+                                               if (o->Enabled)\r
+                                               {\r
+                                                       t->Ports[n++] = o->Port;\r
+                                               }\r
+                                       }\r
+                               }\r
+                               UnlockList(s->ServerListenerList);\r
+\r
+                               t->ServerCert = CloneX(s->Cedar->ServerX);\r
+                               t->NumSessions = Count(s->Cedar->CurrentSessions);\r
+                               t->NumTcpConnections = Count(s->Cedar->CurrentTcpConnections);\r
+                       }\r
+                       else\r
+                       {\r
+                               t->ConnectedTime = f->ConnectedTime;\r
+                               t->Ip = f->Ip;\r
+                               StrCpy(t->Hostname, sizeof(t->Hostname), f->hostname);\r
+                               t->Point = f->Point;\r
+                               t->NumPort = f->NumPort;\r
+                               t->Ports = ZeroMalloc(sizeof(UINT) * t->NumPort);\r
+                               Copy(t->Ports, f->Ports, sizeof(UINT) * t->NumPort);\r
+                               t->ServerCert = CloneX(f->ServerCert);\r
+                               t->NumSessions = f->NumSessions;\r
+                               t->NumTcpConnections = f->NumTcpConnections;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+               }\r
+       }\r
+       UnlockList(s->FarmMemberList);\r
+\r
+       return ret;\r
+}\r
+\r
+// サーバーファーム設定の取得\r
+UINT StGetFarmSetting(ADMIN *a, RPC_FARM *t)\r
+{\r
+       SERVER *s;\r
+       FreeRpcFarm(t);\r
+       Zero(t, sizeof(RPC_FARM));\r
+\r
+       s = a->Server;\r
+       t->ServerType = s->ServerType;\r
+       t->ControllerOnly = s->ControllerOnly;\r
+       t->Weight = s->Weight;\r
+\r
+       if (t->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               t->NumPort = s->NumPublicPort;\r
+               t->Ports = ZeroMalloc(sizeof(UINT) * t->NumPort);\r
+               Copy(t->Ports, s->PublicPorts, sizeof(UINT) * t->NumPort);\r
+               t->PublicIp = s->PublicIp;\r
+               StrCpy(t->ControllerName, sizeof(t->ControllerName), s->ControllerName);\r
+               t->ControllerPort = s->ControllerPort;\r
+       }\r
+       else\r
+       {\r
+               t->NumPort = 0;\r
+               t->Ports = ZeroMalloc(0);\r
+       }\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// サーバーファーム設定の設定\r
+UINT StSetFarmSetting(ADMIN *a, RPC_FARM *t)\r
+{\r
+       bool cluster_allowed = false;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+       NO_SUPPORT_FOR_BRIDGE;\r
+\r
+       cluster_allowed = GetServerCapsInt(a->Server, "b_support_cluster");\r
+\r
+       if (t->ServerType != SERVER_TYPE_STANDALONE && cluster_allowed == false)\r
+       {\r
+               // クラスタとして動作が許可されていないのにクラスタ化しようとすると\r
+               // エラーを発生する\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       ALog(a, NULL, "LA_SET_FARM_SETTING");\r
+\r
+       IncrementServerConfigRevision(a->Server);\r
+\r
+       SiSetServerType(a->Server, t->ServerType, t->PublicIp, t->NumPort, t->Ports,\r
+               t->ControllerName, t->ControllerPort, t->MemberPassword, t->Weight, t->ControllerOnly);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// パスワードの設定\r
+UINT StSetServerPassword(ADMIN *a, RPC_SET_PASSWORD *t)\r
+{\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       Copy(a->Server->HashedPassword, t->HashedPassword, SHA1_SIZE);\r
+\r
+       ALog(a, NULL, "LA_SET_SERVER_PASSWORD");\r
+\r
+       IncrementServerConfigRevision(a->Server);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// リスナーの有効化 / 無効化\r
+UINT StEnableListener(ADMIN *a, RPC_LISTENER *t)\r
+{\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       LockList(a->Server->ServerListenerList);\r
+       {\r
+               if (t->Enable)\r
+               {\r
+                       if (SiEnableListener(a->Server, t->Port) == false)\r
+                       {\r
+                               ret = ERR_LISTENER_NOT_FOUND;\r
+                       }\r
+                       else\r
+                       {\r
+                               ALog(a, NULL, "LA_ENABLE_LISTENER", t->Port);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if (SiDisableListener(a->Server, t->Port) == false)\r
+                       {\r
+                               ret = ERR_LISTENER_NOT_FOUND;\r
+                       }\r
+                       else\r
+                       {\r
+                               ALog(a, NULL, "LA_DISABLE_LISTENER", t->Port);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(a->Server->ServerListenerList);\r
+\r
+       IncrementServerConfigRevision(a->Server);\r
+\r
+       SleepThread(250);\r
+\r
+       return ret;\r
+}\r
+\r
+// リスナーの削除\r
+UINT StDeleteListener(ADMIN *a, RPC_LISTENER *t)\r
+{\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       LockList(a->Server->ServerListenerList);\r
+       {\r
+               if (SiDeleteListener(a->Server, t->Port) == false)\r
+               {\r
+                       ret = ERR_LISTENER_NOT_FOUND;\r
+               }\r
+               else\r
+               {\r
+                       ALog(a, NULL, "LA_DELETE_LISTENER", t->Port);\r
+\r
+                       IncrementServerConfigRevision(a->Server);\r
+               }\r
+       }\r
+       UnlockList(a->Server->ServerListenerList);\r
+\r
+       return ret;\r
+}\r
+\r
+// リスナーの列挙\r
+UINT StEnumListener(ADMIN *a, RPC_LISTENER_LIST *t)\r
+{\r
+       CEDAR *c = a->Server->Cedar;\r
+       UINT i;\r
+\r
+       FreeRpcListenerList(t);\r
+       Zero(t, sizeof(RPC_LISTENER_LIST));\r
+\r
+       LockList(a->Server->ServerListenerList);\r
+       {\r
+               t->NumPort = LIST_NUM(a->Server->ServerListenerList);\r
+               t->Ports = ZeroMalloc(sizeof(UINT) * t->NumPort);\r
+               t->Enables = ZeroMalloc(sizeof(bool) * t->NumPort);\r
+               t->Errors = ZeroMalloc(sizeof(bool) * t->NumPort);\r
+\r
+               for (i = 0;i < t->NumPort;i++)\r
+               {\r
+                       SERVER_LISTENER *o = LIST_DATA(a->Server->ServerListenerList, i);\r
+\r
+                       t->Ports[i] = o->Port;\r
+                       t->Enables[i] = o->Enabled;\r
+                       if (t->Enables[i])\r
+                       {\r
+                               if (o->Listener->Status == LISTENER_STATUS_TRYING)\r
+                               {\r
+                                       t->Errors[i] = true;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(a->Server->ServerListenerList);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// リスナーの作成\r
+UINT StCreateListener(ADMIN *a, RPC_LISTENER *t)\r
+{\r
+       UINT ret = ERR_NO_ERROR;\r
+       CEDAR *c = a->Server->Cedar;\r
+\r
+       if (t->Port == 0 || t->Port > 65535)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       SERVER_ADMIN_ONLY;\r
+\r
+       LockList(a->Server->ServerListenerList);\r
+       {\r
+               if (SiAddListener(a->Server, t->Port, t->Enable) == false)\r
+               {\r
+                       ret = ERR_LISTENER_ALREADY_EXISTS;\r
+               }\r
+               else\r
+               {\r
+                       ALog(a, NULL, "LA_CREATE_LISTENER", t->Port);\r
+\r
+                       IncrementServerConfigRevision(a->Server);\r
+               }\r
+       }\r
+       UnlockList(a->Server->ServerListenerList);\r
+\r
+       SleepThread(250);\r
+\r
+       return ret;\r
+}\r
+\r
+// サーバー状態の取得\r
+UINT StGetServerStatus(ADMIN *a, RPC_SERVER_STATUS *t)\r
+{\r
+       CEDAR *c;\r
+       UINT i;\r
+\r
+       c = a->Server->Cedar;\r
+\r
+       Zero(t, sizeof(RPC_SERVER_STATUS));\r
+\r
+       Lock(c->TrafficLock);\r
+       {\r
+               Copy(&t->Traffic, c->Traffic, sizeof(TRAFFIC));\r
+       }\r
+       Unlock(c->TrafficLock);\r
+\r
+       GetMemInfo(&t->MemInfo);\r
+\r
+       t->ServerType = a->Server->ServerType;\r
+       t->NumTcpConnections = t->NumTcpConnectionsLocal = t->NumTcpConnectionsRemote = 0;\r
+       t->NumSessionsTotal = t->NumSessionsLocal = t->NumSessionsRemote = 0;\r
+\r
+       t->NumTcpConnectionsLocal = Count(c->CurrentTcpConnections);\r
+\r
+       if (a->Server->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               LockList(a->Server->FarmMemberList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(a->Server->FarmMemberList);i++)\r
+                       {\r
+                               FARM_MEMBER *f = LIST_DATA(a->Server->FarmMemberList, i);\r
+\r
+                               if (f->Me == false)\r
+                               {\r
+                                       t->NumTcpConnectionsRemote += f->NumTcpConnections;\r
+                                       t->NumSessionsRemote += f->NumSessions;\r
+                                       AddTraffic(&t->Traffic, &f->Traffic);\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(a->Server->FarmMemberList);\r
+       }\r
+\r
+       t->NumMacTables = t->NumIpTables = t->NumUsers = t->NumGroups = 0;\r
+\r
+       // HUB 数の情報\r
+       LockList(c->HubList);\r
+       {\r
+               t->NumHubTotal = LIST_NUM(c->HubList);\r
+\r
+               t->NumHubStandalone = t->NumHubDynamic = t->NumHubStatic = 0;\r
+\r
+               for (i = 0;i < LIST_NUM(c->HubList);i++)\r
+               {\r
+                       HUB *h = LIST_DATA(c->HubList, i);\r
+                       Lock(h->lock);\r
+                       {\r
+                               switch (h->Type)\r
+                               {\r
+                               case HUB_TYPE_STANDALONE:\r
+                                       t->NumHubStandalone++;\r
+                                       break;\r
+\r
+                               case HUB_TYPE_FARM_STATIC:\r
+                                       t->NumHubStatic++;\r
+                                       break;\r
+\r
+                               case HUB_TYPE_FARM_DYNAMIC:\r
+                                       t->NumHubDynamic++;\r
+                                       break;\r
+                               }\r
+                       }\r
+\r
+                       t->NumMacTables += LIST_NUM(h->MacTable);\r
+                       t->NumIpTables += LIST_NUM(h->IpTable);\r
+\r
+                       if (h->HubDb != NULL)\r
+                       {\r
+                               t->NumUsers += LIST_NUM(h->HubDb->UserList);\r
+                               t->NumGroups += LIST_NUM(h->HubDb->GroupList);\r
+                       }\r
+\r
+                       Unlock(h->lock);\r
+               }\r
+       }\r
+       UnlockList(c->HubList);\r
+\r
+       // セッション数の情報\r
+       t->NumSessionsLocal = Count(c->CurrentSessions);\r
+       t->NumSessionsTotal = t->NumSessionsLocal + t->NumSessionsRemote;\r
+       t->NumTcpConnections = t->NumTcpConnectionsLocal + t->NumTcpConnectionsRemote;\r
+\r
+       t->AssignedBridgeLicenses = Count(c->AssignedBridgeLicense);\r
+       t->AssignedClientLicenses = Count(c->AssignedClientLicense);\r
+\r
+       t->AssignedBridgeLicensesTotal = a->Server->CurrentAssignedBridgeLicense;\r
+       t->AssignedClientLicensesTotal = a->Server->CurrentAssignedClientLicense;\r
+\r
+       t->CurrentTick = Tick64();\r
+       t->CurrentTime = SystemTime64();\r
+\r
+       t->StartTime = a->Server->StartTime;\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// サーバー情報の取得\r
+UINT StGetServerInfo(ADMIN *a, RPC_SERVER_INFO *t)\r
+{\r
+       CEDAR *c;\r
+       OS_INFO *info;\r
+       // 引数チェック\r
+       if (a == NULL || t == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       FreeRpcServerInfo(t);\r
+       Zero(t, sizeof(RPC_SERVER_INFO));\r
+\r
+       c = a->Server->Cedar;\r
+\r
+       GetServerProductName(a->Server, t->ServerProductName, sizeof(t->ServerProductName));\r
+\r
+       StrCpy(t->ServerVersionString, sizeof(t->ServerVersionString), c->VerString);\r
+       StrCpy(t->ServerBuildInfoString, sizeof(t->ServerBuildInfoString), c->BuildInfo);\r
+       t->ServerVerInt = c->Version;\r
+       t->ServerBuildInt = c->Build;\r
+       GetMachineName(t->ServerHostName, sizeof(t->ServerHostName));\r
+       t->ServerType = c->Server->ServerType;\r
+\r
+       info = GetOsInfo();\r
+       if (info != NULL)\r
+       {\r
+               CopyOsInfo(&t->OsInfo, info);\r
+       }\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// OS_INFO のコピー\r
+void CopyOsInfo(OS_INFO *dst, OS_INFO *info)\r
+{\r
+       // 引数チェック\r
+       if (info == NULL || dst == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       dst->OsType = info->OsType;\r
+       dst->OsServicePack = info->OsServicePack;\r
+       dst->OsSystemName = CopyStr(info->OsSystemName);\r
+       dst->OsProductName = CopyStr(info->OsProductName);\r
+       dst->OsVendorName = CopyStr(info->OsVendorName);\r
+       dst->OsVersion = CopyStr(info->OsVersion);\r
+       dst->KernelName = CopyStr(info->KernelName);\r
+       dst->KernelVersion = CopyStr(info->KernelVersion);\r
+}\r
+\r
+// RPC_WINVER\r
+void InRpcWinVer(RPC_WINVER *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_WINVER));\r
+\r
+       t->IsWindows = PackGetBool(p, "V_IsWindows");\r
+       t->IsNT = PackGetBool(p, "V_IsNT");\r
+       t->IsServer = PackGetBool(p, "V_IsServer");\r
+       t->IsBeta = PackGetBool(p, "V_IsBeta");\r
+       t->VerMajor = PackGetInt(p, "V_VerMajor");\r
+       t->VerMinor = PackGetInt(p, "V_VerMinor");\r
+       t->Build = PackGetInt(p, "V_Build");\r
+       t->ServicePack = PackGetInt(p, "V_ServicePack");\r
+       PackGetStr(p, "V_Title", t->Title, sizeof(t->Title));\r
+}\r
+void OutRpcWinVer(PACK *p, RPC_WINVER *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddBool(p, "V_IsWindows", t->IsWindows);\r
+       PackAddBool(p, "V_IsNT", t->IsNT);\r
+       PackAddBool(p, "V_IsServer", t->IsServer);\r
+       PackAddBool(p, "V_IsBeta", t->IsBeta);\r
+       PackAddInt(p, "V_VerMajor", t->VerMajor);\r
+       PackAddInt(p, "V_VerMinor", t->VerMinor);\r
+       PackAddInt(p, "V_Build", t->Build);\r
+       PackAddInt(p, "V_ServicePack", t->ServicePack);\r
+       PackAddStr(p, "V_Title", t->Title);\r
+}\r
+\r
+// RPC_MSG\r
+void InRpcMsg(RPC_MSG *t, PACK *p)\r
+{\r
+       UINT size;\r
+       char *utf8;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_MSG));\r
+\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       size = PackGetDataSize(p, "Msg");\r
+       utf8 = ZeroMalloc(size + 8);\r
+       PackGetData(p, "Msg", utf8);\r
+       t->Msg = CopyUtfToUni(utf8);\r
+       Free(utf8);\r
+}\r
+void OutRpcMsg(PACK *p, RPC_MSG *t)\r
+{\r
+       UINT size;\r
+       char *utf8;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       utf8 = CopyUniToUtf(t->Msg);\r
+       size = StrLen(utf8);\r
+       PackAddData(p, "Msg", utf8, size);\r
+       Free(utf8);\r
+}\r
+void FreeRpcMsg(RPC_MSG *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Msg);\r
+}\r
+\r
+// RPC_ENUM_ETH_VLAN\r
+void InRpcEnumEthVLan(RPC_ENUM_ETH_VLAN *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_ETH_VLAN));\r
+\r
+       t->NumItem = PackGetIndexCount(p, "DeviceName");\r
+       t->Items = ZeroMalloc(sizeof(RPC_ENUM_ETH_VLAN_ITEM) * t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_ETH_VLAN_ITEM *e = &t->Items[i];\r
+\r
+               PackGetStrEx(p, "DeviceName", e->DeviceName, sizeof(e->DeviceName), i);\r
+               PackGetStrEx(p, "Guid", e->Guid, sizeof(e->Guid), i);\r
+               PackGetStrEx(p, "DeviceInstanceId", e->DeviceInstanceId, sizeof(e->DeviceInstanceId), i);\r
+               PackGetStrEx(p, "DriverName", e->DriverName, sizeof(e->DriverName), i);\r
+               PackGetStrEx(p, "DriverType", e->DriverType, sizeof(e->DriverType), i);\r
+               e->Support = PackGetBoolEx(p, "Support", i);\r
+               e->Enabled = PackGetBoolEx(p, "Enabled", i);\r
+       }\r
+}\r
+void OutRpcEnumEthVLan(PACK *p, RPC_ENUM_ETH_VLAN *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_ETH_VLAN_ITEM *e = &t->Items[i];\r
+\r
+               PackAddStrEx(p, "DeviceName", e->DeviceName, i, t->NumItem);\r
+               PackAddStrEx(p, "Guid", e->Guid, i, t->NumItem);\r
+               PackAddStrEx(p, "DeviceInstanceId", e->DeviceInstanceId, i, t->NumItem);\r
+               PackAddStrEx(p, "DriverName", e->DriverName, i, t->NumItem);\r
+               PackAddStrEx(p, "DriverType", e->DriverType, i, t->NumItem);\r
+               PackAddBoolEx(p, "Support", e->Support, i, t->NumItem);\r
+               PackAddBoolEx(p, "Enabled", e->Enabled, i, t->NumItem);\r
+       }\r
+}\r
+void FreeRpcEnumEthVLan(RPC_ENUM_ETH_VLAN *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Items);\r
+}\r
+\r
+// RPC_ENUM_LOG_FILE\r
+void InRpcEnumLogFile(RPC_ENUM_LOG_FILE *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_LOG_FILE));\r
+       t->NumItem = PackGetInt(p, "NumItem");\r
+       t->Items = ZeroMalloc(sizeof(RPC_ENUM_LOG_FILE_ITEM) * t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_LOG_FILE_ITEM *e = &t->Items[i];\r
+\r
+               PackGetStrEx(p, "FilePath", e->FilePath, sizeof(e->FilePath), i);\r
+               PackGetStrEx(p, "ServerName", e->ServerName, sizeof(e->ServerName), i);\r
+               e->FileSize = PackGetIntEx(p, "FileSize", i);\r
+               e->UpdatedTime = PackGetInt64Ex(p, "UpdatedTime", i);\r
+       }\r
+}\r
+void OutRpcEnumLogFile(PACK *p, RPC_ENUM_LOG_FILE *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "NumItem", t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_LOG_FILE_ITEM *e = &t->Items[i];\r
+\r
+               PackAddStrEx(p, "FilePath", e->FilePath, i, t->NumItem);\r
+               PackAddStrEx(p, "ServerName", e->ServerName, i, t->NumItem);\r
+               PackAddIntEx(p, "FileSize", e->FileSize, i, t->NumItem);\r
+               PackAddInt64Ex(p, "UpdatedTime", e->UpdatedTime, i, t->NumItem);\r
+       }\r
+}\r
+void FreeRpcEnumLogFile(RPC_ENUM_LOG_FILE *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Items);\r
+}\r
+void AdjoinRpcEnumLogFile(RPC_ENUM_LOG_FILE *t, RPC_ENUM_LOG_FILE *src)\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o = NewListFast(CmpLogFile);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_LOG_FILE_ITEM *e = &t->Items[i];\r
+               LOG_FILE *f = ZeroMalloc(sizeof(LOG_FILE));\r
+\r
+               f->FileSize = e->FileSize;\r
+               StrCpy(f->Path, sizeof(f->Path), e->FilePath);\r
+               StrCpy(f->ServerName, sizeof(f->ServerName), e->ServerName);\r
+               f->UpdatedTime = e->UpdatedTime;\r
+\r
+               Add(o, f);\r
+       }\r
+\r
+       for (i = 0;i < src->NumItem;i++)\r
+       {\r
+               RPC_ENUM_LOG_FILE_ITEM *e = &src->Items[i];\r
+               LOG_FILE *f = ZeroMalloc(sizeof(LOG_FILE));\r
+\r
+               f->FileSize = e->FileSize;\r
+               StrCpy(f->Path, sizeof(f->Path), e->FilePath);\r
+               StrCpy(f->ServerName, sizeof(f->ServerName), e->ServerName);\r
+               f->UpdatedTime = e->UpdatedTime;\r
+\r
+               Add(o, f);\r
+       }\r
+\r
+       FreeRpcEnumLogFile(t);\r
+\r
+       Sort(o);\r
+\r
+       Zero(t, sizeof(RPC_ENUM_LOG_FILE));\r
+       t->NumItem = LIST_NUM(o);\r
+       t->Items = ZeroMalloc(sizeof(RPC_ENUM_LOG_FILE_ITEM) * t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               LOG_FILE *f = LIST_DATA(o, i);\r
+               RPC_ENUM_LOG_FILE_ITEM *e = &t->Items[i];\r
+\r
+               StrCpy(e->FilePath, sizeof(e->FilePath), f->Path);\r
+               StrCpy(e->ServerName, sizeof(e->ServerName), f->ServerName);\r
+               e->FileSize = f->FileSize;\r
+               e->UpdatedTime = f->UpdatedTime;\r
+       }\r
+\r
+       FreeEnumLogFile(o);\r
+}\r
+\r
+// RPC_READ_LOG_FILE\r
+void InRpcReadLogFile(RPC_READ_LOG_FILE *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_READ_LOG_FILE));\r
+       PackGetStr(p, "FilePath", t->FilePath, sizeof(t->FilePath));\r
+       PackGetStr(p, "ServerName", t->ServerName, sizeof(t->ServerName));\r
+       t->Offset = PackGetInt(p, "Offset");\r
+\r
+       t->Buffer = PackGetBuf(p, "Buffer");\r
+}\r
+void OutRpcReadLogFile(PACK *p, RPC_READ_LOG_FILE *t)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "FilePath", t->FilePath);\r
+       PackAddStr(p, "ServerName", t->ServerName);\r
+       PackAddInt(p, "Offset", t->Offset);\r
+\r
+       if (t->Buffer != NULL)\r
+       {\r
+               PackAddBuf(p, "Buffer", t->Buffer);\r
+       }\r
+}\r
+void FreeRpcReadLogFile(RPC_READ_LOG_FILE *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (t->Buffer != NULL)\r
+       {\r
+               FreeBuf(t->Buffer);\r
+       }\r
+}\r
+\r
+// RPC_AC_LIST\r
+void InRpcAcList(RPC_AC_LIST *t, PACK *p)\r
+{\r
+       UINT i;\r
+       LIST *o;\r
+       UINT num;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_AC_LIST));\r
+       o = NewAcList();\r
+\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       num = PackGetInt(p, "NumItem");\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               AC *ac = ZeroMalloc(sizeof(AC));\r
+\r
+               ac->Deny = PackGetBoolEx(p, "Deny", i);\r
+               PackGetIpEx(p, "IpAddress", &ac->IpAddress, i);\r
+               ac->Masked = PackGetBoolEx(p, "Masked", i);\r
+\r
+               if (ac->Masked)\r
+               {\r
+                       PackGetIpEx(p, "SubnetMask", &ac->SubnetMask, i);\r
+               }\r
+\r
+               PackGetIntEx(p, "testtest", i);\r
+\r
+               ac->Priority = PackGetIntEx(p, "Priority", i);\r
+\r
+               AddAc(o, ac);\r
+\r
+               Free(ac);\r
+       }\r
+\r
+       t->o = o;\r
+}\r
+void OutRpcAcList(PACK *p, RPC_AC_LIST *t)\r
+{\r
+       UINT i, num;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o = t->o;\r
+       num = LIST_NUM(o);\r
+\r
+       PackAddInt(p, "NumItem", num);\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               AC *ac = LIST_DATA(o, i);\r
+\r
+               PackAddBoolEx(p, "Deny", ac->Deny, i, num);\r
+               PackAddIpEx(p, "IpAddress", &ac->IpAddress, i, num);\r
+               PackAddBoolEx(p, "Masked", ac->Masked, i, num);\r
+\r
+               PackAddIpEx(p, "SubnetMask", &ac->SubnetMask, i, num);\r
+\r
+               PackAddIntEx(p, "Priority", ac->Priority, i, num);\r
+       }\r
+}\r
+void FreeRpcAcList(RPC_AC_LIST *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeAcList(t->o);\r
+}\r
+\r
+// RPC_INT\r
+void InRpcInt(RPC_INT *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_INT));\r
+       t->IntValue = PackGetInt(p, "IntValue");\r
+}\r
+void OutRpcInt(PACK *p, RPC_INT *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "IntValue", t->IntValue);\r
+}\r
+\r
+// RPC_ENUM_CRL\r
+void InRpcEnumCrl(RPC_ENUM_CRL *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_CRL));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->NumItem = PackGetInt(p, "NumItem");\r
+\r
+       t->Items = ZeroMalloc(sizeof(RPC_ENUM_CRL_ITEM) * t->NumItem);\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_CRL_ITEM *e = &t->Items[i];\r
+\r
+               e->Key = PackGetIntEx(p, "Key", i);\r
+               PackGetUniStrEx(p, "CrlInfo", e->CrlInfo, sizeof(e->CrlInfo), i);\r
+       }\r
+}\r
+void OutRpcEnumCrl(PACK *p, RPC_ENUM_CRL *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddInt(p, "NumItem", t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_CRL_ITEM *e = &t->Items[i];\r
+\r
+               PackAddIntEx(p, "Key", e->Key, i, t->NumItem);\r
+               PackAddUniStrEx(p, "CrlInfo", e->CrlInfo, i, t->NumItem);\r
+       }\r
+}\r
+void FreeRpcEnumCrl(RPC_ENUM_CRL *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Items);\r
+}\r
+\r
+// RPC_CRL\r
+void InRpcCrl(RPC_CRL *t, PACK *p)\r
+{\r
+       BUF *b;\r
+       NAME *n;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_CRL));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->Key = PackGetInt(p, "Key");\r
+       b = PackGetBuf(p, "Serial");\r
+       t->Crl = ZeroMalloc(sizeof(CRL));\r
+       if (b != NULL)\r
+       {\r
+               t->Crl->Serial = NewXSerial(b->Buf, b->Size);\r
+               FreeBuf(b);\r
+       }\r
+       t->Crl->Name = ZeroMalloc(sizeof(NAME));\r
+       n = t->Crl->Name;\r
+       if (PackGetUniStr(p, "CommonName", tmp, sizeof(tmp)))\r
+       {\r
+               n->CommonName = CopyUniStr(tmp);\r
+       }\r
+       if (PackGetUniStr(p, "Organization", tmp, sizeof(tmp)))\r
+       {\r
+               n->Organization = CopyUniStr(tmp);\r
+       }\r
+       if (PackGetUniStr(p, "Unit", tmp, sizeof(tmp)))\r
+       {\r
+               n->Unit = CopyUniStr(tmp);\r
+       }\r
+       if (PackGetUniStr(p, "Country", tmp, sizeof(tmp)))\r
+       {\r
+               n->Country = CopyUniStr(tmp);\r
+       }\r
+       if (PackGetUniStr(p, "State", tmp, sizeof(tmp)))\r
+       {\r
+               n->State = CopyUniStr(tmp);\r
+       }\r
+       if (PackGetUniStr(p, "Local", tmp, sizeof(tmp)))\r
+       {\r
+               n->Local = CopyUniStr(tmp);\r
+       }\r
+       if (PackGetDataSize(p, "DigestMD5") == MD5_SIZE)\r
+       {\r
+               PackGetData(p, "DigestMD5", t->Crl->DigestMD5);\r
+       }\r
+       if (PackGetDataSize(p, "DigestSHA1") == SHA1_SIZE)\r
+       {\r
+               PackGetData(p, "DigestSHA1", t->Crl->DigestSHA1);\r
+       }\r
+}\r
+void OutRpcCrl(PACK *p, RPC_CRL *t)\r
+{\r
+       NAME *n;\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddInt(p, "Key", t->Key);\r
+\r
+       if (t->Crl == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (t->Crl->Serial != NULL)\r
+       {\r
+               PackAddData(p, "Serial", t->Crl->Serial->data, t->Crl->Serial->size);\r
+       }\r
+       n = t->Crl->Name;\r
+       if (n->CommonName != NULL)\r
+       {\r
+               PackAddUniStr(p, "CommonName", n->CommonName);\r
+       }\r
+       if (n->Organization != NULL)\r
+       {\r
+               PackAddUniStr(p, "Organization", n->Organization);\r
+       }\r
+       if (n->Unit != NULL)\r
+       {\r
+               PackAddUniStr(p, "Unit", n->Unit);\r
+       }\r
+       if (n->Country != NULL)\r
+       {\r
+               PackAddUniStr(p, "Country", n->Country);\r
+       }\r
+       if (n->State != NULL)\r
+       {\r
+               PackAddUniStr(p, "State", n->State);\r
+       }\r
+       if (n->Local != NULL)\r
+       {\r
+               PackAddUniStr(p, "Local", n->Local);\r
+       }\r
+       if (IsZero(t->Crl->DigestMD5, MD5_SIZE) == false)\r
+       {\r
+               PackAddData(p, "DigestMD5", t->Crl->DigestMD5, MD5_SIZE);\r
+       }\r
+       if (IsZero(t->Crl->DigestSHA1, SHA1_SIZE) == false)\r
+       {\r
+               PackAddData(p, "DigestSHA1", t->Crl->DigestSHA1, SHA1_SIZE);\r
+       }\r
+}\r
+void FreeRpcCrl(RPC_CRL *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeCrl(t->Crl);\r
+}\r
+\r
+// RPC_ENUM_L3TABLE\r
+void InRpcEnumL3Table(RPC_ENUM_L3TABLE *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_L3TABLE));\r
+       t->NumItem = PackGetInt(p, "NumItem");\r
+       PackGetStr(p, "Name", t->Name, sizeof(t->Name));\r
+       t->Items = ZeroMalloc(sizeof(RPC_L3TABLE) * t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_L3TABLE *e = &t->Items[i];\r
+\r
+               e->NetworkAddress = PackGetIp32Ex(p, "NetworkAddress", i);\r
+               e->SubnetMask = PackGetIp32Ex(p, "SubnetMask", i);\r
+               e->GatewayAddress = PackGetIp32Ex(p, "GatewayAddress", i);\r
+               e->Metric = PackGetIntEx(p, "Metric", i);\r
+       }\r
+}\r
+void OutRpcEnumL3Table(PACK *p, RPC_ENUM_L3TABLE *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "NumItem", t->NumItem);\r
+       PackAddStr(p, "Name", t->Name);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_L3TABLE *e = &t->Items[i];\r
+\r
+               PackAddIp32Ex(p, "NetworkAddress", e->NetworkAddress, i, t->NumItem);\r
+               PackAddIp32Ex(p, "SubnetMask", e->SubnetMask, i, t->NumItem);\r
+               PackAddIp32Ex(p, "GatewayAddress", e->GatewayAddress, i, t->NumItem);\r
+               PackAddIntEx(p, "Metric", e->Metric, i, t->NumItem);\r
+       }\r
+}\r
+void FreeRpcEnumL3Table(RPC_ENUM_L3TABLE *t)\r
+{\r
+       Free(t->Items);\r
+}\r
+\r
+// RPC_L3TABLE\r
+void InRpcL3Table(RPC_L3TABLE *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_L3TABLE));\r
+       PackGetStr(p, "Name", t->Name, sizeof(t->Name));\r
+       t->NetworkAddress = PackGetIp32(p, "NetworkAddress");\r
+       t->SubnetMask = PackGetIp32(p, "SubnetMask");\r
+       t->GatewayAddress = PackGetIp32(p, "GatewayAddress");\r
+       t->Metric = PackGetInt(p, "Metric");\r
+}\r
+void OutRpcL3Table(PACK *p, RPC_L3TABLE *t)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "Name", t->Name);\r
+       PackAddIp32(p, "NetworkAddress", t->NetworkAddress);\r
+       PackAddIp32(p, "SubnetMask", t->SubnetMask);\r
+       PackAddIp32(p, "GatewayAddress", t->GatewayAddress);\r
+       PackAddInt(p, "Metric", t->Metric);\r
+}\r
+\r
+// RPC_ENUM_L3IF\r
+void InRpcEnumL3If(RPC_ENUM_L3IF *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_L3IF));\r
+       t->NumItem = PackGetInt(p, "NumItem");\r
+       PackGetStr(p, "Name", t->Name, sizeof(t->Name));\r
+       t->Items = ZeroMalloc(sizeof(RPC_L3IF) * t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_L3IF *f = &t->Items[i];\r
+\r
+               PackGetStrEx(p, "HubName", f->HubName, sizeof(f->HubName), i);\r
+               f->IpAddress = PackGetIp32Ex(p, "IpAddress", i);\r
+               f->SubnetMask = PackGetIp32Ex(p, "SubnetMask", i);\r
+       }\r
+}\r
+void OutRpcEnumL3If(PACK *p, RPC_ENUM_L3IF *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "NumItem", t->NumItem);\r
+       PackAddStr(p, "Name", t->Name);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_L3IF *f = &t->Items[i];\r
+\r
+               PackAddStrEx(p, "HubName", f->HubName, i, t->NumItem);\r
+               PackAddIp32Ex(p, "IpAddress", f->IpAddress, i, t->NumItem);\r
+               PackAddIp32Ex(p, "SubnetMask", f->SubnetMask, i, t->NumItem);\r
+       }\r
+}\r
+void FreeRpcEnumL3If(RPC_ENUM_L3IF *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Items);\r
+}\r
+\r
+// RPC_L3IF\r
+void InRpcL3If(RPC_L3IF *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_L3IF));\r
+       PackGetStr(p, "Name", t->Name, sizeof(t->Name));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->IpAddress = PackGetIp32(p, "IpAddress");\r
+       t->SubnetMask = PackGetIp32(p, "SubnetMask");\r
+}\r
+void OutRpcL3If(PACK *p, RPC_L3IF *t)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "Name", t->Name);\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddIp32(p, "IpAddress", t->IpAddress);\r
+       PackAddIp32(p, "SubnetMask", t->SubnetMask);\r
+}\r
+\r
+// RPC_L3SW\r
+void InRpcL3Sw(RPC_L3SW *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_L3SW));\r
+       PackGetStr(p, "Name", t->Name, sizeof(t->Name));\r
+}\r
+void OutRpcL3Sw(PACK *p, RPC_L3SW *t)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "Name", t->Name);\r
+}\r
+\r
+// RPC_ENUM_L3SW\r
+void InRpcEnumL3Sw(RPC_ENUM_L3SW *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_L3SW));\r
+       t->NumItem = PackGetInt(p, "NumItem");\r
+       t->Items = ZeroMalloc(sizeof(RPC_ENUM_L3SW_ITEM) * t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_L3SW_ITEM *s = &t->Items[i];\r
+\r
+               PackGetStrEx(p, "Name", s->Name, sizeof(s->Name), i);\r
+               s->NumInterfaces = PackGetIntEx(p, "NumInterfaces", i);\r
+               s->NumTables = PackGetIntEx(p, "NumTables", i);\r
+               s->Active = PackGetBoolEx(p, "Active", i);\r
+               s->Online = PackGetBoolEx(p, "Online", i);\r
+       }\r
+}\r
+void OutRpcEnumL3Sw(PACK *p, RPC_ENUM_L3SW *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "NumItem", t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_L3SW_ITEM *s = &t->Items[i];\r
+\r
+               PackAddStrEx(p, "Name", s->Name, i, t->NumItem);\r
+               PackAddIntEx(p, "NumInterfaces", s->NumInterfaces, i, t->NumItem);\r
+               PackAddIntEx(p, "NumTables", s->NumTables, i, t->NumItem);\r
+               PackAddBoolEx(p, "Active", s->Active, i, t->NumItem);\r
+               PackAddBoolEx(p, "Online", s->Online, i, t->NumItem);\r
+       }\r
+}\r
+void FreeRpcEnumL3Sw(RPC_ENUM_L3SW *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Items);\r
+}\r
+\r
+// RPC_ENUM_ETH\r
+void InRpcEnumEth(RPC_ENUM_ETH *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_ETH));\r
+       t->NumItem = PackGetInt(p, "NumItem");\r
+       t->Items = ZeroMalloc(sizeof(RPC_ENUM_ETH_ITEM) * t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_ETH_ITEM *e = &t->Items[i];\r
+               PackGetStrEx(p, "DeviceName", e->DeviceName, sizeof(e->DeviceName), i);\r
+               PackGetUniStrEx(p, "NetworkConnectionName", e->NetworkConnectionName, sizeof(e->NetworkConnectionName), i);\r
+       }\r
+}\r
+void OutRpcEnumEth(PACK *p, RPC_ENUM_ETH *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "NumItem", t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_ETH_ITEM *e = &t->Items[i];\r
+               PackAddStrEx(p, "DeviceName", e->DeviceName, i, t->NumItem);\r
+               PackAddUniStrEx(p, "NetworkConnectionName", e->NetworkConnectionName, i, t->NumItem);\r
+       }\r
+}\r
+void FreeRpcEnumEth(RPC_ENUM_ETH *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Items);\r
+}\r
+\r
+// RPC_LOCALBRIDGE\r
+void InRpcLocalBridge(RPC_LOCALBRIDGE *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_LOCALBRIDGE));\r
+       PackGetStr(p, "DeviceName", t->DeviceName, sizeof(t->DeviceName));\r
+       PackGetStr(p, "HubNameLB", t->HubName, sizeof(t->HubName));\r
+       t->TapMode = PackGetBool(p, "TapMode");\r
+}\r
+void OutRpcLocalBridge(PACK *p, RPC_LOCALBRIDGE *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "DeviceName", t->DeviceName);\r
+       PackAddStr(p, "HubNameLB", t->HubName);\r
+       PackAddBool(p, "TapMode", t->TapMode);\r
+}\r
+\r
+// RPC_ENUM_LOCALBRIDGE\r
+void InRpcEnumLocalBridge(RPC_ENUM_LOCALBRIDGE *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_LOCALBRIDGE));\r
+       t->NumItem = PackGetInt(p, "NumItem");\r
+       t->Items = ZeroMalloc(sizeof(RPC_LOCALBRIDGE) * t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_LOCALBRIDGE *e = &t->Items[i];\r
+\r
+               PackGetStrEx(p, "DeviceName", e->DeviceName, sizeof(e->DeviceName), i);\r
+               PackGetStrEx(p, "HubNameLB", e->HubName, sizeof(e->HubName), i);\r
+               e->Online = PackGetBoolEx(p, "Online", i);\r
+               e->Active = PackGetBoolEx(p, "Active", i);\r
+               e->TapMode = PackGetBoolEx(p, "TapMode", i);\r
+       }\r
+}\r
+void OutRpcEnumLocalBridge(PACK *p, RPC_ENUM_LOCALBRIDGE *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "NumItem", t->NumItem);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_LOCALBRIDGE *e = &t->Items[i];\r
+\r
+               PackAddStrEx(p, "DeviceName", e->DeviceName, i, t->NumItem);\r
+               PackAddStrEx(p, "HubNameLB", e->HubName, i, t->NumItem);\r
+               PackAddBoolEx(p, "Online", e->Online, i, t->NumItem);\r
+               PackAddBoolEx(p, "Active", e->Active, i, t->NumItem);\r
+               PackAddBoolEx(p, "TapMode", e->TapMode, i, t->NumItem);\r
+       }\r
+}\r
+void FreeRpcEnumLocalBridge(RPC_ENUM_LOCALBRIDGE *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+       Free(t->Items);\r
+}\r
+\r
+// MEMINFO\r
+void InRpcMemInfo(MEMINFO *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(MEMINFO));\r
+       t->TotalMemory = PackGetInt64(p, "TotalMemory");\r
+       t->UsedMemory = PackGetInt64(p, "UsedMemory");\r
+       t->FreeMemory = PackGetInt64(p, "FreeMemory");\r
+       t->TotalPhys = PackGetInt64(p, "TotalPhys");\r
+       t->UsedPhys = PackGetInt64(p, "UsedPhys");\r
+       t->FreePhys = PackGetInt64(p, "FreePhys");\r
+}\r
+void OutRpcMemInfo(PACK *p, MEMINFO *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt64(p, "TotalMemory", t->TotalMemory);\r
+       PackAddInt64(p, "UsedMemory", t->UsedMemory);\r
+       PackAddInt64(p, "FreeMemory", t->FreeMemory);\r
+       PackAddInt64(p, "TotalPhys", t->TotalPhys);\r
+       PackAddInt64(p, "UsedPhys", t->UsedPhys);\r
+       PackAddInt64(p, "FreePhys", t->FreePhys);\r
+}\r
+\r
+// OS_INFO\r
+void InRpcOsInfo(OS_INFO *t, PACK *p)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(OS_INFO));\r
+       t->OsType = PackGetInt(p, "OsType");\r
+       t->OsServicePack = PackGetInt(p, "OsServicePack");\r
+       if (PackGetStr(p, "OsSystemName", tmp, sizeof(tmp)))\r
+       {\r
+               t->OsSystemName = CopyStr(tmp);\r
+       }\r
+       if (PackGetStr(p, "OsProductName", tmp, sizeof(tmp)))\r
+       {\r
+               t->OsProductName = CopyStr(tmp);\r
+       }\r
+       if (PackGetStr(p, "OsVendorName", tmp, sizeof(tmp)))\r
+       {\r
+               t->OsVendorName = CopyStr(tmp);\r
+       }\r
+       if (PackGetStr(p, "OsVersion", tmp, sizeof(tmp)))\r
+       {\r
+               t->OsVersion = CopyStr(tmp);\r
+       }\r
+       if (PackGetStr(p, "KernelName", tmp, sizeof(tmp)))\r
+       {\r
+               t->KernelName = CopyStr(tmp);\r
+       }\r
+       if (PackGetStr(p, "KernelVersion", tmp, sizeof(tmp)))\r
+       {\r
+               t->KernelVersion = CopyStr(tmp);\r
+       }\r
+}\r
+void OutRpcOsInfo(PACK *p, OS_INFO *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "OsType", t->OsType);\r
+       PackAddInt(p, "OsServicePack", t->OsServicePack);\r
+       PackAddStr(p, "OsSystemName", t->OsSystemName);\r
+       PackAddStr(p, "OsProductName", t->OsProductName);\r
+       PackAddStr(p, "OsVendorName", t->OsVendorName);\r
+       PackAddStr(p, "OsVersion", t->OsVersion);\r
+       PackAddStr(p, "KernelName", t->KernelName);\r
+       PackAddStr(p, "KernelVersion", t->KernelVersion);\r
+}\r
+void FreeRpcOsInfo(OS_INFO *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->OsSystemName);\r
+       Free(t->OsProductName);\r
+       Free(t->OsVendorName);\r
+       Free(t->OsVersion);\r
+       Free(t->KernelName);\r
+       Free(t->KernelVersion);\r
+}\r
+\r
+// ローカルのログファイルを読み込む\r
+void SiReadLocalLogFile(SERVER *s, char *filepath, UINT offset, RPC_READ_LOG_FILE *t)\r
+{\r
+       char exe_dir[MAX_PATH], full_path[MAX_PATH];\r
+       IO *o;\r
+       // 引数チェック\r
+       if (s == NULL || t == NULL || filepath == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_READ_LOG_FILE));\r
+\r
+       GetExeDir(exe_dir, sizeof(exe_dir));\r
+       Format(full_path, sizeof(full_path), "%s/%s", exe_dir, filepath);\r
+\r
+       // ファイルを読み込む\r
+       o = FileOpenEx(full_path, false, false);\r
+       if (o != NULL)\r
+       {\r
+               UINT filesize = FileSize(o);\r
+\r
+               if (offset < filesize)\r
+               {\r
+                       UINT readsize = MIN(filesize - offset, FTP_BLOCK_SIZE);\r
+                       void *buf = ZeroMalloc(readsize);\r
+\r
+                       FileSeek(o, FILE_BEGIN, offset);\r
+                       FileRead(o, buf, readsize);\r
+\r
+                       t->Buffer = NewBuf();\r
+                       WriteBuf(t->Buffer, buf, readsize);\r
+                       Free(buf);\r
+               }\r
+\r
+               FileClose(o);\r
+       }\r
+}\r
+\r
+// ローカルのログファイルを列挙する\r
+void SiEnumLocalLogFileList(SERVER *s, char *hubname, RPC_ENUM_LOG_FILE *t)\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_LOG_FILE));\r
+\r
+       o = EnumLogFile(hubname);\r
+\r
+       t->NumItem = LIST_NUM(o);\r
+       t->Items = ZeroMalloc(sizeof(RPC_ENUM_LOG_FILE_ITEM) * t->NumItem);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               LOG_FILE *f = LIST_DATA(o, i);\r
+               RPC_ENUM_LOG_FILE_ITEM *e = &t->Items[i];\r
+\r
+               StrCpy(e->FilePath, sizeof(e->FilePath), f->Path);\r
+               StrCpy(e->ServerName, sizeof(e->ServerName), f->ServerName);\r
+               e->FileSize = f->FileSize;\r
+               e->UpdatedTime = f->UpdatedTime;\r
+       }\r
+\r
+       FreeEnumLogFile(o);\r
+}\r
+\r
+// ローカルのセッションを列挙する\r
+void SiEnumLocalSession(SERVER *s, char *hubname, RPC_ENUM_SESSION *t)\r
+{\r
+       HUB *h;\r
+       // 引数チェック\r
+       if (s == NULL || hubname == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockHubList(s->Cedar);\r
+       h = GetHub(s->Cedar, hubname);\r
+       UnlockHubList(s->Cedar);\r
+\r
+       if (h == NULL)\r
+       {\r
+               t->NumSession = 0;\r
+               t->Sessions = ZeroMalloc(0);\r
+               return;\r
+       }\r
+\r
+       LockList(h->SessionList);\r
+       {\r
+               UINT i;\r
+               t->NumSession = LIST_NUM(h->SessionList);\r
+               t->Sessions = ZeroMalloc(sizeof(RPC_ENUM_SESSION_ITEM) * t->NumSession);\r
+\r
+               for (i = 0;i < t->NumSession;i++)\r
+               {\r
+                       SESSION *s = LIST_DATA(h->SessionList, i);\r
+                       RPC_ENUM_SESSION_ITEM *e = &t->Sessions[i];\r
+                       Lock(s->lock);\r
+                       {\r
+                               StrCpy(e->Name, sizeof(e->Name), s->Name);\r
+                               StrCpy(e->Username, sizeof(e->Username), s->Username);\r
+                               e->Ip = IPToUINT(&s->Connection->ClientIp);\r
+                               StrCpy(e->Hostname, sizeof(e->Hostname), s->Connection->ClientHostname);\r
+                               e->MaxNumTcp = s->MaxConnection;\r
+                               e->LinkMode = s->LinkModeServer;\r
+                               e->SecureNATMode = s->SecureNATMode;\r
+                               e->BridgeMode = s->BridgeMode;\r
+                               e->Layer3Mode = s->L3SwitchMode;\r
+                               e->VLanId = s->VLanId;\r
+                               LockList(s->Connection->Tcp->TcpSockList);\r
+                               {\r
+                                       e->CurrentNumTcp = s->Connection->Tcp->TcpSockList->num_item;\r
+                               }\r
+                               UnlockList(s->Connection->Tcp->TcpSockList);\r
+                               Lock(s->TrafficLock);\r
+                               {\r
+                                       e->PacketSize = GetTrafficPacketSize(s->Traffic);\r
+                                       e->PacketNum = GetTrafficPacketNum(s->Traffic);\r
+                               }\r
+                               Unlock(s->TrafficLock);\r
+                               e->Client_BridgeMode = s->IsBridgeMode;\r
+                               e->Client_MonitorMode = s->IsMonitorMode;\r
+                               Copy(e->UniqueId, s->NodeInfo.UniqueId, 16);\r
+                       }\r
+                       Unlock(s->lock);\r
+                       GetMachineName(e->RemoteHostname, sizeof(e->RemoteHostname));\r
+               }\r
+       }\r
+       UnlockList(h->SessionList);\r
+\r
+       ReleaseHub(h);\r
+}\r
+\r
+// RPC_ENUM_LICENSE_KEY\r
+void InRpcEnumLicenseKey(RPC_ENUM_LICENSE_KEY *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_LICENSE_KEY));\r
+       t->NumItem = PackGetInt(p, "NumItem");\r
+       t->Items = ZeroMalloc(sizeof(RPC_ENUM_LICENSE_KEY_ITEM) * t->NumItem);\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_LICENSE_KEY_ITEM *e = &t->Items[i];\r
+\r
+               e->Id = PackGetIntEx(p, "Id", i);\r
+               PackGetStrEx(p, "LicenseKey", e->LicenseKey, sizeof(e->LicenseKey), i);\r
+               PackGetStrEx(p, "LicenseId", e->LicenseId, sizeof(e->LicenseId), i);\r
+               PackGetStrEx(p, "LicenseName", e->LicenseName, sizeof(e->LicenseName), i);\r
+               e->Expires = PackGetInt64Ex(p, "Expires", i);\r
+               e->Status = PackGetIntEx(p, "Status", i);\r
+               e->ProductId = PackGetIntEx(p, "ProductId", i);\r
+               e->SystemId = PackGetInt64Ex(p, "SystemId", i);\r
+               e->SerialId = PackGetIntEx(p, "SerialId", i);\r
+       }\r
+}\r
+void OutRpcEnumLicenseKey(PACK *p, RPC_ENUM_LICENSE_KEY *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "NumItem", t->NumItem);\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_LICENSE_KEY_ITEM *e = &t->Items[i];\r
+\r
+               PackAddIntEx(p, "Id", e->Id, i, t->NumItem);\r
+               PackAddStrEx(p, "LicenseKey", e->LicenseKey, i, t->NumItem);\r
+               PackAddStrEx(p, "LicenseId", e->LicenseId, i, t->NumItem);\r
+               PackAddStrEx(p, "LicenseName", e->LicenseName, i, t->NumItem);\r
+               PackAddInt64Ex(p, "Expires", e->Expires, i, t->NumItem);\r
+               PackAddIntEx(p, "Status", e->Status, i, t->NumItem);\r
+               PackAddIntEx(p, "ProductId", e->ProductId, i, t->NumItem);\r
+               PackAddInt64Ex(p, "SystemId", e->SystemId, i, t->NumItem);\r
+               PackAddIntEx(p, "SerialId", e->SerialId, i, t->NumItem);\r
+       }\r
+}\r
+void FreeRpcEnumLicenseKey(RPC_ENUM_LICENSE_KEY *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Items);\r
+}\r
+\r
+// RPC_LICENSE_STATUS\r
+void InRpcLicenseStatus(RPC_LICENSE_STATUS *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_LICENSE_STATUS));\r
+\r
+       t->EditionId = PackGetInt(p, "EditionId");\r
+       PackGetStr(p, "EditionStr", t->EditionStr, sizeof(t->EditionStr) );\r
+       t->SystemId = PackGetInt64(p, "SystemId");\r
+       t->SystemExpires = PackGetInt64(p, "SystemExpires");\r
+       t->NumClientConnectLicense = PackGetInt(p, "NumClientConnectLicense");\r
+       t->NumBridgeConnectLicense = PackGetInt(p, "NumBridgeConnectLicense");\r
+\r
+       // v3.0\r
+       t->NeedSubscription = PackGetBool(p, "NeedSubscription");\r
+       t->AllowEnterpriseFunction = PackGetBool(p, "AllowEnterpriseFunction");\r
+       t->SubscriptionExpires = PackGetInt64(p, "SubscriptionExpires");\r
+       t->IsSubscriptionExpired = PackGetBool(p, "IsSubscriptionExpired");\r
+       t->NumUserCreationLicense = PackGetInt(p, "NumUserCreationLicense");\r
+       t->ReleaseDate = PackGetInt64(p, "ReleaseDate");\r
+}\r
+void OutRpcLicenseStatus(PACK *p, RPC_LICENSE_STATUS *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "EditionId", t->EditionId);\r
+       PackAddStr(p, "EditionStr", t->EditionStr);\r
+       PackAddInt64(p, "SystemId", t->SystemId);\r
+       PackAddInt64(p, "SystemExpires", t->SystemExpires);\r
+       PackAddInt(p, "NumClientConnectLicense", t->NumClientConnectLicense);\r
+       PackAddInt(p, "NumBridgeConnectLicense", t->NumBridgeConnectLicense);\r
+\r
+       // v3.0\r
+       PackAddBool(p, "NeedSubscription", t->NeedSubscription);\r
+       PackAddBool(p, "AllowEnterpriseFunction", t->AllowEnterpriseFunction);\r
+       PackAddInt64(p, "SubscriptionExpires", t->SubscriptionExpires);\r
+       PackAddBool(p, "IsSubscriptionExpired", t->IsSubscriptionExpired);\r
+       PackAddInt(p, "NumUserCreationLicense", t->NumUserCreationLicense);\r
+       PackAddInt64(p, "ReleaseDate", t->ReleaseDate);\r
+}\r
+\r
+// RPC_ADMIN_OPTION\r
+void InRpcAdminOption(RPC_ADMIN_OPTION *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ADMIN_OPTION));\r
+       t->NumItem = PackGetInt(p, "NumItem");\r
+       t->Items = ZeroMalloc(sizeof(ADMIN_OPTION) * t->NumItem);\r
+\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               ADMIN_OPTION *o = &t->Items[i];\r
+\r
+               PackGetStrEx(p, "Name", o->Name, sizeof(o->Name), i);\r
+               o->Value = PackGetIntEx(p, "Value", i);\r
+       }\r
+}\r
+void OutRpcAdminOption(PACK *p, RPC_ADMIN_OPTION *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "NumItem", t->NumItem);\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               ADMIN_OPTION *o = &t->Items[i];\r
+\r
+               PackAddStrEx(p, "Name", o->Name, i, t->NumItem);\r
+               PackAddIntEx(p, "Value", o->Value, i, t->NumItem);\r
+       }\r
+}\r
+void FreeRpcAdminOption(RPC_ADMIN_OPTION *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Items);\r
+}\r
+\r
+// RPC_CONFIG\r
+void InRpcConfig(RPC_CONFIG *t, PACK *p)\r
+{\r
+       UINT size;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_CONFIG));\r
+       PackGetStr(p, "FileName", t->FileName, sizeof(t->FileName));\r
+       size = PackGetDataSize(p, "FileData");\r
+       t->FileData = ZeroMalloc(size + 1);\r
+       PackGetData(p, "FileData", t->FileData);\r
+}\r
+void OutRpcConfig(PACK *p, RPC_CONFIG *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "FileName", t->FileName);\r
+       PackAddData(p, "FileData", t->FileData, StrLen(t->FileData));\r
+}\r
+void FreeRpcConfig(RPC_CONFIG *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->FileData);\r
+}\r
+\r
+// RPC_BRIDGE_SUPPORT\r
+void InRpcBridgeSupport(RPC_BRIDGE_SUPPORT *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_BRIDGE_SUPPORT));\r
+\r
+       t->IsBridgeSupportedOs = PackGetBool(p, "IsBridgeSupportedOs");\r
+       t->IsWinPcapNeeded = PackGetBool(p, "IsWinPcapNeeded");\r
+}\r
+void OutRpcBridgeSupport(PACK *p, RPC_BRIDGE_SUPPORT *t)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddBool(p, "IsBridgeSupportedOs", t->IsBridgeSupportedOs);\r
+       PackAddBool(p, "IsWinPcapNeeded",t->IsWinPcapNeeded);\r
+}\r
+\r
+// RPC_ADD_ACCESS\r
+void InRpcAddAccess(RPC_ADD_ACCESS *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ADD_ACCESS));\r
+\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       InRpcAccess(&t->Access, p);\r
+}\r
+void OutRpcAddAccess(PACK *p, RPC_ADD_ACCESS *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       OutRpcAccess(p, &t->Access);\r
+}\r
+\r
+// RPC_DELETE_ACCESS\r
+void InRpcDeleteAccess(RPC_DELETE_ACCESS *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_DELETE_ACCESS));\r
+\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->Id = PackGetInt(p, "Id");\r
+}\r
+void OutRpcDeleteAccess(PACK *p, RPC_DELETE_ACCESS *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddInt(p, "Id", t->Id);\r
+}\r
+\r
+\r
+// RPC_SERVER_INFO\r
+void InRpcServerInfo(RPC_SERVER_INFO *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_SERVER_INFO));\r
+\r
+       PackGetStr(p, "ServerProductName", t->ServerProductName, sizeof(t->ServerProductName));\r
+       PackGetStr(p, "ServerVersionString", t->ServerVersionString, sizeof(t->ServerVersionString));\r
+       PackGetStr(p, "ServerBuildInfoString", t->ServerBuildInfoString, sizeof(t->ServerBuildInfoString));\r
+       t->ServerVerInt = PackGetInt(p, "ServerVerInt");\r
+       t->ServerBuildInt = PackGetInt(p, "ServerBuildInt");\r
+       PackGetStr(p, "ServerHostName", t->ServerHostName, sizeof(t->ServerHostName));\r
+       t->ServerType = PackGetInt(p, "ServerType");\r
+       InRpcOsInfo(&t->OsInfo, p);\r
+}\r
+void OutRpcServerInfo(PACK *p, RPC_SERVER_INFO *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "ServerProductName", t->ServerProductName);\r
+       PackAddStr(p, "ServerVersionString", t->ServerVersionString);\r
+       PackAddStr(p, "ServerBuildInfoString", t->ServerBuildInfoString);\r
+       PackAddInt(p, "ServerVerInt", t->ServerVerInt);\r
+       PackAddInt(p, "ServerBuildInt", t->ServerBuildInt);\r
+       PackAddStr(p, "ServerHostName", t->ServerHostName);\r
+       PackAddInt(p, "ServerType", t->ServerType);\r
+       OutRpcOsInfo(p, &t->OsInfo);\r
+}\r
+void FreeRpcServerInfo(RPC_SERVER_INFO *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeRpcOsInfo(&t->OsInfo);\r
+}\r
+\r
+// RPC_SERVER_STATUS\r
+void InRpcServerStatus(RPC_SERVER_STATUS *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_SERVER_STATUS));\r
+       t->ServerType = PackGetInt(p, "ServerType");\r
+       t->NumTcpConnections = PackGetInt(p, "NumTcpConnections");\r
+       t->NumTcpConnectionsLocal = PackGetInt(p, "NumTcpConnectionsLocal");\r
+       t->NumTcpConnectionsRemote = PackGetInt(p, "NumTcpConnectionsRemote");\r
+       t->NumHubTotal = PackGetInt(p, "NumHubTotal");\r
+       t->NumHubStandalone = PackGetInt(p, "NumHubStandalone");\r
+       t->NumHubStatic = PackGetInt(p, "NumHubStatic");\r
+       t->NumHubDynamic = PackGetInt(p, "NumHubDynamic");\r
+       t->NumSessionsTotal = PackGetInt(p, "NumSessionsTotal");\r
+       t->NumSessionsLocal = PackGetInt(p, "NumSessionsLocal");\r
+       t->NumSessionsRemote = PackGetInt(p, "NumSessionsRemote");\r
+       t->NumMacTables = PackGetInt(p, "NumMacTables");\r
+       t->NumIpTables = PackGetInt(p, "NumIpTables");\r
+       t->NumUsers = PackGetInt(p, "NumUsers");\r
+       t->NumGroups = PackGetInt(p, "NumGroups");\r
+       t->CurrentTime = PackGetInt64(p, "CurrentTime");\r
+       t->CurrentTick = PackGetInt64(p, "CurrentTick");\r
+       t->AssignedBridgeLicenses = PackGetInt(p, "AssignedBridgeLicenses");\r
+       t->AssignedClientLicenses = PackGetInt(p, "AssignedClientLicenses");\r
+       t->AssignedBridgeLicensesTotal = PackGetInt(p, "AssignedBridgeLicensesTotal");\r
+       t->AssignedClientLicensesTotal = PackGetInt(p, "AssignedClientLicensesTotal");\r
+       t->StartTime = PackGetInt64(p, "StartTime");\r
+\r
+       InRpcTraffic(&t->Traffic, p);\r
+\r
+       InRpcMemInfo(&t->MemInfo, p);\r
+}\r
+void OutRpcServerStatus(PACK *p, RPC_SERVER_STATUS *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "ServerType", t->ServerType);\r
+       PackAddInt(p, "NumTcpConnections", t->NumTcpConnections);\r
+       PackAddInt(p, "NumHubTotal", t->NumHubTotal);\r
+       PackAddInt(p, "NumHubStandalone", t->NumHubStandalone);\r
+       PackAddInt(p, "NumHubStatic", t->NumHubStatic);\r
+       PackAddInt(p, "NumHubDynamic", t->NumHubDynamic);\r
+       PackAddInt(p, "NumSessionsTotal", t->NumSessionsTotal);\r
+       PackAddInt(p, "NumSessionsLocal", t->NumSessionsLocal);\r
+       PackAddInt(p, "NumSessionsRemote", t->NumSessionsRemote);\r
+       PackAddInt(p, "NumTcpConnections", t->NumTcpConnections);\r
+       PackAddInt(p, "NumTcpConnectionsLocal", t->NumTcpConnectionsLocal);\r
+       PackAddInt(p, "NumTcpConnectionsRemote", t->NumTcpConnectionsRemote);\r
+       PackAddInt(p, "NumMacTables", t->NumMacTables);\r
+       PackAddInt(p, "NumIpTables", t->NumIpTables);\r
+       PackAddInt(p, "NumUsers", t->NumUsers);\r
+       PackAddInt(p, "NumGroups", t->NumGroups);\r
+       PackAddInt64(p, "CurrentTime", t->CurrentTime);\r
+       PackAddInt64(p, "CurrentTick", t->CurrentTick);\r
+       PackAddInt(p, "AssignedBridgeLicenses", t->AssignedBridgeLicenses);\r
+       PackAddInt(p, "AssignedClientLicenses", t->AssignedClientLicenses);\r
+       PackAddInt(p, "AssignedBridgeLicensesTotal", t->AssignedBridgeLicensesTotal);\r
+       PackAddInt(p, "AssignedClientLicensesTotal", t->AssignedClientLicensesTotal);\r
+       PackAddInt64(p, "StartTime", t->StartTime);\r
+\r
+       OutRpcTraffic(p, &t->Traffic);\r
+\r
+       OutRpcMemInfo(p, &t->MemInfo);\r
+}\r
+\r
+// RPC_LISTENER\r
+void InRpcListener(RPC_LISTENER *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_LISTENER));\r
+       t->Port = PackGetInt(p, "Port");\r
+       t->Enable = PackGetBool(p, "Enable");\r
+}\r
+void OutRpcListener(PACK *p, RPC_LISTENER *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "Port", t->Port);\r
+       PackAddBool(p, "Enable", t->Enable);\r
+}\r
+\r
+// RPC_LISTENER_LIST\r
+void InRpcListenerList(RPC_LISTENER_LIST *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_LISTENER_LIST));\r
+       t->NumPort = PackGetIndexCount(p, "Ports");\r
+       t->Ports = ZeroMalloc(sizeof(UINT) * t->NumPort);\r
+       t->Enables = ZeroMalloc(sizeof(UINT) * t->NumPort);\r
+       t->Errors = ZeroMalloc(sizeof(UINT) * t->NumPort);\r
+       for (i = 0;i < t->NumPort;i++)\r
+       {\r
+               t->Ports[i] = PackGetIntEx(p, "Ports", i);\r
+               t->Enables[i] = PackGetBoolEx(p, "Enables", i);\r
+               t->Errors[i] = PackGetBoolEx(p, "Errors", i);\r
+       }\r
+}\r
+void OutRpcListenerList(PACK *p, RPC_LISTENER_LIST *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t->NumPort;i++)\r
+       {\r
+               PackAddIntEx(p, "Ports", t->Ports[i], i, t->NumPort);\r
+               PackAddBoolEx(p, "Enables", t->Enables[i], i, t->NumPort);\r
+               PackAddBoolEx(p, "Errors", t->Errors[i], i, t->NumPort);\r
+       }\r
+}\r
+void FreeRpcListenerList(RPC_LISTENER_LIST *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Ports);\r
+       Free(t->Enables);\r
+       Free(t->Errors);\r
+}\r
+\r
+// RPC_STR\r
+void InRpcStr(RPC_STR *t, PACK *p)\r
+{\r
+       UINT size = 65536;\r
+       char *tmp = Malloc(size);\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_STR));\r
+       if (PackGetStr(p, "String", tmp, size) == false)\r
+       {\r
+               t->String = CopyStr("");\r
+       }\r
+       else\r
+       {\r
+               t->String = CopyStr(tmp);\r
+       }\r
+       Free(tmp);\r
+}\r
+void OutRpcStr(PACK *p, RPC_STR *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "String", t->String);\r
+}\r
+void FreeRpcStr(RPC_STR *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL )\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->String);\r
+}\r
+\r
+// RPC_SET_PASSWORD\r
+void InRpcSetPassword(RPC_SET_PASSWORD *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_SET_PASSWORD));\r
+       PackGetData2(p, "HashedPassword", t->HashedPassword, sizeof(t->HashedPassword));\r
+}\r
+void OutRpcSetPassword(PACK *p, RPC_SET_PASSWORD *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddData(p, "HashedPassword", t->HashedPassword, sizeof(t->HashedPassword));\r
+}\r
+\r
+// RPC_FARM\r
+void InRpcFarm(RPC_FARM *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_FARM));\r
+       t->ServerType = PackGetInt(p, "ServerType");\r
+       t->NumPort = PackGetIndexCount(p, "Ports");\r
+       t->Ports = ZeroMalloc(sizeof(UINT) * t->NumPort);\r
+       for (i = 0;i < t->NumPort;i++)\r
+       {\r
+               t->Ports[i] = PackGetIntEx(p, "Ports", i);\r
+       }\r
+       t->PublicIp = PackGetIp32(p, "PublicIp");\r
+       PackGetStr(p, "ControllerName", t->ControllerName, sizeof(t->ControllerName));\r
+       t->ControllerPort = PackGetInt(p, "ControllerPort");\r
+       PackGetData2(p, "MemberPassword", t->MemberPassword, sizeof(t->MemberPassword));\r
+       t->Weight = PackGetInt(p, "Weight");\r
+       t->ControllerOnly = PackGetBool(p, "ControllerOnly");\r
+}\r
+void OutRpcFarm(PACK *p, RPC_FARM *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "ServerType", t->ServerType);\r
+       for (i = 0;i < t->NumPort;i++)\r
+       {\r
+               PackAddIntEx(p, "Ports", t->Ports[i], i, t->NumPort);\r
+       }\r
+       PackAddIp32(p, "PublicIp", t->PublicIp);\r
+       PackAddStr(p, "ControllerName", t->ControllerName);\r
+       PackAddInt(p, "ControllerPort", t->ControllerPort);\r
+       PackAddData(p, "MemberPassword", t->MemberPassword, sizeof(t->MemberPassword));\r
+       PackAddInt(p, "Weight", t->Weight);\r
+       PackAddBool(p, "ControllerOnly", t->ControllerOnly);\r
+}\r
+void FreeRpcFarm(RPC_FARM *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Ports);\r
+}\r
+\r
+// RPC_FARM_HUB\r
+void InRpcFarmHub(RPC_FARM_HUB *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_FARM_HUB));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->DynamicHub = PackGetBool(p, "DynamicHub");\r
+}\r
+void OutRpcFarmHub(PACK *p, RPC_FARM_HUB *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddBool(p, "DynamicHub", t->DynamicHub);\r
+}\r
+\r
+// RPC_FARM_INFO\r
+void InRpcFarmInfo(RPC_FARM_INFO *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_FARM_INFO));\r
+       t->Id = PackGetInt(p, "Id");\r
+       t->Controller = PackGetBool(p, "Controller");\r
+       t->ConnectedTime = PackGetInt64(p, "ConnectedTime");\r
+       t->Ip = PackGetIp32(p, "Ip");\r
+       PackGetStr(p, "Hostname", t->Hostname, sizeof(t->Hostname));\r
+       t->Point = PackGetInt(p, "Point");\r
+       t->NumPort = PackGetIndexCount(p, "Ports");\r
+       t->Ports = ZeroMalloc(sizeof(UINT) * t->NumPort);\r
+       for (i = 0;i < t->NumPort;i++)\r
+       {\r
+               t->Ports[i] = PackGetIntEx(p, "Ports", i);\r
+       }\r
+       t->ServerCert = PackGetX(p, "ServerCert");\r
+       t->NumFarmHub = PackGetIndexCount(p, "HubName");\r
+       t->FarmHubs = ZeroMalloc(sizeof(RPC_FARM_HUB) * t->NumFarmHub);\r
+       for (i = 0;i < t->NumFarmHub;i++)\r
+       {\r
+               PackGetStrEx(p, "HubName", t->FarmHubs[i].HubName, sizeof(t->FarmHubs[i].HubName), i);\r
+               t->FarmHubs[i].DynamicHub = PackGetBoolEx(p, "DynamicHub", i);\r
+       }\r
+       t->NumSessions = PackGetInt(p, "NumSessions");\r
+       t->NumTcpConnections = PackGetInt(p, "NumTcpConnections");\r
+       t->Weight = PackGetInt(p, "Weight");\r
+}\r
+void OutRpcFarmInfo(PACK *p, RPC_FARM_INFO *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "Id", t->Id);\r
+       PackAddBool(p, "Controller", t->Controller);\r
+       PackAddInt64(p, "ConnectedTime", t->ConnectedTime);\r
+       PackAddIp32(p, "Ip", t->Ip);\r
+       PackAddStr(p, "Hostname", t->Hostname);\r
+       PackAddInt(p, "Point", t->Point);\r
+       for (i = 0;i < t->NumPort;i++)\r
+       {\r
+               PackAddIntEx(p, "Ports", t->Ports[i], i, t->NumPort);\r
+       }\r
+       PackAddX(p, "ServerCert", t->ServerCert);\r
+       for (i = 0;i < t->NumFarmHub;i++)\r
+       {\r
+               PackAddStrEx(p, "HubName", t->FarmHubs[i].HubName, i, t->NumFarmHub);\r
+               PackAddBoolEx(p, "DynamicHub", t->FarmHubs[i].DynamicHub, i, t->NumFarmHub);\r
+       }\r
+       PackAddInt(p, "NumSessions", t->NumSessions);\r
+       PackAddInt(p, "NumTcpConnections", t->NumTcpConnections);\r
+       PackAddInt(p, "Weight", t->Weight);\r
+}\r
+void FreeRpcFarmInfo(RPC_FARM_INFO *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Ports);\r
+       Free(t->FarmHubs);\r
+       FreeX(t->ServerCert);\r
+}\r
+\r
+void InRpcEnumFarm(RPC_ENUM_FARM *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_FARM));\r
+       t->NumFarm = PackGetIndexCount(p, "Id");\r
+       t->Farms = ZeroMalloc(sizeof(RPC_ENUM_FARM_ITEM) * t->NumFarm);\r
+\r
+       for (i = 0;i < t->NumFarm;i++)\r
+       {\r
+               RPC_ENUM_FARM_ITEM *e = &t->Farms[i];\r
+\r
+               e->Id = PackGetIntEx(p, "Id", i);\r
+               e->Controller = PackGetBoolEx(p, "Controller", i);\r
+               e->ConnectedTime = PackGetInt64Ex(p, "ConnectedTime", i);\r
+               e->Ip = PackGetIp32Ex(p, "Ip", i);\r
+               PackGetStrEx(p, "Hostname", e->Hostname, sizeof(e->Hostname), i);\r
+               e->Point = PackGetIntEx(p, "Point", i);\r
+               e->NumSessions = PackGetIntEx(p, "NumSessions", i);\r
+               e->NumTcpConnections = PackGetIntEx(p, "NumTcpConnections", i);\r
+               e->NumHubs = PackGetIntEx(p, "NumHubs", i);\r
+               e->AssignedClientLicense = PackGetIntEx(p, "AssignedClientLicense", i);\r
+               e->AssignedBridgeLicense = PackGetIntEx(p, "AssignedBridgeLicense", i);\r
+       }\r
+}\r
+void OutRpcEnumFarm(PACK *p, RPC_ENUM_FARM *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t->NumFarm;i++)\r
+       {\r
+               RPC_ENUM_FARM_ITEM *e = &t->Farms[i];\r
+\r
+               PackAddIntEx(p, "Id", e->Id, i, t->NumFarm);\r
+               PackAddBoolEx(p, "Controller", e->Controller, i, t->NumFarm);\r
+               PackAddInt64Ex(p, "ConnectedTime", e->ConnectedTime, i, t->NumFarm);\r
+               PackAddIp32Ex(p, "Ip", e->Ip, i, t->NumFarm);\r
+               PackAddStrEx(p, "Hostname", e->Hostname, i, t->NumFarm);\r
+               PackAddIntEx(p, "Point", e->Point, i, t->NumFarm);\r
+               PackAddIntEx(p, "NumSessions", e->NumSessions, i, t->NumFarm);\r
+               PackAddIntEx(p, "NumTcpConnections", e->NumTcpConnections, i, t->NumFarm);\r
+               PackAddIntEx(p, "NumHubs", e->NumHubs, i, t->NumFarm);\r
+               PackAddIntEx(p, "AssignedClientLicense", e->AssignedClientLicense, i, t->NumFarm);\r
+               PackAddIntEx(p, "AssignedBridgeLicense", e->AssignedBridgeLicense, i, t->NumFarm);\r
+       }\r
+}\r
+void FreeRpcEnumFarm(RPC_ENUM_FARM *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Farms);\r
+}\r
+\r
+// RPC_FARM_CONNECTION_STATUS\r
+void InRpcFarmConnectionStatus(RPC_FARM_CONNECTION_STATUS *t, PACK *p)\r
+{\r
+       Zero(t, sizeof(RPC_FARM_CONNECTION_STATUS));\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t->Ip = PackGetIp32(p, "Ip");\r
+       t->Port = PackGetInt(p, "Port");\r
+       t->Online = PackGetBool(p, "Online");\r
+       t->LastError = PackGetInt(p, "LastError");\r
+       t->StartedTime = PackGetInt64(p, "StartedTime");\r
+       t->CurrentConnectedTime = PackGetInt64(p, "CurrentConnectedTime");\r
+       t->FirstConnectedTime = PackGetInt64(p, "FirstConnectedTime");\r
+       t->NumConnected = PackGetInt(p, "NumConnected");\r
+       t->NumTry = PackGetInt(p, "NumTry");\r
+       t->NumFailed = PackGetInt(p, "NumFailed");\r
+}\r
+void OutRpcFarmConnectionStatus(PACK *p, RPC_FARM_CONNECTION_STATUS *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddIp32(p, "Ip", t->Ip);\r
+       PackAddInt(p, "Port", t->Port);\r
+       PackAddBool(p, "Online", t->Online);\r
+       PackAddInt(p, "LastError", t->LastError);\r
+       PackAddInt64(p, "StartedTime", t->StartedTime);\r
+       PackAddInt64(p, "CurrentConnectedTime", t->CurrentConnectedTime);\r
+       PackAddInt64(p, "FirstConnectedTime", t->FirstConnectedTime);\r
+       PackAddInt(p, "NumConnected", t->NumConnected);\r
+       PackAddInt(p, "NumTry", t->NumTry);\r
+       PackAddInt(p, "NumFailed", t->NumFailed);\r
+}\r
+\r
+// RPC_HUB_OPTION\r
+void InRpcHubOption(RPC_HUB_OPTION *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_HUB_OPTION));\r
+       t->MaxSession = PackGetInt(p, "MaxSession");\r
+       t->NoEnum = PackGetBool(p, "NoEnum");\r
+}\r
+void OutRpcHubOption(PACK *p, RPC_HUB_OPTION *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "MaxSession", t->MaxSession);\r
+       PackAddBool(p, "NoEnum", t->NoEnum);\r
+}\r
+\r
+// RPC_RADIUS\r
+void InRpcRadius(RPC_RADIUS *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_RADIUS));\r
+       PackGetStr(p, "RadiusServerName", t->RadiusServerName, sizeof(t->RadiusServerName));\r
+       t->RadiusPort = PackGetInt(p, "RadiusPort");\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       PackGetStr(p, "RadiusSecret", t->RadiusSecret, sizeof(t->RadiusSecret));\r
+       t->RadiusRetryInterval = PackGetInt(p, "RadiusRetryInterval");\r
+}\r
+void OutRpcRadius(PACK *p, RPC_RADIUS *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "RadiusServerName", t->RadiusServerName);\r
+       PackAddInt(p, "RadiusPort", t->RadiusPort);\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddStr(p, "RadiusSecret", t->RadiusSecret);\r
+       PackAddInt(p, "RadiusRetryInterval", t->RadiusRetryInterval);\r
+}\r
+\r
+// RPC_HUB\r
+void InRpcHub(RPC_HUB *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_HUB));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+}\r
+void OutRpcHub(PACK *p, RPC_HUB *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+}\r
+\r
+// RPC_CREATE_HUB\r
+void InRpcCreateHub(RPC_CREATE_HUB *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_CREATE_HUB));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       PackGetData2(p, "HashedPassword", t->HashedPassword, sizeof(t->HashedPassword));\r
+       PackGetData2(p, "SecurePassword", t->SecurePassword, sizeof(t->SecurePassword));\r
+       t->Online = PackGetBool(p, "Online");\r
+       InRpcHubOption(&t->HubOption, p);\r
+       t->HubType = PackGetInt(p, "HubType");\r
+}\r
+void OutRpcCreateHub(PACK *p, RPC_CREATE_HUB *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddData(p, "HashedPassword", t->HashedPassword, sizeof(t->HashedPassword));\r
+       PackAddData(p, "SecurePassword", t->SecurePassword, sizeof(t->SecurePassword));\r
+       PackAddBool(p, "Online", t->Online);\r
+       OutRpcHubOption(p, &t->HubOption);\r
+       PackAddInt(p, "HubType", t->HubType);\r
+}\r
+\r
+// RPC_ENUM_HUB\r
+void InRpcEnumHub(RPC_ENUM_HUB *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_HUB));\r
+       t->NumHub = PackGetIndexCount(p, "HubName");\r
+       t->Hubs = ZeroMalloc(sizeof(RPC_ENUM_HUB_ITEM) * t->NumHub);\r
+\r
+       for (i = 0;i < t->NumHub;i++)\r
+       {\r
+               RPC_ENUM_HUB_ITEM *e = &t->Hubs[i];\r
+\r
+               PackGetStrEx(p, "HubName", e->HubName, sizeof(e->HubName), i);\r
+               e->Online = PackGetBoolEx(p, "Online", i);\r
+               e->HubType = PackGetIntEx(p, "HubType", i);\r
+               e->NumSessions = PackGetIntEx(p, "NumSessions", i);\r
+               e->NumUsers = PackGetIntEx(p, "NumUsers", i);\r
+               e->NumGroups = PackGetIntEx(p, "NumGroups", i);\r
+               e->NumMacTables = PackGetIntEx(p, "NumMacTables", i);\r
+               e->NumIpTables = PackGetIntEx(p, "NumIpTables", i);\r
+               e->LastCommTime = PackGetInt64Ex(p, "LastCommTime", i);\r
+               e->CreatedTime = PackGetInt64Ex(p, "CreatedTime", i);\r
+               e->LastLoginTime = PackGetInt64Ex(p, "LastLoginTime", i);\r
+               e->NumLogin = PackGetIntEx(p, "NumLogin", i);\r
+       }\r
+}\r
+void OutRpcEnumHub(PACK *p, RPC_ENUM_HUB *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t->NumHub;i++)\r
+       {\r
+               RPC_ENUM_HUB_ITEM *e = &t->Hubs[i];\r
+\r
+               PackAddStrEx(p, "HubName", e->HubName, i, t->NumHub);\r
+               PackAddBoolEx(p, "Online", e->Online, i, t->NumHub);\r
+               PackAddIntEx(p, "HubType", e->HubType, i, t->NumHub);\r
+               PackAddIntEx(p, "NumSessions", e->NumSessions, i, t->NumHub);\r
+               PackAddIntEx(p, "NumUsers", e->NumUsers, i, t->NumHub);\r
+               PackAddIntEx(p, "NumGroups", e->NumGroups, i, t->NumHub);\r
+               PackAddIntEx(p, "NumMacTables", e->NumMacTables, i, t->NumHub);\r
+               PackAddIntEx(p, "NumIpTables", e->NumIpTables, i, t->NumHub);\r
+               PackAddInt64Ex(p, "LastCommTime", e->LastCommTime, i, t->NumHub);\r
+               PackAddInt64Ex(p, "CreatedTime", e->CreatedTime, i, t->NumHub);\r
+               PackAddInt64Ex(p, "LastLoginTime", e->LastLoginTime, i, t->NumHub);\r
+               PackAddIntEx(p, "NumLogin", e->NumLogin, i, t->NumHub);\r
+       }\r
+}\r
+void FreeRpcEnumHub(RPC_ENUM_HUB *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Hubs);\r
+}\r
+\r
+// RPC_DELETE_HUB\r
+void InRpcDeleteHub(RPC_DELETE_HUB *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_DELETE_HUB));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+}\r
+void OutRpcDeleteHub(PACK *p, RPC_DELETE_HUB *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+}\r
+\r
+// RPC_ENUM_CONNECTION\r
+void InRpcEnumConnection(RPC_ENUM_CONNECTION *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_CONNECTION));\r
+       t->NumConnection = PackGetIndexCount(p, "Name");\r
+       t->Connections = ZeroMalloc(sizeof(RPC_ENUM_CONNECTION_ITEM) * t->NumConnection);\r
+\r
+       for (i = 0;i < t->NumConnection;i++)\r
+       {\r
+               RPC_ENUM_CONNECTION_ITEM *e = &t->Connections[i];\r
+\r
+               e->Ip = PackGetIp32Ex(p, "Ip", i);\r
+               e->Port = PackGetIntEx(p, "Port", i);\r
+               PackGetStrEx(p, "Name", e->Name, sizeof(e->Name), i);\r
+               PackGetStrEx(p, "Hostname", e->Hostname, sizeof(e->Hostname), i);\r
+               e->ConnectedTime = PackGetInt64Ex(p, "ConnectedTime", i);\r
+               e->Type = PackGetIntEx(p, "Type", i);\r
+       }\r
+}\r
+void OutRpcEnumConnection(PACK *p, RPC_ENUM_CONNECTION *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t->NumConnection;i++)\r
+       {\r
+               RPC_ENUM_CONNECTION_ITEM *e = &t->Connections[i];\r
+\r
+               PackAddIp32Ex(p, "Ip", e->Ip, i, t->NumConnection);\r
+               PackAddIntEx(p, "Port", e->Port, i, t->NumConnection);\r
+               PackAddStrEx(p, "Name", e->Name, i, t->NumConnection);\r
+               PackAddStrEx(p, "Hostname", e->Hostname, i, t->NumConnection);\r
+               PackAddInt64Ex(p, "ConnectedTime", e->ConnectedTime, i, t->NumConnection);\r
+               PackAddIntEx(p, "Type", e->Type, i, t->NumConnection);\r
+       }\r
+}\r
+void FreeRpcEnumConnetion(RPC_ENUM_CONNECTION *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Connections);\r
+}\r
+\r
+// RPC_DISCONNECT_CONNECTION\r
+void InRpcDisconnectConnection(RPC_DISCONNECT_CONNECTION *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_DISCONNECT_CONNECTION));\r
+       PackGetStr(p, "Name", t->Name, sizeof(t->Name));\r
+}\r
+void OutRpcDisconnectConnection(PACK *p, RPC_DISCONNECT_CONNECTION *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "Name", t->Name);\r
+}\r
+\r
+// RPC_CONNECTION_INFO\r
+void InRpcConnectionInfo(RPC_CONNECTION_INFO *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_CONNECTION_INFO));\r
+       PackGetStr(p, "Name", t->Name, sizeof(t->Name));\r
+       t->Ip = PackGetIp32(p, "Ip");\r
+       t->Port = PackGetInt(p, "Port");\r
+       t->ConnectedTime = PackGetInt64(p, "ConnectedTime");\r
+       PackGetStr(p, "Hostname", t->Hostname, sizeof(t->Hostname));\r
+       PackGetStr(p, "ServerStr", t->ServerStr, sizeof(t->ServerStr));\r
+       PackGetStr(p, "ClientStr", t->ClientStr, sizeof(t->ClientStr));\r
+       t->ServerVer = PackGetInt(p, "ServerVer");\r
+       t->ServerBuild = PackGetInt(p, "ServerBuild");\r
+       t->ClientVer = PackGetInt(p, "ClientVer");\r
+       t->ClientBuild = PackGetInt(p, "ClientBuild");\r
+       t->Type = PackGetInt(p, "Type");\r
+}\r
+void OutRpcConnectionInfo(PACK *p, RPC_CONNECTION_INFO *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "Name", t->Name);\r
+       PackAddIp32(p, "Ip", t->Ip);\r
+       PackAddInt(p, "Port", t->Port);\r
+       PackAddInt64(p, "ConnectedTime", t->ConnectedTime);\r
+       PackAddStr(p, "Hostname", t->Hostname);\r
+       PackAddStr(p, "ServerStr", t->ServerStr);\r
+       PackAddStr(p, "ClientStr", t->ClientStr);\r
+       PackAddInt(p, "ServerVer", t->ServerVer);\r
+       PackAddInt(p, "ServerBuild", t->ServerBuild);\r
+       PackAddInt(p, "ClientVer", t->ClientVer);\r
+       PackAddInt(p, "ClientBuild", t->ClientBuild);\r
+       PackAddInt(p, "Type", t->Type);\r
+}\r
+\r
+// RPC_SET_HUB_ONLINE\r
+void InRpcSetHubOnline(RPC_SET_HUB_ONLINE *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_SET_HUB_ONLINE));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->Online = PackGetBool(p, "Online");\r
+}\r
+void OutRpcSetHubOnline(PACK *p, RPC_SET_HUB_ONLINE *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddBool(p, "Online", t->Online);\r
+}\r
+\r
+// RPC_HUB_STATUS\r
+void InRpcHubStatus(RPC_HUB_STATUS *t, PACK *p)\r
+{\r
+       Zero(t, sizeof(RPC_HUB_STATUS));\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->Online = PackGetBool(p, "Online");\r
+       t->HubType = PackGetInt(p, "HubType");\r
+       t->NumSessions = PackGetInt(p, "NumSessions");\r
+       t->NumSessionsClient = PackGetInt(p, "NumSessionsClient");\r
+       t->NumSessionsBridge = PackGetInt(p, "NumSessionsBridge");\r
+       t->NumAccessLists = PackGetInt(p, "NumAccessLists");\r
+       t->NumUsers = PackGetInt(p, "NumUsers");\r
+       t->NumGroups = PackGetInt(p, "NumGroups");\r
+       t->NumMacTables = PackGetInt(p, "NumMacTables");\r
+       t->NumIpTables = PackGetInt(p, "NumIpTables");\r
+       t->SecureNATEnabled = PackGetBool(p, "SecureNATEnabled");\r
+       InRpcTraffic(&t->Traffic, p);\r
+       t->LastCommTime = PackGetInt64(p, "LastCommTime");\r
+       t->CreatedTime = PackGetInt64(p, "CreatedTime");\r
+       t->LastLoginTime = PackGetInt64(p, "LastLoginTime");\r
+       t->NumLogin = PackGetInt(p, "NumLogin");\r
+}\r
+void OutRpcHubStatus(PACK *p, RPC_HUB_STATUS *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddBool(p, "Online", t->Online);\r
+       PackAddInt(p, "HubType", t->HubType);\r
+       PackAddInt(p, "NumSessions", t->NumSessions);\r
+       PackAddInt(p, "NumSessionsClient", t->NumSessionsClient);\r
+       PackAddInt(p, "NumSessionsBridge", t->NumSessionsBridge);\r
+       PackAddInt(p, "NumAccessLists", t->NumAccessLists);\r
+       PackAddInt(p, "NumUsers", t->NumUsers);\r
+       PackAddInt(p, "NumGroups", t->NumGroups);\r
+       PackAddInt(p, "NumMacTables", t->NumMacTables);\r
+       PackAddInt(p, "NumIpTables", t->NumIpTables);\r
+       PackAddBool(p, "SecureNATEnabled", t->SecureNATEnabled);\r
+       OutRpcTraffic(p, &t->Traffic);\r
+       PackAddInt64(p, "LastCommTime", t->LastCommTime);\r
+       PackAddInt64(p, "CreatedTime", t->CreatedTime);\r
+       PackAddInt64(p, "LastLoginTime", t->LastLoginTime);\r
+       PackAddInt(p, "NumLogin", t->NumLogin);\r
+}\r
+\r
+// RPC_HUB_LOG\r
+void InRpcHubLog(RPC_HUB_LOG *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_HUB_LOG));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->LogSetting.SaveSecurityLog = PackGetBool(p, "SaveSecurityLog");\r
+       t->LogSetting.SecurityLogSwitchType = PackGetInt(p, "SecurityLogSwitchType");\r
+       t->LogSetting.SavePacketLog = PackGetBool(p, "SavePacketLog");\r
+       t->LogSetting.PacketLogSwitchType = PackGetInt(p, "PacketLogSwitchType");\r
+       for (i = 0;i < NUM_PACKET_LOG;i++)\r
+       {\r
+               t->LogSetting.PacketLogConfig[i] = PackGetIntEx(p, "PacketLogConfig", i);\r
+       }\r
+}\r
+void OutRpcHubLog(PACK *p, RPC_HUB_LOG *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddBool(p, "SaveSecurityLog", t->LogSetting.SaveSecurityLog);\r
+       PackAddInt(p, "SecurityLogSwitchType", t->LogSetting.SecurityLogSwitchType);\r
+       PackAddBool(p, "SavePacketLog", t->LogSetting.SavePacketLog);\r
+       PackAddInt(p, "PacketLogSwitchType", t->LogSetting.PacketLogSwitchType);\r
+       for (i = 0;i < NUM_PACKET_LOG;i++)\r
+       {\r
+               PackAddIntEx(p, "PacketLogConfig", t->LogSetting.PacketLogConfig[i], i, NUM_PACKET_LOG);\r
+       }\r
+}\r
+\r
+// RPC_HUB_ADD_CA\r
+void InRpcHubAddCa(RPC_HUB_ADD_CA *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_HUB_ADD_CA));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->Cert = PackGetX(p, "Cert");\r
+}\r
+void OutRpcHubAddCa(PACK *p, RPC_HUB_ADD_CA *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddX(p, "Cert", t->Cert);\r
+}\r
+void FreeRpcHubAddCa(RPC_HUB_ADD_CA *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeX(t->Cert);\r
+}\r
+\r
+// RPC_HUB_ENUM_CA\r
+void InRpcHubEnumCa(RPC_HUB_ENUM_CA *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_HUB_ENUM_CA));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->NumCa = PackGetIndexCount(p, "Key");\r
+       t->Ca = ZeroMalloc(sizeof(RPC_HUB_ENUM_CA_ITEM) * t->NumCa);\r
+\r
+       for (i = 0;i < t->NumCa;i++)\r
+       {\r
+               RPC_HUB_ENUM_CA_ITEM *e = &t->Ca[i];\r
+\r
+               e->Key = PackGetIntEx(p, "Key", i);\r
+               PackGetUniStrEx(p, "SubjectName", e->SubjectName, sizeof(e->SubjectName), i);\r
+               PackGetUniStrEx(p, "IssuerName", e->IssuerName, sizeof(e->IssuerName), i);\r
+               e->Expires = PackGetInt64Ex(p, "Expires", i);\r
+       }\r
+}\r
+void OutRpcHubEnumCa(PACK *p, RPC_HUB_ENUM_CA *t)\r
+{\r
+       UINT i;\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t->NumCa;i++)\r
+       {\r
+               RPC_HUB_ENUM_CA_ITEM *e = &t->Ca[i];\r
+\r
+               PackAddIntEx(p, "Key", e->Key, i, t->NumCa);\r
+               PackAddUniStrEx(p, "SubjectName", e->SubjectName, i, t->NumCa);\r
+               PackAddUniStrEx(p, "IssuerName", e->IssuerName, i, t->NumCa);\r
+               PackAddInt64Ex(p, "Expires", e->Expires, i, t->NumCa);\r
+       }\r
+}\r
+void FreeRpcHubEnumCa(RPC_HUB_ENUM_CA *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Ca);\r
+}\r
+\r
+// RPC_HUB_GET_CA\r
+void InRpcHubGetCa(RPC_HUB_GET_CA *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_HUB_GET_CA));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->Key = PackGetInt(p, "Key");\r
+       t->Cert = PackGetX(p, "Cert");\r
+}\r
+void OutRpcHubGetCa(PACK *p, RPC_HUB_GET_CA *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddInt(p, "Key", t->Key);\r
+       PackAddX(p, "Cert", t->Cert);\r
+}\r
+void FreeRpcHubGetCa(RPC_HUB_GET_CA *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeX(t->Cert);\r
+}\r
+\r
+// RPC_HUB_DELETE_CA\r
+void InRpcHubDeleteCa(RPC_HUB_DELETE_CA *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_HUB_DELETE_CA));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->Key = PackGetInt(p, "Key");\r
+}\r
+void OutRpcHubDeleteCa(PACK *p, RPC_HUB_DELETE_CA *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddInt(p, "Key", t->Key);\r
+}\r
+\r
+// RPC_CREATE_LINK\r
+void InRpcCreateLink(RPC_CREATE_LINK *t, PACK *p)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_CREATE_LINK));\r
+       PackGetStr(p, "HubName_Ex", t->HubName, sizeof(t->HubName));\r
+       t->Online = PackGetBool(p, "Online");\r
+       t->ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       InRpcClientOption(t->ClientOption, p);\r
+       t->ClientAuth  = ZeroMalloc(sizeof(CLIENT_AUTH));\r
+       InRpcClientAuth(t->ClientAuth, p);\r
+       InRpcPolicy(&t->Policy, p);\r
+\r
+       t->CheckServerCert = PackGetBool(p, "CheckServerCert");\r
+       b = PackGetBuf(p, "ServerCert");\r
+       if (b != NULL)\r
+       {\r
+               t->ServerCert = BufToX(b, false);\r
+               FreeBuf(b);\r
+       }\r
+}\r
+void OutRpcCreateLink(PACK *p, RPC_CREATE_LINK *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName_Ex",t->HubName);\r
+       PackAddBool(p, "Online", t->Online);\r
+       OutRpcClientOption(p, t->ClientOption);\r
+       OutRpcClientAuth(p, t->ClientAuth);\r
+       OutRpcPolicy(p, &t->Policy);\r
+\r
+       PackAddBool(p, "CheckServerCert", t->CheckServerCert);\r
+       if (t->ServerCert != NULL)\r
+       {\r
+               BUF *b;\r
+               b = XToBuf(t->ServerCert, false);\r
+               PackAddBuf(p, "ServerCert", b);\r
+               FreeBuf(b);\r
+       }\r
+}\r
+void FreeRpcCreateLink(RPC_CREATE_LINK *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (t->ServerCert != NULL)\r
+       {\r
+               FreeX(t->ServerCert);\r
+       }\r
+       Free(t->ClientOption);\r
+       CiFreeClientAuth(t->ClientAuth);\r
+}\r
+\r
+// RPC_ENUM_LINK\r
+void InRpcEnumLink(RPC_ENUM_LINK *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_LINK));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->NumLink = PackGetIndexCount(p, "AccountName");\r
+       t->Links = ZeroMalloc(sizeof(RPC_ENUM_LINK_ITEM) * t->NumLink);\r
+\r
+       for (i = 0;i < t->NumLink;i++)\r
+       {\r
+               RPC_ENUM_LINK_ITEM *e = &t->Links[i];\r
+\r
+               PackGetUniStrEx(p, "AccountName", e->AccountName, sizeof(e->AccountName), i);\r
+               PackGetStrEx(p, "Hostname", e->Hostname, sizeof(e->Hostname), i);\r
+               PackGetStrEx(p, "ConnectedHubName", e->HubName, sizeof(e->HubName), i);\r
+               e->Online = PackGetBoolEx(p, "Online", i);\r
+               e->ConnectedTime = PackGetInt64Ex(p, "ConnectedTime", i);\r
+               e->Connected = PackGetBoolEx(p, "Connected", i);\r
+               e->LastError = PackGetIntEx(p, "LastError", i);\r
+       }\r
+}\r
+void OutRpcEnumLink(PACK *p, RPC_ENUM_LINK *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+\r
+       for (i = 0;i < t->NumLink;i++)\r
+       {\r
+               RPC_ENUM_LINK_ITEM *e = &t->Links[i];\r
+\r
+               PackAddUniStrEx(p, "AccountName", e->AccountName, i, t->NumLink);\r
+               PackAddStrEx(p, "ConnectedHubName", e->HubName, i, t->NumLink);\r
+               PackAddStrEx(p, "Hostname", e->Hostname, i, t->NumLink);\r
+               PackAddBoolEx(p, "Online", e->Online, i, t->NumLink);\r
+               PackAddInt64Ex(p, "ConnectedTime", e->ConnectedTime, i, t->NumLink);\r
+               PackAddBoolEx(p, "Connected", e->Connected, i, t->NumLink);\r
+               PackAddIntEx(p, "LastError", e->LastError, i, t->NumLink);\r
+       }\r
+}\r
+void FreeRpcEnumLink(RPC_ENUM_LINK *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Links);\r
+}\r
+\r
+// RPC_LINK_STATUS\r
+void InRpcLinkStatus(RPC_LINK_STATUS *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_LINK_STATUS));\r
+       PackGetStr(p, "HubName_Ex", t->HubName, sizeof(t->HubName));\r
+       PackGetUniStr(p, "AccountName", t->AccountName, sizeof(t->AccountName));\r
+       InRpcClientGetConnectionStatus(&t->Status, p);\r
+}\r
+void OutRpcLinkStatus(PACK *p, RPC_LINK_STATUS *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName_Ex", t->HubName);\r
+       PackAddUniStr(p, "AccountName", t->AccountName);\r
+       OutRpcClientGetConnectionStatus(p, &t->Status);\r
+}\r
+void FreeRpcLinkStatus(RPC_LINK_STATUS *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CiFreeClientGetConnectionStatus(&t->Status);\r
+}\r
+\r
+// RPC_LINK\r
+void InRpcLink(RPC_LINK *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_LINK));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       PackGetUniStr(p, "AccountName", t->AccountName, sizeof(t->AccountName));\r
+}\r
+void OutRpcLink(PACK *p, RPC_LINK *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddUniStr(p, "AccountName", t->AccountName);\r
+}\r
+\r
+// RPC_RENAME_LINK\r
+void InRpcRenameLink(RPC_RENAME_LINK *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_RENAME_LINK));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       PackGetUniStr(p, "OldAccountName", t->OldAccountName, sizeof(t->OldAccountName));\r
+       PackGetUniStr(p, "NewAccountName", t->NewAccountName, sizeof(t->NewAccountName));\r
+}\r
+void OutRpcRenameLink(PACK *p, RPC_RENAME_LINK *t)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddUniStr(p, "OldAccountName", t->OldAccountName);\r
+       PackAddUniStr(p, "NewAccountName", t->NewAccountName);\r
+}\r
+\r
+// ACCESS\r
+void InRpcAccessEx(ACCESS *a, PACK *p, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(a, sizeof(ACCESS));\r
+       a->Id = PackGetIntEx(p, "Id", index);\r
+       PackGetUniStrEx(p, "Note", a->Note, sizeof(a->Note), index);\r
+       a->Active = PackGetBoolEx(p, "Active", index);\r
+       a->Priority = PackGetIntEx(p, "Priority", index);\r
+       a->Discard = PackGetBoolEx(p, "Discard", index);\r
+       a->SrcIpAddress = PackGetIp32Ex(p, "SrcIpAddress", index);\r
+       a->SrcSubnetMask = PackGetIp32Ex(p, "SrcSubnetMask", index);\r
+       a->DestIpAddress = PackGetIp32Ex(p, "DestIpAddress", index);\r
+       a->DestSubnetMask = PackGetIp32Ex(p, "DestSubnetMask", index);\r
+       a->Protocol = PackGetIntEx(p, "Protocol", index);\r
+       a->SrcPortStart = PackGetIntEx(p, "SrcPortStart", index);\r
+       a->SrcPortEnd = PackGetIntEx(p, "SrcPortEnd", index);\r
+       a->DestPortStart = PackGetIntEx(p, "DestPortStart", index);\r
+       a->DestPortEnd = PackGetIntEx(p, "DestPortEnd", index);\r
+       a->SrcUsernameHash = PackGetIntEx(p, "SrcUsernameHash", index);\r
+       PackGetStrEx(p, "SrcUsername", a->SrcUsername, sizeof(a->SrcUsername), index);\r
+       a->DestUsernameHash = PackGetIntEx(p, "DestUsernameHash", index);\r
+       PackGetStrEx(p, "DestUsername", a->DestUsername, sizeof(a->DestUsername), index);\r
+       a->CheckSrcMac = PackGetBoolEx(p, "CheckSrcMac", index);\r
+       PackGetDataEx2(p, "SrcMacAddress", a->SrcMacAddress, sizeof(a->SrcMacAddress), index);\r
+       PackGetDataEx2(p, "SrcMacMask", a->SrcMacMask, sizeof(a->SrcMacMask), index);\r
+       a->CheckDstMac = PackGetBoolEx(p, "CheckDstMac", index);\r
+       PackGetDataEx2(p, "DstMacAddress", a->DstMacAddress, sizeof(a->DstMacAddress), index);\r
+       PackGetDataEx2(p, "DstMacMask", a->DstMacMask, sizeof(a->DstMacMask), index);\r
+       a->CheckTcpState = PackGetBoolEx(p, "CheckTcpState", index);\r
+       a->Established = PackGetBoolEx(p, "Established", index);\r
+       a->Delay = PackGetIntEx(p, "Delay", index);\r
+       a->Jitter = PackGetIntEx(p, "Jitter", index);\r
+       a->Loss = PackGetIntEx(p, "Loss", index);\r
+       a->IsIPv6 = PackGetBoolEx(p, "IsIPv6", index);\r
+       if (a->IsIPv6)\r
+       {\r
+               PackGetIp6AddrEx(p, "SrcIpAddress6", &a->SrcIpAddress6, index);\r
+               PackGetIp6AddrEx(p, "SrcSubnetMask6", &a->SrcSubnetMask6, index);\r
+               PackGetIp6AddrEx(p, "DestIpAddress6", &a->DestIpAddress6, index);\r
+               PackGetIp6AddrEx(p, "DestSubnetMask6", &a->DestSubnetMask6, index);\r
+       }\r
+}\r
+void InRpcAccess(ACCESS *a, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       InRpcAccessEx(a, p, 0);\r
+}\r
+void OutRpcAccessEx(PACK *p, ACCESS *a, UINT index, UINT total)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddIntEx(p, "Id", a->Id, index, total);\r
+       PackAddUniStrEx(p, "Note", a->Note, index, total);\r
+       PackAddBoolEx(p, "Active", a->Active, index, total);\r
+       PackAddIntEx(p, "Priority", a->Priority, index, total);\r
+       PackAddBoolEx(p, "Discard", a->Discard, index, total);\r
+       if (a->IsIPv6)\r
+       {\r
+               PackAddIp32Ex(p, "SrcIpAddress", 0xFDFFFFDF, index, total);\r
+               PackAddIp32Ex(p, "SrcSubnetMask", 0xFFFFFFFF, index, total);\r
+               PackAddIp32Ex(p, "DestIpAddress", 0xFDFFFFDF, index, total);\r
+               PackAddIp32Ex(p, "DestSubnetMask", 0xFFFFFFFF, index, total);\r
+       }\r
+       else\r
+       {\r
+               PackAddIp32Ex(p, "SrcIpAddress", a->SrcIpAddress, index, total);\r
+               PackAddIp32Ex(p, "SrcSubnetMask", a->SrcSubnetMask, index, total);\r
+               PackAddIp32Ex(p, "DestIpAddress", a->DestIpAddress, index, total);\r
+               PackAddIp32Ex(p, "DestSubnetMask", a->DestSubnetMask, index, total);\r
+       }\r
+       PackAddIntEx(p, "Protocol", a->Protocol, index, total);\r
+       PackAddIntEx(p, "SrcPortStart", a->SrcPortStart, index, total);\r
+       PackAddIntEx(p, "SrcPortEnd", a->SrcPortEnd, index, total);\r
+       PackAddIntEx(p, "DestPortStart", a->DestPortStart, index, total);\r
+       PackAddIntEx(p, "DestPortEnd", a->DestPortEnd, index, total);\r
+       PackAddIntEx(p, "SrcUsernameHash", a->SrcUsernameHash, index, total);\r
+       PackAddStrEx(p, "SrcUsername", a->SrcUsername, index, total);\r
+       PackAddIntEx(p, "DestUsernameHash", a->DestUsernameHash, index, total);\r
+       PackAddStrEx(p, "DestUsername", a->DestUsername, index, total);\r
+       PackAddBoolEx(p, "CheckSrcMac", a->CheckSrcMac, index, total);\r
+       PackAddDataEx(p, "SrcMacAddress", a->SrcMacAddress, sizeof(a->SrcMacAddress), index, total);\r
+       PackAddDataEx(p, "SrcMacMask", a->SrcMacMask, sizeof(a->SrcMacMask), index, total);\r
+       PackAddBoolEx(p, "CheckDstMac", a->CheckDstMac, index, total);\r
+       PackAddDataEx(p, "DstMacAddress", a->DstMacAddress, sizeof(a->DstMacAddress), index, total);\r
+       PackAddDataEx(p, "DstMacMask", a->DstMacMask, sizeof(a->DstMacMask), index, total);\r
+       PackAddBoolEx(p, "CheckTcpState", a->CheckTcpState, index, total);\r
+       PackAddBoolEx(p, "Established", a->Established, index, total);\r
+       PackAddIntEx(p, "Delay", a->Delay, index, total);\r
+       PackAddIntEx(p, "Jitter", a->Jitter, index, total);\r
+       PackAddIntEx(p, "Loss", a->Loss, index, total);\r
+       PackAddBoolEx(p, "IsIPv6", a->IsIPv6, index, total);\r
+       if (a->IsIPv6)\r
+       {\r
+               PackAddIp6AddrEx(p, "SrcIpAddress6", &a->SrcIpAddress6, index, total);\r
+               PackAddIp6AddrEx(p, "SrcSubnetMask6", &a->SrcSubnetMask6, index, total);\r
+               PackAddIp6AddrEx(p, "DestIpAddress6", &a->DestIpAddress6, index, total);\r
+               PackAddIp6AddrEx(p, "DestSubnetMask6", &a->DestSubnetMask6, index, total);\r
+       }\r
+       else\r
+       {\r
+               IPV6_ADDR zero;\r
+\r
+               Zero(&zero, sizeof(zero));\r
+\r
+               PackAddIp6AddrEx(p, "SrcIpAddress6", &zero, index, total);\r
+               PackAddIp6AddrEx(p, "SrcSubnetMask6", &zero, index, total);\r
+               PackAddIp6AddrEx(p, "DestIpAddress6", &zero, index, total);\r
+               PackAddIp6AddrEx(p, "DestSubnetMask6", &zero, index, total);\r
+       }\r
+}\r
+void OutRpcAccess(PACK *p, ACCESS *a)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       OutRpcAccessEx(p, a, 0, 1);\r
+}\r
+\r
+// RPC_ENUM_ACCESS_LIST\r
+void InRpcEnumAccessList(RPC_ENUM_ACCESS_LIST *a, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (a == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(a, sizeof(RPC_ENUM_ACCESS_LIST));\r
+       PackGetStr(p, "HubName", a->HubName, sizeof(a->HubName));\r
+       a->NumAccess = PackGetIndexCount(p, "Protocol");\r
+       a->Accesses = ZeroMalloc(sizeof(ACCESS) * a->NumAccess);\r
+\r
+       for (i = 0;i < a->NumAccess;i++)\r
+       {\r
+               ACCESS *e = &a->Accesses[i];\r
+\r
+               InRpcAccessEx(e, p, i);\r
+       }\r
+}\r
+void OutRpcEnumAccessList(PACK *p, RPC_ENUM_ACCESS_LIST *a)\r
+{\r
+       UINT i;\r
+       PackAddStr(p, "HubName", a->HubName);\r
+       // 引数チェック\r
+       if (a == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < a->NumAccess;i++)\r
+       {\r
+               ACCESS *e = &a->Accesses[i];\r
+\r
+               OutRpcAccessEx(p, e, i, a->NumAccess);\r
+       }\r
+}\r
+void FreeRpcEnumAccessList(RPC_ENUM_ACCESS_LIST *a)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(a->Accesses);\r
+}\r
+\r
+// AUTHDATA\r
+void *InRpcAuthData(PACK *p, UINT *authtype)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       AUTHPASSWORD *pw;\r
+       AUTHUSERCERT *usercert;\r
+       AUTHROOTCERT *rootcert;\r
+       AUTHRADIUS *radius;\r
+       AUTHNT *nt;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (authtype == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       *authtype = PackGetInt(p, "AuthType");\r
+\r
+       switch (*authtype)\r
+       {\r
+       case AUTHTYPE_PASSWORD:\r
+               pw = ZeroMalloc(sizeof(AUTHPASSWORD));\r
+               PackGetData2(p, "HashedKey", pw->HashedKey, sizeof(pw->HashedKey));\r
+               return pw;\r
+\r
+       case AUTHTYPE_USERCERT:\r
+               usercert = ZeroMalloc(sizeof(AUTHUSERCERT));\r
+               usercert->UserX = PackGetX(p, "UserX");\r
+               return usercert;\r
+\r
+       case AUTHTYPE_ROOTCERT:\r
+               rootcert = ZeroMalloc(sizeof(AUTHROOTCERT));\r
+               b = PackGetBuf(p, "Serial");\r
+               if (b != NULL)\r
+               {\r
+                       rootcert->Serial = NewXSerial(b->Buf, b->Size);\r
+                       FreeBuf(b);\r
+               }\r
+               if (PackGetUniStr(p, "CommonName", tmp, sizeof(tmp)))\r
+               {\r
+                       rootcert->CommonName = CopyUniStr(tmp);\r
+               }\r
+               return rootcert;\r
+\r
+       case AUTHTYPE_RADIUS:\r
+               radius = ZeroMalloc(sizeof(AUTHRADIUS));\r
+               if (PackGetUniStr(p, "RadiusUsername", tmp, sizeof(tmp)))\r
+               {\r
+                       radius->RadiusUsername = CopyUniStr(tmp);\r
+               }\r
+               else\r
+               {\r
+                       radius->RadiusUsername = CopyUniStr(L"");\r
+               }\r
+               return radius;\r
+\r
+       case AUTHTYPE_NT:\r
+               nt = ZeroMalloc(sizeof(AUTHNT));\r
+               if (PackGetUniStr(p, "NtUsername", tmp, sizeof(tmp)))\r
+               {\r
+                       nt->NtUsername = CopyUniStr(tmp);\r
+               }\r
+               else\r
+               {\r
+                       nt->NtUsername = CopyUniStr(L"");\r
+               }\r
+               return nt;\r
+       }\r
+\r
+       return NULL;\r
+}\r
+void OutRpcAuthData(PACK *p, void *authdata, UINT authtype)\r
+{\r
+       AUTHPASSWORD *pw = authdata;\r
+       AUTHUSERCERT *usercert = authdata;\r
+       AUTHROOTCERT *rootcert = authdata;\r
+       AUTHRADIUS *radius = authdata;\r
+       AUTHNT *nt = authdata;\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "AuthType", authtype);\r
+\r
+       switch (authtype)\r
+       {\r
+       case AUTHTYPE_PASSWORD:\r
+               PackAddData(p, "HashedKey", pw->HashedKey, sizeof(pw->HashedKey));\r
+               break;\r
+\r
+       case AUTHTYPE_USERCERT:\r
+               PackAddX(p, "UserX", usercert->UserX);\r
+               break;\r
+\r
+       case AUTHTYPE_ROOTCERT:\r
+               if (rootcert->Serial != NULL)\r
+               {\r
+                       PackAddData(p, "Serial", rootcert->Serial->data, rootcert->Serial->size);\r
+               }\r
+               if (rootcert->CommonName != NULL)\r
+               {\r
+                       PackAddUniStr(p, "CommonName", rootcert->CommonName);\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_RADIUS:\r
+               PackAddUniStr(p, "RadiusUsername", radius->RadiusUsername);\r
+               break;\r
+\r
+       case AUTHTYPE_NT:\r
+               PackAddUniStr(p, "NtUsername", nt->NtUsername);\r
+               break;\r
+       }\r
+}\r
+void FreeRpcAuthData(void *authdata, UINT authtype)\r
+{\r
+       FreeAuthData(authtype, authdata);\r
+}\r
+\r
+// RPC_SET_USER\r
+void InRpcSetUser(RPC_SET_USER *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_SET_USER));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       PackGetStr(p, "Name", t->Name, sizeof(t->Name));\r
+       PackGetStr(p, "GroupName", t->GroupName, sizeof(t->GroupName));\r
+       PackGetUniStr(p, "Realname", t->Realname, sizeof(t->Realname));\r
+       PackGetUniStr(p, "Note", t->Note, sizeof(t->Note));\r
+       t->CreatedTime = PackGetInt64(p, "CreatedTime");\r
+       t->UpdatedTime = PackGetInt64(p, "UpdatedTime");\r
+       t->ExpireTime = PackGetInt64(p, "ExpireTime");\r
+       t->AuthData = InRpcAuthData(p, &t->AuthType);\r
+       t->NumLogin = PackGetInt(p, "NumLogin");\r
+       InRpcTraffic(&t->Traffic, p);\r
+\r
+       if (PackGetBool(p, "UsePolicy"))\r
+       {\r
+               t->Policy = ZeroMalloc(sizeof(POLICY));\r
+               InRpcPolicy(t->Policy, p);\r
+       }\r
+}\r
+\r
+void OutRpcSetUser(PACK *p, RPC_SET_USER *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddStr(p, "Name", t->Name);\r
+       PackAddStr(p, "GroupName", t->GroupName);\r
+       PackAddUniStr(p, "Realname", t->Realname);\r
+       PackAddUniStr(p, "Note", t->Note);\r
+       PackAddInt64(p, "CreatedTime", t->CreatedTime);\r
+       PackAddInt64(p, "UpdatedTime", t->UpdatedTime);\r
+       PackAddInt64(p, "ExpireTime", t->ExpireTime);\r
+       OutRpcAuthData(p, t->AuthData, t->AuthType);\r
+       PackAddInt(p, "NumLogin", t->NumLogin);\r
+       OutRpcTraffic(p, &t->Traffic);\r
+\r
+       if (t->Policy != NULL)\r
+       {\r
+               PackAddBool(p, "UsePolicy", true);\r
+               OutRpcPolicy(p, t->Policy);\r
+       }\r
+}\r
+void FreeRpcSetUser(RPC_SET_USER *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeRpcAuthData(t->AuthData, t->AuthType);\r
+       if (t->Policy)\r
+       {\r
+               Free(t->Policy);\r
+       }\r
+}\r
+\r
+// RPC_ENUM_USER\r
+void InRpcEnumUser(RPC_ENUM_USER *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_USER));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->NumUser = PackGetIndexCount(p, "Name");\r
+       t->Users = ZeroMalloc(sizeof(RPC_ENUM_USER_ITEM) * t->NumUser);\r
+\r
+       for (i = 0;i < t->NumUser;i++)\r
+       {\r
+               RPC_ENUM_USER_ITEM *e = &t->Users[i];\r
+\r
+               PackGetStrEx(p, "Name", e->Name, sizeof(e->Name), i);\r
+               PackGetStrEx(p, "GroupName", e->GroupName, sizeof(e->GroupName), i);\r
+               PackGetUniStrEx(p, "Realname", e->Realname, sizeof(e->Realname), i);\r
+               PackGetUniStrEx(p, "Note", e->Note, sizeof(e->Note), i);\r
+               e->AuthType = PackGetIntEx(p, "AuthType", i);\r
+               e->LastLoginTime = PackGetInt64Ex(p, "LastLoginTime", i);\r
+               e->NumLogin = PackGetIntEx(p, "NumLogin", i);\r
+               e->DenyAccess = PackGetBoolEx(p, "DenyAccess", i);\r
+       }\r
+}\r
+void OutRpcEnumUser(PACK *p, RPC_ENUM_USER *t)\r
+{\r
+       UINT i;\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t->NumUser;i++)\r
+       {\r
+               RPC_ENUM_USER_ITEM *e = &t->Users[i];\r
+\r
+               PackAddStrEx(p, "Name", e->Name, i, t->NumUser);\r
+               PackAddStrEx(p, "GroupName", e->GroupName, i, t->NumUser);\r
+               PackAddUniStrEx(p, "Realname", e->Realname, i, t->NumUser);\r
+               PackAddUniStrEx(p, "Note", e->Note, i, t->NumUser);\r
+               PackAddIntEx(p, "AuthType", e->AuthType, i, t->NumUser);\r
+               PackAddInt64Ex(p, "LastLoginTime", e->LastLoginTime, i, t->NumUser);\r
+               PackAddIntEx(p, "NumLogin", e->NumLogin, i, t->NumUser);\r
+               PackAddBoolEx(p, "DenyAccess", e->DenyAccess, i, t->NumUser);\r
+       }\r
+}\r
+void FreeRpcEnumUser(RPC_ENUM_USER *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Users);\r
+}\r
+\r
+// RPC_SET_GROUP\r
+void InRpcSetGroup(RPC_SET_GROUP *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_SET_GROUP));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       PackGetStr(p, "Name", t->Name, sizeof(t->Name));\r
+       PackGetUniStr(p, "Realname", t->Realname, sizeof(t->Realname));\r
+       PackGetUniStr(p, "Note", t->Note, sizeof(t->Note));\r
+       InRpcTraffic(&t->Traffic, p);\r
+\r
+       if (PackGetBool(p, "UsePolicy"))\r
+       {\r
+               t->Policy = ZeroMalloc(sizeof(POLICY));\r
+               InRpcPolicy(t->Policy, p);\r
+       }\r
+}\r
+void OutRpcSetGroup(PACK *p, RPC_SET_GROUP *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddStr(p, "Name", t->Name);\r
+       PackAddUniStr(p, "Realname", t->Realname);\r
+       PackAddUniStr(p, "Note", t->Note);\r
+       OutRpcTraffic(p, &t->Traffic);\r
+\r
+       if (t->Policy != NULL)\r
+       {\r
+               PackAddBool(p, "UsePolicy", true);\r
+               OutRpcPolicy(p, t->Policy);\r
+       }\r
+}\r
+void FreeRpcSetGroup(RPC_SET_GROUP *t)\r
+{\r
+       Free(t->Policy);\r
+}\r
+\r
+// RPC_ENUM_GROUP\r
+void InRpcEnumGroup(RPC_ENUM_GROUP *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_GROUP));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->NumGroup = PackGetIndexCount(p, "Name");\r
+       t->Groups = ZeroMalloc(sizeof(RPC_ENUM_GROUP_ITEM) * t->NumGroup);\r
+\r
+       for (i = 0;i < t->NumGroup;i++)\r
+       {\r
+               RPC_ENUM_GROUP_ITEM *e = &t->Groups[i];\r
+\r
+               PackGetStrEx(p, "Name", e->Name, sizeof(e->Name), i);\r
+               PackGetUniStrEx(p, "Realname", e->Realname, sizeof(e->Realname), i);\r
+               PackGetUniStrEx(p, "Note", e->Note, sizeof(e->Note), i);\r
+               e->NumUsers = PackGetIntEx(p, "NumUsers", i);\r
+               e->DenyAccess = PackGetBoolEx(p, "DenyAccess", i);\r
+       }\r
+}\r
+void OutRpcEnumGroup(PACK *p, RPC_ENUM_GROUP *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+\r
+       for (i = 0;i < t->NumGroup;i++)\r
+       {\r
+               RPC_ENUM_GROUP_ITEM *e = &t->Groups[i];\r
+\r
+               PackAddStrEx(p, "Name", e->Name, i, t->NumGroup);\r
+               PackAddUniStrEx(p, "Realname", e->Realname, i, t->NumGroup);\r
+               PackAddUniStrEx(p, "Note", e->Note, i, t->NumGroup);\r
+               PackAddIntEx(p, "NumUsers", e->NumUsers, i, t->NumGroup);\r
+               PackAddBoolEx(p, "DenyAccess", e->DenyAccess, i, t->NumGroup);\r
+       }\r
+}\r
+void FreeRpcEnumGroup(RPC_ENUM_GROUP *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Groups);\r
+}\r
+\r
+// RPC_DELETE_USER\r
+void InRpcDeleteUser(RPC_DELETE_USER *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_DELETE_USER));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       PackGetStr(p, "Name", t->Name, sizeof(t->Name));\r
+}\r
+void OutRpcDeleteUser(PACK *p, RPC_DELETE_USER *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddStr(p, "Name", t->Name);\r
+}\r
+\r
+// RPC_ENUM_SESSION\r
+void InRpcEnumSession(RPC_ENUM_SESSION *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_SESSION));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->NumSession = PackGetIndexCount(p, "Name");\r
+       t->Sessions = ZeroMalloc(sizeof(RPC_ENUM_SESSION_ITEM) * t->NumSession);\r
+\r
+       for (i = 0;i < t->NumSession;i++)\r
+       {\r
+               RPC_ENUM_SESSION_ITEM *e = &t->Sessions[i];\r
+\r
+               PackGetStrEx(p, "Name", e->Name, sizeof(e->Name), i);\r
+               PackGetStrEx(p, "Username", e->Username, sizeof(e->Username), i);\r
+               e->Ip = PackGetIntEx(p, "Ip", i);\r
+               PackGetStrEx(p, "Hostname", e->Hostname, sizeof(e->Hostname), i);\r
+               e->MaxNumTcp = PackGetIntEx(p, "MaxNumTcp", i);\r
+               e->CurrentNumTcp = PackGetIntEx(p, "CurrentNumTcp", i);\r
+               e->PacketSize = PackGetInt64Ex(p, "PacketSize", i);\r
+               e->PacketNum = PackGetInt64Ex(p, "PacketNum", i);\r
+               e->RemoteSession = PackGetBoolEx(p, "RemoteSession", i);\r
+               e->LinkMode = PackGetBoolEx(p, "LinkMode", i);\r
+               e->SecureNATMode = PackGetBoolEx(p, "SecureNATMode", i);\r
+               e->BridgeMode = PackGetBoolEx(p, "BridgeMode", i);\r
+               e->Layer3Mode = PackGetBoolEx(p, "Layer3Mode", i);\r
+               e->Client_BridgeMode = PackGetBoolEx(p, "Client_BridgeMode", i);\r
+               e->Client_MonitorMode = PackGetBoolEx(p, "Client_MonitorMode", i);\r
+               PackGetStrEx(p, "RemoteHostname", e->RemoteHostname, sizeof(e->RemoteHostname), i);\r
+               e->VLanId = PackGetIntEx(p, "VLanId", i);\r
+               PackGetDataEx2(p, "UniqueId", e->UniqueId, sizeof(e->UniqueId), i);\r
+       }\r
+}\r
+void OutRpcEnumSession(PACK *p, RPC_ENUM_SESSION *t)\r
+{\r
+       UINT i;\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t->NumSession;i++)\r
+       {\r
+               RPC_ENUM_SESSION_ITEM *e = &t->Sessions[i];\r
+\r
+               PackAddStrEx(p, "Name", e->Name, i, t->NumSession);\r
+               PackAddStrEx(p, "Username", e->Username, i, t->NumSession);\r
+               PackAddIp32Ex(p, "Ip", e->Ip, i, t->NumSession);\r
+               PackAddStrEx(p, "Hostname", e->Hostname, i, t->NumSession);\r
+               PackAddIntEx(p, "MaxNumTcp", e->MaxNumTcp, i, t->NumSession);\r
+               PackAddIntEx(p, "CurrentNumTcp", e->CurrentNumTcp, i, t->NumSession);\r
+               PackAddInt64Ex(p, "PacketSize", e->PacketSize, i, t->NumSession);\r
+               PackAddInt64Ex(p, "PacketNum", e->PacketNum, i, t->NumSession);\r
+               PackAddBoolEx(p, "RemoteSession", e->RemoteSession, i, t->NumSession);\r
+               PackAddStrEx(p, "RemoteHostname", e->RemoteHostname, i, t->NumSession);\r
+               PackAddBoolEx(p, "LinkMode", e->LinkMode, i, t->NumSession);\r
+               PackAddBoolEx(p, "SecureNATMode", e->SecureNATMode, i, t->NumSession);\r
+               PackAddBoolEx(p, "BridgeMode", e->BridgeMode, i, t->NumSession);\r
+               PackAddBoolEx(p, "Layer3Mode", e->Layer3Mode, i, t->NumSession);\r
+               PackAddBoolEx(p, "Client_BridgeMode", e->Client_BridgeMode, i, t->NumSession);\r
+               PackAddBoolEx(p, "Client_MonitorMode", e->Client_MonitorMode, i, t->NumSession);\r
+               PackAddIntEx(p, "VLanId", e->VLanId, i, t->NumSession);\r
+               PackAddDataEx(p, "UniqueId", e->UniqueId, sizeof(e->UniqueId), i, t->NumSession);\r
+       }\r
+}\r
+void FreeRpcEnumSession(RPC_ENUM_SESSION *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Sessions);\r
+}\r
+\r
+// RPC_KEY_PAIR\r
+void InRpcKeyPair(RPC_KEY_PAIR *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t->Cert = PackGetX(p, "Cert");\r
+       t->Key = PackGetK(p, "Key");\r
+}\r
+void OutRpcKeyPair(PACK *p, RPC_KEY_PAIR *t)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddX(p, "Cert", t->Cert);\r
+       PackAddK(p, "Key", t->Key);\r
+}\r
+void FreeRpcKeyPair(RPC_KEY_PAIR *t)\r
+{\r
+       FreeX(t->Cert);\r
+       FreeK(t->Key);\r
+}\r
+\r
+// NODE_INFO\r
+void InRpcNodeInfo(NODE_INFO *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(NODE_INFO));\r
+       PackGetStr(p, "ClientProductName", t->ClientProductName, sizeof(t->ClientProductName));\r
+       PackGetStr(p, "ServerProductName", t->ServerProductName, sizeof(t->ServerProductName));\r
+       PackGetStr(p, "ClientOsName", t->ClientOsName, sizeof(t->ClientOsName));\r
+       PackGetStr(p, "ClientOsVer", t->ClientOsVer, sizeof(t->ClientOsVer));\r
+       PackGetStr(p, "ClientOsProductId", t->ClientOsProductId, sizeof(t->ClientOsProductId));\r
+       PackGetStr(p, "ClientHostname", t->ClientHostname, sizeof(t->ClientHostname));\r
+       PackGetStr(p, "ServerHostname", t->ServerHostname, sizeof(t->ServerHostname));\r
+       PackGetStr(p, "ProxyHostname", t->ProxyHostname, sizeof(t->ProxyHostname));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       PackGetData2(p, "UniqueId", t->UniqueId, sizeof(t->UniqueId));\r
+\r
+       t->ClientProductVer = PackGetInt(p, "ClientProductVer");\r
+       t->ClientProductBuild = PackGetInt(p, "ClientProductBuild");\r
+       t->ServerProductVer = PackGetInt(p, "ServerProductVer");\r
+       t->ServerProductBuild = PackGetInt(p, "ServerProductBuild");\r
+       t->ClientIpAddress = PackGetIp32(p, "ClientIpAddress");\r
+       PackGetData2(p, "ClientIpAddress6", t->ClientIpAddress6, sizeof(t->ClientIpAddress6));\r
+       t->ClientPort = PackGetInt(p, "ClientPort");\r
+       t->ServerIpAddress = PackGetIp32(p, "ServerIpAddress");\r
+       PackGetData2(p, "ServerIpAddress6", t->ServerIpAddress6, sizeof(t->ServerIpAddress6));\r
+       t->ServerPort = PackGetInt(p, "ServerPort2");\r
+       t->ProxyIpAddress = PackGetIp32(p, "ProxyIpAddress");\r
+       PackGetData2(p, "ProxyIpAddress6", t->ProxyIpAddress6, sizeof(t->ProxyIpAddress6));\r
+       t->ProxyPort = PackGetInt(p, "ProxyPort");\r
+}\r
+void OutRpcNodeInfo(PACK *p, NODE_INFO *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "ClientProductName", t->ClientProductName);\r
+       PackAddStr(p, "ServerProductName", t->ServerProductName);\r
+       PackAddStr(p, "ClientOsName", t->ClientOsName);\r
+       PackAddStr(p, "ClientOsVer", t->ClientOsVer);\r
+       PackAddStr(p, "ClientOsProductId", t->ClientOsProductId);\r
+       PackAddStr(p, "ClientHostname", t->ClientHostname);\r
+       PackAddStr(p, "ServerHostname", t->ServerHostname);\r
+       PackAddStr(p, "ProxyHostname", t->ProxyHostname);\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddData(p, "UniqueId", t->UniqueId, sizeof(t->UniqueId));\r
+\r
+       PackAddInt(p, "ClientProductVer", t->ClientProductVer);\r
+       PackAddInt(p, "ClientProductBuild", t->ClientProductBuild);\r
+       PackAddInt(p, "ServerProductVer", t->ServerProductVer);\r
+       PackAddInt(p, "ServerProductBuild", t->ServerProductBuild);\r
+       PackAddIp32(p, "ClientIpAddress", t->ClientIpAddress);\r
+       PackAddData(p, "ClientIpAddress6", t->ClientIpAddress6, sizeof(t->ClientIpAddress6));\r
+       PackAddInt(p, "ClientPort", t->ClientPort);\r
+       PackAddIp32(p, "ServerIpAddress", t->ServerIpAddress);\r
+       PackAddData(p, "ServerIpAddress6", t->ServerIpAddress6, sizeof(t->ServerIpAddress6));\r
+       PackAddInt(p, "ServerPort2", t->ServerPort);\r
+       PackAddIp32(p, "ProxyIpAddress", t->ProxyIpAddress);\r
+       PackAddData(p, "ProxyIpAddress6", t->ProxyIpAddress6, sizeof(t->ProxyIpAddress6));\r
+       PackAddInt(p, "ProxyPort", t->ProxyPort);\r
+}\r
+\r
+// RPC_SESSION_STATUS\r
+void InRpcSessionStatus(RPC_SESSION_STATUS *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_SESSION_STATUS));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       PackGetStr(p, "Name", t->Name, sizeof(t->Name));\r
+       PackGetStr(p, "Username", t->Username, sizeof(t->Username));\r
+       PackGetStr(p, "GroupName", t->GroupName, sizeof(t->GroupName));\r
+       PackGetStr(p, "RealUsername", t->RealUsername, sizeof(t->RealUsername));\r
+       t->ClientIp = PackGetIp32(p, "SessionStatus_ClientIp");\r
+       PackGetData2(p, "SessionStatus_ClientIp6", t->ClientIp6, sizeof(t->ClientIp6));\r
+       PackGetStr(p, "SessionStatus_ClientHostName", t->ClientHostName, sizeof(t->ClientHostName));\r
+\r
+       InRpcClientGetConnectionStatus(&t->Status, p);\r
+       InRpcNodeInfo(&t->NodeInfo, p);\r
+}\r
+void OutRpcSessionStatus(PACK *p, RPC_SESSION_STATUS *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddStr(p, "Name", t->Name);\r
+       PackAddStr(p, "Username", t->Username);\r
+       PackAddStr(p, "GroupName", t->GroupName);\r
+       PackAddStr(p, "RealUsername", t->RealUsername);\r
+       PackAddIp32(p, "SessionStatus_ClientIp", t->ClientIp);\r
+       PackAddData(p, "SessionStatus_ClientIp6", t->ClientIp6, sizeof(t->ClientIp6));\r
+       PackAddStr(p, "SessionStatus_ClientHostName", t->ClientHostName);\r
+\r
+       OutRpcClientGetConnectionStatus(p, &t->Status);\r
+       OutRpcNodeInfo(p, &t->NodeInfo);\r
+}\r
+void FreeRpcSessionStatus(RPC_SESSION_STATUS *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CiFreeClientGetConnectionStatus(&t->Status);\r
+}\r
+\r
+// RPC_DELETE_SESSION\r
+void InRpcDeleteSession(RPC_DELETE_SESSION *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_DELETE_SESSION));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       PackGetStr(p, "Name", t->Name, sizeof(t->Name));\r
+}\r
+void OutRpcDeleteSession(PACK *p, RPC_DELETE_SESSION *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddStr(p, "Name", t->Name);\r
+}\r
+\r
+// RPC_ENUM_MAC_TABLE\r
+void InRpcEnumMacTable(RPC_ENUM_MAC_TABLE *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_MAC_TABLE));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->NumMacTable = PackGetIndexCount(p, "SessionName");\r
+       t->MacTables = ZeroMalloc(sizeof(RPC_ENUM_MAC_TABLE_ITEM) * t->NumMacTable);\r
+\r
+       for (i = 0;i < t->NumMacTable;i++)\r
+       {\r
+               RPC_ENUM_MAC_TABLE_ITEM *e = &t->MacTables[i];\r
+\r
+               e->Key = PackGetIntEx(p, "Key", i);\r
+               PackGetStrEx(p, "SessionName", e->SessionName, sizeof(e->SessionName), i);\r
+               PackGetDataEx2(p, "MacAddress", e->MacAddress, sizeof(e->MacAddress), i);\r
+               e->VlanId = PackGetIntEx(p, "VlanId", i);\r
+               e->CreatedTime = PackGetInt64Ex(p, "CreatedTime", i);\r
+               e->UpdatedTime = PackGetInt64Ex(p, "UpdatedTime", i);\r
+               e->RemoteItem = PackGetBoolEx(p, "RemoteItem", i);\r
+               PackGetStrEx(p, "RemoteHostname", e->RemoteHostname, sizeof(e->RemoteHostname), i);\r
+       }\r
+}\r
+void OutRpcEnumMacTable(PACK *p, RPC_ENUM_MAC_TABLE *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+\r
+       for (i = 0;i < t->NumMacTable;i++)\r
+       {\r
+               RPC_ENUM_MAC_TABLE_ITEM *e = &t->MacTables[i];\r
+\r
+               PackAddIntEx(p, "Key", e->Key, i, t->NumMacTable);\r
+               PackAddStrEx(p, "SessionName", e->SessionName, i, t->NumMacTable);\r
+               PackAddDataEx(p, "MacAddress", e->MacAddress, sizeof(e->MacAddress), i, t->NumMacTable);\r
+               PackAddIntEx(p, "VlanId", e->VlanId, i, t->NumMacTable);\r
+               PackAddInt64Ex(p, "CreatedTime", e->CreatedTime, i, t->NumMacTable);\r
+               PackAddInt64Ex(p, "UpdatedTime", e->UpdatedTime, i, t->NumMacTable);\r
+               PackAddBoolEx(p, "RemoteItem", e->RemoteItem, i, t->NumMacTable);\r
+               PackAddStrEx(p, "RemoteHostname", e->RemoteHostname, i, t->NumMacTable);\r
+       }\r
+}\r
+void FreeRpcEnumMacTable(RPC_ENUM_MAC_TABLE *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->MacTables);\r
+}\r
+\r
+// RPC_ENUM_IP_TABLE\r
+void InRpcEnumIpTable(RPC_ENUM_IP_TABLE *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_IP_TABLE));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->NumIpTable = PackGetIndexCount(p, "SessionName");\r
+       t->IpTables = ZeroMalloc(sizeof(RPC_ENUM_IP_TABLE_ITEM) * t->NumIpTable);\r
+\r
+       for (i = 0;i < t->NumIpTable;i++)\r
+       {\r
+               RPC_ENUM_IP_TABLE_ITEM *e = &t->IpTables[i];\r
+\r
+               e->Key = PackGetIntEx(p, "Key", i);\r
+               PackGetStrEx(p, "SessionName", e->SessionName, sizeof(e->SessionName), i);\r
+               e->Ip = PackGetIp32Ex(p, "Ip", i);\r
+               if (PackGetIpEx(p, "IpV6", &e->IpV6, i) == false)\r
+               {\r
+                       UINTToIP(&e->IpV6, e->Ip);\r
+               }\r
+               e->DhcpAllocated = PackGetBoolEx(p, "DhcpAllocated", i);\r
+               e->CreatedTime = PackGetInt64Ex(p, "CreatedTime", i);\r
+               e->UpdatedTime = PackGetInt64Ex(p, "UpdatedTime", i);\r
+               e->RemoteItem = PackGetBoolEx(p, "RemoteItem", i);\r
+               PackGetStrEx(p, "RemoteHostname", e->RemoteHostname, sizeof(e->RemoteHostname), i);\r
+       }\r
+}\r
+void OutRpcEnumIpTable(PACK *p, RPC_ENUM_IP_TABLE *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+\r
+       for (i = 0;i < t->NumIpTable;i++)\r
+       {\r
+               RPC_ENUM_IP_TABLE_ITEM *e = &t->IpTables[i];\r
+\r
+               PackAddIntEx(p, "Key", e->Key, i, t->NumIpTable);\r
+               PackAddStrEx(p, "SessionName", e->SessionName, i, t->NumIpTable);\r
+               PackAddIp32Ex(p, "Ip", e->Ip, i, t->NumIpTable);\r
+               PackAddIpEx(p, "IpV6", &e->IpV6, i, t->NumIpTable);\r
+               PackAddBoolEx(p, "DhcpAllocated", e->DhcpAllocated, i, t->NumIpTable);\r
+               PackAddInt64Ex(p, "CreatedTime", e->CreatedTime, i, t->NumIpTable);\r
+               PackAddInt64Ex(p, "UpdatedTime", e->UpdatedTime, i, t->NumIpTable);\r
+               PackAddBoolEx(p, "RemoteItem", e->RemoteItem, i, t->NumIpTable);\r
+               PackAddStrEx(p, "RemoteHostname", e->RemoteHostname, i, t->NumIpTable);\r
+       }\r
+}\r
+void FreeRpcEnumIpTable(RPC_ENUM_IP_TABLE *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->IpTables);\r
+}\r
+\r
+// RPC_DELETE_TABLE\r
+void InRpcDeleteTable(RPC_DELETE_TABLE *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_DELETE_TABLE));\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->Key = PackGetInt(p, "Key");\r
+}\r
+void OutRpcDeleteTable(PACK *p, RPC_DELETE_TABLE *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddInt(p, "Key", t->Key);\r
+}\r
+\r
+// RPC_ENUM_IP_TABLE の結合\r
+void AdjoinRpcEnumIpTable(RPC_ENUM_IP_TABLE *dest, RPC_ENUM_IP_TABLE *src)\r
+{\r
+       UINT old_num;\r
+       UINT i, n;\r
+       if (dest == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (src->NumIpTable == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       old_num = dest->NumIpTable;\r
+       dest->NumIpTable += src->NumIpTable;\r
+       dest->IpTables = ReAlloc(dest->IpTables, sizeof(RPC_ENUM_IP_TABLE_ITEM) * dest->NumIpTable);\r
+\r
+       n = 0;\r
+       for (i = old_num;i < dest->NumIpTable;i++)\r
+       {\r
+               Copy(&dest->IpTables[i], &src->IpTables[n++], sizeof(RPC_ENUM_IP_TABLE_ITEM));\r
+       }\r
+}\r
+\r
+// RPC_ENUM_MAC_TABLE の結合\r
+void AdjoinRpcEnumMacTable(RPC_ENUM_MAC_TABLE *dest, RPC_ENUM_MAC_TABLE *src)\r
+{\r
+       UINT old_num;\r
+       UINT i, n;\r
+       if (dest == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (src->NumMacTable == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       old_num = dest->NumMacTable;\r
+       dest->NumMacTable += src->NumMacTable;\r
+       dest->MacTables = ReAlloc(dest->MacTables, sizeof(RPC_ENUM_MAC_TABLE_ITEM) * dest->NumMacTable);\r
+\r
+       n = 0;\r
+       for (i = old_num;i < dest->NumMacTable;i++)\r
+       {\r
+               Copy(&dest->MacTables[i], &src->MacTables[n++], sizeof(RPC_ENUM_MAC_TABLE_ITEM));\r
+       }\r
+}\r
+\r
+// RPC_ENUM_SESSION の結合\r
+void AdjoinRpcEnumSession(RPC_ENUM_SESSION *dest, RPC_ENUM_SESSION *src)\r
+{\r
+       UINT old_num;\r
+       UINT i, n;\r
+       if (dest == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (src->NumSession == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       old_num = dest->NumSession;\r
+       dest->NumSession += src->NumSession;\r
+       dest->Sessions = ReAlloc(dest->Sessions, sizeof(RPC_ENUM_SESSION_ITEM) * dest->NumSession);\r
+\r
+       n = 0;\r
+       for (i = old_num;i < dest->NumSession;i++)\r
+       {\r
+               Copy(&dest->Sessions[i], &src->Sessions[n++], sizeof(RPC_ENUM_SESSION_ITEM));\r
+       }\r
+}\r
+\r
+// RPC_KEEP\r
+void InRpcKeep(RPC_KEEP *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_KEEP));\r
+       t->UseKeepConnect = PackGetBool(p, "UseKeepConnect");\r
+       PackGetStr(p, "KeepConnectHost", t->KeepConnectHost, sizeof(t->KeepConnectHost));\r
+       t->KeepConnectPort = PackGetInt(p, "KeepConnectPort");\r
+       t->KeepConnectProtocol = PackGetInt(p, "KeepConnectProtocol");\r
+       t->KeepConnectInterval = PackGetInt(p, "KeepConnectInterval");\r
+}\r
+void OutRpcKeep(PACK *p, RPC_KEEP *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddBool(p, "UseKeepConnect", t->UseKeepConnect);\r
+       PackAddStr(p, "KeepConnectHost", t->KeepConnectHost);\r
+       PackAddInt(p, "KeepConnectPort", t->KeepConnectPort);\r
+       PackAddInt(p, "KeepConnectProtocol", t->KeepConnectProtocol);\r
+       PackAddInt(p, "KeepConnectInterval", t->KeepConnectInterval);\r
+}\r
+\r
+// テスト RPC 関数\r
+UINT StTest(ADMIN *a, RPC_TEST *t)\r
+{\r
+       Format(t->StrValue, sizeof(t->StrValue), "%u", t->IntValue);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// RPC_TEST\r
+void InRpcTest(RPC_TEST *t, PACK *p)\r
+{\r
+       Zero(t, sizeof(RPC_TEST));\r
+       t->IntValue = PackGetInt(p, "IntValue");\r
+       PackGetStr(p, "StrValue", t->StrValue, sizeof(t->StrValue));\r
+}\r
+void OutRpcTest(PACK *p, RPC_TEST *t)\r
+{\r
+       PackAddInt(p, "IntValue", t->IntValue);\r
+       PackAddStr(p, "StrValue", t->StrValue);\r
+}\r
+void FreeRpcTest(RPC_TEST *t)\r
+{\r
+}\r
+\r
+// 管理用呼び出し\r
+PACK *AdminCall(RPC *rpc, char *function_name, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (rpc == NULL || function_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (p == NULL)\r
+       {\r
+               p = NewPack();\r
+       }\r
+\r
+       return RpcCall(rpc, function_name, p);\r
+}\r
+\r
+// 管理用コネクションのソースアドレスが許可されているかどうか調べる\r
+bool CheckAdminSourceAddress(SOCK *sock, char *hubname)\r
+{\r
+       BUF *b;\r
+       char *s;\r
+       bool ok = false;\r
+       // 引数チェック\r
+       if (sock == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = ReadDump(ADMINIP_TXT);\r
+       if (b == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               UINT i;\r
+               TOKEN_LIST *t;\r
+               IP ip;\r
+               s = CfgReadNextLine(b);\r
+\r
+               if (s == NULL)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               Trim(s);\r
+\r
+               i = SearchStrEx(s, "//", 0, false);\r
+               if (i != INFINITE)\r
+               {\r
+                       s[i] = 0;\r
+               }\r
+\r
+               i = SearchStrEx(s, "#", 0, false);\r
+               if (i != INFINITE)\r
+               {\r
+                       s[i] = 0;\r
+               }\r
+\r
+               Trim(s);\r
+\r
+               t = ParseToken(s, " \t");\r
+               if (t != NULL)\r
+               {\r
+                       if (t->NumTokens >= 1)\r
+                       {\r
+                               if (t->NumTokens == 1 || StrCmpi(hubname, t->Token[1]) == 0)\r
+                               {\r
+                                       if (StrToIP(&ip, t->Token[0]))\r
+                                       {\r
+                                               if (CmpIpAddr(&sock->RemoteIP, &ip) == 0)\r
+                                               {\r
+                                                       ok = true;\r
+                                               }\r
+                                       }\r
+\r
+                                       if (StrCmpi(t->Token[0], "*") == 0)\r
+                                       {\r
+                                               ok = true;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       FreeToken(t);\r
+               }\r
+\r
+               Free(s);\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return ok;\r
+}\r
+\r
+// 管理用コネクション受け入れ\r
+UINT AdminAccept(CONNECTION *c, PACK *p)\r
+{\r
+       ADMIN *a;\r
+       UCHAR secure_password[SHA1_SIZE];\r
+       UCHAR null_password[SHA1_SIZE];\r
+       UCHAR secure_null_password[SHA1_SIZE];\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       CEDAR *cedar;\r
+       SOCK *sock;\r
+       RPC *rpc;\r
+       UINT err;\r
+       RPC_WINVER ver;\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       cedar = c->Cedar;\r
+       sock = c->FirstSock;\r
+\r
+       // クライアント OS を取得\r
+       InRpcWinVer(&ver, p);\r
+\r
+       // HUB 名を取得\r
+       if (PackGetStr(p, "hubname", hubname, sizeof(hubname)) == false)\r
+       {\r
+               // HUB 名無し\r
+               StrCpy(hubname, sizeof(hubname), "");\r
+       }\r
+\r
+       // IP アドレスを見て許可するかどうか決める\r
+       if (CheckAdminSourceAddress(sock, hubname) == false)\r
+       {\r
+               SLog(c->Cedar, "LA_IP_DENIED", c->Name);\r
+               return ERR_IP_ADDRESS_DENIED;\r
+       }\r
+\r
+       // パスワードを取得\r
+       if (PackGetDataSize(p, "secure_password") != SHA1_SIZE)\r
+       {\r
+               // プロトコルエラー\r
+               return ERR_PROTOCOL_ERROR;\r
+       }\r
+       PackGetData(p, "secure_password", secure_password);\r
+\r
+       if (StrLen(hubname) == 0)\r
+       {\r
+               // サーバー管理モード接続\r
+               SLog(c->Cedar, "LA_CONNECTED_1", c->Name);\r
+       }\r
+       else\r
+       {\r
+               // 仮想 HUB 管理モード接続\r
+               if (cedar->Server != NULL && cedar->Server->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+               {\r
+                       // クラスタ メンバには仮想 HUB 管理モードで接続することはできない\r
+                       return ERR_NOT_ENOUGH_RIGHT;\r
+               }\r
+               SLog(c->Cedar, "LA_CONNECTED_2", c->Name, hubname);\r
+       }\r
+\r
+       // パスワードチェック\r
+       err = AdminCheckPassword(cedar, c->Random, secure_password,\r
+               StrLen(hubname) != 0 ? hubname : NULL);\r
+\r
+       if (err != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               SLog(c->Cedar, "LA_ERROR", c->Name, GetUniErrorStr(err), err);\r
+               return err;\r
+       }\r
+\r
+       SLog(c->Cedar, "LA_OK", c->Name);\r
+\r
+       HashAdminPassword(null_password, "");\r
+       SecurePassword(secure_null_password, null_password, c->Random);\r
+\r
+       if (Cmp(secure_null_password, secure_password, SHA1_SIZE) == 0)\r
+       {\r
+               if (sock->RemoteIP.addr[0] != 127)\r
+               {\r
+                       // パスワードが空であるがリモート接続しようとした\r
+                       // (仮想 HUB 管理モードのみ)\r
+                       if (StrLen(hubname) != 0)\r
+                       {\r
+                               return ERR_NULL_PASSWORD_LOCAL_ONLY;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // 成功結果を送信\r
+       p = NewPack();\r
+       HttpServerSend(sock, p);\r
+       FreePack(p);\r
+\r
+       // ADMIN 構造体を作成\r
+       a = ZeroMalloc(sizeof(ADMIN));\r
+       a->ServerAdmin = ((StrLen(hubname) == 0) ? true : false);\r
+       a->HubName = (StrLen(hubname) != 0 ? hubname : NULL);\r
+       a->Server = c->Cedar->Server;\r
+       a->ClientBuild = c->ClientBuild;\r
+\r
+       Copy(&a->ClientWinVer, &ver, sizeof(RPC_WINVER));\r
+\r
+       // タイムアウト設定\r
+       SetTimeout(sock, INFINITE);\r
+\r
+       // RPC サーバー\r
+       rpc = StartRpcServer(sock, AdminDispatch, a);\r
+\r
+       a->Rpc = rpc;\r
+\r
+       SLog(c->Cedar, "LA_RPC_START", c->Name, rpc->Name);\r
+\r
+       RpcServer(rpc);\r
+       RpcFree(rpc);\r
+\r
+       if (a->LogFileList != NULL)\r
+       {\r
+               // キャッシュされたログファイル列挙リストがあれば解放する\r
+               FreeEnumLogFile(a->LogFileList);\r
+       }\r
+\r
+       // ADMIN 構造体を解放\r
+       Free(a);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// 管理者パスワードのチェック\r
+UINT AdminCheckPassword(CEDAR *c, void *random, void *secure_password, char *hubname)\r
+{\r
+       UCHAR check[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (c == NULL || random == NULL || secure_password == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       if (hubname == NULL || StrLen(hubname) == 0)\r
+       {\r
+               // サーバー全体の管理モード\r
+               Lock(c->lock);\r
+               {\r
+                       SecurePassword(check, c->Server->HashedPassword, random);\r
+               }\r
+               Unlock(c->lock);\r
+\r
+               if (Cmp(check, secure_password, SHA1_SIZE) != 0)\r
+               {\r
+                       // パスワード相違\r
+                       return ERR_ACCESS_DENIED;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               HUB *h;\r
+\r
+#if    0\r
+               if (c->Server->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+               {\r
+                       // ファームメンバの場合は HUB 管理モードで接続できない\r
+                       return ERR_FARM_MEMBER_HUB_ADMIN;\r
+               }\r
+#endif\r
+\r
+               // HUB 管理モード\r
+               LockHubList(c);\r
+               {\r
+                       h = GetHub(c, hubname);\r
+               }\r
+               UnlockHubList(c);\r
+\r
+               if (h == NULL)\r
+               {\r
+                       // HUB が見つからない\r
+                       return ERR_HUB_NOT_FOUND;\r
+               }\r
+\r
+               Lock(h->lock);\r
+               {\r
+                       SecurePassword(check, h->HashedPassword, random);\r
+               }\r
+               Unlock(h->lock);\r
+\r
+               ReleaseHub(h);\r
+\r
+               if (Cmp(check, secure_password, SHA1_SIZE) != 0)\r
+               {\r
+                       // パスワード相違\r
+                       return ERR_ACCESS_DENIED;\r
+               }\r
+       }\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// 管理者パスワードのハッシュ\r
+void HashAdminPassword(void *hash, char *password)\r
+{\r
+       // 引数チェック\r
+       if (hash == NULL || password == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Hash(hash, password, StrLen(password), true);\r
+}\r
+\r
+// 管理用コネクション切断\r
+void AdminDisconnect(RPC *rpc)\r
+{\r
+       SESSION *s;\r
+       SOCK *sock;\r
+       // 引数チェック\r
+       if (rpc == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = (SESSION *)rpc->Param;\r
+       sock = rpc->Sock;\r
+\r
+       EndRpc(rpc);\r
+\r
+       Disconnect(sock);\r
+       ReleaseSession(s);\r
+}\r
+\r
+// 管理接続メイン\r
+SESSION *AdminConnectMain(CEDAR *cedar, CLIENT_OPTION *o, char *hubname, void *hashed_password, UINT *err, char *client_name, void *hWnd)\r
+{\r
+       UCHAR secure_password[SHA1_SIZE];\r
+       SESSION *s;\r
+       SOCK *sock;\r
+       PACK *p;\r
+       RPC_WINVER ver;\r
+       // 接続\r
+       s = NewRpcSessionEx2(cedar, o, err, client_name, hWnd);\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // ソケット取得\r
+       sock = s->Connection->FirstSock;\r
+\r
+       // 接続メソッド作成\r
+       p = NewPack();\r
+\r
+       PackAddClientVersion(p, s->Connection);\r
+\r
+       PackAddStr(p, "method", "admin");\r
+\r
+       // クライアント Windows バージョン\r
+       GetWinVer(&ver);\r
+       OutRpcWinVer(p, &ver);\r
+\r
+       // セキュアパスワード\r
+       SecurePassword(secure_password, hashed_password, s->Connection->Random);\r
+\r
+       PackAddData(p, "secure_password", secure_password, sizeof(secure_password));\r
+\r
+       // HUB 名\r
+       if (hubname != NULL)\r
+       {\r
+               PackAddStr(p, "hubname", hubname);\r
+       }\r
+\r
+       if (HttpClientSend(sock, p) == false)\r
+       {\r
+               // 切断\r
+               FreePack(p);\r
+               ReleaseSession(s);\r
+               *err = ERR_DISCONNECTED;\r
+               return NULL;\r
+       }\r
+\r
+       FreePack(p);\r
+\r
+       p = HttpClientRecv(sock);\r
+       if (p == NULL)\r
+       {\r
+               // 切断\r
+               ReleaseSession(s);\r
+               *err = ERR_DISCONNECTED;\r
+               return NULL;\r
+       }\r
+\r
+       if (GetErrorFromPack(p) != 0)\r
+       {\r
+               // エラー\r
+               ReleaseSession(s);\r
+               *err = GetErrorFromPack(p);\r
+               FreePack(p);\r
+               return NULL;\r
+       }\r
+\r
+       FreePack(p);\r
+\r
+       return s;\r
+}\r
+\r
+// 管理用コネクション接続\r
+RPC *AdminConnect(CEDAR *cedar, CLIENT_OPTION *o, char *hubname, void *hashed_password, UINT *err)\r
+{\r
+       return AdminConnectEx(cedar, o, hubname, hashed_password, err, NULL);\r
+}\r
+RPC *AdminConnectEx(CEDAR *cedar, CLIENT_OPTION *o, char *hubname, void *hashed_password, UINT *err, char *client_name)\r
+{\r
+       return AdminConnectEx2(cedar, o, hubname, hashed_password, err, client_name, NULL);\r
+}\r
+RPC *AdminConnectEx2(CEDAR *cedar, CLIENT_OPTION *o, char *hubname, void *hashed_password, UINT *err, char *client_name, void *hWnd)\r
+{\r
+       SESSION *s;\r
+       SOCK *sock;\r
+       RPC *rpc;\r
+       // 引数チェック\r
+       if (cedar == NULL || o == NULL || hashed_password == NULL || err == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (client_name == NULL)\r
+       {\r
+               client_name = CEDAR_MANAGER_STR;\r
+       }\r
+\r
+       s = AdminConnectMain(cedar, o, hubname, hashed_password, err, client_name, hWnd);\r
+\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       sock = s->Connection->FirstSock;\r
+\r
+       // RPC 開始\r
+       rpc = StartRpcClient(sock, s);\r
+\r
+       rpc->IsVpnServer = true;\r
+       Copy(&rpc->VpnServerClientOption, o, sizeof(CLIENT_OPTION));\r
+       StrCpy(rpc->VpnServerHubName, sizeof(rpc->VpnServerHubName), hubname);\r
+       Copy(rpc->VpnServerHashedPassword, hashed_password, SHA1_SIZE);\r
+       StrCpy(rpc->VpnServerClientName, sizeof(rpc->VpnServerClientName), client_name);\r
+\r
+       // タイムアウト設定\r
+       SetTimeout(sock, INFINITE);\r
+\r
+       return rpc;\r
+}\r
+\r
+// 再接続\r
+UINT AdminReconnect(RPC *rpc)\r
+{\r
+       SESSION *s;\r
+       SOCK *sock;\r
+       CEDAR *cedar;\r
+       UINT err;\r
+       // 引数チェック\r
+       if (rpc == NULL || rpc->IsVpnServer == false)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       s = (SESSION *)rpc->Param;\r
+       cedar = s->Cedar;\r
+       AddRef(cedar->ref);\r
+\r
+       sock = rpc->Sock;\r
+       Disconnect(sock);\r
+       ReleaseSock(sock);\r
+       ReleaseSession(s);\r
+       rpc->Param = NULL;\r
+\r
+       rpc->Sock = NULL;\r
+\r
+       s = AdminConnectMain(cedar, &rpc->VpnServerClientOption,\r
+               rpc->VpnServerHubName,\r
+               rpc->VpnServerHashedPassword,\r
+               &err,\r
+               rpc->VpnServerClientName, NULL);\r
+\r
+       ReleaseCedar(cedar);\r
+\r
+       if (s == NULL)\r
+       {\r
+               return err;\r
+       }\r
+\r
+       rpc->Param = s;\r
+       rpc->Sock = s->Connection->FirstSock;\r
+       AddRef(rpc->Sock->ref);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Admin.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Admin.h
new file mode 100644 (file)
index 0000000..566f379
--- /dev/null
@@ -0,0 +1,1410 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Admin.h\r
+// Admin.c のヘッダ\r
+\r
+#ifndef        ADMIN_H\r
+#define        ADMIN_H\r
+\r
+// Windows のバージョン\r
+struct RPC_WINVER\r
+{\r
+       bool IsWindows;\r
+       bool IsNT;\r
+       bool IsServer;\r
+       bool IsBeta;\r
+       UINT VerMajor;\r
+       UINT VerMinor;\r
+       UINT Build;\r
+       UINT ServicePack;\r
+       char Title[128];\r
+};\r
+\r
+// サーバー側構造体\r
+struct ADMIN\r
+{\r
+       SERVER *Server;                         // サーバー\r
+       bool ServerAdmin;                       // サーバー Administrator\r
+       char *HubName;                          // 管理することができる HUB 名\r
+       RPC *Rpc;                                       // RPC\r
+       LIST *LogFileList;                      // アクセス可能なログファイルリスト\r
+       UINT ClientBuild;                       // クライアントのビルド番号\r
+       RPC_WINVER ClientWinVer;        // クライアントの Windows のバージョン\r
+};\r
+\r
+// テスト\r
+struct RPC_TEST\r
+{\r
+       UINT IntValue;\r
+       char StrValue[1024];\r
+};\r
+\r
+// サーバー情報 *\r
+struct RPC_SERVER_INFO\r
+{\r
+       char ServerProductName[128];            // サーバー製品名\r
+       char ServerVersionString[128];          // サーバーバージョン文字列\r
+       char ServerBuildInfoString[128];        // サーバービルド情報文字列\r
+       UINT ServerVerInt;                                      // サーバーバージョン整数値\r
+       UINT ServerBuildInt;                            // サーバービルド番号整数値\r
+       char ServerHostName[MAX_HOST_NAME_LEN + 1];     // サーバーホスト名\r
+       UINT ServerType;                                        // サーバーの種類\r
+       OS_INFO OsInfo;                                         // OS 情報\r
+};\r
+\r
+// サーバー状態\r
+struct RPC_SERVER_STATUS\r
+{\r
+       UINT ServerType;                                        // サーバーの種類\r
+       UINT NumTcpConnections;                         // 合計 TCP コネクション数\r
+       UINT NumTcpConnectionsLocal;            // ローカル TCP コネクション数\r
+       UINT NumTcpConnectionsRemote;           // リモート TCP コネクション数\r
+       UINT NumHubTotal;                                       // 合計 HUB 数\r
+       UINT NumHubStandalone;                          // スタンドアロン HUB 数\r
+       UINT NumHubStatic;                                      // スタティック HUB 数\r
+       UINT NumHubDynamic;                                     // ダイナミック HUB 数\r
+       UINT NumSessionsTotal;                          // 合計セッション数\r
+       UINT NumSessionsLocal;                          // ローカルセッション数 (コントローラのみ)\r
+       UINT NumSessionsRemote;                         // リモートセッション数 (コントローラ以外)\r
+       UINT NumMacTables;                                      // MAC テーブル数\r
+       UINT NumIpTables;                                       // IP テーブル数\r
+       UINT NumUsers;                                          // ユーザー数\r
+       UINT NumGroups;                                         // グループ数\r
+       UINT AssignedBridgeLicenses;            // 割り当て済みブリッジライセンス数\r
+       UINT AssignedClientLicenses;            // 割り当て済みクライアントライセンス数\r
+       UINT AssignedBridgeLicensesTotal;       // 割り当て済みブリッジライセンス数 (クラスタ全体)\r
+       UINT AssignedClientLicensesTotal;       // 割り当て済みクライアントライセンス数 (クラスタ全体)\r
+       TRAFFIC Traffic;                                        // トラフィック情報\r
+       UINT64 CurrentTime;                                     // 現在時刻\r
+       UINT64 CurrentTick;                                     // 現在 Tick\r
+       UINT64 StartTime;                                       // 起動時刻\r
+       MEMINFO MemInfo;                                        // メモリ情報\r
+};\r
+\r
+// リスナー\r
+struct RPC_LISTENER\r
+{\r
+       UINT Port;                                                      // ポート番号\r
+       bool Enable;                                            // 有効状態\r
+};\r
+\r
+// リスナーのリスト*\r
+struct RPC_LISTENER_LIST\r
+{\r
+       UINT NumPort;                                           // ポート数\r
+       UINT *Ports;                                            // ポート一覧\r
+       bool *Enables;                                          // 有効状態\r
+       bool *Errors;                                           // エラー発生\r
+};\r
+\r
+// 文字列*\r
+struct RPC_STR\r
+{\r
+       char *String;                                           // 文字列\r
+};\r
+\r
+// 整数\r
+struct RPC_INT\r
+{\r
+       UINT IntValue;                                          // 整数\r
+};\r
+\r
+// パスワードの設定\r
+struct RPC_SET_PASSWORD\r
+{\r
+       UCHAR HashedPassword[SHA1_SIZE];        // ハッシュされたパスワード\r
+};\r
+\r
+// サーバーファーム設定*\r
+struct RPC_FARM\r
+{\r
+       UINT ServerType;                                        // サーバーの種類\r
+       UINT NumPort;                                           // 公開ポート数\r
+       UINT *Ports;                                            // 公開ポート一覧\r
+       UINT PublicIp;                                          // 公開 IP\r
+       char ControllerName[MAX_HOST_NAME_LEN + 1];     // コントローラ名\r
+       UINT ControllerPort;                            // コントローラポート\r
+       UCHAR MemberPassword[SHA1_SIZE];        // メンバパスワード\r
+       UINT Weight;                                            // 性能基準比\r
+       bool ControllerOnly;                            // コントローラ機能のみ\r
+};\r
+\r
+// ファームメンバごとの HUB アイテム\r
+struct RPC_FARM_HUB\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       bool DynamicHub;                                        // ダイナミック HUB\r
+};\r
+\r
+// サーバーファームメンバ情報取得*\r
+struct RPC_FARM_INFO\r
+{\r
+       UINT Id;                                                        // ID\r
+       bool Controller;                                        // コントローラ\r
+       UINT64 ConnectedTime;                           // 接続時刻\r
+       UINT Ip;                                                        // IP アドレス\r
+       char Hostname[MAX_HOST_NAME_LEN + 1];   // ホスト名\r
+       UINT Point;                                                     // ポイント\r
+       UINT NumPort;                                           // ポート数\r
+       UINT *Ports;                                            // ポート\r
+       X *ServerCert;                                          // サーバー証明書\r
+       UINT NumFarmHub;                                        // ファーム HUB 数\r
+       RPC_FARM_HUB *FarmHubs;                         // ファーム HUB\r
+       UINT NumSessions;                                       // セッション数\r
+       UINT NumTcpConnections;                         // TCP コネクション数\r
+       UINT Weight;                                            // 性能基準比\r
+};\r
+\r
+// サーバーファームメンバ列挙項目\r
+struct RPC_ENUM_FARM_ITEM\r
+{\r
+       UINT Id;                                                        // ID\r
+       bool Controller;                                        // コントローラ\r
+       UINT64 ConnectedTime;                           // 接続時刻\r
+       UINT Ip;                                                        // IP アドレス\r
+       char Hostname[MAX_HOST_NAME_LEN + 1];   // ホスト名\r
+       UINT Point;                                                     // ポイント\r
+       UINT NumSessions;                                       // セッション数\r
+       UINT NumTcpConnections;                         // TCP コネクション数\r
+       UINT NumHubs;                                           // HUB 数\r
+       UINT AssignedClientLicense;                     // 割り当て済みクライアントライセンス数\r
+       UINT AssignedBridgeLicense;                     // 割り当て済みブリッジライセンス数\r
+};\r
+\r
+// サーバーファームメンバ列挙*\r
+struct RPC_ENUM_FARM\r
+{\r
+       UINT NumFarm;                                           // ファーム数\r
+       RPC_ENUM_FARM_ITEM *Farms;                      // ファーム一覧\r
+};\r
+\r
+// コントローラへの接続状態\r
+struct RPC_FARM_CONNECTION_STATUS\r
+{\r
+       UINT Ip;                                                        // IP アドレス\r
+       UINT Port;                                                      // ポート番号\r
+       bool Online;                                            // オンライン状態\r
+       UINT LastError;                                         // 最終エラー\r
+       UINT64 StartedTime;                                     // 接続開始時刻\r
+       UINT64 FirstConnectedTime;                      // 最初の接続時刻\r
+       UINT64 CurrentConnectedTime;            // 今回の接続時刻\r
+       UINT NumTry;                                            // 試行回数\r
+       UINT NumConnected;                                      // 接続回数\r
+       UINT NumFailed;                                         // 接続失敗回数\r
+};\r
+\r
+// キーペア\r
+struct RPC_KEY_PAIR\r
+{\r
+       X *Cert;                                                        // 証明書\r
+       K *Key;                                                         // 秘密鍵\r
+};\r
+\r
+// HUB オプション\r
+struct RPC_HUB_OPTION\r
+{\r
+       UINT MaxSession;                                        // 最大セッション数\r
+       bool NoEnum;                                            // 列挙しない\r
+};\r
+\r
+// Radius サーバーオプション\r
+struct RPC_RADIUS\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       char RadiusServerName[MAX_HOST_NAME_LEN + 1];   // Radius サーバー名\r
+       UINT RadiusPort;                                        // Radius ポート番号\r
+       char RadiusSecret[MAX_PASSWORD_LEN + 1];        // 秘密鍵\r
+       UINT RadiusRetryInterval;                       // Radius 再試行間隔\r
+};\r
+\r
+// HUB の指定\r
+struct RPC_HUB\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+};\r
+\r
+// HUB の作成\r
+struct RPC_CREATE_HUB\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       UCHAR HashedPassword[SHA1_SIZE];        // 管理用パスワード\r
+       UCHAR SecurePassword[SHA1_SIZE];        // Administrator パスワード\r
+       bool Online;                                            // オンラインフラグ\r
+       RPC_HUB_OPTION HubOption;                       // HUB オプション\r
+       UINT HubType;                                           // HUB の種類\r
+};\r
+\r
+// HUB の列挙項目\r
+struct RPC_ENUM_HUB_ITEM\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       bool Online;                                            // オンライン\r
+       UINT HubType;                                           // HUB の種類\r
+       UINT NumUsers;                                          // ユーザー数\r
+       UINT NumGroups;                                         // グループ数\r
+       UINT NumSessions;                                       // セッション数\r
+       UINT NumMacTables;                                      // MAC テーブル数\r
+       UINT NumIpTables;                                       // IP テーブル数\r
+       UINT64 LastCommTime;                            // 最終通信日時\r
+       UINT64 LastLoginTime;                           // 最終ログイン日時\r
+       UINT64 CreatedTime;                                     // 作成日時\r
+       UINT NumLogin;                                          // ログイン回数\r
+};\r
+\r
+// HUB の列挙*\r
+struct RPC_ENUM_HUB\r
+{\r
+       UINT NumHub;                                            // HUB 数\r
+       RPC_ENUM_HUB_ITEM *Hubs;                        // HUB\r
+};\r
+\r
+// HUB の削除\r
+struct RPC_DELETE_HUB\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+};\r
+\r
+// コネクション列挙項目\r
+struct RPC_ENUM_CONNECTION_ITEM\r
+{\r
+       char Name[MAX_SIZE];                            // コネクション名\r
+       char Hostname[MAX_SIZE];                        // ホスト名\r
+       UINT Ip;                                                        // IP アドレス\r
+       UINT Port;                                                      // ポート番号\r
+       UINT64 ConnectedTime;                           // 接続された時刻\r
+       UINT Type;                                                      // 種類\r
+};\r
+\r
+// コネクション列挙\r
+struct RPC_ENUM_CONNECTION\r
+{\r
+       UINT NumConnection;                                     // コネクション数\r
+       RPC_ENUM_CONNECTION_ITEM *Connections;  // コネクション一覧\r
+};\r
+\r
+// コネクション切断\r
+struct RPC_DISCONNECT_CONNECTION\r
+{\r
+       char Name[MAX_SIZE];                            // コネクション名\r
+};\r
+\r
+// コネクション情報\r
+struct RPC_CONNECTION_INFO\r
+{\r
+       char Name[MAX_SIZE];                            // コネクション名\r
+       UINT Type;                                                      // 種類\r
+       char Hostname[MAX_SIZE];                        // ホスト名\r
+       UINT Ip;                                                        // IP アドレス\r
+       UINT Port;                                                      // ポート番号\r
+       UINT64 ConnectedTime;                           // 接続された時刻\r
+       char ServerStr[MAX_SERVER_STR_LEN + 1]; // サーバー文字列\r
+       UINT ServerVer;                                         // サーバーバージョン\r
+       UINT ServerBuild;                                       // サーバービルド番号\r
+       char ClientStr[MAX_CLIENT_STR_LEN + 1]; // クライアント文字列\r
+       UINT ClientVer;                                         // クライアントバージョン\r
+       UINT ClientBuild;                                       // クライアントビルド番号\r
+};\r
+\r
+// HUB をオンラインまたはオフラインにする\r
+struct RPC_SET_HUB_ONLINE\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       bool Online;                                            // オンライン・オフラインフラグ\r
+};\r
+\r
+// HUB 状態の取得\r
+struct RPC_HUB_STATUS\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       bool Online;                                            // オンライン\r
+       UINT HubType;                                           // HUB の種類\r
+       UINT NumSessions;                                       // セッション数\r
+       UINT NumSessionsClient;                         // セッション数 (クライアント)\r
+       UINT NumSessionsBridge;                         // セッション数 (ブリッジ)\r
+       UINT NumAccessLists;                            // アクセスリスト数\r
+       UINT NumUsers;                                          // ユーザー数\r
+       UINT NumGroups;                                         // グループ数\r
+       UINT NumMacTables;                                      // MAC テーブル数\r
+       UINT NumIpTables;                                       // IP テーブル数\r
+       TRAFFIC Traffic;                                        // トラフィック\r
+       bool SecureNATEnabled;                          // SecureNAT が有効かどうか\r
+       UINT64 LastCommTime;                            // 最終通信日時\r
+       UINT64 LastLoginTime;                           // 最終ログイン日時\r
+       UINT64 CreatedTime;                                     // 作成日時\r
+       UINT NumLogin;                                          // ログイン回数\r
+};\r
+\r
+// HUB ログ設定\r
+struct RPC_HUB_LOG\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       HUB_LOG LogSetting;                                     // ログ設定\r
+};\r
+\r
+// HUB への CA 追加*\r
+struct RPC_HUB_ADD_CA\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       X *Cert;                                                        // 証明書\r
+};\r
+\r
+// HUB の CA 列挙項目\r
+struct RPC_HUB_ENUM_CA_ITEM\r
+{\r
+       UINT Key;                                                               // 証明書キー\r
+       wchar_t SubjectName[MAX_SIZE];                  // 発行先\r
+       wchar_t IssuerName[MAX_SIZE];                   // 発行者\r
+       UINT64 Expires;                                                 // 有効期限\r
+};\r
+\r
+// HUB の CA 列挙*\r
+struct RPC_HUB_ENUM_CA\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       UINT NumCa;                                                             // CA 数\r
+       RPC_HUB_ENUM_CA_ITEM *Ca;                               // CA\r
+};\r
+\r
+// HUB の CA の取得*\r
+struct RPC_HUB_GET_CA\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       UINT Key;                                                       // 証明書キー\r
+       X *Cert;                                                        // 証明書\r
+};\r
+\r
+// HUB の CA の削除\r
+struct RPC_HUB_DELETE_CA\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       UINT Key;                                                       // 削除する証明書キー\r
+};\r
+\r
+// リンクの作成・設定*\r
+struct RPC_CREATE_LINK\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       bool Online;                                            // オンラインフラグ\r
+       CLIENT_OPTION *ClientOption;            // クライアントオプション\r
+       CLIENT_AUTH *ClientAuth;                        // クライアント認証データ\r
+       POLICY Policy;                                          // ポリシー\r
+       bool CheckServerCert;                           // サーバー証明書を検証する\r
+       X *ServerCert;                                          // サーバー証明書\r
+};\r
+\r
+// リンクの列挙項目\r
+struct RPC_ENUM_LINK_ITEM\r
+{\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];  // アカウント名\r
+       bool Online;                                                                    // オンラインフラグ\r
+       bool Connected;                                                                 // 接続完了フラグ\r
+       UINT LastError;                                                                 // 最後に発生したエラー\r
+       UINT64 ConnectedTime;                                                   // 接続完了時刻\r
+       char Hostname[MAX_HOST_NAME_LEN + 1];                   // ホスト名\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+};\r
+\r
+// リンクの列挙*\r
+struct RPC_ENUM_LINK\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       UINT NumLink;                                                                   // リンク数\r
+       RPC_ENUM_LINK_ITEM *Links;                                              // リンク一覧\r
+};\r
+\r
+// リンク状態の取得*\r
+struct RPC_LINK_STATUS\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];  // アカウント名\r
+       RPC_CLIENT_GET_CONNECTION_STATUS Status;                // ステータス\r
+};\r
+\r
+// リンクの指定\r
+struct RPC_LINK\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];  // アカウント名\r
+};\r
+\r
+// リンクの名前変更\r
+struct RPC_RENAME_LINK\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       wchar_t OldAccountName[MAX_ACCOUNT_NAME_LEN + 1];       // 古いアカウント名\r
+       wchar_t NewAccountName[MAX_ACCOUNT_NAME_LEN + 1];       // 新しいアカウント名\r
+};\r
+\r
+// アクセスリストの列挙*\r
+struct RPC_ENUM_ACCESS_LIST\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       UINT NumAccess;                                                                 // アクセスリスト数\r
+       ACCESS *Accesses;                                                               // アクセスリスト\r
+};\r
+\r
+// アクセスリストの追加\r
+struct RPC_ADD_ACCESS\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       ACCESS Access;                                                                  // アクセスリスト\r
+};\r
+\r
+// アクセスリストの削除\r
+struct RPC_DELETE_ACCESS\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       UINT Id;                                                                                // ID\r
+};\r
+\r
+// ユーザーの作成・設定・取得*\r
+struct RPC_SET_USER\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       char Name[MAX_USERNAME_LEN + 1];                                // ユーザー名\r
+       char GroupName[MAX_USERNAME_LEN + 1];                   // グループ名\r
+       wchar_t Realname[MAX_SIZE];                                             // 本名\r
+       wchar_t Note[MAX_SIZE];                                                 // メモ\r
+       UINT64 CreatedTime;                                                             // 作成日時\r
+       UINT64 UpdatedTime;                                                             // 更新日時\r
+       UINT64 ExpireTime;                                                              // 有効期限\r
+       UINT AuthType;                                                                  // 認証方法\r
+       void *AuthData;                                                                 // 認証データ\r
+       UINT NumLogin;                                                                  // ログイン回数\r
+       TRAFFIC Traffic;                                                                // トラフィックデータ\r
+       POLICY *Policy;                                                                 // ポリシー\r
+};\r
+\r
+// ユーザーの列挙項目\r
+struct RPC_ENUM_USER_ITEM\r
+{\r
+       char Name[MAX_USERNAME_LEN + 1];                                // ユーザー名\r
+       char GroupName[MAX_USERNAME_LEN + 1];                   // グループ名\r
+       wchar_t Realname[MAX_SIZE];                                             // 本名\r
+       wchar_t Note[MAX_SIZE];                                                 // メモ\r
+       UINT AuthType;                                                                  // 認証方法\r
+       UINT NumLogin;                                                                  // ログイン回数\r
+       UINT64 LastLoginTime;                                                   // 最終ログイン日時\r
+       bool DenyAccess;                                                                // アクセス拒否\r
+};\r
+\r
+// ユーザーの列挙\r
+struct RPC_ENUM_USER\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       UINT NumUser;                                                                   // ユーザー数\r
+       RPC_ENUM_USER_ITEM *Users;                                              // ユーザー\r
+};\r
+\r
+// グループの作成・設定・取得*\r
+struct RPC_SET_GROUP\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       char Name[MAX_USERNAME_LEN + 1];                                // ユーザー名\r
+       wchar_t Realname[MAX_SIZE];                                             // 本名\r
+       wchar_t Note[MAX_SIZE];                                                 // メモ\r
+       TRAFFIC Traffic;                                                                // トラフィックデータ\r
+       POLICY *Policy;                                                                 // ポリシー\r
+};\r
+\r
+// グループの列挙項目\r
+struct RPC_ENUM_GROUP_ITEM\r
+{\r
+       char Name[MAX_USERNAME_LEN + 1];                                // ユーザー名\r
+       wchar_t Realname[MAX_SIZE];                                             // 本名\r
+       wchar_t Note[MAX_SIZE];                                                 // メモ\r
+       UINT NumUsers;                                                                  // ユーザー数\r
+       bool DenyAccess;                                                                // アクセス拒否\r
+};\r
+\r
+// グループの列挙\r
+struct RPC_ENUM_GROUP\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       UINT NumGroup;                                                                  // グループ数\r
+       RPC_ENUM_GROUP_ITEM *Groups;                                    // グループ\r
+};\r
+\r
+// ユーザーまたはグループの削除\r
+struct RPC_DELETE_USER\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       char Name[MAX_USERNAME_LEN + 1];                                // ユーザー名またはグループ名\r
+};\r
+\r
+// セッションの列挙項目\r
+struct RPC_ENUM_SESSION_ITEM\r
+{\r
+       char Name[MAX_SESSION_NAME_LEN + 1];                    // セッション名\r
+       bool RemoteSession;                                                             // リモートセッション\r
+       char RemoteHostname[MAX_HOST_NAME_LEN + 1];             // リモートサーバー名\r
+       char Username[MAX_USERNAME_LEN + 1];                    // ユーザー名\r
+       UINT Ip;                                                                                // IP アドレス (IPv4)\r
+       char Hostname[MAX_HOST_NAME_LEN + 1];                   // ホスト名\r
+       UINT MaxNumTcp;                                                                 // TCP コネクション数最大\r
+       UINT CurrentNumTcp;                                                             // TCP コネクション数現在\r
+       UINT64 PacketSize;                                                              // パケットサイズ\r
+       UINT64 PacketNum;                                                               // パケット数\r
+       bool LinkMode;                                                                  // リンクモード\r
+       bool SecureNATMode;                                                             // SecureNAT モード\r
+       bool BridgeMode;                                                                // ブリッジモード\r
+       bool Layer3Mode;                                                                // レイヤ 3 モード\r
+       bool Client_BridgeMode;                                                 // クライアントがブリッジモード\r
+       bool Client_MonitorMode;                                                // クライアントがモニタリングモード\r
+       UINT VLanId;                                                                    // VLAN ID\r
+       UCHAR UniqueId[16];                                                             // Unique ID\r
+};\r
+\r
+// セッションの切断\r
+struct RPC_DELETE_SESSION\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       char Name[MAX_SESSION_NAME_LEN + 1];                    // セッション名\r
+};\r
+\r
+// MAC テーブルの列挙項目\r
+struct RPC_ENUM_MAC_TABLE_ITEM\r
+{\r
+       UINT Key;                                                                               // キー\r
+       char SessionName[MAX_SESSION_NAME_LEN + 1];             // セッション名\r
+       UCHAR MacAddress[6];                                                    // MAC アドレス\r
+       UCHAR Padding[2];\r
+       UINT64 CreatedTime;                                                             // 作成日時\r
+       UINT64 UpdatedTime;                                                             // 更新日時\r
+       bool RemoteItem;                                                                // リモートアイテム\r
+       char RemoteHostname[MAX_HOST_NAME_LEN + 1];             // リモートホスト名\r
+       UINT VlanId;                                                                    // VLAN ID\r
+};\r
+\r
+// MAC テーブルの列挙\r
+struct RPC_ENUM_MAC_TABLE\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       UINT NumMacTable;                                                               // テーブル数\r
+       RPC_ENUM_MAC_TABLE_ITEM *MacTables;                             // MAC テーブル\r
+};\r
+\r
+// IP テーブルの列挙項目\r
+struct RPC_ENUM_IP_TABLE_ITEM\r
+{\r
+       UINT Key;                                                                               // キー\r
+       char SessionName[MAX_SESSION_NAME_LEN + 1];             // セッション名\r
+       UINT Ip;                                                                                // IP アドレス\r
+       IP IpV6;                                                                                // IPv6 アドレス\r
+       bool DhcpAllocated;                                                             // DHCP によって割り当て済み\r
+       UINT64 CreatedTime;                                                             // 作成日時\r
+       UINT64 UpdatedTime;                                                             // 更新日時\r
+       bool RemoteItem;                                                                // リモートアイテム\r
+       char RemoteHostname[MAX_HOST_NAME_LEN + 1];             // リモートホスト名\r
+};\r
+\r
+// IP テーブルの列挙\r
+struct RPC_ENUM_IP_TABLE\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       UINT NumIpTable;                                                                // テーブル数\r
+       RPC_ENUM_IP_TABLE_ITEM *IpTables;                               // MAC テーブル\r
+};\r
+\r
+// テーブルの削除\r
+struct RPC_DELETE_TABLE\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       UINT Key;                                                                               // キー\r
+};\r
+\r
+// KEEP 設定\r
+struct RPC_KEEP\r
+{\r
+       bool UseKeepConnect;                                    // インターネットへの接続を維持\r
+       char KeepConnectHost[MAX_HOST_NAME_LEN + 1];    // ホスト名\r
+       UINT KeepConnectPort;                                   // ポート番号\r
+       UINT KeepConnectProtocol;                               // プロトコル\r
+       UINT KeepConnectInterval;                               // 間隔\r
+};\r
+\r
+// Ethernet 列挙アイテム\r
+struct RPC_ENUM_ETH_ITEM\r
+{\r
+       char DeviceName[MAX_SIZE];                              // デバイス名\r
+       wchar_t NetworkConnectionName[MAX_SIZE];// ネットワーク接続名\r
+};\r
+\r
+// Ethernet 列挙\r
+struct RPC_ENUM_ETH\r
+{\r
+       UINT NumItem;                                                   // アイテム数\r
+       RPC_ENUM_ETH_ITEM *Items;                               // アイテム\r
+};\r
+\r
+// ブリッジ項目\r
+struct RPC_LOCALBRIDGE\r
+{\r
+       char DeviceName[MAX_SIZE];                              // デバイス名\r
+       char HubName[MAX_HUBNAME_LEN + 1];              // HUB 名\r
+       bool Online;                                                    // オンラインフラグ\r
+       bool Active;                                                    // 動作フラグ\r
+       bool TapMode;                                                   // tap モード\r
+};\r
+\r
+// ブリッジ列挙\r
+struct RPC_ENUM_LOCALBRIDGE\r
+{\r
+       UINT NumItem;                                                   // アイテム数\r
+       RPC_LOCALBRIDGE *Items;                                 // アイテム\r
+};\r
+\r
+// ブリッジサポート情報\r
+struct RPC_BRIDGE_SUPPORT\r
+{\r
+       bool IsBridgeSupportedOs;                               // ブリッジがサポートされている OS か\r
+       bool IsWinPcapNeeded;                                   // WinPcap が必要とされているか\r
+};\r
+\r
+// config 操作\r
+struct RPC_CONFIG\r
+{\r
+       char FileName[MAX_PATH];                                // ファイル名\r
+       char *FileData;                                                 // ファイルデータ\r
+};\r
+\r
+// 管理オプションリスト\r
+struct RPC_ADMIN_OPTION\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];              // 仮想 HUB 名\r
+       UINT NumItem;                                                   // 個数\r
+       ADMIN_OPTION *Items;                                    // データ\r
+};\r
+\r
+// Layer-3 スイッチ\r
+struct RPC_L3SW\r
+{\r
+       char Name[MAX_HUBNAME_LEN + 1];                 // L3 スイッチ名\r
+};\r
+\r
+// Layer-3 スイッチ列挙\r
+struct RPC_ENUM_L3SW_ITEM\r
+{\r
+       char Name[MAX_HUBNAME_LEN + 1];                 // 名前\r
+       UINT NumInterfaces;                                             // インターフェイス数\r
+       UINT NumTables;                                                 // ルーティングテーブル数\r
+       bool Active;                                                    // 動作中\r
+       bool Online;                                                    // オンライン\r
+};\r
+struct RPC_ENUM_L3SW\r
+{\r
+       UINT NumItem;\r
+       RPC_ENUM_L3SW_ITEM *Items;\r
+};\r
+\r
+// Layer-3 インターフェイス\r
+struct RPC_L3IF\r
+{\r
+       char Name[MAX_HUBNAME_LEN + 1];                 // L3 スイッチ名\r
+       char HubName[MAX_HUBNAME_LEN + 1];              // 仮想 HUB 名\r
+       UINT IpAddress;                                                 // IP アドレス\r
+       UINT SubnetMask;                                                // サブネットマスク\r
+};\r
+\r
+// Layer-3 インターフェイス列挙\r
+struct RPC_ENUM_L3IF\r
+{\r
+       char Name[MAX_HUBNAME_LEN + 1];                 // L3 スイッチ名\r
+       UINT NumItem;\r
+       RPC_L3IF *Items;\r
+};\r
+\r
+// ルーティングテーブル\r
+struct RPC_L3TABLE\r
+{\r
+       char Name[MAX_HUBNAME_LEN + 1];                 // L3 スイッチ名\r
+       UINT NetworkAddress;                                    // ネットワークアドレス\r
+       UINT SubnetMask;                                                // サブネットマスク\r
+       UINT GatewayAddress;                                    // ゲートウェイアドレス\r
+       UINT Metric;                                                    // メトリック\r
+};\r
+\r
+// ルーティングテーブル列挙\r
+struct RPC_ENUM_L3TABLE\r
+{\r
+       char Name[MAX_HUBNAME_LEN + 1];                 // L3 スイッチ名\r
+       UINT NumItem;\r
+       RPC_L3TABLE *Items;\r
+};\r
+\r
+// CRL エントリ\r
+struct RPC_CRL\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];              // HUB 名\r
+       UINT Key;                                                               // キー\r
+       CRL *Crl;                                                               // CRL 本体\r
+};\r
+\r
+// CRL 列挙\r
+struct RPC_ENUM_CRL_ITEM\r
+{\r
+       UINT Key;                                                               // キー\r
+       wchar_t CrlInfo[MAX_SIZE];                              // 情報\r
+};\r
+struct RPC_ENUM_CRL\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];              // HUB 名\r
+       UINT NumItem;                                                   // アイテム数\r
+       RPC_ENUM_CRL_ITEM *Items;                               // リスト\r
+};\r
+\r
+// AC リスト\r
+struct RPC_AC_LIST\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];              // HUB 名\r
+       LIST *o;                                                                // リスト本体\r
+};\r
+\r
+// ログファイル列挙\r
+struct RPC_ENUM_LOG_FILE_ITEM\r
+{\r
+       char ServerName[MAX_HOST_NAME_LEN + 1]; // サーバー名\r
+       char FilePath[MAX_PATH];                                // ファイルパス\r
+       UINT FileSize;                                                  // ファイルサイズ\r
+       UINT64 UpdatedTime;                                             // 更新日時\r
+};\r
+struct RPC_ENUM_LOG_FILE\r
+{\r
+       UINT NumItem;                                                   // アイテム数\r
+       RPC_ENUM_LOG_FILE_ITEM *Items;                  // リスト\r
+};\r
+\r
+// ログファイル読み込み\r
+struct RPC_READ_LOG_FILE\r
+{\r
+       char ServerName[MAX_HOST_NAME_LEN + 1]; // サーバー名\r
+       char FilePath[MAX_PATH];                                // ファイルパス\r
+       UINT Offset;                                                    // オフセット\r
+       BUF *Buffer;                                                    // バッファ\r
+};\r
+\r
+// ダウンロード情報\r
+struct DOWNLOAD_PROGRESS\r
+{\r
+       void *Param;                                                    // ユーザー定義データ\r
+       UINT TotalSize;                                                 // 合計ファイルサイズ\r
+       UINT CurrentSize;                                               // 読み込みが完了したサイズ\r
+       UINT ProgressPercent;                                   // 完了パーセント\r
+};\r
+\r
+// ライセンスキーの列挙\r
+struct RPC_ENUM_LICENSE_KEY_ITEM\r
+{\r
+       UINT Id;                                                                // ID\r
+       char LicenseKey[LICENSE_KEYSTR_LEN + 1];        // ライセンスキー\r
+       char LicenseId[LICENSE_LICENSEID_STR_LEN + 1];  // ライセンス ID\r
+       char LicenseName[LICENSE_MAX_PRODUCT_NAME_LEN + 1];     // ライセンス名\r
+       UINT64 Expires;                                                 // 有効期限\r
+       UINT Status;                                                    // 状況\r
+       UINT ProductId;                                                 // 製品 ID\r
+       UINT64 SystemId;                                                // システム ID\r
+       UINT SerialId;                                                  // シリアル ID\r
+};\r
+struct RPC_ENUM_LICENSE_KEY\r
+{\r
+       UINT NumItem;                                                   // アイテム数\r
+       RPC_ENUM_LICENSE_KEY_ITEM *Items;               // リスト\r
+};\r
+\r
+// サーバーのライセンスの状態\r
+struct RPC_LICENSE_STATUS\r
+{\r
+       UINT EditionId;                                                 // エディション ID\r
+       char EditionStr[LICENSE_MAX_PRODUCT_NAME_LEN + 1];      // エディション名\r
+       UINT64 SystemId;                                                // システム ID\r
+       UINT64 SystemExpires;                                   // システム有効期限\r
+       UINT NumClientConnectLicense;                   // クライアント同時接続可能数\r
+       UINT NumBridgeConnectLicense;                   // ブリッジ同時接続可能数\r
+\r
+       // v3.0\r
+       bool NeedSubscription;                                  // サブスクリプション制度が有効かどうか\r
+       UINT64 SubscriptionExpires;                             // サブスクリプション有効期限\r
+       bool IsSubscriptionExpired;                             // サブスクリプション有効期限が切れているかどうか\r
+       UINT NumUserCreationLicense;                    // ユーザー作成可能数\r
+       bool AllowEnterpriseFunction;                   // エンタープライズ機能の動作\r
+       UINT64 ReleaseDate;                                             // リリース日付\r
+};\r
+\r
+// 物理 LAN カードの VLAN 対応状況の列挙\r
+struct RPC_ENUM_ETH_VLAN_ITEM\r
+{\r
+       char DeviceName[MAX_SIZE];                              // デバイス名\r
+       char Guid[MAX_SIZE];                                    // GUID\r
+       char DeviceInstanceId[MAX_SIZE];                // デバイスインスタンス ID\r
+       char DriverName[MAX_SIZE];                              // ドライバファイル名\r
+       char DriverType[MAX_SIZE];                              // ドライバの種類\r
+       bool Support;                                                   // サポートしているかどうか\r
+       bool Enabled;                                                   // 有効化されているかどうか\r
+};\r
+struct RPC_ENUM_ETH_VLAN\r
+{\r
+       UINT NumItem;                                                   // アイテム数\r
+       RPC_ENUM_ETH_VLAN_ITEM *Items;                  // リスト\r
+};\r
+\r
+// メッセージ\r
+struct RPC_MSG\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];              // HUB 名\r
+       wchar_t *Msg;                                                   // メッセージ\r
+};\r
+\r
+\r
+// 関数プロトタイプ\r
+UINT AdminAccept(CONNECTION *c, PACK *p);\r
+void HashAdminPassword(void *hash, char *password);\r
+SESSION *AdminConnectMain(CEDAR *cedar, CLIENT_OPTION *o, char *hubname, void *hashed_password, UINT *err, char *client_name, void *hWnd);\r
+RPC *AdminConnect(CEDAR *cedar, CLIENT_OPTION *o, char *hubname, void *hashed_password, UINT *err);\r
+RPC *AdminConnectEx(CEDAR *cedar, CLIENT_OPTION *o, char *hubname, void *hashed_password, UINT *err, char *client_name);\r
+RPC *AdminConnectEx2(CEDAR *cedar, CLIENT_OPTION *o, char *hubname, void *hashed_password, UINT *err, char *client_name, void *hWnd);\r
+void AdminDisconnect(RPC *rpc);\r
+UINT AdminReconnect(RPC *rpc);\r
+UINT AdminCheckPassword(CEDAR *c, void *random, void *secure_password, char *hubname);\r
+PACK *AdminDispatch(RPC *rpc, char *name, PACK *p);\r
+PACK *AdminCall(RPC *rpc, char *function_name, PACK *p);\r
+void SiEnumLocalSession(SERVER *s, char *hubname, RPC_ENUM_SESSION *t);\r
+void CopyOsInfo(OS_INFO *dst, OS_INFO *info);\r
+CAPSLIST *ScGetCapsEx(RPC *rpc);\r
+UINT SiEnumMacTable(SERVER *s, char *hubname, RPC_ENUM_MAC_TABLE *t);\r
+UINT SiEnumIpTable(SERVER *s, char *hubname, RPC_ENUM_IP_TABLE *t);\r
+void SiEnumLocalLogFileList(SERVER *s, char *hubname, RPC_ENUM_LOG_FILE *t);\r
+void SiReadLocalLogFile(SERVER *s, char *filepath, UINT offset, RPC_READ_LOG_FILE *t);\r
+typedef bool (DOWNLOAD_PROC)(DOWNLOAD_PROGRESS *progress);\r
+BUF *DownloadFileFromServer(RPC *r, char *server_name, char *filepath, UINT total_size, DOWNLOAD_PROC *proc, void *param);\r
+bool CheckAdminSourceAddress(SOCK *sock, char *hubname);\r
+void SiEnumSessionMain(SERVER *s, RPC_ENUM_SESSION *t);\r
+\r
+UINT StTest(ADMIN *a, RPC_TEST *t);\r
+UINT StGetServerInfo(ADMIN *a, RPC_SERVER_INFO *t);\r
+UINT StGetServerStatus(ADMIN *a, RPC_SERVER_STATUS *t);\r
+UINT StCreateListener(ADMIN *a, RPC_LISTENER *t);\r
+UINT StEnumListener(ADMIN *a, RPC_LISTENER_LIST *t);\r
+UINT StDeleteListener(ADMIN *a, RPC_LISTENER *t);\r
+UINT StEnableListener(ADMIN *a, RPC_LISTENER *t);\r
+UINT StSetServerPassword(ADMIN *a, RPC_SET_PASSWORD *t);\r
+UINT StSetFarmSetting(ADMIN *a, RPC_FARM *t);\r
+UINT StGetFarmSetting(ADMIN *a, RPC_FARM *t);\r
+UINT StGetFarmInfo(ADMIN *a, RPC_FARM_INFO *t);\r
+UINT StEnumFarmMember(ADMIN *a, RPC_ENUM_FARM *t);\r
+UINT StGetFarmConnectionStatus(ADMIN *a, RPC_FARM_CONNECTION_STATUS *t);\r
+UINT StSetServerCert(ADMIN *a, RPC_KEY_PAIR *t);\r
+UINT StGetServerCert(ADMIN *a, RPC_KEY_PAIR *t);\r
+UINT StGetServerCipher(ADMIN *a, RPC_STR *t);\r
+UINT StSetServerCipher(ADMIN *a, RPC_STR *t);\r
+UINT StCreateHub(ADMIN *a, RPC_CREATE_HUB *t);\r
+UINT StSetHub(ADMIN *a, RPC_CREATE_HUB *t);\r
+UINT StGetHub(ADMIN *a, RPC_CREATE_HUB *t);\r
+UINT StEnumHub(ADMIN *a, RPC_ENUM_HUB *t);\r
+UINT StDeleteHub(ADMIN *a, RPC_DELETE_HUB *t);\r
+UINT StGetHubRadius(ADMIN *a, RPC_RADIUS *t);\r
+UINT StSetHubRadius(ADMIN *a, RPC_RADIUS *t);\r
+UINT StEnumConnection(ADMIN *a, RPC_ENUM_CONNECTION *t);\r
+UINT StDisconnectConnection(ADMIN *a, RPC_DISCONNECT_CONNECTION *t);\r
+UINT StGetConnectionInfo(ADMIN *a, RPC_CONNECTION_INFO *t);\r
+UINT StSetHubOnline(ADMIN *a, RPC_SET_HUB_ONLINE *t);\r
+UINT StGetHubStatus(ADMIN *a, RPC_HUB_STATUS *t);\r
+UINT StSetHubLog(ADMIN *a, RPC_HUB_LOG *t);\r
+UINT StGetHubLog(ADMIN *a, RPC_HUB_LOG *t);\r
+UINT StAddCa(ADMIN *a, RPC_HUB_ADD_CA *t);\r
+UINT StEnumCa(ADMIN *a, RPC_HUB_ENUM_CA *t);\r
+UINT StGetCa(ADMIN *a, RPC_HUB_GET_CA *t);\r
+UINT StDeleteCa(ADMIN *a, RPC_HUB_DELETE_CA *t);\r
+UINT StCreateLink(ADMIN *a, RPC_CREATE_LINK *t);\r
+UINT StEnumLink(ADMIN *a, RPC_ENUM_LINK *t);\r
+UINT StGetLinkStatus(ADMIN *a, RPC_LINK_STATUS *t);\r
+UINT StSetLinkOnline(ADMIN *a, RPC_LINK *t);\r
+UINT StSetLinkOffline(ADMIN *a, RPC_LINK *t);\r
+UINT StDeleteLink(ADMIN *a, RPC_LINK *t);\r
+UINT StRenameLink(ADMIN *a, RPC_RENAME_LINK *t);\r
+UINT StAddAccess(ADMIN *a, RPC_ADD_ACCESS *t);\r
+UINT StDeleteAccess(ADMIN *a, RPC_DELETE_ACCESS *t);\r
+UINT StEnumAccess(ADMIN *a, RPC_ENUM_ACCESS_LIST *t);\r
+UINT StCreateUser(ADMIN *a, RPC_SET_USER *t);\r
+UINT StSetUser(ADMIN *a, RPC_SET_USER *t);\r
+UINT StGetUser(ADMIN *a, RPC_SET_USER *t);\r
+UINT StDeleteUser(ADMIN *a, RPC_DELETE_USER *t);\r
+UINT StEnumUser(ADMIN *a, RPC_ENUM_USER *t);\r
+UINT StCreateGroup(ADMIN *a, RPC_SET_GROUP *t);\r
+UINT StSetGroup(ADMIN *a, RPC_SET_GROUP *t);\r
+UINT StGetGroup(ADMIN *a, RPC_SET_GROUP *t);\r
+UINT StDeleteGroup(ADMIN *a, RPC_DELETE_USER *t);\r
+UINT StEnumGroup(ADMIN *a, RPC_ENUM_GROUP *t);\r
+UINT StEnumSession(ADMIN *a, RPC_ENUM_SESSION *t);\r
+UINT StGetSessionStatus(ADMIN *a, RPC_SESSION_STATUS *t);\r
+UINT StDeleteSession(ADMIN *a, RPC_DELETE_SESSION *t);\r
+UINT StEnumMacTable(ADMIN *a, RPC_ENUM_MAC_TABLE *t);\r
+UINT StDeleteMacTable(ADMIN *a, RPC_DELETE_TABLE *t);\r
+UINT StEnumIpTable(ADMIN *a, RPC_ENUM_IP_TABLE *t);\r
+UINT StDeleteIpTable(ADMIN *a, RPC_DELETE_TABLE *t);\r
+UINT StGetLink(ADMIN *a, RPC_CREATE_LINK *t);\r
+UINT StSetLink(ADMIN *a, RPC_CREATE_LINK *t);\r
+UINT StSetAccessList(ADMIN *a, RPC_ENUM_ACCESS_LIST *t);\r
+UINT StSetKeep(ADMIN *a, RPC_KEEP *t);\r
+UINT StGetKeep(ADMIN *a, RPC_KEEP *t);\r
+UINT StEnableSecureNAT(ADMIN *a, RPC_HUB *t);\r
+UINT StDisableSecureNAT(ADMIN *a, RPC_HUB *t);\r
+UINT StSetSecureNATOption(ADMIN *a, VH_OPTION *t);\r
+UINT StGetSecureNATOption(ADMIN *a, VH_OPTION *t);\r
+UINT StEnumNAT(ADMIN *a, RPC_ENUM_NAT *t);\r
+UINT StEnumDHCP(ADMIN *a, RPC_ENUM_DHCP *t);\r
+UINT StGetSecureNATStatus(ADMIN *a, RPC_NAT_STATUS *t);\r
+UINT StEnumEthernet(ADMIN *a, RPC_ENUM_ETH *t);\r
+UINT StAddLocalBridge(ADMIN *a, RPC_LOCALBRIDGE *t);\r
+UINT StDeleteLocalBridge(ADMIN *a, RPC_LOCALBRIDGE *t);\r
+UINT StEnumLocalBridge(ADMIN *a, RPC_ENUM_LOCALBRIDGE *t);\r
+UINT StGetBridgeSupport(ADMIN *a, RPC_BRIDGE_SUPPORT *t);\r
+UINT StRebootServer(ADMIN *a, RPC_TEST *t);\r
+UINT StGetCaps(ADMIN *a, CAPSLIST *t);\r
+UINT StGetConfig(ADMIN *a, RPC_CONFIG *t);\r
+UINT StSetConfig(ADMIN *a, RPC_CONFIG *t);\r
+UINT StGetDefaultHubAdminOptions(ADMIN *a, RPC_ADMIN_OPTION *t);\r
+UINT StGetHubAdminOptions(ADMIN *a, RPC_ADMIN_OPTION *t);\r
+UINT StSetHubAdminOptions(ADMIN *a, RPC_ADMIN_OPTION *t);\r
+UINT StGetHubExtOptions(ADMIN *a, RPC_ADMIN_OPTION *t);\r
+UINT StSetHubExtOptions(ADMIN *a, RPC_ADMIN_OPTION *t);\r
+UINT StAddL3Switch(ADMIN *a, RPC_L3SW *t);\r
+UINT StDelL3Switch(ADMIN *a, RPC_L3SW *t);\r
+UINT StEnumL3Switch(ADMIN *a, RPC_ENUM_L3SW *t);\r
+UINT StStartL3Switch(ADMIN *a, RPC_L3SW *t);\r
+UINT StStopL3Switch(ADMIN *a, RPC_L3SW *t);\r
+UINT StAddL3If(ADMIN *a, RPC_L3IF *t);\r
+UINT StDelL3If(ADMIN *a, RPC_L3IF *t);\r
+UINT StEnumL3If(ADMIN *a, RPC_ENUM_L3IF *t);\r
+UINT StAddL3Table(ADMIN *a, RPC_L3TABLE *t);\r
+UINT StDelL3Table(ADMIN *a, RPC_L3TABLE *t);\r
+UINT StEnumL3Table(ADMIN *a, RPC_ENUM_L3TABLE *t);\r
+UINT StEnumCrl(ADMIN *a, RPC_ENUM_CRL *t);\r
+UINT StAddCrl(ADMIN *a, RPC_CRL *t);\r
+UINT StDelCrl(ADMIN *a, RPC_CRL *t);\r
+UINT StGetCrl(ADMIN *a, RPC_CRL *t);\r
+UINT StSetCrl(ADMIN *a, RPC_CRL *t);\r
+UINT StSetAcList(ADMIN *a, RPC_AC_LIST *t);\r
+UINT StGetAcList(ADMIN *a, RPC_AC_LIST *t);\r
+UINT StEnumLogFile(ADMIN *a, RPC_ENUM_LOG_FILE *t);\r
+UINT StReadLogFile(ADMIN *a, RPC_READ_LOG_FILE *t);\r
+UINT StAddLicenseKey(ADMIN *a, RPC_TEST *t);\r
+UINT StDelLicenseKey(ADMIN *a, RPC_TEST *t);\r
+UINT StEnumLicenseKey(ADMIN *a, RPC_ENUM_LICENSE_KEY *t);\r
+UINT StGetLicenseStatus(ADMIN *a, RPC_LICENSE_STATUS *t);\r
+UINT StSetSysLog(ADMIN *a, SYSLOG_SETTING *t);\r
+UINT StGetSysLog(ADMIN *a, SYSLOG_SETTING *t);\r
+UINT StEnumEthVLan(ADMIN *a, RPC_ENUM_ETH_VLAN *t);\r
+UINT StSetEnableEthVLan(ADMIN *a, RPC_TEST *t);\r
+UINT StSetHubMsg(ADMIN *a, RPC_MSG *t);\r
+UINT StGetHubMsg(ADMIN *a, RPC_MSG *t);\r
+UINT StCrash(ADMIN *a, RPC_TEST *t);\r
+UINT StGetAdminMsg(ADMIN *a, RPC_MSG *t);\r
+UINT StFlush(ADMIN *a, RPC_TEST *t);\r
+UINT StDebug(ADMIN *a, RPC_TEST *t);\r
+\r
+UINT ScTest(RPC *r, RPC_TEST *t);\r
+UINT ScGetServerInfo(RPC *r, RPC_SERVER_INFO *t);\r
+UINT ScGetServerStatus(RPC *r, RPC_SERVER_STATUS *t);\r
+UINT ScCreateListener(RPC *r, RPC_LISTENER *t);\r
+UINT ScEnumListener(RPC *r, RPC_LISTENER_LIST *t);\r
+UINT ScDeleteListener(RPC *r, RPC_LISTENER *t);\r
+UINT ScEnableListener(RPC *r, RPC_LISTENER *t);\r
+UINT ScSetServerPassword(RPC *r, RPC_SET_PASSWORD *t);\r
+UINT ScSetFarmSetting(RPC *r, RPC_FARM *t);\r
+UINT ScGetFarmSetting(RPC *r, RPC_FARM *t);\r
+UINT ScGetFarmInfo(RPC *r, RPC_FARM_INFO *t);\r
+UINT ScEnumFarmMember(RPC *r, RPC_ENUM_FARM *t);\r
+UINT ScGetFarmConnectionStatus(RPC *r, RPC_FARM_CONNECTION_STATUS *t);\r
+UINT ScSetServerCert(RPC *r, RPC_KEY_PAIR *t);\r
+UINT ScGetServerCert(RPC *r, RPC_KEY_PAIR *t);\r
+UINT ScGetServerCipher(RPC *r, RPC_STR *t);\r
+UINT ScSetServerCipher(RPC *r, RPC_STR *t);\r
+UINT ScCreateHub(RPC *r, RPC_CREATE_HUB *t);\r
+UINT ScSetHub(RPC *r, RPC_CREATE_HUB *t);\r
+UINT ScGetHub(RPC *r, RPC_CREATE_HUB *t);\r
+UINT ScEnumHub(RPC *r, RPC_ENUM_HUB *t);\r
+UINT ScDeleteHub(RPC *r, RPC_DELETE_HUB *t);\r
+UINT ScGetHubRadius(RPC *r, RPC_RADIUS *t);\r
+UINT ScSetHubRadius(RPC *r, RPC_RADIUS *t);\r
+UINT ScEnumConnection(RPC *r, RPC_ENUM_CONNECTION *t);\r
+UINT ScDisconnectConnection(RPC *r, RPC_DISCONNECT_CONNECTION *t);\r
+UINT ScGetConnectionInfo(RPC *r, RPC_CONNECTION_INFO *t);\r
+UINT ScSetHubOnline(RPC *r, RPC_SET_HUB_ONLINE *t);\r
+UINT ScGetHubStatus(RPC *r, RPC_HUB_STATUS *t);\r
+UINT ScSetHubLog(RPC *r, RPC_HUB_LOG *t);\r
+UINT ScGetHubLog(RPC *r, RPC_HUB_LOG *t);\r
+UINT ScAddCa(RPC *r, RPC_HUB_ADD_CA *t);\r
+UINT ScEnumCa(RPC *r, RPC_HUB_ENUM_CA *t);\r
+UINT ScGetCa(RPC *r, RPC_HUB_GET_CA *t);\r
+UINT ScDeleteCa(RPC *r, RPC_HUB_DELETE_CA *t);\r
+UINT ScCreateLink(RPC *r, RPC_CREATE_LINK *t);\r
+UINT ScEnumLink(RPC *r, RPC_ENUM_LINK *t);\r
+UINT ScGetLinkStatus(RPC *r, RPC_LINK_STATUS *t);\r
+UINT ScSetLinkOnline(RPC *r, RPC_LINK *t);\r
+UINT ScSetLinkOffline(RPC *r, RPC_LINK *t);\r
+UINT ScDeleteLink(RPC *r, RPC_LINK *t);\r
+UINT ScRenameLink(RPC *r, RPC_RENAME_LINK *t);\r
+UINT ScAddAccess(RPC *r, RPC_ADD_ACCESS *t);\r
+UINT ScDeleteAccess(RPC *r, RPC_DELETE_ACCESS *t);\r
+UINT ScEnumAccess(RPC *r, RPC_ENUM_ACCESS_LIST *t);\r
+UINT ScCreateUser(RPC *r, RPC_SET_USER *t);\r
+UINT ScSetUser(RPC *r, RPC_SET_USER *t);\r
+UINT ScGetUser(RPC *r, RPC_SET_USER *t);\r
+UINT ScDeleteUser(RPC *r, RPC_DELETE_USER *t);\r
+UINT ScEnumUser(RPC *r, RPC_ENUM_USER *t);\r
+UINT ScCreateGroup(RPC *r, RPC_SET_GROUP *t);\r
+UINT ScSetGroup(RPC *r, RPC_SET_GROUP *t);\r
+UINT ScGetGroup(RPC *r, RPC_SET_GROUP *t);\r
+UINT ScDeleteGroup(RPC *r, RPC_DELETE_USER *t);\r
+UINT ScEnumGroup(RPC *r, RPC_ENUM_GROUP *t);\r
+UINT ScEnumSession(RPC *r, RPC_ENUM_SESSION *t);\r
+UINT ScGetSessionStatus(RPC *r, RPC_SESSION_STATUS *t);\r
+UINT ScDeleteSession(RPC *r, RPC_DELETE_SESSION *t);\r
+UINT ScEnumMacTable(RPC *r, RPC_ENUM_MAC_TABLE *t);\r
+UINT ScDeleteMacTable(RPC *r, RPC_DELETE_TABLE *t);\r
+UINT ScEnumIpTable(RPC *r, RPC_ENUM_IP_TABLE *t);\r
+UINT ScDeleteIpTable(RPC *r, RPC_DELETE_TABLE *t);\r
+UINT ScGetLink(RPC *a, RPC_CREATE_LINK *t);\r
+UINT ScSetLink(RPC *a, RPC_CREATE_LINK *t);\r
+UINT ScSetAccessList(RPC *r, RPC_ENUM_ACCESS_LIST *t);\r
+UINT ScSetKeep(RPC *r, RPC_KEEP *t);\r
+UINT ScGetKeep(RPC *r, RPC_KEEP *t);\r
+UINT ScEnableSecureNAT(RPC *r, RPC_HUB *t);\r
+UINT ScDisableSecureNAT(RPC *r, RPC_HUB *t);\r
+UINT ScSetSecureNATOption(RPC *r, VH_OPTION *t);\r
+UINT ScGetSecureNATOption(RPC *r, VH_OPTION *t);\r
+UINT ScEnumNAT(RPC *r, RPC_ENUM_NAT *t);\r
+UINT ScEnumDHCP(RPC *r, RPC_ENUM_DHCP *t);\r
+UINT ScGetSecureNATStatus(RPC *r, RPC_NAT_STATUS *t);\r
+UINT ScEnumEthernet(RPC *r, RPC_ENUM_ETH *t);\r
+UINT ScAddLocalBridge(RPC *r, RPC_LOCALBRIDGE *t);\r
+UINT ScDeleteLocalBridge(RPC *r, RPC_LOCALBRIDGE *t);\r
+UINT ScEnumLocalBridge(RPC *r, RPC_ENUM_LOCALBRIDGE *t);\r
+UINT ScGetBridgeSupport(RPC *r, RPC_BRIDGE_SUPPORT *t);\r
+UINT ScRebootServer(RPC *r, RPC_TEST *t);\r
+UINT ScGetCaps(RPC *r, CAPSLIST *t);\r
+UINT ScGetConfig(RPC *r, RPC_CONFIG *t);\r
+UINT ScSetConfig(RPC *r, RPC_CONFIG *t);\r
+UINT ScGetDefaultHubAdminOptions(RPC *r, RPC_ADMIN_OPTION *t);\r
+UINT ScGetHubAdminOptions(RPC *r, RPC_ADMIN_OPTION *t);\r
+UINT ScSetHubAdminOptions(RPC *r, RPC_ADMIN_OPTION *t);\r
+UINT ScGetHubExtOptions(RPC *r, RPC_ADMIN_OPTION *t);\r
+UINT ScSetHubExtOptions(RPC *r, RPC_ADMIN_OPTION *t);\r
+UINT ScAddL3Switch(RPC *r, RPC_L3SW *t);\r
+UINT ScDelL3Switch(RPC *r, RPC_L3SW *t);\r
+UINT ScEnumL3Switch(RPC *r, RPC_ENUM_L3SW *t);\r
+UINT ScStartL3Switch(RPC *r, RPC_L3SW *t);\r
+UINT ScStopL3Switch(RPC *r, RPC_L3SW *t);\r
+UINT ScAddL3If(RPC *r, RPC_L3IF *t);\r
+UINT ScDelL3If(RPC *r, RPC_L3IF *t);\r
+UINT ScEnumL3If(RPC *r, RPC_ENUM_L3IF *t);\r
+UINT ScAddL3Table(RPC *r, RPC_L3TABLE *t);\r
+UINT ScDelL3Table(RPC *r, RPC_L3TABLE *t);\r
+UINT ScEnumL3Table(RPC *r, RPC_ENUM_L3TABLE *t);\r
+UINT ScEnumCrl(RPC *r, RPC_ENUM_CRL *t);\r
+UINT ScAddCrl(RPC *r, RPC_CRL *t);\r
+UINT ScDelCrl(RPC *r, RPC_CRL *t);\r
+UINT ScGetCrl(RPC *r, RPC_CRL *t);\r
+UINT ScSetCrl(RPC *r, RPC_CRL *t);\r
+UINT ScSetAcList(RPC *r, RPC_AC_LIST *t);\r
+UINT ScGetAcList(RPC *r, RPC_AC_LIST *t);\r
+UINT ScEnumLogFile(RPC *r, RPC_ENUM_LOG_FILE *t);\r
+UINT ScReadLogFile(RPC *r, RPC_READ_LOG_FILE *t);\r
+UINT ScAddLicenseKey(RPC *r, RPC_TEST *t);\r
+UINT ScDelLicenseKey(RPC *r, RPC_TEST *t);\r
+UINT ScEnumLicenseKey(RPC *r, RPC_ENUM_LICENSE_KEY *t);\r
+UINT ScGetLicenseStatus(RPC *r, RPC_LICENSE_STATUS *t);\r
+UINT ScSetSysLog(RPC *r, SYSLOG_SETTING *t);\r
+UINT ScGetSysLog(RPC *r, SYSLOG_SETTING *t);\r
+UINT ScEnumEthVLan(RPC *r, RPC_ENUM_ETH_VLAN *t);\r
+UINT ScSetEnableEthVLan(RPC *r, RPC_TEST *t);\r
+UINT ScSetHubMsg(RPC *r, RPC_MSG *t);\r
+UINT ScGetHubMsg(RPC *r, RPC_MSG *t);\r
+UINT ScCrash(RPC *r, RPC_TEST *t);\r
+UINT ScGetAdminMsg(RPC *r, RPC_MSG *t);\r
+UINT ScFlush(RPC *r, RPC_TEST *t);\r
+UINT ScDebug(RPC *r, RPC_TEST *t);\r
+\r
+void InRpcTest(RPC_TEST *t, PACK *p);\r
+void OutRpcTest(PACK *p, RPC_TEST *t);\r
+void FreeRpcTest(RPC_TEST *t);\r
+void InRpcServerInfo(RPC_SERVER_INFO *t, PACK *p);\r
+void OutRpcServerInfo(PACK *p, RPC_SERVER_INFO *t);\r
+void FreeRpcServerInfo(RPC_SERVER_INFO *t);\r
+void InRpcServerStatus(RPC_SERVER_STATUS *t, PACK *p);\r
+void OutRpcServerStatus(PACK *p, RPC_SERVER_STATUS *t);\r
+void InRpcListener(RPC_LISTENER *t, PACK *p);\r
+void OutRpcListener(PACK *p, RPC_LISTENER *t);\r
+void InRpcListenerList(RPC_LISTENER_LIST *t, PACK *p);\r
+void OutRpcListenerList(PACK *p, RPC_LISTENER_LIST *t);\r
+void FreeRpcListenerList(RPC_LISTENER_LIST *t);\r
+void InRpcStr(RPC_STR *t, PACK *p);\r
+void OutRpcStr(PACK *p, RPC_STR *t);\r
+void FreeRpcStr(RPC_STR *t);\r
+void InRpcSetPassword(RPC_SET_PASSWORD *t, PACK *p);\r
+void OutRpcSetPassword(PACK *p, RPC_SET_PASSWORD *t);\r
+void InRpcFarm(RPC_FARM *t, PACK *p);\r
+void OutRpcFarm(PACK *p, RPC_FARM *t);\r
+void FreeRpcFarm(RPC_FARM *t);\r
+void InRpcFarmHub(RPC_FARM_HUB *t, PACK *p);\r
+void OutRpcFarmHub(PACK *p, RPC_FARM_HUB *t);\r
+void InRpcFarmInfo(RPC_FARM_INFO *t, PACK *p);\r
+void OutRpcFarmInfo(PACK *p, RPC_FARM_INFO *t);\r
+void FreeRpcFarmInfo(RPC_FARM_INFO *t);\r
+void InRpcEnumFarm(RPC_ENUM_FARM *t, PACK *p);\r
+void OutRpcEnumFarm(PACK *p, RPC_ENUM_FARM *t);\r
+void FreeRpcEnumFarm(RPC_ENUM_FARM *t);\r
+void InRpcFarmConnectionStatus(RPC_FARM_CONNECTION_STATUS *t, PACK *p);\r
+void OutRpcFarmConnectionStatus(PACK *p, RPC_FARM_CONNECTION_STATUS *t);\r
+void InRpcHubOption(RPC_HUB_OPTION *t, PACK *p);\r
+void OutRpcHubOption(PACK *p, RPC_HUB_OPTION *t);\r
+void InRpcRadius(RPC_RADIUS *t, PACK *p);\r
+void OutRpcRadius(PACK *p, RPC_RADIUS *t);\r
+void InRpcHub(RPC_HUB *t, PACK *p);\r
+void OutRpcHub(PACK *p, RPC_HUB *t);\r
+void InRpcCreateHub(RPC_CREATE_HUB *t, PACK *p);\r
+void OutRpcCreateHub(PACK *p, RPC_CREATE_HUB *t);\r
+void InRpcEnumHub(RPC_ENUM_HUB *t, PACK *p);\r
+void OutRpcEnumHub(PACK *p, RPC_ENUM_HUB *t);\r
+void FreeRpcEnumHub(RPC_ENUM_HUB *t);\r
+void InRpcDeleteHub(RPC_DELETE_HUB *t, PACK *p);\r
+void OutRpcDeleteHub(PACK *p, RPC_DELETE_HUB *t);\r
+void InRpcEnumConnection(RPC_ENUM_CONNECTION *t, PACK *p);\r
+void OutRpcEnumConnection(PACK *p, RPC_ENUM_CONNECTION *t);\r
+void FreeRpcEnumConnetion(RPC_ENUM_CONNECTION *t);\r
+void InRpcDisconnectConnection(RPC_DISCONNECT_CONNECTION *t, PACK *p);\r
+void OutRpcDisconnectConnection(PACK *p, RPC_DISCONNECT_CONNECTION *t);\r
+void InRpcConnectionInfo(RPC_CONNECTION_INFO *t, PACK *p);\r
+void OutRpcConnectionInfo(PACK *p, RPC_CONNECTION_INFO *t);\r
+void InRpcSetHubOnline(RPC_SET_HUB_ONLINE *t, PACK *p);\r
+void OutRpcSetHubOnline(PACK *p, RPC_SET_HUB_ONLINE *t);\r
+void InRpcHubStatus(RPC_HUB_STATUS *t, PACK *p);\r
+void OutRpcHubStatus(PACK *p, RPC_HUB_STATUS *t);\r
+void InRpcHubLog(RPC_HUB_LOG *t, PACK *p);\r
+void OutRpcHubLog(PACK *p, RPC_HUB_LOG *t);\r
+void InRpcHubAddCa(RPC_HUB_ADD_CA *t, PACK *p);\r
+void OutRpcHubAddCa(PACK *p, RPC_HUB_ADD_CA *t);\r
+void FreeRpcHubAddCa(RPC_HUB_ADD_CA *t);\r
+void InRpcHubEnumCa(RPC_HUB_ENUM_CA *t, PACK *p);\r
+void OutRpcHubEnumCa(PACK *p, RPC_HUB_ENUM_CA *t);\r
+void FreeRpcHubEnumCa(RPC_HUB_ENUM_CA *t);\r
+void InRpcHubGetCa(RPC_HUB_GET_CA *t, PACK *p);\r
+void OutRpcHubGetCa(PACK *p, RPC_HUB_GET_CA *t);\r
+void FreeRpcHubGetCa(RPC_HUB_GET_CA *t);\r
+void InRpcHubDeleteCa(RPC_HUB_DELETE_CA *t, PACK *p);\r
+void OutRpcHubDeleteCa(PACK *p, RPC_HUB_DELETE_CA *t);\r
+void InRpcCreateLink(RPC_CREATE_LINK *t, PACK *p);\r
+void OutRpcCreateLink(PACK *p, RPC_CREATE_LINK *t);\r
+void FreeRpcCreateLink(RPC_CREATE_LINK *t);\r
+void InRpcEnumLink(RPC_ENUM_LINK *t, PACK *p);\r
+void OutRpcEnumLink(PACK *p, RPC_ENUM_LINK *t);\r
+void FreeRpcEnumLink(RPC_ENUM_LINK *t);\r
+void InRpcLinkStatus(RPC_LINK_STATUS *t, PACK *p);\r
+void OutRpcLinkStatus(PACK *p, RPC_LINK_STATUS *t);\r
+void FreeRpcLinkStatus(RPC_LINK_STATUS *t);\r
+void InRpcLink(RPC_LINK *t, PACK *p);\r
+void OutRpcLink(PACK *p, RPC_LINK *t);\r
+void InRpcAccessEx(ACCESS *a, PACK *p, UINT index);\r
+void InRpcAccess(ACCESS *a, PACK *p);\r
+void OutRpcAccessEx(PACK *p, ACCESS *a, UINT index, UINT total);\r
+void OutRpcAccess(PACK *p, ACCESS *a);\r
+void InRpcEnumAccessList(RPC_ENUM_ACCESS_LIST *a, PACK *p);\r
+void OutRpcEnumAccessList(PACK *p, RPC_ENUM_ACCESS_LIST *a);\r
+void FreeRpcEnumAccessList(RPC_ENUM_ACCESS_LIST *a);\r
+void *InRpcAuthData(PACK *p, UINT *authtype);\r
+void OutRpcAuthData(PACK *p, void *authdata, UINT authtype);\r
+void FreeRpcAuthData(void *authdata, UINT authtype);\r
+void InRpcSetUser(RPC_SET_USER *t, PACK *p);\r
+void OutRpcSetUser(PACK *p, RPC_SET_USER *t);\r
+void FreeRpcSetUser(RPC_SET_USER *t);\r
+void InRpcEnumUser(RPC_ENUM_USER *t, PACK *p);\r
+void OutRpcEnumUser(PACK *p, RPC_ENUM_USER *t);\r
+void FreeRpcEnumUser(RPC_ENUM_USER *t);\r
+void InRpcSetGroup(RPC_SET_GROUP *t, PACK *p);\r
+void OutRpcSetGroup(PACK *p, RPC_SET_GROUP *t);\r
+void InRpcEnumGroup(RPC_ENUM_GROUP *t, PACK *p);\r
+void OutRpcEnumGroup(PACK *p, RPC_ENUM_GROUP *t);\r
+void FreeRpcEnumGroup(RPC_ENUM_GROUP *t);\r
+void InRpcDeleteUser(RPC_DELETE_USER *t, PACK *p);\r
+void OutRpcDeleteUser(PACK *p, RPC_DELETE_USER *t);\r
+void InRpcEnumSession(RPC_ENUM_SESSION *t, PACK *p);\r
+void OutRpcEnumSession(PACK *p, RPC_ENUM_SESSION *t);\r
+void FreeRpcEnumSession(RPC_ENUM_SESSION *t);\r
+void InRpcNodeInfo(NODE_INFO *t, PACK *p);\r
+void OutRpcNodeInfo(PACK *p, NODE_INFO *t);\r
+void InRpcSessionStatus(RPC_SESSION_STATUS *t, PACK *p);\r
+void OutRpcSessionStatus(PACK *p, RPC_SESSION_STATUS *t);\r
+void FreeRpcSessionStatus(RPC_SESSION_STATUS *t);\r
+void InRpcDeleteSession(RPC_DELETE_SESSION *t, PACK *p);\r
+void OutRpcDeleteSession(PACK *p, RPC_DELETE_SESSION *t);\r
+void InRpcEnumMacTable(RPC_ENUM_MAC_TABLE *t, PACK *p);\r
+void OutRpcEnumMacTable(PACK *p, RPC_ENUM_MAC_TABLE *t);\r
+void FreeRpcEnumMacTable(RPC_ENUM_MAC_TABLE *t);\r
+void InRpcEnumIpTable(RPC_ENUM_IP_TABLE *t, PACK *p);\r
+void OutRpcEnumIpTable(PACK *p, RPC_ENUM_IP_TABLE *t);\r
+void FreeRpcEnumIpTable(RPC_ENUM_IP_TABLE *t);\r
+void InRpcDeleteTable(RPC_DELETE_TABLE *t, PACK *p);\r
+void OutRpcDeleteTable(PACK *p, RPC_DELETE_TABLE *t);\r
+void InRpcMemInfo(MEMINFO *t, PACK *p);\r
+void OutRpcMemInfo(PACK *p, MEMINFO *t);\r
+void InRpcKeyPair(RPC_KEY_PAIR *t, PACK *p);\r
+void OutRpcKeyPair(PACK *p, RPC_KEY_PAIR *t);\r
+void FreeRpcKeyPair(RPC_KEY_PAIR *t);\r
+void InRpcAddAccess(RPC_ADD_ACCESS *t, PACK *p);\r
+void OutRpcAddAccess(PACK *p, RPC_ADD_ACCESS *t);\r
+void InRpcDeleteAccess(RPC_DELETE_ACCESS *t, PACK *p);\r
+void OutRpcDeleteAccess(PACK *p, RPC_DELETE_ACCESS *t);\r
+void FreeRpcSetGroup(RPC_SET_GROUP *t);\r
+void AdjoinRpcEnumSession(RPC_ENUM_SESSION *dest, RPC_ENUM_SESSION *src);\r
+void AdjoinRpcEnumMacTable(RPC_ENUM_MAC_TABLE *dest, RPC_ENUM_MAC_TABLE *src);\r
+void AdjoinRpcEnumIpTable(RPC_ENUM_IP_TABLE *dest, RPC_ENUM_IP_TABLE *src);\r
+void InRpcKeep(RPC_KEEP *t, PACK *p);\r
+void OutRpcKeep(PACK *p, RPC_KEEP *t);\r
+void InRpcOsInfo(OS_INFO *t, PACK *p);\r
+void OutRpcOsInfo(PACK *p, OS_INFO *t);\r
+void FreeRpcOsInfo(OS_INFO *t);\r
+void InRpcEnumEth(RPC_ENUM_ETH *t, PACK *p);\r
+void OutRpcEnumEth(PACK *p, RPC_ENUM_ETH *t);\r
+void FreeRpcEnumEth(RPC_ENUM_ETH *t);\r
+void InRpcLocalBridge(RPC_LOCALBRIDGE *t, PACK *p);\r
+void OutRpcLocalBridge(PACK *p, RPC_LOCALBRIDGE *t);\r
+void InRpcEnumLocalBridge(RPC_ENUM_LOCALBRIDGE *t, PACK *p);\r
+void OutRpcEnumLocalBridge(PACK *p, RPC_ENUM_LOCALBRIDGE *t);\r
+void FreeRpcEnumLocalBridge(RPC_ENUM_LOCALBRIDGE *t);\r
+void InRpcBridgeSupport(RPC_BRIDGE_SUPPORT *t, PACK *p);\r
+void OutRpcBridgeSupport(PACK *p, RPC_BRIDGE_SUPPORT *t);\r
+void InRpcConfig(RPC_CONFIG *t, PACK *p);\r
+void OutRpcConfig(PACK *p, RPC_CONFIG *t);\r
+void FreeRpcConfig(RPC_CONFIG *t);\r
+void InRpcAdminOption(RPC_ADMIN_OPTION *t, PACK *p);\r
+void OutRpcAdminOption(PACK *p, RPC_ADMIN_OPTION *t);\r
+void FreeRpcAdminOption(RPC_ADMIN_OPTION *t);\r
+void InRpcEnumL3Table(RPC_ENUM_L3TABLE *t, PACK *p);\r
+void OutRpcEnumL3Table(PACK *p, RPC_ENUM_L3TABLE *t);\r
+void FreeRpcEnumL3Table(RPC_ENUM_L3TABLE *t);\r
+void InRpcL3Table(RPC_L3TABLE *t, PACK *p);\r
+void OutRpcL3Table(PACK *p, RPC_L3TABLE *t);\r
+void InRpcEnumL3If(RPC_ENUM_L3IF *t, PACK *p);\r
+void OutRpcEnumL3If(PACK *p, RPC_ENUM_L3IF *t);\r
+void FreeRpcEnumL3If(RPC_ENUM_L3IF *t);\r
+void InRpcL3If(RPC_L3IF *t, PACK *p);\r
+void OutRpcL3If(PACK *p, RPC_L3IF *t);\r
+void InRpcL3Sw(RPC_L3SW *t, PACK *p);\r
+void OutRpcL3Sw(PACK *p, RPC_L3SW *t);\r
+void InRpcEnumL3Sw(RPC_ENUM_L3SW *t, PACK *p);\r
+void OutRpcEnumL3Sw(PACK *p, RPC_ENUM_L3SW *t);\r
+void FreeRpcEnumL3Sw(RPC_ENUM_L3SW *t);\r
+void InRpcCrl(RPC_CRL *t, PACK *p);\r
+void OutRpcCrl(PACK *p, RPC_CRL *t);\r
+void FreeRpcCrl(RPC_CRL *t);\r
+void InRpcEnumCrl(RPC_ENUM_CRL *t, PACK *p);\r
+void OutRpcEnumCrl(PACK *p, RPC_ENUM_CRL *t);\r
+void FreeRpcEnumCrl(RPC_ENUM_CRL *t);\r
+void InRpcInt(RPC_INT *t, PACK *p);\r
+void OutRpcInt(PACK *p, RPC_INT *t);\r
+void InRpcAcList(RPC_AC_LIST *t, PACK *p);\r
+void OutRpcAcList(PACK *p, RPC_AC_LIST *t);\r
+void FreeRpcAcList(RPC_AC_LIST *t);\r
+void InRpcEnumLogFile(RPC_ENUM_LOG_FILE *t, PACK *p);\r
+void OutRpcEnumLogFile(PACK *p, RPC_ENUM_LOG_FILE *t);\r
+void FreeRpcEnumLogFile(RPC_ENUM_LOG_FILE *t);\r
+void AdjoinRpcEnumLogFile(RPC_ENUM_LOG_FILE *t, RPC_ENUM_LOG_FILE *src);\r
+void InRpcReadLogFile(RPC_READ_LOG_FILE *t, PACK *p);\r
+void OutRpcReadLogFile(PACK *p, RPC_READ_LOG_FILE *t);\r
+void FreeRpcReadLogFile(RPC_READ_LOG_FILE *t);\r
+void InRpcRenameLink(RPC_RENAME_LINK *t, PACK *p);\r
+void OutRpcRenameLink(PACK *p, RPC_RENAME_LINK *t);\r
+void InRpcEnumLicenseKey(RPC_ENUM_LICENSE_KEY *t, PACK *p);\r
+void OutRpcEnumLicenseKey(PACK *p, RPC_ENUM_LICENSE_KEY *t);\r
+void FreeRpcEnumLicenseKey(RPC_ENUM_LICENSE_KEY *t);\r
+void InRpcLicenseStatus(RPC_LICENSE_STATUS *t, PACK *p);\r
+void OutRpcLicenseStatus(PACK *p, RPC_LICENSE_STATUS *t);\r
+void InRpcEnumEthVLan(RPC_ENUM_ETH_VLAN *t, PACK *p);\r
+void OutRpcEnumEthVLan(PACK *p, RPC_ENUM_ETH_VLAN *t);\r
+void FreeRpcEnumEthVLan(RPC_ENUM_ETH_VLAN *t);\r
+void InRpcMsg(RPC_MSG *t, PACK *p);\r
+void OutRpcMsg(PACK *p, RPC_MSG *t);\r
+void FreeRpcMsg(RPC_MSG *t);\r
+void InRpcWinVer(RPC_WINVER *t, PACK *p);\r
+void OutRpcWinVer(PACK *p, RPC_WINVER *t);\r
+\r
+\r
+\r
+#endif // ADMIN_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Bridge.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Bridge.c
new file mode 100644 (file)
index 0000000..dbd8002
--- /dev/null
@@ -0,0 +1,513 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Bridge.c\r
+// Ethernet ブリッジプログラム\r
+\r
+#define        BRIDGE_C\r
+\r
+#ifdef WIN32\r
+#define        OS_WIN32\r
+#endif\r
+\r
+#ifdef OS_WIN32\r
+\r
+// Win32 用\r
+#include "BridgeWin32.c"\r
+\r
+#else\r
+\r
+// Unix 用\r
+#include "BridgeUnix.c"\r
+\r
+#endif // OS_WIN32\r
+\r
+// 現在の Ethernet デバイス一覧をハッシュする\r
+UINT GetEthDeviceHash()\r
+{\r
+#ifdef OS_UNIX\r
+       // UNIX 版\r
+       UINT num;\r
+       UINT i;\r
+       char tmp[4096];\r
+       UCHAR hash[SHA1_SIZE];\r
+       TOKEN_LIST *t = GetEthList();\r
+\r
+       num = t->NumTokens;\r
+       tmp[0] = 0;\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               StrCat(tmp, sizeof(tmp), t->Token[i]);\r
+       }\r
+       FreeToken(t);\r
+\r
+       Hash(hash, tmp, StrLen(tmp), true);\r
+\r
+       Copy(&num, hash, sizeof(UINT));\r
+\r
+       return num;\r
+#else  // OS_UNIX\r
+       // Win32 版\r
+       UINT ret = 0;\r
+       MS_ADAPTER_LIST *a = MsCreateAdapterListEx(true);\r
+       UINT num;\r
+       UINT i;\r
+       char tmp[4096];\r
+       UCHAR hash[SHA1_SIZE];\r
+\r
+       tmp[0] = 0;\r
+       if (a != NULL)\r
+       {\r
+               for (i = 0;i < a->Num;i++)\r
+               {\r
+                       StrCat(tmp, sizeof(tmp), a->Adapters[i]->Title);\r
+               }\r
+       }\r
+       MsFreeAdapterList(a);\r
+\r
+       Hash(hash, tmp, StrLen(tmp), true);\r
+\r
+       Copy(&num, hash, sizeof(UINT));\r
+\r
+       return num;\r
+#endif // OS_UNIU\r
+}\r
+\r
+// WinPcap が必要かどうか取得する\r
+bool IsNeedWinPcap()\r
+{\r
+       if (IsBridgeSupported() == false)\r
+       {\r
+               // Windows 以外\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               // Windows\r
+               if (IsEthSupported())\r
+               {\r
+                       // すでに Ethernet デバイスへのアクセスに成功している\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       // Ethernet デバイスへのアクセスに失敗している\r
+                       return true;\r
+               }\r
+       }\r
+}\r
+\r
+// 現在の OS でブリッジがサポートされているかどうか取得する\r
+bool IsBridgeSupported()\r
+{\r
+       UINT type = GetOsInfo()->OsType;\r
+\r
+       if (OS_IS_WINDOWS(type))\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return IsEthSupported();\r
+       }\r
+}\r
+\r
+// ローカルブリッジの削除\r
+bool DeleteLocalBridge(CEDAR *c, char *hubname, char *devicename)\r
+{\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (c == NULL || hubname == NULL || devicename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       LockList(c->HubList);\r
+       {\r
+               LockList(c->LocalBridgeList);\r
+               {\r
+                       UINT i;\r
+\r
+                       for (i = 0;i < LIST_NUM(c->LocalBridgeList);i++)\r
+                       {\r
+                               LOCALBRIDGE *br = LIST_DATA(c->LocalBridgeList, i);\r
+\r
+                               if (StrCmpi(br->HubName, hubname) == 0)\r
+                               {\r
+                                       if (StrCmpi(br->DeviceName, devicename) == 0)\r
+                                       {\r
+                                               if (br->Bridge != NULL)\r
+                                               {\r
+                                                       BrFreeBridge(br->Bridge);\r
+                                                       br->Bridge = NULL;\r
+                                               }\r
+\r
+                                               Delete(c->LocalBridgeList, br);\r
+                                               Free(br);\r
+\r
+                                               ret = true;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(c->LocalBridgeList);\r
+       }\r
+       UnlockList(c->HubList);\r
+\r
+       return ret;\r
+}\r
+\r
+// ローカルブリッジの追加\r
+void AddLocalBridge(CEDAR *c, char *hubname, char *devicename, bool local, bool monitor, bool tapmode, char *tapaddr, bool fullbcast)\r
+{\r
+       UINT i;\r
+       HUB *h = NULL;\r
+       LOCALBRIDGE *br = NULL;\r
+       // 引数チェック\r
+       if (c == NULL || hubname == NULL || devicename == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (OS_IS_UNIX(GetOsInfo()->OsType) == false)\r
+       {\r
+               tapmode = false;\r
+       }\r
+\r
+       LockList(c->HubList);\r
+       {\r
+               LockList(c->LocalBridgeList);\r
+               {\r
+                       bool exists = false;\r
+\r
+                       // 全く同一のブリッジ設定が無いかどうか調べる\r
+                       for (i = 0;i < LIST_NUM(c->LocalBridgeList);i++)\r
+                       {\r
+                               LOCALBRIDGE *br = LIST_DATA(c->LocalBridgeList, i);\r
+                               if (StrCmpi(br->DeviceName, devicename) == 0)\r
+                               {\r
+                                       if (StrCmpi(br->HubName, hubname) == 0)\r
+                                       {\r
+                                               if (br->TapMode == tapmode)\r
+                                               {\r
+                                                       exists = true;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       if (exists == false)\r
+                       {\r
+                               // 設定を追加する\r
+                               br = ZeroMalloc(sizeof(LOCALBRIDGE));\r
+                               StrCpy(br->HubName, sizeof(br->HubName), hubname);\r
+                               StrCpy(br->DeviceName, sizeof(br->DeviceName), devicename);\r
+                               br->Bridge = NULL;\r
+                               br->Local = local;\r
+                               br->TapMode = tapmode;\r
+                               br->FullBroadcast = fullbcast;\r
+                               br->Monitor = monitor;\r
+                               if (br->TapMode)\r
+                               {\r
+                                       if (tapaddr != NULL && IsZero(tapaddr, 6) == false)\r
+                                       {\r
+                                               Copy(br->TapMacAddress, tapaddr, 6);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               GenMacAddress(br->TapMacAddress);\r
+                                       }\r
+                               }\r
+\r
+                               Add(c->LocalBridgeList, br);\r
+\r
+                               // HUB を検索する\r
+                               for (i = 0;i < LIST_NUM(c->HubList);i++)\r
+                               {\r
+                                       HUB *hub = LIST_DATA(c->HubList, i);\r
+                                       if (StrCmpi(hub->Name, br->HubName) == 0)\r
+                                       {\r
+                                               h = hub;\r
+                                               AddRef(h->ref);\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(c->LocalBridgeList);\r
+       }\r
+       UnlockList(c->HubList);\r
+\r
+       // 早速ブリッジを開始する\r
+       if (h != NULL && br != NULL && h->Type != HUB_TYPE_FARM_DYNAMIC)\r
+       {\r
+               Lock(h->lock_online);\r
+               {\r
+                       if (h->Offline == false)\r
+                       {\r
+                               LockList(c->LocalBridgeList);\r
+                               {\r
+                                       if (IsInList(c->LocalBridgeList, br))\r
+                                       {\r
+                                               if (br->Bridge == NULL)\r
+                                               {\r
+                                                       br->Bridge = BrNewBridge(h, br->DeviceName, NULL, br->Local, br->Monitor, br->TapMode, br->TapMacAddress, br->FullBroadcast);\r
+                                               }\r
+                                       }\r
+                               }\r
+                               UnlockList(c->LocalBridgeList);\r
+                       }\r
+               }\r
+               Unlock(h->lock_online);\r
+       }\r
+\r
+       ReleaseHub(h);\r
+}\r
+\r
+// ローカルブリッジリストの初期化\r
+void InitLocalBridgeList(CEDAR *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->LocalBridgeList = NewList(NULL);\r
+}\r
+\r
+// ローカルブリッジリストの解放\r
+void FreeLocalBridgeList(CEDAR *c)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(c->LocalBridgeList);i++)\r
+       {\r
+               LOCALBRIDGE *br = LIST_DATA(c->LocalBridgeList, i);\r
+               Free(br);\r
+       }\r
+\r
+       ReleaseList(c->LocalBridgeList);\r
+       c->LocalBridgeList = NULL;\r
+}\r
+\r
+// ブリッジ用スレッド\r
+void BrBridgeThread(THREAD *thread, void *param)\r
+{\r
+       BRIDGE *b;\r
+       CONNECTION *c;\r
+       SESSION *s;\r
+       HUB *h;\r
+       char name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = (BRIDGE *)param;\r
+\r
+       // コネクションの作成\r
+       c = NewServerConnection(b->Cedar, NULL, thread);\r
+       c->Protocol = CONNECTION_HUB_BRIDGE;\r
+\r
+       // セッションの作成\r
+       s = NewServerSession(b->Cedar, c, b->Hub, BRIDGE_USER_NAME, b->Policy);\r
+       HLog(b->Hub, "LH_START_BRIDGE", b->Name, s->Name);\r
+       StrCpy(name, sizeof(name), b->Name);\r
+       h = b->Hub;\r
+       AddRef(h->ref);\r
+       s->BridgeMode = true;\r
+       s->Bridge = b;\r
+       c->Session = s;\r
+       ReleaseConnection(c);\r
+\r
+       // ユーザー名\r
+       s->Username = CopyStr(BRIDGE_USER_NAME_PRINT);\r
+\r
+       b->Session = s;\r
+       AddRef(s->ref);\r
+\r
+       // 初期化完了を通知\r
+       NoticeThreadInit(thread);\r
+\r
+       // セッションのメイン関数\r
+       Debug("Bridge %s Start.\n", b->Name);\r
+       SessionMain(s);\r
+       Debug("Bridge %s Stop.\n", b->Name);\r
+\r
+       HLog(h, "LH_STOP_BRIDGE", name);\r
+\r
+       ReleaseHub(h);\r
+\r
+       ReleaseSession(s);\r
+}\r
+\r
+// ブリッジの解放\r
+void BrFreeBridge(BRIDGE *b)\r
+{\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // セッション停止\r
+       StopSession(b->Session);\r
+       ReleaseSession(b->Session);\r
+       Free(b->Name);\r
+\r
+       Free(b);\r
+}\r
+\r
+// 新しいブリッジの作成\r
+BRIDGE *BrNewBridge(HUB *h, char *name, POLICY *p, bool local, bool monitor, bool tapmode, char *tapaddr, bool fullbcast)\r
+{\r
+       BRIDGE *b;\r
+       POLICY *policy;\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (h == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (p == NULL)\r
+       {\r
+               policy = ClonePolicy(GetDefaultPolicy());\r
+       }\r
+       else\r
+       {\r
+               policy = ClonePolicy(p);\r
+       }\r
+\r
+       policy->CheckMac = true;\r
+\r
+#ifdef UNIX_LINUX\r
+       policy->CheckMac = false;\r
+#endif // UNIX_LINUX\r
+\r
+       policy->NoBroadcastLimiter = true;\r
+\r
+       b = ZeroMalloc(sizeof(BRIDGE));\r
+       b->Cedar = h->Cedar;\r
+       b->Hub = h;\r
+       b->Name = CopyStr(name);\r
+       b->Policy = policy;\r
+       b->Local = local;\r
+       b->Monitor = monitor;\r
+       b->TapMode = tapmode;\r
+       b->FullBroadcast = fullbcast;\r
+\r
+       if (b->TapMode)\r
+       {\r
+               if (tapaddr != NULL && IsZero(tapaddr, 6) == false)\r
+               {\r
+                       Copy(b->TapMacAddress, tapaddr, 6);\r
+               }\r
+               else\r
+               {\r
+                       GenMacAddress(b->TapMacAddress);\r
+               }\r
+       }\r
+\r
+       if (monitor)\r
+       {\r
+               // モニタリングモード\r
+               policy->MonitorPort = true;\r
+       }\r
+\r
+       if (b->FullBroadcast)\r
+       {\r
+               // ブロードキャストを制限しない\r
+               policy->NoBroadcastLimiter = true;\r
+       }\r
+\r
+       // スレッド作成\r
+       t = NewThread(BrBridgeThread, b);\r
+       WaitThreadInit(t);\r
+       ReleaseThread(t);\r
+\r
+       return b;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Bridge.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Bridge.h
new file mode 100644 (file)
index 0000000..faa158f
--- /dev/null
@@ -0,0 +1,144 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Bridge.h\r
+// Bridge.c のヘッダ\r
+\r
+#ifndef        BRIDGE_H\r
+#define        BRIDGE_H\r
+\r
+#ifdef OS_WIN32\r
+\r
+// Win32 用\r
+#include <Cedar/BridgeWin32.h>\r
+\r
+#else\r
+\r
+// Unix 用\r
+#include <Cedar/BridgeUnix.h>\r
+\r
+#endif // OS_WIN32\r
+\r
+// ブリッジ\r
+struct BRIDGE\r
+{\r
+       bool Active;                    // 状態\r
+       CEDAR *Cedar;                   // Cedar\r
+       HUB *Hub;                               // HUB\r
+       SESSION *Session;               // セッション\r
+       POLICY *Policy;                 // ポリシー\r
+       ETH *Eth;                               // Ethernet\r
+       char *Name;                             // デバイス名\r
+       UINT64 LastBridgeTry;   // 最後にブリッジを試行した時刻\r
+       bool Local;                             // ローカルモード\r
+       bool Monitor;                   // モニタモード\r
+       bool TapMode;                   // tap モード\r
+       bool FullBroadcast;             // フルブロードキャスト\r
+       UCHAR TapMacAddress[6]; // tap の MAC アドレス\r
+       UINT LastNumDevice;             // デバイス個数 (最後にチェックした数)\r
+       UINT64 LastNumDeviceCheck;      // 最後にデバイスの個数をチェックした時刻\r
+       UINT64 LastChangeMtuError;      // 最後に MTU の変更エラーを記録した時刻\r
+};\r
+\r
+// ローカルブリッジ\r
+struct LOCALBRIDGE\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                      // 仮想 HUB 名\r
+       char DeviceName[MAX_SIZE];                                      // デバイス名\r
+       bool Local;                                                                     // ローカルモード\r
+       bool Monitor;                                                           // モニタモード\r
+       bool TapMode;                                                           // tap モード\r
+       bool FullBroadcast;                                                     // フルブロードキャストモード\r
+       UCHAR TapMacAddress[6];                                         // tap の MAC アドレス\r
+       BRIDGE *Bridge;                                                         // ブリッジ\r
+};\r
+\r
+BRIDGE *BrNewBridge(HUB *h, char *name, POLICY *p, bool local, bool monitor, bool tapmode, char *tapaddr, bool fullbcast);\r
+void BrBridgeThread(THREAD *thread, void *param);\r
+void BrFreeBridge(BRIDGE *b);\r
+void InitLocalBridgeList(CEDAR *c);\r
+void FreeLocalBridgeList(CEDAR *c);\r
+void AddLocalBridge(CEDAR *c, char *hubname, char *devicename, bool local, bool monitor, bool tapmode, char *tapaddr, bool fullbcast);\r
+bool DeleteLocalBridge(CEDAR *c, char *hubname, char *devicename);\r
+bool IsBridgeSupported();\r
+bool IsNeedWinPcap();\r
+UINT GetEthDeviceHash();\r
+\r
+#endif // BRIDGE_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/BridgeUnix.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/BridgeUnix.c
new file mode 100644 (file)
index 0000000..758e1f4
--- /dev/null
@@ -0,0 +1,1800 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// BridgeUnix.c\r
+// Ethernet ブリッジプログラム (UNIX 版)\r
+//#define      BRIDGE_C\r
+//#define      UNIX_LINUX\r
+\r
+#ifdef BRIDGE_C\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+\r
+#ifdef UNIX_SOLARIS\r
+#include <sys/sockio.h>\r
+#endif\r
+\r
+#ifdef BRIDGE_PCAP\r
+#include <pcap.h>\r
+#endif // BRIDGE_PCAP\r
+\r
+#ifdef BRIDGE_BPF\r
+#include <sys/ioctl.h>\r
+#include <net/bpf.h>\r
+#include <net/if_types.h>\r
+#include <net/if_dl.h>\r
+#include <ifaddrs.h>\r
+#endif // BRIDGE_BPF\r
+\r
+// 初期化\r
+void InitEth()\r
+{\r
+}\r
+\r
+// 解放\r
+void FreeEth()\r
+{\r
+}\r
+\r
+// Unix のデバイスの説明文字列の取得がサポートされているかどうか取得\r
+bool EthIsInterfaceDescriptionSupportedUnix()\r
+{\r
+       bool ret = false;\r
+       DIRLIST *d = EnumDir("/etc/sysconfig/networking/devices/");\r
+\r
+       if (d == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (d->NumFiles >= 1)\r
+       {\r
+               ret = true;\r
+       }\r
+\r
+       FreeDir(d);\r
+\r
+       return ret;\r
+}\r
+\r
+// Unix のデバイスの説明文字列を取得\r
+bool EthGetInterfaceDescriptionUnix(char *name, char *str, UINT size)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       bool ret = false;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (name == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(str, size, name);\r
+\r
+       Format(tmp, sizeof(tmp), "/etc/sysconfig/networking/devices/ifcfg-%s", name);\r
+\r
+       b = ReadDump(tmp);\r
+       if (b != NULL)\r
+       {\r
+               char *line = CfgReadNextLine(b);\r
+\r
+               if (IsEmptyStr(line) == false)\r
+               {\r
+                       if (StartWith(line, "#"))\r
+                       {\r
+                               char tmp[MAX_SIZE];\r
+\r
+                               StrCpy(tmp, sizeof(tmp), line + 1);\r
+\r
+                               Trim(tmp);\r
+                               tmp[60] = 0;\r
+\r
+                               StrCpy(str, size, tmp);\r
+\r
+                               ret = true;\r
+                       }\r
+               }\r
+\r
+               Free(line);\r
+\r
+               FreeBuf(b);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// Raw ソケットを開く\r
+int UnixEthOpenRawSocket()\r
+{\r
+#ifdef UNIX_LINUX\r
+       int s;\r
+\r
+       s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));\r
+       if (s < 0)\r
+       {\r
+               return INVALID_SOCKET;\r
+       }\r
+       else\r
+       {\r
+               return s;\r
+       }\r
+#else  // UNIX_LINUX\r
+       return -1;\r
+#endif // UNIX_LINUX\r
+}\r
+\r
+// Ethernet 操作がサポートされているかどうか\r
+bool IsEthSupported()\r
+{\r
+       bool ret = false;\r
+\r
+#if            defined(UNIX_LINUX)\r
+       ret = IsEthSupportedLinux();\r
+#elif  defined(UNIX_SOLARIS)\r
+       ret = IsEthSupportedSolaris();\r
+#elif  defined(BRIDGE_PCAP)\r
+       ret = true;\r
+#elif  defined(BRIDGE_BPF)\r
+       ret = true;\r
+#endif\r
+       return ret;\r
+}\r
+\r
+#ifdef UNIX_LINUX\r
+bool IsEthSupportedLinux()\r
+{\r
+       int s;\r
+\r
+       // Raw ソケットを開いてみる\r
+       s = UnixEthOpenRawSocket();\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               // 失敗\r
+               return false;\r
+       }\r
+\r
+       // 成功\r
+       closesocket(s);\r
+\r
+       return true;\r
+}\r
+#endif // UNIX_LINUX\r
+\r
+#ifdef UNIX_SOLARIS\r
+bool IsEthSupportedSolaris()\r
+{\r
+       return true;\r
+}\r
+#endif // UNIX_SOLARIS\r
+\r
+#ifdef UNIX_SOLARIS\r
+// アダプタ一覧を取得 (Solaris)\r
+TOKEN_LIST *GetEthListSolaris()\r
+{\r
+       TOKEN_LIST *t;\r
+       int i, s;\r
+       LIST *o;\r
+\r
+\r
+       o = NewListFast(CompareStr);\r
+       s = socket(AF_INET, SOCK_DGRAM, 0);\r
+       if (s != INVALID_SOCKET)\r
+       {\r
+               struct lifnum lifn;\r
+               lifn.lifn_family = AF_INET;\r
+               lifn.lifn_flags = 0;\r
+               if (ioctl(s, SIOCGLIFNUM, (char *)&lifn) >= 0)\r
+               {\r
+                       struct lifconf lifc;\r
+                       struct lifreq *buf;\r
+                       UINT numifs;\r
+                       UINT bufsize;\r
+                       \r
+                       numifs = lifn.lifn_count;\r
+                       Debug("NumIFs:%d\n",numifs);\r
+                       bufsize = numifs * sizeof(struct lifreq);\r
+                       buf = Malloc(bufsize);\r
+\r
+                       lifc.lifc_family = AF_INET;\r
+                       lifc.lifc_flags = 0;\r
+                       lifc.lifc_len = bufsize;\r
+                       lifc.lifc_buf = (char*) buf;\r
+                       if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) >= 0)\r
+                       {\r
+                               for (i = 0; i<numifs; i++)\r
+                               {\r
+                                       if(StartWith(buf[i].lifr_name, "lo") == false){\r
+                                               Add(o, CopyStr(buf[i].lifr_name));\r
+                                       }\r
+                               }\r
+                       }\r
+                       Free(buf);\r
+               }\r
+               closesocket(s);\r
+       }\r
+\r
+       Sort(o);\r
+\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               char *name = LIST_DATA(o, i);\r
+               t->Token[i] = name;\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       return t;\r
+}\r
+#endif // UNIX_SOLARIS\r
+\r
+#ifdef UNIX_LINUX\r
+// アダプタ一覧を取得 (Linux)\r
+TOKEN_LIST *GetEthListLinux()\r
+{\r
+       struct ifreq ifr;\r
+       TOKEN_LIST *t;\r
+       UINT i, n;\r
+       int s;\r
+       LIST *o;\r
+       char name[MAX_SIZE];\r
+\r
+       o = NewListFast(CompareStr);\r
+\r
+       s = UnixEthOpenRawSocket();\r
+       if (s != INVALID_SOCKET)\r
+       {\r
+               n = 0;\r
+               for (i = 0;;i++)\r
+               {\r
+                       Zero(&ifr, sizeof(ifr));\r
+                       ifr.ifr_ifindex = i;\r
+\r
+                       if (ioctl(s, SIOCGIFNAME, &ifr) >= 0)\r
+                       {\r
+                               n = 0;\r
+                               StrCpy(name, sizeof(name), ifr.ifr_name);\r
+\r
+                               Zero(&ifr, sizeof(ifr));\r
+                               StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), name);\r
+                               if (ioctl(s, SIOCGIFHWADDR, &ifr) >= 0)\r
+                               {\r
+                                       UINT type = ifr.ifr_hwaddr.sa_family;\r
+                                       if (type == 1 || type == 2 || type == 6 || type == 800 || type == 801)\r
+                                       {\r
+                                               if (IsInListStr(o, name) == false)\r
+                                               {\r
+                                                       if (StartWith(name, "tap_") == false)\r
+                                                       {\r
+                                                               Add(o, CopyStr(name));\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               n++;\r
+                               if (n >= 64)\r
+                               {\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+               closesocket(s);\r
+       }\r
+\r
+       Sort(o);\r
+\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               char *name = LIST_DATA(o, i);\r
+               t->Token[i] = name;\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       return t;\r
+}\r
+#endif // UNIX_LINUX\r
+\r
+#ifdef BRIDGE_PCAP\r
+// アダプタ一覧を取得 (Pcap)\r
+TOKEN_LIST *GetEthListPcap()\r
+{\r
+       pcap_if_t *alldevs;\r
+       char errbuf[PCAP_ERRBUF_SIZE];\r
+       LIST *o;\r
+       TOKEN_LIST *t;\r
+       int i;\r
+\r
+       o = NewListFast(CompareStr);\r
+\r
+       if( pcap_findalldevs(&alldevs,errbuf) != -1)\r
+       {\r
+               pcap_if_t *dev = alldevs;\r
+               while(dev != NULL)\r
+               {\r
+                       pcap_t *p;\r
+                       // デバイスを開いてみないとデバイスの種類が分からない?\r
+                       p = pcap_open_live(dev->name, 0, false, 0, errbuf);\r
+                       if(p != NULL)\r
+                       {\r
+                               int datalink = pcap_datalink(p);\r
+       //                      Debug("type:%s\n",pcap_datalink_val_to_name(datalink));\r
+                               pcap_close(p);\r
+                               if(datalink == DLT_EN10MB){\r
+                                       // イーサネットデバイスのみ列挙する\r
+                                       Add(o, CopyStr(dev->name));\r
+                               }\r
+                       }\r
+                       dev = dev->next;\r
+               }\r
+               pcap_freealldevs(alldevs);\r
+       }\r
+       \r
+       Sort(o);\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               t->Token[i] = LIST_DATA(o, i);\r
+       }\r
+       ReleaseList(o);\r
+       return t;\r
+}\r
+#endif // BRIDGE_PCAP\r
+\r
+#ifdef BRIDGE_BPF\r
+// アダプタ一覧を取得 (BPF)\r
+TOKEN_LIST *GetEthListBpf()\r
+{\r
+       struct ifaddrs *ifadrs;\r
+       struct sockaddr_dl *sockadr;\r
+       LIST *o;\r
+       TOKEN_LIST *t;\r
+       int i;\r
+\r
+       o = NewListFast(CompareStr);\r
+\r
+       // ネットワークデバイスの一覧を取得\r
+       if(getifaddrs( &ifadrs ) == 0)\r
+       {\r
+               struct ifaddrs *ifadr = ifadrs;\r
+               while(ifadr)\r
+               {\r
+                       sockadr = (struct sockaddr_dl*)ifadr->ifa_addr;\r
+                       if(sockadr->sdl_family == AF_LINK && sockadr->sdl_type == IFT_ETHER)\r
+                       {\r
+                               // Ethernet デバイスか?\r
+                               if(!IsInListStr(o,ifadr->ifa_name))\r
+                               {\r
+                                       // 既存でなければ追加(複数のMACアドレスを持つインターフェースへの対策)\r
+                                       Add(o, CopyStr(ifadr->ifa_name));\r
+                               }\r
+                       }\r
+                       ifadr = ifadr -> ifa_next;\r
+               }\r
+               freeifaddrs(ifadrs);\r
+       }\r
+\r
+       Sort(o);\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               t->Token[i] = LIST_DATA(o, i);\r
+       }\r
+       ReleaseList(o);\r
+       return t;\r
+}\r
+#endif // BRIDGE_BPF\r
+\r
+// アダプタ一覧を取得\r
+TOKEN_LIST *GetEthList()\r
+{\r
+       TOKEN_LIST *t = NULL;\r
+\r
+#if    defined(UNIX_LINUX)\r
+       t = GetEthListLinux();\r
+#elif  defined(UNIX_SOLARIS)\r
+       t = GetEthListSolaris();\r
+#elif  defined(BRIDGE_PCAP)\r
+       t = GetEthListPcap();\r
+#elif  defined(BRIDGE_BPF)\r
+       t = GetEthListBpf();\r
+#endif\r
+\r
+       return t;\r
+}\r
+\r
+#ifdef UNIX_LINUX\r
+// アダプタを開く (Linux)\r
+ETH *OpenEthLinux(char *name, bool local, bool tapmode, char *tapaddr)\r
+{\r
+       ETH *e;\r
+       struct ifreq ifr;\r
+       struct sockaddr_ll addr;\r
+       int s;\r
+       int index;\r
+       CANCEL *c;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (tapmode)\r
+       {\r
+#ifndef        NO_VLAN\r
+               // tap モードの場合\r
+               VLAN *v = NewTap(name, tapaddr);\r
+               if (v == NULL)\r
+               {\r
+                       return NULL;\r
+               }\r
+\r
+               e = ZeroMalloc(sizeof(ETH));\r
+               e->Name = CopyStr(name);\r
+               e->Title = CopyStr(name);\r
+               e->Cancel = VLanGetCancel(v);\r
+               e->IfIndex = 0;\r
+               e->Socket = INVALID_SOCKET;\r
+               e->Tap = v;\r
+\r
+               return e;\r
+#else  // NO_VLAN\r
+               return NULL;\r
+#endif // NO_VLAN\r
+       }\r
+\r
+       s = UnixEthOpenRawSocket();\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&ifr, sizeof(ifr));\r
+       StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), name);\r
+\r
+       if (ioctl(s, SIOCGIFINDEX, &ifr) < 0)\r
+       {\r
+               closesocket(s);\r
+               return NULL;\r
+       }\r
+\r
+       index = ifr.ifr_ifindex;\r
+\r
+       Zero(&addr, sizeof(addr));\r
+       addr.sll_family = PF_PACKET;\r
+       addr.sll_protocol = htons(ETH_P_ALL);\r
+       addr.sll_ifindex = index;\r
+\r
+       if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0)\r
+       {\r
+               closesocket(s);\r
+               return NULL;\r
+       }\r
+\r
+       if (local == false)\r
+       {\r
+               // プロミスキャスモードに設定する\r
+               Zero(&ifr, sizeof(ifr));\r
+               StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), name);\r
+               if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)\r
+               {\r
+                       // 失敗\r
+                       closesocket(s);\r
+                       return NULL;\r
+               }\r
+\r
+               ifr.ifr_flags |= IFF_PROMISC;\r
+\r
+               if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0)\r
+               {\r
+                       // 失敗\r
+                       closesocket(s);\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       e = ZeroMalloc(sizeof(ETH));\r
+       e->Name = CopyStr(name);\r
+       e->Title = CopyStr(name);\r
+       e->IfIndex = index;\r
+       e->Socket = s;\r
+\r
+       c = NewCancel();\r
+       UnixDeletePipe(c->pipe_read, c->pipe_write);\r
+       c->pipe_read = c->pipe_write = -1;\r
+\r
+       UnixSetSocketNonBlockingMode(s, true);\r
+\r
+       c->SpecialFlag = true;\r
+       c->pipe_read = s;\r
+\r
+       e->Cancel = c;\r
+\r
+       // MTU の取得\r
+       e->InitialMtu = EthGetMtu(e);\r
+\r
+       return e;\r
+}\r
+#endif // UNIX_LINUX\r
+\r
+// MTU の値を取得\r
+UINT EthGetMtu(ETH *e)\r
+{\r
+#if    defined(UNIX_LINUX) || defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+       UINT ret = 0;\r
+#ifdef UNIX_SOLARIS\r
+       struct lifreq ifr;\r
+#else  // UNIX_SOLARIS\r
+       struct ifreq ifr;\r
+#endif // UNIX_SOLARIS\r
+       int s;\r
+       // 引数チェック\r
+       if (e == NULL || e->Tap != NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (e->CurrentMtu != 0)\r
+       {\r
+               return e->CurrentMtu;\r
+       }\r
+\r
+#if    defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+       s = e->SocketBsdIf;\r
+#else  // defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+       s = e->Socket;\r
+#endif // defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+\r
+       Zero(&ifr, sizeof(ifr));\r
+\r
+#ifdef UNIX_SOLARIS\r
+       StrCpy(ifr.lifr_name, sizeof(ifr.lifr_name), e->Name);\r
+#else  // UNIX_SOLARIS\r
+       StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), e->Name);\r
+#endif // UNIX_SOLARIS\r
+\r
+#ifdef UNIX_SOLARIS\r
+       if (ioctl(s, SIOCGLIFMTU, &ifr) < 0)\r
+       {\r
+               // 失敗\r
+               return 0;\r
+       }\r
+#else  // UNIX_SOLARIS\r
+       if (ioctl(s, SIOCGIFMTU, &ifr) < 0)\r
+       {\r
+               // 失敗\r
+               return 0;\r
+       }\r
+#endif // UNIX_SOLARIS\r
+\r
+#ifdef UNIX_SOLARIS\r
+       ret = ifr.lifr_mtu + 14;\r
+#else  // UNIX_SOLARIS\r
+       ret = ifr.ifr_mtu + 14;\r
+#endif // UNIX_SOLARIS\r
+\r
+       e->CurrentMtu = ret;\r
+\r
+       Debug("%s: GetMtu: %u\n", e->Name, ret);\r
+\r
+       return ret;\r
+#else  // defined(UNIX_LINUX) || defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+       return 0;\r
+#endif // defined(UNIX_LINUX) || defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+}\r
+\r
+// MTU の値を設定\r
+bool EthSetMtu(ETH *e, UINT mtu)\r
+{\r
+#if    defined(UNIX_LINUX) || defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+       UINT ret = 0;\r
+#ifdef UNIX_SOLARIS\r
+       struct lifreq ifr;\r
+#else  // UNIX_SOLARIS\r
+       struct ifreq ifr;\r
+#endif // UNIX_SOLARIS\r
+       int s;\r
+       // 引数チェック\r
+       if (e == NULL || e->Tap != NULL || (mtu > 1 && mtu < 1514))\r
+       {\r
+               return false;\r
+       }\r
+       if (mtu == 0 && e->InitialMtu == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (mtu == 0)\r
+       {\r
+               // mtu == 0 の場合は MTU の値を元に戻す\r
+               mtu = e->InitialMtu;\r
+       }\r
+\r
+#if    defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+       s = e->SocketBsdIf;\r
+#else  // defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+       s = e->Socket;\r
+#endif // defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+\r
+       if (e->CurrentMtu == mtu)\r
+       {\r
+               // 変更の必要なし\r
+               return true;\r
+       }\r
+\r
+       Zero(&ifr, sizeof(ifr));\r
+\r
+#ifdef UNIX_SOLARIS\r
+       StrCpy(ifr.lifr_name, sizeof(ifr.lifr_name), e->Name);\r
+       ifr.lifr_mtu = mtu - 14;\r
+#else  // UNIX_SOLARIS\r
+       StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), e->Name);\r
+       ifr.ifr_mtu = mtu - 14;\r
+#endif // UNIX_SOLARIS\r
+\r
+#ifdef UNIX_SOLARIS\r
+       if (ioctl(s, SIOCSLIFMTU, &ifr) < 0)\r
+       {\r
+               // 失敗\r
+               return false;\r
+       }\r
+#else  // UNIX_SOLARIS\r
+       if (ioctl(s, SIOCSIFMTU, &ifr) < 0)\r
+       {\r
+               // 失敗\r
+               return false;\r
+       }\r
+#endif // UNIX_SOLARIS\r
+\r
+       e->CurrentMtu = mtu;\r
+\r
+       Debug("%s: SetMtu: %u\n", e->Name, mtu);\r
+\r
+       return true;\r
+#else  // defined(UNIX_LINUX) || defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+       return false;\r
+#endif // defined(UNIX_LINUX) || defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+}\r
+\r
+// MTU の値の変更がサポートされているかどうか取得\r
+bool EthIsChangeMtuSupported(ETH *e)\r
+{\r
+#if    defined(UNIX_LINUX) || defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+       // 引数チェック\r
+       if (e == NULL || e->Tap != NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+#else  // defined(UNIX_LINUX) || defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+       return false;\r
+#endif // defined(UNIX_LINUX) || defined(UNIX_BSD) || defined(UNIX_SOLARIS)\r
+}\r
+\r
+#ifdef UNIX_SOLARIS\r
+// アダプタを開く (Solaris)\r
+ETH *OpenEthSolaris(char *name, bool local, bool tapmode, char *tapaddr)\r
+{\r
+       char devname[MAX_SIZE];\r
+       UINT devid;\r
+       int fd;\r
+       ETH *e;\r
+       CANCEL *c;\r
+       struct strioctl sioc;\r
+\r
+       // 引数チェック\r
+       if (name == NULL || tapmode != false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // デバイス名を解析\r
+       if (ParseUnixEthDeviceName(devname, sizeof(devname), &devid, name) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // デバイスを開く\r
+       fd = open(devname, O_RDWR);\r
+       if (fd == -1)\r
+       {\r
+               // 失敗\r
+               return NULL;\r
+       }\r
+\r
+       // デバイスにアタッチする\r
+       if (DlipAttatchRequest(fd, devid) == false)\r
+       {\r
+               // 失敗\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+\r
+       // 確認\r
+       if (DlipReceiveAck(fd) == false)\r
+       {\r
+               // 失敗\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+\r
+       // SAPにバインドする\r
+       if (DlipBindRequest(fd) == false)\r
+       {\r
+               // 失敗\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+\r
+       // 確認\r
+       if (DlipReceiveAck(fd) == false)\r
+       {\r
+               // 失敗\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+\r
+       // SAPに関わらず受信するモードにセットする\r
+       if (DlipPromiscuous(fd, DL_PROMISC_SAP) == false)\r
+       {\r
+               // 失敗\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+\r
+       // 確認\r
+       if (DlipReceiveAck(fd) == false)\r
+       {\r
+               // 失敗\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+\r
+       // 自分の送信するパケットも受信するモードにセットする\r
+       if (DlipPromiscuous(fd, DL_PROMISC_PHYS) == false)\r
+       {\r
+               // 失敗\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+\r
+       // 確認\r
+       if (DlipReceiveAck(fd) == false)\r
+       {\r
+               // 失敗\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+\r
+       // Raw モードに設定\r
+       sioc.ic_cmd = DLIOCRAW;\r
+       sioc.ic_timout = -1;\r
+       sioc.ic_len = 0;\r
+       sioc.ic_dp = NULL;\r
+       if (ioctl(fd, I_STR, &sioc) < 0)\r
+       {\r
+               // 失敗\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+\r
+       if (ioctl(fd, I_FLUSH, FLUSHR) < 0)\r
+       {\r
+               // 失敗\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+\r
+       e = ZeroMalloc(sizeof(ETH));\r
+       e->Name = CopyStr(name);\r
+       e->Title = CopyStr(name);\r
+\r
+       c = NewCancel();\r
+       UnixDeletePipe(c->pipe_read, c->pipe_write);\r
+       c->pipe_read = c->pipe_write = -1;\r
+\r
+       c->SpecialFlag = true;\r
+       c->pipe_read = fd;\r
+\r
+       e->Cancel = c;\r
+\r
+       e->IfIndex = -1;\r
+       e->Socket = fd;\r
+\r
+       UnixSetSocketNonBlockingMode(fd, true);\r
+\r
+       // 操作用 I/F の取得\r
+       e->SocketBsdIf = socket(AF_INET, SOCK_DGRAM, 0);\r
+\r
+       // MTU の取得\r
+       e->InitialMtu = EthGetMtu(e);\r
+\r
+       return e;\r
+}\r
+\r
+// プロミスキャスモードにセットする\r
+bool DlipPromiscuous(int fd, UINT level)\r
+{\r
+       dl_promiscon_req_t req;\r
+       struct strbuf ctl;\r
+       int flags;\r
+       // 引数チェック\r
+       if (fd == -1)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&req, sizeof(req));\r
+       req.dl_primitive = DL_PROMISCON_REQ;\r
+       req.dl_level = level;\r
+\r
+       Zero(&ctl, sizeof(ctl));\r
+       ctl.maxlen = 0;\r
+       ctl.len = sizeof(req);\r
+       ctl.buf = (char *)&req;\r
+\r
+       flags = 0;\r
+\r
+       if (putmsg(fd, &ctl, NULL, flags) < 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// SAPにバインドする\r
+bool DlipBindRequest(int fd)\r
+{\r
+       dl_bind_req_t   req;\r
+       struct strbuf ctl;\r
+\r
+       if (fd == -1)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&req, sizeof(req));\r
+       req.dl_primitive = DL_BIND_REQ;\r
+       req.dl_service_mode = DL_CLDLS;\r
+       req.dl_sap = 0;\r
+\r
+       Zero(&ctl, sizeof(ctl));\r
+       ctl.maxlen = 0;\r
+       ctl.len = sizeof(req);\r
+       ctl.buf = (char *)&req;\r
+\r
+       if (putmsg(fd, &ctl, NULL, 0) < 0)\r
+       {\r
+               return false;\r
+       }\r
+       return true;\r
+}\r
+\r
+// デバイスにアタッチする\r
+bool DlipAttatchRequest(int fd, UINT devid)\r
+{\r
+       dl_attach_req_t req;\r
+       struct strbuf ctl;\r
+       int flags;\r
+       // 引数チェック\r
+       if (fd == -1)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&req, sizeof(req));\r
+       req.dl_primitive = DL_ATTACH_REQ;\r
+       req.dl_ppa = devid;\r
+\r
+       Zero(&ctl, sizeof(ctl));\r
+       ctl.maxlen = 0;\r
+       ctl.len = sizeof(req);\r
+       ctl.buf = (char *)&req;\r
+\r
+       flags = 0;\r
+\r
+       if (putmsg(fd, &ctl, NULL, flags) < 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 確認応答を受信する\r
+bool DlipReceiveAck(int fd)\r
+{\r
+       union DL_primitives *dlp;\r
+       struct strbuf ctl;\r
+       int flags = 0;\r
+       char *buf;\r
+       // 引数チェック\r
+       if (fd == -1)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       buf = MallocFast(SOLARIS_MAXDLBUF);\r
+\r
+       Zero(&ctl, sizeof(ctl));\r
+       ctl.maxlen = SOLARIS_MAXDLBUF;\r
+       ctl.len = 0;\r
+       ctl.buf = buf;\r
+\r
+       if (getmsg(fd, &ctl, NULL, &flags) < 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       dlp = (union DL_primitives *)ctl.buf;\r
+       if (dlp->dl_primitive != (UINT)DL_OK_ACK && dlp->dl_primitive != (UINT)DL_BIND_ACK)\r
+       {\r
+               Free(buf);\r
+               return false;\r
+       }\r
+\r
+       Free(buf);\r
+\r
+       return true;\r
+}\r
+\r
+#endif // UNIX_SOLARIS\r
+\r
+// UNIX のデバイス名文字列をデバイス名と番号に分ける\r
+bool ParseUnixEthDeviceName(char *dst_devname, UINT dst_devname_size, UINT *dst_devid, char *src_name)\r
+{\r
+       UINT len, i, j;\r
+\r
+       // 引数チェック\r
+       if (dst_devname == NULL || dst_devid == NULL || src_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       len = strlen(src_name);\r
+       // 文字列長チェック\r
+       if(len == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = len-1; i+1 != 0; i--)\r
+       {\r
+               // 末尾からたどって最初に数字でない文字を検出\r
+               if (src_name[i] < '0' || '9' < src_name[i])\r
+               {\r
+                       // 最後の文字が数字でなければエラー\r
+                       if(src_name[i+1]==0)\r
+                       {\r
+                               return false;\r
+                       }\r
+                       *dst_devid = ToInt(src_name + i + 1);\r
+                       StrCpy(dst_devname, dst_devname_size, "/dev/");\r
+                       for (j = 0; j<i+1 && j<dst_devname_size-6; j++)\r
+                       {\r
+                               dst_devname[j+5] = src_name[j];\r
+                       }\r
+                       dst_devname[j+5]=0;\r
+                       return true;\r
+               }\r
+       }\r
+       // 全て数字ならエラー\r
+       return false;\r
+}\r
+\r
+#if defined(BRIDGE_BPF) || defined(BRIDGE_PCAP)\r
+// キャプチャしたパケットデータ構造体の初期化\r
+struct CAPTUREBLOCK *NewCaptureBlock(UCHAR *data, UINT size){\r
+       struct CAPTUREBLOCK *block = Malloc(sizeof(struct CAPTUREBLOCK));\r
+       block->Buf = data;\r
+       block->Size = size;\r
+       return block;\r
+}\r
+\r
+// キャプチャしたパケットデータ構造体の開放\r
+void FreeCaptureBlock(struct CAPTUREBLOCK *block){\r
+       Free(block);\r
+}\r
+#endif // BRIDGE_BPF || BRIDGE_PCAP\r
+\r
+#ifdef BRIDGE_PCAP\r
+// パケット到着のコールバック関数\r
+void PcapHandler(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes)\r
+{\r
+       ETH *e = (ETH*) user;\r
+       struct CAPTUREBLOCK *block;\r
+       UCHAR *data;\r
+       \r
+       data = Malloc(h->caplen);\r
+       Copy(data, bytes, h->caplen);\r
+       block = NewCaptureBlock(data, h->caplen);\r
+       LockQueue(e->Queue);\r
+       // キューのサイズが限界を超えたらパケットを破棄する。\r
+       if(e->QueueSize < BRIDGE_MAX_QUEUE_SIZE){\r
+               InsertQueue(e->Queue, block);\r
+               e->QueueSize += h->caplen;\r
+       }\r
+       UnlockQueue(e->Queue);\r
+       Cancel(e->Cancel);\r
+       return;\r
+}\r
+\r
+\r
+// Pcap でのパケットキャプチャの中継用スレッド\r
+void PcapThread(THREAD *thread, void *param)\r
+{\r
+       ETH *e = (ETH*)param;\r
+       pcap_t *p = e->Pcap;\r
+       int ret;\r
+\r
+       // 初期化完了を通知\r
+       NoticeThreadInit(thread);\r
+\r
+       // 帰り値 -1:エラー -2:外部からの終了\r
+       ret = pcap_loop(p, -1, PcapHandler, (u_char*) e);\r
+       if(ret == -1){\r
+               e->Socket = INVALID_SOCKET;\r
+               pcap_perror(p, "capture");\r
+       }\r
+       return;\r
+}\r
+\r
+\r
+// アダプタを開く (Pcap)\r
+ETH *OpenEthPcap(char *name, bool local, bool tapmode, char *tapaddr)\r
+{\r
+       char errbuf[PCAP_ERRBUF_SIZE];\r
+       ETH *e;\r
+       pcap_t *p;\r
+       CANCEL *c;\r
+\r
+       // 引数チェック\r
+       if (name == NULL || tapmode != false)\r
+       {\r
+               return NULL;\r
+       }\r
+       \r
+       // エラーメッセージバッファの初期化\r
+       errbuf[0] = 0;\r
+\r
+       // キャプチャデバイスを開く\r
+       p = pcap_open_live(name, 65535, (local == false), 1, errbuf);\r
+       if(p==NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // ノンブロックモードに設定\r
+       // BSD系OSでは、BPFのselectが正常に動作しないのでブロックさせないとビジーループになる\r
+       /*\r
+       if(pcap_setnonblock(p, true, errbuf) == -1)\r
+       {\r
+               Debug("pcap_setnonblock:%s\n",errbuf);\r
+               pcap_close(p);\r
+               return NULL;\r
+       }\r
+       */\r
+       \r
+       e = ZeroMalloc(sizeof(ETH));\r
+       e->Name = CopyStr(name);\r
+       e->Title = CopyStr(name);\r
+       e->Queue = NewQueue();\r
+       e->QueueSize = 0;\r
+       e->Cancel = NewCancel();\r
+       e->IfIndex = -1;\r
+       e->Socket = pcap_get_selectable_fd(p);\r
+       e->Pcap = p;\r
+       \r
+       e->CaptureThread = NewThread(PcapThread, e);\r
+       WaitThreadInit(e->CaptureThread);\r
+\r
+       return e;\r
+}\r
+#endif // BRIDGE_PCAP\r
+\r
+#ifdef BRIDGE_BPF\r
+#ifdef BRIDGE_BPF_THREAD\r
+// BPF でのパケットキャプチャの中継用スレッド\r
+void BpfThread(THREAD *thread, void *param)\r
+{\r
+       ETH *e = (ETH*)param;\r
+       int fd = e->Socket;\r
+       int len;\r
+       int rest;       // バッファ中の残りバイト数\r
+       UCHAR *next;    //バッファ中の次のパケットの先頭\r
+       struct CAPTUREBLOCK *block;     // キューに追加するデータ\r
+       UCHAR *data;\r
+       struct bpf_hdr *hdr;\r
+\r
+       // バッファを確保\r
+       UCHAR *buf = Malloc(e->BufSize);\r
+       \r
+       // 初期化完了を通知\r
+       NoticeThreadInit(thread);\r
+\r
+       while(1){\r
+               // ループの脱出判定\r
+               if(e->Socket == INVALID_SOCKET){\r
+                       break;\r
+               }\r
+               \r
+               rest = read(fd, buf, e->BufSize);\r
+               if(rest < 0 && errno != EAGAIN){\r
+                       // エラー\r
+                       close(fd);\r
+                       e->Socket = INVALID_SOCKET;\r
+                       Free(buf);\r
+                       Cancel(e->Cancel);\r
+                       return;\r
+               }\r
+               next = buf;\r
+               LockQueue(e->Queue);\r
+               while(rest>0){\r
+                       // パケットの切り出し\r
+                       hdr = (struct bpf_hdr*)next;\r
+\r
+                       // Queue中のパケットサイズが限界を超えたらパケットを破棄する\r
+                       if(e->QueueSize < BRIDGE_MAX_QUEUE_SIZE){\r
+                               data = Malloc(hdr->bh_caplen);\r
+                               Copy(data, next+(hdr->bh_hdrlen), hdr->bh_caplen);\r
+                               block = NewCaptureBlock(data, hdr->bh_caplen);\r
+                               InsertQueue(e->Queue, block);\r
+                               e->QueueSize += hdr->bh_caplen;\r
+                       }\r
+\r
+                       // 次のパケットの頭出し\r
+                       rest -= BPF_WORDALIGN(hdr->bh_hdrlen + hdr->bh_caplen);\r
+                       next += BPF_WORDALIGN(hdr->bh_hdrlen + hdr->bh_caplen);\r
+               }\r
+               UnlockQueue(e->Queue);\r
+               Cancel(e->Cancel);\r
+       }\r
+       Free(buf);\r
+       Cancel(e->Cancel);\r
+       return;\r
+}\r
+#endif // BRIDGE_BPF_THREAD\r
+\r
+// アダプタを開く (BPF)\r
+ETH *OpenEthBpf(char *name, bool local, bool tapmode, char *tapaddr)\r
+{\r
+       ETH *e;\r
+       CANCEL *c;\r
+       char devname[MAX_SIZE];\r
+       int n = 0;\r
+       int fd;\r
+       int ret;\r
+       UINT bufsize;\r
+       struct ifreq ifr;\r
+       struct timeval to;\r
+       \r
+       // 未使用の bpf デバイスを探して開く\r
+       do{\r
+               Format(devname, sizeof(devname), "/dev/bpf%d", n++);\r
+               fd = open (devname, O_RDWR);\r
+               if(fd<0){\r
+                       perror("open");\r
+               }\r
+       }while(fd < 0 && errno == EBUSY);\r
+       \r
+       // 開くことが出来るbpfデバイスが無ければエラー\r
+       if(fd < 0){\r
+               Debug("BPF: No minor number are free.\n");\r
+               return NULL;\r
+       }\r
+       \r
+       // バッファサイズを拡大\r
+       n = 524288; // なんとなく(libpcapでは32768だった)\r
+       while(true){\r
+               // バッファサイズを指定\r
+               ioctl(fd, BIOCSBLEN, &n);\r
+\r
+               // ネットワークをバインド\r
+               StrCpy(ifr.ifr_name, IFNAMSIZ, name);\r
+               ret = ioctl(fd, BIOCSETIF, &ifr);\r
+               if(ret < 0){\r
+                       if(ret == ENOBUFS && n>1500){\r
+                               // バッファサイズが不適切\r
+                               // サイズを半分にしてリトライ\r
+                               // バッファサイズ1500バイト以下でエラーになるのは何かおかしい\r
+                               n /= 2;\r
+                               continue;\r
+                       }\r
+                       Debug("bpf: binding network failed.\n");\r
+                       close(fd);\r
+                       return NULL;\r
+               }else{\r
+                       break;\r
+               }\r
+       }\r
+       bufsize = n;\r
+\r
+       // プロミスキャスモードに設定\r
+       if(local == false){\r
+               if (ioctl(fd, BIOCPROMISC, NULL) < 0){\r
+                       printf("bpf: promisc mode failed.\n");\r
+                       close(fd);\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       \r
+       // 即時モードに設定(パケットを受信するとタイムアウトを待たず、すぐにreadがreturnする)\r
+       n = 1;\r
+       if (ioctl(fd, BIOCIMMEDIATE, &n) < 0){\r
+               Debug("BPF: non-block mode failed.\n");\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+\r
+       // 自分が送信するパケットも受信する\r
+       n = 1;\r
+       if (ioctl(fd, BIOCGSEESENT, &n) < 0){\r
+               Debug("BPF: see sent mode failed.\n");\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+\r
+\r
+       // ヘッダ完全モード(送信するパケットのヘッダも自分で生成する)\r
+       n = 1;\r
+       if (ioctl(fd, BIOCSHDRCMPLT, &n) < 0){\r
+               Debug("BPF: Header complete mode failed.\n");\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+       \r
+       // read のタイムアウト時間を設定(1秒)\r
+       to.tv_sec = 1;\r
+       to.tv_usec = 0;\r
+       if (ioctl(fd, BIOCSRTIMEOUT, &to) < 0){\r
+               Debug("BPF: Read timeout setting failed.\n");\r
+               close(fd);\r
+               return NULL;\r
+       }\r
+       \r
+       e = ZeroMalloc(sizeof(ETH));\r
+       e->Name = CopyStr(name);\r
+       e->Title = CopyStr(name);\r
+       e->IfIndex = -1;\r
+       e->Socket = fd;\r
+       e->BufSize = bufsize;\r
+\r
+#ifdef BRIDGE_BPF_THREAD\r
+       e->Queue = NewQueue();\r
+       e->QueueSize = 0;\r
+       e->Cancel = NewCancel();\r
+\r
+       // キャプチャ用スレッドの開始\r
+       e->CaptureThread = NewThread(BpfThread, e);\r
+       WaitThreadInit(e->CaptureThread);\r
+\r
+#else // BRIDGE_BPF_THREAD\r
+       c = NewCancel();\r
+       UnixDeletePipe(c->pipe_read, c->pipe_write);\r
+       c->pipe_read = c->pipe_write = -1;\r
+       c->SpecialFlag = true;\r
+       c->pipe_read = fd;\r
+       e->Cancel = c;\r
+       e->Buffer = Malloc(bufsize);\r
+       e->Next = e->Buffer;\r
+       e->Rest = 0;\r
+\r
+       // ノンブロッキングモードに設定\r
+       UnixSetSocketNonBlockingMode(fd, true);\r
+#endif // BRIDGE_BPF_THREAD\r
+\r
+       // FreeBSD 用インターフェイス操作用ソケットを作成\r
+       e->SocketBsdIf = socket(AF_LOCAL, SOCK_DGRAM, 0);\r
+\r
+       // MTU の取得\r
+       e->InitialMtu = EthGetMtu(e);\r
+\r
+       return e;\r
+}\r
+#endif // BRIDGE_BPF\r
+\r
+// アダプタを開く\r
+ETH *OpenEth(char *name, bool local, bool tapmode, char *tapaddr)\r
+{\r
+       ETH *ret = NULL;\r
+\r
+#if            defined(UNIX_LINUX)\r
+       ret = OpenEthLinux(name, local, tapmode, tapaddr);\r
+#elif  defined(UNIX_SOLARIS)\r
+       ret = OpenEthSolaris(name, local, tapmode, tapaddr);\r
+#elif  defined(BRIDGE_PCAP)\r
+       ret = OpenEthPcap(name, local, tapmode, tapaddr);\r
+#elif  defined(BRIDGE_BPF)\r
+       ret = OpenEthBpf(name, local, tapmode, tapaddr);\r
+#endif\r
+\r
+       return ret;\r
+}\r
+\r
+typedef struct UNIXTHREAD\r
+{\r
+       pthread_t thread;\r
+       bool finished;\r
+} UNIXTHREAD;\r
+\r
+// アダプタを閉じる\r
+void CloseEth(ETH *e)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (e->Tap != NULL)\r
+       {\r
+#ifndef        NO_VLAN\r
+               FreeTap(e->Tap);\r
+#endif // NO_VLAN\r
+       }\r
+\r
+#ifdef BRIDGE_PCAP\r
+       {\r
+               struct CAPTUREBLOCK *block;\r
+               pcap_breakloop(e->Pcap);\r
+               WaitThread(e->CaptureThread, INFINITE);\r
+               ReleaseThread(e->CaptureThread);\r
+               pcap_close(e->Pcap);\r
+               while (block = GetNext(e->Queue)){\r
+                       Free(block->Buf);\r
+                       FreeCaptureBlock(block);\r
+               }\r
+               ReleaseQueue(e->Queue);\r
+       }\r
+#endif // BRIDGE_PCAP\r
+\r
+#ifdef BRIDGE_BPF\r
+#ifdef BRIDGE_BPF_THREAD\r
+       {\r
+               struct CAPTUREBLOCK *block;\r
+               int fd = e->Socket;\r
+               e->Socket = INVALID_SOCKET;\r
+               WaitThread(e->CaptureThread, INFINITE);\r
+               ReleaseThread(e->CaptureThread);\r
+               e->Socket = fd; // 後でcloseするために復帰\r
+               while (block = GetNext(e->Queue)){\r
+                       Free(block->Buf);\r
+                       FreeCaptureBlock(block);\r
+               }\r
+               ReleaseQueue(e->Queue);\r
+       }\r
+#else // BRIDGE_BPF_THREAD\r
+       Free(e->Buffer);\r
+#endif // BRIDGE_BPF_THREAD\r
+#endif // BRIDGE_BPF\r
+\r
+       ReleaseCancel(e->Cancel);\r
+       Free(e->Name);\r
+       Free(e->Title);\r
+\r
+       // MTU の値を元に戻す\r
+       EthSetMtu(e, 0);\r
+\r
+       if (e->Socket != INVALID_SOCKET)\r
+       {\r
+#if defined(BRIDGE_BPF) || defined(BRIDGE_PCAP) || defined(UNIX_SOLARIS)\r
+               close(e->Socket);\r
+#else // BRIDGE_PCAP\r
+               closesocket(e->Socket);\r
+#endif // BRIDGE_PCAP\r
+#if defined(BRIDGE_BPF) || defined(UNIX_SOLARIS)\r
+               if (e->SocketBsdIf != INVALID_SOCKET)\r
+               {\r
+                       close(e->SocketBsdIf);\r
+               }\r
+#endif // BRIDGE_BPF || UNIX_SOLARIS\r
+       }\r
+\r
+       Free(e);\r
+}\r
+\r
+// キャンセルオブジェクトの取得\r
+CANCEL *EthGetCancel(ETH *e)\r
+{\r
+       CANCEL *c;\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       c = e->Cancel;\r
+       AddRef(c->ref);\r
+\r
+       return c;\r
+}\r
+\r
+// パケットの読み込み\r
+UINT EthGetPacket(ETH *e, void **data)\r
+{\r
+       UINT ret = 0;\r
+\r
+#if            defined(UNIX_LINUX)\r
+       ret = EthGetPacketLinux(e, data);\r
+#elif  defined(UNIX_SOLARIS)\r
+       ret = EthGetPacketSolaris(e, data);\r
+#elif  defined(BRIDGE_PCAP)\r
+       ret = EthGetPacketPcap(e, data);\r
+#elif  defined(BRIDGE_BPF)\r
+       ret = EthGetPacketBpf(e, data);\r
+#endif\r
+\r
+       return ret;\r
+}\r
+\r
+#ifdef UNIX_LINUX\r
+UINT EthGetPacketLinux(ETH *e, void **data)\r
+{\r
+       int s, ret;\r
+       UCHAR tmp[UNIX_ETH_TMP_BUFFER_SIZE];\r
+       // 引数チェック\r
+       if (e == NULL || data == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       if (e->Tap != NULL)\r
+       {\r
+#ifndef        NO_VLAN\r
+               // tap モード\r
+               void *buf;\r
+               UINT size;\r
+\r
+               if (VLanGetNextPacket(e->Tap, &buf, &size) == false)\r
+               {\r
+                       return INFINITE;\r
+               }\r
+\r
+               *data = buf;\r
+               return size;\r
+#else  // NO_VLAN\r
+               return INFINITE;\r
+#endif\r
+       }\r
+\r
+       s = e->Socket;\r
+\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       // 読み込み\r
+       ret = read(s, tmp, sizeof(tmp));\r
+       if (ret == 0 || (ret == -1 && errno == EAGAIN))\r
+       {\r
+               // パケット無し\r
+               *data = NULL;\r
+               return 0;\r
+       }\r
+       else if (ret == -1 || ret > sizeof(tmp))\r
+       {\r
+               // エラー\r
+               *data = NULL;\r
+               e->Socket = INVALID_SOCKET;\r
+               return INFINITE;\r
+       }\r
+       else\r
+       {\r
+               // パケット読み込み成功\r
+               *data = MallocFast(ret);\r
+               Copy(*data, tmp, ret);\r
+               return ret;\r
+       }\r
+\r
+       return 0;\r
+}\r
+#endif // UNIX_LINUX\r
+\r
+#ifdef UNIX_SOLARIS\r
+UINT EthGetPacketSolaris(ETH *e, void **data)\r
+{\r
+       UCHAR tmp[UNIX_ETH_TMP_BUFFER_SIZE];\r
+       struct strbuf buf;\r
+       int s;\r
+       int flags = 0;\r
+       int ret;\r
+       // 引数チェック\r
+       if (e == NULL || data == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       s = e->Socket;\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       Zero(&buf, sizeof(buf));\r
+       buf.buf = tmp;\r
+       buf.maxlen = sizeof(tmp);\r
+\r
+       ret = getmsg(s, NULL, &buf, &flags);\r
+\r
+       if (ret < 0 || ret > sizeof(tmp))\r
+       {\r
+               if (errno == EAGAIN)\r
+               {\r
+                       // パケット無し\r
+                       *data = NULL;\r
+                       return 0;\r
+               }\r
+               // エラー\r
+               *data = NULL;\r
+               return INFINITE;\r
+       }\r
+\r
+       ret = buf.len;\r
+\r
+       *data = MallocFast(ret);\r
+       Copy(*data, tmp, ret);\r
+       return ret;\r
+}\r
+#endif // UNIX_SOLARIS\r
+\r
+#ifdef BRIDGE_PCAP\r
+UINT EthGetPacketPcap(ETH *e, void **data)\r
+{\r
+       struct CAPTUREBLOCK *block;\r
+       UINT size;\r
+       \r
+       LockQueue(e->Queue);\r
+       block = GetNext(e->Queue);\r
+       if(block != NULL){\r
+               e->QueueSize -= block->Size;\r
+       }\r
+       UnlockQueue(e->Queue);\r
+       \r
+       if(block == NULL){\r
+               *data = NULL;\r
+               if(e->Socket == INVALID_SOCKET){\r
+                       return INFINITE;\r
+               }\r
+               return 0;\r
+       }\r
+       \r
+       *data = block->Buf;\r
+       size = block->Size;\r
+       FreeCaptureBlock(block);\r
+       \r
+       return size;\r
+}\r
+#endif // BRIDGE_PCAP\r
+\r
+#ifdef BRIDGE_BPF\r
+#ifdef BRIDGE_BPF_THREAD\r
+UINT EthGetPacketBpf(ETH *e, void **data)\r
+{\r
+       struct CAPTUREBLOCK *block;\r
+       UINT size;\r
+       \r
+       LockQueue(e->Queue);\r
+       block = GetNext(e->Queue);\r
+       if(block != NULL){\r
+               e->QueueSize -= block->Size;\r
+       }\r
+       UnlockQueue(e->Queue);\r
+       \r
+       if(block == NULL){\r
+               *data = NULL;\r
+               if(e->Socket == INVALID_SOCKET){\r
+                       return INFINITE;\r
+               }\r
+               return 0;\r
+       }\r
+       \r
+       *data = block->Buf;\r
+       size = block->Size;\r
+       FreeCaptureBlock(block);\r
+       \r
+       return size;\r
+}\r
+#else // BRIDGE_BPF_THREAD\r
+UINT EthGetPacketBpf(ETH *e, void **data)\r
+{\r
+       struct bpf_hdr *hdr;\r
+       \r
+       if(e->Rest<=0){\r
+               e->Rest = read(e->Socket, e->Buffer, e->BufSize);\r
+               if(e->Rest < 0){\r
+                       *data = NULL;\r
+                       if(errno != EAGAIN){\r
+                               // エラー\r
+                               return INFINITE;\r
+                       }\r
+                       // データなし\r
+                       return 0;\r
+               }\r
+               e->Next = e->Buffer;\r
+       }\r
+       // パケットの切り出し\r
+       hdr = (struct bpf_hdr*)e->Next;\r
+       *data = Malloc(hdr->bh_caplen);\r
+       Copy(*data, e->Next+(hdr->bh_hdrlen), hdr->bh_caplen);\r
+\r
+       // 次のパケットの頭出し\r
+       e->Rest -= BPF_WORDALIGN(hdr->bh_hdrlen + hdr->bh_caplen);\r
+       e->Next += BPF_WORDALIGN(hdr->bh_hdrlen + hdr->bh_caplen);\r
+       \r
+       return hdr->bh_caplen;\r
+}\r
+#endif // BRIDGE_BPF_THREAD\r
+#endif // BRIDGE_BPF\r
+\r
+\r
+// 複数のパケットの書き込み\r
+void EthPutPackets(ETH *e, UINT num, void **datas, UINT *sizes)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL || num == 0 || datas == NULL || sizes == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               EthPutPacket(e, datas[i], sizes[i]);\r
+       }\r
+}\r
+\r
+// パケットの書き込み\r
+void EthPutPacket(ETH *e, void *data, UINT size)\r
+{\r
+       int s, ret;\r
+       // 引数チェック\r
+       if (e == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (size < 14 || size > MAX_PACKET_SIZE)\r
+       {\r
+               Free(data);\r
+               return;\r
+       }\r
+\r
+       if (e->Tap != NULL)\r
+       {\r
+#ifndef        NO_VLAN\r
+               // tap モード\r
+               VLanPutPacket(e->Tap, data, size);\r
+#endif // NO_VLAN\r
+               return;\r
+       }\r
+\r
+       s = e->Socket;\r
+\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               Free(data);\r
+               return;\r
+       }\r
+\r
+       // 書き込み\r
+#ifdef BRIDGE_PCAP\r
+       ret = pcap_inject(e->Pcap, data, size);\r
+       if( ret == -1 ){\r
+#ifdef _DEBUG\r
+               pcap_perror(e->Pcap, "inject");\r
+#endif // _DEBUG\r
+               Debug("EthPutPacket: ret:%d size:%d\n", ret, size);\r
+       }\r
+#else // BRIDGE_PCAP\r
+       ret = write(s, data, size);\r
+       if (ret<0)\r
+       {\r
+               Debug("EthPutPacket: ret:%d errno:%d  size:%d\n", ret, errno, size);\r
+       }\r
+#endif //BRIDGE_PCAP\r
+       \r
+       Free(data);\r
+}\r
+\r
+#endif // BRIDGE_C\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/BridgeUnix.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/BridgeUnix.h
new file mode 100644 (file)
index 0000000..0301432
--- /dev/null
@@ -0,0 +1,183 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// BridgeUnix.h\r
+// BridgeUnix.c のヘッダ\r
+\r
+#ifndef        BRIDGEUNIX_H\r
+#define        BRIDGEUNIX_H\r
+\r
+// マクロ\r
+#ifndef SOL_PACKET\r
+#define        SOL_PACKET      263\r
+#endif\r
+#ifndef ifr_newname\r
+#define ifr_newname     ifr_ifru.ifru_slave\r
+#endif\r
+\r
+// 定数\r
+#define        UNIX_ETH_TMP_BUFFER_SIZE                (2000)\r
+#define        SOLARIS_MAXDLBUF                                (32768)\r
+#define BRIDGE_MAX_QUEUE_SIZE                  (4096*1500)\r
+\r
+// ETH 構造体\r
+struct ETH\r
+{\r
+       char *Name;                                     // アダプタ名\r
+       char *Title;                            // アダプタタイトル\r
+       CANCEL *Cancel;                         // キャンセルオブジェクト\r
+       int IfIndex;                            // インデックス\r
+       int Socket;                                     // ソケット\r
+       UINT InitialMtu;                        // 初期の MTU 値\r
+       UINT CurrentMtu;                        // 現在の MTU 値\r
+       int SocketBsdIf;                        // BSD インターフェイス操作用ソケット\r
+\r
+#ifdef BRIDGE_PCAP\r
+       void *Pcap;                                     // Pcap 記述子\r
+       QUEUE *Queue;                           // 中継スレッド用のキュー\r
+       UINT QueueSize;                         // Queue 中のバイト数\r
+       THREAD *CaptureThread;                  // Pcap 中継用スレッド\r
+#endif // BRIDGE_PCAP\r
+\r
+#ifdef BRIDGE_BPF\r
+       UINT BufSize;                           // BPF を read するときのバッファサイズ(これ以外だとエラー)\r
+#ifdef BRIDGE_BPF_THREAD\r
+       QUEUE *Queue;                           // 中継スレッド用のキュー\r
+       UINT QueueSize;                         // Queue 中のバイト数\r
+       THREAD *CaptureThread;                  // BPF 中継用スレッド\r
+#else // BRIDGE_BPF_THREAD\r
+       UCHAR *Buffer;                          // BPF を read するときのバッファ\r
+       UCHAR *Next;\r
+       int Rest;\r
+#endif // BRIDGE_BPF_THREAD\r
+#endif // BRIDGE_BPF\r
+\r
+       VLAN *Tap;                                      // tap\r
+};\r
+\r
+#if defined( BRIDGE_BPF ) || defined( BRIDGE_PCAP )\r
+struct CAPTUREBLOCK{\r
+       UINT Size;\r
+       UCHAR *Buf;\r
+};\r
+#endif // BRIDGE_BPF\r
+\r
+\r
+// 関数プロトタイプ\r
+void InitEth();\r
+void FreeEth();\r
+bool IsEthSupported();\r
+bool IsEthSupportedLinux();\r
+bool IsEthSupportedSolaris();\r
+bool IsEthSupportedPcap();\r
+TOKEN_LIST *GetEthList();\r
+TOKEN_LIST *GetEthListLinux();\r
+TOKEN_LIST *GetEthListSolaris();\r
+TOKEN_LIST *GetEthListPcap();\r
+ETH *OpenEth(char *name, bool local, bool tapmode, char *tapaddr);\r
+ETH *OpenEthLinux(char *name, bool local, bool tapmode, char *tapaddr);\r
+ETH *OpenEthSolaris(char *name, bool local, bool tapmode, char *tapaddr);\r
+ETH *OpenEthPcap(char *name, bool local, bool tapmode, char *tapaddr);\r
+bool ParseUnixEthDeviceName(char *dst_devname, UINT dst_devname_size, UINT *dst_devid, char *src_name);\r
+void CloseEth(ETH *e);\r
+CANCEL *EthGetCancel(ETH *e);\r
+UINT EthGetPacket(ETH *e, void **data);\r
+UINT EthGetPacketLinux(ETH *e, void **data);\r
+UINT EthGetPacketSolaris(ETH *e, void **data);\r
+UINT EthGetPacketPcap(ETH *e, void **data);\r
+UINT EthGetPacketBpf(ETH *e, void **data);\r
+void EthPutPacket(ETH *e, void *data, UINT size);\r
+void EthPutPackets(ETH *e, UINT num, void **datas, UINT *sizes);\r
+UINT EthGetMtu(ETH *e);\r
+bool EthSetMtu(ETH *e, UINT mtu);\r
+bool EthIsChangeMtuSupported(ETH *e);\r
+bool EthGetInterfaceDescriptionUnix(char *name, char *str, UINT size);\r
+bool EthIsInterfaceDescriptionSupportedUnix();\r
+\r
+#ifdef UNIX_SOLARIS\r
+// Solaris 用関数プロトタイプ\r
+bool DlipAttatchRequest(int fd, UINT devid);\r
+bool DlipReceiveAck(int fd);\r
+bool DlipPromiscuous(int fd, UINT level);\r
+bool DlipBindRequest(int fd);\r
+#endif // OS_SOLARIS\r
+\r
+int UnixEthOpenRawSocket();\r
+\r
+#endif // BRIDGEUNIX_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/BridgeWin32.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/BridgeWin32.c
new file mode 100644 (file)
index 0000000..2b726ba
--- /dev/null
@@ -0,0 +1,1694 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// BridgeWin32.c\r
+// Ethernet ブリッジプログラム (Win32 版)\r
+\r
+#ifdef BRIDGE_C\r
+\r
+#include <winsock2.h>\r
+#include <Ws2tcpip.h>\r
+#include <windows.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Packet32.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+\r
+\r
+static WP *wp = NULL;\r
+static LIST *eth_list = NULL;\r
+\r
+static LOCK *eth_list_lock = NULL;\r
+static bool is_sep_mode = false;\r
+\r
+#define        LOAD_DLL_ADDR(name)                             \\r
+       {                                                                       \\r
+               void *addr = GetProcAddress(h, #name);  \\r
+               Copy(&wp->name, &addr, sizeof(void *)); \\r
+       }\r
+\r
+// リスト比較\r
+int CmpRpcEnumEthVLan(void *p1, void *p2)\r
+{\r
+       RPC_ENUM_ETH_VLAN_ITEM *v1, *v2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       v1 = *((RPC_ENUM_ETH_VLAN_ITEM **)p1);\r
+       v2 = *((RPC_ENUM_ETH_VLAN_ITEM **)p2);\r
+       if (v1 == NULL || v2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCmpi(v1->DeviceName, v2->DeviceName);\r
+}\r
+\r
+// MTU の取得 (Windows では非サポート)\r
+UINT EthGetMtu(ETH *e)\r
+{\r
+       return 0;\r
+}\r
+\r
+// MTU の設定 (Windows では非サポート)\r
+bool EthSetMtu(ETH *e, UINT mtu)\r
+{\r
+       return false;\r
+}\r
+\r
+// MTU の設定がサポートされているかどうか取得 (Windows では非サポート)\r
+bool EthIsChangeMtuSupported(ETH *e)\r
+{\r
+       return false;\r
+}\r
+\r
+// デバイスの VLAN 有効化状態を設定\r
+bool SetVLanEnableStatus(char *title, bool enable)\r
+{\r
+       RPC_ENUM_ETH_VLAN t;\r
+       RPC_ENUM_ETH_VLAN_ITEM *e;\r
+       bool ret = false;\r
+       char key[MAX_SIZE];\r
+       char tcpkey[MAX_SIZE];\r
+       char short_key[MAX_SIZE];\r
+       // 引数チェック\r
+       if (title == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (EnumEthVLanWin32(&t) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       e = FindEthVLanItem(&t, title);\r
+\r
+       if (e != NULL)\r
+       {\r
+               if (GetClassRegKeyWin32(key, sizeof(key), short_key, sizeof(short_key), e->Guid))\r
+               {\r
+                       if (StrCmpi(e->DriverType, "Intel") == 0)\r
+                       {\r
+                               if (enable)\r
+                               {\r
+                                       MsRegWriteStr(REG_LOCAL_MACHINE, key, "VlanFiltering", "0");\r
+                                       MsRegWriteStr(REG_LOCAL_MACHINE, key, "TaggingMode", "0");\r
+                                       MsRegWriteInt(REG_LOCAL_MACHINE, key, "MonitorMode", 1);\r
+                                       MsRegWriteInt(REG_LOCAL_MACHINE, key, "MonitorModeEnabled", 1);\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (MsRegReadInt(REG_LOCAL_MACHINE, key, "TaggingMode") == 0)\r
+                                       {\r
+                                               MsRegDeleteValue(REG_LOCAL_MACHINE, key, "TaggingMode");\r
+                                       }\r
+\r
+                                       if (MsRegReadInt(REG_LOCAL_MACHINE, key, "MonitorMode") == 1)\r
+                                       {\r
+                                               MsRegDeleteValue(REG_LOCAL_MACHINE, key, "MonitorMode");\r
+                                       }\r
+\r
+                                       if (MsRegReadInt(REG_LOCAL_MACHINE, key, "MonitorModeEnabled") == 1)\r
+                                       {\r
+                                               MsRegDeleteValue(REG_LOCAL_MACHINE, key, "MonitorModeEnabled");\r
+                                       }\r
+                               }\r
+\r
+                               ret = true;\r
+                       }\r
+                       else if (StrCmpi(e->DriverType, "Broadcom") == 0)\r
+                       {\r
+                               if (enable)\r
+                               {\r
+                                       MsRegWriteStr(REG_LOCAL_MACHINE, key, "PreserveVlanInfoInRxPacket", "1");\r
+                               }\r
+                               else\r
+                               {\r
+                                       MsRegDeleteValue(REG_LOCAL_MACHINE, key, "PreserveVlanInfoInRxPacket");\r
+                               }\r
+\r
+                               ret = true;\r
+                       }\r
+                       else if (StrCmpi(e->DriverType, "Marvell") == 0)\r
+                       {\r
+                               if (enable)\r
+                               {\r
+                                       MsRegWriteInt(REG_LOCAL_MACHINE, key, "SkDisableVlanStrip", 1);\r
+                               }\r
+                               else\r
+                               {\r
+                                       MsRegDeleteValue(REG_LOCAL_MACHINE, key, "SkDisableVlanStrip");\r
+                               }\r
+\r
+                               ret = true;\r
+                       }\r
+\r
+                       Format(tcpkey, sizeof(tcpkey),\r
+                               "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%s",\r
+                               e->Guid);\r
+\r
+                       if (enable)\r
+                       {\r
+                               if (MsRegIsValue(REG_LOCAL_MACHINE, tcpkey, "MTU") == false)\r
+                               {\r
+                                       MsRegWriteInt(REG_LOCAL_MACHINE, tcpkey, "MTU", 1500);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               UINT mtu = MsRegReadInt(REG_LOCAL_MACHINE, tcpkey, "MTU");\r
+                               if (mtu == 1500)\r
+                               {\r
+                                       MsRegDeleteValue(REG_LOCAL_MACHINE, tcpkey, "MTU");\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeRpcEnumEthVLan(&t);\r
+\r
+       return ret;\r
+}\r
+\r
+// デバイスを検索\r
+RPC_ENUM_ETH_VLAN_ITEM *FindEthVLanItem(RPC_ENUM_ETH_VLAN *t, char *name)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               if (StrCmpi(t->Items[i].DeviceName, name) == 0)\r
+               {\r
+                       return &t->Items[i];\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// デバイスの VLAN 有効化状態を取得\r
+void GetVLanEnableStatus(RPC_ENUM_ETH_VLAN_ITEM *e)\r
+{\r
+       char key[MAX_SIZE];\r
+       char short_key[MAX_SIZE];\r
+       char tcpkey[MAX_SIZE];\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       e->Enabled = false;\r
+\r
+       if (e->Support == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (GetClassRegKeyWin32(key, sizeof(key), short_key, sizeof(short_key), e->Guid) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(tcpkey, sizeof(tcpkey),\r
+               "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%s",\r
+               e->Guid);\r
+\r
+       if (StrCmpi(e->DriverType, "Intel") == 0)\r
+       {\r
+               char *VlanFiltering = MsRegReadStr(REG_LOCAL_MACHINE, key, "VlanFiltering");\r
+               UINT MonitorMode = MsRegReadInt(REG_LOCAL_MACHINE, key, "MonitorMode");\r
+               UINT MonitorModeEnabled = MsRegReadInt(REG_LOCAL_MACHINE, key, "MonitorModeEnabled");\r
+               char *TaggingMode = MsRegReadStr(REG_LOCAL_MACHINE, key, "TaggingMode");\r
+\r
+               if (StrCmpi(VlanFiltering, "0") == 0 &&\r
+                       MonitorMode == 1 &&\r
+                       MonitorModeEnabled == 1 &&\r
+                       StrCmpi(TaggingMode, "0") == 0)\r
+               {\r
+                       e->Enabled = true;\r
+               }\r
+\r
+               Free(VlanFiltering);\r
+               Free(TaggingMode);\r
+       }\r
+       else if (StrCmpi(e->DriverType, "Broadcom") == 0)\r
+       {\r
+               char *PreserveVlanInfoInRxPacket = MsRegReadStr(REG_LOCAL_MACHINE,\r
+                       key, "PreserveVlanInfoInRxPacket");\r
+\r
+               if (StrCmpi(PreserveVlanInfoInRxPacket, "1") == 0)\r
+               {\r
+                       e->Enabled = true;\r
+               }\r
+\r
+               Free(PreserveVlanInfoInRxPacket);\r
+       }\r
+       else if (StrCmpi(e->DriverType, "Marvell") == 0)\r
+       {\r
+               DWORD SkDisableVlanStrip = MsRegReadInt(REG_LOCAL_MACHINE,\r
+                       key, "SkDisableVlanStrip");\r
+\r
+               if (SkDisableVlanStrip == 1)\r
+               {\r
+                       e->Enabled = true;\r
+               }\r
+       }\r
+\r
+       if (MsRegIsValue(REG_LOCAL_MACHINE, tcpkey, "MTU") == false)\r
+       {\r
+               e->Enabled = false;\r
+       }\r
+}\r
+\r
+// デバイスの VLAN サポート状態を取得\r
+void GetVLanSupportStatus(RPC_ENUM_ETH_VLAN_ITEM *e)\r
+{\r
+       BUF *b;\r
+       char filename[MAX_SIZE];\r
+       void *wow;\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       wow = MsDisableWow64FileSystemRedirection();\r
+\r
+       // ドライバファイルを読み込む\r
+       CombinePath(filename, sizeof(filename), MsGetSystem32Dir(), "drivers");\r
+       CombinePath(filename, sizeof(filename), filename, e->DriverName);\r
+\r
+       b = ReadDump(filename);\r
+\r
+       if (b != NULL)\r
+       {\r
+               char intel1[] = "VlanFiltering";\r
+               char intel2[] = "V\0l\0a\0n\0F\0i\0l\0t\0e\0r\0i\0n\0g";\r
+               char intel3[] = "MonitorMode";\r
+               char intel4[] = "M\0o\0n\0i\0t\0o\0r\0M\0o\0d\0e";\r
+               char intel5[] = "TaggingMode";\r
+               char intel6[] = "T\0a\0g\0g\0i\0n\0g\0M\0o\0d\0e";\r
+               char broadcom1[] = "PreserveVlanInfoInRxPacket";\r
+               char broadcom2[] = "P\0r\0e\0s\0e\0r\0v\0e\0V\0l\0a\0n\0I\0n\0f\0o\0I\0n\0R\0x\0P\0a\0c\0k\0e\0t";\r
+               char marvell1[] = "SkDisableVlanStrip";\r
+               char marvell2[] = "S\0k\0D\0i\0s\0a\0b\0l\0e\0V\0l\0a\0n\0S\0t\0r\0i\0p";\r
+               char *driver_type = "";\r
+\r
+               if (SearchBin(b->Buf, 0, b->Size, intel1, sizeof(intel1)) != INFINITE\r
+                       || SearchBin(b->Buf, 0, b->Size, intel2, sizeof(intel2)) != INFINITE\r
+                       || SearchBin(b->Buf, 0, b->Size, intel3, sizeof(intel3)) != INFINITE\r
+                       || SearchBin(b->Buf, 0, b->Size, intel4, sizeof(intel4)) != INFINITE\r
+                       || SearchBin(b->Buf, 0, b->Size, intel5, sizeof(intel5)) != INFINITE\r
+                       || SearchBin(b->Buf, 0, b->Size, intel6, sizeof(intel6)) != INFINITE)\r
+               {\r
+                       driver_type = "Intel";\r
+               }\r
+               else if (SearchBin(b->Buf, 0, b->Size, broadcom1, sizeof(broadcom1)) != INFINITE\r
+                       || SearchBin(b->Buf, 0, b->Size, broadcom2, sizeof(broadcom2)) != INFINITE)\r
+               {\r
+                       driver_type = "Broadcom";\r
+               }\r
+               else if (SearchBin(b->Buf, 0, b->Size, marvell1, sizeof(marvell1)) != INFINITE\r
+                       || SearchBin(b->Buf, 0, b->Size, marvell2, sizeof(marvell2)) != INFINITE)\r
+               {\r
+                       driver_type = "Marvell";\r
+               }\r
+\r
+               if (IsEmptyStr(driver_type) == false)\r
+               {\r
+                       StrCpy(e->DriverType, sizeof(e->DriverType), driver_type);\r
+                       e->Support = true;\r
+               }\r
+\r
+               FreeBuf(b);\r
+       }\r
+\r
+       MsRestoreWow64FileSystemRedirection(wow);\r
+}\r
+\r
+// short_key からデバイスのインスタンス ID を取得する\r
+char *SearchDeviceInstanceIdFromShortKey(char *short_key)\r
+{\r
+       char *ret = NULL;\r
+       TOKEN_LIST *t1;\r
+       // 引数チェック\r
+       if (short_key == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t1 = MsRegEnumKey(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Enum");\r
+\r
+       if (t1 != NULL)\r
+       {\r
+               TOKEN_LIST *t2;\r
+               char tmp[MAX_SIZE];\r
+               UINT i;\r
+\r
+               for (i = 0;i < t1->NumTokens;i++)\r
+               {\r
+                       Format(tmp, sizeof(tmp), "SYSTEM\\CurrentControlSet\\Enum\\%s", t1->Token[i]);\r
+\r
+                       t2 = MsRegEnumKey(REG_LOCAL_MACHINE, tmp);\r
+\r
+                       if (t2 != NULL)\r
+                       {\r
+                               TOKEN_LIST *t3;\r
+                               UINT i;\r
+\r
+                               for (i = 0;i < t2->NumTokens;i++)\r
+                               {\r
+                                       char tmp2[MAX_SIZE];\r
+\r
+                                       Format(tmp2, sizeof(tmp2), "%s\\%s", tmp, t2->Token[i]);\r
+\r
+                                       t3 = MsRegEnumKey(REG_LOCAL_MACHINE, tmp2);\r
+\r
+                                       if (t3 != NULL)\r
+                                       {\r
+                                               UINT i;\r
+\r
+                                               for (i = 0;i < t3->NumTokens;i++)\r
+                                               {\r
+                                                       char tmp3[MAX_SIZE];\r
+                                                       char *s;\r
+\r
+                                                       Format(tmp3, sizeof(tmp3), "%s\\%s", tmp2, t3->Token[i]);\r
+\r
+                                                       s = MsRegReadStr(REG_LOCAL_MACHINE, tmp3, "Driver");\r
+\r
+                                                       if (s != NULL)\r
+                                                       {\r
+                                                               if (StrCmpi(s, short_key) == 0)\r
+                                                               {\r
+                                                                       if (ret != NULL)\r
+                                                                       {\r
+                                                                               Free(ret);\r
+                                                                       }\r
+\r
+                                                                       ret = CopyStr(tmp3 + StrLen("SYSTEM\\CurrentControlSet\\Enum\\"));\r
+                                                               }\r
+\r
+                                                               Free(s);\r
+                                                       }\r
+                                               }\r
+\r
+                                               FreeToken(t3);\r
+                                       }\r
+                               }\r
+\r
+                               FreeToken(t2);\r
+                       }\r
+               }\r
+\r
+               FreeToken(t1);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 物理 LAN カードの VLAN 対応状況の列挙\r
+bool EnumEthVLanWin32(RPC_ENUM_ETH_VLAN *t)\r
+{\r
+       UINT i;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_ETH_VLAN));\r
+\r
+       if (MsIsWin2000OrGreater() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsEthSupported() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // アダプタ一覧の取得\r
+       Lock(eth_list_lock);\r
+\r
+       InitEthAdaptersList();\r
+\r
+       o = NewListFast(CmpRpcEnumEthVLan);\r
+\r
+       for (i = 0;i < LIST_NUM(eth_list);i++)\r
+       {\r
+               WP_ADAPTER *a = LIST_DATA(eth_list, i);\r
+\r
+               if (IsEmptyStr(a->Guid) == false)\r
+               {\r
+                       char class_key[MAX_SIZE];\r
+                       char short_key[MAX_SIZE];\r
+\r
+                       if (GetClassRegKeyWin32(class_key, sizeof(class_key),\r
+                               short_key, sizeof(short_key), a->Guid))\r
+                       {\r
+                               char *device_instance_id = MsRegReadStr(REG_LOCAL_MACHINE, class_key, "DeviceInstanceID");\r
+\r
+                               if (IsEmptyStr(device_instance_id))\r
+                               {\r
+                                       Free(device_instance_id);\r
+                                       device_instance_id = SearchDeviceInstanceIdFromShortKey(short_key);\r
+                               }\r
+\r
+                               if (IsEmptyStr(device_instance_id) == false)\r
+                               {\r
+                                       char device_key[MAX_SIZE];\r
+                                       char *service_name;\r
+\r
+                                       Format(device_key, sizeof(device_key), "SYSTEM\\CurrentControlSet\\Enum\\%s",\r
+                                               device_instance_id);\r
+\r
+                                       service_name = MsRegReadStr(REG_LOCAL_MACHINE, device_key, "Service");\r
+                                       if (IsEmptyStr(service_name) == false)\r
+                                       {\r
+                                               char service_key[MAX_SIZE];\r
+                                               char *sys;\r
+\r
+                                               Format(service_key, sizeof(service_key),\r
+                                                       "SYSTEM\\CurrentControlSet\\services\\%s",\r
+                                                       service_name);\r
+\r
+                                               sys = MsRegReadStr(REG_LOCAL_MACHINE, service_key, "ImagePath");\r
+\r
+                                               if (IsEmptyStr(sys) == false)\r
+                                               {\r
+                                                       char sysname[MAX_PATH];\r
+\r
+                                                       GetFileNameFromFilePath(sysname, sizeof(sysname), sys);\r
+\r
+                                                       Trim(sysname);\r
+\r
+                                                       if (EndWith(sysname, ".sys"))\r
+                                                       {\r
+                                                               // デバイス発見\r
+                                                               RPC_ENUM_ETH_VLAN_ITEM *e = ZeroMalloc(sizeof(RPC_ENUM_ETH_VLAN_ITEM));\r
+\r
+                                                               StrCpy(e->DeviceName, sizeof(e->DeviceName), a->Title);\r
+                                                               StrCpy(e->Guid, sizeof(e->Guid), a->Guid);\r
+                                                               StrCpy(e->DeviceInstanceId, sizeof(e->DeviceInstanceId), device_instance_id);\r
+                                                               StrCpy(e->DriverName, sizeof(e->DriverName), sysname);\r
+\r
+                                                               // デバイスの VLAN サポート状態を取得\r
+                                                               GetVLanSupportStatus(e);\r
+\r
+                                                               // 有効化状態を取得\r
+                                                               GetVLanEnableStatus(e);\r
+\r
+                                                               Insert(o, e);\r
+                                                       }\r
+                                               }\r
+\r
+                                               Free(sys);\r
+                                       }\r
+\r
+                                       Free(service_name);\r
+                               }\r
+\r
+                               Free(device_instance_id);\r
+                       }\r
+               }\r
+       }\r
+\r
+       t->NumItem = LIST_NUM(o);\r
+       t->Items = ZeroMalloc(sizeof(RPC_ENUM_ETH_VLAN_ITEM) * i);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               RPC_ENUM_ETH_VLAN_ITEM *e = LIST_DATA(o, i);\r
+\r
+               Copy(&t->Items[i], e, sizeof(RPC_ENUM_ETH_VLAN_ITEM));\r
+\r
+               Free(e);\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       Unlock(eth_list_lock);\r
+\r
+       return true;\r
+}\r
+\r
+// GUID からネットワーククラスデータのレジストリキーを取得\r
+bool GetClassRegKeyWin32(char *key, UINT key_size, char *short_key, UINT short_key_size, char *guid)\r
+{\r
+       TOKEN_LIST *t;\r
+       bool ret = false;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (key == NULL || short_key == NULL || guid == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       t = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+               "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}");\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               char keyname[MAX_SIZE];\r
+               char *value;\r
+\r
+               Format(keyname, sizeof(keyname),\r
+                       "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s",\r
+                       t->Token[i]);\r
+\r
+               value = MsRegReadStr(REG_LOCAL_MACHINE, keyname, "NetCfgInstanceId");\r
+\r
+               if (StrCmpi(value, guid) == 0)\r
+               {\r
+                       ret = true;\r
+\r
+                       StrCpy(key, key_size, keyname);\r
+\r
+                       Format(short_key, short_key_size, "{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s",\r
+                               t->Token[i]);\r
+               }\r
+\r
+               Free(value);\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// 複数のパケットを書き込む\r
+void EthPutPackets(ETH *e, UINT num, void **datas, UINT *sizes)\r
+{\r
+       UINT i, total_size;\r
+       UCHAR *buf;\r
+       UINT write_pointer;\r
+       // 引数チェック\r
+       if (e == NULL || num == 0 || datas == NULL || sizes == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsWin32BridgeWithSep() == false)\r
+       {\r
+               // 古い WinPcap にはバグがあり、2 個以上の CPU が搭載されている場合に\r
+               // ロックが不十分なところがあってカーネル内でクラッシュすることが\r
+               // 頻繁にあった。そこで 1 個目の CPU でしか動作しないように工夫していた\r
+               if (e->LastSetSingleCpu == 0 || (e->LastSetSingleCpu + 10000) <= Tick64())\r
+               {\r
+                       e->LastSetSingleCpu = Tick64();\r
+                       MsSetThreadSingleCpu();\r
+               }\r
+       }\r
+\r
+       // 必要なデータサイズの計算\r
+       total_size = 0;\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               void *data = datas[i];\r
+               UINT size = sizes[i];\r
+               if (data != NULL && size >= 14 && size <= MAX_PACKET_SIZE)\r
+               {\r
+                       total_size += size + sizeof(struct dump_bpf_hdr);\r
+               }\r
+       }\r
+\r
+       // 適当やな\r
+       buf = MallocFast(total_size * 100 / 75 + 1600);\r
+\r
+       write_pointer = 0;\r
+       // キューに入れる\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               void *data = datas[i];\r
+               UINT size = sizes[i];\r
+               if (data != NULL && size >= 14 && size <= MAX_PACKET_SIZE)\r
+               {\r
+                       struct dump_bpf_hdr *h;\r
+\r
+                       h = (struct dump_bpf_hdr *)(buf + write_pointer);\r
+                       Zero(h, sizeof(struct dump_bpf_hdr));\r
+                       h->caplen = h->len = size;\r
+                       write_pointer += sizeof(struct dump_bpf_hdr);\r
+                       Copy(buf + write_pointer, data, size);\r
+                       write_pointer += size;\r
+\r
+                       PROBE_DATA2("EthPutPackets", data, size);\r
+               }\r
+               // 元のメモリは解放する\r
+               Free(data);\r
+       }\r
+\r
+       // 送信\r
+       if (total_size != 0)\r
+       {\r
+               wp->PacketSendPackets(e->Adapter, buf, total_size, true);\r
+       }\r
+\r
+       Free(buf);\r
+}\r
+\r
+// パケットを書き込む\r
+void EthPutPacket(ETH *e, void *data, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL || data == NULL || size == 0)\r
+       {\r
+               return;\r
+       }\r
+       if (size < 14 || size > MAX_PACKET_SIZE)\r
+       {\r
+               Free(data);\r
+               return;\r
+       }\r
+\r
+       if (IsWin32BridgeWithSep() == false)\r
+       {\r
+               if (e->LastSetSingleCpu == 0 || (e->LastSetSingleCpu + 10000) <= Tick64())\r
+               {\r
+                       e->LastSetSingleCpu = Tick64();\r
+                       MsSetThreadSingleCpu();\r
+               }\r
+       }\r
+\r
+       wp->PacketInitPacket(e->PutPacket, data, size);\r
+       wp->PacketSendPacket(e->Adapter, e->PutPacket, false);\r
+\r
+       Free(data);\r
+}\r
+\r
+// 次のパケットを読み込む\r
+UINT EthGetPacket(ETH *e, void **data)\r
+{\r
+       BLOCK *b;\r
+       bool flag = false;\r
+       // 引数チェック\r
+       if (e == NULL || data == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+RETRY:\r
+       // まずキューにパケットがたまっているかどうか見てみる\r
+       b = GetNext(e->PacketQueue);\r
+       if (b != NULL)\r
+       {\r
+               UINT size;\r
+               size = b->Size;\r
+               *data = b->Buf;\r
+               Free(b);\r
+\r
+               if (e->PacketQueue->num_item == 0)\r
+               {\r
+                       e->Empty = true;\r
+               }\r
+\r
+               return size;\r
+       }\r
+\r
+       if (e->Empty)\r
+       {\r
+               e->Empty = false;\r
+               return 0;\r
+       }\r
+\r
+       if (flag == false)\r
+       {\r
+               // 次のパケットの取得を試みる\r
+               PROBE_STR("EthGetPacket: PacketInitPacket");\r
+               wp->PacketInitPacket(e->Packet, e->Buffer, e->BufferSize);\r
+               PROBE_STR("EthGetPacket: PacketReceivePacket");\r
+               if (wp->PacketReceivePacket(e->Adapter, e->Packet, false) == false)\r
+               {\r
+                       // 失敗\r
+                       return INFINITE;\r
+               }\r
+               else\r
+               {\r
+                       UCHAR *buf;\r
+                       UINT total;\r
+                       UINT offset;\r
+\r
+                       buf = (UCHAR *)e->Packet->Buffer;\r
+                       total = e->Packet->ulBytesReceived;\r
+                       offset = 0;\r
+\r
+                       while (offset < total)\r
+                       {\r
+                               struct bpf_hdr *header;\r
+                               UINT packet_size;\r
+                               UCHAR *packet_data;\r
+\r
+                               header = (struct bpf_hdr *)(buf + offset);\r
+                               packet_size = header->bh_caplen;\r
+                               offset += header->bh_hdrlen;\r
+                               packet_data = buf + offset;\r
+                               offset = Packet_WORDALIGN(offset + packet_size);\r
+\r
+                               if (packet_size >= 14)\r
+                               {\r
+                                       UCHAR *tmp;\r
+                                       BLOCK *b;\r
+\r
+                                       PROBE_DATA2("EthGetPacket: NewBlock", packet_data, packet_size);\r
+                                       \r
+                                       tmp = MallocFast(packet_size);\r
+\r
+                                       Copy(tmp, packet_data, packet_size);\r
+                                       b = NewBlock(tmp, packet_size, 0);\r
+                                       InsertQueue(e->PacketQueue, b);\r
+                               }\r
+                       }\r
+\r
+                       flag = true;\r
+                       goto RETRY;\r
+               }\r
+       }\r
+\r
+       // これ以上パケットを取得できない\r
+       return 0;\r
+}\r
+\r
+// キャンセルオブジェクトの取得\r
+CANCEL *EthGetCancel(ETH *e)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       AddRef(e->Cancel->ref);\r
+\r
+       return e->Cancel;\r
+}\r
+\r
+// アダプタを閉じる\r
+void CloseEth(ETH *e)\r
+{\r
+       BLOCK *b;\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ReleaseCancel(e->Cancel);\r
+\r
+       wp->PacketCloseAdapter(e->Adapter);\r
+       wp->PacketFreePacket(e->Packet);\r
+       wp->PacketFreePacket(e->PutPacket);\r
+\r
+       while (b = GetNext(e->PacketQueue))\r
+       {\r
+               FreeBlock(b);\r
+       }\r
+       ReleaseQueue(e->PacketQueue);\r
+\r
+       Free(e->Name);\r
+       Free(e->Title);\r
+       Free(e->Buffer);\r
+\r
+       Free(e);\r
+}\r
+\r
+// アダプタを開く\r
+ETH *OpenEth(char *name, bool local, bool tapmode, char *tapaddr)\r
+{\r
+       ETH *ret;\r
+       void *p;\r
+\r
+       p = MsDisableWow64FileSystemRedirection();\r
+\r
+       ret = OpenEthInternal(name, local, tapmode, tapaddr);\r
+\r
+       MsRestoreWow64FileSystemRedirection(p);\r
+\r
+       return ret;\r
+}\r
+ETH *OpenEthInternal(char *name, bool local, bool tapmode, char *tapaddr)\r
+{\r
+       WP_ADAPTER *t, tt;\r
+       ETH *e;\r
+       ADAPTER *a;\r
+       HANDLE h;\r
+       CANCEL *c;\r
+       // 引数チェック\r
+       if (name == NULL || IsEthSupported() == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (tapmode)\r
+       {\r
+               // Win32 では tap はサポートしていない\r
+               return NULL;\r
+       }\r
+\r
+       Lock(eth_list_lock);\r
+\r
+       InitEthAdaptersList();\r
+\r
+       Zero(&tt, sizeof(tt));\r
+       StrCpy(tt.Title, sizeof(tt.Title), name);\r
+\r
+       t = Search(eth_list, &tt);\r
+       if (t == NULL)\r
+       {\r
+               Unlock(eth_list_lock);\r
+               return NULL;\r
+       }\r
+\r
+       a = wp->PacketOpenAdapter(t->Name);\r
+       if (a == NULL)\r
+       {\r
+               Unlock(eth_list_lock);\r
+               return NULL;\r
+       }\r
+\r
+       if (IsWin32BridgeWithSep() == false)\r
+       {\r
+               MsSetThreadSingleCpu();\r
+       }\r
+\r
+       e = ZeroMalloc(sizeof(ETH));\r
+       e->Name = CopyStr(t->Name);\r
+       e->Title = CopyStr(t->Title);\r
+\r
+       e->Adapter = a;\r
+\r
+       wp->PacketSetBuff(e->Adapter, BRIDGE_WIN32_ETH_BUFFER);\r
+       wp->PacketSetHwFilter(e->Adapter, local ? 0x0080 : 0x0020);\r
+       wp->PacketSetMode(e->Adapter, PACKET_MODE_CAPT);\r
+       wp->PacketSetReadTimeout(e->Adapter, -1);\r
+       wp->PacketSetNumWrites(e->Adapter, 1);\r
+\r
+       if (wp->PacketSetLoopbackBehavior != NULL)\r
+       {\r
+               if (GET_KETA(GetOsType(), 100) >= 3)\r
+               {\r
+                       // Windows XP, Server 2003 以降\r
+                       bool ret = wp->PacketSetLoopbackBehavior(e->Adapter, 1);\r
+                       Debug("*** PacketSetLoopbackBehavior: %u\n", ret);\r
+\r
+                       e->LoopbackBlock = ret;\r
+               }\r
+       }\r
+\r
+       h = wp->PacketGetReadEvent(e->Adapter);\r
+\r
+       c = NewCancelSpecial(h);\r
+       e->Cancel = c;\r
+\r
+       e->Buffer = Malloc(BRIDGE_WIN32_ETH_BUFFER);\r
+       e->BufferSize = BRIDGE_WIN32_ETH_BUFFER;\r
+       e->Packet = wp->PacketAllocatePacket();\r
+\r
+       e->PutPacket = wp->PacketAllocatePacket();\r
+\r
+       e->PacketQueue = NewQueue();\r
+\r
+       Unlock(eth_list_lock);\r
+\r
+       return e;\r
+}\r
+\r
+// Ethernet アダプタリストの取得\r
+TOKEN_LIST *GetEthList()\r
+{\r
+       TOKEN_LIST *ret;\r
+       UINT i;\r
+\r
+       if (IsEthSupported() == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Lock(eth_list_lock);\r
+\r
+       InitEthAdaptersList();\r
+\r
+       ret = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       ret->NumTokens = LIST_NUM(eth_list);\r
+       ret->Token = ZeroMalloc(sizeof(char *) * ret->NumTokens);\r
+       for (i = 0;i < ret->NumTokens;i++)\r
+       {\r
+               WP_ADAPTER *a = LIST_DATA(eth_list, i);\r
+               ret->Token[i] = CopyStr(a->Title);\r
+       }\r
+\r
+       Unlock(eth_list_lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// WP_ADAPTER の名前比較\r
+int CompareWpAdapter(void *p1, void *p2)\r
+{\r
+       int i;\r
+       WP_ADAPTER *a1, *a2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       a1 = *(WP_ADAPTER **)p1;\r
+       a2 = *(WP_ADAPTER **)p2;\r
+       if (a1 == NULL || a2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       i = StrCmpi(a1->Title, a2->Title);\r
+       return i;\r
+}\r
+\r
+// Ethernet アダプタリストの取得\r
+LIST *GetEthAdapterList()\r
+{\r
+       void *p;\r
+       LIST *o;\r
+\r
+       p = MsDisableWow64FileSystemRedirection();\r
+\r
+       o = GetEthAdapterListInternal();\r
+\r
+       MsRestoreWow64FileSystemRedirection(p);\r
+\r
+       return o;\r
+}\r
+LIST *GetEthAdapterListInternal()\r
+{\r
+       LIST *o;\r
+       LIST *ret;\r
+       UINT size;\r
+       char *buf;\r
+       UINT i, j;\r
+       char *qos_tag = " (Microsoft's Packet Scheduler)";\r
+\r
+       o = NewListFast(CompareWpAdapter);\r
+\r
+       size = 200000;\r
+       buf = ZeroMalloc(size);\r
+\r
+       if (wp->PacketGetAdapterNames(buf, &size) == false)\r
+       {\r
+               Free(buf);\r
+               return o;\r
+       }\r
+\r
+       i = 0;\r
+\r
+       if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType))\r
+       {\r
+               // Windows NT\r
+               if (size >= 2 && buf[0] != 0 && buf[1] != 0)\r
+               {\r
+                       goto ANSI_STR;\r
+               }\r
+\r
+               while (true)\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       WP_ADAPTER *a;\r
+                       UniStrCpy(tmp, sizeof(tmp), L"");\r
+\r
+                       if (*((wchar_t *)(&buf[i])) == 0)\r
+                       {\r
+                               i += sizeof(wchar_t);\r
+                               break;\r
+                       }\r
+\r
+                       for (;*((wchar_t *)(&buf[i])) != 0;i += sizeof(wchar_t))\r
+                       {\r
+                               wchar_t str[2];\r
+                               str[0] = *((wchar_t *)(&buf[i]));\r
+                               str[1] = 0;\r
+                               UniStrCat(tmp, sizeof(tmp), str);\r
+                       }\r
+\r
+                       i += sizeof(wchar_t);\r
+\r
+                       a = ZeroMalloc(sizeof(WP_ADAPTER));\r
+                       UniToStr(a->Name, sizeof(a->Name), tmp);\r
+\r
+                       Add(o, a);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // Windows 9x\r
+ANSI_STR:\r
+               while (true)\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+                       WP_ADAPTER *a;\r
+                       StrCpy(tmp, sizeof(tmp), "");\r
+\r
+                       if (*((char *)(&buf[i])) == 0)\r
+                       {\r
+                               i += sizeof(char);\r
+                               break;\r
+                       }\r
+\r
+                       for (;*((char *)(&buf[i])) != 0;i += sizeof(char))\r
+                       {\r
+                               char str[2];\r
+                               str[0] = *((char *)(&buf[i]));\r
+                               str[1] = 0;\r
+                               StrCat(tmp, sizeof(tmp), str);\r
+                       }\r
+\r
+                       i += sizeof(char);\r
+\r
+                       a = ZeroMalloc(sizeof(WP_ADAPTER));\r
+                       StrCpy(a->Name, sizeof(a->Name), tmp);\r
+\r
+                       Add(o, a);\r
+               }\r
+       }\r
+\r
+       for (j = 0;j < LIST_NUM(o);j++)\r
+       {\r
+               WP_ADAPTER *a = LIST_DATA(o, j);\r
+\r
+               StrCpy(a->Title, sizeof(a->Title), &buf[i]);\r
+               i += StrSize(a->Title);\r
+\r
+               // Win9x で デバイスの説明が"Unknown"ならば1文字読み飛ばす。\r
+               if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType))\r
+               {\r
+                       if (StrCmp(a->Title, "Unknown") == 0)\r
+                       {\r
+                               if (buf[i] == 0)\r
+                               {\r
+                                       i+=sizeof(char);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               TrimCrlf(a->Title);\r
+               Trim(a->Title);\r
+               TrimCrlf(a->Title);\r
+               Trim(a->Title);\r
+\r
+               if (EndWith(a->Title, qos_tag))\r
+               {\r
+                       a->Title[StrLen(a->Title) - StrLen(qos_tag)] = 0;\r
+                       TrimCrlf(a->Title);\r
+                       Trim(a->Title);\r
+                       TrimCrlf(a->Title);\r
+                       Trim(a->Title);\r
+               }\r
+       }\r
+\r
+       for (j = 0;j < LIST_NUM(o);j++)\r
+       {\r
+               // GUID の抽出\r
+               WP_ADAPTER *a = LIST_DATA(o, j);\r
+\r
+               StrCpy(a->Guid, sizeof(a->Guid), a->Name);\r
+               ReplaceStr(a->Guid, sizeof(a->Guid), a->Guid, "\\Device\\SEP_", "");\r
+               ReplaceStr(a->Guid, sizeof(a->Guid), a->Guid, "\\Device\\SEE_", "");\r
+               ReplaceStr(a->Guid, sizeof(a->Guid), a->Guid, "\\Device\\NPF_", "");\r
+               ReplaceStr(a->Guid, sizeof(a->Guid), a->Guid, "\\Device\\PCD_", "");\r
+       }\r
+\r
+       // ソート\r
+       Sort(o);\r
+\r
+       ret = NewListFast(CompareWpAdapter);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               WP_ADAPTER *a = LIST_DATA(o, i);\r
+               ADAPTER *ad;\r
+               bool ok = false;\r
+\r
+               if (SearchStrEx(a->Title, "ppp", 0, false) != INFINITE ||\r
+                       SearchStrEx(a->Title, "wan", 0, false) != INFINITE ||\r
+                       SearchStrEx(a->Title, "dialup", 0, false) != INFINITE ||\r
+                       SearchStrEx(a->Title, "pptp", 0, false) != INFINITE ||\r
+                       SearchStrEx(a->Title, "telepho", 0, false) != INFINITE ||\r
+                       SearchStrEx(a->Title, "modem", 0, false) != INFINITE ||\r
+                       SearchStrEx(a->Title, "ras", 0, false) != INFINITE)\r
+               {\r
+                       Free(a);\r
+                       continue;\r
+               }\r
+\r
+               ad = wp->PacketOpenAdapter(a->Name);\r
+               if (ad != NULL)\r
+               {\r
+                       NetType type;\r
+                       if (wp->PacketGetNetType(ad, &type))\r
+                       {\r
+                               if (type.LinkType == 0)\r
+                               {\r
+                                       char tmp[MAX_SIZE];\r
+                                       UINT k;\r
+                                       // Ethernet のみ\r
+                                       StrCpy(tmp, sizeof(tmp), a->Title);\r
+\r
+                                       for (k = 0;;k++)\r
+                                       {\r
+                                               if (k == 0)\r
+                                               {\r
+                                                       StrCpy(tmp, sizeof(tmp), a->Title);\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       Format(tmp, sizeof(tmp), "%s (%u)", a->Title, k + 1);\r
+                                               }\r
+\r
+                                               ok = true;\r
+                                               for (j = 0;j < LIST_NUM(ret);j++)\r
+                                               {\r
+                                                       WP_ADAPTER *aa = LIST_DATA(ret, j);\r
+                                                       if (StrCmpi(aa->Title, tmp) == 0)\r
+                                                       {\r
+                                                               ok = false;\r
+                                                       }\r
+                                               }\r
+\r
+                                               if (ok)\r
+                                               {\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+\r
+                                       StrCpy(a->Title, sizeof(a->Title), tmp);\r
+                                       Add(ret, a);\r
+                               }\r
+                               else\r
+                               {\r
+                                       Debug("%s: type = %u\n", a->Name, type.LinkType);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               Debug("%s: PacketGetNetType() Failed.\n", a->Name);\r
+                       }\r
+                       wp->PacketCloseAdapter(ad);\r
+               }\r
+               else\r
+               {\r
+                       Debug("%s: PacketOpenAdapter() Failed.\n", a->Name);\r
+               }\r
+\r
+               if (ok == false)\r
+               {\r
+                       Free(a);\r
+               }\r
+       }\r
+\r
+       Free(buf);\r
+\r
+       Sort(ret);\r
+\r
+       ReleaseList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// Ethernet アダプタのリストの初期化\r
+void InitEthAdaptersList()\r
+{\r
+       if (eth_list != NULL)\r
+       {\r
+               FreeEthAdaptersList();\r
+               eth_list = NULL;\r
+       }\r
+       eth_list = GetEthAdapterList();\r
+}\r
+\r
+// Ethernet アダプタのリストの解放\r
+void FreeEthAdaptersList()\r
+{\r
+       UINT i;\r
+       if (eth_list == NULL)\r
+       {\r
+               return;\r
+       }\r
+       for (i = 0;i < LIST_NUM(eth_list);i++)\r
+       {\r
+               WP_ADAPTER *a = LIST_DATA(eth_list, i);\r
+               Free(a);\r
+       }\r
+       ReleaseList(eth_list);\r
+       eth_list = NULL;\r
+}\r
+\r
+// Ethernet がサポートされているかどうか\r
+bool IsEthSupported()\r
+{\r
+       if (wp == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return wp->Inited;\r
+}\r
+\r
+// 現在の OS で PCD ドライバがサポートされているか\r
+bool IsPcdSupported()\r
+{\r
+       UINT type;\r
+       OS_INFO *info = GetOsInfo();\r
+\r
+       type = info->OsType;\r
+\r
+       if (OS_IS_WINDOWS_NT(type) == false)\r
+       {\r
+               // Windows NT 以外はダメ\r
+               return false;\r
+       }\r
+\r
+       if (GET_KETA(type, 100) >= 2)\r
+       {\r
+               // Windows 2000 以降は良い\r
+               return true;\r
+       }\r
+\r
+       // Windows NT 4.0, Longhorn はダメ\r
+\r
+       return false;\r
+}\r
+\r
+// PCD ドライバのビルド番号を書き込む\r
+void SavePcdDriverBuild(UINT build)\r
+{\r
+       MsRegWriteInt(REG_LOCAL_MACHINE, BRIDGE_WIN32_PCD_REGKEY, BRIDGE_WIN32_PCD_BUILDVALUE,\r
+               build);\r
+}\r
+\r
+// PCD ドライバのビルド番号を読み込む\r
+UINT LoadPcdDriverBuild()\r
+{\r
+       return MsRegReadInt(REG_LOCAL_MACHINE, BRIDGE_WIN32_PCD_REGKEY, BRIDGE_WIN32_PCD_BUILDVALUE);\r
+}\r
+\r
+// PCD ドライバのインストールを試みる\r
+HINSTANCE InstallPcdDriver()\r
+{\r
+       HINSTANCE ret;\r
+       void *p = MsDisableWow64FileSystemRedirection();\r
+\r
+       ret = InstallPcdDriverInternal();\r
+\r
+       MsRestoreWow64FileSystemRedirection(p);\r
+\r
+       return ret;\r
+}\r
+HINSTANCE InstallPcdDriverInternal()\r
+{\r
+       char tmp[MAX_PATH];\r
+       bool install_driver = true;\r
+       HINSTANCE h;\r
+       char *dll_filename;\r
+\r
+       // まず sep.sys が system32\drivers ディレクトリにインストールされているかどうか確認する\r
+       Format(tmp, sizeof(tmp), "%s\\drivers\\sep.sys", MsGetSystem32Dir());\r
+\r
+       if (IsFileExists(tmp))\r
+       {\r
+               // ドライバが存在している場合は、次にレジストリからビルド番号を取得する\r
+               if (LoadPcdDriverBuild() >= CEDAR_BUILD)\r
+               {\r
+                       // すでに最新版のドライバがインストールされている\r
+                       install_driver = false;\r
+               }\r
+       }\r
+\r
+       if (install_driver)\r
+       {\r
+               char *src_filename = BRIDGE_WIN32_PCD_SYS;\r
+               // ドライバのインストールをする必要がある場合\r
+               // まず Admin かどうかチェックする\r
+               if (MsIsAdmin() == false)\r
+               {\r
+                       // Admin で無い場合はドライバのインストールは不能である\r
+                       return NULL;\r
+               }\r
+\r
+               if (MsIsX64())\r
+               {\r
+                       src_filename = BRIDGE_WIN32_PCD_SYS_X64;\r
+               }\r
+\r
+               if (MsIsIA64())\r
+               {\r
+                       src_filename = BRIDGE_WIN32_PCD_SYS_IA64;\r
+               }\r
+\r
+               // sep.sys をコピーする\r
+               if (FileCopy(src_filename, tmp) == false)\r
+               {\r
+                       return NULL;\r
+               }\r
+\r
+               // ビルド番号を書き込む\r
+               SavePcdDriverBuild(CEDAR_BUILD);\r
+       }\r
+\r
+       dll_filename = BRIDGE_WIN32_PCD_DLL;\r
+\r
+       if (Is64())\r
+       {\r
+               if (MsIsX64())\r
+               {\r
+                       dll_filename = BRIDGE_WIN32_PCD_DLL_X64;\r
+               }\r
+               else if (MsIsIA64())\r
+               {\r
+                       dll_filename = BRIDGE_WIN32_PCD_DLL_IA64;\r
+               }\r
+       }\r
+\r
+       // sep.dll を読み込んで初期化してみる\r
+       h = MsLoadLibrary(dll_filename);\r
+       if (h == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return h;\r
+}\r
+\r
+// Ethernet の初期化\r
+void InitEth()\r
+{\r
+       HINSTANCE h;\r
+       if (wp != NULL)\r
+       {\r
+               // 初期化済み\r
+               return;\r
+       }\r
+\r
+       eth_list_lock = NewLock();\r
+\r
+       wp = ZeroMalloc(sizeof(WP));\r
+\r
+       is_sep_mode = false;\r
+\r
+       if (IsPcdSupported())\r
+       {\r
+               // PCD がサポートされている OS である\r
+               h = InstallPcdDriver();\r
+               if (h != NULL)\r
+               {\r
+                       // PCD を使って初期化を試みる\r
+                       if (InitWpWithLoadLibrary(wp, h) == false)\r
+                       {\r
+                               Debug("InitEth: SEP Failed.\n");\r
+                               FreeLibrary(h);\r
+                       }\r
+                       else\r
+                       {\r
+                               Debug("InitEth: SEP Loaded.\n");\r
+                               is_sep_mode = true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (wp->Inited == false)\r
+       {\r
+               // WinPcap の Packet.dll を使って初期化を試みる\r
+               h = LoadLibrary(BRIDGE_WIN32_PACKET_DLL);\r
+               if (h != NULL)\r
+               {\r
+                       if (InitWpWithLoadLibrary(wp, h) == false)\r
+                       {\r
+                               Debug("InitEth: Packet.dll Failed.\n");\r
+                               FreeLibrary(h);\r
+                       }\r
+                       else\r
+                       {\r
+                               Debug("InitEth: Packet.dll Loaded.\n");\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// sep.sys を用いてブリッジを行っているかどうかを取得\r
+bool IsWin32BridgeWithSep()\r
+{\r
+       return is_sep_mode;\r
+}\r
+\r
+// WP 構造体を DLL で初期化する\r
+bool InitWpWithLoadLibrary(WP *wp, HINSTANCE h)\r
+{\r
+       TOKEN_LIST *o;\r
+       // 引数チェック\r
+       if (wp == NULL || h == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       wp->Inited = true;\r
+       wp->hPacketDll = h;\r
+\r
+       LOAD_DLL_ADDR(PacketGetVersion);\r
+       LOAD_DLL_ADDR(PacketGetDriverVersion);\r
+       LOAD_DLL_ADDR(PacketSetMinToCopy);\r
+       LOAD_DLL_ADDR(PacketSetNumWrites);\r
+       LOAD_DLL_ADDR(PacketSetMode);\r
+       LOAD_DLL_ADDR(PacketSetReadTimeout);\r
+       LOAD_DLL_ADDR(PacketSetBpf);\r
+       LOAD_DLL_ADDR(PacketSetSnapLen);\r
+       LOAD_DLL_ADDR(PacketGetStats);\r
+       LOAD_DLL_ADDR(PacketGetStatsEx);\r
+       LOAD_DLL_ADDR(PacketSetBuff);\r
+       LOAD_DLL_ADDR(PacketGetNetType);\r
+       LOAD_DLL_ADDR(PacketOpenAdapter);\r
+       LOAD_DLL_ADDR(PacketSendPacket);\r
+       LOAD_DLL_ADDR(PacketSendPackets);\r
+       LOAD_DLL_ADDR(PacketAllocatePacket);\r
+       LOAD_DLL_ADDR(PacketInitPacket);\r
+       LOAD_DLL_ADDR(PacketFreePacket);\r
+       LOAD_DLL_ADDR(PacketReceivePacket);\r
+       LOAD_DLL_ADDR(PacketSetHwFilter);\r
+       LOAD_DLL_ADDR(PacketGetAdapterNames);\r
+       LOAD_DLL_ADDR(PacketGetNetInfoEx);\r
+       LOAD_DLL_ADDR(PacketRequest);\r
+       LOAD_DLL_ADDR(PacketGetReadEvent);\r
+       LOAD_DLL_ADDR(PacketSetDumpName);\r
+       LOAD_DLL_ADDR(PacketSetDumpLimits);\r
+       LOAD_DLL_ADDR(PacketSetDumpLimits);\r
+       LOAD_DLL_ADDR(PacketIsDumpEnded);\r
+       LOAD_DLL_ADDR(PacketStopDriver);\r
+       LOAD_DLL_ADDR(PacketCloseAdapter);\r
+       LOAD_DLL_ADDR(PacketSetLoopbackBehavior);\r
+\r
+       if (wp->PacketSetMinToCopy == NULL ||\r
+               wp->PacketSetNumWrites == NULL ||\r
+               wp->PacketSetMode == NULL ||\r
+               wp->PacketSetReadTimeout == NULL ||\r
+               wp->PacketSetBuff == NULL ||\r
+               wp->PacketGetNetType == NULL ||\r
+               wp->PacketOpenAdapter == NULL ||\r
+               wp->PacketSendPacket == NULL ||\r
+               wp->PacketSendPackets == NULL ||\r
+               wp->PacketAllocatePacket == NULL ||\r
+               wp->PacketInitPacket == NULL ||\r
+               wp->PacketFreePacket == NULL ||\r
+               wp->PacketReceivePacket == NULL ||\r
+               wp->PacketSetHwFilter == NULL ||\r
+               wp->PacketGetAdapterNames == NULL ||\r
+               wp->PacketGetNetInfoEx == NULL ||\r
+               wp->PacketCloseAdapter == NULL)\r
+       {\r
+RELEASE:\r
+               wp->Inited = false;\r
+               wp->hPacketDll = NULL;\r
+\r
+               return false;\r
+       }\r
+\r
+       o = GetEthList();\r
+       if (o == NULL || o->NumTokens == 0)\r
+       {\r
+               FreeToken(o);\r
+               goto RELEASE;\r
+       }\r
+\r
+       FreeToken(o);\r
+\r
+       return true;\r
+}\r
+\r
+// Ethernet の解放\r
+void FreeEth()\r
+{\r
+       if (wp == NULL)\r
+       {\r
+               // 初期化されていない\r
+               return;\r
+       }\r
+\r
+       // アダプタリストの解放\r
+       FreeEthAdaptersList();\r
+\r
+       if (wp->Inited)\r
+       {\r
+               // DLL 解放\r
+               FreeLibrary(wp->hPacketDll);\r
+       }\r
+\r
+       Free(wp);\r
+       wp = NULL;\r
+\r
+       DeleteLock(eth_list_lock);\r
+       eth_list_lock = NULL;\r
+}\r
+\r
+// Ethernet デバイスに対応するネットワーク接続名を取得する\r
+void GetEthNetworkConnectionName(wchar_t *dst, UINT size, char *device_name)\r
+{\r
+       WP_ADAPTER *t, tt;\r
+       char *tmp = NULL, guid[MAX_SIZE];\r
+       wchar_t *ncname = NULL;\r
+\r
+       UniStrCpy(dst, size, L"");\r
+\r
+       // 引数チェック\r
+       if (device_name == NULL || IsEthSupported() == false || \r
+               IsNt() == false || MsIsWin2000OrGreater() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(eth_list_lock);\r
+\r
+       InitEthAdaptersList();\r
+\r
+       Zero(&tt, sizeof(tt));\r
+       StrCpy(tt.Title, sizeof(tt.Title), device_name);\r
+\r
+       t = Search(eth_list, &tt);\r
+       if (t == NULL)\r
+       {\r
+               Unlock(eth_list_lock);\r
+               return;\r
+       }\r
+\r
+       tmp = Malloc(sizeof(t->Name));\r
+       StrCpy(tmp, sizeof(t->Name), t->Name);\r
+       Unlock(eth_list_lock);\r
+\r
+       ReplaceStr(guid, sizeof(guid), tmp, "\\Device\\SEP_", "");\r
+       Free(tmp);\r
+\r
+       ReplaceStr(guid, sizeof(guid), guid, "\\Device\\SEE_", "");\r
+       ReplaceStr(guid, sizeof(guid), guid, "\\Device\\NPF_", "");\r
+       ReplaceStr(guid, sizeof(guid), guid, "\\Device\\PCD_", "");\r
+\r
+       if(guid == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ncname = MsGetNetworkConnectionName(guid);\r
+       if(ncname != NULL)\r
+       {\r
+               UniStrCpy(dst, size, ncname);\r
+       }\r
+       Free(ncname);\r
+}\r
+\r
+#endif // BRIDGE_C\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/BridgeWin32.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/BridgeWin32.h
new file mode 100644 (file)
index 0000000..802059c
--- /dev/null
@@ -0,0 +1,210 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// BridgeWin32.h\r
+// BridgeWin32.c のヘッダ\r
+\r
+#ifndef        BRIDGEWIN32_H\r
+#define        BRIDGEWIN32_H\r
+\r
+#define        BRIDGE_WIN32_PACKET_DLL         "Packet.dll"\r
+#define        BRIDGE_WIN32_PCD_DLL            "|sep.dll"\r
+#define        BRIDGE_WIN32_PCD_SYS            "|sep.sys"\r
+#define        BRIDGE_WIN32_PCD_DLL_X64        "|sep_x64.dll"\r
+#define        BRIDGE_WIN32_PCD_SYS_X64        "|sep_x64.sys"\r
+#define        BRIDGE_WIN32_PCD_DLL_IA64       "|sep_ia64.dll"\r
+#define        BRIDGE_WIN32_PCD_SYS_IA64       "|sep_ia64.sys"\r
+#define        BRIDGE_WIN32_PCD_REGKEY         "SYSTEM\\CurrentControlSet\\services\\SEP"\r
+#define        BRIDGE_WIN32_PCD_BUILDVALUE     "CurrentInstalledBuild"\r
+\r
+#define        BRIDGE_WIN32_ETH_BUFFER         (1048576)\r
+\r
+\r
+typedef void *HANDLE;\r
+\r
+#ifdef BRIDGE_C\r
+\r
+// 内部向け関数ヘッダ (BridgeWin32.c 用)\r
+typedef struct WP\r
+{\r
+       bool Inited;\r
+       HINSTANCE hPacketDll;\r
+       PCHAR (*PacketGetVersion)();\r
+       PCHAR (*PacketGetDriverVersion)();\r
+       BOOLEAN (*PacketSetMinToCopy)(LPADAPTER AdapterObject,int nbytes);\r
+       BOOLEAN (*PacketSetNumWrites)(LPADAPTER AdapterObject,int nwrites);\r
+       BOOLEAN (*PacketSetMode)(LPADAPTER AdapterObject,int mode);\r
+       BOOLEAN (*PacketSetReadTimeout)(LPADAPTER AdapterObject,int timeout);\r
+       BOOLEAN (*PacketSetBpf)(LPADAPTER AdapterObject,struct bpf_program *fp);\r
+       INT (*PacketSetSnapLen)(LPADAPTER AdapterObject,int snaplen);\r
+       BOOLEAN (*PacketGetStats)(LPADAPTER AdapterObject,struct bpf_stat *s);\r
+       BOOLEAN (*PacketGetStatsEx)(LPADAPTER AdapterObject,struct bpf_stat *s);\r
+       BOOLEAN (*PacketSetBuff)(LPADAPTER AdapterObject,int dim);\r
+       BOOLEAN (*PacketGetNetType)(LPADAPTER AdapterObject,NetType *type);\r
+       LPADAPTER (*PacketOpenAdapter)(PCHAR AdapterName);\r
+       BOOLEAN (*PacketSendPacket)(LPADAPTER AdapterObject,LPPACKET pPacket,BOOLEAN Sync);\r
+       INT (*PacketSendPackets)(LPADAPTER AdapterObject,PVOID PacketBuff,ULONG Size, BOOLEAN Sync);\r
+       LPPACKET (*PacketAllocatePacket)(void);\r
+       VOID (*PacketInitPacket)(LPPACKET lpPacket,PVOID  Buffer,UINT  Length);\r
+       VOID (*PacketFreePacket)(LPPACKET lpPacket);\r
+       BOOLEAN (*PacketReceivePacket)(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync);\r
+       BOOLEAN (*PacketSetHwFilter)(LPADAPTER AdapterObject,ULONG Filter);\r
+       BOOLEAN (*PacketGetAdapterNames)(PTSTR pStr,PULONG  BufferSize);\r
+       BOOLEAN (*PacketGetNetInfoEx)(PCHAR AdapterName, npf_if_addr* buffer, PLONG NEntries);\r
+       BOOLEAN (*PacketRequest)(LPADAPTER  AdapterObject,BOOLEAN Set,PPACKET_OID_DATA  OidData);\r
+       HANDLE (*PacketGetReadEvent)(LPADAPTER AdapterObject);\r
+       BOOLEAN (*PacketSetDumpName)(LPADAPTER AdapterObject, void *name, int len);\r
+       BOOLEAN (*PacketSetDumpLimits)(LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks);\r
+       BOOLEAN (*PacketIsDumpEnded)(LPADAPTER AdapterObject, BOOLEAN sync);\r
+       BOOL (*PacketStopDriver)();\r
+       VOID (*PacketCloseAdapter)(LPADAPTER lpAdapter);\r
+       BOOLEAN (*PacketSetLoopbackBehavior)(LPADAPTER AdapterObject, UINT LoopbackBehavior);\r
+} WP;\r
+\r
+// アダプタリスト\r
+typedef struct WP_ADAPTER\r
+{\r
+       char Name[MAX_SIZE];\r
+       char Title[MAX_SIZE];\r
+       char Guid[MAX_SIZE];\r
+} WP_ADAPTER;\r
+\r
+// 内部向け関数プロトタイプ\r
+void InitEthAdaptersList();\r
+void FreeEthAdaptersList();\r
+int CompareWpAdapter(void *p1, void *p2);\r
+LIST *GetEthAdapterList();\r
+LIST *GetEthAdapterListInternal();\r
+bool InitWpWithLoadLibrary(WP *wp, HINSTANCE h);\r
+bool IsPcdSupported();\r
+HINSTANCE InstallPcdDriver();\r
+HINSTANCE InstallPcdDriverInternal();\r
+UINT LoadPcdDriverBuild();\r
+void SavePcdDriverBuild(UINT build);\r
+\r
+#endif // BRIDGE_C\r
+\r
+typedef struct _ADAPTER ADAPTER;\r
+typedef struct _PACKET PACKET;\r
+\r
+// ETH 構造体\r
+struct ETH\r
+{\r
+       char *Name;                                     // アダプタ名\r
+       char *Title;                            // アダプタタイトル\r
+       ADAPTER *Adapter;                       // アダプタ\r
+       CANCEL *Cancel;                         // キャンセルオブジェクト\r
+       UCHAR *Buffer;                          // バッファ\r
+       UINT BufferSize;                        // バッファサイズ\r
+       PACKET *Packet;                         // パケット\r
+       PACKET *PutPacket;                      // 書き込みパケット\r
+       QUEUE *PacketQueue;                     // パケットキュー\r
+       UINT64 LastSetSingleCpu;        // 最後にシングル CPU に設定した日時\r
+       bool LoopbackBlock;                     // ループバックパケットを遮断するかどうか\r
+       bool Empty;                                     // 空である\r
+};\r
+\r
+// 関数プロトタイプ\r
+void InitEth();\r
+void FreeEth();\r
+bool IsEthSupported();\r
+TOKEN_LIST *GetEthList();\r
+ETH *OpenEth(char *name, bool local, bool tapmode, char *tapaddr);\r
+ETH *OpenEthInternal(char *name, bool local, bool tapmode, char *tapaddr);\r
+void CloseEth(ETH *e);\r
+CANCEL *EthGetCancel(ETH *e);\r
+UINT EthGetPacket(ETH *e, void **data);\r
+void EthPutPacket(ETH *e, void *data, UINT size);\r
+void EthPutPackets(ETH *e, UINT num, void **datas, UINT *sizes);\r
+void GetEthNetworkConnectionName(wchar_t *dst, UINT size, char *device_name);\r
+bool IsWin32BridgeWithSep();\r
+UINT EthGetMtu(ETH *e);\r
+bool EthSetMtu(ETH *e, UINT mtu);\r
+bool EthIsChangeMtuSupported(ETH *e);\r
+\r
+bool EnumEthVLanWin32(RPC_ENUM_ETH_VLAN *t);\r
+bool GetClassRegKeyWin32(char *key, UINT key_size, char *short_key, UINT short_key_size, char *guid);\r
+int CmpRpcEnumEthVLan(void *p1, void *p2);\r
+void GetVLanSupportStatus(RPC_ENUM_ETH_VLAN_ITEM *e);\r
+void GetVLanEnableStatus(RPC_ENUM_ETH_VLAN_ITEM *e);\r
+bool SetVLanEnableStatus(char *title, bool enable);\r
+RPC_ENUM_ETH_VLAN_ITEM *FindEthVLanItem(RPC_ENUM_ETH_VLAN *t, char *name);\r
+char *SearchDeviceInstanceIdFromShortKey(char *short_key);\r
+\r
+#endif // BRIDGEWIN32_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/CM.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/CM.c
new file mode 100644 (file)
index 0000000..0927b25
--- /dev/null
@@ -0,0 +1,12153 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// CM.c\r
+// Win32 用 SoftEther UT-VPN クライアント接続マネージャ\r
+\r
+\r
+#ifdef WIN32\r
+\r
+#define        CM_C\r
+#define        SM_C\r
+#define        MICROSOFT_C\r
+\r
+#define        _WIN32_WINNT            0x0502\r
+#define        WINVER                          0x0502\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+#include <Iphlpapi.h>\r
+#include <tlhelp32.h>\r
+#include <shlobj.h>\r
+#include <commctrl.h>\r
+#include <Dbghelp.h>\r
+#include <setupapi.h>\r
+#include <regstr.h>\r
+#include <process.h>\r
+#include <psapi.h>\r
+#include <wtsapi32.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+#include "CMInner.h"\r
+#include "SMInner.h"\r
+#include "NMInner.h"\r
+#include "../PenCore/resource.h"\r
+\r
+// IE のレジストリ文字列からプロキシサーバーの設定を取得する\r
+bool CmGetProxyServerNameAndPortFromIeProxyRegStr(char *name, UINT name_size, UINT *port, char *str, char *server_type)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (name == NULL || port == NULL || str == NULL || server_type == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       t = ParseToken(str, ";");\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               char *s = t->Token[i];\r
+               UINT i;\r
+\r
+               Trim(s);\r
+\r
+               i = SearchStrEx(s, "=", 0, false);\r
+               if (i != INFINITE)\r
+               {\r
+                       char tmp[MAX_PATH];\r
+\r
+                       StrCpy(name, name_size, s);\r
+                       name[i] = 0;\r
+\r
+                       if (StrCmpi(name, server_type) == 0)\r
+                       {\r
+                               char *host;\r
+                               StrCpy(tmp, sizeof(tmp), s + i + 1);\r
+\r
+                               if (ParseHostPort(tmp, &host, port, 0))\r
+                               {\r
+                                       StrCpy(name, name_size, host);\r
+                                       Free(host);\r
+\r
+                                       if (*port != 0)\r
+                                       {\r
+                                               ret = true;\r
+                                       }\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+\r
+// 接続設定にプロキシ設定の内容を反映する\r
+void CmProxyDlgSet(HWND hWnd, CLIENT_OPTION *o, CM_INTERNET_SETTING *setting)\r
+{\r
+       // 引数チェック\r
+       if(hWnd == NULL || setting == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // チェックをつける\r
+       Check(hWnd, R_DIRECT_TCP,       setting->ProxyType == PROXY_DIRECT);\r
+       Check(hWnd, R_HTTPS,            setting->ProxyType == PROXY_HTTP);\r
+       Check(hWnd, R_SOCKS,            setting->ProxyType == PROXY_SOCKS);\r
+\r
+       // Proxy 設定\r
+       if(setting->ProxyType != PROXY_DIRECT)\r
+       {\r
+               StrCpy(o->ProxyName, sizeof(setting->ProxyHostName), setting->ProxyHostName);\r
+               o->ProxyPort = setting->ProxyPort;\r
+       }\r
+}\r
+\r
+// IE のプロキシ設定を取得する\r
+void CmGetSystemInternetSetting(CM_INTERNET_SETTING *setting)\r
+{\r
+       bool use_proxy;\r
+       // 引数チェック\r
+       if (setting == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(setting, sizeof(CM_INTERNET_SETTING));\r
+\r
+       use_proxy = MsRegReadInt(REG_CURRENT_USER,\r
+               "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",\r
+               "ProxyEnable");\r
+\r
+       if (use_proxy)\r
+       {\r
+               char *str = MsRegReadStr(REG_CURRENT_USER,\r
+                       "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",\r
+                       "ProxyServer");\r
+               if (str != NULL)\r
+               {\r
+                       char name[MAX_HOST_NAME_LEN + 1];\r
+                       UINT port;\r
+\r
+                       if (CmGetProxyServerNameAndPortFromIeProxyRegStr(name, sizeof(name),\r
+                               &port, str, "https"))\r
+                       {\r
+                               setting->ProxyType = PROXY_HTTP;\r
+                               StrCpy(setting->ProxyHostName, sizeof(setting->ProxyHostName), name);\r
+                               setting->ProxyPort = port;\r
+                       }\r
+                       else if (CmGetProxyServerNameAndPortFromIeProxyRegStr(name, sizeof(name),\r
+                               &port, str, "http"))\r
+                       {\r
+                               setting->ProxyType = PROXY_HTTP;\r
+                               StrCpy(setting->ProxyHostName, sizeof(setting->ProxyHostName), name);\r
+                               setting->ProxyPort = port;\r
+                       }\r
+                       else if (CmGetProxyServerNameAndPortFromIeProxyRegStr(name, sizeof(name),\r
+                               &port, str, "socks"))\r
+                       {\r
+                               setting->ProxyType = PROXY_SOCKS;\r
+                               StrCpy(setting->ProxyHostName, sizeof(setting->ProxyHostName), name);\r
+                               setting->ProxyPort = port;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (SearchStrEx(str, "=", 0, false) == INFINITE)\r
+                               {\r
+                                       char *host;\r
+                                       UINT port;\r
+                                       if (ParseHostPort(str, &host, &port, 0))\r
+                                       {\r
+                                               if (port != 0)\r
+                                               {\r
+                                                       setting->ProxyType = PROXY_HTTP;\r
+                                                       StrCpy(setting->ProxyHostName, sizeof(setting->ProxyHostName), host);\r
+                                                       setting->ProxyPort = port;\r
+                                               }\r
+                                               Free(host);\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       Free(str);\r
+               }\r
+       }\r
+}\r
+\r
+// 経由するプロキシ設定で、IE の設定を使用する\r
+void CmProxyDlgUseForIE(HWND hWnd, CLIENT_OPTION *o)\r
+{\r
+       CM_INTERNET_SETTING s;\r
+\r
+       // 引数チェック\r
+       if(hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&s, sizeof(s));\r
+       CmGetSystemInternetSetting(&s);\r
+       \r
+       CmProxyDlgSet(hWnd, o, &s);\r
+}\r
+\r
+// スマートカード認証画面のビットマップ ID を決定する\r
+UINT CmGetSecureBitmapId(char *dest_hostname)\r
+{\r
+       // 引数チェック\r
+       if (dest_hostname == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// UAC のウインドウをアクティブにする\r
+void CmSetUacWindowActive()\r
+{\r
+       HWND hWnd;\r
+\r
+       if (MsIsVista() == false)\r
+       {\r
+               return;\r
+       }\r
+       \r
+       hWnd = FindWindowA("$$$Secure UAP Dummy Window Class For Interim Dialog", NULL);\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SwitchToThisWindow(hWnd, true);\r
+}\r
+\r
+// UAC ヘルパースレッド\r
+void CmUacHelperThread(THREAD *thread, void *param)\r
+{\r
+       CM_UAC_HELPER *c = (CM_UAC_HELPER *)param;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (c->Halt == false)\r
+       {\r
+               CmSetUacWindowActive();\r
+\r
+               Wait(c->HaltEvent, 200);\r
+       }\r
+}\r
+\r
+// UAC ヘルパーの開始\r
+void *CmStartUacHelper()\r
+{\r
+       CM_UAC_HELPER *c = ZeroMalloc(sizeof(CM_UAC_HELPER));\r
+\r
+       c->HaltEvent = NewEvent();\r
+       c->Thread = NewThread(CmUacHelperThread, c);\r
+\r
+       return (void *)c;\r
+}\r
+\r
+// UAC ヘルパーの終了\r
+void CmStopUacHelper(void *p)\r
+{\r
+       CM_UAC_HELPER *c = (CM_UAC_HELPER *)p;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->Halt = true;\r
+       Set(c->HaltEvent);\r
+       WaitThread(c->Thread, INFINITE);\r
+       ReleaseEvent(c->HaltEvent);\r
+       ReleaseThread(c->Thread);\r
+\r
+       Free(c);\r
+}\r
+\r
+// 簡易接続マネージャのコマンド呼び出し\r
+void CmEasyDlgOnCommand(HWND hWnd, CM_EASY_DLG *d, WPARAM wParam, LPARAM lParam)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       switch (wParam)\r
+       {\r
+       case B_MODE:\r
+               Command(hWnd, CMD_CM_SETTING);\r
+               return;\r
+\r
+       case B_STATUS:\r
+               Command(hWnd, CMD_STATUS);\r
+               return;\r
+\r
+       case IDCANCEL:\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       if (wParam == CMD_CONNECT)\r
+       {\r
+               cm->ConnectStartedFlag = false;\r
+       }\r
+\r
+       CmMainWindowOnCommandEx(hWnd, wParam, lParam, true);\r
+\r
+       if (wParam == CMD_CONNECT && cm->ConnectStartedFlag)\r
+       {\r
+               // 接続を開始することに成功したらウインドウを閉じる\r
+               Close(hWnd);\r
+       }\r
+}\r
+\r
+// 簡易接続マネージャのキーボード押下\r
+void CmEasyDlgOnKey(HWND hWnd, CM_EASY_DLG *d, bool ctrl, bool alt, UINT key)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 単一キー\r
+       switch (key)\r
+       {\r
+       case VK_RETURN:\r
+               Command(hWnd, IDOK);\r
+               break;\r
+       case VK_DELETE:\r
+               // 削除\r
+               if (IsFocus(hWnd, L_ACCOUNT))\r
+               {\r
+                       // アカウントリストに関する操作\r
+                       Command(hWnd, CMD_DELETE);\r
+               }\r
+               else\r
+               {\r
+                       // 仮想 LAN カードリストに関する操作\r
+                       Command(hWnd, CMD_DELETE_VLAN);\r
+               }\r
+               break;\r
+       case VK_F2:\r
+               // 名前変更\r
+               Command(hWnd, CMD_RENAME);\r
+               break;\r
+       case VK_F5:\r
+               // 状態更新\r
+               Command(hWnd, CMD_REFRESH);\r
+               break;\r
+       }\r
+\r
+       if (alt)\r
+       {\r
+               switch (key)\r
+               {\r
+               case 'Q':\r
+                       // 閉じる\r
+                       Command(hWnd, CMD_QUIT);\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (ctrl)\r
+       {\r
+               switch (key)\r
+               {\r
+               case 'G':\r
+                       // スマートカードマネージャ\r
+                       Command(hWnd, CMD_SECURE_MANAGER);\r
+                       break;\r
+               case 'S':\r
+                       // 状態の表示\r
+                       Command(hWnd, CMD_STATUS);\r
+                       break;\r
+               case 'I':\r
+                       // すべての接続を切断\r
+                       Command(hWnd, CMD_DISCONNECT_ALL);\r
+                       break;\r
+               case 'D':\r
+                       // 切断\r
+                       Command(hWnd, CMD_DISCONNECT);\r
+                       break;\r
+               case 'N':\r
+                       // 接続設定の新規作成\r
+                       Command(hWnd, CMD_NEW);\r
+                       break;\r
+               case 'C':\r
+                       // コピーの作成\r
+                       Command(hWnd, CMD_CLONE);\r
+                       break;\r
+               case 'T':\r
+                       // スタートアップ接続に設定\r
+                       Command(hWnd, CMD_STARTUP);\r
+                       break;\r
+               case 'A':\r
+                       // すべて選択\r
+                       Command(hWnd, CMD_SELECT_ALL);\r
+                       break;\r
+               case 'L':\r
+                       // 新規仮想 LAN カードの作成\r
+                       Command(hWnd, CMD_NEW_VLAN);\r
+                       break;\r
+               case 'P':\r
+                       // パスワードの設定\r
+                       Command(hWnd, CMD_PASSWORD);\r
+                       break;\r
+               case 'O':\r
+                       // オプション設定\r
+                       Command(hWnd, CMD_TRAFFIC);\r
+                       break;\r
+               case 'R':\r
+                       // 証明書管理\r
+                       Command(hWnd, CMD_TRUST);\r
+                       break;\r
+               case 'Q':\r
+                       // スループット\r
+                       Command(hWnd, CMD_TRAFFIC);\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// 簡易接続マネージャのリストビューに対する操作\r
+void CmEasyDlgOnNotify(HWND hWnd, CM_EASY_DLG *d, NMHDR *n)\r
+{\r
+       NMLVDISPINFOW *disp_info;\r
+       NMLVKEYDOWN *key;\r
+\r
+       // 引数チェック\r
+       if (hWnd == NULL || n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       switch (n->idFrom)\r
+       {\r
+       case L_ACCOUNT:\r
+               switch (n->code)\r
+               {\r
+               case LVN_ITEMCHANGED:\r
+                       CmEasyDlgUpdate(hWnd, d);\r
+                       break;\r
+               case NM_DBLCLK:\r
+                       // ダブルクリック\r
+                       Command(hWnd, CMD_EASY_DBLCLICK);\r
+                       break;\r
+               case NM_RCLICK:\r
+                       // 右クリック\r
+                       CmAccountListRightClick(hWnd);\r
+                       break;\r
+               case LVN_ENDLABELEDITW:\r
+                       // 名前の変更\r
+                       disp_info = (NMLVDISPINFOW *)n;\r
+                       if (disp_info->item.pszText != NULL)\r
+                       {\r
+                               wchar_t *new_name = disp_info->item.pszText;\r
+                               wchar_t *old_name = LvGetStr(hWnd, L_ACCOUNT, disp_info->item.iItem, 0);\r
+\r
+                               if (old_name != NULL)\r
+                               {\r
+                                       if (UniStrCmp(new_name, old_name) != 0 && UniIsEmptyStr(new_name) == false)\r
+                                       {\r
+                                               RPC_RENAME_ACCOUNT a;\r
+                                               Zero(&a, sizeof(a));\r
+                                               UniStrCpy(a.OldName, sizeof(a.OldName), old_name);\r
+                                               UniStrCpy(a.NewName, sizeof(a.NewName), new_name);\r
+                                               if (CALL(hWnd, CcRenameAccount(cm->Client, &a)))\r
+                                               {\r
+                                                       LvSetItem(hWnd, L_ACCOUNT, disp_info->item.iItem, 0, new_name);\r
+                                               }\r
+                                       }\r
+\r
+                                       Free(old_name);\r
+                               }\r
+                       }\r
+                       break;\r
+               case LVN_KEYDOWN:\r
+                       // キー押下\r
+                       key = (NMLVKEYDOWN *)n;\r
+                       if (key != NULL)\r
+                       {\r
+                               bool ctrl, alt;\r
+                               UINT code = key->wVKey;\r
+                               ctrl = (GetKeyState(VK_CONTROL) & 0x8000) == 0 ? false : true;\r
+                               alt = (GetKeyState(VK_MENU) & 0x8000) == 0 ? false : true;\r
+                               CmEasyDlgOnKey(hWnd, d, ctrl, alt, code);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+}\r
+\r
+// 簡易接続マネージャに対して更新通知を送信する\r
+void CmRefreshEasy()\r
+{\r
+       if (cm->hEasyWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMessage(cm->hEasyWnd, WM_CM_EASY_REFRESH, 0, 0);\r
+}\r
+\r
+// 簡易接続マネージャ初期化\r
+void CmEasyDlgInit(HWND hWnd, CM_EASY_DLG *d)\r
+{\r
+       HFONT hFontForList;\r
+       HFONT hFontButton;\r
+       HFONT hFontTitle;\r
+       HFONT hFontInfo;\r
+       HFONT hFontOther;\r
+       UINT i, num, num2, j;\r
+       bool b = false;\r
+       char *font_name = NULL;\r
+       bool font_bold = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_VPN);\r
+\r
+       // ウインドウハンドル登録\r
+       cm->hEasyWnd = hWnd;\r
+\r
+       // 中央に表示\r
+       Center(hWnd);\r
+\r
+       // アカウントリストの更新\r
+       CmInitAccountListEx(hWnd, true);\r
+\r
+       // リストのフォント設定\r
+       if (cm->VistaStyle)\r
+       {\r
+               if (_GETLANG() == 0)\r
+               {\r
+                       font_name = "Meiryo";\r
+                       font_bold = false;\r
+               }\r
+               else if (_GETLANG() == 2)\r
+               {\r
+                       font_name = "Microsoft YaHei";\r
+                       font_bold = false;\r
+               }\r
+       }\r
+\r
+       hFontForList = GetFont(font_name, 14, font_bold, false, false, false);\r
+       hFontButton = GetFont(font_name, 13, font_bold, false, false, false);\r
+       hFontTitle = GetFont(font_name, 14, font_bold, false, false, false);\r
+       hFontInfo = GetFont(font_name, 11, font_bold, false, false, false);\r
+       hFontOther = GetDialogDefaultFont();\r
+\r
+       if (cm->VistaStyle)\r
+       {\r
+               hFontOther = GetMeiryoFont();\r
+       }\r
+\r
+       SetFont(hWnd, L_ACCOUNT, hFontForList);\r
+       SetFont(hWnd, IDOK, hFontButton);\r
+       SetFont(hWnd, S_TITLE, hFontTitle);\r
+       SetFont(hWnd, S_INFO, hFontInfo);\r
+       SetFont(hWnd, B_MODE, hFontOther);\r
+       SetFont(hWnd, IDCANCEL, hFontOther);\r
+\r
+       CmEasyDlgRefresh(hWnd, d);\r
+\r
+       num = LvNum(hWnd, L_ACCOUNT);\r
+       num2 = 0;\r
+       j = 0;\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               wchar_t *str = LvGetStr(hWnd, L_ACCOUNT, i, 1);\r
+\r
+               if (str != NULL)\r
+               {\r
+                       if (UniStrCmpi(str, _UU("CM_ACCOUNT_ONLINE")) == 0 || UniStrCmpi(str, _UU("CM_ACCOUNT_CONNECTING")) == 0)\r
+                       {\r
+                               num2++;\r
+                               j = i;\r
+                       }\r
+                       Free(str);\r
+               }\r
+       }\r
+\r
+       if (num2 == 1)\r
+       {\r
+               LvSelect(hWnd, L_ACCOUNT, j);\r
+               b = true;\r
+       }\r
+\r
+       if (b == false)\r
+       {\r
+               if (UniIsEmptyStr(cm->EasyLastSelectedAccountName) == false)\r
+               {\r
+                       i = LvSearchStr(hWnd, L_ACCOUNT, 0, cm->EasyLastSelectedAccountName);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               LvSelect(hWnd, L_ACCOUNT, i);\r
+                               b = true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (b == false)\r
+       {\r
+               if (LvNum(hWnd, L_ACCOUNT) != 0)\r
+               {\r
+                       LvSelect(hWnd, L_ACCOUNT, 0);\r
+               }\r
+       }\r
+\r
+       Focus(hWnd, L_ACCOUNT);\r
+\r
+       CmEasyDlgUpdate(hWnd, d);\r
+}\r
+\r
+// 簡易接続マネージャコントロール更新\r
+void CmEasyDlgUpdate(HWND hWnd, CM_EASY_DLG *d)\r
+{\r
+       bool ok = true;\r
+       bool show_status = false;\r
+       wchar_t *button_str = _UU("CM_EASY_CONNECT_BUTTON_1");\r
+       wchar_t *info_str = _UU("CM_EASY_INFO_1");\r
+       wchar_t *title_str = _UU("CM_EASY_TITLE");\r
+       // 引数チェック\r
+       if (hWnd == NULL || d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSingleSelected(hWnd, L_ACCOUNT) == false)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (ok)\r
+       {\r
+               UINT i = LvGetSelected(hWnd, L_ACCOUNT);\r
+               wchar_t *str = LvGetStr(hWnd, L_ACCOUNT, i, 1);\r
+\r
+               info_str = _UU("CM_EASY_INFO_2");\r
+\r
+               if (str != NULL)\r
+               {\r
+                       if (UniStrCmpi(str, _UU("CM_ACCOUNT_ONLINE")) == 0 || UniStrCmpi(str, _UU("CM_ACCOUNT_CONNECTING")) == 0)\r
+                       {\r
+                               button_str = _UU("CM_EASY_CONNECT_BUTTON_2");\r
+                               show_status = true;\r
+                               info_str = _UU("CM_EASY_INFO_3");\r
+\r
+                               if (UniStrCmpi(str, _UU("CM_ACCOUNT_ONLINE")) == 0)\r
+                               {\r
+                                       title_str = _UU("CM_EASY_CONNECTED");\r
+                               }\r
+                               else\r
+                               {\r
+                                       title_str = _UU("CM_EASY_CONNECTING");\r
+                               }\r
+                       }\r
+                       Free(str);\r
+               }\r
+       }\r
+\r
+       SetShow(hWnd, B_STATUS, show_status);\r
+\r
+       SetText(hWnd, IDOK, button_str);\r
+       SetText(hWnd, S_INFO, info_str);\r
+       SetText(hWnd, S_TITLE, title_str);\r
+\r
+       SetShow(hWnd, IDOK, ok);\r
+}\r
+\r
+// 簡易接続マネージャ内容更新\r
+void CmEasyDlgRefresh(HWND hWnd, CM_EASY_DLG *d)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // アカウントリスト更新\r
+       CmRefreshAccountListEx(hWnd, true);\r
+\r
+       CmEasyDlgUpdate(hWnd, d);\r
+}\r
+\r
+// 簡易接続マネージャのダイアログプロシージャ\r
+UINT CmEasyDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       CM_EASY_DLG *d = (CM_EASY_DLG *)param;\r
+       NMHDR *n;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               CmEasyDlgInit(hWnd, d);\r
+               SetTimer(hWnd, 1, 10, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       SetForegroundWindow(hWnd);\r
+                       SetActiveWindow(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CM_EASY_REFRESH:\r
+               CmEasyDlgRefresh(hWnd, d);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               CmEasyDlgOnCommand(hWnd, d, wParam, lParam);\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               CmEasyDlgOnNotify(hWnd, d, n);\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               i = LvGetSelected(hWnd, L_ACCOUNT);\r
+               if (i != INFINITE)\r
+               {\r
+                       wchar_t *s = LvGetStr(hWnd, L_ACCOUNT, i, 0);\r
+                       if (s != NULL)\r
+                       {\r
+                               UniStrCpy(cm->EasyLastSelectedAccountName, sizeof(cm->EasyLastSelectedAccountName),\r
+                                       s);\r
+                               Free(s);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       Zero(cm->EasyLastSelectedAccountName, sizeof(cm->EasyLastSelectedAccountName));\r
+               }\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 簡易接続マネージャのウインドウを表示する (遅延タイマで呼び出される)\r
+void CmMainWindowOnShowEasy(HWND hWnd)\r
+{\r
+       CM_EASY_DLG d;\r
+\r
+       Zero(&d, sizeof(d));\r
+\r
+       if (cm->CmSetting.EasyMode == false)\r
+       {\r
+               // 簡易モードではない\r
+               return;\r
+       }\r
+\r
+       if (cm->hEasyWnd != NULL)\r
+       {\r
+               // すでに表示されている\r
+               SetForegroundWindow(cm->hEasyWnd);\r
+               SetActiveWindow(cm->hEasyWnd);\r
+               return;\r
+       }\r
+\r
+       Dialog(NULL, D_CM_EASY, CmEasyDlg, &d);\r
+\r
+       cm->hEasyWnd = NULL;\r
+}\r
+\r
+// 簡易接続マネージャのウインドウを表示する\r
+void CmShowEasy()\r
+{\r
+       SetTimer(cm->hMainWnd, 4, 2, NULL);\r
+}\r
+\r
+// 簡易接続マネージャのウインドウを閉じる\r
+void CmCloseEasy()\r
+{\r
+       if (cm->hEasyWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMessage(cm->hEasyWnd, WM_CLOSE, 0, 0);\r
+}\r
+\r
+// トレイアイコンのクリック等のメッセージ処理\r
+void CmMainWindowOnTrayClicked(HWND hWnd, WPARAM wParam, LPARAM lParam)\r
+{\r
+       bool easymode = cm->CmSetting.EasyMode;\r
+\r
+       switch (wParam)\r
+       {\r
+       case 1:\r
+               switch (lParam)\r
+               {\r
+               case WM_LBUTTONDOWN:\r
+               case WM_RBUTTONDOWN:\r
+                       // クリック\r
+                       if (easymode == false)\r
+                       {\r
+                               if (IsEnable(hWnd, 0))\r
+                               {\r
+                                       CmShowTrayMenu(hWnd);\r
+                               }\r
+                               else\r
+                               {\r
+                                       CmShowOrHideWindow(hWnd);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               if (cm->hEasyWnd == NULL || IsEnable(cm->hEasyWnd, 0))\r
+                               {\r
+                                       CmShowTrayMenu(hWnd);\r
+                               }\r
+                               else\r
+                               {\r
+                                       //CmShowOrHideWindow(hWnd);\r
+                               }\r
+                       }\r
+                       break;\r
+               case WM_LBUTTONDBLCLK:\r
+               case WM_RBUTTONDBLCLK:\r
+                       // ダブルクリック\r
+                       if (easymode == false)\r
+                       {\r
+                               if (IsEnable(hWnd, 0))\r
+                               {\r
+                                       CmShowOrHideWindow(hWnd);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               if (cm->hEasyWnd == NULL)\r
+                               {\r
+                                       CmShowEasy();\r
+                               }\r
+                               else\r
+                               {\r
+                                       SetForegroundWindow(cm->hEasyWnd);\r
+                                       SetActiveWindow(cm->hEasyWnd);\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+}\r
+\r
+// 動作モードの設定の適用\r
+void CmApplyCmSetting()\r
+{\r
+       CM_SETTING a;\r
+       bool changed = false;\r
+\r
+       if (cm->CmSettingSupported == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 現在の vpnclient の設定を取得する\r
+       Zero(&a, sizeof(a));\r
+       CcGetCmSetting(cm->Client, &a);\r
+\r
+       // 以前の CM_SETTING と比較して変化点があるか調べる\r
+       if (cm->CmSetting.EasyMode != a.EasyMode)\r
+       {\r
+               changed = true;\r
+       }\r
+       if (cm->CmSetting.LockMode != a.LockMode)\r
+       {\r
+               changed = true;\r
+       }\r
+\r
+       Copy(&cm->CmSetting, &a, sizeof(CM_SETTING));\r
+\r
+       if (changed == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (cm->StartupFinished)\r
+       {\r
+               if (IsShow(cm->hMainWnd, 0) && cm->CmSetting.EasyMode)\r
+               {\r
+                       // メインウインドウが表示されていれば閉じる\r
+                       Hide(cm->hMainWnd, 0);\r
+               }\r
+               else\r
+               {\r
+                       if (cm->CmSetting.EasyMode == false && IsShow(cm->hMainWnd, 0) == false)\r
+                       {\r
+                               // 通常モードに復帰した際は、メインウインドウを復元する\r
+                               if (IsZero(&cm->FakeWindowPlacement, sizeof(cm->FakeWindowPlacement)) == false)\r
+                               {\r
+                                       cm->FakeWindowPlacement.flags = cm->FakeWindowPlacement.flags & ~SW_MINIMIZE;\r
+                                       SetWindowPlacement(cm->hMainWnd, &cm->FakeWindowPlacement);\r
+                                       Zero(&cm->FakeWindowPlacement, sizeof(cm->FakeWindowPlacement));\r
+                                       Hide(cm->hMainWnd, 0);\r
+                               }\r
+                               CmShowOrHideWindow(cm->hMainWnd);\r
+                       }\r
+               }\r
+\r
+               Command(cm->hMainWnd, CMD_REFRESH);\r
+       }\r
+\r
+       if (cm->CmSetting.EasyMode)\r
+       {\r
+               if (cm->StartupFinished == false && cm->StartupMode)\r
+               {\r
+                       // /startup の場合は表示しない\r
+               }\r
+               else\r
+               {\r
+                       CmShowEasy();\r
+               }\r
+       }\r
+       else\r
+       {\r
+               CmCloseEasy();\r
+       }\r
+}\r
+\r
+// 動作モード変更ダイアログ初期化\r
+void CmSettingDlgInit(HWND hWnd, CM_SETTING_DLG *d)\r
+{\r
+       CM_SETTING a;\r
+       // 引数チェック\r
+       if (hWnd == NULL || d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 現在の vpnclient の設定を取得する\r
+       Zero(&a, sizeof(a));\r
+       CcGetCmSetting(cm->Client, &a);\r
+\r
+       Check(hWnd, R_EASY, a.EasyMode);\r
+       Check(hWnd, R_NORMAL, a.EasyMode == false);\r
+\r
+       if (a.EasyMode == false)\r
+       {\r
+               Focus(hWnd, R_NORMAL);\r
+       }\r
+       else\r
+       {\r
+               Focus(hWnd, R_EASY);\r
+       }\r
+\r
+       Check(hWnd, R_LOCK, a.LockMode);\r
+\r
+       SetEnable(hWnd, R_EASY, cm->CmEasyModeSupported);\r
+\r
+       if (a.LockMode)\r
+       {\r
+               if (IsZero(a.HashedPassword, sizeof(a.HashedPassword)) == false)\r
+               {\r
+                       // パスワードが設定されている\r
+                       SetText(hWnd, S_PASSWORD1, _UU("CM_SETTING_PASSWORD"));\r
+                       Hide(hWnd, S_PASSWORD3);\r
+                       Hide(hWnd, E_PASSWORD2);\r
+\r
+                       d->CheckPassword = true;\r
+                       Copy(d->HashedPassword, a.HashedPassword, sizeof(d->HashedPassword));\r
+               }\r
+       }\r
+\r
+       CmSettingDlgUpdate(hWnd, d);\r
+}\r
+\r
+// 動作モード変更ダイアログ更新\r
+void CmSettingDlgUpdate(HWND hWnd, CM_SETTING_DLG *d)\r
+{\r
+       bool ok = true;\r
+       char tmp1[MAX_SIZE], tmp2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetTxtA(hWnd, E_PASSWORD1, tmp1, sizeof(tmp1));\r
+       GetTxtA(hWnd, E_PASSWORD2, tmp2, sizeof(tmp2));\r
+\r
+       if (d->CheckPassword == false)\r
+       {\r
+               if (IsChecked(hWnd, R_LOCK))\r
+               {\r
+                       if (StrCmp(tmp1, tmp2) != 0)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               bool password_ok = false;\r
+               UCHAR hash[SHA1_SIZE];\r
+\r
+               Hash(hash, tmp1, StrLen(tmp1), true);\r
+               if (Cmp(hash, d->HashedPassword, sizeof(hash)) == 0)\r
+               {\r
+                       password_ok = true;\r
+               }\r
+\r
+               if (password_ok == false)\r
+               {\r
+                       Check(hWnd, R_LOCK, true);\r
+                       Disable(hWnd, R_LOCK);\r
+               }\r
+               else\r
+               {\r
+                       Enable(hWnd, R_LOCK);\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, S_PASSWORD1, IsChecked(hWnd, R_LOCK));\r
+       SetEnable(hWnd, S_PASSWORD2, IsChecked(hWnd, R_LOCK));\r
+       SetEnable(hWnd, S_PASSWORD3, IsChecked(hWnd, R_LOCK));\r
+       SetEnable(hWnd, E_PASSWORD1, IsChecked(hWnd, R_LOCK));\r
+       SetEnable(hWnd, E_PASSWORD2, IsChecked(hWnd, R_LOCK));\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// 動作モード変更ダイアログ OK\r
+void CmSettingDlgOnOk(HWND hWnd, CM_SETTING_DLG *d)\r
+{\r
+       CM_SETTING a;\r
+       char tmp1[MAX_SIZE], tmp2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetTxtA(hWnd, E_PASSWORD1, tmp1, sizeof(tmp1));\r
+       GetTxtA(hWnd, E_PASSWORD2, tmp2, sizeof(tmp2));\r
+\r
+       Zero(&a, sizeof(a));\r
+\r
+       a.EasyMode = IsChecked(hWnd, R_EASY);\r
+       a.LockMode = IsChecked(hWnd, R_LOCK);\r
+\r
+       if (a.LockMode)\r
+       {\r
+               if (d->CheckPassword && IsEnable(hWnd, R_LOCK) == false)\r
+               {\r
+                       Copy(a.HashedPassword, d->HashedPassword, sizeof(a.HashedPassword));\r
+               }\r
+               else\r
+               {\r
+                       if (StrLen(tmp1) >= 1)\r
+                       {\r
+                               Hash(a.HashedPassword, tmp1, StrLen(tmp1), true);\r
+                       }\r
+               }\r
+       }\r
+\r
+       CcSetCmSetting(cm->Client, &a);\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// 動作モード変更ダイアログ\r
+UINT CmSettingDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       CM_SETTING_DLG *d = (CM_SETTING_DLG *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               CmSettingDlgInit(hWnd, d);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_EASY:\r
+               case R_NORMAL:\r
+               case R_LOCK:\r
+               case E_PASSWORD1:\r
+               case E_PASSWORD2:\r
+               case IDOK:\r
+               case IDCANCEL:\r
+                       CmSettingDlgUpdate(hWnd, d);\r
+                       break;\r
+               }\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       CmSettingDlgOnOk(hWnd, d);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case R_LOCK:\r
+                       if (IsChecked(hWnd, R_LOCK))\r
+                       {\r
+                               if (IsEmpty(hWnd, E_PASSWORD1))\r
+                               {\r
+                                       Focus(hWnd, E_PASSWORD1);\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 動作モード変更\r
+bool CmSetting(HWND hWnd)\r
+{\r
+       CM_SETTING_DLG d;\r
+\r
+       Zero(&d, sizeof(d));\r
+\r
+       return Dialog(hWnd, D_CM_SETTING, CmSettingDlg, &d);\r
+}\r
+\r
+// UI Helper の起動の試行スレッド\r
+void CmTryToExecUiHelperThread(THREAD *thread, void *param)\r
+{\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       bool first_flag = true;\r
+\r
+       while (cm->TryExecUiHelperHalt == false && cm->WindowsShutdowning == false)\r
+       {\r
+               if (first_flag == false)\r
+               {\r
+                       // 初回以外は少し待つ\r
+                       Wait(cm->TryExecUiHelperHaltEvent, CM_TRY_EXEC_UI_HELPER_INTERVAL * 2);\r
+\r
+                       if (cm->TryExecUiHelperHalt || cm->WindowsShutdowning)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+               first_flag = false;\r
+\r
+               if (cm->TryExecUiHelperHalt == false && cm->WindowsShutdowning == false)\r
+               {\r
+                       if (cm->TryExecUiHelperProcessHandle == NULL)\r
+                       {\r
+                               CmTryToExecUiHelper();\r
+                       }\r
+               }\r
+\r
+               if (cm->TryExecUiHelperHalt || cm->WindowsShutdowning)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               if (cm->TryExecUiHelperProcessHandle == NULL)\r
+               {\r
+                       Wait(cm->TryExecUiHelperHaltEvent, CM_TRY_EXEC_UI_HELPER_INTERVAL);\r
+               }\r
+               else\r
+               {\r
+                       HANDLE handles[2];\r
+                       handles[0] = cm->TryExecUiHelperProcessHandle;\r
+                       handles[1] = (HANDLE)cm->TryExecUiHelperHaltEvent->pData;\r
+                       WaitForMultipleObjects(2, handles, false, CM_TRY_EXEC_UI_HELPER_INTERVAL);\r
+\r
+                       if (WaitForSingleObject(cm->TryExecUiHelperProcessHandle, 0) != WAIT_TIMEOUT)\r
+                       {\r
+                               CloseHandle(cm->TryExecUiHelperProcessHandle);\r
+                               cm->TryExecUiHelperProcessHandle = NULL;\r
+                               if (cm->TryExecUiHelperHalt || cm->WindowsShutdowning)\r
+                               {\r
+                                       break;\r
+                               }\r
+                               Wait(cm->TryExecUiHelperHaltEvent, CM_TRY_EXEC_UI_HELPER_INTERVAL * 2);\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// UI Helper 終了\r
+void CmFreeTryToExecUiHelper()\r
+{\r
+       cm->TryExecUiHelperHalt = true;\r
+       Set(cm->TryExecUiHelperHaltEvent);\r
+\r
+       WaitThread(cm->TryExecUiHelperThread, INFINITE);\r
+\r
+       ReleaseThread(cm->TryExecUiHelperThread);\r
+       cm->TryExecUiHelperThread = NULL;\r
+\r
+       ReleaseEvent(cm->TryExecUiHelperHaltEvent);\r
+       cm->TryExecUiHelperHaltEvent = NULL;\r
+\r
+       cm->TryExecUiHelperHalt = false;\r
+       cm->TryExecUiHelperProcessHandle = NULL;\r
+}\r
+\r
+// UI Helper 起動初期化\r
+void CmInitTryToExecUiHelper()\r
+{\r
+       cm->TryExecUiHelperProcessHandle = NULL;\r
+       cm->TryExecUiHelperHalt = false;\r
+       cm->TryExecUiHelperHaltEvent = NewEvent();\r
+       cm->TryExecUiHelperThread = NewThread(CmTryToExecUiHelperThread, NULL);\r
+}\r
+\r
+// UI Helper の起動\r
+void *CmExecUiHelperMain()\r
+{\r
+       HANDLE h;\r
+       wchar_t tmp[MAX_SIZE];\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"%s\\%S", MsGetExeDirNameW(), CiGetVpnClientExeFileName());\r
+\r
+       // 起動\r
+       h = Win32RunExW(tmp, SVC_ARG_UIHELP_W, false);\r
+\r
+       return (void *)h;\r
+}\r
+\r
+// UI Helper の起動の試行\r
+void CmTryToExecUiHelper()\r
+{\r
+       HANDLE h;\r
+       // 既に起動していないかどうかチェックする\r
+       if (CnCheckAlreadyExists(false))\r
+       {\r
+               // 既に起動している\r
+               return;\r
+       }\r
+\r
+       h = (HANDLE)CmExecUiHelperMain();\r
+\r
+       if (h != NULL)\r
+       {\r
+               cm->TryExecUiHelperProcessHandle = h;\r
+       }\r
+}\r
+\r
+// ダイアログ初期化\r
+void CmTrafficResultDlgInit(HWND hWnd, TT_RESULT *res)\r
+{\r
+       LVB *ct;\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t tmp1[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       char str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || res == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_SWITCH);\r
+\r
+       SetFont(hWnd, L_STATUS, GetFont(_SS("DEFAULT_FONT_2"), 10, false, false, false, false));\r
+\r
+       LvInit(hWnd, L_STATUS);\r
+       LvSetStyle(hWnd, L_STATUS, LVS_EX_GRIDLINES);\r
+       LvInsertColumn(hWnd, L_STATUS, 0, _UU("TTC_RES_COLUMN_1"), 100);\r
+       LvInsertColumn(hWnd, L_STATUS, 1, _UU("TTC_RES_COLUMN_2"), 100);\r
+       LvInsertColumn(hWnd, L_STATUS, 2, _UU("TTC_RES_COLUMN_3"), 100);\r
+\r
+       ct = LvInsertStart();\r
+\r
+       // 測定に使用した時間\r
+       GetSpanStrMilli(str, sizeof(str), res->Span);\r
+       StrToUni(tmp, sizeof(tmp), str);\r
+       LvInsertAdd(ct, ICO_DATETIME, NULL, 3, _UU("TTC_RES_SPAN"), tmp, L"");\r
+\r
+       // Ethernet フレーム用にデータ補正\r
+       LvInsertAdd(ct, ICO_INFORMATION, NULL, 3, _UU("TTC_RES_ETHER"), res->Raw ? _UU("SEC_NO") : _UU("SEC_YES"), L"");\r
+\r
+       // ダウンロード方向の通信データ量\r
+       ToStr3(str, sizeof(str), res->NumBytesDownload);\r
+       UniFormat(tmp1, sizeof(tmp1), L"%S Bytes", str);\r
+       ToStrByte1000(str, sizeof(str), res->NumBytesDownload);\r
+       StrToUni(tmp2, sizeof(tmp2), str);\r
+       LvInsertAdd(ct, ICO_INFORMATION, NULL, 3, _UU("TTC_RES_BYTES_DOWNLOAD"), tmp1, tmp2);\r
+\r
+       // アップロード方向の通信データ量\r
+       ToStr3(str, sizeof(str), res->NumBytesUpload);\r
+       UniFormat(tmp1, sizeof(tmp1), L"%S Bytes", str);\r
+       ToStrByte1000(str, sizeof(str), res->NumBytesUpload);\r
+       StrToUni(tmp2, sizeof(tmp2), str);\r
+       LvInsertAdd(ct, ICO_INFORMATION, NULL, 3, _UU("TTC_RES_BYTES_UPLOAD"), tmp1, tmp2);\r
+\r
+       // 合計通信データ量\r
+       ToStr3(str, sizeof(str), res->NumBytesTotal);\r
+       UniFormat(tmp1, sizeof(tmp1), L"%S Bytes", str);\r
+       ToStrByte1000(str, sizeof(str), res->NumBytesTotal);\r
+       StrToUni(tmp2, sizeof(tmp2), str);\r
+       LvInsertAdd(ct, ICO_INFORMATION, NULL, 3, _UU("TTC_RES_BYTES_TOTAL"), tmp1, tmp2);\r
+\r
+       // 中継機器入出力合計スループット算出\r
+       LvInsertAdd(ct, ICO_INFORMATION, NULL, 3, _UU("TTC_RES_DOUBLE"), (res->Double == false) ? _UU("SEC_NO") : _UU("SEC_YES"), L"");\r
+\r
+       // ダウンロード方向の平均スループット\r
+       ToStr3(str, sizeof(str), res->BpsDownload);\r
+       UniFormat(tmp1, sizeof(tmp1), L"%S bps", str);\r
+       ToStrByte1000(str, sizeof(str), res->BpsDownload);\r
+       ReplaceStr(str, sizeof(str), str, "Bytes", "bps");\r
+       StrToUni(tmp2, sizeof(tmp2), str);\r
+       LvInsertAdd(ct, ICO_INFORMATION, NULL, 3, _UU("TTC_RES_BPS_DOWNLOAD"), tmp1, tmp2);\r
+\r
+       // アップロード方向の平均スループット\r
+       ToStr3(str, sizeof(str), res->BpsUpload);\r
+       UniFormat(tmp1, sizeof(tmp1), L"%S bps", str);\r
+       ToStrByte1000(str, sizeof(str), res->BpsUpload);\r
+       ReplaceStr(str, sizeof(str), str, "Bytes", "bps");\r
+       StrToUni(tmp2, sizeof(tmp2), str);\r
+       LvInsertAdd(ct, ICO_INFORMATION, NULL, 3, _UU("TTC_RES_BPS_UPLOAD"), tmp1, tmp2);\r
+\r
+       // 合計平均スループット\r
+       ToStr3(str, sizeof(str), res->BpsTotal);\r
+       UniFormat(tmp1, sizeof(tmp1), L"%S bps", str);\r
+       ToStrByte1000(str, sizeof(str), res->BpsTotal);\r
+       ReplaceStr(str, sizeof(str), str, "Bytes", "bps");\r
+       StrToUni(tmp2, sizeof(tmp2), str);\r
+       LvInsertAdd(ct, ICO_INFORMATION, NULL, 3, _UU("TTC_RES_BPS_TOTAL"), tmp1, tmp2);\r
+\r
+       LvInsertEnd(ct, hWnd, L_STATUS);\r
+\r
+       LvAutoSize(hWnd, L_STATUS);\r
+}\r
+\r
+// トラフィック測定結果の表示ダイアログプロシージャ\r
+UINT CmTrafficResultDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       TT_RESULT *r = (TT_RESULT *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               CmTrafficResultDlgInit(hWnd, r);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// トラフィック測定結果の表示\r
+void CmTrafficResult(HWND hWnd, TT_RESULT *r)\r
+{\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_CM_TRAFFIC_RESULT, CmTrafficResultDlg, r);\r
+}\r
+\r
+// クライアントの終了を待機するスレッド\r
+void CmTrafficRunDlgClientWaitThread(THREAD *t, void *param)\r
+{\r
+       CM_TRAFFIC_DLG *d = (CM_TRAFFIC_DLG *)param;\r
+       TT_RESULT result;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&result, sizeof(result));\r
+       ret = FreeTtc(d->Ttc, &result);\r
+       d->Ttc = NULL;\r
+\r
+       d->RetCode = ret;\r
+       Copy(&d->Result, &result, sizeof(TT_RESULT));\r
+\r
+       PostMessage(d->hWnd, WM_APP + 66, 0, 0);\r
+}\r
+\r
+// 文字列の追記\r
+void CmTrafficRunDlgAddStr(HWND hWnd, wchar_t *str)\r
+{\r
+       wchar_t *tmp;\r
+       UINT tmp_size;\r
+\r
+       tmp_size = UniStrSize(str) + 32;\r
+       tmp = Malloc(tmp_size);\r
+       UniStrCpy(tmp, tmp_size, str);\r
+       if (UniEndWith(str, L"\n") == false)\r
+       {\r
+               UniStrCat(tmp, tmp_size, L"\n");\r
+       }\r
+\r
+       UniReplaceStrEx(tmp, tmp_size, tmp, L"\r\n", L"\n", false);\r
+       UniReplaceStrEx(tmp, tmp_size, tmp, L"\n", L"\r\n", false);\r
+\r
+       if (MsIsNt())\r
+       {\r
+               SendMsg(hWnd, E_EDIT, EM_SETSEL, 0x7fffffff, 0x7fffffff);\r
+               SendMsg(hWnd, E_EDIT, EM_REPLACESEL, false, (LPARAM)tmp);\r
+       }\r
+       else\r
+       {\r
+               char *s = CopyUniToStr(tmp);\r
+               UINT len;\r
+\r
+               len = GetWindowTextLength(DlgItem(hWnd, E_EDIT));\r
+               SendMsg(hWnd, E_EDIT, EM_SETSEL, 0x7fffffff, 0x7fffffff);\r
+               SendMsg(hWnd, E_EDIT, EM_SETSEL, len, len);\r
+               SendMsg(hWnd, E_EDIT, EM_REPLACESEL, false, (LPARAM)s);\r
+               Free(s);\r
+       }\r
+\r
+       Free(tmp);\r
+}\r
+\r
+// 文字列の表示\r
+void CmTrafficRunDlgPrintProc(void *param, wchar_t *str)\r
+{\r
+       CM_TRAFFIC_DLG *d = (CM_TRAFFIC_DLG *)param;\r
+       HWND hWnd;\r
+       // 引数チェック\r
+       if (param == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       hWnd = d->hWnd;\r
+\r
+       PostMessage(hWnd, WM_APP + 64, 0, (LPARAM)UniCopyStr(str));\r
+}\r
+\r
+// 測定プログラムの停止用スレッド\r
+void CmTrafficRunDlgHaltThread(THREAD *t, void *param)\r
+{\r
+       CM_TRAFFIC_DLG *d = (CM_TRAFFIC_DLG *)param;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (d->Setting->ServerMode)\r
+       {\r
+               // サーバーを停止\r
+               d->RetCode = FreeTts(d->Tts);\r
+\r
+               PostMessage(d->hWnd, WM_APP + 65, 0, 0);\r
+       }\r
+}\r
+\r
+// 測定プログラムを停止する\r
+void CmTrafficRunDlgHalt(HWND hWnd, CM_TRAFFIC_DLG *d)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (d->Started == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (d->Setting->ServerMode)\r
+       {\r
+               if (d->HaltThread == NULL)\r
+               {\r
+                       Disable(hWnd, IDCANCEL);\r
+                       d->HaltThread = NewThread(CmTrafficRunDlgHaltThread, d);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (d->ClientEndWaitThread != NULL)\r
+               {\r
+                       StopTtc(d->Ttc);\r
+               }\r
+               else\r
+               {\r
+                       EndDialog(hWnd, 0);\r
+               }\r
+       }\r
+}\r
+\r
+// トラフィック測定の動作を開始する\r
+void CmTrafficRunDlgStart(HWND hWnd, CM_TRAFFIC_DLG *d)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (d->Setting->ServerMode)\r
+       {\r
+               // 測定サーバーを開始\r
+               d->Tts = NewTts(d->Setting->Port, d, CmTrafficRunDlgPrintProc);\r
+       }\r
+       else\r
+       {\r
+               // 測定クライアントを開始\r
+               d->Ttc = NewTtc(d->Setting->Host, d->Setting->Port,\r
+                       d->Setting->NumTcp, d->Setting->Type, d->Setting->Span * 1000ULL,\r
+                       d->Setting->Double, d->Setting->Raw, CmTrafficRunDlgPrintProc, d);\r
+\r
+               d->ClientEndWaitThread = NewThread(CmTrafficRunDlgClientWaitThread, d);\r
+       }\r
+\r
+       d->Started = true;\r
+}\r
+\r
+// トラフィック測定実行ダイアログ初期化\r
+void CmTrafficRunDlgInit(HWND hWnd, CM_TRAFFIC_DLG *d)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       d->hWnd = hWnd;\r
+\r
+       SetIcon(hWnd, 0, ICO_SWITCH);\r
+       DlgFont(hWnd, S_INFO, 11, false);\r
+       SetFont(hWnd, E_EDIT, GetFont(_SS("DEFAULT_FONT_2"), 0, false, false,\r
+               false, false));\r
+\r
+       Focus(hWnd, IDCANCEL);\r
+}\r
+\r
+// トラフィック測定実行ダイアログプロシージャ\r
+UINT CmTrafficRunDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       CM_TRAFFIC_DLG *d = (CM_TRAFFIC_DLG *)param;\r
+       wchar_t *s;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               CmTrafficRunDlgInit(hWnd, d);\r
+\r
+               SetTimer(hWnd, 1, 10, NULL);\r
+               break;\r
+\r
+       case WM_APP + 64:\r
+               // 文字列追加\r
+               s = (wchar_t *)lParam;\r
+               if (s != NULL)\r
+               {\r
+                       CmTrafficRunDlgAddStr(hWnd, s);\r
+                       Free(s);\r
+               }\r
+               break;\r
+\r
+       case WM_APP + 65:\r
+               // 停止完了\r
+               if (d->HaltThread != NULL)\r
+               {\r
+                       WaitThread(d->HaltThread, INFINITE);\r
+                       ReleaseThread(d->HaltThread);\r
+                       d->HaltThread = NULL;\r
+                       EndDialog(hWnd, 0);\r
+               }\r
+               break;\r
+\r
+       case WM_APP + 66:\r
+               // 結果表示\r
+               if (d->RetCode == ERR_NO_ERROR)\r
+               {\r
+                       CmTrafficResult(hWnd, &d->Result);\r
+               }\r
+\r
+               if (d->ClientEndWaitThread != NULL)\r
+               {\r
+                       WaitThread(d->ClientEndWaitThread, INFINITE);\r
+                       ReleaseThread(d->ClientEndWaitThread);\r
+                       d->ClientEndWaitThread = NULL;\r
+               }\r
+\r
+               if (d->CloseDialogAfter)\r
+               {\r
+                       EndDialog(hWnd, 0);\r
+               }\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+\r
+                       CmTrafficRunDlgStart(hWnd, d);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               d->CloseDialogAfter = true;\r
+               CmTrafficRunDlgHalt(hWnd, d);\r
+               return 1;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// トラフィック測定を実行する\r
+void CmExecTraffic(HWND hWnd, CM_TRAFFIC *t)\r
+{\r
+       CM_TRAFFIC_DLG d;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&d, sizeof(d));\r
+       d.Setting = t;\r
+       d.ResultShowEvent = NewEvent();\r
+\r
+       MsSetThreadPriorityHigh();\r
+       Dialog(hWnd, D_CM_TRAFFIC_RUN, CmTrafficRunDlg, &d);\r
+       MsRestoreThreadPriority();\r
+\r
+       ReleaseEvent(d.ResultShowEvent);\r
+}\r
+\r
+// レジストリに設定を書き込む\r
+void CmTrafficSaveToReg(CM_TRAFFIC *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "ServerMode", t->ServerMode ? 1 : 0);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "Double", t->Double ? 1 : 0);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "Raw", t->Raw ? 1 : 0);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "Port", t->Port);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "NumTcp", t->NumTcp);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "Type", t->Type);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "Span", t->Span);\r
+       MsRegWriteStr(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "Host", t->Host);\r
+}\r
+\r
+// レジストリから設定を読み込む\r
+bool CmTrafficLoadFromReg(CM_TRAFFIC *t)\r
+{\r
+       char *s;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(t, sizeof(CM_TRAFFIC));\r
+\r
+       if (MsRegIsKey(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       t->Double = MsRegReadInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "Double") == 0 ? false : true;\r
+       t->Raw = MsRegReadInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "Raw") == 0 ? false : true;\r
+       t->Port = MsRegReadInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "Port");\r
+       if (t->Port == 0)\r
+       {\r
+               t->Port = TRAFFIC_DEFAULT_PORT;\r
+       }\r
+\r
+       s = MsRegReadStr(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "Host");\r
+\r
+       if (IsEmptyStr(s) == false)\r
+       {\r
+               Trim(s);\r
+               StrCpy(t->Host, sizeof(t->Host), s);\r
+       }\r
+\r
+       Free(s);\r
+\r
+       t->NumTcp = MsRegReadInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "NumTcp");\r
+       t->NumTcp = MAKESURE(t->NumTcp, 1, TRAFFIC_NUMTCP_MAX);\r
+       t->Type = MsRegReadInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "Type");\r
+\r
+       if (t->Type != TRAFFIC_TYPE_DOWNLOAD && t->Type != TRAFFIC_TYPE_UPLOAD &&\r
+               t->Type != TRAFFIC_TYPE_FULL)\r
+       {\r
+               t->Type = TRAFFIC_TYPE_FULL;\r
+       }\r
+\r
+       t->Span = MsRegReadInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "Span");\r
+       if (t->Span == 0)\r
+       {\r
+               t->Span = TRAFFIC_SPAN_DEFAULT;\r
+       }\r
+\r
+       t->ServerMode = MsRegReadInt(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "ServerMode") == 0 ? false : true;\r
+\r
+       return true;\r
+}\r
+\r
+// デフォルトの設定を取得する\r
+void CmTrafficGetDefaultSetting(CM_TRAFFIC *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(CM_TRAFFIC));\r
+\r
+       t->Double = false;\r
+       t->Raw = false;\r
+       t->Port = TRAFFIC_DEFAULT_PORT;\r
+       t->NumTcp = TRAFFIC_NUMTCP_DEFAULT;\r
+       t->Type = TRAFFIC_TYPE_FULL;\r
+       t->Span = TRAFFIC_SPAN_DEFAULT;\r
+       t->ServerMode = false;\r
+}\r
+\r
+// 通信スループット測定ツールダイアログ初期化\r
+void CmTrafficDlgInit(HWND hWnd)\r
+{\r
+       CM_TRAFFIC t;\r
+       LIST *c1, *c2;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DlgFont(hWnd, S_8, 9, true);\r
+       DlgFont(hWnd, S_3, 9, true);\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CmTrafficLoadFromReg(&t) == false)\r
+       {\r
+               CmTrafficGetDefaultSetting(&t);\r
+       }\r
+\r
+       // 設定をダイアログに書き出す\r
+       Check(hWnd, R_SERVER, t.ServerMode);\r
+       Check(hWnd, R_CLIENT, t.ServerMode == false);\r
+\r
+       c1 = ReadCandidateFromReg(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "HostCandidate");\r
+       if (c1 != NULL)\r
+       {\r
+               UINT i;\r
+\r
+               CbReset(hWnd, C_HOST);\r
+\r
+               for (i = 0;i < LIST_NUM(c1);i++)\r
+               {\r
+                       CANDIDATE *c = LIST_DATA(c1, i);\r
+\r
+                       CbAddStr(hWnd, C_HOST, c->Str, 0);\r
+               }\r
+\r
+               FreeCandidateList(c1);\r
+       }\r
+\r
+       if (CbNum(hWnd, C_HOST) == 0)\r
+       {\r
+               CbAddStr(hWnd, C_HOST, L"speed.softether.com", 0);\r
+       }\r
+\r
+       if (IsEmptyStr(t.Host) == false)\r
+       {\r
+               SetTextA(hWnd, C_HOST, t.Host);\r
+       }\r
+\r
+       c2 = ReadCandidateFromReg(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "PortCandidate");\r
+       if (c2 != NULL)\r
+       {\r
+               UINT i;\r
+\r
+               if (t.Port != 0)\r
+               {\r
+                       wchar_t tmp[32];\r
+\r
+                       UniToStru(tmp, t.Port);\r
+\r
+                       AddCandidate(c2, tmp, 0);\r
+               }\r
+\r
+               CbReset(hWnd, C_PORT);\r
+\r
+               for (i = 0;i < LIST_NUM(c2);i++)\r
+               {\r
+                       CANDIDATE *c = LIST_DATA(c2, i);\r
+\r
+                       CbAddStr(hWnd, C_PORT, c->Str, 0);\r
+               }\r
+\r
+               FreeCandidateList(c2);\r
+       }\r
+\r
+       CbReset(hWnd, C_NUM);\r
+\r
+       for (i = 1;i <= TRAFFIC_NUMTCP_MAX;i++)\r
+       {\r
+               wchar_t tmp[32];\r
+\r
+               UniToStru(tmp, i);\r
+\r
+               CbAddStr(hWnd, C_NUM, tmp, i);\r
+       }\r
+\r
+       CbSelect(hWnd, C_NUM, t.NumTcp);\r
+\r
+       Check(hWnd, R_DOWNLOAD, t.Type == TRAFFIC_TYPE_DOWNLOAD);\r
+       Check(hWnd, R_UPLOAD, t.Type == TRAFFIC_TYPE_UPLOAD);\r
+       Check(hWnd, R_FULL, t.Type == TRAFFIC_TYPE_FULL);\r
+\r
+       Check(hWnd, R_ETHERNET, t.Raw ? false : true);\r
+       Check(hWnd, R_DOUBLE, t.Double);\r
+\r
+       SetIntEx(hWnd, E_SPAN, t.Span);\r
+\r
+       CmTrafficDlgUpdate(hWnd);\r
+}\r
+\r
+// ダイアログの内容を構造体に入れる\r
+void CmTrafficDlgToStruct(HWND hWnd, CM_TRAFFIC *t)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(CM_TRAFFIC));\r
+       t->ServerMode = IsChecked(hWnd, R_SERVER);\r
+       GetTxtA(hWnd, C_HOST, t->Host, sizeof(t->Host));\r
+       Trim(t->Host);\r
+\r
+       t->Port = GetInt(hWnd, C_PORT);\r
+       t->NumTcp = CbGetSelect(hWnd, C_NUM);\r
+       t->Span = GetInt(hWnd, E_SPAN);\r
+       t->Raw = IsChecked(hWnd, R_ETHERNET) ? false : true;\r
+       t->Double = IsChecked(hWnd, R_DOUBLE);\r
+\r
+       if (IsChecked(hWnd, R_DOWNLOAD))\r
+       {\r
+               t->Type = TRAFFIC_TYPE_DOWNLOAD;\r
+       }\r
+       else if (IsChecked(hWnd, R_UPLOAD))\r
+       {\r
+               t->Type = TRAFFIC_TYPE_UPLOAD;\r
+       }\r
+       else\r
+       {\r
+               t->Type = TRAFFIC_TYPE_FULL;\r
+       }\r
+}\r
+\r
+// 通信スループット測定ツールダイアログ更新\r
+bool CmTrafficDlgUpdate(HWND hWnd)\r
+{\r
+       CM_TRAFFIC t;\r
+       bool ok = true;\r
+       bool client_only;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       CmTrafficDlgToStruct(hWnd, &t);\r
+\r
+       client_only = t.ServerMode ? false : true;\r
+\r
+       SetEnable(hWnd, C_HOST, client_only);\r
+       SetEnable(hWnd, S_5, client_only);\r
+       SetEnable(hWnd, S_8, client_only);\r
+       SetEnable(hWnd, S_9, client_only);\r
+       SetEnable(hWnd, R_DOWNLOAD, client_only);\r
+       SetEnable(hWnd, R_UPLOAD, client_only);\r
+       SetEnable(hWnd, R_FULL, client_only);\r
+       SetEnable(hWnd, S_10, client_only);\r
+       SetEnable(hWnd, S_11, client_only);\r
+       SetEnable(hWnd, C_NUM, client_only);\r
+       SetEnable(hWnd, S_14, client_only);\r
+       SetEnable(hWnd, S_12, client_only);\r
+       SetEnable(hWnd, E_SPAN, client_only);\r
+       SetEnable(hWnd, S_13, client_only);\r
+       SetEnable(hWnd, R_ETHERNET, client_only);\r
+       SetEnable(hWnd, R_DOUBLE, client_only);\r
+\r
+       if (t.Port == 0 || t.Port >= 65536)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (t.ServerMode == false)\r
+       {\r
+               if (IsEmptyStr(t.Host))\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (t.NumTcp == 0 || t.NumTcp >= 33)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (t.Span == 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (t.Type == TRAFFIC_TYPE_FULL && ((t.NumTcp % 2) != 0))\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+\r
+       return ok;\r
+}\r
+\r
+// 通信スループット測定ツールダイアログ OK ボタン\r
+void CmTrafficDlgOnOk(HWND hWnd)\r
+{\r
+       CM_TRAFFIC t;\r
+       LIST *c;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 基本データの取得\r
+       CmTrafficDlgToStruct(hWnd, &t);\r
+\r
+       // レジストリに保存\r
+       CmTrafficSaveToReg(&t);\r
+\r
+       // サーバー名候補の取得と保存\r
+       if (IsEmptyStr(t.Host) == false)\r
+       {\r
+               c = ReadCandidateFromReg(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "HostCandidate");\r
+               if (c != NULL)\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       StrToUni(tmp, sizeof(tmp), t.Host);\r
+                       AddCandidate(c, tmp, 0);\r
+\r
+                       WriteCandidateToReg(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, c, "HostCandidate");\r
+\r
+                       FreeCandidateList(c);\r
+               }\r
+       }\r
+\r
+       if (t.Port != 0 && t.Port <= 65536)\r
+       {\r
+               // ポート番号候補の取得と保存\r
+               c = ReadCandidateFromReg(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, "PortCandidate");\r
+               if (c != NULL)\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       UniToStru(tmp, t.Port);\r
+                       AddCandidate(c, tmp, 0);\r
+\r
+                       WriteCandidateToReg(REG_CURRENT_USER, CM_TRAFFIC_REG_KEY, c, "PortCandidate");\r
+\r
+                       FreeCandidateList(c);\r
+               }\r
+       }\r
+\r
+       // 実行\r
+       CmExecTraffic(hWnd, &t);\r
+\r
+       // ダイアログを更新\r
+       CmTrafficDlgInit(hWnd);\r
+}\r
+\r
+// 通信スループット測定ツールダイアログプロシージャ\r
+UINT CmTrafficDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetIcon(hWnd, 0, ICO_SWITCH);\r
+               CmTrafficDlgInit(hWnd);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_SERVER:\r
+               case R_CLIENT:\r
+               case C_HOST:\r
+               case C_PORT:\r
+               case R_DOWNLOAD:\r
+               case R_UPLOAD:\r
+               case R_FULL:\r
+               case C_NUM:\r
+               case E_SPAN:\r
+               case R_ETHERNET:\r
+               case R_DOUBLE:\r
+                       CmTrafficDlgUpdate(hWnd);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       CmTrafficDlgOnOk(hWnd);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 通信スループット測定ツール\r
+void CmTraffic(HWND hWnd)\r
+{\r
+       Dialog(hWnd, D_CM_TRAFFIC, CmTrafficDlgProc, NULL);\r
+}\r
+\r
+// 古いスタートアップファイルがあれば削除する\r
+void CmDeleteOldStartupTrayFile()\r
+{\r
+       char tmp[MAX_SIZE];\r
+       char *tag = _SS("CM_JAPANESE_ONLY_OLD_STARTUP");\r
+       if (IsEmptyStr(tag))\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), tag, MsGetCommonStartupDir());\r
+\r
+       FileDelete(tmp);\r
+}\r
+\r
+// PKCS ライセンス確認ダイアログ\r
+UINT CmPkcsEulaDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       UINT id;\r
+       SECURE_DEVICE *dev;\r
+       char *name;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               id = (UINT)param;\r
+               dev = GetSecureDevice(id);\r
+               if (dev == NULL)\r
+               {\r
+                       EndDialog(hWnd, 0);\r
+                       return 0;\r
+               }\r
+\r
+               name = dev->ModuleName;\r
+\r
+               FormatText(hWnd, S_INFO_1, name);\r
+               FormatText(hWnd, S_INFO_2, name, name);\r
+               FormatText(hWnd, S_INFO_3, name);\r
+\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       EndDialog(hWnd, 1);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// PKCS の DLL の EULA に同意しているかどうかの確認画面\r
+bool CmCheckPkcsEula(HWND hWnd, UINT id)\r
+{\r
+       return (Dialog(hWnd, D_CM_PKCSEULA, CmPkcsEulaDlg, (void *)id) == 0) ? false : true;\r
+}\r
+\r
+// コントロール更新\r
+void CmSecurePinDlgUpdate(HWND hWnd)\r
+{\r
+       char *tmp1, *tmp2, *tmp3;\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tmp1 = GetTextA(hWnd, E_PIN1);\r
+       tmp2 = GetTextA(hWnd, E_PIN2);\r
+       tmp3 = GetTextA(hWnd, E_PIN3);\r
+       if (IsEmptyStr(tmp1))\r
+       {\r
+               ok = false;\r
+       }\r
+       if (IsEmptyStr(tmp2))\r
+       {\r
+               ok = false;\r
+       }\r
+       if (IsEmptyStr(tmp3))\r
+       {\r
+               ok = false;\r
+       }\r
+       if (StrCmp(tmp2, tmp3) != 0)\r
+       {\r
+               ok = false;\r
+       }\r
+       Free(tmp1);\r
+       Free(tmp2);\r
+       Free(tmp3);\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// PIN コード変更ダイアログ\r
+UINT CmSecurePinDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       UINT id = (UINT)param;\r
+       char *src, *dst;\r
+       SECURE *s;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               CmSecurePinDlgUpdate(hWnd);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_PIN1:\r
+               case E_PIN2:\r
+               case E_PIN3:\r
+                       CmSecurePinDlgUpdate(hWnd);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       src = GetTextA(hWnd, E_PIN1);\r
+                       dst = GetTextA(hWnd, E_PIN3);\r
+\r
+                       Disable(hWnd, IDOK);\r
+                       Disable(hWnd, IDCANCEL);\r
+\r
+                       s = OpenSec(id);\r
+                       if (s == NULL)\r
+                       {\r
+                               if (GetSecureDevice(id) != NULL)\r
+                               {\r
+                                       MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("SEC_PIN_DEVICE_OPEN_ERR"),\r
+                                               GetSecureDevice(id)->DeviceName);\r
+                               }\r
+                               else\r
+                               {\r
+                                       MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("SEC_PIN_DEVICE_OPEN_ERR"),\r
+                                               "Unknown");\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               if (OpenSecSession(s, 0) == false)\r
+                               {\r
+                                       if (GetSecureDevice(id) != NULL)\r
+                                       {\r
+                                               MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("SEC_PIN_DEVICE_OPEN_ERR"),\r
+                                                       GetSecureDevice(id)->DeviceName);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("SEC_PIN_DEVICE_OPEN_ERR"),\r
+                                                       "Unknown");\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (LoginSec(s, src) == false)\r
+                                       {\r
+                                               MsgBox(hWnd, MB_ICONEXCLAMATION, _UU("SEC_PIN_CURRENT_BAD"));\r
+                                               FocusEx(hWnd, E_PIN1);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (ChangePin(s, src, dst) == false)\r
+                                               {\r
+                                                       MsgBox(hWnd, MB_ICONEXCLAMATION, _UU("SEC_PIN_CHANGE_FAILED"));\r
+                                                       FocusEx(hWnd, E_PIN1);\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       // PIN コードのキャッシュの消去\r
+                                                       cached_pin_code_expires = 0;\r
+                                                       cached_pin_code[0] = 0;\r
+                                                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("SEC_PIN_OK"));\r
+                                                       EndDialog(hWnd, true);\r
+                                               }\r
+\r
+                                               LogoutSec(s);\r
+                                       }\r
+\r
+                                       CloseSecSession(s);\r
+                               }\r
+                               CloseSec(s);\r
+                       }\r
+\r
+                       Enable(hWnd, IDOK);\r
+                       Enable(hWnd, IDCANCEL);\r
+\r
+                       Free(src);\r
+                       Free(dst);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// PIN コードの変更\r
+void CmSecurePin(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || id == 0 || CheckSecureDeviceId(id) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_CM_SECURE_PIN, CmSecurePinDlg, (void *)id);\r
+}\r
+\r
+// オブジェクト種類選択ダイアログ\r
+UINT CmSecureTypeDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       UINT type;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               type = MsRegReadInt(REG_CURRENT_USER, SECURE_MANAGER_KEY, "DefaultImportType");\r
+               Check(hWnd, R_DATA, type == SEC_DATA);\r
+               Check(hWnd, R_CERT, type == SEC_X);\r
+               Check(hWnd, R_KEY, type == SEC_K);\r
+               goto UPDATE_CONTROL;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       type = SEC_DATA;\r
+                       if (IsChecked(hWnd, R_CERT))\r
+                       {\r
+                               type = SEC_X;\r
+                       }\r
+                       else if (IsChecked(hWnd, R_KEY))\r
+                       {\r
+                               type = SEC_K;\r
+                       }\r
+\r
+                       MsRegWriteInt(REG_CURRENT_USER, SECURE_MANAGER_KEY, "DefaultImportType", type);\r
+\r
+                       EndDialog(hWnd, type);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               case R_CERT:\r
+               case R_KEY:\r
+               case R_DATA:\r
+UPDATE_CONTROL:\r
+                       SetEnable(hWnd, IDOK, IsChecked(hWnd, R_CERT) || \r
+                               IsChecked(hWnd, R_KEY) || \r
+                               IsChecked(hWnd, R_DATA));\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, INFINITE);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// オブジェクト種類選択\r
+UINT CmSecureType(HWND hWnd)\r
+{\r
+       return Dialog(hWnd, D_CM_SECURE_TYPE, CmSecureTypeDlg, NULL);\r
+}\r
+\r
+// ダイアログ初期化\r
+void CmSecureManagerDlgInit(HWND hWnd, UINT id)\r
+{\r
+       SECURE_DEVICE *dev;\r
+       // 引数チェック\r
+       if (hWnd == NULL || id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_SECURE);\r
+\r
+       dev = GetSecureDevice(id);\r
+       if (dev != NULL)\r
+       {\r
+               FormatText(hWnd, S_INFO, dev->DeviceName);\r
+       }\r
+\r
+       SetFont(hWnd, B_BOLD, Font(0, true));\r
+\r
+       LvInit(hWnd, L_LIST);\r
+       LvInsertColumn(hWnd, L_LIST, 0, _UU("SEC_MGR_COLUMN1"), 200);\r
+       LvInsertColumn(hWnd, L_LIST, 1, _UU("SEC_MGR_COLUMN2"), 110);\r
+\r
+       CmSecureManagerDlgUpdate(hWnd, id);\r
+}\r
+\r
+// コントロール更新\r
+void CmSecureManagerDlgUpdate(HWND hWnd, UINT id)\r
+{\r
+       bool b = true;\r
+       bool read_only = IsJPKI(id);\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSingleSelected(hWnd, L_LIST) == false)\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       SetEnable(hWnd, B_EXPORT, b && ((UINT)LvGetParam(hWnd, L_LIST, LvGetSelected(hWnd, L_LIST)) != SEC_K));\r
+       SetEnable(hWnd, B_DELETE, b && (read_only == false));\r
+       SetEnable(hWnd, B_PIN, (read_only == false));\r
+       SetEnable(hWnd, B_IMPORT, (read_only == false));\r
+       SetEnable(hWnd, B_NEW_CERT, (read_only == false));\r
+}\r
+\r
+// 内容更新\r
+void CmSecureManagerDlgRefresh(HWND hWnd, UINT id)\r
+{\r
+       bool ret;\r
+       LIST *o;\r
+       WINUI_SECURE_BATCH batch[] =\r
+       {\r
+               {WINUI_SECURE_ENUM_OBJECTS, NULL, false, NULL, NULL, NULL, NULL, NULL, NULL},\r
+       };\r
+       // 引数チェック\r
+       if (hWnd == NULL || id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ret = SecureDeviceWindow(hWnd, batch, sizeof(batch) / sizeof(batch[0]), id, 0);\r
+\r
+       if (ret == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o = batch[0].EnumList;\r
+       if (o != NULL)\r
+       {\r
+               CmSecureManagerDlgPrintList(hWnd, o);\r
+\r
+               FreeEnumSecObject(o);\r
+       }\r
+\r
+       // コントロール更新\r
+       CmSecureManagerDlgUpdate(hWnd, id);\r
+}\r
+\r
+// オブジェクト一覧の表示\r
+void CmSecureManagerDlgPrintList(HWND hWnd, LIST *o)\r
+{\r
+       CmSecureManagerDlgPrintListEx(hWnd, L_LIST, o, INFINITE);\r
+}\r
+void CmSecureManagerDlgPrintListEx(HWND hWnd, UINT id, LIST *o, UINT type)\r
+{\r
+       UINT i;\r
+       LVB *v;\r
+       // 引数チェック\r
+       if (hWnd == NULL || o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LvReset(hWnd, id);\r
+\r
+       v = LvInsertStart();\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               UINT icon = ICO_LOG2;\r
+               wchar_t tmp1[MAX_SIZE], *tmp2, *tmp3;\r
+               SEC_OBJ *obj = LIST_DATA(o, i);\r
+\r
+               if (type == INFINITE || obj->Type == type)\r
+               {\r
+                       StrToUni(tmp1, sizeof(tmp1), obj->Name);\r
+                       tmp2 = CmSecureObjTypeToStr(obj->Type);\r
+                       tmp3 = obj->Private ? _UU("SEC_YES") : _UU("SEC_NO");\r
+\r
+                       if (obj->Type == SEC_X)\r
+                       {\r
+                               icon = ICO_CERT;\r
+                       }\r
+                       else if (obj->Type == SEC_K || obj->Type == SEC_P)\r
+                       {\r
+                               icon = ICO_KEY;\r
+                       }\r
+\r
+                       LvInsertAdd(v, icon, (void *)obj->Type, 2, tmp1, tmp2);\r
+               }\r
+       }\r
+\r
+       LvInsertEnd(v, hWnd, id);\r
+}\r
+\r
+// オブジェクトの種類を文字列にする\r
+wchar_t *CmSecureObjTypeToStr(UINT type)\r
+{\r
+       wchar_t *ret = _UU("SEC_TYPE_DATA");\r
+\r
+       if (type == SEC_X)\r
+       {\r
+               ret = _UU("SEC_TYPE_CERT");\r
+       }\r
+       else if (type == SEC_K)\r
+       {\r
+               ret = _UU("SEC_TYPE_KEY");\r
+       }\r
+       else if (type == SEC_P)\r
+       {\r
+               ret = _UU("SEC_TYPE_PUB");\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 新しい証明書を作成して書き込み\r
+void CmSecureManagerDlgNewCert(HWND hWnd, UINT id)\r
+{\r
+       X *x;\r
+       K *k;\r
+       char default_name[MAX_SIZE];\r
+       char *object_name;\r
+       bool ok = false;\r
+       WINUI_SECURE_BATCH batch[] =\r
+       {\r
+               {WINUI_SECURE_WRITE_CERT, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL},\r
+               {WINUI_SECURE_WRITE_KEY, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL},\r
+               {WINUI_SECURE_ENUM_OBJECTS, NULL, false, NULL, NULL, NULL, NULL, NULL, NULL},\r
+       };\r
+       // 引数チェック\r
+       if (hWnd == NULL || id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 証明書の作成ダイアログ\r
+       if (SmCreateCert(hWnd, &x, &k, true, NULL) == false)\r
+       {\r
+               return;\r
+       }\r
+       // デフォルトの名前を生成する\r
+       GetPrintNameFromXA(default_name, sizeof(default_name), x);\r
+       ConvertSafeFileName(default_name, sizeof(default_name), default_name);\r
+\r
+       object_name = StringDlgA(hWnd, _UU("SEC_OBJECT_NAME_TITLE"),\r
+               _UU("SEC_OBJECT_NAME_INFO"), default_name, ICO_CERT, false, false);\r
+\r
+       if (object_name != NULL)\r
+       {\r
+               // 書き込みと列挙\r
+               batch[0].InputX = x;\r
+               batch[0].Name = object_name;\r
+               batch[1].InputK = k;\r
+               batch[1].Name = object_name;\r
+\r
+               if (SecureDeviceWindow(hWnd, batch, sizeof(batch) / sizeof(batch[0]), id, 0) == false)\r
+               {\r
+                       // 失敗\r
+               }\r
+               else\r
+               {\r
+                       ok = true;\r
+               }\r
+\r
+               Free(object_name);\r
+       }\r
+\r
+       if (ok)\r
+       {\r
+               LIST *o = batch[2].EnumList;\r
+\r
+               CmSecureManagerDlgPrintList(hWnd, o);\r
+\r
+               FreeEnumSecObject(o);\r
+\r
+               MsgBox(hWnd, MB_ICONINFORMATION, _UU("SEC_NEW_CERT_IMPORT_OK"));\r
+       }\r
+\r
+       FreeX(x);\r
+       FreeK(k);\r
+}\r
+\r
+// インポート\r
+void CmSecureManagerDlgImport(HWND hWnd, UINT id)\r
+{\r
+       UINT type;\r
+       char name[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       wchar_t *tmp;\r
+       wchar_t *filename;\r
+       BUF *b;\r
+       K *k;\r
+       bool ok = false;\r
+       X *x;\r
+       WINUI_SECURE_BATCH batch[] =\r
+       {\r
+               {WINUI_SECURE_WRITE_DATA, name, true, NULL, NULL, NULL, NULL, NULL, NULL},\r
+               {WINUI_SECURE_ENUM_OBJECTS, NULL, false, NULL, NULL, NULL, NULL, NULL, NULL},\r
+       };\r
+       // 引数チェック\r
+       if (hWnd == NULL || id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // オブジェクトの種類の選択\r
+       type = CmSecureType(hWnd);\r
+\r
+       switch (type)\r
+       {\r
+       case SEC_DATA:\r
+               // データ\r
+               tmp = OpenDlg(hWnd, _UU("DLG_ALL_FILES"), _UU("SEC_IMPORT_DATA"));\r
+               if (tmp == NULL)\r
+               {\r
+                       return;\r
+               }\r
+\r
+               filename = CopyUniStr(tmp);\r
+               Free(tmp);\r
+\r
+               // ファイル読み込み\r
+               b = ReadDumpW(filename);\r
+               if (b == NULL)\r
+               {\r
+                       // 読み込み失敗\r
+                       MsgBox(hWnd, MB_ICONSTOP, _UU("SEC_READ_FAILED"));\r
+               }\r
+               else\r
+               {\r
+                       if (b->Size > MAX_SEC_DATA_SIZE)\r
+                       {\r
+                               // ファイルサイズが大きすぎる\r
+                               MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("SEC_DATA_TOO_BIG"), MAX_SEC_DATA_SIZE);\r
+                       }\r
+                       else\r
+                       {\r
+                               // デフォルトの名前を生成する\r
+                               char default_name[MAX_SIZE];\r
+                               wchar_t default_name_w[MAX_SIZE];\r
+                               char *object_name;\r
+                               GetFileNameFromFilePathW(default_name_w, sizeof(default_name_w), filename);\r
+                               UniToStr(default_name, sizeof(default_name), default_name_w);\r
+                               ConvertSafeFileName(default_name, sizeof(default_name), default_name);\r
+\r
+                               object_name = StringDlgA(hWnd, _UU("SEC_OBJECT_NAME_TITLE"),\r
+                                       _UU("SEC_OBJECT_NAME_INFO"), default_name, ICO_LOG2, false, false);\r
+\r
+                               if (object_name != NULL)\r
+                               {\r
+                                       // 書き込みと列挙\r
+                                       batch[0].InputData = b;\r
+                                       batch[0].Name = object_name;\r
+\r
+                                       if (SecureDeviceWindow(hWnd, batch, sizeof(batch) / sizeof(batch[0]), id, 0) == false)\r
+                                       {\r
+                                               // 失敗\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               ok = true;\r
+                                       }\r
+\r
+                                       Free(object_name);\r
+                               }\r
+                       }\r
+\r
+                       FreeBuf(b);\r
+               }\r
+\r
+               Free(filename);\r
+               break;\r
+\r
+       case SEC_X:\r
+               // 証明書読み込み\r
+               if (CmLoadXExW(hWnd, &x, tmp2, sizeof(tmp2)))\r
+               {\r
+                       // デフォルトの名前を生成する\r
+                       char default_name[MAX_SIZE];\r
+                       wchar_t default_name_w[MAX_PATH];\r
+                       char *object_name;\r
+                       GetFileNameFromFilePathW(default_name_w, sizeof(default_name_w), tmp2);\r
+                       UniToStr(default_name, sizeof(default_name), default_name_w);\r
+                       ConvertSafeFileName(default_name, sizeof(default_name), default_name);\r
+\r
+                       object_name = StringDlgA(hWnd, _UU("SEC_OBJECT_NAME_TITLE"),\r
+                               _UU("SEC_OBJECT_NAME_INFO"), default_name, ICO_CERT, false, false);\r
+\r
+                       if (object_name != NULL)\r
+                       {\r
+                               // 書き込みと列挙\r
+                               batch[0].Type = WINUI_SECURE_WRITE_CERT;\r
+                               batch[0].InputX = x;\r
+                               batch[0].Name = object_name;\r
+\r
+                               if (SecureDeviceWindow(hWnd, batch, sizeof(batch) / sizeof(batch[0]), id, 0) == false)\r
+                               {\r
+                                       // 失敗\r
+                               }\r
+                               else\r
+                               {\r
+                                       ok = true;\r
+                               }\r
+\r
+                               Free(object_name);\r
+                       }\r
+\r
+                       FreeX(x);\r
+               }\r
+\r
+               break;\r
+\r
+       case SEC_K:\r
+               // 秘密鍵\r
+               if (CmLoadKExW(hWnd, &k, tmp2, sizeof(tmp2)))\r
+               {\r
+                       // デフォルトの名前を生成する\r
+                       char default_name[MAX_SIZE];\r
+                       wchar_t default_name_w[MAX_PATH];\r
+                       char *object_name;\r
+                       GetFileNameFromFilePathW(default_name_w, sizeof(default_name_w), tmp2);\r
+                       UniToStr(default_name, sizeof(default_name), default_name_w);\r
+                       ConvertSafeFileName(default_name, sizeof(default_name), default_name);\r
+\r
+                       object_name = StringDlgA(hWnd, _UU("SEC_OBJECT_NAME_TITLE"),\r
+                               _UU("SEC_OBJECT_NAME_INFO"), default_name, ICO_KEY, false, false);\r
+\r
+                       if (object_name != NULL)\r
+                       {\r
+                               // 書き込みと列挙\r
+                               batch[0].Type = WINUI_SECURE_WRITE_KEY;\r
+                               batch[0].InputK = k;\r
+                               batch[0].Name = object_name;\r
+\r
+                               if (SecureDeviceWindow(hWnd, batch, sizeof(batch) / sizeof(batch[0]), id, 0) == false)\r
+                               {\r
+                                       // 失敗\r
+                               }\r
+                               else\r
+                               {\r
+                                       ok = true;\r
+                               }\r
+\r
+                               Free(object_name);\r
+                       }\r
+\r
+                       FreeK(k);\r
+               }\r
+               break;\r
+\r
+       default:\r
+               // 無効\r
+               return;\r
+       }\r
+\r
+       if (ok)\r
+       {\r
+               LIST *o = batch[1].EnumList;\r
+\r
+               CmSecureManagerDlgPrintList(hWnd, o);\r
+\r
+               FreeEnumSecObject(o);\r
+\r
+               MsgBox(hWnd, MB_ICONINFORMATION, _UU("SEC_OBJECT_IMPORT_OK"));\r
+       }\r
+}\r
+\r
+// オブジェクトのエクスポート\r
+void CmSecureManagerDlgExport(HWND hWnd, UINT id)\r
+{\r
+       char name[MAX_SIZE];\r
+       UINT method = WINUI_SECURE_READ_DATA;\r
+       char *tmp;\r
+       UINT type;\r
+       wchar_t filename[MAX_PATH];\r
+       wchar_t *uni_tmp;\r
+       X *x;\r
+       BUF *b;\r
+       wchar_t default_name[128];\r
+       WINUI_SECURE_BATCH batch[] =\r
+       {\r
+               {WINUI_SECURE_READ_DATA, name, true, NULL, NULL, NULL, NULL, NULL, NULL},\r
+       };\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       i = LvGetSelected(hWnd, L_LIST);\r
+       if (i == INFINITE)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tmp = LvGetStrA(hWnd, L_LIST, i, 0);\r
+       StrCpy(name, sizeof(name), tmp);\r
+       Free(tmp);\r
+\r
+       type = (UINT)LvGetParam(hWnd, L_LIST, i);\r
+\r
+       switch (type)\r
+       {\r
+       case SEC_X:\r
+               method = WINUI_SECURE_READ_CERT;\r
+               break;\r
+\r
+       default:\r
+               method = WINUI_SECURE_READ_DATA;\r
+               break;\r
+       }\r
+\r
+       batch[0].Type = method;\r
+\r
+       // スマートカードの操作を行う\r
+       if (SecureDeviceWindow(hWnd, batch, sizeof(batch) / sizeof(batch[0]), id, 0) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       switch (type)\r
+       {\r
+       case SEC_X:\r
+               // 証明書\r
+               x = batch[0].OutputX;\r
+\r
+               CertDlg(hWnd, x, NULL, true);\r
+\r
+               FreeX(x);\r
+               break;\r
+\r
+       default:\r
+               // ファイル\r
+               b = batch[0].OutputData;\r
+               StrToUni(default_name, sizeof(default_name), name);\r
+               uni_tmp = SaveDlg(hWnd, _UU("DLG_ALL_FILES"), _UU("DLG_SAVE_FILE"), default_name, NULL);\r
+\r
+               if (uni_tmp != NULL)\r
+               {\r
+                       UniStrCpy(filename, sizeof(filename), uni_tmp);\r
+\r
+                       DumpBufW(b, filename);\r
+\r
+                       Free(uni_tmp);\r
+\r
+                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("SEC_OBJECT_EXPORT_OK"));\r
+               }\r
+\r
+\r
+               FreeBuf(b);\r
+               break;\r
+       }\r
+}\r
+\r
+// オブジェクトの削除\r
+void CmSecureManagerDlgDelete(HWND hWnd, UINT id)\r
+{\r
+       char name[MAX_SIZE];\r
+       UINT method = WINUI_SECURE_DELETE_DATA;\r
+       char *tmp;\r
+       UINT type;\r
+       LIST *o;\r
+       WINUI_SECURE_BATCH batch[] =\r
+       {\r
+               {WINUI_SECURE_DELETE_OBJECT, name, false, NULL, NULL, NULL, NULL, NULL, NULL},\r
+               {WINUI_SECURE_ENUM_OBJECTS, NULL, false, NULL, NULL, NULL, NULL, NULL, NULL},\r
+       };\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       i = LvGetSelected(hWnd, L_LIST);\r
+       if (i == INFINITE)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tmp = LvGetStrA(hWnd, L_LIST, i, 0);\r
+       StrCpy(name, sizeof(name), tmp);\r
+       Free(tmp);\r
+\r
+       type = (UINT)LvGetParam(hWnd, L_LIST, i);\r
+\r
+       switch (type)\r
+       {\r
+       case SEC_X:\r
+               method = WINUI_SECURE_DELETE_CERT;\r
+               break;\r
+\r
+       case SEC_K:\r
+               method = WINUI_SECURE_DELETE_KEY;\r
+               break;\r
+\r
+       default:\r
+               method = WINUI_SECURE_DELETE_DATA;\r
+               break;\r
+       }\r
+\r
+       batch[0].Type = method;\r
+\r
+       if (SecureDeviceWindow(hWnd, batch, sizeof(batch) / sizeof(batch[0]), id, 0) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o = batch[1].EnumList;\r
+\r
+       CmSecureManagerDlgPrintList(hWnd, o);\r
+\r
+       FreeEnumSecObject(o);\r
+}\r
+\r
+static bool cm_secure_manager_no_new_cert = false;\r
+\r
+// スマートカードマネージャダイアログ\r
+UINT CmSecureManagerDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       NMHDR *n;\r
+       UINT id = (UINT)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               CmSecureManagerDlgInit(hWnd, id);\r
+\r
+               if (cm_secure_manager_no_new_cert)\r
+               {\r
+                       Hide(hWnd, B_NEW_CERT);\r
+               }\r
+\r
+               SetTimer(hWnd, 1, 1, NULL);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_REFRESH:\r
+                       CmSecureManagerDlgRefresh(hWnd, id);\r
+                       break;\r
+\r
+               case B_IMPORT:\r
+                       CmSecureManagerDlgImport(hWnd, id);\r
+                       break;\r
+\r
+               case B_EXPORT:\r
+                       CmSecureManagerDlgExport(hWnd, id);\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       if (MsgBox(hWnd, MB_YESNO | MB_ICONEXCLAMATION | MB_DEFBUTTON2,\r
+                               _UU("SEC_DELETE_MSG")) == IDYES)\r
+                       {\r
+                               CmSecureManagerDlgDelete(hWnd, id);\r
+                       }\r
+                       break;\r
+\r
+               case B_NEW_CERT:\r
+                       CmSecureManagerDlgNewCert(hWnd, id);\r
+                       break;\r
+\r
+               case B_PIN:\r
+                       CmSecurePin(hWnd, id);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+\r
+                       CmSecureManagerDlgRefresh(hWnd, id);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_LIST:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               CmSecureManagerDlgUpdate(hWnd, id);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// スマートカードマネージャ\r
+void CmSecureManager(HWND hWnd, UINT id)\r
+{\r
+       CmSecureManagerEx(hWnd, id, false);\r
+}\r
+void CmSecureManagerEx(HWND hWnd, UINT id, bool no_new_cert)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ID チェック\r
+       if (CheckSecureDeviceId(id) == false)\r
+       {\r
+               MsgBox(hWnd, MB_ICONEXCLAMATION, _UU("SEC_INVALID_ID"));\r
+               return;\r
+       }\r
+\r
+       if (no_new_cert)\r
+       {\r
+               cm_secure_manager_no_new_cert = true;\r
+       }\r
+       else\r
+       {\r
+               cm_secure_manager_no_new_cert = false;\r
+       }\r
+\r
+       Dialog(hWnd, D_CM_SECURE_MANAGER, CmSecureManagerDlg, (void *)id);\r
+}\r
+\r
+// クライアント用スマートカードマネージャ\r
+void CmClientSecureManager(HWND hWnd)\r
+{\r
+       RPC_USE_SECURE t;\r
+       UINT id;\r
+\r
+       Zero(&t, sizeof(t));\r
+       CcGetUseSecure(cm->Client, &t);\r
+\r
+       id = t.DeviceId;\r
+\r
+       if (id == 0 || CheckSecureDeviceId(id) == false)\r
+       {\r
+               id = CmClientSelectSecure(hWnd);\r
+       }\r
+\r
+       if (id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CmSecureManager(hWnd, id);\r
+}\r
+\r
+// ダイアログの初期化\r
+void CmSelectSecureDlgInit(HWND hWnd, UINT default_id)\r
+{\r
+       UINT i;\r
+       LIST *o;\r
+       LVB *v;\r
+\r
+       SetIcon(hWnd, 0, ICO_SECURE);\r
+\r
+       o = GetSecureDeviceList();\r
+\r
+       LvInit(hWnd, L_LIST);\r
+       LvInsertColumn(hWnd, L_LIST, 0, _UU("SEC_COLUMN1"), 150);\r
+       LvInsertColumn(hWnd, L_LIST, 1, _UU("SEC_COLUMN2"), 100);\r
+       LvInsertColumn(hWnd, L_LIST, 2, _UU("SEC_COLUMN3"), 130);\r
+       LvInsertColumn(hWnd, L_LIST, 3, _UU("SEC_COLUMN4"), 100);\r
+\r
+       v = LvInsertStart();\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t *tmp2;\r
+               wchar_t tmp3[MAX_SIZE];\r
+               wchar_t tmp4[MAX_SIZE];\r
+               SECURE_DEVICE *dev = LIST_DATA(o, i);\r
+\r
+               StrToUni(tmp1, sizeof(tmp1), dev->DeviceName);\r
+               tmp2 = (dev->Type == SECURE_IC_CARD) ? _UU("SEC_SMART_CARD") : _UU("SEC_USB_TOKEN");\r
+               StrToUni(tmp3, sizeof(tmp3), dev->Manufacturer);\r
+               StrToUni(tmp4, sizeof(tmp4), dev->ModuleName);\r
+\r
+               LvInsertAdd(v, ICO_SECURE, (void *)dev->Id, 4, tmp1, tmp2, tmp3, tmp4);\r
+       }\r
+\r
+       LvInsertEnd(v, hWnd, L_LIST);\r
+\r
+       if (default_id != 0)\r
+       {\r
+               LvSelect(hWnd, L_LIST, LvSearchParam(hWnd, L_LIST, (void *)default_id));\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       // コントロール更新\r
+       CmSelectSecureDlgUpdate(hWnd);\r
+}\r
+\r
+// ダイアログのコントロール更新\r
+void CmSelectSecureDlgUpdate(HWND hWnd)\r
+{\r
+       SetEnable(hWnd, IDOK, LvIsSingleSelected(hWnd, L_LIST));\r
+}\r
+\r
+// スマートカード選択ダイアログ\r
+UINT CmSelectSecureDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       UINT default_id = (UINT)param;\r
+       NMHDR *n = NULL;\r
+       static UINT old_id;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               old_id = default_id;\r
+               CmSelectSecureDlgInit(hWnd, default_id);\r
+\r
+               if (LvNum(hWnd, L_LIST) == 0)\r
+               {\r
+                       // 1 つもスマートカードが無い\r
+                       SetTimer(hWnd, 1, 100, NULL);\r
+               }\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+\r
+                       Disable(hWnd, L_LIST);\r
+                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("SEC_NO_SECURE_DEVICE"));\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       if (IsEnable(hWnd, IDOK))\r
+                       {\r
+                               UINT i = LvGetSelected(hWnd, L_LIST);\r
+                               if (i != INFINITE)\r
+                               {\r
+                                       UINT id = (UINT)LvGetParam(hWnd, L_LIST, i);\r
+\r
+                                       if (old_id != id)\r
+                                       {\r
+                                               if (CmCheckPkcsEula(hWnd, id) == false)\r
+                                               {\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                                       EndDialog(hWnd, id);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_LIST:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               CmSelectSecureDlgUpdate(hWnd);\r
+                               break;\r
+                       case NM_DBLCLK:\r
+                               Command(hWnd, IDOK);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 使用するスマートカードデバイスの選択\r
+UINT CmSelectSecure(HWND hWnd, UINT current_id)\r
+{\r
+       return Dialog(hWnd, D_CM_SELECT_SECURE, CmSelectSecureDlg, (void *)current_id);\r
+}\r
+\r
+// 使用するスマートカードデバイスの選択 (クライアント)\r
+UINT CmClientSelectSecure(HWND hWnd)\r
+{\r
+       UINT id;\r
+       RPC_USE_SECURE t;\r
+\r
+       if (cm->server_name != NULL)\r
+       {\r
+               MsgBox(hWnd, MB_ICONEXCLAMATION, _UU("CM_SECURE_MUST_LOCAL"));\r
+               return 0;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       CcGetUseSecure(cm->Client, &t);\r
+\r
+       id = t.DeviceId;\r
+\r
+       id = CmSelectSecure(hWnd, id);\r
+       if (id != 0)\r
+       {\r
+               Zero(&t, sizeof(t));\r
+               t.DeviceId = id;\r
+\r
+               CALL(hWnd, CcUseSecure(cm->Client, &t));\r
+\r
+               SmWriteSelectSecureIdReg(id);\r
+       }\r
+\r
+       return id;\r
+}\r
+\r
+// ショートカット接続\r
+void CmConnectShortcut(UCHAR *key)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (key == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 接続を試行する\r
+       ret = CcShortcut(key);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               if (ret == ERR_ACCOUNT_ACTIVE)\r
+               {\r
+                       // 現在接続中なので、切断するかどうか問い合わせる\r
+                       if (MsgBox(NULL, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("CM_SHORTCUT_DISCONNECT")) == IDYES)\r
+                       {\r
+                               // 切断してみる\r
+                               ret = CcShortcutDisconnect(key);\r
+\r
+                               if (ret != ERR_NO_ERROR)\r
+                               {\r
+                                       // エラー\r
+                                       MsgBox(NULL, MB_ICONEXCLAMATION, GetUniErrorStr(ret));\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // その他のエラー\r
+                       MsgBox(NULL, MB_ICONEXCLAMATION, GetUniErrorStr(ret));\r
+               }\r
+       }\r
+}\r
+\r
+// 音声ガイドを再生する\r
+void CmVoice(char *name)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (cm->DisableVoice)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < sizeof(cm_voice) / sizeof(CM_VOICE);i++)\r
+       {\r
+               if (cm_voice[i].voice_id == cm->VoiceId)\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+                       Format(tmp, sizeof(tmp), "%s_%s.wav", cm_voice[i].perfix, name);\r
+                       MsPlaySound(tmp);\r
+                       return;\r
+               }\r
+       }\r
+}\r
+\r
+// パスワード変更画面更新\r
+void CmChangePasswordUpdate(HWND hWnd, CM_CHANGE_PASSWORD *p)\r
+{\r
+       bool ok = true;\r
+       char *s1, *s2;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsEmpty(hWnd, E_USERNAME))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       s1 = GetTextA(hWnd, E_NEW_PASSWORD1);\r
+       s2 = GetTextA(hWnd, E_NEW_PASSWORD2);\r
+\r
+       if (StrCmp(s1, s2) != 0)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       Free(s1);\r
+       Free(s2);\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// パスワード変更ダイアログプロシージャ\r
+UINT CmChangePasswordProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       CM_CHANGE_PASSWORD *p = (CM_CHANGE_PASSWORD *)param;\r
+       char username[MAX_USERNAME_LEN + 1];\r
+       char old_pass[MAX_PASSWORD_LEN + 1];\r
+       char new_pass[MAX_PASSWORD_LEN + 1];\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetTextA(hWnd, E_HUBNAME, p->HubName);\r
+               SetTextA(hWnd, E_USERNAME, p->Username);\r
+               FormatText(hWnd, S_TITLE, p->ClientOption->Hostname);\r
+\r
+               if (IsEmpty(hWnd, E_USERNAME))\r
+               {\r
+                       FocusEx(hWnd, E_USERNAME);\r
+               }\r
+               else\r
+               {\r
+                       FocusEx(hWnd, E_OLD_PASSWORD);\r
+               }\r
+\r
+               CmChangePasswordUpdate(hWnd, p);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_USERNAME:\r
+               case E_OLD_PASSWORD:\r
+               case E_NEW_PASSWORD1:\r
+               case E_NEW_PASSWORD2:\r
+                       CmChangePasswordUpdate(hWnd, p);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       GetTxtA(hWnd, E_USERNAME, username, sizeof(username));\r
+                       GetTxtA(hWnd, E_OLD_PASSWORD, old_pass, sizeof(old_pass));\r
+                       GetTxtA(hWnd, E_NEW_PASSWORD1, new_pass, sizeof(new_pass));\r
+\r
+                       Disable(hWnd, E_USERNAME);\r
+                       Disable(hWnd, E_OLD_PASSWORD);\r
+                       Disable(hWnd, E_NEW_PASSWORD1);\r
+                       Disable(hWnd, E_NEW_PASSWORD2);\r
+                       Disable(hWnd, IDOK);\r
+                       Disable(hWnd, IDCANCEL);\r
+\r
+                       ret = ChangePassword(cm->Cedar, p->ClientOption, p->HubName, username, old_pass, new_pass);\r
+\r
+                       if (ret == ERR_NO_ERROR)\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_PASSWORD_CHANGED"));\r
+                               EndDialog(hWnd, true);\r
+                       }\r
+                       else\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONSTOP, _E(ret));\r
+                               Enable(hWnd, E_USERNAME);\r
+                               Enable(hWnd, E_OLD_PASSWORD);\r
+                               Enable(hWnd, E_NEW_PASSWORD1);\r
+                               Enable(hWnd, E_NEW_PASSWORD2);\r
+                               Enable(hWnd, IDOK);\r
+                               Enable(hWnd, IDCANCEL);\r
+\r
+                               SetTextA(hWnd, E_OLD_PASSWORD, "");\r
+                               SetTextA(hWnd, E_NEW_PASSWORD1, "");\r
+                               SetTextA(hWnd, E_NEW_PASSWORD2, "");\r
+\r
+                               Focus(hWnd, E_OLD_PASSWORD);\r
+                       }\r
+\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               }\r
+\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// パスワード変更ダイアログ表示\r
+void CmChangePassword(HWND hWnd, CLIENT_OPTION *o, char *hubname, char *username)\r
+{\r
+       CM_CHANGE_PASSWORD p;\r
+       // 引数チェック\r
+       if (hWnd == NULL || o == NULL || hubname == NULL || username == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       StrCpy(p.Username, sizeof(p.Username), username);\r
+       StrCpy(p.HubName, sizeof(p.HubName), hubname);\r
+       p.ClientOption = o;\r
+\r
+       CmVoice("password");\r
+\r
+       Dialog(hWnd, D_CM_CHANGE_PASSWORD, CmChangePasswordProc, &p);\r
+}\r
+\r
+// デスクトップ相違警告メッセージダイアログ初期化\r
+void CmDesktopDlgInit(HWND hWnd, wchar_t *account_name)\r
+{\r
+       wchar_t tmp[2048];\r
+       bool remote = false;\r
+       bool user_switching = false;\r
+       bool console_active = false;\r
+       wchar_t *console_user = NULL;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FormatText(hWnd, 0, account_name);\r
+       FormatText(hWnd, S_TITLE, account_name);\r
+       DlgFont(hWnd, S_TITLE, 11, true);\r
+       DlgFont(hWnd, S_INFO, 11, true);\r
+       if (cm->server_name == NULL)\r
+       {\r
+               UniStrCpy(tmp, sizeof(tmp), _UU("CM_DESKTOP_LOCAL_PC"));\r
+       }\r
+       else\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_DESKTOP_REMOTE_PC"), cm->server_name);\r
+       }\r
+       FormatText(hWnd, S_WARNING, tmp);\r
+\r
+       if (cm->server_name != NULL)\r
+       {\r
+               remote = true;\r
+       }\r
+       else\r
+       {\r
+               if (MsIsTerminalServiceInstalled())\r
+               {\r
+                       user_switching = false;\r
+               }\r
+               else\r
+               {\r
+                       user_switching = true;\r
+               }\r
+\r
+               console_user = MsGetSessionUserName(0);\r
+\r
+               if (console_user == NULL)\r
+               {\r
+                       console_active = false;\r
+               }\r
+               else\r
+               {\r
+                       console_active = true;\r
+               }\r
+       }\r
+\r
+       // MSG1\r
+       if (remote == false)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_DESKTOP_MSG_LOCAL_1"),\r
+                       user_switching ? _UU("CM_DESKTOP_MSG_LOCAL_SW") : _UU("CM_DESKTOP_MSG_LOCAL_TS"));\r
+       }\r
+       else\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_DESKTOP_MSG_REMOTE_1"),\r
+                       cm->server_name);\r
+       }\r
+       SetText(hWnd, S_MSG_1, tmp);\r
+\r
+       // MSG2\r
+       if (remote == false)\r
+       {\r
+               if (console_active)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_DESKTOP_MSG_LOCAL_21"),\r
+                               console_user, MsGetCurrentTerminalSessionId());\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_DESKTOP_MSG_LOCAL_22"),\r
+                               MsGetCurrentTerminalSessionId());\r
+               }\r
+       }\r
+       else\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_DESKTOP_MSG_REMOTE_2"), cm->server_name);\r
+       }\r
+       SetText(hWnd, S_MSG_2, tmp);\r
+\r
+       // MSG3\r
+       if (remote == false)\r
+       {\r
+               if (console_active)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_DESKTOP_MSG_LOCAL_31"),\r
+                               console_user, account_name);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_DESKTOP_MSG_LOCAL_32"),\r
+                               account_name);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_DESKTOP_MSG_REMOTE_3"), cm->server_name,\r
+                       account_name);\r
+       }\r
+       SetText(hWnd, S_MSG_3, tmp);\r
+\r
+       if (console_user != NULL)\r
+       {\r
+               Free(console_user);\r
+       }\r
+}\r
+\r
+// デスクトップ相違警告メッセージダイアログ\r
+UINT CmDesktopDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       wchar_t *account_name = (wchar_t *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               CmDesktopDlgInit(hWnd, account_name);\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 必要であればデスクトップが異なる旨の警告メッセージを表示する\r
+bool CmWarningDesktop(HWND hWnd, wchar_t *account_name)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || account_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (cm->Client->Unix)\r
+       {\r
+               //クライアントが UNIX の場合警告の必要は無い\r
+               return true;\r
+       }\r
+\r
+       if (/*MsIsTerminalServiceInstalled() || MsIsUserSwitchingInstalled() ||*/ (cm->server_name != NULL))\r
+       {\r
+               if (cm->server_name == NULL)\r
+               {\r
+                       //if (MsGetCurrentTerminalSessionId() == 0)\r
+                       {\r
+                               // 警告の必要は無い\r
+                               return true;\r
+                       }\r
+               }\r
+               // 警告の必要がある\r
+               return Dialog(hWnd, D_CM_DESKTOP, CmDesktopDlgProc, account_name);\r
+       }\r
+       else\r
+       {\r
+               // 警告の必要は無い\r
+               return true;\r
+       }\r
+}\r
+\r
+// パスワード設定ダイアログ更新\r
+void CmPasswordRefresh(HWND hWnd)\r
+{\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEnable(hWnd, E_PASSWORD, IsChecked(hWnd, R_USE_PASSWORD));\r
+       SetEnable(hWnd, E_PASSWORD2, IsChecked(hWnd, R_USE_PASSWORD));\r
+       SetEnable(hWnd, IDC_STATIC1, IsChecked(hWnd, R_USE_PASSWORD));\r
+       SetEnable(hWnd, IDC_STATIC2, IsChecked(hWnd, R_USE_PASSWORD));\r
+       SetEnable(hWnd, R_REMOTE_ONLY, IsChecked(hWnd, R_USE_PASSWORD));\r
+\r
+       if (IsChecked(hWnd, R_USE_PASSWORD))\r
+       {\r
+               char tmp1[MAX_SIZE];\r
+               char tmp2[MAX_SIZE];\r
+               if (IsEmpty(hWnd, E_PASSWORD))\r
+               {\r
+                       ok = false;\r
+               }\r
+               GetTxtA(hWnd, E_PASSWORD, tmp1, sizeof(tmp1));\r
+               GetTxtA(hWnd, E_PASSWORD2, tmp2, sizeof(tmp2));\r
+               if (StrCmp(tmp1, tmp2) != 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+               if (StrCmp(tmp1, HIDDEN_PASSWORD) == 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// パスワード設定プロシージャ\r
+UINT CmPasswordProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       RPC_CLIENT_PASSWORD_SETTING c;\r
+       RPC_CLIENT_PASSWORD p;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // パスワード設定の取得\r
+               if (CALL(hWnd, CcGetPasswordSetting(cm->Client, &c)))\r
+               {\r
+                       Check(hWnd, R_USE_PASSWORD, c.IsPasswordPresented);\r
+                       if (c.IsPasswordPresented)\r
+                       {\r
+                               SetTextA(hWnd, E_PASSWORD, HIDDEN_PASSWORD);\r
+                               SetTextA(hWnd, E_PASSWORD2, HIDDEN_PASSWORD);\r
+                               FocusEx(hWnd, E_PASSWORD);\r
+                               Check(hWnd, R_REMOTE_ONLY, c.PasswordRemoteOnly);\r
+                       }\r
+                       else\r
+                       {\r
+                               Focus(hWnd, R_USE_PASSWORD);\r
+                       }\r
+               }\r
+               CmPasswordRefresh(hWnd);\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case R_USE_PASSWORD:\r
+                       if (IsChecked(hWnd, R_USE_PASSWORD))\r
+                       {\r
+                               FocusEx(hWnd, E_PASSWORD);\r
+                       }\r
+                       break;\r
+               case IDOK:\r
+                       GetTxtA(hWnd, E_PASSWORD, tmp, sizeof(tmp));\r
+                       Zero(&p, sizeof(p));\r
+                       if (IsChecked(hWnd, R_USE_PASSWORD))\r
+                       {\r
+                               StrCpy(p.Password, sizeof(p.Password), tmp);\r
+                               p.PasswordRemoteOnly = IsChecked(hWnd, R_REMOTE_ONLY);\r
+                       }\r
+\r
+                       if (CALL(hWnd, CcSetPassword(cm->Client, &p)))\r
+                       {\r
+                               if (StrLen(p.Password) > 0)\r
+                               {\r
+                                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_PASSWORD_SET"));\r
+                               }\r
+                               else\r
+                               {\r
+                                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_PASSWORD_REMOVE"));\r
+                               }\r
+                               EndDialog(hWnd, true);\r
+                       }\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_USE_PASSWORD:\r
+               case R_REMOTE_ONLY:\r
+               case E_PASSWORD:\r
+               case E_PASSWORD2:\r
+                       CmPasswordRefresh(hWnd);\r
+                       break;\r
+               }\r
+               switch (wParam)\r
+               {\r
+               case R_REMOTE_ONLY:\r
+               case R_USE_PASSWORD:\r
+                       if (IsChecked(hWnd, R_USE_PASSWORD))\r
+                       {\r
+                               FocusEx(hWnd, E_PASSWORD);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// パスワード設定\r
+void CmPassword(HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_CM_PASSWORD, CmPasswordProc, NULL);\r
+}\r
+\r
+// CA ダイアログ更新\r
+void CmTrustDlgUpdate(HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEnable(hWnd, B_EXPORT, LvIsSelected(hWnd, L_CERT));\r
+       SetEnable(hWnd, B_DELETE, LvIsSelected(hWnd, L_CERT) && cm->CmSetting.LockMode == false);\r
+       SetEnable(hWnd, IDOK, LvIsSelected(hWnd, L_CERT));\r
+       SetEnable(hWnd, B_IMPORT, cm->CmSetting.LockMode == false);\r
+}\r
+\r
+// 証明書リストの更新\r
+void CmTrustDlgRefresh(HWND hWnd)\r
+{\r
+       RPC_CLIENT_ENUM_CA c;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (CALL(hWnd, CcEnumCa(cm->Client, &c)))\r
+       {\r
+               UINT i;\r
+               LVB *b = LvInsertStart();\r
+               for (i = 0;i < c.NumItem;i++)\r
+               {\r
+                       RPC_CLIENT_ENUM_CA_ITEM *cert = c.Items[i];\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       GetDateStrEx64(tmp, sizeof(tmp), SystemToLocal64(cert->Expires), NULL);\r
+                       LvInsertAdd(b, ICO_CERT, (void *)cert->Key, 3,\r
+                               cert->SubjectName, cert->IssuerName, tmp);\r
+               }\r
+               LvInsertEnd(b, hWnd, L_CERT);\r
+               CiFreeClientEnumCa(&c);\r
+       }\r
+\r
+       CmTrustDlgUpdate(hWnd);\r
+}\r
+\r
+// インポート\r
+void CmTrustImport(HWND hWnd)\r
+{\r
+       X *x;\r
+       RPC_CERT c;\r
+       if (CmLoadXFromFileOrSecureCard(hWnd, &x) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&c, sizeof(c));\r
+       c.x = x;\r
+\r
+       CALL(hWnd, CcAddCa(cm->Client, &c));\r
+       CmVoice("new_cert");\r
+\r
+       FreeX(c.x);\r
+       CmTrustDlgRefresh(hWnd);\r
+}\r
+\r
+// エクスポート\r
+void CmTrustExport(HWND hWnd)\r
+{\r
+       UINT key;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       key = (UINT)LvGetParam(hWnd, L_CERT, LvGetSelected(hWnd, L_CERT));\r
+       if (key != INFINITE)\r
+       {\r
+               RPC_GET_CA a;\r
+               Zero(&a, sizeof(a));\r
+               a.Key = key;\r
+\r
+               if (CALL(hWnd, CcGetCa(cm->Client, &a)))\r
+               {\r
+                       wchar_t *name;\r
+                       X *x = CloneX(a.x);\r
+                       CiFreeGetCa(&a);\r
+\r
+                       // 保存\r
+                       name = SaveDlg(hWnd, _UU("DLG_CERT_FILES"), _UU("DLG_SAVE_CERT"), NULL, L".cer");\r
+                       if (name != NULL)\r
+                       {\r
+                               wchar_t str[MAX_SIZE];\r
+                               UniStrCpy(str, sizeof(str), name);\r
+                               if (XToFileW(x, str, true))\r
+                               {\r
+                                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("DLG_CERT_SAVE_OK"));\r
+                               }\r
+                               else\r
+                               {\r
+                                       MsgBox(hWnd, MB_ICONSTOP, _UU("DLG_CERT_SAVE_ERROR"));\r
+                               }\r
+                               Free(name);\r
+                       }\r
+                       FreeX(x);\r
+               }\r
+       }\r
+}\r
+\r
+// 表示\r
+void CmTrustView(HWND hWnd)\r
+{\r
+       UINT key;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       key = (UINT)LvGetParam(hWnd, L_CERT, LvGetSelected(hWnd, L_CERT));\r
+       if (key != INFINITE)\r
+       {\r
+               RPC_GET_CA a;\r
+               Zero(&a, sizeof(a));\r
+               a.Key = key;\r
+\r
+               if (CALL(hWnd, CcGetCa(cm->Client, &a)))\r
+               {\r
+                       X *x = CloneX(a.x);\r
+                       X *x_issuer;\r
+                       CiFreeGetCa(&a);\r
+\r
+                       x_issuer = CmGetIssuer(x);\r
+                       CertDlg(hWnd, x, x_issuer, true);\r
+                       FreeX(x);\r
+                       FreeX(x_issuer);\r
+               }\r
+       }\r
+}\r
+\r
+// CA ダイアログプロシージャ\r
+UINT CmTrustDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       NMHDR *n;\r
+       UINT index;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               LvInit(hWnd, L_CERT);\r
+               LvInsertColumn(hWnd, L_CERT, 0, _UU("CM_CERT_COLUMN_1"), 190);\r
+               LvInsertColumn(hWnd, L_CERT, 1, _UU("CM_CERT_COLUMN_2"), 190);\r
+               LvInsertColumn(hWnd, L_CERT, 2, _UU("CM_CERT_COLUMN_3"), 160);\r
+               CmTrustDlgRefresh(hWnd);\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_IMPORT:\r
+                       CmTrustImport(hWnd);\r
+                       break;\r
+               case B_EXPORT:\r
+                       CmTrustExport(hWnd);\r
+                       break;\r
+               case B_DELETE:\r
+                       index = LvGetSelected(hWnd, L_CERT);\r
+                       if (index != INFINITE)\r
+                       {\r
+                               UINT key = (UINT)LvGetParam(hWnd, L_CERT, index);\r
+                               if (key != INFINITE)\r
+                               {\r
+                                       if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("CM_CERT_DELETE_MSG")) == IDYES)\r
+                                       {\r
+                                               RPC_CLIENT_DELETE_CA c;\r
+                                               Zero(&c, sizeof(c));\r
+                                               c.Key = key;\r
+                                               if (CALL(hWnd, CcDeleteCa(cm->Client, &c)))\r
+                                               {\r
+                                                       CmTrustDlgRefresh(hWnd);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+               case IDOK:\r
+                       if (IsEnable(hWnd, IDOK))\r
+                       {\r
+                               CmTrustView(hWnd);\r
+                       }\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_CERT:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               CmTrustDlgUpdate(hWnd);\r
+                               break;\r
+                       case NM_DBLCLK:\r
+                               Command(hWnd, IDOK);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       LvSortHander(hWnd, msg, wParam, lParam, L_CERT);\r
+\r
+       return 0;\r
+}\r
+\r
+// CA ダイアログの表示\r
+void CmTrustDlg(HWND hWnd)\r
+{\r
+       Dialog(hWnd, D_CM_TRUST, CmTrustDlgProc, NULL);\r
+}\r
+\r
+// メインウインドウプロシージャ\r
+UINT CmMainWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       NMHDR *n;\r
+       static UINT taskbar_msg = 0;\r
+       COPYDATASTRUCT *cpy;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (taskbar_msg != 0 && msg == taskbar_msg)\r
+       {\r
+               // タスクバーが再生成された\r
+               if (cm->TrayInited)\r
+               {\r
+                       MsRestoreIconOnTray();\r
+               }\r
+       }\r
+\r
+       // CmSetForegroundProcessToCnService();\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_CM_SETTING_CHANGED_MESSAGE:\r
+               // CM_SETTING が変更された\r
+               CmApplyCmSetting();\r
+               break;\r
+       case WM_INITDIALOG:\r
+               CmMainWindowOnInit(hWnd);\r
+               taskbar_msg = RegisterWindowMessage("TaskbarCreated");\r
+               CmEndStartupMutex();\r
+               break;\r
+       case WM_SHOWWINDOW:\r
+LABEL_SPLASH:\r
+               if (cm->SplashHasBeenShown == false)\r
+               {\r
+                       if ((msg == WM_SHOWWINDOW && wParam) || (msg != WM_SHOWWINDOW && IsShow(hWnd, 0)))\r
+                       {\r
+                               if (IsIconic(hWnd) == false)\r
+                               {\r
+                                       SetTimer(hWnd, 5, 100, NULL);\r
+                               }\r
+                       }\r
+               }\r
+               break;\r
+       case WM_CM_SHOW:\r
+               // 別のプロセスから表示要求を受けた\r
+               if (cm->CmSetting.EasyMode == false)\r
+               {\r
+                       ShowWindow(hWnd, SW_SHOWNORMAL);\r
+               }\r
+               else\r
+               {\r
+                       if (cm->hEasyWnd == NULL)\r
+                       {\r
+                               CmShowEasy();\r
+                       }\r
+                       else\r
+                       {\r
+                               SetForegroundWindow(cm->hEasyWnd);\r
+                               SetActiveWindow(cm->hEasyWnd);\r
+                       }\r
+               }\r
+               break;\r
+       case WM_COMMAND:\r
+               CmMainWindowOnCommand(hWnd, wParam, lParam);\r
+               break;\r
+       case WM_SIZE:\r
+               CmMainWindowOnSize(hWnd);\r
+               goto LABEL_SPLASH;\r
+       case WM_CLOSE:\r
+               if (cm->CmSetting.EasyMode == false)\r
+               {\r
+                       CmShowOrHideWindow(hWnd);\r
+               }\r
+               else\r
+               {\r
+                       if (cm->hEasyWnd == NULL)\r
+                       {\r
+                               CmShowEasy();\r
+                       }\r
+                       else\r
+                       {\r
+                               SetForegroundWindow(cm->hEasyWnd);\r
+                               SetActiveWindow(cm->hEasyWnd);\r
+                       }\r
+               }\r
+               return 1;\r
+       case WM_INITMENUPOPUP:\r
+               if (HIWORD(lParam) == false)\r
+               {\r
+                       CmMainWindowOnPopupMenu(hWnd, (HMENU)wParam, LOWORD(lParam));\r
+               }\r
+               break;\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               if (n->idFrom == L_ACCOUNT && (n->code == LVN_BEGINLABELEDITW || n->code == LVN_BEGINLABELEDITA))\r
+               {\r
+                       wchar_t *tmp = LvGetSelectedStr(hWnd, L_ACCOUNT, 0);\r
+                       if (tmp != NULL)\r
+                       {\r
+                               if (UniStrCmpi(tmp, _UU("CM_NEW_ICON")) == 0 ||\r
+                                       UniStrCmpi(tmp, _UU("CM_ASP")) == 0)\r
+                               {\r
+                                       SendMsg(hWnd, L_ACCOUNT, LVM_CANCELEDITLABEL, 0, 0);\r
+                                       Free(tmp);\r
+                                       return true;\r
+                               }\r
+                               Free(tmp);\r
+                       }\r
+               }\r
+               CmMainWindowOnNotify(hWnd, (NMHDR *)lParam);\r
+               break;\r
+       case WM_CM_NOTIFY:\r
+               CmRefreshVLanList(hWnd);\r
+               CmRefreshAccountList(hWnd);\r
+               CmRefreshStatusBar(hWnd);\r
+               break;\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       CmSetForegroundProcessToCnService();\r
+                       break;\r
+               case 2:\r
+                       CmPollingTray(hWnd);\r
+                       break;\r
+               case 3:\r
+                       KillTimer(hWnd, 3);\r
+                       Hide(hWnd, 0);\r
+                       break;\r
+               case 4:\r
+                       KillTimer(hWnd, 4);\r
+                       CmMainWindowOnShowEasy(hWnd);\r
+                       break;\r
+               case 5:\r
+                       KillTimer(hWnd, 5);\r
+                       if (cm->SplashHasBeenShown == false)\r
+                       {\r
+                               cm->SplashHasBeenShown = true;\r
+\r
+                               ShowSplashEx(hWnd, "UT-VPN Client", 1300, CM_SPLASH_BORDER_COLOR);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CM_TRAY_MESSAGE:\r
+               // タスクトレイのアイコンからのメッセージ\r
+               CmMainWindowOnTrayClicked(hWnd, wParam, lParam);\r
+               break;\r
+       case WM_COPYDATA:\r
+               cpy = (COPYDATASTRUCT *)lParam;\r
+               if (cpy != NULL)\r
+               {\r
+                       if (cpy->dwData == CM_IMPORT_FILENAME_MSG || cpy->dwData == CM_IMPORT_FILENAME_MSG_OVERWRITE)\r
+                       {\r
+                               char *filename = (char *)cpy->lpData;\r
+\r
+                               if (cm->CmSetting.LockMode == false || cpy->dwData == CM_IMPORT_FILENAME_MSG_OVERWRITE)\r
+                               {\r
+                                       wchar_t fullpath[MAX_PATH];\r
+\r
+                                       if (StrLen(filename) >= 2 && IsFileExists(filename))\r
+                                       {\r
+                                               StrToUni(fullpath, sizeof(fullpath), filename);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               UniStrCpy(fullpath, sizeof(fullpath), (wchar_t *)filename);\r
+                                       }\r
+\r
+                                       CmImportAccountMainEx(cm->hEasyWnd ? cm->hEasyWnd : hWnd, fullpath, cpy->dwData == CM_IMPORT_FILENAME_MSG_OVERWRITE);\r
+                               }\r
+                               else\r
+                               {\r
+                                       MsgBox(cm->hEasyWnd ? cm->hEasyWnd : hWnd, MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST, _UU("CM_VPN_FILE_IMPORT_NG"));\r
+                               }\r
+                       }\r
+               }\r
+               break;\r
+       case WM_QUERYENDSESSION:\r
+               // Windows が終了しようとしている\r
+               cm->WindowsShutdowning = true;\r
+               CmSaveMainWindowPos(hWnd);\r
+               SleepThread(256);\r
+               break;\r
+       case WM_ENDSESSION:\r
+               // Windows が終了した\r
+               _exit(0);\r
+               break;\r
+       }\r
+\r
+       LvSortHander(hWnd, msg, wParam, lParam, L_ACCOUNT);\r
+       LvSortHander(hWnd, msg, wParam, lParam, L_VLAN);\r
+\r
+       return 0;\r
+}\r
+\r
+// 通知サービスをフォアグラウンドプロセスに指定する\r
+void CmSetForegroundProcessToCnService()\r
+{\r
+       if (cm->MenuPopuping)\r
+       {\r
+               return;\r
+       }\r
+       if (cm->server_name == NULL)\r
+       {\r
+               if (CnCheckAlreadyExists(false))\r
+               {\r
+                       AllowFGWindow(MsRegReadInt(REG_CURRENT_USER,\r
+                               CM_REG_KEY, "NotifyServerProcessId"));\r
+               }\r
+       }\r
+}\r
+\r
+// [最近の接続先] のサブメニューを表示する\r
+HMENU CmCreateRecentSubMenu(HWND hWnd, UINT start_id)\r
+{\r
+       HMENU h = NULL;\r
+       UINT i;\r
+       RPC_CLIENT_ENUM_ACCOUNT a;\r
+       LIST *o;\r
+       bool easy;\r
+\r
+       easy = cm->CmSetting.EasyMode;\r
+\r
+       Zero(&a, sizeof(a));\r
+\r
+       if (CcEnumAccount(cm->Client, &a) == ERR_NO_ERROR)\r
+       {\r
+               o = NewListFast(CiCompareClientAccountEnumItemByLastConnectDateTime);\r
+\r
+               for (i = 0;i < a.NumItem;i++)\r
+               {\r
+                       RPC_CLIENT_ENUM_ACCOUNT_ITEM *item = a.Items[i];\r
+\r
+                       item->tmp1 = i;\r
+\r
+                       if (item->LastConnectDateTime != 0)\r
+                       {\r
+                               Add(o, item);\r
+                       }\r
+               }\r
+\r
+               Sort(o);\r
+\r
+               for (i = 0;i < MIN(LIST_NUM(o), CM_NUM_RECENT);i++)\r
+               {\r
+                       RPC_CLIENT_ENUM_ACCOUNT_ITEM *item = (RPC_CLIENT_ENUM_ACCOUNT_ITEM *)LIST_DATA(o, i);\r
+                       wchar_t tmp[MAX_PATH];\r
+                       wchar_t *account_name;\r
+                       char *server_name;\r
+                       char *hub_name;\r
+                       UINT pos;\r
+\r
+                       if (h == NULL)\r
+                       {\r
+                               h = CreatePopupMenu();\r
+                       }\r
+\r
+                       account_name = item->AccountName;\r
+                       server_name = item->ServerName;\r
+                       hub_name = item->HubName;\r
+\r
+                       UniStrCpy(tmp, sizeof(tmp), account_name);\r
+\r
+                       pos = LvSearchStr(hWnd, L_ACCOUNT, 0, account_name);\r
+                       if (pos != INFINITE)\r
+                       {\r
+                               MsAppendMenu(h, MF_STRING, start_id + pos, tmp);\r
+                       }\r
+               }\r
+\r
+               ReleaseList(o);\r
+\r
+               CiFreeClientEnumAccount(&a);\r
+       }\r
+\r
+       return h;\r
+}\r
+\r
+// タスクトレイの右クリックメニューのサブメニューを表示する\r
+HMENU CmCreateTraySubMenu(HWND hWnd, bool flag, UINT start_id)\r
+{\r
+       HMENU h = NULL;\r
+       UINT i, num;\r
+       bool easy;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       easy = cm->CmSetting.EasyMode;\r
+\r
+       num = LvNum(hWnd, L_ACCOUNT);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               wchar_t *status_str = LvGetStr(hWnd, L_ACCOUNT, i, 1);\r
+\r
+               if (status_str != NULL)\r
+               {\r
+                       bool b = false;\r
+                       bool is_account = false;\r
+\r
+                       if (UniStrCmpi(status_str, _UU("CM_ACCOUNT_OFFLINE")) == 0)\r
+                       {\r
+                               if (flag == false)\r
+                               {\r
+                                       b = true;\r
+                               }\r
+\r
+                               is_account = true;\r
+                       }\r
+\r
+                       if (UniStrCmpi(status_str, _UU("CM_ACCOUNT_ONLINE")) == 0 ||\r
+                               UniStrCmpi(status_str, _UU("CM_ACCOUNT_CONNECTING")) == 0)\r
+                       {\r
+                               if (flag == true)\r
+                               {\r
+                                       b = true;\r
+                               }\r
+\r
+                               is_account = true;\r
+                       }\r
+\r
+                       if (b)\r
+                       {\r
+                               wchar_t tmp[MAX_PATH];\r
+                               wchar_t *account_name, *server_name;\r
+                               wchar_t *hub_name;\r
+                               if (h == NULL)\r
+                               {\r
+                                       h = CreatePopupMenu();\r
+                               }\r
+\r
+                               account_name = LvGetStr(hWnd, L_ACCOUNT, i, 0);\r
+                               server_name = LvGetStr(hWnd, L_ACCOUNT, i, 2);\r
+                               hub_name = LvGetStr(hWnd, L_ACCOUNT, i, 3);\r
+\r
+                               if (easy == false)\r
+                               {\r
+                                       UniFormat(tmp, sizeof(tmp), L"%s\t- %s [%s]", account_name, server_name, hub_name);\r
+                               }\r
+                               else\r
+                               {\r
+                                       UniStrCpy(tmp, sizeof(tmp), account_name);\r
+                               }\r
+\r
+                               MsAppendMenu(h, MF_STRING, start_id + i, tmp);\r
+\r
+                               Free(account_name);\r
+                               Free(server_name);\r
+                               Free(hub_name);\r
+                       }\r
+\r
+                       Free(status_str);\r
+               }\r
+       }\r
+\r
+       return h;\r
+}\r
+\r
+// タスクトレイの右クリックメニューを表示する\r
+void CmShowTrayMenu(HWND hWnd)\r
+{\r
+       HMENU h;\r
+       POINT p;\r
+       HMENU sub1, sub2, sub3, sub4;\r
+       bool locked;\r
+       bool easy;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       cm->MenuPopuping = true;\r
+\r
+       locked = cm->CmSetting.LockMode;\r
+       easy = cm->CmSetting.EasyMode;\r
+\r
+       // メニューを作成する\r
+       h = CreatePopupMenu();\r
+\r
+       // キャンセル\r
+       MsAppendMenu(h, MF_ENABLED | MF_STRING, 100007, _UU("CM_TRAY_MENU_CANCEL"));\r
+\r
+       // セパレータ\r
+       MsAppendMenu(h, MF_SEPARATOR, 10006, NULL);\r
+\r
+       if (locked == false && easy == false)\r
+       {\r
+               // 新しい接続設定の作成\r
+               MsAppendMenu(h, MF_ENABLED | MF_STRING, CMD_NEW, _UU("CM_TRAY_MENU_NEW"));\r
+\r
+               // セパレータ\r
+               MsAppendMenu(h, MF_SEPARATOR, 10005, NULL);\r
+       }\r
+\r
+       // 接続メニュー\r
+       sub1 = CmCreateTraySubMenu(hWnd, false, CM_TRAY_MENU_CONNECT_ID_START);\r
+       if (sub1 != NULL)\r
+       {\r
+               MsAppendMenu(h, MF_BYPOSITION | MF_ENABLED | MF_POPUP | MF_STRING,\r
+                       (UINT_PTR)sub1, _UU("CM_TRAY_MENU_CONNECT"));\r
+       }\r
+\r
+       // 切断メニュー\r
+       sub2 = CmCreateTraySubMenu(hWnd, true, CM_TRAY_MENU_DISCONNECT_ID_START);\r
+       if (sub2 != NULL)\r
+       {\r
+               MsAppendMenu(h, MF_BYPOSITION | MF_ENABLED | MF_POPUP | MF_STRING,\r
+                       (UINT_PTR)sub2, _UU("CM_TRAY_MENU_DISCONNECT"));\r
+       }\r
+\r
+       // ステータス表示メニュー\r
+       sub3 = CmCreateTraySubMenu(hWnd, true, CM_TRAY_MENU_STATUS_ID_START);\r
+       if (sub3 != NULL)\r
+       {\r
+               MsAppendMenu(h, MF_BYPOSITION | MF_ENABLED | MF_POPUP | MF_STRING,\r
+                       (UINT_PTR)sub3, _UU("CM_TRAY_MENU_STATUS"));\r
+       }\r
+\r
+       if (sub3 != NULL)\r
+       {\r
+               // すべての接続を切断\r
+               MsAppendMenu(h, MF_ENABLED | MF_STRING, CMD_DISCONNECT_ALL, _UU("CM_TRAY_MENU_DISCONNECT_ALL"));\r
+       }\r
+\r
+       if (sub1 != NULL || sub2 != NULL || sub3 != NULL)\r
+       {\r
+               // セパレータ\r
+               MsAppendMenu(h, MF_SEPARATOR, 10003, NULL);\r
+       }\r
+\r
+       // 最近接続した VPN サーバーに接続\r
+       sub4 = CmCreateRecentSubMenu(hWnd, CM_TRAY_MENU_RECENT_ID_START);\r
+       if (sub4 != NULL)\r
+       {\r
+               MsAppendMenu(h, MF_BYPOSITION | MF_ENABLED | MF_POPUP | MF_STRING,\r
+                       (UINT_PTR)sub4, _UU("CM_TRAY_MENU_RECENT"));\r
+               MsAppendMenu(h, MF_SEPARATOR, 10008, NULL);\r
+       }\r
+\r
+       if (locked == false && easy == false)\r
+       {\r
+               // 通信スループット測定\r
+               MsAppendMenu(h, MF_ENABLED | MF_STRING, CMD_TRAFFIC, _UU("CM_TRAY_MENU_TRAFFIC"));\r
+       }\r
+\r
+       if (easy == false)\r
+       {\r
+               // ネットワークデバイス状態\r
+               MsAppendMenu(h, MF_ENABLED | MF_STRING, CMD_NETIF, _UU("CM_TRAY_MENU_NETIF"));\r
+       }\r
+\r
+       // バージョン情報\r
+       MsAppendMenu(h, MF_ENABLED | MF_STRING, CMD_ABOUT, _UU("CM_TRAY_MENU_ABOUT"));\r
+\r
+       // セパレータ\r
+       MsAppendMenu(h, MF_SEPARATOR, 10001, NULL);\r
+\r
+       // 動作モードの変更\r
+       MsAppendMenu(h, MF_ENABLED | MF_STRING, CMD_CM_SETTING, _UU("CM_TRAY_MENU_SETTING"));\r
+\r
+       // セパレータ\r
+       MsAppendMenu(h, MF_SEPARATOR, 10001, NULL);\r
+\r
+       // アイコンを非表示\r
+       MsAppendMenu(h, MF_ENABLED | MF_STRING, CMD_TRAYICON, _UU("CM_MENU@CMD_TRAYICON"));\r
+\r
+       // セパレータ\r
+       MsAppendMenu(h, MF_SEPARATOR, 10001, NULL);\r
+\r
+       // 表示または非表示\r
+       MsAppendMenu(h, MF_ENABLED | MF_STRING, CMD_EXIT,\r
+               IsHide(hWnd, 0) ? _UU("CM_TRAY_MENU_1_SHOW") : _UU("CM_TRAY_MENU_1_HIDE"));\r
+\r
+       // 終了\r
+       MsAppendMenu(h, MF_ENABLED | MF_STRING, CMD_QUIT, _UU("CM_TRAY_MENU_2_QUIT"));\r
+\r
+       // メニューを表示する\r
+       GetCursorPos(&p);\r
+\r
+       SetForegroundWindow(hWnd);\r
+       TrackPopupMenu(h, TPM_LEFTALIGN, p.x, p.y, 0, hWnd, NULL);\r
+       PostMessage(hWnd, WM_NULL, 0, 0);\r
+\r
+       if (sub1 != NULL)\r
+       {\r
+               DestroyMenu(sub1);\r
+       }\r
+\r
+       if (sub2 != NULL)\r
+       {\r
+               DestroyMenu(sub2);\r
+       }\r
+\r
+       if (sub3 != NULL)\r
+       {\r
+               DestroyMenu(sub3);\r
+       }\r
+\r
+       DestroyMenu(h);\r
+\r
+       cm->MenuPopuping = false;\r
+}\r
+\r
+// メインウインドウを表示または隠す\r
+void CmShowOrHideWindow(HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsHide(hWnd, 0))\r
+       {\r
+               Show(hWnd, 0);\r
+               if (IsIconic(hWnd))\r
+               {\r
+                       ShowWindow(hWnd, SW_SHOWNORMAL);\r
+               }\r
+               SetForegroundWindow(hWnd);\r
+               SetActiveWindow(hWnd);\r
+       }\r
+       else\r
+       {\r
+               CmSaveMainWindowPos(hWnd);\r
+               Hide(hWnd, 0);\r
+\r
+               if (cm->TrayInited == false)\r
+               {\r
+                       Command(hWnd, CMD_QUIT);\r
+                       return;\r
+               }\r
+       }\r
+}\r
+\r
+// アカウントリストを右クリックした\r
+void CmAccountListRightClick(HWND hWnd)\r
+{\r
+       HMENU h;\r
+       HMENU parent;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メニューをロード\r
+       h = LoadSubMenu(M_MAIN, 0, &parent);\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       InitMenuInternational(h, "CM_MENU");\r
+\r
+       // ショートカットキーを除去\r
+       RemoveShortcutKeyStrFromMenu(h);\r
+\r
+       // 終了メニューを削除\r
+       i = GetMenuItemPos(h, CMD_QUIT);\r
+       if (i != INFINITE)\r
+       {\r
+               DeleteMenuItem(h, i);\r
+               DeleteMenuItem(h, i - 1);\r
+               DeleteMenuItem(h, i - 2);\r
+               DeleteMenuItem(h, i - 3);\r
+       }\r
+\r
+       // 有効 / 無効の設定\r
+       CmMainWindowOnPopupMenu(hWnd, h, INFINITE);\r
+\r
+       if (h != NULL)\r
+       {\r
+               // 選択されているアカウントが接続中かどうか判別する\r
+               UINT i = LvGetSelected(hWnd, L_ACCOUNT);\r
+               wchar_t *str;\r
+               bool is_connected = false;\r
+               if (i != INFINITE)\r
+               {\r
+                       str = LvGetStr(hWnd, L_ACCOUNT, i, 1);\r
+                       if (str != NULL)\r
+                       {\r
+                               if (UniStrCmpi(str, _UU("CM_ACCOUNT_ONLINE")) == 0 || UniStrCmpi(str, _UU("CM_ACCOUNT_CONNECTING")) == 0)\r
+                               {\r
+                                       // 接続中\r
+                                       is_connected = true;\r
+                               }\r
+                               Free(str);\r
+                       }\r
+               }\r
+\r
+               if (i == INFINITE)\r
+               {\r
+                       // 新規作成メニューを太字にする\r
+                       SetMenuItemBold(h, GetMenuItemPos(h, CMD_NEW), true);\r
+               }\r
+               else\r
+               {\r
+                       if (is_connected == false)\r
+                       {\r
+                               // 接続メニューを太字にする\r
+                               SetMenuItemBold(h, GetMenuItemPos(h, CMD_CONNECT), true);\r
+                       }\r
+                       else\r
+                       {\r
+                               // 状況メニューを太字にする\r
+                               SetMenuItemBold(h, GetMenuItemPos(h, CMD_STATUS), true);\r
+                       }\r
+               }\r
+       }\r
+\r
+       // メニューを表示\r
+       PrintMenu(hWnd, h);\r
+\r
+       DestroyMenu(parent);\r
+}\r
+\r
+// 仮想 LAN カードリストを右クリックした\r
+void CmVLanListRightClick(HWND hWnd)\r
+{\r
+       HMENU h;\r
+       HMENU parent;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メニューをロード\r
+       h = LoadSubMenu(M_MAIN, 3, &parent);\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       InitMenuInternational(h, "CM_MENU");\r
+\r
+       // ショートカットキーを除去\r
+       RemoveShortcutKeyStrFromMenu(h);\r
+\r
+       // 有効 / 無効の設定\r
+       CmMainWindowOnPopupMenu(hWnd, h, INFINITE);\r
+\r
+       if (h != NULL)\r
+       {\r
+               // 選択されているデバイスが有効かどうか調べる\r
+               UINT i = LvGetSelected(hWnd, L_VLAN);\r
+               wchar_t *str;\r
+               bool is_active = false;\r
+               if (i != INFINITE)\r
+               {\r
+                       str = LvGetStr(hWnd, L_VLAN, i, 1);\r
+                       if (str != NULL)\r
+                       {\r
+                               if (UniStrCmpi(str, _UU("CM_VLAN_ENABLED")) == 0)\r
+                               {\r
+                                       // 有効\r
+                                       is_active = true;\r
+                               }\r
+                               Free(str);\r
+                       }\r
+               }\r
+\r
+               if (i == INFINITE)\r
+               {\r
+                       // 新規作成メニューを太字にする\r
+                       SetMenuItemBold(h, GetMenuItemPos(h, CMD_NEW_VLAN), true);\r
+               }\r
+               else\r
+               {\r
+                       if (is_active == false)\r
+                       {\r
+                               // 有効化メニューを太字にする\r
+                               SetMenuItemBold(h, GetMenuItemPos(h, CMD_ENABLE_VLAN), true);\r
+                       }\r
+                       else\r
+                       {\r
+                               // Windows ネットワーク設定メニューを太字にする\r
+                               SetMenuItemBold(h, GetMenuItemPos(h, CMD_WINNET), true);\r
+                       }\r
+               }\r
+       }\r
+\r
+       // メニューを表示\r
+       PrintMenu(hWnd, h);\r
+\r
+       DestroyMenu(parent);\r
+}\r
+\r
+// メインウインドウへの通知\r
+void CmMainWindowOnNotify(HWND hWnd, NMHDR *n)\r
+{\r
+       bool item_vlan;\r
+       NMLVDISPINFOW *disp_info;\r
+       NMLVKEYDOWN *key;\r
+\r
+       // 引数チェック\r
+       if (hWnd == NULL || n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       switch (n->idFrom)\r
+       {\r
+       case L_ACCOUNT:\r
+       case L_VLAN:\r
+               if (n->idFrom == L_ACCOUNT)\r
+               {\r
+                       item_vlan = false;\r
+               }\r
+               else\r
+               {\r
+                       item_vlan = true;\r
+               }\r
+\r
+               switch (n->code)\r
+               {\r
+               case NM_DBLCLK:\r
+                       // ダブルクリック\r
+                       CmOnKey(hWnd, false, false, VK_RETURN);\r
+                       break;\r
+               case NM_RCLICK:\r
+                       // 右クリック\r
+                       if (item_vlan == false)\r
+                       {\r
+                               CmAccountListRightClick(hWnd);\r
+                       }\r
+                       else\r
+                       {\r
+                               CmVLanListRightClick(hWnd);\r
+                       }\r
+                       break;\r
+               case LVN_ENDLABELEDITW:\r
+                       // 名前の変更\r
+                       disp_info = (NMLVDISPINFOW *)n;\r
+                       if (disp_info->item.pszText != NULL)\r
+                       {\r
+                               wchar_t *new_name = disp_info->item.pszText;\r
+                               wchar_t *old_name = LvGetStr(hWnd, L_ACCOUNT, disp_info->item.iItem, 0);\r
+\r
+                               if (old_name != NULL)\r
+                               {\r
+                                       if (UniStrCmp(new_name, old_name) != 0 && UniIsEmptyStr(new_name) == false)\r
+                                       {\r
+                                               RPC_RENAME_ACCOUNT a;\r
+                                               Zero(&a, sizeof(a));\r
+                                               UniStrCpy(a.OldName, sizeof(a.OldName), old_name);\r
+                                               UniStrCpy(a.NewName, sizeof(a.NewName), new_name);\r
+                                               if (CALL(hWnd, CcRenameAccount(cm->Client, &a)))\r
+                                               {\r
+                                                       LvSetItem(hWnd, L_ACCOUNT, disp_info->item.iItem, 0, new_name);\r
+                                               }\r
+                                       }\r
+\r
+                                       Free(old_name);\r
+                               }\r
+                       }\r
+                       break;\r
+               case LVN_KEYDOWN:\r
+                       // キー押下\r
+                       key = (NMLVKEYDOWN *)n;\r
+                       if (key != NULL)\r
+                       {\r
+                               bool ctrl, alt;\r
+                               UINT code = key->wVKey;\r
+                               ctrl = (GetKeyState(VK_CONTROL) & 0x8000) == 0 ? false : true;\r
+                               alt = (GetKeyState(VK_MENU) & 0x8000) == 0 ? false : true;\r
+                               CmOnKey(hWnd, ctrl, alt, code);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+}\r
+\r
+// キーボード押下\r
+void CmOnKey(HWND hWnd, bool ctrl, bool alt, UINT key)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 単一キー\r
+       switch (key)\r
+       {\r
+       case VK_RETURN:\r
+               Command(hWnd, IDOK);\r
+               break;\r
+       case VK_DELETE:\r
+               // 削除\r
+               if (IsFocus(hWnd, L_ACCOUNT))\r
+               {\r
+                       // アカウントリストに関する操作\r
+                       Command(hWnd, CMD_DELETE);\r
+               }\r
+               else\r
+               {\r
+                       // 仮想 LAN カードリストに関する操作\r
+                       Command(hWnd, CMD_DELETE_VLAN);\r
+               }\r
+               break;\r
+       case VK_F2:\r
+               // 名前変更\r
+               Command(hWnd, CMD_RENAME);\r
+               break;\r
+       case VK_F5:\r
+               // 状態更新\r
+               Command(hWnd, CMD_REFRESH);\r
+               break;\r
+       }\r
+\r
+       if (alt)\r
+       {\r
+               switch (key)\r
+               {\r
+               case 'Q':\r
+                       // 閉じる\r
+                       Command(hWnd, CMD_QUIT);\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (ctrl)\r
+       {\r
+               switch (key)\r
+               {\r
+               case 'G':\r
+                       // スマートカードマネージャ\r
+                       Command(hWnd, CMD_SECURE_MANAGER);\r
+                       break;\r
+               case 'S':\r
+                       // 状態の表示\r
+                       Command(hWnd, CMD_STATUS);\r
+                       break;\r
+               case 'I':\r
+                       // すべての接続を切断\r
+                       Command(hWnd, CMD_DISCONNECT_ALL);\r
+                       break;\r
+               case 'D':\r
+                       // 切断\r
+                       Command(hWnd, CMD_DISCONNECT);\r
+                       break;\r
+               case 'N':\r
+                       // 接続設定の新規作成\r
+                       Command(hWnd, CMD_NEW);\r
+                       break;\r
+               case 'C':\r
+                       // コピーの作成\r
+                       Command(hWnd, CMD_CLONE);\r
+                       break;\r
+               case 'T':\r
+                       // スタートアップ接続に設定\r
+                       Command(hWnd, CMD_STARTUP);\r
+                       break;\r
+               case 'A':\r
+                       // すべて選択\r
+                       Command(hWnd, CMD_SELECT_ALL);\r
+                       break;\r
+               case 'L':\r
+                       // 新規仮想 LAN カードの作成\r
+                       Command(hWnd, CMD_NEW_VLAN);\r
+                       break;\r
+               case 'E':\r
+                       // 仮想 LAN カードの有効化\r
+                       Command(hWnd, CMD_ENABLE_VLAN);\r
+                       break;\r
+               case 'B':\r
+                       // 仮想 LAN カードの無効化\r
+                       Command(hWnd, CMD_DISABLE_VLAN);\r
+                       break;\r
+               case 'U':\r
+                       // ドライバの再インストール\r
+                       Command(hWnd, CMD_REINSTALL);\r
+                       break;\r
+               case 'W':\r
+                       // Windows ネットワーク接続の設定\r
+                       Command(hWnd, CMD_WINNET);\r
+                       break;\r
+               case 'P':\r
+                       // パスワードの設定\r
+                       Command(hWnd, CMD_PASSWORD);\r
+                       break;\r
+               case 'O':\r
+                       // オプション設定\r
+                       Command(hWnd, CMD_TRAFFIC);\r
+                       break;\r
+               case 'R':\r
+                       // 証明書管理\r
+                       Command(hWnd, CMD_TRUST);\r
+                       break;\r
+               case 'Q':\r
+                       // スループット\r
+                       Command(hWnd, CMD_TRAFFIC);\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// メインウインドウのコマンド\r
+void CmMainWindowOnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)\r
+{\r
+       CmMainWindowOnCommandEx(hWnd, wParam, lParam, false);\r
+}\r
+void CmMainWindowOnCommandEx(HWND hWnd, WPARAM wParam, LPARAM lParam, bool easy)\r
+{\r
+       wchar_t *tmp;\r
+       char *name;\r
+       UINT index;\r
+       UINT id;\r
+       bool ctrl, alt;\r
+       UINT flag = 0;\r
+       // 引数チェック\r
+       wchar_t *selected_name = NULL;\r
+       UINT starter_id = 0;\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ctrl = (GetKeyState(VK_CONTROL) & 0x8000) == 0 ? false : true;\r
+       alt = (GetKeyState(VK_MENU) & 0x8000) == 0 ? false : true;\r
+\r
+       if (wParam == IDOK)\r
+       {\r
+               tmp = LvGetSelectedStr(hWnd, L_ACCOUNT, 0);\r
+               if (tmp != NULL)\r
+               {\r
+                       if (UniStrCmpi(tmp, _UU("CM_NEW_ICON")) == 0)\r
+                       {\r
+                               Free(tmp);\r
+                               Command(hWnd, CMD_NEW);\r
+                               return;\r
+                       }\r
+                       if (UniStrCmpi(tmp, _UU("CM_ASP")) == 0)\r
+                       {\r
+                               Free(tmp);\r
+                               ShellExecuteA(hWnd, "open", _SS("CM_ASP_URL"), NULL, NULL, SW_SHOW);\r
+                               return;\r
+                       }\r
+                       Free(tmp);\r
+               }\r
+       }\r
+\r
+       if (CmIsEnabled(hWnd, (UINT)wParam) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (CM_TRAY_IS_CONNECT_ID(wParam))\r
+       {\r
+               // 接続要求\r
+               starter_id = CM_TRAY_MENU_CONNECT_ID_START;\r
+               flag = 1;\r
+       }\r
+\r
+       if (CM_TRAY_IS_STATUS_ID(wParam))\r
+       {\r
+               // 情報表示要求\r
+               starter_id = CM_TRAY_MENU_STATUS_ID_START;\r
+               flag = 2;\r
+       }\r
+\r
+       if (CM_TRAY_IS_DISCONNECT_ID(wParam))\r
+       {\r
+               // 切断要求\r
+               starter_id = CM_TRAY_MENU_DISCONNECT_ID_START;\r
+               flag = 3;\r
+       }\r
+\r
+       if (CM_TRAY_IS_RECENT_ID(wParam))\r
+       {\r
+               // 最近の接続先\r
+               starter_id = CM_TRAY_MENU_RECENT_ID_START;\r
+               flag = 1;\r
+       }\r
+\r
+       if (starter_id != 0)\r
+       {\r
+               UINT num;\r
+\r
+               id = (UINT)wParam - starter_id;\r
+\r
+               num = LvNum(hWnd, L_ACCOUNT);\r
+\r
+               if (id < num)\r
+               {\r
+                       selected_name = LvGetStr(hWnd, L_ACCOUNT, id, 0);\r
+\r
+                       if (selected_name != NULL)\r
+                       {\r
+                               if (UniStrCmpi(selected_name, _UU("CM_NEW_ICON")) != 0 &&\r
+                                       UniStrCmpi(selected_name, _UU("CM_ASP")) != 0)\r
+                               {\r
+                                       switch (flag)\r
+                                       {\r
+                                       case 1:\r
+                                               CmConnect(hWnd, selected_name);\r
+                                               break;\r
+\r
+                                       case 2:\r
+                                               CmStatus(hWnd, selected_name);\r
+                                               break;\r
+\r
+                                       case 3:\r
+                                               CmDisconnect(hWnd, selected_name);\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       Free(selected_name);\r
+               }\r
+       }\r
+\r
+       switch (wParam)\r
+       {\r
+       case IDOK:\r
+       case CMD_EASY_DBLCLICK:\r
+               // 接続またはプロパティ\r
+               if (IsFocus(hWnd, L_ACCOUNT) || (hWnd == cm->hEasyWnd))\r
+               {\r
+                       // アカウントリストに関する操作\r
+                       if (alt == false)\r
+                       {\r
+                               UINT index = LvGetSelected(hWnd, L_ACCOUNT);\r
+                               bool b = false;\r
+                               if (index != INFINITE)\r
+                               {\r
+                                       wchar_t *s = LvGetStr(hWnd, L_ACCOUNT, index, 1);\r
+                                       if (s != NULL)\r
+                                       {\r
+                                               if (UniStrCmpi(s, _UU("CM_ACCOUNT_ONLINE")) == 0 || UniStrCmpi(s, _UU("CM_ACCOUNT_CONNECTING")) == 0)\r
+                                               {\r
+                                                       b = true;\r
+                                               }\r
+                                               Free(s);\r
+                                       }\r
+                               }\r
+\r
+                               if (b == false)\r
+                               {\r
+                                       // 接続\r
+                                       Command(hWnd, CMD_CONNECT);\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (hWnd != cm->hEasyWnd || wParam == CMD_EASY_DBLCLICK)\r
+                                       {\r
+                                               // 状況表示\r
+                                               Command(hWnd, CMD_STATUS);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // 切断\r
+                                               Command(hWnd, CMD_DISCONNECT);\r
+                                       }\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // プロパティ\r
+                               Command(hWnd, CMD_PROPERTY);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // Windows ネットワーク接続の設定\r
+                       Command(hWnd, CMD_WINNET);\r
+               }\r
+               break;\r
+       case CMD_CONNECT:\r
+               // 接続\r
+               tmp = LvGetStr(hWnd, L_ACCOUNT, LvGetSelected(hWnd, L_ACCOUNT), 0);\r
+               if (tmp != NULL)\r
+               {\r
+                       CmConnect(hWnd, tmp);\r
+                       Free(tmp);\r
+               }\r
+               break;\r
+       case CMD_STATUS:\r
+               // 状態の表示\r
+               tmp = LvGetStr(hWnd, L_ACCOUNT, LvGetSelected(hWnd, L_ACCOUNT), 0);\r
+               if (tmp != NULL)\r
+               {\r
+                       CmStatus(hWnd, tmp);\r
+                       Free(tmp);\r
+               }\r
+               break;\r
+       case CMD_DISCONNECT_ALL:\r
+               // すべての接続を切断する\r
+               CmDisconnectAll(hWnd);\r
+               break;\r
+       case CMD_DISCONNECT:\r
+               // 切断\r
+               tmp = LvGetStr(hWnd, L_ACCOUNT, LvGetSelected(hWnd, L_ACCOUNT), 0);\r
+               if (tmp != NULL)\r
+               {\r
+                       CmDisconnect(hWnd, tmp);\r
+                       Free(tmp);\r
+               }\r
+               break;\r
+       case CMD_NEW:\r
+               // 新規作成\r
+               CmNewAccount(hWnd);\r
+               break;\r
+       case CMD_CLONE:\r
+               // コピー\r
+               tmp = LvGetStr(hWnd, L_ACCOUNT, LvGetSelected(hWnd, L_ACCOUNT), 0);\r
+               if (tmp != NULL)\r
+               {\r
+                       CmCopyAccount(hWnd, tmp);\r
+                       Free(tmp);\r
+               }\r
+               break;\r
+       case CMD_SHORTCUT:\r
+               // ショートカット作成\r
+               tmp = LvGetStr(hWnd, L_ACCOUNT, LvGetSelected(hWnd, L_ACCOUNT), 0);\r
+               if (tmp != NULL)\r
+               {\r
+                       CmSortcut(hWnd, tmp);\r
+                       Free(tmp);\r
+               }\r
+               break;\r
+       case CMD_EXPORT_ACCOUNT:\r
+               // 設定のエクスポート\r
+               tmp = LvGetStr(hWnd, L_ACCOUNT, LvGetSelected(hWnd, L_ACCOUNT), 0);\r
+               if (tmp != NULL)\r
+               {\r
+                       CmExportAccount(hWnd, tmp);\r
+                       Free(tmp);\r
+               }\r
+               break;\r
+       case CMD_IMPORT_ACCOUNT:\r
+               // 設定のインポート\r
+               CmImportAccount(hWnd);\r
+               break;\r
+       case CMD_STARTUP:\r
+               // スタートアップ接続に設定\r
+               tmp = LvGetStr(hWnd, L_ACCOUNT, LvGetSelected(hWnd, L_ACCOUNT), 0);\r
+               if (tmp != NULL)\r
+               {\r
+                       RPC_CLIENT_DELETE_ACCOUNT c;\r
+                       Zero(&c, sizeof(c));\r
+                       UniStrCpy(c.AccountName, sizeof(c.AccountName), tmp);\r
+                       CALL(hWnd, CcSetStartupAccount(cm->Client, &c));\r
+                       CmVoice("set_startup");\r
+                       MsgBoxEx(hWnd, MB_ICONINFORMATION, _UU("CM_SET_STARTUP"), tmp);\r
+                       Free(tmp);\r
+               }\r
+               break;\r
+       case CMD_NOSTARTUP:\r
+               // スタートアップ接続を解除\r
+               tmp = LvGetStr(hWnd, L_ACCOUNT, LvGetSelected(hWnd, L_ACCOUNT), 0);\r
+               if (tmp != NULL)\r
+               {\r
+                       if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2,\r
+                               _UU("CM_REMOVE_STARTUP"), tmp) == IDYES)\r
+                       {\r
+                               RPC_CLIENT_DELETE_ACCOUNT c;\r
+                               Zero(&c, sizeof(c));\r
+                               UniStrCpy(c.AccountName, sizeof(c.AccountName), tmp);\r
+                               CALL(hWnd, CcRemoveStartupAccount(cm->Client, &c));\r
+                               CmVoice("remove_startup");\r
+                       }\r
+                       Free(tmp);\r
+               }\r
+               break;\r
+       case CMD_DELETE:\r
+               // 削除\r
+               tmp = LvGetStr(hWnd, L_ACCOUNT, LvGetSelected(hWnd, L_ACCOUNT), 0);\r
+               if (tmp != NULL)\r
+               {\r
+                       CmDeleteAccount(hWnd, tmp);\r
+                       Free(tmp);\r
+               }\r
+               break;\r
+       case CMD_RENAME:\r
+               // 名前の変更\r
+               Focus(hWnd, L_ACCOUNT);\r
+               LvRename(hWnd, L_ACCOUNT, LvGetSelected(hWnd, L_ACCOUNT));\r
+               break;\r
+       case CMD_PROPERTY:\r
+               // プロパティ\r
+               tmp = LvGetStr(hWnd, L_ACCOUNT, LvGetSelected(hWnd, L_ACCOUNT), 0);\r
+               if (tmp != NULL)\r
+               {\r
+                       CmEditAccount(hWnd, tmp);\r
+                       Free(tmp);\r
+               }\r
+               break;\r
+       case IDCANCEL:\r
+       case CMD_EXIT:\r
+               // 閉じる\r
+               Close(hWnd);\r
+               break;\r
+       case CMD_QUIT:\r
+               // 終了\r
+               CmMainWindowOnQuit(hWnd);\r
+               break;\r
+       case CMD_SELECT_ALL:\r
+               // すべて選択\r
+               LvSelectAll(hWnd, L_ACCOUNT);\r
+               LvSelectAll(hWnd, L_VLAN);\r
+               break;\r
+       case CMD_SWITCH_SELECT:\r
+               // 選択反転\r
+               LvSwitchSelect(hWnd, L_ACCOUNT);\r
+               LvSwitchSelect(hWnd, L_VLAN);\r
+               break;\r
+       case CMD_GRID:\r
+               // 罫線表示\r
+               cm->ShowGrid = !cm->ShowGrid;\r
+               CmRefreshVLanListEx(hWnd, true);\r
+               CmRefreshAccountListEx2(hWnd, false, true);\r
+               break;\r
+       case CMD_STATUSBAR:\r
+               // ステータスバー表示\r
+               if (cm->HideStatusBar == false)\r
+               {\r
+                       cm->HideStatusBar = true;\r
+                       Hide(hWnd, S_STATUSBAR);\r
+                       CmMainWindowOnSize(hWnd);\r
+               }\r
+               else\r
+               {\r
+                       cm->HideStatusBar = false;\r
+                       Show(hWnd, S_STATUSBAR);\r
+                       CmMainWindowOnSize(hWnd);\r
+               }\r
+               CmSaveMainWindowPos(hWnd);\r
+               break;\r
+       case CMD_VISTASTYLE:\r
+               cm->VistaStyle = !cm->VistaStyle;\r
+               CmRefreshEx(hWnd, true);\r
+               CmSaveMainWindowPos(hWnd);\r
+               break;\r
+       case CMD_TRAYICON:\r
+               // トレイアイコン表示\r
+               if (cm->HideTrayIcon == false)\r
+               {\r
+                       cm->HideTrayIcon = true;\r
+                       CmFreeTray(hWnd);\r
+\r
+                       if (IsHide(hWnd, 0))\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_TRAY_ICON_RESTORE"));\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       cm->HideTrayIcon = false;\r
+                       if (cm->server_name == NULL)\r
+                       {\r
+                               CmInitTray(hWnd);\r
+                       }\r
+               }\r
+               break;\r
+       case CMD_SHOWPORT:\r
+               // ポート番号を表示\r
+               cm->ShowPort = !cm->ShowPort;\r
+               CmRefresh(hWnd);\r
+               break;\r
+       case CMD_ICON:\r
+               // アイコン表示\r
+               if (cm->IconView == false)\r
+               {\r
+                       cm->IconView = true;\r
+                       CmRefresh(hWnd);\r
+               }\r
+               break;\r
+       case CMD_DETAIL:\r
+               // 詳細表示\r
+               if (cm->IconView)\r
+               {\r
+                       cm->IconView = false;\r
+                       CmRefresh(hWnd);\r
+               }\r
+               break;\r
+       case CMD_REFRESH:\r
+               if (easy == false)\r
+               {\r
+                       // 表示更新\r
+                       LvReset(hWnd, L_ACCOUNT);\r
+                       LvReset(hWnd, L_VLAN);\r
+                       CmRefresh(hWnd);\r
+               }\r
+               break;\r
+       case CMD_NEW_VLAN:\r
+               // 仮想 LAN カード作成\r
+               name = CmNewVLanDlg(hWnd);\r
+               if (name != NULL)\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       void *helper = NULL;\r
+                       RPC_CLIENT_CREATE_VLAN c;\r
+                       Zero(&c, sizeof(c));\r
+                       StrCpy(c.DeviceName, sizeof(c.DeviceName), name);\r
+                       if (MsIsNt() == false)\r
+                       {\r
+                               // ウインドウのタイトルを変更する\r
+                               GetTxt(hWnd, 0, tmp, sizeof(tmp));\r
+                               SetText(hWnd, 0, _UU("CM_VLAN_INSTALLING"));\r
+                       }\r
+                       // 最小化\r
+                       if (MsIsVista() == false)\r
+                       {\r
+                               ShowWindow(hWnd, SW_SHOWMINIMIZED);\r
+                       }\r
+\r
+                       if (MsIsVista())\r
+                       {\r
+                               helper = CmStartUacHelper();\r
+                       }\r
+\r
+                       if (CALL(hWnd, CcCreateVLan(cm->Client, &c)))\r
+                       {\r
+                               CmVoice("new_vlan");\r
+                       }\r
+\r
+                       CmStopUacHelper(helper);\r
+\r
+                       if (MsIsNt() == false)\r
+                       {\r
+                               // ウインドウのタイトルを戻す\r
+                               SetText(hWnd, 0, tmp);\r
+                       }\r
+                       // 戻す\r
+                       if (MsIsVista() == false)\r
+                       {\r
+                               ShowWindow(hWnd, SW_SHOWNORMAL);\r
+                       }\r
+                       Free(name);\r
+               }\r
+               break;\r
+       case CMD_DELETE_VLAN:\r
+               // 仮想 LAN カード削除\r
+               index = LvGetSelected(hWnd, L_VLAN);\r
+               if (index != INFINITE)\r
+               {\r
+                       if (cm->Client->Win9x == false)\r
+                       {\r
+                               // Windows 2000 以降\r
+                               wchar_t *s = LvGetStr(hWnd, L_VLAN, index, 0);\r
+                               if (s != NULL)\r
+                               {\r
+                                       RPC_CLIENT_CREATE_VLAN c;\r
+                                       char str[MAX_SIZE];\r
+                                       CmVoice("delete_vlan_1");\r
+                                       if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("CM_DELETE_VLAN"), s) == IDYES)\r
+                                       {\r
+                                               Zero(&c, sizeof(c));\r
+                                               UniToStr(str, sizeof(str), s);\r
+                                               if (CmPrintNameToVLanName(c.DeviceName, sizeof(c.DeviceName), str))\r
+                                               {\r
+                                                       if (CALL(hWnd, CcDeleteVLan(cm->Client, &c)))\r
+                                                       {\r
+                                                               CmVoice("delete_vlan_2");\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       Free(s);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // Windows 9x\r
+                               if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("CM_9X_VLAN_UNINSTALL")) == IDYES)\r
+                               {\r
+                                       Run("rundll32.exe", "shell32.dll,Control_RunDLL NETCPL.CPL",\r
+                                               false, false);\r
+                               }\r
+                       }\r
+               }\r
+               break;\r
+       case CMD_ENABLE_VLAN:\r
+               // 仮想 LAN カードの有効化\r
+               index = LvGetSelected(hWnd, L_VLAN);\r
+               if (index != INFINITE)\r
+               {\r
+                       wchar_t *s = LvGetStr(hWnd, L_VLAN, index, 0);\r
+                       if (s != NULL)\r
+                       {\r
+                               RPC_CLIENT_CREATE_VLAN c;\r
+                               char str[MAX_SIZE];\r
+                               Zero(&c, sizeof(c));\r
+                               UniToStr(str, sizeof(str), s);\r
+                               if (CmPrintNameToVLanName(c.DeviceName, sizeof(c.DeviceName), str))\r
+                               {\r
+                                       CALL(hWnd, CcEnableVLan(cm->Client, &c));\r
+                               }\r
+                               Free(s);\r
+                       }\r
+               }\r
+               break;\r
+       case CMD_DISABLE_VLAN:\r
+               // 仮想 LAN カードの無効化\r
+               index = LvGetSelected(hWnd, L_VLAN);\r
+               if (index != INFINITE)\r
+               {\r
+                       wchar_t *s = LvGetStr(hWnd, L_VLAN, index, 0);\r
+                       if (s != NULL)\r
+                       {\r
+                               RPC_CLIENT_CREATE_VLAN c;\r
+                               char str[MAX_SIZE];\r
+                               Zero(&c, sizeof(c));\r
+                               UniToStr(str, sizeof(str), s);\r
+                               if (CmPrintNameToVLanName(c.DeviceName, sizeof(c.DeviceName), str))\r
+                               {\r
+                                       CALL(hWnd, CcDisableVLan(cm->Client, &c));\r
+                               }\r
+                               Free(s);\r
+                       }\r
+               }\r
+               break;\r
+       case CMD_REINSTALL:\r
+               // 仮想 LAN カードの再インストール\r
+               index = LvGetSelected(hWnd, L_VLAN);\r
+               if (index != INFINITE)\r
+               {\r
+                       wchar_t *s = LvGetStr(hWnd, L_VLAN, index, 0);\r
+                       if (s != NULL)\r
+                       {\r
+                               RPC_CLIENT_CREATE_VLAN c;\r
+                               char str[MAX_SIZE];\r
+                               Zero(&c, sizeof(c));\r
+                               UniToStr(str, sizeof(str), s);\r
+                               if (CmPrintNameToVLanName(c.DeviceName, sizeof(c.DeviceName), str))\r
+                               {\r
+                                       void *helper = NULL;\r
+\r
+                                       if (MsIsVista() == false)\r
+                                       {\r
+                                               ShowWindow(hWnd, SW_SHOWMINIMIZED);\r
+                                       }\r
+\r
+                                       if (MsIsVista())\r
+                                       {\r
+                                               helper = CmStartUacHelper();\r
+                                       }\r
+\r
+                                       CALL(hWnd, CcUpgradeVLan(cm->Client, &c));\r
+\r
+                                       CmStopUacHelper(helper);\r
+\r
+                                       if (MsIsVista() == false)\r
+                                       {\r
+                                               ShowWindow(hWnd, SW_SHOWNORMAL);\r
+                                       }\r
+                               }\r
+                               Free(s);\r
+                       }\r
+               }\r
+               break;\r
+       case CMD_PASSWORD:\r
+               // パスワード設定\r
+               CmPassword(hWnd);\r
+               break;\r
+       case CMD_OPTION:\r
+               // オプション\r
+               CmConfigDlg(hWnd);\r
+               break;\r
+       case CMD_TRUST:\r
+               // 証明書管理\r
+               CmTrustDlg(hWnd);\r
+               break;\r
+       case CMD_ABOUT:\r
+               // バージョン情報\r
+               if (IsEnable(hWnd, 0))\r
+               {\r
+                       ShowSplashEx(hWnd, "UT-VPN Client", 0, CM_SPLASH_BORDER_COLOR);\r
+               }\r
+               break;\r
+       case CMD_VOIDE_NONE:\r
+               cm->DisableVoice = true;\r
+               break;\r
+       case CMD_VOICE_NORMAL:\r
+               cm->DisableVoice = false;\r
+               cm->VoiceId = VOICE_SSK;\r
+               break;\r
+       case CMD_VOICE_ODD:\r
+               if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("CM_EXT_VOICE_MSG")) == IDYES)\r
+               {\r
+                       cm->DisableVoice = false;\r
+                       cm->VoiceId = VOICE_AHO;\r
+               }\r
+               break;\r
+       case CMD_SECURE_MANAGER:\r
+               // スマートカードマネージャ\r
+               CmClientSecureManager(hWnd);\r
+               break;\r
+       case CMD_SECURE_SELECT:\r
+               // スマートカードの選択\r
+               CmClientSelectSecure(hWnd);\r
+               break;\r
+       case CMD_NETIF:\r
+               // ネットワークデバイスの状態\r
+               if (IsEnable(hWnd, 0))\r
+               {\r
+                       UtSpeedMeterEx(hWnd);\r
+               }\r
+               break;\r
+       case CMD_TCPIP:\r
+               // TCP/IP 最適化ユーティリティ\r
+               if (IsEnable(hWnd, 0))\r
+               {\r
+                       ShowTcpIpConfigUtil(hWnd, true);\r
+               }\r
+               break;\r
+       case CMD_MMCSS:\r
+               // Windows Vista 用最適化ユーティリティ\r
+               if (MsIsVista() == false)\r
+               {\r
+                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("VISTA_MMCSS_MSG_4"));\r
+               }\r
+               else\r
+               {\r
+                       if (MsIsAdmin() == false)\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONEXCLAMATION, _UU("VISTA_MMCSS_MSG_4"));\r
+                       }\r
+                       else\r
+                       {\r
+                               if (MsIsMMCSSNetworkThrottlingEnabled())\r
+                               {\r
+                                       if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("VISTA_MMCSS_MSG")) == IDYES)\r
+                                       {\r
+                                               MsSetMMCSSNetworkThrottlingEnable(false);\r
+                                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("VISTA_MMCSS_MSG_5"));\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("VISTA_MMCSS_MSG_2")) == IDYES)\r
+                                       {\r
+                                               MsSetMMCSSNetworkThrottlingEnable(true);\r
+                                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("VISTA_MMCSS_MSG_6"));\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               break;\r
+       case CMD_TRAFFIC:\r
+               // 通信トラフィック測定\r
+               if (IsEnable(hWnd, 0))\r
+               {\r
+                       CmTraffic(hWnd);\r
+               }\r
+               break;\r
+       case CMD_CM_SETTING:\r
+               // 動作モード設定\r
+               if (IsEnable(hWnd, 0))\r
+               {\r
+                       if (CmSetting(hWnd))\r
+                       {\r
+                               CmApplyCmSetting();\r
+                       }\r
+               }\r
+               break;\r
+       case CMD_WINNET:\r
+               // Windows ネットワークの設定\r
+               ShowWindowsNetworkConnectionDialog();\r
+               break;\r
+       }\r
+}\r
+\r
+// オプション設定ダイアログ\r
+void CmConfigDlg(HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_CM_CONFIG, CmConfigDlgProc, NULL);\r
+}\r
+\r
+// オプション設定ダイアログの初期化\r
+void CmConfigDlgInit(HWND hWnd)\r
+{\r
+       bool use_alpha;\r
+       UINT alpha_value;\r
+       UINT os;\r
+       CLIENT_CONFIG c;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DlgFont(hWnd, S_WARNING, 10, true);\r
+       DlgFont(hWnd, S_INFO, 10, false);\r
+\r
+       Zero(&c, sizeof(c));\r
+       if (CALL(hWnd, CcGetClientConfig(cm->Client, &c)) == false)\r
+       {\r
+               EndDialog(hWnd, 0);\r
+               return;\r
+       }\r
+\r
+       Check(hWnd, R_ALLOW_REMOTE_CONFIG, c.AllowRemoteConfig);\r
+\r
+       Check(hWnd, R_USE_KEEP_CONNECT, c.UseKeepConnect);\r
+       SetTextA(hWnd, E_HOSTNAME, c.KeepConnectHost);\r
+       SetIntEx(hWnd, E_PORT, c.KeepConnectPort);\r
+       SetIntEx(hWnd, E_INTERVAL, c.KeepConnectInterval);\r
+\r
+       Check(hWnd, R_TCP, c.KeepConnectProtocol == CONNECTION_TCP);\r
+       Check(hWnd, R_UDP, c.KeepConnectProtocol == CONNECTION_UDP);\r
+\r
+       use_alpha = MsRegReadInt(REG_CURRENT_USER, CM_REG_KEY, "UseAlpha") == 0 ? false : true;\r
+       alpha_value = MsRegReadInt(REG_CURRENT_USER, CM_REG_KEY, "AlphaValue");\r
+       alpha_value = MAKESURE(alpha_value, 0, 100);\r
+\r
+       SetInt(hWnd, E_ALPHA_VALUE, alpha_value == 0 ? 50 : alpha_value);\r
+       Check(hWnd, R_ALPHA, use_alpha);\r
+\r
+       os = GetOsInfo()->OsType;\r
+       if (OS_IS_WINDOWS_NT(os) && GET_KETA(os, 100) >= 2)\r
+       {\r
+               Enable(hWnd, R_ALPHA);\r
+       }\r
+       else\r
+       {\r
+               Disable(hWnd, R_ALPHA);\r
+       }\r
+\r
+       CmConfigDlgRefresh(hWnd);\r
+}\r
+\r
+// オプション設定ダイアログの更新\r
+void CmConfigDlgRefresh(HWND hWnd)\r
+{\r
+       bool ok = true;\r
+       bool use_keep_connect;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       use_keep_connect = IsChecked(hWnd, R_USE_KEEP_CONNECT);\r
+       SetEnable(hWnd, S_HOSTNAME, use_keep_connect);\r
+       SetEnable(hWnd, S_PORT, use_keep_connect);\r
+       SetEnable(hWnd, S_INTERVAL, use_keep_connect);\r
+       SetEnable(hWnd, S_INTERVAL2, use_keep_connect);\r
+       SetEnable(hWnd, S_PROTOCOL, use_keep_connect);\r
+       SetEnable(hWnd, S_INFO, use_keep_connect);\r
+       SetEnable(hWnd, S_INFO2, use_keep_connect);\r
+       SetEnable(hWnd, E_HOSTNAME, use_keep_connect);\r
+       SetEnable(hWnd, E_PORT, use_keep_connect);\r
+       SetEnable(hWnd, E_INTERVAL, use_keep_connect);\r
+       SetEnable(hWnd, R_TCP, use_keep_connect);\r
+       SetEnable(hWnd, R_UDP, use_keep_connect);\r
+\r
+       SetEnable(hWnd, S_WARNING, IsChecked(hWnd, R_ALLOW_REMOTE_CONFIG));\r
+\r
+       if (IsChecked(hWnd, R_USE_KEEP_CONNECT))\r
+       {\r
+               if (IsEmpty(hWnd, E_HOSTNAME))\r
+               {\r
+                       ok = false;\r
+               }\r
+               if (IsChecked(hWnd, R_TCP) == false && IsChecked(hWnd, R_UDP) == false)\r
+               {\r
+                       ok = false;\r
+               }\r
+               if (GetInt(hWnd, E_PORT) == 0 || GetInt(hWnd, E_PORT) >= 65536)\r
+               {\r
+                       ok = false;\r
+               }\r
+               if (GetInt(hWnd, E_INTERVAL) == 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_ALPHA))\r
+       {\r
+               UINT i = GetInt(hWnd, E_ALPHA_VALUE);\r
+               if (i < 20 || i >= 100)\r
+               {\r
+                       ok = false;\r
+               }\r
+               Enable(hWnd, E_ALPHA_VALUE);\r
+       }\r
+       else\r
+       {\r
+               Disable(hWnd, E_ALPHA_VALUE);\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// オプション設定ダイアログの設定保存\r
+void CmConfigDlgOnOk(HWND hWnd)\r
+{\r
+       CLIENT_CONFIG c;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&c, sizeof(c));\r
+       c.AllowRemoteConfig = IsChecked(hWnd, R_ALLOW_REMOTE_CONFIG);\r
+       c.UseKeepConnect = IsChecked(hWnd, R_USE_KEEP_CONNECT);\r
+       GetTxtA(hWnd, E_HOSTNAME, c.KeepConnectHost, sizeof(c.KeepConnectHost));\r
+       c.KeepConnectPort = GetInt(hWnd, E_PORT);\r
+       c.KeepConnectInterval = GetInt(hWnd, E_INTERVAL);\r
+       if (IsChecked(hWnd, R_TCP))\r
+       {\r
+               c.KeepConnectProtocol = CONNECTION_TCP;\r
+       }\r
+       else if (IsChecked(hWnd, R_UDP))\r
+       {\r
+               c.KeepConnectProtocol = CONNECTION_UDP;\r
+       }\r
+       else\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (c.UseKeepConnect)\r
+       {\r
+               if (c.KeepConnectInterval < KEEP_INTERVAL_MIN || c.KeepConnectInterval > KEEP_INTERVAL_MAX)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONINFORMATION, _UU("CM_KEEP_INTERVAL_MSG"),\r
+                               KEEP_INTERVAL_MIN, KEEP_INTERVAL_MAX);\r
+                       FocusEx(hWnd, E_INTERVAL);\r
+                       return;\r
+               }\r
+       }\r
+\r
+       if (CALL(hWnd, CcSetClientConfig(cm->Client, &c)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_REG_KEY, "AlphaValue", GetInt(hWnd, E_ALPHA_VALUE));\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_REG_KEY, "UseAlpha", IsChecked(hWnd, R_ALPHA));\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// オプション設定ダイアログプロシージャ\r
+UINT CmConfigDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               CmConfigDlgInit(hWnd);\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_ALLOW_REMOTE_CONFIG:\r
+               case R_USE_KEEP_CONNECT:\r
+               case E_HOSTNAME:\r
+               case E_PORT:\r
+               case E_INTERVAL:\r
+               case R_ALPHA:\r
+               case E_ALPHA_VALUE:\r
+                       CmConfigDlgRefresh(hWnd);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       CmConfigDlgRefresh(hWnd);\r
+                       CmConfigDlgOnOk(hWnd);\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               case R_ALLOW_REMOTE_CONFIG:\r
+                       if (IsChecked(hWnd, R_ALLOW_REMOTE_CONFIG) == false)\r
+                       {\r
+                               if (cm->server_name != NULL)\r
+                               {\r
+                                       // 現在リモート接続している場合、リモート管理を無効にするように\r
+                                       // 選択すると警告を表示する\r
+                                       if (MsgBoxEx(hWnd, MB_ICONEXCLAMATION | MB_DEFBUTTON2 | MB_YESNO, _UU("CM_REMOTE_WARNING"),\r
+                                               cm->server_name, cm->server_name) == IDNO)\r
+                                       {\r
+                                               Check(hWnd, R_ALLOW_REMOTE_CONFIG, true);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+               case R_USE_KEEP_CONNECT:\r
+                       if (IsChecked(hWnd, R_USE_KEEP_CONNECT))\r
+                       {\r
+                               FocusEx(hWnd, E_HOSTNAME);\r
+                       }\r
+                       break;\r
+               case R_ALPHA:\r
+                       if (IsChecked(hWnd, R_ALPHA))\r
+                       {\r
+                               FocusEx(hWnd, E_ALPHA_VALUE);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ショートカット作成\r
+void CmSortcut(HWND hWnd, wchar_t *account_name)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       CM_ACCOUNT *a;\r
+       wchar_t *filename;\r
+       UCHAR key[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || account_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // アカウント情報を取得\r
+       a = CmGetExistAccountObject(hWnd, account_name);\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Copy(key, a->ShortcutKey, SHA1_SIZE);\r
+\r
+       if (IsZero(key, SHA1_SIZE))\r
+       {\r
+               MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_SHORTCUT_UNSUPPORTED"));\r
+       }\r
+       else\r
+       {\r
+               // ファイル名を決定\r
+               UniFormat(tmp, sizeof(tmp), L"%s.lnk", account_name);\r
+               UniSafeFileName(tmp);\r
+\r
+               filename = SaveDlg(hWnd, _UU("CM_SHORTCUT_FILE"),\r
+                       _UU("CM_SHORTCUT_SAVE_TITLE"), tmp, L".uvpn");\r
+\r
+               if (filename != NULL)\r
+               {\r
+                       char key_str[64];\r
+                       wchar_t target[MAX_PATH];\r
+                       wchar_t workdir[MAX_PATH];\r
+                       wchar_t args[MAX_PATH];\r
+                       wchar_t comment[MAX_SIZE];\r
+                       wchar_t icon[MAX_PATH];\r
+\r
+                       BinToStr(key_str, sizeof(key_str), key, SHA1_SIZE);\r
+\r
+                       // ショートカットを作成\r
+                       UniStrCpy(target, sizeof(target), MsGetExeFileNameW());\r
+                       UniStrCpy(workdir, sizeof(workdir), MsGetExeDirNameW());\r
+                       StrToUni(args, sizeof(args), key_str);\r
+                       UniFormat(comment, sizeof(comment), _UU("CM_SHORTCUT_COMMENT"), account_name);\r
+                       UniStrCpy(icon, sizeof(icon), MsGetExeFileNameW());\r
+\r
+                       if (CreateLink(tmp, target, workdir, args, comment, icon, 1) == false)\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONSTOP, _UU("CM_SHORTCUT_ERROR"));\r
+                       }\r
+\r
+                       Free(filename);\r
+               }\r
+       }\r
+\r
+       CmFreeAccountObject(hWnd, a);\r
+}\r
+\r
+// アカウントのエクスポート\r
+void CmExportAccount(HWND hWnd, wchar_t *account_name)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       CM_ACCOUNT *a;\r
+       wchar_t *filename;\r
+       // 引数チェック\r
+       if (hWnd == NULL || account_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // アカウント情報を取得\r
+       a = CmGetExistAccountObject(hWnd, account_name);\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ファイル名を決定\r
+       UniFormat(tmp, sizeof(tmp), L"%s.uvpn", account_name);\r
+       UniSafeFileName(tmp);\r
+\r
+       filename = SaveDlg(hWnd, _UU("CM_ACCOUNT_SETTING_FILE"),\r
+               _UU("CM_ACCOUNT_SAVE_TITLE"), tmp, L".uvpn");\r
+\r
+       if (filename != NULL)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT t;\r
+               BUF *b;\r
+               BUF *b2;\r
+               wchar_t tmp[MAX_SIZE];\r
+               UCHAR *buf;\r
+               UINT buf_size;\r
+               UCHAR bom[] = {0xef, 0xbb, 0xbf, };\r
+\r
+               Zero(&t, sizeof(t));\r
+               t.ClientOption = a->ClientOption;\r
+               t.ClientAuth = a->ClientAuth;\r
+               t.StartupAccount = a->Startup;\r
+               t.CheckServerCert = a->CheckServerCert;\r
+               t.ServerCert = a->ServerCert;\r
+               t.ClientOption->FromAdminPack = false;\r
+\r
+               b = CiAccountToCfg(&t);\r
+\r
+               UniStrCpy(tmp, sizeof(tmp), filename);\r
+               b2 = NewBuf();\r
+\r
+               WriteBuf(b2, bom, sizeof(bom));\r
+\r
+               // ヘッダ部分を付加する\r
+               buf_size = CalcUniToUtf8(_UU("CM_ACCOUNT_FILE_BANNER"));\r
+               buf = ZeroMalloc(buf_size + 32);\r
+               UniToUtf8(buf, buf_size, _UU("CM_ACCOUNT_FILE_BANNER"));\r
+\r
+               WriteBuf(b2, buf, StrLen((char *)buf));\r
+               WriteBuf(b2, b->Buf, b->Size);\r
+               SeekBuf(b2, 0, 0);\r
+\r
+               FreeBuf(b);\r
+\r
+               if (DumpBufW(b2, tmp) == false)\r
+               {\r
+                       MsgBox(hWnd, MB_ICONSTOP, _UU("CM_FAILED_TO_SAVE_FILE"));\r
+               }\r
+\r
+               Free(filename);\r
+               FreeBuf(b2);\r
+               Free(buf);\r
+       }\r
+\r
+       CmFreeAccountObject(hWnd, a);\r
+}\r
+\r
+// アカウントのインポートメイン処理\r
+void CmImportAccountMain(HWND hWnd, wchar_t *filename)\r
+{\r
+       CmImportAccountMainEx(hWnd, filename, false);\r
+}\r
+void CmImportAccountMainEx(HWND hWnd, wchar_t *filename, bool overwrite)\r
+{\r
+       wchar_t name[MAX_SIZE];\r
+       wchar_t tmp[MAX_SIZE];\r
+       BUF *b;\r
+       RPC_CLIENT_CREATE_ACCOUNT *t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || filename == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniStrCpy(tmp, sizeof(tmp), filename);\r
+\r
+       b = ReadDumpW(tmp);\r
+       if (b == NULL)\r
+       {\r
+               MsgBox(hWnd, MB_ICONSTOP, _UU("CM_FAILED_TO_OPEN_FILE"));\r
+               return;\r
+       }\r
+\r
+       t = CiCfgToAccount(b);\r
+       if (t == NULL)\r
+       {\r
+               FreeBuf(b);\r
+               MsgBox(hWnd, MB_ICONEXCLAMATION, _UU("CM_ACCOUNT_PARSE_FAILED"));\r
+               return;\r
+       }\r
+\r
+       if (overwrite)\r
+       {\r
+               // すでに同一名が存在する場合は削除する\r
+               if (LvSearchStr(hWnd, L_ACCOUNT, 0, t->ClientOption->AccountName) != INFINITE)\r
+               {\r
+                       RPC_CLIENT_DELETE_ACCOUNT d;\r
+                       RPC_CLIENT_GET_ACCOUNT get;\r
+                       HWND h = cm->hEasyWnd == NULL ? hWnd : cm->hEasyWnd;\r
+\r
+                       Zero(&d, sizeof(d));\r
+                       UniStrCpy(d.AccountName, sizeof(d.AccountName), t->ClientOption->AccountName);\r
+\r
+                       Zero(&get, sizeof(get));\r
+                       UniStrCpy(get.AccountName, sizeof(get.AccountName), t->ClientOption->AccountName);\r
+                       if (CcGetAccount(cm->Client, &get) == ERR_NO_ERROR)\r
+                       {\r
+                               // すでに存在する同一名のアカウント情報を取得して\r
+                               // クライアントオプションのうちいくつかの情報を継承する\r
+                               if (get.ClientOption != NULL && get.ClientAuth != NULL)\r
+                               {\r
+                                       CLIENT_OPTION *old_option = get.ClientOption;\r
+                                       CLIENT_AUTH *old_auth = get.ClientAuth;\r
+\r
+                                       // 接続パラメータの継承\r
+                                       t->ClientOption->ProxyType = old_option->ProxyType;\r
+                                       StrCpy(t->ClientOption->ProxyName, sizeof(t->ClientOption->ProxyName),\r
+                                               old_option->ProxyName);\r
+                                       t->ClientOption->ProxyPort = old_option->ProxyPort;\r
+                                       StrCpy(t->ClientOption->ProxyUsername, sizeof(t->ClientOption->ProxyUsername),\r
+                                               old_option->ProxyUsername);\r
+                                       StrCpy(t->ClientOption->ProxyPassword, sizeof(t->ClientOption->ProxyPassword),\r
+                                               old_option->ProxyPassword);\r
+                                       t->ClientOption->NumRetry = old_option->NumRetry;\r
+                                       t->ClientOption->RetryInterval = old_option->RetryInterval;\r
+                                       t->ClientOption->MaxConnection = old_option->MaxConnection;\r
+                                       t->ClientOption->UseEncrypt = old_option->UseEncrypt;\r
+                                       t->ClientOption->UseCompress = old_option->UseCompress;\r
+                                       t->ClientOption->HalfConnection = old_option->HalfConnection;\r
+                                       t->ClientOption->NoRoutingTracking = old_option->NoRoutingTracking;\r
+                                       StrCpy(t->ClientOption->DeviceName, sizeof(t->ClientOption->DeviceName),\r
+                                               old_option->DeviceName);\r
+                                       t->ClientOption->AdditionalConnectionInterval = old_option->AdditionalConnectionInterval;\r
+                                       t->ClientOption->ConnectionDisconnectSpan = old_option->ConnectionDisconnectSpan;\r
+                                       t->ClientOption->HideStatusWindow = old_option->HideStatusWindow;\r
+                                       t->ClientOption->RequireMonitorMode = old_option->RequireMonitorMode;\r
+                                       t->ClientOption->RequireBridgeRoutingMode = old_option->RequireBridgeRoutingMode;\r
+                                       t->ClientOption->DisableQoS = old_option->DisableQoS;\r
+                                       t->ClientOption->NoTls1 = old_option->NoTls1;\r
+\r
+                                       // 認証データの継承\r
+                                       CiFreeClientAuth(t->ClientAuth);\r
+                                       t->ClientAuth = CopyClientAuth(old_auth);\r
+\r
+                                       // その他の設定\r
+                                       t->StartupAccount = get.StartupAccount;\r
+                                       t->CheckServerCert = get.CheckServerCert;\r
+                                       if (t->ServerCert != NULL)\r
+                                       {\r
+                                               FreeX(t->ServerCert);\r
+                                       }\r
+                                       t->ServerCert = NULL;\r
+                                       if (get.ServerCert != NULL)\r
+                                       {\r
+                                               t->ServerCert = CloneX(get.ServerCert);\r
+                                       }\r
+                                       Copy(t->ShortcutKey, get.ShortcutKey, sizeof(t->ShortcutKey));\r
+                               }\r
+\r
+                               CiFreeClientGetAccount(&get);\r
+                       }\r
+\r
+                       if (CALL(h, CcDeleteAccount(cm->Client, &d)) == false)\r
+                       {\r
+                               CiFreeClientCreateAccount(t);\r
+                               Free(t);\r
+                               return;\r
+                       }\r
+\r
+                       CmRefreshAccountList(hWnd);\r
+               }\r
+       }\r
+\r
+       CmGenerateImportName(hWnd, name, sizeof(name), t->ClientOption->AccountName);\r
+       UniStrCpy(t->ClientOption->AccountName, sizeof(t->ClientOption->AccountName), name);\r
+\r
+       if (overwrite)\r
+       {\r
+               t->ClientOption->FromAdminPack = true;\r
+       }\r
+\r
+       CALL(hWnd, CcCreateAccount(cm->Client, t));\r
+\r
+       CiFreeClientCreateAccount(t);\r
+       Free(t);\r
+\r
+       FreeBuf(b);\r
+\r
+       if (overwrite)\r
+       {\r
+               // VPN 接続を開始する\r
+               CmConnect(hWnd, name);\r
+       }\r
+\r
+       //MsgBoxEx(hWnd, MB_ICONINFORMATION, _UU("CM_IMPORT_MESSAGE"), filename, name);\r
+}\r
+\r
+// アカウントのインポート\r
+void CmImportAccount(HWND hWnd)\r
+{\r
+       wchar_t *filename;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ファイルを開く\r
+       filename = OpenDlg(hWnd, _UU("CM_ACCOUNT_SETTING_FILE"), _UU("CM_ACCOUNT_OPEN_TITLE"));\r
+       if (filename == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniStrCpy(tmp, sizeof(tmp), filename);\r
+       Free(filename);\r
+\r
+       CmImportAccountMain(hWnd, tmp);\r
+}\r
+\r
+// アカウントのコピーの作成\r
+void CmCopyAccount(HWND hWnd, wchar_t *account_name)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       CM_ACCOUNT *a;\r
+       RPC_CLIENT_CREATE_ACCOUNT c;\r
+       // 引数チェック\r
+       if (hWnd == NULL || account_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CmGenerateCopyName(hWnd, tmp, sizeof(tmp), account_name);\r
+\r
+       // アカウント情報を取得\r
+       a = CmGetExistAccountObject(hWnd, account_name);\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // アカウント名を変更\r
+       UniStrCpy(a->ClientOption->AccountName, sizeof(a->ClientOption->AccountName), tmp);\r
+\r
+       // 書き込み\r
+       Zero(&c, sizeof(c));\r
+       c.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       Copy(c.ClientOption, a->ClientOption, sizeof(CLIENT_OPTION));\r
+       c.ClientAuth = CopyClientAuth(a->ClientAuth);\r
+       if (a->ServerCert)\r
+       {\r
+               c.ServerCert = CloneX(a->ServerCert);\r
+       }\r
+       c.CheckServerCert = a->CheckServerCert;\r
+       c.StartupAccount = false;               // スタートアップ属性はコピーしない\r
+\r
+       CALL(hWnd, CcCreateAccount(cm->Client, &c));\r
+       CiFreeClientCreateAccount(&c);\r
+\r
+       CmFreeAccountObject(hWnd, a);\r
+}\r
+\r
+// 仮想 LAN カード名ダイアログ更新\r
+void CmNewVLanDlgUpdate(HWND hWnd)\r
+{\r
+       bool ok = true;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetTxtA(hWnd, E_NAME, tmp, sizeof(tmp));\r
+       if (IsSafeStr(tmp) == false)\r
+       {\r
+               ok = false;\r
+       }\r
+       Trim(tmp);\r
+       if (StrLen(tmp) == 0)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// 仮想 LAN カード名決定ダイアログプロシージャ\r
+UINT CmNewVLanDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       char *tmp = (char *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               LimitText(hWnd, E_NAME, cm->Client->Win9x ? MAX_DEVICE_NAME_LEN_9X : MAX_DEVICE_NAME_LEN);\r
+               FormatText(hWnd, S_INFO, cm->Client->Win9x ? MAX_DEVICE_NAME_LEN_9X : MAX_DEVICE_NAME_LEN);\r
+               CmNewVLanDlgUpdate(hWnd);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       if (cm->Client->Win9x)\r
+                       {\r
+                               // Windows 9x の場合、確認メッセージを出す\r
+                               if (MsgBox(hWnd, MB_ICONQUESTION | MB_OKCANCEL, _UU("CM_9X_VLAN_INSTALL")) == IDCANCEL)\r
+                               {\r
+                                       break;\r
+                               }\r
+                       }\r
+                       GetTxtA(hWnd, E_NAME, tmp, (cm->Client->Win9x ? MAX_DEVICE_NAME_LEN_9X : MAX_DEVICE_NAME_LEN) + 1);\r
+                       Trim(tmp);\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_NAME:\r
+                       CmNewVLanDlgUpdate(hWnd);\r
+                       break;\r
+\r
+               case R_USE_DISCONNECT:\r
+                       if (IsChecked(hWnd, R_USE_DISCONNECT))\r
+                       {\r
+                               FocusEx(hWnd, E_DISCONNECT_SPAN);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 新しい仮想 LAN カード名を決定するダイアログ\r
+char *CmNewVLanDlg(HWND hWnd)\r
+{\r
+       char tmp[MAX_DEVICE_NAME_LEN + 1];\r
+\r
+       if (Dialog(hWnd, D_CM_NEW_VLAN, CmNewVLanDlgProc, tmp) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return CopyStr(tmp);\r
+}\r
+\r
+// 詳細設定ダイアログ更新\r
+void CmDetailDlgUpdate(HWND hWnd, CM_ACCOUNT *a)\r
+{\r
+       bool ok = true;\r
+       bool locked;\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       locked = a->LockMode;\r
+\r
+       if (a->LinkMode || a->NatMode)\r
+       {\r
+               Disable(hWnd, R_NO_ROUTING);\r
+       }\r
+       else\r
+       {\r
+               if (cm->Client->Unix)\r
+               {\r
+                       Disable(hWnd, R_NO_ROUTING);\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, E_DISCONNECT_SPAN, IsChecked(hWnd, R_USE_DISCONNECT));\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+\r
+       if (locked)\r
+       {\r
+               Disable(hWnd, C_NUM_TCP);\r
+               Disable(hWnd, S_STATIC5);\r
+               Disable(hWnd, S_STATIC8);\r
+               Disable(hWnd, E_INTERVAL);\r
+               Disable(hWnd, S_STATIC9);\r
+               Disable(hWnd, E_DISCONNECT_SPAN);\r
+               Disable(hWnd, S_STATIC10);\r
+               Disable(hWnd, S_STATIC11);\r
+               Disable(hWnd, R_USE_DISCONNECT);\r
+               Disable(hWnd, R_USE_HALF_CONNECTION);\r
+               Disable(hWnd, R_DISABLE_QOS);\r
+               Disable(hWnd, R_USE_ENCRYPT);\r
+               Disable(hWnd, R_USE_COMPRESS);\r
+               Disable(hWnd, R_BRIDGE);\r
+               Disable(hWnd, R_MONITOR);\r
+               Disable(hWnd, R_NO_ROUTING);\r
+       }\r
+}\r
+\r
+// 詳細設定ダイアログプロシージャ\r
+UINT CmDetailDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       CM_ACCOUNT *a = (CM_ACCOUNT *)param;\r
+       UINT i;\r
+       UINT num;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // TCP コネクション本数\r
+               for (i = 1;i <= MAX_TCP_CONNECTION;i++)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), L"%u", i);\r
+                       CbAddStr(hWnd, C_NUM_TCP, tmp, i);\r
+               }\r
+               CbSelect(hWnd, C_NUM_TCP, a->ClientOption->MaxConnection);\r
+\r
+               // コネクション確立間隔\r
+               SetInt(hWnd, E_INTERVAL, a->ClientOption->AdditionalConnectionInterval);\r
+\r
+               // 寿命\r
+               SetIntEx(hWnd, E_DISCONNECT_SPAN, a->ClientOption->ConnectionDisconnectSpan);\r
+               Check(hWnd, R_USE_DISCONNECT, a->ClientOption->ConnectionDisconnectSpan != 0);\r
+               Check(hWnd, R_USE_HALF_CONNECTION, a->ClientOption->HalfConnection);\r
+               Check(hWnd, R_USE_ENCRYPT, a->ClientOption->UseEncrypt);\r
+               Check(hWnd, R_USE_COMPRESS, a->ClientOption->UseCompress);\r
+               Check(hWnd, R_NO_ROUTING, a->ClientOption->NoRoutingTracking);\r
+               Check(hWnd, R_DISABLE_QOS, a->ClientOption->DisableQoS);\r
+\r
+               // 接続モードの選択\r
+               if (a->LinkMode == false)\r
+               {\r
+                       Check(hWnd, R_BRIDGE, a->ClientOption->RequireBridgeRoutingMode);\r
+                       Check(hWnd, R_MONITOR, a->ClientOption->RequireMonitorMode);\r
+               }\r
+               else\r
+               {\r
+                       Check(hWnd, R_BRIDGE, true);\r
+                       Check(hWnd, R_MONITOR, false);\r
+\r
+                       SetText(hWnd, S_MODE, _UU("CM_DETAIL_MODE_LINK_STR"));\r
+                       Disable(hWnd, R_BRIDGE);\r
+                       Disable(hWnd, R_MONITOR);\r
+               }\r
+\r
+               CmDetailDlgUpdate(hWnd, a);\r
+               Focus(hWnd, IDOK);\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       if (IsChecked(hWnd, R_USE_DISCONNECT) && GetInt(hWnd, E_DISCONNECT_SPAN) == 0)\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_NO_DISCONNECT_SPAN"));\r
+                               FocusEx(hWnd, E_DISCONNECT_SPAN);\r
+                               break;\r
+                       }\r
+                       num = GetInt(hWnd, C_NUM_TCP);\r
+                       if (num == 0)\r
+                       {\r
+                               break;\r
+                       }\r
+                       if (num == 1 && IsChecked(hWnd, R_USE_HALF_CONNECTION))\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_HALF_MSG"));\r
+                               Focus(hWnd, C_NUM_TCP);\r
+                               break;\r
+                       }\r
+                       if (GetInt(hWnd, E_INTERVAL) < 1)\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_TOO_SMALL_INTERVAL"));\r
+                               Focus(hWnd, E_INTERVAL);\r
+                               break;\r
+                       }\r
+\r
+                       a->ClientOption->MaxConnection = num;\r
+                       a->ClientOption->AdditionalConnectionInterval = GetInt(hWnd, E_INTERVAL);\r
+                       if (IsChecked(hWnd, R_USE_DISCONNECT) == false)\r
+                       {\r
+                               a->ClientOption->ConnectionDisconnectSpan = 0;\r
+                       }\r
+                       else\r
+                       {\r
+                               a->ClientOption->ConnectionDisconnectSpan = GetInt(hWnd, E_DISCONNECT_SPAN);\r
+                       }\r
+                       a->ClientOption->HalfConnection = IsChecked(hWnd, R_USE_HALF_CONNECTION);\r
+                       a->ClientOption->UseEncrypt = IsChecked(hWnd, R_USE_ENCRYPT);\r
+                       a->ClientOption->UseCompress = IsChecked(hWnd, R_USE_COMPRESS);\r
+                       a->ClientOption->NoRoutingTracking = IsChecked(hWnd, R_NO_ROUTING);\r
+                       a->ClientOption->DisableQoS = IsChecked(hWnd, R_DISABLE_QOS);\r
+\r
+                       if (a->LinkMode)\r
+                       {\r
+                               a->ClientOption->RequireBridgeRoutingMode = true;\r
+                               a->ClientOption->RequireMonitorMode = false;\r
+                       }\r
+                       else\r
+                       {\r
+                               a->ClientOption->RequireBridgeRoutingMode = IsChecked(hWnd, R_BRIDGE);\r
+                               a->ClientOption->RequireMonitorMode = IsChecked(hWnd, R_MONITOR);\r
+                       }\r
+\r
+                       EndDialog(hWnd, true);\r
+\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case C_NUM_TCP:\r
+               case E_INTERVAL:\r
+               case E_DISCONNECT_SPAN:\r
+               case R_USE_DISCONNECT:\r
+               case R_USE_HALF_CONNECTION:\r
+                       CmDetailDlgUpdate(hWnd, a);\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 詳細設定ダイアログ\r
+bool CmDetailDlg(HWND hWnd, CM_ACCOUNT *a)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return Dialog(hWnd, D_CM_DETAIL, CmDetailDlgProc, a);\r
+}\r
+\r
+// アカウント編集ダイアログプロシージャ更新\r
+void CmEditAccountDlgUpdate(HWND hWnd, CM_ACCOUNT *a)\r
+{\r
+       bool ok = true;\r
+       char str[MAX_SIZE];\r
+       bool locked;\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       locked = a->LockMode;\r
+\r
+       if (a->Inited == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (a->EditMode)\r
+       {\r
+               Disable(hWnd, E_ACCOUNT_NAME);\r
+       }\r
+\r
+       // 接続設定名\r
+       GetTxt(hWnd, E_ACCOUNT_NAME, a->ClientOption->AccountName, sizeof(a->ClientOption->AccountName));\r
+       UniTrim(a->ClientOption->AccountName);\r
+\r
+       // ホスト名\r
+       GetTxtA(hWnd, E_HOSTNAME, a->ClientOption->Hostname, sizeof(a->ClientOption->Hostname));\r
+       Trim(a->ClientOption->Hostname);\r
+\r
+       // ポート番号\r
+       a->ClientOption->Port = GetInt(hWnd, C_PORT);\r
+\r
+       // HUB 名\r
+       GetTxtA(hWnd,C_HUBNAME, a->ClientOption->HubName, sizeof(a->ClientOption->HubName));\r
+\r
+       // プロキシの種類\r
+       a->ClientOption->ProxyType = PROXY_DIRECT;\r
+       if (IsChecked(hWnd, R_HTTPS))\r
+       {\r
+               a->ClientOption->ProxyType = PROXY_HTTP;\r
+       }\r
+       if (IsChecked(hWnd, R_SOCKS))\r
+       {\r
+               a->ClientOption->ProxyType = PROXY_SOCKS;\r
+       }\r
+\r
+       // サーバー証明書検証\r
+       a->CheckServerCert = IsChecked(hWnd, R_CHECK_CERT);\r
+\r
+       if (a->NatMode)\r
+       {\r
+               Disable(hWnd, R_CHECK_CERT);\r
+               Disable(hWnd, B_TRUST);\r
+       }\r
+\r
+       if (a->HideTrustCert)\r
+       {\r
+               Disable(hWnd, B_TRUST);\r
+       }\r
+\r
+       // デバイス名\r
+       StrCpy(a->ClientOption->DeviceName, sizeof(a->ClientOption->DeviceName), "");\r
+       if (LvIsSelected(hWnd, L_VLAN))\r
+       {\r
+               wchar_t *s = LvGetStr(hWnd, L_VLAN, LvGetSelected(hWnd, L_VLAN), 0);\r
+               if (s != NULL)\r
+               {\r
+                       char str[MAX_SIZE];\r
+                       UniToStr(str, sizeof(str), s);\r
+                       CmPrintNameToVLanName(a->ClientOption->DeviceName, sizeof(a->ClientOption->DeviceName), str);\r
+                       Free(s);\r
+               }\r
+       }\r
+\r
+       // ユーザー認証\r
+       a->ClientAuth->AuthType = CbGetSelect(hWnd, C_TYPE);\r
+       GetTxtA(hWnd, E_USERNAME, a->ClientAuth->Username, sizeof(a->ClientAuth->Username));\r
+       Trim(a->ClientAuth->Username);\r
+       switch (a->ClientAuth->AuthType)\r
+       {\r
+       case CLIENT_AUTHTYPE_PASSWORD:\r
+               // パスワード認証\r
+               GetTxtA(hWnd, E_PASSWORD, str, sizeof(str));\r
+               if (StrCmp(str, HIDDEN_PASSWORD) != 0)\r
+               {\r
+                       HashPassword(a->ClientAuth->HashedPassword, a->ClientAuth->Username, str);\r
+               }\r
+               break;\r
+       case CLIENT_AUTHTYPE_PLAIN_PASSWORD:\r
+               // 平文パスワード認証\r
+               GetTxtA(hWnd, E_PASSWORD, str, sizeof(str));\r
+               if (StrCmp(str, HIDDEN_PASSWORD) != 0)\r
+               {\r
+                       StrCpy(a->ClientAuth->PlainPassword, sizeof(a->ClientAuth->PlainPassword), str);\r
+               }\r
+               break;\r
+       }\r
+\r
+       // 再接続オプション\r
+       if ((a->LinkMode || a->NatMode) || a->ClientAuth->AuthType == CLIENT_AUTHTYPE_SECURE)\r
+       {\r
+               Disable(hWnd, R_RETRY);\r
+       }\r
+       else\r
+       {\r
+               Enable(hWnd, R_RETRY);\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_RETRY) == false)\r
+       {\r
+               a->ClientOption->NumRetry = 0;\r
+       }\r
+       else\r
+       {\r
+               if (IsChecked(hWnd, R_INFINITE))\r
+               {\r
+                       a->ClientOption->NumRetry = INFINITE;\r
+               }\r
+               else\r
+               {\r
+                       a->ClientOption->NumRetry = GetInt(hWnd, E_RETRY_NUM);\r
+               }\r
+       }\r
+       a->ClientOption->RetryInterval = GetInt(hWnd, E_RETRY_SPAN);\r
+\r
+       a->ClientOption->NoTls1 = IsChecked(hWnd, R_NOTLS1);\r
+\r
+       // 情報判定\r
+       if (UniStrLen(a->ClientOption->AccountName) == 0 && a->NatMode == false)\r
+       {\r
+               ok = false;\r
+       }\r
+       if (StrLen(a->ClientOption->Hostname) == 0)\r
+       {\r
+               ok = false;\r
+       }\r
+       if (a->ClientOption->Port == 0 || a->ClientOption->Port >= 65536)\r
+       {\r
+               ok = false;\r
+       }\r
+       if (StrLen(a->ClientOption->HubName) == 0)\r
+       {\r
+               ok = false;\r
+       }\r
+       if (StrLen(a->ClientAuth->Username) == 0)\r
+       {\r
+               ok = false;\r
+       }\r
+       if (a->ClientAuth->AuthType == CLIENT_AUTHTYPE_CERT)\r
+       {\r
+               if (a->ClientAuth->ClientK == NULL || a->ClientAuth->ClientX == NULL)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+       if (a->ClientAuth->AuthType == CLIENT_AUTHTYPE_SECURE)\r
+       {\r
+               if (IsEmptyStr(a->ClientAuth->SecurePrivateKeyName) || IsEmptyStr(a->ClientAuth->SecurePublicCertName))\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       // 表示更新\r
+       if (IsChecked(hWnd, R_RETRY) && IsEnable(hWnd, R_RETRY))\r
+       {\r
+               if (a->LinkMode == false && a->NatMode == false)\r
+               {\r
+                       Enable(hWnd, R_INFINITE);\r
+                       Enable(hWnd, E_RETRY_SPAN);\r
+                       Enable(hWnd, S_RETRY_SPAN_1);\r
+                       Enable(hWnd, S_RETRY_SPAN_2);\r
+               }\r
+               else\r
+               {\r
+                       Disable(hWnd, R_INFINITE);\r
+                       Disable(hWnd, E_RETRY_SPAN);\r
+                       Disable(hWnd, S_RETRY_SPAN_1);\r
+                       Disable(hWnd, S_RETRY_SPAN_2);\r
+               }\r
+               if (IsChecked(hWnd, R_INFINITE) == false)\r
+               {\r
+                       Enable(hWnd, E_RETRY_NUM);\r
+                       Enable(hWnd, S_RETRY_NUM_1);\r
+                       Enable(hWnd, S_RETRY_NUM_2);\r
+                       if (GetInt(hWnd, E_RETRY_NUM) == 0)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       Disable(hWnd, E_RETRY_NUM);\r
+                       Disable(hWnd, S_RETRY_NUM_1);\r
+                       Disable(hWnd, S_RETRY_NUM_2);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               Disable(hWnd, E_RETRY_NUM);\r
+               Disable(hWnd, E_RETRY_SPAN);\r
+               Disable(hWnd, R_INFINITE);\r
+               Disable(hWnd, S_RETRY_NUM_1);\r
+               Disable(hWnd, S_RETRY_NUM_2);\r
+               Disable(hWnd, S_RETRY_SPAN_1);\r
+               Disable(hWnd, S_RETRY_SPAN_2);\r
+       }\r
+\r
+       if (a->NatMode == false)\r
+       {\r
+               if (a->ServerCert == NULL)\r
+               {\r
+                       SetText(hWnd, B_SERVER_CERT, _UU("CM_SERVER_CERT_1"));\r
+                       Disable(hWnd, B_VIEW_SERVER_CERT);\r
+               }\r
+               else\r
+               {\r
+                       SetText(hWnd, B_SERVER_CERT, _UU("CM_SERVER_CERT_2"));\r
+                       Enable(hWnd, B_VIEW_SERVER_CERT);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               Disable(hWnd, B_VIEW_SERVER_CERT);\r
+               Disable(hWnd, B_SERVER_CERT);\r
+       }\r
+\r
+       if (a->ClientAuth->AuthType == CLIENT_AUTHTYPE_CERT || a->ClientAuth->AuthType == CLIENT_AUTHTYPE_SECURE)\r
+       {\r
+               wchar_t tmp[MAX_SIZE * 2];\r
+               wchar_t issuer[MAX_SIZE];\r
+               wchar_t subject[MAX_SIZE];\r
+               wchar_t expires[MAX_SIZE];\r
+\r
+               SetIcon(hWnd, S_CERT, (a->ClientAuth->AuthType == CLIENT_AUTHTYPE_CERT) ? ICO_CERT : ICO_SECURE);\r
+\r
+               Hide(hWnd, S_PASSWORD);\r
+               Hide(hWnd, E_PASSWORD);\r
+               if (a->ClientAuth->AuthType == CLIENT_AUTHTYPE_CERT)\r
+               {\r
+                       if (a->ClientAuth->ClientX != NULL)\r
+                       {\r
+                               Enable(hWnd, B_VIEW_CLIENT_CERT);\r
+                               SetText(hWnd, B_REGIST_CLIENT_CERT, _UU("CM_CLIENT_CERT_2"));\r
+                               GetPrintNameFromName(issuer, sizeof(issuer), a->ClientAuth->ClientX->issuer_name);\r
+                               GetPrintNameFromName(subject, sizeof(subject), a->ClientAuth->ClientX->subject_name);\r
+                               GetDateStrEx64(expires, sizeof(expires), SystemToLocal64(a->ClientAuth->ClientX->notAfter), NULL);\r
+                               UniFormat(tmp, sizeof(tmp), _UU("CM_CERT_INFO"), subject, issuer, expires);\r
+                       }\r
+                       else\r
+                       {\r
+                               Disable(hWnd, B_VIEW_CLIENT_CERT);\r
+                               SetText(hWnd, B_REGIST_CLIENT_CERT, _UU("CM_CLIENT_CERT_1"));\r
+                               UniStrCpy(tmp, sizeof(tmp), _UU("CM_NO_CERT"));\r
+                       }\r
+                       SetText(hWnd, B_VIEW_CLIENT_CERT, _UU("CM_VIEW_CLIENT_CERT"));\r
+\r
+                       Enable(hWnd, B_REGIST_CLIENT_CERT);\r
+               }\r
+               else\r
+               {\r
+                       if (IsEmptyStr(a->ClientAuth->SecurePrivateKeyName) || IsEmptyStr(a->ClientAuth->SecurePublicCertName))\r
+                       {\r
+                               UniStrCpy(tmp, sizeof(tmp), _UU("CM_NO_SECURE"));\r
+                       }\r
+                       else\r
+                       {\r
+                               UniFormat(tmp, sizeof(tmp), _UU("CM_CERT_SECURE_INFO"),\r
+                                       a->ClientAuth->SecurePublicCertName, a->ClientAuth->SecurePrivateKeyName);\r
+                       }\r
+\r
+                       SetText(hWnd, B_VIEW_CLIENT_CERT, _UU("CM_SELECT_SECURE_DEVICE"));\r
+                       SetText(hWnd, B_REGIST_CLIENT_CERT, _UU("CM_SELECT_CERT_INCARD"));\r
+                       Enable(hWnd, B_VIEW_CLIENT_CERT);\r
+\r
+                       if (SmGetCurrentSecureIdFromReg() == 0)\r
+                       {\r
+                               Disable(hWnd, B_REGIST_CLIENT_CERT);\r
+                       }\r
+                       else\r
+                       {\r
+                               Enable(hWnd, B_REGIST_CLIENT_CERT);\r
+                       }\r
+               }\r
+               SetText(hWnd, S_CERT_INFO, tmp);\r
+               Show(hWnd, S_CERT);\r
+               Show(hWnd, S_CERT_INFO);\r
+               Show(hWnd, B_VIEW_CLIENT_CERT);\r
+               Show(hWnd, B_REGIST_CLIENT_CERT);\r
+       }\r
+       else\r
+       {\r
+               if (a->ClientAuth->AuthType == CLIENT_AUTHTYPE_ANONYMOUS)\r
+               {\r
+                       Hide(hWnd, S_PASSWORD);\r
+                       Hide(hWnd, E_PASSWORD);\r
+               }\r
+               else\r
+               {\r
+                       Show(hWnd, S_PASSWORD);\r
+                       Show(hWnd, E_PASSWORD);\r
+               }\r
+               Hide(hWnd, S_CERT);\r
+               Hide(hWnd, S_CERT_INFO);\r
+               Hide(hWnd, B_VIEW_CLIENT_CERT);\r
+               Hide(hWnd, B_REGIST_CLIENT_CERT);\r
+       }\r
+\r
+       if (a->ClientOption->ProxyType != PROXY_DIRECT)\r
+       {\r
+               Enable(hWnd, B_PROXY_CONFIG);\r
+               if (StrLen(a->ClientOption->ProxyName) == 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+               if (a->ClientOption->ProxyPort == 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               Disable(hWnd, B_PROXY_CONFIG);\r
+       }\r
+\r
+       if (a->ClientAuth->AuthType == CLIENT_AUTHTYPE_PASSWORD)\r
+       {\r
+               bool b = true;\r
+\r
+               if (ok == false)\r
+               {\r
+                       b = false;\r
+               }\r
+\r
+               if (a->LinkMode == false && a->NatMode == false)\r
+               {\r
+                       SetEnable(hWnd, B_CHANGE_PASSWORD, b);\r
+                       SetEnable(hWnd, S_CHANGE_PASSWORD, b);\r
+                       Show(hWnd, B_CHANGE_PASSWORD);\r
+                       Show(hWnd, S_CHANGE_PASSWORD);\r
+               }\r
+               else\r
+               {\r
+                       Hide(hWnd, B_CHANGE_PASSWORD);\r
+                       Hide(hWnd, S_CHANGE_PASSWORD);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               Hide(hWnd, B_CHANGE_PASSWORD);\r
+               Hide(hWnd, S_CHANGE_PASSWORD);\r
+       }\r
+\r
+       if ((StrLen(a->ClientOption->DeviceName) == 0) && (a->LinkMode == false && a->NatMode == false))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (a->LinkMode || a->NatMode)\r
+       {\r
+               Disable(hWnd, L_VLAN);\r
+       }\r
+\r
+       if (a->EditMode == false)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               GetTxtA(hWnd, E_HOSTNAME, tmp, sizeof(tmp));\r
+               Trim(tmp);\r
+\r
+               if (StartWith(tmp, "127.") || (StrCmpi(tmp, "localhost") == 0))\r
+               {\r
+                       if (a->Flag1 == false)\r
+                       {\r
+                               a->Flag1 = true;\r
+                               a->ClientOption->UseEncrypt = a->ClientOption->UseCompress = false;\r
+                               a->ClientOption->MaxConnection = 1;\r
+                       }\r
+               }\r
+       }\r
+\r
+       a->ClientOption->HideStatusWindow = IsChecked(hWnd, R_HIDE);\r
+       a->ClientOption->HideNicInfoWindow = IsChecked(hWnd, R_HIDE2);\r
+\r
+       if (locked)\r
+       {\r
+               SetEnable(hWnd, E_HOSTNAME, false);\r
+               SetEnable(hWnd, C_PORT, false);\r
+               SetEnable(hWnd, C_HUBNAME, false);\r
+               SetEnable(hWnd, S_STATIC2, false);\r
+               SetEnable(hWnd, S_STATIC3, false);\r
+               SetEnable(hWnd, S_STATIC4, false);\r
+               SetEnable(hWnd, S_STATIC5, false);\r
+               SetEnable(hWnd, S_STATIC66, false);\r
+               SetEnable(hWnd, S_STATIC7, false);\r
+               SetEnable(hWnd, S_STATIC11, false);\r
+               SetEnable(hWnd, R_CHECK_CERT, false);\r
+               SetEnable(hWnd, B_TRUST, false);\r
+               SetEnable(hWnd, B_SERVER_CERT, false);\r
+               SetEnable(hWnd, B_VIEW_SERVER_CERT, false);\r
+               SetEnable(hWnd, R_RETRY, false);\r
+               SetEnable(hWnd, S_RETRY_NUM_1, false);\r
+               SetEnable(hWnd, E_RETRY_NUM, false);\r
+               SetEnable(hWnd, S_RETRY_NUM_2, false);\r
+               SetEnable(hWnd, S_RETRY_SPAN_1, false);\r
+               SetEnable(hWnd, E_RETRY_SPAN, false);\r
+               SetEnable(hWnd, S_RETRY_SPAN_2, false);\r
+               SetEnable(hWnd, R_INFINITE, false);\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// アカウント編集ダイアログ初期化\r
+void CmEditAccountDlgInit(HWND hWnd, CM_ACCOUNT *a)\r
+{\r
+       RPC_CLIENT_ENUM_VLAN v;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (a->LockMode)\r
+       {\r
+               SetText(hWnd, S_STATIC1, _UU("CM_EASY_ACCOUNT_WARNING"));\r
+       }\r
+\r
+       // 接続設定名\r
+       if (a->EditMode || a->NatMode)\r
+       {\r
+               Disable(hWnd, E_ACCOUNT_NAME);\r
+       }\r
+\r
+       if (a->NatMode || a->LinkMode)\r
+       {\r
+               Hide(hWnd, R_HIDE);\r
+               Hide(hWnd, R_HIDE2);\r
+       }\r
+\r
+       Check(hWnd, R_HIDE, a->ClientOption->HideStatusWindow);\r
+       Check(hWnd, R_HIDE2, a->ClientOption->HideNicInfoWindow);\r
+\r
+       if (a->NatMode)\r
+       {\r
+               Hide(hWnd, E_ACCOUNT_NAME);\r
+               Hide(hWnd, S_ACCOUNT_NAME);\r
+       }\r
+\r
+       if ((cm != NULL && cm->server_name != NULL) || a->LinkMode)\r
+       {\r
+               Hide(hWnd, B_IE);\r
+       }\r
+\r
+       SetText(hWnd, E_ACCOUNT_NAME, a->ClientOption->AccountName);\r
+\r
+       // ホスト名\r
+       SetTextA(hWnd, E_HOSTNAME, a->ClientOption->Hostname);\r
+       StrCpy(a->old_server_name, sizeof(a->old_server_name), a->ClientOption->Hostname);\r
+\r
+       // ポート番号\r
+       CbSetHeight(hWnd, C_PORT, 18);\r
+       CbAddStr(hWnd, C_PORT, _UU("CM_PORT_4"), 0);\r
+       CbAddStr(hWnd, C_PORT, _UU("CM_PORT_1"), 0);\r
+       CbAddStr(hWnd, C_PORT, _UU("CM_PORT_2"), 0);\r
+       CbAddStr(hWnd, C_PORT, _UU("CM_PORT_3"), 0);\r
+       SetInt(hWnd, C_PORT, a->ClientOption->Port);\r
+\r
+       // 仮想 HUB 名\r
+       CbSetHeight(hWnd, C_HUBNAME, 18);\r
+       SetTextA(hWnd, C_HUBNAME, a->ClientOption->HubName);\r
+\r
+       // プロキシの種類\r
+       Check(hWnd, R_DIRECT_TCP, a->ClientOption->ProxyType == PROXY_DIRECT);\r
+       Check(hWnd, R_HTTPS, a->ClientOption->ProxyType == PROXY_HTTP);\r
+       Check(hWnd, R_SOCKS, a->ClientOption->ProxyType == PROXY_SOCKS);\r
+\r
+       // サーバー証明書の検証\r
+       Check(hWnd, R_CHECK_CERT, a->CheckServerCert);\r
+\r
+       // LAN カード一覧\r
+       if (a->NatMode == false && a->LinkMode == false)\r
+       {\r
+               Zero(&v, sizeof(v));\r
+               CcEnumVLan(cm->Client, &v);\r
+               LvInit(hWnd, L_VLAN);\r
+               LvInsertColumn(hWnd, L_VLAN, 0, L"DeviceName", 345);\r
+               for (i = 0;i < v.NumItem;i++)\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       char str[MAX_SIZE];\r
+                       CmVLanNameToPrintName(str, sizeof(str), v.Items[i]->DeviceName);\r
+                       StrToUni(tmp, sizeof(tmp), str);\r
+                       LvInsert(hWnd, L_VLAN, ICO_NIC_ONLINE, NULL, 1, tmp);\r
+               }\r
+//             LvAutoSize(hWnd, L_VLAN);\r
+\r
+               if (v.NumItem == 1)\r
+               {\r
+                       // 仮想 LAN カードが 1 枚だけのときはそれを最初から選択する\r
+                       LvSelect(hWnd, L_VLAN, 0);\r
+               }\r
+\r
+               CiFreeClientEnumVLan(&v);\r
+       }\r
+\r
+       // LAN カードを選択する\r
+       if (StrLen(a->ClientOption->DeviceName) != 0)\r
+       {\r
+               char str[MAX_SIZE];\r
+               wchar_t tmp[MAX_SIZE];\r
+               UINT index;\r
+               CmVLanNameToPrintName(str, sizeof(str), a->ClientOption->DeviceName);\r
+               StrToUni(tmp, sizeof(tmp), str);\r
+               index = LvSearchStr(hWnd, L_VLAN, 0, tmp);\r
+               if (index != INFINITE)\r
+               {\r
+                       LvSelect(hWnd, L_VLAN, index);\r
+               }\r
+       }\r
+\r
+       // 認証の種類\r
+       CbSetHeight(hWnd, C_TYPE, 18);\r
+       CbAddStr(hWnd, C_TYPE, _UU("PW_TYPE_0"), CLIENT_AUTHTYPE_ANONYMOUS);\r
+       CbAddStr(hWnd, C_TYPE, _UU("PW_TYPE_1"), CLIENT_AUTHTYPE_PASSWORD);\r
+       CbAddStr(hWnd, C_TYPE, _UU("PW_TYPE_2"), CLIENT_AUTHTYPE_PLAIN_PASSWORD);\r
+\r
+       if (a->HideClientCertAuth == false)\r
+       {\r
+               // HideClientCertAuth が true の場合は証明書認証は利用できない\r
+               CbAddStr(hWnd, C_TYPE, _UU("PW_TYPE_3"), CLIENT_AUTHTYPE_CERT);\r
+       }\r
+\r
+       if (a->HideSecureAuth == false)\r
+       {\r
+               // スマートカードを利用した認証\r
+               CbAddStr(hWnd, C_TYPE, _UU("PW_TYPE_4"), CLIENT_AUTHTYPE_SECURE);\r
+       }\r
+\r
+       // 認証の選択\r
+       CbSelect(hWnd, C_TYPE, a->ClientAuth->AuthType);\r
+\r
+       // ユーザー名\r
+       SetTextA(hWnd, E_USERNAME, a->ClientAuth->Username);\r
+\r
+       // パスワード\r
+       if (a->EditMode)\r
+       {\r
+               SetTextA(hWnd, E_PASSWORD, HIDDEN_PASSWORD);\r
+       }\r
+\r
+       // 再接続回数\r
+       if (a->ClientOption->NumRetry == 0)\r
+       {\r
+               Check(hWnd, R_RETRY, false);\r
+       }\r
+       else\r
+       {\r
+               Check(hWnd, R_RETRY, true);\r
+               if (a->ClientOption->NumRetry == INFINITE)\r
+               {\r
+                       Check(hWnd, R_INFINITE, true);\r
+               }\r
+               else\r
+               {\r
+                       Check(hWnd, R_INFINITE, false);\r
+                       SetInt(hWnd, E_RETRY_NUM, a->ClientOption->NumRetry);\r
+               }\r
+       }\r
+       SetIntEx(hWnd, E_RETRY_SPAN, a->ClientOption->RetryInterval);\r
+\r
+       Check(hWnd, R_NOTLS1, a->ClientOption->NoTls1);\r
+\r
+       // タイトル\r
+       if (a->NatMode == false)\r
+       {\r
+               if (a->EditMode == false)\r
+               {\r
+                       SetText(hWnd, 0, _UU("CM_ACCOUNT_TITLE_1"));\r
+                       FocusEx(hWnd, E_ACCOUNT_NAME);\r
+               }\r
+               else\r
+               {\r
+                       SetText(hWnd, 0, _UU("CM_ACCOUNT_TITLE_2"));\r
+                       FormatText(hWnd, 0, a->ClientOption->AccountName);\r
+                       FocusEx(hWnd, E_HOSTNAME);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               SetText(hWnd, 0, _UU("NM_ACCOUNT_TITLE"));\r
+               FocusEx(hWnd, E_HOSTNAME);\r
+       }\r
+\r
+       if (a->LinkMode || a->NatMode)\r
+       {\r
+               Hide(hWnd, L_VLAN);\r
+\r
+               if (a->NatMode == false)\r
+               {\r
+                       SetText(hWnd, S_VLAN_GROUP, _UU("SM_LINK_POLICY_GROUP"));\r
+                       Show(hWnd, S_POLICY_1);\r
+                       Show(hWnd, S_POLICY_2);\r
+                       Show(hWnd, B_POLICY);\r
+               }\r
+               else\r
+               {\r
+                       Hide(hWnd, S_VLAN_GROUP);\r
+                       Show(hWnd, S_ROUTER_LOGO);\r
+               }\r
+       }\r
+\r
+       // 表示更新\r
+       a->Inited = true;\r
+       CmEditAccountDlgUpdate(hWnd, a);\r
+}\r
+\r
+// アカウント編集ダイアログプロシージャ\r
+UINT CmEditAccountDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       CM_ACCOUNT *a = (CM_ACCOUNT *)param;\r
+       NMHDR *n;\r
+       X *x;\r
+       K *k;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               CmEditAccountDlgInit(hWnd, a);\r
+               if (a->EditMode == false && a->LinkMode == false && a->NatMode == false)\r
+               {\r
+                       SetTimer(hWnd, 1, 100, NULL);\r
+               }\r
+               break;\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       {\r
+                               CM_INTERNET_SETTING s;\r
+\r
+                               KillTimer(hWnd, 1);\r
+\r
+                               Zero(&s, sizeof(s));\r
+                               CmGetSystemInternetSetting(&s);\r
+\r
+                               if (s.ProxyType != PROXY_DIRECT)\r
+                               {\r
+                                       if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO,\r
+                                               _UU("CM_WOULDYOULOAD_IE_PROXY"),\r
+                                               s.ProxyHostName) == IDYES)\r
+                                       {\r
+                                               Command(hWnd, B_IE);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_ACCOUNT_NAME:\r
+               case E_HOSTNAME:\r
+               case C_PORT:\r
+               case C_HUBNAME:\r
+               case R_DIRECT_TCP:\r
+               case R_HTTPS:\r
+               case R_SOCKS:\r
+               case R_CHECK_CERT:\r
+               case C_TYPE:\r
+               case E_USERNAME:\r
+               case E_PASSWORD:\r
+               case R_RETRY:\r
+               case E_RETRY_NUM:\r
+               case E_RETRY_SPAN:\r
+               case R_INFINITE:\r
+                       CmEditAccountDlgUpdate(hWnd, a);\r
+                       break;\r
+               }\r
+               switch (HIWORD(wParam))\r
+               {\r
+               case EN_KILLFOCUS:\r
+                       switch (LOWORD(wParam))\r
+                       {\r
+                       case E_HOSTNAME:\r
+                               CmEditAccountDlgStartEnumHub(hWnd, a);\r
+                               break;\r
+                       }\r
+                       break;\r
+               case BN_KILLFOCUS:\r
+                       switch (LOWORD(wParam))\r
+                       {\r
+                       case R_DIRECT_TCP:\r
+                       case R_HTTPS:\r
+                       case R_SOCKS:\r
+                               CmEditAccountDlgStartEnumHub(hWnd, a);\r
+                               break;\r
+                       }\r
+                       break;\r
+               case CBN_KILLFOCUS:\r
+                       switch (LOWORD(wParam))\r
+                       {\r
+                       case C_PORT:\r
+                               CmEditAccountDlgStartEnumHub(hWnd, a);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               if (HIWORD(wParam) == 0)\r
+               {\r
+                       CmEditAccountDlgUpdate(hWnd, a);\r
+               }\r
+               switch (wParam)\r
+               {\r
+               case B_POLICY:\r
+                       // ポリシー\r
+                       if (a->LinkMode || a->NatMode)\r
+                       {\r
+                               a->Policy.Access = true;\r
+                               a->Policy.MonitorPort = false;\r
+                               SmPolicyDlgEx2(hWnd, &a->Policy, _UU("SM_LINK_POLICY_CAPTION"), true, a->PolicyVer);\r
+                               a->Policy.Access = true;\r
+                               a->Policy.MonitorPort = false;\r
+                       }\r
+                       break;\r
+               case IDOK:\r
+                       CmEditAccountDlgUpdate(hWnd, a);\r
+                       CmEditAccountDlgOnOk(hWnd, a);\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               case B_PROXY_CONFIG:\r
+                       // プロキシ設定\r
+                       if (CmProxyDlg(hWnd, a->ClientOption))\r
+                       {\r
+                               UINT n = GetInt(hWnd, C_PORT);\r
+                               if (a->ClientOption->ProxyType == PROXY_HTTP &&\r
+                                       n != 443)\r
+                               {\r
+                                       // HTTP プロキシ経由の設定になっていて接続先が 443 番ポート\r
+                                       // 以外のポートである場合は警告を表示する\r
+                                       if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("CM_HTTP_PROXY_WARNING"), n) == IDYES)\r
+                                       {\r
+                                               // ポート番号を 443 に変更する\r
+                                               SetText(hWnd, C_PORT, _UU("CM_PORT_2"));\r
+                                       }\r
+                               }\r
+                               CmEditAccountDlgStartEnumHub(hWnd, a);\r
+                               CmEditAccountDlgUpdate(hWnd, a);\r
+                       }\r
+                       break;\r
+               case B_IE:\r
+                       // IE の設定を使用する\r
+                       if(cm->server_name == NULL)\r
+                       {\r
+                               CmProxyDlgUseForIE(hWnd, a->ClientOption);\r
+                               CmEditAccountDlgUpdate(hWnd, a);\r
+                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_PROXY_FROM_IE"));\r
+                       }\r
+                       break;\r
+               case B_TRUST:\r
+                       // CA\r
+                       if (a->LinkMode == false)\r
+                       {\r
+                               CmTrustDlg(hWnd);\r
+                       }\r
+                       else\r
+                       {\r
+                               SmCaDlg(hWnd, a->Hub);\r
+                       }\r
+                       break;\r
+               case B_SERVER_CERT:\r
+                       // サーバー証明書登録 / 削除\r
+                       if (a->ServerCert == NULL)\r
+                       {\r
+                               if (CmLoadXFromFileOrSecureCard(hWnd, &x))\r
+                               {\r
+                                       a->ServerCert = x;\r
+                                       CmEditAccountDlgUpdate(hWnd, a);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("CM_DELETE_SERVER_CERT")) == IDYES)\r
+                               {\r
+                                       FreeX(a->ServerCert);\r
+                                       a->ServerCert = NULL;\r
+                                       CmEditAccountDlgUpdate(hWnd, a);\r
+                               }\r
+                       }\r
+                       break;\r
+               case B_VIEW_SERVER_CERT:\r
+                       // サーバー証明書表示\r
+                       if (a->ServerCert != NULL)\r
+                       {\r
+                               X *issuer = CmGetIssuer(a->ServerCert);\r
+                               CertDlg(hWnd, a->ServerCert, issuer, true);\r
+                               FreeX(issuer);\r
+                       }\r
+                       break;\r
+               case B_VIEW_CLIENT_CERT:\r
+                       if (a->ClientAuth->AuthType != CLIENT_AUTHTYPE_SECURE)\r
+                       {\r
+                               // クライアント証明書表示\r
+                               if (a->ClientAuth->ClientX != NULL)\r
+                               {\r
+                                       X *issuer = CmGetIssuer(a->ClientAuth->ClientX);\r
+                                       CertDlg(hWnd, a->ClientAuth->ClientX, issuer, true);\r
+                                       FreeX(issuer);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               UINT id;\r
+                               // スマートカードの種類の選択\r
+                               SmSelectSecureId(hWnd);\r
+                               id = SmGetCurrentSecureIdFromReg();\r
+                               if (id != 0)\r
+                               {\r
+                                       if (cm->server_name == NULL)\r
+                                       {\r
+                                               RPC_USE_SECURE t;\r
+\r
+                                               Zero(&t, sizeof(t));\r
+                                               t.DeviceId = id;\r
+                                               CcUseSecure(cm->Client, &t);\r
+                                       }\r
+                               }\r
+                               CmEditAccountDlgUpdate(hWnd, a);\r
+                       }\r
+                       break;\r
+               case B_REGIST_CLIENT_CERT:\r
+                       if (a->ClientAuth->AuthType != CLIENT_AUTHTYPE_SECURE)\r
+                       {\r
+                               // クライアント証明書登録 / 削除\r
+                               if (a->ClientAuth->ClientX == NULL)\r
+                               {\r
+                                       if (CmLoadXAndK(hWnd, &x, &k))\r
+                                       {\r
+                                               a->ClientAuth->ClientX = x;\r
+                                               a->ClientAuth->ClientK = k;\r
+                                               CmEditAccountDlgUpdate(hWnd, a);\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("CM_DELETE_CLIENT_CERT")) == IDYES)\r
+                                       {\r
+                                               FreeX(a->ClientAuth->ClientX);\r
+                                               FreeK(a->ClientAuth->ClientK);\r
+                                               a->ClientAuth->ClientX = NULL;\r
+                                               a->ClientAuth->ClientK = NULL;\r
+                                               CmEditAccountDlgUpdate(hWnd, a);\r
+                                       }\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               char cert[MAX_SECURE_DEVICE_FILE_LEN + 1], priv[MAX_SECURE_DEVICE_FILE_LEN + 1];\r
+\r
+                               // スマートカード内証明書の選択\r
+                               if (SmSelectKeyPairEx(hWnd, cert, sizeof(cert), priv, sizeof(priv), CmGetSecureBitmapId(a->ClientOption->Hostname)))\r
+                               {\r
+                                       StrCpy(a->ClientAuth->SecurePublicCertName, sizeof(a->ClientAuth->SecurePublicCertName), cert);\r
+                                       StrCpy(a->ClientAuth->SecurePrivateKeyName, sizeof(a->ClientAuth->SecurePrivateKeyName), priv);\r
+                                       CmEditAccountDlgUpdate(hWnd, a);\r
+                               }\r
+                       }\r
+                       break;\r
+               case B_DETAIL:\r
+                       // 高度な通信設定\r
+                       if (CmDetailDlg(hWnd, a))\r
+                       {\r
+                               CmEditAccountDlgUpdate(hWnd, a);\r
+                       }\r
+                       break;\r
+               case B_CHANGE_PASSWORD:\r
+                       // パスワードの変更\r
+                       CmChangePassword(hWnd, a->ClientOption, a->ClientOption->HubName,\r
+                               a->ClientAuth->Username);\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_VLAN:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               CmEditAccountDlgUpdate(hWnd, a);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// プロキシサーバー設定更新\r
+void CmProxyDlgUpdate(HWND hWnd, CLIENT_OPTION *a)\r
+{\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsEmpty(hWnd, E_HOSTNAME))\r
+       {\r
+               ok = false;\r
+       }\r
+       if (GetInt(hWnd, C_PORT) == 0)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// プロキシサーバー設定ダイアログc\r
+UINT CmProxyDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       CLIENT_OPTION *a = (CLIENT_OPTION *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetTextA(hWnd, E_HOSTNAME, a->ProxyName);\r
+               CbSetHeight(hWnd, C_PORT, 18);\r
+               CbAddStr(hWnd, C_PORT, L"8080", 0);\r
+               CbAddStr(hWnd, C_PORT, L"1080", 0);\r
+               CbAddStr(hWnd, C_PORT, L"80", 0);\r
+               CbAddStr(hWnd, C_PORT, L"3128", 0);\r
+               CbAddStr(hWnd, C_PORT, L"443", 0);\r
+               CbAddStr(hWnd, C_PORT, L"9821", 0);\r
+               CbAddStr(hWnd, C_PORT, L"9801", 0);\r
+               SetIntEx(hWnd, C_PORT, a->ProxyPort);\r
+               SetTextA(hWnd, E_USERNAME, a->ProxyUsername);\r
+               SetTextA(hWnd, E_PASSWORD, a->ProxyPassword);\r
+               if (a->ProxyPort == 0)\r
+               {\r
+                       if (a->ProxyType == PROXY_HTTP)\r
+                       {\r
+                               SetInt(hWnd, C_PORT, 8080);\r
+                       }\r
+                       else\r
+                       {\r
+                               SetInt(hWnd, C_PORT, 1080);\r
+                       }\r
+               }\r
+               CmProxyDlgUpdate(hWnd, a);\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_HOSTNAME:\r
+               case C_PORT:\r
+               case E_USERNAME:\r
+               case E_PASSWORD:\r
+                       CmProxyDlgUpdate(hWnd, a);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       GetTxtA(hWnd, E_HOSTNAME, a->ProxyName, sizeof(a->ProxyName));\r
+                       GetTxtA(hWnd, E_USERNAME, a->ProxyUsername, sizeof(a->ProxyUsername));\r
+                       GetTxtA(hWnd, E_PASSWORD, a->ProxyPassword, sizeof(a->ProxyPassword));\r
+                       a->ProxyPort = GetInt(hWnd, C_PORT);\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// プロキシサーバー設定\r
+bool CmProxyDlg(HWND hWnd, CLIENT_OPTION *a)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return Dialog(hWnd, D_CM_PROXY, CmProxyDlgProc, a);\r
+}\r
+\r
+// 指定した証明書の署名者がわかれば取得する\r
+X *CmGetIssuer(X *x)\r
+{\r
+       RPC_GET_ISSUER a;\r
+       X *ret;\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&a, sizeof(a));\r
+       a.x = CloneX(x);\r
+       if (CALLEX(cm->hMainWnd, CcGetIssuer(cm->Client, &a)) == 0)\r
+       {\r
+               ret = CloneX(a.issuer_x);\r
+       }\r
+       else\r
+       {\r
+               ret = NULL;\r
+       }\r
+\r
+       CiFreeGetIssuer(&a);\r
+\r
+       return ret;\r
+}\r
+\r
+// ダイアログ初期化\r
+void CmLoadXFromFileOrSecureCardDlgInit(HWND hWnd, CM_LOADX *p)\r
+{\r
+       UINT current;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       current = MsRegReadInt(REG_CURRENT_USER, SECURE_MANAGER_KEY, "CertLoadSource");\r
+\r
+       Check(hWnd, R_FROM_FILE, current == 0);\r
+       Check(hWnd, R_FROM_SECURE, current != 0);\r
+\r
+       SetFont(hWnd, S_INFO, Font(0, true));\r
+\r
+       CmLoadXFromFileOrSecureCardDlgUpdate(hWnd, p);\r
+}\r
+\r
+// ダイアログコントロール更新\r
+void CmLoadXFromFileOrSecureCardDlgUpdate(HWND hWnd, CM_LOADX *p)\r
+{\r
+       SECURE_DEVICE *dev;\r
+       wchar_t tmp[MAX_SIZE];\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       dev = GetSecureDevice(SmGetCurrentSecureIdFromReg());\r
+       if (dev == NULL)\r
+       {\r
+               UniStrCpy(tmp, sizeof(tmp), _UU("SEC_CURRENT_NO_DEVICE"));\r
+       }\r
+       else\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("SEC_CURRENT_DEVICE"), dev->DeviceName);\r
+       }\r
+\r
+       SetText(hWnd, S_INFO, tmp);\r
+\r
+       if (IsChecked(hWnd, R_FROM_SECURE))\r
+       {\r
+               if (dev == NULL)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+       SetEnable(hWnd, B_SELECT, IsChecked(hWnd, R_FROM_SECURE));\r
+       SetEnable(hWnd, S_CERT, IsChecked(hWnd, R_FROM_SECURE));\r
+       SetEnable(hWnd, S_FILE, IsChecked(hWnd, R_FROM_FILE));\r
+}\r
+\r
+// 証明書読み込み選択ダイアログプロシージャ\r
+UINT CmLoadXFromFileOrSecureCardDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       CM_LOADX *p = (CM_LOADX *)param;\r
+       X *x;\r
+       UINT current;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               CmLoadXFromFileOrSecureCardDlgInit(hWnd, p);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       current = (IsChecked(hWnd, R_FROM_FILE)) ? 0 : 1;\r
+                       MsRegWriteInt(REG_CURRENT_USER, SECURE_MANAGER_KEY, "CertLoadSource", current);\r
+\r
+                       if (current == 0)\r
+                       {\r
+                               // ファイルから\r
+                               if (CmLoadX(hWnd, &x))\r
+                               {\r
+                                       p->x = x;\r
+                                       EndDialog(hWnd, true);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // スマートカードから\r
+                               char name[MAX_SIZE];\r
+\r
+                               // カード内の証明書名を選択\r
+                               if (SmSelectKeyPair(hWnd, name, sizeof(name), NULL, 0))\r
+                               {\r
+                                       // 読み込み\r
+                                       WINUI_SECURE_BATCH batch[] =\r
+                                       {\r
+                                               {WINUI_SECURE_READ_CERT, name, true, NULL, NULL, NULL, NULL, NULL, NULL},\r
+                                       };\r
+\r
+                                       // 読み込み実行\r
+                                       if (SecureDeviceWindow(hWnd, batch, sizeof(batch) / sizeof(batch[0]), SmGetCurrentSecureIdFromReg(), 0))\r
+                                       {\r
+                                               // 成功\r
+                                               p->x = batch[0].OutputX;\r
+                                               EndDialog(hWnd, true);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case R_FROM_FILE:\r
+                       CmLoadXFromFileOrSecureCardDlgUpdate(hWnd, p);\r
+                       break;\r
+\r
+               case R_FROM_SECURE:\r
+                       CmLoadXFromFileOrSecureCardDlgUpdate(hWnd, p);\r
+                       break;\r
+\r
+               case B_SELECT:\r
+                       SmSelectSecureId(hWnd);\r
+                       CmLoadXFromFileOrSecureCardDlgUpdate(hWnd, p);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 証明書をスマートカードかファイルから読み込む\r
+bool CmLoadXFromFileOrSecureCard(HWND hWnd, X **x)\r
+{\r
+       CM_LOADX p;\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       if (Dialog(hWnd, D_CM_LOAD_X, CmLoadXFromFileOrSecureCardDlgProc, &p) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       *x = p.x;\r
+\r
+       return true;\r
+}\r
+\r
+// 証明書を読み込む\r
+bool CmLoadX(HWND hWnd, X **x)\r
+{\r
+       return CmLoadXEx(hWnd, x, NULL, 0);\r
+}\r
+bool CmLoadXEx(HWND hWnd, X **x, char *filename, UINT size)\r
+{\r
+       wchar_t *filename_w = CopyStrToUni(filename);\r
+       bool ret;\r
+\r
+       ret = CmLoadXExW(hWnd, x, filename_w, size);\r
+\r
+       Free(filename_w);\r
+\r
+       return ret;\r
+}\r
+bool CmLoadXExW(HWND hWnd, X **x, wchar_t *filename, UINT size)\r
+{\r
+       wchar_t *s;\r
+       bool is_p12;\r
+       wchar_t tmp[MAX_SIZE];\r
+       K *k;\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 証明書を読み込む\r
+       s = OpenDlg(hWnd, _UU("DLG_CERT_OR_P12_FILTER"), _UU("DLG_OPEN_CERT"));\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       UniStrCpy(tmp, sizeof(tmp), s);\r
+       if (filename != NULL)\r
+       {\r
+               UniStrCpy(filename, size, tmp);\r
+       }\r
+       Free(s);\r
+       if (UniEndWith(tmp, L".p12") || UniEndWith(tmp, L".pfx"))\r
+       {\r
+               is_p12 = true;\r
+       }\r
+       else\r
+       {\r
+               is_p12 = false;\r
+       }\r
+\r
+       if (is_p12)\r
+       {\r
+               // PKCS#12 の処理\r
+               BUF *b = ReadDumpW(tmp);\r
+               P12 *p12;\r
+               if (b == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_OPEN_FILE_ERROR_W"), tmp);\r
+                       return false;\r
+               }\r
+               p12 = BufToP12(b);\r
+               if (p12 == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_P12_W"), tmp);\r
+                       FreeBuf(b);\r
+                       return false;\r
+               }\r
+               if (IsEncryptedP12(p12) == false)\r
+               {\r
+                       if (ParseP12(p12, x, &k, NULL) == false)\r
+                       {\r
+                               MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_P12_W"), tmp);\r
+                               FreeP12(p12);\r
+                               FreeBuf(b);\r
+                               return false;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       char password[MAX_SIZE];\r
+                       if (PassphraseDlg(hWnd, password, sizeof(password), b, true) == false)\r
+                       {\r
+                               FreeP12(p12);\r
+                               FreeBuf(b);\r
+                               return false;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (ParseP12(p12, x, &k, password) == false)\r
+                               {\r
+                                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_P12_W"), tmp);\r
+                                       FreeP12(p12);\r
+                                       FreeBuf(b);\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+               FreeP12(p12);\r
+               FreeBuf(b);\r
+               FreeK(k);\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               // X509 の処理\r
+               BUF *b = ReadDumpW(tmp);\r
+               X *x509;\r
+               if (b == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_OPEN_FILE_ERROR_W"), tmp);\r
+                       return false;\r
+               }\r
+\r
+               x509 = BufToX(b, IsBase64(b));\r
+               FreeBuf(b);\r
+               if (x509 == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_X509_W"), tmp);\r
+                       return false;\r
+               }\r
+\r
+               *x = x509;\r
+               return true;\r
+       }\r
+}\r
+\r
+// 秘密鍵を読み込む\r
+bool CmLoadK(HWND hWnd, K **k)\r
+{\r
+       return CmLoadKEx(hWnd, k, NULL, 0);\r
+}\r
+bool CmLoadKEx(HWND hWnd, K **k, char *filename, UINT size)\r
+{\r
+       wchar_t *filename_w = CopyStrToUni(filename);\r
+       bool ret;\r
+\r
+       ret = CmLoadKExW(hWnd, k, filename_w, size);\r
+\r
+       Free(filename_w);\r
+\r
+       return ret;\r
+}\r
+bool CmLoadKExW(HWND hWnd, K **k, wchar_t *filename, UINT size)\r
+{\r
+       wchar_t *s;\r
+       bool is_p12;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 証明書を読み込む\r
+       s = OpenDlg(hWnd, _UU("DLG_KEY_OR_P12_FILTER"), _UU("DLG_OPEN_KEY"));\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       UniStrCpy(tmp, sizeof(tmp), s);\r
+       Free(s);\r
+       if (filename != NULL)\r
+       {\r
+               UniStrCpy(filename, size, tmp);\r
+       }\r
+       if (UniEndWith(tmp, L".p12") || UniEndWith(tmp, L".pfx"))\r
+       {\r
+               is_p12 = true;\r
+       }\r
+       else\r
+       {\r
+               is_p12 = false;\r
+       }\r
+\r
+       if (is_p12)\r
+       {\r
+               // PKCS#12 の処理\r
+               BUF *b = ReadDumpW(tmp);\r
+               P12 *p12;\r
+               if (b == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_OPEN_FILE_ERROR_W"), tmp);\r
+                       return false;\r
+               }\r
+               p12 = BufToP12(b);\r
+               if (p12 == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_P12_W"), tmp);\r
+                       FreeBuf(b);\r
+                       return false;\r
+               }\r
+               if (IsEncryptedP12(p12) == false)\r
+               {\r
+                       X *x;\r
+                       if (ParseP12(p12, &x, k, NULL) == false)\r
+                       {\r
+                               MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_P12_W"), tmp);\r
+                               FreeP12(p12);\r
+                               FreeBuf(b);\r
+                               return false;\r
+                       }\r
+\r
+                       FreeX(x);\r
+               }\r
+               else\r
+               {\r
+                       char password[MAX_SIZE];\r
+                       if (PassphraseDlg(hWnd, password, sizeof(password), b, true) == false)\r
+                       {\r
+                               FreeP12(p12);\r
+                               FreeBuf(b);\r
+                               return false;\r
+                       }\r
+                       else\r
+                       {\r
+                               X *x;\r
+                               if (ParseP12(p12, &x, k, password) == false)\r
+                               {\r
+                                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_P12_W"), tmp);\r
+                                       FreeP12(p12);\r
+                                       FreeBuf(b);\r
+                                       return false;\r
+                               }\r
+\r
+                               FreeX(x);\r
+                       }\r
+               }\r
+               FreeP12(p12);\r
+               FreeBuf(b);\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               // 秘密鍵の処理\r
+               BUF *b = ReadDumpW(tmp);\r
+               K *key;\r
+               if (b == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_OPEN_FILE_ERROR_W"), tmp);\r
+                       return false;\r
+               }\r
+\r
+               if (IsEncryptedK(b, true) == false)\r
+               {\r
+                       key = BufToK(b, true, IsBase64(b), NULL);\r
+               }\r
+               else\r
+               {\r
+                       char pass[MAX_SIZE];\r
+                       if (PassphraseDlg(hWnd, pass, sizeof(pass), b, false) == false)\r
+                       {\r
+                               FreeBuf(b);\r
+                               return false;\r
+                       }\r
+                       key = BufToK(b, true, IsBase64(b), pass);\r
+               }\r
+\r
+               if (key == NULL)\r
+               {\r
+                       FreeBuf(b);\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_KEY_W"), tmp);\r
+                       return false;\r
+               }\r
+\r
+               FreeBuf(b);\r
+               *k = key;\r
+               return true;\r
+       }\r
+}\r
+\r
+// 証明書と秘密鍵のセットを読み込む\r
+bool CmLoadXAndK(HWND hWnd, X **x, K **k)\r
+{\r
+       wchar_t *s;\r
+       bool is_p12;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (x == NULL || k == NULL)\r
+       {\r
+               return false;\r
+       }\r
+START_FIRST:\r
+\r
+       // 証明書を読み込む\r
+       s = OpenDlg(hWnd, _UU("DLG_CERT_OR_P12_FILTER"), _UU("DLG_OPEN_CERT"));\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       UniStrCpy(tmp, sizeof(tmp), s);\r
+       Free(s);\r
+       if (UniEndWith(tmp, L".p12") || UniEndWith(tmp, L".pfx"))\r
+       {\r
+               is_p12 = true;\r
+       }\r
+       else\r
+       {\r
+               is_p12 = false;\r
+       }\r
+\r
+       if (is_p12)\r
+       {\r
+               // PKCS#12 の処理\r
+               BUF *b = ReadDumpW(tmp);\r
+               P12 *p12;\r
+               if (b == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_OPEN_FILE_ERROR_W"), tmp);\r
+                       return false;\r
+               }\r
+               p12 = BufToP12(b);\r
+               if (p12 == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_P12_W"), tmp);\r
+                       FreeBuf(b);\r
+                       return false;\r
+               }\r
+               if (IsEncryptedP12(p12) == false)\r
+               {\r
+                       if (ParseP12(p12, x, k, NULL) == false)\r
+                       {\r
+                               MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_P12_W"), tmp);\r
+                               FreeP12(p12);\r
+                               FreeBuf(b);\r
+                               return false;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       char password[MAX_SIZE];\r
+                       if (PassphraseDlg(hWnd, password, sizeof(password), b, true) == false)\r
+                       {\r
+                               FreeP12(p12);\r
+                               FreeBuf(b);\r
+                               return false;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (ParseP12(p12, x, k, password) == false)\r
+                               {\r
+                                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_P12_W"), tmp);\r
+                                       FreeP12(p12);\r
+                                       FreeBuf(b);\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+               if (CheckXandK(*x, *k) == false)\r
+               {\r
+                       FreeX(*x);\r
+                       FreeK(*k);\r
+                       FreeP12(p12);\r
+                       FreeBuf(b);\r
+                       if (MsgBox(hWnd, MB_ICONEXCLAMATION | MB_RETRYCANCEL, _UU("DLG_BAD_SIGNATURE")) == IDRETRY)\r
+                       {\r
+                               goto START_FIRST;\r
+                       }\r
+                       return false;\r
+               }\r
+               FreeP12(p12);\r
+               FreeBuf(b);\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               // X509 の処理\r
+               BUF *b = ReadDumpW(tmp);\r
+               X *x509;\r
+               K *key;\r
+               if (b == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_OPEN_FILE_ERROR_W"), tmp);\r
+                       return false;\r
+               }\r
+\r
+               x509 = BufToX(b, IsBase64(b));\r
+               FreeBuf(b);\r
+               if (x509 == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_X509_W"), tmp);\r
+                       return false;\r
+               }\r
+\r
+               // 秘密鍵を読み込む\r
+               s = OpenDlg(hWnd, _UU("DLG_KEY_FILTER"), _UU("DLG_OPEN_KEY_WITH_CERT"));\r
+               if (s == NULL)\r
+               {\r
+                       FreeX(x509);\r
+                       return false;\r
+               }\r
+               UniStrCpy(tmp, sizeof(tmp), s);\r
+               Free(s);\r
+\r
+               b = ReadDumpW(tmp);\r
+               if (b == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_OPEN_FILE_ERROR_W"), tmp);\r
+                       FreeX(x509);\r
+                       return false;\r
+               }\r
+\r
+               if (IsEncryptedK(b, true) == false)\r
+               {\r
+                       key = BufToK(b, true, IsBase64(b), NULL);\r
+               }\r
+               else\r
+               {\r
+                       char pass[MAX_SIZE];\r
+                       if (PassphraseDlg(hWnd, pass, sizeof(pass), b, false) == false)\r
+                       {\r
+                               FreeBuf(b);\r
+                               FreeX(x509);\r
+                               return false;\r
+                       }\r
+                       key = BufToK(b, true, IsBase64(b), pass);\r
+               }\r
+\r
+               if (key == NULL)\r
+               {\r
+                       FreeBuf(b);\r
+                       FreeX(x509);\r
+                       MsgBoxEx(hWnd, MB_ICONSTOP, _UU("DLG_BAD_KEY_W"), tmp);\r
+                       return false;\r
+               }\r
+\r
+               if (CheckXandK(x509, key) == false)\r
+               {\r
+                       FreeBuf(b);\r
+                       FreeX(x509);\r
+                       FreeK(key);\r
+                       if (MsgBox(hWnd, MB_ICONEXCLAMATION | MB_RETRYCANCEL, _UU("DLG_BAD_SIGNATURE")) == IDRETRY)\r
+                       {\r
+                               goto START_FIRST;\r
+                       }\r
+                       return false;\r
+               }\r
+\r
+               FreeBuf(b);\r
+               *x = x509;\r
+               *k = key;\r
+               return true;\r
+       }\r
+}\r
+\r
+// 仮想 HUB 列挙開始\r
+void CmEditAccountDlgStartEnumHub(HWND hWnd, CM_ACCOUNT *a)\r
+{\r
+       char server_name[MAX_HOST_NAME_LEN + 1];\r
+       UINT old_proxy_type;\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (StrLen(a->ClientOption->Hostname) == 0)\r
+       {\r
+               return;\r
+       }\r
+       if (a->ClientOption->Port == 0)\r
+       {\r
+               return;\r
+       }\r
+       if (a->ClientOption->ProxyType != PROXY_DIRECT &&\r
+               (StrLen(a->ClientOption->ProxyName) == 0 ||\r
+               a->ClientOption->ProxyPort == 0))\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (StrCmpi(server_name, a->old_server_name) == 0)\r
+       {\r
+               if (CbNum(hWnd, C_HUBNAME) != 0)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               StrCpy(a->old_server_name, sizeof(a->old_server_name), server_name);\r
+               CbReset(hWnd, C_HUBNAME);\r
+       }\r
+\r
+       old_proxy_type = a->ClientOption->ProxyType;\r
+\r
+       if (IsChecked(hWnd, R_DIRECT_TCP))\r
+       {\r
+               a->ClientOption->ProxyType = PROXY_DIRECT;\r
+       }\r
+       if (IsChecked(hWnd, R_HTTPS))\r
+       {\r
+               a->ClientOption->ProxyType = PROXY_HTTP;\r
+       }\r
+       if (IsChecked(hWnd, R_SOCKS))\r
+       {\r
+               a->ClientOption->ProxyType = PROXY_SOCKS;\r
+       }\r
+\r
+       CmEnumHubStart(hWnd, a->ClientOption);\r
+\r
+       a->ClientOption->ProxyType = old_proxy_type;\r
+}\r
+\r
+// [OK] ボタン\r
+void CmEditAccountDlgOnOk(HWND hWnd, CM_ACCOUNT *a)\r
+{\r
+       RPC_CLIENT_CREATE_ACCOUNT c;\r
+       bool b;\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (a->ClientOption->NumRetry != 0 && a->ClientOption->RetryInterval < 5)\r
+       {\r
+               MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_RETRY_INTERVAL_ERROR"));\r
+               FocusEx(hWnd, E_RETRY_SPAN);\r
+               return;\r
+       }\r
+\r
+       CmEditAccountDlgUpdate(hWnd, a);\r
+\r
+       if (a->LinkMode == false && a->NatMode == false)\r
+       {\r
+               // アカウントを保存\r
+               Zero(&c, sizeof(c));\r
+               c.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               Copy(c.ClientOption, a->ClientOption, sizeof(CLIENT_OPTION));\r
+               c.ClientAuth = CopyClientAuth(a->ClientAuth);\r
+               c.CheckServerCert = a->CheckServerCert;\r
+               if (a->ServerCert != NULL)\r
+               {\r
+                       c.ServerCert = CloneX(a->ServerCert);\r
+               }\r
+               c.StartupAccount = a->Startup;\r
+\r
+               if (a->EditMode == false)\r
+               {\r
+                       b = CALL(hWnd, CcCreateAccount(cm->Client, &c));\r
+               }\r
+               else\r
+               {\r
+                       b = CALL(hWnd, CcSetAccount(cm->Client, &c));\r
+               }\r
+\r
+               CiFreeClientCreateAccount(&c);\r
+\r
+               // 現在このアカウントが動作中かどうかチェック\r
+               if (b)\r
+               {\r
+                       RPC_CLIENT_GET_CONNECTION_STATUS st;\r
+                       Zero(&st, sizeof(st));\r
+                       UniStrCpy(st.AccountName, sizeof(st.AccountName), a->ClientOption->AccountName);\r
+                       if (CALL(hWnd, CcGetAccountStatus(cm->Client, &st)))\r
+                       {\r
+                               if (st.Active)\r
+                               {\r
+                                       MsgBoxEx(hWnd, MB_ICONINFORMATION, _UU("CM_CURRENT_ACTIVE"),\r
+                                               st.AccountName);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (b)\r
+               {\r
+                       EndDialog(hWnd, true);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (a->LinkMode)\r
+               {\r
+                       // リンクモード\r
+                       RPC_CREATE_LINK t;\r
+\r
+                       Zero(&t, sizeof(t));\r
+                       StrCpy(t.HubName, sizeof(t.HubName), a->Hub->HubName);\r
+                       t.Online = a->OnlineFlag;\r
+                       Copy(&t.Policy, &a->Policy, sizeof(POLICY));\r
+                       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+                       Copy(t.ClientOption, a->ClientOption, sizeof(CLIENT_OPTION));\r
+                       t.ClientAuth = CopyClientAuth(a->ClientAuth);\r
+                       t.CheckServerCert = a->CheckServerCert;\r
+                       t.ServerCert = CloneX(a->ServerCert);\r
+\r
+                       // カスケード接続の設定を保存\r
+                       if (a->EditMode)\r
+                       {\r
+                               if (CALL(hWnd, ScSetLink(a->Hub->Rpc, &t)))\r
+                               {\r
+                                       if (a->OnlineFlag)\r
+                                       {\r
+                                               MsgBoxEx(hWnd, MB_ICONINFORMATION, _UU("SM_LINK_SAVE_ONLINE"), a->ClientOption->AccountName);\r
+                                       }\r
+                                       EndDialog(hWnd, true);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               if (CALL(hWnd, ScCreateLink(a->Hub->Rpc, &t)))\r
+                               {\r
+                                       if (a->Link_ConnectNow)\r
+                                       {\r
+                                               RPC_LINK tt;\r
+\r
+                                               Zero(&tt, sizeof(tt));\r
+                                               UniStrCpy(tt.AccountName, sizeof(tt.AccountName), a->ClientOption->AccountName);\r
+                                               StrCpy(tt.HubName, sizeof(tt.HubName), a->Hub->HubName);\r
+\r
+                                               CALL(hWnd, ScSetLinkOnline(a->Hub->Rpc, &tt));\r
+                                       }\r
+                                       EndDialog(hWnd, true);\r
+                               }\r
+                       }\r
+\r
+                       FreeRpcCreateLink(&t);\r
+               }\r
+               else\r
+               {\r
+                       // NAT モード\r
+                       RPC_CREATE_LINK t;\r
+                       Zero(&t, sizeof(t));\r
+\r
+                       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+                       Copy(t.ClientOption, a->ClientOption, sizeof(CLIENT_OPTION));\r
+                       t.ClientAuth = CopyClientAuth(a->ClientAuth);\r
+\r
+                       if (CALL(hWnd, NcSetClientConfig(a->Rpc, &t)))\r
+                       {\r
+                               EndDialog(hWnd, true);\r
+                       }\r
+\r
+                       FreeRpcCreateLink(&t);\r
+               }\r
+       }\r
+}\r
+\r
+// アカウント編集ダイアログの表示\r
+bool CmEditAccountDlg(HWND hWnd, CM_ACCOUNT *a)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return Dialog(hWnd, D_CM_ACCOUNT, CmEditAccountDlgProc, a);\r
+}\r
+\r
+// アカウント編集\r
+void CmEditAccount(HWND hWnd, wchar_t *account_name)\r
+{\r
+       CM_ACCOUNT *a;\r
+       // 引数チェック\r
+       if (hWnd == NULL || account_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       a = CmGetExistAccountObject(hWnd, account_name);\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CmVoice("input_config");\r
+       if (CmEditAccountDlg(hWnd, a))\r
+       {\r
+               CmVoice("set_config");\r
+       }\r
+\r
+       CmFreeAccountObject(hWnd, a);\r
+}\r
+\r
+// アカウント作成\r
+void CmNewAccount(HWND hWnd)\r
+{\r
+       CM_ACCOUNT *a;\r
+       RPC_CLIENT_ENUM_VLAN t;\r
+       UINT num_vlan = 0;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsEnable(hWnd, 0) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CcEnumVLan(cm->Client, &t) == ERR_NO_ERROR)\r
+       {\r
+               num_vlan = t.NumItem;\r
+\r
+               CiFreeClientEnumVLan(&t);\r
+       }\r
+\r
+       if (num_vlan == 0)\r
+       {\r
+               if (MsgBox(hWnd, MB_ICONINFORMATION | MB_YESNO, _UU("CM_NO_VLAN")) == IDNO)\r
+               {\r
+                       return;\r
+               }\r
+               else\r
+               {\r
+                       if (cm->server_name == NULL)\r
+                       {\r
+                               Command(hWnd, CMD_NEW_VLAN);\r
+                               return;\r
+                       }\r
+                       else\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_VLAN_REMOTE_ERROR"));\r
+                       }\r
+                       return;\r
+               }\r
+       }\r
+\r
+       a = CmCreateNewAccountObject(hWnd);\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CmVoice("input_config");\r
+       if (CmEditAccountDlg(hWnd, a))\r
+       {\r
+               CmVoice("new_config");\r
+       }\r
+\r
+       CmFreeAccountObject(hWnd, a);\r
+}\r
+\r
+// アカウントオブジェクトの解放\r
+void CmFreeAccountObject(HWND hWnd, CM_ACCOUNT *a)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(a->ClientOption);\r
+       CiFreeClientAuth(a->ClientAuth);\r
+       if (a->ServerCert != NULL)\r
+       {\r
+               FreeX(a->ServerCert);\r
+       }\r
+       Free(a);\r
+}\r
+\r
+// 既存のアカウントオブジェクトの取得\r
+CM_ACCOUNT *CmGetExistAccountObject(HWND hWnd, wchar_t *account_name)\r
+{\r
+       RPC_CLIENT_GET_ACCOUNT c;\r
+       CM_ACCOUNT *a;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&c, sizeof(c));\r
+       UniStrCpy(c.AccountName, sizeof(c.AccountName), account_name);\r
+       if (CALL(hWnd, CcGetAccount(cm->Client, &c)) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       a = ZeroMalloc(sizeof(CM_ACCOUNT));\r
+       a->EditMode = true;\r
+       a->CheckServerCert = c.CheckServerCert;\r
+       a->Startup = c.StartupAccount;\r
+       if (c.ServerCert != NULL)\r
+       {\r
+               a->ServerCert = CloneX(c.ServerCert);\r
+       }\r
+       a->ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       Copy(a->ClientOption, c.ClientOption, sizeof(CLIENT_OPTION));\r
+       a->ClientAuth = CopyClientAuth(c.ClientAuth);\r
+       Copy(a->ShortcutKey, c.ShortcutKey, SHA1_SIZE);\r
+       CiFreeClientGetAccount(&c);\r
+\r
+       a->LockMode = cm->CmSetting.LockMode;\r
+\r
+       return a;\r
+}\r
+\r
+// 新しいアカウントオブジェクトの作成\r
+CM_ACCOUNT *CmCreateNewAccountObject(HWND hWnd)\r
+{\r
+       CM_ACCOUNT *a;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       a = ZeroMalloc(sizeof(CM_ACCOUNT));\r
+       a->EditMode = false;\r
+       a->CheckServerCert = false;\r
+       a->Startup = false;\r
+       a->ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+\r
+       // クライアントオプションの初期化\r
+       CmGenerateNewAccountName(hWnd, a->ClientOption->AccountName, sizeof(a->ClientOption->AccountName));\r
+       a->ClientOption->Port = 443;    // デフォルトポート番号\r
+       a->ClientOption->NumRetry = INFINITE;\r
+       a->ClientOption->RetryInterval = 15;\r
+       a->ClientOption->MaxConnection = 1;\r
+       a->ClientOption->HalfConnection = false;\r
+       a->ClientOption->UseEncrypt = true;\r
+       a->ClientOption->AdditionalConnectionInterval = 1;\r
+\r
+       if (cm->Client->Unix)\r
+       {\r
+               a->ClientOption->NoRoutingTracking = true;\r
+       }\r
+\r
+       a->ClientAuth = ZeroMalloc(sizeof(CLIENT_AUTH));\r
+\r
+       // パスワード認証\r
+       a->ClientAuth->AuthType = CLIENT_AUTHTYPE_PASSWORD;\r
+\r
+       return a;\r
+}\r
+\r
+// インポート名の作成\r
+void CmGenerateImportName(HWND hWnd, wchar_t *name, UINT size, wchar_t *old_name)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (name == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 1;;i++)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               if (i == 1)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_IMPORT_NAME_1"), old_name);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_IMPORT_NAME_2"), old_name, i);\r
+               }\r
+\r
+               if (LvSearchStr(hWnd, L_ACCOUNT, 0, tmp) == INFINITE)\r
+               {\r
+                       UniStrCpy(name, size, tmp);\r
+                       return;\r
+               }\r
+       }\r
+}\r
+\r
+// コピー名の作成\r
+void CmGenerateCopyName(HWND hWnd, wchar_t *name, UINT size, wchar_t *old_name)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (name == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 1;;i++)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               if (i == 1)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_COPY_NAME_1"), old_name);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_COPY_NAME_2"), i, old_name);\r
+               }\r
+\r
+               if (LvSearchStr(hWnd, L_ACCOUNT, 0, tmp) == INFINITE)\r
+               {\r
+                       UniStrCpy(name, size, tmp);\r
+                       return;\r
+               }\r
+       }\r
+}\r
+\r
+// 新しいアカウント名の作成\r
+void CmGenerateNewAccountName(HWND hWnd, wchar_t *name, UINT size)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (name == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 1;;i++)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               if (i == 1)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_NEW_ACCOUNT_NAME_1"));\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_NEW_ACCOUNT_NAME_2"), i);\r
+               }\r
+\r
+               if (LvSearchStr(hWnd, L_ACCOUNT, 0, tmp) == INFINITE)\r
+               {\r
+                       UniStrCpy(name, size, tmp);\r
+                       return;\r
+               }\r
+       }\r
+}\r
+\r
+// ポリシー一覧を表示する\r
+void CmPolicyDlgPrint(HWND hWnd, CM_POLICY *p)\r
+{\r
+       CmPolicyDlgPrintEx(hWnd, p, false);\r
+}\r
+void CmPolicyDlgPrintEx(HWND hWnd, CM_POLICY *p, bool cascade_mode)\r
+{\r
+       CmPolicyDlgPrintEx2(hWnd, p, cascade_mode, POLICY_CURRENT_VERSION);\r
+}\r
+void CmPolicyDlgPrintEx2(HWND hWnd, CM_POLICY *p, bool cascade_mode, bool ver)\r
+{\r
+       POLICY *pol;\r
+       UINT i;\r
+       LVB *b;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pol = p->Policy;\r
+\r
+       b = LvInsertStart();\r
+\r
+       for (i = 0;i < NUM_POLICY_ITEM;i++)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               if (cascade_mode)\r
+               {\r
+                       if (PolicyIsSupportedForCascade(i) == false)\r
+                       {\r
+                               continue;\r
+                       }\r
+               }\r
+\r
+               if (IS_POLICY_FOR_CURRENT_VER(i, ver))\r
+               {\r
+                       if (policy_item[i].TypeInt == false)\r
+                       {\r
+                               // bool 型\r
+                               UniStrCpy(tmp, sizeof(tmp), POLICY_BOOL(pol, i) ? _UU("POL_BOOL_ENABLE") : (p->Extension ? _UU("POL_BOOL_DISABLE_EX") : _UU("POL_BOOL_DISABLE")));\r
+                       }\r
+                       else\r
+                       {\r
+                               // int 型\r
+                               if (policy_item[i].AllowZero && POLICY_INT(pol, i) == 0)\r
+                               {\r
+                                       UniStrCpy(tmp, sizeof(tmp), _UU("POL_INT_ZERO"));\r
+                               }\r
+                               else\r
+                               {\r
+                                       UniFormat(tmp, sizeof(tmp), _UU(policy_item[i].FormatStr), POLICY_INT(pol, i));\r
+                               }\r
+                       }\r
+\r
+                       LvInsertAdd(b, ICO_MACHINE, (void *)i, 2, GetPolicyTitle(i), tmp);\r
+               }\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_POLICY);\r
+}\r
+\r
+// ポリシー一覧ダイアログ\r
+UINT CmPolicyDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       CM_POLICY *p = (CM_POLICY *)param;\r
+       NMHDR *n;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               FormatText(hWnd, 0, p->AccountName);\r
+               FormatText(hWnd, S_TITLE, p->AccountName);\r
+               p->hWnd = hWnd;\r
+               if (p->CmStatus != NULL)\r
+               {\r
+                       p->CmStatus->hWndPolicy = hWnd;\r
+               }\r
+\r
+               // カラム初期化\r
+               LvInit(hWnd, L_POLICY);\r
+               LvInsertColumn(hWnd, L_POLICY, 0, _UU("POL_TITLE_STR"), 375);\r
+               LvInsertColumn(hWnd, L_POLICY, 1, _UU("POL_VALUE_STR"), 100);\r
+\r
+               // 表示\r
+               CmPolicyDlgPrint(hWnd, p);\r
+\r
+               // 1 つ目を選択\r
+               LvSelect(hWnd, L_POLICY, 0);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_POLICY:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               // 選択変更\r
+                               if (LvIsSelected(hWnd, L_POLICY) == false)\r
+                               {\r
+                                       SetText(hWnd, S_DESCRIPTION, L"");\r
+                               }\r
+                               else\r
+                               {\r
+                                       UINT index = LvGetSelected(hWnd, L_POLICY);\r
+                                       UINT id = (UINT)LvGetParam(hWnd, L_POLICY, index);\r
+                                       if (id < NUM_POLICY_ITEM)\r
+                                       {\r
+                                               SetText(hWnd, S_DESCRIPTION, GetPolicyDescription(id));\r
+                                       }\r
+                               }\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       LvSortHander(hWnd, msg, wParam, lParam, L_POLICY);\r
+\r
+       return 0;\r
+}\r
+\r
+// ポリシー一覧ダイアログの表示\r
+void CmPolicyDlg(HWND hWnd, CM_STATUS *st)\r
+{\r
+       RPC_CLIENT_GET_CONNECTION_STATUS s;\r
+       POLICY *policy;\r
+       CM_POLICY cp;\r
+       // 引数チェック\r
+       if (hWnd == NULL || st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ポリシーの取得\r
+       Zero(&s, sizeof(s));\r
+       UniStrCpy(s.AccountName, sizeof(s.AccountName), st->AccountName);\r
+       if (CALL(hWnd, CcGetAccountStatus(cm->Client, &s)) == false)\r
+       {\r
+               return;\r
+       }\r
+       if (s.Active == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       policy = &s.Policy;\r
+\r
+       Zero(&cp, sizeof(cp));\r
+       UniStrCpy(cp.AccountName, sizeof(cp.AccountName), st->AccountName);\r
+       cp.Policy = policy;\r
+       cp.CmStatus = st;\r
+\r
+       Dialog(hWnd, D_CM_POLICY, CmPolicyDlgProc, &cp);\r
+\r
+       st->hWndPolicy = NULL;\r
+\r
+       CiFreeClientGetConnectionStatus(&s);\r
+}\r
+\r
+// 証明書の表示\r
+void CmStatusDlgPrintCert(HWND hWnd, CM_STATUS *st, bool server)\r
+{\r
+       RPC_CLIENT_GET_CONNECTION_STATUS s;\r
+       X *x, *issuer;\r
+       // 引数チェック\r
+       if (hWnd == NULL || st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 最新情報を取得する\r
+       Zero(&s, sizeof(s));\r
+       UniStrCpy(s.AccountName, sizeof(s.AccountName), st->AccountName);\r
+       if (CALL(hWnd, CcGetAccountStatus(cm->Client, &s)) == false)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       if (s.Active == false)\r
+       {\r
+               // 接続切断\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       if (server == false)\r
+       {\r
+               // クライアント証明書の表示\r
+               x = s.ClientX;\r
+       }\r
+       else\r
+       {\r
+               // サーバー証明書の表示\r
+               x = s.ServerX;\r
+       }\r
+\r
+       cm->WindowCount++;\r
+       issuer = CmGetIssuer(x);\r
+       CertDlg(hWnd, x, issuer, true);\r
+       FreeX(issuer);\r
+       cm->WindowCount--;\r
+\r
+       CiFreeClientGetConnectionStatus(&s);\r
+}\r
+\r
+// ステータスダイアログの情報を表示\r
+void CmStatusDlgPrint(HWND hWnd, CM_STATUS *cmst)\r
+{\r
+       RPC_CLIENT_GET_CONNECTION_STATUS s;\r
+       LVB *b;\r
+       // 引数チェック\r
+       if (hWnd == NULL || cmst == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 最新情報を取得する\r
+       Zero(&s, sizeof(s));\r
+       UniStrCpy(s.AccountName, sizeof(s.AccountName), cmst->AccountName);\r
+       if (CALL(hWnd, CcGetAccountStatus(cm->Client, &s)) == false)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       if (s.Active == false)\r
+       {\r
+               // 接続切断\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       // ステータスダイアログのリストボックスにステータスを表示する\r
+       b = LvInsertStart();\r
+       CmPrintStatusToListView(b, &s);\r
+       LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+       LvAutoSize(hWnd, L_STATUS);\r
+\r
+       SetEnable(hWnd, B_POLICY, s.Connected);\r
+\r
+       SetEnable(hWnd, B_SERVER_CERT, s.ServerX != NULL);\r
+       SetEnable(hWnd, B_CLIENT_CERT, s.ClientX != NULL);\r
+\r
+       CiFreeClientGetConnectionStatus(&s);\r
+}\r
+\r
+// ステータスダイアログのリストボックスにステータスを表示する\r
+void CmPrintStatusToListView(LVB *b, RPC_CLIENT_GET_CONNECTION_STATUS *s)\r
+{\r
+       CmPrintStatusToListViewEx(b, s, false);\r
+}\r
+void CmPrintStatusToListViewEx(LVB *b, RPC_CLIENT_GET_CONNECTION_STATUS *s, bool server_mode)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       char str[MAX_SIZE];\r
+       char vv[128];\r
+       // 引数チェック\r
+       if (b == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (server_mode == false)\r
+       {\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_ACCOUNT_NAME"), s->AccountName);\r
+\r
+               if (s->Connected == false)\r
+               {\r
+                       wchar_t *st = _UU("CM_ST_CONNECTED_FALSE");\r
+                       switch (s->SessionStatus)\r
+                       {\r
+                       case CLIENT_STATUS_CONNECTING:\r
+                               st = _UU("CM_ST_CONNECTING");\r
+                               break;\r
+                       case CLIENT_STATUS_NEGOTIATION:\r
+                               st = _UU("CM_ST_NEGOTIATION");\r
+                               break;\r
+                       case CLIENT_STATUS_AUTH:\r
+                               st = _UU("CM_ST_AUTH");\r
+                               break;\r
+                       case CLIENT_STATUS_ESTABLISHED:\r
+                               st = _UU("CM_ST_ESTABLISHED");\r
+                               break;\r
+                       case CLIENT_STATUS_RETRY:\r
+                               st = _UU("CM_ST_RETRY");\r
+                               break;\r
+                       case CLIENT_STATUS_IDLE:\r
+                               st = _UU("CM_ST_IDLE");\r
+                               break;\r
+                       }\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_CONNECTED"), st);\r
+               }\r
+               else\r
+               {\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_CONNECTED"), _UU("CM_ST_CONNECTED_TRUE"));\r
+               }\r
+       }\r
+\r
+       if (s->Connected)\r
+       {\r
+               if (s->VLanId == 0)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("CM_ST_NO_VLAN"));\r
+               }\r
+               else\r
+               {\r
+                       UniToStru(tmp, s->VLanId);\r
+               }\r
+\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_VLAN_ID"), tmp);\r
+\r
+               if (server_mode == false)\r
+               {\r
+                       StrToUni(tmp, sizeof(tmp), s->ServerName);\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_SERVER_NAME"), tmp);\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_ST_PORT_TCP"), s->ServerPort);\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_SERVER_PORT"), tmp);\r
+               }\r
+\r
+               StrToUni(tmp, sizeof(tmp), s->ServerProductName);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_SERVER_P_NAME"), tmp);\r
+\r
+               UniFormat(tmp, sizeof(tmp), L"%u.%02u", s->ServerProductVer / 100, s->ServerProductVer % 100);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_SERVER_P_VER"), tmp);\r
+               UniFormat(tmp, sizeof(tmp), L"Build %u", s->ServerProductBuild);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_SERVER_P_BUILD"), tmp);\r
+       }\r
+\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(s->StartTime), NULL);\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_START_TIME"), tmp);\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(s->FirstConnectionEstablisiedTime), NULL);\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_FIRST_ESTAB_TIME"), s->FirstConnectionEstablisiedTime == 0 ? _UU("CM_ST_NONE") : tmp);\r
+\r
+       if (s->Connected)\r
+       {\r
+               GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(s->CurrentConnectionEstablishTime), NULL);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_CURR_ESTAB_TIME"), tmp);\r
+       }\r
+\r
+       if (server_mode == false)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_STR"), s->NumConnectionsEatablished);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_NUM_ESTABLISHED"), tmp);\r
+       }\r
+\r
+       if (s->Connected)\r
+       {\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_HALF_CONNECTION"), s->HalfConnection ? _UU("CM_ST_HALF_TRUE") : _UU("CM_ST_HALF_FALSE"));\r
+\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_QOS"), s->QoS ? _UU("CM_ST_QOS_TRUE") : _UU("CM_ST_QOS_FALSE"));\r
+\r
+               UniFormat(tmp, sizeof(tmp), L"%u", s->NumTcpConnections);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_NUM_TCP"), tmp);\r
+\r
+               if (s->HalfConnection)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), L"%u", s->NumTcpConnectionsUpload);\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_NUM_TCP_UPLOAD"), tmp);\r
+                       UniFormat(tmp, sizeof(tmp), L"%u", s->NumTcpConnectionsDownload);\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_NUM_TCP_DOWNLOAD"), tmp);\r
+               }\r
+\r
+               UniFormat(tmp, sizeof(tmp), L"%u", s->MaxTcpConnections);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_MAX_TCP"), tmp);\r
+\r
+               if (s->UseEncrypt == false)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("CM_ST_USE_ENCRYPT_FALSE"));\r
+               }\r
+               else\r
+               {\r
+                       if (StrLen(s->CipherName) != 0)\r
+                       {\r
+                               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_USE_ENCRYPT_TRUE"), s->CipherName);\r
+                       }\r
+                       else\r
+                       {\r
+                               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_USE_ENCRYPT_TRUE2"));\r
+                       }\r
+               }\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_USE_ENCRYPT"), tmp);\r
+\r
+               if (s->UseCompress)\r
+               {\r
+                       UINT percent = 0;\r
+                       if ((s->TotalRecvSize + s->TotalSendSize) > 0)\r
+                       {\r
+                               percent = (UINT)((UINT64)100 - (UINT64)(s->TotalRecvSizeReal + s->TotalSendSizeReal) * (UINT64)100 /\r
+                                       (s->TotalRecvSize + s->TotalSendSize));\r
+                               percent = MAKESURE(percent, 0, 100);\r
+                       }\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_ST_COMPRESS_TRUE"), percent);\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("CM_ST_COMPRESS_FALSE"));\r
+               }\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_USE_COMPRESS"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), s->SessionName);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_SESSION_NAME"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), s->ConnectionName);\r
+               if (UniStrCmpi(tmp, L"INITING") != 0)\r
+               {\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_CONNECTION_NAME"), tmp);\r
+               }\r
+\r
+               BinToStr(str, sizeof(str), s->SessionKey, sizeof(s->SessionKey));\r
+               StrToUni(tmp, sizeof(tmp), str);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_SESSION_KEY"), tmp);\r
+\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_BRIDGE_MODE"), s->IsBridgeMode ? _UU("CM_ST_YES") : _UU("CM_ST_NO"));\r
+\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_MONITOR_MODE"), s->IsMonitorMode ? _UU("CM_ST_YES") : _UU("CM_ST_NO"));\r
+\r
+               ToStr3(vv, sizeof(vv), s->TotalSendSize);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_SEND_SIZE"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->TotalRecvSize);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_RECV_SIZE"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Send.UnicastCount);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_PACKET_STR"), vv);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_SEND_UCAST_NUM"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Send.UnicastBytes);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_SEND_UCAST_SIZE"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Send.BroadcastCount);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_PACKET_STR"), vv);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_SEND_BCAST_NUM"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Send.BroadcastBytes);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_SEND_BCAST_SIZE"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Recv.UnicastCount);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_PACKET_STR"), vv);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_RECV_UCAST_NUM"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Recv.UnicastBytes);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_RECV_UCAST_SIZE"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Recv.BroadcastCount);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_PACKET_STR"), vv);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_RECV_BCAST_NUM"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Recv.BroadcastBytes);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("CM_ST_RECV_BCAST_SIZE"), tmp);\r
+       }\r
+}\r
+\r
+// ステータスダイアログプロシージャ\r
+UINT CmStatusDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       CM_STATUS *s = (CM_STATUS *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetIcon(hWnd, 0, ICO_TOWER);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_TITLE"), s->AccountName);\r
+               SetText(hWnd, 0, tmp);\r
+               FormatText(hWnd, S_TITLE, s->AccountName);\r
+               DlgFont(hWnd, S_TITLE, 0, 1);\r
+\r
+               Add(cm->StatusWindowList, hWnd);\r
+\r
+               SetTimer(hWnd, 1, 500, NULL);\r
+\r
+               LvInitEx(hWnd, L_STATUS, true);\r
+               ListView_SetImageList(DlgItem(hWnd, L_STATUS), NULL, LVSIL_NORMAL);\r
+               ListView_SetImageList(DlgItem(hWnd, L_STATUS), NULL, LVSIL_SMALL);\r
+               LvInsertColumn(hWnd, L_STATUS, 0, _UU("CM_ST_COLUMN_1"), 160);\r
+               LvInsertColumn(hWnd, L_STATUS, 1, _UU("CM_ST_COLUMN_2"), 270);\r
+\r
+               CmStatusDlgPrint(hWnd, s);\r
+\r
+               break;\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       CmStatusDlgPrint(hWnd, s);\r
+                       SetTimer(hWnd, 1, 500, NULL);\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+               case IDCANCEL:\r
+                       // 閉じる\r
+                       Close(hWnd);\r
+                       break;\r
+               case B_POLICY:\r
+                       // ポリシー表示\r
+                       CmPolicyDlg(hWnd, s);\r
+                       break;\r
+               case B_SERVER_CERT:\r
+                       CmStatusDlgPrintCert(hWnd, s, true);\r
+                       break;\r
+               case B_CLIENT_CERT:\r
+                       CmStatusDlgPrintCert(hWnd, s, false);\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CLOSE:\r
+               Delete(cm->StatusWindowList, hWnd);\r
+               if (s->hWndPolicy != NULL)\r
+               {\r
+                       EndDialog(s->hWndPolicy, false);\r
+                       s->hWndPolicy = NULL;\r
+               }\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ステータスダイアログの表示\r
+void CmStatusDlg(HWND hWnd, wchar_t *account_name)\r
+{\r
+       CM_STATUS *s;\r
+       // 引数チェック\r
+       if (hWnd == NULL || account_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = ZeroMalloc(sizeof(CM_STATUS));\r
+       UniStrCpy(s->AccountName, sizeof(s->AccountName), account_name);\r
+\r
+       Dialog(hWnd, D_CONNECTION_STATUS, CmStatusDlgProc, s);\r
+\r
+       Free(s);\r
+}\r
+\r
+// ステータスの表示\r
+void CmStatus(HWND hWnd, wchar_t *account_name)\r
+{\r
+       UINT i;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || account_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniFormat(tmp, sizeof(tmp), _UU("CM_ST_TITLE"), account_name);\r
+\r
+       for (i = 0;i < LIST_NUM(cm->StatusWindowList);i++)\r
+       {\r
+               HWND h = LIST_DATA(cm->StatusWindowList, i);\r
+               if (h != NULL)\r
+               {\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       if (GetTxt(h, 0, tmp2, sizeof(tmp2)))\r
+                       {\r
+                               if (UniStrCmpi(tmp2, tmp) == 0)\r
+                               {\r
+                                       SetActiveWindow(h);\r
+                                       return;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       CmStatusDlg(hWnd, account_name);\r
+}\r
+\r
+// 削除\r
+void CmDeleteAccount(HWND hWnd, wchar_t *account_name)\r
+{\r
+       RPC_CLIENT_DELETE_ACCOUNT c;\r
+       // 引数チェック\r
+       if (hWnd == NULL || account_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+       Zero(&c, sizeof(c));\r
+       UniStrCpy(c.AccountName, sizeof(c.AccountName), account_name);\r
+\r
+       CmVoice("delete_config_1");\r
+       if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("CM_DELETE_ACCOUNT_MSG"), account_name)\r
+               == IDNO)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CALL(hWnd, CcDeleteAccount(cm->Client, &c));\r
+       CmVoice("delete_config_2");\r
+}\r
+\r
+// 切断\r
+void CmDisconnect(HWND hWnd, wchar_t *account_name)\r
+{\r
+       RPC_CLIENT_CONNECT c;\r
+       // 引数チェック\r
+       if (hWnd == NULL || account_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&c, sizeof(c));\r
+       UniStrCpy(c.AccountName, sizeof(c.AccountName), account_name);\r
+\r
+       cm->PositiveDisconnectFlag = true;\r
+\r
+       CALL(hWnd, CcDisconnect(cm->Client, &c));\r
+}\r
+\r
+// 宣伝ウインドウの表示\r
+void SmShowPublicVpnServerHtml(HWND hWnd)\r
+{\r
+       char *langstr = _SS("LANGSTR");\r
+\r
+       if(StrCmpi(langstr, "Japanese") == 0)\r
+       {\r
+               ShowHtml(hWnd, PUBLIC_SERVER_HTML, PUBLIC_SERVER_TAG);\r
+       }\r
+       else\r
+       {\r
+               ShowHtml(hWnd, PUBLIC_SERVER_HTML_EN, PUBLIC_SERVER_TAG);\r
+       }\r
+}\r
+\r
+// 接続\r
+void CmConnect(HWND hWnd, wchar_t *account_name)\r
+{\r
+       RPC_CLIENT_CONNECT c;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || account_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsEnable(hWnd, 0) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (hWnd == cm->hMainWnd)\r
+       {\r
+               if (LvNum(hWnd, L_VLAN) == 0 && cm->Client->Win9x)\r
+               {\r
+                       if (MsgBox(hWnd, MB_ICONINFORMATION | MB_YESNO, _UU("CM_NO_VLAN_2")) == IDNO)\r
+                       {\r
+                               return;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (cm->server_name == NULL)\r
+                               {\r
+                                       Command(hWnd, CMD_NEW_VLAN);\r
+                                       return;\r
+                               }\r
+                               else\r
+                               {\r
+                                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_VLAN_REMOTE_ERROR"));\r
+                               }\r
+                               return;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // 警告を表示 (必要な場合)\r
+       if (CmWarningDesktop(hWnd, account_name) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (cm->server_name == NULL)\r
+       {\r
+               if (cm->BadProcessChecked == false)\r
+               {\r
+                       cm->BadProcessChecked = true;\r
+\r
+                       CheckBadProcesses(hWnd);\r
+               }\r
+       }\r
+\r
+       if (cm->server_name == NULL)\r
+       {\r
+               // Windows バージョンチェック\r
+               RPC_WINVER winver;\r
+               wchar_t winver_msg_client[3800];\r
+\r
+               GetWinVer(&winver);\r
+               Zero(winver_msg_client, sizeof(winver_msg_client));\r
+\r
+               if (IsSupportedWinVer(&winver) == false)\r
+               {\r
+                       SYSTEMTIME st;\r
+\r
+                       LocalTime(&st);\r
+\r
+                       UniFormat(winver_msg_client, sizeof(winver_msg_client), _UU("WINVER_ERROR_FORMAT"),\r
+                               _UU("WINVER_ERROR_PC_LOCAL"),\r
+                               winver.Title,\r
+                               _UU("WINVER_ERROR_VPNCLIENT"),\r
+                               SUPPORTED_WINDOWS_LIST,\r
+                               _UU("WINVER_ERROR_PC_LOCAL"),\r
+                               _UU("WINVER_ERROR_VPNCLIENT"),\r
+                               _UU("WINVER_ERROR_VPNCLIENT"),\r
+                               _UU("WINVER_ERROR_VPNCLIENT"),\r
+                               st.wYear, st.wMonth);\r
+               }\r
+\r
+               if (UniIsEmptyStr(winver_msg_client) == false)\r
+               {\r
+                       OnceMsgEx(hWnd, _UU("WINVER_TITLE"), winver_msg_client,\r
+                               true, ICO_WARNING, NULL);\r
+               }\r
+       }\r
+\r
+       i = LvSearchStr(hWnd, L_ACCOUNT, 0, account_name);\r
+       if (i != INFINITE)\r
+       {\r
+               wchar_t *tmp = LvGetStr(hWnd, L_ACCOUNT, i, 2);\r
+               if (tmp != NULL)\r
+               {\r
+                       wchar_t tag[MAX_SIZE];\r
+                       StrToUni(tag, sizeof(tag), PUBLIC_SERVER_NAME);\r
+\r
+                       if (UniSearchStrEx(tmp, tag, 0, false) != INFINITE)\r
+                       {\r
+                               SmShowPublicVpnServerHtml(hWnd);\r
+                       }\r
+\r
+                       Free(tmp);\r
+               }\r
+       }\r
+\r
+       Zero(&c, sizeof(c));\r
+       UniStrCpy(c.AccountName, sizeof(c.AccountName), account_name);\r
+\r
+       CmSetForegroundProcessToCnService();\r
+\r
+       if (CALL(hWnd, CcConnect(cm->Client, &c)))\r
+       {\r
+               cm->ConnectStartedFlag = true;\r
+       }\r
+}\r
+\r
+// 指定されたメニュー項目を太字にするかどうか判断する\r
+bool CmIsBold(UINT id)\r
+{\r
+       return false;\r
+}\r
+\r
+// 指定されたメニュー項目を有効にするかどうか判断する\r
+bool CmIsEnabled(HWND hWnd, UINT id)\r
+{\r
+       UINT index;\r
+       wchar_t *name;\r
+       bool locked = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       locked = cm->CmSetting.LockMode;\r
+\r
+       if (locked)\r
+       {\r
+               switch (id)\r
+               {\r
+               case CMD_NEW:\r
+               case CMD_CLONE:\r
+               case CMD_IMPORT_ACCOUNT:\r
+               case CMD_DELETE:\r
+               case CMD_TCPIP:\r
+               case CMD_OPTION:\r
+               case CMD_VOIDE_NONE:\r
+               case CMD_VOICE_NORMAL:\r
+               case CMD_VOICE_ODD:\r
+               case CMD_STARTUP:\r
+               case CMD_NOSTARTUP:\r
+               case CMD_TRAFFIC:\r
+               case CMD_MMCSS:\r
+                       return false;\r
+               case CMD_NEW_VLAN:\r
+               case CMD_ENABLE_VLAN:\r
+               case CMD_DISABLE_VLAN:\r
+               case CMD_DELETE_VLAN:\r
+               case CMD_REINSTALL:\r
+               case CMD_WINNET:\r
+                       if (cm->CmEasyModeSupported)\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       switch (id)\r
+       {\r
+       case CMD_SHOWPORT:\r
+       case CMD_GRID:\r
+               if (cm->IconView)\r
+               {\r
+                       return false;\r
+               }\r
+               return true;\r
+       case CMD_TCPIP:\r
+               if (MsIsTcpConfigSupported() == false)\r
+               {\r
+                       return false;\r
+               }\r
+               return cm->server_name != NULL ? false : true;\r
+       case CMD_MMCSS:\r
+               if (MsIsVista() == false || IsEmptyStr(cm->server_name) == false)\r
+               {\r
+                       return false;\r
+               }\r
+               if (OS_IS_SERVER(GetOsType()))\r
+               {\r
+                       return false;\r
+               }\r
+               return true;\r
+       case CMD_TRAYICON:\r
+       case CMD_TRAFFIC:\r
+               return (cm->server_name == NULL);\r
+       case CMD_NETIF:\r
+               if (MsIsNt() == false)\r
+               {\r
+                       return false;\r
+               }\r
+               return (cm->server_name == NULL);\r
+       case CMD_CM_SETTING:\r
+               return cm->CmSettingSupported;\r
+       case CMD_CONNECT:\r
+       case CMD_DISCONNECT:\r
+       case CMD_STATUS:\r
+       case CMD_RENAME:\r
+       case CMD_DELETE:\r
+               if (LvIsMultiMasked(hWnd, L_ACCOUNT))\r
+               {\r
+                       return false;\r
+               }\r
+               if (LvIsSelected(hWnd, L_ACCOUNT) == false)\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       // 選択されているアカウントが接続中かどうか判別する\r
+                       UINT i = LvGetSelected(hWnd, L_ACCOUNT);\r
+                       wchar_t *str = LvGetStr(hWnd, L_ACCOUNT, i, 1);\r
+                       wchar_t *name = LvGetStr(hWnd, L_ACCOUNT, i, 0);\r
+                       bool is_connected = false;\r
+                       if (str != NULL)\r
+                       {\r
+                               if (UniStrCmpi(str, _UU("CM_ACCOUNT_ONLINE")) == 0 || UniStrCmpi(str, _UU("CM_ACCOUNT_CONNECTING")) == 0)\r
+                               {\r
+                                       is_connected = true;\r
+                               }\r
+                               Free(str);\r
+                       }\r
+                       if (name != NULL)\r
+                       {\r
+                               if (UniStrCmpi(name, _UU("CM_NEW_ICON")) == 0 || UniStrCmpi(name, _UU("CM_ASP")) == 0)\r
+                               {\r
+                                       Free(name);\r
+                                       return false;\r
+                               }\r
+                               Free(name);\r
+                       }\r
+                       if (id == CMD_CONNECT || id == CMD_RENAME || id == CMD_DELETE)\r
+                       {\r
+                               return !is_connected;\r
+                       }\r
+                       else\r
+                       {\r
+                               return is_connected;\r
+                       }\r
+               }\r
+               break;\r
+       case CMD_DISCONNECT_ALL:\r
+               if (CmGetNumConnected(hWnd) == 0)\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       return true;\r
+               }\r
+       case CMD_SHORTCUT:\r
+               // ショートカットの作成\r
+               if (cm->Client->Rpc->Sock->RemoteIP.addr[0] != 127)\r
+               {\r
+                       return false;\r
+               }\r
+       case CMD_EXPORT_ACCOUNT:\r
+               if (LvIsMultiMasked(hWnd, L_ACCOUNT))\r
+               {\r
+                       return false;\r
+               }\r
+               name = LvGetSelectedStr(hWnd, L_ACCOUNT, 0);\r
+               if (name != NULL)\r
+               {\r
+                       if (UniStrCmpi(name, _UU("CM_NEW_ICON")) == 0 || UniStrCmpi(name, _UU("CM_ASP")) == 0)\r
+                       {\r
+                               Free(name);\r
+                               return false;\r
+                       }\r
+                       Free(name);\r
+               }\r
+               return LvIsSelected(hWnd, L_ACCOUNT);\r
+       case CMD_CLONE:\r
+               if (LvIsMultiMasked(hWnd, L_ACCOUNT))\r
+               {\r
+                       return false;\r
+               }\r
+               name = LvGetSelectedStr(hWnd, L_ACCOUNT, 0);\r
+               if (name != NULL)\r
+               {\r
+                       if (UniStrCmpi(name, _UU("CM_NEW_ICON")) == 0 || UniStrCmpi(name, _UU("CM_ASP")) == 0)\r
+                       {\r
+                               Free(name);\r
+                               return false;\r
+                       }\r
+                       Free(name);\r
+               }\r
+               return LvIsSelected(hWnd, L_ACCOUNT);\r
+       case CMD_STARTUP:\r
+       case CMD_NOSTARTUP:\r
+               name = LvGetSelectedStr(hWnd, L_ACCOUNT, 0);\r
+               if (name != NULL)\r
+               {\r
+                       if (UniStrCmpi(name, _UU("CM_NEW_ICON")) == 0 || UniStrCmpi(name, _UU("CM_ASP")) == 0)\r
+                       {\r
+                               Free(name);\r
+                               return false;\r
+                       }\r
+                       Free(name);\r
+               }\r
+               if (LvIsMultiMasked(hWnd, L_ACCOUNT))\r
+               {\r
+                       return false;\r
+               }\r
+               if (LvIsSelected(hWnd, L_ACCOUNT) == false)\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       // 選択されているアカウントがスタートアップアカウントかどうか判別する\r
+                       UINT i = LvGetSelected(hWnd, L_ACCOUNT);\r
+                       bool is_startup = (bool)LvGetParam(hWnd, L_ACCOUNT, i);\r
+                       if (id == CMD_STARTUP)\r
+                       {\r
+                               return !is_startup;\r
+                       }\r
+                       else\r
+                       {\r
+                               return is_startup;\r
+                       }\r
+               }\r
+               break;\r
+       case CMD_NEW_VLAN:\r
+               if (cm->Client->Unix == false && cm->Client->Win9x == false)\r
+               {\r
+                       if (cm->server_name != NULL)\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+               if (cm->Client->Win9x)\r
+               {\r
+                       if (LvNum(hWnd, L_VLAN) >= 1)\r
+                       {\r
+                               // Win9x では 2 枚以上の仮想 LAN カードをインストールできない\r
+                               return false;\r
+                       }\r
+               }\r
+               break;\r
+       case CMD_PROPERTY:\r
+               name = LvGetSelectedStr(hWnd, L_ACCOUNT, 0);\r
+               if (name != NULL)\r
+               {\r
+                       if (UniStrCmpi(name, _UU("CM_NEW_ICON")) == 0 || UniStrCmpi(name, _UU("CM_ASP")) == 0)\r
+                       {\r
+                               Free(name);\r
+                               return false;\r
+                       }\r
+                       Free(name);\r
+               }\r
+               if (LvIsMultiMasked(hWnd, L_ACCOUNT))\r
+               {\r
+                       return false;\r
+               }\r
+               return LvIsSelected(hWnd, L_ACCOUNT);\r
+       case CMD_DELETE_VLAN:\r
+               if (LvIsMultiMasked(hWnd, L_VLAN))\r
+               {\r
+                       return false;\r
+               }\r
+               return LvIsSelected(hWnd, L_VLAN);\r
+       case CMD_ENABLE_VLAN:\r
+               if (cm->Client->Win9x)\r
+               {\r
+                       return false;\r
+               }\r
+               if (LvIsMultiMasked(hWnd, L_VLAN))\r
+               {\r
+                       return false;\r
+               }\r
+               index = LvGetSelected(hWnd, L_VLAN);\r
+               if (index == INFINITE)\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       wchar_t *s = LvGetStr(hWnd, L_VLAN, index, 1);\r
+                       if (s != NULL)\r
+                       {\r
+                               if (UniStrCmpi(s, _UU("CM_VLAN_DISABLED")) == 0)\r
+                               {\r
+                                       Free(s);\r
+                                       return true;\r
+                               }\r
+                               Free(s);\r
+                       }\r
+                       return false;\r
+               }\r
+               break;\r
+       case CMD_DISABLE_VLAN:\r
+               if (cm->Client->Win9x)\r
+               {\r
+                       return false;\r
+               }\r
+               if (LvIsMultiMasked(hWnd, L_VLAN))\r
+               {\r
+                       return false;\r
+               }\r
+               index = LvGetSelected(hWnd, L_VLAN);\r
+               if (index == INFINITE)\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       wchar_t *s = LvGetStr(hWnd, L_VLAN, index, 1);\r
+                       if (s != NULL)\r
+                       {\r
+                               if (UniStrCmpi(s, _UU("CM_VLAN_ENABLED")) == 0)\r
+                               {\r
+                                       Free(s);\r
+                                       return true;\r
+                               }\r
+                               Free(s);\r
+                       }\r
+                       return false;\r
+               }\r
+               break;\r
+       case CMD_REINSTALL:\r
+               if (cm->server_name != NULL)\r
+               {\r
+                       return false;\r
+               }\r
+               if (cm->Client->Win9x || cm->Client->Unix)\r
+               {\r
+                       // Win9x と UNIX 系では仮想 LAN カードのアップグレード不可\r
+                       return false;\r
+               }\r
+               if (LvIsMultiMasked(hWnd, L_VLAN))\r
+               {\r
+                       return false;\r
+               }\r
+               return LvIsSelected(hWnd, L_VLAN);\r
+       case CMD_WINNET:\r
+               {\r
+                       UINT os_type = GetOsInfo()->OsType;\r
+\r
+                       if (OS_IS_WINDOWS_NT(os_type) && GET_KETA(os_type, 100) >= 2)\r
+                       {\r
+                               if (cm->server_name != NULL)\r
+                               {\r
+                                       return false;\r
+                               }\r
+\r
+                               return true;\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+               break;\r
+       case CMD_EXIT:\r
+               return cm->TrayInited;\r
+       }\r
+       return true;\r
+}\r
+\r
+// VLAN デバイス名を表示名に変換\r
+void CmVLanNameToPrintName(char *str, UINT size, char *name)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(str, size, VLAN_ADAPTER_NAME_TAG, name);\r
+}\r
+\r
+// 表示名を VLAN デバイス名に変換\r
+bool CmPrintNameToVLanName(char *name, UINT size, char *str)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StartWith(str, VLAN_ADAPTER_NAME))\r
+       {\r
+               if (StrLen(str) < (StrLen(VLAN_ADAPTER_NAME) + 3))\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               StrCpy(name, size, str + StrLen(VLAN_ADAPTER_NAME) + 3);\r
+\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// アカウントリストの初期化\r
+void CmInitAccountList(HWND hWnd)\r
+{\r
+       CmInitAccountListEx(hWnd, false);\r
+}\r
+void CmInitAccountListEx(HWND hWnd, bool easy)\r
+{\r
+       UINT width[5];\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 設定読み込み\r
+       b = MsRegReadBin(REG_CURRENT_USER, CM_REG_KEY, "AccountListColumnWidth");\r
+       if ((b != NULL) && (b->Size == sizeof(width)))\r
+       {\r
+               Copy(width, b->Buf, sizeof(width));\r
+       }\r
+       else if ((b != NULL) && (b->Size == (sizeof(width) - sizeof(UINT))))\r
+       {\r
+               // 旧バージョンからの移行\r
+               Zero(width, sizeof(width));\r
+               Copy(width, b->Buf, sizeof(width) - sizeof(UINT));\r
+               width[4] = width[3];\r
+               width[3] = 0;\r
+       }\r
+       else\r
+       {\r
+               Zero(width, sizeof(width));\r
+       }\r
+       FreeBuf(b);\r
+\r
+       LvInitEx2(hWnd, L_ACCOUNT, false, easy);\r
+\r
+//     LvSetStyle(hWnd, L_ACCOUNT, LVS_EX_TRACKSELECT);\r
+\r
+       // カラムの初期化\r
+       if (easy == false)\r
+       {\r
+               LvInsertColumn(hWnd, L_ACCOUNT, 0, _UU("CM_ACCOUNT_COLUMN_1"), width[0] == 0 ? 215 : width[0]);\r
+               LvInsertColumn(hWnd, L_ACCOUNT, 1, _UU("CM_ACCOUNT_COLUMN_2"), width[1] == 0 ? 80 : width[1]);\r
+               LvInsertColumn(hWnd, L_ACCOUNT, 2, _UU("CM_ACCOUNT_COLUMN_3"), width[2] == 0 ? 220 : width[2]);\r
+               LvInsertColumn(hWnd, L_ACCOUNT, 3, _UU("CM_ACCOUNT_COLUMN_3_2"), width[3] == 0 ? 90 : width[3]);\r
+               LvInsertColumn(hWnd, L_ACCOUNT, 4, _UU("CM_ACCOUNT_COLUMN_4"), (width[4] == 0 || width[4] == 250) ? 120 : width[4]);\r
+\r
+               //LvSetBkImage(hWnd, L_ACCOUNT, "|ClientBack2.bmp");\r
+       }\r
+       else\r
+       {\r
+               LvInsertColumn(hWnd, L_ACCOUNT, 0, _UU("CM_ACCOUNT_COLUMN_1"), 345);\r
+               LvInsertColumn(hWnd, L_ACCOUNT, 1, _UU("CM_ACCOUNT_COLUMN_2"), 140);\r
+               LvInsertColumn(hWnd, L_ACCOUNT, 2, _UU("CM_ACCOUNT_COLUMN_3"), 0);\r
+               LvInsertColumn(hWnd, L_ACCOUNT, 3, _UU("CM_ACCOUNT_COLUMN_3_2"), 0);\r
+               LvInsertColumn(hWnd, L_ACCOUNT, 4, _UU("CM_ACCOUNT_COLUMN_4"), 0);\r
+       }\r
+\r
+}\r
+\r
+// アカウントリストの解放\r
+void CmSaveAccountListPos(HWND hWnd)\r
+{\r
+       UINT width[5];\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < 5;i++)\r
+       {\r
+               width[i] = LvGetColumnWidth(hWnd, L_ACCOUNT, i);\r
+       }\r
+\r
+       MsRegWriteBin(REG_CURRENT_USER, CM_REG_KEY, "AccountListColumnWidth", width, sizeof(width));\r
+}\r
+\r
+// VLAN リストの初期化\r
+void CmInitVLanList(HWND hWnd)\r
+{\r
+       UINT width[4];\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 設定読み込み\r
+       b = MsRegReadBin(REG_CURRENT_USER, CM_REG_KEY, "VLanListColumnWidth");\r
+       if ((b != NULL) && (b->Size == sizeof(width)))\r
+       {\r
+               Copy(width, b->Buf, sizeof(width));\r
+       }\r
+       else\r
+       {\r
+               Zero(width, sizeof(width));\r
+       }\r
+       FreeBuf(b);\r
+\r
+       LvInit(hWnd, L_VLAN);\r
+\r
+//     LvSetStyle(hWnd, L_ACCOUNT, LVS_EX_TRACKSELECT);\r
+\r
+       // カラムの初期化\r
+       LvInsertColumn(hWnd, L_VLAN, 0, _UU("CM_VLAN_COLUMN_1"), width[0] == 0 ? 310 : width[0]);\r
+       LvInsertColumn(hWnd, L_VLAN, 1, _UU("CM_VLAN_COLUMN_2"), width[1] == 0 ? 120 : width[1]);\r
+       LvInsertColumn(hWnd, L_VLAN, 2, _UU("CM_VLAN_COLUMN_3"), width[2] == 0 ? 175 : width[2]);\r
+       LvInsertColumn(hWnd, L_VLAN, 3, _UU("CM_VLAN_COLUMN_4"), width[3] == 0 ? 120 : width[3]);\r
+\r
+       // 背景イメージ\r
+       LvSetBkImage(hWnd, L_VLAN, "|ClientBack2.bmp");\r
+}\r
+\r
+// VLAN リストの解放\r
+void CmSaveVLanListPos(HWND hWnd)\r
+{\r
+       UINT width[4];\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < 4;i++)\r
+       {\r
+               width[i] = LvGetColumnWidth(hWnd, L_VLAN, i);\r
+       }\r
+\r
+       MsRegWriteBin(REG_CURRENT_USER, CM_REG_KEY, "VLanListColumnWidth", width, sizeof(width));\r
+}\r
+\r
+// アカウントリストの更新\r
+void CmRefreshAccountList(HWND hWnd)\r
+{\r
+       CmRefreshAccountListEx(hWnd, false);\r
+       CmRefreshEasy();\r
+}\r
+void CmRefreshAccountListEx(HWND hWnd, bool easy)\r
+{\r
+       CmRefreshAccountListEx2(hWnd, easy, false);\r
+}\r
+void CmRefreshAccountListEx2(HWND hWnd, bool easy, bool style_changed)\r
+{\r
+       UINT num = 0;\r
+       RPC_CLIENT_ENUM_ACCOUNT a;\r
+       UINT num_connecting = 0, num_connected = 0;\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t new_inserted_item[MAX_ACCOUNT_NAME_LEN + 1];\r
+       bool select_new_insteted_item = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // アイコン / 詳細表示の切り替え\r
+       LvSetView(hWnd, L_ACCOUNT, cm->IconView == false || easy);\r
+\r
+       // グリッド表示\r
+       if (cm->ShowGrid || easy)\r
+       {\r
+               LvSetStyle(hWnd, L_ACCOUNT, LVS_EX_GRIDLINES);\r
+       }\r
+       else\r
+       {\r
+               LvRemoveStyle(hWnd, L_ACCOUNT, LVS_EX_GRIDLINES);\r
+       }\r
+\r
+       if (style_changed)\r
+       {\r
+               // フォントの変更\r
+               if (easy == false)\r
+               {\r
+                       if (cm->VistaStyle)\r
+                       {\r
+                               SetFontMeiryo(hWnd, L_ACCOUNT);\r
+                       }\r
+                       else\r
+                       {\r
+                               SetFontDefault(hWnd, L_ACCOUNT);\r
+                       }\r
+\r
+                       if (cm->VistaStyle && (cm->IconView == false))\r
+                       {\r
+                               LvSetStyle(hWnd, L_ACCOUNT, LVS_EX_FULLROWSELECT);\r
+                       }\r
+                       else\r
+                       {\r
+                               LvRemoveStyle(hWnd, L_ACCOUNT, LVS_EX_FULLROWSELECT);\r
+                       }\r
+               }\r
+       }\r
+\r
+       Zero(new_inserted_item, sizeof(new_inserted_item));\r
+\r
+       if (LvNum(hWnd, L_ACCOUNT) == 0)\r
+       {\r
+               select_new_insteted_item = false;\r
+       }\r
+\r
+       // アカウントリストの列挙\r
+       if (CALL(hWnd, CcEnumAccount(cm->Client, &a)))\r
+       {\r
+               UINT i;\r
+               LVB *b = LvInsertStart();\r
+\r
+               if (cm->CmSetting.LockMode == false && (easy == false))\r
+               {\r
+                       // 特別なアイコン\r
+                       LvInsertAdd(b, ICO_NEW, NULL, 4, _UU("CM_NEW_ICON"), L"", L"", L"");\r
+                       LvInsertAdd(b, ICO_INTERNET, NULL, 4, _UU("CM_ASP"), L"", L"", L"");\r
+               }\r
+\r
+               for (i = 0;i < a.NumItem;i++)\r
+               {\r
+                       RPC_CLIENT_ENUM_ACCOUNT_ITEM *t = a.Items[i];\r
+                       UINT icon;\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       char tmp3[MAX_SIZE];\r
+                       wchar_t tmp4[MAX_SIZE];\r
+                       IP ip;\r
+                       char ip_str[MAX_SIZE];\r
+\r
+                       // IPv6 アドレスの場合の特別処理\r
+                       if (StrToIP6(&ip, t->ServerName) && StartWith(t->ServerName, "[") == false)\r
+                       {\r
+                               Format(ip_str, sizeof(ip_str),\r
+                                       "[%s]", t->ServerName);\r
+                       }\r
+                       else\r
+                       {\r
+                               StrCpy(ip_str, sizeof(ip_str), t->ServerName);\r
+                       }\r
+\r
+                       // アイコンの決定\r
+                       if (t->Active == false)\r
+                       {\r
+                               if (t->StartupAccount == false)\r
+                               {\r
+                                       icon = ICO_SERVER_OFFLINE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       icon = ICO_SERVER_OFFLINE_EX;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               num++;\r
+                               if (t->StartupAccount == false)\r
+                               {\r
+                                       icon = ICO_SERVER_ONLINE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       icon = ICO_SERVER_ONLINE_EX;\r
+                               }\r
+                       }\r
+\r
+                       // 追加\r
+                       if (easy == false)\r
+                       {\r
+                               //CmVLanNameToPrintName(tmp3, sizeof(tmp3), t->DeviceName);\r
+                               StrCpy(tmp3, sizeof(tmp3), t->DeviceName);\r
+                               StrToUni(tmp, sizeof(tmp), tmp3);\r
+                       }\r
+                       else\r
+                       {\r
+                               StrToUni(tmp, sizeof(tmp), t->DeviceName);\r
+                       }\r
+\r
+                       if (t->Port == 0 || cm->ShowPort == false)\r
+                       {\r
+                               // ポート番号不明\r
+                               UniFormat(tmp2, sizeof(tmp2), L"%S (%s)", ip_str, CmGetProtocolName(t->ProxyType));\r
+                       }\r
+                       else\r
+                       {\r
+                               // ポート番号併記\r
+                               UniFormat(tmp2, sizeof(tmp2), L"%S:%u (%s)", ip_str, t->Port, CmGetProtocolName(t->ProxyType));\r
+                       }\r
+\r
+                       if (LvSearchStr(hWnd, L_ACCOUNT, 0, t->AccountName) == INFINITE)\r
+                       {\r
+                               UniStrCpy(new_inserted_item, sizeof(new_inserted_item), t->AccountName);\r
+                       }\r
+\r
+                       // 仮想 HUB 名\r
+                       StrToUni(tmp4, sizeof(tmp4), t->HubName);\r
+\r
+                       if (easy == false)\r
+                       {\r
+                               LvInsertAdd(b, icon, (void *)t->StartupAccount, 5, t->AccountName,\r
+                                       t->Active == false ? _UU("CM_ACCOUNT_OFFLINE") :\r
+                                       (t->Connected ? _UU("CM_ACCOUNT_ONLINE") : _UU("CM_ACCOUNT_CONNECTING")),\r
+                                       tmp2, tmp4,\r
+                                       tmp);\r
+                       }\r
+                       else\r
+                       {\r
+                               LvInsertAdd(b, icon, (void *)t->StartupAccount, 5, t->AccountName,\r
+                                       t->Active == false ? _UU("CM_ACCOUNT_OFFLINE") :\r
+                                       (t->Connected ? _UU("CM_ACCOUNT_ONLINE") : _UU("CM_ACCOUNT_CONNECTING")),\r
+                                       tmp2, tmp4,\r
+                                       tmp);\r
+                       }\r
+\r
+                       if (t->Active)\r
+                       {\r
+                               if (t->Connected)\r
+                               {\r
+                                       num_connected++;\r
+                               }\r
+                               else\r
+                               {\r
+                                       num_connecting++;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               LvInsertEnd(b, hWnd, L_ACCOUNT);\r
+\r
+               CiFreeClientEnumAccount(&a);\r
+\r
+               if (select_new_insteted_item)\r
+               {\r
+                       if (UniStrLen(new_inserted_item) >= 1)\r
+                       {\r
+                               LvSelect(hWnd, L_ACCOUNT, INFINITE);\r
+                               LvSelect(hWnd, L_ACCOUNT, LvSearchStr(hWnd, L_ACCOUNT, 0, new_inserted_item));\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (easy == false)\r
+       {\r
+               // 音声ガイドのため、新しく接続されたり、切断されたりした場合を検出する\r
+               if (cm->UpdateConnectedNumFlag == false)\r
+               {\r
+                       cm->UpdateConnectedNumFlag = true;\r
+                       cm->OldConnectedNum = num;\r
+               }\r
+               else\r
+               {\r
+                       if (cm->OldConnectedNum != num)\r
+                       {\r
+                               if (cm->OldConnectedNum < num)\r
+                               {\r
+                                       CmVoice("connect");\r
+                               }\r
+                               else\r
+                               {\r
+                                       CmVoice("disconnect");\r
+\r
+                                       if (cm->CmSetting.EasyMode && cm->PositiveDisconnectFlag == false)\r
+                                       {\r
+                                               CmShowEasy();\r
+                                       }\r
+\r
+                                       cm->PositiveDisconnectFlag = false;\r
+                               }\r
+                               cm->OldConnectedNum = num;\r
+                       }\r
+               }\r
+\r
+               if (num_connecting == 0 && num_connected == 0)\r
+               {\r
+                       // 接続中も接続完了も無し\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("CM_TRAY_NOT_CONNECTED"));\r
+               }\r
+               else if (num_connected == 0)\r
+               {\r
+                       // 接続中だけ有り\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_TRAY_CONNECTED_1"), num_connecting);\r
+               }\r
+               else if (num_connecting == 0)\r
+               {\r
+                       // 接続完了だけ有り\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_TRAY_CONNECTED_2"), num_connected);\r
+               }\r
+               else\r
+               {\r
+                       // 両方有り\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_TRAY_CONNECTED_0"), num_connected, num_connecting);\r
+               }\r
+\r
+               if (num_connecting == 0 && num_connected == 0)\r
+               {\r
+                       cm->TrayAnimation = false;\r
+                       cm->TraySpeedAnimation = false;\r
+               }\r
+               else\r
+               {\r
+                       cm->TrayAnimation = true;\r
+\r
+                       if (num_connecting == 0)\r
+                       {\r
+                               cm->TraySpeedAnimation = false;\r
+                       }\r
+                       else\r
+                       {\r
+                               cm->TraySpeedAnimation = true;\r
+                       }\r
+               }\r
+\r
+               CmChangeTrayString(hWnd, tmp);\r
+       }\r
+\r
+       Refresh(hWnd);\r
+\r
+       //ジャンプリストを更新\r
+       CmUpdateJumpList(0);\r
+}\r
+\r
+// VLAN リストの更新\r
+void CmRefreshVLanList(HWND hWnd)\r
+{\r
+       CmRefreshVLanListEx(hWnd, false);\r
+}\r
+void CmRefreshVLanListEx(HWND hWnd, bool style_changed)\r
+{\r
+       RPC_CLIENT_ENUM_VLAN e;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LvSetView(hWnd, L_VLAN, cm->IconView == false);\r
+\r
+       // グリッド表示\r
+       if (cm->ShowGrid)\r
+       {\r
+               LvSetStyle(hWnd, L_VLAN, LVS_EX_GRIDLINES);\r
+       }\r
+       else\r
+       {\r
+               LvRemoveStyle(hWnd, L_VLAN, LVS_EX_GRIDLINES);\r
+       }\r
+\r
+       if (style_changed)\r
+       {\r
+               // フォントの変更\r
+               if (cm->VistaStyle)\r
+               {\r
+                       SetFontMeiryo(hWnd, L_VLAN);\r
+               }\r
+               else\r
+               {\r
+                       SetFontDefault(hWnd, L_VLAN);\r
+               }\r
+\r
+               if (cm->VistaStyle && (cm->IconView == false))\r
+               {\r
+                       LvSetStyle(hWnd, L_VLAN, LVS_EX_FULLROWSELECT);\r
+               }\r
+               else\r
+               {\r
+                       LvRemoveStyle(hWnd, L_VLAN, LVS_EX_FULLROWSELECT);\r
+               }\r
+       }\r
+\r
+       // 列挙\r
+       Zero(&e, sizeof(e));\r
+       if (CALL(hWnd, CcEnumVLan(cm->Client, &e)))\r
+       {\r
+               LVB *b = LvInsertStart();\r
+               UINT i;\r
+               for (i = 0;i < e.NumItem;i++)\r
+               {\r
+                       wchar_t name[MAX_SIZE];\r
+                       wchar_t mac[MAX_SIZE];\r
+                       wchar_t ver[MAX_SIZE];\r
+                       char str[MAX_SIZE];\r
+                       wchar_t *status;\r
+                       RPC_CLIENT_ENUM_VLAN_ITEM *v = e.Items[i];\r
+\r
+                       // デバイス名\r
+                       CmVLanNameToPrintName(str, sizeof(str), v->DeviceName);\r
+                       StrToUni(name, sizeof(name), str);\r
+\r
+                       // 状態\r
+                       status = v->Enabled ? _UU("CM_VLAN_ENABLED") : _UU("CM_VLAN_DISABLED");\r
+\r
+                       // MAC アドレス\r
+                       StrToUni(mac, sizeof(mac), v->MacAddress);\r
+\r
+                       // バージョン\r
+                       StrToUni(ver, sizeof(ver), v->Version);\r
+\r
+                       LvInsertAdd(b, v->Enabled ? ICO_NIC_ONLINE : ICO_NIC_OFFLINE, NULL, 4,\r
+                               name, status, mac, ver);\r
+               }\r
+               LvInsertEnd(b, hWnd, L_VLAN);\r
+\r
+               CiFreeClientEnumVLan(&e);\r
+       }\r
+}\r
+\r
+// プロトコル名文字列を取得\r
+wchar_t *CmGetProtocolName(UINT n)\r
+{\r
+       return GetProtocolName(n);\r
+}\r
+\r
+// 表示更新\r
+void CmRefresh(HWND hWnd)\r
+{\r
+       CmRefreshEx(hWnd, false);\r
+}\r
+void CmRefreshEx(HWND hWnd, bool style_changed)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // サイズ更新\r
+       CmMainWindowOnSize(hWnd);\r
+\r
+       // VLAN リストの更新\r
+       CmRefreshVLanListEx(hWnd, style_changed);\r
+\r
+       // アカウントリストの更新\r
+       CmRefreshAccountListEx2(hWnd, false, style_changed);\r
+\r
+       // ステータスバーの更新\r
+       CmRefreshStatusBar(hWnd);\r
+}\r
+\r
+// 指定されたメニュー項目をチェックするかどうか判断する\r
+bool CmIsChecked(UINT id)\r
+{\r
+       switch (id)\r
+       {\r
+       case CMD_TRAYICON:\r
+               return cm->HideTrayIcon == false;\r
+       case CMD_STATUSBAR:\r
+               return cm->HideStatusBar == false;\r
+       case CMD_VISTASTYLE:\r
+               return cm->VistaStyle;\r
+       case CMD_ICON:\r
+               return cm->IconView;\r
+       case CMD_DETAIL:\r
+               return cm->IconView == false;\r
+       case CMD_GRID:\r
+               return cm->ShowGrid;\r
+       case CMD_VOIDE_NONE:\r
+               return cm->DisableVoice;\r
+       case CMD_SHOWPORT:\r
+               return cm->ShowPort;\r
+       case CMD_VOICE_NORMAL:\r
+               if (cm->DisableVoice)\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       return cm->VoiceId == VOICE_SSK;\r
+               }\r
+       case CMD_VOICE_ODD:\r
+               if (cm->DisableVoice)\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       return cm->VoiceId == VOICE_AHO;\r
+               }\r
+       }\r
+       return false;\r
+}\r
+\r
+// メニューがポップアップされた\r
+void CmMainWindowOnPopupMenu(HWND hWnd, HMENU hMenu, UINT pos)\r
+{\r
+       UINT num_menu, i, id;\r
+       // 引数チェック\r
+       if (hWnd == NULL || hMenu == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       num_menu = GetMenuItemCount(hMenu);\r
+       for (i = 0;i < num_menu;i++)\r
+       {\r
+               id = GetMenuItemID(hMenu, i);\r
+\r
+               if (id != INFINITE)\r
+               {\r
+                       bool enable_flag = CmIsEnabled(hWnd, id);\r
+                       bool checked_flag = CmIsChecked(id);\r
+                       bool bold_flag = CmIsBold(id);\r
+                       MENUITEMINFO info;\r
+\r
+                       Zero(&info, sizeof(info));\r
+                       info.cbSize = sizeof(info);\r
+                       info.fMask = MIIM_STATE;\r
+                       info.fState = (enable_flag ? MFS_ENABLED : MFS_DISABLED) |\r
+                               (checked_flag ? MFS_CHECKED : MFS_UNCHECKED) |\r
+                               (bold_flag ? MFS_DEFAULT : 0);\r
+\r
+                       if (id == CMD_ICON || id == CMD_DETAIL || id == CMD_VOIDE_NONE ||\r
+                               id == CMD_VOICE_NORMAL || id == CMD_VOICE_ODD)\r
+                       {\r
+                               info.fMask |= MIIM_FTYPE;\r
+                               info.fType = MFT_RADIOCHECK;\r
+                       }\r
+\r
+                       SetMenuItemInfo(hMenu, id, false, &info);\r
+               }\r
+\r
+               if (id == CMD_RECENT)\r
+               {\r
+                       HMENU sub = CmCreateRecentSubMenu(hWnd, CM_TRAY_MENU_RECENT_ID_START);\r
+\r
+                       if (sub != NULL)\r
+                       {\r
+                               DeleteMenu(hMenu, i, MF_BYPOSITION);\r
+                               MsInsertMenu(hMenu, i, MF_BYPOSITION | MF_ENABLED | MF_POPUP | MF_STRING,\r
+                                       (UINT_PTR)sub, _UU("CM_TRAY_MENU_RECENT"));\r
+                       }\r
+                       else\r
+                       {\r
+                               MENUITEMINFO info;\r
+\r
+                               Zero(&info, sizeof(info));\r
+                               info.cbSize = sizeof(info);\r
+                               info.fMask = MIIM_STATE;\r
+                               info.fState = MFS_DISABLED;\r
+\r
+                               SetMenuItemInfo(hMenu, id, false, &info);\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// メインウインドウタイトルの設定\r
+wchar_t *CmGenerateMainWindowTitle()\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       if (cm->server_name == NULL)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), L"%s", _UU("CM_TITLE"));\r
+       }\r
+       else\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), L"%s - %S", _UU("CM_TITLE"), cm->server_name);\r
+       }\r
+\r
+       return CopyUniStr(tmp);\r
+}\r
+\r
+// タスクトレイの初期化\r
+void CmInitTray(HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (cm->server_name != NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (cm->TrayInited)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsShowIconOnTray(hWnd, LoadSmallIcon(CmGetTrayIconId(false, 0)), _UU("CM_TRAY_INITING"), WM_CM_TRAY_MESSAGE);\r
+\r
+       cm->TrayInited = true;\r
+       cm->TrayAnimation = false;\r
+\r
+       SetTimer(hWnd, 2, CM_TRAY_ANIMATION_INTERVAL / 4, NULL);\r
+}\r
+\r
+// タスクトレイの文字列の変更\r
+void CmChangeTrayString(HWND hWnd, wchar_t *str)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (cm->TrayInited == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsChangeIconOnTray(NULL, str);\r
+}\r
+\r
+// タスクトレイの解放\r
+void CmFreeTray(HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (cm->TrayInited == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsHideIconOnTray();\r
+\r
+       cm->TrayInited = false;\r
+}\r
+void CmFreeTrayExternal(void *hWnd)\r
+{\r
+       CmFreeTray((HWND)hWnd);\r
+}\r
+\r
+// タスクトレイに対する定期的な処理\r
+void CmPollingTray(HWND hWnd)\r
+{\r
+       UINT interval;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (cm->TrayInited == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsChangeIconOnTray(LoadSmallIcon(CmGetTrayIconId(cm->TrayAnimation, cm->TrayAnimationCounter)),\r
+               NULL);\r
+\r
+       cm->TrayAnimationCounter++;\r
+\r
+       KillTimer(hWnd, 2);\r
+       interval = CM_TRAY_ANIMATION_INTERVAL / 4;\r
+       if (cm->TraySpeedAnimation)\r
+       {\r
+               interval /= 4;\r
+       }\r
+       SetTimer(hWnd, 2, interval, NULL);\r
+}\r
+\r
+// アニメーション用のタスクトレイのアイコン ID の取得\r
+UINT CmGetTrayIconId(bool animation, UINT animation_counter)\r
+{\r
+       if (animation == false)\r
+       {\r
+               return ICO_TRAY0;\r
+       }\r
+       else\r
+       {\r
+               switch (animation_counter % 4)\r
+               {\r
+               case 0:\r
+                       return ICO_TRAY1;\r
+\r
+               case 1:\r
+                       return ICO_TRAY2;\r
+\r
+               case 2:\r
+                       return ICO_TRAY3;\r
+\r
+               default:\r
+                       return ICO_TRAY4;\r
+               }\r
+       }\r
+}\r
+\r
+// メインウインドウの初期化\r
+void CmMainWindowOnInit(HWND hWnd)\r
+{\r
+       wchar_t *s;\r
+       BUF *b;\r
+       bool startup_mode = cm->StartupMode;\r
+       CM_SETTING a;\r
+       bool fake = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // リストのフォント設定\r
+       SetFontMeiryo(hWnd, L_ACCOUNT);\r
+       SetFontMeiryo(hWnd, L_VLAN);\r
+\r
+       // 現在の vpnclient の設定を取得する\r
+       Zero(&a, sizeof(a));\r
+       CcGetCmSetting(cm->Client, &a);\r
+\r
+       if (a.EasyMode)\r
+       {\r
+               fake = true;\r
+       }\r
+\r
+       InitMenuInternational(GetMenu(hWnd), "CM_MENU");\r
+\r
+       cm->HideStatusBar = MsRegReadInt(REG_CURRENT_USER, CM_REG_KEY, "HideStatusBar");\r
+       cm->HideTrayIcon = MsRegReadInt(REG_CURRENT_USER, CM_REG_KEY, "HideTrayIcon");\r
+       cm->IconView = MsRegReadInt(REG_CURRENT_USER, CM_REG_KEY, "IconView");\r
+       cm->ShowGrid = MsRegReadInt(REG_CURRENT_USER, CM_REG_KEY, "ShowGrid");\r
+\r
+       if (MsRegIsValue(REG_CURRENT_USER, CM_REG_KEY, "VistaStyle"))\r
+       {\r
+               cm->VistaStyle = MsRegReadInt(REG_CURRENT_USER, CM_REG_KEY, "VistaStyle");\r
+       }\r
+       else\r
+       {\r
+               cm->VistaStyle = MsIsVista();\r
+       }\r
+\r
+       if (MsRegIsValue(REG_CURRENT_USER, CM_REG_KEY, "ShowPort"))\r
+       {\r
+               cm->ShowPort = MsRegReadInt(REG_CURRENT_USER, CM_REG_KEY, "ShowPort");\r
+       }\r
+       else\r
+       {\r
+               cm->ShowPort = false;\r
+       }\r
+\r
+       if (MsRegIsValue(REG_CURRENT_USER, CM_REG_KEY, "DisableVoice"))\r
+       {\r
+               cm->DisableVoice = MsRegReadInt(REG_CURRENT_USER, CM_REG_KEY, "DisableVoice");\r
+       }\r
+       else\r
+       {\r
+               cm->DisableVoice = true;\r
+       }\r
+       cm->VoiceId = MsRegReadInt(REG_CURRENT_USER, CM_REG_KEY, "VoiceId");\r
+\r
+       cm->StatusWindowList = NewList(NULL);\r
+\r
+       SetIcon(hWnd, 0, ICO_VPN);\r
+\r
+       s = CmGenerateMainWindowTitle();\r
+       SetText(hWnd, 0, s);\r
+       Free(s);\r
+\r
+       // ウインドウ位置の初期化\r
+       b = MsRegReadBin(REG_CURRENT_USER, CM_REG_KEY, "WindowPlacement");\r
+       if (b != NULL && b->Size == sizeof(WINDOWPLACEMENT))\r
+       {\r
+               // ウインドウ位置を復元\r
+               WINDOWPLACEMENT *p;\r
+               p = ZeroMalloc(b->Size);\r
+               Copy(p, b->Buf, b->Size);\r
+\r
+               if (startup_mode)\r
+               {\r
+                       p->showCmd = SW_SHOWMINIMIZED;\r
+               }\r
+\r
+               if (fake)\r
+               {\r
+                       Copy(&cm->FakeWindowPlacement, p, sizeof(WINDOWPLACEMENT));\r
+               }\r
+               else\r
+               {\r
+                       SetWindowPlacement(hWnd, p);\r
+               }\r
+               Free(p);\r
+       }\r
+       else\r
+       {\r
+               // ウインドウ位置を初期化\r
+               SetWindowPos(hWnd, NULL, 0, 0, CM_DEFAULT_WIDTH, CM_DEFAULT_HEIGHT, SWP_NOREDRAW);\r
+               Center(hWnd);\r
+               if (startup_mode)\r
+               {\r
+                       ShowWindow(hWnd, SW_SHOWMINIMIZED);\r
+               }\r
+\r
+               if (fake)\r
+               {\r
+                       WINDOWPLACEMENT p;\r
+\r
+                       Zero(&p, sizeof(p));\r
+                       p.length = sizeof(p);\r
+                       GetWindowPlacement(hWnd, &p);\r
+                       Copy(&cm->FakeWindowPlacement, &p, sizeof(WINDOWPLACEMENT));\r
+               }\r
+       }\r
+       FreeBuf(b);\r
+\r
+       if (fake)\r
+       {\r
+               SetWindowPos(hWnd, NULL, -200, -200, 100, 100,\r
+                       SWP_NOREDRAW | SWP_SHOWWINDOW);\r
+       }\r
+\r
+       // ステータスバー関係の初期化\r
+       cm->hMainWnd = hWnd;\r
+       cm->hStatusBar = CreateStatusWindowW(WS_CHILD |\r
+               (cm->HideStatusBar == false ? WS_VISIBLE : 0),\r
+               _UU("CM_TITLE"),\r
+               hWnd, S_STATUSBAR);\r
+\r
+       UniStrCpy(cm->StatudBar1, sizeof(cm->StatudBar1), _UU("CM_TITLE"));\r
+       UniStrCpy(cm->StatudBar2, sizeof(cm->StatudBar2), _UU("CM_CONN_NO"));\r
+       UniFormat(cm->StatudBar3, sizeof(cm->StatudBar3), _UU("CM_PRODUCT_NAME"), CEDAR_BUILD);\r
+\r
+       cm->Icon2 = LoadSmallIcon(ICO_SERVER_OFFLINE);\r
+       cm->Icon3 = LoadSmallIcon(ICO_VPN);\r
+\r
+       // アカウントリストの初期化\r
+       CmInitAccountList(hWnd);\r
+\r
+       // VLAN リストの初期化\r
+       CmInitVLanList(hWnd);\r
+\r
+       // 表示更新\r
+       CmRefreshEx(hWnd, true);\r
+\r
+       // 通知クライアントのスレッドを開始\r
+       CmInitNotifyClientThread();\r
+\r
+       // タイマー設定\r
+       SetTimer(hWnd, 1, 128, NULL);\r
+\r
+       // タスクトレイの初期化\r
+       if (cm->server_name == NULL)\r
+       {\r
+               if (cm->HideTrayIcon == false)\r
+               {\r
+                       CmInitTray(hWnd);\r
+               }\r
+       }\r
+\r
+       CmVoice("start");\r
+\r
+       if (startup_mode || a.EasyMode)\r
+       {\r
+               SetTimer(hWnd, 3, 1, NULL);\r
+       }\r
+\r
+       if (cm->import_file_name != NULL)\r
+       {\r
+               // 引数として指定されたファイルをインポートする\r
+               CmSendImportMessage(hWnd, cm->import_file_name, cm->CmSettingInitialFlag == CM_SETTING_INIT_NONE ? CM_IMPORT_FILENAME_MSG : CM_IMPORT_FILENAME_MSG_OVERWRITE);\r
+               /*if (a.LockMode == false)\r
+               {\r
+                       CmImportAccountMainEx(hWnd, cm->import_file_name, cm->CmSettingInitialFlag != CM_SETTING_INIT_NONE);\r
+               }\r
+               else\r
+               {\r
+                       MsgBox(cm->hEasyWnd ? cm->hEasyWnd : hWnd, MB_ICONEXCLAMATION, _UU("CM_VPN_FILE_IMPORT_NG"));\r
+               }*/\r
+       }\r
+\r
+       // CM_SETTING の適用\r
+       CmApplyCmSetting();\r
+\r
+       cm->StartupFinished = true;\r
+}\r
+\r
+// 通知クライアントのスレッドを開始\r
+void CmInitNotifyClientThread()\r
+{\r
+       cm->NotifyClient = CcConnectNotify(cm->Client);\r
+       if (cm->NotifyClient == false)\r
+       {\r
+               Close(cm->hMainWnd);\r
+               exit(0);\r
+       }\r
+       cm->NotifyClientThread = NewThread(CmNotifyClientThread, NULL);\r
+}\r
+\r
+// 通知クライアントスレッド\r
+void CmNotifyClientThread(THREAD *thread, void *param)\r
+{\r
+       NOTIFY_CLIENT *nc;\r
+       // 引数チェック\r
+       if (thread == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       nc = cm->NotifyClient;\r
+\r
+       // 次の通知を待機する\r
+       while (cm->Halt == false)\r
+       {\r
+               if (CcWaitNotify(nc))\r
+               {\r
+                       // メッセージ送信\r
+                       PostMessage(cm->hMainWnd, WM_CM_NOTIFY, 0, 0);\r
+               }\r
+               else\r
+               {\r
+                       // 切断された\r
+                       if (cm->Halt == false)\r
+                       {\r
+                               if (cm != NULL)\r
+                               {\r
+                                       CmFreeTrayExternal((void *)cm->hMainWnd);\r
+                               }\r
+                               CncExit();\r
+                               exit(0);\r
+                       }\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// 通知クライアントのスレッドを終了\r
+void CmFreeNotifyClientThread()\r
+{\r
+       cm->Halt = true;\r
+\r
+       // 切断\r
+       CcStopNotify(cm->NotifyClient);\r
+\r
+       // スレッド終了を待機する\r
+       WaitThread(cm->NotifyClientThread, INFINITE);\r
+\r
+       // コネクション終了\r
+       CcDisconnectNotify(cm->NotifyClient);\r
+       ReleaseThread(cm->NotifyClientThread);\r
+}\r
+\r
+// メインウインドウのサイズ変更\r
+void CmMainWindowOnSize(HWND hWnd)\r
+{\r
+       RECT r;\r
+       UINT client_width, client_height;\r
+       UINT status_height;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メインウインドウのクライアント領域のサイズを取得する\r
+       GetClientRect(hWnd, &r);\r
+       client_width = MAX(r.right - r.left, 0);\r
+       client_height = MAX(r.bottom - r.top, 0);\r
+\r
+       SendMsg(hWnd, S_STATUSBAR, WM_SIZE, 0, 0);\r
+\r
+       // ステータスバーのサイズを取得する\r
+       GetWindowRect(DlgItem(hWnd, S_STATUSBAR), &r);\r
+       status_height = MAX(r.bottom - r.top, 0);\r
+\r
+       if (cm->HideStatusBar == false)\r
+       {\r
+               client_height = MAX(client_height - status_height, 0);\r
+       }\r
+\r
+       MoveWindow(DlgItem(hWnd, L_ACCOUNT), 0, 0, client_width, client_height * 3 / 5 - 3, true);\r
+       MoveWindow(DlgItem(hWnd, L_VLAN), 0, client_height * 3 / 5, client_width, client_height * 2 / 5, true);\r
+\r
+       // ステータスバーの再描画\r
+       CmRedrawStatusBar(hWnd);\r
+}\r
+\r
+// 現在接続中のアカウントをすべて切断する\r
+void CmDisconnectAll(HWND hWnd)\r
+{\r
+       UINT i, num;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 警告を表示する\r
+       num = CmGetNumConnected(hWnd);\r
+       if (num == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsgBoxEx(hWnd, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2, _UU("CM_DISCONNECT_ALL"), num) == IDNO)\r
+       {\r
+               return;\r
+       }\r
+\r
+       cm->PositiveDisconnectFlag = true;\r
+\r
+       // 接続中のリストを作成する\r
+       o = NewListFast(NULL);\r
+\r
+       num = LvNum(hWnd, L_ACCOUNT);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               wchar_t *s = LvGetStr(hWnd, L_ACCOUNT, i, 1);\r
+               if (s != NULL)\r
+               {\r
+                       if (UniStrCmpi(s, _UU("CM_ACCOUNT_ONLINE")) == 0 || UniStrCmpi(s, _UU("CM_ACCOUNT_CONNECTING")) == 0)\r
+                       {\r
+                               Add(o, LvGetStr(hWnd, L_ACCOUNT, i, 0));\r
+                       }\r
+                       Free(s);\r
+               }\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               wchar_t *s = LIST_DATA(o, i);\r
+               if (s != NULL)\r
+               {\r
+                       CmDisconnect(hWnd, s);\r
+                       Free(s);\r
+               }\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// 現在接続中の接続設定数を取得する\r
+UINT CmGetNumConnected(HWND hWnd)\r
+{\r
+       UINT i, num, num_active;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       num_active = 0;\r
+       num = LvNum(hWnd, L_ACCOUNT);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               wchar_t *s = LvGetStr(hWnd, L_ACCOUNT, i, 1);\r
+               if (s != NULL)\r
+               {\r
+                       if (UniStrCmpi(s, _UU("CM_ACCOUNT_ONLINE")) == 0 || UniStrCmpi(s, _UU("CM_ACCOUNT_CONNECTING")) == 0)\r
+                       {\r
+                               num_active++;\r
+                       }\r
+                       Free(s);\r
+               }\r
+       }\r
+\r
+       return num_active;\r
+}\r
+\r
+// ステータスバー情報を更新\r
+void CmRefreshStatusBar(HWND hWnd)\r
+{\r
+       UINT num_active = CmGetNumConnected(hWnd);\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (num_active == 0)\r
+       {\r
+               UniStrCpy(cm->StatudBar2, sizeof(cm->StatudBar2), _UU("CM_CONN_NO"));\r
+               cm->Icon2 = LoadSmallIcon(ICO_SERVER_OFFLINE);\r
+       }\r
+       else\r
+       {\r
+               UniFormat(cm->StatudBar2, sizeof(cm->StatudBar2), _UU("CM_NUM_CONN_COUNT"), num_active);\r
+               cm->Icon2 = LoadSmallIcon(ICO_SERVER_ONLINE);\r
+       }\r
+\r
+       CmRedrawStatusBar(hWnd);\r
+}\r
+\r
+// ステータスバーの再描画\r
+void CmRedrawStatusBar(HWND hWnd)\r
+{\r
+       HWND h;\r
+       RECT r;\r
+       int width;\r
+       int x1, x2, x3;\r
+       int xx[3];\r
+       wchar_t tmp[MAX_SIZE];\r
+       HICON icon;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       h = cm->hStatusBar;\r
+\r
+       // ステータスバーの横幅を取得\r
+       GetWindowRect(h, &r);\r
+       width = MAX(r.right - r.left, 0);\r
+       x2 = 180;\r
+       x3 = 245;\r
+       x1 = MAX(width - x2 - x3, 0);\r
+\r
+       // 3 つの部分に分割する\r
+       xx[0] = x1;\r
+       xx[1] = x2 + x1;\r
+       xx[2] = x3 + x2 + x1;\r
+       SendMsg(h, 0, SB_SETPARTS, 3, (LPARAM)xx);\r
+\r
+       // アイコンを設定\r
+       icon = (HICON)SendMsg(h, 0, SB_GETICON, 1, 0);\r
+       if (icon != cm->Icon2)\r
+       {\r
+               SendMsg(h, 0, SB_SETICON, 1, (LPARAM)cm->Icon2);\r
+       }\r
+\r
+       icon = (HICON)SendMsg(h, 0, SB_GETICON, 2, 0);\r
+       if (icon != cm->Icon3)\r
+       {\r
+               SendMsg(h, 0, SB_SETICON, 2, (LPARAM)cm->Icon3);\r
+       }\r
+\r
+       // 文字列を設定\r
+       SendMsg(h, 0, SB_GETTEXTW, 0, (LPARAM)tmp);\r
+       if (UniStrCmp(tmp, cm->StatudBar1))\r
+       {\r
+               SendMsg(h, 0, SB_SETTEXTW, 0, (LPARAM)cm->StatudBar1);\r
+       }\r
+\r
+       SendMsg(h, 0, SB_GETTEXTW, 1, (LPARAM)tmp);\r
+       if (UniStrCmp(tmp, cm->StatudBar2))\r
+       {\r
+               SendMsg(h, 0, SB_SETTEXTW, 1, (LPARAM)cm->StatudBar2);\r
+       }\r
+\r
+       SendMsg(h, 0, SB_GETTEXTW, 2, (LPARAM)tmp);\r
+       if (UniStrCmp(tmp, cm->StatudBar3))\r
+       {\r
+               SendMsg(h, 0, SB_SETTEXTW, 2, (LPARAM)cm->StatudBar3);\r
+       }\r
+}\r
+\r
+// メインウインドウの位置情報を保存する\r
+void CmSaveMainWindowPos(HWND hWnd)\r
+{\r
+       WINDOWPLACEMENT p;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 設定の保存\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_REG_KEY, "HideStatusBar", cm->HideStatusBar);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_REG_KEY, "HideTrayIcon", cm->HideTrayIcon);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_REG_KEY, "IconView", cm->IconView);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_REG_KEY, "ShowGrid", cm->ShowGrid);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_REG_KEY, "DisableVoice", cm->DisableVoice);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_REG_KEY, "VoiceId", cm->VoiceId);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_REG_KEY, "VistaStyle", cm->VistaStyle);\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_REG_KEY, "ShowPort", cm->ShowPort);\r
+\r
+       // ウインドウ位置の保存\r
+       Zero(&p, sizeof(p));\r
+       p.length = sizeof(p);\r
+       GetWindowPlacement(hWnd, &p);\r
+\r
+       if (IsZero(&cm->FakeWindowPlacement, sizeof(cm->FakeWindowPlacement)) == false)\r
+       {\r
+               Copy(&p, &cm->FakeWindowPlacement, sizeof(cm->FakeWindowPlacement));\r
+       }\r
+\r
+       MsRegWriteBin(REG_CURRENT_USER, CM_REG_KEY, "WindowPlacement", &p, sizeof(p));\r
+\r
+       CmSaveAccountListPos(hWnd);\r
+       CmSaveVLanListPos(hWnd);\r
+}\r
+\r
+// メインウインドウを閉じる\r
+void CmMainWindowOnQuit(HWND hWnd)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (cm->TrayInited)\r
+       {\r
+               if (MsgBox(hWnd, MB_YESNO | MB_ICONQUESTION,\r
+                       _UU("CM_EXIT_MESSAGE")) == IDNO)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       if (cm->OnCloseDispatched)\r
+       {\r
+               return;\r
+       }\r
+       cm->OnCloseDispatched = true;\r
+\r
+       CmCloseEasy();\r
+\r
+       // トレイを解放\r
+       CmFreeTray(hWnd);\r
+\r
+       // メインウインドウの位置情報を保存する\r
+       CmSaveMainWindowPos(hWnd);\r
+\r
+       // ステータスウインドウを閉じる\r
+       for (i = 0;i < LIST_NUM(cm->StatusWindowList);i++)\r
+       {\r
+               HWND h = LIST_DATA(cm->StatusWindowList, i);\r
+               //EndDialog(h, 0);\r
+               PostMessage(h, WM_CLOSE, 0, 0);\r
+       }\r
+\r
+       ReleaseList(cm->StatusWindowList);\r
+       cm->StatusWindowList = NULL;\r
+\r
+       if (cm->WindowCount != 0)\r
+       {\r
+               // 強制終了\r
+               exit(0);\r
+       }\r
+\r
+       // 閉じる\r
+       CmFreeNotifyClientThread();\r
+\r
+       EndDialog(hWnd, false);\r
+}\r
+\r
+// 起動時に使用する mutex を開始\r
+bool CmStartStartupMutex()\r
+{\r
+       INSTANCE *o = NewSingleInstance(STARTUP_MUTEX_NAME);\r
+\r
+       if (o == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       cm->StartupMutex = o;\r
+\r
+       return true;\r
+}\r
+\r
+// 起動時に使用する mutex を解放\r
+void CmEndStartupMutex()\r
+{\r
+       if (cm->StartupMutex != NULL)\r
+       {\r
+               FreeSingleInstance(cm->StartupMutex);\r
+\r
+               cm->StartupMutex = NULL;\r
+       }\r
+}\r
+\r
+// メインウインドウ\r
+void MainCMWindow()\r
+{\r
+       HWND h;\r
+       wchar_t *s;\r
+       CM_SETTING a;\r
+\r
+       if (CmStartStartupMutex() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = CmGenerateMainWindowTitle();\r
+       h = SearchWindow(s);\r
+       Free(s);\r
+\r
+       Zero(&a, sizeof(a));\r
+       CcGetCmSetting(cm->Client, &a);\r
+       if (cm->server_name != NULL && a.EasyMode)\r
+       {\r
+               CmEndStartupMutex();\r
+               MsgBox(NULL, MB_ICONEXCLAMATION, _UU("CM_EASY_MODE_NOT_ON_REMOTE"));\r
+               return;\r
+       }\r
+\r
+       // 動作モードの変更\r
+       if (cm->CmSettingSupported)\r
+       {\r
+               if (cm->CmSettingInitialFlag == CM_SETTING_INIT_SELECT)\r
+               {\r
+                       if (h != NULL)\r
+                       {\r
+                               CmEndStartupMutex();\r
+                       }\r
+\r
+                       // 選択画面を表示\r
+                       CmSetting(NULL);\r
+\r
+                       if (h != NULL)\r
+                       {\r
+                               goto SEND_MESSAGES;\r
+                       }\r
+                       else\r
+                       {\r
+                               return;\r
+                       }\r
+               }\r
+               else if ((cm->CmSettingInitialFlag == CM_SETTING_INIT_EASY && cm->CmEasyModeSupported) || cm->CmSettingInitialFlag == CM_SETTING_INIT_NORMAL)\r
+               {\r
+                       // 状態遷移\r
+                       CM_SETTING a;\r
+\r
+                       Zero(&a, sizeof(a));\r
+                       CcGetCmSetting(cm->Client, &a);\r
+\r
+                       if (cm->CmSettingInitialFlag == CM_SETTING_INIT_EASY)\r
+                       {\r
+                               a.EasyMode = true;\r
+                       }\r
+                       else\r
+                       {\r
+                               a.EasyMode = false;\r
+                       }\r
+\r
+                       CcSetCmSetting(cm->Client, &a);\r
+               }\r
+       }\r
+\r
+       if (h == NULL)\r
+       {\r
+               // 他に同じタイトルのウインドウが無いのでウインドウを作成する\r
+               if (cm->server_name == NULL)\r
+               {\r
+                       CmInitTryToExecUiHelper();\r
+                       CnWaitForCnServiceReady();\r
+               }\r
+               Dialog(NULL, D_CM_MAIN, CmMainWindowProc, NULL);\r
+               CmFreeTryToExecUiHelper();\r
+       }\r
+       else\r
+       {\r
+SEND_MESSAGES:\r
+               CmEndStartupMutex();\r
+\r
+               // すでに同じタイトルのウインドウが存在する場合はそれをアクティブにして\r
+               // 自分自身は終了する\r
+               SetForegroundWindow(h);\r
+               SendMessage(h, WM_CM_SHOW, 0, 0);\r
+               SetForegroundWindow(h);\r
+\r
+               if (cm->CmSettingInitialFlag != CM_SETTING_INIT_NONE)\r
+               {\r
+                       // CM_SETTING が変更されたのでそれを通知する\r
+                       SendMessage(h, WM_CM_SETTING_CHANGED_MESSAGE, 0, 0);\r
+               }\r
+\r
+               if (cm->import_file_name != NULL)\r
+               {\r
+                       UINT msg;\r
+                       if (cm->CmSettingInitialFlag == CM_SETTING_INIT_NONE)\r
+                       {\r
+                               msg = CM_IMPORT_FILENAME_MSG;\r
+                       }\r
+                       else\r
+                       {\r
+                               msg = CM_IMPORT_FILENAME_MSG_OVERWRITE;\r
+                       }\r
+\r
+                       CmSendImportMessage(h, cm->import_file_name, msg);\r
+               }\r
+       }\r
+\r
+       CmEndStartupMutex();\r
+}\r
+\r
+// インポートメッセージの送信\r
+void CmSendImportMessage(HWND hWnd, wchar_t *filename, UINT msg)\r
+{\r
+       COPYDATASTRUCT cpy;\r
+       // 引数チェック\r
+       if (hWnd == NULL || filename == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // インポートすべきファイルを指定する\r
+       Zero(&cpy, sizeof(cpy));\r
+\r
+       cpy.cbData = UniStrSize(filename);\r
+       cpy.lpData = filename;\r
+       cpy.dwData = msg;\r
+\r
+       SendMessage(hWnd, WM_COPYDATA, 0, (LPARAM)&cpy);\r
+}\r
+\r
+// ログインダイアログ\r
+UINT CmLoginDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       // 引数チェック\r
+       wchar_t server_name[MAX_SIZE];\r
+       char password[MAX_PASSWORD_LEN + 1];\r
+       bool bad_pass;\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               if (cm->server_name != NULL)\r
+               {\r
+                       StrToUni(server_name, sizeof(server_name), cm->server_name);\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(server_name, sizeof(server_name), _UU("CM_PW_LOCALMACHINE"));\r
+               }\r
+               FormatText(hWnd, S_TITLE, server_name);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       if (cm->server_name != NULL)\r
+                       {\r
+                               StrToUni(server_name, sizeof(server_name), cm->server_name);\r
+                       }\r
+                       else\r
+                       {\r
+                               UniStrCpy(server_name, sizeof(server_name), _UU("CM_PW_LOCALMACHINE"));\r
+                       }\r
+                       GetTxtA(hWnd, E_PASSWORD, password, sizeof(password));\r
+                       cm->Client = CcConnectRpc(cm->server_name == NULL ? "127.0.0.1" : cm->server_name,\r
+                               password, &bad_pass, NULL, 0);\r
+                       if (cm->Client == NULL)\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONSTOP, _UU("CM_BAD_PASSWORD"));\r
+                               FocusEx(hWnd, E_PASSWORD);\r
+                       }\r
+                       else\r
+                       {\r
+                               EndDialog(hWnd, true);\r
+                       }\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ログイン\r
+bool LoginCM()\r
+{\r
+       // まず空のパスワードでログインを試みる\r
+       bool bad_pass, no_remote;\r
+       wchar_t server_name[MAX_SIZE];\r
+       RPC_CLIENT_VERSION a;\r
+\r
+RETRY:\r
+       if (cm->server_name != NULL)\r
+       {\r
+               StrToUni(server_name, sizeof(server_name), cm->server_name);\r
+       }\r
+       else\r
+       {\r
+               UniStrCpy(server_name, sizeof(server_name), _UU("CM_PW_LOCALMACHINE"));\r
+       }\r
+\r
+       // 接続試行\r
+       if ((cm->Client = CcConnectRpc(\r
+               cm->server_name == NULL ? "localhost" : cm->server_name,\r
+               "", &bad_pass, &no_remote, cm->StartupMode == false ? 0 : 60000)) == NULL)\r
+       {\r
+               if (no_remote)\r
+               {\r
+                       // リモート接続が拒否された\r
+                       if (MsgBoxEx(NULL, MB_ICONEXCLAMATION | MB_RETRYCANCEL, _UU("CM_NO_REMOTE"), server_name) == IDRETRY)\r
+                       {\r
+                               // 再試行\r
+                               goto RETRY;\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+               else if (bad_pass)\r
+               {\r
+                       if (Dialog(NULL, D_CM_LOGIN, CmLoginDlgProc, NULL) == false)\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // 接続失敗\r
+                       if (cm->StartupMode == false && MsgBoxEx(NULL, MB_ICONEXCLAMATION | MB_RETRYCANCEL, _UU("CM_CONNECT_FAILED"), server_name) == IDRETRY)\r
+                       {\r
+                               // 再試行\r
+                               goto RETRY;\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       Zero(&a, sizeof(a));\r
+       CcGetClientVersion(cm->Client, &a);\r
+       if (a.ClientBuildInt >= 5192)\r
+       {\r
+               cm->CmSettingSupported = true;\r
+               cm->CmEasyModeSupported = true;\r
+               if (OS_IS_WINDOWS_9X(a.OsType))\r
+               {\r
+                       cm->CmEasyModeSupported = false;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// メイン処理\r
+void MainCM()\r
+{\r
+       // 引数に /remote があればリモート接続の画面を出す\r
+       char *cmdline = GetCommandLineStr();\r
+\r
+       if (StrCmpi(cmdline, "/remote") == 0)\r
+       {\r
+               char *hostname = RemoteDlg(NULL, CM_REG_KEY, ICO_VPN, _UU("CM_TITLE"), _UU("CM_REMOTE_TITLE"), NULL);\r
+               if (hostname == NULL)\r
+               {\r
+                       return;\r
+               }\r
+               if (cm->server_name != NULL)\r
+               {\r
+                       Free(cm->server_name);\r
+               }\r
+               cm->server_name = NULL;\r
+               if (StrCmpi(hostname, "localhost") != 0 && StrCmpi(hostname, "127.0.0.1") != 0 )\r
+               {\r
+                       cm->server_name = hostname;\r
+               }\r
+       }\r
+\r
+       if (StrCmpi(cmdline, "/startup") == 0)\r
+       {\r
+               // スタートアップモード\r
+               cm->StartupMode = true;\r
+       }\r
+\r
+       Free(cmdline);\r
+\r
+       if (IsZero(cm->ShortcutKey, SHA1_SIZE) == false)\r
+       {\r
+               //if (MsGetCurrentTerminalSessionId() == 0)\r
+               {\r
+                       // ショートカット接続の開始\r
+                       CmConnectShortcut(cm->ShortcutKey);\r
+               }/*\r
+               else\r
+               {\r
+                       MsgBoxEx(NULL, MB_ICONEXCLAMATION, _UU("CM_SHORTCUT_DESKTOP_MSG"),\r
+                               MsGetCurrentTerminalSessionId());\r
+               }*/\r
+               return;\r
+       }\r
+\r
+       // ログイン\r
+       if (LoginCM() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       //ジャンプリストの更新\r
+       CmUpdateJumpList(0);\r
+\r
+       // メインウインドウ\r
+       MainCMWindow();\r
+\r
+       // ログアウト\r
+       LogoutCM();\r
+}\r
+\r
+// ログアウト\r
+void LogoutCM()\r
+{\r
+       if (cm->Client != NULL)\r
+       {\r
+               CcDisconnectRpc(cm->Client);\r
+       }\r
+}\r
+\r
+// クライアント接続マネージャ起動関数\r
+void CMExec()\r
+{\r
+       // 初期化\r
+       InitCM();\r
+\r
+       // メイン処理\r
+       MainCM();\r
+\r
+       // 解放\r
+       FreeCM();\r
+}\r
+\r
+// HUB 列挙スレッド\r
+void CmEnumHubThread(THREAD *t, void *param)\r
+{\r
+       CM_ENUM_HUB *e = (CM_ENUM_HUB *)param;\r
+       HWND hWnd;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       e->Thread = t;\r
+       hWnd = e->hWnd;\r
+       LockList(cm->EnumHubList);\r
+       {\r
+               Add(cm->EnumHubList, e);\r
+       }\r
+       UnlockList(cm->EnumHubList);\r
+\r
+       // スレッド初期化完了\r
+       NoticeThreadInit(t);\r
+\r
+       // セッション作成\r
+       e->Session = NewRpcSession(cm->Cedar, e->ClientOption);\r
+       if (e->Session)\r
+       {\r
+               // HUB の列挙\r
+               e->Hub = EnumHub(e->Session);\r
+\r
+               if (e->Hub != NULL)\r
+               {\r
+                       // 列挙完了\r
+                       // コンボボックスに追加する\r
+                       if (CbNum(hWnd, C_HUBNAME) == 0)\r
+                       {\r
+                               UINT i;\r
+                               wchar_t tmp[MAX_SIZE];\r
+                               for (i = 0;i < e->Hub->NumTokens;i++)\r
+                               {\r
+                                       StrToUni(tmp, sizeof(tmp), e->Hub->Token[i]);\r
+                                       CbAddStr(hWnd, C_HUBNAME, tmp, 0);\r
+                               }\r
+                       }\r
+\r
+                       // メモリ解放\r
+                       FreeToken(e->Hub);\r
+               }\r
+\r
+               // セッション解放\r
+               ReleaseSession(e->Session);\r
+       }\r
+\r
+       LockList(cm->EnumHubList);\r
+       {\r
+               Delete(cm->EnumHubList, e);\r
+       }\r
+       UnlockList(cm->EnumHubList);\r
+\r
+       Free(e->ClientOption);\r
+       Free(e);\r
+}\r
+\r
+// HUB 列挙の開始\r
+void CmEnumHubStart(HWND hWnd, CLIENT_OPTION *o)\r
+{\r
+       CM_ENUM_HUB *e;\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (StrLen(o->Hostname) == 0 ||\r
+               o->Port == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (o->ProxyType != PROXY_DIRECT)\r
+       {\r
+               if (StrLen(o->ProxyName) == 0 ||\r
+                       o->ProxyPort == 0)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       if (LvNum(hWnd, C_HUBNAME) != 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       e = ZeroMalloc(sizeof(CM_ENUM_HUB));\r
+       e->ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       e->hWnd = hWnd;\r
+       Copy(e->ClientOption, o, sizeof(CLIENT_OPTION));\r
+\r
+       t = NewThread(CmEnumHubThread, e);\r
+       WaitThreadInit(t);\r
+       ReleaseThread(t);\r
+}\r
+\r
+// HUB 列挙処理の初期化\r
+void CmInitEnumHub()\r
+{\r
+       cm->EnumHubList = NewList(NULL);\r
+}\r
+\r
+// HUB 列挙処理の解放\r
+void CmFreeEnumHub()\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       if (cm->EnumHubList == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o = NewList(NULL);\r
+       LockList(cm->EnumHubList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(cm->EnumHubList);i++)\r
+               {\r
+                       CM_ENUM_HUB *e = LIST_DATA(cm->EnumHubList, i);\r
+                       Add(o, e->Thread);\r
+                       AddRef(e->Thread->ref);\r
+               }\r
+       }\r
+       UnlockList(cm->EnumHubList);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               THREAD *t = LIST_DATA(o, i);\r
+               WaitThread(t, INFINITE);\r
+               ReleaseThread(t);\r
+       }\r
+       ReleaseList(o);\r
+\r
+       ReleaseList(cm->EnumHubList);\r
+}\r
+\r
+// クライアント接続マネージャの初期化\r
+#define APPID L"SoftEther.SoftEther UT-VPN Client"\r
+\r
+void InitCM()\r
+{\r
+       UNI_TOKEN_LIST *ut;\r
+       if (cm != NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       //Set Application ID\r
+       if(JL_SetCurrentProcessExplicitAppUserModelID(APPID) != S_OK)\r
+       {\r
+       }\r
+\r
+       CmDeleteOldStartupTrayFile();\r
+\r
+       MsSetShutdownParameters(0x4ff, SHUTDOWN_NORETRY);\r
+\r
+       // メモリ確保\r
+       cm = ZeroMalloc(sizeof(CM));\r
+\r
+       // コマンドライン引数が設定されている場合はサーバー名として取り扱う\r
+       ut = GetCommandLineUniToken();\r
+\r
+       if (ut->NumTokens >= 1)\r
+       {\r
+               if (UniStrLen(ut->Token[0]) != 0)\r
+               {\r
+                       if (UniStrCmpi(ut->Token[0], L"cm") != 0 && ut->Token[0][0] != L'/')\r
+                       {\r
+                               BUF *b = UniStrToBin(ut->Token[0]);\r
+                               if (b->Size == SHA1_SIZE)\r
+                               {\r
+                                       // 接続設定のショートカットキーとして扱う\r
+                                       Copy(cm->ShortcutKey, b->Buf, SHA1_SIZE);\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (UniEndWith(ut->Token[0], L".uvpn") == false)\r
+                                       {\r
+                                               // サーバー名として扱う\r
+                                               cm->server_name = CopyUniToStr(ut->Token[0]);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // インポートファイル名として扱う\r
+                                               cm->import_file_name = CopyUniStr(ut->Token[0]);\r
+                                       }\r
+                               }\r
+                               FreeBuf(b);\r
+                       }\r
+                       else if (UniStrCmpi(ut->Token[0], L"/easy") == 0)\r
+                       {\r
+                               // 簡易モード\r
+                               if (ut->NumTokens >= 2)\r
+                               {\r
+                                       // インポートすべき接続設定が指定されている\r
+                                       cm->import_file_name = CopyUniStr(ut->Token[1]);\r
+                               }\r
+\r
+                               cm->CmSettingInitialFlag = CM_SETTING_INIT_EASY;\r
+                       }\r
+                       else if (UniStrCmpi(ut->Token[0], L"/normal") == 0)\r
+                       {\r
+                               // 通常モード\r
+                               if (ut->NumTokens >= 2)\r
+                               {\r
+                                       // インポートすべき接続設定が指定されている\r
+                                       cm->import_file_name = CopyUniStr(ut->Token[1]);\r
+                               }\r
+\r
+                               cm->CmSettingInitialFlag = CM_SETTING_INIT_NORMAL;\r
+                       }\r
+                       else if (UniStrCmpi(ut->Token[0], L"/select") == 0)\r
+                       {\r
+                               // 選択画面\r
+                               cm->CmSettingInitialFlag = CM_SETTING_INIT_SELECT;\r
+                       }\r
+               }\r
+       }\r
+\r
+       UniFreeToken(ut);\r
+\r
+       InitWinUi(_UU("CM_TITLE"), _SS("DEFAULT_FONT"), _II("DEFAULT_FONT_SIZE"));\r
+\r
+       // アルファブレンディング関係\r
+       UseAlpha = MsRegReadInt(REG_CURRENT_USER, CM_REG_KEY, "UseAlpha");\r
+       AlphaValue = MsRegReadInt(REG_CURRENT_USER, CM_REG_KEY, "AlphaValue");\r
+\r
+       cm->Cedar = NewCedar(NULL, NULL);\r
+       CmInitEnumHub();\r
+}\r
+\r
+// クライアント接続マネージャの終了\r
+void FreeCM()\r
+{\r
+       if (cm == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CmFreeEnumHub();\r
+       ReleaseCedar(cm->Cedar);\r
+\r
+       FreeWinUi();\r
+\r
+       // メモリ解放\r
+       if (cm->server_name != NULL)\r
+       {\r
+               Free(cm->server_name);\r
+       }\r
+       Free(cm);\r
+       cm = NULL;\r
+}\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////////\r
+//JumpList ToDo\r
+// By Takao Ito\r
+void *CmUpdateJumpList(UINT start_id)\r
+{\r
+       HMENU h = NULL;\r
+       UINT i;\r
+       RPC_CLIENT_ENUM_ACCOUNT a;\r
+       LIST *o;\r
+       bool easy;\r
+\r
+       JL_PCustomDestinationList pcdl;\r
+       JL_PObjectCollection poc;\r
+       JL_PShellLink shell;\r
+       JL_PObjectArray poaRemoved;\r
+\r
+       HRESULT hr;\r
+\r
+       if (cm->server_name != NULL)\r
+       {\r
+               // 外部 PC の場合は利用しない\r
+               return NULL;\r
+       }\r
+\r
+       //試しに追加\r
+       if(SUCCEEDED(JL_CreateCustomDestinationList(&pcdl,APPID)))\r
+       {\r
+\r
+               JL_DeleteJumpList(pcdl,APPID);\r
+\r
+               easy = cm->CmSetting.EasyMode;\r
+\r
+               Zero(&a, sizeof(a));\r
+\r
+               \r
+               if (CcEnumAccount(cm->Client, &a) == ERR_NO_ERROR)\r
+               {\r
+                       o = NewListFast(CiCompareClientAccountEnumItemByLastConnectDateTime);\r
+\r
+                       for (i = 0;i < a.NumItem;i++)\r
+                       {\r
+                               RPC_CLIENT_ENUM_ACCOUNT_ITEM *item = a.Items[i];\r
+\r
+                               item->tmp1 = i;\r
+\r
+                               if (item->LastConnectDateTime != 0)\r
+                               {\r
+                                       Add(o, item);\r
+                               }\r
+                       }\r
+\r
+                       Sort(o);\r
+\r
+                       if(LIST_NUM(o) > 0)\r
+                       {\r
+\r
+                               if(SUCCEEDED(JL_BeginList(pcdl, &poaRemoved)))\r
+                               {\r
+\r
+\r
+                                       //コレクションの作成\r
+                                       if(SUCCEEDED(JL_CreateObjectCollection(&poc)))\r
+                                       {\r
+\r
+                                               for (i = 0;i < MIN(LIST_NUM(o), CM_NUM_RECENT);i++)\r
+                                               {\r
+\r
+                                                       RPC_CLIENT_ENUM_ACCOUNT_ITEM *item = (RPC_CLIENT_ENUM_ACCOUNT_ITEM *)LIST_DATA(o, i);\r
+//                                                     wchar_t tmp[MAX_PATH];\r
+                                                       wchar_t *account_name;\r
+                                                       char *server_name;\r
+                                                       char *hub_name;\r
+//                                                     CM_ACCOUNT *a;\r
+                                                       UCHAR key[SHA1_SIZE];\r
+                                                       RPC_CLIENT_GET_ACCOUNT c;\r
+\r
+\r
+                                                       account_name = item->AccountName;\r
+                                                       server_name = item->ServerName;\r
+                                                       hub_name = item->HubName;\r
+\r
+\r
+\r
+                                                       //\r
+                                                       //a = CmGetExistAccountObject(hWnd, account_name);\r
+\r
+\r
+                                                       //if (a == NULL)\r
+                                                       //{\r
+                                                       //continue;\r
+                                                       //}\r
+\r
+                                                       //Copy(key, a->ShortcutKey, SHA1_SIZE);\r
+                                                       //\r
+\r
+                                                       Zero(&c, sizeof(c));\r
+                                                       UniStrCpy(c.AccountName, sizeof(c.AccountName), account_name);\r
+                                                       if (CALL(NULL, CcGetAccount(cm->Client, &c)) == false)\r
+                                                       {\r
+                                                               break;\r
+                                                       }\r
+\r
+                                                       Copy(key, c.ShortcutKey, SHA1_SIZE);\r
+\r
+                                                       if (IsZero(key, SHA1_SIZE))\r
+                                                       {\r
+                                                               //MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_SHORTCUT_UNSUPPORTED"));\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+\r
+                                                               //wchar_t target[MAX_PATH];\r
+                                                               ////wchar_t workdir[MAX_PATH];\r
+                                                               //wchar_t args[MAX_PATH];\r
+                                                               ////wchar_t comment[MAX_SIZE];\r
+                                                               //wchar_t icon[MAX_PATH];\r
+\r
+                                                               char key_str[64];\r
+                                                               wchar_t target[MAX_PATH];\r
+                                                               //wchar_t workdir[MAX_PATH];\r
+                                                               wchar_t args[MAX_PATH];\r
+                                                               wchar_t commentW[MAX_SIZE];\r
+                                                               wchar_t icon[MAX_PATH];\r
+                                                               int iconNum;\r
+\r
+                                                               //char icon = "C:\\Server.ico";\r
+\r
+                                                               BinToStr(key_str, sizeof(key_str), key, SHA1_SIZE);\r
+                                                               UniStrCpy(target, sizeof(target), MsGetExeFileNameW());\r
+                                                               StrToUni(args, sizeof(args), key_str);\r
+                                                               UniStrCpy(icon, sizeof(icon), MsGetExeFileNameW());\r
+                                                               UniFormat(commentW, sizeof(commentW), _UU("CM_SHORTCUT_COMMENT"), account_name);\r
+\r
+                                                               if(item->Connected)\r
+                                                               {\r
+                                                                       iconNum = 1;\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       iconNum = 2;\r
+                                                               }\r
+\r
+                                                               hr = JL_CreateShellLink(\r
+                                                                       target,\r
+                                                                       args,\r
+                                                                       account_name,\r
+                                                                       icon,iconNum,\r
+                                                                       commentW,\r
+                                                                       &shell);\r
+\r
+                                                               if(SUCCEEDED(hr))\r
+                                                               {\r
+\r
+                                                                       if(SUCCEEDED(JL_ObjectCollectionAddShellLink(poc, shell)))\r
+                                                                       {\r
+                                                                               //Print("Add JumpList %d c:%s\n",i, comment);\r
+                                                                               //wprintf(comment);\r
+                                                                       }\r
+                                                                       JL_ReleaseShellLink(shell);\r
+                                                               }\r
+                                                       }\r
+\r
+                                                       CiFreeClientGetAccount(&c);\r
+                                               }\r
+\r
+                                               hr = JL_AddCategoryToList(pcdl,poc,_UU("CM_JUMPLIST_RCCONNECT"),poaRemoved);\r
+\r
+                                               if(SUCCEEDED(hr))\r
+                                               {\r
+                                                       //wprintf(L"AddCategory\n");\r
+\r
+                                                       hr = JL_CommitList(pcdl);\r
+                                                       if(SUCCEEDED(hr))\r
+                                                       {\r
+                                                               //wprintf(L"JumpList Commit\n");\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       //wprintf(L"Erro JumpList AddCategory %x\n", hr);\r
+                                               }\r
+\r
+                                               //リリース\r
+                                               JL_ReleaseObjectCollection(poc);\r
+                                       }\r
+                               }\r
+\r
+                       }\r
+\r
+\r
+                       ReleaseList(o);\r
+\r
+                       CiFreeClientEnumAccount(&a);\r
+               }\r
+\r
+               \r
+\r
+\r
+               /*\r
+                       JL_BeginList(pcdl, &poaRemoved);\r
+\r
+                       JL_CreateObjectCollection(&poc);\r
+\r
+                       //てしゅと\r
+                       for (i = 0; i < 5; i++)\r
+                       {\r
+\r
+                               JL_CreateShellLink(\r
+                                       "",\r
+                                       "",\r
+                                       L"せつぞく",\r
+                                       NULL,0,\r
+                                       NULL,\r
+                                       &shell);\r
+                               JL_ObjectCollectionAddShellLink(poc, shell);\r
+\r
+                               JL_ReleaseShellLink(shell);\r
+\r
+                       }\r
+\r
+                       JL_AddCategoryToList(pcdl,poc,_UU("CM_JUMPLIST_RCCONNECT"),poaRemoved);\r
+                       JL_CommitList(pcdl);\r
+                       JL_ReleaseObjectCollection(poc);\r
+\r
+               JL_ReleaseCustomDestinationList(pcdl);\r
+               */\r
+\r
+       }\r
+\r
+       return h;\r
+}\r
+\r
+\r
+\r
+#endif // WIN32\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/CM.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/CM.h
new file mode 100644 (file)
index 0000000..0f73f8e
--- /dev/null
@@ -0,0 +1,124 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// CM.h\r
+// CM.c のヘッダ\r
+\r
+#ifndef        CM_H\r
+#define        CM_H\r
+\r
+// 定数\r
+#define        CM_REG_KEY                      "Software\\SoftEther Corporation\\UT-VPN\\Client Manager"\r
+#define        SECURE_MANAGER_KEY      "Software\\SoftEther Corporation\\UT-VPN\\SmartCard Manager"\r
+#define        CM_TRAFFIC_REG_KEY      "Software\\SoftEther Corporation\\UT-VPN\\Traffic Test Tool"\r
+\r
+\r
+#define        CM_TRY_EXEC_UI_HELPER_INTERVAL          5000\r
+\r
+#define        CM_DEFAULT_WIDTH        800\r
+#define        CM_DEFAULT_HEIGHT       600\r
+\r
+#define        WM_CM_NOTIFY            (WM_APP + 999)\r
+\r
+#define        CM_IMPORT_FILENAME_MSG  1267\r
+#define        CM_IMPORT_FILENAME_MSG_OVERWRITE        1268\r
+\r
+#define        CM_NUM_RECENT           8\r
+\r
+#define        PUBLIC_SERVER_HTML      "http://www.softether.com/jp/special/se2hub.aspx"\r
+#define PUBLIC_SERVER_HTML_EN "http://www.softether.com/jp/special/se2hub_en.aspx"\r
+#define        PUBLIC_SERVER_TAG       L"help:no; status:no; DialogWidth:600px; dialogHeight=700px"\r
+#define        PUBLIC_SERVER_NAME      "public.softether.com"\r
+\r
+#define        VOICE_SSK                       0       // 佐々木さん (真面目)\r
+#define        VOICE_AHO                       1       // 佐々木さん (ユニーク)\r
+\r
+// 外部エクスポート用コード\r
+\r
+// 構造体\r
+\r
+// 関数プロトタイプ\r
+void CMExec();\r
+void CmTraffic(HWND hWnd);\r
+void *CmStartUacHelper();\r
+void CmStopUacHelper(void *p);\r
+void *CmExecUiHelperMain();\r
+UINT CmGetSecureBitmapId(char *dest_hostname);\r
+\r
+#endif // CM_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/CMInner.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/CMInner.h
new file mode 100644 (file)
index 0000000..34e9e3c
--- /dev/null
@@ -0,0 +1,600 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// CMInner.h\r
+// CM.c の内部向けヘッダ\r
+\r
+#define STARTUP_MUTEX_NAME     "utvpncmgr_startup_mutex"\r
+\r
+void CmVoice(char *name);\r
+\r
+typedef struct CM_UAC_HELPER\r
+{\r
+       THREAD *Thread;\r
+       volatile bool Halt;\r
+       EVENT *HaltEvent;\r
+} CM_UAC_HELPER;\r
+\r
+typedef struct CM_VOICE\r
+{\r
+       UINT voice_id;\r
+       char *perfix;\r
+} CM_VOICE;\r
+\r
+static CM_VOICE cm_voice[] =\r
+{\r
+       {VOICE_SSK,             "ssk"           },\r
+       {VOICE_AHO,             "aho"           },\r
+};\r
+\r
+typedef struct CM_ENUM_HUB\r
+{\r
+       HWND hWnd;\r
+       THREAD *Thread;\r
+       SESSION *Session;\r
+       CLIENT_OPTION *ClientOption;\r
+       TOKEN_LIST *Hub;\r
+} CM_ENUM_HUB;\r
+\r
+#define CM_SETTING_INIT_NONE           0\r
+#define CM_SETTING_INIT_EASY           1       // 簡易モードへ遷移\r
+#define CM_SETTING_INIT_NORMAL         2       // 通常モードへ遷移\r
+#define CM_SETTING_INIT_SELECT         3       // 選択画面を表示\r
+\r
+typedef struct CM\r
+{\r
+       HWND hMainWnd;\r
+       HWND hStatusBar;\r
+       REMOTE_CLIENT *Client;\r
+       char *server_name;\r
+       wchar_t *import_file_name;\r
+       bool HideStatusBar;\r
+       bool HideTrayIcon;\r
+       bool ShowGrid;\r
+       bool VistaStyle;\r
+       bool ShowPort;\r
+       wchar_t StatudBar1[MAX_SIZE];\r
+       wchar_t StatudBar2[MAX_SIZE];\r
+       wchar_t StatudBar3[MAX_SIZE];\r
+       HICON Icon2, Icon3;\r
+       bool IconView;\r
+       THREAD *NotifyClientThread;\r
+       NOTIFY_CLIENT *NotifyClient;\r
+       volatile bool Halt;\r
+       bool OnCloseDispatched;\r
+       LIST *StatusWindowList;\r
+       CEDAR *Cedar;\r
+       LIST *EnumHubList;\r
+       UINT WindowCount;\r
+       bool DisableVoice;\r
+       UINT VoiceId;\r
+       UINT OldConnectedNum;\r
+       bool UpdateConnectedNumFlag;\r
+       UCHAR ShortcutKey[SHA1_SIZE];\r
+       bool TrayInited;\r
+       bool TrayAnimation;\r
+       bool TraySpeedAnimation;\r
+       UINT TrayAnimationCounter;\r
+       bool StartupMode;\r
+       THREAD *TryExecUiHelperThread;\r
+       volatile bool TryExecUiHelperHalt;\r
+       HANDLE TryExecUiHelperProcessHandle;\r
+       EVENT *TryExecUiHelperHaltEvent;\r
+       bool WindowsShutdowning;\r
+       bool CmSettingSupported;\r
+       bool CmEasyModeSupported;\r
+       bool CmSettingInitialFlag;\r
+       CM_SETTING CmSetting;\r
+       HWND hEasyWnd;\r
+       bool StartupFinished;\r
+       bool ConnectStartedFlag;\r
+       bool PositiveDisconnectFlag;\r
+       wchar_t EasyLastSelectedAccountName[MAX_ACCOUNT_NAME_LEN + 1];\r
+       WINDOWPLACEMENT FakeWindowPlacement;\r
+       INSTANCE *StartupMutex;\r
+       bool BadProcessChecked;\r
+       bool MenuPopuping;\r
+       bool SplashHasBeenShown;\r
+} CM;\r
+\r
+typedef struct CM_STATUS\r
+{\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];          // アカウント名\r
+       HWND hWndPolicy;                                        // ポリシーダイアログ\r
+} CM_STATUS;\r
+\r
+typedef struct CM_POLICY\r
+{\r
+       HWND hWnd;\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];          // アカウント名\r
+       POLICY *Policy;                                         // ポリシーダイアログ\r
+       CM_STATUS *CmStatus;                            // CM_STATUS\r
+       bool Extension;                                         // 拡張\r
+} CM_POLICY;\r
+\r
+typedef struct CM_ACCOUNT\r
+{\r
+       bool EditMode;                                          // 編集モード (false: 新規作成モード)\r
+       bool LinkMode;                                          // リンクモード\r
+       bool NatMode;                                           // NAT モード\r
+       CLIENT_OPTION *ClientOption;            // クライアントオプション\r
+       CLIENT_AUTH *ClientAuth;                        // 認証データ\r
+       bool Startup;                                           // スタートアップアカウント\r
+       bool CheckServerCert;                           // サーバー証明書のチェック\r
+       X *ServerCert;                                          // サーバー証明書\r
+       char old_server_name[MAX_HOST_NAME_LEN + 1];    // 古いサーバー名\r
+       bool Inited;                                            // 初期化フラグ\r
+       POLICY Policy;                                          // ポリシー (リンクモードのみ)\r
+       struct SM_HUB *Hub;                                     // HUB\r
+       RPC *Rpc;                                                       // RPC\r
+       bool OnlineFlag;                                        // オンライン フラグ\r
+       bool Flag1;                                                     // フラグ 1\r
+       bool HideClientCertAuth;                        // クライアント認証を隠す\r
+       bool HideSecureAuth;                            // スマートカード認証を隠す\r
+       bool HideTrustCert;                                     // 信頼する証明機関ボタンを隠す\r
+       UCHAR ShortcutKey[SHA1_SIZE];           // ショートカットキー\r
+       bool LockMode;                                          // 設定ロックモード\r
+       bool Link_ConnectNow;                           // すぐに接続を開始する\r
+       UINT PolicyVer;                                         // ポリシーバージョン\r
+} CM_ACCOUNT;\r
+\r
+typedef struct CM_CHANGE_PASSWORD\r
+{\r
+       CLIENT_OPTION *ClientOption;            // クライアントオプション\r
+       char Username[MAX_USERNAME_LEN + 1];    // ユーザー名\r
+       char HubName[MAX_HUBNAME_LEN + 1];              // HUB 名\r
+} CM_CHANGE_PASSWORD;\r
+\r
+typedef struct CM_TRAFFIC\r
+{\r
+       bool ServerMode;                // サーバーモード\r
+       bool Double;                    // 2 倍モード\r
+       bool Raw;                               // 生データモード\r
+       UINT Port;                              // ポート番号\r
+       char Host[MAX_HOST_NAME_LEN + 1];       // ホスト名\r
+       UINT NumTcp;                    // TCP コネクション数\r
+       UINT Type;                              // 種類\r
+       UINT Span;                              // 期間\r
+} CM_TRAFFIC;\r
+\r
+typedef struct CM_TRAFFIC_DLG\r
+{\r
+       HWND hWnd;                              // ウインドウハンドル\r
+       CM_TRAFFIC *Setting;    // 設定\r
+       TTS *Tts;                               // 測定サーバー\r
+       TTC *Ttc;                               // 測定クライアント\r
+       THREAD *HaltThread;             // 停止用スレッド\r
+       THREAD *ClientEndWaitThread;    // クライアントが終了するのを待機するスレッド\r
+       bool Started;                   // 開始フラグ\r
+       bool Stopping;                  // 停止中\r
+       UINT RetCode;                   // 戻り値\r
+       TT_RESULT Result;               // 結果\r
+       EVENT *ResultShowEvent; // 結果表示イベント\r
+       bool CloseDialogAfter;  // ダイアログを閉じるかどうかのフラグ\r
+} CM_TRAFFIC_DLG;\r
+\r
+// インターネット接続設定\r
+typedef struct CM_INTERNET_SETTING\r
+{\r
+       UINT ProxyType;                                                         // プロキシサーバーの種類\r
+       char ProxyHostName[MAX_HOST_NAME_LEN + 1];      // プロキシサーバーホスト名\r
+       UINT ProxyPort;                                                         // プロキシサーバーポート番号\r
+       char ProxyUsername[MAX_USERNAME_LEN + 1];       // プロキシサーバーユーザー名\r
+       char ProxyPassword[MAX_USERNAME_LEN + 1];       // プロキシサーバーパスワード\r
+} CM_INTERNET_SETTING;\r
+\r
+static CM *cm = NULL;\r
+\r
+void CmFreeTrayExternal(void *hWnd);\r
+\r
+// 通常 RPC 呼び出しマクロ\r
+__forceinline static bool CALL(HWND hWnd, UINT code)\r
+{\r
+       UINT ret = code;\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               if (ret == ERR_DISCONNECTED)\r
+               {\r
+                       if (cm != NULL)\r
+                       {\r
+                               Close(cm->hMainWnd);\r
+                       }\r
+                       else\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONSTOP, _UU("SM_DISCONNECTED"));\r
+                       }\r
+\r
+                       if (cm != NULL)\r
+                       {\r
+                               CmFreeTrayExternal((void *)cm->hMainWnd);\r
+                       }\r
+                       exit(0);\r
+               }\r
+               else\r
+               {\r
+                       UINT flag = MB_ICONEXCLAMATION;\r
+                       if (ret == ERR_VLAN_IS_USED)\r
+                       {\r
+                               CmVoice("using_vlan");\r
+                       }\r
+                       if (hWnd != NULL && cm != NULL && cm->hEasyWnd != NULL)\r
+                       {\r
+                               hWnd = cm->hEasyWnd;\r
+                       }\r
+                       if (hWnd != NULL && cm != NULL && hWnd == cm->hEasyWnd)\r
+                       {\r
+                               flag |= MB_SETFOREGROUND | MB_TOPMOST;\r
+                       }\r
+                       MsgBox(hWnd, flag, _E(ret));\r
+               }\r
+       }\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// 拡張 RPC 呼び出しマクロ (エラー値を取得する)\r
+__forceinline static UINT CALLEX(HWND hWnd, UINT code)\r
+{\r
+       UINT ret = code;\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               if (ret == ERR_DISCONNECTED)\r
+               {\r
+                       if (cm != NULL)\r
+                       {\r
+                               Close(cm->hMainWnd);\r
+                       }\r
+                       else\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONSTOP, _UU("SM_DISCONNECTED"));\r
+                       }\r
+                       if (cm != NULL)\r
+                       {\r
+                               CmFreeTrayExternal((void *)cm->hMainWnd);\r
+                       }\r
+                       exit(0);\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+typedef struct CM_LOADX\r
+{\r
+       X *x;\r
+} CM_LOADX;\r
+\r
+typedef struct CM_SETTING_DLG\r
+{\r
+       bool CheckPassword;\r
+       UCHAR HashedPassword[SHA1_SIZE];\r
+} CM_SETTING_DLG;\r
+\r
+typedef struct CM_EASY_DLG\r
+{\r
+       bool EndDialogCalled;\r
+} CM_EASY_DLG;\r
+\r
+\r
+// タスクトレイ関係\r
+#define        WM_CM_TRAY_MESSAGE                      (WM_APP + 44)\r
+#define WM_CM_SETTING_CHANGED_MESSAGE  (WM_APP + 45)\r
+#define WM_CM_EASY_REFRESH                     (WM_APP + 46)\r
+#define WM_CM_SHOW                                     (WM_APP + 47)\r
+#define        CMD_EASY_DBLCLICK                       40697\r
+#define        CM_TRAY_ANIMATION_INTERVAL      3000\r
+#define        CM_TRAY_MAX_ITEMS                       4096\r
+#define        CM_TRAY_MENU_ID_START           12000\r
+#define        CM_TRAY_MENU_CONNECT_ID_START   (CM_TRAY_MENU_ID_START + CM_TRAY_MAX_ITEMS)\r
+#define        CM_TRAY_MENU_STATUS_ID_START    (CM_TRAY_MENU_CONNECT_ID_START + CM_TRAY_MAX_ITEMS)\r
+#define        CM_TRAY_MENU_DISCONNECT_ID_START        (CM_TRAY_MENU_STATUS_ID_START + CM_TRAY_MAX_ITEMS)\r
+#define        CM_TRAY_MENU_RECENT_ID_START    (CM_TRAY_MENU_DISCONNECT_ID_START + CM_TRAY_MAX_ITEMS)\r
+#define        CM_TRAY_IS_CONNECT_ID(id)       (((id) >= CM_TRAY_MENU_CONNECT_ID_START) && (id) < CM_TRAY_MENU_STATUS_ID_START)\r
+#define        CM_TRAY_IS_STATUS_ID(id)        (((id) >= CM_TRAY_MENU_STATUS_ID_START) && (id) < CM_TRAY_MENU_DISCONNECT_ID_START)\r
+#define        CM_TRAY_IS_DISCONNECT_ID(id)    (((id) >= CM_TRAY_MENU_DISCONNECT_ID_START) && (id) < (CM_TRAY_MENU_DISCONNECT_ID_START + CM_TRAY_MAX_ITEMS))\r
+#define        CM_TRAY_IS_RECENT_ID(id)        (((id) >= CM_TRAY_MENU_RECENT_ID_START) && (id) < (CM_TRAY_MENU_RECENT_ID_START + CM_TRAY_MAX_ITEMS))\r
+\r
+// スプラッシュスクリーンの枠線の色\r
+#define        CM_SPLASH_BORDER_COLOR  (RGB(102, 0, 204))\r
+\r
+\r
+// 関数プロトタイプ\r
+void InitCM();\r
+void FreeCM();\r
+void MainCM();\r
+bool LoginCM();\r
+void LogoutCM();\r
+UINT CmLoginDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void MainCMWindow();\r
+void CmSendImportMessage(HWND hWnd, wchar_t *filename, UINT msg);\r
+UINT CmMainWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmMainWindowOnSize(HWND hWnd);\r
+void CmMainWindowOnInit(HWND hWnd);\r
+void CmMainWindowOnQuit(HWND hWnd);\r
+void CmSaveMainWindowPos(HWND hWnd);\r
+void CmMainWindowOnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);\r
+void CmMainWindowOnCommandEx(HWND hWnd, WPARAM wParam, LPARAM lParam, bool easy);\r
+bool CmIsEnabled(HWND hWnd, UINT id);\r
+bool CmIsChecked(UINT id);\r
+bool CmIsBold(UINT id);\r
+void CmMainWindowOnPopupMenu(HWND hWnd, HMENU hMenu, UINT pos);\r
+void CmSaveMainWindowPos(HWND hWnd);\r
+void CmRedrawStatusBar(HWND hWnd);\r
+void CmRefresh(HWND hWnd);\r
+void CmRefreshEx(HWND hWnd, bool style_changed);\r
+void CmSetForegroundProcessToCnService();\r
+void CmInitAccountList(HWND hWnd);\r
+void CmInitAccountListEx(HWND hWnd, bool easy);\r
+void CmInitVLanList(HWND hWnd);\r
+void CmRefreshAccountList(HWND hWnd);\r
+void CmRefreshAccountListEx(HWND hWnd, bool easy);\r
+void CmRefreshAccountListEx2(HWND hWnd, bool easy, bool style_changed);\r
+void CmRefreshVLanList(HWND hWnd);\r
+void CmRefreshVLanListEx(HWND hWnd, bool style_changed);\r
+void CmSaveAccountListPos(HWND hWnd);\r
+void CmSaveVLanListPos(HWND hWnd);\r
+wchar_t *CmGetProtocolName(UINT n);\r
+void CmVLanNameToPrintName(char *str, UINT size, char *name);\r
+bool CmPrintNameToVLanName(char *name, UINT size, char *str);\r
+void CmMainWindowOnNotify(HWND hWnd, NMHDR *n);\r
+void CmOnKey(HWND hWnd, bool ctrl, bool alt, UINT key);\r
+void CmAccountListRightClick(HWND hWnd);\r
+void CmVLanListRightClick(HWND hWnd);\r
+void CmConnect(HWND hWnd, wchar_t *account_name);\r
+void CmDisconnect(HWND hWnd, wchar_t *account_name);\r
+void CmInitNotifyClientThread();\r
+void CmFreeNotifyClientThread();\r
+void CmNotifyClientThread(THREAD *thread, void *param);\r
+void CmDeleteAccount(HWND hWnd, wchar_t *account_name);\r
+void CmStatus(HWND hWnd, wchar_t *account_name);\r
+void CmStatusDlg(HWND hWnd, wchar_t *account_name);\r
+UINT CmStatusDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmStatusDlgPrint(HWND hWnd, CM_STATUS *cmst);\r
+void CmPrintStatusToListView(LVB *b, RPC_CLIENT_GET_CONNECTION_STATUS *s);\r
+void CmPrintStatusToListViewEx(LVB *b, RPC_CLIENT_GET_CONNECTION_STATUS *s, bool server_mode);\r
+void CmStatusDlgPrintCert(HWND hWnd, CM_STATUS *st, bool server);\r
+void CmPolicyDlg(HWND hWnd, CM_STATUS *st);\r
+UINT CmPolicyDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmPolicyDlgPrint(HWND hWnd, CM_POLICY *p);\r
+void CmPolicyDlgPrintEx(HWND hWnd, CM_POLICY *p, bool cascade_mode);\r
+void CmPolicyDlgPrintEx2(HWND hWnd, CM_POLICY *p, bool cascade_mode, bool ver);\r
+void CmNewAccount(HWND hWnd);\r
+void CmEditAccount(HWND hWnd, wchar_t *account_name);\r
+void CmGenerateNewAccountName(HWND hWnd, wchar_t *name, UINT size);\r
+void CmGenerateCopyName(HWND hWnd, wchar_t *name, UINT size, wchar_t *old_name);\r
+void CmGenerateImportName(HWND hWnd, wchar_t *name, UINT size, wchar_t *old_name);\r
+CM_ACCOUNT *CmCreateNewAccountObject(HWND hWnd);\r
+CM_ACCOUNT *CmGetExistAccountObject(HWND hWnd, wchar_t *account_name);\r
+void CmEnumHubStart(HWND hWnd, CLIENT_OPTION *o);\r
+void CmInitEnumHub();\r
+void CmFreeEnumHub();\r
+void CmFreeAccountObject(HWND hWnd, CM_ACCOUNT *a);\r
+bool CmEditAccountDlg(HWND hWnd, CM_ACCOUNT *a);\r
+UINT CmEditAccountDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmEditAccountDlgUpdate(HWND hWnd, CM_ACCOUNT *a);\r
+void CmEditAccountDlgInit(HWND hWnd, CM_ACCOUNT *a);\r
+void CmEditAccountDlgOnOk(HWND hWnd, CM_ACCOUNT *a);\r
+void CmEditAccountDlgStartEnumHub(HWND hWnd, CM_ACCOUNT *a);\r
+bool CmLoadXAndK(HWND hWnd, X **x, K **k);\r
+bool CmLoadK(HWND hWnd, K **k);\r
+bool CmLoadKEx(HWND hWnd, K **k, char *filename, UINT size);\r
+bool CmLoadKExW(HWND hWnd, K **k, wchar_t *filename, UINT size);\r
+bool CmLoadXFromFileOrSecureCard(HWND hWnd, X **x);\r
+void CmLoadXFromFileOrSecureCardDlgInit(HWND hWnd, CM_LOADX *p);\r
+void CmLoadXFromFileOrSecureCardDlgUpdate(HWND hWnd, CM_LOADX *p);\r
+UINT CmLoadXFromFileOrSecureCardDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+bool CmLoadX(HWND hWnd, X **x);\r
+bool CmLoadXEx(HWND hWnd, X **x, char *filename, UINT size);\r
+bool CmLoadXExW(HWND hWnd, X **x, wchar_t *filename, UINT size);\r
+X *CmGetIssuer(X *x);\r
+bool CmProxyDlg(HWND hWnd, CLIENT_OPTION *a);\r
+void CmProxyDlgUpdate(HWND hWnd, CLIENT_OPTION *a);\r
+UINT CmProxyDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+bool CmDetailDlg(HWND hWnd, CM_ACCOUNT *a);\r
+UINT CmDetailDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+char *CmNewVLanDlg(HWND hWnd);\r
+UINT CmNewVLanDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmCopyAccount(HWND hWnd, wchar_t *account_name);\r
+void CmExportAccount(HWND hWnd, wchar_t *account_name);\r
+void CmSortcut(HWND hWnd, wchar_t *account_name);\r
+void CmImportAccount(HWND hWnd);\r
+void CmImportAccountMain(HWND hWnd, wchar_t *filename);\r
+void CmImportAccountMainEx(HWND hWnd, wchar_t *filename, bool overwrite);\r
+void CmTrustDlg(HWND hWnd);\r
+UINT CmTrustDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmTrustDlgUpdate(HWND hWnd);\r
+void CmTrustDlgRefresh(HWND hWnd);\r
+void CmTrustImport(HWND hWnd);\r
+void CmTrustExport(HWND hWnd);\r
+void CmTrustView(HWND hWnd);\r
+void CmPassword(HWND hWnd);\r
+UINT CmPasswordProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmPasswordRefresh(HWND hWnd);\r
+void CmRefreshStatusBar(HWND hWnd);\r
+UINT CmGetNumConnected(HWND hWnd);\r
+void CmDisconnectAll(HWND hWnd);\r
+wchar_t *CmGenerateMainWindowTitle();\r
+void CmConfigDlg(HWND hWnd);\r
+UINT CmConfigDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmConfigDlgInit(HWND hWnd);\r
+void CmConfigDlgRefresh(HWND hWnd);\r
+void CmConfigDlgOnOk(HWND hWnd);\r
+bool CmWarningDesktop(HWND hWnd, wchar_t *account_name);\r
+UINT CmDesktopDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmDesktopDlgInit(HWND hWnd, wchar_t *account_name);\r
+void CmChangePassword(HWND hWnd, CLIENT_OPTION *o, char *hubname, char *username);\r
+UINT CmChangePasswordProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmChangePasswordUpdate(HWND hWnd, CM_CHANGE_PASSWORD *p);\r
+void SmShowPublicVpnServerHtml(HWND hWnd);\r
+void CmConnectShortcut(UCHAR *key);\r
+UINT CmSelectSecure(HWND hWnd, UINT current_id);\r
+void CmClientSecureManager(HWND hWnd);\r
+UINT CmClientSelectSecure(HWND hWnd);\r
+UINT CmSelectSecureDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmSelectSecureDlgInit(HWND hWnd, UINT default_id);\r
+void CmSelectSecureDlgUpdate(HWND hWnd);\r
+void CmSecureManager(HWND hWnd, UINT id);\r
+void CmSecureManagerEx(HWND hWnd, UINT id, bool no_new_cert);\r
+UINT CmSecureManagerDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmSecureManagerDlgInit(HWND hWnd, UINT id);\r
+void CmSecureManagerDlgUpdate(HWND hWnd, UINT id);\r
+void CmSecureManagerDlgRefresh(HWND hWnd, UINT id);\r
+void CmSecureManagerDlgPrintList(HWND hWnd, LIST *o);\r
+void CmSecureManagerDlgPrintListEx(HWND hWnd, UINT id, LIST *o, UINT type);\r
+wchar_t *CmSecureObjTypeToStr(UINT type);\r
+UINT CmSecureType(HWND hWnd);\r
+UINT CmSecureTypeDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmSecureManagerDlgImport(HWND hWnd, UINT id);\r
+void CmSecureManagerDlgDelete(HWND hWnd, UINT id);\r
+void CmSecureManagerDlgExport(HWND hWnd, UINT id);\r
+void CmSecureManagerDlgNewCert(HWND hWnd, UINT id);\r
+void CmSecurePin(HWND hWnd, UINT id);\r
+UINT CmSecurePinDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmSecurePinDlgUpdate(HWND hWnd);\r
+void CmInitTray(HWND hWnd);\r
+void CmPollingTray(HWND hWnd);\r
+void CmFreeTray(HWND hWnd);\r
+void CmChangeTrayString(HWND hWnd, wchar_t *str);\r
+UINT CmGetTrayIconId(bool animation, UINT animation_counter);\r
+void CmShowOrHideWindow(HWND hWnd);\r
+void CmShowTrayMenu(HWND hWnd);\r
+HMENU CmCreateTraySubMenu(HWND hWnd, bool flag, UINT start_id);\r
+HMENU CmCreateRecentSubMenu(HWND hWnd, UINT start_id);\r
+bool CmCheckPkcsEula(HWND hWnd, UINT id);\r
+UINT CmPkcsEulaDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmDeleteOldStartupTrayFile();\r
+UINT CmTrafficDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmTrafficDlgInit(HWND hWnd);\r
+bool CmTrafficDlgUpdate(HWND hWnd);\r
+void CmTrafficDlgOnOk(HWND hWnd);\r
+bool CmTrafficLoadFromReg(CM_TRAFFIC *t);\r
+void CmTrafficGetDefaultSetting(CM_TRAFFIC *t);\r
+void CmTrafficSaveToReg(CM_TRAFFIC *t);\r
+void CmTrafficDlgToStruct(HWND hWnd, CM_TRAFFIC *t);\r
+void CmExecTraffic(HWND hWnd, CM_TRAFFIC *t);\r
+UINT CmTrafficRunDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmTrafficRunDlgInit(HWND hWnd, CM_TRAFFIC_DLG *d);\r
+void CmTrafficRunDlgStart(HWND hWnd, CM_TRAFFIC_DLG *d);\r
+void CmTrafficRunDlgPrintProc(void *param, wchar_t *str);\r
+void CmTrafficRunDlgAddStr(HWND hWnd, wchar_t *str);\r
+void CmTrafficRunDlgHalt(HWND hWnd, CM_TRAFFIC_DLG *d);\r
+void CmTrafficRunDlgHaltThread(THREAD *t, void *param);\r
+void CmTrafficRunDlgClientWaitThread(THREAD *t, void *param);\r
+void CmTrafficResult(HWND hWnd, TT_RESULT *r);\r
+UINT CmTrafficResultDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmTrafficResultDlgInit(HWND hWnd, TT_RESULT *res);\r
+void CmTryToExecUiHelper();\r
+void CmInitTryToExecUiHelper();\r
+void CmFreeTryToExecUiHelper();\r
+void CmTryToExecUiHelperThread(THREAD *thread, void *param);\r
+bool CmSetting(HWND hWnd);\r
+UINT CmSettingDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmSettingDlgInit(HWND hWnd, CM_SETTING_DLG *d);\r
+void CmSettingDlgUpdate(HWND hWnd, CM_SETTING_DLG *d);\r
+void CmSettingDlgOnOk(HWND hWnd, CM_SETTING_DLG *d);\r
+void CmApplyCmSetting();\r
+void CmMainWindowOnTrayClicked(HWND hWnd, WPARAM wParam, LPARAM lParam);\r
+void CmShowEasy();\r
+void CmCloseEasy();\r
+void CmMainWindowOnShowEasy(HWND hWnd);\r
+UINT CmEasyDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CmEasyDlgInit(HWND hWnd, CM_EASY_DLG *d);\r
+void CmEasyDlgUpdate(HWND hWnd, CM_EASY_DLG *d);\r
+void CmEasyDlgRefresh(HWND hWnd, CM_EASY_DLG *d);\r
+void CmRefreshEasy();\r
+void CmEasyDlgOnNotify(HWND hWnd, CM_EASY_DLG *d, NMHDR *n);\r
+void CmEasyDlgOnKey(HWND hWnd, CM_EASY_DLG *d, bool ctrl, bool alt, UINT key);\r
+void CmEasyDlgOnCommand(HWND hWnd, CM_EASY_DLG *d, WPARAM wParam, LPARAM lParam);\r
+bool CmStartStartupMutex();\r
+void CmEndStartupMutex();\r
+void CmSetUacWindowActive();\r
+void CmUacHelperThread(THREAD *thread, void *param);\r
+void CmProxyDlgUseForIE(HWND hWnd, CLIENT_OPTION *o);\r
+void CmGetSystemInternetSetting(CM_INTERNET_SETTING *setting);\r
+void CmProxyDlgSet(HWND hWnd, CLIENT_OPTION *o, CM_INTERNET_SETTING *setting);\r
+bool CmGetProxyServerNameAndPortFromIeProxyRegStr(char *name, UINT name_size, UINT *port, char *str, char *server_type);\r
+void *CmUpdateJumpList(UINT start_id);\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Cedar.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Cedar.c
new file mode 100644 (file)
index 0000000..99e60fc
--- /dev/null
@@ -0,0 +1,1566 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Cedar.c\r
+// Cedar 通信モジュールプログラムコード\r
+\r
+// Build 7101\r
+\r
+\r
+#include "CedarPch.h"\r
+\r
+static UINT init_cedar_counter = 0;\r
+static REF *cedar_log_ref = NULL;\r
+static LOG *cedar_log;\r
+\r
+// 現在サポートされている Windows のバージョンかどうか取得する\r
+// (以前、XP までしか想定していないコードを Vista (Longhorn) で動作させたときに\r
+//  OS ごと大変おかしくなってしまったことがあるので、バージョンチェックは\r
+//  必ず行うようにした。ただし、警告メッセージを画面に表示するだけであり、\r
+//  動作は一応できるようにしている。)\r
+bool IsSupportedWinVer(RPC_WINVER *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (v->IsWindows == false)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (v->IsNT == false)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (v->IsBeta)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (v->VerMajor <= 4)\r
+       {\r
+               // Windows NT\r
+               return true;\r
+       }\r
+\r
+       if (v->VerMajor == 5 && v->VerMinor == 0)\r
+       {\r
+               // Windows 2000\r
+               if (v->ServicePack <= 4)\r
+               {\r
+                       // SP4 までサポート\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       if (v->VerMajor == 5 && v->VerMinor == 1)\r
+       {\r
+               // Windows XP x86\r
+               if (v->ServicePack <= 3)\r
+               {\r
+                       // SP3 までサポート\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       if (v->VerMajor == 5 && v->VerMinor == 2)\r
+       {\r
+               // Windows XP x64, Windows Server 2003\r
+               if (v->ServicePack <= 2)\r
+               {\r
+                       // SP2 までサポート\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       if (v->VerMajor == 6 && v->VerMinor == 0)\r
+       {\r
+               // Windows Vista, Server 2008\r
+               if (v->ServicePack <= 2)\r
+               {\r
+                       // SP2 までサポート\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       if (v->VerMajor == 6 && v->VerMinor == 1)\r
+       {\r
+               // Windows 7, Server 2008 R2\r
+               if (v->ServicePack <= 0)\r
+               {\r
+                       // SP0 までサポート\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// Windows のバージョンを取得する\r
+void GetWinVer(RPC_WINVER *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       Win32GetWinVer(v);\r
+#else  // OS_WIN32\r
+       Zero(v, sizeof(RPC_WINVER));\r
+       StrCpy(v->Title, sizeof(v->Title), GetOsInfo()->OsProductName);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// 簡易ログを閉じる\r
+void FreeTinyLog(TINY_LOG *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FileClose(t->io);\r
+       DeleteLock(t->Lock);\r
+       Free(t);\r
+}\r
+\r
+// 簡易ログの書き込み\r
+void WriteTinyLog(TINY_LOG *t, char *str)\r
+{\r
+       BUF *b;\r
+       char dt[MAX_PATH];\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetDateTimeStrMilli64(dt, sizeof(dt), LocalTime64());\r
+       StrCat(dt, sizeof(dt), ": ");\r
+\r
+       b = NewBuf();\r
+\r
+       WriteBuf(b, dt, StrLen(dt));\r
+       WriteBuf(b, str, StrLen(str));\r
+       WriteBuf(b, "\r\n", 2);\r
+\r
+       Lock(t->Lock);\r
+       {\r
+               FileWrite(t->io, b->Buf, b->Size);\r
+               FileFlush(t->io);\r
+       }\r
+       Unlock(t->Lock);\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// 簡易ログの初期化\r
+TINY_LOG *NewTinyLog()\r
+{\r
+       char name[MAX_PATH];\r
+       SYSTEMTIME st;\r
+       TINY_LOG *t;\r
+\r
+       LocalTime(&st);\r
+\r
+       MakeDir(TINY_LOG_DIRNAME);\r
+\r
+       Format(name, sizeof(name), TINY_LOG_FILENAME,\r
+               st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);\r
+\r
+       t = ZeroMalloc(sizeof(TINY_LOG));\r
+\r
+       StrCpy(t->FileName, sizeof(t->FileName), name);\r
+       t->io = FileCreate(name);\r
+       t->Lock = NewLock();\r
+\r
+       return t;\r
+}\r
+\r
+// 非 SSL リストのエントリの比較\r
+int CompareNoSslList(void *p1, void *p2)\r
+{\r
+       NON_SSL *n1, *n2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       n1 = *(NON_SSL **)p1;\r
+       n2 = *(NON_SSL **)p2;\r
+       if (n1 == NULL || n2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return CmpIpAddr(&n1->IpAddress, &n2->IpAddress);\r
+}\r
+\r
+// 指定された IP アドレスが非 SSL リストに存在するかどうかチェック\r
+bool IsInNoSsl(CEDAR *c, IP *ip)\r
+{\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (c == NULL || ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       LockList(c->NonSslList);\r
+       {\r
+               NON_SSL *n = SearchNoSslList(c, ip);\r
+\r
+               if (n != NULL)\r
+               {\r
+                       if (n->EntryExpires > Tick64() && n->Count > NON_SSL_MIN_COUNT)\r
+                       {\r
+                               n->EntryExpires = Tick64() + (UINT64)NON_SSL_ENTRY_EXPIRES;\r
+                               ret = true;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(c->NonSslList);\r
+\r
+       return ret;\r
+}\r
+\r
+// 非 SSL リストのエントリをデクリメント\r
+void DecrementNoSsl(CEDAR *c, IP *ip, UINT num_dec)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(c->NonSslList);\r
+       {\r
+               NON_SSL *n = SearchNoSslList(c, ip);\r
+\r
+               if (n != NULL)\r
+               {\r
+                       if (n->Count >= num_dec)\r
+                       {\r
+                               n->Count -= num_dec;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(c->NonSslList);\r
+}\r
+\r
+// 非 SSL リストにエントリを追加\r
+bool AddNoSsl(CEDAR *c, IP *ip)\r
+{\r
+       NON_SSL *n;\r
+       bool ret = true;\r
+       // 引数チェック\r
+       if (c == NULL || ip == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       LockList(c->NonSslList);\r
+       {\r
+               DeleteOldNoSsl(c);\r
+\r
+               n = SearchNoSslList(c, ip);\r
+\r
+               if (n == NULL)\r
+               {\r
+                       n = ZeroMalloc(sizeof(NON_SSL));\r
+                       Copy(&n->IpAddress, ip, sizeof(IP));\r
+                       n->Count = 0;\r
+\r
+                       Add(c->NonSslList, n);\r
+               }\r
+\r
+               n->EntryExpires = Tick64() + (UINT64)NON_SSL_ENTRY_EXPIRES;\r
+\r
+               n->Count++;\r
+\r
+               if (n->Count > NON_SSL_MIN_COUNT)\r
+               {\r
+                       ret = false;\r
+               }\r
+       }\r
+       UnlockList(c->NonSslList);\r
+\r
+       return ret;\r
+}\r
+\r
+// 古い非 SSL リストの削除\r
+void DeleteOldNoSsl(CEDAR *c)\r
+{\r
+       UINT i;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       for (i = 0;i < LIST_NUM(c->NonSslList);i++)\r
+       {\r
+               NON_SSL *n = LIST_DATA(c->NonSslList, i);\r
+\r
+               if (n->EntryExpires <= Tick64())\r
+               {\r
+                       Add(o, n);\r
+               }\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               NON_SSL *n = LIST_DATA(o, i);\r
+\r
+               Delete(c->NonSslList, n);\r
+               Free(n);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// 非 SSL リストの検索\r
+NON_SSL *SearchNoSslList(CEDAR *c, IP *ip)\r
+{\r
+       NON_SSL *n, t;\r
+       // 引数チェック\r
+       if (c == NULL || ip == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       Copy(&t.IpAddress, ip, sizeof(IP));\r
+\r
+       n = Search(c->NonSslList, &t);\r
+\r
+       if (n == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return n;\r
+}\r
+\r
+// 非 SSL リストの初期化\r
+void InitNoSslList(CEDAR *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->NonSslList = NewList(CompareNoSslList);\r
+}\r
+\r
+// 非 SSL リストの解放\r
+void FreeNoSslList(CEDAR *c)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(c->NonSslList);i++)\r
+       {\r
+               NON_SSL *n = LIST_DATA(c->NonSslList, i);\r
+\r
+               Free(n);\r
+       }\r
+\r
+       ReleaseList(c->NonSslList);\r
+       c->NonSslList = NULL;\r
+}\r
+\r
+// Cedar ログをとる\r
+void CedarLog(char *str)\r
+{\r
+       char *tmp;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (cedar_log_ref == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tmp = CopyStr(str);\r
+\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       if (StrLen(tmp) > 1)\r
+       {\r
+               if (tmp[StrLen(tmp) - 1] == '\n')\r
+               {\r
+                       tmp[StrLen(tmp) - 1] = 0;\r
+               }\r
+               if (StrLen(tmp) > 1)\r
+               {\r
+                       if (tmp[StrLen(tmp) - 1] == '\r')\r
+                       {\r
+                               tmp[StrLen(tmp) - 1] = 0;\r
+                       }\r
+               }\r
+       }\r
+\r
+       InsertStringRecord(cedar_log, tmp);\r
+\r
+       Free(tmp);\r
+}\r
+\r
+// ログを開始する\r
+void StartCedarLog()\r
+{\r
+       if (cedar_log_ref == NULL)\r
+       {\r
+               cedar_log_ref = NewRef();\r
+       }\r
+       else\r
+       {\r
+               AddRef(cedar_log_ref);\r
+       }\r
+\r
+       cedar_log = NewLog("debug_log", "debug", LOG_SWITCH_DAY);\r
+}\r
+\r
+// ログを停止する\r
+void StopCedarLog()\r
+{\r
+       if (cedar_log_ref == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(cedar_log_ref) == 0)\r
+       {\r
+               FreeLog(cedar_log);\r
+               cedar_log = NULL;\r
+               cedar_log_ref = NULL;\r
+       }\r
+}\r
+\r
+// トラフィックのパケットサイズを取得する\r
+UINT64 GetTrafficPacketSize(TRAFFIC *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return t->Recv.BroadcastBytes + t->Recv.UnicastBytes +\r
+               t->Send.BroadcastBytes + t->Send.UnicastBytes;\r
+}\r
+\r
+// トラフィックのパケット数を取得する\r
+UINT64 GetTrafficPacketNum(TRAFFIC *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return t->Recv.BroadcastCount + t->Recv.UnicastCount +\r
+               t->Send.BroadcastCount + t->Send.UnicastCount;\r
+}\r
+\r
+// 非表示パスワードの内容が変更されたかどうかチェックする\r
+bool IsHiddenPasswordChanged(char *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (StrCmpi(str, HIDDEN_PASSWORD) == 0)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// 非表示パスワードを初期化する\r
+void InitHiddenPassword(char *str, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(str, size, HIDDEN_PASSWORD);\r
+}\r
+\r
+// 証明書が仮想 HUB に登録されている CA によって署名されているかどうか確認する\r
+bool CheckSignatureByCaLinkMode(SESSION *s, X *x)\r
+{\r
+       LINK *k;\r
+       HUB *h;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (s == NULL || x == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (s->LinkModeClient == false || (k = s->Link) == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       h = k->Hub;\r
+\r
+       if (h->HubDb != NULL)\r
+       {\r
+               LockList(h->HubDb->RootCertList);\r
+               {\r
+                       X *root_cert;\r
+                       root_cert = GetIssuerFromList(h->HubDb->RootCertList, x);\r
+                       if (root_cert != NULL)\r
+                       {\r
+                               ret = true;\r
+                       }\r
+               }\r
+               UnlockList(h->HubDb->RootCertList);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 証明書が Cedar に登録されている CA によって署名されているかどうか確認する\r
+bool CheckSignatureByCa(CEDAR *cedar, X *x)\r
+{\r
+       X *ca;\r
+       // 引数チェック\r
+       if (cedar == NULL || x == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 指定された証明書を署名した CA を取得\r
+       ca = FindCaSignedX(cedar->CaList, x);\r
+       if (ca == NULL)\r
+       {\r
+               // 発見できなかった\r
+               return false;\r
+       }\r
+\r
+       // 発見した\r
+       FreeX(ca);\r
+       return true;\r
+}\r
+\r
+// 指定された証明書を署名した CA を取得\r
+X *FindCaSignedX(LIST *o, X *x)\r
+{\r
+       X *ret;\r
+       // 引数チェック\r
+       if (o == NULL || x == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = NULL;\r
+\r
+       LockList(o);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       X *ca = LIST_DATA(o, i);\r
+                       if (CheckXDateNow(ca))\r
+                       {\r
+                               if (CompareName(ca->subject_name, x->issuer_name))\r
+                               {\r
+                                       K *k = GetKFromX(ca);\r
+                                       if (k != NULL)\r
+                                       {\r
+                                               if (CheckSignature(x, k))\r
+                                               {\r
+                                                       ret = CloneX(ca);\r
+                                               }\r
+                                               FreeK(k);\r
+                                       }\r
+                               }\r
+                               else if (CompareX(ca, x))\r
+                               {\r
+                                       ret = CloneX(ca);\r
+                               }\r
+                       }\r
+\r
+                       if (ret != NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// Cedar から CA を削除する\r
+bool DeleteCa(CEDAR *cedar, UINT ptr)\r
+{\r
+       bool b = false;\r
+       // 引数チェック\r
+       if (cedar == NULL || ptr == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       LockList(cedar->CaList);\r
+       {\r
+               UINT i;\r
+\r
+               for (i = 0;i < LIST_NUM(cedar->CaList);i++)\r
+               {\r
+                       X *x = LIST_DATA(cedar->CaList, i);\r
+\r
+                       if (POINTER_TO_KEY(x) == ptr)\r
+                       {\r
+                               Delete(cedar->CaList, x);\r
+                               FreeX(x);\r
+\r
+                               b = true;\r
+\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(cedar->CaList);\r
+\r
+       return b;\r
+}\r
+\r
+// Cedar に CA を追加する\r
+void AddCa(CEDAR *cedar, X *x)\r
+{\r
+       // 引数チェック\r
+       if (cedar == NULL || x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(cedar->CaList);\r
+       {\r
+               UINT i;\r
+               bool ok = true;\r
+\r
+               for (i = 0;i < LIST_NUM(cedar->CaList);i++)\r
+               {\r
+                       X *exist_x = LIST_DATA(cedar->CaList, i);\r
+                       if (CompareX(exist_x, x))\r
+                       {\r
+                               ok = false;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               if (ok)\r
+               {\r
+                       Insert(cedar->CaList, CloneX(x));\r
+               }\r
+       }\r
+       UnlockList(cedar->CaList);\r
+}\r
+\r
+// Cedar からコネクションを削除する\r
+void DelConnection(CEDAR *cedar, CONNECTION *c)\r
+{\r
+       // 引数チェック\r
+       if (cedar == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(cedar->ConnectionList);\r
+       {\r
+               Debug("Connection %s Deleted from Cedar.\n", c->Name);\r
+               if (Delete(cedar->ConnectionList, c))\r
+               {\r
+                       ReleaseConnection(c);\r
+               }\r
+       }\r
+       UnlockList(cedar->ConnectionList);\r
+}\r
+\r
+// 現在の未確立コネクション数を取得する\r
+UINT GetUnestablishedConnections(CEDAR *cedar)\r
+{\r
+       UINT i, ret;\r
+       // 引数チェック\r
+       if (cedar == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = 0;\r
+\r
+       LockList(cedar->ConnectionList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(cedar->ConnectionList);i++)\r
+               {\r
+                       CONNECTION *c = LIST_DATA(cedar->ConnectionList, i);\r
+\r
+                       switch (c->Type)\r
+                       {\r
+                       case CONNECTION_TYPE_CLIENT:\r
+                       case CONNECTION_TYPE_INIT:\r
+                       case CONNECTION_TYPE_LOGIN:\r
+                       case CONNECTION_TYPE_ADDITIONAL:\r
+                               switch (c->Status)\r
+                               {\r
+                               case CONNECTION_STATUS_ACCEPTED:\r
+                               case CONNECTION_STATUS_NEGOTIATION:\r
+                               case CONNECTION_STATUS_USERAUTH:\r
+                                       ret++;\r
+                                       break;\r
+                               }\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(cedar->ConnectionList);\r
+\r
+       return ret + Count(cedar->AcceptingSockets);\r
+}\r
+\r
+// Cedar にコネクションを追加する\r
+void AddConnection(CEDAR *cedar, CONNECTION *c)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UINT i;\r
+       // 引数チェック\r
+       if (cedar == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       //新しいコネクションの名前を決定する\r
+       i = Inc(cedar->ConnectionIncrement);\r
+       Format(tmp, sizeof(tmp), "CID-%u", i);\r
+       Lock(c->lock);\r
+       {\r
+               Free(c->Name);\r
+               c->Name = CopyStr(tmp);\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       LockList(cedar->ConnectionList);\r
+       {\r
+               Add(cedar->ConnectionList, c);\r
+               AddRef(c->ref);\r
+               Debug("Connection %s Inserted to Cedar.\n", c->Name);\r
+       }\r
+       UnlockList(cedar->ConnectionList);\r
+}\r
+\r
+// すべてのコネクションを停止\r
+void StopAllConnection(CEDAR *c)\r
+{\r
+       UINT num;\r
+       UINT i;\r
+       CONNECTION **connections;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(c->ConnectionList);\r
+       {\r
+               connections = ToArray(c->ConnectionList);\r
+               num = LIST_NUM(c->ConnectionList);\r
+               DeleteAll(c->ConnectionList);\r
+       }\r
+       UnlockList(c->ConnectionList);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               StopConnection(connections[i], false);\r
+               ReleaseConnection(connections[i]);\r
+       }\r
+       Free(connections);\r
+}\r
+\r
+// CEDAR から HUB を削除\r
+void DelHub(CEDAR *c, HUB *h)\r
+{\r
+       DelHubEx(c, h, false);\r
+}\r
+void DelHubEx(CEDAR *c, HUB *h, bool no_lock)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (no_lock == false)\r
+       {\r
+               LockHubList(c);\r
+       }\r
+\r
+       if (Delete(c->HubList, h))\r
+       {\r
+               ReleaseHub(h);\r
+       }\r
+\r
+       if (no_lock == false)\r
+       {\r
+               UnlockHubList(c);\r
+       }\r
+}\r
+\r
+// CEDAR に HUB を追加\r
+void AddHub(CEDAR *c, HUB *h)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+#if    0\r
+               // HUB 数はここではチェックしないことにする\r
+               if (LIST_NUM(c->HubList) >= MAX_HUBS)\r
+               {\r
+                       // 上限数超過\r
+                       UnlockHubList(c);\r
+                       return;\r
+               }\r
+#endif\r
+\r
+               // 同一名の HUB が存在しないかどうかチェック\r
+               if (IsHub(c, h->Name))\r
+               {\r
+                       // 存在する\r
+                       UnlockHubList(c);\r
+                       return;\r
+               }\r
+\r
+               // HUB を登録する\r
+               Insert(c->HubList, h);\r
+               AddRef(h->ref);\r
+       }\r
+       UnlockHubList(c);\r
+}\r
+\r
+// CEDAR のすべての HUB を停止\r
+void StopAllHub(CEDAR *c)\r
+{\r
+       HUB **hubs;\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockHubList(c);\r
+       {\r
+               hubs = ToArray(c->HubList);\r
+               num = LIST_NUM(c->HubList);\r
+               DeleteAll(c->HubList);\r
+       }\r
+       UnlockHubList(c);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               StopHub(hubs[i]);\r
+               ReleaseHub(hubs[i]);\r
+       }\r
+\r
+       Free(hubs);\r
+}\r
+\r
+// CEDAR にリスナーを追加\r
+void AddListener(CEDAR *c, LISTENER *r)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(c->ListenerList);\r
+       {\r
+               Add(c->ListenerList, r);\r
+               AddRef(r->ref);\r
+       }\r
+       UnlockList(c->ListenerList);\r
+}\r
+\r
+// CEDAR のすべてのリスナーを停止\r
+void StopAllListener(CEDAR *c)\r
+{\r
+       LISTENER **array;\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(c->ListenerList);\r
+       {\r
+               array = ToArray(c->ListenerList);\r
+               num = LIST_NUM(c->ListenerList);\r
+               DeleteAll(c->ListenerList);\r
+       }\r
+       UnlockList(c->ListenerList);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               StopListener(array[i]);\r
+               ReleaseListener(array[i]);\r
+       }\r
+       Free(array);\r
+}\r
+\r
+// CEDAR の停止\r
+void StopCedar(CEDAR *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 停止フラグ\r
+       c->Halt = true;\r
+\r
+       // すべてのリスナーを停止\r
+       StopAllListener(c);\r
+       // すべてのコネクションを停止\r
+       StopAllConnection(c);\r
+       // すべての HUB を停止\r
+       StopAllHub(c);\r
+       // すべての L3 スイッチを解放\r
+       L3FreeAllSw(c);\r
+}\r
+\r
+// CEDAR のクリーンアップ\r
+void CleanupCedar(CEDAR *c)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeCedarLayer3(c);\r
+\r
+/*\r
+       for (i = 0;i < LIST_NUM(c->HubList);i++)\r
+       {\r
+               HUB *h = LIST_DATA(c->HubList, i);\r
+       }\r
+*/\r
+       for (i = 0;i < LIST_NUM(c->CaList);i++)\r
+       {\r
+               X *x = LIST_DATA(c->CaList, i);\r
+               FreeX(x);\r
+       }\r
+       ReleaseList(c->CaList);\r
+\r
+       ReleaseList(c->ListenerList);\r
+       ReleaseList(c->HubList);\r
+       ReleaseList(c->ConnectionList);\r
+       //CleanupUDPEntry(c);\r
+       ReleaseList(c->UDPEntryList);\r
+       DeleteLock(c->lock);\r
+       DeleteCounter(c->ConnectionIncrement);\r
+       DeleteCounter(c->CurrentSessions);\r
+\r
+       if (c->DebugLog != NULL)\r
+       {\r
+               FreeLog(c->DebugLog);\r
+       }\r
+\r
+       if (c->ServerX)\r
+       {\r
+               FreeX(c->ServerX);\r
+       }\r
+       if (c->ServerK)\r
+       {\r
+               FreeK(c->ServerK);\r
+       }\r
+\r
+       if (c->CipherList)\r
+       {\r
+               Free(c->CipherList);\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(c->TrafficDiffList);i++)\r
+       {\r
+               TRAFFIC_DIFF *d = LIST_DATA(c->TrafficDiffList, i);\r
+               Free(d->Name);\r
+               Free(d->HubName);\r
+               Free(d);\r
+       }\r
+\r
+       ReleaseList(c->TrafficDiffList);\r
+\r
+       Free(c->ServerStr);\r
+       Free(c->MachineName);\r
+\r
+       Free(c->HttpUserAgent);\r
+       Free(c->HttpAccept);\r
+       Free(c->HttpAcceptLanguage);\r
+       Free(c->HttpAcceptEncoding);\r
+\r
+       FreeTraffic(c->Traffic);\r
+\r
+       DeleteLock(c->TrafficLock);\r
+\r
+       FreeNetSvcList(c);\r
+\r
+       Free(c->VerString);\r
+       Free(c->BuildInfo);\r
+\r
+       FreeLocalBridgeList(c);\r
+\r
+       DeleteCounter(c->AssignedBridgeLicense);\r
+       DeleteCounter(c->AssignedClientLicense);\r
+\r
+       FreeNoSslList(c);\r
+\r
+       DeleteLock(c->CedarSuperLock);\r
+\r
+       DeleteCounter(c->AcceptingSockets);\r
+\r
+       Free(c);\r
+}\r
+\r
+// CEDAR の解放\r
+void ReleaseCedar(CEDAR *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(c->ref) == 0)\r
+       {\r
+               CleanupCedar(c);\r
+       }\r
+}\r
+\r
+// CipherList のセット\r
+void SetCedarCipherList(CEDAR *cedar, char *name)\r
+{\r
+       // 引数チェック\r
+       if (cedar == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (cedar->CipherList != NULL)\r
+       {\r
+               Free(cedar->CipherList);\r
+       }\r
+       if (name != NULL)\r
+       {\r
+               cedar->CipherList = CopyStr(name);\r
+       }\r
+       else\r
+       {\r
+               cedar->CipherList = NULL;\r
+       }\r
+}\r
+\r
+// ネットサービスリストのソート\r
+int CompareNetSvc(void *p1, void *p2)\r
+{\r
+       NETSVC *n1, *n2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       n1 = *(NETSVC **)p1;\r
+       n2 = *(NETSVC **)p2;\r
+       if (n1 == NULL || n2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (n1->Port > n2->Port)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (n1->Port < n2->Port)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (n1->Udp > n2->Udp)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (n1->Udp < n2->Udp)\r
+       {\r
+               return -1;\r
+       }\r
+       return 0;\r
+}\r
+\r
+// ネットサービスリストの初期化\r
+void InitNetSvcList(CEDAR *cedar)\r
+{\r
+       char filename[MAX_PATH] = "/etc/services";\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (cedar == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       // 自力でがんばって読む\r
+       Format(filename, sizeof(filename), "%s\\drivers\\etc\\services", MsGetSystem32Dir());\r
+#endif\r
+\r
+       cedar->NetSvcList = NewList(CompareNetSvc);\r
+\r
+       b = ReadDump(filename);\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               char *s = CfgReadNextLine(b);\r
+               if (s == NULL)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               Trim(s);\r
+               if (s[0] != '#')\r
+               {\r
+                       TOKEN_LIST *t = ParseToken(s, " \t/");\r
+                       if (t->NumTokens >= 3)\r
+                       {\r
+                               NETSVC *n = ZeroMalloc(sizeof(NETSVC));\r
+                               n->Name = CopyStr(t->Token[0]);\r
+                               n->Udp = (StrCmpi(t->Token[2], "udp") == 0 ? true : false);\r
+                               n->Port = ToInt(t->Token[1]);\r
+                               Add(cedar->NetSvcList, n);\r
+                       }\r
+                       FreeToken(t);\r
+               }\r
+               Free(s);\r
+       }\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// ネットサービス名の取得\r
+char *GetSvcName(CEDAR *cedar, bool udp, UINT port)\r
+{\r
+       char *ret = NULL;\r
+       NETSVC t;\r
+       // 引数チェック\r
+       if (cedar == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t.Udp = (udp == 0 ? false : true);\r
+       t.Port = port;\r
+\r
+       LockList(cedar->NetSvcList);\r
+       {\r
+               NETSVC *n = Search(cedar->NetSvcList, &t);\r
+               if (n != NULL)\r
+               {\r
+                       ret = n->Name;\r
+               }\r
+       }\r
+       UnlockList(cedar->NetSvcList);\r
+\r
+       return ret;\r
+}\r
+\r
+// ネットサービスリストの解放\r
+void FreeNetSvcList(CEDAR *cedar)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (cedar == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(cedar->NetSvcList);i++)\r
+       {\r
+               NETSVC *n = LIST_DATA(cedar->NetSvcList, i);\r
+               Free(n->Name);\r
+               Free(n);\r
+       }\r
+       ReleaseList(cedar->NetSvcList);\r
+}\r
+\r
+// CEDAR の証明書の変更\r
+void SetCedarCert(CEDAR *c, X *server_x, K *server_k)\r
+{\r
+       // 引数チェック\r
+       if (server_x == NULL || server_k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(c->lock);\r
+       {\r
+               if (c->ServerX != NULL)\r
+               {\r
+                       FreeX(c->ServerX);\r
+               }\r
+\r
+               if (c->ServerK != NULL)\r
+               {\r
+                       FreeK(c->ServerK);\r
+               }\r
+\r
+               c->ServerX = CloneX(server_x);\r
+               c->ServerK = CloneK(server_k);\r
+       }\r
+       Unlock(c->lock);\r
+}\r
+\r
+// デバッグログを有効にする\r
+void EnableDebugLog(CEDAR *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || c->DebugLog != NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->DebugLog = NewLog("cedar_debug_log", "cedar", LOG_SWITCH_NO);\r
+}\r
+\r
+// CEDAR を VPN Bridge にする\r
+void SetCedarVpnBridge(CEDAR *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->Bridge = true;\r
+\r
+       Free(c->ServerStr);\r
+       c->ServerStr = CopyStr(CEDAR_BRIDGE_STR);\r
+}\r
+\r
+// CEDAR の作成\r
+CEDAR *NewCedar(X *server_x, K *server_k)\r
+{\r
+       CEDAR *c;\r
+       char tmp[MAX_SIZE];\r
+       char tmp2[MAX_SIZE];\r
+       char *beta_str;\r
+\r
+       c = ZeroMalloc(sizeof(CEDAR));\r
+\r
+       c->AcceptingSockets = NewCounter();\r
+\r
+       c->CedarSuperLock = NewLock();\r
+\r
+#ifdef BETA_NUMBER\r
+       c->Beta = BETA_NUMBER;\r
+#endif // BETA_NUMBER\r
+\r
+       InitNoSslList(c);\r
+\r
+       c->AssignedBridgeLicense = NewCounter();\r
+       c->AssignedClientLicense = NewCounter();\r
+\r
+       Rand(c->UniqueId, sizeof(c->UniqueId));\r
+\r
+       c->CreatedTick = Tick64();\r
+\r
+       c->lock = NewLock();\r
+       c->ref = NewRef();\r
+\r
+       c->CurrentTcpConnections = GetNumTcpConnectionsCounter();\r
+\r
+       c->ListenerList = NewList(CompareListener);\r
+       c->UDPEntryList = NewList(CompareUDPEntry);\r
+       c->HubList = NewList(CompareHub);\r
+       c->ConnectionList = NewList(CompareConnection);\r
+\r
+       c->ConnectionIncrement = NewCounter();\r
+       c->CurrentSessions = NewCounter();\r
+\r
+       if (server_k && server_x)\r
+       {\r
+               c->ServerK = CloneK(server_k);\r
+               c->ServerX = CloneX(server_x);\r
+       }\r
+\r
+       c->Version = CEDAR_VER;\r
+       c->Build = CEDAR_BUILD;\r
+       c->ServerStr = CopyStr(CEDAR_SERVER_STR);\r
+\r
+       GetMachineName(tmp, sizeof(tmp));\r
+       c->MachineName = CopyStr(tmp);\r
+\r
+       c->HttpUserAgent = CopyStr(DEFAULT_USER_AGENT);\r
+       c->HttpAccept = CopyStr(DEFAULT_ACCEPT);\r
+       c->HttpAcceptLanguage = CopyStr("ja");\r
+       c->HttpAcceptEncoding = CopyStr(DEFAULT_ENCODING);\r
+\r
+       c->Traffic = NewTraffic();\r
+       c->TrafficLock = NewLock();\r
+       c->CaList = NewList(CompareCert);\r
+\r
+       c->TrafficDiffList = NewList(NULL);\r
+\r
+       SetCedarCipherList(c, "RC4-MD5");\r
+\r
+       c->ClientId = _II("CLIENT_ID");\r
+\r
+       InitNetSvcList(c);\r
+\r
+       InitLocalBridgeList(c);\r
+\r
+       InitCedarLayer3(c);\r
+\r
+#ifdef ALPHA_VERSION\r
+       beta_str = "Alpha";\r
+#else  // ALPHA_VERSION\r
+       beta_str = "Release Candidate";\r
+#endif // ALPHA_VERSION\r
+\r
+       ToStr(tmp2, c->Beta);\r
+\r
+       Format(tmp, sizeof(tmp), "Version %u.%02u Build %u %s %s (%s)",\r
+               CEDAR_VER / 100, CEDAR_VER - (CEDAR_VER / 100) * 100,\r
+               CEDAR_BUILD,\r
+               c->Beta == 0 ? "" : beta_str,\r
+               c->Beta == 0 ? "" : tmp2,\r
+               _SS("LANGSTR"));\r
+       Trim(tmp);\r
+\r
+       if (true)\r
+       {\r
+               SYSTEMTIME st;\r
+               Zero(&st, sizeof(st));\r
+\r
+               st.wYear = BUILD_DATE_Y;\r
+               st.wMonth = BUILD_DATE_M;\r
+               st.wDay = BUILD_DATE_D;\r
+\r
+               c->BuiltDate = SystemToUINT64(&st);\r
+       }\r
+\r
+       c->VerString = CopyStr(tmp);\r
+\r
+       Format(tmp, sizeof(tmp), "Compiled %04u/%02u/%02u %02u:%02u:%02u by %s at %s",\r
+               BUILD_DATE_Y, BUILD_DATE_M, BUILD_DATE_D, BUILD_DATE_HO, BUILD_DATE_MI, BUILD_DATE_SE, BUILDER_NAME, BUILD_PLACE);\r
+\r
+       c->BuildInfo = CopyStr(tmp);\r
+\r
+       return c;\r
+}\r
+\r
+// 指定した日付よりも遅い日付にビルドされたものであるかどうか取得\r
+bool IsLaterBuild(CEDAR *c, UINT64 t)\r
+{\r
+       SYSTEMTIME sb, st;\r
+       UINT64 b;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&sb, sizeof(sb));\r
+       Zero(&st, sizeof(st));\r
+\r
+       UINT64ToSystem(&sb, c->BuiltDate);\r
+       UINT64ToSystem(&st, t);\r
+\r
+       // 時刻データを無視\r
+       sb.wHour = sb.wMinute = sb.wSecond = sb.wMilliseconds = 0;\r
+       st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;\r
+\r
+       b = SystemToUINT64(&sb);\r
+       t = SystemToUINT64(&st);\r
+\r
+       if (b > t)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// トラフィック情報の加算\r
+void AddTraffic(TRAFFIC *dst, TRAFFIC *diff)\r
+{\r
+       // 引数チェック\r
+       if (dst == NULL || diff == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       dst->Recv.BroadcastBytes += diff->Recv.BroadcastBytes;\r
+       dst->Recv.BroadcastCount += diff->Recv.BroadcastCount;\r
+       dst->Recv.UnicastBytes += diff->Recv.UnicastBytes;\r
+       dst->Recv.UnicastCount += diff->Recv.UnicastCount;\r
+\r
+       dst->Send.BroadcastBytes += diff->Send.BroadcastBytes;\r
+       dst->Send.BroadcastCount += diff->Send.BroadcastCount;\r
+       dst->Send.UnicastBytes += diff->Send.UnicastBytes;\r
+       dst->Send.UnicastCount += diff->Send.UnicastCount;\r
+}\r
+\r
+// トラフィック情報の作成\r
+TRAFFIC *NewTraffic()\r
+{\r
+       TRAFFIC *t;\r
+\r
+       // メモリ確保\r
+       t = ZeroMalloc(sizeof(TRAFFIC));\r
+       return t;\r
+}\r
+\r
+// トラフィック情報の解放\r
+void FreeTraffic(TRAFFIC *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メモリ解放\r
+       Free(t);\r
+}\r
+\r
+// Cedar 通信モジュールの初期化\r
+void InitCedar()\r
+{\r
+       if ((init_cedar_counter++) > 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // プロトコル初期化\r
+       InitProtocol();\r
+}\r
+\r
+// Cedar 通信モジュールの解放\r
+void FreeCedar()\r
+{\r
+       if ((--init_cedar_counter) > 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // プロトコル解放\r
+       FreeProtocol();\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Cedar.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Cedar.h
new file mode 100644 (file)
index 0000000..b7aab5a
--- /dev/null
@@ -0,0 +1,1139 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Cedar.h\r
+// Cedar.c のヘッダ\r
+\r
+#ifndef        CEDAR_H\r
+#define        CEDAR_H\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// 製品情報関連定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        bool    UINT\r
+#define        BOOL    UINT\r
+\r
+// バージョン番号\r
+#define        CEDAR_VER                                       101\r
+\r
+// ビルド番号\r
+#define        CEDAR_BUILD                                     7101\r
+\r
+// ベータ番号\r
+//#define      BETA_NUMBER                                     2\r
+\r
+// ビルド担当者の名前を指定\r
+#ifndef        BUILDER_NAME\r
+#define        BUILDER_NAME            "yagi"\r
+#endif // BUILDER_NAME\r
+\r
+// ビルドした場所を指定\r
+#ifndef        BUILD_PLACE\r
+#define        BUILD_PLACE                     "pc25"\r
+#endif // BUILD_PLACE\r
+\r
+// ビルド日時を指定\r
+#define        BUILD_DATE_Y            2010\r
+#define        BUILD_DATE_M            6\r
+#define        BUILD_DATE_D            27\r
+#define        BUILD_DATE_HO           18\r
+#define        BUILD_DATE_MI           40\r
+#define        BUILD_DATE_SE           28\r
+\r
+// 許容する時差\r
+#define        ALLOW_TIMESTAMP_DIFF            (UINT64)(3 * 24 * 60 * 60 * 1000)\r
+\r
+// SoftEther UT-VPN シリーズ製品名\r
+#define        CEDAR_PRODUCT_STR                       "UT-VPN"\r
+\r
+// Server 製品名\r
+#define        CEDAR_SERVER_STR                        "UT-VPN Server"\r
+\r
+// Bridge 製品名\r
+#define        CEDAR_BRIDGE_STR                        "UT-VPN Bridge"\r
+\r
+// Server 製品名 (ベータ)\r
+#define        CEDAR_BETA_SERVER                       "UT-VPN Server Pre Release"\r
+\r
+// VPN Server Manager 製品名\r
+#define        CEDAR_MANAGER_STR                       "UT-VPN Server Manager"\r
+\r
+// VPN Command-Line Admin Tool 製品名\r
+#define        CEDAR_CUI_STR                           "UT-VPN Command-Line Admin Tool"\r
+\r
+// VPN User-mode Router 製品名\r
+#define        CEDAR_ROUTER_STR                        "UT-VPN User-mode Router"\r
+\r
+// VPN Client 製品名\r
+#define        CEDAR_CLIENT_STR                        "UT-VPN Client"\r
+\r
+// VPN Client Manager 製品名\r
+#define CEDAR_CLIENT_MANAGER_STR       "UT-VPN Client Connection Manager"\r
+\r
+// VPN Server のカスケード接続時の製品名\r
+#define        CEDAR_SERVER_LINK_STR           "UT-VPN Server (Cascade Mode)"\r
+\r
+// VPN Server のサーバーファーム RPC 接続時の製品名\r
+#define        CEDAR_SERVER_FARM_STR           "UT-VPN Server (Cluster RPC Mode)"\r
+\r
+\r
+// IDS 検出用シグネチャの指定\r
+#define        CEDAR_SIGNATURE_STR                     "SE-UTVPN-PROTOCOL"\r
+\r
+// スマートカードのデフォルトの RSA 証明書名\r
+#define        SECURE_DEFAULT_CERT_NAME        "VPN_RSA_CERT"\r
+\r
+// スマートカードのデフォルトの RSA 秘密鍵名\r
+#define        SECURE_DEFAULT_KEY_NAME         "VPN_RSA_KEY"\r
+\r
+// 8 文字の非表示パスワード文字列\r
+#define        HIDDEN_PASSWORD                         "********"\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// 各種文字列の最大長の定義\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        MAX_ACCOUNT_NAME_LEN            255             // 最大アカウント名長\r
+#define        MAX_USERNAME_LEN                        255             // ユーザー名最大長\r
+#define        MAX_PASSWORD_LEN                        255             // パスワード名最大長\r
+#define        MAX_HOST_NAME_LEN                       255             // ホスト名最大長\r
+#define        MAX_PROXY_USERNAME_LEN          255             // プロキシユーザー名最大長\r
+#define        MAX_PROXY_PASSWORD_LEN          255             // プロキシパスワード最大長\r
+#define        MAX_SERVER_STR_LEN                      255             // サーバー文字列最大長\r
+#define        MAX_CLIENT_STR_LEN                      255             // クライアント文字列最大長\r
+#define        MAX_HUBNAME_LEN                         255             // HUB 名最大長\r
+#define        MAX_SESSION_NAME_LEN            255             // セッション名最大長\r
+#define        MAX_CONNECTION_NAME_LEN         255             // コネクション名最大長\r
+#define        MAX_DEVICE_NAME_LEN                     31              // デバイス名最大長\r
+#define        MAX_DEVICE_NAME_LEN_9X          4               // Win9x での仮想 LAN カード名最大長\r
+#define        MAX_ACCESSLIST_NOTE_LEN         255             // アクセスリストのメモ最大長\r
+#define        MAX_SECURE_DEVICE_FILE_LEN      255             // セキュアデバイス内ファイル名最大長\r
+#define        MAX_ADMIN_OPTION_NAME_LEN       63              // 管理オプション名\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// サーバーおよびセッション管理関連定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        SERVER_MAX_SESSIONS                     4096    // サーバーがサポートする最大セッション数\r
+#define SERVER_MAX_SESSIONS_FOR_64BIT  100000  // サーバーがサポートする最大セッション数 (64 bit)\r
+#define        NAT_MAX_SESSIONS                        4096    // NAT がサポートする最大セッション数\r
+#define        MAX_HUBS                                        4096    // 仮想 HUB の最大数 (32 bit)\r
+#define MAX_HUBS_FOR_64BIT                     100000  // 仮想 HUB の最大数 (64 bit)\r
+#define        MAX_ACCESSLISTS                         4096    // アクセスリストの最大数\r
+#define        MAX_USERS                                       10000   // 最大ユーザー数\r
+#define        MAX_GROUPS                                      10000   // 最大グループ数\r
+#define        MAX_MAC_TABLES                          65536   // 最大 MAC アドレステーブル数\r
+#define        MAX_IP_TABLES                           65536   // 最大 IP アドレステーブル数\r
+#define        MAX_HUB_CERTS                           4096    // 登録できるルート CA 最大数\r
+#define        MAX_HUB_CRLS                            4096    // 登録できる CRL 最大数\r
+#define        MAX_HUB_ACS                                     4096    // 登録できる AC 最大数\r
+#define        MAX_HUB_LINKS                           128             // 登録できるカスケード接続最大数\r
+#define        MAX_HUB_ADMIN_OPTIONS           4096    // 登録できる仮想 HUB 管理オプション最大数\r
+\r
+#define        MAX_PACKET_SIZE                         1560    // 最大パケットサイズ\r
+#define        UDP_BUF_SIZE                            (32 * 1024) // UDP パケットサイズの目安\r
+\r
+#define        MAX_SEND_SOCKET_QUEUE_SIZE      (1600 * 1600 * 1)       // 最大送信キューサイズ\r
+#define        MIN_SEND_SOCKET_QUEUE_SIZE      (1600 * 200 * 1)\r
+#define        MAX_SEND_SOCKET_QUEUE_NUM       128             // 最大送信キュー数\r
+#define        MAX_TCP_CONNECTION                      32              // 最大 TCP コネクション数\r
+#define        SELECT_TIME                                     256\r
+#define        SELECT_TIME_FOR_NAT                     30\r
+#define        SELECT_TIME_FOR_DELAYED_PKT     1               // 遅延パケットがある場合\r
+#define        MAX_STORED_QUEUE_NUM            1024            // セッションごとにストアできるキューの数\r
+#define        MAX_BUFFERING_PACKET_SIZE       (1600 * 1600)   // バッファリング可能なパケットサイズの最大値\r
+\r
+#define        TIMEOUT_MIN                                     (5 * 1000)      // 最小タイムアウト秒数\r
+#define        TIMEOUT_MAX                                     (60 * 1000)     // 最大タイムアウト秒数\r
+#define        TIMEOUT_DEFAULT                         (30 * 1000) // デフォルトのタイムアウト秒数\r
+#define        CONNECTING_TIMEOUT                      (15 * 1000)     // 接続中のタイムアウト秒数\r
+#define        CONNECTING_TIMEOUT_PROXY        (4 * 1000)      // 接続中のタイムアウト秒数 (Proxy)\r
+#define        CONNECTING_POOLING_SPAN         (3 * 1000) // 接続中のポーリング間隔\r
+#define        MIN_RETRY_INTERVAL                      (5 * 1000)              // 最小リトライ間隔\r
+#define        MAX_RETRY_INTERVAL                      (300 * 1000)    // 最大リトライ間隔\r
+#define        RETRY_INTERVAL_SPECIAL          (60 * 1000)             // 特別な場合の再接続間隔\r
+\r
+#define        MAC_MIN_LIMIT_COUNT                     3               // 最小 MAC アドレス数制限値\r
+#define        IP_MIN_LIMIT_COUNT                      4               // 最小 IPv4 アドレス数制限値\r
+#define        IP_MIN_LIMIT_COUNT_V6           5               // 最小 IPv6 アドレス数制限値\r
+#define        IP_LIMIT_WHEN_NO_ROUTING_V6     15              // NoRouting ポリシーが有効な場合の IPv6 アドレス数制限値\r
+\r
+#define        MAC_TABLE_EXCLUSIVE_TIME        (13 * 1000)                     // MAC アドレスを占有することができる期間\r
+#define        IP_TABLE_EXCLUSIVE_TIME         (13 * 1000)                     // IP アドレスを占有することができる期間\r
+#define        MAC_TABLE_EXPIRE_TIME           (600 * 1000)                    // MAC アドレステーブル有効期限\r
+#define        IP_TABLE_EXPIRE_TIME            (60 * 1000)                     // IP アドレステーブル有効期限\r
+#define        IP_TABLE_EXPIRE_TIME_DHCP       (5 * 60 * 1000)         // IP アドレステーブル有効期限 (DHCP の場合)\r
+#define        HUB_ARP_SEND_INTERVAL           (5 * 1000)                      // ARP パケット送信間隔 (生存チェック)\r
+\r
+#define        LIMITER_SAMPLING_SPAN           1000    // トラフィック制限装置のサンプリング間隔\r
+\r
+#define        STORM_CHECK_SPAN                        500             // ブロードキャストストームチェック間隔\r
+#define        STORM_DISCARD_VALUE_START       3               // ブロードキャストパケット破棄値開始値\r
+#define        STORM_DISCARD_VALUE_END         1024    // ブロードキャストパケット破棄値終了値\r
+\r
+#define        KEEP_INTERVAL_MIN                       5               // パケット送出間隔最小値\r
+#define        KEEP_INTERVAL_DEFAULT           50              // パケット送出間隔デフォルト値\r
+#define        KEEP_INTERVAL_MAX                       600             // パケット送出間隔最大値\r
+#define KEEP_TCP_TIMEOUT                       1000    // TCP タイムアウト値\r
+\r
+#define        TICKET_EXPIRES                          (60 * 1000)     // チケットの有効期限\r
+\r
+\r
+#define        FARM_BASE_POINT                         100000          // クラスタ得点の基準値\r
+#define        FARM_DEFAULT_WEIGHT                     100                     // 標準の性能基準比\r
+\r
+\r
+// HTTPS サーバー / クライアント関連文字列定数\r
+#define        DEFAULT_USER_AGENT      "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"\r
+#define        DEFAULT_ACCEPT          "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-powerpoint, application/vnd.ms-excel, */*"\r
+#define        DEFAULT_ENCODING        "gzip, deflate"\r
+#define        HTTP_CONTENT_TYPE       "text/html; charset=iso-8859-1"\r
+#define        HTTP_CONTENT_TYPE2      "application/octet-stream"\r
+#define        HTTP_CONTENT_TYPE3      "image/jpeg"\r
+#define        HTTP_CONTENT_TYPE4      "text/html"\r
+#define        HTTP_CONTENT_TYPE5      "message/rfc822"\r
+#define        HTTP_KEEP_ALIVE         "timeout=15; max=19"\r
+#define        HTTP_VPN_TARGET         "/vpnsvc/vpn.cgi"\r
+#define        HTTP_VPN_TARGET2        "/vpnsvc/connect.cgi"\r
+#define HTTP_VPN_TARGET_POSTDATA       "VPNCONNECT"\r
+#define        HTTP_SAITAMA            "/saitama.jpg"\r
+#define        HTTP_PICTURES           "/picture"\r
+\r
+#define        SE_UDP_SIGN                     "SE2P"          // 未使用 (旧 UDP モードのみ)\r
+\r
+// トラフィック情報更新間隔\r
+#define        INCREMENT_TRAFFIC_INTERVAL              (10 * 1000)\r
+\r
+// クライアント セッションの状態\r
+#define        CLIENT_STATUS_CONNECTING        0               // 接続中\r
+#define        CLIENT_STATUS_NEGOTIATION       1               // ネゴシエーション中\r
+#define        CLIENT_STATUS_AUTH                      2               // ユーザー認証中\r
+#define        CLIENT_STATUS_ESTABLISHED       3               // 接続完了\r
+#define        CLIENT_STATUS_RETRY                     4               // リトライまで待機中\r
+#define        CLIENT_STATUS_IDLE                      5               // アイドル状態\r
+\r
+// ファイル転送時に一度に転送するブロック\r
+#define        FTP_BLOCK_SIZE                          (640 * 1024)\r
+\r
+// syslog 設定\r
+#define SYSLOG_NONE                                                    0               // syslog を使わない\r
+#define SYSLOG_SERVER_LOG                                      1               // サーバーログのみ\r
+#define SYSLOG_SERVER_AND_HUB_SECURITY_LOG     2               // サーバーと仮想 HUB セキュリティログ\r
+#define SYSLOG_SERVER_AND_HUB_ALL_LOG          3               // サーバー、仮想 HUB セキュリティおよびパケットログ\r
+\r
+#define SYSLOG_PORT                                    514                     // syslog ポート番号\r
+#define SYSLOG_POLL_IP_INTERVAL                (UINT64)(3600 * 1000)   // IP アドレスを調べる間隔\r
+#define        SYSLOG_POLL_IP_INTERVAL_NG      (UINT64)(60 * 1000)     // IP アドレスを調べる間隔 (前回失敗時)\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// コネクション関連の定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+// インターネット接続維持機能 (KeepAlive)\r
+\r
+#define        KEEP_RETRY_INTERVAL             (60 * 1000)                     // 接続失敗時の再接続間隔\r
+#define        KEEP_MIN_PACKET_SIZE    1                                       // 最小パケットサイズ\r
+#define        KEEP_MAX_PACKET_SIZE    128                                     // 最大パケットサイズ\r
+#define        KEEP_POLLING_INTERVAL   250                                     // KEEP ポーリング間隔\r
+\r
+// 定数\r
+#define        RECV_BUF_SIZE                           65536                   // 一度に受信するバッファサイズ\r
+\r
+// プロキシの種類\r
+#define        PROXY_DIRECT                    0       // 直接 TCP 接続\r
+#define        PROXY_HTTP                              1       // HTTP プロキシサーバー経由接続\r
+#define        PROXY_SOCKS                             2       // SOCKS プロキシサーバー経由接続\r
+\r
+// データの流れる方向\r
+#define        TCP_BOTH                                0       // 双方向\r
+#define        TCP_SERVER_TO_CLIENT    1       // サーバー -> クライアント方向のみ\r
+#define        TCP_CLIENT_TO_SERVER    2       // クライアント -> サーバー方向のみ\r
+\r
+// コネクションの種類\r
+#define        CONNECTION_TYPE_CLIENT                  0       // クライアント\r
+#define        CONNECTION_TYPE_INIT                    1       // 初期化中\r
+#define        CONNECTION_TYPE_LOGIN                   2       // ログインコネクション\r
+#define        CONNECTION_TYPE_ADDITIONAL              3       // 追加接続コネクション\r
+#define        CONNECTION_TYPE_FARM_RPC                4       // サーバーファーム用 RPC\r
+#define        CONNECTION_TYPE_ADMIN_RPC               5       // 管理用 RPC\r
+#define        CONNECTION_TYPE_ENUM_HUB                6       // HUB 列挙\r
+#define        CONNECTION_TYPE_PASSWORD                7       // パスワード変更\r
+\r
+// プロトコル\r
+#define        CONNECTION_TCP                                  0       // TCP プロトコル\r
+#define        CONNECTION_UDP                                  1       // UDP プロトコル\r
+#define        CONNECTION_HUB_LAYER3                   6       // Layer-3 スイッチ セッション\r
+#define        CONNECTION_HUB_BRIDGE                   7       // Bridge セッション\r
+#define        CONNECTION_HUB_SECURE_NAT               8       // Secure NAT セッション\r
+#define        CONNECTION_HUB_LINK_SERVER              9       // HUB リンクセッション\r
+\r
+\r
+// 状態\r
+#define        CONNECTION_STATUS_ACCEPTED              0       // 接続を受け付けた (クライアント側)\r
+#define        CONNECTION_STATUS_NEGOTIATION   1       // ネゴシエーション中\r
+#define        CONNECTION_STATUS_USERAUTH              2       // ユーザー認証中\r
+#define        CONNECTION_STATUS_ESTABLISHED   3       // コネクション確立済み\r
+#define        CONNECTION_STATUS_CONNECTING    0       // 接続中 (クライアント側)\r
+\r
+// KeepAlive パケットのマジックナンバー\r
+#define        KEEP_ALIVE_MAGIC                                0xffffffff\r
+#define        MAX_KEEPALIVE_SIZE                              512\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// 仮想 HUB 関連の定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        SE_HUB_MAC_ADDR_SIGN                            0xAE                                    // 仮想 HUB MAC アドレスのサイン\r
+\r
+// トラフィック差分値\r
+#define        TRAFFIC_DIFF_USER               0               // ユーザー\r
+#define        TRAFFIC_DIFF_HUB                1               // 仮想 HUB\r
+#define        MAX_TRAFFIC_DIFF                30000   // 最大件数\r
+\r
+// HUB の種類\r
+#define        HUB_TYPE_STANDALONE                     0       // スタンドアロン HUB\r
+#define        HUB_TYPE_FARM_STATIC            1       // スタティック HUB\r
+#define        HUB_TYPE_FARM_DYNAMIC           2       // ダイナミック HUB\r
+\r
+// アクセスリストにおける遅延、ジッタ、パケットロス関係\r
+#define        HUB_ACCESSLIST_DELAY_MAX        10000           // 最大遅延\r
+#define        HUB_ACCESSLIST_JITTER_MAX       100                     // 最大ジッタ\r
+#define        HUB_ACCESSLIST_LOSS_MAX         100                     // 最大パケットロス\r
+\r
+// メッセージ関係\r
+#define        HUB_MAXMSG_LEN                          20000           // 最大メッセージ文字数\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// ユーザー認証の種類\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+// サーバー側における定数\r
+#define        AUTHTYPE_ANONYMOUS                              0                       // 匿名認証\r
+#define        AUTHTYPE_PASSWORD                               1                       // パスワード認証\r
+#define        AUTHTYPE_USERCERT                               2                       // ユーザー証明書認証\r
+#define        AUTHTYPE_ROOTCERT                               3                       // 信頼するルート証明期間が発行する証明書\r
+#define        AUTHTYPE_RADIUS                                 4                       // Radius 認証\r
+#define        AUTHTYPE_NT                                             5                       // Windows NT 認証\r
+#define        AUTHTYPE_TICKET                                 99                      // チケット認証\r
+\r
+// クライアント側における定数\r
+#define        CLIENT_AUTHTYPE_ANONYMOUS               0                       // 匿名認証\r
+#define        CLIENT_AUTHTYPE_PASSWORD                1                       // パスワード認証\r
+#define        CLIENT_AUTHTYPE_PLAIN_PASSWORD  2                       // プレーンパスワード認証\r
+#define        CLIENT_AUTHTYPE_CERT                    3                       // 証明書認証\r
+#define        CLIENT_AUTHTYPE_SECURE                  4                       // セキュアデバイス認証\r
+\r
+// Radius 関係\r
+#define        RADIUS_DEFAULT_PORT             1812                    // デフォルトのポート番号\r
+#define        RADIUS_RETRY_INTERVAL   500                             // 再送間隔\r
+#define        RADIUS_RETRY_TIMEOUT    (10 * 1000)             // タイムアウト時間\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// TCP リスナー関係の定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+// Listen に失敗した場合の再試行回数\r
+#define        LISTEN_RETRY_TIME                       (2 * 1000)              // 普通に Listen に失敗した場合\r
+#define LISTEN_RETRY_TIME_NOIPV6       (60 * 1000)             // IPv6 サポートが無効な場合\r
+\r
+\r
+// リスナーの使用するプロトコル\r
+#define        LISTENER_TCP                            0               // TCP/IP\r
+#define        LISTENER_UDP                            1               // UDP/IP\r
+\r
+// リスナーの状態\r
+#define        LISTENER_STATUS_TRYING          0               // 試行中\r
+#define        LISTENER_STATUS_LISTENING       1               // Listen 中\r
+\r
+// 最大の UDP パケットサイズ\r
+#define        UDP_PACKET_SIZE                         65536\r
+\r
+// 標準の IP アドレスごとのコネクション数\r
+#define DEFAULT_MAX_CONNECTIONS_PER_IP 256\r
+#define MIN_MAX_CONNECTIONS_PER_IP     10              // 最小値\r
+\r
+// 許容される未処理のコネクション数\r
+#define        DEFAULT_MAX_UNESTABLISHED_CONNECTIONS   1000\r
+#define        MIN_MAX_UNESTABLISHED_CONNECTIONS       30      // 最小値\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// ログ関係の定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        LOG_ENGINE_SAVE_START_CACHE_COUNT       100000          // 強制的に保存を開始する数\r
+#define        LOG_ENGINE_BUFFER_CACHE_SIZE_MAX        (10 * 1024 * 1024)      // 書き込みキャッシュサイズ\r
+\r
+// ファイル名などの定数\r
+#define        SERVER_LOG_DIR_NAME                     "@server_log"\r
+#define        BRIDGE_LOG_DIR_NAME                     SERVER_LOG_DIR_NAME\r
+#define        SERVER_LOG_PERFIX                       "vpn"\r
+\r
+#define        HUB_SECURITY_LOG_DIR_NAME       "@security_log"\r
+#define        HUB_SECURITY_LOG_FILE_NAME      "@security_log/%s"\r
+#define        HUB_SECURITY_LOG_PREFIX         "sec"\r
+#define        HUB_PACKET_LOG_DIR_NAME         "@packet_log"\r
+#define        HUB_PACKET_LOG_FILE_NAME        "@packet_log/%s"\r
+#define        HUB_PACKET_LOG_PREFIX           "pkt"\r
+\r
+#define        NAT_LOG_DIR_NAME                        "@secure_nat_log"\r
+#define        NAT_LOG_FILE_NAME                       "@secure_nat_log/%s"\r
+#define        NAT_LOG_PREFIX                          "snat"\r
+\r
+#define        CLIENT_LOG_DIR_NAME                     "@client_log"\r
+#define        CLIENT_LOG_PREFIX                       "client"\r
+\r
+// パケットログ設定\r
+#define        NUM_PACKET_LOG                          16\r
+#define        PACKET_LOG_TCP_CONN                     0               // TCP コネクションログ\r
+#define        PACKET_LOG_TCP                          1               // TCP パケットログ\r
+#define        PACKET_LOG_DHCP                         2               // DHCP ログ\r
+#define        PACKET_LOG_UDP                          3               // UDP ログ\r
+#define        PACKET_LOG_ICMP                         4               // ICMP ログ\r
+#define        PACKET_LOG_IP                           5               // IP ログ\r
+#define        PACKET_LOG_ARP                          6               // ARP ログ\r
+#define        PACKET_LOG_ETHERNET                     7               // Ethernet ログ\r
+\r
+#define        PACKET_LOG_NONE                         0               // 保存しない\r
+#define        PACKET_LOG_HEADER                       1               // ヘッダのみ\r
+#define        PACKET_LOG_ALL                          2               // データも保存する\r
+\r
+// ログ切り替えのタイミング\r
+#define        LOG_SWITCH_NO                           0               // 切り替え無し\r
+#define        LOG_SWITCH_SECOND                       1               // 1 秒単位\r
+#define        LOG_SWITCH_MINUTE                       2               // 1 分単位\r
+#define        LOG_SWITCH_HOUR                         3               // 1 時間単位\r
+#define        LOG_SWITCH_DAY                          4               // 1 日単位\r
+#define        LOG_SWITCH_MONTH                        5               // 1 ヶ月単位\r
+\r
+// ディスクの空き容量の最小サイズ\r
+#define        DISK_FREE_SPACE_MIN                     1048576 // 1 MBytes\r
+#define        DISK_FREE_SPACE_DEFAULT         (DISK_FREE_SPACE_MIN * 100)     // 100 Mbytes\r
+\r
+// 空き容量をチェックする間隔\r
+#define        DISK_FREE_CHECK_INTERVAL        (5 * 60 * 1000)\r
+\r
+// 簡易ログ\r
+#define TINY_LOG_DIRNAME                       "@tiny_log"\r
+#define TINY_LOG_FILENAME                      "@tiny_log/%04u%02u%02u_%02u%02u%02u.log"\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// Carrier Edition 関係の定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define CE_SNAPSHOT_INTERVAL           ((UINT64)(3600 * 1000))\r
+//#define CE_SNAPSHOT_INTERVAL         ((UINT64)(3000))\r
+#define CE_SNAPSHOT_POLLING_INTERVAL   (1 * 1000)\r
+#define CE_SNAPSHOT_POLLING_INTERVAL_LICENSE   (30 * 1000)\r
+#define CE_SNAPSHOT_DIR_NAME           "@carrier_log"\r
+#define CE_SNAPSHOT_PREFIX                     "carrier"\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// 通信プロトコル関係の定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+// 管理者ユーザー名\r
+#define        ADMINISTRATOR_USERNAME          "administrator"\r
+// HTTP ヘッダの 1 行のサイズの最大値\r
+#define        HTTP_HEADER_LINE_MAX_SIZE       4096\r
+// PACK に含める乱数サイズの最大値\r
+#define        HTTP_PACK_RAND_SIZE_MAX         1000\r
+// ランダムサイズの最大値\r
+#define        RAND_SIZE_MAX                           4096\r
+// ランダムサイズキャッシュの有効期限\r
+#define        RAND_SIZE_CACHE_EXPIRE          (24 * 60 * 60 * 1000)\r
+// 管理許可 IP アドレスリストファイル名\r
+#define        ADMINIP_TXT                                     "@adminip.txt"\r
+\r
+#define NON_SSL_MIN_COUNT                      60\r
+#define NON_SSL_ENTRY_EXPIRES          (60 * 60 * 1000)\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// カスケード接続関係の定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        LINK_DEVICE_NAME                "_SEHUBLINKCLI_"\r
+#define        LINK_USER_NAME                  "link"\r
+#define        LINK_USER_NAME_PRINT    "Cascade"\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// SecureNAT 接続関係の定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        SNAT_DEVICE_NAME                "_SEHUBSECURENAT_"\r
+#define        SNAT_USER_NAME                  "securenat"\r
+#define        SNAT_USER_NAME_PRINT    "SecureNAT"\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// Bridge 接続関係の定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        BRIDGE_DEVICE_NAME                              "_SEHUBBRIDGE_"\r
+#define        BRIDGE_USER_NAME                                "localbridge"\r
+#define        BRIDGE_USER_NAME_PRINT                  "Local Bridge"\r
+#define        BRIDGE_TRY_SPAN                                 1000\r
+#define        BRIDGE_NUM_DEVICE_CHECK_SPAN    (5 * 60 * 1000)\r
+#define BRIDGE_NETWORK_CONNECTION_STR  L"%s [%S]"\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// EtherLogger 関係の定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        EL_ADMIN_PORT                   22888\r
+#define        EL_CONFIG_FILENAME              "@etherlogger.config"\r
+#define        EL_PACKET_LOG_DIR_NAME  "@etherlogger_log"\r
+#define        EL_PACKET_LOG_FILE_NAME "@etherlogger_log/%s"\r
+#define        EL_PACKET_LOG_PREFIX    "pkt"\r
+#define        EL_LICENSE_CHECK_SPAN   (10 * 1000)\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// Layer-3 Switch 関係の定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        MAX_NUM_L3_SWITCH               4096\r
+#define        MAX_NUM_L3_IF                   4096\r
+#define        MAX_NUM_L3_TABLE                4096\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// User-mode Router 関係の定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        ARP_ENTRY_EXPIRES                       (30 * 1000)             // ARP テーブル有効期限\r
+#define        ARP_ENTRY_POLLING_TIME          (1 * 1000)              // ARP テーブル清掃タイマ\r
+#define        ARP_REQUEST_TIMEOUT                     (200)                   // ARP リクエストタイムアウト時間\r
+#define        ARP_REQUEST_GIVEUP                      (5 * 1000)              // ARP リクエストの送信を諦める時刻\r
+#define        IP_WAIT_FOR_ARP_TIMEOUT         (5 * 1000)              // IP パケットが ARP テーブルを待つ合計時間\r
+#define        IP_COMBINE_TIMEOUT                      (10 * 1000)             // IP パケットの結合タイムアウト\r
+#define        NAT_TCP_MAX_TIMEOUT                     (2000000 * 1000)        // 最大 TCP セッションタイムアウト秒数\r
+#define        NAT_UDP_MAX_TIMEOUT                     (2000000 * 1000)        // 最大 UDP セッションタイムアウト秒数\r
+#define        NAT_TCP_MIN_TIMEOUT                     (5 * 60 * 1000)         // 最小 TCP セッションタイムアウト秒数\r
+#define        NAT_UDP_MIN_TIMEOUT                     (10 * 1000)                     // 最小 UDP セッションタイムアウト秒数\r
+#define        NAT_TCP_RECV_WINDOW_SIZE        64512                           // TCP 受信ウインドウサイズ\r
+#define        NAT_TCP_SYNACK_SEND_TIMEOUT     250                                     // TCP SYN+ACK 送信間隔\r
+#define        NAT_SEND_BUF_SIZE                       (64 * 1024)                     // TCP 送信バッファサイズ\r
+#define        NAT_RECV_BUF_SIZE                       (64 * 1024)                     // TCP 受信バッファサイズ\r
+#define        NAT_TMPBUF_SIZE                         (128 * 1024)            // TCP 一時メモリ領域サイズ\r
+#define        NAT_ACK_KEEPALIVE_SPAN          (5 * 1000)                      // TCP キープアライブ用 ACK 送信間隔\r
+#define        NAT_INITIAL_RTT_VALUE           500                                     // 初期 RTT 値\r
+#define        NAT_FIN_SEND_INTERVAL           1000                            // FIN 送信間隔\r
+#define        NAT_FIN_SEND_MAX_COUNT          5                                       // 合計 FIN 送信数\r
+#define        NAT_DNS_PROXY_PORT                      53                                      // DNS プロキシポート番号\r
+#define        NAT_DNS_RESPONSE_TTL            (20 * 60)                       // DNS 応答の TTL\r
+#define        NAT_DHCP_SERVER_PORT            67                                      // DHCP サーバーポート番号\r
+#define        DHCP_MIN_EXPIRE_TIMESPAN        (15 * 1000)                     // DHCP 最小有効期限\r
+#define        DHCP_POLLING_INTERVAL           1000                            // DHCP ポーリング間隔\r
+#define        X32                                                     ((UINT64)4294967296ULL) // 32bit + 1\r
+#define        NAT_DNS_QUERY_TIMEOUT           (512)                           // DNS クエリのタイムアウト値\r
+\r
+// ビーコン送信間隔\r
+#define        BEACON_SEND_INTERVAL            (5 * 1000)\r
+\r
+// IP パケットの結合用のキューで許容される合計サイズ クォータ\r
+#define        IP_COMBINE_WAIT_QUEUE_SIZE_QUOTA        (50 * 1024 * 1024)\r
+\r
+// ヘッダサイズ定数\r
+#define        MAC_HEADER_SIZE                         (sizeof(MAC_HEADER))\r
+#define        ARP_HEADER_SIZE                         (sizeof(ARPV4_HEADER))\r
+#define        IP_HEADER_SIZE                          (sizeof(IPV4_HEADER))\r
+#define        TCP_HEADER_SIZE                         (sizeof(TCP_HEADER))\r
+#define        UDP_HEADER_SIZE                         (sizeof(UDP_HEADER))\r
+\r
+// データ最大サイズ定数\r
+#define        MAX_L3_DATA_SIZE                        (1500)\r
+#define        MAX_IP_DATA_SIZE                        (MAX_L3_DATA_SIZE - IP_HEADER_SIZE)\r
+#define        MAX_TCP_DATA_SIZE                       (MAX_IP_DATA_SIZE - TCP_HEADER_SIZE)\r
+#define        MAX_UDP_DATA_SIZE                       (MAX_IP_DATA_SIZE - UDP_HEADER_SIZE)\r
+#define        MAX_IP_DATA_SIZE_TOTAL          (65535)\r
+\r
+// IP パケットオプション定数\r
+#define        DEFAULT_IP_TOS                          0                               // IP ヘッダの TOS\r
+#define        DEFAULT_IP_TTL                          128                             // IP ヘッダの TTL\r
+\r
+// NAT セッションの種類\r
+#define        NAT_TCP                                         0               // TCP NAT\r
+#define        NAT_UDP                                         1               // UDP NAT\r
+#define        NAT_DNS                                         2               // DNS NAT\r
+\r
+// NAT セッションの状態\r
+#define        NAT_TCP_CONNECTING                      0               // 接続中\r
+#define        NAT_TCP_SEND_RESET                      1               // RST を送信する (接続失敗または切断)\r
+#define        NAT_TCP_CONNECTED                       2               // 接続完了\r
+#define        NAT_TCP_ESTABLISHED                     3               // 接続確立済み\r
+#define        NAT_TCP_WAIT_DISCONNECT         4               // ソケット切断を待機\r
+\r
+// DHCP クライアント動作\r
+#define        DHCP_DISCOVER           1\r
+#define        DHCP_REQUEST            3\r
+\r
+// DHCP サーバー動作\r
+#define        DHCP_OFFER                      2\r
+#define        DHCP_ACK                        5\r
+#define        DHCP_NACK                       6\r
+\r
+// DHCP 関係の定数\r
+#define        DHCP_ID_MESSAGE_TYPE            0x35\r
+#define        DHCP_ID_REQUEST_IP_ADDRESS      0x32\r
+#define        DHCP_ID_HOST_NAME                       0x0c\r
+#define        DHCP_ID_SERVER_ADDRESS          0x36\r
+#define        DHCP_ID_LEASE_TIME                      0x33\r
+#define        DHCP_ID_DOMAIN_NAME                     0x0f\r
+#define        DHCP_ID_SUBNET_MASK                     0x01\r
+#define        DHCP_ID_GATEWAY_ADDR            0x03\r
+#define        DHCP_ID_DNS_ADDR                        0x06\r
+\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// UNIX 用仮想 LAN カード関係定数\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        TAP_FILENAME_1                          "/dev/net/tun"\r
+#define        TAP_FILENAME_2                          "/dev/tun"\r
+#define        TAP_MACOS_FILENAME                      "/dev/tap0"\r
+\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// ライセンスデータベース関係\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        LICENSE_MAX_PRODUCT_NAME_LEN    255                             // ライセンス製品名の最大長\r
+#define        LICENSE_KEYSTR_LEN                              41                              // ライセンスキーの長さ\r
+#define        LICENSE_LICENSEID_STR_LEN               33                              // ライセンス ID の長さ\r
+\r
+\r
+// ライセンスされている製品エディション\r
+#define        LICENSE_EDITION_VPN3_NO_LICENSE                                 0               // ライセンス無し\r
+#define        LICENSE_EDITION_UTVPN_GPL                                               201             // UT-VPN (GPL)\r
+\r
+// ライセンスステータス\r
+#define        LICENSE_STATUS_OK                               0               // 有効\r
+#define        LICENSE_STATUS_EXPIRED                  1               // 無効 (有効期限切れ)\r
+#define        LICENSE_STATUS_ID_DIFF                  2               // 無効 (システム ID 不一致)\r
+#define        LICENSE_STATUS_DUP                              3               // 無効 (重複)\r
+#define        LICENSE_STATUS_INSUFFICIENT             4               // 無効 (必要な他のライセンスが不足)\r
+#define        LICENSE_STATUS_COMPETITION              5               // 無効 (他のライセンスと競合)\r
+#define        LICENSE_STATUS_NONSENSE                 6               // 無効 (現在のエディションでは無意味)\r
+#define        LICENSE_STATUS_CPU                              7               // 無効 (CPU の種類が不一致)\r
+\r
+\r
+#define        BIT_TO_BYTE(x)                                  (((x) + 7) / 8)\r
+#define        BYTE_TO_BIT(x)                                  ((x) * 8)\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////\r
+// \r
+// エラーコード\r
+// \r
+//////////////////////////////////////////////////////////////////////\r
+\r
+#define        ERR_NO_ERROR                                    0       // エラー無し\r
+#define        ERR_CONNECT_FAILED                              1       // サーバーへの接続が失敗した\r
+#define        ERR_SERVER_IS_NOT_VPN                   2       // 接続先サーバーは VPN サーバーではない\r
+#define        ERR_DISCONNECTED                                3       // 接続が切断された\r
+#define        ERR_PROTOCOL_ERROR                              4       // プロトコルエラー\r
+#define        ERR_CLIENT_IS_NOT_VPN                   5       // 接続元クライアントは VPN クライアントではない\r
+#define        ERR_USER_CANCEL                                 6       // ユーザーキャンセル\r
+#define        ERR_AUTHTYPE_NOT_SUPPORTED              7       // 指定された認証方法はサポートされていない\r
+#define        ERR_HUB_NOT_FOUND                               8       // HUB が存在しない\r
+#define        ERR_AUTH_FAILED                                 9       // 認証失敗\r
+#define        ERR_HUB_STOPPING                                10      // HUB が停止中\r
+#define        ERR_SESSION_REMOVED                             11      // セッションが削除された\r
+#define        ERR_ACCESS_DENIED                               12      // アクセス拒否\r
+#define        ERR_SESSION_TIMEOUT                             13      // セッションがタイムアウトした\r
+#define        ERR_INVALID_PROTOCOL                    14      // プロトコルが不正\r
+#define        ERR_TOO_MANY_CONNECTION                 15      // コネクション数が多すぎる\r
+#define        ERR_HUB_IS_BUSY                                 16      // HUB のセッション数が多すぎる\r
+#define        ERR_PROXY_CONNECT_FAILED                17      // プロキシサーバーへの接続が失敗した\r
+#define        ERR_PROXY_ERROR                                 18      // プロキシエラーが発生\r
+#define        ERR_PROXY_AUTH_FAILED                   19      // プロキシサーバーでの認証に失敗\r
+#define        ERR_TOO_MANY_USER_SESSION               20      // 同一ユーザーのセッション数が多すぎる\r
+#define        ERR_LICENSE_ERROR                               21      // ライセンスエラー\r
+#define        ERR_DEVICE_DRIVER_ERROR                 22      // デバイスドライバエラー\r
+#define        ERR_INTERNAL_ERROR                              23      // 内部エラー\r
+#define        ERR_SECURE_DEVICE_OPEN_FAILED   24      // セキュアデバイスを開けなかった\r
+#define        ERR_SECURE_PIN_LOGIN_FAILED             25      // PIN コードが違う\r
+#define        ERR_SECURE_NO_CERT                              26      // 指定された証明書が格納されていない\r
+#define        ERR_SECURE_NO_PRIVATE_KEY               27      // 指定された秘密鍵が格納されていない\r
+#define        ERR_SECURE_CANT_WRITE                   28      // 書き込み失敗\r
+#define        ERR_OBJECT_NOT_FOUND                    29      // 指定されたオブジェクトが見つからない\r
+#define        ERR_VLAN_ALREADY_EXISTS                 30      // 指定された名前の仮想 LAN カードは存在する\r
+#define        ERR_VLAN_INSTALL_ERROR                  31      // 指定された仮想 LAN カードを生成できない\r
+#define        ERR_VLAN_INVALID_NAME                   32      // 指定された仮想 LAN カードの名前は不正\r
+#define        ERR_NOT_SUPPORTED                               33      // サポートされていない\r
+#define        ERR_ACCOUNT_ALREADY_EXISTS              34      // アカウントはすでに存在する\r
+#define        ERR_ACCOUNT_ACTIVE                              35      // アカウントは動作中\r
+#define        ERR_ACCOUNT_NOT_FOUND                   36      // 指定されたアカウントは無い\r
+#define        ERR_ACCOUNT_INACTIVE                    37      // アカウントは停止中\r
+#define        ERR_INVALID_PARAMETER                   38      // パラメータが不正\r
+#define        ERR_SECURE_DEVICE_ERROR                 39      // セキュアデバイスの操作でエラーが発生した\r
+#define        ERR_NO_SECURE_DEVICE_SPECIFIED  40      // セキュアデバイスが指定されていない\r
+#define        ERR_VLAN_IS_USED                                41      // 仮想 LAN カードはアカウントによって使用中\r
+#define        ERR_VLAN_FOR_ACCOUNT_NOT_FOUND  42      // アカウントの仮想 LAN カードが見つからない\r
+#define        ERR_VLAN_FOR_ACCOUNT_USED               43      // アカウントの仮想 LAN カードはすでに使用中\r
+#define        ERR_VLAN_FOR_ACCOUNT_DISABLED   44      // アカウントの仮想 LAN カードは無効化されている\r
+#define        ERR_INVALID_VALUE                               45      // 値が不正\r
+#define        ERR_NOT_FARM_CONTROLLER                 46      // ファームコントローラではない\r
+#define        ERR_TRYING_TO_CONNECT                   47      // 接続を試行中\r
+#define        ERR_CONNECT_TO_FARM_CONTROLLER  48      // ファームコントローラへの接続に失敗\r
+#define        ERR_COULD_NOT_HOST_HUB_ON_FARM  49      // ファーム上に仮想 HUB を作成できなかった\r
+#define        ERR_FARM_MEMBER_HUB_ADMIN               50      // ファームメンバで HUB を管理することはできない\r
+#define        ERR_NULL_PASSWORD_LOCAL_ONLY    51      // 空文字のパスワードのためローカル接続のみ受付中\r
+#define        ERR_NOT_ENOUGH_RIGHT                    52      // 権利が不足している\r
+#define        ERR_LISTENER_NOT_FOUND                  53      // リスナーが見つからない\r
+#define        ERR_LISTENER_ALREADY_EXISTS             54      // すでにリスナーが存在している\r
+#define        ERR_NOT_FARM_MEMBER                             55      // ファームメンバではない\r
+#define        ERR_CIPHER_NOT_SUPPORTED                56      // 暗号化アルゴリズムがサポートされていない\r
+#define        ERR_HUB_ALREADY_EXISTS                  57      // HUB はすでに存在する\r
+#define        ERR_TOO_MANY_HUBS                               58      // HUB が多すぎる\r
+#define        ERR_LINK_ALREADY_EXISTS                 59      // リンクはすでに存在する\r
+#define        ERR_LINK_CANT_CREATE_ON_FARM    60      // リンクはサーバーファーム上に作成できない\r
+#define        ERR_LINK_IS_OFFLINE                             61      // リンクはオフラインである\r
+#define        ERR_TOO_MANY_ACCESS_LIST                62      // アクセスリストが多すぎる\r
+#define        ERR_TOO_MANY_USER                               63      // ユーザーが多すぎる\r
+#define        ERR_TOO_MANY_GROUP                              64      // グループが多すぎる\r
+#define        ERR_GROUP_NOT_FOUND                             65      // グループが見つからない\r
+#define        ERR_USER_ALREADY_EXISTS                 66      // ユーザーがすでに存在する\r
+#define        ERR_GROUP_ALREADY_EXISTS                67      // グループがすでに存在する\r
+#define        ERR_USER_AUTHTYPE_NOT_PASSWORD  68      // ユーザーの認証方法はパスワード認証ではない\r
+#define        ERR_OLD_PASSWORD_WRONG                  69      // 古いパスワードが間違っているかユーザーが存在しない\r
+#define        ERR_LINK_CANT_DISCONNECT                73      // カスケード セッションは切断できない\r
+#define        ERR_ACCOUNT_NOT_PRESENT                 74      // VPN サーバーへの接続設定が未完了である\r
+#define        ERR_ALREADY_ONLINE                              75      // すでにオンラインである\r
+#define        ERR_OFFLINE                                             76      // オフラインである\r
+#define        ERR_NOT_RSA_1024                                77      // RSA 1024bit 以外の証明書である\r
+#define        ERR_SNAT_CANT_DISCONNECT                78      // SecureNAT セッションは切断できない\r
+#define        ERR_SNAT_NEED_STANDALONE                79      // SecureNAT はスタンドアロン HUB でしか動作しない\r
+#define        ERR_SNAT_NOT_RUNNING                    80      // SecureNAT 機能が動作していない\r
+#define        ERR_SE_VPN_BLOCK                                81      // システム管理者向けブロックツールで停止された (廃止)\r
+#define        ERR_BRIDGE_CANT_DISCONNECT              82      // Bridge セッションは切断できない\r
+#define        ERR_LOCAL_BRIDGE_STOPPING               83      // Bridge 機能は停止している\r
+#define        ERR_LOCAL_BRIDGE_UNSUPPORTED    84      // Bridge 機能がサポートされていない\r
+#define        ERR_CERT_NOT_TRUSTED                    85      // 接続先サーバーの証明書が信頼できない\r
+#define        ERR_PRODUCT_CODE_INVALID                86      // 製品コードが違う\r
+#define        ERR_VERSION_INVALID                             87      // バージョンが違う\r
+#define        ERR_CAPTURE_DEVICE_ADD_ERROR    88      // キャプチャデバイス追加失敗\r
+#define        ERR_VPN_CODE_INVALID                    89      // VPN コードが違う\r
+#define        ERR_CAPTURE_NOT_FOUND                   90      // キャプチャデバイスが見つからない\r
+#define        ERR_LAYER3_CANT_DISCONNECT              91      // Layer-3 セッションは切断できない\r
+#define        ERR_LAYER3_SW_EXISTS                    92      // すでに同一の L3 スイッチが存在する\r
+#define        ERR_LAYER3_SW_NOT_FOUND                 93      // Layer-3 スイッチが見つからない\r
+#define        ERR_INVALID_NAME                                94      // 名前が不正\r
+#define        ERR_LAYER3_IF_ADD_FAILED                95      // インターフェイスの追加に失敗した\r
+#define        ERR_LAYER3_IF_DEL_FAILED                96      // インターフェイスの削除に失敗した\r
+#define        ERR_LAYER3_IF_EXISTS                    97      // 指定したインターフェイスはすでに存在する\r
+#define        ERR_LAYER3_TABLE_ADD_FAILED             98      // ルーティングテーブルの追加に失敗した\r
+#define        ERR_LAYER3_TABLE_DEL_FAILED             99      // ルーティングテーブルの削除に失敗した\r
+#define        ERR_LAYER3_TABLE_EXISTS                 100     // 指定したルーティングテーブルはすでに存在する\r
+#define        ERR_BAD_CLOCK                                   101     // 時刻がおかしい\r
+#define        ERR_LAYER3_CANT_START_SWITCH    102     // 仮想レイヤ 3 スイッチを開始できない\r
+#define        ERR_CLIENT_LICENSE_NOT_ENOUGH   103     // クライアント接続ライセンス数不足\r
+#define        ERR_BRIDGE_LICENSE_NOT_ENOUGH   104 // ブリッジ接続ライセンス数不足\r
+#define        ERR_SERVER_CANT_ACCEPT                  105     // 技術的な問題で Accept していない\r
+#define        ERR_SERVER_CERT_EXPIRES                 106     // 接続先 VPN サーバーの有効期限が切れている\r
+#define        ERR_MONITOR_MODE_DENIED                 107     // モニタポートモードは拒否された\r
+#define        ERR_BRIDGE_MODE_DENIED                  108     // ブリッジまたはルーティングモードは拒否された\r
+#define        ERR_IP_ADDRESS_DENIED                   109     // クライアント IP アドレスが拒否された\r
+#define        ERR_TOO_MANT_ITEMS                              110     // 項目数が多すぎる\r
+#define        ERR_MEMORY_NOT_ENOUGH                   111     // メモリ不足\r
+#define        ERR_OBJECT_EXISTS                               112     // オブジェクトはすでに存在している\r
+#define        ERR_FATAL                                               113     // 致命的なエラーが発生した\r
+#define        ERR_SERVER_LICENSE_FAILED               114     // サーバー側でライセンス違反が発生した\r
+#define        ERR_SERVER_INTERNET_FAILED              115     // サーバー側がインターネットに接続されていない\r
+#define        ERR_CLIENT_LICENSE_FAILED               116     // クライアント側でライセンス違反が発生した\r
+#define        ERR_BAD_COMMAND_OR_PARAM                117     // コマンドまたはパラメータが不正\r
+#define        ERR_INVALID_LICENSE_KEY                 118     // ライセンスキー不正\r
+#define        ERR_NO_VPN_SERVER_LICENSE               119     // VPN Server の有効なライセンスが無い\r
+#define        ERR_NO_VPN_CLUSTER_LICENSE              120     // クラスタライセンスが無い\r
+#define ERR_NOT_ADMINPACK_SERVER               121     // Administrator Pack ライセンスを持ったサーバーに接続しようとしていない\r
+#define ERR_NOT_ADMINPACK_SERVER_NET   122     // Administrator Pack ライセンスを持ったサーバーに接続しようとしていない (.NET 用)\r
+#define ERR_BETA_EXPIRES                               123     // 接続先 VPN Server のベータ版の有効期限が切れている\r
+#define ERR_BRANDED_C_TO_S                             124 // 接続制限用のブランド化文字列が異なる(サーバ側での認証用)\r
+#define ERR_BRANDED_C_FROM_S                   125     // 接続制限用のブランド化文字列が異なる(クライアント側での認証用)\r
+#define        ERR_AUTO_DISCONNECTED                   126     // 一定時間が経過したため VPN セッションが切断された\r
+#define        ERR_CLIENT_ID_REQUIRED                  127     // クライアント ID が一致していない\r
+#define        ERR_TOO_MANY_USERS_CREATED              128     // 作成されているユーザー数が多すぎる\r
+#define        ERR_SUBSCRIPTION_IS_OLDER               129     // サブスクリプションの期限が VPN Server のビルド日時よりも前である\r
+#define        ERR_UTVPN_NOT_SUPPORT_THIS_AUTH 130     // UT-VPN はこの認証方法を実装していない\r
+#define        ERR_UTVPN_NOT_SUPPORT_THIS_FUNC 131     // UT-VPN はこの機能を実装していない\r
+\r
+\r
+////////////////////////////\r
+// 全般的に使用される構造体\r
+\r
+// ネットワーク サービス\r
+typedef struct NETSVC\r
+{\r
+       bool Udp;                                               // false=TCP, true=UDP\r
+       UINT Port;                                              // ポート番号\r
+       char *Name;                                             // 名称\r
+} NETSVC;\r
+\r
+// トラフィックデータエントリ\r
+typedef struct TRAFFIC_ENTRY\r
+{\r
+       UINT64 BroadcastCount;                  // ブロードキャストパケット数\r
+       UINT64 BroadcastBytes;                  // ブロードキャストバイト数\r
+       UINT64 UnicastCount;                    // ユニキャストカウント数\r
+       UINT64 UnicastBytes;                    // ユニキャストバイト数\r
+} TRAFFIC_ENTRY;\r
+\r
+// トラフィックデータ\r
+typedef struct TRAFFIC\r
+{\r
+       TRAFFIC_ENTRY Send;                             // 送信データ\r
+       TRAFFIC_ENTRY Recv;                             // 受信データ\r
+} TRAFFIC;\r
+\r
+// 非 SSL 接続元\r
+typedef struct NON_SSL\r
+{\r
+       IP IpAddress;                                   // IP アドレス\r
+       UINT64 EntryExpires;                    // エントリの有効期限\r
+       UINT Count;                                             // 接続回数\r
+} NON_SSL;\r
+\r
+// 簡易ログ保存\r
+typedef struct TINY_LOG\r
+{\r
+       char FileName[MAX_PATH];                // ファイル名\r
+       IO *io;                                                 // ファイル\r
+       LOCK *Lock;                                             // ロック\r
+} TINY_LOG;\r
+\r
+// CEDAR 構造体\r
+typedef struct CEDAR\r
+{\r
+       LOCK *lock;                                             // ロック\r
+       REF *ref;                                               // 参照カウンタ\r
+       COUNTER *AcceptingSockets;              // Accept 中のソケット数\r
+       UINT Type;                                              // 種類\r
+       LIST *ListenerList;                             // リスナーリスト\r
+       LIST *HubList;                                  // HUB リスト\r
+       LIST *ConnectionList;                   // ネゴシエーション中のコネクションリスト\r
+       LIST *CaList;                                   // CA のリスト\r
+       volatile bool Halt;                             // 停止フラグ\r
+       COUNTER *ConnectionIncrement;   // コネクションインクリメントカウンタ\r
+       X *ServerX;                                             // サーバー証明書\r
+       K *ServerK;                                             // サーバー証明書の秘密鍵\r
+       char *CipherList;                               // 暗号化アルゴリズムのリスト\r
+       UINT Version;                                   // バージョン情報\r
+       UINT Build;                                             // ビルド番号\r
+       char *ServerStr;                                // サーバー文字列\r
+       char *MachineName;                              // コンピュータ名\r
+       char *HttpUserAgent;                    // HTTP ユーザーエージェント\r
+       char *HttpAccept;                               // HTTP Accept\r
+       char *HttpAcceptLanguage;               // HTTP Accept Language\r
+       char *HttpAcceptEncoding;               // HTTP Accept Encoding\r
+       TRAFFIC *Traffic;                               // トラフィック情報\r
+       LOCK *TrafficLock;                              // トラフィック情報ロック\r
+       LIST *UDPEntryList;                             // UDP エントリリスト\r
+       COUNTER *CurrentSessions;               // 現在のセッション数\r
+       COUNTER *CurrentTcpConnections; // 現在の TCP コネクション数\r
+       LIST *NetSvcList;                               // ネットワークサービスリスト\r
+       char *VerString;                                // バージョン文字列\r
+       char *BuildInfo;                                // ビルド情報\r
+       struct CLIENT *Client;                  // クライアント\r
+       struct SERVER *Server;                  // サーバー\r
+       UINT64 CreatedTick;                             // 生成日時\r
+       bool CheckExpires;                              // 有効期限をチェックする\r
+       LIST *TrafficDiffList;                  // トラフィック差分リスト\r
+       struct LOG *DebugLog;                   // デバッグログ\r
+       UCHAR UniqueId[16];                             // ユニーク ID\r
+       LIST *LocalBridgeList;                  // ローカルブリッジリスト\r
+       bool Bridge;                                    // ブリッジ版\r
+       LIST *L3SwList;                                 // Layer-3 スイッチリスト\r
+       COUNTER *AssignedClientLicense; // 割り当て済みクライアントライセンス数\r
+       COUNTER *AssignedBridgeLicense; // 割り当て済みブリッジライセンス数\r
+       UINT64 LicenseViolationTick;    // ライセンス違反発生\r
+       LIST *NonSslList;                               // 非 SSL 接続リスト\r
+       struct WEBUI *WebUI;                    // WebUI サービス用データ\r
+       UINT Beta;                                              // ベータ番号\r
+       LOCK *CedarSuperLock;                   // シーダー スーパー ロック!\r
+       bool DisableIPv6Listener;               // IPv6 リスナーを無効にする\r
+       UINT ClientId;                                  // クライアント ID\r
+       UINT64 BuiltDate;                               // ビルドされた日付\r
+} CEDAR;\r
+\r
+// CEDAR の種類\r
+#define        CEDAR_CLIENT                            0       // クライアント\r
+#define        CEDAR_STANDALONE_SERVER         1       // スタンドアロンサーバー\r
+#define        CEDAR_FARM_CONTROLLER           2       // サーバーファーム コントローラ\r
+#define        CEDAR_FARM_MEMBER                       3       // サーバーファーム メンバー\r
+\r
+\r
+////////////////////////////\r
+// ヘッダファイルの読み込み\r
+\r
+// 型\r
+#include <Cedar/CedarType.h>\r
+// アカウントマネージャ\r
+#include <Cedar/Account.h>\r
+// リスナー モジュール\r
+#include <Cedar/Listener.h>\r
+// TCP/IP\r
+#include <Cedar/TcpIp.h>\r
+// ログ保存モジュール\r
+#include <Cedar/Logging.h>\r
+// コネクション管理\r
+#include <Cedar/Connection.h>\r
+// セッション管理\r
+#include <Cedar/Session.h>\r
+// RPC\r
+#include <Cedar/Remote.h>\r
+// HUB 管理\r
+#include <Cedar/Hub.h>\r
+// セキュリティアカウントマネージャ\r
+#include <Cedar/Sam.h>\r
+// プロトコル\r
+#include <Cedar/Protocol.h>\r
+// HUB 間リンク\r
+#include <Cedar/Link.h>\r
+// ユーザーモード仮想ホスト\r
+#include <Cedar/Virtual.h>\r
+// SecureNAT\r
+#include <Cedar/SecureNAT.h>\r
+// コンソール サービス\r
+#include <Cedar/Console.h>\r
+// vpncmd ユーティリティ\r
+#include <Cedar/Command.h>\r
+\r
+#ifdef OS_WIN32\r
+// Sen デバイスドライバ\r
+#include <Sen/Sen.h>\r
+#endif // OS_WIN32\r
+\r
+// Sen デバイスドライバ操作用ライブラリ\r
+#include <Cedar/VLan.h>\r
+// ブリッジ\r
+#include <Cedar/Bridge.h>\r
+// Layer-3 スイッチ\r
+#include <Cedar/Layer3.h>\r
+// テスト用仮想 LAN カード\r
+#include <Cedar/NullLan.h>\r
+// クライアント\r
+#include <Cedar/Client.h>\r
+/// サーバー\r
+#include <Cedar/Server.h>\r
+// ライセンスデータベース\r
+#include <Cedar/Database.h>\r
+// 管理 RPC\r
+#include <Cedar/Admin.h>\r
+// User-mode Router\r
+#include <Cedar/Nat.h>\r
+\r
+#ifdef OS_WIN32\r
+\r
+// Win32 ユーザーインターフェイス\r
+#include <Cedar/WinUi.h>\r
+// Win32 クライアント接続マネージャ\r
+#include <Cedar/CM.h>\r
+// Win32 Server Manager\r
+#include <Cedar/SM.h>\r
+// Win32 User-mode Router Manager\r
+#include <Cedar/NM.h>\r
+// Win32 Network Utility\r
+#include <Cedar/UT.h>\r
+// Win32 HTML 表示モジュール\r
+#include <Cedar/Win32Html.h>\r
+\r
+#endif\r
+\r
+\r
+\r
+\r
+////////////////////////////\r
+// 関数プロトタイプ\r
+\r
+TRAFFIC *NewTraffic();\r
+void FreeTraffic(TRAFFIC *t);\r
+CEDAR *NewCedar(X *server_x, K *server_k);\r
+void SetCedarVpnBridge(CEDAR *c);\r
+void SetCedarCert(CEDAR *c, X *server_x, K *server_k);\r
+void ReleaseCedar(CEDAR *c);\r
+void CleanupCedar(CEDAR *c);\r
+void StopCedar(CEDAR *c);\r
+void AddListener(CEDAR *c, LISTENER *r);\r
+void StopAllListener(CEDAR *c);\r
+void AddTraffic(TRAFFIC *dst, TRAFFIC *diff);\r
+void AddHub(CEDAR *c, HUB *h);\r
+void DelHub(CEDAR *c, HUB *h);\r
+void DelHubEx(CEDAR *c, HUB *h, bool no_lock);\r
+void StopAllHub(CEDAR *c);\r
+void StopAllConnection(CEDAR *c);\r
+void AddConnection(CEDAR *cedar, CONNECTION *c);\r
+UINT GetUnestablishedConnections(CEDAR *cedar);\r
+void DelConnection(CEDAR *cedar, CONNECTION *c);\r
+void SetCedarCipherList(CEDAR *cedar, char *name);\r
+void InitCedar();\r
+void FreeCedar();\r
+void AddCa(CEDAR *cedar, X *x);\r
+bool DeleteCa(CEDAR *cedar, UINT ptr);\r
+bool CheckSignatureByCa(CEDAR *cedar, X *x);\r
+bool CheckSignatureByCaLinkMode(SESSION *s, X *x);\r
+X *FindCaSignedX(LIST *o, X *x);\r
+void InitNetSvcList(CEDAR *cedar);\r
+void FreeNetSvcList(CEDAR *cedar);\r
+int CompareNetSvc(void *p1, void *p2);\r
+char *GetSvcName(CEDAR *cedar, bool udp, UINT port);\r
+void InitHiddenPassword(char *str, UINT size);\r
+bool IsHiddenPasswordChanged(char *str);\r
+UINT64 GetTrafficPacketSize(TRAFFIC *t);\r
+UINT64 GetTrafficPacketNum(TRAFFIC *t);\r
+void EnableDebugLog(CEDAR *c);\r
+void StartCedarLog();\r
+void StopCedarLog();\r
+void CedarLog(char *str);\r
+int CompareNoSslList(void *p1, void *p2);\r
+void InitNoSslList(CEDAR *c);\r
+void FreeNoSslList(CEDAR *c);\r
+bool AddNoSsl(CEDAR *c, IP *ip);\r
+void DecrementNoSsl(CEDAR *c, IP *ip, UINT num_dec);\r
+void DeleteOldNoSsl(CEDAR *c);\r
+NON_SSL *SearchNoSslList(CEDAR *c, IP *ip);\r
+bool IsInNoSsl(CEDAR *c, IP *ip);\r
+void FreeTinyLog(TINY_LOG *t);\r
+void WriteTinyLog(TINY_LOG *t, char *str);\r
+TINY_LOG *NewTinyLog();\r
+void GetWinVer(RPC_WINVER *v);\r
+bool IsSupportedWinVer(RPC_WINVER *v);\r
+bool IsLaterBuild(CEDAR *c, UINT64 t);\r
+\r
+\r
+#endif // CEDAR_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/CedarPch.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/CedarPch.c
new file mode 100644 (file)
index 0000000..97ed74b
--- /dev/null
@@ -0,0 +1,82 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// CedarPch.c\r
+// Cedar 用プリコンパイルヘッダ生成コード\r
+\r
+#include "CedarPch.h"\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/CedarPch.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/CedarPch.h
new file mode 100644 (file)
index 0000000..2d115d1
--- /dev/null
@@ -0,0 +1,91 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// CedarPch.h\r
+// Cedar 用プリコンパイルヘッダ生成用ヘッダファイル\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/CedarType.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/CedarType.h
new file mode 100644 (file)
index 0000000..5e79235
--- /dev/null
@@ -0,0 +1,528 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// CedarType.h\r
+// Cedar が使用している型の一覧\r
+\r
+#ifndef        CEDARTYPE_H\r
+#define        CEDARTYPE_H\r
+\r
+\r
+// ==============================================================\r
+//   Remote Procedure Call\r
+// ==============================================================\r
+\r
+typedef struct RPC RPC;\r
+\r
+\r
+// ==============================================================\r
+//   Account\r
+// ==============================================================\r
+\r
+typedef struct POLICY_ITEM POLICY_ITEM;\r
+typedef struct POLICY POLICY;\r
+typedef struct USERGROUP USERGROUP;\r
+typedef struct USER USER;\r
+typedef struct AUTHPASSWORD AUTHPASSWORD;\r
+typedef struct AUTHUSERCERT AUTHUSERCERT;\r
+typedef struct AUTHROOTCERT AUTHROOTCERT;\r
+typedef struct AUTHRADIUS AUTHRADIUS;\r
+typedef struct AUTHNT AUTHNT;\r
+\r
+\r
+// ==============================================================\r
+//   Listener\r
+// ==============================================================\r
+\r
+typedef struct LISTENER LISTENER;\r
+typedef struct TCP_ACCEPTED_PARAM TCP_ACCEPTED_PARAM;\r
+typedef struct UDP_ENTRY UDP_ENTRY;\r
+\r
+\r
+// ==============================================================\r
+//   Logging\r
+// ==============================================================\r
+\r
+typedef struct PACKET_LOG PACKET_LOG;\r
+typedef struct HUB_LOG HUB_LOG;\r
+typedef struct RECORD RECORD;\r
+typedef struct LOG LOG;\r
+typedef struct ERASER ERASER;\r
+typedef struct SLOG SLOG;\r
+\r
+\r
+// ==============================================================\r
+//   Connection\r
+// ==============================================================\r
+\r
+typedef struct KEEP KEEP;\r
+typedef struct SECURE_SIGN SECURE_SIGN;\r
+typedef struct RC4_KEY_PAIR RC4_KEY_PAIR;\r
+typedef struct CLIENT_OPTION CLIENT_OPTION;\r
+typedef struct CLIENT_AUTH CLIENT_AUTH;\r
+typedef struct TCPSOCK TCPSOCK;\r
+typedef struct TCP TCP;\r
+typedef struct UDP UDP;\r
+typedef struct BLOCK BLOCK;\r
+typedef struct CONNECTION CONNECTION;\r
+\r
+\r
+// ==============================================================\r
+//   Session\r
+// ==============================================================\r
+\r
+typedef struct NODE_INFO NODE_INFO;\r
+typedef struct PACKET_ADAPTER PACKET_ADAPTER;\r
+typedef struct SESSION SESSION;\r
+typedef struct UI_PASSWORD_DLG UI_PASSWORD_DLG;\r
+typedef struct UI_MSG_DLG UI_MSG_DLG;\r
+typedef struct UI_NICINFO UI_NICINFO;\r
+typedef struct UI_CONNECTERROR_DLG UI_CONNECTERROR_DLG;\r
+typedef struct UI_CHECKCERT UI_CHECKCERT;\r
+\r
+\r
+// ==============================================================\r
+//   Hub\r
+// ==============================================================\r
+\r
+typedef struct SE_LINK SE_LINK;\r
+typedef struct TEST_HISTORY TEST_HISTORY;\r
+typedef struct SE_TEST SE_TEST;\r
+typedef struct HUBDB HUBDB;\r
+typedef struct TRAFFIC_LIMITER TRAFFIC_LIMITER;\r
+typedef struct STORM STORM;\r
+typedef struct HUB_PA HUB_PA;\r
+typedef struct HUB_OPTION HUB_OPTION;\r
+typedef struct MAC_TABLE_ENTRY MAC_TABLE_ENTRY;\r
+typedef struct IP_TABLE_ENTRY IP_TABLE_ENTRY;\r
+typedef struct LOOP_LIST LOOP_LIST;\r
+typedef struct ACCESS ACCESS;\r
+typedef struct TICKET TICKET;\r
+typedef struct TRAFFIC_DIFF TRAFFIC_DIFF;\r
+typedef struct HUB HUB;\r
+typedef struct ADMIN_OPTION ADMIN_OPTION;\r
+typedef struct CRL CRL;\r
+typedef struct AC AC;\r
+\r
+\r
+// ==============================================================\r
+//   Protocol\r
+// ==============================================================\r
+\r
+typedef struct CHECK_CERT_THREAD_PROC CHECK_CERT_THREAD_PROC;\r
+typedef struct SECURE_SIGN_THREAD_PROC SECURE_SIGN_THREAD_PROC;\r
+typedef struct RAND_CACHE RAND_CACHE;\r
+typedef struct HTTP_VALUE HTTP_VALUE;\r
+typedef struct HTTP_HEADER HTTP_HEADER;\r
+typedef struct SEND_SIGNATURE_PARAM SEND_SIGNATURE_PARAM;\r
+\r
+\r
+// ==============================================================\r
+//   Link\r
+// ==============================================================\r
+\r
+typedef struct LINK LINK;\r
+\r
+\r
+// ==============================================================\r
+//   Virtual\r
+// ==============================================================\r
+\r
+typedef struct ARP_ENTRY ARP_ENTRY;\r
+typedef struct ARP_WAIT ARP_WAIT;\r
+typedef struct IP_WAIT IP_WAIT;\r
+typedef struct IP_PART IP_PART;\r
+typedef struct IP_COMBINE IP_COMBINE;\r
+typedef struct NAT_ENTRY NAT_ENTRY;\r
+typedef struct TCP_OPTION TCP_OPTION;\r
+typedef struct VH VH;\r
+typedef struct VH_OPTION VH_OPTION;\r
+typedef struct DHCP_OPTION DHCP_OPTION;\r
+typedef struct DHCP_OPTION_LIST DHCP_OPTION_LIST;\r
+typedef struct DHCP_LEASE DHCP_LEASE;\r
+\r
+\r
+// ==============================================================\r
+//   VLAN\r
+// ==============================================================\r
+\r
+typedef struct ROUTE_TRACKING ROUTE_TRACKING;\r
+typedef struct VLAN VLAN;\r
+typedef struct INSTANCE_LIST INSTANCE_LIST;\r
+typedef struct VLAN_PARAM VLAN_PARAM;\r
+\r
+#ifdef OS_UNIX\r
+typedef struct UNIX_VLAN_LIST UNIX_VLAN_LIST;\r
+#endif // OS_UNIX\r
+\r
+// ==============================================================\r
+//   Null LAN\r
+// ==============================================================\r
+\r
+typedef struct NULL_LAN NULL_LAN;\r
+\r
+\r
+// ==============================================================\r
+//   Bridge\r
+// ==============================================================\r
+\r
+typedef struct ETH ETH;\r
+typedef struct BRIDGE BRIDGE;\r
+typedef struct LOCALBRIDGE LOCALBRIDGE;\r
+\r
+\r
+// ==============================================================\r
+//   Layer-3 Switch\r
+// ==============================================================\r
+\r
+typedef struct L3IF L3IF;\r
+typedef struct L3SW L3SW;\r
+typedef struct L3TABLE L3TABLE;\r
+typedef struct L3ARPENTRY L3ARPENTRY;\r
+typedef struct L3ARPWAIT L3ARPWAIT;\r
+typedef struct L3PACKET L3PACKET;\r
+\r
+\r
+// ==============================================================\r
+//   Client\r
+// ==============================================================\r
+\r
+typedef struct ACCOUNT ACCOUNT;\r
+typedef struct CLIENT_CONFIG CLIENT_CONFIG;\r
+typedef struct RPC_CLIENT_VERSION RPC_CLIENT_VERSION;\r
+typedef struct RPC_CLIENT_PASSWORD RPC_CLIENT_PASSWORD;\r
+typedef struct RPC_CLIENT_PASSWORD_SETTING RPC_CLIENT_PASSWORD_SETTING;\r
+typedef struct RPC_CLIENT_ENUM_CA_ITEM RPC_CLIENT_ENUM_CA_ITEM;\r
+typedef struct RPC_CLIENT_ENUM_CA RPC_CLIENT_ENUM_CA;\r
+typedef struct RPC_CERT RPC_CERT;\r
+typedef struct RPC_CLIENT_DELETE_CA RPC_CLIENT_DELETE_CA;\r
+typedef struct RPC_GET_CA RPC_GET_CA;\r
+typedef struct RPC_GET_ISSUER RPC_GET_ISSUER;\r
+typedef struct RPC_CLIENT_ENUM_SECURE_ITEM RPC_CLIENT_ENUM_SECURE_ITEM;\r
+typedef struct RPC_CLIENT_ENUM_SECURE RPC_CLIENT_ENUM_SECURE;\r
+typedef struct RPC_USE_SECURE RPC_USE_SECURE;\r
+typedef struct RPC_ENUM_OBJECT_IN_SECURE RPC_ENUM_OBJECT_IN_SECURE;\r
+typedef struct RPC_CLIENT_CREATE_VLAN RPC_CLIENT_CREATE_VLAN;\r
+typedef struct RPC_CLIENT_GET_VLAN RPC_CLIENT_GET_VLAN;\r
+typedef struct RPC_CLIENT_SET_VLAN RPC_CLIENT_SET_VLAN;\r
+typedef struct RPC_CLIENT_ENUM_VLAN_ITEM RPC_CLIENT_ENUM_VLAN_ITEM;\r
+typedef struct RPC_CLIENT_ENUM_VLAN RPC_CLIENT_ENUM_VLAN;\r
+typedef struct RPC_CLIENT_CREATE_ACCOUNT RPC_CLIENT_CREATE_ACCOUNT;\r
+typedef struct RPC_CLIENT_ENUM_ACCOUNT_ITEM RPC_CLIENT_ENUM_ACCOUNT_ITEM;\r
+typedef struct RPC_CLIENT_ENUM_ACCOUNT RPC_CLIENT_ENUM_ACCOUNT;\r
+typedef struct RPC_CLIENT_DELETE_ACCOUNT RPC_CLIENT_DELETE_ACCOUNT;\r
+typedef struct RPC_RENAME_ACCOUNT RPC_RENAME_ACCOUNT;\r
+typedef struct RPC_CLIENT_GET_ACCOUNT RPC_CLIENT_GET_ACCOUNT;\r
+typedef struct RPC_CLIENT_CONNECT RPC_CLIENT_CONNECT;\r
+typedef struct RPC_CLIENT_GET_CONNECTION_STATUS RPC_CLIENT_GET_CONNECTION_STATUS;\r
+typedef struct CLIENT_RPC_CONNECTION CLIENT_RPC_CONNECTION;\r
+typedef struct CLIENT CLIENT;\r
+typedef struct RPC_CLIENT_NOTIFY RPC_CLIENT_NOTIFY;\r
+typedef struct REMOTE_CLIENT REMOTE_CLIENT;\r
+typedef struct NOTIFY_CLIENT NOTIFY_CLIENT;\r
+typedef struct UNIX_VLAN UNIX_VLAN;\r
+typedef struct CM_SETTING CM_SETTING;\r
+\r
+\r
+// ==============================================================\r
+//   Server\r
+// ==============================================================\r
+\r
+typedef struct HUB_LIST HUB_LIST;\r
+typedef struct FARM_TASK FARM_TASK;\r
+typedef struct FARM_MEMBER FARM_MEMBER;\r
+typedef struct FARM_CONTROLLER FARM_CONTROLLER;\r
+typedef struct SERVER_LISTENER SERVER_LISTENER;\r
+typedef struct SERVER SERVER;\r
+typedef struct RPC_ENUM_SESSION RPC_ENUM_SESSION;\r
+typedef struct RPC_SESSION_STATUS RPC_SESSION_STATUS;\r
+typedef struct CAPS CAPS;\r
+typedef struct CAPSLIST CAPSLIST;\r
+typedef struct LOG_FILE LOG_FILE;\r
+typedef struct SYSLOG_SETTING SYSLOG_SETTING;\r
+typedef struct HUB_SNAPSHOT HUB_SNAPSHOT;\r
+typedef struct SERVER_SNAPSHOT SERVER_SNAPSHOT;\r
+typedef struct SERVER_HUB_CREATE_HISTORY SERVER_HUB_CREATE_HISTORY;\r
+\r
+// ==============================================================\r
+//   Server Admin Tool\r
+// ==============================================================\r
+\r
+typedef struct ADMIN ADMIN;\r
+typedef struct RPC_TEST RPC_TEST;\r
+typedef struct RPC_SERVER_INFO RPC_SERVER_INFO;\r
+typedef struct RPC_SERVER_STATUS RPC_SERVER_STATUS;\r
+typedef struct RPC_LISTENER RPC_LISTENER;\r
+typedef struct RPC_LISTENER_LIST RPC_LISTENER_LIST;\r
+typedef struct RPC_STR RPC_STR;\r
+typedef struct RPC_SET_PASSWORD RPC_SET_PASSWORD;\r
+typedef struct RPC_FARM RPC_FARM;\r
+typedef struct RPC_FARM_HUB RPC_FARM_HUB;\r
+typedef struct RPC_FARM_INFO RPC_FARM_INFO;\r
+typedef struct RPC_ENUM_FARM_ITEM RPC_ENUM_FARM_ITEM;\r
+typedef struct RPC_ENUM_FARM RPC_ENUM_FARM;\r
+typedef struct RPC_FARM_CONNECTION_STATUS RPC_FARM_CONNECTION_STATUS;\r
+typedef struct RPC_KEY_PAIR RPC_KEY_PAIR;\r
+typedef struct RPC_HUB_OPTION RPC_HUB_OPTION;\r
+typedef struct RPC_RADIUS RPC_RADIUS;\r
+typedef struct RPC_HUB RPC_HUB;\r
+typedef struct RPC_CREATE_HUB RPC_CREATE_HUB;\r
+typedef struct RPC_ENUM_HUB_ITEM RPC_ENUM_HUB_ITEM;\r
+typedef struct RPC_ENUM_HUB RPC_ENUM_HUB;\r
+typedef struct RPC_DELETE_HUB RPC_DELETE_HUB;\r
+typedef struct RPC_ENUM_CONNECTION_ITEM RPC_ENUM_CONNECTION_ITEM;\r
+typedef struct RPC_ENUM_CONNECTION RPC_ENUM_CONNECTION;\r
+typedef struct RPC_DISCONNECT_CONNECTION RPC_DISCONNECT_CONNECTION;\r
+typedef struct RPC_CONNECTION_INFO RPC_CONNECTION_INFO;\r
+typedef struct RPC_SET_HUB_ONLINE RPC_SET_HUB_ONLINE;\r
+typedef struct RPC_HUB_STATUS RPC_HUB_STATUS;\r
+typedef struct RPC_HUB_LOG RPC_HUB_LOG;\r
+typedef struct RPC_HUB_ADD_CA RPC_HUB_ADD_CA;\r
+typedef struct RPC_HUB_ENUM_CA_ITEM RPC_HUB_ENUM_CA_ITEM;\r
+typedef struct RPC_HUB_ENUM_CA RPC_HUB_ENUM_CA;\r
+typedef struct RPC_HUB_GET_CA RPC_HUB_GET_CA;\r
+typedef struct RPC_HUB_DELETE_CA RPC_HUB_DELETE_CA;\r
+typedef struct RPC_CREATE_LINK RPC_CREATE_LINK;\r
+typedef struct RPC_ENUM_LINK_ITEM RPC_ENUM_LINK_ITEM;\r
+typedef struct RPC_ENUM_LINK RPC_ENUM_LINK;\r
+typedef struct RPC_LINK_STATUS RPC_LINK_STATUS;\r
+typedef struct RPC_LINK RPC_LINK;\r
+typedef struct RPC_ENUM_ACCESS_LIST RPC_ENUM_ACCESS_LIST;\r
+typedef struct RPC_ADD_ACCESS RPC_ADD_ACCESS;\r
+typedef struct RPC_DELETE_ACCESS RPC_DELETE_ACCESS;\r
+typedef struct RPC_SET_USER RPC_SET_USER;\r
+typedef struct RPC_ENUM_USER_ITEM RPC_ENUM_USER_ITEM;\r
+typedef struct RPC_ENUM_USER RPC_ENUM_USER;\r
+typedef struct RPC_SET_GROUP RPC_SET_GROUP;\r
+typedef struct RPC_ENUM_GROUP_ITEM RPC_ENUM_GROUP_ITEM;\r
+typedef struct RPC_ENUM_GROUP RPC_ENUM_GROUP;\r
+typedef struct RPC_DELETE_USER RPC_DELETE_USER;\r
+typedef struct RPC_ENUM_SESSION_ITEM RPC_ENUM_SESSION_ITEM;\r
+typedef struct RPC_DELETE_SESSION RPC_DELETE_SESSION;\r
+typedef struct RPC_ENUM_MAC_TABLE_ITEM RPC_ENUM_MAC_TABLE_ITEM;\r
+typedef struct RPC_ENUM_MAC_TABLE RPC_ENUM_MAC_TABLE;\r
+typedef struct RPC_ENUM_IP_TABLE_ITEM RPC_ENUM_IP_TABLE_ITEM;\r
+typedef struct RPC_ENUM_IP_TABLE RPC_ENUM_IP_TABLE;\r
+typedef struct RPC_DELETE_TABLE RPC_DELETE_TABLE;\r
+typedef struct RPC_KEEP RPC_KEEP;\r
+typedef struct RPC_ENUM_ETH_ITEM RPC_ENUM_ETH_ITEM;\r
+typedef struct RPC_ENUM_ETH RPC_ENUM_ETH;\r
+typedef struct RPC_LOCALBRIDGE RPC_LOCALBRIDGE;\r
+typedef struct RPC_ENUM_LOCALBRIDGE RPC_ENUM_LOCALBRIDGE;\r
+typedef struct RPC_BRIDGE_SUPPORT RPC_BRIDGE_SUPPORT;\r
+typedef struct RPC_CONFIG RPC_CONFIG;\r
+typedef struct RPC_ADMIN_OPTION RPC_ADMIN_OPTION;\r
+typedef struct RPC_L3SW RPC_L3SW;\r
+typedef struct RPC_L3IF RPC_L3IF;\r
+typedef struct RPC_L3TABLE RPC_L3TABLE;\r
+typedef struct RPC_ENUM_L3SW_ITEM RPC_ENUM_L3SW_ITEM;\r
+typedef struct RPC_ENUM_L3SW RPC_ENUM_L3SW;\r
+typedef struct RPC_ENUM_L3IF RPC_ENUM_L3IF;\r
+typedef struct RPC_ENUM_L3TABLE RPC_ENUM_L3TABLE;\r
+typedef struct RPC_CRL RPC_CRL;\r
+typedef struct RPC_ENUM_CRL_ITEM RPC_ENUM_CRL_ITEM;\r
+typedef struct RPC_ENUM_CRL RPC_ENUM_CRL;\r
+typedef struct RPC_INT RPC_INT;\r
+typedef struct RPC_AC_LIST RPC_AC_LIST;\r
+typedef struct RPC_ENUM_LOG_FILE_ITEM RPC_ENUM_LOG_FILE_ITEM;\r
+typedef struct RPC_ENUM_LOG_FILE RPC_ENUM_LOG_FILE;\r
+typedef struct RPC_READ_LOG_FILE RPC_READ_LOG_FILE;\r
+typedef struct DOWNLOAD_PROGRESS DOWNLOAD_PROGRESS;\r
+typedef struct RPC_RENAME_LINK RPC_RENAME_LINK;\r
+typedef struct RPC_ENUM_LICENSE_KEY RPC_ENUM_LICENSE_KEY;\r
+typedef struct RPC_ENUM_LICENSE_KEY_ITEM RPC_ENUM_LICENSE_KEY_ITEM;\r
+typedef struct RPC_LICENSE_STATUS RPC_LICENSE_STATUS;\r
+typedef struct RPC_ENUM_ETH_VLAN_ITEM RPC_ENUM_ETH_VLAN_ITEM;\r
+typedef struct RPC_ENUM_ETH_VLAN RPC_ENUM_ETH_VLAN;\r
+typedef struct RPC_MSG RPC_MSG;\r
+typedef struct RPC_WINVER RPC_WINVER;\r
+\r
+\r
+// ==============================================================\r
+//  NAT\r
+// ==============================================================\r
+\r
+typedef struct NAT NAT;\r
+typedef struct NAT_ADMIN NAT_ADMIN;\r
+typedef struct RPC_DUMMY RPC_DUMMY;\r
+typedef struct RPC_NAT_STATUS RPC_NAT_STATUS;\r
+typedef struct RPC_NAT_INFO RPC_NAT_INFO;\r
+typedef struct RPC_ENUM_NAT_ITEM RPC_ENUM_NAT_ITEM;\r
+typedef struct RPC_ENUM_NAT RPC_ENUM_NAT;\r
+typedef struct RPC_ENUM_DHCP_ITEM RPC_ENUM_DHCP_ITEM;\r
+typedef struct RPC_ENUM_DHCP RPC_ENUM_DHCP;\r
+\r
+\r
+// ==============================================================\r
+//  SecureNAT\r
+// ==============================================================\r
+\r
+typedef struct SNAT SNAT;\r
+\r
+\r
+// ==============================================================\r
+//  TcpIp\r
+// ==============================================================\r
+\r
+typedef struct MAC_HEADER MAC_HEADER;\r
+typedef struct ARPV4_HEADER ARPV4_HEADER;\r
+typedef struct IPV4_HEADER IPV4_HEADER;\r
+typedef struct TAGVLAN_HEADER TAGVLAN_HEADER;\r
+typedef struct UDP_HEADER UDP_HEADER;\r
+typedef struct UDPV4_PSEUDO_HEADER UDPV4_PSEUDO_HEADER;\r
+typedef struct TCPV4_PSEUDO_HEADER TCPV4_PSEUDO_HEADER;\r
+typedef struct TCP_HEADER TCP_HEADER;\r
+typedef struct ICMP_HEADER ICMP_HEADER;\r
+typedef struct ICMP_ECHO ICMP_ECHO;\r
+typedef struct DHCPV4_HEADER DHCPV4_HEADER;\r
+typedef struct DNSV4_HEADER DNSV4_HEADER;\r
+typedef struct BPDU_HEADER BPDU_HEADER;\r
+typedef struct LLC_HEADER LLC_HEADER;\r
+typedef struct PKT PKT;\r
+typedef struct IPV6_HEADER_PACKET_INFO IPV6_HEADER_PACKET_INFO;\r
+typedef struct IPV6_HEADER IPV6_HEADER;\r
+typedef struct IPV6_OPTION_HEADER IPV6_OPTION_HEADER;\r
+typedef struct IPV6_FRAGMENT_HEADER IPV6_FRAGMENT_HEADER;\r
+typedef struct IPV6_PSEUDO_HEADER IPV6_PSEUDO_HEADER;\r
+typedef struct ICMPV6_ROUTER_SOLICIATION_HEADER ICMPV6_ROUTER_SOLICIATION_HEADER;\r
+typedef struct ICMPV6_ROUTER_ADVERTISEMENT_HEADER ICMPV6_ROUTER_ADVERTISEMENT_HEADER;\r
+typedef struct ICMPV6_NEIGHBOR_SOLICIATION_HEADER ICMPV6_NEIGHBOR_SOLICIATION_HEADER;\r
+typedef struct ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER;\r
+typedef struct ICMPV6_OPTION_LIST ICMPV6_OPTION_LIST;\r
+typedef struct ICMPV6_OPTION ICMPV6_OPTION;\r
+typedef struct ICMPV6_OPTION_LINK_LAYER ICMPV6_OPTION_LINK_LAYER;\r
+typedef struct ICMPV6_OPTION_PREFIX ICMPV6_OPTION_PREFIX;\r
+typedef struct ICMPV6_OPTION_MTU ICMPV6_OPTION_MTU;\r
+typedef struct IPV6_HEADER_INFO IPV6_HEADER_INFO;\r
+typedef struct ICMPV6_HEADER_INFO ICMPV6_HEADER_INFO;\r
+\r
+\r
+// ==============================================================\r
+//  Console\r
+// ==============================================================\r
+\r
+typedef struct PARAM PARAM;\r
+typedef struct PARAM_VALUE PARAM_VALUE;\r
+typedef struct CONSOLE CONSOLE;\r
+typedef struct LOCAL_CONSOLE_PARAM LOCAL_CONSOLE_PARAM;\r
+typedef struct CMD CMD;\r
+typedef struct CMD_EVAL_MIN_MAX CMD_EVAL_MIN_MAX;\r
+\r
+\r
+// ==============================================================\r
+//  Command\r
+// ==============================================================\r
+\r
+typedef struct PS PS;\r
+typedef struct PC PC;\r
+typedef struct CT CT;\r
+typedef struct CTC CTC;\r
+typedef struct CTR CTR;\r
+typedef struct TTC TTC;\r
+typedef struct TTS TTS;\r
+typedef struct TT_RESULT TT_RESULT;\r
+typedef struct TTS_SOCK TTS_SOCK;\r
+typedef struct TTC_SOCK TTC_SOCK;\r
+typedef struct PT PT;\r
+\r
+// ==============================================================\r
+//  EtherLogger\r
+// ==============================================================\r
+\r
+typedef struct EL EL;\r
+typedef struct EL_DEVICE EL_DEVICE;\r
+typedef struct EL_LICENSE_STATUS EL_LICENSE_STATUS;\r
+typedef struct RPC_ADD_DEVICE RPC_ADD_DEVICE;\r
+typedef struct RPC_DELETE_DEVICE RPC_DELETE_DEVICE;\r
+typedef struct RPC_ENUM_DEVICE_ITEM RPC_ENUM_DEVICE_ITEM;\r
+typedef struct RPC_ENUM_DEVICE RPC_ENUM_DEVICE;\r
+typedef struct RPC_EL_LICENSE_STATUS RPC_EL_LICENSE_STATUS;\r
+\r
+\r
+// ==============================================================\r
+//  Database\r
+// ==============================================================\r
+\r
+typedef struct LICENSE_SYSTEM LICENSE_SYSTEM;\r
+typedef struct LICENSE_DATA LICENSE_DATA;\r
+typedef struct LICENSE LICENSE;\r
+typedef struct LICENSE_STATUS LICENSE_STATUS;\r
+\r
+\r
+\r
+\r
+#endif // CEDARTYPE_H\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Client.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Client.c
new file mode 100644 (file)
index 0000000..40c67ab
--- /dev/null
@@ -0,0 +1,9916 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Client.c\r
+// クライアントマネージャ\r
+\r
+#include "CedarPch.h"\r
+\r
+static CLIENT *client = NULL;\r
+static LISTENER *cn_listener = NULL;\r
+static LOCK *cn_listener_lock = NULL;\r
+static UINT64 cn_next_allow = 0;\r
+\r
+#ifdef OS_WIN32\r
+\r
+#endif // OS_WIN32\r
+\r
+// 注意: VPN Client サービスを実装するこのソースコードの一部には、\r
+// リエントラント (Reentrant: 再入可能) でないコードが含まれている。\r
+// もともと VPN Client のサービスと GUI (クライアント接続マネージャ) は一体\r
+// のものとして開発され、途中で分離された。その際に本来であれば TLS 等を用いて\r
+// スレッドセーフにしなければならない部分が、もとのままになってしまっている。\r
+// したがって、ごくまれに、GUI (クライアント接続マネージャ) や utvpncmd が\r
+// 複数個、1 個の VPN Client サービスに対して接続して、ほぼ同時に何らかの\r
+// 内部状態を変化させる処理を行ったとき、戻り値に不整合が生じる場合がある。\r
+\r
+// RPC_CLIENT_ENUM_ACCOUNT_ITEM を最終接続日時で逆ソート\r
+int CiCompareClientAccountEnumItemByLastConnectDateTime(void *p1, void *p2)\r
+{\r
+       RPC_CLIENT_ENUM_ACCOUNT_ITEM *a1, *a2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       a1 = *(RPC_CLIENT_ENUM_ACCOUNT_ITEM **)p1;\r
+       a2 = *(RPC_CLIENT_ENUM_ACCOUNT_ITEM **)p2;\r
+       if (a1 == NULL || a2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (a1->LastConnectDateTime > a2->LastConnectDateTime)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (a1->LastConnectDateTime < a2->LastConnectDateTime)\r
+       {\r
+               return 1;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// マシンが変更されていた場合はすべての仮想 LAN カードの MAC アドレスを乱数に設定する\r
+// このあたりは急いで実装したのでコードがあまり美しくない。\r
+// Q. なぜこのような処理が必要なのか?\r
+// A. Windows をインストールし、次に VPN Client をインストールして仮想 LAN カード\r
+//    を作成した状態を初期状態として HDD イメージをクローンし社内の複数の PC に\r
+//    インストールするような企業が存在する。\r
+//    そのような企業においてクローン後も仮想 LAN カードの MAC アドレスがすべて同一\r
+//    であれば障害の理由になる可能性があるためである。\r
+void CiChangeAllVLanMacAddressIfMachineChanged(CLIENT *c)\r
+{\r
+       UCHAR current_hash[SHA1_SIZE];\r
+       UCHAR current_hash_old[SHA1_SIZE];\r
+       UCHAR saved_hash[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       if (MsIsAdmin() == false)\r
+       {\r
+               return;\r
+       }\r
+#endif\r
+\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       CiGetCurrentMachineHash(current_hash);\r
+       CiGetCurrentMachineHashOld(current_hash_old);\r
+\r
+       if (CiReadLastMachineHash(saved_hash) == false)\r
+       {\r
+               CiWriteLastMachineHash(current_hash);\r
+               return;\r
+       }\r
+\r
+       if (Cmp(saved_hash, current_hash_old, SHA1_SIZE) == 0)\r
+       {\r
+               CiWriteLastMachineHash(current_hash);\r
+               return;\r
+       }\r
+\r
+       if (Cmp(saved_hash, current_hash, SHA1_SIZE) == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (CiWriteLastMachineHash(current_hash) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CiChangeAllVLanMacAddress(c);\r
+}\r
+\r
+// 現在のマシンハッシュを取得する (古い方式)\r
+// このあたりは急いで実装したのでコードがあまり美しくない。\r
+void CiGetCurrentMachineHashOld(void *data)\r
+{\r
+       char name[MAX_PATH];\r
+       char *product_id = NULL;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       // プロダクト ID\r
+       product_id = MsRegReadStr(REG_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductId");\r
+       if (product_id == NULL)\r
+       {\r
+               product_id = MsRegReadStr(REG_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProductId");\r
+       }\r
+\r
+       StrCpy(name, sizeof(name), product_id);\r
+\r
+       Free(product_id);\r
+\r
+#else  // OS_WIN32\r
+       GetMachineName(name, sizeof(name));\r
+#endif // OS_WIN32\r
+\r
+       Trim(name);\r
+       StrUpper(name);\r
+\r
+       Hash(data, name, StrLen(name), true);\r
+}\r
+\r
+// 現在のマシンハッシュを取得する\r
+void CiGetCurrentMachineHash(void *data)\r
+{\r
+       char name[MAX_PATH];\r
+       char *product_id = NULL;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetMachineName(name, sizeof(name));\r
+\r
+       Trim(name);\r
+       StrUpper(name);\r
+\r
+       Hash(data, name, StrLen(name), true);\r
+}\r
+\r
+// マシンハッシュを書き込む\r
+bool CiWriteLastMachineHash(void *data)\r
+{\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       if (MsRegWriteBinEx(REG_LOCAL_MACHINE, MS_REG_TCP_SETTING_KEY, "LastMachineHash_UTVPNClient", data, SHA1_SIZE, true) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+#else  // OS_WIN32\r
+       return false;\r
+#endif // OS_WIN32\r
+}\r
+\r
+// 前回のマシンハッシュを取得する\r
+bool CiReadLastMachineHash(void *data)\r
+{\r
+       BUF *b = NULL;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       b = MsRegReadBinEx(REG_LOCAL_MACHINE, MS_REG_TCP_SETTING_KEY, "LastMachineHash_UTVPNClient", true);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (b->Size == SHA1_SIZE)\r
+       {\r
+               Copy(data, b->Buf, b->Size);\r
+               FreeBuf(b);\r
+\r
+               return true;\r
+       }\r
+\r
+       FreeBuf(b);\r
+       return false;\r
+#else  // OS_WIN32\r
+       return false;\r
+#endif // OS_WIN32\r
+}\r
+\r
+// すべての仮想 LAN カードの MAC アドレスを乱数に設定する\r
+void CiChangeAllVLanMacAddress(CLIENT *c)\r
+{\r
+       RPC_CLIENT_ENUM_VLAN t;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CtEnumVLan(c, &t))\r
+       {\r
+               UINT i;\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       RPC_CLIENT_ENUM_VLAN_ITEM *e = t.Items[i];\r
+                       UCHAR mac[6];\r
+\r
+                       if (StrToMac(mac, e->MacAddress) && mac[1] == 0xAC)\r
+                       {\r
+                               char *name = e->DeviceName;\r
+                               RPC_CLIENT_SET_VLAN s;\r
+                               UCHAR mac[6];\r
+\r
+                               GenMacAddress(mac);\r
+\r
+                               Zero(&s, sizeof(s));\r
+                               StrCpy(s.DeviceName, sizeof(s.DeviceName), name);\r
+\r
+                               MacToStr(s.MacAddress, sizeof(s.MacAddress), mac);\r
+\r
+                               CtSetVLan(c, &s);\r
+                       }\r
+               }\r
+\r
+               CiFreeClientEnumVLan(&t);\r
+       }\r
+}\r
+\r
+// 通知サービスの準備が完了するまで待機する\r
+void CnWaitForCnServiceReady()\r
+{\r
+       UINT64 start_time = Tick64();\r
+\r
+       while ((start_time + (UINT64)CLIENT_WAIT_CN_READY_TIMEOUT) >= Tick64())\r
+       {\r
+               if (CnIsCnServiceReady())\r
+               {\r
+                       break;\r
+               }\r
+\r
+               SleepThread(100);\r
+       }\r
+}\r
+\r
+// 通知サービスの準備が完了しているかどうかチェックする\r
+// このあたりは急いで実装したのでコードがあまり美しくない。\r
+bool CnIsCnServiceReady()\r
+{\r
+       SOCK *s;\r
+       // 通知サービスの起動を確認する\r
+       if (CnCheckAlreadyExists(false) == false)\r
+       {\r
+               // 起動していない\r
+               return false;\r
+       }\r
+\r
+       // TCP ポートへの接続を試行する\r
+       s = ConnectEx("localhost", CLIENT_NOTIFY_PORT, 500);\r
+       if (s == NULL)\r
+       {\r
+               // TCP ポートを開いていない\r
+               return false;\r
+       }\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+\r
+       // 起動していた\r
+       return true;\r
+}\r
+\r
+// すでに通知サービスが動作しているかどうかチェックする\r
+bool CnCheckAlreadyExists(bool lock)\r
+{\r
+       bool ret = false;\r
+\r
+#ifdef OS_WIN32\r
+       ret = Win32CnCheckAlreadyExists(lock);\r
+#endif\r
+\r
+       return ret;\r
+}\r
+\r
+typedef struct CNC_STATUS_PRINTER_WINDOW_PARAM\r
+{\r
+       THREAD *Thread;\r
+       SESSION *Session;\r
+       SOCK *Sock;\r
+} CNC_STATUS_PRINTER_WINDOW_PARAM;\r
+\r
+typedef struct CNC_CONNECT_ERROR_DLG_THREAD_PARAM\r
+{\r
+       SESSION *Session;\r
+       SOCK *Sock;\r
+       bool HaltThread;\r
+       EVENT *Event;\r
+} CNC_CONNECT_ERROR_DLG_THREAD_PARAM;\r
+\r
+\r
+// Win32 における utvpnclient.exe のファイル名を取得する\r
+char *CiGetVpnClientExeFileName()\r
+{\r
+       if (Is64() == false)\r
+       {\r
+               return CLIENT_WIN32_EXE_FILENAME;\r
+       }\r
+       else\r
+       {\r
+               if (IsX64())\r
+               {\r
+                       return CLIENT_WIN32_EXE_FILENAME_X64;\r
+               }\r
+               else\r
+               {\r
+                       return CLIENT_WIN32_EXE_FILENAME_IA64;\r
+               }\r
+       }\r
+}\r
+\r
+// 証明書チェックダイアログクライアント強制停止用スレッド\r
+void CncCheckCertHaltThread(THREAD *thread, void *param)\r
+{\r
+       CNC_CONNECT_ERROR_DLG_THREAD_PARAM *dp = (CNC_CONNECT_ERROR_DLG_THREAD_PARAM *)param;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               if (dp->Session->Halt || dp->HaltThread)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               Wait(dp->Event, 100);\r
+       }\r
+\r
+       Disconnect(dp->Sock);\r
+}\r
+\r
+// 証明書チェックダイアログの表示\r
+void CncCheckCert(SESSION *session, UI_CHECKCERT *dlg)\r
+{\r
+       SOCK *s;\r
+       PACK *p;\r
+       CNC_CONNECT_ERROR_DLG_THREAD_PARAM *dp;\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (dlg == NULL || session == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = CncConnect();\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "function", "check_cert");\r
+       PackAddUniStr(p, "AccountName", dlg->AccountName);\r
+       PackAddStr(p, "ServerName", dlg->ServerName);\r
+       PackAddX(p, "x", dlg->x);\r
+       PackAddX(p, "parent_x", dlg->parent_x);\r
+       PackAddX(p, "old_x", dlg->old_x);\r
+       PackAddBool(p, "DiffWarning", dlg->DiffWarning);\r
+       PackAddBool(p, "Ok", dlg->Ok);\r
+       PackAddBool(p, "SaveServerCert", dlg->SaveServerCert);\r
+\r
+       SendPack(s, p);\r
+       FreePack(p);\r
+\r
+       dp = ZeroMalloc(sizeof(CNC_CONNECT_ERROR_DLG_THREAD_PARAM));\r
+       dp->Sock = s;\r
+       dp->Event = NewEvent();\r
+       dp->Session = session;\r
+\r
+       t = NewThread(CncCheckCertHaltThread, dp);\r
+\r
+       p = RecvPack(s);\r
+       if (p != NULL)\r
+       {\r
+               dlg->Ok = PackGetBool(p, "Ok");\r
+               dlg->DiffWarning = PackGetBool(p, "DiffWarning");\r
+               dlg->SaveServerCert = PackGetBool(p, "SaveServerCert");\r
+\r
+               FreePack(p);\r
+       }\r
+\r
+       dp->HaltThread = true;\r
+       Set(dp->Event);\r
+\r
+       WaitThread(t, INFINITE);\r
+\r
+       ReleaseEvent(dp->Event);\r
+       Free(dp);\r
+       ReleaseThread(t);\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+}\r
+\r
+// スマートカード署名ダイアログ\r
+bool CncSecureSignDlg(SECURE_SIGN *sign)\r
+{\r
+       SOCK *s;\r
+       PACK *p;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (sign == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s = CncConnect();\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "function", "secure_sign");\r
+       OutRpcSecureSign(p, sign);\r
+\r
+       SendPack(s, p);\r
+       FreePack(p);\r
+\r
+       p = RecvPack(s);\r
+       if (p != NULL)\r
+       {\r
+               ret = PackGetBool(p, "ret");\r
+\r
+               if (ret)\r
+               {\r
+                       FreeRpcSecureSign(sign);\r
+\r
+                       Zero(sign, sizeof(SECURE_SIGN));\r
+                       InRpcSecureSign(sign, p);\r
+               }\r
+\r
+               FreePack(p);\r
+       }\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// NIC 情報ダイアログの表示\r
+SOCK *CncNicInfo(UI_NICINFO *info)\r
+{\r
+       SOCK *s;\r
+       PACK *p;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (info == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       s = CncConnectEx(200);\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "function", "nicinfo");\r
+       PackAddStr(p, "NicName", info->NicName);\r
+       PackAddUniStr(p, "AccountName", info->AccountName);\r
+\r
+       SendPack(s, p);\r
+       FreePack(p);\r
+\r
+       return s;\r
+}\r
+\r
+// NIC 情報ダイアログを閉じる\r
+void CncNicInfoFree(SOCK *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+}\r
+\r
+// メッセージダイアログの表示\r
+SOCK *CncMsgDlg(UI_MSG_DLG *dlg)\r
+{\r
+       SOCK *s;\r
+       PACK *p;\r
+       bool ret = false;\r
+       char *utf;\r
+       // 引数チェック\r
+       if (dlg == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       s = CncConnectEx(200);\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "function", "msg_dialog");\r
+       PackAddStr(p, "ServerName", dlg->ServerName);\r
+       PackAddStr(p, "HubName", dlg->HubName);\r
+       utf = CopyUniToUtf(dlg->Msg);\r
+       PackAddData(p, "Msg", utf, StrLen(utf));\r
+       Free(utf);\r
+\r
+       SendPack(s, p);\r
+       FreePack(p);\r
+\r
+       return s;\r
+}\r
+\r
+// メッセージダイアログを閉じる\r
+void CndMsgDlgFree(SOCK *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+}\r
+\r
+// パスワード入力ダイアログクライアント強制停止用スレッド\r
+void CncPasswordDlgHaltThread(THREAD *thread, void *param)\r
+{\r
+       CNC_CONNECT_ERROR_DLG_THREAD_PARAM *dp = (CNC_CONNECT_ERROR_DLG_THREAD_PARAM *)param;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               if (dp->Session->Halt || dp->HaltThread)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               Wait(dp->Event, 100);\r
+       }\r
+\r
+       Disconnect(dp->Sock);\r
+}\r
+\r
+// パスワード入力ダイアログの表示\r
+bool CncPasswordDlg(SESSION *session, UI_PASSWORD_DLG *dlg)\r
+{\r
+       SOCK *s;\r
+       PACK *p;\r
+       CNC_CONNECT_ERROR_DLG_THREAD_PARAM *dp;\r
+       THREAD *t;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (dlg == NULL || session == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s = CncConnect();\r
+       if (s == NULL)\r
+       {\r
+               Wait(session->HaltEvent, session->RetryInterval);\r
+               return true;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "function", "password_dialog");\r
+       PackAddInt(p, "Type", dlg->Type);\r
+       PackAddStr(p, "Username", dlg->Username);\r
+       PackAddStr(p, "Password", dlg->Password);\r
+       PackAddStr(p, "ServerName", dlg->ServerName);\r
+       PackAddInt(p, "RetryIntervalSec", dlg->RetryIntervalSec);\r
+       PackAddBool(p, "ProxyServer", dlg->ProxyServer);\r
+       PackAddBool(p, "AdminMode", dlg->AdminMode);\r
+       PackAddBool(p, "ShowNoSavePassword", dlg->ShowNoSavePassword);\r
+       PackAddBool(p, "NoSavePassword", dlg->NoSavePassword);\r
+\r
+       SendPack(s, p);\r
+       FreePack(p);\r
+\r
+       dp = ZeroMalloc(sizeof(CNC_CONNECT_ERROR_DLG_THREAD_PARAM));\r
+       dp->Session = session;\r
+       dp->Sock = s;\r
+       dp->Event = NewEvent();\r
+\r
+       t = NewThread(CncConnectErrorDlgHaltThread, dp);\r
+\r
+       p = RecvPack(s);\r
+       if (p != NULL)\r
+       {\r
+               ret = PackGetBool(p, "ok");\r
+               dlg->NoSavePassword = PackGetBool(p, "NoSavePassword");\r
+               dlg->ProxyServer = PackGetBool(p, "ProxyServer");\r
+               dlg->Type = PackGetInt(p, "Type");\r
+               PackGetStr(p, "Username", dlg->Username, sizeof(dlg->Username));\r
+               PackGetStr(p, "Password", dlg->Password, sizeof(dlg->Password));\r
+\r
+               FreePack(p);\r
+       }\r
+\r
+       dp->HaltThread = true;\r
+       Set(dp->Event);\r
+\r
+       WaitThread(t, INFINITE);\r
+\r
+       ReleaseEvent(dp->Event);\r
+       Free(dp);\r
+       ReleaseThread(t);\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続エラーダイアログクライアント強制停止用スレッド\r
+void CncConnectErrorDlgHaltThread(THREAD *thread, void *param)\r
+{\r
+       CNC_CONNECT_ERROR_DLG_THREAD_PARAM *dp = (CNC_CONNECT_ERROR_DLG_THREAD_PARAM *)param;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               if (dp->Session->Halt || dp->HaltThread)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               Wait(dp->Event, 100);\r
+       }\r
+\r
+       Disconnect(dp->Sock);\r
+}\r
+\r
+// 接続エラーダイアログの表示\r
+bool CncConnectErrorDlg(SESSION *session, UI_CONNECTERROR_DLG *dlg)\r
+{\r
+       SOCK *s;\r
+       PACK *p;\r
+       CNC_CONNECT_ERROR_DLG_THREAD_PARAM *dp;\r
+       THREAD *t;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (dlg == NULL || session == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s = CncConnect();\r
+       if (s == NULL)\r
+       {\r
+               Wait(session->HaltEvent, session->RetryInterval);\r
+               return true;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "function", "connecterror_dialog");\r
+       PackAddUniStr(p, "AccountName", dlg->AccountName);\r
+       PackAddStr(p, "ServerName", dlg->ServerName);\r
+       PackAddInt(p, "Err", dlg->Err);\r
+       PackAddInt(p, "CurrentRetryCount", dlg->CurrentRetryCount);\r
+       PackAddInt(p, "RetryLimit", dlg->RetryLimit);\r
+       PackAddInt(p, "RetryIntervalSec", dlg->RetryIntervalSec);\r
+       PackAddBool(p, "HideWindow", dlg->HideWindow);\r
+\r
+       SendPack(s, p);\r
+       FreePack(p);\r
+\r
+       dp = ZeroMalloc(sizeof(CNC_CONNECT_ERROR_DLG_THREAD_PARAM));\r
+       dp->Session = session;\r
+       dp->Sock = s;\r
+       dp->Event = NewEvent();\r
+\r
+       t = NewThread(CncConnectErrorDlgHaltThread, dp);\r
+\r
+       p = RecvPack(s);\r
+       if (p != NULL)\r
+       {\r
+               ret = PackGetBool(p, "ok");\r
+               dlg->HideWindow = PackGetBool(p, "HideWindow");\r
+\r
+               FreePack(p);\r
+       }\r
+\r
+       dp->HaltThread = true;\r
+       Set(dp->Event);\r
+\r
+       WaitThread(t, INFINITE);\r
+\r
+       ReleaseEvent(dp->Event);\r
+       Free(dp);\r
+       ReleaseThread(t);\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// ステータス表示器クライアント用スレッド\r
+void CncStatusPrinterWindowThreadProc(THREAD *thread, void *param)\r
+{\r
+       CNC_STATUS_PRINTER_WINDOW_PARAM *pp;\r
+       SOCK *sock;\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pp = (CNC_STATUS_PRINTER_WINDOW_PARAM *)param;\r
+       sock = pp->Sock;\r
+       pp->Thread = thread;\r
+       AddRef(pp->Thread->ref);\r
+\r
+       NoticeThreadInit(thread);\r
+\r
+       p = RecvPack(sock);\r
+       if (p != NULL)\r
+       {\r
+               // セッションを停止する\r
+               StopSessionEx(pp->Session, true);\r
+\r
+               FreePack(p);\r
+       }\r
+}\r
+\r
+// ステータス表示器クライアントの作成\r
+SOCK *CncStatusPrinterWindowStart(SESSION *s)\r
+{\r
+       SOCK *sock;\r
+       PACK *p;\r
+       THREAD *t;\r
+       CNC_STATUS_PRINTER_WINDOW_PARAM *param;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       sock = CncConnect();\r
+\r
+       if (sock == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "function", "status_printer");\r
+       PackAddUniStr(p, "account_name", s->Account->ClientOption->AccountName);\r
+\r
+       if (SendPack(sock, p) == false)\r
+       {\r
+               FreePack(p);\r
+               ReleaseSock(sock);\r
+\r
+               return NULL;\r
+       }\r
+\r
+       FreePack(p);\r
+\r
+       param = ZeroMalloc(sizeof(CNC_STATUS_PRINTER_WINDOW_PARAM));\r
+       param->Sock = sock;\r
+       param->Session = s;\r
+\r
+       sock->Param = param;\r
+\r
+       t = NewThread(CncStatusPrinterWindowThreadProc, param);\r
+       WaitThreadInit(t);\r
+\r
+       ReleaseThread(t);\r
+\r
+       return sock;\r
+}\r
+\r
+// ステータス表示器に対して文字列を送信\r
+void CncStatusPrinterWindowPrint(SOCK *s, wchar_t *str)\r
+{\r
+       CNC_STATUS_PRINTER_WINDOW_PARAM *param;\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (s == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       param = (CNC_STATUS_PRINTER_WINDOW_PARAM *)s->Param;\r
+\r
+       p = NewPack();\r
+       PackAddUniStr(p, "string", str);\r
+       SendPack(s, p);\r
+       FreePack(p);\r
+}\r
+\r
+// ステータス表示器クライアントの停止\r
+void CncStatusPrinterWindowStop(SOCK *s)\r
+{\r
+       CNC_STATUS_PRINTER_WINDOW_PARAM *param;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       param = (CNC_STATUS_PRINTER_WINDOW_PARAM *)s->Param;\r
+\r
+       // クライアントソケット切断\r
+       Disconnect(s);\r
+\r
+       // スレッド終了\r
+       WaitThread(param->Thread, INFINITE);\r
+       ReleaseThread(param->Thread);\r
+\r
+       Free(param);\r
+       ReleaseSock(s);\r
+}\r
+\r
+// Windows Vista 用のドライバインストーラの起動\r
+bool CncExecDriverInstaller(char *arg)\r
+{\r
+       SOCK *s = CncConnect();\r
+       PACK *p;\r
+       bool ret;\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "function", "exec_driver_installer");\r
+       PackAddStr(p, "arg", arg);\r
+\r
+       SendPack(s, p);\r
+       FreePack(p);\r
+\r
+       p = RecvPack(s);\r
+       if (p == NULL)\r
+       {\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+               return false;\r
+       }\r
+\r
+       ret = PackGetBool(p, "ret");\r
+\r
+       FreePack(p);\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// 現在動作しているクライアント通知サービスにソケットを解放させる\r
+void CncReleaseSocket()\r
+{\r
+       SOCK *s = CncConnect();\r
+       PACK *p;\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "function", "release_socket");\r
+\r
+#ifdef OS_WIN32\r
+       PackAddInt(p, "pid", MsGetProcessId());\r
+#endif // OS_WIN32\r
+\r
+       SendPack(s, p);\r
+       FreePack(p);\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+}\r
+\r
+// クライアント通知サービスのセッション ID の取得\r
+UINT CncGetSessionId()\r
+{\r
+       SOCK *s = CncConnect();\r
+       PACK *p;\r
+       UINT ret;\r
+       if (s == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "function", "get_session_id");\r
+\r
+       SendPack(s, p);\r
+       FreePack(p);\r
+\r
+       p = RecvPack(s);\r
+       if (p == NULL)\r
+       {\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+               return INFINITE;\r
+       }\r
+\r
+       ret = PackGetInt(p, "session_id");\r
+\r
+       FreePack(p);\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// クライアント通知サービスのプロセスの終了\r
+void CncExit()\r
+{\r
+       SOCK *s = CncConnectEx(256);\r
+       PACK *p;\r
+       if (s != NULL)\r
+       {\r
+               p = NewPack();\r
+               PackAddStr(p, "function", "exit");\r
+\r
+               SendPack(s, p);\r
+\r
+               FreePack(p);\r
+\r
+               FreePack(RecvPack(s));\r
+\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       MsKillOtherInstanceEx("utvpnclient");\r
+#endif // OS_WIN32\r
+}\r
+\r
+// クライアント通知サービスへの接続\r
+SOCK *CncConnect()\r
+{\r
+       return CncConnectEx(0);\r
+}\r
+SOCK *CncConnectEx(UINT timeout)\r
+{\r
+       SOCK *s = ConnectEx("localhost", CLIENT_NOTIFY_PORT, timeout);\r
+\r
+       return s;\r
+}\r
+\r
+#ifdef OS_WIN32\r
+\r
+// 証明書チェックダイアログ用スレッド\r
+void Win32CnCheckCertThreadProc(THREAD *thread, void *param)\r
+{\r
+       UI_CHECKCERT *dlg;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       dlg = (UI_CHECKCERT *)param;\r
+\r
+       CheckCertDlg(dlg);\r
+       {\r
+               PACK *p = NewPack();\r
+\r
+               PackAddBool(p, "Ok", dlg->Ok);\r
+               PackAddBool(p, "SaveServerCert", dlg->SaveServerCert);\r
+\r
+               SendPack(dlg->Sock, p);\r
+               FreePack(p);\r
+\r
+               FreePack(RecvPack(dlg->Sock));\r
+       }\r
+\r
+       Disconnect(dlg->Sock);\r
+}\r
+\r
+// 証明書チェックダイアログ\r
+void Win32CnCheckCert(SOCK *s, PACK *p)\r
+{\r
+       UI_CHECKCERT dlg;\r
+       THREAD *t;\r
+       Zero(&dlg, sizeof(dlg));\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackGetUniStr(p, "AccountName", dlg.AccountName, sizeof(dlg.AccountName));\r
+       PackGetStr(p, "ServerName", dlg.ServerName, sizeof(dlg.ServerName));\r
+       dlg.x = PackGetX(p, "x");\r
+       dlg.parent_x = PackGetX(p, "parent_x");\r
+       dlg.old_x = PackGetX(p, "old_x");\r
+       dlg.DiffWarning = PackGetBool(p, "DiffWarning");\r
+       dlg.Ok = PackGetBool(p, "Ok");\r
+       dlg.SaveServerCert = PackGetBool(p, "SaveServerCert");\r
+       dlg.Sock = s;\r
+\r
+       t = NewThread(Win32CnCheckCertThreadProc, &dlg);\r
+\r
+       FreePack(RecvPack(s));\r
+\r
+       dlg.Halt = true;\r
+\r
+       WaitThread(t, INFINITE);\r
+       ReleaseThread(t);\r
+\r
+       FreeX(dlg.parent_x);\r
+       FreeX(dlg.old_x);\r
+       FreeX(dlg.x);\r
+}\r
+\r
+// メッセージ表示ダイアログスレッドプロシージャ\r
+void Win32CnMsgDlgThreadProc(THREAD *thread, void *param)\r
+{\r
+       UI_MSG_DLG *dlg = (UI_MSG_DLG *)param;\r
+       wchar_t tmp[MAX_SIZE];\r
+       char url[MAX_SIZE];\r
+       // 引数チェック\r
+       if (thread == NULL || dlg == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniFormat(tmp, sizeof(tmp), _UU("CM_MSG_TITLE"),\r
+               dlg->ServerName, dlg->HubName);\r
+\r
+       if (IsURLMsg(dlg->Msg, url, sizeof(url)) == false)\r
+       {\r
+               OnceMsgEx(NULL, tmp, dlg->Msg, true, 167, &dlg->Halt);\r
+       }\r
+       else\r
+       {\r
+               if (MsExecute(url, NULL) == false)\r
+               {\r
+                       OnceMsgEx(NULL, tmp, dlg->Msg, true, 167, &dlg->Halt);\r
+               }\r
+       }\r
+\r
+       Disconnect(dlg->Sock);\r
+}\r
+\r
+// NIC 情報ダイアログスレッドプロシージャ\r
+void Win32CnNicInfoThreadProc(THREAD *thread, void *param)\r
+{\r
+       UI_NICINFO *info = (UI_NICINFO *)param;\r
+       // 引数チェック\r
+       if (thread == NULL || info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsNt())\r
+       {\r
+               // Windows 9x 系ではダイアログを表示しない\r
+               NicInfo(info);\r
+       }\r
+\r
+       Disconnect(info->Sock);\r
+}\r
+\r
+// NIC 情報ダイアログ\r
+void Win32CnNicInfo(SOCK *s, PACK *p)\r
+{\r
+       UI_NICINFO info;\r
+       THREAD *t;\r
+       Zero(&info, sizeof(info));\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackGetStr(p, "NicName", info.NicName, sizeof(info.NicName));\r
+       PackGetUniStr(p, "AccountName", info.AccountName, sizeof(info.AccountName));\r
+\r
+       info.Sock = s;\r
+\r
+       t = NewThread(Win32CnNicInfoThreadProc, &info);\r
+\r
+       FreePack(RecvPack(s));\r
+\r
+       info.Halt = true;\r
+\r
+       WaitThread(t, INFINITE);\r
+       ReleaseThread(t);\r
+}\r
+\r
+// メッセージ表示ダイアログ\r
+void Win32CnMsgDlg(SOCK *s, PACK *p)\r
+{\r
+       UI_MSG_DLG dlg;\r
+       THREAD *t;\r
+       UINT utf_size;\r
+       char *utf;\r
+       wchar_t *msg;\r
+       Zero(&dlg, sizeof(dlg));\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackGetStr(p, "ServerName", dlg.ServerName, sizeof(dlg.ServerName));\r
+       PackGetStr(p, "HubName", dlg.HubName, sizeof(dlg.HubName));\r
+\r
+       utf_size = PackGetDataSize(p, "Msg");\r
+       utf = ZeroMalloc(utf_size + 8);\r
+\r
+       PackGetData(p, "Msg", utf);\r
+\r
+       msg = CopyUtfToUni(utf);\r
+       Free(utf);\r
+\r
+       dlg.Sock = s;\r
+       dlg.Msg = msg;\r
+\r
+       t = NewThread(Win32CnMsgDlgThreadProc, &dlg);\r
+\r
+       FreePack(RecvPack(s));\r
+\r
+       dlg.Halt = true;\r
+\r
+       WaitThread(t, INFINITE);\r
+       ReleaseThread(t);\r
+\r
+       Free(msg);\r
+}\r
+\r
+// パスワード入力ダイアログ用スレッド\r
+void Win32CnPasswordDlgThreadProc(THREAD *thread, void *param)\r
+{\r
+       UI_PASSWORD_DLG *dlg;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       dlg = (UI_PASSWORD_DLG *)param;\r
+\r
+       if (PasswordDlg(NULL, dlg))\r
+       {\r
+               PACK *p = NewPack();\r
+\r
+               PackAddBool(p, "ok", true);\r
+               PackAddStr(p, "Username", dlg->Username);\r
+               PackAddStr(p, "Password", dlg->Password);\r
+               PackAddInt(p, "Type", dlg->Type);\r
+               PackAddBool(p, "ProxyServer", dlg->ProxyServer);\r
+               PackAddBool(p, "NoSavePassword", dlg->NoSavePassword);\r
+\r
+               SendPack(dlg->Sock, p);\r
+               FreePack(p);\r
+\r
+               FreePack(RecvPack(dlg->Sock));\r
+       }\r
+\r
+       Disconnect(dlg->Sock);\r
+}\r
+\r
+// パスワード入力ダイアログ\r
+void Win32CnPasswordDlg(SOCK *s, PACK *p)\r
+{\r
+       UI_PASSWORD_DLG dlg;\r
+       THREAD *t = NULL;\r
+       Zero(&dlg, sizeof(dlg));\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       dlg.Type = PackGetInt(p, "Type");\r
+       PackGetStr(p, "Username", dlg.Username, sizeof(dlg.Username));\r
+       PackGetStr(p, "Password", dlg.Password, sizeof(dlg.Password));\r
+       PackGetStr(p, "ServerName", dlg.ServerName, sizeof(dlg.ServerName));\r
+       dlg.RetryIntervalSec = PackGetInt(p, "RetryIntervalSec");\r
+       dlg.ProxyServer = PackGetBool(p, "ProxyServer");\r
+       dlg.AdminMode = PackGetBool(p, "AdminMode");\r
+       dlg.ShowNoSavePassword = PackGetBool(p, "ShowNoSavePassword");\r
+       dlg.NoSavePassword = PackGetBool(p, "NoSavePassword");\r
+       dlg.CancelEvent = NewEvent();\r
+       dlg.Sock = s;\r
+\r
+       t = NewThread(Win32CnPasswordDlgThreadProc, &dlg);\r
+\r
+       FreePack(RecvPack(s));\r
+\r
+       Set(dlg.CancelEvent);\r
+\r
+       WaitThread(t, INFINITE);\r
+       ReleaseEvent(dlg.CancelEvent);\r
+       ReleaseThread(t);\r
+}\r
+\r
+// 接続エラーダイアログ用スレッド\r
+void Win32CnConnectErrorDlgThreadProc(THREAD *thread, void *param)\r
+{\r
+       UI_CONNECTERROR_DLG *dlg;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       dlg = (UI_CONNECTERROR_DLG *)param;\r
+\r
+       if (ConnectErrorDlg(dlg))\r
+       {\r
+               PACK *p = NewPack();\r
+\r
+               PackAddBool(p, "ok", true);\r
+               PackAddBool(p, "HideWindow", dlg->HideWindow);\r
+\r
+               SendPack(dlg->Sock, p);\r
+               FreePack(p);\r
+\r
+               FreePack(RecvPack(dlg->Sock));\r
+       }\r
+\r
+       Disconnect(dlg->Sock);\r
+}\r
+\r
+// 接続エラーダイアログ (Win32)\r
+void Win32CnConnectErrorDlg(SOCK *s, PACK *p)\r
+{\r
+       UI_CONNECTERROR_DLG dlg;\r
+       THREAD *t;\r
+       Zero(&dlg, sizeof(dlg));\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackGetUniStr(p, "AccountName", dlg.AccountName, sizeof(dlg.AccountName));\r
+       PackGetStr(p, "ServerName", dlg.ServerName, sizeof(dlg.ServerName));\r
+       dlg.Err = PackGetInt(p, "Err");\r
+       dlg.CurrentRetryCount = PackGetInt(p, "CurrentRetryCount");\r
+       dlg.RetryLimit = PackGetInt(p, "RetryLimit");\r
+       dlg.RetryIntervalSec = PackGetInt(p, "RetryIntervalSec");\r
+       dlg.HideWindow = PackGetBool(p, "HideWindow");\r
+       dlg.CancelEvent = NewEvent();\r
+       dlg.Sock = s;\r
+\r
+       t = NewThread(Win32CnConnectErrorDlgThreadProc, &dlg);\r
+\r
+       FreePack(RecvPack(s));\r
+\r
+       Set(dlg.CancelEvent);\r
+\r
+       WaitThread(t, INFINITE);\r
+       ReleaseEvent(dlg.CancelEvent);\r
+       ReleaseThread(t);\r
+}\r
+\r
+// ステータス表示器 (Win32)\r
+void Win32CnStatusPrinter(SOCK *s, PACK *p)\r
+{\r
+       STATUS_WINDOW *w;\r
+       wchar_t account_name[MAX_ACCOUNT_NAME_LEN + 1];\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackGetUniStr(p, "account_name", account_name, sizeof(account_name));\r
+\r
+       w = StatusPrinterWindowStart(s, account_name);\r
+\r
+       while (true)\r
+       {\r
+               PACK *p = RecvPack(s);\r
+\r
+               if (p == NULL)\r
+               {\r
+                       // 切断されたのでダイアログを終了する\r
+                       break;\r
+               }\r
+               else\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       // 文字列を書き換える\r
+                       PackGetUniStr(p, "string", tmp, sizeof(tmp));\r
+\r
+                       StatusPrinterWindowPrint(w, tmp);\r
+\r
+                       FreePack(p);\r
+               }\r
+       }\r
+\r
+       StatusPrinterWindowStop(w);\r
+}\r
+\r
+// ドライバインストーラの起動 (Windows Vista 用)\r
+void Win32CnExecDriverInstaller(SOCK *s, PACK *p)\r
+{\r
+       char arg[MAX_SIZE];\r
+       bool ret;\r
+       void *helper = NULL;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (PackGetStr(p, "arg", arg, sizeof(arg)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsVista())\r
+       {\r
+               helper = CmStartUacHelper();\r
+       }\r
+\r
+       ret = MsExecDriverInstaller(arg);\r
+\r
+       CmStopUacHelper(helper);\r
+\r
+       p = NewPack();\r
+       PackAddBool(p, "ret", ret);\r
+       SendPack(s, p);\r
+\r
+       FreePack(p);\r
+}\r
+\r
+#endif // OS_WIN32\r
+\r
+// ドライバインストーラの起動\r
+void CnExecDriverInstaller(SOCK *s, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       Win32CnExecDriverInstaller(s, p);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// 証明書確認ダイアログ\r
+void CnCheckCert(SOCK *s, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       Win32CnCheckCert(s, p);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// NIC 情報ダイアログ\r
+void CnNicInfo(SOCK *s, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       Win32CnNicInfo(s, p);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// メッセージ表示ダイアログ\r
+void CnMsgDlg(SOCK *s, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       Win32CnMsgDlg(s, p);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// パスワード入力ダイアログ\r
+void CnPasswordDlg(SOCK *s, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       Win32CnPasswordDlg(s, p);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// 接続エラーダイアログ\r
+void CnConnectErrorDlg(SOCK *s, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       Win32CnConnectErrorDlg(s, p);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// ステータス表示器\r
+void CnStatusPrinter(SOCK *s, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       Win32CnStatusPrinter(s, p);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// クライアント通知サービスリスナースレッド\r
+// このあたりは急いで実装したのでコードがあまり美しくない。\r
+void CnListenerProc(THREAD *thread, void *param)\r
+{\r
+       TCP_ACCEPTED_PARAM *data = (TCP_ACCEPTED_PARAM *)param;\r
+       SOCK *s;\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (data == NULL || thread == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = data->s;\r
+       AddRef(s->ref);\r
+       NoticeThreadInit(thread);\r
+\r
+       if (s->LocalIP.addr[0] == 127)\r
+       {\r
+               p = RecvPack(s);\r
+\r
+               if (p != NULL)\r
+               {\r
+                       char function[MAX_SIZE];\r
+\r
+                       if (PackGetStr(p, "function", function, sizeof(function)))\r
+                       {\r
+                               if (StrCmpi(function, "status_printer") == 0)\r
+                               {\r
+                                       CnStatusPrinter(s, p);\r
+                               }\r
+                               else if (StrCmpi(function, "connecterror_dialog") == 0)\r
+                               {\r
+                                       CnConnectErrorDlg(s, p);\r
+                               }\r
+                               else if (StrCmpi(function, "msg_dialog") == 0)\r
+                               {\r
+                                       CnMsgDlg(s, p);\r
+                               }\r
+                               else if (StrCmpi(function, "nicinfo") == 0)\r
+                               {\r
+                                       CnNicInfo(s, p);\r
+                               }\r
+                               else if (StrCmpi(function, "password_dialog") == 0)\r
+                               {\r
+                                       CnPasswordDlg(s, p);\r
+                               }\r
+                               else if (StrCmpi(function, "secure_sign") == 0)\r
+                               {\r
+                                       CnSecureSign(s, p);\r
+                               }\r
+                               else if (StrCmpi(function, "check_cert") == 0)\r
+                               {\r
+                                       CnCheckCert(s, p);\r
+                               }\r
+                               else if (StrCmpi(function, "exit") == 0)\r
+                               {\r
+#ifdef OS_WIN32\r
+                                       MsTerminateProcess();\r
+#else  // OS_WIN32\r
+                                       _exit(0);\r
+#endif // OS_WIN32\r
+                               }\r
+                               else if (StrCmpi(function, "get_session_id") == 0)\r
+                               {\r
+                                       PACK *p = NewPack();\r
+#ifdef OS_WIN32\r
+                                       PackAddInt(p, "session_id", MsGetCurrentTerminalSessionId());\r
+#endif // OS_WIN32\r
+                                       SendPack(s, p);\r
+                                       FreePack(p);\r
+                               }\r
+                               else if (StrCmpi(function, "exec_driver_installer") == 0)\r
+                               {\r
+                                       CnExecDriverInstaller(s, p);\r
+                               }\r
+                               else if (StrCmpi(function, "release_socket") == 0)\r
+                               {\r
+                                       // リスナーを停止する\r
+                                       CnReleaseSocket(s, p);\r
+                               }\r
+                       }\r
+\r
+                       FreePack(p);\r
+               }\r
+       }\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+}\r
+\r
+// Secure Sign を行う\r
+void CnSecureSign(SOCK *s, PACK *p)\r
+{\r
+       SECURE_SIGN sign;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&sign, sizeof(sign));\r
+       InRpcSecureSign(&sign, p);\r
+\r
+#ifdef OS_WIN32\r
+       // Win32: ダイアログを表示\r
+       ret = Win32CiSecureSign(&sign);\r
+#else  // OS_WIN32\r
+       // UNIX: 未実装\r
+       ret = false;\r
+#endif // OS_WIN32\r
+\r
+       p = NewPack();\r
+\r
+       OutRpcSecureSign(p, &sign);\r
+       FreeRpcSecureSign(&sign);\r
+\r
+       PackAddBool(p, "ret", ret);\r
+\r
+       SendPack(s, p);\r
+       FreePack(p);\r
+}\r
+\r
+// リスナーを停止する\r
+void CnReleaseSocket(SOCK *s, PACK *p)\r
+{\r
+       UINT pid = 0;\r
+       UINT current_pid = 0;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pid = PackGetInt(p, "pid");\r
+\r
+#ifdef OS_WIN32\r
+       current_pid = MsGetProcessId();\r
+#endif // OS_WIN32\r
+\r
+       if (current_pid == pid)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(cn_listener_lock);\r
+       {\r
+               if (cn_listener != NULL)\r
+               {\r
+                       if (cn_listener->Halt == false)\r
+                       {\r
+                               StopListener(cn_listener);\r
+\r
+                               cn_next_allow = Tick64() + (6 * 1000);\r
+                       }\r
+               }\r
+       }\r
+       Unlock(cn_listener_lock);\r
+}\r
+\r
+// クライアント通知サービスの開始\r
+void CnStart()\r
+{\r
+       CEDAR *cedar;\r
+       LISTENER *o;\r
+       UINT last_cursor_hash = 0;\r
+       bool last_session_active = false;\r
+\r
+       cn_next_allow = 0;\r
+       cn_listener_lock = NewLock();\r
+\r
+#ifdef OS_WIN32\r
+       MsSetShutdownParameters(0xff, 0x00000001);\r
+       InitWinUi(_UU("CN_TITLE"), _SS("DEFAULT_FONT"), _II("DEFAULT_FONT_SIZE"));\r
+#endif // OS_WIN32\r
+\r
+       cedar = NewCedar(NULL, NULL);\r
+\r
+       if (CnCheckAlreadyExists(true))\r
+       {\r
+               // すでに起動している\r
+               ReleaseCedar(cedar);\r
+#ifdef OS_WIN32\r
+               FreeWinUi();\r
+#endif // OS_WIN32\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       MsRegWriteInt(REG_CURRENT_USER, CM_REG_KEY,\r
+               "NotifyServerProcessId", MsGetProcessId());\r
+#endif // OS_WIN32\r
+\r
+BEGIN_LISTENER:\r
+       Lock(cn_listener_lock);\r
+       cn_listener = o = NewListenerEx(cedar, LISTENER_TCP, CLIENT_NOTIFY_PORT, CnListenerProc, NULL);\r
+       Unlock(cn_listener_lock);\r
+\r
+       while (true)\r
+       {\r
+               UINT current_cursor_hash = 0;\r
+               bool cursor_changed = false;\r
+\r
+#ifdef OS_WIN32\r
+               // 現在のカーソル位置を取得\r
+               current_cursor_hash = MsGetCursorPosHash();\r
+#endif // OS_WIN32\r
+\r
+               if (last_cursor_hash != current_cursor_hash)\r
+               {\r
+                       // カーソル位置をチェック\r
+                       cursor_changed = true;\r
+                       last_cursor_hash = current_cursor_hash;\r
+               }\r
+\r
+               Lock(cn_listener_lock);\r
+\r
+               // リスナーが開始した後一定間隔で状態をチェックする\r
+               if (cn_listener->Status == LISTENER_STATUS_TRYING || cn_listener->Halt)\r
+               {\r
+                       bool session_active = false;\r
+#ifdef OS_WIN32\r
+                       session_active = MsIsCurrentTerminalSessionActive();\r
+                       if (cursor_changed)\r
+                       {\r
+                               // カーソル位置が変化してもターミナルセッションがアクティブでない\r
+                               // 場合は変化していないものと見なす\r
+                               if (session_active == false)\r
+                               {\r
+                                       cursor_changed = false;\r
+                               }\r
+                       }\r
+                       if (last_session_active != session_active)\r
+                       {\r
+                               // カーソルが変化していなくてもターミナルセッション\r
+                               // 前回と比較してアクティブになった場合はカーソルが変化した\r
+                               // ものとみなす\r
+                               last_session_active = session_active;\r
+\r
+                               if (session_active)\r
+                               {\r
+                                       cursor_changed = true;\r
+                               }\r
+                       }\r
+#endif // OS_WIN32\r
+\r
+                       // ポートが開けない場合\r
+                       if (cn_next_allow <= Tick64())\r
+                       {\r
+                               if (cursor_changed || cn_listener->Halt)\r
+                               {\r
+                                       if (cursor_changed)\r
+                                       {\r
+                                               // マウスカーソルが移動しているので自分がポートを開く権利を持っている\r
+                                               // と判断できる。\r
+                                               // そこで、他のプロセスが持っているポートを強制的に奪う。\r
+                                               CncReleaseSocket();\r
+                                       }\r
+\r
+                                       if (cn_listener->Halt)\r
+                                       {\r
+                                               ReleaseListener(cn_listener);\r
+                                               cn_listener = NULL;\r
+\r
+                                               Unlock(cn_listener_lock);\r
+                                               goto BEGIN_LISTENER;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               Unlock(cn_listener_lock);\r
+\r
+               SleepThread(1000);\r
+       }\r
+}\r
+\r
+// バッファからアカウント情報を読み込む\r
+RPC_CLIENT_CREATE_ACCOUNT *CiCfgToAccount(BUF *b)\r
+{\r
+       RPC_CLIENT_CREATE_ACCOUNT *t;\r
+       FOLDER *f;\r
+       ACCOUNT *a;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       f = CfgBufTextToFolder(b);\r
+       if (f == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       a = CiLoadClientAccount(f);\r
+\r
+       CfgDeleteFolder(f);\r
+\r
+       if (a == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       DeleteLock(a->lock);\r
+\r
+       t = ZeroMalloc(sizeof(RPC_CLIENT_CREATE_ACCOUNT));\r
+       t->ClientOption = a->ClientOption;\r
+       t->ClientAuth = a->ClientAuth;\r
+       t->StartupAccount = a->StartupAccount;\r
+       t->CheckServerCert = a->CheckServerCert;\r
+       t->ServerCert = a->ServerCert;\r
+       Free(a);\r
+\r
+       return t;\r
+}\r
+\r
+// アカウント情報をバッファに書き出す\r
+BUF *CiAccountToCfg(RPC_CLIENT_CREATE_ACCOUNT *t)\r
+{\r
+       BUF *b;\r
+       FOLDER *root;\r
+       ACCOUNT a;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       root = CfgCreateFolder(NULL, TAG_ROOT);\r
+       Zero(&a, sizeof(a));\r
+       a.ClientOption = t->ClientOption;\r
+       a.ClientAuth = t->ClientAuth;\r
+       a.CheckServerCert = t->CheckServerCert;\r
+       a.ServerCert = t->ServerCert;\r
+       a.StartupAccount = t->StartupAccount;\r
+\r
+       CiWriteAccountData(root, &a);\r
+\r
+       b = CfgFolderToBufEx(root, true, true);\r
+       CfgDeleteFolder(root);\r
+\r
+       return b;\r
+}\r
+\r
+// RPC ディスパッチルーチン\r
+PACK *CiRpcDispatch(RPC *rpc, char *name, PACK *p)\r
+{\r
+       CLIENT *c = rpc->Param;\r
+       PACK *ret;\r
+       // 引数チェック\r
+       if (rpc == NULL || name == NULL || p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = NewPack();\r
+\r
+       if (StrCmpi(name, "GetClientVersion") == 0)\r
+       {\r
+               RPC_CLIENT_VERSION a;\r
+               if (CtGetClientVersion(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcClientVersion(ret, &a);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "GetCmSetting") == 0)\r
+       {\r
+               CM_SETTING a;\r
+               if (CtGetCmSetting(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcCmSetting(ret, &a);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "SetCmSetting") == 0)\r
+       {\r
+               CM_SETTING a;\r
+               Zero(&a, sizeof(a));\r
+               InRpcCmSetting(&a, p);\r
+               if (CtSetCmSetting(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "SetPassword") == 0)\r
+       {\r
+               RPC_CLIENT_PASSWORD a;\r
+               InRpcClientPassword(&a, p);\r
+               if (CtSetPassword(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "GetPasswordSetting") == 0)\r
+       {\r
+               RPC_CLIENT_PASSWORD_SETTING a;\r
+               if (CtGetPasswordSetting(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcClientPasswordSetting(ret, &a);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "EnumCa") == 0)\r
+       {\r
+               RPC_CLIENT_ENUM_CA a;\r
+               if (CtEnumCa(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcClientEnumCa(ret, &a);\r
+                       CiFreeClientEnumCa(&a);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "AddCa") == 0)\r
+       {\r
+               RPC_CERT a;\r
+               InRpcCert(&a, p);\r
+               if (CtAddCa(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               FreeX(a.x);\r
+       }\r
+       else if (StrCmpi(name, "DeleteCa") == 0)\r
+       {\r
+               RPC_CLIENT_DELETE_CA a;\r
+               InRpcClientDeleteCa(&a, p);\r
+               if (CtDeleteCa(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "GetCa") == 0)\r
+       {\r
+               RPC_GET_CA a;\r
+               InRpcGetCa(&a, p);\r
+               if (CtGetCa(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcGetCa(ret, &a);\r
+               }\r
+               CiFreeGetCa(&a);\r
+       }\r
+       else if (StrCmpi(name, "EnumSecure") == 0)\r
+       {\r
+               RPC_CLIENT_ENUM_SECURE a;\r
+               if (CtEnumSecure(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcClientEnumSecure(ret, &a);\r
+                       CiFreeClientEnumSecure(&a);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "UseSecure") == 0)\r
+       {\r
+               RPC_USE_SECURE a;\r
+               InRpcUseSecure(&a, p);\r
+               if (CtUseSecure(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "GetUseSecure") == 0)\r
+       {\r
+               RPC_USE_SECURE a;\r
+               Zero(&a, sizeof(a));\r
+               if (CtGetUseSecure(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcUseSecure(ret, &a);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "EnumObjectInSecure") == 0)\r
+       {\r
+               RPC_ENUM_OBJECT_IN_SECURE a;\r
+               if (CtEnumObjectInSecure(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcEnumObjectInSecure(ret, &a);\r
+                       CiFreeEnumObjectInSecure(&a);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "CreateVLan") == 0)\r
+       {\r
+               RPC_CLIENT_CREATE_VLAN a;\r
+               InRpcCreateVLan(&a, p);\r
+               if (CtCreateVLan(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "UpgradeVLan") == 0)\r
+       {\r
+               RPC_CLIENT_CREATE_VLAN a;\r
+               InRpcCreateVLan(&a, p);\r
+               if (CtUpgradeVLan(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "GetVLan") == 0)\r
+       {\r
+               RPC_CLIENT_GET_VLAN a;\r
+               InRpcClientGetVLan(&a, p);\r
+               if (CtGetVLan(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcClientGetVLan(ret, &a);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "SetVLan") == 0)\r
+       {\r
+               RPC_CLIENT_SET_VLAN a;\r
+               InRpcClientSetVLan(&a, p);\r
+               if (CtSetVLan(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "EnumVLan") == 0)\r
+       {\r
+               RPC_CLIENT_ENUM_VLAN a;\r
+               if (CtEnumVLan(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcClientEnumVLan(ret, &a);\r
+                       CiFreeClientEnumVLan(&a);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "DeleteVLan") == 0)\r
+       {\r
+               RPC_CLIENT_CREATE_VLAN a;\r
+               InRpcCreateVLan(&a, p);\r
+               if (CtDeleteVLan(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "EnableVLan") == 0)\r
+       {\r
+               RPC_CLIENT_CREATE_VLAN a;\r
+               InRpcCreateVLan(&a, p);\r
+               if (CtEnableVLan(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "DisableVLan") == 0)\r
+       {\r
+               RPC_CLIENT_CREATE_VLAN a;\r
+               InRpcCreateVLan(&a, p);\r
+               if (CtDisableVLan(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "CreateAccount") == 0)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT a;\r
+               InRpcClientCreateAccount(&a, p);\r
+               if (CtCreateAccount(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               CiFreeClientCreateAccount(&a);\r
+       }\r
+       else if (StrCmpi(name, "EnumAccount") == 0)\r
+       {\r
+               RPC_CLIENT_ENUM_ACCOUNT a;\r
+               if (CtEnumAccount(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcClientEnumAccount(ret, &a);\r
+                       CiFreeClientEnumAccount(&a);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "DeleteAccount") == 0)\r
+       {\r
+               RPC_CLIENT_DELETE_ACCOUNT a;\r
+               InRpcClientDeleteAccount(&a, p);\r
+               if (CtDeleteAccount(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "SetStartupAccount") == 0)\r
+       {\r
+               RPC_CLIENT_DELETE_ACCOUNT a;\r
+               InRpcClientDeleteAccount(&a, p);\r
+               if (CtSetStartupAccount(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "RemoveStartupAccount") == 0)\r
+       {\r
+               RPC_CLIENT_DELETE_ACCOUNT a;\r
+               InRpcClientDeleteAccount(&a, p);\r
+               if (CtRemoveStartupAccount(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "GetIssuer") == 0)\r
+       {\r
+               RPC_GET_ISSUER a;\r
+               InRpcGetIssuer(&a, p);\r
+               if (CtGetIssuer(c, &a))\r
+               {\r
+                       OutRpcGetIssuer(ret, &a);\r
+               }\r
+               else\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               CiFreeGetIssuer(&a);\r
+       }\r
+       else if (StrCmpi(name, "SetAccount") == 0)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT a;\r
+               InRpcClientCreateAccount(&a, p);\r
+               if (CtSetAccount(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               CiFreeClientCreateAccount(&a);\r
+       }\r
+       else if (StrCmpi(name, "GetAccount") == 0)\r
+       {\r
+               RPC_CLIENT_GET_ACCOUNT a;\r
+               InRpcClientGetAccount(&a, p);\r
+               if (CtGetAccount(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcClientGetAccount(ret, &a);\r
+               }\r
+               CiFreeClientGetAccount(&a);\r
+       }\r
+       else if (StrCmpi(name, "RenameAccount") == 0)\r
+       {\r
+               RPC_RENAME_ACCOUNT a;\r
+               InRpcRenameAccount(&a, p);\r
+               if (CtRenameAccount(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "SetClientConfig") == 0)\r
+       {\r
+               CLIENT_CONFIG a;\r
+               InRpcClientConfig(&a, p);\r
+               if (CtSetClientConfig(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "GetClientConfig") == 0)\r
+       {\r
+               CLIENT_CONFIG a;\r
+               if (CtGetClientConfig(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcClientConfig(ret, &a);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "Connect") == 0)\r
+       {\r
+               RPC_CLIENT_CONNECT a;\r
+               InRpcClientConnect(&a, p);\r
+               if (CtConnect(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "Disconnect") == 0)\r
+       {\r
+               RPC_CLIENT_CONNECT a;\r
+               InRpcClientConnect(&a, p);\r
+               if (CtDisconnect(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+       }\r
+       else if (StrCmpi(name, "GetAccountStatus") == 0)\r
+       {\r
+               RPC_CLIENT_GET_CONNECTION_STATUS a;\r
+               InRpcClientGetConnectionStatus(&a, p);\r
+               if (CtGetAccountStatus(c, &a) == false)\r
+               {\r
+                       RpcError(ret, c->Err);\r
+               }\r
+               else\r
+               {\r
+                       OutRpcClientGetConnectionStatus(ret, &a);\r
+               }\r
+               CiFreeClientGetConnectionStatus(&a);\r
+       }\r
+       else\r
+       {\r
+               FreePack(ret);\r
+               ret = NULL;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// CM_SETTING の設定\r
+UINT CcSetCmSetting(REMOTE_CLIENT *r, CM_SETTING *a)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err;\r
+       // 引数チェック\r
+       if (r == NULL || a == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcCmSetting(p, a);\r
+\r
+       ret = RpcCall(r->Rpc, "SetCmSetting", p);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               FreePack(ret);\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+               FreePack(ret);\r
+               return err;\r
+       }\r
+}\r
+\r
+// CM_SETTING の取得\r
+UINT CcGetCmSetting(REMOTE_CLIENT *r, CM_SETTING *a)\r
+{\r
+       PACK *ret;\r
+       // 引数チェック\r
+       if (r == NULL || a == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       ret = RpcCall(r->Rpc, "GetCmSetting", NULL);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               InRpcCmSetting(a, ret);\r
+               FreePack(ret);\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               UINT err = RpcGetError(ret);\r
+               FreePack(ret);\r
+               return err;\r
+       }\r
+}\r
+\r
+// クライアントバージョンの取得\r
+UINT CcGetClientVersion(REMOTE_CLIENT *r, RPC_CLIENT_VERSION *a)\r
+{\r
+       PACK *ret;\r
+       // 引数チェック\r
+       if (r == NULL || a == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       ret = RpcCall(r->Rpc, "GetClientVersion", NULL);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               InRpcClientVersion(a, ret);\r
+               FreePack(ret);\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               UINT err = RpcGetError(ret);\r
+               FreePack(ret);\r
+               return err;\r
+       }\r
+}\r
+\r
+// パスワードの設定\r
+UINT CcSetPassword(REMOTE_CLIENT *r, RPC_CLIENT_PASSWORD *pass)\r
+{\r
+       PACK *ret, *p;\r
+       // 引数チェック\r
+       if (r == NULL || pass == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+\r
+       OutRpcClientPassword(p, pass);\r
+\r
+       ret = RpcCall(r->Rpc, "SetPassword", p);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               FreePack(ret);\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               UINT err = RpcGetError(ret);\r
+               FreePack(ret);\r
+               return err;\r
+       }\r
+}\r
+\r
+// パスワード設定の取得\r
+UINT CcGetPasswordSetting(REMOTE_CLIENT *r, RPC_CLIENT_PASSWORD_SETTING *a)\r
+{\r
+       PACK *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || a == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       ret = RpcCall(r->Rpc, "GetPasswordSetting", NULL);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               InRpcClientPasswordSetting(a, ret);\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+       return err;\r
+}\r
+\r
+// CA の列挙\r
+UINT CcEnumCa(REMOTE_CLIENT *r, RPC_CLIENT_ENUM_CA *e)\r
+{\r
+       PACK *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || e == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       ret = RpcCall(r->Rpc, "EnumCa", NULL);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               InRpcClientEnumCa(e, ret);\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// CA の追加\r
+UINT CcAddCa(REMOTE_CLIENT *r, RPC_CERT *cert)\r
+{\r
+       PACK *p, *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || cert == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcCert(p, cert);\r
+\r
+       ret = RpcCall(r->Rpc, "AddCa", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// CA の削除\r
+UINT CcDeleteCa(REMOTE_CLIENT *r, RPC_CLIENT_DELETE_CA *c)\r
+{\r
+       PACK *p, *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || c == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcClientDeleteCa(p, c);\r
+\r
+       ret = RpcCall(r->Rpc, "DeleteCa", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// 署名者の取得\r
+UINT CcGetIssuer(REMOTE_CLIENT *r, RPC_GET_ISSUER *a)\r
+{\r
+       PACK *p, *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || a == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcGetIssuer(p, a);\r
+\r
+       ret = RpcCall(r->Rpc, "GetIssuer", p);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               if (a->x != NULL)\r
+               {\r
+                       FreeX(a->x);\r
+                       a->x = NULL;\r
+               }\r
+               InRpcGetIssuer(a, ret);\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// CA の取得\r
+UINT CcGetCa(REMOTE_CLIENT *r, RPC_GET_CA *get)\r
+{\r
+       PACK *p, *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || get == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcGetCa(p, get);\r
+\r
+       ret = RpcCall(r->Rpc, "GetCa", p);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               InRpcGetCa(get, ret);\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// セキュアデバイスの列挙\r
+UINT CcEnumSecure(REMOTE_CLIENT *r, RPC_CLIENT_ENUM_SECURE *e)\r
+{\r
+       PACK *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || e == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       ret = RpcCall(r->Rpc, "EnumSecure", NULL);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               InRpcClientEnumSecure(e, ret);\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// 使用しているセキュアデバイスの取得\r
+UINT CcGetUseSecure(REMOTE_CLIENT *r, RPC_USE_SECURE *sec)\r
+{\r
+       PACK *p, *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || sec == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+\r
+       ret = RpcCall(r->Rpc, "GetUseSecure", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+       else\r
+       {\r
+               InRpcUseSecure(sec, ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// セキュアデバイスの使用\r
+UINT CcUseSecure(REMOTE_CLIENT *r, RPC_USE_SECURE *sec)\r
+{\r
+       PACK *p, *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || sec == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcUseSecure(p, sec);\r
+\r
+       ret = RpcCall(r->Rpc, "UseSecure", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// セキュアデバイス内のオブジェクトの列挙\r
+UINT CcEnumObjectInSecure(REMOTE_CLIENT *r, RPC_ENUM_OBJECT_IN_SECURE *e)\r
+{\r
+       PACK *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || e == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       ret = RpcCall(r->Rpc, "EnumObjectInSecure", NULL);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               InRpcEnumObjectInSecure(e, ret);\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// VLAN の作成\r
+UINT CcCreateVLan(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_VLAN *create)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       char *s = NULL;\r
+       // 引数チェック\r
+       if (r == NULL || create == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcCreateVLan(p, create);\r
+\r
+#ifdef OS_WIN32\r
+       s = MsNoWarningSoundInit();\r
+#endif // OS_WIN32\r
+\r
+       ret = RpcCall(r->Rpc, "CreateVLan", p);\r
+\r
+#ifdef OS_WIN32\r
+       MsNoWarningSoundFree(s);\r
+#endif // OS_WIN32\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// VLAN のアップグレード\r
+UINT CcUpgradeVLan(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_VLAN *create)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       char *s = NULL;\r
+       // 引数チェック\r
+       if (r == NULL || create == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcCreateVLan(p, create);\r
+\r
+#ifdef OS_WIN32\r
+       s = MsNoWarningSoundInit();\r
+#endif // OS_WIN32\r
+\r
+       ret = RpcCall(r->Rpc, "UpgradeVLan", p);\r
+\r
+#ifdef OS_WIN32\r
+       MsNoWarningSoundFree(s);\r
+#endif // OS_WIN32\r
+\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// VLAN の取得\r
+UINT CcGetVLan(REMOTE_CLIENT *r, RPC_CLIENT_GET_VLAN *get)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || get == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcClientGetVLan(p, get);\r
+\r
+       ret = RpcCall(r->Rpc, "GetVLan", p);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               InRpcClientGetVLan(get, ret);\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// VLAN の設定\r
+UINT CcSetVLan(REMOTE_CLIENT *r, RPC_CLIENT_SET_VLAN *set)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || set == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcClientSetVLan(p, set);\r
+\r
+       ret = RpcCall(r->Rpc, "SetVLan", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// VLAN の列挙\r
+UINT CcEnumVLan(REMOTE_CLIENT *r, RPC_CLIENT_ENUM_VLAN *e)\r
+{\r
+       PACK *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || e == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       ret = RpcCall(r->Rpc, "EnumVLan", NULL);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               InRpcClientEnumVLan(e, ret);\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// VLAN の削除\r
+UINT CcDeleteVLan(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_VLAN *d)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || d == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcCreateVLan(p, d);\r
+\r
+       ret = RpcCall(r->Rpc, "DeleteVLan", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// VLAN の有効化\r
+UINT CcEnableVLan(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_VLAN *vlan)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || vlan == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcCreateVLan(p, vlan);\r
+\r
+       ret = RpcCall(r->Rpc, "EnableVLan", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// VLAN の無効化\r
+UINT CcDisableVLan(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_VLAN *vlan)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || vlan == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcCreateVLan(p, vlan);\r
+\r
+       ret = RpcCall(r->Rpc, "DisableVLan", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// アカウントの作成\r
+UINT CcCreateAccount(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_ACCOUNT *a)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || a == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcClientCreateAccount(p, a);\r
+\r
+       ret = RpcCall(r->Rpc, "CreateAccount", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// アカウントの列挙\r
+UINT CcEnumAccount(REMOTE_CLIENT *r, RPC_CLIENT_ENUM_ACCOUNT *e)\r
+{\r
+       PACK *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || e == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       ret = RpcCall(r->Rpc, "EnumAccount", NULL);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               UINT i;\r
+               InRpcClientEnumAccount(e, ret);\r
+\r
+               for (i = 0;i < e->NumItem;i++)\r
+               {\r
+                       RPC_CLIENT_ENUM_ACCOUNT_ITEM *t = e->Items[i];\r
+\r
+                       if (IsEmptyStr(t->HubName) && t->Port == 0)\r
+                       {\r
+                               UINT err2;\r
+                               RPC_CLIENT_GET_ACCOUNT a;\r
+\r
+                               // 古いバージョンの VPN Client では列挙時に HUB 名とポート番号\r
+                               // を取得できないので、別途取得する。\r
+                               Zero(&a, sizeof(a));\r
+                               UniStrCpy(a.AccountName, sizeof(a.AccountName), t->AccountName);\r
+                               err2 = CcGetAccount(r, &a);\r
+                               if (err2 == ERR_NO_ERROR)\r
+                               {\r
+                                       StrCpy(t->HubName, sizeof(t->HubName), a.ClientOption->HubName);\r
+                                       t->Port = a.ClientOption->Port;\r
+\r
+                                       CiFreeClientGetAccount(&a);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// スタートアップを解除する\r
+UINT CcRemoveStartupAccount(REMOTE_CLIENT *r, RPC_CLIENT_DELETE_ACCOUNT *a)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || a == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcClientDeleteAccount(p, a);\r
+\r
+       ret = RpcCall(r->Rpc, "RemoveStartupAccount", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// スタートアップにする\r
+UINT CcSetStartupAccount(REMOTE_CLIENT *r, RPC_CLIENT_DELETE_ACCOUNT *a)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || a == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcClientDeleteAccount(p, a);\r
+\r
+       ret = RpcCall(r->Rpc, "SetStartupAccount", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// アカウントの削除\r
+UINT CcDeleteAccount(REMOTE_CLIENT *r, RPC_CLIENT_DELETE_ACCOUNT *a)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || a == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcClientDeleteAccount(p, a);\r
+\r
+       ret = RpcCall(r->Rpc, "DeleteAccount", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// アカウントの設定\r
+UINT CcSetAccount(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_ACCOUNT *a)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || a == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcClientCreateAccount(p, a);\r
+\r
+       ret = RpcCall(r->Rpc, "SetAccount", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// アカウントの取得\r
+UINT CcGetAccount(REMOTE_CLIENT *r, RPC_CLIENT_GET_ACCOUNT *a)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || a == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcClientGetAccount(p, a);\r
+\r
+       ret = RpcCall(r->Rpc, "GetAccount", p);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               InRpcClientGetAccount(a, ret);\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// アカウント名の変更\r
+UINT CcRenameAccount(REMOTE_CLIENT *r, RPC_RENAME_ACCOUNT *rename)\r
+{\r
+       PACK *p, *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || rename == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcRenameAccount(p, rename);\r
+\r
+       ret = RpcCall(r->Rpc, "RenameAccount", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// クライアント設定の設定\r
+UINT CcSetClientConfig(REMOTE_CLIENT *r, CLIENT_CONFIG *o)\r
+{\r
+       PACK *p, *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || o == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcClientConfig(p, o);\r
+\r
+       ret = RpcCall(r->Rpc, "SetClientConfig", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// クライアント設定の取得\r
+UINT CcGetClientConfig(REMOTE_CLIENT *r, CLIENT_CONFIG *o)\r
+{\r
+       PACK *ret;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || o == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       ret = RpcCall(r->Rpc, "GetClientConfig", NULL);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               InRpcClientConfig(o, ret);\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// サービスをフォアグラウンドプロセスに設定する\r
+void CcSetServiceToForegroundProcess(REMOTE_CLIENT *r)\r
+{\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+       // 廃止\r
+/*\r
+       if (r->Rpc != NULL && r->Rpc->Sock != NULL && r->Rpc->Sock->RemoteIP.addr[0] == 127)\r
+       {\r
+               if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType) &&\r
+                       GET_KETA(GetOsInfo()->OsType, 100) >= 2)\r
+               {\r
+                       // Windows 2000 以降でのみこの操作は行う\r
+                       RPC_CLIENT_VERSION v;\r
+                       Zero(&v, sizeof(v));\r
+\r
+                       if (r->ClientBuildInt == 0)\r
+                       {\r
+                               CcGetClientVersion(r, &v);\r
+                               r->ClientBuildInt = v.ClientBuildInt;\r
+                               r->ProcessId = v.ProcessId;\r
+                       }\r
+                       if (r->ProcessId != 0 && r->ClientBuildInt <= 5080)\r
+                       {\r
+#ifdef OS_WIN32\r
+                               // サービスプロセスをフォアグラウンドウインドウに設定する\r
+                               AllowFGWindow(v.ProcessId);\r
+#endif // OS_WIN32\r
+                       }\r
+               }\r
+       }*/\r
+}\r
+\r
+// 接続\r
+UINT CcConnect(REMOTE_CLIENT *r, RPC_CLIENT_CONNECT *connect)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || connect == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       CcSetServiceToForegroundProcess(r);\r
+\r
+       p = NewPack();\r
+       OutRpcClientConnect(p, connect);\r
+\r
+       ret = RpcCall(r->Rpc, "Connect", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// 切断\r
+UINT CcDisconnect(REMOTE_CLIENT *r, RPC_CLIENT_CONNECT *connect)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || connect == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       CcSetServiceToForegroundProcess(r);\r
+\r
+       p = NewPack();\r
+       OutRpcClientConnect(p, connect);\r
+\r
+       ret = RpcCall(r->Rpc, "Disconnect", p);\r
+\r
+       if (RpcIsOk(ret) == false)\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+// アカウント状況の取得\r
+UINT CcGetAccountStatus(REMOTE_CLIENT *r, RPC_CLIENT_GET_CONNECTION_STATUS *st)\r
+{\r
+       PACK *ret, *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || st == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcClientGetConnectionStatus(p, st);\r
+\r
+       ret = RpcCall(r->Rpc, "GetAccountStatus", p);\r
+\r
+       if (RpcIsOk(ret))\r
+       {\r
+               InRpcClientGetConnectionStatus(st, ret);\r
+       }\r
+       else\r
+       {\r
+               err = RpcGetError(ret);\r
+       }\r
+\r
+       FreePack(ret);\r
+\r
+       return err;\r
+}\r
+\r
+\r
+// クライアントサービスが接続マネージャに対して通知を送信する\r
+void CiNotify(CLIENT *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // すべての通知イベントを起動する\r
+       LockList(c->NotifyCancelList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(c->NotifyCancelList);i++)\r
+               {\r
+                       CANCEL *cancel = LIST_DATA(c->NotifyCancelList, i);\r
+                       Cancel(cancel);\r
+               }\r
+       }\r
+       UnlockList(c->NotifyCancelList);\r
+}\r
+\r
+// RPC_CLIENT_ENUM_ACCOUNT の解放\r
+void CiFreeClientEnumAccount(RPC_CLIENT_ENUM_ACCOUNT *a)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < a->NumItem;i++)\r
+       {\r
+               RPC_CLIENT_ENUM_ACCOUNT_ITEM *e = a->Items[i];\r
+               Free(e);\r
+       }\r
+       Free(a->Items);\r
+}\r
+\r
+\r
+// 一定時間ごとに設定ファイルを保存するスレッド\r
+void CiSaverThread(THREAD *t, void *param)\r
+{\r
+       CLIENT *c = (CLIENT *)param;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       NoticeThreadInit(t);\r
+\r
+       // 一定時間待つ\r
+       while (c->Halt == false)\r
+       {\r
+               Wait(c->SaverHalter, CLIENT_SAVER_INTERVAL);\r
+\r
+               // 保存\r
+               CiSaveConfigurationFile(c);\r
+       }\r
+}\r
+\r
+// 設定データ自動保存の初期化\r
+void CiInitSaver(CLIENT *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->SaverHalter = NewEvent();\r
+\r
+       c->SaverThread = NewThread(CiSaverThread, c);\r
+       WaitThreadInit(c->SaverThread);\r
+}\r
+\r
+// 設定データ自動保存の解放\r
+void CiFreeSaver(CLIENT *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->Halt = true;\r
+       Set(c->SaverHalter);\r
+       WaitThread(c->SaverThread, INFINITE);\r
+       ReleaseThread(c->SaverThread);\r
+\r
+       ReleaseEvent(c->SaverHalter);\r
+}\r
+\r
+// CM_SETTING\r
+void InRpcCmSetting(CM_SETTING *c, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(c, sizeof(CM_SETTING));\r
+       c->EasyMode = PackGetBool(p, "EasyMode");\r
+       c->LockMode = PackGetBool(p, "LockMode");\r
+       PackGetData2(p, "HashedPassword", c->HashedPassword, sizeof(c->HashedPassword));\r
+}\r
+void OutRpcCmSetting(PACK *p, CM_SETTING *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddBool(p, "EasyMode", c->EasyMode);\r
+       PackAddBool(p, "LockMode", c->LockMode);\r
+       PackAddData(p, "HashedPassword", c->HashedPassword, sizeof(c->HashedPassword));\r
+}\r
+\r
+// CLIENT_CONFIG\r
+void InRpcClientConfig(CLIENT_CONFIG *c, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(c, sizeof(CLIENT_CONFIG));\r
+       c->UseKeepConnect = PackGetInt(p, "UseKeepConnect") == 0 ? false : true;\r
+       c->KeepConnectPort = PackGetInt(p, "KeepConnectPort");\r
+       c->KeepConnectProtocol = PackGetInt(p, "KeepConnectProtocol");\r
+       c->KeepConnectInterval = PackGetInt(p, "KeepConnectInterval");\r
+       c->AllowRemoteConfig = PackGetInt(p, "AllowRemoteConfig") == 0 ? false : true;\r
+       PackGetStr(p, "KeepConnectHost", c->KeepConnectHost, sizeof(c->KeepConnectHost));\r
+}\r
+void OutRpcClientConfig(PACK *p, CLIENT_CONFIG *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "UseKeepConnect", c->UseKeepConnect);\r
+       PackAddInt(p, "KeepConnectPort", c->KeepConnectPort);\r
+       PackAddInt(p, "KeepConnectProtocol", c->KeepConnectProtocol);\r
+       PackAddInt(p, "KeepConnectInterval", c->KeepConnectInterval);\r
+       PackAddInt(p, "AllowRemoteConfig", c->AllowRemoteConfig);\r
+       PackAddStr(p, "KeepConnectHost", c->KeepConnectHost);\r
+}\r
+\r
+// RPC_CLIENT_VERSION\r
+void InRpcClientVersion(RPC_CLIENT_VERSION *ver, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (ver == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(ver, sizeof(RPC_CLIENT_VERSION));\r
+       PackGetStr(p, "ClientProductName", ver->ClientProductName, sizeof(ver->ClientProductName));\r
+       PackGetStr(p, "ClientVersionString", ver->ClientVersionString, sizeof(ver->ClientVersionString));\r
+       PackGetStr(p, "ClientBuildInfoString", ver->ClientBuildInfoString, sizeof(ver->ClientBuildInfoString));\r
+       ver->ClientVerInt = PackGetInt(p, "ClientVerInt");\r
+       ver->ClientBuildInt = PackGetInt(p, "ClientBuildInt");\r
+       ver->ProcessId = PackGetInt(p, "ProcessId");\r
+       ver->OsType = PackGetInt(p, "OsType");\r
+}\r
+void OutRpcClientVersion(PACK *p, RPC_CLIENT_VERSION *ver)\r
+{\r
+       // 引数チェック\r
+       if (ver == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "ClientProductName", ver->ClientProductName);\r
+       PackAddStr(p, "ClientVersionString", ver->ClientVersionString);\r
+       PackAddStr(p, "ClientBuildInfoString", ver->ClientBuildInfoString);\r
+       PackAddInt(p, "ClientVerInt", ver->ClientVerInt);\r
+       PackAddInt(p, "ClientBuildInt", ver->ClientBuildInt);\r
+       PackAddInt(p, "ProcessId", ver->ProcessId);\r
+       PackAddInt(p, "OsType", ver->OsType);\r
+}\r
+\r
+// RPC_CLIENT_PASSWORD\r
+void InRpcClientPassword(RPC_CLIENT_PASSWORD *pw, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (pw == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(pw, sizeof(RPC_CLIENT_PASSWORD));\r
+       PackGetStr(p, "Password", pw->Password, sizeof(pw->Password));\r
+       pw->PasswordRemoteOnly = PackGetInt(p, "PasswordRemoteOnly");\r
+}\r
+void OutRpcClientPassword(PACK *p, RPC_CLIENT_PASSWORD *pw)\r
+{\r
+       // 引数チェック\r
+       if (pw == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "Password", pw->Password);\r
+       PackAddInt(p, "PasswordRemoteOnly", pw->PasswordRemoteOnly);\r
+}\r
+\r
+// RPC_CLIENT_PASSWORD_SETTING\r
+void InRpcClientPasswordSetting(RPC_CLIENT_PASSWORD_SETTING *a, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(a, sizeof(RPC_CLIENT_PASSWORD_SETTING));\r
+\r
+       a->IsPasswordPresented = PackGetInt(p, "IsPasswordPresented") == 0 ? false : true;\r
+       a->PasswordRemoteOnly = PackGetInt(p, "PasswordRemoteOnly") == 0 ? false : true;\r
+}\r
+void OutRpcClientPasswordSetting(PACK *p, RPC_CLIENT_PASSWORD_SETTING *a)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "IsPasswordPresented", a->IsPasswordPresented);\r
+       PackAddInt(p, "PasswordRemoteOnly", a->PasswordRemoteOnly);\r
+}\r
+\r
+// RPC_CLIENT_ENUM_CA\r
+void InRpcClientEnumCa(RPC_CLIENT_ENUM_CA *e, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(e, sizeof(RPC_CLIENT_ENUM_CA));\r
+       e->NumItem = PackGetNum(p, "NumItem");\r
+\r
+       e->Items = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_CA_ITEM *) * e->NumItem);\r
+       for (i = 0;i < e->NumItem;i++)\r
+       {\r
+               RPC_CLIENT_ENUM_CA_ITEM *item = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_CA_ITEM));\r
+               e->Items[i] = item;\r
+\r
+               item->Key = PackGetIntEx(p, "Key", i);\r
+               PackGetUniStrEx(p, "SubjectName", item->SubjectName, sizeof(item->SubjectName), i);\r
+               PackGetUniStrEx(p, "IssuerName", item->IssuerName, sizeof(item->IssuerName), i);\r
+               item->Expires = PackGetInt64Ex(p, "Expires", i);\r
+       }\r
+}\r
+void OutRpcClientEnumCa(PACK *p, RPC_CLIENT_ENUM_CA *e)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddNum(p, "NumItem", e->NumItem);\r
+\r
+       for (i = 0;i < e->NumItem;i++)\r
+       {\r
+               RPC_CLIENT_ENUM_CA_ITEM *item = e->Items[i];\r
+               PackAddIntEx(p, "Key", item->Key, i, e->NumItem);\r
+               PackAddUniStrEx(p, "SubjectName", item->SubjectName, i, e->NumItem);\r
+               PackAddUniStrEx(p, "IssuerName", item->IssuerName, i, e->NumItem);\r
+               PackAddInt64Ex(p, "Expires", item->Expires, i, e->NumItem);\r
+       }\r
+}\r
+\r
+// RPC_GET_ISSUER\r
+void InRpcGetIssuer(RPC_GET_ISSUER *c, PACK *p)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(c, sizeof(RPC_GET_ISSUER));\r
+       b = PackGetBuf(p, "x");\r
+       if (b != NULL)\r
+       {\r
+               if (c->x != NULL)\r
+               {\r
+                       FreeX(c->x);\r
+               }\r
+               c->x = BufToX(b, false);\r
+               FreeBuf(b);\r
+       }\r
+\r
+       b = PackGetBuf(p, "issuer_x");\r
+       if (b != NULL)\r
+       {\r
+               c->issuer_x = BufToX(b, false);\r
+               FreeBuf(b);\r
+       }\r
+}\r
+void OutRpcGetIssuer(PACK *p, RPC_GET_ISSUER *c)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (p == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (c->x != NULL)\r
+       {\r
+               b = XToBuf(c->x, false);\r
+\r
+               PackAddBuf(p, "x", b);\r
+               FreeBuf(b);\r
+       }\r
+\r
+       if (c->issuer_x != NULL)\r
+       {\r
+               b = XToBuf(c->issuer_x, false);\r
+\r
+               PackAddBuf(p, "issuer_x", b);\r
+               FreeBuf(b);\r
+       }\r
+}\r
+\r
+// TRAFFIC_EX\r
+void InRpcTrafficEx(TRAFFIC *t, PACK *p, UINT i)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(TRAFFIC));\r
+       t->Recv.BroadcastBytes = PackGetInt64Ex(p, "Ex.Recv.BroadcastBytes", i);\r
+       t->Recv.BroadcastCount = PackGetInt64Ex(p, "Ex.Recv.BroadcastCount", i);\r
+       t->Recv.UnicastBytes = PackGetInt64Ex(p, "Ex.Recv.UnicastBytes", i);\r
+       t->Recv.UnicastCount = PackGetInt64Ex(p, "Ex.Recv.UnicastCount", i);\r
+       t->Send.BroadcastBytes = PackGetInt64Ex(p, "Ex.Send.BroadcastBytes", i);\r
+       t->Send.BroadcastCount = PackGetInt64Ex(p, "Ex.Send.BroadcastCount", i);\r
+       t->Send.UnicastBytes = PackGetInt64Ex(p, "Ex.Send.UnicastBytes", i);\r
+       t->Send.UnicastCount = PackGetInt64Ex(p, "Ex.Send.UnicastCount", i);\r
+}\r
+void OutRpcTrafficEx(TRAFFIC *t, PACK *p, UINT i, UINT num)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt64Ex(p, "Ex.Recv.BroadcastBytes", t->Recv.BroadcastBytes, i, num);\r
+       PackAddInt64Ex(p, "Ex.Recv.BroadcastCount", t->Recv.BroadcastCount, i, num);\r
+       PackAddInt64Ex(p, "Ex.Recv.UnicastBytes", t->Recv.UnicastBytes, i, num);\r
+       PackAddInt64Ex(p, "Ex.Recv.UnicastCount", t->Recv.UnicastCount, i, num);\r
+       PackAddInt64Ex(p, "Ex.Send.BroadcastBytes", t->Send.BroadcastBytes, i, num);\r
+       PackAddInt64Ex(p, "Ex.Send.BroadcastCount", t->Send.BroadcastCount, i, num);\r
+       PackAddInt64Ex(p, "Ex.Send.UnicastBytes", t->Send.UnicastBytes, i, num);\r
+       PackAddInt64Ex(p, "Ex.Send.UnicastCount", t->Send.UnicastCount, i, num);\r
+}\r
+\r
+// TRAFFIC\r
+void InRpcTraffic(TRAFFIC *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(TRAFFIC));\r
+       t->Recv.BroadcastBytes = PackGetInt64(p, "Recv.BroadcastBytes");\r
+       t->Recv.BroadcastCount = PackGetInt64(p, "Recv.BroadcastCount");\r
+       t->Recv.UnicastBytes = PackGetInt64(p, "Recv.UnicastBytes");\r
+       t->Recv.UnicastCount = PackGetInt64(p, "Recv.UnicastCount");\r
+       t->Send.BroadcastBytes = PackGetInt64(p, "Send.BroadcastBytes");\r
+       t->Send.BroadcastCount = PackGetInt64(p, "Send.BroadcastCount");\r
+       t->Send.UnicastBytes = PackGetInt64(p, "Send.UnicastBytes");\r
+       t->Send.UnicastCount = PackGetInt64(p, "Send.UnicastCount");\r
+}\r
+void OutRpcTraffic(PACK *p, TRAFFIC *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt64(p, "Recv.BroadcastBytes", t->Recv.BroadcastBytes);\r
+       PackAddInt64(p, "Recv.BroadcastCount", t->Recv.BroadcastCount);\r
+       PackAddInt64(p, "Recv.UnicastBytes", t->Recv.UnicastBytes);\r
+       PackAddInt64(p, "Recv.UnicastCount", t->Recv.UnicastCount);\r
+       PackAddInt64(p, "Send.BroadcastBytes", t->Send.BroadcastBytes);\r
+       PackAddInt64(p, "Send.BroadcastCount", t->Send.BroadcastCount);\r
+       PackAddInt64(p, "Send.UnicastBytes", t->Send.UnicastBytes);\r
+       PackAddInt64(p, "Send.UnicastCount", t->Send.UnicastCount);\r
+}\r
+\r
+// RPC_CERT\r
+void InRpcCert(RPC_CERT *c, PACK *p)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(c, sizeof(RPC_CERT));\r
+       b = PackGetBuf(p, "x");\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->x = BufToX(b, false);\r
+       FreeBuf(b);\r
+}\r
+void OutRpcCert(PACK *p, RPC_CERT *c)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (p == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (c->x != NULL)\r
+       {\r
+               b = XToBuf(c->x, false);\r
+\r
+               PackAddBuf(p, "x", b);\r
+\r
+               FreeBuf(b);\r
+       }\r
+}\r
+\r
+// RPC_CLIENT_DELETE_CA\r
+void InRpcClientDeleteCa(RPC_CLIENT_DELETE_CA *c, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(c, sizeof(RPC_CLIENT_DELETE_CA));\r
+       c->Key = PackGetInt(p, "Key");\r
+}\r
+void OutRpcClientDeleteCa(PACK *p, RPC_CLIENT_DELETE_CA *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "Key", c->Key);\r
+}\r
+\r
+// RPC_GET_CA\r
+void InRpcGetCa(RPC_GET_CA *c, PACK *p)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(c, sizeof(RPC_GET_CA));\r
+\r
+       c->Key = PackGetInt(p, "Key");\r
+\r
+       b = PackGetBuf(p, "x");\r
+       if (b != NULL)\r
+       {\r
+               c->x = BufToX(b, false);\r
+\r
+               FreeBuf(b);\r
+       }\r
+}\r
+void OutRpcGetCa(PACK *p, RPC_GET_CA *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "Key", c->Key);\r
+\r
+       if (c->x != NULL)\r
+       {\r
+               BUF *b = XToBuf(c->x, false);\r
+\r
+               PackAddBuf(p, "x", b);\r
+\r
+               FreeBuf(b);\r
+       }\r
+}\r
+\r
+// RPC_CLIENT_ENUM_SECURE\r
+void InRpcClientEnumSecure(RPC_CLIENT_ENUM_SECURE *e, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(e, sizeof(RPC_CLIENT_ENUM_SECURE));\r
+\r
+       e->NumItem = PackGetNum(p, "NumItem");\r
+       e->Items = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_SECURE_ITEM *) * e->NumItem);\r
+       for (i = 0;i < e->NumItem;i++)\r
+       {\r
+               RPC_CLIENT_ENUM_SECURE_ITEM *item = e->Items[i] = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_SECURE_ITEM));\r
+\r
+               item->DeviceId = PackGetIntEx(p, "DeviceId", i);\r
+               item->Type = PackGetIntEx(p, "Type", i);\r
+               PackGetStrEx(p, "DeviceName", item->DeviceName, sizeof(item->DeviceName), i);\r
+               PackGetStrEx(p, "Manufacturer", item->Manufacturer, sizeof(item->Manufacturer), i);\r
+       }\r
+}\r
+void OutRpcClientEnumSecure(PACK *p, RPC_CLIENT_ENUM_SECURE *e)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddNum(p, "NumItem", e->NumItem);\r
+\r
+       for (i = 0;i < e->NumItem;i++)\r
+       {\r
+               RPC_CLIENT_ENUM_SECURE_ITEM *item = e->Items[i];\r
+\r
+               PackAddIntEx(p, "DeviceId", item->DeviceId, i, e->NumItem);\r
+               PackAddIntEx(p, "Type", item->Type, i, e->NumItem);\r
+               PackAddStrEx(p, "DeviceName", item->DeviceName, i, e->NumItem);\r
+               PackAddStrEx(p, "Manufacturer", item->Manufacturer, i, e->NumItem);\r
+       }\r
+}\r
+\r
+// RPC_USE_SECURE\r
+void InRpcUseSecure(RPC_USE_SECURE *u, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (u == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(u, sizeof(RPC_USE_SECURE));\r
+       u->DeviceId = PackGetInt(p, "DeviceId");\r
+}\r
+void OutRpcUseSecure(PACK *p, RPC_USE_SECURE *u)\r
+{\r
+       // 引数チェック\r
+       if (u == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "DeviceId", u->DeviceId);\r
+}\r
+\r
+// RPC_ENUM_OBJECT_IN_SECURE の解放\r
+void CiFreeEnumObjectInSecure(RPC_ENUM_OBJECT_IN_SECURE *a)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < a->NumItem;i++)\r
+       {\r
+               Free(a->ItemName[i]);\r
+       }\r
+       Free(a->ItemName);\r
+       Free(a->ItemType);\r
+}\r
+\r
+// RPC_ENUM_OBJECT_IN_SECURE\r
+void InRpcEnumObjectInSecure(RPC_ENUM_OBJECT_IN_SECURE *e, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(e, sizeof(RPC_ENUM_OBJECT_IN_SECURE));\r
+\r
+       e->NumItem = PackGetNum(p, "NumItem");\r
+       e->hWnd = PackGetInt(p, "hWnd");\r
+       e->ItemName = ZeroMalloc(sizeof(char *) * e->NumItem);\r
+       e->ItemType = ZeroMalloc(sizeof(bool) * e->NumItem);\r
+\r
+       for (i = 0;i < e->NumItem;i++)\r
+       {\r
+               char name[MAX_SIZE];\r
+\r
+               Zero(name, sizeof(name));\r
+               PackGetStrEx(p, "ItemName", name, sizeof(name), i);\r
+               e->ItemName[i] = CopyStr(name);\r
+\r
+               e->ItemType[i] = PackGetIntEx(p, "ItemType", i) ? true : false;\r
+       }\r
+}\r
+void OutRpcEnumObjectInSecure(PACK *p, RPC_ENUM_OBJECT_IN_SECURE *e)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddNum(p, "NumItem", e->NumItem);\r
+       PackAddInt(p, "hWnd", e->hWnd);\r
+\r
+       for (i = 0;i < e->NumItem;i++)\r
+       {\r
+               PackAddStrEx(p, "ItemName", e->ItemName[i], i, e->NumItem);\r
+               PackAddIntEx(p, "ItemType", e->ItemType[i], i, e->NumItem);\r
+       }\r
+}\r
+\r
+// RPC_CLIENT_CREATE_VLAN\r
+void InRpcCreateVLan(RPC_CLIENT_CREATE_VLAN *v, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(v, sizeof(RPC_CLIENT_CREATE_VLAN));\r
+       PackGetStr(p, "DeviceName", v->DeviceName, sizeof(v->DeviceName));\r
+}\r
+void OutRpcCreateVLan(PACK *p, RPC_CLIENT_CREATE_VLAN *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "DeviceName", v->DeviceName);\r
+}\r
+\r
+// RPC_CLIENT_GET_VLAN\r
+void InRpcClientGetVLan(RPC_CLIENT_GET_VLAN *v, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(v, sizeof(RPC_CLIENT_GET_VLAN));\r
+       PackGetStr(p, "DeviceName", v->DeviceName, sizeof(v->DeviceName));\r
+       v->Enabled = PackGetInt(p, "Enabled") ? true : false;\r
+       PackGetStr(p, "MacAddress", v->MacAddress, sizeof(v->MacAddress));\r
+       PackGetStr(p, "Version", v->Version, sizeof(v->Version));\r
+       PackGetStr(p, "FileName", v->FileName, sizeof(v->FileName));\r
+       PackGetStr(p, "Guid", v->Guid, sizeof(v->Guid));\r
+}\r
+void OutRpcClientGetVLan(PACK *p, RPC_CLIENT_GET_VLAN *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "DeviceName", v->DeviceName);\r
+       PackAddInt(p, "Enabled", v->Enabled);\r
+       PackAddStr(p, "MacAddress", v->MacAddress);\r
+       PackAddStr(p, "Version", v->Version);\r
+       PackAddStr(p, "FileName", v->FileName);\r
+       PackAddStr(p, "Guid", v->Guid);\r
+}\r
+\r
+// RPC_CLIENT_SET_VLAN\r
+void InRpcClientSetVLan(RPC_CLIENT_SET_VLAN *v, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(v, sizeof(RPC_CLIENT_SET_VLAN));\r
+       PackGetStr(p, "DeviceName", v->DeviceName, sizeof(v->DeviceName));\r
+       PackGetStr(p, "MacAddress", v->MacAddress, sizeof(v->MacAddress));\r
+}\r
+void OutRpcClientSetVLan(PACK *p, RPC_CLIENT_SET_VLAN *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "DeviceName", v->DeviceName);\r
+       PackAddStr(p, "MacAddress", v->MacAddress);\r
+}\r
+\r
+// RPC_CLIENT_ENUM_VLAN\r
+void InRpcClientEnumVLan(RPC_CLIENT_ENUM_VLAN *v, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(v, sizeof(RPC_CLIENT_ENUM_VLAN));\r
+       v->NumItem = PackGetNum(p, "NumItem");\r
+       v->Items = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_VLAN_ITEM *) * v->NumItem);\r
+\r
+       for (i = 0;i < v->NumItem;i++)\r
+       {\r
+               RPC_CLIENT_ENUM_VLAN_ITEM *item = v->Items[i] =\r
+                       ZeroMalloc(sizeof(RPC_CLIENT_ENUM_VLAN_ITEM));\r
+\r
+               PackGetStrEx(p, "DeviceName", item->DeviceName, sizeof(item->DeviceName), i);\r
+               item->Enabled = PackGetIntEx(p, "Enabled", i) ? true : false;\r
+               PackGetStrEx(p, "MacAddress", item->MacAddress, sizeof(item->MacAddress), i);\r
+               PackGetStrEx(p, "Version", item->Version, sizeof(item->Version), i);\r
+       }\r
+}\r
+void OutRpcClientEnumVLan(PACK *p, RPC_CLIENT_ENUM_VLAN *v)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddNum(p, "NumItem", v->NumItem);\r
+\r
+       for (i = 0;i < v->NumItem;i++)\r
+       {\r
+               RPC_CLIENT_ENUM_VLAN_ITEM *item = v->Items[i];\r
+\r
+               PackAddStrEx(p, "DeviceName", item->DeviceName, i, v->NumItem);\r
+               PackAddIntEx(p, "Enabled", item->Enabled, i, v->NumItem);\r
+               PackAddStrEx(p, "MacAddress", item->MacAddress, i, v->NumItem);\r
+               PackAddStrEx(p, "Version", item->Version, i, v->NumItem);\r
+       }\r
+}\r
+\r
+// CLIENT_OPTION\r
+void InRpcClientOption(CLIENT_OPTION *c, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(c, sizeof(CLIENT_OPTION));\r
+\r
+       PackGetUniStr(p, "AccountName", c->AccountName, sizeof(c->AccountName));\r
+       PackGetStr(p, "Hostname", c->Hostname, sizeof(c->Hostname));\r
+       c->Port = PackGetInt(p, "Port");\r
+       c->PortUDP = PackGetInt(p, "PortUDP");\r
+       c->ProxyType = PackGetInt(p, "ProxyType");\r
+       c->ProxyPort = PackGetInt(p, "ProxyPort");\r
+       c->NumRetry = PackGetInt(p, "NumRetry");\r
+       c->RetryInterval = PackGetInt(p, "RetryInterval");\r
+       c->MaxConnection = PackGetInt(p, "MaxConnection");\r
+       c->AdditionalConnectionInterval = PackGetInt(p, "AdditionalConnectionInterval");\r
+       c->ConnectionDisconnectSpan = PackGetInt(p, "ConnectionDisconnectSpan");\r
+       c->HideStatusWindow = PackGetBool(p, "HideStatusWindow");\r
+       c->HideNicInfoWindow = PackGetBool(p, "HideNicInfoWindow");\r
+       c->DisableQoS = PackGetBool(p, "DisableQoS");\r
+       PackGetStr(p, "ProxyName", c->ProxyName, sizeof(c->ProxyName));\r
+       PackGetStr(p, "ProxyUsername", c->ProxyUsername, sizeof(c->ProxyUsername));\r
+       PackGetStr(p, "ProxyPassword", c->ProxyPassword, sizeof(c->ProxyPassword));\r
+       PackGetStr(p, "HubName", c->HubName, sizeof(c->HubName));\r
+       PackGetStr(p, "DeviceName", c->DeviceName, sizeof(c->DeviceName));\r
+       c->UseEncrypt = PackGetInt(p, "UseEncrypt") ? true : false;\r
+       c->UseCompress = PackGetInt(p, "UseCompress") ? true : false;\r
+       c->HalfConnection = PackGetInt(p, "HalfConnection") ? true : false;\r
+       c->NoRoutingTracking = PackGetInt(p, "NoRoutingTracking") ? true : false;\r
+       c->RequireMonitorMode = PackGetBool(p, "RequireMonitorMode");\r
+       c->RequireBridgeRoutingMode = PackGetBool(p, "RequireBridgeRoutingMode");\r
+       c->FromAdminPack = PackGetBool(p, "FromAdminPack");\r
+       c->NoTls1 = PackGetBool(p, "NoTls1");\r
+}\r
+void OutRpcClientOption(PACK *p, CLIENT_OPTION *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddUniStr(p, "AccountName", c->AccountName);\r
+       PackAddStr(p, "Hostname", c->Hostname);\r
+       PackAddStr(p, "ProxyName", c->ProxyName);\r
+       PackAddStr(p, "ProxyUsername", c->ProxyUsername);\r
+       PackAddStr(p, "ProxyPassword", c->ProxyPassword);\r
+       PackAddStr(p, "HubName", c->HubName);\r
+       PackAddStr(p, "DeviceName", c->DeviceName);\r
+       PackAddInt(p, "Port", c->Port);\r
+       PackAddInt(p, "PortUDP", c->PortUDP);\r
+       PackAddInt(p, "ProxyType", c->ProxyType);\r
+       PackAddInt(p, "ProxyPort", c->ProxyPort);\r
+       PackAddInt(p, "NumRetry", c->NumRetry);\r
+       PackAddInt(p, "RetryInterval", c->RetryInterval);\r
+       PackAddInt(p, "MaxConnection", c->MaxConnection);\r
+       PackAddInt(p, "UseEncrypt", c->UseEncrypt);\r
+       PackAddInt(p, "UseCompress", c->UseCompress);\r
+       PackAddInt(p, "HalfConnection", c->HalfConnection);\r
+       PackAddInt(p, "NoRoutingTracking", c->NoRoutingTracking);\r
+       PackAddInt(p, "AdditionalConnectionInterval", c->AdditionalConnectionInterval);\r
+       PackAddInt(p, "ConnectionDisconnectSpan", c->ConnectionDisconnectSpan);\r
+       PackAddBool(p, "HideStatusWindow", c->HideStatusWindow);\r
+       PackAddBool(p, "HideNicInfoWindow", c->HideNicInfoWindow);\r
+       PackAddBool(p, "RequireMonitorMode", c->RequireMonitorMode);\r
+       PackAddBool(p, "RequireBridgeRoutingMode", c->RequireBridgeRoutingMode);\r
+       PackAddBool(p, "DisableQoS", c->DisableQoS);\r
+       PackAddBool(p, "FromAdminPack", c->FromAdminPack);\r
+       PackAddBool(p, "NoTls1", c->NoTls1);\r
+}\r
+\r
+// CLIENT_AUTH\r
+void InRpcClientAuth(CLIENT_AUTH *c, PACK *p)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(c, sizeof(CLIENT_AUTH));\r
+       c->AuthType = PackGetInt(p, "AuthType");\r
+       PackGetStr(p, "Username", c->Username, sizeof(c->Username));\r
+\r
+       switch (c->AuthType)\r
+       {\r
+       case CLIENT_AUTHTYPE_ANONYMOUS:\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_PASSWORD:\r
+               if (PackGetDataSize(p, "HashedPassword") == SHA1_SIZE)\r
+               {\r
+                       PackGetData(p, "HashedPassword", c->HashedPassword);\r
+               }\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_PLAIN_PASSWORD:\r
+               PackGetStr(p, "PlainPassword", c->PlainPassword, sizeof(c->PlainPassword));\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_CERT:\r
+               b = PackGetBuf(p, "ClientX");\r
+               if (b != NULL)\r
+               {\r
+                       c->ClientX = BufToX(b, false);\r
+                       FreeBuf(b);\r
+               }\r
+               b = PackGetBuf(p, "ClientK");\r
+               if (b != NULL)\r
+               {\r
+                       c->ClientK = BufToK(b, true, false, NULL);\r
+                       FreeBuf(b);\r
+               }\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_SECURE:\r
+               PackGetStr(p, "SecurePublicCertName", c->SecurePublicCertName, sizeof(c->SecurePublicCertName));\r
+               PackGetStr(p, "SecurePrivateKeyName", c->SecurePrivateKeyName, sizeof(c->SecurePrivateKeyName));\r
+               break;\r
+       }\r
+}\r
+void OutRpcClientAuth(PACK *p, CLIENT_AUTH *c)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "AuthType", c->AuthType);\r
+       PackAddStr(p, "Username", c->Username);\r
+\r
+       switch (c->AuthType)\r
+       {\r
+       case CLIENT_AUTHTYPE_ANONYMOUS:\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_PASSWORD:\r
+               PackAddData(p, "HashedPassword", c->HashedPassword, SHA1_SIZE);\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_PLAIN_PASSWORD:\r
+               PackAddStr(p, "PlainPassword", c->PlainPassword);\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_CERT:\r
+               b = XToBuf(c->ClientX, false);\r
+               if (b != NULL)\r
+               {\r
+                       PackAddBuf(p, "ClientX", b);\r
+                       FreeBuf(b);\r
+               }\r
+               b = KToBuf(c->ClientK, false, NULL);\r
+               if (b != NULL)\r
+               {\r
+                       PackAddBuf(p, "ClientK", b);\r
+                       FreeBuf(b);\r
+               }\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_SECURE:\r
+               PackAddStr(p, "SecurePublicCertName", c->SecurePublicCertName);\r
+               PackAddStr(p, "SecurePrivateKeyName", c->SecurePrivateKeyName);\r
+               break;\r
+       }\r
+}\r
+\r
+// RPC_CLIENT_CREATE_ACCOUNT\r
+void InRpcClientCreateAccount(RPC_CLIENT_CREATE_ACCOUNT *c, PACK *p)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(c, sizeof(RPC_CLIENT_CREATE_ACCOUNT));\r
+       c->ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       c->ClientAuth = ZeroMalloc(sizeof(CLIENT_AUTH));\r
+\r
+       InRpcClientOption(c->ClientOption, p);\r
+       InRpcClientAuth(c->ClientAuth, p);\r
+\r
+       c->StartupAccount = PackGetInt(p, "StartupAccount") ? true : false;\r
+       c->CheckServerCert = PackGetInt(p, "CheckServerCert") ? true : false;\r
+       b = PackGetBuf(p, "ServerCert");\r
+       if (b != NULL)\r
+       {\r
+               c->ServerCert = BufToX(b, false);\r
+               FreeBuf(b);\r
+       }\r
+       PackGetData2(p, "ShortcutKey", c->ShortcutKey, sizeof(c->ShortcutKey));\r
+}\r
+void OutRpcClientCreateAccount(PACK *p, RPC_CLIENT_CREATE_ACCOUNT *c)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       OutRpcClientOption(p, c->ClientOption);\r
+       OutRpcClientAuth(p, c->ClientAuth);\r
+\r
+       PackAddInt(p, "StartupAccount", c->StartupAccount);\r
+       PackAddInt(p, "CheckServerCert", c->CheckServerCert);\r
+       if (c->ServerCert != NULL)\r
+       {\r
+               b = XToBuf(c->ServerCert, false);\r
+               if (b != NULL)\r
+               {\r
+                       PackAddBuf(p, "ServerCert", b);\r
+                       FreeBuf(b);\r
+               }\r
+       }\r
+       PackAddData(p, "ShortcutKey", c->ShortcutKey, sizeof(c->ShortcutKey));\r
+}\r
+\r
+// RPC_CLIENT_ENUM_ACCOUNT\r
+void InRpcClientEnumAccount(RPC_CLIENT_ENUM_ACCOUNT *e, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(e, sizeof(RPC_CLIENT_ENUM_ACCOUNT));\r
+\r
+       e->NumItem = PackGetNum(p, "NumItem");\r
+       e->Items = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_ACCOUNT_ITEM *) * e->NumItem);\r
+\r
+       for (i = 0;i < e->NumItem;i++)\r
+       {\r
+               RPC_CLIENT_ENUM_ACCOUNT_ITEM *item = e->Items[i] =\r
+                       ZeroMalloc(sizeof(RPC_CLIENT_ENUM_ACCOUNT_ITEM));\r
+\r
+               PackGetUniStrEx(p, "AccountName", item->AccountName, sizeof(item->AccountName), i);\r
+               PackGetStrEx(p, "UserName", item->UserName, sizeof(item->UserName), i);\r
+               PackGetStrEx(p, "ServerName", item->ServerName, sizeof(item->ServerName), i);\r
+               PackGetStrEx(p, "ProxyName", item->ProxyName, sizeof(item->ProxyName), i);\r
+               PackGetStrEx(p, "DeviceName", item->DeviceName, sizeof(item->DeviceName), i);\r
+               item->ProxyType = PackGetIntEx(p, "ProxyType", i);\r
+               item->Active = PackGetIntEx(p, "Active", i) ? true : false;\r
+               item->StartupAccount = PackGetIntEx(p, "StartupAccount", i) ? true : false;\r
+               item->Connected = PackGetBoolEx(p, "Connected", i);\r
+               item->Port = PackGetIntEx(p, "Port", i);\r
+               PackGetStrEx(p, "HubName", item->HubName, sizeof(item->HubName), i);\r
+               item->CreateDateTime = PackGetInt64Ex(p, "CreateDateTime", i);\r
+               item->UpdateDateTime = PackGetInt64Ex(p, "UpdateDateTime", i);\r
+               item->LastConnectDateTime = PackGetInt64Ex(p, "LastConnectDateTime", i);\r
+       }\r
+}\r
+void OutRpcClientEnumAccount(PACK *p, RPC_CLIENT_ENUM_ACCOUNT *e)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddNum(p, "NumItem", e->NumItem);\r
+\r
+       for (i = 0;i < e->NumItem;i++)\r
+       {\r
+               RPC_CLIENT_ENUM_ACCOUNT_ITEM *item = e->Items[i];\r
+\r
+               PackAddUniStrEx(p, "AccountName", item->AccountName, i, e->NumItem);\r
+               PackAddStrEx(p, "UserName", item->UserName, i, e->NumItem);\r
+               PackAddStrEx(p, "ServerName", item->ServerName, i, e->NumItem);\r
+               PackAddStrEx(p, "ProxyName", item->ProxyName, i, e->NumItem);\r
+               PackAddStrEx(p, "DeviceName", item->DeviceName, i, e->NumItem);\r
+               PackAddIntEx(p, "ProxyType", item->ProxyType, i, e->NumItem);\r
+               PackAddIntEx(p, "Active", item->Active, i, e->NumItem);\r
+               PackAddIntEx(p, "StartupAccount", item->StartupAccount, i, e->NumItem);\r
+               PackAddBoolEx(p, "Connected", item->Connected, i, e->NumItem);\r
+               PackAddIntEx(p, "Port", item->Port, i, e->NumItem);\r
+               PackAddStrEx(p, "HubName", item->HubName, i, e->NumItem);\r
+               PackAddInt64Ex(p, "CreateDateTime", item->CreateDateTime, i, e->NumItem);\r
+               PackAddInt64Ex(p, "UpdateDateTime", item->UpdateDateTime, i, e->NumItem);\r
+               PackAddInt64Ex(p, "LastConnectDateTime", item->LastConnectDateTime, i, e->NumItem);\r
+       }\r
+}\r
+\r
+// RPC_CLIENT_DELETE_ACCOUNT\r
+void InRpcClientDeleteAccount(RPC_CLIENT_DELETE_ACCOUNT *a, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(a, sizeof(RPC_CLIENT_DELETE_ACCOUNT));\r
+       PackGetUniStr(p, "AccountName", a->AccountName, sizeof(a->AccountName));\r
+}\r
+void OutRpcClientDeleteAccount(PACK *p, RPC_CLIENT_DELETE_ACCOUNT *a)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddUniStr(p, "AccountName", a->AccountName);\r
+}\r
+\r
+// RPC_RENAME_ACCOUNT\r
+void InRpcRenameAccount(RPC_RENAME_ACCOUNT *a, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(a, sizeof(RPC_RENAME_ACCOUNT));\r
+\r
+       PackGetUniStr(p, "OldName", a->OldName, sizeof(a->OldName));\r
+       PackGetUniStr(p, "NewName", a->NewName, sizeof(a->NewName));\r
+}\r
+void OutRpcRenameAccount(PACK *p, RPC_RENAME_ACCOUNT *a)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddUniStr(p, "OldName", a->OldName);\r
+       PackAddUniStr(p, "NewName", a->NewName);\r
+}\r
+\r
+// RPC_CLIENT_GET_ACCOUNT\r
+void InRpcClientGetAccount(RPC_CLIENT_GET_ACCOUNT *c, PACK *p)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(c, sizeof(RPC_CLIENT_GET_ACCOUNT));\r
+\r
+       c->ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       c->ClientAuth = ZeroMalloc(sizeof(CLIENT_AUTH));\r
+\r
+       PackGetUniStr(p, "AccountName", c->AccountName, sizeof(c->AccountName));\r
+       c->StartupAccount = PackGetInt(p, "StartupAccount") ? true : false;\r
+       c->CheckServerCert = PackGetInt(p, "CheckServerCert") ? true : false;\r
+       b = PackGetBuf(p, "ServerCert");\r
+       if (b != NULL)\r
+       {\r
+               c->ServerCert = BufToX(b, false);\r
+               FreeBuf(b);\r
+       }\r
+\r
+       InRpcClientOption(c->ClientOption, p);\r
+       InRpcClientAuth(c->ClientAuth, p);\r
+\r
+       c->CreateDateTime = PackGetInt64(p, "CreateDateTime");\r
+       c->UpdateDateTime = PackGetInt64(p, "UpdateDateTime");\r
+       c->LastConnectDateTime = PackGetInt64(p, "LastConnectDateTime");\r
+\r
+       PackGetData2(p, "ShortcutKey", c->ShortcutKey, SHA1_SIZE);\r
+}\r
+void OutRpcClientGetAccount(PACK *p, RPC_CLIENT_GET_ACCOUNT *c)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddUniStr(p, "AccountName", c->AccountName);\r
+       PackAddInt(p, "StartupAccount", c->StartupAccount);\r
+       PackAddInt(p, "CheckServerCert", c->CheckServerCert);\r
+\r
+       if (c->ServerCert != NULL)\r
+       {\r
+               b = XToBuf(c->ServerCert, false);\r
+               if (b != NULL)\r
+               {\r
+                       PackAddBuf(p, "ServerCert", b);\r
+                       FreeBuf(b);\r
+               }\r
+       }\r
+\r
+       OutRpcClientOption(p, c->ClientOption);\r
+       OutRpcClientAuth(p, c->ClientAuth);\r
+\r
+       PackAddData(p, "ShortcutKey", c->ShortcutKey, SHA1_SIZE);\r
+\r
+       PackAddInt64(p, "CreateDateTime", c->CreateDateTime);\r
+       PackAddInt64(p, "UpdateDateTime", c->UpdateDateTime);\r
+       PackAddInt64(p, "LastConnectDateTime", c->LastConnectDateTime);\r
+}\r
+\r
+// RPC_CLIENT_CONNECT\r
+void InRpcClientConnect(RPC_CLIENT_CONNECT *c, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(c, sizeof(RPC_CLIENT_CONNECT));\r
+\r
+       PackGetUniStr(p, "AccountName", c->AccountName, sizeof(c->AccountName));\r
+}\r
+void OutRpcClientConnect(PACK *p, RPC_CLIENT_CONNECT *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddUniStr(p, "AccountName", c->AccountName);\r
+}\r
+\r
+// POLICY\r
+void InRpcPolicy(POLICY *o, PACK *p)\r
+{\r
+       POLICY *pol;\r
+       // 引数チェック\r
+       if (o == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pol = PackGetPolicy(p);\r
+       Copy(o, pol, sizeof(POLICY));\r
+       Free(pol);\r
+}\r
+void OutRpcPolicy(PACK *p, POLICY *o)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddPolicy(p, o);\r
+}\r
+\r
+// RPC_CLIENT_GET_CONNECTION_STATUS\r
+void InRpcClientGetConnectionStatus(RPC_CLIENT_GET_CONNECTION_STATUS *s, PACK *p)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(s, sizeof(RPC_CLIENT_GET_CONNECTION_STATUS));\r
+\r
+       PackGetUniStr(p, "AccountName", s->AccountName, sizeof(s->AccountName));\r
+\r
+       PackGetStr(p, "ServerName", s->ServerName, sizeof(s->ServerName));\r
+       PackGetStr(p, "ServerProductName", s->ServerProductName, sizeof(s->ServerProductName));\r
+       PackGetStr(p, "CipherName", s->CipherName, sizeof(s->CipherName));\r
+       PackGetStr(p, "SessionName", s->SessionName, sizeof(s->SessionName));\r
+       PackGetStr(p, "ConnectionName", s->ConnectionName, sizeof(s->ConnectionName));\r
+\r
+       if (PackGetDataSize(p, "SessionKey") == SHA1_SIZE)\r
+       {\r
+               PackGetData(p, "SessionKey", s->SessionKey);\r
+       }\r
+\r
+       s->SessionStatus = PackGetInt(p, "SessionStatus");\r
+       s->ServerPort = PackGetInt(p, "ServerPort");\r
+       s->ServerProductVer = PackGetInt(p, "ServerProductVer");\r
+       s->ServerProductBuild = PackGetInt(p, "ServerProductBuild");\r
+       s->NumConnectionsEatablished = PackGetInt(p, "NumConnectionsEatablished");\r
+       s->MaxTcpConnections = PackGetInt(p, "MaxTcpConnections");\r
+       s->NumTcpConnections = PackGetInt(p, "NumTcpConnections");\r
+       s->NumTcpConnectionsUpload = PackGetInt(p, "NumTcpConnectionsUpload");\r
+       s->NumTcpConnectionsDownload = PackGetInt(p, "NumTcpConnectionsDownload");\r
+\r
+       s->StartTime = PackGetInt64(p, "StartTime");\r
+       s->FirstConnectionEstablisiedTime = PackGetInt64(p, "FirstConnectionEstablisiedTime");\r
+       s->CurrentConnectionEstablishTime = PackGetInt64(p, "CurrentConnectionEstablishTime");\r
+       s->TotalSendSize = PackGetInt64(p, "TotalSendSize");\r
+       s->TotalRecvSize = PackGetInt64(p, "TotalRecvSize");\r
+       s->TotalSendSizeReal = PackGetInt64(p, "TotalSendSizeReal");\r
+       s->TotalRecvSizeReal = PackGetInt64(p, "TotalRecvSizeReal");\r
+\r
+       s->Active = PackGetInt(p, "Active") ? true : false;\r
+       s->Connected = PackGetInt(p, "Connected") ? true : false;\r
+       s->HalfConnection = PackGetInt(p, "HalfConnection") ? true : false;\r
+       s->QoS = PackGetInt(p, "QoS") ? true : false;\r
+       s->UseEncrypt = PackGetInt(p, "UseEncrypt") ? true : false;\r
+       s->UseCompress = PackGetInt(p, "UseCompress") ? true : false;\r
+\r
+       s->IsBridgeMode = PackGetBool(p, "IsBridgeMode");\r
+       s->IsMonitorMode = PackGetBool(p, "IsMonitorMode");\r
+\r
+       s->VLanId = PackGetInt(p, "VLanId");\r
+\r
+       b = PackGetBuf(p, "ServerX");\r
+       if (b != NULL)\r
+       {\r
+               s->ServerX = BufToX(b, false);\r
+               FreeBuf(b);\r
+       }\r
+\r
+       b = PackGetBuf(p, "ClientX");\r
+       if (b != NULL)\r
+       {\r
+               s->ClientX = BufToX(b, false);\r
+               FreeBuf(b);\r
+       }\r
+\r
+       InRpcPolicy(&s->Policy, p);\r
+\r
+       InRpcTraffic(&s->Traffic, p);\r
+}\r
+void OutRpcClientGetConnectionStatus(PACK *p, RPC_CLIENT_GET_CONNECTION_STATUS *c)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (p == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddUniStr(p, "AccountName", c->AccountName);\r
+\r
+       PackAddStr(p, "ServerName", c->ServerName);\r
+       PackAddStr(p, "ServerProductName", c->ServerProductName);\r
+       PackAddStr(p, "CipherName", c->CipherName);\r
+       PackAddStr(p, "SessionName", c->SessionName);\r
+       PackAddStr(p, "ConnectionName", c->ConnectionName);\r
+\r
+       PackAddData(p, "SessionKey", c->SessionKey, SHA1_SIZE);\r
+\r
+       PackAddInt(p, "Active", c->Active);\r
+       PackAddInt(p, "Connected", c->Connected);\r
+       PackAddInt(p, "SessionStatus", c->SessionStatus);\r
+       PackAddInt(p, "ServerPort", c->ServerPort);\r
+       PackAddInt(p, "ServerProductVer", c->ServerProductVer);\r
+       PackAddInt(p, "ServerProductBuild", c->ServerProductBuild);\r
+       PackAddInt(p, "NumConnectionsEatablished", c->NumConnectionsEatablished);\r
+       PackAddInt(p, "HalfConnection", c->HalfConnection);\r
+       PackAddInt(p, "QoS", c->QoS);\r
+       PackAddInt(p, "MaxTcpConnections", c->MaxTcpConnections);\r
+       PackAddInt(p, "NumTcpConnections", c->NumTcpConnections);\r
+       PackAddInt(p, "NumTcpConnectionsUpload", c->NumTcpConnectionsUpload);\r
+       PackAddInt(p, "NumTcpConnectionsDownload", c->NumTcpConnectionsDownload);\r
+       PackAddInt(p, "UseEncrypt", c->UseEncrypt);\r
+       PackAddInt(p, "UseCompress", c->UseCompress);\r
+\r
+       PackAddBool(p, "IsBridgeMode", c->IsBridgeMode);\r
+       PackAddBool(p, "IsMonitorMode", c->IsMonitorMode);\r
+\r
+       PackAddInt64(p, "StartTime", c->StartTime);\r
+       PackAddInt64(p, "FirstConnectionEstablisiedTime", c->FirstConnectionEstablisiedTime);\r
+       PackAddInt64(p, "CurrentConnectionEstablishTime", c->CurrentConnectionEstablishTime);\r
+       PackAddInt64(p, "TotalSendSize", c->TotalSendSize);\r
+       PackAddInt64(p, "TotalRecvSize", c->TotalRecvSize);\r
+       PackAddInt64(p, "TotalSendSizeReal", c->TotalSendSizeReal);\r
+       PackAddInt64(p, "TotalRecvSizeReal", c->TotalRecvSizeReal);\r
+\r
+       PackAddInt(p, "VLanId", c->VLanId);\r
+\r
+       OutRpcPolicy(p, &c->Policy);\r
+\r
+       OutRpcTraffic(p, &c->Traffic);\r
+\r
+       if (c->ServerX != NULL)\r
+       {\r
+               b = XToBuf(c->ServerX, false);\r
+               PackAddBuf(p, "ServerX", b);\r
+               FreeBuf(b);\r
+       }\r
+\r
+       if (c->ClientX != NULL)\r
+       {\r
+               b = XToBuf(c->ClientX, false);\r
+               PackAddBuf(p, "ClientX", b);\r
+               FreeBuf(b);\r
+       }\r
+}\r
+\r
+void InRpcClientNotify(RPC_CLIENT_NOTIFY *n, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(n, sizeof(RPC_CLIENT_NOTIFY));\r
+\r
+       n->NotifyCode = PackGetInt(p, "NotifyCode");\r
+}\r
+void OutRpcClientNotify(PACK *p, RPC_CLIENT_NOTIFY *n)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "NotifyCode", n->NotifyCode);\r
+}\r
+\r
+// 通知メイン\r
+void CiNotifyMain(CLIENT *c, SOCK *s)\r
+{\r
+       CANCEL *cancel;\r
+       // 引数チェック\r
+       if (c == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // キャンセルを登録\r
+       cancel = NewCancel();\r
+       LockList(c->NotifyCancelList);\r
+       {\r
+               Add(c->NotifyCancelList, cancel);\r
+       }\r
+       UnlockList(c->NotifyCancelList);\r
+\r
+       // 待機\r
+       while (true)\r
+       {\r
+               char ch = '@';\r
+               SOCKSET set;\r
+               InitSockSet(&set);\r
+               AddSockSet(&set, s);\r
+               Select(&set, INFINITE, cancel, NULL);\r
+\r
+               if (c->Halt)\r
+               {\r
+                       // 強制終了\r
+                       break;\r
+               }\r
+\r
+               // 1 バイト送信\r
+               if (Send(s, &ch, 1, false) == 0)\r
+               {\r
+                       // 切断された\r
+                       break;\r
+               }\r
+       }\r
+\r
+       // 切断\r
+       Disconnect(s);\r
+\r
+       // キャンセルを登録解除\r
+       LockList(c->NotifyCancelList);\r
+       {\r
+               Delete(c->NotifyCancelList, cancel);\r
+       }\r
+       UnlockList(c->NotifyCancelList);\r
+\r
+       ReleaseCancel(cancel);\r
+}\r
+\r
+// RPC 受付コード\r
+void CiRpcAccepted(CLIENT *c, SOCK *s)\r
+{\r
+       UCHAR hashed_password[SHA1_SIZE];\r
+       UINT rpc_mode;\r
+       UINT retcode;\r
+       RPC *rpc;\r
+       // 引数チェック\r
+       if (c == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // RPC モード受信\r
+       if (RecvAll(s, &rpc_mode, sizeof(UINT), false) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       rpc_mode = Endian32(rpc_mode);\r
+\r
+       if (rpc_mode == CLIENT_RPC_MODE_NOTIFY)\r
+       {\r
+               // 通知モード\r
+               CiNotifyMain(c, s);\r
+               return;\r
+       }\r
+       else if (rpc_mode == CLIENT_RPC_MODE_SHORTCUT || rpc_mode == CLIENT_RPC_MODE_SHORTCUT_DISCONNECT)\r
+       {\r
+               // ショートカットキー受信\r
+               UCHAR key[SHA1_SIZE];\r
+               UINT err = ERR_NO_ERROR;\r
+               if (RecvAll(s, key, SHA1_SIZE, false))\r
+               {\r
+                       UINT i;\r
+                       wchar_t title[MAX_ACCOUNT_NAME_LEN + 1];\r
+                       bool ok = false;\r
+                       // 指定された接続設定に接続する\r
+                       LockList(c->AccountList);\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(c->AccountList);i++)\r
+                               {\r
+                                       ACCOUNT *a = LIST_DATA(c->AccountList, i);\r
+                                       Lock(a->lock);\r
+                                       {\r
+                                               if (Cmp(a->ShortcutKey, key, SHA1_SIZE) == 0)\r
+                                               {\r
+                                                       ok = true;\r
+                                                       UniStrCpy(title, sizeof(title), a->ClientOption->AccountName);\r
+                                               }\r
+                                       }\r
+                                       Unlock(a->lock);\r
+                               }\r
+                       }\r
+                       UnlockList(c->AccountList);\r
+\r
+                       if (ok == false)\r
+                       {\r
+                               err = ERR_ACCOUNT_NOT_FOUND;\r
+                       }\r
+                       else\r
+                       {\r
+                               RPC_CLIENT_CONNECT t;\r
+                               Zero(&t, sizeof(t));\r
+                               UniStrCpy(t.AccountName, sizeof(t.AccountName), title);\r
+\r
+                               if (rpc_mode == CLIENT_RPC_MODE_SHORTCUT)\r
+                               {\r
+                                       // 接続\r
+                                       if (CtConnect(c, &t))\r
+                                       {\r
+                                               err = ERR_NO_ERROR;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               err = c->Err;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 接続\r
+                                       if (CtDisconnect(c, &t))\r
+                                       {\r
+                                               err = ERR_NO_ERROR;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               err = c->Err;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       err = Endian32(err);\r
+                       SendAll(s, &err, sizeof(UINT), false);\r
+                       RecvAll(s, &err, sizeof(UINT), false);\r
+               }\r
+               return;\r
+       }\r
+\r
+       // パスワード受信\r
+       if (RecvAll(s, hashed_password, SHA1_SIZE, false) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       retcode = 0;\r
+\r
+       // パスワード比較\r
+       if (Cmp(hashed_password, c->EncryptedPassword, SHA1_SIZE) != 0)\r
+       {\r
+               retcode = 1;\r
+       }\r
+\r
+       if (c->PasswordRemoteOnly && s->RemoteIP.addr[0] == 127)\r
+       {\r
+               // リモートのみパスワードを要求するモードで、ローカルから接続された場合は\r
+               // パスワードを常に正しいと見なす\r
+               retcode = 0;\r
+       }\r
+\r
+       Lock(c->lock);\r
+       {\r
+               if (c->Config.AllowRemoteConfig == false)\r
+               {\r
+                       // リモート管理が禁止されている場合は\r
+                       // このコネクションが外部からのものであるかどうか識別する\r
+                       if (s->RemoteIP.addr[0] != 127)\r
+                       {\r
+                               retcode = 2;\r
+                       }\r
+               }\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       retcode = Endian32(retcode);\r
+       // エラーコード送信\r
+       if (SendAll(s, &retcode, sizeof(UINT), false) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+\r
+\r
+       if (retcode != 0)\r
+       {\r
+               // エラーによる切断\r
+               return;\r
+       }\r
+\r
+       // RPC サーバー作成\r
+       rpc = StartRpcServer(s, CiRpcDispatch, c);\r
+\r
+       // RPC サーバー動作\r
+       RpcServer(rpc);\r
+\r
+       // RPC サーバーの解放\r
+       EndRpc(rpc);\r
+}\r
+\r
+// RPC 受付スレッド\r
+void CiRpcAcceptThread(THREAD *thread, void *param)\r
+{\r
+       CLIENT_RPC_CONNECTION *conn;\r
+       CLIENT *c;\r
+       SOCK *s;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       conn = (CLIENT_RPC_CONNECTION *)param;\r
+       s = conn->Sock;\r
+       c = conn->Client;\r
+       AddRef(s->ref);\r
+\r
+       // RPC コネクションリストに追加\r
+       LockList(c->RpcConnectionList);\r
+       {\r
+               Add(c->RpcConnectionList, conn);\r
+       }\r
+       UnlockList(c->RpcConnectionList);\r
+\r
+       NoticeThreadInit(thread);\r
+\r
+       // メイン処理\r
+       CiRpcAccepted(c, s);\r
+\r
+       // コネクションリストから解放\r
+       LockList(c->RpcConnectionList);\r
+       {\r
+               Delete(c->RpcConnectionList, conn);\r
+       }\r
+       UnlockList(c->RpcConnectionList);\r
+\r
+       ReleaseSock(conn->Sock);\r
+       ReleaseThread(conn->Thread);\r
+       Free(conn);\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+}\r
+\r
+// RPC サーバースレッド\r
+void CiRpcServerThread(THREAD *thread, void *param)\r
+{\r
+       CLIENT *c;\r
+       SOCK *listener;\r
+       UINT i;\r
+       LIST *thread_list;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c = (CLIENT *)param;\r
+\r
+       // RPC コネクションリスト\r
+       c->RpcConnectionList = NewList(NULL);\r
+\r
+       // ポートを開く\r
+       listener = NULL;\r
+       for (i = CLIENT_CONFIG_PORT;i < (CLIENT_CONFIG_PORT + 5);i++)\r
+       {\r
+               listener = Listen(i);\r
+               if (listener != NULL)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (listener == NULL)\r
+       {\r
+               // エラー\r
+               Alert("SoftEther UT-VPN Client RPC Port Open Failed.", CEDAR_CLIENT_STR);\r
+               return;\r
+       }\r
+\r
+       c->RpcListener = listener;\r
+       AddRef(listener->ref);\r
+\r
+       NoticeThreadInit(thread);\r
+\r
+       while (true)\r
+       {\r
+               // クライアント接続を待機\r
+               CLIENT_RPC_CONNECTION *conn;\r
+               SOCK *s = Accept(listener);\r
+               if (s == NULL)\r
+               {\r
+                       // 停止\r
+                       break;\r
+               }\r
+\r
+               // クライアント処理用スレッドを作成する\r
+               conn = ZeroMalloc(sizeof(CLIENT_RPC_CONNECTION));\r
+               conn->Client = c;\r
+               conn->Sock = s;\r
+               AddRef(s->ref);\r
+\r
+               conn->Thread = NewThread(CiRpcAcceptThread, (void *)conn);\r
+               WaitThreadInit(conn->Thread);\r
+\r
+               ReleaseSock(s);\r
+       }\r
+\r
+       // リスナーを解放\r
+       ReleaseSock(listener);\r
+\r
+       thread_list = NewListFast(NULL);\r
+\r
+       // すべての通知イベントを起動する\r
+       LockList(c->NotifyCancelList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(c->NotifyCancelList);i++)\r
+               {\r
+                       CANCEL *cancel = LIST_DATA(c->NotifyCancelList, i);\r
+                       Cancel(cancel);\r
+               }\r
+       }\r
+       UnlockList(c->NotifyCancelList);\r
+\r
+       // まだ接続しているすべてのコネクションを切断する\r
+       LockList(c->RpcConnectionList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(c->RpcConnectionList);i++)\r
+               {\r
+                       CLIENT_RPC_CONNECTION *cc = LIST_DATA(c->RpcConnectionList, i);\r
+                       AddRef(cc->Thread->ref);\r
+                       Add(thread_list, cc->Thread);\r
+                       Disconnect(cc->Sock);\r
+               }\r
+       }\r
+       UnlockList(c->RpcConnectionList);\r
+\r
+       for (i = 0;i < LIST_NUM(thread_list);i++)\r
+       {\r
+               THREAD *t = LIST_DATA(thread_list, i);\r
+               WaitThread(t, INFINITE);\r
+               ReleaseThread(t);\r
+       }\r
+\r
+       ReleaseList(c->RpcConnectionList);\r
+       ReleaseList(thread_list);\r
+}\r
+\r
+// Keep を開始\r
+void CiInitKeep(CLIENT *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->Keep = StartKeep();\r
+\r
+       // 設定の適用\r
+       if (c->Config.UseKeepConnect)\r
+       {\r
+               KEEP *k = c->Keep;\r
+               Lock(k->lock);\r
+               {\r
+                       StrCpy(k->ServerName, sizeof(k->ServerName), c->Config.KeepConnectHost);\r
+                       k->ServerPort = c->Config.KeepConnectPort;\r
+                       k->Interval = c->Config.KeepConnectInterval * 1000;\r
+                       k->UdpMode = (c->Config.KeepConnectProtocol == CONNECTION_UDP) ? true : false;\r
+                       k->Enable = true;\r
+               }\r
+               Unlock(k->lock);\r
+       }\r
+}\r
+\r
+// Keep を停止\r
+void CiFreeKeep(CLIENT *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StopKeep(c->Keep);\r
+       c->Keep = NULL;\r
+}\r
+\r
+// RPC を開始\r
+void CiStartRpcServer(CLIENT *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->RpcThread = NewThread(CiRpcServerThread, (void *)c);\r
+       WaitThreadInit(c->RpcThread);\r
+}\r
+\r
+// RPC を終了\r
+void CiStopRpcServer(CLIENT *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Disconnect(c->RpcListener);\r
+       ReleaseSock(c->RpcListener);\r
+\r
+       WaitThread(c->RpcThread, INFINITE);\r
+       ReleaseThread(c->RpcThread);\r
+}\r
+\r
+// 次の通知を待機する\r
+bool CcWaitNotify(NOTIFY_CLIENT *n)\r
+{\r
+       UCHAR c;\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 1 文字受信する\r
+       if (RecvAll(n->Sock, &c, 1, false) == false)\r
+       {\r
+               // 切断された\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 通知クライアントとして接続する\r
+NOTIFY_CLIENT *CcConnectNotify(REMOTE_CLIENT *rc)\r
+{\r
+       NOTIFY_CLIENT *n;\r
+       SOCK *s;\r
+       char tmp[MAX_SIZE];\r
+       bool rpc_mode = false;\r
+       UINT port;\r
+       // 引数チェック\r
+       if (rc == NULL || rc->Rpc == NULL || rc->Rpc->Sock == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 接続\r
+       IPToStr(tmp, sizeof(tmp), &rc->Rpc->Sock->RemoteIP);\r
+       port = rc->Rpc->Sock->RemotePort;\r
+\r
+       s = Connect(tmp, port);\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       rpc_mode = Endian32(rpc_mode);\r
+       if (SendAll(s, &rpc_mode, sizeof(rpc_mode), false) == false)\r
+       {\r
+               ReleaseSock(s);\r
+               return NULL;\r
+       }\r
+\r
+       n = ZeroMalloc(sizeof(NOTIFY_CLIENT));\r
+       n->Sock = s;\r
+\r
+       return n;\r
+}\r
+\r
+// 通知クライアントを停止する\r
+void CcStopNotify(NOTIFY_CLIENT *n)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Disconnect(n->Sock);\r
+}\r
+\r
+// 通知クライアントを削除する\r
+void CcDisconnectNotify(NOTIFY_CLIENT *n)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 切断\r
+       Disconnect(n->Sock);\r
+       ReleaseSock(n->Sock);\r
+\r
+       // メモリ解放\r
+       Free(n);\r
+}\r
+\r
+// リモート接続を切断する\r
+void CcDisconnectRpc(REMOTE_CLIENT *rc)\r
+{\r
+       // 引数チェック\r
+       if (rc == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       RpcFree(rc->Rpc);\r
+       Free(rc);\r
+}\r
+\r
+// クライアントに接続しショートカット接続設定を起動する\r
+UINT CcShortcut(UCHAR *key)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (key == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       CcConnectRpcEx("localhost", NULL, NULL, NULL, key, &ret, false, 0);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続中のショートカット接続を切断する\r
+UINT CcShortcutDisconnect(UCHAR *key)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (key == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       CcConnectRpcEx("localhost", NULL, NULL, NULL, key, &ret, true, 0);\r
+\r
+       return ret;\r
+}\r
+\r
+// クライアントにリモート接続する\r
+REMOTE_CLIENT *CcConnectRpc(char *server_name, char *password, bool *bad_pass, bool *no_remote, UINT wait_retry)\r
+{\r
+       return CcConnectRpcEx(server_name, password, bad_pass, no_remote, NULL, NULL, false, wait_retry);\r
+}\r
+REMOTE_CLIENT *CcConnectRpcEx(char *server_name, char *password, bool *bad_pass, bool *no_remote, UCHAR *key, UINT *key_error_code, bool shortcut_disconnect, UINT wait_retry)\r
+{\r
+       SOCK *s;\r
+       UINT i;\r
+       UINT retcode;\r
+       UINT rpc_mode = CLIENT_RPC_MODE_MANAGEMENT;\r
+       RPC *rpc;\r
+       REMOTE_CLIENT *ret;\r
+       UCHAR hash_password[SHA1_SIZE];\r
+       UINT port_start;\r
+       UINT64 try_started = 0;\r
+       bool ok;\r
+       // 引数チェック\r
+       if (server_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (password == NULL)\r
+       {\r
+               password = "";\r
+       }\r
+\r
+       if (key_error_code != NULL)\r
+       {\r
+               *key_error_code = ERR_NO_ERROR;\r
+       }\r
+\r
+       if (bad_pass != NULL)\r
+       {\r
+               *bad_pass = false;\r
+       }\r
+\r
+       if (no_remote != NULL)\r
+       {\r
+               *no_remote = false;\r
+       }\r
+\r
+       port_start = CLIENT_CONFIG_PORT - 1;\r
+\r
+RETRY:\r
+       port_start++;\r
+\r
+       if (port_start >= (CLIENT_CONFIG_PORT + 5))\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ok = false;\r
+\r
+       while (true)\r
+       {\r
+               for (i = port_start;i < (CLIENT_CONFIG_PORT + 5);i++)\r
+               {\r
+                       if (CheckTCPPort(server_name, i))\r
+                       {\r
+                               ok = true;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               if (ok)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               if (wait_retry == 0)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               if (try_started == 0)\r
+               {\r
+                       try_started = Tick64();\r
+               }\r
+\r
+               if ((try_started + (UINT64)wait_retry) <= Tick64())\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (ok == false)\r
+       {\r
+               if (key_error_code)\r
+               {\r
+                       *key_error_code = ERR_CONNECT_FAILED;\r
+               }\r
+               return NULL;\r
+       }\r
+\r
+       port_start = i;\r
+\r
+       s = Connect(server_name, i);\r
+       if (s == NULL)\r
+       {\r
+               if (key_error_code)\r
+               {\r
+                       *key_error_code = ERR_CONNECT_FAILED;\r
+               }\r
+               goto RETRY;\r
+       }\r
+\r
+       Hash(hash_password, password, StrLen(password), true);\r
+\r
+       if (key != NULL)\r
+       {\r
+               if (shortcut_disconnect == false)\r
+               {\r
+                       rpc_mode = CLIENT_RPC_MODE_SHORTCUT;\r
+               }\r
+               else\r
+               {\r
+                       rpc_mode = CLIENT_RPC_MODE_SHORTCUT_DISCONNECT;\r
+               }\r
+       }\r
+\r
+       rpc_mode = Endian32(rpc_mode);\r
+       SendAdd(s, &rpc_mode, sizeof(UINT));\r
+\r
+       if (key != NULL)\r
+       {\r
+               SendAdd(s, key, SHA1_SIZE);\r
+       }\r
+       else\r
+       {\r
+               SendAdd(s, hash_password, SHA1_SIZE);\r
+       }\r
+\r
+       if (SendNow(s, false) == false)\r
+       {\r
+               ReleaseSock(s);\r
+               goto RETRY;\r
+       }\r
+\r
+       if (RecvAll(s, &retcode, sizeof(UINT), false) == false)\r
+       {\r
+               ReleaseSock(s);\r
+               goto RETRY;\r
+       }\r
+\r
+       retcode = Endian32(retcode);\r
+\r
+       if (retcode >= 1024)\r
+       {\r
+               goto RETRY;\r
+       }\r
+\r
+       if (key != NULL)\r
+       {\r
+               if (key_error_code)\r
+               {\r
+                       *key_error_code = retcode;\r
+               }\r
+               SendAll(s, &retcode, sizeof(UINT), false);\r
+               ReleaseSock(s);\r
+               return NULL;\r
+       }\r
+\r
+       switch (retcode)\r
+       {\r
+       case 1:\r
+               if (bad_pass != NULL)\r
+               {\r
+                       *bad_pass = true;\r
+               }\r
+               break;\r
+       case 2:\r
+               if (no_remote != NULL)\r
+               {\r
+                       *no_remote = true;\r
+               }\r
+               break;\r
+       }\r
+\r
+       if (retcode != 0)\r
+       {\r
+               ReleaseSock(s);\r
+               return NULL;\r
+       }\r
+\r
+       rpc = StartRpcClient(s, NULL);\r
+\r
+       ReleaseSock(s);\r
+\r
+       ret = ZeroMalloc(sizeof(REMOTE_CLIENT));\r
+       ret->Rpc = rpc;\r
+       rpc->Param = ret;\r
+\r
+       if (ret != NULL)\r
+       {\r
+               RPC_CLIENT_VERSION t;\r
+               Zero(&t, sizeof(t));\r
+               CcGetClientVersion(ret, &t);\r
+               ret->OsType = t.OsType;\r
+               ret->Unix = OS_IS_UNIX(ret->OsType);\r
+               ret->Win9x = OS_IS_WINDOWS_9X(ret->OsType);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// セッションから RPC_CLIENT_GET_CONNECTION_STATUS を取得\r
+void CiGetSessionStatus(RPC_CLIENT_GET_CONNECTION_STATUS *st, SESSION *s)\r
+{\r
+       // 引数チェック\r
+       if (st == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(s->lock);\r
+       {\r
+               // 動作フラグ\r
+               st->Active = true;\r
+\r
+               // セッションステータス\r
+               st->SessionStatus = s->ClientStatus;\r
+\r
+               // アカウント名\r
+               UniStrCpy(st->AccountName, sizeof(st->AccountName), s->ClientOption->AccountName);\r
+\r
+               if (s->ClientStatus == CLIENT_STATUS_ESTABLISHED && s->Connection != NULL)\r
+               {\r
+                       Lock(s->Connection->lock);\r
+                       {\r
+                               // 接続済みフラグ\r
+                               st->Connected = true;\r
+                               // 製品名\r
+                               StrCpy(st->ServerProductName, sizeof(st->ServerProductName), s->Connection->ServerStr);\r
+                               // バージョン\r
+                               st->ServerProductVer = s->Connection->ServerVer;\r
+                               // ビルド番号\r
+                               st->ServerProductBuild = s->Connection->ServerBuild;\r
+                               // サーバー証明書\r
+                               st->ServerX = CloneX(s->Connection->ServerX);\r
+                               // クライアント証明書\r
+                               st->ClientX = CloneX(s->Connection->ClientX);\r
+                               // このコネクションの接続完了時刻\r
+                               st->CurrentConnectionEstablishTime = TickToTime(s->CurrentConnectionEstablishTime);\r
+                               // 最大の TCP コネクション数\r
+                               st->MaxTcpConnections = s->MaxConnection;\r
+                               // ハーフコネクション\r
+                               st->HalfConnection = s->HalfConnection;\r
+                               // VLAN\r
+                               st->VLanId = s->VLanId;\r
+                               // VoIP / QoS\r
+                               st->QoS = s->QoS;\r
+                               if (s->Connection->Protocol == CONNECTION_TCP)\r
+                               {\r
+                                       UINT i;\r
+                                       // 現在の TCP コネクション数\r
+                                       LockList(s->Connection->Tcp->TcpSockList);\r
+                                       {\r
+                                               st->NumTcpConnections = LIST_NUM(s->Connection->Tcp->TcpSockList);\r
+                                               if (st->HalfConnection)\r
+                                               {\r
+                                                       for (i = 0;i < st->NumTcpConnections;i++)\r
+                                                       {\r
+                                                               TCPSOCK *ts = LIST_DATA(s->Connection->Tcp->TcpSockList, i);\r
+                                                               if (ts->Direction & TCP_SERVER_TO_CLIENT)\r
+                                                               {\r
+                                                                       st->NumTcpConnectionsDownload++;\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       st->NumTcpConnectionsUpload++;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       UnlockList(s->Connection->Tcp->TcpSockList);\r
+                               }\r
+                               // 暗号化の使用\r
+                               st->UseEncrypt = s->UseEncrypt;\r
+                               if (st->UseEncrypt)\r
+                               {\r
+                                       StrCpy(st->CipherName, sizeof(st->CipherName), s->Connection->CipherName);\r
+                               }\r
+                               // 圧縮の使用\r
+                               st->UseCompress = s->UseCompress;\r
+                               // セッションキー\r
+                               Copy(st->SessionKey, s->SessionKey, SHA1_SIZE);\r
+                               // ポリシー\r
+                               Copy(&st->Policy, s->Policy, sizeof(POLICY));\r
+                               // データサイズ\r
+                               if (s->ServerMode == false)\r
+                               {\r
+                                       st->TotalSendSize = s->TotalSendSize;\r
+                                       st->TotalRecvSize = s->TotalRecvSize;\r
+                                       st->TotalRecvSizeReal = s->TotalRecvSizeReal;\r
+                                       st->TotalSendSizeReal = s->TotalSendSizeReal;\r
+                               }\r
+                               else\r
+                               {\r
+                                       st->TotalSendSize = s->TotalRecvSize;\r
+                                       st->TotalRecvSize = s->TotalSendSize;\r
+                                       st->TotalRecvSizeReal = s->TotalSendSizeReal;\r
+                                       st->TotalSendSizeReal = s->TotalRecvSizeReal;\r
+                               }\r
+                               // セッション名\r
+                               StrCpy(st->SessionName, sizeof(st->SessionName), s->Name);\r
+                               // コネクション名\r
+                               StrCpy(st->ConnectionName, sizeof(st->ConnectionName), s->Connection->Name);\r
+                               // サーバー名\r
+                               StrCpy(st->ServerName, sizeof(st->ServerName), s->Connection->ServerName);\r
+                               // ポート番号\r
+                               st->ServerPort = s->Connection->ServerPort;\r
+                               // トラフィックデータ\r
+                               Lock(s->TrafficLock);\r
+                               {\r
+                                       Copy(&st->Traffic, s->Traffic, sizeof(TRAFFIC));\r
+                               }\r
+                               Unlock(s->TrafficLock);\r
+\r
+                               st->IsBridgeMode = s->IsBridgeMode;\r
+                               st->IsMonitorMode = s->IsMonitorMode;\r
+                       }\r
+                       Unlock(s->Connection->lock);\r
+               }\r
+               // 接続開始時刻\r
+               st->StartTime = TickToTime(s->CreatedTime);\r
+               // 最初のコネクションの接続完了時刻\r
+               st->FirstConnectionEstablisiedTime = TickToTime(s->FirstConnectionEstablisiedTime);\r
+               // これまでに確立したコネクション数\r
+               st->NumConnectionsEatablished = s->NumConnectionsEatablished;\r
+       }\r
+       Unlock(s->lock);\r
+}\r
+\r
+// 接続ステータスの取得\r
+bool CtGetAccountStatus(CLIENT *c, RPC_CLIENT_GET_CONNECTION_STATUS *st)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || st == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       LockList(c->AccountList);\r
+       {\r
+               ACCOUNT t, *r;\r
+\r
+               // アカウントを検索\r
+               t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), st->AccountName);\r
+\r
+               r = Search(c->AccountList, &t);\r
+               if (r == NULL)\r
+               {\r
+                       // 指定したアカウントは見つからない\r
+                       UnlockList(c->AccountList);\r
+\r
+                       Free(t.ClientOption);\r
+                       CiSetError(c, ERR_ACCOUNT_NOT_FOUND);\r
+                       return false;\r
+               }\r
+\r
+               Free(t.ClientOption);\r
+\r
+               Lock(r->lock);\r
+               {\r
+                       Zero(st, sizeof(RPC_CLIENT_GET_CONNECTION_STATUS));\r
+                       if (r->ClientSession != NULL)\r
+                       {\r
+                               SESSION *s = r->ClientSession;\r
+                               CiGetSessionStatus(st, s);\r
+                       }\r
+               }\r
+               Unlock(r->lock);\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+       return true;\r
+}\r
+\r
+// 接続ステータスの解放\r
+void CiFreeClientGetConnectionStatus(RPC_CLIENT_GET_CONNECTION_STATUS *st)\r
+{\r
+       // 引数チェック\r
+       if (st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (st->ServerX != NULL)\r
+       {\r
+               FreeX(st->ServerX);\r
+       }\r
+\r
+       if (st->ClientX != NULL)\r
+       {\r
+               FreeX(st->ClientX);\r
+       }\r
+}\r
+\r
+// サーバー証明書の確認プロシージャ\r
+bool CiCheckCertProc(SESSION *s, CONNECTION *c, X *server_x, bool *expired)\r
+{\r
+#ifdef OS_WIN32\r
+       ACCOUNT *a;\r
+       X *old_x = NULL;\r
+       UI_CHECKCERT dlg;\r
+       // 引数チェック\r
+       if (s == NULL || c == NULL || server_x == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (expired != NULL)\r
+       {\r
+               *expired = false;\r
+       }\r
+\r
+       Zero(&dlg, sizeof(dlg));\r
+\r
+       a = s->Account;\r
+       if (a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(a->lock);\r
+       {\r
+               if (a->CheckServerCert == false)\r
+               {\r
+                       // サーバー証明書を検証しない\r
+                       Unlock(a->lock);\r
+                       return true;\r
+               }\r
+\r
+               if (a->ServerCert != NULL)\r
+               {\r
+                       old_x = CloneX(a->ServerCert);\r
+               }\r
+       }\r
+       Unlock(a->lock);\r
+\r
+       if (CheckXDateNow(server_x) == false)\r
+       {\r
+               // 有効期限が切れている\r
+               if (old_x != NULL)\r
+               {\r
+                       FreeX(old_x);\r
+               }\r
+\r
+               if (expired != NULL)\r
+               {\r
+                       *expired = true;\r
+               }\r
+\r
+               return false;\r
+       }\r
+\r
+       if (old_x != NULL)\r
+       {\r
+               if (CompareX(old_x, server_x))\r
+               {\r
+                       // すでに登録されている証明書と完全一致した\r
+                       if (old_x != NULL)\r
+                       {\r
+                               FreeX(old_x);\r
+                       }\r
+                       return true;\r
+               }\r
+               else\r
+               {\r
+                       dlg.DiffWarning = true;\r
+               }\r
+       }\r
+\r
+       // この証明書は信頼できないのでダイアログボックスを出して確認する\r
+       UniStrCpy(dlg.AccountName, sizeof(dlg.AccountName), a->ClientOption->AccountName);\r
+       StrCpy(dlg.ServerName, sizeof(dlg.ServerName), a->ClientOption->Hostname);\r
+       dlg.x = server_x;\r
+       dlg.old_x = old_x;\r
+       \r
+       dlg.Session = s;\r
+       AddRef(s->ref);\r
+\r
+       CncCheckCert(s, &dlg);\r
+\r
+       ReleaseSession(s);\r
+\r
+       if (old_x != NULL)\r
+       {\r
+               FreeX(old_x);\r
+       }\r
+\r
+       if (dlg.Ok && dlg.SaveServerCert)\r
+       {\r
+               // このサーバー証明書を保存し次回から信頼する\r
+               Lock(a->lock);\r
+               {\r
+                       if (a->ServerCert != NULL)\r
+                       {\r
+                               FreeX(a->ServerCert);\r
+                       }\r
+\r
+                       a->ServerCert = CloneX(server_x);\r
+               }\r
+               Unlock(a->lock);\r
+               CiSaveConfigurationFile(s->Cedar->Client);\r
+       }\r
+\r
+       return dlg.Ok;\r
+#else  // OS_WIN32\r
+       ACCOUNT *a;\r
+       X *old_x = NULL;\r
+       // 引数チェック\r
+       if (s == NULL || c == NULL || server_x == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (expired != NULL)\r
+       {\r
+               *expired = false;\r
+       }\r
+\r
+       a = s->Account;\r
+       if (a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(a->lock);\r
+       {\r
+               if (a->CheckServerCert == false)\r
+               {\r
+                       // サーバー証明書を検証しない\r
+                       Unlock(a->lock);\r
+                       return true;\r
+               }\r
+\r
+               if (a->ServerCert != NULL)\r
+               {\r
+                       old_x = CloneX(a->ServerCert);\r
+               }\r
+       }\r
+       Unlock(a->lock);\r
+\r
+       if (CheckXDateNow(server_x) == false)\r
+       {\r
+               // 有効期限が切れている\r
+               if (old_x != NULL)\r
+               {\r
+                       FreeX(old_x);\r
+               }\r
+\r
+               if (expired != NULL)\r
+               {\r
+                       *expired = true;\r
+               }\r
+\r
+               return false;\r
+       }\r
+\r
+       if (old_x != NULL)\r
+       {\r
+               if (CompareX(old_x, server_x))\r
+               {\r
+                       // すでに登録されている証明書と完全一致した\r
+                       if (old_x != NULL)\r
+                       {\r
+                               FreeX(old_x);\r
+                       }\r
+                       return true;\r
+               }\r
+               else\r
+               {\r
+                       // 不一致\r
+                       if (old_x != NULL)\r
+                       {\r
+                               FreeX(old_x);\r
+                       }\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       if (old_x != NULL)\r
+       {\r
+               FreeX(old_x);\r
+       }\r
+\r
+       return false;\r
+#endif // OS_WIN32\r
+}\r
+\r
+// セキュアデバイスを使用した署名プロシージャ\r
+bool CiSecureSignProc(SESSION *s, CONNECTION *c, SECURE_SIGN *sign)\r
+{\r
+       // Win32 の場合は UI を使用することができる\r
+       return CncSecureSignDlg(sign);\r
+}\r
+\r
+#ifdef OS_WIN32\r
+// 署名プロシージャ (Win32 用)\r
+bool Win32CiSecureSign(SECURE_SIGN *sign)\r
+{\r
+       bool ret = false;\r
+       BUF *random;\r
+       // 引数チェック\r
+       if (sign == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       random = NewBuf();\r
+       WriteBuf(random, sign->Random, SHA1_SIZE);\r
+\r
+       // バッチ処理\r
+       {\r
+               WINUI_SECURE_BATCH batch[] =\r
+               {\r
+                       {WINUI_SECURE_READ_CERT, sign->SecurePublicCertName, true, NULL, NULL, NULL, NULL, NULL, NULL},\r
+                       {WINUI_SECURE_SIGN_WITH_KEY, sign->SecurePrivateKeyName, true, random, NULL, NULL, NULL, NULL, NULL}\r
+               };\r
+\r
+               if (SecureDeviceWindow(NULL, batch, sizeof(batch) / sizeof(batch[0]),\r
+                       sign->UseSecureDeviceId, sign->BitmapId) == false)\r
+               {\r
+                       // 失敗\r
+                       if (batch[0].OutputX != 0)\r
+                       {\r
+                               FreeX(batch[0].OutputX);\r
+                       }\r
+                       ret = false;\r
+               }\r
+               else\r
+               {\r
+                       // 成功\r
+                       ret = true;\r
+                       sign->ClientCert = batch[0].OutputX;\r
+                       Copy(sign->Signature, batch[1].OutputSign, 128);\r
+               }\r
+       }\r
+\r
+       FreeBuf(random);\r
+\r
+       return ret;\r
+}\r
+#endif // OS_WIN32\r
+\r
+// 切断\r
+bool CtDisconnect(CLIENT *c, RPC_CLIENT_CONNECT *connect)\r
+{\r
+       bool ret = false;\r
+       ACCOUNT t, *r;\r
+       SESSION *s = NULL;\r
+       // 引数チェック\r
+       if (c == NULL || connect == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       LockList(c->AccountList);\r
+       {\r
+\r
+               // アカウントを検索\r
+               t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), connect->AccountName);\r
+\r
+               r = Search(c->AccountList, &t);\r
+               if (r == NULL)\r
+               {\r
+                       // 指定したアカウントは見つからない\r
+                       UnlockList(c->AccountList);\r
+\r
+                       Free(t.ClientOption);\r
+                       CiSetError(c, ERR_ACCOUNT_NOT_FOUND);\r
+                       return false;\r
+               }\r
+\r
+               Free(t.ClientOption);\r
+\r
+               Lock(r->lock);\r
+               {\r
+                       if (r->ClientSession == NULL)\r
+                       {\r
+                               // 接続していない\r
+                               CiSetError(c, ERR_ACCOUNT_INACTIVE);\r
+                       }\r
+                       else\r
+                       {\r
+                               s = r->ClientSession;\r
+                               AddRef(s->ref);\r
+                               // 切断完了\r
+                               r->ClientSession = NULL;\r
+                               ret = true;\r
+                       }\r
+               }\r
+               Unlock(r->lock);\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+       if (s != NULL)\r
+       {\r
+               // 接続を切断 (切断完了まで待機)\r
+               CLog(c, "LC_DISCONNECT", connect->AccountName);\r
+               StopSession(s);\r
+               ReleaseSession(s);\r
+       }\r
+\r
+       if (ret != false)\r
+       {\r
+               CiNotify(c);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続\r
+bool CtConnect(CLIENT *c, RPC_CLIENT_CONNECT *connect)\r
+{\r
+       bool ret = false;\r
+       RPC_CLIENT_ENUM_VLAN t;\r
+       // 引数チェック\r
+       if (c == NULL || connect == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(c->lockForConnect);\r
+       {\r
+               Zero(&t, sizeof(t));\r
+               if (CtEnumVLan(c, &t))\r
+               {\r
+                       if (t.NumItem == 0)\r
+                       {\r
+                               // システムに仮想 LAN カードが 1 枚も無い\r
+                               if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType) || OS_IS_UNIX(GetOsInfo()->OsType))\r
+                               {\r
+                                       // Windows NT 系または Linux 系の場合のみ、自動的に "VPN" という名前の\r
+                                       // 新しい仮想 LAN カードを作成する\r
+                                       RPC_CLIENT_CREATE_VLAN t;\r
+\r
+                                       Zero(&t, sizeof(t));\r
+                                       StrCpy(t.DeviceName, sizeof(t.DeviceName), "VPN");\r
+                                       CtCreateVLan(c,  &t);\r
+                               }\r
+                       }\r
+\r
+                       CiFreeClientEnumVLan(&t);\r
+               }\r
+       }\r
+       Unlock(c->lockForConnect);\r
+\r
+       CiNormalizeAccountVLan(c);\r
+\r
+       LockList(c->AccountList);\r
+       {\r
+               ACCOUNT t, *r;\r
+               bool unix_disabled = false;\r
+\r
+               // アカウントを検索\r
+               t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), connect->AccountName);\r
+\r
+               r = Search(c->AccountList, &t);\r
+               if (r == NULL)\r
+               {\r
+                       // 指定したアカウントは見つからない\r
+                       UnlockList(c->AccountList);\r
+\r
+                       Free(t.ClientOption);\r
+                       CiSetError(c, ERR_ACCOUNT_NOT_FOUND);\r
+                       return false;\r
+               }\r
+\r
+               Free(t.ClientOption);\r
+\r
+#ifndef        OS_WIN32\r
+               // 仮想 LAN カードを検索する\r
+               LockList(c->UnixVLanList);\r
+               {\r
+                       UNIX_VLAN *v, t;\r
+\r
+                       Zero(&t, sizeof(t));\r
+                       StrCpy(t.Name, sizeof(t.Name), r->ClientOption->DeviceName);\r
+\r
+                       v = Search(c->UnixVLanList, &t);\r
+                       if (v == NULL)\r
+                       {\r
+                               UnlockList(c->UnixVLanList);\r
+                               CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+                               return false;\r
+                       }\r
+\r
+                       unix_disabled = v->Enabled ? false : true;\r
+               }\r
+               UnlockList(c->UnixVLanList);\r
+#endif // OS_WIN32\r
+\r
+               Lock(r->lock);\r
+               {\r
+                       bool already_used = false;\r
+                       UINT i;\r
+\r
+                       if (r->ClientSession != NULL)\r
+                       {\r
+                               // すでに接続中\r
+                               CiSetError(c, ERR_ACCOUNT_ACTIVE);\r
+                       }\r
+                       else if (r->ClientAuth->AuthType == CLIENT_AUTHTYPE_SECURE &&\r
+                               client->UseSecureDeviceId == 0)\r
+                       {\r
+                               // セキュアデバイスが指定されていない\r
+                               CiSetError(c, ERR_NO_SECURE_DEVICE_SPECIFIED);\r
+                       }\r
+#ifdef OS_WIN32\r
+                       else if (MsIsVLanExists(VLAN_ADAPTER_NAME_TAG, r->ClientOption->DeviceName) == false)\r
+                       {\r
+                               // 仮想 LAN カードが見つからない\r
+                               CiSetError(c, ERR_VLAN_FOR_ACCOUNT_NOT_FOUND);\r
+                               CiNotify(c);\r
+                       }\r
+                       else if (MsIsVLanEnabled(r->ClientOption->DeviceName) == false)\r
+                       {\r
+                               // 仮想 LAN カードは無効化されている\r
+                               CiSetError(c, ERR_VLAN_FOR_ACCOUNT_DISABLED);\r
+                               CiNotify(c);\r
+                       }\r
+#else  // OS_WIN32\r
+                       else if (unix_disabled)\r
+                       {\r
+                               // 仮想 LAN カードは無効化されている\r
+                               CiSetError(c, ERR_VLAN_FOR_ACCOUNT_DISABLED);\r
+                               CiNotify(c);\r
+                       }\r
+#endif // OS_WIN32\r
+                       else\r
+                       {\r
+                               // 仮想 LAN カードがすでに別のアカウントで使用されているかどうか調べる\r
+                               for (i = 0;i < LIST_NUM(c->AccountList);i++)\r
+                               {\r
+                                       ACCOUNT *a = LIST_DATA(c->AccountList, i);\r
+                                       if (a != r)\r
+                                       {\r
+                                               if (StrCmpi(a->ClientOption->DeviceName,\r
+                                                       r->ClientOption->DeviceName) == 0)\r
+                                               {\r
+                                                       if (a->ClientSession != NULL)\r
+                                                       {\r
+                                                               already_used = true;\r
+                                                               break;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               if (already_used)\r
+                               {\r
+                                       CiSetError(c, ERR_VLAN_FOR_ACCOUNT_USED);\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 接続を開始\r
+                                       PACKET_ADAPTER *pa = VLanGetPacketAdapter();\r
+\r
+                                       if (r->ClientAuth->AuthType == CLIENT_AUTHTYPE_SECURE)\r
+                                       {\r
+                                               // セキュアデバイス認証のためのプロシージャを登録する\r
+                                               r->ClientAuth->SecureSignProc = CiSecureSignProc;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               r->ClientAuth->SecureSignProc = NULL;\r
+                                       }\r
+\r
+                                       if (r->CheckServerCert)\r
+                                       {\r
+                                               // サーバー証明書確認のためのプロシージャを登録する\r
+                                               r->ClientAuth->CheckCertProc = CiCheckCertProc;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               r->ClientAuth->CheckCertProc = NULL;\r
+                                       }\r
+\r
+                                       r->StatusPrinter = CiClientStatusPrinter;\r
+                                       r->LastConnectDateTime = SystemTime64();\r
+\r
+                                       CLog(c, "LC_CONNECT", connect->AccountName);\r
+\r
+                                       r->ClientSession = NewClientSessionEx(c->Cedar, r->ClientOption, r->ClientAuth, pa, r);\r
+                                       Notify(r->ClientSession, CLIENT_NOTIFY_ACCOUNT_CHANGED);\r
+\r
+                                       ret = true;\r
+                               }\r
+                       }\r
+               }\r
+               Unlock(r->lock);\r
+\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+       CiSaveConfigurationFile(c);\r
+\r
+       return ret;\r
+}\r
+\r
+// アカウント情報の取得\r
+bool CtGetAccount(CLIENT *c, RPC_CLIENT_GET_ACCOUNT *a)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       LockList(c->AccountList);\r
+       {\r
+               ACCOUNT t, *r;\r
+\r
+               // アカウントを検索\r
+               t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), a->AccountName);\r
+\r
+               r = Search(c->AccountList, &t);\r
+               if (r == NULL)\r
+               {\r
+                       // 指定したアカウントは見つからない\r
+                       UnlockList(c->AccountList);\r
+\r
+                       Free(t.ClientOption);\r
+                       CiSetError(c, ERR_ACCOUNT_NOT_FOUND);\r
+                       return false;\r
+               }\r
+\r
+               Free(t.ClientOption);\r
+\r
+               Lock(r->lock);\r
+               {\r
+                       // クライアントオプションをコピー\r
+                       if (a->ClientOption != NULL)\r
+                       {\r
+                               Free(a->ClientOption);\r
+                       }\r
+                       a->ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+                       Copy(a->ClientOption, r->ClientOption, sizeof(CLIENT_OPTION));\r
+\r
+                       // 認証データをコピー\r
+                       if (a->ClientAuth != NULL)\r
+                       {\r
+                               CiFreeClientAuth(a->ClientAuth);\r
+                       }\r
+                       a->ClientAuth = CopyClientAuth(r->ClientAuth);\r
+\r
+                       a->StartupAccount = r->StartupAccount;\r
+\r
+                       a->CheckServerCert = r->CheckServerCert;\r
+                       a->ServerCert = NULL;\r
+                       if (r->ServerCert != NULL)\r
+                       {\r
+                               a->ServerCert = CloneX(r->ServerCert);\r
+                       }\r
+\r
+                       // ショートカットキー\r
+                       Copy(a->ShortcutKey, r->ShortcutKey, SHA1_SIZE);\r
+\r
+                       a->CreateDateTime = r->CreateDateTime;\r
+                       a->LastConnectDateTime = r->LastConnectDateTime;\r
+                       a->UpdateDateTime = r->UpdateDateTime;\r
+               }\r
+               Unlock(r->lock);\r
+\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+       return true;\r
+}\r
+\r
+// アカウント名の変更\r
+bool CtRenameAccount(CLIENT *c, RPC_RENAME_ACCOUNT *rename)\r
+{\r
+       bool ret;\r
+       // 引数チェック\r
+       if (c == NULL || rename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = false;\r
+\r
+       if (UniStrCmp(rename->NewName, rename->OldName) == 0)\r
+       {\r
+               // 名前が変更されていない\r
+               return true;\r
+       }\r
+\r
+       LockList(c->AccountList);\r
+       {\r
+               ACCOUNT t, *r, *r2;\r
+\r
+               if (UniStrLen(rename->NewName) == 0)\r
+               {\r
+                       // 名前が不正\r
+                       CiSetError(c, ERR_INVALID_VALUE);\r
+                       UnlockList(c->AccountList);\r
+                       return false;\r
+               }\r
+\r
+               // 古いアカウント名を検索\r
+               t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), rename->OldName);\r
+\r
+               r = Search(c->AccountList, &t);\r
+               if (r == NULL)\r
+               {\r
+                       // 指定したアカウントは見つからない\r
+                       UnlockList(c->AccountList);\r
+\r
+                       Free(t.ClientOption);\r
+                       CiSetError(c, ERR_ACCOUNT_NOT_FOUND);\r
+                       return false;\r
+               }\r
+\r
+               Free(t.ClientOption);\r
+\r
+               // 新しいアカウント名を検索\r
+               t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), rename->NewName);\r
+\r
+               r2 = Search(c->AccountList, &t);\r
+               if (r2 != NULL)\r
+               {\r
+                       // 指定した名前のアカウントはすでに存在する\r
+                       UnlockList(c->AccountList);\r
+\r
+                       Free(t.ClientOption);\r
+                       CiSetError(c, ERR_ACCOUNT_ALREADY_EXISTS);\r
+                       return false;\r
+               }\r
+\r
+               Free(t.ClientOption);\r
+\r
+               Lock(r->lock);\r
+               {\r
+                       // アカウントの動作状態チェック\r
+                       if (r->ClientSession != NULL)\r
+                       {\r
+                               // アカウントは動作中\r
+                               Unlock(r->lock);\r
+                               UnlockList(c->AccountList);\r
+                               CiSetError(c, ERR_ACCOUNT_ACTIVE);\r
+\r
+                               return false;\r
+                       }\r
+\r
+                       // アカウント名を更新\r
+                       UniStrCpy(r->ClientOption->AccountName, sizeof(r->ClientOption->AccountName),\r
+                               rename->NewName);\r
+\r
+                       CLog(c, "LC_RENAME_ACCOUNT", rename->OldName, rename->NewName);\r
+\r
+                       ret = true;\r
+               }\r
+               Unlock(r->lock);\r
+\r
+               Sort(c->AccountList);\r
+\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+       CiSaveConfigurationFile(c);\r
+\r
+       CiNotify(c);\r
+\r
+       return ret;\r
+}\r
+\r
+// クライアント設定の設定\r
+bool CtSetClientConfig(CLIENT *c, CLIENT_CONFIG *o)\r
+{\r
+       KEEP *k;\r
+       // 引数チェック\r
+       if (c == NULL || o == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (o->UseKeepConnect)\r
+       {\r
+               if (IsEmptyStr(o->KeepConnectHost) ||\r
+                       o->KeepConnectPort == 0 ||\r
+                       o->KeepConnectPort >= 65536)\r
+               {\r
+                       CiSetError(c, ERR_INVALID_PARAMETER);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       Lock(c->lock);\r
+       {\r
+               Copy(&c->Config, o, sizeof(CLIENT_CONFIG));\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       // 設定の保存\r
+       CiSaveConfigurationFile(c);\r
+\r
+       // Keep Connect の適用\r
+       k = c->Keep;\r
+       Lock(k->lock);\r
+       {\r
+               if (o->UseKeepConnect)\r
+               {\r
+                       StrCpy(k->ServerName, sizeof(k->ServerName), c->Config.KeepConnectHost);\r
+                       k->ServerPort = c->Config.KeepConnectPort;\r
+                       k->Interval = c->Config.KeepConnectInterval * 1000;\r
+                       k->UdpMode = (c->Config.KeepConnectProtocol == CONNECTION_UDP) ? true : false;\r
+                       k->Enable = true;\r
+               }\r
+               else\r
+               {\r
+                       k->Enable = false;\r
+               }\r
+       }\r
+       Unlock(k->lock);\r
+\r
+       return true;\r
+}\r
+\r
+// ククライアント設定の取得\r
+bool CtGetClientConfig(CLIENT *c, CLIENT_CONFIG *o)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || o == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(c->lock);\r
+       {\r
+               Copy(o, &c->Config, sizeof(CLIENT_CONFIG));\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       return true;\r
+}\r
+\r
+// アカウントのスタートアップ属性を解除する\r
+bool CtRemoveStartupAccount(CLIENT *c, RPC_CLIENT_DELETE_ACCOUNT *a)\r
+{\r
+       bool ret;\r
+       // 引数チェック\r
+       if (c == NULL || a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = false;\r
+\r
+       LockList(c->AccountList);\r
+       {\r
+               ACCOUNT t, *r;\r
+               // アカウントの検索\r
+\r
+               t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), a->AccountName);\r
+\r
+               r = Search(c->AccountList, &t);\r
+               if (r == NULL)\r
+               {\r
+                       // 指定したアカウントは見つからない\r
+                       UnlockList(c->AccountList);\r
+\r
+                       Free(t.ClientOption);\r
+                       CiSetError(c, ERR_ACCOUNT_NOT_FOUND);\r
+                       return false;\r
+               }\r
+\r
+               Free(t.ClientOption);\r
+\r
+               Lock(r->lock);\r
+               {\r
+                       // スタートアップアカウントを解除する\r
+                       ret = true;\r
+                       r->StartupAccount = false;\r
+               }\r
+               Unlock(r->lock);\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+       if (ret)\r
+       {\r
+               CiSaveConfigurationFile(c);\r
+               CiNotify(c);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// アカウントをスタートアップアカウントにする\r
+bool CtSetStartupAccount(CLIENT *c, RPC_CLIENT_DELETE_ACCOUNT *a)\r
+{\r
+       bool ret;\r
+       // 引数チェック\r
+       if (c == NULL || a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = false;\r
+\r
+       LockList(c->AccountList);\r
+       {\r
+               ACCOUNT t, *r;\r
+               // アカウントの検索\r
+\r
+               t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), a->AccountName);\r
+\r
+               r = Search(c->AccountList, &t);\r
+               if (r == NULL)\r
+               {\r
+                       // 指定したアカウントは見つからない\r
+                       UnlockList(c->AccountList);\r
+\r
+                       Free(t.ClientOption);\r
+                       CiSetError(c, ERR_ACCOUNT_NOT_FOUND);\r
+                       return false;\r
+               }\r
+\r
+               Free(t.ClientOption);\r
+\r
+               Lock(r->lock);\r
+               {\r
+                       // スタートアップアカウントにする\r
+                       ret = true;\r
+                       r->StartupAccount = true;\r
+               }\r
+               Unlock(r->lock);\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+       if (ret)\r
+       {\r
+               CiSaveConfigurationFile(c);\r
+               CiNotify(c);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// アカウントの削除\r
+bool CtDeleteAccount(CLIENT *c, RPC_CLIENT_DELETE_ACCOUNT *a)\r
+{\r
+       bool ret;\r
+       // 引数チェック\r
+       if (c == NULL || a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = false;\r
+\r
+       LockList(c->AccountList);\r
+       {\r
+               ACCOUNT t, *r;\r
+               // アカウントの検索\r
+\r
+               t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), a->AccountName);\r
+\r
+               r = Search(c->AccountList, &t);\r
+               if (r == NULL)\r
+               {\r
+                       // 指定したアカウントは見つからない\r
+                       UnlockList(c->AccountList);\r
+\r
+                       Free(t.ClientOption);\r
+                       CiSetError(c, ERR_ACCOUNT_NOT_FOUND);\r
+                       return false;\r
+               }\r
+\r
+               Free(t.ClientOption);\r
+\r
+               Lock(r->lock);\r
+               {\r
+                       // アカウントの動作状態チェック\r
+                       if (r->ClientSession != NULL)\r
+                       {\r
+                               // アカウントは動作中\r
+                               Unlock(r->lock);\r
+                               UnlockList(c->AccountList);\r
+                               CiSetError(c, ERR_ACCOUNT_ACTIVE);\r
+\r
+                               return false;\r
+                       }\r
+\r
+                       // このアカウントをリストから削除する\r
+                       Delete(c->AccountList, r);\r
+               }\r
+               Unlock(r->lock);\r
+\r
+               // このアカウントのメモリを解放する\r
+               CiFreeAccount(r);\r
+\r
+               CLog(c, "LC_DELETE_ACCOUNT", a->AccountName);\r
+               ret = true;\r
+\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+       if (ret)\r
+       {\r
+               CiSaveConfigurationFile(c);\r
+               CiNotify(c);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// アカウントの列挙\r
+bool CtEnumAccount(CLIENT *c, RPC_CLIENT_ENUM_ACCOUNT *e)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       LockList(c->AccountList);\r
+       {\r
+               UINT i;\r
+               // アカウント件数\r
+               e->NumItem = LIST_NUM(c->AccountList);\r
+               e->Items = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_ACCOUNT_ITEM *) * e->NumItem);\r
+\r
+               for (i = 0;i < e->NumItem;i++)\r
+               {\r
+                       ACCOUNT *a = LIST_DATA(c->AccountList, i);\r
+                       RPC_CLIENT_ENUM_ACCOUNT_ITEM *item = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_ACCOUNT_ITEM));\r
+                       e->Items[i] = item;\r
+\r
+                       // アカウント名\r
+                       UniStrCpy(item->AccountName, sizeof(item->AccountName), a->ClientOption->AccountName);\r
+\r
+                       // ユーザー名\r
+                       StrCpy(item->UserName, sizeof(item->UserName), a->ClientAuth->Username);\r
+\r
+                       // サーバー名\r
+                       StrCpy(item->ServerName, sizeof(item->ServerName), a->ClientOption->Hostname);\r
+\r
+                       // プロキシ種類\r
+                       item->ProxyType = a->ClientOption->ProxyType;\r
+\r
+                       // デバイス名\r
+                       StrCpy(item->DeviceName, sizeof(item->DeviceName), a->ClientOption->DeviceName);\r
+\r
+                       // プロキシ情報\r
+                       if (item->ProxyType != PROXY_DIRECT)\r
+                       {\r
+                               StrCpy(item->ProxyName, sizeof(item->ProxyName), a->ClientOption->ProxyName);\r
+                       }\r
+\r
+                       // スタートアップ\r
+                       item->StartupAccount = a->StartupAccount;\r
+\r
+                       // 動作フラグ\r
+                       item->Active = (a->ClientSession == NULL ? false : true);\r
+\r
+                       // 接続フラグ\r
+                       item->Connected = (item->Active == false) ? false : a->ClientSession->ConnectSucceed;\r
+\r
+                       // ポート番号\r
+                       item->Port = a->ClientOption->Port;\r
+\r
+                       // 仮想 HUB 名\r
+                       StrCpy(item->HubName, sizeof(item->HubName), a->ClientOption->HubName);\r
+\r
+                       item->CreateDateTime = a->CreateDateTime;\r
+                       item->LastConnectDateTime = a->LastConnectDateTime;\r
+                       item->UpdateDateTime = a->UpdateDateTime;\r
+               }\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+       return true;\r
+}\r
+\r
+// アカウントの設定\r
+bool CtSetAccount(CLIENT *c, RPC_CLIENT_CREATE_ACCOUNT *a)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 既存のアカウントが存在するかどうかチェック\r
+       LockList(c->AccountList);\r
+       {\r
+               ACCOUNT t, *ret;\r
+               t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName),\r
+                       a->ClientOption->AccountName);\r
+\r
+               ret = Search(c->AccountList, &t);\r
+               if (ret == NULL)\r
+               {\r
+                       // 存在しない\r
+                       UnlockList(c->AccountList);\r
+                       Free(t.ClientOption);\r
+\r
+                       CiSetError(c, ERR_ACCOUNT_NOT_FOUND);\r
+\r
+                       return false;\r
+               }\r
+               Free(t.ClientOption);\r
+\r
+               if (a->ClientAuth->AuthType == CLIENT_AUTHTYPE_CERT)\r
+               {\r
+                       if (a->ClientAuth->ClientX == NULL ||\r
+                               a->ClientAuth->ClientX->is_compatible_bit == false ||\r
+                               a->ClientAuth->ClientK == NULL)\r
+                       {\r
+                               // クライアント証明書が不正\r
+                               UnlockList(c->AccountList);\r
+                               CiSetError(c, ERR_NOT_RSA_1024);\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               if (a->ServerCert != NULL && a->ServerCert->is_compatible_bit == false)\r
+               {\r
+                       // サーバー証明書が不正\r
+                       UnlockList(c->AccountList);\r
+                       CiSetError(c, ERR_NOT_RSA_1024);\r
+                       return false;\r
+               }\r
+\r
+               Lock(ret->lock);\r
+               {\r
+\r
+#if    0\r
+                       // 現在のバージョンではアカウント動作中でも設定の書き換えは行われる\r
+                       // (ただし次回接続時まで設定は適用されない)\r
+                       if (ret->ClientSession != NULL)\r
+                       {\r
+                               // アカウントが動作中である\r
+                               Unlock(ret->lock);\r
+                               UnlockList(c->AccountList);\r
+\r
+                               CiSetError(c, ERR_ACCOUNT_ACTIVE);\r
+\r
+                               return false;\r
+                       }\r
+#endif\r
+\r
+                       // クライアント認証データの削除\r
+                       CiFreeClientAuth(ret->ClientAuth);\r
+\r
+                       // クライアント認証データのコピー\r
+                       ret->ClientAuth = CopyClientAuth(a->ClientAuth);\r
+\r
+                       // クライアントオプションの削除\r
+                       Free(ret->ClientOption);\r
+\r
+                       // クライアントオプションのコピー\r
+                       ret->ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+                       Copy(ret->ClientOption, a->ClientOption, sizeof(CLIENT_OPTION));\r
+\r
+                       ret->StartupAccount = a->StartupAccount;\r
+\r
+                       ret->CheckServerCert = a->CheckServerCert;\r
+\r
+                       if (a->ServerCert != NULL)\r
+                       {\r
+                               if (ret->ServerCert != NULL)\r
+                               {\r
+                                       FreeX(ret->ServerCert);\r
+                               }\r
+                               ret->ServerCert = CloneX(a->ServerCert);\r
+                       }\r
+                       else\r
+                       {\r
+                               if (ret->ServerCert != NULL)\r
+                               {\r
+                                       FreeX(ret->ServerCert);\r
+                               }\r
+                               ret->ServerCert = false;\r
+                       }\r
+\r
+                       ret->UpdateDateTime = SystemTime64();\r
+               }\r
+               Unlock(ret->lock);\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+       CiSaveConfigurationFile(c);\r
+\r
+       CiNotify(c);\r
+\r
+       return true;\r
+}\r
+\r
+// アカウントの作成\r
+bool CtCreateAccount(CLIENT *c, RPC_CLIENT_CREATE_ACCOUNT *a)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 既存のアカウントが存在するかどうかチェック\r
+       LockList(c->AccountList);\r
+       {\r
+               ACCOUNT t, *ret, *new_account;\r
+               t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName),\r
+                       a->ClientOption->AccountName);\r
+\r
+               ret = Search(c->AccountList, &t);\r
+               if (ret != NULL)\r
+               {\r
+                       // すでに存在する\r
+                       UnlockList(c->AccountList);\r
+                       Free(t.ClientOption);\r
+\r
+                       CiSetError(c, ERR_ACCOUNT_ALREADY_EXISTS);\r
+\r
+                       return false;\r
+               }\r
+\r
+               Free(t.ClientOption);\r
+\r
+               if (UniStrLen(a->ClientOption->AccountName) == 0)\r
+               {\r
+                       // 名前が不正\r
+                       UnlockList(c->AccountList);\r
+                       CiSetError(c, ERR_INVALID_VALUE);\r
+                       return false;\r
+               }\r
+\r
+               if (a->ClientAuth->AuthType == CLIENT_AUTHTYPE_CERT)\r
+               {\r
+                       if (a->ClientAuth->ClientX == NULL ||\r
+                               a->ClientAuth->ClientX->is_compatible_bit == false ||\r
+                               a->ClientAuth->ClientK == NULL)\r
+                       {\r
+                               // クライアント証明書が不正\r
+                               UnlockList(c->AccountList);\r
+                               CiSetError(c, ERR_NOT_RSA_1024);\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               if (a->ServerCert != NULL && a->ServerCert->is_compatible_bit == false)\r
+               {\r
+                       // サーバー証明書が不正\r
+                       UnlockList(c->AccountList);\r
+                       CiSetError(c, ERR_NOT_RSA_1024);\r
+                       return false;\r
+               }\r
+\r
+               // 新しいアカウントを追加する\r
+               new_account = ZeroMalloc(sizeof(ACCOUNT));\r
+               new_account->lock = NewLock();\r
+\r
+               // クライアント認証データのコピー\r
+               new_account->ClientAuth = CopyClientAuth(a->ClientAuth);\r
+\r
+               // クライアントオプションのコピー\r
+               new_account->ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               Copy(new_account->ClientOption, a->ClientOption, sizeof(CLIENT_OPTION));\r
+\r
+               new_account->StartupAccount = a->StartupAccount;\r
+\r
+               new_account->CheckServerCert = a->CheckServerCert;\r
+               if (a->ServerCert != NULL)\r
+               {\r
+                       new_account->ServerCert = CloneX(a->ServerCert);\r
+               }\r
+\r
+               // ショートカットキー\r
+               if (IsZero(a->ShortcutKey, SHA1_SIZE))\r
+               {\r
+                       Rand(new_account->ShortcutKey, SHA1_SIZE);\r
+               }\r
+               else\r
+               {\r
+                       Copy(new_account->ShortcutKey, a->ShortcutKey, SHA1_SIZE);\r
+               }\r
+\r
+               new_account->CreateDateTime = new_account->UpdateDateTime = SystemTime64();\r
+\r
+               // リストに挿入する\r
+               Insert(c->AccountList, new_account);\r
+\r
+               CLog(c, "LC_NEW_ACCOUNT", a->ClientOption->AccountName);\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+       CiNormalizeAccountVLan(c);\r
+\r
+       CiSaveConfigurationFile(c);\r
+\r
+       CiNotify(c);\r
+\r
+       return true;\r
+}\r
+\r
+// アカウント取得構造体の解放\r
+void CiFreeClientGetAccount(RPC_CLIENT_GET_ACCOUNT *a)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // アカウント情報の解放\r
+       if (a->ServerCert != NULL)\r
+       {\r
+               FreeX(a->ServerCert);\r
+       }\r
+       CiFreeClientAuth(a->ClientAuth);\r
+       Free(a->ClientOption);\r
+}\r
+\r
+// アカウント作成構造体の解放\r
+void CiFreeClientCreateAccount(RPC_CLIENT_CREATE_ACCOUNT *a)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // アカウント情報の解放\r
+       if (a->ServerCert != NULL)\r
+       {\r
+               FreeX(a->ServerCert);\r
+       }\r
+       CiFreeClientAuth(a->ClientAuth);\r
+       Free(a->ClientOption);\r
+}\r
+\r
+// 仮想 LAN カードの停止\r
+bool CtDisableVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *vlan)\r
+{\r
+       UINT i;\r
+       bool used;\r
+       // 引数チェック\r
+       if (c == NULL || vlan == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifndef        OS_WIN32\r
+\r
+       if (GetOsInfo()->OsType == OSTYPE_MACOS_X)\r
+       {\r
+               // MacOS X では仮想 LAN カードは増減できない\r
+               CiSetError(c, ERR_NOT_SUPPORTED);\r
+               return false;\r
+       }\r
+\r
+       // 指定した名前の仮想 LAN カードが 1 つ以上のアカウントによって使用されていない\r
+       // かどうか確認する\r
+       used = false;\r
+       LockList(c->AccountList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(c->AccountList);i++)\r
+               {\r
+                       ACCOUNT *a = LIST_DATA(c->AccountList, i);\r
+                       if (StrCmpi(a->ClientOption->DeviceName, vlan->DeviceName) == 0)\r
+                       {\r
+                               Lock(a->lock);\r
+                               {\r
+                                       if (a->ClientSession != NULL)\r
+                                       {\r
+                                               used = true;\r
+                                       }\r
+                               }\r
+                               Unlock(a->lock);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+       // 仮想 LAN カードを検索する\r
+       LockList(c->UnixVLanList);\r
+       {\r
+               UNIX_VLAN *v, t;\r
+\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.Name, sizeof(t.Name), vlan->DeviceName);\r
+\r
+               v = Search(c->UnixVLanList, &t);\r
+               if (v == NULL)\r
+               {\r
+                       UnlockList(c->UnixVLanList);\r
+                       CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+                       return false;\r
+               }\r
+\r
+               // 停止する\r
+               v->Enabled = false;\r
+       }\r
+       UnlockList(c->UnixVLanList);\r
+\r
+       CiSaveConfigurationFile(c);\r
+       CiNotify(c);\r
+\r
+       return true;\r
+\r
+#else  // OS_WIN32\r
+\r
+       // 指定した名前の仮想 LAN カードが 1 つ以上のアカウントによって使用されていない\r
+       // かどうか確認する\r
+       used = false;\r
+       LockList(c->AccountList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(c->AccountList);i++)\r
+               {\r
+                       ACCOUNT *a = LIST_DATA(c->AccountList, i);\r
+                       if (StrCmpi(a->ClientOption->DeviceName, vlan->DeviceName) == 0)\r
+                       {\r
+                               Lock(a->lock);\r
+                               {\r
+                                       if (a->ClientSession != NULL)\r
+                                       {\r
+                                               used = true;\r
+                                       }\r
+                               }\r
+                               Unlock(a->lock);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+#if    0\r
+       if (used)\r
+       {\r
+               // 使用中\r
+               CiSetError(c, ERR_VLAN_IS_USED);\r
+               return false;\r
+       }\r
+#endif\r
+\r
+\r
+       // 仮想 LAN カードが存在しているかチェック\r
+       if (MsIsVLanExists(VLAN_ADAPTER_NAME_TAG, vlan->DeviceName) == false)\r
+       {\r
+               CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+               CiNotify(c);\r
+               return false;\r
+       }\r
+\r
+\r
+       if (MsIs64BitWindows() && Is32() && MsIsAdmin())\r
+       {\r
+               // Windows は 64 bit だがこのコードは 32 bit であるので\r
+               // driver_installer を起動して処理を実行する\r
+               char tmp[MAX_SIZE];\r
+\r
+               Format(tmp, sizeof(tmp), "disablevlan %s", vlan->DeviceName);\r
+\r
+               if (MsExecDriverInstaller(tmp) == false)\r
+               {\r
+                       CiSetError(c, ERR_VLAN_INSTALL_ERROR);\r
+                       CiNotify(c);\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // 仮想 LAN カードを停止\r
+               if (MsDisableVLan(vlan->DeviceName) == false)\r
+               {\r
+                       CiSetError(c, ERR_VLAN_INSTALL_ERROR);\r
+                       CiNotify(c);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       CiNotify(c);\r
+\r
+       return true;\r
+\r
+#endif // OS_WIN32\r
+\r
+}\r
+\r
+// 仮想 LAN カードの開始\r
+bool CtEnableVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *vlan)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || vlan == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifndef        OS_WIN32\r
+\r
+       if (GetOsInfo()->OsType == OSTYPE_MACOS_X)\r
+       {\r
+               // MacOS X では仮想 LAN カードは増減できない\r
+               CiSetError(c, ERR_NOT_SUPPORTED);\r
+               return false;\r
+       }\r
+\r
+       // 仮想 LAN カードを検索する\r
+       LockList(c->UnixVLanList);\r
+       {\r
+               UNIX_VLAN *v, t;\r
+\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.Name, sizeof(t.Name), vlan->DeviceName);\r
+\r
+               v = Search(c->UnixVLanList, &t);\r
+               if (v == NULL)\r
+               {\r
+                       UnlockList(c->UnixVLanList);\r
+                       CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+                       return false;\r
+               }\r
+\r
+               // 有効にする\r
+               v->Enabled = true;\r
+       }\r
+       UnlockList(c->UnixVLanList);\r
+\r
+       CiSaveConfigurationFile(c);\r
+       CiNotify(c);\r
+\r
+       return true;\r
+\r
+#else  // OS_WIN32\r
+\r
+       // 仮想 LAN カードが存在しているかチェック\r
+       if (MsIsVLanExists(VLAN_ADAPTER_NAME_TAG, vlan->DeviceName) == false)\r
+       {\r
+               CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+               CiNotify(c);\r
+               return false;\r
+       }\r
+\r
+       if (MsIs64BitWindows() && Is32() && MsIsAdmin())\r
+       {\r
+               // Windows は 64 bit だがこのコードは 32 bit であるので\r
+               // driver_installer を起動して処理を実行する\r
+               char tmp[MAX_SIZE];\r
+\r
+               Format(tmp, sizeof(tmp), "enablevlan %s", vlan->DeviceName);\r
+\r
+               if (MsExecDriverInstaller(tmp) == false)\r
+               {\r
+                       CiSetError(c, ERR_VLAN_INSTALL_ERROR);\r
+                       CiNotify(c);\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // 仮想 LAN カードを開始\r
+               if (MsEnableVLan(vlan->DeviceName) == false)\r
+               {\r
+                       CiSetError(c, ERR_VLAN_INSTALL_ERROR);\r
+                       CiNotify(c);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       CiNotify(c);\r
+\r
+       return true;\r
+\r
+#endif // OS_WIN32\r
+\r
+}\r
+\r
+// 仮想 LAN カードの削除\r
+bool CtDeleteVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *d)\r
+{\r
+       UINT i;\r
+       bool used;\r
+       // 引数チェック\r
+       if (c == NULL || d == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifndef        OS_WIN32\r
+\r
+       if (GetOsInfo()->OsType == OSTYPE_MACOS_X)\r
+       {\r
+               // MacOS X では仮想 LAN カードは増減できない\r
+               CiSetError(c, ERR_NOT_SUPPORTED);\r
+               return false;\r
+       }\r
+\r
+       // 指定した名前の仮想 LAN カードが 1 つ以上のアカウントによって使用されていない\r
+       // かどうか確認する\r
+       used = false;\r
+       LockList(c->AccountList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(c->AccountList);i++)\r
+               {\r
+                       ACCOUNT *a = LIST_DATA(c->AccountList, i);\r
+                       if (StrCmpi(a->ClientOption->DeviceName, d->DeviceName) == 0)\r
+                       {\r
+                               used = true;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+#if    0\r
+       if (used)\r
+       {\r
+               // 使用中\r
+               CiSetError(c, ERR_VLAN_IS_USED);\r
+               return false;\r
+       }\r
+#endif\r
+\r
+       // 仮想 LAN カードを検索する\r
+       LockList(c->UnixVLanList);\r
+       {\r
+               UNIX_VLAN *v, t;\r
+\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.Name, sizeof(t.Name), d->DeviceName);\r
+\r
+               v = Search(c->UnixVLanList, &t);\r
+               if (v == NULL)\r
+               {\r
+                       UnlockList(c->UnixVLanList);\r
+                       CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+                       return false;\r
+               }\r
+\r
+               // 削除する\r
+               if (Delete(c->UnixVLanList, v))\r
+               {\r
+                       Free(v);\r
+               }\r
+\r
+               CLog(c, "LC_DELETE_VLAN", d->DeviceName);\r
+\r
+               UnixVLanDelete(d->DeviceName);\r
+       }\r
+       UnlockList(c->UnixVLanList);\r
+\r
+       CiNormalizeAccountVLan(c);\r
+\r
+       CiSaveConfigurationFile(c);\r
+       CiNotify(c);\r
+\r
+       return true;\r
+\r
+#else  // OS_WIN32\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               // Win9x では使用できない\r
+               CiSetError(c, ERR_NOT_SUPPORTED);\r
+               return false;\r
+       }\r
+\r
+       // 仮想 LAN カードが存在しているかチェック\r
+       if (MsIsVLanExists(VLAN_ADAPTER_NAME_TAG, d->DeviceName) == false)\r
+       {\r
+               CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+               return false;\r
+       }\r
+\r
+       // 指定した名前の仮想 LAN カードが 1 つ以上のアカウントによって使用されていない\r
+       // かどうか確認する\r
+       used = false;\r
+       LockList(c->AccountList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(c->AccountList);i++)\r
+               {\r
+                       ACCOUNT *a = LIST_DATA(c->AccountList, i);\r
+                       if (StrCmpi(a->ClientOption->DeviceName, d->DeviceName) == 0)\r
+                       {\r
+                               used = true;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(c->AccountList);\r
+\r
+#if    0\r
+       if (used)\r
+       {\r
+               // 使用中\r
+               CiSetError(c, ERR_VLAN_IS_USED);\r
+               return false;\r
+       }\r
+#endif\r
+\r
+       if (MsIs64BitWindows() && Is32() && MsIsAdmin())\r
+       {\r
+               // Windows は 64 bit だがこのコードは 32 bit であるので\r
+               // driver_installer を起動して処理を実行する\r
+               char tmp[MAX_SIZE];\r
+\r
+               Format(tmp, sizeof(tmp), "uninstvlan %s", d->DeviceName);\r
+\r
+               if (MsExecDriverInstaller(tmp) == false)\r
+               {\r
+                       CiSetError(c, ERR_VLAN_INSTALL_ERROR);\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // 仮想 LAN カードを直接削除\r
+               if (MsUninstallVLan(d->DeviceName) == false)\r
+               {\r
+                       CiSetError(c, ERR_VLAN_INSTALL_ERROR);\r
+                       CiNotify(c);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       CLog(c, "LC_DELETE_VLAN", d->DeviceName);\r
+\r
+       CiNormalizeAccountVLan(c);\r
+\r
+       CiNotify(c);\r
+\r
+       return true;\r
+\r
+#endif // OS_WIN32\r
+\r
+}\r
+\r
+// 最初の VLAN の名前を取得\r
+char *CiGetFirstVLan(CLIENT *c)\r
+{\r
+       char *ret = NULL;\r
+       RPC_CLIENT_ENUM_VLAN t;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CtEnumVLan(c, &t) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (t.NumItem >= 1)\r
+       {\r
+               UINT i;\r
+               char *tmp = t.Items[0]->DeviceName;\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       if (t.Items[i]->Enabled)\r
+                       {\r
+                               tmp = t.Items[i]->DeviceName;\r
+                       }\r
+               }\r
+\r
+               ret = CopyStr(tmp);\r
+       }\r
+\r
+       CiFreeClientEnumVLan(&t);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カードの列挙\r
+bool CtEnumVLan(CLIENT *c, RPC_CLIENT_ENUM_VLAN *e)\r
+{\r
+       UINT i;\r
+       TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (c == NULL || e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifndef        OS_WIN32\r
+\r
+       LockList(c->UnixVLanList);\r
+       {\r
+               e->NumItem = LIST_NUM(c->UnixVLanList);\r
+               e->Items = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_VLAN_ITEM *) * e->NumItem);\r
+\r
+               for (i = 0;i < e->NumItem;i++)\r
+               {\r
+                       RPC_CLIENT_ENUM_VLAN_ITEM *item;\r
+                       UNIX_VLAN *v;\r
+\r
+                       v = LIST_DATA(c->UnixVLanList, i);\r
+                       e->Items[i] = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_VLAN_ITEM));\r
+                       item = e->Items[i];\r
+\r
+                       item->Enabled = v->Enabled;\r
+                       BinToStr(item->MacAddress, sizeof(item->MacAddress), v->MacAddress, 6);\r
+                       StrCpy(item->DeviceName, sizeof(item->DeviceName), v->Name);\r
+                       StrCpy(item->Version, sizeof(item->Version), c->Cedar->VerString);\r
+               }\r
+       }\r
+       UnlockList(c->UnixVLanList);\r
+\r
+       return true;\r
+\r
+#else  // OS_WIN32\r
+\r
+       // 列挙\r
+       t = MsEnumNetworkAdapters(VLAN_ADAPTER_NAME, "---dummy-string-ut--");\r
+       if (t == NULL)\r
+       {\r
+               // 列挙失敗\r
+               e->NumItem = 0;\r
+               e->Items = ZeroMalloc(0);\r
+       }\r
+       else\r
+       {\r
+               // 列挙成功\r
+               e->NumItem = t->NumTokens;\r
+               e->Items = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_VLAN_ITEM *) * e->NumItem);\r
+\r
+               for (i = 0;i < e->NumItem;i++)\r
+               {\r
+                       char *tmp;\r
+                       RPC_CLIENT_ENUM_VLAN_ITEM *item;\r
+                       e->Items[i] = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_VLAN_ITEM));\r
+                       item = e->Items[i];\r
+\r
+                       StrCpy(item->DeviceName, sizeof(item->DeviceName), t->Token[i]);\r
+                       item->Enabled = MsIsVLanEnabled(item->DeviceName);\r
+\r
+                       tmp = MsGetMacAddress(VLAN_ADAPTER_NAME_TAG, item->DeviceName);\r
+\r
+                       StrCpy(item->MacAddress, sizeof(item->MacAddress), tmp);\r
+                       Free(tmp);\r
+\r
+                       tmp = MsGetDriverVersion(VLAN_ADAPTER_NAME_TAG, item->DeviceName);\r
+\r
+                       StrCpy(item->Version, sizeof(item->Version), tmp);\r
+                       Free(tmp);\r
+               }\r
+\r
+               FreeToken(t);\r
+       }\r
+\r
+       return true;\r
+\r
+#endif // OS_WIN32\r
+}\r
+\r
+// 仮想 LAN カード列挙体の解放\r
+void CiFreeClientEnumVLan(RPC_CLIENT_ENUM_VLAN *e)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < e->NumItem;i++)\r
+       {\r
+               Free(e->Items[i]);\r
+       }\r
+       Free(e->Items);\r
+}\r
+\r
+// 仮想 LAN カードに関する情報の設定\r
+bool CtSetVLan(CLIENT *c, RPC_CLIENT_SET_VLAN *set)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || set == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifndef        OS_WIN32\r
+\r
+       LockList(c->UnixVLanList);\r
+       {\r
+               UNIX_VLAN t, *r;\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.Name, sizeof(t.Name), set->DeviceName);\r
+\r
+               r = Search(c->UnixVLanList, &t);\r
+               if (r == NULL)\r
+               {\r
+                       // 存在しない\r
+                       CiSetError(c, ERR_VLAN_ALREADY_EXISTS);\r
+                       UnlockList(c->UnixVLanList);\r
+                       return false;\r
+               }\r
+\r
+               StrToMac(r->MacAddress, set->MacAddress);\r
+       }\r
+       UnlockList(c->UnixVLanList);\r
+\r
+       CiSaveConfigurationFile(c);\r
+       CiNotify(c);\r
+\r
+       return true;\r
+\r
+#else  // OS_WIN32\r
+\r
+       // 指定された名前の仮想 LAN カードが存在するかチェック\r
+       if (MsIsVLanExists(VLAN_ADAPTER_NAME_TAG, set->DeviceName) == false)\r
+       {\r
+               // 存在していない\r
+               CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+               return false;\r
+       }\r
+\r
+       // MAC アドレスの設定\r
+       MsSetMacAddress(VLAN_ADAPTER_NAME_TAG, set->DeviceName, set->MacAddress);\r
+\r
+       CiNotify(c);\r
+\r
+       return true;\r
+\r
+#endif // OS_WIN32\r
+}\r
+\r
+// 仮想 LAN カードに関する情報の取得\r
+bool CtGetVLan(CLIENT *c, RPC_CLIENT_GET_VLAN *get)\r
+{\r
+       char *tmp;\r
+       // 引数チェック\r
+       if (c == NULL || get == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifndef        OS_WIN32\r
+\r
+       // サポートされていない\r
+       CiSetError(c, ERR_NOT_SUPPORTED);\r
+       return false;\r
+\r
+#else  // OS_WIN32\r
+\r
+       // 指定された名前の仮想 LAN カードが存在するかチェック\r
+       if (MsIsVLanExists(VLAN_ADAPTER_NAME_TAG, get->DeviceName) == false)\r
+       {\r
+               // 存在していない\r
+               CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+               return false;\r
+       }\r
+\r
+       // 動作状況\r
+       get->Enabled = MsIsVLanEnabled(get->DeviceName);\r
+\r
+       // MAC アドレス\r
+       tmp = MsGetMacAddress(VLAN_ADAPTER_NAME_TAG, get->DeviceName);\r
+       StrCpy(get->MacAddress, sizeof(get->MacAddress), tmp);\r
+       Free(tmp);\r
+\r
+       // バージョン\r
+       tmp = MsGetDriverVersion(VLAN_ADAPTER_NAME_TAG, get->DeviceName);\r
+       StrCpy(get->Version, sizeof(get->Version), tmp);\r
+       Free(tmp);\r
+\r
+       // ファイル名\r
+       tmp = MsGetDriverFileName(VLAN_ADAPTER_NAME_TAG, get->DeviceName);\r
+       StrCpy(get->FileName, sizeof(get->FileName), tmp);\r
+       Free(tmp);\r
+\r
+       // GUID\r
+       tmp = MsGetNetworkAdapterGuid(VLAN_ADAPTER_NAME_TAG, get->DeviceName);\r
+       StrCpy(get->Guid, sizeof(get->Guid), tmp);\r
+       Free(tmp);\r
+\r
+       return true;\r
+\r
+#endif // OS_WIN32\r
+}\r
+\r
+// 仮想 LAN カードのアップグレード\r
+bool CtUpgradeVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create)\r
+{\r
+#ifdef OS_WIN32\r
+       KAKUSHI *k = NULL;\r
+#endif // OS_WIN32\r
+\r
+       // 引数チェック\r
+       if (c == NULL || create == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifndef        OS_WIN32\r
+\r
+       // 常に成功\r
+       return true;\r
+\r
+#else  // OS_WIN32\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               // Win9x では不可\r
+               CiSetError(c, ERR_NOT_SUPPORTED);\r
+               return false;\r
+       }\r
+\r
+       // 指定された名前の LAN カードがすでに存在していないかどうかチェックする\r
+       if (MsIsVLanExists(VLAN_ADAPTER_NAME_TAG, create->DeviceName) == false)\r
+       {\r
+               // 存在していない\r
+               CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+               CiNotify(c);\r
+               return false;\r
+       }\r
+\r
+       if (MsIsVista() == false)\r
+       {\r
+               k = InitKakushi();      \r
+       }\r
+\r
+\r
+       if (MsIsVista() == false)\r
+       {\r
+               // インストールを行う (Windows Vista 以外)\r
+               if (MsUpgradeVLan(VLAN_ADAPTER_NAME_TAG,\r
+                       VLAN_CONNECTION_NAME,\r
+                       create->DeviceName) == false)\r
+               {\r
+                       // インストール失敗\r
+                       FreeKakushi(k);\r
+                       CiSetError(c, ERR_VLAN_INSTALL_ERROR);\r
+                       CiNotify(c);\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // インストールを行う (Windows Vista)\r
+               char tmp[MAX_SIZE];\r
+\r
+               Format(tmp, sizeof(tmp), "upgradevlan %s", create->DeviceName);\r
+\r
+               if (CncExecDriverInstaller(tmp) == false)\r
+               {\r
+                       // インストール失敗\r
+                       FreeKakushi(k);\r
+                       CiSetError(c, ERR_VLAN_INSTALL_ERROR);\r
+                       CiNotify(c);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       FreeKakushi(k);\r
+\r
+       CLog(c, "LC_UPDATE_VLAN", create->DeviceName);\r
+\r
+       CiNotify(c);\r
+\r
+       return true;\r
+\r
+#endif // OS_WIN32\r
+}\r
+\r
+// 仮想 LAN カードの作成\r
+bool CtCreateVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT max_len;\r
+\r
+#ifdef OS_WIN32\r
+       KAKUSHI *k = NULL;\r
+#endif // OS_WIN32\r
+\r
+       // 引数チェック\r
+       if (c == NULL || create == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifndef        OS_WIN32\r
+\r
+       // Win32 以外\r
+       if (GetOsInfo()->OsType == OSTYPE_MACOS_X)\r
+       {\r
+               // MacOS X では仮想 LAN カードは増減できない\r
+               CiSetError(c, ERR_NOT_SUPPORTED);\r
+               return false;\r
+       }\r
+\r
+       // 指定された名前が有効かどうかチェックする\r
+       if (IsSafeStr(create->DeviceName) == false)\r
+       {\r
+               // 名前が不正\r
+               CiSetError(c, ERR_VLAN_INVALID_NAME);\r
+               return false;\r
+       }\r
+\r
+       // 指定した名前の LAN カードがすでに存在していないかどうかチェックする\r
+       LockList(c->UnixVLanList);\r
+       {\r
+               UNIX_VLAN t, *r;\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.Name, sizeof(t.Name), create->DeviceName);\r
+\r
+               r = Search(c->UnixVLanList, &t);\r
+               if (r != NULL)\r
+               {\r
+                       // すでに存在している\r
+                       CiSetError(c, ERR_VLAN_ALREADY_EXISTS);\r
+                       UnlockList(c->UnixVLanList);\r
+                       return false;\r
+               }\r
+\r
+               // 登録する\r
+               r = ZeroMalloc(sizeof(UNIX_VLAN));\r
+               r->Enabled = true;\r
+               GenMacAddress(r->MacAddress);\r
+               StrCpy(r->Name, sizeof(r->Name), create->DeviceName);\r
+\r
+               // tap 作成\r
+               if (UnixVLanCreate(r->Name, r->MacAddress) == false)\r
+               {\r
+                       // 失敗\r
+                       Free(r);\r
+                       CiSetError(c, ERR_VLAN_INSTALL_ERROR);\r
+                       UnlockList(c->UnixVLanList);\r
+                       return false;\r
+               }\r
+\r
+               CLog(c, "LC_CREATE_VLAN", create->DeviceName);\r
+\r
+               Add(c->UnixVLanList, r);\r
+       }\r
+       UnlockList(c->UnixVLanList);\r
+\r
+       CiNormalizeAccountVLan(c);\r
+\r
+       CiNotify(c);\r
+       CiSaveConfigurationFile(c);\r
+\r
+       return true;\r
+\r
+#else  // OS_WIN32\r
+\r
+       if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType))\r
+       {\r
+               // Win9x では LAN カードは 1 個しか作成できない\r
+               TOKEN_LIST *t;\r
+\r
+               t = MsEnumNetworkAdapters(VLAN_ADAPTER_NAME, "---dummy-string-ut--");\r
+               if (t != NULL)\r
+               {\r
+                       if (t->NumTokens >= 1)\r
+                       {\r
+                               FreeToken(t);\r
+                               CiSetError(c, ERR_NOT_SUPPORTED);\r
+                               return false;\r
+                       }\r
+                       FreeToken(t);\r
+               }\r
+       }\r
+\r
+       // 指定された名前が有効かどうかチェックする\r
+       if (IsSafeStr(create->DeviceName) == false)\r
+       {\r
+               // 名前が不正\r
+               CiSetError(c, ERR_VLAN_INVALID_NAME);\r
+               return false;\r
+       }\r
+\r
+       max_len = MsIsNt() ? MAX_DEVICE_NAME_LEN : MAX_DEVICE_NAME_LEN_9X;\r
+       if (StrLen(create->DeviceName) > max_len)\r
+       {\r
+               // 名前が長すぎる\r
+               CiSetError(c, ERR_VLAN_INVALID_NAME);\r
+               return false;\r
+       }\r
+\r
+       // 指定された名前の LAN カードがすでに存在していないかどうかチェックする\r
+       if (MsIsVLanExists(VLAN_ADAPTER_NAME_TAG, create->DeviceName))\r
+       {\r
+               // すでに存在している\r
+               CiSetError(c, ERR_VLAN_ALREADY_EXISTS);\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt())\r
+       {\r
+               if (MsIsVista() == false)\r
+               {\r
+                       k = InitKakushi();\r
+               }\r
+       }\r
+\r
+       if (MsIsVista() == false)\r
+       {\r
+               // インストールを行う (Windows Vista 以外)\r
+               if (MsInstallVLan(VLAN_ADAPTER_NAME_TAG, VLAN_CONNECTION_NAME, create->DeviceName) == false)\r
+               {\r
+                       // インストール失敗\r
+                       FreeKakushi(k);\r
+                       CiSetError(c, ERR_VLAN_INSTALL_ERROR);\r
+                       CiNotify(c);\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // インストールを行う (Windows Vista)\r
+               char tmp[MAX_SIZE];\r
+\r
+               Format(tmp, sizeof(tmp), "instvlan %s", create->DeviceName);\r
+\r
+               if (CncExecDriverInstaller(tmp) == false)\r
+               {\r
+                       // インストール失敗\r
+                       FreeKakushi(k);\r
+                       CiSetError(c, ERR_VLAN_INSTALL_ERROR);\r
+                       CiNotify(c);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       FreeKakushi(k);\r
+\r
+       t = MsEnumNetworkAdapters(VLAN_ADAPTER_NAME, "---dummy-string-ut--");\r
+       if (t->NumTokens == 1)\r
+       {\r
+               UINT i;\r
+               // インストールを行った結果、仮想 LAN カードが 1 つになった場合は\r
+               // 既存のすべてのアカウントの仮想 LAN カードをこの仮想 LAN カードにセットする\r
+               LockList(c->AccountList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(c->AccountList);i++)\r
+                       {\r
+                               ACCOUNT *a = LIST_DATA(c->AccountList, i);\r
+                               Lock(a->lock);\r
+                               {\r
+                                       if (a->ClientOption != NULL)\r
+                                       {\r
+                                               StrCpy(a->ClientOption->DeviceName, sizeof(a->ClientOption->DeviceName), create->DeviceName);\r
+                                       }\r
+                               }\r
+                               Unlock(a->lock);\r
+                       }\r
+               }\r
+               UnlockList(c->AccountList);\r
+       }\r
+       FreeToken(t);\r
+\r
+       CLog(c, "LC_CREATE_VLAN", create->DeviceName);\r
+\r
+       CiNormalizeAccountVLan(c);\r
+\r
+       CiNotify(c);\r
+\r
+       CiSaveConfigurationFile(c);\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               if (GetOsInfo()->OsType == OSTYPE_WINDOWS_ME)\r
+               {\r
+                       // Windows Me の場合は警告表示\r
+                       MsgBox(NULL, 0x00000040L, _UU("CM_9X_VLAN_ME_MESSAGE"));\r
+               }\r
+\r
+               ReleaseThread(NewThread(Win9xRebootThread, NULL));\r
+       }\r
+\r
+       return true;\r
+\r
+#endif // OS_WIN32\r
+}\r
+\r
+// セキュアデバイス内のオブジェクト列挙\r
+bool CtEnumObjectInSecure(CLIENT *c, RPC_ENUM_OBJECT_IN_SECURE *e)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (c == NULL || e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       e->NumItem = 5;\r
+       e->ItemName = ZeroMalloc(sizeof(char *) * e->NumItem);\r
+       e->ItemType = ZeroMalloc(sizeof(bool) * e->NumItem);\r
+\r
+       for (i = 0;i < e->NumItem;i++)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               Format(tmp, sizeof(tmp), "Test Object %u", i);\r
+               e->ItemName[i] = CopyStr(tmp);\r
+               e->ItemType[i] = (i % 2 == 0) ? false : true;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 使用するセキュアデバイスの取得\r
+bool CtGetUseSecure(CLIENT *c, RPC_USE_SECURE *sec)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       sec->DeviceId = c->UseSecureDeviceId;\r
+\r
+       return true;\r
+}\r
+\r
+// 使用するセキュアデバイスの指定\r
+bool CtUseSecure(CLIENT *c, RPC_USE_SECURE *sec)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+// クライアントマネージャに指定されたデバイスが存在するかどうかチェックしない\r
+/*     if (CheckSecureDeviceId(sec->DeviceId))\r
+       {\r
+               c->UseSecureDeviceId = sec->DeviceId;\r
+       }\r
+       else\r
+       {\r
+               CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+               return false;\r
+       }\r
+*/\r
+       c->UseSecureDeviceId = sec->DeviceId;\r
+\r
+       CiSaveConfigurationFile(c);\r
+\r
+       return true;\r
+}\r
+\r
+// セキュアデバイスの列挙\r
+bool CtEnumSecure(CLIENT *c, RPC_CLIENT_ENUM_SECURE *e)\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (c == NULL || e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       o = GetSecureDeviceList();\r
+\r
+       e->NumItem = LIST_NUM(o);\r
+       e->Items = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_SECURE_ITEM *) * e->NumItem);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               RPC_CLIENT_ENUM_SECURE_ITEM *item = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_SECURE_ITEM));\r
+               SECURE_DEVICE *s = LIST_DATA(o, i);\r
+\r
+               item->DeviceId = s->Id;\r
+               StrCpy(item->DeviceName, sizeof(item->DeviceName), s->DeviceName);\r
+               StrCpy(item->Manufacturer, sizeof(item->Manufacturer), s->Manufacturer);\r
+               item->Type = s->Type;\r
+\r
+               e->Items[i] = item;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// セキュアデバイス列挙体の解放\r
+void CiFreeClientEnumSecure(RPC_CLIENT_ENUM_SECURE *e)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < e->NumItem;i++)\r
+       {\r
+               Free(e->Items[i]);\r
+       }\r
+       Free(e->Items);\r
+}\r
+\r
+// RPC_GET_ISSUER の解放\r
+void CiFreeGetIssuer(RPC_GET_ISSUER *a)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (a->issuer_x != NULL)\r
+       {\r
+               FreeX(a->issuer_x);\r
+       }\r
+       if (a->x != NULL)\r
+       {\r
+               FreeX(a->x);\r
+       }\r
+}\r
+\r
+// 署名者の取得\r
+bool CtGetIssuer(CLIENT *c, RPC_GET_ISSUER *a)\r
+{\r
+       X *x;\r
+       // 引数チェック\r
+       if (c == NULL || a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       x = FindCaSignedX(c->Cedar->CaList, a->x);\r
+       if (x == NULL)\r
+       {\r
+               CiSetError(c, ERR_OBJECT_NOT_FOUND);;\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               a->issuer_x = x;\r
+               if (a->x != NULL)\r
+               {\r
+                       FreeX(a->x);\r
+                       a->x = NULL;\r
+               }\r
+               return true;\r
+       }\r
+}\r
+\r
+// CA 証明書の取得\r
+bool CtGetCa(CLIENT *c, RPC_GET_CA *get)\r
+{\r
+       bool ret = true;\r
+       X *cert = NULL;\r
+       // 引数チェック\r
+       if (c == NULL || get == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       LockList(c->Cedar->CaList);\r
+       {\r
+               UINT i;\r
+\r
+               for (i = 0;i < LIST_NUM(c->Cedar->CaList);i++)\r
+               {\r
+                       X *x = LIST_DATA(c->Cedar->CaList, i);\r
+\r
+                       if (POINTER_TO_KEY(x) == get->Key)\r
+                       {\r
+                               cert = CloneX(x);\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(c->Cedar->CaList);\r
+\r
+       if (cert == NULL)\r
+       {\r
+               // 証明書は存在しない\r
+               ret = false;\r
+               CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+       }\r
+       else\r
+       {\r
+               ret = true;\r
+               get->x = cert;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// CA 証明書の削除\r
+bool CtDeleteCa(CLIENT *c, RPC_CLIENT_DELETE_CA *p)\r
+{\r
+       bool ret;\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = DeleteCa(c->Cedar, p->Key);\r
+\r
+       if (ret == false)\r
+       {\r
+               CiSetError(c, ERR_OBJECT_NOT_FOUND);\r
+       }\r
+\r
+       CiSaveConfigurationFile(c);\r
+\r
+       return ret;\r
+}\r
+\r
+// CA 証明書の追加\r
+bool CtAddCa(CLIENT *c, RPC_CERT *cert)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || cert == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (cert->x->is_compatible_bit == false)\r
+       {\r
+               CiSetError(c, ERR_NOT_RSA_1024);\r
+               return false;\r
+       }\r
+\r
+       AddCa(c->Cedar, cert->x);\r
+\r
+       CiSaveConfigurationFile(c);\r
+\r
+       return true;\r
+}\r
+\r
+// 信頼する CA の列挙\r
+bool CtEnumCa(CLIENT *c, RPC_CLIENT_ENUM_CA *e)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(e, sizeof(RPC_CLIENT_ENUM_CA));\r
+\r
+       LockList(c->Cedar->CaList);\r
+       {\r
+               UINT i;\r
+               e->NumItem = LIST_NUM(c->Cedar->CaList);\r
+               e->Items = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_CA_ITEM *) * e->NumItem);\r
+\r
+               for (i = 0;i < e->NumItem;i++)\r
+               {\r
+                       X *x = LIST_DATA(c->Cedar->CaList, i);\r
+                       e->Items[i] = ZeroMalloc(sizeof(RPC_CLIENT_ENUM_CA_ITEM));\r
+                       GetAllNameFromNameEx(e->Items[i]->SubjectName, sizeof(e->Items[i]->SubjectName), x->subject_name);\r
+                       GetAllNameFromNameEx(e->Items[i]->IssuerName, sizeof(e->Items[i]->IssuerName), x->issuer_name);\r
+                       e->Items[i]->Expires = x->notAfter;\r
+                       e->Items[i]->Key = POINTER_TO_KEY(x);\r
+               }\r
+       }\r
+       UnlockList(c->Cedar->CaList);\r
+\r
+       return true;\r
+}\r
+\r
+// CA 列挙体を解放する\r
+void CiFreeClientEnumCa(RPC_CLIENT_ENUM_CA *e)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < e->NumItem;i++)\r
+       {\r
+               RPC_CLIENT_ENUM_CA_ITEM *ca = e->Items[i];\r
+               Free(ca);\r
+       }\r
+       Free(e->Items);\r
+}\r
+\r
+// パスワードの設定の取得\r
+bool CtGetPasswordSetting(CLIENT *c, RPC_CLIENT_PASSWORD_SETTING *a)\r
+{\r
+       UCHAR hash[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (c == NULL || a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Hash(hash, "", 0, true);\r
+       if (Cmp(hash, c->EncryptedPassword, SHA1_SIZE) == 0)\r
+       {\r
+               a->IsPasswordPresented = false;\r
+       }\r
+       else\r
+       {\r
+               a->IsPasswordPresented = true;\r
+       }\r
+\r
+       a->PasswordRemoteOnly = c->PasswordRemoteOnly;\r
+\r
+       return true;\r
+}\r
+\r
+// パスワードの設定\r
+bool CtSetPassword(CLIENT *c, RPC_CLIENT_PASSWORD *pass)\r
+{\r
+       char *str;\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (pass->Password == NULL)\r
+       {\r
+               str = "";\r
+       }\r
+       else\r
+       {\r
+               str = pass->Password;\r
+       }\r
+\r
+       if (StrCmp(str, "********") != 0)\r
+       {\r
+               // パスワードのハッシュ\r
+               Hash(c->EncryptedPassword, str, StrLen(str), true);\r
+       }\r
+\r
+       c->PasswordRemoteOnly = pass->PasswordRemoteOnly;\r
+\r
+       CLog(c, "LC_SET_PASSWORD");\r
+\r
+       CiSaveConfigurationFile(c);\r
+\r
+       return true;\r
+}\r
+\r
+// クライアントエラーコードの設定\r
+void CiSetError(CLIENT *c, UINT err)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->Err = err;\r
+}\r
+\r
+// UNIX 仮想 LAN カード比較関数\r
+int CiCompareUnixVLan(void *p1, void *p2)\r
+{\r
+       UNIX_VLAN *v1, *v2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       v1 = *(UNIX_VLAN **)p1;\r
+       v2 = *(UNIX_VLAN **)p2;\r
+       if (v1 == NULL || v2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCmpi(v1->Name, v2->Name);\r
+}\r
+\r
+// 不正な VLAN 名が指定されているアカウントの設定を修正する\r
+void CiNormalizeAccountVLan(CLIENT *c)\r
+{\r
+       bool b = false;\r
+       char *name;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       name = CiGetFirstVLan(c);\r
+\r
+       if (name != NULL)\r
+       {\r
+               LockList(c->AccountList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(c->AccountList);i++)\r
+                       {\r
+                               ACCOUNT *a = LIST_DATA(c->AccountList, i);\r
+\r
+                               Lock(a->lock);\r
+                               {\r
+                                       if (a->ClientOption != NULL)\r
+                                       {\r
+                                               if (CiIsVLan(c, a->ClientOption->DeviceName) == false)\r
+                                               {\r
+                                                       StrCpy(a->ClientOption->DeviceName, sizeof(a->ClientOption->DeviceName),\r
+                                                               name);\r
+                                                       b = true;\r
+                                               }\r
+                                       }\r
+                               }\r
+                               Unlock(a->lock);\r
+                       }\r
+               }\r
+               UnlockList(c->AccountList);\r
+\r
+               Free(name);\r
+       }\r
+\r
+       if (b)\r
+       {\r
+               CiNotify(c);\r
+               CiSaveConfigurationFile(c);\r
+       }\r
+}\r
+\r
+// 指定した名前の仮想 LAN カードが存在しているかどうか調べる\r
+bool CiIsVLan(CLIENT *c, char *name)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       {\r
+               TOKEN_LIST *t;\r
+               UINT i;\r
+\r
+               t = MsEnumNetworkAdapters(VLAN_ADAPTER_NAME, "---dummy-string-ut--");\r
+               if (t == NULL)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               for (i = 0;i < t->NumTokens;i++)\r
+               {\r
+                       if (StrCmpi(t->Token[i], name) == 0)\r
+                       {\r
+                               FreeToken(t);\r
+                               return true;\r
+                       }\r
+               }\r
+\r
+               FreeToken(t);\r
+\r
+               return false;\r
+       }\r
+#else  // OS_WIN32\r
+       {\r
+               UNIX_VLAN *v;\r
+               UINT i;\r
+               bool ret = false;\r
+\r
+               LockList(c->UnixVLanList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(c->UnixVLanList);i++)\r
+                       {\r
+                               v = (UNIX_VLAN *)LIST_DATA(c->UnixVLanList, i);\r
+                               if (StrCmpi(v->Name, name) == 0)\r
+                               {\r
+                                       ret = true;\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(c->UnixVLanList);\r
+\r
+               return ret;\r
+       }\r
+#endif // OS_WIN32\r
+}\r
+\r
+// すべての接続アカウントにおいて、存在しない仮想 LAN カードが指定されている場合で\r
+// 現在の仮想 LAN カードが 1 枚だけの場合は、その仮想 LAN カードに指定しなおす\r
+void CiSetVLanToDefault(CLIENT *c)\r
+{\r
+       char device_name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       {\r
+               TOKEN_LIST *t;\r
+\r
+               t = MsEnumNetworkAdapters(VLAN_ADAPTER_NAME, "---dummy-string-ut--");\r
+               if (t == NULL)\r
+               {\r
+                       return;\r
+               }\r
+               if (t->NumTokens != 1)\r
+               {\r
+                       FreeToken(t);\r
+                       return;\r
+               }\r
+               StrCpy(device_name, sizeof(device_name), t->Token[0]);\r
+               FreeToken(t);\r
+       }\r
+#else  // OS_WIN32\r
+       {\r
+               UINT i;\r
+               UNIX_VLAN *v;\r
+\r
+               LockList(c->UnixVLanList);\r
+\r
+               if (LIST_NUM(c->UnixVLanList) != 1)\r
+               {\r
+                       UnlockList(c->UnixVLanList);\r
+                       return;\r
+               }\r
+               v = LIST_DATA(c->UnixVLanList, 0);\r
+               StrCpy(device_name, sizeof(device_name), v->Name);\r
+\r
+               UnlockList(c->UnixVLanList);\r
+       }\r
+#endif // OS_WIN32\r
+\r
+       {\r
+               UINT i;\r
+               LockList(c->AccountList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(c->AccountList);i++)\r
+                       {\r
+                               ACCOUNT *a = LIST_DATA(c->AccountList, i);\r
+\r
+                               Lock(a->lock);\r
+                               {\r
+                                       if (CiIsVLan(c, a->ClientOption->DeviceName) == false)\r
+                                       {\r
+                                               StrCpy(a->ClientOption->DeviceName, sizeof(a->ClientOption->DeviceName),\r
+                                                       device_name);\r
+                                       }\r
+                               }\r
+                               Unlock(a->lock);\r
+                       }\r
+               }\r
+               UnlockList(c->AccountList);\r
+       }\r
+}\r
+\r
+// 設定の初期化\r
+void CiInitConfiguration(CLIENT *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_UNIX\r
+       // VLAN 初期化\r
+       UnixVLanInit();\r
+#endif  // OS_UNIX\r
+\r
+       // アカウントリスト\r
+       c->AccountList = NewList(CiCompareAccount);\r
+\r
+       // Unix 版 VLAN リスト\r
+       if (OS_IS_UNIX(GetOsInfo()->OsType))\r
+       {\r
+               c->UnixVLanList = NewList(CiCompareUnixVLan);\r
+       }\r
+\r
+       // 設定ファイルの読み込み\r
+       CLog(c, "LC_LOAD_CONFIG_1");\r
+       if (CiLoadConfigurationFile(c) == false)\r
+       {\r
+               CLog(c, "LC_LOAD_CONFIG_3");\r
+               // 設定ファイルが存在しないので初期設定を行う\r
+               // パスワードを空にする\r
+               Hash(c->EncryptedPassword, "", 0, true);\r
+               // クライアント設定を初期化\r
+               if (OS_IS_WINDOWS(GetOsInfo()->OsType))\r
+               {\r
+                       // Windows の場合はリモートを禁止\r
+                       c->Config.AllowRemoteConfig = false;\r
+               }\r
+               else\r
+               {\r
+                       // UNIX の場合もリモートを禁止\r
+                       c->Config.AllowRemoteConfig = false;\r
+               }\r
+               StrCpy(c->Config.KeepConnectHost, sizeof(c->Config.KeepConnectHost), CLIENT_DEFAULT_KEEPALIVE_HOST);\r
+               c->Config.KeepConnectPort = CLIENT_DEFAULT_KEEPALIVE_PORT;\r
+               c->Config.KeepConnectProtocol = CONNECTION_UDP;\r
+               c->Config.KeepConnectInterval = CLIENT_DEFAULT_KEEPALIVE_INTERVAL;\r
+               c->Config.UseKeepConnect = false;       // Client ではデフォルトでは接続維持機能を使用しない\r
+               // 自動ファイル削除器\r
+               c->Eraser = NewEraser(c->Logger, 0);\r
+       }\r
+       else\r
+       {\r
+               CLog(c, "LC_LOAD_CONFIG_2");\r
+       }\r
+\r
+       // 仮想 LAN カードの適切な設定\r
+       CiSetVLanToDefault(c);\r
+}\r
+\r
+// 設定の解放\r
+void CiFreeConfiguration(CLIENT *c)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 設定ファイルへ書き込み\r
+       CiSaveConfigurationFile(c);\r
+\r
+       // 設定ファイル解放\r
+       FreeCfgRw(c->CfgRw);\r
+\r
+       // アカウントリストの解放\r
+       for (i = 0;i < LIST_NUM(c->AccountList);i++)\r
+       {\r
+               ACCOUNT *a = LIST_DATA(c->AccountList, i);\r
+\r
+               CiFreeAccount(a);\r
+       }\r
+       ReleaseList(c->AccountList);\r
+\r
+       if (c->UnixVLanList != NULL)\r
+       {\r
+               // UNIX 版 VLAN リストの解放\r
+               for (i = 0;i < LIST_NUM(c->UnixVLanList);i++)\r
+               {\r
+                       UNIX_VLAN *v = LIST_DATA(c->UnixVLanList, i);\r
+                       Free(v);\r
+               }\r
+               ReleaseList(c->UnixVLanList);\r
+       }\r
+       c->UnixVLanList = NULL;\r
+\r
+#ifdef OS_UNIX\r
+       // VLAN 解放\r
+       UnixVLanFree();\r
+#endif // OS_UNIX\r
+}\r
+\r
+// 証明書取得データの解放\r
+void CiFreeGetCa(RPC_GET_CA *a)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeX(a->x);\r
+}\r
+\r
+// クライアント認証データの解放\r
+void CiFreeClientAuth(CLIENT_AUTH *auth)\r
+{\r
+       // 引数チェック\r
+       if (auth == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (auth->ClientX != NULL)\r
+       {\r
+               FreeX(auth->ClientX);\r
+       }\r
+       if (auth->ClientK != NULL)\r
+       {\r
+               FreeK(auth->ClientK);\r
+       }\r
+\r
+       Free(auth);\r
+}\r
+\r
+// アカウントの解放\r
+void CiFreeAccount(ACCOUNT *a)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ロック解放\r
+       DeleteLock(a->lock);\r
+\r
+       // クライアントオプションの解放\r
+       Free(a->ClientOption);\r
+\r
+       // クライアント認証データの解放\r
+       CiFreeClientAuth(a->ClientAuth);\r
+\r
+       if (a->ServerCert != NULL)\r
+       {\r
+               FreeX(a->ServerCert);\r
+       }\r
+\r
+       Free(a);\r
+}\r
+\r
+// アカウントのソート\r
+int CiCompareAccount(void *p1, void *p2)\r
+{\r
+       ACCOUNT *a1, *a2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       a1 = *(ACCOUNT **)p1;\r
+       a2 = *(ACCOUNT **)p2;\r
+       if (a1 == NULL || a2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return UniStrCmpi(a1->ClientOption->AccountName, a2->ClientOption->AccountName);\r
+}\r
+\r
+// クライアントコンフィグレーションの読み込み\r
+void CiLoadClientConfig(CLIENT_CONFIG *c, FOLDER *f)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->UseKeepConnect = CfgGetBool(f, "UseKeepConnect");\r
+       CfgGetStr(f, "KeepConnectHost", c->KeepConnectHost, sizeof(c->KeepConnectHost));\r
+       c->KeepConnectPort = CfgGetInt(f, "KeepConnectPort");\r
+       c->KeepConnectProtocol = CfgGetInt(f, "KeepConnectProtocol");\r
+       c->AllowRemoteConfig = CfgGetBool(f, "AllowRemoteConfig");\r
+       c->KeepConnectInterval = MAKESURE(CfgGetInt(f, "KeepConnectInterval"), KEEP_INTERVAL_MIN, KEEP_INTERVAL_MAX);\r
+}\r
+\r
+// クライアント認証データの読み込み\r
+CLIENT_AUTH *CiLoadClientAuth(FOLDER *f)\r
+{\r
+       CLIENT_AUTH *a;\r
+       char *s;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       a = ZeroMalloc(sizeof(CLIENT_AUTH));\r
+\r
+       a->AuthType = CfgGetInt(f, "AuthType");\r
+       CfgGetStr(f, "Username", a->Username, sizeof(a->Username));\r
+\r
+       switch (a->AuthType)\r
+       {\r
+       case CLIENT_AUTHTYPE_ANONYMOUS:\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_PASSWORD:\r
+               CfgGetByte(f, "HashedPassword", a->HashedPassword, SHA1_SIZE);\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_PLAIN_PASSWORD:\r
+               b = CfgGetBuf(f, "EncryptedPassword");\r
+               if (b != NULL)\r
+               {\r
+                       s = DecryptPassword(b);\r
+                       StrCpy(a->PlainPassword, sizeof(a->PlainPassword), s);\r
+                       Free(s);\r
+                       FreeBuf(b);\r
+               }\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_CERT:\r
+               b = CfgGetBuf(f, "ClientCert");\r
+               if (b != NULL)\r
+               {\r
+                       a->ClientX = BufToX(b, false);\r
+               }\r
+               FreeBuf(b);\r
+               b = CfgGetBuf(f, "ClientKey");\r
+               if (b != NULL)\r
+               {\r
+                       a->ClientK = BufToK(b, true, false, NULL);\r
+               }\r
+               FreeBuf(b);\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_SECURE:\r
+               CfgGetStr(f, "SecurePublicCertName", a->SecurePublicCertName, sizeof(a->SecurePublicCertName));\r
+               CfgGetStr(f, "SecurePrivateKeyName", a->SecurePrivateKeyName, sizeof(a->SecurePrivateKeyName));\r
+               break;\r
+       }\r
+\r
+       return a;\r
+}\r
+\r
+// クライアントオプションの読み込み\r
+CLIENT_OPTION *CiLoadClientOption(FOLDER *f)\r
+{\r
+       CLIENT_OPTION *o;\r
+       char *s;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+\r
+       CfgGetUniStr(f, "AccountName", o->AccountName, sizeof(o->AccountName));\r
+       CfgGetStr(f, "Hostname", o->Hostname, sizeof(o->Hostname));\r
+       o->Port = CfgGetInt(f, "Port");\r
+       o->PortUDP = CfgGetInt(f, "PortUDP");\r
+       o->ProxyType = CfgGetInt(f, "ProxyType");\r
+       CfgGetStr(f, "ProxyName", o->ProxyName, sizeof(o->ProxyName));\r
+       o->ProxyPort = CfgGetInt(f, "ProxyPort");\r
+       CfgGetStr(f, "ProxyUsername", o->ProxyUsername, sizeof(o->ProxyUsername));\r
+       b = CfgGetBuf(f, "ProxyPassword");\r
+       s = DecryptPassword(b);\r
+       StrCpy(o->ProxyPassword, sizeof(o->ProxyPassword), s);\r
+       Free(s);\r
+       FreeBuf(b);\r
+       o->NumRetry = CfgGetInt(f, "NumRetry");\r
+       o->RetryInterval = CfgGetInt(f, "RetryInterval");\r
+       CfgGetStr(f, "HubName", o->HubName, sizeof(o->HubName));\r
+       o->MaxConnection = CfgGetInt(f, "MaxConnection");\r
+       o->UseEncrypt = CfgGetBool(f, "UseEncrypt");\r
+       o->UseCompress = CfgGetBool(f, "UseCompress");\r
+       o->HalfConnection = CfgGetBool(f, "HalfConnection");\r
+       o->NoRoutingTracking = CfgGetBool(f, "NoRoutingTracking");\r
+       CfgGetStr(f, "DeviceName", o->DeviceName, sizeof(o->DeviceName));\r
+       o->AdditionalConnectionInterval = CfgGetInt(f, "AdditionalConnectionInterval");\r
+       o->HideStatusWindow = CfgGetBool(f, "HideStatusWindow");\r
+       o->HideNicInfoWindow = CfgGetBool(f, "HideNicInfoWindow");\r
+       o->ConnectionDisconnectSpan = CfgGetInt(f, "ConnectionDisconnectSpan");\r
+       o->RequireMonitorMode = CfgGetBool(f, "RequireMonitorMode");\r
+       o->RequireBridgeRoutingMode = CfgGetBool(f, "RequireBridgeRoutingMode");\r
+       o->DisableQoS = CfgGetBool(f, "DisableQoS");\r
+       o->FromAdminPack = CfgGetBool(f, "FromAdminPack");\r
+       o->NoTls1 = CfgGetBool(f, "NoTls1");\r
+\r
+       return o;\r
+}\r
+\r
+// アカウントデータの読み込み\r
+ACCOUNT *CiLoadClientAccount(FOLDER *f)\r
+{\r
+       ACCOUNT *a;\r
+       FOLDER *client_option_folder, *client_auth_folder;\r
+       BUF *b;\r
+       char tmp[64];\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       client_option_folder = CfgGetFolder(f, "ClientOption");\r
+\r
+       if (client_option_folder != NULL)\r
+       {\r
+               // すでに登録されているアカウント名と一致するかどうか比較する\r
+       }\r
+\r
+       client_auth_folder = CfgGetFolder(f, "ClientAuth");\r
+\r
+       if (client_option_folder == NULL || client_auth_folder == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       a = ZeroMalloc(sizeof(ACCOUNT));\r
+       a->lock = NewLock();\r
+\r
+       a->ClientOption = CiLoadClientOption(client_option_folder);\r
+       a->ClientAuth = CiLoadClientAuth(client_auth_folder);\r
+\r
+       a->StartupAccount = CfgGetBool(f, "StartupAccount");\r
+       a->CheckServerCert = CfgGetBool(f, "CheckServerCert");\r
+       a->CreateDateTime = CfgGetInt64(f, "CreateDateTime");\r
+       a->UpdateDateTime = CfgGetInt64(f, "UpdateDateTime");\r
+       a->LastConnectDateTime = CfgGetInt64(f, "LastConnectDateTime");\r
+\r
+       b = CfgGetBuf(f, "ServerCert");\r
+       if (b != NULL)\r
+       {\r
+               a->ServerCert = BufToX(b, false);\r
+               FreeBuf(b);\r
+       }\r
+\r
+       if (CfgGetStr(f, "ShortcutKey", tmp, sizeof(tmp)))\r
+       {\r
+               BUF *b = StrToBin(tmp);\r
+               if (b->Size == SHA1_SIZE)\r
+               {\r
+                       Copy(a->ShortcutKey, b->Buf, SHA1_SIZE);\r
+               }\r
+               FreeBuf(b);\r
+       }\r
+\r
+       if (IsZero(a->ShortcutKey, SHA1_SIZE))\r
+       {\r
+               Rand(a->ShortcutKey, SHA1_SIZE);\r
+       }\r
+\r
+       return a;\r
+}\r
+\r
+// アカウントデータベースの読み込み\r
+void CiLoadAccountDatabase(CLIENT *c, FOLDER *f)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (c == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = CfgEnumFolderToTokenList(f);\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               FOLDER *ff = CfgGetFolder(f, t->Token[i]);\r
+\r
+               if (ff != NULL)\r
+               {\r
+                       ACCOUNT *a = CiLoadClientAccount(ff);\r
+                       if (a != NULL)\r
+                       {\r
+                               Add(c->AccountList, a);\r
+                       }\r
+               }\r
+       }\r
+\r
+       Sort(c->AccountList);\r
+\r
+       FreeToken(t);\r
+}\r
+\r
+// ルート CA 証明書を読み込む\r
+void CiLoadCACert(CLIENT *c, FOLDER *f)\r
+{\r
+       BUF *b;\r
+       X *x;\r
+       // 引数チェック\r
+       if (c == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = CfgGetBuf(f, "X509");\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       x = BufToX(b, false);\r
+\r
+       AddCa(c->Cedar, x);\r
+\r
+       FreeX(x);\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// ルート CA リストを読み込む\r
+void CiLoadCAList(CLIENT *c, FOLDER *f)\r
+{\r
+       CEDAR *cedar;\r
+       TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (c == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = CfgEnumFolderToTokenList(f);\r
+\r
+       cedar = c->Cedar;\r
+\r
+       LockList(cedar->CaList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < t->NumTokens;i++)\r
+               {\r
+                       FOLDER *folder = CfgGetFolder(f, t->Token[i]);\r
+                       CiLoadCACert(c, folder);\r
+               }\r
+       }\r
+       UnlockList(cedar->CaList);\r
+\r
+       FreeToken(t);\r
+}\r
+\r
+// VLAN を読み込む\r
+void CiLoadVLan(CLIENT *c, FOLDER *f)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UCHAR addr[6];\r
+       BUF *b;\r
+       UNIX_VLAN *v;\r
+       // 引数チェック\r
+       if (c == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (CfgGetStr(f, "MacAddress", tmp, sizeof(tmp)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = StrToBin(tmp);\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (b->Size != 6)\r
+       {\r
+               FreeBuf(b);\r
+               return;\r
+       }\r
+\r
+       Copy(addr, b->Buf, 6);\r
+\r
+       FreeBuf(b);\r
+\r
+       if (IsZero(addr, 6))\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = ZeroMalloc(sizeof(UNIX_VLAN));\r
+       Copy(v->MacAddress, addr, 6);\r
+       StrCpy(v->Name, sizeof(v->Name), f->Name);\r
+       v->Enabled = CfgGetBool(f, "Enabled");\r
+\r
+       Add(c->UnixVLanList, v);\r
+\r
+#ifdef OS_UNIX\r
+       UnixVLanCreate(v->Name, v->MacAddress);\r
+#endif // OS_UNIX\r
+}\r
+\r
+// VLAN リストを読み込む\r
+void CiLoadVLanList(CLIENT *c, FOLDER *f)\r
+{\r
+       TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (c == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = CfgEnumFolderToTokenList(f);\r
+\r
+       LockList(c->UnixVLanList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < t->NumTokens;i++)\r
+               {\r
+                       FOLDER *folder = CfgGetFolder(f, t->Token[i]);\r
+                       CiLoadVLan(c, folder);\r
+               }\r
+       }\r
+       UnlockList(c->UnixVLanList);\r
+\r
+       FreeToken(t);\r
+}\r
+\r
+// 設定ファイルから設定の読み込み\r
+bool CiReadSettingFromCfg(CLIENT *c, FOLDER *root)\r
+{\r
+       FOLDER *config;\r
+       FOLDER *cert;\r
+       FOLDER *db;\r
+       FOLDER *vlan;\r
+       FOLDER *cmsetting;\r
+       char user_agent[MAX_SIZE];\r
+       // 引数チェック\r
+       if (c == NULL || root == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // Config と AccountDatabase の両方が無い場合は設定を初期化する\r
+       config = CfgGetFolder(root, "Config");\r
+       if (config == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       db = CfgGetFolder(root, "AccountDatabase");\r
+       if (db == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       cmsetting = CfgGetFolder(root, "ClientManagerSetting");\r
+\r
+       CiLoadClientConfig(&c->Config, config);\r
+\r
+       // 自動ファイル削除器\r
+       c->Eraser = NewEraser(c->Logger, CfgGetInt64(config, "AutoDeleteCheckDiskFreeSpaceMin"));\r
+\r
+       if (OS_IS_UNIX(GetOsInfo()->OsType) && GetOsInfo()->OsType != OSTYPE_MACOS_X)\r
+       {\r
+               // Unix 版仮想 LAN カード一覧の読み込み (MacOS の場合はしない)\r
+               vlan = CfgGetFolder(root, "UnixVLan");\r
+               if (vlan != NULL)\r
+               {\r
+                       CiLoadVLanList(c, vlan);\r
+               }\r
+       }\r
+\r
+       if (GetOsInfo()->OsType == OSTYPE_MACOS_X)\r
+       {\r
+#ifdef OS_UNIX\r
+               UNIX_VLAN *uv;\r
+\r
+               // MacOS X の場合は Tap を作成する\r
+               if (UnixVLanCreate(CLIENT_MACOS_TAP_NAME, NULL) == false)\r
+               {\r
+                       // 失敗 (強制終了)\r
+                       CLog(c, "LC_TAP_NOT_FOUND");\r
+                       Alert("tun/tap driver not found.", NULL);\r
+                       exit(0);\r
+               }\r
+\r
+               uv = ZeroMalloc(sizeof(UNIX_VLAN));\r
+               uv->Enabled = true;\r
+               StrCpy(uv->Name, sizeof(uv->Name), CLIENT_MACOS_TAP_NAME);\r
+               Add(c->UnixVLanList, uv);\r
+#endif // OS_UNIX\r
+       }\r
+\r
+       CiLoadAccountDatabase(c, db);\r
+\r
+       if (CfgGetByte(root, "EncryptedPassword", c->EncryptedPassword, SHA1_SIZE) == false)\r
+       {\r
+               Hash(c->EncryptedPassword, "", 0, true);\r
+       }\r
+\r
+       c->PasswordRemoteOnly = CfgGetBool(root, "PasswordRemoteOnly");\r
+       c->UseSecureDeviceId = CfgGetInt(root, "UseSecureDeviceId");\r
+\r
+       if (CfgGetStr(root, "UserAgent", user_agent, sizeof(user_agent)))\r
+       {\r
+               if (IsEmptyStr(user_agent) == false)\r
+               {\r
+                       Free(c->Cedar->HttpUserAgent);\r
+                       c->Cedar->HttpUserAgent = CopyStr(user_agent);\r
+               }\r
+       }\r
+\r
+       cert = CfgGetFolder(root, "RootCA");\r
+       if (cert != NULL)\r
+       {\r
+               CiLoadCAList(c, cert);\r
+       }\r
+\r
+       c->DontSavePassword = CfgGetBool(root, "DontSavePassword");\r
+\r
+       if (cmsetting != NULL)\r
+       {\r
+               UINT ostype = GetOsInfo()->OsType;\r
+               // CM_SETTING\r
+               CM_SETTING *s = c->CmSetting;\r
+\r
+               if (OS_IS_UNIX(ostype) || OS_IS_WINDOWS_NT(ostype))\r
+               {\r
+                       s->EasyMode = CfgGetBool(cmsetting, "EasyMode");\r
+               }\r
+\r
+               s->LockMode = CfgGetBool(cmsetting, "LockMode");\r
+               CfgGetByte(cmsetting, "HashedPassword", s->HashedPassword, sizeof(s->HashedPassword));\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 設定ファイルの読み込み\r
+bool CiLoadConfigurationFile(CLIENT *c)\r
+{\r
+       bool ret;\r
+       FOLDER *root;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 設定ファイルの読み込み\r
+       c->CfgRw = NewCfgRw(&root, CLIENT_CONFIG_FILE_NAME);\r
+\r
+       if (root == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = CiReadSettingFromCfg(c, root);\r
+\r
+       CfgDeleteFolder(root);\r
+\r
+       return ret;\r
+}\r
+\r
+// CLIENT_CONFIG を書き込む\r
+void CiWriteClientConfig(FOLDER *cc, CLIENT_CONFIG *config)\r
+{\r
+       // 引数チェック\r
+       if (cc == NULL || config == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CfgAddBool(cc, "UseKeepConnect", config->UseKeepConnect);\r
+       CfgAddStr(cc, "KeepConnectHost", config->KeepConnectHost);\r
+       CfgAddInt(cc, "KeepConnectPort", config->KeepConnectPort);\r
+       CfgAddInt(cc, "KeepConnectProtocol", config->KeepConnectProtocol);\r
+       CfgAddBool(cc, "AllowRemoteConfig", config->AllowRemoteConfig);\r
+       CfgAddInt(cc, "KeepConnectInterval", config->KeepConnectInterval);\r
+}\r
+\r
+// クライアント認証データを書き込む\r
+void CiWriteClientAuth(FOLDER *f, CLIENT_AUTH *a)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (f == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CfgAddInt(f, "AuthType", a->AuthType);\r
+       CfgAddStr(f, "Username", a->Username);\r
+\r
+       switch (a->AuthType)\r
+       {\r
+       case CLIENT_AUTHTYPE_ANONYMOUS:\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_PASSWORD:\r
+               CfgAddByte(f, "HashedPassword", a->HashedPassword, SHA1_SIZE);\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_PLAIN_PASSWORD:\r
+               b = EncryptPassword(a->PlainPassword);\r
+               CfgAddByte(f, "EncryptedPassword", b->Buf, b->Size);\r
+               FreeBuf(b);\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_CERT:\r
+               if (a->ClientK != NULL && a->ClientX != NULL)\r
+               {\r
+                       b = XToBuf(a->ClientX, false);\r
+                       CfgAddByte(f, "ClientCert", b->Buf, b->Size);\r
+                       FreeBuf(b);\r
+\r
+                       b = KToBuf(a->ClientK, false, NULL);\r
+                       CfgAddByte(f, "ClientKey", b->Buf, b->Size);\r
+                       FreeBuf(b);\r
+               }\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_SECURE:\r
+               CfgAddStr(f, "SecurePublicCertName", a->SecurePublicCertName);\r
+               CfgAddStr(f, "SecurePrivateKeyName", a->SecurePrivateKeyName);\r
+               break;\r
+       }\r
+}\r
+\r
+// クライアントオプションを書き込む\r
+void CiWriteClientOption(FOLDER *f, CLIENT_OPTION *o)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (f == NULL || o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CfgAddUniStr(f, "AccountName", o->AccountName);\r
+       CfgAddStr(f, "Hostname", o->Hostname);\r
+       CfgAddInt(f, "Port", o->Port);\r
+       CfgAddInt(f, "PortUDP", o->PortUDP);\r
+       CfgAddInt(f, "ProxyType", o->ProxyType);\r
+       CfgAddStr(f, "ProxyName", o->ProxyName);\r
+       CfgAddInt(f, "ProxyPort", o->ProxyPort);\r
+       CfgAddStr(f, "ProxyUsername", o->ProxyUsername);\r
+       b = EncryptPassword(o->ProxyPassword);\r
+       CfgAddByte(f, "ProxyPassword", b->Buf, b->Size);\r
+       FreeBuf(b);\r
+       CfgAddInt(f, "NumRetry", o->NumRetry);\r
+       CfgAddInt(f, "RetryInterval", o->RetryInterval);\r
+       CfgAddStr(f, "HubName", o->HubName);\r
+       CfgAddInt(f, "MaxConnection", o->MaxConnection);\r
+       CfgAddBool(f, "UseEncrypt", o->UseEncrypt);\r
+       CfgAddBool(f, "UseCompress", o->UseCompress);\r
+       CfgAddBool(f, "HalfConnection", o->HalfConnection);\r
+       CfgAddBool(f, "NoRoutingTracking", o->NoRoutingTracking);\r
+       CfgAddStr(f, "DeviceName", o->DeviceName);\r
+       CfgAddInt(f, "AdditionalConnectionInterval", o->AdditionalConnectionInterval);\r
+       CfgAddBool(f, "HideStatusWindow", o->HideStatusWindow);\r
+       CfgAddBool(f, "HideNicInfoWindow", o->HideNicInfoWindow);\r
+       CfgAddInt(f, "ConnectionDisconnectSpan", o->ConnectionDisconnectSpan);\r
+       CfgAddBool(f, "RequireMonitorMode", o->RequireMonitorMode);\r
+       CfgAddBool(f, "RequireBridgeRoutingMode", o->RequireBridgeRoutingMode);\r
+       CfgAddBool(f, "DisableQoS", o->DisableQoS);\r
+       CfgAddBool(f, "NoTls1", o->NoTls1);\r
+\r
+       if (o->FromAdminPack)\r
+       {\r
+               CfgAddBool(f, "FromAdminPack", o->FromAdminPack);\r
+       }\r
+}\r
+\r
+// パスワードの解読\r
+char *DecryptPassword(BUF *b)\r
+{\r
+       char *str;\r
+       char *key = "EncryptPassword";\r
+       CRYPT *c;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return CopyStr("");\r
+       }\r
+\r
+       str = ZeroMalloc(b->Size + 1);\r
+       c = NewCrypt(key, sizeof(key));\r
+       Encrypt(c, str, b->Buf, b->Size);\r
+       FreeCrypt(c);\r
+\r
+       str[b->Size] = 0;\r
+\r
+       return str;\r
+}\r
+\r
+// パスワードの暗号化\r
+BUF *EncryptPassword(char *password)\r
+{\r
+       UCHAR *tmp;\r
+       UINT size;\r
+       char *key = "EncryptPassword";\r
+       CRYPT *c;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (password == NULL)\r
+       {\r
+               password = "";\r
+       }\r
+\r
+       size = StrLen(password) + 1;\r
+       tmp = ZeroMalloc(size);\r
+\r
+       c = NewCrypt(key, sizeof(key));\r
+       Encrypt(c, tmp, password, size - 1);\r
+       FreeCrypt(c);\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, tmp, size - 1);\r
+       SeekBuf(b, 0, 0);\r
+       Free(tmp);\r
+\r
+       return b;\r
+}\r
+\r
+// アカウントデータを書き込む\r
+void CiWriteAccountData(FOLDER *f, ACCOUNT *a)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // クライアントオプション\r
+       CiWriteClientOption(CfgCreateFolder(f, "ClientOption"), a->ClientOption);\r
+\r
+       // クライアント認証データ\r
+       CiWriteClientAuth(CfgCreateFolder(f, "ClientAuth"), a->ClientAuth);\r
+\r
+       // スタートアップアカウント\r
+       CfgAddBool(f, "StartupAccount", a->StartupAccount);\r
+\r
+       // サーバー証明書チェックフラグ\r
+       CfgAddBool(f, "CheckServerCert", a->CheckServerCert);\r
+\r
+       // 日時\r
+       CfgAddInt64(f, "CreateDateTime", a->CreateDateTime);\r
+       CfgAddInt64(f, "UpdateDateTime", a->UpdateDateTime);\r
+       CfgAddInt64(f, "LastConnectDateTime", a->LastConnectDateTime);\r
+\r
+       // サーバー証明書本体\r
+       if (a->ServerCert != NULL)\r
+       {\r
+               BUF *b = XToBuf(a->ServerCert, false);\r
+               if (b != NULL)\r
+               {\r
+                       CfgAddBuf(f, "ServerCert", b);\r
+                       FreeBuf(b);\r
+               }\r
+       }\r
+\r
+       // ショートカットキー\r
+       if (IsZero(a->ShortcutKey, SHA1_SIZE) == false)\r
+       {\r
+               char tmp[64];\r
+               BinToStr(tmp, sizeof(tmp), a->ShortcutKey, SHA1_SIZE);\r
+               CfgAddStr(f, "ShortcutKey", tmp);\r
+       }\r
+}\r
+\r
+// アカウントデータベースを書き込む\r
+void CiWriteAccountDatabase(CLIENT *c, FOLDER *f)\r
+{\r
+       char name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (c == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(c->AccountList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(c->AccountList);i++)\r
+               {\r
+                       ACCOUNT *a = LIST_DATA(c->AccountList, i);\r
+                       Format(name, sizeof(name), "Account%u", i);\r
+                       Lock(a->lock);\r
+                       {\r
+                               CiWriteAccountData(CfgCreateFolder(f, name), a);\r
+                       }\r
+                       Unlock(a->lock);\r
+               }\r
+       }\r
+       UnlockList(c->AccountList);\r
+}\r
+\r
+// CA 証明書を書き込む\r
+void CiWriteCACert(CLIENT *c, FOLDER *f, X *x)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (c == NULL || f == NULL || x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = XToBuf(x, false);\r
+       CfgAddBuf(f, "X509", b);\r
+       FreeBuf(b);\r
+}\r
+\r
+// VLAN を書き込む\r
+void CiWriteVLan(CLIENT *c, FOLDER *f, UNIX_VLAN *v)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (c == NULL || f == NULL || v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MacToStr(tmp, sizeof(tmp), v->MacAddress);\r
+       CfgAddStr(f, "MacAddress", tmp);\r
+       CfgAddBool(f, "Enabled", v->Enabled);\r
+}\r
+\r
+// VLAN リストを書き込む\r
+void CiWriteVLanList(CLIENT *c, FOLDER *f)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(c->UnixVLanList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(c->UnixVLanList);i++)\r
+               {\r
+                       UNIX_VLAN *v = LIST_DATA(c->UnixVLanList, i);\r
+                       CiWriteVLan(c, CfgCreateFolder(f, v->Name), v);\r
+               }\r
+       }\r
+       UnlockList(c->UnixVLanList);\r
+}\r
+\r
+// CA リストを書き込む\r
+void CiWriteCAList(CLIENT *c, FOLDER *f)\r
+{\r
+       CEDAR *cedar;\r
+       // 引数チェック\r
+       if (c == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       cedar = c->Cedar;\r
+\r
+       LockList(cedar->CaList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(cedar->CaList);i++)\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+                       X *x = LIST_DATA(cedar->CaList, i);\r
+                       Format(tmp, sizeof(tmp), "Certificate%u", i);\r
+                       CiWriteCACert(c, CfgCreateFolder(f, tmp), x);\r
+               }\r
+       }\r
+       UnlockList(cedar->CaList);\r
+}\r
+\r
+// 現在の設定を ROOT に書き込む\r
+void CiWriteSettingToCfg(CLIENT *c, FOLDER *root)\r
+{\r
+       FOLDER *cc;\r
+       FOLDER *account_database;\r
+       FOLDER *ca;\r
+       FOLDER *vlan;\r
+       FOLDER *cmsetting;\r
+       // 引数チェック\r
+       if (c == NULL || root == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       cmsetting = CfgCreateFolder(root, "ClientManagerSetting");\r
+\r
+       // CLIENT_CONFIG\r
+       cc = CfgCreateFolder(root, "Config");\r
+       CiWriteClientConfig(cc, &c->Config);\r
+\r
+       // 自動ファイル削除器\r
+       CfgAddInt64(cc, "AutoDeleteCheckDiskFreeSpaceMin", c->Eraser->MinFreeSpace);\r
+\r
+       // Account Database\r
+       account_database = CfgCreateFolder(root, "AccountDatabase");\r
+       CiWriteAccountDatabase(c, account_database);\r
+\r
+       // CA\r
+       ca = CfgCreateFolder(root, "RootCA");\r
+       CiWriteCAList(c, ca);\r
+\r
+       // VLAN\r
+       if (OS_IS_UNIX(GetOsInfo()->OsType) && GetOsInfo()->OsType != OSTYPE_MACOS_X)\r
+       {\r
+               vlan = CfgCreateFolder(root, "UnixVLan");\r
+               CiWriteVLanList(c, vlan);\r
+       }\r
+\r
+       // Password\r
+       CfgAddByte(root, "EncryptedPassword", c->EncryptedPassword, SHA1_SIZE);\r
+       CfgAddBool(root, "PasswordRemoteOnly", c->PasswordRemoteOnly);\r
+\r
+       // UseSecureDeviceId\r
+       CfgAddInt(root, "UseSecureDeviceId", c->UseSecureDeviceId);\r
+\r
+       // DontSavePassword\r
+       CfgAddBool(root, "DontSavePassword", c->DontSavePassword);\r
+\r
+       // UserAgent\r
+       if (c->Cedar != NULL)\r
+       {\r
+               CfgAddStr(root, "UserAgent", c->Cedar->HttpUserAgent);\r
+       }\r
+\r
+       if (cmsetting != NULL)\r
+       {\r
+               CM_SETTING *s = c->CmSetting;\r
+\r
+               CfgAddBool(cmsetting, "EasyMode", s->EasyMode);\r
+               CfgAddBool(cmsetting, "LockMode", s->LockMode);\r
+\r
+               if (IsZero(s->HashedPassword, sizeof(s->HashedPassword)) == false)\r
+               {\r
+                       CfgAddByte(cmsetting, "HashedPassword", s->HashedPassword, sizeof(s->HashedPassword));\r
+               }\r
+       }\r
+}\r
+\r
+// 設定ファイルへ書き込み\r
+void CiSaveConfigurationFile(CLIENT *c)\r
+{\r
+       FOLDER *root;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+       \r
+       // 設定ファイルを保存しない\r
+       if(c->NoSaveConfig)\r
+       {\r
+               return;\r
+       }\r
+\r
+       root = CfgCreateFolder(NULL, TAG_ROOT);\r
+       CiWriteSettingToCfg(c, root);\r
+\r
+       SaveCfgRw(c->CfgRw, root);\r
+\r
+       CfgDeleteFolder(root);\r
+}\r
+\r
+// CM_SETTING の設定\r
+bool CtSetCmSetting(CLIENT *c, CM_SETTING *s)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Copy(c->CmSetting, s, sizeof(CM_SETTING));\r
+\r
+       CiSaveConfigurationFile(c);\r
+\r
+       return true;\r
+}\r
+\r
+// CM_SETTING の取得\r
+bool CtGetCmSetting(CLIENT *c, CM_SETTING *s)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Copy(s, c->CmSetting, sizeof(CM_SETTING));\r
+       \r
+       return true;\r
+}\r
+\r
+// クライアントバージョンの取得\r
+bool CtGetClientVersion(CLIENT *c, RPC_CLIENT_VERSION *ver)\r
+{\r
+       // 引数チェック\r
+       if (ver == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(ver, sizeof(RPC_CLIENT_VERSION));\r
+       StrCpy(ver->ClientProductName, sizeof(ver->ClientProductName), CEDAR_CLIENT_STR);\r
+       StrCpy(ver->ClientVersionString, sizeof(ver->ClientVersionString), c->Cedar->VerString);\r
+       StrCpy(ver->ClientBuildInfoString, sizeof(ver->ClientBuildInfoString), c->Cedar->BuildInfo);\r
+       ver->ClientVerInt = c->Cedar->Version;\r
+       ver->ClientBuildInt = c->Cedar->Build;\r
+\r
+#ifdef OS_WIN32\r
+       ver->ProcessId = MsGetProcessId();\r
+#endif // OS_WIN32\r
+\r
+       ver->OsType = GetOsInfo()->OsType;\r
+\r
+       return true;\r
+}\r
+\r
+// クライアントオブジェクトの作成\r
+CLIENT *CiNewClient()\r
+{\r
+       CLIENT *c = ZeroMalloc(sizeof(CLIENT));\r
+\r
+//     StartCedarLog();\r
+\r
+       c->CmSetting = ZeroMalloc(sizeof(CM_SETTING));\r
+\r
+       c->SockList = NewSockList();\r
+\r
+       c->lock = NewLock();\r
+       c->lockForConnect = NewLock();\r
+       c->ref = NewRef();\r
+\r
+       c->Cedar = NewCedar(NULL, NULL);\r
+\r
+       c->Cedar->Client = c;\r
+\r
+       c->NotifyCancelList = NewList(NULL);\r
+\r
+       Hash(c->EncryptedPassword, "", 0, true);\r
+\r
+       // ログ設定\r
+       if(c->NoSaveLog == false)\r
+       {\r
+               MakeDir(CLIENT_LOG_DIR_NAME);\r
+               c->Logger = NewLog(CLIENT_LOG_DIR_NAME, CLIENT_LOG_PREFIX, LOG_SWITCH_DAY);\r
+       }\r
+\r
+       CLog(c, "L_LINE");\r
+       CLog(c, "LC_START_2", CEDAR_CLIENT_STR, c->Cedar->VerString);\r
+       CLog(c, "LC_START_3", c->Cedar->BuildInfo);\r
+       CLog(c, "LC_START_1");\r
+\r
+#ifdef OS_WIN32\r
+       {\r
+               // Win32 UI の初期化\r
+               wchar_t tmp[MAX_SIZE];\r
+               StrToUni(tmp, sizeof(tmp), CEDAR_CLIENT_STR);\r
+\r
+               InitWinUi(tmp, _SS("DEFAULT_FONT"), _II("DEFAULT_FONT_SIZE"));\r
+       }\r
+#endif // OS_WIN32\r
+\r
+       // 設定の初期化\r
+       CiInitConfiguration(c);\r
+\r
+       // 優先順位を上げる\r
+       OSSetHighPriority();\r
+\r
+#ifdef OS_WIN32\r
+       // Win9x の場合、すべての仮想 LAN カードの DHCP アドレスを解放する\r
+       if (MsIsNt() == false)\r
+       {\r
+               Win32ReleaseAllDhcp9x(true);\r
+       }\r
+#endif // OS_WIN32\r
+\r
+       CiChangeAllVLanMacAddressIfMachineChanged(c);\r
+\r
+       return c;\r
+}\r
+\r
+// クライアントのクリーンアップ\r
+void CiCleanupClient(CLIENT *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 設定の解放\r
+       CiFreeConfiguration(c);\r
+\r
+#ifdef OS_WIN32\r
+       // Win32 UI の解放\r
+       FreeWinUi();\r
+#endif // OS_WIN32\r
+\r
+       CLog(c, "LC_END");\r
+       CLog(c, "L_LINE");\r
+       FreeEraser(c->Eraser);\r
+       FreeLog(c->Logger);\r
+       c->Logger = NULL;\r
+\r
+       ReleaseCedar(c->Cedar);\r
+\r
+       DeleteLock(c->lockForConnect);\r
+       DeleteLock(c->lock);\r
+\r
+       ReleaseList(c->NotifyCancelList);\r
+\r
+       FreeSockList(c->SockList);\r
+\r
+       Free(c->CmSetting);\r
+\r
+       Free(c);\r
+\r
+#ifdef OS_WIN32\r
+       // Win9x の場合、すべての仮想 LAN カードの DHCP アドレスを解放する\r
+       if (MsIsNt() == false)\r
+       {\r
+               Win32ReleaseAllDhcp9x(true);\r
+       }\r
+#endif // OS_WIN32\r
+\r
+       StopCedarLog();\r
+}\r
+\r
+// クライアントの解放\r
+void CtReleaseClient(CLIENT *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(c->ref) == 0)\r
+       {\r
+               CiCleanupClient(c);\r
+       }\r
+}\r
+\r
+// クライアントプログラムの動作開始\r
+void CtStartClient()\r
+{\r
+       UINT i;\r
+       LIST *o;\r
+       if (client != NULL)\r
+       {\r
+               // すでに動作している\r
+               return;\r
+       }\r
+\r
+       // OS チェック\r
+       CiCheckOs();\r
+\r
+#ifdef OS_WIN32\r
+       RegistWindowsFirewallAll();\r
+#endif\r
+\r
+       // クライアントの作成\r
+       client = CiNewClient();\r
+\r
+       // Keep を開始\r
+       CiInitKeep(client);\r
+\r
+       // RPC サーバーを開始\r
+       CiStartRpcServer(client);\r
+\r
+       // 設定データ自動保存を開始\r
+       CiInitSaver(client);\r
+\r
+       // スタートアップ接続を開始する\r
+       o = NewListFast(NULL);\r
+       LockList(client->AccountList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(client->AccountList);i++)\r
+               {\r
+                       ACCOUNT *a = LIST_DATA(client->AccountList, i);\r
+                       Lock(a->lock);\r
+                       {\r
+                               if (a->StartupAccount)\r
+                               {\r
+                                       Add(o, CopyUniStr(a->ClientOption->AccountName));\r
+                               }\r
+                       }\r
+                       Unlock(a->lock);\r
+               }\r
+       }\r
+       UnlockList(client->AccountList);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               wchar_t *s = LIST_DATA(o, i);\r
+               RPC_CLIENT_CONNECT c;\r
+               Zero(&c, sizeof(c));\r
+               UniStrCpy(c.AccountName, sizeof(c.AccountName), s);\r
+               CtConnect(client, &c);\r
+               Free(s);\r
+       }\r
+       ReleaseList(o);\r
+}\r
+\r
+// クライアントプログラムの動作終了\r
+void CtStopClient()\r
+{\r
+       UINT i, num;\r
+       ACCOUNT **account_list;\r
+       if (client == NULL)\r
+       {\r
+               // まだ動作していない\r
+               return;\r
+       }\r
+\r
+       // 停止フラグ\r
+       client->Halt = true;\r
+\r
+       // RPC をすべて切断\r
+       CiStopRpcServer(client);\r
+\r
+       // クライアント通知サービスを終了\r
+       CncExit();\r
+\r
+       // Keep を終了\r
+       CiFreeKeep(client);\r
+\r
+       // 接続中のアカウントをすべて切断\r
+       LockList(client->AccountList);\r
+       {\r
+               num = LIST_NUM(client->AccountList);\r
+               account_list = ToArray(client->AccountList);\r
+       }\r
+       UnlockList(client->AccountList);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               ACCOUNT *a = account_list[i];\r
+               SESSION *s = NULL;\r
+\r
+               Lock(a->lock);\r
+               {\r
+                       if (a->ClientSession != NULL)\r
+                       {\r
+                               s = a->ClientSession;\r
+                               AddRef(s->ref);\r
+                       }\r
+               }\r
+               Unlock(a->lock);\r
+\r
+               if (s != NULL)\r
+               {\r
+                       StopSession(s);\r
+                       ReleaseSession(s);\r
+                       Lock(a->lock);\r
+                       {\r
+                               if (a->ClientSession != NULL)\r
+                               {\r
+                                       ReleaseSession(a->ClientSession);\r
+                                       a->ClientSession = NULL;\r
+                               }\r
+                       }\r
+                       Unlock(a->lock);\r
+               }\r
+       }\r
+\r
+       Free(account_list);\r
+\r
+       // 設定データ自動保存を停止\r
+       CiFreeSaver(client);\r
+\r
+       // クライアントの解放\r
+       CtReleaseClient(client);\r
+       client = NULL;\r
+}\r
+\r
+// OS チェック\r
+void CiCheckOs()\r
+{\r
+       // OS の種類の取得\r
+       OS_INFO *info = GetOsInfo();\r
+\r
+       if (OS_IS_WINDOWS(info->OsType))\r
+       {\r
+               bool ok = IS_CLIENT_SUPPORTED_OS(info->OsType);\r
+\r
+               if (ok == false)\r
+               {\r
+                       Alert(\r
+                               "SoftEther UT-VPN Client doesn't support this Windows Operating System.\n"\r
+                               "SoftEther UT-VPN Client requires Windows 98 SE, Windows Me, Windows 2000, Windows XP, Windows Server 2003 or Greater.\n\n"\r
+                               "Please contact your system administrator.", "SoftEther UT-VPN Client");\r
+                       exit(0);\r
+               }\r
+       }\r
+}\r
+\r
+// クライアントオブジェクトの取得\r
+CLIENT *CtGetClient()\r
+{\r
+       if (client == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       AddRef(client->ref);\r
+\r
+       return client;\r
+}\r
+\r
+// クライアントステータス表示器\r
+void CiClientStatusPrinter(SESSION *s, wchar_t *status)\r
+{\r
+#ifdef OS_WIN32\r
+       ACCOUNT *a;\r
+       // 引数チェック\r
+       if (s == NULL || status == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       a = s->Account;\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (UniStrCmpi(status, L"init") == 0)\r
+       {\r
+               if (a->StatusWindow == NULL && s->Win32HideConnectWindow == false)\r
+               {\r
+                       a->StatusWindow = CncStatusPrinterWindowStart(s);\r
+               }\r
+       }\r
+       else if (UniStrCmpi(status, L"free") == 0)\r
+       {\r
+               if (a->StatusWindow != NULL)\r
+               {\r
+                       CncStatusPrinterWindowStop(a->StatusWindow);\r
+                       a->StatusWindow = NULL;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (a->StatusWindow != NULL)\r
+               {\r
+                       CncStatusPrinterWindowPrint(a->StatusWindow, status);\r
+               }\r
+       }\r
+#else  // OS_WIN32\r
+       UniPrint(L"Status: %s\n", status);\r
+#endif // OS_WIN32\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Client.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Client.h
new file mode 100644 (file)
index 0000000..4aae830
--- /dev/null
@@ -0,0 +1,787 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Client.h\r
+// Client.c のヘッダ\r
+\r
+#ifndef        CLIENT_H\r
+#define        CLIENT_H\r
+\r
+#define        CLIENT_CONFIG_PORT                                      9930            // クライアントポート番号\r
+#define        CLIENT_NOTIFY_PORT                                      9983            // クライアント通知ポート番号\r
+#define CLIENT_WAIT_CN_READY_TIMEOUT           (10 * 1000)     // クライアント通知サービスが起動するまでの待機時間\r
+\r
+\r
+// クライアントが指定された OS_TYPE で稼動するかどうかチェック\r
+#define        IS_CLIENT_SUPPORTED_OS(t)                       \\r
+       ((OS_IS_WINDOWS_NT(t) && GET_KETA(t, 100) >= 2) || (OS_IS_WINDOWS_9X(t)))\r
+\r
+\r
+// 定数\r
+#define        CLIENT_CONFIG_FILE_NAME                         "@vpn_client.config"\r
+#define        CLIENT_DEFAULT_KEEPALIVE_HOST           "keepalive.utvpn.tsukuba.ac.jp"\r
+#define        CLIENT_DEFAULT_KEEPALIVE_PORT           80\r
+#define        CLIENT_DEFAULT_KEEPALIVE_INTERVAL       KEEP_INTERVAL_DEFAULT\r
+\r
+#define        CLIENT_RPC_MODE_NOTIFY                          0\r
+#define        CLIENT_RPC_MODE_MANAGEMENT                      1\r
+#define        CLIENT_RPC_MODE_SHORTCUT                        2\r
+#define        CLIENT_RPC_MODE_SHORTCUT_DISCONNECT     3\r
+\r
+#define        CLIENT_MACOS_TAP_NAME                           "tap0"\r
+\r
+#define        CLIENT_SAVER_INTERVAL                           (30 * 1000)\r
+\r
+#define        CLIENT_NOTIFY_SERVICE_INSTANCENAME      "utvpnclient_uihelper"\r
+\r
+#define        CLIENT_WIN32_EXE_FILENAME                       "utvpnclient.exe"\r
+#define        CLIENT_WIN32_EXE_FILENAME_X64           "utvpnclient_x64.exe"\r
+#define        CLIENT_WIN32_EXE_FILENAME_IA64          "utvpnclient_ia64.exe"\r
+\r
+#define CLIENT_CUSTOM_INI_FILENAME                     "@custom.ini"\r
+\r
+\r
+// UNIX における仮想 LAN カードの一覧\r
+struct UNIX_VLAN\r
+{\r
+       bool Enabled;                                                   // 有効フラグ\r
+       char Name[MAX_SIZE];                                    // 名前\r
+       UCHAR MacAddress[6];                                    // MAC アドレス\r
+       UCHAR Padding[2];\r
+};\r
+\r
+// アカウント\r
+struct ACCOUNT\r
+{\r
+       // 静的データ\r
+       CLIENT_OPTION *ClientOption;                    // クライアント オプション\r
+       CLIENT_AUTH *ClientAuth;                                // クライアント認証データ\r
+       bool CheckServerCert;                                   // サーバー証明書をチェックする\r
+       X *ServerCert;                                                  // サーバー証明書\r
+       bool StartupAccount;                                    // スタートアップアカウントにする\r
+       UCHAR ShortcutKey[SHA1_SIZE];                   // キー\r
+       UINT64 CreateDateTime;                                  // 作成日時\r
+       UINT64 UpdateDateTime;                                  // 更新日時\r
+       UINT64 LastConnectDateTime;                             // 最終接続日時\r
+\r
+       // 動的データ\r
+       LOCK *lock;                                                             // ロック\r
+       SESSION *ClientSession;                                 // クライアントセッション\r
+       CLIENT_STATUS_PRINTER *StatusPrinter;   // ステータス表示器\r
+\r
+       SOCK *StatusWindow;                                             // ステータスウインドウ\r
+};\r
+\r
+// クライアント設定\r
+struct CLIENT_CONFIG\r
+{\r
+       bool AllowRemoteConfig;                                 // リモート設定を許可する\r
+       bool UseKeepConnect;                                    // インターネットへの接続を維持\r
+       char KeepConnectHost[MAX_HOST_NAME_LEN + 1];    // ホスト名\r
+       UINT KeepConnectPort;                                   // ポート番号\r
+       UINT KeepConnectProtocol;                               // プロトコル\r
+       UINT KeepConnectInterval;                               // 間隔\r
+};\r
+\r
+// バージョン取得\r
+struct RPC_CLIENT_VERSION\r
+{\r
+       char ClientProductName[128];            // クライアント製品名\r
+       char ClientVersionString[128];          // クライアントバージョン文字列\r
+       char ClientBuildInfoString[128];        // クライアントビルド情報文字列\r
+       UINT ClientVerInt;                                      // クライアントバージョン整数値\r
+       UINT ClientBuildInt;                            // クライアントビルド番号整数値\r
+       UINT ProcessId;                                         // プロセス ID\r
+       UINT OsType;                                            // OS の種類\r
+};\r
+\r
+// パスワード設定\r
+struct RPC_CLIENT_PASSWORD\r
+{\r
+       char Password[MAX_PASSWORD_LEN + 1];    // パスワード\r
+       bool PasswordRemoteOnly;                                // パスワードはリモートのみ必要\r
+};\r
+\r
+// パスワード設定の取得\r
+struct RPC_CLIENT_PASSWORD_SETTING\r
+{\r
+       bool IsPasswordPresented;                               // パスワードが存在する\r
+       bool PasswordRemoteOnly;                                // パスワードはリモートのみ必要\r
+};\r
+\r
+// 証明書列挙項目\r
+struct RPC_CLIENT_ENUM_CA_ITEM\r
+{\r
+       UINT Key;                                                               // 証明書キー\r
+       wchar_t SubjectName[MAX_SIZE];                  // 発行先\r
+       wchar_t IssuerName[MAX_SIZE];                   // 発行者\r
+       UINT64 Expires;                                                 // 有効期限\r
+};\r
+\r
+// 証明書列挙\r
+struct RPC_CLIENT_ENUM_CA\r
+{\r
+       UINT NumItem;                                                   // 項目数\r
+       RPC_CLIENT_ENUM_CA_ITEM **Items;                // 項目\r
+};\r
+\r
+// 証明書項目\r
+struct RPC_CERT\r
+{\r
+       X *x;                                                                   // 証明書\r
+};\r
+\r
+// 証明書削除\r
+struct RPC_CLIENT_DELETE_CA\r
+{\r
+       UINT Key;                                                               // 証明書キー\r
+};\r
+\r
+// 証明書の取得\r
+struct RPC_GET_CA\r
+{\r
+       UINT Key;                                                               // 証明書キー\r
+       X *x;                                                                   // 証明書\r
+};\r
+\r
+// 署名者の取得\r
+struct RPC_GET_ISSUER\r
+{\r
+       X *x;                                                                   // 証明書\r
+       X *issuer_x;                                                    // 署名者\r
+};\r
+\r
+// セキュアデバイス列挙項目\r
+struct RPC_CLIENT_ENUM_SECURE_ITEM\r
+{\r
+       UINT DeviceId;                                                  // デバイス ID\r
+       UINT Type;                                                              // 種別\r
+       char DeviceName[MAX_SIZE];                              // デバイス名\r
+       char Manufacturer[MAX_SIZE];                    // 製造元\r
+};\r
+\r
+// セキュアデバイスの列挙\r
+struct RPC_CLIENT_ENUM_SECURE\r
+{\r
+       UINT NumItem;                                                   // 項目数\r
+       RPC_CLIENT_ENUM_SECURE_ITEM **Items;    // 項目\r
+};\r
+\r
+// セキュアデバイス指定\r
+struct RPC_USE_SECURE\r
+{\r
+       UINT DeviceId;                                                  // デバイス ID\r
+};\r
+\r
+// セキュアデバイス内オブジェクト列挙\r
+struct RPC_ENUM_OBJECT_IN_SECURE\r
+{\r
+       UINT hWnd;                                                              // ウインドウハンドル\r
+       UINT NumItem;                                                   // 項目数\r
+       char **ItemName;                                                // 項目名\r
+       bool *ItemType;                                                 // 種類 (true=秘密鍵, false=公開鍵)\r
+};\r
+\r
+// 仮想 LAN の作成\r
+struct RPC_CLIENT_CREATE_VLAN\r
+{\r
+       char DeviceName[MAX_SIZE];                              // デバイス名\r
+};\r
+\r
+// 仮想 LAN 情報の取得\r
+struct RPC_CLIENT_GET_VLAN\r
+{\r
+       char DeviceName[MAX_SIZE];                              // デバイス名\r
+       bool Enabled;                                                   // 動作しているかどうかのフラグ\r
+       char MacAddress[MAX_SIZE];                              // MAC アドレス\r
+       char Version[MAX_SIZE];                                 // バージョン\r
+       char FileName[MAX_SIZE];                                // ドライバファイル名\r
+       char Guid[MAX_SIZE];                                    // GUID\r
+};\r
+\r
+// 仮想 LAN 情報の設定\r
+struct RPC_CLIENT_SET_VLAN\r
+{\r
+       char DeviceName[MAX_SIZE];                              // デバイス名\r
+       char MacAddress[MAX_SIZE];                              // MAC アドレス\r
+};\r
+\r
+// 仮想 LAN 列挙アイテム\r
+struct RPC_CLIENT_ENUM_VLAN_ITEM\r
+{\r
+       char DeviceName[MAX_SIZE];                              // デバイス名\r
+       bool Enabled;                                                   // 動作フラグ\r
+       char MacAddress[MAX_SIZE];                              // MAC アドレス\r
+       char Version[MAX_SIZE];                                 // バージョン\r
+};\r
+\r
+// 仮想 LAN の列挙\r
+struct RPC_CLIENT_ENUM_VLAN\r
+{\r
+       UINT NumItem;                                                   // アイテム数\r
+       RPC_CLIENT_ENUM_VLAN_ITEM **Items;              // アイテム\r
+};\r
+\r
+// アカウントの作成\r
+struct RPC_CLIENT_CREATE_ACCOUNT\r
+{\r
+       CLIENT_OPTION *ClientOption;                    // クライアント オプション\r
+       CLIENT_AUTH *ClientAuth;                                // クライアント認証データ\r
+       bool StartupAccount;                                    // スタートアップアカウント\r
+       bool CheckServerCert;                                   // サーバー証明書をチェックする\r
+       X *ServerCert;                                                  // サーバー証明書\r
+       UCHAR ShortcutKey[SHA1_SIZE];                   // ショートカットキー\r
+};\r
+\r
+// アカウントの列挙アイテム\r
+struct RPC_CLIENT_ENUM_ACCOUNT_ITEM\r
+{\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];  // アカウント名\r
+       char UserName[MAX_USERNAME_LEN + 1];    //  ユーザー名\r
+       char ServerName[MAX_HOST_NAME_LEN + 1]; // サーバー名\r
+       char DeviceName[MAX_DEVICE_NAME_LEN + 1];       // デバイス名\r
+       UINT ProxyType;                                                 // プロキシ接続の種類\r
+       char ProxyName[MAX_HOST_NAME_LEN + 1];  // ホスト名\r
+       bool Active;                                                    // 動作フラグ\r
+       bool Connected;                                                 // 接続完了フラグ\r
+       bool StartupAccount;                                    // スタートアップアカウント\r
+       UINT Port;                                                              // ポート番号 (Ver 3.0 以降)\r
+       char HubName[MAX_HUBNAME_LEN + 1];              // 仮想 HUB 名 (Ver 3.0 以降)\r
+       UINT64 CreateDateTime;                                  // 作成日時 (Ver 3.0 以降)\r
+       UINT64 UpdateDateTime;                                  // 更新日時 (Ver 3.0 以降)\r
+       UINT64 LastConnectDateTime;                             // 最終接続日時 (Ver 3.0 以降)\r
+       UINT tmp1;                                                              // 一時データ\r
+};\r
+\r
+// アカウントの列挙\r
+struct RPC_CLIENT_ENUM_ACCOUNT\r
+{\r
+       UINT NumItem;                                                   // アイテム数\r
+       RPC_CLIENT_ENUM_ACCOUNT_ITEM **Items;   // アイテム\r
+};\r
+\r
+// アカウントの削除\r
+struct RPC_CLIENT_DELETE_ACCOUNT\r
+{\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];  // アカウント名\r
+};\r
+\r
+// アカウント名の変更\r
+struct RPC_RENAME_ACCOUNT\r
+{\r
+       wchar_t OldName[MAX_ACCOUNT_NAME_LEN + 1];              // 古い名前\r
+       wchar_t NewName[MAX_ACCOUNT_NAME_LEN + 1];              // 新しい名前\r
+};\r
+\r
+// アカウントの取得\r
+struct RPC_CLIENT_GET_ACCOUNT\r
+{\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];  // アカウント名\r
+       CLIENT_OPTION *ClientOption;                    // クライアント オプション\r
+       CLIENT_AUTH *ClientAuth;                                // クライアント認証データ\r
+       bool StartupAccount;                                    // スタートアップアカウント\r
+       bool CheckServerCert;                                   // サーバー証明書をチェックする\r
+       X *ServerCert;                                                  // サーバー証明書\r
+       UCHAR ShortcutKey[SHA1_SIZE];                   // ショートカットキー\r
+       UINT64 CreateDateTime;                                  // 作成日時 (Ver 3.0 以降)\r
+       UINT64 UpdateDateTime;                                  // 更新日時 (Ver 3.0 以降)\r
+       UINT64 LastConnectDateTime;                             // 最終接続日時 (Ver 3.0 以降)\r
+};\r
+\r
+// 接続\r
+struct RPC_CLIENT_CONNECT\r
+{\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];  // アカウント名\r
+};\r
+\r
+// コネクション状況の取得\r
+struct RPC_CLIENT_GET_CONNECTION_STATUS\r
+{\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];  // アカウント名\r
+       bool Active;                                                    // 動作フラグ\r
+       bool Connected;                                                 // 接続済みフラグ\r
+       UINT SessionStatus;                                             // セッションステータス\r
+       char ServerName[MAX_HOST_NAME_LEN + 1]; // サーバー名\r
+       UINT ServerPort;                                                // サーバーのポート番号\r
+       char ServerProductName[MAX_SIZE];               // サーバー製品名\r
+       UINT ServerProductVer;                                  // サーバー製品バージョン\r
+       UINT ServerProductBuild;                                // サーバー製品ビルド番号\r
+       X *ServerX;                                                             // サーバーの証明書\r
+       X *ClientX;                                                             // クライアントの証明書\r
+       UINT64 StartTime;                                               // 接続開始時刻\r
+       UINT64 FirstConnectionEstablisiedTime;  // 最初のコネクションの接続完了時刻\r
+       UINT64 CurrentConnectionEstablishTime;  // このコネクションの接続完了時刻\r
+       UINT NumConnectionsEatablished;                 // これまでに確立したコネクション数\r
+       bool HalfConnection;                                    // ハーフコネクション\r
+       bool QoS;                                                               // VoIP / QoS\r
+       UINT MaxTcpConnections;                                 // 最大の TCP コネクション数\r
+       UINT NumTcpConnections;                                 // 現在の TCP コネクション数\r
+       UINT NumTcpConnectionsUpload;                   // 上りコネクション数\r
+       UINT NumTcpConnectionsDownload;                 // 下りコネクション数\r
+       bool UseEncrypt;                                                // 暗号化の使用\r
+       char CipherName[32];                                    // 暗号化アルゴリズム名\r
+       bool UseCompress;                                               // 圧縮の使用\r
+       char SessionName[MAX_SESSION_NAME_LEN + 1];     // セッション名\r
+       char ConnectionName[MAX_CONNECTION_NAME_LEN + 1];       // コネクション名\r
+       UCHAR SessionKey[SHA1_SIZE];                    // セッションキー\r
+       POLICY Policy;                                                  // ポリシー\r
+       UINT64 TotalSendSize;                                   // 合計送信データサイズ\r
+       UINT64 TotalRecvSize;                                   // 合計受信データサイズ\r
+       UINT64 TotalSendSizeReal;                               // 合計送信データサイズ (無圧縮)\r
+       UINT64 TotalRecvSizeReal;                               // 合計受信データサイズ (無圧縮)\r
+       TRAFFIC Traffic;                                                // トラフィックデータ\r
+       bool IsBridgeMode;                                              // ブリッジモード\r
+       bool IsMonitorMode;                                             // モニタモード\r
+       UINT VLanId;                                                    // VLAN ID\r
+};\r
+\r
+\r
+// RPC コネクション\r
+struct CLIENT_RPC_CONNECTION\r
+{\r
+       struct CLIENT *Client;                                  // クライアント\r
+       bool RpcMode;                                                   // true: RPC モード, false: 通知モード\r
+       THREAD *Thread;                                                 // 処理スレッド\r
+       SOCK *Sock;                                                             // ソケット\r
+};\r
+\r
+// クライアント オブジェクト\r
+struct CLIENT\r
+{\r
+       LOCK *lock;                                                             // ロック\r
+       LOCK *lockForConnect;                                   // CtConnect 内部で使用するロック\r
+       REF *ref;                                                               // 参照カウンタ\r
+       CEDAR *Cedar;                                                   // Cedar\r
+       volatile bool Halt;                                             // 停止フラグ\r
+       UINT Err;                                                               // エラーコード\r
+       CFG_RW *CfgRw;                                                  // 設定ファイル R/W\r
+       LIST *AccountList;                                              // アカウントリスト\r
+       UCHAR EncryptedPassword[SHA1_SIZE];             // パスワード\r
+       bool PasswordRemoteOnly;                                // パスワードはリモート接続のみ必要とする\r
+       UINT UseSecureDeviceId;                                 // 使用するセキュアデバイス ID\r
+       CLIENT_CONFIG Config;                                   // クライアント設定\r
+       LIST *RpcConnectionList;                                // RPC コネクションリスト\r
+       SOCK *RpcListener;                                              // RPC リスナ\r
+       THREAD *RpcThread;                                              // RPC スレッド\r
+       LOCK *HelperLock;                                               // 補助ロック\r
+       THREAD *SaverThread;                                    // 設定データ自動保存スレッド\r
+       EVENT *SaverHalter;                                             // 設定データ自動保存スレッド停止用イベント\r
+       LIST *NotifyCancelList;                                 // 通知イベントリスト\r
+       KEEP *Keep;                                                             // Keep Connection\r
+       LIST *UnixVLanList;                                             // UNIX における仮想 LAN カードのリスト\r
+       LOG *Logger;                                                    // ロガー\r
+       bool DontSavePassword;                                  // パスワードを保存しないフラグ\r
+       ERASER *Eraser;                                                 // 自動ファイル削除器\r
+       SOCKLIST *SockList;                                             // ソケットリスト\r
+       CM_SETTING *CmSetting;                                  // CM 設定\r
+       bool NoSaveLog;                                                 // ログ保存をしない\r
+       bool NoSaveConfig;                                              // 設定を保存しない\r
+};\r
+\r
+// リモートクライアントへの通知\r
+struct RPC_CLIENT_NOTIFY\r
+{\r
+       UINT NotifyCode;                                                // コード\r
+};\r
+\r
+// 通知の種類\r
+#define        CLIENT_NOTIFY_ACCOUNT_CHANGED   1       // アカウント変化通知\r
+#define        CLIENT_NOTIFY_VLAN_CHANGED              2       // 仮想 LAN カード変化通知\r
+\r
+// リモートクライアント\r
+struct REMOTE_CLIENT\r
+{\r
+       RPC *Rpc;\r
+       UINT OsType;\r
+       bool Unix;\r
+       bool Win9x;\r
+       UINT ProcessId;\r
+       UINT ClientBuildInt;\r
+};\r
+\r
+// 通知クライアント\r
+struct NOTIFY_CLIENT\r
+{\r
+       SOCK *Sock;\r
+};\r
+\r
+// CM 設定\r
+struct CM_SETTING\r
+{\r
+       bool EasyMode;                                                  // 簡易モード\r
+       bool LockMode;                                                  // 設定ロックモード\r
+       UCHAR HashedPassword[SHA1_SIZE];                // パスワード\r
+};\r
+\r
+\r
+\r
+\r
+// 関数プロトタイプ\r
+REMOTE_CLIENT *CcConnectRpc(char *server_name, char *password, bool *bad_pass, bool *no_remote, UINT wait_retry);\r
+REMOTE_CLIENT *CcConnectRpcEx(char *server_name, char *password, bool *bad_pass, bool *no_remote, UCHAR *key, UINT *key_error_code, bool shortcut_disconnect, UINT wait_retry);\r
+UINT CcShortcut(UCHAR *key);\r
+UINT CcShortcutDisconnect(UCHAR *key);\r
+void CcDisconnectRpc(REMOTE_CLIENT *rc);\r
+NOTIFY_CLIENT *CcConnectNotify(REMOTE_CLIENT *rc);\r
+void CcDisconnectNotify(NOTIFY_CLIENT *n);\r
+void CcStopNotify(NOTIFY_CLIENT *n);\r
+bool CcWaitNotify(NOTIFY_CLIENT *n);\r
+UINT CcGetClientVersion(REMOTE_CLIENT *r, RPC_CLIENT_VERSION *a);\r
+UINT CcSetCmSetting(REMOTE_CLIENT *r, CM_SETTING *a);\r
+UINT CcGetCmSetting(REMOTE_CLIENT *r, CM_SETTING *a);\r
+UINT CcSetPassword(REMOTE_CLIENT *r, RPC_CLIENT_PASSWORD *pass);\r
+UINT CcGetPasswordSetting(REMOTE_CLIENT *r, RPC_CLIENT_PASSWORD_SETTING *a);\r
+UINT CcEnumCa(REMOTE_CLIENT *r, RPC_CLIENT_ENUM_CA *e);\r
+UINT CcAddCa(REMOTE_CLIENT *r, RPC_CERT *cert);\r
+UINT CcDeleteCa(REMOTE_CLIENT *r, RPC_CLIENT_DELETE_CA *p);\r
+UINT CcGetCa(REMOTE_CLIENT *r, RPC_GET_CA *get);\r
+UINT CcEnumSecure(REMOTE_CLIENT *r, RPC_CLIENT_ENUM_SECURE *e);\r
+UINT CcUseSecure(REMOTE_CLIENT *r, RPC_USE_SECURE *sec);\r
+UINT CcGetUseSecure(REMOTE_CLIENT *r, RPC_USE_SECURE *sec);\r
+UINT CcEnumObjectInSecure(REMOTE_CLIENT *r, RPC_ENUM_OBJECT_IN_SECURE *e);\r
+UINT CcCreateVLan(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_VLAN *create);\r
+UINT CcUpgradeVLan(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_VLAN *create);\r
+UINT CcGetVLan(REMOTE_CLIENT *r, RPC_CLIENT_GET_VLAN *get);\r
+UINT CcSetVLan(REMOTE_CLIENT *r, RPC_CLIENT_SET_VLAN *set);\r
+UINT CcEnumVLan(REMOTE_CLIENT *r, RPC_CLIENT_ENUM_VLAN *e);\r
+UINT CcDeleteVLan(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_VLAN *d);\r
+UINT CcEnableVLan(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_VLAN *vlan);\r
+UINT CcDisableVLan(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_VLAN *vlan);\r
+UINT CcCreateAccount(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_ACCOUNT *a);\r
+UINT CcEnumAccount(REMOTE_CLIENT *r, RPC_CLIENT_ENUM_ACCOUNT *e);\r
+UINT CcDeleteAccount(REMOTE_CLIENT *r, RPC_CLIENT_DELETE_ACCOUNT *a);\r
+UINT CcSetAccount(REMOTE_CLIENT *r, RPC_CLIENT_CREATE_ACCOUNT *a);\r
+UINT CcGetAccount(REMOTE_CLIENT *r, RPC_CLIENT_GET_ACCOUNT *a);\r
+UINT CcRenameAccount(REMOTE_CLIENT *r, RPC_RENAME_ACCOUNT *rename);\r
+UINT CcSetClientConfig(REMOTE_CLIENT *r, CLIENT_CONFIG *o);\r
+UINT CcGetClientConfig(REMOTE_CLIENT *r, CLIENT_CONFIG *o);\r
+UINT CcConnect(REMOTE_CLIENT *r, RPC_CLIENT_CONNECT *connect);\r
+UINT CcDisconnect(REMOTE_CLIENT *r, RPC_CLIENT_CONNECT *connect);\r
+UINT CcGetAccountStatus(REMOTE_CLIENT *r, RPC_CLIENT_GET_CONNECTION_STATUS *st);\r
+UINT CcSetStartupAccount(REMOTE_CLIENT *r, RPC_CLIENT_DELETE_ACCOUNT *a);\r
+UINT CcRemoveStartupAccount(REMOTE_CLIENT *r, RPC_CLIENT_DELETE_ACCOUNT *a);\r
+UINT CcGetIssuer(REMOTE_CLIENT *r, RPC_GET_ISSUER *a);\r
+void CcSetServiceToForegroundProcess(REMOTE_CLIENT *r);\r
+char *CiGetFirstVLan(CLIENT *c);\r
+void CiNormalizeAccountVLan(CLIENT *c);\r
+\r
+\r
+void CnStart();\r
+void CnListenerProc(THREAD *thread, void *param);\r
+\r
+void CnReleaseSocket(SOCK *s, PACK *p);\r
+\r
+void CnStatusPrinter(SOCK *s, PACK *p);\r
+void Win32CnStatusPrinter(SOCK *s, PACK *p);\r
+\r
+void CnConnectErrorDlg(SOCK *s, PACK *p);\r
+void Win32CnConnectErrorDlg(SOCK *s, PACK *p);\r
+void Win32CnConnectErrorDlgThreadProc(THREAD *thread, void *param);\r
+\r
+void CnPasswordDlg(SOCK *s, PACK *p);\r
+void Win32CnPasswordDlg(SOCK *s, PACK *p);\r
+void Win32CnPasswordDlgThreadProc(THREAD *thread, void *param);\r
+\r
+void CnMsgDlg(SOCK *s, PACK *p);\r
+void Win32CnMsgDlg(SOCK *s, PACK *p);\r
+void Win32CnMsgDlgThreadProc(THREAD *thread, void *param);\r
+\r
+void CnNicInfo(SOCK *s, PACK *p);\r
+void Win32CnNicInfo(SOCK *s, PACK *p);\r
+void Win32CnNicInfoThreadProc(THREAD *thread, void *param);\r
+\r
+void CnCheckCert(SOCK *s, PACK *p);\r
+void Win32CnCheckCert(SOCK *s, PACK *p);\r
+void Win32CnCheckCertThreadProc(THREAD *thread, void *param);\r
+\r
+void CnExecDriverInstaller(SOCK *s, PACK *p);\r
+void Win32CnExecDriverInstaller(SOCK *s, PACK *p);\r
+\r
+bool CnCheckAlreadyExists(bool lock);\r
+bool CnIsCnServiceReady();\r
+void CnWaitForCnServiceReady();\r
+\r
+void CnSecureSign(SOCK *s, PACK *p);\r
+\r
+SOCK *CncConnect();\r
+SOCK *CncConnectEx(UINT timeout);\r
+void CncReleaseSocket();\r
+void CncExit();\r
+UINT CncGetSessionId();\r
+bool CncExecDriverInstaller(char *arg);\r
+SOCK *CncStatusPrinterWindowStart(SESSION *s);\r
+void CncStatusPrinterWindowPrint(SOCK *s, wchar_t *str);\r
+void CncStatusPrinterWindowStop(SOCK *s);\r
+void CncStatusPrinterWindowThreadProc(THREAD *thread, void *param);\r
+bool CncConnectErrorDlg(SESSION *session, UI_CONNECTERROR_DLG *dlg);\r
+void CncConnectErrorDlgHaltThread(THREAD *thread, void *param);\r
+bool CncPasswordDlg(SESSION *session, UI_PASSWORD_DLG *dlg);\r
+void CncPasswordDlgHaltThread(THREAD *thread, void *param);\r
+void CncCheckCert(SESSION *session, UI_CHECKCERT *dlg);\r
+void CncCheckCertHaltThread(THREAD *thread, void *param);\r
+bool CncSecureSignDlg(SECURE_SIGN *sign);\r
+SOCK *CncMsgDlg(UI_MSG_DLG *dlg);\r
+void CndMsgDlgFree(SOCK *s);\r
+SOCK *CncNicInfo(UI_NICINFO *info);\r
+void CncNicInfoFree(SOCK *s);\r
+\r
+void CtStartClient();\r
+void CtStopClient();\r
+CLIENT *CtGetClient();\r
+void CtReleaseClient(CLIENT *c);\r
+bool CtGetClientVersion(CLIENT *c, RPC_CLIENT_VERSION *ver);\r
+bool CtGetCmSetting(CLIENT *c, CM_SETTING *s);\r
+bool CtSetCmSetting(CLIENT *c, CM_SETTING *s);\r
+bool CtSetPassword(CLIENT *c, RPC_CLIENT_PASSWORD *pass);\r
+bool CtGetPasswordSetting(CLIENT *c, RPC_CLIENT_PASSWORD_SETTING *a);\r
+bool CtEnumCa(CLIENT *c, RPC_CLIENT_ENUM_CA *e);\r
+bool CtAddCa(CLIENT *c, RPC_CERT *cert);\r
+bool CtDeleteCa(CLIENT *c, RPC_CLIENT_DELETE_CA *p);\r
+bool CtGetCa(CLIENT *c, RPC_GET_CA *get);\r
+bool CtEnumSecure(CLIENT *c, RPC_CLIENT_ENUM_SECURE *e);\r
+bool CtUseSecure(CLIENT *c, RPC_USE_SECURE *sec);\r
+bool CtGetUseSecure(CLIENT *c, RPC_USE_SECURE *sec);\r
+bool CtEnumObjectInSecure(CLIENT *c, RPC_ENUM_OBJECT_IN_SECURE *e);\r
+bool CtCreateVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create);\r
+bool CtUpgradeVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create);\r
+bool CtGetVLan(CLIENT *c, RPC_CLIENT_GET_VLAN *get);\r
+bool CtSetVLan(CLIENT *c, RPC_CLIENT_SET_VLAN *set);\r
+bool CtEnumVLan(CLIENT *c, RPC_CLIENT_ENUM_VLAN *e);\r
+bool CtDeleteVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *d);\r
+bool CtEnableVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *vlan);\r
+bool CtDisableVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *vlan);\r
+bool CtCreateAccount(CLIENT *c, RPC_CLIENT_CREATE_ACCOUNT *a);\r
+bool CtEnumAccount(CLIENT *c, RPC_CLIENT_ENUM_ACCOUNT *e);\r
+bool CtDeleteAccount(CLIENT *c, RPC_CLIENT_DELETE_ACCOUNT *a);\r
+bool CtSetAccount(CLIENT *c, RPC_CLIENT_CREATE_ACCOUNT *a);\r
+bool CtGetAccount(CLIENT *c, RPC_CLIENT_GET_ACCOUNT *a);\r
+bool CtRenameAccount(CLIENT *c, RPC_RENAME_ACCOUNT *rename);\r
+bool CtSetClientConfig(CLIENT *c, CLIENT_CONFIG *o);\r
+bool CtGetClientConfig(CLIENT *c, CLIENT_CONFIG *o);\r
+bool CtConnect(CLIENT *c, RPC_CLIENT_CONNECT *connect);\r
+bool CtDisconnect(CLIENT *c, RPC_CLIENT_CONNECT *connect);\r
+bool CtGetAccountStatus(CLIENT *c, RPC_CLIENT_GET_CONNECTION_STATUS *st);\r
+bool CtSetStartupAccount(CLIENT *c, RPC_CLIENT_DELETE_ACCOUNT *a);\r
+bool CtRemoveStartupAccount(CLIENT *c, RPC_CLIENT_DELETE_ACCOUNT *a);\r
+bool CtGetIssuer(CLIENT *c, RPC_GET_ISSUER *a);\r
+\r
+\r
+\r
+\r
+\r
+// 内部関数プロトタイプ\r
+char *CiGetVpnClientExeFileName();\r
+void CiServerThread(THREAD *t, void *param);\r
+void CiInitSaver(CLIENT *c);\r
+void CiFreeSaver(CLIENT *c);\r
+void CiGetSessionStatus(RPC_CLIENT_GET_CONNECTION_STATUS *st, SESSION *s);\r
+PACK *CiRpcDispatch(RPC *rpc, char *name, PACK *p);\r
+void CiRpcAccepted(CLIENT *c, SOCK *s);\r
+void CiNotifyMain(CLIENT *c, SOCK *s);\r
+void CiRpcAcceptThread(THREAD *thread, void *param);\r
+void CiRpcServerThread(THREAD *thread, void *param);\r
+void CiStartRpcServer(CLIENT *c);\r
+void CiStopRpcServer(CLIENT *c);\r
+CLIENT_OPTION *CiLoadClientOption(FOLDER *f);\r
+CLIENT_AUTH *CiLoadClientAuth(FOLDER *f);\r
+ACCOUNT *CiLoadClientAccount(FOLDER *f);\r
+void CiLoadClientConfig(CLIENT_CONFIG *c, FOLDER *f);\r
+void CiLoadAccountDatabase(CLIENT *c, FOLDER *f);\r
+void CiLoadCAList(CLIENT *c, FOLDER *f);\r
+void CiLoadCACert(CLIENT *c, FOLDER *f);\r
+void CiLoadVLanList(CLIENT *c, FOLDER *f);\r
+void CiLoadVLan(CLIENT *c, FOLDER *f);\r
+bool CiReadSettingFromCfg(CLIENT *c, FOLDER *root);\r
+void CiWriteAccountDatabase(CLIENT *c, FOLDER *f);\r
+void CiWriteAccountData(FOLDER *f, ACCOUNT *a);\r
+void CiWriteClientOption(FOLDER *f, CLIENT_OPTION *o);\r
+void CiWriteClientAuth(FOLDER *f, CLIENT_AUTH *a);\r
+void CiWriteClientConfig(FOLDER *cc, CLIENT_CONFIG *config);\r
+void CiWriteSettingToCfg(CLIENT *c, FOLDER *root);\r
+void CiWriteCAList(CLIENT *c, FOLDER *f);\r
+void CiWriteCACert(CLIENT *c, FOLDER *f, X *x);\r
+void CiWriteVLanList(CLIENT *c, FOLDER *f);\r
+void CiWriteVLan(CLIENT *c, FOLDER *f, UNIX_VLAN *v);\r
+void CiFreeClientGetConnectionStatus(RPC_CLIENT_GET_CONNECTION_STATUS *st);\r
+bool CiCheckCertProc(SESSION *s, CONNECTION *c, X *server_x, bool *expired);\r
+bool CiSecureSignProc(SESSION *s, CONNECTION *c, SECURE_SIGN *sign);\r
+bool Win32CiSecureSign(SECURE_SIGN *sign);\r
+void CiFreeClientAuth(CLIENT_AUTH *auth);\r
+void CiFreeClientCreateAccount(RPC_CLIENT_CREATE_ACCOUNT *a);\r
+void CiFreeClientGetAccount(RPC_CLIENT_GET_ACCOUNT *a);\r
+void CiFreeClientEnumVLan(RPC_CLIENT_ENUM_VLAN *e);\r
+void CiFreeClientEnumSecure(RPC_CLIENT_ENUM_SECURE *e);\r
+void CiFreeClientEnumCa(RPC_CLIENT_ENUM_CA *e);\r
+void CiFreeEnumObjectInSecure(RPC_ENUM_OBJECT_IN_SECURE *a);\r
+void CiFreeGetCa(RPC_GET_CA *a);\r
+void CiFreeGetIssuer(RPC_GET_ISSUER *a);\r
+void CiFreeClientEnumAccount(RPC_CLIENT_ENUM_ACCOUNT *a);\r
+void CiSetError(CLIENT *c, UINT err);\r
+void CiCheckOs();\r
+CLIENT *CiNewClient();\r
+void CiCleanupClient(CLIENT *c);\r
+bool CiLoadConfigurationFile(CLIENT *c);\r
+void CiSaveConfigurationFile(CLIENT *c);\r
+void CiInitConfiguration(CLIENT *c);\r
+void CiSetVLanToDefault(CLIENT *c);\r
+bool CiIsVLan(CLIENT *c, char *name);\r
+void CiFreeConfiguration(CLIENT *c);\r
+int CiCompareAccount(void *p1, void *p2);\r
+void CiFreeAccount(ACCOUNT *a);\r
+void CiNotify(CLIENT *c);\r
+void CiClientStatusPrinter(SESSION *s, wchar_t *status);\r
+void CiInitKeep(CLIENT *c);\r
+void CiFreeKeep(CLIENT *c);\r
+int CiCompareUnixVLan(void *p1, void *p2);\r
+BUF *CiAccountToCfg(RPC_CLIENT_CREATE_ACCOUNT *t);\r
+RPC_CLIENT_CREATE_ACCOUNT *CiCfgToAccount(BUF *b);\r
+void CiChangeAllVLanMacAddress(CLIENT *c);\r
+void CiChangeAllVLanMacAddressIfMachineChanged(CLIENT *c);\r
+bool CiReadLastMachineHash(void *data);\r
+bool CiWriteLastMachineHash(void *data);\r
+void CiGetCurrentMachineHash(void *data);\r
+void CiGetCurrentMachineHashOld(void *data);\r
+int CiCompareClientAccountEnumItemByLastConnectDateTime(void *p1, void *p2);\r
+\r
+BUF *EncryptPassword(char *password);\r
+char *DecryptPassword(BUF *b);\r
+\r
+void InRpcGetIssuer(RPC_GET_ISSUER *c, PACK *p);\r
+void OutRpcGetIssuer(PACK *p, RPC_GET_ISSUER *c);\r
+void InRpcClientVersion(RPC_CLIENT_VERSION *ver, PACK *p);\r
+void OutRpcClientVersion(PACK *p, RPC_CLIENT_VERSION *ver);\r
+void InRpcClientPassword(RPC_CLIENT_PASSWORD *pw, PACK *p);\r
+void OutRpcClientPassword(PACK *p, RPC_CLIENT_PASSWORD *pw);\r
+void InRpcClientEnumCa(RPC_CLIENT_ENUM_CA *e, PACK *p);\r
+void OutRpcClientEnumCa(PACK *p, RPC_CLIENT_ENUM_CA *e);\r
+void InRpcCert(RPC_CERT *c, PACK *p);\r
+void OutRpcCert(PACK *p, RPC_CERT *c);\r
+void InRpcClientDeleteCa(RPC_CLIENT_DELETE_CA *c, PACK *p);\r
+void OutRpcClientDeleteCa(PACK *p, RPC_CLIENT_DELETE_CA *c);\r
+void InRpcGetCa(RPC_GET_CA *c, PACK *p);\r
+void OutRpcGetCa(PACK *p, RPC_GET_CA *c);\r
+void InRpcClientEnumSecure(RPC_CLIENT_ENUM_SECURE *e, PACK *p);\r
+void OutRpcClientEnumSecure(PACK *p, RPC_CLIENT_ENUM_SECURE *e);\r
+void InRpcUseSecure(RPC_USE_SECURE *u, PACK *p);\r
+void OutRpcUseSecure(PACK *p, RPC_USE_SECURE *u);\r
+void InRpcEnumObjectInSecure(RPC_ENUM_OBJECT_IN_SECURE *e, PACK *p);\r
+void OutRpcEnumObjectInSecure(PACK *p, RPC_ENUM_OBJECT_IN_SECURE *e);\r
+void InRpcCreateVLan(RPC_CLIENT_CREATE_VLAN *v, PACK *p);\r
+void OutRpcCreateVLan(PACK *p, RPC_CLIENT_CREATE_VLAN *v);\r
+void InRpcClientGetVLan(RPC_CLIENT_GET_VLAN *v, PACK *p);\r
+void OutRpcClientGetVLan(PACK *p, RPC_CLIENT_GET_VLAN *v);\r
+void InRpcClientSetVLan(RPC_CLIENT_SET_VLAN *v, PACK *p);\r
+void OutRpcClientSetVLan(PACK *p, RPC_CLIENT_SET_VLAN *v);\r
+void InRpcClientEnumVLan(RPC_CLIENT_ENUM_VLAN *v, PACK *p);\r
+void OutRpcClientEnumVLan(PACK *p, RPC_CLIENT_ENUM_VLAN *v);\r
+void InRpcClientOption(CLIENT_OPTION *c, PACK *p);\r
+void OutRpcClientOption(PACK *p, CLIENT_OPTION *c);\r
+void InRpcClientAuth(CLIENT_AUTH *c, PACK *p);\r
+void OutRpcClientAuth(PACK *p, CLIENT_AUTH *c);\r
+void InRpcClientCreateAccount(RPC_CLIENT_CREATE_ACCOUNT *c, PACK *p);\r
+void OutRpcClientCreateAccount(PACK *p, RPC_CLIENT_CREATE_ACCOUNT *c);\r
+void InRpcClientEnumAccount(RPC_CLIENT_ENUM_ACCOUNT *e, PACK *p);\r
+void OutRpcClientEnumAccount(PACK *p, RPC_CLIENT_ENUM_ACCOUNT *e);\r
+void InRpcClientDeleteAccount(RPC_CLIENT_DELETE_ACCOUNT *a, PACK *p);\r
+void OutRpcClientDeleteAccount(PACK *p, RPC_CLIENT_DELETE_ACCOUNT *a);\r
+void InRpcRenameAccount(RPC_RENAME_ACCOUNT *a, PACK *p);\r
+void OutRpcRenameAccount(PACK *p, RPC_RENAME_ACCOUNT *a);\r
+void InRpcClientGetAccount(RPC_CLIENT_GET_ACCOUNT *c, PACK *p);\r
+void OutRpcClientGetAccount(PACK *p, RPC_CLIENT_GET_ACCOUNT *c);\r
+void InRpcClientConnect(RPC_CLIENT_CONNECT *c, PACK *p);\r
+void OutRpcClientConnect(PACK *p, RPC_CLIENT_CONNECT *c);\r
+void InRpcPolicy(POLICY *o, PACK *p);\r
+void OutRpcPolicy(PACK *p, POLICY *o);\r
+void InRpcClientGetConnectionStatus(RPC_CLIENT_GET_CONNECTION_STATUS *s, PACK *p);\r
+void OutRpcClientGetConnectionStatus(PACK *p, RPC_CLIENT_GET_CONNECTION_STATUS *c);\r
+void InRpcClientNotify(RPC_CLIENT_NOTIFY *n, PACK *p);\r
+void OutRpcClientNotify(PACK *p, RPC_CLIENT_NOTIFY *n);\r
+void InRpcClientConfig(CLIENT_CONFIG *c, PACK *p);\r
+void OutRpcClientConfig(PACK *p, CLIENT_CONFIG *c);\r
+void InRpcClientPasswordSetting(RPC_CLIENT_PASSWORD_SETTING *a, PACK *p);\r
+void OutRpcClientPasswordSetting(PACK *p, RPC_CLIENT_PASSWORD_SETTING *a);\r
+void InRpcTraffic(TRAFFIC *t, PACK *p);\r
+void OutRpcTraffic(PACK *p, TRAFFIC *t);\r
+void InRpcTrafficEx(TRAFFIC *t, PACK *p, UINT i);\r
+void OutRpcTrafficEx(TRAFFIC *t, PACK *p, UINT i, UINT num);\r
+void OutRpcCmSetting(PACK *p, CM_SETTING *c);\r
+void InRpcCmSetting(CM_SETTING *c, PACK *p);\r
+\r
+\r
+#endif // CLIENT_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Command.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Command.c
new file mode 100644 (file)
index 0000000..ff1adf1
--- /dev/null
@@ -0,0 +1,22416 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Command.c\r
+// vpncmd コマンドライン管理ユーティリティ\r
+\r
+#include "CedarPch.h"\r
+\r
+// システムチェッカ定義\r
+typedef bool (CHECKER_PROC_DEF)();\r
+typedef struct CHECKER_PROC\r
+{\r
+       char *Title;\r
+       CHECKER_PROC_DEF *Proc;\r
+} CHECKER_PROC;\r
+\r
+static CHECKER_PROC checker_procs[] =\r
+{\r
+       {"CHECK_PROC_KERNEL", CheckKernel},\r
+       {"CHECK_PROC_MEMORY", CheckMemory},\r
+       {"CHECK_PROC_STRINGS", CheckStrings},\r
+       {"CHECK_PROC_FILESYSTEM", CheckFileSystem},\r
+       {"CHECK_PROC_THREAD", CheckThread},\r
+       {"CHECK_PROC_NETWORK", CheckNetwork},\r
+};\r
+\r
+typedef struct CHECK_NETWORK_1\r
+{\r
+       SOCK *ListenSocket;\r
+} CHECK_NETWORK_1;\r
+\r
+typedef struct CHECK_NETWORK_2\r
+{\r
+       SOCK *s;\r
+       X *x;\r
+       K *k;\r
+} CHECK_NETWORK_2;\r
+\r
+\r
+// TT_RESULT を RPC に変換\r
+void OutRpcTtResult(PACK *p, TT_RESULT *t)\r
+{\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddBool(p, "Raw", t->Raw);\r
+       PackAddBool(p, "Double", t->Double);\r
+       PackAddInt64(p, "NumBytesUpload", t->NumBytesUpload);\r
+       PackAddInt64(p, "NumBytesDownload", t->NumBytesDownload);\r
+       PackAddInt64(p, "NumBytesTotal", t->NumBytesTotal);\r
+       PackAddInt64(p, "Span", t->Span);\r
+       PackAddInt64(p, "BpsUpload", t->BpsUpload);\r
+       PackAddInt64(p, "BpsDownload", t->BpsDownload);\r
+       PackAddInt64(p, "BpsTotal", t->BpsTotal);\r
+}\r
+\r
+// RPC を TT_RESULT に変換\r
+void InRpcTtResult(PACK *p, TT_RESULT *t)\r
+{\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(TT_RESULT));\r
+\r
+       t->Raw = PackGetBool(p, "Raw");\r
+       t->Double = PackGetBool(p, "Double");\r
+       t->NumBytesUpload = PackGetInt64(p, "NumBytesUpload");\r
+       t->NumBytesDownload = PackGetInt64(p, "NumBytesDownload");\r
+       t->NumBytesTotal = PackGetInt64(p, "NumBytesTotal");\r
+       t->Span = PackGetInt64(p, "Span");\r
+       t->BpsUpload = PackGetInt64(p, "BpsUpload");\r
+       t->BpsDownload = PackGetInt64(p, "BpsDownload");\r
+       t->BpsTotal = PackGetInt64(p, "BpsTotal");\r
+}\r
+\r
+// Accept スレッド\r
+void CheckNetworkAcceptThread(THREAD *thread, void *param)\r
+{\r
+       CHECK_NETWORK_2 *c = (CHECK_NETWORK_2 *)param;\r
+       SOCK *s = c->s;\r
+       UINT i = 0;\r
+\r
+       if (StartSSL(s, c->x, c->k))\r
+       {\r
+               while (true)\r
+               {\r
+                       i++;\r
+                       if (Send(s, &i, sizeof(UINT), true) == 0)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+}\r
+\r
+\r
+// Listen スレッド\r
+void CheckNetworkListenThread(THREAD *thread, void *param)\r
+{\r
+       CHECK_NETWORK_1 *c = (CHECK_NETWORK_1 *)param;\r
+       SOCK *s;\r
+       UINT i;\r
+       K *pub, *pri;\r
+       X *x;\r
+       LIST *o = NewList(NULL);\r
+       NAME *name = NewName(L"Test", L"Test", L"Test", L"JP", L"Ibaraki", L"Tsukuba");\r
+\r
+       RsaGen(&pri, &pub, 1024);\r
+       x = NewRootX(pub, pri, name, 1000, NULL);\r
+\r
+       FreeName(name);\r
+\r
+       for (i = 1025;;i++)\r
+       {\r
+               s = Listen(i);\r
+               if (s != NULL)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       c->ListenSocket = s;\r
+       AddRef(s->ref);\r
+\r
+       NoticeThreadInit(thread);\r
+\r
+       while (true)\r
+       {\r
+               SOCK *new_sock = Accept(s);\r
+\r
+               if (new_sock == NULL)\r
+               {\r
+                       break;\r
+               }\r
+               else\r
+               {\r
+                       CHECK_NETWORK_2 c;\r
+                       THREAD *t;\r
+\r
+                       Zero(&c, sizeof(c));\r
+                       c.s = new_sock;\r
+                       c.k = pri;\r
+                       c.x = x;\r
+\r
+                       t = NewThread(CheckNetworkAcceptThread, &c);\r
+                       Insert(o, t);\r
+               }\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               THREAD *t = LIST_DATA(o, i);\r
+               WaitThread(t, INFINITE);\r
+               ReleaseThread(t);\r
+       }\r
+\r
+       FreeK(pri);\r
+       FreeK(pub);\r
+\r
+       FreeX(x);\r
+\r
+       ReleaseSock(s);\r
+       ReleaseList(o);\r
+}\r
+\r
+// ネットワーク機能チェック\r
+bool CheckNetwork()\r
+{\r
+       CHECK_NETWORK_1 c;\r
+       THREAD *t;\r
+       SOCK *listen_socket;\r
+       UINT port;\r
+       UINT i, num;\r
+       bool ok = true;\r
+       SOCK **socks;\r
+       SOCK_EVENT *se = NewSockEvent();\r
+\r
+       Zero(&c, sizeof(c));\r
+       t = NewThread(CheckNetworkListenThread, &c);\r
+       WaitThreadInit(t);\r
+\r
+       listen_socket = c.ListenSocket;\r
+\r
+       port = listen_socket->LocalPort;\r
+\r
+       num = 8;\r
+       socks = ZeroMalloc(sizeof(SOCK *) * num);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               socks[i] = Connect("localhost", port);\r
+               if (socks[i] == NULL)\r
+               {\r
+                       Print("Connect Failed. (%u)\n", i);\r
+                       ok = false;\r
+                       num = i;\r
+                       break;\r
+               }\r
+               if (StartSSL(socks[i], NULL, NULL) == false)\r
+               {\r
+                       ReleaseSock(socks[i]);\r
+                       Print("Connect Failed. (%u)\n", i);\r
+                       ok = false;\r
+                       num = i;\r
+                       break;\r
+               }\r
+\r
+               JoinSockToSockEvent(socks[i], se);\r
+       }\r
+\r
+       if (ok)\r
+       {\r
+               while (true)\r
+               {\r
+                       UINT i;\r
+                       bool end = false;\r
+                       bool all_blocked = true;\r
+\r
+                       for (i = 0;i < num;i++)\r
+                       {\r
+                               UINT n;\r
+                               UINT ret;\r
+\r
+                               n = 0;\r
+                               ret = Recv(socks[i], &n, sizeof(UINT), true);\r
+                               if (ret == 0)\r
+                               {\r
+                                       Print("Recv Failed (Disconnected).\n", ret);\r
+                                       end = true;\r
+                                       ok = false;\r
+                               }\r
+                               if (ret != SOCK_LATER)\r
+                               {\r
+                                       all_blocked = false;\r
+                               }\r
+\r
+                               if (n >= 128)\r
+                               {\r
+                                       end = true;\r
+                               }\r
+                       }\r
+\r
+                       if (end)\r
+                       {\r
+                               break;\r
+                       }\r
+\r
+                       if (all_blocked)\r
+                       {\r
+                               WaitSockEvent(se, INFINITE);\r
+                       }\r
+               }\r
+       }\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               Disconnect(socks[i]);\r
+               ReleaseSock(socks[i]);\r
+       }\r
+       Free(socks);\r
+\r
+       Disconnect(listen_socket);\r
+\r
+       WaitThread(t, INFINITE);\r
+       ReleaseThread(t);\r
+\r
+       ReleaseSock(listen_socket);\r
+\r
+       ReleaseSockEvent(se);\r
+\r
+       return ok;\r
+}\r
+\r
+typedef struct CHECK_THREAD_1\r
+{\r
+       UINT num;\r
+       LOCK *lock;\r
+       THREAD *wait_thread;\r
+} CHECK_THREAD_1;\r
+\r
+static UINT check_thread_global_1 = 0;\r
+\r
+#define        CHECK_THREAD_INCREMENT_COUNT            32\r
+\r
+// テストスレッド 1\r
+void CheckThread1(THREAD *thread, void *param)\r
+{\r
+       CHECK_THREAD_1 *ct1 = (CHECK_THREAD_1 *)param;\r
+       UINT i;\r
+       UINT num = CHECK_THREAD_INCREMENT_COUNT;\r
+\r
+       WaitThread(ct1->wait_thread, INFINITE);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               Lock(ct1->lock);\r
+               check_thread_global_1 = ct1->num;\r
+               InputToNull((void *)check_thread_global_1);\r
+               check_thread_global_1 = check_thread_global_1 + 1 + RetZero();\r
+               ct1->num = check_thread_global_1;\r
+               Unlock(ct1->lock);\r
+       }\r
+}\r
+\r
+// テストスレッド 2\r
+void CheckThread2(THREAD *thread, void *param)\r
+{\r
+       EVENT *e = (EVENT *)param;\r
+       Wait(e, INFINITE);\r
+}\r
+\r
+typedef struct CHECK_THREAD_3\r
+{\r
+       UINT num, a;\r
+} CHECK_THREAD_3;\r
+\r
+// テストスレッド 3\r
+void CheckThread3(THREAD *thread, void *param)\r
+{\r
+       CHECK_THREAD_3 *c = (CHECK_THREAD_3 *)param;\r
+       THREAD *t;\r
+\r
+       if (c->num == 0)\r
+       {\r
+               return;\r
+       }\r
+       c->num--;\r
+       c->a++;\r
+\r
+       t = NewThread(CheckThread3, c);\r
+       WaitThread(t, INFINITE);\r
+       ReleaseThread(t);\r
+}\r
+\r
+// スレッドチェック\r
+bool CheckThread()\r
+{\r
+       bool ok = true;\r
+       CHECK_THREAD_1 ct1;\r
+       UINT num = 32;\r
+       UINT i;\r
+       THREAD **threads;\r
+       EVENT *e;\r
+       THREAD *t2;\r
+       THREAD *t;\r
+       CHECK_THREAD_3 c;\r
+\r
+       e = NewEvent();\r
+\r
+       Zero(&ct1, sizeof(ct1));\r
+       ct1.lock = NewLock();\r
+\r
+       t2 = NewThread(CheckThread2, e);\r
+       ct1.wait_thread = t2;\r
+\r
+       threads = ZeroMalloc(sizeof(THREAD *) * num);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               threads[i] = NewThread(CheckThread1, &ct1);\r
+               if (threads[i] == NULL)\r
+               {\r
+                       Print("Thread %u Create Failed.\n", i);\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       Set(e);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               WaitThread(threads[i], INFINITE);\r
+               ReleaseThread(threads[i]);\r
+       }\r
+\r
+       Free(threads);\r
+\r
+       if (ct1.num != (num * CHECK_THREAD_INCREMENT_COUNT))\r
+       {\r
+               Print("Threading: %u != %u\n", ct1.num, num * CHECK_THREAD_INCREMENT_COUNT);\r
+               ok = false;\r
+       }\r
+\r
+       DeleteLock(ct1.lock);\r
+\r
+       WaitThread(t2, INFINITE);\r
+       ReleaseThread(t2);\r
+\r
+       ReleaseEvent(e);\r
+\r
+       num = 32;\r
+\r
+       Zero(&c, sizeof(c));\r
+       c.num = num;\r
+       t = NewThread(CheckThread3, &c);\r
+       WaitThread(t, INFINITE);\r
+       ReleaseThread(t);\r
+\r
+       if (c.a != num)\r
+       {\r
+               Print("Threading: %u != %u\n", c.a, num);\r
+               ok = false;\r
+       }\r
+\r
+       return ok;\r
+}\r
+\r
+// ファイルシステムチェック\r
+bool CheckFileSystem()\r
+{\r
+       bool ok = true;\r
+       char exe[MAX_PATH];\r
+       char exe_dir[MAX_PATH];\r
+       DIRLIST *dirs;\r
+       UINT i;\r
+\r
+       GetExeName(exe, sizeof(exe));\r
+       GetExeDir(exe_dir, sizeof(exe_dir));\r
+\r
+       ok = false;\r
+       dirs = EnumDir(exe_dir);\r
+       for (i = 0;i < dirs->NumFiles;i++)\r
+       {\r
+               if (EndWith(exe, dirs->File[i]->FileName))\r
+               {\r
+                       ok = true;\r
+                       break;\r
+               }\r
+       }\r
+       FreeDir(dirs);\r
+\r
+       if (ok == false)\r
+       {\r
+               Print("EnumDir Failed.\n");\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               UINT size = 1234567;\r
+               UCHAR *buf;\r
+               IO *io;\r
+#ifndef        OS_WIN32\r
+               wchar_t *filename = L"/tmp/vpn_checker_tmp";\r
+#else  // OS_WIN32\r
+               wchar_t filename[MAX_PATH];\r
+               CombinePathW(filename, sizeof(filename), MsGetMyTempDirW(), L"vpn_checker_tmp");\r
+#endif // OS_WIN32\r
+\r
+               buf = Malloc(size);\r
+               for (i = 0;i < size;i++)\r
+               {\r
+                       buf[i] = i % 256;\r
+               }\r
+\r
+               io = FileCreateW(filename);\r
+               if (io == NULL)\r
+               {\r
+                       Print("FileCreate Failed.\n");\r
+                       Free(buf);\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       FileWrite(io, buf, size);\r
+                       Free(buf);\r
+                       FileClose(io);\r
+\r
+                       io = FileOpenW(filename, false);\r
+                       if (FileSize(io) != 1234567)\r
+                       {\r
+                               Print("FileSize Failed.\n");\r
+                               FileClose(io);\r
+                               return false;\r
+                       }\r
+                       else\r
+                       {\r
+                               BUF *b;\r
+\r
+                               FileClose(io);\r
+                               b = ReadDumpW(filename);\r
+\r
+                               for (i = 0;i < b->Size;i++)\r
+                               {\r
+                                       UCHAR c = ((UCHAR *)b->Buf)[i];\r
+\r
+                                       if (c != (i % 256))\r
+                                       {\r
+                                               Print("FileToBuf Failed.\n");\r
+                                               FreeBuf(b);\r
+                                               return false;\r
+                                       }\r
+                               }\r
+\r
+                               FreeBuf(b);\r
+                       }\r
+               }\r
+\r
+               FileDeleteW(filename);\r
+       }\r
+\r
+       return ok;\r
+}\r
+\r
+// 文字列チェック\r
+bool CheckStrings()\r
+{\r
+       wchar_t *numstr = _UU("CHECK_TEST_123456789");\r
+       char tmp[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       UINT i;\r
+       UINT sum, sum2;\r
+       UNI_TOKEN_LIST *t;\r
+\r
+       UniStrCpy(tmp2, sizeof(tmp2), L"");\r
+\r
+       sum2 = 0;\r
+       for (i = 0;i < 64;i++)\r
+       {\r
+               sum2 += i;\r
+               UniFormat(tmp2, sizeof(tmp2), L"%s,%u", tmp2, i);\r
+       }\r
+\r
+       t = UniParseToken(tmp2, L",");\r
+\r
+       sum = 0;\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               wchar_t *s = t->Token[i];\r
+               UINT n = UniToInt(s);\r
+\r
+               sum += n;\r
+       }\r
+\r
+       UniFreeToken(t);\r
+\r
+       if (sum != sum2)\r
+       {\r
+               Print("UniParseToken Failed.\n");\r
+               return false;\r
+       }\r
+\r
+       if (UniToInt(numstr) != 123456789)\r
+       {\r
+               Print("UniToInt Failed.\n");\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), numstr);\r
+       if (ToInt(tmp) != 123456789)\r
+       {\r
+               Print("UniToStr Failed.\n");\r
+               return false;\r
+       }\r
+\r
+       StrToUni(tmp2, sizeof(tmp2), _SS("CHECK_TEST_TESTSTR"));\r
+       if (UniStrCmp(_UU("CHECK_TEST_TESTSTR"), tmp2) != 0)\r
+       {\r
+               Print("StrToUni Failed.\n");\r
+               printf("[%S] [%S]\n", tmp2, _UU("CHECK_TEST_TESTSTR"));\r
+               return false;\r
+       }\r
+\r
+       ReplaceStrEx(tmp, sizeof(tmp), _SS("CHECK_TEST_REPLACE1"), _SS("CHECK_TEST_REPLACE3"),\r
+               _SS("CHECK_TEST_REPLACE4"), false);\r
+\r
+       if (StrCmp(tmp, _SS("CHECK_TEST_REPLACE2")) != 0)\r
+       {\r
+               Print("ReplaceStrEx Failed.\n");\r
+               return false;\r
+       }\r
+\r
+       UniReplaceStrEx(tmp2, sizeof(tmp2), _UU("CHECK_TEST_REPLACE1"), _UU("CHECK_TEST_REPLACE3"),\r
+               _UU("CHECK_TEST_REPLACE4"), false);\r
+\r
+       if (UniStrCmp(tmp2, _UU("CHECK_TEST_REPLACE2")) != 0)\r
+       {\r
+               Print("UniReplaceStrEx Failed.\n");\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// メモリチェック\r
+bool CheckMemory()\r
+{\r
+       UINT i, num, size, j;\r
+       void **pp;\r
+       bool ok = true;\r
+       UINT old_size;\r
+\r
+       num = 2000;\r
+       size = 1000;\r
+       pp = ZeroMalloc(sizeof(void *) * num);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               pp[i] = ZeroMalloc(size);\r
+               InputToNull(pp[i]);\r
+               for (j = 0;j < size;j++)\r
+               {\r
+                       ((UCHAR *)pp[i])[j] = j % 256;\r
+               }\r
+       }\r
+       old_size = size;\r
+       size = size * 3;\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               pp[i] = ReAlloc(pp[i], size);\r
+               for (j = old_size;j < size;j++)\r
+               {\r
+                       InputToNull((void *)(UINT)(((UCHAR *)pp[i])[j] = j % 256));\r
+               }\r
+       }\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               for (j = 0;j < size;j++)\r
+               {\r
+                       if (((UCHAR *)pp[i])[j] != (j % 256))\r
+                       {\r
+                               ok = false;\r
+                       }\r
+               }\r
+               Free(pp[i]);\r
+       }\r
+       Free(pp);\r
+\r
+       return ok;\r
+}\r
+\r
+// 何もしない関数\r
+void InputToNull(void *p)\r
+{\r
+       // 意味不明!\r
+       if (RetZero() == 1)\r
+       {\r
+               UCHAR *c = (UCHAR *)p;\r
+               c[0] = 0x32;\r
+       }\r
+}\r
+\r
+// 0 を返す関数\r
+UINT RetZero()\r
+{\r
+       // 意味不明!\r
+       if (g_debug == 0x123455)\r
+       {\r
+               return 1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+\r
+// カーネルチェック\r
+bool CheckKernel()\r
+{\r
+       UINT num = 10, i;\r
+       UINT64 s = Tick64();\r
+       UINT64 t = Tick64();\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               UINT64 q = Tick64();\r
+               if (t > q)\r
+               {\r
+                       Print("Tick64 #1 Failed.\n");\r
+                       return false;\r
+               }\r
+\r
+               t = q;\r
+\r
+               SleepThread(100);\r
+       }\r
+\r
+       t = (Tick64() - s);\r
+       if (t <= 500 || t >= 2000)\r
+       {\r
+               Print("Tick64 #2 Failed.\n");\r
+               return false;\r
+       }\r
+       else if (false)\r
+       {\r
+               UINT64 tick1 = Tick64();\r
+               UINT64 time1;\r
+               UINT64 tick2, time2;\r
+\r
+               SleepThread(1000);\r
+\r
+               tick2 = Tick64();\r
+               time2 = LocalTime64();\r
+               time1 = SystemToLocal64(TickToTime(tick1));\r
+\r
+               if (time2 > time1)\r
+               {\r
+                       s = time2 - time1;\r
+               }\r
+               else\r
+               {\r
+                       s = time1 - time2;\r
+               }\r
+\r
+               if (s <= 500 || s >= 2000)\r
+               {\r
+                       Print("TickToTime Failed.\n");\r
+                       return false;\r
+               }\r
+       }\r
+\r
+#ifdef OS_UNIX\r
+       {\r
+               // 子プロセスのテスト\r
+               UINT pid;\r
+               char exe[MAX_SIZE];\r
+\r
+               GetExeName(exe, sizeof(exe));\r
+\r
+               pid = fork();\r
+\r
+               if (pid == -1)\r
+               {\r
+                       Print("fork Failed.\n");\r
+                       return false;\r
+               }\r
+\r
+               if (pid == 0)\r
+               {\r
+                       char *param = UNIX_ARG_EXIT;\r
+                       char **args;\r
+\r
+                       args = ZeroMalloc(sizeof(char *) * 3);\r
+                       args[0] = exe;\r
+                       args[1] = param;\r
+                       args[2] = NULL;\r
+\r
+                       setsid();\r
+\r
+                       // 標準入出力をクローズする\r
+                       UnixCloseIO();\r
+\r
+                       // 不要なシグナルを停止する\r
+                       signal(SIGHUP, SIG_IGN);\r
+\r
+                       execvp(exe, args);\r
+                       AbortExit();\r
+               }\r
+               else\r
+               {\r
+                       int status = 0, ret;\r
+\r
+                       // 子プロセスの終了を待機する\r
+                       ret = waitpid(pid, &status, 0);\r
+\r
+                       if (WIFEXITED(status) == 0)\r
+                       {\r
+                               // 異常終了した\r
+                               Print("waitpid Failed: 0x%x\n", ret);\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+#endif // OS_UNIX\r
+\r
+       return true;\r
+}\r
+\r
+// システムチェッカ\r
+bool SystemCheck()\r
+{\r
+       UINT i;\r
+       bool ng = false;\r
+\r
+       UniPrint(_UU("CHECK_TITLE"));\r
+       UniPrint(_UU("CHECK_NOTE"));\r
+       for (i = 0;i < sizeof(checker_procs) / sizeof(checker_procs[0]);i++)\r
+       {\r
+               wchar_t *title;\r
+               bool ret = false;\r
+               CHECKER_PROC *p = &checker_procs[i];\r
+\r
+               title = _UU(p->Title);\r
+\r
+               UniPrint(_UU("CHECK_EXEC_TAG"), title);\r
+\r
+               ret = p->Proc();\r
+\r
+               if (ret == false)\r
+               {\r
+                       ng = true;\r
+               }\r
+\r
+               UniPrint(L"              %s\n", ret ? _UU("CHECK_PASS") : _UU("CHECK_FAIL"));\r
+       }\r
+\r
+       UniPrint(L"\n");\r
+       if (ng == false)\r
+       {\r
+               UniPrint(L"%s\n\n", _UU("CHECK_RESULT_1"));\r
+       }\r
+       else\r
+       {\r
+               UniPrint(L"%s\n\n", _UU("CHECK_RESULT_2"));\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+\r
+// 動作チェッカ\r
+UINT PtCheck(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       UINT ret = ERR_NO_ERROR;\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (SystemCheck() == false)\r
+       {\r
+               ret = ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// VPN Tools メイン関数\r
+void PtMain(PT *pt)\r
+{\r
+       char prompt[MAX_SIZE];\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (pt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 起動が完了したメッセージを表示する\r
+       UniFormat(tmp, sizeof(tmp), _UU("CMD_UTVPNCMD_TOOLS_CONNECTED"));\r
+       pt->Console->Write(pt->Console, tmp);\r
+       pt->Console->Write(pt->Console, L"");\r
+\r
+       while (true)\r
+       {\r
+               // コマンドの定義\r
+               CMD cmd[] =\r
+               {\r
+                       {"About", PsAbout},\r
+                       {"MakeCert", PtMakeCert},\r
+                       {"TrafficClient", PtTrafficClient},\r
+                       {"TrafficServer", PtTrafficServer},\r
+                       {"Check", PtCheck},\r
+               };\r
+\r
+               // プロンプトの生成\r
+               StrCpy(prompt, sizeof(prompt), "VPN Tools>");\r
+\r
+               if (DispatchNextCmdEx(pt->Console, pt->CmdLine, prompt, cmd, sizeof(cmd) / sizeof(cmd[0]), pt) == false)\r
+               {\r
+                       break;\r
+               }\r
+               pt->LastError = pt->Console->RetCode;\r
+\r
+               if (pt->LastError == ERR_NO_ERROR && pt->Console->ConsoleType != CONSOLE_CSV)\r
+               {\r
+                       pt->Console->Write(pt->Console, _UU("CMD_MSG_OK"));\r
+                       pt->Console->Write(pt->Console, L"");\r
+               }\r
+\r
+               if (pt->CmdLine != NULL)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// VPN Tools コンテキストの作成\r
+PT *NewPt(CONSOLE *c, wchar_t *cmdline)\r
+{\r
+       PT *pt;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (UniIsEmptyStr(cmdline))\r
+       {\r
+               cmdline = NULL;\r
+       }\r
+\r
+       pt = ZeroMalloc(sizeof(PT));\r
+       pt->Console = c;\r
+       pt->CmdLine = CopyUniStr(cmdline);\r
+\r
+       return pt;\r
+}\r
+\r
+// VPN Tools コンテキストの解放\r
+void FreePt(PT *pt)\r
+{\r
+       // 引数チェック\r
+       if (pt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(pt->CmdLine);\r
+       Free(pt);\r
+}\r
+\r
+// VPN Tools 開始\r
+UINT PtConnect(CONSOLE *c, wchar_t *cmdline)\r
+{\r
+       PT *pt;\r
+       UINT ret = 0;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       pt = NewPt(c, cmdline);\r
+\r
+       PtMain(pt);\r
+\r
+       ret = pt->LastError;\r
+\r
+       FreePt(pt);\r
+\r
+       return ret;\r
+}\r
+\r
+// vpncmd コマンドの起動パス情報の初期化\r
+void VpnCmdInitBootPath()\r
+{\r
+#ifdef OS_WIN32\r
+       char exe_path[MAX_PATH];\r
+       char tmp[MAX_PATH];\r
+       GetExeName(exe_path, sizeof(exe_path));\r
+\r
+       if (SearchStrEx(exe_path, "ham.exe", 0, false) != INFINITE || SearchStrEx(exe_path, "ham_x64.exe", 0, false) != INFINITE || SearchStrEx(exe_path, "ham_ia64.exe", 0, false) != INFINITE)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsAdmin())\r
+       {\r
+               UINT current_ver;\r
+\r
+               // 現在インストールされている vpncmd のバージョンの取得\r
+               current_ver = MsRegReadInt(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_VER);\r
+\r
+               if ((CEDAR_BUILD >= current_ver) ||\r
+                       MsRegIsValue(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH) == false)\r
+               {\r
+                       char *src_filename;\r
+                       bool b = false;\r
+                       // vpncmdsys.exe を system32 にコピーする\r
+                       if (MsIsNt())\r
+                       {\r
+                               Format(tmp, sizeof(tmp), "%s\\utvpncmd.exe", MsGetSystem32Dir());\r
+                       }\r
+                       else\r
+                       {\r
+                               Format(tmp, sizeof(tmp), "%s\\utvpncmd.exe", MsGetWindowsDir());\r
+                       }\r
+\r
+                       src_filename = VPNCMD_BOOTSTRAP_FILENAME;\r
+\r
+                       if (IsX64())\r
+                       {\r
+                               src_filename = VPNCMD_BOOTSTRAP_FILENAME_X64;\r
+                       }\r
+\r
+                       if (IsIA64())\r
+                       {\r
+                               src_filename = VPNCMD_BOOTSTRAP_FILENAME_IA64;\r
+                       }\r
+\r
+                       b = true;\r
+\r
+                       if (MsIs64BitWindows() == false || Is64())\r
+                       {\r
+                               if (IsFile(tmp) == false || (CEDAR_BUILD > current_ver) || MsRegIsValue(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH) == false)\r
+                               {\r
+                                       b = FileCopy(src_filename, tmp);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               void *wow;\r
+\r
+                               wow = MsDisableWow64FileSystemRedirection();\r
+\r
+                               if (true)\r
+                               {\r
+                                       if (IsFile(tmp) == false || (CEDAR_BUILD > current_ver) || MsRegIsValue(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH) == false)\r
+                                       {\r
+                                               b = FileCopy(src_filename, tmp);\r
+                                       }\r
+                               }\r
+\r
+                               MsRestoreWow64FileSystemRedirection(wow);\r
+\r
+                               if (true)\r
+                               {\r
+                                       if (IsFile(tmp) == false || (CEDAR_BUILD > current_ver) || MsRegIsValue(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH) == false)\r
+                                       {\r
+                                               b = FileCopy(src_filename, tmp);\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       // 現在実行しているプロンプトのほうがバージョンが新しいのでレジストリを上書きする\r
+                       if (MsIs64BitWindows() == false)\r
+                       {\r
+                               MsRegWriteStr(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH, exe_path);\r
+                               MsRegWriteInt(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_VER, CEDAR_BUILD);\r
+                       }\r
+                       else\r
+                       {\r
+                               MsRegWriteStrEx2(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH, exe_path, true, false);\r
+                               MsRegWriteIntEx2(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_VER, CEDAR_BUILD, true, false);\r
+\r
+                               MsRegWriteStrEx2(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH, exe_path, false, true);\r
+                               MsRegWriteIntEx2(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_VER, CEDAR_BUILD, false, true);\r
+                       }\r
+               }\r
+       }\r
+#endif // OS_WIN32\r
+}\r
+\r
+// 文字列の表示\r
+void TtPrint(void *param, TT_PRINT_PROC *print_proc, wchar_t *str)\r
+{\r
+       // 引数チェック\r
+       if (print_proc == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       print_proc(param, str);\r
+}\r
+\r
+// 新しいランダムデータの生成\r
+void TtGenerateRandomData(UCHAR **buf, UINT *size)\r
+{\r
+       UCHAR *tmp;\r
+       UINT sz;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (buf == NULL || size == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       sz = TRAFFIC_BUF_SIZE;\r
+       tmp = Malloc(sz);\r
+       for (i = 0;i < sz;i++)\r
+       {\r
+               tmp[i] = rand() % 256;\r
+\r
+               if (tmp[i] == '!')\r
+               {\r
+                       tmp[i] = '_';\r
+               }\r
+       }\r
+\r
+       *buf = tmp;\r
+       *size = sz;\r
+}\r
+\r
+// 通信スループット測定サーバーワーカースレッド\r
+void TtsWorkerThread(THREAD *thread, void *param)\r
+{\r
+       TTS *tts;\r
+       UINT buf_size;\r
+       UCHAR *send_buf_data, *recv_buf_data;\r
+       bool all_sockets_blocked = false;\r
+       UINT64 tmp64;\r
+       LIST *o;\r
+       UINT i;\r
+       wchar_t tmp[MAX_SIZE];\r
+       bool dont_block_next_time = false;\r
+       char *ver_str = TRAFFIC_VER_STR;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // データ領域の確保\r
+       TtGenerateRandomData(&send_buf_data, &buf_size);\r
+       TtGenerateRandomData(&recv_buf_data, &buf_size);\r
+\r
+       tts = (TTS *)param;\r
+\r
+       // ソケットイベントの準備\r
+       tts->SockEvent = NewSockEvent();\r
+       AddRef(tts->SockEvent->ref);\r
+\r
+       // サーバーソケットリストの準備\r
+       tts->TtsSockList = NewList(NULL);\r
+\r
+       // 親スレッドに準備完了を伝える\r
+       NoticeThreadInit(thread);\r
+\r
+       o = NewList(NULL);\r
+\r
+       while (tts->Halt == false)\r
+       {\r
+               // すべてのソケットを待機する\r
+               if (dont_block_next_time == false)\r
+               {\r
+                       WaitSockEvent(tts->SockEvent, 50);\r
+               }\r
+               dont_block_next_time = false;\r
+\r
+               // 現在登録されているソケットについて処理する\r
+               LockList(tts->TtsSockList);\r
+               {\r
+                       UINT i;\r
+\r
+                       all_sockets_blocked = false;\r
+\r
+                       // すべてのソケットがブロック状態にならない限り\r
+                       // データの送受信を続ける\r
+                       while (all_sockets_blocked == false)\r
+                       {\r
+                               all_sockets_blocked = true;\r
+\r
+                               for (i = 0;i < LIST_NUM(tts->TtsSockList);i++)\r
+                               {\r
+                                       UINT ret = SOCK_LATER;\r
+                                       UCHAR *send_data = NULL, *recv_data = NULL;\r
+                                       UINT send_size = 0, recv_size = 0;\r
+                                       TTS_SOCK *ts = LIST_DATA(tts->TtsSockList, i);\r
+                                       bool blocked_for_this_socket = false;\r
+\r
+                                       if (ts->SockJoined == false)\r
+                                       {\r
+                                               JoinSockToSockEvent(ts->Sock, tts->SockEvent);\r
+                                               ts->SockJoined = true;\r
+                                       }\r
+\r
+                                       switch (ts->State)\r
+                                       {\r
+                                       case 0:\r
+                                               // バージョン文字列を返す\r
+                                               ret = Send(ts->Sock, ver_str, TRAFFIC_VER_STR_SIZE, false);\r
+                                               if (ret != 0 && ret != SOCK_LATER)\r
+                                               {\r
+                                                       ts->State = 5;\r
+                                               }\r
+                                               break;\r
+\r
+                                       case 5:\r
+                                               // クライアントから方向を受信する\r
+                                               ret = Recv(ts->Sock, recv_buf_data, buf_size, false);\r
+                                               if (ret != 0 && ret != SOCK_LATER)\r
+                                               {\r
+                                                       UCHAR c;\r
+\r
+                                                       // 受信した 1 バイト目にデータの方向が入っている\r
+                                                       c = recv_buf_data[0];\r
+\r
+                                                       if (c == 0)\r
+                                                       {\r
+                                                               // 0 の場合はクライアント -> サーバー\r
+                                                               ts->State = 1;\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               // それ以外の場合はサーバー -> クライアント\r
+                                                               ts->State = 2;\r
+                                                       }\r
+                                               }\r
+                                               break;\r
+\r
+                                       case 1:\r
+                                               // クライアント -> サーバー\r
+                                               ret = Recv(ts->Sock, recv_buf_data, buf_size, false);\r
+\r
+                                               if (ret != 0 && ret != SOCK_LATER)\r
+                                               {\r
+                                                       // 受信した 1 バイト目を検査する\r
+                                                       UCHAR c = recv_buf_data[0];\r
+\r
+                                                       if (c == '!')\r
+                                                       {\r
+                                                               // サーバーからクライアントにサイズ情報を通知\r
+                                                               ts->State = 3;\r
+                                                               Debug("!");\r
+                                                       }\r
+                                               }\r
+                                               break;\r
+\r
+                                       case 2:\r
+                                               // サーバー -> クライアント\r
+                                               ret = Send(ts->Sock, send_buf_data, buf_size, false);\r
+                                               break;\r
+\r
+                                       case 3:\r
+                                               // サーバー -> クライアントにサイズ情報を通知する\r
+                                               tmp64 = Endian64(ts->NumBytes);\r
+\r
+                                               Recv(ts->Sock, recv_buf_data, buf_size, false);\r
+\r
+                                               if (ts->LastWaitTick == 0 || ts->LastWaitTick <= Tick64())\r
+                                               {\r
+                                                       ret = Send(ts->Sock, &tmp64, sizeof(tmp64), false);\r
+\r
+                                                       if (ret != SOCK_LATER)\r
+                                                       {\r
+                                                               ts->LastWaitTick = Tick64() + 100;\r
+                                                       }\r
+                                               }\r
+                                               break;\r
+                                       }\r
+\r
+                                       if (ret == 0)\r
+                                       {\r
+                                               // 切断されたのでこのソケットを削除としてマークする\r
+                                               Insert(o, ts);\r
+                                       }\r
+                                       else if (ret == SOCK_LATER)\r
+                                       {\r
+                                               // 遅延が発生した\r
+                                               blocked_for_this_socket = true;\r
+                                               dont_block_next_time = false;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (ts->State == 1)\r
+                                               {\r
+                                                       ts->NumBytes += (UINT64)ret;\r
+                                               }\r
+                                       }\r
+\r
+                                       if (blocked_for_this_socket == false)\r
+                                       {\r
+                                               all_sockets_blocked = false;\r
+                                       }\r
+                               }\r
+\r
+                               if (LIST_NUM(o) != 0)\r
+                               {\r
+                                       UINT i;\r
+                                       // 1 つ以上のソケットが切断された\r
+                                       for (i = 0;i < LIST_NUM(o);i++)\r
+                                       {\r
+                                               TTS_SOCK *ts = LIST_DATA(o, i);\r
+\r
+                                               UniFormat(tmp, sizeof(tmp), _UU("TTS_DISCONNECTED"), ts->Id, ts->Sock->RemoteHostname);\r
+                                               TtPrint(tts->Param, tts->Print, tmp);\r
+\r
+                                               Disconnect(ts->Sock);\r
+                                               ReleaseSock(ts->Sock);\r
+\r
+                                               Delete(tts->TtsSockList, ts);\r
+\r
+                                               Free(ts);\r
+                                       }\r
+\r
+                                       DeleteAll(o);\r
+                               }\r
+\r
+                               if (tts->NewSocketArrived || tts->Halt)\r
+                               {\r
+                                       tts->NewSocketArrived = false;\r
+                                       all_sockets_blocked = true;\r
+                                       dont_block_next_time = true;\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(tts->TtsSockList);\r
+       }\r
+\r
+       LockList(tts->TtsSockList);\r
+       {\r
+               // 残留しているすべてのソケットを解放する\r
+               for (i = 0;i < LIST_NUM(tts->TtsSockList);i++)\r
+               {\r
+                       TTS_SOCK *ts = LIST_DATA(tts->TtsSockList, i);\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("TTS_DISCONNECT"), ts->Id, ts->Sock->RemoteHostname);\r
+                       TtPrint(tts->Param, tts->Print, tmp);\r
+\r
+                       Disconnect(ts->Sock);\r
+                       ReleaseSock(ts->Sock);\r
+\r
+                       Free(ts);\r
+               }\r
+       }\r
+       UnlockList(tts->TtsSockList);\r
+\r
+       // クリーンアップ\r
+       ReleaseList(o);\r
+       ReleaseList(tts->TtsSockList);\r
+       ReleaseSockEvent(tts->SockEvent);\r
+       Free(send_buf_data);\r
+       Free(recv_buf_data);\r
+}\r
+\r
+// IPv6 用 Accept スレッド\r
+void TtsIPv6AcceptThread(THREAD *thread, void *param)\r
+{\r
+       TTS *tts = (TTS *)param;\r
+       // 引数チェック\r
+       if (tts == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       TtsAcceptProc(tts, tts->ListenSocketV6);\r
+}\r
+\r
+// Accept プロシージャ\r
+void TtsAcceptProc(TTS *tts, SOCK *listen_socket)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (tts == NULL || listen_socket == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (tts->Halt == false)\r
+       {\r
+               SOCK *s;\r
+               // Accept する\r
+               s = Accept(listen_socket);\r
+\r
+               if (s == NULL)\r
+               {\r
+                       if (tts->Halt == false)\r
+                       {\r
+                               SleepThread(10);\r
+                       }\r
+                       continue;\r
+               }\r
+               else\r
+               {\r
+                       // クライアントから接続された\r
+                       AcceptInit(s);\r
+                       tts->NewSocketArrived = true;\r
+                       LockList(tts->TtsSockList);\r
+                       {\r
+                               TTS_SOCK *ts = ZeroMalloc(sizeof(TTS_SOCK));\r
+\r
+                               ts->Id = (++tts->IdSeed);\r
+                               ts->Sock = s;\r
+\r
+                               UniFormat(tmp, sizeof(tmp), _UU("TTS_ACCEPTED"), ts->Id,\r
+                                       s->RemoteHostname, s->RemotePort);\r
+                               TtPrint(tts->Param, tts->Print, tmp);\r
+\r
+                               Insert(tts->TtsSockList, ts);\r
+                               tts->NewSocketArrived = true;\r
+                       }\r
+                       UnlockList(tts->TtsSockList);\r
+               }\r
+       }\r
+}\r
+\r
+// 通信スループット測定サーバー待機スレッド\r
+void TtsListenThread(THREAD *thread, void *param)\r
+{\r
+       TTS *tts;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tts = (TTS *)param;\r
+\r
+       tts->ListenSocket = NULL;\r
+       tts->ListenSocket = Listen(tts->Port);\r
+       tts->ListenSocketV6 = Listen6(tts->Port);\r
+\r
+       if (tts->ListenSocket == NULL && tts->ListenSocketV6 == NULL)\r
+       {\r
+               // Listen に失敗した\r
+               UniFormat(tmp, sizeof(tmp), _UU("TT_LISTEN_FAILED"), tts->Port);\r
+               TtPrint(tts->Param, tts->Print, tmp);\r
+\r
+               // 親スレッドに準備完了を伝える\r
+               NoticeThreadInit(thread);\r
+\r
+               tts->ErrorCode = ERR_INTERNAL_ERROR;\r
+       }\r
+       else\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("TTS_LISTEN_STARTED"), tts->Port);\r
+               TtPrint(tts->Param, tts->Print, tmp);\r
+\r
+               if (tts->ListenSocketV6 != NULL)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("TTS_LISTEN_STARTED_V6"), tts->Port);\r
+                       TtPrint(tts->Param, tts->Print, tmp);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("TTS_LISTEN_FAILED_V6"), tts->Port);\r
+                       TtPrint(tts->Param, tts->Print, tmp);\r
+               }\r
+\r
+               if (tts->ListenSocket != NULL)\r
+               {\r
+                       AddRef(tts->ListenSocket->ref);\r
+               }\r
+               if (tts->ListenSocketV6 != NULL)\r
+               {\r
+                       AddRef(tts->ListenSocketV6->ref);\r
+               }\r
+\r
+               // ワーカースレッドを開始する\r
+               tts->WorkThread = NewThread(TtsWorkerThread, tts);\r
+               WaitThreadInit(tts->WorkThread);\r
+\r
+               // 親スレッドに準備完了を伝える\r
+               NoticeThreadInit(thread);\r
+\r
+               // IPv6 用 Accept スレッドを準備\r
+               tts->IPv6AcceptThread = NULL;\r
+               if (tts->ListenSocketV6 != NULL)\r
+               {\r
+                       tts->IPv6AcceptThread = NewThread(TtsIPv6AcceptThread, tts);\r
+               }\r
+\r
+               TtsAcceptProc(tts, tts->ListenSocket);\r
+\r
+               if (tts->IPv6AcceptThread != NULL)\r
+               {\r
+                       WaitThread(tts->IPv6AcceptThread, INFINITE);\r
+                       ReleaseThread(tts->IPv6AcceptThread);\r
+               }\r
+\r
+               TtPrint(tts->Param, tts->Print, _UU("TTS_LISTEN_STOP"));\r
+\r
+               ReleaseSock(tts->ListenSocket);\r
+               ReleaseSock(tts->ListenSocketV6);\r
+               SetSockEvent(tts->SockEvent);\r
+\r
+               // ワーカースレッドの停止を待機する\r
+               WaitThread(tts->WorkThread, INFINITE);\r
+               ReleaseThread(tts->WorkThread);\r
+               ReleaseSockEvent(tts->SockEvent);\r
+       }\r
+}\r
+\r
+// データが流れる方向の文字列\r
+wchar_t *GetTtcTypeStr(UINT type)\r
+{\r
+       switch (type)\r
+       {\r
+       case TRAFFIC_TYPE_DOWNLOAD:\r
+               return _UU("TTC_TYPE_DOWNLOAD");\r
+\r
+       case TRAFFIC_TYPE_UPLOAD:\r
+               return _UU("TTC_TYPE_UPLOAD");\r
+\r
+       default:\r
+               return _UU("TTC_TYPE_FULL");\r
+       }\r
+}\r
+\r
+// サマリーの表示\r
+void TtcPrintSummary(TTC *ttc)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       wchar_t *tag = L"%-35s %s";\r
+       // 引数チェック\r
+       if (ttc == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       TtPrint(ttc->Param, ttc->Print, L"");\r
+       TtPrint(ttc->Param, ttc->Print, _UU("TTC_SUMMARY_BAR"));\r
+       TtPrint(ttc->Param, ttc->Print, _UU("TTC_SUMMARY_TITLE"));\r
+       TtPrint(ttc->Param, ttc->Print, L"");\r
+\r
+       // 接続先のホスト名\r
+       StrToUni(tmp2, sizeof(tmp2), ttc->Host);\r
+       UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_HOST"), tmp2);\r
+       TtPrint(ttc->Param, ttc->Print, tmp);\r
+\r
+       // 接続先の TCP ポート番号\r
+       UniToStru(tmp2, ttc->Port);\r
+       UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_PORT"), tmp2);\r
+       TtPrint(ttc->Param, ttc->Print, tmp);\r
+\r
+       // 確立する TCP コネクション数\r
+       UniToStru(tmp2, ttc->NumTcp);\r
+       UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_NUMTCP"), tmp2);\r
+       TtPrint(ttc->Param, ttc->Print, tmp);\r
+\r
+       // データ伝送方向\r
+       UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_TYPE"), GetTtcTypeStr(ttc->Type));\r
+       TtPrint(ttc->Param, ttc->Print, tmp);\r
+\r
+       // データ伝送時間\r
+       UniFormat(tmp2, sizeof(tmp2), _UU("TTC_SPAN_STR"), (double)(ttc->Span) / 1000.0);\r
+       UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_SPAN"), tmp2);\r
+       TtPrint(ttc->Param, ttc->Print, tmp);\r
+\r
+       // Ethernet フレーム用にデータ補正\r
+       UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_ETHER"), ttc->Raw ? _UU("SEC_NO") : _UU("SEC_YES"));\r
+       TtPrint(ttc->Param, ttc->Print, tmp);\r
+\r
+       // 中継機器の入出力合計スループット計測\r
+       UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_DOUBLE"), ttc->Double ? _UU("SEC_YES") : _UU("SEC_NO"));\r
+       TtPrint(ttc->Param, ttc->Print, tmp);\r
+\r
+       TtPrint(ttc->Param, ttc->Print, _UU("TTC_SUMMARY_BAR"));\r
+       TtPrint(ttc->Param, ttc->Print, L"");\r
+}\r
+\r
+// 通信スループット測定クライアントの停止\r
+void StopTtc(TTC *ttc)\r
+{\r
+       // 引数チェック\r
+       if (ttc == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       TtPrint(ttc->Param, ttc->Print, _UU("TTC_STOPPING"));\r
+\r
+       ttc->Halt = true;\r
+       SetSockEvent(ttc->SockEvent);\r
+}\r
+\r
+// 結果を生成\r
+void TtcGenerateResult(TTC *ttc)\r
+{\r
+       TT_RESULT *res;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (ttc == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       res = &ttc->Result;\r
+\r
+       Zero(res, sizeof(TT_RESULT));\r
+\r
+       res->Raw = ttc->Raw;\r
+       res->Double = ttc->Double;\r
+       res->Span = ttc->RealSpan;\r
+\r
+       for (i = 0;i < LIST_NUM(ttc->ItcSockList);i++)\r
+       {\r
+               TTC_SOCK *ts = LIST_DATA(ttc->ItcSockList, i);\r
+\r
+               if (ts->Download == false)\r
+               {\r
+                       // アップロード\r
+                       res->NumBytesUpload += ts->NumBytes;\r
+               }\r
+               else\r
+               {\r
+                       // ダウンロード\r
+                       res->NumBytesDownload += ts->NumBytes;\r
+               }\r
+       }\r
+\r
+       if (res->Raw == false)\r
+       {\r
+               // Ethernet に合わせて補正する\r
+               // (1 個の Ethernet フレーム中の最大の TCP ペイロードサイズは 1460 である。)\r
+               res->NumBytesDownload = (UINT64)((double)res->NumBytesDownload * 1514.0 / 1460.0);\r
+               res->NumBytesUpload = (UINT64)((double)res->NumBytesUpload * 1514.0 / 1460.0);\r
+       }\r
+\r
+       res->NumBytesTotal = res->NumBytesDownload + res->NumBytesUpload;\r
+\r
+       // スループットを計測する\r
+       if (res->Span != 0)\r
+       {\r
+               res->BpsUpload = (UINT64)((double)res->NumBytesUpload * 8.0 / ((double)res->Span / 1000.0));\r
+               res->BpsDownload = (UINT64)((double)res->NumBytesDownload * 8.0 / ((double)res->Span / 1000.0));\r
+       }\r
+\r
+       if (res->Double)\r
+       {\r
+               res->BpsUpload *= 2ULL;\r
+               res->BpsDownload *= 2ULL;\r
+       }\r
+\r
+       res->BpsTotal = res->BpsUpload + res->BpsDownload;\r
+}\r
+\r
+// クライアントスレッド\r
+void TtcThread(THREAD *thread, void *param)\r
+{\r
+       TTC *ttc;\r
+       UINT i;\r
+       wchar_t tmp[MAX_SIZE];\r
+       bool ok = false;\r
+       UINT buf_size;\r
+       UCHAR *send_buf_data, *recv_buf_data;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // データ領域の確保\r
+       TtGenerateRandomData(&send_buf_data, &buf_size);\r
+       TtGenerateRandomData(&recv_buf_data, &buf_size);\r
+\r
+       ttc = (TTC *)param;\r
+\r
+       ttc->SockEvent = NewSockEvent();\r
+       AddRef(ttc->SockEvent->ref);\r
+\r
+       // 準備完了\r
+       NoticeThreadInit(thread);\r
+\r
+       TtcPrintSummary(ttc);\r
+\r
+       UniFormat(tmp, sizeof(tmp), _UU("TTC_CONNECT_START"),\r
+               ttc->Host, ttc->Port, ttc->NumTcp);\r
+       TtPrint(ttc->Param, ttc->Print, tmp);\r
+\r
+       // クライアントへのすべてのコネクションを確立する\r
+       ttc->ItcSockList = NewList(NULL);\r
+\r
+       ok = true;\r
+\r
+       for (i = 0;i < ttc->NumTcp;i++)\r
+       {\r
+               SOCK *s;\r
+               TTC_SOCK *ts = ZeroMalloc(sizeof(TTC_SOCK));\r
+\r
+               ts->Id = i + 1;\r
+\r
+               if (ttc->Type == TRAFFIC_TYPE_DOWNLOAD)\r
+               {\r
+                       ts->Download = true;\r
+               }\r
+               else if (ttc->Type == TRAFFIC_TYPE_UPLOAD)\r
+               {\r
+                       ts->Download = false;\r
+               }\r
+               else\r
+               {\r
+                       ts->Download = ((i % 2) == 0) ? true : false;\r
+               }\r
+\r
+               s = Connect(ttc->Host, ttc->Port);\r
+\r
+               if (s == NULL)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("TTC_CONNECT_FAILED"), i + 1);\r
+                       TtPrint(ttc->Param, ttc->Print, tmp);\r
+                       ok = false;\r
+                       Free(ts);\r
+                       break;\r
+               }\r
+               else\r
+               {\r
+                       char buffer[TRAFFIC_VER_STR_SIZE];\r
+\r
+                       SetTimeout(s, 5000);\r
+\r
+                       Zero(buffer, sizeof(buffer));\r
+                       if (Recv(s, buffer, sizeof(buffer), false) != sizeof(buffer) || Cmp(buffer, TRAFFIC_VER_STR, TRAFFIC_VER_STR_SIZE) != 0)\r
+                       {\r
+                               TtPrint(ttc->Param, ttc->Print, _UU("TTC_CONNECT_NOT_SERVER"));\r
+                               ok = false;\r
+                               ReleaseSock(s);\r
+                               Free(ts);\r
+                               break;\r
+                       }\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("TTC_CONNECT_OK"), i + 1);\r
+                       TtPrint(ttc->Param, ttc->Print, tmp);\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("TTC_CONNECT_OK_2"), GetTtcTypeStr(ts->Download ? TRAFFIC_TYPE_DOWNLOAD : TRAFFIC_TYPE_UPLOAD));\r
+                       TtPrint(ttc->Param, ttc->Print, tmp);\r
+\r
+                       ts->Sock = s;\r
+\r
+                       SetTimeout(s, TIMEOUT_INFINITE);\r
+\r
+                       JoinSockToSockEvent(s, ttc->SockEvent);\r
+               }\r
+\r
+               Insert(ttc->ItcSockList, ts);\r
+       }\r
+\r
+       Set(ttc->InitedEvent);\r
+\r
+       if (ttc->StartEvent != NULL)\r
+       {\r
+               Wait(ttc->StartEvent, INFINITE);\r
+               SleepThread(500);\r
+       }\r
+\r
+       if (ok)\r
+       {\r
+               bool all_sockets_blocked;\r
+               bool dont_block_next_time = false;\r
+               bool halt_flag = false;\r
+               UINT64 start_tick, end_tick;\r
+               UINT64 halt_timeout = 0;\r
+               wchar_t tmp1[MAX_SIZE], tmp2[MAX_SIZE];\r
+               UINT check_clock_seed = 0;\r
+               bool halting = false;\r
+               UINT64 tmp64;\r
+\r
+               // 現在時刻を記録\r
+               start_tick = Tick64();\r
+               end_tick = start_tick + ttc->Span;\r
+\r
+               // 開始メッセージを表示\r
+               GetDateTimeStrEx64(tmp1, sizeof(tmp1), SystemToLocal64(TickToTime(start_tick)), NULL);\r
+               GetDateTimeStrEx64(tmp2, sizeof(tmp2), SystemToLocal64(TickToTime(end_tick)), NULL);\r
+               UniFormat(tmp, sizeof(tmp), _UU("TTC_COMM_START"), tmp1, tmp2);\r
+               TtPrint(ttc->Param, ttc->Print, tmp);\r
+\r
+               // メインループ\r
+               while (true)\r
+               {\r
+                       UINT i;\r
+\r
+                       if (dont_block_next_time == false)\r
+                       {\r
+                               WaitSockEvent(ttc->SockEvent, 50);\r
+                       }\r
+\r
+                       dont_block_next_time = false;\r
+\r
+                       if (ttc->AbnormalTerminated)\r
+                       {\r
+                               // 異常終了が発生した\r
+                               break;\r
+                       }\r
+\r
+                       if (ttc->Halt || end_tick <= Tick64())\r
+                       {\r
+                               // 計測終了\r
+                               if (halting == false)\r
+                               {\r
+                                       if (ttc->Halt)\r
+                                       {\r
+                                               // ユーザーキャンセル\r
+                                               TtPrint(ttc->Param, ttc->Print, _UU("TTC_COMM_USER_CANCEL"));\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // 時間経過\r
+                                               UniFormat(tmp, sizeof(tmp), _UU("TTC_COMM_END"),\r
+                                                       (double)ttc->Span / 1000.0);\r
+                                               TtPrint(ttc->Param, ttc->Print, tmp);\r
+                                       }\r
+\r
+                                       ttc->RealSpan = Tick64() - start_tick;\r
+\r
+                                       halting = true;\r
+\r
+                                       // サーバーからの報告データを待つ\r
+                                       halt_timeout = Tick64() + 60000ULL;\r
+                               }\r
+                       }\r
+\r
+                       if (halt_timeout != 0)\r
+                       {\r
+                               bool ok = true;\r
+\r
+                               // すべての TCP コネクションが処理を完了するまで待機する\r
+                               for (i = 0;i < LIST_NUM(ttc->ItcSockList);i++)\r
+                               {\r
+                                       TTC_SOCK *ts = LIST_DATA(ttc->ItcSockList, i);\r
+\r
+                                       if (ts->Download == false)\r
+                                       {\r
+                                               if (ts->ServerUploadReportReceived == false)\r
+                                               {\r
+                                                       ok = false;\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               if (ok)\r
+                               {\r
+                                       // 測定完了\r
+                                       // 結果を表示する\r
+                                       TtcGenerateResult(ttc);\r
+                                       break;\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (halt_timeout <= Tick64())\r
+                                       {\r
+                                               // 異常発生\r
+                                               ttc->AbnormalTerminated = true;\r
+                                               ttc->ErrorCode = ERR_PROTOCOL_ERROR;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       all_sockets_blocked = false;\r
+\r
+                       // すべてのソケットがブロック状態にならない限り\r
+                       // データの送受信を続ける\r
+                       while (all_sockets_blocked == false)\r
+                       {\r
+                               all_sockets_blocked = true;\r
+\r
+                               for (i = 0;i < LIST_NUM(ttc->ItcSockList);i++)\r
+                               {\r
+                                       UINT ret = SOCK_LATER;\r
+                                       TTC_SOCK *ts = LIST_DATA(ttc->ItcSockList, i);\r
+                                       bool blocked_for_this_socket = false;\r
+                                       UCHAR c = 0;\r
+\r
+                                       if (halt_timeout != 0)\r
+                                       {\r
+                                               if (ts->State != 3 && ts->State != 4)\r
+                                               {\r
+                                                       if (ts->Download == false)\r
+                                                       {\r
+                                                               if (ts->State != 0)\r
+                                                               {\r
+                                                                       ts->State = 3;\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       ts->ServerUploadReportReceived = true;\r
+                                                                       ts->State = 4;\r
+                                                               }\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               ts->State = 4;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+\r
+                                       switch (ts->State)\r
+                                       {\r
+                                       case 0:\r
+                                               // 初期状態: クライアント/サーバー間のデータの流れの\r
+                                               // 方向を指定する\r
+                                               if (ts->Download)\r
+                                               {\r
+                                                       c = 1;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       c = 0;\r
+                                               }\r
+\r
+                                               ret = Send(ts->Sock, &c, 1, false);\r
+\r
+                                               if (ret != 0 && ret != SOCK_LATER)\r
+                                               {\r
+                                                       if (ts->Download)\r
+                                                       {\r
+                                                               ts->State = 1;\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               ts->State = 2;\r
+                                                       }\r
+                                               }\r
+                                               break;\r
+\r
+                                       case 1:\r
+                                               // サーバー -> クライアント (ダウンロード)\r
+                                               ret = Recv(ts->Sock, recv_buf_data, buf_size, false);\r
+                                               break;\r
+\r
+                                       case 2:\r
+                                               // クライアント -> サーバー (アップロード)\r
+                                               ret = Send(ts->Sock, send_buf_data, buf_size, false);\r
+                                               break;\r
+\r
+                                       case 3:\r
+                                               // クライアント -> サーバー (アップロード) の送信完了\r
+                                               // データサイズの要求処理\r
+                                               if (ts->NextSendRequestReportTick == 0 ||\r
+                                                       (Tick64() >= ts->NextSendRequestReportTick))\r
+                                               {\r
+                                                       UCHAR suprise[MAX_SIZE];\r
+                                                       UINT i;\r
+\r
+                                                       ts->NextSendRequestReportTick = Tick64() + 200ULL;\r
+\r
+                                                       for (i = 0;i < sizeof(suprise);i++)\r
+                                                       {\r
+                                                               suprise[i] = '!';\r
+                                                       }\r
+\r
+                                                       ret = Send(ts->Sock, suprise, sizeof(suprise), false);\r
+                                               }\r
+\r
+                                               ret = Recv(ts->Sock, &tmp64, sizeof(tmp64), false);\r
+                                               if (ret != 0 && ret != SOCK_LATER && ret == sizeof(tmp64))\r
+                                               {\r
+                                                       ts->NumBytes = Endian64(tmp64);\r
+\r
+                                                       ts->ServerUploadReportReceived = true;\r
+\r
+                                                       ts->State = 4;\r
+                                               }\r
+                                               break;\r
+\r
+                                       case 4:\r
+                                               // 何もしない\r
+                                               if (Recv(ts->Sock, recv_buf_data, buf_size, false) == SOCK_LATER)\r
+                                               {\r
+                                                       ret = SOCK_LATER;\r
+                                               }\r
+                                               break;\r
+                                       }\r
+\r
+                                       if (ret == 0)\r
+                                       {\r
+                                               // ソケットが切断された\r
+                                               ttc->AbnormalTerminated = true;\r
+                                               ttc->ErrorCode = ERR_PROTOCOL_ERROR;\r
+                                               blocked_for_this_socket = true;\r
+                                               dont_block_next_time = false;\r
+\r
+                                               UniFormat(tmp, sizeof(tmp), _UU("TTC_COMM_DISCONNECTED"), ts->Id);\r
+                                               TtPrint(ttc->Param, ttc->Print, tmp);\r
+                                       }\r
+                                       else if (ret == SOCK_LATER)\r
+                                       {\r
+                                               // 遅延が発生した\r
+                                               blocked_for_this_socket = true;\r
+                                               dont_block_next_time = false;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (ts->Download)\r
+                                               {\r
+                                                       ts->NumBytes += (UINT64)ret;\r
+                                               }\r
+                                       }\r
+\r
+                                       if (blocked_for_this_socket == false)\r
+                                       {\r
+                                               all_sockets_blocked = false;\r
+                                       }\r
+                               }\r
+\r
+                               if (ttc->Halt)\r
+                               {\r
+                                       all_sockets_blocked = true;\r
+                                       dont_block_next_time = true;\r
+                               }\r
+\r
+                               if (end_tick <= Tick64())\r
+                               {\r
+                                       all_sockets_blocked = true;\r
+                                       dont_block_next_time = true;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // 中止\r
+               TtPrint(ttc->Param, ttc->Print, _UU("TTC_ERROR_ABORTED"));\r
+               ttc->ErrorCode = ERR_CONNECT_FAILED;\r
+       }\r
+\r
+       // クリーンアップ\r
+       for (i = 0;i < LIST_NUM(ttc->ItcSockList);i++)\r
+       {\r
+               TTC_SOCK *ts = LIST_DATA(ttc->ItcSockList, i);\r
+\r
+               Disconnect(ts->Sock);\r
+               ReleaseSock(ts->Sock);\r
+               Free(ts);\r
+       }\r
+\r
+       ReleaseSockEvent(ttc->SockEvent);\r
+       ReleaseList(ttc->ItcSockList);\r
+       Free(send_buf_data);\r
+       Free(recv_buf_data);\r
+}\r
+\r
+// 通信スループット測定クライアントの開始\r
+TTC *NewTtc(char *host, UINT port, UINT numtcp, UINT type, UINT64 span, bool dbl, bool raw, TT_PRINT_PROC *print_proc, void *param)\r
+{\r
+       return NewTtcEx(host, port, numtcp, type, span, dbl, raw, print_proc, param, NULL);\r
+}\r
+TTC *NewTtcEx(char *host, UINT port, UINT numtcp, UINT type, UINT64 span, bool dbl, bool raw, TT_PRINT_PROC *print_proc, void *param, EVENT *start_event)\r
+{\r
+       TTC *ttc;\r
+\r
+       ttc = ZeroMalloc(sizeof(TTC));\r
+       ttc->InitedEvent = NewEvent();\r
+       ttc->Port = port;\r
+       StrCpy(ttc->Host, sizeof(ttc->Host), host);\r
+       ttc->NumTcp = numtcp;\r
+       ttc->Type = type;\r
+       ttc->Span = span;\r
+       ttc->Double = dbl;\r
+       ttc->Raw = raw;\r
+       ttc->StartEvent = start_event;\r
+\r
+       if (ttc->Type == TRAFFIC_TYPE_FULL && ttc->NumTcp < 2)\r
+       {\r
+               ttc->NumTcp = 2;\r
+       }\r
+\r
+       ttc->Print = print_proc;\r
+       ttc->Param = param;\r
+       ttc->ErrorCode = ERR_NO_ERROR;\r
+\r
+       TtPrint(ttc->Param, ttc->Print, _UU("TTC_INIT"));\r
+\r
+       ttc->Thread = NewThread(TtcThread, ttc);\r
+       WaitThreadInit(ttc->Thread);\r
+\r
+       return ttc;\r
+}\r
+\r
+// 通信スループット測定クライアントの終了を待機\r
+UINT FreeTtc(TTC *ttc, TT_RESULT *result)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (ttc == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       WaitThread(ttc->Thread, INFINITE);\r
+       ReleaseThread(ttc->Thread);\r
+\r
+       TtPrint(ttc->Param, ttc->Print, _UU("TTC_FREE"));\r
+\r
+       ret = ttc->ErrorCode;\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               if (result != NULL)\r
+               {\r
+                       Copy(result, &ttc->Result, sizeof(TT_RESULT));\r
+               }\r
+       }\r
+\r
+       ReleaseSockEvent(ttc->SockEvent);\r
+       ReleaseEvent(ttc->InitedEvent);\r
+\r
+       Free(ttc);\r
+\r
+       return ret;\r
+}\r
+\r
+// 通信スループット測定サーバーの開始\r
+TTS *NewTts(UINT port, void *param, TT_PRINT_PROC *print_proc)\r
+{\r
+       TTS *tts;\r
+       THREAD *t;\r
+\r
+       tts = ZeroMalloc(sizeof(TTS));\r
+       tts->Port = port;\r
+       tts->Param = param;\r
+       tts->Print = print_proc;\r
+\r
+       TtPrint(param, print_proc, _UU("TTS_INIT"));\r
+\r
+       // スレッドの作成\r
+       t = NewThread(TtsListenThread, tts);\r
+       WaitThreadInit(t);\r
+\r
+       tts->Thread = t;\r
+\r
+       return tts;\r
+}\r
+\r
+// 通信スループット測定サーバーの終了を待機\r
+UINT FreeTts(TTS *tts)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (tts == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       TtPrint(tts->Param, tts->Print, _UU("TTS_STOP_INIT"));\r
+\r
+       tts->Halt = true;\r
+       Disconnect(tts->ListenSocket);\r
+       ReleaseSock(tts->ListenSocket);\r
+       Disconnect(tts->ListenSocketV6);\r
+       ReleaseSock(tts->ListenSocketV6);\r
+\r
+       // スレッドの終了を待機\r
+       WaitThread(tts->Thread, INFINITE);\r
+\r
+       ReleaseThread(tts->Thread);\r
+\r
+       TtPrint(tts->Param, tts->Print, _UU("TTS_STOP_FINISHED"));\r
+\r
+       ret = tts->ErrorCode;\r
+\r
+       Free(tts);\r
+\r
+       return ret;\r
+}\r
+\r
+// 測定ツールプロンプトの表示\r
+void PtTrafficPrintProc(void *param, wchar_t *str)\r
+{\r
+       CONSOLE *c;\r
+       // 引数チェック\r
+       if (param == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c = (CONSOLE *)param;\r
+\r
+       if (c->ConsoleType == CONSOLE_LOCAL)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               // ローカルコンソールの場合のみ表示する (それ以外の場合はマルチスレッドの同期\r
+               //  がとれないので表示できない?)\r
+               UniStrCpy(tmp, sizeof(tmp), str);\r
+               if (UniEndWith(str, L"\n") == false)\r
+               {\r
+                       UniStrCat(tmp, sizeof(tmp), L"\n");\r
+               }\r
+               UniPrint(L"%s", tmp);\r
+       }\r
+}\r
+\r
+// 通信スループット結果の表示\r
+void TtcPrintResult(CONSOLE *c, TT_RESULT *res)\r
+{\r
+       CT *ct;\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t tmp1[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       char str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (c == NULL || res == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->Write(c, _UU("TTC_RES_TITLE"));\r
+\r
+       ct = CtNew();\r
+       CtInsertColumn(ct, _UU("TTC_RES_COLUMN_1"), false);\r
+       CtInsertColumn(ct, _UU("TTC_RES_COLUMN_2"), true);\r
+       CtInsertColumn(ct, _UU("TTC_RES_COLUMN_3"), true);\r
+\r
+       // 測定に使用した時間\r
+       GetSpanStrMilli(str, sizeof(str), res->Span);\r
+       StrToUni(tmp, sizeof(tmp), str);\r
+       CtInsert(ct, _UU("TTC_RES_SPAN"), tmp, L"");\r
+\r
+       // Ethernet フレーム用にデータ補正\r
+       CtInsert(ct, _UU("TTC_RES_ETHER"), res->Raw ? _UU("SEC_NO") : _UU("SEC_YES"), L"");\r
+\r
+       // ダウンロード方向の通信データ量\r
+       ToStr3(str, sizeof(str), res->NumBytesDownload);\r
+       UniFormat(tmp1, sizeof(tmp1), L"%S Bytes", str);\r
+       ToStrByte1000(str, sizeof(str), res->NumBytesDownload);\r
+       StrToUni(tmp2, sizeof(tmp2), str);\r
+       CtInsert(ct, _UU("TTC_RES_BYTES_DOWNLOAD"), tmp1, tmp2);\r
+\r
+       // アップロード方向の通信データ量\r
+       ToStr3(str, sizeof(str), res->NumBytesUpload);\r
+       UniFormat(tmp1, sizeof(tmp1), L"%S Bytes", str);\r
+       ToStrByte1000(str, sizeof(str), res->NumBytesUpload);\r
+       StrToUni(tmp2, sizeof(tmp2), str);\r
+       CtInsert(ct, _UU("TTC_RES_BYTES_UPLOAD"), tmp1, tmp2);\r
+\r
+       // 合計通信データ量\r
+       ToStr3(str, sizeof(str), res->NumBytesTotal);\r
+       UniFormat(tmp1, sizeof(tmp1), L"%S Bytes", str);\r
+       ToStrByte1000(str, sizeof(str), res->NumBytesTotal);\r
+       StrToUni(tmp2, sizeof(tmp2), str);\r
+       CtInsert(ct, _UU("TTC_RES_BYTES_TOTAL"), tmp1, tmp2);\r
+\r
+       // 中継機器入出力合計スループット算出\r
+       CtInsert(ct, _UU("TTC_RES_DOUBLE"), (res->Double == false) ? _UU("SEC_NO") : _UU("SEC_YES"), L"");\r
+\r
+       // ダウンロード方向の平均スループット\r
+       ToStr3(str, sizeof(str), res->BpsDownload);\r
+       UniFormat(tmp1, sizeof(tmp1), L"%S bps", str);\r
+       ToStrByte1000(str, sizeof(str), res->BpsDownload);\r
+       ReplaceStr(str, sizeof(str), str, "Bytes", "bps");\r
+       StrToUni(tmp2, sizeof(tmp2), str);\r
+       CtInsert(ct, _UU("TTC_RES_BPS_DOWNLOAD"), tmp1, tmp2);\r
+\r
+       // アップロード方向の平均スループット\r
+       ToStr3(str, sizeof(str), res->BpsUpload);\r
+       UniFormat(tmp1, sizeof(tmp1), L"%S bps", str);\r
+       ToStrByte1000(str, sizeof(str), res->BpsUpload);\r
+       ReplaceStr(str, sizeof(str), str, "Bytes", "bps");\r
+       StrToUni(tmp2, sizeof(tmp2), str);\r
+       CtInsert(ct, _UU("TTC_RES_BPS_UPLOAD"), tmp1, tmp2);\r
+\r
+       // 合計平均スループット\r
+       ToStr3(str, sizeof(str), res->BpsTotal);\r
+       UniFormat(tmp1, sizeof(tmp1), L"%S bps", str);\r
+       ToStrByte1000(str, sizeof(str), res->BpsTotal);\r
+       ReplaceStr(str, sizeof(str), str, "Bytes", "bps");\r
+       StrToUni(tmp2, sizeof(tmp2), str);\r
+       CtInsert(ct, _UU("TTC_RES_BPS_TOTAL"), tmp1, tmp2);\r
+\r
+       CtFree(ct, c);\r
+}\r
+\r
+// 通信スループット測定ツールサーバーの実行\r
+UINT PtTrafficServer(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       UINT ret = ERR_NO_ERROR;\r
+       UINT port;\r
+       TTS *tts;\r
+       PARAM args[] =\r
+       {\r
+               {"[port]", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       port = GetParamInt(o, "[port]");\r
+       if (port == 0)\r
+       {\r
+               port = TRAFFIC_DEFAULT_PORT;\r
+       }\r
+\r
+       tts = NewTts(port, c, PtTrafficPrintProc);\r
+\r
+       c->Write(c, _UU("TTS_ENTER_TO_EXIT"));\r
+\r
+       Free(c->ReadLine(c, L"", true));\r
+\r
+       ret = tts->ErrorCode;\r
+\r
+       FreeTts(tts);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 通信スループット測定ツールクライアントの実行\r
+UINT PtTrafficClient(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       TTC *ttc;\r
+       LIST *o;\r
+       UINT ret = ERR_NO_ERROR;\r
+       char *host = NULL;\r
+       UINT port;\r
+       UINT num, type;\r
+       bool dbl = false, raw = false;\r
+       UINT64 span;\r
+       // 指定できるパラメータ リスト\r
+       CMD_EVAL_MIN_MAX minmax =\r
+       {\r
+               "CMD_TrafficClient_EVAL_NUMTCP",\r
+               0, TRAFFIC_NUMTCP_MAX,\r
+       };\r
+       PARAM args[] =\r
+       {\r
+               {"[host:port]", CmdPrompt, _UU("CMD_TrafficClient_PROMPT_HOST"), CmdEvalNotEmpty, NULL},\r
+               {"NUMTCP", NULL, NULL, CmdEvalMinMax, &minmax},\r
+               {"TYPE", NULL, NULL, NULL, NULL},\r
+               {"SPAN", NULL, NULL, NULL, NULL},\r
+               {"DOUBLE", NULL, NULL, NULL, NULL},\r
+               {"RAW", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (ParseHostPort(GetParamStr(o, "[host:port]"), &host, &port, TRAFFIC_DEFAULT_PORT) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_TrafficClient_ERROR_HOSTPORT"));\r
+               ret = ERR_INVALID_PARAMETER;\r
+       }\r
+       else\r
+       {\r
+               char *s;\r
+               UINT i;\r
+\r
+               Trim(host);\r
+\r
+               num = GetParamInt(o, "NUMTCP");\r
+               if (num == 0)\r
+               {\r
+                       num = TRAFFIC_NUMTCP_DEFAULT;\r
+               }\r
+               s = GetParamStr(o, "TYPE");\r
+\r
+               if (StartWith("download", s))\r
+               {\r
+                       type = TRAFFIC_TYPE_DOWNLOAD;\r
+               }\r
+               else if (StartWith("upload", s))\r
+               {\r
+                       type = TRAFFIC_TYPE_UPLOAD;\r
+               }\r
+               else\r
+               {\r
+                       type = TRAFFIC_TYPE_FULL;\r
+               }\r
+\r
+               i = GetParamInt(o, "SPAN");\r
+\r
+               if (i == 0)\r
+               {\r
+                       i = TRAFFIC_SPAN_DEFAULT;\r
+               }\r
+\r
+               span = (UINT64)i * 1000ULL;\r
+\r
+               dbl = GetParamYes(o, "DOUBLE");\r
+               raw = GetParamYes(o, "RAW");\r
+\r
+               if (type == TRAFFIC_TYPE_FULL)\r
+               {\r
+                       if ((num % 2) != 0)\r
+                       {\r
+                               ret = ERR_INVALID_PARAMETER;\r
+                               c->Write(c, _UU("CMD_TrafficClient_ERROR_NUMTCP"));\r
+                       }\r
+               }\r
+\r
+               if (ret == ERR_NO_ERROR)\r
+               {\r
+                       TT_RESULT result;\r
+                       ttc = NewTtc(host, port, num, type, span, dbl, raw, PtTrafficPrintProc, c);\r
+\r
+                       if (c->ConsoleType == CONSOLE_LOCAL)\r
+                       {\r
+                               if (c->Param != NULL && (((LOCAL_CONSOLE_PARAM *)c->Param)->InBuf == NULL))\r
+                               {\r
+//                                     c->Write(c, _UU("TTC_ENTER_TO_EXIT"));\r
+//                                     GetLine(NULL, 0);\r
+//                                     StopTtc(ttc);\r
+                               }\r
+                       }\r
+\r
+\r
+                       Zero(&result, sizeof(result));\r
+                       ret = FreeTtc(ttc, &result);\r
+\r
+                       if (ret == ERR_NO_ERROR)\r
+                       {\r
+                               TtcPrintResult(c, &result);\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       Free(host);\r
+\r
+       return ret;\r
+}\r
+\r
+// 証明書簡易作成ツール\r
+UINT PtMakeCert(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       UINT ret = ERR_NO_ERROR;\r
+       X *x = NULL;\r
+       K *pub = NULL;\r
+       K *pri = NULL;\r
+       NAME *n;\r
+       X_SERIAL *x_serial = NULL;\r
+       BUF *buf;\r
+       UINT days;\r
+       X *root_x = NULL;\r
+       K *root_k = NULL;\r
+       // 指定できるパラメータ リスト\r
+       CMD_EVAL_MIN_MAX minmax =\r
+       {\r
+               "CMD_MakeCert_EVAL_EXPIRES",\r
+               0,\r
+               10950,\r
+       };\r
+       PARAM args[] =\r
+       {\r
+               {"CN", CmdPrompt, _UU("CMD_MakeCert_PROMPT_CN"), NULL, NULL},\r
+               {"O", CmdPrompt, _UU("CMD_MakeCert_PROMPT_O"), NULL, NULL},\r
+               {"OU", CmdPrompt, _UU("CMD_MakeCert_PROMPT_OU"), NULL, NULL},\r
+               {"C", CmdPrompt, _UU("CMD_MakeCert_PROMPT_C"), NULL, NULL},\r
+               {"ST", CmdPrompt, _UU("CMD_MakeCert_PROMPT_ST"), NULL, NULL},\r
+               {"L", CmdPrompt, _UU("CMD_MakeCert_PROMPT_L"), NULL, NULL},\r
+               {"SERIAL", CmdPrompt, _UU("CMD_MakeCert_PROMPT_SERIAL"), NULL, NULL},\r
+               {"EXPIRES", CmdPrompt, _UU("CMD_MakeCert_PROMPT_EXPIRES"), CmdEvalMinMax, &minmax},\r
+               {"SIGNCERT", NULL, NULL, CmdEvalIsFile, NULL},\r
+               {"SIGNKEY", NULL, NULL, CmdEvalIsFile, NULL},\r
+               {"SAVECERT", CmdPrompt, _UU("CMD_MakeCert_PROMPT_SAVECERT"), CmdEvalNotEmpty, NULL},\r
+               {"SAVEKEY", CmdPrompt, _UU("CMD_MakeCert_PROMPT_SAVEKEY"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (IsEmptyStr(GetParamStr(o, "SIGNCERT")) == false && IsEmptyStr(GetParamStr(o, "SIGNKEY")) == false)\r
+       {\r
+               root_x = FileToX(GetParamStr(o, "SIGNCERT"));\r
+               root_k = FileToK(GetParamStr(o, "SIGNKEY"), true, NULL);\r
+\r
+               if (root_x == NULL || root_k == NULL || CheckXandK(root_x, root_k) == false)\r
+               {\r
+                       ret = ERR_INTERNAL_ERROR;\r
+\r
+                       c->Write(c, _UU("CMD_MakeCert_ERROR_SIGNKEY"));\r
+               }\r
+       }\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               buf = StrToBin(GetParamStr(o, "SERIAL"));\r
+               if (buf != NULL && buf->Size >= 1)\r
+               {\r
+                       x_serial = NewXSerial(buf->Buf, buf->Size);\r
+               }\r
+               FreeBuf(buf);\r
+\r
+               n = NewName(GetParamUniStr(o, "CN"), GetParamUniStr(o, "O"), GetParamUniStr(o, "OU"), \r
+                       GetParamUniStr(o, "C"), GetParamUniStr(o, "ST"), GetParamUniStr(o, "L"));\r
+\r
+               days = GetParamInt(o, "EXPIRES");\r
+               if (days == 0)\r
+               {\r
+                       days = 3650;\r
+               }\r
+\r
+               RsaGen(&pri, &pub, 1024);\r
+\r
+               if (root_x == NULL)\r
+               {\r
+                       x = NewRootX(pub, pri, n, days, x_serial);\r
+               }\r
+               else\r
+               {\r
+                       x = NewX(pub, root_k, root_x, n, days, x_serial);\r
+               }\r
+\r
+               FreeXSerial(x_serial);\r
+               FreeName(n);\r
+\r
+               if (x == NULL)\r
+               {\r
+                       ret = ERR_INTERNAL_ERROR;\r
+                       c->Write(c, _UU("CMD_MakeCert_ERROR_GEN_FAILED"));\r
+               }\r
+               else\r
+               {\r
+                       if (XToFile(x, GetParamStr(o, "SAVECERT"), true) == false)\r
+                       {\r
+                               c->Write(c, _UU("CMD_SAVECERT_FAILED"));\r
+                       }\r
+                       else if (KToFile(pri, GetParamStr(o, "SAVEKEY"), true, NULL) == false)\r
+                       {\r
+                               c->Write(c, _UU("CMD_SAVEKEY_FAILED"));\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       FreeX(root_x);\r
+       FreeK(root_k);\r
+\r
+       FreeX(x);\r
+       FreeK(pri);\r
+       FreeK(pub);\r
+\r
+       return ret;\r
+}\r
+\r
+\r
+// クライアント管理ツールメイン\r
+void PcMain(PC *pc)\r
+{\r
+       char prompt[MAX_SIZE];\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (pc == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 接続が完了したメッセージを表示する\r
+       UniFormat(tmp, sizeof(tmp), _UU("CMD_UTVPNCMD_CLIENT_CONNECTED"),\r
+               pc->ServerName);\r
+       pc->Console->Write(pc->Console, tmp);\r
+       pc->Console->Write(pc->Console, L"");\r
+\r
+       while (true)\r
+       {\r
+               // コマンドの定義\r
+               CMD cmd[] =\r
+               {\r
+                       {"About", PsAbout},\r
+                       {"Check", PtCheck},\r
+                       {"VersionGet", PcVersionGet},\r
+                       {"PasswordSet", PcPasswordSet},\r
+                       {"PasswordGet", PcPasswordGet},\r
+                       {"CertList", PcCertList},\r
+                       {"CertAdd", PcCertAdd},\r
+                       {"CertDelete", PcCertDelete},\r
+                       {"CertGet", PcCertGet},\r
+                       {"SecureList", PcSecureList},\r
+                       {"SecureSelect", PcSecureSelect},\r
+                       {"SecureGet", PcSecureGet},\r
+                       {"NicCreate", PcNicCreate},\r
+                       {"NicDelete", PcNicDelete},\r
+                       {"NicUpgrade", PcNicUpgrade},\r
+                       {"NicGetSetting", PcNicGetSetting},\r
+                       {"NicSetSetting", PcNicSetSetting},\r
+                       {"NicEnable", PcNicEnable},\r
+                       {"NicDisable", PcNicDisable},\r
+                       {"NicList", PcNicList},\r
+                       {"AccountList", PcAccountList},\r
+                       {"AccountCreate", PcAccountCreate},\r
+                       {"AccountSet", PcAccountSet},\r
+                       {"AccountGet", PcAccountGet},\r
+                       {"AccountDelete", PcAccountDelete},\r
+                       {"AccountUsernameSet", PcAccountUsernameSet},\r
+                       {"AccountAnonymousSet", PcAccountAnonymousSet},\r
+                       {"AccountPasswordSet", PcAccountPasswordSet},\r
+                       {"AccountCertSet", PcAccountCertSet},\r
+                       {"AccountCertGet", PcAccountCertGet},\r
+                       {"AccountEncryptDisable", PcAccountEncryptDisable},\r
+                       {"AccountEncryptEnable", PcAccountEncryptEnable},\r
+                       {"AccountCompressEnable", PcAccountCompressEnable},\r
+                       {"AccountCompressDisable", PcAccountCompressDisable},\r
+                       {"AccountProxyNone", PcAccountProxyNone},\r
+                       {"AccountProxyHttp", PcAccountProxyHttp},\r
+                       {"AccountProxySocks", PcAccountProxySocks},\r
+                       {"AccountServerCertEnable", PcAccountServerCertEnable},\r
+                       {"AccountServerCertDisable", PcAccountServerCertDisable},\r
+                       {"AccountServerCertSet", PcAccountServerCertSet},\r
+                       {"AccountServerCertDelete", PcAccountServerCertDelete},\r
+                       {"AccountServerCertGet", PcAccountServerCertGet},\r
+                       {"AccountDetailSet", PcAccountDetailSet},\r
+                       {"AccountRename", PcAccountRename},\r
+                       {"AccountConnect", PcAccountConnect},\r
+                       {"AccountDisconnect", PcAccountDisconnect},\r
+                       {"AccountStatusGet", PcAccountStatusGet},\r
+                       {"AccountNicSet", PcAccountNicSet},\r
+                       {"AccountStatusShow", PcAccountStatusShow},\r
+                       {"AccountStatusHide", PcAccountStatusHide},\r
+                       {"AccountSecureCertSet", PcAccountSecureCertSet},\r
+                       {"AccountRetrySet", PcAccountRetrySet},\r
+                       {"AccountStartupSet", PcAccountStartupSet},\r
+                       {"AccountStartupRemove", PcAccountStartupRemove},\r
+                       {"AccountExport", PcAccountExport},\r
+                       {"AccountImport", PcAccountImport},\r
+                       {"RemoteEnable", PcRemoteEnable},\r
+                       {"RemoteDisable", PcRemoteDisable},\r
+                       {"KeepEnable", PcKeepEnable},\r
+                       {"KeepDisable", PcKeepDisable},\r
+                       {"KeepSet", PcKeepSet},\r
+                       {"KeepGet", PcKeepGet},\r
+                       {"MakeCert", PtMakeCert},\r
+                       {"TrafficClient", PtTrafficClient},\r
+                       {"TrafficServer", PtTrafficServer},\r
+               };\r
+\r
+               // プロンプトの生成\r
+               StrCpy(prompt, sizeof(prompt), "VPN Client>");\r
+\r
+               if (DispatchNextCmdEx(pc->Console, pc->CmdLine, prompt, cmd, sizeof(cmd) / sizeof(cmd[0]), pc) == false)\r
+               {\r
+                       break;\r
+               }\r
+               pc->LastError = pc->Console->RetCode;\r
+\r
+               if (pc->LastError == ERR_NO_ERROR && pc->Console->ConsoleType != CONSOLE_CSV)\r
+               {\r
+                       pc->Console->Write(pc->Console, _UU("CMD_MSG_OK"));\r
+                       pc->Console->Write(pc->Console, L"");\r
+               }\r
+\r
+               if (pc->CmdLine != NULL)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// VPN Client サービスのバージョン情報の取得\r
+UINT PcVersionGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_VERSION t;\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcGetClientVersion(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               CT *ct;\r
+\r
+               // 成功\r
+               ct = CtNewStandard();\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.ClientProductName);\r
+               CtInsert(ct, _UU("CMD_VersionGet_1"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.ClientVersionString);\r
+               CtInsert(ct, _UU("CMD_VersionGet_2"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.ClientBuildInfoString);\r
+               CtInsert(ct, _UU("CMD_VersionGet_3"), tmp);\r
+\r
+               UniToStru(tmp, t.ProcessId);\r
+               CtInsert(ct, _UU("CMD_VersionGet_4"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), OsTypeToStr(t.OsType));\r
+               CtInsert(ct, _UU("CMD_VersionGet_5"), tmp);\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// VPN Client サービスに接続するためのパスワードの設定\r
+UINT PcPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_PASSWORD t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[password]", CmdPromptChoosePassword, NULL, NULL, NULL},\r
+               {"REMOTEONLY", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.Password, sizeof(t.Password), GetParamStr(o, "[password]"));\r
+       t.PasswordRemoteOnly = GetParamYes(o, "REMOTEONLY");\r
+\r
+       ret = CcSetPassword(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// VPN Client サービスに接続するためのパスワードの設定の取得\r
+UINT PcPasswordGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_PASSWORD_SETTING t;\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcGetPasswordSetting(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+               CT *ct = CtNewStandard();\r
+\r
+               CtInsert(ct, _UU("CMD_PasswordGet_1"),\r
+                       t.IsPasswordPresented ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               CtInsert(ct, _UU("CMD_PasswordGet_2"),\r
+                       t.PasswordRemoteOnly ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 信頼する証明機関の証明書一覧の取得\r
+UINT PcCertList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_ENUM_CA t;\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcEnumCa(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+               UINT i;\r
+               CT *ct = CtNewStandard();\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       wchar_t tmp2[64];\r
+                       RPC_CLIENT_ENUM_CA_ITEM *e = t.Items[i];\r
+\r
+                       GetDateStrEx64(tmp, sizeof(tmp), SystemToLocal64(e->Expires), NULL);\r
+\r
+                       UniToStru(tmp2, e->Key);\r
+\r
+                       CtInsert(ct, _UU("CMD_CAList_COLUMN_ID"), tmp2);\r
+                       CtInsert(ct, _UU("CM_CERT_COLUMN_1"), e->SubjectName);\r
+                       CtInsert(ct, _UU("CM_CERT_COLUMN_2"), e->IssuerName);\r
+                       CtInsert(ct, _UU("CM_CERT_COLUMN_3"), tmp);\r
+\r
+                       if (i != (t.NumItem - 1))\r
+                       {\r
+                               CtInsert(ct, L"---", L"---");\r
+                       }\r
+               }\r
+\r
+               CtFree(ct, c);\r
+\r
+               CiFreeClientEnumCa(&t);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 信頼する証明機関の証明書の追加\r
+UINT PcCertAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CERT t;\r
+       X *x;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[path]", CmdPrompt, _UU("CMD_CAAdd_PROMPT_PATH"), CmdEvalIsFile, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+\r
+       x = FileToX(GetParamStr(o, "[path]"));\r
+\r
+       if (x == NULL)\r
+       {\r
+               FreeParamValueList(o);\r
+               c->Write(c, _UU("CMD_MSG_LOAD_CERT_FAILED"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       t.x = x;\r
+\r
+       ret = CcAddCa(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       FreeX(x);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 信頼する証明機関の証明書の削除\r
+UINT PcCertDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_DELETE_CA t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[id]", CmdPrompt, _UU("CMD_CADelete_PROMPT_ID"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       t.Key = GetParamInt(o, "[id]");\r
+\r
+       ret = CcDeleteCa(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 信頼する証明機関の証明書の取得\r
+UINT PcCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_GET_CA t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[id]", CmdPrompt, _UU("CMD_CAGet_PROMPT_ID"), CmdEvalNotEmpty, NULL},\r
+               {"SAVECERT", CmdPrompt, _UU("CMD_CAGet_PROMPT_SAVECERT"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       t.Key = GetParamInt(o, "[id]");\r
+\r
+       ret = CcGetCa(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+               if (XToFile(t.x, GetParamStr(o, "SAVECERT"), true))\r
+               {\r
+                       // 成功\r
+               }\r
+               else\r
+               {\r
+                       // 失敗\r
+                       ret = ERR_INTERNAL_ERROR;\r
+                       c->Write(c, _UU("CMD_MSG_SAVE_CERT_FAILED"));\r
+               }\r
+\r
+               CiFreeGetCa(&t);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 使用できるスマートカードの種類の一覧の取得\r
+UINT PcSecureList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_ENUM_SECURE t;\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcEnumSecure(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               CT *ct;\r
+               UINT i;\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               wchar_t tmp4[MAX_SIZE];\r
+               wchar_t *tmp3;\r
+\r
+               // 成功\r
+               ct = CtNew();\r
+               CtInsertColumn(ct, _UU("SEC_COLUMN1"), false);\r
+               CtInsertColumn(ct, _UU("SEC_COLUMN2"), false);\r
+               CtInsertColumn(ct, _UU("SEC_COLUMN3"), false);\r
+               CtInsertColumn(ct, _UU("SEC_COLUMN4"), false);\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       RPC_CLIENT_ENUM_SECURE_ITEM *e = t.Items[i];\r
+\r
+                       // ID\r
+                       UniToStru(tmp1, e->DeviceId);\r
+\r
+                       // デバイス名\r
+                       StrToUni(tmp2, sizeof(tmp2), e->DeviceName);\r
+\r
+                       // 種類\r
+                       tmp3 = (e->Type == SECURE_IC_CARD) ? _UU("SEC_SMART_CARD") : _UU("SEC_USB_TOKEN");\r
+\r
+                       // 製造元\r
+                       StrToUni(tmp4, sizeof(tmp4), e->Manufacturer);\r
+\r
+                       CtInsert(ct, tmp1, tmp2, tmp3, tmp4);\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+\r
+               CiFreeClientEnumSecure(&t);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 使用するスマートカードの種類の選択\r
+UINT PcSecureSelect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_USE_SECURE t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[id]", CmdPrompt, _UU("CMD_SecureSelect_PROMPT_ID"), NULL, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       t.DeviceId = GetParamInt(o, "[id]");\r
+\r
+       ret = CcUseSecure(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 使用するスマートカードの種類の ID の取得\r
+UINT PcSecureGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_USE_SECURE t;\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcGetUseSecure(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               if (t.DeviceId != 0)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CMD_SecureGet_Print"), t.DeviceId);\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("CMD_SecureGet_NoPrint"));\r
+               }\r
+               c->Write(c, tmp);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 新規仮想 LAN カードの作成\r
+UINT PcNicCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_CREATE_VLAN t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));\r
+\r
+       ret = CcCreateVLan(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カードの削除\r
+UINT PcNicDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_CREATE_VLAN t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));\r
+\r
+       ret = CcDeleteVLan(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カードのデバイスドライバのアップグレード\r
+UINT PcNicUpgrade(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_CREATE_VLAN t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));\r
+\r
+       ret = CcUpgradeVLan(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カードの設定の取得\r
+UINT PcNicGetSetting(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_VLAN t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));\r
+\r
+       ret = CcGetVLan(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+               CT *ct = CtNewStandard();\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.DeviceName);\r
+               CtInsert(ct, _UU("CMD_NicGetSetting_1"), tmp);\r
+\r
+               CtInsert(ct, _UU("CMD_NicGetSetting_2"), t.Enabled ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.MacAddress);\r
+               CtInsert(ct, _UU("CMD_NicGetSetting_3"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.Version);\r
+               CtInsert(ct, _UU("CMD_NicGetSetting_4"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.FileName);\r
+               CtInsert(ct, _UU("CMD_NicGetSetting_5"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.Guid);\r
+               CtInsert(ct, _UU("CMD_NicGetSetting_6"), tmp);\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カードの設定の変更\r
+UINT PcNicSetSetting(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_SET_VLAN t;\r
+       UCHAR mac_address[6];\r
+       BUF *b;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"MAC", CmdPrompt, _UU("CMD_NicSetSetting_PROMPT_MAC"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // MAC アドレスの検査\r
+       Zero(mac_address, sizeof(mac_address));\r
+       b = StrToBin(GetParamStr(o, "MAC"));\r
+       if (b != NULL && b->Size == 6)\r
+       {\r
+               Copy(mac_address, b->Buf, 6);\r
+       }\r
+       FreeBuf(b);\r
+\r
+       if (IsZero(mac_address, 6))\r
+       {\r
+               // MAC アドレスが不正\r
+               FreeParamValueList(o);\r
+\r
+               CmdPrintError(c, ERR_INVALID_PARAMETER);\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));\r
+       NormalizeMacAddress(t.MacAddress, sizeof(t.MacAddress), GetParamStr(o, "MAC"));\r
+\r
+       ret = CcSetVLan(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カードの有効化\r
+UINT PcNicEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_CREATE_VLAN t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));\r
+\r
+       ret = CcEnableVLan(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カードの無効化\r
+UINT PcNicDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_CREATE_VLAN t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));\r
+\r
+       ret = CcDisableVLan(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カード一覧の取得\r
+UINT PcNicList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_ENUM_VLAN t;\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcEnumVLan(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               CT *ct;\r
+               UINT i;\r
+\r
+               // 成功\r
+               ct = CtNew();\r
+               CtInsertColumn(ct, _UU("CM_VLAN_COLUMN_1"), false);\r
+               CtInsertColumn(ct, _UU("CM_VLAN_COLUMN_2"), false);\r
+               CtInsertColumn(ct, _UU("CM_VLAN_COLUMN_3"), false);\r
+               CtInsertColumn(ct, _UU("CM_VLAN_COLUMN_4"), false);\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       wchar_t name[MAX_SIZE];\r
+                       wchar_t mac[MAX_SIZE];\r
+                       wchar_t ver[MAX_SIZE];\r
+                       wchar_t *status;\r
+                       RPC_CLIENT_ENUM_VLAN_ITEM *v = t.Items[i];\r
+\r
+                       // デバイス名\r
+                       StrToUni(name, sizeof(name), v->DeviceName);\r
+\r
+                       // 状態\r
+                       status = v->Enabled ? _UU("CM_VLAN_ENABLED") : _UU("CM_VLAN_DISABLED");\r
+\r
+                       // MAC アドレス\r
+                       StrToUni(mac, sizeof(mac), v->MacAddress);\r
+\r
+                       // バージョン\r
+                       StrToUni(ver, sizeof(ver), v->Version);\r
+\r
+                       CtInsert(ct,\r
+                               name, status, mac, ver);\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientEnumVLan(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// プロトコル名文字列を取得\r
+wchar_t *GetProtocolName(UINT n)\r
+{\r
+       switch (n)\r
+       {\r
+       case PROXY_DIRECT:\r
+               return _UU("PROTO_DIRECT_TCP");\r
+       case PROXY_HTTP:\r
+               return _UU("PROTO_HTTP_PROXY");\r
+       case PROXY_SOCKS:\r
+               return _UU("PROTO_SOCKS_PROXY");\r
+       }\r
+\r
+       return _UU("PROTO_UNKNOWN");\r
+}\r
+\r
+// 接続設定一覧の取得\r
+UINT PcAccountList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_ENUM_ACCOUNT t;\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcEnumAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               UINT i;\r
+               CT *ct;\r
+\r
+               // 成功\r
+               ct = CtNew();\r
+               CtInsertColumn(ct, _UU("CM_ACCOUNT_COLUMN_1"), false);\r
+               CtInsertColumn(ct, _UU("CM_ACCOUNT_COLUMN_2"), false);\r
+               CtInsertColumn(ct, _UU("CM_ACCOUNT_COLUMN_3"), false);\r
+               CtInsertColumn(ct, _UU("CM_ACCOUNT_COLUMN_3_2"), false);\r
+               CtInsertColumn(ct, _UU("CM_ACCOUNT_COLUMN_4"), false);\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       RPC_CLIENT_ENUM_ACCOUNT_ITEM *e = t.Items[i];\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       wchar_t tmp4[MAX_SIZE];\r
+                       IP ip;\r
+                       char ip_str[MAX_SIZE];\r
+\r
+                       // IPv6 アドレスの場合の特別処理\r
+                       if (StrToIP6(&ip, e->ServerName) && StartWith(e->ServerName, "[") == false)\r
+                       {\r
+                               Format(ip_str, sizeof(ip_str),\r
+                                       "[%s]", e->ServerName);\r
+                       }\r
+                       else\r
+                       {\r
+                               StrCpy(ip_str, sizeof(ip_str), e->ServerName);\r
+                       }\r
+\r
+                       if (e->Port == 0)\r
+                       {\r
+                               // ポート番号不明\r
+                               UniFormat(tmp2, sizeof(tmp2), L"%S (%s)", ip_str, GetProtocolName(e->ProxyType));\r
+                       }\r
+                       else\r
+                       {\r
+                               // ポート番号併記\r
+                               UniFormat(tmp2, sizeof(tmp2), L"%S:%u (%s)", ip_str, e->Port, GetProtocolName(e->ProxyType));\r
+                       }\r
+\r
+                       // 仮想 HUB 名\r
+                       StrToUni(tmp4, sizeof(tmp4), e->HubName);\r
+\r
+                       // 追加\r
+                       StrToUni(tmp, sizeof(tmp), e->DeviceName);\r
+\r
+                       CtInsert(ct,\r
+                               e->AccountName,\r
+                               e->Active == false ? _UU("CM_ACCOUNT_OFFLINE") :\r
+                               (e->Connected ? _UU("CM_ACCOUNT_ONLINE") : _UU("CM_ACCOUNT_CONNECTING")),\r
+                               tmp2, tmp4,\r
+                               tmp);\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       CiFreeClientEnumAccount(&t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 新しい接続設定の作成\r
+UINT PcAccountCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_CREATE_ACCOUNT t;\r
+       UINT port = 443;\r
+       char *host = NULL;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SERVER", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Server"), CmdEvalHostAndPort, NULL},\r
+               {"HUB", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Hub"), CmdEvalSafe, NULL},\r
+               {"USERNAME", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Username"), CmdEvalNotEmpty, NULL},\r
+               {"NICNAME", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Nicname"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 443);\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+       t.ClientOption->Port = port;\r
+       StrCpy(t.ClientOption->Hostname, sizeof(t.ClientOption->Hostname), host);\r
+       StrCpy(t.ClientOption->HubName, sizeof(t.ClientOption->HubName), GetParamStr(o, "HUB"));\r
+       t.ClientOption->NumRetry = INFINITE;\r
+       t.ClientOption->RetryInterval = 15;\r
+       t.ClientOption->MaxConnection = 1;\r
+       t.ClientOption->UseEncrypt = true;\r
+       t.ClientOption->AdditionalConnectionInterval = 1;\r
+       StrCpy(t.ClientOption->DeviceName, sizeof(t.ClientOption->DeviceName), GetParamStr(o, "NICNAME"));\r
+\r
+       t.ClientAuth = ZeroMalloc(sizeof(CLIENT_AUTH));\r
+       t.ClientAuth->AuthType = CLIENT_AUTHTYPE_ANONYMOUS;\r
+       StrCpy(t.ClientAuth->Username, sizeof(t.ClientAuth->Username), GetParamStr(o, "USERNAME"));\r
+\r
+       Free(host);\r
+\r
+       ret = CcCreateAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       CiFreeClientCreateAccount(&t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の接続先の設定\r
+UINT PcAccountSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       char *host = NULL;\r
+       UINT port = 443;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SERVER", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Server"), CmdEvalHostAndPort, NULL},\r
+               {"HUB", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Hub"), CmdEvalSafe, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 443);\r
+\r
+       Zero(&t, sizeof(t));\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT c;\r
+               // 成功\r
+               t.ClientOption->Port = port;\r
+               StrCpy(t.ClientOption->Hostname, sizeof(t.ClientOption->Hostname), host);\r
+               StrCpy(t.ClientOption->HubName, sizeof(t.ClientOption->HubName), GetParamStr(o, "HUB"));\r
+\r
+               Zero(&c, sizeof(c));\r
+\r
+               c.ClientAuth = t.ClientAuth;\r
+               c.ClientOption = t.ClientOption;\r
+               c.CheckServerCert = t.CheckServerCert;\r
+               c.ServerCert = t.ServerCert;\r
+               c.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &c);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       Free(host);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の設定の取得\r
+UINT PcAccountGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 接続設定の内容を表示\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               CT *ct = CtNewStandard();\r
+\r
+               // 接続設定名\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NAME"), t.ClientOption->AccountName);\r
+\r
+               // 接続先 VPN Server のホスト名\r
+               StrToUni(tmp, sizeof(tmp), t.ClientOption->Hostname);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_HOSTNAME"), tmp);\r
+\r
+               // 接続先 VPN Server のポート番号\r
+               UniToStru(tmp, t.ClientOption->Port);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PORT"), tmp);\r
+\r
+               // 接続先 VPN Server の仮想 HUB 名\r
+               StrToUni(tmp, sizeof(tmp), t.ClientOption->HubName);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_HUBNAME"), tmp);\r
+\r
+               // 経由するプロキシ サーバーの種類\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_TYPE"), GetProxyTypeStr(t.ClientOption->ProxyType));\r
+\r
+               if (t.ClientOption->ProxyType != PROXY_DIRECT)\r
+               {\r
+                       // プロキシ サーバーのホスト名\r
+                       StrToUni(tmp, sizeof(tmp), t.ClientOption->ProxyName);\r
+                       CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_HOSTNAME"), tmp);\r
+\r
+                       // プロキシ サーバーのポート番号\r
+                       UniToStru(tmp, t.ClientOption->ProxyPort);\r
+                       CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_PORT"), tmp);\r
+\r
+                       // プロキシ サーバーのユーザー名\r
+                       StrToUni(tmp, sizeof(tmp), t.ClientOption->ProxyUsername);\r
+                       CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_USERNAME"), tmp);\r
+               }\r
+\r
+               // サーバー証明書の検証\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_SERVER_CERT_USE"),\r
+                       t.CheckServerCert ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // 登録されている固有証明書\r
+               if (t.ServerCert != NULL)\r
+               {\r
+                       GetAllNameFromX(tmp, sizeof(tmp), t.ServerCert);\r
+                       CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_SERVER_CERT_NAME"), tmp);\r
+               }\r
+\r
+               // 接続に使用するデバイス名\r
+               StrToUni(tmp, sizeof(tmp), t.ClientOption->DeviceName);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_DEVICE_NAME"), tmp);\r
+\r
+               // 認証の種類\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_AUTH_TYPE"), GetClientAuthTypeStr(t.ClientAuth->AuthType));\r
+\r
+               // ユーザー名\r
+               StrToUni(tmp, sizeof(tmp), t.ClientAuth->Username);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_AUTH_USERNAME"), tmp);\r
+\r
+               if (t.ClientAuth->AuthType == CLIENT_AUTHTYPE_CERT)\r
+               {\r
+                       if (t.ClientAuth->ClientX != NULL)\r
+                       {\r
+                               // クライアント証明書名\r
+                               GetAllNameFromX(tmp, sizeof(tmp), t.ClientAuth->ClientX);\r
+                               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_AUTH_CERT_NAME"), tmp);\r
+                       }\r
+               }\r
+\r
+               // VPN 通信に使用する TCP コネクション数\r
+               UniToStru(tmp, t.ClientOption->MaxConnection);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NUMTCP"), tmp);\r
+\r
+               // 各 TCP コネクションの確立間隔\r
+               UniToStru(tmp, t.ClientOption->AdditionalConnectionInterval);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_TCP_INTERVAL"), tmp);\r
+\r
+               // 各 TCP コネクションの寿命\r
+               if (t.ClientOption->ConnectionDisconnectSpan != 0)\r
+               {\r
+                       UniToStru(tmp, t.ClientOption->ConnectionDisconnectSpan);\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("CMD_MSG_INFINITE"));\r
+               }\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_TCP_TTL"), tmp);\r
+\r
+               // 半二重モードの使用\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_TCP_HALF"),\r
+                       t.ClientOption->HalfConnection ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // SSL による暗号化\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_ENCRYPT"),\r
+                       t.ClientOption->UseEncrypt ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // データ圧縮\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_COMPRESS"),\r
+                       t.ClientOption->UseCompress ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // ブリッジ / ルータモードで接続\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_BRIDGE_ROUTER"),\r
+                       t.ClientOption->RequireBridgeRoutingMode ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // モニタリングモードで接続\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_MONITOR"),\r
+                       t.ClientOption->RequireMonitorMode ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // ルーティング テーブルを書き換えない\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NO_TRACKING"),\r
+                       t.ClientOption->NoRoutingTracking ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // QoS制御を無効化する\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_QOS_DISABLE"),\r
+                       t.ClientOption->DisableQoS ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の削除\r
+UINT PcAccountDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_DELETE_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcDeleteAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の接続に使用するユーザー名の設定\r
+UINT PcAccountUsernameSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"USERNAME", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Username"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               StrCpy(t.ClientAuth->Username, sizeof(t.ClientAuth->Username), GetParamStr(o, "USERNAME"));\r
+\r
+               if (t.ClientAuth->AuthType == CLIENT_AUTHTYPE_PASSWORD)\r
+               {\r
+                       c->Write(c, _UU("CMD_AccountUsername_Notice"));\r
+               }\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定のユーザー認証の種類を匿名認証に設定\r
+UINT PcAccountAnonymousSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.ClientAuth->AuthType = CLIENT_AUTHTYPE_ANONYMOUS;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定のユーザー認証の種類をパスワード認証に設定\r
+UINT PcAccountPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},\r
+               {"TYPE", CmdPrompt, _UU("CMD_CascadePasswordSet_Prompt_Type"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               char *typestr = GetParamStr(o, "TYPE");\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+\r
+               // 設定変更\r
+               if (StartWith("standard", typestr))\r
+               {\r
+                       t.ClientAuth->AuthType = CLIENT_AUTHTYPE_PASSWORD;\r
+                       HashPassword(t.ClientAuth->HashedPassword, t.ClientAuth->Username,\r
+                               GetParamStr(o, "PASSWORD"));\r
+               }\r
+               else if (StartWith("radius", typestr) || StartWith("ntdomain", typestr))\r
+               {\r
+                       t.ClientAuth->AuthType = CLIENT_AUTHTYPE_PLAIN_PASSWORD;\r
+\r
+                       StrCpy(t.ClientAuth->PlainPassword, sizeof(t.ClientAuth->PlainPassword),\r
+                               GetParamStr(o, "PASSWORD"));\r
+               }\r
+               else\r
+               {\r
+                       // エラー発生\r
+                       c->Write(c, _UU("CMD_CascadePasswordSet_Type_Invalid"));\r
+                       ret = ERR_INVALID_PARAMETER;\r
+               }\r
+\r
+               if (ret == ERR_NO_ERROR)\r
+               {\r
+                       Zero(&z, sizeof(z));\r
+                       z.CheckServerCert = t.CheckServerCert;\r
+                       z.ClientAuth = t.ClientAuth;\r
+                       z.ClientOption = t.ClientOption;\r
+                       z.ServerCert = t.ServerCert;\r
+                       z.StartupAccount = t.StartupAccount;\r
+\r
+                       ret = CcSetAccount(pc->RemoteClient, &z);\r
+               }\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定のユーザー認証の種類をクライアント証明書認証に設定\r
+UINT PcAccountCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       X *x;\r
+       K *k;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"LOADCERT", CmdPrompt, _UU("CMD_LOADCERTPATH"), CmdEvalIsFile, NULL},\r
+               {"LOADKEY", CmdPrompt, _UU("CMD_LOADKEYPATH"), CmdEvalIsFile, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (CmdLoadCertAndKey(c, &x, &k, GetParamStr(o, "LOADCERT"), GetParamStr(o, "LOADKEY")) == false)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+\r
+               t.ClientAuth->AuthType = CLIENT_AUTHTYPE_CERT;\r
+               if (t.ClientAuth->ClientX != NULL)\r
+               {\r
+                       FreeX(t.ClientAuth->ClientX);\r
+               }\r
+               if (t.ClientAuth->ClientK != NULL)\r
+               {\r
+                       FreeK(t.ClientAuth->ClientK);\r
+               }\r
+\r
+               t.ClientAuth->ClientX = CloneX(x);\r
+               t.ClientAuth->ClientK = CloneK(k);\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       FreeX(x);\r
+       FreeK(k);\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定に用いるクライアント証明書の取得\r
+UINT PcAccountCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SAVECERT", CmdPrompt, _UU("CMD_SAVECERTPATH"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               if (t.ClientAuth->AuthType != CLIENT_AUTHTYPE_CERT)\r
+               {\r
+                       c->Write(c, _UU("CMD_CascadeCertSet_Not_Auth_Cert"));\r
+                       ret = ERR_INTERNAL_ERROR;\r
+               }\r
+               else if (t.ClientAuth->ClientX == NULL)\r
+               {\r
+                       c->Write(c, _UU("CMD_CascadeCertSet_Cert_Not_Exists"));\r
+                       ret = ERR_INTERNAL_ERROR;\r
+               }\r
+               else\r
+               {\r
+                       XToFile(t.ClientAuth->ClientX, GetParamStr(o, "SAVECERT"), true);\r
+               }\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の通信時の暗号化の無効化\r
+UINT PcAccountEncryptDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.ClientOption->UseEncrypt = false;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の通信時の暗号化の有効化\r
+UINT PcAccountEncryptEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.ClientOption->UseEncrypt = true;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の通信時のデータ圧縮の有効化\r
+UINT PcAccountCompressEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.ClientOption->UseCompress = true;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の通信時のデータ圧縮の無効化\r
+UINT PcAccountCompressDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.ClientOption->UseCompress = false;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の接続方法を直接 TCP/IP 接続に設定\r
+UINT PcAccountProxyNone(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.ClientOption->ProxyType = PROXY_DIRECT;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の接続方法を HTTP プロキシサーバー経由接続に設定\r
+UINT PcAccountProxyHttp(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SERVER", CmdPrompt, _UU("CMD_AccountProxyHttp_Prompt_Server"), CmdEvalHostAndPort, NULL},\r
+               {"USERNAME", NULL, NULL, NULL, NULL},\r
+               {"PASSWORD", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               char *host;\r
+               UINT port;\r
+\r
+               // データ変更\r
+               if (ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 8080))\r
+               {\r
+                       t.ClientOption->ProxyType = PROXY_HTTP;\r
+                       StrCpy(t.ClientOption->ProxyName, sizeof(t.ClientOption->ProxyName), host);\r
+                       t.ClientOption->ProxyPort = port;\r
+                       StrCpy(t.ClientOption->ProxyUsername, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "USERNAME"));\r
+                       StrCpy(t.ClientOption->ProxyPassword, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "PASSWORD"));\r
+                       Free(host);\r
+               }\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の接続方法を SOCKS プロキシサーバー経由接続に設定\r
+UINT PcAccountProxySocks(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SERVER", CmdPrompt, _UU("CMD_AccountProxyHttp_Prompt_Server"), CmdEvalHostAndPort, NULL},\r
+               {"USERNAME", NULL, NULL, NULL, NULL},\r
+               {"PASSWORD", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               char *host;\r
+               UINT port;\r
+\r
+               // データ変更\r
+               if (ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 8080))\r
+               {\r
+                       t.ClientOption->ProxyType = PROXY_SOCKS;\r
+                       StrCpy(t.ClientOption->ProxyName, sizeof(t.ClientOption->ProxyName), host);\r
+                       t.ClientOption->ProxyPort = port;\r
+                       StrCpy(t.ClientOption->ProxyUsername, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "USERNAME"));\r
+                       StrCpy(t.ClientOption->ProxyPassword, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "PASSWORD"));\r
+                       Free(host);\r
+               }\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定のサーバー証明書の検証オプションの有効化\r
+UINT PcAccountServerCertEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.CheckServerCert = true;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定のサーバー証明書の検証オプションの無効化\r
+UINT PcAccountServerCertDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.CheckServerCert = false;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定のサーバー固有証明書の設定\r
+UINT PcAccountServerCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       X *x;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"LOADCERT", CmdPrompt, _UU("CMD_LOADCERTPATH"), CmdEvalIsFile, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       x = FileToX(GetParamStr(o, "LOADCERT"));\r
+       if (x == NULL)\r
+       {\r
+               FreeParamValueList(o);\r
+               c->Write(c, _UU("CMD_LOADCERT_FAILED"));\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               if (t.ServerCert != NULL)\r
+               {\r
+                       FreeX(t.ServerCert);\r
+               }\r
+               t.ServerCert = CloneX(x);\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       FreeX(x);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定のサーバー固有証明書の削除\r
+UINT PcAccountServerCertDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               if (t.ServerCert != NULL)\r
+               {\r
+                       FreeX(t.ServerCert);\r
+               }\r
+               t.ServerCert = NULL;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定のサーバー固有証明書の取得\r
+UINT PcAccountServerCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SAVECERT", CmdPrompt, _UU("CMD_SAVECERTPATH"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               if (t.ServerCert != NULL)\r
+               {\r
+                       FreeX(t.ServerCert);\r
+               }\r
+               t.ServerCert = NULL;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の高度な通信設定の設定\r
+UINT PcAccountDetailSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       CMD_EVAL_MIN_MAX mm_maxtcp =\r
+       {\r
+               "CMD_CascadeDetailSet_Eval_MaxTcp", 1, 32\r
+       };\r
+       CMD_EVAL_MIN_MAX mm_interval =\r
+       {\r
+               "CMD_CascadeDetailSet_Eval_Interval", 1, 4294967295UL\r
+       };\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"MAXTCP", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_MaxTcp"), CmdEvalMinMax, &mm_maxtcp},\r
+               {"INTERVAL", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_Interval"), CmdEvalMinMax, &mm_interval},\r
+               {"TTL", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_TTL"), NULL, NULL},\r
+               {"HALF", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_HALF"), NULL, NULL},\r
+               {"BRIDGE", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_BRIDGE"), NULL, NULL},\r
+               {"MONITOR", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_MONITOR"), NULL, NULL},\r
+               {"NOTRACK", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_NOTRACK"), NULL, NULL},\r
+               {"NOQOS", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_NOQOS"), NULL, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // データ変更\r
+               t.ClientOption->MaxConnection = GetParamInt(o, "MAXTCP");\r
+               t.ClientOption->AdditionalConnectionInterval = GetParamInt(o, "INTERVAL");\r
+               t.ClientOption->ConnectionDisconnectSpan = GetParamInt(o, "TTL");\r
+               t.ClientOption->HalfConnection = GetParamYes(o, "HALF");\r
+               t.ClientOption->RequireBridgeRoutingMode = GetParamYes(o, "BRIDGE");\r
+               t.ClientOption->RequireMonitorMode = GetParamYes(o, "MONITOR");\r
+               t.ClientOption->NoRoutingTracking = GetParamYes(o, "NOTRACK");\r
+               t.ClientOption->DisableQoS = GetParamYes(o, "NOQOS");\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の名前の変更\r
+UINT PcAccountRename(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_RENAME_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountRename_PROMPT_OLD"), CmdEvalNotEmpty, NULL},\r
+               {"NEW", CmdPrompt, _UU("CMD_AccountRename_PROMPT_NEW"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       UniStrCpy(t.NewName, sizeof(t.NewName), GetParamUniStr(o, "NEW"));\r
+       UniStrCpy(t.OldName, sizeof(t.OldName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcRenameAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定を使用して VPN Server へ接続を開始\r
+UINT PcAccountConnect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_CONNECT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcConnect(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続中の接続設定の切断\r
+UINT PcAccountDisconnect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_CONNECT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcDisconnect(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の現在の状態の取得\r
+UINT PcAccountStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_CONNECTION_STATUS t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccountStatus(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               if (t.Active == false)\r
+               {\r
+                       // 切断されている\r
+                       ret = ERR_ACCOUNT_INACTIVE;\r
+               }\r
+               else\r
+               {\r
+                       CT *ct = CtNewStandard();\r
+\r
+                       CmdPrintStatusToListView(ct, &t);\r
+\r
+                       CtFree(ct, c);\r
+               }\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetConnectionStatus(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定で使用する仮想 LAN カードの設定\r
+UINT PcAccountNicSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"NICNAME", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Nicname"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       Zero(&t, sizeof(t));\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT c;\r
+               // 成功\r
+               StrCpy(t.ClientOption->DeviceName, sizeof(t.ClientOption->DeviceName),\r
+                       GetParamStr(o, "NICNAME"));\r
+\r
+               Zero(&c, sizeof(c));\r
+\r
+               c.ClientAuth = t.ClientAuth;\r
+               c.ClientOption = t.ClientOption;\r
+               c.CheckServerCert = t.CheckServerCert;\r
+               c.ServerCert = t.ServerCert;\r
+               c.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &c);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// VPN Server への接続中に接続状況やエラー画面を表示するように設定\r
+UINT PcAccountStatusShow(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.ClientOption->HideStatusWindow = false;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// VPN Server への接続中に接続状況やエラー画面を表示しないように設定\r
+UINT PcAccountStatusHide(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.ClientOption->HideStatusWindow = true;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定のユーザー認証の種類をスマートカード認証に設定\r
+UINT PcAccountSecureCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"CERTNAME", CmdPrompt, _UU("CMD_AccountSecureCertSet_PROMPT_CERTNAME"), CmdEvalNotEmpty, NULL},\r
+               {"KEYNAME", CmdPrompt, _UU("CMD_AccountSecureCertSet_PROMPT_KEYNAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.ClientAuth->AuthType = CLIENT_AUTHTYPE_SECURE;\r
+               StrCpy(t.ClientAuth->SecurePublicCertName, sizeof(t.ClientAuth->SecurePublicCertName),\r
+                       GetParamStr(o, "CERTNAME"));\r
+               StrCpy(t.ClientAuth->SecurePrivateKeyName, sizeof(t.ClientAuth->SecurePrivateKeyName),\r
+                       GetParamStr(o, "KEYNAME"));\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の接続失敗または切断時の再試行回数と間隔の設定\r
+UINT PcAccountRetrySet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       CMD_EVAL_MIN_MAX minmax =\r
+       {\r
+               "CMD_AccountRetrySet_EVAL_INTERVAL",\r
+               5,\r
+               4294967295UL,\r
+       };\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"NUM", CmdPrompt, _UU("CMD_AccountRetrySet_PROMPT_NUM"), CmdEvalNotEmpty, NULL},\r
+               {"INTERVAL", CmdPrompt, _UU("CMD_AccountRetrySet_PROMPY_INTERVAL"), CmdEvalMinMax, &minmax},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               UINT num = GetParamInt(o, "NUM");\r
+               UINT interval = GetParamInt(o, "INTERVAL");\r
+\r
+               t.ClientOption->NumRetry = (num == 999) ? INFINITE : num;\r
+               t.ClientOption->RetryInterval = interval;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+\r
+// 接続設定をスタートアップ接続に設定\r
+UINT PcAccountStartupSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.StartupAccount = true;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定のスタートアップ接続を解除\r
+UINT PcAccountStartupRemove(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               // 設定変更\r
+               t.StartupAccount = false;\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               ret = CcSetAccount(pc->RemoteClient, &z);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定のエクスポート\r
+UINT PcAccountExport(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       RPC_CLIENT_GET_ACCOUNT t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SAVEPATH", CmdPrompt, _UU("CMD_AccountExport_PROMPT_SAVEPATH"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = CcGetAccount(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT z;\r
+               BUF *b;\r
+               BUF *b2;\r
+               char tmp[MAX_SIZE];\r
+               UCHAR *buf;\r
+               UINT buf_size;\r
+               UCHAR bom[] = {0xef, 0xbb, 0xbf, };\r
+\r
+               Zero(&z, sizeof(z));\r
+               z.CheckServerCert = t.CheckServerCert;\r
+               z.ClientAuth = t.ClientAuth;\r
+               z.ClientOption = t.ClientOption;\r
+               z.ServerCert = t.ServerCert;\r
+               z.StartupAccount = t.StartupAccount;\r
+\r
+               b = CiAccountToCfg(&z);\r
+\r
+               StrCpy(tmp, sizeof(tmp), GetParamStr(o, "SAVEPATH"));\r
+               b2 = NewBuf();\r
+\r
+               WriteBuf(b2, bom, sizeof(bom));\r
+\r
+               // ヘッダ部分を付加する\r
+               buf_size = CalcUniToUtf8(_UU("CM_ACCOUNT_FILE_BANNER"));\r
+               buf = ZeroMalloc(buf_size + 32);\r
+               UniToUtf8(buf, buf_size, _UU("CM_ACCOUNT_FILE_BANNER"));\r
+\r
+               WriteBuf(b2, buf, StrLen((char *)buf));\r
+               WriteBuf(b2, b->Buf, b->Size);\r
+               SeekBuf(b2, 0, 0);\r
+\r
+               FreeBuf(b);\r
+\r
+               if (DumpBuf(b2, tmp) == false)\r
+               {\r
+                       c->Write(c, _UU("CMD_SAVEFILE_FAILED"));\r
+                       ret = ERR_INTERNAL_ERROR;\r
+               }\r
+\r
+               FreeBuf(b2);\r
+               Free(buf);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       CiFreeClientGetAccount(&t);\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 指定されたアカウント名が存在するかチェックする\r
+bool CmdIsAccountName(REMOTE_CLIENT *r, wchar_t *name)\r
+{\r
+       UINT i;\r
+       RPC_CLIENT_ENUM_ACCOUNT t;\r
+       wchar_t tmp[MAX_SIZE];\r
+       bool b = false;\r
+       // 引数チェック\r
+       if (r == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (CcEnumAccount(r, &t) != ERR_NO_ERROR)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniStrCpy(tmp, sizeof(tmp), name);\r
+       UniTrim(tmp);\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               if (UniStrCmpi(t.Items[i]->AccountName, tmp) == 0)\r
+               {\r
+                       b = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       CiFreeClientEnumAccount(&t);\r
+\r
+       return b;\r
+}\r
+\r
+// インポート名の生成\r
+void CmdGenerateImportName(REMOTE_CLIENT *r, wchar_t *name, UINT size, wchar_t *old_name)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (r == NULL || name == NULL || old_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 1;;i++)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               if (i == 1)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_IMPORT_NAME_1"), old_name);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_IMPORT_NAME_2"), old_name, i);\r
+               }\r
+\r
+               if (CmdIsAccountName(r, tmp) == false)\r
+               {\r
+                       UniStrCpy(name, size, tmp);\r
+                       return;\r
+               }\r
+       }\r
+}\r
+\r
+// 接続設定のインポート\r
+UINT PcAccountImport(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       BUF *b;\r
+       wchar_t name[MAX_SIZE];\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[path]", CmdPrompt, _UU("CMD_AccountImport_PROMPT_PATH"), CmdEvalIsFile, NULL},\r
+       };\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // ファイルを読み込む\r
+       b = ReadDump(GetParamStr(o, "[path]"));\r
+\r
+       if (b == NULL)\r
+       {\r
+               // 読み込み失敗\r
+               c->Write(c, _UU("CMD_LOADFILE_FAILED"));\r
+               ret = ERR_INTERNAL_ERROR;\r
+       }\r
+       else\r
+       {\r
+               RPC_CLIENT_CREATE_ACCOUNT *t;\r
+\r
+               t = CiCfgToAccount(b);\r
+\r
+               if (t == NULL)\r
+               {\r
+                       // パースに失敗\r
+                       c->Write(c, _UU("CMD_AccountImport_FAILED_PARSE"));\r
+                       ret = ERR_INTERNAL_ERROR;\r
+               }\r
+               else\r
+               {\r
+                       CmdGenerateImportName(pc->RemoteClient, name, sizeof(name), t->ClientOption->AccountName);\r
+                       UniStrCpy(t->ClientOption->AccountName, sizeof(t->ClientOption->AccountName), name);\r
+\r
+                       ret = CcCreateAccount(pc->RemoteClient, t);\r
+\r
+                       if (ret == ERR_NO_ERROR)\r
+                       {\r
+                               wchar_t tmp[MAX_SIZE];\r
+\r
+                               UniFormat(tmp, sizeof(tmp), _UU("CMD_AccountImport_OK"), name);\r
+                               c->Write(c, tmp);\r
+                       }\r
+\r
+                       CiFreeClientCreateAccount(t);\r
+                       Free(t);\r
+               }\r
+\r
+               FreeBuf(b);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// VPN Client サービスのリモート管理の許可\r
+UINT PcRemoteEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       CLIENT_CONFIG t;\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcGetClientConfig(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               t.AllowRemoteConfig = true;\r
+               ret = CcSetClientConfig(pc->RemoteClient, &t);\r
+       }\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// VPN Client サービスのリモート管理の禁止\r
+UINT PcRemoteDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       CLIENT_CONFIG t;\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcGetClientConfig(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               t.AllowRemoteConfig = false;\r
+               ret = CcSetClientConfig(pc->RemoteClient, &t);\r
+       }\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// インターネット接続の維持機能の有効化\r
+UINT PcKeepEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       CLIENT_CONFIG t;\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcGetClientConfig(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 設定変更\r
+               t.UseKeepConnect = true;\r
+               ret = CcSetClientConfig(pc->RemoteClient, &t);\r
+       }\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// インターネット接続の維持機能の無効化\r
+UINT PcKeepDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       CLIENT_CONFIG t;\r
+\r
+       // パラメータリストの取得\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcGetClientConfig(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 設定変更\r
+               t.UseKeepConnect = false;\r
+               ret = CcSetClientConfig(pc->RemoteClient, &t);\r
+       }\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               // 成功\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// インターネット接続の維持機能の設定\r
+UINT PcKeepSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       CLIENT_CONFIG t;\r
+       char *host;\r
+       UINT port;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"HOST", CmdPrompt, _UU("CMD_KeepSet_PROMPT_HOST"), CmdEvalHostAndPort, NULL},\r
+               {"PROTOCOL", CmdPrompt, _UU("CMD_KeepSet_PROMPT_PROTOCOL"), CmdEvalTcpOrUdp, NULL},\r
+               {"INTERVAL", CmdPrompt, _UU("CMD_KeepSet_PROMPT_INTERVAL"), NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcGetClientConfig(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               if (ParseHostPort(GetParamStr(o, "HOST"), &host, &port, 0))\r
+               {\r
+                       StrCpy(t.KeepConnectHost, sizeof(t.KeepConnectHost), host);\r
+                       t.KeepConnectPort = port;\r
+                       t.KeepConnectInterval = GetParamInt(o, "INTERVAL");\r
+                       t.KeepConnectProtocol = (StrCmpi(GetParamStr(o, "PROTOCOL"), "tcp") == 0) ? 0 : 1;\r
+                       Free(host);\r
+\r
+                       ret = CcSetClientConfig(pc->RemoteClient, &t);\r
+               }\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// インターネット接続の維持機能の取得\r
+UINT PcKeepGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PC *pc = (PC *)param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       CLIENT_CONFIG t;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = CcGetClientConfig(pc->RemoteClient, &t);\r
+\r
+       if (ret == ERR_NO_ERROR)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               CT *ct = CtNewStandard();\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.KeepConnectHost);\r
+               CtInsert(ct, _UU("CMD_KeepGet_COLUMN_1"), tmp);\r
+\r
+               UniToStru(tmp, t.KeepConnectPort);\r
+               CtInsert(ct, _UU("CMD_KeepGet_COLUMN_2"), tmp);\r
+\r
+               UniToStru(tmp, t.KeepConnectInterval);\r
+               CtInsert(ct, _UU("CMD_KeepGet_COLUMN_3"), tmp);\r
+\r
+               CtInsert(ct, _UU("CMD_KeepGet_COLUMN_4"),\r
+                       t.KeepConnectProtocol == 0 ? L"TCP/IP" : L"UDP/IP");\r
+\r
+               CtInsert(ct, _UU("CMD_KeepGet_COLUMN_5"),\r
+                       t.UseKeepConnect ? _UU("SM_ACCESS_ENABLE") : _UU("SM_ACCESS_DISABLE"));\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラーが発生した\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       // パラメータリストの解放\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+\r
+// 新しいクライアント管理ツールコンテキストの作成\r
+PC *NewPc(CONSOLE *c, REMOTE_CLIENT *remote_client, char *servername, wchar_t *cmdline)\r
+{\r
+       PC *pc;\r
+       // 引数チェック\r
+       if (c == NULL || remote_client == NULL || servername == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (UniIsEmptyStr(cmdline))\r
+       {\r
+               cmdline = NULL;\r
+       }\r
+\r
+       pc = ZeroMalloc(sizeof(PC));\r
+       pc->ConsoleForServer = false;\r
+       pc->ServerName = CopyStr(servername);\r
+       pc->Console = c;\r
+       pc->LastError = 0;\r
+       pc->RemoteClient = remote_client;\r
+       pc->CmdLine = CopyUniStr(cmdline);\r
+\r
+       return pc;\r
+}\r
+\r
+// クライアント管理ツールコンテキストの解放\r
+void FreePc(PC *pc)\r
+{\r
+       // 引数チェック\r
+       if (pc == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(pc->ServerName);\r
+       Free(pc->CmdLine);\r
+       Free(pc);\r
+}\r
+\r
+// クライアント管理ツール\r
+UINT PcConnect(CONSOLE *c, char *target, wchar_t *cmdline, char *password)\r
+{\r
+       CEDAR *cedar;\r
+       REMOTE_CLIENT *client;\r
+       bool bad_pass;\r
+       bool no_remote;\r
+       char pass[MAX_SIZE];\r
+       UINT ret = 0;\r
+       // 引数チェック\r
+       if (c == NULL || target == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       StrCpy(pass, sizeof(pass), password);\r
+\r
+       cedar = NewCedar(NULL, NULL);\r
+\r
+RETRY:\r
+       client = CcConnectRpc(target, pass, &bad_pass, &no_remote, 0);\r
+\r
+       if (client == NULL)\r
+       {\r
+               if (no_remote)\r
+               {\r
+                       // リモート接続拒否\r
+                       c->Write(c, _UU("CMD_UTVPNCMD_CLIENT_NO_REMODE"));\r
+                       ReleaseCedar(cedar);\r
+                       return ERR_INTERNAL_ERROR;\r
+               }\r
+               else if (bad_pass)\r
+               {\r
+                       char *tmp;\r
+                       // パスワード違い\r
+                       c->Write(c, _UU("CMD_UTVPNCMD_PASSWORD_1"));\r
+                       tmp = c->ReadPassword(c, _UU("CMD_UTVPNCMD_PASSWORD_2"));\r
+                       c->Write(c, L"");\r
+\r
+                       if (tmp == NULL)\r
+                       {\r
+                               // キャンセル\r
+                               ReleaseCedar(cedar);\r
+                               return ERR_ACCESS_DENIED;\r
+                       }\r
+                       else\r
+                       {\r
+                               StrCpy(pass, sizeof(pass), tmp);\r
+                               Free(tmp);\r
+                       }\r
+\r
+                       goto RETRY;\r
+               }\r
+               else\r
+               {\r
+                       // 接続失敗\r
+                       CmdPrintError(c, ERR_CONNECT_FAILED);\r
+                       ReleaseCedar(cedar);\r
+                       return ERR_CONNECT_FAILED;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // 接続完了\r
+               PC *pc = NewPc(c, client, target, cmdline);\r
+               PcMain(pc);\r
+               ret = pc->LastError;\r
+               FreePc(pc);\r
+       }\r
+\r
+       CcDisconnectRpc(client);\r
+\r
+       ReleaseCedar(cedar);\r
+\r
+       return ret;\r
+}\r
+\r
+\r
+// サーバー管理ツールプロセッサメイン\r
+void PsMain(PS *ps)\r
+{\r
+       char prompt[MAX_SIZE];\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (ps == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // CSV モードでなければ、接続が完了したメッセージを表示する\r
+       if(ps->Console->ConsoleType != CONSOLE_CSV)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("CMD_UTVPNCMD_SERVER_CONNECTED"),\r
+                       ps->ServerName, ps->ServerPort);\r
+               ps->Console->Write(ps->Console, tmp);\r
+               ps->Console->Write(ps->Console, L"");\r
+\r
+               if (ps->HubName == NULL)\r
+               {\r
+                       // サーバー管理モード\r
+                       ps->Console->Write(ps->Console, _UU("CMD_UTVPNCMD_SERVER_CONNECTED_1"));\r
+               }\r
+               else\r
+               {\r
+                       // 仮想 HUB 管理モード\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CMD_UTVPNCMD_SERVER_CONNECTED_2"),\r
+                               ps->HubName);\r
+                       ps->Console->Write(ps->Console, tmp);\r
+               }\r
+               ps->Console->Write(ps->Console, L"");\r
+       }\r
+\r
+       // Caps を取得\r
+       ps->CapsList = ScGetCapsEx(ps->Rpc);\r
+\r
+       if (ps->AdminHub != NULL)\r
+       {\r
+               RPC_HUB_STATUS t;\r
+               UINT ret;\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               // ADMINHUB で指定された仮想 HUB を選択する\r
+               Zero(&t, sizeof(t));\r
+\r
+               StrCpy(t.HubName, sizeof(t.HubName), ps->AdminHub);\r
+\r
+               ret = ScGetHubStatus(ps->Rpc, &t);\r
+               if (ret == ERR_NO_ERROR)\r
+               {\r
+                       // 成功\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CMD_Hub_Selected"), t.HubName);\r
+\r
+                       if (ps->HubName != NULL)\r
+                       {\r
+                               Free(ps->HubName);\r
+                       }\r
+                       ps->HubName = CopyStr(t.HubName);\r
+\r
+                       if( ps->Console->ConsoleType != CONSOLE_CSV)\r
+                       {\r
+                               ps->Console->Write(ps->Console, tmp);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // 失敗\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CMD_Hub_Select_Failed"), ps->AdminHub);\r
+\r
+                       ps->Console->Write(ps->Console, tmp);\r
+                       CmdPrintError(ps->Console, ret);\r
+               }\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               // コマンドの定義\r
+               CMD cmd[] =\r
+               {\r
+                       {"About", PsAbout},\r
+                       {"Check", PtCheck},\r
+                       {"Crash", PsCrash},\r
+                       {"Flush", PsFlush},\r
+                       {"Debug", PsDebug},\r
+                       {"ServerInfoGet", PsServerInfoGet},\r
+                       {"ServerStatusGet", PsServerStatusGet},\r
+                       {"ListenerCreate", PsListenerCreate},\r
+                       {"ListenerDelete", PsListenerDelete},\r
+                       {"ListenerList", PsListenerList},\r
+                       {"ListenerEnable", PsListenerEnable},\r
+                       {"ListenerDisable", PsListenerDisable},\r
+                       {"ServerPasswordSet", PsServerPasswordSet},\r
+                       {"ClusterSettingGet", PsClusterSettingGet},\r
+                       {"ClusterSettingStandalone", PsClusterSettingStandalone},\r
+                       {"ClusterSettingController", PsClusterSettingController},\r
+                       {"ClusterSettingMember", PsClusterSettingMember},\r
+                       {"ClusterMemberList", PsClusterMemberList},\r
+                       {"ClusterMemberInfoGet", PsClusterMemberInfoGet},\r
+                       {"ClusterMemberCertGet", PsClusterMemberCertGet},\r
+                       {"ClusterConnectionStatusGet", PsClusterConnectionStatusGet},\r
+                       {"ServerCertGet", PsServerCertGet},\r
+                       {"ServerKeyGet", PsServerKeyGet},\r
+                       {"ServerCertSet", PsServerCertSet},\r
+                       {"ServerCipherGet", PsServerCipherGet},\r
+                       {"ServerCipherSet", PsServerCipherSet},\r
+                       {"KeepEnable", PsKeepEnable},\r
+                       {"KeepDisable", PsKeepDisable},\r
+                       {"KeepSet", PsKeepSet},\r
+                       {"KeepGet", PsKeepGet},\r
+                       {"SyslogGet", PsSyslogGet},\r
+                       {"SyslogDisable", PsSyslogDisable},\r
+                       {"SyslogEnable", PsSyslogEnable},\r
+                       {"ConnectionList", PsConnectionList},\r
+                       {"ConnectionGet", PsConnectionGet},\r
+                       {"ConnectionDisconnect", PsConnectionDisconnect},\r
+                       {"BridgeDeviceList", PsBridgeDeviceList},\r
+                       {"BridgeList", PsBridgeList},\r
+                       {"BridgeCreate", PsBridgeCreate},\r
+                       {"BridgeDelete", PsBridgeDelete},\r
+                       {"Caps", PsCaps},\r
+                       {"Reboot", PsReboot},\r
+                       {"ConfigGet", PsConfigGet},\r
+                       {"ConfigSet", PsConfigSet},\r
+                       {"RouterList", PsRouterList},\r
+                       {"RouterAdd", PsRouterAdd},\r
+                       {"RouterDelete", PsRouterDelete},\r
+                       {"RouterStart", PsRouterStart},\r
+                       {"RouterStop", PsRouterStop},\r
+                       {"RouterIfList", PsRouterIfList},\r
+                       {"RouterIfAdd", PsRouterIfAdd},\r
+                       {"RouterIfDel", PsRouterIfDel},\r
+                       {"RouterTableList", PsRouterTableList},\r
+                       {"RouterTableAdd", PsRouterTableAdd},\r
+                       {"RouterTableDel", PsRouterTableDel},\r
+                       {"LogFileList", PsLogFileList},\r
+                       {"LogFileGet", PsLogFileGet},\r
+                       {"HubCreate", PsHubCreate},\r
+                       {"HubCreateDynamic", PsHubCreateDynamic},\r
+                       {"HubCreateStatic", PsHubCreateStatic},\r
+                       {"HubDelete", PsHubDelete},\r
+                       {"HubSetStatic", PsHubSetStatic},\r
+                       {"HubSetDynamic", PsHubSetDynamic},\r
+                       {"HubList", PsHubList},\r
+                       {"Hub", PsHub},\r
+                       {"Online", PsOnline},\r
+                       {"Offline", PsOffline},\r
+                       {"SetMaxSession", PsSetMaxSession},\r
+                       {"SetHubPassword", PsSetHubPassword},\r
+                       {"SetEnumAllow", PsSetEnumAllow},\r
+                       {"SetEnumDeny", PsSetEnumDeny},\r
+                       {"OptionsGet", PsOptionsGet},\r
+                       {"RadiusServerSet", PsRadiusServerSet},\r
+                       {"RadiusServerDelete", PsRadiusServerDelete},\r
+                       {"RadiusServerGet", PsRadiusServerGet},\r
+                       {"StatusGet", PsStatusGet},\r
+                       {"LogGet", PsLogGet},\r
+                       {"LogEnable", PsLogEnable},\r
+                       {"LogDisable", PsLogDisable},\r
+                       {"LogSwitchSet", PsLogSwitchSet},\r
+                       {"LogPacketSaveType", PsLogPacketSaveType},\r
+                       {"CAList", PsCAList},\r
+                       {"CAAdd", PsCAAdd},\r
+                       {"CADelete", PsCADelete},\r
+                       {"CAGet", PsCAGet},\r
+                       {"CascadeList", PsCascadeList},\r
+                       {"CascadeCreate", PsCascadeCreate},\r
+                       {"CascadeSet", PsCascadeSet},\r
+                       {"CascadeGet", PsCascadeGet},\r
+                       {"CascadeDelete", PsCascadeDelete},\r
+                       {"CascadeUsernameSet", PsCascadeUsernameSet},\r
+                       {"CascadeAnonymousSet", PsCascadeAnonymousSet},\r
+                       {"CascadePasswordSet", PsCascadePasswordSet},\r
+                       {"CascadeCertSet", PsCascadeCertSet},\r
+                       {"CascadeCertGet", PsCascadeCertGet},\r
+                       {"CascadeEncryptEnable", PsCascadeEncryptEnable},\r
+                       {"CascadeEncryptDisable", PsCascadeEncryptDisable},\r
+                       {"CascadeCompressEnable", PsCascadeCompressEnable},\r
+                       {"CascadeCompressDisable", PsCascadeCompressDisable},\r
+                       {"CascadeProxyNone", PsCascadeProxyNone},\r
+                       {"CascadeProxyHttp", PsCascadeProxyHttp},\r
+                       {"CascadeProxySocks", PsCascadeProxySocks},\r
+                       {"CascadeServerCertEnable", PsCascadeServerCertEnable},\r
+                       {"CascadeServerCertDisable", PsCascadeServerCertDisable},\r
+                       {"CascadeServerCertSet", PsCascadeServerCertSet},\r
+                       {"CascadeServerCertDelete", PsCascadeServerCertDelete},\r
+                       {"CascadeServerCertGet", PsCascadeServerCertGet},\r
+                       {"CascadeDetailSet", PsCascadeDetailSet},\r
+                       {"CascadePolicySet", PsCascadePolicySet},\r
+                       {"PolicyList", PsPolicyList},\r
+                       {"CascadeStatusGet", PsCascadeStatusGet},\r
+                       {"CascadeRename", PsCascadeRename},\r
+                       {"CascadeOnline", PsCascadeOnline},\r
+                       {"CascadeOffline", PsCascadeOffline},\r
+                       {"AccessAdd", PsAccessAdd},\r
+                       {"AccessAddEx", PsAccessAddEx},\r
+                       {"AccessAdd6", PsAccessAdd6},\r
+                       {"AccessAddEx6", PsAccessAddEx6},\r
+                       {"AccessList", PsAccessList},\r
+                       {"AccessDelete", PsAccessDelete},\r
+                       {"AccessEnable", PsAccessEnable},\r
+                       {"AccessDisable", PsAccessDisable},\r
+                       {"UserList", PsUserList},\r
+                       {"UserCreate", PsUserCreate},\r
+                       {"UserSet", PsUserSet},\r
+                       {"UserDelete", PsUserDelete},\r
+                       {"UserGet", PsUserGet},\r
+                       {"UserAnonymousSet", PsUserAnonymousSet},\r
+                       {"UserPasswordSet", PsUserPasswordSet},\r
+                       {"UserCertSet", PsUserCertSet},\r
+                       {"UserCertGet", PsUserCertGet},\r
+                       {"UserSignedSet", PsUserSignedSet},\r
+                       {"UserRadiusSet", PsUserRadiusSet},\r
+                       {"UserNTLMSet", PsUserNTLMSet},\r
+                       {"UserPolicyRemove", PsUserPolicyRemove},\r
+                       {"UserPolicySet", PsUserPolicySet},\r
+                       {"UserExpiresSet", PsUserExpiresSet},\r
+                       {"GroupList", PsGroupList},\r
+                       {"GroupCreate", PsGroupCreate},\r
+                       {"GroupSet", PsGroupSet},\r
+                       {"GroupDelete", PsGroupDelete},\r
+                       {"GroupGet", PsGroupGet},\r
+                       {"GroupJoin", PsGroupJoin},\r
+                       {"GroupUnjoin", PsGroupUnjoin},\r
+                       {"GroupPolicyRemove", PsGroupPolicyRemove},\r
+                       {"GroupPolicySet", PsGroupPolicySet},\r
+                       {"SessionList", PsSessionList},\r
+                       {"SessionGet", PsSessionGet},\r
+                       {"SessionDisconnect", PsSessionDisconnect},\r
+                       {"MacTable", PsMacTable},\r
+                       {"MacDelete", PsMacDelete},\r
+                       {"IpTable", PsIpTable},\r
+                       {"IpDelete", PsIpDelete},\r
+                       {"SecureNatEnable", PsSecureNatEnable},\r
+                       {"SecureNatDisable", PsSecureNatDisable},\r
+                       {"SecureNatStatusGet", PsSecureNatStatusGet},\r
+                       {"SecureNatHostGet", PsSecureNatHostGet},\r
+                       {"SecureNatHostSet", PsSecureNatHostSet},\r
+                       {"NatGet", PsNatGet},\r
+                       {"NatEnable", PsNatEnable},\r
+                       {"NatDisable", PsNatDisable},\r
+                       {"NatSet", PsNatSet},\r
+                       {"NatTable", PsNatTable},\r
+                       {"DhcpGet", PsDhcpGet},\r
+                       {"DhcpEnable", PsDhcpEnable},\r
+                       {"DhcpDisable", PsDhcpDisable},\r
+                       {"DhcpSet", PsDhcpSet},\r
+                       {"DhcpTable", PsDhcpTable},\r
+                       {"AdminOptionList", PsAdminOptionList},\r
+                       {"AdminOptionSet", PsAdminOptionSet},\r
+                       {"ExtOptionList", PsExtOptionList},\r
+                       {"ExtOptionSet", PsExtOptionSet},\r
+                       {"CrlList", PsCrlList},\r
+                       {"CrlAdd", PsCrlAdd},\r
+                       {"CrlDel", PsCrlDel},\r
+                       {"CrlGet", PsCrlGet},\r
+                       {"AcList", PsAcList},\r
+                       {"AcAdd", PsAcAdd},\r
+                       {"AcAdd6", PsAcAdd6},\r
+                       {"AcDel", PsAcDel},\r
+                       {"MakeCert", PtMakeCert},\r
+                       {"TrafficClient", PtTrafficClient},\r
+                       {"TrafficServer", PtTrafficServer},\r
+                       {"LicenseAdd", PsLicenseAdd},\r
+                       {"LicenseDel", PsLicenseDel},\r
+                       {"LicenseList", PsLicenseList},\r
+                       {"LicenseStatus", PsLicenseStatus},\r
+               };\r
+\r
+               // プロンプトの生成\r
+               if (ps->HubName == NULL)\r
+               {\r
+                       Format(prompt, sizeof(prompt), "VPN Server>");\r
+               }\r
+               else\r
+               {\r
+                       Format(prompt, sizeof(prompt), "VPN Server/%s>", ps->HubName);\r
+               }\r
+\r
+               if (DispatchNextCmdEx(ps->Console, ps->CmdLine, prompt, cmd, sizeof(cmd) / sizeof(cmd[0]), ps) == false)\r
+               {\r
+                       break;\r
+               }\r
+               ps->LastError = ps->Console->RetCode;\r
+\r
+               if (ps->LastError == ERR_NO_ERROR && ps->Console->ConsoleType != CONSOLE_CSV)\r
+               {\r
+                       ps->Console->Write(ps->Console, _UU("CMD_MSG_OK"));\r
+                       ps->Console->Write(ps->Console, L"");\r
+               }\r
+\r
+               if (ps->CmdLine != NULL)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       // Caps を解放\r
+       FreeCapsList(ps->CapsList);\r
+       ps->CapsList = NULL;\r
+}\r
+\r
+// 新しいコマンド関数のテンプレート\r
+UINT PsXxx(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret;\r
+       RPC_LISTENER t;\r
+       PARAM args[] =\r
+       {\r
+               {"[port]", CmdPromptPort, _UU("CMD_ListenerCreate_PortPrompt"), CmdEvalPort, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.Enable = true;\r
+       t.Port = ToInt(GetParamStr(o, "[port]"));\r
+\r
+       ret = ScCreateListener(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// スタンドアロンモードに設定\r
+UINT PsClusterSettingStandalone(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_FARM t;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.ServerType = SERVER_TYPE_STANDALONE;\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetFarmSetting(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// クラスタコントローラモードに設定\r
+UINT PsClusterSettingController(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_FARM t;\r
+       UINT weight;\r
+       PARAM args[] =\r
+       {\r
+               {"WEIGHT", NULL, NULL, NULL, NULL},\r
+               {"ONLY", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       weight = GetParamInt(o, "WEIGHT");\r
+       if (weight == 0)\r
+       {\r
+               weight = FARM_DEFAULT_WEIGHT;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.ServerType = SERVER_TYPE_FARM_CONTROLLER;\r
+       t.Weight = weight;\r
+       t.ControllerOnly = GetParamYes(o, "ONLY");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetFarmSetting(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// IP アドレスの評価\r
+bool CmdEvalIp(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (UniIsEmptyStr(str))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (UniStrToIP32(str) == 0 && UniStrCmpi(str, L"0.0.0.0") != 0)\r
+       {\r
+               wchar_t *msg = (param == NULL) ? _UU("CMD_IP_EVAL_FAILED") : (wchar_t *)param;\r
+               c->Write(c, msg);\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 文字列をポートリストに変換\r
+LIST *StrToPortList(char *str)\r
+{\r
+       LIST *o;\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // トークンに変換\r
+       t = ParseToken(str, ", ");\r
+       if (t == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (t->NumTokens == 0)\r
+       {\r
+               FreeToken(t);\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               char *s = t->Token[i];\r
+               UINT n;\r
+               if (IsNum(s) == false)\r
+               {\r
+                       ReleaseList(o);\r
+                       FreeToken(t);\r
+                       return NULL;\r
+               }\r
+               n = ToInt(s);\r
+               if (n == 0 || n >= 65536)\r
+               {\r
+                       ReleaseList(o);\r
+                       FreeToken(t);\r
+                       return NULL;\r
+               }\r
+               if (IsInList(o, (void *)n))\r
+               {\r
+                       ReleaseList(o);\r
+                       FreeToken(t);\r
+                       return NULL;\r
+               }\r
+               Add(o, (void *)n);\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       if (LIST_NUM(o) > MAX_PUBLIC_PORT_NUM)\r
+       {\r
+               ReleaseList(o);\r
+               return NULL;\r
+       }\r
+\r
+       return o;\r
+}\r
+\r
+// クラスタメンバモードに設定\r
+UINT PsClusterSettingMember(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_FARM t;\r
+       char *host_and_port;\r
+       char *host;\r
+       UINT port;\r
+       UINT weight;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[server:port]", CmdPrompt, _UU("CMD_ClusterSettingMember_Prompt_HOST_1"), CmdEvalHostAndPort, NULL},\r
+               {"IP", PsClusterSettingMemberPromptIp, NULL, CmdEvalIp, NULL},\r
+               {"PORTS", PsClusterSettingMemberPromptPorts, NULL, CmdEvalPortList, NULL},\r
+               {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},\r
+               {"WEIGHT", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       weight = GetParamInt(o, "WEIGHT");\r
+\r
+       if (weight == 0)\r
+       {\r
+               weight = FARM_DEFAULT_WEIGHT;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       host_and_port = GetParamStr(o, "[server:port]");\r
+       if (ParseHostPort(host_and_port, &host, &port, 0))\r
+       {\r
+               char *pw;\r
+               char *ports_str;\r
+               LIST *ports;\r
+               UINT i;\r
+\r
+               StrCpy(t.ControllerName, sizeof(t.ControllerName), host);\r
+               t.ControllerPort = port;\r
+               Free(host);\r
+\r
+               pw = GetParamStr(o, "PASSWORD");\r
+\r
+               Hash(t.MemberPassword, pw, StrLen(pw), true);\r
+               t.PublicIp = StrToIP32(GetParamStr(o, "IP"));\r
+               t.ServerType = SERVER_TYPE_FARM_MEMBER;\r
+\r
+               ports_str = GetParamStr(o, "PORTS");\r
+\r
+               ports = StrToPortList(ports_str);\r
+\r
+               t.NumPort = LIST_NUM(ports);\r
+               t.Ports = ZeroMalloc(sizeof(UINT) * t.NumPort);\r
+\r
+               for (i = 0;i < t.NumPort;i++)\r
+               {\r
+                       t.Ports[i] = (UINT)LIST_DATA(ports, i);\r
+               }\r
+\r
+               t.Weight = weight;\r
+\r
+               ReleaseList(ports);\r
+\r
+               // RPC 呼び出し\r
+               ret = ScSetFarmSetting(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcFarm(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ポート一覧の評価\r
+bool CmdEvalPortList(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char *s;\r
+       bool ret = false;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s = CopyUniToStr(str);\r
+\r
+       o = StrToPortList(s);\r
+\r
+       if (o != NULL)\r
+       {\r
+               ret = true;\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       Free(s);\r
+\r
+       if (ret == false)\r
+       {\r
+               c->Write(c, _UU("CMD_PORTLIST_EVAL_FAILED"));\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ホスト名とポート番号の形式の文字列のチェック\r
+bool CmdEvalHostAndPort(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char *tmp;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       tmp = CopyUniToStr(str);\r
+\r
+       ret = ParseHostPort(tmp, NULL, NULL, (UINT)param);\r
+\r
+       if (ret == false)\r
+       {\r
+               c->Write(c, param == NULL ? _UU("CMD_HOSTPORT_EVAL_FAILED") : (wchar_t *)param);\r
+       }\r
+\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// 公開 ポート番号の入力\r
+wchar_t *PsClusterSettingMemberPromptPorts(CONSOLE *c, void *param)\r
+{\r
+       wchar_t *ret;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       c->Write(c, _UU("CMD_ClusterSettingMember_Prompt_PORT_1"));\r
+       c->Write(c, L"");\r
+\r
+       ret = c->ReadLine(c, _UU("CMD_ClusterSettingMember_Prompt_PORT_2"), true);\r
+\r
+       return ret;\r
+}\r
+\r
+// 公開 IP アドレスの入力\r
+wchar_t *PsClusterSettingMemberPromptIp(CONSOLE *c, void *param)\r
+{\r
+       wchar_t *ret;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       c->Write(c, _UU("CMD_ClusterSettingMember_Prompt_IP_1"));\r
+       c->Write(c, L"");\r
+\r
+       ret = c->ReadLine(c, _UU("CMD_ClusterSettingMember_Prompt_IP_2"), true);\r
+\r
+       return ret;\r
+}\r
+\r
+// クラスタメンバリストの表示\r
+UINT PsClusterMemberList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_FARM t;\r
+       CT *ct;\r
+       UINT i;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumFarmMember(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       ct = CtNew();\r
+\r
+       CtInsertColumn(ct, _UU("CMD_ID"), true);\r
+       CtInsertColumn(ct, _UU("SM_FM_COLUMN_1"), false);\r
+       CtInsertColumn(ct, _UU("SM_FM_COLUMN_2"), false);\r
+       CtInsertColumn(ct, _UU("SM_FM_COLUMN_3"), false);\r
+       CtInsertColumn(ct, _UU("SM_FM_COLUMN_4"), true);\r
+       CtInsertColumn(ct, _UU("SM_FM_COLUMN_5"), true);\r
+       CtInsertColumn(ct, _UU("SM_FM_COLUMN_6"), true);\r
+       CtInsertColumn(ct, _UU("SM_FM_COLUMN_7"), true);\r
+       CtInsertColumn(ct, _UU("SM_FM_COLUMN_8"), true);\r
+       CtInsertColumn(ct, _UU("SM_FM_COLUMN_9"), true);\r
+\r
+       for (i = 0;i < t.NumFarm;i++)\r
+       {\r
+               RPC_ENUM_FARM_ITEM *e = &t.Farms[i];\r
+               wchar_t tmp0[64];\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               wchar_t tmp3[64];\r
+               wchar_t tmp4[64];\r
+               wchar_t tmp5[64];\r
+               wchar_t tmp6[64];\r
+               wchar_t tmp7[64];\r
+               wchar_t tmp8[64];\r
+\r
+               GetDateTimeStrEx64(tmp1, sizeof(tmp1), SystemToLocal64(e->ConnectedTime), NULL);\r
+               StrToUni(tmp2, sizeof(tmp2), e->Hostname);\r
+               UniToStru(tmp3, e->Point);\r
+               UniToStru(tmp4, e->NumSessions);\r
+               UniToStru(tmp5, e->NumTcpConnections);\r
+               UniToStru(tmp6, e->NumHubs);\r
+               UniToStru(tmp7, e->AssignedClientLicense);\r
+               UniToStru(tmp8, e->AssignedBridgeLicense);\r
+\r
+               UniToStru(tmp0, e->Id);\r
+\r
+               CtInsert(ct, tmp0,\r
+                       e->Controller ? _UU("SM_FM_CONTROLLER") : _UU("SM_FM_MEMBER"),\r
+                       tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8);\r
+       }\r
+\r
+       CtFree(ct, c);\r
+\r
+       FreeRpcEnumFarm(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// クラスタ メンバの情報の取得\r
+UINT PsClusterMemberInfoGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_FARM_INFO t;\r
+       CT *ct;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_ClusterMemberInfoGet_PROMPT_ID"), NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.Id = UniToInt(GetParamUniStr(o, "[id]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetFarmInfo(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       ct = CtNewStandard();\r
+\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               char str[MAX_SIZE];\r
+               UINT i;\r
+\r
+               CtInsert(ct, _UU("SM_FMINFO_TYPE"),\r
+                       t.Controller ? _UU("SM_FARM_CONTROLLER") : _UU("SM_FARM_MEMBER"));\r
+\r
+               GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.ConnectedTime), NULL);\r
+               CtInsert(ct, _UU("SM_FMINFO_CONNECT_TIME"), tmp);\r
+\r
+               IPToStr32(str, sizeof(str), t.Ip);\r
+               StrToUni(tmp, sizeof(tmp), str);\r
+               CtInsert(ct, _UU("SM_FMINFO_IP"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.Hostname);\r
+               CtInsert(ct, _UU("SM_FMINFO_HOSTNAME"), tmp);\r
+\r
+               UniToStru(tmp, t.Point);\r
+               CtInsert(ct, _UU("SM_FMINFO_POINT"), tmp);\r
+\r
+               UniToStru(tmp, t.Weight);\r
+               CtInsert(ct, _UU("SM_FMINFO_WEIGHT"), tmp);\r
+\r
+               UniToStru(tmp, t.NumPort);\r
+               CtInsert(ct, _UU("SM_FMINFO_NUM_PORT"), tmp);\r
+\r
+               for (i = 0;i < t.NumPort;i++)\r
+               {\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       UniFormat(tmp, sizeof(tmp), _UU("SM_FMINFO_PORT"), i + 1);\r
+                       UniToStru(tmp2, t.Ports[i]);\r
+                       CtInsert(ct, tmp, tmp2);\r
+               }\r
+\r
+               UniToStru(tmp, t.NumFarmHub);\r
+               CtInsert(ct, _UU("SM_FMINFO_NUM_HUB"), tmp);\r
+\r
+               for (i = 0;i < t.NumFarmHub;i++)\r
+               {\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       UniFormat(tmp, sizeof(tmp), _UU("SM_FMINFO_HUB"), i + 1);\r
+                       UniFormat(tmp2, sizeof(tmp2),\r
+                               t.FarmHubs[i].DynamicHub ? _UU("SM_FMINFO_HUB_TAG_2") : _UU("SM_FMINFO_HUB_TAG_1"),\r
+                               t.FarmHubs[i].HubName);\r
+                       CtInsert(ct, tmp, tmp2);\r
+               }\r
+\r
+               UniToStru(tmp, t.NumSessions);\r
+               CtInsert(ct, _UU("SM_FMINFO_NUM_SESSION"), tmp);\r
+\r
+               UniToStru(tmp, t.NumTcpConnections);\r
+               CtInsert(ct, _UU("SM_FMINFO_NUN_CONNECTION"), tmp);\r
+       }\r
+\r
+       CtFree(ct, c);\r
+\r
+       FreeRpcFarmInfo(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// クラスタ メンバの証明書の取得\r
+UINT PsClusterMemberCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_FARM_INFO t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_ClusterMemberCertGet_PROMPT_ID"), NULL, NULL},\r
+               {"SAVECERT", CmdPrompt, _UU("CMD_SAVECERTPATH"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       t.Id = UniToInt(GetParamUniStr(o, "[id]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetFarmInfo(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               X *x = t.ServerCert;\r
+               char *filename = GetParamStr(o, "SAVECERT");\r
+\r
+               if (XToFile(x, filename, true) == false)\r
+               {\r
+                       c->Write(c, _UU("CMD_SAVECERT_FAILED"));\r
+\r
+                       ret = ERR_INTERNAL_ERROR;\r
+               }\r
+       }\r
+\r
+       FreeRpcFarmInfo(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// クラスタ コントローラへの接続状態の取得\r
+UINT PsClusterConnectionStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_FARM_CONNECTION_STATUS t;\r
+       wchar_t tmp[MAX_SIZE];\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetFarmConnectionStatus(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNewStandard();\r
+               char str[MAX_SIZE];\r
+\r
+               if (t.Online == false)\r
+               {\r
+                       CtInsert(ct, _UU("SM_FC_IP"), _UU("SM_FC_NOT_CONNECTED"));\r
+\r
+                       CtInsert(ct, _UU("SM_FC_PORT"), _UU("SM_FC_NOT_CONNECTED"));\r
+               }\r
+               else\r
+               {\r
+                       IPToStr32(str, sizeof(str), t.Ip);\r
+                       StrToUni(tmp, sizeof(tmp), str);\r
+                       CtInsert(ct, _UU("SM_FC_IP"), tmp);\r
+\r
+                       UniToStru(tmp, t.Port);\r
+                       CtInsert(ct, _UU("SM_FC_PORT"), tmp);\r
+               }\r
+\r
+               CtInsert(ct,\r
+                       _UU("SM_FC_STATUS"),\r
+                       t.Online ? _UU("SM_FC_ONLINE") : _UU("SM_FC_OFFLINE"));\r
+\r
+               if (t.Online == false)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("SM_FC_ERROR_TAG"), _E(t.LastError), t.LastError);\r
+                       CtInsert(ct,\r
+                               _UU("SM_FC_LAST_ERROR"), tmp);\r
+               }\r
+\r
+               GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.StartedTime), NULL);\r
+               CtInsert(ct, _UU("SM_FC_START_TIME"), tmp);\r
+\r
+               GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.FirstConnectedTime), NULL);\r
+               CtInsert(ct, _UU("SM_FC_FIRST_TIME"), tmp);\r
+\r
+               //if (t.Online == false)\r
+               {\r
+                       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.CurrentConnectedTime), NULL);\r
+                       CtInsert(ct, _UU("SM_FC_CURRENT_TIME"), tmp);\r
+               }\r
+\r
+               UniToStru(tmp, t.NumTry);\r
+               CtInsert(ct, _UU("SM_FC_NUM_TRY"), tmp);\r
+\r
+               UniToStru(tmp, t.NumConnected);\r
+               CtInsert(ct, _UU("SM_FC_NUM_CONNECTED"), tmp);\r
+\r
+               UniToStru(tmp, t.NumFailed);\r
+               CtInsert(ct, _UU("SM_FC_NUM_FAILED"), tmp);\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// VPN Server の SSL 証明書の取得\r
+UINT PsServerCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_KEY_PAIR t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[cert]", CmdPrompt, _UU("CMD_SAVECERTPATH"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetServerCert(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       if (XToFile(t.Cert, GetParamStr(o, "[cert]"), true) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_SAVECERT_FAILED"));\r
+       }\r
+\r
+       FreeRpcKeyPair(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// VPN Server の SSL 証明書の秘密鍵の取得\r
+UINT PsServerKeyGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_KEY_PAIR t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[key]", CmdPrompt, _UU("CMD_SAVEKEYPATH"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetServerCert(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       if (t.Key != NULL)\r
+       {\r
+               if (KToFile(t.Key, GetParamStr(o, "[key]"), true, NULL) == false)\r
+               {\r
+                       c->Write(c, _UU("CMD_SAVEKEY_FAILED"));\r
+               }\r
+       }\r
+       else\r
+       {\r
+               ret = ERR_NOT_ENOUGH_RIGHT;\r
+               CmdPrintError(c, ret);\r
+       }\r
+\r
+       FreeRpcKeyPair(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 証明書と秘密鍵の読み込み\r
+bool CmdLoadCertAndKey(CONSOLE *c, X **xx, K **kk, char *cert_filename, char *key_filename)\r
+{\r
+       X *x;\r
+       K *k;\r
+       // 引数チェック\r
+       if (c == NULL || cert_filename == NULL || key_filename == NULL || xx == NULL || kk == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       x = FileToX(cert_filename);\r
+       if (x == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_LOADCERT_FAILED"));\r
+               return false;\r
+       }\r
+\r
+       k = CmdLoadKey(c, key_filename);\r
+       if (k == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_LOADKEY_FAILED"));\r
+               FreeX(x);\r
+               return false;\r
+       }\r
+\r
+       if (CheckXandK(x, k) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_KEYPAIR_FAILED"));\r
+               FreeX(x);\r
+               FreeK(k);\r
+\r
+               return false;\r
+       }\r
+\r
+       *xx = x;\r
+       *kk = k;\r
+\r
+       return true;\r
+}\r
+\r
+// 秘密鍵の読み込み\r
+K *CmdLoadKey(CONSOLE *c, char *filename)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (c == NULL || filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = ReadDump(filename);\r
+       if (b == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_LOADCERT_FAILED"));\r
+               return NULL;\r
+       }\r
+       else\r
+       {\r
+               K *key;\r
+               if (IsEncryptedK(b, true) == false)\r
+               {\r
+                       key = BufToK(b, true, IsBase64(b), NULL);\r
+               }\r
+               else\r
+               {\r
+                       c->Write(c, _UU("CMD_LOADKEY_ENCRYPTED_1"));\r
+\r
+                       while (true)\r
+                       {\r
+                               char *pass = c->ReadPassword(c, _UU("CMD_LOADKEY_ENCRYPTED_2"));\r
+\r
+                               if (pass == NULL)\r
+                               {\r
+                                       FreeBuf(b);\r
+                                       return NULL;\r
+                               }\r
+\r
+                               key = BufToK(b, true, IsBase64(b), pass);\r
+                               Free(pass);\r
+\r
+                               if (key != NULL)\r
+                               {\r
+                                       break;\r
+                               }\r
+\r
+                               c->Write(c, _UU("CMD_LOADKEY_ENCRYPTED_3"));\r
+                       }\r
+               }\r
+\r
+               FreeBuf(b);\r
+\r
+               return key;\r
+       }\r
+}\r
+\r
+// VPN Server の SSL 証明書と秘密鍵の設定\r
+UINT PsServerCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_KEY_PAIR t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"LOADCERT", CmdPrompt, _UU("CMD_LOADCERTPATH"), CmdEvalIsFile, NULL},\r
+               {"LOADKEY", CmdPrompt, _UU("CMD_LOADKEYPATH"), CmdEvalIsFile, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       if (CmdLoadCertAndKey(c, &t.Cert, &t.Key,\r
+               GetParamStr(o, "LOADCERT"),\r
+               GetParamStr(o, "LOADKEY")))\r
+       {\r
+               // RPC 呼び出し\r
+               ret = ScSetServerCert(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcKeyPair(&t);\r
+       }\r
+       else\r
+       {\r
+               ret = ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// VPN 通信で使用される暗号化アルゴリズムの取得\r
+UINT PsServerCipherGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_STR t;\r
+       TOKEN_LIST *ciphers;\r
+       UINT i;\r
+       wchar_t tmp[MAX_SIZE];\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetServerCipher(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       ciphers = GetCipherList();\r
+\r
+       c->Write(c, _UU("CMD_ServerCipherGet_SERVER"));\r
+\r
+       UniFormat(tmp, sizeof(tmp), L" %S", t.String);\r
+       c->Write(c, tmp);\r
+\r
+       c->Write(c, L"");\r
+       c->Write(c, _UU("CMD_ServerCipherGet_CIPHERS"));\r
+\r
+       for (i = 0;i < ciphers->NumTokens;i++)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), L" %S", ciphers->Token[i]);\r
+               c->Write(c, tmp);\r
+       }\r
+\r
+       FreeRpcStr(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// VPN 通信で使用される暗号化アルゴリズムの設定\r
+UINT PsServerCipherSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_STR t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_ServerCipherSet_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.String = CopyStr(GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetServerCipher(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcStr(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// インターネット接続の維持機能の有効化\r
+UINT PsKeepEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_KEEP t;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetKeep(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       t.UseKeepConnect = true;\r
+\r
+       ret = ScSetKeep(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// インターネット接続の維持機能の無効化\r
+UINT PsKeepDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_KEEP t;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetKeep(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       t.UseKeepConnect = false;\r
+\r
+       ret = ScSetKeep(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// tcp または udp の評価\r
+bool CmdEvalTcpOrUdp(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (UniStrCmpi(str, L"tcp") == 0 || UniStrCmpi(str, L"udp") == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       c->Write(c, _UU("CMD_KeepSet_EVAL_TCP_UDP"));\r
+\r
+       return false;\r
+}\r
+\r
+// syslog 設定の有効化\r
+UINT PsSyslogEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       SYSLOG_SETTING t;\r
+       CMD_EVAL_MIN_MAX minmax = {"CMD_SyslogEnable_MINMAX", 1, 3};\r
+       char *host;\r
+       UINT port;\r
+\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[1|2|3]", CmdPrompt, _UU("CMD_SyslogEnable_Prompt_123"), CmdEvalMinMax, &minmax},\r
+               {"HOST", CmdPrompt, _UU("CMD_SyslogEnable_Prompt_HOST"), CmdEvalHostAndPort, (void *)SYSLOG_PORT},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       if (ParseHostPort(GetParamStr(o, "HOST"), &host, &port, SYSLOG_PORT))\r
+       {\r
+               StrCpy(t.Hostname, sizeof(t.Hostname), host);\r
+               t.Port = port;\r
+               t.SaveType = GetParamInt(o, "[1|2|3]");\r
+\r
+               Free(host);\r
+\r
+               // RPC 呼び出し\r
+               ret = ScSetSysLog(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// syslog 設定の無効化\r
+UINT PsSyslogDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       SYSLOG_SETTING t;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSysLog(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       t.SaveType = SYSLOG_NONE;\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetSysLog(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// syslog 設定の取得\r
+UINT PsSyslogGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       SYSLOG_SETTING t;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSysLog(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               CT *ct = CtNewStandard();\r
+\r
+               CtInsert(ct, _UU("CMD_SyslogGet_COLUMN_1"), GetSyslogSettingName(t.SaveType));\r
+\r
+               if (t.SaveType != SYSLOG_NONE)\r
+               {\r
+                       StrToUni(tmp, sizeof(tmp), t.Hostname);\r
+                       CtInsert(ct, _UU("CMD_SyslogGet_COLUMN_2"), tmp);\r
+\r
+                       UniToStru(tmp, t.Port);\r
+                       CtInsert(ct, _UU("CMD_SyslogGet_COLUMN_3"), tmp);\r
+               }\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// syslog 設定名を取得\r
+wchar_t *GetSyslogSettingName(UINT n)\r
+{\r
+       char tmp[MAX_PATH];\r
+\r
+       Format(tmp, sizeof(tmp), "SM_SYSLOG_%u", n);\r
+\r
+       return _UU(tmp);\r
+}\r
+\r
+// インターネット接続の維持機能の設定\r
+UINT PsKeepSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_KEEP t;\r
+       char *host;\r
+       UINT port;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"HOST", CmdPrompt, _UU("CMD_KeepSet_PROMPT_HOST"), CmdEvalHostAndPort, NULL},\r
+               {"PROTOCOL", CmdPrompt, _UU("CMD_KeepSet_PROMPT_PROTOCOL"), CmdEvalTcpOrUdp, NULL},\r
+               {"INTERVAL", CmdPrompt, _UU("CMD_KeepSet_PROMPT_INTERVAL"), NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetKeep(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       if (ParseHostPort(GetParamStr(o, "HOST"), &host, &port, 0))\r
+       {\r
+               StrCpy(t.KeepConnectHost, sizeof(t.KeepConnectHost), host);\r
+               t.KeepConnectPort = port;\r
+               t.KeepConnectInterval = GetParamInt(o, "INTERVAL");\r
+               t.KeepConnectProtocol = (StrCmpi(GetParamStr(o, "PROTOCOL"), "tcp") == 0) ? 0 : 1;\r
+               Free(host);\r
+\r
+               // RPC 呼び出し\r
+               ret = ScSetKeep(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// インターネット接続の維持機能の取得\r
+UINT PsKeepGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_KEEP t;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetKeep(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               CT *ct = CtNewStandard();\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.KeepConnectHost);\r
+               CtInsert(ct, _UU("CMD_KeepGet_COLUMN_1"), tmp);\r
+\r
+               UniToStru(tmp, t.KeepConnectPort);\r
+               CtInsert(ct, _UU("CMD_KeepGet_COLUMN_2"), tmp);\r
+\r
+               UniToStru(tmp, t.KeepConnectInterval);\r
+               CtInsert(ct, _UU("CMD_KeepGet_COLUMN_3"), tmp);\r
+\r
+               CtInsert(ct, _UU("CMD_KeepGet_COLUMN_4"),\r
+                       t.KeepConnectProtocol == 0 ? L"TCP/IP" : L"UDP/IP");\r
+\r
+               CtInsert(ct, _UU("CMD_KeepGet_COLUMN_5"),\r
+                       t.UseKeepConnect ? _UU("SM_ACCESS_ENABLE") : _UU("SM_ACCESS_DISABLE"));\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// コネクション種類文字列の取得\r
+wchar_t *GetConnectionTypeStr(UINT type)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       Format(tmp, sizeof(tmp), "SM_CONNECTION_TYPE_%u", type);\r
+\r
+       return _UU(tmp);\r
+}\r
+\r
+// VPN Server に接続中の TCP コネクション一覧の取得\r
+UINT PsConnectionList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_CONNECTION t;\r
+       UINT i;\r
+       CT *ct;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumConnection(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       ct = CtNew();\r
+       CtInsertColumn(ct, _UU("SM_CONN_COLUMN_1"), false);\r
+       CtInsertColumn(ct, _UU("SM_CONN_COLUMN_2"), false);\r
+       CtInsertColumn(ct, _UU("SM_CONN_COLUMN_3"), false);\r
+       CtInsertColumn(ct, _UU("SM_CONN_COLUMN_4"), false);\r
+\r
+       for (i = 0;i < t.NumConnection;i++)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               wchar_t name[MAX_SIZE];\r
+               wchar_t datetime[MAX_SIZE];\r
+               RPC_ENUM_CONNECTION_ITEM *e = &t.Connections[i];\r
+\r
+               StrToUni(name, sizeof(name), e->Name);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_HOSTNAME_AND_PORT"), e->Hostname, e->Port);\r
+               GetDateTimeStrEx64(datetime, sizeof(datetime), SystemToLocal64(e->ConnectedTime), NULL);\r
+\r
+               CtInsert(ct, name, tmp, datetime,\r
+                       GetConnectionTypeStr(e->Type));\r
+       }\r
+\r
+       CtFree(ct, c);\r
+\r
+       FreeRpcEnumConnetion(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// VPN Server に接続中の TCP コネクションの情報の取得\r
+UINT PsConnectionGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CONNECTION_INFO t;\r
+       CT *ct;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_ConnectionGet_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetConnectionInfo(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               ct = CtNewStandard();\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.Name);\r
+               CtInsert(ct, _UU("SM_CONNINFO_NAME"), tmp);\r
+\r
+               CtInsert(ct, _UU("SM_CONNINFO_TYPE"), GetConnectionTypeStr(t.Type));\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.Hostname);\r
+               CtInsert(ct, _UU("SM_CONNINFO_HOSTNAME"), tmp);\r
+\r
+               UniToStru(tmp, t.Port);\r
+               CtInsert(ct, _UU("SM_CONNINFO_PORT"), tmp);\r
+\r
+               GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.ConnectedTime), NULL);\r
+               CtInsert(ct, _UU("SM_CONNINFO_TIME"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.ServerStr);\r
+               CtInsert(ct, _UU("SM_CONNINFO_SERVER_STR"), tmp);\r
+\r
+               UniFormat(tmp, sizeof(tmp), L"%u.%02u", t.ServerVer / 100, t.ServerVer % 100);\r
+               CtInsert(ct, _UU("SM_CONNINFO_SERVER_VER"), tmp);\r
+\r
+               UniToStru(tmp, t.ServerBuild);\r
+               CtInsert(ct, _UU("SM_CONNINFO_SERVER_BUILD"), tmp);\r
+\r
+               if (StrLen(t.ClientStr) != 0)\r
+               {\r
+                       StrToUni(tmp, sizeof(tmp), t.ClientStr);\r
+                       CtInsert(ct, _UU("SM_CONNINFO_CLIENT_STR"), tmp);\r
+\r
+                       UniFormat(tmp, sizeof(tmp), L"%u.%02u", t.ClientVer / 100, t.ClientVer % 100);\r
+                       CtInsert(ct, _UU("SM_CONNINFO_CLIENT_VER"), tmp);\r
+\r
+                       UniToStru(tmp, t.ClientBuild);\r
+                       CtInsert(ct, _UU("SM_CONNINFO_CLIENT_BUILD"), tmp);\r
+               }\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// VPN Server に接続中の TCP コネクションの切断\r
+UINT PsConnectionDisconnect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_DISCONNECT_CONNECTION t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_ConnectionDisconnect_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDisconnectConnection(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ローカル ブリッジに使用できる LAN カード一覧の取得\r
+UINT PsBridgeDeviceList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_ETH t;\r
+       UINT i;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumEthernet(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               RPC_ENUM_ETH_ITEM *item = &t.Items[i];\r
+               wchar_t tmp[MAX_SIZE * 2];\r
+\r
+               if(UniIsEmptyStr(item->NetworkConnectionName) == false)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), BRIDGE_NETWORK_CONNECTION_STR, item->NetworkConnectionName, item->DeviceName);\r
+               }\r
+               else\r
+               {\r
+                       StrToUni(tmp, sizeof(tmp), item->DeviceName);\r
+               }\r
+               c->Write(c, tmp);\r
+       }\r
+\r
+       FreeRpcEnumEth(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ローカル ブリッジ接続の一覧の取得\r
+UINT PsBridgeList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_LOCALBRIDGE t;\r
+       UINT i;\r
+       CT *ct;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumLocalBridge(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       ct = CtNew();\r
+\r
+       CtInsertColumn(ct, _UU("SM_BRIDGE_COLUMN_1"), false);\r
+       CtInsertColumn(ct, _UU("SM_BRIDGE_COLUMN_2"), false);\r
+       CtInsertColumn(ct, _UU("SM_BRIDGE_COLUMN_3"), false);\r
+       CtInsertColumn(ct, _UU("SM_BRIDGE_COLUMN_4"), false);\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               RPC_LOCALBRIDGE *e = &t.Items[i];\r
+               wchar_t name[MAX_SIZE];\r
+               wchar_t nic[MAX_SIZE];\r
+               wchar_t hub[MAX_SIZE];\r
+               wchar_t *status = _UU("SM_BRIDGE_OFFLINE");\r
+\r
+               UniToStru(name, i + 1);\r
+               StrToUni(nic, sizeof(nic), e->DeviceName);\r
+               StrToUni(hub, sizeof(hub), e->HubName);\r
+\r
+               if (e->Online)\r
+               {\r
+                       status = e->Active ? _UU("SM_BRIDGE_ONLINE") : _UU("SM_BRIDGE_ERROR");\r
+               }\r
+\r
+               CtInsert(ct, name, hub, nic, status);\r
+       }\r
+\r
+       CtFree(ct, c);\r
+\r
+       FreeRpcEnumLocalBridge(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ローカル ブリッジ接続の作成\r
+UINT PsBridgeCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_LOCALBRIDGE t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[hubname]", CmdPrompt, _UU("CMD_BridgeCreate_PROMPT_HUBNAME"), CmdEvalNotEmpty, NULL},\r
+               {"DEVICE", CmdPrompt, _UU("CMD_BridgeCreate_PROMPT_DEVICE"), CmdEvalNotEmpty, NULL},\r
+               {"TAP", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       t.Active = true;\r
+       StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "DEVICE"));\r
+       StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[hubname]"));\r
+       t.Online = true;\r
+       t.TapMode = GetParamYes(o, "TAP");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScAddLocalBridge(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               c->Write(c, _UU("SM_BRIDGE_INTEL"));\r
+               c->Write(c, L"");\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ローカル ブリッジ接続の削除\r
+UINT PsBridgeDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_LOCALBRIDGE t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[hubname]", CmdPrompt, _UU("CMD_BridgeDelete_PROMPT_HUBNAME"), CmdEvalNotEmpty, NULL},\r
+               {"DEVICE", CmdPrompt, _UU("CMD_BridgeDelete_PROMPT_DEVICE"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "DEVICE"));\r
+       StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[hubname]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDeleteLocalBridge(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// サーバーの機能・能力一覧の取得\r
+UINT PsCaps(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       CAPSLIST *t;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       t = ScGetCapsEx(ps->Rpc);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+               CT *ct;\r
+\r
+               ct = CtNewStandard();\r
+\r
+               for (i = 0;i < LIST_NUM(t->CapsList);i++)\r
+               {\r
+                       CAPS *c = LIST_DATA(t->CapsList, i);\r
+                       wchar_t title[MAX_SIZE];\r
+                       char name[256];\r
+\r
+                       Format(name, sizeof(name), "CT_%s", c->Name);\r
+\r
+                       UniStrCpy(title, sizeof(title), _UU(name));\r
+\r
+                       if (UniIsEmptyStr(title))\r
+                       {\r
+                               UniFormat(title, sizeof(title), L"%S", (StrLen(c->Name) >= 2) ? c->Name + 2 : c->Name);\r
+                       }\r
+\r
+                       if (StartWith(c->Name, "b_"))\r
+                       {\r
+                               bool icon_pass = c->Value == 0 ? false : true;\r
+                               if (StrCmpi(c->Name, "b_must_install_pcap") == 0)\r
+                               {\r
+                                       // WinPcap の項目のみ反転する\r
+                                       icon_pass = !icon_pass;\r
+                               }\r
+                               CtInsert(ct, title, c->Value == 0 ? _UU("CAPS_NO") : _UU("CAPS_YES"));\r
+                       }\r
+                       else\r
+                       {\r
+                               wchar_t str[64];\r
+                               UniToStru(str, c->Value);\r
+                               CtInsert(ct, title, str);\r
+                       }\r
+               }\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeCapsList(t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// VPN Server サービスの再起動\r
+UINT PsReboot(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_TEST t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"RESETCONFIG", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       t.IntValue = GetParamYes(o, "RESETCONFIG") ? 1 : 0;\r
+\r
+       // RPC 呼び出し\r
+       ret = ScRebootServer(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcTest(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// VPN Server の現在のコンフィグレーションの取得\r
+UINT PsConfigGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CONFIG t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[path]", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetConfig(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               char *filename = GetParamStr(o, "[path]");\r
+\r
+               if (IsEmptyStr(filename))\r
+               {\r
+                       // 画面に表示\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       UINT buf_size;\r
+                       wchar_t *buf;\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CMD_ConfigGet_FILENAME"), t.FileName,\r
+                               StrLen(t.FileData));\r
+                       c->Write(c, tmp);\r
+                       c->Write(c, L"");\r
+\r
+                       buf_size = CalcUtf8ToUni((BYTE *)t.FileData, StrLen(t.FileData));\r
+                       buf = ZeroMalloc(buf_size + 32);\r
+\r
+                       Utf8ToUni(buf, buf_size, (BYTE *)t.FileData, StrLen(t.FileData));\r
+\r
+                       c->Write(c, buf);\r
+                       c->Write(c, L"");\r
+\r
+                       Free(buf);\r
+               }\r
+               else\r
+               {\r
+                       // ファイルに保存\r
+                       IO *io = FileCreate(filename);\r
+\r
+                       if (io == NULL)\r
+                       {\r
+                               c->Write(c, _UU("CMD_ConfigGet_FILE_SAVE_FAILED"));\r
+\r
+                               ret = ERR_INTERNAL_ERROR;\r
+                       }\r
+                       else\r
+                       {\r
+                               FileWrite(io, t.FileData, StrLen(t.FileData));\r
+                               FileClose(io);\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeRpcConfig(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// VPN Server へのコンフィグレーションの書き込み\r
+UINT PsConfigSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CONFIG t;\r
+       char *filename;\r
+       BUF *buf;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[path]", CmdPrompt, _UU("CMD_ConfigSet_PROMPT_PATH"), CmdEvalIsFile, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       filename = GetParamStr(o, "[path]");\r
+\r
+       buf = ReadDump(filename);\r
+       if (buf == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_ConfigSet_FILE_LOAD_FAILED"));\r
+       }\r
+       else\r
+       {\r
+               Zero(&t, sizeof(t));\r
+\r
+               t.FileData = ZeroMalloc(buf->Size + 1);\r
+               Copy(t.FileData, buf->Buf, buf->Size);\r
+               FreeBuf(buf);\r
+\r
+               // RPC 呼び出し\r
+               ret = ScSetConfig(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcConfig(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチ一覧の取得\r
+UINT PsRouterList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_L3SW t;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumL3Switch(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNew();\r
+               UINT i;\r
+\r
+               CtInsertColumn(ct, _UU("SM_L3_SW_COLUMN1"), false);\r
+               CtInsertColumn(ct, _UU("SM_L3_SW_COLUMN2"), false);\r
+               CtInsertColumn(ct, _UU("SM_L3_SW_COLUMN3"), true);\r
+               CtInsertColumn(ct, _UU("SM_L3_SW_COLUMN4"), true);\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       RPC_ENUM_L3SW_ITEM *e = &t.Items[i];\r
+                       wchar_t tmp1[MAX_SIZE], *tmp2, tmp3[64], tmp4[64];\r
+\r
+                       StrToUni(tmp1, sizeof(tmp1), e->Name);\r
+                       if (e->Active == false)\r
+                       {\r
+                               tmp2 = _UU("SM_L3_SW_ST_F_F");\r
+                       }\r
+                       else if (e->Online == false)\r
+                       {\r
+                               tmp2 = _UU("SM_L3_SW_ST_T_F");\r
+                       }\r
+                       else\r
+                       {\r
+                               tmp2 = _UU("SM_L3_SW_ST_T_T");\r
+                       }\r
+                       UniToStru(tmp3, e->NumInterfaces);\r
+                       UniToStru(tmp4, e->NumTables);\r
+\r
+                       CtInsert(ct,\r
+                               tmp1, tmp2, tmp3, tmp4);\r
+               }\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeRpcEnumL3Sw(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 新しい仮想レイヤ 3 スイッチの定義\r
+UINT PsRouterAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_L3SW t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_RouterAdd_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScAddL3Switch(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチの削除\r
+UINT PsRouterDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_L3SW t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_RouterDelete_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDelL3Switch(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチの動作の開始\r
+UINT PsRouterStart(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_L3SW t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_RouterStart_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScStartL3Switch(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチの動作の停止\r
+UINT PsRouterStop(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_L3SW t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_RouterStop_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScStopL3Switch(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチに登録されているインターフェイス一覧の取得\r
+UINT PsRouterIfList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_L3IF t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_RouterIfList_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumL3If(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               wchar_t tmp3[MAX_SIZE];\r
+               CT *ct = CtNew();\r
+\r
+               CtInsertColumn(ct, _UU("SM_L3_SW_IF_COLUMN1"), false);\r
+               CtInsertColumn(ct, _UU("SM_L3_SW_IF_COLUMN2"), false);\r
+               CtInsertColumn(ct, _UU("SM_L3_SW_IF_COLUMN3"), false);\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       RPC_L3IF *e = &t.Items[i];\r
+\r
+                       IPToUniStr32(tmp1, sizeof(tmp1), e->IpAddress);\r
+                       IPToUniStr32(tmp2, sizeof(tmp2), e->SubnetMask);\r
+                       StrToUni(tmp3, sizeof(tmp3), e->HubName);\r
+\r
+                       CtInsert(ct, tmp1, tmp2, tmp3);\r
+               }\r
+\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeRpcEnumL3If(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// IP アドレスとマスクの評価\r
+bool CmdEvalIpAndMask4(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UINT ip, mask;\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       if (ParseIpAndMask4(tmp, &ip, &mask) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_PARSE_IP_MASK_ERROR_1"));\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+bool CmdEvalIpAndMask6(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       IP ip, mask;\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       if (ParseIpAndMask6(tmp, &ip, &mask) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_PARSE_IP_MASK_ERROR_1_6"));\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+bool CmdEvalIpAndMask46(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       TOKEN_LIST *t;\r
+       bool ret = false;\r
+\r
+       Zero(tmp, sizeof(tmp));\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       t = ParseToken(tmp, "/");\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (t->NumTokens >= 1)\r
+       {\r
+               Trim(t->Token[0]);\r
+\r
+               if (IsIpStr4(t->Token[0]))\r
+               {\r
+                       ret = CmdEvalIpAndMask4(c, str, param);\r
+               }\r
+               else\r
+               {\r
+                       ret = CmdEvalIpAndMask6(c, str, param);\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// ネットワークアドレスとサブネットマスクの評価\r
+bool CmdEvalNetworkAndSubnetMask4(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UINT ip, mask;\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       if (ParseIpAndSubnetMask4(tmp, &ip, &mask) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_PARSE_IP_SUBNET_ERROR_1"));\r
+               return false;\r
+       }\r
+\r
+       if (IsNetworkAddress32(ip, mask) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_PARSE_IP_SUBNET_ERROR_2"));\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+bool CmdEvalNetworkAndSubnetMask6(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       IP ip, mask;\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       if (ParseIpAndSubnetMask6(tmp, &ip, &mask) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_PARSE_IP_SUBNET_ERROR_1_6"));\r
+               return false;\r
+       }\r
+\r
+       if (IsNetworkPrefixAddress6(&ip, &mask) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_PARSE_IP_SUBNET_ERROR_3"));\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+bool CmdEvalNetworkAndSubnetMask46(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       TOKEN_LIST *t;\r
+       bool ret = false;\r
+\r
+       Zero(tmp, sizeof(tmp));\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       t = ParseToken(tmp, "/");\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (t->NumTokens >= 1)\r
+       {\r
+               Trim(t->Token[0]);\r
+\r
+               if (IsIpStr4(t->Token[0]))\r
+               {\r
+                       ret = CmdEvalNetworkAndSubnetMask4(c, str, param);\r
+               }\r
+               else\r
+               {\r
+                       ret = CmdEvalNetworkAndSubnetMask6(c, str, param);\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// IP アドレスとサブネットマスクの評価\r
+bool CmdEvalHostAndSubnetMask4(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       if (ParseIpAndSubnetMask4(tmp, NULL, NULL) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_PARSE_IP_SUBNET_ERROR_1"));\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチへの仮想インターフェイスの追加\r
+UINT PsRouterIfAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_L3IF t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_RouterIfAdd_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"HUB", CmdPrompt, _UU("CMD_RouterIfAdd_PROMPT_HUB"), CmdEvalNotEmpty, NULL},\r
+               {"IP", CmdPrompt, _UU("CMD_RouterIfAdd_PROMPT_IP"), CmdEvalHostAndSubnetMask4, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+       ParseIpAndSubnetMask4(GetParamStr(o, "IP"), &t.IpAddress, &t.SubnetMask);\r
+       StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "HUB"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScAddL3If(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチの仮想インターフェイスの削除\r
+UINT PsRouterIfDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_L3IF t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_RouterIfAdd_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"HUB", CmdPrompt, _UU("CMD_RouterIfAdd_PROMPT_HUB"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+       StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "HUB"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDelL3If(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチのルーティング テーブル一覧の取得\r
+UINT PsRouterTableList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_L3TABLE t;\r
+       CT *ct;\r
+       wchar_t tmp1[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       wchar_t tmp3[MAX_SIZE];\r
+       wchar_t tmp4[MAX_SIZE];\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_RouterTableList_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumL3Table(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+\r
+               ct = CtNew();\r
+\r
+               CtInsertColumn(ct, _UU("SM_L3_SW_TABLE_COLUMN1"), false);\r
+               CtInsertColumn(ct, _UU("SM_L3_SW_TABLE_COLUMN2"), false);\r
+               CtInsertColumn(ct, _UU("SM_L3_SW_TABLE_COLUMN3"), false);\r
+               CtInsertColumn(ct, _UU("SM_L3_SW_TABLE_COLUMN4"), true);\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       RPC_L3TABLE *e = &t.Items[i];\r
+\r
+                       IPToUniStr32(tmp1, sizeof(tmp1), e->NetworkAddress);\r
+                       IPToUniStr32(tmp2, sizeof(tmp2), e->SubnetMask);\r
+                       IPToUniStr32(tmp3, sizeof(tmp3), e->GatewayAddress);\r
+                       UniToStru(tmp4, e->Metric);\r
+\r
+                       CtInsert(ct, tmp1, tmp2, tmp3, tmp4);\r
+               }\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeRpcEnumL3Table(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチへのルーティング テーブル エントリの追加\r
+UINT PsRouterTableAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_L3TABLE t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"NETWORK", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_NETWORK"), CmdEvalNetworkAndSubnetMask4, NULL},\r
+               {"GATEWAY", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_GATEWAY"), CmdEvalIp, NULL},\r
+               {"METRIC", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_METRIC"), CmdEvalInt1, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+       ParseIpAndSubnetMask4(GetParamStr(o, "NETWORK"), &t.NetworkAddress, &t.SubnetMask);\r
+       t.Metric = GetParamInt(o, "METRIC");\r
+       t.GatewayAddress = StrToIP32(GetParamStr(o, "GATEWAY"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScAddL3Table(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチのルーティング テーブル エントリの削除\r
+UINT PsRouterTableDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_L3TABLE t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"NETWORK", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_NETWORK"), CmdEvalNetworkAndSubnetMask4, NULL},\r
+               {"GATEWAY", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_GATEWAY"), CmdEvalIp, NULL},\r
+               {"METRIC", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_METRIC"), CmdEvalInt1, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+       ParseIpAndSubnetMask4(GetParamStr(o, "NETWORK"), &t.NetworkAddress, &t.SubnetMask);\r
+       t.Metric = GetParamInt(o, "METRIC");\r
+       t.GatewayAddress = StrToIP32(GetParamStr(o, "GATEWAY"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDelL3Table(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ログ ファイル一覧の取得\r
+UINT PsLogFileList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_LOG_FILE t;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       c->Write(c, _UU("CMD_LogFileList_START"));\r
+       c->Write(c, L"");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumLogFile(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+               wchar_t tmp[MAX_SIZE];\r
+               CT *ct;\r
+\r
+               UniFormat(tmp, sizeof(tmp), _UU("CMD_LogFileList_NUM_LOGS"), t.NumItem);\r
+               c->Write(c, tmp);\r
+\r
+               ct = CtNew();\r
+\r
+               CtInsertColumn(ct, _UU("SM_LOG_FILE_COLUMN_1"), false);\r
+               CtInsertColumn(ct, _UU("SM_LOG_FILE_COLUMN_2"), true);\r
+               CtInsertColumn(ct, _UU("SM_LOG_FILE_COLUMN_3"), false);\r
+               CtInsertColumn(ct, _UU("SM_LOG_FILE_COLUMN_4"), false);\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       RPC_ENUM_LOG_FILE_ITEM *e = &t.Items[i];\r
+                       wchar_t tmp1[MAX_PATH], tmp2[128], tmp3[128], tmp4[MAX_HOST_NAME_LEN + 1];\r
+                       char tmp[MAX_SIZE];\r
+\r
+                       StrToUni(tmp1, sizeof(tmp1), e->FilePath);\r
+\r
+                       ToStrByte(tmp, sizeof(tmp), e->FileSize);\r
+                       StrToUni(tmp2, sizeof(tmp2), tmp);\r
+\r
+                       GetDateTimeStr64Uni(tmp3, sizeof(tmp3), SystemToLocal64(e->UpdatedTime));\r
+\r
+                       StrToUni(tmp4, sizeof(tmp4), e->ServerName);\r
+\r
+                       CtInsert(ct, tmp1, tmp2, tmp3, tmp4);\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcEnumLogFile(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ログ ファイルのダウンロード\r
+UINT PsLogFileGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       BUF *buf;\r
+       char *filename = NULL;\r
+       char *server_name;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_LogFileGet_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"SERVER", NULL, NULL, NULL, NULL},\r
+               {"SAVEPATH", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       filename = GetParamStr(o, "SAVE");\r
+\r
+       c->Write(c, _UU("CMD_LogFileGet_START"));\r
+\r
+       server_name = GetParamStr(o, "SERVER");\r
+\r
+       buf = DownloadFileFromServer(ps->Rpc, server_name,\r
+               GetParamStr(o, "[name]"), 0, NULL, NULL);\r
+\r
+       if (buf == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_LogFileGet_FAILED"));\r
+\r
+               ret = ERR_INTERNAL_ERROR;\r
+       }\r
+       else\r
+       {\r
+               if (IsEmptyStr(filename) == false)\r
+               {\r
+                       // ファイルに保存\r
+                       if (DumpBuf(buf, filename) == false)\r
+                       {\r
+                               ret = ERR_INTERNAL_ERROR;\r
+                               c->Write(c, _UU("CMD_LogFileGet_SAVE_FAILED"));\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // 画面に表示\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       UINT buf_size;\r
+                       wchar_t *uni_buf;\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CMD_LogFileGet_FILESIZE"),\r
+                               buf->Size);\r
+                       c->Write(c, tmp);\r
+                       c->Write(c, L"");\r
+\r
+                       buf_size = CalcUtf8ToUni((BYTE *)buf->Buf, buf->Size);\r
+                       uni_buf = ZeroMalloc(buf_size + 32);\r
+\r
+                       Utf8ToUni(uni_buf, buf_size, (BYTE *)buf->Buf, buf->Size);\r
+\r
+                       c->Write(c, uni_buf);\r
+                       c->Write(c, L"");\r
+\r
+                       Free(uni_buf);\r
+               }\r
+\r
+               FreeBuf(buf);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 新しい仮想 HUB の作成\r
+UINT PsHubCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_HUB t;\r
+       char *pass = "";\r
+       UINT hub_type = HUB_TYPE_STANDALONE;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_HubCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+       else\r
+       {\r
+               RPC_SERVER_INFO t;\r
+               Zero(&t, sizeof(t));\r
+               if (ScGetServerInfo(ps->Rpc, &t) == ERR_NO_ERROR)\r
+               {\r
+                       if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+                       {\r
+                               hub_type = HUB_TYPE_FARM_DYNAMIC;\r
+                       }\r
+                       FreeRpcServerInfo(&t);\r
+               }\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));\r
+       t.HubType = hub_type;\r
+\r
+       if (IsEmptyStr(GetParamStr(o, "PASSWORD")) == false)\r
+       {\r
+               pass = GetParamStr(o, "PASSWORD");\r
+       }\r
+\r
+       Hash(t.HashedPassword, pass, StrLen(pass), true);\r
+       HashPassword(t.SecurePassword, ADMINISTRATOR_USERNAME, pass);\r
+       t.Online = true;\r
+\r
+       // RPC 呼び出し\r
+       ret = ScCreateHub(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 新しい仮想 HUB の作成 (ダイナミックモード)\r
+UINT PsHubCreateDynamic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_HUB t;\r
+       char *pass = "";\r
+       UINT hub_type = HUB_TYPE_FARM_DYNAMIC;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_HubCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));\r
+       t.HubType = hub_type;\r
+\r
+       if (IsEmptyStr(GetParamStr(o, "PASSWORD")) == false)\r
+       {\r
+               pass = GetParamStr(o, "PASSWORD");\r
+       }\r
+\r
+       Hash(t.HashedPassword, pass, StrLen(pass), true);\r
+       HashPassword(t.SecurePassword, ADMINISTRATOR_USERNAME, pass);\r
+       t.Online = true;\r
+\r
+       // RPC 呼び出し\r
+       ret = ScCreateHub(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 新しい仮想 HUB の作成 (スタティックモード)\r
+UINT PsHubCreateStatic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_HUB t;\r
+       char *pass = "";\r
+       UINT hub_type = HUB_TYPE_FARM_STATIC;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_HubCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));\r
+       t.HubType = hub_type;\r
+\r
+       if (IsEmptyStr(GetParamStr(o, "PASSWORD")) == false)\r
+       {\r
+               pass = GetParamStr(o, "PASSWORD");\r
+       }\r
+\r
+       Hash(t.HashedPassword, pass, StrLen(pass), true);\r
+       HashPassword(t.SecurePassword, ADMINISTRATOR_USERNAME, pass);\r
+       t.Online = true;\r
+\r
+       // RPC 呼び出し\r
+       ret = ScCreateHub(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB の削除\r
+UINT PsHubDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_DELETE_HUB t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_HubDelete_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDeleteHub(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB をスタティックにする\r
+UINT PsHubSetStatic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_HUB t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_HubChange_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));\r
+\r
+       // まず現在の設定を取得する\r
+       ret = ScGetHub(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 設定を変更する\r
+       StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));\r
+       t.HubType = HUB_TYPE_FARM_STATIC;\r
+\r
+       // 書き込む\r
+       ret = ScSetHub(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB の種類をダイナミック仮想 HUB に変更\r
+UINT PsHubSetDynamic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_HUB t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_HubChange_PROMPT_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));\r
+\r
+       // まず現在の設定を取得する\r
+       ret = ScGetHub(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 設定を変更する\r
+       StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));\r
+       t.HubType = HUB_TYPE_FARM_DYNAMIC;\r
+\r
+       // 書き込む\r
+       ret = ScSetHub(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB の一覧の取得\r
+UINT PsHubList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_HUB t;\r
+       UINT i;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumHub(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNew();\r
+\r
+               CtInsertColumn(ct, _UU("SM_HUB_COLUMN_1"), false);\r
+               CtInsertColumn(ct, _UU("SM_HUB_COLUMN_2"), false);\r
+               CtInsertColumn(ct, _UU("SM_HUB_COLUMN_3"), false);\r
+               CtInsertColumn(ct, _UU("SM_HUB_COLUMN_4"), false);\r
+               CtInsertColumn(ct, _UU("SM_HUB_COLUMN_5"), false);\r
+               CtInsertColumn(ct, _UU("SM_HUB_COLUMN_6"), false);\r
+               CtInsertColumn(ct, _UU("SM_HUB_COLUMN_7"), false);\r
+               CtInsertColumn(ct, _UU("SM_HUB_COLUMN_8"), false);\r
+               CtInsertColumn(ct, _UU("SM_HUB_COLUMN_9"), false);\r
+               CtInsertColumn(ct, _UU("SM_HUB_COLUMN_10"), false);\r
+               CtInsertColumn(ct, _UU("SM_HUB_COLUMN_11"), false);\r
+\r
+               for (i = 0;i < t.NumHub;i++)\r
+               {\r
+                       RPC_ENUM_HUB_ITEM *e = &t.Hubs[i];\r
+                       wchar_t name[MAX_HUBNAME_LEN + 1];\r
+                       wchar_t s1[64], s2[64], s3[64], s4[64], s5[64];\r
+                       wchar_t s6[64], s7[128], s8[128];\r
+                       UniToStru(s1, e->NumUsers);\r
+                       UniToStru(s2, e->NumGroups);\r
+                       UniToStru(s3, e->NumSessions);\r
+                       UniToStru(s4, e->NumMacTables);\r
+                       UniToStru(s5, e->NumIpTables);\r
+\r
+                       UniToStru(s6, e->NumLogin);\r
+\r
+                       if (e->LastLoginTime != 0)\r
+                       {\r
+                               GetDateTimeStr64Uni(s7, sizeof(s7), SystemToLocal64(e->LastLoginTime));\r
+                       }\r
+                       else\r
+                       {\r
+                               UniStrCpy(s7, sizeof(s7), _UU("COMMON_UNKNOWN"));\r
+                       }\r
+\r
+                       if (e->LastCommTime != 0)\r
+                       {\r
+                               GetDateTimeStr64Uni(s8, sizeof(s8), SystemToLocal64(e->LastCommTime));\r
+                       }\r
+                       else\r
+                       {\r
+                               UniStrCpy(s8, sizeof(s8), _UU("COMMON_UNKNOWN"));\r
+                       }\r
+\r
+                       StrToUni(name, sizeof(name), e->HubName);\r
+\r
+                       CtInsert(ct,\r
+                               name,\r
+                               e->Online ? _UU("SM_HUB_ONLINE") : _UU("SM_HUB_OFFLINE"),\r
+                               GetHubTypeStr(e->HubType),\r
+                               s1, s2, s3, s4, s5, s6, s7, s8);\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcEnumHub(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 管理する仮想 HUB の選択\r
+UINT PsHub(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB_STATUS t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (IsEmptyStr(GetParamStr(o, "[name]")) == false)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               Zero(&t, sizeof(t));\r
+\r
+               // 指定した仮想 HUB にアクセスできるかどうか調べる\r
+               StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));\r
+\r
+               // RPC 呼び出し\r
+               ret = ScGetHubStatus(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               // 選択を変更する\r
+               if (ps->HubName != NULL)\r
+               {\r
+                       Free(ps->HubName);\r
+               }\r
+               ps->HubName = CopyStr(t.HubName);\r
+\r
+               UniFormat(tmp, sizeof(tmp), _UU("CMD_Hub_Selected"), t.HubName);\r
+               c->Write(c, tmp);\r
+       }\r
+       else\r
+       {\r
+               // 選択を解除する\r
+               if (ps->HubName != NULL)\r
+               {\r
+                       c->Write(c, _UU("CMD_Hub_Unselected"));\r
+                       Free(ps->HubName);\r
+               }\r
+               ps->HubName = NULL;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB をオンラインにする\r
+UINT PsOnline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_HUB_ONLINE t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.Online = true;\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetHubOnline(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB をオフラインにする\r
+UINT PsOffline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_HUB_ONLINE t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.Online = false;\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetHubOnline(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB の最大同時接続セッション数を設定する\r
+UINT PsSetMaxSession(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_HUB t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[max_session]", CmdPrompt, _UU("CMD_SetMaxSession_Prompt"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // 現在の仮想 HUB の設定を取得\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       ret = ScGetHub(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       t.HubOption.MaxSession = GetParamInt(o, "[max_session]");\r
+\r
+       // 仮想 HUB の設定を書き込み\r
+       ret = ScSetHub(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB の管理パスワードを設定する\r
+UINT PsSetHubPassword(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_HUB t;\r
+       char *pw;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[password]", CmdPromptChoosePassword, NULL, NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // 現在の仮想 HUB の設定を取得\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       ret = ScGetHub(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 設定の変更\r
+       pw = GetParamStr(o, "[password]");\r
+       HashPassword(t.SecurePassword, ADMINISTRATOR_USERNAME, pw);\r
+       Hash(t.HashedPassword, pw, StrLen(pw), true);\r
+\r
+       // 仮想 HUB の設定を書き込み\r
+       ret = ScSetHub(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB の匿名ユーザーへの列挙の許可設定\r
+UINT PsSetEnumAllow(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_HUB t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // 現在の仮想 HUB の設定を取得\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       ret = ScGetHub(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       t.HubOption.NoEnum = false;\r
+\r
+       // 仮想 HUB の設定を書き込み\r
+       ret = ScSetHub(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB の匿名ユーザーへの列挙の禁止設定\r
+UINT PsSetEnumDeny(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_HUB t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // 現在の仮想 HUB の設定を取得\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       ret = ScGetHub(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       t.HubOption.NoEnum = true;\r
+\r
+       // 仮想 HUB の設定を書き込み\r
+       ret = ScSetHub(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB のオプション設定の取得\r
+UINT PsOptionsGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_HUB t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetHub(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct;\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               UniFormat(tmp, sizeof(tmp), _UU("CMD_OptionsGet_TITLE"), ps->HubName);\r
+               c->Write(c, tmp);\r
+\r
+               // 設定の表示\r
+               ct = CtNewStandard();\r
+\r
+               CtInsert(ct, _UU("CMD_OptionsGet_ENUM"),\r
+                       t.HubOption.NoEnum ? _UU("CMD_MSG_DENY") : _UU("CMD_MSG_ALLOW"));\r
+\r
+               if (t.HubOption.MaxSession == 0)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("CMD_MSG_INFINITE"));\r
+               }\r
+               else\r
+               {\r
+                       UniToStru(tmp, t.HubOption.MaxSession);\r
+               }\r
+               CtInsert(ct, _UU("CMD_OptionsGet_MAXSESSIONS"), tmp);\r
+\r
+               CtInsert(ct, _UU("CMD_OptionsGet_STATUS"), t.Online ? _UU("SM_HUB_ONLINE") : _UU("SM_HUB_OFFLINE"));\r
+\r
+               CtInsert(ct, _UU("CMD_OptionsGet_TYPE"), GetHubTypeStr(t.HubType));\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザー認証に使用する Radius サーバーの設定\r
+UINT PsRadiusServerSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_RADIUS t;\r
+       char *host;\r
+       UINT port;\r
+       // 指定できるパラメータ リスト\r
+       CMD_EVAL_MIN_MAX minmax =\r
+       {\r
+               "CMD_RadiusServerSet_EVAL_NUMINTERVAL", RADIUS_RETRY_INTERVAL, RADIUS_RETRY_TIMEOUT,\r
+       };\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[server_name:port]", CmdPrompt, _UU("CMD_RadiusServerSet_Prompt_Host"), CmdEvalNotEmpty, NULL},\r
+               {"SECRET", CmdPromptChoosePassword, _UU("CMD_RadiusServerSet_Prompt_Secret"), NULL, NULL},\r
+               {"RETRY_INTERVAL", CmdPrompt, _UU("CMD_RadiusServerSet_Prompt_RetryInterval"), CmdEvalMinMax, &minmax},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (ParseHostPort(GetParamStr(o, "[server_name:port]"), &host, &port, 1812))\r
+       {\r
+               Zero(&t, sizeof(t));\r
+\r
+               StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+               t.RadiusPort = port;\r
+               StrCpy(t.RadiusServerName, sizeof(t.RadiusServerName), host);\r
+               StrCpy(t.RadiusSecret, sizeof(t.RadiusSecret), GetParamStr(o, "SECRET"));\r
+               t.RadiusRetryInterval = GetParamInt(o, "RETRY_INTERVAL");\r
+\r
+               Free(host);\r
+\r
+               // RPC 呼び出し\r
+               ret = ScSetHubRadius(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザー認証に使用する Radius サーバー設定の削除\r
+UINT PsRadiusServerDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_RADIUS t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.RadiusPort = 1812;\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetHubRadius(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザー認証に使用する Radius サーバー設定の取得\r
+UINT PsRadiusServerGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_RADIUS t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetHubRadius(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct;\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               ct = CtNewStandard();\r
+\r
+               if (IsEmptyStr(t.RadiusServerName))\r
+               {\r
+                       CtInsert(ct, _UU("CMD_RadiusServerGet_STATUS"), _UU("CMD_MSG_DISABLE"));\r
+               }\r
+               else\r
+               {\r
+                       CtInsert(ct, _UU("CMD_RadiusServerGet_STATUS"), _UU("CMD_MSG_ENABLE"));\r
+\r
+                       StrToUni(tmp, sizeof(tmp), t.RadiusServerName);\r
+                       CtInsert(ct, _UU("CMD_RadiusServerGet_HOST"), tmp);\r
+\r
+                       UniToStri(tmp, t.RadiusPort);\r
+                       CtInsert(ct, _UU("CMD_RadiusServerGet_PORT"), tmp);\r
+\r
+                       StrToUni(tmp, sizeof(tmp), t.RadiusSecret);\r
+                       CtInsert(ct, _UU("CMD_RadiusServerGet_SECRET"), tmp);\r
+\r
+                       UniToStri(tmp, t.RadiusRetryInterval);\r
+                       CtInsert(ct, _UU("CMD_RadiusServerGet_RetryInterval"), tmp);\r
+               }\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB の現在の状況の取得\r
+UINT PsStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB_STATUS t;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetHubStatus(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNewStandard();\r
+               wchar_t *s;\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               // HUB 名\r
+               s = CopyStrToUni(t.HubName);\r
+               CtInsert(ct, _UU("SM_HUB_STATUS_HUBNAME"), s);\r
+               Free(s);\r
+\r
+               // オンライン\r
+               CtInsert(ct, _UU("SM_HUB_STATUS_ONLINE"),\r
+                       t.Online ? _UU("SM_HUB_ONLINE") : _UU("SM_HUB_OFFLINE"));\r
+\r
+               // HUB の種類\r
+               CtInsert(ct, _UU("SM_HUB_TYPE"),\r
+                       GetHubTypeStr(t.HubType));\r
+\r
+               if (t.HubType == HUB_TYPE_STANDALONE)\r
+               {\r
+                       // SecureNAT の有効/無効\r
+                       CtInsert(ct, _UU("SM_HUB_SECURE_NAT"),\r
+                               t.SecureNATEnabled ? _UU("SM_HUB_SECURE_NAT_YES") : _UU("SM_HUB_SECURE_NAT_NO"));\r
+               }\r
+\r
+               // その他の値\r
+               UniToStru(tmp, t.NumSessions);\r
+               CtInsert(ct, _UU("SM_HUB_NUM_SESSIONS"), tmp);\r
+\r
+               if (t.NumSessionsClient != 0 || t.NumSessionsBridge != 0)\r
+               {\r
+                       UniToStru(tmp, t.NumSessionsClient);\r
+                       CtInsert(ct, _UU("SM_HUB_NUM_SESSIONS_CLIENT"), tmp);\r
+                       UniToStru(tmp, t.NumSessionsBridge);\r
+                       CtInsert(ct, _UU("SM_HUB_NUM_SESSIONS_BRIDGE"), tmp);\r
+               }\r
+\r
+               UniToStru(tmp, t.NumAccessLists);\r
+               CtInsert(ct, _UU("SM_HUB_NUM_ACCESSES"), tmp);\r
+\r
+               UniToStru(tmp, t.NumUsers);\r
+               CtInsert(ct, _UU("SM_HUB_NUM_USERS"), tmp);\r
+               UniToStru(tmp, t.NumGroups);\r
+               CtInsert(ct, _UU("SM_HUB_NUM_GROUPS"), tmp);\r
+\r
+               UniToStru(tmp, t.NumMacTables);\r
+               CtInsert(ct, _UU("SM_HUB_NUM_MAC_TABLES"), tmp);\r
+               UniToStru(tmp, t.NumIpTables);\r
+               CtInsert(ct, _UU("SM_HUB_NUM_IP_TABLES"), tmp);\r
+\r
+               // 利用状況\r
+               UniToStru(tmp, t.NumLogin);\r
+               CtInsert(ct, _UU("SM_HUB_NUM_LOGIN"), tmp);\r
+\r
+               if (t.LastLoginTime != 0)\r
+               {\r
+                       GetDateTimeStr64Uni(tmp, sizeof(tmp), SystemToLocal64(t.LastLoginTime));\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("COMMON_UNKNOWN"));\r
+               }\r
+               CtInsert(ct, _UU("SM_HUB_LAST_LOGIN_TIME"), tmp);\r
+\r
+               if (t.LastCommTime != 0)\r
+               {\r
+                       GetDateTimeStr64Uni(tmp, sizeof(tmp), SystemToLocal64(t.LastCommTime));\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("COMMON_UNKNOWN"));\r
+               }\r
+               CtInsert(ct, _UU("SM_HUB_LAST_COMM_TIME"), tmp);\r
+\r
+               if (t.CreatedTime != 0)\r
+               {\r
+                       GetDateTimeStr64Uni(tmp, sizeof(tmp), SystemToLocal64(t.CreatedTime));\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("COMMON_UNKNOWN"));\r
+               }\r
+               CtInsert(ct, _UU("SM_HUB_CREATED_TIME"), tmp);\r
+\r
+               // トラフィック情報\r
+               CmdInsertTrafficInfo(ct, &t.Traffic);\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ログ切り替え文字列の取得\r
+wchar_t *GetLogSwitchStr(UINT i)\r
+{\r
+       char tmp[64];\r
+\r
+       Format(tmp, sizeof(tmp), "SM_LOG_SWITCH_%u", i);\r
+\r
+       return _UU(tmp);\r
+}\r
+\r
+// パケットログ名文字列の取得\r
+wchar_t *GetPacketLogNameStr(UINT i)\r
+{\r
+       char tmp[64];\r
+\r
+       Format(tmp, sizeof(tmp), "CMD_Log_%u", i);\r
+\r
+       return _UU(tmp);\r
+}\r
+\r
+// 仮想 HUB のログ保存設定の取得\r
+UINT PsLogGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB_LOG t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetHubLog(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNewStandard();\r
+\r
+               CtInsert(ct, _UU("CMD_Log_SecurityLog"),\r
+                       t.LogSetting.SaveSecurityLog ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+               if (t.LogSetting.SaveSecurityLog)\r
+               {\r
+                       CtInsert(ct, _UU("CMD_Log_SwitchType"), GetLogSwitchStr(t.LogSetting.SecurityLogSwitchType));\r
+               }\r
+\r
+               CtInsert(ct, L"", L"");\r
+\r
+               CtInsert(ct, _UU("CMD_Log_PacketLog"),\r
+                       t.LogSetting.SavePacketLog ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+               if (t.LogSetting.SavePacketLog)\r
+               {\r
+                       UINT i;\r
+\r
+                       CtInsert(ct, _UU("CMD_Log_SwitchType"), GetLogSwitchStr(t.LogSetting.PacketLogSwitchType));\r
+\r
+                       for (i = 0;i <= 7;i++)\r
+                       {\r
+                               wchar_t *tmp = NULL;\r
+\r
+                               switch (t.LogSetting.PacketLogConfig[i])\r
+                               {\r
+                               case PACKET_LOG_NONE:\r
+                                       tmp = _UU("D_SM_LOG@B_PACKET_0_0");\r
+                                       break;\r
+\r
+                               case PACKET_LOG_HEADER:\r
+                                       tmp = _UU("D_SM_LOG@B_PACKET_0_1");\r
+                                       break;\r
+\r
+                               case PACKET_LOG_ALL:\r
+                                       tmp = _UU("D_SM_LOG@B_PACKET_0_2");\r
+                                       break;\r
+                               }\r
+\r
+                               CtInsert(ct, GetPacketLogNameStr(i),\r
+                                       tmp);\r
+                       }\r
+               }\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// LogEnable コマンド\r
+UINT PsLogEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB_LOG t;\r
+       bool packet_log = false;\r
+       char *tmp;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[security|packet]", CmdPrompt, _UU("CMD_LogEnable_Prompt"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       tmp = GetParamStr(o, "[security|packet]");\r
+\r
+       if (StartWith(tmp, "p"))\r
+       {\r
+               packet_log = true;\r
+       }\r
+       else if (StartWith(tmp, "s") == false)\r
+       {\r
+               c->Write(c, _UU("CMD_LogEnable_Prompt_Error"));\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetHubLog(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       if (packet_log == false)\r
+       {\r
+               t.LogSetting.SaveSecurityLog = true;\r
+       }\r
+       else\r
+       {\r
+               t.LogSetting.SavePacketLog = true;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetHubLog(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// セキュリティ ログまたはパケット ログの無効化\r
+UINT PsLogDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB_LOG t;\r
+       bool packet_log = false;\r
+       char *tmp;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[security|packet]", CmdPrompt, _UU("CMD_LogEnable_Prompt"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       tmp = GetParamStr(o, "[security|packet]");\r
+\r
+       if (StartWith(tmp, "p"))\r
+       {\r
+               packet_log = true;\r
+       }\r
+       else if (StartWith(tmp, "s") == false)\r
+       {\r
+               c->Write(c, _UU("CMD_LogEnable_Prompt_Error"));\r
+               FreeParamValueList(o);\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetHubLog(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       if (packet_log == false)\r
+       {\r
+               t.LogSetting.SaveSecurityLog = false;\r
+       }\r
+       else\r
+       {\r
+               t.LogSetting.SavePacketLog = false;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetHubLog(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 文字列をログ切り替え種類に変換\r
+UINT StrToLogSwitchType(char *str)\r
+{\r
+       UINT ret = INFINITE;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       if (IsEmptyStr(str) || StartWith("none", str))\r
+       {\r
+               ret = LOG_SWITCH_NO;\r
+       }\r
+       else if (StartWith("second", str))\r
+       {\r
+               ret = LOG_SWITCH_SECOND;\r
+       }\r
+       else if (StartWith("minute", str))\r
+       {\r
+               ret = LOG_SWITCH_MINUTE;\r
+       }\r
+       else if (StartWith("hour", str))\r
+       {\r
+               ret = LOG_SWITCH_HOUR;\r
+       }\r
+       else if (StartWith("day", str))\r
+       {\r
+               ret = LOG_SWITCH_DAY;\r
+       }\r
+       else if (StartWith("month", str))\r
+       {\r
+               ret = LOG_SWITCH_MONTH;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ログ ファイルの切り替え周期の設定\r
+UINT PsLogSwitchSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB_LOG t;\r
+       bool packet_log = false;\r
+       char *tmp;\r
+       UINT new_switch_type = 0;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[security|packet]", CmdPrompt, _UU("CMD_LogEnable_Prompt"), CmdEvalNotEmpty, NULL},\r
+               {"SWITCH", CmdPrompt, _UU("CMD_LogSwitchSet_Prompt"), NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       tmp = GetParamStr(o, "[security|packet]");\r
+\r
+       if (StartWith(tmp, "p"))\r
+       {\r
+               packet_log = true;\r
+       }\r
+       else if (StartWith(tmp, "s") == false)\r
+       {\r
+               c->Write(c, _UU("CMD_LogEnable_Prompt_Error"));\r
+               FreeParamValueList(o);\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+       \r
+       new_switch_type = StrToLogSwitchType(GetParamStr(o, "SWITCH"));\r
+\r
+       if (new_switch_type == INFINITE)\r
+       {\r
+               c->Write(c, _UU("CMD_LogEnable_Prompt_Error"));\r
+               FreeParamValueList(o);\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetHubLog(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       if (packet_log == false)\r
+       {\r
+               t.LogSetting.SecurityLogSwitchType = new_switch_type;\r
+       }\r
+       else\r
+       {\r
+               t.LogSetting.PacketLogSwitchType = new_switch_type;\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetHubLog(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// パケットログのパケットの保存内容の文字列を整数に変換\r
+UINT StrToPacketLogSaveInfoType(char *str)\r
+{\r
+       UINT ret = INFINITE;\r
+       if (str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       if (StartWith("none", str) || IsEmptyStr(str))\r
+       {\r
+               ret = PACKET_LOG_NONE;\r
+       }\r
+       else if (StartWith("header", str))\r
+       {\r
+               ret = PACKET_LOG_HEADER;\r
+       }\r
+       else if (StartWith("full", str) || StartWith("all", str))\r
+       {\r
+               ret = PACKET_LOG_ALL;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// パケットログのパケットの種類の文字列を整数に変換\r
+UINT StrToPacketLogType(char *str)\r
+{\r
+       UINT ret = INFINITE;\r
+       if (str == NULL || IsEmptyStr(str))\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       if (StartWith("tcpconn", str))\r
+       {\r
+               ret = PACKET_LOG_TCP_CONN;\r
+       }\r
+       else if (StartWith("tcpdata", str))\r
+       {\r
+               ret = PACKET_LOG_TCP;\r
+       }\r
+       else if (StartWith("dhcp", str))\r
+       {\r
+               ret = PACKET_LOG_DHCP;\r
+       }\r
+       else if (StartWith("udp", str))\r
+       {\r
+               ret = PACKET_LOG_UDP;\r
+       }\r
+       else if (StartWith("icmp", str))\r
+       {\r
+               ret = PACKET_LOG_ICMP;\r
+       }\r
+       else if (StartWith("ip", str))\r
+       {\r
+               ret = PACKET_LOG_IP;\r
+       }\r
+       else if (StartWith("arp", str))\r
+       {\r
+               ret = PACKET_LOG_ARP;\r
+       }\r
+       else if (StartWith("ethernet", str))\r
+       {\r
+               ret = PACKET_LOG_ETHERNET;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// パケット ログに保存するパケットの種類と保存内容の設定\r
+UINT PsLogPacketSaveType(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB_LOG t;\r
+       bool packet_log = false;\r
+       UINT packet_type = INFINITE;\r
+       UINT packet_save_info_type = INFINITE;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"TYPE", CmdPrompt, _UU("CMD_LogPacketSaveType_Prompt_TYPE"), NULL, NULL},\r
+               {"SAVE", CmdPrompt, _UU("CMD_LogPacketSaveType_Prompt_SAVE"), NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+       \r
+       packet_type = StrToPacketLogType(GetParamStr(o, "TYPE"));\r
+       packet_save_info_type = StrToPacketLogSaveInfoType(GetParamStr(o, "SAVE"));\r
+\r
+       if (packet_type == INFINITE || packet_save_info_type == INFINITE)\r
+       {\r
+               c->Write(c, _UU("CMD_LogEnable_Prompt_Error"));\r
+               FreeParamValueList(o);\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetHubLog(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       t.LogSetting.PacketLogConfig[packet_type] = packet_save_info_type;\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetHubLog(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 信頼する証明機関の証明書一覧の取得\r
+UINT PsCAList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB_ENUM_CA t;\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumCa(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+               CT *ct = CtNewStandard();\r
+\r
+               for (i = 0;i < t.NumCa;i++)\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       wchar_t tmp2[64];\r
+                       RPC_HUB_ENUM_CA_ITEM *e = &t.Ca[i];\r
+\r
+                       GetDateStrEx64(tmp, sizeof(tmp), SystemToLocal64(e->Expires), NULL);\r
+\r
+                       UniToStru(tmp2, e->Key);\r
+\r
+                       CtInsert(ct, _UU("CMD_CAList_COLUMN_ID"), tmp2);\r
+                       CtInsert(ct, _UU("CM_CERT_COLUMN_1"), e->SubjectName);\r
+                       CtInsert(ct, _UU("CM_CERT_COLUMN_2"), e->IssuerName);\r
+                       CtInsert(ct, _UU("CM_CERT_COLUMN_3"), tmp);\r
+\r
+                       if (i != (t.NumCa - 1))\r
+                       {\r
+                               CtInsert(ct, L"---", L"---");\r
+                       }\r
+               }\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeRpcHubEnumCa(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 信頼する証明機関の証明書の追加\r
+UINT PsCAAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB_ADD_CA t;\r
+       X *x;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[path]", CmdPrompt, _UU("CMD_CAAdd_PROMPT_PATH"), CmdEvalIsFile, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       x = FileToX(GetParamStr(o, "[path]"));\r
+\r
+       if (x == NULL)\r
+       {\r
+               FreeParamValueList(o);\r
+               c->Write(c, _UU("CMD_MSG_LOAD_CERT_FAILED"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.Cert = x;\r
+\r
+       // RPC 呼び出し\r
+       ret = ScAddCa(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcHubAddCa(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 信頼する証明機関の証明書の削除\r
+UINT PsCADelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB_DELETE_CA t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_CADelete_PROMPT_ID"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.Key = GetParamInt(o, "[id]");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDeleteCa(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 信頼する証明機関の証明書の取得\r
+UINT PsCAGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB_GET_CA t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_CAGet_PROMPT_ID"), CmdEvalNotEmpty, NULL},\r
+               {"SAVECERT", CmdPrompt, _UU("CMD_CAGet_PROMPT_SAVECERT"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.Key = GetParamInt(o, "[id]");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetCa(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               if (XToFile(t.Cert, GetParamStr(o, "SAVECERT"), true))\r
+               {\r
+                       // 成功\r
+               }\r
+               else\r
+               {\r
+                       ret = ERR_INTERNAL_ERROR;\r
+                       c->Write(c, _UU("CMD_MSG_SAVE_CERT_FAILED"));\r
+               }\r
+       }\r
+\r
+       FreeRpcHubGetCa(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// カスケード接続一覧の取得\r
+UINT PsCascadeList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_LINK t;\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNew();\r
+               UINT i;\r
+\r
+               CtInsertColumn(ct, _UU("SM_LINK_COLUMN_1"), false);\r
+               CtInsertColumn(ct, _UU("SM_LINK_COLUMN_2"), false);\r
+               CtInsertColumn(ct, _UU("SM_LINK_COLUMN_3"), false);\r
+               CtInsertColumn(ct, _UU("SM_LINK_COLUMN_4"), false);\r
+               CtInsertColumn(ct, _UU("SM_LINK_COLUMN_5"), false);\r
+\r
+               for (i = 0;i < t.NumLink;i++)\r
+               {\r
+                       RPC_ENUM_LINK_ITEM *e = &t.Links[i];\r
+                       wchar_t tmp1[MAX_SIZE];\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       wchar_t tmp3[MAX_SIZE];\r
+                       wchar_t tmp4[MAX_SIZE];\r
+\r
+                       GetDateTimeStrEx64(tmp1, sizeof(tmp1), SystemToLocal64(e->ConnectedTime), NULL);\r
+                       StrToUni(tmp2, sizeof(tmp2), e->Hostname);\r
+                       StrToUni(tmp3, sizeof(tmp3), e->HubName);\r
+\r
+                       if (e->Online == false)\r
+                       {\r
+                               UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_LINK_STATUS_OFFLINE"));\r
+                       }\r
+                       else\r
+                       {\r
+                               if (e->Connected)\r
+                               {\r
+                                       UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_LINK_STATUS_ONLINE"));\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (e->LastError != 0)\r
+                                       {\r
+                                               UniFormat(tmp4, sizeof(tmp4), _UU("SM_LINK_STATUS_ERROR"), e->LastError, _E(e->LastError));\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_LINK_CONNECTING"));\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       CtInsert(ct, e->AccountName, tmp4, tmp1, tmp2, tmp3);\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcEnumLink(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 新しいカスケード接続の作成\r
+UINT PsCascadeCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       char *host = NULL;\r
+       UINT port = 443;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SERVER", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Server"), CmdEvalHostAndPort, NULL},\r
+               {"HUB", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Hub"), CmdEvalSafe, NULL},\r
+               {"USERNAME", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Username"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 443);\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       t.Online = false;\r
+\r
+       Copy(&t.Policy, GetDefaultPolicy(), sizeof(POLICY));\r
+\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+       t.ClientOption->Port = port;\r
+       StrCpy(t.ClientOption->Hostname, sizeof(t.ClientOption->Hostname), host);\r
+       StrCpy(t.ClientOption->HubName, sizeof(t.ClientOption->HubName), GetParamStr(o, "HUB"));\r
+       t.ClientOption->NumRetry = INFINITE;\r
+       t.ClientOption->RetryInterval = 15;\r
+       t.ClientOption->MaxConnection = 8;\r
+       t.ClientOption->UseEncrypt = true;\r
+       t.ClientOption->AdditionalConnectionInterval = 1;\r
+       t.ClientOption->RequireBridgeRoutingMode = true;\r
+\r
+       t.ClientAuth = ZeroMalloc(sizeof(CLIENT_AUTH));\r
+       t.ClientAuth->AuthType = CLIENT_AUTHTYPE_ANONYMOUS;\r
+       StrCpy(t.ClientAuth->Username, sizeof(t.ClientAuth->Username), GetParamStr(o, "USERNAME"));\r
+\r
+       Free(host);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScCreateLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcCreateLink(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続の接続先とユーザー名の設定\r
+UINT PsCascadeSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       char *host = NULL;\r
+       UINT port = 443;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SERVER", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Server"), CmdEvalHostAndPort, NULL},\r
+               {"HUB", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Hub"), CmdEvalSafe, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 443);\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               Free(host);\r
+               return ret;\r
+       }\r
+\r
+       t.ClientOption->Port = port;\r
+       StrCpy(t.ClientOption->Hostname, sizeof(t.ClientOption->Hostname), host);\r
+       StrCpy(t.ClientOption->HubName, sizeof(t.ClientOption->HubName), GetParamStr(o, "HUB"));\r
+\r
+       Free(host);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcCreateLink(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// プロキシの種類文字列の取得\r
+wchar_t *GetProxyTypeStr(UINT i)\r
+{\r
+       switch (i)\r
+       {\r
+       case PROXY_DIRECT:\r
+\r
+               return _UU("PROTO_DIRECT_TCP");\r
+\r
+       case PROXY_HTTP:\r
+               return _UU("PROTO_HTTP_PROXY");\r
+\r
+       case PROXY_SOCKS:\r
+               return _UU("PROTO_SOCKS_PROXY");\r
+\r
+       default:\r
+               return _UU("PROTO_UNKNOWN");\r
+       }\r
+}\r
+\r
+// クライアントのユーザー認証の種類文字列の取得\r
+wchar_t *GetClientAuthTypeStr(UINT i)\r
+{\r
+       char tmp[MAX_SIZE];\r
+\r
+       Format(tmp, sizeof(tmp), "PW_TYPE_%u", i);\r
+\r
+       return _UU(tmp);\r
+}\r
+\r
+// カスケード接続の設定の取得\r
+UINT PsCascadeGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName),\r
+               GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // 接続設定の内容を表示\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               CT *ct = CtNewStandard();\r
+\r
+               // 接続設定名\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NAME"), t.ClientOption->AccountName);\r
+\r
+               // 接続先 VPN Server のホスト名\r
+               StrToUni(tmp, sizeof(tmp), t.ClientOption->Hostname);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_HOSTNAME"), tmp);\r
+\r
+               // 接続先 VPN Server のポート番号\r
+               UniToStru(tmp, t.ClientOption->Port);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PORT"), tmp);\r
+\r
+               // 接続先 VPN Server の仮想 HUB 名\r
+               StrToUni(tmp, sizeof(tmp), t.ClientOption->HubName);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_HUBNAME"), tmp);\r
+\r
+               // 経由するプロキシ サーバーの種類\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_TYPE"), GetProxyTypeStr(t.ClientOption->ProxyType));\r
+\r
+               if (t.ClientOption->ProxyType != PROXY_DIRECT)\r
+               {\r
+                       // プロキシ サーバーのホスト名\r
+                       StrToUni(tmp, sizeof(tmp), t.ClientOption->ProxyName);\r
+                       CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_HOSTNAME"), tmp);\r
+\r
+                       // プロキシ サーバーのポート番号\r
+                       UniToStru(tmp, t.ClientOption->ProxyPort);\r
+                       CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_PORT"), tmp);\r
+\r
+                       // プロキシ サーバーのユーザー名\r
+                       StrToUni(tmp, sizeof(tmp), t.ClientOption->ProxyUsername);\r
+                       CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_USERNAME"), tmp);\r
+               }\r
+\r
+               // サーバー証明書の検証\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_SERVER_CERT_USE"),\r
+                       t.CheckServerCert ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // 登録されている固有証明書\r
+               if (t.ServerCert != NULL)\r
+               {\r
+                       GetAllNameFromX(tmp, sizeof(tmp), t.ServerCert);\r
+                       CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_SERVER_CERT_NAME"), tmp);\r
+               }\r
+\r
+               // 接続に使用するデバイス名\r
+               StrToUni(tmp, sizeof(tmp), t.ClientOption->DeviceName);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_DEVICE_NAME"), tmp);\r
+\r
+               // 認証の種類\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_AUTH_TYPE"), GetClientAuthTypeStr(t.ClientAuth->AuthType));\r
+\r
+               // ユーザー名\r
+               StrToUni(tmp, sizeof(tmp), t.ClientAuth->Username);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_AUTH_USERNAME"), tmp);\r
+\r
+               if (t.ClientAuth->AuthType == CLIENT_AUTHTYPE_CERT)\r
+               {\r
+                       if (t.ClientAuth->ClientX != NULL)\r
+                       {\r
+                               // クライアント証明書名\r
+                               GetAllNameFromX(tmp, sizeof(tmp), t.ClientAuth->ClientX);\r
+                               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_AUTH_CERT_NAME"), tmp);\r
+                       }\r
+               }\r
+\r
+               // VPN 通信に使用する TCP コネクション数\r
+               UniToStru(tmp, t.ClientOption->MaxConnection);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NUMTCP"), tmp);\r
+\r
+               // 各 TCP コネクションの確立間隔\r
+               UniToStru(tmp, t.ClientOption->AdditionalConnectionInterval);\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_TCP_INTERVAL"), tmp);\r
+\r
+               // 各 TCP コネクションの寿命\r
+               if (t.ClientOption->ConnectionDisconnectSpan != 0)\r
+               {\r
+                       UniToStru(tmp, t.ClientOption->ConnectionDisconnectSpan);\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("CMD_MSG_INFINITE"));\r
+               }\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_TCP_TTL"), tmp);\r
+\r
+               // 半二重モードの使用\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_TCP_HALF"),\r
+                       t.ClientOption->HalfConnection ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // SSL による暗号化\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_ENCRYPT"),\r
+                       t.ClientOption->UseEncrypt ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // データ圧縮\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_COMPRESS"),\r
+                       t.ClientOption->UseCompress ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // ブリッジ / ルータモードで接続\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_BRIDGE_ROUTER"),\r
+                       t.ClientOption->RequireBridgeRoutingMode ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // モニタリングモードで接続\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_MONITOR"),\r
+                       t.ClientOption->RequireMonitorMode ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // ルーティング テーブルを書き換えない\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NO_TRACKING"),\r
+                       t.ClientOption->NoRoutingTracking ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               // QoS制御を無効化する\r
+               CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_QOS_DISABLE"),\r
+                       t.ClientOption->DisableQoS ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));\r
+\r
+               CtFree(ct, c);\r
+\r
+               // セキュリティ ポリシー\r
+               c->Write(c, L"");\r
+               c->Write(c, _UU("CMD_CascadeGet_Policy"));\r
+               PrintPolicy(c, &t.Policy, true);\r
+       }\r
+\r
+       FreeRpcCreateLink(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続の削除\r
+UINT PsCascadeDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDeleteLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続の接続に使用するユーザー名の設定\r
+UINT PsCascadeUsernameSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"USERNAME", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Username"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // カスケード接続の設定の変更\r
+               StrCpy(t.ClientAuth->Username, sizeof(t.ClientAuth->Username),\r
+                       GetParamStr(o, "USERNAME"));\r
+\r
+               if (t.ClientAuth->AuthType == CLIENT_AUTHTYPE_PASSWORD)\r
+               {\r
+                       c->Write(c, _UU("CMD_CascadeUsername_Notice"));\r
+               }\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+//カスケード接続のユーザー認証の種類を匿名認証に設定\r
+UINT PsCascadeAnonymousSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // カスケード接続の設定の変更\r
+               t.ClientAuth->AuthType = CLIENT_AUTHTYPE_ANONYMOUS;\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続のユーザー認証の種類をパスワード認証に設定\r
+UINT PsCascadePasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},\r
+               {"TYPE", CmdPrompt, _UU("CMD_CascadePasswordSet_Prompt_Type"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // カスケード接続の設定の変更\r
+               char *typestr = GetParamStr(o, "TYPE");\r
+\r
+               if (StartWith("standard", typestr))\r
+               {\r
+                       t.ClientAuth->AuthType = CLIENT_AUTHTYPE_PASSWORD;\r
+                       HashPassword(t.ClientAuth->HashedPassword, t.ClientAuth->Username,\r
+                               GetParamStr(o, "PASSWORD"));\r
+               }\r
+               else if (StartWith("radius", typestr) || StartWith("ntdomain", typestr))\r
+               {\r
+                       t.ClientAuth->AuthType = CLIENT_AUTHTYPE_PLAIN_PASSWORD;\r
+\r
+                       StrCpy(t.ClientAuth->PlainPassword, sizeof(t.ClientAuth->PlainPassword),\r
+                               GetParamStr(o, "PASSWORD"));\r
+               }\r
+               else\r
+               {\r
+                       // エラー発生\r
+                       c->Write(c, _UU("CMD_CascadePasswordSet_Type_Invalid"));\r
+                       FreeRpcCreateLink(&t);\r
+                       ret = ERR_INVALID_PARAMETER;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ERR_INTERNAL_ERROR;\r
+               }\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続のユーザー認証の種類をクライアント証明書認証に設定\r
+UINT PsCascadeCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       X *x;\r
+       K *k;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"LOADCERT", CmdPrompt, _UU("CMD_LOADCERTPATH"), CmdEvalIsFile, NULL},\r
+               {"LOADKEY", CmdPrompt, _UU("CMD_LOADKEYPATH"), CmdEvalIsFile, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (CmdLoadCertAndKey(c, &x, &k, GetParamStr(o, "LOADCERT"), GetParamStr(o, "LOADKEY")) == false)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               FreeX(x);\r
+               FreeK(k);\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // 認証データ変更\r
+               t.ClientAuth->AuthType = CLIENT_AUTHTYPE_CERT;\r
+               if (t.ClientAuth->ClientX != NULL)\r
+               {\r
+                       FreeX(t.ClientAuth->ClientX);\r
+               }\r
+               if (t.ClientAuth->ClientK != NULL)\r
+               {\r
+                       FreeK(t.ClientAuth->ClientK);\r
+               }\r
+\r
+               t.ClientAuth->ClientX = x;\r
+               t.ClientAuth->ClientK = k;\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続に用いるクライアント証明書の取得\r
+UINT PsCascadeCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SAVECERT", CmdPrompt, _UU("CMD_SAVECERTPATH"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               if (t.ClientAuth->AuthType != CLIENT_AUTHTYPE_CERT)\r
+               {\r
+                       c->Write(c, _UU("CMD_CascadeCertSet_Not_Auth_Cert"));\r
+                       ret = ERR_INTERNAL_ERROR;\r
+               }\r
+               else if (t.ClientAuth->ClientX == NULL)\r
+               {\r
+                       c->Write(c, _UU("CMD_CascadeCertSet_Cert_Not_Exists"));\r
+                       ret = ERR_INTERNAL_ERROR;\r
+               }\r
+               else\r
+               {\r
+                       XToFile(t.ClientAuth->ClientX, GetParamStr(o, "SAVECERT"), true);\r
+               }\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// カスケード接続の通信時の暗号化の有効化\r
+UINT PsCascadeEncryptEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // データ変更\r
+               t.ClientOption->UseEncrypt = true;\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続の通信時の暗号化の無効化\r
+UINT PsCascadeEncryptDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // データ変更\r
+               t.ClientOption->UseEncrypt = false;\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続の通信時のデータ圧縮の有効化\r
+UINT PsCascadeCompressEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // データ変更\r
+               t.ClientOption->UseCompress = true;\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続の通信時のデータ圧縮の無効化\r
+UINT PsCascadeCompressDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // データ変更\r
+               t.ClientOption->UseCompress = false;\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続の接続方法を直接 TCP/IP 接続に設定\r
+UINT PsCascadeProxyNone(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // データ変更\r
+               t.ClientOption->ProxyType = PROXY_DIRECT;\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続の接続方法を HTTP プロキシサーバー経由接続に設定\r
+UINT PsCascadeProxyHttp(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SERVER", CmdPrompt, _UU("CMD_CascadeProxyHttp_Prompt_Server"), CmdEvalHostAndPort, NULL},\r
+               {"USERNAME", NULL, NULL, NULL, NULL},\r
+               {"PASSWORD", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               char *host;\r
+               UINT port;\r
+\r
+               // データ変更\r
+               if (ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 8080))\r
+               {\r
+                       t.ClientOption->ProxyType = PROXY_HTTP;\r
+                       StrCpy(t.ClientOption->ProxyName, sizeof(t.ClientOption->ProxyName), host);\r
+                       t.ClientOption->ProxyPort = port;\r
+                       StrCpy(t.ClientOption->ProxyUsername, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "USERNAME"));\r
+                       StrCpy(t.ClientOption->ProxyPassword, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "PASSWORD"));\r
+                       Free(host);\r
+               }\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続の接続方法を SOCKS プロキシサーバー経由接続に設定\r
+UINT PsCascadeProxySocks(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SERVER", CmdPrompt, _UU("CMD_CascadeProxyHttp_Prompt_Server"), CmdEvalHostAndPort, NULL},\r
+               {"USERNAME", NULL, NULL, NULL, NULL},\r
+               {"PASSWORD", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               char *host;\r
+               UINT port;\r
+\r
+               // データ変更\r
+               if (ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 8080))\r
+               {\r
+                       t.ClientOption->ProxyType = PROXY_SOCKS;\r
+                       StrCpy(t.ClientOption->ProxyName, sizeof(t.ClientOption->ProxyName), host);\r
+                       t.ClientOption->ProxyPort = port;\r
+                       StrCpy(t.ClientOption->ProxyUsername, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "USERNAME"));\r
+                       StrCpy(t.ClientOption->ProxyPassword, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "PASSWORD"));\r
+                       Free(host);\r
+               }\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続のサーバー証明書の検証オプションの有効化\r
+UINT PsCascadeServerCertEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // データ変更\r
+               t.CheckServerCert = true;\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続のサーバー証明書の検証オプションの無効化\r
+UINT PsCascadeServerCertDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // データ変更\r
+               t.CheckServerCert = false;\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続のサーバー固有証明書の設定\r
+UINT PsCascadeServerCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       X *x;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"LOADCERT", CmdPrompt, _UU("CMD_LOADCERTPATH"), CmdEvalIsFile, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       x = FileToX(GetParamStr(o, "LOADCERT"));\r
+       if (x == NULL)\r
+       {\r
+               FreeParamValueList(o);\r
+               c->Write(c, _UU("CMD_LOADCERT_FAILED"));\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               FreeX(x);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // データ変更\r
+               if (t.ServerCert != NULL)\r
+               {\r
+                       FreeX(t.ServerCert);\r
+               }\r
+               t.ServerCert = x;\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続のサーバー固有証明書の削除\r
+UINT PsCascadeServerCertDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // データ変更\r
+               if (t.ServerCert != NULL)\r
+               {\r
+                       FreeX(t.ServerCert);\r
+               }\r
+               t.ServerCert = NULL;\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続のサーバー固有証明書の取得\r
+UINT PsCascadeServerCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"SAVECERT", CmdPrompt, _UU("CMD_SAVECERTPATH"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // 証明書保存\r
+               if (t.ServerCert == NULL)\r
+               {\r
+                       c->Write(c, _UU("CMD_CERT_NOT_EXISTS"));\r
+                       ret = ERR_INTERNAL_ERROR;\r
+               }\r
+               else\r
+               {\r
+                       if (XToFile(t.ServerCert, GetParamStr(o, "SAVECERT"), true) == false)\r
+                       {\r
+                               c->Write(c, _UU("CMD_SAVECERT_FAILED"));\r
+                               ret = ERR_INTERNAL_ERROR;\r
+                       }\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// カスケード接続の高度な通信設定の設定\r
+UINT PsCascadeDetailSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       CMD_EVAL_MIN_MAX mm_maxtcp =\r
+       {\r
+               "CMD_CascadeDetailSet_Eval_MaxTcp", 1, 32\r
+       };\r
+       CMD_EVAL_MIN_MAX mm_interval =\r
+       {\r
+               "CMD_CascadeDetailSet_Eval_Interval", 1, 4294967295UL\r
+       };\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"MAXTCP", CmdPrompt, _UU("CMD_CascadeDetailSet_Prompt_MaxTcp"), CmdEvalMinMax, &mm_maxtcp},\r
+               {"INTERVAL", CmdPrompt, _UU("CMD_CascadeDetailSet_Prompt_Interval"), CmdEvalMinMax, &mm_interval},\r
+               {"TTL", CmdPrompt, _UU("CMD_CascadeDetailSet_Prompt_TTL"), NULL, NULL},\r
+               {"HALF", CmdPrompt, _UU("CMD_CascadeDetailSet_Prompt_HALF"), NULL, NULL},\r
+               {"NOQOS", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_NOQOS"), NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // データ変更\r
+               t.ClientOption->MaxConnection = GetParamInt(o, "MAXTCP");\r
+               t.ClientOption->AdditionalConnectionInterval = GetParamInt(o, "INTERVAL");\r
+               t.ClientOption->ConnectionDisconnectSpan = GetParamInt(o, "TTL");\r
+               t.ClientOption->HalfConnection = GetParamYes(o, "HALF");\r
+               t.ClientOption->DisableQoS = GetParamYes(o, "NOQOS");\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// セキュリティ ポリシーを表示\r
+void PrintPolicy(CONSOLE *c, POLICY *pol, bool cascade_mode)\r
+{\r
+       UINT i;\r
+       CT *ct;\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (c == NULL || pol == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ct = CtNew();\r
+       CtInsertColumn(ct, _UU("CMD_PolicyList_Column_1"), false);\r
+       CtInsertColumn(ct, _UU("CMD_PolicyList_Column_2"), false);\r
+       CtInsertColumn(ct, _UU("CMD_PolicyList_Column_3"), false);\r
+\r
+       p = NewPack();\r
+       OutRpcPolicy(p, pol);\r
+\r
+       // すべてのポリシー一覧を表示する\r
+       for (i = 0; i < PolicyNum();i++)\r
+       {\r
+               char name[64];\r
+               wchar_t *tmp;\r
+\r
+               if (cascade_mode == false || PolicyIsSupportedForCascade(i))\r
+               {\r
+                       wchar_t value_str[256];\r
+                       UINT value;\r
+                       char tmp2[256];\r
+\r
+                       Format(tmp2, sizeof(tmp2), "policy:%s", PolicyIdToStr(i));\r
+                       value = PackGetInt(p, tmp2);\r
+\r
+                       tmp = CopyStrToUni(PolicyIdToStr(i));\r
+\r
+                       FormatPolicyValue(value_str, sizeof(value_str),\r
+                               i, value);\r
+\r
+                       Format(name, sizeof(name), "POL_%u", i);\r
+                       CtInsert(ct, tmp, _UU(name), value_str);\r
+\r
+                       Free(tmp);\r
+               }\r
+       }\r
+\r
+       FreePack(p);\r
+\r
+       CtFree(ct, c);\r
+}\r
+\r
+// セキュリティ ポリシー リストを表示\r
+void PrintPolicyList(CONSOLE *c, char *name)\r
+{\r
+       UINT id;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (IsEmptyStr(name))\r
+       {\r
+               name = NULL;\r
+       }\r
+\r
+       if (name != NULL)\r
+       {\r
+               id = PolicyStrToId(name);\r
+               if (id == INFINITE)\r
+               {\r
+                       // 不正な ID\r
+                       c->Write(c, _UU("CMD_PolicyList_Invalid_Name"));\r
+               }\r
+               else\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       char name1[64], name2[64];\r
+                       wchar_t *title, *descript;\r
+                       wchar_t policy_name[MAX_SIZE];\r
+\r
+                       Format(name1, sizeof(name1), "POL_%u", id);\r
+                       Format(name2, sizeof(name2), "POL_EX_%u", id);\r
+\r
+                       title = _UU(name1);\r
+                       descript = _UU(name2);\r
+\r
+                       StrToUni(policy_name, sizeof(policy_name), PolicyIdToStr(id));\r
+\r
+                       // ポリシー名\r
+                       c->Write(c, _UU("CMD_PolicyList_Help_1"));\r
+                       UniFormat(tmp2, sizeof(tmp2), L" %s", policy_name);\r
+                       c->Write(c, tmp2);\r
+                       c->Write(c, L"");\r
+\r
+                       // ポリシーの簡易説明\r
+                       c->Write(c, _UU("CMD_PolicyList_Help_2"));\r
+                       UniFormat(tmp2, sizeof(tmp2), L" %s", title);\r
+                       c->Write(c, tmp2);\r
+                       c->Write(c, L"");\r
+\r
+                       // 設定できる値の範囲\r
+                       GetPolicyValueRangeStr(tmp, sizeof(tmp), id);\r
+                       c->Write(c, _UU("CMD_PolicyList_Help_3"));\r
+                       UniFormat(tmp2, sizeof(tmp2), L" %s", tmp);\r
+                       c->Write(c, tmp2);\r
+                       c->Write(c, L"");\r
+\r
+                       // デフォルト値\r
+                       FormatPolicyValue(tmp, sizeof(tmp), id, GetPolicyItem(id)->DefaultValue);\r
+                       c->Write(c, _UU("CMD_PolicyList_Help_4"));\r
+                       UniFormat(tmp2, sizeof(tmp2), L" %s", tmp);\r
+                       c->Write(c, tmp2);\r
+                       c->Write(c, L"");\r
+\r
+                       // ポリシーの詳細説明\r
+                       c->Write(c, _UU("CMD_PolicyList_Help_5"));\r
+                       c->Write(c, descript);\r
+                       c->Write(c, L"");\r
+               }\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+               CT *ct = CtNew();\r
+               CtInsertColumn(ct, _UU("CMD_PolicyList_Column_1"), false);\r
+               CtInsertColumn(ct, _UU("CMD_PolicyList_Column_2"), false);\r
+\r
+               // すべてのポリシー一覧を表示する\r
+               for (i = 0; i < PolicyNum();i++)\r
+               {\r
+                       char name[64];\r
+                       wchar_t *tmp;\r
+\r
+                       tmp = CopyStrToUni(PolicyIdToStr(i));\r
+\r
+                       Format(name, sizeof(name), "POL_%u", i);\r
+                       CtInsert(ct, tmp, _UU(name));\r
+\r
+                       Free(tmp);\r
+               }\r
+\r
+               CtFree(ct, c);\r
+       }\r
+}\r
+\r
+// ポリシーの内容の編集\r
+bool EditPolicy(CONSOLE *c, POLICY *pol, char *name, char *value, bool cascade_mode)\r
+{\r
+       PACK *p;\r
+       ELEMENT *e;\r
+       POLICY_ITEM *item;\r
+       UINT id;\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       char pack_name[128];\r
+       // 引数チェック\r
+       if (c == NULL || pol == NULL || name == NULL || value == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = NewPack();\r
+\r
+       OutRpcPolicy(p, pol);\r
+\r
+       Format(pack_name, sizeof(pack_name), "policy:%s", PolicyIdToStr(PolicyStrToId(name)));\r
+\r
+       if ((e = GetElement(p, pack_name, VALUE_INT)) == NULL || (id = PolicyStrToId(name)) == INFINITE)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("CMD_CascadePolicySet_Invalid_Name"), name);\r
+               c->Write(c, tmp);\r
+               FreePack(p);\r
+               return false;\r
+       }\r
+\r
+       if (cascade_mode && (PolicyIsSupportedForCascade(id) == false))\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("CMD_CascadePolicySet_Invalid_Name_For_Cadcade"), name);\r
+               c->Write(c, tmp);\r
+               FreePack(p);\r
+               return false;\r
+       }\r
+\r
+       item = GetPolicyItem(id);\r
+\r
+       if (item->TypeInt == false)\r
+       {\r
+               // bool 型\r
+               e->values[0]->IntValue = (\r
+                       StartWith(value, "y") || StartWith(value, "t") ||\r
+                       ToInt(value) != 0) ? 1 : 0;\r
+       }\r
+       else\r
+       {\r
+               UINT n = ToInt(value);\r
+               bool b = true;\r
+\r
+               // int 型\r
+               GetPolicyValueRangeStr(tmp, sizeof(tmp), id);\r
+\r
+               if (item->AllowZero == false)\r
+               {\r
+                       if (n == 0)\r
+                       {\r
+                               b = false;\r
+                       }\r
+               }\r
+\r
+               if (n != 0 && (n < item->MinValue || n > item->MaxValue))\r
+               {\r
+                       b = false;\r
+               }\r
+\r
+               if (b == false)\r
+               {\r
+                       UniFormat(tmp2, sizeof(tmp2), _UU("CMD_CascadePolicySet_Invalid_Range"), PolicyIdToStr(id), tmp);\r
+                       c->Write(c, tmp2);\r
+                       FreePack(p);\r
+                       return false;\r
+               }\r
+\r
+               e->values[0]->IntValue = n;\r
+       }\r
+\r
+       Zero(pol, sizeof(POLICY));\r
+\r
+       InRpcPolicy(pol, p);\r
+\r
+       FreePack(p);\r
+\r
+       return true;\r
+}\r
+\r
+// セキュリティ ポリシーの種類と設定可能値の一覧を表示\r
+UINT PsPolicyList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", NULL, NULL, NULL, NULL}\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       PrintPolicyList(c, GetParamStr(o, "[name]"));\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// カスケード接続セッションのセキュリティ ポリシーの設定\r
+UINT PsCascadePolicySet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CREATE_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+               {"NAME", CmdPrompt, _UU("CMD_CascadePolicySet_PROMPT_POLNAME"), CmdEvalNotEmpty, NULL},\r
+               {"VALUE", CmdPrompt, _UU("CMD_CascadePolicySet_PROMPT_POLVALUE"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               if (EditPolicy(c, &t.Policy, GetParamStr(o, "NAME"), GetParamStr(o, "VALUE"), true) == false)\r
+               {\r
+                       // エラー発生\r
+                       FreeRpcCreateLink(&t);\r
+                       FreeParamValueList(o);\r
+                       return ERR_INTERNAL_ERROR;\r
+               }\r
+\r
+               ret = ScSetLink(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// セッションのステータス情報の表示\r
+void CmdPrintStatusToListView(CT *ct, RPC_CLIENT_GET_CONNECTION_STATUS *s)\r
+{\r
+       CmdPrintStatusToListViewEx(ct, s, false);\r
+}\r
+void CmdPrintStatusToListViewEx(CT *ct, RPC_CLIENT_GET_CONNECTION_STATUS *s, bool server_mode)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       char str[MAX_SIZE];\r
+       char vv[128];\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (server_mode == false)\r
+       {\r
+               CtInsert(ct, _UU("CM_ST_ACCOUNT_NAME"), s->AccountName);\r
+\r
+               if (s->Connected == false)\r
+               {\r
+                       wchar_t *st = _UU("CM_ST_CONNECTED_FALSE");\r
+                       switch (s->SessionStatus)\r
+                       {\r
+                       case CLIENT_STATUS_CONNECTING:\r
+                               st = _UU("CM_ST_CONNECTING");\r
+                               break;\r
+                       case CLIENT_STATUS_NEGOTIATION:\r
+                               st = _UU("CM_ST_NEGOTIATION");\r
+                               break;\r
+                       case CLIENT_STATUS_AUTH:\r
+                               st = _UU("CM_ST_AUTH");\r
+                               break;\r
+                       case CLIENT_STATUS_ESTABLISHED:\r
+                               st = _UU("CM_ST_ESTABLISHED");\r
+                               break;\r
+                       case CLIENT_STATUS_RETRY:\r
+                               st = _UU("CM_ST_RETRY");\r
+                               break;\r
+                       case CLIENT_STATUS_IDLE:\r
+                               st = _UU("CM_ST_IDLE");\r
+                               break;\r
+                       }\r
+                       CtInsert(ct, _UU("CM_ST_CONNECTED"), st);\r
+               }\r
+               else\r
+               {\r
+                       CtInsert(ct, _UU("CM_ST_CONNECTED"), _UU("CM_ST_CONNECTED_TRUE"));\r
+               }\r
+       }\r
+\r
+       if (s->Connected)\r
+       {\r
+               if (s->VLanId == 0)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("CM_ST_NO_VLAN"));\r
+               }\r
+               else\r
+               {\r
+                       UniToStru(tmp, s->VLanId);\r
+               }\r
+\r
+               CtInsert(ct, _UU("CM_ST_VLAN_ID"), tmp);\r
+\r
+               if (server_mode == false)\r
+               {\r
+                       StrToUni(tmp, sizeof(tmp), s->ServerName);\r
+                       CtInsert(ct, _UU("CM_ST_SERVER_NAME"), tmp);\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_ST_PORT_TCP"), s->ServerPort);\r
+                       CtInsert(ct, _UU("CM_ST_SERVER_PORT"), tmp);\r
+               }\r
+\r
+               StrToUni(tmp, sizeof(tmp), s->ServerProductName);\r
+               CtInsert(ct, _UU("CM_ST_SERVER_P_NAME"), tmp);\r
+\r
+               UniFormat(tmp, sizeof(tmp), L"%u.%02u", s->ServerProductVer / 100, s->ServerProductVer % 100);\r
+               CtInsert(ct, _UU("CM_ST_SERVER_P_VER"), tmp);\r
+               UniFormat(tmp, sizeof(tmp), L"Build %u", s->ServerProductBuild);\r
+               CtInsert(ct, _UU("CM_ST_SERVER_P_BUILD"), tmp);\r
+       }\r
+\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(s->StartTime), NULL);\r
+       CtInsert(ct, _UU("CM_ST_START_TIME"), tmp);\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(s->FirstConnectionEstablisiedTime), NULL);\r
+       CtInsert(ct, _UU("CM_ST_FIRST_ESTAB_TIME"), s->FirstConnectionEstablisiedTime == 0 ? _UU("CM_ST_NONE") : tmp);\r
+\r
+       if (s->Connected)\r
+       {\r
+               GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(s->CurrentConnectionEstablishTime), NULL);\r
+               CtInsert(ct, _UU("CM_ST_CURR_ESTAB_TIME"), tmp);\r
+       }\r
+\r
+       if (server_mode == false)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_STR"), s->NumConnectionsEatablished);\r
+               CtInsert(ct, _UU("CM_ST_NUM_ESTABLISHED"), tmp);\r
+       }\r
+\r
+       if (s->Connected)\r
+       {\r
+               CtInsert(ct, _UU("CM_ST_HALF_CONNECTION"), s->HalfConnection ? _UU("CM_ST_HALF_TRUE") : _UU("CM_ST_HALF_FALSE"));\r
+\r
+               CtInsert(ct, _UU("CM_ST_QOS"), s->QoS ? _UU("CM_ST_QOS_TRUE") : _UU("CM_ST_QOS_FALSE"));\r
+\r
+               UniFormat(tmp, sizeof(tmp), L"%u", s->NumTcpConnections);\r
+               CtInsert(ct, _UU("CM_ST_NUM_TCP"), tmp);\r
+\r
+               if (s->HalfConnection)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), L"%u", s->NumTcpConnectionsUpload);\r
+                       CtInsert(ct, _UU("CM_ST_NUM_TCP_UPLOAD"), tmp);\r
+                       UniFormat(tmp, sizeof(tmp), L"%u", s->NumTcpConnectionsDownload);\r
+                       CtInsert(ct, _UU("CM_ST_NUM_TCP_DOWNLOAD"), tmp);\r
+               }\r
+\r
+               UniFormat(tmp, sizeof(tmp), L"%u", s->MaxTcpConnections);\r
+               CtInsert(ct, _UU("CM_ST_MAX_TCP"), tmp);\r
+\r
+               if (s->UseEncrypt == false)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("CM_ST_USE_ENCRYPT_FALSE"));\r
+               }\r
+               else\r
+               {\r
+                       if (StrLen(s->CipherName) != 0)\r
+                       {\r
+                               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_USE_ENCRYPT_TRUE"), s->CipherName);\r
+                       }\r
+                       else\r
+                       {\r
+                               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_USE_ENCRYPT_TRUE2"));\r
+                       }\r
+               }\r
+               CtInsert(ct, _UU("CM_ST_USE_ENCRYPT"), tmp);\r
+\r
+               if (s->UseCompress)\r
+               {\r
+                       UINT percent = 0;\r
+                       if ((s->TotalRecvSize + s->TotalSendSize) > 0)\r
+                       {\r
+                               percent = (UINT)((UINT64)100 - (UINT64)(s->TotalRecvSizeReal + s->TotalSendSizeReal) * (UINT64)100 /\r
+                                       (s->TotalRecvSize + s->TotalSendSize));\r
+                               percent = MAKESURE(percent, 0, 100);\r
+                       }\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_ST_COMPRESS_TRUE"), percent);\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("CM_ST_COMPRESS_FALSE"));\r
+               }\r
+               CtInsert(ct, _UU("CM_ST_USE_COMPRESS"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), s->SessionName);\r
+               CtInsert(ct, _UU("CM_ST_SESSION_NAME"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), s->ConnectionName);\r
+               if (UniStrCmpi(tmp, L"INITING") != 0)\r
+               {\r
+                       CtInsert(ct, _UU("CM_ST_CONNECTION_NAME"), tmp);\r
+               }\r
+\r
+               BinToStr(str, sizeof(str), s->SessionKey, sizeof(s->SessionKey));\r
+               StrToUni(tmp, sizeof(tmp), str);\r
+               CtInsert(ct, _UU("CM_ST_SESSION_KEY"), tmp);\r
+\r
+               CtInsert(ct, _UU("CM_ST_BRIDGE_MODE"), s->IsBridgeMode ? _UU("CM_ST_YES") : _UU("CM_ST_NO"));\r
+\r
+               CtInsert(ct, _UU("CM_ST_MONITOR_MODE"), s->IsMonitorMode ? _UU("CM_ST_YES") : _UU("CM_ST_NO"));\r
+\r
+               ToStr3(vv, sizeof(vv), s->TotalSendSize);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);\r
+               CtInsert(ct, _UU("CM_ST_SEND_SIZE"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->TotalRecvSize);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);\r
+               CtInsert(ct, _UU("CM_ST_RECV_SIZE"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Send.UnicastCount);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_PACKET_STR"), vv);\r
+               CtInsert(ct, _UU("CM_ST_SEND_UCAST_NUM"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Send.UnicastBytes);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);\r
+               CtInsert(ct, _UU("CM_ST_SEND_UCAST_SIZE"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Send.BroadcastCount);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_PACKET_STR"), vv);\r
+               CtInsert(ct, _UU("CM_ST_SEND_BCAST_NUM"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Send.BroadcastBytes);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);\r
+               CtInsert(ct, _UU("CM_ST_SEND_BCAST_SIZE"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Recv.UnicastCount);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_PACKET_STR"), vv);\r
+               CtInsert(ct, _UU("CM_ST_RECV_UCAST_NUM"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Recv.UnicastBytes);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);\r
+               CtInsert(ct, _UU("CM_ST_RECV_UCAST_SIZE"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Recv.BroadcastCount);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_PACKET_STR"), vv);\r
+               CtInsert(ct, _UU("CM_ST_RECV_BCAST_NUM"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), s->Traffic.Recv.BroadcastBytes);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);\r
+               CtInsert(ct, _UU("CM_ST_RECV_BCAST_SIZE"), tmp);\r
+       }\r
+}\r
+\r
+// カスケード接続の現在の状態の取得\r
+UINT PsCascadeStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_LINK_STATUS t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLinkStatus(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // カスケード接続状態の取得\r
+               CT *ct = CtNewStandard();\r
+\r
+               CmdPrintStatusToListView(ct, &t.Status);\r
+\r
+               CtFree(ct, c);\r
+\r
+               FreeRpcLinkStatus(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続の名前の変更\r
+UINT PsCascadeRename(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_RENAME_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeRename_PROMPT_OLD"), CmdEvalNotEmpty, NULL},\r
+               {"NEW", CmdPrompt, _UU("CMD_CascadeRename_PROMPT_NEW"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       UniStrCpy(t.NewAccountName, sizeof(t.NewAccountName), GetParamUniStr(o, "NEW"));\r
+       UniStrCpy(t.OldAccountName, sizeof(t.OldAccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScRenameLink(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続のオンライン状態への設定\r
+UINT PsCascadeOnline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetLinkOnline(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続のオフライン状態への設定\r
+UINT PsCascadeOffline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_LINK t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetLinkOffline(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 文字列を pass/discard に変換\r
+bool StrToPassOrDiscard(char *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ToInt(str) != 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (StartWith(str, "p") || StartWith(str, "y") || StartWith(str, "t"))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// 文字列をプロトコルに変換\r
+UINT StrToProtocol(char *str)\r
+{\r
+       if (IsEmptyStr(str))\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (StartWith("ip", str))\r
+       {\r
+               return 0;\r
+       }\r
+       else if (StartWith("tcp", str))\r
+       {\r
+               return IP_PROTO_TCP;\r
+       }\r
+       else if (StartWith("udp", str))\r
+       {\r
+               return IP_PROTO_UDP;\r
+       }\r
+       else if (StartWith("icmpv4", str))\r
+       {\r
+               return IP_PROTO_ICMPV4;\r
+       }\r
+       else if (StartWith("icmpv6", str))\r
+       {\r
+               return IP_PROTO_ICMPV6;\r
+       }\r
+\r
+       if (ToInt(str) == 0)\r
+       {\r
+               if (StrCmpi(str, "0") == 0)\r
+               {\r
+                       return 0;\r
+               }\r
+               else\r
+               {\r
+                       return INFINITE;\r
+               }\r
+       }\r
+\r
+       if (ToInt(str) >= 256)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return ToInt(str);\r
+}\r
+\r
+// プロトコル名のチェック\r
+bool CmdEvalProtocol(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char tmp[64];\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       if (StrToProtocol(tmp) == INFINITE)\r
+       {\r
+               c->Write(c, _UU("CMD_PROTOCOL_EVAL_FAILED"));\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ポート範囲のパース\r
+bool ParsePortRange(char *str, UINT *start, UINT *end)\r
+{\r
+       UINT a = 0, b = 0;\r
+       TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsEmptyStr(str) == false)\r
+       {\r
+\r
+               t = ParseToken(str, "\t -");\r
+\r
+               if (t->NumTokens == 1)\r
+               {\r
+                       a = b = ToInt(t->Token[0]);\r
+               }\r
+               else if (t->NumTokens == 2)\r
+               {\r
+                       a = ToInt(t->Token[0]);\r
+                       b = ToInt(t->Token[1]);\r
+               }\r
+\r
+               FreeToken(t);\r
+\r
+               if (a > b)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               if (a >= 65536 || b >= 65536)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               if (a == 0 && b != 0)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       if (start != NULL)\r
+       {\r
+               *start = a;\r
+       }\r
+       if (end != NULL)\r
+       {\r
+               *end = b;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ポート範囲のチェック\r
+bool CmdEvalPortRange(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char tmp[64];\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       if (ParsePortRange(tmp, NULL, NULL) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_PORT_RANGE_EVAL_FAILED"));\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// MAC アドレスとマスクのパース\r
+bool ParseMacAddressAndMask(char *src, bool *check_mac, UCHAR *mac_bin, UCHAR *mask_bin)\r
+{\r
+       TOKEN_LIST *t;\r
+       char *macstr, *maskstr;\r
+       UCHAR mac[6], mask[6];\r
+       bool ok = false;\r
+\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       //Zero(mac, sizeof(mac));\r
+       //Zero(mask, sizeof(mask));\r
+\r
+       if(check_mac != NULL && mac_bin != NULL && mask_bin != NULL)\r
+       {\r
+               ok = true;\r
+       }\r
+       if(IsEmptyStr(src) != false)\r
+       {\r
+               if(ok != false)\r
+               {\r
+                       *check_mac = false;\r
+                       Zero(mac_bin, 6);\r
+                       Zero(mask_bin, 6);\r
+               }\r
+               return true;\r
+       }\r
+\r
+       t = ParseToken(src, "/");\r
+       if(t->NumTokens != 2)\r
+       {\r
+               FreeToken(t);\r
+               return false;\r
+       }\r
+\r
+       macstr = t->Token[0];\r
+       maskstr = t->Token[1];\r
+\r
+       Trim(macstr);\r
+       Trim(maskstr);\r
+\r
+       if(StrToMac(mac, macstr) == false || StrToMac(mask, maskstr) == false)\r
+       {\r
+               FreeToken(t);\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               if(ok != false)\r
+               {\r
+                       Copy(mac_bin, mac, 6);\r
+                       Copy(mask_bin, mask, 6);\r
+                       *check_mac = true;\r
+               }\r
+       }\r
+       FreeToken(t);\r
+\r
+       return true;\r
+}\r
+\r
+// MAC アドレスとマスクのチェック\r
+bool CmdEvalMacAddressAndMask(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char tmp[64];\r
+       // 引数チェック\r
+       if(c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+\r
+       if(ParseMacAddressAndMask(tmp, NULL, NULL, NULL) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_MAC_ADDRESS_AND_MASK_EVAL_FAILED"));\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+// TCP コネクションの状態パース\r
+bool ParseTcpState(char *src, bool *check_tcp_state, bool *established)\r
+{\r
+       bool ok = false;\r
+       // 引数チェック\r
+       if(src == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if(check_tcp_state != NULL && established != NULL)\r
+       {\r
+               ok = true;\r
+       }\r
+\r
+       if (IsEmptyStr(src) == false)\r
+       {\r
+               if (StartWith("Established", src) == 0)\r
+               {\r
+                       if(ok != false)\r
+                       {\r
+                               *check_tcp_state = true;\r
+                               *established = true;\r
+                       }\r
+               }\r
+               else if (StartWith("Unestablished", src) == 0)\r
+               {\r
+                       if(ok != false)\r
+                       {\r
+                               *check_tcp_state = true;\r
+                               *established = false;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // 不正な文字列\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if(ok != false)\r
+               {\r
+                       *check_tcp_state = false;\r
+                       *established = false;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+// TCP コネクションの状態チェック\r
+bool CmdEvalTcpState(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char tmp[64];\r
+       // 引数チェック\r
+       if(c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       if(ParseTcpState(tmp, NULL, NULL) == false)\r
+       {\r
+               c->Write(c, _UU("CMD_TCP_CONNECTION_STATE_EVAL_FAILED"));\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// アクセス リストへのルールの追加 (標準、IPv4)\r
+UINT PsAccessAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ADD_ACCESS t;\r
+       ACCESS *a;\r
+       // 指定できるパラメータ リスト\r
+       CMD_EVAL_MIN_MAX minmax =\r
+       {\r
+               "CMD_AccessAdd_Eval_PRIORITY", 1, 4294967295UL,\r
+       };\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[pass|discard]", CmdPrompt, _UU("CMD_AccessAdd_Prompt_TYPE"), CmdEvalNotEmpty, NULL},\r
+               {"MEMO", CmdPrompt, _UU("CMD_AccessAdd_Prompt_MEMO"), NULL, NULL},\r
+               {"PRIORITY", CmdPrompt, _UU("CMD_AccessAdd_Prompt_PRIORITY"), CmdEvalMinMax, &minmax},\r
+               {"SRCUSERNAME", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCUSERNAME"), NULL, NULL},\r
+               {"DESTUSERNAME", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTUSERNAME"), NULL, NULL},\r
+               {"SRCMAC", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCMAC"), CmdEvalMacAddressAndMask, NULL},\r
+               {"DESTMAC", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTMAC"), CmdEvalMacAddressAndMask, NULL},\r
+               {"SRCIP", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCIP"), CmdEvalIpAndMask4, NULL},\r
+               {"DESTIP", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTIP"), CmdEvalIpAndMask4, NULL},\r
+               {"PROTOCOL", CmdPrompt, _UU("CMD_AccessAdd_Prompt_PROTOCOL"), CmdEvalProtocol, NULL},\r
+               {"SRCPORT", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCPORT"), CmdEvalPortRange, NULL},\r
+               {"DESTPORT", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTPORT"), CmdEvalPortRange, NULL},\r
+               {"TCPSTATE", CmdPrompt, _UU("CMD_AccessAdd_Prompt_TCPSTATE"), CmdEvalTcpState, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       a = &t.Access;\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       UniStrCpy(a->Note, sizeof(a->Note), GetParamUniStr(o, "MEMO"));\r
+       a->Active = true;\r
+       a->Priority = GetParamInt(o, "PRIORITY");\r
+       a->Discard = StrToPassOrDiscard(GetParamStr(o, "[pass|discard]")) ? false : true;\r
+       StrCpy(a->SrcUsername, sizeof(a->SrcUsername), GetParamStr(o, "SRCUSERNAME"));\r
+       StrCpy(a->DestUsername, sizeof(a->DestUsername), GetParamStr(o, "DESTUSERNAME"));\r
+       ParseMacAddressAndMask(GetParamStr(o, "SRCMAC"), &a->CheckSrcMac, a->SrcMacAddress, a->SrcMacMask);\r
+       ParseMacAddressAndMask(GetParamStr(o, "DESTMAC"), &a->CheckDstMac, a->DstMacAddress, a->DstMacMask);\r
+       ParseIpAndMask4(GetParamStr(o, "SRCIP"), &a->SrcIpAddress, &a->SrcSubnetMask);\r
+       ParseIpAndMask4(GetParamStr(o, "DESTIP"), &a->DestIpAddress, &a->DestSubnetMask);\r
+       a->Protocol = StrToProtocol(GetParamStr(o, "PROTOCOL"));\r
+       ParsePortRange(GetParamStr(o, "SRCPORT"), &a->SrcPortStart, &a->SrcPortEnd);\r
+       ParsePortRange(GetParamStr(o, "DESTPORT"), &a->DestPortStart, &a->DestPortEnd);\r
+       ParseTcpState(GetParamStr(o, "TCPSTATE"), &a->CheckTcpState, &a->Established);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScAddAccess(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// アクセス リストへのルールの追加 (拡張、IPv4)\r
+UINT PsAccessAddEx(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ADD_ACCESS t;\r
+       ACCESS *a;\r
+       // 指定できるパラメータ リスト\r
+       CMD_EVAL_MIN_MAX minmax =\r
+       {\r
+               "CMD_AccessAdd_Eval_PRIORITY", 1, 4294967295UL,\r
+       };\r
+       CMD_EVAL_MIN_MAX minmax_delay =\r
+       {\r
+               "CMD_AccessAddEx_Eval_DELAY", 0, HUB_ACCESSLIST_DELAY_MAX,\r
+       };\r
+       CMD_EVAL_MIN_MAX minmax_jitter =\r
+       {\r
+               "CMD_AccessAddEx_Eval_JITTER", 0, HUB_ACCESSLIST_JITTER_MAX,\r
+       };\r
+       CMD_EVAL_MIN_MAX minmax_loss =\r
+       {\r
+               "CMD_AccessAddEx_Eval_LOSS", 0, HUB_ACCESSLIST_LOSS_MAX,\r
+       };\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[pass|discard]", CmdPrompt, _UU("CMD_AccessAdd_Prompt_TYPE"), CmdEvalNotEmpty, NULL},\r
+               {"MEMO", CmdPrompt, _UU("CMD_AccessAdd_Prompt_MEMO"), NULL, NULL},\r
+               {"PRIORITY", CmdPrompt, _UU("CMD_AccessAdd_Prompt_PRIORITY"), CmdEvalMinMax, &minmax},\r
+               {"SRCUSERNAME", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCUSERNAME"), NULL, NULL},\r
+               {"DESTUSERNAME", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTUSERNAME"), NULL, NULL},\r
+               {"SRCMAC", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCMAC"), CmdEvalMacAddressAndMask, NULL},\r
+               {"DESTMAC", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTMAC"), CmdEvalMacAddressAndMask, NULL},\r
+               {"SRCIP", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCIP"), CmdEvalIpAndMask4, NULL},\r
+               {"DESTIP", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTIP"), CmdEvalIpAndMask4, NULL},\r
+               {"PROTOCOL", CmdPrompt, _UU("CMD_AccessAdd_Prompt_PROTOCOL"), CmdEvalProtocol, NULL},\r
+               {"SRCPORT", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCPORT"), CmdEvalPortRange, NULL},\r
+               {"DESTPORT", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTPORT"), CmdEvalPortRange, NULL},\r
+               {"TCPSTATE", CmdPrompt, _UU("CMD_AccessAdd_Prompt_TCPSTATE"), CmdEvalTcpState, NULL},\r
+               {"DELAY", CmdPrompt, _UU("CMD_AccessAddEx_Prompt_DELAY"), CmdEvalMinMax, &minmax_delay},\r
+               {"JITTER", CmdPrompt, _UU("CMD_AccessAddEx_Prompt_JITTER"), CmdEvalMinMax, &minmax_jitter},\r
+               {"LOSS", CmdPrompt, _UU("CMD_AccessAddEx_Prompt_LOSS"), CmdEvalMinMax, &minmax_loss},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // サポートしているかどうかチェック\r
+       if (GetCapsBool(ps->CapsList, "b_support_ex_acl") == false)\r
+       {\r
+               c->Write(c, _E(ERR_NOT_SUPPORTED));\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       a = &t.Access;\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       UniStrCpy(a->Note, sizeof(a->Note), GetParamUniStr(o, "MEMO"));\r
+       a->Active = true;\r
+       a->Priority = GetParamInt(o, "PRIORITY");\r
+       a->Discard = StrToPassOrDiscard(GetParamStr(o, "[pass|discard]")) ? false : true;\r
+       StrCpy(a->SrcUsername, sizeof(a->SrcUsername), GetParamStr(o, "SRCUSERNAME"));\r
+       StrCpy(a->DestUsername, sizeof(a->DestUsername), GetParamStr(o, "DESTUSERNAME"));\r
+       ParseMacAddressAndMask(GetParamStr(o, "SRCMAC"), &a->CheckSrcMac, a->SrcMacAddress, a->SrcMacMask);\r
+       ParseMacAddressAndMask(GetParamStr(o, "DESTMAC"), &a->CheckDstMac, a->DstMacAddress, a->DstMacMask);\r
+       ParseIpAndMask4(GetParamStr(o, "SRCIP"), &a->SrcIpAddress, &a->SrcSubnetMask);\r
+       ParseIpAndMask4(GetParamStr(o, "DESTIP"), &a->DestIpAddress, &a->DestSubnetMask);\r
+       a->Protocol = StrToProtocol(GetParamStr(o, "PROTOCOL"));\r
+       ParsePortRange(GetParamStr(o, "SRCPORT"), &a->SrcPortStart, &a->SrcPortEnd);\r
+       ParsePortRange(GetParamStr(o, "DESTPORT"), &a->DestPortStart, &a->DestPortEnd);\r
+       ParseTcpState(GetParamStr(o, "TCPSTATE"), &a->CheckTcpState, &a->Established);\r
+       a->Delay = GetParamInt(o, "DELAY");\r
+       a->Jitter = GetParamInt(o, "JITTER");\r
+       a->Loss = GetParamInt(o, "LOSS");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScAddAccess(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// アクセス リストへのルールの追加 (標準、IPv6)\r
+UINT PsAccessAdd6(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ADD_ACCESS t;\r
+       ACCESS *a;\r
+       IP ip, mask;\r
+       // 指定できるパラメータ リスト\r
+       CMD_EVAL_MIN_MAX minmax =\r
+       {\r
+               "CMD_AccessAdd6_Eval_PRIORITY", 1, 4294967295UL,\r
+       };\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[pass|discard]", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_TYPE"), CmdEvalNotEmpty, NULL},\r
+               {"MEMO", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_MEMO"), NULL, NULL},\r
+               {"PRIORITY", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_PRIORITY"), CmdEvalMinMax, &minmax},\r
+               {"SRCUSERNAME", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCUSERNAME"), NULL, NULL},\r
+               {"DESTUSERNAME", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTUSERNAME"), NULL, NULL},\r
+               {"SRCMAC", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCMAC"), CmdEvalMacAddressAndMask, NULL},\r
+               {"DESTMAC", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTMAC"), CmdEvalMacAddressAndMask, NULL},\r
+               {"SRCIP", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCIP"), CmdEvalIpAndMask6, NULL},\r
+               {"DESTIP", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTIP"), CmdEvalIpAndMask6, NULL},\r
+               {"PROTOCOL", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_PROTOCOL"), CmdEvalProtocol, NULL},\r
+               {"SRCPORT", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCPORT"), CmdEvalPortRange, NULL},\r
+               {"DESTPORT", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTPORT"), CmdEvalPortRange, NULL},\r
+               {"TCPSTATE", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_TCPSTATE"), CmdEvalTcpState, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // サポートしているかどうかチェック\r
+       if (GetCapsBool(ps->CapsList, "b_support_ex_acl") == false)\r
+       {\r
+               c->Write(c, _E(ERR_NOT_SUPPORTED));\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       a = &t.Access;\r
+\r
+       a->IsIPv6 = true;\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       UniStrCpy(a->Note, sizeof(a->Note), GetParamUniStr(o, "MEMO"));\r
+       a->Active = true;\r
+       a->Priority = GetParamInt(o, "PRIORITY");\r
+       a->Discard = StrToPassOrDiscard(GetParamStr(o, "[pass|discard]")) ? false : true;\r
+       StrCpy(a->SrcUsername, sizeof(a->SrcUsername), GetParamStr(o, "SRCUSERNAME"));\r
+       StrCpy(a->DestUsername, sizeof(a->DestUsername), GetParamStr(o, "DESTUSERNAME"));\r
+       ParseMacAddressAndMask(GetParamStr(o, "SRCMAC"), &a->CheckSrcMac, a->SrcMacAddress, a->SrcMacMask);\r
+       ParseMacAddressAndMask(GetParamStr(o, "DESTMAC"), &a->CheckDstMac, a->DstMacAddress, a->DstMacMask);\r
+\r
+       Zero(&ip, sizeof(ip));\r
+       Zero(&mask, sizeof(mask));\r
+\r
+       ParseIpAndMask6(GetParamStr(o, "SRCIP"), &ip, &mask);\r
+       IPToIPv6Addr(&a->SrcIpAddress6, &ip);\r
+       IPToIPv6Addr(&a->SrcSubnetMask6, &mask);\r
+\r
+       ParseIpAndMask6(GetParamStr(o, "DESTIP"), &ip, &mask);\r
+       IPToIPv6Addr(&a->DestIpAddress6, &ip);\r
+       IPToIPv6Addr(&a->DestSubnetMask6, &mask);\r
+\r
+       a->Protocol = StrToProtocol(GetParamStr(o, "PROTOCOL"));\r
+       ParsePortRange(GetParamStr(o, "SRCPORT"), &a->SrcPortStart, &a->SrcPortEnd);\r
+       ParsePortRange(GetParamStr(o, "DESTPORT"), &a->DestPortStart, &a->DestPortEnd);\r
+       ParseTcpState(GetParamStr(o, "TCPSTATE"), &a->CheckTcpState, &a->Established);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScAddAccess(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// アクセス リストへのルールの追加 (拡張、IPv6)\r
+UINT PsAccessAddEx6(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ADD_ACCESS t;\r
+       ACCESS *a;\r
+       IP ip, mask;\r
+       // 指定できるパラメータ リスト\r
+       CMD_EVAL_MIN_MAX minmax =\r
+       {\r
+               "CMD_AccessAdd6_Eval_PRIORITY", 1, 4294967295UL,\r
+       };\r
+       CMD_EVAL_MIN_MAX minmax_delay =\r
+       {\r
+               "CMD_AccessAddEx6_Eval_DELAY", 0, HUB_ACCESSLIST_DELAY_MAX,\r
+       };\r
+       CMD_EVAL_MIN_MAX minmax_jitter =\r
+       {\r
+               "CMD_AccessAddEx6_Eval_JITTER", 0, HUB_ACCESSLIST_JITTER_MAX,\r
+       };\r
+       CMD_EVAL_MIN_MAX minmax_loss =\r
+       {\r
+               "CMD_AccessAddEx6_Eval_LOSS", 0, HUB_ACCESSLIST_LOSS_MAX,\r
+       };\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[pass|discard]", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_TYPE"), CmdEvalNotEmpty, NULL},\r
+               {"MEMO", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_MEMO"), NULL, NULL},\r
+               {"PRIORITY", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_PRIORITY"), CmdEvalMinMax, &minmax},\r
+               {"SRCUSERNAME", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCUSERNAME"), NULL, NULL},\r
+               {"DESTUSERNAME", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTUSERNAME"), NULL, NULL},\r
+               {"SRCMAC", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCMAC"), CmdEvalMacAddressAndMask, NULL},\r
+               {"DESTMAC", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTMAC"), CmdEvalMacAddressAndMask, NULL},\r
+               {"SRCIP", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCIP"), CmdEvalIpAndMask6, NULL},\r
+               {"DESTIP", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTIP"), CmdEvalIpAndMask6, NULL},\r
+               {"PROTOCOL", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_PROTOCOL"), CmdEvalProtocol, NULL},\r
+               {"SRCPORT", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCPORT"), CmdEvalPortRange, NULL},\r
+               {"DESTPORT", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTPORT"), CmdEvalPortRange, NULL},\r
+               {"TCPSTATE", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_TCPSTATE"), CmdEvalTcpState, NULL},\r
+               {"DELAY", CmdPrompt, _UU("CMD_AccessAddEx6_Prompt_DELAY"), CmdEvalMinMax, &minmax_delay},\r
+               {"JITTER", CmdPrompt, _UU("CMD_AccessAddEx6_Prompt_JITTER"), CmdEvalMinMax, &minmax_jitter},\r
+               {"LOSS", CmdPrompt, _UU("CMD_AccessAddEx6_Prompt_LOSS"), CmdEvalMinMax, &minmax_loss},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // サポートしているかどうかチェック\r
+       if (GetCapsBool(ps->CapsList, "b_support_ex_acl") == false)\r
+       {\r
+               c->Write(c, _E(ERR_NOT_SUPPORTED));\r
+               return ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       a = &t.Access;\r
+\r
+       a->IsIPv6 = true;\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       UniStrCpy(a->Note, sizeof(a->Note), GetParamUniStr(o, "MEMO"));\r
+       a->Active = true;\r
+       a->Priority = GetParamInt(o, "PRIORITY");\r
+       a->Discard = StrToPassOrDiscard(GetParamStr(o, "[pass|discard]")) ? false : true;\r
+       StrCpy(a->SrcUsername, sizeof(a->SrcUsername), GetParamStr(o, "SRCUSERNAME"));\r
+       StrCpy(a->DestUsername, sizeof(a->DestUsername), GetParamStr(o, "DESTUSERNAME"));\r
+       ParseMacAddressAndMask(GetParamStr(o, "SRCMAC"), &a->CheckSrcMac, a->SrcMacAddress, a->SrcMacMask);\r
+       ParseMacAddressAndMask(GetParamStr(o, "DESTMAC"), &a->CheckDstMac, a->DstMacAddress, a->DstMacMask);\r
+\r
+       Zero(&ip, sizeof(ip));\r
+       Zero(&mask, sizeof(mask));\r
+\r
+       ParseIpAndMask6(GetParamStr(o, "SRCIP"), &ip, &mask);\r
+       IPToIPv6Addr(&a->SrcIpAddress6, &ip);\r
+       IPToIPv6Addr(&a->SrcSubnetMask6, &mask);\r
+\r
+       ParseIpAndMask6(GetParamStr(o, "DESTIP"), &ip, &mask);\r
+       IPToIPv6Addr(&a->DestIpAddress6, &ip);\r
+       IPToIPv6Addr(&a->DestSubnetMask6, &mask);\r
+\r
+       a->Protocol = StrToProtocol(GetParamStr(o, "PROTOCOL"));\r
+       ParsePortRange(GetParamStr(o, "SRCPORT"), &a->SrcPortStart, &a->SrcPortEnd);\r
+       ParsePortRange(GetParamStr(o, "DESTPORT"), &a->DestPortStart, &a->DestPortEnd);\r
+       ParseTcpState(GetParamStr(o, "TCPSTATE"), &a->CheckTcpState, &a->Established);\r
+       a->Delay = GetParamInt(o, "DELAY");\r
+       a->Jitter = GetParamInt(o, "JITTER");\r
+       a->Loss = GetParamInt(o, "LOSS");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScAddAccess(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+\r
+// アクセス リストのルール一覧の取得\r
+UINT PsAccessList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_ACCESS_LIST t;\r
+       CT *ct;\r
+       UINT i;\r
+       \r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumAccess(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       ct = CtNew();\r
+       CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_0"), true);\r
+       CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_1"), true);\r
+       CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_2"), true);\r
+       CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_3"), true);\r
+       CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_5"), false);\r
+       CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_4"), false);\r
+\r
+       for (i = 0;i < t.NumAccess;i++)\r
+       {\r
+               ACCESS *a = &t.Accesses[i];\r
+               char tmp[MAX_SIZE];\r
+               wchar_t tmp3[MAX_SIZE];\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+\r
+               GetAccessListStr(tmp, sizeof(tmp), a);\r
+               UniToStru(tmp1, a->Priority);\r
+               StrToUni(tmp2, sizeof(tmp2), tmp);\r
+\r
+               UniToStru(tmp3, a->Id);\r
+\r
+               CtInsert(ct,\r
+                       tmp3,\r
+                       a->Discard ? _UU("SM_ACCESS_DISCARD") : _UU("SM_ACCESS_PASS"),\r
+                       a->Active ? _UU("SM_ACCESS_ENABLE") : _UU("SM_ACCESS_DISABLE"),\r
+                       tmp1,\r
+                       tmp2,\r
+                       a->Note);\r
+       }\r
+\r
+       CtFreeEx(ct, c, true);\r
+\r
+       FreeRpcEnumAccessList(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// アクセス リストからルールを削除\r
+UINT PsAccessDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_DELETE_ACCESS t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_Access_Prompt_ID"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.Id = GetParamInt(o, "[id]");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDeleteAccess(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// アクセス リストのルールの有効化\r
+UINT PsAccessEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_ACCESS_LIST t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_Access_Prompt_ID"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumAccess(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+               bool b = false;\r
+               for (i = 0;i < t.NumAccess;i++)\r
+               {\r
+                       ACCESS *a = &t.Accesses[i];\r
+\r
+                       if (a->Id == GetParamInt(o, "[id]"))\r
+                       {\r
+                               b = true;\r
+\r
+                               a->Active = true;\r
+                       }\r
+               }\r
+\r
+               if (b == false)\r
+               {\r
+                       // 指定した ID が見つからない\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       FreeRpcEnumAccessList(&t);\r
+                       return ret;\r
+               }\r
+\r
+               ret = ScSetAccessList(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcEnumAccessList(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// アクセス リストのルールの無効化\r
+UINT PsAccessDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_ACCESS_LIST t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_Access_Prompt_ID"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumAccess(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+               bool b = false;\r
+               for (i = 0;i < t.NumAccess;i++)\r
+               {\r
+                       ACCESS *a = &t.Accesses[i];\r
+\r
+                       if (a->Id == GetParamInt(o, "[id]"))\r
+                       {\r
+                               b = true;\r
+\r
+                               a->Active = false;\r
+                       }\r
+               }\r
+\r
+               if (b == false)\r
+               {\r
+                       // 指定した ID が見つからない\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       FreeRpcEnumAccessList(&t);\r
+                       return ret;\r
+               }\r
+\r
+               ret = ScSetAccessList(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               FreeRpcEnumAccessList(&t);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザー一覧の取得\r
+UINT PsUserList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_USER t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+               CT *ct = CtNew();\r
+\r
+               CtInsertColumn(ct, _UU("SM_USER_COLUMN_1"), false);\r
+               CtInsertColumn(ct, _UU("SM_USER_COLUMN_2"), false);\r
+               CtInsertColumn(ct, _UU("SM_USER_COLUMN_3"), false);\r
+               CtInsertColumn(ct, _UU("SM_USER_COLUMN_4"), false);\r
+               CtInsertColumn(ct, _UU("SM_USER_COLUMN_5"), false);\r
+               CtInsertColumn(ct, _UU("SM_USER_COLUMN_6"), false);\r
+               CtInsertColumn(ct, _UU("SM_USER_COLUMN_7"), false);\r
+\r
+               for (i = 0;i < t.NumUser;i++)\r
+               {\r
+                       RPC_ENUM_USER_ITEM *e = &t.Users[i];\r
+                       wchar_t name[MAX_SIZE];\r
+                       wchar_t group[MAX_SIZE];\r
+                       wchar_t num[MAX_SIZE];\r
+                       wchar_t time[MAX_SIZE];\r
+\r
+                       StrToUni(name, sizeof(name), e->Name);\r
+\r
+                       if (StrLen(e->GroupName) != 0)\r
+                       {\r
+                               StrToUni(group, sizeof(group), e->GroupName);\r
+                       }\r
+                       else\r
+                       {\r
+                               UniStrCpy(group, sizeof(group), _UU("SM_NO_GROUP"));\r
+                       }\r
+\r
+                       UniToStru(num, e->NumLogin);\r
+\r
+                       GetDateTimeStrEx64(time, sizeof(time), SystemToLocal64(e->LastLoginTime), NULL);\r
+\r
+                       CtInsert(ct,\r
+                               name, e->Realname, group, e->Note, GetAuthTypeStr(e->AuthType),\r
+                               num, time);\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcEnumUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザー認証方法の文字列の取得\r
+wchar_t *GetAuthTypeStr(UINT id)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       Format(tmp, sizeof(tmp), "SM_AUTHTYPE_%u", id);\r
+\r
+       return _UU(tmp);\r
+}\r
+\r
+// ユーザーの作成\r
+UINT PsUserCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"GROUP", CmdPrompt, _UU("CMD_UserCreate_Prompt_GROUP"), NULL, NULL},\r
+               {"REALNAME", CmdPrompt, _UU("CMD_UserCreate_Prompt_REALNAME"), NULL, NULL},\r
+               {"NOTE", CmdPrompt, _UU("CMD_UserCreate_Prompt_NOTE"), NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+       StrCpy(t.GroupName, sizeof(t.GroupName), GetParamStr(o, "GROUP"));\r
+       UniStrCpy(t.Realname, sizeof(t.Realname), GetParamUniStr(o, "REALNAME"));\r
+       UniStrCpy(t.Note, sizeof(t.Note), GetParamUniStr(o, "NOTE"));\r
+\r
+       Trim(t.Name);\r
+       if (StrCmpi(t.Name, "*") == 0)\r
+       {\r
+               t.AuthType = AUTHTYPE_RADIUS;\r
+               t.AuthData = NewRadiusAuthData(NULL);\r
+       }\r
+       else\r
+       {\r
+               UCHAR random_pass[SHA1_SIZE];\r
+\r
+               Rand(random_pass, sizeof(random_pass));\r
+               t.AuthType = AUTHTYPE_PASSWORD;\r
+               t.AuthData = NewPasswordAuthDataRaw(random_pass);\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       ret = ScCreateUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザー情報の変更\r
+UINT PsUserSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"GROUP", CmdPrompt, _UU("CMD_UserCreate_Prompt_GROUP"), NULL, NULL},\r
+               {"REALNAME", CmdPrompt, _UU("CMD_UserCreate_Prompt_REALNAME"), NULL, NULL},\r
+               {"NOTE", CmdPrompt, _UU("CMD_UserCreate_Prompt_NOTE"), NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       // ユーザーオブジェクトを取得\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 情報を更新する\r
+       StrCpy(t.GroupName, sizeof(t.GroupName), GetParamStr(o, "GROUP"));\r
+       UniStrCpy(t.Realname, sizeof(t.Realname), GetParamUniStr(o, "REALNAME"));\r
+       UniStrCpy(t.Note, sizeof(t.Note), GetParamUniStr(o, "NOTE"));\r
+\r
+       // ユーザーオブジェクトを書き込み\r
+       ret = ScSetUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザーの削除\r
+UINT PsUserDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_DELETE_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDeleteUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザー情報の取得\r
+UINT PsUserGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       // ユーザーオブジェクトを取得\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               CT *ct;\r
+\r
+               // ユーザーデータを表示\r
+               ct = CtNewStandard();\r
+\r
+               // ユーザー名\r
+               StrToUni(tmp, sizeof(tmp), t.Name);\r
+               CtInsert(ct, _UU("CMD_UserGet_Column_Name"), tmp);\r
+\r
+               // 本名\r
+               CtInsert(ct, _UU("CMD_UserGet_Column_RealName"), t.Realname);\r
+\r
+               // 説明\r
+               CtInsert(ct, _UU("CMD_UserGet_Column_Note"), t.Note);\r
+\r
+               // グループ名\r
+               if (IsEmptyStr(t.GroupName) == false)\r
+               {\r
+                       StrToUni(tmp, sizeof(tmp), t.GroupName);\r
+                       CtInsert(ct, _UU("CMD_UserGet_Column_Group"), tmp);\r
+               }\r
+\r
+               // 有効期限\r
+               GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.ExpireTime), NULL);\r
+               CtInsert(ct, _UU("CMD_UserGet_Column_Expires"), tmp);\r
+\r
+               // 認証方法\r
+               CtInsert(ct, _UU("CMD_UserGet_Column_AuthType"), GetAuthTypeStr(t.AuthType));\r
+\r
+               switch (t.AuthType)\r
+               {\r
+               case AUTHTYPE_USERCERT:\r
+                       if (t.AuthData != NULL)\r
+                       {\r
+                               AUTHUSERCERT *auc = (AUTHUSERCERT *)t.AuthData;\r
+\r
+                               if (auc != NULL && auc->UserX != NULL)\r
+                               {\r
+                                       // 登録済みユーザー固有証明書\r
+                                       GetAllNameFromX(tmp, sizeof(tmp), auc->UserX);\r
+                                       CtInsert(ct, _UU("CMD_UserGet_Column_UserCert"), tmp);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case AUTHTYPE_ROOTCERT:\r
+                       if (t.AuthData != NULL)\r
+                       {\r
+                               AUTHROOTCERT *arc = (AUTHROOTCERT *)t.AuthData;\r
+\r
+                               if (IsEmptyUniStr(arc->CommonName) == false)\r
+                               {\r
+                                       // 証明書の CN の値の限定\r
+                                       CtInsert(ct, _UU("CMD_UserGet_Column_RootCert_CN"), arc->CommonName);\r
+                               }\r
+\r
+                               if (arc->Serial != NULL && arc->Serial->size >= 1)\r
+                               {\r
+                                       char tmp2[MAX_SIZE];\r
+\r
+                                       // 証明書のシリアル番号の限定\r
+                                       BinToStrEx(tmp2, sizeof(tmp2), arc->Serial->data, arc->Serial->size);\r
+                                       StrToUni(tmp, sizeof(tmp), tmp2);\r
+                                       CtInsert(ct, _UU("CMD_UserGet_Column_RootCert_SERIAL"), tmp);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case AUTHTYPE_RADIUS:\r
+               case AUTHTYPE_NT:\r
+                       if (t.AuthData != NULL)\r
+                       {\r
+                               AUTHRADIUS *ar = (AUTHRADIUS *)t.AuthData;\r
+\r
+                               // 外部認証サーバーの認証ユーザー名\r
+                               if (IsEmptyUniStr(ar->RadiusUsername) == false)\r
+                               {\r
+                                       CtInsert(ct, _UU("CMD_UserGet_Column_RadiusAlias"), ar->RadiusUsername);\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+\r
+               CtInsert(ct, L"---", L"---");\r
+\r
+               GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.CreatedTime), NULL);\r
+               CtInsert(ct, _UU("SM_USERINFO_CREATE"), tmp);\r
+\r
+               GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.UpdatedTime), NULL);\r
+               CtInsert(ct, _UU("SM_USERINFO_UPDATE"), tmp);\r
+\r
+               CmdInsertTrafficInfo(ct, &t.Traffic);\r
+\r
+               UniToStru(tmp, t.NumLogin);\r
+               CtInsert(ct, _UU("SM_USERINFO_NUMLOGIN"), tmp);\r
+\r
+\r
+               CtFree(ct, c);\r
+\r
+               if (t.Policy != NULL)\r
+               {\r
+                       c->Write(c, L"");\r
+                       c->Write(c, _UU("CMD_UserGet_Policy"));\r
+                       PrintPolicy(c, t.Policy, false);\r
+               }\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザーの認証方法を匿名認証に設定\r
+UINT PsUserAnonymousSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       // ユーザーオブジェクトを取得\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 情報を更新する\r
+       FreeAuthData(t.AuthType, t.AuthData);\r
+\r
+       // 匿名認証に設定する\r
+       t.AuthType = AUTHTYPE_ANONYMOUS;\r
+       t.AuthData = NULL;\r
+\r
+       // ユーザーオブジェクトを書き込み\r
+       ret = ScSetUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザーの認証方法をパスワード認証に設定しパスワードを設定\r
+UINT PsUserPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       // ユーザーオブジェクトを取得\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 情報を更新する\r
+       FreeAuthData(t.AuthType, t.AuthData);\r
+\r
+       {\r
+               AUTHPASSWORD *pw;\r
+\r
+               pw = NewPasswordAuthData(t.Name, GetParamStr(o, "PASSWORD"));\r
+\r
+               // パスワード認証に設定する\r
+               t.AuthType = AUTHTYPE_PASSWORD;\r
+               t.AuthData = pw;\r
+       }\r
+\r
+       // ユーザーオブジェクトを書き込み\r
+       ret = ScSetUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザーの認証方法を固有証明書認証に設定し証明書を設定\r
+UINT PsUserCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       X *x;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"LOADCERT", CmdPrompt, _UU("CMD_LOADCERTPATH"), CmdEvalIsFile, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // 証明書を読み込む\r
+       x = FileToX(GetParamStr(o, "LOADCERT"));\r
+       if (x == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_LOADCERT_FAILED"));\r
+\r
+               FreeParamValueList(o);\r
+\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       // ユーザーオブジェクトを取得\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               FreeX(x);\r
+               return ret;\r
+       }\r
+\r
+       // 情報を更新する\r
+       FreeAuthData(t.AuthType, t.AuthData);\r
+\r
+       {\r
+               AUTHUSERCERT *c;\r
+\r
+               c = NewUserCertAuthData(x);\r
+\r
+               FreeX(x);\r
+\r
+               // パスワード認証に設定する\r
+               t.AuthType = AUTHTYPE_USERCERT;\r
+               t.AuthData = c;\r
+       }\r
+\r
+       // ユーザーオブジェクトを書き込み\r
+       ret = ScSetUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 固有証明書認証のユーザーの登録されている証明書の取得\r
+UINT PsUserCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       AUTHUSERCERT *a;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"SAVECERT", CmdPrompt, _UU("CMD_SAVECERTPATH"), NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       // ユーザーオブジェクトを取得\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       a = (AUTHUSERCERT *)t.AuthData;\r
+\r
+       if (t.AuthType != AUTHTYPE_USERCERT || a == NULL || a->UserX == NULL)\r
+       {\r
+               // ユーザーは固有証明書認証ではない\r
+               ret = ERR_INVALID_PARAMETER;\r
+\r
+               c->Write(c, _UU("CMD_UserCertGet_Not_Cert"));\r
+       }\r
+       else\r
+       {\r
+               if (XToFile(a->UserX, GetParamStr(o, "SAVECERT"), true) == false)\r
+               {\r
+                       c->Write(c, _UU("CMD_SAVECERT_FAILED"));\r
+               }\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザーの認証方法を署名済み証明書認証に設定\r
+UINT PsUserSignedSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"CN", CmdPrompt, _UU("CMD_UserSignedSet_Prompt_CN"), NULL, NULL},\r
+               {"SERIAL", CmdPrompt, _UU("CMD_UserSignedSet_Prompt_SERIAL"), NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       // ユーザーオブジェクトを取得\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 情報を更新する\r
+       FreeAuthData(t.AuthType, t.AuthData);\r
+\r
+       {\r
+               AUTHROOTCERT *c;\r
+               BUF *b;\r
+               X_SERIAL *serial = NULL;\r
+\r
+               b = StrToBin(GetParamStr(o, "SERIAL"));\r
+\r
+               if (b != NULL && b->Size >= 1)\r
+               {\r
+                       serial = NewXSerial(b->Buf, b->Size);\r
+               }\r
+\r
+               FreeBuf(b);\r
+\r
+               c = NewRootCertAuthData(serial, GetParamUniStr(o, "CN"));\r
+\r
+               FreeXSerial(serial);\r
+\r
+               // パスワード認証に設定する\r
+               t.AuthType = AUTHTYPE_ROOTCERT;\r
+               t.AuthData = c;\r
+       }\r
+\r
+       // ユーザーオブジェクトを書き込み\r
+       ret = ScSetUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザーの認証方法を Radius 認証に設定\r
+UINT PsUserRadiusSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"ALIAS", CmdPrompt, _UU("CMD_UserRadiusSet_Prompt_ALIAS"), NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       // ユーザーオブジェクトを取得\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 情報を更新する\r
+       FreeAuthData(t.AuthType, t.AuthData);\r
+\r
+       {\r
+               AUTHRADIUS *a;\r
+\r
+               a = NewRadiusAuthData(GetParamUniStr(o, "ALIAS"));\r
+\r
+               // Radius 認証に設定する\r
+               t.AuthType = AUTHTYPE_RADIUS;\r
+               t.AuthData = a;\r
+       }\r
+\r
+       // ユーザーオブジェクトを書き込み\r
+       ret = ScSetUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザーの認証方法を NT ドメイン認証に設定\r
+UINT PsUserNTLMSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"ALIAS", CmdPrompt, _UU("CMD_UserRadiusSet_Prompt_ALIAS"), NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       // ユーザーオブジェクトを取得\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 情報を更新する\r
+       FreeAuthData(t.AuthType, t.AuthData);\r
+\r
+       {\r
+               AUTHRADIUS *a;\r
+\r
+               a = NewRadiusAuthData(GetParamUniStr(o, "ALIAS"));\r
+\r
+               // NT ドメイン認証に設定する\r
+               t.AuthType = AUTHTYPE_NT;\r
+               t.AuthData = a;\r
+       }\r
+\r
+       // ユーザーオブジェクトを書き込み\r
+       ret = ScSetUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザーのセキュリティ ポリシーの削除\r
+UINT PsUserPolicyRemove(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       // ユーザーオブジェクトを取得\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 更新\r
+       if (t.Policy != NULL)\r
+       {\r
+               Free(t.Policy);\r
+               t.Policy = NULL;\r
+       }\r
+\r
+       // ユーザーオブジェクトを書き込み\r
+       ret = ScSetUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザーのセキュリティ ポリシーの設定\r
+UINT PsUserPolicySet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"NAME", CmdPrompt, _UU("CMD_CascadePolicySet_PROMPT_POLNAME"), CmdEvalNotEmpty, NULL},\r
+               {"VALUE", CmdPrompt, _UU("CMD_CascadePolicySet_PROMPT_POLVALUE"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       // ユーザーオブジェクトを取得\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 更新\r
+       if (t.Policy == NULL)\r
+       {\r
+               t.Policy = ClonePolicy(GetDefaultPolicy());\r
+       }\r
+\r
+       // 編集\r
+       if (EditPolicy(c, t.Policy, GetParamStr(o, "NAME"), GetParamStr(o, "VALUE"), false) == false)\r
+       {\r
+               ret = ERR_INVALID_PARAMETER;\r
+       }\r
+       else\r
+       {\r
+               // ユーザーオブジェクトを書き込み\r
+               ret = ScSetUser(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 文字列を日時に変換\r
+UINT64 StrToDateTime64(char *str)\r
+{\r
+       UINT64 ret = 0;\r
+       TOKEN_LIST *t;\r
+       UINT a, b, c, d, e, f;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       if (IsEmptyStr(str) || StrCmpi(str, "none") == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       t = ParseToken(str, ":/,. \"");\r
+       if (t->NumTokens != 6)\r
+       {\r
+               FreeToken(t);\r
+               return INFINITE;\r
+       }\r
+\r
+       a = ToInt(t->Token[0]);\r
+       b = ToInt(t->Token[1]);\r
+       c = ToInt(t->Token[2]);\r
+       d = ToInt(t->Token[3]);\r
+       e = ToInt(t->Token[4]);\r
+       f = ToInt(t->Token[5]);\r
+\r
+       ret = INFINITE;\r
+\r
+       if (a >= 1000 && a <= 9999 && b >= 1 && b <= 12 && c >= 1 && c <= 31 &&\r
+               d >= 0 && d <= 23 && e >= 0 && e <= 59 && f >= 0 && f <= 59)\r
+       {\r
+               SYSTEMTIME t;\r
+\r
+               Zero(&t, sizeof(t));\r
+               t.wYear = a;\r
+               t.wMonth = b;\r
+               t.wDay = c;\r
+               t.wHour = d;\r
+               t.wMinute = e;\r
+               t.wSecond = f;\r
+\r
+               ret = SystemToUINT64(&t);\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// 日時文字列の評価\r
+bool CmdEvalDateTime(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       UINT64 ret;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       ret = StrToDateTime64(tmp);\r
+\r
+       if (ret == INFINITE)\r
+       {\r
+               c->Write(c, _UU("CMD_EVAL_DATE_TIME_FAILED"));\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ユーザーの有効期限の設定\r
+UINT PsUserExpiresSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       UINT64 expires;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"EXPIRES", CmdPrompt, _UU("CMD_UserExpiresSet_Prompt_EXPIRES"), CmdEvalDateTime, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       // ユーザーオブジェクトを取得\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 情報を更新する\r
+       expires = StrToDateTime64(GetParamStr(o, "EXPIRES"));\r
+\r
+       if (expires != 0)\r
+       {\r
+               expires = LocalToSystem64(expires);\r
+       }\r
+\r
+       t.ExpireTime = expires;\r
+\r
+       // ユーザーオブジェクトを書き込み\r
+       ret = ScSetUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// グループ一覧の取得\r
+UINT PsGroupList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_GROUP t;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumGroup(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNew();\r
+               UINT i;\r
+\r
+               CtInsertColumn(ct, _UU("SM_GROUPLIST_NAME"), false);\r
+               CtInsertColumn(ct, _UU("SM_GROUPLIST_REALNAME"), false);\r
+               CtInsertColumn(ct, _UU("SM_GROUPLIST_NOTE"), false);\r
+               CtInsertColumn(ct, _UU("SM_GROUPLIST_NUMUSERS"), false);\r
+\r
+               for (i = 0;i < t.NumGroup;i++)\r
+               {\r
+                       wchar_t tmp1[MAX_SIZE];\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       RPC_ENUM_GROUP_ITEM *e = &t.Groups[i];\r
+\r
+                       StrToUni(tmp1, sizeof(tmp1), e->Name);\r
+                       UniToStru(tmp2, e->NumUsers);\r
+\r
+                       CtInsert(ct, tmp1, e->Realname, e->Note, tmp2);\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcEnumGroup(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// グループの作成\r
+UINT PsGroupCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_GROUP t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"REALNAME", CmdPrompt, _UU("CMD_GroupCreate_Prompt_REALNAME"), NULL, NULL},\r
+               {"NOTE", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NOTE"), NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+       UniStrCpy(t.Realname, sizeof(t.Realname), GetParamUniStr(o, "REALNAME"));\r
+       UniStrCpy(t.Note, sizeof(t.Note), GetParamUniStr(o, "NOTE"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScCreateGroup(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcSetGroup(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// グループ情報の設定\r
+UINT PsGroupSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_GROUP t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"REALNAME", CmdPrompt, _UU("CMD_GroupCreate_Prompt_REALNAME"), NULL, NULL},\r
+               {"NOTE", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NOTE"), NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetGroup(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       // 情報更新\r
+       UniStrCpy(t.Realname, sizeof(t.Realname), GetParamUniStr(o, "REALNAME"));\r
+       UniStrCpy(t.Note, sizeof(t.Note), GetParamUniStr(o, "NOTE"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScSetGroup(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcSetGroup(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// グループの削除\r
+UINT PsGroupDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_DELETE_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDeleteGroup(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// グループ情報と所属しているユーザー一覧の取得\r
+UINT PsGroupGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_GROUP t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetGroup(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               char groupname[MAX_USERNAME_LEN + 1];\r
+               CT *ct = CtNewStandard();\r
+\r
+               StrCpy(groupname, sizeof(groupname), t.Name);\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.Name);\r
+               CtInsert(ct, _UU("CMD_GroupGet_Column_NAME"), tmp);\r
+               CtInsert(ct, _UU("CMD_GroupGet_Column_REALNAME"), t.Realname);\r
+               CtInsert(ct, _UU("CMD_GroupGet_Column_NOTE"), t.Note);\r
+\r
+               CtFree(ct, c);\r
+\r
+               if (t.Policy != NULL)\r
+               {\r
+                       c->Write(c, L"");\r
+                       c->Write(c, _UU("CMD_GroupGet_Column_POLICY"));\r
+\r
+                       PrintPolicy(c, t.Policy, false);\r
+               }\r
+\r
+               {\r
+                       RPC_ENUM_USER t;\r
+                       bool b = false;\r
+\r
+                       Zero(&t, sizeof(t));\r
+\r
+                       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+                       if (ScEnumUser(ps->Rpc, &t) == ERR_NO_ERROR)\r
+                       {\r
+                               UINT i;\r
+\r
+                               for (i = 0;i < t.NumUser;i++)\r
+                               {\r
+                                       RPC_ENUM_USER_ITEM *u = &t.Users[i];\r
+\r
+                                       if (StrCmpi(u->GroupName, groupname) == 0)\r
+                                       {\r
+                                               if (b == false)\r
+                                               {\r
+                                                       b = true;\r
+                                                       c->Write(c, L"");\r
+                                                       c->Write(c, _UU("CMD_GroupGet_Column_MEMBERS"));\r
+                                               }\r
+\r
+                                               UniFormat(tmp, sizeof(tmp), L" %S", u->Name);\r
+                                               c->Write(c, tmp);\r
+                                       }\r
+                               }\r
+                               FreeRpcEnumUser(&t);\r
+\r
+                               if (b)\r
+                               {\r
+                                       c->Write(c, L"");\r
+                               }\r
+                       }\r
+               }\r
+\r
+       }\r
+\r
+       FreeRpcSetGroup(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// グループにユーザーを追加\r
+UINT PsGroupJoin(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"USERNAME", CmdPrompt, _UU("CMD_GroupJoin_Prompt_USERNAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "USERNAME"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // グループの更新\r
+               StrCpy(t.GroupName, sizeof(t.GroupName), GetParamStr(o, "[name]"));\r
+\r
+               ret = ScSetUser(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// グループからユーザーを削除\r
+UINT PsGroupUnjoin(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_USER t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_GroupUnjoin_Prompt_name"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetUser(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // グループの更新\r
+               StrCpy(t.GroupName, sizeof(t.GroupName), "");\r
+\r
+               ret = ScSetUser(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// グループのセキュリティ ポリシーの削除\r
+UINT PsGroupPolicyRemove(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_GROUP t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetGroup(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // 更新\r
+               if (t.Policy != NULL)\r
+               {\r
+                       Free(t.Policy);\r
+                       t.Policy = NULL;\r
+               }\r
+\r
+               ret = ScSetGroup(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       FreeRpcSetGroup(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// グループのセキュリティ ポリシーの設定\r
+UINT PsGroupPolicySet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SET_GROUP t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+               {"NAME", CmdPrompt, _UU("CMD_CascadePolicySet_PROMPT_POLNAME"), CmdEvalNotEmpty, NULL},\r
+               {"VALUE", CmdPrompt, _UU("CMD_CascadePolicySet_PROMPT_POLVALUE"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetGroup(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // 更新\r
+               if (t.Policy == NULL)\r
+               {\r
+                       t.Policy = ClonePolicy(GetDefaultPolicy());\r
+               }\r
+\r
+               if (EditPolicy(c, t.Policy, GetParamStr(o, "NAME"), GetParamStr(o, "VALUE"), false) == false)\r
+               {\r
+                       // エラー発生\r
+                       FreeRpcSetGroup(&t);\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ERR_INTERNAL_ERROR;\r
+               }\r
+\r
+               ret = ScSetGroup(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       FreeRpcSetGroup(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 接続中のセッション一覧の取得\r
+UINT PsSessionList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_SESSION t;\r
+       UINT server_type = 0;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       {\r
+               // サーバー種類の取得\r
+               RPC_SERVER_INFO t;\r
+\r
+               Zero(&t, sizeof(t));\r
+\r
+               if (ScGetServerInfo(ps->Rpc, &t) == ERR_NO_ERROR)\r
+               {\r
+                       server_type = t.ServerType;\r
+\r
+                       FreeRpcServerInfo(&t);\r
+               }\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumSession(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNew();\r
+               UINT i;\r
+\r
+               CtInsertColumn(ct, _UU("SM_SESS_COLUMN_1"), false);\r
+               CtInsertColumn(ct, _UU("SM_SESS_COLUMN_8"), false);\r
+               CtInsertColumn(ct, _UU("SM_SESS_COLUMN_2"), false);\r
+               CtInsertColumn(ct, _UU("SM_SESS_COLUMN_3"), false);\r
+               CtInsertColumn(ct, _UU("SM_SESS_COLUMN_4"), false);\r
+               CtInsertColumn(ct, _UU("SM_SESS_COLUMN_5"), true);\r
+               CtInsertColumn(ct, _UU("SM_SESS_COLUMN_6"), true);\r
+               CtInsertColumn(ct, _UU("SM_SESS_COLUMN_7"), true);\r
+\r
+               for (i = 0;i < t.NumSession;i++)\r
+               {\r
+                       RPC_ENUM_SESSION_ITEM *e = &t.Sessions[i];\r
+                       wchar_t tmp1[MAX_SIZE];\r
+                       wchar_t *tmp2;\r
+                       wchar_t tmp3[MAX_SIZE];\r
+                       wchar_t tmp4[MAX_SIZE];\r
+                       wchar_t tmp5[MAX_SIZE];\r
+                       wchar_t tmp6[MAX_SIZE];\r
+                       wchar_t tmp7[MAX_SIZE];\r
+                       wchar_t tmp8[MAX_SIZE];\r
+                       bool free_tmp2 = false;\r
+\r
+                       StrToUni(tmp1, sizeof(tmp1), e->Name);\r
+\r
+                       tmp2 = _UU("SM_SESS_NORMAL");\r
+                       if (server_type != SERVER_TYPE_STANDALONE)\r
+                       {\r
+                               if (e->RemoteSession)\r
+                               {\r
+                                       tmp2 = ZeroMalloc(MAX_SIZE);\r
+                                       UniFormat(tmp2, MAX_SIZE, _UU("SM_SESS_REMOTE"), e->RemoteHostname);\r
+                                       free_tmp2 = true;\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (StrLen(e->RemoteHostname) == 0)\r
+                                       {\r
+                                               tmp2 = _UU("SM_SESS_LOCAL");\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               tmp2 = ZeroMalloc(MAX_SIZE);\r
+                                               UniFormat(tmp2, MAX_SIZE, _UU("SM_SESS_LOCAL_2"), e->RemoteHostname);\r
+                                               free_tmp2 = true;\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (e->LinkMode)\r
+                       {\r
+                               if (free_tmp2)\r
+                               {\r
+                                       Free(tmp2);\r
+                                       free_tmp2 = false;\r
+                               }\r
+                               tmp2 = _UU("SM_SESS_LINK");\r
+                       }\r
+                       else if (e->SecureNATMode)\r
+                       {\r
+                               /*if (free_tmp2)\r
+                               {\r
+                                       Free(tmp2);\r
+                                       free_tmp2 = false;\r
+                               }*/\r
+                               tmp2 = _UU("SM_SESS_SNAT");\r
+                       }\r
+\r
+                       StrToUni(tmp3, sizeof(tmp3), e->Username);\r
+\r
+                       StrToUni(tmp4, sizeof(tmp4), e->Hostname);\r
+                       if (e->LinkMode)\r
+                       {\r
+                               UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_SESS_LINK_HOSTNAME"));\r
+                       }\r
+                       else if (e->SecureNATMode)\r
+                       {\r
+                               UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_SESS_SNAT_HOSTNAME"));\r
+                       }\r
+                       else if (e->BridgeMode)\r
+                       {\r
+                               UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_SESS_BRIDGE_HOSTNAME"));\r
+                       }\r
+                       else if (StartWith(e->Username, L3_USERNAME))\r
+                       {\r
+                               UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_SESS_LAYER3_HOSTNAME"));\r
+                       }\r
+\r
+                       UniFormat(tmp5, sizeof(tmp5), L"%u / %u", e->CurrentNumTcp, e->MaxNumTcp);\r
+                       if (e->LinkMode)\r
+                       {\r
+                               UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_SESS_LINK_TCP"));\r
+                       }\r
+                       else if (e->SecureNATMode)\r
+                       {\r
+                               UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_SESS_SNAT_TCP"));\r
+                       }\r
+                       else if (e->BridgeMode)\r
+                       {\r
+                               UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_SESS_BRIDGE_TCP"));\r
+                       }\r
+\r
+                       UniToStr3(tmp6, sizeof(tmp6), e->PacketSize);\r
+                       UniToStr3(tmp7, sizeof(tmp7), e->PacketNum);\r
+\r
+                       if (e->VLanId == 0)\r
+                       {\r
+                               UniStrCpy(tmp8, sizeof(tmp8), _UU("CM_ST_NO_VLAN"));\r
+                       }\r
+                       else\r
+                       {\r
+                               UniToStru(tmp8, e->VLanId);\r
+                       }\r
+\r
+                       CtInsert(ct, tmp1, tmp8, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7);\r
+\r
+                       if (free_tmp2)\r
+                       {\r
+                               Free(tmp2);\r
+                       }\r
+               }\r
+\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcEnumSession(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// NODE_INFO の表示\r
+void CmdPrintNodeInfo(CT *ct, NODE_INFO *info)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       char str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (ct == NULL || info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrToUni(tmp, sizeof(tmp), info->ClientProductName);\r
+       CtInsert(ct, _UU("SM_NODE_CLIENT_NAME"), tmp);\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"%u.%02u", Endian32(info->ClientProductVer) / 100, Endian32(info->ClientProductVer) % 100);\r
+       CtInsert(ct, _UU("SM_NODE_CLIENT_VER"), tmp);\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"Build %u", Endian32(info->ClientProductBuild));\r
+       CtInsert(ct, _UU("SM_NODE_CLIENT_BUILD"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), info->ClientOsName);\r
+       CtInsert(ct, _UU("SM_NODE_CLIENT_OS_NAME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), info->ClientOsVer);\r
+       CtInsert(ct, _UU("SM_NODE_CLIENT_OS_VER"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), info->ClientOsProductId);\r
+       CtInsert(ct, _UU("SM_NODE_CLIENT_OS_PID"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), info->ClientHostname);\r
+       CtInsert(ct, _UU("SM_NODE_CLIENT_HOST"), tmp);\r
+\r
+       IPToStr4or6(str, sizeof(str), info->ClientIpAddress, info->ClientIpAddress6);\r
+       StrToUni(tmp, sizeof(tmp), str);\r
+       CtInsert(ct, _UU("SM_NODE_CLIENT_IP"), tmp);\r
+\r
+       UniToStru(tmp, Endian32(info->ClientPort));\r
+       CtInsert(ct, _UU("SM_NODE_CLIENT_PORT"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), info->ServerHostname);\r
+       CtInsert(ct, _UU("SM_NODE_SERVER_HOST"), tmp);\r
+\r
+       IPToStr4or6(str, sizeof(str), info->ServerIpAddress, info->ServerIpAddress6);\r
+       StrToUni(tmp, sizeof(tmp), str);\r
+       CtInsert(ct, _UU("SM_NODE_SERVER_IP"), tmp);\r
+\r
+       UniToStru(tmp, Endian32(info->ServerPort));\r
+       CtInsert(ct, _UU("SM_NODE_SERVER_PORT"), tmp);\r
+\r
+       if (StrLen(info->ProxyHostname) != 0)\r
+       {\r
+               StrToUni(tmp, sizeof(tmp), info->ProxyHostname);\r
+               CtInsert(ct, _UU("SM_NODE_PROXY_HOSTNAME"), tmp);\r
+\r
+               IPToStr4or6(str, sizeof(str), info->ProxyIpAddress, info->ProxyIpAddress6);\r
+               StrToUni(tmp, sizeof(tmp), str);\r
+               CtInsert(ct, _UU("SM_NODE_PROXY_IP"), tmp);\r
+\r
+               UniToStru(tmp, Endian32(info->ProxyPort));\r
+               CtInsert(ct, _UU("SM_NODE_PROXY_PORT"), tmp);\r
+       }\r
+}\r
+\r
+// セッション情報の取得\r
+UINT PsSessionGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_SESSION_STATUS t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_SessionGet_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSessionStatus(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               char str[MAX_SIZE];\r
+               CT *ct = CtNewStandard();\r
+\r
+               if (t.ClientIp != 0)\r
+               {\r
+                       IPToStr4or6(str, sizeof(str), t.ClientIp, t.ClientIp6);\r
+                       StrToUni(tmp, sizeof(tmp), str);\r
+                       CtInsert(ct, _UU("SM_CLIENT_IP"), tmp);\r
+               }\r
+\r
+               if (StrLen(t.ClientHostName) != 0)\r
+               {\r
+                       StrToUni(tmp, sizeof(tmp), t.ClientHostName);\r
+                       CtInsert(ct, _UU("SM_CLIENT_HOSTNAME"), tmp);\r
+               }\r
+\r
+               StrToUni(tmp, sizeof(tmp), t.Username);\r
+               CtInsert(ct, _UU("SM_SESS_STATUS_USERNAME"), tmp);\r
+\r
+               if (StrCmpi(t.Username, LINK_USER_NAME_PRINT) != 0 && StrCmpi(t.Username, SNAT_USER_NAME_PRINT) != 0 && StrCmpi(t.Username, BRIDGE_USER_NAME_PRINT) != 0)\r
+               {\r
+                       StrToUni(tmp, sizeof(tmp), t.RealUsername);\r
+                       CtInsert(ct, _UU("SM_SESS_STATUS_REALUSER"), tmp);\r
+               }\r
+\r
+               if (IsEmptyStr(t.GroupName) == false)\r
+               {\r
+                       StrToUni(tmp, sizeof(tmp), t.GroupName);\r
+                       CtInsert(ct, _UU("SM_SESS_STATUS_GROUPNAME"), tmp);\r
+               }\r
+\r
+\r
+               CmdPrintStatusToListViewEx(ct, &t.Status, true);\r
+\r
+               if (StrCmpi(t.Username, LINK_USER_NAME_PRINT) != 0 && StrCmpi(t.Username, SNAT_USER_NAME_PRINT) != 0 && StrCmpi(t.Username, BRIDGE_USER_NAME_PRINT) != 0 &&\r
+                       StartWith(t.Username, L3_USERNAME) == false)\r
+               {\r
+                       CmdPrintNodeInfo(ct, &t.NodeInfo);\r
+               }\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeRpcSessionStatus(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// セッションの切断\r
+UINT PsSessionDisconnect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_DELETE_SESSION t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_SessionGet_Prompt_NAME"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDeleteSession(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// MAC アドレス テーブル データベースの取得\r
+UINT PsMacTable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_MAC_TABLE t;\r
+       UINT i;\r
+\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[session_name]", NULL, NULL, NULL, NULL,}\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumMacTable(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNew();\r
+               char *session_name = GetParamStr(o, "[session_name]");\r
+\r
+               if (IsEmptyStr(session_name))\r
+               {\r
+                       session_name = NULL;\r
+               }\r
+\r
+               CtInsertColumn(ct, _UU("CMD_ID"), false);\r
+               CtInsertColumn(ct, _UU("SM_MAC_COLUMN_1"), false);\r
+               CtInsertColumn(ct, _UU("SM_MAC_COLUMN_1A"), false);\r
+               CtInsertColumn(ct, _UU("SM_MAC_COLUMN_2"), false);\r
+               CtInsertColumn(ct, _UU("SM_MAC_COLUMN_3"), false);\r
+               CtInsertColumn(ct, _UU("SM_MAC_COLUMN_4"), false);\r
+               CtInsertColumn(ct, _UU("SM_MAC_COLUMN_5"), false);\r
+\r
+               for (i = 0;i < t.NumMacTable;i++)\r
+               {\r
+                       char str[MAX_SIZE];\r
+                       wchar_t tmp0[128];\r
+                       wchar_t tmp1[MAX_SIZE];\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       wchar_t tmp3[MAX_SIZE];\r
+                       wchar_t tmp4[MAX_SIZE];\r
+                       wchar_t tmp5[MAX_SIZE];\r
+                       wchar_t tmp6[MAX_SIZE];\r
+\r
+                       RPC_ENUM_MAC_TABLE_ITEM *e = &t.MacTables[i];\r
+\r
+                       if (session_name == NULL || StrCmpi(e->SessionName, session_name) == 0)\r
+                       {\r
+                               UniToStru(tmp0, e->Key);\r
+\r
+                               StrToUni(tmp1, sizeof(tmp1), e->SessionName);\r
+\r
+                               MacToStr(str, sizeof(str), e->MacAddress);\r
+                               StrToUni(tmp2, sizeof(tmp2), str);\r
+\r
+                               GetDateTimeStr64Uni(tmp3, sizeof(tmp3), SystemToLocal64(e->CreatedTime));\r
+\r
+                               GetDateTimeStr64Uni(tmp4, sizeof(tmp4), SystemToLocal64(e->UpdatedTime));\r
+\r
+                               if (StrLen(e->RemoteHostname) == 0)\r
+                               {\r
+                                       UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_MACIP_LOCAL"));\r
+                               }\r
+                               else\r
+                               {\r
+                                       UniFormat(tmp5, sizeof(tmp5), _UU("SM_MACIP_SERVER"), e->RemoteHostname);\r
+                               }\r
+\r
+                               UniToStru(tmp6, e->VlanId);\r
+                               if (e->VlanId == 0)\r
+                               {\r
+                                       UniStrCpy(tmp6, sizeof(tmp6), _UU("CM_ST_NONE"));\r
+                               }\r
+\r
+                               CtInsert(ct,\r
+                                       tmp0, tmp1, tmp6, tmp2, tmp3, tmp4, tmp5);\r
+                       }\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcEnumMacTable(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// MAC アドレス テーブル エントリの削除\r
+UINT PsMacDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_DELETE_TABLE t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_MacDelete_Prompt"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.Key = GetParamInt(o, "[id]");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDeleteMacTable(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// IP アドレス テーブル データベースの取得\r
+UINT PsIpTable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_IP_TABLE t;\r
+       UINT i;\r
+\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[session_name]", NULL, NULL, NULL, NULL,}\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumIpTable(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNew();\r
+               char *session_name = GetParamStr(o, "[session_name]");\r
+\r
+               if (IsEmptyStr(session_name))\r
+               {\r
+                       session_name = NULL;\r
+               }\r
+\r
+               CtInsertColumn(ct, _UU("CMD_ID"), false);\r
+               CtInsertColumn(ct, _UU("SM_IP_COLUMN_1"), false);\r
+               CtInsertColumn(ct, _UU("SM_IP_COLUMN_2"), false);\r
+               CtInsertColumn(ct, _UU("SM_IP_COLUMN_3"), false);\r
+               CtInsertColumn(ct, _UU("SM_IP_COLUMN_4"), false);\r
+               CtInsertColumn(ct, _UU("SM_IP_COLUMN_5"), false);\r
+\r
+               for (i = 0;i < t.NumIpTable;i++)\r
+               {\r
+                       char str[MAX_SIZE];\r
+                       wchar_t tmp0[128];\r
+                       wchar_t tmp1[MAX_SIZE];\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       wchar_t tmp3[MAX_SIZE];\r
+                       wchar_t tmp4[MAX_SIZE];\r
+                       wchar_t tmp5[MAX_SIZE];\r
+                       RPC_ENUM_IP_TABLE_ITEM *e = &t.IpTables[i];\r
+\r
+                       if (session_name == NULL || StrCmpi(e->SessionName, session_name) == 0)\r
+                       {\r
+                               UniToStru(tmp0, e->Key);\r
+\r
+                               StrToUni(tmp1, sizeof(tmp1), e->SessionName);\r
+\r
+                               if (e->DhcpAllocated == false)\r
+                               {\r
+                                       IPToStr(str, sizeof(str), &e->IpV6);\r
+                                       StrToUni(tmp2, sizeof(tmp2), str);\r
+                               }\r
+                               else\r
+                               {\r
+                                       IPToStr(str, sizeof(str), &e->IpV6);\r
+                                       UniFormat(tmp2, sizeof(tmp2), _UU("SM_MAC_IP_DHCP"), str);\r
+                               }\r
+\r
+                               GetDateTimeStr64Uni(tmp3, sizeof(tmp3), SystemToLocal64(e->CreatedTime));\r
+\r
+                               GetDateTimeStr64Uni(tmp4, sizeof(tmp4), SystemToLocal64(e->UpdatedTime));\r
+\r
+                               if (StrLen(e->RemoteHostname) == 0)\r
+                               {\r
+                                       UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_MACIP_LOCAL"));\r
+                               }\r
+                               else\r
+                               {\r
+                                       UniFormat(tmp5, sizeof(tmp5), _UU("SM_MACIP_SERVER"), e->RemoteHostname);\r
+                               }\r
+\r
+                               CtInsert(ct,\r
+                                       tmp0, tmp1, tmp2, tmp3, tmp4, tmp5);\r
+                       }\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcEnumIpTable(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// IP アドレス テーブル エントリの削除\r
+UINT PsIpDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_DELETE_TABLE t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_MacDelete_Prompt"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.Key = GetParamInt(o, "[id]");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDeleteIpTable(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 NAT および DHCP サーバー機能 (SecureNAT 機能) の有効化\r
+UINT PsSecureNatEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnableSecureNAT(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 NAT および DHCP サーバー機能 (SecureNAT 機能) の無効化\r
+UINT PsSecureNatDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_HUB t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDisableSecureNAT(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 NAT および DHCP サーバー機能 (SecureNAT 機能) の動作状況の取得\r
+UINT PsSecureNatStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_NAT_STATUS t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSecureNATStatus(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               CT *ct = CtNewStandard();\r
+\r
+               StrToUni(tmp, sizeof(tmp), ps->HubName);\r
+               CtInsert(ct, _UU("SM_HUB_COLUMN_1"), tmp);\r
+\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_SESSION"), t.NumTcpSessions);\r
+               CtInsert(ct, _UU("NM_STATUS_TCP"), tmp);\r
+\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_SESSION"), t.NumUdpSessions);\r
+               CtInsert(ct, _UU("NM_STATUS_UDP"), tmp);\r
+\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_CLIENT"), t.NumDhcpClients);\r
+               CtInsert(ct, _UU("NM_STATUS_DHCP"), tmp);\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeRpcNatStatus(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// SecureNAT 機能の仮想ホストのネットワーク インターフェイス設定の取得\r
+UINT PsSecureNatHostGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       VH_OPTION t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSecureNATOption(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               char str[MAX_SIZE];\r
+               CT *ct = CtNewStandard();\r
+\r
+               // 使用フラグ\r
+               // MAC アドレス\r
+               MacToStr(str, sizeof(str), t.MacAddress);\r
+               StrToUni(tmp, sizeof(tmp), str);\r
+               CtInsert(ct, _UU("CMD_SecureNatHostGet_Column_MAC"), tmp);\r
+\r
+               // IP アドレス\r
+               IPToUniStr(tmp, sizeof(tmp), &t.Ip);\r
+               CtInsert(ct, _UU("CMD_SecureNatHostGet_Column_IP"), tmp);\r
+\r
+               // サブネット マスク\r
+               IPToUniStr(tmp, sizeof(tmp), &t.Mask);\r
+               CtInsert(ct, _UU("CMD_SecureNatHostGet_Column_MASK"), tmp);\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// SecureNAT 機能の仮想ホストのネットワーク インターフェイス設定の変更\r
+UINT PsSecureNatHostSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       VH_OPTION t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"MAC", CmdPrompt, _UU("CMD_SecureNatHostSet_Prompt_MAC"), NULL, NULL},\r
+               {"IP", CmdPrompt, _UU("CMD_SecureNatHostSet_Prompt_IP"), CmdEvalIp, NULL},\r
+               {"MASK", CmdPrompt, _UU("CMD_SecureNatHostSet_Prompt_MASK"), CmdEvalIp, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSecureNATOption(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               char *mac, *ip, *mask;\r
+               bool ok = true;\r
+\r
+               StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+               mac = GetParamStr(o, "MAC");\r
+               ip = GetParamStr(o, "IP");\r
+               mask = GetParamStr(o, "MASK");\r
+\r
+               if (IsEmptyStr(mac) == false)\r
+               {\r
+                       BUF *b = StrToBin(mac);\r
+\r
+                       if (b == NULL || b->Size != 6)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+                       else\r
+                       {\r
+                               Copy(t.MacAddress, b->Buf, 6);\r
+                       }\r
+\r
+                       FreeBuf(b);\r
+               }\r
+\r
+               if (IsEmptyStr(ip) == false)\r
+               {\r
+                       if (IsIpStr4(ip) == false)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+                       else\r
+                       {\r
+                               UINT u = StrToIP32(ip);\r
+\r
+                               if (u == 0 || u == 0xffffffff)\r
+                               {\r
+                                       ok = false;\r
+                               }\r
+                               else\r
+                               {\r
+                                       UINTToIP(&t.Ip, u);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (IsEmptyStr(mask) == false)\r
+               {\r
+                       if (IsIpStr4(mask) == false)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+                       else\r
+                       {\r
+                               StrToIP(&t.Mask, mask);\r
+                       }\r
+               }\r
+\r
+               if (ok == false)\r
+               {\r
+                       // パラメータが不正\r
+                       ret = ERR_INVALID_PARAMETER;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+               else\r
+               {\r
+                       ret = ScSetSecureNATOption(ps->Rpc, &t);\r
+\r
+                       if (ret != ERR_NO_ERROR)\r
+                       {\r
+                               // エラー発生\r
+                               CmdPrintError(c, ret);\r
+                               FreeParamValueList(o);\r
+                               return ret;\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// SecureNAT 機能の仮想 NAT 機能の設定の取得\r
+UINT PsNatGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       VH_OPTION t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSecureNATOption(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               CT *ct = CtNewStandard();\r
+\r
+               // 仮想 NAT 機能を使用する\r
+               CtInsert(ct, _UU("CMD_NatGet_Column_USE"), t.UseNat ? _UU("SEC_YES") : _UU("SEC_NO"));\r
+\r
+               // MTU 値\r
+               UniToStru(tmp, t.Mtu);\r
+               CtInsert(ct, _UU("CMD_NetGet_Column_MTU"), tmp);\r
+\r
+               // TCP セッションのタイムアウト (秒)\r
+               UniToStru(tmp, t.NatTcpTimeout);\r
+               CtInsert(ct, _UU("CMD_NatGet_Column_TCP"), tmp);\r
+\r
+               // UDP セッションのタイムアウト (秒)\r
+               UniToStru(tmp, t.NatUdpTimeout);\r
+               CtInsert(ct, _UU("CMD_NatGet_Column_UDP"), tmp);\r
+\r
+               // ログ保存\r
+               CtInsert(ct, _UU("CMD_SecureNatHostGet_Column_LOG"), t.SaveLog ? _UU("SEC_YES") : _UU("SEC_NO"));\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// SecureNAT 機能の仮想 NAT 機能の有効化\r
+UINT PsNatEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       VH_OPTION t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSecureNATOption(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               bool ok = true;\r
+\r
+               t.UseNat = true;\r
+\r
+               if (ok == false)\r
+               {\r
+                       // パラメータが不正\r
+                       ret = ERR_INVALID_PARAMETER;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+               else\r
+               {\r
+                       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+                       ret = ScSetSecureNATOption(ps->Rpc, &t);\r
+\r
+                       if (ret != ERR_NO_ERROR)\r
+                       {\r
+                               // エラー発生\r
+                               CmdPrintError(c, ret);\r
+                               FreeParamValueList(o);\r
+                               return ret;\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// SecureNAT 機能の仮想 NAT 機能の無効化\r
+UINT PsNatDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       VH_OPTION t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSecureNATOption(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               bool ok = true;\r
+\r
+               t.UseNat = false;\r
+\r
+               if (ok == false)\r
+               {\r
+                       // パラメータが不正\r
+                       ret = ERR_INVALID_PARAMETER;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+               else\r
+               {\r
+                       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+                       ret = ScSetSecureNATOption(ps->Rpc, &t);\r
+\r
+                       if (ret != ERR_NO_ERROR)\r
+                       {\r
+                               // エラー発生\r
+                               CmdPrintError(c, ret);\r
+                               FreeParamValueList(o);\r
+                               return ret;\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// SecureNAT 機能の仮想 NAT 機能の設定の変更\r
+UINT PsNatSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       VH_OPTION t;\r
+       // 指定できるパラメータ リスト\r
+       CMD_EVAL_MIN_MAX mtu_mm =\r
+       {\r
+               "CMD_NatSet_Eval_MTU", TCP_HEADER_SIZE + IP_HEADER_SIZE + MAC_HEADER_SIZE + 8, MAX_L3_DATA_SIZE,\r
+       };\r
+       CMD_EVAL_MIN_MAX tcp_mm =\r
+       {\r
+               "CMD_NatSet_Eval_TCP", NAT_TCP_MIN_TIMEOUT / 1000, NAT_TCP_MAX_TIMEOUT / 1000,\r
+       };\r
+       CMD_EVAL_MIN_MAX udp_mm =\r
+       {\r
+               "CMD_NatSet_Eval_UDP", NAT_UDP_MIN_TIMEOUT / 1000, NAT_UDP_MAX_TIMEOUT / 1000,\r
+       };\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"MTU", CmdPrompt, _UU("CMD_NatSet_Prompt_MTU"), CmdEvalMinMax, &mtu_mm},\r
+               {"TCPTIMEOUT", CmdPrompt, _UU("CMD_NatSet_Prompt_TCPTIMEOUT"), CmdEvalMinMax, &tcp_mm},\r
+               {"UDPTIMEOUT", CmdPrompt, _UU("CMD_NatSet_Prompt_UDPTIMEOUT"), CmdEvalMinMax, &udp_mm},\r
+               {"LOG", CmdPrompt, _UU("CMD_NatSet_Prompt_LOG"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSecureNATOption(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               bool ok = true;\r
+\r
+               t.Mtu = GetParamInt(o, "MTU");\r
+               t.NatTcpTimeout = GetParamInt(o, "TCPTIMEOUT");\r
+               t.NatUdpTimeout = GetParamInt(o, "UDPTIMEOUT");\r
+               t.SaveLog = GetParamYes(o, "LOG");\r
+\r
+               if (ok == false)\r
+               {\r
+                       // パラメータが不正\r
+                       ret = ERR_INVALID_PARAMETER;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+               else\r
+               {\r
+                       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+                       ret = ScSetSecureNATOption(ps->Rpc, &t);\r
+\r
+                       if (ret != ERR_NO_ERROR)\r
+                       {\r
+                               // エラー発生\r
+                               CmdPrintError(c, ret);\r
+                               FreeParamValueList(o);\r
+                               return ret;\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// SecureNAT 機能の仮想 NAT 機能のセッション テーブルの取得\r
+UINT PsNatTable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_NAT t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumNAT(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNew();\r
+               UINT i;\r
+\r
+               CtInsertColumn(ct, _UU("NM_NAT_ID"), false);\r
+               CtInsertColumn(ct, _UU("NM_NAT_PROTOCOL"), false);\r
+               CtInsertColumn(ct, _UU("NM_NAT_SRC_HOST"), false);\r
+               CtInsertColumn(ct, _UU("NM_NAT_SRC_PORT"), false);\r
+               CtInsertColumn(ct, _UU("NM_NAT_DST_HOST"), false);\r
+               CtInsertColumn(ct, _UU("NM_NAT_DST_PORT"), false);\r
+               CtInsertColumn(ct, _UU("NM_NAT_CREATED"), false);\r
+               CtInsertColumn(ct, _UU("NM_NAT_LAST_COMM"), false);\r
+               CtInsertColumn(ct, _UU("NM_NAT_SIZE"), false);\r
+               CtInsertColumn(ct, _UU("NM_NAT_TCP_STATUS"), false);\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       RPC_ENUM_NAT_ITEM *e = &t.Items[i];\r
+                       wchar_t tmp0[MAX_SIZE];\r
+                       wchar_t *tmp1 = L"";\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       wchar_t tmp3[MAX_SIZE];\r
+                       wchar_t tmp4[MAX_SIZE];\r
+                       wchar_t tmp5[MAX_SIZE];\r
+                       wchar_t tmp6[MAX_SIZE];\r
+                       wchar_t tmp7[MAX_SIZE];\r
+                       wchar_t tmp8[MAX_SIZE];\r
+                       wchar_t *tmp9 = L"";\r
+                       char v1[128], v2[128];\r
+\r
+                       // ID\r
+                       UniToStru(tmp0, e->Id);\r
+\r
+                       // プロトコル\r
+                       switch (e->Protocol)\r
+                       {\r
+                       case NAT_TCP:\r
+                               tmp1 = _UU("NM_NAT_PROTO_TCP");\r
+                               break;\r
+                       case NAT_UDP:\r
+                               tmp1 = _UU("NM_NAT_PROTO_UDP");\r
+                               break;\r
+                       case NAT_DNS:\r
+                               tmp1 = _UU("NM_NAT_PROTO_DNS");\r
+                               break;\r
+                       }\r
+\r
+                       // 接続元ホスト\r
+                       StrToUni(tmp2, sizeof(tmp2), e->SrcHost);\r
+\r
+                       // 接続元ポート\r
+                       UniToStru(tmp3, e->SrcPort);\r
+\r
+                       // 接続先ホスト\r
+                       StrToUni(tmp4, sizeof(tmp4), e->DestHost);\r
+\r
+                       // 接続先ポート\r
+                       UniToStru(tmp5, e->DestPort);\r
+\r
+                       // セッション作成日時\r
+                       GetDateTimeStrEx64(tmp6, sizeof(tmp6), SystemToLocal64(e->CreatedTime), NULL);\r
+\r
+                       // 最終通信日時\r
+                       GetDateTimeStrEx64(tmp7, sizeof(tmp7), SystemToLocal64(e->LastCommTime), NULL);\r
+\r
+                       // 通信量\r
+                       ToStr3(v1, sizeof(v1), e->RecvSize);\r
+                       ToStr3(v2, sizeof(v2), e->SendSize);\r
+                       UniFormat(tmp8, sizeof(tmp8), L"%S / %S", v1, v2);\r
+\r
+                       // TCP 状態\r
+                       if (e->Protocol == NAT_TCP)\r
+                       {\r
+                               switch (e->TcpStatus)\r
+                               {\r
+                               case NAT_TCP_CONNECTING:\r
+                                       tmp9 = _UU("NAT_TCP_CONNECTING");\r
+                                       break;\r
+                               case NAT_TCP_SEND_RESET:\r
+                                       tmp9 = _UU("NAT_TCP_SEND_RESET");\r
+                                       break;\r
+                               case NAT_TCP_CONNECTED:\r
+                                       tmp9 = _UU("NAT_TCP_CONNECTED");\r
+                                       break;\r
+                               case NAT_TCP_ESTABLISHED:\r
+                                       tmp9 = _UU("NAT_TCP_ESTABLISHED");\r
+                                       break;\r
+                               case NAT_TCP_WAIT_DISCONNECT:\r
+                                       tmp9 = _UU("NAT_TCP_WAIT_DISCONNECT");\r
+                                       break;\r
+                               }\r
+                       }\r
+\r
+                       CtInsert(ct,\r
+                               tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9);\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcEnumNat(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// SecureNAT 機能の仮想 DHCP サーバー機能の設定の取得\r
+UINT PsDhcpGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       VH_OPTION t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSecureNATOption(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               CT *ct = CtNewStandard();\r
+\r
+               // 仮想 DHCP 機能を使用する\r
+               CtInsert(ct, _UU("CMD_DhcpGet_Column_USE"), t.UseDhcp ? _UU("SEC_YES") : _UU("SEC_NO"));\r
+\r
+               // 配布アドレス帯の開始\r
+               IPToUniStr(tmp, sizeof(tmp), &t.DhcpLeaseIPStart);\r
+               CtInsert(ct, _UU("CMD_DhcpGet_Column_IP1"), tmp);\r
+\r
+               // 配布アドレス帯の終了\r
+               IPToUniStr(tmp, sizeof(tmp), &t.DhcpLeaseIPEnd);\r
+               CtInsert(ct, _UU("CMD_DhcpGet_Column_IP2"), tmp);\r
+\r
+               // サブネット マスク\r
+               IPToUniStr(tmp, sizeof(tmp), &t.DhcpSubnetMask);\r
+               CtInsert(ct, _UU("CMD_DhcpGet_Column_MASK"), tmp);\r
+\r
+               // リース期限 (秒)\r
+               UniToStru(tmp, t.DhcpExpireTimeSpan);\r
+               CtInsert(ct, _UU("CMD_DhcpGet_Column_LEASE"), tmp);\r
+\r
+               // デフォルトゲートウェイアドレス\r
+               UniStrCpy(tmp, sizeof(tmp), _UU("SEC_NONE"));\r
+               if (IPToUINT(&t.DhcpGatewayAddress) != 0)\r
+               {\r
+                       IPToUniStr(tmp, sizeof(tmp), &t.DhcpGatewayAddress);\r
+               }\r
+               CtInsert(ct, _UU("CMD_DhcpGet_Column_GW"), tmp);\r
+\r
+               // DNS サーバー アドレス\r
+               UniStrCpy(tmp, sizeof(tmp), _UU("SEC_NONE"));\r
+               if (IPToUINT(&t.DhcpDnsServerAddress) != 0)\r
+               {\r
+                       IPToUniStr(tmp, sizeof(tmp), &t.DhcpDnsServerAddress);\r
+               }\r
+               CtInsert(ct, _UU("CMD_DhcpGet_Column_DNS"), tmp);\r
+\r
+               // ドメイン名\r
+               StrToUni(tmp, sizeof(tmp), t.DhcpDomainName);\r
+               CtInsert(ct, _UU("CMD_DhcpGet_Column_DOMAIN"), tmp);\r
+\r
+               // ログ保存\r
+               CtInsert(ct, _UU("CMD_SecureNatHostGet_Column_LOG"), t.SaveLog ? _UU("SEC_YES") : _UU("SEC_NO"));\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// SecureNAT 機能の仮想 DHCP サーバー機能の有効化\r
+UINT PsDhcpEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       VH_OPTION t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSecureNATOption(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               bool ok = true;\r
+\r
+               t.UseDhcp = true;\r
+\r
+               if (ok == false)\r
+               {\r
+                       // パラメータが不正\r
+                       ret = ERR_INVALID_PARAMETER;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+               else\r
+               {\r
+                       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+                       ret = ScSetSecureNATOption(ps->Rpc, &t);\r
+\r
+                       if (ret != ERR_NO_ERROR)\r
+                       {\r
+                               // エラー発生\r
+                               CmdPrintError(c, ret);\r
+                               FreeParamValueList(o);\r
+                               return ret;\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// SecureNAT 機能の仮想 DHCP サーバー機能の無効化\r
+UINT PsDhcpDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       VH_OPTION t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSecureNATOption(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               bool ok = true;\r
+\r
+               t.UseDhcp = false;\r
+\r
+               if (ok == false)\r
+               {\r
+                       // パラメータが不正\r
+                       ret = ERR_INVALID_PARAMETER;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+               else\r
+               {\r
+                       ret = ScSetSecureNATOption(ps->Rpc, &t);\r
+\r
+                       if (ret != ERR_NO_ERROR)\r
+                       {\r
+                               // エラー発生\r
+                               CmdPrintError(c, ret);\r
+                               FreeParamValueList(o);\r
+                               return ret;\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// SecureNAT 機能の仮想 DHCP サーバー機能の設定の変更\r
+UINT PsDhcpSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       VH_OPTION t;\r
+       // 指定できるパラメータ リスト\r
+       CMD_EVAL_MIN_MAX mm =\r
+       {\r
+               "CMD_NatSet_Eval_UDP", NAT_UDP_MIN_TIMEOUT / 1000, NAT_UDP_MAX_TIMEOUT / 1000,\r
+       };\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"START", CmdPrompt, _UU("CMD_DhcpSet_Prompt_START"), CmdEvalIp, NULL},\r
+               {"END", CmdPrompt, _UU("CMD_DhcpSet_Prompt_END"), CmdEvalIp, NULL},\r
+               {"MASK", CmdPrompt, _UU("CMD_DhcpSet_Prompt_MASK"), CmdEvalIp, NULL},\r
+               {"EXPIRE", CmdPrompt, _UU("CMD_DhcpSet_Prompt_EXPIRE"), CmdEvalMinMax, &mm},\r
+               {"GW", CmdPrompt, _UU("CMD_DhcpSet_Prompt_GW"), CmdEvalIp, NULL},\r
+               {"DNS", CmdPrompt, _UU("CMD_DhcpSet_Prompt_DNS"), CmdEvalIp, NULL},\r
+               {"DOMAIN", CmdPrompt, _UU("CMD_DhcpSet_Prompt_DOMAIN"), NULL, NULL},\r
+               {"LOG", CmdPrompt, _UU("CMD_NatSet_Prompt_LOG"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetSecureNATOption(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               bool ok = true;\r
+\r
+               StrToIP(&t.DhcpLeaseIPStart, GetParamStr(o, "START"));\r
+               StrToIP(&t.DhcpLeaseIPEnd, GetParamStr(o, "END"));\r
+               StrToIP(&t.DhcpSubnetMask, GetParamStr(o, "MASK"));\r
+               t.DhcpExpireTimeSpan = GetParamInt(o, "EXPIRE");\r
+               StrToIP(&t.DhcpGatewayAddress, GetParamStr(o, "GW"));\r
+               StrToIP(&t.DhcpDnsServerAddress, GetParamStr(o, "DNS"));\r
+               StrCpy(t.DhcpDomainName, sizeof(t.DhcpDomainName), GetParamStr(o, "DOMAIN"));\r
+               t.SaveLog = GetParamYes(o, "LOG");\r
+\r
+               if (ok == false)\r
+               {\r
+                       // パラメータが不正\r
+                       ret = ERR_INVALID_PARAMETER;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+               else\r
+               {\r
+                       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+                       ret = ScSetSecureNATOption(ps->Rpc, &t);\r
+\r
+                       if (ret != ERR_NO_ERROR)\r
+                       {\r
+                               // エラー発生\r
+                               CmdPrintError(c, ret);\r
+                               FreeParamValueList(o);\r
+                               return ret;\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// SecureNAT 機能の仮想 DHCP サーバー機能のリース テーブルの取得\r
+UINT PsDhcpTable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_DHCP t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumDHCP(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNew();\r
+               UINT i;\r
+\r
+               CtInsertColumn(ct, _UU("DHCP_DHCP_ID"), false);\r
+               CtInsertColumn(ct, _UU("DHCP_LEASED_TIME"), false);\r
+               CtInsertColumn(ct, _UU("DHCP_EXPIRE_TIME"), false);\r
+               CtInsertColumn(ct, _UU("DHCP_MAC_ADDRESS"), false);\r
+               CtInsertColumn(ct, _UU("DHCP_IP_ADDRESS"), false);\r
+               CtInsertColumn(ct, _UU("DHCP_HOSTNAME"), false);\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       RPC_ENUM_DHCP_ITEM *e = &t.Items[i];\r
+                       wchar_t tmp0[MAX_SIZE];\r
+                       wchar_t tmp1[MAX_SIZE];\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       wchar_t tmp3[MAX_SIZE];\r
+                       wchar_t tmp4[MAX_SIZE];\r
+                       wchar_t tmp5[MAX_SIZE];\r
+                       char str[MAX_SIZE];\r
+\r
+                       // ID\r
+                       UniToStru(tmp0, e->Id);\r
+\r
+                       // 時刻\r
+                       GetDateTimeStrEx64(tmp1, sizeof(tmp1), SystemToLocal64(e->LeasedTime), NULL);\r
+                       GetDateTimeStrEx64(tmp2, sizeof(tmp2), SystemToLocal64(e->ExpireTime), NULL);\r
+\r
+                       MacToStr(str, sizeof(str), e->MacAddress);\r
+                       StrToUni(tmp3, sizeof(tmp3), str);\r
+\r
+                       IPToStr32(str, sizeof(str), e->IpAddress);\r
+                       StrToUni(tmp4, sizeof(tmp4), str);\r
+\r
+                       StrToUni(tmp5, sizeof(tmp5), e->Hostname);\r
+\r
+                       CtInsert(ct,\r
+                               tmp0, tmp1, tmp2, tmp3, tmp4, tmp5);\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcEnumDhcp(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB 管理オプションの一覧の取得\r
+UINT PsAdminOptionList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ADMIN_OPTION t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetHubAdminOptions(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNewStandardEx();\r
+               UINT i;\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       ADMIN_OPTION *e = &t.Items[i];\r
+                       wchar_t tmp1[MAX_SIZE];\r
+                       wchar_t tmp2[MAX_SIZE];\r
+\r
+                       StrToUni(tmp1, sizeof(tmp1), e->Name);\r
+                       UniToStru(tmp2, e->Value);\r
+\r
+                       CtInsert(ct, tmp1, tmp2, GetHubAdminOptionHelpString(e->Name));\r
+                               \r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcAdminOption(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB 管理オプションの値の設定\r
+UINT PsAdminOptionSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ADMIN_OPTION t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_AdminOptionSet_Prompt_name"), CmdEvalNotEmpty, NULL},\r
+               {"VALUE", CmdPrompt, _UU("CMD_AdminOptionSet_Prompt_VALUE"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetHubAdminOptions(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+               bool b = false;\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       if (StrCmpi(t.Items[i].Name, GetParamStr(o, "[name]")) == 0)\r
+                       {\r
+                               t.Items[i].Value = GetParamInt(o, "VALUE");\r
+                               b = true;\r
+                       }\r
+               }\r
+\r
+               if (b == false)\r
+               {\r
+                       // エラー発生\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       FreeRpcAdminOption(&t);\r
+                       return ret;\r
+               }\r
+               else\r
+               {\r
+                       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+                       ret = ScSetHubAdminOptions(ps->Rpc, &t);\r
+\r
+                       if (ret != ERR_NO_ERROR)\r
+                       {\r
+                               // エラー発生\r
+                               CmdPrintError(c, ret);\r
+                               FreeParamValueList(o);\r
+                               return ret;\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeRpcAdminOption(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB 拡張オプションの一覧の取得\r
+UINT PsExtOptionList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ADMIN_OPTION t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetHubExtOptions(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               CT *ct = CtNewStandardEx();\r
+               UINT i;\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       ADMIN_OPTION *e = &t.Items[i];\r
+                       wchar_t tmp1[MAX_SIZE];\r
+                       wchar_t tmp2[MAX_SIZE];\r
+\r
+                       StrToUni(tmp1, sizeof(tmp1), e->Name);\r
+                       UniToStru(tmp2, e->Value);\r
+\r
+                       CtInsert(ct, tmp1, tmp2, GetHubAdminOptionHelpString(e->Name));\r
+\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcAdminOption(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB 拡張オプションの値の設定\r
+UINT PsExtOptionSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ADMIN_OPTION t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[name]", CmdPrompt, _UU("CMD_AdminOptionSet_Prompt_name"), CmdEvalNotEmpty, NULL},\r
+               {"VALUE", CmdPrompt, _UU("CMD_AdminOptionSet_Prompt_VALUE"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetHubExtOptions(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+               bool b = false;\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       if (StrCmpi(t.Items[i].Name, GetParamStr(o, "[name]")) == 0)\r
+                       {\r
+                               t.Items[i].Value = GetParamInt(o, "VALUE");\r
+                               b = true;\r
+                       }\r
+               }\r
+\r
+               if (b == false)\r
+               {\r
+                       // エラー発生\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       FreeRpcAdminOption(&t);\r
+                       return ret;\r
+               }\r
+               else\r
+               {\r
+                       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+                       ret = ScSetHubExtOptions(ps->Rpc, &t);\r
+\r
+                       if (ret != ERR_NO_ERROR)\r
+                       {\r
+                               // エラー発生\r
+                               CmdPrintError(c, ret);\r
+                               FreeParamValueList(o);\r
+                               return ret;\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeRpcAdminOption(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 無効な証明書リストの一覧の取得\r
+UINT PsCrlList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_CRL t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumCrl(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+               CT *ct = CtNew();\r
+\r
+               CtInsertColumn(ct, _UU("CMD_ID"), false);\r
+               CtInsertColumn(ct, _UU("SM_CRL_COLUMN_1"), false);\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       wchar_t tmp[64];\r
+                       RPC_ENUM_CRL_ITEM *e = &t.Items[i];\r
+\r
+                       UniToStru(tmp, e->Key);\r
+                       CtInsert(ct, tmp, e->CrlInfo);\r
+               }\r
+\r
+               CtFreeEx(ct, c, true);\r
+       }\r
+\r
+       FreeRpcEnumCrl(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 無効な証明書の追加\r
+UINT PsCrlAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CRL t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               {"SERIAL", NULL, NULL, NULL, NULL},\r
+               {"MD5", NULL, NULL, NULL, NULL},\r
+               {"SHA1", NULL, NULL, NULL, NULL},\r
+               {"CN", NULL, NULL, NULL, NULL},\r
+               {"O", NULL, NULL, NULL, NULL},\r
+               {"OU", NULL, NULL, NULL, NULL},\r
+               {"C", NULL, NULL, NULL, NULL},\r
+               {"ST", NULL, NULL, NULL, NULL},\r
+               {"L", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       {\r
+               bool param_exists = false;\r
+               CRL *crl = ZeroMalloc(sizeof(CRL));\r
+               NAME *n;\r
+               n = crl->Name = ZeroMalloc(sizeof(NAME));\r
+\r
+               if (IsEmptyStr(GetParamStr(o, "CN")) == false)\r
+               {\r
+                       n->CommonName = CopyUniStr(GetParamUniStr(o, "CN"));\r
+                       param_exists = true;\r
+               }\r
+\r
+               if (IsEmptyStr(GetParamStr(o, "O")) == false)\r
+               {\r
+                       n->CommonName = CopyUniStr(GetParamUniStr(o, "O"));\r
+                       param_exists = true;\r
+               }\r
+\r
+               if (IsEmptyStr(GetParamStr(o, "OU")) == false)\r
+               {\r
+                       n->CommonName = CopyUniStr(GetParamUniStr(o, "OU"));\r
+                       param_exists = true;\r
+               }\r
+\r
+               if (IsEmptyStr(GetParamStr(o, "C")) == false)\r
+               {\r
+                       n->CommonName = CopyUniStr(GetParamUniStr(o, "C"));\r
+                       param_exists = true;\r
+               }\r
+\r
+               if (IsEmptyStr(GetParamStr(o, "ST")) == false)\r
+               {\r
+                       n->CommonName = CopyUniStr(GetParamUniStr(o, "ST"));\r
+                       param_exists = true;\r
+               }\r
+\r
+               if (IsEmptyStr(GetParamStr(o, "L")) == false)\r
+               {\r
+                       n->CommonName = CopyUniStr(GetParamUniStr(o, "L"));\r
+                       param_exists = true;\r
+               }\r
+\r
+               if (IsEmptyStr(GetParamStr(o, "SERIAL")) == false)\r
+               {\r
+                       BUF *b;\r
+\r
+                       b = StrToBin(GetParamStr(o, "SERIAL"));\r
+\r
+                       if (b != NULL && b->Size >= 1)\r
+                       {\r
+                               crl->Serial = NewXSerial(b->Buf, b->Size);\r
+                               param_exists = true;\r
+                       }\r
+\r
+                       FreeBuf(b);\r
+               }\r
+\r
+               if (IsEmptyStr(GetParamStr(o, "MD5")) == false)\r
+               {\r
+                       BUF *b;\r
+\r
+                       b = StrToBin(GetParamStr(o, "MD5"));\r
+\r
+                       if (b != NULL && b->Size == MD5_SIZE)\r
+                       {\r
+                               Copy(crl->DigestMD5, b->Buf, MD5_SIZE);\r
+                               param_exists = true;\r
+                       }\r
+\r
+                       FreeBuf(b);\r
+               }\r
+\r
+               if (IsEmptyStr(GetParamStr(o, "SHA1")) == false)\r
+               {\r
+                       BUF *b;\r
+\r
+                       b = StrToBin(GetParamStr(o, "SHA1"));\r
+\r
+                       if (b != NULL && b->Size == SHA1_SIZE)\r
+                       {\r
+                               Copy(crl->DigestSHA1, b->Buf, SHA1_SIZE);\r
+                               param_exists = true;\r
+                       }\r
+\r
+                       FreeBuf(b);\r
+               }\r
+\r
+               t.Crl = crl;\r
+\r
+               if (param_exists == false)\r
+               {\r
+                       FreeRpcCrl(&t);\r
+                       ret = ERR_INVALID_PARAMETER;\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       // RPC 呼び出し\r
+       ret = ScAddCrl(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcCrl(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 無効な証明書の削除\r
+UINT PsCrlDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CRL t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_CrlDel_Prompt_ID"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.Key = GetParamInt(o, "[id]");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDelCrl(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeRpcCrl(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 無効な証明書の取得\r
+UINT PsCrlGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_CRL t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_CrlGet_Prompt_ID"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+       t.Key = GetParamInt(o, "[id]");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetCrl(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // 内容の表示\r
+               CT *ct = CtNewStandard();\r
+               CRL *crl = t.Crl;\r
+               NAME *n;\r
+\r
+               if (crl != NULL)\r
+               {\r
+                       n = crl->Name;\r
+\r
+                       if (n != NULL)\r
+                       {\r
+                               if (UniIsEmptyStr(n->CommonName) == false)\r
+                               {\r
+                                       CtInsert(ct, _UU("CMD_CrlGet_CN"), n->CommonName);\r
+                               }\r
+                               if (UniIsEmptyStr(n->Organization) == false)\r
+                               {\r
+                                       CtInsert(ct, _UU("CMD_CrlGet_O"), n->Organization);\r
+                               }\r
+                               if (UniIsEmptyStr(n->Unit) == false)\r
+                               {\r
+                                       CtInsert(ct, _UU("CMD_CrlGet_OU"), n->Unit);\r
+                               }\r
+                               if (UniIsEmptyStr(n->Country) == false)\r
+                               {\r
+                                       CtInsert(ct, _UU("CMD_CrlGet_C"), n->Country);\r
+                               }\r
+                               if (UniIsEmptyStr(n->State) == false)\r
+                               {\r
+                                       CtInsert(ct, _UU("CMD_CrlGet_ST"), n->State);\r
+                               }\r
+                               if (UniIsEmptyStr(n->Local) == false)\r
+                               {\r
+                                       CtInsert(ct, _UU("CMD_CrlGet_L"), n->Local);\r
+                               }\r
+                       }\r
+\r
+                       if (crl->Serial != NULL && crl->Serial->size >= 1)\r
+                       {\r
+                               wchar_t tmp[MAX_SIZE];\r
+                               char str[MAX_SIZE];\r
+\r
+                               BinToStrEx(str, sizeof(str), crl->Serial->data, crl->Serial->size);\r
+                               StrToUni(tmp, sizeof(tmp), str);\r
+\r
+                               CtInsert(ct, _UU("CMD_CrlGet_SERI"), tmp);\r
+                       }\r
+\r
+                       if (IsZero(crl->DigestMD5, MD5_SIZE) == false)\r
+                       {\r
+                               wchar_t tmp[MAX_SIZE];\r
+                               char str[MAX_SIZE];\r
+\r
+                               BinToStrEx(str, sizeof(str), crl->DigestMD5, MD5_SIZE);\r
+                               StrToUni(tmp, sizeof(tmp), str);\r
+\r
+                               CtInsert(ct, _UU("CMD_CrlGet_MD5_HASH"), tmp);\r
+                       }\r
+\r
+                       if (IsZero(crl->DigestSHA1, SHA1_SIZE) == false)\r
+                       {\r
+                               wchar_t tmp[MAX_SIZE];\r
+                               char str[MAX_SIZE];\r
+\r
+                               BinToStrEx(str, sizeof(str), crl->DigestSHA1, SHA1_SIZE);\r
+                               StrToUni(tmp, sizeof(tmp), str);\r
+\r
+                               CtInsert(ct, _UU("CMD_CrlGet_SHA1_HASH"), tmp);\r
+                       }\r
+               }\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeRpcCrl(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// IP アクセス制御リストのルール一覧の取得\r
+UINT PsAcList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_AC_LIST t;\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetAcList(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               UINT i;\r
+               CT *ct;\r
+\r
+               ct = CtNew();\r
+               CtInsertColumn(ct, _UU("SM_AC_COLUMN_1"), true);\r
+               CtInsertColumn(ct, _UU("SM_AC_COLUMN_2"), true);\r
+               CtInsertColumn(ct, _UU("SM_AC_COLUMN_3"), false);\r
+               CtInsertColumn(ct, _UU("SM_AC_COLUMN_4"), false);\r
+\r
+               for (i = 0;i < LIST_NUM(t.o);i++)\r
+               {\r
+                       wchar_t tmp1[32], *tmp2, tmp3[MAX_SIZE], tmp4[32];\r
+                       char *tmp_str;\r
+                       AC *ac = LIST_DATA(t.o, i);\r
+\r
+                       UniToStru(tmp1, ac->Id);\r
+                       tmp2 = ac->Deny ? _UU("SM_AC_DENY") : _UU("SM_AC_PASS");\r
+                       tmp_str = GenerateAcStr(ac);\r
+                       StrToUni(tmp3, sizeof(tmp3), tmp_str);\r
+\r
+                       Free(tmp_str);\r
+\r
+                       UniToStru(tmp4, ac->Priority);\r
+\r
+                       CtInsert(ct, tmp1, tmp4, tmp2, tmp3);\r
+               }\r
+\r
+               CtFree(ct, c);\r
+       }\r
+\r
+       FreeRpcAcList(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// IP アクセス制御リストにルールを追加 (IPv4)\r
+UINT PsAcAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_AC_LIST t;\r
+       // 指定できるパラメータ リスト\r
+       CMD_EVAL_MIN_MAX mm =\r
+       {\r
+               "CMD_AcAdd_Eval_PRIORITY", 1, 4294967295UL,\r
+       };\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[allow|deny]", CmdPrompt, _UU("CMD_AcAdd_Prompt_AD"), CmdEvalNotEmpty, NULL},\r
+               {"PRIORITY", CmdPrompt, _UU("CMD_AcAdd_Prompt_PRIORITY"), CmdEvalMinMax, &mm},\r
+               {"IP", CmdPrompt, _UU("CMD_AcAdd_Prompt_IP"), CmdEvalIpAndMask4, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetAcList(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // リストに新しい項目を追加する\r
+               AC *ac = ZeroMalloc(sizeof(AC));\r
+               char *test = GetParamStr(o, "[allow|deny]");\r
+               UINT u_ip, u_mask;\r
+\r
+               if (StartWith("deny", test))\r
+               {\r
+                       ac->Deny = true;\r
+               }\r
+\r
+               ParseIpAndMask4(GetParamStr(o, "IP"), &u_ip, &u_mask);\r
+               UINTToIP(&ac->IpAddress, u_ip);\r
+\r
+               if (u_mask == 0xffffffff)\r
+               {\r
+                       ac->Masked = false;\r
+               }\r
+               else\r
+               {\r
+                       ac->Masked = true;\r
+                       UINTToIP(&ac->SubnetMask, u_mask);\r
+               }\r
+\r
+               ac->Priority = GetParamInt(o, "PRIORITY");\r
+\r
+               Insert(t.o, ac);\r
+\r
+               ret = ScSetAcList(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       FreeRpcAcList(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// IP アクセス制御リストにルールを追加 (IPv6)\r
+UINT PsAcAdd6(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_AC_LIST t;\r
+       // 指定できるパラメータ リスト\r
+       CMD_EVAL_MIN_MAX mm =\r
+       {\r
+               "CMD_AcAdd6_Eval_PRIORITY", 1, 4294967295UL,\r
+       };\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[allow|deny]", CmdPrompt, _UU("CMD_AcAdd6_Prompt_AD"), CmdEvalNotEmpty, NULL},\r
+               {"PRIORITY", CmdPrompt, _UU("CMD_AcAdd6_Prompt_PRIORITY"), CmdEvalMinMax, &mm},\r
+               {"IP", CmdPrompt, _UU("CMD_AcAdd6_Prompt_IP"), CmdEvalIpAndMask6, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetAcList(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // リストに新しい項目を追加する\r
+               AC *ac = ZeroMalloc(sizeof(AC));\r
+               char *test = GetParamStr(o, "[allow|deny]");\r
+               IP u_ip, u_mask;\r
+\r
+               if (StartWith("deny", test))\r
+               {\r
+                       ac->Deny = true;\r
+               }\r
+\r
+               ParseIpAndMask6(GetParamStr(o, "IP"), &u_ip, &u_mask);\r
+               Copy(&ac->IpAddress, &u_ip, sizeof(IP));\r
+\r
+               if (SubnetMaskToInt6(&u_mask) == 128)\r
+               {\r
+                       ac->Masked = false;\r
+               }\r
+               else\r
+               {\r
+                       ac->Masked = true;\r
+                       Copy(&ac->SubnetMask, &u_mask, sizeof(IP));\r
+               }\r
+\r
+               ac->Priority = GetParamInt(o, "PRIORITY");\r
+\r
+               Insert(t.o, ac);\r
+\r
+               ret = ScSetAcList(ps->Rpc, &t);\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       FreeRpcAcList(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// デバッグコマンドを実行する\r
+UINT PsDebug(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       UINT id;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", NULL, NULL, NULL, NULL},\r
+               {"ARG", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       id = GetParamInt(o, "[id]");\r
+\r
+       if (true)\r
+       {\r
+               RPC_TEST t;\r
+               UINT ret;\r
+\r
+               c->Write(c, _UU("CMD_Debug_Msg1"));\r
+\r
+               Zero(&t, sizeof(t));\r
+\r
+               t.IntValue = id;\r
+               StrCpy(t.StrValue, sizeof(t.StrValue), GetParamStr(o, "ARG"));\r
+\r
+               ret = ScDebug(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+               else\r
+               {\r
+                       wchar_t tmp[sizeof(t.StrValue)];\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CMD_Debug_Msg2"), t.StrValue);\r
+                       c->Write(c, tmp);\r
+               }\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// サーバーの設定ファイルをフラッシュする\r
+UINT PsFlush(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (true)\r
+       {\r
+               RPC_TEST t;\r
+               UINT ret;\r
+               wchar_t tmp[MAX_SIZE];\r
+               char sizestr[MAX_SIZE];\r
+\r
+               c->Write(c, _UU("CMD_Flush_Msg1"));\r
+\r
+               Zero(&t, sizeof(t));\r
+\r
+               ret = ScFlush(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+\r
+               ToStr3(sizestr, sizeof(sizestr), (UINT64)t.IntValue);\r
+               UniFormat(tmp, sizeof(tmp), _UU("CMD_Flush_Msg2"), sizestr);\r
+               c->Write(c, tmp);\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// クラッシュさせる\r
+UINT PsCrash(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       char *yes;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[yes]", CmdPrompt, _UU("CMD_Crash_Confirm"), NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       yes = GetParamStr(o, "[yes]");\r
+\r
+       if (StrCmpi(yes, "yes") != 0)\r
+       {\r
+               c->Write(c, _UU("CMD_Crash_Aborted"));\r
+       }\r
+       else\r
+       {\r
+               RPC_TEST t;\r
+               UINT ret;\r
+\r
+               c->Write(c, _UU("CMD_Crash_Msg"));\r
+\r
+               Zero(&t, sizeof(t));\r
+\r
+               ret = ScCrash(ps->Rpc, &t);\r
+\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// IP アクセス制御リスト内のルールの削除\r
+UINT PsAcDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_AC_LIST t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_AcDel_Prompt_ID"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       // 仮想 HUB が選択されていない場合はエラー\r
+       if (ps->HubName == NULL)\r
+       {\r
+               c->Write(c, _UU("CMD_Hub_Not_Selected"));\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetAcList(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               // ID 一致を削除\r
+               UINT i;\r
+               bool b = false;\r
+\r
+               for (i = 0;i < LIST_NUM(t.o);i++)\r
+               {\r
+                       AC *ac = LIST_DATA(t.o, i);\r
+\r
+                       if (ac->Id == GetParamInt(o, "[id]"))\r
+                       {\r
+                               Delete(t.o, ac);\r
+                               Free(ac);\r
+                               b = true;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               if (b == false)\r
+               {\r
+                       ret = ERR_OBJECT_NOT_FOUND;\r
+                       FreeRpcAcList(&t);\r
+               }\r
+               else\r
+               {\r
+                       ret = ScSetAcList(ps->Rpc, &t);\r
+               }\r
+               if (ret != ERR_NO_ERROR)\r
+               {\r
+                       // エラー発生\r
+                       CmdPrintError(c, ret);\r
+                       FreeParamValueList(o);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       FreeRpcAcList(&t);\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 新しいライセンスキーの登録\r
+UINT PsLicenseAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_TEST t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[key]", CmdPrompt, _UU("CMD_LicenseAdd_Prompt_Key"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.StrValue, sizeof(t.StrValue), GetParamStr(o, "[key]"));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScAddLicenseKey(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 登録されているライセンスの削除\r
+UINT PsLicenseDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_TEST t;\r
+       // 指定できるパラメータ リスト\r
+       PARAM args[] =\r
+       {\r
+               // "name", prompt_proc, prompt_param, eval_proc, eval_param\r
+               {"[id]", CmdPrompt, _UU("CMD_LicenseDel_Prompt_ID"), CmdEvalNotEmpty, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.IntValue = GetParamInt(o, "[id]");\r
+\r
+       // RPC 呼び出し\r
+       ret = ScDelLicenseKey(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 登録されているライセンス一覧の取得\r
+UINT PsLicenseList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_ENUM_LICENSE_KEY t;\r
+       CT *ct;\r
+       UINT i;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScEnumLicenseKey(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       ct = CtNew();\r
+       CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_1"), false);\r
+       CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_2"), false);\r
+       CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_3"), false);\r
+       CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_4"), false);\r
+       CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_5"), false);\r
+       CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_6"), false);\r
+       CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_7"), false);\r
+       CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_8"), false);\r
+       CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_9"), false);\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               wchar_t tmp1[32], tmp2[LICENSE_KEYSTR_LEN + 1], tmp3[LICENSE_MAX_PRODUCT_NAME_LEN + 1],\r
+                       *tmp4, tmp5[128], tmp6[LICENSE_LICENSEID_STR_LEN + 1], tmp7[64],\r
+                       tmp8[64], tmp9[64];\r
+               RPC_ENUM_LICENSE_KEY_ITEM *e = &t.Items[i];\r
+\r
+               UniToStru(tmp1, e->Id);\r
+               StrToUni(tmp2, sizeof(tmp2), e->LicenseKey);\r
+               StrToUni(tmp3, sizeof(tmp3), e->LicenseName);\r
+               tmp4 = LiGetLicenseStatusStr(e->Status);\r
+               if (e->Expires == 0)\r
+               {\r
+                       UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_LICENSE_NO_EXPIRES"));\r
+               }\r
+               else\r
+               {\r
+                       GetDateStrEx64(tmp5, sizeof(tmp5), e->Expires, NULL);\r
+               }\r
+               StrToUni(tmp6, sizeof(tmp6), e->LicenseId);\r
+               UniToStru(tmp7, e->ProductId);\r
+               UniFormat(tmp8, sizeof(tmp8), L"%I64u", e->SystemId);\r
+               UniToStru(tmp9, e->SerialId);\r
+\r
+               CtInsert(ct,\r
+                       tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9);\r
+       }\r
+\r
+       CtFreeEx(ct, c, true);\r
+\r
+       FreeRpcEnumLicenseKey(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 現在の VPN Server のライセンス状態の取得\r
+UINT PsLicenseStatus(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret = 0;\r
+       RPC_LICENSE_STATUS st;\r
+       CT *ct;\r
+       wchar_t tmp[MAX_SIZE];\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&st, sizeof(st));\r
+\r
+       // RPC 呼び出し\r
+       ret = ScGetLicenseStatus(ps->Rpc, &st);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               // エラー発生\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       ct = CtNewStandard();\r
+\r
+       if (st.EditionId == LICENSE_EDITION_VPN3_NO_LICENSE)\r
+       {\r
+               CtInsert(ct, _UU("SM_NO_LICENSE_COLUMN"), _UU("SM_NO_LICENSE"));\r
+       }\r
+       else\r
+       {\r
+               // 製品エディション名\r
+               StrToUni(tmp, sizeof(tmp), st.EditionStr);\r
+               CtInsert(ct, _UU("SM_LICENSE_STATUS_EDITION"), tmp);\r
+\r
+               // リリース日付\r
+               if (st.ReleaseDate != 0)\r
+               {\r
+                       GetDateStrEx64(tmp, sizeof(tmp), st.ReleaseDate, NULL);\r
+                       CtInsert(ct, _UU("SM_LICENSE_STATUS_RELEASE"), tmp);\r
+               }\r
+\r
+               // 現在のシステム ID\r
+               UniFormat(tmp, sizeof(tmp), L"%I64u", st.SystemId);\r
+               CtInsert(ct, _UU("SM_LICENSE_STATUS_SYSTEM_ID"), tmp);\r
+\r
+               // 現在の製品ライセンスの有効期限\r
+               if (st.SystemExpires == 0)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_NO_EXPIRES"));\r
+               }\r
+               else\r
+               {\r
+                       GetDateStrEx64(tmp, sizeof(tmp), st.SystemExpires, NULL);\r
+               }\r
+               CtInsert(ct,  _UU("SM_LICENSE_STATUS_EXPIRES"), tmp);\r
+\r
+               // サブスクリプション (サポート) 契約\r
+               if (st.NeedSubscription == false)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_STATUS_SUBSCRIPTION_NONEED"));\r
+               }\r
+               else\r
+               {\r
+                       if (st.SubscriptionExpires == 0)\r
+                       {\r
+                               UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_STATUS_SUBSCRIPTION_NONE"));\r
+                       }\r
+                       else\r
+                       {\r
+                               wchar_t dtstr[MAX_PATH];\r
+\r
+                               GetDateStrEx64(dtstr, sizeof(dtstr), st.SubscriptionExpires, NULL);\r
+\r
+                               UniFormat(tmp, sizeof(tmp),\r
+                                       st.IsSubscriptionExpired ? _UU("SM_LICENSE_STATUS_SUBSCRIPTION_EXPIRED") :  _UU("SM_LICENSE_STATUS_SUBSCRIPTION_VALID"),\r
+                                       dtstr);\r
+                       }\r
+               }\r
+               CtInsert(ct, _UU("SM_LICENSE_STATUS_SUBSCRIPTION"), tmp);\r
+\r
+               if (st.NeedSubscription == false && st.SubscriptionExpires != 0)\r
+               {\r
+                       wchar_t dtstr[MAX_PATH];\r
+\r
+                       GetDateStrEx64(dtstr, sizeof(dtstr), st.SubscriptionExpires, NULL);\r
+\r
+                       CtInsert(ct, _UU("SM_LICENSE_STATUS_SUBSCRIPTION_BUILD_STR"), tmp);\r
+               }\r
+\r
+               if (GetCapsBool(ps->CapsList, "b_vpn3"))\r
+               {\r
+                       // ユーザー作成可能数\r
+                       if (st.NumClientConnectLicense == INFINITE)\r
+                       {\r
+                               UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_INFINITE"));\r
+                       }\r
+                       else\r
+                       {\r
+                               UniToStru(tmp, st.NumClientConnectLicense);\r
+                       }\r
+                       CtInsert(ct, _UU("SM_LICENSE_NUM_CLIENT"), tmp);\r
+               }\r
+\r
+               // クライアント同時接続可能数\r
+               if (st.NumBridgeConnectLicense == INFINITE)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_INFINITE"));\r
+               }\r
+               else\r
+               {\r
+                       UniToStru(tmp, st.NumBridgeConnectLicense);\r
+               }\r
+               CtInsert(ct, _UU("SM_LICENSE_NUM_BRIDGE"), tmp);\r
+\r
+               // エンタープライズ機能の利用可否\r
+               CtInsert(ct, _UU("SM_LICENSE_STATUS_ENTERPRISE"),\r
+                       st.AllowEnterpriseFunction ? _UU("SM_LICENSE_STATUS_ENTERPRISE_YES") : _UU("SM_LICENSE_STATUS_ENTERPRISE_NO"));\r
+       }\r
+\r
+       CtFreeEx(ct, c, false);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+\r
+// クラスタ設定の取得\r
+UINT PsClusterSettingGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret;\r
+       RPC_FARM t;\r
+       CT *ct;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = ScGetFarmSetting(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       if (t.Weight == 0)\r
+       {\r
+               t.Weight = FARM_DEFAULT_WEIGHT;\r
+       }\r
+\r
+       // クラスタ設定の表示\r
+       ct = CtNewStandard();\r
+\r
+       CtInsert(ct, _UU("CMD_ClusterSettingGet_Current"),\r
+               GetServerTypeStr(t.ServerType));\r
+\r
+       if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               CtInsert(ct, _UU("CMD_ClusterSettingGet_ControllerOnly"), t.ControllerOnly ? _UU("SEC_YES") : _UU("SEC_NO"));\r
+       }\r
+\r
+       if (t.ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               UniToStru(tmp, t.Weight);\r
+\r
+               CtInsert(ct, _UU("CMD_ClusterSettingGet_Weight"), tmp);\r
+       }\r
+\r
+       if (t.ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               UINT i;\r
+\r
+               // 公開 IP アドレス\r
+               if (t.PublicIp != 0)\r
+               {\r
+                       IPToUniStr32(tmp, sizeof(tmp), t.PublicIp);\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("CMD_ClusterSettingGet_None"));\r
+               }\r
+\r
+               CtInsert(ct, _UU("CMD_ClusterSettingGet_PublicIp"), tmp);\r
+\r
+               // 公開ポート一覧\r
+               tmp[0] = 0;\r
+               for (i = 0;i < t.NumPort;i++)\r
+               {\r
+                       wchar_t tmp2[64];\r
+\r
+                       UniFormat(tmp2, sizeof(tmp2), L"%u, ", t.Ports[i]);\r
+\r
+                       UniStrCat(tmp, sizeof(tmp), tmp2);\r
+               }\r
+\r
+               if (UniEndWith(tmp, L", "))\r
+               {\r
+                       tmp[UniStrLen(tmp) - 2] = 0;\r
+               }\r
+\r
+               CtInsert(ct, _UU("CMD_ClusterSettingGet_PublicPorts"), tmp);\r
+\r
+               // 接続先コントローラ\r
+               UniFormat(tmp, sizeof(tmp), L"%S:%u", t.ControllerName, t.ControllerPort);\r
+               CtInsert(ct, _UU("CMD_ClusterSettingGet_Controller"), tmp);\r
+       }\r
+\r
+       CtFree(ct, c);\r
+\r
+       FreeRpcFarm(&t);\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// サーバーパスワードの設定\r
+UINT PsServerPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret;\r
+       RPC_SET_PASSWORD t;\r
+       char *pw;\r
+       PARAM args[] =\r
+       {\r
+               {"[password]", CmdPromptChoosePassword, NULL, NULL, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       pw = GetParamStr(o, "[password]");\r
+\r
+       Zero(&t, sizeof(t));\r
+       Hash(t.HashedPassword, pw, StrLen(pw), true);\r
+\r
+       ret = ScSetServerPassword(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// パスワード決定プロンプト (プロンプト関数用)\r
+wchar_t *CmdPromptChoosePassword(CONSOLE *c, void *param)\r
+{\r
+       char *s;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       s = CmdPasswordPrompt(c);\r
+\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       else\r
+       {\r
+               wchar_t *ret = CopyStrToUni(s);\r
+\r
+               Free(s);\r
+\r
+               return ret;\r
+       }\r
+}\r
+\r
+// パスワード入力用プロンプト (汎用)\r
+char *CmdPasswordPrompt(CONSOLE *c)\r
+{\r
+       char *pw1, *pw2;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       c->Write(c, _UU("CMD_UTVPNCMD_PWPROMPT_0"));\r
+\r
+RETRY:\r
+       c->Write(c, L"");\r
+\r
+\r
+       pw1 = c->ReadPassword(c, _UU("CMD_UTVPNCMD_PWPROMPT_1"));\r
+       if (pw1 == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       pw2 = c->ReadPassword(c, _UU("CMD_UTVPNCMD_PWPROMPT_2"));\r
+       if (pw2 == NULL)\r
+       {\r
+               Free(pw1);\r
+               return NULL;\r
+       }\r
+\r
+       c->Write(c, L"");\r
+\r
+       if (StrCmp(pw1, pw2) != 0)\r
+       {\r
+               Free(pw1);\r
+               Free(pw2);\r
+               c->Write(c, _UU("CMD_UTVPNCMD_PWPROMPT_3"));\r
+               goto RETRY;\r
+       }\r
+\r
+       Free(pw1);\r
+\r
+       return pw2;\r
+}\r
+\r
+// リスナー無効化\r
+UINT PsListenerDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret;\r
+       RPC_LISTENER t;\r
+       PARAM args[] =\r
+       {\r
+               {"[port]", CmdPromptPort, _UU("CMD_ListenerDisable_PortPrompt"), CmdEvalPort, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.Enable = false;\r
+       t.Port = ToInt(GetParamStr(o, "[port]"));\r
+\r
+       ret = ScEnableListener(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// リスナー有効化\r
+UINT PsListenerEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret;\r
+       RPC_LISTENER t;\r
+       PARAM args[] =\r
+       {\r
+               {"[port]", CmdPromptPort, _UU("CMD_ListenerEnable_PortPrompt"), CmdEvalPort, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.Enable = true;\r
+       t.Port = ToInt(GetParamStr(o, "[port]"));\r
+\r
+       ret = ScEnableListener(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// コンソールテーブルの 1 行を描画\r
+void CtPrintRow(CONSOLE *c, UINT num, UINT *widths, wchar_t **strings, bool *rights, char separate_char)\r
+{\r
+       UINT i;\r
+       wchar_t *buf;\r
+       UINT buf_size;\r
+       bool is_sep_line = true;\r
+       // 引数チェック\r
+       if (c == NULL || num == 0 || widths == NULL || strings == NULL || rights == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       buf_size = 32;\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               buf_size += sizeof(wchar_t) * widths[i] + 6;\r
+       }\r
+\r
+       buf = ZeroMalloc(buf_size);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               char *tmp;\r
+               wchar_t *space_string;\r
+               UINT w;\r
+               UINT space = 0;\r
+               wchar_t *string = strings[i];\r
+               wchar_t *tmp_line = NULL;\r
+\r
+               if (UniStrCmpi(string, L"---") == 0)\r
+               {\r
+                       char *s = MakeCharArray('-', widths[i]);\r
+                       tmp_line = string = CopyStrToUni(s);\r
+\r
+                       Free(s);\r
+               }\r
+               else\r
+               {\r
+                       is_sep_line = false;\r
+               }\r
+\r
+               w = UniStrWidth(string);\r
+\r
+               if (widths[i] >= w)\r
+               {\r
+                       space = widths[i] - w;\r
+               }\r
+\r
+               tmp = MakeCharArray(' ', space);\r
+               space_string = CopyStrToUni(tmp);\r
+\r
+               if (rights[i] != false)\r
+               {\r
+                       UniStrCat(buf, buf_size, space_string);\r
+               }\r
+\r
+               UniStrCat(buf, buf_size, string);\r
+\r
+               if (rights[i] == false)\r
+               {\r
+                       UniStrCat(buf, buf_size, space_string);\r
+               }\r
+\r
+               Free(space_string);\r
+               Free(tmp);\r
+\r
+               if (i < (num - 1))\r
+               {\r
+                       wchar_t tmp[4];\r
+                       char str[2];\r
+\r
+                       if (UniStrCmpi(strings[i], L"---") == 0)\r
+                       {\r
+                               str[0] = '+';\r
+                       }\r
+                       else\r
+                       {\r
+                               str[0] = separate_char;\r
+                       }\r
+                       str[1] = 0;\r
+\r
+                       StrToUni(tmp, sizeof(tmp), str);\r
+\r
+                       UniStrCat(buf, buf_size, tmp);\r
+               }\r
+\r
+               if (tmp_line != NULL)\r
+               {\r
+                       Free(tmp_line);\r
+               }\r
+       }\r
+\r
+       UniTrimRight(buf);\r
+\r
+       if (is_sep_line)\r
+       {\r
+               if (UniStrLen(buf) > (c->GetWidth(c) - 1))\r
+               {\r
+                       buf[c->GetWidth(c) - 1] = 0;\r
+               }\r
+       }\r
+\r
+       c->Write(c, buf);\r
+\r
+       Free(buf);\r
+}\r
+\r
+// コンソール テーブルを標準形式で描画\r
+void CtPrintStandard(CT *ct, CONSOLE *c)\r
+{\r
+       CT *t;\r
+       UINT i, j;\r
+       // 引数チェック\r
+       if (ct == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = CtNewStandard();\r
+       for (i = 0;i < LIST_NUM(ct->Rows);i++)\r
+       {\r
+               CTR *row = LIST_DATA(ct->Rows, i);\r
+\r
+               for (j = 0;j < LIST_NUM(ct->Columns);j++)\r
+               {\r
+                       CTC *column = LIST_DATA(ct->Columns, j);\r
+\r
+                       CtInsert(t, column->String, row->Strings[j]);\r
+               }\r
+\r
+               if (i != (LIST_NUM(ct->Rows) - 1))\r
+               {\r
+                       CtInsert(t, L"---", L"---");\r
+               }\r
+       }\r
+\r
+       CtFree(t, c);\r
+}\r
+\r
+// コンソールテーブルの描画\r
+void CtPrint(CT *ct, CONSOLE *c)\r
+{\r
+       UINT *widths;\r
+       UINT num;\r
+       UINT i, j;\r
+       wchar_t **header_strings;\r
+       bool *rights;\r
+       // 引数チェック\r
+       if (ct == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       num = LIST_NUM(ct->Columns);\r
+       widths = ZeroMalloc(sizeof(UINT) * num);\r
+\r
+       // 各列の最大文字幅を計算する\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               CTC *ctc = LIST_DATA(ct->Columns, i);\r
+               UINT w;\r
+\r
+               w = UniStrWidth(ctc->String);\r
+               widths[i] = MAX(widths[i], w);\r
+       }\r
+       for (j = 0;j < LIST_NUM(ct->Rows);j++)\r
+       {\r
+               CTR *ctr = LIST_DATA(ct->Rows, j);\r
+\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       UINT w;\r
+\r
+                       w = UniStrWidth(ctr->Strings[i]);\r
+                       widths[i] = MAX(widths[i], w);\r
+               }\r
+       }\r
+\r
+       // ヘッダ部分を表示する\r
+       header_strings = ZeroMalloc(sizeof(wchar_t *) * num);\r
+       rights = ZeroMalloc(sizeof(bool) * num);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               CTC *ctc = LIST_DATA(ct->Columns, i);\r
+\r
+               header_strings[i] = ctc->String;\r
+               rights[i] = ctc->Right;\r
+       }\r
+\r
+       CtPrintRow(c, num, widths, header_strings, rights, '|');\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               char *s;\r
+\r
+               s = MakeCharArray('-', widths[i]);\r
+               header_strings[i] = CopyStrToUni(s);\r
+               Free(s);\r
+       }\r
+\r
+       CtPrintRow(c, num, widths, header_strings, rights, '+');\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               Free(header_strings[i]);\r
+       }\r
+\r
+       // データ部を表示する\r
+       for (j = 0;j < LIST_NUM(ct->Rows);j++)\r
+       {\r
+               CTR *ctr = LIST_DATA(ct->Rows, j);\r
+\r
+               CtPrintRow(c, num, widths, ctr->Strings, rights, '|');\r
+       }\r
+\r
+       Free(rights);\r
+       Free(header_strings);\r
+       Free(widths);\r
+}\r
+\r
+// CSV でのメタ文字をエスケープする\r
+void CtEscapeCsv(wchar_t *dst, UINT size, wchar_t *src){\r
+       UINT i;\r
+       UINT len = UniStrLen(src);\r
+       UINT idx;\r
+       BOOL need_to_escape = false;\r
+       wchar_t tmp[2]=L"*";\r
+\r
+       // 入力値のチェック\r
+       if (src==NULL || dst==NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 入力文字中にエスケープする必要のある文字が無ければそのまま出力にコピー\r
+       len = UniStrLen(src);\r
+       for (i=0; i<len; i++)\r
+       {\r
+               tmp[0] = src[i];\r
+               if (tmp[0] == L","[0] || tmp[0] == L"\n"[0] || tmp[0] == L"\""[0])\r
+               {\r
+                       need_to_escape = true;\r
+               }\r
+       }\r
+       if (need_to_escape == false)\r
+       {\r
+               UniStrCpy(dst,size,src);\r
+               return;\r
+       }\r
+\r
+       // メタ文字(改行、コンマ、ダブルクオート)を含んでいる場合は”で囲む\r
+       UniStrCpy(dst, size, L"\"");\r
+       idx = UniStrLen(dst);\r
+       if(idx<size-1)\r
+       {\r
+               for (i=0; i<len; i++)\r
+               {\r
+                       tmp[0] = src[i];\r
+                       // ”は””に変換する(MS-Excel方式)\r
+                       if (tmp[0] == L"\""[0])\r
+                       {\r
+                               UniStrCat(dst, size, tmp);\r
+                       }\r
+                       UniStrCat(dst, size, tmp);\r
+               }\r
+       }\r
+       UniStrCat(dst, size, L"\"");\r
+       return;\r
+}\r
+\r
+// コンソールテーブルの CSV 形式の表示\r
+void CtPrintCsv(CT *ct, CONSOLE *c)\r
+{\r
+       UINT i, j;\r
+       UINT num_columns = LIST_NUM(ct->Columns);\r
+       wchar_t buf[MAX_SIZE];\r
+       wchar_t fmtbuf[MAX_SIZE];\r
+\r
+       // 見出しの行を表示\r
+       buf[0] = 0;\r
+       for(i=0; i<num_columns; i++)\r
+       {\r
+               CTC *ctc = LIST_DATA(ct->Columns, i);\r
+               CtEscapeCsv(fmtbuf, MAX_SIZE, ctc->String);\r
+               UniStrCat(buf, MAX_SIZE, fmtbuf);\r
+               if(i != num_columns-1)\r
+                       UniStrCat(buf, MAX_SIZE, L",");\r
+       }\r
+       c->Write(c, buf);\r
+\r
+       // 表の本体を表示\r
+       for(j=0; j<LIST_NUM(ct->Rows); j++)\r
+       {\r
+               CTR *ctr = LIST_DATA(ct->Rows, j);\r
+               buf[0] = 0;\r
+               for(i=0; i<num_columns; i++)\r
+               {\r
+                       CtEscapeCsv(fmtbuf, MAX_SIZE, ctr->Strings[i]);\r
+                       UniStrCat(buf, MAX_SIZE, fmtbuf);\r
+                       if(i != num_columns-1)\r
+                               UniStrCat(buf, MAX_SIZE, L",");\r
+               }\r
+               c->Write(c, buf);\r
+       }\r
+}\r
+\r
+// コンソールテーブルの削除\r
+void CtFreeEx(CT *ct, CONSOLE *c, bool standard_view)\r
+{\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (ct == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (c != NULL)\r
+       {\r
+               if (c->ConsoleType == CONSOLE_CSV)\r
+               {\r
+                       CtPrintCsv(ct, c);\r
+               }\r
+               else\r
+               {\r
+                       if (standard_view == false)\r
+                       {\r
+                               CtPrint(ct, c);\r
+                       }\r
+                       else\r
+                       {\r
+                               CtPrintStandard(ct, c);\r
+                       }\r
+               }\r
+       }\r
+\r
+       num = LIST_NUM(ct->Columns);\r
+\r
+       for (i = 0;i < LIST_NUM(ct->Rows);i++)\r
+       {\r
+               UINT j;\r
+               CTR *ctr = LIST_DATA(ct->Rows, i);\r
+\r
+               for (j = 0;j < num;j++)\r
+               {\r
+                       Free(ctr->Strings[j]);\r
+               }\r
+\r
+               Free(ctr->Strings);\r
+               Free(ctr);\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(ct->Columns);i++)\r
+       {\r
+               CTC *ctc = LIST_DATA(ct->Columns, i);\r
+\r
+               Free(ctc->String);\r
+               Free(ctc);\r
+       }\r
+\r
+       ReleaseList(ct->Columns);\r
+       ReleaseList(ct->Rows);\r
+\r
+       Free(ct);\r
+}\r
+void CtFree(CT *ct, CONSOLE *c)\r
+{\r
+       CtFreeEx(ct, c, false);\r
+}\r
+\r
+// テーブルに行を追加\r
+void CtInsert(CT *ct, ...)\r
+{\r
+       CTR *ctr;\r
+       UINT num, i;\r
+       va_list va;\r
+       // 引数チェック\r
+       if (ct == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       num = LIST_NUM(ct->Columns);\r
+\r
+       va_start(va, ct);\r
+\r
+       ctr = ZeroMalloc(sizeof(CTR));\r
+       ctr->Strings = ZeroMalloc(sizeof(wchar_t *) * num);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               wchar_t *s = va_arg(va, wchar_t *);\r
+\r
+               ctr->Strings[i] = CopyUniStr(s);\r
+       }\r
+\r
+       va_end(va);\r
+\r
+       Insert(ct->Rows, ctr);\r
+}\r
+\r
+// テーブルにカラムを追加\r
+void CtInsertColumn(CT *ct, wchar_t *str, bool right)\r
+{\r
+       CTC *ctc;\r
+       // 引数チェック\r
+       if (ct == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (str == NULL)\r
+       {\r
+               str = L"";\r
+       }\r
+\r
+       ctc = ZeroMalloc(sizeof(CTC));\r
+       ctc->String = CopyUniStr(str);\r
+       ctc->Right = right;\r
+\r
+       Insert(ct->Columns, ctc);\r
+}\r
+\r
+// 新規コンソールテーブルの作成\r
+CT *CtNew()\r
+{\r
+       CT *ct;\r
+\r
+       ct = ZeroMalloc(sizeof(CT));\r
+       ct->Columns = NewList(NULL);\r
+       ct->Rows = NewList(NULL);\r
+\r
+       return ct;\r
+}\r
+\r
+// テーブルのカラムに標準的なカラムを追加する\r
+CT *CtNewStandard()\r
+{\r
+       CT *ct = CtNew();\r
+\r
+       CtInsertColumn(ct, _UU("CMD_CT_STD_COLUMN_1"), false);\r
+       CtInsertColumn(ct, _UU("CMD_CT_STD_COLUMN_2"), false);\r
+\r
+       return ct;\r
+}\r
+CT *CtNewStandardEx()\r
+{\r
+       CT *ct = CtNew();\r
+\r
+       CtInsertColumn(ct, _UU("CMD_CT_STD_COLUMN_1"), false);\r
+       CtInsertColumn(ct, _UU("CMD_CT_STD_COLUMN_2"), false);\r
+       CtInsertColumn(ct, _UU("CMD_CT_STD_COLUMN_3"), false);\r
+\r
+       return ct;\r
+}\r
+\r
+// TCP リスナー一覧の取得\r
+UINT PsListenerList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret;\r
+       RPC_LISTENER_LIST t;\r
+       UINT i;\r
+       CT *ct;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       ret = ScEnumListener(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       ct = CtNew();\r
+\r
+       CtInsertColumn(ct, _UU("CM_LISTENER_COLUMN_1"), false);\r
+       CtInsertColumn(ct, _UU("CM_LISTENER_COLUMN_2"), false);\r
+\r
+       for (i = 0;i < t.NumPort;i++)\r
+       {\r
+               wchar_t *status = _UU("CM_LISTENER_OFFLINE");\r
+               wchar_t tmp[128];\r
+\r
+               if (t.Errors[i])\r
+               {\r
+                       status = _UU("CM_LISTENER_ERROR");\r
+               }\r
+               else if (t.Enables[i])\r
+               {\r
+                       status = _UU("CM_LISTENER_ONLINE");\r
+               }\r
+\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_LISTENER_TCP_PORT"), t.Ports[i]);\r
+\r
+               CtInsert(ct, tmp, status);\r
+       }\r
+\r
+       CtFree(ct, c);\r
+\r
+       FreeRpcListenerList(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// TCP リスナーの削除\r
+UINT PsListenerDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret;\r
+       RPC_LISTENER t;\r
+       PARAM args[] =\r
+       {\r
+               {"[port]", CmdPromptPort, _UU("CMD_ListenerDelete_PortPrompt"), CmdEvalPort, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.Enable = true;\r
+       t.Port = ToInt(GetParamStr(o, "[port]"));\r
+\r
+       ret = ScDeleteListener(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 行を描画\r
+void CmdPrintRow(CONSOLE *c, wchar_t *title, wchar_t *tag, ...)\r
+{\r
+       wchar_t buf[MAX_SIZE * 2];\r
+       wchar_t buf2[MAX_SIZE * 2];\r
+       va_list args;\r
+       // 引数チェック\r
+       if (title == NULL || c == NULL || tag == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, tag);\r
+       UniFormatArgs(buf, sizeof(buf), tag, args);\r
+\r
+       UniFormat(buf2, sizeof(buf2), L"[%s] %s", title, buf);\r
+\r
+       va_end(args);\r
+\r
+       c->Write(c, buf2);\r
+}\r
+\r
+// ServerInfoGet コマンド\r
+UINT PsServerInfoGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret;\r
+       RPC_SERVER_INFO t;\r
+       CT *ct;\r
+       wchar_t tmp[MAX_SIZE];\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       ret = ScGetServerInfo(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       ct = CtNew();\r
+\r
+       CtInsertColumn(ct, _UU("SM_STATUS_COLUMN_1"), false);\r
+       CtInsertColumn(ct, _UU("SM_STATUS_COLUMN_2"), false);\r
+\r
+       // 製品名\r
+       StrToUni(tmp, sizeof(tmp), t.ServerProductName);\r
+       CtInsert(ct, _UU("SM_INFO_PRODUCT_NAME"), tmp);\r
+\r
+       // バージョン\r
+       StrToUni(tmp, sizeof(tmp), t.ServerVersionString);\r
+       CtInsert(ct, _UU("SM_INFO_VERSION"), tmp);\r
+\r
+       // ビルド\r
+       StrToUni(tmp, sizeof(tmp), t.ServerBuildInfoString);\r
+       CtInsert(ct, _UU("SM_INFO_BUILD"), tmp);\r
+\r
+       // ホスト名\r
+       StrToUni(tmp, sizeof(tmp), t.ServerHostName);\r
+       CtInsert(ct, _UU("SM_INFO_HOSTNAME"), tmp);\r
+\r
+       // 種類\r
+       CtInsert(ct, _UU("SM_ST_SERVER_TYPE"), GetServerTypeStr(t.ServerType));\r
+\r
+       // OS\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.OsSystemName);\r
+       CtInsert(ct, _UU("SM_OS_SYSTEM_NAME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.OsProductName);\r
+       CtInsert(ct, _UU("SM_OS_PRODUCT_NAME"), tmp);\r
+\r
+       if (t.OsInfo.OsServicePack != 0)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_OS_SP_TAG"), t.OsInfo.OsServicePack);\r
+               CtInsert(ct, _UU("SM_OS_SERVICE_PACK"), tmp);\r
+       }\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.OsVendorName);\r
+       CtInsert(ct, _UU("SM_OS_VENDER_NAME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.OsVersion);\r
+       CtInsert(ct, _UU("SM_OS_VERSION"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.KernelName);\r
+       CtInsert(ct, _UU("SM_OS_KERNEL_NAME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.KernelVersion);\r
+       CtInsert(ct, _UU("SM_OS_KERNEL_VERSION"), tmp);\r
+\r
+       CtFree(ct, c);\r
+\r
+       FreeRpcServerInfo(&t);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// HUB の種類の文字列を取得\r
+wchar_t *GetHubTypeStr(UINT type)\r
+{\r
+       if (type == HUB_TYPE_FARM_STATIC)\r
+       {\r
+               return _UU("SM_HUB_STATIC");\r
+       }\r
+       else if (type == HUB_TYPE_FARM_DYNAMIC)\r
+       {\r
+               return _UU("SM_HUB_DYNAMIC");\r
+       }\r
+       return _UU("SM_HUB_STANDALONE");\r
+}\r
+\r
+// サーバーの種類の文字列を取得\r
+wchar_t *GetServerTypeStr(UINT type)\r
+{\r
+       if (type == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               return _UU("SM_FARM_CONTROLLER");\r
+       }\r
+       else if (type == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return _UU("SM_FARM_MEMBER");\r
+       }\r
+       return _UU("SM_SERVER_STANDALONE");\r
+}\r
+\r
+// ServerStatusGet コマンド\r
+UINT PsServerStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret;\r
+       RPC_SERVER_STATUS t;\r
+       wchar_t tmp[MAX_PATH];\r
+       char tmp2[MAX_PATH];\r
+       CT *ct;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       ret = ScGetServerStatus(ps->Rpc, &t);\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       ct = CtNew();\r
+\r
+       CtInsertColumn(ct, _UU("SM_STATUS_COLUMN_1"), false);\r
+       CtInsertColumn(ct, _UU("SM_STATUS_COLUMN_2"), false);\r
+\r
+       // サーバーの種類\r
+       CtInsert(ct, _UU("SM_ST_SERVER_TYPE"),\r
+               t.ServerType == SERVER_TYPE_STANDALONE ? _UU("SM_SERVER_STANDALONE") :\r
+               t.ServerType == SERVER_TYPE_FARM_MEMBER ? _UU("SM_FARM_MEMBER") : _UU("SM_FARM_CONTROLLER"));\r
+\r
+       // TCP コネクション数\r
+       UniToStru(tmp, t.NumTcpConnections);\r
+       CtInsert(ct, _UU("SM_ST_NUM_TCP"), tmp);\r
+\r
+       if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               // ローカル TCP コネクション数\r
+               UniToStru(tmp, t.NumTcpConnectionsLocal);\r
+               CtInsert(ct, _UU("SM_ST_NUM_TCP_LOCAL"), tmp);\r
+\r
+               // リモート TCP コネクション数\r
+               UniToStru(tmp, t.NumTcpConnectionsRemote);\r
+               CtInsert(ct, _UU("SM_ST_NUM_TCP_REMOTE"), tmp);\r
+       }\r
+\r
+       // 仮想 HUB 数\r
+       UniToStru(tmp, t.NumHubTotal);\r
+       CtInsert(ct, _UU("SM_ST_NUM_HUB_TOTAL"), tmp);\r
+\r
+       if (t.ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               // スタティック HUB 数\r
+               UniToStru(tmp, t.NumHubStatic);\r
+               CtInsert(ct, _UU("SM_ST_NUM_HUB_STATIC"), tmp);\r
+\r
+               // ダイナミック HUB 数\r
+               UniToStru(tmp, t.NumHubDynamic);\r
+               CtInsert(ct, _UU("SM_ST_NUM_HUB_DYNAMIC"), tmp);\r
+       }\r
+\r
+       // セッション数\r
+       UniToStru(tmp, t.NumSessionsTotal);\r
+       CtInsert(ct, _UU("SM_ST_NUM_SESSION_TOTAL"), tmp);\r
+\r
+       if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               // ローカルセッション数\r
+               UniToStru(tmp, t.NumSessionsLocal);\r
+               CtInsert(ct, _UU("SM_ST_NUM_SESSION_LOCAL"), tmp);\r
+\r
+               // ローカルセッション数\r
+               UniToStru(tmp, t.NumSessionsRemote);\r
+               CtInsert(ct, _UU("SM_ST_NUM_SESSION_REMOTE"), tmp);\r
+       }\r
+\r
+       // MAC テーブル数\r
+       UniToStru(tmp, t.NumMacTables);\r
+       CtInsert(ct, _UU("SM_ST_NUM_MAC_TABLE"), tmp);\r
+\r
+       // IP テーブル数\r
+       UniToStru(tmp, t.NumIpTables);\r
+       CtInsert(ct, _UU("SM_ST_NUM_IP_TABLE"), tmp);\r
+\r
+       // ユーザー数\r
+       UniToStru(tmp, t.NumUsers);\r
+       CtInsert(ct, _UU("SM_ST_NUM_USERS"), tmp);\r
+\r
+       // グループ数\r
+       UniToStru(tmp, t.NumGroups);\r
+       CtInsert(ct, _UU("SM_ST_NUM_GROUPS"), tmp);\r
+\r
+       // 割り当て済みライセンス数\r
+       UniToStru(tmp, t.AssignedClientLicenses);\r
+       CtInsert(ct, _UU("SM_ST_CLIENT_LICENSE"), tmp);\r
+\r
+       UniToStru(tmp, t.AssignedBridgeLicenses);\r
+       CtInsert(ct, _UU("SM_ST_BRIDGE_LICENSE"), tmp);\r
+\r
+       if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               UniToStru(tmp, t.AssignedClientLicensesTotal);\r
+               CtInsert(ct, _UU("SM_ST_CLIENT_LICENSE_EX"), tmp);\r
+\r
+               UniToStru(tmp, t.AssignedBridgeLicensesTotal);\r
+               CtInsert(ct, _UU("SM_ST_BRIDGE_LICENSE_EX"), tmp);\r
+       }\r
+\r
+       // トラフィック\r
+       CmdInsertTrafficInfo(ct, &t.Traffic);\r
+\r
+       // サーバー起動時刻\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.StartTime), NULL);\r
+       CtInsert(ct, _UU("SM_ST_START_TIME"), tmp);\r
+\r
+       // 現在時刻\r
+       GetDateTimeStrMilli64(tmp2, sizeof(tmp2), SystemToLocal64(t.CurrentTime));\r
+       StrToUni(tmp, sizeof(tmp), tmp2);\r
+       CtInsert(ct, _UU("SM_ST_CURRENT_TIME"), tmp);\r
+\r
+       // Tick 値\r
+       UniFormat(tmp, sizeof(tmp), L"%I64u", t.CurrentTick);\r
+       CtInsert(ct, _UU("SM_ST_CURRENT_TICK"), tmp);\r
+\r
+       // メモリ情報\r
+       if (t.MemInfo.TotalMemory != 0)\r
+       {\r
+               char vv[128];\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.TotalMemory);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               CtInsert(ct, _UU("SM_ST_TOTAL_MEMORY"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.UsedMemory);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               CtInsert(ct, _UU("SM_ST_USED_MEMORY"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.FreeMemory);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               CtInsert(ct, _UU("SM_ST_FREE_MEMORY"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.TotalPhys);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               CtInsert(ct, _UU("SM_ST_TOTAL_PHYS"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.UsedPhys);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               CtInsert(ct, _UU("SM_ST_USED_PHYS"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.FreePhys);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               CtInsert(ct, _UU("SM_ST_FREE_PHYS"), tmp);\r
+       }\r
+\r
+       CtFree(ct, c);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// トラフィック情報を LVB に追加\r
+void CmdInsertTrafficInfo(CT *ct, TRAFFIC *t)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       char vv[128];\r
+       // 引数チェック\r
+       if (ct == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 送信情報\r
+       ToStr3(vv, sizeof(vv), t->Send.UnicastCount);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_NUM_PACKET_STR"), vv);\r
+       CtInsert(ct, _UU("SM_ST_SEND_UCAST_NUM"), tmp);\r
+\r
+       ToStr3(vv, sizeof(vv), t->Send.UnicastBytes);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_SIZE_BYTE_STR"), vv);\r
+       CtInsert(ct, _UU("SM_ST_SEND_UCAST_SIZE"), tmp);\r
+\r
+       ToStr3(vv, sizeof(vv), t->Send.BroadcastCount);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_NUM_PACKET_STR"), vv);\r
+       CtInsert(ct, _UU("SM_ST_SEND_BCAST_NUM"), tmp);\r
+\r
+       ToStr3(vv, sizeof(vv), t->Send.BroadcastBytes);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_SIZE_BYTE_STR"), vv);\r
+       CtInsert(ct, _UU("SM_ST_SEND_BCAST_SIZE"), tmp);\r
+\r
+       // 受信情報\r
+       ToStr3(vv, sizeof(vv), t->Recv.UnicastCount);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_NUM_PACKET_STR"), vv);\r
+       CtInsert(ct, _UU("SM_ST_RECV_UCAST_NUM"), tmp);\r
+\r
+       ToStr3(vv, sizeof(vv), t->Recv.UnicastBytes);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_SIZE_BYTE_STR"), vv);\r
+       CtInsert(ct, _UU("SM_ST_RECV_UCAST_SIZE"), tmp);\r
+\r
+       ToStr3(vv, sizeof(vv), t->Recv.BroadcastCount);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_NUM_PACKET_STR"), vv);\r
+       CtInsert(ct, _UU("SM_ST_RECV_BCAST_NUM"), tmp);\r
+\r
+       ToStr3(vv, sizeof(vv), t->Recv.BroadcastBytes);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_SIZE_BYTE_STR"), vv);\r
+       CtInsert(ct, _UU("SM_ST_RECV_BCAST_SIZE"), tmp);\r
+}\r
+\r
+// ポート番号の入力\r
+wchar_t *CmdPromptPort(CONSOLE *c, void *param)\r
+{\r
+       wchar_t *prompt_str;\r
+\r
+       if (param != NULL)\r
+       {\r
+               prompt_str = (wchar_t *)param;\r
+       }\r
+       else\r
+       {\r
+               prompt_str = _UU("CMD_PROPMT_PORT");\r
+       }\r
+\r
+       return c->ReadLine(c, prompt_str, true);\r
+}\r
+\r
+// ポート番号の検証\r
+bool CmdEvalPort(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       i = UniToInt(str);\r
+\r
+       if (i >= 1 && i <= 65535)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       c->Write(c, _UU("CMD_EVAL_PORT"));\r
+\r
+       return false;\r
+}\r
+\r
+// ListenerCreate コマンド\r
+UINT PsListenerCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       PS *ps = (PS *)param;\r
+       UINT ret;\r
+       RPC_LISTENER t;\r
+       PARAM args[] =\r
+       {\r
+               {"[port]", CmdPromptPort, _UU("CMD_ListenerCreate_PortPrompt"), CmdEvalPort, NULL},\r
+       };\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.Enable = true;\r
+       t.Port = ToInt(GetParamStr(o, "[port]"));\r
+\r
+       ret = ScCreateListener(ps->Rpc, &t);\r
+\r
+       if (ret != ERR_NO_ERROR)\r
+       {\r
+               CmdPrintError(c, ret);\r
+               FreeParamValueList(o);\r
+               return ret;\r
+       }\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// About コマンド\r
+UINT PsAbout(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+\r
+       o = ParseCommandList(c, cmd_name, str, NULL, 0);\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // バージョン情報を表示する\r
+       CmdPrintAbout(c);\r
+\r
+       FreeParamValueList(o);\r
+\r
+       return 0;\r
+}\r
+\r
+// 新しいサーバー管理コンテキストの作成\r
+PS *NewPs(CONSOLE *c, RPC *rpc, char *servername, UINT serverport, char *hubname, char *adminhub, wchar_t *cmdline)\r
+{\r
+       PS *ps;\r
+       // 引数チェック\r
+       if (c == NULL || rpc == NULL || servername == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (IsEmptyStr(hubname))\r
+       {\r
+               hubname = NULL;\r
+       }\r
+       if (IsEmptyStr(adminhub))\r
+       {\r
+               adminhub = NULL;\r
+       }\r
+       if (UniIsEmptyStr(cmdline))\r
+       {\r
+               cmdline = NULL;\r
+       }\r
+\r
+       ps = ZeroMalloc(sizeof(PS));\r
+       ps->ConsoleForServer = true;\r
+       ps->ServerPort = serverport;\r
+       ps->ServerName = CopyStr(servername);\r
+       ps->Console = c;\r
+       ps->Rpc = rpc;\r
+       ps->HubName = CopyStr(hubname);\r
+       ps->LastError = 0;\r
+       ps->AdminHub = CopyStr(adminhub);\r
+       ps->CmdLine = CopyUniStr(cmdline);\r
+\r
+       return ps;\r
+}\r
+\r
+// サーバー管理コンテキストの解放\r
+void FreePs(PS *ps)\r
+{\r
+       // 引数チェック\r
+       if (ps == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(ps->HubName);\r
+       Free(ps->AdminHub);\r
+       Free(ps->CmdLine);\r
+       Free(ps->ServerName);\r
+\r
+       Free(ps);\r
+}\r
+\r
+// サーバー管理ツール\r
+UINT PsConnect(CONSOLE *c, char *host, UINT port, char *hub, char *adminhub, wchar_t *cmdline, char *password)\r
+{\r
+       UINT retcode = 0;\r
+       RPC *rpc = NULL;\r
+       CEDAR *cedar;\r
+       CLIENT_OPTION o;\r
+       UCHAR hashed_password[SHA1_SIZE];\r
+       bool b = false;\r
+       // 引数チェック\r
+       if (c == NULL || host == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+       if (port == 0)\r
+       {\r
+               port = 443;\r
+       }\r
+       if (hub != NULL)\r
+       {\r
+               adminhub = NULL;\r
+       }\r
+\r
+       cedar = NewCedar(NULL, NULL);\r
+\r
+       Zero(&o, sizeof(o));\r
+       UniStrCpy(o.AccountName, sizeof(o.AccountName), L"VPNCMD");\r
+       StrCpy(o.Hostname, sizeof(o.Hostname), host);\r
+       o.Port = port;\r
+       o.ProxyType = PROXY_DIRECT;\r
+\r
+       Hash(hashed_password, password, StrLen(password), true);\r
+\r
+       if (IsEmptyStr(password) == false)\r
+       {\r
+               b = true;\r
+       }\r
+\r
+       // 接続\r
+       while (true)\r
+       {\r
+               UINT err;\r
+\r
+               rpc = AdminConnectEx(cedar, &o, hub, hashed_password, &err, CEDAR_CUI_STR);\r
+               if (rpc == NULL)\r
+               {\r
+                       // 失敗\r
+                       retcode = err;\r
+\r
+                       if (err == ERR_ACCESS_DENIED)\r
+                       {\r
+                               char *pass;\r
+                               // パスワード違い\r
+                               if (b)\r
+                               {\r
+                                       // パスワードを入力させる\r
+                                       c->Write(c, _UU("CMD_UTVPNCMD_PASSWORD_1"));\r
+                               }\r
+\r
+                               b = true;\r
+\r
+                               pass = c->ReadPassword(c, _UU("CMD_UTVPNCMD_PASSWORD_2"));\r
+                               c->Write(c, L"");\r
+\r
+                               if (pass != NULL)\r
+                               {\r
+                                       Hash(hashed_password, pass, StrLen(pass), true);\r
+                                       Free(pass);\r
+                               }\r
+                               else\r
+                               {\r
+                                       break;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // その他のエラー\r
+                               CmdPrintError(c, err);\r
+                               break;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       PS *ps;\r
+\r
+                       // 成功\r
+                       ps = NewPs(c, rpc, host, port, hub, adminhub, cmdline);\r
+                       PsMain(ps);\r
+                       retcode = ps->LastError;\r
+                       FreePs(ps);\r
+                       AdminDisconnect(rpc);\r
+                       break;\r
+               }\r
+       }\r
+\r
+       ReleaseCedar(cedar);\r
+\r
+       return retcode;\r
+}\r
+\r
+// エラーを表示する\r
+void CmdPrintError(CONSOLE *c, UINT err)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniFormat(tmp, sizeof(tmp), _UU("CMD_UTVPNCMD_ERROR"),\r
+               err, GetUniErrorStr(err));\r
+       c->Write(c, tmp);\r
+\r
+       if (err == ERR_DISCONNECTED)\r
+       {\r
+               c->Write(c, _UU("CMD_DISCONNECTED_MSG"));\r
+       }\r
+}\r
+\r
+// バージョン情報を表示する\r
+void CmdPrintAbout(CONSOLE *c)\r
+{\r
+       CEDAR *cedar;\r
+       wchar_t tmp[MAX_SIZE];\r
+       char exe[MAX_PATH];\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       cedar = NewCedar(NULL, NULL);\r
+\r
+       GetExeName(exe, sizeof(exe));\r
+\r
+       UniFormat(tmp, sizeof(tmp), _UU("CMD_UTVPNCMD_ABOUT"),\r
+               cedar->VerString, cedar->BuildInfo);\r
+\r
+       c->Write(c, tmp);\r
+\r
+       ReleaseCedar(cedar);\r
+}\r
+\r
+// ホスト名とポート番号をパースする (@ で区切る)\r
+bool ParseHostPortAtmark(char *src, char **host, UINT *port, UINT default_port)\r
+{\r
+       TOKEN_LIST *t;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       t = ParseToken(src, "@");\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (port != NULL)\r
+       {\r
+               *port = 0;\r
+       }\r
+\r
+       if (default_port == 0)\r
+       {\r
+               if (t->NumTokens < 2)\r
+               {\r
+                       FreeToken(t);\r
+                       return false;\r
+               }\r
+\r
+               if (ToInt(t->Token[1]) == 0)\r
+               {\r
+                       FreeToken(t);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       if (t->NumTokens >= 2 && ToInt(t->Token[1]) == 0)\r
+       {\r
+               FreeToken(t);\r
+               return false;\r
+       }\r
+\r
+       if (t->NumTokens >= 1 && IsEmptyStr(t->Token[0]) == false)\r
+       {\r
+               ret = true;\r
+\r
+               if (host != NULL)\r
+               {\r
+                       *host = CopyStr(t->Token[0]);\r
+                       Trim(*host);\r
+               }\r
+\r
+               if (t->NumTokens >= 2)\r
+               {\r
+                       if (port != NULL)\r
+                       {\r
+                               *port = ToInt(t->Token[1]);\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (port != NULL)\r
+       {\r
+               if (*port == 0)\r
+               {\r
+                       *port = default_port;\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// ホスト名とポート番号をパースする\r
+bool ParseHostPort(char *src, char **host, UINT *port, UINT default_port)\r
+{\r
+       TOKEN_LIST *t;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StartWith(src, "["))\r
+       {\r
+               if (InStr(src, "]"))\r
+               {\r
+                       // [target]:port の形式\r
+                       UINT i, n;\r
+                       char tmp[MAX_SIZE];\r
+\r
+                       StrCpy(tmp, sizeof(tmp), src);\r
+\r
+                       n = SearchStrEx(tmp, "]", 0, false);\r
+                       if (n != INFINITE)\r
+                       {\r
+                               UINT len = StrLen(tmp);\r
+\r
+                               for (i = n;i < len;i++)\r
+                               {\r
+                                       if (tmp[i] == ':')\r
+                                       {\r
+                                               tmp[i] = '@';\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       return ParseHostPortAtmark(tmp, host, port, default_port);\r
+               }\r
+       }\r
+\r
+       if (InStr(src, "@"))\r
+       {\r
+               // @ で区切られている\r
+               return ParseHostPortAtmark(src, host, port, default_port);\r
+       }\r
+\r
+       t = ParseToken(src, ":");\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (port != NULL)\r
+       {\r
+               *port = 0;\r
+       }\r
+\r
+       if (default_port == 0)\r
+       {\r
+               if (t->NumTokens < 2)\r
+               {\r
+                       FreeToken(t);\r
+                       return false;\r
+               }\r
+\r
+               if (ToInt(t->Token[1]) == 0)\r
+               {\r
+                       FreeToken(t);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       if (t->NumTokens >= 2 && ToInt(t->Token[1]) == 0)\r
+       {\r
+               FreeToken(t);\r
+               return false;\r
+       }\r
+\r
+       if (t->NumTokens >= 1 && IsEmptyStr(t->Token[0]) == false)\r
+       {\r
+               ret = true;\r
+\r
+               if (host != NULL)\r
+               {\r
+                       *host = CopyStr(t->Token[0]);\r
+                       Trim(*host);\r
+               }\r
+\r
+               if (t->NumTokens >= 2)\r
+               {\r
+                       if (port != NULL)\r
+                       {\r
+                               *port = ToInt(t->Token[1]);\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (port != NULL)\r
+       {\r
+               if (*port == 0)\r
+               {\r
+                       *port = default_port;\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// vpncmd コマンドプロシージャ\r
+UINT VpnCmdProc(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)\r
+{\r
+       LIST *o;\r
+       char *target;\r
+       bool server = false;\r
+       bool client = false;\r
+       bool tools = false;\r
+       char *hostname = NULL;\r
+       char *password;\r
+       wchar_t *cmdline;\r
+       bool host_inputted = false;\r
+       UINT port = 0;\r
+       UINT retcode = 0;\r
+       PARAM args[] =\r
+       {\r
+               {"[host:port]", NULL, NULL, NULL, NULL},\r
+               {"CLIENT", NULL, NULL, NULL, NULL},\r
+               {"SERVER", NULL, NULL, NULL, NULL},\r
+               {"TOOLS", NULL, NULL, NULL, NULL},\r
+               {"HUB", NULL, NULL, NULL, NULL},\r
+               {"ADMINHUB", NULL, NULL, NULL, NULL},\r
+               {"PASSWORD", NULL, NULL, NULL, NULL},\r
+               {"IN", NULL, NULL, NULL, NULL},\r
+               {"OUT", NULL, NULL, NULL, NULL},\r
+               {"CMD", NULL, NULL, NULL, NULL},\r
+               {"CSV", NULL, NULL, NULL, NULL},\r
+       };\r
+\r
+       if (c->ConsoleType == CONSOLE_LOCAL)\r
+       {\r
+               // 起動パス情報の初期化\r
+               VpnCmdInitBootPath();\r
+       }\r
+\r
+       if(c->ConsoleType != CONSOLE_CSV)\r
+       {\r
+               CmdPrintAbout(c);\r
+               c->Write(c, L"");\r
+       }\r
+\r
+       o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));\r
+\r
+       if (o == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // Client か Server か Tools かの指定\r
+       if ((GetParamStr(o, "CLIENT") == NULL && GetParamStr(o, "SERVER") == NULL && GetParamStr(o, "TOOLS") == NULL) ||\r
+               (GetParamStr(o, "CLIENT") != NULL && GetParamStr(o, "SERVER") != NULL && GetParamStr(o, "TOOLS") != NULL))\r
+       {\r
+               wchar_t *ret;\r
+               UINT code;\r
+               // Client か Server か Tools かが指定されていない\r
+               c->Write(c, _UU("CMD_UTVPNCMD_CS_1"));\r
+\r
+               ret = c->ReadLine(c, _UU("CMD_UTVPNCMD_CS_2"), true);\r
+\r
+               code = UniToInt(ret);\r
+               Free(ret);\r
+\r
+               switch (code)\r
+               {\r
+               case 1:\r
+                       // Server\r
+                       server = true;\r
+                       break;\r
+\r
+               case 2:\r
+                       // Client\r
+                       client = true;\r
+                       break;\r
+\r
+               case 3:\r
+                       // Tools\r
+                       tools = true;\r
+                       break;\r
+\r
+               default:\r
+                       // 指定無し\r
+                       FreeParamValueList(o);\r
+                       return ERR_USER_CANCEL;\r
+               }\r
+\r
+               c->Write(c, L"");\r
+       }\r
+       else\r
+       {\r
+               if (GetParamStr(o, "SERVER") != NULL)\r
+               {\r
+                       server = true;\r
+               }\r
+               else if (GetParamStr(o, "CLIENT") != NULL)\r
+               {\r
+                       client = true;\r
+               }\r
+               else\r
+               {\r
+                       tools = true;\r
+               }\r
+       }\r
+\r
+       // 接続先ホスト名\r
+       target = CopyStr(GetParamStr(o, "[host:port]"));\r
+\r
+       if (target == NULL && tools == false)\r
+       {\r
+               wchar_t *str;\r
+               // ホスト名を入力させる\r
+               if (server)\r
+               {\r
+                       c->Write(c, _UU("CMD_UTVPNCMD_HOST_1"));\r
+               }\r
+               else if (client)\r
+               {\r
+                       c->Write(c, _UU("CMD_UTVPNCMD_HOST_2"));\r
+               }\r
+\r
+               str = c->ReadLine(c, _UU("CMD_UTVPNCMD_HOST_3"), true);\r
+               c->Write(c, L"");\r
+               target = CopyUniToStr(str);\r
+               Free(str);\r
+\r
+               if (target == NULL)\r
+               {\r
+                       // キャンセル\r
+                       FreeParamValueList(o);\r
+                       return ERR_USER_CANCEL;\r
+               }\r
+\r
+               if (IsEmptyStr(target))\r
+               {\r
+                       Free(target);\r
+                       target = CopyStr("localhost");\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // ユーザーがホスト名を指定した\r
+               host_inputted = true;\r
+       }\r
+\r
+       if (tools == false)\r
+       {\r
+               if (ParseHostPort(target, &hostname, &port, 443) == false)\r
+               {\r
+                       c->Write(c, _UU("CMD_MSG_INVALID_HOSTNAME"));\r
+                       Free(target);\r
+                       FreeParamValueList(o);\r
+                       return ERR_INVALID_PARAMETER;\r
+               }\r
+       }\r
+\r
+       // パスワード\r
+       password = GetParamStr(o, "PASSWORD");\r
+       if (password == NULL)\r
+       {\r
+               password = "";\r
+       }\r
+\r
+       // コマンドライン\r
+       cmdline = GetParamUniStr(o, "CMD");\r
+\r
+       if (server)\r
+       {\r
+               // サーバーとしての処理\r
+               char *hub;\r
+               char *adminhub = NULL;\r
+\r
+               hub = CopyStr(GetParamStr(o, "HUB"));\r
+               adminhub = GetParamStr(o, "ADMINHUB");\r
+\r
+               // 仮想 HUB 管理モードで指定する仮想 HUB を決定する\r
+               if (hub == NULL)\r
+               {\r
+                       if (host_inputted == false)\r
+                       {\r
+                               wchar_t *s;\r
+                               // ユーザーがホスト名をコマンドラインで指定していない場合は\r
+                               // プロンプトを表示して仮想 HUB 名も取得する\r
+                               c->Write(c, _UU("CMD_UTVPNCMD_HUB_1"));\r
+\r
+                               s = c->ReadLine(c, _UU("CMD_UTVPNCMD_HUB_2"), true);\r
+\r
+                               hub = CopyUniToStr(s);\r
+                               Free(s);\r
+                       }\r
+               }\r
+\r
+               if (IsEmptyStr(hub))\r
+               {\r
+                       Free(hub);\r
+                       hub = NULL;\r
+               }\r
+               if (IsEmptyStr(adminhub))\r
+               {\r
+                       adminhub = NULL;\r
+               }\r
+\r
+               retcode = PsConnect(c, hostname, port, hub, adminhub, cmdline, password);\r
+\r
+               Free(hub);\r
+       }\r
+       else if (client)\r
+       {\r
+               // クライアントとしての処理\r
+               Trim(target);\r
+\r
+               retcode = PcConnect(c, target, cmdline, password);\r
+       }\r
+       else if (tools)\r
+       {\r
+               // VPN Tools として処理\r
+               retcode = PtConnect(c, cmdline);\r
+       }\r
+\r
+       Free(hostname);\r
+       Free(target);\r
+       FreeParamValueList(o);\r
+\r
+       return retcode;\r
+}\r
+\r
+// vpncmd のエントリポイント\r
+UINT CommandMain(wchar_t *command_line)\r
+{\r
+       UINT ret = 0;\r
+       wchar_t *infile, *outfile;\r
+       char *a_infile, *a_outfile;\r
+       wchar_t *csvmode;\r
+       CONSOLE *c;\r
+\r
+       // 引数チェック\r
+       if (command_line == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       // /in と /out の項目だけ先読みする\r
+       infile = ParseCommand(command_line, L"in");\r
+       outfile = ParseCommand(command_line, L"out");\r
+       if (UniIsEmptyStr(infile))\r
+       {\r
+               Free(infile);\r
+               infile = NULL;\r
+       }\r
+       if (UniIsEmptyStr(outfile))\r
+       {\r
+               Free(outfile);\r
+               outfile = NULL;\r
+       }\r
+\r
+       a_infile = CopyUniToStr(infile);\r
+       a_outfile = CopyUniToStr(outfile);\r
+\r
+       // ローカルコンソールの確保\r
+       c = NewLocalConsole(infile, outfile);\r
+       if (c != NULL)\r
+       {\r
+               // vpncmd コマンドの定義\r
+               CMD cmd[] =\r
+               {\r
+                       {"utvpncmd", VpnCmdProc},\r
+               };\r
+\r
+               // CSV モードを先読みしてチェック\r
+               csvmode = ParseCommand(command_line, L"csv");\r
+               if(csvmode != NULL)\r
+               {\r
+                       Free(csvmode);\r
+                       c->ConsoleType = CONSOLE_CSV;\r
+               }\r
+\r
+               if (DispatchNextCmdEx(c, command_line, ">", cmd, sizeof(cmd) / sizeof(cmd[0]), NULL) == false)\r
+               {\r
+                       ret = ERR_INVALID_PARAMETER;\r
+               }\r
+               else\r
+               {\r
+                       ret = c->RetCode;\r
+               }\r
+\r
+               // ローカルコンソールの解放\r
+               c->Free(c);\r
+       }\r
+       else\r
+       {\r
+               Print("Error: Couldn't open local console.\n");\r
+       }\r
+\r
+       Free(a_infile);\r
+       Free(a_outfile);\r
+       Free(infile);\r
+       Free(outfile);\r
+\r
+       return ret;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Command.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Command.h
new file mode 100644 (file)
index 0000000..8d3f093
--- /dev/null
@@ -0,0 +1,617 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Command.h\r
+// Command.c のヘッダ\r
+\r
+#ifndef        COMMAND_H\r
+#define        COMMAND_H\r
+\r
+// 定数\r
+#define        TRAFFIC_DEFAULT_PORT            9821\r
+#define        TRAFFIC_NUMTCP_MAX                      32\r
+#define        TRAFFIC_NUMTCP_DEFAULT          32\r
+#define        TRAFFIC_SPAN_DEFAULT            15\r
+#define        TRAFFIC_TYPE_DOWNLOAD           1\r
+#define        TRAFFIC_TYPE_UPLOAD                     2\r
+#define        TRAFFIC_TYPE_FULL                       0\r
+#define        TRAFFIC_BUF_SIZE                        65535\r
+#define        TRAFFIC_VER_STR_SIZE            16\r
+#define        TRAFFIC_VER_STR                         "TrafficServer\r\n"\r
+\r
+// Win32 用定数\r
+#define        VPNCMD_BOOTSTRAP_REG_KEYNAME    "Software\\SoftEther Corporation\\UT-VPN Command Line Utility"\r
+#define        VPNCMD_BOOTSTRAP_REG_VALUENAME_VER      "InstalledVersion"\r
+#define        VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH     "InstalledPath"\r
+#define        VPNCMD_BOOTSTRAP_FILENAME               "|utvpncmdsys.exe"\r
+#define        VPNCMD_BOOTSTRAP_FILENAME_X64   "|utvpncmdsys_x64.exe"\r
+#define        VPNCMD_BOOTSTRAP_FILENAME_IA64  "|utvpncmdsys_ia64.exe"\r
+\r
+\r
+// トラフィックテスト結果\r
+struct TT_RESULT\r
+{\r
+       bool Raw;                                       // 生データかどうか\r
+       bool Double;                            // 2 倍にしているかどうか\r
+       UINT64 NumBytesUpload;          // アップロードしたサイズ\r
+       UINT64 NumBytesDownload;        // ダウンロードしたサイズ\r
+       UINT64 NumBytesTotal;           // 合計サイズ\r
+       UINT64 Span;                            // 期間 (ミリ秒)\r
+       UINT64 BpsUpload;                       // アップロードスループット\r
+       UINT64 BpsDownload;                     // ダウンロードスループット\r
+       UINT64 BpsTotal;                        // 合計スループット\r
+};\r
+\r
+// 文字表示関数\r
+typedef void (TT_PRINT_PROC)(void *param, wchar_t *str);\r
+\r
+// クライアント側ソケット\r
+struct TTC_SOCK\r
+{\r
+       SOCK *Sock;                             // ソケット\r
+       UINT State;                             // ステート\r
+       UINT64 NumBytes;                // 伝送したバイト数\r
+       bool Download;                  // ダウンロードソケット\r
+       bool ServerUploadReportReceived;        // サーバーからのアップロード量レポートの受信完了\r
+       UINT64 NextSendRequestReportTick;       // 次にレポートをリクエストする時刻\r
+       UINT Id;\r
+};\r
+\r
+// トラフィックテストクライアント\r
+struct TTC\r
+{\r
+       TT_PRINT_PROC *Print;   // 文字表示関数\r
+       void *Param;                    // 任意のパラメータ\r
+       bool Double;                    // 2 倍モード\r
+       bool Raw;                               // 生データモード\r
+       UINT Port;                              // ポート番号\r
+       char Host[MAX_HOST_NAME_LEN + 1];       // ホスト名\r
+       UINT NumTcp;                    // TCP コネクション数\r
+       UINT Type;                              // 種類\r
+       UINT64 Span;                    // 期間\r
+       UINT64 RealSpan;                // 実際の期間\r
+       THREAD *Thread;                 // スレッド\r
+       volatile bool Halt;             // 停止フラグ\r
+       SOCK_EVENT *SockEvent;  // ソケットイベント\r
+       LIST *ItcSockList;              // クライアントソケットリスト\r
+       TT_RESULT Result;               // 結果\r
+       UINT ErrorCode;                 // エラーコード\r
+       bool AbnormalTerminated;        // 異常終了\r
+       EVENT *StartEvent;              // 開始イベント\r
+       EVENT *InitedEvent;             // 初期化完了通知イベント\r
+};\r
+\r
+// サーバー側ソケット\r
+struct TTS_SOCK\r
+{\r
+       SOCK *Sock;                             // ソケット\r
+       UINT State;                             // ステート\r
+       UINT64 NumBytes;                // 伝送したバイト数\r
+       bool SockJoined;                // イベントに追加されたかどうか\r
+       UINT Id;                                // ID\r
+       UINT64 LastWaitTick;    // クライアントにサイズ情報を通知するための再試行待機時間\r
+};\r
+\r
+// トラフィックテストサーバー\r
+struct TTS\r
+{\r
+       TT_PRINT_PROC *Print;   // 文字表示関数\r
+       void *Param;                    // 任意のパラメータ\r
+       volatile bool Halt;             // 停止フラグ\r
+       UINT Port;                              // ポート番号\r
+       THREAD *Thread;                 // スレッド\r
+       THREAD *WorkThread;             // ワーカースレッド\r
+       THREAD *IPv6AcceptThread;       // IPv6 Accept スレッド\r
+       SOCK *ListenSocket;             // 待機するソケット\r
+       SOCK *ListenSocketV6;   // 待機するソケット (IPv6)\r
+       UINT ErrorCode;                 // エラーコード\r
+       SOCK_EVENT *SockEvent;  // ソケットイベント\r
+       LIST *TtsSockList;              // サーバーソケットリスト\r
+       bool NewSocketArrived;  // 新しいソケットが到着している\r
+       UINT IdSeed;                    // ID 値\r
+};\r
+\r
+// VPN Tools コンテキスト\r
+struct PT\r
+{\r
+       CONSOLE *Console;       // コンソール\r
+       UINT LastError;         // 最後のエラー\r
+       wchar_t *CmdLine;       // 実行するコマンドライン\r
+};\r
+\r
+// サーバー管理コンテキスト\r
+struct PS\r
+{\r
+       bool ConsoleForServer;  // サーバーのためのコンソール (常に true)\r
+       CONSOLE *Console;       // コンソール\r
+       RPC *Rpc;                       // RPC\r
+       char *ServerName;       // サーバー名\r
+       UINT ServerPort;        // ポート番号\r
+       char *HubName;          // 現在管理対象にある仮想 HUB 名\r
+       UINT LastError;         // 最後のエラー\r
+       char *AdminHub;         // デフォルトで管理する仮想 HUB\r
+       wchar_t *CmdLine;       // 実行するコマンドライン\r
+       CAPSLIST *CapsList;     // Caps リスト\r
+};\r
+\r
+// クライアント管理コンテキスト\r
+struct PC\r
+{\r
+       bool ConsoleForServer;  // サーバーのためのコンソール (常に false)\r
+       CONSOLE *Console;       // コンソール\r
+       REMOTE_CLIENT *RemoteClient;    // リモートクライアント\r
+       char *ServerName;       // サーバー名\r
+       UINT LastError;         // 最後のエラー\r
+       wchar_t *CmdLine;       // コマンドライン\r
+};\r
+\r
+// テーブルのカラム\r
+struct CTC\r
+{\r
+       wchar_t *String;        // 文字列\r
+       bool Right;                     // 右寄せ\r
+};\r
+\r
+// テーブルの行\r
+struct CTR\r
+{\r
+       wchar_t **Strings;      // 文字列リスト\r
+};\r
+\r
+// コンソール用テーブル\r
+struct CT\r
+{\r
+       LIST *Columns;          // カラム一覧\r
+       LIST *Rows;                     // 行一覧\r
+};\r
+\r
+UINT CommandMain(wchar_t *command_line);\r
+UINT VpnCmdProc(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+bool ParseHostPort(char *src, char **host, UINT *port, UINT default_port);\r
+bool ParseHostPortAtmark(char *src, char **host, UINT *port, UINT default_port);\r
+CT *CtNew();\r
+void CtFree(CT *ct, CONSOLE *c);\r
+void CtFreeEx(CT *ct, CONSOLE *c, bool standard_view);\r
+void CtInsertColumn(CT *ct, wchar_t *str, bool right);\r
+CT *CtNewStandard();\r
+CT *CtNewStandardEx();\r
+void CtInsert(CT *ct, ...);\r
+void CtPrint(CT *ct, CONSOLE *c);\r
+void CtPrintStandard(CT *ct, CONSOLE *c);\r
+void CtPrintRow(CONSOLE *c, UINT num, UINT *widths, wchar_t **strings, bool *rights, char separate_char);\r
+void VpnCmdInitBootPath();\r
+void OutRpcTtResult(PACK *p, TT_RESULT *t);\r
+void InRpcTtResult(PACK *p, TT_RESULT *t);\r
+\r
+void CmdPrintError(CONSOLE *c, UINT err);\r
+void CmdPrintAbout(CONSOLE *c);\r
+void CmdPrintRow(CONSOLE *c, wchar_t *title, wchar_t *tag, ...);\r
+wchar_t *CmdPromptPort(CONSOLE *c, void *param);\r
+wchar_t *CmdPromptChoosePassword(CONSOLE *c, void *param);\r
+bool CmdEvalPort(CONSOLE *c, wchar_t *str, void *param);\r
+void CmdInsertTrafficInfo(CT *ct, TRAFFIC *t);\r
+wchar_t *GetHubTypeStr(UINT type);\r
+wchar_t *GetServerTypeStr(UINT type);\r
+char *CmdPasswordPrompt(CONSOLE *c);\r
+bool CmdEvalIp(CONSOLE *c, wchar_t *str, void *param);\r
+wchar_t *PsClusterSettingMemberPromptIp(CONSOLE *c, void *param);\r
+bool CmdEvalHostAndPort(CONSOLE *c, wchar_t *str, void *param);\r
+LIST *StrToPortList(char *str);\r
+bool CmdEvalPortList(CONSOLE *c, wchar_t *str, void *param);\r
+wchar_t *PsClusterSettingMemberPromptPorts(CONSOLE *c, void *param);\r
+K *CmdLoadKey(CONSOLE *c, char *filename);\r
+bool CmdLoadCertAndKey(CONSOLE *c, X **xx, K **kk, char *cert_filename, char *key_filename);\r
+bool CmdEvalTcpOrUdp(CONSOLE *c, wchar_t *str, void *param);\r
+wchar_t *GetConnectionTypeStr(UINT type);\r
+bool CmdEvalHostAndSubnetMask4(CONSOLE *c, wchar_t *str, void *param);\r
+bool CmdEvalNetworkAndSubnetMask4(CONSOLE *c, wchar_t *str, void *param);\r
+bool CmdEvalNetworkAndSubnetMask6(CONSOLE *c, wchar_t *str, void *param);\r
+bool CmdEvalNetworkAndSubnetMask46(CONSOLE *c, wchar_t *str, void *param);\r
+bool CmdEvalIpAndMask4(CONSOLE *c, wchar_t *str, void *param);\r
+bool CmdEvalIpAndMask6(CONSOLE *c, wchar_t *str, void *param);\r
+bool CmdEvalIpAndMask46(CONSOLE *c, wchar_t *str, void *param);\r
+wchar_t *GetLogSwitchStr(UINT i);\r
+wchar_t *GetPacketLogNameStr(UINT i);\r
+UINT StrToLogSwitchType(char *str);\r
+UINT StrToPacketLogType(char *str);\r
+UINT StrToPacketLogSaveInfoType(char *str);\r
+wchar_t *GetProxyTypeStr(UINT i);\r
+wchar_t *GetClientAuthTypeStr(UINT i);\r
+void PrintPolicyList(CONSOLE *c, char *name);\r
+void PrintPolicy(CONSOLE *c, POLICY *pol, bool cascade_mode);\r
+bool EditPolicy(CONSOLE *c, POLICY *pol, char *name, char *value, bool cascade_mode);\r
+void CmdPrintStatusToListView(CT *ct, RPC_CLIENT_GET_CONNECTION_STATUS *s);\r
+void CmdPrintStatusToListViewEx(CT *ct, RPC_CLIENT_GET_CONNECTION_STATUS *s, bool server_mode);\r
+bool CmdEvalPassOrDiscard(CONSOLE *c, wchar_t *str, void *param);\r
+bool StrToPassOrDiscard(char *str);\r
+bool CmdEvalProtocol(CONSOLE *c, wchar_t *str, void *param);\r
+UINT StrToProtocol(char *str);\r
+bool CmdEvalPortRange(CONSOLE *c, wchar_t *str, void *param);\r
+bool ParsePortRange(char *str, UINT *start, UINT *end);\r
+wchar_t *GetAuthTypeStr(UINT id);\r
+UINT64 StrToDateTime64(char *str);\r
+bool CmdEvalDateTime(CONSOLE *c, wchar_t *str, void *param);\r
+void CmdPrintNodeInfo(CT *ct, NODE_INFO *info);\r
+wchar_t *GetProtocolName(UINT n);\r
+void CmdGenerateImportName(REMOTE_CLIENT *r, wchar_t *name, UINT size, wchar_t *old_name);\r
+bool CmdIsAccountName(REMOTE_CLIENT *r, wchar_t *name);\r
+wchar_t *GetSyslogSettingName(UINT n);\r
+\r
+\r
+void TtPrint(void *param, TT_PRINT_PROC *print_proc, wchar_t *str);\r
+void TtGenerateRandomData(UCHAR **buf, UINT *size);\r
+void TtsWorkerThread(THREAD *thread, void *param);\r
+void TtsListenThread(THREAD *thread, void *param);\r
+void TtsAcceptProc(TTS *tts, SOCK *listen_socket);\r
+void TtsIPv6AcceptThread(THREAD *thread, void *param);\r
+wchar_t *GetTtcTypeStr(UINT type);\r
+void TtcPrintSummary(TTC *ttc);\r
+void StopTtc(TTC *ttc);\r
+void TtcGenerateResult(TTC *ttc);\r
+void TtcThread(THREAD *thread, void *param);\r
+TTC *NewTtcEx(char *host, UINT port, UINT numtcp, UINT type, UINT64 span, bool dbl, bool raw, TT_PRINT_PROC *print_proc, void *param, EVENT *start_event);\r
+TTC *NewTtc(char *host, UINT port, UINT numtcp, UINT type, UINT64 span, bool dbl, bool raw, TT_PRINT_PROC *print_proc, void *param);\r
+UINT FreeTtc(TTC *ttc, TT_RESULT *result);\r
+TTS *NewTts(UINT port, void *param, TT_PRINT_PROC *print_proc);\r
+UINT FreeTts(TTS *tts);\r
+void PtTrafficPrintProc(void *param, wchar_t *str);\r
+void TtcPrintResult(CONSOLE *c, TT_RESULT *res);\r
+\r
+\r
+bool SystemCheck();\r
+bool CheckKernel();\r
+bool CheckMemory();\r
+bool CheckStrings();\r
+bool CheckFileSystem();\r
+bool CheckThread();\r
+bool CheckNetwork();\r
+void InputToNull(void *p);\r
+UINT RetZero();\r
+\r
+\r
+\r
+UINT PtConnect(CONSOLE *c, wchar_t *cmdline);\r
+PT *NewPt(CONSOLE *c, wchar_t *cmdline);\r
+void FreePt(PT *pt);\r
+void PtMain(PT *pt);\r
+UINT PtMakeCert(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PtTrafficClient(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PtTrafficServer(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PtCheck(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+\r
+\r
+UINT PcConnect(CONSOLE *c, char *target, wchar_t *cmdline, char *password);\r
+PC *NewPc(CONSOLE *c, REMOTE_CLIENT *remote_client, char *servername, wchar_t *cmdline);\r
+void FreePc(PC *pc);\r
+void PcMain(PC *pc);\r
+UINT PcAbout(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcVersionGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcPasswordGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcCertList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcCertAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcCertDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcSecureList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcSecureSelect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcSecureGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcNicCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcNicDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcNicUpgrade(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcNicGetSetting(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcNicSetSetting(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcNicEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcNicDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcNicList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountUsernameSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountAnonymousSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountEncryptDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountEncryptEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountCompressEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountCompressDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountProxyNone(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountProxyHttp(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountProxySocks(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountServerCertEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountServerCertDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountServerCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountServerCertDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountServerCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountDetailSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountRename(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountConnect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountDisconnect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountNicSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountStatusShow(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountStatusHide(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountSecureCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountRetrySet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountStartupSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountStartupRemove(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountExport(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcAccountImport(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcRemoteEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcRemoteDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcKeepEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcKeepDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcKeepSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PcKeepGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+\r
+\r
+PS *NewPs(CONSOLE *c, RPC *rpc, char *servername, UINT serverport, char *hubname, char *adminhub, wchar_t *cmdline);\r
+void FreePs(PS *ps);\r
+UINT PsConnect(CONSOLE *c, char *host, UINT port, char *hub, char *adminhub, wchar_t *cmdline, char *password);\r
+void PsMain(PS *ps);\r
+UINT PsAbout(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsServerInfoGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsServerStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsListenerCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsListenerDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsListenerList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsListenerEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsListenerDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsServerPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsClusterSettingGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsClusterSettingStandalone(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsClusterSettingController(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsClusterSettingMember(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsClusterMemberList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsClusterMemberInfoGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsClusterMemberCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsClusterConnectionStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCrash(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsFlush(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsDebug(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsServerCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsServerKeyGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsServerCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsServerCipherGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsServerCipherSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsKeepEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsKeepDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsKeepSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsKeepGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSyslogGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSyslogDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSyslogEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsConnectionList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsConnectionGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsConnectionDisconnect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsBridgeDeviceList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsBridgeList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsBridgeCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsBridgeDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCaps(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsReboot(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsConfigGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsConfigSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRouterList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRouterAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRouterDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRouterStart(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRouterStop(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRouterIfList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRouterIfAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRouterIfDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRouterTableList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRouterTableAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRouterTableDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsLogFileList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsLogFileGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsHubCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsHubCreateDynamic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsHubCreateStatic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsHubDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsHubSetStatic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsHubSetDynamic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsHubList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsHub(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsOnline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsOffline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSetMaxSession(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSetHubPassword(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSetEnumAllow(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSetEnumDeny(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsOptionsGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRadiusServerSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRadiusServerDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsRadiusServerGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsLogGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsLogEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsLogDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsLogSwitchSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsLogPacketSaveType(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCAList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCAAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCADelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCAGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeUsernameSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeAnonymousSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadePasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeEncryptEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeEncryptDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeCompressEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeCompressDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeProxyNone(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeProxyHttp(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeProxySocks(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeServerCertEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeServerCertDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeServerCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeServerCertDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeServerCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeDetailSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadePolicyRemove(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadePolicySet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsPolicyList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeRename(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeOnline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCascadeOffline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAccessAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAccessAddEx(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAccessAdd6(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAccessAddEx6(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAccessList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAccessDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAccessEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAccessDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserAnonymousSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserSignedSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserRadiusSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserNTLMSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserPolicyRemove(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserPolicySet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsUserExpiresSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsGroupList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsGroupCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsGroupSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsGroupDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsGroupGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsGroupJoin(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsGroupUnjoin(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsGroupPolicyRemove(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsGroupPolicySet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSessionList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSessionGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSessionDisconnect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsMacTable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsMacDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsIpTable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsIpDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSecureNatEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSecureNatDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSecureNatStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSecureNatHostGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsSecureNatHostSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsNatGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsNatEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsNatDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsNatSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsNatTable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsDhcpGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsDhcpEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsDhcpDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsDhcpSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsDhcpTable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAdminOptionList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAdminOptionSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsExtOptionList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsExtOptionSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCrlList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCrlAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCrlDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsCrlGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAcList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAcAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAcAdd6(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAcGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsAcDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsLicenseAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsLicenseDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsLicenseList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+UINT PsLicenseStatus(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+\r
+\r
+#endif // COMMAND_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Connection.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Connection.c
new file mode 100644 (file)
index 0000000..896052c
--- /dev/null
@@ -0,0 +1,2926 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Connection.c\r
+// コネクションマネージャ\r
+\r
+#include "CedarPch.h"\r
+\r
+// 送信に使用するかどうかの判別\r
+#define        IS_SEND_TCP_SOCK(ts)            \\r
+       ((ts->Direction == TCP_BOTH) || ((ts->Direction == TCP_SERVER_TO_CLIENT) && (s->ServerMode)) || ((ts->Direction == TCP_CLIENT_TO_SERVER) && (s->ServerMode == false)))\r
+\r
+// 受信に使用するかどうかの判別\r
+#define        IS_RECV_TCP_SOCK(ts)            \\r
+       ((ts->Direction == TCP_BOTH) || ((ts->Direction == TCP_SERVER_TO_CLIENT) && (s->ServerMode == false)) || ((ts->Direction == TCP_CLIENT_TO_SERVER) && (s->ServerMode)))\r
+\r
+// SECURE_SIGN の変換\r
+void InRpcSecureSign(SECURE_SIGN *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(SECURE_SIGN));\r
+       PackGetStr(p, "SecurePublicCertName", t->SecurePublicCertName, sizeof(t->SecurePublicCertName));\r
+       PackGetStr(p, "SecurePrivateKeyName", t->SecurePrivateKeyName, sizeof(t->SecurePrivateKeyName));\r
+       t->ClientCert = PackGetX(p, "ClientCert");\r
+       PackGetData2(p, "Random", t->Random, sizeof(t->Random));\r
+       PackGetData2(p, "Signature", t->Signature, sizeof(t->Signature));\r
+       t->UseSecureDeviceId = PackGetInt(p, "UseSecureDeviceId");\r
+       t->BitmapId = PackGetInt(p, "BitmapId");\r
+}\r
+void OutRpcSecureSign(PACK *p, SECURE_SIGN *t)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "SecurePublicCertName", t->SecurePublicCertName);\r
+       PackAddStr(p, "SecurePrivateKeyName", t->SecurePrivateKeyName);\r
+       PackAddX(p, "ClientCert", t->ClientCert);\r
+       PackAddData(p, "Random", t->Random, sizeof(t->Random));\r
+       PackAddData(p, "Signature", t->Signature, sizeof(t->Signature));\r
+       PackAddInt(p, "UseSecureDeviceId", t->UseSecureDeviceId);\r
+       PackAddInt(p, "BitmapId", t->BitmapId);\r
+}\r
+void FreeRpcSecureSign(SECURE_SIGN *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeX(t->ClientCert);\r
+}\r
+\r
+// 次のパケットを生成する\r
+BUF *NewKeepPacket(bool server_mode)\r
+{\r
+       BUF *b = NewBuf();\r
+       char *string = KEEP_ALIVE_STRING;\r
+\r
+       WriteBuf(b, string, StrLen(string));\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       return b;\r
+}\r
+\r
+// KEEP スレッド\r
+void KeepThread(THREAD *thread, void *param)\r
+{\r
+       KEEP *k = (KEEP *)param;\r
+       SOCK *s;\r
+       char server_name[MAX_HOST_NAME_LEN + 1];\r
+       UINT server_port;\r
+       bool udp_mode;\r
+       bool enabled;\r
+       // 引数チェック\r
+       if (thread == NULL || k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+WAIT_FOR_ENABLE:\r
+       Wait(k->HaltEvent, KEEP_POLLING_INTERVAL);\r
+\r
+       // 有効になるまで待機する\r
+       while (true)\r
+       {\r
+               enabled = false;\r
+               Lock(k->lock);\r
+               {\r
+                       if (k->Enable)\r
+                       {\r
+                               if (StrLen(k->ServerName) != 0 && k->ServerPort != 0 && k->Interval != 0)\r
+                               {\r
+                                       StrCpy(server_name, sizeof(server_name), k->ServerName);\r
+                                       server_port = k->ServerPort;\r
+                                       udp_mode = k->UdpMode;\r
+                                       enabled = true;\r
+                               }\r
+                       }\r
+               }\r
+               Unlock(k->lock);\r
+               if (enabled)\r
+               {\r
+                       break;\r
+               }\r
+               if (k->Halt)\r
+               {\r
+                       return;\r
+               }\r
+               Wait(k->HaltEvent, KEEP_POLLING_INTERVAL);\r
+       }\r
+\r
+       if (udp_mode == false)\r
+       {\r
+               // TCP モード\r
+               // 接続に成功するまで試行する\r
+               while (true)\r
+               {\r
+                       UINT64 connect_started_tick;\r
+                       bool changed = false;\r
+                       Lock(k->lock);\r
+                       {\r
+                               if (StrCmpi(k->ServerName, server_name) != 0 ||\r
+                                       k->ServerPort != server_port || k->Enable == false ||\r
+                                       k->UdpMode)\r
+                               {\r
+                                       changed = true;\r
+                               }\r
+                       }\r
+                       Unlock(k->lock);\r
+                       if (changed)\r
+                       {\r
+                               // 設定が変更された\r
+                               goto WAIT_FOR_ENABLE;\r
+                       }\r
+\r
+                       if (k->Halt)\r
+                       {\r
+                               // 停止\r
+                               return;\r
+                       }\r
+\r
+                       // サーバーへ接続を試行\r
+                       connect_started_tick = Tick64();\r
+                       s = ConnectEx2(server_name, server_port, KEEP_TCP_TIMEOUT, (bool *)&k->Halt);\r
+                       if (s != NULL)\r
+                       {\r
+                               // 接続成功\r
+                               break;\r
+                       }\r
+\r
+                       // 接続失敗 設定が変更されるかタイムアウトするまで待機する\r
+                       while (true)\r
+                       {\r
+                               changed = false;\r
+                               if (k->Halt)\r
+                               {\r
+                                       // 停止\r
+                                       return;\r
+                               }\r
+                               Lock(k->lock);\r
+                               {\r
+                                       if (StrCmpi(k->ServerName, server_name) != 0 ||\r
+                                               k->ServerPort != server_port || k->Enable == false ||\r
+                                               k->UdpMode)\r
+                                       {\r
+                                               changed = true;\r
+                                       }\r
+                               }\r
+                               Unlock(k->lock);\r
+\r
+                               if (changed)\r
+                               {\r
+                                       // 設定が変更された\r
+                                       goto WAIT_FOR_ENABLE;\r
+                               }\r
+\r
+                               if ((Tick64() - connect_started_tick) >= KEEP_RETRY_INTERVAL)\r
+                               {\r
+                                       break;\r
+                               }\r
+\r
+                               Wait(k->HaltEvent, KEEP_POLLING_INTERVAL);\r
+                       }\r
+               }\r
+\r
+               // サーバーへの接続に成功した\r
+               // 一定時間ごとにパケットデータを送受信する\r
+               if (s != NULL)\r
+               {\r
+                       UINT64 last_packet_sent_time = 0;\r
+                       while (true)\r
+                       {\r
+                               SOCKSET set;\r
+                               UINT ret;\r
+                               UCHAR buf[MAX_SIZE];\r
+                               bool changed;\r
+\r
+                               InitSockSet(&set);\r
+                               AddSockSet(&set, s);\r
+\r
+                               Select(&set, KEEP_POLLING_INTERVAL, k->Cancel, NULL);\r
+\r
+                               ret = Recv(s, buf, sizeof(buf), false);\r
+                               if (ret == 0)\r
+                               {\r
+                                       // 切断された\r
+                                       Disconnect(s);\r
+                                       ReleaseSock(s);\r
+                                       s = NULL;\r
+                               }\r
+\r
+                               if (s != NULL)\r
+                               {\r
+                                       if ((Tick64() - last_packet_sent_time) >= (UINT64)k->Interval)\r
+                                       {\r
+                                               BUF *b;\r
+\r
+                                               // 次のパケットを送出する\r
+                                               last_packet_sent_time = Tick64();\r
+\r
+                                               b = NewKeepPacket(k->Server);\r
+\r
+                                               ret = Send(s, b->Buf, b->Size, false);\r
+                                               FreeBuf(b);\r
+\r
+                                               if (ret == 0)\r
+                                               {\r
+                                                       // 切断された\r
+                                                       Disconnect(s);\r
+                                                       ReleaseSock(s);\r
+                                                       s = NULL;\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               changed = false;\r
+\r
+                               Lock(k->lock);\r
+                               {\r
+                                       if (StrCmpi(k->ServerName, server_name) != 0 ||\r
+                                               k->ServerPort != server_port || k->Enable == false ||\r
+                                               k->UdpMode)\r
+                                       {\r
+                                               changed = true;\r
+                                       }\r
+                               }\r
+                               Unlock(k->lock);\r
+\r
+                               if (changed || s == NULL)\r
+                               {\r
+                                       // 設定が変更された または 切断された\r
+                                       Disconnect(s);\r
+                                       ReleaseSock(s);\r
+                                       s = NULL;\r
+                                       goto WAIT_FOR_ENABLE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (k->Halt)\r
+                                       {\r
+                                               // 停止\r
+                                               Disconnect(s);\r
+                                               ReleaseSock(s);\r
+                                               return;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               IP dest_ip;\r
+               // UDP モード\r
+               // ソケット作成が成功するまで試行する\r
+               while (true)\r
+               {\r
+                       UINT64 connect_started_tick;\r
+                       bool changed = false;\r
+                       Lock(k->lock);\r
+                       {\r
+                               if (StrCmpi(k->ServerName, server_name) != 0 ||\r
+                                       k->ServerPort != server_port || k->Enable == false ||\r
+                                       k->UdpMode == false)\r
+                               {\r
+                                       changed = true;\r
+                               }\r
+                       }\r
+                       Unlock(k->lock);\r
+                       if (changed)\r
+                       {\r
+                               // 設定が変更された\r
+                               goto WAIT_FOR_ENABLE;\r
+                       }\r
+\r
+                       if (k->Halt)\r
+                       {\r
+                               // 停止\r
+                               return;\r
+                       }\r
+\r
+                       // ソケット作成を試行\r
+                       connect_started_tick = Tick64();\r
+\r
+                       // まず名前解決を試行\r
+                       if (GetIP(&dest_ip, server_name))\r
+                       {\r
+                               // 名前解決に成功したら、次にソケットを作成\r
+                               s = NewUDP(0);\r
+                               if (s != NULL)\r
+                               {\r
+                                       // 作成成功\r
+                                       break;\r
+                               }\r
+                       }\r
+\r
+                       // 作成失敗 設定が変更されるかタイムアウトするまで待機する\r
+                       while (true)\r
+                       {\r
+                               changed = false;\r
+                               if (k->Halt)\r
+                               {\r
+                                       // 停止\r
+                                       return;\r
+                               }\r
+                               Lock(k->lock);\r
+                               {\r
+                                       if (StrCmpi(k->ServerName, server_name) != 0 ||\r
+                                               k->ServerPort != server_port || k->Enable == false ||\r
+                                               k->UdpMode)\r
+                                       {\r
+                                               changed = true;\r
+                                       }\r
+                               }\r
+                               Unlock(k->lock);\r
+\r
+                               if (changed)\r
+                               {\r
+                                       // 設定が変更された\r
+                                       goto WAIT_FOR_ENABLE;\r
+                               }\r
+\r
+                               if ((Tick64() - connect_started_tick) >= KEEP_RETRY_INTERVAL)\r
+                               {\r
+                                       break;\r
+                               }\r
+\r
+                               Wait(k->HaltEvent, KEEP_POLLING_INTERVAL);\r
+                       }\r
+               }\r
+\r
+               // 一定時間ごとにパケットデータを送信する\r
+               if (s != NULL)\r
+               {\r
+                       UINT64 last_packet_sent_time = 0;\r
+                       while (true)\r
+                       {\r
+                               SOCKSET set;\r
+                               UINT ret;\r
+                               UCHAR buf[MAX_SIZE];\r
+                               bool changed;\r
+                               IP src_ip;\r
+                               UINT src_port;\r
+\r
+                               InitSockSet(&set);\r
+                               AddSockSet(&set, s);\r
+\r
+                               Select(&set, KEEP_POLLING_INTERVAL, k->Cancel, NULL);\r
+\r
+                               // 受信\r
+                               ret = RecvFrom(s, &src_ip, &src_port, buf, sizeof(buf));\r
+                               if (ret == 0 && s->IgnoreRecvErr == false)\r
+                               {\r
+                                       // 切断された\r
+                                       Disconnect(s);\r
+                                       ReleaseSock(s);\r
+                                       s = NULL;\r
+                               }\r
+\r
+                               if (s != NULL)\r
+                               {\r
+                                       if ((Tick64() - last_packet_sent_time) >= (UINT64)k->Interval)\r
+                                       {\r
+                                               BUF *b;\r
+\r
+                                               // 次のパケットを送出する\r
+                                               last_packet_sent_time = Tick64();\r
+\r
+                                               b = NewKeepPacket(k->Server);\r
+\r
+                                               ret = SendTo(s, &dest_ip, server_port, b->Buf, b->Size);\r
+                                               FreeBuf(b);\r
+\r
+                                               if (ret == 0 && s->IgnoreSendErr == false)\r
+                                               {\r
+                                                       // 切断された\r
+                                                       Disconnect(s);\r
+                                                       ReleaseSock(s);\r
+                                                       s = NULL;\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               changed = false;\r
+\r
+                               Lock(k->lock);\r
+                               {\r
+                                       if (StrCmpi(k->ServerName, server_name) != 0 ||\r
+                                               k->ServerPort != server_port || k->Enable == false ||\r
+                                               k->UdpMode == false)\r
+                                       {\r
+                                               changed = true;\r
+                                       }\r
+                               }\r
+                               Unlock(k->lock);\r
+\r
+                               if (changed || s == NULL)\r
+                               {\r
+                                       // 設定が変更された または 切断された\r
+                                       Disconnect(s);\r
+                                       ReleaseSock(s);\r
+                                       s = NULL;\r
+                                       goto WAIT_FOR_ENABLE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (k->Halt)\r
+                                       {\r
+                                               // 停止\r
+                                               Disconnect(s);\r
+                                               ReleaseSock(s);\r
+                                               return;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// KEEP 停止\r
+void StopKeep(KEEP *k)\r
+{\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       k->Halt = true;\r
+       Set(k->HaltEvent);\r
+       Cancel(k->Cancel);\r
+\r
+       WaitThread(k->Thread, INFINITE);\r
+       ReleaseThread(k->Thread);\r
+       DeleteLock(k->lock);\r
+\r
+       ReleaseCancel(k->Cancel);\r
+       ReleaseEvent(k->HaltEvent);\r
+\r
+       Free(k);\r
+}\r
+\r
+// KEEP 開始\r
+KEEP *StartKeep()\r
+{\r
+       KEEP *k = ZeroMalloc(sizeof(KEEP));\r
+\r
+       k->lock = NewLock();\r
+       k->HaltEvent = NewEvent();\r
+       k->Cancel = NewCancel();\r
+\r
+       // スレッド開始\r
+       k->Thread = NewThread(KeepThread, k);\r
+\r
+       return k;\r
+}\r
+\r
+// クライアント認証データのコピー\r
+CLIENT_AUTH *CopyClientAuth(CLIENT_AUTH *a)\r
+{\r
+       CLIENT_AUTH *ret;\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMallocEx(sizeof(CLIENT_AUTH), true);\r
+\r
+       ret->AuthType = a->AuthType;\r
+       StrCpy(ret->Username, sizeof(ret->Username), a->Username);\r
+\r
+       switch (a->AuthType)\r
+       {\r
+       case CLIENT_AUTHTYPE_ANONYMOUS:\r
+               // 匿名認証\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_PASSWORD:\r
+               // パスワード認証\r
+               Copy(ret->HashedPassword, a->HashedPassword, SHA1_SIZE);\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_PLAIN_PASSWORD:\r
+               // 平文パスワード認証\r
+               StrCpy(ret->PlainPassword, sizeof(ret->PlainPassword), a->PlainPassword);\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_CERT:\r
+               // 証明書認証\r
+               ret->ClientX = CloneX(a->ClientX);\r
+               ret->ClientK = CloneK(a->ClientK);\r
+               break;\r
+\r
+       case CLIENT_AUTHTYPE_SECURE:\r
+               // セキュアデバイス認証\r
+               StrCpy(ret->SecurePublicCertName, sizeof(ret->SecurePublicCertName), a->SecurePublicCertName);\r
+               StrCpy(ret->SecurePrivateKeyName, sizeof(ret->SecurePrivateKeyName), a->SecurePrivateKeyName);\r
+               break;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 送信 FIFO にデータを書き込む (自動暗号化)\r
+void WriteSendFifo(SESSION *s, TCPSOCK *ts, void *data, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || ts == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->UseFastRC4)\r
+       {\r
+               Encrypt(ts->SendKey, data, data, size);\r
+       }\r
+\r
+       WriteFifo(ts->SendFifo, data, size);\r
+}\r
+\r
+// 受信 FIFO にデータを書き込む (自動解読)\r
+void WriteRecvFifo(SESSION *s, TCPSOCK *ts, void *data, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || ts == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->UseFastRC4)\r
+       {\r
+               Encrypt(ts->RecvKey, data, data, size);\r
+       }\r
+\r
+       WriteFifo(ts->RecvFifo, data, size);\r
+}\r
+\r
+// TCP ソケット受信\r
+UINT TcpSockRecv(SESSION *s, TCPSOCK *ts, void *data, UINT size)\r
+{\r
+       // 受信\r
+       return Recv(ts->Sock, data, size, s->UseSSLDataEncryption);\r
+}\r
+\r
+// TCP ソケット送信\r
+UINT TcpSockSend(SESSION *s, TCPSOCK *ts, void *data, UINT size)\r
+{\r
+       // 送信\r
+       return Send(ts->Sock, data, size, s->UseSSLDataEncryption);\r
+}\r
+\r
+// データを UDP パケットとして送信する\r
+void SendDataWithUDP(SOCK *s, CONNECTION *c)\r
+{\r
+       UCHAR *buf;\r
+       BUF *b;\r
+       UINT64 dummy_64 = 0;\r
+       UCHAR dummy_buf[16];\r
+       UINT64 now = Tick64();\r
+       UINT ret;\r
+       bool force_flag = false;\r
+       bool packet_sent = false;\r
+       // 引数チェック\r
+       if (s == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 一時バッファをヒープから確保しておく\r
+       if (c->RecvBuf == NULL)\r
+       {\r
+               c->RecvBuf = Malloc(RECV_BUF_SIZE);\r
+       }\r
+       buf = c->RecvBuf;\r
+\r
+       if (c->Udp->NextKeepAliveTime == 0 || c->Udp->NextKeepAliveTime <= now)\r
+       {\r
+               force_flag = true;\r
+       }\r
+\r
+       // バッファの作成\r
+       while ((c->SendBlocks->num_item > 0) || force_flag)\r
+       {\r
+               UINT *key32;\r
+               UINT64 *seq;\r
+               char *sign;\r
+\r
+               force_flag = false;\r
+\r
+               // 現在のキューからバッファを組み立てる\r
+               b = NewBuf();\r
+\r
+               // パケットヘッダ (16バイト) 分の領域を確保\r
+               WriteBuf(b, dummy_buf, sizeof(dummy_buf));\r
+\r
+               // 送信キューのパケットを詰め込む\r
+               LockQueue(c->SendBlocks);\r
+               {\r
+                       while (true)\r
+                       {\r
+                               BLOCK *block;\r
+\r
+                               if (b->Size > UDP_BUF_SIZE)\r
+                               {\r
+                                       break;\r
+                               }\r
+                               block = GetNext(c->SendBlocks);\r
+                               if (block == NULL)\r
+                               {\r
+                                       break;\r
+                               }\r
+\r
+                               if (block->Size != 0)\r
+                               {\r
+                                       WriteBufInt(b, block->Size);\r
+                                       WriteBuf(b, block->Buf, block->Size);\r
+\r
+                                       c->Session->TotalSendSize += (UINT64)block->SizeofData;\r
+                                       c->Session->TotalSendSizeReal += (UINT64)block->Size;\r
+                               }\r
+\r
+                               FreeBlock(block);\r
+                               break;\r
+                       }\r
+               }\r
+               UnlockQueue(c->SendBlocks);\r
+\r
+               // セッションキーとシーケンス番号の書き込み\r
+               sign = (char *)(((UCHAR *)b->Buf));\r
+               key32 = (UINT *)(((UCHAR *)b->Buf + 4));\r
+               seq = (UINT64 *)(((UCHAR *)b->Buf + 8));\r
+               Copy(sign, SE_UDP_SIGN, 4);\r
+               *key32 = Endian32(c->Session->SessionKey32);\r
+               *seq = Endian64(c->Udp->Seq++); // シーケンス番号をインクリメントする\r
+\r
+//             InsertQueue(c->Udp->BufferQueue, b);\r
+\r
+               packet_sent = true;\r
+/*     }\r
+\r
+       // バッファの送信\r
+       while (c->Udp->BufferQueue->num_item != 0)\r
+       {\r
+               FIFO *f = c->Udp->BufferQueue->fifo;\r
+               BUF **pb = (BUF**)(((UCHAR *)f->p) + f->pos);\r
+               BUF *b = *pb;\r
+\r
+*/             ret = SendTo(s, &c->Udp->ip, c->Udp->port, b->Buf, b->Size);\r
+               if (ret == SOCK_LATER)\r
+               {\r
+                       // ブロッキング\r
+                       Debug(".");\r
+//                     break;\r
+               }\r
+               if (ret != b->Size)\r
+               {\r
+                       if (s->IgnoreSendErr == false)\r
+                       {\r
+                               // エラー\r
+                               Debug("******* SendTo Error !!!\n");\r
+                       }\r
+               }\r
+\r
+               // メモリ解放\r
+               FreeBuf(b);\r
+//             GetNext(c->Udp->BufferQueue);\r
+       }\r
+\r
+       if (packet_sent)\r
+       {\r
+               // KeepAlive 時刻更新\r
+               c->Udp->NextKeepAliveTime = now + (UINT64)GenNextKeepAliveSpan(c);\r
+       }\r
+}\r
+\r
+// UDP パケットのデータをコネクションに書き込む\r
+void PutUDPPacketData(CONNECTION *c, void *data, UINT size)\r
+{\r
+       BUF *b;\r
+       char sign[4];\r
+       // 引数チェック\r
+       if (c == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // プロトコルを調べる\r
+       if (c->Protocol != CONNECTION_UDP)\r
+       {\r
+               // UDP プロトコルは利用されていない\r
+               return;\r
+       }\r
+\r
+       // バッファ構成\r
+       b = NewBuf();\r
+       WriteBuf(b, data, size);\r
+\r
+       SeekBuf(b, 0, 0);\r
+       ReadBuf(b, sign, 4);\r
+\r
+       // サイン確認\r
+       if (Cmp(sign, SE_UDP_SIGN, 4) == 0)\r
+       {\r
+               UINT key32;\r
+\r
+               // セッションキー番号\r
+               key32 = ReadBufInt(b);\r
+\r
+               if (c->Session->SessionKey32 == key32)\r
+               {\r
+                       UINT64 seq;\r
+\r
+                       // シーケンス番号読み込み\r
+                       ReadBuf(b, &seq, sizeof(seq));\r
+                       seq = Endian64(seq);\r
+\r
+                       if ((UINT)(seq - c->Udp->RecvSeq - (UINT64)1))\r
+                       {\r
+                               //Debug("** UDP Seq Lost %u\n", (UINT)(seq - c->Udp->RecvSeq - (UINT64)1));\r
+                       }\r
+                       c->Udp->RecvSeq = seq;\r
+\r
+                       //Debug("SEQ: %I32u\n", seq);\r
+\r
+                       while (true)\r
+                       {\r
+                               UINT size;\r
+\r
+                               size = ReadBufInt(b);\r
+                               if (size == 0)\r
+                               {\r
+                                       break;\r
+                               }\r
+                               else if (size <= MAX_PACKET_SIZE)\r
+                               {\r
+                                       void *tmp;\r
+                                       BLOCK *block;\r
+\r
+                                       tmp = Malloc(size);\r
+                                       if (ReadBuf(b, tmp, size) != size)\r
+                                       {\r
+                                               Free(tmp);\r
+                                               break;\r
+                                       }\r
+\r
+                                       // ブロック構成\r
+                                       block = NewBlock(tmp, size, 0);\r
+\r
+                                       // ブロック挿入\r
+                                       InsertReveicedBlockToQueue(c, block);\r
+                               }\r
+                       }\r
+\r
+                       // 最終通信時刻を更新\r
+                       c->Session->LastCommTime = Tick64();\r
+               }\r
+               else\r
+               {\r
+                       Debug("Invalid SessionKey: 0x%X\n", key32);\r
+               }\r
+       }\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// 受信キューにブロックを追加する\r
+void InsertReveicedBlockToQueue(CONNECTION *c, BLOCK *block)\r
+{\r
+       SESSION *s;\r
+       // 引数チェック\r
+       if (c == NULL || block == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = c->Session;\r
+       \r
+       if (c->Protocol == CONNECTION_TCP)\r
+       {\r
+               s->TotalRecvSizeReal += block->SizeofData;\r
+               s->TotalRecvSize += block->Size;\r
+       }\r
+\r
+       LockQueue(c->ReceivedBlocks);\r
+       {\r
+               InsertQueue(c->ReceivedBlocks, block);\r
+       }\r
+       UnlockQueue(c->ReceivedBlocks);\r
+}\r
+\r
+// 次の Keep-Alive パケットまでの間隔を生成 (ネットワーク負荷減少のため乱数にする)\r
+UINT GenNextKeepAliveSpan(CONNECTION *c)\r
+{\r
+       UINT a, b;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       a = c->Session->Timeout;\r
+       b = rand() % (a / 2);\r
+       b = MAX(b, a / 5);\r
+\r
+       return b;\r
+}\r
+\r
+// Keep-Alive パケットを送信する\r
+void SendKeepAlive(CONNECTION *c, TCPSOCK *ts)\r
+{\r
+       UINT size, i, num;\r
+       UINT size_be;\r
+       UCHAR *buf;\r
+       // 引数チェック\r
+       if (c == NULL || ts == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       size = rand() % MAX_KEEPALIVE_SIZE;\r
+       num = KEEP_ALIVE_MAGIC;\r
+       buf = MallocFast(size);\r
+\r
+       for (i = 0;i < size;i++)\r
+       {\r
+               buf[i] = rand();\r
+       }\r
+\r
+       num = Endian32(num);\r
+       size_be = Endian32(size);\r
+       WriteSendFifo(c->Session, ts, &num, sizeof(UINT));\r
+       WriteSendFifo(c->Session, ts, &size_be, sizeof(UINT));\r
+       WriteSendFifo(c->Session, ts, buf, size);\r
+\r
+       c->Session->TotalSendSize += sizeof(UINT) * 2 + size;\r
+       c->Session->TotalSendSizeReal += sizeof(UINT) * 2 + size;\r
+\r
+       Free(buf);\r
+}\r
+\r
+// ブロックの送信\r
+void ConnectionSend(CONNECTION *c)\r
+{\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       UINT i, num;\r
+       UINT64 now;\r
+       UINT min_count;\r
+       TCPSOCK **tcpsocks;\r
+       UINT size;\r
+       SESSION *s;\r
+       bool use_qos;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = c->Session;\r
+       use_qos = s->QoS;\r
+\r
+       now = Tick64();\r
+\r
+       // プロトコル\r
+       if (c->Protocol == CONNECTION_TCP)\r
+       {\r
+               // TCP\r
+               TCP *tcp = c->Tcp;\r
+               TCPSOCK *ts;\r
+               TCPSOCK *ts_hp;\r
+               UINT num_available;\r
+               LockList(tcp->TcpSockList);\r
+               {\r
+                       num = LIST_NUM(tcp->TcpSockList);\r
+                       tcpsocks = ToArrayEx(tcp->TcpSockList, true);\r
+               }\r
+               UnlockList(tcp->TcpSockList);\r
+\r
+               // 送信に使用するソケットを選択する\r
+               // 遅延回数が最も少ないソケットを選出\r
+               min_count = INFINITE;\r
+               ts = NULL;\r
+               ts_hp = NULL;\r
+\r
+               num_available = 0;\r
+\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       TCPSOCK *tcpsock = tcpsocks[i];\r
+                       if (tcpsock->Sock->Connected && tcpsock->Sock->AsyncMode &&\r
+                               IS_SEND_TCP_SOCK(tcpsock))\r
+                       {\r
+                               // KeepAlive の処理\r
+                               if (now >= tcpsock->NextKeepAliveTime || tcpsock->NextKeepAliveTime == 0)\r
+                               {\r
+                                       // KeepAlive を打つ\r
+                                       SendKeepAlive(c, tcpsock);\r
+                                       tcpsock->NextKeepAliveTime = now + (UINT64)GenNextKeepAliveSpan(c);\r
+                               }\r
+\r
+                               // 送信に利用可能なソケット数を計測する\r
+                               num_available++;\r
+\r
+                               ts_hp = tcpsock;\r
+                       }\r
+               }\r
+\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       TCPSOCK *tcpsock = tcpsocks[i];\r
+                       if (tcpsock->Sock->Connected && tcpsock->Sock->AsyncMode &&\r
+                               IS_SEND_TCP_SOCK(tcpsock))\r
+                       {\r
+                               // ソケットの選出\r
+                               bool b = false;\r
+\r
+                               if (use_qos == false)\r
+                               {\r
+                                       b = true;\r
+                               }\r
+                               else if (num_available < 2)\r
+                               {\r
+                                       b = true;\r
+                               }\r
+                               else if (tcpsock != ts_hp)\r
+                               {\r
+                                       b = true;\r
+                               }\r
+\r
+                               if (b)\r
+                               {\r
+                                       if (tcpsock->LateCount <= min_count)\r
+                                       {\r
+                                               min_count = tcpsock->LateCount;\r
+                                               ts = tcpsock;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (use_qos == false)\r
+               {\r
+                       ts_hp = ts;\r
+               }\r
+\r
+               if (ts == NULL || ts_hp == NULL)\r
+               {\r
+                       // 現在 送信可能なソケットが存在しない\r
+               }\r
+               else\r
+               {\r
+                       TCPSOCK *tss;\r
+                       UINT j;\r
+                       QUEUE *q;\r
+\r
+                       for (j = 0;j < 2;j++)\r
+                       {\r
+                               if (j == 0)\r
+                               {\r
+                                       q = c->SendBlocks2;\r
+                                       tss = ts_hp;\r
+                               }\r
+                               else\r
+                               {\r
+                                       q = c->SendBlocks;\r
+                                       tss = ts;\r
+                               }\r
+                               // 選択されたソケット ts に対して送信データを予約する\r
+                               LockQueue(c->SendBlocks);\r
+                               if (q->num_item != 0)\r
+                               {\r
+                                       UINT num_data;\r
+                                       BLOCK *b;\r
+\r
+                                       if (tss->SendFifo->size >= MAX((MAX_SEND_SOCKET_QUEUE_SIZE / s->MaxConnection), MIN_SEND_SOCKET_QUEUE_SIZE))\r
+                                       {\r
+                                               // 送信ソケットキューのサイズが超過\r
+                                               // 送信できない\r
+                                               while (b = GetNext(q))\r
+                                               {\r
+                                                       if (b != NULL)\r
+                                                       {\r
+                                                               c->CurrentSendQueueSize -= b->Size;\r
+                                                               FreeBlock(b);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               bool update_keepalive_timer = false;\r
+                                               // 個数データ\r
+                                               num_data = Endian32(q->num_item);\r
+                                               PROBE_DATA2("WriteSendFifo num", &num_data, sizeof(UINT));\r
+                                               WriteSendFifo(s, tss, &num_data, sizeof(UINT));\r
+\r
+                                               s->TotalSendSize += sizeof(UINT);\r
+                                               s->TotalSendSizeReal += sizeof(UINT);\r
+\r
+                                               while (b = GetNext(q))\r
+                                               {\r
+                                                       // サイズデータ\r
+                                                       UINT size_data;\r
+                                                       size_data = Endian32(b->Size);\r
+                                                       PROBE_DATA2("WriteSendFifo size", &size_data, sizeof(UINT));\r
+                                                       WriteSendFifo(s, tss, &size_data, sizeof(UINT));\r
+\r
+                                                       c->CurrentSendQueueSize -= b->Size;\r
+\r
+                                                       s->TotalSendSize += sizeof(UINT);\r
+                                                       s->TotalSendSizeReal += sizeof(UINT);\r
+\r
+                                                       // データ本体\r
+                                                       PROBE_DATA2("WriteSendFifo data", b->Buf, b->Size);\r
+                                                       WriteSendFifo(s, tss, b->Buf, b->Size);\r
+\r
+                                                       s->TotalSendSize += b->SizeofData;\r
+                                                       s->TotalSendSizeReal += b->Size;\r
+\r
+                                                       update_keepalive_timer = true;\r
+\r
+                                                       // ブロック解放\r
+                                                       FreeBlock(b);\r
+                                               }\r
+\r
+                                               if (update_keepalive_timer)\r
+                                               {\r
+                                                       // KeepAlive タイマを増加させる\r
+                                                       tss->NextKeepAliveTime = now + (UINT64)GenNextKeepAliveSpan(c);\r
+                                               }\r
+                                       }\r
+                               }\r
+                               UnlockQueue(c->SendBlocks);\r
+                       }\r
+               }\r
+\r
+               // 現在各ソケットに登録されている送信予約データを送信する\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       ts = tcpsocks[i];\r
+\r
+SEND_START:\r
+                       if (ts->Sock->Connected == false)\r
+                       {\r
+                               s->LastTryAddConnectTime = Tick64();\r
+                               // 通信が切断された\r
+                               LockList(tcp->TcpSockList);\r
+                               {\r
+                                       // ソケットリストからこのソケットを削除する\r
+                                       Delete(tcp->TcpSockList, ts);\r
+                                       // TCPSOCK の解放\r
+                                       FreeTcpSock(ts);\r
+                                       // 個数のデクリメント\r
+                                       Dec(c->CurrentNumConnection);\r
+                                       Debug("--- TCP Connection Decremented: %u (%s Line %u)\n", Count(c->CurrentNumConnection), __FILE__, __LINE__);\r
+                                       Debug("LIST_NUM(tcp->TcpSockList): %u\n", LIST_NUM(tcp->TcpSockList));\r
+                               }\r
+                               UnlockList(tcp->TcpSockList);\r
+\r
+                               continue;\r
+                       }\r
+\r
+                       // Fifo サイズを取得\r
+                       if (ts->SendFifo->size != 0)\r
+                       {\r
+                               UCHAR *buf;\r
+                               UINT want_send_size;\r
+                               // 1 バイト以上送信予定データが存在する場合のみ送信する\r
+                               // バッファへのポインタを取得\r
+                               buf = (UCHAR *)ts->SendFifo->p + ts->SendFifo->pos;\r
+                               want_send_size = ts->SendFifo->size;\r
+\r
+                               PROBE_DATA2("TcpSockSend", buf, want_send_size);\r
+                               size = TcpSockSend(s, ts, buf, want_send_size);\r
+                               if (size == 0)\r
+                               {\r
+                                       // 切断された\r
+                                       continue;\r
+                               }\r
+                               else if (size == SOCK_LATER)\r
+                               {\r
+                                       // パケットが詰まっている\r
+                                       ts->LateCount++; // 遅延カウンタのインクリメント\r
+                                       PROBE_STR("ts->LateCount++;");\r
+                               }\r
+                               else\r
+                               {\r
+                                       // パケットが size だけ送信された\r
+                                       // FIFO を進める\r
+                                       ReadFifo(ts->SendFifo, NULL, size);\r
+                                       if (size < want_send_size)\r
+                                       {\r
+                                               // 予定されたデータのすべてを送信することができなかった\r
+#ifdef USE_PROBE\r
+                                               {\r
+                                                       char tmp[MAX_SIZE];\r
+\r
+                                                       snprintf(tmp, sizeof(tmp), "size < want_send_size: %u < %u",\r
+                                                               size, want_send_size);\r
+\r
+                                                       PROBE_STR(tmp);\r
+                                               }\r
+#endif // USE_PROBE\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // すべてのパケットの送信が完了した (キューが無くなった)\r
+                                               // ので、遅延カウンタをリセットする\r
+                                               ts->LateCount = 0;\r
+\r
+                                               PROBE_STR("TcpSockSend All Completed");\r
+                                       }\r
+                                       // 最終通信日時を更新\r
+                                       c->Session->LastCommTime = now;\r
+\r
+                                       goto SEND_START;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               Free(tcpsocks);\r
+       }\r
+       else if (c->Protocol == CONNECTION_UDP)\r
+       {\r
+               // UDP\r
+               UDP *udp = c->Udp;\r
+               SOCK *sock = NULL;\r
+\r
+               Lock(c->lock);\r
+               {\r
+                       sock = udp->s;\r
+                       if (sock != NULL)\r
+                       {\r
+                               AddRef(sock->ref);\r
+                       }\r
+               }\r
+               Unlock(c->lock);\r
+\r
+               if (sock != NULL)\r
+               {\r
+                       // UDP で送信する\r
+\r
+                       // KeepAlive 送信\r
+                       if ((udp->NextKeepAliveTime == 0 || udp->NextKeepAliveTime <= now) ||\r
+                               (c->SendBlocks->num_item != 0) || (udp->BufferQueue->num_item != 0))\r
+                       {\r
+                               // 現在のキューを UDP で送信\r
+                               SendDataWithUDP(sock, c);\r
+                       }\r
+               }\r
+\r
+               if (sock != NULL)\r
+               {\r
+                       ReleaseSock(sock);\r
+               }\r
+       }\r
+       else if (c->Protocol == CONNECTION_HUB_SECURE_NAT)\r
+       {\r
+               // SecureNAT セッション\r
+               SNAT *snat = s->SecureNAT;\r
+               VH *v = snat->Nat->Virtual;\r
+\r
+               LockQueue(c->SendBlocks);\r
+               {\r
+                       BLOCK *block;\r
+                       UINT num_packet = 0;\r
+\r
+                       while (block = GetNext(c->SendBlocks))\r
+                       {\r
+                               num_packet++;\r
+                               c->CurrentSendQueueSize -= block->Size;\r
+                               VirtualPutPacket(v, block->Buf, block->Size);\r
+                               Free(block);\r
+                       }\r
+\r
+                       if (num_packet != 0)\r
+                       {\r
+                               VirtualPutPacket(v, NULL, 0);\r
+                       }\r
+               }\r
+               UnlockQueue(c->SendBlocks);\r
+       }\r
+       else if (c->Protocol == CONNECTION_HUB_LAYER3)\r
+       {\r
+               // Layer-3 セッション\r
+               L3IF *f = s->L3If;\r
+\r
+               LockQueue(c->SendBlocks);\r
+               {\r
+                       BLOCK *block;\r
+                       UINT num_packet = 0;\r
+\r
+                       while (block = GetNext(c->SendBlocks))\r
+                       {\r
+                               num_packet++;\r
+                               c->CurrentSendQueueSize -= block->Size;\r
+                               L3PutPacket(f, block->Buf, block->Size);\r
+                               Free(block);\r
+                       }\r
+\r
+                       if (num_packet != 0)\r
+                       {\r
+                               L3PutPacket(f, NULL, 0);\r
+                       }\r
+               }\r
+               UnlockQueue(c->SendBlocks);\r
+       }\r
+       else if (c->Protocol == CONNECTION_HUB_LINK_SERVER)\r
+       {\r
+               // HUB リンク\r
+               LINK *k = (LINK *)s->Link;\r
+\r
+               if (k != NULL)\r
+               {\r
+                       LockQueue(c->SendBlocks);\r
+                       {\r
+                               UINT num_blocks = 0;\r
+                               LockQueue(k->SendPacketQueue);\r
+                               {\r
+                                       BLOCK *block;\r
+\r
+                                       // パケットキューをクライアントスレッドに転送する\r
+                                       while (block = GetNext(c->SendBlocks))\r
+                                       {\r
+                                               num_blocks++;\r
+                                               c->CurrentSendQueueSize -= block->Size;\r
+                                               InsertQueue(k->SendPacketQueue, block);\r
+                                       }\r
+                               }\r
+                               UnlockQueue(k->SendPacketQueue);\r
+\r
+                               if (num_blocks != 0)\r
+                               {\r
+                                       // キャンセルの発行\r
+                                       Cancel(k->ClientSession->Cancel1);\r
+                               }\r
+                       }\r
+                       UnlockQueue(c->SendBlocks);\r
+               }\r
+       }\r
+       else if (c->Protocol == CONNECTION_HUB_BRIDGE)\r
+       {\r
+               // ローカルブリッジ\r
+               BRIDGE *b = s->Bridge;\r
+\r
+               if (b != NULL)\r
+               {\r
+                       if (b->Active)\r
+                       {\r
+                               LockQueue(c->SendBlocks);\r
+                               {\r
+                                       BLOCK *block;\r
+                                       UINT num_packet = c->SendBlocks->num_item; // パケット数\r
+\r
+                                       if (num_packet != 0)\r
+                                       {\r
+                                               // パケットデータ配列\r
+                                               void **datas = MallocFast(sizeof(void *) * num_packet);\r
+                                               UINT *sizes = MallocFast(sizeof(UINT *) * num_packet);\r
+                                               UINT i;\r
+\r
+                                               i = 0;\r
+                                               while (block = GetNext(c->SendBlocks))\r
+                                               {\r
+                                                       datas[i] = block->Buf;\r
+                                                       sizes[i] = block->Size;\r
+\r
+                                                       if (block->Size > 1514)\r
+                                                       {\r
+                                                               NormalizeEthMtu(b, c, block->Size);\r
+                                                       }\r
+\r
+                                                       c->CurrentSendQueueSize -= block->Size;\r
+                                                       Free(block);\r
+                                                       i++;\r
+                                               }\r
+\r
+                                               // パケットを書き込む\r
+                                               EthPutPackets(b->Eth, num_packet, datas, sizes);\r
+\r
+                                               Free(datas);\r
+                                               Free(sizes);\r
+                                       }\r
+                               }\r
+                               UnlockQueue(c->SendBlocks);\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// ブロックの受信\r
+void ConnectionReceive(CONNECTION *c, CANCEL *c1, CANCEL *c2)\r
+{\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       UINT i, num;\r
+       SOCKSET set;\r
+       SESSION *s;\r
+       TCPSOCK **tcpsocks;\r
+       UCHAR *buf;\r
+       UINT size;\r
+       UINT64 now;\r
+       UINT time;\r
+       UINT num_delayed = 0;\r
+       bool no_spinlock_for_delay = false;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PROBE_STR("ConnectionReceive");\r
+\r
+       s = c->Session;\r
+\r
+       if (s->Hub != NULL)\r
+       {\r
+               no_spinlock_for_delay = s->Hub->Option->NoSpinLockForPacketDelay;\r
+       }\r
+\r
+       now = Tick64();\r
+\r
+       if (c->RecvBuf == NULL)\r
+       {\r
+               c->RecvBuf = Malloc(RECV_BUF_SIZE);\r
+       }\r
+       buf = c->RecvBuf;\r
+\r
+       // プロトコル\r
+       if (c->Protocol == CONNECTION_TCP)\r
+       {\r
+               // TCP\r
+               TCP *tcp = c->Tcp;\r
+\r
+               // コネクション切断間隔が指定されている場合はコネクションの切断を行う\r
+               if (s->ServerMode == false)\r
+               {\r
+                       if (s->ClientOption->ConnectionDisconnectSpan != 0)\r
+                       {\r
+                               LockList(tcp->TcpSockList);\r
+                               {\r
+                                       UINT i;\r
+                                       for (i = 0;i < LIST_NUM(tcp->TcpSockList);i++)\r
+                                       {\r
+                                               TCPSOCK *ts = LIST_DATA(tcp->TcpSockList, i);\r
+                                               if (ts->DisconnectTick != 0 &&\r
+                                                       ts->DisconnectTick <= now)\r
+                                               {\r
+                                                       Debug("ts->DisconnectTick <= now\n");\r
+                                                       Disconnect(ts->Sock);\r
+                                               }\r
+                                       }\r
+                               }\r
+                               UnlockList(tcp->TcpSockList);\r
+                       }\r
+               }\r
+\r
+               if (s->HalfConnection && (s->ServerMode == false))\r
+               {\r
+                       // 現在の TCP コネクションの方向を調べ、\r
+                       // 一方向しか無く かつコネクション数が限界の場合は\r
+                       // 1 つ切断する\r
+                       LockList(tcp->TcpSockList);\r
+                       {\r
+                               UINT i, num;\r
+                               UINT c2s, s2c;\r
+                               c2s = s2c = 0;\r
+                               num = LIST_NUM(tcp->TcpSockList);\r
+                               if (num >= s->MaxConnection)\r
+                               {\r
+                                       TCPSOCK *ts;\r
+                                       for (i = 0;i < num;i++)\r
+                                       {\r
+                                               ts = LIST_DATA(tcp->TcpSockList, i);\r
+                                               if (ts->Direction == TCP_SERVER_TO_CLIENT)\r
+                                               {\r
+                                                       s2c++;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       c2s++;\r
+                                               }\r
+                                       }\r
+                                       if (s2c == 0 || c2s == 0)\r
+                                       {\r
+                                               // 最後のソケットを切断する\r
+                                               Disconnect(ts->Sock);\r
+                                               Debug("Disconnect (s2c=%u, c2s=%u)\n", s2c, c2s);\r
+                                       }\r
+                               }\r
+                       }\r
+                       UnlockList(tcp->TcpSockList);\r
+               }\r
+\r
+               // ソケットセットの初期化\r
+               InitSockSet(&set);\r
+               LockList(tcp->TcpSockList);\r
+               {\r
+                       num = LIST_NUM(tcp->TcpSockList);\r
+                       tcpsocks = ToArrayEx(tcp->TcpSockList, true);\r
+               }\r
+               UnlockList(tcp->TcpSockList);\r
+\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       AddSockSet(&set, tcpsocks[i]->Sock);\r
+               }\r
+\r
+               // Select\r
+               time = SELECT_TIME;\r
+               if (s->VirtualHost)\r
+               {\r
+                       time = MIN(time, SELECT_TIME_FOR_NAT);\r
+               }\r
+               time = MIN(time, GetNextDelayedPacketTickDiff(s));\r
+               num_delayed = LIST_NUM(s->DelayedPacketList);\r
+\r
+               PROBE_STR("ConnectionReceive: Select 0");\r
+\r
+               if (s->Flag1 != set.NumSocket)\r
+               {\r
+                       Select(&set, (num_delayed == 0 ? time : 1), c1, c2);\r
+                       s->Flag1 = set.NumSocket;\r
+               }\r
+               else\r
+               {\r
+                       if (no_spinlock_for_delay || time >= 50 || num_delayed == false)\r
+                       {\r
+                               Select(&set, (num_delayed == 0 ? time : (time > 100 ? (time - 100) : 1)), c1, c2);\r
+                               s->Flag1 = set.NumSocket;\r
+                       }\r
+                       else\r
+                       {\r
+                               YieldCpu();\r
+                       }\r
+               }\r
+\r
+               PROBE_STR("ConnectionReceive: Select 1");\r
+\r
+               // TCP ソケットに到着しているデータをすべて読み込む\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       TCPSOCK *ts = tcpsocks[i];\r
+                       if (ts->WantSize == 0)\r
+                       {\r
+                               // 最初に必ず sizeof(UINT) だけ読み込む\r
+                               ts->WantSize = sizeof(UINT);\r
+                       }\r
+\r
+RECV_START:\r
+                       // 受信\r
+                       size = TcpSockRecv(s, ts, buf, RECV_BUF_SIZE);\r
+                       if (size == 0)\r
+                       {\r
+DISCONNECT_THIS_TCP:\r
+                               s->LastTryAddConnectTime = Tick64();\r
+                               // 通信が切断された\r
+                               LockList(tcp->TcpSockList);\r
+                               {\r
+                                       // ソケットリストからこのソケットを削除する\r
+                                       Delete(tcp->TcpSockList, ts);\r
+                                       // TCPSOCK の解放\r
+                                       FreeTcpSock(ts);\r
+                                       // デクリメント\r
+                                       Dec(c->CurrentNumConnection);\r
+                                       Debug("--- TCP Connection Decremented: %u (%s Line %u)\n", Count(c->CurrentNumConnection), __FILE__, __LINE__);\r
+                                       Debug("LIST_NUM(tcp->TcpSockList): %u\n", LIST_NUM(tcp->TcpSockList));\r
+                               }\r
+                               UnlockList(tcp->TcpSockList);\r
+\r
+                               continue;\r
+                       }\r
+                       else if (size == SOCK_LATER)\r
+                       {\r
+                               // 受信待ち状態: 何もしない\r
+                               if (IS_RECV_TCP_SOCK(ts))\r
+                               {\r
+                                       if ((now > ts->LastCommTime) && ((now - ts->LastCommTime) >= ((UINT64)s->Timeout)))\r
+                                       {\r
+                                               // このコネクションはタイムアウトした\r
+                                               Debug("Connection %u Timeouted.\n", i);\r
+                                               goto DISCONNECT_THIS_TCP;\r
+                                       }\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // 最終通信時刻を更新\r
+                               ts->LastCommTime = now;\r
+                               c->Session->LastCommTime = now;\r
+\r
+                               // データが受信できたので FIFO に書き込む\r
+                               PROBE_DATA2("WriteRecvFifo", buf, size);\r
+                               WriteRecvFifo(s, ts, buf, size);\r
+\r
+                               // 受信バッファがいっぱいになったら受信をやめる\r
+                               if (ts->RecvFifo->size < MAX_SEND_SOCKET_QUEUE_SIZE)\r
+                               {\r
+                                       goto RECV_START;\r
+                               }\r
+                       }\r
+\r
+                       // FIFO に書き込まれたデータを処理する\r
+                       while (ts->RecvFifo->size >= ts->WantSize)\r
+                       {\r
+                               UCHAR *buf;\r
+                               void *data;\r
+                               BLOCK *block;\r
+                               UINT sz;\r
+                               // すでに十分な量のデータが格納されている\r
+                               // データのポインタを取得\r
+                               buf = (UCHAR *)ts->RecvFifo->p + ts->RecvFifo->pos;\r
+\r
+                               switch (ts->Mode)\r
+                               {\r
+                               case 0:\r
+                                       // データブロック個数\r
+                                       ts->WantSize = sizeof(UINT);\r
+                                       Copy(&sz, buf, sizeof(UINT));\r
+                                       PROBE_DATA2("ReadFifo 0", buf, sizeof(UINT));\r
+                                       sz = Endian32(sz);\r
+                                       ts->NextBlockNum = sz;\r
+                                       ReadFifo(ts->RecvFifo, NULL, sizeof(UINT));\r
+\r
+                                       s->TotalRecvSize += sizeof(UINT);\r
+                                       s->TotalRecvSizeReal += sizeof(UINT);\r
+\r
+                                       ts->CurrentPacketNum = 0;\r
+                                       if (ts->NextBlockNum != 0)\r
+                                       {\r
+                                               if (ts->NextBlockNum == KEEP_ALIVE_MAGIC)\r
+                                               {\r
+                                                       ts->Mode = 3;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       ts->Mode = 1;\r
+                                               }\r
+                                       }\r
+                                       break;\r
+\r
+                               case 1:\r
+                                       // データブロックサイズ\r
+                                       Copy(&sz, buf, sizeof(UINT));\r
+                                       sz = Endian32(sz);\r
+                                       PROBE_DATA2("ReadFifo 1", buf, sizeof(UINT));\r
+                                       if (sz > (MAX_PACKET_SIZE * 2))\r
+                                       {\r
+                                               // おかしなデータサイズを受信した\r
+                                               // TCP/IP 通信エラー?\r
+                                               Debug("%s %u sz > (MAX_PACKET_SIZE * 2)\n", __FILE__, __LINE__);\r
+                                               Disconnect(ts->Sock);\r
+                                       }\r
+                                       ts->NextBlockSize = MIN(sz, MAX_PACKET_SIZE * 2);\r
+                                       ReadFifo(ts->RecvFifo, NULL, sizeof(UINT));\r
+\r
+                                       s->TotalRecvSize += sizeof(UINT);\r
+                                       s->TotalRecvSizeReal += sizeof(UINT);\r
+\r
+                                       ts->WantSize = ts->NextBlockSize;\r
+                                       if (ts->WantSize != 0)\r
+                                       {\r
+                                               ts->Mode = 2;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               ts->Mode = 1;\r
+                                               ts->WantSize = sizeof(UINT);\r
+                                               ts->CurrentPacketNum++;\r
+                                               if (ts->CurrentPacketNum >= ts->NextBlockNum)\r
+                                               {\r
+                                                       ts->Mode = 0;\r
+                                               }\r
+                                       }\r
+                                       break;\r
+\r
+                               case 2:\r
+                                       // データブロック本体\r
+                                       ts->WantSize = sizeof(UINT);\r
+                                       ts->CurrentPacketNum++;\r
+                                       data = MallocFast(ts->NextBlockSize);\r
+                                       Copy(data, buf, ts->NextBlockSize);\r
+                                       PROBE_DATA2("ReadFifo 2", buf, ts->NextBlockSize);\r
+                                       ReadFifo(ts->RecvFifo, NULL, ts->NextBlockSize);\r
+                                       block = NewBlock(data, ts->NextBlockSize, s->UseCompress ? -1 : 0);\r
+\r
+                                       if (block->Size > MAX_PACKET_SIZE)\r
+                                       {\r
+                                               // パケットサイズ超過\r
+                                               FreeBlock(block);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // データブロックをキューに追加\r
+                                               InsertReveicedBlockToQueue(c, block);\r
+                                       }\r
+\r
+                                       if (ts->CurrentPacketNum >= ts->NextBlockNum)\r
+                                       {\r
+                                               // すべてのデータブロックの受信が完了\r
+                                               ts->Mode = 0;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // 次のデータブロックサイズを受信\r
+                                               ts->Mode = 1;\r
+                                       }\r
+                                       break;\r
+\r
+                               case 3:\r
+                                       // Keep-Alive パケットサイズ\r
+                                       ts->Mode = 4;\r
+                                       Copy(&sz, buf, sizeof(UINT));\r
+                                       PROBE_DATA2("ReadFifo 3", buf, sizeof(UINT));\r
+                                       sz = Endian32(sz);\r
+                                       if (sz > MAX_KEEPALIVE_SIZE)\r
+                                       {\r
+                                               // おかしなデータサイズを受信した\r
+                                               // TCP/IP 通信エラー?\r
+                                               Debug("%s %u sz > MAX_KEEPALIVE_SIZE\n", __FILE__, __LINE__);\r
+                                               Disconnect(ts->Sock);\r
+                                       }\r
+                                       ts->NextBlockSize = MIN(sz, MAX_KEEPALIVE_SIZE);\r
+                                       ReadFifo(ts->RecvFifo, NULL, sizeof(UINT));\r
+\r
+                                       s->TotalRecvSize += sizeof(UINT);\r
+                                       s->TotalRecvSizeReal += sizeof(UINT);\r
+\r
+                                       ts->WantSize = sz;\r
+                                       break;\r
+\r
+                               case 4:\r
+                                       // Keep-Alive パケット本体\r
+                                       //Debug("KeepAlive Recved.\n");\r
+                                       ts->Mode = 0;\r
+                                       sz = ts->NextBlockSize;\r
+                                       PROBE_DATA2("ReadFifo 4", NULL, 0);\r
+                                       ReadFifo(ts->RecvFifo, NULL, sz);\r
+\r
+                                       s->TotalRecvSize += sz;\r
+                                       s->TotalRecvSizeReal += sz;\r
+\r
+                                       ts->WantSize = sizeof(UINT);\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               Free(tcpsocks);\r
+       }\r
+       else if (c->Protocol == CONNECTION_UDP)\r
+       {\r
+               // UDP\r
+               UDP *udp = c->Udp;\r
+               SOCK *sock = NULL;\r
+\r
+               if (s->ServerMode == false)\r
+               {\r
+                       Lock(c->lock);\r
+                       {\r
+                               if (c->Udp->s != NULL)\r
+                               {\r
+                                       sock = c->Udp->s;\r
+                                       if (sock != NULL)\r
+                                       {\r
+                                               AddRef(sock->ref);\r
+                                       }\r
+                               }\r
+                       }\r
+                       Unlock(c->lock);\r
+\r
+                       InitSockSet(&set);\r
+\r
+                       if (sock != NULL)\r
+                       {\r
+                               AddSockSet(&set, sock);\r
+                       }\r
+\r
+                       Select(&set, SELECT_TIME, c1, c2);\r
+\r
+                       if (sock != NULL)\r
+                       {\r
+                               IP ip;\r
+                               UINT port;\r
+                               UCHAR *buf;\r
+                               UINT size;\r
+\r
+                               while (true)\r
+                               {\r
+                                       buf = c->RecvBuf;\r
+                                       size = RecvFrom(sock, &ip, &port, buf, RECV_BUF_SIZE);\r
+                                       if (size == 0 && sock->IgnoreRecvErr == false)\r
+                                       {\r
+                                               Debug("UDP Socket Disconnected.\n");\r
+                                               Lock(c->lock);\r
+                                               {\r
+                                                       ReleaseSock(udp->s);\r
+                                                       udp->s = NULL;\r
+                                               }\r
+                                               Unlock(c->lock);\r
+                                               break;\r
+                                       }\r
+                                       else if (size == SOCK_LATER)\r
+                                       {\r
+                                               break;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (size)\r
+                                               {\r
+                                                       PutUDPPacketData(c, buf, size);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       if (sock != NULL)\r
+                       {\r
+                               Release(sock->ref);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       Select(NULL, SELECT_TIME, c1, c2);\r
+               }\r
+       }\r
+       else if (c->Protocol == CONNECTION_HUB_SECURE_NAT)\r
+       {\r
+               SNAT *snat = c->Session->SecureNAT;\r
+               VH *v = snat->Nat->Virtual;\r
+               UINT size;\r
+               void *data;\r
+               UINT num;\r
+               UINT select_wait_time = SELECT_TIME_FOR_NAT;\r
+\r
+               if (snat->Nat != NULL && snat->Nat->Option.UseNat == false)\r
+               {\r
+                       select_wait_time = SELECT_TIME;\r
+               }\r
+               else\r
+               {\r
+                       if (snat->Nat != NULL)\r
+                       {\r
+                               LockList(v->NatTable);\r
+                               {\r
+                                       if (LIST_NUM(v->NatTable) == 0 && LIST_NUM(v->ArpWaitTable) == 0)\r
+                                       {\r
+                                               select_wait_time = SELECT_TIME;\r
+                                       }\r
+                               }\r
+                               UnlockList(v->NatTable);\r
+                       }\r
+               }\r
+\r
+               select_wait_time = MIN(select_wait_time, GetNextDelayedPacketTickDiff(s));\r
+               num_delayed = LIST_NUM(s->DelayedPacketList);\r
+\r
+               if (no_spinlock_for_delay || select_wait_time >= 50 || num_delayed == false)\r
+               {\r
+                       Select(NULL, (num_delayed == 0 ? select_wait_time :\r
+                               (select_wait_time > 100 ? (select_wait_time - 100) : 1)), c1, c2);\r
+               }\r
+               else\r
+               {\r
+                       YieldCpu();\r
+               }\r
+\r
+               num = 0;\r
+\r
+               // 仮想マシンからパケットを受信する\r
+               while (size = VirtualGetNextPacket(v, &data))\r
+               {\r
+                       BLOCK *block;\r
+\r
+                       // パケットブロックを生成\r
+                       block = NewBlock(data, size, 0);\r
+                       if (block->Size > MAX_PACKET_SIZE)\r
+                       {\r
+                               // パケットサイズ超過\r
+                               FreeBlock(block);\r
+                       }\r
+                       else\r
+                       {\r
+                               // データブロックをキューに追加\r
+                               InsertReveicedBlockToQueue(c, block);\r
+                       }\r
+                       num++;\r
+                       if (num >= MAX_SEND_SOCKET_QUEUE_NUM)\r
+                       {\r
+//                             WHERE;\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       else if (c->Protocol == CONNECTION_HUB_LINK_SERVER)\r
+       {\r
+               // HUB リンク\r
+               // 単純に Cancel を待つだけ\r
+               if (c->SendBlocks->num_item == 0)\r
+               {\r
+                       UINT time = SELECT_TIME;\r
+\r
+                       time = MIN(time, GetNextDelayedPacketTickDiff(s));\r
+                       num_delayed = LIST_NUM(s->DelayedPacketList);\r
+\r
+                       if (no_spinlock_for_delay || time >= 50 || num_delayed == false)\r
+                       {\r
+                               Select(NULL, (num_delayed == 0 ? time : (time > 100 ? (time - 100) : 1)), c1, c2);\r
+                       }\r
+                       else\r
+                       {\r
+                               YieldCpu();\r
+                       }\r
+               }\r
+       }\r
+       else if (c->Protocol == CONNECTION_HUB_LAYER3)\r
+       {\r
+               // Layer-3 スイッチ セッション\r
+               L3IF *f = s->L3If;\r
+               UINT size, num = 0;\r
+               void *data;\r
+\r
+               if (f->SendQueue->num_item == 0)\r
+               {\r
+                       UINT time = SELECT_TIME_FOR_NAT;\r
+\r
+                       if (f->ArpWaitTable != NULL)\r
+                       {\r
+                               LockList(f->ArpWaitTable);\r
+                               {\r
+                                       if (LIST_NUM(f->ArpWaitTable) == 0)\r
+                                       {\r
+                                               time = SELECT_TIME;\r
+                                       }\r
+                               }\r
+                               UnlockList(f->ArpWaitTable);\r
+                       }\r
+\r
+                       time = MIN(time, GetNextDelayedPacketTickDiff(s));\r
+                       num_delayed = LIST_NUM(s->DelayedPacketList);\r
+\r
+                       if (no_spinlock_for_delay || time >= 50 || num_delayed == false)\r
+                       {\r
+                               Select(NULL, (num_delayed == 0 ? time : (time > 100 ? (time - 100) : 1)), c1, c2);\r
+                       }\r
+                       else\r
+                       {\r
+                               YieldCpu();\r
+                       }\r
+               }\r
+\r
+               // 次のパケットを取得する\r
+               while (size = L3GetNextPacket(f, &data))\r
+               {\r
+                       BLOCK *block = NewBlock(data, size, 0);\r
+                       if (block->Size > MAX_PACKET_SIZE)\r
+                       {\r
+                               FreeBlock(block);\r
+                       }\r
+                       else\r
+                       {\r
+                               InsertReveicedBlockToQueue(c, block);\r
+                       }\r
+\r
+                       num++;\r
+                       if (num >= MAX_SEND_SOCKET_QUEUE_NUM)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       else if (c->Protocol == CONNECTION_HUB_BRIDGE)\r
+       {\r
+               BRIDGE *b = c->Session->Bridge;\r
+\r
+               // Bridge セッション\r
+               if (b->Active)\r
+               {\r
+                       void *data;\r
+                       UINT ret;\r
+                       UINT num = 0;\r
+                       bool check_device_num = false;\r
+                       UINT time = SELECT_TIME;\r
+\r
+                       time = MIN(time, GetNextDelayedPacketTickDiff(s));\r
+                       num_delayed = LIST_NUM(s->DelayedPacketList);\r
+\r
+                       // ブリッジ動作中\r
+                       if (no_spinlock_for_delay || time >= 50 || num_delayed == false)\r
+                       {\r
+                               Select(NULL, (num_delayed == 0 ? time : (time > 100 ? (time - 100) : 1)), c1, c2);\r
+                       }\r
+                       else\r
+                       {\r
+                               YieldCpu();\r
+                       }\r
+\r
+                       if ((b->LastNumDeviceCheck + BRIDGE_NUM_DEVICE_CHECK_SPAN) <= Tick64())\r
+                       {\r
+                               check_device_num = true;\r
+                               b->LastNumDeviceCheck = Tick64();\r
+                       }\r
+\r
+                       // ブリッジから次のパケットを取得する\r
+                       while (true)\r
+                       {\r
+                               if (check_device_num && b->LastNumDevice != GetEthDeviceHash())\r
+                               {\r
+                                       ret = INFINITE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       ret = EthGetPacket(b->Eth, &data);\r
+                               }\r
+\r
+#ifdef OS_WIN32\r
+                               if (b->Eth != NULL && b->Eth->LoopbackBlock)\r
+                               {\r
+                                       // ブリッジにおける eth デバイスがループバックパケットを遮断\r
+                                       // する能力がある場合は CheckMac ポリシーを無効にする\r
+                                       if (c->Session != NULL && c->Session->Policy != NULL)\r
+                                       {\r
+                                               c->Session->Policy->CheckMac = false;\r
+                                       }\r
+                               }\r
+#endif // OS_WIN32\r
+\r
+                               if (ret == INFINITE)\r
+                               {\r
+                                       // エラー発生 ブリッジを停止させる\r
+                                       CloseEth(b->Eth);\r
+                                       b->Eth = NULL;\r
+                                       b->Active = false;\r
+                                       ReleaseCancel(s->Cancel2);\r
+                                       s->Cancel2 = NULL;\r
+\r
+                                       HLog(s->Hub, "LH_BRIDGE_2", s->Name, b->Name);\r
+                                       Debug("Bridge Device Error.\n");\r
+\r
+                                       break;\r
+                               }\r
+                               else if (ret == 0)\r
+                               {\r
+                                       // これ以上パケットが無い\r
+                                       break;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // パケットをキューに追加\r
+                                       BLOCK *block = NewBlock(data, ret, 0);\r
+\r
+                                       PROBE_DATA2("ConnectionReceive: NewBlock", data, ret);\r
+\r
+                                       if (ret > 1514)\r
+                                       {\r
+                                               NormalizeEthMtu(b, c, ret);\r
+                                       }\r
+\r
+                                       if (block->Size > MAX_PACKET_SIZE)\r
+                                       {\r
+                                               // パケットサイズ超過\r
+                                               FreeBlock(block);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               InsertReveicedBlockToQueue(c, block);\r
+                                       }\r
+                                       num++;\r
+                                       if (num >= MAX_SEND_SOCKET_QUEUE_NUM)\r
+                                       {\r
+//                                             WHERE;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       ETH *e;\r
+                       // 現在ブリッジは停止している\r
+                       Select(NULL, SELECT_TIME, c1, NULL);\r
+\r
+                       if (b->LastBridgeTry == 0 || (b->LastBridgeTry + BRIDGE_TRY_SPAN) <= Tick64())\r
+                       {\r
+                               b->LastBridgeTry = Tick64();\r
+\r
+                               // Ethernet デバイスを開こうとしてみる\r
+                               e = OpenEth(b->Name, b->Local, b->TapMode, b->TapMacAddress);\r
+                               if (e != NULL)\r
+                               {\r
+                                       // 成功\r
+                                       b->Eth = e;\r
+                                       b->Active = true;\r
+                                       b->LastNumDeviceCheck = Tick64();\r
+                                       b->LastNumDevice = GetEthDeviceHash();\r
+\r
+                                       Debug("Bridge Open Succeed.\n");\r
+\r
+                                       HLog(c->Session->Hub, "LH_BRIDGE_1", c->Session->Name, b->Name);\r
+\r
+                                       s->Cancel2 = EthGetCancel(b->Eth);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// Ethernet デバイスの MTU を正規化する\r
+void NormalizeEthMtu(BRIDGE *b, CONNECTION *c, UINT packet_size)\r
+{\r
+       // 引数チェック\r
+       if (packet_size == 0 || b == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 現在の MTU を超えるパケットの場合は MTU を引き上げる\r
+       if (EthIsChangeMtuSupported(b->Eth))\r
+       {\r
+               UINT currentMtu = EthGetMtu(b->Eth);\r
+               if (currentMtu != 0)\r
+               {\r
+                       if (packet_size > currentMtu)\r
+                       {\r
+                               bool ok = EthSetMtu(b->Eth, packet_size);\r
+\r
+                               if (ok)\r
+                               {\r
+                                       HLog(c->Session->Hub, "LH_SET_MTU", c->Session->Name,\r
+                                               b->Name, currentMtu, packet_size, packet_size);\r
+                               }\r
+                               else\r
+                               {\r
+                                       UINT64 now = Tick64();\r
+\r
+                                       if (b->LastChangeMtuError == 0 ||\r
+                                               now >= (b->LastChangeMtuError + 60000ULL))\r
+                                       {\r
+                                               HLog(c->Session->Hub, "LH_SET_MTU_ERROR", c->Session->Name,\r
+                                                       b->Name, currentMtu, packet_size, packet_size);\r
+\r
+                                               b->LastChangeMtuError = now;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// ブロックの解放\r
+void FreeBlock(BLOCK *b)\r
+{\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(b->Buf);\r
+       Free(b);\r
+}\r
+\r
+// 新しいブロック作成\r
+BLOCK *NewBlock(void *data, UINT size, int compress)\r
+{\r
+       BLOCK *b;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = ZeroMallocFast(sizeof(BLOCK));\r
+\r
+       if (compress == 0)\r
+       {\r
+               // 非圧縮\r
+               b->Compressed = FALSE;\r
+               b->Buf = data;\r
+               b->Size = size;\r
+               b->SizeofData = size;\r
+       }\r
+       else if (compress == 1)\r
+       {\r
+               UINT max_size;\r
+\r
+               // 圧縮\r
+               b->Compressed = TRUE;\r
+               max_size = CalcCompress(size);\r
+               b->Buf = MallocFast(max_size);\r
+               b->Size = Compress(b->Buf, max_size, data, size);\r
+               b->SizeofData = size;\r
+\r
+               // 古いデータブロックを破棄\r
+               Free(data);\r
+       }\r
+       else\r
+       {\r
+               // 展開\r
+               UINT max_size;\r
+\r
+               max_size = MAX_PACKET_SIZE;\r
+               b->Buf = MallocFast(max_size);\r
+               b->Size = Uncompress(b->Buf, max_size, data, size);\r
+               b->SizeofData = size;\r
+\r
+               // 古いデータを破棄\r
+               Free(data);\r
+       }\r
+\r
+       return b;\r
+}\r
+\r
+// TCP ソケットの作成\r
+TCPSOCK *NewTcpSock(SOCK *s)\r
+{\r
+       TCPSOCK *ts;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ts = ZeroMalloc(sizeof(TCPSOCK));\r
+\r
+       ts->Sock = s;\r
+       AddRef(s->ref);\r
+\r
+       ts->RecvFifo = NewFifo();\r
+       ts->SendFifo = NewFifo();\r
+       ts->LastCommTime = Tick64();\r
+\r
+       // タイムアウト値の解消\r
+       SetTimeout(s, TIMEOUT_INFINITE);\r
+\r
+       return ts;\r
+}\r
+\r
+// TCP ソケット用暗号化鍵の設定\r
+void InitTcpSockRc4Key(TCPSOCK *ts, bool server_mode)\r
+{\r
+       RC4_KEY_PAIR *pair;\r
+       CRYPT *c1, *c2;\r
+       // 引数チェック\r
+       if (ts == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pair = &ts->Rc4KeyPair;\r
+\r
+       c1 = NewCrypt(pair->ClientToServerKey, sizeof(pair->ClientToServerKey));\r
+       c2 = NewCrypt(pair->ServerToClientKey, sizeof(pair->ServerToClientKey));\r
+\r
+       if (server_mode)\r
+       {\r
+               ts->RecvKey = c1;\r
+               ts->SendKey = c2;\r
+       }\r
+       else\r
+       {\r
+               ts->SendKey = c1;\r
+               ts->RecvKey = c2;\r
+       }\r
+}\r
+\r
+// TCP ソケットの解放\r
+void FreeTcpSock(TCPSOCK *ts)\r
+{\r
+       // 引数チェック\r
+       if (ts == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Disconnect(ts->Sock);\r
+       ReleaseSock(ts->Sock);\r
+       ReleaseFifo(ts->RecvFifo);\r
+       ReleaseFifo(ts->SendFifo);\r
+\r
+       if (ts->SendKey)\r
+       {\r
+               FreeCrypt(ts->SendKey);\r
+       }\r
+       if (ts->RecvKey)\r
+       {\r
+               FreeCrypt(ts->RecvKey);\r
+       }\r
+\r
+       Free(ts);\r
+}\r
+\r
+// コネクションのトンネリングモードを終了する\r
+void EndTunnelingMode(CONNECTION *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // プロトコル\r
+       if (c->Protocol == CONNECTION_TCP)\r
+       {\r
+               // TCP\r
+               DisconnectTcpSockets(c);\r
+       }\r
+       else\r
+       {\r
+               // UDP\r
+               DisconnectUDPSockets(c);\r
+       }\r
+}\r
+\r
+// コネクションをトンネリングモードに移行させる\r
+void StartTunnelingMode(CONNECTION *c)\r
+{\r
+       SOCK *s;\r
+       TCP *tcp;\r
+       TCPSOCK *ts;\r
+       IP ip;\r
+       UINT port;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tcp = c->Tcp;\r
+\r
+       // プロトコル\r
+       if (c->Protocol == CONNECTION_TCP)\r
+       {\r
+               // TCP\r
+               s = c->FirstSock;\r
+\r
+               ts = NewTcpSock(s);\r
+\r
+               if (c->ServerMode == false)\r
+               {\r
+                       if (c->Session->ClientOption->ConnectionDisconnectSpan != 0)\r
+                       {\r
+                               ts->DisconnectTick = Tick64() + c->Session->ClientOption->ConnectionDisconnectSpan * (UINT64)1000;\r
+                       }\r
+               }\r
+\r
+               LockList(tcp->TcpSockList);\r
+               {\r
+                       Add(tcp->TcpSockList, ts);\r
+               }\r
+               UnlockList(tcp->TcpSockList);\r
+               ReleaseSock(s);\r
+               c->FirstSock = NULL;\r
+       }\r
+       else\r
+       {\r
+               // UDP\r
+               s = c->FirstSock;\r
+               Copy(&ip, &s->RemoteIP, sizeof(IP));\r
+               // この時点で TCP コネクションは切断してよい\r
+               c->FirstSock = NULL;\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+\r
+               // UDP 構造体の初期化\r
+               c->Udp = ZeroMalloc(sizeof(UDP));\r
+\r
+               if (c->ServerMode)\r
+               {\r
+                       // サーバーモード\r
+                       // エントリの追加\r
+                       AddUDPEntry(c->Cedar, c->Session);\r
+                       c->Udp->s = NULL;\r
+               }\r
+               else\r
+               {\r
+                       port = c->Session->ClientOption->PortUDP;\r
+                       // クライアントモード\r
+                       c->Udp->s = NewUDP(0);\r
+                       // IP アドレスとポート番号を書く\r
+                       Copy(&c->Udp->ip, &ip, sizeof(IP));\r
+                       c->Udp->port = port;\r
+               }\r
+\r
+               // キュー\r
+               c->Udp->BufferQueue = NewQueue();\r
+       }\r
+}\r
+\r
+// 新しいコネクションを受け付ける関数\r
+void ConnectionAccept(CONNECTION *c)\r
+{\r
+       SOCK *s;\r
+       X *x;\r
+       K *k;\r
+       char tmp[128];\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Debug("ConnectionAccept()\n");\r
+\r
+       // ソケットを取得する\r
+       s = c->FirstSock;\r
+       AddRef(s->ref);\r
+\r
+       Dec(c->Cedar->AcceptingSockets);\r
+\r
+       IPToStr(tmp, sizeof(tmp), &s->RemoteIP);\r
+       SLog(c->Cedar, "LS_CONNECTION_START_1", tmp, s->RemoteHostname, s->RemotePort, c->Name);\r
+\r
+       // タイムアウト設定\r
+       SetTimeout(s, CONNECTING_TIMEOUT);\r
+\r
+       // 暗号化アルゴリズムを指定する\r
+       Lock(c->lock);\r
+       {\r
+               if (c->Cedar->CipherList != NULL)\r
+               {\r
+                       SetWantToUseCipher(s, c->Cedar->CipherList);\r
+               }\r
+\r
+               x = CloneX(c->Cedar->ServerX);\r
+               k = CloneK(c->Cedar->ServerK);\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       // SSL 通信を開始する\r
+       Debug("StartSSL()\n");\r
+       if (StartSSL(s, x, k) == false)\r
+       {\r
+               // 失敗\r
+               Debug("Failed to StartSSL.\n");\r
+               FreeX(x);\r
+               FreeK(k);\r
+               goto ERROR;\r
+       }\r
+\r
+       FreeX(x);\r
+       FreeK(k);\r
+\r
+       SLog(c->Cedar, "LS_SSL_START", c->Name, s->CipherName);\r
+\r
+       // 接続を受諾する\r
+       if (ServerAccept(c) == false)\r
+       {\r
+               // 失敗\r
+               Debug("ServerAccept Failed. Err = %u\n", c->Err);\r
+               goto ERROR;\r
+       }\r
+\r
+       if (c->flag1 == false)\r
+       {\r
+               Debug("%s %u c->flag1 == false\n", __FILE__, __LINE__);\r
+               Disconnect(s);\r
+       }\r
+       DelConnection(c->Cedar, c);\r
+       ReleaseSock(s);\r
+       return;\r
+\r
+ERROR:\r
+       Debug("ConnectionAccept() Error.\n");\r
+       Disconnect(s);\r
+       DelConnection(c->Cedar, c);\r
+       ReleaseSock(s);\r
+}\r
+\r
+// 現在動作しているすべての追加コネクションを張るスレッドを中断する\r
+void StopAllAdditionalConnectThread(CONNECTION *c)\r
+{\r
+       UINT i, num;\r
+       SOCK **socks;\r
+       THREAD **threads;\r
+       // 引数チェック\r
+       if (c == NULL || c->ServerMode != false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // まずソケットを切断する\r
+       LockList(c->ConnectingSocks);\r
+       {\r
+               num = LIST_NUM(c->ConnectingSocks);\r
+               socks = ToArray(c->ConnectingSocks);\r
+               DeleteAll(c->ConnectingSocks);\r
+       }\r
+       UnlockList(c->ConnectingSocks);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               Disconnect(socks[i]);\r
+               ReleaseSock(socks[i]);\r
+       }\r
+       Free(socks);\r
+\r
+       // 次にスレッドの停止を待つ\r
+       LockList(c->ConnectingThreads);\r
+       {\r
+               num = LIST_NUM(c->ConnectingThreads);\r
+               Debug("c->ConnectingThreads: %u\n", num);\r
+               threads = ToArray(c->ConnectingThreads);\r
+               DeleteAll(c->ConnectingThreads);\r
+       }\r
+       UnlockList(c->ConnectingThreads);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               WaitThread(threads[i], INFINITE);\r
+               ReleaseThread(threads[i]);\r
+       }\r
+       Free(threads);\r
+}\r
+\r
+// コネクションの停止\r
+void StopConnection(CONNECTION *c, bool no_wait)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Debug("Stop Connection: %s\n", c->Name);\r
+\r
+       // 停止フラグ\r
+       c->Halt = true;\r
+       Disconnect(c->FirstSock);\r
+\r
+       if (no_wait == false)\r
+       {\r
+               // スレッド停止まで待機\r
+               WaitThread(c->Thread, INFINITE);\r
+       }\r
+}\r
+\r
+// UDP ソケットをすべて閉じる\r
+void DisconnectUDPSockets(CONNECTION *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (c->Protocol != CONNECTION_UDP)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // エントリの削除\r
+       if (c->ServerMode)\r
+       {\r
+               DelUDPEntry(c->Cedar, c->Session);\r
+       }\r
+\r
+       // UDP 構造体の削除\r
+       if (c->Udp != NULL)\r
+       {\r
+               if (c->Udp->s != NULL)\r
+               {\r
+                       ReleaseSock(c->Udp->s);\r
+               }\r
+               if (c->Udp->BufferQueue != NULL)\r
+               {\r
+                       // キューの解放\r
+                       BUF *b;\r
+                       while (b = GetNext(c->Udp->BufferQueue))\r
+                       {\r
+                               FreeBuf(b);\r
+                       }\r
+                       ReleaseQueue(c->Udp->BufferQueue);\r
+               }\r
+               Free(c->Udp);\r
+               c->Udp = NULL;\r
+       }\r
+\r
+       if (c->FirstSock != NULL)\r
+       {\r
+               Disconnect(c->FirstSock);\r
+               ReleaseSock(c->FirstSock);\r
+               c->FirstSock = NULL;\r
+       }\r
+}\r
+\r
+// TCP コネクションをすべて閉じる\r
+void DisconnectTcpSockets(CONNECTION *c)\r
+{\r
+       UINT i, num;\r
+       TCP *tcp;\r
+       TCPSOCK **tcpsocks;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (c->Protocol != CONNECTION_TCP)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tcp = c->Tcp;\r
+       LockList(tcp->TcpSockList);\r
+       {\r
+               tcpsocks = ToArray(tcp->TcpSockList);\r
+               num = LIST_NUM(tcp->TcpSockList);\r
+               DeleteAll(tcp->TcpSockList);\r
+       }\r
+       UnlockList(tcp->TcpSockList);\r
+\r
+       if (num != 0)\r
+       {\r
+               Debug("--- SOCKET STATUS ---\n");\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       TCPSOCK *ts = tcpsocks[i];\r
+                       Debug(" SOCK %2u: %u\n", i, ts->Sock->SendSize);\r
+                       FreeTcpSock(ts);\r
+               }\r
+       }\r
+\r
+       Free(tcpsocks);\r
+}\r
+\r
+// コネクションのクリーンアップ\r
+void CleanupConnection(CONNECTION *c)\r
+{\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DeleteLock(c->lock);\r
+       ReleaseCedar(c->Cedar);\r
+\r
+       switch (c->Protocol)\r
+       {\r
+       case CONNECTION_TCP:\r
+               // TCP コネクションリストの解放\r
+               DisconnectTcpSockets(c);\r
+               break;\r
+\r
+       case CONNECTION_UDP:\r
+               break;\r
+       }\r
+\r
+       ReleaseList(c->Tcp->TcpSockList);\r
+       Free(c->Tcp);\r
+\r
+       ReleaseSock(c->FirstSock);\r
+       c->FirstSock = NULL;\r
+\r
+       ReleaseThread(c->Thread);\r
+       Free(c->Name);\r
+\r
+       // すべての送信ブロックと受信ブロックを解放\r
+       if (c->SendBlocks)\r
+       {\r
+               LockQueue(c->SendBlocks);\r
+               {\r
+                       BLOCK *b;\r
+                       while (b = GetNext(c->SendBlocks))\r
+                       {\r
+                               FreeBlock(b);\r
+                       }\r
+               }\r
+               UnlockQueue(c->SendBlocks);\r
+       }\r
+       if (c->SendBlocks2)\r
+       {\r
+               LockQueue(c->SendBlocks2);\r
+               {\r
+                       BLOCK *b;\r
+                       while (b = GetNext(c->SendBlocks2))\r
+                       {\r
+                               FreeBlock(b);\r
+                       }\r
+               }\r
+               UnlockQueue(c->SendBlocks2);\r
+       }\r
+       if (c->ReceivedBlocks)\r
+       {\r
+               LockQueue(c->ReceivedBlocks);\r
+               {\r
+                       BLOCK *b;\r
+                       while (b = GetNext(c->ReceivedBlocks))\r
+                       {\r
+                               FreeBlock(b);\r
+                       }\r
+               }\r
+               UnlockQueue(c->ReceivedBlocks);\r
+       }\r
+\r
+       if (c->ConnectingThreads)\r
+       {\r
+               THREAD **threads;\r
+               LockList(c->ConnectingThreads);\r
+               {\r
+                       num = LIST_NUM(c->ConnectingThreads);\r
+                       threads = ToArray(c->ConnectingThreads);\r
+                       for (i = 0;i < num;i++)\r
+                       {\r
+                               ReleaseThread(threads[i]);\r
+                       }\r
+                       Free(threads);\r
+               }\r
+               UnlockList(c->ConnectingThreads);\r
+               ReleaseList(c->ConnectingThreads);\r
+       }\r
+\r
+       if (c->ConnectingSocks)\r
+       {\r
+               SOCK **socks;\r
+               LockList(c->ConnectingSocks);\r
+               {\r
+                       num = LIST_NUM(c->ConnectingSocks);\r
+                       socks = ToArray(c->ConnectingSocks);\r
+                       for (i = 0;i < num;i++)\r
+                       {\r
+                               Disconnect(socks[i]);\r
+                               ReleaseSock(socks[i]);\r
+                       }\r
+                       Free(socks);\r
+               }\r
+               UnlockList(c->ConnectingSocks);\r
+               ReleaseList(c->ConnectingSocks);\r
+       }\r
+\r
+       if (c->RecvBuf)\r
+       {\r
+               Free(c->RecvBuf);\r
+       }\r
+\r
+       if (c->ServerX != NULL)\r
+       {\r
+               FreeX(c->ServerX);\r
+       }\r
+\r
+       if (c->ClientX != NULL)\r
+       {\r
+               FreeX(c->ClientX);\r
+       }\r
+\r
+       ReleaseQueue(c->ReceivedBlocks);\r
+       ReleaseQueue(c->SendBlocks);\r
+       ReleaseQueue(c->SendBlocks2);\r
+\r
+       DeleteCounter(c->CurrentNumConnection);\r
+\r
+       if (c->CipherName != NULL)\r
+       {\r
+               Free(c->CipherName);\r
+       }\r
+\r
+       Free(c);\r
+}\r
+\r
+// コネクションの解放\r
+void ReleaseConnection(CONNECTION *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(c->ref) == 0)\r
+       {\r
+               CleanupConnection(c);\r
+       }\r
+}\r
+\r
+// コネクションの比較\r
+int CompareConnection(void *p1, void *p2)\r
+{\r
+       CONNECTION *c1, *c2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       c1 = *(CONNECTION **)p1;\r
+       c2 = *(CONNECTION **)p2;\r
+       if (c1 == NULL || c2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCmpi(c1->Name, c2->Name);\r
+}\r
+\r
+// サーバーコネクションの作成\r
+CONNECTION *NewServerConnection(CEDAR *cedar, SOCK *s, THREAD *t)\r
+{\r
+       CONNECTION *c;\r
+       // 引数チェック\r
+       if (cedar == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       c = ZeroMalloc(sizeof(CONNECTION));\r
+       c->ConnectedTick = Tick64();\r
+       c->lock = NewLock();\r
+       c->ref = NewRef();\r
+       c->Cedar = cedar;\r
+       AddRef(c->Cedar->ref);\r
+       c->Protocol = CONNECTION_TCP;\r
+       c->Type = CONNECTION_TYPE_INIT;\r
+       c->FirstSock = s;\r
+       if (s != NULL)\r
+       {\r
+               AddRef(c->FirstSock->ref);\r
+               Copy(&c->ClientIp, &s->RemoteIP, sizeof(IP));\r
+               StrCpy(c->ClientHostname, sizeof(c->ClientHostname), s->RemoteHostname);\r
+       }\r
+       c->Tcp = ZeroMalloc(sizeof(TCP));\r
+       c->Tcp->TcpSockList = NewList(NULL);\r
+       c->ServerMode = true;\r
+       c->Status = CONNECTION_STATUS_ACCEPTED;\r
+       c->Name = CopyStr("INITING");\r
+       c->Thread = t;\r
+       AddRef(t->ref);\r
+       c->CurrentNumConnection = NewCounter();\r
+       Inc(c->CurrentNumConnection);\r
+\r
+       c->ServerVer = cedar->Version;\r
+       c->ServerBuild = cedar->Build;\r
+       StrCpy(c->ServerStr, sizeof(c->ServerStr), cedar->ServerStr);\r
+       GetServerProductName(cedar->Server, c->ServerStr, sizeof(c->ServerStr));\r
+\r
+       if (s != NULL && s->RemoteX != NULL)\r
+       {\r
+               c->ServerX = CloneX(s->RemoteX);\r
+       }\r
+\r
+       // キューの作成\r
+       c->ReceivedBlocks = NewQueue();\r
+       c->SendBlocks = NewQueue();\r
+       c->SendBlocks2 = NewQueue();\r
+\r
+       return c;\r
+}\r
+\r
+// クライアントコネクションの作成\r
+CONNECTION *NewClientConnection(SESSION *s)\r
+{\r
+       return NewClientConnectionEx(s, NULL, 0, 0);\r
+}\r
+CONNECTION *NewClientConnectionEx(SESSION *s, char *client_str, UINT client_ver, UINT client_build)\r
+{\r
+       CONNECTION *c;\r
+\r
+       // CONNECTION オブジェクトの初期化\r
+       c = ZeroMalloc(sizeof(CONNECTION));\r
+       c->ConnectedTick = Tick64();\r
+       c->lock = NewLock();\r
+       c->ref = NewRef();\r
+       c->Cedar = s->Cedar;\r
+       AddRef(c->Cedar->ref);\r
+       if (s->ClientOption->PortUDP == 0)\r
+       {\r
+               // TCP\r
+               c->Protocol = CONNECTION_TCP;\r
+               c->Tcp = ZeroMalloc(sizeof(TCP));\r
+               c->Tcp->TcpSockList = NewList(NULL);\r
+       }\r
+       else\r
+       {\r
+               // UDP\r
+               c->Protocol = CONNECTION_UDP;\r
+       }\r
+       c->ServerMode = false;\r
+       c->Status = CONNECTION_STATUS_CONNECTING;\r
+       c->Name = CopyStr("CLIENT_CONNECTION");\r
+       c->Session = s;\r
+       c->CurrentNumConnection = NewCounter();\r
+       Inc(c->CurrentNumConnection);\r
+\r
+       c->ConnectingThreads = NewList(NULL);\r
+       c->ConnectingSocks = NewList(NULL);\r
+\r
+       if (client_str == NULL)\r
+       {\r
+               c->ClientVer = s->Cedar->Version;\r
+               c->ClientBuild = s->Cedar->Build;\r
+\r
+               if (c->Session->VirtualHost == false)\r
+               {\r
+                       if (c->Session->LinkModeClient == false)\r
+                       {\r
+                               StrCpy(c->ClientStr, sizeof(c->ClientStr), CEDAR_CLIENT_STR);\r
+                       }\r
+                       else\r
+                       {\r
+                               StrCpy(c->ClientStr, sizeof(c->ClientStr), CEDAR_SERVER_LINK_STR);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       StrCpy(c->ClientStr, sizeof(c->ClientStr), CEDAR_ROUTER_STR);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               c->ClientVer = client_ver;\r
+               c->ClientBuild = client_build;\r
+               StrCpy(c->ClientStr, sizeof(c->ClientStr), client_str);\r
+       }\r
+\r
+       // サーバー名とポート番号\r
+       StrCpy(c->ServerName, sizeof(c->ServerName), s->ClientOption->Hostname);\r
+       c->ServerPort = s->ClientOption->Port;\r
+\r
+       // TLS 1.0 使用フラグ\r
+       c->DontUseTls1 = s->ClientOption->NoTls1;\r
+\r
+       // キューの作成\r
+       c->ReceivedBlocks = NewQueue();\r
+       c->SendBlocks = NewQueue();\r
+       c->SendBlocks2 = NewQueue();\r
+\r
+       return c;\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Connection.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Connection.h
new file mode 100644 (file)
index 0000000..642d17c
--- /dev/null
@@ -0,0 +1,317 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Connection.h\r
+// Connection.c のヘッダ\r
+\r
+#ifndef        CONNECTION_H\r
+#define        CONNECTION_H\r
+\r
+#define        KEEP_ALIVE_STRING                               "Internet Connection Keep Alive Packet"\r
+\r
+// KEEP CONNECT 構造体\r
+struct KEEP\r
+{\r
+       LOCK *lock;                                                                             // ロック\r
+       bool Server;                                                                    // サーバーモード\r
+       volatile bool Halt;                                                             // 停止フラグ\r
+       bool Enable;                                                                    // 有効フラグ\r
+       char ServerName[MAX_HOST_NAME_LEN + 1];                 // サーバー名\r
+       UINT ServerPort;                                                                // サーバーポート番号\r
+       bool UdpMode;                                                                   // UDP モード\r
+       UINT Interval;                                                                  // パケット送出間隔\r
+       THREAD *Thread;                                                                 // 接続スレッド\r
+       EVENT *HaltEvent;                                                               // 停止イベント\r
+       CANCEL *Cancel;                                                                 // キャンセル\r
+};\r
+\r
+// 構造体\r
+struct SECURE_SIGN\r
+{\r
+       char SecurePublicCertName[MAX_SECURE_DEVICE_FILE_LEN + 1];      // セキュアデバイス証明書名\r
+       char SecurePrivateKeyName[MAX_SECURE_DEVICE_FILE_LEN + 1];      // セキュアデバイス秘密鍵名\r
+       X *ClientCert;                                  // クライアント証明書\r
+       UCHAR Random[SHA1_SIZE];                // 署名元乱数値\r
+       UCHAR Signature[128];                   // 署名済データ\r
+       UINT UseSecureDeviceId;\r
+       UINT BitmapId;                                  // ビットマップ ID\r
+};\r
+\r
+// 関数型宣言\r
+typedef bool (CHECK_CERT_PROC)(SESSION *s, CONNECTION *c, X *server_x, bool *expired);\r
+typedef bool (SECURE_SIGN_PROC)(SESSION *s, CONNECTION *c, SECURE_SIGN *sign);\r
+\r
+// RC4 鍵ペア\r
+struct RC4_KEY_PAIR\r
+{\r
+       UCHAR ServerToClientKey[16];\r
+       UCHAR ClientToServerKey[16];\r
+};\r
+\r
+// クライアントオプション\r
+struct CLIENT_OPTION\r
+{\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];  // 接続設定名\r
+       char Hostname[MAX_HOST_NAME_LEN + 1];                   // ホスト名\r
+       UINT Port;                                                                              // ポート番号\r
+       UINT PortUDP;                                                                   // UDP ポート番号 (0…TCPのみ使用)\r
+       UINT ProxyType;                                                                 // プロキシの種類\r
+       char ProxyName[MAX_HOST_NAME_LEN + 1];                  // プロキシサーバー名\r
+       UINT ProxyPort;                                                                 // プロキシサーバーのポート番号\r
+       char ProxyUsername[MAX_PROXY_USERNAME_LEN + 1]; // 最大ユーザー名長\r
+       char ProxyPassword[MAX_PROXY_PASSWORD_LEN + 1]; // 最大パスワード長\r
+       UINT NumRetry;                                                                  // 自動リトライ回数\r
+       UINT RetryInterval;                                                             // リトライ間隔\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       UINT MaxConnection;                                                             // 最大同時接続 TCP コネクション数\r
+       bool UseEncrypt;                                                                // 暗号化通信を使用\r
+       bool UseCompress;                                                               // データ圧縮を使用\r
+       bool HalfConnection;                                                    // TCP でハーフコネクションを利用する\r
+       bool NoRoutingTracking;                                                 // ルーティング追跡を無効にする\r
+       char DeviceName[MAX_DEVICE_NAME_LEN + 1];               // VLAN デバイス名\r
+       UINT AdditionalConnectionInterval;                              // 追加コネクション確立時の接続試行間隔\r
+       UINT ConnectionDisconnectSpan;                                  // コネクション切断間隔\r
+       bool HideStatusWindow;                                                  // 状況ウインドウを非表示にする\r
+       bool HideNicInfoWindow;                                                 // NIC 状態ウインドウを非表示にする\r
+       bool RequireMonitorMode;                                                // モニタポートモード\r
+       bool RequireBridgeRoutingMode;                                  // ブリッジまたはルーティングモード\r
+       bool DisableQoS;                                                                // VoIP / QoS 機能を無効化する\r
+       bool FromAdminPack;                                                             // Administration Pack 用\r
+       bool NoTls1;                                                                    // TLS 1.0 を使用しない\r
+};\r
+\r
+// クライアント認証データ\r
+struct CLIENT_AUTH\r
+{\r
+       UINT AuthType;                                                                  // 認証の種類\r
+       char Username[MAX_USERNAME_LEN + 1];                    // ユーザー名\r
+       UCHAR HashedPassword[SHA1_SIZE];                                // ハッシュされたパスワード\r
+       char PlainPassword[MAX_PASSWORD_LEN + 1];               // パスワード\r
+       X *ClientX;                                                                             // クライアント証明書\r
+       K *ClientK;                                                                             // クライアント秘密鍵\r
+       char SecurePublicCertName[MAX_SECURE_DEVICE_FILE_LEN + 1];      // セキュアデバイス証明書名\r
+       char SecurePrivateKeyName[MAX_SECURE_DEVICE_FILE_LEN + 1];      // セキュアデバイス秘密鍵名\r
+       CHECK_CERT_PROC *CheckCertProc;                                 // サーバー証明書確認用プロシージャ\r
+       SECURE_SIGN_PROC *SecureSignProc;                               // セキュリティ署名用プロシージャ\r
+};\r
+\r
+// TCP ソケットデータ構造体\r
+struct TCPSOCK\r
+{\r
+       SOCK *Sock;                                             // ソケット\r
+       FIFO *RecvFifo;                                 // 受信バッファ\r
+       FIFO *SendFifo;                                 // 送信バッファ\r
+       UINT Mode;                                              // 読み取りモード\r
+       UINT WantSize;                                  // 要求しているデータサイズ\r
+       UINT NextBlockNum;                              // 次に読み取れるブロック数の合計\r
+       UINT NextBlockSize;                             // 次に読み取る予定のブロックサイズ\r
+       UINT CurrentPacketNum;                  // 現在のパケット番号\r
+       UINT64 LastCommTime;                    // 最後に通信を行った時刻\r
+       UINT LateCount;                                 // 遅延回数\r
+       UINT Direction;                                 // 方向\r
+       UINT64 NextKeepAliveTime;               // 次に KeepAlive パケットを送信する時刻\r
+       RC4_KEY_PAIR Rc4KeyPair;                // RC4 キーペア\r
+       CRYPT *SendKey;                                 // 送信鍵\r
+       CRYPT *RecvKey;                                 // 受信鍵\r
+       UINT64 DisconnectTick;                  // このコネクションを切断する予定の時刻\r
+};\r
+\r
+// TCP 通信データ構造体\r
+struct TCP\r
+{\r
+       LIST *TcpSockList;                              // TCP ソケットリスト\r
+};\r
+\r
+// UDP 通信データ構造体\r
+struct UDP\r
+{\r
+       SOCK *s;                                                // UDP ソケット (送信用)\r
+       IP ip;                                                  // 送信先 IP アドレス\r
+       UINT port;                                              // 送信先ポート番号\r
+       UINT64 NextKeepAliveTime;               // 次に KeepAlive パケットを送信する時刻\r
+       UINT64 Seq;                                             // パケットシーケンス番号\r
+       UINT64 RecvSeq;\r
+       QUEUE *BufferQueue;                             // 送信予定バッファのキュー\r
+};\r
+\r
+// データブロック\r
+struct BLOCK\r
+{\r
+       BOOL Compressed;                                // 圧縮フラグ\r
+       UINT Size;                                              // ブロックサイズ\r
+       UINT SizeofData;                                // データサイズ\r
+       UCHAR *Buf;                                             // バッファ\r
+       bool PriorityQoS;                               // VoIP / QoS 機能用優先パケット\r
+};\r
+\r
+// コネクション構造体\r
+struct CONNECTION\r
+{\r
+       LOCK *lock;                                             // ロック\r
+       REF *ref;                                               // 参照カウンタ\r
+       CEDAR *Cedar;                                   // Cedar\r
+       struct SESSION *Session;                // セッション\r
+       UINT Protocol;                                  // プロトコル\r
+       SOCK *FirstSock;                                // ネゴシエーション用のソケット\r
+       TCP *Tcp;                                               // TCP 通信データ構造体\r
+       UDP *Udp;                                               // UDP 通信データ構造体\r
+       bool ServerMode;                                // サーバーモード\r
+       UINT Status;                                    // 状態\r
+       char *Name;                                             // コネクション名\r
+       THREAD *Thread;                                 // スレッド\r
+       volatile bool Halt;                             // 停止フラグ\r
+       UCHAR Random[SHA1_SIZE];                // 認証用乱数\r
+       UINT ServerVer;                                 // サーバーバージョン\r
+       UINT ServerBuild;                               // サーバービルド番号\r
+       UINT ClientVer;                                 // クライアントバージョン\r
+       UINT ClientBuild;                               // クライアントビルド番号\r
+       char ServerStr[MAX_SERVER_STR_LEN + 1]; // サーバー文字列\r
+       char ClientStr[MAX_CLIENT_STR_LEN + 1]; // クライアント文字列\r
+       UINT Err;                                               // エラー値\r
+       bool ClientConnectError_NoSavePassword; // 指定されたユーザー名に関してパスワードを保存しない\r
+       QUEUE *ReceivedBlocks;                  // 受信したブロック キュー\r
+       QUEUE *SendBlocks;                              // 送信する予定のブロック キュー\r
+       QUEUE *SendBlocks2;                             // 送信キュー (優先度高)\r
+       COUNTER *CurrentNumConnection;  // 現在のコネクション数のカウンタ\r
+       LIST *ConnectingThreads;                // 接続中のスレッドのリスト\r
+       LIST *ConnectingSocks;                  // 接続中のソケットのリスト\r
+       bool flag1;                                             // フラグ 1\r
+       UCHAR *RecvBuf;                                 // 受信バッファ\r
+       char ServerName[MAX_HOST_NAME_LEN + 1]; // サーバー名\r
+       UINT ServerPort;                                // ポート番号\r
+       bool RestoreServerNameAndPort;  // サーバー名とポート番号を元に戻すフラグ\r
+       bool UseTicket;                                 // チケット使用フラグ\r
+       UCHAR Ticket[SHA1_SIZE];                // チケット\r
+       UINT CurrentSendQueueSize;              // 送信キューの合計サイズ\r
+       X *ServerX;                                             // サーバー証明書\r
+       X *ClientX;                                             // クライアント証明書\r
+       char *CipherName;                               // 暗号化アルゴリズム名\r
+       UINT64 ConnectedTick;                   // 接続された時刻\r
+       IP ClientIp;                                    // クライアント IP アドレス\r
+       char ClientHostname[MAX_HOST_NAME_LEN + 1];     // クライアントホスト名\r
+       UINT Type;                                              // 種類\r
+       bool DontUseTls1;                               // TLS 1.0 を使用しない\r
+       void *hWndForUI;                                // 親ウインドウ\r
+};\r
+\r
+\r
+\r
+// 関数プロトタイプ\r
+\r
+CONNECTION *NewClientConnection(SESSION *s);\r
+CONNECTION *NewClientConnectionEx(SESSION *s, char *client_str, UINT client_ver, UINT client_build);\r
+CONNECTION *NewServerConnection(CEDAR *cedar, SOCK *s, THREAD *t);\r
+void ReleaseConnection(CONNECTION *c);\r
+void CleanupConnection(CONNECTION *c);\r
+int CompareConnection(void *p1, void *p2);\r
+void StopConnection(CONNECTION *c, bool no_wait);\r
+void ConnectionAccept(CONNECTION *c);\r
+void StartTunnelingMode(CONNECTION *c);\r
+void EndTunnelingMode(CONNECTION *c);\r
+void DisconnectTcpSockets(CONNECTION *c);\r
+void ConnectionReceive(CONNECTION *c, CANCEL *c1, CANCEL *c2);\r
+void ConnectionSend(CONNECTION *c);\r
+TCPSOCK *NewTcpSock(SOCK *s);\r
+void FreeTcpSock(TCPSOCK *ts);\r
+BLOCK *NewBlock(void *data, UINT size, int compress);\r
+void FreeBlock(BLOCK *b);\r
+void StopAllAdditionalConnectThread(CONNECTION *c);\r
+UINT GenNextKeepAliveSpan(CONNECTION *c);\r
+void SendKeepAlive(CONNECTION *c, TCPSOCK *ts);\r
+void DisconnectUDPSockets(CONNECTION *c);\r
+void PutUDPPacketData(CONNECTION *c, void *data, UINT size);\r
+void SendDataWithUDP(SOCK *s, CONNECTION *c);\r
+void InsertReveicedBlockToQueue(CONNECTION *c, BLOCK *block);\r
+void InitTcpSockRc4Key(TCPSOCK *ts, bool server_mode);\r
+UINT TcpSockRecv(SESSION *s, TCPSOCK *ts, void *data, UINT size);\r
+UINT TcpSockSend(SESSION *s, TCPSOCK *ts, void *data, UINT size);\r
+void WriteSendFifo(SESSION *s, TCPSOCK *ts, void *data, UINT size);\r
+void WriteRecvFifo(SESSION *s, TCPSOCK *ts, void *data, UINT size);\r
+CLIENT_AUTH *CopyClientAuth(CLIENT_AUTH *a);\r
+BUF *NewKeepPacket(bool server_mode);\r
+void KeepThread(THREAD *thread, void *param);\r
+KEEP *StartKeep();\r
+void StopKeep(KEEP *k);\r
+void InRpcSecureSign(SECURE_SIGN *t, PACK *p);\r
+void OutRpcSecureSign(PACK *p, SECURE_SIGN *t);\r
+void FreeRpcSecureSign(SECURE_SIGN *t);\r
+void NormalizeEthMtu(BRIDGE *b, CONNECTION *c, UINT packet_size);\r
+\r
+\r
+\r
+#endif // CONNECTION_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Console.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Console.c
new file mode 100644 (file)
index 0000000..53c9cab
--- /dev/null
@@ -0,0 +1,2411 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Console.c\r
+// コンソール サービス\r
+\r
+#include "CedarPch.h"\r
+\r
+\r
+// コマンドのヘルプを表示する\r
+void PrintCmdHelp(CONSOLE *c, char *cmd_name, TOKEN_LIST *param_list)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t *buf;\r
+       UINT buf_size;\r
+       wchar_t *description, *args, *help;\r
+       UNI_TOKEN_LIST *t;\r
+       UINT width;\r
+       UINT i;\r
+       char *space;\r
+       // 引数チェック\r
+       if (c == NULL || cmd_name == NULL || param_list == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       width = GetConsoleWidth(c) - 2;\r
+\r
+       buf_size = sizeof(wchar_t) * (width + 32);\r
+       buf = Malloc(buf_size);\r
+\r
+       GetCommandHelpStr(cmd_name, &description, &args, &help);\r
+\r
+       space = MakeCharArray(' ', 2);\r
+\r
+       // タイトル\r
+       UniFormat(tmp, sizeof(tmp), _UU("CMD_HELP_TITLE"), cmd_name);\r
+       c->Write(c, tmp);\r
+       c->Write(c, L"");\r
+\r
+       // 目的\r
+       c->Write(c, _UU("CMD_HELP_DESCRIPTION"));\r
+       t = SeparateStringByWidth(description, width - 2);\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               UniFormat(buf, buf_size, L"%S%s", space, t->Token[i]);\r
+               c->Write(c, buf);\r
+       }\r
+       UniFreeToken(t);\r
+       c->Write(c, L"");\r
+\r
+       // 説明\r
+       c->Write(c, _UU("CMD_HELP_HELP"));\r
+       t = SeparateStringByWidth(help, width - 2);\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               UniFormat(buf, buf_size, L"%S%s", space, t->Token[i]);\r
+               c->Write(c, buf);\r
+       }\r
+       UniFreeToken(t);\r
+       c->Write(c, L"");\r
+\r
+       // 使用方法\r
+       c->Write(c, _UU("CMD_HELP_USAGE"));\r
+       t = SeparateStringByWidth(args, width - 2);\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               UniFormat(buf, buf_size, L"%S%s", space, t->Token[i]);\r
+               c->Write(c, buf);\r
+       }\r
+       UniFreeToken(t);\r
+\r
+       // 引数\r
+       if (param_list->NumTokens >= 1)\r
+       {\r
+               c->Write(c, L"");\r
+               c->Write(c, _UU("CMD_HELP_ARGS"));\r
+               PrintCandidateHelp(c, cmd_name, param_list, 2);\r
+       }\r
+\r
+       Free(space);\r
+\r
+       Free(buf);\r
+}\r
+\r
+// SafeStr であるかどうかの評価\r
+bool CmdEvalSafe(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       wchar_t *p = (param == NULL) ? _UU("CMD_EVAL_SAFE") : (wchar_t *)param;\r
+\r
+       if (IsSafeUniStr(str))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       c->Write(c, p);\r
+\r
+       return false;\r
+}\r
+\r
+// 文字列入力プロンプト\r
+wchar_t *CmdPrompt(CONSOLE *c, void *param)\r
+{\r
+       wchar_t *p = (param == NULL) ? _UU("CMD_PROMPT") : (wchar_t *)param;\r
+\r
+       return c->ReadLine(c, p, true);\r
+}\r
+\r
+// 指定されたファイルが存在するかどうか評価\r
+bool CmdEvalIsFile(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       if (IsEmptyStr(tmp))\r
+       {\r
+               c->Write(c, _UU("CMD_FILE_NAME_EMPTY"));\r
+               return false;\r
+       }\r
+\r
+       if (IsFileExists(tmp) == false)\r
+       {\r
+               wchar_t tmp2[MAX_SIZE];\r
+\r
+               UniFormat(tmp2, sizeof(tmp2), _UU("CMD_FILE_NOT_FOUND"), tmp);\r
+               c->Write(c, tmp2);\r
+\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 整数の評価\r
+bool CmdEvalInt1(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       wchar_t *p = (param == NULL) ? _UU("CMD_EVAL_INT") : (wchar_t *)param;\r
+\r
+       if (UniToInt(str) == 0)\r
+       {\r
+               c->Write(c, p);\r
+\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 空白を指定できないパラメータの評価\r
+bool CmdEvalNotEmpty(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       wchar_t *p = (param == NULL) ? _UU("CMD_EVAL_NOT_EMPTY") : (wchar_t *)param;\r
+\r
+       if (UniIsEmptyStr(str) == false)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       c->Write(c, p);\r
+\r
+       return false;\r
+}\r
+\r
+// パラメータの最小 / 最大値評価関数\r
+bool CmdEvalMinMax(CONSOLE *c, wchar_t *str, void *param)\r
+{\r
+       CMD_EVAL_MIN_MAX *e;\r
+       wchar_t *tag;\r
+       UINT v;\r
+       // 引数チェック\r
+       if (param == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       e = (CMD_EVAL_MIN_MAX *)param;\r
+\r
+       if (e->StrName == NULL)\r
+       {\r
+               tag = _UU("CMD_EVAL_MIN_MAX");\r
+       }\r
+       else\r
+       {\r
+               tag = _UU(e->StrName);\r
+       }\r
+\r
+       v = UniToInt(str);\r
+\r
+       if (v >= e->MinValue && v <= e->MaxValue)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               UniFormat(tmp, sizeof(tmp), tag, e->MinValue, e->MaxValue);\r
+               c->Write(c, tmp);\r
+\r
+               return false;\r
+       }\r
+}\r
+\r
+// コマンドのヘルプ文字列を取得する\r
+void GetCommandHelpStr(char *command_name, wchar_t **description, wchar_t **args, wchar_t **help)\r
+{\r
+       char tmp1[128], tmp2[128], tmp3[128];\r
+\r
+       Format(tmp1, sizeof(tmp1), "CMD_%s", command_name);\r
+       Format(tmp2, sizeof(tmp2), "CMD_%s_ARGS", command_name);\r
+       Format(tmp3, sizeof(tmp3), "CMD_%s_HELP", command_name);\r
+\r
+       if (description != NULL)\r
+       {\r
+               *description = _UU(tmp1);\r
+               if (UniIsEmptyStr(*description))\r
+               {\r
+                       *description = _UU("CMD_UNKNOWM");\r
+               }\r
+       }\r
+\r
+       if (args != NULL)\r
+       {\r
+               *args = _UU(tmp2);\r
+               if (UniIsEmptyStr(*args))\r
+               {\r
+                       *args = _UU("CMD_UNKNOWN_ARGS");\r
+               }\r
+       }\r
+\r
+       if (help != NULL)\r
+       {\r
+               *help = _UU(tmp3);\r
+               if (UniIsEmptyStr(*help))\r
+               {\r
+                       *help = _UU("CMD_UNKNOWN_HELP");\r
+               }\r
+       }\r
+}\r
+\r
+// パラメータのヘルプ文字列を取得する\r
+void GetCommandParamHelpStr(char *command_name, char *param_name, wchar_t **description)\r
+{\r
+       char tmp[160];\r
+       if (description == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), "CMD_%s_%s", command_name, param_name);\r
+\r
+       *description = _UU(tmp);\r
+\r
+       if (UniIsEmptyStr(*description))\r
+       {\r
+               *description = _UU("CMD_UNKNOWN_PARAM");\r
+       }\r
+}\r
+\r
+// 文字列比較関数\r
+int CompareCandidateStr(void *p1, void *p2)\r
+{\r
+       char *s1, *s2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       s1 = *(char **)p1;\r
+       s2 = *(char **)p2;\r
+       if (s1 == NULL || s2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (s1[0] == '[' && s2[0] != '[')\r
+       {\r
+               return -1;\r
+       }\r
+       else if (s2[0] == '[' && s1[0] != '[')\r
+       {\r
+               return 1;\r
+       }\r
+\r
+       return StrCmp(s1, s2);\r
+}\r
+\r
+// 候補一覧のヘルプを表示する\r
+void PrintCandidateHelp(CONSOLE *c, char *cmd_name, TOKEN_LIST *candidate_list, UINT left_space)\r
+{\r
+       UINT console_width;\r
+       UINT max_keyword_width;\r
+       LIST *o;\r
+       UINT i;\r
+       wchar_t *tmpbuf;\r
+       UINT tmpbuf_size;\r
+       char *left_space_array;\r
+       char *max_space_array;\r
+       // 引数チェック\r
+       if (c == NULL || candidate_list == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 画面の横幅の取得\r
+       console_width = GetConsoleWidth(c) - 1;\r
+\r
+       tmpbuf_size = sizeof(wchar_t) * (console_width + 32);\r
+       tmpbuf = Malloc(tmpbuf_size);\r
+\r
+       left_space_array = MakeCharArray(' ', left_space);\r
+\r
+       // コマンド名はソートしてリスト化する\r
+       // パラメータ名はソートしない\r
+       o = NewListFast(cmd_name == NULL ? CompareCandidateStr : NULL);\r
+\r
+       max_keyword_width = 0;\r
+\r
+       for (i = 0;i < candidate_list->NumTokens;i++)\r
+       {\r
+               UINT keyword_width;\r
+\r
+               // 各キーワードの横幅を取得する\r
+               Insert(o, candidate_list->Token[i]);\r
+\r
+               keyword_width = StrWidth(candidate_list->Token[i]);\r
+               if (cmd_name != NULL)\r
+               {\r
+                       if (candidate_list->Token[i][0] != '[')\r
+                       {\r
+                               keyword_width += 1;\r
+                       }\r
+                       else\r
+                       {\r
+                               keyword_width -= 2;\r
+                       }\r
+               }\r
+\r
+               max_keyword_width = MAX(max_keyword_width, keyword_width);\r
+       }\r
+\r
+       max_space_array = MakeCharArray(' ', max_keyword_width);\r
+\r
+       // 候補を表示する\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               char tmp[128];\r
+               char *name = LIST_DATA(o, i);\r
+               UNI_TOKEN_LIST *t;\r
+               wchar_t *help;\r
+               UINT j;\r
+               UINT keyword_start_width = left_space;\r
+               UINT descript_start_width = left_space + max_keyword_width + 1;\r
+               UINT descript_width;\r
+               char *space;\r
+\r
+               if (console_width >= (descript_start_width + 5))\r
+               {\r
+                       descript_width = console_width - descript_start_width - 3;\r
+               }\r
+               else\r
+               {\r
+                       descript_width = 2;\r
+               }\r
+\r
+               // 名前を生成する\r
+               if (cmd_name != NULL && name[0] != '[')\r
+               {\r
+                       // パラメータの場合は先頭に "/" を付ける\r
+                       Format(tmp, sizeof(tmp), "/%s", name);\r
+               }\r
+               else\r
+               {\r
+                       // コマンド名の場合はそのままの文字を使用する\r
+                       if (cmd_name == NULL)\r
+                       {\r
+                               StrCpy(tmp, sizeof(tmp), name);\r
+                       }\r
+                       else\r
+                       {\r
+                               StrCpy(tmp, sizeof(tmp), name + 1);\r
+                               if (StrLen(tmp) >= 1)\r
+                               {\r
+                                       tmp[StrLen(tmp) - 1] = 0;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // ヘルプ文字を取得する\r
+               if (cmd_name == NULL)\r
+               {\r
+                       GetCommandHelpStr(name, &help, NULL, NULL);\r
+               }\r
+               else\r
+               {\r
+                       GetCommandParamHelpStr(cmd_name, name, &help);\r
+               }\r
+\r
+               space = MakeCharArray(' ', max_keyword_width - StrWidth(name) - (cmd_name == NULL ? 0 : (name[0] != '[' ? 1 : -2)));\r
+\r
+               t = SeparateStringByWidth(help, descript_width);\r
+\r
+               for (j = 0;j < t->NumTokens;j++)\r
+               {\r
+                       if (j == 0)\r
+                       {\r
+                               UniFormat(tmpbuf, tmpbuf_size, L"%S%S%S - %s",\r
+                                       left_space_array, tmp, space, t->Token[j]);\r
+                       }\r
+                       else\r
+                       {\r
+                               UniFormat(tmpbuf, tmpbuf_size, L"%S%S   %s",\r
+                                       left_space_array, max_space_array, t->Token[j]);\r
+                       }\r
+\r
+                       c->Write(c, tmpbuf);\r
+               }\r
+\r
+               Free(space);\r
+\r
+               UniFreeToken(t);\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       Free(max_space_array);\r
+       Free(tmpbuf);\r
+       Free(left_space_array);\r
+}\r
+\r
+// 文字列を指定された横幅で分割する\r
+UNI_TOKEN_LIST *SeparateStringByWidth(wchar_t *str, UINT width)\r
+{\r
+       UINT wp;\r
+       wchar_t *tmp;\r
+       UINT len, i;\r
+       LIST *o;\r
+       UNI_TOKEN_LIST *ret;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return UniNullToken();\r
+       }\r
+       if (width == 0)\r
+       {\r
+               width = 1;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       len = UniStrLen(str);\r
+       tmp = ZeroMalloc(sizeof(wchar_t) * (len + 32));\r
+       wp = 0;\r
+\r
+       for (i = 0;i < (len + 1);i++)\r
+       {\r
+               wchar_t c = str[i];\r
+\r
+               switch (c)\r
+               {\r
+               case 0:\r
+               case L'\r':\r
+               case L'\n':\r
+                       if (c == L'\r')\r
+                       {\r
+                               if (str[i + 1] == L'\n')\r
+                               {\r
+                                       i++;\r
+                               }\r
+                       }\r
+\r
+                       tmp[wp++] = 0;\r
+                       wp = 0;\r
+\r
+                       Insert(o, UniCopyStr(tmp));\r
+                       break;\r
+\r
+               default:\r
+                       tmp[wp++] = c;\r
+                       tmp[wp] = 0;\r
+                       if (UniStrWidth(tmp) >= width)\r
+                       {\r
+                               tmp[wp++] = 0;\r
+                               wp = 0;\r
+\r
+                               Insert(o, UniCopyStr(tmp));\r
+                       }\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (LIST_NUM(o) == 0)\r
+       {\r
+               Insert(o, CopyUniStr(L""));\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(UNI_TOKEN_LIST));\r
+       ret->NumTokens = LIST_NUM(o);\r
+       ret->Token = ZeroMalloc(sizeof(wchar_t *) * ret->NumTokens);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               wchar_t *s = LIST_DATA(o, i);\r
+\r
+               ret->Token[i] = s;\r
+       }\r
+\r
+       ReleaseList(o);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// 指定した文字列が help を示すかどうかをチェック\r
+bool IsHelpStr(char *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(str, "help") == 0 || StrCmpi(str, "?") == 0 ||\r
+               StrCmpi(str, "man") == 0 || StrCmpi(str, "/man") == 0 ||\r
+               StrCmpi(str, "-man") == 0 || StrCmpi(str, "--man") == 0 ||\r
+               StrCmpi(str, "/help") == 0 || StrCmpi(str, "/?") == 0 ||\r
+               StrCmpi(str, "-help") == 0 || StrCmpi(str, "-?") == 0 ||\r
+               StrCmpi(str, "/h") == 0 || StrCmpi(str, "--help") == 0 ||\r
+               StrCmpi(str, "--?") == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// コマンドの実行\r
+bool DispatchNextCmd(CONSOLE *c, char *prompt, CMD cmd[], UINT num_cmd, void *param)\r
+{\r
+       return DispatchNextCmdEx(c, NULL, prompt, cmd, num_cmd, param);\r
+}\r
+bool DispatchNextCmdEx(CONSOLE *c, wchar_t *exec_command, char *prompt, CMD cmd[], UINT num_cmd, void *param)\r
+{\r
+       wchar_t *str;\r
+       wchar_t *tmp;\r
+       char *cmd_name;\r
+       bool b_exit = false;\r
+       wchar_t *cmd_param;\r
+       UINT ret = ERR_NO_ERROR;\r
+       TOKEN_LIST *t;\r
+       TOKEN_LIST *candidate;\r
+       bool no_end_crlf = false;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (c == NULL || (num_cmd >= 1 && cmd == NULL))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (exec_command == NULL)\r
+       {\r
+               // プロンプトを表示\r
+RETRY:\r
+               tmp = CopyStrToUni(prompt);\r
+               str = c->ReadLine(c, tmp, false);\r
+               Free(tmp);\r
+\r
+               if (str != NULL && IsEmptyUniStr(str))\r
+               {\r
+                       Free(str);\r
+                       goto RETRY;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               // exec_command を使用\r
+               if (UniStartWith(exec_command, L"utvpncmd") == false)\r
+               {\r
+                       if (prompt != NULL)\r
+                       {\r
+                               if (c->ConsoleType != CONSOLE_CSV)\r
+                               {\r
+                                       UniFormat(tmp, sizeof(tmp), L"%S%s", prompt, exec_command);\r
+                                       c->Write(c, tmp);\r
+                               }\r
+                       }\r
+               }\r
+               str = CopyUniStr(exec_command);\r
+       }\r
+\r
+       if (str == NULL)\r
+       {\r
+               // ユーザーキャンセル\r
+               return false;\r
+       }\r
+\r
+       UniTrimCrlf(str);\r
+       UniTrim(str);\r
+\r
+       if (UniIsEmptyStr(str))\r
+       {\r
+               // 何もしない\r
+               Free(str);\r
+               return true;\r
+       }\r
+\r
+       // コマンド名とパラメータに分ける\r
+       if (SeparateCommandAndParam(str, &cmd_name, &cmd_param) == false)\r
+       {\r
+               // 何もしない\r
+               Free(str);\r
+               return true;\r
+       }\r
+\r
+       if (StrLen(cmd_name) >= 2 && cmd_name[0] == '?' && cmd_name[1] != '?')\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               wchar_t *s;\r
+\r
+               StrCpy(tmp, sizeof(tmp), cmd_name + 1);\r
+               StrCpy(cmd_name, 0, tmp);\r
+\r
+               s = UniCopyStr(L"/?");\r
+               Free(cmd_param);\r
+\r
+               cmd_param = s;\r
+       }\r
+\r
+       if (StrLen(cmd_name) >= 2 && EndWith(cmd_name, "?") && cmd_name[StrLen(cmd_name) - 2] != '?')\r
+       {\r
+               wchar_t *s;\r
+\r
+               cmd_name[StrLen(cmd_name) - 1] = 0;\r
+\r
+               s = UniCopyStr(L"/?");\r
+               Free(cmd_param);\r
+\r
+               cmd_param = s;\r
+       }\r
+\r
+       // コマンドの候補を取得する\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = num_cmd;\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               t->Token[i] = CopyStr(cmd[i].Name);\r
+       }\r
+\r
+       if (IsHelpStr(cmd_name))\r
+       {\r
+               if (UniIsEmptyStr(cmd_param))\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       // 使用できるコマンド一覧を表示する\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CMD_HELP_1"), t->NumTokens);\r
+                       c->Write(c, tmp);\r
+\r
+                       PrintCandidateHelp(c, NULL, t, 1);\r
+\r
+                       c->Write(c, L"");\r
+                       c->Write(c, _UU("CMD_HELP_2"));\r
+               }\r
+               else\r
+               {\r
+                       char *cmd_name;\r
+\r
+                       // 指定したコマンドのヘルプを表示する\r
+                       if (SeparateCommandAndParam(cmd_param, &cmd_name, NULL))\r
+                       {\r
+                               bool b = true;\r
+\r
+                               if (IsHelpStr(cmd_name))\r
+                               {\r
+                                       b = false;\r
+                               }\r
+\r
+                               if (b)\r
+                               {\r
+                                       wchar_t str[MAX_SIZE];\r
+\r
+                                       UniFormat(str, sizeof(str), L"%S /help", cmd_name);\r
+                                       DispatchNextCmdEx(c, str, NULL, cmd, num_cmd, param);\r
+                                       no_end_crlf = true;\r
+                               }\r
+\r
+                               Free(cmd_name);\r
+                       }\r
+               }\r
+       }\r
+       else if (StrCmpi(cmd_name, "exit") == 0 || StrCmpi(cmd_name, "quit") == 0)\r
+       {\r
+               // 終了\r
+               b_exit = true;\r
+       }\r
+       else\r
+       {\r
+               candidate = GetRealnameCandidate(cmd_name, t);\r
+\r
+               if (candidate == NULL || candidate->NumTokens == 0)\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       // 候補無し\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CON_UNKNOWN_CMD"), cmd_name);\r
+                       c->Write(c, tmp);\r
+\r
+                       c->RetCode = ERR_BAD_COMMAND_OR_PARAM;\r
+               }\r
+               else if (candidate->NumTokens >= 2)\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       // 候補が複数ある\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CON_AMBIGIOUS_CMD"), cmd_name);\r
+                       c->Write(c, tmp);\r
+                       c->Write(c, _UU("CON_AMBIGIOUS_CMD_1"));\r
+                       PrintCandidateHelp(c, NULL, candidate, 1);\r
+                       c->Write(c, _UU("CON_AMBIGIOUS_CMD_2"));\r
+\r
+                       c->RetCode = ERR_BAD_COMMAND_OR_PARAM;\r
+               }\r
+               else\r
+               {\r
+                       char *real_cmd_name;\r
+                       UINT i;\r
+\r
+                       // 1 つに定まった\r
+                       real_cmd_name = candidate->Token[0];\r
+\r
+                       for (i = 0;i < num_cmd;i++)\r
+                       {\r
+                               if (StrCmpi(cmd[i].Name, real_cmd_name) == 0)\r
+                               {\r
+                                       if (cmd[i].Proc != NULL)\r
+                                       {\r
+                                               // CSV モードでなければコマンドの説明を表示する\r
+                                               if(c->ConsoleType != CONSOLE_CSV)\r
+                                               {\r
+                                                       wchar_t tmp[256];\r
+                                                       wchar_t *note;\r
+\r
+                                                       GetCommandHelpStr(cmd[i].Name, &note, NULL, NULL);\r
+                                                       UniFormat(tmp, sizeof(tmp), _UU("CMD_EXEC_MSG_NAME"), cmd[i].Name, note);\r
+                                                       c->Write(c, tmp);\r
+                                               }\r
+\r
+                                               // コマンドのプロシージャを呼び出す\r
+                                               ret = cmd[i].Proc(c, cmd[i].Name, cmd_param, param);\r
+\r
+                                               if (ret == INFINITE)\r
+                                               {\r
+                                                       // 終了コマンド\r
+                                                       b_exit = true;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       c->RetCode = ret;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               FreeToken(candidate);\r
+       }\r
+\r
+       FreeToken(t);\r
+       Free(str);\r
+       Free(cmd_name);\r
+       Free(cmd_param);\r
+\r
+       if (no_end_crlf == false)\r
+       {\r
+               //c->Write(c, L"");\r
+       }\r
+\r
+       if (b_exit)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 現在のコンソールの横幅を取得する\r
+UINT GetConsoleWidth(CONSOLE *c)\r
+{\r
+       UINT size;\r
+\r
+       size = c->GetWidth(c);\r
+\r
+       if (size == 0)\r
+       {\r
+               size = 80;\r
+       }\r
+\r
+       if (size < 32)\r
+       {\r
+               size = 32;\r
+       }\r
+\r
+       if (size > 65536)\r
+       {\r
+               size = 65535;\r
+       }\r
+\r
+       return size;\r
+}\r
+\r
+// コマンドラインをコマンドとパラメータの 2 つに分離する\r
+bool SeparateCommandAndParam(wchar_t *src, char **cmd, wchar_t **param)\r
+{\r
+       UINT i, len, wp;\r
+       wchar_t *tmp;\r
+       wchar_t *src_tmp;\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (cmd != NULL)\r
+       {\r
+               *cmd = NULL;\r
+       }\r
+       if (param != NULL)\r
+       {\r
+               *param = NULL;\r
+       }\r
+\r
+       src_tmp = UniCopyStr(src);\r
+       UniTrimCrlf(src_tmp);\r
+       UniTrim(src_tmp);\r
+\r
+       len = UniStrLen(src_tmp);\r
+       tmp = Malloc(sizeof(wchar_t) * (len + 32));\r
+       wp = 0;\r
+\r
+       for (i = 0;i < (len + 1);i++)\r
+       {\r
+               wchar_t c = src_tmp[i];\r
+\r
+               switch (c)\r
+               {\r
+               case 0:\r
+               case L' ':\r
+               case L'\t':\r
+                       tmp[wp] = 0;\r
+                       if (UniIsEmptyStr(tmp))\r
+                       {\r
+                               Free(tmp);\r
+                               Free(src_tmp);\r
+                               return false;\r
+                       }\r
+                       if (cmd != NULL)\r
+                       {\r
+                               *cmd = CopyUniToStr(tmp);\r
+                               Trim(*cmd);\r
+                       }\r
+                       goto ESCAPE;\r
+\r
+               default:\r
+                       tmp[wp++] = c;\r
+                       break;\r
+               }\r
+       }\r
+\r
+ESCAPE:\r
+       if (param != NULL)\r
+       {\r
+               *param = CopyUniStr(&src_tmp[wp]);\r
+               UniTrim(*param);\r
+       }\r
+\r
+       Free(tmp);\r
+       Free(src_tmp);\r
+\r
+       return true;\r
+}\r
+\r
+// ユーザーが指定したコマンド名の省略形に一致する実在するコマンドの一覧の候補を取得する\r
+TOKEN_LIST *GetRealnameCandidate(char *input_name, TOKEN_LIST *real_name_list)\r
+{\r
+       TOKEN_LIST *ret;\r
+       LIST *o;\r
+       UINT i;\r
+       bool ok = false;\r
+       // 引数チェック\r
+       if (input_name == NULL || real_name_list == NULL)\r
+       {\r
+               return NullToken();\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       for (i = 0;i < real_name_list->NumTokens;i++)\r
+       {\r
+               char *name = real_name_list->Token[i];\r
+\r
+               // まず最優先で完全一致するものを検索する\r
+               if (StrCmpi(name, input_name) == 0)\r
+               {\r
+                       Insert(o, name);\r
+                       ok = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (ok == false)\r
+       {\r
+               // 完全一致するコマンドが無い場合、省略形コマンドとして一致するかどうかチェックする\r
+               for (i = 0;i < real_name_list->NumTokens;i++)\r
+               {\r
+                       char *name = real_name_list->Token[i];\r
+\r
+                       if (IsOmissionName(input_name, name) || IsNameInRealName(input_name, name))\r
+                       {\r
+                               // 省略形を発見した\r
+                               Insert(o, name);\r
+                               ok = true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (ok)\r
+       {\r
+               // 1 つ以上の候補が見つかった\r
+               ret = ListToTokenList(o);\r
+       }\r
+       else\r
+       {\r
+               ret = NullToken();\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザーが指定したコマンドが既存のコマンドの省略形かどうかチェックする\r
+bool IsOmissionName(char *input_name, char *real_name)\r
+{\r
+       char oname[128];\r
+       // 引数チェック\r
+       if (input_name == NULL || real_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsAllUpperStr(real_name))\r
+       {\r
+               // すべて大文字のコマンドは省略形をとらない\r
+               return false;\r
+       }\r
+\r
+       GetOmissionName(oname, sizeof(oname), real_name);\r
+\r
+       if (IsEmptyStr(oname))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StartWith(oname, input_name))\r
+       {\r
+               // 例: AccountSecureCertSet の oname は ascs だが\r
+               //     ユーザーが asc と入力した場合は true を返す\r
+               return true;\r
+       }\r
+\r
+       if (StartWith(input_name, oname))\r
+       {\r
+               // 例: AccountConnect と\r
+               //     AccountCreate の 2 つのコマンドが実在する際、\r
+               //     ユーザーが "aconnect" と入力すると、\r
+               //     AccountConnect のみ true になるようにする\r
+\r
+               if (EndWith(real_name, &input_name[StrLen(oname)]))\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// 指定したコマンド名の省略名を取得する\r
+void GetOmissionName(char *dst, UINT size, char *src)\r
+{\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(dst, size, "");\r
+       len = StrLen(src);\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               char c = src[i];\r
+\r
+               if ((c >= '0' && c <= '9') ||\r
+                       (c >= 'A' && c <= 'Z'))\r
+               {\r
+                       char tmp[2];\r
+                       tmp[0] = c;\r
+                       tmp[1] = 0;\r
+\r
+                       StrCat(dst, size, tmp);\r
+               }\r
+       }\r
+}\r
+\r
+// ユーザーが指定したコマンドが既存のコマンドに一致するかどうかチェックする\r
+bool IsNameInRealName(char *input_name, char *real_name)\r
+{\r
+       // 引数チェック\r
+       if (input_name == NULL || real_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StartWith(real_name, input_name))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// コマンドリストをパースする\r
+LIST *ParseCommandList(CONSOLE *c, char *cmd_name, wchar_t *command, PARAM param[], UINT num_param)\r
+{\r
+       UINT i;\r
+       LIST *o;\r
+       bool ok = true;\r
+       TOKEN_LIST *param_list;\r
+       TOKEN_LIST *real_name_list;\r
+       bool help_mode = false;\r
+       wchar_t *tmp;\r
+       // 引数チェック\r
+       if (c == NULL || command == NULL || (num_param >= 1 && param == NULL) || cmd_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 初期化\r
+       for (i = 0;i < num_param;i++)\r
+       {\r
+               if (IsEmptyStr(param[i].Name) == false)\r
+               {\r
+                       if (param[i].Name[0] == '[')\r
+                       {\r
+                               param[i].Tmp = "";\r
+                       }\r
+                       else\r
+                       {\r
+                               param[i].Tmp = NULL;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       param[i].Tmp = "";\r
+               }\r
+       }\r
+\r
+       real_name_list = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       real_name_list->NumTokens = num_param;\r
+       real_name_list->Token = ZeroMalloc(sizeof(char *) * real_name_list->NumTokens);\r
+\r
+       for (i = 0;i < real_name_list->NumTokens;i++)\r
+       {\r
+               real_name_list->Token[i] = CopyStr(param[i].Name);\r
+       }\r
+\r
+       // ユーザーが指定したパラメータ名のリストを生成する\r
+       param_list = GetCommandNameList(command);\r
+\r
+       for (i = 0;i < param_list->NumTokens;i++)\r
+       {\r
+               char *s = param_list->Token[i];\r
+\r
+               if (StrCmpi(s, "help") == 0 || StrCmpi(s, "?") == 0)\r
+               {\r
+                       help_mode = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       tmp = ParseCommand(command, L"");\r
+       if (tmp != NULL)\r
+       {\r
+               if (UniStrCmpi(tmp, L"?") == 0)\r
+               {\r
+                       help_mode = true;\r
+               }\r
+               Free(tmp);\r
+       }\r
+\r
+       if (help_mode)\r
+       {\r
+               // ヘルプを表示\r
+               PrintCmdHelp(c, cmd_name, real_name_list);\r
+               FreeToken(param_list);\r
+               FreeToken(real_name_list);\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < param_list->NumTokens;i++)\r
+       {\r
+               // ユーザーが指定したすべてのパラメータ名について対応するコマンドを取得する\r
+               TOKEN_LIST *candidate = GetRealnameCandidate(param_list->Token[i], real_name_list);\r
+\r
+               if (candidate != NULL && candidate->NumTokens >= 1)\r
+               {\r
+                       if (candidate->NumTokens >= 2)\r
+                       {\r
+                               wchar_t tmp[MAX_SIZE];\r
+\r
+                               // 2 つ以上の候補がある\r
+                               UniFormat(tmp, sizeof(tmp), _UU("CON_AMBIGIOUS_PARAM"), param_list->Token[i]);\r
+                               c->Write(c, tmp);\r
+                               UniFormat(tmp, sizeof(tmp), _UU("CON_AMBIGIOUS_PARAM_1"), cmd_name);\r
+                               c->Write(c, tmp);\r
+\r
+                               PrintCandidateHelp(c, cmd_name, candidate, 1);\r
+\r
+                               c->Write(c, _UU("CON_AMBIGIOUS_PARAM_2"));\r
+\r
+                               ok = false;\r
+                       }\r
+                       else\r
+                       {\r
+                               UINT j;\r
+                               char *real_name = candidate->Token[0];\r
+\r
+                               // 候補が 1 つだけしか無い\r
+                               for (j = 0;j < num_param;j++)\r
+                               {\r
+                                       if (StrCmpi(param[j].Name, real_name) == 0)\r
+                                       {\r
+                                               param[j].Tmp = param_list->Token[i];\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       // 候補無し\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CON_INVALID_PARAM"), param_list->Token[i], cmd_name, cmd_name);\r
+                       c->Write(c, tmp);\r
+\r
+                       ok = false;\r
+               }\r
+\r
+               FreeToken(candidate);\r
+       }\r
+\r
+       if (ok == false)\r
+       {\r
+               FreeToken(param_list);\r
+               FreeToken(real_name_list);\r
+\r
+               return NULL;\r
+       }\r
+\r
+       // リストの作成\r
+       o = NewParamValueList();\r
+\r
+       // パラメータ一覧に指定された名前のすべてのパラメータを読み込む\r
+       for (i = 0;i < num_param;i++)\r
+       {\r
+               bool prompt_input_value = false;\r
+               PARAM *p = &param[i];\r
+\r
+               if (p->Tmp != NULL || p->PromptProc != NULL)\r
+               {\r
+                       wchar_t *name = CopyStrToUni(p->Name);\r
+                       wchar_t *tmp;\r
+                       wchar_t *str;\r
+\r
+                       if (p->Tmp != NULL)\r
+                       {\r
+                               tmp = CopyStrToUni(p->Tmp);\r
+                       }\r
+                       else\r
+                       {\r
+                               tmp = CopyStrToUni(p->Name);\r
+                       }\r
+\r
+                       str = ParseCommand(command, tmp);\r
+                       Free(tmp);\r
+                       if (str != NULL)\r
+                       {\r
+                               wchar_t *unistr;\r
+                               bool ret;\r
+EVAL_VALUE:\r
+                               // 読み込みに成功した\r
+                               unistr = str;\r
+\r
+                               if (p->EvalProc != NULL)\r
+                               {\r
+                                       // EvalProc が指定されている場合は値を評価する\r
+                                       ret = p->EvalProc(c, unistr, p->EvalProcParam);\r
+                               }\r
+                               else\r
+                               {\r
+                                       // EvalProc が指定されていない場合はどのような値でも受け付ける\r
+                                       ret = true;\r
+                               }\r
+\r
+                               if (ret == false)\r
+                               {\r
+                                       // 指定した値は不正である\r
+                                       if (p->PromptProc == NULL)\r
+                                       {\r
+                                               // キャンセル\r
+                                               ok = false;\r
+                                               Free(name);\r
+                                               Free(str);\r
+                                               break;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // もう一度入力させる\r
+                                               Free(str);\r
+                                               str = NULL;\r
+                                               goto SHOW_PROMPT;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       PARAM_VALUE *v;\r
+                                       // 読み込み完了したのでリストに追加する\r
+                                       v = ZeroMalloc(sizeof(PARAM_VALUE));\r
+                                       v->Name = CopyStr(p->Name);\r
+                                       v->StrValue = CopyUniToStr(str);\r
+                                       v->UniStrValue = CopyUniStr(str);\r
+                                       v->IntValue = ToInt(v->StrValue);\r
+                                       Insert(o, v);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // 読み込みに失敗した。指定されたパラメータが指定されていない\r
+                               if (p->PromptProc != NULL)\r
+                               {\r
+                                       wchar_t *tmp;\r
+SHOW_PROMPT:\r
+                                       // 必須パラメータであるのでプロンプトを表示する\r
+                                       tmp = p->PromptProc(c, p->PromptProcParam);\r
+                                       if (tmp == NULL)\r
+                                       {\r
+                                               // ユーザーがキャンセルした\r
+                                               ok = false;\r
+                                               Free(str);\r
+                                               Free(name);\r
+                                               break;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // ユーザーが入力した\r
+                                               c->Write(c, L"");\r
+                                               str = tmp;\r
+                                               prompt_input_value = true;\r
+                                               goto EVAL_VALUE;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       Free(str);\r
+                       Free(name);\r
+               }\r
+       }\r
+\r
+       FreeToken(param_list);\r
+       FreeToken(real_name_list);\r
+\r
+       if (ok)\r
+       {\r
+               return o;\r
+       }\r
+       else\r
+       {\r
+               FreeParamValueList(o);\r
+               return NULL;\r
+       }\r
+}\r
+\r
+// [はい] か [いいえ] の取得\r
+bool GetParamYes(LIST *o, char *name)\r
+{\r
+       char *s;\r
+       char tmp[64];\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s = GetParamStr(o, name);\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), s);\r
+       Trim(tmp);\r
+\r
+       if (StartWith(tmp, "y"))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (StartWith(tmp, "t"))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (ToInt(tmp) != 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// パラメータ値 Int の取得\r
+UINT GetParamInt(LIST *o, char *name)\r
+{\r
+       PARAM_VALUE *v;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       v = FindParamValue(o, name);\r
+       if (v == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               return v->IntValue;\r
+       }\r
+}\r
+\r
+// パラメータ値 Unicode 文字列の取得\r
+wchar_t *GetParamUniStr(LIST *o, char *name)\r
+{\r
+       PARAM_VALUE *v;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       v = FindParamValue(o, name);\r
+       if (v == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       else\r
+       {\r
+               return v->UniStrValue;\r
+       }\r
+}\r
+\r
+// パラメータ値文字列の所得\r
+char *GetParamStr(LIST *o, char *name)\r
+{\r
+       PARAM_VALUE *v;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       v = FindParamValue(o, name);\r
+       if (v == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       else\r
+       {\r
+               return v->StrValue;\r
+       }\r
+}\r
+\r
+// パラメータ値の取得\r
+PARAM_VALUE *FindParamValue(LIST *o, char *name)\r
+{\r
+       PARAM_VALUE t, *ret;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (name == NULL)\r
+       {\r
+               name = "";\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.Name = name;\r
+\r
+       ret = Search(o, &t);\r
+\r
+       return ret;\r
+}\r
+\r
+// パラメータ値リストの解放\r
+void FreeParamValueList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               PARAM_VALUE *v = LIST_DATA(o, i);\r
+\r
+               Free(v->StrValue);\r
+               Free(v->UniStrValue);\r
+               Free(v->Name);\r
+               Free(v);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// パラメータ値リストソート関数\r
+int CmpParamValue(void *p1, void *p2)\r
+{\r
+       PARAM_VALUE *v1, *v2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       v1 = *(PARAM_VALUE **)p1;\r
+       v2 = *(PARAM_VALUE **)p2;\r
+       if (v1 == NULL || v2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (IsEmptyStr(v1->Name) && IsEmptyStr(v2->Name))\r
+       {\r
+               return 0;\r
+       }\r
+       return StrCmpi(v1->Name, v2->Name);\r
+}\r
+\r
+// パラメータ値リストの生成\r
+LIST *NewParamValueList()\r
+{\r
+       return NewListFast(CmpParamValue);\r
+}\r
+\r
+// 入力されたコマンドに含まれていたパラメータ名のリストを取得する\r
+TOKEN_LIST *GetCommandNameList(wchar_t *str)\r
+{\r
+       TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NullToken();\r
+       }\r
+\r
+       Free(ParseCommandEx(str, L"dummy_str", &t));\r
+\r
+       return t;\r
+}\r
+\r
+// 指定した名前で始まるコマンドを取得する\r
+wchar_t *ParseCommand(wchar_t *str, wchar_t *name)\r
+{\r
+       return ParseCommandEx(str, name, NULL);\r
+}\r
+wchar_t *ParseCommandEx(wchar_t *str, wchar_t *name, TOKEN_LIST **param_list)\r
+{\r
+       UNI_TOKEN_LIST *t;\r
+       UINT i;\r
+       wchar_t *tmp;\r
+       wchar_t *ret = NULL;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (name != NULL && UniIsEmptyStr(name))\r
+       {\r
+               name = NULL;\r
+       }\r
+\r
+       o = NULL;\r
+       if (param_list != NULL)\r
+       {\r
+               o = NewListFast(CompareStr);\r
+       }\r
+\r
+       tmp = CopyUniStr(str);\r
+       UniTrim(tmp);\r
+\r
+       i = UniSearchStrEx(tmp, L"/CMD ", 0, false);\r
+\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       if (i != INFINITE && i >= 1 && tmp[i - 1] == L'/')\r
+       {\r
+               i = INFINITE;\r
+       }\r
+       if (i == INFINITE)\r
+       {\r
+               i = UniSearchStrEx(tmp, L"/CMD\t", 0, false);\r
+               if (i != INFINITE && i >= 1 && tmp[i - 1] == L'/')\r
+               {\r
+                       i = INFINITE;\r
+               }\r
+       }\r
+       if (i == INFINITE)\r
+       {\r
+               i = UniSearchStrEx(tmp, L"/CMD:", 0, false);\r
+               if (i != INFINITE && i >= 1 && tmp[i - 1] == L'/')\r
+               {\r
+                       i = INFINITE;\r
+               }\r
+       }\r
+       if (i == INFINITE)\r
+       {\r
+               i = UniSearchStrEx(tmp, L"/CMD=", 0, false);\r
+               if (i != INFINITE && i >= 1 && tmp[i - 1] == L'/')\r
+               {\r
+                       i = INFINITE;\r
+               }\r
+       }\r
+       if (i == INFINITE)\r
+       {\r
+               i = UniSearchStrEx(tmp, L"-CMD ", 0, false);\r
+               if (i != INFINITE && i >= 1 && tmp[i - 1] == L'-')\r
+               {\r
+                       i = INFINITE;\r
+               }\r
+       }\r
+       if (i == INFINITE)\r
+       {\r
+               i = UniSearchStrEx(tmp, L"-CMD\t", 0, false);\r
+               if (i != INFINITE && i >= 1 && tmp[i - 1] == L'-')\r
+               {\r
+                       i = INFINITE;\r
+               }\r
+       }\r
+       if (i == INFINITE)\r
+       {\r
+               i = UniSearchStrEx(tmp, L"-CMD:", 0, false);\r
+               if (i != INFINITE && i >= 1 && tmp[i - 1] == L'-')\r
+               {\r
+                       i = INFINITE;\r
+               }\r
+       }\r
+       if (i == INFINITE)\r
+       {\r
+               i = UniSearchStrEx(tmp, L"-CMD=", 0, false);\r
+               if (i != INFINITE && i >= 1 && tmp[i - 1] == L'-')\r
+               {\r
+                       i = INFINITE;\r
+               }\r
+       }\r
+\r
+       if (i != INFINITE)\r
+       {\r
+               char *s = CopyStr("CMD");\r
+               if (InsertStr(o, s) == false)\r
+               {\r
+                       Free(s);\r
+               }\r
+               if (UniStrCmpi(name, L"CMD") == 0)\r
+               {\r
+                       ret = CopyUniStr(&str[i + 5]);\r
+                       UniTrim(ret);\r
+               }\r
+               else\r
+               {\r
+                       tmp[i] = 0;\r
+               }\r
+       }\r
+\r
+       if (ret == NULL)\r
+       {\r
+               t = UniParseCmdLine(tmp);\r
+\r
+               if (t != NULL)\r
+               {\r
+                       for (i = 0;i < t->NumTokens;i++)\r
+                       {\r
+                               wchar_t *token = t->Token[i];\r
+\r
+                               if ((token[0] == L'-' && token[1] != L'-') ||\r
+                                       (UniStrCmpi(token, L"--help") == 0) ||\r
+                                       (token[0] == L'/' && token[1] != L'/'))\r
+                               {\r
+                                       UINT i;\r
+\r
+                                       // 名前付き引数\r
+                                       // コロン文字があるかどうか調べる\r
+\r
+                                       if (UniStrCmpi(token, L"--help") == 0)\r
+                                       {\r
+                                               token++;\r
+                                       }\r
+\r
+                                       i = UniSearchStrEx(token, L":", 0, false);\r
+                                       if (i == INFINITE)\r
+                                       {\r
+                                               i = UniSearchStrEx(token, L"=", 0, false);\r
+                                       }\r
+                                       if (i != INFINITE)\r
+                                       {\r
+                                               wchar_t *tmp;\r
+                                               char *a;\r
+\r
+                                               // コロン文字がある\r
+                                               tmp = CopyUniStr(token);\r
+                                               tmp[i] = 0;\r
+\r
+                                               a = CopyUniToStr(&tmp[1]);\r
+                                               if (InsertStr(o, a) == false)\r
+                                               {\r
+                                                       Free(a);\r
+                                               }\r
+\r
+                                               if (UniStrCmpi(name, &tmp[1]) == 0)\r
+                                               {\r
+                                                       if (ret == NULL)\r
+                                                       {\r
+                                                               // 内容\r
+                                                               ret = UniCopyStr(&token[i + 1]);\r
+                                                       }\r
+                                               }\r
+\r
+                                               Free(tmp);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // コロン文字が無い\r
+                                               char *a;\r
+\r
+                                               a = CopyUniToStr(&token[1]);\r
+                                               if (InsertStr(o, a) == false)\r
+                                               {\r
+                                                       Free(a);\r
+                                               }\r
+\r
+                                               if (UniStrCmpi(name, &token[1]) == 0)\r
+                                               {\r
+                                                       if (ret == NULL)\r
+                                                       {\r
+                                                               // 空文字\r
+                                                               ret = UniCopyStr(L"");\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 名前無し引数\r
+                                       if (name == NULL)\r
+                                       {\r
+                                               if (ret == NULL)\r
+                                               {\r
+                                                       if (token[0] == L'-' && token[1] == L'-')\r
+                                                       {\r
+                                                               ret = UniCopyStr(&token[1]);\r
+                                                       }\r
+                                                       else if (token[0] == L'/' && token[1] == L'/')\r
+                                                       {\r
+                                                               ret = UniCopyStr(&token[1]);\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               ret = UniCopyStr(token);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       UniFreeToken(t);\r
+               }\r
+       }\r
+\r
+       Free(tmp);\r
+\r
+       if (o != NULL)\r
+       {\r
+               TOKEN_LIST *t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+               UINT i;\r
+\r
+               t->NumTokens = LIST_NUM(o);\r
+               t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+\r
+               for (i = 0;i < t->NumTokens;i++)\r
+               {\r
+                       t->Token[i] = LIST_DATA(o, i);\r
+               }\r
+\r
+               ReleaseList(o);\r
+\r
+               *param_list = t;\r
+       }\r
+\r
+       if (UniStrCmpi(ret, L"none") == 0 || UniStrCmpi(ret, L"null") == 0)\r
+       {\r
+               // none と null は予約語である\r
+               ret[0] = 0;\r
+       }\r
+\r
+       return ret;\r
+}\r
+char *ParseCommandA(wchar_t *str, char *name)\r
+{\r
+       wchar_t *tmp1, *tmp2;\r
+       char *ret;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (name != NULL)\r
+       {\r
+               tmp1 = CopyStrToUni(name);\r
+       }\r
+       else\r
+       {\r
+               tmp1 = NULL;\r
+       }\r
+\r
+       tmp2 = ParseCommand(str, tmp1);\r
+\r
+       if (tmp2 == NULL)\r
+       {\r
+               ret = NULL;\r
+       }\r
+       else\r
+       {\r
+               ret = CopyUniToStr(tmp2);\r
+               Free(tmp2);\r
+       }\r
+\r
+       Free(tmp1);\r
+\r
+       return ret;\r
+}\r
+\r
+// パスワードプロンプト\r
+bool PasswordPrompt(char *password, UINT size)\r
+{\r
+       UINT wp;\r
+       bool escape = false;\r
+       void *console;\r
+       // 引数チェック\r
+       if (password == NULL || size <= 1)\r
+       {\r
+               if (size >= 1)\r
+               {\r
+                       password[0] = 0;\r
+               }\r
+               return false;\r
+       }\r
+\r
+       wp = 0;\r
+\r
+       Zero(password, size);\r
+\r
+       console = SetConsoleRaw();\r
+\r
+       while (true)\r
+       {\r
+               int c;\r
+\r
+#ifdef OS_WIN32\r
+               c = getch();\r
+#else  // OS_WIN32\r
+               c = getc(stdin);\r
+#endif // OS_WIN32\r
+\r
+               if (c >= 0x20 && c <= 0x7E)\r
+               {\r
+                       // 文字\r
+                       if ((wp + 1) < size)\r
+                       {\r
+                               password[wp++] = (char)c;\r
+                               putc('*', stdout);\r
+                       }\r
+               }\r
+               else if (c == 0x03)\r
+               {\r
+                       // 強制終了\r
+                       exit(0);\r
+               }\r
+               else if (c == 0x04 || c == 0x1a || c == 0x0D || c==0x0A)\r
+               {\r
+                       // 終了\r
+                       if (c == 0x04 || c == 0x1a)\r
+                       {\r
+                               escape = true;\r
+                       }\r
+                       break;\r
+               }\r
+               else if (c == 0xE0)\r
+               {\r
+                       // もう 1 文字読む\r
+                       c = getch();\r
+                       if (c == 0x4B || c == 0x53)\r
+                       {\r
+                               // バックスペース\r
+                               goto BACKSPACE;\r
+                       }\r
+               }\r
+               else if (c == 0x08)\r
+               {\r
+BACKSPACE:\r
+                       // バックスペース\r
+                       if (wp >= 1)\r
+                       {\r
+                               password[--wp] = 0;\r
+                               putc(0x08, stdout);\r
+                               putc(' ', stdout);\r
+                               putc(0x08, stdout);\r
+                       }\r
+               }\r
+       }\r
+       Print("\n");\r
+\r
+       RestoreConsole(console);\r
+\r
+       return (escape ? false : true);\r
+}\r
+\r
+// プロンプトを表示\r
+wchar_t *Prompt(wchar_t *prompt_str)\r
+{\r
+       wchar_t *ret = NULL;\r
+       wchar_t *tmp = NULL;\r
+       // 引数チェック\r
+       if (prompt_str == NULL)\r
+       {\r
+               prompt_str = L"";\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       UniPrint(L"%s", prompt_str);\r
+       tmp = Malloc(MAX_PROMPT_STRSIZE);\r
+       if (fgetws(tmp, MAX_PROMPT_STRSIZE - 1, stdin) != NULL)\r
+       {\r
+               bool escape = false;\r
+               UINT i, len;\r
+\r
+               len = UniStrLen(tmp);\r
+               for (i = 0;i < len;i++)\r
+               {\r
+                       if (tmp[i] == 0x04 || tmp[i] == 0x1A)\r
+                       {\r
+                               escape = true;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               if (escape == false)\r
+               {\r
+                       UniTrimCrlf(tmp);\r
+\r
+                       ret = UniCopyStr(tmp);\r
+               }\r
+       }\r
+       Free(tmp);\r
+#else  // OS_WIN32\r
+       {\r
+               char *prompt = CopyUniToStr(prompt_str);\r
+               char *s = readline(prompt);\r
+               Free(prompt);\r
+\r
+               if (s != NULL)\r
+               {\r
+                       TrimCrlf(s);\r
+                       Trim(s);\r
+\r
+                       if (IsEmptyStr(s) == false)\r
+                       {\r
+                               add_history(s);\r
+                       }\r
+\r
+                       ret = CopyStrToUni(s);\r
+\r
+                       free(s);\r
+               }\r
+       }\r
+#endif // OS_WIN32\r
+\r
+       if (ret == NULL)\r
+       {\r
+               Print("\n");\r
+       }\r
+\r
+       return ret;\r
+}\r
+char *PromptA(wchar_t *prompt_str)\r
+{\r
+       wchar_t *str = Prompt(prompt_str);\r
+\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       else\r
+       {\r
+               char *ret = CopyUniToStr(str);\r
+\r
+               Free(str);\r
+               return ret;\r
+       }\r
+}\r
+\r
+// コンソールを Raw モードにする\r
+void *SetConsoleRaw()\r
+{\r
+#ifdef OS_UNIX\r
+       struct termios t, *ret;\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (tcgetattr(0, &t) != 0)\r
+       {\r
+               // 失敗\r
+               return NULL;\r
+       }\r
+\r
+       // 現在の設定をコピー\r
+       ret = Clone(&t, sizeof(t));\r
+\r
+       // 設定を変更\r
+       t.c_lflag &= (~ICANON);\r
+       t.c_lflag &= (~ECHO);\r
+       t.c_cc[VTIME] = 0;\r
+       t.c_cc[VMIN] = 1;\r
+       tcsetattr(0, TCSANOW, &t);\r
+\r
+       return ret;\r
+#else  // OS_UNIX\r
+       return Malloc(0);\r
+#endif // OS_UNIX\r
+}\r
+\r
+// コンソールのモードを復帰する\r
+void RestoreConsole(void *p)\r
+{\r
+#ifdef OS_UNIX\r
+       struct termios *t;\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = (struct termios *)p;\r
+\r
+       // 設定を復帰する\r
+       tcsetattr(0, TCSANOW, t);\r
+\r
+       Free(t);\r
+#else  // OS_UNIX\r
+       if (p != NULL)\r
+       {\r
+               Free(p);\r
+       }\r
+#endif // OS_UNIX\r
+}\r
+\r
+////////////////////////////\r
+// ローカルコンソール関数\r
+\r
+// 新しいローカルコンソールの作成\r
+CONSOLE *NewLocalConsole(wchar_t *infile, wchar_t *outfile)\r
+{\r
+       IO *in_io = NULL, *out_io = NULL;\r
+       CONSOLE *c = ZeroMalloc(sizeof(CONSOLE));\r
+       LOCAL_CONSOLE_PARAM *p;\r
+       UINT old_size = 0;\r
+\r
+#ifdef OS_WIN32\r
+       if (MsGetConsoleWidth() == 80)\r
+       {\r
+               //old_size = MsSetConsoleWidth(WIN32_DEFAULT_CONSOLE_WIDTH);\r
+       }\r
+#endif // OS_WIN32\r
+\r
+       c->ConsoleType = CONSOLE_LOCAL;\r
+       c->Free = ConsoleLocalFree;\r
+       c->ReadLine = ConsoleLocalReadLine;\r
+       c->ReadPassword = ConsoleLocalReadPassword;\r
+       c->Write = ConsoleLocalWrite;\r
+       c->GetWidth = ConsoleLocalGetWidth;\r
+\r
+       if (UniIsEmptyStr(infile) == false)\r
+       {\r
+               // 入力ファイルが指定されている\r
+               in_io = FileOpenW(infile, false);\r
+               if (in_io == NULL)\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CON_INFILE_ERROR"), infile);\r
+                       c->Write(c, tmp);\r
+                       Free(c);\r
+                       return NULL;\r
+               }\r
+               else\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CON_INFILE_START"), infile);\r
+                       c->Write(c, tmp);\r
+               }\r
+       }\r
+\r
+       if (UniIsEmptyStr(outfile) == false)\r
+       {\r
+               // 出力ファイルが指定されている\r
+               out_io = FileCreateW(outfile);\r
+               if (out_io == NULL)\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CON_OUTFILE_ERROR"), outfile);\r
+                       c->Write(c, tmp);\r
+                       Free(c);\r
+\r
+                       if (in_io != NULL)\r
+                       {\r
+                               FileClose(in_io);\r
+                       }\r
+                       return NULL;\r
+               }\r
+               else\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CON_OUTFILE_START"), outfile);\r
+                       c->Write(c, tmp);\r
+               }\r
+       }\r
+\r
+       p = ZeroMalloc(sizeof(LOCAL_CONSOLE_PARAM));\r
+       c->Param = p;\r
+\r
+       p->InFile = in_io;\r
+       p->OutFile = out_io;\r
+       p->Win32_OldConsoleWidth = old_size;\r
+\r
+       if (in_io != NULL)\r
+       {\r
+               UINT size;\r
+               void *buf;\r
+\r
+               size = FileSize(in_io);\r
+               buf = ZeroMalloc(size + 1);\r
+               FileRead(in_io, buf, size);\r
+\r
+               p->InBuf = NewBuf();\r
+               WriteBuf(p->InBuf, buf, size);\r
+               Free(buf);\r
+\r
+               p->InBuf->Current = 0;\r
+       }\r
+\r
+       return c;\r
+}\r
+\r
+// コンソール解放\r
+void ConsoleLocalFree(CONSOLE *c)\r
+{\r
+       LOCAL_CONSOLE_PARAM *p;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = (LOCAL_CONSOLE_PARAM *)c->Param;\r
+\r
+#ifdef OS_WIN32\r
+       if (p->Win32_OldConsoleWidth != 0)\r
+       {\r
+               MsSetConsoleWidth(p->Win32_OldConsoleWidth);\r
+       }\r
+#endif // OS_WIN32\r
+\r
+       if (p != NULL)\r
+       {\r
+               if (p->InFile != NULL)\r
+               {\r
+                       FileClose(p->InFile);\r
+                       FreeBuf(p->InBuf);\r
+               }\r
+\r
+               if (p->OutFile != NULL)\r
+               {\r
+                       FileClose(p->OutFile);\r
+               }\r
+\r
+               Free(p);\r
+       }\r
+\r
+       // メモリ解放\r
+       Free(c);\r
+}\r
+\r
+// 画面の横幅を取得\r
+UINT ConsoleLocalGetWidth(CONSOLE *c)\r
+{\r
+       UINT ret = 0;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       ret = MsGetConsoleWidth();\r
+#else  // OS_WIN32\r
+       {\r
+               struct winsize t;\r
+\r
+               Zero(&t, sizeof(t));\r
+\r
+               if (ioctl(1, TIOCGWINSZ, &t) == 0)\r
+               {\r
+                       ret = t.ws_col;\r
+               }\r
+       }\r
+#endif // OS_WIN32\r
+\r
+       return ret;\r
+}\r
+\r
+// コンソールから 1 行読み込む\r
+wchar_t *ConsoleLocalReadLine(CONSOLE *c, wchar_t *prompt, bool nofile)\r
+{\r
+       wchar_t *ret;\r
+       LOCAL_CONSOLE_PARAM *p;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       p = (LOCAL_CONSOLE_PARAM *)c->Param;\r
+       if (prompt == NULL)\r
+       {\r
+               prompt = L">";\r
+       }\r
+\r
+       ConsoleWriteOutFile(c, prompt, false);\r
+\r
+       if (nofile == false && p->InBuf != NULL)\r
+       {\r
+               // ファイルから次の行を読み込む\r
+               ret = ConsoleReadNextFromInFile(c);\r
+\r
+               if (ret != NULL)\r
+               {\r
+                       // 擬似プロンプトを表示する\r
+                       UniPrint(L"%s", prompt);\r
+\r
+                       // 画面に描画する\r
+                       UniPrint(L"%s\n", ret);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // 画面から次の行を読み込む\r
+               ret = Prompt(prompt);\r
+       }\r
+\r
+       if (ret != NULL)\r
+       {\r
+               ConsoleWriteOutFile(c, ret, true);\r
+       }\r
+       else\r
+       {\r
+               ConsoleWriteOutFile(c, _UU("CON_USER_CANCEL"), true);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// コンソールからパスワードを読み込む\r
+char *ConsoleLocalReadPassword(CONSOLE *c, wchar_t *prompt)\r
+{\r
+       char tmp[64];\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (prompt == NULL)\r
+       {\r
+               prompt = L"Password>";\r
+       }\r
+\r
+       UniPrint(L"%s", prompt);\r
+       ConsoleWriteOutFile(c, prompt, false);\r
+\r
+       if (PasswordPrompt(tmp, sizeof(tmp)))\r
+       {\r
+               ConsoleWriteOutFile(c, L"********", true);\r
+               return CopyStr(tmp);\r
+       }\r
+       else\r
+       {\r
+               ConsoleWriteOutFile(c, _UU("CON_USER_CANCEL"), true);\r
+               return NULL;\r
+       }\r
+}\r
+\r
+// コンソールに文字列を表示する\r
+bool ConsoleLocalWrite(CONSOLE *c, wchar_t *str)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniPrint(L"%s%s", str, (UniEndWith(str, L"\n") ? L"" : L"\n"));\r
+\r
+       ConsoleWriteOutFile(c, str, true);\r
+\r
+       return true;\r
+}\r
+\r
+// 入力ファイルから次の 1 行を読み込む\r
+wchar_t *ConsoleReadNextFromInFile(CONSOLE *c)\r
+{\r
+       LOCAL_CONSOLE_PARAM *p;\r
+       char *str;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = (LOCAL_CONSOLE_PARAM *)c->Param;\r
+\r
+       if (p->InBuf == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               str = CfgReadNextLine(p->InBuf);\r
+\r
+               if (str == NULL)\r
+               {\r
+                       return NULL;\r
+               }\r
+\r
+               Trim(str);\r
+\r
+               if (IsEmptyStr(str) == false)\r
+               {\r
+                       UINT size;\r
+                       wchar_t *ret;\r
+\r
+                       size = CalcUtf8ToUni((BYTE *)str, StrLen(str));\r
+                       ret = ZeroMalloc(size + 32);\r
+                       Utf8ToUni(ret, size, (BYTE *)str, StrLen(str));\r
+\r
+                       Free(str);\r
+\r
+                       return ret;\r
+               }\r
+\r
+               Free(str);\r
+       }\r
+}\r
+\r
+// 出力ファイルが指定されている場合は書き出す\r
+void ConsoleWriteOutFile(CONSOLE *c, wchar_t *str, bool add_last_crlf)\r
+{\r
+       LOCAL_CONSOLE_PARAM *p;\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = (LOCAL_CONSOLE_PARAM *)c->Param;\r
+\r
+       if (p != NULL && p->OutFile != NULL)\r
+       {\r
+               wchar_t *tmp = UniNormalizeCrlf(str);\r
+               UINT utf8_size;\r
+               UCHAR *utf8;\r
+\r
+               utf8_size = CalcUniToUtf8(tmp);\r
+               utf8 = ZeroMalloc(utf8_size + 1);\r
+               UniToUtf8(utf8, utf8_size + 1, tmp);\r
+\r
+               FileWrite(p->OutFile, utf8, utf8_size);\r
+\r
+               if (UniEndWith(str, L"\n") == false && add_last_crlf)\r
+               {\r
+                       char *crlf = "\r\n";\r
+                       FileWrite(p->OutFile, "\r\n", StrLen(crlf));\r
+               }\r
+\r
+               Free(utf8);\r
+               Free(tmp);\r
+       }\r
+\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Console.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Console.h
new file mode 100644 (file)
index 0000000..b4d546e
--- /dev/null
@@ -0,0 +1,213 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Console.h\r
+// Console.c のヘッダ\r
+\r
+#ifndef        CONSOLE_H\r
+#define        CONSOLE_H\r
+\r
+// 定数\r
+#define        MAX_PROMPT_STRSIZE                      65536\r
+#define        WIN32_DEFAULT_CONSOLE_WIDTH     100\r
+\r
+// コンソールの種類\r
+#define        CONSOLE_LOCAL                           0       // ローカルコンソール\r
+#define        CONSOLE_CSV                                     1       // CSV 出力モード\r
+\r
+// パラメータ補完プロンプト関数\r
+typedef wchar_t *(PROMPT_PROC)(CONSOLE *c, void *param);\r
+\r
+// パラメータ検証プロンプト関数\r
+typedef bool (EVAL_PROC)(CONSOLE *c, wchar_t *str, void *param);\r
+\r
+// パラメータ項目の定義\r
+struct PARAM\r
+{\r
+       char *Name;                                     // パラメータ名\r
+       PROMPT_PROC *PromptProc;        // パラメータが指定されていない場合に自動的に呼び出す\r
+                                                               // プロンプト関数 (NULL の場合は呼ばない)\r
+       void *PromptProcParam;          // プロンプト関数に渡す任意のポインタ\r
+       EVAL_PROC *EvalProc;            // パラメータ文字列検証関数\r
+       void *EvalProcParam;            // 検証関数に渡す任意のポインタ\r
+       char *Tmp;                                      // 一時変数\r
+};\r
+\r
+// パラメータ値内部データ\r
+struct PARAM_VALUE\r
+{\r
+       char *Name;                                     // 名前\r
+       char *StrValue;                         // 文字列値\r
+       wchar_t *UniStrValue;           // Unicode 文字列値\r
+       UINT IntValue;                          // 整数値\r
+};\r
+\r
+// コンソールサービス構造体\r
+struct CONSOLE\r
+{\r
+       UINT ConsoleType;                                                                               // コンソールの種類\r
+       UINT RetCode;                                                                                   // 最後の終了コード\r
+       void *Param;                                                                                    // 任意のデータ\r
+       void (*Free)(CONSOLE *c);                                                               // 解放関数\r
+       wchar_t *(*ReadLine)(CONSOLE *c, wchar_t *prompt, bool nofile);         // 1 行読み込む関数\r
+       char *(*ReadPassword)(CONSOLE *c, wchar_t *prompt);             // パスワードを読み込む関数\r
+       bool (*Write)(CONSOLE *c, wchar_t *str);                                // 文字列を書き出す関数\r
+       UINT (*GetWidth)(CONSOLE *c);                                                   // 画面の横幅の取得\r
+};\r
+\r
+// ローカルコンソールパラメータ\r
+struct LOCAL_CONSOLE_PARAM\r
+{\r
+       IO *InFile;             // 入力ファイル\r
+       BUF *InBuf;             // 入力バッファ\r
+       IO *OutFile;    // 出力ファイル\r
+       UINT Win32_OldConsoleWidth;     // 以前のコンソールサイズ\r
+};\r
+\r
+// コマンドプロシージャ\r
+typedef UINT (COMMAND_PROC)(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);\r
+\r
+// コマンドの定義\r
+struct CMD\r
+{\r
+       char *Name;                             // コマンド名\r
+       COMMAND_PROC *Proc;             // プロシージャ関数\r
+};\r
+\r
+// パラメータの最小 / 最大値評価\r
+struct CMD_EVAL_MIN_MAX\r
+{\r
+       char *StrName;\r
+       UINT MinValue, MaxValue;\r
+};\r
+\r
+\r
+// 関数プロトタイプ\r
+wchar_t *Prompt(wchar_t *prompt_str);\r
+char *PromptA(wchar_t *prompt_str);\r
+bool PasswordPrompt(char *password, UINT size);\r
+void *SetConsoleRaw();\r
+void RestoreConsole(void *p);\r
+wchar_t *ParseCommandEx(wchar_t *str, wchar_t *name, TOKEN_LIST **param_list);\r
+wchar_t *ParseCommand(wchar_t *str, wchar_t *name);\r
+TOKEN_LIST *GetCommandNameList(wchar_t *str);\r
+char *ParseCommandA(wchar_t *str, char *name);\r
+LIST *NewParamValueList();\r
+int CmpParamValue(void *p1, void *p2);\r
+void FreeParamValueList(LIST *o);\r
+PARAM_VALUE *FindParamValue(LIST *o, char *name);\r
+char *GetParamStr(LIST *o, char *name);\r
+wchar_t *GetParamUniStr(LIST *o, char *name);\r
+UINT GetParamInt(LIST *o, char *name);\r
+bool GetParamYes(LIST *o, char *name);\r
+LIST *ParseCommandList(CONSOLE *c, char *cmd_name, wchar_t *command, PARAM param[], UINT num_param);\r
+bool IsNameInRealName(char *input_name, char *real_name);\r
+void GetOmissionName(char *dst, UINT size, char *src);\r
+bool IsOmissionName(char *input_name, char *real_name);\r
+TOKEN_LIST *GetRealnameCandidate(char *input_name, TOKEN_LIST *real_name_list);\r
+bool SeparateCommandAndParam(wchar_t *src, char **cmd, wchar_t **param);\r
+UINT GetConsoleWidth(CONSOLE *c);\r
+bool DispatchNextCmd(CONSOLE *c, char *prompt, CMD cmd[], UINT num_cmd, void *param);\r
+bool DispatchNextCmdEx(CONSOLE *c, wchar_t *exec_command, char *prompt, CMD cmd[], UINT num_cmd, void *param);\r
+void PrintCandidateHelp(CONSOLE *c, char *cmd_name, TOKEN_LIST *candidate_list, UINT left_space);\r
+UNI_TOKEN_LIST *SeparateStringByWidth(wchar_t *str, UINT width);\r
+void GetCommandHelpStr(char *command_name, wchar_t **description, wchar_t **args, wchar_t **help);\r
+void GetCommandParamHelpStr(char *command_name, char *param_name, wchar_t **description);\r
+bool CmdEvalMinMax(CONSOLE *c, wchar_t *str, void *param);\r
+wchar_t *CmdPrompt(CONSOLE *c, void *param);\r
+bool CmdEvalNotEmpty(CONSOLE *c, wchar_t *str, void *param);\r
+bool CmdEvalInt1(CONSOLE *c, wchar_t *str, void *param);\r
+bool CmdEvalIsFile(CONSOLE *c, wchar_t *str, void *param);\r
+bool CmdEvalSafe(CONSOLE *c, wchar_t *str, void *param);\r
+void PrintCmdHelp(CONSOLE *c, char *cmd_name, TOKEN_LIST *param_list);\r
+int CompareCandidateStr(void *p1, void *p2);\r
+bool IsHelpStr(char *str);\r
+\r
+CONSOLE *NewLocalConsole(wchar_t *infile, wchar_t *outfile);\r
+void ConsoleLocalFree(CONSOLE *c);\r
+wchar_t *ConsoleLocalReadLine(CONSOLE *c, wchar_t *prompt, bool nofile);\r
+char *ConsoleLocalReadPassword(CONSOLE *c, wchar_t *prompt);\r
+bool ConsoleLocalWrite(CONSOLE *c, wchar_t *str);\r
+void ConsoleWriteOutFile(CONSOLE *c, wchar_t *str, bool add_last_crlf);\r
+wchar_t *ConsoleReadNextFromInFile(CONSOLE *c);\r
+UINT ConsoleLocalGetWidth(CONSOLE *c);\r
+\r
+\r
+#endif // CONSOLE_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Database.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Database.c
new file mode 100644 (file)
index 0000000..a776399
--- /dev/null
@@ -0,0 +1,217 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Database.c\r
+// ライセンスデータベース\r
+\r
+// 注意: このコードは製品版 PacketiX VPN と互換性を保つために存在しており、\r
+//       UT-VPN ではほとんど必要がないプログラムが含まれている。\r
+\r
+#include "CedarPch.h"\r
+\r
+// ライセンス状態文字列の取得\r
+wchar_t *LiGetLicenseStatusStr(UINT i)\r
+{\r
+       wchar_t *ret = _UU("LICENSE_STATUS_OTHERERROR");\r
+\r
+       switch (i)\r
+       {\r
+       case LICENSE_STATUS_OK:\r
+               ret = _UU("LICENSE_STATUS_OK");\r
+               break;\r
+\r
+       case LICENSE_STATUS_EXPIRED:\r
+               ret = _UU("LICENSE_STATUS_EXPIRED");\r
+               break;\r
+\r
+       case LICENSE_STATUS_ID_DIFF:\r
+               ret = _UU("LICENSE_STATUS_ID_DIFF");\r
+               break;\r
+\r
+       case LICENSE_STATUS_DUP:\r
+               ret = _UU("LICENSE_STATUS_DUP");\r
+               break;\r
+\r
+       case LICENSE_STATUS_INSUFFICIENT:\r
+               ret = _UU("LICENSE_STATUS_INSUFFICIENT");\r
+               break;\r
+\r
+       case LICENSE_STATUS_COMPETITION:\r
+               ret = _UU("LICENSE_STATUS_COMPETITION");\r
+               break;\r
+\r
+       case LICENSE_STATUS_NONSENSE:\r
+               ret = _UU("LICENSE_STATUS_NONSENSE");\r
+               break;\r
+\r
+       case LICENSE_STATUS_CPU:\r
+               ret = _UU("LICENSE_STATUS_CPU");\r
+               break;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 現在のライセンスのステータスを解析して保存する\r
+void LiParseCurrentLicenseStatus(LICENSE_SYSTEM *s, LICENSE_STATUS *status)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               if (status != NULL)\r
+               {\r
+                       Zero(status, sizeof(LICENSE_STATUS));\r
+               }\r
+               return;\r
+       }\r
+\r
+       if (true)\r
+       {\r
+               LICENSE_STATUS *st = ZeroMalloc(sizeof(LICENSE_STATUS));\r
+\r
+               st->MaxHubs = MAX_HUBS;\r
+\r
+               if (Is64())\r
+               {\r
+                       st->MaxHubs = MAX_HUBS_FOR_64BIT;\r
+               }\r
+\r
+               st->MaxSessions = SERVER_MAX_SESSIONS;\r
+\r
+               if (Is64())\r
+               {\r
+                       st->MaxSessions = SERVER_MAX_SESSIONS_FOR_64BIT;\r
+               }\r
+\r
+               // エディション名\r
+               StrCpy(st->EditionStr, sizeof(st->EditionStr),\r
+                       "SoftEther UT-VPN Server (GPL)");\r
+               st->Edition = LICENSE_EDITION_UTVPN_GPL;\r
+\r
+               st->AllowAcceptFromClient = true;\r
+               st->NeedSubscription = false;\r
+               st->NumUserLicense = INFINITE;\r
+               st->NumBridgeLicense = INFINITE;\r
+               st->NumClientLicense = INFINITE;\r
+               st->AllowEnterpriseFunction = true;\r
+               st->CarrierEdition = false;\r
+               st->Expires = 0;\r
+               st->IsSubscriptionExpired = false;\r
+               st->SystemId = 0;\r
+\r
+               if (status != NULL)\r
+               {\r
+                       Copy(status, st, sizeof(LICENSE_STATUS));\r
+               }\r
+\r
+               Copy(s->Status, st, sizeof(LICENSE_STATUS));\r
+\r
+               Free(st);\r
+       }\r
+       UnlockList(s->LicenseList);\r
+}\r
+\r
+// ライセンスシステムの解放\r
+void LiFreeLicenseSystem(LICENSE_SYSTEM *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ReleaseList(s->LicenseList);\r
+\r
+       if (s->Status != NULL)\r
+       {\r
+               Free(s->Status);\r
+       }\r
+\r
+       Free(s);\r
+}\r
+\r
+// ライセンスシステムをデバッグモードで作成\r
+LICENSE_SYSTEM *LiNewLicenseSystem()\r
+{\r
+       LICENSE_SYSTEM *s;\r
+\r
+       s = ZeroMalloc(sizeof(LICENSE_SYSTEM));\r
+\r
+       s->Status = ZeroMalloc(sizeof(LICENSE_STATUS));\r
+\r
+       return s;\r
+}\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Database.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Database.h
new file mode 100644 (file)
index 0000000..d545350
--- /dev/null
@@ -0,0 +1,145 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Database.h\r
+// Database.c のヘッダ\r
+\r
+#ifndef        DATABASE_H\r
+#define        DATABASE_H\r
+\r
+// ライセンスシステム\r
+struct LICENSE_SYSTEM\r
+{\r
+       LIST *LicenseList;                                                                      // ライセンスリスト\r
+       LICENSE_STATUS *Status;                                                         // ライセンス状況\r
+};\r
+\r
+// ライセンスデータ\r
+struct LICENSE_DATA\r
+{\r
+       UINT ProductId;                 // 製品 ID\r
+       UINT SerialId;                  // シリアル ID (16 bit)\r
+       UINT64 SystemId;                // システム ID (40 bit)\r
+       UINT ExpiresInt;                // 有効期限 (数値)\r
+       UINT64 Expires;                 // 有効期限\r
+};\r
+\r
+// 登録されているライセンス\r
+struct LICENSE\r
+{\r
+       UINT Id;                                                                                        // 番号\r
+       char Name[LICENSE_MAX_PRODUCT_NAME_LEN + 1];            // 製品名\r
+       char LicenseKeyStr[LICENSE_KEYSTR_LEN + 1];                     // ライセンスキー文字列\r
+       char LicenseIdStr[LICENSE_LICENSEID_STR_LEN + 1];       // ライセンス ID 文字列 \r
+       UINT ProductId;                                                                         // 製品 ID\r
+       UINT64 SystemId;                                                                        // システム ID\r
+       UINT SerialId;                                                                          // シリアル ID\r
+       UINT64 Expires;                                                                         // 有効期限\r
+       UINT Status;                                                                            // 状況\r
+};\r
+\r
+// ライセンス状況\r
+struct LICENSE_STATUS\r
+{\r
+       UINT Edition;                   // エディション\r
+       char EditionStr[LICENSE_MAX_PRODUCT_NAME_LEN + 1];      // エディション名\r
+       UINT64 SystemId;                // システム ID\r
+       UINT MaxSessions;               // システムでサポートされている最大同時接続可能セッション数\r
+       UINT MaxHubs;                   // システムでサポートされている最大同時接続可能仮想 HUB 数\r
+       UINT NumUserLicense;    // ユーザー作成ライセンス数\r
+       UINT NumClientLicense;  // クライアント接続ライセンス数\r
+       UINT NumBridgeLicense;  // ブリッジ接続ライセンス数\r
+       UINT64 Expires;                 // ライセンスの有効期限\r
+       UINT64 SubscriptionExpires;     // サブスクリプションの有効期限\r
+       bool NeedSubscription;  // サブスクリプションが必要かどうか\r
+       bool AllowAcceptFromClient;     // クライアントからの接続を受け付ける\r
+       bool AllowEnterpriseFunction;   // エンタープライズ向け機能が動作する\r
+       bool CarrierEdition;    // Carrier Edition である\r
+       bool IsSubscriptionExpired;     // サブスクリプションの期限が切れているかどうか\r
+};\r
+\r
+\r
+// 関数プロトタイプ\r
+LICENSE_SYSTEM *LiNewLicenseSystem();\r
+void LiFreeLicenseSystem(LICENSE_SYSTEM *s);\r
+void LiParseCurrentLicenseStatus(LICENSE_SYSTEM *s, LICENSE_STATUS *status);\r
+wchar_t *LiGetLicenseStatusStr(UINT i);\r
+\r
+\r
+#endif // DATABASE_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Hub.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Hub.c
new file mode 100644 (file)
index 0000000..0717a4c
--- /dev/null
@@ -0,0 +1,5840 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Hub.c\r
+// 仮想 HUB モジュール\r
+\r
+#include "CedarPch.h"\r
+\r
+static UCHAR broadcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};\r
+\r
+// 現在サポートされている管理オプションの一覧とデフォルト値\r
+// 名前は 63 文字以内にすること\r
+ADMIN_OPTION admin_options[] =\r
+{\r
+       {"allow_hub_admin_change_option", 0},\r
+       {"max_users", 0},\r
+       {"max_multilogins_per_user", 0},\r
+       {"max_groups", 0},\r
+       {"max_accesslists", 0},\r
+       {"max_sessions_client_bridge_apply", 0},\r
+       {"max_sessions", 0},\r
+       {"max_sessions_client", 0},\r
+       {"max_sessions_bridge", 0},\r
+       {"max_bitrates_download", 0},\r
+       {"max_bitrates_upload", 0},\r
+       {"deny_empty_password", 0},\r
+       {"deny_bridge", 0},\r
+       {"deny_routing", 0},\r
+       {"deny_qos", 0},\r
+       {"deny_change_user_password", 0},\r
+       {"no_change_users", 0},\r
+       {"no_change_groups", 0},\r
+       {"no_securenat", 0},\r
+       {"no_securenat_enablenat", 0},\r
+       {"no_securenat_enabledhcp", 0},\r
+       {"no_cascade", 0},\r
+       {"no_online", 0},\r
+       {"no_offline", 0},\r
+       {"no_change_log_config", 0},\r
+       {"no_disconnect_session", 0},\r
+       {"no_delete_iptable", 0},\r
+       {"no_delete_mactable", 0},\r
+       {"no_enum_session", 0},\r
+       {"no_query_session", 0},\r
+       {"no_change_admin_password", 0},\r
+       {"no_change_log_switch_type", 0},\r
+       {"no_change_access_list", 0},\r
+       {"no_change_access_control_list", 0},\r
+       {"no_change_cert_list", 0},\r
+       {"no_change_crl_list", 0},\r
+       {"no_read_log_file", 0},\r
+       {"deny_hub_admin_change_ext_option", 0},\r
+       {"no_delay_jitter_packet_loss", 0},\r
+       {"no_change_msg", 0},\r
+};\r
+\r
+UINT num_admin_options = sizeof(admin_options) / sizeof(ADMIN_OPTION);\r
+\r
+// 指定されたメッセージが URL 文字列かどうか取得\r
+bool IsURLMsg(wchar_t *str, char *url, UINT url_size)\r
+{\r
+       UNI_TOKEN_LIST *t;\r
+       bool ret = false;\r
+       UINT i;\r
+       UINT n = 0;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       t = UniParseToken(str, L"\r\n");\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               wchar_t *str = t->Token[i];\r
+\r
+               if (IsEmptyUniStr(str) == false)\r
+               {\r
+                       n++;\r
+\r
+                       UniTrim(str);\r
+\r
+                       if (n == 1)\r
+                       {\r
+                               if (UniStartWith(str, L"http://") ||\r
+                                       UniStartWith(str, L"https://") ||\r
+                                       UniStartWith(str, L"ftp://"))\r
+                               {\r
+                                       ret = true;\r
+\r
+                                       UniToStr(url, url_size, str);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (n != 1)\r
+       {\r
+               ret = false;\r
+       }\r
+\r
+       UniFreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// RPC_ADMIN_OPTION からデータを取得\r
+UINT GetHubAdminOptionData(RPC_ADMIN_OPTION *ao, char *name)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (ao == NULL || name == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       for (i = 0;i < ao->NumItem;i++)\r
+       {\r
+               ADMIN_OPTION *a = &ao->Items[i];\r
+\r
+               if (StrCmpi(a->Name, name) == 0)\r
+               {\r
+                       return a->Value;\r
+               }\r
+       }\r
+\r
+       return INFINITE;\r
+}\r
+void GetHubAdminOptionDataAndSet(RPC_ADMIN_OPTION *ao, char *name, UINT *dest)\r
+{\r
+       UINT value;\r
+       // 引数チェック\r
+       if (ao == NULL || name == NULL || dest == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       value = GetHubAdminOptionData(ao, name);\r
+       if (value == INFINITE)\r
+       {\r
+               return;\r
+       }\r
+\r
+       *dest = value;\r
+}\r
+\r
+// データをもとに HUB_OPTION の内容を設定\r
+void DataToHubOptionStruct(HUB_OPTION *o, RPC_ADMIN_OPTION *ao)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || ao == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetHubAdminOptionDataAndSet(ao, "NoAddressPollingIPv4", &o->NoArpPolling);\r
+       GetHubAdminOptionDataAndSet(ao, "NoAddressPollingIPv6", &o->NoIPv6AddrPolling);\r
+       GetHubAdminOptionDataAndSet(ao, "NoIpTable", &o->NoIpTable);\r
+       GetHubAdminOptionDataAndSet(ao, "NoMacAddressLog", &o->NoMacAddressLog);\r
+       GetHubAdminOptionDataAndSet(ao, "ManageOnlyPrivateIP", &o->ManageOnlyPrivateIP);\r
+       GetHubAdminOptionDataAndSet(ao, "ManageOnlyLocalUnicastIPv6", &o->ManageOnlyLocalUnicastIPv6);\r
+       GetHubAdminOptionDataAndSet(ao, "DisableIPParsing", &o->DisableIPParsing);\r
+       GetHubAdminOptionDataAndSet(ao, "YieldAfterStorePacket", &o->YieldAfterStorePacket);\r
+       GetHubAdminOptionDataAndSet(ao, "NoSpinLockForPacketDelay", &o->NoSpinLockForPacketDelay);\r
+       GetHubAdminOptionDataAndSet(ao, "BroadcastStormDetectionThreshold", &o->BroadcastStormDetectionThreshold);\r
+       GetHubAdminOptionDataAndSet(ao, "ClientMinimumRequiredBuild", &o->ClientMinimumRequiredBuild);\r
+       GetHubAdminOptionDataAndSet(ao, "FilterPPPoE", &o->FilterPPPoE);\r
+       GetHubAdminOptionDataAndSet(ao, "FilterOSPF", &o->FilterOSPF);\r
+       GetHubAdminOptionDataAndSet(ao, "FilterIPv4", &o->FilterIPv4);\r
+       GetHubAdminOptionDataAndSet(ao, "FilterIPv6", &o->FilterIPv6);\r
+       GetHubAdminOptionDataAndSet(ao, "FilterNonIP", &o->FilterNonIP);\r
+       GetHubAdminOptionDataAndSet(ao, "NoIPv4PacketLog", &o->NoIPv4PacketLog);\r
+       GetHubAdminOptionDataAndSet(ao, "NoIPv6PacketLog", &o->NoIPv6PacketLog);\r
+       GetHubAdminOptionDataAndSet(ao, "FilterBPDU", &o->FilterBPDU);\r
+       GetHubAdminOptionDataAndSet(ao, "NoIPv6DefaultRouterInRAWhenIPv6", &o->NoIPv6DefaultRouterInRAWhenIPv6);\r
+       GetHubAdminOptionDataAndSet(ao, "NoLookBPDUBridgeId", &o->NoLookBPDUBridgeId);\r
+       GetHubAdminOptionDataAndSet(ao, "NoManageVlanId", &o->NoManageVlanId);\r
+       GetHubAdminOptionDataAndSet(ao, "VlanTypeId", &o->VlanTypeId);\r
+       GetHubAdminOptionDataAndSet(ao, "FixForDLinkBPDU", &o->FixForDLinkBPDU);\r
+       GetHubAdminOptionDataAndSet(ao, "RequiredClientId", &o->RequiredClientId);\r
+}\r
+\r
+// HUB_OPTION の内容をデータに変換\r
+void HubOptionStructToData(RPC_ADMIN_OPTION *ao, HUB_OPTION *o, char *hub_name)\r
+{\r
+       LIST *aol;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (ao == NULL || o == NULL || hub_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       aol = NewListFast(NULL);\r
+\r
+       Add(aol, NewAdminOption("NoAddressPollingIPv4", o->NoArpPolling));\r
+       Add(aol, NewAdminOption("NoAddressPollingIPv6", o->NoIPv6AddrPolling));\r
+       Add(aol, NewAdminOption("NoIpTable", o->NoIpTable));\r
+       Add(aol, NewAdminOption("NoMacAddressLog", o->NoMacAddressLog));\r
+       Add(aol, NewAdminOption("ManageOnlyPrivateIP", o->ManageOnlyPrivateIP));\r
+       Add(aol, NewAdminOption("ManageOnlyLocalUnicastIPv6", o->ManageOnlyLocalUnicastIPv6));\r
+       Add(aol, NewAdminOption("DisableIPParsing", o->DisableIPParsing));\r
+       Add(aol, NewAdminOption("YieldAfterStorePacket", o->YieldAfterStorePacket));\r
+       Add(aol, NewAdminOption("NoSpinLockForPacketDelay", o->NoSpinLockForPacketDelay));\r
+       Add(aol, NewAdminOption("BroadcastStormDetectionThreshold", o->BroadcastStormDetectionThreshold));\r
+       Add(aol, NewAdminOption("ClientMinimumRequiredBuild", o->ClientMinimumRequiredBuild));\r
+       Add(aol, NewAdminOption("FilterPPPoE", o->FilterPPPoE));\r
+       Add(aol, NewAdminOption("FilterOSPF", o->FilterOSPF));\r
+       Add(aol, NewAdminOption("FilterIPv4", o->FilterIPv4));\r
+       Add(aol, NewAdminOption("FilterIPv6", o->FilterIPv6));\r
+       Add(aol, NewAdminOption("FilterNonIP", o->FilterNonIP));\r
+       Add(aol, NewAdminOption("NoIPv4PacketLog", o->NoIPv4PacketLog));\r
+       Add(aol, NewAdminOption("NoIPv6PacketLog", o->NoIPv6PacketLog));\r
+       Add(aol, NewAdminOption("FilterBPDU", o->FilterBPDU));\r
+       Add(aol, NewAdminOption("NoIPv6DefaultRouterInRAWhenIPv6", o->NoIPv6DefaultRouterInRAWhenIPv6));\r
+       Add(aol, NewAdminOption("NoLookBPDUBridgeId", o->NoLookBPDUBridgeId));\r
+       Add(aol, NewAdminOption("NoManageVlanId", o->NoManageVlanId));\r
+       Add(aol, NewAdminOption("VlanTypeId", o->VlanTypeId));\r
+       Add(aol, NewAdminOption("FixForDLinkBPDU", o->FixForDLinkBPDU));\r
+       Add(aol, NewAdminOption("RequiredClientId", o->RequiredClientId));\r
+\r
+       Zero(ao, sizeof(RPC_ADMIN_OPTION));\r
+\r
+       StrCpy(ao->HubName, sizeof(ao->HubName), hub_name);\r
+\r
+       ao->NumItem = LIST_NUM(aol);\r
+       ao->Items = ZeroMalloc(sizeof(ADMIN_OPTION) * ao->NumItem);\r
+\r
+       for (i = 0;i < LIST_NUM(aol);i++)\r
+       {\r
+               ADMIN_OPTION *a = LIST_DATA(aol, i);\r
+\r
+               Copy(&ao->Items[i], a, sizeof(ADMIN_OPTION));\r
+\r
+               Free(a);\r
+       }\r
+\r
+       ReleaseList(aol);\r
+}\r
+\r
+// 新しい ADMIN OPTION の作成\r
+ADMIN_OPTION *NewAdminOption(char *name, UINT value)\r
+{\r
+       ADMIN_OPTION *a;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       a = ZeroMalloc(sizeof(ADMIN_OPTION));\r
+       StrCpy(a->Name, sizeof(a->Name), name);\r
+       a->Value = value;\r
+\r
+       return a;\r
+}\r
+\r
+// AC リストのクローン\r
+LIST *CloneAcList(LIST *o)\r
+{\r
+       LIST *ret;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = NewAcList();\r
+       SetAcList(ret, o);\r
+\r
+       return ret;\r
+}\r
+\r
+// AC リストをすべてセットする\r
+void SetAcList(LIST *o, LIST *src)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DelAllAc(o);\r
+\r
+       for (i = 0;i < LIST_NUM(src);i++)\r
+       {\r
+               AC *ac = LIST_DATA(src, i);\r
+\r
+               AddAc(o, ac);\r
+       }\r
+}\r
+\r
+// AC リストからすべての AC を削除する\r
+void DelAllAc(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               AC *ac = LIST_DATA(o, i);\r
+\r
+               Free(ac);\r
+       }\r
+\r
+       DeleteAll(o);\r
+}\r
+\r
+// AC リストを解放する\r
+void FreeAcList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               AC *ac = LIST_DATA(o, i);\r
+\r
+               Free(ac);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// AC の内容を示す文字列を生成する\r
+char *GenerateAcStr(AC *ac)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       char ip[64], mask[64];\r
+\r
+       if (ac == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       IPToStr(ip, sizeof(ip), &ac->IpAddress);\r
+       MaskToStr(mask, sizeof(mask), &ac->SubnetMask);\r
+\r
+       if (ac->Masked == false)\r
+       {\r
+               Format(tmp, sizeof(tmp), "%s", ip);\r
+       }\r
+       else\r
+       {\r
+               Format(tmp, sizeof(tmp), "%s/%s", ip, mask);\r
+       }\r
+\r
+       return CopyStr(tmp);\r
+}\r
+\r
+// AC の設定\r
+void SetAc(LIST *o, UINT id, AC *ac)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || id == 0 || ac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (DelAc(o, id))\r
+       {\r
+               AddAc(o, ac);\r
+       }\r
+}\r
+\r
+// AC の取得\r
+AC *GetAc(LIST *o, UINT id)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL || id == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               AC *ac = LIST_DATA(o, i);\r
+\r
+               if (ac->Id == id)\r
+               {\r
+                       return Clone(ac, sizeof(AC));\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// AC の削除\r
+bool DelAc(LIST *o, UINT id)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL || id == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               AC *ac = LIST_DATA(o, i);\r
+\r
+               if (ac->Id == id)\r
+               {\r
+                       if (Delete(o, ac))\r
+                       {\r
+                               Free(ac);\r
+\r
+                               NormalizeAcList(o);\r
+\r
+                               return true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// AC の追加\r
+void AddAc(LIST *o, AC *ac)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || ac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LIST_NUM(o) < MAX_HUB_ACS)\r
+       {\r
+               Insert(o, Clone(ac, sizeof(AC)));\r
+\r
+               NormalizeAcList(o);\r
+       }\r
+}\r
+\r
+// AC リストを正規化する\r
+void NormalizeAcList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               AC *ac = LIST_DATA(o, i);\r
+\r
+               if (IsIP6(&ac->IpAddress))\r
+               {\r
+                       ac->IpAddress.ipv6_scope_id = 0;\r
+               }\r
+\r
+               ac->Id = (i + 1);\r
+       }\r
+}\r
+\r
+// 新しい AC リストの作成\r
+LIST *NewAcList()\r
+{\r
+       return NewList(CmpAc);\r
+}\r
+\r
+// AC 比較\r
+int CmpAc(void *p1, void *p2)\r
+{\r
+       AC *a1, *a2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       a1 = *(AC **)p1;\r
+       a2 = *(AC **)p2;\r
+       if (a1 == NULL || a2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (a1->Priority > a2->Priority)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (a1->Priority < a2->Priority)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (a1->Deny > a2->Deny)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (a1->Deny < a2->Deny)\r
+       {\r
+               return -1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+// CRL のコピー\r
+CRL *CopyCrl(CRL *crl)\r
+{\r
+       CRL *ret;\r
+       // 引数チェック\r
+       if (crl == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(CRL));\r
+\r
+       if (crl->Serial != NULL)\r
+       {\r
+               ret->Serial = NewXSerial(crl->Serial->data, crl->Serial->size);\r
+       }\r
+\r
+       ret->Name = CopyName(crl->Name);\r
+\r
+       Copy(ret->DigestMD5, crl->DigestMD5, MD5_SIZE);\r
+       Copy(ret->DigestSHA1, crl->DigestSHA1, SHA1_SIZE);\r
+\r
+       return ret;\r
+}\r
+\r
+// CRL の解放\r
+void FreeCrl(CRL *crl)\r
+{\r
+       // 引数チェック\r
+       if (crl == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (crl->Serial != NULL)\r
+       {\r
+               FreeXSerial(crl->Serial);\r
+       }\r
+\r
+       if (crl->Name != NULL)\r
+       {\r
+               FreeName(crl->Name);\r
+       }\r
+\r
+       Free(crl);\r
+}\r
+\r
+// 仮想 HUB の CRL リストを検索して証明書が無効化されていないかどうか調べる\r
+bool IsValidCertInHub(HUB *h, X *x)\r
+{\r
+       bool ret;\r
+       // 引数チェック\r
+       if (h == NULL || x == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (h->HubDb == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsXRevoked(x))\r
+       {\r
+               // ファイルに保存されている CRL によって無効化されている\r
+               return false;\r
+       }\r
+\r
+       LockList(h->HubDb->CrlList);\r
+       {\r
+               ret = IsCertMatchCrlList(x, h->HubDb->CrlList);\r
+       }\r
+       UnlockList(h->HubDb->CrlList);\r
+\r
+       if (ret)\r
+       {\r
+               // 一致するので無効である\r
+               return false;\r
+       }\r
+\r
+       // 一致しなかったので有効である\r
+       return true;\r
+}\r
+\r
+// CRL リストに証明書が一致するかどうか検索\r
+bool IsCertMatchCrlList(X *x, LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (x == NULL || o == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               CRL *crl = LIST_DATA(o, i);\r
+\r
+               if (IsCertMatchCrl(x, crl))\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// CRL を示す文字列に変換する\r
+wchar_t *GenerateCrlStr(CRL *crl)\r
+{\r
+       wchar_t tmp[2048];\r
+       // 引数チェック\r
+       if (crl == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       UniStrCpy(tmp, sizeof(tmp), L"");\r
+\r
+       if (crl->Name != NULL)\r
+       {\r
+               // 名前情報\r
+               wchar_t name[MAX_SIZE];\r
+\r
+               UniStrCat(tmp, sizeof(tmp), L"Subject=\"");\r
+\r
+               GetAllNameFromName(name, sizeof(name), crl->Name);\r
+               UniStrCat(tmp, sizeof(tmp), name);\r
+               UniStrCat(tmp, sizeof(tmp), L"\", ");\r
+       }\r
+\r
+       if (crl->Serial != NULL)\r
+       {\r
+               // シリアル情報\r
+               char str[128];\r
+               wchar_t uni[128];\r
+\r
+               BinToStrEx(str, sizeof(str), crl->Serial->data, crl->Serial->size);\r
+               StrToUni(uni, sizeof(uni), str);\r
+               UniStrCat(tmp, sizeof(tmp), L"Serial=\"");\r
+               UniStrCat(tmp, sizeof(tmp), uni);\r
+               UniStrCat(tmp, sizeof(tmp), L"\", ");\r
+       }\r
+\r
+       if (IsZero(crl->DigestMD5, MD5_SIZE) == false)\r
+       {\r
+               // MD5\r
+               char str[128];\r
+               wchar_t uni[128];\r
+\r
+               BinToStrEx(str, sizeof(str), crl->DigestMD5, MD5_SIZE);\r
+               StrToUni(uni, sizeof(uni), str);\r
+               UniStrCat(tmp, sizeof(tmp), L"MD5=\"");\r
+               UniStrCat(tmp, sizeof(tmp), uni);\r
+               UniStrCat(tmp, sizeof(tmp), L"\", ");\r
+       }\r
+\r
+       if (IsZero(crl->DigestSHA1, SHA1_SIZE) == false)\r
+       {\r
+               // MD5\r
+               char str[128];\r
+               wchar_t uni[128];\r
+\r
+               BinToStrEx(str, sizeof(str), crl->DigestSHA1, SHA1_SIZE);\r
+               StrToUni(uni, sizeof(uni), str);\r
+               UniStrCat(tmp, sizeof(tmp), L"SHA1=\"");\r
+               UniStrCat(tmp, sizeof(tmp), uni);\r
+               UniStrCat(tmp, sizeof(tmp), L"\", ");\r
+       }\r
+\r
+       if (UniEndWith(tmp, L", "))\r
+       {\r
+               tmp[UniStrLen(tmp) - 2] = 0;\r
+       }\r
+\r
+       return CopyUniStr(tmp);\r
+}\r
+\r
+// 証明書無効リストエントリに一致するかどうか検査する\r
+bool IsCertMatchCrl(X *x, CRL *crl)\r
+{\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       bool b = true;\r
+       // 引数チェック\r
+       if (x == NULL || crl == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (crl->Serial != NULL)\r
+       {\r
+               // CRL にシリアル番号が定義されている場合\r
+               if (x->serial == NULL || CompareXSerial(x->serial, crl->Serial) == false)\r
+               {\r
+                       // シリアル番号不一致\r
+                       b = false;\r
+               }\r
+       }\r
+\r
+       if (IsZero(crl->DigestMD5, sizeof(crl->DigestMD5)) == false)\r
+       {\r
+               UCHAR test[MD5_SIZE];\r
+               // CRL に DigestMD5 が定義されている場合\r
+               GetXDigest(x, test, false);\r
+\r
+               if (Cmp(test, crl->DigestMD5, MD5_SIZE) != 0)\r
+               {\r
+                       b = false;\r
+               }\r
+       }\r
+\r
+       if (IsZero(crl->DigestSHA1, sizeof(crl->DigestSHA1)) == false)\r
+       {\r
+               UCHAR test[SHA1_SIZE];\r
+               // CRL に DigestSHA1 が定義されている場合\r
+               GetXDigest(x, test, true);\r
+\r
+               if (Cmp(test, crl->DigestSHA1, SHA1_SIZE) != 0)\r
+               {\r
+                       b = false;\r
+               }\r
+       }\r
+\r
+       if (crl->Name != NULL)\r
+       {\r
+               // CRL に名前が定義されている場合\r
+               NAME *xn, *cn;\r
+               xn = x->subject_name;\r
+               cn = crl->Name;\r
+\r
+               if (cn->CommonName != NULL && (UniIsEmptyStr(cn->CommonName) == false))\r
+               {\r
+                       if (xn->CommonName == NULL || UniSoftStrCmp(xn->CommonName, cn->CommonName) != 0)\r
+                       {\r
+                               // CommonName 不一致\r
+                               b = false;\r
+                       }\r
+               }\r
+\r
+               if (cn->Organization != NULL && (UniIsEmptyStr(cn->Organization) == false))\r
+               {\r
+                       if (xn->Organization == NULL || UniSoftStrCmp(xn->Organization, cn->Organization) != 0)\r
+                       {\r
+                               // Organization 不一致\r
+                               b = false;\r
+                       }\r
+               }\r
+\r
+               if (cn->Unit != NULL && (UniIsEmptyStr(cn->Unit) == false))\r
+               {\r
+                       if (xn->Unit == NULL || UniSoftStrCmp(xn->Unit, cn->Unit) != 0)\r
+                       {\r
+                               // Unit不一致\r
+                               b = false;\r
+                       }\r
+               }\r
+\r
+               if (cn->Country != NULL && (UniIsEmptyStr(cn->Country) == false))\r
+               {\r
+                       if (xn->Country == NULL || UniSoftStrCmp(xn->Country, cn->Country) != 0)\r
+                       {\r
+                               // Country 不一致\r
+                               b = false;\r
+                       }\r
+               }\r
+\r
+               if (cn->State != NULL && (UniIsEmptyStr(cn->State) == false))\r
+               {\r
+                       if (xn->State == NULL || UniSoftStrCmp(xn->State, cn->State) != 0)\r
+                       {\r
+                               // State 不一致\r
+                               b = false;\r
+                       }\r
+               }\r
+\r
+               if (cn->Local != NULL && (UniIsEmptyStr(cn->Local) == false))\r
+               {\r
+                       if (xn->Local == NULL || UniSoftStrCmp(xn->Local, cn->Local) != 0)\r
+                       {\r
+                               // Local 不一致\r
+                               b = false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return b;\r
+}\r
+\r
+// 管理オプションのヘルプ文字列を取得する\r
+wchar_t *GetHubAdminOptionHelpString(char *name)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       wchar_t *ret;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return L"";\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), "HUB_AO_%s", name);\r
+\r
+       ret = _UU(tmp);\r
+       if (UniIsEmptyStr(ret))\r
+       {\r
+               ret = _UU("HUB_AO_UNKNOWN");\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 HUB にデフォルトの管理オプションを追加する\r
+void AddHubAdminOptionsDefaults(HUB *h, bool lock)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (lock)\r
+       {\r
+               LockList(h->AdminOptionList);\r
+       }\r
+\r
+       for (i = 0;i < num_admin_options;i++)\r
+       {\r
+               ADMIN_OPTION *e = &admin_options[i];\r
+               ADMIN_OPTION t, *r;\r
+\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.Name, sizeof(t.Name), e->Name);\r
+\r
+               r = Search(h->AdminOptionList, &t);\r
+               if (r == NULL)\r
+               {\r
+                       ADMIN_OPTION *a = ZeroMalloc(sizeof(ADMIN_OPTION));\r
+\r
+                       StrCpy(a->Name, sizeof(a->Name), e->Name);\r
+                       a->Value = e->Value;\r
+\r
+                       Insert(h->AdminOptionList, a);\r
+               }\r
+       }\r
+\r
+       if (lock)\r
+       {\r
+               UnlockList(h->AdminOptionList);\r
+       }\r
+}\r
+\r
+// 仮想 HUB のすべての管理オプションの削除\r
+void DeleteAllHubAdminOption(HUB *h, bool lock)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (lock)\r
+       {\r
+               LockList(h->AdminOptionList);\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(h->AdminOptionList);i++)\r
+       {\r
+               Free(LIST_DATA(h->AdminOptionList, i));\r
+       }\r
+\r
+       DeleteAll(h->AdminOptionList);\r
+\r
+       if (lock)\r
+       {\r
+               UnlockList(h->AdminOptionList);\r
+       }\r
+}\r
+\r
+// 仮想 HUB の管理オプションの取得\r
+UINT GetHubAdminOptionEx(HUB *h, char *name, UINT default_value)\r
+{\r
+       UINT ret = default_value;\r
+       // 引数チェック\r
+       if (h == NULL || name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       LockList(h->AdminOptionList);\r
+       {\r
+               ADMIN_OPTION *a, t;\r
+\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.Name, sizeof(t.Name), name);\r
+               Trim(t.Name);\r
+\r
+               a = Search(h->AdminOptionList, &t);\r
+\r
+               if (a != NULL)\r
+               {\r
+                       ret = a->Value;\r
+               }\r
+       }\r
+       UnlockList(h->AdminOptionList);\r
+\r
+       return ret;\r
+}\r
+UINT GetHubAdminOption(HUB *h, char *name)\r
+{\r
+       return GetHubAdminOptionEx(h, name, 0);\r
+}\r
+\r
+// 管理オプション\r
+int CompareAdminOption(void *p1, void *p2)\r
+{\r
+       ADMIN_OPTION *a1, *a2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       a1 = *(ADMIN_OPTION **)p1;\r
+       a2 = *(ADMIN_OPTION **)p2;\r
+       if (a1 == NULL || a2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return StrCmpi(a1->Name, a2->Name);\r
+}\r
+\r
+// 番犬開始\r
+void StartHubWatchDog(HUB *h)\r
+{\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       h->HaltWatchDog = false;\r
+       h->WatchDogEvent = NewEvent();\r
+\r
+       t = NewThread(HubWatchDogThread, h);\r
+       WaitThreadInit(t);\r
+       ReleaseThread(t);\r
+}\r
+\r
+// 番犬停止\r
+void StopHubWatchDog(HUB *h)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       h->HaltWatchDog = true;\r
+       Set(h->WatchDogEvent);\r
+\r
+       WaitThread(h->WatchDogThread, INFINITE);\r
+       ReleaseThread(h->WatchDogThread);\r
+       h->WatchDogThread = NULL;\r
+       h->HaltWatchDog = false;\r
+\r
+       ReleaseEvent(h->WatchDogEvent);\r
+       h->WatchDogEvent = NULL;\r
+}\r
+\r
+// 番犬スレッド\r
+void HubWatchDogThread(THREAD *t, void *param)\r
+{\r
+       UINT num_packets_v4 = 0;\r
+       UINT num_packets_v6 = 0;\r
+       HUB *hub;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       hub = (HUB *)param;\r
+\r
+       hub->WatchDogThread = t;\r
+       AddRef(t->ref);\r
+\r
+       NoticeThreadInit(t);\r
+\r
+       while (true)\r
+       {\r
+               LIST *o;\r
+               LIST *o2;\r
+               UINT i, num;\r
+               UINT interval;\r
+               UINT wait_time = 100;\r
+               if (hub->HaltWatchDog)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               o = NewListFast(NULL);\r
+               o2 = NewListFast(NULL);\r
+\r
+               // ARP パケットの送信\r
+               LockList(hub->IpTable);\r
+               {\r
+                       num = LIST_NUM(hub->IpTable);\r
+                       for (i = 0;i < LIST_NUM(hub->IpTable);i++)\r
+                       {\r
+                               IP_TABLE_ENTRY *e = LIST_DATA(hub->IpTable, i);\r
+\r
+                               if ((e->UpdatedTime + (UINT64)(IP_TABLE_EXPIRE_TIME)) > Tick64())\r
+                               {\r
+                                       if (e->MacAddress[0] != 0xff || e->MacAddress[1] != 0xff || e->MacAddress[2] != 0xff ||\r
+                                               e->MacAddress[3] != 0xff || e->MacAddress[4] != 0xff || e->MacAddress[5] != 0xff)\r
+                                       {\r
+                                               if (hub->Option != NULL && hub->Option->NoArpPolling == false)\r
+                                               {\r
+                                                       if (IsIP4(&e->Ip))\r
+                                                       {\r
+                                                               // IPv4\r
+                                                               MAC_HEADER *mac = ZeroMalloc(sizeof(MAC_HEADER) + sizeof(ARPV4_HEADER));\r
+                                                               ARPV4_HEADER *p = (ARPV4_HEADER *)(((UCHAR *)mac) + sizeof(MAC_HEADER));\r
+\r
+                                                               Copy(mac->DestAddress, e->MacAddress, 6);\r
+                                                               Copy(mac->SrcAddress, hub->HubMacAddr, 6);\r
+                                                               mac->Protocol = Endian16(MAC_PROTO_ARPV4);\r
+\r
+                                                               p->HardwareType = Endian16(ARP_HARDWARE_TYPE_ETHERNET);\r
+                                                               p->ProtocolType = Endian16(MAC_PROTO_IPV4);\r
+                                                               p->HardwareSize = 6;\r
+                                                               p->ProtocolSize = 4;\r
+                                                               p->Operation = Endian16(ARP_OPERATION_REQUEST);\r
+                                                               Copy(p->SrcAddress, hub->HubMacAddr, 6);\r
+                                                               p->SrcIP = IPToUINT(&hub->HubIp);\r
+                                                               p->TargetAddress[0] =\r
+                                                                       p->TargetAddress[1] =\r
+                                                                       p->TargetAddress[2] =\r
+                                                                       p->TargetAddress[3] =\r
+                                                                       p->TargetAddress[4] =\r
+                                                                       p->TargetAddress[5] = 0x00;\r
+                                                               p->TargetIP = IPToUINT(&e->Ip);\r
+                                                               Insert(o, mac);\r
+                                                       }\r
+                                               }\r
+\r
+                                               if (hub->Option != NULL && hub->Option->NoIPv6AddrPolling == false)\r
+                                               {\r
+                                                       if (IsIP6(&e->Ip))\r
+                                                       {\r
+                                                               // IPv6\r
+                                                               BUF *buf;\r
+                                                               IPV6_ADDR ip6addr;\r
+\r
+                                                               if (IPToIPv6Addr(&ip6addr, &e->Ip))\r
+                                                               {\r
+                                                                       buf = BuildICMPv6NeighborSoliciation(&hub->HubIpV6,\r
+                                                                               &ip6addr,\r
+                                                                               hub->HubMacAddr, ++hub->HubIP6Id);\r
+\r
+                                                                       if (buf != NULL)\r
+                                                                       {\r
+                                                                               BUF *buf2 = NewBuf();\r
+                                                                               MAC_HEADER mac;\r
+\r
+                                                                               Zero(&mac, sizeof(mac));\r
+\r
+                                                                               Copy(mac.DestAddress, e->MacAddress, 6);\r
+                                                                               Copy(mac.SrcAddress, hub->HubMacAddr, 6);\r
+                                                                               mac.Protocol = Endian16(MAC_PROTO_IPV6);\r
+\r
+                                                                               WriteBuf(buf2, &mac, sizeof(MAC_HEADER));\r
+\r
+                                                                               WriteBuf(buf2, buf->Buf, buf->Size);\r
+\r
+                                                                               FreeBuf(buf);\r
+\r
+                                                                               Insert(o2, buf2);\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(hub->IpTable);\r
+\r
+               if ((LIST_NUM(o) + LIST_NUM(o2)) != 0)\r
+               {\r
+                       interval = HUB_ARP_SEND_INTERVAL / (LIST_NUM(o) + LIST_NUM(o2));\r
+               }\r
+               else\r
+               {\r
+                       interval = HUB_ARP_SEND_INTERVAL;\r
+               }\r
+\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       PKT *packet;\r
+                       void *p = LIST_DATA(o, i);\r
+\r
+                       Wait(hub->WatchDogEvent, interval);\r
+                       if (hub->HaltWatchDog)\r
+                       {\r
+                               for (;i < LIST_NUM(o);i++)\r
+                               {\r
+                                       Free(LIST_DATA(o, i));\r
+                               }\r
+                               ReleaseList(o);\r
+\r
+                               for (i = 0;i < LIST_NUM(o2);i++)\r
+                               {\r
+                                       FreeBuf(LIST_DATA(o2, i));\r
+                               }\r
+                               ReleaseList(o2);\r
+                               goto ESCAPE;\r
+                       }\r
+\r
+                       packet = ParsePacket((UCHAR *)p, sizeof(MAC_HEADER) + sizeof(ARPV4_HEADER));\r
+                       if (packet != NULL)\r
+                       {\r
+                               StorePacket(hub, NULL, packet);\r
+                               num_packets_v4++;\r
+                       }\r
+                       else\r
+                       {\r
+                               Free(p);\r
+                       }\r
+               }\r
+\r
+               for (i = 0;i < LIST_NUM(o2);i++)\r
+               {\r
+                       PKT *packet;\r
+                       BUF *buf = LIST_DATA(o2, i);\r
+\r
+                       Wait(hub->WatchDogEvent, interval);\r
+                       if (hub->HaltWatchDog)\r
+                       {\r
+                               ReleaseList(o);\r
+\r
+                               for (;i < LIST_NUM(o2);i++)\r
+                               {\r
+                                       FreeBuf(LIST_DATA(o2, i));\r
+                               }\r
+                               ReleaseList(o2);\r
+                               goto ESCAPE;\r
+                       }\r
+\r
+                       packet = ParsePacket(buf->Buf, buf->Size);\r
+                       if (packet != NULL)\r
+                       {\r
+                               StorePacket(hub, NULL, packet);\r
+                               num_packets_v6++;\r
+                       }\r
+                       else\r
+                       {\r
+                               Free(buf->Buf);\r
+                       }\r
+\r
+                       Free(buf);\r
+               }\r
+\r
+               ReleaseList(o);\r
+               ReleaseList(o2);\r
+\r
+               if (num == 0)\r
+               {\r
+                       wait_time = HUB_ARP_SEND_INTERVAL;\r
+               }\r
+\r
+               Wait(hub->WatchDogEvent, wait_time);\r
+       }\r
+ESCAPE:\r
+       return;\r
+}\r
+\r
+// SecureNAT を有効/無効に設定する\r
+void EnableSecureNAT(HUB *h, bool enable)\r
+{\r
+       EnableSecureNATEx(h, enable, false);\r
+}\r
+void EnableSecureNATEx(HUB *h, bool enable, bool no_change)\r
+{\r
+       bool for_cluster = false;\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (h->Cedar->Server != NULL && h->Cedar->Server->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               if (h->Type == HUB_TYPE_FARM_DYNAMIC)\r
+               {\r
+                       for_cluster = true;\r
+               }\r
+       }\r
+\r
+       Lock(h->lock_online);\r
+       {\r
+               if (no_change == false)\r
+               {\r
+                       h->EnableSecureNAT = enable;\r
+               }\r
+\r
+               if (h->EnableSecureNAT == false)\r
+               {\r
+STOP:\r
+                       // すでに開始している場合は停止する\r
+                       if (h->SecureNAT != NULL)\r
+                       {\r
+                               SnFreeSecureNAT(h->SecureNAT);\r
+                               h->SecureNAT = NULL;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if (for_cluster)\r
+                       {\r
+                               if ((h->SecureNAT != NULL && LIST_NUM(h->SessionList) <= 1) ||\r
+                                       (h->SecureNAT == NULL && LIST_NUM(h->SessionList) == 0))\r
+                               {\r
+                                       // 開始モードだが、ダイナミック仮想 HUB で他にセッションが無い場合\r
+                                       // は停止する\r
+                                       goto STOP;\r
+                               }\r
+                       }\r
+\r
+                       // まだ開始していない場合で HUB がオンラインの場合は開始する\r
+                       if (h->SecureNAT == NULL && h->Offline == false)\r
+                       {\r
+                               h->SecureNAT = SnNewSecureNAT(h, h->SecureNATOption);\r
+                       }\r
+               }\r
+       }\r
+       Unlock(h->lock_online);\r
+}\r
+\r
+// アクセスリストを文字列に変換する\r
+void GetAccessListStr(char *str, UINT size, ACCESS *a)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       char tmp1[MAX_SIZE];\r
+       char tmp2[MAX_SIZE];\r
+       bool l3 = false;\r
+       bool asterisk = false;\r
+       // 引数チェック\r
+       if (str == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(str, size, "");\r
+\r
+       if (a->IsIPv6 == false)\r
+       {\r
+               if (a->SrcIpAddress != 0 || a->SrcSubnetMask != 0)\r
+               {\r
+                       IPToStr32(tmp1, sizeof(tmp1), a->SrcIpAddress);\r
+                       MaskToStr32(tmp2, sizeof(tmp2), a->SrcSubnetMask);\r
+                       Format(tmp, sizeof(tmp), "SrcIPv4=%s/%s, ", tmp1, tmp2);\r
+                       StrCat(str, size, tmp);\r
+\r
+                       l3 = true;\r
+               }\r
+\r
+               if (a->DestIpAddress != 0 || a->DestSubnetMask != 0)\r
+               {\r
+                       IPToStr32(tmp1, sizeof(tmp1), a->DestIpAddress);\r
+                       MaskToStr32(tmp2, sizeof(tmp2), a->DestSubnetMask);\r
+                       Format(tmp, sizeof(tmp), "DstIPv4=%s/%s, ", tmp1, tmp2);\r
+                       StrCat(str, size, tmp);\r
+\r
+                       l3 = true;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (IsZeroIP6Addr(&a->SrcIpAddress6) == false || IsZeroIP6Addr(&a->SrcSubnetMask6) == false)\r
+               {\r
+                       IP6AddrToStr(tmp1, sizeof(tmp1), &a->SrcIpAddress6);\r
+                       Mask6AddrToStr(tmp2, sizeof(tmp2), &a->SrcSubnetMask6);\r
+                       Format(tmp, sizeof(tmp), "SrcIPv6=%s/%s, ", tmp1, tmp2);\r
+                       StrCat(str, size, tmp);\r
+\r
+                       l3 = true;\r
+               }\r
+\r
+               if (IsZeroIP6Addr(&a->DestIpAddress6) == false || IsZeroIP6Addr(&a->DestSubnetMask6) == false)\r
+               {\r
+                       IP6AddrToStr(tmp1, sizeof(tmp1), &a->DestIpAddress6);\r
+                       Mask6AddrToStr(tmp2, sizeof(tmp2), &a->DestSubnetMask6);\r
+                       Format(tmp, sizeof(tmp), "DstIPv6=%s/%s, ", tmp1, tmp2);\r
+                       StrCat(str, size, tmp);\r
+\r
+                       l3 = true;\r
+               }\r
+       }\r
+\r
+       if (a->Protocol != 0)\r
+       {\r
+               StrCpy(tmp1, sizeof(tmp1), "");\r
+               switch (a->Protocol)\r
+               {\r
+               case 1:\r
+                       StrCpy(tmp1, sizeof(tmp1), "ICMPv4");\r
+                       break;\r
+               case 3:\r
+                       StrCpy(tmp1, sizeof(tmp1), "GGP");\r
+                       break;\r
+               case 6:\r
+                       StrCpy(tmp1, sizeof(tmp1), "TCP");\r
+                       break;\r
+               case 8:\r
+                       StrCpy(tmp1, sizeof(tmp1), "EGP");\r
+                       break;\r
+               case 12:\r
+                       StrCpy(tmp1, sizeof(tmp1), "PUP");\r
+                       break;\r
+               case 17:\r
+                       StrCpy(tmp1, sizeof(tmp1), "UDP");\r
+                       break;\r
+               case 20:\r
+                       StrCpy(tmp1, sizeof(tmp1), "HMP");\r
+                       break;\r
+               case 22:\r
+                       StrCpy(tmp1, sizeof(tmp1), "XNS-IDP");\r
+                       break;\r
+               case 27:\r
+                       StrCpy(tmp1, sizeof(tmp1), "RDP");\r
+                       break;\r
+               case 58:\r
+                       StrCpy(tmp1, sizeof(tmp1), "ICMPv6");\r
+                       break;\r
+               case 66:\r
+                       StrCpy(tmp1, sizeof(tmp1), "RVD");\r
+                       break;\r
+               }\r
+               Format(tmp, sizeof(tmp), "Protocol=%s(%u), ", tmp1, a->Protocol);\r
+               StrCat(str, size, tmp);\r
+\r
+               l3 = true;\r
+       }\r
+\r
+       if (a->SrcPortStart != 0)\r
+       {\r
+               if (a->SrcPortEnd == a->SrcPortStart)\r
+               {\r
+                       Format(tmp, sizeof(tmp), "SrcPort=%u, ", a->SrcPortStart);\r
+                       StrCat(str, size, tmp);\r
+               }\r
+               else\r
+               {\r
+                       Format(tmp, sizeof(tmp), "SrcPort=%u-%u, ", a->SrcPortStart, a->SrcPortEnd);\r
+                       StrCat(str, size, tmp);\r
+               }\r
+\r
+               l3 = true;\r
+       }\r
+\r
+       if (a->DestPortStart != 0)\r
+       {\r
+               if (a->DestPortEnd == a->DestPortStart)\r
+               {\r
+                       Format(tmp, sizeof(tmp), "DstPort=%u, ", a->DestPortStart);\r
+                       StrCat(str, size, tmp);\r
+               }\r
+               else\r
+               {\r
+                       Format(tmp, sizeof(tmp), "DstPort=%u-%u, ", a->DestPortStart, a->DestPortEnd);\r
+                       StrCat(str, size, tmp);\r
+               }\r
+\r
+               l3 = true;\r
+       }\r
+\r
+       if (StrLen(a->SrcUsername) != 0)\r
+       {\r
+               Format(tmp, sizeof(tmp), "SrcUser=%s, ", a->SrcUsername);\r
+               StrCat(str, size, tmp);\r
+       }\r
+\r
+       if (StrLen(a->DestUsername) != 0)\r
+       {\r
+               Format(tmp, sizeof(tmp), "DstUser=%s, ", a->DestUsername);\r
+               StrCat(str, size, tmp);\r
+       }\r
+\r
+       if (a->CheckSrcMac != false)\r
+       {\r
+               char mac[MAX_SIZE], mask[MAX_SIZE];\r
+               MacToStr(mac, sizeof(mac), a->SrcMacAddress);\r
+               MacToStr(mask, sizeof(mask), a->SrcMacMask);\r
+               Format(tmp, sizeof(tmp), "SrcMac=%s/%s, ", mac, mask);\r
+               StrCat(str, size, tmp);\r
+       }\r
+       if (a->CheckDstMac != false)\r
+       {\r
+               char mac[MAX_SIZE], mask[MAX_SIZE];\r
+               MacToStr(mac, sizeof(mac), a->DstMacAddress);\r
+               MacToStr(mask, sizeof(mask), a->DstMacMask);\r
+               Format(tmp, sizeof(tmp), "DstMac=%s/%s, ", mac, mask);\r
+               StrCat(str, size, tmp);\r
+       }\r
+\r
+       if (a->CheckTcpState)\r
+       {\r
+               if(a->Established)\r
+               {\r
+                       StrCat(str, size, "Established, ");\r
+               }\r
+               else\r
+               {\r
+                       StrCat(str, size, "Unestablished, ");\r
+               }\r
+\r
+               l3 = true;\r
+       }\r
+\r
+       if (a->Discard == false)\r
+       {\r
+               if (a->Delay >= 1)\r
+               {\r
+                       Format(tmp, sizeof(tmp), "Delay=%u, ", a->Delay);\r
+                       StrCat(str, size, tmp);\r
+               }\r
+\r
+               if (a->Jitter >= 1)\r
+               {\r
+                       Format(tmp, sizeof(tmp), "Jitter=%u, ", a->Jitter);\r
+                       StrCat(str, size, tmp);\r
+               }\r
+\r
+               if (a->Loss >= 1)\r
+               {\r
+                       Format(tmp, sizeof(tmp), "Loss=%u, " , a->Loss);\r
+                       StrCat(str, size, tmp);\r
+               }\r
+       }\r
+\r
+       if (StrLen(str) == 0)\r
+       {\r
+               asterisk = true;\r
+       }\r
+\r
+       if (l3)\r
+       {\r
+               if (a->IsIPv6)\r
+               {\r
+                       StrCatLeft(str, size, "(ipv6) ");\r
+               }\r
+               else\r
+               {\r
+                       StrCatLeft(str, size, "(ipv4) ");\r
+               }\r
+       }\r
+       else\r
+       {\r
+               StrCatLeft(str, size, "(ether) ");\r
+       }\r
+\r
+       if (EndWith(str, ", "))\r
+       {\r
+               str[StrLen(str) - 2] = 0;\r
+       }\r
+\r
+       if (asterisk)\r
+       {\r
+               StrCat(str, size, "*");\r
+       }\r
+}\r
+\r
+// パケットをアクセスリストによってマスクすることができるかどうか判定する\r
+bool IsPacketMaskedByAccessList(SESSION *s, PKT *p, ACCESS *a, UINT dest_username, UINT dest_groupname)\r
+{\r
+       UINT src_username;\r
+       UINT src_groupname;\r
+       HUB_PA *pa;\r
+       IPV4_HEADER *ip = NULL;\r
+       IPV6_HEADER *ip6 = NULL;\r
+       bool is_ipv4_packet = false;\r
+       bool is_ipv6_packet = false;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL || a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (a->Active == false)\r
+       {\r
+               // アクセスリストは無効\r
+               return false;\r
+       }\r
+\r
+       pa = (HUB_PA *)s->PacketAdapter->Param;\r
+\r
+       // 送信元のユーザー名ハッシュ\r
+       src_username = pa->UsernameHash;\r
+       src_groupname = pa->GroupnameHash;\r
+\r
+       // 送信元・宛先 MAC アドレスの判定\r
+       if (a->CheckSrcMac != false)\r
+       {\r
+               UINT i;\r
+               for (i = 0; i < 6; i++)\r
+               {\r
+                       if((a->SrcMacAddress[i] & a->SrcMacMask[i]) != (a->SrcMacMask[i] & p->MacAddressSrc[i]))\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (a->CheckDstMac != false)\r
+       {\r
+               UINT i;\r
+               for (i = 0; i < 6; i++)\r
+               {\r
+                       if ((a->DstMacAddress[i] & a->DstMacMask[i]) != (a->DstMacMask[i] & p->MacAddressDest[i]))\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // 送信元ユーザー名 / グループ名のチェック\r
+       if (a->SrcUsernameHash != 0)\r
+       {\r
+               if ((a->SrcUsernameHash != src_username) && (a->SrcUsernameHash != src_groupname))\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // 宛先ユーザー名 / グループ名のチェック\r
+       if (a->DestUsernameHash != 0)\r
+       {\r
+               if ((a->DestUsernameHash != dest_username) && (a->DestUsernameHash != dest_groupname))\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // IP パケットの判定\r
+       if (p->TypeL3 != L3_IPV4)\r
+       {\r
+               is_ipv4_packet = false;\r
+       }\r
+       else\r
+       {\r
+               is_ipv4_packet = true;\r
+       }\r
+\r
+       if (p->TypeL3 != L3_IPV6)\r
+       {\r
+               is_ipv6_packet = false;\r
+       }\r
+       else\r
+       {\r
+               is_ipv6_packet = true;\r
+       }\r
+\r
+       if (is_ipv4_packet)\r
+       {\r
+               ip = p->L3.IPv4Header;\r
+       }\r
+\r
+       if (is_ipv6_packet)\r
+       {\r
+               ip6 = p->L3.IPv6Header;\r
+       }\r
+\r
+       if (a->IsIPv6 == false)\r
+       {\r
+               // IPv4\r
+\r
+               // 送信元 IP アドレスのチェック\r
+               if (a->SrcIpAddress != 0 || a->SrcSubnetMask != 0)\r
+               {\r
+                       if (is_ipv4_packet == false)\r
+                       {\r
+                               if (p->TypeL3 == L3_ARPV4)\r
+                               {\r
+                                       bool arp_match = false;\r
+                                       if (p->L3.ARPv4Header->HardwareSize == 6 &&\r
+                                               Endian16(p->L3.ARPv4Header->HardwareType) == ARP_HARDWARE_TYPE_ETHERNET &&\r
+                                               p->L3.ARPv4Header->ProtocolSize == 4 &&\r
+                                               Endian16(p->L3.ARPv4Header->ProtocolType) == 0x0800)\r
+                                       {\r
+                                               UINT uint_ip = p->L3.ARPv4Header->SrcIP;\r
+\r
+                                               if (uint_ip != 0 && uint_ip != 0xffffffff && !(IsHubIpAddress32(uint_ip) && IsHubMacAddress(p->MacAddressSrc)))\r
+                                               {\r
+                                                       if ((uint_ip & a->SrcSubnetMask) != (a->SrcIpAddress & a->SrcSubnetMask))\r
+                                                       {\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               arp_match = true;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+\r
+                                       if (arp_match == false)\r
+                                       {\r
+                                               return false;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               if ((ip->SrcIP & a->SrcSubnetMask) != (a->SrcIpAddress & a->SrcSubnetMask))\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // 宛先 IP アドレスのチェック\r
+               if (a->DestIpAddress != 0 || a->DestSubnetMask != 0)\r
+               {\r
+                       if (is_ipv4_packet == false)\r
+                       {\r
+                               if (p->TypeL3 == L3_ARPV4)\r
+                               {\r
+                                       bool arp_match = false;\r
+                                       if (p->L3.ARPv4Header->HardwareSize == 6 &&\r
+                                               Endian16(p->L3.ARPv4Header->HardwareType) == ARP_HARDWARE_TYPE_ETHERNET &&\r
+                                               p->L3.ARPv4Header->ProtocolSize == 4 &&\r
+                                               Endian16(p->L3.ARPv4Header->ProtocolType) == 0x0800)\r
+                                       {\r
+                                               UINT uint_ip = p->L3.ARPv4Header->TargetIP;\r
+\r
+                                               if (uint_ip != 0 && uint_ip != 0xffffffff && !(IsHubIpAddress32(uint_ip) && IsHubMacAddress(p->MacAddressSrc)))\r
+                                               {\r
+                                                       if ((uint_ip & a->DestSubnetMask) != (a->DestIpAddress & a->DestSubnetMask))\r
+                                                       {\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               arp_match = true;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+\r
+                                       if (arp_match == false)\r
+                                       {\r
+                                               return false;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               if ((ip->DstIP & a->DestSubnetMask) != (a->DestIpAddress & a->DestSubnetMask))\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // IPv6\r
+\r
+               // 送信元 IP アドレスのチェック\r
+               if (IsZeroIP6Addr(&a->SrcIpAddress6) == false ||\r
+                       IsZeroIP6Addr(&a->SrcSubnetMask6) == false)\r
+               {\r
+                       if (is_ipv6_packet == false)\r
+                       {\r
+                               return false;\r
+                       }\r
+                       else\r
+                       {\r
+                               IP a_ip, a_subnet, p_ip;\r
+                               IP and1, and2;\r
+\r
+                               IPv6AddrToIP(&a_ip, &a->SrcIpAddress6);\r
+                               IPv6AddrToIP(&a_subnet, &a->SrcSubnetMask6);\r
+                               IPv6AddrToIP(&p_ip, &ip6->SrcAddress);\r
+\r
+                               IPAnd6(&and1, &a_ip, &a_subnet);\r
+                               IPAnd6(&and2, &p_ip, &a_subnet);\r
+\r
+                               if (CmpIpAddr(&and1, &and2) != 0)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // 宛先 IP アドレスのチェック\r
+               if (IsZeroIP6Addr(&a->DestIpAddress6) == false ||\r
+                       IsZeroIP6Addr(&a->DestSubnetMask6) == false)\r
+               {\r
+                       if (is_ipv6_packet == false)\r
+                       {\r
+                               return false;\r
+                       }\r
+                       else\r
+                       {\r
+                               IP a_ip, a_subnet, p_ip;\r
+                               IP and1, and2;\r
+\r
+                               IPv6AddrToIP(&a_ip, &a->DestIpAddress6);\r
+                               IPv6AddrToIP(&a_subnet, &a->DestSubnetMask6);\r
+                               IPv6AddrToIP(&p_ip, &ip6->DestAddress);\r
+\r
+                               IPAnd6(&and1, &a_ip, &a_subnet);\r
+                               IPAnd6(&and2, &p_ip, &a_subnet);\r
+\r
+                               if (CmpIpAddr(&and1, &and2) != 0)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       // IPv4 でも IPv6 でもないパケットはマッチさせない。\r
+       if(is_ipv4_packet == false && is_ipv6_packet==false){\r
+               return false;\r
+       }\r
+\r
+       // プロトコル番号のチェック\r
+       if (a->Protocol != 0)\r
+       {\r
+               if (a->IsIPv6 == false)\r
+               {\r
+                       if (is_ipv4_packet == false)\r
+                       {\r
+                               return false;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (ip->Protocol != a->Protocol)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if (is_ipv6_packet == false)\r
+                       {\r
+                               return false;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (p->IPv6HeaderPacketInfo.Protocol != a->Protocol)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       // ポート番号のチェック\r
+       if (a->SrcPortStart != 0 || a->DestPortStart != 0 ||\r
+               a->SrcPortEnd != 0 || a->DestPortEnd != 0)\r
+       {\r
+               if ((a->IsIPv6 == false && is_ipv4_packet == false) ||\r
+                       (a->IsIPv6 && is_ipv6_packet == false))\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       if (p->TypeL4 == L4_TCP)\r
+                       {\r
+                               TCP_HEADER *tcp = p->L4.TCPHeader;\r
+                               // 送信元ポートのチェック\r
+                               if (a->SrcPortStart != 0 || a->SrcPortEnd != 0)\r
+                               {\r
+                                       UINT src_port = Endian16(tcp->SrcPort);\r
+                                       if (src_port < a->SrcPortStart || src_port > a->SrcPortEnd)\r
+                                       {\r
+                                               return false;\r
+                                       }\r
+                               }\r
+\r
+                               // 宛先ポート番号のチェック\r
+                               if (a->DestPortStart != 0 || a->DestPortEnd != 0)\r
+                               {\r
+                                       UINT dest_port = Endian16(tcp->DstPort);\r
+                                       if (dest_port < a->DestPortStart || dest_port > a->DestPortEnd)\r
+                                       {\r
+                                               return false;\r
+                                       }\r
+                               }\r
+                       }\r
+                       else if (p->TypeL4 == L4_UDP)\r
+                       {\r
+                               UDP_HEADER *udp = p->L4.UDPHeader;\r
+                               // 送信元ポートのチェック\r
+                               if (a->SrcPortStart != 0 || a->SrcPortEnd != 0)\r
+                               {\r
+                                       UINT src_port = Endian16(udp->SrcPort);\r
+                                       if (src_port < a->SrcPortStart || src_port > a->SrcPortEnd)\r
+                                       {\r
+                                               return false;\r
+                                       }\r
+                               }\r
+\r
+                               // 宛先ポート番号のチェック\r
+                               if (a->DestPortStart != 0 || a->DestPortEnd != 0)\r
+                               {\r
+                                       UINT dest_port = Endian16(udp->DstPort);\r
+                                       if (dest_port < a->DestPortStart || dest_port > a->DestPortEnd)\r
+                                       {\r
+                                               return false;\r
+                                       }\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // アクセスリストにポート番号が指定されているときは\r
+                               // TCP か UDP 以外のパケットは適用されない\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // TCP コネクションの状態チェック\r
+       if (a->CheckTcpState != false)\r
+       {\r
+               if ((a->IsIPv6 == false && is_ipv4_packet == false) ||\r
+                       (a->IsIPv6 && is_ipv6_packet == false))\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       if(p->TypeL4 == L4_TCP)\r
+                       {\r
+                               // by shimizu\r
+                               TCP_HEADER *tcp = p->L4.TCPHeader;\r
+                               bool est = true;\r
+\r
+                               if (tcp->Flag & TCP_SYN)\r
+                               {\r
+                                       est = false;\r
+                               }\r
+\r
+                               if((MAKEBOOL(a->Established) ^ MAKEBOOL(est)))\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// フォワードするパケットに対してアクセスリストを適用する\r
+bool ApplyAccessListToForwardPacket(HUB *hub, SESSION *src_session, SESSION *dest_session, PKT *p)\r
+{\r
+       UINT i;\r
+       bool pass = true;       // デフォルトでは通過させる\r
+       bool skip = true;\r
+       // 引数チェック\r
+       if (hub == NULL || src_session == NULL || p == NULL || dest_session == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 既にチェックされたパケットはアクセスリストを再適用しない。\r
+       if (p->AccessChecked)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       LockList(hub->AccessList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(hub->AccessList);i++)\r
+               {\r
+                       ACCESS *a = LIST_DATA(hub->AccessList, i);\r
+\r
+                       // あて先ユーザー名が指定されているエントリ以降のみを走査する。\r
+                       if (a->DestUsernameHash != 0)\r
+                       {\r
+                               skip = false;\r
+                       }\r
+\r
+                       if (skip == false)\r
+                       {\r
+                               if (IsPacketMaskedByAccessList(src_session, p, a,\r
+                                       ((HUB_PA *)dest_session->PacketAdapter->Param)->UsernameHash,\r
+                                       ((HUB_PA *)dest_session->PacketAdapter->Param)->GroupnameHash))\r
+                               {\r
+                                       // パケットの通過または破棄を決定する\r
+                                       pass = a->Discard ? false : true;\r
+\r
+                                       // リストの走査をここで完了する\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(hub->AccessList);\r
+\r
+       return pass;\r
+}\r
+\r
+// ストアされたパケットに対してアクセスリストを適用する\r
+bool ApplyAccessListToStoredPacket(HUB *hub, SESSION *s, PKT *p)\r
+{\r
+       UINT i;\r
+       bool pass = true;       // デフォルトでは通過させる\r
+       // 引数チェック\r
+       if (hub == NULL || s == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (hub->Option != NULL && hub->Option->FilterPPPoE)\r
+       {\r
+               if (p->MacHeader != NULL)\r
+               {\r
+                       USHORT proto = Endian16(p->MacHeader->Protocol);\r
+                       if (proto == 0x8863 || proto == 0x8864)\r
+                       {\r
+                               // PPPoE Filter\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (hub->Option != NULL && hub->Option->FilterOSPF)\r
+       {\r
+               if (p->TypeL3 == L3_IPV4)\r
+               {\r
+                       if (p->L3.IPv4Header != NULL)\r
+                       {\r
+                               if (p->L3.IPv4Header->Protocol == 89)\r
+                               {\r
+                                       // OSPF Filter\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (hub->Option != NULL && hub->Option->FilterIPv4)\r
+       {\r
+               if (p->MacHeader != NULL)\r
+               {\r
+                       USHORT proto = Endian16(p->MacHeader->Protocol);\r
+                       if (proto == 0x0800 || proto == 0x0806)\r
+                       {\r
+                               // IPv4 Filter\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (hub->Option != NULL && hub->Option->FilterIPv6)\r
+       {\r
+               if (p->MacHeader != NULL)\r
+               {\r
+                       USHORT proto = Endian16(p->MacHeader->Protocol);\r
+                       if (proto == 0x86dd)\r
+                       {\r
+                               // IPv6 Filter\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (hub->Option != NULL && hub->Option->FilterNonIP)\r
+       {\r
+               if (p->MacHeader != NULL)\r
+               {\r
+                       USHORT proto = Endian16(p->MacHeader->Protocol);\r
+                       if (!(proto == 0x86dd || proto == 0x0800 || proto == 0x0806))\r
+                       {\r
+                               // Non-IP Filter\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (hub->Option != NULL && hub->Option->FilterBPDU)\r
+       {\r
+               if (p->MacHeader != NULL)\r
+               {\r
+                       if (p->TypeL3 == L3_BPDU)\r
+                       {\r
+                               // BPDU Filter\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       LockList(hub->AccessList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(hub->AccessList);i++)\r
+               {\r
+                       ACCESS *a = LIST_DATA(hub->AccessList, i);\r
+\r
+                       if (a->DestUsernameHash != 0)\r
+                       {\r
+                               // あて先ユーザー名が指定されていたら、そこでリストの走査を中断する。\r
+                               break;\r
+                       }\r
+\r
+                       if (IsPacketMaskedByAccessList(s, p, a, 0, 0))\r
+                       {\r
+                               // パケットの通過または破棄を決定する\r
+                               pass = a->Discard ? false : true;\r
+\r
+                               // ここで処理が決定したパケットはHUBを出るときに走査しない。\r
+                               p->AccessChecked = true;\r
+\r
+                               // 遅延・ジッタ・パケットロスのパラメータのコピー\r
+                               p->Delay = a->Delay;\r
+                               p->Jitter = a->Jitter;\r
+                               p->Loss = a->Loss;\r
+\r
+                               // リストの走査をここで完了する\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(hub->AccessList);\r
+\r
+       return pass;\r
+}\r
+\r
+// アクセスリストの追加\r
+void AddAccessList(HUB *hub, ACCESS *a)\r
+{\r
+       // 引数チェック\r
+       if (hub == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(hub->AccessList);\r
+       {\r
+               ACCESS *access;\r
+               UINT i;\r
+\r
+               // 個数のチェック\r
+               if (LIST_NUM(hub->AccessList) >= MAX_ACCESSLISTS)\r
+               {\r
+                       UnlockList(hub->AccessList);\r
+                       return;\r
+               }\r
+\r
+               access = Malloc(sizeof(ACCESS));\r
+               Copy(access, a, sizeof(ACCESS));\r
+               access->SrcUsernameHash = UsernameToInt(access->SrcUsername);\r
+               access->DestUsernameHash = UsernameToInt(access->DestUsername);\r
+\r
+               // ポート番号補正\r
+               if (access->SrcPortStart != 0)\r
+               {\r
+                       access->SrcPortEnd = MAX(access->SrcPortEnd, access->SrcPortStart);\r
+               }\r
+               if (access->DestPortStart != 0)\r
+               {\r
+                       access->DestPortEnd = MAX(access->DestPortEnd, access->DestPortStart);\r
+               }\r
+\r
+               // 遅延、ジッタ、パケットロスの補正\r
+               access->Delay = MAKESURE(access->Delay, 0, HUB_ACCESSLIST_DELAY_MAX);\r
+               access->Jitter = MAKESURE(access->Jitter, 0, HUB_ACCESSLIST_JITTER_MAX);\r
+               access->Loss = MAKESURE(access->Loss, 0, HUB_ACCESSLIST_LOSS_MAX);\r
+\r
+               Insert(hub->AccessList, access);\r
+\r
+               // ID を振り直す\r
+               for (i = 0;i < LIST_NUM(hub->AccessList);i++)\r
+               {\r
+                       ACCESS *a = LIST_DATA(hub->AccessList, i);\r
+                       a->Id = (i + 1);\r
+               }\r
+       }\r
+       UnlockList(hub->AccessList);\r
+}\r
+\r
+// アクセスリストの初期化\r
+void InitAccessList(HUB *hub)\r
+{\r
+       // 引数チェック\r
+       if (hub == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       hub->AccessList = NewList(CmpAccessList);\r
+}\r
+\r
+// アクセスリストの解放\r
+void FreeAccessList(HUB *hub)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hub == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(hub->AccessList);i++)\r
+       {\r
+               ACCESS *a = LIST_DATA(hub->AccessList, i);\r
+               Free(a);\r
+       }\r
+\r
+       ReleaseList(hub->AccessList);\r
+       hub->AccessList = NULL;\r
+}\r
+\r
+// アクセスリストの比較\r
+int CmpAccessList(void *p1, void *p2)\r
+{\r
+       ACCESS *a1, *a2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       a1 = *(ACCESS **)p1;\r
+       a2 = *(ACCESS **)p2;\r
+       if (a1 == NULL || a2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       // 優先順位別にソートする\r
+       if (a1->Priority > a2->Priority)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (a1->Priority < a2->Priority)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (a1->Discard > a2->Discard)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (a1->Discard < a2->Discard)\r
+       {\r
+               return -1;\r
+       }\r
+       else\r
+       {\r
+               return Cmp(&a1->Active, &a2->Active, sizeof(ACCESS) - 4);\r
+       }\r
+}\r
+\r
+// ユーザー名を UINT に変換\r
+UINT UsernameToInt(char *name)\r
+{\r
+       UCHAR hash[SHA1_SIZE];\r
+       UINT ret;\r
+       char tmp[MAX_USERNAME_LEN + 1];\r
+       // 引数チェック\r
+       if (name == 0 || StrLen(name) == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), name);\r
+       Trim(tmp);\r
+       StrUpper(tmp);\r
+\r
+       if (StrLen(tmp) == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Hash(hash, tmp, StrLen(tmp), true);\r
+       Copy(&ret, hash, sizeof(ret));\r
+\r
+       return ret;\r
+}\r
+\r
+// セッションポインタからセッションを検索\r
+SESSION *GetSessionByPtr(HUB *hub, void *ptr)\r
+{\r
+       // 引数チェック\r
+       if (hub == NULL || ptr == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       LockList(hub->SessionList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(hub->SessionList);i++)\r
+               {\r
+                       SESSION *s = LIST_DATA(hub->SessionList, i);\r
+                       if (s == (SESSION *)ptr)\r
+                       {\r
+                               // 発見\r
+                               AddRef(s->ref);\r
+                               UnlockList(hub->SessionList);\r
+                               return s;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(hub->SessionList);\r
+\r
+       return NULL;\r
+}\r
+\r
+// セッション名からセッションを検索\r
+SESSION *GetSessionByName(HUB *hub, char *name)\r
+{\r
+       // 引数チェック\r
+       if (hub == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       LockList(hub->SessionList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(hub->SessionList);i++)\r
+               {\r
+                       SESSION *s = LIST_DATA(hub->SessionList, i);\r
+                       if (StrCmpi(s->Name, name) == 0)\r
+                       {\r
+                               // 発見\r
+                               AddRef(s->ref);\r
+                               UnlockList(hub->SessionList);\r
+                               return s;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(hub->SessionList);\r
+\r
+       return NULL;\r
+}\r
+\r
+// STORM リストのソート\r
+int CompareStormList(void *p1, void *p2)\r
+{\r
+       STORM *s1, *s2;\r
+       UINT r;\r
+       // 引数チェック\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       s1 = *(STORM **)p1;\r
+       s2 = *(STORM **)p2;\r
+       if (s1 == NULL || s2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       r = CmpIpAddr(&s1->DestIp, &s2->DestIp);\r
+       if (r != 0)\r
+       {\r
+               return r;\r
+       }\r
+       r = CmpIpAddr(&s1->SrcIp, &s2->SrcIp);\r
+       if (r != 0)\r
+       {\r
+               return r;\r
+       }\r
+       r = Cmp(s1->MacAddress, s2->MacAddress, 6);\r
+       return r;\r
+}\r
+\r
+// パケットアダプタ初期化\r
+bool HubPaInit(SESSION *s)\r
+{\r
+       // パケットアダプタ情報の初期化\r
+       HUB_PA *pa = ZeroMalloc(sizeof(HUB_PA));\r
+       pa->Cancel = NewCancel();\r
+       pa->PacketQueue = NewQueue();\r
+       pa->Now = Tick64();\r
+       pa->Session = s;\r
+       pa->StormList = NewList(CompareStormList);\r
+       pa->UsernameHash = UsernameToInt(s->Username);\r
+       pa->GroupnameHash = UsernameToInt(s->GroupName);\r
+\r
+       s->PacketAdapter->Param = pa;\r
+\r
+       if (s->Policy->MonitorPort)\r
+       {\r
+               // このポートをモニタリングポートとしてマークする\r
+               pa->MonitorPort = true;\r
+\r
+               // HUB のモニタリングポート一覧にこのセッションを追加する\r
+               LockList(s->Hub->MonitorList);\r
+               {\r
+                       Insert(s->Hub->MonitorList, s);\r
+               }\r
+               UnlockList(s->Hub->MonitorList);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// パケットアダプタ解放\r
+void HubPaFree(SESSION *s)\r
+{\r
+       HUB_PA *pa = (HUB_PA *)s->PacketAdapter->Param;\r
+       HUB *hub = s->Hub;\r
+\r
+       if (pa->MonitorPort)\r
+       {\r
+               // HUB のモニタポート一覧からこのセッションを削除する\r
+               LockList(s->Hub->MonitorList);\r
+               {\r
+                       Delete(s->Hub->MonitorList, s);\r
+               }\r
+               UnlockList(s->Hub->MonitorList);\r
+       }\r
+\r
+       // このセッションに関連付けられている MAC アドレステーブルを消去\r
+       LockList(hub->MacTable);\r
+       {\r
+               UINT i, num = LIST_NUM(hub->MacTable);\r
+               LIST *o = NewListFast(NULL);\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       MAC_TABLE_ENTRY *e = (MAC_TABLE_ENTRY *)LIST_DATA(hub->MacTable, i);\r
+                       if (e->Session == s)\r
+                       {\r
+                               Add(o, e);\r
+                       }\r
+               }\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       MAC_TABLE_ENTRY *e = (MAC_TABLE_ENTRY *)LIST_DATA(o, i);\r
+                       Delete(hub->MacTable, e);\r
+                       Free(e);\r
+               }\r
+               ReleaseList(o);\r
+       }\r
+       {\r
+               UINT i, num = LIST_NUM(hub->IpTable);\r
+               LIST *o = NewListFast(NULL);\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       IP_TABLE_ENTRY *e = LIST_DATA(hub->IpTable, i);\r
+                       if (e->Session == s)\r
+                       {\r
+                               Add(o, e);\r
+                       }\r
+               }\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       IP_TABLE_ENTRY *e = LIST_DATA(o, i);\r
+                       Delete(hub->IpTable, e);\r
+                       Free(e);\r
+               }\r
+               ReleaseList(o);\r
+       }\r
+       UnlockList(hub->MacTable);\r
+\r
+       // STORM リストを解放\r
+       LockList(pa->StormList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(pa->StormList);i++)\r
+               {\r
+                       STORM *s = (STORM *)LIST_DATA(pa->StormList, i);\r
+                       Free(s);\r
+               }\r
+               DeleteAll(pa->StormList);\r
+       }\r
+       UnlockList(pa->StormList);\r
+\r
+       ReleaseList(pa->StormList);\r
+\r
+       // キューに残っているパケットを解放\r
+       LockQueue(pa->PacketQueue);\r
+       {\r
+               BLOCK *b;\r
+\r
+               while (b = GetNext(pa->PacketQueue))\r
+               {\r
+                       // ブロックの解放\r
+                       FreeBlock(b);\r
+               }\r
+       }\r
+       UnlockQueue(pa->PacketQueue);\r
+\r
+       // キューを解放\r
+       ReleaseQueue(pa->PacketQueue);\r
+\r
+       // キャンセルオブジェクトの解放\r
+       ReleaseCancel(pa->Cancel);\r
+\r
+       // パケットアダプタ情報の解放\r
+       Free(pa);\r
+       s->PacketAdapter->Param = NULL;\r
+}\r
+\r
+// キャンセルオブジェクトの取得\r
+CANCEL *HubPaGetCancel(SESSION *s)\r
+{\r
+       HUB_PA *pa = (HUB_PA *)s->PacketAdapter->Param;\r
+\r
+       AddRef(pa->Cancel->ref);\r
+       return pa->Cancel;\r
+}\r
+\r
+// 次の送信予定パケットの取得\r
+UINT HubPaGetNextPacket(SESSION *s, void **data)\r
+{\r
+       UINT ret = 0;\r
+       HUB_PA *pa = (HUB_PA *)s->PacketAdapter->Param;\r
+\r
+       // キューの先頭から 1 つ取得する\r
+       LockQueue(pa->PacketQueue);\r
+       {\r
+               BLOCK *block = GetNext(pa->PacketQueue);\r
+               if (block == NULL)\r
+               {\r
+                       // キュー無し\r
+                       ret = 0;\r
+               }\r
+               else\r
+               {\r
+                       // あった\r
+                       *data = block->Buf;\r
+                       ret = block->Size;\r
+                       // ブロックの構造体のメモリは解放する\r
+                       Free(block);\r
+               }\r
+       }\r
+       UnlockQueue(pa->PacketQueue);\r
+\r
+       return ret;\r
+}\r
+\r
+// パケットの受信\r
+bool HubPaPutPacket(SESSION *s, void *data, UINT size)\r
+{\r
+       PKT *packet;\r
+       HUB_PA *pa = (HUB_PA *)s->PacketAdapter->Param;\r
+       bool b = false;\r
+       HUB *hub;\r
+       bool no_l3 = false;\r
+       LIST *o = NULL;\r
+       UINT i;\r
+       UINT vlan_type_id = 0;\r
+       bool no_look_bpdu_bridge_id = false;\r
+\r
+       hub = s->Hub;\r
+\r
+       pa->Now = Tick64();\r
+\r
+       if (data == NULL)\r
+       {\r
+               // 遅延パケットのチェック\r
+               o = NULL;\r
+               LockList(s->DelayedPacketList);\r
+               {\r
+                       UINT i;\r
+                       if (LIST_NUM(s->DelayedPacketList) >= 1)\r
+                       {\r
+                               UINT64 now = TickHighres64();\r
+                               for (i = 0;i < LIST_NUM(s->DelayedPacketList);i++)\r
+                               {\r
+                                       PKT *p = LIST_DATA(s->DelayedPacketList, i);\r
+\r
+                                       if (now >= p->DelayedForwardTick)\r
+                                       {\r
+                                               if (o == NULL)\r
+                                               {\r
+                                                       o = NewListFast(NULL);\r
+                                               }\r
+\r
+                                               Add(o, p);\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       if (o != NULL)\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(o);i++)\r
+                               {\r
+                                       PKT *p = LIST_DATA(o, i);\r
+\r
+                                       Delete(s->DelayedPacketList, p);\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(s->DelayedPacketList);\r
+\r
+               // 遅延パケットがある場合はストアする\r
+               if (o != NULL)\r
+               {\r
+                       for (i = 0;i < LIST_NUM(o);i++)\r
+                       {\r
+                               PKT *p = LIST_DATA(o, i);\r
+\r
+                               StorePacket(s->Hub, s, p);\r
+                       }\r
+\r
+                       ReleaseList(o);\r
+               }\r
+\r
+               // このセッションからのすべてのパケットの受信が完了した\r
+               CancelList(s->CancelList);\r
+\r
+               // イールドする\r
+               if (hub->Option != NULL && hub->Option->YieldAfterStorePacket)\r
+               {\r
+                       YieldCpu();\r
+               }\r
+\r
+               return true;\r
+       }\r
+\r
+       if (hub != NULL && hub->Option != NULL && hub->Option->DisableIPParsing)\r
+       {\r
+               no_l3 = true;\r
+       }\r
+\r
+       if (hub != NULL && hub->Option != NULL)\r
+       {\r
+               vlan_type_id = hub->Option->VlanTypeId;\r
+               no_look_bpdu_bridge_id = hub->Option->NoLookBPDUBridgeId;\r
+       }\r
+\r
+       // VLAN タグを挿入する\r
+       if (s->VLanId != 0)\r
+       {\r
+               VLanInsertTag(&data, &size, s->VLanId);\r
+       }\r
+\r
+       // パケットをパースする\r
+       packet = ParsePacketEx3(data, size, no_l3, vlan_type_id, !no_look_bpdu_bridge_id);\r
+\r
+       if (packet != NULL)\r
+       {\r
+               if (packet->InvalidSourcePacket)\r
+               {\r
+                       // 不正な送信元のパケット\r
+                       FreePacket(packet);\r
+                       packet = NULL;\r
+               }\r
+       }\r
+\r
+       if (packet != NULL)\r
+       {\r
+               // パケットのストア\r
+               StorePacket(s->Hub, s, packet);\r
+       }\r
+       else\r
+       {\r
+               // 不良パケット (正しい MAC フレームではない)\r
+               // であるのでパケットデータを解放する\r
+               Free(data);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ブロードキャストストームが発生しないようにチェックするアルゴリズム\r
+// 特定のエンドポイントからのブロードキャストが頻繁に来た場合はフィルタリングする\r
+bool CheckBroadcastStorm(SESSION *s, PKT *p)\r
+{\r
+       IP src_ip, dest_ip;\r
+       HUB_PA *pa;\r
+       UINT64 now = Tick64();\r
+       UINT limit_start_count;\r
+       SESSION *sess = s;\r
+       bool ret = true;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (s->Policy->NoBroadcastLimiter)\r
+       {\r
+               // ブロードキャスト数の制限無し\r
+               return true;\r
+       }\r
+\r
+       pa = (HUB_PA *)s->PacketAdapter->Param;\r
+\r
+       if (p->TypeL3 == L3_IPV4)\r
+       {\r
+               UINTToIP(&src_ip, p->L3.IPv4Header->SrcIP);\r
+               UINTToIP(&dest_ip, p->L3.IPv4Header->DstIP);\r
+       }\r
+       else if (p->TypeL3 == L3_ARPV4)\r
+       {\r
+               UINTToIP(&src_ip, p->L3.ARPv4Header->SrcIP);\r
+               Zero(&dest_ip, sizeof(IP));\r
+       }\r
+       else if (p->TypeL3 == L3_IPV6)\r
+       {\r
+               IPv6AddrToIP(&src_ip, &p->L3.IPv6Header->SrcAddress);\r
+               IPv6AddrToIP(&dest_ip, &p->L3.IPv6Header->DestAddress);\r
+       }\r
+       else\r
+       {\r
+               Zero(&src_ip, sizeof(IP));\r
+               Zero(&dest_ip, sizeof(IP));\r
+       }\r
+\r
+       // 1 間隔ごとに制限を開始する個数\r
+       limit_start_count = 32;\r
+\r
+       if (s->Hub != NULL && s->Hub->Option->BroadcastStormDetectionThreshold != 0)\r
+       {\r
+               limit_start_count = s->Hub->Option->BroadcastStormDetectionThreshold;\r
+       }\r
+\r
+       LockList(pa->StormList);\r
+       {\r
+               STORM *s;\r
+               UINT num;\r
+               s = SearchStormList(pa, p->MacAddressSrc, &src_ip, &dest_ip);\r
+               if (s == NULL)\r
+               {\r
+                       s = AddStormList(pa, p->MacAddressSrc, &src_ip, &dest_ip);\r
+               }\r
+\r
+               s->CurrentBroadcastNum++;\r
+\r
+               if ((s->CheckStartTick + STORM_CHECK_SPAN) < now ||\r
+                       s->CheckStartTick == 0 || s->CheckStartTick > now)\r
+               {\r
+                       // 一定期間ごとにブロードキャスト数を計測する\r
+                       UINT64 diff_time;\r
+                       if (s->CheckStartTick < now)\r
+                       {\r
+                               diff_time = now - s->CheckStartTick;\r
+                       }\r
+                       else\r
+                       {\r
+                               diff_time = 0;\r
+                       }\r
+                       s->CheckStartTick = now;\r
+                       num = (UINT)((UINT64)s->CurrentBroadcastNum * (UINT64)1000 / (UINT64)STORM_CHECK_SPAN);\r
+                       s->CurrentBroadcastNum = 0;\r
+                       if (num >= limit_start_count)\r
+                       {\r
+                               char ip1[64];\r
+                               char ip2[64];\r
+                               char mac[MAX_SIZE];\r
+                               IPToStr(ip1, sizeof(ip1), &src_ip);\r
+                               IPToStr(ip2, sizeof(ip2), &dest_ip);\r
+                               ret = false;\r
+                               if (s->DiscardValue < STORM_DISCARD_VALUE_END)\r
+                               {\r
+                                       s->DiscardValue = MAX(s->DiscardValue, 1) * 2;\r
+                               }\r
+                               Debug("s->DiscardValue: %u  (%u)\n", s->DiscardValue, num);\r
+\r
+                               MacToStr(mac, sizeof(mac), p->MacAddressSrc);\r
+\r
+                               HLog(sess->Hub, "LH_BCAST_STORM", sess->Name, mac, ip1, ip2, num);\r
+                       }\r
+                       else\r
+                       {\r
+                               if (s->DiscardValue >= 1)\r
+                               {\r
+                                       s->DiscardValue = (UINT)((UINT64)s->DiscardValue / MAX((UINT64)2, (UINT64)diff_time / (UINT64)STORM_CHECK_SPAN));\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (s->DiscardValue >= STORM_DISCARD_VALUE_START)\r
+               {\r
+                       if (s->DiscardValue >= 128)\r
+                       {\r
+                               ret = false;\r
+                       }\r
+                       else if ((rand() % s->DiscardValue) != 0)\r
+                       {\r
+                               ret = false;\r
+                       }\r
+               }\r
+\r
+       }\r
+       UnlockList(pa->StormList);\r
+\r
+       return ret;\r
+}\r
+\r
+// パケットのストア\r
+void StorePacket(HUB *hub, SESSION *s, PKT *packet)\r
+{\r
+       MAC_TABLE_ENTRY *entry = NULL;\r
+       MAC_TABLE_ENTRY t;\r
+       void *data;\r
+       UINT size;\r
+       bool broadcast_mode;\r
+       HUB_PA *dest_pa;\r
+       SESSION *dest_session;\r
+       TRAFFIC traffic;\r
+       UINT64 now = Tick64();\r
+       // 引数チェック\r
+       if (hub == NULL || packet == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s != NULL)\r
+       {\r
+               if (((HUB_PA *)s->PacketAdapter->Param)->MonitorPort)\r
+               {\r
+                       // モニタポートからもらったパケットはフォワードしてはならない\r
+                       Free(packet->PacketData);\r
+                       FreePacket(packet);\r
+                       return;\r
+               }\r
+       }\r
+\r
+       // MAC アドレステーブル全体をロック\r
+       LockList(hub->MacTable);\r
+       {\r
+               // フィルタリング\r
+               if (s != NULL && (packet->DelayedForwardTick == 0 && StorePacketFilter(s, packet) == false))\r
+               {\r
+DISCARD_PACKET:\r
+                       // 通過が不許可となったのでパケットを解放する\r
+                       Free(packet->PacketData);\r
+                       FreePacket(packet);\r
+               }\r
+               else // 通過が許可された\r
+               {\r
+                       bool forward_now = true;\r
+\r
+                       if (packet->Loss >= 1)\r
+                       {\r
+                               // パケットロスを発生させる\r
+                               UINT r = rand() % 100;\r
+                               if ((packet->Loss >= 100) || (r < packet->Loss))\r
+                               {\r
+                                       // パケットロス\r
+                                       goto DISCARD_PACKET;\r
+                               }\r
+                       }\r
+\r
+                       if (packet->Delay >= 1)\r
+                       {\r
+                               float delay = (float)packet->Delay;\r
+                               float jitter;\r
+                               UINT delay_uint;\r
+                               bool f = Rand1();\r
+                               if (packet->Jitter == 0)\r
+                               {\r
+                                       jitter = 0;\r
+                               }\r
+                               else\r
+                               {\r
+                                       jitter = (float)(Rand32() % (int)((float)packet->Jitter * delay / 100.0f));\r
+                               }\r
+\r
+                               delay += jitter * (f ? 1 : -1);\r
+                               delay_uint = (UINT)delay;\r
+\r
+                               if (delay_uint >= 1)\r
+                               {\r
+                                       // 遅延を発生させる\r
+                                       forward_now = false;\r
+                                       packet->Loss = packet->Jitter = packet->Delay = 0;\r
+                                       packet->DelayedForwardTick = TickHighres64() + (UINT64)delay_uint;\r
+                                       packet->DelayedSrcSession = s;\r
+\r
+                                       LockList(s->DelayedPacketList);\r
+                                       {\r
+                                               Add(s->DelayedPacketList, packet);\r
+                                       }\r
+                                       UnlockList(s->DelayedPacketList);\r
+                               }\r
+                       }\r
+\r
+                       if (forward_now)\r
+                       {\r
+                               if (Cmp(packet->MacAddressSrc, hub->HubMacAddr, 6) == 0)\r
+                               {\r
+                                       if (s != NULL)\r
+                                       {\r
+                                               // この HUB 自身が発信しようとしたパケットが外部から入力された\r
+                                               goto DISCARD_PACKET;\r
+                                       }\r
+                               }\r
+                               if (s != NULL && (Cmp(packet->MacAddressSrc, hub->HubMacAddr, 6) != 0))\r
+                               {\r
+                                       // 送信元 MAC アドレスがテーブルに登録されているかどうか調べる\r
+                                       Copy(t.MacAddress, packet->MacAddressSrc, 6);\r
+                                       if (hub->Option->NoManageVlanId == false)\r
+                                       {\r
+                                               t.VlanId = packet->VlanId;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               t.VlanId = 0;\r
+                                       }\r
+                                       entry = Search(hub->MacTable, &t);\r
+\r
+                                       if (entry == NULL)\r
+                                       {\r
+                                               // 古いエントリを削除する\r
+                                               DeleteExpiredMacTableEntry(hub->MacTable);\r
+\r
+                                               // 登録されていないので登録する\r
+                                               if (s->Policy->MaxMac != 0 || s->Policy->NoBridge)\r
+                                               {\r
+                                                       UINT i, num_mac_for_me = 0;\r
+                                                       UINT limited_count;\r
+\r
+                                                       // 現在このセッションで登録されている MAC アドレス数を調べる\r
+                                                       for (i = 0;i < LIST_NUM(hub->MacTable);i++)\r
+                                                       {\r
+                                                               MAC_TABLE_ENTRY *e = LIST_DATA(hub->MacTable, i);\r
+                                                               if (e->Session == s)\r
+                                                               {\r
+                                                                       num_mac_for_me++;\r
+                                                               }\r
+                                                       }\r
+\r
+                                                       limited_count = 0xffffffff;\r
+                                                       if (s->Policy->NoBridge)\r
+                                                       {\r
+                                                               limited_count = MIN(limited_count, MAC_MIN_LIMIT_COUNT);\r
+                                                       }\r
+                                                       if (s->Policy->MaxMac != 0)\r
+                                                       {\r
+                                                               limited_count = MIN(limited_count, s->Policy->MaxMac);\r
+                                                       }\r
+                                                       limited_count = MAX(limited_count, MAC_MIN_LIMIT_COUNT);\r
+\r
+                                                       if (num_mac_for_me >= limited_count)\r
+                                                       {\r
+                                                               // すでに登録されている MAC アドレス数が上限を超えている\r
+                                                               char mac_str[64];\r
+\r
+                                                               if (s != NULL)\r
+                                                               {\r
+                                                                       MacToStr(mac_str, sizeof(mac_str), packet->MacAddressSrc);\r
+                                                                       if (s->Policy->NoBridge)\r
+                                                                       {\r
+                                                                               HLog(hub, "LH_BRIDGE_LIMIT", s->Name, mac_str, num_mac_for_me, limited_count);\r
+                                                                       }\r
+                                                                       else\r
+                                                                       {\r
+                                                                               HLog(hub, "LH_MAC_LIMIT", s->Name, mac_str, num_mac_for_me, limited_count);\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               goto DISCARD_PACKET;    // パケット破棄\r
+                                                       }\r
+                                               }\r
+\r
+                                               if (LIST_NUM(hub->MacTable) >= MAX_MAC_TABLES)\r
+                                               {\r
+                                                       // MAC テーブルデータベースが最大件数を超えたので\r
+                                                       // 最も古いテーブルを削除する\r
+                                                       UINT i;\r
+                                                       UINT64 old_time = 0xffffffffffffffffULL;\r
+                                                       MAC_TABLE_ENTRY *old_entry = NULL;\r
+                                                       for (i = 0;i < LIST_NUM(hub->MacTable);i++)\r
+                                                       {\r
+                                                               MAC_TABLE_ENTRY *e = LIST_DATA(hub->MacTable, i);\r
+                                                               if (e->UpdatedTime <= old_time)\r
+                                                               {\r
+                                                                       old_time = e->CreatedTime;\r
+                                                                       old_entry = e;\r
+                                                               }\r
+                                                       }\r
+                                                       if (old_entry != NULL)\r
+                                                       {\r
+                                                               Delete(hub->MacTable, old_entry);\r
+                                                               Free(old_entry);\r
+                                                       }\r
+                                               }\r
+\r
+                                               entry = ZeroMalloc(sizeof(MAC_TABLE_ENTRY));\r
+                                               entry->HubPa = (HUB_PA *)s->PacketAdapter->Param;\r
+                                               Copy(entry->MacAddress, packet->MacAddressSrc, 6);\r
+                                               if (hub->Option->NoManageVlanId == false)\r
+                                               {\r
+                                                       entry->VlanId = packet->VlanId;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       entry->VlanId = 0;\r
+                                               }\r
+                                               entry->Session = s;\r
+                                               entry->UpdatedTime = entry->CreatedTime = now;\r
+\r
+                                               Insert(hub->MacTable, entry);\r
+\r
+                                               if (hub->Option->NoMacAddressLog == false)\r
+                                               {\r
+                                                       // デバッグ表示\r
+                                                       char mac_address[32];\r
+\r
+                                                       if (s != NULL)\r
+                                                       {\r
+                                                               MacToStr(mac_address, sizeof(mac_address), packet->MacAddressSrc);\r
+//                                                             Debug("Register MAC Address %s to Session %X.\n", mac_address, s);\r
+\r
+                                                               if (packet->VlanId == 0)\r
+                                                               {\r
+                                                                       HLog(hub, "LH_MAC_REGIST", s->Name, mac_address);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       HLog(hub, "LH_MAC_REGIST_VLAN", s->Name, mac_address, packet->VlanId);\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (entry->Session == s)\r
+                                               {\r
+                                                       // 既に登録されているので何もしない\r
+                                                       entry->UpdatedTime = now;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       // 既に登録されていて自分のセッション以外である\r
+                                                       if (s->Policy->CheckMac && (Cmp(packet->MacAddressSrc, hub->HubMacAddr, 6) != 0) &&\r
+                                                               ((entry->UpdatedTime + MAC_TABLE_EXCLUSIVE_TIME) >= now))\r
+                                                       {\r
+                                                               UCHAR *mac = packet->MacAddressSrc;\r
+                                                               if (hub->Option != NULL && hub->Option->FixForDLinkBPDU &&\r
+                                                                       (mac[0] == 0x00 && mac[1] == 0x80 && mac[2] == 0xc8 && mac[3] == 0x00 && mac[4] == 0x00 && mac[5] == 0x00) ||\r
+                                                                       (mac[0] == 0x00 && mac[1] == 0x0d && mac[2] == 0x88 && mac[3] == 0x00 && mac[4] == 0x00 && mac[5] == 0x00))\r
+                                                               {\r
+                                                                       // D-Link 用バグ対策。D-Link のスパニングツリーパケットは上記アドレスから送出される。\r
+                                                                       // ローカルブリッジ時の CheckMac オプションが悪影響を与えることがある。\r
+                                                                       // そこで例外的に処理。\r
+                                                                       UCHAR hash[MD5_SIZE];\r
+                                                                       UINT64 tick_diff = Tick64() - s->LastDLinkSTPPacketSendTick;\r
+\r
+                                                                       Hash(hash, packet->PacketData, packet->PacketSize, false);\r
+\r
+                                                                       if ((s->LastDLinkSTPPacketSendTick != 0) &&\r
+                                                                               (tick_diff < 750ULL) &&\r
+                                                                               (Cmp(hash, s->LastDLinkSTPPacketDataHash, MD5_SIZE) == 0))\r
+                                                                       {\r
+                                                                               // 750ms より前に同一パケットを送信した場合は破棄\r
+                                                                               Debug("D-Link Discard %u\n", (UINT)tick_diff);\r
+                                                                               goto DISCARD_PACKET;    // パケット破棄\r
+                                                                       }\r
+                                                                       else\r
+                                                                       {\r
+                                                                               goto UPDATE_FDB;\r
+                                                                       }\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       if (0)\r
+                                                                       {\r
+                                                                               // CheckMac ポリシーが有効な場合\r
+                                                                               // 別のセッションが同じ MAC アドレスを持っていることは禁止されている\r
+                                                                               // (2 バイト目が 0xAE の場合はこのチェックを行わない)\r
+                                                                               char mac_address[32];\r
+                                                                               BinToStr(mac_address, sizeof(mac_address), packet->MacAddressSrc, 6);\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               goto DISCARD_PACKET;    // パケット破棄\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               // MAC アドレステーブルのセッションと HUB_PA を書き換える\r
+                                                               char mac_address[32];\r
+UPDATE_FDB:\r
+                                                               BinToStr(mac_address, sizeof(mac_address), packet->MacAddressSrc, 6);\r
+\r
+                                                               entry->Session = s;\r
+                                                               entry->HubPa = (HUB_PA *)s->PacketAdapter->Param;\r
+                                                               entry->UpdatedTime = entry->CreatedTime = now;\r
+\r
+                                                               if (1)\r
+                                                               {\r
+                                                                       // デバッグ表示\r
+                                                                       char mac_address[32];\r
+\r
+                                                                       if (s != NULL)\r
+                                                                       {\r
+                                                                               MacToStr(mac_address, sizeof(mac_address), packet->MacHeader->SrcAddress);\r
+                                                                               Debug("Register MAC Address %s to Session %X.\n", mac_address, s);\r
+                                                                               if (packet->VlanId == 0)\r
+                                                                               {\r
+                                                                                       HLog(hub, "LH_MAC_REGIST", s->Name, mac_address);\r
+                                                                               }\r
+                                                                               else\r
+                                                                               {\r
+                                                                                       HLog(hub, "LH_MAC_REGIST_VLAN", s->Name, mac_address, packet->VlanId);\r
+                                                                               }\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               broadcast_mode = false;\r
+                               dest_pa = NULL;\r
+                               dest_session = NULL;\r
+\r
+                               if (packet->BroadcastPacket)\r
+                               {\r
+                                       // ブロードキャストパケット\r
+                                       broadcast_mode = true;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 宛先 MAC アドレスがテーブルに登録されているかどうか調べる\r
+                                       Copy(t.MacAddress, packet->MacAddressDest, 6);\r
+                                       if (hub->Option->NoManageVlanId == false)\r
+                                       {\r
+                                               t.VlanId = packet->VlanId;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               t.VlanId = 0;\r
+                                       }\r
+                                       entry = Search(hub->MacTable, &t);\r
+\r
+                                       if (entry == NULL)\r
+                                       {\r
+                                               // 宛先が見つからないのでブロードキャストする\r
+                                               broadcast_mode = true;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (entry->Session != s)\r
+                                               {\r
+                                                       // 宛先が見つかった\r
+                                                       dest_pa = entry->HubPa;\r
+                                                       dest_session = entry->Session;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       // 宛先が自分自身である不正なパケット\r
+                                                       goto DISCARD_PACKET;\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               if (s != NULL && hub->Option->NoIpTable == false)\r
+                               {\r
+                                       if (packet->TypeL3 == L3_IPV6)\r
+                                       {\r
+                                               // IPv6 パケット\r
+                                               IP ip;\r
+                                               bool b = true;\r
+                                               UINT ip_type;\r
+                                               bool dhcp_or_ra = false;\r
+\r
+                                               IPv6AddrToIP(&ip, &packet->L3.IPv6Header->SrcAddress);\r
+                                               ip_type = GetIPv6AddrType(&packet->L3.IPv6Header->SrcAddress);\r
+\r
+                                               if (!(ip_type & IPV6_ADDR_UNICAST))\r
+                                               {\r
+                                                       // マルチキャストアドレス\r
+                                                       b = false;\r
+                                               }\r
+                                               else if ((ip_type & IPV6_ADDR_LOOPBACK) || (ip_type & IPV6_ADDR_ZERO))\r
+                                               {\r
+                                                       // ループバックアドレスまたは All-Zero アドレス\r
+                                                       b = false;\r
+                                               }\r
+\r
+                                               if (packet->TypeL4 == L4_ICMPV6)\r
+                                               {\r
+                                                       if (packet->ICMPv6HeaderPacketInfo.Type == 133 ||\r
+                                                               packet->ICMPv6HeaderPacketInfo.Type == 134)\r
+                                                       {\r
+                                                               // ICMPv6 RS/RA\r
+                                                               dhcp_or_ra = true;\r
+                                                       }\r
+                                               }\r
+                                               else if (packet->TypeL4 == L4_UDP)\r
+                                               {\r
+                                                       if (Endian16(packet->L4.UDPHeader->DstPort) == 546 ||\r
+                                                               Endian16(packet->L4.UDPHeader->DstPort) == 547)\r
+                                                       {\r
+                                                               // DHCPv6\r
+                                                               dhcp_or_ra = true;\r
+                                                       }\r
+                                               }\r
+\r
+                                               if (IsHubMacAddress(packet->MacAddressSrc) &&\r
+                                                       IsHubIpAddress64(&packet->L3.IPv6Header->SrcAddress))\r
+                                               {\r
+                                                       // 仮想 HUB のポーリング用送信元アドレス\r
+                                                       b = false;\r
+                                               }\r
+\r
+                                               if (b)\r
+                                               {\r
+                                                       // ICMPv6 RS/RA および DHCPv6 以外のパケット\r
+                                                       IP_TABLE_ENTRY t, *e;\r
+\r
+                                                       Copy(&t.Ip, &ip, sizeof(IP));\r
+\r
+                                                       // 既存のテーブルに登録されているかどうかチェック\r
+                                                       e = Search(hub->IpTable, &t);\r
+\r
+                                                       if (e == NULL)\r
+                                                       {\r
+                                                               // 登録されていないので登録する\r
+                                                               if (s->Policy->NoRoutingV6 || s->Policy->MaxIPv6 != 0)\r
+                                                               {\r
+                                                                       UINT i, num_ip_for_me = 0;\r
+                                                                       UINT limited_count = 0xffffffff;\r
+\r
+                                                                       for (i = 0;i < LIST_NUM(hub->IpTable);i++)\r
+                                                                       {\r
+                                                                               IP_TABLE_ENTRY *e = LIST_DATA(hub->IpTable, i);\r
+\r
+                                                                               if (e->Session == s)\r
+                                                                               {\r
+                                                                                       if (IsIP6(&e->Ip))\r
+                                                                                       {\r
+                                                                                               num_ip_for_me++;\r
+                                                                                       }\r
+                                                                               }\r
+                                                                       }\r
+\r
+                                                                       if (s->Policy->NoRoutingV6)\r
+                                                                       {\r
+                                                                               limited_count = MIN(limited_count, IP_LIMIT_WHEN_NO_ROUTING_V6);\r
+                                                                       }\r
+                                                                       if (s->Policy->MaxIPv6 != 0)\r
+                                                                       {\r
+                                                                               limited_count = MIN(limited_count, s->Policy->MaxIPv6);\r
+                                                                       }\r
+                                                                       limited_count = MAX(limited_count, IP_MIN_LIMIT_COUNT_V6);\r
+\r
+                                                                       if (dhcp_or_ra)\r
+                                                                       {\r
+                                                                               limited_count = 0xffffffff;\r
+                                                                       }\r
+\r
+                                                                       if (num_ip_for_me >= limited_count)\r
+                                                                       {\r
+                                                                               // 使用できる IP アドレスの上限を超えているので\r
+                                                                               // このパケットを破棄する\r
+                                                                               char tmp[64];\r
+                                                                               IPToStr(tmp, sizeof(tmp), &ip);\r
+                                                                               if (s->Policy->NoRoutingV6 == false)\r
+                                                                               {\r
+                                                                                       HLog(hub, "LH_IP_LIMIT", s->Name, tmp, num_ip_for_me, limited_count);\r
+                                                                               }\r
+                                                                               else\r
+                                                                               {\r
+                                                                                       HLog(hub, "LH_ROUTING_LIMIT", s->Name, tmp, num_ip_for_me, limited_count);\r
+                                                                               }\r
+                                                                               goto DISCARD_PACKET;\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               if (IsIPManagementTargetForHUB(&ip, hub))\r
+                                                               {\r
+                                                                       // エントリ作成\r
+                                                                       e = ZeroMalloc(sizeof(IP_TABLE_ENTRY));\r
+                                                                       e->CreatedTime = e->UpdatedTime = now;\r
+                                                                       e->DhcpAllocated = false;\r
+                                                                       Copy(&e->Ip, &ip, sizeof(IP));\r
+                                                                       Copy(e->MacAddress, packet->MacAddressSrc, 6);\r
+                                                                       e->Session = s;\r
+\r
+                                                                       DeleteExpiredIpTableEntry(hub->IpTable);\r
+\r
+                                                                       if (LIST_NUM(hub->IpTable) >= MAX_IP_TABLES)\r
+                                                                       {\r
+                                                                               // 古い IP テーブルエントリを削除する\r
+                                                                               DeleteOldIpTableEntry(hub->IpTable);\r
+                                                                       }\r
+\r
+                                                                       Insert(hub->IpTable, e);\r
+\r
+                                                                       if (0)\r
+                                                                       {\r
+                                                                               char ip_address[64];\r
+                                                                               IPToStr(ip_address, sizeof(ip_address), &ip);\r
+                                                                               Debug("Registered IP Address %s to Session %X.\n",\r
+                                                                                       ip_address, s);\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               if (e->Session == s)\r
+                                                               {\r
+                                                                       // 自分のセッションであるので何もしない\r
+                                                                       // 更新日時を上書きする\r
+                                                                       e->UpdatedTime = now;\r
+                                                                       Copy(e->MacAddress, packet->MacAddressSrc, 6);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       // 別のセッションが以前この IP アドレスを使っていた\r
+                                                                       if ((s->Policy->CheckIPv6) &&\r
+                                                                               ((e->UpdatedTime + IP_TABLE_EXCLUSIVE_TIME) >= now))\r
+                                                                       {\r
+                                                                               // 他のセッションがこの IP アドレスを使っているので\r
+                                                                               // パケットを破棄する\r
+                                                                               char ip_address[32];\r
+                                                                               IPToStr(ip_address, sizeof(ip_address), &ip);\r
+\r
+                                                                               Debug("IP Address %s is Already used by Session %X.\n",\r
+                                                                                       ip_address, s);\r
+\r
+                                                                               HLog(hub, "LH_IP_CONFLICT", s->Name, ip_address, e->Session->Name);\r
+\r
+                                                                               goto DISCARD_PACKET;\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               if (\r
+                                       (s != NULL) &&\r
+                                       (hub->Option->NoIpTable == false) &&\r
+                                       (\r
+                                               (packet->TypeL3 == L3_IPV4 ||\r
+                                                       (packet->TypeL3 == L3_ARPV4 && packet->L3.ARPv4Header->HardwareSize == 6 &&\r
+                                                       Endian16(packet->L3.ARPv4Header->HardwareType) == ARP_HARDWARE_TYPE_ETHERNET &&\r
+                                                       packet->L3.ARPv4Header->ProtocolSize == 4 &&\r
+                                                       Endian16(packet->L3.ARPv4Header->ProtocolType) == 0x0800)\r
+                                               ) &&\r
+                                               (packet->TypeL7 != L7_DHCPV4)\r
+                                       )\r
+                                       ) // DHCP パケット以外\r
+                               {\r
+                                       // IP パケットまたは ARP 応答パケットの場合は IP アドレステーブルを検索する\r
+                                       IP_TABLE_ENTRY t, *e;\r
+                                       IP ip;\r
+                                       UINT uint_ip = 0;\r
+\r
+                                       if (packet->TypeL3 == L3_IPV4)\r
+                                       {\r
+                                               uint_ip = packet->L3.IPv4Header->SrcIP;\r
+                                       }\r
+                                       else if (packet->TypeL3 == L3_ARPV4)\r
+                                       {\r
+                                               uint_ip = packet->L3.ARPv4Header->SrcIP;\r
+                                       }\r
+\r
+                                       if (uint_ip != 0 && uint_ip != 0xffffffff && !(IsHubIpAddress32(uint_ip) && IsHubMacAddress(packet->MacAddressSrc)))\r
+                                       {\r
+                                               UINTToIP(&ip, uint_ip);\r
+                                               Copy(&t.Ip, &ip, sizeof(IP));\r
+\r
+                                               // 既存のテーブルに登録されているかどうかチェック\r
+                                               e = Search(hub->IpTable, &t);\r
+\r
+                                               if (e == NULL)\r
+                                               {\r
+                                                       // 登録されていないので登録する\r
+                                                       if (s->Policy->DHCPForce)\r
+                                                       {\r
+                                                               char ipstr[MAX_SIZE];\r
+\r
+                                                               // DHCP サーバーによって割り当てられた IP アドレスではない\r
+                                                               // のでこのパケットを破棄する\r
+                                                               IPToStr32(ipstr, sizeof(ipstr), uint_ip);\r
+                                                               HLog(hub, "LH_DHCP_FORCE", s->Name, ipstr);\r
+                                                               goto DISCARD_PACKET;\r
+                                                       }\r
+\r
+       //                                              if (packet->TypeL3 == L3_ARPV4)\r
+                                                       {\r
+                                                               // すでにこのセッションで登録されている個数を調べる\r
+                                                               if (s->Policy->NoRouting || s->Policy->MaxIP != 0)\r
+                                                               {\r
+                                                                       UINT i, num_ip_for_me = 0;\r
+                                                                       UINT limited_count = 0xffffffff;\r
+\r
+                                                                       for (i = 0;i < LIST_NUM(hub->IpTable);i++)\r
+                                                                       {\r
+                                                                               IP_TABLE_ENTRY *e = LIST_DATA(hub->IpTable, i);\r
+\r
+                                                                               if (e->Session == s)\r
+                                                                               {\r
+                                                                                       if (IsIP4(&e->Ip))\r
+                                                                                       {\r
+                                                                                               num_ip_for_me++;\r
+                                                                                       }\r
+                                                                               }\r
+                                                                       }\r
+\r
+                                                                       if (s->Policy->NoRouting)\r
+                                                                       {\r
+                                                                               limited_count = MIN(limited_count, IP_MIN_LIMIT_COUNT);\r
+                                                                       }\r
+                                                                       if (s->Policy->MaxIP != 0)\r
+                                                                       {\r
+                                                                               limited_count = MIN(limited_count, s->Policy->MaxIP);\r
+                                                                       }\r
+                                                                       limited_count = MAX(limited_count, IP_MIN_LIMIT_COUNT);\r
+\r
+                                                                       if (num_ip_for_me >= limited_count)\r
+                                                                       {\r
+                                                                               // 使用できる IP アドレスの上限を超えているので\r
+                                                                               // このパケットを破棄する\r
+                                                                               char tmp[64];\r
+                                                                               IPToStr32(tmp, sizeof(tmp), uint_ip);\r
+                                                                               if (s->Policy->NoRouting == false)\r
+                                                                               {\r
+                                                                                       HLog(hub, "LH_IP_LIMIT", s->Name, tmp, num_ip_for_me, limited_count);\r
+                                                                               }\r
+                                                                               else\r
+                                                                               {\r
+                                                                                       HLog(hub, "LH_ROUTING_LIMIT", s->Name, tmp, num_ip_for_me, limited_count);\r
+                                                                               }\r
+                                                                               goto DISCARD_PACKET;\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               if (IsIPManagementTargetForHUB(&ip, hub))\r
+                                                               {\r
+                                                                       // エントリ作成\r
+                                                                       e = ZeroMalloc(sizeof(IP_TABLE_ENTRY));\r
+                                                                       e->CreatedTime = e->UpdatedTime = now;\r
+                                                                       e->DhcpAllocated = false;\r
+                                                                       Copy(&e->Ip, &ip, sizeof(IP));\r
+                                                                       Copy(e->MacAddress, packet->MacAddressSrc, 6);\r
+                                                                       e->Session = s;\r
+\r
+                                                                       DeleteExpiredIpTableEntry(hub->IpTable);\r
+\r
+                                                                       if (LIST_NUM(hub->IpTable) >= MAX_IP_TABLES)\r
+                                                                       {\r
+                                                                               // 古い IP テーブルエントリを削除する\r
+                                                                               DeleteOldIpTableEntry(hub->IpTable);\r
+                                                                       }\r
+\r
+                                                                       Insert(hub->IpTable, e);\r
+\r
+                                                                       if (0)\r
+                                                                       {\r
+                                                                               char ip_address[64];\r
+                                                                               IPToStr(ip_address, sizeof(ip_address), &ip);\r
+                                                                               Debug("Registered IP Address %s to Session %X.\n",\r
+                                                                                       ip_address, s);\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       if (e->Session == s)\r
+                                                       {\r
+                                                               // 自分のセッションであるので何もしない\r
+                                                               // 更新日時を上書きする\r
+                                                               e->UpdatedTime = now;\r
+                                                               Copy(e->MacAddress, packet->MacAddressSrc, 6);\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               // 別のセッションが以前この IP アドレスを使っていた\r
+                                                               if ((s->Policy->CheckIP || s->Policy->DHCPForce) &&\r
+                                                                       ((e->UpdatedTime + IP_TABLE_EXCLUSIVE_TIME) >= now))\r
+                                                               {\r
+                                                                       // 他のセッションがこの IP アドレスを使っているので\r
+                                                                       // パケットを破棄する\r
+                                                                       char ip_address[32];\r
+                                                                       IPToStr(ip_address, sizeof(ip_address), &ip);\r
+\r
+                                                                       Debug("IP Address %s is Already used by Session %X.\n",\r
+                                                                               ip_address, s);\r
+\r
+                                                                       HLog(hub, "LH_IP_CONFLICT", s->Name, ip_address, e->Session->Name);\r
+\r
+                                                                       goto DISCARD_PACKET;\r
+                                                               }\r
+\r
+                                                               if (s->Policy->DHCPForce)\r
+                                                               {\r
+                                                                       if (e->DhcpAllocated == false)\r
+                                                                       {\r
+                                                                               char ipstr[MAX_SIZE];\r
+\r
+                                                                               // DHCP サーバーによって割り当てられた IP アドレスではない\r
+                                                                               // のでこのパケットを破棄する\r
+                                                                               IPToStr32(ipstr, sizeof(ipstr), uint_ip);\r
+                                                                               HLog(hub, "LH_DHCP_FORCE", s->Name, ipstr);\r
+                                                                               goto DISCARD_PACKET;\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               // エントリを上書きする\r
+                                                               e->Session = s;\r
+                                                               e->UpdatedTime = now;\r
+                                                               Copy(e->MacAddress, packet->MacAddressSrc, 6);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               if (s != NULL && broadcast_mode)\r
+                               {\r
+                                       // ブロードキャストパケットのループや\r
+                                       // 大量のブロードキャストの発生を防止するため\r
+                                       // Broadcast Storm 回避アルゴリズムを呼び出す\r
+                                       if (CheckBroadcastStorm(s, packet) == false)\r
+                                       {\r
+                                               goto DISCARD_PACKET;\r
+                                       }\r
+                               }\r
+\r
+                               // トラフィック加算\r
+                               Zero(&traffic, sizeof(traffic));\r
+                               if (packet->BroadcastPacket)\r
+                               {\r
+                                       // ブロードキャスト\r
+                                       traffic.Send.BroadcastBytes = packet->PacketSize;\r
+                                       traffic.Send.BroadcastCount = 1;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // ユニキャスト\r
+                                       traffic.Send.UnicastBytes = packet->PacketSize;\r
+                                       traffic.Send.UnicastCount = 1;\r
+                               }\r
+\r
+                               if (s != NULL)\r
+                               {\r
+                                       AddTrafficForSession(s, &traffic);\r
+                               }\r
+\r
+                               // トラフィック情報の Send と Recv を反転\r
+                               Copy(&traffic.Recv, &traffic.Send, sizeof(TRAFFIC_ENTRY));\r
+                               Zero(&traffic.Send, sizeof(TRAFFIC_ENTRY));\r
+\r
+                               // HUB のモニタポートにこのパケットをブロードキャストする\r
+                               if (hub->MonitorList->num_item != 0)\r
+                               {\r
+                                       LockList(hub->MonitorList);\r
+                                       {\r
+                                               UINT i;\r
+                                               void *data;\r
+                                               UINT size = packet->PacketSize;\r
+                                               for (i = 0;i < LIST_NUM(hub->MonitorList);i++)\r
+                                               {\r
+                                                       SESSION *monitor_session = (SESSION *)LIST_DATA(hub->MonitorList, i);\r
+\r
+                                                       // パケットをフラッディング\r
+                                                       if (monitor_session->PacketAdapter->Param != NULL)\r
+                                                       {\r
+                                                               data = MallocFast(size);\r
+                                                               Copy(data, packet->PacketData, size);\r
+                                                               StorePacketToHubPa((HUB_PA *)monitor_session->PacketAdapter->Param,\r
+                                                                       s, data, size, packet);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       UnlockList(hub->MonitorList);\r
+                               }\r
+\r
+                               if (broadcast_mode == false)\r
+                               {\r
+                                       if (dest_pa != NULL)\r
+                                       {\r
+                                               if (dest_session->Policy->NoIPv6DefaultRouterInRA ||\r
+                                                       (dest_session->Policy->NoIPv6DefaultRouterInRAWhenIPv6 && dest_session->IPv6Session) ||\r
+                                                       (hub->Option->NoIPv6DefaultRouterInRAWhenIPv6 && dest_session->IPv6Session))\r
+                                               {\r
+                                                       DeleteIPv6DefaultRouterInRA(packet);\r
+                                               }\r
+                                               if (dest_session->Policy->RSandRAFilter)\r
+                                               {\r
+                                                       if (packet->TypeL3 == L3_IPV6 &&\r
+                                                               packet->TypeL4 == L4_ICMPV6 &&\r
+                                                               (packet->ICMPv6HeaderPacketInfo.Type == ICMPV6_TYPE_ROUTER_SOLICIATION ||\r
+                                                                packet->ICMPv6HeaderPacketInfo.Type == ICMPV6_TYPE_ROUTER_ADVERTISEMENT))\r
+                                                       {\r
+                                                               goto DISCARD_UNICAST_PACKET;\r
+                                                       }\r
+                                               }\r
+                                               if (dest_session->Policy->DHCPFilter)\r
+                                               {\r
+                                                       if (packet->TypeL3 == L3_IPV4 &&\r
+                                                               packet->TypeL4 == L4_UDP &&\r
+                                                               packet->TypeL7 == L7_DHCPV4)\r
+                                                       {\r
+                                                               goto DISCARD_UNICAST_PACKET;\r
+                                                       }\r
+                                               }\r
+                                               if (dest_session->Policy->DHCPv6Filter)\r
+                                               {\r
+                                                       if (packet->TypeL3 == L3_IPV6 &&\r
+                                                               packet->TypeL4 == L4_UDP &&\r
+                                                               (Endian16(packet->L4.UDPHeader->DstPort) == 546 || Endian16(packet->L4.UDPHeader->DstPort) == 547))\r
+                                                       {\r
+                                                               goto DISCARD_UNICAST_PACKET;\r
+                                                       }\r
+                                               }\r
+                                               if (dest_session->Policy->ArpDhcpOnly)\r
+                                               {\r
+                                                       if (packet->BroadcastPacket)\r
+                                                       {\r
+                                                               bool b = true;\r
+\r
+                                                               if (packet->TypeL3 == L3_IPV4 &&\r
+                                                                       packet->TypeL4 == L4_UDP &&\r
+                                                                       packet->TypeL7 == L7_DHCPV4)\r
+                                                               {\r
+                                                                       b = false;\r
+                                                               }\r
+                                                               else if (packet->TypeL3 == L3_ARPV4)\r
+                                                               {\r
+                                                                       b = false;\r
+                                                               }\r
+                                                               else if (packet->TypeL3 == L3_IPV6 &&\r
+                                                                       packet->TypeL4 == L4_UDP &&\r
+                                                                       (Endian16(packet->L4.UDPHeader->DstPort) == 546 || Endian16(packet->L4.UDPHeader->DstPort) == 547))\r
+                                                               {\r
+                                                                       b = false;\r
+                                                               }\r
+                                                               else if (packet->TypeL3 == L3_IPV6 &&\r
+                                                                       packet->TypeL4 == L4_ICMPV6)\r
+                                                               {\r
+                                                                       b = false;\r
+                                                               }\r
+\r
+                                                               if (b)\r
+                                                               {\r
+                                                                       goto DISCARD_UNICAST_PACKET;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                               if (dest_session->Policy->FilterIPv4)\r
+                                               {\r
+                                                       if (packet->TypeL3 == L3_IPV4 || packet->TypeL3 == L3_ARPV4)\r
+                                                       {\r
+                                                               goto DISCARD_UNICAST_PACKET;\r
+                                                       }\r
+                                               }\r
+                                               if (dest_session->Policy->FilterIPv6)\r
+                                               {\r
+                                                       if (packet->TypeL3 == L3_IPV6)\r
+                                                       {\r
+                                                               goto DISCARD_UNICAST_PACKET;\r
+                                                       }\r
+                                               }\r
+                                               if (dest_session->Policy->FilterNonIP)\r
+                                               {\r
+                                                       if (packet->TypeL3 != L3_IPV4 && packet->TypeL3 != L3_ARPV4 && packet->TypeL3 != L3_IPV6)\r
+                                                       {\r
+                                                               goto DISCARD_UNICAST_PACKET;\r
+                                                       }\r
+                                               }\r
+\r
+                                               if (s != NULL &&\r
+                                                       (packet->BroadcastPacket == false &&\r
+                                                       s->Policy->PrivacyFilter &&\r
+                                                       dest_session->Policy->PrivacyFilter)\r
+                                                       )\r
+                                               {\r
+                                                       // プライバシーフィルタ\r
+                                                       if (packet->TypeL3 != L3_ARPV4)\r
+                                                       {\r
+                                                               goto DISCARD_UNICAST_PACKET;\r
+                                                       }\r
+                                               }\r
+\r
+                                               if (s != NULL)\r
+                                               {\r
+                                                       if (Cmp(packet->MacAddressSrc, s->Hub->HubMacAddr, 6) == 0 ||\r
+                                                               Cmp(packet->MacAddressDest, s->Hub->HubMacAddr, 6) == 0)\r
+                                                       {\r
+                                                               goto DISCARD_UNICAST_PACKET;\r
+                                                       }\r
+                                               }\r
+\r
+                                               // パケットログをとる\r
+                                               if (s != NULL)\r
+                                               {\r
+                                                       PacketLog(s->Hub, s, dest_session, packet);\r
+                                               }\r
+\r
+                                               // 宛先 HUB_PA にストアする\r
+                                               StorePacketToHubPa(dest_pa, s, packet->PacketData, packet->PacketSize, packet);\r
+\r
+                                               // トラフィック加算\r
+                                               AddTrafficForSession(dest_session, &traffic);\r
+                                       }\r
+                                       else\r
+                                       {\r
+DISCARD_UNICAST_PACKET:\r
+                                               Free(packet->PacketData);\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       // すべてのセッションにストアする\r
+                                       LockList(hub->SessionList);\r
+                                       {\r
+                                               UINT i, num = LIST_NUM(hub->SessionList);\r
+                                               for (i = 0;i < num;i++)\r
+                                               {\r
+                                                       SESSION *dest_session = LIST_DATA(hub->SessionList, i);\r
+                                                       HUB_PA *dest_pa = (HUB_PA *)dest_session->PacketAdapter->Param;\r
+                                                       bool discard = false;\r
+\r
+                                                       if (dest_session != s)\r
+                                                       {\r
+                                                               bool delete_default_router_in_ra = false;\r
+\r
+                                                               if (dest_session->VLanId != 0 && packet->TypeL3 == L3_TAGVLAN &&\r
+                                                                       packet->VlanId != dest_session->VLanId)\r
+                                                               {\r
+                                                                       discard = true;\r
+                                                               }\r
+\r
+                                                               if (dest_session->Policy->NoIPv6DefaultRouterInRA ||\r
+                                                                       (dest_session->Policy->NoIPv6DefaultRouterInRAWhenIPv6 && dest_session->IPv6Session) ||\r
+                                                                       (hub->Option->NoIPv6DefaultRouterInRAWhenIPv6 && dest_session->IPv6Session))\r
+                                                               {\r
+                                                                       if (packet->TypeL3 == L3_IPV6 && packet->TypeL4 == L4_ICMPV6 &&\r
+                                                                               (packet->ICMPv6HeaderPacketInfo.Type == ICMPV6_TYPE_ROUTER_ADVERTISEMENT))\r
+                                                                       {\r
+                                                                               if (packet->ICMPv6HeaderPacketInfo.Headers.RouterAdvertisementHeader->Lifetime != 0)\r
+                                                                               {\r
+                                                                                       delete_default_router_in_ra = true;\r
+                                                                               }\r
+                                                                       }\r
+                                                               }\r
+                                                               if (dest_session->Policy->RSandRAFilter)\r
+                                                               {\r
+                                                                       if (packet->TypeL3 == L3_IPV6 &&\r
+                                                                               packet->TypeL4 == L4_ICMPV6 &&\r
+                                                                               (packet->ICMPv6HeaderPacketInfo.Type == ICMPV6_TYPE_ROUTER_SOLICIATION ||\r
+                                                                                packet->ICMPv6HeaderPacketInfo.Type == ICMPV6_TYPE_ROUTER_ADVERTISEMENT))\r
+                                                                       {\r
+                                                                               discard = true;\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               if (dest_session->Policy->DHCPFilter)\r
+                                                               {\r
+                                                                       if (packet->TypeL3 == L3_IPV4 &&\r
+                                                                               packet->TypeL4 == L4_UDP &&\r
+                                                                               packet->TypeL7 == L7_DHCPV4)\r
+                                                                       {\r
+                                                                               discard = true;\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               if (dest_session->Policy->DHCPv6Filter)\r
+                                                               {\r
+                                                                       if (packet->TypeL3 == L3_IPV6 &&\r
+                                                                               packet->TypeL4 == L4_UDP &&\r
+                                                                               (Endian16(packet->L4.UDPHeader->DstPort) == 546 || Endian16(packet->L4.UDPHeader->DstPort) == 547))\r
+                                                                       {\r
+                                                                               discard = true;\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               if (dest_session->Policy->ArpDhcpOnly)\r
+                                                               {\r
+                                                                       if (packet->BroadcastPacket)\r
+                                                                       {\r
+                                                                               bool b = true;\r
+\r
+                                                                               if (packet->TypeL3 == L3_IPV4 &&\r
+                                                                                       packet->TypeL4 == L4_UDP &&\r
+                                                                                       packet->TypeL7 == L7_DHCPV4)\r
+                                                                               {\r
+                                                                                       b = false;\r
+                                                                               }\r
+                                                                               else if (packet->TypeL3 == L3_ARPV4)\r
+                                                                               {\r
+                                                                                       b = false;\r
+                                                                               }\r
+                                                                               else if (packet->TypeL3 == L3_IPV6 &&\r
+                                                                                       packet->TypeL4 == L4_UDP &&\r
+                                                                                       (Endian16(packet->L4.UDPHeader->DstPort) == 546 || Endian16(packet->L4.UDPHeader->DstPort) == 547))\r
+                                                                               {\r
+                                                                                       b = false;\r
+                                                                               }\r
+                                                                               else if (packet->TypeL3 == L3_IPV6 &&\r
+                                                                                       packet->TypeL4 == L4_ICMPV6)\r
+                                                                               {\r
+                                                                                       b = false;\r
+                                                                               }\r
+\r
+                                                                               if (discard == false)\r
+                                                                               {\r
+                                                                                       discard = b;\r
+                                                                               }\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               if (dest_session->Policy->FilterIPv4)\r
+                                                               {\r
+                                                                       if (packet->TypeL3 == L3_IPV4 || packet->TypeL3 == L3_ARPV4)\r
+                                                                       {\r
+                                                                               discard = true;\r
+                                                                       }\r
+                                                               }\r
+                                                               if (dest_session->Policy->FilterIPv6)\r
+                                                               {\r
+                                                                       if (packet->TypeL3 == L3_IPV6)\r
+                                                                       {\r
+                                                                               discard = true;\r
+                                                                       }\r
+                                                               }\r
+                                                               if (dest_session->Policy->FilterNonIP)\r
+                                                               {\r
+                                                                       if (packet->TypeL3 != L3_IPV4 && packet->TypeL3 != L3_ARPV4 && packet->TypeL3 != L3_IPV6)\r
+                                                                       {\r
+                                                                               discard = true;\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               if (s != NULL &&\r
+                                                                       (packet->BroadcastPacket == false &&\r
+                                                                       s->Policy->PrivacyFilter &&\r
+                                                                       dest_session->Policy->PrivacyFilter)\r
+                                                                       )\r
+                                                               {\r
+                                                                       // プライバシーフィルタ\r
+                                                                       if (packet->TypeL3 != L3_ARPV4)\r
+                                                                       {\r
+                                                                               discard = true;\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               if (s != NULL)\r
+                                                               {\r
+                                                                       if (Cmp(packet->MacAddressSrc, s->Hub->HubMacAddr, 6) == 0 ||\r
+                                                                               Cmp(packet->MacAddressDest, s->Hub->HubMacAddr, 6) == 0)\r
+                                                                       {\r
+                                                                               discard = true;\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               if (discard == false && dest_pa != NULL)\r
+                                                               {\r
+                                                                       // 自分以外のセッションにストア\r
+                                                                       data = MallocFast(packet->PacketSize);\r
+                                                                       Copy(data, packet->PacketData, packet->PacketSize);\r
+                                                                       size = packet->PacketSize;\r
+\r
+                                                                       if (delete_default_router_in_ra)\r
+                                                                       {\r
+                                                                               PKT *pkt2 = ParsePacket(data, size);\r
+\r
+                                                                               DeleteIPv6DefaultRouterInRA(pkt2);\r
+\r
+                                                                               FreePacket(pkt2);\r
+                                                                       }\r
+\r
+                                                                       StorePacketToHubPa(dest_pa, s, data, size, packet);\r
+\r
+                                                                       // トラフィック加算\r
+                                                                       AddTrafficForSession(dest_session, &traffic);\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       UnlockList(hub->SessionList);\r
+\r
+                                       // パケットログをとる\r
+                                       if (s != NULL)\r
+                                       {\r
+                                               PacketLog(s->Hub, s, NULL, packet);\r
+                                       }\r
+\r
+                                       Free(packet->PacketData);\r
+                               }\r
+                               FreePacket(packet);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(hub->MacTable);\r
+}\r
+\r
+// 指定された IP アドレスがプライベート IP アドレスかどうかチェックする\r
+bool IsIPPrivate(IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ip->addr[0] == 10)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (ip->addr[0] == 172)\r
+       {\r
+               if (ip->addr[1] >= 16 && ip->addr[1] <= 31)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       if (ip->addr[0] == 192 && ip->addr[1] == 168)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (ip->addr[0] == 2)\r
+       {\r
+               // Special !!\r
+               return true;\r
+       }\r
+\r
+       if (ip->addr[0] == 169 && ip->addr[1] == 254)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// 指定された IP アドレスが仮想 HUB による管理対象かどうか確認する\r
+bool IsIPManagementTargetForHUB(IP *ip, HUB *hub)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL || hub == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (hub->Option == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (IsIP4(ip))\r
+       {\r
+               if (hub->Option->ManageOnlyPrivateIP)\r
+               {\r
+                       if (IsIPPrivate(ip) == false)\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (hub->Option->ManageOnlyLocalUnicastIPv6)\r
+               {\r
+                       UINT ip_type = GetIPAddrType6(ip);\r
+\r
+                       if (!(ip_type & IPV6_ADDR_LOCAL_UNICAST))\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 古い IP テーブルエントリを削除する\r
+void DeleteOldIpTableEntry(LIST *o)\r
+{\r
+       UINT i;\r
+       UINT64 oldest_time = 0xffffffffffffffffULL;\r
+       IP_TABLE_ENTRY *old = NULL;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               IP_TABLE_ENTRY *e = LIST_DATA(o, i);\r
+\r
+               if (e->UpdatedTime <= oldest_time)\r
+               {\r
+                       old = e;\r
+               }\r
+       }\r
+\r
+       if (old != NULL)\r
+       {\r
+               Delete(o, old);\r
+               Free(old);\r
+       }\r
+}\r
+\r
+// ストームリストの追加\r
+STORM *AddStormList(HUB_PA *pa, UCHAR *mac_address, IP *src_ip, IP *dest_ip)\r
+{\r
+       STORM *s;\r
+       // 引数チェック\r
+       if (pa == NULL || mac_address == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       s = ZeroMalloc(sizeof(STORM));\r
+       if (src_ip != NULL)\r
+       {\r
+               Copy(&s->SrcIp, src_ip, sizeof(IP));\r
+       }\r
+       if (dest_ip != NULL)\r
+       {\r
+               Copy(&s->DestIp, dest_ip, sizeof(IP));\r
+       }\r
+       Copy(s->MacAddress, mac_address, 6);\r
+\r
+       Insert(pa->StormList, s);\r
+\r
+       return s;\r
+}\r
+\r
+// ストームリストのサーチ\r
+STORM *SearchStormList(HUB_PA *pa, UCHAR *mac_address, IP *src_ip, IP *dest_ip)\r
+{\r
+       STORM t, *s;\r
+       // 引数チェック\r
+       if (pa == NULL || mac_address == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (src_ip != NULL)\r
+       {\r
+               Copy(&t.SrcIp, src_ip, sizeof(IP));\r
+       }\r
+       if (dest_ip != NULL)\r
+       {\r
+               Copy(&t.DestIp, dest_ip, sizeof(IP));\r
+       }\r
+       Copy(t.MacAddress, mac_address, 6);\r
+\r
+       s = Search(pa->StormList, &t);\r
+\r
+       return s;\r
+}\r
+\r
+// パケットを宛先の HUB_PA にストアする\r
+void StorePacketToHubPa(HUB_PA *dest, SESSION *src, void *data, UINT size, PKT *packet)\r
+{\r
+       BLOCK *b;\r
+       // 引数チェック\r
+       if (dest == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (size < 14)\r
+       {\r
+               Free(data);\r
+               return;\r
+       }\r
+\r
+       if (src != NULL)\r
+       {\r
+               // フォワード用のアクセスリスト適用\r
+               if (ApplyAccessListToForwardPacket(src->Hub, src, dest->Session, packet) == false)\r
+               {\r
+                       Free(data);\r
+                       return;\r
+               }\r
+       }\r
+\r
+       if (src != NULL)\r
+       {\r
+               if (dest->Session->Policy->MaxDownload != 0)\r
+               {\r
+                       // トラフィック制限\r
+                       if (packet != NULL && IsMostHighestPriorityPacket(dest->Session, packet) == false)\r
+                       {\r
+                               TRAFFIC_LIMITER *tr = &dest->DownloadLimiter;\r
+                               IntoTrafficLimiter(tr, packet);\r
+\r
+                               if ((tr->Value * (UINT64)1000 / (UINT64)LIMITER_SAMPLING_SPAN) > dest->Session->Policy->MaxDownload)\r
+                               {\r
+                                       // 制限する\r
+                                       Free(data);\r
+                                       return;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (src != NULL && src->Hub != NULL && src->Hub->Option != NULL && src->Hub->Option->FixForDLinkBPDU)\r
+       {\r
+               // D-Link バグ対策\r
+               UCHAR *mac = packet->MacAddressSrc;\r
+               if ((mac[0] == 0x00 && mac[1] == 0x80 && mac[2] == 0xc8 && mac[3] == 0x00 && mac[4] == 0x00 && mac[5] == 0x00) ||\r
+                       (mac[0] == 0x00 && mac[1] == 0x0d && mac[2] == 0x88 && mac[3] == 0x00 && mac[4] == 0x00 && mac[5] == 0x00))\r
+               {\r
+                       SESSION *session = dest->Session;\r
+\r
+                       if (session != NULL)\r
+                       {\r
+                               if (session->Policy != NULL && session->Policy->CheckMac)\r
+                               {\r
+                                       UCHAR hash[MD5_SIZE];\r
+                                       Hash(hash, packet->PacketData, packet->PacketSize, false);\r
+\r
+                                       Copy(session->LastDLinkSTPPacketDataHash, hash, MD5_SIZE);\r
+                                       session->LastDLinkSTPPacketSendTick = Tick64();\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       // VLAN タグを除去\r
+       if (dest->Session != NULL && dest->Session->VLanId != 0)\r
+       {\r
+               if (VLanRemoveTag(&data, &size, dest->Session->VLanId) == false)\r
+               {\r
+                       Free(data);\r
+                       return;\r
+               }\r
+       }\r
+\r
+       // ブロック作成\r
+       b = NewBlock(data, size, 0);\r
+\r
+       LockQueue(dest->PacketQueue);\r
+       {\r
+               // キューの数を測定\r
+               if ((dest->PacketQueue->num_item < MAX_STORED_QUEUE_NUM) ||\r
+                       (((UCHAR *)data)[12] == 'S' && ((UCHAR *)data)[13] == 'E'))\r
+               {\r
+                       // ストア\r
+                       InsertQueue(dest->PacketQueue, b);\r
+               }\r
+               else\r
+               {\r
+                       // パケット破棄\r
+                       FreeBlock(b);\r
+               }\r
+       }\r
+       UnlockQueue(dest->PacketQueue);\r
+\r
+       // キャンセルの発行\r
+       if (src != NULL)\r
+       {\r
+               AddCancelList(src->CancelList, dest->Cancel);\r
+       }\r
+       else\r
+       {\r
+               Cancel(dest->Cancel);\r
+       }\r
+}\r
+\r
+// IPv6 ルータ広告からデフォルトルータ指定を削除\r
+bool DeleteIPv6DefaultRouterInRA(PKT *p)\r
+{\r
+       if (p->TypeL3 == L3_IPV6 && p->TypeL4 == L4_ICMPV6 &&\r
+               (p->ICMPv6HeaderPacketInfo.Type == ICMPV6_TYPE_ROUTER_ADVERTISEMENT))\r
+       {\r
+               if (p->ICMPv6HeaderPacketInfo.Headers.RouterAdvertisementHeader->Lifetime != 0)\r
+               {\r
+                       p->ICMPv6HeaderPacketInfo.Headers.RouterAdvertisementHeader->Lifetime = 0;\r
+\r
+                       p->L4.ICMPHeader->Checksum = 0;\r
+                       p->L4.ICMPHeader->Checksum =\r
+                               CalcChecksumForIPv6(&p->L3.IPv6Header->SrcAddress,\r
+                                       &p->L3.IPv6Header->DestAddress, IP_PROTO_ICMPV6,\r
+                                       p->L4.ICMPHeader, p->IPv6HeaderPacketInfo.PayloadSize);\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// ポリシーによるパケットフィルタ\r
+bool StorePacketFilterByPolicy(SESSION *s, PKT *p)\r
+{\r
+       POLICY *pol;\r
+       HUB *hub;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       hub = s->Hub;\r
+\r
+       // ポリシー\r
+       pol = s->Policy;\r
+\r
+       // サーバーとしての動作を禁止する\r
+       if (pol->NoServer)\r
+       {\r
+               if (p->TypeL3 == L3_IPV4)\r
+               {\r
+                       if (p->TypeL4 == L4_TCP)\r
+                       {\r
+                               UCHAR flag = p->L4.TCPHeader->Flag;\r
+                               if ((flag & TCP_SYN) && (flag & TCP_ACK))\r
+                               {\r
+                                       char ip1[64], ip2[64];\r
+                                       // SYN + ACK パケットを送信させない\r
+                                       Debug("pol->NoServer: Discard SYN+ACK Packet.\n");\r
+\r
+                                       IPToStr32(ip1, sizeof(ip1), p->L3.IPv4Header->SrcIP);\r
+                                       IPToStr32(ip2, sizeof(ip2), p->L3.IPv4Header->DstIP);\r
+\r
+                                       HLog(s->Hub, "LH_NO_SERVER", s->Name, ip2, p->L4.TCPHeader->DstPort,\r
+                                               ip1, p->L4.TCPHeader->SrcPort);\r
+\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       // サーバーとしての動作を禁止する (IPv6)\r
+       if (pol->NoServerV6)\r
+       {\r
+               if (p->TypeL3 == L3_IPV6)\r
+               {\r
+                       if (p->TypeL4 == L4_TCP)\r
+                       {\r
+                               UCHAR flag = p->L4.TCPHeader->Flag;\r
+                               if ((flag & TCP_SYN) && (flag & TCP_ACK))\r
+                               {\r
+                                       char ip1[128], ip2[128];\r
+                                       // SYN + ACK パケットを送信させない\r
+                                       Debug("pol->NoServerV6: Discard SYN+ACK Packet.\n");\r
+\r
+                                       IP6AddrToStr(ip1, sizeof(ip1), &p->IPv6HeaderPacketInfo.IPv6Header->SrcAddress);\r
+                                       IP6AddrToStr(ip2, sizeof(ip2), &p->IPv6HeaderPacketInfo.IPv6Header->DestAddress);\r
+\r
+                                       HLog(s->Hub, "LH_NO_SERVER", s->Name, ip2, p->L4.TCPHeader->DstPort,\r
+                                               ip1, p->L4.TCPHeader->SrcPort);\r
+\r
+                                       return false;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       // ブロードキャストは ARP と DHCP のみ許可\r
+       if (pol->ArpDhcpOnly && p->BroadcastPacket)\r
+       {\r
+               bool ok = false;\r
+\r
+               if (p->TypeL3 == L3_ARPV4)\r
+               {\r
+                       ok = true;\r
+               }\r
+               if (p->TypeL3 == L3_IPV4)\r
+               {\r
+                       if (p->TypeL4 == L4_UDP)\r
+                       {\r
+                               if (p->TypeL7 == L7_DHCPV4)\r
+                               {\r
+                                       ok = true;\r
+                               }\r
+                       }\r
+               }\r
+               if (p->TypeL3 == L3_IPV6)\r
+               {\r
+                       if (p->TypeL4 == L4_ICMPV6)\r
+                       {\r
+                               ok = true;\r
+                       }\r
+               }\r
+\r
+               if (p->TypeL3 == L3_IPV6 &&\r
+                       p->TypeL4 == L4_UDP &&\r
+                       (Endian16(p->L4.UDPHeader->DstPort) == 546 || Endian16(p->L4.UDPHeader->DstPort) == 547))\r
+               {\r
+                       ok = true;\r
+               }\r
+\r
+               if (ok == false)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // IPv4 パケットのフィルタリング\r
+       if (pol->FilterIPv4)\r
+       {\r
+               if (p->MacHeader != NULL)\r
+               {\r
+                       USHORT proto = Endian16(p->MacHeader->Protocol);\r
+                       if (proto == 0x0800 || proto == 0x0806)\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // IPv6 パケットのフィルタリング\r
+       if (pol->FilterIPv6)\r
+       {\r
+               if (p->MacHeader != NULL)\r
+               {\r
+                       USHORT proto = Endian16(p->MacHeader->Protocol);\r
+                       if (proto == 0x86dd)\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // 非 IP パケットのフィルタリング\r
+       if (pol->FilterNonIP)\r
+       {\r
+               if (p->MacHeader != NULL)\r
+               {\r
+                       USHORT proto = Endian16(p->MacHeader->Protocol);\r
+                       if (!(proto == 0x86dd || proto == 0x0800 || proto == 0x0806))\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // DHCP パケットのフィルタリング\r
+       if (pol->DHCPFilter)\r
+       {\r
+               if (p->TypeL3 == L3_IPV4 &&\r
+                       p->TypeL4 == L4_UDP &&\r
+                       p->TypeL7 == L7_DHCPV4)\r
+               {\r
+                       // DHCP パケットを破棄する\r
+                       Debug("pol->DHCPFilter: Discard DHCP Packet.\n");\r
+\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // DHCPv6 パケットのフィルタリング\r
+       if (pol->DHCPv6Filter)\r
+       {\r
+               if (p->TypeL3 == L3_IPV6 &&\r
+                       p->TypeL4 == L4_UDP)\r
+               {\r
+                       if (Endian16(p->L4.UDPHeader->DstPort) == 546 ||\r
+                               Endian16(p->L4.UDPHeader->DstPort) == 547)\r
+                       {\r
+                               // DHCPv6 パケットを破棄する\r
+                               Debug("pol->DHCPv6Filter: Discard DHCPv6 Packet.\n");\r
+\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // DHCP サーバーとしての動作を禁止\r
+       if (pol->DHCPNoServer)\r
+       {\r
+               if (p->TypeL3 == L3_IPV4 &&\r
+                       p->TypeL4 == L4_UDP &&\r
+                       p->TypeL7 == L7_DHCPV4)\r
+               {\r
+                       DHCPV4_HEADER *h = p->L7.DHCPv4Header;\r
+                       if (h->OpCode == 2)\r
+                       {\r
+                               char ip1[64], ip2[64];\r
+\r
+                               // DHCP パケットを破棄する\r
+                               IPToStr32(ip1, sizeof(ip1), p->L3.IPv4Header->SrcIP);\r
+                               IPToStr32(ip2, sizeof(ip2), p->L3.IPv4Header->DstIP);\r
+\r
+                               HLog(s->Hub, "LH_NO_DHCP", s->Name, ip1, ip2);\r
+\r
+                               // DHCP 応答パケットを破棄する\r
+                               Debug("pol->DHCPNoServer: Discard DHCP Response Packet.\n");\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // DHCPv6 サーバーとしての動作を禁止\r
+       if (pol->DHCPv6NoServer)\r
+       {\r
+               if (p->TypeL3 == L3_IPV6 &&\r
+                       p->TypeL4 == L4_UDP &&\r
+                       (Endian16(p->L4.UDPHeader->DstPort) == 546 || Endian16(p->L4.UDPHeader->SrcPort) == 547))\r
+               {\r
+                       char ip1[128], ip2[128];\r
+\r
+                       // DHCP パケットを破棄する\r
+                       IP6AddrToStr(ip1, sizeof(ip1), &p->L3.IPv6Header->SrcAddress);\r
+                       IP6AddrToStr(ip2, sizeof(ip2), &p->L3.IPv6Header->DestAddress);\r
+\r
+                       HLog(s->Hub, "LH_NO_DHCP", s->Name, ip1, ip2);\r
+\r
+                       // DHCP 応答パケットを破棄する\r
+                       Debug("pol->DHCPv6NoServer: Discard DHCPv6 Response Packet.\n");\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // ルータ要請/広告パケットをフィルタリング (IPv6)\r
+       if (pol->RSandRAFilter)\r
+       {\r
+               if (p->TypeL3 == L3_IPV6 && p->TypeL4 == L4_ICMPV6 &&\r
+                       (p->ICMPv6HeaderPacketInfo.Type == ICMPV6_TYPE_ROUTER_SOLICIATION ||\r
+                        p->ICMPv6HeaderPacketInfo.Type == ICMPV6_TYPE_ROUTER_ADVERTISEMENT))\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // ルータ広告パケットをフィルタリング (IPv6)\r
+       if (pol->RAFilter)\r
+       {\r
+               if (p->TypeL3 == L3_IPV6 && p->TypeL4 == L4_ICMPV6 &&\r
+                       p->ICMPv6HeaderPacketInfo.Type == ICMPV6_TYPE_ROUTER_ADVERTISEMENT)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // DHCP 応答パケットを記録して IP テーブルに登録\r
+       if (p->TypeL3 == L3_IPV4 &&\r
+               p->TypeL4 == L4_UDP &&\r
+               p->TypeL7 == L7_DHCPV4 &&\r
+               (s->Hub != NULL && s->Hub->Option->NoIpTable == false))\r
+       {\r
+               DHCPV4_HEADER *h = p->L7.DHCPv4Header;\r
+               if (h->OpCode == 2)\r
+               {\r
+                       // DHCP 応答パケットの中身を見て IP テーブルに登録する\r
+                       if (h->HardwareType == ARP_HARDWARE_TYPE_ETHERNET)\r
+                       {\r
+                               if (h->HardwareAddressSize == 6)\r
+                               {\r
+                                       if (h->YourIP != 0 && h->YourIP != 0xffffffff)\r
+                                       {\r
+                                               UINT ip_uint = h->YourIP;\r
+                                               IP ip;\r
+                                               IP_TABLE_ENTRY *e, t;\r
+                                               MAC_TABLE_ENTRY *mac_table, mt;\r
+                                               mt.VlanId = 0;\r
+                                               Copy(&mt.MacAddress, &h->ClientMacAddress, 6);\r
+                                               mac_table = Search(hub->MacTable, &mt);\r
+\r
+                                               if (mac_table != NULL)\r
+                                               {\r
+                                                       bool new_entry = true;\r
+                                                       UINTToIP(&ip, ip_uint);\r
+                                                       Copy(&t.Ip, &ip, sizeof(IP));\r
+\r
+                                                       e = Search(hub->IpTable, &t);\r
+                                                       if (e == NULL)\r
+                                                       {\r
+                                                               // 新しく登録\r
+                                                               e = ZeroMalloc(sizeof(IP_TABLE_ENTRY));\r
+UPDATE_DHCP_ALLOC_ENTRY:\r
+                                                               e->CreatedTime = e->UpdatedTime = Tick64();\r
+                                                               e->DhcpAllocated = true;\r
+                                                               Copy(&e->Ip, &ip, sizeof(IP));\r
+                                                               e->Session = mac_table->Session;\r
+                                                               Copy(e->MacAddress, p->MacAddressDest, 6);\r
+\r
+                                                               if (new_entry)\r
+                                                               {\r
+                                                                       // 有効期限の切れた IP テーブルエントリを削除する\r
+                                                                       DeleteExpiredIpTableEntry(hub->IpTable);\r
+                                                                       if (LIST_NUM(hub->IpTable) >= MAX_IP_TABLES)\r
+                                                                       {\r
+                                                                               // 古いエントリを削除する\r
+                                                                               DeleteOldIpTableEntry(hub->IpTable);\r
+                                                                       }\r
+                                                                       Insert(hub->IpTable, e);\r
+                                                               }\r
+\r
+                                                               if (new_entry)\r
+                                                               {\r
+                                                                       char dhcp_mac_addr[64];\r
+                                                                       char dest_mac_addr[64];\r
+                                                                       char dest_ip_addr[64];\r
+                                                                       char server_ip_addr[64];\r
+                                                                       MacToStr(dhcp_mac_addr, sizeof(dhcp_mac_addr), p->MacAddressSrc);\r
+                                                                       MacToStr(dest_mac_addr, sizeof(dest_mac_addr), h->ClientMacAddress);\r
+                                                                       IPToStr(dest_ip_addr, sizeof(dest_ip_addr), &ip);\r
+                                                                       IPToStr32(server_ip_addr, sizeof(server_ip_addr), p->L3.IPv4Header->SrcIP);\r
+                                                                       Debug("DHCP Allocated; dhcp server: %s, client: %s, new_ip: %s\n",\r
+                                                                               dhcp_mac_addr, dest_mac_addr, dest_ip_addr);\r
+\r
+                                                                       HLog(s->Hub, "LH_REGIST_DHCP", s->Name, dhcp_mac_addr, server_ip_addr,\r
+                                                                               mac_table->Session->Name, dest_mac_addr, dest_ip_addr);\r
+                                                               }\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               // 更新\r
+                                                               new_entry = false;\r
+                                                               goto UPDATE_DHCP_ALLOC_ENTRY;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 有効期限の切れた MAC テーブルエントリを削除する\r
+void DeleteExpiredMacTableEntry(LIST *o)\r
+{\r
+       LIST *o2;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o2 = NewListFast(NULL);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               MAC_TABLE_ENTRY *e = LIST_DATA(o, i);\r
+               if ((e->UpdatedTime + (UINT64)MAC_TABLE_EXPIRE_TIME) <= Tick64())\r
+               {\r
+                       Add(o2, e);\r
+               }\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o2);i++)\r
+       {\r
+               MAC_TABLE_ENTRY *e = LIST_DATA(o2, i);\r
+               Delete(o, e);\r
+               Free(e);\r
+       }\r
+\r
+       ReleaseList(o2);\r
+}\r
+\r
+// 有効期限の切れた IP テーブルエントリを削除する\r
+void DeleteExpiredIpTableEntry(LIST *o)\r
+{\r
+       LIST *o2;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o2 = NewListFast(NULL);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               IP_TABLE_ENTRY *e = LIST_DATA(o, i);\r
+               if ((e->UpdatedTime + (UINT64)(e->DhcpAllocated ? IP_TABLE_EXPIRE_TIME_DHCP : IP_TABLE_EXPIRE_TIME)) <= Tick64())\r
+               {\r
+                       Add(o2, e);\r
+               }\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o2);i++)\r
+       {\r
+               IP_TABLE_ENTRY *e = LIST_DATA(o2, i);\r
+               Delete(o, e);\r
+               Free(e);\r
+       }\r
+\r
+       ReleaseList(o2);\r
+}\r
+\r
+// 優先して取り扱うべきパケットかどうかを判断\r
+bool IsMostHighestPriorityPacket(SESSION *s, PKT *p)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (p->TypeL3 == L3_ARPV4)\r
+       {\r
+               // ARP パケット\r
+               return true;\r
+       }\r
+\r
+       if (p->TypeL3 == L3_IPV4)\r
+       {\r
+               if (p->TypeL4 == L4_ICMPV4)\r
+               {\r
+                       // ICMP パケット\r
+                       return true;\r
+               }\r
+\r
+               if (p->TypeL4 == L4_TCP)\r
+               {\r
+                       if ((p->L4.TCPHeader->Flag & TCP_SYN) || (p->L4.TCPHeader->Flag & TCP_FIN)\r
+                               || (p->L4.TCPHeader->Flag & TCP_RST))\r
+                       {\r
+                               // SYN, FIN, RST パケット\r
+                               return true;\r
+                       }\r
+               }\r
+\r
+               if (p->TypeL4 == L4_UDP)\r
+               {\r
+                       if (p->TypeL7 == L7_DHCPV4)\r
+                       {\r
+                               // DHCP パケット\r
+                               return true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// トラフィック リミッターへのパケット追加\r
+void IntoTrafficLimiter(TRAFFIC_LIMITER *tr, PKT *p)\r
+{\r
+       UINT64 now = Tick64();\r
+       // 引数チェック\r
+       if (tr == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (tr->LastTime == 0 || tr->LastTime > now ||\r
+               (tr->LastTime + LIMITER_SAMPLING_SPAN) < now)\r
+       {\r
+               // サンプリング初期化\r
+               tr->Value = 0;\r
+               tr->LastTime = now;\r
+       }\r
+\r
+       // 値増加\r
+       tr->Value += (UINT64)(p->PacketSize * 8);\r
+}\r
+\r
+// トラフィック リミッターによる帯域幅削減\r
+bool StorePacketFilterByTrafficLimiter(SESSION *s, PKT *p)\r
+{\r
+       HUB_PA *pa;\r
+       TRAFFIC_LIMITER *tr;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (s->Policy->MaxUpload == 0)\r
+       {\r
+               // 制限無し\r
+               return true;\r
+       }\r
+\r
+       pa = (HUB_PA *)s->PacketAdapter->Param;\r
+       tr = &pa->UploadLimiter;\r
+\r
+       // 優先パケットは制限を適用しない\r
+       if (IsMostHighestPriorityPacket(s, p))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       // リミッターへパケットを投入\r
+       IntoTrafficLimiter(tr, p);\r
+\r
+       // 現在の帯域幅と制限値を比較\r
+       if ((tr->Value * (UINT64)1000 / (UINT64)LIMITER_SAMPLING_SPAN) > s->Policy->MaxUpload)\r
+       {\r
+               // パケットを破棄\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ストアするパケットのフィルタリング\r
+bool StorePacketFilter(SESSION *s, PKT *packet)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || packet == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // トラフィック リミッターによる帯域幅削減\r
+       if (StorePacketFilterByTrafficLimiter(s, packet) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ポリシーによるパケットフィルタ\r
+       if (StorePacketFilterByPolicy(s, packet) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // アクセスリストによるパケットフィルタ\r
+       if (ApplyAccessListToStoredPacket(s->Hub, s, packet) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// HUB 用のパケットアダプタの取得\r
+PACKET_ADAPTER *GetHubPacketAdapter()\r
+{\r
+       // 関数リストを生成して引き渡す\r
+       PACKET_ADAPTER *pa = NewPacketAdapter(HubPaInit,\r
+               HubPaGetCancel, HubPaGetNextPacket, HubPaPutPacket, HubPaFree);\r
+\r
+       return pa;\r
+}\r
+\r
+// HUB のすべての SESSION を停止させる\r
+void StopAllSession(HUB *h)\r
+{\r
+       SESSION **s;\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(h->SessionList);\r
+       {\r
+               num = LIST_NUM(h->SessionList);\r
+               s = ToArray(h->SessionList);\r
+               DeleteAll(h->SessionList);\r
+       }\r
+       UnlockList(h->SessionList);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               StopSession(s[i]);\r
+               ReleaseSession(s[i]);\r
+       }\r
+\r
+       Free(s);\r
+}\r
+\r
+// HUB から SESSION を削除\r
+void DelSession(HUB *h, SESSION *s)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(h->SessionList);\r
+       {\r
+               if (Delete(h->SessionList, s))\r
+               {\r
+                       Debug("Session %s was Deleted from %s.\n", s->Name, h->Name);\r
+                       ReleaseSession(s);\r
+               }\r
+       }\r
+       UnlockList(h->SessionList);\r
+}\r
+\r
+// HUB に SESSION を追加\r
+void AddSession(HUB *h, SESSION *s)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(h->SessionList);\r
+       {\r
+               Insert(h->SessionList, s);\r
+               AddRef(s->ref);\r
+               Debug("Session %s Inserted to %s.\n", s->Name, h->Name);\r
+       }\r
+       UnlockList(h->SessionList);\r
+}\r
+\r
+// HUB の動作を停止する\r
+void StopHub(HUB *h)\r
+{\r
+       bool old_status = false;\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       old_status = h->Offline;\r
+       h->HubIsOnlineButHalting = true;\r
+\r
+       SetHubOffline(h);\r
+\r
+       if (h->Halt == false)\r
+       {\r
+               SLog(h->Cedar, "LS_HUB_STOP", h->Name);\r
+               h->Halt = true;\r
+       }\r
+\r
+       h->Offline = old_status;\r
+       h->HubIsOnlineButHalting = false;\r
+}\r
+\r
+// HUB をオンラインにする\r
+void SetHubOnline(HUB *h)\r
+{\r
+       bool for_cluster = false;\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (h->Cedar->Server != NULL && h->Cedar->Server->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               if (h->Type == HUB_TYPE_FARM_DYNAMIC)\r
+               {\r
+                       for_cluster = true;\r
+               }\r
+       }\r
+\r
+       Lock(h->lock_online);\r
+       {\r
+               if (h->Offline == false)\r
+               {\r
+                       Unlock(h->lock_online);\r
+                       return;\r
+               }\r
+               HLog(h, "LH_ONLINE");\r
+\r
+               // すべてのリンクを開始\r
+               StartAllLink(h);\r
+\r
+               // SecureNAT を開始\r
+               if (h->EnableSecureNAT)\r
+               {\r
+                       if (h->SecureNAT == NULL)\r
+                       {\r
+                               if (for_cluster == false)\r
+                               {\r
+                                       h->SecureNAT = SnNewSecureNAT(h, h->SecureNATOption);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // この HUB に関連付けられているローカルブリッジをすべて開始する\r
+               if (h->Type != HUB_TYPE_FARM_DYNAMIC)\r
+               {\r
+                       LockList(h->Cedar->LocalBridgeList);\r
+                       {\r
+                               UINT i;\r
+                               for (i = 0;i < LIST_NUM(h->Cedar->LocalBridgeList);i++)\r
+                               {\r
+                                       LOCALBRIDGE *br = LIST_DATA(h->Cedar->LocalBridgeList, i);\r
+\r
+                                       if (StrCmpi(br->HubName, h->Name) == 0)\r
+                                       {\r
+                                               if (br->Bridge == NULL)\r
+                                               {\r
+                                                       br->Bridge = BrNewBridge(h, br->DeviceName, NULL, br->Local, br->Monitor,\r
+                                                               br->TapMode, br->TapMacAddress, br->FullBroadcast);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       UnlockList(h->Cedar->LocalBridgeList);\r
+               }\r
+\r
+               h->Offline = false;\r
+       }\r
+       Unlock(h->lock_online);\r
+\r
+       if (h->Cedar->Server != NULL)\r
+       {\r
+               SiHubOnlineProc(h);\r
+       }\r
+}\r
+\r
+// HUB をオフラインにする\r
+void SetHubOffline(HUB *h)\r
+{\r
+       UINT i;\r
+       bool for_cluster = false;\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (h->Cedar->Server != NULL && h->Cedar->Server->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               if (h->Type == HUB_TYPE_FARM_DYNAMIC)\r
+               {\r
+                       for_cluster = true;\r
+               }\r
+       }\r
+\r
+       h->BeingOffline = true;\r
+\r
+       Lock(h->lock_online);\r
+       {\r
+               if (h->Offline || h->Halt)\r
+               {\r
+                       Unlock(h->lock_online);\r
+                       h->BeingOffline = false;\r
+                       return;\r
+               }\r
+\r
+               HLog(h, "LH_OFFLINE");\r
+\r
+               // すべてのリンクを停止\r
+               StopAllLink(h);\r
+\r
+               // SecureNAT を停止\r
+               SnFreeSecureNAT(h->SecureNAT);\r
+               h->SecureNAT = NULL;\r
+\r
+               // この HUB に関連付けられているローカルブリッジをすべて停止する\r
+               LockList(h->Cedar->LocalBridgeList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(h->Cedar->LocalBridgeList);i++)\r
+                       {\r
+                               LOCALBRIDGE *br = LIST_DATA(h->Cedar->LocalBridgeList, i);\r
+\r
+                               if (StrCmpi(br->HubName, h->Name) == 0)\r
+                               {\r
+                                       BrFreeBridge(br->Bridge);\r
+                                       br->Bridge = NULL;\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(h->Cedar->LocalBridgeList);\r
+\r
+               // オフラインにする\r
+               h->Offline = true;\r
+\r
+               // すべてのセッションを切断する\r
+               StopAllSession(h);\r
+       }\r
+       Unlock(h->lock_online);\r
+\r
+       h->BeingOffline = false;\r
+\r
+       if (h->Cedar->Server != NULL)\r
+       {\r
+               SiHubOfflineProc(h);\r
+       }\r
+}\r
+\r
+// 指定された名前の HUB が存在するかどうか取得\r
+bool IsHub(CEDAR *cedar, char *name)\r
+{\r
+       HUB *h;\r
+       // 引数チェック\r
+       if (cedar == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       h = GetHub(cedar, name);\r
+       if (h == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       return true;\r
+}\r
+\r
+// HUB の取得\r
+HUB *GetHub(CEDAR *cedar, char *name)\r
+{\r
+       HUB *h, t;\r
+       // 引数チェック\r
+       if (cedar == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       LockHubList(cedar);\r
+\r
+       t.Name = name;\r
+       h = Search(cedar->HubList, &t);\r
+       if (h == NULL)\r
+       {\r
+               UnlockHubList(cedar);\r
+               return NULL;\r
+       }\r
+\r
+       AddRef(h->ref);\r
+\r
+       UnlockHubList(cedar);\r
+\r
+       return h;\r
+}\r
+\r
+// HUB リストのロック\r
+void LockHubList(CEDAR *cedar)\r
+{\r
+       // 引数チェック\r
+       if (cedar == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(cedar->HubList);\r
+}\r
+\r
+// HUB リストのロック解除\r
+void UnlockHubList(CEDAR *cedar)\r
+{\r
+       // 引数チェック\r
+       if (cedar == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UnlockList(cedar->HubList);\r
+}\r
+\r
+// HUB の解放\r
+void ReleaseHub(HUB *h)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(h->ref) == 0)\r
+       {\r
+               CleanupHub(h);\r
+       }\r
+}\r
+\r
+// Radius サーバー情報を取得\r
+bool GetRadiusServer(HUB *hub, char *name, UINT size, UINT *port, char *secret, UINT secret_size)\r
+{\r
+       UINT interval;\r
+       return GetRadiusServerEx(hub, name, size, port, secret, secret_size, &interval);\r
+}\r
+bool GetRadiusServerEx(HUB *hub, char *name, UINT size, UINT *port, char *secret, UINT secret_size, UINT *interval)\r
+{\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (hub == NULL || name == NULL || port == NULL || secret == NULL || interval == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(hub->RadiusOptionLock);\r
+       {\r
+               if (hub->RadiusServerName != NULL)\r
+               {\r
+                       char *tmp;\r
+                       UINT tmp_size;\r
+                       StrCpy(name, size, hub->RadiusServerName);\r
+                       *port = hub->RadiusServerPort;\r
+                       *interval = hub->RadiusRetryInterval;\r
+\r
+                       tmp_size = hub->RadiusSecret->Size + 1;\r
+                       tmp = ZeroMalloc(tmp_size);\r
+                       Copy(tmp, hub->RadiusSecret->Buf, hub->RadiusSecret->Size);\r
+                       StrCpy(secret, secret_size, tmp);\r
+                       Free(tmp);\r
+\r
+                       ret = true;\r
+               }\r
+       }\r
+       Unlock(hub->RadiusOptionLock);\r
+\r
+       return ret;\r
+}\r
+\r
+// Radius サーバー情報を設定\r
+void SetRadiusServer(HUB *hub, char *name, UINT port, char *secret)\r
+{\r
+       SetRadiusServerEx(hub, name, port, secret, RADIUS_RETRY_INTERVAL);\r
+}\r
+void SetRadiusServerEx(HUB *hub, char *name, UINT port, char *secret, UINT interval)\r
+{\r
+       // 引数チェック\r
+       if (hub == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(hub->RadiusOptionLock);\r
+       {\r
+               if (hub->RadiusServerName != NULL)\r
+               {\r
+                       Free(hub->RadiusServerName);\r
+               }\r
+\r
+               if (name == NULL)\r
+               {\r
+                       hub->RadiusServerName = NULL;\r
+                       hub->RadiusServerPort = 0;\r
+                       hub->RadiusRetryInterval = RADIUS_RETRY_INTERVAL;\r
+                       FreeBuf(hub->RadiusSecret);\r
+               }\r
+               else\r
+               {\r
+                       hub->RadiusServerName = CopyStr(name);\r
+                       hub->RadiusServerPort = port;\r
+                       if (interval == 0)\r
+                       {\r
+                               hub->RadiusRetryInterval = RADIUS_RETRY_INTERVAL;\r
+                       }\r
+                       else if (interval > RADIUS_RETRY_TIMEOUT)\r
+                       {\r
+                               hub->RadiusRetryInterval = RADIUS_RETRY_TIMEOUT;\r
+                       }\r
+                       else\r
+                       {\r
+                               hub->RadiusRetryInterval = interval;\r
+                       }\r
+                       FreeBuf(hub->RadiusSecret);\r
+\r
+                       if (secret == NULL)\r
+                       {\r
+                               hub->RadiusSecret = NewBuf();\r
+                       }\r
+                       else\r
+                       {\r
+                               hub->RadiusSecret = NewBuf();\r
+                               WriteBuf(hub->RadiusSecret, secret, StrLen(secret));\r
+                               SeekBuf(hub->RadiusSecret, 0, 0);\r
+                       }\r
+               }\r
+       }\r
+       Unlock(hub->RadiusOptionLock);\r
+}\r
+\r
+// 仮想 HUB のトラフィック情報の追加\r
+void IncrementHubTraffic(HUB *h)\r
+{\r
+       TRAFFIC t;\r
+       // 引数チェック\r
+       if (h == NULL || h->FarmMember == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       Lock(h->TrafficLock);\r
+       {\r
+               t.Send.BroadcastBytes =\r
+                       h->Traffic->Send.BroadcastBytes - h->OldTraffic->Send.BroadcastBytes;\r
+               t.Send.BroadcastCount =\r
+                       h->Traffic->Send.BroadcastCount - h->OldTraffic->Send.BroadcastCount;\r
+               t.Send.UnicastBytes =\r
+                       h->Traffic->Send.UnicastBytes - h->OldTraffic->Send.UnicastBytes;\r
+               t.Send.UnicastCount =\r
+                       h->Traffic->Send.UnicastCount - h->OldTraffic->Send.UnicastCount;\r
+               t.Recv.BroadcastBytes =\r
+                       h->Traffic->Recv.BroadcastBytes - h->OldTraffic->Recv.BroadcastBytes;\r
+               t.Recv.BroadcastCount =\r
+                       h->Traffic->Recv.BroadcastCount - h->OldTraffic->Recv.BroadcastCount;\r
+               t.Recv.UnicastBytes =\r
+                       h->Traffic->Recv.UnicastBytes - h->OldTraffic->Recv.UnicastBytes;\r
+               t.Recv.UnicastCount =\r
+                       h->Traffic->Recv.UnicastCount - h->OldTraffic->Recv.UnicastCount;\r
+               Copy(h->OldTraffic, h->Traffic, sizeof(TRAFFIC));\r
+       }\r
+       Unlock(h->TrafficLock);\r
+\r
+       if (IsZero(&t, sizeof(TRAFFIC)))\r
+       {\r
+               return;\r
+       }\r
+\r
+       AddTrafficDiff(h, h->Name, TRAFFIC_DIFF_HUB, &t);\r
+}\r
+\r
+// トラフィック情報の追加\r
+void AddTrafficDiff(HUB *h, char *name, UINT type, TRAFFIC *traffic)\r
+{\r
+       TRAFFIC_DIFF *d;\r
+       // 引数チェック\r
+       if (h == NULL || h->FarmMember == false || name == NULL || traffic == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LIST_NUM(h->Cedar->TrafficDiffList) > MAX_TRAFFIC_DIFF)\r
+       {\r
+               return;\r
+       }\r
+\r
+       d = ZeroMallocFast(sizeof(TRAFFIC_DIFF));\r
+       d->HubName = CopyStr(h->Name);\r
+       d->Name = CopyStr(name);\r
+       d->Type = type;\r
+       Copy(&d->Traffic, traffic, sizeof(TRAFFIC));\r
+\r
+       LockList(h->Cedar->TrafficDiffList);\r
+       {\r
+               Insert(h->Cedar->TrafficDiffList, d);\r
+       }\r
+       UnlockList(h->Cedar->TrafficDiffList);\r
+}\r
+\r
+// HUB のクリーンアップ\r
+void CleanupHub(HUB *h)\r
+{\r
+       UINT i;\r
+       char name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(name, sizeof(name), h->Name);\r
+\r
+       if (h->WatchDogStarted)\r
+       {\r
+               StopHubWatchDog(h);\r
+       }\r
+\r
+       FreeAccessList(h);\r
+\r
+       if (h->RadiusServerName != NULL)\r
+       {\r
+               Free(h->RadiusServerName);\r
+               FreeBuf(h->RadiusSecret);\r
+       }\r
+       ReleaseAllLink(h);\r
+       DeleteHubDb(h->HubDb);\r
+       ReleaseCedar(h->Cedar);\r
+       DeleteLock(h->lock);\r
+       DeleteLock(h->lock_online);\r
+       Free(h->Name);\r
+       ReleaseList(h->SessionList);\r
+       ReleaseList(h->MacTable);\r
+       ReleaseList(h->IpTable);\r
+       ReleaseList(h->MonitorList);\r
+       ReleaseList(h->LinkList);\r
+       DeleteCounter(h->NumSessions);\r
+       DeleteCounter(h->NumSessionsClient);\r
+       DeleteCounter(h->NumSessionsBridge);\r
+       DeleteCounter(h->SessionCounter);\r
+       FreeTraffic(h->Traffic);\r
+       FreeTraffic(h->OldTraffic);\r
+       Free(h->Option);\r
+\r
+       Free(h->SecureNATOption);\r
+\r
+       DeleteLock(h->TrafficLock);\r
+\r
+       for (i = 0;i < LIST_NUM(h->TicketList);i++)\r
+       {\r
+               Free(LIST_DATA(h->TicketList, i));\r
+       }\r
+\r
+       ReleaseList(h->TicketList);\r
+\r
+       DeleteLock(h->RadiusOptionLock);\r
+\r
+       FreeLog(h->PacketLogger);\r
+       FreeLog(h->SecurityLogger);\r
+\r
+       for (i = 0;i < LIST_NUM(h->AdminOptionList);i++)\r
+       {\r
+               Free(LIST_DATA(h->AdminOptionList, i));\r
+       }\r
+       ReleaseList(h->AdminOptionList);\r
+\r
+       if (h->Msg != NULL)\r
+       {\r
+               Free(h->Msg);\r
+       }\r
+\r
+       Free(h);\r
+}\r
+\r
+// IP テーブルの比較関数\r
+int CompareIpTable(void *p1, void *p2)\r
+{\r
+       IP_TABLE_ENTRY *e1, *e2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       e1 = *(IP_TABLE_ENTRY **)p1;\r
+       e2 = *(IP_TABLE_ENTRY **)p2;\r
+       if (e1 == NULL || e2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return CmpIpAddr(&e1->Ip, &e2->Ip);\r
+}\r
+\r
+// MAC テーブルの比較関数\r
+int CompareMacTable(void *p1, void *p2)\r
+{\r
+       int r;\r
+       MAC_TABLE_ENTRY *e1, *e2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       e1 = *(MAC_TABLE_ENTRY **)p1;\r
+       e2 = *(MAC_TABLE_ENTRY **)p2;\r
+       if (e1 == NULL || e2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       r = Cmp(e1->MacAddress, e2->MacAddress, 6);\r
+       if (r != 0)\r
+       {\r
+               return r;\r
+       }\r
+       if (e1->VlanId > e2->VlanId)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (e1->VlanId < e2->VlanId)\r
+       {\r
+               return -1;\r
+       }\r
+       return 0;\r
+}\r
+\r
+// HUB の比較関数\r
+int CompareHub(void *p1, void *p2)\r
+{\r
+       HUB *h1, *h2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       h1 = *(HUB **)p1;\r
+       h2 = *(HUB **)p2;\r
+       if (h1 == NULL || h2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return StrCmpi(h1->Name, h2->Name);\r
+}\r
+\r
+// MAC アドレスが仮想 HUB の ARP ポーリング用の MAC アドレスかどうか調べる\r
+bool IsHubMacAddress(UCHAR *mac)\r
+{\r
+       // 引数チェック\r
+       if (mac == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (mac[0] == 0x00 && mac[1] == SE_HUB_MAC_ADDR_SIGN)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// IP アドレスが仮想 HUB の ARP ポーリング用の IP アドレスかどうか調べる\r
+bool IsHubIpAddress32(UINT ip32)\r
+{\r
+       IP ip;\r
+\r
+       UINTToIP(&ip, ip32);\r
+\r
+       return IsHubIpAddress(&ip);\r
+}\r
+bool IsHubIpAddress(IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ip->addr[0] == 172 && ip->addr[1] == 31)\r
+       {\r
+               if (ip->addr[2] >= 1 && ip->addr[2] <= 254)\r
+               {\r
+                       if (ip->addr[3] >= 1 && ip->addr[3] <= 254)\r
+                       {\r
+                               return true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+bool IsHubIpAddress64(IPV6_ADDR *addr)\r
+{\r
+       // 引数チェック\r
+       if (addr == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (addr->Value[0] == 0xfe && addr->Value[1] == 0x80 &&\r
+               addr->Value[2] == 0 &&\r
+               addr->Value[3] == 0 &&\r
+               addr->Value[4] == 0 &&\r
+               addr->Value[5] == 0 &&\r
+               addr->Value[6] == 0 &&\r
+               addr->Value[7] == 0 &&\r
+               addr->Value[8] == 0x02 && addr->Value[9] == 0xae && \r
+               addr->Value[11] == 0xff && addr->Value[12] == 0xfe)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// 仮想 HUB 用 IP アドレスの生成\r
+void GenHubIpAddress(IP *ip, char *name)\r
+{\r
+       char tmp1[MAX_SIZE];\r
+       char tmp2[MAX_SIZE];\r
+       UCHAR hash[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (ip == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(tmp1, sizeof(tmp1), name);\r
+       Trim(tmp1);\r
+       GenerateMachineUniqueHash(hash);\r
+       BinToStr(tmp2, sizeof(tmp2), hash, sizeof(hash));\r
+       StrCat(tmp2, sizeof(tmp2), tmp1);\r
+       StrUpper(tmp2);\r
+\r
+       Hash(hash, tmp2, StrLen(tmp2), true);\r
+\r
+       Zero(ip, sizeof(IP));\r
+       ip->addr[0] = 172;\r
+       ip->addr[1] = 31;\r
+       ip->addr[2] = hash[0] % 254 + 1;\r
+       ip->addr[3] = hash[1] % 254 + 1;\r
+}\r
+\r
+// 仮想 HUB 用 MAC アドレスの生成\r
+void GenHubMacAddress(UCHAR *mac, char *name)\r
+{\r
+       char tmp1[MAX_SIZE];\r
+       char tmp2[MAX_SIZE];\r
+       UCHAR hash[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (mac == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(tmp1, sizeof(tmp1), name);\r
+       Trim(tmp1);\r
+       GenerateMachineUniqueHash(hash);\r
+       BinToStr(tmp2, sizeof(tmp2), hash, sizeof(hash));\r
+       StrCat(tmp2, sizeof(tmp2), tmp1);\r
+       StrUpper(tmp2);\r
+\r
+       Hash(hash, tmp2, StrLen(tmp2), true);\r
+\r
+       mac[0] = 0x00;\r
+       mac[1] = SE_HUB_MAC_ADDR_SIGN;\r
+       mac[2] = hash[0];\r
+       mac[3] = hash[1];\r
+       mac[4] = hash[2];\r
+       mac[5] = hash[3];\r
+}\r
+\r
+// HUB からメッセージを取得\r
+wchar_t *GetHubMsg(HUB *h)\r
+{\r
+       wchar_t *ret = NULL;\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Lock(h->lock);\r
+       {\r
+               if (h->Msg != NULL)\r
+               {\r
+                       ret = CopyUniStr(h->Msg);\r
+               }\r
+       }\r
+       Unlock(h->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// HUB にメッセージを設定\r
+void SetHubMsg(HUB *h, wchar_t *msg)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(h->lock);\r
+       {\r
+               if (h->Msg != NULL)\r
+               {\r
+                       Free(h->Msg);\r
+                       h->Msg = NULL;\r
+               }\r
+\r
+               if (UniIsEmptyStr(msg) == false)\r
+               {\r
+                       h->Msg = UniCopyStr(msg);\r
+               }\r
+       }\r
+       Unlock(h->lock);\r
+}\r
+\r
+// 新しい HUB の作成\r
+HUB *NewHub(CEDAR *cedar, char *HubName, HUB_OPTION *option)\r
+{\r
+       HUB *h;\r
+       char packet_logger_name[MAX_SIZE];\r
+       char tmp[MAX_SIZE];\r
+       char safe_hub_name[MAX_HUBNAME_LEN + 1];\r
+       UCHAR hash[SHA1_SIZE];\r
+       IP ip6;\r
+       // 引数チェック\r
+       if (cedar == NULL || option == NULL || HubName == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       h = ZeroMalloc(sizeof(HUB));\r
+       Hash(h->HashedPassword, "", 0, true);\r
+       HashPassword(h->SecurePassword, ADMINISTRATOR_USERNAME, "");\r
+       h->lock = NewLock();\r
+       h->lock_online = NewLock();\r
+       h->ref = NewRef();\r
+       h->Cedar = cedar;\r
+       AddRef(h->Cedar->ref);\r
+       h->Type = HUB_TYPE_STANDALONE;\r
+\r
+       ConvertSafeFileName(safe_hub_name, sizeof(safe_hub_name), HubName);\r
+       h->Name = CopyStr(safe_hub_name);\r
+\r
+       h->AdminOptionList = NewList(CompareAdminOption);\r
+       AddHubAdminOptionsDefaults(h, true);\r
+\r
+       h->LastCommTime = SystemTime64();\r
+       h->LastLoginTime = SystemTime64();\r
+       h->NumLogin = 0;\r
+\r
+       h->TrafficLock = NewLock();\r
+\r
+       h->HubDb = NewHubDb();\r
+\r
+       h->SessionList = NewList(NULL);\r
+       h->SessionCounter = NewCounter();\r
+       h->NumSessions = NewCounter();\r
+       h->NumSessionsClient = NewCounter();\r
+       h->NumSessionsBridge = NewCounter();\r
+       h->MacTable = NewList(CompareMacTable);\r
+       h->IpTable = NewList(CompareIpTable);\r
+       h->MonitorList = NewList(NULL);\r
+       h->LinkList = NewList(NULL);\r
+\r
+       h->Traffic = NewTraffic();\r
+       h->OldTraffic = NewTraffic();\r
+\r
+       h->Option = ZeroMalloc(sizeof(HUB_OPTION));\r
+       Copy(h->Option, option, sizeof(HUB_OPTION));\r
+\r
+       if (h->Option->VlanTypeId == 0)\r
+       {\r
+               h->Option->VlanTypeId = MAC_PROTO_TAGVLAN;\r
+       }\r
+\r
+       Rand(h->HubSignature, sizeof(h->HubSignature));\r
+\r
+       // SecureNAT 関係\r
+       h->EnableSecureNAT = false;\r
+       h->SecureNAT = NULL;\r
+       h->SecureNATOption = ZeroMalloc(sizeof(VH_OPTION));\r
+       NiSetDefaultVhOption(NULL, h->SecureNATOption);\r
+\r
+       if (h->Cedar != NULL && h->Cedar->Server != NULL && h->Cedar->Server->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               NiClearUnsupportedVhOptionForDynamicHub(h->SecureNATOption, true);\r
+       }\r
+\r
+       // HUB 用の一時的な MAC アドレスを生成する\r
+       GenerateMachineUniqueHash(hash);\r
+       GenHubMacAddress(h->HubMacAddr, h->Name);\r
+       GenHubIpAddress(&h->HubIp, h->Name);\r
+\r
+       // HUB 用 IPv6 アドレス\r
+       GenerateEui64LocalAddress(&ip6, h->HubMacAddr);\r
+       IPToIPv6Addr(&h->HubIpV6, &ip6);\r
+\r
+       h->RadiusOptionLock = NewLock();\r
+       h->RadiusServerPort = RADIUS_DEFAULT_PORT;\r
+\r
+       h->TicketList = NewList(NULL);\r
+\r
+       InitAccessList(h);\r
+\r
+       // デフォルトのログ設定\r
+       h->LogSetting.SaveSecurityLog = true;\r
+       h->LogSetting.SavePacketLog = false;\r
+       h->LogSetting.PacketLogConfig[PACKET_LOG_TCP_CONN] =\r
+               h->LogSetting.PacketLogConfig[PACKET_LOG_DHCP] = PACKET_LOG_HEADER;\r
+       h->LogSetting.SecurityLogSwitchType = LOG_SWITCH_DAY;\r
+       h->LogSetting.PacketLogSwitchType = LOG_SWITCH_DAY;\r
+\r
+       MakeDir(HUB_SECURITY_LOG_DIR_NAME);\r
+       MakeDir(HUB_PACKET_LOG_DIR_NAME);\r
+\r
+       // パケットロガーの開始\r
+       Format(packet_logger_name, sizeof(packet_logger_name), HUB_PACKET_LOG_FILE_NAME, h->Name);\r
+       h->PacketLogger = NewLog(packet_logger_name, HUB_PACKET_LOG_PREFIX, h->LogSetting.PacketLogSwitchType);\r
+\r
+       // セキュリティロガーの開始\r
+       Format(tmp, sizeof(tmp), HUB_SECURITY_LOG_FILE_NAME, h->Name);\r
+       h->SecurityLogger = NewLog(tmp, HUB_SECURITY_LOG_PREFIX, h->LogSetting.SecurityLogSwitchType);\r
+\r
+       if (h->Cedar->Server != NULL && h->Cedar->Server->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               h->FarmMember = true;\r
+       }\r
+\r
+       // HUB の開始\r
+       SetHubOnline(h);\r
+\r
+       if (h->Cedar->Bridge)\r
+       {\r
+               h->Option->NoArpPolling = true;\r
+       }\r
+\r
+       if (h->Option->NoArpPolling == false && h->Option->NoIpTable == false)\r
+       {\r
+               StartHubWatchDog(h);\r
+               h->WatchDogStarted = true;\r
+       }\r
+\r
+       SLog(h->Cedar, "LS_HUB_START", h->Name);\r
+\r
+       MacToStr(tmp, sizeof(tmp), h->HubMacAddr);\r
+       SLog(h->Cedar, "LS_HUB_MAC", h->Name, tmp);\r
+\r
+       return h;\r
+}\r
+\r
+// HUBDB の削除\r
+void DeleteHubDb(HUBDB *d)\r
+{\r
+       // 引数チェック\r
+       if (d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(d->UserList);\r
+       {\r
+               LockList(d->GroupList);\r
+               {\r
+                       // すべてのユーザーとグループを解放\r
+                       UINT i;\r
+                       USER **users;\r
+                       USERGROUP **groups;\r
+\r
+                       users = ToArray(d->UserList);\r
+                       groups = ToArray(d->GroupList);\r
+\r
+                       for (i = 0;i < LIST_NUM(d->UserList);i++)\r
+                       {\r
+                               ReleaseUser(users[i]);\r
+                       }\r
+                       for (i = 0;i < LIST_NUM(d->GroupList);i++)\r
+                       {\r
+                               ReleaseGroup(groups[i]);\r
+                       }\r
+\r
+                       Free(users);\r
+                       Free(groups);\r
+               }\r
+               UnlockList(d->GroupList);\r
+       }\r
+       UnlockList(d->UserList);\r
+\r
+       // ルート証明書一覧を解放\r
+       LockList(d->RootCertList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(d->RootCertList);i++)\r
+               {\r
+                       X *x = LIST_DATA(d->RootCertList, i);\r
+                       FreeX(x);\r
+               }\r
+       }\r
+       UnlockList(d->RootCertList);\r
+\r
+       // CRL を解放\r
+       LockList(d->CrlList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(d->CrlList);i++)\r
+               {\r
+                       CRL *crl = LIST_DATA(d->CrlList, i);\r
+                       FreeCrl(crl);\r
+               }\r
+       }\r
+       UnlockList(d->CrlList);\r
+\r
+       ReleaseList(d->GroupList);\r
+       ReleaseList(d->UserList);\r
+       ReleaseList(d->RootCertList);\r
+       ReleaseList(d->CrlList);\r
+       Free(d);\r
+}\r
+\r
+// HUB のログ設定を取得する\r
+void GetHubLogSetting(HUB *h, HUB_LOG *setting)\r
+{\r
+       // 引数チェック\r
+       if (setting == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Copy(setting, &h->LogSetting, sizeof(HUB_LOG));\r
+}\r
+\r
+// HUB のログ設定を更新する\r
+void SetHubLogSettingEx(HUB *h, HUB_LOG *setting, bool no_change_switch_type)\r
+{\r
+       UINT i1, i2;\r
+       // 引数チェック\r
+       if (setting == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       i1 = h->LogSetting.PacketLogSwitchType;\r
+       i2 = h->LogSetting.SecurityLogSwitchType;\r
+\r
+       Copy(&h->LogSetting, setting, sizeof(HUB_LOG));\r
+\r
+       if (no_change_switch_type)\r
+       {\r
+               h->LogSetting.PacketLogSwitchType = i1;\r
+               h->LogSetting.SecurityLogSwitchType = i2;\r
+       }\r
+\r
+       // パケットロガー設定\r
+       SetLogSwitchType(h->PacketLogger, setting->PacketLogSwitchType);\r
+       SetLogSwitchType(h->SecurityLogger, setting->SecurityLogSwitchType);\r
+}\r
+void SetHubLogSetting(HUB *h, HUB_LOG *setting)\r
+{\r
+       SetHubLogSettingEx(h, setting, false);\r
+}\r
+\r
+// HUB に信頼するルート証明書を追加する\r
+void AddRootCert(HUB *hub, X *x)\r
+{\r
+       HUBDB *db;\r
+       // 引数チェック\r
+       if (hub == NULL || x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       db = hub->HubDb;\r
+       if (db != NULL)\r
+       {\r
+               LockList(db->RootCertList);\r
+               {\r
+                       if (LIST_NUM(db->RootCertList) < MAX_HUB_CERTS)\r
+                       {\r
+                               UINT i;\r
+                               bool ok = true;\r
+\r
+                               for (i = 0;i < LIST_NUM(db->RootCertList);i++)\r
+                               {\r
+                                       X *exist_x = LIST_DATA(db->RootCertList, i);\r
+                                       if (CompareX(exist_x, x))\r
+                                       {\r
+                                               ok = false;\r
+                                               break;\r
+                                       }\r
+                               }\r
+\r
+                               if (ok)\r
+                               {\r
+                                       Insert(db->RootCertList, CloneX(x));\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(db->RootCertList);\r
+       }\r
+}\r
+\r
+// 証明書リストの比較\r
+int CompareCert(void *p1, void *p2)\r
+{\r
+       X *x1, *x2;\r
+       wchar_t tmp1[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       x1 = *(X **)p1;\r
+       x2 = *(X **)p2;\r
+       if (x1 == NULL || x2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       GetPrintNameFromX(tmp1, sizeof(tmp1), x1);\r
+       GetPrintNameFromX(tmp2, sizeof(tmp2), x2);\r
+\r
+       return UniStrCmpi(tmp1, tmp2);\r
+}\r
+\r
+// 新しい HUBDB の作成\r
+HUBDB *NewHubDb()\r
+{\r
+       HUBDB *d = ZeroMalloc(sizeof(HUBDB));\r
+\r
+       d->GroupList = NewList(CompareGroupName);\r
+       d->UserList = NewList(CompareUserName);\r
+       d->RootCertList = NewList(CompareCert);\r
+       d->CrlList = NewList(NULL);\r
+\r
+       return d;\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Hub.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Hub.h
new file mode 100644 (file)
index 0000000..802a015
--- /dev/null
@@ -0,0 +1,510 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Hub.h\r
+// Hub.c のヘッダ\r
+\r
+#ifndef        HUB_H\r
+#define        HUB_H\r
+\r
+\r
+\r
+// SoftEther リンク制御パケット\r
+struct SE_LINK\r
+{\r
+       UCHAR DestMacAddress[6];                        // 宛先 MAC アドレス\r
+       UCHAR SrcMacAddress[6];                         // 送信元 MAC アドレス\r
+       UCHAR SignatureS;                                       // 'S'\r
+       UCHAR SignatureE;                                       // 'E'\r
+       UCHAR Padding[2];                                       // パディング\r
+       UINT Type;                                                      // 種類\r
+       UCHAR HubSignature[16];                         // HUB シグネチャ\r
+       UINT TransactionId;                                     // トランザクション ID\r
+       UINT Data;                                                      // データ\r
+       UCHAR Dummy[20];                                        // ダミー\r
+       UCHAR Checksum[SHA1_SIZE];                      // チェックサム\r
+};\r
+\r
+\r
+// テストパケット受信記録\r
+struct TEST_HISTORY\r
+{\r
+       SESSION *s1;\r
+       SESSION *s2;\r
+};\r
+\r
+// リンクテスト用状態マシン\r
+struct SE_TEST\r
+{\r
+       LOCK *lock;                                                     // ロック\r
+       UINT64 LastTestPacketSentTime;          // 最後にテストパケットを送信した時刻\r
+       UINT NextTestPacketSendInterval;        // 次のテストパケット送信間隔\r
+       bool CurrentTesting;                            // 現在テストパケットを送信してテスト中\r
+       UINT TransactionId;                                     // トランザクション ID\r
+       LIST *TestHistory;                                      // 受信履歴\r
+};\r
+\r
+// マクロ\r
+#define        NO_ACCOUNT_DB(h)                ((h)->FarmMember)\r
+\r
+// スタンドアロンまたはファームマスタ HUB の場合のデータベース\r
+struct HUBDB\r
+{\r
+       LIST *UserList;                                         // ユーザーリスト\r
+       LIST *GroupList;                                        // グループリスト\r
+       LIST *RootCertList;                                     // 信頼する証明書リスト\r
+       LIST *CrlList;                                          // CRL リスト\r
+};\r
+\r
+// トラフィック リミッタ\r
+struct TRAFFIC_LIMITER\r
+{\r
+       UINT64 LastTime;                                        // 最後に測定した時刻\r
+       UINT64 Value;                                           // 現在の値\r
+};\r
+\r
+// エンドポイントごとのブロードキャスト数記録\r
+struct STORM\r
+{\r
+       UCHAR MacAddress[6];                            // MAC アドレス\r
+       UCHAR Padding[2];                                       // パディング\r
+       IP SrcIp;                                                       // 送信元 IP アドレス\r
+       IP DestIp;                                                      // 宛先 IP アドレス\r
+       UINT64 CheckStartTick;                          // チェックを開始した時刻\r
+       UINT CurrentBroadcastNum;                       // 現在のブロードキャスト個数\r
+       UINT DiscardValue;                                      // ブロードキャストパケットを破棄する割合\r
+};\r
+\r
+// HUB 用パケットアダプタ情報構造体\r
+struct HUB_PA\r
+{\r
+       CANCEL *Cancel;                                         // キャンセルオブジェクト\r
+       QUEUE *PacketQueue;                                     // パケットキュー\r
+       bool MonitorPort;                                       // モニタポート\r
+       UINT64 Now;                                                     // 現在時刻\r
+       TRAFFIC_LIMITER UploadLimiter;          // アップロード帯域幅制限\r
+       TRAFFIC_LIMITER DownloadLimiter;        // ダウンロード帯域幅制限\r
+       SESSION *Session;                                       // セッション\r
+       LIST *StormList;                                        // ブロードキャスト嵐記録用リスト\r
+       UINT UsernameHash;                                      // ユーザー名ハッシュ\r
+       UINT GroupnameHash;                                     // グループ名ハッシュ\r
+};\r
+\r
+// HUB オプション\r
+struct HUB_OPTION\r
+{\r
+       // 標準オプション\r
+       UINT MaxSession;                                        // 最大同時接続数\r
+       bool NoEnum;                                            // 列挙の対象外\r
+       // 拡張オプション\r
+       bool NoArpPolling;                                      // ARP ポーリングしない\r
+       bool NoIPv6AddrPolling;                         // IPv6 アドレスポーリングしない\r
+       bool NoIpTable;                                         // IP アドレステーブルを生成しない\r
+       bool NoMacAddressLog;                           // MAC アドレスの登録ログを書き込まない\r
+       bool ManageOnlyPrivateIP;                       // プライベート IP のみを管理対象にする\r
+       bool ManageOnlyLocalUnicastIPv6;        // ローカルユニキャスト IPv6 アドレスのみを管理対象にする\r
+       bool DisableIPParsing;                          // IP 解釈を禁止する\r
+       bool YieldAfterStorePacket;                     // パケットをストアした後イールドする\r
+       bool NoSpinLockForPacketDelay;          // スピンロックを使用しない\r
+       UINT BroadcastStormDetectionThreshold;  // ブロードキャスト数制限閾値\r
+       bool FilterPPPoE;                                       // PPPoE をフィルタリングする (0x8863, 0x8864)\r
+       bool FilterOSPF;                                        // OSPF をフィルタリングする (ip_proto=89)\r
+       bool FilterIPv4;                                        // IPv4 パケットをフィルタリングする\r
+       bool FilterIPv6;                                        // IPv6 パケットをフィルタリングする\r
+       bool FilterNonIP;                                       // 非 IP パケットをすべてフィルタリング\r
+       bool FilterBPDU;                                        // BPDU パケットをフィルタリングする\r
+       UINT ClientMinimumRequiredBuild;        // クライアントのビルド番号が一定以下であれば拒否\r
+       bool NoIPv6DefaultRouterInRAWhenIPv6;   // IPv6 ルータ広告からデフォルトルータ指定を削除 (IPv6 物理接続時のみ)\r
+       bool NoIPv4PacketLog;                           // IPv4 パケットのパケットログを保存しない\r
+       bool NoIPv6PacketLog;                           // IPv6 パケットのパケットログを保存しない\r
+       bool NoLookBPDUBridgeId;                        // スイッチングのために BPDU ブリッジ ID を見ない\r
+       bool NoManageVlanId;                            // VLAN ID を管理しない\r
+       UINT VlanTypeId;                                        // VLAN パケットの Type ID (通常は 0x8100)\r
+       bool FixForDLinkBPDU;                           // D-Link の変な挙動をする BPDU のための fix を適用する\r
+       UINT RequiredClientId;                          // クライアント ID\r
+};\r
+\r
+// MAC テーブルエントリ\r
+struct MAC_TABLE_ENTRY\r
+{\r
+       UCHAR MacAddress[6];                            // MAC アドレス\r
+       UCHAR Padding[2];\r
+       UINT VlanId;                                            // VLAN ID\r
+       SESSION *Session;                                       // セッション\r
+       HUB_PA *HubPa;                                          // HUB パケットアダプタ\r
+       UINT64 CreatedTime;                                     // 作成日時\r
+       UINT64 UpdatedTime;                                     // 更新日時\r
+};\r
+\r
+// IP テーブルエントリ\r
+struct IP_TABLE_ENTRY\r
+{\r
+       IP Ip;                                                          // IP アドレス\r
+       SESSION *Session;                                       // セッション\r
+       bool DhcpAllocated;                                     // DHCP によって割り当て済み\r
+       UINT64 CreatedTime;                                     // 作成日時\r
+       UINT64 UpdatedTime;                                     // 更新日時\r
+       UCHAR MacAddress[6];                            // MAC アドレス\r
+};\r
+\r
+// ループリスト\r
+struct LOOP_LIST\r
+{\r
+       UINT NumSessions;\r
+       SESSION **Session;\r
+};\r
+\r
+// アクセスリスト\r
+struct ACCESS\r
+{\r
+       // IPv4\r
+       UINT Id;                                                        // ID\r
+       wchar_t Note[MAX_ACCESSLIST_NOTE_LEN + 1];      // メモ\r
+       bool Active;                                            // 有効フラグ\r
+       UINT Priority;                                          // 優先順位\r
+       bool Discard;                                           // 破棄フラグ\r
+       UINT SrcIpAddress;                                      // 送信元 IP アドレス\r
+       UINT SrcSubnetMask;                                     // 送信元サブネットマスク\r
+       UINT DestIpAddress;                                     // 宛先 IP アドレス\r
+       UINT DestSubnetMask;                            // 宛先サブネットマスク\r
+       UINT Protocol;                                          // プロトコル\r
+       UINT SrcPortStart;                                      // 送信元ポート番号開始点\r
+       UINT SrcPortEnd;                                        // 送信元ポート番号終了点\r
+       UINT DestPortStart;                                     // 宛先ポート番号開始点\r
+       UINT DestPortEnd;                                       // 宛先ポート番号終了点\r
+       UINT SrcUsernameHash;                           // 送信元ユーザー名ハッシュ\r
+       char SrcUsername[MAX_USERNAME_LEN + 1];\r
+       UINT DestUsernameHash;                          // 宛先ユーザー名ハッシュ\r
+       char DestUsername[MAX_USERNAME_LEN + 1];\r
+       bool CheckSrcMac;                                       // 送信元 MAC アドレスの設定の有無\r
+       UCHAR SrcMacAddress[6];                         // 送信元 MAC アドレス\r
+       UCHAR SrcMacMask[6];                            // 送信元 MAC アドレスマスク\r
+       bool CheckDstMac;                                       // 宛先 MAC アドレスの設定の有無\r
+       UCHAR DstMacAddress[6];                         // 宛先 MAC アドレス\r
+       UCHAR DstMacMask[6];                            // 宛先 MAC アドレスマスク\r
+       bool CheckTcpState;                                     // TCP コネクションの状態\r
+       bool Established;                                       // Establieshed(TCP)\r
+       UINT Delay;                                                     // 遅延\r
+       UINT Jitter;                                            // ジッタ\r
+       UINT Loss;                                                      // パケットロス\r
+\r
+       // IPv6\r
+       bool IsIPv6;                                            // IPv6 かどうか\r
+       IPV6_ADDR SrcIpAddress6;                        // 送信元 IP アドレス (IPv6)\r
+       IPV6_ADDR SrcSubnetMask6;                       // 送信元サブネットマスク (IPv6)\r
+       IPV6_ADDR DestIpAddress6;                       // 宛先 IP アドレス (IPv6)\r
+       IPV6_ADDR DestSubnetMask6;                      // 宛先サブネットマスク (IPv6)\r
+};\r
+\r
+// チケット\r
+struct TICKET\r
+{\r
+       UINT64 CreatedTick;                                             // 作成日時\r
+       UCHAR Ticket[SHA1_SIZE];                                // チケット\r
+       char Username[MAX_USERNAME_LEN + 1];    // ユーザー名\r
+       char UsernameReal[MAX_USERNAME_LEN + 1];        // 本当のユーザー名\r
+       char GroupName[MAX_USERNAME_LEN + 1];   // グループ名\r
+       char SessionName[MAX_SESSION_NAME_LEN + 1];     // セッション名\r
+       POLICY Policy;                                                  // ポリシー\r
+};\r
+\r
+// トラフィック差分\r
+struct TRAFFIC_DIFF\r
+{\r
+       UINT Type;                                                      // 種別\r
+       TRAFFIC Traffic;                                        // トラフィック\r
+       char *HubName;                                          // HUB 名\r
+       char *Name;                                                     // 名前\r
+};\r
+\r
+// 管理オプション\r
+struct ADMIN_OPTION\r
+{\r
+       char Name[MAX_ADMIN_OPTION_NAME_LEN + 1];       // 名前\r
+       UINT Value;                                                                     // データ\r
+};\r
+\r
+// 証明書無効エントリ\r
+struct CRL\r
+{\r
+       X_SERIAL *Serial;                                       // シリアル番号\r
+       NAME *Name;                                                     // 名前情報\r
+       UCHAR DigestMD5[MD5_SIZE];                      // MD5 ハッシュ\r
+       UCHAR DigestSHA1[SHA1_SIZE];            // SHA-1 ハッシュ\r
+};\r
+\r
+// アクセスコントロール\r
+struct AC\r
+{\r
+       UINT Id;                                                        // ID\r
+       UINT Priority;                                          // 優先順位\r
+       bool Deny;                                                      // アクセスを拒否\r
+       bool Masked;                                            // マスクされているかどうか\r
+       IP IpAddress;                                           // IP アドレス\r
+       IP SubnetMask;                                          // サブネットマスク\r
+};\r
+\r
+// HUB 構造体\r
+struct HUB\r
+{\r
+       LOCK *lock;                                                     // ロック\r
+       LOCK *lock_online;                                      // オンライン用ロック\r
+       REF *ref;                                                       // 参照カウンタ\r
+       CEDAR *Cedar;                                           // Cedar\r
+       UINT Type;                                                      // 種類\r
+       HUBDB *HubDb;                                           // データベース\r
+       char *Name;                                                     // HUB の名前\r
+       LOCK *RadiusOptionLock;                         // Radius オプション用ロック\r
+       char *RadiusServerName;                         // Radius サーバー名\r
+       UINT RadiusServerPort;                          // Radius サーバーポート番号\r
+       UINT RadiusRetryInterval;                       // Radius 再試行間隔\r
+       BUF *RadiusSecret;                                      // Radius 共有鍵\r
+       volatile bool Halt;                                     // 停止フラグ\r
+       bool Offline;                                           // オフライン\r
+       bool BeingOffline;                                      // オフライン化中\r
+       LIST *SessionList;                                      // セッションリスト\r
+       COUNTER *SessionCounter;                        // セッション番号生成カウンタ\r
+       TRAFFIC *Traffic;                                       // トラフィック情報\r
+       TRAFFIC *OldTraffic;                            // 古いトラフィック情報\r
+       LOCK *TrafficLock;                                      // トラフィックロック\r
+       COUNTER *NumSessions;                           // 現在のセッション数\r
+       COUNTER *NumSessionsClient;                     // 現在のセッション数 (クライアント)\r
+       COUNTER *NumSessionsBridge;                     // 現在のセッション数 (ブリッジ)\r
+       HUB_OPTION *Option;                                     // HUB オプション\r
+       LIST *MacTable;                                         // MAC アドレステーブル\r
+       LIST *IpTable;                                          // IP アドレステーブル\r
+       LIST *MonitorList;                                      // モニタポートセッションリスト\r
+       LIST *LinkList;                                         // リンクリスト\r
+       UCHAR HubSignature[16];                         // HUB シグネチャ\r
+       UCHAR HubMacAddr[6];                            // HUB の MAC アドレス\r
+       IP HubIp;                                                       // HUB の IP アドレス (IPv4)\r
+       IPV6_ADDR HubIpV6;                                      // HUB の IP アドレス (IPv6)\r
+       UINT HubIP6Id;                                          // HUB の IPv6 パケット ID\r
+       UCHAR Padding[2];                                       // パディング\r
+       LOCK *LoopListLock;                                     // ループリスト用ロック\r
+       UINT NumLoopList;                                       // ループリスト数\r
+       LOOP_LIST **LoopLists;                          // ループリスト\r
+       LIST *AccessList;                                       // アクセスリスト\r
+       HUB_LOG LogSetting;                                     // ログ設定\r
+       LOG *PacketLogger;                                      // パケットロガー\r
+       LOG *SecurityLogger;                            // セキュリティロガー\r
+       UCHAR HashedPassword[SHA1_SIZE];        // パスワード\r
+       UCHAR SecurePassword[SHA1_SIZE];        // セキュアパスワード\r
+       LIST *TicketList;                                       // チケットリスト\r
+       bool FarmMember;                                        // ファームメンバー\r
+       UINT64 LastIncrementTraffic;            // トラフィック報告時刻\r
+       UINT64 LastSendArpTick;                         // 最後の ARP 送信時刻\r
+       SNAT *SecureNAT;                                        // SecureNAT\r
+       bool EnableSecureNAT;                           // SecureNAT 有効/無効フラグ\r
+       VH_OPTION *SecureNATOption;                     // SecureNAT のオプション\r
+       THREAD *WatchDogThread;                         // 番犬スレッド\r
+       EVENT *WatchDogEvent;                           // 番犬イベント\r
+       bool WatchDogStarted;                           // 番犬スレッドが使用されているかどうか\r
+       volatile bool HaltWatchDog;                     // 番犬スレッドの停止\r
+       LIST *AdminOptionList;                          // 管理オプションリスト\r
+       UINT64 CreatedTime;                                     // 作成日時\r
+       UINT64 LastCommTime;                            // 最終通信日時\r
+       UINT64 LastLoginTime;                           // 最終ログイン日時\r
+       UINT NumLogin;                                          // ログイン回数\r
+       bool HubIsOnlineButHalting;                     // 仮想 HUB は本当はオンラインだが停止のためにオフライン化してある\r
+       UINT FarmMember_MaxSessionClient;       // クラスタメンバ用 最大クライアント接続セッション数\r
+       UINT FarmMember_MaxSessionBridge;       // クラスタメンバ用 最大ブリッジ接続セッション数\r
+       bool FarmMember_MaxSessionClientBridgeApply;    // FarmMember_MaxSession* を適用する\r
+       UINT CurrentVersion;                            // 現在のバージョン\r
+       UINT LastVersion;                                       // 最後に更新通知を発行したときのバージョン\r
+       wchar_t *Msg;                                           // クライアントが接続してきたときに表示するメッセージ\r
+};\r
+\r
+\r
+// グローバル変数\r
+extern ADMIN_OPTION admin_options[];\r
+extern UINT num_admin_options;\r
+\r
+\r
+// 関数プロトタイプ\r
+HUBDB *NewHubDb();\r
+void DeleteHubDb(HUBDB *d);\r
+HUB *NewHub(CEDAR *cedar, char *HubName, HUB_OPTION *option);\r
+void SetHubMsg(HUB *h, wchar_t *msg);\r
+wchar_t *GetHubMsg(HUB *h);\r
+void GenHubMacAddress(UCHAR *mac, char *name);\r
+void GenHubIpAddress(IP *ip, char *name);\r
+bool IsHubIpAddress(IP *ip);\r
+bool IsHubIpAddress32(UINT ip32);\r
+bool IsHubIpAddress64(IPV6_ADDR *addr);\r
+bool IsHubMacAddress(UCHAR *mac);\r
+void ReleaseHub(HUB *h);\r
+void CleanupHub(HUB *h);\r
+int CompareHub(void *p1, void *p2);\r
+void LockHubList(CEDAR *cedar);\r
+void UnlockHubList(CEDAR *cedar);\r
+HUB *GetHub(CEDAR *cedar, char *name);\r
+bool IsHub(CEDAR *cedar, char *name);\r
+void StopHub(HUB *h);\r
+void AddSession(HUB *h, SESSION *s);\r
+void DelSession(HUB *h, SESSION *s);\r
+void StopAllSession(HUB *h);\r
+bool HubPaInit(SESSION *s);\r
+void HubPaFree(SESSION *s);\r
+CANCEL *HubPaGetCancel(SESSION *s);\r
+UINT HubPaGetNextPacket(SESSION *s, void **data);\r
+bool HubPaPutPacket(SESSION *s, void *data, UINT size);\r
+PACKET_ADAPTER *GetHubPacketAdapter();\r
+int CompareMacTable(void *p1, void *p2);\r
+void StorePacket(HUB *hub, SESSION *s, PKT *packet);\r
+bool StorePacketFilter(SESSION *s, PKT *packet);\r
+void StorePacketToHubPa(HUB_PA *dest, SESSION *src, void *data, UINT size, PKT *packet);\r
+void SetHubOnline(HUB *h);\r
+void SetHubOffline(HUB *h);\r
+SESSION *GetSessionByPtr(HUB *hub, void *ptr);\r
+SESSION *GetSessionByName(HUB *hub, char *name);\r
+int CompareIpTable(void *p1, void *p2);\r
+bool StorePacketFilterByPolicy(SESSION *s, PKT *p);\r
+bool DeleteIPv6DefaultRouterInRA(PKT *p);\r
+bool StorePacketFilterByTrafficLimiter(SESSION *s, PKT *p);\r
+void IntoTrafficLimiter(TRAFFIC_LIMITER *tr, PKT *p);\r
+bool IsMostHighestPriorityPacket(SESSION *s, PKT *p);\r
+bool IsPriorityPacketForQoS(PKT *p);\r
+int CompareStormList(void *p1, void *p2);\r
+STORM *SearchStormList(HUB_PA *pa, UCHAR *mac_address, IP *src_ip, IP *dest_ip);\r
+STORM *AddStormList(HUB_PA *pa, UCHAR *mac_address, IP *src_ip, IP *dest_ip);\r
+bool CheckBroadcastStorm(SESSION *s, PKT *p);\r
+void AddRootCert(HUB *hub, X *x);\r
+int CmpAccessList(void *p1, void *p2);\r
+void InitAccessList(HUB *hub);\r
+void FreeAccessList(HUB *hub);\r
+void AddAccessList(HUB *hub, ACCESS *a);\r
+UINT UsernameToInt(char *name);\r
+bool ApplyAccessListToStoredPacket(HUB *hub, SESSION *s, PKT *p);\r
+bool ApplyAccessListToForwardPacket(HUB *hub, SESSION *src_session, SESSION *dest_session, PKT *p);\r
+bool IsPacketMaskedByAccessList(SESSION *s, PKT *p, ACCESS *a, UINT dest_username, UINT dest_groupname);\r
+void GetAccessListStr(char *str, UINT size, ACCESS *a);\r
+void DeleteOldIpTableEntry(LIST *o);\r
+void SetRadiusServer(HUB *hub, char *name, UINT port, char *secret);\r
+void SetRadiusServerEx(HUB *hub, char *name, UINT port, char *secret, UINT interval);\r
+bool GetRadiusServer(HUB *hub, char *name, UINT size, UINT *port, char *secret, UINT secret_size);\r
+bool GetRadiusServerEx(HUB *hub, char *name, UINT size, UINT *port, char *secret, UINT secret_size, UINT *interval);\r
+int CompareCert(void *p1, void *p2);\r
+void GetHubLogSetting(HUB *h, HUB_LOG *setting);\r
+void SetHubLogSetting(HUB *h, HUB_LOG *setting);\r
+void SetHubLogSettingEx(HUB *h, HUB_LOG *setting, bool no_change_switch_type);\r
+void DeleteExpiredIpTableEntry(LIST *o);\r
+void DeleteExpiredMacTableEntry(LIST *o);\r
+void AddTrafficDiff(HUB *h, char *name, UINT type, TRAFFIC *traffic);\r
+void IncrementHubTraffic(HUB *h);\r
+void EnableSecureNAT(HUB *h, bool enable);\r
+void EnableSecureNATEx(HUB *h, bool enable, bool no_change);\r
+void StartHubWatchDog(HUB *h);\r
+void StopHubWatchDog(HUB *h);\r
+void HubWatchDogThread(THREAD *t, void *param);\r
+int CompareAdminOption(void *p1, void *p2);\r
+UINT GetHubAdminOptionEx(HUB *h, char *name, UINT default_value);\r
+UINT GetHubAdminOption(HUB *h, char *name);\r
+void DeleteAllHubAdminOption(HUB *h, bool lock);\r
+void AddHubAdminOptionsDefaults(HUB *h, bool lock);\r
+bool IsCertMatchCrl(X *x, CRL *crl);\r
+bool IsCertMatchCrlList(X *x, LIST *o);\r
+wchar_t *GenerateCrlStr(CRL *crl);\r
+bool IsValidCertInHub(HUB *h, X *x);\r
+void FreeCrl(CRL *crl);\r
+CRL *CopyCrl(CRL *crl);\r
+int CmpAc(void *p1, void *p2);\r
+LIST *NewAcList();\r
+void AddAc(LIST *o, AC *ac);\r
+bool DelAc(LIST *o, UINT id);\r
+AC *GetAc(LIST *o, UINT id);\r
+void SetAc(LIST *o, UINT id, AC *ac);\r
+void DelAllAc(LIST *o);\r
+void SetAcList(LIST *o, LIST *src);\r
+void NormalizeAcList(LIST *o);\r
+char *GenerateAcStr(AC *ac);\r
+void FreeAcList(LIST *o);\r
+LIST *CloneAcList(LIST *o);\r
+bool IsIPPrivate(IP *ip);\r
+bool IsIPManagementTargetForHUB(IP *ip, HUB *hub);\r
+wchar_t *GetHubAdminOptionHelpString(char *name);\r
+void HubOptionStructToData(RPC_ADMIN_OPTION *ao, HUB_OPTION *o, char *hub_name);\r
+ADMIN_OPTION *NewAdminOption(char *name, UINT value);\r
+void DataToHubOptionStruct(HUB_OPTION *o, RPC_ADMIN_OPTION *ao);\r
+UINT GetHubAdminOptionData(RPC_ADMIN_OPTION *ao, char *name);\r
+void GetHubAdminOptionDataAndSet(RPC_ADMIN_OPTION *ao, char *name, UINT *dest);\r
+bool IsURLMsg(wchar_t *str, char *url, UINT url_size);\r
+\r
+\r
+#endif // HUB_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Layer3.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Layer3.c
new file mode 100644 (file)
index 0000000..c4485f6
--- /dev/null
@@ -0,0 +1,2167 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Layer3.c\r
+// Layer-3 スイッチ モジュール\r
+\r
+#include "CedarPch.h"\r
+\r
+static UCHAR broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};\r
+\r
+// IP キューの処理\r
+void L3PollingIpQueue(L3IF *f)\r
+{\r
+       L3PACKET *p;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 別のセッションから来たパケットを処理する\r
+       while (p = GetNext(f->IpPacketQueue))\r
+       {\r
+               PKT *pkt = p->Packet;\r
+\r
+               // IP パケットとして送信する\r
+               L3SendIp(f, p);\r
+       }\r
+}\r
+\r
+// IP パケットの処理\r
+void L3RecvIp(L3IF *f, PKT *p, bool self)\r
+{\r
+       IPV4_HEADER *ip;\r
+       UINT header_size;\r
+       UINT next_hop = 0;\r
+       L3IF *dst;\r
+       L3PACKET *packet;\r
+       UINT new_ttl = 0;\r
+       // 引数チェック\r
+       if (f == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ip = p->L3.IPv4Header;\r
+       header_size = IPV4_GET_HEADER_LEN(p->L3.IPv4Header) * 4;\r
+\r
+       // チェックサムの計算\r
+       if (IpCheckChecksum(ip) == false)\r
+       {\r
+               // チェックサムが一致しない\r
+               goto FREE_PACKET;\r
+       }\r
+\r
+       // ARP テーブルに登録\r
+       L3KnownArp(f, ip->SrcIP, p->MacAddressSrc);\r
+\r
+       if (p->BroadcastPacket)\r
+       {\r
+               // ブロードキャストパケットの場合はルーティングしない\r
+               goto FREE_PACKET;\r
+       }\r
+\r
+       // TTL を計算\r
+       if (ip->TimeToLive >= 1)\r
+       {\r
+               new_ttl = ip->TimeToLive - 1;\r
+       }\r
+       else\r
+       {\r
+               new_ttl = 0;\r
+       }\r
+\r
+       if (new_ttl == 0)\r
+       {\r
+               if (ip->DstIP != f->IpAddress)\r
+               {\r
+                       UINT src_packet_size = p->PacketSize - sizeof(MAC_HEADER);\r
+                       UINT icmp_packet_total_size = sizeof(MAC_HEADER) + sizeof(IPV4_HEADER) + sizeof(ICMP_HEADER) + 4 + header_size + 8;\r
+                       UCHAR *buf;\r
+                       IPV4_HEADER *ipv4;\r
+                       ICMP_HEADER *icmpv4;\r
+                       UCHAR *data;\r
+                       PKT *pkt;\r
+                       UINT data_size = MIN(p->PacketSize - header_size, header_size + 8);\r
+\r
+                       // TTL 切れが発生したことを知らせる ICMP メッセージを生成する\r
+                       buf = ZeroMalloc(icmp_packet_total_size);\r
+                       ipv4 = (IPV4_HEADER *)(buf + sizeof(MAC_HEADER));\r
+                       icmpv4 = (ICMP_HEADER *)(buf + sizeof(MAC_HEADER) + sizeof(IPV4_HEADER));\r
+                       data = buf + sizeof(MAC_HEADER) + sizeof(IPV4_HEADER) + sizeof(ICMP_HEADER) + 4;\r
+\r
+                       IPV4_SET_VERSION(ipv4, 4);\r
+                       IPV4_SET_HEADER_LEN(ipv4, sizeof(IPV4_HEADER) / 4);\r
+                       ipv4->TotalLength = Endian16((USHORT)(icmp_packet_total_size - sizeof(MAC_HEADER)));\r
+                       ipv4->TimeToLive = 0xff;\r
+                       ipv4->Protocol = IP_PROTO_ICMPV4;\r
+                       ipv4->SrcIP = f->IpAddress;\r
+                       ipv4->DstIP = ip->SrcIP;\r
+                       ipv4->Checksum = IpChecksum(ipv4, sizeof(IPV4_HEADER));\r
+\r
+                       icmpv4->Type = 11;\r
+                       Copy(data, ip, data_size);\r
+                       icmpv4->Checksum = IpChecksum(icmpv4, sizeof(ICMP_HEADER) + data_size + 4);\r
+\r
+                       buf[12] = 0x08;\r
+                       buf[13] = 0x00;\r
+\r
+                       pkt = ParsePacket(buf, icmp_packet_total_size);\r
+                       if (pkt == NULL)\r
+                       {\r
+                               Free(buf);\r
+                       }\r
+                       else\r
+                       {\r
+                               L3RecvIp(f, pkt, true);\r
+                       }\r
+\r
+                       // TTL が切れたパケット本体は破棄する\r
+                       goto FREE_PACKET;\r
+               }\r
+       }\r
+\r
+       // 書き換える\r
+       p->L3.IPv4Header->TimeToLive = (UCHAR)new_ttl;\r
+\r
+       // 宛先 IP アドレスに対するインターフェイスを取得する\r
+       dst = L3GetNextIf(f->Switch, ip->DstIP, &next_hop);\r
+\r
+       if (dst == NULL && self == false)\r
+       {\r
+               UINT src_packet_size = p->PacketSize - sizeof(MAC_HEADER);\r
+               UINT icmp_packet_total_size = sizeof(MAC_HEADER) + sizeof(IPV4_HEADER) + sizeof(ICMP_HEADER) + 4 + header_size + 8;\r
+               UCHAR *buf;\r
+               IPV4_HEADER *ipv4;\r
+               ICMP_HEADER *icmpv4;\r
+               UCHAR *data;\r
+               PKT *pkt;\r
+                       UINT data_size = MIN(p->PacketSize - header_size, header_size + 8);\r
+\r
+               // ルートが見つからない旨を ICMP で応答する\r
+               buf = ZeroMalloc(icmp_packet_total_size);\r
+               ipv4 = (IPV4_HEADER *)(buf + sizeof(MAC_HEADER));\r
+               icmpv4 = (ICMP_HEADER *)(buf + sizeof(MAC_HEADER) + sizeof(IPV4_HEADER));\r
+               data = buf + sizeof(MAC_HEADER) + sizeof(IPV4_HEADER) + sizeof(ICMP_HEADER) + 4;\r
+\r
+               IPV4_SET_VERSION(ipv4, 4);\r
+               IPV4_SET_HEADER_LEN(ipv4, sizeof(IPV4_HEADER) / 4);\r
+               ipv4->TotalLength = Endian16((USHORT)(icmp_packet_total_size - sizeof(MAC_HEADER)));\r
+               ipv4->TimeToLive = 0xff;\r
+               ipv4->Protocol = IP_PROTO_ICMPV4;\r
+               ipv4->SrcIP = f->IpAddress;\r
+               ipv4->DstIP = ip->SrcIP;\r
+               ipv4->Checksum = IpChecksum(ipv4, sizeof(IPV4_HEADER));\r
+\r
+               icmpv4->Type = 3;\r
+               Copy(data, ip, data_size);\r
+               icmpv4->Checksum = IpChecksum(icmpv4, sizeof(ICMP_HEADER) + data_size + 4);\r
+\r
+               buf[12] = 0x08;\r
+               buf[13] = 0x00;\r
+\r
+               pkt = ParsePacket(buf, icmp_packet_total_size);\r
+               if (pkt == NULL)\r
+               {\r
+                       Free(buf);\r
+               }\r
+               else\r
+               {\r
+                       L3RecvIp(f, pkt, true);\r
+               }\r
+\r
+               // ルートが見つからないパケット本体は破棄する\r
+               goto FREE_PACKET;\r
+       }\r
+\r
+       if (dst != NULL && ip->DstIP == dst->IpAddress)\r
+       {\r
+               bool free_packet = true;\r
+               // 自分宛の IP パケットが届いた\r
+               if (p->TypeL4 == L4_ICMPV4)\r
+               {\r
+                       ICMP_HEADER *icmp = p->L4.ICMPHeader;\r
+                       if (icmp->Type == ICMP_TYPE_ECHO_REQUEST)\r
+                       {\r
+                               // この IP パケットの宛先と送信元を書き換えて返信する\r
+                               UINT src_ip, dst_ip;\r
+                               src_ip = p->L3.IPv4Header->DstIP;\r
+                               dst_ip = p->L3.IPv4Header->SrcIP;\r
+\r
+                               p->L3.IPv4Header->DstIP = dst_ip;\r
+                               p->L3.IPv4Header->SrcIP = src_ip;\r
+\r
+                               ip->TimeToLive = 0xff;\r
+\r
+                               // チェックサムを再計算する\r
+                               ip->FlagsAndFlagmentOffset[0] = ip->FlagsAndFlagmentOffset[1] = 0;\r
+                               icmp->Checksum = 0;\r
+                               icmp->Type = ICMP_TYPE_ECHO_RESPONSE;\r
+                               icmp->Checksum = IpChecksum(icmp, p->PacketSize - sizeof(MAC_HEADER) - header_size);\r
+\r
+                               dst = L3GetNextIf(f->Switch, ip->DstIP, &next_hop);\r
+\r
+                               free_packet = false;\r
+                       }\r
+               }\r
+\r
+               if (free_packet)\r
+               {\r
+                       goto FREE_PACKET;\r
+               }\r
+       }\r
+\r
+       if (dst == NULL)\r
+       {\r
+               // 宛先が存在しない\r
+               goto FREE_PACKET;\r
+       }\r
+\r
+       // IP チェックサムの再計算\r
+       ip->Checksum = 0;\r
+       ip->Checksum = IpChecksum(ip, header_size);\r
+\r
+       // Layer-3 パケットとして処理する\r
+       packet = ZeroMalloc(sizeof(L3PACKET));\r
+       packet->Expire = Tick64() + IP_WAIT_FOR_ARP_TIMEOUT;\r
+       packet->NextHopIp = next_hop;\r
+       packet->Packet = p;\r
+\r
+       // 宛先セッションにストアする\r
+       L3StoreIpPacketToIf(f, dst, packet);\r
+\r
+       return;\r
+\r
+FREE_PACKET:\r
+       // パケットの解放\r
+       Free(p->PacketData);\r
+       FreePacket(p);\r
+       return;\r
+}\r
+\r
+// レイヤ 2 パケットの処理\r
+void L3RecvL2(L3IF *f, PKT *p)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 自分が送信したパケットか、ユニキャストパケットで自分宛で無いパケット\r
+       // はすべて無視する\r
+       if (Cmp(p->MacAddressSrc, f->MacAddress, 6) == 0 ||\r
+               (p->BroadcastPacket == false && Cmp(p->MacAddressDest, f->MacAddress, 6) != 0))\r
+       {\r
+               // パケット解放\r
+               Free(p->PacketData);\r
+               FreePacket(p);\r
+               return;\r
+       }\r
+\r
+       if (p->TypeL3 == L3_ARPV4)\r
+       {\r
+               // ARP パケットを受信した\r
+               L3RecvArp(f, p);\r
+\r
+               // パケット解放\r
+               Free(p->PacketData);\r
+               FreePacket(p);\r
+       }\r
+       else if (p->TypeL3 == L3_IPV4)\r
+       {\r
+               // IP パケットを受信した\r
+               L3RecvIp(f, p, false);\r
+       }\r
+       else\r
+       {\r
+               // パケット解放\r
+               Free(p->PacketData);\r
+               FreePacket(p);\r
+       }\r
+}\r
+\r
+// IP パケットを別のインターフェイスにストアする\r
+void L3StoreIpPacketToIf(L3IF *src_if, L3IF *dst_if, L3PACKET *p)\r
+{\r
+       // 引数チェック\r
+       if (src_if == NULL || p == NULL || dst_if == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ストア先セッションのキューに追加する\r
+       InsertQueue(dst_if->IpPacketQueue, p);\r
+\r
+       // ストア先セッションの Cancel オブジェクトを叩くことにする\r
+       AddCancelList(src_if->CancelList, dst_if->Session->Cancel1);\r
+}\r
+\r
+// パケットを書き込む (新しいパケットが届いたので処理する)\r
+void L3PutPacket(L3IF *f, void *data, UINT size)\r
+{\r
+       PKT *p;\r
+       L3SW *s;\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = f->Switch;\r
+\r
+       if (data != NULL)\r
+       {\r
+               // 次のパケットを処理する\r
+               if (f->CancelList == NULL)\r
+               {\r
+                       f->CancelList = NewCancelList();\r
+               }\r
+\r
+               // パケット解析\r
+               p = ParsePacket(data, size);\r
+\r
+               if (p == NULL)\r
+               {\r
+                       // パケット解析失敗\r
+                       Free(data);\r
+               }\r
+               else\r
+               {\r
+                       // パケット解析成功\r
+                       Lock(s->lock);\r
+                       {\r
+                               L3RecvL2(f, p);\r
+                       }\r
+                       Unlock(s->lock);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // すべてのパケットの処理が終わったらキャンセルリストをキャンセル処理する\r
+               if (f->CancelList != NULL)\r
+               {\r
+                       CancelList(f->CancelList);\r
+                       ReleaseCancelList(f->CancelList);\r
+                       f->CancelList = NULL;\r
+               }\r
+       }\r
+}\r
+\r
+// 待機している IP パケットのうち送信先 MAC アドレスが解決したものを送信する\r
+void L3SendWaitingIp(L3IF *f, UCHAR *mac, UINT ip, L3ARPENTRY *a)\r
+{\r
+       UINT i;\r
+       LIST *o = NULL;\r
+       // 引数チェック\r
+       if (f == NULL || mac == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(f->IpWaitList);i++)\r
+       {\r
+               L3PACKET *p = LIST_DATA(f->IpWaitList, i);\r
+\r
+               if (p->NextHopIp == ip)\r
+               {\r
+                       if (o == NULL)\r
+                       {\r
+                               o = NewListFast(NULL);\r
+                       }\r
+                       Add(o, p);\r
+               }\r
+       }\r
+\r
+       if (o != NULL)\r
+       {\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       L3PACKET *p = LIST_DATA(o, i);\r
+\r
+                       // 送信\r
+                       L3SendIpNow(f, a, p);\r
+\r
+                       Delete(f->IpWaitList, p);\r
+                       Free(p->Packet->PacketData);\r
+                       FreePacket(p->Packet);\r
+                       Free(p);\r
+               }\r
+\r
+               ReleaseList(o);\r
+       }\r
+}\r
+\r
+// ARP テーブルに登録する\r
+void L3InsertArpTable(L3IF *f, UINT ip, UCHAR *mac)\r
+{\r
+       L3ARPENTRY *a, t;\r
+       // 引数チェック\r
+       if (f == NULL || ip == 0 || ip == 0xffffffff || mac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.IpAddress = ip;\r
+\r
+       a = Search(f->ArpTable, &t);\r
+\r
+       if (a == NULL)\r
+       {\r
+               // リストに登録されていないので登録する\r
+               a = ZeroMalloc(sizeof(L3ARPENTRY));\r
+               a->IpAddress = ip;\r
+               Copy(a->MacAddress, mac, 6);\r
+               Insert(f->ArpTable, a);\r
+       }\r
+\r
+       // 有効期限を延長する\r
+       a->Expire = Tick64() + ARP_ENTRY_EXPIRES;\r
+\r
+       // 待機している IP パケットを送信させる\r
+       L3SendWaitingIp(f, mac, ip, a);\r
+}\r
+\r
+// ARP テーブルを知ったときに呼ばれる関数\r
+void L3KnownArp(L3IF *f, UINT ip, UCHAR *mac)\r
+{\r
+       L3ARPWAIT t, *w;\r
+       // 引数チェック\r
+       if (f == NULL || ip == 0 || ip == 0xffffffff || mac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // この IP アドレスへの ARP 問い合わせテーブルを削除する\r
+       Zero(&t, sizeof(t));\r
+       t.IpAddress = ip;\r
+       w = Search(f->IpWaitList, &t);\r
+       if (w != NULL)\r
+       {\r
+               Delete(f->IpWaitList, w);\r
+               Free(w);\r
+       }\r
+\r
+       // ARP テーブルに登録する\r
+       L3InsertArpTable(f, ip, mac);\r
+}\r
+\r
+// ARP を発行する\r
+void L3SendArp(L3IF *f, UINT ip)\r
+{\r
+       L3ARPWAIT t, *w;\r
+       // 引数チェック\r
+       if (f == NULL || ip == 0 || ip == 0xffffffff)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // すでに登録されていないかどうか調べる\r
+       Zero(&t, sizeof(t));\r
+       t.IpAddress = ip;\r
+       w = Search(f->ArpWaitTable, &t);\r
+\r
+       if (w != NULL)\r
+       {\r
+               // すでに待機リストに登録されているので何もしない\r
+               return;\r
+       }\r
+       else\r
+       {\r
+               // 新しくリストに登録する\r
+               w = ZeroMalloc(sizeof(L3ARPWAIT));\r
+               w->Expire = Tick64() + ARP_REQUEST_GIVEUP;\r
+               w->IpAddress = ip;\r
+               Insert(f->ArpWaitTable, w);\r
+       }\r
+}\r
+\r
+// ARP 要求を受信した\r
+void L3RecvArpRequest(L3IF *f, PKT *p)\r
+{\r
+       ARPV4_HEADER *a;\r
+       // 引数チェック\r
+       if (f == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       a = p->L3.ARPv4Header;\r
+\r
+       L3KnownArp(f, a->SrcIP, a->SrcAddress);\r
+\r
+       if (a->TargetIP == f->IpAddress)\r
+       {\r
+               // 自分宛の ARP パケットの場合のみ応答する\r
+               L3SendArpResponseNow(f, a->SrcAddress, a->SrcIP, f->IpAddress);\r
+       }\r
+}\r
+\r
+// ARP 応答を受信した\r
+void L3RecvArpResponse(L3IF *f, PKT *p)\r
+{\r
+       ARPV4_HEADER *a;\r
+       // 引数チェック\r
+       if (f == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       a = p->L3.ARPv4Header;\r
+\r
+       L3KnownArp(f, a->SrcIP, a->SrcAddress);\r
+}\r
+\r
+// ARP パケットを受信した\r
+void L3RecvArp(L3IF *f, PKT *p)\r
+{\r
+       ARPV4_HEADER *a;\r
+       // 引数チェック\r
+       if (f == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       a = p->L3.ARPv4Header;\r
+\r
+       if (Endian16(a->HardwareType) != ARP_HARDWARE_TYPE_ETHERNET ||\r
+               Endian16(a->ProtocolType) != MAC_PROTO_IPV4 ||\r
+               a->HardwareSize != 6 || a->ProtocolSize != 4)\r
+       {\r
+               return;\r
+       }\r
+       if (Cmp(a->SrcAddress, p->MacAddressSrc, 6) != 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       switch (Endian16(a->Operation))\r
+       {\r
+       case ARP_OPERATION_REQUEST:\r
+               // ARP 要求が届いた\r
+               L3RecvArpRequest(f, p);\r
+               break;\r
+\r
+       case ARP_OPERATION_RESPONSE:\r
+               // ARP 応答が届いた\r
+               L3RecvArpResponse(f, p);\r
+               break;\r
+       }\r
+}\r
+\r
+// IP パケットを送信する\r
+void L3SendIp(L3IF *f, L3PACKET *p)\r
+{\r
+       L3ARPENTRY *a = NULL;\r
+       bool broadcast = false;\r
+       IPV4_HEADER *ip;\r
+       bool for_me = false;\r
+       // 引数チェック\r
+       if (f == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (p->Packet->TypeL3 != L3_IPV4)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ip = p->Packet->L3.IPv4Header;\r
+\r
+       // ブロードキャストかどうか判定\r
+       if (p->NextHopIp == 0xffffffff ||\r
+               ((p->NextHopIp & f->SubnetMask) == (f->IpAddress & f->SubnetMask)) &&\r
+               ((p->NextHopIp & (~f->SubnetMask)) == (~f->SubnetMask)))\r
+       {\r
+               broadcast = true;\r
+       }\r
+\r
+       if (broadcast == false && ip->DstIP == f->IpAddress)\r
+       {\r
+               // me?\r
+       }\r
+       else if (broadcast == false)\r
+       {\r
+               // ユニキャストの場合 ARP エントリに入っているかどうか調べる\r
+               a = L3SearchArpTable(f, p->NextHopIp);\r
+\r
+               if (a == NULL)\r
+               {\r
+                       // ARP エントリに入っていないので、すぐに送信せずに\r
+                       // IP 待ちリストに挿入する\r
+                       p->Expire = Tick64() + IP_WAIT_FOR_ARP_TIMEOUT;\r
+\r
+                       Insert(f->IpWaitList, p);\r
+\r
+                       // ARP を発行しておく\r
+                       L3SendArp(f, p->NextHopIp);\r
+                       return;\r
+               }\r
+       }\r
+\r
+       if (for_me == false)\r
+       {\r
+               // IP パケットを送信する\r
+               L3SendIpNow(f, a, p);\r
+       }\r
+\r
+       // パケットを解放する\r
+       Free(p->Packet->PacketData);\r
+       FreePacket(p->Packet);\r
+       Free(p);\r
+}\r
+\r
+// IP パケットをすぐに送信する\r
+void L3SendIpNow(L3IF *f, L3ARPENTRY *a, L3PACKET *p)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       L3SendL2Now(f, a != NULL ? a->MacAddress : broadcast, f->MacAddress, Endian16(p->Packet->MacHeader->Protocol),\r
+               p->Packet->L3.PointerL3, p->Packet->PacketSize - sizeof(MAC_HEADER));\r
+}\r
+\r
+// ARP テーブルを検索する\r
+L3ARPENTRY *L3SearchArpTable(L3IF *f, UINT ip)\r
+{\r
+       L3ARPENTRY *e, t;\r
+       // 引数チェック\r
+       if (f == NULL || ip == 0 || ip == 0xffffffff)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.IpAddress = ip;\r
+\r
+       e = Search(f->ArpTable, &t);\r
+\r
+       return e;\r
+}\r
+\r
+// ARP 要求パケットを送信する\r
+void L3SendArpRequestNow(L3IF *f, UINT dest_ip)\r
+{\r
+       ARPV4_HEADER arp;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ARP ヘッダを構築\r
+       arp.HardwareType = Endian16(ARP_HARDWARE_TYPE_ETHERNET);\r
+       arp.ProtocolType = Endian16(MAC_PROTO_IPV4);\r
+       arp.HardwareSize = 6;\r
+       arp.ProtocolSize = 4;\r
+       arp.Operation = Endian16(ARP_OPERATION_REQUEST);\r
+       Copy(arp.SrcAddress, f->MacAddress, 6);\r
+       arp.SrcIP = f->IpAddress;\r
+       Zero(&arp.TargetAddress, 6);\r
+       arp.TargetIP = dest_ip;\r
+\r
+       // 送信\r
+       L3SendL2Now(f, broadcast, f->MacAddress, MAC_PROTO_ARPV4, &arp, sizeof(arp));\r
+}\r
+\r
+// ARP 応答パケットを送信する\r
+void L3SendArpResponseNow(L3IF *f, UCHAR *dest_mac, UINT dest_ip, UINT src_ip)\r
+{\r
+       ARPV4_HEADER arp;\r
+       // 引数チェック\r
+       if (f == NULL || dest_mac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ヘッダ構築\r
+       arp.HardwareType = Endian16(ARP_HARDWARE_TYPE_ETHERNET);\r
+       arp.ProtocolType = Endian16(MAC_PROTO_IPV4);\r
+       arp.HardwareSize = 6;\r
+       arp.ProtocolSize = 4;\r
+       arp.Operation = Endian16(ARP_OPERATION_RESPONSE);\r
+       Copy(arp.SrcAddress, f->MacAddress, 6);\r
+       Copy(arp.TargetAddress, dest_mac, 6);\r
+       arp.SrcIP = src_ip;\r
+       arp.TargetIP = dest_ip;\r
+\r
+       // 送信\r
+       L3SendL2Now(f, dest_mac, f->MacAddress, MAC_PROTO_ARPV4, &arp, sizeof(arp));\r
+}\r
+\r
+// インターフェイスの MAC アドレスの生成\r
+void L3GenerateMacAddress(L3IF *f)\r
+{\r
+       BUF *b;\r
+       UCHAR hash[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, f->Switch->Name, StrLen(f->Switch->Name));\r
+       WriteBuf(b, f->HubName, StrLen(f->HubName));\r
+       WriteBuf(b, &f->IpAddress, sizeof(f->IpAddress));\r
+\r
+       GenMacAddress(f->MacAddress);\r
+       Hash(hash, b->Buf, b->Size, true);\r
+       Copy(f->MacAddress + 2, hash, 4);\r
+       f->MacAddress[1] = 0xA3;\r
+       FreeBuf(b);\r
+}\r
+\r
+// L2 パケットをすぐに送信する\r
+void L3SendL2Now(L3IF *f, UCHAR *dest_mac, UCHAR *src_mac, USHORT protocol, void *data, UINT size)\r
+{\r
+       UCHAR *buf;\r
+       MAC_HEADER *mac_header;\r
+       PKT *p;\r
+       // 引数チェック\r
+       if (f == NULL || dest_mac == NULL || src_mac == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // バッファ生成\r
+       buf = Malloc(MAC_HEADER_SIZE + size);\r
+\r
+       // MAC ヘッダ\r
+       mac_header = (MAC_HEADER *)&buf[0];\r
+       Copy(mac_header->DestAddress, dest_mac, 6);\r
+       Copy(mac_header->SrcAddress, src_mac, 6);\r
+       mac_header->Protocol = Endian16(protocol);\r
+\r
+       // データのコピー\r
+       Copy(&buf[sizeof(MAC_HEADER)], data, size);\r
+\r
+       // サイズ\r
+       size += sizeof(MAC_HEADER);\r
+\r
+       // パケット生成\r
+       p = ZeroMalloc(sizeof(PKT));\r
+       p->PacketData = buf;\r
+       p->PacketSize = size;\r
+\r
+       // キューに追加する\r
+       InsertQueue(f->SendQueue, p);\r
+}\r
+\r
+// ARP 解決待ちリストのポーリング\r
+void L3PollingArpWaitTable(L3IF *f)\r
+{\r
+       UINT i;\r
+       LIST *o = NULL;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(f->ArpWaitTable);i++)\r
+       {\r
+               L3ARPWAIT *w = LIST_DATA(f->ArpWaitTable, i);\r
+\r
+               if (w->Expire <= Tick64())\r
+               {\r
+                       // ARP 要求テーブルが期限切れである\r
+                       if (o == NULL)\r
+                       {\r
+                               o = NewListFast(NULL);\r
+                       }\r
+\r
+                       Insert(o, w);\r
+               }\r
+               else if ((w->LastSentTime + ARP_REQUEST_TIMEOUT) <= Tick64())\r
+               {\r
+                       // 次の ARP 要求パケットを送信する\r
+                       w->LastSentTime = Tick64();\r
+\r
+                       L3SendArpRequestNow(f, w->IpAddress);\r
+               }\r
+       }\r
+\r
+       if (o != NULL)\r
+       {\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       L3ARPWAIT *w = LIST_DATA(o, i);\r
+\r
+                       Delete(f->ArpWaitTable, w);\r
+                       Free(w);\r
+               }\r
+\r
+               ReleaseList(o);\r
+       }\r
+}\r
+\r
+// 古い ARP テーブルの清掃\r
+void L3DeleteOldArpTable(L3IF *f)\r
+{\r
+       UINT i;\r
+       LIST *o = NULL;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if ((f->LastDeleteOldArpTable + ARP_ENTRY_POLLING_TIME) > Tick64())\r
+       {\r
+               return;\r
+       }\r
+       f->LastDeleteOldArpTable = Tick64();\r
+\r
+       for (i = 0;i < LIST_NUM(f->ArpTable);i++)\r
+       {\r
+               L3ARPENTRY *a = LIST_DATA(f->ArpTable, i);\r
+\r
+               if (a->Expire <= Tick64())\r
+               {\r
+                       // 有効期限切れ\r
+                       if (o == NULL)\r
+                       {\r
+                               o = NewListFast(NULL);\r
+                       }\r
+\r
+                       Insert(o, a);\r
+               }\r
+       }\r
+\r
+       if (o != NULL)\r
+       {\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       L3ARPENTRY *a = LIST_DATA(o, i);\r
+\r
+                       Delete(f->ArpTable, a);\r
+                       Free(a);\r
+               }\r
+\r
+               ReleaseList(o);\r
+       }\r
+}\r
+\r
+// IP 待ちリストの清掃\r
+void L3DeleteOldIpWaitList(L3IF *f)\r
+{\r
+       UINT i;\r
+       LIST *o = NULL;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(f->IpWaitList);i++)\r
+       {\r
+               L3PACKET *p = LIST_DATA(f->IpWaitList, i);\r
+\r
+               if (p->Expire <= Tick64())\r
+               {\r
+                       if (o == NULL)\r
+                       {\r
+                               o = NewListFast(NULL);\r
+                       }\r
+\r
+                       Insert(o, p);\r
+               }\r
+       }\r
+\r
+       if (o != NULL)\r
+       {\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       L3PACKET *p = LIST_DATA(o, i);\r
+\r
+                       Delete(f->IpWaitList, p);\r
+\r
+                       Free(p->Packet->PacketData);\r
+                       FreePacket(p->Packet);\r
+                       Free(p);\r
+               }\r
+\r
+               ReleaseList(o);\r
+       }\r
+}\r
+\r
+// ビーコン送信\r
+void L3PollingBeacon(L3IF *f)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (f->LastBeaconSent == 0 ||\r
+               (f->LastBeaconSent + BEACON_SEND_INTERVAL) <= Tick64())\r
+       {\r
+               UINT dest_ip;\r
+               UCHAR *udp_buf;\r
+               UINT udp_buf_size;\r
+               ARPV4_HEADER arp;\r
+               IPV4_HEADER *ip;\r
+               UDP_HEADER *udp;\r
+               static char beacon_str[] =\r
+                       "SoftEther UT-VPN Virtual Layer-3 Switch Beacon";\r
+\r
+               // UDP を送信\r
+               dest_ip = (f->IpAddress & f->SubnetMask) | (~f->SubnetMask);\r
+               udp_buf_size = sizeof(IPV4_HEADER) + sizeof(UDP_HEADER) + sizeof(beacon_str);\r
+               udp_buf = ZeroMalloc(udp_buf_size);\r
+\r
+               ip = (IPV4_HEADER *)udp_buf;\r
+               udp = (UDP_HEADER *)(udp_buf + sizeof(IPV4_HEADER));\r
+               udp->DstPort = Endian16(7);\r
+               udp->SrcPort = Endian16(7);\r
+               udp->PacketLength = Endian16(sizeof(UDP_HEADER) + sizeof(beacon_str));\r
+\r
+               Copy(udp_buf + sizeof(IPV4_HEADER) + sizeof(UDP_HEADER), beacon_str, sizeof(beacon_str));\r
+\r
+               udp->Checksum = IpChecksum(udp, sizeof(UDP_HEADER) + sizeof(beacon_str));\r
+\r
+               ip->DstIP = dest_ip;\r
+               IPV4_SET_VERSION(ip, 4);\r
+               IPV4_SET_HEADER_LEN(ip, (IP_HEADER_SIZE / 4));\r
+               ip->TypeOfService = DEFAULT_IP_TOS;\r
+               ip->TotalLength = Endian16((USHORT)(udp_buf_size));\r
+               ip->TimeToLive = DEFAULT_IP_TTL;\r
+               ip->Protocol = IP_PROTO_UDP;\r
+               ip->SrcIP = f->IpAddress;\r
+               ip->Checksum = IpChecksum(ip, IP_HEADER_SIZE);\r
+\r
+               L3SendL2Now(f, broadcast, f->MacAddress, MAC_PROTO_IPV4, udp_buf, udp_buf_size);\r
+\r
+               Free(udp_buf);\r
+\r
+               // ARP ヘッダを構築\r
+               arp.HardwareType = Endian16(ARP_HARDWARE_TYPE_ETHERNET);\r
+               arp.ProtocolType = Endian16(MAC_PROTO_IPV4);\r
+               arp.HardwareSize = 6;\r
+               arp.ProtocolSize = 4;\r
+               arp.Operation = Endian16(ARP_OPERATION_RESPONSE);\r
+               Copy(arp.SrcAddress, f->MacAddress, 6);\r
+               arp.SrcIP = f->IpAddress;\r
+               arp.TargetAddress[0] =\r
+                       arp.TargetAddress[1] =\r
+                       arp.TargetAddress[2] =\r
+                       arp.TargetAddress[3] =\r
+                       arp.TargetAddress[4] =\r
+                       arp.TargetAddress[5] = 0xff;\r
+               arp.TargetIP = dest_ip;\r
+\r
+               // 送信\r
+               L3SendL2Now(f, broadcast, f->MacAddress, MAC_PROTO_ARPV4, &arp, sizeof(arp));\r
+\r
+               f->LastBeaconSent = Tick64();\r
+       }\r
+}\r
+\r
+// ポーリング処理\r
+void L3Polling(L3IF *f)\r
+{\r
+       L3SW *s;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = f->Switch;\r
+\r
+       // ポーリング処理の途中ではスイッチ全体にロックをかける\r
+       Lock(s->lock);\r
+       {\r
+               // ビーコン送信\r
+               L3PollingBeacon(f);\r
+\r
+               // IP キューの処理\r
+               L3PollingIpQueue(f);\r
+\r
+               // 古い ARP テーブルの清掃\r
+               L3DeleteOldArpTable(f);\r
+\r
+               // ARP 解決待ちリストのポーリング\r
+               L3PollingArpWaitTable(f);\r
+\r
+               // IP 待ちリストの清掃\r
+               L3DeleteOldIpWaitList(f);\r
+       }\r
+       Unlock(s->lock);\r
+}\r
+\r
+// 次のパケットを取得する\r
+UINT L3GetNextPacket(L3IF *f, void **data)\r
+{\r
+       UINT ret = 0;\r
+       // 引数チェック\r
+       if (f == NULL || data == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+START:\r
+       // 送信キューを調べる\r
+       LockQueue(f->SendQueue);\r
+       {\r
+               PKT *p = GetNext(f->SendQueue);\r
+\r
+               if (p != NULL)\r
+               {\r
+                       // パケットがあった\r
+                       ret = p->PacketSize;\r
+                       *data = p->PacketData;\r
+                       // パケット構造体は破棄して良い\r
+                       Free(p);\r
+               }\r
+       }\r
+       UnlockQueue(f->SendQueue);\r
+\r
+       if (ret == 0)\r
+       {\r
+               // ポーリング処理\r
+               L3Polling(f);\r
+\r
+        // ポーリング処理の結果、新たにパケットがキューに入っていないか\r
+               // どうか調べる\r
+               if (f->SendQueue->num_item != 0)\r
+               {\r
+                       // キューに入っていたら早速そのパケットを取得させる\r
+                       goto START;\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 指定した IP アドレス宛のパケットをどのインターフェイスに投げれば良いか決める\r
+L3IF *L3GetNextIf(L3SW *s, UINT ip, UINT *next_hop)\r
+{\r
+       UINT i;\r
+       L3IF *f;\r
+       UINT next_hop_ip = 0;\r
+       // 引数チェック\r
+       if (s == NULL || ip == 0 || ip == 0xffffffff)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       f = NULL;\r
+\r
+       // まず各インターフェイスの所属しているネットワークに指定した IP アドレスが\r
+       // 含まれるものが無いかどうか調べる\r
+       for (i = 0;i < LIST_NUM(s->IfList);i++)\r
+       {\r
+               L3IF *ff = LIST_DATA(s->IfList, i);\r
+\r
+               if ((ff->IpAddress & ff->SubnetMask) == (ip & ff->SubnetMask))\r
+               {\r
+                       f = ff;\r
+                       next_hop_ip = ip;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (f == NULL)\r
+       {\r
+               // 見つからなかったらルーティングテーブルを探す\r
+               L3TABLE *t = L3GetBestRoute(s, ip);\r
+\r
+               if (t == NULL)\r
+               {\r
+                       // それでも見つからなかった\r
+                       return NULL;\r
+               }\r
+               else\r
+               {\r
+                       // 見つかったルートの NextHop のルータの IP アドレスを持つ\r
+                       // インターフェイスを探す\r
+                       for (i = 0;i < LIST_NUM(s->IfList);i++)\r
+                       {\r
+                               L3IF *ff = LIST_DATA(s->IfList, i);\r
+\r
+                               if ((ff->IpAddress & ff->SubnetMask) == (t->GatewayAddress & ff->SubnetMask))\r
+                               {\r
+                                       f = ff;\r
+                                       next_hop_ip = t->GatewayAddress;\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (f == NULL)\r
+       {\r
+               // 結局宛先インターフェイスが不明であった\r
+               return NULL;\r
+       }\r
+\r
+       if (next_hop != NULL)\r
+       {\r
+               *next_hop = next_hop_ip;\r
+       }\r
+\r
+       return f;\r
+}\r
+\r
+// 指定した IP アドレス宛の最適なルーティングテーブルエントリを取得する\r
+L3TABLE *L3GetBestRoute(L3SW *s, UINT ip)\r
+{\r
+       UINT i;\r
+       UINT max_mask = 0;\r
+       UINT min_metric = INFINITE;\r
+       L3TABLE *ret = NULL;\r
+       // 引数チェック\r
+       if (s == NULL || ip == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 第一条件: サブネットマスクが最も大きいものを選択\r
+       // 第二条件: メトリックが最も小さいものを選択\r
+       for (i = 0;i < LIST_NUM(s->TableList);i++)\r
+       {\r
+               L3TABLE *t = LIST_DATA(s->TableList, i);\r
+\r
+               if ((t->NetworkAddress & t->SubnetMask) == (ip & t->SubnetMask))\r
+               {\r
+                       if (t->SubnetMask >= max_mask)\r
+                       {\r
+                               max_mask = t->SubnetMask;\r
+                               if (min_metric >= t->Metric)\r
+                               {\r
+                                       min_metric = t->Metric;\r
+                                       ret = t;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// Layer-3 インターフェイスの初期化\r
+void L3InitInterface(L3IF *f)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // MAC アドレス生成\r
+       L3GenerateMacAddress(f);\r
+\r
+       // リスト生成\r
+       f->ArpTable = NewList(CmpL3ArpEntry);\r
+       f->ArpWaitTable = NewList(CmpL3ArpWaitTable);\r
+       f->IpPacketQueue = NewQueue();\r
+       f->IpWaitList = NewList(NULL);\r
+       f->SendQueue = NewQueue();\r
+}\r
+\r
+// Layer-3 インターフェイスの解放\r
+void L3FreeInterface(L3IF *f)\r
+{\r
+       UINT i;\r
+       L3PACKET *p;\r
+       PKT *pkt;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(f->ArpTable);i++)\r
+       {\r
+               L3ARPENTRY *a = LIST_DATA(f->ArpTable, i);\r
+               Free(a);\r
+       }\r
+       ReleaseList(f->ArpTable);\r
+       f->ArpTable = NULL;\r
+\r
+       for (i = 0;i < LIST_NUM(f->ArpWaitTable);i++)\r
+       {\r
+               L3ARPWAIT *w = LIST_DATA(f->ArpWaitTable, i);\r
+               Free(w);\r
+       }\r
+       ReleaseList(f->ArpWaitTable);\r
+       f->ArpWaitTable = NULL;\r
+\r
+       while (p = GetNext(f->IpPacketQueue))\r
+       {\r
+               Free(p->Packet->PacketData);\r
+               FreePacket(p->Packet);\r
+               Free(p);\r
+       }\r
+       ReleaseQueue(f->IpPacketQueue);\r
+       f->IpPacketQueue = NULL;\r
+\r
+       for (i = 0;i < LIST_NUM(f->IpWaitList);i++)\r
+       {\r
+               L3PACKET *p = LIST_DATA(f->IpWaitList, i);\r
+               Free(p->Packet->PacketData);\r
+               FreePacket(p->Packet);\r
+               Free(p);\r
+       }\r
+       ReleaseList(f->IpWaitList);\r
+       f->IpWaitList = NULL;\r
+\r
+       while (pkt = GetNext(f->SendQueue))\r
+       {\r
+               Free(pkt->PacketData);\r
+               FreePacket(pkt);\r
+       }\r
+       ReleaseQueue(f->SendQueue);\r
+       f->SendQueue = NULL;\r
+}\r
+\r
+// Layer-3 インターフェイスのスレッド\r
+void L3IfThread(THREAD *t, void *param)\r
+{\r
+       L3IF *f;\r
+       CONNECTION *c;\r
+       SESSION *s;\r
+       POLICY *policy;\r
+       char tmp[MAX_SIZE];\r
+       char name[MAX_SIZE];\r
+       char username[MAX_SIZE];\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       f = (L3IF *)param;\r
+\r
+       StrCpy(username, sizeof(username), L3_USERNAME);\r
+       if (f->Switch != NULL)\r
+       {\r
+               StrCat(username, sizeof(username), f->Switch->Name);\r
+       }\r
+\r
+       // コネクションの作成\r
+       c = NewServerConnection(f->Switch->Cedar, NULL, t);\r
+       c->Protocol = CONNECTION_HUB_LAYER3;\r
+\r
+       // セッションの作成\r
+       policy = ClonePolicy(GetDefaultPolicy());\r
+       // ポリシーではブロードキャスト数を制限しない\r
+       policy->NoBroadcastLimiter = true;\r
+       s = NewServerSession(f->Switch->Cedar, c, f->Hub, username, policy);\r
+       c->Session = s;\r
+\r
+       ReleaseConnection(c);\r
+\r
+       // セッション名を決定する\r
+       GetMachineHostName(tmp, sizeof(tmp));\r
+       if (f->Switch->Cedar->Server->ServerType == SERVER_TYPE_STANDALONE)\r
+       {\r
+               Format(name, sizeof(name), "SID-L3-%s-%u", f->Switch->Name, Inc(f->Hub->SessionCounter));\r
+       }\r
+       else\r
+       {\r
+               Format(name, sizeof(name), "SID-L3-%s-%s-%u", tmp, f->Switch->Name, Inc(f->Hub->SessionCounter));\r
+       }\r
+       ConvertSafeFileName(name, sizeof(name), name);\r
+       StrUpper(name);\r
+\r
+       Free(s->Name);\r
+       s->Name = CopyStr(name);\r
+\r
+       s->L3SwitchMode = true;\r
+       s->L3If = f;\r
+\r
+       if (s->Username != NULL)\r
+       {\r
+               Free(s->Username);\r
+       }\r
+       s->Username = CopyStr(username);\r
+\r
+       StrCpy(s->UserNameReal, sizeof(s->UserNameReal), username);\r
+\r
+       f->Session = s;\r
+       AddRef(s->ref);\r
+\r
+       // 初期化完了を通知\r
+       NoticeThreadInit(t);\r
+\r
+       // セッションメイン処理\r
+       SessionMain(s);\r
+\r
+       // セッションの解放\r
+       ReleaseSession(s);\r
+}\r
+\r
+// すべての Layer-3 インターフェイスの初期化をする\r
+void L3InitAllInterfaces(L3SW *s)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(s->IfList);i++)\r
+       {\r
+               L3IF *f = LIST_DATA(s->IfList, i);\r
+               THREAD *t;\r
+\r
+               L3InitInterface(f);\r
+\r
+               f->Hub = GetHub(s->Cedar, f->HubName);\r
+               t = NewThread(L3IfThread, f);\r
+               WaitThreadInit(t);\r
+               ReleaseThread(t);\r
+       }\r
+}\r
+\r
+// すべての Layer-3 インターフェイスの解放をする\r
+void L3FreeAllInterfaces(L3SW *s)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(s->IfList);i++)\r
+       {\r
+               L3IF *f = LIST_DATA(s->IfList, i);\r
+\r
+               ReleaseHub(f->Hub);\r
+               f->Hub = NULL;\r
+               ReleaseSession(f->Session);\r
+               f->Session = NULL;\r
+\r
+               L3FreeInterface(f);\r
+       }\r
+}\r
+\r
+// Layer-3 テスト\r
+void L3Test(SERVER *s)\r
+{\r
+       L3SW *ss = L3AddSw(s->Cedar, "TEST");\r
+       L3AddIf(ss, "DEFAULT", 0x0101a8c0, 0x00ffffff);\r
+       L3AddIf(ss, "DEFAULT2", 0x0102a8c0, 0x00ffffff);\r
+       L3SwStart(ss);\r
+       ReleaseL3Sw(ss);\r
+}\r
+\r
+// Layer-3 スイッチスレッド\r
+void L3SwThread(THREAD *t, void *param)\r
+{\r
+       L3SW *s;\r
+       bool shutdown_now = false;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = (L3SW *)param;\r
+\r
+       s->Active = true;\r
+\r
+       NoticeThreadInit(t);\r
+\r
+       // 動作開始\r
+       SLog(s->Cedar, "L3_SWITCH_START", s->Name);\r
+\r
+       while (s->Halt == false)\r
+       {\r
+               if (s->Online == false)\r
+               {\r
+                       // 現在 L3 スイッチはオフラインなので、一定時間ごとにオンライン化\r
+                       // を試みる\r
+                       LockList(s->Cedar->HubList);\r
+                       {\r
+                               Lock(s->lock);\r
+                               {\r
+                                       UINT i;\r
+                                       UINT n = 0;\r
+                                       bool all_exists = true;\r
+                                       if (LIST_NUM(s->IfList) == 0)\r
+                                       {\r
+                                               // 1 つもインターフェイスが無い場合は動作しない\r
+                                               all_exists = false;\r
+                                       }\r
+                                       for (i = 0;i < LIST_NUM(s->IfList);i++)\r
+                                       {\r
+                                               L3IF *f = LIST_DATA(s->IfList, i);\r
+                                               HUB *h = GetHub(s->Cedar, f->HubName);\r
+\r
+                                               if (h != NULL)\r
+                                               {\r
+                                                       if (h->Offline || h->Type == HUB_TYPE_FARM_DYNAMIC)\r
+                                                       {\r
+                                                               all_exists = false;\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               n++;\r
+                                                       }\r
+                                                       ReleaseHub(h);\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       all_exists = false;\r
+                                               }\r
+                                       }\r
+\r
+                                       if (all_exists && n >= 1)\r
+                                       {\r
+                                               // すべてのインターフェイスの仮想 HUB が有効になったので\r
+                                               // 動作を開始する\r
+                                               SLog(s->Cedar, "L3_SWITCH_ONLINE", s->Name);\r
+                                               L3InitAllInterfaces(s);\r
+                                               s->Online = true;\r
+                                       }\r
+                               }\r
+                               Unlock(s->lock);\r
+                       }\r
+                       UnlockList(s->Cedar->HubList);\r
+               }\r
+               else\r
+               {\r
+                       // 一定時間ごとにすべてのセッションが終了していないかどうか調査する\r
+                       UINT i;\r
+                       bool any_halted = false;\r
+                       LIST *o = NULL;\r
+\r
+SHUTDOWN:\r
+\r
+                       Lock(s->lock);\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(s->IfList);i++)\r
+                               {\r
+                                       L3IF *f = LIST_DATA(s->IfList, i);\r
+                                       if (f->Session->Halt || f->Hub->Offline != false)\r
+                                       {\r
+                                               any_halted = true;\r
+                                               break;\r
+                                       }\r
+                               }\r
+\r
+                               if (shutdown_now)\r
+                               {\r
+                                       any_halted = true;\r
+                               }\r
+\r
+                               if (any_halted)\r
+                               {\r
+                                       SLog(s->Cedar, "L3_SWITCH_OFFLINE", s->Name);\r
+                                       o = NewListFast(NULL);\r
+                                       // 1 つでも終了したセッションがあれば、すべてのセッションを終了する\r
+                                       for (i = 0;i < LIST_NUM(s->IfList);i++)\r
+                                       {\r
+                                               L3IF *f = LIST_DATA(s->IfList, i);\r
+                                               Insert(o, f->Session);\r
+                                       }\r
+\r
+                                       // オフラインに戻す\r
+                                       s->Online = false;\r
+                               }\r
+                       }\r
+                       Unlock(s->lock);\r
+\r
+                       if (o != NULL)\r
+                       {\r
+                               UINT i;\r
+                               for (i = 0;i < LIST_NUM(o);i++)\r
+                               {\r
+                                       SESSION *s = LIST_DATA(o, i);\r
+                                       StopSession(s);\r
+                               }\r
+                               L3FreeAllInterfaces(s);\r
+                               ReleaseList(o);\r
+                               o = NULL;\r
+                       }\r
+               }\r
+\r
+               SleepThread(50);\r
+       }\r
+\r
+       if (s->Online != false)\r
+       {\r
+               shutdown_now = true;\r
+               goto SHUTDOWN;\r
+       }\r
+\r
+       // 動作停止\r
+       SLog(s->Cedar, "L3_SWITCH_STOP", s->Name);\r
+}\r
+\r
+// Layer-3 スイッチを開始する\r
+void L3SwStart(L3SW *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(s->lock);\r
+       {\r
+               if (s->Active == false)\r
+               {\r
+                       // 登録されている IF 数が 1 以上でないと開始しない\r
+                       if (LIST_NUM(s->IfList) >= 1)\r
+                       {\r
+                               s->Halt = false;\r
+\r
+                               // スレッド作成\r
+                               s->Thread = NewThread(L3SwThread, s);\r
+                               WaitThreadInit(s->Thread);\r
+                       }\r
+               }\r
+       }\r
+       Unlock(s->lock);\r
+}\r
+\r
+// Layer-3 スイッチを停止する\r
+void L3SwStop(L3SW *s)\r
+{\r
+       THREAD *t = NULL;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(s->lock);\r
+       {\r
+               if (s->Active == false)\r
+               {\r
+                       Unlock(s->lock);\r
+                       return;\r
+               }\r
+\r
+               s->Halt = true;\r
+\r
+               t = s->Thread;\r
+\r
+               s->Active = false;\r
+       }\r
+       Unlock(s->lock);\r
+\r
+       WaitThread(t, INFINITE);\r
+       ReleaseThread(t);\r
+}\r
+\r
+// Layer-3 スイッチを追加する\r
+L3SW *L3AddSw(CEDAR *c, char *name)\r
+{\r
+       L3SW *s = NULL;\r
+       // 引数チェック\r
+       if (c == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       LockList(c->L3SwList);\r
+       {\r
+               s = L3GetSw(c, name);\r
+\r
+               if (s == NULL)\r
+               {\r
+                       s = NewL3Sw(c, name);\r
+\r
+                       Insert(c->L3SwList, s);\r
+\r
+                       AddRef(s->ref);\r
+               }\r
+               else\r
+               {\r
+                       ReleaseL3Sw(s);\r
+                       s = NULL;\r
+               }\r
+       }\r
+       UnlockList(c->L3SwList);\r
+\r
+       return s;\r
+}\r
+\r
+// Layer-3 スイッチを削除する\r
+bool L3DelSw(CEDAR *c, char *name)\r
+{\r
+       L3SW *s;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (c == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       LockList(c->L3SwList);\r
+       {\r
+               s = L3GetSw(c, name);\r
+\r
+               if (s != NULL)\r
+               {\r
+                       // 停止して削除\r
+                       L3SwStop(s);\r
+                       Delete(c->L3SwList, s);\r
+                       ReleaseL3Sw(s);\r
+                       ReleaseL3Sw(s);\r
+\r
+                       ret = true;\r
+               }\r
+       }\r
+       UnlockList(c->L3SwList);\r
+\r
+       return ret;\r
+}\r
+\r
+\r
+// ルーティングテーブルの削除\r
+bool L3DelTable(L3SW *s, L3TABLE *tbl)\r
+{\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (s == NULL || tbl == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(s->lock);\r
+       {\r
+               if (s->Active == false)\r
+               {\r
+                       L3TABLE *t = Search(s->TableList, tbl);\r
+\r
+                       if (t != NULL)\r
+                       {\r
+                               Delete(s->TableList, t);\r
+                               Free(t);\r
+\r
+                               ret = true;\r
+                       }\r
+               }\r
+       }\r
+       Unlock(s->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// ルーティングテーブルの追加\r
+bool L3AddTable(L3SW *s, L3TABLE *tbl)\r
+{\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (s == NULL || tbl == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (tbl->Metric == 0 || tbl->GatewayAddress == 0 || tbl->GatewayAddress == 0xffffffff)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(s->lock);\r
+       {\r
+               if (LIST_NUM(s->TableList) >= GetServerCapsInt(s->Cedar->Server, "i_max_l3_table"))\r
+               {\r
+                       // 数が多すぎる\r
+               }\r
+               else\r
+               {\r
+                       // 作成\r
+                       if (s->Active == false)\r
+                       {\r
+                               if (Search(s->TableList, tbl) == NULL)\r
+                               {\r
+                                       L3TABLE *t = ZeroMalloc(sizeof(L3TABLE));\r
+\r
+                                       Copy(t, tbl, sizeof(L3TABLE));\r
+\r
+                                       Insert(s->TableList, t);\r
+\r
+                                       ret = true;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       Unlock(s->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// L3 スイッチを取得する\r
+L3SW *L3GetSw(CEDAR *c, char *name)\r
+{\r
+       L3SW t, *s;\r
+       // 引数チェック\r
+       if (c == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.Name, sizeof(t.Name), name);\r
+\r
+       LockList(c->L3SwList);\r
+       {\r
+               s = Search(c->L3SwList, &t);\r
+       }\r
+       UnlockList(c->L3SwList);\r
+\r
+       if (s != NULL)\r
+       {\r
+               AddRef(s->ref);\r
+       }\r
+\r
+       return s;\r
+}\r
+\r
+// L3 スイッチから指定した仮想 HUB に接続されているインターフェイスを取得する\r
+L3IF *L3SearchIf(L3SW *s, char *hubname)\r
+{\r
+       L3IF t, *f;\r
+       // 引数チェック\r
+       if (s == NULL || hubname == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), hubname);\r
+\r
+       f = Search(s->IfList, &t);\r
+\r
+       return f;\r
+}\r
+\r
+// インターフェイスの削除\r
+bool L3DelIf(L3SW *s, char *hubname)\r
+{\r
+       L3IF *f;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (s == NULL || hubname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(s->lock);\r
+       {\r
+               if (s->Active == false)\r
+               {\r
+                       f = L3SearchIf(s, hubname);\r
+\r
+                       if (f != NULL)\r
+                       {\r
+                               // 削除する\r
+                               Delete(s->IfList, f);\r
+                               Free(f);\r
+\r
+                               ret = true;\r
+                       }\r
+               }\r
+       }\r
+       Unlock(s->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// インターフェイスの追加\r
+bool L3AddIf(L3SW *s, char *hubname, UINT ip, UINT subnet)\r
+{\r
+       L3IF *f;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (s == NULL || hubname == NULL || IsSafeStr(hubname) == false ||\r
+               ip == 0 || ip == 0xffffffff)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(s->lock);\r
+       {\r
+               if (LIST_NUM(s->TableList) >= GetServerCapsInt(s->Cedar->Server, "i_max_l3_if"))\r
+               {\r
+                       // 数が多すぎる\r
+               }\r
+               else\r
+               {\r
+                       if (s->Active == false)\r
+                       {\r
+                               // 同じ仮想 HUB にすでにインターフェイスが入っていないかどうか調べる\r
+                               if (L3SearchIf(s, hubname) == NULL)\r
+                               {\r
+                                       // 追加\r
+                                       f = ZeroMalloc(sizeof(L3IF));\r
+\r
+                                       f->Switch = s;\r
+                                       StrCpy(f->HubName, sizeof(f->HubName), hubname);\r
+                                       f->IpAddress = ip;\r
+                                       f->SubnetMask = subnet;\r
+\r
+                                       Insert(s->IfList, f);\r
+\r
+                                       ret = true;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       Unlock(s->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// L3 スイッチのクリーンアップ\r
+void CleanupL3Sw(L3SW *s)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(s->IfList);i++)\r
+       {\r
+               L3IF *f = LIST_DATA(s->IfList, i);\r
+               Free(f);\r
+       }\r
+       ReleaseList(s->IfList);\r
+\r
+       for (i = 0;i < LIST_NUM(s->TableList);i++)\r
+       {\r
+               L3TABLE *t = LIST_DATA(s->TableList, i);\r
+               Free(t);\r
+       }\r
+       ReleaseList(s->TableList);\r
+\r
+       DeleteLock(s->lock);\r
+       Free(s);\r
+}\r
+\r
+// L3 スイッチの解放\r
+void ReleaseL3Sw(L3SW *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(s->ref) == 0)\r
+       {\r
+               CleanupL3Sw(s);\r
+       }\r
+}\r
+\r
+// 新しい L3 スイッチを作成する\r
+L3SW *NewL3Sw(CEDAR *c, char *name)\r
+{\r
+       L3SW *o;\r
+       // 引数チェック\r
+       if (c == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = ZeroMalloc(sizeof(L3SW));\r
+\r
+       StrCpy(o->Name, sizeof(o->Name), name);\r
+\r
+       o->lock = NewLock();\r
+       o->ref = NewRef();\r
+       o->Cedar = c;\r
+       o->Active = false;\r
+\r
+       o->IfList = NewList(CmpL3If);\r
+       o->TableList = NewList(CmpL3Table);\r
+\r
+       return o;\r
+}\r
+\r
+// Cedar にあるすべての L3 スイッチを停止する\r
+void L3FreeAllSw(CEDAR *c)\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       LockList(c->L3SwList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(c->L3SwList);i++)\r
+               {\r
+                       L3SW *s = LIST_DATA(c->L3SwList, i);\r
+                       Insert(o, CopyStr(s->Name));\r
+               }\r
+\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       char *name = LIST_DATA(o, i);\r
+\r
+                       L3DelSw(c, name);\r
+\r
+                       Free(name);\r
+               }\r
+\r
+               ReleaseList(o);\r
+       }\r
+       UnlockList(c->L3SwList);\r
+}\r
+\r
+// Cedar の L3 スイッチ機能を停止する\r
+void FreeCedarLayer3(CEDAR *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ReleaseList(c->L3SwList);\r
+       c->L3SwList = NULL;\r
+}\r
+\r
+// Cedar の L3 スイッチ機能を開始する\r
+void InitCedarLayer3(CEDAR *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c->L3SwList = NewList(CmpL3Sw);\r
+}\r
+\r
+// インターフェイス比較関数\r
+int CmpL3If(void *p1, void *p2)\r
+{\r
+       L3IF *f1, *f2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       f1 = *(L3IF **)p1;\r
+       f2 = *(L3IF **)p2;\r
+       if (f1 == NULL || f2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCmpi(f1->HubName, f2->HubName);\r
+}\r
+\r
+// ルーティングテーブル比較関数\r
+int CmpL3Table(void *p1, void *p2)\r
+{\r
+       L3TABLE *t1, *t2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       t1 = *(L3TABLE **)p1;\r
+       t2 = *(L3TABLE **)p2;\r
+       if (t1 == NULL || t2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (t1->NetworkAddress > t2->NetworkAddress)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (t1->NetworkAddress < t2->NetworkAddress)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (t1->SubnetMask > t2->SubnetMask)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (t1->SubnetMask < t2->SubnetMask)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (t1->GatewayAddress > t2->GatewayAddress)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (t1->GatewayAddress < t2->GatewayAddress)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (t1->Metric > t2->Metric)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (t1->Metric < t2->Metric)\r
+       {\r
+               return -1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+// L3SW 比較関数\r
+int CmpL3Sw(void *p1, void *p2)\r
+{\r
+       L3SW *s1, *s2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       s1 = *(L3SW **)p1;\r
+       s2 = *(L3SW **)p2;\r
+       if (s1 == NULL || s2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCmpi(s1->Name, s2->Name);\r
+}\r
+\r
+// ARP 待機エントリ比較関数\r
+int CmpL3ArpWaitTable(void *p1, void *p2)\r
+{\r
+       L3ARPWAIT *w1, *w2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       w1 = *(L3ARPWAIT **)p1;\r
+       w2 = *(L3ARPWAIT **)p2;\r
+       if (w1 == NULL || w2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (w1->IpAddress > w2->IpAddress)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (w1->IpAddress < w2->IpAddress)\r
+       {\r
+               return -1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+// ARP エントリ比較関数\r
+int CmpL3ArpEntry(void *p1, void *p2)\r
+{\r
+       L3ARPENTRY *e1, *e2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       e1 = *(L3ARPENTRY **)p1;\r
+       e2 = *(L3ARPENTRY **)p2;\r
+       if (e1 == NULL || e2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (e1->IpAddress > e2->IpAddress)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (e1->IpAddress < e2->IpAddress)\r
+       {\r
+               return -1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Layer3.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Layer3.h
new file mode 100644 (file)
index 0000000..f50efe8
--- /dev/null
@@ -0,0 +1,222 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Layer3.h\r
+// Layer3.c のヘッダ\r
+\r
+#ifndef        LAYER3_H\r
+#define        LAYER3_H\r
+\r
+// 定数\r
+#define        L3_USERNAME                                     "L3SW_"\r
+\r
+\r
+// L3 ARP テーブルエントリ\r
+struct L3ARPENTRY\r
+{\r
+       UINT IpAddress;                                 // IP アドレス\r
+       UCHAR MacAddress[6];                    // MAC アドレス\r
+       UCHAR Padding[2];\r
+       UINT64 Expire;                                  // 有効期限\r
+};\r
+\r
+// L3 ARP 解決待ちリストエントリ\r
+struct L3ARPWAIT\r
+{\r
+       UINT IpAddress;                                 // IP アドレス\r
+       UINT64 LastSentTime;                    // 最後に ARP を送信した時刻\r
+       UINT64 Expire;                                  // 有効期限\r
+};\r
+\r
+// L3 IP パケットテーブル\r
+struct L3PACKET\r
+{\r
+       PKT *Packet;                                    // パケットデータ本体\r
+       UINT64 Expire;                                  // 有効期限\r
+       UINT NextHopIp;                                 // ローカル配信宛先 IP アドレス\r
+};\r
+\r
+// L3 ルーティングテーブル定義\r
+struct L3TABLE\r
+{\r
+       UINT NetworkAddress;                    // ネットワークアドレス\r
+       UINT SubnetMask;                                // サブネットマスク\r
+       UINT GatewayAddress;                    // ゲートウェイアドレス\r
+       UINT Metric;                                    // メトリック\r
+};\r
+\r
+// L3 インターフェイス定義\r
+struct L3IF\r
+{\r
+       L3SW *Switch;                                   // Layer-3 スイッチ\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // 仮想 HUB 名\r
+       UINT IpAddress;                                 // IP アドレス\r
+       UINT SubnetMask;                                // サブネットマスク\r
+\r
+       HUB *Hub;                                               // 仮想 HUB\r
+       SESSION *Session;                               // セッション\r
+       LIST *ArpTable;                                 // ARP テーブル\r
+       LIST *ArpWaitTable;                             // ARP 待機テーブル\r
+       QUEUE *IpPacketQueue;                   // IP パケットキュー (他のインターフェイスからの受信用)\r
+       LIST *IpWaitList;                               // IP 待機リスト\r
+       QUEUE *SendQueue;                               // 送信キュー\r
+       UCHAR MacAddress[6];                    // MAC アドレス\r
+       UCHAR Padding[2];\r
+       UINT64 LastDeleteOldArpTable;   // 古い ARP テーブルを清掃した時刻\r
+       LIST *CancelList;                               // キャンセルリスト\r
+       UINT64 LastBeaconSent;                  // 最後にビーコンを送信した時刻\r
+};\r
+\r
+// L3 スイッチ定義\r
+struct L3SW\r
+{\r
+       char Name[MAX_HUBNAME_LEN + 1]; // 名前\r
+       LOCK *lock;                                             // ロック\r
+       REF *ref;                                               // 参照カウンタ\r
+       CEDAR *Cedar;                                   // Cedar\r
+       bool Active;                                    // 動作中フラグ\r
+       bool Online;                                    // オンラインフラグ\r
+       volatile bool Halt;                             // 停止フラグ\r
+       LIST *IfList;                                   // インターフェイスリスト\r
+       LIST *TableList;                                // ルーティングテーブルリスト\r
+       THREAD *Thread;                                 // スレッド\r
+};\r
+\r
+\r
+\r
+// 関数プロトタイプ\r
+int CmpL3Sw(void *p1, void *p2);\r
+int CmpL3ArpEntry(void *p1, void *p2);\r
+int CmpL3ArpWaitTable(void *p1, void *p2);\r
+int CmpL3Table(void *p1, void *p2);\r
+int CmpL3If(void *p1, void *p2);\r
+void InitCedarLayer3(CEDAR *c);\r
+void FreeCedarLayer3(CEDAR *c);\r
+L3SW *NewL3Sw(CEDAR *c, char *name);\r
+void ReleaseL3Sw(L3SW *s);\r
+void CleanupL3Sw(L3SW *s);\r
+bool L3AddIf(L3SW *s, char *hubname, UINT ip, UINT subnet);\r
+bool L3DelIf(L3SW *s, char *hubname);\r
+bool L3AddTable(L3SW *s, L3TABLE *tbl);\r
+bool L3DelTable(L3SW *s, L3TABLE *tbl);\r
+L3IF *L3SearchIf(L3SW *s, char *hubname);\r
+L3SW *L3GetSw(CEDAR *c, char *name);\r
+L3SW *L3AddSw(CEDAR *c, char *name);\r
+bool L3DelSw(CEDAR *c, char *name);\r
+void L3FreeAllSw(CEDAR *c);\r
+void L3SwStart(L3SW *s);\r
+void L3SwStop(L3SW *s);\r
+void L3SwThread(THREAD *t, void *param);\r
+void L3Test(SERVER *s);\r
+void L3InitAllInterfaces(L3SW *s);\r
+void L3FreeAllInterfaces(L3SW *s);\r
+void L3IfThread(THREAD *t, void *param);\r
+void L3InitInterface(L3IF *f);\r
+void L3FreeInterface(L3IF *f);\r
+L3IF *L3GetNextIf(L3SW *s, UINT ip, UINT *next_hop);\r
+L3TABLE *L3GetBestRoute(L3SW *s, UINT ip);\r
+UINT L3GetNextPacket(L3IF *f, void **data);\r
+void L3Polling(L3IF *f);\r
+void L3PollingBeacon(L3IF *f);\r
+void L3DeleteOldArpTable(L3IF *f);\r
+void L3DeleteOldIpWaitList(L3IF *f);\r
+void L3PollingArpWaitTable(L3IF *f);\r
+void L3SendL2Now(L3IF *f, UCHAR *dest_mac, UCHAR *src_mac, USHORT protocol, void *data, UINT size);\r
+void L3SendArpRequestNow(L3IF *f, UINT dest_ip);\r
+void L3SendArpResponseNow(L3IF *f, UCHAR *dest_mac, UINT dest_ip, UINT src_ip);\r
+void L3GenerateMacAddress(L3IF *f);\r
+L3ARPENTRY *L3SearchArpTable(L3IF *f, UINT ip);\r
+void L3SendIpNow(L3IF *f, L3ARPENTRY *a, L3PACKET *p);\r
+void L3SendIp(L3IF *f, L3PACKET *p);\r
+void L3RecvArp(L3IF *f, PKT *p);\r
+void L3RecvArpRequest(L3IF *f, PKT *p);\r
+void L3RecvArpResponse(L3IF *f, PKT *p);\r
+void L3KnownArp(L3IF *f, UINT ip, UCHAR *mac);\r
+void L3SendArp(L3IF *f, UINT ip);\r
+void L3InsertArpTable(L3IF *f, UINT ip, UCHAR *mac);\r
+void L3SendWaitingIp(L3IF *f, UCHAR *mac, UINT ip, L3ARPENTRY *a);\r
+void L3PutPacket(L3IF *f, void *data, UINT size); \r
+void L3RecvL2(L3IF *f, PKT *p);\r
+void L3StoreIpPacketToIf(L3IF *src_if, L3IF *dst_if, L3PACKET *p);\r
+void L3RecvIp(L3IF *f, PKT *p, bool self);\r
+void L3PollingIpQueue(L3IF *f);\r
+\r
+\r
+#endif // LAYER3_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Link.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Link.c
new file mode 100644 (file)
index 0000000..5cc5165
--- /dev/null
@@ -0,0 +1,649 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Link.c\r
+// HUB 間リンク接続\r
+\r
+#include "CedarPch.h"\r
+\r
+// リンクサーバースレッド\r
+void LinkServerSessionThread(THREAD *t, void *param)\r
+{\r
+       LINK *k = (LINK *)param;\r
+       CONNECTION *c;\r
+       SESSION *s;\r
+       POLICY *policy;\r
+       wchar_t name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // サーバーコネクションの作成\r
+       c = NewServerConnection(k->Cedar, NULL, t);\r
+       c->Protocol = CONNECTION_HUB_LINK_SERVER;\r
+\r
+       // ポリシーの作成\r
+       policy = ZeroMalloc(sizeof(POLICY));\r
+       Copy(policy, k->Policy, sizeof(POLICY));\r
+\r
+       // サーバーセッションの作成\r
+       s = NewServerSession(k->Cedar, c, k->Hub, LINK_USER_NAME, policy);\r
+       s->LinkModeServer = true;\r
+       s->Link = k;\r
+       c->Session = s;\r
+       ReleaseConnection(c);\r
+\r
+       // ユーザー名\r
+       s->Username = CopyStr(LINK_USER_NAME_PRINT);\r
+\r
+       k->ServerSession = s;\r
+       AddRef(k->ServerSession->ref);\r
+\r
+       // 初期化完了を通知\r
+       NoticeThreadInit(t);\r
+\r
+       UniStrCpy(name, sizeof(name), k->Option->AccountName);\r
+       HLog(s->Hub, "LH_LINK_START", name, s->Name);\r
+\r
+       // セッションのメイン関数\r
+       SessionMain(s);\r
+\r
+       HLog(s->Hub, "LH_LINK_STOP", name);\r
+\r
+       ReleaseSession(s);\r
+}\r
+\r
+// パケットアダプタ初期化\r
+bool LinkPaInit(SESSION *s)\r
+{\r
+       LINK *k;\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (s == NULL || (k = (LINK *)s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 送信パケットキューの作成\r
+       k->SendPacketQueue = NewQueue();\r
+\r
+       // リンクサーバースレッドの作成\r
+       t = NewThread(LinkServerSessionThread, (void *)k);\r
+       WaitThreadInit(t);\r
+\r
+       ReleaseThread(t);\r
+\r
+       return true;\r
+}\r
+\r
+// キャンセルオブジェクトの取得\r
+CANCEL *LinkPaGetCancel(SESSION *s)\r
+{\r
+       LINK *k;\r
+       // 引数チェック\r
+       if (s == NULL || (k = (LINK *)s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// 次のパケットを取得\r
+UINT LinkPaGetNextPacket(SESSION *s, void **data)\r
+{\r
+       LINK *k;\r
+       UINT ret = 0;\r
+       // 引数チェック\r
+       if (s == NULL || data == NULL || (k = (LINK *)s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       // キューにパケットが溜まっているかどうか調べる\r
+       LockQueue(k->SendPacketQueue);\r
+       {\r
+               BLOCK *block = GetNext(k->SendPacketQueue);\r
+\r
+               if (block != NULL)\r
+               {\r
+                       // パケットがあった\r
+                       *data = block->Buf;\r
+                       ret = block->Size;\r
+                       // 構造体のメモリは破棄する\r
+                       Free(block);\r
+               }\r
+       }\r
+       UnlockQueue(k->SendPacketQueue);\r
+\r
+       return ret;\r
+}\r
+\r
+// 受信したパケットを書き込み\r
+bool LinkPaPutPacket(SESSION *s, void *data, UINT size)\r
+{\r
+       LINK *k;\r
+       BLOCK *block;\r
+       SESSION *server_session;\r
+       CONNECTION *server_connection;\r
+       // 引数チェック\r
+       if (s == NULL || (k = (LINK *)s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       server_session = k->ServerSession;\r
+       server_connection = server_session->Connection;\r
+\r
+       // ここにはリンク接続先の HUB から届いたパケットが来るので\r
+       // サーバーセッションの ReceivedBlocks に届けてあげる\r
+       if (data != NULL)\r
+       {\r
+               block = NewBlock(data, size, 0);\r
+\r
+               LockQueue(server_connection->ReceivedBlocks);\r
+               {\r
+                       InsertQueue(server_connection->ReceivedBlocks, block);\r
+               }\r
+               UnlockQueue(server_connection->ReceivedBlocks);\r
+       }\r
+       else\r
+       {\r
+               // data == NULL のとき、すべてのパケットを格納し終わったので\r
+               // Cancel を発行する\r
+               Cancel(server_session->Cancel1);\r
+\r
+               if (k->Hub != NULL && k->Hub->Option != NULL && k->Hub->Option->YieldAfterStorePacket)\r
+               {\r
+                       YieldCpu();\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// パケットアダプタの解放\r
+void LinkPaFree(SESSION *s)\r
+{\r
+       LINK *k;\r
+       // 引数チェック\r
+       if (s == NULL || (k = (LINK *)s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // サーバーセッションの停止\r
+       StopSession(k->ServerSession);\r
+       ReleaseSession(k->ServerSession);\r
+\r
+       // 送信パケットキューの解放\r
+       LockQueue(k->SendPacketQueue);\r
+       {\r
+               BLOCK *block;\r
+               while (block = GetNext(k->SendPacketQueue))\r
+               {\r
+                       FreeBlock(block);\r
+               }\r
+       }\r
+       UnlockQueue(k->SendPacketQueue);\r
+\r
+       ReleaseQueue(k->SendPacketQueue);\r
+}\r
+\r
+// パケットアダプタ\r
+PACKET_ADAPTER *LinkGetPacketAdapter()\r
+{\r
+       return NewPacketAdapter(LinkPaInit, LinkPaGetCancel, LinkPaGetNextPacket,\r
+               LinkPaPutPacket, LinkPaFree);\r
+}\r
+\r
+// すべてのリンクの解放\r
+void ReleaseAllLink(HUB *h)\r
+{\r
+       LINK **kk;\r
+       UINT num, i;\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(h->LinkList);\r
+       {\r
+               num = LIST_NUM(h->LinkList);\r
+               kk = ToArray(h->LinkList);\r
+               DeleteAll(h->LinkList);\r
+       }\r
+       UnlockList(h->LinkList);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               LINK *k = kk[i];\r
+\r
+               ReleaseLink(k);\r
+       }\r
+\r
+       Free(kk);\r
+}\r
+\r
+// リンクの解放\r
+void ReleaseLink(LINK *k)\r
+{\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(k->ref) == 0)\r
+       {\r
+               CleanupLink(k);\r
+       }\r
+}\r
+\r
+// リンクのクリーンアップ\r
+void CleanupLink(LINK *k)\r
+{\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DeleteLock(k->lock);\r
+       if (k->ClientSession)\r
+       {\r
+               ReleaseSession(k->ClientSession);\r
+       }\r
+       Free(k->Option);\r
+       CiFreeClientAuth(k->Auth);\r
+       Free(k->Policy);\r
+\r
+       if (k->ServerCert != NULL)\r
+       {\r
+               FreeX(k->ServerCert);\r
+       }\r
+\r
+       Free(k);\r
+}\r
+\r
+// リンクをオンラインにする\r
+void SetLinkOnline(LINK *k)\r
+{\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (k->Offline == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       k->Offline = false;\r
+       StartLink(k);\r
+}\r
+\r
+// リンクをオフラインにする\r
+void SetLinkOffline(LINK *k)\r
+{\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (k->Offline)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StopLink(k);\r
+       k->Offline = true;\r
+}\r
+\r
+// リンクの削除\r
+void DelLink(HUB *hub, LINK *k)\r
+{\r
+       // 引数チェック\r
+       if (hub == NULL || k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(hub->LinkList);\r
+       {\r
+               if (Delete(hub->LinkList, k))\r
+               {\r
+                       ReleaseLink(k);\r
+               }\r
+       }\r
+       UnlockList(hub->LinkList);\r
+}\r
+\r
+// すべてのリンクの開始\r
+void StartAllLink(HUB *h)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(h->LinkList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(h->LinkList);i++)\r
+               {\r
+                       LINK *k = (LINK *)LIST_DATA(h->LinkList, i);\r
+\r
+                       if (k->Offline == false)\r
+                       {\r
+                               StartLink(k);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(h->LinkList);\r
+}\r
+\r
+// すべてのリンクの停止\r
+void StopAllLink(HUB *h)\r
+{\r
+       LINK **link_list;\r
+       UINT num_link;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(h->LinkList);\r
+       {\r
+               link_list = ToArray(h->LinkList);\r
+               num_link = LIST_NUM(h->LinkList);\r
+               for (i = 0;i < num_link;i++)\r
+               {\r
+                       AddRef(link_list[i]->ref);\r
+               }\r
+       }\r
+       UnlockList(h->LinkList);\r
+\r
+       for (i = 0;i < num_link;i++)\r
+       {\r
+               StopLink(link_list[i]);\r
+               ReleaseLink(link_list[i]);\r
+       }\r
+\r
+       Free(link_list);\r
+}\r
+\r
+// リンクの開始\r
+void StartLink(LINK *k)\r
+{\r
+       PACKET_ADAPTER *pa;\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockLink(k);\r
+       {\r
+               if (k->Started || k->Halting)\r
+               {\r
+                       UnlockLink(k);\r
+                       return;\r
+               }\r
+               k->Started = true;\r
+       }\r
+       UnlockLink(k);\r
+\r
+       // クライアントセッション接続\r
+       pa = LinkGetPacketAdapter();\r
+       pa->Param = (void *)k;\r
+       LockLink(k);\r
+       {\r
+               k->ClientSession = NewClientSession(k->Cedar, k->Option, k->Auth, pa);\r
+       }\r
+       UnlockLink(k);\r
+}\r
+\r
+// リンクの停止\r
+void StopLink(LINK *k)\r
+{\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockLink(k);\r
+       {\r
+               if (k->Started == false)\r
+               {\r
+                       UnlockLink(k);\r
+                       return;\r
+               }\r
+               k->Started = false;\r
+               k->Halting = true;\r
+       }\r
+       UnlockLink(k);\r
+\r
+       if (k->ClientSession != NULL)\r
+       {\r
+               // クライアントセッション切断\r
+               StopSession(k->ClientSession);\r
+\r
+               LockLink(k);\r
+               {\r
+                       ReleaseSession(k->ClientSession);\r
+                       k->ClientSession = NULL;\r
+               }\r
+               UnlockLink(k);\r
+       }\r
+\r
+       LockLink(k);\r
+       {\r
+               k->Halting = false;\r
+       }\r
+       UnlockLink(k);\r
+}\r
+\r
+// リンクのロック\r
+void LockLink(LINK *k)\r
+{\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(k->lock);\r
+}\r
+\r
+// ロックのリンク解除\r
+void UnlockLink(LINK *k)\r
+{\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Unlock(k->lock);\r
+}\r
+\r
+// リンク用ポリシーの正規化\r
+void NormalizeLinkPolicy(POLICY *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p->Access = true;\r
+       p->NoBridge = p->NoRouting = p->PrivacyFilter =\r
+               p->MonitorPort = false;\r
+       p->MaxConnection = 32;\r
+       p->TimeOut = 20;\r
+       p->FixPassword = false;\r
+}\r
+\r
+// リンクの作成\r
+LINK *NewLink(CEDAR *cedar, HUB *hub, CLIENT_OPTION *option, CLIENT_AUTH *auth, POLICY *policy)\r
+{\r
+       CLIENT_OPTION *o;\r
+       LINK *k;\r
+       CLIENT_AUTH *a;\r
+       // 引数チェック\r
+       if (cedar == NULL || hub == NULL || option == NULL || auth == NULL || policy == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (hub->Halt)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (LIST_NUM(hub->LinkList) >= MAX_HUB_LINKS)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (UniIsEmptyStr(option->AccountName))\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 認証方法の制限\r
+       if (auth->AuthType != CLIENT_AUTHTYPE_ANONYMOUS && auth->AuthType != CLIENT_AUTHTYPE_PASSWORD &&\r
+               auth->AuthType != CLIENT_AUTHTYPE_PLAIN_PASSWORD && auth->AuthType != CLIENT_AUTHTYPE_CERT)\r
+       {\r
+               // 匿名認証、パスワード認証、プレーンパスワード、証明書認証以外の認証方法は使用できない\r
+               return NULL;\r
+       }\r
+\r
+       // クライアントオプションのコピー (改変用)\r
+       o = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       Copy(o, option, sizeof(CLIENT_OPTION));\r
+       StrCpy(o->DeviceName, sizeof(o->DeviceName), LINK_DEVICE_NAME);\r
+\r
+       o->RequireBridgeRoutingMode = true;     // ブリッジモードを要求する\r
+       o->RequireMonitorMode = false;  // モニタモードは要求しない\r
+\r
+       o->NumRetry = INFINITE;                 // 接続の再試行は無限に行う\r
+       o->RetryInterval = 10;                  // 再試行間隔は 10 秒\r
+       o->NoRoutingTracking = true;    // ルーティング追跡停止\r
+\r
+       // 認証データのコピー\r
+       a = CopyClientAuth(auth);\r
+       a->SecureSignProc = NULL;\r
+       a->CheckCertProc = NULL;\r
+\r
+       // リンク オブジェクト\r
+       k = ZeroMalloc(sizeof(LINK));\r
+       k->lock = NewLock();\r
+       k->ref = NewRef();\r
+\r
+       k->Cedar = cedar;\r
+       k->Option = o;\r
+       k->Auth = a;\r
+       k->Hub = hub;\r
+\r
+       // ポリシーのコピー\r
+       k->Policy = ZeroMalloc(sizeof(POLICY));\r
+       Copy(k->Policy, policy, sizeof(POLICY));\r
+\r
+       // ポリシーの正規化\r
+       NormalizeLinkPolicy(k->Policy);\r
+\r
+       // HUB のリンクリストに登録する\r
+       LockList(hub->LinkList);\r
+       {\r
+               Add(hub->LinkList, k);\r
+               AddRef(k->ref);\r
+       }\r
+       UnlockList(hub->LinkList);\r
+\r
+       return k;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Link.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Link.h
new file mode 100644 (file)
index 0000000..9124ab1
--- /dev/null
@@ -0,0 +1,132 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Link.h\r
+// Link.c のヘッダ\r
+\r
+#ifndef        LINK_H\r
+#define        LINK_H\r
+\r
+struct LINK\r
+{\r
+       bool Started;                                   // 開始フラグ\r
+       volatile bool Halting;                  // 停止フラグ\r
+       bool Offline;                                   // オフライン\r
+       REF *ref;                                               // 参照カウンタ\r
+       LOCK *lock;                                             // ロック\r
+       CEDAR *Cedar;                                   // Cedar\r
+       HUB *Hub;                                               // HUB\r
+       SESSION *ClientSession;                 // クライアントセッション\r
+       SESSION *ServerSession;                 // サーバーセッション\r
+       CLIENT_OPTION *Option;                  // クライアントオプション\r
+       CLIENT_AUTH *Auth;                              // 認証データ\r
+       POLICY *Policy;                                 // ポリシー\r
+       QUEUE *SendPacketQueue;                 // 送信パケットキュー\r
+       UINT LastError;                                 // 最後のエラー\r
+       bool CheckServerCert;                   // サーバー証明書をチェックする\r
+       X *ServerCert;                                  // サーバー証明書\r
+};\r
+\r
+\r
+PACKET_ADAPTER *LinkGetPacketAdapter();\r
+bool LinkPaInit(SESSION *s);\r
+CANCEL *LinkPaGetCancel(SESSION *s);\r
+UINT LinkPaGetNextPacket(SESSION *s, void **data);\r
+bool LinkPaPutPacket(SESSION *s, void *data, UINT size);\r
+void LinkPaFree(SESSION *s);\r
+\r
+void LinkServerSessionThread(THREAD *t, void *param);\r
+LINK *NewLink(CEDAR *cedar, HUB *hub, CLIENT_OPTION *option, CLIENT_AUTH *auth, POLICY *policy);\r
+void StartLink(LINK *k);\r
+void StopLink(LINK *k);\r
+void DelLink(HUB *hub, LINK *k);\r
+void LockLink(LINK *k);\r
+void UnlockLink(LINK *k);\r
+void StopAllLink(HUB *h);\r
+void StartAllLink(HUB *h);\r
+void SetLinkOnline(LINK *k);\r
+void SetLinkOffline(LINK *k);\r
+void ReleaseLink(LINK *k);\r
+void CleanupLink(LINK *k);\r
+void ReleaseAllLink(HUB *h);\r
+void NormalizeLinkPolicy(POLICY *p);\r
+\r
+#endif // LINK_H\r
+\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Listener.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Listener.c
new file mode 100644 (file)
index 0000000..2d155cc
--- /dev/null
@@ -0,0 +1,823 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Listener.c\r
+// リスナー モジュール\r
+\r
+#include "CedarPch.h"\r
+\r
+// UDP パケットを 1 つ受信した\r
+void UDPReceivedPacket(CEDAR *cedar, SOCK *s, IP *ip, UINT port, void *data, UINT size)\r
+{\r
+       SESSION *session;\r
+       UINT *key32;\r
+       UCHAR *buf;\r
+       CONNECTION *c;\r
+       // 引数チェック\r
+       if (s == NULL || ip == NULL || data == NULL || size == 0 || cedar == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (size < 16)\r
+       {\r
+               // パケットサイズが足らないので無視\r
+               return;\r
+       }\r
+       buf = (UCHAR *)data;\r
+       key32 = (UINT *)(buf + 4);\r
+\r
+\r
+       // Key32 の値からセッションを取得\r
+       session = GetSessionFromUDPEntry(cedar, Endian32(*key32));\r
+       if (session == NULL)\r
+       {\r
+               Debug("Invalid UDP Session Key 32: 0x%X\n", *key32);\r
+               return;\r
+       }\r
+\r
+       c = session->Connection;\r
+\r
+       // データを書き込む\r
+       PutUDPPacketData(c, buf, size);\r
+\r
+       // コネクションに関連付けられている UDP ソケットを書き換える\r
+       Lock(c->lock);\r
+       {\r
+               if (c->Protocol == CONNECTION_UDP)\r
+               {\r
+                       if (c->Udp->s != s)\r
+                       {\r
+                               if (c->Udp->s != NULL)\r
+                               {\r
+                                       ReleaseSock(c->Udp->s);\r
+                               }\r
+                               AddRef(s->ref);\r
+                               c->Udp->s = s;\r
+                       }\r
+                       Copy(&c->Udp->ip, ip, sizeof(UINT));\r
+                       c->Udp->port = port;\r
+               }\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       // キャンセル発動\r
+       Cancel(session->Cancel1);\r
+\r
+       // セッションを解放\r
+       ReleaseSession(session);\r
+}\r
+\r
+// Accept された TCP コネクションを処理するスレッド\r
+void TCPAcceptedThread(THREAD *t, void *param)\r
+{\r
+       TCP_ACCEPTED_PARAM *data;\r
+       LISTENER *r;\r
+       SOCK *s;\r
+       CONNECTION *c;\r
+       bool flag1;\r
+       char tmp[128];\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 初期化\r
+       data = (TCP_ACCEPTED_PARAM *)param;\r
+       r = data->r;\r
+       s = data->s;\r
+       AddRef(r->ref);\r
+       AddRef(s->ref);\r
+\r
+       // コネクションの作成\r
+       c = NewServerConnection(r->Cedar, s, t);\r
+\r
+       // Cedar に一時コネクションとして登録する\r
+       AddConnection(c->Cedar, c);\r
+\r
+       NoticeThreadInit(t);\r
+\r
+       AcceptInit(s);\r
+       StrCpy(c->ClientHostname, sizeof(c->ClientHostname), s->RemoteHostname);\r
+       IPToStr(tmp, sizeof(tmp), &s->RemoteIP);\r
+       SLog(r->Cedar, "LS_LISTENER_ACCEPT", r->Port, tmp, s->RemoteHostname, s->RemotePort);\r
+\r
+       // 受付\r
+       ConnectionAccept(c);\r
+       flag1 = c->flag1;\r
+\r
+       // 解放\r
+       SLog(r->Cedar, "LS_CONNECTION_END_1", c->Name);\r
+       ReleaseConnection(c);\r
+\r
+       // 解放\r
+       if (flag1 == false)\r
+       {\r
+               Debug("%s %u flag1 == false\n", __FILE__, __LINE__);\r
+               IPToStr(tmp, sizeof(tmp), &s->RemoteIP);\r
+               SLog(r->Cedar, "LS_LISTENER_DISCONNECT", tmp, s->RemotePort);\r
+               Disconnect(s);\r
+       }\r
+       ReleaseSock(s);\r
+       ReleaseListener(r);\r
+}\r
+\r
+// TCP で Accept されたコネクションがある場合はここに飛ぶ\r
+void TCPAccepted(LISTENER *r, SOCK *s)\r
+{\r
+       TCP_ACCEPTED_PARAM *data;\r
+       THREAD *t;\r
+       char tmp[MAX_SIZE];\r
+       UINT num_clients_from_this_ip = 0;\r
+       CEDAR *cedar;\r
+       // 引数チェック\r
+       if (r == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       cedar = r->Cedar;\r
+\r
+       num_clients_from_this_ip = GetNumIpClient(&s->RemoteIP);\r
+\r
+       IPToStr(tmp, sizeof(tmp), &s->RemoteIP);\r
+\r
+       data = ZeroMalloc(sizeof(TCP_ACCEPTED_PARAM));\r
+       data->r = r;\r
+       data->s = s;\r
+\r
+       if (r->ThreadProc == TCPAcceptedThread)\r
+       {\r
+               Inc(cedar->AcceptingSockets);\r
+       }\r
+\r
+       t = NewThread(r->ThreadProc, data);\r
+       WaitThreadInit(t);\r
+       Free(data);\r
+       ReleaseThread(t);\r
+}\r
+\r
+// UDP リスナーメインループ\r
+void ListenerUDPMainLoop(LISTENER *r)\r
+{\r
+       UCHAR *data;\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Debug("ListenerUDPMainLoop Starts.\n");\r
+       r->Status = LISTENER_STATUS_TRYING;\r
+\r
+       while (true)\r
+       {\r
+               // UDP ポートでの待機を試みる\r
+               while (true)\r
+               {\r
+                       // 停止フラグ検査\r
+                       if (r->Halt)\r
+                       {\r
+                               // 停止\r
+                               return;\r
+                       }\r
+\r
+                       Debug("NewUDP()\n");\r
+                       r->Sock = NewUDP(r->Port);\r
+                       if (r->Sock != NULL)\r
+                       {\r
+                               // 待機成功\r
+                               break;\r
+                       }\r
+\r
+                       // 待機失敗\r
+                       Debug("Failed to NewUDP.\n");\r
+                       Wait(r->Event, LISTEN_RETRY_TIME);\r
+\r
+                       // 停止フラグ検査\r
+                       if (r->Halt)\r
+                       {\r
+                               Debug("UDP Halt.\n");\r
+                               return;\r
+                       }\r
+               }\r
+\r
+               r->Status = LISTENER_STATUS_LISTENING;\r
+               Debug("Start Listening at UDP Port %u.\n", r->Sock->LocalPort);\r
+\r
+               // 停止フラグ検査\r
+               if (r->Halt)\r
+               {\r
+                       // 停止\r
+                       goto STOP;\r
+               }\r
+\r
+               // バッファ領域の確保\r
+               data = Malloc(UDP_PACKET_SIZE);\r
+\r
+               // 次のパケットを読み込む\r
+               while (true)\r
+               {\r
+                       IP src_ip;\r
+                       UINT src_port;\r
+                       UINT size;\r
+                       SOCKSET set;\r
+\r
+                       InitSockSet(&set);\r
+                       AddSockSet(&set, r->Sock);\r
+                       Select(&set, SELECT_TIME, NULL, NULL);\r
+\r
+                       size = RecvFrom(r->Sock, &src_ip, &src_port, data, UDP_PACKET_SIZE);\r
+                       if (((size == 0) && (r->Sock->IgnoreRecvErr == false)) || r->Halt)\r
+                       {\r
+                               // エラーが発生した\r
+STOP:\r
+                               Disconnect(r->Sock);\r
+                               ReleaseSock(r->Sock);\r
+                               r->Sock = NULL;\r
+                               Debug("UDP Listen Stopped.\n");\r
+                               Free(data);\r
+                               break;\r
+                       }\r
+\r
+                       // UDP パケットを 1 つ受信した\r
+                       if (size != SOCK_LATER)\r
+                       {\r
+                               UDPReceivedPacket(r->Cedar, r->Sock, &src_ip, src_port, data, size);\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// TCP リスナーメインループ\r
+void ListenerTCPMainLoop(LISTENER *r)\r
+{\r
+       SOCK *new_sock;\r
+       SOCK *s;\r
+       UINT num_failed;\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Debug("ListenerTCPMainLoop Starts.\n");\r
+       r->Status = LISTENER_STATUS_TRYING;\r
+\r
+       while (true)\r
+       {\r
+               bool first_failed = true;\r
+               Debug("Status = LISTENER_STATUS_TRYING\n");\r
+               r->Status = LISTENER_STATUS_TRYING;\r
+\r
+               // Listen を試みる\r
+               while (true)\r
+               {\r
+                       UINT interval;\r
+                       // 停止フラグ検査\r
+                       if (r->Halt)\r
+                       {\r
+                               // 停止\r
+                               return;\r
+                       }\r
+\r
+                       if (r->ShadowIPv6 == false)\r
+                       {\r
+                               s = ListenEx(r->Port, r->LocalOnly);\r
+                       }\r
+                       else\r
+                       {\r
+                               s = ListenEx6(r->Port, r->LocalOnly);\r
+                       }\r
+\r
+                       if (s != NULL)\r
+                       {\r
+                               // Listen 成功\r
+                               AddRef(s->ref);\r
+                               r->Sock = s;\r
+                               if (r->ShadowIPv6 == false)\r
+                               {\r
+                                       SLog(r->Cedar, "LS_LISTENER_START_2", r->Port);\r
+                               }\r
+                               break;\r
+                       }\r
+\r
+                       // Listen 失敗\r
+                       if (first_failed)\r
+                       {\r
+                               first_failed = false;\r
+                               if (r->ShadowIPv6 == false)\r
+                               {\r
+                                       SLog(r->Cedar, "LS_LISTENER_START_3", r->Port, LISTEN_RETRY_TIME / 1000);\r
+                               }\r
+                       }\r
+\r
+                       interval = LISTEN_RETRY_TIME;\r
+\r
+                       if (r->ShadowIPv6)\r
+                       {\r
+                               if (IsIPv6Supported() == false)\r
+                               {\r
+                                       interval = LISTEN_RETRY_TIME_NOIPV6;\r
+\r
+                                       Debug("IPv6 is not supported.\n");\r
+                               }\r
+                       }\r
+\r
+                       Wait(r->Event, interval);\r
+\r
+                       // 停止フラグ検査\r
+                       if (r->Halt)\r
+                       {\r
+                               // 停止\r
+                               Debug("Listener Halt.\n");\r
+                               return;\r
+                       }\r
+               }\r
+\r
+               r->Status = LISTENER_STATUS_LISTENING;\r
+               Debug("Status = LISTENER_STATUS_LISTENING\n");\r
+\r
+               // 停止フラグ検査\r
+               if (r->Halt)\r
+               {\r
+                       // 停止\r
+                       goto STOP;\r
+               }\r
+\r
+               num_failed = 0;\r
+\r
+               // Accpet ループ\r
+               while (true)\r
+               {\r
+                       // Accept を行う\r
+                       Debug("Accept()\n");\r
+                       new_sock = Accept(r->Sock);\r
+                       if (new_sock != NULL)\r
+                       {\r
+                               // Accept 成功\r
+                               Debug("Accepted.\n");\r
+                               TCPAccepted(r, new_sock);\r
+                               ReleaseSock(new_sock);\r
+                       }\r
+                       else\r
+                       {\r
+                               if (r->Halt == false)\r
+                               {\r
+                                       if ((++num_failed) <= 5)\r
+                                       {\r
+                                               continue;\r
+                                       }\r
+                               }\r
+STOP:\r
+                               Debug("Accept Canceled.\n");\r
+                               // Accept に失敗した (ソケットが破壊された)\r
+                               // Listen しているソケットを閉じる\r
+                               Disconnect(s);\r
+                               ReleaseSock(s);\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               // 停止フラグ検査\r
+               if (r->Halt)\r
+               {\r
+                       // 停止\r
+                       Debug("Listener Halt.\n");\r
+                       return;\r
+               }\r
+       }\r
+}\r
+\r
+// リスナーのスレッド\r
+void ListenerThread(THREAD *thread, void *param)\r
+{\r
+       LISTENER *r;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 初期化\r
+       r = (LISTENER *)param;\r
+       AddRef(r->ref);\r
+       r->Thread = thread;\r
+       AddRef(thread->ref);\r
+       NoticeThreadInit(thread);\r
+\r
+       // メインループ\r
+       switch (r->Protocol)\r
+       {\r
+       case LISTENER_TCP:\r
+               // TCP プロトコル\r
+               ListenerTCPMainLoop(r);\r
+               break;\r
+\r
+       case LISTENER_UDP:\r
+               // UDP プロトコル\r
+               ListenerUDPMainLoop(r);\r
+               break;\r
+       }\r
+\r
+       // 解放\r
+       ReleaseListener(r);\r
+}\r
+\r
+// リスナーの停止\r
+void StopListener(LISTENER *r)\r
+{\r
+       UINT port;\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (r->Halt)\r
+       {\r
+               return;\r
+       }\r
+\r
+       port = r->Port;\r
+\r
+       // 停止フラグセット\r
+       r->Halt = true;\r
+\r
+       if (r->ShadowIPv6 == false)\r
+       {\r
+               SLog(r->Cedar, "LS_LISTENER_STOP_1", port);\r
+       }\r
+\r
+       // ソケットを閉じる\r
+       Disconnect(r->Sock);\r
+\r
+       // イベントのセット\r
+       Set(r->Event);\r
+\r
+       // スレッドが停止するまで待機\r
+       WaitThread(r->Thread, INFINITE);\r
+\r
+       // 影のリスナーを停止させる\r
+       if (r->ShadowIPv6 == false)\r
+       {\r
+               if (r->ShadowListener != NULL)\r
+               {\r
+                       StopListener(r->ShadowListener);\r
+\r
+                       ReleaseListener(r->ShadowListener);\r
+\r
+                       r->ShadowListener = NULL;\r
+               }\r
+       }\r
+\r
+       if (r->ShadowIPv6 == false)\r
+       {\r
+               SLog(r->Cedar, "LS_LISTENER_STOP_2", port);\r
+       }\r
+}\r
+\r
+// リスナーのクリーンアップ\r
+void CleanupListener(LISTENER *r)\r
+{\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (r->Sock != NULL)\r
+       {\r
+               ReleaseSock(r->Sock);\r
+       }\r
+\r
+       DeleteLock(r->lock);\r
+       ReleaseThread(r->Thread);\r
+       ReleaseEvent(r->Event);\r
+\r
+       ReleaseCedar(r->Cedar);\r
+\r
+       Free(r);\r
+}\r
+\r
+// リスナーの解放\r
+void ReleaseListener(LISTENER *r)\r
+{\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(r->ref) == 0)\r
+       {\r
+               CleanupListener(r);\r
+       }\r
+}\r
+\r
+// UDP エントリリストの比較関数\r
+int CompareUDPEntry(void *p1, void *p2)\r
+{\r
+       UDP_ENTRY *e1, *e2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       e1 = *(UDP_ENTRY **)p1;\r
+       e2 = *(UDP_ENTRY **)p2;\r
+       if (e1 == NULL || e2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (e1->SessionKey32 > e2->SessionKey32)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (e1->SessionKey32 == e2->SessionKey32)\r
+       {\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               return -1;\r
+       }\r
+}\r
+\r
+// リスナーの比較関数\r
+int CompareListener(void *p1, void *p2)\r
+{\r
+       LISTENER *r1, *r2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       r1 = *(LISTENER **)p1;\r
+       r2 = *(LISTENER **)p2;\r
+       if (r1 == NULL || r2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (r1->Protocol > r2->Protocol)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (r1->Protocol < r2->Protocol)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (r1->Port > r2->Port)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (r1->Port < r2->Port)\r
+       {\r
+               return -1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+// 新しいリスナーの作成\r
+LISTENER *NewListener(CEDAR *cedar, UINT proto, UINT port)\r
+{\r
+       return NewListenerEx(cedar, proto, port, TCPAcceptedThread, NULL);\r
+}\r
+LISTENER *NewListenerEx(CEDAR *cedar, UINT proto, UINT port, THREAD_PROC *proc, void *thread_param)\r
+{\r
+       return NewListenerEx2(cedar, proto, port, proc, thread_param, false);\r
+}\r
+LISTENER *NewListenerEx2(CEDAR *cedar, UINT proto, UINT port, THREAD_PROC *proc, void *thread_param, bool local_only)\r
+{\r
+       return NewListenerEx3(cedar, proto, port, proc, thread_param, local_only, false);\r
+}\r
+LISTENER *NewListenerEx3(CEDAR *cedar, UINT proto, UINT port, THREAD_PROC *proc, void *thread_param, bool local_only, bool shadow_ipv6)\r
+{\r
+       LISTENER *r;\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (port == 0 || cedar == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       // プロトコル番号のチェック\r
+       if (proto != LISTENER_TCP && proto != LISTENER_UDP)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       r = ZeroMalloc(sizeof(LISTENER));\r
+\r
+       r->ThreadProc = proc;\r
+       r->ThreadParam = thread_param;\r
+       r->Cedar = cedar;\r
+       AddRef(r->Cedar->ref);\r
+       r->lock = NewLock();\r
+       r->ref = NewRef();\r
+       r->Protocol = proto;\r
+       r->Port = port;\r
+       r->Event = NewEvent();\r
+       r->LocalOnly = local_only;\r
+       r->ShadowIPv6 = shadow_ipv6;\r
+\r
+       if (r->ShadowIPv6 == false)\r
+       {\r
+               SLog(cedar, "LS_LISTENER_START_1", port);\r
+       }\r
+\r
+       // スレッドの作成\r
+       t = NewThread(ListenerThread, r);\r
+       WaitThreadInit(t);\r
+       ReleaseThread(t);\r
+\r
+       if (r->ShadowIPv6 == false)\r
+       {\r
+               if (r->Cedar->DisableIPv6Listener == false)\r
+               {\r
+                       // 影のリスナーを追加する\r
+                       r->ShadowListener = NewListenerEx3(cedar, proto, port, proc, thread_param,\r
+                               local_only, true);\r
+               }\r
+       }\r
+\r
+       if (r->ShadowIPv6 == false)\r
+       {\r
+               // Cedar に追加\r
+               AddListener(cedar, r);\r
+       }\r
+\r
+       return r;\r
+}\r
+\r
+// セッションキーからセッションを取得する\r
+SESSION *GetSessionFromUDPEntry(CEDAR *cedar, UINT key32)\r
+{\r
+       UDP_ENTRY *e, t;\r
+       SESSION *s;\r
+       // 引数チェック\r
+       if (cedar == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t.SessionKey32 = key32;\r
+\r
+       LockList(cedar->UDPEntryList);\r
+       {\r
+               e = Search(cedar->UDPEntryList, &t);\r
+               if (e == NULL)\r
+               {\r
+                       UnlockList(cedar->UDPEntryList);\r
+                       return NULL;\r
+               }\r
+               s = e->Session;\r
+               AddRef(s->ref);\r
+       }\r
+       UnlockList(cedar->UDPEntryList);\r
+\r
+       return s;\r
+}\r
+\r
+// UDP セッションを UDP エントリから削除する\r
+void DelUDPEntry(CEDAR *cedar, SESSION *session)\r
+{\r
+       UINT num, i;\r
+       // 引数チェック\r
+       if (cedar == NULL || session == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(cedar->UDPEntryList);\r
+       {\r
+               num = LIST_NUM(cedar->UDPEntryList);\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       UDP_ENTRY *e = LIST_DATA(cedar->UDPEntryList, i);\r
+                       if (e->Session == session)\r
+                       {\r
+                               ReleaseSession(e->Session);\r
+                               Delete(cedar->UDPEntryList, e);\r
+                               Free(e);\r
+                               UnlockList(cedar->UDPEntryList);\r
+                               Debug("UDP_Entry Deleted.\n");\r
+                               return;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(cedar->UDPEntryList);\r
+}\r
+\r
+// UDP セッションを UDP エントリに追加する\r
+void AddUDPEntry(CEDAR *cedar, SESSION *session)\r
+{\r
+       UDP_ENTRY *e;\r
+       // 引数チェック\r
+       if (cedar == NULL || session == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       e = ZeroMalloc(sizeof(UDP_ENTRY));\r
+       e->Session = session;\r
+       e->SessionKey32 = session->SessionKey32;\r
+       AddRef(session->ref);\r
+\r
+       LockList(cedar->UDPEntryList);\r
+       {\r
+               Add(cedar->UDPEntryList, e);\r
+       }\r
+       UnlockList(cedar->UDPEntryList);\r
+\r
+       Debug("UDP_Entry Added.\n");\r
+}\r
+\r
+// UDP エントリのクリア\r
+void CleanupUDPEntry(CEDAR *cedar)\r
+{\r
+       // 引数チェック\r
+       if (cedar == NULL)\r
+       {\r
+               return;\r
+       }\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Listener.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Listener.h
new file mode 100644 (file)
index 0000000..edf22ed
--- /dev/null
@@ -0,0 +1,147 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Listener.h\r
+// Listener.c のヘッダ\r
+\r
+#ifndef        LISTENER_H\r
+#define        LISTENER_H\r
+\r
+\r
+// 新しいコネクションを受け付けた際に呼び出す関数\r
+typedef void (NEW_CONNECTION_PROC)(CONNECTION *c);\r
+\r
+\r
+// リスナー構造体\r
+struct LISTENER\r
+{\r
+       LOCK *lock;                                             // ロック\r
+       REF *ref;                                               // 参照カウンタ\r
+       CEDAR *Cedar;                                   // Cedar\r
+       UINT Protocol;                                  // プロトコル\r
+       UINT Port;                                              // ポート番号\r
+       THREAD *Thread;                                 // 動作スレッド\r
+       SOCK *Sock;                                             // ソケット\r
+       EVENT *Event;                                   // イベント\r
+       volatile bool Halt;                             // 停止フラグ\r
+       UINT Status;                                    // 状態\r
+       THREAD_PROC *ThreadProc;                // スレッドプロシージャ\r
+       void *ThreadParam;                              // スレッドパラメータ\r
+       bool LocalOnly;                                 // localhost からのみ接続できる\r
+       bool ShadowIPv6;                                // 影の IPv6 リスナーであることを示すフラグ\r
+       LISTENER *ShadowListener;               // 管理している影の IPv6 リスナーへの参照\r
+};\r
+\r
+// TCPAcceptedThread のパラメータ\r
+struct TCP_ACCEPTED_PARAM\r
+{\r
+       LISTENER *r;\r
+       SOCK *s;\r
+};\r
+\r
+// UDP エントリ\r
+struct UDP_ENTRY\r
+{\r
+       UINT SessionKey32;                              // 32bit セッションキー\r
+       SESSION *Session;               // セッションへの参照\r
+};\r
+\r
+\r
+// 関数プロトタイプ\r
+LISTENER *NewListener(CEDAR *cedar, UINT proto, UINT port);\r
+LISTENER *NewListenerEx(CEDAR *cedar, UINT proto, UINT port, THREAD_PROC *proc, void *thread_param);\r
+LISTENER *NewListenerEx2(CEDAR *cedar, UINT proto, UINT port, THREAD_PROC *proc, void *thread_param, bool local_only);\r
+LISTENER *NewListenerEx3(CEDAR *cedar, UINT proto, UINT port, THREAD_PROC *proc, void *thread_param, bool local_only, bool shadow_ipv6);\r
+void ReleaseListener(LISTENER *r);\r
+void CleanupListener(LISTENER *r);\r
+void ListenerThread(THREAD *thread, void *param);\r
+void ListenerTCPMainLoop(LISTENER *r);\r
+void StopListener(LISTENER *r);\r
+int CompareListener(void *p1, void *p2);\r
+void TCPAccepted(LISTENER *r, SOCK *s);\r
+void TCPAcceptedThread(THREAD *t, void *param);\r
+void ListenerUDPMainLoop(LISTENER *r);\r
+void UDPReceivedPacket(CEDAR *cedar, SOCK *s, IP *ip, UINT port, void *data, UINT size);\r
+int CompareUDPEntry(void *p1, void *p2);\r
+void CleanupUDPEntry(CEDAR *cedar);\r
+void AddUDPEntry(CEDAR *cedar, SESSION *session);\r
+void DelUDPEntry(CEDAR *cedar, SESSION *session);\r
+SESSION *GetSessionFromUDPEntry(CEDAR *cedar, UINT key32);\r
+\r
+#endif // LISTENER_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Logging.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Logging.c
new file mode 100644 (file)
index 0000000..b47731e
--- /dev/null
@@ -0,0 +1,1958 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Logging.c\r
+// ログ保存モジュール\r
+\r
+#include "CedarPch.h"\r
+\r
+static char *delete_targets[] =\r
+{\r
+       "backup.vpn_bridge.config",\r
+       "backup.vpn_client.config",\r
+       "backup.vpn_server.config",\r
+       "backup.etherlogger.config",\r
+       "packet_log",\r
+       "etherlogger_log",\r
+       "secure_nat_log",\r
+       "security_log",\r
+       "server_log",\r
+       "bridge_log",\r
+};\r
+\r
+// syslog の送信\r
+void SendSysLog(SLOG *g, wchar_t *str)\r
+{\r
+       UCHAR *buf;\r
+       UINT buf_size;\r
+       // 引数チェック\r
+       if (g == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       buf_size = CalcUniToUtf8(str);\r
+       buf = ZeroMalloc(buf_size);\r
+       UniToUtf8(buf, buf_size, str);\r
+\r
+       if (buf_size >= 1024)\r
+       {\r
+               buf_size = 1023;\r
+       }\r
+\r
+       Lock(g->lock);\r
+       {\r
+               if (Tick64() >= g->NextPollIp)\r
+               {\r
+                       IP ip;\r
+\r
+                       if (GetIP(&ip, g->HostName))\r
+                       {\r
+                               g->NextPollIp = Tick64() + SYSLOG_POLL_IP_INTERVAL;\r
+                               Copy(&g->DestIp, &ip, sizeof(IP));\r
+                       }\r
+                       else\r
+                       {\r
+                               g->NextPollIp = Tick64() + SYSLOG_POLL_IP_INTERVAL_NG;\r
+                       }\r
+               }\r
+\r
+               if (g->DestPort != 0 && IsZeroIp(&g->DestIp) == false)\r
+               {\r
+                       SendTo(g->Udp, &g->DestIp, g->DestPort, buf, buf_size);\r
+               }\r
+       }\r
+       Unlock(g->lock);\r
+\r
+       Free(buf);\r
+}\r
+\r
+// syslog クライアントの解放\r
+void FreeSysLog(SLOG *g)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DeleteLock(g->lock);\r
+       ReleaseSock(g->Udp);\r
+       Free(g);\r
+}\r
+\r
+// syslog クライアントの設定\r
+void SetSysLog(SLOG *g, char *hostname, UINT port)\r
+{\r
+       IP ip;\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (port == 0)\r
+       {\r
+               port = SYSLOG_PORT;\r
+       }\r
+\r
+       if (hostname == NULL)\r
+       {\r
+               hostname = "";\r
+       }\r
+\r
+       Zero(&ip, sizeof(IP));\r
+       GetIP(&ip, hostname);\r
+\r
+       Lock(g->lock);\r
+       {\r
+               Copy(&g->DestIp, &ip, sizeof(IP));\r
+               g->DestPort = port;\r
+               StrCpy(g->HostName, sizeof(g->HostName), hostname);\r
+               g->NextPollIp = Tick64() + IsZeroIp(&ip) ? SYSLOG_POLL_IP_INTERVAL_NG : SYSLOG_POLL_IP_INTERVAL;\r
+       }\r
+       Unlock(g->lock);\r
+}\r
+\r
+// syslog クライアントの作成\r
+SLOG *NewSysLog(char *hostname, UINT port)\r
+{\r
+       // 引数チェック\r
+       SLOG *g = ZeroMalloc(sizeof(SLOG));\r
+\r
+       g->lock = NewLock();\r
+       g->Udp = NewUDP(0);\r
+\r
+       SetSysLog(g, hostname, port);\r
+\r
+       return g;\r
+}\r
+\r
+// ディスクに十分な空き容量があるかチェックする\r
+bool CheckEraserDiskFreeSpace(ERASER *e)\r
+{\r
+       UINT64 s;\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       // ディスクの空き容量を取得する\r
+       if (GetDiskFree(e->DirName, &s, NULL, NULL) == false)\r
+       {\r
+               // 取得失敗\r
+               return true;\r
+       }\r
+\r
+       if (e->MinFreeSpace > s)\r
+       {\r
+               // 空き容量が指定されたバイト数未満である\r
+               return false;\r
+       }\r
+\r
+       // 十分空いている\r
+       return true;\r
+}\r
+\r
+// 削除対象ファイルリストを解放する\r
+void FreeEraseFileList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               ERASE_FILE *f = LIST_DATA(o, i);\r
+               Free(f->FullPath);\r
+               Free(f);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// 削除対象ファイルリストを表示する\r
+void PrintEraseFileList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               ERASE_FILE *f = LIST_DATA(o, i);\r
+               Print("%I64u - %s\n", f->UpdateTime, f->FullPath);\r
+       }\r
+}\r
+\r
+// 指定されたディレクトリの削除対象ファイルリストを生成する\r
+void EnumEraseFile(LIST *o, char *dirname)\r
+{\r
+       DIRLIST *dir;\r
+       UINT i;\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (o == NULL || dirname == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 列挙\r
+       dir = EnumDir(dirname);\r
+\r
+       for (i = 0;i < dir->NumFiles;i++)\r
+       {\r
+               DIRENT *e = dir->File[i];\r
+               Format(tmp, sizeof(tmp), "%s/%s", dirname, e->FileName);\r
+               NormalizePath(tmp, sizeof(tmp), tmp);\r
+\r
+               if (e->Folder == false)\r
+               {\r
+                       // ファイル\r
+                       ERASE_FILE *f;\r
+\r
+                       if (EndWith(tmp, ".log") || EndWith(tmp, ".config"))\r
+                       {\r
+                               // ログファイルと .config ファイルのみを対象とする\r
+                               f = ZeroMalloc(sizeof(ERASE_FILE));\r
+                               f->FullPath = CopyStr(tmp);\r
+                               f->UpdateTime = e->UpdateDate;\r
+\r
+                               Add(o, f);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // フォルダ\r
+                       EnumEraseFile(o, tmp);\r
+               }\r
+       }\r
+\r
+       FreeDir(dir);\r
+}\r
+\r
+// 削除対象ファイルリストを生成する\r
+LIST *GenerateEraseFileList(ERASER *e)\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListFast(CompareEraseFile);\r
+\r
+       // 各ディレクトリを走査する\r
+       for (i = 0;i < sizeof(delete_targets) / sizeof(delete_targets[0]);i++)\r
+       {\r
+               char dirname[MAX_PATH];\r
+               Format(dirname, sizeof(dirname), "%s/%s", e->DirName, delete_targets[i]);\r
+\r
+               EnumEraseFile(o, dirname);\r
+       }\r
+\r
+       // ソートする\r
+       Sort(o);\r
+\r
+       return o;\r
+}\r
+\r
+// 不要ファイルの消去処理\r
+void EraserMain(ERASER *e)\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       bool ok = false;\r
+       char bs[64];\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // まず空き容量をチェック\r
+       if (CheckEraserDiskFreeSpace(e))\r
+       {\r
+               // 十分空いている\r
+               return;\r
+       }\r
+\r
+       ToStrByte(bs, sizeof(bs), e->MinFreeSpace);\r
+\r
+       // ファイル一覧の生成\r
+       o = GenerateEraseFileList(e);\r
+\r
+       // ファイルを古い順に 1 つずつ削除してみる\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               ERASE_FILE *f = LIST_DATA(o, i);\r
+\r
+               // ファイルを削除する\r
+               if (FileDelete(f->FullPath))\r
+               {\r
+                       ELog(e, "LE_DELETE", bs, f->FullPath);\r
+               }\r
+\r
+               // 削除したあと空き容量を確認してみる\r
+               if (CheckEraserDiskFreeSpace(e))\r
+               {\r
+                       // 空き容量が回復した\r
+                       ok = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       // ファイル一覧の解放\r
+       FreeEraseFileList(o);\r
+\r
+       if (e->LastFailed == false && ok == false)\r
+       {\r
+               // 空き容量が足りないがこれ以上ファイルを削除できない状態になってしまった\r
+               ELog(e, "LE_NOT_ENOUGH_FREE", bs);\r
+       }\r
+\r
+       e->LastFailed = ok ? false : true;\r
+}\r
+\r
+// 削除するファイル項目の比較\r
+int CompareEraseFile(void *p1, void *p2)\r
+{\r
+       ERASE_FILE *f1, *f2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       f1 = *(ERASE_FILE **)p1;\r
+       f2 = *(ERASE_FILE **)p2;\r
+       if (f1 == NULL || f2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (f1->UpdateTime > f2->UpdateTime)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (f1->UpdateTime == f2->UpdateTime)\r
+       {\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               return -1;\r
+       }\r
+}\r
+\r
+// 自動ファイル削除器スレッド\r
+void EraserThread(THREAD *t, void *p)\r
+{\r
+       ERASER *e = (ERASER *)p;\r
+       char bs[64];\r
+       // 引数チェック\r
+       if (t == NULL || e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 監視を開始\r
+       ToStrByte(bs, sizeof(bs), e->MinFreeSpace);\r
+       ELog(e, "LE_START", e->DirName, bs);\r
+\r
+       while (e->Halt == false)\r
+       {\r
+               // 一定間隔ごとにディスクの空き容量をチェックする\r
+               EraserMain(e);\r
+\r
+               Wait(e->HaltEvent, DISK_FREE_CHECK_INTERVAL);\r
+       }\r
+}\r
+\r
+// 新しい自動ファイル削除器の作成\r
+ERASER *NewEraser(LOG *log, UINT64 min_size)\r
+{\r
+       ERASER *e;\r
+       char dir[MAX_PATH];\r
+\r
+       if (min_size == 0)\r
+       {\r
+               min_size = DISK_FREE_SPACE_DEFAULT;\r
+       }\r
+\r
+       if (min_size < DISK_FREE_SPACE_MIN)\r
+       {\r
+               min_size = DISK_FREE_SPACE_MIN;\r
+       }\r
+\r
+       e = ZeroMalloc(sizeof(ERASER));\r
+\r
+       GetExeDir(dir, sizeof(dir));\r
+\r
+       e->Log = log;\r
+       e->MinFreeSpace = min_size;\r
+       e->DirName = CopyStr(dir);\r
+       e->HaltEvent = NewEvent();\r
+\r
+       e->Thread = NewThread(EraserThread, e);\r
+\r
+       return e;\r
+}\r
+\r
+// 自動ファイル削除器の解放\r
+void FreeEraser(ERASER *e)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       e->Halt = true;\r
+       Set(e->HaltEvent);\r
+       WaitThread(e->Thread, INFINITE);\r
+       ReleaseThread(e->Thread);\r
+       ReleaseEvent(e->HaltEvent);\r
+\r
+       Free(e->DirName);\r
+       Free(e);\r
+}\r
+\r
+// デバッグログをとる (可変長引数)\r
+void DebugLog(CEDAR *c, char *fmt, ...)\r
+{\r
+       char buf[MAX_SIZE * 2];\r
+       va_list args;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (c->DebugLog == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, fmt);\r
+       FormatArgs(buf, sizeof(buf), fmt, args);\r
+\r
+       InsertStringRecord(c->DebugLog, buf);\r
+       va_end(args);\r
+}\r
+\r
+// 自動ファイル削除器のログをとる\r
+void ELog(ERASER *e, char *name, ...)\r
+{\r
+       wchar_t buf[MAX_SIZE * 2];\r
+       va_list args;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, name);\r
+       UniFormatArgs(buf, sizeof(buf), _UU(name), args);\r
+\r
+       InsertUnicodeRecord(e->Log, buf);\r
+\r
+       if (IsDebug())\r
+       {\r
+               UniPrint(L"LOG: %s\n", buf);\r
+       }\r
+       va_end(args);\r
+}\r
+\r
+// サーバーのログをとる\r
+void ServerLog(CEDAR *c, wchar_t *fmt, ...)\r
+{\r
+       wchar_t buf[MAX_SIZE * 2];\r
+       va_list args;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, fmt);\r
+       UniFormatArgs(buf, sizeof(buf), fmt, args);\r
+\r
+       WriteServerLog(c, buf);\r
+       va_end(args);\r
+}\r
+void SLog(CEDAR *c, char *name, ...)\r
+{\r
+       wchar_t buf[MAX_SIZE * 2];\r
+       va_list args;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, name);\r
+       UniFormatArgs(buf, sizeof(buf), _UU(name), args);\r
+\r
+       WriteServerLog(c, buf);\r
+       va_end(args);\r
+}\r
+\r
+// クライアントログ\r
+void CLog(CLIENT *c, char *name, ...)\r
+{\r
+       wchar_t buf[MAX_SIZE * 2];\r
+       va_list args;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (c == NULL || c->NoSaveLog)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, name);\r
+       UniFormatArgs(buf, sizeof(buf), _UU(name), args);\r
+\r
+       WriteClientLog(c, buf);\r
+       va_end(args);\r
+}\r
+\r
+// HUB のセキュリティログをとる\r
+void HubLog(HUB *h, wchar_t *fmt, ...)\r
+{\r
+       wchar_t buf[MAX_SIZE * 2];\r
+       va_list args;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, fmt);\r
+       UniFormatArgs(buf, sizeof(buf), fmt, args);\r
+\r
+       WriteHubLog(h, buf);\r
+       va_end(args);\r
+}\r
+void ALog(ADMIN *a, HUB *h, char *name, ...)\r
+{\r
+       wchar_t buf[MAX_SIZE * 2];\r
+       wchar_t tmp[MAX_SIZE * 2];\r
+       va_list args;\r
+       RPC *r;\r
+       // 引数チェック\r
+       if (a == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       r = a->Rpc;\r
+\r
+       va_start(args, name);\r
+       UniFormatArgs(buf, sizeof(buf), _UU(name), args);\r
+\r
+       if (h == NULL)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("LA_TAG_1"), r->Name);\r
+       }\r
+       else\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("LA_TAG_2"), r->Name, h->Name);\r
+       }\r
+\r
+       UniStrCat(tmp, sizeof(tmp), buf);\r
+\r
+       if (h == NULL)\r
+       {\r
+               WriteServerLog(((ADMIN *)r->Param)->Server->Cedar, tmp);\r
+       }\r
+       else\r
+       {\r
+               WriteHubLog(h, tmp);\r
+       }\r
+       va_end(args);\r
+}\r
+void HLog(HUB *h, char *name, ...)\r
+{\r
+       wchar_t buf[MAX_SIZE * 2];\r
+       va_list args;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, name);\r
+       UniFormatArgs(buf, sizeof(buf), _UU(name), args);\r
+\r
+       WriteHubLog(h, buf);\r
+       va_end(args);\r
+}\r
+void NLog(VH *v, char *name, ...)\r
+{\r
+       wchar_t buf[MAX_SIZE * 2];\r
+       static wchar_t snat_prefix[] = L"SecureNAT: ";\r
+       va_list args;\r
+       // 引数チェック\r
+       if (name == NULL || v == NULL || v->nat == NULL || v->nat->SecureNAT == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, name);\r
+       Copy(buf, snat_prefix, sizeof(snat_prefix));\r
+       UniFormatArgs(&buf[11], sizeof(buf) - 12 * sizeof(wchar_t), _UU(name), args);\r
+\r
+       WriteHubLog(v->nat->SecureNAT->Hub, buf);\r
+       va_end(args);\r
+}\r
+\r
+// HUB のセキュリティログを保存する\r
+void WriteHubLog(HUB *h, wchar_t *str)\r
+{\r
+       wchar_t buf[MAX_SIZE * 2];\r
+       SERVER *s;\r
+       // 引数チェック\r
+       if (h == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = h->Cedar->Server;\r
+\r
+       UniFormat(buf, sizeof(buf), L"[HUB \"%S\"] %s", h->Name, str);\r
+\r
+       WriteServerLog(h->Cedar, buf);\r
+\r
+       if (h->LogSetting.SaveSecurityLog == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       InsertUnicodeRecord(h->SecurityLogger, str);\r
+}\r
+\r
+// クライアントログを保存する\r
+void WriteClientLog(CLIENT *c, wchar_t *str)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       InsertUnicodeRecord(c->Logger, str);\r
+}\r
+\r
+// サーバーのセキュリティログを保存する\r
+void WriteServerLog(CEDAR *c, wchar_t *str)\r
+{\r
+       SERVER *s;\r
+       // 引数チェック\r
+       if (c == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = c->Server;\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsDebug())\r
+       {\r
+               UniPrint(L"LOG: %s\n", str);\r
+       }\r
+\r
+       InsertUnicodeRecord(s->Logger, str);\r
+}\r
+\r
+// 複数行にわたるログを書き出す\r
+void WriteMultiLineLog(LOG *g, BUF *b)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL || b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       while (true)\r
+       {\r
+               char *s = CfgReadNextLine(b);\r
+               if (s == NULL)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               if (IsEmptyStr(s) == false)\r
+               {\r
+                       InsertStringRecord(g, s);\r
+               }\r
+\r
+               Free(s);\r
+       }\r
+}\r
+\r
+// セキュリティログをとる (可変長引数) ※ 廃止\r
+void SecLog(HUB *h, char *fmt, ...)\r
+{\r
+       char buf[MAX_SIZE * 2];\r
+       va_list args;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (h->LogSetting.SaveSecurityLog == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, fmt);\r
+       FormatArgs(buf, sizeof(buf), fmt, args);\r
+\r
+       WriteSecurityLog(h, buf);\r
+       va_end(args);\r
+}\r
+\r
+// セキュリティログをとる\r
+void WriteSecurityLog(HUB *h, char *str)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       InsertStringRecord(h->SecurityLogger, str);\r
+}\r
+\r
+// パケットログをとる\r
+void PacketLog(HUB *hub, SESSION *src_session, SESSION *dest_session, PKT *packet)\r
+{\r
+       UINT level;\r
+       PKT *p;\r
+       PACKET_LOG *pl;\r
+       SERVER *s;\r
+       bool no_log = false;\r
+       // 引数チェック\r
+       if (hub == NULL || src_session == NULL || packet == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = hub->Cedar->Server;\r
+\r
+       if (hub->LogSetting.SavePacketLog == false)\r
+       {\r
+               // パケットログをとらない\r
+               return;\r
+       }\r
+\r
+       if (Cmp(hub->HubMacAddr, packet->MacAddressSrc, 6) == 0 ||\r
+               Cmp(hub->HubMacAddr, packet->MacAddressDest, 6) == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ロギングレベルの決定\r
+       level = CalcPacketLoggingLevel(hub, packet);\r
+       if (level == PACKET_LOG_NONE)\r
+       {\r
+               // 保存しない\r
+               return;\r
+       }\r
+\r
+       if (hub->Option != NULL)\r
+       {\r
+               if (hub->Option->NoIPv4PacketLog && (packet->TypeL3 == L3_IPV4 || packet->TypeL3 == L3_ARPV4))\r
+               {\r
+                       // IPv4 パケットログを一切保存しない\r
+                       return;\r
+               }\r
+\r
+               if (hub->Option->NoIPv6PacketLog && packet->TypeL3 == L3_IPV6)\r
+               {\r
+                       // IPv6 パケットログを一切保存しない\r
+                       return;\r
+               }\r
+       }\r
+\r
+       if (s->Cedar->Bridge == false)\r
+       {\r
+               if (s->LicenseSystem != NULL && s->LicenseSystem->Status != NULL)\r
+               {\r
+                       if (s->LicenseSystem->Status->AllowEnterpriseFunction == false &&\r
+                               s->LicenseSystem->Status->Edition != 0)\r
+                       {\r
+                               // VPN Server の製品エディションが低い場合はパケットログのうち一部\r
+                               // を保存しない\r
+                               no_log = true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // パケットのクローン\r
+       p = ClonePacket(packet, level == PACKET_LOG_ALL ? true : false);\r
+\r
+       // 情報の取得\r
+       pl = ZeroMalloc(sizeof(PACKET_LOG));\r
+       pl->Cedar = hub->Cedar;\r
+       pl->Packet = p;\r
+       pl->NoLog = no_log;\r
+       if (src_session != NULL)\r
+       {\r
+               pl->SrcSessionName = CopyStr(src_session->Name);\r
+       }\r
+       else\r
+       {\r
+               pl->SrcSessionName = CopyStr("");\r
+       }\r
+       if (dest_session != NULL)\r
+       {\r
+               pl->DestSessionName = CopyStr(dest_session->Name);\r
+       }\r
+       else\r
+       {\r
+               pl->DestSessionName = CopyStr("");\r
+       }\r
+\r
+       if (src_session->LoggingRecordCount != NULL)\r
+       {\r
+               UINT n = 0;\r
+               while (src_session->LoggingRecordCount->c >= 30000)\r
+               {\r
+                       SleepThread(50);\r
+                       n++;\r
+                       if (n >= 5)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+\r
+       pl->SrcSession = src_session;\r
+       AddRef(src_session->ref);\r
+\r
+       Inc(src_session->LoggingRecordCount);\r
+\r
+       // パケットログの挿入\r
+       InsertRecord(hub->PacketLogger, pl, PacketLogParseProc);\r
+}\r
+\r
+// 指定されたパケットのロギングレベルを計算する\r
+UINT CalcPacketLoggingLevelEx(HUB_LOG *g, PKT *packet)\r
+{\r
+       UINT ret = 0;\r
+       // 引数チェック\r
+       if (g == NULL || packet == NULL)\r
+       {\r
+               return PACKET_LOG_NONE;\r
+       }\r
+\r
+       // Ethernet ログ\r
+       ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_ETHERNET]);\r
+\r
+       switch (packet->TypeL3)\r
+       {\r
+       case L3_ARPV4:\r
+               // ARP\r
+               ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_ARP]);\r
+               break;\r
+\r
+       case L3_IPV4:\r
+               // IPv4\r
+               ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_IP]);\r
+\r
+               switch (packet->TypeL4)\r
+               {\r
+               case L4_ICMPV4:\r
+                       // ICMPv4\r
+                       ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_ICMP]);\r
+                       break;\r
+\r
+               case L4_TCP:\r
+                       // TCPv4\r
+                       ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP]);\r
+\r
+                       if (packet->L4.TCPHeader->Flag & TCP_SYN ||\r
+                               packet->L4.TCPHeader->Flag & TCP_RST ||\r
+                               packet->L4.TCPHeader->Flag & TCP_FIN)\r
+                       {\r
+                               // TCP SYN LOG\r
+                               ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP_CONN]);\r
+                       }\r
+\r
+                       break;\r
+\r
+               case L4_UDP:\r
+                       // UDPv4\r
+                       ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_UDP]);\r
+\r
+                       switch (packet->TypeL7)\r
+                       {\r
+                       case L7_DHCPV4:\r
+                               // DHCPv4\r
+                               ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_DHCP]);\r
+                               break;\r
+                       }\r
+\r
+                       break;\r
+               }\r
+\r
+               break;\r
+\r
+       case L3_IPV6:\r
+               // IPv6\r
+               ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_IP]);\r
+\r
+               switch (packet->TypeL4)\r
+               {\r
+               case L4_ICMPV6:\r
+                       // ICMPv6\r
+                       ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_ICMP]);\r
+                       break;\r
+\r
+               case L4_TCP:\r
+                       // TCPv6\r
+                       ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP]);\r
+\r
+                       if (packet->L4.TCPHeader->Flag & TCP_SYN ||\r
+                               packet->L4.TCPHeader->Flag & TCP_RST ||\r
+                               packet->L4.TCPHeader->Flag & TCP_FIN)\r
+                       {\r
+                               // TCP SYN LOG\r
+                               ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP_CONN]);\r
+                       }\r
+\r
+                       break;\r
+\r
+               case L4_UDP:\r
+                       // UDPv6\r
+                       ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_UDP]);\r
+\r
+                       break;\r
+               }\r
+\r
+               break;\r
+       }\r
+\r
+       return ret;\r
+}\r
+UINT CalcPacketLoggingLevel(HUB *hub, PKT *packet)\r
+{\r
+       // 引数チェック\r
+       if (hub == NULL || packet == NULL)\r
+       {\r
+               return PACKET_LOG_NONE;\r
+       }\r
+\r
+       return CalcPacketLoggingLevelEx(&hub->LogSetting, packet);\r
+}\r
+\r
+// パケットログエントリを文字列に変換するプロシージャ\r
+char *PacketLogParseProc(RECORD *rec)\r
+{\r
+       PACKET_LOG *pl;\r
+       PKT *p;\r
+       char *s;\r
+       TOKEN_LIST *t;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (rec == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       pl = (PACKET_LOG *)rec->Data;\r
+       p = pl->Packet;\r
+\r
+       // 各部を生成する\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = 16;\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+\r
+       // 送信元セッション\r
+       t->Token[0] = pl->SrcSessionName;\r
+\r
+       // 宛先セッション\r
+       t->Token[1] = pl->DestSessionName;\r
+\r
+       // 送信元 MAC アドレス\r
+       BinToStr(tmp, sizeof(tmp), p->MacAddressSrc, 6);\r
+\r
+       t->Token[2] = CopyStr(tmp);\r
+       // 宛先 MAC アドレス\r
+       BinToStr(tmp, sizeof(tmp), p->MacAddressDest, 6);\r
+\r
+       t->Token[3] = CopyStr(tmp);\r
+\r
+       // MAC プロトコル\r
+       snprintf(tmp, sizeof(tmp), "0x%04X", Endian16(p->MacHeader->Protocol));\r
+       t->Token[4] = CopyStr(tmp);\r
+\r
+       // パケットサイズ\r
+       ToStr(tmp, p->PacketSize);\r
+       t->Token[5] = CopyStr(tmp);\r
+\r
+       // パケットログ本体は実装されていない\r
+       t->Token[6] = CopyUniToUtf(_UU("LH_PACKET_LOG_NO_LOG"));\r
+\r
+       s = GenCsvLine(t);\r
+       FreeToken(t);\r
+\r
+       // パケットデータを破棄する\r
+       if (pl->PurePacket == false)\r
+       {\r
+               FreeClonePacket(p);\r
+       }\r
+       else\r
+       {\r
+               Free(p->PacketData);\r
+               FreePacket(p);\r
+       }\r
+\r
+       // セッションを解放する\r
+       if (pl->SrcSession != NULL)\r
+       {\r
+               Dec(pl->SrcSession->LoggingRecordCount);\r
+               ReleaseSession(pl->SrcSession);\r
+       }\r
+\r
+       // PACKET_LOG を破棄する\r
+       Free(pl);\r
+\r
+       return s;\r
+}\r
+\r
+// TCP フラグを文字列に変換\r
+char *TcpFlagStr(UCHAR flag)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       StrCpy(tmp, sizeof(tmp), "");\r
+\r
+       if (flag & TCP_FIN)\r
+       {\r
+               StrCat(tmp, sizeof(tmp), "FIN+");\r
+       }\r
+\r
+       if (flag & TCP_SYN)\r
+       {\r
+               StrCat(tmp, sizeof(tmp), "SYN+");\r
+       }\r
+\r
+       if (flag & TCP_RST)\r
+       {\r
+               StrCat(tmp, sizeof(tmp), "RST+");\r
+       }\r
+\r
+       if (flag & TCP_PSH)\r
+       {\r
+               StrCat(tmp, sizeof(tmp), "PSH+");\r
+       }\r
+\r
+       if (flag & TCP_ACK)\r
+       {\r
+               StrCat(tmp, sizeof(tmp), "ACK+");\r
+       }\r
+\r
+       if (flag & TCP_URG)\r
+       {\r
+               StrCat(tmp, sizeof(tmp), "URG+");\r
+       }\r
+\r
+       if (StrLen(tmp) >= 1)\r
+       {\r
+               if (tmp[StrLen(tmp) - 1] == '+')\r
+               {\r
+                       tmp[StrLen(tmp) - 1] = 0;\r
+               }\r
+       }\r
+\r
+       return CopyStr(tmp);\r
+}\r
+\r
+// ポート文字列の生成\r
+char *PortStr(CEDAR *cedar, UINT port, bool udp)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       char *name;\r
+       // 引数チェック\r
+       if (cedar == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       name = GetSvcName(cedar, udp, port);\r
+\r
+       if (name == NULL)\r
+       {\r
+               snprintf(tmp, sizeof(tmp), "%u", port);\r
+       }\r
+       else\r
+       {\r
+               snprintf(tmp, sizeof(tmp), "%s(%u)", name, port);\r
+       }\r
+\r
+       return CopyStr(tmp);\r
+}\r
+\r
+// カンマで区切られた文字列を生成する\r
+char *GenCsvLine(TOKEN_LIST *t)\r
+{\r
+       UINT i;\r
+       BUF *b;\r
+       char *ret;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               if (t->Token[i] != NULL)\r
+               {\r
+                       ReplaceForCsv(t->Token[i]);\r
+                       if (StrLen(t->Token[i]) == 0)\r
+                       {\r
+                               WriteBuf(b, "-", 1);\r
+                       }\r
+                       else\r
+                       {\r
+                               WriteBuf(b, t->Token[i], StrLen(t->Token[i]));\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       WriteBuf(b, "-", 1);\r
+               }\r
+               if (i != (t->NumTokens - 1))\r
+               {\r
+                       WriteBuf(b, ",", 1);\r
+               }\r
+       }\r
+       WriteBuf(b, "\0", 1);\r
+\r
+       ret = (char *)b->Buf;\r
+\r
+       Free(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// CSV の中に入る文字列を正しく置換する\r
+void ReplaceForCsv(char *str)\r
+{\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 空白があればトリミングする\r
+       Trim(str);\r
+       len = StrLen(str);\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               // カンマをアンダーバーに変換する\r
+               if (str[i] == ',')\r
+               {\r
+                       str[i] = '_';\r
+               }\r
+       }\r
+}\r
+\r
+// ログのディレクトリ名を設定\r
+void SetLogDirName(LOG *g, char *dir)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL || dir == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockLog(g);\r
+       {\r
+               if (g->DirName != NULL)\r
+               {\r
+                       Free(g->DirName);\r
+               }\r
+               g->DirName = CopyStr(dir);\r
+       }\r
+       UnlockLog(g);\r
+}\r
+\r
+// ログの名前を設定\r
+void SetLogPrefix(LOG *g, char *prefix)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL || prefix == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockLog(g);\r
+       {\r
+               if (g->DirName != NULL)\r
+               {\r
+                       Free(g->Prefix);\r
+               }\r
+               g->DirName = CopyStr(prefix);\r
+       }\r
+       UnlockLog(g);\r
+}\r
+\r
+// ログのスイッチ種類を設定\r
+void SetLogSwitchType(LOG *g, UINT switch_type)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockLog(g);\r
+       {\r
+               g->SwitchType = switch_type;\r
+       }\r
+       UnlockLog(g);\r
+}\r
+\r
+// 文字列レコードの解析\r
+char *StringRecordParseProc(RECORD *rec)\r
+{\r
+       // 引数チェック\r
+       if (rec == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return (char *)rec->Data;\r
+}\r
+\r
+// ログに Unicode 文字列レコードを追加\r
+void InsertUnicodeRecord(LOG *g, wchar_t *unistr)\r
+{\r
+       char *str;\r
+       UINT size;\r
+       // 引数チェック\r
+       if (g == NULL || unistr == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       size = CalcUniToUtf8(unistr) + 32;\r
+       str = ZeroMalloc(size);\r
+\r
+       UniToUtf8((BYTE *)str, size, unistr);\r
+       InsertStringRecord(g, str);\r
+       Free(str);\r
+}\r
+\r
+// ログに文字列レコードを追加\r
+void InsertStringRecord(LOG *g, char *str)\r
+{\r
+       char *str_copy;\r
+       // 引数チェック\r
+       if (g == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       str_copy = CopyStr(str);\r
+\r
+       InsertRecord(g, str_copy, StringRecordParseProc);\r
+}\r
+\r
+// ログにレコードを追加\r
+void InsertRecord(LOG *g, void *data, RECORD_PARSE_PROC *proc)\r
+{\r
+       RECORD *rec;\r
+       // 引数チェック\r
+       if (g == NULL || data == NULL || proc == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       rec = ZeroMalloc(sizeof(RECORD));\r
+       rec->Tick = Tick64();\r
+       rec->ParseProc = proc;\r
+       rec->Data = data;\r
+\r
+       LockQueue(g->RecordQueue);\r
+       {\r
+               InsertQueue(g->RecordQueue, rec);\r
+       }\r
+       UnlockQueue(g->RecordQueue);\r
+\r
+       Set(g->Event);\r
+}\r
+\r
+// ログのロック\r
+void LockLog(LOG *g)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(g->lock);\r
+}\r
+\r
+// ログのロック解除\r
+void UnlockLog(LOG *g)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Unlock(g->lock);\r
+}\r
+\r
+// ログファイル名の文字列部分を時刻とスイッチ規則から生成する\r
+void MakeLogFileNameStringFromTick(LOG *g, char *str, UINT size, UINT64 tick, UINT switch_type)\r
+{\r
+       UINT64 time;\r
+       SYSTEMTIME st;\r
+\r
+       // 引数チェック\r
+       if (str == NULL || g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (g->CacheFlag)\r
+       {\r
+               if (g->LastTick == tick &&\r
+                       g->LastSwitchType == switch_type)\r
+               {\r
+                       StrCpy(str, size, g->LastStr);\r
+                       return;\r
+               }\r
+       }\r
+\r
+       time = TickToTime(tick);\r
+       UINT64ToSystem(&st, SystemToLocal64(time));\r
+\r
+       switch (switch_type)\r
+       {\r
+       case LOG_SWITCH_SECOND: // 1 秒単位\r
+               snprintf(str, size, "_%04u%02u%02u_%02u%02u%02u",\r
+                       st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);\r
+               break;\r
+\r
+       case LOG_SWITCH_MINUTE: // 1 分単位\r
+               snprintf(str, size, "_%04u%02u%02u_%02u%02u",\r
+                       st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute);\r
+               break;\r
+\r
+       case LOG_SWITCH_HOUR:   // 1 時間単位\r
+               snprintf(str, size, "_%04u%02u%02u_%02u", st.wYear, st.wMonth, st.wDay, st.wHour);\r
+               break;\r
+\r
+       case LOG_SWITCH_DAY:    // 1 日単位\r
+               snprintf(str, size, "_%04u%02u%02u", st.wYear, st.wMonth, st.wDay);\r
+               break;\r
+\r
+       case LOG_SWITCH_MONTH:  // 1 ヶ月単位\r
+               snprintf(str, size, "_%04u%02u", st.wYear, st.wMonth);\r
+               break;\r
+\r
+       default:                                // 切り替え無し\r
+               snprintf(str, size, "");\r
+               break;\r
+       }\r
+\r
+       g->CacheFlag = true;\r
+       g->LastTick = tick;\r
+       g->LastSwitchType = switch_type;\r
+       StrCpy(g->LastStr, sizeof(g->LastStr), str);\r
+}\r
+\r
+// ログファイル名を作成する\r
+bool MakeLogFileName(LOG *g, char *name, UINT size, char *dir, char *prefix, UINT64 tick, UINT switch_type, UINT num, char *old_datestr)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       char tmp2[64];\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (g == NULL || name == NULL || prefix == NULL || old_datestr == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       MakeLogFileNameStringFromTick(g, tmp, sizeof(tmp), tick, switch_type);\r
+\r
+       if (num == 0)\r
+       {\r
+               tmp2[0] = 0;\r
+       }\r
+       else\r
+       {\r
+               snprintf(tmp2, sizeof(tmp2), "~%02u", num);\r
+       }\r
+\r
+       if (strcmp(old_datestr, tmp) != 0)\r
+       {\r
+               ret = true;\r
+               strcpy(old_datestr, tmp);\r
+       }\r
+\r
+       snprintf(name, size, "%s%s%s%s%s.log", dir,\r
+               StrLen(dir) == 0 ? "" : "/",\r
+               prefix, tmp, tmp2\r
+               );\r
+\r
+       return ret;\r
+}\r
+\r
+// ログがフラッシュされるまで待機\r
+void WaitLogFlush(LOG *g)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               UINT num;\r
+               LockQueue(g->RecordQueue);\r
+               {\r
+                       num = g->RecordQueue->num_item;\r
+               }\r
+               UnlockQueue(g->RecordQueue);\r
+\r
+               if (num == 0)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               Wait(g->FlushEvent, 100);\r
+       }\r
+}\r
+\r
+// ログ記録用スレッド\r
+void LogThread(THREAD *thread, void *param)\r
+{\r
+       LOG *g;\r
+       IO *io;\r
+       BUF *b;\r
+       bool flag = false;\r
+       char current_file_name[MAX_SIZE];\r
+       char current_logfile_datename[MAX_SIZE];\r
+       bool last_priority_flag = false;\r
+       bool log_date_changed = false;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(current_file_name, sizeof(current_file_name));\r
+       Zero(current_logfile_datename, sizeof(current_logfile_datename));\r
+\r
+       g = (LOG *)param;\r
+\r
+       io = NULL;\r
+       b = NewBuf();\r
+\r
+#ifdef OS_WIN32\r
+\r
+       // 優先順位を最低にする\r
+       MsSetThreadPriorityIdle();\r
+\r
+#endif // OS_WIN32\r
+\r
+       NoticeThreadInit(thread);\r
+\r
+       while (true)\r
+       {\r
+               RECORD *rec;\r
+               UINT64 s = Tick64();\r
+\r
+               while (true)\r
+               {\r
+                       char file_name[MAX_SIZE];\r
+                       UINT num;\r
+\r
+                       // キューの先頭からレコードを取得する\r
+                       LockQueue(g->RecordQueue);\r
+                       {\r
+                               rec = GetNext(g->RecordQueue);\r
+                               num = g->RecordQueue->num_item;\r
+                       }\r
+                       UnlockQueue(g->RecordQueue);\r
+\r
+#ifdef OS_WIN32\r
+                       if (num >= LOG_ENGINE_SAVE_START_CACHE_COUNT)\r
+                       {\r
+                               // 優先順位を上げる\r
+                               if (last_priority_flag == false)\r
+                               {\r
+                                       Debug("LOG_THREAD: MsSetThreadPriorityRealtime\n");\r
+                                       MsSetThreadPriorityRealtime();\r
+                                       last_priority_flag = true;\r
+                               }\r
+                       }\r
+\r
+                       if (num < (LOG_ENGINE_SAVE_START_CACHE_COUNT / 2))\r
+                       {\r
+                               // 優先順位を戻す\r
+                               if (last_priority_flag)\r
+                               {\r
+                                       Debug("LOG_THREAD: MsSetThreadPriorityIdle\n");\r
+                                       MsSetThreadPriorityIdle();\r
+                                       last_priority_flag = false;\r
+                               }\r
+                       }\r
+#endif // OS_WIN32\r
+\r
+                       if (b->Size > g->MaxLogFileSize)\r
+                       {\r
+                               // バッファのサイズが最大ログファイルサイズを超える場合は消去する\r
+                               ClearBuf(b);\r
+                       }\r
+\r
+                       if (b->Size >= LOG_ENGINE_BUFFER_CACHE_SIZE_MAX)\r
+                       {\r
+                               // バッファの中身をファイルに書き出す\r
+                               if (io != NULL)\r
+                               {\r
+                                       if ((g->CurrentFilePointer + (UINT64)b->Size) > g->MaxLogFileSize)\r
+                                       {\r
+                                               if (g->log_number_incremented == false)\r
+                                               {\r
+                                                       g->CurrentLogNumber++;\r
+                                                       g->log_number_incremented = true;\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (FileWrite(io, b->Buf, b->Size) == false)\r
+                                               {\r
+                                                       FileCloseEx(io, true);\r
+                                                       // ファイルへの書き込みに失敗した場合は仕方が無い\r
+                                                       // のでバッファを消して諦める\r
+                                                       ClearBuf(b);\r
+                                                       io = NULL;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       g->CurrentFilePointer += (UINT64)b->Size;\r
+                                                       ClearBuf(b);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       if (rec == NULL)\r
+                       {\r
+                               if (b->Size != 0)\r
+                               {\r
+                                       // バッファの中身をファイルに書き出す\r
+                                       if (io != NULL)\r
+                                       {\r
+                                               if ((g->CurrentFilePointer + (UINT64)b->Size) > g->MaxLogFileSize)\r
+                                               {\r
+                                                       if (g->log_number_incremented == false)\r
+                                                       {\r
+                                                               g->CurrentLogNumber++;\r
+                                                               g->log_number_incremented = true;\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       if (FileWrite(io, b->Buf, b->Size) == false)\r
+                                                       {\r
+                                                               FileCloseEx(io, true);\r
+                                                               // ファイルへの書き込みに失敗した場合は仕方が無い\r
+                                                               // のでバッファを消して諦める\r
+                                                               ClearBuf(b);\r
+                                                               io = NULL;\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               g->CurrentFilePointer += (UINT64)b->Size;\r
+                                                               ClearBuf(b);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               Set(g->FlushEvent);\r
+                               break;\r
+                       }\r
+\r
+                       // ログファイル名を生成する\r
+                       LockLog(g);\r
+                       {\r
+                               log_date_changed = MakeLogFileName(g, file_name, sizeof(file_name),\r
+                                       g->DirName, g->Prefix, rec->Tick, g->SwitchType, g->CurrentLogNumber, current_logfile_datename);\r
+\r
+                               if (log_date_changed)\r
+                               {\r
+                                       UINT i;\r
+\r
+                                       g->CurrentLogNumber = 0;\r
+                                       MakeLogFileName(g, file_name, sizeof(file_name),\r
+                                               g->DirName, g->Prefix, rec->Tick, g->SwitchType, 0, current_logfile_datename);\r
+                                       for (i = 0;;i++)\r
+                                       {\r
+                                               char tmp[MAX_SIZE];\r
+                                               MakeLogFileName(g, tmp, sizeof(tmp),\r
+                                                       g->DirName, g->Prefix, rec->Tick, g->SwitchType, i, current_logfile_datename);\r
+\r
+                                               if (IsFileExists(tmp) == false)\r
+                                               {\r
+                                                       break;\r
+                                               }\r
+                                               StrCpy(file_name, sizeof(file_name), tmp);\r
+                                               g->CurrentLogNumber = i;\r
+                                       }\r
+                               }\r
+                       }\r
+                       UnlockLog(g);\r
+\r
+                       if (io != NULL)\r
+                       {\r
+                               if (StrCmp(current_file_name, file_name) != 0)\r
+                               {\r
+                                       // 現在ログファイルを開いていて今回別のログファイルへの書き込みが必要になった\r
+                                       // 場合はログファイルにバッファの内容を書き込んでからログファイルを閉じる\r
+                                       // バッファの中身をファイルに書き出す\r
+                                       if (io != NULL)\r
+                                       {\r
+                                               if (log_date_changed)\r
+                                               {\r
+                                                       if ((g->CurrentFilePointer + (UINT64)b->Size) <= g->MaxLogFileSize)\r
+                                                       {\r
+                                                               if (FileWrite(io, b->Buf, b->Size) == false)\r
+                                                               {\r
+                                                                       FileCloseEx(io, true);\r
+                                                                       ClearBuf(b);\r
+                                                                       io = NULL;\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       g->CurrentFilePointer += (UINT64)b->Size;\r
+                                                                       ClearBuf(b);\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                               // ファイルを閉じる\r
+                                               FileCloseEx(io, true);\r
+                                       }\r
+\r
+                                       g->log_number_incremented = false;\r
+\r
+                                       // 新しいログファイルを開くか作成する\r
+                                       StrCpy(current_file_name, sizeof(current_file_name), file_name);\r
+                                       io = FileOpen(file_name, true);\r
+                                       if (io == NULL)\r
+                                       {\r
+                                               // ログファイルを作成する\r
+                                               LockLog(g);\r
+                                               {\r
+                                                       MakeDir(g->DirName);\r
+\r
+#ifdef OS_WIN32\r
+                                                       Win32SetFolderCompress(g->DirName, true);\r
+#endif // OS_WIN32\r
+                                               }\r
+                                               UnlockLog(g);\r
+                                               io = FileCreate(file_name);\r
+                                               g->CurrentFilePointer = 0;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // ログファイルの末尾に移動する\r
+                                               g->CurrentFilePointer = FileSize64(io);\r
+                                               FileSeek(io, SEEK_END, 0);\r
+                                       }\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // 新しいログファイルを開くか作成する\r
+                               StrCpy(current_file_name, sizeof(current_file_name), file_name);\r
+                               io = FileOpen(file_name, true);\r
+                               if (io == NULL)\r
+                               {\r
+                                       // ログファイルを作成する\r
+                                       LockLog(g);\r
+                                       {\r
+                                               MakeDir(g->DirName);\r
+#ifdef OS_WIN32\r
+                                               Win32SetFolderCompress(g->DirName, true);\r
+#endif // OS_WIN32\r
+                                       }\r
+                                       UnlockLog(g);\r
+                                       io = FileCreate(file_name);\r
+                                       g->CurrentFilePointer = 0;\r
+                                       if (io == NULL)\r
+                                       {\r
+                                               Debug("Logging.c: SleepThread(30);\n");\r
+                                               SleepThread(30);\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       // ログファイルの末尾に移動する\r
+                                       g->CurrentFilePointer = FileSize64(io);\r
+                                       FileSeek(io, SEEK_END, 0);\r
+                               }\r
+\r
+                               g->log_number_incremented = false;\r
+                       }\r
+\r
+                       // ログの内容をバッファに書き出す\r
+                       WriteRecordToBuffer(b, rec);\r
+\r
+                       // レコードのメモリを解放\r
+                       Free(rec);\r
+\r
+                       if (io == NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               if (g->Halt)\r
+               {\r
+                       // 停止フラグが立った場合\r
+                       // すべてのレコードを保存し終えるとブレイクする\r
+                       UINT num;\r
+\r
+                       if (flag == false)\r
+                       {\r
+#ifdef OS_WIN32\r
+                               MsSetThreadPriorityRealtime();\r
+#endif // OS_WIN32\r
+                               flag = true;\r
+                       }\r
+\r
+                       LockQueue(g->RecordQueue);\r
+                       {\r
+                               num = g->RecordQueue->num_item;\r
+                       }\r
+                       UnlockQueue(g->RecordQueue);\r
+\r
+                       if (num == 0 || io == NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       Wait(g->Event, 9821);\r
+               }\r
+       }\r
+\r
+       if (io != NULL)\r
+       {\r
+               FileCloseEx(io, true);\r
+       }\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// ログの内容をバッファに書き出す\r
+void WriteRecordToBuffer(BUF *b, RECORD *r)\r
+{\r
+       UINT64 time;\r
+       char time_str[MAX_SIZE];\r
+       char date_str[MAX_SIZE];\r
+       char *s;\r
+       // 引数チェック\r
+       if (b == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 時刻の取得\r
+       time = SystemToLocal64(TickToTime(r->Tick));\r
+\r
+       // 時刻を文字列に変換\r
+       GetDateStr64(date_str, sizeof(date_str), time);\r
+       GetTimeStrMilli64(time_str, sizeof(time_str), time);\r
+\r
+       if (r->ParseProc != PacketLogParseProc)\r
+       {\r
+               // パケットログ以外\r
+               WriteBuf(b, date_str, StrLen(date_str));\r
+               WriteBuf(b, " ", 1);\r
+               WriteBuf(b, time_str, StrLen(time_str));\r
+               WriteBuf(b, " ", 1);\r
+       }\r
+       else\r
+       {\r
+               // パケットログ\r
+               WriteBuf(b, date_str, StrLen(date_str));\r
+               WriteBuf(b, ",", 1);\r
+               WriteBuf(b, time_str, StrLen(time_str));\r
+               WriteBuf(b, ",", 1);\r
+       }\r
+\r
+       // 本文を出力\r
+       s = r->ParseProc(r);\r
+       WriteBuf(b, s, StrLen(s));\r
+       Free(s);\r
+\r
+       WriteBuf(b, "\r\n", 2);\r
+}\r
+\r
+// ログ記録の終了\r
+void FreeLog(LOG *g)\r
+{\r
+       RECORD *rec;\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 停止フラグ\r
+       g->Halt = true;\r
+       Set(g->Event);\r
+\r
+       WaitThread(g->Thread, INFINITE);\r
+       ReleaseThread(g->Thread);\r
+\r
+       DeleteLock(g->lock);\r
+       Free(g->DirName);\r
+       Free(g->Prefix);\r
+\r
+       // 未処理のレコードが残っている場合は解放する\r
+       // (本来はここでは残っていないはず)\r
+       while (rec = GetNext(g->RecordQueue))\r
+       {\r
+               char *s = rec->ParseProc(rec);\r
+               Free(s);\r
+               Free(rec);\r
+       }\r
+       ReleaseQueue(g->RecordQueue);\r
+\r
+       ReleaseEvent(g->Event);\r
+       ReleaseEvent(g->FlushEvent);\r
+\r
+       Free(g);\r
+}\r
+\r
+// 新しいログ記録の開始\r
+LOG *NewLog(char *dir, char *prefix, UINT switch_type)\r
+{\r
+       LOG *g;\r
+\r
+       g = ZeroMalloc(sizeof(LOG));\r
+       g->lock = NewLock();\r
+       g->DirName = CopyStr(dir == NULL ? "" : dir);\r
+       g->Prefix = CopyStr(prefix == NULL ? "log" : prefix);\r
+       g->SwitchType = switch_type;\r
+       g->RecordQueue = NewQueue();\r
+       g->Event = NewEvent();\r
+       g->MaxLogFileSize = MAX_LOG_SIZE;\r
+       g->FlushEvent = NewEvent();\r
+\r
+       g->Thread = NewThread(LogThread, g);\r
+\r
+       WaitThreadInit(g->Thread);\r
+\r
+       return g;\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Logging.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Logging.h
new file mode 100644 (file)
index 0000000..7bd9476
--- /dev/null
@@ -0,0 +1,229 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Logging.h\r
+// Logging.c のヘッダ\r
+\r
+#ifndef        LOGGING_H\r
+#define        LOGGING_H\r
+\r
+\r
+#define        MAX_LOG_SIZE                                            1073741823ULL\r
+\r
+typedef char *(RECORD_PARSE_PROC)(RECORD *rec);\r
+\r
+// パケットログ構造体\r
+struct PACKET_LOG\r
+{\r
+       CEDAR *Cedar;\r
+       struct PKT *Packet;\r
+       char *SrcSessionName;\r
+       char *DestSessionName;\r
+       bool PurePacket;                                                // クローンしていないパケット\r
+       bool PurePacketNoPayload;                               // クローンしていないパケット (ペイロード無し)\r
+       SESSION *SrcSession;\r
+       bool NoLog;                                                             // ログを書かない\r
+};\r
+\r
+// HUB のログ保存オプション\r
+struct HUB_LOG\r
+{\r
+       bool SaveSecurityLog;                                   // セキュリティログの保存\r
+       UINT SecurityLogSwitchType;                             // セキュリティログの切り替え種類\r
+       bool SavePacketLog;                                             // パケットログの保存\r
+       UINT PacketLogSwitchType;                               // パケットログの切り替え種類\r
+       UINT PacketLogConfig[NUM_PACKET_LOG];   // パケットログ設定\r
+};\r
+\r
+// レコード\r
+struct RECORD\r
+{\r
+       UINT64 Tick;                                                    // 時刻\r
+       RECORD_PARSE_PROC *ParseProc;                   // パース用プロシージャ\r
+       void *Data;                                                             // データ\r
+};\r
+\r
+// LOG オブジェクト\r
+struct LOG\r
+{\r
+       LOCK *lock;                                                             // ロック\r
+       THREAD *Thread;                                                 // スレッド\r
+       char *DirName;                                                  // 保存先ディレクトリ名\r
+       char *Prefix;                                                   // ファイル名\r
+       UINT SwitchType;                                                // ログファイルの切り替え種類\r
+       QUEUE *RecordQueue;                                             // レコードキュー\r
+       volatile bool Halt;                                             // 停止フラグ\r
+       EVENT *Event;                                                   // ログ用イベント\r
+       EVENT *FlushEvent;                                              // フラッシュ完了イベント\r
+       bool CacheFlag;\r
+       UINT64 LastTick;\r
+       UINT LastSwitchType;\r
+       char LastStr[MAX_SIZE];\r
+       UINT64 CurrentFilePointer;                              // 現在のファイルポインタ\r
+       UINT64 MaxLogFileSize;                                  // 最大ログファイルサイズ\r
+       UINT CurrentLogNumber;                                  // 現在のログファイル番号\r
+       bool log_number_incremented;\r
+};\r
+\r
+// ERASER オブジェクト\r
+struct ERASER\r
+{\r
+       LOG *Log;                                                               // ロガー\r
+       UINT64 MinFreeSpace;                                    // ファイルの削除を開始するディスク空き容量\r
+       char *DirName;                                                  // ディレクトリ名\r
+       volatile bool Halt;                                             // 停止フラグ\r
+       THREAD *Thread;                                                 // スレッド\r
+       bool LastFailed;                                                // 最後にファイル削除に失敗したかどうか\r
+       EVENT *HaltEvent;                                               // 停止イベント\r
+};\r
+\r
+// 削除できるファイルの一覧\r
+typedef struct ERASE_FILE\r
+{\r
+       char *FullPath;                                                 // フルパス\r
+       UINT64 UpdateTime;                                              // 更新日時\r
+} ERASE_FILE;\r
+\r
+// SYSLOG オブジェクト\r
+struct SLOG\r
+{\r
+       LOCK *lock;                                                             // ロック\r
+       SOCK *Udp;                                                              // UDP ソケット\r
+       IP DestIp;                                                              // 宛先 IP アドレス\r
+       UINT DestPort;                                                  // 宛先ポート番号\r
+       char HostName[MAX_HOST_NAME_LEN + 1];   // ホスト名\r
+       UINT64 NextPollIp;                                              // 最後に IP アドレスを調べた日時\r
+};\r
+\r
+// 関数プロトタイプ\r
+LOG *NewLog(char *dir, char *prefix, UINT switch_type);\r
+void FreeLog(LOG *g);\r
+void LogThread(THREAD *thread, void *param);\r
+void WaitLogFlush(LOG *g);\r
+void LockLog(LOG *g);\r
+void UnlockLog(LOG *g);\r
+void InsertRecord(LOG *g, void *data, RECORD_PARSE_PROC *proc);\r
+void InsertStringRecord(LOG *g, char *str);\r
+void InsertUnicodeRecord(LOG *g, wchar_t *unistr);\r
+char *StringRecordParseProc(RECORD *rec);\r
+bool MakeLogFileName(LOG *g, char *name, UINT size, char *dir, char *prefix, UINT64 tick, UINT switch_type, UINT num, char *old_datestr);\r
+void MakeLogFileNameStringFromTick(LOG *g, char *str, UINT size, UINT64 tick, UINT switch_type);\r
+void WriteRecordToBuffer(BUF *b, RECORD *r);\r
+void SetLogDirName(LOG *g, char *dir);\r
+void SetLogPrefix(LOG *g, char *prefix);\r
+void SetLogSwitchType(LOG *g, UINT switch_type);\r
+void PacketLog(HUB *hub, SESSION *src_session, SESSION *dest_session, PKT *packet);\r
+char *PacketLogParseProc(RECORD *rec);\r
+UINT CalcPacketLoggingLevel(HUB *hub, PKT *packet);\r
+UINT CalcPacketLoggingLevelEx(HUB_LOG *g, PKT *packet);\r
+char *GenCsvLine(TOKEN_LIST *t);\r
+void ReplaceForCsv(char *str);\r
+char *PortStr(CEDAR *cedar, UINT port, bool udp);\r
+char *TcpFlagStr(UCHAR flag);\r
+void WriteSecurityLog(HUB *h, char *str);\r
+void SecLog(HUB *h, char *fmt, ...);\r
+void SiSetDefaultLogSetting(HUB_LOG *g);\r
+void DebugLog(CEDAR *c, char *fmt, ...);\r
+void HubLog(HUB *h, wchar_t *fmt, ...);\r
+void ServerLog(CEDAR *c, wchar_t *fmt, ...);\r
+void SLog(CEDAR *c, char *name, ...);\r
+void WriteHubLog(HUB *h, wchar_t *str);\r
+void HLog(HUB *h, char *name, ...);\r
+void NLog(VH *v, char *name, ...);\r
+void WriteServerLog(CEDAR *c, wchar_t *str);\r
+void ALog(ADMIN *a, HUB *h, char *name, ...);\r
+void CLog(CLIENT *c, char *name, ...);\r
+void WriteClientLog(CLIENT *c, wchar_t *str);\r
+ERASER *NewEraser(LOG *log, UINT64 min_size);\r
+void FreeEraser(ERASER *e);\r
+void ELog(ERASER *e, char *name, ...);\r
+void EraserThread(THREAD *t, void *p);\r
+void EraserMain(ERASER *e);\r
+bool CheckEraserDiskFreeSpace(ERASER *e);\r
+int CompareEraseFile(void *p1, void *p2);\r
+LIST *GenerateEraseFileList(ERASER *e);\r
+void FreeEraseFileList(LIST *o);\r
+void PrintEraseFileList(LIST *o);\r
+void EnumEraseFile(LIST *o, char *dirname);\r
+SLOG *NewSysLog(char *hostname, UINT port);\r
+void SetSysLog(SLOG *g, char *hostname, UINT port);\r
+void FreeSysLog(SLOG *g);\r
+void SendSysLog(SLOG *g, wchar_t *str);\r
+void WriteMultiLineLog(LOG *g, BUF *b);\r
+\r
+#endif // LOGGING_G\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/NM.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/NM.c
new file mode 100644 (file)
index 0000000..7d0ae37
--- /dev/null
@@ -0,0 +1,1483 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// NM.c\r
+// Win32 用 SoftEther UT-VPN User-mode Router Manager\r
+\r
+\r
+#ifdef WIN32\r
+\r
+#define        SM_C\r
+#define        CM_C\r
+#define        NM_C\r
+\r
+#define        _WIN32_WINNT            0x0502\r
+#define        WINVER                          0x0502\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+#include <wincrypt.h>\r
+#include <wininet.h>\r
+#include <shlobj.h>\r
+#include <commctrl.h>\r
+#include <Dbghelp.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+#include "CMInner.h"\r
+#include "SMInner.h"\r
+#include "NMInner.h"\r
+#include "../PenCore/resource.h"\r
+\r
+// グローバル変数\r
+static NM *nm = NULL;\r
+\r
+\r
+// パスワード変更ダイアログ\r
+UINT NmChangePasswordProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       RPC *r = (RPC *)param;\r
+       char tmp1[MAX_SIZE];\r
+       char tmp2[MAX_SIZE];\r
+       RPC_SET_PASSWORD t;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               FormatText(hWnd, 0, r->Sock->RemoteHostname);\r
+               FormatText(hWnd, S_TITLE, r->Sock->RemoteHostname);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               GetTxtA(hWnd, E_PASSWORD1, tmp1, sizeof(tmp1));\r
+               GetTxtA(hWnd, E_PASSWORD2, tmp2, sizeof(tmp2));\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_PASSWORD1:\r
+               case E_PASSWORD2:\r
+                       SetEnable(hWnd, IDOK, StrCmp(tmp1, tmp2) == 0);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       Zero(&t, sizeof(t));\r
+                       Hash(t.HashedPassword, tmp1, StrLen(tmp1), true);\r
+\r
+                       if (CALL(hWnd, NcSetPassword(r, &t)))\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("NM_PASSWORD_MSG"));\r
+                               EndDialog(hWnd, true);\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// パスワードの変更\r
+void NmChangePassword(HWND hWnd, RPC *r)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_NM_CHANGE_PASSWORD, NmChangePasswordProc, r);\r
+}\r
+\r
+// DHCP 列挙初期化\r
+void NmDhcpInit(HWND hWnd, SM_HUB *r)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_INTERNET);\r
+\r
+       LvInit(hWnd, L_TABLE);\r
+       LvInsertColumn(hWnd, L_TABLE, 0, _UU("DHCP_DHCP_ID"), 50);\r
+       LvInsertColumn(hWnd, L_TABLE, 1, _UU("DHCP_LEASED_TIME"), 200);\r
+       LvInsertColumn(hWnd, L_TABLE, 2, _UU("DHCP_EXPIRE_TIME"), 200);\r
+       LvInsertColumn(hWnd, L_TABLE, 3, _UU("DHCP_MAC_ADDRESS"), 130);\r
+       LvInsertColumn(hWnd, L_TABLE, 4, _UU("DHCP_IP_ADDRESS"), 100);\r
+       LvInsertColumn(hWnd, L_TABLE, 5, _UU("DHCP_HOSTNAME"), 150);\r
+\r
+       NmDhcpRefresh(hWnd, r);\r
+}\r
+\r
+// DHCP 列挙\r
+void NmDhcpRefresh(HWND hWnd, SM_HUB *r)\r
+{\r
+       LVB *b;\r
+       RPC_ENUM_DHCP t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), r->HubName);\r
+\r
+       if (CALL(hWnd, ScEnumDHCP(r->Rpc, &t)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+       \r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               RPC_ENUM_DHCP_ITEM *e = &t.Items[i];\r
+               wchar_t tmp0[MAX_SIZE];\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               wchar_t tmp3[MAX_SIZE];\r
+               wchar_t tmp4[MAX_SIZE];\r
+               wchar_t tmp5[MAX_SIZE];\r
+               char str[MAX_SIZE];\r
+\r
+               // ID\r
+               UniToStru(tmp0, e->Id);\r
+\r
+               // 時刻\r
+               GetDateTimeStrEx64(tmp1, sizeof(tmp1), SystemToLocal64(e->LeasedTime), NULL);\r
+               GetDateTimeStrEx64(tmp2, sizeof(tmp2), SystemToLocal64(e->ExpireTime), NULL);\r
+\r
+               MacToStr(str, sizeof(str), e->MacAddress);\r
+               StrToUni(tmp3, sizeof(tmp3), str);\r
+\r
+               IPToStr32(str, sizeof(str), e->IpAddress);\r
+               StrToUni(tmp4, sizeof(tmp4), str);\r
+\r
+               StrToUni(tmp5, sizeof(tmp5), e->Hostname);\r
+\r
+               LvInsertAdd(b, ICO_INTERNET, NULL, 6,\r
+                       tmp0, tmp1, tmp2, tmp3, tmp4, tmp5);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_TABLE);\r
+\r
+       FreeRpcEnumDhcp(&t);\r
+}\r
+\r
+// DHCP 列挙プロシージャ\r
+UINT NmDhcpProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_HUB *r = (SM_HUB *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               NmDhcpInit(hWnd, r);\r
+               SetTimer(hWnd, 1, NM_DHCP_REFRESH_TIME, NULL);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       NmDhcpRefresh(hWnd, r);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       NmDhcpRefresh(hWnd, r);\r
+                       SetTimer(hWnd, 1, NM_DHCP_REFRESH_TIME, NULL);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_TABLE);\r
+\r
+       return 0;\r
+}\r
+\r
+// DHCP 列挙\r
+void NmDhcp(HWND hWnd, SM_HUB *r)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_NM_DHCP, NmDhcpProc, r);\r
+}\r
+\r
+\r
+// NAT 列挙初期化\r
+void NmNatInit(HWND hWnd, SM_HUB *r)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_PROTOCOL);\r
+\r
+       LvInit(hWnd, L_TABLE);\r
+       LvInsertColumn(hWnd, L_TABLE, 0, _UU("NM_NAT_ID"), 50);\r
+       LvInsertColumn(hWnd, L_TABLE, 1, _UU("NM_NAT_PROTOCOL"), 80);\r
+       LvInsertColumn(hWnd, L_TABLE, 2, _UU("NM_NAT_SRC_HOST"), 100);\r
+       LvInsertColumn(hWnd, L_TABLE, 3, _UU("NM_NAT_SRC_PORT"), 80);\r
+       LvInsertColumn(hWnd, L_TABLE, 4, _UU("NM_NAT_DST_HOST"), 150);\r
+       LvInsertColumn(hWnd, L_TABLE, 5, _UU("NM_NAT_DST_PORT"), 80);\r
+       LvInsertColumn(hWnd, L_TABLE, 6, _UU("NM_NAT_CREATED"), 200);\r
+       LvInsertColumn(hWnd, L_TABLE, 7, _UU("NM_NAT_LAST_COMM"), 200);\r
+       LvInsertColumn(hWnd, L_TABLE, 8, _UU("NM_NAT_SIZE"), 120);\r
+       LvInsertColumn(hWnd, L_TABLE, 9, _UU("NM_NAT_TCP_STATUS"), 120);\r
+\r
+       NmNatRefresh(hWnd, r);\r
+}\r
+\r
+// NAT 列挙\r
+void NmNatRefresh(HWND hWnd, SM_HUB *r)\r
+{\r
+       LVB *b;\r
+       RPC_ENUM_NAT t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), r->HubName);\r
+\r
+       if (CALL(hWnd, ScEnumNAT(r->Rpc, &t)) == false)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+       \r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               RPC_ENUM_NAT_ITEM *e = &t.Items[i];\r
+               wchar_t tmp0[MAX_SIZE];\r
+               wchar_t *tmp1 = L"";\r
+               wchar_t tmp2[MAX_SIZE];\r
+               wchar_t tmp3[MAX_SIZE];\r
+               wchar_t tmp4[MAX_SIZE];\r
+               wchar_t tmp5[MAX_SIZE];\r
+               wchar_t tmp6[MAX_SIZE];\r
+               wchar_t tmp7[MAX_SIZE];\r
+               wchar_t tmp8[MAX_SIZE];\r
+               wchar_t *tmp9 = L"";\r
+               char v1[128], v2[128];\r
+\r
+               // ID\r
+               UniToStru(tmp0, e->Id);\r
+\r
+               // プロトコル\r
+               switch (e->Protocol)\r
+               {\r
+               case NAT_TCP:\r
+                       tmp1 = _UU("NM_NAT_PROTO_TCP");\r
+                       break;\r
+               case NAT_UDP:\r
+                       tmp1 = _UU("NM_NAT_PROTO_UDP");\r
+                       break;\r
+               case NAT_DNS:\r
+                       tmp1 = _UU("NM_NAT_PROTO_DNS");\r
+                       break;\r
+               }\r
+\r
+               // 接続元ホスト\r
+               StrToUni(tmp2, sizeof(tmp2), e->SrcHost);\r
+\r
+               // 接続元ポート\r
+               UniToStru(tmp3, e->SrcPort);\r
+\r
+               // 接続先ホスト\r
+               StrToUni(tmp4, sizeof(tmp4), e->DestHost);\r
+\r
+               // 接続先ポート\r
+               UniToStru(tmp5, e->DestPort);\r
+\r
+               // セッション作成日時\r
+               GetDateTimeStrEx64(tmp6, sizeof(tmp6), SystemToLocal64(e->CreatedTime), NULL);\r
+\r
+               // 最終通信日時\r
+               GetDateTimeStrEx64(tmp7, sizeof(tmp7), SystemToLocal64(e->LastCommTime), NULL);\r
+\r
+               // 通信量\r
+               ToStr3(v1, sizeof(v1), e->RecvSize);\r
+               ToStr3(v2, sizeof(v2), e->SendSize);\r
+               UniFormat(tmp8, sizeof(tmp8), L"%S / %S", v1, v2);\r
+\r
+               // TCP 状態\r
+               if (e->Protocol == NAT_TCP)\r
+               {\r
+                       switch (e->TcpStatus)\r
+                       {\r
+                       case NAT_TCP_CONNECTING:\r
+                               tmp9 = _UU("NAT_TCP_CONNECTING");\r
+                               break;\r
+                       case NAT_TCP_SEND_RESET:\r
+                               tmp9 = _UU("NAT_TCP_SEND_RESET");\r
+                               break;\r
+                       case NAT_TCP_CONNECTED:\r
+                               tmp9 = _UU("NAT_TCP_CONNECTED");\r
+                               break;\r
+                       case NAT_TCP_ESTABLISHED:\r
+                               tmp9 = _UU("NAT_TCP_ESTABLISHED");\r
+                               break;\r
+                       case NAT_TCP_WAIT_DISCONNECT:\r
+                               tmp9 = _UU("NAT_TCP_WAIT_DISCONNECT");\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               LvInsertAdd(b, ICO_PROTOCOL, NULL, 10,\r
+                       tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_TABLE);\r
+\r
+       FreeRpcEnumNat(&t);\r
+}\r
+\r
+// NAT 列挙プロシージャ\r
+UINT NmNatProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_HUB *r = (SM_HUB *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               NmNatInit(hWnd, r);\r
+               SetTimer(hWnd, 1, NM_NAT_REFRESH_TIME, NULL);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       NmNatRefresh(hWnd, r);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       NmNatRefresh(hWnd, r);\r
+                       SetTimer(hWnd, 1, NM_NAT_REFRESH_TIME, NULL);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_TABLE);\r
+\r
+       return 0;\r
+}\r
+\r
+// NAT 列挙\r
+void NmNat(HWND hWnd, SM_HUB *r)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_NM_NAT, NmNatProc, r);\r
+}\r
+\r
+// ルーターの情報の表示\r
+bool NmInfo(HWND hWnd, SM_SERVER *s, void *param)\r
+{\r
+       LVB *b;\r
+       RPC_NAT_INFO t;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       if (CALL(hWnd, NcGetInfo(s->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.NatProductName);\r
+       LvInsertAdd(b, ICO_ROUTER, NULL, 2, _UU("NM_INFO_PRODUCT_NAME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.NatVersionString);\r
+       LvInsertAdd(b, ICO_INFORMATION, NULL, 2, _UU("NM_INFO_VERSION_STR"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.NatBuildInfoString);\r
+       LvInsertAdd(b, ICO_INFORMATION, NULL, 2, _UU("NM_INFO_BUILD_INFO"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.NatHostName);\r
+       LvInsertAdd(b, ICO_TOWER, NULL, 2, _UU("NM_INFO_HOSTNAME"), tmp);\r
+\r
+       // OS\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.OsSystemName);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_SYSTEM_NAME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.OsProductName);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_PRODUCT_NAME"), tmp);\r
+\r
+       if (t.OsInfo.OsServicePack != 0)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_OS_SP_TAG"), t.OsInfo.OsServicePack);\r
+               LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_SERVICE_PACK"), tmp);\r
+       }\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.OsVendorName);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_VENDER_NAME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.OsVersion);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_VERSION"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.KernelName);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_KERNEL_NAME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.KernelVersion);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_KERNEL_VERSION"), tmp);\r
+\r
+       // メモリ情報\r
+       if (t.MemInfo.TotalMemory != 0)\r
+       {\r
+               char vv[128];\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.TotalMemory);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               LvInsertAdd(b, ICO_MEMORY, NULL, 2, _UU("SM_ST_TOTAL_MEMORY"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.UsedMemory);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               LvInsertAdd(b, ICO_MEMORY, NULL, 2, _UU("SM_ST_USED_MEMORY"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.FreeMemory);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               LvInsertAdd(b, ICO_MEMORY, NULL, 2, _UU("SM_ST_FREE_MEMORY"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.TotalPhys);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               LvInsertAdd(b, ICO_MEMORY, NULL, 2, _UU("SM_ST_TOTAL_PHYS"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.UsedPhys);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               LvInsertAdd(b, ICO_MEMORY, NULL, 2, _UU("SM_ST_USED_PHYS"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.FreePhys);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               LvInsertAdd(b, ICO_MEMORY, NULL, 2, _UU("SM_ST_FREE_PHYS"), tmp);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+       FreeRpcNatInfo(&t);\r
+\r
+       return true;\r
+}\r
+\r
+// ルータの状況の表示\r
+bool NmStatus(HWND hWnd, SM_SERVER *s, void *param)\r
+{\r
+       LVB *b;\r
+       RPC_NAT_STATUS t;\r
+       wchar_t tmp[MAX_SIZE];\r
+       SM_HUB *h = (SM_HUB *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), h->HubName);\r
+\r
+       if (CALL(hWnd, ScGetSecureNATStatus(s->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       StrToUni(tmp, sizeof(tmp), h->HubName);\r
+       LvInsertAdd(b, ICO_HUB, NULL, 2, _UU("SM_HUB_COLUMN_1"), tmp);\r
+\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_SESSION"), t.NumTcpSessions);\r
+       LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("NM_STATUS_TCP"), tmp);\r
+\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_SESSION"), t.NumUdpSessions);\r
+       LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("NM_STATUS_UDP"), tmp);\r
+\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_CLIENT"), t.NumDhcpClients);\r
+       LvInsertAdd(b, ICO_PROTOCOL_DHCP, NULL, 2, _UU("NM_STATUS_DHCP"), tmp);\r
+\r
+       LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+       FreeRpcNatStatus(&t);\r
+\r
+       return true;\r
+}\r
+\r
+// フォームの内容を VH_OPTION に変換\r
+void NmEditVhOptionFormToVH(HWND hWnd, VH_OPTION *t)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (hWnd == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(VH_OPTION));\r
+\r
+       GetTxtA(hWnd, E_MAC, tmp, sizeof(tmp));\r
+       b = StrToBin(tmp);\r
+       if (b != NULL)\r
+       {\r
+               if (b->Size == 6)\r
+               {\r
+                       Copy(t->MacAddress, b->Buf, 6);\r
+               }\r
+               FreeBuf(b);\r
+       }\r
+\r
+       UINTToIP(&t->Ip, IpGet(hWnd, E_IP));\r
+       UINTToIP(&t->Mask, IpGet(hWnd, E_MASK));\r
+\r
+       t->UseNat = IsChecked(hWnd, R_USE_NAT);\r
+       t->Mtu = GetInt(hWnd, E_MTU);\r
+       t->NatTcpTimeout = GetInt(hWnd, E_TCP);\r
+       t->NatUdpTimeout = GetInt(hWnd, E_UDP);\r
+\r
+       t->UseDhcp = IsChecked(hWnd, R_USE_DHCP);\r
+       UINTToIP(&t->DhcpLeaseIPStart, IpGet(hWnd, E_DHCP_START));\r
+       UINTToIP(&t->DhcpLeaseIPEnd, IpGet(hWnd, E_DHCP_END));\r
+       UINTToIP(&t->DhcpSubnetMask, IpGet(hWnd, E_DHCP_MASK));\r
+       t->DhcpExpireTimeSpan = GetInt(hWnd, E_EXPIRES);\r
+       UINTToIP(&t->DhcpGatewayAddress, IpGet(hWnd, E_GATEWAY));\r
+       UINTToIP(&t->DhcpDnsServerAddress, IpGet(hWnd, E_DNS));\r
+       GetTxtA(hWnd, E_DOMAIN, t->DhcpDomainName, sizeof(t->DhcpDomainName));\r
+       t->SaveLog = IsChecked(hWnd, R_SAVE_LOG);\r
+}\r
+\r
+// 初期化\r
+void NmEditVhOptionInit(HWND hWnd, SM_HUB *r)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       VH_OPTION t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FormatText(hWnd, S_TITLE, r->HubName);\r
+\r
+       Zero(&t, sizeof(VH_OPTION));\r
+       StrCpy(t.HubName, sizeof(t.HubName), r->HubName);\r
+       if (CALL(hWnd, ScGetSecureNATOption(r->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       if (GetCapsBool(r->p->CapsList, "b_virtual_nat_disabled"))\r
+       {\r
+               SetEnable(hWnd, R_USE_NAT, false);\r
+               Check(hWnd, R_USE_NAT, false);\r
+       }\r
+\r
+       MacToStr(tmp, sizeof(tmp), t.MacAddress);\r
+       SetTextA(hWnd, E_MAC, tmp);\r
+       IpSet(hWnd, E_IP, IPToUINT(&t.Ip));\r
+       IpSet(hWnd, E_MASK, IPToUINT(&t.Mask));\r
+\r
+       Check(hWnd, R_USE_NAT, t.UseNat);\r
+       SetIntEx(hWnd, E_MTU, t.Mtu);\r
+       SetIntEx(hWnd, E_TCP, t.NatTcpTimeout);\r
+       SetIntEx(hWnd, E_UDP, t.NatUdpTimeout);\r
+\r
+       Check(hWnd, R_USE_DHCP, t.UseDhcp);\r
+       IpSet(hWnd, E_DHCP_START, IPToUINT(&t.DhcpLeaseIPStart));\r
+       IpSet(hWnd, E_DHCP_END, IPToUINT(&t.DhcpLeaseIPEnd));\r
+       IpSet(hWnd, E_DHCP_MASK, IPToUINT(&t.DhcpSubnetMask));\r
+       SetIntEx(hWnd, E_EXPIRES, t.DhcpExpireTimeSpan);\r
+\r
+       if (IPToUINT(&t.DhcpGatewayAddress) != 0)\r
+       {\r
+               IpSet(hWnd, E_GATEWAY, IPToUINT(&t.DhcpGatewayAddress));\r
+       }\r
+\r
+       if (IPToUINT(&t.DhcpDnsServerAddress) != 0)\r
+       {\r
+               IpSet(hWnd, E_DNS, IPToUINT(&t.DhcpDnsServerAddress));\r
+       }\r
+\r
+       SetTextA(hWnd, E_DOMAIN, t.DhcpDomainName);\r
+       Check(hWnd, R_SAVE_LOG, t.SaveLog);\r
+\r
+       NmEditVhOptionUpdate(hWnd, r);\r
+\r
+}\r
+\r
+void NmEditVhOptionUpdate(HWND hWnd, SM_HUB *r)\r
+{\r
+       VH_OPTION t;\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       NmEditVhOptionFormToVH(hWnd, &t);\r
+\r
+       if (IsZero(t.MacAddress, 6))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (IPToUINT(&t.Ip) == 0 || IPToUINT(&t.Mask) == 0)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (IpIsFilled(hWnd, E_IP) == false || IpIsFilled(hWnd, E_MASK) == false)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (IsHostIPAddress4(&t.Ip) == false || IsSubnetMask4(&t.Mask) == false)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (t.UseNat)\r
+       {\r
+               if (t.Mtu < 64 || t.Mtu > 1500)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (t.NatTcpTimeout < (NAT_TCP_MIN_TIMEOUT / 1000) || t.NatTcpTimeout > (NAT_TCP_MAX_TIMEOUT / 1000))\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (t.NatUdpTimeout < (NAT_UDP_MIN_TIMEOUT / 1000) || t.NatUdpTimeout > (NAT_UDP_MAX_TIMEOUT / 1000))\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       if (t.UseDhcp)\r
+       {\r
+               if (IpIsFilled(hWnd, E_DHCP_START) == false || IpIsFilled(hWnd, E_DHCP_END) == false ||\r
+                       IpIsFilled(hWnd, E_DHCP_MASK) == false)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (IpGetFilledNum(hWnd, E_GATEWAY) != 0 && IpGetFilledNum(hWnd, E_GATEWAY) != 4)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (IpGetFilledNum(hWnd, E_DNS) != 0 && IpGetFilledNum(hWnd, E_DNS) != 4)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (IPToUINT(&t.DhcpLeaseIPStart) == 0 || IPToUINT(&t.DhcpLeaseIPEnd) == 0 ||\r
+                       IPToUINT(&t.DhcpSubnetMask) == 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (t.DhcpExpireTimeSpan < 15)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (Endian32(IPToUINT(&t.DhcpLeaseIPStart)) > Endian32(IPToUINT(&t.DhcpLeaseIPEnd)))\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (IsHostIPAddress4(&t.DhcpLeaseIPStart) == false ||\r
+                       IsHostIPAddress4(&t.DhcpLeaseIPEnd) == false)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (IsSubnetMask4(&t.DhcpSubnetMask) == false)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, E_MTU, t.UseNat);\r
+       SetEnable(hWnd, E_TCP, t.UseNat);\r
+       SetEnable(hWnd, E_UDP, t.UseNat);\r
+\r
+       SetEnable(hWnd, E_DHCP_START, t.UseDhcp);\r
+       SetEnable(hWnd, E_DHCP_END, t.UseDhcp);\r
+       SetEnable(hWnd, E_DHCP_MASK, t.UseDhcp);\r
+       SetEnable(hWnd, E_EXPIRES, t.UseDhcp);\r
+       SetEnable(hWnd, E_GATEWAY, t.UseDhcp);\r
+       SetEnable(hWnd, E_DNS, t.UseDhcp);\r
+       SetEnable(hWnd, E_DOMAIN, t.UseDhcp);\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// OK ボタン\r
+void NmEditVhOptionOnOk(HWND hWnd, SM_HUB *r)\r
+{\r
+       VH_OPTION t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       NmEditVhOptionFormToVH(hWnd, &t);\r
+       StrCpy(t.HubName, sizeof(t.HubName), r->HubName);\r
+\r
+       if (CALL(hWnd, ScSetSecureNATOption(r->Rpc, &t)))\r
+       {\r
+               EndDialog(hWnd, true);\r
+       }\r
+}\r
+\r
+// 仮想ホストオプション編集ダイアログ\r
+UINT NmEditVhOptionProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_HUB *r = (SM_HUB *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               NmEditVhOptionInit(hWnd, r);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_MAC:\r
+               case E_IP:\r
+               case E_MASK:\r
+               case R_USE_NAT:\r
+               case E_MTU:\r
+               case E_TCP:\r
+               case E_UDP:\r
+               case R_SAVE_LOG:\r
+               case R_USE_DHCP:\r
+               case E_DHCP_START:\r
+               case E_DHCP_END:\r
+               case E_DHCP_MASK:\r
+               case E_EXPIRES:\r
+               case E_GATEWAY:\r
+               case E_DNS:\r
+               case E_DOMAIN:\r
+                       NmEditVhOptionUpdate(hWnd, r);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       NmEditVhOptionOnOk(hWnd, r);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       EndDialog(hWnd, false);\r
+                       break;\r
+\r
+               case R_USE_NAT:\r
+                       if (IsChecked(hWnd, R_USE_NAT))\r
+                       {\r
+                               FocusEx(hWnd, E_MTU);\r
+                       }\r
+\r
+                       if (IsChecked(hWnd, R_USE_DHCP))\r
+                       {\r
+                               Focus(hWnd, E_DHCP_START);\r
+                       }\r
+                       break;\r
+               }\r
+\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想ホストオプションの編集\r
+void NmEditVhOption(HWND hWnd, SM_HUB *r)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_NM_OPTION, NmEditVhOptionProc, r);\r
+}\r
+\r
+// クライアント設定の編集\r
+void NmEditClientConfig(HWND hWnd, RPC *r)\r
+{\r
+       CM_ACCOUNT a;\r
+       RPC_CREATE_LINK t;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&a, sizeof(a));\r
+       Zero(&t, sizeof(t));\r
+\r
+       a.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       a.NatMode = true;\r
+       a.Rpc = r;\r
+\r
+       if (CALLEX(hWnd, NcGetClientConfig(r, &t)) != ERR_NO_ERROR)\r
+       {\r
+               // 新規作成\r
+               a.ClientOption->Port = 443;\r
+               a.ClientOption->RetryInterval = 15;\r
+               a.ClientOption->NumRetry = INFINITE;\r
+               a.ClientOption->AdditionalConnectionInterval = 1;\r
+               a.ClientOption->UseEncrypt = true;\r
+               a.ClientOption->NoRoutingTracking = true;\r
+               a.ClientAuth = ZeroMalloc(sizeof(CLIENT_AUTH));\r
+               a.ClientAuth->AuthType = CLIENT_AUTHTYPE_PASSWORD;\r
+       }\r
+       else\r
+       {\r
+               // 編集\r
+               a.EditMode = true;\r
+               Copy(a.ClientOption, t.ClientOption, sizeof(CLIENT_OPTION));\r
+               a.ClientAuth = CopyClientAuth(t.ClientAuth);\r
+\r
+               FreeRpcCreateLink(&t);\r
+       }\r
+\r
+       ret = CmEditAccountDlg(hWnd, &a);\r
+\r
+       Free(a.ServerCert);\r
+       Free(a.ClientOption);\r
+       CiFreeClientAuth(a.ClientAuth);\r
+}\r
+\r
+// 初期化\r
+void NmMainDlgInit(HWND hWnd, RPC *r)\r
+{\r
+       // 引数チェック\r
+       if (r == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_ROUTER);\r
+       FormatText(hWnd, 0, r->Sock->RemoteHostname);\r
+       DlgFont(hWnd, S_STATUS, 11, true);\r
+\r
+       NmMainDlgRefresh(hWnd, r);\r
+}\r
+\r
+// 更新\r
+void NmMainDlgRefresh(HWND hWnd, RPC *r)\r
+{\r
+#if    0\r
+       RPC_NAT_STATUS t;\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (r == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(RPC_NAT_STATUS));\r
+\r
+       CALL(hWnd, NcGetStatus(r, &t));\r
+\r
+       if (t.Online == false)\r
+       {\r
+               UniStrCpy(tmp, sizeof(tmp), _UU("NM_OFFLINE"));\r
+\r
+               Enable(hWnd, B_CONNECT);\r
+               Disable(hWnd, B_DISCONNECT);\r
+       }\r
+       else\r
+       {\r
+               if (t.Connected)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("NM_CONNECTED"), t.Status.ServerName);\r
+               }\r
+               else\r
+               {\r
+                       if (t.LastError == ERR_NO_ERROR)\r
+                       {\r
+                               UniStrCpy(tmp, sizeof(tmp), _UU("NM_CONNECTING"));\r
+                       }\r
+                       else\r
+                       {\r
+                               UniFormat(tmp, sizeof(tmp), _UU("NM_CONNECT_ERROR"), t.LastError, _E(t.LastError));\r
+                       }\r
+               }\r
+               Disable(hWnd, B_CONNECT);\r
+               Enable(hWnd, B_DISCONNECT);\r
+       }\r
+\r
+       UniFormat(tmp2, sizeof(tmp2), _UU("NM_STATUS_TAG"), tmp);\r
+\r
+       SetText(hWnd, S_STATUS, tmp2);\r
+\r
+       FreeRpcNatStatus(&t);\r
+#endif\r
+}\r
+\r
+// メインダイアログプロシージャ\r
+UINT NmMainDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+#if    0\r
+       SM_HUB *r = (SM_HUB *)param;\r
+       RPC_DUMMY dummy;\r
+       SM_SERVER sm;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               NmMainDlgInit(hWnd, r);\r
+\r
+               SetTimer(hWnd, 1, NM_REFRESH_TIME, NULL);\r
+\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_SETTING:\r
+                       // 接続設定\r
+                       NmEditClientConfig(hWnd, r);\r
+                       break;\r
+\r
+               case B_CONNECT:\r
+                       // 接続\r
+                       Zero(&dummy, sizeof(dummy));\r
+                       CALL(hWnd, NcOnline(r, &dummy));\r
+                       NmMainDlgRefresh(hWnd, r);\r
+                       break;\r
+\r
+               case B_DISCONNECT:\r
+                       // 切断\r
+                       Zero(&dummy, sizeof(dummy));\r
+                       CALL(hWnd, NcOffline(r, &dummy));\r
+                       NmMainDlgRefresh(hWnd, r);\r
+                       break;\r
+\r
+               case B_OPTION:\r
+                       // 動作設定\r
+                       NmEditVhOption(hWnd, r->Rpc);\r
+                       break;\r
+\r
+               case B_NAT:\r
+                       // NAT\r
+                       NmNat(hWnd, r);\r
+                       break;\r
+\r
+               case B_DHCP:\r
+                       // DHCP\r
+                       NmDhcp(hWnd, r);\r
+                       break;\r
+\r
+               case B_STATUS:\r
+                       // 状況\r
+                       Zero(&sm, sizeof(sm));\r
+                       sm.Rpc = r;\r
+                       SmStatusDlg(hWnd, &sm, NULL, true, true, _UU("NM_STATUS"), ICO_ROUTER,\r
+                               NULL, NmStatus);\r
+                       break;\r
+\r
+               case B_INFO:\r
+                       // 情報\r
+                       Zero(&sm, sizeof(sm));\r
+                       sm.Rpc = r;\r
+                       SmStatusDlg(hWnd, &sm, NULL, false, true, _UU("NM_INFO"), ICO_ROUTER,\r
+                               NULL, NmInfo);\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       // 更新\r
+                       NmMainDlgRefresh(hWnd, r);\r
+                       break;\r
+\r
+               case B_PASSWORD:\r
+                       // パスワード変更\r
+                       NmChangePassword(hWnd, r);\r
+                       break;\r
+\r
+               case B_ABOUT:\r
+                       // バージョン情報\r
+                       About(hWnd, nm->Cedar, CEDAR_ROUTER_STR, BMP_SPLASH_ROUTER);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+\r
+                       if (IsEnable(hWnd, 0))\r
+                       {\r
+                               NmMainDlgRefresh(hWnd, r);\r
+                       }\r
+\r
+                       SetTimer(hWnd, 1, NM_REFRESH_TIME, NULL);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+#endif\r
+\r
+       return 0;\r
+}\r
+\r
+// メインダイアログ\r
+void NmMainDlg(RPC *r)\r
+{\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(NULL, D_NM_MAIN, NmMainDlgProc, r);\r
+}\r
+\r
+// ログインダイアログ\r
+UINT NmLogin(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       NM_LOGIN *login = (NM_LOGIN *)param;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               FormatText(hWnd, S_TITLE, login->Hostname);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       GetTxtA(hWnd, E_PASSWORD, tmp, sizeof(tmp));\r
+                       Hash(login->hashed_password, tmp, StrLen(tmp), true);\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 接続ダイアログ\r
+UINT NmConnectDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       NM_CONNECT *t = (NM_CONNECT *)param;\r
+       RPC *rpc;\r
+       NM_LOGIN login;\r
+       UINT err;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               FormatText(hWnd, S_TITLE, t->Hostname);\r
+               SetTimer(hWnd, 1, 50, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+\r
+                       while (true)\r
+                       {\r
+                               bool flag = false;\r
+RETRY_PASSWORD:\r
+                               // パスワード入力ダイアログ\r
+                               Zero(&login, sizeof(login));\r
+                               login.Hostname = t->Hostname;\r
+                               login.Port = t->Port;\r
+                               Hash(login.hashed_password, "", 0, true);\r
+\r
+                               if (flag)\r
+                               {\r
+                                       if (Dialog(hWnd, D_NM_LOGIN, NmLogin, &login) == false)\r
+                                       {\r
+                                               EndDialog(hWnd, false);\r
+                                               break;\r
+                                       }\r
+                               }\r
+\r
+RETRY_CONNECT:\r
+                               Refresh(DlgItem(hWnd, S_TITLE));\r
+                               Refresh(hWnd);\r
+                               // 接続\r
+                               rpc = NatAdminConnect(nm->Cedar, t->Hostname, t->Port, login.hashed_password, &err);\r
+                               if (rpc != NULL)\r
+                               {\r
+                                       t->Rpc = rpc;\r
+                                       EndDialog(hWnd, true);\r
+                                       break;\r
+                               }\r
+\r
+                               // エラー\r
+                               if (err == ERR_ACCESS_DENIED || err == ERR_AUTH_FAILED)\r
+                               {\r
+                                       if (flag)\r
+                                       {\r
+                                               if (MsgBox(hWnd, MB_ICONEXCLAMATION | MB_RETRYCANCEL,\r
+                                                       _E(err)) == IDCANCEL)\r
+                                               {\r
+                                                       EndDialog(hWnd, false);\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                                       flag = true;\r
+                                       goto RETRY_PASSWORD;\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (MsgBox(hWnd, MB_ICONEXCLAMATION | MB_RETRYCANCEL,\r
+                                               _E(err)) == IDCANCEL)\r
+                                       {\r
+                                               EndDialog(hWnd, false);\r
+                                               break;\r
+                                       }\r
+                                       goto RETRY_CONNECT;\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// User-mode NAT プログラムに接続する\r
+RPC *NmConnect(char *hostname, UINT port)\r
+{\r
+       NM_CONNECT t;\r
+       // 引数チェック\r
+       if (hostname == NULL || port == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.Hostname = hostname;\r
+       t.Port = port;\r
+\r
+       Dialog(NULL, D_NM_CONNECT, NmConnectDlgProc, &t);\r
+\r
+       return t.Rpc;\r
+}\r
+\r
+// メイン処理\r
+void MainNM()\r
+{\r
+       UINT port;\r
+       char hostname[MAX_HOST_NAME_LEN + 1];\r
+       char *tmp =\r
+               RemoteDlg(NULL, NM_SETTING_REG_KEY, ICO_ROUTER,\r
+               _UU("NM_TITLE"), _UU("NM_CONNECT_TITLE"), NULL);\r
+       TOKEN_LIST *t;\r
+\r
+       Zero(hostname, sizeof(hostname));\r
+\r
+       if (tmp == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = ParseToken(tmp, ":");\r
+       port = DEFAULT_NAT_ADMIN_PORT;\r
+\r
+       if (t->NumTokens >= 2)\r
+       {\r
+               UINT i = ToInt(t->Token[1]);\r
+               if (i != 0)\r
+               {\r
+                       port = i;\r
+               }\r
+       }\r
+       if (t->NumTokens >= 1)\r
+       {\r
+               RPC *rpc;\r
+               StrCpy(hostname, sizeof(hostname), t->Token[0]);\r
+\r
+               // 接続\r
+               Trim(hostname);\r
+\r
+               if (StrLen(hostname) != 0)\r
+               {\r
+                       rpc = NmConnect(hostname, port);\r
+                       if (rpc != NULL)\r
+                       {\r
+                               // 接続した\r
+                               NmMainDlg(rpc);\r
+                               NatAdminDisconnect(rpc);\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       Free(tmp);\r
+}\r
+\r
+// 初期化\r
+void InitNM()\r
+{\r
+       if (nm != NULL)\r
+       {\r
+               // すでに初期化されている\r
+               return;\r
+       }\r
+\r
+       nm = ZeroMalloc(sizeof(NM));\r
+\r
+       InitWinUi(_UU("NM_TITLE"), _SS("DEFAULT_FONT"), _II("DEFAULT_FONT_SIZE"));\r
+\r
+       nm->Cedar = NewCedar(NULL, NULL);\r
+\r
+       InitCM();\r
+       InitSM();\r
+}\r
+\r
+// 解放\r
+void FreeNM()\r
+{\r
+       if (nm == NULL)\r
+       {\r
+               // 初期化されていない\r
+               return;\r
+       }\r
+\r
+       FreeSM();\r
+       FreeCM();\r
+\r
+       ReleaseCedar(nm->Cedar);\r
+\r
+       FreeWinUi();\r
+\r
+       Free(nm);\r
+       nm = NULL;\r
+}\r
+\r
+// NM の実行\r
+void NMExec()\r
+{\r
+       InitNM();\r
+       MainNM();\r
+       FreeNM();\r
+}\r
+\r
+#endif\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/NM.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/NM.h
new file mode 100644 (file)
index 0000000..4dba0ec
--- /dev/null
@@ -0,0 +1,89 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// NM.h\r
+// NM.c のヘッダ\r
+\r
+#ifndef        NM_H\r
+#define        NM_H\r
+\r
+// 外部向け関数\r
+void NMExec();\r
+\r
+#endif // NM_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/NMInner.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/NMInner.h
new file mode 100644 (file)
index 0000000..30b71dd
--- /dev/null
@@ -0,0 +1,141 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// NMInner.h\r
+// NM.c の内部向けヘッダ\r
+\r
+\r
+// 定数\r
+#define        NM_REG_KEY                      "Software\\SoftEther Corporation\\UT-VPN\\User-mode Router Manager"\r
+#define        NM_SETTING_REG_KEY      "Software\\SoftEther Corporation\\UT-VPN\\User-mode Router Manager\\Settings"\r
+\r
+#define        NM_REFRESH_TIME                 1000\r
+#define        NM_NAT_REFRESH_TIME             1000\r
+#define        NM_DHCP_REFRESH_TIME    1000\r
+\r
+// Nat Admin 構造体\r
+typedef struct NM\r
+{\r
+       CEDAR *Cedar;                           // Cedar\r
+} NM;\r
+\r
+// 接続構造体\r
+typedef struct NM_CONNECT\r
+{\r
+       RPC *Rpc;                                       // RPC\r
+       char *Hostname;\r
+       UINT Port;\r
+} NM_CONNECT;\r
+\r
+// ログイン\r
+typedef struct NM_LOGIN\r
+{\r
+       char *Hostname;\r
+       UINT Port;\r
+       UCHAR hashed_password[SHA1_SIZE];\r
+} NM_LOGIN;\r
+\r
+// 内部向け関数\r
+void InitNM();\r
+void FreeNM();\r
+void MainNM();\r
+RPC *NmConnect(char *hostname, UINT port);\r
+UINT NmConnectDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+UINT NmLogin(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void NmMainDlg(RPC *r);\r
+UINT NmMainDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void NmMainDlgInit(HWND hWnd, RPC *r);\r
+void NmMainDlgRefresh(HWND hWnd, RPC *r);\r
+void NmEditClientConfig(HWND hWnd, RPC *r);\r
+void NmEditVhOption(HWND hWnd, SM_HUB *r);\r
+UINT NmEditVhOptionProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void NmEditVhOptionInit(HWND hWnd, SM_HUB *r);\r
+void NmEditVhOptionUpdate(HWND hWnd, SM_HUB *r);\r
+void NmEditVhOptionOnOk(HWND hWnd, SM_HUB *r);\r
+void NmEditVhOptionFormToVH(HWND hWnd, VH_OPTION *t);\r
+bool NmStatus(HWND hWnd, SM_SERVER *s, void *param);\r
+bool NmInfo(HWND hWnd, SM_SERVER *s, void *param);\r
+void NmNat(HWND hWnd, SM_HUB *r);\r
+UINT NmNatProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void NmNatInit(HWND hWnd, SM_HUB *r);\r
+void NmNatRefresh(HWND hWnd, SM_HUB *r);\r
+void NmDhcp(HWND hWnd, SM_HUB *r);\r
+UINT NmDhcpProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void NmDhcpRefresh(HWND hWnd, SM_HUB *r);\r
+void NmDhcpInit(HWND hWnd, SM_HUB *r);\r
+void NmChangePassword(HWND hWnd, RPC *r);\r
+UINT NmChangePasswordProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Nat.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Nat.c
new file mode 100644 (file)
index 0000000..bc7b783
--- /dev/null
@@ -0,0 +1,1778 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Nat.c\r
+// User-mode Router\r
+\r
+#include "CedarPch.h"\r
+\r
+static LOCK *nat_lock = NULL;\r
+static NAT *nat = NULL;\r
+\r
+\r
+// NAT 管理者用接続を切断\r
+void NatAdminDisconnect(RPC *r)\r
+{\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       EndRpc(r);\r
+}\r
+\r
+// NAT 管理者用接続\r
+RPC *NatAdminConnect(CEDAR *cedar, char *hostname, UINT port, void *hashed_password, UINT *err)\r
+{\r
+       UCHAR secure_password[SHA1_SIZE];\r
+       UCHAR random[SHA1_SIZE];\r
+       SOCK *sock;\r
+       RPC *rpc;\r
+       PACK *p;\r
+       UINT error;\r
+       // 引数チェック\r
+       if (cedar == NULL || hostname == NULL || port == 0 || hashed_password == NULL || err == NULL)\r
+       {\r
+               if (err != NULL)\r
+               {\r
+                       *err = ERR_INTERNAL_ERROR;\r
+               }\r
+               return NULL;\r
+       }\r
+\r
+       // 接続\r
+       sock = Connect(hostname, port);\r
+       if (sock == NULL)\r
+       {\r
+               *err = ERR_CONNECT_FAILED;\r
+               return NULL;\r
+       }\r
+\r
+       if (StartSSL(sock, NULL, NULL) == false)\r
+       {\r
+               *err = ERR_PROTOCOL_ERROR;\r
+               ReleaseSock(sock);\r
+               return NULL;\r
+       }\r
+\r
+       SetTimeout(sock, 5000);\r
+\r
+       p = HttpClientRecv(sock);\r
+       if (p == NULL)\r
+       {\r
+               *err = ERR_DISCONNECTED;\r
+               ReleaseSock(sock);\r
+               return NULL;\r
+       }\r
+\r
+       if (PackGetData2(p, "auth_random", random, SHA1_SIZE) == false)\r
+       {\r
+               FreePack(p);\r
+               *err = ERR_PROTOCOL_ERROR;\r
+               ReleaseSock(sock);\r
+               return NULL;\r
+       }\r
+\r
+       FreePack(p);\r
+\r
+       SecurePassword(secure_password, hashed_password, random);\r
+\r
+       p = NewPack();\r
+       PackAddData(p, "secure_password", secure_password, SHA1_SIZE);\r
+\r
+       if (HttpClientSend(sock, p) == false)\r
+       {\r
+               FreePack(p);\r
+               *err = ERR_DISCONNECTED;\r
+               ReleaseSock(sock);\r
+               return NULL;\r
+       }\r
+\r
+       FreePack(p);\r
+\r
+       p = HttpClientRecv(sock);\r
+       if (p == NULL)\r
+       {\r
+               *err = ERR_DISCONNECTED;\r
+               ReleaseSock(sock);\r
+               return NULL;\r
+       }\r
+\r
+       error = GetErrorFromPack(p);\r
+\r
+       FreePack(p);\r
+\r
+       if (error != ERR_NO_ERROR)\r
+       {\r
+               *err = error;\r
+               ReleaseSock(sock);\r
+               return NULL;\r
+       }\r
+\r
+       SetTimeout(sock, TIMEOUT_INFINITE);\r
+\r
+       rpc = StartRpcClient(sock, NULL);\r
+       ReleaseSock(sock);\r
+\r
+       return rpc;\r
+}\r
+\r
+// RPC 関数関係マクロ\r
+#define        DECLARE_RPC_EX(rpc_name, data_type, function, in_rpc, out_rpc, free_rpc)                \\r
+       else if (StrCmpi(name, rpc_name) == 0)                                                          \\r
+       {                                                                                                                                       \\r
+               data_type t;                                                                                                    \\r
+               Zero(&t, sizeof(t));                                                                                    \\r
+               in_rpc(&t, p);                                                                                                  \\r
+               err = function(n, &t);                                                                                  \\r
+               if (err == ERR_NO_ERROR)                                                                                \\r
+               {                                                                                                                               \\r
+                       out_rpc(ret, &t);                                                                                       \\r
+               }                                                                                                                               \\r
+               free_rpc(&t);                                                                                                   \\r
+               ok = true;                                                                                                              \\r
+       }\r
+#define        DECLARE_RPC(rpc_name, data_type, function, in_rpc, out_rpc)             \\r
+       else if (StrCmpi(name, rpc_name) == 0)                                                          \\r
+       {                                                                                                                                       \\r
+               data_type t;                                                                                                    \\r
+               Zero(&t, sizeof(t));                                                                                    \\r
+               in_rpc(&t, p);                                                                                                  \\r
+               err = function(n, &t);                                                                                  \\r
+               if (err == ERR_NO_ERROR)                                                                                \\r
+               {                                                                                                                               \\r
+                       out_rpc(ret, &t);                                                                                       \\r
+               }                                                                                                                               \\r
+               ok = true;                                                                                                              \\r
+       }\r
+#define        DECLARE_SC_EX(rpc_name, data_type, function, in_rpc, out_rpc, free_rpc) \\r
+       UINT function(RPC *r, data_type *t)                                                                     \\r
+       {                                                                                                                                       \\r
+               PACK *p, *ret;                                                                                                  \\r
+               UINT err;                                                                                                               \\r
+               if (r == NULL || t == NULL)                                                                             \\r
+               {                                                                                                                               \\r
+                       return ERR_INTERNAL_ERROR;                                                                      \\r
+               }                                                                                                                               \\r
+               p = NewPack();                                                                                                  \\r
+               out_rpc(p, t);                                                                                                  \\r
+               free_rpc(t);                                                                                                    \\r
+               Zero(t, sizeof(data_type));                                                                             \\r
+               ret = AdminCall(r, rpc_name, p);                                                                \\r
+               err = GetErrorFromPack(ret);                                                                    \\r
+               if (err == ERR_NO_ERROR)                                                                                \\r
+               {                                                                                                                               \\r
+                       in_rpc(t, ret);                                                                                         \\r
+               }                                                                                                                               \\r
+               FreePack(ret);                                                                                                  \\r
+               return err;                                                                                                             \\r
+       }\r
+#define        DECLARE_SC(rpc_name, data_type, function, in_rpc, out_rpc)              \\r
+       UINT function(RPC *r, data_type *t)                                                                     \\r
+       {                                                                                                                                       \\r
+               PACK *p, *ret;                                                                                                  \\r
+               UINT err;                                                                                                               \\r
+               if (r == NULL || t == NULL)                                                                             \\r
+               {                                                                                                                               \\r
+                       return ERR_INTERNAL_ERROR;                                                                      \\r
+               }                                                                                                                               \\r
+               p = NewPack();                                                                                                  \\r
+               out_rpc(p, t);                                                                                                  \\r
+               ret = AdminCall(r, rpc_name, p);                                                                \\r
+               err = GetErrorFromPack(ret);                                                                    \\r
+               if (err == ERR_NO_ERROR)                                                                                \\r
+               {                                                                                                                               \\r
+                       in_rpc(t, ret);                                                                                         \\r
+               }                                                                                                                               \\r
+               FreePack(ret);                                                                                                  \\r
+               return err;                                                                                                             \\r
+       }\r
+\r
+// RPC サーバー関数\r
+PACK *NiRpcServer(RPC *r, char *name, PACK *p)\r
+{\r
+       NAT *n = (NAT *)r->Param;\r
+       PACK *ret;\r
+       UINT err;\r
+       bool ok;\r
+       // 引数チェック\r
+       if (r == NULL || name == NULL || p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = NewPack();\r
+       err = ERR_NO_ERROR;\r
+       ok = false;\r
+\r
+       if (0) {}\r
+\r
+       // RPC 関数定義: ここから\r
+\r
+//     DECLARE_RPC("Online", RPC_DUMMY, NtOnline, InRpcDummy, OutRpcDummy)\r
+//     DECLARE_RPC("Offline", RPC_DUMMY, NtOffline, InRpcDummy, OutRpcDummy)\r
+       DECLARE_RPC("SetHostOption", VH_OPTION, NtSetHostOption, InVhOption, OutVhOption)\r
+       DECLARE_RPC("GetHostOption", VH_OPTION, NtGetHostOption, InVhOption, OutVhOption)\r
+//     DECLARE_RPC_EX("SetClientConfig", RPC_CREATE_LINK, NtSetClientConfig, InRpcCreateLink, OutRpcCreateLink, FreeRpcCreateLink)\r
+//     DECLARE_RPC_EX("GetClientConfig", RPC_CREATE_LINK, NtGetClientConfig, InRpcCreateLink, OutRpcCreateLink, FreeRpcCreateLink)\r
+       DECLARE_RPC_EX("GetStatus", RPC_NAT_STATUS, NtGetStatus, InRpcNatStatus, OutRpcNatStatus, FreeRpcNatStatus)\r
+//     DECLARE_RPC_EX("GetInfo", RPC_NAT_INFO, NtGetInfo, InRpcNatInfo, OutRpcNatInfo, FreeRpcNatInfo)\r
+       DECLARE_RPC_EX("EnumNatList", RPC_ENUM_NAT, NtEnumNatList, InRpcEnumNat, OutRpcEnumNat, FreeRpcEnumNat)\r
+       DECLARE_RPC_EX("EnumDhcpList", RPC_ENUM_DHCP, NtEnumDhcpList, InRpcEnumDhcp, OutRpcEnumDhcp, FreeRpcEnumDhcp)\r
+//     DECLARE_RPC("SetPassword", RPC_SET_PASSWORD, NtSetPassword, InRpcSetPassword, OutRpcSetPassword)\r
+\r
+       // RPC 関数定義: ここまで\r
+\r
+       if (ok == false)\r
+       {\r
+               err = ERR_NOT_SUPPORTED;\r
+       }\r
+\r
+       PackAddInt(ret, "error", err);\r
+\r
+       return ret;\r
+}\r
+\r
+\r
+\r
+\r
+// RPC 呼び出し定義ここから\r
+\r
+DECLARE_SC("Online", RPC_DUMMY, NcOnline, InRpcDummy, OutRpcDummy)\r
+DECLARE_SC("Offline", RPC_DUMMY, NcOffline, InRpcDummy, OutRpcDummy)\r
+DECLARE_SC("SetHostOption", VH_OPTION, NcSetHostOption, InVhOption, OutVhOption)\r
+DECLARE_SC("GetHostOption", VH_OPTION, NcGetHostOption, InVhOption, OutVhOption)\r
+DECLARE_SC_EX("SetClientConfig", RPC_CREATE_LINK, NcSetClientConfig, InRpcCreateLink, OutRpcCreateLink, FreeRpcCreateLink)\r
+DECLARE_SC_EX("GetClientConfig", RPC_CREATE_LINK, NcGetClientConfig, InRpcCreateLink, OutRpcCreateLink, FreeRpcCreateLink)\r
+DECLARE_SC_EX("GetStatus", RPC_NAT_STATUS, NcGetStatus, InRpcNatStatus, OutRpcNatStatus, FreeRpcNatStatus)\r
+DECLARE_SC_EX("GetInfo", RPC_NAT_INFO, NcGetInfo, InRpcNatInfo, OutRpcNatInfo, FreeRpcNatInfo)\r
+DECLARE_SC_EX("EnumNatList", RPC_ENUM_NAT, NcEnumNatList, InRpcEnumNat, OutRpcEnumNat, FreeRpcEnumNat)\r
+DECLARE_SC_EX("EnumDhcpList", RPC_ENUM_DHCP, NcEnumDhcpList, InRpcEnumDhcp, OutRpcEnumDhcp, FreeRpcEnumDhcp)\r
+DECLARE_SC("SetPassword", RPC_SET_PASSWORD, NcSetPassword, InRpcSetPassword, OutRpcSetPassword)\r
+\r
+// RPC 呼び出し定義ここまで\r
+\r
+\r
+\r
+// パスワードを設定する\r
+UINT NtSetPassword(NAT *n, RPC_SET_PASSWORD *t)\r
+{\r
+       Copy(n->HashedPassword, t->HashedPassword, SHA1_SIZE);\r
+\r
+       NiWriteConfig(n);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// オンラインにする\r
+UINT NtOnline(NAT *n, RPC_DUMMY *t)\r
+{\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       Lock(n->lock);\r
+       {\r
+               if (n->Online)\r
+               {\r
+                       // すでにオンラインである\r
+                       ret = ERR_ALREADY_ONLINE;\r
+               }\r
+               else\r
+               {\r
+                       if (n->ClientOption == NULL || n->ClientAuth == NULL)\r
+                       {\r
+                               // 設定がまだ\r
+                               ret = ERR_ACCOUNT_NOT_PRESENT;\r
+                       }\r
+                       else\r
+                       {\r
+                               // OK\r
+                               n->Online = true;\r
+\r
+                               // 接続開始\r
+                               n->Virtual = NewVirtualHostEx(n->Cedar, n->ClientOption, n->ClientAuth,\r
+                                       &n->Option, n);\r
+                       }\r
+               }\r
+       }\r
+       Unlock(n->lock);\r
+\r
+       NiWriteConfig(n);\r
+\r
+       return ret;\r
+}\r
+\r
+// オフラインにする\r
+UINT NtOffline(NAT *n, RPC_DUMMY *t)\r
+{\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       Lock(n->lock);\r
+       {\r
+               if (n->Online == false)\r
+               {\r
+                       // オフラインである\r
+                       ret = ERR_OFFLINE;\r
+               }\r
+               else\r
+               {\r
+                       // オフラインにする\r
+                       StopVirtualHost(n->Virtual);\r
+                       ReleaseVirtual(n->Virtual);\r
+                       n->Virtual = NULL;\r
+\r
+                       n->Online = false;\r
+               }\r
+       }\r
+       Unlock(n->lock);\r
+\r
+       NiWriteConfig(n);\r
+\r
+       return ret;\r
+}\r
+\r
+// ホストオプションの設定\r
+UINT NtSetHostOption(NAT *n, VH_OPTION *t)\r
+{\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       Lock(n->lock);\r
+       {\r
+               Copy(&n->Option, t, sizeof(VH_OPTION));\r
+       }\r
+       Unlock(n->lock);\r
+\r
+       SetVirtualHostOption(n->Virtual, t);\r
+\r
+       NiWriteConfig(n);\r
+\r
+       return ret;\r
+}\r
+\r
+// ホストオプションの取得\r
+UINT NtGetHostOption(NAT *n, VH_OPTION *t)\r
+{\r
+       UINT ret = ERR_NO_ERROR;\r
+\r
+       Lock(n->lock);\r
+       {\r
+               Copy(t, &n->Option, sizeof(VH_OPTION));\r
+       }\r
+       Unlock(n->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// 接続設定の設定\r
+UINT NtSetClientConfig(NAT *n, RPC_CREATE_LINK *t)\r
+{\r
+       Lock(n->lock);\r
+       {\r
+               if (n->ClientOption != NULL || n->ClientAuth != NULL)\r
+               {\r
+                       Free(n->ClientOption);\r
+                       CiFreeClientAuth(n->ClientAuth);\r
+               }\r
+\r
+               n->ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+               Copy(n->ClientOption, t->ClientOption, sizeof(CLIENT_OPTION));\r
+               n->ClientAuth = CopyClientAuth(t->ClientAuth);\r
+       }\r
+       Unlock(n->lock);\r
+\r
+       NiWriteConfig(n);\r
+\r
+       if (n->Online)\r
+       {\r
+               NtOffline(n, NULL);\r
+               NtOnline(n, NULL);\r
+       }\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// 接続設定の取得\r
+UINT NtGetClientConfig(NAT *n, RPC_CREATE_LINK *t)\r
+{\r
+       UINT err = ERR_NO_ERROR;\r
+\r
+       Lock(n->lock);\r
+       {\r
+               if (n->ClientOption == NULL || n->ClientAuth == NULL)\r
+               {\r
+                       err = ERR_ACCOUNT_NOT_PRESENT;\r
+               }\r
+               else\r
+               {\r
+                       FreeRpcCreateLink(t);\r
+\r
+                       Zero(t, sizeof(RPC_CREATE_LINK));\r
+                       t->ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+                       Copy(t->ClientOption, n->ClientOption, sizeof(CLIENT_OPTION));\r
+                       t->ClientAuth = CopyClientAuth(n->ClientAuth);\r
+               }\r
+       }\r
+       Unlock(n->lock);\r
+\r
+       return err;\r
+}\r
+\r
+// 状態の取得\r
+UINT NtGetStatus(NAT *n, RPC_NAT_STATUS *t)\r
+{\r
+       Lock(n->lock);\r
+       {\r
+               VH *v = n->Virtual;\r
+               FreeRpcNatStatus(t);\r
+               Zero(t, sizeof(RPC_NAT_STATUS));\r
+\r
+               LockVirtual(v);\r
+               {\r
+                       UINT i;\r
+\r
+                       LockList(v->NatTable);\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(v->NatTable);i++)\r
+                               {\r
+                                       NAT_ENTRY *e = LIST_DATA(v->NatTable, i);\r
+\r
+                                       switch (e->Protocol)\r
+                                       {\r
+                                       case NAT_TCP:\r
+                                               t->NumTcpSessions++;\r
+                                               break;\r
+\r
+                                       case NAT_UDP:\r
+                                               t->NumUdpSessions++;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+                       UnlockList(v->NatTable);\r
+\r
+                       t->NumDhcpClients = LIST_NUM(v->DhcpLeaseList);\r
+               }\r
+               UnlockVirtual(v);\r
+       }\r
+       Unlock(n->lock);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// 情報の取得\r
+UINT NtGetInfo(NAT *n, RPC_NAT_INFO *t)\r
+{\r
+       OS_INFO *info;\r
+       FreeRpcNatInfo(t);\r
+       Zero(t, sizeof(RPC_NAT_INFO));\r
+\r
+       StrCpy(t->NatProductName, sizeof(t->NatProductName), CEDAR_ROUTER_STR);\r
+       StrCpy(t->NatVersionString, sizeof(t->NatVersionString), n->Cedar->VerString);\r
+       StrCpy(t->NatBuildInfoString, sizeof(t->NatBuildInfoString), n->Cedar->BuildInfo);\r
+       t->NatVerInt = n->Cedar->Build;\r
+       t->NatBuildInt = n->Cedar->Build;\r
+\r
+       GetMachineName(t->NatHostName, sizeof(t->NatHostName));\r
+\r
+       info = GetOsInfo();\r
+\r
+       CopyOsInfo(&t->OsInfo, info);\r
+\r
+       GetMemInfo(&t->MemInfo);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// NAT リストの取得\r
+UINT NtEnumNatList(NAT *n, RPC_ENUM_NAT *t)\r
+{\r
+       UINT ret = ERR_NO_ERROR;\r
+       VH *v = NULL;\r
+\r
+       Lock(n->lock);\r
+       {\r
+               v = n->Virtual;\r
+\r
+               if (n->Online == false || v == NULL)\r
+               {\r
+                       ret = ERR_OFFLINE;\r
+               }\r
+               else\r
+               {\r
+                       LockVirtual(v);\r
+                       {\r
+                               if (v->Active == false)\r
+                               {\r
+                                       ret = ERR_OFFLINE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       FreeRpcEnumNat(t);\r
+                                       Zero(t, sizeof(RPC_ENUM_NAT));\r
+\r
+                                       LockList(v->NatTable);\r
+                                       {\r
+                                               UINT i;\r
+                                               t->NumItem = LIST_NUM(v->NatTable);\r
+                                               t->Items = ZeroMalloc(sizeof(RPC_ENUM_NAT_ITEM) * t->NumItem);\r
+\r
+                                               for (i = 0;i < t->NumItem;i++)\r
+                                               {\r
+                                                       NAT_ENTRY *nat = LIST_DATA(v->NatTable, i);\r
+                                                       RPC_ENUM_NAT_ITEM *e = &t->Items[i];\r
+\r
+                                                       e->Id = nat->Id;\r
+                                                       e->Protocol = nat->Protocol;\r
+                                                       e->SrcIp = nat->SrcIp;\r
+                                                       e->DestIp = nat->DestIp;\r
+                                                       e->SrcPort = nat->SrcPort;\r
+                                                       e->DestPort = nat->DestPort;\r
+\r
+                                                       e->CreatedTime = TickToTime(nat->CreatedTime);\r
+                                                       e->LastCommTime = TickToTime(nat->LastCommTime);\r
+\r
+                                                       IPToStr32(e->SrcHost, sizeof(e->SrcHost), e->SrcIp);\r
+                                                       IPToStr32(e->DestHost, sizeof(e->DestHost), e->DestIp);\r
+\r
+                                                       if (nat->Sock != NULL)\r
+                                                       {\r
+                                                               e->SendSize = nat->Sock->SendSize;\r
+                                                               e->RecvSize = nat->Sock->RecvSize;\r
+\r
+                                                               if (nat->Sock->Type == SOCK_TCP)\r
+                                                               {\r
+                                                                       StrCpy(e->DestHost, sizeof(e->DestHost), nat->Sock->RemoteHostname);\r
+                                                               }\r
+                                                       }\r
+\r
+                                                       e->TcpStatus = nat->TcpStatus;\r
+                                               }\r
+                                       }\r
+                                       UnlockList(v->NatTable);\r
+                               }\r
+                       }\r
+                       UnlockVirtual(v);\r
+               }\r
+       }\r
+       Unlock(n->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+UINT NtEnumDhcpList(NAT *n, RPC_ENUM_DHCP *t)\r
+{\r
+       UINT ret = ERR_NO_ERROR;\r
+       VH *v = NULL;\r
+\r
+       Lock(n->lock);\r
+       {\r
+               v = n->Virtual;\r
+\r
+               if (n->Online == false || v == NULL)\r
+               {\r
+                       ret = ERR_OFFLINE;\r
+               }\r
+               else\r
+               {\r
+                       LockVirtual(v);\r
+                       {\r
+                               if (v->Active == false)\r
+                               {\r
+                                       ret = ERR_OFFLINE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       FreeRpcEnumDhcp(t);\r
+                                       Zero(t, sizeof(RPC_ENUM_DHCP));\r
+\r
+                                       LockList(v->DhcpLeaseList);\r
+                                       {\r
+                                               UINT i;\r
+                                               t->NumItem = LIST_NUM(v->DhcpLeaseList);\r
+                                               t->Items = ZeroMalloc(sizeof(RPC_ENUM_DHCP_ITEM) * t->NumItem);\r
+\r
+                                               for (i = 0;i < t->NumItem;i++)\r
+                                               {\r
+                                                       DHCP_LEASE *dhcp = LIST_DATA(v->DhcpLeaseList, i);\r
+                                                       RPC_ENUM_DHCP_ITEM *e = &t->Items[i];\r
+\r
+                                                       e->Id = dhcp->Id;\r
+                                                       e->LeasedTime = TickToTime(dhcp->LeasedTime);\r
+                                                       e->ExpireTime = TickToTime(dhcp->ExpireTime);\r
+                                                       Copy(e->MacAddress, dhcp->MacAddress, 6);\r
+                                                       e->IpAddress = dhcp->IpAddress;\r
+                                                       e->Mask = dhcp->Mask;\r
+                                                       StrCpy(e->Hostname, sizeof(e->Hostname), dhcp->Hostname);\r
+                                               }\r
+                                       }\r
+                                       UnlockList(v->DhcpLeaseList);\r
+                               }\r
+                       }\r
+                       UnlockVirtual(v);\r
+               }\r
+       }\r
+       Unlock(n->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// VH_OPTION\r
+void InVhOption(VH_OPTION *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(VH_OPTION));\r
+       PackGetData2(p, "MacAddress", t->MacAddress, 6);\r
+       PackGetIp(p, "Ip", &t->Ip);\r
+       PackGetIp(p, "Mask", &t->Mask);\r
+       t->UseNat = PackGetBool(p, "UseNat");\r
+       t->Mtu = PackGetInt(p, "Mtu");\r
+       t->NatTcpTimeout = PackGetInt(p, "NatTcpTimeout");\r
+       t->NatUdpTimeout = PackGetInt(p, "NatUdpTimeout");\r
+       t->UseDhcp = PackGetBool(p, "UseDhcp");\r
+       PackGetIp(p, "DhcpLeaseIPStart", &t->DhcpLeaseIPStart);\r
+       PackGetIp(p, "DhcpLeaseIPEnd", &t->DhcpLeaseIPEnd);\r
+       PackGetIp(p, "DhcpSubnetMask", &t->DhcpSubnetMask);\r
+       t->DhcpExpireTimeSpan = PackGetInt(p, "DhcpExpireTimeSpan");\r
+       PackGetIp(p, "DhcpGatewayAddress", &t->DhcpGatewayAddress);\r
+       PackGetIp(p, "DhcpDnsServerAddress", &t->DhcpDnsServerAddress);\r
+       PackGetStr(p, "DhcpDomainName", t->DhcpDomainName, sizeof(t->DhcpDomainName));\r
+       t->SaveLog = PackGetBool(p, "SaveLog");\r
+       PackGetStr(p, "RpcHubName", t->HubName, sizeof(t->HubName));\r
+}\r
+void OutVhOption(PACK *p, VH_OPTION *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddData(p, "MacAddress", t->MacAddress, 6);\r
+       PackAddIp(p, "Ip", &t->Ip);\r
+       PackAddIp(p, "Mask", &t->Mask);\r
+       PackAddBool(p, "UseNat", t->UseNat);\r
+       PackAddInt(p, "Mtu", t->Mtu);\r
+       PackAddInt(p, "NatTcpTimeout", t->NatTcpTimeout);\r
+       PackAddInt(p, "NatUdpTimeout", t->NatUdpTimeout);\r
+       PackAddBool(p, "UseDhcp", t->UseDhcp);\r
+       PackAddIp(p, "DhcpLeaseIPStart", &t->DhcpLeaseIPStart);\r
+       PackAddIp(p, "DhcpLeaseIPEnd", &t->DhcpLeaseIPEnd);\r
+       PackAddIp(p, "DhcpSubnetMask", &t->DhcpSubnetMask);\r
+       PackAddInt(p, "DhcpExpireTimeSpan", t->DhcpExpireTimeSpan);\r
+       PackAddIp(p, "DhcpGatewayAddress", &t->DhcpGatewayAddress);\r
+       PackAddIp(p, "DhcpDnsServerAddress", &t->DhcpDnsServerAddress);\r
+       PackAddStr(p, "DhcpDomainName", t->DhcpDomainName);\r
+       PackAddBool(p, "SaveLog", t->SaveLog);\r
+       PackAddStr(p, "RpcHubName", t->HubName);\r
+}\r
+\r
+// RPC_ENUM_DHCP\r
+void InRpcEnumDhcp(RPC_ENUM_DHCP *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_DHCP));\r
+       t->NumItem = PackGetInt(p, "NumItem");\r
+       t->Items = ZeroMalloc(sizeof(RPC_ENUM_DHCP_ITEM) * t->NumItem);\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_DHCP_ITEM *e = &t->Items[i];\r
+\r
+               e->Id = PackGetIntEx(p, "Id", i);\r
+               e->LeasedTime = PackGetInt64Ex(p, "LeasedTime", i);\r
+               e->ExpireTime = PackGetInt64Ex(p, "ExpireTime", i);\r
+               PackGetDataEx2(p, "MacAddress", e->MacAddress, 6, i);\r
+               e->IpAddress = PackGetIp32Ex(p, "IpAddress", i);\r
+               e->Mask = PackGetIntEx(p, "Mask", i);\r
+               PackGetStrEx(p, "Hostname", e->Hostname, sizeof(e->Hostname), i);\r
+       }\r
+}\r
+void OutRpcEnumDhcp(PACK *p, RPC_ENUM_DHCP *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "NumItem", t->NumItem);\r
+       PackAddStr(p, "HubName", t->HubName);\r
+\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_DHCP_ITEM *e = &t->Items[i];\r
+\r
+               PackAddIntEx(p, "Id", e->Id, i, t->NumItem);\r
+               PackAddInt64Ex(p, "LeasedTime", e->LeasedTime, i, t->NumItem);\r
+               PackAddInt64Ex(p, "ExpireTime", e->ExpireTime, i, t->NumItem);\r
+               PackAddDataEx(p, "MacAddress", e->MacAddress, 6, i, t->NumItem);\r
+               PackAddIp32Ex(p, "IpAddress", e->IpAddress, i, t->NumItem);\r
+               PackAddIntEx(p, "Mask", e->Mask, i, t->NumItem);\r
+               PackAddStrEx(p, "Hostname", e->Hostname, i, t->NumItem);\r
+       }\r
+}\r
+void FreeRpcEnumDhcp(RPC_ENUM_DHCP *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Items);\r
+}\r
+\r
+// RPC_ENUM_NAT\r
+void InRpcEnumNat(RPC_ENUM_NAT *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_ENUM_NAT));\r
+       t->NumItem = PackGetInt(p, "NumItem");\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+       t->Items = ZeroMalloc(sizeof(RPC_ENUM_NAT_ITEM) * t->NumItem);\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_NAT_ITEM *e = &t->Items[i];\r
+\r
+               e->Id = PackGetIntEx(p, "Id", i);\r
+               e->Protocol = PackGetIntEx(p, "Protocol", i);\r
+               e->SrcIp = PackGetIntEx(p, "SrcIp", i);\r
+               PackGetStrEx(p, "SrcHost", e->SrcHost, sizeof(e->SrcHost), i);\r
+               e->SrcPort = PackGetIntEx(p, "SrcPort", i);\r
+               e->DestIp = PackGetIntEx(p, "DestIp", i);\r
+               PackGetStrEx(p, "DestHost", e->DestHost, sizeof(e->DestHost), i);\r
+               e->DestPort = PackGetIntEx(p, "DestPort", i);\r
+               e->CreatedTime = PackGetInt64Ex(p, "CreatedTime", i);\r
+               e->LastCommTime = PackGetInt64Ex(p, "LastCommTime", i);\r
+               e->SendSize = PackGetInt64Ex(p, "SendSize", i);\r
+               e->RecvSize = PackGetInt64Ex(p, "RecvSize", i);\r
+               e->TcpStatus = PackGetIntEx(p, "TcpStatus", i);\r
+       }\r
+}\r
+void OutRpcEnumNat(PACK *p, RPC_ENUM_NAT *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "NumItem", t->NumItem);\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       for (i = 0;i < t->NumItem;i++)\r
+       {\r
+               RPC_ENUM_NAT_ITEM *e = &t->Items[i];\r
+\r
+               PackAddIntEx(p, "Id", e->Id, i, t->NumItem);\r
+               PackAddIntEx(p, "Protocol", e->Protocol, i, t->NumItem);\r
+               PackAddIp32Ex(p, "SrcIp", e->SrcIp, i, t->NumItem);\r
+               PackAddStrEx(p, "SrcHost", e->SrcHost, i, t->NumItem);\r
+               PackAddIntEx(p, "SrcPort", e->SrcPort, i, t->NumItem);\r
+               PackAddIp32Ex(p, "DestIp", e->DestIp, i, t->NumItem);\r
+               PackAddStrEx(p, "DestHost", e->DestHost, i, t->NumItem);\r
+               PackAddIntEx(p, "DestPort", e->DestPort, i, t->NumItem);\r
+               PackAddInt64Ex(p, "CreatedTime", e->CreatedTime, i, t->NumItem);\r
+               PackAddInt64Ex(p, "LastCommTime", e->LastCommTime, i, t->NumItem);\r
+               PackAddInt64Ex(p, "SendSize", e->SendSize, i, t->NumItem);\r
+               PackAddInt64Ex(p, "RecvSize", e->RecvSize, i, t->NumItem);\r
+               PackAddIntEx(p, "TcpStatus", e->TcpStatus, i, t->NumItem);\r
+       }\r
+}\r
+void FreeRpcEnumNat(RPC_ENUM_NAT *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(t->Items);\r
+}\r
+\r
+// RPC_NAT_INFO\r
+void InRpcNatInfo(RPC_NAT_INFO *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_NAT_INFO));\r
+       PackGetStr(p, "NatProductName", t->NatProductName, sizeof(t->NatProductName));\r
+       PackGetStr(p, "NatVersionString", t->NatVersionString, sizeof(t->NatVersionString));\r
+       PackGetStr(p, "NatBuildInfoString", t->NatBuildInfoString, sizeof(t->NatBuildInfoString));\r
+       t->NatVerInt = PackGetInt(p, "NatVerInt");\r
+       t->NatBuildInt = PackGetInt(p, "NatBuildInt");\r
+       PackGetStr(p, "NatHostName", t->NatHostName, sizeof(t->NatHostName));\r
+       InRpcOsInfo(&t->OsInfo, p);\r
+       InRpcMemInfo(&t->MemInfo, p);\r
+}\r
+void OutRpcNatInfo(PACK *p, RPC_NAT_INFO *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "NatProductName", t->NatProductName);\r
+       PackAddStr(p, "NatVersionString", t->NatVersionString);\r
+       PackAddStr(p, "NatBuildInfoString", t->NatBuildInfoString);\r
+       PackAddInt(p, "NatVerInt", t->NatVerInt);\r
+       PackAddInt(p, "NatBuildInt", t->NatBuildInt);\r
+       PackAddStr(p, "NatHostName", t->NatHostName);\r
+       OutRpcOsInfo(p, &t->OsInfo);\r
+       OutRpcMemInfo(p, &t->MemInfo);\r
+}\r
+void FreeRpcNatInfo(RPC_NAT_INFO *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeRpcOsInfo(&t->OsInfo);\r
+}\r
+\r
+// RPC_NAT_STATUS\r
+void InRpcNatStatus(RPC_NAT_STATUS *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_NAT_STATUS));\r
+       t->NumTcpSessions = PackGetInt(p, "NumTcpSessions");\r
+       t->NumUdpSessions = PackGetInt(p, "NumUdpSessions");\r
+       t->NumDhcpClients = PackGetInt(p, "NumDhcpClients");\r
+       PackGetStr(p, "HubName", t->HubName, sizeof(t->HubName));\r
+}\r
+void OutRpcNatStatus(PACK *p, RPC_NAT_STATUS *t)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "HubName", t->HubName);\r
+       PackAddInt(p, "NumTcpSessions", t->NumTcpSessions);\r
+       PackAddInt(p, "NumUdpSessions", t->NumUdpSessions);\r
+       PackAddInt(p, "NumDhcpClients", t->NumDhcpClients);\r
+}\r
+void FreeRpcNatStatus(RPC_NAT_STATUS *t)\r
+{\r
+}\r
+\r
+// RPC_DUMMY\r
+void InRpcDummy(RPC_DUMMY *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(RPC_DUMMY));\r
+       t->DummyValue = PackGetInt(p, "DummyValue");\r
+}\r
+void OutRpcDummy(PACK *p, RPC_DUMMY *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "DummyValue", t->DummyValue);\r
+}\r
+\r
+// 管理用メインプロシージャ\r
+void NiAdminMain(NAT *n, SOCK *s)\r
+{\r
+       RPC *r;\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (n == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = NewPack();\r
+       HttpServerSend(s, p);\r
+       FreePack(p);\r
+\r
+       r = StartRpcServer(s, NiRpcServer, n);\r
+\r
+       RpcServer(r);\r
+\r
+       RpcFree(r);\r
+}\r
+\r
+// 管理スレッド\r
+void NiAdminThread(THREAD *thread, void *param)\r
+{\r
+       NAT_ADMIN *a = (NAT_ADMIN *)param;\r
+       NAT *n;\r
+       SOCK *s;\r
+       UCHAR random[SHA1_SIZE];\r
+       UINT err;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 乱数生成\r
+       Rand(random, sizeof(random));\r
+\r
+       a->Thread = thread;\r
+       AddRef(a->Thread->ref);\r
+       s = a->Sock;\r
+       AddRef(s->ref);\r
+\r
+       n = a->Nat;\r
+\r
+       LockList(n->AdminList);\r
+       {\r
+               Add(n->AdminList, a);\r
+       }\r
+       UnlockList(n->AdminList);\r
+\r
+       NoticeThreadInit(thread);\r
+\r
+       err = ERR_AUTH_FAILED;\r
+\r
+       if (StartSSL(s, n->AdminX, n->AdminK))\r
+       {\r
+               PACK *p;\r
+\r
+               // 乱数を送信する\r
+               p = NewPack();\r
+               PackAddData(p, "auth_random", random, sizeof(random));\r
+\r
+               if (HttpServerSend(s, p))\r
+               {\r
+                       PACK *p;\r
+                       // パスワードを受け取る\r
+                       p = HttpServerRecv(s);\r
+                       if (p != NULL)\r
+                       {\r
+                               UCHAR secure_password[SHA1_SIZE];\r
+                               UCHAR secure_check[SHA1_SIZE];\r
+\r
+                               if (PackGetData2(p, "secure_password", secure_password, sizeof(secure_password)))\r
+                               {\r
+                                       SecurePassword(secure_check, n->HashedPassword, random);\r
+\r
+                                       if (Cmp(secure_check, secure_password, SHA1_SIZE) == 0)\r
+                                       {\r
+                                               UCHAR test[SHA1_SIZE];\r
+                                               // パスワード一致\r
+                                               Hash(test, "", 0, true);\r
+                                               SecurePassword(test, test, random);\r
+\r
+#if    0\r
+                                               if (Cmp(test, secure_check, SHA1_SIZE) == 0 && s->RemoteIP.addr[0] != 127)\r
+                                               {\r
+                                                       // 空白パスワードは外部から接続できない\r
+                                                       err = ERR_NULL_PASSWORD_LOCAL_ONLY;\r
+                                               }\r
+                                               else\r
+#endif\r
+\r
+                                               {\r
+                                                       // 接続成功\r
+                                                       err = ERR_NO_ERROR;\r
+                                                       NiAdminMain(n, s);\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               FreePack(p);\r
+                       }\r
+               }\r
+\r
+               FreePack(p);\r
+\r
+               if (err != ERR_NO_ERROR)\r
+               {\r
+                       p = PackError(err);\r
+                       HttpServerSend(s, p);\r
+                       FreePack(p);\r
+               }\r
+       }\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+}\r
+\r
+// 管理ポート Listen スレッド\r
+void NiListenThread(THREAD *thread, void *param)\r
+{\r
+       NAT *n = (NAT *)param;\r
+       SOCK *a;\r
+       UINT i;\r
+       bool b = false;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 管理リストの初期化\r
+       n->AdminList = NewList(NULL);\r
+\r
+       while (true)\r
+       {\r
+               a = Listen(DEFAULT_NAT_ADMIN_PORT);\r
+               if (b == false)\r
+               {\r
+                       b = true;\r
+                       NoticeThreadInit(thread);\r
+               }\r
+               if (a != NULL)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               Wait(n->HaltEvent, NAT_ADMIN_PORT_LISTEN_INTERVAL);\r
+               if (n->Halt)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       n->AdminListenSock = a;\r
+       AddRef(a->ref);\r
+\r
+       // 待ち受け\r
+       while (true)\r
+       {\r
+               SOCK *s = Accept(a);\r
+               THREAD *t;\r
+               NAT_ADMIN *admin;\r
+               if (s == NULL)\r
+               {\r
+                       break;\r
+               }\r
+               if (n->Halt)\r
+               {\r
+                       ReleaseSock(s);\r
+                       break;\r
+               }\r
+\r
+               admin = ZeroMalloc(sizeof(NAT_ADMIN));\r
+               admin->Nat = n;\r
+               admin->Sock = s;\r
+               t = NewThread(NiAdminThread, admin);\r
+               WaitThreadInit(t);\r
+               ReleaseThread(t);\r
+       }\r
+\r
+       // すべての管理コネクションを切断\r
+       LockList(n->AdminList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(n->AdminList);i++)\r
+               {\r
+                       NAT_ADMIN *a = LIST_DATA(n->AdminList, i);\r
+                       Disconnect(a->Sock);\r
+                       WaitThread(a->Thread, INFINITE);\r
+                       ReleaseThread(a->Thread);\r
+                       ReleaseSock(a->Sock);\r
+                       Free(a);\r
+               }\r
+       }\r
+       UnlockList(n->AdminList);\r
+\r
+       ReleaseList(n->AdminList);\r
+\r
+       ReleaseSock(a);\r
+}\r
+\r
+// 管理コマンド受付初期化\r
+void NiInitAdminAccept(NAT *n)\r
+{\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = NewThread(NiListenThread, n);\r
+       WaitThreadInit(t);\r
+       n->AdminAcceptThread = t;\r
+}\r
+\r
+// 管理コマンド受付終了\r
+void NiFreeAdminAccept(NAT *n)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       n->Halt = true;\r
+       Disconnect(n->AdminListenSock);\r
+       Set(n->HaltEvent);\r
+\r
+       while (true)\r
+       {\r
+               if (WaitThread(n->AdminAcceptThread, 1000) == false)\r
+               {\r
+                       Disconnect(n->AdminListenSock);\r
+               }\r
+               else\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+       ReleaseThread(n->AdminAcceptThread);\r
+\r
+       ReleaseSock(n->AdminListenSock);\r
+}\r
+\r
+// ダイナミック仮想 HUB でサポートされていない DHCP オプションをクリアする\r
+void NiClearUnsupportedVhOptionForDynamicHub(VH_OPTION *o, bool initial)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o->UseNat = false;\r
+\r
+       if (initial)\r
+       {\r
+               Zero(&o->DhcpGatewayAddress, sizeof(IP));\r
+               Zero(&o->DhcpDnsServerAddress, sizeof(IP));\r
+               StrCpy(o->DhcpDomainName, sizeof(o->DhcpDomainName), "");\r
+       }\r
+}\r
+\r
+// 仮想ホストのオプションを初期化する\r
+void NiSetDefaultVhOption(NAT *n, VH_OPTION *o)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(o, sizeof(VH_OPTION));\r
+       GenMacAddress(o->MacAddress);\r
+\r
+       // 仮想 IP を 192.168.30.1/24 にする\r
+       SetIP(&o->Ip, 192, 168, 30, 1);\r
+       SetIP(&o->Mask, 255, 255, 255, 0);\r
+       o->UseNat = true;\r
+       o->Mtu = 1500;\r
+       o->NatTcpTimeout = 7200;\r
+       o->NatUdpTimeout = 60;\r
+       o->UseDhcp = true;\r
+       SetIP(&o->DhcpLeaseIPStart, 192, 168, 30, 10);\r
+       SetIP(&o->DhcpLeaseIPEnd, 192, 168, 30, 200);\r
+       SetIP(&o->DhcpSubnetMask, 255, 255, 255, 0);\r
+       o->DhcpExpireTimeSpan = 7200;\r
+       o->SaveLog = true;\r
+\r
+       SetIP(&o->DhcpGatewayAddress, 192, 168, 30, 1);\r
+       SetIP(&o->DhcpDnsServerAddress, 192, 168, 30, 1);\r
+\r
+       GetDomainName(o->DhcpDomainName, sizeof(o->DhcpDomainName));\r
+}\r
+\r
+// NAT の設定を初期状態にする\r
+void NiInitDefaultConfig(NAT *n)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 仮想ホストオプション初期化\r
+       NiSetDefaultVhOption(n, &n->Option);\r
+\r
+       // 管理用ポート初期化\r
+       n->AdminPort = DEFAULT_NAT_ADMIN_PORT;\r
+\r
+       // オフライン\r
+       n->Online = false;\r
+\r
+       // ログを保存\r
+       n->Option.SaveLog = true;\r
+}\r
+\r
+// NAT の設定の初期化\r
+void NiInitConfig(NAT *n)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 初期状態\r
+       NiInitDefaultConfig(n);\r
+}\r
+\r
+// 仮想ホストオプションの読み込み (拡張)\r
+void NiLoadVhOptionEx(VH_OPTION *o, FOLDER *root)\r
+{\r
+       FOLDER *host, *nat, *dhcp;\r
+       char mac_address[MAX_SIZE];\r
+       // 引数チェック\r
+       if (o == NULL || root == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       host = CfgGetFolder(root, "VirtualHost");\r
+       nat = CfgGetFolder(root, "VirtualRouter");\r
+       dhcp = CfgGetFolder(root, "VirtualDhcpServer");\r
+\r
+       Zero(o, sizeof(VH_OPTION));\r
+\r
+       GenMacAddress(o->MacAddress);\r
+       if (CfgGetStr(host, "VirtualHostMacAddress", mac_address, sizeof(mac_address)))\r
+       {\r
+               BUF *b = StrToBin(mac_address);\r
+               if (b != NULL)\r
+               {\r
+                       if (b->Size == 6)\r
+                       {\r
+                               Copy(o->MacAddress, b->Buf, 6);\r
+                       }\r
+               }\r
+               FreeBuf(b);\r
+       }\r
+       CfgGetIp(host, "VirtualHostIp", &o->Ip);\r
+       CfgGetIp(host, "VirtualHostIpSubnetMask", &o->Mask);\r
+\r
+       o->UseNat = CfgGetBool(nat, "NatEnabled");\r
+       o->Mtu = CfgGetInt(nat, "NatMtu");\r
+       o->NatTcpTimeout = CfgGetInt(nat, "NatTcpTimeout");\r
+       o->NatUdpTimeout = CfgGetInt(nat, "NatUdpTimeout");\r
+\r
+       o->UseDhcp = CfgGetBool(dhcp, "DhcpEnabled");\r
+       CfgGetIp(dhcp, "DhcpLeaseIPStart", &o->DhcpLeaseIPStart);\r
+       CfgGetIp(dhcp, "DhcpLeaseIPEnd", &o->DhcpLeaseIPEnd);\r
+       CfgGetIp(dhcp, "DhcpSubnetMask", &o->DhcpSubnetMask);\r
+       o->DhcpExpireTimeSpan = CfgGetInt(dhcp, "DhcpExpireTimeSpan");\r
+       CfgGetIp(dhcp, "DhcpGatewayAddress", &o->DhcpGatewayAddress);\r
+       CfgGetIp(dhcp, "DhcpDnsServerAddress", &o->DhcpDnsServerAddress);\r
+       CfgGetStr(dhcp, "DhcpDomainName", o->DhcpDomainName, sizeof(o->DhcpDomainName));\r
+\r
+       Trim(o->DhcpDomainName);\r
+       if (StrLen(o->DhcpDomainName) == 0)\r
+       {\r
+               //GetDomainName(o->DhcpDomainName, sizeof(o->DhcpDomainName));\r
+       }\r
+\r
+       o->SaveLog = CfgGetBool(root, "SaveLog");\r
+}\r
+\r
+// 仮想ホストオプションの読み込み\r
+void NiLoadVhOption(NAT *n, FOLDER *root)\r
+{\r
+       VH_OPTION *o;\r
+       FOLDER *host, *nat, *dhcp;\r
+       char mac_address[MAX_SIZE];\r
+       // 引数チェック\r
+       if (n == NULL || root == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       host = CfgGetFolder(root, "VirtualHost");\r
+       nat = CfgGetFolder(root, "VirtualRouter");\r
+       dhcp = CfgGetFolder(root, "VirtualDhcpServer");\r
+\r
+       o = &n->Option;\r
+       Zero(o, sizeof(VH_OPTION));\r
+\r
+       GenMacAddress(o->MacAddress);\r
+       if (CfgGetStr(host, "VirtualHostMacAddress", mac_address, sizeof(mac_address)))\r
+       {\r
+               BUF *b = StrToBin(mac_address);\r
+               if (b != NULL)\r
+               {\r
+                       if (b->Size == 6)\r
+                       {\r
+                               Copy(o->MacAddress, b->Buf, 6);\r
+                       }\r
+               }\r
+               FreeBuf(b);\r
+       }\r
+       CfgGetIp(host, "VirtualHostIp", &o->Ip);\r
+       CfgGetIp(host, "VirtualHostIpSubnetMask", &o->Mask);\r
+\r
+       o->UseNat = CfgGetBool(nat, "NatEnabled");\r
+       o->Mtu = CfgGetInt(nat, "NatMtu");\r
+       o->NatTcpTimeout = CfgGetInt(nat, "NatTcpTimeout");\r
+       o->NatUdpTimeout = CfgGetInt(nat, "NatUdpTimeout");\r
+\r
+       o->UseDhcp = CfgGetBool(dhcp, "DhcpEnabled");\r
+       CfgGetIp(dhcp, "DhcpLeaseIPStart", &o->DhcpLeaseIPStart);\r
+       CfgGetIp(dhcp, "DhcpLeaseIPEnd", &o->DhcpLeaseIPEnd);\r
+       CfgGetIp(dhcp, "DhcpSubnetMask", &o->DhcpSubnetMask);\r
+       o->DhcpExpireTimeSpan = CfgGetInt(dhcp, "DhcpExpireTimeSpan");\r
+       CfgGetIp(dhcp, "DhcpGatewayAddress", &o->DhcpGatewayAddress);\r
+       CfgGetIp(dhcp, "DhcpDnsServerAddress", &o->DhcpDnsServerAddress);\r
+       CfgGetStr(dhcp, "DhcpDomainName", o->DhcpDomainName, sizeof(o->DhcpDomainName));\r
+\r
+       o->SaveLog = CfgGetBool(root, "SaveLog");\r
+}\r
+\r
+// VPN サーバーからの接続オプションの読み込み\r
+void NiLoadClientData(NAT *n, FOLDER *root)\r
+{\r
+       FOLDER *co, *ca;\r
+       // 引数チェック\r
+       if (n == NULL || root == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       co = CfgGetFolder(root, "VpnClientOption");\r
+       ca = CfgGetFolder(root, "VpnClientAuth");\r
+       if (co == NULL || ca == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       n->ClientOption = CiLoadClientOption(co);\r
+       n->ClientAuth = CiLoadClientAuth(ca);\r
+}\r
+\r
+// VPN サーバーへの接続オプションの書き込み\r
+void NiWriteClientData(NAT *n, FOLDER *root)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL || root == NULL || n->ClientOption == NULL || n->ClientAuth == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CiWriteClientOption(CfgCreateFolder(root, "VpnClientOption"), n->ClientOption);\r
+       CiWriteClientAuth(CfgCreateFolder(root, "VpnClientAuth"), n->ClientAuth);\r
+}\r
+\r
+// 仮想ホストオプションの書き込み (拡張)\r
+void NiWriteVhOptionEx(VH_OPTION *o, FOLDER *root)\r
+{\r
+       FOLDER *host, *nat, *dhcp;\r
+       char mac_address[MAX_SIZE];\r
+       // 引数チェック\r
+       if (o == NULL || root == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       host = CfgCreateFolder(root, "VirtualHost");\r
+       nat = CfgCreateFolder(root, "VirtualRouter");\r
+       dhcp = CfgCreateFolder(root, "VirtualDhcpServer");\r
+\r
+       MacToStr(mac_address, sizeof(mac_address), o->MacAddress);\r
+       CfgAddStr(host, "VirtualHostMacAddress", mac_address);\r
+       CfgAddIp(host, "VirtualHostIp", &o->Ip);\r
+       CfgAddIp(host, "VirtualHostIpSubnetMask", &o->Mask);\r
+\r
+       CfgAddBool(nat, "NatEnabled", o->UseNat);\r
+       CfgAddInt(nat, "NatMtu", o->Mtu);\r
+       CfgAddInt(nat, "NatTcpTimeout", o->NatTcpTimeout);\r
+       CfgAddInt(nat, "NatUdpTimeout", o->NatUdpTimeout);\r
+\r
+       CfgAddBool(dhcp, "DhcpEnabled", o->UseDhcp);\r
+       CfgAddIp(dhcp, "DhcpLeaseIPStart", &o->DhcpLeaseIPStart);\r
+       CfgAddIp(dhcp, "DhcpLeaseIPEnd", &o->DhcpLeaseIPEnd);\r
+       CfgAddIp(dhcp, "DhcpSubnetMask", &o->DhcpSubnetMask);\r
+       CfgAddInt(dhcp, "DhcpExpireTimeSpan", o->DhcpExpireTimeSpan);\r
+       CfgAddIp(dhcp, "DhcpGatewayAddress", &o->DhcpGatewayAddress);\r
+       CfgAddIp(dhcp, "DhcpDnsServerAddress", &o->DhcpDnsServerAddress);\r
+       CfgAddStr(dhcp, "DhcpDomainName", o->DhcpDomainName);\r
+\r
+       CfgAddBool(root, "SaveLog", o->SaveLog);\r
+}\r
+\r
+// 仮想ホストオプションの書き込み\r
+void NiWriteVhOption(NAT *n, FOLDER *root)\r
+{\r
+       VH_OPTION *o;\r
+       FOLDER *host, *nat, *dhcp;\r
+       char mac_address[MAX_SIZE];\r
+       // 引数チェック\r
+       if (n == NULL || root == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       host = CfgCreateFolder(root, "VirtualHost");\r
+       nat = CfgCreateFolder(root, "VirtualRouter");\r
+       dhcp = CfgCreateFolder(root, "VirtualDhcpServer");\r
+\r
+       o = &n->Option;\r
+\r
+       MacToStr(mac_address, sizeof(mac_address), o->MacAddress);\r
+       CfgAddStr(host, "VirtualHostMacAddress", mac_address);\r
+       CfgAddIp(host, "VirtualHostIp", &o->Ip);\r
+       CfgAddIp(host, "VirtualHostIpSubnetMask", &o->Mask);\r
+\r
+       CfgAddBool(nat, "NatEnabled", o->UseNat);\r
+       CfgAddInt(nat, "NatMtu", o->Mtu);\r
+       CfgAddInt(nat, "NatTcpTimeout", o->NatTcpTimeout);\r
+       CfgAddInt(nat, "NatUdpTimeout", o->NatUdpTimeout);\r
+\r
+       CfgAddBool(dhcp, "DhcpEnabled", o->UseDhcp);\r
+       CfgAddIp(dhcp, "DhcpLeaseIPStart", &o->DhcpLeaseIPStart);\r
+       CfgAddIp(dhcp, "DhcpLeaseIPEnd", &o->DhcpLeaseIPEnd);\r
+       CfgAddIp(dhcp, "DhcpSubnetMask", &o->DhcpSubnetMask);\r
+       CfgAddInt(dhcp, "DhcpExpireTimeSpan", o->DhcpExpireTimeSpan);\r
+       CfgAddIp(dhcp, "DhcpGatewayAddress", &o->DhcpGatewayAddress);\r
+       CfgAddIp(dhcp, "DhcpDnsServerAddress", &o->DhcpDnsServerAddress);\r
+       CfgAddStr(dhcp, "DhcpDomainName", o->DhcpDomainName);\r
+\r
+       CfgAddBool(root, "SaveLog", o->SaveLog);\r
+}\r
+\r
+// 設定ファイルを読み込む\r
+bool NiLoadConfig(NAT *n, FOLDER *root)\r
+{\r
+       FOLDER *host;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (n == NULL || root == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       host = CfgGetFolder(root, "VirtualHost");\r
+       if (host == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       CfgGetByte(root, "HashedPassword", n->HashedPassword, sizeof(n->HashedPassword));\r
+       n->AdminPort = CfgGetInt(root, "AdminPort");\r
+       n->Online = CfgGetBool(root, "Online");\r
+\r
+       b = CfgGetBuf(root, "AdminCert");\r
+       if (b != NULL)\r
+       {\r
+               n->AdminX = BufToX(b, false);\r
+               FreeBuf(b);\r
+       }\r
+\r
+       b = CfgGetBuf(root, "AdminKey");\r
+       if (b != NULL)\r
+       {\r
+               n->AdminK = BufToK(b, true, false, NULL);\r
+               FreeBuf(b);\r
+       }\r
+\r
+       NiLoadVhOption(n, root);\r
+\r
+       NiLoadClientData(n, root);\r
+\r
+       return true;\r
+}\r
+\r
+// 設定をファイルに書き込む\r
+void NiWriteConfig(NAT *n)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(n->lock);\r
+       {\r
+               FOLDER *root = CfgCreateFolder(NULL, TAG_ROOT);\r
+               BUF *b;\r
+\r
+               // 証明書\r
+               b = XToBuf(n->AdminX, false);\r
+               CfgAddBuf(root, "AdminCert", b);\r
+               FreeBuf(b);\r
+\r
+               // 秘密鍵\r
+               b = KToBuf(n->AdminK, false, NULL);\r
+               CfgAddBuf(root, "AdminKey", b);\r
+               FreeBuf(b);\r
+\r
+               // パスワード\r
+               CfgAddByte(root, "HashedPassword", n->HashedPassword, sizeof(n->HashedPassword));\r
+               CfgAddInt(root, "AdminPort", n->AdminPort);\r
+               CfgAddBool(root, "Online", n->Online);\r
+\r
+               // 仮想ホストオプション\r
+               NiWriteVhOption(n, root);\r
+\r
+               // 接続オプション\r
+               if (n->ClientOption != NULL && n->ClientAuth != NULL)\r
+               {\r
+                       NiWriteClientData(n, root);\r
+               }\r
+\r
+               SaveCfgRw(n->CfgRw, root);\r
+               CfgDeleteFolder(root);\r
+       }\r
+       Unlock(n->lock);\r
+}\r
+\r
+// NAT の設定の解放\r
+void NiFreeConfig(NAT *n)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 最新の設定の書き込み\r
+       NiWriteConfig(n);\r
+\r
+       // 設定 R/W の解放\r
+       FreeCfgRw(n->CfgRw);\r
+       n->CfgRw = NULL;\r
+\r
+       Free(n->ClientOption);\r
+       CiFreeClientAuth(n->ClientAuth);\r
+\r
+       FreeX(n->AdminX);\r
+       FreeK(n->AdminK);\r
+}\r
+\r
+// NAT の作成\r
+NAT *NiNewNatEx(SNAT *snat, VH_OPTION *o)\r
+{\r
+       NAT *n = ZeroMalloc(sizeof(NAT));\r
+\r
+       n->lock = NewLock();\r
+       Hash(n->HashedPassword, "", 0, true);\r
+       n->HaltEvent = NewEvent();\r
+\r
+       //n->Cedar = NewCedar(NULL, NULL);\r
+\r
+       n->SecureNAT = snat;\r
+\r
+       // 優先順位を上げる\r
+       //OSSetHighPriority();\r
+\r
+       // 設定の初期化\r
+       NiInitConfig(n);\r
+\r
+#if    0\r
+       // 仮想ホストの動作を開始\r
+       if (n->Online && n->ClientOption != NULL)\r
+       {\r
+               n->Virtual = NewVirtualHostEx(n->Cedar, n->ClientOption, n->ClientAuth, &n->Option, n);\r
+       }\r
+       else\r
+       {\r
+               n->Online = false;\r
+               n->Virtual = NULL;\r
+       }\r
+#else\r
+       n->Virtual = NewVirtualHostEx(n->Cedar, NULL, NULL, o, n);\r
+       n->Online = true;\r
+#endif\r
+\r
+       // 管理コマンド開始\r
+       //NiInitAdminAccept(n);\r
+\r
+       return n;\r
+}\r
+NAT *NiNewNat()\r
+{\r
+       return NiNewNatEx(NULL, NULL);\r
+}\r
+\r
+// NAT の解放\r
+void NiFreeNat(NAT *n)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 管理コマンド終了\r
+       //NiFreeAdminAccept(n);\r
+\r
+       // 仮想ホストが動作中の場合は停止\r
+       Lock(n->lock);\r
+       {\r
+               if (n->Virtual != NULL)\r
+               {\r
+                       StopVirtualHost(n->Virtual);\r
+                       ReleaseVirtual(n->Virtual);\r
+                       n->Virtual = NULL;\r
+               }\r
+       }\r
+       Unlock(n->lock);\r
+\r
+       // 設定の解放\r
+       NiFreeConfig(n);\r
+\r
+       // オブジェクトの削除\r
+       ReleaseCedar(n->Cedar);\r
+       ReleaseEvent(n->HaltEvent);\r
+       DeleteLock(n->lock);\r
+\r
+       Free(n);\r
+}\r
+\r
+// NAT の停止\r
+void NtStopNat()\r
+{\r
+       Lock(nat_lock);\r
+       {\r
+               if (nat != NULL)\r
+               {\r
+                       NiFreeNat(nat);\r
+                       nat = NULL;\r
+               }\r
+       }\r
+       Unlock(nat_lock);\r
+}\r
+\r
+// NAT の開始\r
+void NtStartNat()\r
+{\r
+       Lock(nat_lock);\r
+       {\r
+               if (nat == NULL)\r
+               {\r
+                       nat = NiNewNat();\r
+               }\r
+       }\r
+       Unlock(nat_lock);\r
+}\r
+\r
+// NtXxx 関数の初期化\r
+void NtInit()\r
+{\r
+       if (nat_lock != NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       nat_lock = NewLock();\r
+}\r
+\r
+// NtXxx 関数の解放\r
+void NtFree()\r
+{\r
+       if (nat_lock == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DeleteLock(nat_lock);\r
+       nat_lock = NULL;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Nat.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Nat.h
new file mode 100644 (file)
index 0000000..6766e51
--- /dev/null
@@ -0,0 +1,281 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Nat.h\r
+// Nat.c のヘッダ\r
+\r
+#ifndef        NAT_H\r
+#define        NAT_H\r
+\r
+// 定数\r
+#define        NAT_CONFIG_FILE_NAME                    "@vpn_router.config"    // NAT 設定ファイル\r
+#define        DEFAULT_NAT_ADMIN_PORT                  2828            // デフォルトの管理用ポート番号\r
+#define        NAT_ADMIN_PORT_LISTEN_INTERVAL  1000            // 管理用ポートを開こうとする間隔\r
+#define        NAT_FILE_SAVE_INTERVAL                  (30 * 1000)     // 保存間隔\r
+\r
+\r
+// NAT オブジェクト\r
+struct NAT\r
+{\r
+       LOCK *lock;                                                     // ロック\r
+       UCHAR HashedPassword[SHA1_SIZE];        // 管理用パスワード\r
+       VH_OPTION Option;                                       // オプション\r
+       CEDAR *Cedar;                                           // Cedar\r
+       UINT AdminPort;                                         // 管理用ポート番号\r
+       bool Online;                                            // オンライン フラグ\r
+       VH *Virtual;                                            // 仮想ホストオブジェクト\r
+       CLIENT_OPTION *ClientOption;            // クライアントオプション\r
+       CLIENT_AUTH *ClientAuth;                        // クライアント認証データ\r
+       CFG_RW *CfgRw;                                          // Config ファイル R/W\r
+       THREAD *AdminAcceptThread;                      // 管理用コネクション受付スレッド\r
+       SOCK *AdminListenSock;                          // 管理ポートソケット\r
+       EVENT *HaltEvent;                                       // 停止イベント\r
+       volatile bool Halt;                                     // 停止フラグ\r
+       LIST *AdminList;                                        // 管理スレッドリスト\r
+       X *AdminX;                                                      // 管理用サーバー証明書\r
+       K *AdminK;                                                      // 管理用サーバー秘密鍵\r
+       SNAT *SecureNAT;                                        // SecureNAT オブジェクト\r
+};\r
+\r
+// NAT 管理コネクション\r
+struct NAT_ADMIN\r
+{\r
+       NAT *Nat;                                                       // NAT\r
+       SOCK *Sock;                                                     // ソケット\r
+       THREAD *Thread;                                         // スレッド\r
+};\r
+\r
+// RPC_DUMMY\r
+struct RPC_DUMMY\r
+{\r
+       UINT DummyValue;\r
+};\r
+\r
+// RPC_NAT_STATUS\r
+struct RPC_NAT_STATUS\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                      // HUB 名\r
+       UINT NumTcpSessions;                                            // TCP セッション数\r
+       UINT NumUdpSessions;                                            // UDP セッション数\r
+       UINT NumDhcpClients;                                            // DHCP クライアント数\r
+};\r
+\r
+// RPC_NAT_INFO *\r
+struct RPC_NAT_INFO\r
+{\r
+       char NatProductName[128];                                       // サーバー製品名\r
+       char NatVersionString[128];                                     // サーバーバージョン文字列\r
+       char NatBuildInfoString[128];                           // サーバービルド情報文字列\r
+       UINT NatVerInt;                                                         // サーバーバージョン整数値\r
+       UINT NatBuildInt;                                                       // サーバービルド番号整数値\r
+       char NatHostName[MAX_HOST_NAME_LEN + 1];        // サーバーホスト名\r
+       OS_INFO OsInfo;                                                         // OS 情報\r
+       MEMINFO MemInfo;                                                        // メモリ情報\r
+};\r
+\r
+// RPC_ENUM_NAT_ITEM\r
+struct RPC_ENUM_NAT_ITEM\r
+{\r
+       UINT Id;                                                                        // ID\r
+       UINT Protocol;                                                          // プロトコル\r
+       UINT SrcIp;                                                                     // 接続元 IP アドレス\r
+       char SrcHost[MAX_HOST_NAME_LEN + 1];            // 接続元ホスト名\r
+       UINT SrcPort;                                                           // 接続元ポート番号\r
+       UINT DestIp;                                                            // 接続先 IP アドレス\r
+       char DestHost[MAX_HOST_NAME_LEN + 1];           // 接続先ホスト名\r
+       UINT DestPort;                                                          // 接続先ポート番号\r
+       UINT64 CreatedTime;                                                     // 接続時刻\r
+       UINT64 LastCommTime;                                            // 最終通信時刻\r
+       UINT64 SendSize;                                                        // 送信サイズ\r
+       UINT64 RecvSize;                                                        // 受信サイズ\r
+       UINT TcpStatus;                                                         // TCP 状態\r
+};\r
+\r
+// RPC_ENUM_NAT *\r
+struct RPC_ENUM_NAT\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                      // HUB 名\r
+       UINT NumItem;                                                           // アイテム数\r
+       RPC_ENUM_NAT_ITEM *Items;                                       // アイテム\r
+};\r
+\r
+// RPC_ENUM_DHCP_ITEM\r
+struct RPC_ENUM_DHCP_ITEM\r
+{\r
+       UINT Id;                                                                        // ID\r
+       UINT64 LeasedTime;                                                      // リース時刻\r
+       UINT64 ExpireTime;                                                      // 有効期限\r
+       UCHAR MacAddress[6];                                            // MAC アドレス\r
+       UCHAR Padding[2];                                                       // パディング\r
+       UINT IpAddress;                                                         // IP アドレス\r
+       UINT Mask;                                                                      // サブネットマスク\r
+       char Hostname[MAX_HOST_NAME_LEN + 1];           // ホスト名\r
+};\r
+\r
+// RPC_ENUM_DHCP *\r
+struct RPC_ENUM_DHCP\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                      // HUB 名\r
+       UINT NumItem;                                                           // アイテム数\r
+       RPC_ENUM_DHCP_ITEM *Items;                                      // アイテム\r
+};\r
+\r
+\r
+// 関数プロトタイプ\r
+NAT *NiNewNat();\r
+NAT *NiNewNatEx(SNAT *snat, VH_OPTION *o);\r
+void NiFreeNat(NAT *n);\r
+void NiInitConfig(NAT *n);\r
+void NiFreeConfig(NAT *n);\r
+void NiInitDefaultConfig(NAT *n);\r
+void NiSetDefaultVhOption(NAT *n, VH_OPTION *o);\r
+void NiClearUnsupportedVhOptionForDynamicHub(VH_OPTION *o, bool initial);\r
+void NiWriteConfig(NAT *n);\r
+void NiWriteVhOption(NAT *n, FOLDER *root);\r
+void NiWriteVhOptionEx(VH_OPTION *o, FOLDER *root);\r
+void NiWriteClientData(NAT *n, FOLDER *root);\r
+void NiLoadVhOption(NAT *n, FOLDER *root);\r
+void NiLoadVhOptionEx(VH_OPTION *o, FOLDER *root);\r
+bool NiLoadConfig(NAT *n, FOLDER *root);\r
+void NiLoadClientData(NAT *n, FOLDER *root);\r
+void NiInitAdminAccept(NAT *n);\r
+void NiFreeAdminAccept(NAT *n);\r
+void NiListenThread(THREAD *thread, void *param);\r
+void NiAdminThread(THREAD *thread, void *param);\r
+void NiAdminMain(NAT *n, SOCK *s);\r
+PACK *NiRpcServer(RPC *r, char *name, PACK *p);\r
+\r
+RPC *NatAdminConnect(CEDAR *cedar, char *hostname, UINT port, void *hashed_password, UINT *err);\r
+void NatAdminDisconnect(RPC *r);\r
+\r
+void NtStartNat();\r
+void NtStopNat();\r
+void NtInit();\r
+void NtFree();\r
+\r
+\r
+UINT NtOnline(NAT *n, RPC_DUMMY *t);\r
+UINT NtOffline(NAT *n, RPC_DUMMY *t);\r
+UINT NtSetHostOption(NAT *n, VH_OPTION *t);\r
+UINT NtGetHostOption(NAT *n, VH_OPTION *t);\r
+UINT NtSetClientConfig(NAT *n, RPC_CREATE_LINK *t);\r
+UINT NtGetClientConfig(NAT *n, RPC_CREATE_LINK *t);\r
+UINT NtGetStatus(NAT *n, RPC_NAT_STATUS *t);\r
+UINT NtGetInfo(NAT *n, RPC_NAT_INFO *t);\r
+UINT NtEnumNatList(NAT *n, RPC_ENUM_NAT *t);\r
+UINT NtEnumDhcpList(NAT *n, RPC_ENUM_DHCP *t);\r
+UINT NtSetPassword(NAT *n, RPC_SET_PASSWORD *t);\r
+\r
+\r
+UINT NcOnline(RPC *r, RPC_DUMMY *t);\r
+UINT NcOffline(RPC *r, RPC_DUMMY *t);\r
+UINT NcSetHostOption(RPC *r, VH_OPTION *t);\r
+UINT NcGetHostOption(RPC *r, VH_OPTION *t);\r
+UINT NcSetClientConfig(RPC *r, RPC_CREATE_LINK *t);\r
+UINT NcGetClientConfig(RPC *r, RPC_CREATE_LINK *t);\r
+UINT NcGetStatus(RPC *r, RPC_NAT_STATUS *t);\r
+UINT NcGetInfo(RPC *r, RPC_NAT_INFO *t);\r
+UINT NcEnumNatList(RPC *r, RPC_ENUM_NAT *t);\r
+UINT NcEnumDhcpList(RPC *r, RPC_ENUM_DHCP *t);\r
+UINT NcSetPassword(RPC *r, RPC_SET_PASSWORD *t);\r
+\r
+\r
+\r
+\r
+void InRpcEnumDhcp(RPC_ENUM_DHCP *t, PACK *p);\r
+void OutRpcEnumDhcp(PACK *p, RPC_ENUM_DHCP *t);\r
+void FreeRpcEnumDhcp(RPC_ENUM_DHCP *t);\r
+void InRpcEnumNat(RPC_ENUM_NAT *t, PACK *p);\r
+void OutRpcEnumNat(PACK *p, RPC_ENUM_NAT *t);\r
+void FreeRpcEnumNat(RPC_ENUM_NAT *t);\r
+void InRpcNatInfo(RPC_NAT_INFO *t, PACK *p);\r
+void OutRpcNatInfo(PACK *p, RPC_NAT_INFO *t);\r
+void FreeRpcNatInfo(RPC_NAT_INFO *t);\r
+void InRpcNatStatus(RPC_NAT_STATUS *t, PACK *p);\r
+void OutRpcNatStatus(PACK *p, RPC_NAT_STATUS *t);\r
+void FreeRpcNatStatus(RPC_NAT_STATUS *t);\r
+void InVhOption(VH_OPTION *t, PACK *p);\r
+void OutVhOption(PACK *p, VH_OPTION *t);\r
+void InRpcDummy(RPC_DUMMY *t, PACK *p);\r
+void OutRpcDummy(PACK *p, RPC_DUMMY *t);\r
+\r
+\r
+\r
+\r
+#endif // NAT_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/NullLan.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/NullLan.c
new file mode 100644 (file)
index 0000000..a974549
--- /dev/null
@@ -0,0 +1,249 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// NullLan.c\r
+// テスト用仮想 LAN カードデバイスドライバ\r
+\r
+#include "CedarPch.h"\r
+\r
+static UCHAR null_lan_broadcast_address[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};\r
+\r
+// パケットアダプタの取得\r
+PACKET_ADAPTER *NullGetPacketAdapter()\r
+{\r
+       PACKET_ADAPTER *pa = NewPacketAdapter(NullPaInit, NullPaGetCancel, NullPaGetNextPacket,\r
+               NullPaPutPacket, NullPaFree);\r
+\r
+       return pa;\r
+}\r
+\r
+// パケット生成スレッド\r
+void NullPacketGenerateThread(THREAD *t, void *param)\r
+{\r
+       NULL_LAN *n = (NULL_LAN *)param;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               Wait(n->Event, Rand32() % NULL_PACKET_GENERATE_INTERVAL);\r
+               if (n->Halt)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               LockQueue(n->PacketQueue);\r
+               {\r
+                       UCHAR *data;\r
+                       BLOCK *b;\r
+                       UINT size = Rand32() % 1500 + 14;\r
+                       data = Malloc(size);\r
+                       Copy(data, null_lan_broadcast_address, 6);\r
+                       Copy(data + 6, n->MacAddr, 6);\r
+                       b = NewBlock(data, size, 0);\r
+                       InsertQueue(n->PacketQueue, b);\r
+               }\r
+               UnlockQueue(n->PacketQueue);\r
+               Cancel(n->Cancel);\r
+       }\r
+}\r
+\r
+// パケットアダプタの初期化\r
+bool NullPaInit(SESSION *s)\r
+{\r
+       NULL_LAN *n;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       n = ZeroMalloc(sizeof(NULL_LAN));\r
+       s->PacketAdapter->Param = (void *)n;\r
+\r
+       n->Cancel = NewCancel();\r
+       n->PacketQueue = NewQueue();\r
+       n->Event = NewEvent();\r
+\r
+       GenMacAddress(n->MacAddr);\r
+\r
+       n->PacketGeneratorThread = NewThread(NullPacketGenerateThread, n);\r
+\r
+       return true;\r
+}\r
+\r
+// キャンセルオブジェクトの取得\r
+CANCEL *NullPaGetCancel(SESSION *s)\r
+{\r
+       // 引数チェック\r
+       NULL_LAN *n;\r
+       if (s == NULL || (n = s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       AddRef(n->Cancel->ref);\r
+\r
+       return n->Cancel;\r
+}\r
+\r
+// 次のパケットを取得\r
+UINT NullPaGetNextPacket(SESSION *s, void **data)\r
+{\r
+       UINT size = 0;\r
+       // 引数チェック\r
+       NULL_LAN *n;\r
+       if (s == NULL || (n = s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       LockQueue(n->PacketQueue);\r
+       {\r
+               BLOCK *b = GetNext(n->PacketQueue);\r
+\r
+               if (b != NULL)\r
+               {\r
+                       *data = b->Buf;\r
+                       size = b->Size;\r
+                       Free(b);\r
+               }\r
+       }\r
+       UnlockQueue(n->PacketQueue);\r
+\r
+       return size;\r
+}\r
+\r
+// パケットを書き込み\r
+bool NullPaPutPacket(SESSION *s, void *data, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (data == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       // パケット無視\r
+       Free(data);\r
+\r
+       return true;\r
+}\r
+\r
+// 解放\r
+void NullPaFree(SESSION *s)\r
+{\r
+       // 引数チェック\r
+       NULL_LAN *n;\r
+       BLOCK *b;\r
+       if (s == NULL || (n = s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       n->Halt = true;\r
+       Set(n->Event);\r
+\r
+       WaitThread(n->PacketGeneratorThread, INFINITE);\r
+       ReleaseThread(n->PacketGeneratorThread);\r
+\r
+       LockQueue(n->PacketQueue);\r
+       {\r
+               while (b = GetNext(n->PacketQueue))\r
+               {\r
+                       FreeBlock(b);\r
+               }\r
+       }\r
+       UnlockQueue(n->PacketQueue);\r
+\r
+       ReleaseQueue(n->PacketQueue);\r
+\r
+       ReleaseCancel(n->Cancel);\r
+\r
+       ReleaseEvent(n->Event);\r
+\r
+       s->PacketAdapter->Param = NULL;\r
+       Free(n);\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/NullLan.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/NullLan.h
new file mode 100644 (file)
index 0000000..c0f28e8
--- /dev/null
@@ -0,0 +1,110 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// NullLan.h\r
+// NullLan.c のヘッダ\r
+\r
+#ifndef        NULLLAN_H\r
+#define        NULLLAN_H\r
+\r
+\r
+#define        NULL_PACKET_GENERATE_INTERVAL           100000000               // パケット発生間隔\r
+\r
+// NULL デバイス構造体\r
+struct NULL_LAN\r
+{\r
+       THREAD *PacketGeneratorThread;\r
+       CANCEL *Cancel;\r
+       QUEUE *PacketQueue;\r
+       volatile bool Halt;\r
+       EVENT *Event;\r
+       UCHAR MacAddr[6];\r
+       UCHAR Padding[2];\r
+};\r
+\r
+PACKET_ADAPTER *NullGetPacketAdapter();\r
+bool NullPaInit(SESSION *s);\r
+CANCEL *NullPaGetCancel(SESSION *s);\r
+UINT NullPaGetNextPacket(SESSION *s, void **data);\r
+bool NullPaPutPacket(SESSION *s, void *data, UINT size);\r
+void NullPaFree(SESSION *s);\r
+void NullPacketGenerateThread(THREAD *t, void *param);\r
+\r
+#endif // NULLAN_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Protocol.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Protocol.c
new file mode 100644 (file)
index 0000000..260dc43
--- /dev/null
@@ -0,0 +1,7005 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Protocol.c\r
+// SoftEther プロトコル関係のルーチン\r
+\r
+#include "CedarPch.h"\r
+\r
+static char http_404_str[] = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n<HTML><HEAD>\r\n<TITLE>404 Not Found</TITLE>\r\n</HEAD><BODY>\r\n<H1>Not Found</H1>\r\nThe requested URL $TARGET$ was not found on this server.<P>\r\n<HR>\r\n<ADDRESS>HTTP Server at $HOST$ Port $PORT$</ADDRESS>\r\n</BODY></HTML>\r\n";\r
+static char http_403_str[] = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n<HTML><HEAD>\r\n<TITLE>403 Forbidden</TITLE>\r\n</HEAD><BODY>\r\n<H1>Forbidden</H1>\r\nYou don't have permission to access $TARGET$\r\non this server.<P>\r\n<HR>\r\n<ADDRESS>HTTP Server at $HOST$ Port $PORT$</ADDRESS>\r\n</BODY></HTML>\r\n";\r
+static char http_501_str[] = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n<HTML><HEAD>\r\n<TITLE>501 Method Not Implemented</TITLE>\r\n</HEAD><BODY>\r\n<H1>Method Not Implemented</H1>\r\n$METHOD$ to $TARGET$ not supported.<P>\r\nInvalid method in request $METHOD$ $TARGET$ $VERSION$<P>\r\n<HR>\r\n<ADDRESS>HTTP Server at $HOST$ Port $PORT$</ADDRESS>\r\n</BODY></HTML>\r\n";\r
+\r
+// マシンごとにユニークな ID を生成する\r
+void GenerateMachineUniqueHash(void *data)\r
+{\r
+       BUF *b;\r
+       char name[64];\r
+       char ip_str[64];\r
+       IP ip;\r
+       OS_INFO *osinfo;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = NewBuf();\r
+       GetMachineName(name, sizeof(name));\r
+       GetMachineIp(&ip);\r
+       IPToStr(ip_str, sizeof(ip_str), &ip);\r
+\r
+       osinfo = GetOsInfo();\r
+\r
+       WriteBuf(b, name, StrLen(name));\r
+       WriteBuf(b, ip_str, StrLen(ip_str));\r
+\r
+       WriteBuf(b, &osinfo->OsType, sizeof(osinfo->OsType));\r
+       WriteBuf(b, osinfo->KernelName, StrLen(osinfo->KernelName));\r
+       WriteBuf(b, osinfo->KernelVersion, StrLen(osinfo->KernelVersion));\r
+       WriteBuf(b, osinfo->OsProductName, StrLen(osinfo->OsProductName));\r
+       WriteBuf(b, &osinfo->OsServicePack, sizeof(osinfo->OsServicePack));\r
+       WriteBuf(b, osinfo->OsSystemName, StrLen(osinfo->OsSystemName));\r
+       WriteBuf(b, osinfo->OsVendorName, StrLen(osinfo->OsVendorName));\r
+       WriteBuf(b, osinfo->OsVersion, StrLen(osinfo->OsVersion));\r
+\r
+       Hash(data, b->Buf, b->Size, true);\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// ノード情報を文字列に変換する\r
+void NodeInfoToStr(wchar_t *str, UINT size, NODE_INFO *info)\r
+{\r
+       char client_ip[128], server_ip[128], proxy_ip[128], unique_id[128];\r
+       // 引数チェック\r
+       if (str == NULL || info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       IPToStr4or6(client_ip, sizeof(client_ip), info->ClientIpAddress, info->ClientIpAddress6);\r
+       IPToStr4or6(server_ip, sizeof(server_ip), info->ServerIpAddress, info->ServerIpAddress6);\r
+       IPToStr4or6(proxy_ip, sizeof(proxy_ip), info->ProxyIpAddress, info->ProxyIpAddress6);\r
+       BinToStr(unique_id, sizeof(unique_id), info->UniqueId, sizeof(info->UniqueId));\r
+\r
+       UniFormat(str, size, _UU("LS_NODE_INFO_TAG"), info->ClientProductName,\r
+               Endian32(info->ClientProductVer), Endian32(info->ClientProductBuild),\r
+               info->ServerProductName, Endian32(info->ServerProductVer), Endian32(info->ServerProductBuild),\r
+               info->ClientOsName, info->ClientOsVer, info->ClientOsProductId,\r
+               info->ClientHostname, client_ip, Endian32(info->ClientPort),\r
+               info->ServerHostname, server_ip, Endian32(info->ServerPort),\r
+               info->ProxyHostname, proxy_ip, Endian32(info->ProxyPort),\r
+               info->HubName, unique_id);\r
+}\r
+\r
+// ノード情報の比較\r
+bool CompareNodeInfo(NODE_INFO *a, NODE_INFO *b)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL || b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       if (StrCmp(a->ClientProductName, b->ClientProductName) != 0)\r
+       {\r
+               return false;\r
+       }\r
+       if (a->ClientProductVer != b->ClientProductVer)\r
+       {\r
+               return false;\r
+       }\r
+       if (a->ClientProductBuild != b->ClientProductBuild)\r
+       {\r
+               return false;\r
+       }\r
+       if (StrCmp(a->ServerProductName, b->ServerProductName) != 0)\r
+       {\r
+               return false;\r
+       }\r
+       if (a->ServerProductVer != b->ServerProductVer)\r
+       {\r
+               return false;\r
+       }\r
+       if (a->ServerProductBuild != b->ServerProductBuild)\r
+       {\r
+               return false;\r
+       }\r
+       if (StrCmp(a->ClientOsName, b->ClientOsName) != 0)\r
+       {\r
+               return false;\r
+       }\r
+       if (StrCmp(a->ClientOsVer, b->ClientOsVer) != 0)\r
+       {\r
+               return false;\r
+       }\r
+       if (StrCmp(a->ClientOsProductId, b->ClientOsProductId) != 0)\r
+       {\r
+               return false;\r
+       }\r
+       if (StrCmp(a->ClientHostname, b->ClientHostname) != 0)\r
+       {\r
+               return false;\r
+       }\r
+       if (a->ClientIpAddress != b->ClientIpAddress)\r
+       {\r
+               return false;\r
+       }\r
+       if (StrCmp(a->ServerHostname, b->ServerHostname) != 0)\r
+       {\r
+               return false;\r
+       }\r
+       if (a->ServerIpAddress != b->ServerIpAddress)\r
+       {\r
+               return false;\r
+       }\r
+       if (a->ServerPort != b->ServerPort)\r
+       {\r
+               return false;\r
+       }\r
+       if (StrCmp(a->ProxyHostname, b->ProxyHostname) != 0)\r
+       {\r
+               return false;\r
+       }\r
+       if (a->ProxyIpAddress != b->ProxyIpAddress)\r
+       {\r
+               return false;\r
+       }\r
+       if (a->ProxyPort != b->ProxyPort)\r
+       {\r
+               return false;\r
+       }\r
+       if (StrCmp(a->HubName, b->HubName) != 0)\r
+       {\r
+               return false;\r
+       }\r
+       if (Cmp(a->UniqueId, b->UniqueId, 16) != 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// パスワード変更受付\r
+UINT ChangePasswordAccept(CONNECTION *c, PACK *p)\r
+{\r
+       CEDAR *cedar;\r
+       UCHAR random[SHA1_SIZE];\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       char username[MAX_USERNAME_LEN + 1];\r
+       UCHAR secure_old_password[SHA1_SIZE];\r
+       UCHAR new_password[SHA1_SIZE];\r
+       UCHAR check_secure_old_password[SHA1_SIZE];\r
+       UINT ret = ERR_NO_ERROR;\r
+       HUB *hub;\r
+       bool save = false;\r
+       // 引数チェック\r
+       if (c == NULL || p == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       Copy(random, c->Random, SHA1_SIZE);\r
+       if (PackGetStr(p, "hubname", hubname, sizeof(hubname)) == false ||\r
+               PackGetStr(p, "username", username, sizeof(username)) == false ||\r
+               PackGetData2(p, "secure_old_password", secure_old_password, sizeof(secure_old_password)) == false ||\r
+               PackGetData2(p, "new_password", new_password, sizeof(new_password)) == false)\r
+       {\r
+               return ERR_PROTOCOL_ERROR;\r
+       }\r
+\r
+       cedar = c->Cedar;\r
+\r
+       LockHubList(cedar);\r
+       {\r
+               hub = GetHub(cedar, hubname);\r
+       }\r
+       UnlockHubList(cedar);\r
+\r
+       if (hub == NULL)\r
+       {\r
+               ret = ERR_HUB_NOT_FOUND;\r
+       }\r
+       else\r
+       {\r
+               char tmp[MAX_SIZE];\r
+\r
+               if (GetHubAdminOption(hub, "deny_change_user_password") != 0)\r
+               {\r
+                       ReleaseHub(hub);\r
+                       return ERR_NOT_ENOUGH_RIGHT;\r
+               }\r
+\r
+               IPToStr(tmp, sizeof(tmp), &c->FirstSock->RemoteIP);\r
+               HLog(hub, "LH_CHANGE_PASSWORD_1", c->Name, tmp);\r
+\r
+               AcLock(hub);\r
+               {\r
+                       USER *u = AcGetUser(hub, username);\r
+                       if (u == NULL)\r
+                       {\r
+                               HLog(hub, "LH_CHANGE_PASSWORD_2", c->Name, username);\r
+                               ret = ERR_OLD_PASSWORD_WRONG;\r
+                       }\r
+                       else\r
+                       {\r
+                               Lock(u->lock);\r
+                               {\r
+                                       if (u->AuthType != AUTHTYPE_PASSWORD)\r
+                                       {\r
+                                               // パスワード認証ではない\r
+                                               HLog(hub, "LH_CHANGE_PASSWORD_3", c->Name, username);\r
+                                               ret = ERR_USER_AUTHTYPE_NOT_PASSWORD;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               bool fix_password = false;\r
+                                               if (u->Policy != NULL)\r
+                                               {\r
+                                                       fix_password = u->Policy->FixPassword;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       if (u->Group != NULL)\r
+                                                       {\r
+                                                               if (u->Group->Policy != NULL)\r
+                                                               {\r
+                                                                       fix_password = u->Group->Policy->FixPassword;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                               if (fix_password == false)\r
+                                               {\r
+                                                       // 古いパスワードの確認\r
+                                                       AUTHPASSWORD *pw = (AUTHPASSWORD *)u->AuthData;\r
+\r
+                                                       SecurePassword(check_secure_old_password, pw->HashedKey, random);\r
+                                                       if (Cmp(check_secure_old_password, secure_old_password, SHA1_SIZE) != 0)\r
+                                                       {\r
+                                                               // 古いパスワードが間違っている\r
+                                                               ret = ERR_OLD_PASSWORD_WRONG;\r
+                                                               HLog(hub, "LH_CHANGE_PASSWORD_4", c->Name, username);\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               // 新しいパスワードの書き込み\r
+                                                               Copy(pw->HashedKey, new_password, SHA1_SIZE);\r
+                                                               HLog(hub, "LH_CHANGE_PASSWORD_5", c->Name, username);\r
+                                                               save = true;\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       // パスワード変更は禁止\r
+                                                       ret = ERR_NOT_ENOUGH_RIGHT;\r
+                                               }\r
+                                       }\r
+                               }\r
+                               Unlock(u->lock);\r
+\r
+                               ReleaseUser(u);\r
+                       }\r
+               }\r
+               AcUnlock(hub);\r
+               ReleaseHub(hub);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// パスワードを変更する\r
+UINT ChangePassword(CEDAR *cedar, CLIENT_OPTION *o, char *hubname, char *username, char *old_pass, char *new_pass)\r
+{\r
+       UINT ret = ERR_NO_ERROR;\r
+       UCHAR old_password[SHA1_SIZE];\r
+       UCHAR secure_old_password[SHA1_SIZE];\r
+       UCHAR new_password[SHA1_SIZE];\r
+       SOCK *sock;\r
+       SESSION *s;\r
+       // 引数チェック\r
+       if (cedar == NULL || o == NULL || hubname == NULL || username == NULL || old_pass == NULL || new_pass == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+\r
+       // セッション作成\r
+       s = NewRpcSessionEx(cedar, o, &ret, NULL);\r
+\r
+       if (s != NULL)\r
+       {\r
+               PACK *p = NewPack();\r
+\r
+               sock = s->Connection->FirstSock;\r
+\r
+               HashPassword(old_password, username, old_pass);\r
+               SecurePassword(secure_old_password, old_password, s->Connection->Random);\r
+               HashPassword(new_password, username, new_pass);\r
+\r
+               PackAddClientVersion(p, s->Connection);\r
+\r
+               PackAddStr(p, "method", "password");\r
+               PackAddStr(p, "hubname", hubname);\r
+               PackAddStr(p, "username", username);\r
+               PackAddData(p, "secure_old_password", secure_old_password, SHA1_SIZE);\r
+               PackAddData(p, "new_password", new_password, SHA1_SIZE);\r
+\r
+               if (HttpClientSend(sock, p))\r
+               {\r
+                       PACK *p = HttpClientRecv(sock);\r
+                       if (p == NULL)\r
+                       {\r
+                               ret = ERR_DISCONNECTED;\r
+                       }\r
+                       else\r
+                       {\r
+                               ret = GetErrorFromPack(p);\r
+                       }\r
+                       FreePack(p);\r
+               }\r
+               else\r
+               {\r
+                       ret = ERR_DISCONNECTED;\r
+               }\r
+               FreePack(p);\r
+\r
+               ReleaseSession(s);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// HUB を列挙する\r
+TOKEN_LIST *EnumHub(SESSION *s)\r
+{\r
+       SOCK *sock;\r
+       TOKEN_LIST *ret;\r
+       PACK *p;\r
+       UINT num;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || s->Connection == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       sock = s->Connection->FirstSock;\r
+       if (sock == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // タイムアウトの設定\r
+       SetTimeout(sock, 10000);\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "method", "enum_hub");\r
+\r
+       PackAddClientVersion(p, s->Connection);\r
+\r
+       if (HttpClientSend(sock, p) == false)\r
+       {\r
+               FreePack(p);\r
+               return NULL;\r
+       }\r
+       FreePack(p);\r
+\r
+       p = HttpClientRecv(sock);\r
+       if (p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       num = PackGetInt(p, "NumHub");\r
+       ret = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       ret->NumTokens = num;\r
+       ret->Token = ZeroMalloc(sizeof(char *) * num);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               if (PackGetStrEx(p, "HubName", tmp, sizeof(tmp), i))\r
+               {\r
+                       ret->Token[i] = CopyStr(tmp);\r
+               }\r
+       }\r
+       FreePack(p);\r
+\r
+       return ret;\r
+}\r
+\r
+// サーバーがクライアントからの接続を受け付ける\r
+bool ServerAccept(CONNECTION *c)\r
+{\r
+       bool ret = false;\r
+       UINT err;\r
+       PACK *p;\r
+       char username_real[MAX_SIZE];\r
+       char method[MAX_SIZE];\r
+       char hubname[MAX_SIZE];\r
+       char username[MAX_SIZE];\r
+       char groupname[MAX_SIZE];\r
+       UCHAR session_key[SHA1_SIZE];\r
+       UCHAR ticket[SHA1_SIZE];\r
+       RC4_KEY_PAIR key_pair;\r
+       UINT authtype;\r
+       POLICY *policy;\r
+       HUB *hub;\r
+       SESSION *s;\r
+       UINT64 user_expires = 0;\r
+       bool use_encrypt;\r
+       bool use_compress;\r
+       bool half_connection;\r
+       bool use_fast_rc4;\r
+       bool admin_mode = false;\r
+       UINT direction;\r
+       UINT max_connection;\r
+       UINT timeout;\r
+       bool farm_controller = false;\r
+       bool farm_member = false;\r
+       bool farm_mode = false;\r
+       bool require_bridge_routing_mode;\r
+       bool require_monitor_mode;\r
+       bool use_client_license = false, use_bridge_license = false;\r
+       bool local_host_session = false;\r
+       char sessionname[MAX_SESSION_NAME_LEN + 1];\r
+       bool is_server_or_bridge = false;\r
+       bool qos = false;\r
+       bool cluster_dynamic_secure_nat = false;\r
+       bool no_save_password = false;\r
+       NODE_INFO node;\r
+       wchar_t *msg = NULL;\r
+       USER *loggedin_user_object = NULL;\r
+       FARM_MEMBER *f = NULL;\r
+       SERVER *server = NULL;\r
+       POLICY ticketed_policy;\r
+       UINT64 timestamp;\r
+       UCHAR unique[SHA1_SIZE], unique2[SHA1_SIZE];\r
+       LICENSE_STATUS license;\r
+       CEDAR *cedar;\r
+       RPC_WINVER winver;\r
+       UINT client_id;\r
+       bool no_more_users_in_server = false;\r
+\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&winver, sizeof(winver));\r
+\r
+       StrCpy(groupname, sizeof(groupname), "");\r
+       StrCpy(sessionname, sizeof(sessionname), "");\r
+\r
+       cedar = c->Cedar;\r
+\r
+       // ライセンス状況の取得\r
+       Zero(&license, sizeof(license));\r
+       if (c->Cedar->Server != NULL)\r
+       {\r
+               LiParseCurrentLicenseStatus(c->Cedar->Server->LicenseSystem, &license);\r
+       }\r
+\r
+       no_more_users_in_server = SiTooManyUserObjectsInServer(cedar->Server, true);\r
+\r
+       c->Status = CONNECTION_STATUS_NEGOTIATION;\r
+\r
+       if (c->Cedar->Server != NULL)\r
+       {\r
+               SERVER *s = c->Cedar->Server;\r
+               server = s;\r
+\r
+               if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+               {\r
+                       farm_member = true;\r
+                       farm_mode = true;\r
+               }\r
+\r
+               if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+               {\r
+                       farm_controller = true;\r
+                       farm_mode = true;\r
+               }\r
+       }\r
+\r
+       // シグネチャを受信\r
+       Debug("Downloading Signature...\n");\r
+       if (ServerDownloadSignature(c) == false)\r
+       {\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // Hello パケットを送信\r
+       Debug("Uploading Hello...\n");\r
+       if (ServerUploadHello(c) == false)\r
+       {\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // 認証データを受信\r
+       Debug("Auth...\n");\r
+\r
+       p = HttpServerRecv(c->FirstSock);\r
+       if (p == NULL)\r
+       {\r
+               // 通信切断\r
+               c->Err = ERR_DISCONNECTED;\r
+               goto CLEANUP;\r
+       }\r
+\r
+       if (err = GetErrorFromPack(p))\r
+       {\r
+               // エラー発生\r
+               FreePack(p);\r
+               c->Err = err;\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // メソッド取得\r
+       if (GetMethodFromPack(p, method, sizeof(method)) == false)\r
+       {\r
+               // プロトコルエラー\r
+               FreePack(p);\r
+               c->Err = ERR_PROTOCOL_ERROR;\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // 時刻検査\r
+       timestamp = PackGetInt64(p, "timestamp");\r
+       if (timestamp != 0)\r
+       {\r
+               UINT64 now = SystemTime64();\r
+               UINT64 abs;\r
+               if (now >= timestamp)\r
+               {\r
+                       abs = now - timestamp;\r
+               }\r
+               else\r
+               {\r
+                       abs = timestamp - now;\r
+               }\r
+\r
+               if (abs > ALLOW_TIMESTAMP_DIFF)\r
+               {\r
+                       // 時差が大きすぎる\r
+                       FreePack(p);\r
+                       c->Err = ERR_BAD_CLOCK;\r
+                       goto CLEANUP;\r
+               }\r
+       }\r
+\r
+       // クライアントバージョン取得\r
+       PackGetStr(p, "client_str", c->ClientStr, sizeof(c->ClientStr));\r
+       c->ClientVer = PackGetInt(p, "client_ver");\r
+       c->ClientBuild = PackGetInt(p, "client_build");\r
+\r
+       if (SearchStrEx(c->ClientStr, "server", 0, false) != INFINITE ||\r
+               SearchStrEx(c->ClientStr, "bridge", 0, false) != INFINITE)\r
+       {\r
+               is_server_or_bridge = true;\r
+       }\r
+\r
+       // クライアント Windows バージョンの取得\r
+       InRpcWinVer(&winver, p);\r
+\r
+       DecrementNoSsl(c->Cedar, &c->FirstSock->RemoteIP, 2);\r
+\r
+       if (StrCmpi(method, "login") == 0)\r
+       {\r
+               bool auth_ret = false;\r
+\r
+               Debug("Login...\n");\r
+               c->Status = CONNECTION_STATUS_USERAUTH;\r
+\r
+               c->Type = CONNECTION_TYPE_LOGIN;\r
+\r
+               if (no_more_users_in_server)\r
+               {\r
+                       // VPN Server に許可されているよりも多くのユーザーが存在する\r
+                       FreePack(p);\r
+                       c->Err = ERR_TOO_MANY_USER;\r
+                       goto CLEANUP;\r
+               }\r
+\r
+               // クライアント名など\r
+               if (PackGetStr(p, "hello", c->ClientStr, sizeof(c->ClientStr)) == false)\r
+               {\r
+                       StrCpy(c->ClientStr, sizeof(c->ClientStr), "Unknown");\r
+               }\r
+               c->ServerVer = CEDAR_VER;\r
+               c->ServerBuild = CEDAR_BUILD;\r
+\r
+               // NODE_INFO を取得する\r
+               Zero(&node, sizeof(node));\r
+               InRpcNodeInfo(&node, p);\r
+\r
+               // プロトコル\r
+               c->Protocol = GetProtocolFromPack(p);\r
+               if (c->Protocol == CONNECTION_UDP)\r
+               {\r
+                       // TCP 関係の構造体を解放する\r
+                       if (c->Tcp)\r
+                       {\r
+                               ReleaseList(c->Tcp->TcpSockList);\r
+                               Free(c->Tcp);\r
+                       }\r
+               }\r
+\r
+               if (GetServerCapsBool(c->Cedar->Server, "b_vpn_client_connect") == false)\r
+               {\r
+                       // VPN クライアントが接続不可能である\r
+                       FreePack(p);\r
+                       c->Err = ERR_NOT_SUPPORTED;\r
+                       goto CLEANUP;\r
+               }\r
+\r
+               // ログイン\r
+               if (GetHubnameAndUsernameFromPack(p, username, sizeof(username), hubname, sizeof(hubname)) == false)\r
+               {\r
+                       // プロトコルエラー\r
+                       FreePack(p);\r
+                       c->Err = ERR_PROTOCOL_ERROR;\r
+                       goto CLEANUP;\r
+               }\r
+\r
+               if (farm_member)\r
+               {\r
+                       bool ok = false;\r
+                       UINT authtype;\r
+\r
+                       authtype = GetAuthTypeFromPack(p);\r
+                       if (StrCmpi(username, ADMINISTRATOR_USERNAME) == 0 &&\r
+                               authtype == AUTHTYPE_PASSWORD)\r
+                       {\r
+                               ok = true;\r
+                       }\r
+\r
+                       if (authtype == AUTHTYPE_TICKET)\r
+                       {\r
+                               ok = true;\r
+                       }\r
+\r
+                       if (ok == false)\r
+                       {\r
+                               // サーバーファームメンバへの Administrators 以外の直接ログオンは\r
+                               // 禁止されている\r
+                               FreePack(p);\r
+                               SLog(c->Cedar, "LS_FARMMEMBER_NOT_ADMIN", c->Name, hubname, ADMINISTRATOR_USERNAME, username);\r
+                               c->Err = ERR_ACCESS_DENIED;\r
+                               goto CLEANUP;\r
+                       }\r
+               }\r
+\r
+               Debug("Username = %s, HubName = %s\n", username, hubname);\r
+               LockHubList(c->Cedar);\r
+               {\r
+                       hub = GetHub(c->Cedar, hubname);\r
+               }\r
+               UnlockHubList(c->Cedar);\r
+               if (hub == NULL)\r
+               {\r
+                       // HUB が存在しない\r
+                       FreePack(p);\r
+                       c->Err = ERR_HUB_NOT_FOUND;\r
+                       SLog(c->Cedar, "LS_HUB_NOT_FOUND", c->Name, hubname);\r
+                       goto CLEANUP;\r
+               }\r
+\r
+               Lock(hub->lock);\r
+               {\r
+                       USER *user;\r
+                       USERGROUP *group;\r
+                       if (hub->Halt || hub->Offline)\r
+                       {\r
+                               // HUB は停止中\r
+                               FreePack(p);\r
+                               Unlock(hub->lock);\r
+                               ReleaseHub(hub);\r
+                               c->Err = ERR_HUB_STOPPING;\r
+                               goto CLEANUP;\r
+                       }\r
+\r
+                       // 各種フラグの取得\r
+                       use_encrypt = PackGetInt(p, "use_encrypt") == 0 ? false : true;\r
+                       use_compress = PackGetInt(p, "use_compress") == 0 ? false : true;\r
+                       max_connection = PackGetInt(p, "max_connection");\r
+                       half_connection = PackGetInt(p, "half_connection") == 0 ? false : true;\r
+                       use_fast_rc4 = PackGetInt(p, "use_fast_rc4") == 0 ? false : true;\r
+                       qos = PackGetInt(p, "qos") ? true : false;\r
+                       client_id = PackGetInt(p, "client_id");\r
+\r
+                       // 要求モード\r
+                       require_bridge_routing_mode = PackGetBool(p, "require_bridge_routing_mode");\r
+                       require_monitor_mode = PackGetBool(p, "require_monitor_mode");\r
+                       if (require_monitor_mode)\r
+                       {\r
+                               qos = false;\r
+                       }\r
+\r
+                       if (is_server_or_bridge)\r
+                       {\r
+                               require_bridge_routing_mode = true;\r
+                       }\r
+\r
+                       // クライアントユニーク ID\r
+                       Zero(unique, sizeof(unique));\r
+                       if (PackGetDataSize(p, "unique_id") == SHA1_SIZE)\r
+                       {\r
+                               PackGetData(p, "unique_id", unique);\r
+                       }\r
+\r
+                       // 認証方法の取得\r
+                       authtype = GetAuthTypeFromPack(p);\r
+\r
+                       if (1)\r
+                       {\r
+                               // ログ\r
+                               char ip1[64], ip2[64], verstr[64];\r
+                               wchar_t *authtype_str = _UU("LH_AUTH_UNKNOWN");\r
+                               switch (authtype)\r
+                               {\r
+                               case CLIENT_AUTHTYPE_ANONYMOUS:\r
+                                       authtype_str = _UU("LH_AUTH_ANONYMOUS");\r
+                                       break;\r
+                               case CLIENT_AUTHTYPE_PASSWORD:\r
+                                       authtype_str = _UU("LH_AUTH_PASSWORD");\r
+                                       break;\r
+                               case CLIENT_AUTHTYPE_PLAIN_PASSWORD:\r
+                                       authtype_str = _UU("LH_AUTH_PLAIN_PASSWORD");\r
+                                       break;\r
+                               case CLIENT_AUTHTYPE_CERT:\r
+                                       authtype_str = _UU("LH_AUTH_CERT");\r
+                                       break;\r
+                               case AUTHTYPE_TICKET:\r
+                                       authtype_str = _UU("LH_AUTH_TICKET");\r
+                                       break;\r
+                               }\r
+                               IPToStr(ip1, sizeof(ip1), &c->FirstSock->RemoteIP);\r
+                               IPToStr(ip2, sizeof(ip2), &c->FirstSock->LocalIP);\r
+\r
+                               Format(verstr, sizeof(verstr), "%u.%02u", c->ClientVer / 100, c->ClientVer % 100);\r
+\r
+                               HLog(hub, "LH_CONNECT_CLIENT", c->Name, ip1, c->FirstSock->RemoteHostname, c->FirstSock->RemotePort,\r
+                                       c->ClientStr, verstr, c->ClientBuild, authtype_str, username);\r
+                       }\r
+\r
+                       // まず匿名認証を試行する\r
+                       auth_ret = SamAuthUserByAnonymous(hub, username);\r
+\r
+                       if (auth_ret)\r
+                       {\r
+                               // ユーザー認証成功\r
+                               HLog(hub, "LH_AUTH_OK", c->Name, username);\r
+                       }\r
+\r
+                       if (auth_ret == false)\r
+                       {\r
+                               // 匿名認証に失敗した場合は他の認証方法を試行する\r
+                               switch (authtype)\r
+                               {\r
+                               case CLIENT_AUTHTYPE_ANONYMOUS:\r
+                                       // 匿名認証 (すでに試行している)\r
+                                       break;\r
+\r
+                               case AUTHTYPE_TICKET:\r
+                                       // チケット認証\r
+                                       if (PackGetDataSize(p, "ticket") == SHA1_SIZE)\r
+                                       {\r
+                                               PackGetData(p, "ticket", ticket);\r
+\r
+                                               auth_ret = SiCheckTicket(hub, ticket, username, sizeof(username), username_real, sizeof(username_real),\r
+                                                       &ticketed_policy, sessionname, sizeof(sessionname), groupname, sizeof(groupname));\r
+                                       }\r
+                                       break;\r
+\r
+                               case CLIENT_AUTHTYPE_PASSWORD:\r
+                                       // パスワード認証\r
+                                       if (PackGetDataSize(p, "secure_password") == SHA1_SIZE)\r
+                                       {\r
+                                               POLICY *pol = NULL;\r
+                                               UCHAR secure_password[SHA1_SIZE];\r
+                                               Zero(secure_password, sizeof(secure_password));\r
+                                               if (PackGetDataSize(p, "secure_password") == SHA1_SIZE)\r
+                                               {\r
+                                                       PackGetData(p, "secure_password", secure_password);\r
+                                               }\r
+                                               auth_ret = SamAuthUserByPassword(hub, username, c->Random, secure_password);\r
+\r
+                                               pol = SamGetUserPolicy(hub, username);\r
+                                               if (pol != NULL)\r
+                                               {\r
+                                                       no_save_password = pol->NoSavePassword;\r
+                                                       Free(pol);\r
+                                               }\r
+                                       }\r
+                                       break;\r
+\r
+                               case CLIENT_AUTHTYPE_PLAIN_PASSWORD:\r
+                                       // 外部サーバーによる認証はサポートされていない\r
+                                       HLog(hub, "LH_AUTH_RADIUS_NOT_SUPPORT", c->Name, username);\r
+                                       Unlock(hub->lock);\r
+                                       ReleaseHub(hub);\r
+                                       FreePack(p);\r
+                                       c->Err = ERR_AUTHTYPE_NOT_SUPPORTED;\r
+                                       goto CLEANUP;\r
+\r
+                               case CLIENT_AUTHTYPE_CERT:\r
+                                       // 証明書認証はサポートされていない\r
+                                       HLog(hub, "LH_AUTH_CERT_NOT_SUPPORT", c->Name, username);\r
+                                       Unlock(hub->lock);\r
+                                       ReleaseHub(hub);\r
+                                       FreePack(p);\r
+                                       c->Err = ERR_AUTHTYPE_NOT_SUPPORTED;\r
+                                       goto CLEANUP;\r
+\r
+                               default:\r
+                                       // 不明な認証方法\r
+                                       Unlock(hub->lock);\r
+                                       ReleaseHub(hub);\r
+                                       FreePack(p);\r
+                                       c->Err = ERR_AUTHTYPE_NOT_SUPPORTED;\r
+                                       goto CLEANUP;\r
+                               }\r
+\r
+                               if (auth_ret == false)\r
+                               {\r
+                                       // 認証失敗\r
+                                       HLog(hub, "LH_AUTH_NG", c->Name, username);\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 認証成功\r
+                                       HLog(hub, "LH_AUTH_OK", c->Name, username);\r
+                               }\r
+                       }\r
+\r
+                       if (auth_ret == false)\r
+                       {\r
+                               // 認証失敗\r
+                               Unlock(hub->lock);\r
+                               ReleaseHub(hub);\r
+                               FreePack(p);\r
+                               c->Err = ERR_AUTH_FAILED;\r
+                               goto CLEANUP;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (authtype == CLIENT_AUTHTYPE_PASSWORD)\r
+                               {\r
+                                       UCHAR test[SHA1_SIZE];\r
+                                       HashPassword(test, username, "");\r
+                                       if (Cmp(test, hub->SecurePassword, SHA1_SIZE) == 0)\r
+                                       {\r
+                                               SOCK *s = c->FirstSock;\r
+                                               if (s != NULL)\r
+                                               {\r
+                                                       if (GetHubAdminOption(hub, "deny_empty_password") != 0 ||\r
+                                                               (StrCmpi(username, ADMINISTRATOR_USERNAME) == 0 && s->RemoteIP.addr[0] != 127))\r
+                                                       {\r
+                                                               // パスワードが空のとき、リモートから接続してはいけない\r
+                                                               HLog(hub, "LH_LOCAL_ONLY", c->Name, username);\r
+\r
+                                                               Unlock(hub->lock);\r
+                                                               ReleaseHub(hub);\r
+                                                               FreePack(p);\r
+                                                               c->Err = ERR_NULL_PASSWORD_LOCAL_ONLY;\r
+                                                               goto CLEANUP;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       policy = NULL;\r
+\r
+                       // 認証成功\r
+                       FreePack(p);\r
+\r
+                       if (StrCmpi(username, ADMINISTRATOR_USERNAME) != 0)\r
+                       {\r
+                               // ポリシーを取得\r
+                               if (farm_member == false)\r
+                               {\r
+                                       // ファームメンバ以外の場合\r
+                                       user = AcGetUser(hub, username);\r
+                                       if (user == NULL)\r
+                                       {\r
+                                               user = AcGetUser(hub, "*");\r
+                                               if (user == NULL)\r
+                                               {\r
+                                                       // ユーザー取得失敗\r
+                                                       Unlock(hub->lock);\r
+                                                       ReleaseHub(hub);\r
+                                                       c->Err = ERR_ACCESS_DENIED;\r
+                                                       goto CLEANUP;\r
+                                               }\r
+                                       }\r
+\r
+                                       policy = NULL;\r
+\r
+                                       Lock(user->lock);\r
+                                       {\r
+                                               // 有効期限を取得\r
+                                               user_expires = user->ExpireTime;\r
+\r
+                                               StrCpy(username_real, sizeof(username_real), user->Name);\r
+                                               group = user->Group;\r
+                                               if (group != NULL)\r
+                                               {\r
+                                                       AddRef(group->ref);\r
+\r
+                                                       Lock(group->lock);\r
+                                                       {\r
+                                                               // グループ名を取得\r
+                                                               StrCpy(groupname, sizeof(groupname), group->Name);\r
+                                                       }\r
+                                                       Unlock(group->lock);\r
+                                               }\r
+\r
+                                               if (user->Policy != NULL)\r
+                                               {\r
+                                                       policy = ClonePolicy(user->Policy);\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       if (group)\r
+                                                       {\r
+                                                               Lock(group->lock);\r
+                                                               {\r
+                                                                       if (group->Policy != NULL)\r
+                                                                       {\r
+                                                                               policy = ClonePolicy(group->Policy);\r
+                                                                       }\r
+                                                               }\r
+                                                               Unlock(group->lock);\r
+                                                       }\r
+                                               }\r
+\r
+                                               if (group != NULL)\r
+                                               {\r
+                                                       ReleaseGroup(group);\r
+                                               }\r
+                                       }\r
+                                       Unlock(user->lock);\r
+                                       loggedin_user_object = user;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // ファームメンバの場合\r
+                                       policy = ClonePolicy(&ticketed_policy);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // 管理者モード\r
+                               admin_mode = true;\r
+                               StrCpy(username_real, sizeof(username_real), ADMINISTRATOR_USERNAME);\r
+\r
+                               policy = ClonePolicy(GetDefaultPolicy());\r
+                               policy->NoBroadcastLimiter = true;\r
+                               policy->MonitorPort = true;\r
+                       }\r
+\r
+                       if (policy == NULL)\r
+                       {\r
+                               // デフォルトのポリシーを使用する\r
+                               policy = ClonePolicy(GetDefaultPolicy());\r
+                       }\r
+\r
+                       if (policy->MaxConnection == 0)\r
+                       {\r
+                               policy->MaxConnection = MAX_TCP_CONNECTION;\r
+                       }\r
+\r
+                       if (policy->TimeOut == 0)\r
+                       {\r
+                               policy->TimeOut = 20;\r
+                       }\r
+\r
+                       if (qos)\r
+                       {\r
+                               // VoIP / QoS\r
+                               if (policy->NoQoS)\r
+                               {\r
+                                       // ポリシーが許可していない\r
+                                       qos = false;\r
+                               }\r
+                               if (GetServerCapsBool(c->Cedar->Server, "b_support_qos") == false)\r
+                               {\r
+                                       // サーバーがサポートしていない\r
+                                       qos = false;\r
+                                       policy->NoQoS = true;\r
+                               }\r
+                               if (GetHubAdminOption(hub, "deny_qos") != 0)\r
+                               {\r
+                                       // 管理オプションで禁止されている\r
+                                       qos = false;\r
+                                       policy->NoQoS = true;\r
+                               }\r
+                       }\r
+\r
+                       if (GetHubAdminOption(hub, "max_bitrates_download") != 0)\r
+                       {\r
+                               if (policy->MaxDownload == 0)\r
+                               {\r
+                                       policy->MaxDownload = GetHubAdminOption(hub, "max_bitrates_download");\r
+                               }\r
+                               else\r
+                               {\r
+                                       policy->MaxDownload = MIN(policy->MaxDownload, GetHubAdminOption(hub, "max_bitrates_download"));\r
+                               }\r
+                       }\r
+\r
+                       if (GetHubAdminOption(hub, "max_bitrates_upload") != 0)\r
+                       {\r
+                               if (policy->MaxUpload == 0)\r
+                               {\r
+                                       policy->MaxUpload = GetHubAdminOption(hub, "max_bitrates_upload");\r
+                               }\r
+                               else\r
+                               {\r
+                                       policy->MaxUpload = MIN(policy->MaxUpload, GetHubAdminOption(hub, "max_bitrates_upload"));\r
+                               }\r
+                       }\r
+\r
+                       if (GetHubAdminOption(hub, "deny_bridge") != 0)\r
+                       {\r
+                               policy->NoBridge = true;\r
+                       }\r
+\r
+                       if (GetHubAdminOption(hub, "deny_routing") != 0)\r
+                       {\r
+                               policy->NoRouting = true;\r
+                       }\r
+\r
+                       if (hub->Option->ClientMinimumRequiredBuild > c->ClientBuild &&\r
+                                InStrEx(c->ClientStr, "client", false))\r
+                       {\r
+                               // クライアントのビルド番号が小さすぎる\r
+                               HLog(hub, "LH_CLIENT_VERSION_OLD", c->Name, c->ClientBuild, hub->Option->ClientMinimumRequiredBuild);\r
+\r
+                               Unlock(hub->lock);\r
+                               ReleaseHub(hub);\r
+                               c->Err = ERR_VERSION_INVALID;\r
+                               Free(policy);\r
+                               goto CLEANUP;\r
+                       }\r
+\r
+                       if (hub->Option->RequiredClientId != 0 &&\r
+                               hub->Option->RequiredClientId != client_id && \r
+                               InStrEx(c->ClientStr, "client", false))\r
+                       {\r
+                               // クライアントのビルド番号が小さすぎる\r
+                               HLog(hub, "LH_CLIENT_ID_REQUIRED", c->Name, client_id, hub->Option->RequiredClientId);\r
+\r
+                               Unlock(hub->lock);\r
+                               ReleaseHub(hub);\r
+                               c->Err = ERR_CLIENT_ID_REQUIRED;\r
+                               Free(policy);\r
+                               goto CLEANUP;\r
+                       }\r
+\r
+                       if ((policy->NoSavePassword) || (policy->AutoDisconnect != 0))\r
+                       {\r
+                               if (c->ClientBuild < 6560 && InStrEx(c->ClientStr, "client", false))\r
+                               {\r
+                                       // NoSavePassword ポリシーが指定されている場合は対応クライアント\r
+                                       // でなければ接続できない\r
+                                       HLog(hub, "LH_CLIENT_VERSION_OLD", c->Name, c->ClientBuild, 6560);\r
+\r
+                                       Unlock(hub->lock);\r
+                                       ReleaseHub(hub);\r
+                                       c->Err = ERR_VERSION_INVALID;\r
+                                       Free(policy);\r
+                                       goto CLEANUP;\r
+                               }\r
+                       }\r
+\r
+                       if (user_expires != 0 && user_expires <= SystemTime64())\r
+                       {\r
+                               // 有効期限が切れている\r
+                               // アクセスが拒否されている\r
+                               HLog(hub, "LH_USER_EXPIRES", c->Name, username);\r
+\r
+                               Unlock(hub->lock);\r
+                               ReleaseHub(hub);\r
+                               c->Err = ERR_ACCESS_DENIED;\r
+                               Free(policy);\r
+                               goto CLEANUP;\r
+                       }\r
+\r
+                       if (policy->Access == false)\r
+                       {\r
+                               // アクセスが拒否されている\r
+                               HLog(hub, "LH_POLICY_ACCESS_NG", c->Name, username);\r
+\r
+                               Unlock(hub->lock);\r
+                               ReleaseHub(hub);\r
+                               c->Err = ERR_ACCESS_DENIED;\r
+                               Free(policy);\r
+                               goto CLEANUP;\r
+                       }\r
+\r
+                       // ポリシーの内容をクライアントが要求したオプションと比較して\r
+                       // 決定するか接続を拒否する\r
+                       // 最初にモニタポートモードで接続できるかどうか確認する\r
+                       if (require_monitor_mode && policy->MonitorPort == false)\r
+                       {\r
+                               // モニタポートモードで接続できない\r
+                               HLog(hub, "LH_POLICY_MONITOR_MODE", c->Name);\r
+\r
+                               Unlock(hub->lock);\r
+                               ReleaseHub(hub);\r
+                               c->Err = ERR_MONITOR_MODE_DENIED;\r
+                               Free(policy);\r
+                               goto CLEANUP;\r
+                       }\r
+\r
+                       if (policy->MonitorPort)\r
+                       {\r
+                               if (require_monitor_mode == false)\r
+                               {\r
+                                       policy->MonitorPort = false;\r
+                               }\r
+                       }\r
+\r
+                       if (policy->MonitorPort)\r
+                       {\r
+                               qos = false;\r
+                       }\r
+\r
+                       // 次にブリッジ / ルーティングモードで接続できるか確認する\r
+                       if (require_bridge_routing_mode &&\r
+                               (policy->NoBridge && policy->NoRouting))\r
+                       {\r
+                               // ブリッジ / ルーティングモードで接続できない\r
+                               HLog(hub, "LH_POLICY_BRIDGE_MODE", c->Name);\r
+\r
+                               Unlock(hub->lock);\r
+                               ReleaseHub(hub);\r
+                               c->Err = ERR_BRIDGE_MODE_DENIED;\r
+                               Free(policy);\r
+                               goto CLEANUP;\r
+                       }\r
+\r
+                       if (require_bridge_routing_mode == false)\r
+                       {\r
+                               policy->NoBridge = true;\r
+                               policy->NoRouting = true;\r
+                       }\r
+\r
+                       // ライセンスが必要かどうかチェック\r
+                       GenerateMachineUniqueHash(unique2);\r
+\r
+                       if (Cmp(unique, unique2, SHA1_SIZE) == 0)\r
+                       {\r
+                               // ローカルホストセッションである\r
+                               local_host_session = true;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (license.NumUserLicense != INFINITE)\r
+                               {\r
+                                       // ユーザー作成数が制限されているエディションでは多重ログイン禁止\r
+                                       policy->MultiLogins = 1;\r
+                               }\r
+\r
+                               if (policy->NoBridge == false || policy->NoRouting == false)\r
+                               {\r
+                                       // ブリッジライセンスを消費\r
+                                       use_bridge_license = true;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // クライアントライセンスを消費\r
+                                       use_client_license = true;\r
+                               }\r
+                       }\r
+\r
+                       if (server != NULL && server->ServerType != SERVER_TYPE_FARM_MEMBER &&\r
+                               (use_bridge_license || use_client_license))\r
+                       {\r
+                               // クラスタコントローラまたはスタンドアロンサーバーの場合で\r
+                               // クライアントにライセンスが必要になった場合、ここでライセンス数が\r
+                               // 足りているかどうかを計算する\r
+\r
+                               if (use_client_license)\r
+                               {\r
+                                       if (server->CurrentAssignedClientLicense >= license.NumClientLicense)\r
+                                       {\r
+                                               // クライアント接続ライセンスが足りない\r
+                                               Unlock(hub->lock);\r
+\r
+                                               // 詳細エラーログを吐く\r
+                                               HLog(hub, "LH_NOT_ENOUGH_CLIENT_LICENSE", c->Name,\r
+                                                       license.NumClientLicense,\r
+                                                       server->CurrentAssignedClientLicense + 1);\r
+\r
+                                               ReleaseHub(hub);\r
+                                               c->Err = ERR_CLIENT_LICENSE_NOT_ENOUGH;\r
+                                               Free(policy);\r
+                                               goto CLEANUP;\r
+                                       }\r
+                               }\r
+                               if (use_bridge_license)\r
+                               {\r
+                                       if (server->CurrentAssignedBridgeLicense >= license.NumBridgeLicense)\r
+                                       {\r
+                                               // ブリッジ接続ライセンス数が足りない\r
+                                               Unlock(hub->lock);\r
+\r
+                                               // 詳細エラーログを吐く\r
+                                               HLog(hub, "LH_NOT_ENOUGH_BRIDGE_LICENSE", c->Name,\r
+                                                       license.NumBridgeLicense,\r
+                                                       server->CurrentAssignedBridgeLicense + 1);\r
+\r
+                                               ReleaseHub(hub);\r
+                                               c->Err = ERR_BRIDGE_LICENSE_NOT_ENOUGH;\r
+                                               Free(policy);\r
+                                               goto CLEANUP;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       if (server != NULL && server->ServerType != SERVER_TYPE_FARM_MEMBER &&\r
+                               policy != NULL)\r
+                       {\r
+                               if (GetServerCapsBool(hub->Cedar->Server, "b_support_limit_multilogin"))\r
+                               {\r
+                                       // ポリシーで多重ログイン制限数が指定されている場合は確認する\r
+                                       RPC_ENUM_SESSION t;\r
+                                       UINT i, num;\r
+                                       UINT max_logins = policy->MultiLogins;\r
+                                       UINT ao = GetHubAdminOption(hub, "max_multilogins_per_user");\r
+\r
+                                       if (ao != 0)\r
+                                       {\r
+                                               if (max_logins != 0)\r
+                                               {\r
+                                                       max_logins = MIN(max_logins, ao);\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       max_logins = ao;\r
+                                               }\r
+                                       }\r
+\r
+                                       if (max_logins != 0)\r
+                                       {\r
+                                               Zero(&t, sizeof(t));\r
+                                               StrCpy(t.HubName, sizeof(t.HubName), hub->Name);\r
+\r
+                                               Unlock(hub->lock);\r
+\r
+                                               SiEnumSessionMain(server, &t);\r
+\r
+                                               Lock(hub->lock);\r
+\r
+                                               num = 0;\r
+\r
+                                               for (i = 0;i < t.NumSession;i++)\r
+                                               {\r
+                                                       RPC_ENUM_SESSION_ITEM *e = &t.Sessions[i];\r
+\r
+                                                       if (e->BridgeMode == false && e->Layer3Mode == false && e->LinkMode == false && e->CurrentNumTcp != 0)\r
+                                                       {\r
+                                                               if (StrCmpi(e->Username, username) == 0 &&\r
+                                                                       (IsZero(e->UniqueId, 16) || Cmp(e->UniqueId, node.UniqueId, 16) != 0))\r
+                                                               {\r
+                                                                       num++;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+\r
+                                               FreeRpcEnumSession(&t);\r
+\r
+                                               if (num >= max_logins)\r
+                                               {\r
+                                                       // これ以上接続できない\r
+                                                       Unlock(hub->lock);\r
+\r
+                                                       // 詳細エラーログを吐く\r
+                                                       HLog(hub, license.NumUserLicense == INFINITE ? "LH_TOO_MANY_MULTILOGINS" : "LH_TOO_MANY_MULTILOGINS2",\r
+                                                               c->Name,\r
+                                                               username, max_logins, num);\r
+\r
+                                                       ReleaseHub(hub);\r
+                                                       c->Err = ERR_TOO_MANY_USER_SESSION;\r
+                                                       Free(policy);\r
+                                                       goto CLEANUP;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       if (loggedin_user_object != NULL)\r
+                       {\r
+                               // ユーザー情報の更新\r
+                               Lock(loggedin_user_object->lock);\r
+                               {\r
+                                       loggedin_user_object->NumLogin++;\r
+                                       loggedin_user_object->LastLoginTime = SystemTime64();\r
+                               }\r
+                               Unlock(loggedin_user_object->lock);\r
+                       }\r
+\r
+                       // ログイン回数を更新する\r
+                       hub->NumLogin++;\r
+                       hub->LastCommTime = hub->LastLoginTime = SystemTime64();\r
+\r
+                       if (farm_controller)\r
+                       {\r
+                               wchar_t *msg = GetHubMsg(hub);\r
+\r
+                               Unlock(hub->lock);\r
+\r
+                               Lock(cedar->CedarSuperLock);\r
+\r
+                               // ファームコントローラの場合、この HUB をホスティングする\r
+                               // ファームメンバを選定する\r
+                               LockList(server->FarmMemberList);\r
+                               {\r
+                                       HLog(hub, "LH_FARM_SELECT_1", c->Name);\r
+                                       f = SiGetHubHostingMember(server, hub, admin_mode);\r
+\r
+                                       if (f == NULL)\r
+                                       {\r
+                                               // 選定に失敗した\r
+                                               HLog(hub, "LH_FARM_SELECT_2", c->Name);\r
+                                               UnlockList(server->FarmMemberList);\r
+                                               Unlock(cedar->CedarSuperLock);\r
+                                               ReleaseHub(hub);\r
+                                               c->Err = ERR_COULD_NOT_HOST_HUB_ON_FARM;\r
+                                               Free(policy);\r
+                                               Free(msg);\r
+                                               goto CLEANUP;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (f->Me == false)\r
+                                               {\r
+                                                       UCHAR ticket[SHA1_SIZE];\r
+                                                       PACK *p;\r
+                                                       BUF *b;\r
+                                                       UINT i;\r
+\r
+                                                       SLog(c->Cedar, "LH_FARM_SELECT_4", c->Name, f->hostname);\r
+\r
+                                                       // 選定したサーバーファームメンバにセッションを作成する\r
+                                                       Rand(ticket, sizeof(ticket));\r
+                                                       SiCallCreateTicket(server, f, hub->Name,\r
+                                                               username, username_real, policy, ticket, Inc(hub->SessionCounter), groupname);\r
+\r
+                                                       p = NewPack();\r
+                                                       PackAddInt(p, "Redirect", 1);\r
+                                                       PackAddIp32(p, "Ip", f->Ip);\r
+                                                       for (i = 0;i < f->NumPort;i++)\r
+                                                       {\r
+                                                               PackAddIntEx(p, "Port", f->Ports[i], i, f->NumPort);\r
+                                                       }\r
+                                                       PackAddData(p, "Ticket", ticket, sizeof(ticket));\r
+\r
+                                                       if (true)\r
+                                                       {\r
+                                                               char *utf = CopyUniToUtf(msg);\r
+\r
+                                                               PackAddData(p, "Msg", utf, StrLen(utf));\r
+\r
+                                                               Free(utf);\r
+                                                       }\r
+\r
+                                                       b = XToBuf(f->ServerCert, false);\r
+                                                       PackAddBuf(p, "Cert", b);\r
+                                                       FreeBuf(b);\r
+\r
+                                                       UnlockList(server->FarmMemberList);\r
+                                                       Unlock(cedar->CedarSuperLock);\r
+                                                       ReleaseHub(hub);\r
+\r
+                                                       HttpServerSend(c->FirstSock, p);\r
+                                                       FreePack(p);\r
+\r
+                                                       c->Err = 0;\r
+                                                       Free(policy);\r
+\r
+                                                       FreePack(HttpServerRecv(c->FirstSock));\r
+                                                       Free(msg);\r
+                                                       goto CLEANUP;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       HLog(hub, "LH_FARM_SELECT_3", c->Name);\r
+                                                       // 自分自身が選定されたのでこのまま続ける\r
+                                                       UnlockList(server->FarmMemberList);\r
+                                                       Unlock(cedar->CedarSuperLock);\r
+                                                       f->Point = SiGetPoint(server);\r
+                                                       Lock(hub->lock);\r
+                                                       Free(msg);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       if (admin_mode == false)\r
+                       {\r
+                               // HUB の最大接続数をチェック\r
+                               if (hub->Option->MaxSession != 0 &&\r
+                                       hub->Option->MaxSession <= Count(hub->NumSessions))\r
+                               {\r
+                                       // これ以上接続できない\r
+                                       Unlock(hub->lock);\r
+\r
+                                       HLog(hub, "LH_MAX_SESSION", c->Name, hub->Option->MaxSession);\r
+\r
+                                       ReleaseHub(hub);\r
+                                       c->Err = ERR_HUB_IS_BUSY;\r
+                                       Free(policy);\r
+                                       goto CLEANUP;\r
+                               }\r
+                       }\r
+\r
+                       if (use_client_license || use_bridge_license)\r
+                       {\r
+                               // 仮想 HUB 管理オプションで規定された同時接続セッション数\r
+                               // の制限に抵触しないかどうか調べる\r
+                               if (\r
+                                       (GetHubAdminOption(hub, "max_sessions") != 0 &&\r
+                                       (Count(hub->NumSessionsClient) + Count(hub->NumSessionsBridge)) >= GetHubAdminOption(hub, "max_sessions"))\r
+                                       ||\r
+                                       (hub->Option->MaxSession != 0 &&\r
+                                       (Count(hub->NumSessionsClient) + Count(hub->NumSessionsBridge)) >= hub->Option->MaxSession))\r
+                               {\r
+                                       // これ以上接続できない\r
+                                       Unlock(hub->lock);\r
+\r
+                                       HLog(hub, "LH_MAX_SESSION", c->Name, GetHubAdminOption(hub, "max_sessions"));\r
+\r
+                                       ReleaseHub(hub);\r
+                                       c->Err = ERR_HUB_IS_BUSY;\r
+                                       Free(policy);\r
+                                       goto CLEANUP;\r
+                               }\r
+                       }\r
+\r
+                       if (use_client_license)\r
+                       {\r
+                               // 仮想 HUB 管理オプションで規定された同時接続セッション数 (クライアント)\r
+                               // の制限に抵触しないかどうか調べる\r
+                               if (((GetHubAdminOption(hub, "max_sessions_client_bridge_apply") != 0 || license.CarrierEdition) &&\r
+                                       Count(hub->NumSessionsClient) >= GetHubAdminOption(hub, "max_sessions_client") && hub->Cedar->Server != NULL && hub->Cedar->Server->ServerType != SERVER_TYPE_FARM_MEMBER)\r
+                                       ||\r
+                                       (hub->FarmMember_MaxSessionClientBridgeApply &&\r
+                                       Count(hub->NumSessionsClient) >= hub->FarmMember_MaxSessionClient))\r
+                               {\r
+                                       // これ以上接続できない\r
+                                       Unlock(hub->lock);\r
+\r
+                                       HLog(hub, "LH_MAX_SESSION_CLIENT", c->Name, GetHubAdminOption(hub, "max_sessions_client"));\r
+\r
+                                       ReleaseHub(hub);\r
+                                       c->Err = ERR_HUB_IS_BUSY;\r
+                                       Free(policy);\r
+                                       goto CLEANUP;\r
+                               }\r
+                       }\r
+\r
+                       if (use_bridge_license)\r
+                       {\r
+                               // 仮想 HUB 管理オプションで規定された同時接続セッション数 (ブリッジ)\r
+                               // の制限に抵触しないかどうか調べる\r
+                               if (((GetHubAdminOption(hub, "max_sessions_client_bridge_apply") != 0 || license.CarrierEdition) &&\r
+                                       Count(hub->NumSessionsBridge) >= GetHubAdminOption(hub, "max_sessions_bridge") && hub->Cedar->Server != NULL && hub->Cedar->Server->ServerType != SERVER_TYPE_FARM_MEMBER)\r
+                                       ||\r
+                                       (hub->FarmMember_MaxSessionClientBridgeApply &&\r
+                                       Count(hub->NumSessionsBridge) >= hub->FarmMember_MaxSessionBridge))\r
+                               {\r
+                                       // これ以上接続できない\r
+                                       Unlock(hub->lock);\r
+\r
+                                       HLog(hub, "LH_MAX_SESSION_BRIDGE", c->Name, GetHubAdminOption(hub, "max_sessions_bridge"));\r
+\r
+                                       ReleaseHub(hub);\r
+                                       c->Err = ERR_HUB_IS_BUSY;\r
+                                       Free(policy);\r
+                                       goto CLEANUP;\r
+                               }\r
+                       }\r
+\r
+                       if (Count(hub->Cedar->CurrentSessions) >= GetServerCapsInt(hub->Cedar->Server, "i_max_sessions"))\r
+                       {\r
+                               // これ以上接続できない\r
+                               Unlock(hub->lock);\r
+\r
+                               HLog(hub, "LH_MAX_SESSION_2", c->Name, GetServerCapsInt(hub->Cedar->Server, "i_max_sessions"));\r
+\r
+                               ReleaseHub(hub);\r
+                               c->Err = ERR_HUB_IS_BUSY;\r
+                               Free(policy);\r
+                               goto CLEANUP;\r
+                       }\r
+\r
+                       // 現在の接続数をインクリメント\r
+                       Inc(hub->NumSessions);\r
+                       if (use_bridge_license)\r
+                       {\r
+                               Inc(hub->NumSessionsBridge);\r
+                       }\r
+\r
+                       if (use_client_license)\r
+                       {\r
+                               Inc(hub->NumSessionsClient);\r
+                       }\r
+                       Inc(hub->Cedar->CurrentSessions);\r
+\r
+                       // タイムアウト時間を計算\r
+                       timeout = policy->TimeOut * 1000;       // ミリ秒 → 秒 に変換\r
+                       if (timeout == 0)\r
+                       {\r
+                               timeout = TIMEOUT_DEFAULT;\r
+                       }\r
+                       timeout = MIN(timeout, TIMEOUT_MAX);\r
+                       timeout = MAX(timeout, TIMEOUT_MIN);\r
+\r
+                       // ポリシーに応じて max_connection を更新\r
+                       max_connection = MIN(max_connection, policy->MaxConnection);\r
+                       max_connection = MIN(max_connection, MAX_TCP_CONNECTION);\r
+                       max_connection = MAX(max_connection, 1);\r
+                       if (half_connection)\r
+                       {\r
+                               // Half Connection 時にはコネクション数は 2 以上とする\r
+                               max_connection = MAX(max_connection, 2);\r
+                       }\r
+\r
+                       if (qos)\r
+                       {\r
+                               // VoIP / QoS 使用時にはコネクション数は 2 以上とする\r
+                               max_connection = MAX(max_connection, 2);\r
+                               if (half_connection)\r
+                               {\r
+                                       max_connection = MAX(max_connection, 4);\r
+                               }\r
+                       }\r
+\r
+                       c->Status = CONNECTION_STATUS_ESTABLISHED;\r
+\r
+                       // コネクションを Cedar から削除\r
+                       DelConnection(c->Cedar, c);\r
+\r
+                       // セッションの作成\r
+                       StrLower(username);\r
+                       s = NewServerSession(c->Cedar, c, hub, username, policy);\r
+\r
+                       if (server != NULL)\r
+                       {\r
+                               s->NoSendSignature = server->NoSendSignature;\r
+                       }\r
+\r
+                       s->UseClientLicense = use_client_license;\r
+                       s->UseBridgeLicense = use_bridge_license;\r
+\r
+                       s->IsBridgeMode = (policy->NoBridge == false) || (policy->NoRouting == false);\r
+                       s->IsMonitorMode = policy->MonitorPort;\r
+\r
+                       // IPv6 セッションかどうかの判定\r
+                       s->IPv6Session = false;\r
+\r
+                       if (node.ClientIpAddress == 0)\r
+                       {\r
+                               s->IPv6Session = true;\r
+                       }\r
+\r
+                       if (use_bridge_license)\r
+                       {\r
+                               Inc(s->Cedar->AssignedBridgeLicense);\r
+                       }\r
+\r
+                       if (use_client_license)\r
+                       {\r
+                               Inc(s->Cedar->AssignedClientLicense);\r
+                       }\r
+\r
+                       if (server != NULL)\r
+                       {\r
+                               // Server 構造体の合計割り当て済みライセンス数の更新\r
+                               if (server->ServerType == SERVER_TYPE_STANDALONE)\r
+                               {\r
+                                       // スタンドアロンモードのみ更新\r
+                                       // (クラスタコントローラモードでは定期的にポーリングしている)\r
+                                       server->CurrentAssignedClientLicense = Count(s->Cedar->AssignedClientLicense);\r
+                                       server->CurrentAssignedBridgeLicense = Count(s->Cedar->AssignedBridgeLicense);\r
+                               }\r
+                       }\r
+\r
+                       if (StrLen(sessionname) != 0)\r
+                       {\r
+                               // セッション名の指定\r
+                               Free(s->Name);\r
+                               s->Name = CopyStr(sessionname);\r
+                       }\r
+\r
+                       {\r
+                               char ip[128];\r
+                               IPToStr(ip, sizeof(ip), &c->FirstSock->RemoteIP);\r
+                               HLog(hub, "LH_NEW_SESSION", c->Name, s->Name, ip, c->FirstSock->RemotePort);\r
+                       }\r
+\r
+                       c->Session = s;\r
+                       s->AdministratorMode = admin_mode;\r
+                       StrCpy(s->UserNameReal, sizeof(s->UserNameReal), username_real);\r
+                       StrCpy(s->GroupName, sizeof(s->GroupName), groupname);\r
+\r
+                       // セッションキーの取得\r
+                       Copy(session_key, s->SessionKey, SHA1_SIZE);\r
+\r
+                       // パラメータをセット\r
+                       s->MaxConnection = max_connection;\r
+                       s->UseEncrypt = use_encrypt;\r
+                       if (s->UseEncrypt && use_fast_rc4)\r
+                       {\r
+                               s->UseFastRC4 = use_fast_rc4;\r
+                       }\r
+                       s->UseCompress = use_compress;\r
+                       s->HalfConnection = half_connection;\r
+                       s->Timeout = timeout;\r
+                       s->QoS = qos;\r
+\r
+                       if (policy != NULL)\r
+                       {\r
+                               s->VLanId = policy->VLanId;\r
+                       }\r
+\r
+                       // ユーザー名\r
+                       s->Username = CopyStr(username);\r
+\r
+                       HLog(hub, "LH_SET_SESSION", s->Name, s->MaxConnection,\r
+                               s->UseEncrypt ? _UU("L_YES") : _UU("L_NO"),\r
+                               s->UseCompress ? _UU("L_YES") : _UU("L_NO"),\r
+                               s->HalfConnection ? _UU("L_YES") : _UU("L_NO"),\r
+                               s->Timeout / 1000);\r
+\r
+                       msg = GetHubMsg(hub);\r
+               }\r
+               Unlock(hub->lock);\r
+\r
+               // クライアントに Welcome パケットを送信\r
+               p = PackWelcome(s);\r
+\r
+               if (true)\r
+               {\r
+                       // VPN Client に表示するメッセージ\r
+                       char *utf;\r
+                       wchar_t winver_msg_client[3800];\r
+                       wchar_t winver_msg_server[3800];\r
+                       wchar_t *utvpn_msg;\r
+                       UINT tmpsize;\r
+                       wchar_t *tmp;\r
+                       RPC_WINVER server_winver;\r
+\r
+                       GetWinVer(&server_winver);\r
+\r
+                       Zero(winver_msg_client, sizeof(winver_msg_client));\r
+                       Zero(winver_msg_server, sizeof(winver_msg_server));\r
+\r
+                       utvpn_msg = _UU("UTVPN_MSG");\r
+\r
+                       if (IsSupportedWinVer(&winver) == false)\r
+                       {\r
+                               SYSTEMTIME st;\r
+\r
+                               LocalTime(&st);\r
+\r
+                               UniFormat(winver_msg_client, sizeof(winver_msg_client), _UU("WINVER_ERROR_FORMAT"),\r
+                                       _UU("WINVER_ERROR_PC_LOCAL"),\r
+                                       winver.Title,\r
+                                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                                       SUPPORTED_WINDOWS_LIST,\r
+                                       _UU("WINVER_ERROR_PC_LOCAL"),\r
+                                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                                       st.wYear, st.wMonth);\r
+                       }\r
+\r
+                       if (IsSupportedWinVer(&server_winver) == false)\r
+                       {\r
+                               SYSTEMTIME st;\r
+\r
+                               LocalTime(&st);\r
+\r
+                               UniFormat(winver_msg_server, sizeof(winver_msg_server), _UU("WINVER_ERROR_FORMAT"),\r
+                                       _UU("WINVER_ERROR_PC_REMOTE"),\r
+                                       server_winver.Title,\r
+                                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                                       SUPPORTED_WINDOWS_LIST,\r
+                                       _UU("WINVER_ERROR_PC_REMOTE"),\r
+                                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                                       _UU("WINVER_ERROR_VPNSERVER"),\r
+                                       st.wYear, st.wMonth);\r
+                       }\r
+\r
+                       tmpsize = UniStrSize(winver_msg_client) + UniStrSize(winver_msg_server) + UniStrSize(utvpn_msg) + UniStrSize(msg) * 100;\r
+\r
+                       tmp = ZeroMalloc(tmpsize);\r
+\r
+                       if (IsURLMsg(msg, NULL, 0) == false)\r
+                       {\r
+                               UniStrCat(tmp, tmpsize, utvpn_msg);\r
+                               UniStrCat(tmp, tmpsize, winver_msg_client);\r
+                               UniStrCat(tmp, tmpsize, winver_msg_server);\r
+                       }\r
+                       UniStrCat(tmp, tmpsize, msg);\r
+                       \r
+                       utf = CopyUniToUtf(tmp);\r
+\r
+                       PackAddData(p, "Msg", utf, StrLen(utf));\r
+\r
+                       Free(tmp);\r
+                       Free(utf);\r
+               }\r
+\r
+               Free(msg);\r
+\r
+               if (s->UseFastRC4)\r
+               {\r
+                       // RC4 キーペアを生成\r
+                       GenerateRC4KeyPair(&key_pair);\r
+\r
+                       // Welcome パケットに追加\r
+                       PackAddData(p, "rc4_key_client_to_server", key_pair.ClientToServerKey, sizeof(key_pair.ClientToServerKey));\r
+                       PackAddData(p, "rc4_key_server_to_client", key_pair.ServerToClientKey, sizeof(key_pair.ServerToClientKey));\r
+                       {\r
+                               char key1[64], key2[64];\r
+                               BinToStr(key1, sizeof(key1), key_pair.ClientToServerKey, 16);\r
+                               BinToStr(key2, sizeof(key2), key_pair.ServerToClientKey, 16);\r
+                               Debug(\r
+                                       "Client to Server Key: %s\n"\r
+                                       "Server to Client Key: %s\n",\r
+                                       key1, key2);\r
+                       }\r
+               }\r
+               HttpServerSend(c->FirstSock, p);\r
+               FreePack(p);\r
+\r
+               Copy(&c->Session->NodeInfo, &node, sizeof(NODE_INFO));\r
+               {\r
+                       wchar_t tmp[MAX_SIZE * 2];\r
+                       NodeInfoToStr(tmp, sizeof(tmp), &s->NodeInfo);\r
+\r
+                       HLog(hub, "LH_NODE_INFO", s->Name, tmp);\r
+               }\r
+\r
+               // コネクションをトンネリングモードに移行\r
+               StartTunnelingMode(c);\r
+\r
+               // ハーフコネクションモード時の処理\r
+               if (s->HalfConnection)\r
+               {\r
+                       // 1 つ目のソケットはクライアント→サーバー 方向 とする\r
+                       TCPSOCK *ts = (TCPSOCK *)LIST_DATA(c->Tcp->TcpSockList, 0);\r
+                       ts->Direction = TCP_CLIENT_TO_SERVER;\r
+               }\r
+\r
+               if (s->UseFastRC4)\r
+               {\r
+                       // 1 つ目の TCP コネクションに RC4 キー情報をセットする\r
+                       TCPSOCK *ts = (TCPSOCK *)LIST_DATA(c->Tcp->TcpSockList, 0);\r
+                       Copy(&ts->Rc4KeyPair, &key_pair, sizeof(RC4_KEY_PAIR));\r
+\r
+                       InitTcpSockRc4Key(ts, true);\r
+               }\r
+\r
+               if (s->UseEncrypt && s->UseFastRC4 == false)\r
+               {\r
+                       s->UseSSLDataEncryption = true;\r
+               }\r
+               else\r
+               {\r
+                       s->UseSSLDataEncryption = false;\r
+               }\r
+\r
+               if (s->Hub->Type == HUB_TYPE_FARM_DYNAMIC && s->Cedar->Server != NULL && s->Cedar->Server->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+               {\r
+                       if (s->Hub->BeingOffline == false)\r
+                       {\r
+                               // ダイナミック仮想 HUB で SecureNAT を開始\r
+                               EnableSecureNATEx(s->Hub, false, true);\r
+\r
+                               cluster_dynamic_secure_nat = true;\r
+                       }\r
+               }\r
+\r
+               // セッションのメインルーチン\r
+               SessionMain(s);\r
+\r
+               // 現在の接続数をデクリメント\r
+               Lock(s->Hub->lock);\r
+               {\r
+                       if (use_bridge_license)\r
+                       {\r
+                               Dec(hub->NumSessionsBridge);\r
+                       }\r
+\r
+                       if (use_client_license)\r
+                       {\r
+                               Dec(hub->NumSessionsClient);\r
+                       }\r
+\r
+                       Dec(s->Hub->NumSessions);\r
+                       Dec(s->Hub->Cedar->CurrentSessions);\r
+\r
+                       // ライセンス数のデクリメント\r
+                       if (use_bridge_license)\r
+                       {\r
+                               Dec(s->Cedar->AssignedBridgeLicense);\r
+                       }\r
+\r
+                       if (use_client_license)\r
+                       {\r
+                               Dec(s->Cedar->AssignedClientLicense);\r
+                       }\r
+\r
+                       if (server != NULL)\r
+                       {\r
+                               // Server 構造体の合計割り当て済みライセンス数の更新\r
+                               if (server->ServerType == SERVER_TYPE_STANDALONE)\r
+                               {\r
+                                       // スタンドアロンモードのみ更新\r
+                                       // (クラスタコントローラモードでは定期的にポーリングしている)\r
+                                       server->CurrentAssignedClientLicense = Count(s->Cedar->AssignedClientLicense);\r
+                                       server->CurrentAssignedBridgeLicense = Count(s->Cedar->AssignedBridgeLicense);\r
+                               }\r
+                       }\r
+               }\r
+               Unlock(s->Hub->lock);\r
+\r
+               PrintSessionTotalDataSize(s);\r
+\r
+               HLog(s->Hub, "LH_END_SESSION", s->Name, s->TotalSendSizeReal, s->TotalRecvSizeReal);\r
+\r
+               if (cluster_dynamic_secure_nat && s->Hub->BeingOffline == false)\r
+               {\r
+                       // ダイナミック仮想 HUB で SecureNAT を停止\r
+                       EnableSecureNATEx(s->Hub, false, true);\r
+               }\r
+\r
+               ReleaseSession(s);\r
+\r
+               ret = true;\r
+               c->Err = ERR_SESSION_REMOVED;\r
+\r
+               ReleaseHub(hub);\r
+\r
+               goto CLEANUP;\r
+       }\r
+       else if (StrCmpi(method, "additional_connect") == 0)\r
+       {\r
+               SOCK *sock;\r
+               TCPSOCK *ts;\r
+               UINT dummy;\r
+\r
+               c->Type = CONNECTION_TYPE_ADDITIONAL;\r
+\r
+               // 追加接続\r
+               // セッションキーを読み出し\r
+               if (GetSessionKeyFromPack(p, session_key, &dummy) == false)\r
+               {\r
+                       FreePack(p);\r
+                       c->Err = ERR_PROTOCOL_ERROR;\r
+                       goto CLEANUP;\r
+               }\r
+\r
+               FreePack(p);\r
+\r
+               // セッションキーからセッションを取得\r
+               s = GetSessionFromKey(c->Cedar, session_key);\r
+               if (s == NULL || s->Halt)\r
+               {\r
+                       // セッションが発見できない\r
+                       Debug("Session Not Found.\n");\r
+                       c->Err = ERR_SESSION_TIMEOUT;\r
+                       goto CLEANUP;\r
+               }\r
+\r
+               // セッションが見つかった\r
+               Debug("Session Found: %s\n", s->Name);\r
+               // セッションのプロトコルを確認\r
+               c->Err = 0;\r
+               Lock(s->lock);\r
+               {\r
+                       if (s->Connection->Protocol != CONNECTION_TCP)\r
+                       {\r
+                               c->Err = ERR_INVALID_PROTOCOL;\r
+                       }\r
+               }\r
+               Unlock(s->lock);\r
+               // セッションの現在のコネクション数を調べる\r
+               Lock(s->Connection->lock);\r
+               if (c->Err == 0)\r
+               {\r
+                       if (Count(s->Connection->CurrentNumConnection) > s->MaxConnection)\r
+                       {\r
+                               c->Err = ERR_TOO_MANY_CONNECTION;\r
+                       }\r
+               }\r
+               if (c->Err != 0)\r
+               {\r
+                       Unlock(s->Connection->lock);\r
+                       if (c->Err == ERR_TOO_MANY_CONNECTION)\r
+                       {\r
+                               Debug("Session TOO MANY CONNECTIONS !!: %u\n",\r
+                                       Count(s->Connection->CurrentNumConnection));\r
+                       }\r
+                       else\r
+                       {\r
+                               Debug("Session Invalid Protocol.\n");\r
+                       }\r
+                       ReleaseSession(s);\r
+                       goto CLEANUP;\r
+               }\r
+\r
+               // RC4 高速暗号化鍵の生成\r
+               if (s->UseFastRC4)\r
+               {\r
+                       GenerateRC4KeyPair(&key_pair);\r
+               }\r
+\r
+               // セッションのコネクションリスト (TCP) にこのコネクションのソケットを追加する\r
+               sock = c->FirstSock;\r
+               ts = NewTcpSock(sock);\r
+               SetTimeout(sock, CONNECTING_TIMEOUT);\r
+               direction = TCP_BOTH;\r
+               LockList(s->Connection->Tcp->TcpSockList);\r
+               {\r
+                       if (s->HalfConnection)\r
+                       {\r
+                               // ハーフコネクション時、現在のすべての TCP コネクションの方向を\r
+                               // 調べて自動的に調整する\r
+                               UINT i, c2s, s2c;\r
+                               c2s = s2c = 0;\r
+                               for (i = 0;i < LIST_NUM(s->Connection->Tcp->TcpSockList);i++)\r
+                               {\r
+                                       TCPSOCK *ts = (TCPSOCK *)LIST_DATA(s->Connection->Tcp->TcpSockList, i);\r
+                                       if (ts->Direction == TCP_SERVER_TO_CLIENT)\r
+                                       {\r
+                                               s2c++;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               c2s++;\r
+                                       }\r
+                               }\r
+                               if (s2c > c2s)\r
+                               {\r
+                                       direction = TCP_CLIENT_TO_SERVER;\r
+                               }\r
+                               else\r
+                               {\r
+                                       direction = TCP_SERVER_TO_CLIENT;\r
+                               }\r
+                               Debug("%u/%u\n", s2c, c2s);\r
+                               ts->Direction = direction;\r
+                       }\r
+               }\r
+               UnlockList(s->Connection->Tcp->TcpSockList);\r
+\r
+               if (s->UseFastRC4)\r
+               {\r
+                       // RC4 鍵情報の設定\r
+                       Copy(&ts->Rc4KeyPair, &key_pair, sizeof(RC4_KEY_PAIR));\r
+\r
+                       InitTcpSockRc4Key(ts, true);\r
+               }\r
+\r
+               // 成功結果を返す\r
+               p = PackError(ERR_NO_ERROR);\r
+               PackAddInt(p, "direction", direction);\r
+\r
+               if (s->UseFastRC4)\r
+               {\r
+                       // RC4 鍵情報の追加\r
+                       PackAddData(p, "rc4_key_client_to_server", key_pair.ClientToServerKey, sizeof(key_pair.ClientToServerKey));\r
+                       PackAddData(p, "rc4_key_server_to_client", key_pair.ServerToClientKey, sizeof(key_pair.ServerToClientKey));\r
+                       {\r
+                               char key1[64], key2[64];\r
+                               BinToStr(key1, sizeof(key1), key_pair.ClientToServerKey, 16);\r
+                               BinToStr(key2, sizeof(key2), key_pair.ServerToClientKey, 16);\r
+                               Debug(\r
+                                       "Client to Server Key: %s\n"\r
+                                       "Server to Client Key: %s\n",\r
+                                       key1, key2);\r
+                       }\r
+               }\r
+\r
+               HttpServerSend(c->FirstSock, p);\r
+               FreePack(p);\r
+\r
+               SetTimeout(sock, INFINITE);\r
+\r
+               LockList(s->Connection->Tcp->TcpSockList);\r
+               {\r
+                       Add(s->Connection->Tcp->TcpSockList, ts);\r
+               }\r
+               UnlockList(s->Connection->Tcp->TcpSockList);\r
+\r
+               // コネクション数をインクリメントする\r
+               Inc(s->Connection->CurrentNumConnection);\r
+               Debug("TCP Connection Incremented: %u\n", Count(s->Connection->CurrentNumConnection));\r
+\r
+               // セッションの Cancel を発行する\r
+               Cancel(s->Cancel1);\r
+\r
+               Unlock(s->Connection->lock);\r
+\r
+               c->flag1 = true;\r
+\r
+               ReleaseSession(s);\r
+\r
+               return true;\r
+       }\r
+       else if (StrCmpi(method, "enum_hub") == 0)\r
+       {\r
+               // 仮想 HUB の列挙\r
+               UINT i, num;\r
+               LIST *o;\r
+               o = NewListFast(NULL);\r
+\r
+               c->Type = CONNECTION_TYPE_ENUM_HUB;\r
+\r
+               FreePack(p);\r
+               p = NewPack();\r
+               LockList(c->Cedar->HubList);\r
+               {\r
+                       num = LIST_NUM(c->Cedar->HubList);\r
+                       for (i = 0;i < num;i++)\r
+                       {\r
+                               HUB *h = LIST_DATA(c->Cedar->HubList, i);\r
+                               if (h->Option != NULL && h->Option->NoEnum == false)\r
+                               {\r
+                                       Insert(o, CopyStr(h->Name));\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(c->Cedar->HubList);\r
+\r
+               num = LIST_NUM(o);\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       char *name = LIST_DATA(o, i);\r
+                       PackAddStrEx(p, "HubName", name, i, num);\r
+                       Free(name);\r
+               }\r
+               ReleaseList(o);\r
+               PackAddInt(p, "NumHub", num);\r
+\r
+               HttpServerSend(c->FirstSock, p);\r
+               FreePack(p);\r
+               FreePack(HttpServerRecv(c->FirstSock));\r
+               c->Err = 0;\r
+\r
+               SLog(c->Cedar, "LS_ENUM_HUB", c->Name, num);\r
+\r
+               goto CLEANUP;\r
+       }\r
+       else if (StrCmpi(method, "farm_connect") == 0)\r
+       {\r
+               // サーバーファーム接続要求\r
+               CEDAR *cedar = c->Cedar;\r
+               c->Type = CONNECTION_TYPE_FARM_RPC;\r
+               c->Err = 0;\r
+               if (c->Cedar->Server == NULL)\r
+               {\r
+                       // サポートされていない\r
+                       c->Err = ERR_NOT_FARM_CONTROLLER;\r
+               }\r
+               else\r
+               {\r
+                       SERVER *s = c->Cedar->Server;\r
+                       if (s->ServerType != SERVER_TYPE_FARM_CONTROLLER || s->FarmControllerInited == false)\r
+                       {\r
+                               // ファームコントローラではない\r
+                               SLog(c->Cedar, "LS_FARM_ACCEPT_1", c->Name);\r
+                               c->Err = ERR_NOT_FARM_CONTROLLER;\r
+                       }\r
+                       else\r
+                       {\r
+                               UCHAR check_secure_password[SHA1_SIZE];\r
+                               UCHAR secure_password[SHA1_SIZE];\r
+                               // ユーザー認証\r
+                               SecurePassword(check_secure_password, s->HashedPassword, c->Random);\r
+                               if (PackGetDataSize(p, "SecurePassword") == sizeof(secure_password))\r
+                               {\r
+                                       PackGetData(p, "SecurePassword", secure_password);\r
+                               }\r
+                               else\r
+                               {\r
+                                       Zero(secure_password, sizeof(secure_password));\r
+                               }\r
+\r
+                               if (Cmp(secure_password, check_secure_password, SHA1_SIZE) != 0)\r
+                               {\r
+                                       // パスワードが違う\r
+                                       SLog(c->Cedar, "LS_FARM_ACCEPT_2", c->Name);\r
+                                       c->Err = ERR_ACCESS_DENIED;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 証明書を取得する\r
+                                       BUF *b;\r
+                                       X *server_x;\r
+\r
+                                       SLog(c->Cedar, "LS_FARM_ACCEPT_3", c->Name);\r
+                                       b = PackGetBuf(p, "ServerCert");\r
+                                       if (b == NULL)\r
+                                       {\r
+                                               c->Err = ERR_PROTOCOL_ERROR;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               server_x = BufToX(b, false);\r
+                                               FreeBuf(b);\r
+                                               if (server_x == NULL)\r
+                                               {\r
+                                                       c->Err = ERR_PROTOCOL_ERROR;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       UINT ip;\r
+                                                       UINT point;\r
+                                                       char hostname[MAX_SIZE];\r
+\r
+#ifdef OS_WIN32\r
+                                                       MsSetThreadPriorityRealtime();\r
+#endif // OS_WIN32\r
+\r
+                                                       SetTimeout(c->FirstSock, SERVER_CONTROL_TCP_TIMEOUT);\r
+\r
+                                                       ip = PackGetIp32(p, "PublicIp");\r
+                                                       point = PackGetInt(p, "Point");\r
+                                                       if (PackGetStr(p, "HostName", hostname, sizeof(hostname)))\r
+                                                       {\r
+                                                               UINT num_port = PackGetIndexCount(p, "PublicPort");\r
+                                                               if (num_port >= 1 && num_port <= MAX_PUBLIC_PORT_NUM)\r
+                                                               {\r
+                                                                       UINT *ports = ZeroMalloc(sizeof(UINT) * num_port);\r
+                                                                       UINT i;\r
+\r
+                                                                       for (i = 0;i < num_port;i++)\r
+                                                                       {\r
+                                                                               ports[i] = PackGetIntEx(p, "PublicPort", i);\r
+                                                                       }\r
+\r
+                                                                       SiFarmServ(s, c->FirstSock, server_x, ip, num_port, ports, hostname, point,\r
+                                                                               PackGetInt(p, "Weight"), PackGetInt(p, "MaxSessions"));\r
+\r
+                                                                       Free(ports);\r
+                                                               }\r
+                                                       }\r
+\r
+                                                       FreeX(server_x);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               FreePack(p);\r
+               goto CLEANUP;\r
+       }\r
+       else if (StrCmpi(method, "admin") == 0 && c->Cedar->Server != NULL)\r
+       {\r
+               UINT err;\r
+               // 管理用 RPC 接続要求\r
+               c->Type = CONNECTION_TYPE_ADMIN_RPC;\r
+               err = AdminAccept(c, p);\r
+               FreePack(p);\r
+               if (err != ERR_NO_ERROR)\r
+               {\r
+                       PACK *p = PackError(err);\r
+                       HttpServerSend(c->FirstSock, p);\r
+                       FreePack(p);\r
+               }\r
+               goto CLEANUP;\r
+       }\r
+       else if (StrCmpi(method, "password") == 0)\r
+       {\r
+               UINT err;\r
+               // パスワード変更要求\r
+               c->Type = CONNECTION_TYPE_PASSWORD;\r
+               err = ChangePasswordAccept(c, p);\r
+               FreePack(p);\r
+\r
+               p = PackError(err);\r
+               HttpServerSend(c->FirstSock, p);\r
+               FreePack(p);\r
+               goto CLEANUP;\r
+       }\r
+       else\r
+       {\r
+               // 不明なメソッド\r
+               FreePack(p);\r
+               c->Err = ERR_PROTOCOL_ERROR;\r
+               goto CLEANUP;\r
+       }\r
+\r
+CLEANUP:\r
+       // ユーザーオブジェクトの解放\r
+       if (loggedin_user_object != NULL)\r
+       {\r
+               ReleaseUser(loggedin_user_object);\r
+       }\r
+\r
+       // エラーパケット送信\r
+       p = PackError(c->Err);\r
+       PackAddBool(p, "no_save_password", no_save_password);\r
+       HttpServerSend(c->FirstSock, p);\r
+       FreePack(p);\r
+\r
+       SLog(c->Cedar, "LS_CONNECTION_ERROR", c->Name, GetUniErrorStr(c->Err), c->Err);\r
+\r
+       return ret;\r
+}\r
+// シグネチャの送信 (TCP パケット) 用スレッド\r
+void SendSignatureByTcpThread(THREAD *thread, void *param)\r
+{\r
+       BUF *buf;\r
+       SEND_SIGNATURE_PARAM *p;\r
+       SOCK *s;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = (SEND_SIGNATURE_PARAM *)param;\r
+\r
+       AddWaitThread(thread);\r
+       NoticeThreadInit(thread);\r
+\r
+       buf = p->Buffer;\r
+\r
+       s = Connect(p->Hostname, p->Port);\r
+\r
+       if (s != NULL)\r
+       {\r
+               SendAll(s, buf->Buf, buf->Size, false);\r
+\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+       }\r
+\r
+       DelWaitThread(thread);\r
+\r
+       FreeBuf(buf);\r
+       Free(p);\r
+}\r
+\r
+// シグネチャの送信 (TCP パケット)\r
+void SendSignatureByTcp(CONNECTION *c, IP *ip)\r
+{\r
+       NODE_INFO info;\r
+       BUF *b;\r
+       SEND_SIGNATURE_PARAM *param;\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (c == NULL || ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (c->Session == NULL || c->Session->ClientOption == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CreateNodeInfo(&info, c);\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, CEDAR_SIGNATURE_STR, StrLen(CEDAR_SIGNATURE_STR));\r
+       SeekBuf(b, 0, 0);\r
+\r
+       param = ZeroMalloc(sizeof(SEND_SIGNATURE_PARAM));\r
+       param->Buffer = b;\r
+\r
+       if (c->Session != NULL && c->Session->ClientOption != NULL)\r
+       {\r
+               CLIENT_OPTION *o = c->Session->ClientOption;\r
+\r
+               if (o->ProxyType == PROXY_DIRECT)\r
+               {\r
+                       IPToStr(param->Hostname, sizeof(param->Hostname), ip);\r
+                       param->Port = o->Port;\r
+               }\r
+               else\r
+               {\r
+                       StrCpy(param->Hostname, sizeof(param->Hostname), o->ProxyName);\r
+                       param->Port = o->ProxyPort;\r
+               }\r
+       }\r
+\r
+       t = NewThread(SendSignatureByTcpThread, param);\r
+       WaitThreadInit(t);\r
+       ReleaseThread(t);\r
+}\r
+\r
+// ノード情報の作成\r
+void CreateNodeInfo(NODE_INFO *info, CONNECTION *c)\r
+{\r
+       SESSION *s;\r
+       OS_INFO *os;\r
+       char *product_id;\r
+       IP ip;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = c->Session;\r
+       os = GetOsInfo();\r
+\r
+       Zero(info, sizeof(NODE_INFO));\r
+\r
+       // クライアント製品名\r
+       StrCpy(info->ClientProductName, sizeof(info->ClientProductName), c->ClientStr);\r
+       // クライアントバージョン\r
+       info->ClientProductVer = Endian32(c->ClientVer);\r
+       // クライアントビルド番号\r
+       info->ClientProductBuild = Endian32(c->ClientBuild);\r
+\r
+       // サーバー製品名\r
+       StrCpy(info->ServerProductName, sizeof(info->ServerProductName), c->ServerStr);\r
+       // サーバーバージョン\r
+       info->ServerProductVer = Endian32(c->ServerVer);\r
+       // サーバービルド番号\r
+       info->ServerProductBuild = Endian32(c->ServerBuild);\r
+\r
+       // クライアント OS 名\r
+       StrCpy(info->ClientOsName, sizeof(info->ClientOsName), os->OsProductName);\r
+       // クライアント OS バージョン\r
+       StrCpy(info->ClientOsVer, sizeof(info->ClientOsVer), os->OsVersion);\r
+       // クライアント OS プロダクト ID\r
+       product_id = OSGetProductId();\r
+       StrCpy(info->ClientOsProductId, sizeof(info->ClientOsProductId), product_id);\r
+       Free(product_id);\r
+\r
+       // クライアントホスト名\r
+       GetMachineName(info->ClientHostname, sizeof(info->ClientHostname));\r
+       // クライアント IP アドレス\r
+       if (IsIP6(&c->FirstSock->LocalIP) == false)\r
+       {\r
+               info->ClientIpAddress = IPToUINT(&c->FirstSock->LocalIP);\r
+       }\r
+       else\r
+       {\r
+               Copy(info->ClientIpAddress6, c->FirstSock->LocalIP.ipv6_addr, sizeof(info->ClientIpAddress6));\r
+       }\r
+       // クライアントポート番号\r
+       info->ClientPort = Endian32(c->FirstSock->LocalPort);\r
+\r
+       // サーバーホスト名\r
+       StrCpy(info->ServerHostname, sizeof(info->ServerHostname), c->ServerName);\r
+       // サーバー IP アドレス\r
+       if (GetIP(&ip, info->ServerHostname))\r
+       {\r
+               if (IsIP6(&ip) == false)\r
+               {\r
+                       info->ServerIpAddress = IPToUINT(&ip);\r
+               }\r
+               else\r
+               {\r
+                       Copy(info->ServerIpAddress6, ip.ipv6_addr, sizeof(info->ServerIpAddress6));\r
+               }\r
+       }\r
+       // サーバーポート番号\r
+       info->ServerPort = Endian32(c->ServerPort);\r
+\r
+       if (s->ClientOption->ProxyType == PROXY_SOCKS || s->ClientOption->ProxyType == PROXY_HTTP)\r
+       {\r
+               // プロキシホスト名\r
+               StrCpy(info->ProxyHostname, sizeof(info->ProxyHostname), s->ClientOption->ProxyName);\r
+\r
+               // プロキシ IP アドレス\r
+               if (IsIP6(&c->FirstSock->RemoteIP) == false)\r
+               {\r
+                       info->ProxyIpAddress = IPToUINT(&c->FirstSock->RemoteIP);\r
+               }\r
+               else\r
+               {\r
+                       Copy(&info->ProxyIpAddress6, c->FirstSock->RemoteIP.ipv6_addr, sizeof(info->ProxyIpAddress6));\r
+               }\r
+\r
+               info->ProxyPort = Endian32(c->FirstSock->RemotePort);\r
+       }\r
+\r
+       // HUB 名\r
+       StrCpy(info->HubName, sizeof(info->HubName), s->ClientOption->HubName);\r
+\r
+       // ユニーク ID\r
+       Copy(info->UniqueId, c->Cedar->UniqueId, sizeof(info->UniqueId));\r
+}\r
+\r
+// ソケットを追加接続する\r
+SOCK *ClientAdditionalConnectToServer(CONNECTION *c)\r
+{\r
+       SOCK *s;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // ソケット接続\r
+       s = ClientConnectGetSocket(c, true);\r
+       if (s == NULL)\r
+       {\r
+               // 接続失敗\r
+               return NULL;\r
+       }\r
+\r
+       // ソケットをリストに追加する\r
+       LockList(c->ConnectingSocks);\r
+       {\r
+               Add(c->ConnectingSocks, s);\r
+               AddRef(s->ref);\r
+       }\r
+       UnlockList(c->ConnectingSocks);\r
+\r
+       if (c->Session->Halt)\r
+       {\r
+               // 停止\r
+               Disconnect(s);\r
+               LockList(c->ConnectingSocks);\r
+               {\r
+                       if (Delete(c->ConnectingSocks, s))\r
+                       {\r
+                               ReleaseSock(s);\r
+                       }\r
+               }\r
+               UnlockList(c->ConnectingSocks);\r
+               ReleaseSock(s);\r
+               return NULL;\r
+       }\r
+\r
+       // タイムアウト\r
+       SetTimeout(s, CONNECTING_TIMEOUT);\r
+\r
+       // SSL 通信開始\r
+       if (StartSSLEx(s, NULL, NULL, (c->DontUseTls1 ? false : true)) == false)\r
+       {\r
+               // SSL 通信失敗\r
+               Disconnect(s);\r
+               LockList(c->ConnectingSocks);\r
+               {\r
+                       if (Delete(c->ConnectingSocks, s))\r
+                       {\r
+                               ReleaseSock(s);\r
+                       }\r
+               }\r
+               UnlockList(c->ConnectingSocks);\r
+               ReleaseSock(s);\r
+               return NULL;\r
+       }\r
+\r
+       // 証明書のチェック\r
+       if (CompareX(s->RemoteX, c->ServerX) == false)\r
+       {\r
+               // 証明書が不正\r
+               Disconnect(s);\r
+               c->Session->SessionTimeOuted = true;\r
+       }\r
+\r
+       return s;\r
+}\r
+\r
+// セキュアデバイス内の証明書と鍵を削除する\r
+UINT SecureDelete(UINT device_id, char *pin, char *cert_name, char *key_name)\r
+{\r
+       SECURE *sec;\r
+       // 引数チェック\r
+       if (pin == NULL || device_id == 0)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       // デバイスを開く\r
+       sec = OpenSec(device_id);\r
+       if (sec == NULL)\r
+       {\r
+               return ERR_SECURE_DEVICE_OPEN_FAILED;\r
+       }\r
+\r
+       // セッションを開く\r
+       if (OpenSecSession(sec, 0) == false)\r
+       {\r
+               CloseSec(sec);\r
+               return ERR_SECURE_DEVICE_OPEN_FAILED;\r
+       }\r
+\r
+       // ログイン\r
+       if (LoginSec(sec, pin) == false)\r
+       {\r
+               CloseSecSession(sec);\r
+               CloseSec(sec);\r
+               return ERR_SECURE_PIN_LOGIN_FAILED;\r
+       }\r
+\r
+       // 証明書削除\r
+       if (cert_name != NULL)\r
+       {\r
+               DeleteSecCert(sec, cert_name);\r
+       }\r
+\r
+       // 秘密鍵削除\r
+       if (key_name != NULL)\r
+       {\r
+               DeleteSecKey(sec, key_name);\r
+       }\r
+\r
+       // ログアウト\r
+       LogoutSec(sec);\r
+\r
+       // セッションを閉じる\r
+       CloseSecSession(sec);\r
+\r
+       // デバイスを閉じる\r
+       CloseSec(sec);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// セキュアデバイス内の証明書と鍵を列挙する\r
+UINT SecureEnum(UINT device_id, char *pin, TOKEN_LIST **cert_list, TOKEN_LIST **key_list)\r
+{\r
+       SECURE *sec;\r
+       LIST *o;\r
+       LIST *cert_name_list, *key_name_list;\r
+       // 引数チェック\r
+       if (pin == NULL || device_id == 0 || cert_list == NULL || key_list == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       // デバイスを開く\r
+       sec = OpenSec(device_id);\r
+       if (sec == NULL)\r
+       {\r
+               return ERR_SECURE_DEVICE_OPEN_FAILED;\r
+       }\r
+\r
+       // セッションを開く\r
+       if (OpenSecSession(sec, 0) == false)\r
+       {\r
+               CloseSec(sec);\r
+               return ERR_SECURE_DEVICE_OPEN_FAILED;\r
+       }\r
+\r
+       // ログイン\r
+       if (LoginSec(sec, pin) == false)\r
+       {\r
+               CloseSecSession(sec);\r
+               CloseSec(sec);\r
+               return ERR_SECURE_PIN_LOGIN_FAILED;\r
+       }\r
+\r
+       // オブジェクトの列挙\r
+       if ((o = EnumSecObject(sec)) != NULL)\r
+       {\r
+               UINT i;\r
+\r
+               cert_name_list = NewList(CompareStr);\r
+               key_name_list = NewList(CompareStr);\r
+\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       SEC_OBJ *obj = LIST_DATA(o, i);\r
+\r
+                       if (obj->Type == SEC_X)\r
+                       {\r
+                               Add(cert_name_list, CopyStr(obj->Name));\r
+                       }\r
+                       else if (obj->Type == SEC_K)\r
+                       {\r
+                               Add(key_name_list, CopyStr(obj->Name));\r
+                       }\r
+               }\r
+\r
+               Sort(cert_name_list);\r
+               Sort(key_name_list);\r
+\r
+               *cert_list = ListToTokenList(cert_name_list);\r
+               *key_list = ListToTokenList(key_name_list);\r
+\r
+               // メモリ解放\r
+               FreeStrList(cert_name_list);\r
+               FreeStrList(key_name_list);\r
+               FreeEnumSecObject(o);\r
+       }\r
+       else\r
+       {\r
+               *cert_list = NullToken();\r
+               *key_list = NullToken();\r
+       }\r
+\r
+       // ログアウト\r
+       LogoutSec(sec);\r
+\r
+       // セッションを閉じる\r
+       CloseSecSession(sec);\r
+\r
+       // デバイスを閉じる\r
+       CloseSec(sec);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// セキュアデバイスに証明書と鍵を記録する\r
+UINT SecureWrite(UINT device_id, char *cert_name, X *x, char *key_name, K *k, char *pin)\r
+{\r
+       SECURE *sec;\r
+       bool failed;\r
+       // 引数チェック\r
+       if (pin == NULL || device_id == 0 || cert_name == NULL || x == NULL || key_name == NULL || k == NULL)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       // デバイスを開く\r
+       sec = OpenSec(device_id);\r
+       if (sec == NULL)\r
+       {\r
+               return ERR_SECURE_DEVICE_OPEN_FAILED;\r
+       }\r
+\r
+       // セッションを開く\r
+       if (OpenSecSession(sec, 0) == false)\r
+       {\r
+               CloseSec(sec);\r
+               return ERR_SECURE_DEVICE_OPEN_FAILED;\r
+       }\r
+\r
+       // ログイン\r
+       if (LoginSec(sec, pin) == false)\r
+       {\r
+               CloseSecSession(sec);\r
+               CloseSec(sec);\r
+               return ERR_SECURE_PIN_LOGIN_FAILED;\r
+       }\r
+\r
+       // 登録\r
+       failed = false;\r
+\r
+       // 証明書の登録\r
+       if (WriteSecCert(sec, true, cert_name, x) == false)\r
+       {\r
+               failed = true;\r
+       }\r
+\r
+       // 秘密鍵の登録\r
+       if (WriteSecKey(sec, true, key_name, k) == false)\r
+       {\r
+               failed = true;\r
+       }\r
+\r
+       // ログアウト\r
+       LogoutSec(sec);\r
+\r
+       // セッションを閉じる\r
+       CloseSecSession(sec);\r
+\r
+       // デバイスを閉じる\r
+       CloseSec(sec);\r
+\r
+       if (failed == false)\r
+       {\r
+               // 成功\r
+               return ERR_NO_ERROR;\r
+       }\r
+       else\r
+       {\r
+               // 失敗\r
+               return ERR_SECURE_CANT_WRITE;\r
+       }\r
+}\r
+\r
+// セキュアデバイスによる署名を試行する\r
+UINT SecureSign(SECURE_SIGN *sign, UINT device_id, char *pin)\r
+{\r
+       SECURE *sec;\r
+       X *x;\r
+       // 引数チェック\r
+       if (sign == false || pin == NULL || device_id == 0)\r
+       {\r
+               return ERR_INTERNAL_ERROR;\r
+       }\r
+\r
+       // デバイスを開く\r
+       sec = OpenSec(device_id);\r
+       if (sec == NULL)\r
+       {\r
+               return ERR_SECURE_DEVICE_OPEN_FAILED;\r
+       }\r
+\r
+       // セッションを開く\r
+       if (OpenSecSession(sec, 0) == false)\r
+       {\r
+               CloseSec(sec);\r
+               return ERR_SECURE_DEVICE_OPEN_FAILED;\r
+       }\r
+\r
+       // ログイン\r
+       if (LoginSec(sec, pin) == false)\r
+       {\r
+               CloseSecSession(sec);\r
+               CloseSec(sec);\r
+               return ERR_SECURE_PIN_LOGIN_FAILED;\r
+       }\r
+\r
+       // 証明書の読み込み\r
+       x = ReadSecCert(sec, sign->SecurePublicCertName);\r
+       if (x == NULL)\r
+       {\r
+               LogoutSec(sec);\r
+               CloseSecSession(sec);\r
+               CloseSec(sec);\r
+               return ERR_SECURE_NO_CERT;\r
+       }\r
+\r
+       // 秘密鍵による署名\r
+       if (SignSec(sec, sign->SecurePrivateKeyName, sign->Signature, sign->Random, SHA1_SIZE) == false)\r
+       {\r
+               // 署名失敗\r
+               FreeX(x);\r
+               LogoutSec(sec);\r
+               CloseSecSession(sec);\r
+               CloseSec(sec);\r
+               return ERR_SECURE_NO_PRIVATE_KEY;\r
+       }\r
+\r
+       // 証明書をバッファに変換\r
+       sign->ClientCert = x;\r
+\r
+       // ログアウト\r
+       LogoutSec(sec);\r
+\r
+       // セッションを閉じる\r
+       CloseSecSession(sec);\r
+\r
+       // デバイスを閉じる\r
+       CloseSec(sec);\r
+\r
+       // 成功\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// クライアントがサーバーに追加接続する\r
+bool ClientAdditionalConnect(CONNECTION *c, THREAD *t)\r
+{\r
+       SOCK *s;\r
+       PACK *p;\r
+       TCPSOCK *ts;\r
+       UINT err;\r
+       UINT direction;\r
+       RC4_KEY_PAIR key_pair;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // サーバーにソケット接続\r
+       s = ClientAdditionalConnectToServer(c);\r
+       if (s == NULL)\r
+       {\r
+               // ソケット接続に失敗\r
+               return false;\r
+       }\r
+\r
+       if (c->Halt)\r
+       {\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // シグネチャを送信\r
+       Debug("Uploading Signature...\n");\r
+       if (ClientUploadSignature(s) == false)\r
+       {\r
+               goto CLEANUP;\r
+       }\r
+\r
+       if (c->Halt)\r
+       {\r
+               // 停止\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // Hello パケットを受信\r
+       Debug("Downloading Hello...\n");\r
+       if (ClientDownloadHello(c, s) == false)\r
+       {\r
+               goto CLEANUP;\r
+       }\r
+\r
+       if (c->Halt)\r
+       {\r
+               // 停止\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // 追加接続用の認証データを送信\r
+       if (ClientUploadAuth2(c, s) == false)\r
+       {\r
+               // 切断された\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // 応答を受信\r
+       p = HttpClientRecv(s);\r
+       if (p == NULL)\r
+       {\r
+               // 切断された\r
+               goto CLEANUP;\r
+       }\r
+\r
+       err = GetErrorFromPack(p);\r
+       direction = PackGetInt(p, "direction");\r
+\r
+       if (c->Session->UseFastRC4)\r
+       {\r
+               // RC4 鍵情報の取得\r
+               if (PackGetDataSize(p, "rc4_key_client_to_server") == 16)\r
+               {\r
+                       PackGetData(p, "rc4_key_client_to_server", key_pair.ClientToServerKey);\r
+               }\r
+               if (PackGetDataSize(p, "rc4_key_server_to_client") == 16)\r
+               {\r
+                       PackGetData(p, "rc4_key_server_to_client", key_pair.ServerToClientKey);\r
+               }\r
+               {\r
+                       char key1[64], key2[64];\r
+                       BinToStr(key1, sizeof(key1), key_pair.ClientToServerKey, 16);\r
+                       BinToStr(key2, sizeof(key2), key_pair.ServerToClientKey, 16);\r
+                       Debug(\r
+                               "Client to Server Key: %s\n"\r
+                               "Server to Client Key: %s\n",\r
+                               key1, key2);\r
+               }\r
+       }\r
+\r
+       FreePack(p);\r
+       p = NULL;\r
+\r
+       if (err != 0)\r
+       {\r
+               // エラーが発生した\r
+               Debug("Additional Connect Error: %u\n", err);\r
+               if (err == ERR_SESSION_TIMEOUT || err == ERR_INVALID_PROTOCOL)\r
+               {\r
+                       // 致命的なエラーなので再接続しなおすことにする\r
+                       c->Session->SessionTimeOuted = true;\r
+               }\r
+               goto CLEANUP;\r
+       }\r
+\r
+       Debug("Additional Connect Succeed!\n");\r
+\r
+       // 追加接続成功\r
+       // コネクションの TcpSockList に追加する\r
+       ts = NewTcpSock(s);\r
+\r
+       if (c->ServerMode == false)\r
+       {\r
+               if (c->Session->ClientOption->ConnectionDisconnectSpan != 0)\r
+               {\r
+                       ts->DisconnectTick = Tick64() + c->Session->ClientOption->ConnectionDisconnectSpan * (UINT64)1000;\r
+               }\r
+       }\r
+\r
+       LockList(c->Tcp->TcpSockList);\r
+       {\r
+               ts->Direction = direction;\r
+               Add(c->Tcp->TcpSockList, ts);\r
+       }\r
+       UnlockList(c->Tcp->TcpSockList);\r
+       Debug("TCP Connection Incremented: %u\n", Count(c->CurrentNumConnection));\r
+\r
+       if (c->Session->HalfConnection)\r
+       {\r
+               Debug("New Half Connection: %s\n",\r
+                       direction == TCP_SERVER_TO_CLIENT ? "TCP_SERVER_TO_CLIENT" : "TCP_CLIENT_TO_SERVER"\r
+                       );\r
+       }\r
+\r
+       if (c->Session->UseFastRC4)\r
+       {\r
+               // RC4 暗号化鍵のセット\r
+               Copy(&ts->Rc4KeyPair, &key_pair, sizeof(RC4_KEY_PAIR));\r
+\r
+               InitTcpSockRc4Key(ts, false);\r
+       }\r
+\r
+       // セッションに Cancel を発行する\r
+       Cancel(c->Session->Cancel1);\r
+\r
+       // 接続中のソケット一覧からこのソケットを削除\r
+       LockList(c->ConnectingSocks);\r
+       {\r
+               if (Delete(c->ConnectingSocks, s))\r
+               {\r
+                       ReleaseSock(s);\r
+               }\r
+       }\r
+       UnlockList(c->ConnectingSocks);\r
+       ReleaseSock(s);\r
+       return true;\r
+\r
+CLEANUP:\r
+       // 切断処理\r
+       Disconnect(s);\r
+       LockList(c->ConnectingSocks);\r
+       {\r
+               if (Delete(c->ConnectingSocks, s))\r
+               {\r
+                       ReleaseSock(s);\r
+\r
+               }\r
+       }\r
+       UnlockList(c->ConnectingSocks);\r
+       ReleaseSock(s);\r
+       return false;\r
+}\r
+\r
+// セキュアデバイス署名スレッド\r
+void ClientSecureSignThread(THREAD *thread, void *param)\r
+{\r
+       SECURE_SIGN_THREAD_PROC *p = (SECURE_SIGN_THREAD_PROC *)param;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       NoticeThreadInit(thread);\r
+\r
+       p->Ok = p->SecureSignProc(p->Connection->Session, p->Connection, p->SecureSign);\r
+       p->UserFinished = true;\r
+}\r
+\r
+// セキュアデバイスを使用した署名\r
+bool ClientSecureSign(CONNECTION *c, UCHAR *sign, UCHAR *random, X **x)\r
+{\r
+       SECURE_SIGN_THREAD_PROC *p;\r
+       SECURE_SIGN *ss;\r
+       SESSION *s;\r
+       CLIENT_OPTION *o;\r
+       CLIENT_AUTH *a;\r
+       THREAD *thread;\r
+       UINT64 start;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (c == NULL || sign == NULL || random == NULL || x == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s = c->Session;\r
+       o = s->ClientOption;\r
+       a = s->ClientAuth;\r
+\r
+       p = ZeroMalloc(sizeof(SECURE_SIGN_THREAD_PROC));\r
+       p->Connection = c;\r
+       ss = p->SecureSign = ZeroMallocEx(sizeof(SECURE_SIGN), true);\r
+       StrCpy(ss->SecurePrivateKeyName, sizeof(ss->SecurePrivateKeyName),\r
+               a->SecurePrivateKeyName);\r
+       StrCpy(ss->SecurePublicCertName, sizeof(ss->SecurePublicCertName),\r
+               a->SecurePublicCertName);\r
+       ss->UseSecureDeviceId = c->Cedar->Client->UseSecureDeviceId;\r
+       Copy(ss->Random, random, SHA1_SIZE);\r
+\r
+#ifdef OS_WIN32\r
+       ss->BitmapId = CmGetSecureBitmapId(c->ServerName);\r
+#endif // OS_WIN32\r
+\r
+       p->SecureSignProc = a->SecureSignProc;\r
+\r
+       // スレッド作成\r
+       thread = NewThread(ClientSecureSignThread, p);\r
+       WaitThreadInit(thread);\r
+\r
+       // 署名が完了するかキャンセルするまで 0.5 秒ごとにポーリングする\r
+       start = Tick64();\r
+       while (true)\r
+       {\r
+               if ((Tick64() - start) > CONNECTING_POOLING_SPAN)\r
+               {\r
+                       // 切断防止のため一定期間ごとに NOOP を送信する\r
+                       start = Tick64();\r
+                       ClientUploadNoop(c);\r
+               }\r
+               if (p->UserFinished)\r
+               {\r
+                       // ユーザーが選択した\r
+                       break;\r
+               }\r
+               WaitThread(thread, 500);\r
+       }\r
+       ReleaseThread(thread);\r
+\r
+       ret = p->Ok;\r
+\r
+       if (ret)\r
+       {\r
+               Copy(sign, ss->Signature, 128);\r
+               *x = ss->ClientCert;\r
+       }\r
+\r
+       Free(p->SecureSign);\r
+       Free(p);\r
+\r
+       return ret;\r
+}\r
+\r
+// サーバー証明書確認用スレッド\r
+void ClientCheckServerCertThread(THREAD *thread, void *param)\r
+{\r
+       CHECK_CERT_THREAD_PROC *p = (CHECK_CERT_THREAD_PROC *)param;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 初期化完了を通知する\r
+       NoticeThreadInit(thread);\r
+\r
+       // ユーザーに選択を問い合わせる\r
+       p->Ok = p->CheckCertProc(p->Connection->Session, p->Connection, p->ServerX, &p->Exipred);\r
+       p->UserSelected = true;\r
+}\r
+\r
+// クライアントがサーバーの証明書を確認する\r
+bool ClientCheckServerCert(CONNECTION *c, bool *expired)\r
+{\r
+       CLIENT_AUTH *auth;\r
+       X *x;\r
+       CHECK_CERT_THREAD_PROC *p;\r
+       THREAD *thread;\r
+       CEDAR *cedar;\r
+       bool ret;\r
+       UINT64 start;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (expired != NULL)\r
+       {\r
+               *expired = false;\r
+       }\r
+\r
+       auth = c->Session->ClientAuth;\r
+       cedar = c->Cedar;\r
+\r
+       if (auth->CheckCertProc == NULL && c->Session->LinkModeClient == false)\r
+       {\r
+               // チェック関数無し\r
+               return true;\r
+       }\r
+\r
+       if (c->Session->LinkModeClient && c->Session->Link->CheckServerCert == false)\r
+       {\r
+               // カスケード接続モードだがサーバー証明書はチェックしない\r
+               return true;\r
+       }\r
+\r
+       if (c->UseTicket)\r
+       {\r
+               // リダイレクト先 VPN サーバーの証明書を確認する\r
+               if (CompareX(c->FirstSock->RemoteX, c->ServerX) == false)\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       x = CloneX(c->FirstSock->RemoteX);\r
+       if (x == NULL)\r
+       {\r
+               // 変なエラーが発生した\r
+               return false;\r
+       }\r
+\r
+       if (CheckXDateNow(x))\r
+       {\r
+               // 信頼するルート証明書によって署名されているかどうか確認する\r
+               if (c->Session->LinkModeClient == false)\r
+               {\r
+                       // 通常の VPN Client モード\r
+                       if (CheckSignatureByCa(cedar, x))\r
+                       {\r
+                               // 署名されているのでこの証明書は信頼できる\r
+                               FreeX(x);\r
+                               return true;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // カスケード接続モード\r
+                       if (CheckSignatureByCaLinkMode(c->Session, x))\r
+                       {\r
+                               // 署名されているのでこの証明書は信頼できる\r
+                               FreeX(x);\r
+                               return true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (c->Session->LinkModeClient)\r
+       {\r
+               if (CheckXDateNow(x))\r
+               {\r
+                       Lock(c->Session->Link->lock);\r
+                       {\r
+                               if (c->Session->Link->ServerCert != NULL)\r
+                               {\r
+                                       if (CompareX(c->Session->Link->ServerCert, x))\r
+                                       {\r
+                                               Unlock(c->Session->Link->lock);\r
+                                               // カスケード接続設定に登録されている証明書と完全一致\r
+                                               FreeX(x);\r
+                                               return true;\r
+                                       }\r
+                               }\r
+                       }\r
+                       Unlock(c->Session->Link->lock);\r
+               }\r
+               else\r
+               {\r
+                       if (expired != NULL)\r
+                       {\r
+                               *expired = true;\r
+                       }\r
+               }\r
+\r
+               // カスケード接続モードの場合はこの時点で検証失敗\r
+               FreeX(x);\r
+               return false;\r
+       }\r
+\r
+       p = ZeroMalloc(sizeof(CHECK_CERT_THREAD_PROC));\r
+       p->ServerX = x;\r
+       p->CheckCertProc = auth->CheckCertProc;\r
+       p->Connection = c;\r
+\r
+       // スレッドを作成する\r
+       thread = NewThread(ClientCheckServerCertThread, p);\r
+       WaitThreadInit(thread);\r
+\r
+       // ユーザーが接続の可否を選択するまで 0.5 秒間隔でポーリングする\r
+       start = Tick64();\r
+       while (true)\r
+       {\r
+               if ((Tick64() - start) > CONNECTING_POOLING_SPAN)\r
+               {\r
+                       // 切断防止のため一定期間ごとに NOOP を送信する\r
+                       start = Tick64();\r
+                       ClientUploadNoop(c);\r
+               }\r
+               if (p->UserSelected)\r
+               {\r
+                       // ユーザーが選択した\r
+                       break;\r
+               }\r
+               WaitThread(thread, 500);\r
+       }\r
+\r
+       if (expired != NULL)\r
+       {\r
+               *expired = p->Exipred;\r
+       }\r
+\r
+       ret = p->Ok;\r
+       FreeX(p->ServerX);\r
+       Free(p);\r
+       ReleaseThread(thread);\r
+\r
+       return ret;\r
+}\r
+\r
+// クライアントがサーバーに接続する\r
+bool ClientConnect(CONNECTION *c)\r
+{\r
+       bool ret = false;\r
+       bool ok = false;\r
+       UINT err;\r
+       SOCK *s;\r
+       PACK *p = NULL;\r
+       UINT session_key_32;\r
+       SESSION *sess;\r
+       char session_name[MAX_SESSION_NAME_LEN + 1];\r
+       char connection_name[MAX_CONNECTION_NAME_LEN + 1];\r
+       UCHAR session_key[SHA1_SIZE];\r
+       RC4_KEY_PAIR key_pair;\r
+       POLICY *policy;\r
+       bool expired = false;\r
+       IP server_ip;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       sess = c->Session;\r
+\r
+       PrintStatus(sess, L"init");\r
+       PrintStatus(sess, _UU("STATUS_1"));\r
+\r
+REDIRECTED:\r
+\r
+       // [接続中]\r
+       c->Status = CONNECTION_STATUS_CONNECTING;\r
+       c->Session->ClientStatus = CLIENT_STATUS_CONNECTING;\r
+\r
+       s = ClientConnectToServer(c);\r
+       if (s == NULL)\r
+       {\r
+               PrintStatus(sess, L"free");\r
+               return false;\r
+       }\r
+\r
+       Copy(&server_ip, &s->RemoteIP, sizeof(IP));\r
+\r
+       if (c->Halt)\r
+       {\r
+               // 停止\r
+               c->Err = ERR_USER_CANCEL;\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // [ネゴシエーション中]\r
+       c->Session->ClientStatus = CLIENT_STATUS_NEGOTIATION;\r
+\r
+       // シグネチャを送信\r
+       Debug("Uploading Signature...\n");\r
+       if (ClientUploadSignature(s) == false)\r
+       {\r
+               c->Err = ERR_DISCONNECTED;\r
+               goto CLEANUP;\r
+       }\r
+\r
+       if (c->Halt)\r
+       {\r
+               // 停止\r
+               c->Err = ERR_USER_CANCEL;\r
+               goto CLEANUP;\r
+       }\r
+\r
+       PrintStatus(sess, _UU("STATUS_5"));\r
+\r
+       // Hello パケットを受信\r
+       Debug("Downloading Hello...\n");\r
+       if (ClientDownloadHello(c, s) == false)\r
+       {\r
+               goto CLEANUP;\r
+       }\r
+\r
+       if (c->Session->ClientOption != NULL && c->Session->ClientOption->FromAdminPack)\r
+       {\r
+               if (IsAdminPackSupportedServerProduct(c->ServerStr) == false)\r
+               {\r
+                       c->Err = ERR_NOT_ADMINPACK_SERVER;\r
+                       goto CLEANUP;\r
+               }\r
+       }\r
+\r
+       if (c->Halt)\r
+       {\r
+               // 停止\r
+               c->Err = ERR_USER_CANCEL;\r
+               goto CLEANUP;\r
+       }\r
+\r
+       Debug("Server Version : %u\n"\r
+               "Server String  : %s\n"\r
+               "Server Build   : %u\n"\r
+               "Client Version : %u\n"\r
+               "Client String  : %s\n"\r
+               "Client Build   : %u\n",\r
+               c->ServerVer, c->ServerStr, c->ServerBuild,\r
+               c->ClientVer, c->ClientStr, c->ClientBuild);\r
+\r
+       // ユーザー認証中\r
+       c->Session->ClientStatus = CLIENT_STATUS_AUTH;\r
+\r
+       // クライアントによるサーバー証明書の確認\r
+       if (ClientCheckServerCert(c, &expired) == false)\r
+       {\r
+               if (expired == false)\r
+               {\r
+                       c->Err = ERR_CERT_NOT_TRUSTED;\r
+               }\r
+               else\r
+               {\r
+                       c->Err = ERR_SERVER_CERT_EXPIRES;\r
+               }\r
+\r
+               if (c->Session->LinkModeClient == false && c->Err == ERR_CERT_NOT_TRUSTED)\r
+               {\r
+                       c->Session->ForceStopFlag = true;\r
+               }\r
+\r
+               goto CLEANUP;\r
+       }\r
+\r
+       PrintStatus(sess, _UU("STATUS_6"));\r
+\r
+       // 認証データを送信\r
+       if (ClientUploadAuth(c) == false)\r
+       {\r
+               goto CLEANUP;\r
+       }\r
+\r
+       if (c->Halt)\r
+       {\r
+               // 停止\r
+               c->Err = ERR_USER_CANCEL;\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // Welcome パケットを受信\r
+       p = HttpClientRecv(s);\r
+       if (p == NULL)\r
+       {\r
+               c->Err = ERR_DISCONNECTED;\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // エラーチェック\r
+       err = GetErrorFromPack(p);\r
+       if (err != 0)\r
+       {\r
+               // エラー発生\r
+               c->Err = err;\r
+               c->ClientConnectError_NoSavePassword = PackGetBool(p, "no_save_password");\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // 接続制限のためのブランド化文字列チェック\r
+       {\r
+               char tmp[20];\r
+               char *branded_cfroms = _SS("BRANDED_C_FROM_S");\r
+               PackGetStr(p, "branded_cfroms", tmp, sizeof(tmp));\r
+\r
+               if(StrLen(branded_cfroms) > 0 && StrCmpi(branded_cfroms, tmp) != 0)\r
+               {\r
+                       c->Err = ERR_BRANDED_C_FROM_S;\r
+                       goto CLEANUP;\r
+               }\r
+       }\r
+\r
+       if (true)\r
+       {\r
+               // メッセージ取得\r
+               UINT utf_size;\r
+               char *utf;\r
+               wchar_t *msg;\r
+\r
+               utf_size = PackGetDataSize(p, "Msg");\r
+               utf = ZeroMalloc(utf_size + 8);\r
+               PackGetData(p, "Msg", utf);\r
+\r
+               msg = CopyUtfToUni(utf);\r
+\r
+               if (IsEmptyUniStr(msg) == false)\r
+               {\r
+                       if (c->Session->Client_Message != NULL)\r
+                       {\r
+                               Free(c->Session->Client_Message);\r
+                       }\r
+\r
+                       c->Session->Client_Message = msg;\r
+               }\r
+               else\r
+               {\r
+                       Free(msg);\r
+               }\r
+\r
+               Free(utf);\r
+       }\r
+\r
+       if (PackGetInt(p, "Redirect") != 0)\r
+       {\r
+               UINT i;\r
+               UINT ip;\r
+               UINT num_port;\r
+               UINT *ports;\r
+               UINT use_port = 0;\r
+               UINT current_port = c->ServerPort;\r
+               UCHAR ticket[SHA1_SIZE];\r
+               X *server_cert;\r
+               BUF *b;\r
+\r
+               // リダイレクトモード\r
+               PrintStatus(sess, _UU("STATUS_8"));\r
+\r
+               ip = PackGetIp32(p, "Ip");\r
+               num_port = MAX(MIN(PackGetIndexCount(p, "Port"), MAX_PUBLIC_PORT_NUM), 1);\r
+               ports = ZeroMalloc(sizeof(UINT) * num_port);\r
+               for (i = 0;i < num_port;i++)\r
+               {\r
+                       ports[i] = PackGetIntEx(p, "Port", i);\r
+               }\r
+\r
+               // ポート番号を選定する\r
+               for (i = 0;i < num_port;i++)\r
+               {\r
+                       if (ports[i] == current_port)\r
+                       {\r
+                               use_port = current_port;\r
+                       }\r
+               }\r
+               if (use_port == 0)\r
+               {\r
+                       use_port = ports[0];\r
+               }\r
+\r
+               Free(ports);\r
+\r
+               if (PackGetDataSize(p, "Ticket") == SHA1_SIZE)\r
+               {\r
+                       PackGetData(p, "Ticket", ticket);\r
+               }\r
+\r
+               b = PackGetBuf(p, "Cert");\r
+               if (b != NULL)\r
+               {\r
+                       server_cert = BufToX(b, false);\r
+                       FreeBuf(b);\r
+               }\r
+\r
+               if (c->ServerX != NULL)\r
+               {\r
+                       FreeX(c->ServerX);\r
+               }\r
+               c->ServerX = server_cert;\r
+\r
+               IPToStr32(c->ServerName, sizeof(c->ServerName), ip);\r
+               c->ServerPort = use_port;\r
+\r
+               c->UseTicket = true;\r
+               Copy(c->Ticket, ticket, SHA1_SIZE);\r
+\r
+               FreePack(p);\r
+\r
+               p = NewPack();\r
+               HttpClientSend(s, p);\r
+               FreePack(p);\r
+\r
+               p = NULL;\r
+\r
+               c->FirstSock = NULL;\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+               s = NULL;\r
+\r
+               goto REDIRECTED;\r
+       }\r
+\r
+       PrintStatus(sess, _UU("STATUS_7"));\r
+\r
+       // Welcome パケットをパース\r
+       if (ParseWelcomeFromPack(p, session_name, sizeof(session_name),\r
+               connection_name, sizeof(connection_name), &policy) == false)\r
+       {\r
+               // パース失敗\r
+               c->Err = ERR_PROTOCOL_ERROR;\r
+               goto CLEANUP;\r
+       }\r
+\r
+       // セッションキーを取得\r
+       if (GetSessionKeyFromPack(p, session_key, &session_key_32) == false)\r
+       {\r
+               // 取得失敗\r
+               Free(policy);\r
+               policy = NULL;\r
+               c->Err = ERR_PROTOCOL_ERROR;\r
+               goto CLEANUP;\r
+       }\r
+\r
+       Copy(c->Session->SessionKey, session_key, SHA1_SIZE);\r
+       c->Session->SessionKey32 = session_key_32;\r
+\r
+       // Welcome パケットの内容を保存\r
+       Debug("session_name: %s, connection_name: %s\n",\r
+               session_name, connection_name);\r
+\r
+       Lock(c->Session->lock);\r
+       {\r
+               // 接続パラメータの展開と更新\r
+               c->Session->MaxConnection = PackGetInt(p, "max_connection");\r
+               c->Session->MaxConnection = MIN(c->Session->MaxConnection, c->Session->ClientOption->MaxConnection);\r
+               c->Session->MaxConnection = MIN(c->Session->MaxConnection, MAX_TCP_CONNECTION);\r
+               c->Session->MaxConnection = MAX(c->Session->MaxConnection, 1);\r
+               c->Session->UseCompress = PackGetInt(p, "use_compress") == 0 ? false : true;\r
+               c->Session->UseEncrypt = PackGetInt(p, "use_encrypt") == 0 ? false : true;\r
+               c->Session->NoSendSignature = PackGetBool(p, "no_send_signature");\r
+               if (c->Session->UseEncrypt)\r
+               {\r
+                       c->Session->UseFastRC4 = PackGetInt(p, "use_fast_rc4") == 0 ? false : true;\r
+               }\r
+               c->Session->HalfConnection = PackGetInt(p, "half_connection") == 0 ? false : true;\r
+               c->Session->Timeout = PackGetInt(p, "timeout");\r
+               c->Session->QoS = PackGetInt(p, "qos") == 0 ? false : true;\r
+               if (c->Session->QoS)\r
+               {\r
+                       c->Session->MaxConnection = MAX(c->Session->MaxConnection, (UINT)(c->Session->HalfConnection ? 4 : 2));\r
+               }\r
+               c->Session->VLanId = PackGetInt(p, "vlan_id");\r
+\r
+               if (c->Protocol == CONNECTION_UDP)\r
+               {\r
+                       // UDP プロトコルの場合、サーバーから鍵を受け取る\r
+                       if (PackGetDataSize(p, "udp_send_key") == sizeof(c->Session->UdpSendKey))\r
+                       {\r
+                               PackGetData(p, "udp_send_key", c->Session->UdpSendKey);\r
+                       }\r
+\r
+                       if (PackGetDataSize(p, "udp_recv_key") == sizeof(c->Session->UdpRecvKey))\r
+                       {\r
+                               PackGetData(p, "udp_recv_key", c->Session->UdpRecvKey);\r
+                       }\r
+               }\r
+\r
+               if (c->Session->UseFastRC4)\r
+               {\r
+                       // RC4 鍵情報の取得\r
+                       if (PackGetDataSize(p, "rc4_key_client_to_server") == 16)\r
+                       {\r
+                               PackGetData(p, "rc4_key_client_to_server", key_pair.ClientToServerKey);\r
+                       }\r
+                       if (PackGetDataSize(p, "rc4_key_server_to_client") == 16)\r
+                       {\r
+                               PackGetData(p, "rc4_key_server_to_client", key_pair.ServerToClientKey);\r
+                       }\r
+                       {\r
+                               char key1[64], key2[64];\r
+                               BinToStr(key1, sizeof(key1), key_pair.ClientToServerKey, 16);\r
+                               BinToStr(key2, sizeof(key2), key_pair.ServerToClientKey, 16);\r
+                               Debug(\r
+                                       "Client to Server Key: %s\n"\r
+                                       "Server to Client Key: %s\n",\r
+                                       key1, key2);\r
+                       }\r
+               }\r
+       }\r
+       Unlock(c->Session->lock);\r
+\r
+       Lock(c->lock);\r
+       {\r
+               if (c->Name != NULL)\r
+               {\r
+                       Free(c->Name);\r
+               }\r
+               c->Name = CopyStr(connection_name);\r
+\r
+               // 暗号化アルゴリズム名の保存\r
+               if (c->CipherName != NULL)\r
+               {\r
+                       Free(c->CipherName);\r
+               }\r
+\r
+               c->CipherName = CopyStr(c->FirstSock->CipherName);\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       Lock(c->Session->lock);\r
+       {\r
+               if (c->Session->Name != NULL)\r
+               {\r
+                       Free(c->Session->Name);\r
+               }\r
+               c->Session->Name = CopyStr(session_name);\r
+\r
+               c->Session->Policy = policy;\r
+       }\r
+       Unlock(c->Session->lock);\r
+\r
+       // Welcome パケットを破棄\r
+       FreePack(p);\r
+       p = NULL;\r
+\r
+       // server_ip に対して TCP でシグネチャを送信\r
+       if (c->Session->NoSendSignature == false)\r
+       {\r
+               SendSignatureByTcp(c, &server_ip);\r
+       }\r
+\r
+       // コネクション確立\r
+       c->Session->ClientStatus = CLIENT_STATUS_ESTABLISHED;\r
+\r
+       // サーバー証明書の保存\r
+       if (c->ServerX == NULL)\r
+       {\r
+               c->ServerX = CloneX(c->FirstSock->RemoteX);\r
+       }\r
+\r
+       PrintStatus(sess, _UU("STATUS_9"));\r
+\r
+       // コネクションをトンネリングモードに移行\r
+       StartTunnelingMode(c);\r
+       s = NULL;\r
+\r
+       if (c->Session->HalfConnection)\r
+       {\r
+               // ハーフコネクション時の処理\r
+               TCPSOCK *ts = (TCPSOCK *)LIST_DATA(c->Tcp->TcpSockList, 0);\r
+               ts->Direction = TCP_CLIENT_TO_SERVER;\r
+       }\r
+\r
+       if (c->Session->UseFastRC4)\r
+       {\r
+               // RC4 高速暗号化鍵のセット\r
+               TCPSOCK *ts = (TCPSOCK *)LIST_DATA(c->Tcp->TcpSockList, 0);\r
+               Copy(&ts->Rc4KeyPair, &key_pair, sizeof(key_pair));\r
+\r
+               InitTcpSockRc4Key(ts, false);\r
+       }\r
+\r
+       // SSL 暗号化フラグ\r
+       if (c->Session->UseEncrypt && c->Session->UseFastRC4 == false)\r
+       {\r
+               c->Session->UseSSLDataEncryption = true;\r
+       }\r
+       else\r
+       {\r
+               c->Session->UseSSLDataEncryption = false;\r
+       }\r
+\r
+       PrintStatus(sess, L"free");\r
+\r
+       CLog(c->Cedar->Client, "LC_CONNECT_2", c->Session->ClientOption->AccountName,\r
+               session_name);\r
+\r
+       if (c->Session->LinkModeClient && c->Session->Link != NULL)\r
+       {\r
+               HLog(c->Session->Link->Hub, "LH_CONNECT_2", c->Session->ClientOption->AccountName, session_name);\r
+       }\r
+\r
+       // セッションのメインルーチン\r
+       SessionMain(c->Session);\r
+\r
+       ok = true;\r
+\r
+       if (c->Err == ERR_USER_CANCEL)\r
+       {\r
+               ret = true;\r
+       }\r
+\r
+CLEANUP:\r
+       c->FirstSock = NULL;\r
+\r
+       if (p != NULL)\r
+       {\r
+               FreePack(p);\r
+       }\r
+\r
+       Disconnect(s);\r
+       ReleaseSock(s);\r
+\r
+       Debug("Error: %u\n", c->Err);\r
+\r
+       if (ok == false)\r
+       {\r
+               PrintStatus(sess, L"free");\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// Welcome パケットのパース\r
+bool ParseWelcomeFromPack(PACK *p, char *session_name, UINT session_name_size,\r
+                                                 char *connection_name, UINT connection_name_size,\r
+                                                 POLICY **policy)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || session_name == NULL || connection_name == NULL || policy == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // セッション名\r
+       if (PackGetStr(p, "session_name", session_name, session_name_size) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // コネクション名\r
+       if (PackGetStr(p, "connection_name", connection_name, connection_name_size) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ポリシー\r
+       *policy = PackGetPolicy(p);\r
+       if (*policy == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// Welcome パケットの生成\r
+PACK *PackWelcome(SESSION *s)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = NewPack();\r
+\r
+       // セッション名\r
+       PackAddStr(p, "session_name", s->Name);\r
+\r
+       // コネクション名\r
+       PackAddStr(p, "connection_name", s->Connection->Name);\r
+\r
+       // パラメータ\r
+       PackAddInt(p, "max_connection", s->MaxConnection);\r
+       PackAddInt(p, "use_encrypt", s->UseEncrypt == false ? 0 : 1);\r
+       PackAddInt(p, "use_fast_rc4", s->UseFastRC4 == false ? 0 : 1);\r
+       PackAddInt(p, "use_compress", s->UseCompress == false ? 0 : 1);\r
+       PackAddInt(p, "half_connection", s->HalfConnection == false ? 0 : 1);\r
+       PackAddInt(p, "timeout", s->Timeout);\r
+       PackAddInt(p, "qos", s->QoS ? 1 : 0);\r
+\r
+       // セッションキー\r
+       PackAddData(p, "session_key", s->SessionKey, SHA1_SIZE);\r
+       PackAddInt(p, "session_key_32", s->SessionKey32);\r
+\r
+       // ポリシー\r
+       PackAddPolicy(p, s->Policy);\r
+\r
+       // VLAN ID\r
+       PackAddInt(p, "vlan_id", s->VLanId);\r
+\r
+       if (s->Connection->Protocol == CONNECTION_UDP)\r
+       {\r
+               // UDP プロトコルの場合、2 組のキーを生成する\r
+               Rand(s->UdpSendKey, sizeof(s->UdpSendKey));\r
+               Rand(s->UdpRecvKey, sizeof(s->UdpRecvKey));\r
+\r
+               // クライアントには鍵を反転して送る\r
+               PackAddData(p, "udp_send_key", s->UdpRecvKey, sizeof(s->UdpRecvKey));\r
+               PackAddData(p, "udp_recv_key", s->UdpSendKey, sizeof(s->UdpSendKey));\r
+       }\r
+\r
+       // no_send_signature\r
+       if (s->NoSendSignature)\r
+       {\r
+               PackAddBool(p, "no_send_signature", true);\r
+       }\r
+\r
+       return p;\r
+}\r
+\r
+#define        PACK_ADD_POLICY_BOOL(name, value)       \\r
+       PackAddInt(p, "policy:" name, y->value == false ? 0 : 1)\r
+#define        PACK_ADD_POLICY_UINT(name, value)       \\r
+       PackAddInt(p, "policy:" name, y->value)\r
+#define        PACK_GET_POLICY_BOOL(name, value)       \\r
+       y->value = (PackGetInt(p, "policy:" name) == 0 ? false : true)\r
+#define        PACK_GET_POLICY_UINT(name, value)       \\r
+       y->value = PackGetInt(p, "policy:" name)\r
+\r
+// セッションキーを PACK から取得\r
+bool GetSessionKeyFromPack(PACK *p, UCHAR *session_key, UINT *session_key_32)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || session_key == NULL || session_key_32 == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (PackGetDataSize(p, "session_key") != SHA1_SIZE)\r
+       {\r
+               return false;\r
+       }\r
+       if (PackGetData(p, "session_key", session_key) == false)\r
+       {\r
+               return false;\r
+       }\r
+       *session_key_32 = PackGetInt(p, "session_key_32");\r
+\r
+       return true;\r
+}\r
+\r
+// ポリシーを PACK から取得\r
+POLICY *PackGetPolicy(PACK *p)\r
+{\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       POLICY *y;\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       y = ZeroMalloc(sizeof(POLICY));\r
+\r
+       // bool 値\r
+       // Ver 2\r
+       PACK_GET_POLICY_BOOL("Access", Access);\r
+       PACK_GET_POLICY_BOOL("DHCPFilter", DHCPFilter);\r
+       PACK_GET_POLICY_BOOL("DHCPNoServer", DHCPNoServer);\r
+       PACK_GET_POLICY_BOOL("DHCPForce", DHCPForce);\r
+       PACK_GET_POLICY_BOOL("NoBridge", NoBridge);\r
+       PACK_GET_POLICY_BOOL("NoRouting", NoRouting);\r
+       PACK_GET_POLICY_BOOL("PrivacyFilter", PrivacyFilter);\r
+       PACK_GET_POLICY_BOOL("NoServer", NoServer);\r
+       PACK_GET_POLICY_BOOL("CheckMac", CheckMac);\r
+       PACK_GET_POLICY_BOOL("CheckIP", CheckIP);\r
+       PACK_GET_POLICY_BOOL("ArpDhcpOnly", ArpDhcpOnly);\r
+       PACK_GET_POLICY_BOOL("MonitorPort", MonitorPort);\r
+       PACK_GET_POLICY_BOOL("NoBroadcastLimiter", NoBroadcastLimiter);\r
+       PACK_GET_POLICY_BOOL("FixPassword", FixPassword);\r
+       PACK_GET_POLICY_BOOL("NoQoS", NoQoS);\r
+       // Ver 3\r
+       PACK_GET_POLICY_BOOL("RSandRAFilter", RSandRAFilter);\r
+       PACK_GET_POLICY_BOOL("RAFilter", RAFilter);\r
+       PACK_GET_POLICY_BOOL("DHCPv6Filter", DHCPv6Filter);\r
+       PACK_GET_POLICY_BOOL("DHCPv6NoServer", DHCPv6NoServer);\r
+       PACK_GET_POLICY_BOOL("NoRoutingV6", NoRoutingV6);\r
+       PACK_GET_POLICY_BOOL("CheckIPv6", CheckIPv6);\r
+       PACK_GET_POLICY_BOOL("NoServerV6", NoServerV6);\r
+       PACK_GET_POLICY_BOOL("NoSavePassword", NoSavePassword);\r
+       PACK_GET_POLICY_BOOL("FilterIPv4", FilterIPv4);\r
+       PACK_GET_POLICY_BOOL("FilterIPv6", FilterIPv6);\r
+       PACK_GET_POLICY_BOOL("FilterNonIP", FilterNonIP);\r
+       PACK_GET_POLICY_BOOL("NoIPv6DefaultRouterInRA", NoIPv6DefaultRouterInRA);\r
+       PACK_GET_POLICY_BOOL("NoIPv6DefaultRouterInRAWhenIPv6", NoIPv6DefaultRouterInRAWhenIPv6);\r
+\r
+       // UINT 値\r
+       // Ver 2\r
+       PACK_GET_POLICY_UINT("MaxConnection", MaxConnection);\r
+       PACK_GET_POLICY_UINT("TimeOut", TimeOut);\r
+       PACK_GET_POLICY_UINT("MaxMac", MaxMac);\r
+       PACK_GET_POLICY_UINT("MaxIP", MaxIP);\r
+       PACK_GET_POLICY_UINT("MaxUpload", MaxUpload);\r
+       PACK_GET_POLICY_UINT("MaxDownload", MaxDownload);\r
+       PACK_GET_POLICY_UINT("MultiLogins", MultiLogins);\r
+       // Ver 3\r
+       PACK_GET_POLICY_UINT("MaxIPv6", MaxIPv6);\r
+       PACK_GET_POLICY_UINT("AutoDisconnect", AutoDisconnect);\r
+       PACK_GET_POLICY_UINT("VLanId", VLanId);\r
+\r
+       // Ver 3 フラグ\r
+       PACK_GET_POLICY_BOOL("Ver3", Ver3);\r
+\r
+       return y;\r
+}\r
+\r
+// ポリシーを PACK に挿入\r
+void PackAddPolicy(PACK *p, POLICY *y)\r
+{\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       // 引数チェック\r
+       if (p == NULL || y == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // bool 値\r
+       // Ver 2\r
+       PACK_ADD_POLICY_BOOL("Access", Access);\r
+       PACK_ADD_POLICY_BOOL("DHCPFilter", DHCPFilter);\r
+       PACK_ADD_POLICY_BOOL("DHCPNoServer", DHCPNoServer);\r
+       PACK_ADD_POLICY_BOOL("DHCPForce", DHCPForce);\r
+       PACK_ADD_POLICY_BOOL("NoBridge", NoBridge);\r
+       PACK_ADD_POLICY_BOOL("NoRouting", NoRouting);\r
+       PACK_ADD_POLICY_BOOL("PrivacyFilter", PrivacyFilter);\r
+       PACK_ADD_POLICY_BOOL("NoServer", NoServer);\r
+       PACK_ADD_POLICY_BOOL("CheckMac", CheckMac);\r
+       PACK_ADD_POLICY_BOOL("CheckIP", CheckIP);\r
+       PACK_ADD_POLICY_BOOL("ArpDhcpOnly", ArpDhcpOnly);\r
+       PACK_ADD_POLICY_BOOL("MonitorPort", MonitorPort);\r
+       PACK_ADD_POLICY_BOOL("NoBroadcastLimiter", NoBroadcastLimiter);\r
+       PACK_ADD_POLICY_BOOL("FixPassword", FixPassword);\r
+       PACK_ADD_POLICY_BOOL("NoQoS", NoQoS);\r
+       // Ver 3\r
+       PACK_ADD_POLICY_BOOL("RSandRAFilter", RSandRAFilter);\r
+       PACK_ADD_POLICY_BOOL("RAFilter", RAFilter);\r
+       PACK_ADD_POLICY_BOOL("DHCPv6Filter", DHCPv6Filter);\r
+       PACK_ADD_POLICY_BOOL("DHCPv6NoServer", DHCPv6NoServer);\r
+       PACK_ADD_POLICY_BOOL("NoRoutingV6", NoRoutingV6);\r
+       PACK_ADD_POLICY_BOOL("CheckIPv6", CheckIPv6);\r
+       PACK_ADD_POLICY_BOOL("NoServerV6", NoServerV6);\r
+       PACK_ADD_POLICY_BOOL("NoSavePassword", NoSavePassword);\r
+       PACK_ADD_POLICY_BOOL("FilterIPv4", FilterIPv4);\r
+       PACK_ADD_POLICY_BOOL("FilterIPv6", FilterIPv6);\r
+       PACK_ADD_POLICY_BOOL("FilterNonIP", FilterNonIP);\r
+       PACK_ADD_POLICY_BOOL("NoIPv6DefaultRouterInRA", NoIPv6DefaultRouterInRA);\r
+       PACK_ADD_POLICY_BOOL("NoIPv6DefaultRouterInRAWhenIPv6", NoIPv6DefaultRouterInRAWhenIPv6);\r
+\r
+       // UINT 値\r
+       // Ver 2\r
+       PACK_ADD_POLICY_UINT("MaxConnection", MaxConnection);\r
+       PACK_ADD_POLICY_UINT("TimeOut", TimeOut);\r
+       PACK_ADD_POLICY_UINT("MaxMac", MaxMac);\r
+       PACK_ADD_POLICY_UINT("MaxIP", MaxIP);\r
+       PACK_ADD_POLICY_UINT("MaxUpload", MaxUpload);\r
+       PACK_ADD_POLICY_UINT("MaxDownload", MaxDownload);\r
+       PACK_ADD_POLICY_UINT("MultiLogins", MultiLogins);\r
+       // Ver 3\r
+       PACK_ADD_POLICY_UINT("MaxIPv6", MaxIPv6);\r
+       PACK_ADD_POLICY_UINT("AutoDisconnect", AutoDisconnect);\r
+       PACK_ADD_POLICY_UINT("VLanId", VLanId);\r
+\r
+       // Ver 3 フラグ\r
+       PackAddBool(p, "policy:Ver3", true);\r
+}\r
+\r
+// 追加接続用の認証データをアップロードする\r
+bool ClientUploadAuth2(CONNECTION *c, SOCK *s)\r
+{\r
+       PACK *p = NULL;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = PackAdditionalConnect(c->Session->SessionKey);\r
+\r
+       PackAddClientVersion(p, c);\r
+\r
+       if (HttpClientSend(s, p) == false)\r
+       {\r
+               FreePack(p);\r
+               return false;\r
+       }\r
+       FreePack(p);\r
+\r
+       return true;\r
+}\r
+\r
+// NOOP を送信する\r
+void ClientUploadNoop(CONNECTION *c)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = PackError(0);\r
+       PackAddInt(p, "noop", 1);\r
+       HttpClientSend(c->FirstSock, p);\r
+       FreePack(p);\r
+\r
+       p = HttpClientRecv(c->FirstSock);\r
+       if (p != NULL)\r
+       {\r
+               FreePack(p);\r
+       }\r
+}\r
+\r
+// クライアントのバージョン情報を PACK に追加する\r
+void PackAddClientVersion(PACK *p, CONNECTION *c)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddStr(p, "client_str", c->ClientStr);\r
+       PackAddInt(p, "client_ver", c->ClientVer);\r
+       PackAddInt(p, "client_build", c->ClientBuild);\r
+}\r
+\r
+// 新規接続用の認証データをアップロードする\r
+bool ClientUploadAuth(CONNECTION *c)\r
+{\r
+       PACK *p = NULL;\r
+       CLIENT_AUTH *a;\r
+       CLIENT_OPTION *o;\r
+       X *x;\r
+       bool ret;\r
+       NODE_INFO info;\r
+       UCHAR secure_password[SHA1_SIZE];\r
+       UCHAR sign[4096 / 8];\r
+       UCHAR unique[SHA1_SIZE];\r
+       RPC_WINVER v;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(sign, sizeof(sign));\r
+\r
+       a = c->Session->ClientAuth;\r
+       o = c->Session->ClientOption;\r
+\r
+       if (c->UseTicket == false)\r
+       {\r
+               switch (a->AuthType)\r
+               {\r
+               case CLIENT_AUTHTYPE_ANONYMOUS:\r
+                       // 匿名認証\r
+                       p = PackLoginWithAnonymous(o->HubName, a->Username);\r
+                       break;\r
+\r
+               case CLIENT_AUTHTYPE_PASSWORD:\r
+                       // パスワード認証\r
+                       SecurePassword(secure_password, a->HashedPassword, c->Random);\r
+                       p = PackLoginWithPassword(o->HubName, a->Username, secure_password);\r
+                       break;\r
+\r
+               case CLIENT_AUTHTYPE_PLAIN_PASSWORD:\r
+                       // 平文パスワード認証\r
+                       p = PackLoginWithPlainPassword(o->HubName, a->Username, a->PlainPassword);\r
+                       break;\r
+\r
+               case CLIENT_AUTHTYPE_CERT:\r
+                       // 証明書認証\r
+                       if (a->ClientX != NULL && a->ClientX->is_compatible_bit &&\r
+                               a->ClientX->bits != 0 && (a->ClientX->bits / 8) <= sizeof(sign))\r
+                       {\r
+                               if (RsaSignEx(sign, c->Random, SHA1_SIZE, a->ClientK, a->ClientX->bits))\r
+                               {\r
+                                       p = PackLoginWithCert(o->HubName, a->Username, a->ClientX, sign, a->ClientX->bits / 8);\r
+                                       c->ClientX = CloneX(a->ClientX);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case CLIENT_AUTHTYPE_SECURE:\r
+                       // セキュアデバイスによる認証\r
+                       if (ClientSecureSign(c, sign, c->Random, &x))\r
+                       {\r
+                               p = PackLoginWithCert(o->HubName, a->Username, x, sign, 128);\r
+                               c->ClientX = CloneX(x);\r
+                               FreeX(x);\r
+                       }\r
+                       else\r
+                       {\r
+                               c->Err = ERR_SECURE_DEVICE_OPEN_FAILED;\r
+                               c->Session->ForceStopFlag = true;\r
+                       }\r
+                       break;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // チケット\r
+               p = NewPack();\r
+               PackAddStr(p, "method", "login");\r
+               PackAddStr(p, "hubname", o->HubName);\r
+               PackAddStr(p, "username", a->Username);\r
+               PackAddInt(p, "authtype", AUTHTYPE_TICKET);\r
+               PackAddData(p, "ticket", c->Ticket, SHA1_SIZE);\r
+       }\r
+\r
+       // 現在時刻\r
+       PackAddInt64(p, "timestamp", SystemTime64());\r
+\r
+       if (p == NULL)\r
+       {\r
+               // エラー\r
+               if (c->Err != ERR_SECURE_DEVICE_OPEN_FAILED)\r
+               {\r
+                       c->Err = ERR_PROTOCOL_ERROR;\r
+               }\r
+               return false;\r
+       }\r
+\r
+       PackAddClientVersion(p, c);\r
+\r
+       // プロトコル\r
+       PackAddInt(p, "protocol", c->Protocol);\r
+\r
+       // バージョン等\r
+       PackAddStr(p, "hello", c->ClientStr);\r
+       PackAddInt(p, "version", c->ClientVer);\r
+       PackAddInt(p, "build", c->ClientBuild);\r
+       PackAddInt(p, "client_id", c->Cedar->ClientId);\r
+\r
+       // 最大コネクション数\r
+       PackAddInt(p, "max_connection", o->MaxConnection);\r
+       // 暗号化使用フラグ\r
+       PackAddInt(p, "use_encrypt", o->UseEncrypt == false ? 0 : 1);\r
+       // 高速暗号化使用フラグ\r
+       //      PackAddInt(p, "use_fast_rc4", o->UseFastRC4 == false ? 0 : 1);\r
+       // データ圧縮使用フラグ\r
+       PackAddInt(p, "use_compress", o->UseCompress == false ? 0 : 1);\r
+       // ハーフコネクションフラグ\r
+       PackAddInt(p, "half_connection", o->HalfConnection == false ? 0 : 1);\r
+\r
+       // ブリッジ / ルーティングモードフラグ\r
+       PackAddBool(p, "require_bridge_routing_mode", o->RequireBridgeRoutingMode);\r
+\r
+       // モニタモードフラグ\r
+       PackAddBool(p, "require_monitor_mode", o->RequireMonitorMode);\r
+\r
+       // VoIP / QoS フラグ\r
+       PackAddBool(p, "qos", o->DisableQoS ? false : true);\r
+\r
+       // ユニーク ID\r
+       GenerateMachineUniqueHash(unique);\r
+       PackAddData(p, "unique_id", unique, SHA1_SIZE);\r
+\r
+       // ノード情報\r
+       CreateNodeInfo(&info, c);\r
+       OutRpcNodeInfo(p, &info);\r
+\r
+       // OS 情報\r
+       GetWinVer(&v);\r
+       OutRpcWinVer(p, &v);\r
+\r
+       ret = HttpClientSend(c->FirstSock, p);\r
+       if (ret == false)\r
+       {\r
+               c->Err = ERR_DISCONNECTED;\r
+       }\r
+\r
+       FreePack(p);\r
+\r
+       return ret;\r
+}\r
+\r
+// Hello パケットをアップロードする\r
+bool ServerUploadHello(CONNECTION *c)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 乱数生成\r
+       Rand(c->Random, SHA1_SIZE);\r
+\r
+       p = PackHello(c->Random, c->ServerVer, c->ServerBuild, c->ServerStr);\r
+       if (HttpServerSend(c->FirstSock, p) == false)\r
+       {\r
+               FreePack(p);\r
+               c->Err = ERR_DISCONNECTED;\r
+               return false;\r
+       }\r
+\r
+       FreePack(p);\r
+\r
+       return true;\r
+}\r
+\r
+// Hello パケットをダウンロードする\r
+bool ClientDownloadHello(CONNECTION *c, SOCK *s)\r
+{\r
+       PACK *p;\r
+       UINT err;\r
+       UCHAR random[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // データ受信\r
+       p = HttpClientRecv(s);\r
+       if (p == NULL)\r
+       {\r
+               c->Err = ERR_SERVER_IS_NOT_VPN;\r
+               return false;\r
+       }\r
+\r
+       if (err = GetErrorFromPack(p))\r
+       {\r
+               // エラー発生\r
+               c->Err = err;\r
+               FreePack(p);\r
+               return false;\r
+       }\r
+\r
+       // パケット解釈\r
+       if (GetHello(p, random, &c->ServerVer, &c->ServerBuild, c->ServerStr, sizeof(c->ServerStr)) == false)\r
+       {\r
+               c->Err = ERR_SERVER_IS_NOT_VPN;\r
+               FreePack(p);\r
+               return false;\r
+       }\r
+\r
+       if (c->FirstSock == s)\r
+       {\r
+               Copy(c->Random, random, SHA1_SIZE);\r
+       }\r
+\r
+       FreePack(p);\r
+\r
+       return true;\r
+}\r
+\r
+// シグネチャをダウンロードする\r
+bool ServerDownloadSignature(CONNECTION *c)\r
+{\r
+       HTTP_HEADER *h;\r
+       UCHAR *data;\r
+       UINT data_size;\r
+       SOCK *s;\r
+       UINT num = 0, max = 19;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s = c->FirstSock;\r
+\r
+       while (true)\r
+       {\r
+               num++;\r
+               if (num > max)\r
+               {\r
+                       // 切断\r
+                       Disconnect(s);\r
+                       c->Err = ERR_CLIENT_IS_NOT_VPN;\r
+                       return false;\r
+               }\r
+               // ヘッダを受信する\r
+               h = RecvHttpHeader(s);\r
+               if (h == NULL)\r
+               {\r
+                       c->Err = ERR_CLIENT_IS_NOT_VPN;\r
+                       return false;\r
+               }\r
+\r
+               // 解釈する\r
+               if (StrCmpi(h->Method, "POST") == 0)\r
+               {\r
+                       // POST なのでデータを受信する\r
+                       data_size = GetContentLength(h);\r
+                       if ((data_size > 3411 || data_size < 1411) && (data_size != StrLen(HTTP_VPN_TARGET_POSTDATA)))\r
+                       {\r
+                               // データが大きすぎる\r
+                               HttpSendForbidden(s, h->Target, NULL);\r
+                               FreeHttpHeader(h);\r
+                               c->Err = ERR_CLIENT_IS_NOT_VPN;\r
+                               return false;\r
+                       }\r
+                       data = Malloc(data_size);\r
+                       if (RecvAll(s, data, data_size, s->SecureMode) == false)\r
+                       {\r
+                               // データ受信失敗\r
+                               Free(data);\r
+                               FreeHttpHeader(h);\r
+                               c->Err = ERR_DISCONNECTED;\r
+                               return false;\r
+                       }\r
+                       // Target を確認する\r
+                       if (StrCmpi(h->Target, HTTP_VPN_TARGET2) != 0)\r
+                       {\r
+                               // ターゲットが不正\r
+                               HttpSendNotFound(s, h->Target);\r
+                               Free(data);\r
+                               FreeHttpHeader(h);\r
+                       }\r
+                       else\r
+                       {\r
+                               if (((data_size == StrLen(HTTP_VPN_TARGET_POSTDATA)) && (Cmp(data, HTTP_VPN_TARGET_POSTDATA, data_size) == 0)) || (data_size >= 1411))\r
+                               {\r
+                                       // VPN Client が接続してきた\r
+                                       Free(data);\r
+                                       FreeHttpHeader(h);\r
+                                       return true;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // VPN Client 以外のソフトウェアが接続してきた\r
+                                       HttpSendForbidden(s, h->Target, NULL);\r
+                                       FreeHttpHeader(h);\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // これ以上解釈しても VPN クライアントで無い可能性が高いが\r
+                       // 一応する\r
+                       if (StrCmpi(h->Method, "GET") != 0)\r
+                       {\r
+                               // サポートされていないメソッド呼び出し\r
+                               HttpSendNotImplemented(s, h->Method, h->Target, h->Version);\r
+                       }\r
+                       else\r
+                       {\r
+                               if (StrCmpi(h->Target, "/") == 0)\r
+                               {\r
+                                       // ルートディレクトリ\r
+                                       HttpSendForbidden(c->FirstSock, h->Target, "");\r
+                               }\r
+                               else\r
+                               {\r
+                                       // Not Found\r
+                                       HttpSendNotFound(s, h->Target);\r
+                               }\r
+                       }\r
+                       FreeHttpHeader(h);\r
+               }\r
+       }\r
+}\r
+\r
+// シグネチャをアップロードする\r
+bool ClientUploadSignature(SOCK *s)\r
+{\r
+       HTTP_HEADER *h;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       h = NewHttpHeader("POST", HTTP_VPN_TARGET2, "HTTP/1.1");\r
+       AddHttpValue(h, NewHttpValue("Content-Type", HTTP_CONTENT_TYPE3));\r
+       AddHttpValue(h, NewHttpValue("Connection", "Keep-Alive"));\r
+\r
+       if (PostHttp(s, h, HTTP_VPN_TARGET_POSTDATA, StrLen(HTTP_VPN_TARGET_POSTDATA)) == false)\r
+       {\r
+               FreeHttpHeader(h);\r
+               return false;\r
+       }\r
+\r
+       FreeHttpHeader(h);\r
+\r
+       return true;\r
+}\r
+\r
+// サーバーへの接続を確立する\r
+SOCK *ClientConnectToServer(CONNECTION *c)\r
+{\r
+       SOCK *s = NULL;\r
+       X *x = NULL;\r
+       K *k = NULL;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (c->Halt)\r
+       {\r
+               c->Err = ERR_USER_CANCEL;\r
+               return NULL;\r
+       }\r
+\r
+       // 接続してソケットを取得\r
+       s = ClientConnectGetSocket(c, false);\r
+       if (s == NULL)\r
+       {\r
+               // 接続失敗\r
+               return NULL;\r
+       }\r
+\r
+       c->FirstSock = s;\r
+\r
+       if (c->Halt)\r
+       {\r
+               c->Err = ERR_USER_CANCEL;\r
+               ReleaseSock(s);\r
+               c->FirstSock = NULL;\r
+               return NULL;\r
+       }\r
+\r
+       // タイムアウト\r
+       SetTimeout(s, CONNECTING_TIMEOUT);\r
+\r
+       // SSL 通信の開始\r
+       if (StartSSLEx(s, x, k, (c->DontUseTls1 ? false : true)) == false)\r
+       {\r
+               // SSL 通信開始失敗\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+               c->FirstSock = NULL;\r
+               c->Err = ERR_SERVER_IS_NOT_VPN;\r
+               return NULL;\r
+       }\r
+\r
+       if (s->RemoteX == NULL)\r
+       {\r
+               // SSL 通信開始失敗\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+               c->FirstSock = NULL;\r
+               c->Err = ERR_SERVER_IS_NOT_VPN;\r
+               return NULL;\r
+       }\r
+\r
+       return s;\r
+}\r
+\r
+// サーバーに接続しソケットを返す\r
+SOCK *ClientConnectGetSocket(CONNECTION *c, bool additional_connect)\r
+{\r
+       SOCK *s = NULL;\r
+       CLIENT_OPTION *o;\r
+       char *host_for_direct_connection;\r
+       UINT port_for_direct_connection;\r
+       wchar_t tmp[MAX_SIZE];\r
+       SESSION *sess;\r
+       volatile bool *cancel_flag = NULL;\r
+       void *hWnd;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       sess = c->Session;\r
+\r
+       if (sess != NULL)\r
+       {\r
+               cancel_flag = &sess->CancelConnect;\r
+       }\r
+\r
+       hWnd = c->hWndForUI;\r
+\r
+       o = c->Session->ClientOption;\r
+\r
+       if (c->RestoreServerNameAndPort && additional_connect)\r
+       {\r
+               // サーバー名とポート番号を元に戻す\r
+               c->RestoreServerNameAndPort = false;\r
+\r
+               StrCpy(c->ServerName, sizeof(c->ServerName), o->Hostname);\r
+               c->ServerPort = o->Port;\r
+       }\r
+\r
+       host_for_direct_connection = c->ServerName;\r
+       port_for_direct_connection = c->ServerPort;\r
+\r
+       if (o->PortUDP != 0)\r
+       {\r
+               // UDP Connection\r
+               goto UDP_CONNECTION;\r
+       }\r
+\r
+       switch (o->ProxyType)\r
+       {\r
+       case PROXY_DIRECT:      // TCP/IP\r
+UDP_CONNECTION:\r
+               UniFormat(tmp, sizeof(tmp), _UU("STATUS_4"), c->ServerName);\r
+               PrintStatus(sess, tmp);\r
+               // 本番\r
+               s = TcpIpConnectEx(host_for_direct_connection, port_for_direct_connection,\r
+                       (bool *)cancel_flag, hWnd);\r
+               if (s == NULL)\r
+               {\r
+                       // 接続失敗\r
+                       c->Err = ERR_CONNECT_FAILED;\r
+                       return NULL;\r
+               }\r
+               break;\r
+\r
+       case PROXY_HTTP:        // HTTP Proxy\r
+               host_for_direct_connection = o->ProxyName;\r
+               port_for_direct_connection = o->ProxyPort;\r
+\r
+               UniFormat(tmp, sizeof(tmp), _UU("STATUS_2"), c->ServerName, o->ProxyName);\r
+               PrintStatus(sess, tmp);\r
+               // プロキシ接続\r
+               s = ProxyConnectEx(c, host_for_direct_connection, port_for_direct_connection,\r
+                       c->ServerName, c->ServerPort, o->ProxyUsername, o->ProxyPassword,\r
+                       additional_connect, (bool *)cancel_flag, hWnd);\r
+               if (s == NULL)\r
+               {\r
+                       // 接続失敗\r
+                       return NULL;\r
+               }\r
+               break;\r
+\r
+       case PROXY_SOCKS:       // SOCKS Proxy\r
+               host_for_direct_connection = o->ProxyName;\r
+\r
+               port_for_direct_connection = o->ProxyPort;\r
+\r
+               UniFormat(tmp, sizeof(tmp), _UU("STATUS_2"), c->ServerName, o->ProxyName);\r
+               PrintStatus(sess, tmp);\r
+               // SOCKS 接続\r
+               s = SocksConnectEx(c, host_for_direct_connection, port_for_direct_connection,\r
+                       c->ServerName, c->ServerPort, o->ProxyUsername,\r
+                       additional_connect, (bool *)cancel_flag, hWnd);\r
+               if (s == NULL)\r
+               {\r
+                       // 接続失敗\r
+                       return NULL;\r
+               }\r
+               break;\r
+       }\r
+\r
+       if (s == NULL)\r
+       {\r
+               // 接続失敗\r
+               c->Err = ERR_CONNECT_FAILED;\r
+       }\r
+       else\r
+       {\r
+               // 接続成功\r
+               // IP アドレスを控えておく\r
+               if (GetIP(&c->Session->ServerIP, host_for_direct_connection) == false)\r
+               {\r
+                       Copy(&c->Session->ServerIP, &s->RemoteIP, sizeof(IP));\r
+               }\r
+       }\r
+\r
+       return s;\r
+}\r
+\r
+// SOCKS 経由で接続する\r
+SOCK *SocksConnect(CONNECTION *c, char *proxy_host_name, UINT proxy_port,\r
+                                  char *server_host_name, UINT server_port,\r
+                                  char *username, bool additional_connect)\r
+{\r
+       return SocksConnectEx(c, proxy_host_name, proxy_port,\r
+               server_host_name, server_port, username, additional_connect, NULL, NULL);\r
+}\r
+SOCK *SocksConnectEx(CONNECTION *c, char *proxy_host_name, UINT proxy_port,\r
+                                  char *server_host_name, UINT server_port,\r
+                                  char *username, bool additional_connect,\r
+                                  bool *cancel_flag, void *hWnd)\r
+{\r
+       SOCK *s = NULL;\r
+       IP ip;\r
+       // 引数チェック\r
+       if (c == NULL || proxy_host_name == NULL || proxy_port == 0 || server_host_name == NULL\r
+               || server_port == 0)\r
+       {\r
+               c->Err = ERR_PROXY_CONNECT_FAILED;\r
+               return NULL;\r
+       }\r
+\r
+       // 接続先サーバーの IP アドレスを取得す\r
+       if (GetIP(&ip, server_host_name) == false)\r
+       {\r
+               // 失敗\r
+               c->Err = ERR_CONNECT_FAILED;\r
+               return NULL;\r
+       }\r
+\r
+       if (c->Halt)\r
+       {\r
+               // 停止\r
+               c->Err = ERR_USER_CANCEL;\r
+               return NULL;\r
+       }\r
+\r
+       // 接続\r
+       s = TcpConnectEx2(proxy_host_name, proxy_port, 0, cancel_flag, hWnd);\r
+       if (s == NULL)\r
+       {\r
+               // 失敗\r
+               c->Err = ERR_PROXY_CONNECT_FAILED;\r
+               return NULL;\r
+       }\r
+\r
+       // タイムアウト設定\r
+       SetTimeout(s, CONNECTING_TIMEOUT_PROXY);\r
+\r
+       if (additional_connect == false)\r
+       {\r
+               c->FirstSock = s;\r
+       }\r
+\r
+       // リクエストパケット送信\r
+       if (SocksSendRequestPacket(c, s, server_port, &ip, username) == false)\r
+       {\r
+               // 失敗\r
+               if (additional_connect == false)\r
+               {\r
+                       c->FirstSock = NULL;\r
+               }\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+               return NULL;\r
+       }\r
+\r
+       // 応答パケット受信\r
+       if (SocksRecvResponsePacket(c, s) == false)\r
+       {\r
+               // 失敗\r
+               if (additional_connect == false)\r
+               {\r
+                       c->FirstSock = NULL;\r
+               }\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+               return NULL;\r
+       }\r
+\r
+       SetTimeout(s, INFINITE);\r
+\r
+       return s;\r
+}\r
+\r
+// SOCKS 応答パケットを受信する\r
+bool SocksRecvResponsePacket(CONNECTION *c, SOCK *s)\r
+{\r
+       BUF *b;\r
+       UINT size = 8;\r
+       UCHAR tmp[8];\r
+       UCHAR vn, cd;\r
+       // 引数チェック\r
+       if (c == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (RecvAll(s, tmp, sizeof(tmp), false) == false)\r
+       {\r
+               c->Err = ERR_DISCONNECTED;\r
+               return false;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, tmp, sizeof(tmp));\r
+       SeekBuf(b, 0, 0);\r
+\r
+       ReadBuf(b, &vn, 1);\r
+       ReadBuf(b, &cd, 1);\r
+\r
+       FreeBuf(b);\r
+\r
+       if (vn != 0)\r
+       {\r
+               c->Err = ERR_PROXY_ERROR;\r
+               return false;\r
+       }\r
+\r
+       switch (cd)\r
+       {\r
+       case 90:\r
+               // 成功\r
+               return true;\r
+\r
+       case 93:\r
+               // 認証失敗\r
+               c->Err = ERR_PROXY_AUTH_FAILED;\r
+               return false;\r
+\r
+       default:\r
+               // サーバーへの接続失敗\r
+               c->Err = ERR_CONNECT_FAILED;\r
+               return false;\r
+       }\r
+}\r
+\r
+// SOCKS リクエストパケットを送信する\r
+bool SocksSendRequestPacket(CONNECTION *c, SOCK *s, UINT dest_port, IP *dest_ip, char *userid)\r
+{\r
+       BUF *b;\r
+       UCHAR vn, cd;\r
+       USHORT port;\r
+       UINT ip;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (s == NULL || dest_port == 0 || dest_ip == NULL || c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (userid == NULL)\r
+       {\r
+               userid = "";\r
+       }\r
+\r
+       b = NewBuf();\r
+       vn = 4;\r
+       cd = 1;\r
+       WriteBuf(b, &vn, 1);\r
+       WriteBuf(b, &cd, 1);\r
+       port = Endian16((USHORT)dest_port);\r
+       ip = IPToUINT(dest_ip);\r
+       WriteBuf(b, &port, 2);\r
+       WriteBuf(b, &ip, 4);\r
+       WriteBuf(b, userid, StrLen(userid) + 1);\r
+\r
+       ret = SendAll(s, b->Buf, b->Size, false);\r
+       if (ret == false)\r
+       {\r
+               c->Err = ERR_DISCONNECTED;\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// プロキシ経由で接続する\r
+SOCK *ProxyConnect(CONNECTION *c, char *proxy_host_name, UINT proxy_port,\r
+                                  char *server_host_name, UINT server_port,\r
+                                  char *username, char *password, bool additional_connect)\r
+{\r
+       return ProxyConnectEx(c, proxy_host_name, proxy_port,\r
+               server_host_name, server_port, username, password, additional_connect, NULL, NULL);\r
+}\r
+SOCK *ProxyConnectEx(CONNECTION *c, char *proxy_host_name, UINT proxy_port,\r
+                                  char *server_host_name, UINT server_port,\r
+                                  char *username, char *password, bool additional_connect,\r
+                                  bool *cancel_flag, void *hWnd)\r
+{\r
+       SOCK *s = NULL;\r
+       bool use_auth = false;\r
+       char tmp[MAX_SIZE];\r
+       char auth_tmp_str[MAX_SIZE], auth_b64_str[MAX_SIZE * 2];\r
+       char basic_str[MAX_SIZE * 2];\r
+       UINT http_error_code;\r
+       HTTP_HEADER *h;\r
+       // 引数チェック\r
+       if (c == NULL || proxy_host_name == NULL || proxy_port == 0 || server_host_name == NULL ||\r
+               server_port == 0)\r
+       {\r
+               c->Err = ERR_PROXY_CONNECT_FAILED;\r
+               return NULL;\r
+       }\r
+       if (username != NULL && password != NULL &&\r
+               (StrLen(username) != 0 || StrLen(password) != 0))\r
+       {\r
+               use_auth = true;\r
+       }\r
+\r
+       if (c->Halt)\r
+       {\r
+               // 停止\r
+               c->Err = ERR_USER_CANCEL;\r
+               return NULL;\r
+       }\r
+\r
+       // 接続\r
+       s = TcpConnectEx2(proxy_host_name, proxy_port, 0, cancel_flag, hWnd);\r
+       if (s == NULL)\r
+       {\r
+               // 失敗\r
+               c->Err = ERR_PROXY_CONNECT_FAILED;\r
+               return NULL;\r
+       }\r
+\r
+       // タイムアウト設定\r
+       SetTimeout(s, CONNECTING_TIMEOUT_PROXY);\r
+\r
+       if (additional_connect == false)\r
+       {\r
+               c->FirstSock = s;\r
+       }\r
+\r
+       // HTTP ヘッダ生成\r
+       if (IsStrIPv6Address(server_host_name))\r
+       {\r
+               IP ip;\r
+               char iptmp[MAX_PATH];\r
+\r
+               StrToIP(&ip, server_host_name);\r
+               IPToStr(iptmp, sizeof(iptmp), &ip);\r
+\r
+               Format(tmp, sizeof(tmp), "[%s]:%u", iptmp, server_port);\r
+       }\r
+       else\r
+       {\r
+               Format(tmp, sizeof(tmp), "%s:%u", server_host_name, server_port);\r
+       }\r
+\r
+       h = NewHttpHeader("CONNECT", tmp, "HTTP/1.0");\r
+       AddHttpValue(h, NewHttpValue("User-Agent", c->Cedar->HttpUserAgent));\r
+       Debug("proxy user agent = %s\n", c->Cedar->HttpUserAgent);\r
+       AddHttpValue(h, NewHttpValue("Host", server_host_name));\r
+       AddHttpValue(h, NewHttpValue("Content-Length", "0"));\r
+       AddHttpValue(h, NewHttpValue("Proxy-Connection", "Keep-Alive"));\r
+       AddHttpValue(h, NewHttpValue("Pragma", "no-cache"));\r
+\r
+       if (use_auth)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               UniFormat(tmp, sizeof(tmp), _UU("STATUS_3"), server_host_name);\r
+               // 認証文字列の生成\r
+               Format(auth_tmp_str, sizeof(auth_tmp_str), "%s:%s",\r
+                       username, password);\r
+\r
+               // Base64 エンコード\r
+               Zero(auth_b64_str, sizeof(auth_b64_str));\r
+               Encode64(auth_b64_str, auth_tmp_str);\r
+               Format(basic_str, sizeof(basic_str), "Basic %s", auth_b64_str);\r
+\r
+               AddHttpValue(h, NewHttpValue("Proxy-Authorization", basic_str));\r
+       }\r
+\r
+       // 送信\r
+       if (SendHttpHeader(s, h) == false)\r
+       {\r
+               // 失敗\r
+               if (additional_connect == false)\r
+               {\r
+                       c->FirstSock = NULL;\r
+               }\r
+               FreeHttpHeader(h);\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+               c->Err = ERR_PROXY_ERROR;\r
+               return NULL;\r
+       }\r
+\r
+       FreeHttpHeader(h);\r
+\r
+       if (c->Halt)\r
+       {\r
+               // 停止\r
+               if (additional_connect == false)\r
+               {\r
+                       c->FirstSock = NULL;\r
+               }\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+               c->Err = ERR_USER_CANCEL;\r
+               return NULL;\r
+       }\r
+\r
+       // 結果を受信\r
+       h = RecvHttpHeader(s);\r
+       if (h == NULL)\r
+       {\r
+               // 失敗\r
+               if (additional_connect == false)\r
+               {\r
+                       c->FirstSock = NULL;\r
+               }\r
+               FreeHttpHeader(h);\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+               c->Err = ERR_PROXY_ERROR;\r
+               return NULL;\r
+       }\r
+\r
+       http_error_code = 0;\r
+       if (StrLen(h->Method) == 8)\r
+       {\r
+               if (Cmp(h->Method, "HTTP/1.", 7) == 0)\r
+               {\r
+                       http_error_code = ToInt(h->Target);\r
+               }\r
+       }\r
+       FreeHttpHeader(h);\r
+\r
+       // コードを確認\r
+       switch (http_error_code)\r
+       {\r
+       case 401:\r
+       case 403:\r
+       case 407:\r
+               // 認証失敗\r
+               if (additional_connect == false)\r
+               {\r
+                       c->FirstSock = NULL;\r
+               }\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+               c->Err = ERR_PROXY_AUTH_FAILED;\r
+               return NULL;\r
+\r
+       default:\r
+               if ((http_error_code / 100) == 2)\r
+               {\r
+                       // 成功\r
+                       SetTimeout(s, INFINITE);\r
+                       return s;\r
+               }\r
+               else\r
+               {\r
+                       // 不明な結果を受信\r
+                       if (additional_connect == false)\r
+                       {\r
+                               c->FirstSock = NULL;\r
+                       }\r
+                       Disconnect(s);\r
+                       ReleaseSock(s);\r
+                       c->Err = ERR_PROXY_ERROR;\r
+                       return NULL;\r
+               }\r
+       }\r
+}\r
+\r
+// TCP 接続関数\r
+SOCK *TcpConnectEx2(char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd)\r
+{\r
+#ifdef OS_WIN32\r
+       if (hWnd == NULL)\r
+       {\r
+               return ConnectEx2(hostname, port, timeout, cancel_flag);\r
+       }\r
+       else\r
+       {\r
+               return WinConnectEx2((HWND)hWnd, hostname, port, timeout, 0, NULL, NULL);\r
+       }\r
+#else  // OS_WIN32\r
+       return ConnectEx2(hostname, port, timeout, cancel_flag);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// TCP/IP で接続する\r
+SOCK *TcpIpConnect(char *hostname, UINT port)\r
+{\r
+       return TcpIpConnectEx(hostname, port, NULL, NULL);\r
+}\r
+SOCK *TcpIpConnectEx(char *hostname, UINT port, bool *cancel_flag, void *hWnd)\r
+{\r
+       SOCK *s = NULL;\r
+       // 引数チェック\r
+       if (hostname == NULL || port == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       s = TcpConnectEx2(hostname, port, 0, cancel_flag, hWnd);\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return s;\r
+}\r
+\r
+// PACK にダミーのエントリを作成する\r
+// Q. なぜランダムなサイズのランダムデータをここで挿入するのか?\r
+// A. ネットワーク経路中の盗聴者によってこの SSL 通信が VPN 通信であること\r
+//    を検出しにくいようにするためである。\r
+void CreateDummyValue(PACK *p)\r
+{\r
+       UINT size;\r
+       UCHAR *buf;\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       size = Rand32() % HTTP_PACK_RAND_SIZE_MAX;\r
+       buf = Malloc(size);\r
+       Rand(buf, size);\r
+\r
+       PackAddData(p, "pencore", buf, size);\r
+\r
+       Free(buf);\r
+}\r
+\r
+// サーバーがクライアントから PACK を受信する\r
+PACK *HttpServerRecv(SOCK *s)\r
+{\r
+       BUF *b;\r
+       PACK *p;\r
+       HTTP_HEADER *h;\r
+       UINT size;\r
+       UCHAR *tmp;\r
+       HTTP_VALUE *v;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+START:\r
+\r
+       h = RecvHttpHeader(s);\r
+       if (h == NULL)\r
+       {\r
+               goto BAD_REQUEST;\r
+       }\r
+\r
+       if (StrCmpi(h->Method, "POST") != 0 ||\r
+               StrCmpi(h->Target, HTTP_VPN_TARGET) != 0 ||\r
+               StrCmpi(h->Version, "HTTP/1.1") != 0)\r
+       {\r
+               FreeHttpHeader(h);\r
+               goto BAD_REQUEST;\r
+       }\r
+\r
+       v = GetHttpValue(h, "Content-Type");\r
+       if (v == NULL || StrCmpi(v->Data, HTTP_CONTENT_TYPE2) != 0)\r
+       {\r
+               FreeHttpHeader(h);\r
+               goto BAD_REQUEST;\r
+       }\r
+\r
+       size = GetContentLength(h);\r
+       if (size == 0 || size > MAX_PACK_SIZE)\r
+       {\r
+               FreeHttpHeader(h);\r
+               goto BAD_REQUEST;\r
+       }\r
+\r
+       tmp = MallocEx(size, true);\r
+       if (RecvAll(s, tmp, size, s->SecureMode) == false)\r
+       {\r
+               Free(tmp);\r
+               FreeHttpHeader(h);\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, tmp, size);\r
+       Free(tmp);\r
+       FreeHttpHeader(h);\r
+\r
+       SeekBuf(b, 0, 0);\r
+       p = BufToPack(b);\r
+       FreeBuf(b);\r
+\r
+       // NOOP かどうか判断\r
+       if (PackGetInt(p, "noop") != 0)\r
+       {\r
+               Debug("recv: noop\n");\r
+               FreePack(p);\r
+\r
+               p = PackError(0);\r
+               PackAddInt(p, "noop", 1);\r
+               if (HttpServerSend(s, p) == false)\r
+               {\r
+                       FreePack(p);\r
+                       return NULL;\r
+               }\r
+\r
+               FreePack(p);\r
+\r
+               goto START;\r
+       }\r
+\r
+       return p;\r
+\r
+BAD_REQUEST:\r
+       // エラーを返す\r
+\r
+\r
+       return NULL;\r
+}\r
+\r
+// クライアントがサーバーから PACK を受信する\r
+PACK *HttpClientRecv(SOCK *s)\r
+{\r
+       BUF *b;\r
+       PACK *p;\r
+       HTTP_HEADER *h;\r
+       UINT size;\r
+       UCHAR *tmp;\r
+       HTTP_VALUE *v;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       h = RecvHttpHeader(s);\r
+       if (h == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (StrCmpi(h->Method, "HTTP/1.1") != 0 ||\r
+               StrCmpi(h->Target, "200") != 0)\r
+       {\r
+               FreeHttpHeader(h);\r
+               return NULL;\r
+       }\r
+\r
+       v = GetHttpValue(h, "Content-Type");\r
+       if (v == NULL || StrCmpi(v->Data, HTTP_CONTENT_TYPE2) != 0)\r
+       {\r
+               FreeHttpHeader(h);\r
+               return NULL;\r
+       }\r
+\r
+       size = GetContentLength(h);\r
+       if (size == 0 || size > MAX_PACK_SIZE)\r
+       {\r
+               FreeHttpHeader(h);\r
+               return NULL;\r
+       }\r
+\r
+       tmp = MallocEx(size, true);\r
+       if (RecvAll(s, tmp, size, s->SecureMode) == false)\r
+       {\r
+               Free(tmp);\r
+               FreeHttpHeader(h);\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, tmp, size);\r
+       Free(tmp);\r
+       FreeHttpHeader(h);\r
+\r
+       SeekBuf(b, 0, 0);\r
+       p = BufToPack(b);\r
+       FreeBuf(b);\r
+\r
+       return p;\r
+}\r
+\r
+// クライアントからサーバーに PACK を送信する\r
+bool HttpClientSend(SOCK *s, PACK *p)\r
+{\r
+       BUF *b;\r
+       bool ret;\r
+       HTTP_HEADER *h;\r
+       char date_str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       CreateDummyValue(p);\r
+\r
+       b = PackToBuf(p);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       h = NewHttpHeader("POST", HTTP_VPN_TARGET, "HTTP/1.1");\r
+\r
+       GetHttpDateStr(date_str, sizeof(date_str), SystemTime64());\r
+       AddHttpValue(h, NewHttpValue("Date", date_str));\r
+       AddHttpValue(h, NewHttpValue("Keep-Alive", HTTP_KEEP_ALIVE));\r
+       AddHttpValue(h, NewHttpValue("Connection", "Keep-Alive"));\r
+       AddHttpValue(h, NewHttpValue("Content-Type", HTTP_CONTENT_TYPE2));\r
+\r
+       ret = PostHttp(s, h, b->Buf, b->Size);\r
+\r
+       FreeHttpHeader(h);\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// サーバーからクライアントに PACK を送信する\r
+bool HttpServerSend(SOCK *s, PACK *p)\r
+{\r
+       BUF *b;\r
+       bool ret;\r
+       HTTP_HEADER *h;\r
+       char date_str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       CreateDummyValue(p);\r
+\r
+       b = PackToBuf(p);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       h = NewHttpHeader("HTTP/1.1", "200", "OK");\r
+\r
+       GetHttpDateStr(date_str, sizeof(date_str), SystemTime64());\r
+       AddHttpValue(h, NewHttpValue("Date", date_str));\r
+       AddHttpValue(h, NewHttpValue("Keep-Alive", HTTP_KEEP_ALIVE));\r
+       AddHttpValue(h, NewHttpValue("Connection", "Keep-Alive"));\r
+       AddHttpValue(h, NewHttpValue("Content-Type", HTTP_CONTENT_TYPE2));\r
+\r
+       ret = PostHttp(s, h, b->Buf, b->Size);\r
+\r
+       FreeHttpHeader(h);\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// 501 Not Implemented エラーの送信\r
+bool HttpSendNotImplemented(SOCK *s, char *method, char *target, char *version)\r
+{\r
+       HTTP_HEADER *h;\r
+       char date_str[MAX_SIZE];\r
+       char *str;\r
+       UINT str_size;\r
+       char port_str[MAX_SIZE];\r
+       bool ret;\r
+       char host[MAX_SIZE];\r
+       UINT port;\r
+       // 引数チェック\r
+       if (s == NULL || target == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ホスト名の取得\r
+       GetMachineName(host, MAX_SIZE);\r
+       // ポート番号の取得\r
+       port = s->LocalPort;\r
+\r
+       // ヘッダの作成\r
+       GetHttpDateStr(date_str, sizeof(date_str), SystemTime64());\r
+\r
+       h = NewHttpHeader("HTTP/1.1", "501", "Method Not Implemented");\r
+\r
+       AddHttpValue(h, NewHttpValue("Date", date_str));\r
+       AddHttpValue(h, NewHttpValue("Keep-Alive", HTTP_KEEP_ALIVE));\r
+       AddHttpValue(h, NewHttpValue("Connection", "Keep-Alive"));\r
+       AddHttpValue(h, NewHttpValue("Content-Type", HTTP_CONTENT_TYPE));\r
+\r
+       // データの作成\r
+       str_size = sizeof(http_501_str) * 2 + StrLen(target) + StrLen(host) + StrLen(method) + StrLen(version);\r
+       str = Malloc(str_size);\r
+       StrCpy(str, str_size, http_501_str);\r
+\r
+       // TARGET\r
+       ReplaceStri(str, str_size, str, "$TARGET$", target);\r
+\r
+       // HOST\r
+       ReplaceStri(str, str_size, str, "$HOST$", host);\r
+\r
+       // PORT\r
+       ToStr(port_str, port);\r
+       ReplaceStri(str, str_size, str, "$PORT$", port_str);\r
+\r
+       // METHOD\r
+       ReplaceStri(str, str_size, str, "$METHOD$", method);\r
+\r
+       // VERSION\r
+       ReplaceStri(str, str_size, str, "$VERSION$", version);\r
+\r
+       // 送信\r
+       ret = PostHttp(s, h, str, StrLen(str));\r
+\r
+       FreeHttpHeader(h);\r
+       Free(str);\r
+\r
+       return ret;\r
+}\r
+\r
+// 404 Not Found エラーの送信\r
+bool HttpSendNotFound(SOCK *s, char *target)\r
+{\r
+       HTTP_HEADER *h;\r
+       char date_str[MAX_SIZE];\r
+       char *str;\r
+       UINT str_size;\r
+       char port_str[MAX_SIZE];\r
+       bool ret;\r
+       char host[MAX_SIZE];\r
+       UINT port;\r
+       // 引数チェック\r
+       if (s == NULL || target == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ホスト名の取得\r
+       GetMachineName(host, MAX_SIZE);\r
+       // ポート番号の取得\r
+       port = s->LocalPort;\r
+\r
+       // ヘッダの作成\r
+       GetHttpDateStr(date_str, sizeof(date_str), SystemTime64());\r
+\r
+       h = NewHttpHeader("HTTP/1.1", "404", "Not Found");\r
+\r
+       AddHttpValue(h, NewHttpValue("Date", date_str));\r
+       AddHttpValue(h, NewHttpValue("Keep-Alive", HTTP_KEEP_ALIVE));\r
+       AddHttpValue(h, NewHttpValue("Connection", "Keep-Alive"));\r
+       AddHttpValue(h, NewHttpValue("Content-Type", HTTP_CONTENT_TYPE));\r
+\r
+       // データの作成\r
+       str_size = sizeof(http_404_str) * 2 + StrLen(target) + StrLen(host);\r
+       str = Malloc(str_size);\r
+       StrCpy(str, str_size, http_404_str);\r
+\r
+       // TARGET\r
+       ReplaceStri(str, str_size, str, "$TARGET$", target);\r
+\r
+       // HOST\r
+       ReplaceStri(str, str_size, str, "$HOST$", host);\r
+\r
+       // PORT\r
+       ToStr(port_str, port);\r
+       ReplaceStri(str, str_size, str, "$PORT$", port_str);\r
+\r
+       // 送信\r
+       ret = PostHttp(s, h, str, StrLen(str));\r
+\r
+       FreeHttpHeader(h);\r
+       Free(str);\r
+\r
+       return ret;\r
+}\r
+\r
+// 403 Forbidden エラーの送信\r
+bool HttpSendForbidden(SOCK *s, char *target, char *server_id)\r
+{\r
+       HTTP_HEADER *h;\r
+       char date_str[MAX_SIZE];\r
+       char *str;\r
+       UINT str_size;\r
+       char port_str[MAX_SIZE];\r
+       bool ret;\r
+       char host[MAX_SIZE];\r
+       UINT port;\r
+       // 引数チェック\r
+       if (s == NULL || target == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ホスト名の取得\r
+       GetMachineName(host, MAX_SIZE);\r
+       // ポート番号の取得\r
+       port = s->LocalPort;\r
+\r
+       // ヘッダの作成\r
+       GetHttpDateStr(date_str, sizeof(date_str), SystemTime64());\r
+\r
+       h = NewHttpHeader("HTTP/1.1", "403", "Forbidden");\r
+\r
+       AddHttpValue(h, NewHttpValue("Date", date_str));\r
+       AddHttpValue(h, NewHttpValue("Keep-Alive", HTTP_KEEP_ALIVE));\r
+       AddHttpValue(h, NewHttpValue("Connection", "Keep-Alive"));\r
+       AddHttpValue(h, NewHttpValue("Content-Type", HTTP_CONTENT_TYPE));\r
+\r
+       // データの作成\r
+       str_size = sizeof(http_403_str) * 2 + StrLen(target) + StrLen(host);\r
+       str = Malloc(str_size);\r
+       StrCpy(str, str_size, http_403_str);\r
+\r
+       // TARGET\r
+       ReplaceStri(str, str_size, str, "$TARGET$", target);\r
+\r
+       // HOST\r
+       ReplaceStri(str, str_size, str, "$HOST$", host);\r
+\r
+       // PORT\r
+       ToStr(port_str, port);\r
+       ReplaceStri(str, str_size, str, "$PORT$", port_str);\r
+\r
+       // 送信\r
+       ret = PostHttp(s, h, str, StrLen(str));\r
+\r
+       FreeHttpHeader(h);\r
+       Free(str);\r
+\r
+       return ret;\r
+}\r
+\r
+// HTTP ヘッダ用の日時文字列を取得\r
+void GetHttpDateStr(char *str, UINT size, UINT64 t)\r
+{\r
+       SYSTEMTIME s;\r
+       static char *wday[] =\r
+       {\r
+               "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",\r
+       };\r
+       static char *month[] =\r
+       {\r
+               "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",\r
+               "Nov", "Dec",\r
+       };\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+       UINT64ToSystem(&s, t);\r
+\r
+       Format(str, size, "%s, %02u %s %04u %02u:%02u:%02u GMT",\r
+               wday[s.wDayOfWeek], s.wDay, month[s.wMonth - 1], s.wYear,\r
+               s.wHour, s.wMinute, s.wSecond);\r
+}\r
+\r
+// HTTP ヘッダからコンテンツ長を取得する\r
+UINT GetContentLength(HTTP_HEADER *header)\r
+{\r
+       UINT ret;\r
+       HTTP_VALUE *v;\r
+       // 引数チェック\r
+       if (header == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       v = GetHttpValue(header, "Content-Length");\r
+       if (v == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = ToInt(v->Data);\r
+\r
+       return ret;\r
+}\r
+\r
+// HTTP でデータを送信する\r
+bool PostHttp(SOCK *s, HTTP_HEADER *header, void *post_data, UINT post_size)\r
+{\r
+       char *header_str;\r
+       BUF *b;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (s == NULL || header == NULL || post_data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // Content-Lentgh が存在するかどうかチェック\r
+       if (GetHttpValue(header, "Content-Length") == NULL)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               // 存在しないので付加する\r
+               ToStr(tmp, post_size);\r
+               AddHttpValue(header, NewHttpValue("Content-Length", tmp));\r
+       }\r
+\r
+       // ヘッダを文字列にする\r
+       header_str = HttpHeaderToStr(header);\r
+       if (header_str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       b = NewBuf();\r
+       WriteBuf(b, header_str, StrLen(header_str));\r
+       Free(header_str);\r
+\r
+       // データを追記する\r
+       WriteBuf(b, post_data, post_size);\r
+\r
+       // 送信する\r
+       ret = SendAll(s, b->Buf, b->Size, s->SecureMode);\r
+\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// HTTP ヘッダを文字列に変換\r
+char *HttpHeaderToStr(HTTP_HEADER *header)\r
+{\r
+       BUF *b;\r
+       char *tmp;\r
+       UINT i;\r
+       char *s;\r
+       // 引数チェック\r
+       if (header == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       tmp = Malloc(HTTP_HEADER_LINE_MAX_SIZE);\r
+       b = NewBuf();\r
+\r
+       // ヘッダ\r
+       Format(tmp, HTTP_HEADER_LINE_MAX_SIZE,\r
+               "%s %s %s\r\n", header->Method, header->Target, header->Version);\r
+       WriteBuf(b, tmp, StrLen(tmp));\r
+\r
+       // 値\r
+       for (i = 0;i < LIST_NUM(header->ValueList);i++)\r
+       {\r
+               HTTP_VALUE *v = (HTTP_VALUE *)LIST_DATA(header->ValueList, i);\r
+               Format(tmp, HTTP_HEADER_LINE_MAX_SIZE,\r
+                       "%s: %s\r\n", v->Name, v->Data);\r
+               WriteBuf(b, tmp, StrLen(tmp));\r
+       }\r
+\r
+       // 最後の改行\r
+       WriteBuf(b, "\r\n", 2);\r
+       s = Malloc(b->Size + 1);\r
+       Copy(s, b->Buf, b->Size);\r
+       s[b->Size] = 0;\r
+\r
+       FreeBuf(b);\r
+       Free(tmp);\r
+\r
+       return s;\r
+}\r
+\r
+// HTTP ヘッダを送信\r
+bool SendHttpHeader(SOCK *s, HTTP_HEADER *header)\r
+{\r
+       char *str;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (s == NULL || header == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 文字列に変換\r
+       str = HttpHeaderToStr(header);\r
+\r
+       // 送信\r
+       ret = SendAll(s, str, StrLen(str), s->SecureMode);\r
+\r
+       Free(str);\r
+\r
+       return ret;\r
+}\r
+\r
+// HTTP ヘッダを受信\r
+HTTP_HEADER *RecvHttpHeader(SOCK *s)\r
+{\r
+       TOKEN_LIST *token = NULL;\r
+       char *str = NULL;\r
+       HTTP_HEADER *header = NULL;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 1 行目を取得する\r
+       str = RecvLine(s, HTTP_HEADER_LINE_MAX_SIZE);\r
+       if (str == NULL)\r
+       {\r
+               goto ERROR;\r
+       }\r
+\r
+       // トークンに分割する\r
+       token = ParseToken(str, " ");\r
+       if (token->NumTokens < 3)\r
+       {\r
+               goto ERROR;\r
+       }\r
+\r
+       Free(str);\r
+       str = NULL;\r
+\r
+       // ヘッダの作成\r
+       header = NewHttpHeader(token->Token[0], token->Token[1], token->Token[2]);\r
+\r
+       if (!StrCmpi(header->Version, "HTTP/1.0") || !StrCmpi(header->Version, "HTTP/0.9"))\r
+       {\r
+               // この行で終わり\r
+               return header;\r
+       }\r
+\r
+       // 2 行目以降を取得する\r
+       while (true)\r
+       {\r
+               UINT pos;\r
+               HTTP_VALUE *v;\r
+               char *value_name, *value_data;\r
+               str = RecvLine(s, HTTP_HEADER_LINE_MAX_SIZE);\r
+               if (str == NULL)\r
+               {\r
+                       goto ERROR;\r
+               }\r
+               Trim(str);\r
+\r
+               if (StrLen(str) == 0)\r
+               {\r
+                       // ヘッダの終了\r
+                       Free(str);\r
+                       str = NULL;\r
+                       break;\r
+               }\r
+\r
+               // コロンの位置を取得する\r
+               pos = SearchStr(str, ":", 0);\r
+               if (pos == INFINITE)\r
+               {\r
+                       // コロンが存在しない\r
+                       goto ERROR;\r
+               }\r
+               if ((pos + 1) >= StrLen(str))\r
+               {\r
+                       // データが存在しない\r
+                       goto ERROR;\r
+               }\r
+\r
+               // 名前とデータの 2 つに分ける\r
+               value_name = Malloc(pos + 1);\r
+               Copy(value_name, str, pos);\r
+               value_name[pos] = 0;\r
+               value_data = &str[pos + 1];\r
+\r
+               v = NewHttpValue(value_name, value_data);\r
+               if (v == NULL)\r
+               {\r
+                       Free(value_name);\r
+                       goto ERROR;\r
+               }\r
+\r
+               Free(value_name);\r
+\r
+               AddHttpValue(header, v);\r
+               Free(str);\r
+       }\r
+\r
+       FreeToken(token);\r
+\r
+       return header;\r
+\r
+ERROR:\r
+       // メモリ解放\r
+       if (token)\r
+       {\r
+               FreeToken(token);\r
+       }\r
+       if (str)\r
+       {\r
+               Free(str);\r
+       }\r
+       if (header)\r
+       {\r
+               FreeHttpHeader(header);\r
+       }\r
+       return NULL;\r
+}\r
+\r
+// 1 行を受信する\r
+char *RecvLine(SOCK *s, UINT max_size)\r
+{\r
+       BUF *b;\r
+       char c;\r
+       char *str;\r
+       // 引数チェック\r
+       if (s == NULL || max_size == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+       while (true)\r
+       {\r
+               UCHAR *buf;\r
+               if (RecvAll(s, &c, sizeof(c), s->SecureMode) == false)\r
+               {\r
+                       FreeBuf(b);\r
+                       return NULL;\r
+               }\r
+               WriteBuf(b, &c, sizeof(c));\r
+               buf = (UCHAR *)b->Buf;\r
+               if (b->Size > max_size)\r
+               {\r
+                       FreeBuf(b);\r
+                       return NULL;\r
+               }\r
+               if (b->Size >= 1)\r
+               {\r
+                       if (buf[b->Size - 1] == '\n')\r
+                       {\r
+                               b->Size--;\r
+                               if (b->Size >= 1)\r
+                               {\r
+                                       if (buf[b->Size - 1] == '\r')\r
+                                       {\r
+                                               b->Size--;\r
+                                       }\r
+                               }\r
+                               str = Malloc(b->Size + 1);\r
+                               Copy(str, b->Buf, b->Size);\r
+                               str[b->Size] = 0;\r
+                               FreeBuf(b);\r
+\r
+                               return str;\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// 新しい HTTP 値の作成\r
+HTTP_VALUE *NewHttpValue(char *name, char *data)\r
+{\r
+       HTTP_VALUE *v;\r
+       // 引数チェック\r
+       if (name == NULL || data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       v = ZeroMalloc(sizeof(HTTP_VALUE));\r
+\r
+       v->Name = CopyStr(name);\r
+       v->Data = CopyStr(data);\r
+\r
+       Trim(v->Name);\r
+       Trim(v->Data);\r
+\r
+       return v;\r
+}\r
+\r
+// プロトコルルーチンの初期化\r
+void InitProtocol()\r
+{\r
+}\r
+\r
+// プロトコルルーチンの解放\r
+void FreeProtocol()\r
+{\r
+}\r
+\r
+// HTTP ヘッダから HTTP 値を探す\r
+HTTP_VALUE *GetHttpValue(HTTP_HEADER *header, char *name)\r
+{\r
+       HTTP_VALUE *v, t;\r
+       // 引数チェック\r
+       if (header == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t.Name = name;\r
+       v = Search(header->ValueList, &t);\r
+       if (v == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return v;\r
+}\r
+\r
+// HTTP ヘッダに HTTP 値を追加\r
+void AddHttpValue(HTTP_HEADER *header, HTTP_VALUE *value)\r
+{\r
+       // 引数チェック\r
+       if (header == NULL || value == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Insert(header->ValueList, value);\r
+}\r
+\r
+// HTTP ヘッダを作成\r
+HTTP_HEADER *NewHttpHeader(char *method, char *target, char *version)\r
+{\r
+       HTTP_HEADER *header;\r
+       // 引数チェック\r
+       if (method == NULL || target == NULL || version == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       header = ZeroMalloc(sizeof(HTTP_HEADER));\r
+\r
+       header->Method = CopyStr(method);\r
+       header->Target = CopyStr(target);\r
+       header->Version = CopyStr(version);\r
+       header->ValueList = NewListFast(CompareHttpValue);\r
+\r
+       return header;\r
+}\r
+\r
+// HTTP 値の比較関数\r
+int CompareHttpValue(void *p1, void *p2)\r
+{\r
+       HTTP_VALUE *v1, *v2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       v1 = *(HTTP_VALUE **)p1;\r
+       v2 = *(HTTP_VALUE **)p2;\r
+       if (v1 == NULL || v2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return StrCmpi(v1->Name, v2->Name);\r
+}\r
+\r
+// HTTP 値を解放\r
+void FreeHttpValue(HTTP_VALUE *value)\r
+{\r
+       // 引数チェック\r
+       if (value == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(value->Data);\r
+       Free(value->Name);\r
+\r
+       Free(value);\r
+}\r
+\r
+// HTTP ヘッダを解放\r
+void FreeHttpHeader(HTTP_HEADER *header)\r
+{\r
+       UINT i;\r
+       HTTP_VALUE **values;\r
+       // 引数チェック\r
+       if (header == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(header->Method);\r
+       Free(header->Target);\r
+       Free(header->Version);\r
+\r
+       values = ToArray(header->ValueList);\r
+       for (i = 0;i < LIST_NUM(header->ValueList);i++)\r
+       {\r
+               FreeHttpValue(values[i]);\r
+       }\r
+       Free(values);\r
+\r
+       ReleaseList(header->ValueList);\r
+\r
+       Free(header);\r
+}\r
+\r
+// パケットを受信\r
+PACK *RecvPack(SOCK *s)\r
+{\r
+       PACK *p;\r
+       BUF *b;\r
+       void *data;\r
+       UINT sz;\r
+       // 引数チェック\r
+       if (s == NULL || s->Type != SOCK_TCP)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (RecvAll(s, &sz, sizeof(UINT), s->SecureMode) == false)\r
+       {\r
+               return false;\r
+       }\r
+       sz = Endian32(sz);\r
+       if (sz > MAX_PACK_SIZE)\r
+       {\r
+               return false;\r
+       }\r
+       data = MallocEx(sz, true);\r
+       if (RecvAll(s, data, sz, s->SecureMode) == false)\r
+       {\r
+               Free(data);\r
+               return false;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, data, sz);\r
+       SeekBuf(b, 0, 0);\r
+       p = BufToPack(b);\r
+       FreeBuf(b);\r
+       Free(data);\r
+\r
+       return p;\r
+}\r
+\r
+// パケットを送信\r
+bool SendPack(SOCK *s, PACK *p)\r
+{\r
+       BUF *b;\r
+       UINT sz;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL || s->Type != SOCK_TCP)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = PackToBuf(p);\r
+       sz = Endian32(b->Size);\r
+\r
+       SendAdd(s, &sz, sizeof(UINT));\r
+       SendAdd(s, b->Buf, b->Size);\r
+       FreeBuf(b);\r
+\r
+       return SendNow(s, s->SecureMode);\r
+}\r
+\r
+// Hello パケットを作成\r
+PACK *PackHello(void *random, UINT ver, UINT build, char *server_str)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (random == NULL || server_str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "hello", server_str);\r
+       PackAddInt(p, "version", ver);\r
+       PackAddInt(p, "build", build);\r
+       PackAddData(p, "random", random, SHA1_SIZE);\r
+\r
+       return p;\r
+}\r
+\r
+// Hello パケットを解釈\r
+bool GetHello(PACK *p, void *random, UINT *ver, UINT *build, char *server_str, UINT server_str_size)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || random == NULL || ver == NULL || server_str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (PackGetStr(p, "hello", server_str, server_str_size) == false)\r
+       {\r
+               return false;\r
+       }\r
+       *ver = PackGetInt(p, "version");\r
+       *build = PackGetInt(p, "build");\r
+       if (PackGetDataSize(p, "random") != SHA1_SIZE)\r
+       {\r
+               return false;\r
+       }\r
+       if (PackGetData(p, "random", random) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// エラー値を PACK に格納\r
+PACK *PackError(UINT error)\r
+{\r
+       PACK *p;\r
+\r
+       p = NewPack();\r
+       PackAddInt(p, "error", error);\r
+\r
+       return p;\r
+}\r
+\r
+// エラー値を PACK から取得\r
+UINT GetErrorFromPack(PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return PackGetInt(p, "error");\r
+}\r
+\r
+// 認証方法を PACK から取得\r
+UINT GetAuthTypeFromPack(PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return PackGetInt(p, "authtype");\r
+}\r
+\r
+// ユーザー名と HUB 名を PACK から取得\r
+bool GetHubnameAndUsernameFromPack(PACK *p, char *username, UINT username_size,\r
+                                                                  char *hubname, UINT hubname_size)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || username == NULL || hubname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (PackGetStr(p, "username", username, username_size) == false)\r
+       {\r
+               return false;\r
+       }\r
+       if (PackGetStr(p, "hubname", hubname, hubname_size) == false)\r
+       {\r
+               return false;\r
+       }\r
+       return true;\r
+}\r
+\r
+// プロトコルを PACK から取得\r
+UINT GetProtocolFromPack(PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+#if    0\r
+       return PackGetInt(p, "protocol");\r
+#else\r
+       // 現バージョンでは TCP プロトコルに限定する\r
+       return CONNECTION_TCP;\r
+#endif\r
+}\r
+\r
+// メソッドを PACK から取得\r
+bool GetMethodFromPack(PACK *p, char *method, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || method == NULL || size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return PackGetStr(p, "method", method, size);\r
+}\r
+\r
+// 証明書認証ログイン用のパケットを生成\r
+PACK *PackLoginWithCert(char *hubname, char *username, X *x, void *sign, UINT sign_size)\r
+{\r
+       PACK *p;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (hubname == NULL || username == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "method", "login");\r
+       PackAddStr(p, "hubname", hubname);\r
+       PackAddStr(p, "username", username);\r
+       PackAddInt(p, "authtype", CLIENT_AUTHTYPE_CERT);\r
+\r
+       // 証明書\r
+       b = XToBuf(x, false);\r
+       PackAddData(p, "cert", b->Buf, b->Size);\r
+       FreeBuf(b);\r
+\r
+       // 署名データ\r
+       PackAddData(p, "sign", sign, sign_size);\r
+\r
+       return p;\r
+}\r
+\r
+// 平文パスワード認証ログイン用のパケットを生成\r
+PACK *PackLoginWithPlainPassword(char *hubname, char *username, void *plain_password)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (hubname == NULL || username == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "method", "login");\r
+       PackAddStr(p, "hubname", hubname);\r
+       PackAddStr(p, "username", username);\r
+       PackAddInt(p, "authtype", CLIENT_AUTHTYPE_PLAIN_PASSWORD);\r
+       PackAddStr(p, "plain_password", plain_password);\r
+\r
+       return p;\r
+}\r
+\r
+// パスワード認証ログイン用のパケットを作成\r
+PACK *PackLoginWithPassword(char *hubname, char *username, void *secure_password)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (hubname == NULL || username == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "method", "login");\r
+       PackAddStr(p, "hubname", hubname);\r
+       PackAddStr(p, "username", username);\r
+       PackAddInt(p, "authtype", CLIENT_AUTHTYPE_PASSWORD);\r
+       PackAddData(p, "secure_password", secure_password, SHA1_SIZE);\r
+\r
+       return p;\r
+}\r
+\r
+// 匿名ログイン用のパケットを作成\r
+PACK *PackLoginWithAnonymous(char *hubname, char *username)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (hubname == NULL || username == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "method", "login");\r
+       PackAddStr(p, "hubname", hubname);\r
+       PackAddStr(p, "username", username);\r
+       PackAddInt(p, "authtype", CLIENT_AUTHTYPE_ANONYMOUS);\r
+\r
+       return p;\r
+}\r
+\r
+// 追加接続用のパケットを作成\r
+PACK *PackAdditionalConnect(UCHAR *session_key)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (session_key == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "method", "additional_connect");\r
+       PackAddData(p, "session_key", session_key, SHA1_SIZE);\r
+\r
+       return p;\r
+}\r
+\r
+// PACK から K を取得\r
+K *PackGetK(PACK *p, char *name)\r
+{\r
+       K *k;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = PackGetBuf(p, name);\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       k = BufToK(b, true, false, NULL);\r
+       FreeBuf(b);\r
+\r
+       return k;\r
+}\r
+\r
+// PACK から X を取得\r
+X *PackGetX(PACK *p, char *name)\r
+{\r
+       X *x;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = PackGetBuf(p, name);\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       x = BufToX(b, false);\r
+       FreeBuf(b);\r
+\r
+       return x;\r
+}\r
+\r
+// PACK に K を追加\r
+void PackAddK(PACK *p, char *name, K *k)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = KToBuf(k, false, NULL);\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddBuf(p, name, b);\r
+       FreeBuf(b);\r
+}\r
+\r
+// PACK に X を追加\r
+void PackAddX(PACK *p, char *name, X *x)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = XToBuf(x, false);\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddBuf(p, name, b);\r
+       FreeBuf(b);\r
+}\r
+\r
+// PACK からバッファを取得\r
+BUF *PackGetBuf(PACK *p, char *name)\r
+{\r
+       return PackGetBufEx(p, name, 0);\r
+}\r
+BUF *PackGetBufEx(PACK *p, char *name, UINT index)\r
+{\r
+       UINT size;\r
+       void *tmp;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = PackGetDataSizeEx(p, name, index);\r
+       tmp = MallocEx(size, true);\r
+       if (PackGetDataEx(p, name, tmp, index) == false)\r
+       {\r
+               Free(tmp);\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, tmp, size);\r
+       SeekBuf(b, 0, 0);\r
+\r
+       Free(tmp);\r
+\r
+       return b;\r
+}\r
+\r
+// PACK からデータを取得\r
+bool PackGetData(PACK *p, char *name, void *data)\r
+{\r
+       return PackGetDataEx(p, name, data, 0);\r
+}\r
+bool PackGetDataEx(PACK *p, char *name, void *data, UINT index)\r
+{\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       e = GetElement(p, name, VALUE_DATA);\r
+       if (e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       Copy(data, GetDataValue(e, index), GetDataValueSize(e, index));\r
+       return true;\r
+}\r
+bool PackGetData2(PACK *p, char *name, void *data, UINT size)\r
+{\r
+       return PackGetDataEx2(p, name, data, size, 0);\r
+}\r
+bool PackGetDataEx2(PACK *p, char *name, void *data, UINT size, UINT index)\r
+{\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       e = GetElement(p, name, VALUE_DATA);\r
+       if (e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (GetDataValueSize(e, index) != size)\r
+       {\r
+               return false;\r
+       }\r
+       Copy(data, GetDataValue(e, index), GetDataValueSize(e, index));\r
+       return true;\r
+}\r
+\r
+// PACK からデータサイズを取得\r
+UINT PackGetDataSize(PACK *p, char *name)\r
+{\r
+       return PackGetDataSizeEx(p, name, 0);\r
+}\r
+UINT PackGetDataSizeEx(PACK *p, char *name, UINT index)\r
+{\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       e = GetElement(p, name, VALUE_DATA);\r
+       if (e == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return GetDataValueSize(e, index);\r
+}\r
+\r
+// PACK から整数を取得\r
+UINT64 PackGetInt64(PACK *p, char *name)\r
+{\r
+       return PackGetInt64Ex(p, name, 0);\r
+}\r
+UINT64 PackGetInt64Ex(PACK *p, char *name, UINT index)\r
+{\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       e = GetElement(p, name, VALUE_INT64);\r
+       if (e == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return GetInt64Value(e, index);\r
+}\r
+\r
+// PACK からインデックス数を取得\r
+UINT PackGetIndexCount(PACK *p, char *name)\r
+{\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       e = GetElement(p, name, INFINITE);\r
+       if (e == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return e->num_value;\r
+}\r
+\r
+// PACK から個数を取得\r
+UINT PackGetNum(PACK *p, char *name)\r
+{\r
+       return MIN(PackGetInt(p, name), 65536);\r
+}\r
+\r
+// PACK から bool 型を取得\r
+bool PackGetBool(PACK *p, char *name)\r
+{\r
+       return PackGetInt(p, name) == 0 ? false : true;\r
+}\r
+bool PackGetBoolEx(PACK *p, char *name, UINT index)\r
+{\r
+       return PackGetIntEx(p, name, index) == 0 ? false : true;\r
+}\r
+\r
+// PACK に bool 型を追加\r
+void PackAddBool(PACK *p, char *name, bool b)\r
+{\r
+       PackAddInt(p, name, b ? 1 : 0);\r
+}\r
+void PackAddBoolEx(PACK *p, char *name, bool b, UINT index, UINT total)\r
+{\r
+       PackAddIntEx(p, name, b ? 1 : 0, index, total);\r
+}\r
+\r
+// PACK に IPV6_ADDR を追加\r
+void PackAddIp6AddrEx(PACK *p, char *name, IPV6_ADDR *addr, UINT index, UINT total)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || addr == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddDataEx(p, name, addr, sizeof(IPV6_ADDR), index, total);\r
+}\r
+void PackAddIp6Addr(PACK *p, char *name, IPV6_ADDR *addr)\r
+{\r
+       PackAddIp6AddrEx(p, name, addr, 0, 1);\r
+}\r
+\r
+// PACK から IPV6_ADDR を取得\r
+bool PackGetIp6AddrEx(PACK *p, char *name, IPV6_ADDR *addr, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || addr == NULL)\r
+       {\r
+               Zero(addr, sizeof(IPV6_ADDR));\r
+               return false;\r
+       }\r
+\r
+       return PackGetDataEx2(p, name, addr, sizeof(IPV6_ADDR), index);\r
+}\r
+bool PackGetIp6Addr(PACK *p, char *name, IPV6_ADDR *addr)\r
+{\r
+       return PackGetIp6AddrEx(p, name, addr, 0);\r
+}\r
+\r
+// PACK に IP を追加\r
+void PackAddIp32Ex(PACK *p, char *name, UINT ip32, UINT index, UINT total)\r
+{\r
+       IP ip;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UINTToIP(&ip, ip32);\r
+\r
+       PackAddIpEx(p, name, &ip, index, total);\r
+}\r
+void PackAddIp32(PACK *p, char *name, UINT ip32)\r
+{\r
+       PackAddIp32Ex(p, name, ip32, 0, 1);\r
+}\r
+void PackAddIpEx(PACK *p, char *name, IP *ip, UINT index, UINT total)\r
+{\r
+       UINT i;\r
+       bool b = false;\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = IsIP6(ip);\r
+\r
+       Format(tmp, sizeof(tmp), "%s@ipv6_bool", name);\r
+       PackAddBoolEx(p, tmp, b, index, total);\r
+\r
+       Format(tmp, sizeof(tmp), "%s@ipv6_array", name);\r
+       if (b)\r
+       {\r
+               PackAddDataEx(p, tmp, ip->ipv6_addr, sizeof(ip->ipv6_addr), index, total);\r
+       }\r
+       else\r
+       {\r
+               UCHAR dummy[16];\r
+\r
+               Zero(dummy, sizeof(dummy));\r
+\r
+               PackAddDataEx(p, tmp, dummy, sizeof(dummy), index, total);\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), "%s@ipv6_scope_id", name);\r
+       if (b)\r
+       {\r
+               PackAddIntEx(p, tmp, ip->ipv6_scope_id, index, total);\r
+       }\r
+       else\r
+       {\r
+               PackAddIntEx(p, tmp, 0, index, total);\r
+       }\r
+\r
+       i = IPToUINT(ip);\r
+\r
+       if (IsBigEndian())\r
+       {\r
+               i = Swap32(i);\r
+       }\r
+\r
+       PackAddIntEx(p, name, i, index, total);\r
+}\r
+void PackAddIp(PACK *p, char *name, IP *ip)\r
+{\r
+       PackAddIpEx(p, name, ip, 0, 1);\r
+}\r
+\r
+// PACK から IP を取得\r
+UINT PackGetIp32Ex(PACK *p, char *name, UINT index)\r
+{\r
+       IP ip;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (PackGetIpEx(p, name, &ip, index) == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return IPToUINT(&ip);\r
+}\r
+UINT PackGetIp32(PACK *p, char *name)\r
+{\r
+       return PackGetIp32Ex(p, name, 0);\r
+}\r
+bool PackGetIpEx(PACK *p, char *name, IP *ip, UINT index)\r
+{\r
+       UINT i;\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (p == NULL || ip == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), "%s@ipv6_bool", name);\r
+       if (PackGetBoolEx(p, tmp, index))\r
+       {\r
+               UCHAR data[16];\r
+               UINT scope_id;\r
+\r
+               Zero(data, sizeof(data));\r
+\r
+               Format(tmp, sizeof(tmp), "%s@ipv6_array", name);\r
+               PackGetDataEx2(p, tmp, data, sizeof(data), index);\r
+\r
+               Format(tmp, sizeof(tmp), "%s@ipv6_scope_id", name);\r
+               scope_id = PackGetIntEx(p, tmp, index);\r
+\r
+               SetIP6(ip, data);\r
+               ip->ipv6_scope_id = scope_id;\r
+       }\r
+       else\r
+       {\r
+               if (GetElement(p, name, VALUE_INT) == NULL)\r
+               {\r
+                       Zero(ip, sizeof(IP));\r
+                       return false;\r
+               }\r
+\r
+               i = PackGetIntEx(p, name, index);\r
+\r
+               if (IsBigEndian())\r
+               {\r
+                       i = Swap32(i);\r
+               }\r
+\r
+               UINTToIP(ip, i);\r
+       }\r
+\r
+       return true;\r
+}\r
+bool PackGetIp(PACK *p, char *name, IP *ip)\r
+{\r
+       return PackGetIpEx(p, name, ip, 0);\r
+}\r
+\r
+// PACK から整数を取得\r
+UINT PackGetInt(PACK *p, char *name)\r
+{\r
+       return PackGetIntEx(p, name, 0);\r
+}\r
+UINT PackGetIntEx(PACK *p, char *name, UINT index)\r
+{\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       e = GetElement(p, name, VALUE_INT);\r
+       if (e == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return GetIntValue(e, index);\r
+}\r
+\r
+// PACK から Unicode 文字列を取得\r
+bool PackGetUniStr(PACK *p, char *name, wchar_t *unistr, UINT size)\r
+{\r
+       return PackGetUniStrEx(p, name, unistr, size, 0);\r
+}\r
+bool PackGetUniStrEx(PACK *p, char *name, wchar_t *unistr, UINT size, UINT index)\r
+{\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || unistr == NULL || size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       unistr[0] = 0;\r
+\r
+       e = GetElement(p, name, VALUE_UNISTR);\r
+       if (e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       UniStrCpy(unistr, size, GetUniStrValue(e, index));\r
+       return true;\r
+}\r
+\r
+// PACK から文字列を取得\r
+bool PackGetStr(PACK *p, char *name, char *str, UINT size)\r
+{\r
+       return PackGetStrEx(p, name, str, size, 0);\r
+}\r
+bool PackGetStrEx(PACK *p, char *name, char *str, UINT size, UINT index)\r
+{\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || str == NULL || size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       str[0] = 0;\r
+\r
+       e = GetElement(p, name, VALUE_STR);\r
+       if (e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(str, size, GetStrValue(e, index));\r
+       return true;\r
+}\r
+\r
+// バッファを PACK に追加 (配列)\r
+void PackAddBufEx(PACK *p, char *name, BUF *b, UINT index, UINT total)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || b == NULL || total == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddDataEx(p, name, b->Buf, b->Size, index, total);\r
+}\r
+\r
+// データを PACK に追加 (配列)\r
+void PackAddDataEx(PACK *p, char *name, void *data, UINT size, UINT index, UINT total)\r
+{\r
+       VALUE *v;\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || data == NULL || name == NULL || total == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = NewDataValue(data, size);\r
+       e = GetElement(p, name, VALUE_DATA);\r
+       if (e != NULL)\r
+       {\r
+               if (e->num_value <= total)\r
+               {\r
+                       e->values[index] = v;\r
+               }\r
+               else\r
+               {\r
+                       FreeValue(v, VALUE_DATA);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               e = ZeroMallocEx(sizeof(ELEMENT), true);\r
+               StrCpy(e->name, sizeof(e->name), name);\r
+               e->num_value = total;\r
+               e->type = VALUE_DATA;\r
+               e->values = ZeroMallocEx(sizeof(VALUE *) * total, true);\r
+               e->values[index] = v;\r
+               AddElement(p, e);\r
+       }\r
+}\r
+\r
+// バッファを PACK に追加\r
+void PackAddBuf(PACK *p, char *name, BUF *b)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddData(p, name, b->Buf, b->Size);\r
+}\r
+\r
+// データを PACK に追加\r
+void PackAddData(PACK *p, char *name, void *data, UINT size)\r
+{\r
+       VALUE *v;\r
+       // 引数チェック\r
+       if (p == NULL || data == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = NewDataValue(data, size);\r
+       AddElement(p, NewElement(name, VALUE_DATA, 1, &v));\r
+}\r
+\r
+// 64 bit 整数を PACK に追加 (配列)\r
+void PackAddInt64Ex(PACK *p, char *name, UINT64 i, UINT index, UINT total)\r
+{\r
+       VALUE *v;\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || total == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = NewInt64Value(i);\r
+       e = GetElement(p, name, VALUE_INT64);\r
+       if (e != NULL)\r
+       {\r
+               if (e->num_value <= total)\r
+               {\r
+                       e->values[index] = v;\r
+               }\r
+               else\r
+               {\r
+                       FreeValue(v, VALUE_INT64);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               e = ZeroMallocEx(sizeof(ELEMENT), true);\r
+               StrCpy(e->name, sizeof(e->name), name);\r
+               e->num_value = total;\r
+               e->type = VALUE_INT64;\r
+               e->values = ZeroMallocEx(sizeof(VALUE *) * total, true);\r
+               e->values[index] = v;\r
+               AddElement(p, e);\r
+       }\r
+}\r
+\r
+// 整数を PACK に追加 (配列)\r
+void PackAddIntEx(PACK *p, char *name, UINT i, UINT index, UINT total)\r
+{\r
+       VALUE *v;\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || total == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = NewIntValue(i);\r
+       e = GetElement(p, name, VALUE_INT);\r
+       if (e != NULL)\r
+       {\r
+               if (e->num_value <= total)\r
+               {\r
+                       e->values[index] = v;\r
+               }\r
+               else\r
+               {\r
+                       FreeValue(v, VALUE_INT);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               e = ZeroMallocEx(sizeof(ELEMENT), true);\r
+               StrCpy(e->name, sizeof(e->name), name);\r
+               e->num_value = total;\r
+               e->type = VALUE_INT;\r
+               e->values = ZeroMallocEx(sizeof(VALUE *) * total, true);\r
+               e->values[index] = v;\r
+               AddElement(p, e);\r
+       }\r
+}\r
+\r
+// 64 bit 整数を PACK に追加\r
+void PackAddInt64(PACK *p, char *name, UINT64 i)\r
+{\r
+       VALUE *v;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = NewInt64Value(i);\r
+       AddElement(p, NewElement(name, VALUE_INT64, 1, &v));\r
+}\r
+\r
+// 個数を PACK に追加\r
+void PackAddNum(PACK *p, char *name, UINT num)\r
+{\r
+       PackAddInt(p, name, num);\r
+}\r
+\r
+// 整数を PACK に追加\r
+void PackAddInt(PACK *p, char *name, UINT i)\r
+{\r
+       VALUE *v;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = NewIntValue(i);\r
+       AddElement(p, NewElement(name, VALUE_INT, 1, &v));\r
+}\r
+\r
+// Unicode 文字列を PACK に追加 (配列)\r
+void PackAddUniStrEx(PACK *p, char *name, wchar_t *unistr, UINT index, UINT total)\r
+{\r
+       VALUE *v;\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || unistr == NULL || total == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = NewUniStrValue(unistr);\r
+       e = GetElement(p, name, VALUE_UNISTR);\r
+       if (e != NULL)\r
+       {\r
+               if (e->num_value <= total)\r
+               {\r
+                       e->values[index] = v;\r
+               }\r
+               else\r
+               {\r
+                       FreeValue(v, VALUE_UNISTR);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               e = ZeroMallocEx(sizeof(ELEMENT), true);\r
+               StrCpy(e->name, sizeof(e->name), name);\r
+               e->num_value = total;\r
+               e->type = VALUE_UNISTR;\r
+               e->values = ZeroMallocEx(sizeof(VALUE *) * total, true);\r
+               e->values[index] = v;\r
+               AddElement(p, e);\r
+       }\r
+}\r
+\r
+// Unicode 文字列を PACK に追加\r
+void PackAddUniStr(PACK *p, char *name, wchar_t *unistr)\r
+{\r
+       VALUE *v;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || unistr == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = NewUniStrValue(unistr);\r
+       AddElement(p, NewElement(name, VALUE_UNISTR, 1, &v));\r
+}\r
+\r
+// 文字列を PACK に追加 (配列)\r
+void PackAddStrEx(PACK *p, char *name, char *str, UINT index, UINT total)\r
+{\r
+       VALUE *v;\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || str == NULL || total == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = NewStrValue(str);\r
+       e = GetElement(p, name, VALUE_STR);\r
+       if (e != NULL)\r
+       {\r
+               if (e->num_value <= total)\r
+               {\r
+                       e->values[index] = v;\r
+               }\r
+               else\r
+               {\r
+                       FreeValue(v, VALUE_STR);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               e = ZeroMallocEx(sizeof(ELEMENT), true);\r
+               StrCpy(e->name, sizeof(e->name), name);\r
+               e->num_value = total;\r
+               e->type = VALUE_STR;\r
+               e->values = ZeroMallocEx(sizeof(VALUE *) * total, true);\r
+               e->values[index] = v;\r
+               AddElement(p, e);\r
+       }\r
+}\r
+\r
+// 文字列を PACK に追加\r
+void PackAddStr(PACK *p, char *name, char *str)\r
+{\r
+       VALUE *v;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = NewStrValue(str);\r
+       AddElement(p, NewElement(name, VALUE_STR, 1, &v));\r
+}\r
+\r
+// RC4 キーペアを生成\r
+void GenerateRC4KeyPair(RC4_KEY_PAIR *k)\r
+{\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Rand(k->ClientToServerKey, sizeof(k->ClientToServerKey));\r
+       Rand(k->ServerToClientKey, sizeof(k->ServerToClientKey));\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Protocol.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Protocol.h
new file mode 100644 (file)
index 0000000..4946f21
--- /dev/null
@@ -0,0 +1,299 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Protocol.h\r
+// Protocol.c のヘッダ\r
+\r
+#ifndef        PROTOCOL_H\r
+#define        PROTOCOL_H\r
+\r
+// 証明書確認用スレッドに渡すパラメータ\r
+struct CHECK_CERT_THREAD_PROC\r
+{\r
+       CONNECTION *Connection;\r
+       X *ServerX;\r
+       CHECK_CERT_PROC *CheckCertProc;\r
+       bool UserSelected;\r
+       bool Exipred;\r
+       bool Ok;\r
+};\r
+\r
+// セキュアデバイス署名用スレッドに渡すパラメータ\r
+struct SECURE_SIGN_THREAD_PROC\r
+{\r
+       SECURE_SIGN_PROC *SecureSignProc;\r
+       CONNECTION *Connection;\r
+       SECURE_SIGN *SecureSign;\r
+       bool UserFinished;\r
+       bool Ok;\r
+};\r
+\r
+// ランダムサイズキャッシュ\r
+struct RAND_CACHE\r
+{\r
+       IP Ip;                                                  // IP アドレス\r
+       UINT RandSize;                                  // ランダムサイズ\r
+       UINT64 LastTime;                                // 最終使用日時\r
+};\r
+\r
+// HTTP 値\r
+struct HTTP_VALUE\r
+{\r
+       char *Name;                                             // 名前\r
+       char *Data;                                             // データ\r
+};\r
+\r
+// HTTP ヘッダ\r
+struct HTTP_HEADER\r
+{\r
+       char *Method;                                   // メソッド\r
+       char *Target;                                   // ターゲット\r
+       char *Version;                                  // バージョン\r
+       LIST *ValueList;                                // 値リスト\r
+};\r
+\r
+// シグネチャ送信スレッド用パラメータ\r
+struct SEND_SIGNATURE_PARAM\r
+{\r
+       char Hostname[MAX_PATH];                // ホスト名\r
+       UINT Port;                                              // ポート番号\r
+       BUF *Buffer;                                    // パケット内容\r
+};\r
+\r
+\r
+// 関数プロトタイプ\r
+bool ServerAccept(CONNECTION *c);\r
+bool ClientConnect(CONNECTION *c);\r
+SOCK *ClientConnectToServer(CONNECTION *c);\r
+SOCK *TcpIpConnect(char *hostname, UINT port);\r
+SOCK *TcpIpConnectEx(char *hostname, UINT port, bool *cancel_flag, void *hWnd);\r
+bool ClientUploadSignature(SOCK *s);\r
+bool ClientDownloadHello(CONNECTION *c, SOCK *s);\r
+bool ServerDownloadSignature(CONNECTION *c);\r
+bool ServerUploadHello(CONNECTION *c);\r
+bool ClientUploadAuth(CONNECTION *c);\r
+SOCK *ClientConnectGetSocket(CONNECTION *c, bool additional_connect);\r
+SOCK *TcpConnectEx2(char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd);\r
+\r
+void InitProtocol();\r
+void FreeProtocol();\r
+\r
+bool HttpServerSend(SOCK *s, PACK *p);\r
+PACK *HttpServerRecv(SOCK *s);\r
+PACK *HttpClientRecv(SOCK *s);\r
+bool HttpClientSend(SOCK *s, PACK *p);\r
+\r
+bool HttpSendForbidden(SOCK *s, char *target, char *server_id);\r
+bool HttpSendNotFound(SOCK *s, char *target);\r
+bool HttpSendNotImplemented(SOCK *s, char *method, char *target, char *version);\r
+\r
+char *RecvLine(SOCK *s, UINT max_size);\r
+HTTP_HEADER *RecvHttpHeader(SOCK *s);\r
+void FreeHttpHeader(HTTP_HEADER *header);\r
+void FreeHttpValue(HTTP_VALUE *value);\r
+HTTP_HEADER *NewHttpHeader(char *method, char *target, char *version);\r
+void AddHttpValue(HTTP_HEADER *header, HTTP_VALUE *value);\r
+int CompareHttpValue(void *p1, void *p2);\r
+HTTP_VALUE *GetHttpValue(HTTP_HEADER *header, char *name);\r
+HTTP_VALUE *NewHttpValue(char *name, char *data);\r
+char *HttpHeaderToStr(HTTP_HEADER *header);\r
+bool SendHttpHeader(SOCK *s, HTTP_HEADER *header);\r
+bool PostHttp(SOCK *s, HTTP_HEADER *header, void *post_data, UINT post_size);\r
+UINT GetContentLength(HTTP_HEADER *header);\r
+void GetHttpDateStr(char *str, UINT size, UINT64 t);\r
+void CreateDummyValue(PACK *p);\r
+\r
+X *PackGetX(PACK *p, char *name);\r
+K *PackGetK(PACK *p, char *name);\r
+void PackAddX(PACK *p, char *name, X *x);\r
+void PackAddK(PACK *p, char *name, K *k);\r
+void PackAddStr(PACK *p, char *name, char *str);\r
+void PackAddStrEx(PACK *p, char *name, char *str, UINT index, UINT total);\r
+void PackAddUniStr(PACK *p, char *name, wchar_t *unistr);\r
+void PackAddUniStrEx(PACK *p, char *name, wchar_t *unistr, UINT index, UINT total);\r
+void PackAddInt(PACK *p, char *name, UINT i);\r
+void PackAddNum(PACK *p, char *name, UINT num);\r
+void PackAddIntEx(PACK *p, char *name, UINT i, UINT index, UINT total);\r
+void PackAddInt64(PACK *p, char *name, UINT64 i);\r
+void PackAddInt64Ex(PACK *p, char *name, UINT64 i, UINT index, UINT total);\r
+void PackAddData(PACK *p, char *name, void *data, UINT size);\r
+void PackAddDataEx(PACK *p, char *name, void *data, UINT size, UINT index, UINT total);\r
+void PackAddBuf(PACK *p, char *name, BUF *b);\r
+void PackAddBufEx(PACK *p, char *name, BUF *b, UINT index, UINT total);\r
+bool PackGetStr(PACK *p, char *name, char *str, UINT size);\r
+bool PackGetStrEx(PACK *p, char *name, char *str, UINT size, UINT index);\r
+bool PackGetUniStr(PACK *p, char *name, wchar_t *unistr, UINT size);\r
+bool PackGetUniStrEx(PACK *p, char *name, wchar_t *unistr, UINT size, UINT index);\r
+UINT PackGetIndexCount(PACK *p, char *name);\r
+UINT PackGetInt(PACK *p, char *name);\r
+UINT PackGetNum(PACK *p, char *name);\r
+UINT PackGetIntEx(PACK *p, char *name, UINT index);\r
+UINT64 PackGetInt64(PACK *p, char *name);\r
+UINT64 PackGetInt64Ex(PACK *p, char *name, UINT index);\r
+UINT PackGetDataSizeEx(PACK *p, char *name, UINT index);\r
+UINT PackGetDataSize(PACK *p, char *name);\r
+bool PackGetData(PACK *p, char *name, void *data);\r
+bool PackGetDataEx(PACK *p, char *name, void *data, UINT index);\r
+BUF *PackGetBuf(PACK *p, char *name);\r
+BUF *PackGetBufEx(PACK *p, char *name, UINT index);\r
+POLICY *PackGetPolicy(PACK *p);\r
+void PackAddPolicy(PACK *p, POLICY *y);\r
+bool PackGetBool(PACK *p, char *name);\r
+void PackAddBool(PACK *p, char *name, bool b);\r
+void PackAddBoolEx(PACK *p, char *name, bool b, UINT index, UINT total);\r
+bool PackGetBoolEx(PACK *p, char *name, UINT index);\r
+void PackAddIp(PACK *p, char *name, IP *ip);\r
+void PackAddIpEx(PACK *p, char *name, IP *ip, UINT index, UINT total);\r
+bool PackGetIp(PACK *p, char *name, IP *ip);\r
+bool PackGetIpEx(PACK *p, char *name, IP *ip, UINT index);\r
+UINT PackGetIp32(PACK *p, char *name);\r
+UINT PackGetIp32Ex(PACK *p, char *name, UINT index);\r
+void PackAddIp32(PACK *p, char *name, UINT ip32);\r
+void PackAddIp32Ex(PACK *p, char *name, UINT ip32, UINT index, UINT total);\r
+void PackAddIp6AddrEx(PACK *p, char *name, IPV6_ADDR *addr, UINT index, UINT total);\r
+bool PackGetIp6AddrEx(PACK *p, char *name, IPV6_ADDR *addr, UINT index);\r
+void PackAddIp6Addr(PACK *p, char *name, IPV6_ADDR *addr);\r
+bool PackGetIp6Addr(PACK *p, char *name, IPV6_ADDR *addr);\r
+\r
+PACK *PackWelcome(SESSION *s);\r
+PACK *PackHello(void *random, UINT ver, UINT build, char *server_str);\r
+bool GetHello(PACK *p, void *random, UINT *ver, UINT *build, char *server_str, UINT server_str_size);\r
+PACK *PackLoginWithAnonymous(char *hubname, char *username);\r
+PACK *PackLoginWithPassword(char *hubname, char *username, void *secure_password);\r
+PACK *PackLoginWithPlainPassword(char *hubname, char *username, void *plain_password);\r
+PACK *PackLoginWithCert(char *hubname, char *username, X *x, void *sign, UINT sign_size);\r
+bool GetMethodFromPack(PACK *p, char *method, UINT size);\r
+bool GetHubnameAndUsernameFromPack(PACK *p, char *username, UINT username_size,\r
+                                                                  char *hubname, UINT hubname_size);\r
+PACK *PackAdditionalConnect(UCHAR *session_key);\r
+UINT GetAuthTypeFromPack(PACK *p);\r
+UINT GetErrorFromPack(PACK *p);\r
+PACK *PackError(UINT error);\r
+UINT GetProtocolFromPack(PACK *p);\r
+bool ParseWelcomeFromPack(PACK *p, char *session_name, UINT session_name_size,\r
+                                                 char *connection_name, UINT connection_name_size,\r
+                                                 POLICY **policy);\r
+\r
+bool SendPack(SOCK *s, PACK *p);\r
+PACK *RecvPack(SOCK *s);\r
+\r
+bool ClientAdditionalConnect(CONNECTION *c, THREAD *t);\r
+SOCK *ClientAdditionalConnectToServer(CONNECTION *c);\r
+bool ClientUploadAuth2(CONNECTION *c, SOCK *s);\r
+bool GetSessionKeyFromPack(PACK *p, UCHAR *session_key, UINT *session_key_32);\r
+void GenerateRC4KeyPair(RC4_KEY_PAIR *k);\r
+\r
+SOCK *ProxyConnect(CONNECTION *c, char *proxy_host_name, UINT proxy_port,\r
+                                  char *server_host_name, UINT server_port,\r
+                                  char *username, char *password, bool additional_connect);\r
+SOCK *ProxyConnectEx(CONNECTION *c, char *proxy_host_name, UINT proxy_port,\r
+                                        char *server_host_name, UINT server_port,\r
+                                        char *username, char *password, bool additional_connect,\r
+                                        bool *cancel_flag, void *hWnd);\r
+SOCK *SocksConnect(CONNECTION *c, char *proxy_host_name, UINT proxy_port,\r
+                                  char *server_host_name, UINT server_port,\r
+                                  char *username, bool additional_connect);\r
+SOCK *SocksConnectEx(CONNECTION *c, char *proxy_host_name, UINT proxy_port,\r
+                                        char *server_host_name, UINT server_port,\r
+                                        char *username, bool additional_connect,\r
+                                        bool *cancel_flag, void *hWnd);\r
+bool SocksSendRequestPacket(CONNECTION *c, SOCK *s, UINT dest_port, IP *dest_ip, char *userid);\r
+bool SocksRecvResponsePacket(CONNECTION *c, SOCK *s);\r
+void CreateNodeInfo(NODE_INFO *info, CONNECTION *c);\r
+UINT SecureSign(SECURE_SIGN *sign, UINT device_id, char *pin);\r
+void ClientUploadNoop(CONNECTION *c);\r
+bool ClientCheckServerCert(CONNECTION *c, bool *expired);\r
+void ClientCheckServerCertThread(THREAD *thread, void *param);\r
+bool ClientSecureSign(CONNECTION *c, UCHAR *sign, UCHAR *random, X **x);\r
+void ClientSecureSignThread(THREAD *thread, void *param);\r
+UINT SecureWrite(UINT device_id, char *cert_name, X *x, char *key_name, K *k, char *pin);\r
+UINT SecureEnum(UINT device_id, char *pin, TOKEN_LIST **cert_list, TOKEN_LIST **key_list);\r
+UINT SecureDelete(UINT device_id, char *pin, char *cert_name, char *key_name);\r
+bool PackGetData2(PACK *p, char *name, void *data, UINT size);\r
+bool PackGetDataEx2(PACK *p, char *name, void *data, UINT size, UINT index);\r
+TOKEN_LIST *EnumHub(SESSION *s);\r
+UINT ChangePasswordAccept(CONNECTION *c, PACK *p);\r
+UINT ChangePassword(CEDAR *cedar, CLIENT_OPTION *o, char *hubname, char *username, char *old_pass, char *new_pass);\r
+void PackAddClientVersion(PACK *p, CONNECTION *c);\r
+void NodeInfoToStr(wchar_t *str, UINT size, NODE_INFO *info);\r
+void GenerateMachineUniqueHash(void *data);\r
+void SendSignatureByUdp(CONNECTION *c, IP *ip);\r
+void SendSignatureByTcp(CONNECTION *c, IP *ip);\r
+void SendSignatureByTcpThread(THREAD *thread, void *param);\r
+\r
+\r
+#endif // PROTOCOL_H\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Remote.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Remote.c
new file mode 100644 (file)
index 0000000..6bd508b
--- /dev/null
@@ -0,0 +1,441 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Remote.c\r
+// リモートプロシージャーコール\r
+\r
+#include "CedarPch.h"\r
+\r
+// RPC の終了\r
+void EndRpc(RPC *rpc)\r
+{\r
+       RpcFree(rpc);\r
+}\r
+\r
+// RPC の解放\r
+void RpcFree(RPC *rpc)\r
+{\r
+       // 引数チェック\r
+       if (rpc == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Disconnect(rpc->Sock);\r
+       ReleaseSock(rpc->Sock);\r
+\r
+       DeleteLock(rpc->Lock);\r
+\r
+       Free(rpc);\r
+}\r
+\r
+// エラーの取得\r
+UINT RpcGetError(PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return ERR_DISCONNECTED;\r
+       }\r
+\r
+       return PackGetInt(p, "error_code");\r
+}\r
+\r
+// エラーチェック\r
+bool RpcIsOk(PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (PackGetInt(p, "error") == 0)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// エラーコード設定\r
+void RpcError(PACK *p, UINT err)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "error", 1);\r
+       PackAddInt(p, "error_code", err);\r
+}\r
+\r
+// RPC ディスパッチャを起動する\r
+PACK *CallRpcDispatcher(RPC *r, PACK *p)\r
+{\r
+       char func_name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (r == NULL || p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (PackGetStr(p, "function_name", func_name, sizeof(func_name)) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return r->Dispatch(r, func_name, p);\r
+}\r
+\r
+// 次の RPC 呼び出しを待機する\r
+bool RpcRecvNextCall(RPC *r)\r
+{\r
+       UINT size;\r
+       void *tmp;\r
+       SOCK *s;\r
+       BUF *b;\r
+       PACK *p;\r
+       PACK *ret;\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s = r->Sock;\r
+\r
+       if (RecvAll(s, &size, sizeof(UINT), s->SecureMode) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       size = Endian32(size);\r
+\r
+       if (size > MAX_PACK_SIZE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       tmp = MallocEx(size, true);\r
+\r
+       if (RecvAll(s, tmp, size, s->SecureMode) == false)\r
+       {\r
+               Free(tmp);\r
+               return false;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, tmp, size);\r
+       SeekBuf(b, 0, 0);\r
+       Free(tmp);\r
+\r
+       p = BufToPack(b);\r
+       FreeBuf(b);\r
+\r
+       if (p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = CallRpcDispatcher(r, p);\r
+       FreePack(p);\r
+\r
+       if (ret == NULL)\r
+       {\r
+               ret = PackError(ERR_NOT_SUPPORTED);\r
+       }\r
+\r
+       b = PackToBuf(ret);\r
+       FreePack(ret);\r
+\r
+       size = Endian32(b->Size);\r
+       SendAdd(s, &size, sizeof(UINT));\r
+       SendAdd(s, b->Buf, b->Size);\r
+\r
+       if (SendNow(s, s->SecureMode) == false)\r
+       {\r
+               FreeBuf(b);\r
+               return false;\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return true;\r
+}\r
+\r
+// RPC サーバー動作\r
+void RpcServer(RPC *r)\r
+{\r
+       SOCK *s;\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = r->Sock;\r
+\r
+       while (true)\r
+       {\r
+               // 次の RPC 呼び出しを待機する\r
+               if (RpcRecvNextCall(r) == false)\r
+               {\r
+                       // 通信エラー\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// RPC 呼び出し\r
+PACK *RpcCall(RPC *r, char *function_name, PACK *p)\r
+{\r
+       PACK *ret;\r
+       UINT num_retry = 0;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (r == NULL || function_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+//     Debug("RpcCall: %s\n", function_name);\r
+\r
+       Lock(r->Lock);\r
+       {\r
+               if (p == NULL)\r
+               {\r
+                       p = NewPack();\r
+               }\r
+\r
+               PackAddStr(p, "function_name", function_name);\r
+\r
+RETRY:\r
+               err = 0;\r
+               ret = RpcCallInternal(r, p);\r
+\r
+               if (ret == NULL)\r
+               {\r
+                       if (r->IsVpnServer && r->Sock != NULL)\r
+                       {\r
+                               if (num_retry < 1)\r
+                               {\r
+                                       num_retry++;\r
+\r
+                                       // VPN Server に RPC 再接続を試みる\r
+                                       err = AdminReconnect(r);\r
+\r
+                                       if (err == ERR_NO_ERROR)\r
+                                       {\r
+                                               goto RETRY;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               FreePack(p);\r
+\r
+               if (ret == NULL)\r
+               {\r
+                       if (err == 0)\r
+                       {\r
+                               err = ERR_DISCONNECTED;\r
+                       }\r
+\r
+                       ret = PackError(err);\r
+                       PackAddInt(ret, "error_code", err);\r
+               }\r
+       }\r
+       Unlock(r->Lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// RPC 内部呼び出し\r
+PACK *RpcCallInternal(RPC *r, PACK *p)\r
+{\r
+       BUF *b;\r
+       UINT size;\r
+       PACK *ret;\r
+       void *tmp;\r
+       // 引数チェック\r
+       if (r == NULL || p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (r->Sock == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = PackToBuf(p);\r
+\r
+       size = Endian32(b->Size);\r
+       SendAdd(r->Sock, &size, sizeof(UINT));\r
+       SendAdd(r->Sock, b->Buf, b->Size);\r
+       FreeBuf(b);\r
+\r
+       if (SendNow(r->Sock, r->Sock->SecureMode) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (RecvAll(r->Sock, &size, sizeof(UINT), r->Sock->SecureMode) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = Endian32(size);\r
+       if (size > MAX_PACK_SIZE)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       tmp = MallocEx(size, true);\r
+       if (RecvAll(r->Sock, tmp, size, r->Sock->SecureMode) == false)\r
+       {\r
+               Free(tmp);\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, tmp, size);\r
+       SeekBuf(b, 0, 0);\r
+       Free(tmp);\r
+\r
+       ret = BufToPack(b);\r
+       if (ret == NULL)\r
+       {\r
+               FreeBuf(b);\r
+               return NULL;\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// RPC サーバーの開始\r
+RPC *StartRpcServer(SOCK *s, RPC_DISPATCHER *dispatch, void *param)\r
+{\r
+       RPC *r;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       r = ZeroMallocEx(sizeof(RPC), true);\r
+       r->Sock = s;\r
+       r->Param = param;\r
+       r->Lock = NewLock();\r
+       AddRef(s->ref);\r
+\r
+       r->ServerMode = true;\r
+       r->Dispatch = dispatch;\r
+\r
+       // 名前の生成\r
+       Format(r->Name, sizeof(r->Name), "RPC-%u", s->socket);\r
+\r
+       return r;\r
+}\r
+\r
+// RPC クライアントの開始\r
+RPC *StartRpcClient(SOCK *s, void *param)\r
+{\r
+       RPC *r;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       r = ZeroMalloc(sizeof(RPC));\r
+       r->Sock = s;\r
+       r->Param = param;\r
+       r->Lock = NewLock();\r
+       AddRef(s->ref);\r
+\r
+       r->ServerMode = false;\r
+\r
+       return r;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Remote.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Remote.h
new file mode 100644 (file)
index 0000000..48970f3
--- /dev/null
@@ -0,0 +1,120 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Remote.h\r
+// Remote.c のヘッダ\r
+\r
+#ifndef        REMOTE_H\r
+#define        REMOTE_H\r
+\r
+// RPC 実行関数\r
+typedef PACK *(RPC_DISPATCHER)(RPC *r, char *function_name, PACK *p);\r
+\r
+// RPC オブジェクト\r
+struct RPC\r
+{\r
+       SOCK *Sock;                                             // ソケット\r
+       bool ServerMode;                                // サーバーモード\r
+       RPC_DISPATCHER *Dispatch;               // 実行ルーチン\r
+       void *Param;                                    // パラメータ\r
+       bool ServerAdminMode;                   // サーバー管理モード\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // 管理対象 HUB 名\r
+       char Name[MAX_SIZE];                    // RPC セッション名\r
+       LOCK *Lock;                                             // ロック\r
+       bool IsVpnServer;                               // VPN Server 管理 RPC かどうか\r
+       CLIENT_OPTION VpnServerClientOption;\r
+       char VpnServerHubName[MAX_HUBNAME_LEN + 1];\r
+       UCHAR VpnServerHashedPassword[SHA1_SIZE];\r
+       char VpnServerClientName[MAX_PATH];\r
+};\r
+\r
+// 関数プロトタイプ\r
+RPC *StartRpcClient(SOCK *s, void *param);\r
+RPC *StartRpcServer(SOCK *s, RPC_DISPATCHER *dispatch, void *param);\r
+PACK *RpcCallInternal(RPC *r, PACK *p);\r
+PACK *RpcCall(RPC *r, char *function_name, PACK *p);\r
+void RpcServer(RPC *r);\r
+bool RpcRecvNextCall(RPC *r);\r
+PACK *CallRpcDispatcher(RPC *r, PACK *p);\r
+void RpcError(PACK *p, UINT err);\r
+bool RpcIsOk(PACK *p);\r
+UINT RpcGetError(PACK *p);\r
+void EndRpc(RPC *rpc);\r
+void RpcFree(RPC *rpc);\r
+\r
+#endif // REMOTE_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/SM.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/SM.c
new file mode 100644 (file)
index 0000000..d773f1a
--- /dev/null
@@ -0,0 +1,17688 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// SM.c\r
+// Win32 用 SoftEther UT-VPN Server Manager\r
+\r
+\r
+#ifdef WIN32\r
+\r
+#define        SM_C\r
+#define        CM_C\r
+#define        NM_C\r
+\r
+#define        _WIN32_WINNT            0x0502\r
+#define        WINVER                          0x0502\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+#include <wincrypt.h>\r
+#include <wininet.h>\r
+#include <shlobj.h>\r
+#include <commctrl.h>\r
+#include <Dbghelp.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+#include "CMInner.h"\r
+#include "SMInner.h"\r
+#include "NMInner.h"\r
+#include "../PenCore/resource.h"\r
+\r
+// グローバル変数\r
+static SM *sm = NULL;\r
+static bool link_create_now = false;\r
+\r
+// メッセージ設定\r
+void SmHubMsg(HWND hWnd, SM_EDIT_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_SM_MSG, SmHubMsgDlg, s);\r
+}\r
+\r
+// メッセージダイアログプロシージャ\r
+UINT SmHubMsgDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_EDIT_HUB *s = (SM_EDIT_HUB *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmHubMsgDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_TEXT:\r
+                       SmHubMsgDlgUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       SmHubMsgDlgOnOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case C_USEMSG:\r
+                       SmHubMsgDlgUpdate(hWnd, s);\r
+\r
+                       if (IsChecked(hWnd, C_USEMSG))\r
+                       {\r
+                               FocusEx(hWnd, E_TEXT);\r
+                       }\r
+                       break;\r
+               }\r
+\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// メッセージダイアログ初期化\r
+void SmHubMsgDlgInit(HWND hWnd, SM_EDIT_HUB *s)\r
+{\r
+       RPC_MSG t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsVista())\r
+       {\r
+               SetFont(hWnd, E_TEXT, GetMeiryoFont());\r
+       }\r
+       else\r
+       {\r
+               DlgFont(hWnd, E_TEXT, 11, false);\r
+       }\r
+\r
+       FormatText(hWnd, S_MSG_2, s->HubName);\r
+\r
+       LimitText(hWnd, E_TEXT, HUB_MAXMSG_LEN);\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+\r
+       if (CALL(hWnd, ScGetHubMsg(s->p->Rpc, &t)) == false)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       if (UniIsEmptyStr(t.Msg) == false)\r
+       {\r
+               SetText(hWnd, E_TEXT, t.Msg);\r
+\r
+               Check(hWnd, C_USEMSG, true);\r
+       }\r
+       else\r
+       {\r
+               Check(hWnd, C_USEMSG, false);\r
+       }\r
+\r
+       FreeRpcMsg(&t);\r
+\r
+       SmHubMsgDlgUpdate(hWnd, s);\r
+}\r
+\r
+// OK ボタン\r
+void SmHubMsgDlgOnOk(HWND hWnd, SM_EDIT_HUB *s)\r
+{\r
+       RPC_MSG t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+\r
+       if (IsChecked(hWnd, C_USEMSG) == false)\r
+       {\r
+               t.Msg = CopyUniStr(L"");\r
+       }\r
+       else\r
+       {\r
+               t.Msg = GetText(hWnd, E_TEXT);\r
+       }\r
+\r
+       if (CALL(hWnd, ScSetHubMsg(s->p->Rpc, &t)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeRpcMsg(&t);\r
+\r
+       EndDialog(hWnd, 1);\r
+}\r
+\r
+// メッセージダイアログ更新\r
+void SmHubMsgDlgUpdate(HWND hWnd, SM_EDIT_HUB *s)\r
+{\r
+       bool b = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEnable(hWnd, E_TEXT, IsChecked(hWnd, C_USEMSG));\r
+\r
+       if (IsChecked(hWnd, C_USEMSG))\r
+       {\r
+               wchar_t *s = GetText(hWnd, E_TEXT);\r
+\r
+               b = !IsEmptyUniStr(s);\r
+\r
+               Free(s);\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, b);\r
+}\r
+\r
+// VLAN ユーティリティ\r
+void SmVLan(HWND hWnd, SM_SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_SM_VLAN, SmVLanDlg, s);\r
+}\r
+\r
+// VLAN ダイアログ\r
+UINT SmVLanDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SERVER *s = (SM_SERVER *)param;\r
+       NMHDR *n;\r
+\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmVLanDlgInit(hWnd, s);\r
+\r
+               if (LvNum(hWnd, L_LIST) == 0)\r
+               {\r
+                       Disable(hWnd, L_LIST);\r
+                       SetTimer(hWnd, 1, 100, NULL);\r
+               }\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+\r
+                       MsgBoxEx(hWnd, MB_ICONINFORMATION, _UU("SM_VLAN_NOTHING"),\r
+                               s->CurrentSetting->ClientOption.Hostname);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_ENABLE:\r
+               case B_DISABLE:\r
+                       {\r
+                               UINT i = LvGetSelected(hWnd, L_LIST);\r
+                               if (i != INFINITE)\r
+                               {\r
+                                       char *name = LvGetStrA(hWnd, L_LIST, i, 0);\r
+\r
+                                       if (IsEmptyStr(name) == false)\r
+                                       {\r
+                                               RPC_TEST t;\r
+\r
+                                               Zero(&t, sizeof(t));\r
+\r
+                                               StrCpy(t.StrValue, sizeof(t.StrValue), name);\r
+                                               t.IntValue = BOOL_TO_INT(wParam == B_ENABLE);\r
+\r
+                                               if (CALL(hWnd, ScSetEnableEthVLan(s->Rpc, &t)))\r
+                                               {\r
+                                                       SmVLanDlgRefresh(hWnd, s);\r
+\r
+                                                       if (wParam == B_ENABLE)\r
+                                                       {\r
+                                                               MsgBoxEx(hWnd, MB_ICONINFORMATION,\r
+                                                                       _UU("SM_VLAN_MSG_1"),\r
+                                                                       name, name, name);\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               MsgBoxEx(hWnd, MB_ICONINFORMATION,\r
+                                                                       _UU("SM_VLAN_MSG_2"),\r
+                                                                       name);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+\r
+                                       Free(name);\r
+                               }\r
+                               break;\r
+                       }\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_LIST:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmVLanDlgUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// VLAN ダイアログ初期化\r
+void SmVLanDlgInit(HWND hWnd, SM_SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LvInit(hWnd, L_LIST);\r
+       LvInsertColumn(hWnd, L_LIST, 0, _UU("SM_VLAN_COLUMN_0"), 245);\r
+       LvInsertColumn(hWnd, L_LIST, 1, _UU("SM_VLAN_COLUMN_1"), 75);\r
+       LvInsertColumn(hWnd, L_LIST, 2, _UU("SM_VLAN_COLUMN_2"), 100);\r
+       LvInsertColumn(hWnd, L_LIST, 3, _UU("SM_VLAN_COLUMN_3"), 100);\r
+       LvInsertColumn(hWnd, L_LIST, 4, _UU("SM_VLAN_COLUMN_4"), 290);\r
+       LvInsertColumn(hWnd, L_LIST, 5, _UU("SM_VLAN_COLUMN_5"), 430);\r
+\r
+       SmVLanDlgRefresh(hWnd, s);\r
+}\r
+\r
+// VLAN ダイアログ内容更新\r
+void SmVLanDlgRefresh(HWND hWnd, SM_SERVER *s)\r
+{\r
+       LVB *b;\r
+       RPC_ENUM_ETH_VLAN t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CALL(hWnd, ScEnumEthVLan(s->Rpc, &t)) == false)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               RPC_ENUM_ETH_VLAN_ITEM *e = &t.Items[i];\r
+\r
+               if (e->Support)\r
+               {\r
+                       wchar_t tmp0[MAX_SIZE];\r
+                       wchar_t tmp1[MAX_SIZE];\r
+                       wchar_t tmp2[MAX_SIZE];\r
+                       wchar_t *tmp3;\r
+                       wchar_t tmp4[MAX_SIZE];\r
+                       wchar_t tmp5[MAX_SIZE];\r
+\r
+                       StrToUni(tmp0, sizeof(tmp0), e->DeviceName);\r
+                       StrToUni(tmp1, sizeof(tmp1), e->DriverType);\r
+                       StrToUni(tmp2, sizeof(tmp2), e->DriverName);\r
+                       tmp3 = (e->Enabled ? _UU("SM_VLAN_YES") : _UU("SM_VLAN_NO"));\r
+                       StrToUni(tmp4, sizeof(tmp4), e->Guid);\r
+                       StrToUni(tmp5, sizeof(tmp5), e->DeviceInstanceId);\r
+\r
+                       LvInsertAdd(b,\r
+                               e->Enabled ? ICO_NIC_ONLINE : ICO_NIC_OFFLINE, 0, 6,\r
+                               tmp0, tmp1, tmp2, tmp3, tmp4, tmp5);\r
+               }\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_LIST);\r
+\r
+       FreeRpcEnumEthVLan(&t);\r
+\r
+       SmVLanDlgUpdate(hWnd, s);\r
+}\r
+\r
+// VLAN ダイアログコントロール更新\r
+void SmVLanDlgUpdate(HWND hWnd, SM_SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSingleSelected(hWnd, L_LIST) == false)\r
+       {\r
+               Disable(hWnd, B_ENABLE);\r
+               Disable(hWnd, B_DISABLE);\r
+       }\r
+       else\r
+       {\r
+               UINT i = LvGetSelected(hWnd, L_LIST);\r
+               if (i != INFINITE)\r
+               {\r
+                       wchar_t *s = LvGetStr(hWnd, L_LIST, i, 3);\r
+\r
+                       if (UniStrCmpi(s, _UU("SM_VLAN_YES")) != 0)\r
+                       {\r
+                               Enable(hWnd, B_ENABLE);\r
+                               Disable(hWnd, B_DISABLE);\r
+                       }\r
+                       else\r
+                       {\r
+                               Enable(hWnd, B_DISABLE);\r
+                               Disable(hWnd, B_ENABLE);\r
+                       }\r
+\r
+                       Free(s);\r
+               }\r
+       }\r
+}\r
+\r
+// 現在の VPN Server / VPN Bridge の状態が初期状態かどうか調べる\r
+bool SmSetupIsNew(SM_SERVER *s)\r
+{\r
+       RPC *rpc;\r
+       bool is_bridge;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       bool check_hub = false;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (s->ServerAdminMode == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       rpc = s->Rpc;\r
+       is_bridge =s->Bridge;\r
+\r
+       // ローカルブリッジのサポート\r
+       if (true)\r
+       {\r
+               RPC_BRIDGE_SUPPORT t;\r
+\r
+               Zero(&t, sizeof(t));\r
+\r
+               if (ScGetBridgeSupport(rpc, &t) == ERR_NO_ERROR)\r
+               {\r
+                       if (t.IsBridgeSupportedOs == false ||\r
+                               t.IsWinPcapNeeded)\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // サーバー種類\r
+       if (is_bridge == false)\r
+       {\r
+               bool b = false;\r
+               RPC_SERVER_INFO t;\r
+\r
+               Zero(&t, sizeof(t));\r
+               if (ScGetServerInfo(rpc, &t) == ERR_NO_ERROR)\r
+               {\r
+                       if (t.ServerType != SERVER_TYPE_STANDALONE)\r
+                       {\r
+                               b = true;\r
+                       }\r
+\r
+                       FreeRpcServerInfo(&t);\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               if (b)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // ローカルブリッジ\r
+       if (true)\r
+       {\r
+               RPC_ENUM_LOCALBRIDGE t;\r
+               bool b = false;\r
+\r
+               Zero(&t, sizeof(t));\r
+               if (ScEnumLocalBridge(rpc, &t) == ERR_NO_ERROR)\r
+               {\r
+                       if (t.NumItem != 0)\r
+                       {\r
+                               b = true;\r
+                       }\r
+                       FreeRpcEnumLocalBridge(&t);\r
+               }\r
+\r
+               if (b)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // 仮想 HUB\r
+\r
+       check_hub = false;\r
+\r
+       if (is_bridge == false)\r
+       {\r
+               RPC_ENUM_HUB t;\r
+               bool b = false;\r
+\r
+               Zero(&t, sizeof(t));\r
+               if (ScEnumHub(rpc, &t) == ERR_NO_ERROR)\r
+               {\r
+                       if (t.NumHub >= 2)\r
+                       {\r
+                               b = true;\r
+                       }\r
+                       else if (t.NumHub == 1)\r
+                       {\r
+                               if (StrCmpi(t.Hubs[0].HubName, SERVER_DEFAULT_HUB_NAME) != 0)\r
+                               {\r
+                                       b = true;\r
+                               }\r
+                               else\r
+                               {\r
+                                       check_hub = true;\r
+                               }\r
+                       }\r
+\r
+                       FreeRpcEnumHub(&t);\r
+               }\r
+\r
+               if (b)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               check_hub = true;\r
+       }\r
+\r
+       // 仮想 HUB の状態\r
+       if (is_bridge == false)\r
+       {\r
+               StrCpy(hubname, sizeof(hubname), SERVER_DEFAULT_HUB_NAME);\r
+       }\r
+       else\r
+       {\r
+               StrCpy(hubname, sizeof(hubname), SERVER_DEFAULT_BRIDGE_NAME);\r
+       }\r
+\r
+       if (check_hub)\r
+       {\r
+               if (true)\r
+               {\r
+                       // 仮想 HUB 内のオブジェクト数\r
+                       RPC_HUB_STATUS t;\r
+\r
+                       Zero(&t, sizeof(t));\r
+                       StrCpy(t.HubName, sizeof(t.HubName), hubname);\r
+\r
+                       if (ScGetHubStatus(rpc, &t) == ERR_NO_ERROR)\r
+                       {\r
+                               if (t.NumSessions != 0 || t.NumAccessLists != 0 ||\r
+                                       t.NumUsers != 0 || t.NumGroups != 0 ||\r
+                                       t.NumMacTables != 0 || t.NumIpTables != 0 ||\r
+                                       t.SecureNATEnabled)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               if (true)\r
+               {\r
+                       // カスケード接続\r
+                       RPC_ENUM_LINK t;\r
+\r
+                       Zero(&t, sizeof(t));\r
+                       StrCpy(t.HubName, sizeof(t.HubName), hubname);\r
+\r
+                       if (ScEnumLink(rpc, &t) == ERR_NO_ERROR)\r
+                       {\r
+                               bool b = false;\r
+\r
+                               if (t.NumLink != 0)\r
+                               {\r
+                                       b = true;\r
+                               }\r
+\r
+                               FreeRpcEnumLink(&t);\r
+\r
+                               if (b)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               if (is_bridge == false)\r
+               {\r
+                       // 信頼する証明書一覧\r
+                       RPC_HUB_ENUM_CA t;\r
+\r
+                       Zero(&t, sizeof(t));\r
+                       StrCpy(t.HubName, sizeof(t.HubName), hubname);\r
+\r
+                       if (ScEnumCa(rpc, &t) == ERR_NO_ERROR)\r
+                       {\r
+                               bool b = false;\r
+\r
+                               if (t.NumCa != 0)\r
+                               {\r
+                                       b = true;\r
+                               }\r
+\r
+                               FreeRpcHubEnumCa(&t);\r
+\r
+                               if (b)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               if (is_bridge == false)\r
+               {\r
+                       // 無効な証明書一覧\r
+                       RPC_ENUM_CRL t;\r
+\r
+                       Zero(&t, sizeof(t));\r
+                       StrCpy(t.HubName, sizeof(t.HubName), hubname);\r
+\r
+                       if (ScEnumCrl(rpc, &t) == ERR_NO_ERROR)\r
+                       {\r
+                               bool b = false;\r
+\r
+                               if (t.NumItem != 0)\r
+                               {\r
+                                       b = true;\r
+                               }\r
+\r
+                               FreeRpcEnumCrl(&t);\r
+\r
+                               if (b)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               if (is_bridge == false)\r
+               {\r
+                       // 認証サーバーの設定\r
+                       RPC_RADIUS t;\r
+\r
+                       Zero(&t, sizeof(t));\r
+                       StrCpy(t.HubName, sizeof(t.HubName), hubname);\r
+\r
+                       if (ScGetHubRadius(rpc, &t) == ERR_NO_ERROR)\r
+                       {\r
+                               if (IsEmptyStr(t.RadiusServerName) == false)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               if (is_bridge == false)\r
+               {\r
+                       // 仮想 HUB の設定\r
+                       RPC_CREATE_HUB t;\r
+\r
+                       Zero(&t, sizeof(t));\r
+                       StrCpy(t.HubName, sizeof(t.HubName), hubname);\r
+\r
+                       if (ScGetHub(rpc, &t) == ERR_NO_ERROR)\r
+                       {\r
+                               if (t.HubOption.NoEnum || t.HubOption.MaxSession != 0 ||\r
+                                       t.Online == false)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               if (is_bridge == false)\r
+               {\r
+                       // IP アクセス制御リスト\r
+                       RPC_AC_LIST t;\r
+\r
+                       Zero(&t, sizeof(t));\r
+                       StrCpy(t.HubName, sizeof(t.HubName), hubname);\r
+\r
+                       if (ScGetAcList(rpc, &t) == ERR_NO_ERROR)\r
+                       {\r
+                               bool b = false;\r
+                               if (LIST_NUM(t.o) != 0)\r
+                               {\r
+                                       b = true;\r
+                               }\r
+                               FreeRpcAcList(&t);\r
+\r
+                               if (b)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               if (is_bridge == false)\r
+               {\r
+                       // AO\r
+                       RPC_ADMIN_OPTION t;\r
+\r
+                       Zero(&t, sizeof(t));\r
+                       StrCpy(t.HubName, sizeof(t.HubName), hubname);\r
+\r
+                       if (ScGetHubAdminOptions(rpc, &t) == ERR_NO_ERROR)\r
+                       {\r
+                               bool b = false;\r
+                               UINT i;\r
+\r
+                               for (i = 0;i < t.NumItem;i++)\r
+                               {\r
+                                       if (t.Items[i].Value != 0)\r
+                                       {\r
+                                               b = true;\r
+                                       }\r
+                               }\r
+\r
+                               FreeRpcAdminOption(&t);\r
+\r
+                               if (b)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // 仮想レイヤ 3 スイッチ\r
+       if (is_bridge == false)\r
+       {\r
+               RPC_ENUM_L3SW t;\r
+               bool b = false;\r
+\r
+               Zero(&t, sizeof(t));\r
+               if (ScEnumL3Switch(rpc, &t) == ERR_NO_ERROR)\r
+               {\r
+                       if (t.NumItem != 0)\r
+                       {\r
+                               b = true;\r
+                       }\r
+\r
+                       FreeRpcEnumL3Sw(&t);\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               if (b)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// セットアップ手順ダイアログ初期化\r
+void SmSetupStepDlgInit(HWND hWnd, SM_SETUP *s)\r
+{\r
+       bool b;\r
+       RPC_ENUM_ETH t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_SETUP);\r
+\r
+       DlgFont(hWnd, S_1_1, 0, true);\r
+       DlgFont(hWnd, S_2_1, 0, true);\r
+       DlgFont(hWnd, S_3_1, 0, true);\r
+\r
+       b = false;\r
+       if (s->UseRemote)\r
+       {\r
+               b = true;\r
+       }\r
+       if (s->UseSite && s->UseSiteEdge == false)\r
+       {\r
+               b = true;\r
+       }\r
+\r
+       SetEnable(hWnd, S_1_1, b);\r
+       SetEnable(hWnd, S_1_2, b);\r
+       SetEnable(hWnd, B_USER, b);\r
+\r
+       b = false;\r
+       if (s->UseSiteEdge)\r
+       {\r
+               b = true;\r
+       }\r
+\r
+       SetEnable(hWnd, S_2_1, b);\r
+       SetEnable(hWnd, S_2_2, b);\r
+       SetEnable(hWnd, B_CASCADE, b);\r
+\r
+       CbReset(hWnd, C_DEVICE);\r
+       CbSetHeight(hWnd, C_DEVICE, 18);\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       CbAddStr(hWnd, C_DEVICE, _UU("SM_SETUP_SELECT"), 0);\r
+\r
+       if (CALL(hWnd, ScEnumEthernet(s->Rpc, &t)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               wchar_t tmp[MAX_PATH];\r
+               RPC_ENUM_ETH_ITEM *e = &t.Items[i];\r
+\r
+               StrToUni(tmp, sizeof(tmp), e->DeviceName);\r
+\r
+               CbAddStr(hWnd, C_DEVICE, tmp, 1);\r
+       }\r
+\r
+       FreeRpcEnumEth(&t);\r
+\r
+       s->Flag1 = false;\r
+       s->Flag2 = false;\r
+}\r
+\r
+// 閉じる\r
+void SmSetupOnClose(HWND hWnd, SM_SETUP *s)\r
+{\r
+       wchar_t *tmp;\r
+       char name[MAX_PATH];\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tmp = CbGetStr(hWnd, C_DEVICE);\r
+\r
+       if (tmp != NULL)\r
+       {\r
+               UniToStr(name, sizeof(name), tmp);\r
+\r
+               if (CbGetSelect(hWnd, C_DEVICE) != 0)\r
+               {\r
+                       RPC_LOCALBRIDGE t;\r
+\r
+                       Zero(&t, sizeof(t));\r
+                       t.Active = true;\r
+                       StrCpy(t.DeviceName, sizeof(t.DeviceName), name);\r
+                       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+                       t.Online = true;\r
+                       t.TapMode = false;\r
+\r
+                       if (CALL(hWnd, ScAddLocalBridge(s->Rpc, &t)) == false)\r
+                       {\r
+                               Free(tmp);\r
+                               return;\r
+                       }\r
+               }\r
+               Free(tmp);\r
+       }\r
+\r
+       EndDialog(hWnd, 0);\r
+}\r
+\r
+// セットアップ手順ダイアログプロシージャ\r
+UINT SmSetupStepDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SETUP *s = (SM_SETUP *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmSetupStepDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_USER:\r
+                       // ユーザー作成\r
+                       if (true)\r
+                       {\r
+                               SM_HUB h;\r
+\r
+                               Zero(&h, sizeof(h));\r
+                               h.HubName = s->HubName;\r
+                               h.p = s->s;\r
+                               h.Rpc = s->Rpc;\r
+\r
+                               SmUserListDlgEx(hWnd, &h, NULL, s->Flag1 ? false : true);\r
+\r
+                               s->Flag1 = true;\r
+                       }\r
+                       break;\r
+\r
+               case B_CASCADE:\r
+                       // カスケード接続作成\r
+                       if (true)\r
+                       {\r
+                               SM_HUB h;\r
+\r
+                               Zero(&h, sizeof(h));\r
+                               h.HubName = s->HubName;\r
+                               h.p = s->s;\r
+                               h.Rpc = s->Rpc;\r
+\r
+                               SmLinkDlgEx(hWnd, &h, s->Flag2 ? false : true);\r
+                               s->Flag2 = true;\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // 閉じるボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               // 終了\r
+               SmSetupOnClose(hWnd, s);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// セットアップ手順ダイアログ\r
+void SmSetupStep(HWND hWnd, SM_SETUP *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_SM_SETUP_STEP, SmSetupStepDlg, s);\r
+}\r
+\r
+// セットアップによる初期化を行う\r
+bool SmSetupInit(HWND hWnd, SM_SETUP *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (s->IsBridge == false)\r
+       {\r
+               if (SmSetupDeleteAllLayer3(hWnd, s) == false)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               if (SmSetupDeleteAllHub(hWnd, s) == false)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (SmSetupDeleteAllObjectInBridgeHub(hWnd, s) == false)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       if (SmSetupDeleteAllLocalBridge(hWnd, s) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (s->IsBridge == false)\r
+       {\r
+               // 仮想 HUB の作成\r
+               RPC_CREATE_HUB t;\r
+               char *password = "";\r
+\r
+               Zero(&t, sizeof(t));\r
+               Hash(t.HashedPassword, password, StrLen(password), true);\r
+               HashPassword(t.SecurePassword, ADMINISTRATOR_USERNAME, password);\r
+               StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+               t.HubType = HUB_TYPE_STANDALONE;\r
+               t.Online = true;\r
+\r
+               if (CALL(hWnd, ScCreateHub(s->Rpc, &t)) == false)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// すべての VPN Bridge 用の仮想 HUB 内のオブジェクトを削除\r
+bool SmSetupDeleteAllObjectInBridgeHub(HWND hWnd, SM_SETUP *s)\r
+{\r
+       char *hubname = SERVER_DEFAULT_BRIDGE_NAME;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (true)\r
+       {\r
+               RPC_ENUM_LINK t;\r
+               UINT i;\r
+\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.HubName, sizeof(t.HubName), hubname);\r
+\r
+               if (CALL(hWnd, ScEnumLink(s->Rpc, &t)) == false)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               for (i = 0;i < t.NumLink;i++)\r
+               {\r
+                       RPC_ENUM_LINK_ITEM *e = &t.Links[i];\r
+                       RPC_LINK a;\r
+\r
+                       Zero(&a, sizeof(a));\r
+                       StrCpy(a.HubName, sizeof(a.HubName), hubname);\r
+                       UniStrCpy(a.AccountName, sizeof(a.AccountName), e->AccountName);\r
+\r
+                       if (CALL(hWnd, ScDeleteLink(s->Rpc, &a)) == false)\r
+                       {\r
+                               FreeRpcEnumLink(&t);\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               FreeRpcEnumLink(&t);\r
+       }\r
+\r
+       if (true)\r
+       {\r
+               RPC_HUB t;\r
+\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.HubName, sizeof(t.HubName), hubname);\r
+\r
+               if (CALL(hWnd, ScDisableSecureNAT(s->Rpc, &t)) == false)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// すべての仮想レイヤ 3 スイッチの削除\r
+bool SmSetupDeleteAllLayer3(HWND hWnd, SM_SETUP *s)\r
+{\r
+       RPC_ENUM_L3SW t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if(CALL(hWnd, ScEnumL3Switch(s->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               RPC_ENUM_L3SW_ITEM *e = &t.Items[i];\r
+               RPC_L3SW tt;\r
+\r
+               Zero(&tt, sizeof(tt));\r
+               StrCpy(tt.Name, sizeof(tt.Name), e->Name);\r
+\r
+               if (CALL(hWnd, ScDelL3Switch(s->Rpc, &tt)) == false)\r
+               {\r
+                       FreeRpcEnumL3Sw(&t);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       FreeRpcEnumL3Sw(&t);\r
+\r
+       return true;\r
+}\r
+\r
+// すべてのローカルブリッジの削除\r
+bool SmSetupDeleteAllLocalBridge(HWND hWnd, SM_SETUP *s)\r
+{\r
+       RPC_ENUM_LOCALBRIDGE t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CALL(hWnd, ScEnumLocalBridge(s->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               RPC_LOCALBRIDGE *e = &t.Items[i];\r
+\r
+               if (CALL(hWnd, ScDeleteLocalBridge(s->Rpc, e)) == false)\r
+               {\r
+                       FreeRpcEnumLocalBridge(&t);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       FreeRpcEnumLocalBridge(&t);\r
+\r
+       return true;\r
+}\r
+\r
+// すべての仮想 HUB の削除\r
+bool SmSetupDeleteAllHub(HWND hWnd, SM_SETUP *s)\r
+{\r
+       RPC_ENUM_HUB t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CALL(hWnd, ScEnumHub(s->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < t.NumHub;i++)\r
+       {\r
+               RPC_ENUM_HUB_ITEM *e = &t.Hubs[i];\r
+               RPC_DELETE_HUB tt;\r
+\r
+               Zero(&tt, sizeof(tt));\r
+               StrCpy(tt.HubName, sizeof(tt.HubName), e->HubName);\r
+\r
+               if (CALL(hWnd, ScDeleteHub(s->Rpc, &tt)) == false)\r
+               {\r
+                       FreeRpcEnumHub(&t);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       FreeRpcEnumHub(&t);\r
+\r
+       return true;\r
+}\r
+\r
+// 仮想 HUB のコントロール更新\r
+void SmSetupHubDlgUpdate(HWND hWnd, SM_SETUP *s)\r
+{\r
+       bool ok = true;\r
+       char tmp[MAX_HUBNAME_LEN + 1];\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetTxtA(hWnd, E_HUBNAME, tmp, sizeof(tmp));\r
+\r
+       if (IsEmptyStr(tmp) || IsSafeStr(tmp) == false)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// 仮想 HUB 作成ダイアログ\r
+UINT SmSetupHubDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SETUP *s = (SM_SETUP *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetTextA(hWnd, E_HUBNAME, "VPN");\r
+               FocusEx(hWnd, E_HUBNAME);\r
+               SmSetupHubDlgUpdate(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               SmSetupHubDlgUpdate(hWnd, s);\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       GetTxtA(hWnd, E_HUBNAME, s->HubName, sizeof(s->HubName));\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// セットアップダイアログの [次へ] ボタン\r
+void SmSetupDlgOnOk(HWND hWnd, SM_SETUP *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsgBox(hWnd, MB_YESNO | MB_ICONEXCLAMATION, _UU("SM_SETUP_WARNING")) == IDNO)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s->UseRemote = IsChecked(hWnd, C_REMOTE);\r
+       s->UseSite = IsChecked(hWnd, C_SITE);\r
+       s->UseSiteEdge = IsChecked(hWnd, C_EDGE);\r
+\r
+       if (s->IsBridge)\r
+       {\r
+               StrCpy(s->HubName, sizeof(s->HubName), SERVER_DEFAULT_BRIDGE_NAME);\r
+       }\r
+       else\r
+       {\r
+               if (Dialog(hWnd, D_SM_SETUP_HUB, SmSetupHubDlg, s) == false)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       // 初期化 (既存オブジェクトの抹消)\r
+       if (SmSetupInit(hWnd, s) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 手順の実行\r
+       SmSetupStep(hWnd, s);\r
+\r
+       // ダイアログを閉じる\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// セットアップダイアログ初期化\r
+void SmSetupDlgInit(HWND hWnd, SM_SETUP *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_SETUP);\r
+       DlgFont(hWnd, S_TITLE, 14, true);\r
+       DlgFont(hWnd, C_REMOTE, 0, true);\r
+       DlgFont(hWnd, C_SITE, 0, true);\r
+       DlgFont(hWnd, C_OTHER, 0, true);\r
+\r
+       if (s->IsBridge)\r
+       {\r
+               SetText(hWnd, B_BOLD, _UU("SM_SETUP_BRIDGE_ONLY"));\r
+               SetText(hWnd, C_EDGE, _UU("SM_SETUP_BRIDGE_EDGE"));\r
+\r
+               Check(hWnd, C_SITE, true);\r
+               Check(hWnd, C_EDGE, true);\r
+               Focus(hWnd, C_SITE);\r
+       }\r
+\r
+       SmSetupDlgUpdate(hWnd, s);\r
+}\r
+\r
+// セットアップダイアログ更新\r
+void SmSetupDlgUpdate(HWND hWnd, SM_SETUP *s)\r
+{\r
+       bool enable_remote = true;\r
+       bool enable_site = true;\r
+       bool enable_site_center = true;\r
+       bool enable_detail = true;\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->IsBridge)\r
+       {\r
+               enable_remote = false;\r
+               enable_site_center = false;\r
+               enable_detail = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, C_OTHER))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       SetEnable(hWnd, C_REMOTE, enable_remote && IsChecked(hWnd, C_OTHER) == false);\r
+       SetEnable(hWnd, S_REMOTE_1, enable_remote && IsChecked(hWnd, C_OTHER) == false);\r
+\r
+       SetEnable(hWnd, C_SITE, enable_site && IsChecked(hWnd, C_OTHER) == false);\r
+       SetEnable(hWnd, S_SITE_1, enable_site && IsChecked(hWnd, C_OTHER) == false);\r
+       SetEnable(hWnd, S_SITE_2, enable_site && IsChecked(hWnd, C_SITE) && IsChecked(hWnd, C_OTHER) == false);\r
+       SetEnable(hWnd, C_CENTER, enable_site && enable_site_center && IsChecked(hWnd, C_SITE) && IsChecked(hWnd, C_OTHER) == false);\r
+       SetEnable(hWnd, C_EDGE, enable_site && IsChecked(hWnd, C_SITE) && IsChecked(hWnd, C_OTHER) == false);\r
+\r
+       SetEnable(hWnd, C_OTHER, enable_detail);\r
+       SetEnable(hWnd, S_OTHER, enable_detail);\r
+\r
+       if (IsChecked(hWnd, C_REMOTE) == false && IsChecked(hWnd, C_SITE) == false)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, C_SITE))\r
+       {\r
+               if (IsChecked(hWnd, C_CENTER) == false && IsChecked(hWnd, C_EDGE) == false)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+\r
+       SetText(hWnd, S_INFO,\r
+               IsChecked(hWnd, C_OTHER) ? _UU("SM_SETUP_INFO_2") : _UU("SM_SETUP_INFO_1"));\r
+}\r
+\r
+// セットアップダイアログ\r
+UINT SmSetupDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SETUP *s = (SM_SETUP *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmSetupDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               SmSetupDlgUpdate(hWnd, s);\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       SmSetupDlgOnOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// セットアップ\r
+bool SmSetup(HWND hWnd, SM_SERVER *s)\r
+{\r
+       SM_SETUP ss;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&ss, sizeof(ss));\r
+       ss.s = s;\r
+       ss.IsBridge = ss.s->Bridge;\r
+       ss.Rpc = s->Rpc;\r
+\r
+       if (Dialog(hWnd, D_SM_SETUP, SmSetupDlg, &ss) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ライセンス登録処理\r
+void SmLicenseAddDlgOnOk(HWND hWnd, SM_SERVER *s)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SmLicenseAddDlgGetText(hWnd, tmp, sizeof(tmp));\r
+\r
+       if (true)\r
+       {\r
+               RPC_TEST t;\r
+\r
+               Disable(hWnd, IDOK);\r
+               Disable(hWnd, IDCANCEL);\r
+\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.StrValue, sizeof(t.StrValue), tmp);\r
+\r
+               if (CALL(hWnd, ScAddLicenseKey(s->Rpc, &t)) == false)\r
+               {\r
+                       FocusEx(hWnd, B_KEY6);\r
+               }\r
+               else\r
+               {\r
+                       EndDialog(hWnd, true);\r
+               }\r
+\r
+               Enable(hWnd, IDOK);\r
+               Enable(hWnd, IDCANCEL);\r
+       }\r
+}\r
+\r
+// テキスト入力のシフト処理\r
+void SmLicenseAddDlgShiftTextItem(HWND hWnd, UINT id1, UINT id2, UINT *next_focus)\r
+{\r
+       char *s;\r
+       // 引数チェック\r
+       if (hWnd == NULL || next_focus == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = GetTextA(hWnd, id1);\r
+       if (StrLen(s) >= 6)\r
+       {\r
+               char *s2 = CopyStr(s);\r
+               char tmp[MAX_SIZE];\r
+               s2[6] = 0;\r
+               SetTextA(hWnd, id1, s2);\r
+               Free(s2);\r
+\r
+               if (id2 != 0)\r
+               {\r
+                       GetTxtA(hWnd, id2, tmp, sizeof(tmp));\r
+\r
+                       StrCat(tmp, sizeof(tmp), s + 6);\r
+                       ReplaceStrEx(tmp, sizeof(tmp), tmp, "-", "", false);\r
+\r
+                       SetTextA(hWnd, id2, tmp);\r
+\r
+                       *next_focus = id2;\r
+               }\r
+               else\r
+               {\r
+                       *next_focus = IDOK;\r
+               }\r
+       }\r
+\r
+       Free(s);\r
+}\r
+\r
+// 入力データをテキスト化\r
+void SmLicenseAddDlgGetText(HWND hWnd, char *str, UINT size)\r
+{\r
+       char *k1, *k2, *k3, *k4, *k5, *k6;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       k1 = GetTextA(hWnd, B_KEY1);\r
+       k2 = GetTextA(hWnd, B_KEY2);\r
+       k3 = GetTextA(hWnd, B_KEY3);\r
+       k4 = GetTextA(hWnd, B_KEY4);\r
+       k5 = GetTextA(hWnd, B_KEY5);\r
+       k6 = GetTextA(hWnd, B_KEY6);\r
+\r
+       Format(str, size, "%s-%s-%s-%s-%s-%s", k1, k2, k3, k4, k5, k6);\r
+\r
+       Free(k1);\r
+       Free(k2);\r
+       Free(k3);\r
+       Free(k4);\r
+       Free(k5);\r
+       Free(k6);\r
+}\r
+\r
+// ライセンス追加ダイアログ更新\r
+void SmLicenseAddDlgUpdate(HWND hWnd, SM_SERVER *s)\r
+{\r
+       UINT next_focus = 0;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (s == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SmLicenseAddDlgShiftTextItem(hWnd, B_KEY1, B_KEY2, &next_focus);\r
+       SmLicenseAddDlgShiftTextItem(hWnd, B_KEY2, B_KEY3, &next_focus);\r
+       SmLicenseAddDlgShiftTextItem(hWnd, B_KEY3, B_KEY4, &next_focus);\r
+       SmLicenseAddDlgShiftTextItem(hWnd, B_KEY4, B_KEY5, &next_focus);\r
+       SmLicenseAddDlgShiftTextItem(hWnd, B_KEY5, B_KEY6, &next_focus);\r
+       SmLicenseAddDlgShiftTextItem(hWnd, B_KEY6, 0, &next_focus);\r
+\r
+       if ((IsFocus(hWnd, B_KEY1) && GetTextLen(hWnd, B_KEY1, true) <= 5) ||\r
+               (IsFocus(hWnd, B_KEY2) && GetTextLen(hWnd, B_KEY2, true) <= 5) ||\r
+               (IsFocus(hWnd, B_KEY3) && GetTextLen(hWnd, B_KEY3, true) <= 5) ||\r
+               (IsFocus(hWnd, B_KEY4) && GetTextLen(hWnd, B_KEY4, true) <= 5) ||\r
+               (IsFocus(hWnd, B_KEY5) && GetTextLen(hWnd, B_KEY5, true) <= 5) ||\r
+               (IsFocus(hWnd, B_KEY6) && GetTextLen(hWnd, B_KEY6, true) <= 5))\r
+       {\r
+               next_focus = 0;\r
+       }\r
+\r
+       if (next_focus != 0)\r
+       {\r
+               Focus(hWnd, next_focus);\r
+       }\r
+\r
+       SmLicenseAddDlgGetText(hWnd, tmp, sizeof(tmp));\r
+\r
+       SetEnable(hWnd, IDOK, true);\r
+}\r
+\r
+// ライセンス追加ダイアログ初期化\r
+void SmLicenseAddDlgInit(HWND hWnd, SM_SERVER *s)\r
+{\r
+       HFONT h;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       h = GetFont("Arial", 10, true, false, false, false);\r
+       SetFont(hWnd, B_KEY1, h);\r
+       SetFont(hWnd, B_KEY2, h);\r
+       SetFont(hWnd, B_KEY3, h);\r
+       SetFont(hWnd, B_KEY4, h);\r
+       SetFont(hWnd, B_KEY5, h);\r
+       SetFont(hWnd, B_KEY6, h);\r
+\r
+       DlgFont(hWnd, S_INFO, 10, true);\r
+\r
+       SmLicenseAddDlgUpdate(hWnd, s);\r
+}\r
+\r
+// ライセンスの追加ダイアログ\r
+UINT SmLicenseAddDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SERVER *s = (SM_SERVER *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmLicenseAddDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case B_KEY1:\r
+               case B_KEY2:\r
+               case B_KEY3:\r
+               case B_KEY4:\r
+               case B_KEY5:\r
+               case B_KEY6:\r
+                       switch (HIWORD(wParam))\r
+                       {\r
+                       case EN_CHANGE:\r
+                               SmLicenseAddDlgUpdate(hWnd, s);\r
+\r
+                               switch (LOWORD(wParam))\r
+                               {\r
+                               case B_KEY2:\r
+                                       if (GetTextLen(hWnd, B_KEY2, true) == 0)\r
+                                       {\r
+                                               FocusEx(hWnd, B_KEY1);\r
+                                       }\r
+                                       break;\r
+                               case B_KEY3:\r
+                                       if (GetTextLen(hWnd, B_KEY3, true) == 0)\r
+                                       {\r
+                                               FocusEx(hWnd, B_KEY2);\r
+                                       }\r
+                                       break;\r
+                               case B_KEY4:\r
+                                       if (GetTextLen(hWnd, B_KEY4, true) == 0)\r
+                                       {\r
+                                               FocusEx(hWnd, B_KEY3);\r
+                                       }\r
+                                       break;\r
+                               case B_KEY5:\r
+                                       if (GetTextLen(hWnd, B_KEY5, true) == 0)\r
+                                       {\r
+                                               FocusEx(hWnd, B_KEY4);\r
+                                       }\r
+                                       break;\r
+                               case B_KEY6:\r
+                                       if (GetTextLen(hWnd, B_KEY6, true) == 0)\r
+                                       {\r
+                                               FocusEx(hWnd, B_KEY5);\r
+                                       }\r
+                                       break;\r
+                               }\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       SmLicenseAddDlgOnOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ライセンスの追加\r
+bool SmLicenseAdd(HWND hWnd, SM_SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return Dialog(hWnd, D_SM_LICENSE_ADD, SmLicenseAddDlg, s);\r
+}\r
+\r
+// ライセンスダイアログ初期化\r
+void SmLicenseDlgInit(HWND hWnd, SM_SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_CERT);\r
+\r
+       DlgFont(hWnd, S_BOLD, 0, true);\r
+       DlgFont(hWnd, S_BOLD2, 0, true);\r
+\r
+       LvInit(hWnd, L_LIST);\r
+       LvSetStyle(hWnd, L_LIST, LVS_EX_GRIDLINES);\r
+       LvInsertColumn(hWnd, L_LIST, 0, _UU("SM_LICENSE_COLUMN_1"), 50);\r
+       LvInsertColumn(hWnd, L_LIST, 1, _UU("SM_LICENSE_COLUMN_2"), 100);\r
+       LvInsertColumn(hWnd, L_LIST, 2, _UU("SM_LICENSE_COLUMN_3"), 290);\r
+       LvInsertColumn(hWnd, L_LIST, 3, _UU("SM_LICENSE_COLUMN_4"), 150);\r
+       LvInsertColumn(hWnd, L_LIST, 4, _UU("SM_LICENSE_COLUMN_5"), 120);\r
+       LvInsertColumn(hWnd, L_LIST, 5, _UU("SM_LICENSE_COLUMN_6"), 250);\r
+       LvInsertColumn(hWnd, L_LIST, 6, _UU("SM_LICENSE_COLUMN_7"), 100);\r
+       LvInsertColumn(hWnd, L_LIST, 7, _UU("SM_LICENSE_COLUMN_8"), 100);\r
+       LvInsertColumn(hWnd, L_LIST, 8, _UU("SM_LICENSE_COLUMN_9"), 100);\r
+\r
+       LvInitEx(hWnd, L_STATUS, true);\r
+       LvInsertColumn(hWnd, L_STATUS, 0, _UU("SM_STATUS_COLUMN_1"), 100);\r
+       LvInsertColumn(hWnd, L_STATUS, 1, _UU("SM_STATUS_COLUMN_2"), 100);\r
+\r
+       SmLicenseDlgRefresh(hWnd, s);\r
+}\r
+\r
+// ライセンスダイアログ更新\r
+void SmLicenseDlgRefresh(HWND hWnd, SM_SERVER *s)\r
+{\r
+       RPC_ENUM_LICENSE_KEY t;\r
+       RPC_LICENSE_STATUS st;\r
+       UINT i;\r
+       wchar_t tmp[MAX_SIZE];\r
+       LVB *b;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       if (CALL(hWnd, ScEnumLicenseKey(s->Rpc, &t)) == false)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               wchar_t tmp1[32], tmp2[LICENSE_KEYSTR_LEN + 1], tmp3[LICENSE_MAX_PRODUCT_NAME_LEN + 1],\r
+                       *tmp4, tmp5[128], tmp6[LICENSE_LICENSEID_STR_LEN + 1], tmp7[64],\r
+                       tmp8[64], tmp9[64];\r
+               RPC_ENUM_LICENSE_KEY_ITEM *e = &t.Items[i];\r
+\r
+               UniToStru(tmp1, e->Id);\r
+               StrToUni(tmp2, sizeof(tmp2), e->LicenseKey);\r
+               StrToUni(tmp3, sizeof(tmp3), e->LicenseName);\r
+               tmp4 = LiGetLicenseStatusStr(e->Status);\r
+               if (e->Expires == 0)\r
+               {\r
+                       UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_LICENSE_NO_EXPIRES"));\r
+               }\r
+               else\r
+               {\r
+                       GetDateStrEx64(tmp5, sizeof(tmp5), e->Expires, NULL);\r
+               }\r
+               StrToUni(tmp6, sizeof(tmp6), e->LicenseId);\r
+               UniToStru(tmp7, e->ProductId);\r
+               UniFormat(tmp8, sizeof(tmp8), L"%I64u", e->SystemId);\r
+               UniToStru(tmp9, e->SerialId);\r
+\r
+               LvInsertAdd(b,\r
+                       e->Status == LICENSE_STATUS_OK ? ICO_PASS : ICO_DISCARD,\r
+                       (void *)e->Id, 9,\r
+                       tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_LIST);\r
+\r
+       FreeRpcEnumLicenseKey(&t);\r
+\r
+       Zero(&st, sizeof(st));\r
+\r
+       if (CALL(hWnd, ScGetLicenseStatus(s->Rpc, &st)) == false)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       if (st.EditionId == LICENSE_EDITION_VPN3_NO_LICENSE)\r
+       {\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_NO_LICENSE_COLUMN"), _UU("SM_NO_LICENSE"));\r
+       }\r
+       else\r
+       {\r
+               // 製品エディション名\r
+               StrToUni(tmp, sizeof(tmp), st.EditionStr);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_STATUS_EDITION"), tmp);\r
+\r
+               // リリース日付\r
+               if (st.ReleaseDate != 0)\r
+               {\r
+                       GetDateStrEx64(tmp, sizeof(tmp), st.ReleaseDate, NULL);\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_STATUS_RELEASE"), tmp);\r
+               }\r
+\r
+               // 現在のシステム ID\r
+               UniFormat(tmp, sizeof(tmp), L"%I64u", st.SystemId);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_STATUS_SYSTEM_ID"), tmp);\r
+\r
+               // 現在の製品ライセンスの有効期限\r
+               if (st.SystemExpires == 0)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_NO_EXPIRES"));\r
+               }\r
+               else\r
+               {\r
+                       GetDateStrEx64(tmp, sizeof(tmp), st.SystemExpires, NULL);\r
+               }\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_STATUS_EXPIRES"), tmp);\r
+\r
+               // サブスクリプション (サポート) 契約\r
+               if (st.NeedSubscription == false)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_STATUS_SUBSCRIPTION_NONEED"));\r
+               }\r
+               else\r
+               {\r
+                       if (st.SubscriptionExpires == 0)\r
+                       {\r
+                               UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_STATUS_SUBSCRIPTION_NONE"));\r
+                       }\r
+                       else\r
+                       {\r
+                               wchar_t dtstr[MAX_PATH];\r
+\r
+                               GetDateStrEx64(dtstr, sizeof(dtstr), st.SubscriptionExpires, NULL);\r
+\r
+                               UniFormat(tmp, sizeof(tmp),\r
+                                       st.IsSubscriptionExpired ? _UU("SM_LICENSE_STATUS_SUBSCRIPTION_EXPIRED") :  _UU("SM_LICENSE_STATUS_SUBSCRIPTION_VALID"),\r
+                                       dtstr);\r
+                       }\r
+               }\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_STATUS_SUBSCRIPTION"), tmp);\r
+\r
+               if (st.NeedSubscription == false && st.SubscriptionExpires != 0)\r
+               {\r
+                       wchar_t dtstr[MAX_PATH];\r
+\r
+                       GetDateStrEx64(dtstr, sizeof(dtstr), st.SubscriptionExpires, NULL);\r
+\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_STATUS_SUBSCRIPTION_BUILD_STR"), tmp);\r
+               }\r
+\r
+               if (st.NeedSubscription && st.SubscriptionExpires != 0)\r
+               {\r
+                       wchar_t dtstr[MAX_PATH];\r
+\r
+                       GetDateStrEx64(dtstr, sizeof(dtstr), st.SubscriptionExpires, NULL);\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("SM_LICENSE_STATUS_SUBSCRIPTION_BUILD_STR"), dtstr);\r
+\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_STATUS_SUBSCRIPTION_BUILD"), tmp);\r
+               }\r
+\r
+               if (GetCapsBool(s->CapsList, "b_vpn3"))\r
+               {\r
+                       // ユーザー作成可能数\r
+                       if (st.NumUserCreationLicense == INFINITE)\r
+                       {\r
+                               UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_INFINITE"));\r
+                       }\r
+                       else\r
+                       {\r
+                               UniToStru(tmp, st.NumUserCreationLicense);\r
+                       }\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_NUM_USER"), tmp);\r
+               }\r
+\r
+               // クライアント同時接続可能数\r
+               if (st.NumClientConnectLicense == INFINITE)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_INFINITE"));\r
+               }\r
+               else\r
+               {\r
+                       UniToStru(tmp, st.NumClientConnectLicense);\r
+               }\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_NUM_CLIENT"), tmp);\r
+\r
+               // ブリッジ同時接続可能数\r
+               if (st.NumBridgeConnectLicense == INFINITE)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_INFINITE"));\r
+               }\r
+               else\r
+               {\r
+                       UniToStru(tmp, st.NumBridgeConnectLicense);\r
+               }\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_NUM_BRIDGE"), tmp);\r
+\r
+               // エンタープライズ機能の利用可否\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_STATUS_ENTERPRISE"),\r
+                       st.AllowEnterpriseFunction ? _UU("SM_LICENSE_STATUS_ENTERPRISE_YES") : _UU("SM_LICENSE_STATUS_ENTERPRISE_NO"));\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+       if (LvNum(hWnd, L_STATUS) >= 1)\r
+       {\r
+               LvAutoSize(hWnd, L_STATUS);\r
+       }\r
+\r
+       SmLicenseDlgUpdate(hWnd, s);\r
+}\r
+\r
+// ライセンスダイアログコントロール更新\r
+void SmLicenseDlgUpdate(HWND hWnd, SM_SERVER *s)\r
+{\r
+       bool b = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = LvIsSingleSelected(hWnd, L_LIST);\r
+\r
+       SetEnable(hWnd, B_DEL, b);\r
+       SetEnable(hWnd, IDOK, b);\r
+}\r
+\r
+// ライセンスダイアログ\r
+UINT SmLicenseDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SERVER *s = (SM_SERVER *)param;\r
+       NMHDR *n;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmLicenseDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->code)\r
+               {\r
+               case LVN_ITEMCHANGED:\r
+                       switch (n->idFrom)\r
+                       {\r
+                       case L_LIST:\r
+                       case L_STATUS:\r
+                               SmLicenseDlgUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       if (IsEnable(hWnd, IDOK))\r
+                       {\r
+                               UINT i = LvGetSelected(hWnd, L_LIST);\r
+\r
+                               if (i != INFINITE)\r
+                               {\r
+                                       char *s = LvGetStrA(hWnd, L_LIST, i, 1);\r
+                                       char tmp[MAX_SIZE];\r
+\r
+                                       Format(tmp, sizeof(tmp), _SS("LICENSE_SUPPORT_URL"), s);\r
+                                       ShellExecute(hWnd, "open", tmp, NULL, NULL, SW_SHOW);\r
+\r
+                                       Free(s);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_OBTAIN:\r
+                       ShellExecute(hWnd, "open", _SS("LICENSE_INFO_URL"), NULL, NULL, SW_SHOW);\r
+                       break;\r
+\r
+               case B_ADD:\r
+                       if (SmLicenseAdd(hWnd, s))\r
+                       {\r
+                               SmLicenseDlgRefresh(hWnd, s);\r
+                       }\r
+                       break;\r
+\r
+               case B_DEL:\r
+                       if (IsEnable(hWnd, B_DEL))\r
+                       {\r
+                               UINT id = (UINT)LvGetParam(hWnd, L_LIST, LvGetSelected(hWnd, L_LIST));\r
+\r
+                               if (id != 0)\r
+                               {\r
+                                       if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("SM_LICENSE_DELETE_MSG")) == IDYES)\r
+                                       {\r
+                                               RPC_TEST t;\r
+\r
+                                               Zero(&t, sizeof(t));\r
+                                               t.IntValue = id;\r
+\r
+                                               if (CALL(hWnd, ScDelLicenseKey(s->Rpc, &t)))\r
+                                               {\r
+                                                       SmLicenseDlgRefresh(hWnd, s);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_LIST);\r
+\r
+       return 0;\r
+}\r
+\r
+// ライセンスの追加と削除\r
+void SmLicense(HWND hWnd, SM_SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_SM_LICENSE, SmLicenseDlg, s);\r
+\r
+       FreeCapsList(s->CapsList);\r
+       s->CapsList = ScGetCapsEx(s->Rpc);\r
+}\r
+\r
+// ログ保存プロシージャ\r
+UINT SmSaveLogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_READ_LOG_FILE *p = (SM_READ_LOG_FILE *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               FormatText(hWnd, S_INFO, p->filepath);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+               case B_SAVE:\r
+                       if (p->Buffer != NULL)\r
+                       {\r
+                               char filename[MAX_PATH];\r
+\r
+                               Format(filename, sizeof(filename), "%s_%s", p->server_name, p->filepath);\r
+                               ConvertSafeFileName(filename, sizeof(filename), filename);\r
+\r
+                               if (wParam == IDOK)\r
+                               {\r
+                                       // エディタで開く\r
+                                       char fullpath[MAX_PATH];\r
+\r
+                                       Format(fullpath, sizeof(fullpath), "%s\\%s",\r
+                                               MsGetMyTempDir(), filename);\r
+\r
+                                       if (DumpBuf(p->Buffer, fullpath) == false)\r
+                                       {\r
+                                               MsgBoxEx(hWnd, MB_ICONSTOP, _UU("SM_READ_SAVE_TMP_FAILED"),\r
+                                                       fullpath);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (((UINT)ShellExecute(hWnd, "open", fullpath, NULL, NULL, SW_SHOWNORMAL)) > 32)\r
+                                               {\r
+                                                       EndDialog(hWnd, true);\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("SM_READ_SAVE_OPEN_ERROR"), fullpath);\r
+                                               }\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       // ファイルに保存する\r
+                                       wchar_t def[MAX_PATH];\r
+                                       wchar_t *uni_path;\r
+\r
+                                       StrToUni(def, sizeof(def), filename);\r
+                                       \r
+                                       uni_path = SaveDlg(hWnd, _UU("SM_READ_SAVE_DLG_FILTER"), _UU("SM_READ_SAVE_DLG_TITLE"),\r
+                                               def, L".log");\r
+\r
+                                       if (uni_path != NULL)\r
+                                       {\r
+                                               char path[MAX_PATH];\r
+\r
+                                               UniToStr(path, sizeof(path), uni_path);\r
+                                               Free(uni_path);\r
+\r
+                                               if (DumpBuf(p->Buffer, path) == false)\r
+                                               {\r
+                                                       MsgBox(hWnd, MB_ICONSTOP, _UU("SM_READ_SAVE_FAILED"));\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       EndDialog(hWnd, true);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ダウンロードコールバックプロシージャ\r
+bool SmReadLogFileProc(DOWNLOAD_PROGRESS *g)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       char size1[64], size2[64];\r
+       SM_READ_LOG_FILE *p;\r
+       HWND hWnd;\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = (SM_READ_LOG_FILE *)g->Param;\r
+       hWnd = p->hWnd;\r
+\r
+       SetPos(hWnd, P_PROGRESS, g->ProgressPercent);\r
+\r
+       ToStrByte(size1, sizeof(size1), g->CurrentSize);\r
+       ToStrByte(size2, sizeof(size2), g->TotalSize);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_READ_LOG_FILE_INFO_2"), size2, size1);\r
+\r
+       SetText(hWnd, S_INFO, tmp);\r
+\r
+       DoEvents(hWnd);\r
+\r
+       return p->cancel_flag ? false : true;\r
+}\r
+\r
+// ログファイルダウンロードダイアログプロシージャ\r
+UINT SmReadLogFile(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_READ_LOG_FILE *p = (SM_READ_LOG_FILE *)param;\r
+       BUF *buf;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               p->hWnd = hWnd;\r
+               SetFont(hWnd, S_INFO, Font(11, true));\r
+               SetText(hWnd, S_INFO, _UU("SM_READ_LOG_FILE_INFO_1"));\r
+               DisableClose(hWnd);\r
+               FormatText(hWnd, S_INFO2, p->filepath);\r
+               SetRange(hWnd, P_PROGRESS, 0, 100);\r
+\r
+               SetTimer(hWnd, 1, 100, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       buf = DownloadFileFromServer(p->s->Rpc, p->server_name, p->filepath, p->totalsize, SmReadLogFileProc, p);\r
+                       if (buf == NULL)\r
+                       {\r
+                               if (p->cancel_flag == false)\r
+                               {\r
+                                       // ダウンロード失敗\r
+                                       MsgBox(hWnd, MB_ICONSTOP, _UU("SM_READ_LOG_FILE_ERROR"));\r
+                               }\r
+                               EndDialog(hWnd, false);\r
+                       }\r
+                       else\r
+                       {\r
+                               // ダウンロード成功\r
+                               p->Buffer = buf;\r
+                               Dialog(hWnd, D_SM_SAVE_LOG, SmSaveLogProc, p);\r
+                               FreeBuf(buf);\r
+                               EndDialog(hWnd, true);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDCANCEL:\r
+                       p->cancel_flag = true;\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ログファイルのダウンロードを開始する\r
+void SmLogFileStartDownload(HWND hWnd, SM_SERVER *s, char *server_name, char *filepath, UINT totalsize)\r
+{\r
+       SM_READ_LOG_FILE p;\r
+       // 引数チェック\r
+       if (hWnd == NULL || server_name == NULL || filepath == NULL || totalsize == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.filepath = filepath;\r
+       p.s = s;\r
+       p.server_name = server_name;\r
+       p.totalsize = totalsize;\r
+\r
+       Dialog(hWnd, D_SM_READ_LOG_FILE, SmReadLogFile, &p);\r
+}\r
+\r
+// ダイアログ初期化\r
+void SmLogFileDlgInit(HWND hWnd, SM_SERVER *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_LOG2);\r
+\r
+       LvInit(hWnd, L_LIST);\r
+\r
+       LvInsertColumn(hWnd, L_LIST, 0, _UU("SM_LOG_FILE_COLUMN_1"), 250);\r
+       LvInsertColumn(hWnd, L_LIST, 1, _UU("SM_LOG_FILE_COLUMN_2"), 100);\r
+       LvInsertColumn(hWnd, L_LIST, 2, _UU("SM_LOG_FILE_COLUMN_3"), 130);\r
+       LvInsertColumn(hWnd, L_LIST, 3, _UU("SM_LOG_FILE_COLUMN_4"), 110);\r
+\r
+       SmLogFileDlgRefresh(hWnd, p);\r
+}\r
+\r
+// ダイアログ内容更新\r
+void SmLogFileDlgRefresh(HWND hWnd, SM_SERVER *p)\r
+{\r
+       UINT i;\r
+       LVB *v;\r
+       RPC_ENUM_LOG_FILE t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CALL(hWnd, ScEnumLogFile(p->Rpc, &t)) == false)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       v = LvInsertStart();\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               RPC_ENUM_LOG_FILE_ITEM *e = &t.Items[i];\r
+               wchar_t tmp1[MAX_PATH], tmp2[128], tmp3[128], tmp4[MAX_HOST_NAME_LEN + 1];\r
+               char tmp[MAX_SIZE];\r
+\r
+               StrToUni(tmp1, sizeof(tmp1), e->FilePath);\r
+\r
+               ToStrByte(tmp, sizeof(tmp), e->FileSize);\r
+               StrToUni(tmp2, sizeof(tmp2), tmp);\r
+\r
+               GetDateTimeStr64Uni(tmp3, sizeof(tmp3), SystemToLocal64(e->UpdatedTime));\r
+\r
+               StrToUni(tmp4, sizeof(tmp4), e->ServerName);\r
+\r
+               LvInsertAdd(v, ICO_LOG2, (void *)e->FileSize, 4, tmp1, tmp2, tmp3, tmp4);\r
+       }\r
+\r
+       LvInsertEndEx(v, hWnd, L_LIST, true);\r
+\r
+       if (t.NumItem != 0)\r
+       {\r
+               LvAutoSize(hWnd, L_LIST);\r
+       }\r
+\r
+       FreeRpcEnumLogFile(&t);\r
+\r
+       SmLogFileDlgUpdate(hWnd, p);\r
+}\r
+\r
+// ダイアログコントロール更新\r
+void SmLogFileDlgUpdate(HWND hWnd, SM_SERVER *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, LvIsSingleSelected(hWnd, L_LIST));\r
+}\r
+\r
+// ログファイルダイアログプロシージャ\r
+UINT SmLogFileDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       NMHDR *n;\r
+       SM_SERVER *p = (SM_SERVER *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmLogFileDlgInit(hWnd, p);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       if (IsEnable(hWnd, IDOK))\r
+                       {\r
+                               UINT i = LvGetSelected(hWnd, L_LIST);\r
+                               if (i != INFINITE)\r
+                               {\r
+                                       UINT size = (UINT)LvGetParam(hWnd, L_LIST, i);\r
+                                       char *server_name;\r
+                                       char *filepath;\r
+\r
+                                       server_name = LvGetStrA(hWnd, L_LIST, i, 3);\r
+                                       filepath = LvGetStrA(hWnd, L_LIST, i, 0);\r
+                                       SmLogFileStartDownload(hWnd, p, server_name, filepath, size);\r
+                                       Free(filepath);\r
+                                       Free(server_name);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       SmLogFileDlgRefresh(hWnd, p);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->code)\r
+               {\r
+               case LVN_ITEMCHANGED:\r
+                       switch (n->idFrom)\r
+                       {\r
+                       case L_LIST:\r
+                               SmLogFileDlgUpdate(hWnd, p);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_LIST);\r
+\r
+       return 0;\r
+}\r
+\r
+// ダイアログ初期化\r
+void SmHubEditAcDlgInit(HWND hWnd, SM_EDIT_AC *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEnable(hWnd, R_IPV6, GetCapsBool(p->e->s->p->CapsList, "b_support_ipv6_ac"));\r
+\r
+       if (p->id == 0)\r
+       {\r
+               UINT i, v;\r
+\r
+               Check(hWnd, R_SINGLE, true);\r
+               Check(hWnd, R_PASS, true);\r
+               Check(hWnd, R_IPV4, true);\r
+\r
+               v = 0;\r
+\r
+               for (i = 0;i < LIST_NUM(p->e->AcList);i++)\r
+               {\r
+                       AC *ac = LIST_DATA(p->e->AcList, i);\r
+\r
+                       v = MAX(v, ac->Priority);\r
+               }\r
+\r
+               v += 100;\r
+\r
+               SetInt(hWnd, E_PRIORITY, v);\r
+       }\r
+       else\r
+       {\r
+               AC *ac = GetAc(p->e->AcList, p->id);\r
+\r
+               if (ac == NULL)\r
+               {\r
+                       EndDialog(hWnd, false);\r
+                       return;\r
+               }\r
+\r
+               Check(hWnd, R_SINGLE, ac->Masked == false);\r
+               Check(hWnd, R_MASKED, ac->Masked);\r
+               Check(hWnd, R_IPV4, IsIP4(&ac->IpAddress));\r
+               Check(hWnd, R_IPV6, IsIP6(&ac->IpAddress));\r
+\r
+               if (IsIP4(&ac->IpAddress))\r
+               {\r
+                       IpSet(hWnd, E_IP, IPToUINT(&ac->IpAddress));\r
+               }\r
+               else\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+\r
+                       IPToStr(tmp, sizeof(tmp), &ac->IpAddress);\r
+                       SetTextA(hWnd, E_IPV6, tmp);\r
+               }\r
+\r
+               if (ac->Masked)\r
+               {\r
+                       if (IsIP4(&ac->IpAddress))\r
+                       {\r
+                               IpSet(hWnd, E_MASK, IPToUINT(&ac->SubnetMask));\r
+                       }\r
+                       else\r
+                       {\r
+                               char tmp[MAX_SIZE];\r
+\r
+                               MaskToStrEx(tmp, sizeof(tmp), &ac->SubnetMask, false);\r
+\r
+                               if (IsNum(tmp))\r
+                               {\r
+                                       StrCatLeft(tmp, sizeof(tmp), "/");\r
+                               }\r
+\r
+                               SetTextA(hWnd, E_MASKV6, tmp);\r
+                       }\r
+               }\r
+\r
+               Check(hWnd, R_PASS, ac->Deny == false);\r
+               Check(hWnd, R_DENY, ac->Deny);\r
+               SetInt(hWnd, E_PRIORITY, ac->Priority);\r
+\r
+               Free(ac);\r
+       }\r
+\r
+       Focus(hWnd, E_IP);\r
+\r
+       SmHubEditAcDlgUpdate(hWnd, p);\r
+}\r
+\r
+// ダイアログ更新\r
+void SmHubEditAcDlgUpdate(HWND hWnd, SM_EDIT_AC *p)\r
+{\r
+       bool b = true;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_SINGLE))\r
+       {\r
+               if (IsChecked(hWnd, R_IPV6) == false)\r
+               {\r
+                       Show(hWnd, E_IP);\r
+                       Hide(hWnd, E_IPV6);\r
+\r
+                       if (IpIsFilled(hWnd, E_IP) == false)\r
+                       {\r
+                               b = false;\r
+                       }\r
+\r
+                       if (IpGet(hWnd, E_IP) == 0 || IpGet(hWnd, E_IP) == 0xffffffff)\r
+                       {\r
+                               b = false;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       Show(hWnd, E_IPV6);\r
+                       Hide(hWnd, E_IP);\r
+\r
+                       GetTxtA(hWnd, E_IPV6, tmp, sizeof(tmp));\r
+\r
+                       if (IsStrIPv6Address(tmp) == false)\r
+                       {\r
+                               b = false;\r
+                       }\r
+               }\r
+\r
+               Hide(hWnd, S_MASK);\r
+               Hide(hWnd, E_MASK);\r
+               Hide(hWnd, E_MASKV6);\r
+       }\r
+       else\r
+       {\r
+               if (IsChecked(hWnd, R_IPV6) == false)\r
+               {\r
+                       Show(hWnd, E_IP);\r
+                       Hide(hWnd, E_IPV6);\r
+\r
+                       if (IpIsFilled(hWnd, E_IP) == false || IpIsFilled(hWnd, E_MASK) == false)\r
+                       {\r
+                               b = false;\r
+                       }\r
+\r
+                       if (IpGet(hWnd, E_IP) == 0xffffffff)\r
+                       {\r
+                               b = false;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       char tmp1[MAX_SIZE], tmp2[MAX_SIZE];\r
+\r
+                       Show(hWnd, E_IPV6);\r
+                       Hide(hWnd, E_IP);\r
+\r
+                       GetTxtA(hWnd, E_IPV6, tmp1, sizeof(tmp1));\r
+                       GetTxtA(hWnd, E_MASKV6, tmp2, sizeof(tmp2));\r
+\r
+                       if (!(IsIpStr6(tmp1) && IsIpMask6(tmp2)))\r
+                       {\r
+                               b = false;\r
+                       }\r
+               }\r
+\r
+               Show(hWnd, S_MASK);\r
+               SetShow(hWnd, E_MASK, !IsChecked(hWnd, R_IPV6));\r
+               SetShow(hWnd, E_MASKV6, IsChecked(hWnd, R_IPV6));\r
+       }\r
+\r
+       if (GetInt(hWnd, E_PRIORITY) == 0)\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       SetIcon(hWnd, S_ICON, IsChecked(hWnd, R_PASS) ? ICO_INTERNET : ICO_INTERNET_X);\r
+\r
+       SetEnable(hWnd, IDOK, b);\r
+}\r
+\r
+// ダイアログで OK ボタンがクリックされた\r
+void SmHubEditAcDlgOnOk(HWND hWnd, SM_EDIT_AC *p)\r
+{\r
+       AC ac;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&ac, sizeof(ac));\r
+       ac.Deny = IsChecked(hWnd, R_DENY);\r
+       ac.Priority = GetInt(hWnd, E_PRIORITY);\r
+\r
+       if (IsChecked(hWnd, R_IPV6) == false)\r
+       {\r
+               UINTToIP(&ac.IpAddress, IpGet(hWnd, E_IP));\r
+       }\r
+       else\r
+       {\r
+               GetTxtA(hWnd, E_IPV6, tmp, sizeof(tmp));\r
+\r
+               StrToIP6(&ac.IpAddress, tmp);\r
+       }\r
+\r
+       ac.Masked = IsChecked(hWnd, R_MASKED);\r
+\r
+       if (ac.Masked)\r
+       {\r
+               if (IsChecked(hWnd, R_IPV6) == false)\r
+               {\r
+                       UINTToIP(&ac.SubnetMask, IpGet(hWnd, E_MASK));\r
+               }\r
+               else\r
+               {\r
+                       GetTxtA(hWnd, E_MASKV6, tmp, sizeof(tmp));\r
+\r
+                       StrToMask6(&ac.SubnetMask, tmp);\r
+               }\r
+       }\r
+\r
+       if (p->id != 0)\r
+       {\r
+               SetAc(p->e->AcList, p->id, &ac);\r
+       }\r
+       else\r
+       {\r
+               AddAc(p->e->AcList, &ac);\r
+       }\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// AC 編集ダイアログ\r
+UINT SmHubEditAcDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_EDIT_AC *p = (SM_EDIT_AC *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmHubEditAcDlgInit(hWnd, p);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_SINGLE:\r
+               case R_MASKED:\r
+               case E_IP:\r
+               case E_MASK:\r
+               case R_PASS:\r
+               case R_DENY:\r
+               case E_PRIORITY:\r
+               case R_IPV4:\r
+               case R_IPV6:\r
+               case E_IPV6:\r
+               case E_MASKV6:\r
+                       SmHubEditAcDlgUpdate(hWnd, p);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case R_IPV4:\r
+               case R_IPV6:\r
+               case R_SINGLE:\r
+               case R_MASKED:\r
+                       if (IsChecked(hWnd, R_IPV6) == false)\r
+                       {\r
+                               if (IpIsFilled(hWnd, E_IP))\r
+                               {\r
+                                       Focus(hWnd, E_MASK);\r
+                               }\r
+                               else\r
+                               {\r
+                                       Focus(hWnd, E_IP);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               char tmp[MAX_SIZE];\r
+\r
+                               GetTxtA(hWnd, E_IPV6, tmp, sizeof(tmp));\r
+\r
+                               if (IsStrIPv6Address(tmp))\r
+                               {\r
+                                       FocusEx(hWnd, E_MASKV6);\r
+                               }\r
+                               else\r
+                               {\r
+                                       FocusEx(hWnd, E_IPV6);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDOK:\r
+                       SmHubEditAcDlgOnOk(hWnd, p);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ダイアログ初期化\r
+void SmHubAcDlgInit(HWND hWnd, SM_EDIT_AC_LIST *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_INTERNET);\r
+\r
+       FormatText(hWnd, S_TITLE, p->s->HubName);\r
+\r
+       LvInit(hWnd, L_LIST);\r
+       LvInsertColumn(hWnd, L_LIST, 0, _UU("SM_AC_COLUMN_1"), 40);\r
+       LvInsertColumn(hWnd, L_LIST, 1, _UU("SM_AC_COLUMN_2"), 80);\r
+       LvInsertColumn(hWnd, L_LIST, 2, _UU("SM_AC_COLUMN_3"), 90);\r
+       LvInsertColumn(hWnd, L_LIST, 3, _UU("SM_AC_COLUMN_4"), 170);\r
+\r
+       SmHubAcDlgRefresh(hWnd, p);\r
+}\r
+\r
+// ダイアログコントロール更新\r
+void SmHubAcDlgUpdate(HWND hWnd, SM_EDIT_AC_LIST *p)\r
+{\r
+       bool b;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = LvIsSingleSelected(hWnd, L_LIST);\r
+\r
+       SetEnable(hWnd, IDOK, b);\r
+       SetEnable(hWnd, B_DELETE, b);\r
+}\r
+\r
+// ダイアログ内容更新\r
+void SmHubAcDlgRefresh(HWND hWnd, SM_EDIT_AC_LIST *p)\r
+{\r
+       UINT i;\r
+       LVB *v;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = LvInsertStart();\r
+\r
+       for (i = 0;i < LIST_NUM(p->AcList);i++)\r
+       {\r
+               wchar_t tmp1[32], *tmp2, tmp3[MAX_SIZE], tmp4[32];\r
+               char *tmp_str;\r
+               AC *ac = LIST_DATA(p->AcList, i);\r
+\r
+               UniToStru(tmp1, ac->Id);\r
+               tmp2 = ac->Deny ? _UU("SM_AC_DENY") : _UU("SM_AC_PASS");\r
+               tmp_str = GenerateAcStr(ac);\r
+               StrToUni(tmp3, sizeof(tmp3), tmp_str);\r
+\r
+               Free(tmp_str);\r
+\r
+               UniToStru(tmp4, ac->Priority);\r
+\r
+               LvInsertAdd(v, ac->Deny ? ICO_INTERNET_X : ICO_INTERNET,\r
+                       (void *)ac->Id, 4, tmp1, tmp4, tmp2, tmp3);\r
+       }\r
+\r
+       LvInsertEnd(v, hWnd, L_LIST);\r
+       LvSortEx(hWnd, L_LIST, 0, false, true);\r
+\r
+\r
+       SmHubAcDlgUpdate(hWnd, p);\r
+}\r
+\r
+// アクセス制御リスト編集ダイアログ\r
+UINT SmHubAcDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       NMHDR *n;\r
+       SM_EDIT_AC_LIST *p = (SM_EDIT_AC_LIST *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmHubAcDlgInit(hWnd, p);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       if (IsEnable(hWnd, IDOK))\r
+                       {\r
+                               SM_EDIT_AC s;\r
+                               Zero(&s, sizeof(s));\r
+\r
+                               s.e = p;\r
+                               s.id = (UINT)LvGetParam(hWnd, L_LIST, LvGetSelected(hWnd, L_LIST));\r
+\r
+                               if (Dialog(hWnd, D_SM_AC, SmHubEditAcDlgProc, &s))\r
+                               {\r
+                                       SmHubAcDlgRefresh(hWnd, p);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_ADD:\r
+                       if (IsEnable(hWnd, B_ADD))\r
+                       {\r
+                               SM_EDIT_AC s;\r
+                               Zero(&s, sizeof(s));\r
+\r
+                               s.e = p;\r
+\r
+                               if (Dialog(hWnd, D_SM_AC, SmHubEditAcDlgProc, &s))\r
+                               {\r
+                                       SmHubAcDlgRefresh(hWnd, p);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       if (IsEnable(hWnd, B_DELETE))\r
+                       {\r
+                               UINT id = (UINT)LvGetParam(hWnd, L_LIST, LvGetSelected(hWnd, L_LIST));\r
+\r
+                               if (DelAc(p->AcList, id))\r
+                               {\r
+                                       SmHubAcDlgRefresh(hWnd, p);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_SAVE:\r
+                       if (IsEnable(hWnd, B_SAVE))\r
+                       {\r
+                               RPC_AC_LIST t;\r
+\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.HubName, sizeof(t.HubName), p->s->HubName);\r
+                               t.o = CloneAcList(p->AcList);\r
+\r
+                               if (CALL(hWnd, ScSetAcList(p->s->p->Rpc, &t)))\r
+                               {\r
+                                       EndDialog(hWnd, true);\r
+                               }\r
+\r
+                               FreeRpcAcList(&t);\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->code)\r
+               {\r
+               case LVN_ITEMCHANGED:\r
+                       switch (n->idFrom)\r
+                       {\r
+                       case L_LIST:\r
+                               SmHubAcDlgUpdate(hWnd, p);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_LIST);\r
+\r
+       return 0;\r
+}\r
+\r
+// アクセス制御リスト編集\r
+void SmHubAc(HWND hWnd, SM_EDIT_HUB *s)\r
+{\r
+       SM_EDIT_AC_LIST p;\r
+       RPC_AC_LIST t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+\r
+       if (CALL(hWnd, ScGetAcList(s->p->Rpc, &t)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.s = s;\r
+       p.AcList = CloneAcList(t.o);\r
+\r
+       FreeRpcAcList(&t);\r
+\r
+       Dialog(hWnd, D_SM_AC_LIST, SmHubAcDlgProc, &p);\r
+\r
+       FreeAcList(p.AcList);\r
+}\r
+\r
+// ダイアログ初期化\r
+void SmEditCrlDlgInit(HWND hWnd, SM_EDIT_CRL *c)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (c->NewCrl == false)\r
+       {\r
+               RPC_CRL t;\r
+               CRL *crl;\r
+\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.HubName, sizeof(t.HubName), c->s->HubName);\r
+               t.Key = c->Key;\r
+\r
+               if (CALL(hWnd, ScGetCrl(c->s->Rpc, &t)) == false)\r
+               {\r
+                       EndDialog(hWnd, false);\r
+                       return;\r
+               }\r
+\r
+               crl = t.Crl;\r
+\r
+               SmEditCrlDlgSetName(hWnd, crl->Name);\r
+               SmEditCrlDlgSetSerial(hWnd, crl->Serial);\r
+               SmEditCrlDlgSetHash(hWnd, crl->DigestMD5, crl->DigestSHA1);\r
+\r
+               FreeRpcCrl(&t);\r
+       }\r
+\r
+       SmEditCrlDlgUpdate(hWnd, c);\r
+}\r
+\r
+// コントロール更新\r
+void SmEditCrlDlgUpdate(HWND hWnd, SM_EDIT_CRL *c)\r
+{\r
+       bool b = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEnable(hWnd, E_CN, IsChecked(hWnd, R_CN));\r
+       SetEnable(hWnd, E_O, IsChecked(hWnd, R_O));\r
+       SetEnable(hWnd, E_OU, IsChecked(hWnd, R_OU));\r
+       SetEnable(hWnd, E_C, IsChecked(hWnd, R_C));\r
+       SetEnable(hWnd, E_ST, IsChecked(hWnd, R_ST));\r
+       SetEnable(hWnd, E_L, IsChecked(hWnd, R_L));\r
+       SetEnable(hWnd, E_SERI, IsChecked(hWnd, R_SERI));\r
+       SetEnable(hWnd, E_MD5_HASH, IsChecked(hWnd, R_MD5_HASH));\r
+       SetEnable(hWnd, E_SHA1_HASH, IsChecked(hWnd, R_SHA1_HASH));\r
+\r
+       if (IsChecked(hWnd, R_CN))\r
+       {\r
+               if (IsEmpty(hWnd, E_CN))\r
+               {\r
+                       b = false;\r
+               }\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_O))\r
+       {\r
+               if (IsEmpty(hWnd, E_O))\r
+               {\r
+                       b = false;\r
+               }\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_OU))\r
+       {\r
+               if (IsEmpty(hWnd, E_OU))\r
+               {\r
+                       b = false;\r
+               }\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_C))\r
+       {\r
+               if (IsEmpty(hWnd, E_C))\r
+               {\r
+                       b = false;\r
+               }\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_ST))\r
+       {\r
+               if (IsEmpty(hWnd, E_ST))\r
+               {\r
+                       b = false;\r
+               }\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_L))\r
+       {\r
+               if (IsEmpty(hWnd, E_L))\r
+               {\r
+                       b = false;\r
+               }\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_SERI))\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               BUF *buf;\r
+\r
+               GetTxtA(hWnd, E_SERI, tmp, sizeof(tmp));\r
+               buf = StrToBin(tmp);\r
+\r
+               if (buf->Size == 0)\r
+               {\r
+                       b = false;\r
+               }\r
+\r
+               FreeBuf(buf);\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_MD5_HASH))\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               BUF *buf;\r
+\r
+               GetTxtA(hWnd, E_MD5_HASH, tmp, sizeof(tmp));\r
+               buf = StrToBin(tmp);\r
+\r
+               if (buf->Size != MD5_SIZE)\r
+               {\r
+                       b = false;\r
+               }\r
+\r
+               FreeBuf(buf);\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_SHA1_HASH))\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               BUF *buf;\r
+\r
+               GetTxtA(hWnd, E_SHA1_HASH, tmp, sizeof(tmp));\r
+               buf = StrToBin(tmp);\r
+\r
+               if (buf->Size != SHA1_SIZE)\r
+               {\r
+                       b = false;\r
+               }\r
+\r
+               FreeBuf(buf);\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, b);\r
+}\r
+\r
+// OK ボタンクリック\r
+void SmEditCrlDlgOnOk(HWND hWnd, SM_EDIT_CRL *c)\r
+{\r
+       CRL *crl;\r
+       NAME *n;\r
+       RPC_CRL t;\r
+       bool empty = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       crl = ZeroMalloc(sizeof(CRL));\r
+       crl->Name = ZeroMalloc(sizeof(NAME));\r
+       n = crl->Name;\r
+\r
+       if (IsChecked(hWnd, R_CN))\r
+       {\r
+               n->CommonName = GetText(hWnd, E_CN);\r
+               empty = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_O))\r
+       {\r
+               n->Organization = GetText(hWnd, E_O);\r
+               empty = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_OU))\r
+       {\r
+               n->Unit = GetText(hWnd, E_OU);\r
+               empty = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_C))\r
+       {\r
+               n->Country = GetText(hWnd, E_C);\r
+               empty = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_ST))\r
+       {\r
+               n->State = GetText(hWnd, E_ST);\r
+               empty = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_L))\r
+       {\r
+               n->Local = GetText(hWnd, E_L);\r
+               empty = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_SERI))\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               BUF *b;\r
+\r
+               GetTxtA(hWnd, E_SERI, tmp, sizeof(tmp));\r
+               b = StrToBin(tmp);\r
+\r
+               if (b != NULL && b->Size >= 1)\r
+               {\r
+                       crl->Serial = NewXSerial(b->Buf, b->Size);\r
+               }\r
+\r
+               FreeBuf(b);\r
+\r
+               empty = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_MD5_HASH))\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               BUF *b;\r
+\r
+               GetTxtA(hWnd, E_MD5_HASH, tmp, sizeof(tmp));\r
+               b = StrToBin(tmp);\r
+\r
+               if (b != NULL && b->Size == MD5_SIZE)\r
+               {\r
+                       Copy(crl->DigestMD5, b->Buf, MD5_SIZE);\r
+               }\r
+\r
+               FreeBuf(b);\r
+\r
+               empty = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_SHA1_HASH))\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               BUF *b;\r
+\r
+               GetTxtA(hWnd, E_SHA1_HASH, tmp, sizeof(tmp));\r
+               b = StrToBin(tmp);\r
+\r
+               if (b != NULL && b->Size == SHA1_SIZE)\r
+               {\r
+                       Copy(crl->DigestSHA1, b->Buf, SHA1_SIZE);\r
+               }\r
+\r
+               FreeBuf(b);\r
+\r
+               empty = false;\r
+       }\r
+\r
+       if (empty)\r
+       {\r
+               if (MsgBox(hWnd, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2, _UU("SM_CRL_EMPTY_MSG")) == IDNO)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       if (c->NewCrl)\r
+       {\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.HubName, sizeof(t.HubName), c->s->HubName);\r
+               t.Crl = crl;\r
+\r
+               if (CALL(hWnd, ScAddCrl(c->s->Rpc, &t)))\r
+               {\r
+                       EndDialog(hWnd, true);\r
+               }\r
+\r
+               FreeRpcCrl(&t);\r
+       }\r
+       else\r
+       {\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.HubName, sizeof(t.HubName), c->s->HubName);\r
+               t.Crl = crl;\r
+               t.Key = c->Key;\r
+\r
+               if (CALL(hWnd, ScSetCrl(c->s->Rpc, &t)))\r
+               {\r
+                       EndDialog(hWnd, true);\r
+               }\r
+\r
+               FreeRpcCrl(&t);\r
+       }\r
+}\r
+\r
+// 証明書の読み込み\r
+void SmEditCrlDlgOnLoad(HWND hWnd, SM_EDIT_CRL *c)\r
+{\r
+       X *x;\r
+       // 引数チェック\r
+       if (hWnd == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (CmLoadXFromFileOrSecureCard(hWnd, &x))\r
+       {\r
+               UCHAR md5[MD5_SIZE], sha1[SHA1_SIZE];\r
+\r
+               SmEditCrlDlgSetName(hWnd, x->subject_name);\r
+               SmEditCrlDlgSetSerial(hWnd, x->serial);\r
+               GetXDigest(x, md5, false);\r
+               GetXDigest(x, sha1, true);\r
+               SmEditCrlDlgSetHash(hWnd, md5, sha1);\r
+\r
+               FreeX(x);\r
+\r
+               SmEditCrlDlgUpdate(hWnd, c);\r
+       }\r
+}\r
+\r
+// ダイアログにハッシュ情報を設定する\r
+void SmEditCrlDlgSetHash(HWND hWnd, UCHAR *hash_md5, UCHAR *hash_sha1)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (hash_md5 != NULL && IsZero(hash_md5, MD5_SIZE) == false)\r
+       {\r
+               Check(hWnd, R_MD5_HASH, true);\r
+               BinToStrEx(tmp, sizeof(tmp), hash_md5, MD5_SIZE);\r
+               SetTextA(hWnd, E_MD5_HASH, tmp);\r
+       }\r
+       else\r
+       {\r
+               Check(hWnd, R_MD5_HASH, false);\r
+       }\r
+\r
+       if (hash_sha1 != NULL && IsZero(hash_sha1, SHA1_SIZE) == false)\r
+       {\r
+               Check(hWnd, R_SHA1_HASH, true);\r
+               BinToStrEx(tmp, sizeof(tmp), hash_sha1, SHA1_SIZE);\r
+               SetTextA(hWnd, E_SHA1_HASH, tmp);\r
+       }\r
+       else\r
+       {\r
+               Check(hWnd, R_SHA1_HASH, false);\r
+       }\r
+}\r
+\r
+// ダイアログにシリアル番号を設定する\r
+void SmEditCrlDlgSetSerial(HWND hWnd, X_SERIAL *serial)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || serial == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       BinToStrEx(tmp, sizeof(tmp), serial->data, serial->size);\r
+\r
+       Check(hWnd, R_SERI, true);\r
+\r
+       SetTextA(hWnd, E_SERI, tmp);\r
+}\r
+\r
+// ダイアログに名前状況を設定する\r
+void SmEditCrlDlgSetName(HWND hWnd, NAME *name)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // CN\r
+       if (UniIsEmptyStr(name->CommonName))\r
+       {\r
+               Check(hWnd, R_CN, false);\r
+       }\r
+       else\r
+       {\r
+               Check(hWnd, R_CN, true);\r
+               SetText(hWnd, E_CN, name->CommonName);\r
+       }\r
+\r
+       // O\r
+       if (UniIsEmptyStr(name->Organization))\r
+       {\r
+               Check(hWnd, R_O, false);\r
+       }\r
+       else\r
+       {\r
+               Check(hWnd, R_O, true);\r
+               SetText(hWnd, E_O, name->Organization);\r
+       }\r
+\r
+       // OU\r
+       if (UniIsEmptyStr(name->Unit))\r
+       {\r
+               Check(hWnd, R_OU, false);\r
+       }\r
+       else\r
+       {\r
+               Check(hWnd, R_OU, true);\r
+               SetText(hWnd, E_OU, name->Unit);\r
+       }\r
+\r
+       // C\r
+       if (UniIsEmptyStr(name->Country))\r
+       {\r
+               Check(hWnd, R_C, false);\r
+       }\r
+       else\r
+       {\r
+               Check(hWnd, R_C, true);\r
+               SetText(hWnd, E_C, name->Country);\r
+       }\r
+\r
+       // ST\r
+       if (UniIsEmptyStr(name->State))\r
+       {\r
+               Check(hWnd, R_ST, false);\r
+       }\r
+       else\r
+       {\r
+               Check(hWnd, R_ST, true);\r
+               SetText(hWnd, E_ST, name->State);\r
+       }\r
+\r
+       // L\r
+       if (UniIsEmptyStr(name->Local))\r
+       {\r
+               Check(hWnd, R_L, false);\r
+       }\r
+       else\r
+       {\r
+               Check(hWnd, R_L, true);\r
+               SetText(hWnd, E_L, name->Local);\r
+       }\r
+}\r
+\r
+// CRL 編集ダイアログプロシージャ\r
+UINT SmEditCrlDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_EDIT_CRL *c = (SM_EDIT_CRL *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmEditCrlDlgInit(hWnd, c);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_CN:\r
+               case E_CN:\r
+               case R_O:\r
+               case E_O:\r
+               case R_OU:\r
+               case E_OU:\r
+               case R_C:\r
+               case E_C:\r
+               case R_ST:\r
+               case E_ST:\r
+               case R_L:\r
+               case E_L:\r
+               case R_SERI:\r
+               case E_SERI:\r
+               case R_MD5_HASH:\r
+               case E_MD5_HASH:\r
+               case R_SHA1_HASH:\r
+               case E_SHA1_HASH:\r
+                       SmEditCrlDlgUpdate(hWnd, c);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case B_LOAD:\r
+                       SmEditCrlDlgOnLoad(hWnd, c);\r
+                       break;\r
+\r
+               case IDOK:\r
+                       SmEditCrlDlgOnOk(hWnd, c);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case R_CN:\r
+                       FocusEx(hWnd, E_CN);\r
+                       break;\r
+\r
+               case R_O:\r
+                       FocusEx(hWnd, E_O);\r
+                       break;\r
+\r
+               case R_OU:\r
+                       FocusEx(hWnd, E_OU);\r
+                       break;\r
+\r
+               case R_C:\r
+                       FocusEx(hWnd, E_C);\r
+                       break;\r
+\r
+               case R_ST:\r
+                       FocusEx(hWnd, E_ST);\r
+                       break;\r
+\r
+               case R_L:\r
+                       FocusEx(hWnd, E_L);\r
+                       break;\r
+\r
+               case R_SERI:\r
+                       FocusEx(hWnd, E_SERI);\r
+                       break;\r
+\r
+               case R_MD5_HASH:\r
+                       FocusEx(hWnd, E_MD5_HASH);\r
+                       break;\r
+\r
+               case R_SHA1_HASH:\r
+                       FocusEx(hWnd, E_SHA1_HASH);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ダイアログ初期化\r
+void SmCrlDlgInit(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_CERT_X);\r
+\r
+       LvInit(hWnd, L_LIST);\r
+       LvInsertColumn(hWnd, L_LIST, 0, _UU("SM_CRL_COLUMN_1"), 555);\r
+\r
+       SmCrlDlgRefresh(hWnd, s);\r
+}\r
+\r
+// コントロール更新\r
+void SmCrlDlgUpdate(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, LvIsSingleSelected(hWnd, L_LIST));\r
+       SetEnable(hWnd, B_DELETE, LvIsSingleSelected(hWnd, L_LIST));\r
+}\r
+\r
+// 内容更新\r
+void SmCrlDlgRefresh(HWND hWnd, SM_HUB *s)\r
+{\r
+       UINT i;\r
+       RPC_ENUM_CRL t;\r
+       LVB *v;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+\r
+       if (CALL(hWnd, ScEnumCrl(s->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       v = LvInsertStart();\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               RPC_ENUM_CRL_ITEM *e = &t.Items[i];\r
+               LvInsertAdd(v, ICO_CERT_X, (void *)e->Key, 1, e->CrlInfo);\r
+       }\r
+\r
+       LvInsertEndEx(v, hWnd, L_LIST, true);\r
+\r
+       if (t.NumItem >= 1)\r
+       {\r
+               LvAutoSize(hWnd, L_LIST);\r
+       }\r
+\r
+       FreeRpcEnumCrl(&t);\r
+\r
+       SmCrlDlgUpdate(hWnd, s);\r
+}\r
+\r
+// 無効な証明書一覧ダイアログプロシージャ\r
+UINT SmCrlDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_EDIT_CRL c;\r
+       SM_HUB *s = (SM_HUB *)param;\r
+       NMHDR *n;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmCrlDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_ADD:\r
+                       Zero(&c, sizeof(c));\r
+                       c.NewCrl = true;\r
+                       c.s = s;\r
+\r
+                       if (Dialog(hWnd, D_SM_EDIT_CRL, SmEditCrlDlgProc, &c))\r
+                       {\r
+                               SmCrlDlgRefresh(hWnd, s);\r
+                       }\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       if (IsEnable(hWnd, B_DELETE))\r
+                       {\r
+                               if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("SM_CRL_DELETE_MSG")) == IDYES)\r
+                               {\r
+                                       RPC_CRL t;\r
+\r
+                                       Zero(&t, sizeof(t));\r
+                                       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+                                       t.Key = (UINT)LvGetParam(hWnd, L_LIST, LvGetSelected(hWnd, L_LIST));\r
+\r
+                                       if (CALL(hWnd, ScDelCrl(s->Rpc, &t)))\r
+                                       {\r
+                                               SmCrlDlgRefresh(hWnd, s);\r
+                                       }\r
+\r
+                                       FreeRpcCrl(&t);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDOK:\r
+                       if (IsEnable(hWnd, IDOK))\r
+                       {\r
+                               SM_EDIT_CRL c;\r
+\r
+                               Zero(&c, sizeof(c));\r
+                               c.NewCrl = false;\r
+                               c.s = s;\r
+                               c.Key = (UINT)LvGetParam(hWnd, L_LIST, LvGetSelected(hWnd, L_LIST));\r
+\r
+                               if (Dialog(hWnd, D_SM_EDIT_CRL, SmEditCrlDlgProc, &c))\r
+                               {\r
+                                       SmCrlDlgRefresh(hWnd, s);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->code)\r
+               {\r
+               case LVN_ITEMCHANGED:\r
+                       switch (n->idFrom)\r
+                       {\r
+                       case L_LIST:\r
+                               SmCrlDlgUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_LIST);\r
+\r
+       return 0;\r
+}\r
+\r
+// スマートカードマネージャ\r
+void SmSecureManager(HWND hWnd)\r
+{\r
+       UINT id = SmGetCurrentSecureIdFromReg();\r
+\r
+       if (id == 0)\r
+       {\r
+               id = SmSelectSecureId(hWnd);\r
+       }\r
+\r
+       if (id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CmSecureManager(hWnd, id);\r
+}\r
+\r
+// ダイアログ初期化\r
+void SmSelectKeyPairDlgInit(HWND hWnd, SM_SECURE_KEYPAIR *k)\r
+{\r
+       SECURE_DEVICE *dev;\r
+       // 引数チェック\r
+       if (hWnd == NULL || k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       dev = GetSecureDevice(k->Id);\r
+       if (dev != NULL)\r
+       {\r
+               FormatText(hWnd, S_INFO, dev->DeviceName);\r
+       }\r
+\r
+       LvInit(hWnd, L_CERT);\r
+       LvInsertColumn(hWnd, L_CERT, 0, _UU("SEC_MGR_COLUMN1"), 200);\r
+       LvInsertColumn(hWnd, L_CERT, 1, _UU("SEC_MGR_COLUMN2"), 110);\r
+\r
+       LvInit(hWnd, L_KEY);\r
+       LvInsertColumn(hWnd, L_KEY, 0, _UU("SEC_MGR_COLUMN1"), 200);\r
+       LvInsertColumn(hWnd, L_KEY, 1, _UU("SEC_MGR_COLUMN2"), 110);\r
+\r
+       SetEnable(hWnd, L_CERT, k->UseCert);\r
+       SetEnable(hWnd, B_BOLD1, k->UseCert);\r
+       SetEnable(hWnd, L_KEY, k->UseKey);\r
+       SetEnable(hWnd, B_BOLD2, k->UseKey);\r
+\r
+       SetFont(hWnd, B_BOLD1, Font(0, true));\r
+       SetFont(hWnd, B_BOLD2, Font(0, true));\r
+\r
+       SmSelectKeyPairDlgUpdate(hWnd, k);\r
+}\r
+\r
+// ダイアログコントロール更新\r
+void SmSelectKeyPairDlgUpdate(HWND hWnd, SM_SECURE_KEYPAIR *k)\r
+{\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (k->UseCert)\r
+       {\r
+               if (LvIsSingleSelected(hWnd, L_CERT) == false)\r
+               {\r
+                       ok = false;\r
+               }\r
+               else\r
+               {\r
+                       char *name = LvGetSelectedStrA(hWnd, L_CERT, 0);\r
+                       if (name != NULL)\r
+                       {\r
+                               if (LvIsSingleSelected(hWnd, L_KEY) == false)\r
+                               {\r
+                                       if ((k->Flag++) == 0)\r
+                                       {\r
+                                               LvSelect(hWnd, L_KEY, LvSearchStrA(hWnd, L_KEY, 0, name));\r
+                                       }\r
+                               }\r
+                               Free(name);\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (k->UseKey)\r
+       {\r
+               if (LvIsSingleSelected(hWnd, L_KEY) == false)\r
+               {\r
+                       ok = false;\r
+               }\r
+               else\r
+               {\r
+                       char *name = LvGetSelectedStrA(hWnd, L_KEY, 0);\r
+                       if (name != NULL)\r
+                       {\r
+                               if (LvIsSingleSelected(hWnd, L_CERT) == false)\r
+                               {\r
+                                       if ((k->Flag++) == 0)\r
+                                       {\r
+                                               LvSelect(hWnd, L_CERT, LvSearchStrA(hWnd, L_CERT, 0, name));\r
+                                       }\r
+                               }\r
+                               Free(name);\r
+                       }\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// コンテンツ更新\r
+void SmSelectKeyPairDlgRefresh(HWND hWnd, SM_SECURE_KEYPAIR *k)\r
+{\r
+       bool ret;\r
+       LIST *o;\r
+       WINUI_SECURE_BATCH batch[] =\r
+       {\r
+               {WINUI_SECURE_ENUM_OBJECTS, NULL, false, NULL, NULL, NULL, NULL, NULL, NULL},\r
+       };\r
+       // 引数チェック\r
+       if (hWnd == NULL || k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ret = SecureDeviceWindow(hWnd, batch, sizeof(batch) / sizeof(batch[0]), k->Id, k->BitmapId);\r
+\r
+       if (ret == false)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       o = batch[0].EnumList;\r
+       if (o != NULL)\r
+       {\r
+               if (k->UseCert)\r
+               {\r
+                       CmSecureManagerDlgPrintListEx(hWnd, L_CERT, o, SEC_X);\r
+               }\r
+\r
+               if (k->UseKey)\r
+               {\r
+                       CmSecureManagerDlgPrintListEx(hWnd, L_KEY, o, SEC_K);\r
+               }\r
+\r
+               FreeEnumSecObject(o);\r
+       }\r
+\r
+       // コントロール更新\r
+       SmSelectKeyPairDlgUpdate(hWnd, k);\r
+}\r
+\r
+// キーペア読み込みダイアログプロシージャ\r
+UINT SmSelectKeyPairDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       NMHDR *n;\r
+       SM_SECURE_KEYPAIR *k = (SM_SECURE_KEYPAIR *)param;\r
+       char *s1, *s2;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmSelectKeyPairDlgInit(hWnd, k);\r
+\r
+               SetTimer(hWnd, 1, 1, NULL);\r
+               SetTimer(hWnd, 2, 100, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       SmSelectKeyPairDlgRefresh(hWnd, k);\r
+                       break;\r
+\r
+               case 2:\r
+                       SmSelectKeyPairDlgUpdate(hWnd, k);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       s1 = LvGetSelectedStrA(hWnd, L_CERT, 0);\r
+                       s2 = LvGetSelectedStrA(hWnd, L_KEY, 0);\r
+                       if (k->UseCert)\r
+                       {\r
+                               StrCpy(k->CertName, sizeof(k->CertName), s1);\r
+                       }\r
+                       if (k->UseKey)\r
+                       {\r
+                               StrCpy(k->KeyName, sizeof(k->KeyName), s2);\r
+                       }\r
+                       Free(s1);\r
+                       Free(s2);\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_CERT:\r
+               case L_KEY:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmSelectKeyPairDlgUpdate(hWnd, k);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// キーペアをスマートカードから読み込む\r
+bool SmSelectKeyPair(HWND hWnd, char *cert_name, UINT cert_name_size, char *key_name, UINT key_name_size)\r
+{\r
+       return SmSelectKeyPairEx(hWnd, cert_name, cert_name_size, key_name, key_name_size, 0);\r
+}\r
+bool SmSelectKeyPairEx(HWND hWnd, char *cert_name, UINT cert_name_size, char *key_name, UINT key_name_size, UINT bitmap_id)\r
+{\r
+       SM_SECURE_KEYPAIR p;\r
+       // 引数チェック\r
+       if (hWnd == NULL || (cert_name == NULL && key_name == NULL))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.Id = SmGetCurrentSecureId(hWnd);\r
+       if (p.Id == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p.UseCert = (cert_name == NULL) ? false : true;\r
+       p.UseKey = (key_name == NULL) ? false : true;\r
+       p.BitmapId = bitmap_id;\r
+\r
+       if (Dialog(hWnd, D_SM_SELECT_KEYPAIR, SmSelectKeyPairDlg, &p) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (p.UseCert)\r
+       {\r
+               StrCpy(cert_name, cert_name_size, p.CertName);\r
+       }\r
+       if (p.UseKey)\r
+       {\r
+               StrCpy(key_name, key_name_size, p.KeyName);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// スマートカード番号をユーザーに選択させる\r
+UINT SmSelectSecureId(HWND hWnd)\r
+{\r
+       UINT id = MsRegReadInt(REG_CURRENT_USER, SECURE_MANAGER_KEY, "DeviceId");\r
+       UINT ret;\r
+\r
+       if (id != 0 && CheckSecureDeviceId(id) == false)\r
+       {\r
+               id = 0;\r
+       }\r
+\r
+       ret = CmSelectSecure(hWnd, id);\r
+       if (ret == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       SmWriteSelectSecureIdReg(ret);\r
+\r
+       return ret;\r
+}\r
+\r
+// 現在のスマートカード番号をレジストリに書き込む\r
+void SmWriteSelectSecureIdReg(UINT id)\r
+{\r
+       MsRegWriteInt(REG_CURRENT_USER, SECURE_MANAGER_KEY, "DeviceId", id);\r
+}\r
+\r
+// 現在のスマートカード番号を取得する\r
+UINT SmGetCurrentSecureId(HWND hWnd)\r
+{\r
+       // 現在の設定をロード\r
+       UINT id = MsRegReadInt(REG_CURRENT_USER, SECURE_MANAGER_KEY, "DeviceId");\r
+\r
+       // 正常かどうかチェック\r
+       if (id == 0 || CheckSecureDeviceId(id) == false)\r
+       {\r
+               // 不正な場合はスマートカードデバイス番号を選択させる\r
+               id = SmSelectSecureId(hWnd);\r
+       }\r
+\r
+       return id;\r
+}\r
+\r
+// レジストリから現在のスマートカード番号を取得する\r
+UINT SmGetCurrentSecureIdFromReg()\r
+{\r
+       // 現在の設定をロード\r
+       UINT id = MsRegReadInt(REG_CURRENT_USER, SECURE_MANAGER_KEY, "DeviceId");\r
+\r
+       // 正常かどうかチェック\r
+       if (id == 0 || CheckSecureDeviceId(id) == false)\r
+       {\r
+               id = 0;\r
+       }\r
+\r
+       return id;\r
+}\r
+\r
+// 指定した名前の L3 スイッチが開始されているかどうか取得する\r
+bool SmL3IsSwActive(SM_SERVER *s, char *name)\r
+{\r
+       bool ret = false;\r
+       UINT i;\r
+       RPC_ENUM_L3SW t;\r
+       // 引数チェック\r
+       if (s == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (ScEnumL3Switch(s->Rpc, &t) == ERR_NO_ERROR)\r
+       {\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       RPC_ENUM_L3SW_ITEM *e = &t.Items[i];\r
+                       if (StrCmpi(e->Name, name) == 0)\r
+                       {\r
+                               if (e->Active)\r
+                               {\r
+                                       ret = true;\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+               FreeRpcEnumL3Sw(&t);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ダイアログ初期化\r
+void SmL3SwTableDlgInit(HWND hWnd, SM_L3SW *w)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || w == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SmL3SwTableDlgUpdate(hWnd, w);\r
+}\r
+\r
+// コントロール更新\r
+void SmL3SwTableDlgUpdate(HWND hWnd, SM_L3SW *w)\r
+{\r
+       bool b = true;\r
+       UINT ip;\r
+       // 引数チェック\r
+       if (hWnd == NULL || w == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IpIsFilled(hWnd, E_NETWORK) == false ||\r
+               IpIsFilled(hWnd, E_MASK) == false ||\r
+               IpIsFilled(hWnd, E_GATEWAY) == false)\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       ip = IpGet(hWnd, E_GATEWAY);\r
+       if (ip == 0 || ip == 0xffffffff)\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       if (GetInt(hWnd, E_METRIC) == 0)\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       if (IsNetworkAddress32(IpGet(hWnd, E_NETWORK), IpGet(hWnd, E_MASK)) == false)\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, b);\r
+}\r
+\r
+UINT SmL3SwTableDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_L3SW *w = (SM_L3SW *)param;\r
+       RPC_L3TABLE t;\r
+\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmL3SwTableDlgInit(hWnd, w);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_NETWORK:\r
+               case E_MASK:\r
+               case E_GATEWAY:\r
+               case E_METRIC:\r
+                       SmL3SwTableDlgUpdate(hWnd, w);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       Zero(&t, sizeof(t));\r
+                       StrCpy(t.Name, sizeof(t.Name), w->SwitchName);\r
+                       t.NetworkAddress = IpGet(hWnd, E_NETWORK);\r
+                       t.SubnetMask = IpGet(hWnd, E_MASK);\r
+                       t.GatewayAddress = IpGet(hWnd, E_GATEWAY);\r
+                       t.Metric = GetInt(hWnd, E_METRIC);\r
+\r
+                       if (CALL(hWnd, ScAddL3Table(w->s->Rpc, &t)))\r
+                       {\r
+                               EndDialog(hWnd, 1);\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ダイアログ初期化\r
+void SmL3SwIfDlgInit(HWND hWnd, SM_L3SW *w)\r
+{\r
+       RPC_ENUM_HUB t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || w == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       if (CALL(hWnd, ScEnumHub(w->s->Rpc, &t)) == false)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       CbReset(hWnd, E_HUBNAME);\r
+       CbSetHeight(hWnd, E_HUBNAME, 18);\r
+\r
+       for (i = 0;i < t.NumHub;i++)\r
+       {\r
+               RPC_ENUM_HUB_ITEM *e = &t.Hubs[i];\r
+\r
+               if (e->HubType != HUB_TYPE_FARM_DYNAMIC)\r
+               {\r
+                       CbAddStrA(hWnd, E_HUBNAME, e->HubName, 0);\r
+               }\r
+       }\r
+\r
+       FreeRpcEnumHub(&t);\r
+\r
+       SetTextA(hWnd, E_HUBNAME, "");\r
+\r
+       SmL3SwIfDlgUpdate(hWnd, w);\r
+}\r
+\r
+// コントロール更新\r
+void SmL3SwIfDlgUpdate(HWND hWnd, SM_L3SW *w)\r
+{\r
+       bool b = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || w == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsEmpty(hWnd, E_HUBNAME))\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       if (IpIsFilled(hWnd, E_IP) == false || IpIsFilled(hWnd, E_MASK) == false)\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       if (IpGet(hWnd, E_IP) == 0 || IpGet(hWnd, E_IP) == 0xffffffff)\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       if (IsSubnetMask32(IpGet(hWnd, E_MASK)) == false)\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, b);\r
+}\r
+\r
+// 仮想インターフェイスの追加ダイアログ\r
+UINT SmL3SwIfDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_L3SW *w = (SM_L3SW *)param;\r
+       char *hubname;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmL3SwIfDlgInit(hWnd, w);\r
+\r
+               SetTimer(hWnd, 1, 250, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       SmL3SwIfDlgUpdate(hWnd, w);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_HUBNAME:\r
+               case E_IP:\r
+               case E_MASK:\r
+                       SmL3SwIfDlgUpdate(hWnd, w);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       hubname = GetTextA(hWnd, E_HUBNAME);\r
+                       if (hubname != NULL)\r
+                       {\r
+                               RPC_L3IF t;\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.HubName, sizeof(t.HubName), hubname);\r
+                               t.IpAddress = IpGet(hWnd, E_IP);\r
+                               t.SubnetMask = IpGet(hWnd, E_MASK);\r
+                               StrCpy(t.Name, sizeof(t.Name), w->SwitchName);\r
+\r
+                               if (CALL(hWnd, ScAddL3If(w->s->Rpc, &t)))\r
+                               {\r
+                                       EndDialog(hWnd, 1);\r
+                               }\r
+\r
+                               Free(hubname);\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 初期化\r
+void SmL3SwDlgInit(HWND hWnd, SM_L3SW *w)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || w == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_SWITCH_OFFLINE);\r
+\r
+       FormatText(hWnd, 0, w->SwitchName);\r
+\r
+       SetFont(hWnd, S_BOLD1, Font(0, true));\r
+       SetFont(hWnd, S_BOLD2, Font(0, true));\r
+\r
+       LvInit(hWnd, L_IF);\r
+       LvInsertColumn(hWnd, L_IF, 0, _UU("SM_L3_SW_IF_COLUMN1"), 150);\r
+       LvInsertColumn(hWnd, L_IF, 1, _UU("SM_L3_SW_IF_COLUMN2"), 150);\r
+       LvInsertColumn(hWnd, L_IF, 2, _UU("SM_L3_SW_IF_COLUMN3"), 180);\r
+\r
+       LvInit(hWnd, L_TABLE);\r
+       LvInsertColumn(hWnd, L_TABLE, 0, _UU("SM_L3_SW_TABLE_COLUMN1"), 130);\r
+       LvInsertColumn(hWnd, L_TABLE, 1, _UU("SM_L3_SW_TABLE_COLUMN2"), 130);\r
+       LvInsertColumn(hWnd, L_TABLE, 2, _UU("SM_L3_SW_TABLE_COLUMN3"), 130);\r
+       LvInsertColumn(hWnd, L_TABLE, 3, _UU("SM_L3_SW_TABLE_COLUMN4"), 100);\r
+\r
+       w->Enable = SmL3IsSwActive(w->s, w->SwitchName) ? false : true;\r
+\r
+       SmL3SwDlgRefresh(hWnd, w);\r
+}\r
+\r
+// コントロール更新\r
+void SmL3SwDlgUpdate(HWND hWnd, SM_L3SW *w)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || w == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEnable(hWnd, B_ADD_IF, w->s->ServerAdminMode && w->Enable);\r
+       SetEnable(hWnd, B_ADD_TABLE, w->s->ServerAdminMode && w->Enable);\r
+       SetEnable(hWnd, B_DEL_IF, LvIsSingleSelected(hWnd, L_IF) && w->s->ServerAdminMode && w->Enable);\r
+       SetEnable(hWnd, B_DEL_TABLE, LvIsSingleSelected(hWnd, L_TABLE) && w->s->ServerAdminMode && w->Enable);\r
+       SetEnable(hWnd, B_START, w->s->ServerAdminMode && w->Enable);\r
+       SetEnable(hWnd, B_STOP, w->s->ServerAdminMode && (w->Enable == false));\r
+}\r
+\r
+// 内容更新\r
+void SmL3SwDlgRefresh(HWND hWnd, SM_L3SW *w)\r
+{\r
+       UINT i;\r
+       wchar_t tmp1[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       wchar_t tmp3[MAX_SIZE];\r
+       wchar_t tmp4[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || w == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 仮想インターフェイス一覧\r
+       {\r
+               RPC_ENUM_L3IF t;\r
+               LVB *v;\r
+\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.Name, sizeof(t.Name), w->SwitchName);\r
+\r
+               if (CALL(hWnd, ScEnumL3If(w->s->Rpc, &t)) == false)\r
+               {\r
+                       Close(hWnd);\r
+                       return;\r
+               }\r
+\r
+               v = LvInsertStart();\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       RPC_L3IF *e = &t.Items[i];\r
+\r
+                       IPToUniStr32(tmp1, sizeof(tmp1), e->IpAddress);\r
+                       IPToUniStr32(tmp2, sizeof(tmp2), e->SubnetMask);\r
+                       StrToUni(tmp3, sizeof(tmp3), e->HubName);\r
+\r
+                       LvInsertAdd(v, ICO_NIC_ONLINE, NULL, 3, tmp1, tmp2, tmp3);\r
+               }\r
+\r
+               LvReset(hWnd, L_IF);\r
+\r
+               LvInsertEnd(v, hWnd, L_IF);\r
+\r
+               FreeRpcEnumL3If(&t);\r
+       }\r
+\r
+       // ルーティングテーブル一覧\r
+       {\r
+               RPC_ENUM_L3TABLE t;\r
+               LVB *v;\r
+\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(t.Name, sizeof(t.Name), w->SwitchName);\r
+\r
+               if (CALL(hWnd, ScEnumL3Table(w->s->Rpc, &t)) == false)\r
+               {\r
+                       Close(hWnd);\r
+                       return;\r
+               }\r
+\r
+               v = LvInsertStart();\r
+\r
+               for (i = 0;i < t.NumItem;i++)\r
+               {\r
+                       RPC_L3TABLE *e = &t.Items[i];\r
+\r
+                       IPToUniStr32(tmp1, sizeof(tmp1), e->NetworkAddress);\r
+                       IPToUniStr32(tmp2, sizeof(tmp2), e->SubnetMask);\r
+                       IPToUniStr32(tmp3, sizeof(tmp3), e->GatewayAddress);\r
+                       UniToStru(tmp4, e->Metric);\r
+\r
+                       LvInsertAdd(v, ICO_PROTOCOL, NULL, 4, tmp1, tmp2, tmp3, tmp4);\r
+               }\r
+\r
+               LvReset(hWnd, L_TABLE);\r
+\r
+               LvInsertEnd(v, hWnd, L_TABLE);\r
+\r
+               FreeRpcEnumL3Table(&t);\r
+       }\r
+\r
+       SmL3SwDlgUpdate(hWnd, w);\r
+}\r
+\r
+// L3 スイッチの編集ダイアログ\r
+UINT SmL3SwDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_L3SW *w = (SM_L3SW *)param;\r
+       NMHDR *n;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmL3SwDlgInit(hWnd, w);\r
+\r
+               SetTimer(hWnd, 1, 1000, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       w->Enable = SmL3IsSwActive(w->s, w->SwitchName) ? false : true;\r
+                       SmL3SwDlgUpdate(hWnd, w);\r
+                       SetTimer(hWnd, 1, 1000, NULL);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_START:\r
+                       if (IsEnable(hWnd, B_START))\r
+                       {\r
+                               RPC_L3SW t;\r
+\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.Name, sizeof(t.Name), w->SwitchName);\r
+\r
+                               if (CALL(hWnd, ScStartL3Switch(w->s->Rpc, &t)))\r
+                               {\r
+                                       SmL3SwDlgUpdate(hWnd, w);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_STOP:\r
+                       if (IsEnable(hWnd, B_STOP))\r
+                       {\r
+                               RPC_L3SW t;\r
+\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.Name, sizeof(t.Name), w->SwitchName);\r
+\r
+                               if (CALL(hWnd, ScStopL3Switch(w->s->Rpc, &t)))\r
+                               {\r
+                                       SmL3SwDlgUpdate(hWnd, w);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_ADD_IF:\r
+                       if (Dialog(hWnd, D_SM_L3_SW_IF, SmL3SwIfDlg, w))\r
+                       {\r
+                               SmL3SwDlgRefresh(hWnd, w);\r
+                       }\r
+                       break;\r
+\r
+               case B_DEL_IF:\r
+                       if (LvIsSingleSelected(hWnd, L_IF))\r
+                       {\r
+                               RPC_L3IF t;\r
+                               char *tmp1, *tmp2, *tmp3;\r
+\r
+                               tmp1 = LvGetSelectedStrA(hWnd, L_IF, 0);\r
+                               tmp2 = LvGetSelectedStrA(hWnd, L_IF, 1);\r
+                               tmp3 = LvGetSelectedStrA(hWnd, L_IF, 2);\r
+\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.Name, sizeof(t.Name), w->SwitchName);\r
+                               t.IpAddress = StrToIP32(tmp1);\r
+                               t.SubnetMask = StrToIP32(tmp2);\r
+                               StrCpy(t.HubName, sizeof(t.HubName), tmp3);\r
+\r
+                               if (CALL(hWnd, ScDelL3If(w->s->Rpc, &t)))\r
+                               {\r
+                                       SmL3SwDlgRefresh(hWnd, w);\r
+                               }\r
+\r
+                               Free(tmp1);\r
+                               Free(tmp2);\r
+                               Free(tmp3);\r
+                       }\r
+                       break;\r
+\r
+               case B_ADD_TABLE:\r
+                       if (Dialog(hWnd, D_SM_L3_SW_TABLE, SmL3SwTableDlg, w))\r
+                       {\r
+                               SmL3SwDlgRefresh(hWnd, w);\r
+                       }\r
+                       break;\r
+\r
+               case B_DEL_TABLE:\r
+                       if (LvIsSingleSelected(hWnd, L_TABLE))\r
+                       {\r
+                               RPC_L3TABLE t;\r
+                               char *tmp1, *tmp2, *tmp3, *tmp4;\r
+\r
+                               tmp1 = LvGetSelectedStrA(hWnd, L_TABLE, 0);\r
+                               tmp2 = LvGetSelectedStrA(hWnd, L_TABLE, 1);\r
+                               tmp3 = LvGetSelectedStrA(hWnd, L_TABLE, 2);\r
+                               tmp4 = LvGetSelectedStrA(hWnd, L_TABLE, 3);\r
+\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.Name, sizeof(t.Name), w->SwitchName);\r
+                               t.NetworkAddress = StrToIP32(tmp1);\r
+                               t.SubnetMask = StrToIP32(tmp2);\r
+                               t.GatewayAddress = StrToIP32(tmp3);\r
+                               t.Metric = ToInt(tmp4);\r
+\r
+                               if (CALL(hWnd, ScDelL3Table(w->s->Rpc, &t)))\r
+                               {\r
+                                       SmL3SwDlgRefresh(hWnd, w);\r
+                               }\r
+\r
+                               Free(tmp1);\r
+                               Free(tmp2);\r
+                               Free(tmp3);\r
+                               Free(tmp4);\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_IF:\r
+               case L_TABLE:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmL3SwDlgUpdate(hWnd, w);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// コントロール更新\r
+void SmL3AddDlgUpdate(HWND hWnd, SM_SERVER *s)\r
+{\r
+       char *tmp;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tmp = GetTextA(hWnd, E_NAME);\r
+\r
+       SetEnable(hWnd, IDOK, IsEmptyStr(tmp) == false && IsSafeStr(tmp));\r
+\r
+       Free(tmp);\r
+}\r
+\r
+// 新しい L3 スイッチの作成ダイアログ\r
+UINT SmL3AddDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SERVER *s = (SM_SERVER *)param;\r
+       RPC_L3SW t;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               LimitText(hWnd, E_NAME, MAX_HUBNAME_LEN);\r
+               SmL3AddDlgUpdate(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_NAME:\r
+                       SmL3AddDlgUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       Zero(&t, sizeof(t));\r
+                       GetTxtA(hWnd, E_NAME, t.Name, sizeof(t.Name));\r
+                       if (CALL(hWnd, ScAddL3Switch(s->Rpc, &t)))\r
+                       {\r
+                               EndDialog(hWnd, 1);\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ダイアログ初期化\r
+void SmL3DlgInit(HWND hWnd, SM_SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetFont(hWnd, S_BOLD, Font(0, true));\r
+\r
+       SetIcon(hWnd, 0, ICO_SWITCH);\r
+\r
+       LvInit(hWnd, L_LIST);\r
+       LvInsertColumn(hWnd, L_LIST, 0, _UU("SM_L3_SW_COLUMN1"), 150);\r
+       LvInsertColumn(hWnd, L_LIST, 1, _UU("SM_L3_SW_COLUMN2"), 120);\r
+       LvInsertColumn(hWnd, L_LIST, 2, _UU("SM_L3_SW_COLUMN3"), 100);\r
+       LvInsertColumn(hWnd, L_LIST, 3, _UU("SM_L3_SW_COLUMN4"), 100);\r
+\r
+       SmL3DlgRefresh(hWnd, s);\r
+}\r
+\r
+// ダイアログコントロール更新\r
+void SmL3DlgUpdate(HWND hWnd, SM_SERVER *s)\r
+{\r
+       bool b = false;\r
+       bool active = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSingleSelected(hWnd, L_LIST))\r
+       {\r
+               wchar_t *tmp;\r
+               UINT i;\r
+               b = true;\r
+               i = LvGetSelected(hWnd, L_LIST);\r
+               if (i != INFINITE)\r
+               {\r
+                       tmp = LvGetStr(hWnd, L_LIST, i, 1);\r
+                       if (UniStrCmpi(tmp, _UU("SM_L3_SW_ST_F_F")) != 0)\r
+                       {\r
+                               active = true;\r
+                       }\r
+                       Free(tmp);\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, B_START, b && (active == false));\r
+       SetEnable(hWnd, B_STOP, b && (active != false));\r
+       SetEnable(hWnd, IDOK, b);\r
+       SetEnable(hWnd, B_DELETE, b);\r
+}\r
+\r
+// ダイアログ内容更新\r
+void SmL3DlgRefresh(HWND hWnd, SM_SERVER *s)\r
+{\r
+       RPC_ENUM_L3SW t;\r
+       UINT i;\r
+       LVB *v;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CALL(hWnd, ScEnumL3Switch(s->Rpc, &t)) == false)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       v = LvInsertStart();\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               RPC_ENUM_L3SW_ITEM *e = &t.Items[i];\r
+               wchar_t tmp1[MAX_SIZE], *tmp2, tmp3[64], tmp4[64];\r
+\r
+               StrToUni(tmp1, sizeof(tmp1), e->Name);\r
+               if (e->Active == false)\r
+               {\r
+                       tmp2 = _UU("SM_L3_SW_ST_F_F");\r
+               }\r
+               else if (e->Online == false)\r
+               {\r
+                       tmp2 = _UU("SM_L3_SW_ST_T_F");\r
+               }\r
+               else\r
+               {\r
+                       tmp2 = _UU("SM_L3_SW_ST_T_T");\r
+               }\r
+               UniToStru(tmp3, e->NumInterfaces);\r
+               UniToStru(tmp4, e->NumTables);\r
+\r
+               LvInsertAdd(v, e->Active ? ICO_SWITCH : ICO_SWITCH_OFFLINE, NULL,\r
+                       4, tmp1, tmp2, tmp3, tmp4);\r
+       }\r
+\r
+       LvInsertEnd(v, hWnd, L_LIST);\r
+\r
+       FreeRpcEnumL3Sw(&t);\r
+\r
+       SmL3DlgUpdate(hWnd, s);\r
+}\r
+\r
+// L3 ダイアログプロシージャ\r
+UINT SmL3Dlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       NMHDR *n;\r
+       SM_SERVER *s = (SM_SERVER *)param;\r
+       RPC_L3SW t;\r
+       char *name;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmL3DlgInit(hWnd, s);\r
+\r
+               SetTimer(hWnd, 1, 1000, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               KillTimer(hWnd, 1);\r
+               SmL3DlgRefresh(hWnd, s);\r
+               SetTimer(hWnd, 1, 1000, NULL);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_ADD:\r
+                       // 追加\r
+                       if (Dialog(hWnd, D_SM_L3_ADD, SmL3AddDlg, s))\r
+                       {\r
+                               SmL3DlgRefresh(hWnd, s);\r
+                       }\r
+                       break;\r
+\r
+               case B_START:\r
+                       // 動作開始\r
+                       name = LvGetSelectedStrA(hWnd, L_LIST, 0);\r
+                       if (name != NULL)\r
+                       {\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.Name, sizeof(t.Name), name);\r
+\r
+                               if (CALL(hWnd, ScStartL3Switch(s->Rpc, &t)))\r
+                               {\r
+                                       SmL3DlgRefresh(hWnd, s);\r
+                               }\r
+\r
+                               Free(name);\r
+                       }\r
+                       break;\r
+\r
+               case B_STOP:\r
+                       // 動作停止\r
+                       name = LvGetSelectedStrA(hWnd, L_LIST, 0);\r
+                       if (name != NULL)\r
+                       {\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.Name, sizeof(t.Name), name);\r
+\r
+                               if (CALL(hWnd, ScStopL3Switch(s->Rpc, &t)))\r
+                               {\r
+                                       SmL3DlgRefresh(hWnd, s);\r
+                               }\r
+\r
+                               Free(name);\r
+                       }\r
+                       break;\r
+\r
+               case IDOK:\r
+                       // 編集\r
+                       if (IsEnable(hWnd, IDOK))\r
+                       {\r
+                               name = LvGetSelectedStrA(hWnd, L_LIST, 0);\r
+                               if (name != NULL)\r
+                               {\r
+                                       SM_L3SW w;\r
+                                       Zero(&w, sizeof(w));\r
+                                       w.s = s;\r
+                                       w.SwitchName = name;\r
+\r
+                                       Dialog(hWnd, D_SM_L3_SW, SmL3SwDlg, &w);\r
+\r
+                                       Free(name);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       // 削除\r
+                       name = LvGetSelectedStrA(hWnd, L_LIST, 0);\r
+                       if (name != NULL)\r
+                       {\r
+                               if (MsgBoxEx(hWnd, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2,\r
+                                       _UU("SM_L3_SW_DEL_MSG"), name) == IDYES)\r
+                               {\r
+                                       Zero(&t, sizeof(t));\r
+                                       StrCpy(t.Name, sizeof(t.Name), name);\r
+\r
+                                       if (CALL(hWnd, ScDelL3Switch(s->Rpc, &t)))\r
+                                       {\r
+                                               SmL3DlgRefresh(hWnd, s);\r
+                                       }\r
+                               }\r
+\r
+                               Free(name);\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // 閉じる\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_LIST:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmL3DlgUpdate(hWnd, s);\r
+                               break;\r
+\r
+                       case NM_DBLCLK:\r
+                               Command(hWnd, IDOK);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// L3 ダイアログ\r
+void SmL3(HWND hWnd, SM_SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_SM_L3, SmL3Dlg, s);\r
+}\r
+\r
+// 管理オプション値用ダイアログ\r
+UINT SmHubAdminOptionValueDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_EDIT_AO *a = (SM_EDIT_AO *)param;\r
+       UINT i;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               CbReset(hWnd, C_NAME);\r
+               for (i = 0;i < a->DefaultOptions.NumItem;i++)\r
+               {\r
+                       wchar_t tmp[MAX_PATH];\r
+                       StrToUni(tmp, sizeof(tmp), a->DefaultOptions.Items[i].Name);\r
+                       CbAddStr(hWnd, C_NAME, tmp, 0);\r
+               }\r
+               if (a->NewMode == false)\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+\r
+                       SetTextA(hWnd, C_NAME, a->Name);\r
+                       ToStr(tmp, a->Value);\r
+\r
+                       SetTextA(hWnd, E_VALUE, tmp);\r
+               }\r
+               else\r
+               {\r
+                       SetTextA(hWnd, C_NAME, "");\r
+               }\r
+               SmHubAdminOptionValueDlgUpdate(hWnd, a);\r
+               if (a->NewMode == false)\r
+               {\r
+                       FocusEx(hWnd, E_VALUE);\r
+                       Disable(hWnd, C_NAME);\r
+               }\r
+               else\r
+               {\r
+                       FocusEx(hWnd, C_NAME);\r
+               }\r
+\r
+               SetTimer(hWnd, 1, 100, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               SmHubAdminOptionValueDlgUpdate(hWnd, a);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       if (a->NewMode)\r
+                       {\r
+                               GetTxtA(hWnd, C_NAME, a->Name, sizeof(a->Name));\r
+                       }\r
+\r
+                       GetTxtA(hWnd, E_VALUE, tmp, sizeof(tmp));\r
+                       a->Value = ToInt(tmp);\r
+\r
+                       Trim(a->Name);\r
+\r
+                       if (StartWith(a->Name, "no") || StartWith(a->Name, "allow") || StartWith(a->Name, "deny")\r
+                                || StartWith(a->Name, "filter") || StartWith(a->Name, "fix") || StartWith(a->Name, "force")\r
+                                || StartWith(a->Name, "use") || StartWith(a->Name, "b_") || StartWith(a->Name, "is")\r
+                                || StartWith(a->Name, "manage") || StartWith(a->Name, "yield")\r
+                                || StartWith(a->Name, "permit") || StartWith(a->Name, "yes") || StartWith(a->Name, "ok")\r
+                                || StartWith(a->Name, "do") || StartWith(a->Name, "only") || StartWith(a->Name, "disable"))\r
+                       {\r
+                               if (StrCmpi(tmp, "0") != 0 && StrCmpi(tmp, "1") != 0)\r
+                               {\r
+                                       MsgBox(hWnd, MB_ICONEXCLAMATION, _UU("SM_TRUE_OR_FALSE"));\r
+                                       FocusEx(hWnd, E_VALUE);\r
+                                       break;\r
+                               }\r
+                       }\r
+\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+\r
+               SmHubAdminOptionValueDlgUpdate(hWnd, a);\r
+\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 管理オプション値用ダイアログ コントロール更新\r
+void SmHubAdminOptionValueDlgUpdate(HWND hWnd, SM_EDIT_AO *a)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetTxtA(hWnd, C_NAME, tmp, sizeof(tmp));\r
+\r
+       SetEnable(hWnd, IDOK, IsEmpty(hWnd, C_NAME) == false && IsEmpty(hWnd, E_VALUE) == false &&\r
+               IsSafeStr(tmp));\r
+}\r
+\r
+// 初期化\r
+void SmHubAdminOptionDlgInit(HWND hWnd, SM_EDIT_AO *a)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_USER_ADMIN);\r
+\r
+       if (a->e->p->ServerAdminMode)\r
+       {\r
+               a->CanChange = true;\r
+       }\r
+       else\r
+       {\r
+               if (a->ExtOption == false)\r
+               {\r
+                       for (i = 0;i < a->CurrentOptions.NumItem;i++)\r
+                       {\r
+                               if (StrCmpi(a->CurrentOptions.Items[i].Name, "allow_hub_admin_change_option") == 0)\r
+                               {\r
+                                       if (a->CurrentOptions.Items[i].Value != 0)\r
+                                       {\r
+                                               a->CanChange = true;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       a->CanChange = true;\r
+               }\r
+       }\r
+\r
+       FormatText(hWnd, S_INFO, a->e->HubName);\r
+\r
+       DlgFont(hWnd, S_BOLD, 0, true);\r
+\r
+       LvInit(hWnd, L_LIST);\r
+       LvInsertColumn(hWnd, L_LIST, 0, _UU("SM_AO_COLUMN_1"), 260);\r
+       LvInsertColumn(hWnd, L_LIST, 1, _UU("SM_AO_COLUMN_2"), 100);\r
+\r
+       for (i = 0;i < a->CurrentOptions.NumItem;i++)\r
+       {\r
+               ADMIN_OPTION *e = &a->CurrentOptions.Items[i];\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+\r
+               StrToUni(tmp1, sizeof(tmp1), e->Name);\r
+               UniToStru(tmp2, e->Value);\r
+\r
+               LvInsert(hWnd, L_LIST, ICO_LOG, NULL, 2, tmp1, tmp2);\r
+                       \r
+       }\r
+\r
+       if (a->ExtOption)\r
+       {\r
+               SetIcon(hWnd, S_ICON, ICO_LINK2);\r
+               SetIcon(hWnd, 0, ICO_LINK2);\r
+\r
+               SetText(hWnd, 0, _UU("SM_HUBEXT_OPTION_TITLE"));\r
+               SetText(hWnd, S_STATIC1, _UU("SM_HUBEXT_OPTION_STATIC1"));\r
+               SetText(hWnd, S_STATIC2, _UU("SM_HUBEXT_OPTION_STATIC2"));\r
+       }\r
+\r
+       // コントロール更新\r
+       SmHubAdminOptionDlgUpdate(hWnd, a);\r
+}\r
+\r
+// コントロール更新\r
+void SmHubAdminOptionDlgUpdate(HWND hWnd, SM_EDIT_AO *a)\r
+{\r
+       bool b = false;\r
+       wchar_t *helpstr;\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       helpstr = _UU("HUB_AO_CLICK");\r
+\r
+       SetEnable(hWnd, IDOK, a->CanChange);\r
+       SetEnable(hWnd, B_ADD, a->CanChange);\r
+       SetEnable(hWnd, B_EDIT, a->CanChange && (LvIsMasked(hWnd, L_LIST) && LvIsMultiMasked(hWnd, L_LIST) == false));\r
+\r
+       if (LvIsMasked(hWnd, L_LIST) && LvIsMultiMasked(hWnd, L_LIST) == false)\r
+       {\r
+               UINT i;\r
+               i = LvGetSelected(hWnd, L_LIST);\r
+\r
+               if (a->CanChange)\r
+               {\r
+\r
+                       b = true;\r
+\r
+                       if (i != INFINITE)\r
+                       {\r
+                               char *name = LvGetStrA(hWnd, L_LIST, i, 0);\r
+                               if (name != NULL)\r
+                               {\r
+                                       UINT j;\r
+\r
+                                       for (j = 0;j < a->DefaultOptions.NumItem;j++)\r
+                                       {\r
+                                               if (StrCmpi(a->DefaultOptions.Items[j].Name, name) == 0)\r
+                                               {\r
+                                                       b = false;\r
+                                               }\r
+                                       }\r
+                                       Free(name);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (i != INFINITE)\r
+               {\r
+                       char *name = LvGetStrA(hWnd, L_LIST, i, 0);\r
+                       if (name != NULL)\r
+                       {\r
+                               helpstr = GetHubAdminOptionHelpString(name);\r
+                       }\r
+                       Free(name);\r
+               }\r
+       }\r
+       SetEnable(hWnd, B_DELETE, b);\r
+\r
+       SetText(hWnd, E_HELP, helpstr);\r
+}\r
+\r
+// 保存\r
+void SmHubAdminOptionDlgOk(HWND hWnd, SM_EDIT_AO *a)\r
+{\r
+       UINT i, num;\r
+       RPC_ADMIN_OPTION t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       num = LvNum(hWnd, L_LIST);\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), a->e->HubName);\r
+       t.NumItem = num;\r
+       t.Items = ZeroMalloc(sizeof(ADMIN_OPTION) * num);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               char *name = LvGetStrA(hWnd, L_LIST, i, 0);\r
+               char *s_value = LvGetStrA(hWnd, L_LIST, i, 1);\r
+               ADMIN_OPTION *a = &t.Items[i];\r
+\r
+               StrCpy(a->Name, sizeof(a->Name), name);\r
+               a->Value = ToInt(s_value);\r
+\r
+               Free(name);\r
+               Free(s_value);\r
+       }\r
+\r
+       if (a->ExtOption == false)\r
+       {\r
+               if (CALL(hWnd, ScSetHubAdminOptions(a->e->p->Rpc, &t)))\r
+               {\r
+                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_AO_SET_OK"));\r
+                       EndDialog(hWnd, true);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (CALL(hWnd, ScSetHubExtOptions(a->e->p->Rpc, &t)))\r
+               {\r
+                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_EXT_OPTION_SET_OK"));\r
+                       EndDialog(hWnd, true);\r
+               }\r
+       }\r
+\r
+       FreeRpcAdminOption(&t);\r
+}\r
+\r
+// 仮想 HUB 管理オプションダイアログ\r
+UINT SmHubAdminOptionDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_EDIT_AO *a = (SM_EDIT_AO *)param;\r
+       NMHDR *n;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmHubAdminOptionDlgInit(hWnd, a);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_ADD:\r
+                       a->NewMode = true;\r
+                       StrCpy(a->Name, sizeof(a->Name), "");\r
+                       a->Value = 0;\r
+                       if (Dialog(hWnd, D_SM_AO_VALUE, SmHubAdminOptionValueDlg,\r
+                               a))\r
+                       {\r
+                               wchar_t tmp1[MAX_SIZE];\r
+                               wchar_t tmp2[MAX_SIZE];\r
+                               StrToUni(tmp1, sizeof(tmp1), a->Name);\r
+                               UniToStru(tmp2, a->Value);\r
+\r
+                               LvInsert(hWnd, L_LIST, ICO_LOG, NULL, 2, tmp1, tmp2);\r
+                       }\r
+                       break;\r
+\r
+               case B_EDIT:\r
+                       i = LvGetSelected(hWnd, L_LIST);\r
+                       if (i != INFINITE && a->CanChange)\r
+                       {\r
+                               char *name, *value;\r
+                               name = LvGetStrA(hWnd, L_LIST, i, 0);\r
+                               value = LvGetStrA(hWnd, L_LIST, i, 1);\r
+                               a->NewMode = false;\r
+                               StrCpy(a->Name, sizeof(a->Name), name);\r
+                               a->Value = ToInt(value);\r
+\r
+                               if (Dialog(hWnd, D_SM_AO_VALUE, SmHubAdminOptionValueDlg,\r
+                                       a))\r
+                               {\r
+                                       char tmp[MAX_PATH];\r
+                                       ToStr(tmp, a->Value);\r
+                                       LvSetItemA(hWnd, L_LIST, i, 1, tmp);\r
+                               }\r
+\r
+                               Free(name);\r
+                               Free(value);\r
+                       }\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       i = LvGetSelected(hWnd, L_LIST);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               LvDeleteItem(hWnd, L_LIST, i);\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case IDOK:\r
+                       SmHubAdminOptionDlgOk(hWnd, a);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_LIST:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmHubAdminOptionDlgUpdate(hWnd, a);\r
+                               break;\r
+\r
+                       case NM_DBLCLK:\r
+                               Command(hWnd, B_EDIT);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 HUB 拡張オプション\r
+void SmHubExtOption(HWND hWnd, SM_EDIT_HUB *e)\r
+{\r
+       SM_EDIT_AO a;\r
+       // 引数チェック\r
+       if (hWnd == NULL || e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&a, sizeof(a));\r
+       a.e = e;\r
+       a.ExtOption = true;\r
+\r
+       StrCpy(a.CurrentOptions.HubName, sizeof(a.CurrentOptions.HubName), e->HubName);\r
+\r
+       // 現在のサーバー上のオプションを取得する\r
+       if (CALL(hWnd, ScGetHubExtOptions(e->p->Rpc, &a.CurrentOptions)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_SM_ADMIN_OPTION, SmHubAdminOptionDlg, &a);\r
+\r
+       FreeRpcAdminOption(&a.CurrentOptions);\r
+       FreeRpcAdminOption(&a.DefaultOptions);\r
+}\r
+\r
+// 仮想 HUB 管理オプション\r
+void SmHubAdminOption(HWND hWnd, SM_EDIT_HUB *e)\r
+{\r
+       SM_EDIT_AO a;\r
+       // 引数チェック\r
+       if (hWnd == NULL || e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&a, sizeof(a));\r
+       a.e = e;\r
+\r
+       StrCpy(a.CurrentOptions.HubName, sizeof(a.CurrentOptions.HubName), e->HubName);\r
+\r
+       // 現在のサーバー上のオプションを取得する\r
+       if (CALL(hWnd, ScGetHubAdminOptions(e->p->Rpc, &a.CurrentOptions)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ScGetDefaultHubAdminOptions(e->p->Rpc, &a.DefaultOptions);\r
+\r
+       Dialog(hWnd, D_SM_ADMIN_OPTION, SmHubAdminOptionDlg, &a);\r
+\r
+       FreeRpcAdminOption(&a.CurrentOptions);\r
+       FreeRpcAdminOption(&a.DefaultOptions);\r
+}\r
+\r
+// 初期化\r
+void SmConfigDlgInit(HWND hWnd, SM_CONFIG *c)\r
+{\r
+       wchar_t *tmp;\r
+       UINT tmp_size;\r
+       // 引数チェック\r
+       if (hWnd == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Focus(hWnd, IDCANCEL);\r
+\r
+       SetIcon(hWnd, 0, ICO_MACHINE);\r
+\r
+       SetFont(hWnd, E_CONFIG, GetFont(_SS("DEFAULT_FONT_2"), 0, false, false,\r
+               false, false));\r
+\r
+       FormatText(hWnd, IDC_INFO, c->s->ServerName);\r
+\r
+       // UTF-8 から Unicode に変換\r
+       tmp_size = CalcUtf8ToUni(c->Config.FileData, StrLen(c->Config.FileData)) + 1;\r
+       tmp = ZeroMalloc(tmp_size);\r
+       Utf8ToUni(tmp, tmp_size, c->Config.FileData, StrLen(c->Config.FileData));\r
+\r
+       SetText(hWnd, E_CONFIG, tmp);\r
+\r
+       Free(tmp);\r
+}\r
+\r
+// config 編集ダイアログ\r
+UINT SmConfigDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_CONFIG *c = (SM_CONFIG *)param;\r
+       char *filename;\r
+       wchar_t *filename_unicode;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmConfigDlgInit(hWnd, c);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_EXPORT:\r
+                       StrToUni(tmp, sizeof(tmp), c->Config.FileName);\r
+                       filename_unicode = SaveDlg(hWnd, _UU("DLG_CONFIG_FILES"), _UU("DLG_SAVE_CONFIG"), tmp, L".config");\r
+                       if (filename_unicode != NULL)\r
+                       {\r
+                               BUF *b = NewBuf();\r
+                               filename = CopyUniToStr(filename_unicode);\r
+                               WriteBuf(b, c->Config.FileData, StrLen(c->Config.FileData));\r
+                               if (DumpBuf(b, filename))\r
+                               {\r
+                                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_CONFIG_SAVED"));\r
+                               }\r
+                               else\r
+                               {\r
+                                       MsgBox(hWnd, MB_ICONSTOP, _UU("SM_CONFIG_SAVE_FAILED"));\r
+                               }\r
+                               FreeBuf(b);\r
+                               Free(filename);\r
+                               Free(filename_unicode);\r
+                       }\r
+                       break;\r
+\r
+               case B_IMPORT:\r
+                       filename_unicode = OpenDlg(hWnd, _UU("DLG_CONFIG_FILES"), _UU("DLG_OPEN_CONFIG"));\r
+                       if (filename_unicode != NULL)\r
+                       {\r
+                               BUF *b;\r
+                               filename = CopyUniToStr(filename_unicode);\r
+                               b = ReadDump(filename);\r
+                               if (b != NULL)\r
+                               {\r
+                                       RPC_CONFIG t;\r
+\r
+                                       if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("SM_CONFIG_CONFIRM")) == IDYES)\r
+                                       {\r
+                                               Zero(&t, sizeof(t));\r
+                                               t.FileData = ZeroMalloc(b->Size + 1);\r
+                                               Copy(t.FileData, b->Buf, b->Size);\r
+\r
+                                               if (CALL(hWnd, ScSetConfig(c->s->Rpc, &t)))\r
+                                               {\r
+                                                       // 成功\r
+                                                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_CONFIG_WRITE_OK"));\r
+                                                       _exit(0);\r
+                                               }\r
+\r
+                                               FreeRpcConfig(&t);\r
+\r
+                                               FreeRpcConfig(&t);\r
+                                               FreeBuf(b);\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       MsgBox(hWnd, MB_ICONSTOP, _UU("SM_CONFIG_OPEN_FAILED"));\r
+                               }\r
+                               Free(filename);\r
+                               Free(filename_unicode);\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// config 編集ダイアログを表示する\r
+void SmConfig(HWND hWnd, SM_SERVER *s)\r
+{\r
+       SM_CONFIG c;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&c, sizeof(c));\r
+\r
+       c.s = s;\r
+\r
+       // 現在の config をサーバーから取得\r
+       if (CALL(hWnd, ScGetConfig(s->Rpc, &c.Config)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ダイアログ表示\r
+       Dialog(hWnd, D_SM_CONFIG, SmConfigDlg, &c);\r
+\r
+       // 解放\r
+       FreeRpcConfig(&c.Config);\r
+}\r
+\r
+// ブリッジダイアログ初期化\r
+void SmBridgeDlgInit(HWND hWnd, SM_SERVER *s)\r
+{\r
+       UINT i;\r
+       RPC_ENUM_ETH t;\r
+       RPC_SERVER_INFO si;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LvInit(hWnd, L_LIST);\r
+       LvInsertColumn(hWnd, L_LIST, 0, _UU("SM_BRIDGE_COLUMN_1"), 50);\r
+       LvInsertColumn(hWnd, L_LIST, 1, _UU("SM_BRIDGE_COLUMN_2"), 145);\r
+       LvInsertColumn(hWnd, L_LIST, 2, _UU("SM_BRIDGE_COLUMN_3"), 300);\r
+       LvInsertColumn(hWnd, L_LIST, 3, _UU("SM_BRIDGE_COLUMN_4"), 100);\r
+\r
+       SmBridgeDlgRefresh(hWnd, s);\r
+\r
+       SetShow(hWnd, B_VLAN, GetCapsBool(s->CapsList, "b_support_eth_vlan"));\r
+\r
+       SetIcon(hWnd, 0, ICO_BRIDGE);\r
+\r
+       // サーバー情報を取得\r
+       Zero(&si, sizeof(si));\r
+       ScGetServerInfo(s->Rpc, &si);\r
+       if (GetCapsBool(s->CapsList, "b_tap_supported") == false)\r
+       {\r
+               // tap はサポートしていない\r
+               Hide(hWnd, R_TAP);\r
+               Hide(hWnd, S_TAP_1);\r
+               Hide(hWnd, E_TAPNAME);\r
+               Hide(hWnd, S_TAP_2);\r
+               Hide(hWnd, R_BRIDGE);\r
+               Hide(hWnd, S_STATIC5);\r
+       }\r
+       Check(hWnd, R_BRIDGE, true);\r
+       FreeRpcServerInfo(&si);\r
+\r
+       // Ethernet 列挙\r
+       Zero(&t, sizeof(t));\r
+       ScEnumEthernet(s->Rpc, &t);\r
+\r
+       CbReset(hWnd, E_NICNAME);\r
+       CbSetHeight(hWnd, E_NICNAME, 18);\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               RPC_ENUM_ETH_ITEM *e = &t.Items[i];\r
+               if(UniIsEmptyStr(e->NetworkConnectionName) == false)\r
+               {\r
+                       wchar_t ncname[MAX_SIZE * 2];\r
+                       UniFormat(ncname, sizeof(ncname), BRIDGE_NETWORK_CONNECTION_STR, e->NetworkConnectionName, e->DeviceName);\r
+                       CbAddStr(hWnd, E_NICNAME, ncname, 0);\r
+               }\r
+               else\r
+               {\r
+                       wchar_t *s = CopyStrToUni(e->DeviceName);\r
+                       CbAddStr(hWnd, E_NICNAME, s, 0);\r
+                       Free(s);\r
+               }\r
+       }\r
+\r
+       FreeRpcEnumEth(&t);\r
+\r
+       // 仮想 HUB 列挙\r
+       {\r
+               RPC_ENUM_HUB t;\r
+               Zero(&t, sizeof(t));\r
+\r
+               ScEnumHub(s->Rpc, &t);\r
+\r
+               CbReset(hWnd, E_HUBNAME);\r
+               CbSetHeight(hWnd, E_HUBNAME, 18);\r
+\r
+               for (i = 0;i < t.NumHub;i++)\r
+               {\r
+                       RPC_ENUM_HUB_ITEM *e = &t.Hubs[i];\r
+                       wchar_t *s = CopyStrToUni(e->HubName);\r
+\r
+                       if (e->HubType != HUB_TYPE_FARM_DYNAMIC)\r
+                       {\r
+                               CbAddStr(hWnd, E_HUBNAME, s, 0);\r
+                       }\r
+                       Free(s);\r
+               }\r
+\r
+               SetText(hWnd, E_HUBNAME, L"");\r
+\r
+               FreeRpcEnumHub(&t);\r
+       }\r
+\r
+       if (s->Bridge)\r
+       {\r
+               SetTextA(hWnd, E_HUBNAME, "BRIDGE");\r
+       }\r
+\r
+       Focus(hWnd, E_HUBNAME);\r
+       \r
+       SmBridgeDlgUpdate(hWnd, s);\r
+\r
+       SetTimer(hWnd, 1, 1000, NULL);\r
+}\r
+\r
+// ブリッジダイアログコントロール更新\r
+void SmBridgeDlgUpdate(HWND hWnd, SM_SERVER *s)\r
+{\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsMasked(hWnd, L_LIST) && LvIsMultiMasked(hWnd, L_LIST) == false)\r
+       {\r
+               Enable(hWnd, B_DELETE);\r
+       }\r
+       else\r
+       {\r
+               Disable(hWnd, B_DELETE);\r
+       }\r
+\r
+       if (IsEmpty(hWnd, E_HUBNAME))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_TAP) == false)\r
+       {\r
+               // ブリッジモード\r
+               Enable(hWnd, S_ETH_1);\r
+               Enable(hWnd, E_NICNAME);\r
+               Disable(hWnd, S_TAP_1);\r
+               Disable(hWnd, S_TAP_2);\r
+               Disable(hWnd, E_TAPNAME);\r
+               SetText(hWnd, S_INFO, _UU("SM_BRIDGE_INFO_1"));\r
+               SetIcon(hWnd, S_ICON, ICO_NIC_ONLINE);\r
+               if (IsEmpty(hWnd, E_NICNAME))\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               // tap モード\r
+               Disable(hWnd, S_ETH_1);\r
+               Disable(hWnd, E_NICNAME);\r
+               Enable(hWnd, S_TAP_1);\r
+               Enable(hWnd, S_TAP_2);\r
+               Enable(hWnd, E_TAPNAME);\r
+               SetText(hWnd, S_INFO, _UU("SM_BRIDGE_INFO_2"));\r
+               SetIcon(hWnd, S_ICON, ICO_PROTOCOL);\r
+               GetTxtA(hWnd, E_TAPNAME, tmp, sizeof(tmp));\r
+               if (IsEmptyStr(tmp))\r
+               {\r
+                       ok = false;\r
+               }\r
+               else\r
+               {\r
+                       if (IsSafeStr(tmp) == false)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+                       if (StrLen(tmp) >= 12)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// ブリッジダイアログ更新\r
+void SmBridgeDlgRefresh(HWND hWnd, SM_SERVER *s)\r
+{\r
+       LVB *lvb;\r
+       RPC_ENUM_LOCALBRIDGE t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       lvb = LvInsertStart();\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       ScEnumLocalBridge(s->Rpc, &t);\r
+\r
+       for (i = 0;i < t.NumItem;i++)\r
+       {\r
+               RPC_LOCALBRIDGE *e = &t.Items[i];\r
+               wchar_t name[MAX_SIZE];\r
+               wchar_t nic[MAX_SIZE];\r
+               wchar_t hub[MAX_SIZE];\r
+               wchar_t *status = _UU("SM_BRIDGE_OFFLINE");\r
+\r
+               UniToStru(name, i + 1);\r
+               StrToUni(nic, sizeof(nic), e->DeviceName);\r
+               StrToUni(hub, sizeof(hub), e->HubName);\r
+\r
+               if (e->Online)\r
+               {\r
+                       status = e->Active ? _UU("SM_BRIDGE_ONLINE") : _UU("SM_BRIDGE_ERROR");\r
+               }\r
+\r
+               LvInsertAdd(lvb, e->TapMode == false ? (e->Active ? ICO_NIC_ONLINE : ICO_NIC_OFFLINE) : ICO_PROTOCOL,\r
+                       NULL, 4, name, hub, nic, status);\r
+       }\r
+\r
+       FreeRpcEnumLocalBridge(&t);\r
+\r
+       LvInsertEnd(lvb, hWnd, L_LIST);\r
+\r
+       SmBridgeDlgUpdate(hWnd, s);\r
+}\r
+\r
+// ローカルブリッジの追加\r
+void SmBridgeDlgOnOk(HWND hWnd, SM_SERVER *s)\r
+{\r
+       char nic[MAX_SIZE];\r
+       char hub[MAX_SIZE];\r
+       RPC_LOCALBRIDGE t;\r
+       bool tapmode = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetTxtA(hWnd, E_HUBNAME, hub, sizeof(hub));\r
+\r
+       Zero(nic, sizeof(nic));\r
+\r
+       if (IsChecked(hWnd, R_TAP) == false)\r
+       {\r
+               wchar_t nctmp[MAX_SIZE * 2];\r
+               if(GetCapsBool(s->CapsList, "b_support_network_connection_name") && GetTxt(hWnd, E_NICNAME, nctmp, sizeof(nctmp)))\r
+               {\r
+                       RPC_ENUM_ETH et;\r
+                       UINT i;\r
+                       Zero(&et, sizeof(et));\r
+                       ScEnumEthernet(s->Rpc, &et);\r
+                       for(i = 0; i < et.NumItem; i++)\r
+                       {\r
+                               RPC_ENUM_ETH_ITEM *e = &et.Items[i];\r
+                               if(UniIsEmptyStr(e->NetworkConnectionName) == false)\r
+                               {\r
+                                       wchar_t ncname[MAX_SIZE * 2];\r
+                                       UniFormat(ncname, sizeof(ncname), BRIDGE_NETWORK_CONNECTION_STR, e->NetworkConnectionName, e->DeviceName);\r
+                                       if(UniStrCmp(ncname, nctmp) == 0)\r
+                                       {\r
+                                               StrCpy(nic, sizeof(nic), e->DeviceName);\r
+                                               break;\r
+                                       }\r
+                               }               \r
+                       }\r
+                       FreeRpcEnumEth(&et);\r
+\r
+                       if (IsEmptyStr(nic))\r
+                       {\r
+                               GetTxtA(hWnd, E_NICNAME, nic, sizeof(nic));\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       GetTxtA(hWnd, E_NICNAME, nic, sizeof(nic));\r
+               }\r
+       }\r
+       else\r
+       {\r
+               tapmode = true;\r
+               GetTxtA(hWnd, E_TAPNAME, nic, sizeof(nic));\r
+       }\r
+\r
+       Trim(hub);\r
+       Trim(nic);\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.DeviceName, sizeof(t.DeviceName), nic);\r
+       StrCpy(t.HubName, sizeof(t.HubName), hub);\r
+       t.TapMode = tapmode;\r
+\r
+       if (InStrEx(t.DeviceName, "vpn", false) || InStrEx(t.DeviceName, "tun", false)\r
+               || InStrEx(t.DeviceName, "tap", false))\r
+       {\r
+               // VPN デバイスにローカルブリッジしようとしている\r
+               if (MsgBoxEx(hWnd, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2,\r
+                       _UU("SM_BRIDGE_VPN"),\r
+                       t.DeviceName) == IDNO)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       // Intel 製 LAN カードなどに関する警告\r
+       if (tapmode == false)\r
+       {\r
+               MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_BRIDGE_INTEL"));\r
+       }\r
+\r
+       if (CALL(hWnd, ScAddLocalBridge(s->Rpc, &t)) == false)\r
+       {\r
+               Focus(hWnd, E_HUBNAME);\r
+               return;\r
+       }\r
+\r
+       SetText(hWnd, E_HUBNAME, L"");\r
+       Focus(hWnd, E_HUBNAME);\r
+\r
+       if (tapmode)\r
+       {\r
+               SetTextA(hWnd, E_TAPNAME, "");\r
+       }\r
+\r
+       SmBridgeDlgRefresh(hWnd, s);\r
+\r
+       MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_BRIDGE_OK"));\r
+}\r
+\r
+// ブリッジダイアログプロシージャ\r
+UINT SmBridgeDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       NMHDR *n;\r
+       SM_SERVER *s = (SM_SERVER *)param;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmBridgeDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_HUBNAME:\r
+               case E_NICNAME:\r
+               case R_BRIDGE:\r
+               case R_TAP:\r
+               case E_TAPNAME:\r
+                       SmBridgeDlgUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case R_BRIDGE:\r
+                       Focus(hWnd, E_NICNAME);\r
+                       break;\r
+\r
+               case R_TAP:\r
+                       FocusEx(hWnd, E_TAPNAME);\r
+                       break;\r
+\r
+               case IDOK:\r
+                       // 追加\r
+                       SmBridgeDlgOnOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // 閉じる\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_VLAN:\r
+                       // VLAN ユーティリティ\r
+                       SmVLan(hWnd, s);\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       // 削除\r
+                       i = LvGetSelected(hWnd, L_LIST);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               wchar_t *nic, *hub;\r
+                               wchar_t tmp[MAX_SIZE];\r
+                               RPC_LOCALBRIDGE t;\r
+\r
+                               hub = LvGetStr(hWnd, L_LIST, i, 1);\r
+                               nic = LvGetStr(hWnd, L_LIST, i, 2);\r
+\r
+                               UniFormat(tmp, sizeof(tmp), _UU("SM_BRIDGE_DELETE"),\r
+                                       hub, nic);\r
+\r
+                               if (MsgBox(hWnd, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2, tmp) == IDYES)\r
+                               {\r
+                                       Zero(&t, sizeof(t));\r
+                                       UniToStr(t.DeviceName, sizeof(t.DeviceName), nic);\r
+                                       UniToStr(t.HubName, sizeof(t.HubName), hub);\r
+\r
+                                       if (CALL(hWnd, ScDeleteLocalBridge(s->Rpc, &t)))\r
+                                       {\r
+                                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_BRIDGE_DELETE_OK"));\r
+                                               SmBridgeDlgRefresh(hWnd, s);\r
+                                       }\r
+                               }\r
+\r
+                               Free(hub);\r
+                               Free(nic);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       SmBridgeDlgRefresh(hWnd, s);\r
+                       SetTimer(hWnd, 1, 1000, NULL);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->code)\r
+               {\r
+               case LVN_ITEMCHANGED:\r
+                       switch (n->idFrom)\r
+                       {\r
+                       case L_LIST:\r
+                               SmBridgeDlgUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// WinPcap のインストール作業\r
+void SmInstallWinPcap(HWND hWnd, SM_SERVER *s)\r
+{\r
+       wchar_t temp_name[MAX_SIZE];\r
+       IO *io;\r
+       BUF *buf;\r
+\r
+       // インストールを開始するかどうか質問する\r
+       if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("SM_BRIDGE_WPCAP_INSTALL")) == IDNO)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 一時ファイル名を生成\r
+       UniFormat(temp_name, sizeof(temp_name), L"%s\\winpcap_installer.exe", MsGetTempDirW());\r
+\r
+       // hamcore から読み込む\r
+       buf = ReadDump(MsIsNt() ? "|winpcap_installer.exe" : "|winpcap_installer_win9x.exe");\r
+       if (buf == NULL)\r
+       {\r
+RES_ERROR:\r
+               MsgBox(hWnd, MB_ICONSTOP, _UU("SM_BRIDGE_RESOURCE"));\r
+               return;\r
+       }\r
+\r
+       // 一時ファイルに書き出す\r
+       io = FileCreateW(temp_name);\r
+       if (io == NULL)\r
+       {\r
+               FreeBuf(buf);\r
+               goto RES_ERROR;\r
+       }\r
+\r
+       FileWrite(io, buf->Buf, buf->Size);\r
+       FileClose(io);\r
+\r
+       FreeBuf(buf);\r
+\r
+       // 実行する\r
+       if (RunW(temp_name, NULL, false, true) == false)\r
+       {\r
+               // 失敗\r
+               FileDeleteW(temp_name);\r
+               goto RES_ERROR;\r
+       }\r
+\r
+       FileDeleteW(temp_name);\r
+\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 終了後のメッセージ\r
+       if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType) == false)\r
+       {\r
+               // コンピュータの再起動が必要\r
+               MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_BRIDGE_WPCAP_REBOOT1"));\r
+       }\r
+       else\r
+       {\r
+               // サービスの再起動が必要\r
+               if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("SM_BRIDGE_WPCAP_REBOOT2")) == IDNO)\r
+               {\r
+                       // 再起動しない\r
+               }\r
+               else\r
+               {\r
+                       // 再起動する\r
+                       RPC_TEST t;\r
+                       Zero(&t, sizeof(t));\r
+                       ScRebootServer(s->Rpc, &t);\r
+\r
+                       SleepThread(500);\r
+\r
+                       Zero(&t, sizeof(t));\r
+                       CALL(hWnd, ScTest(s->Rpc, &t));\r
+               }\r
+       }\r
+}\r
+\r
+// ブリッジダイアログ\r
+void SmBridgeDlg(HWND hWnd, SM_SERVER *s)\r
+{\r
+       RPC_BRIDGE_SUPPORT t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // まずサーバー側のブリッジ対応状況を調べる\r
+       Zero(&t, sizeof(t));\r
+       if (CALLEX(hWnd, ScGetBridgeSupport(s->Rpc, &t)) != ERR_NO_ERROR)\r
+       {\r
+               // 古いバージョンなので未対応\r
+               MsgBox(hWnd, MB_ICONEXCLAMATION, _UU("SM_BRIDGE_TOO_OLD_VER"));\r
+               return;\r
+       }\r
+\r
+       if (t.IsBridgeSupportedOs == false)\r
+       {\r
+               // OS がブリッジに対応していない\r
+               MsgBox(hWnd, MB_ICONEXCLAMATION, _UU("SM_BRIDGE_UNSUPPORTED"));\r
+               return;\r
+       }\r
+\r
+       if (t.IsWinPcapNeeded)\r
+       {\r
+               if (s->Rpc->Sock->RemoteIP.addr[0] != 127)\r
+               {\r
+                       // WinPcap が必要だがリモート管理モードなので何も出来ない\r
+                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_BRIDGE_WPCAP_REMOTE"));\r
+                       return;\r
+               }\r
+               else\r
+               {\r
+                       // WinPcap が必要でローカル管理モードである\r
+                       if (MsIsAdmin())\r
+                       {\r
+                               // Administrators である\r
+                               SmInstallWinPcap(hWnd, s);\r
+                               return;\r
+                       }\r
+                       else\r
+                       {\r
+                               // Administrators でない\r
+                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_BRIDGE_WPCAP_ROOT"));\r
+                               return;\r
+                       }\r
+               }\r
+       }\r
+\r
+       Dialog(hWnd, D_SM_BRIDGE, SmBridgeDlgProc, s);\r
+}\r
+\r
+// SecureNAT 画面更新\r
+void SmSNATDlgUpdate(HWND hWnd, SM_HUB *s)\r
+{\r
+       bool b;\r
+       RPC_HUB_STATUS t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+       if (CALL(hWnd, ScGetHubStatus(s->Rpc, &t)) == false)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       b = t.SecureNATEnabled;\r
+\r
+       if (b)\r
+       {\r
+               Disable(hWnd, B_ENABLE);\r
+               Enable(hWnd, B_DISABLE);\r
+               Enable(hWnd, B_NAT);\r
+               Enable(hWnd, B_DHCP);\r
+               Enable(hWnd, B_STATUS);\r
+       }\r
+       else\r
+       {\r
+               Enable(hWnd, B_ENABLE);\r
+               Disable(hWnd, B_DISABLE);\r
+               Disable(hWnd, B_NAT);\r
+               Disable(hWnd, B_DHCP);\r
+               Disable(hWnd, B_STATUS);\r
+       }\r
+}\r
+\r
+// SecureNAT 設定画面\r
+UINT SmSNATDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_HUB *s = (SM_HUB *)param;\r
+       RPC_HUB t;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetIcon(hWnd, 0, ICO_ROUTER);\r
+               DlgFont(hWnd, S_WARNING, (_GETLANG() == 0 || _GETLANG() == 2) ? 13 : 10, true);\r
+               FormatText(hWnd, S_TITLE, s->HubName);\r
+               SmSNATDlgUpdate(hWnd, s);\r
+\r
+               SetTimer(hWnd, 1, 1000, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               if (wParam == 1)\r
+               {\r
+                       KillTimer(hWnd, 1);\r
+\r
+                       SmSNATDlgUpdate(hWnd, s);\r
+\r
+                       SetTimer(hWnd, 1, 1000, NULL);\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_ENABLE:\r
+                       if (MsgBox(hWnd, MB_ICONEXCLAMATION | MB_OKCANCEL | MB_DEFBUTTON2,\r
+                               _UU("SM_SECURE_NAT_MSG")) == IDOK)\r
+                       {\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+                               CALL(hWnd, ScEnableSecureNAT(s->Rpc, &t));\r
+                               SmSNATDlgUpdate(hWnd, s);\r
+                       }\r
+                       break;\r
+\r
+               case B_DISABLE:\r
+                       Zero(&t, sizeof(t));\r
+                       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+                       CALL(hWnd, ScDisableSecureNAT(s->Rpc, &t));\r
+                       SmSNATDlgUpdate(hWnd, s);\r
+                       break;\r
+\r
+               case B_CONFIG:\r
+                       NmEditVhOption(hWnd, s);\r
+                       break;\r
+\r
+               case B_NAT:\r
+                       NmNat(hWnd, s);\r
+                       break;\r
+\r
+               case B_DHCP:\r
+                       NmDhcp(hWnd, s);\r
+                       break;\r
+\r
+               case B_STATUS:\r
+                       SmStatusDlg(hWnd, s->p, s, false, true, _UU("SM_SNAT_STATUS"), ICO_ROUTER,\r
+                               NULL, NmStatus);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 初期化\r
+void SmCreateCertDlgInit(HWND hWnd, SM_CERT *s)\r
+{\r
+       UINT cert_sign;\r
+       UINT cert_days;\r
+       char *reg_o, *reg_ou, *reg_c, *reg_st, *reg_l;\r
+       UINT bits[] = {1024, 1536, 2048, 3072, 4096 };\r
+       UINT i;\r
+       UINT last_bit;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetTextA(hWnd, E_CN, s->default_cn);\r
+\r
+       last_bit = MsRegReadInt(REG_CURRENT_USER, SM_CERT_REG_KEY, "Bits");\r
+       if (last_bit == 0)\r
+       {\r
+               last_bit = 1024;\r
+       }\r
+\r
+       CbReset(hWnd, C_BITS);\r
+       for (i = 0;i < sizeof(bits) / sizeof(bits[0]);i++)\r
+       {\r
+               char tmp[MAX_PATH];\r
+               UINT index;\r
+\r
+               ToStr(tmp, bits[i]);\r
+\r
+               index = CbAddStrA(hWnd, C_BITS, tmp, bits[i]);\r
+       }\r
+\r
+       CbSelect(hWnd, C_BITS, 1024);\r
+       CbSelect(hWnd, C_BITS, last_bit);\r
+\r
+       reg_o = MsRegReadStr(REG_CURRENT_USER, SM_CERT_REG_KEY, "O");\r
+       reg_ou = MsRegReadStr(REG_CURRENT_USER, SM_CERT_REG_KEY, "OU");\r
+       reg_c = MsRegReadStr(REG_CURRENT_USER, SM_CERT_REG_KEY, "C");\r
+       reg_st = MsRegReadStr(REG_CURRENT_USER, SM_CERT_REG_KEY, "ST");\r
+       reg_l = MsRegReadStr(REG_CURRENT_USER, SM_CERT_REG_KEY, "L");\r
+       SetTextA(hWnd, E_O, reg_o);\r
+       SetTextA(hWnd, E_OU, reg_ou);\r
+       SetTextA(hWnd, E_C, reg_c);\r
+       SetTextA(hWnd, E_ST, reg_st);\r
+       SetTextA(hWnd, E_L, reg_l);\r
+       Free(reg_o);\r
+       Free(reg_ou);\r
+       Free(reg_c);\r
+       Free(reg_st);\r
+       Free(reg_l);\r
+\r
+       LimitText(hWnd, E_C, 2);\r
+\r
+       cert_sign = MsRegReadInt(REG_CURRENT_USER, SM_CERT_REG_KEY, "Sign");\r
+       cert_days = MsRegReadInt(REG_CURRENT_USER, SM_CERT_REG_KEY, "Days");\r
+\r
+       Check(hWnd, R_ROOT_CERT, cert_sign ? false : true);\r
+       Check(hWnd, R_SIGNED_CERT, cert_sign ? true : false);\r
+\r
+       if (cert_days == 0)\r
+       {\r
+               cert_days = 3650;\r
+       }\r
+\r
+       SetIntEx(hWnd, E_EXPIRE, cert_days);\r
+\r
+       SmCreateCertDlgUpdate(hWnd, s);\r
+\r
+       FocusEx(hWnd, E_CN);\r
+}\r
+\r
+// 更新\r
+void SmCreateCertDlgUpdate(HWND hWnd, SM_CERT *s)\r
+{\r
+       bool ok = true;\r
+       bool b;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsEmpty(hWnd, E_CN) && IsEmpty(hWnd, E_O) && IsEmpty(hWnd, E_OU) &&\r
+               IsEmpty(hWnd, E_ST) && IsEmpty(hWnd, E_L))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       i = GetInt(hWnd, E_EXPIRE);\r
+       if (i == 0 || i >= (365 * 30))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       b = IsChecked(hWnd, R_SIGNED_CERT);\r
+\r
+       SetEnable(hWnd, S_LOAD_1, b);\r
+       SetEnable(hWnd, B_LOAD, b);\r
+       SetEnable(hWnd, S_LOAD_2, b);\r
+\r
+       if (b && (s->root_k == NULL || s->root_x == NULL))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// OK ボタン\r
+void SmCreateCertDlgOnOk(HWND hWnd, SM_CERT *s)\r
+{\r
+       wchar_t cn[MAX_SIZE], o[MAX_SIZE], ou[MAX_SIZE], c[MAX_SIZE], st[MAX_SIZE], l[MAX_SIZE];\r
+       char *reg_o, *reg_ou, *reg_c, *reg_st, *reg_l;\r
+       UINT days;\r
+       bool sign;\r
+       char serial[MAX_SIZE * 2];\r
+       X *x;\r
+       K *pub;\r
+       K *pri;\r
+       NAME *n;\r
+       X_SERIAL *x_serial;\r
+       BUF *buf;\r
+       UINT bits;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetTxt(hWnd, E_CN, cn, sizeof(cn));\r
+       GetTxt(hWnd, E_O, o, sizeof(o));\r
+       GetTxt(hWnd, E_OU, ou, sizeof(ou));\r
+       GetTxt(hWnd, E_C, c, sizeof(c));\r
+       GetTxt(hWnd, E_ST, st, sizeof(st));\r
+       GetTxt(hWnd, E_L, l, sizeof(l));\r
+       GetTxtA(hWnd, E_SERIAL, serial, sizeof(serial));\r
+\r
+       bits = CbGetSelect(hWnd, C_BITS);\r
+       if (bits == INFINITE)\r
+       {\r
+               bits = 1024;\r
+       }\r
+\r
+       buf = StrToBin(serial);\r
+       if (buf == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (buf->Size > 1)\r
+       {\r
+               x_serial = NewXSerial(buf->Buf, buf->Size);\r
+       }\r
+       else\r
+       {\r
+               x_serial = NULL;\r
+       }\r
+\r
+       FreeBuf(buf);\r
+\r
+       n = NewName(UniStrLen(cn) ? cn : NULL,\r
+               UniStrLen(o) ? o : NULL,\r
+               UniStrLen(ou) ? ou : NULL,\r
+               UniStrLen(c) ? c : NULL,\r
+               UniStrLen(st) ? st : NULL,\r
+               UniStrLen(l) ? l : NULL);\r
+\r
+       days = GetInt(hWnd, E_EXPIRE);\r
+\r
+       sign = IsChecked(hWnd, R_SIGNED_CERT);\r
+\r
+       MsRegWriteInt(REG_CURRENT_USER, SM_CERT_REG_KEY, "Sign", sign);\r
+       MsRegWriteInt(REG_CURRENT_USER, SM_CERT_REG_KEY, "Days", days);\r
+       MsRegWriteInt(REG_CURRENT_USER, SM_CERT_REG_KEY, "Bits", bits);\r
+\r
+       RsaGen(&pri, &pub, bits);\r
+\r
+       if (sign == false)\r
+       {\r
+               x = NewRootX(pub, pri, n, days, x_serial);\r
+       }\r
+       else\r
+       {\r
+               x = NewX(pub, s->root_k, s->root_x, n, days, x_serial);\r
+       }\r
+\r
+       FreeName(n);\r
+\r
+       FreeXSerial(x_serial);\r
+\r
+       if (x == NULL)\r
+       {\r
+               FreeX(x);\r
+               FreeK(pub);\r
+               FreeK(pri);\r
+               return;\r
+       }\r
+\r
+       if (s->do_not_save == false)\r
+       {\r
+               if (SmSaveKeyPairDlg(hWnd, x, pri) == false)\r
+               {\r
+                       FreeX(x);\r
+                       FreeK(pub);\r
+                       FreeK(pri);\r
+                       return;\r
+               }\r
+       }\r
+\r
+       s->x = x;\r
+       s->k = pri;\r
+       FreeK(pub);\r
+\r
+       reg_o = GetTextA(hWnd, E_O);\r
+       reg_ou = GetTextA(hWnd, E_OU);\r
+       reg_c = GetTextA(hWnd, E_C);\r
+       reg_st = GetTextA(hWnd, E_ST);\r
+       reg_l = GetTextA(hWnd, E_L);\r
+       MsRegWriteStr(REG_CURRENT_USER, SM_CERT_REG_KEY, "O", reg_o);\r
+       MsRegWriteStr(REG_CURRENT_USER, SM_CERT_REG_KEY, "OU", reg_ou);\r
+       MsRegWriteStr(REG_CURRENT_USER, SM_CERT_REG_KEY, "C", reg_c);\r
+       MsRegWriteStr(REG_CURRENT_USER, SM_CERT_REG_KEY, "ST", reg_st);\r
+       MsRegWriteStr(REG_CURRENT_USER, SM_CERT_REG_KEY, "L", reg_l);\r
+       Free(reg_o);\r
+       Free(reg_ou);\r
+       Free(reg_c);\r
+       Free(reg_st);\r
+       Free(reg_l);\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// 証明書作成画面\r
+UINT SmCreateCertDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_CERT *s = (SM_CERT *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmCreateCertDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_ROOT_CERT:\r
+               case R_SIGNED_CERT:\r
+               case B_LOAD:\r
+               case E_CN:\r
+               case E_O:\r
+               case E_OU:\r
+               case E_C:\r
+               case E_ST:\r
+               case E_L:\r
+               case E_EXPIRE:\r
+                       SmCreateCertDlgUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // OK ボタン\r
+                       SmCreateCertDlgOnOk(hWnd, s);\r
+                       break;\r
+\r
+               case R_ROOT_CERT:\r
+                       if (IsChecked(hWnd, R_ROOT_CERT))\r
+                       {\r
+                               FocusEx(hWnd, E_CN);\r
+                       }\r
+                       break;\r
+\r
+               case B_LOAD:\r
+                       // 証明書読み込み\r
+                       if (1)\r
+                       {\r
+                               X *x;\r
+                               K *k;\r
+                               if (CmLoadXAndK(hWnd, &x, &k))\r
+                               {\r
+                                       wchar_t tmp[MAX_SIZE];\r
+                                       FreeX(s->root_x);\r
+                                       FreeK(s->root_k);\r
+                                       s->root_x = x;\r
+                                       s->root_k = k;\r
+\r
+                                       SmGetCertInfoStr(tmp, sizeof(tmp), x);\r
+                                       SetText(hWnd, S_LOAD_2, tmp);\r
+                                       SmCreateCertDlgUpdate(hWnd, s);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 証明書ツール\r
+bool SmCreateCert(HWND hWnd, X **x, K **k, bool do_not_save, char *default_cn)\r
+{\r
+       bool ret;\r
+       SM_CERT s;\r
+       Zero(&s, sizeof(s));\r
+\r
+       if (default_cn == NULL)\r
+       {\r
+               default_cn = "";\r
+       }\r
+\r
+       s.default_cn = default_cn;\r
+\r
+       s.do_not_save = do_not_save;\r
+\r
+       ret = Dialog(hWnd, D_SM_CREATE_CERT, SmCreateCertDlgProc, &s);\r
+\r
+       if (ret)\r
+       {\r
+               if (x != NULL)\r
+               {\r
+                       *x = CloneX(s.x);\r
+               }\r
+\r
+               if (k != NULL)\r
+               {\r
+                       *k = CloneK(s.k);\r
+               }\r
+       }\r
+\r
+       FreeX(s.x);\r
+       FreeK(s.k);\r
+       FreeX(s.root_x);\r
+       FreeK(s.root_k);\r
+\r
+       return ret;\r
+}\r
+\r
+// 初期化\r
+void SmIpTableDlgInit(HWND hWnd, SM_TABLE *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_PROTOCOL);\r
+       FormatText(hWnd, S_TITLE, s->Hub->HubName);\r
+\r
+       if (s->SessionName != NULL)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               GetTxt(hWnd, S_TITLE, tmp, sizeof(tmp));\r
+               UniFormat(tmp2, sizeof(tmp2), _UU("SM_SESSION_FILTER"), s->SessionName);\r
+               UniStrCat(tmp, sizeof(tmp), tmp2);\r
+               SetText(hWnd, S_TITLE, tmp);\r
+       }\r
+\r
+       LvInit(hWnd, L_TABLE);\r
+       LvInsertColumn(hWnd, L_TABLE, 0, _UU("SM_IP_COLUMN_1"), 190);\r
+       LvInsertColumn(hWnd, L_TABLE, 1, _UU("SM_IP_COLUMN_2"), 140);\r
+       LvInsertColumn(hWnd, L_TABLE, 2, _UU("SM_IP_COLUMN_3"), 133);\r
+       LvInsertColumn(hWnd, L_TABLE, 3, _UU("SM_IP_COLUMN_4"), 133);\r
+       LvInsertColumn(hWnd, L_TABLE, 4, _UU("SM_IP_COLUMN_5"), 133);\r
+       LvSetStyle(hWnd, L_TABLE, LVS_EX_GRIDLINES);\r
+\r
+       SmIpTableDlgRefresh(hWnd, s);\r
+}\r
+\r
+// コントロール更新\r
+void SmIpTableDlgUpdate(HWND hWnd, SM_TABLE *s)\r
+{\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSelected(hWnd, L_TABLE) == false || LvIsMultiMasked(hWnd, L_TABLE))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       SetEnable(hWnd, B_DELETE, ok);\r
+}\r
+\r
+// 内容更新\r
+void SmIpTableDlgRefresh(HWND hWnd, SM_TABLE *s)\r
+{\r
+       UINT i;\r
+       RPC_ENUM_IP_TABLE t;\r
+       UINT old_selected = 0;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->Hub->HubName);\r
+\r
+       if (CALL(hWnd, ScEnumIpTable(s->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       i = LvGetSelected(hWnd, L_TABLE);\r
+       if (i != INFINITE)\r
+       {\r
+               old_selected = (UINT)LvGetParam(hWnd, L_TABLE, i);\r
+       }\r
+\r
+       LvReset(hWnd, L_TABLE);\r
+\r
+       for (i = 0;i < t.NumIpTable;i++)\r
+       {\r
+               char str[MAX_SIZE];\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               wchar_t tmp3[MAX_SIZE];\r
+               wchar_t tmp4[MAX_SIZE];\r
+               wchar_t tmp5[MAX_SIZE];\r
+               RPC_ENUM_IP_TABLE_ITEM *e = &t.IpTables[i];\r
+\r
+               if (s->SessionName == NULL || StrCmpi(e->SessionName, s->SessionName) == 0)\r
+               {\r
+                       StrToUni(tmp1, sizeof(tmp1), e->SessionName);\r
+\r
+                       if (e->DhcpAllocated == false)\r
+                       {\r
+                               IPToStr(str, sizeof(str), &e->IpV6);\r
+                               StrToUni(tmp2, sizeof(tmp2), str);\r
+                       }\r
+                       else\r
+                       {\r
+                               IPToStr(str, sizeof(str), &e->IpV6);\r
+                               UniFormat(tmp2, sizeof(tmp2), _UU("SM_MAC_IP_DHCP"), str);\r
+                       }\r
+\r
+                       GetDateTimeStr64Uni(tmp3, sizeof(tmp3), SystemToLocal64(e->CreatedTime));\r
+\r
+                       GetDateTimeStr64Uni(tmp4, sizeof(tmp4), SystemToLocal64(e->UpdatedTime));\r
+\r
+                       if (StrLen(e->RemoteHostname) == 0)\r
+                       {\r
+                               UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_MACIP_LOCAL"));\r
+                       }\r
+                       else\r
+                       {\r
+                               UniFormat(tmp5, sizeof(tmp5), _UU("SM_MACIP_SERVER"), e->RemoteHostname);\r
+                       }\r
+\r
+                       LvInsert(hWnd, L_TABLE, e->DhcpAllocated ? ICO_PROTOCOL_DHCP : ICO_PROTOCOL, (void *)e->Key, 5,\r
+                               tmp1, tmp2, tmp3, tmp4, tmp5);\r
+               }\r
+       }\r
+\r
+       FreeRpcEnumIpTable(&t);\r
+\r
+       if (old_selected != 0)\r
+       {\r
+               LvSelect(hWnd, L_TABLE, LvSearchParam(hWnd, L_TABLE, (void *)old_selected));\r
+       }\r
+\r
+       SmIpTableDlgUpdate(hWnd, s);\r
+}\r
+\r
+// IP アドレステーブルダイアログプロシージャ\r
+UINT SmIpTableDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_TABLE *s = (SM_TABLE *)param;\r
+       NMHDR *n;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmIpTableDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_DELETE:\r
+                       // 削除\r
+                       i = LvGetSelected(hWnd, L_TABLE);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               RPC_DELETE_TABLE t;\r
+                               UINT key = (UINT)LvGetParam(hWnd, L_TABLE, i);\r
+\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.HubName, sizeof(t.HubName), s->Hub->HubName);\r
+                               t.Key = key;\r
+                               if (CALL(hWnd, ScDeleteIpTable(s->Rpc, &t)))\r
+                               {\r
+                                       LvDeleteItem(hWnd, L_TABLE, i);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       // 更新\r
+                       SmIpTableDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_TABLE:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmIpTableDlgUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_TABLE);\r
+\r
+       return 0;\r
+}\r
+\r
+// IP アドレステーブルダイアログ\r
+void SmIpTableDlg(HWND hWnd, SM_HUB *s, char *session_name)\r
+{\r
+       SM_TABLE t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.Hub = s;\r
+       t.Rpc = s->Rpc;\r
+       t.SessionName = session_name;\r
+\r
+       Dialog(hWnd, D_SM_IP, SmIpTableDlgProc, &t);\r
+}\r
+\r
+\r
+// 初期化\r
+void SmMacTableDlgInit(HWND hWnd, SM_TABLE *s)\r
+{\r
+       UINT i = 0;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_NIC_ONLINE);\r
+       FormatText(hWnd, S_TITLE, s->Hub->HubName);\r
+\r
+       if (s->SessionName != NULL)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               GetTxt(hWnd, S_TITLE, tmp, sizeof(tmp));\r
+               UniFormat(tmp2, sizeof(tmp2), _UU("SM_SESSION_FILTER"), s->SessionName);\r
+               UniStrCat(tmp, sizeof(tmp), tmp2);\r
+               SetText(hWnd, S_TITLE, tmp);\r
+       }\r
+\r
+       LvInit(hWnd, L_TABLE);\r
+       LvInsertColumn(hWnd, L_TABLE, i++, _UU("SM_MAC_COLUMN_1"), 190);\r
+       if (GetCapsBool(s->Hub->p->CapsList, "b_support_vlan"))\r
+       {\r
+               LvInsertColumn(hWnd, L_TABLE, i++, _UU("SM_MAC_COLUMN_1A"), 65);\r
+       }\r
+       LvInsertColumn(hWnd, L_TABLE, i++, _UU("SM_MAC_COLUMN_2"), 140);\r
+       LvInsertColumn(hWnd, L_TABLE, i++, _UU("SM_MAC_COLUMN_3"), 133);\r
+       LvInsertColumn(hWnd, L_TABLE, i++, _UU("SM_MAC_COLUMN_4"), 133);\r
+       LvInsertColumn(hWnd, L_TABLE, i++, _UU("SM_MAC_COLUMN_5"), 133);\r
+       LvSetStyle(hWnd, L_TABLE, LVS_EX_GRIDLINES);\r
+\r
+       SmMacTableDlgRefresh(hWnd, s);\r
+}\r
+\r
+// コントロール更新\r
+void SmMacTableDlgUpdate(HWND hWnd, SM_TABLE *s)\r
+{\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSelected(hWnd, L_TABLE) == false || LvIsMultiMasked(hWnd, L_TABLE))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       SetEnable(hWnd, B_DELETE, ok);\r
+}\r
+\r
+// 内容更新\r
+void SmMacTableDlgRefresh(HWND hWnd, SM_TABLE *s)\r
+{\r
+       UINT i;\r
+       RPC_ENUM_MAC_TABLE t;\r
+       UINT old_selected = 0;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->Hub->HubName);\r
+\r
+       if (CALL(hWnd, ScEnumMacTable(s->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       i = LvGetSelected(hWnd, L_TABLE);\r
+       if (i != INFINITE)\r
+       {\r
+               old_selected = (UINT)LvGetParam(hWnd, L_TABLE, i);\r
+       }\r
+\r
+       LvReset(hWnd, L_TABLE);\r
+\r
+       for (i = 0;i < t.NumMacTable;i++)\r
+       {\r
+               char str[MAX_SIZE];\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               wchar_t tmp3[MAX_SIZE];\r
+               wchar_t tmp4[MAX_SIZE];\r
+               wchar_t tmp5[MAX_SIZE];\r
+               wchar_t tmp6[MAX_SIZE];\r
+               RPC_ENUM_MAC_TABLE_ITEM *e = &t.MacTables[i];\r
+\r
+               if (s->SessionName == NULL || StrCmpi(e->SessionName, s->SessionName) == 0)\r
+               {\r
+                       StrToUni(tmp1, sizeof(tmp1), e->SessionName);\r
+\r
+                       MacToStr(str, sizeof(str), e->MacAddress);\r
+                       StrToUni(tmp2, sizeof(tmp2), str);\r
+\r
+                       GetDateTimeStr64Uni(tmp3, sizeof(tmp3), SystemToLocal64(e->CreatedTime));\r
+\r
+                       GetDateTimeStr64Uni(tmp4, sizeof(tmp4), SystemToLocal64(e->UpdatedTime));\r
+\r
+                       if (StrLen(e->RemoteHostname) == 0)\r
+                       {\r
+                               UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_MACIP_LOCAL"));\r
+                       }\r
+                       else\r
+                       {\r
+                               UniFormat(tmp5, sizeof(tmp5), _UU("SM_MACIP_SERVER"), e->RemoteHostname);\r
+                       }\r
+\r
+                       UniToStru(tmp6, e->VlanId);\r
+                       if (e->VlanId == 0)\r
+                       {\r
+                               UniStrCpy(tmp6, sizeof(tmp6), _UU("CM_ST_NONE"));\r
+                       }\r
+\r
+                       if (GetCapsBool(s->Hub->p->CapsList, "b_support_vlan"))\r
+                       {\r
+                               LvInsert(hWnd, L_TABLE, ICO_NIC_ONLINE, (void *)e->Key, 6,\r
+                                       tmp1, tmp6, tmp2, tmp3, tmp4, tmp5);\r
+                       }\r
+                       else\r
+                       {\r
+                               LvInsert(hWnd, L_TABLE, ICO_NIC_ONLINE, (void *)e->Key, 5,\r
+                                       tmp1, tmp2, tmp3, tmp4, tmp5);\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeRpcEnumMacTable(&t);\r
+\r
+       if (old_selected != 0)\r
+       {\r
+               LvSelect(hWnd, L_TABLE, LvSearchParam(hWnd, L_TABLE, (void *)old_selected));\r
+       }\r
+\r
+       SmMacTableDlgUpdate(hWnd, s);\r
+}\r
+\r
+// MAC アドレステーブルダイアログプロシージャ\r
+UINT SmMacTableDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_TABLE *s = (SM_TABLE *)param;\r
+       NMHDR *n;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmMacTableDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_DELETE:\r
+                       // 削除\r
+                       i = LvGetSelected(hWnd, L_TABLE);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               RPC_DELETE_TABLE t;\r
+                               UINT key = (UINT)LvGetParam(hWnd, L_TABLE, i);\r
+\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.HubName, sizeof(t.HubName), s->Hub->HubName);\r
+                               t.Key = key;\r
+                               if (CALL(hWnd, ScDeleteMacTable(s->Rpc, &t)))\r
+                               {\r
+                                       LvDeleteItem(hWnd, L_TABLE, i);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       // 更新\r
+                       SmMacTableDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_TABLE:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmMacTableDlgUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_TABLE);\r
+\r
+       return 0;\r
+}\r
+\r
+// MAC アドレステーブルダイアログ\r
+void SmMacTableDlg(HWND hWnd, SM_HUB *s, char *session_name)\r
+{\r
+       SM_TABLE t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.Hub = s;\r
+       t.Rpc = s->Rpc;\r
+       t.SessionName = session_name;\r
+\r
+       Dialog(hWnd, D_SM_MAC, SmMacTableDlgProc, &t);\r
+}\r
+\r
+// 初期化\r
+void SmSessionDlgInit(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_VPN);\r
+       FormatText(hWnd, 0, s->HubName);\r
+       FormatText(hWnd, S_TITLE, s->HubName);\r
+\r
+       LvInit(hWnd, L_LIST);\r
+       LvInsertColumn(hWnd, L_LIST, 0, _UU("SM_SESS_COLUMN_1"), 176);\r
+       LvInsertColumn(hWnd, L_LIST, 1, _UU("SM_SESS_COLUMN_8"), 58);\r
+       LvInsertColumn(hWnd, L_LIST, 2, _UU("SM_SESS_COLUMN_2"), 62);\r
+       LvInsertColumn(hWnd, L_LIST, 3, _UU("SM_SESS_COLUMN_3"), 78);\r
+       LvInsertColumn(hWnd, L_LIST, 4, _UU("SM_SESS_COLUMN_4"), 122);\r
+       LvInsertColumn(hWnd, L_LIST, 5, _UU("SM_SESS_COLUMN_5"), 68);\r
+       LvInsertColumn(hWnd, L_LIST, 6, _UU("SM_SESS_COLUMN_6"), 100);\r
+       LvInsertColumn(hWnd, L_LIST, 7, _UU("SM_SESS_COLUMN_7"), 100);\r
+       LvSetStyle(hWnd, L_LIST, LVS_EX_GRIDLINES);\r
+\r
+       if (s->p->ServerType == SERVER_TYPE_FARM_CONTROLLER && GetCapsBool(s->p->CapsList, "b_support_cluster_admin") == false)\r
+       {\r
+               Show(hWnd, S_FARM_INFO_1);\r
+               Show(hWnd, S_FARM_INFO_2);\r
+       }\r
+\r
+       SmSessionDlgRefresh(hWnd, s);\r
+}\r
+\r
+// コントロールを更新する\r
+void SmSessionDlgUpdate(HWND hWnd, SM_HUB *s)\r
+{\r
+       bool ok = true;\r
+       bool ok2 = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSelected(hWnd, L_LIST) == false || LvIsMultiMasked(hWnd, L_LIST))\r
+       {\r
+               ok = false;\r
+               ok2 = false;\r
+       }\r
+       else\r
+       {\r
+               UINT i = LvGetSelected(hWnd, L_LIST);\r
+               if (i != INFINITE)\r
+               {\r
+                       void *p = LvGetParam(hWnd, L_LIST, i);\r
+                       if (((bool)p) != false)\r
+                       {\r
+                               if (GetCapsBool(s->p->CapsList, "b_support_cluster_admin") == false)\r
+                               {\r
+                                       ok = false;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (s->p->ServerInfo.ServerBuildInt < 2844)\r
+       {\r
+               // セッションのリモート管理非対応 Ver\r
+               ok2 = ok;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok2);\r
+       SetEnable(hWnd, B_DISCONNECT, ok2);\r
+       SetEnable(hWnd, B_SESSION_IP_TABLE, ok);\r
+       SetEnable(hWnd, B_SESSION_MAC_TABLE, ok);\r
+}\r
+\r
+// リストを更新する\r
+void SmSessionDlgRefresh(HWND hWnd, SM_HUB *s)\r
+{\r
+       LVB *b;\r
+       UINT i;\r
+       wchar_t *old_select;\r
+       RPC_ENUM_SESSION t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+\r
+       if (CALL(hWnd, ScEnumSession(s->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       old_select = LvGetSelectedStr(hWnd, L_LIST, 0);\r
+\r
+       LvReset(hWnd, L_LIST);\r
+\r
+       b = LvInsertStart();\r
+\r
+       for (i = 0;i < t.NumSession;i++)\r
+       {\r
+               RPC_ENUM_SESSION_ITEM *e = &t.Sessions[i];\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t *tmp2;\r
+               wchar_t tmp3[MAX_SIZE];\r
+               wchar_t tmp4[MAX_SIZE];\r
+               wchar_t tmp5[MAX_SIZE];\r
+               wchar_t tmp6[MAX_SIZE];\r
+               wchar_t tmp7[MAX_SIZE];\r
+               wchar_t tmp8[MAX_SIZE];\r
+               bool free_tmp2 = false;\r
+               UINT icon;\r
+\r
+               StrToUni(tmp1, sizeof(tmp1), e->Name);\r
+\r
+               tmp2 = _UU("SM_SESS_NORMAL");\r
+               icon = ICO_VPN;\r
+               if (s->p->ServerType != SERVER_TYPE_STANDALONE)\r
+               {\r
+                       if (e->RemoteSession)\r
+                       {\r
+                               tmp2 = ZeroMalloc(MAX_SIZE);\r
+                               UniFormat(tmp2, MAX_SIZE, _UU("SM_SESS_REMOTE"), e->RemoteHostname);\r
+                               icon = ICO_VPN;\r
+                               free_tmp2 = true;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (StrLen(e->RemoteHostname) == 0)\r
+                               {\r
+                                       tmp2 = _UU("SM_SESS_LOCAL");\r
+                               }\r
+                               else\r
+                               {\r
+                                       tmp2 = ZeroMalloc(MAX_SIZE);\r
+                                       UniFormat(tmp2, MAX_SIZE, _UU("SM_SESS_LOCAL_2"), e->RemoteHostname);\r
+                                       free_tmp2 = true;\r
+                               }\r
+                       }\r
+               }\r
+               if (e->LinkMode)\r
+               {\r
+                       if (free_tmp2)\r
+                       {\r
+                               Free(tmp2);\r
+                               free_tmp2 = false;\r
+                       }\r
+                       tmp2 = _UU("SM_SESS_LINK");\r
+                       icon = ICO_CASCADE;\r
+               }\r
+               else if (e->SecureNATMode)\r
+               {\r
+                       /*if (free_tmp2)\r
+                       {\r
+                               Free(tmp2);\r
+                               free_tmp2 = false;\r
+                       }\r
+                       tmp2 = _UU("SM_SESS_SNAT");*/\r
+                       icon = ICO_ROUTER;\r
+               }\r
+               else if (e->BridgeMode)\r
+               {\r
+                       icon = ICO_BRIDGE;\r
+               }\r
+               else if (e->Layer3Mode)\r
+               {\r
+                       icon = ICO_SWITCH;\r
+               }\r
+\r
+               StrToUni(tmp3, sizeof(tmp3), e->Username);\r
+\r
+               StrToUni(tmp4, sizeof(tmp4), e->Hostname);\r
+               if (e->LinkMode)\r
+               {\r
+                       UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_SESS_LINK_HOSTNAME"));\r
+               }\r
+               else if (e->SecureNATMode)\r
+               {\r
+                       UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_SESS_SNAT_HOSTNAME"));\r
+               }\r
+               else if (e->BridgeMode)\r
+               {\r
+                       UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_SESS_BRIDGE_HOSTNAME"));\r
+               }\r
+               else if (StartWith(e->Username, L3_USERNAME))\r
+               {\r
+                       UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_SESS_LAYER3_HOSTNAME"));\r
+               }\r
+\r
+               UniFormat(tmp5, sizeof(tmp5), L"%u / %u", e->CurrentNumTcp, e->MaxNumTcp);\r
+               if (e->LinkMode)\r
+               {\r
+                       UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_SESS_LINK_TCP"));\r
+               }\r
+               else if (e->SecureNATMode)\r
+               {\r
+                       UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_SESS_SNAT_TCP"));\r
+               }\r
+               else if (e->BridgeMode)\r
+               {\r
+                       UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_SESS_BRIDGE_TCP"));\r
+               }\r
+\r
+               if (e->VLanId == 0)\r
+               {\r
+                       UniStrCpy(tmp8, sizeof(tmp8), _UU("CM_ST_NO_VLAN"));\r
+               }\r
+               else\r
+               {\r
+                       UniToStru(tmp8, e->VLanId);\r
+               }\r
+\r
+               UniToStr3(tmp6, sizeof(tmp6), e->PacketSize);\r
+               UniToStr3(tmp7, sizeof(tmp7), e->PacketNum);\r
+\r
+               if (icon == ICO_VPN)\r
+               {\r
+                       if (e->Client_BridgeMode)\r
+                       {\r
+                               icon = ICO_SESSION_BRIDGE;\r
+                       }\r
+                       else if (e->Client_MonitorMode)\r
+                       {\r
+                               icon = ICO_SESSION_MONITOR;\r
+                       }\r
+               }\r
+\r
+               LvInsertAdd(b, icon, (void *)(e->RemoteSession), 8, tmp1, tmp8, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7);\r
+\r
+               if (free_tmp2)\r
+               {\r
+                       Free(tmp2);\r
+               }\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_LIST);\r
+\r
+       if (old_select != NULL && UniStrLen(old_select) != 0)\r
+       {\r
+               UINT i = LvSearchStr(hWnd, L_LIST, 0, old_select);\r
+               if (i != INFINITE)\r
+               {\r
+                       LvSelect(hWnd, L_LIST, i);\r
+               }\r
+       }\r
+\r
+       Free(old_select);\r
+\r
+       FreeRpcEnumSession(&t);\r
+\r
+       SmSessionDlgUpdate(hWnd, s);\r
+}\r
+\r
+// NODE_INFO の表示\r
+void SmPrintNodeInfo(LVB *b, NODE_INFO *info)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       char str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (b == NULL || info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrToUni(tmp, sizeof(tmp), info->ClientProductName);\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_CLIENT_NAME"), tmp);\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"%u.%02u", Endian32(info->ClientProductVer) / 100, Endian32(info->ClientProductVer) % 100);\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_CLIENT_VER"), tmp);\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"Build %u", Endian32(info->ClientProductBuild));\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_CLIENT_BUILD"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), info->ClientOsName);\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_CLIENT_OS_NAME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), info->ClientOsVer);\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_CLIENT_OS_VER"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), info->ClientOsProductId);\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_CLIENT_OS_PID"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), info->ClientHostname);\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_CLIENT_HOST"), tmp);\r
+\r
+       IPToStr4or6(str, sizeof(str), info->ClientIpAddress, info->ClientIpAddress6);\r
+       StrToUni(tmp, sizeof(tmp), str);\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_CLIENT_IP"), tmp);\r
+\r
+       UniToStru(tmp, Endian32(info->ClientPort));\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_CLIENT_PORT"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), info->ServerHostname);\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_SERVER_HOST"), tmp);\r
+\r
+       IPToStr4or6(str, sizeof(str), info->ServerIpAddress, info->ServerIpAddress6);\r
+       StrToUni(tmp, sizeof(tmp), str);\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_SERVER_IP"), tmp);\r
+\r
+       UniToStru(tmp, Endian32(info->ServerPort));\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_SERVER_PORT"), tmp);\r
+\r
+       if (StrLen(info->ProxyHostname) != 0)\r
+       {\r
+               StrToUni(tmp, sizeof(tmp), info->ProxyHostname);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_PROXY_HOSTNAME"), tmp);\r
+\r
+               IPToStr4or6(str, sizeof(str), info->ProxyIpAddress, info->ProxyIpAddress6);\r
+               StrToUni(tmp, sizeof(tmp), str);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_PROXY_IP"), tmp);\r
+\r
+               UniToStru(tmp, Endian32(info->ProxyPort));\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_NODE_PROXY_PORT"), tmp);\r
+       }\r
+}\r
+\r
+// セッション ステータスの更新\r
+bool SmRefreshSessionStatus(HWND hWnd, SM_SERVER *s, void *param)\r
+{\r
+       LVB *b;\r
+       SM_SESSION_STATUS *status = (SM_SESSION_STATUS *)param;\r
+       RPC_SESSION_STATUS t;\r
+       wchar_t tmp[MAX_SIZE];\r
+       char str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL || param == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), status->Hub->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), status->SessionName);\r
+\r
+       if (CALL(hWnd, ScGetSessionStatus(s->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       if (t.ClientIp != 0)\r
+       {\r
+               IPToStr4or6(str, sizeof(str), t.ClientIp, t.ClientIp6);\r
+               StrToUni(tmp, sizeof(tmp), str);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_CLIENT_IP"), tmp);\r
+       }\r
+\r
+       if (StrLen(t.ClientHostName) != 0)\r
+       {\r
+               StrToUni(tmp, sizeof(tmp), t.ClientHostName);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_CLIENT_HOSTNAME"), tmp);\r
+       }\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.Username);\r
+       LvInsertAdd(b, 0, NULL, 2, _UU("SM_SESS_STATUS_USERNAME"), tmp);\r
+\r
+       if (StrCmpi(t.Username, LINK_USER_NAME_PRINT) != 0 && StrCmpi(t.Username, SNAT_USER_NAME_PRINT) != 0 && StrCmpi(t.Username, BRIDGE_USER_NAME_PRINT) != 0)\r
+       {\r
+               StrToUni(tmp, sizeof(tmp), t.RealUsername);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_SESS_STATUS_REALUSER"), tmp);\r
+       }\r
+\r
+       if (IsEmptyStr(t.GroupName) == false)\r
+       {\r
+               StrToUni(tmp, sizeof(tmp), t.GroupName);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("SM_SESS_STATUS_GROUPNAME"), tmp);\r
+       }\r
+\r
+       CmPrintStatusToListViewEx(b, &t.Status, true);\r
+\r
+       if (StrCmpi(t.Username, LINK_USER_NAME_PRINT) != 0 && StrCmpi(t.Username, SNAT_USER_NAME_PRINT) != 0 && StrCmpi(t.Username, BRIDGE_USER_NAME_PRINT) != 0 &&\r
+               StartWith(t.Username, L3_USERNAME) == false)\r
+       {\r
+               SmPrintNodeInfo(b, &t.NodeInfo);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+       FreeRpcSessionStatus(&t);\r
+\r
+       return true;\r
+}\r
+\r
+// セッション管理ダイアログプロシージャ\r
+UINT SmSessionDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_HUB *s = (SM_HUB *)param;\r
+       wchar_t *tmp;\r
+       wchar_t tmp2[MAX_SIZE];\r
+       char name[MAX_SIZE];\r
+       NMHDR *n;\r
+       SM_SESSION_STATUS status;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       tmp = LvGetSelectedStr(hWnd, L_LIST, 0);\r
+       UniToStr(name, sizeof(name), tmp);\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmSessionDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       if (IsEnable(hWnd, IDOK))\r
+                       {\r
+                               // セッション状態表示\r
+                               UniFormat(tmp2, sizeof(tmp2), _UU("SM_SESS_STATUS_CAPTION"), name);\r
+                               Zero(&status, sizeof(status));\r
+                               status.Hub = s;\r
+                               status.SessionName = name;\r
+                               SmStatusDlg(hWnd, s->p, &status, true, true, tmp2, ICO_VPN,\r
+                                       NULL, SmRefreshSessionStatus);\r
+                       }\r
+                       break;\r
+\r
+               case B_DISCONNECT:\r
+                       // 切断\r
+                       if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2,\r
+                               _UU("SM_SESS_DISCONNECT_MSG"), name) == IDYES)\r
+                       {\r
+                               RPC_DELETE_SESSION t;\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+                               StrCpy(t.Name, sizeof(t.Name), name);\r
+\r
+                               if (CALL(hWnd, ScDeleteSession(s->Rpc, &t)))\r
+                               {\r
+                                       SmSessionDlgRefresh(hWnd, s);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       // 更新\r
+                       SmSessionDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case B_SESSION_IP_TABLE:\r
+                       // IP テーブル\r
+                       SmIpTableDlg(hWnd, s, name);\r
+                       break;\r
+\r
+               case B_SESSION_MAC_TABLE:\r
+                       // MAC テーブル\r
+                       SmMacTableDlg(hWnd, s, name);\r
+                       break;\r
+\r
+               case B_MAC_TABLE:\r
+                       // MAC テーブル一覧\r
+                       SmMacTableDlg(hWnd, s, NULL);\r
+                       break;\r
+\r
+               case B_IP_TABLE:\r
+                       // IP テーブル一覧\r
+                       SmIpTableDlg(hWnd, s, NULL);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->code)\r
+               {\r
+               case LVN_ITEMCHANGED:\r
+                       switch (n->idFrom)\r
+                       {\r
+                       case L_LIST:\r
+                               SmSessionDlgUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       Free(tmp);\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_LIST);\r
+\r
+       return 0;\r
+}\r
+\r
+// セッション管理ダイアログ\r
+void SmSessionDlg(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_SM_SESSION, SmSessionDlgProc, s);\r
+}\r
+\r
+// 証明書一覧更新\r
+void SmCaDlgRefresh(HWND hWnd, SM_HUB *s)\r
+{\r
+       LVB *b;\r
+       UINT i;\r
+       RPC_HUB_ENUM_CA t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+       if (CALL(hWnd, ScEnumCa(s->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       for (i = 0;i < t.NumCa;i++)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               RPC_HUB_ENUM_CA_ITEM *e = &t.Ca[i];\r
+\r
+               GetDateStrEx64(tmp, sizeof(tmp), SystemToLocal64(e->Expires), NULL);\r
+\r
+               LvInsertAdd(b, ICO_SERVER_CERT, (void *)e->Key, 3,\r
+                       e->SubjectName, e->IssuerName, tmp);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_CERT);\r
+\r
+       FreeRpcHubEnumCa(&t);\r
+\r
+       SmCaDlgUpdate(hWnd, s);\r
+}\r
+\r
+// 初期化\r
+void SmCaDlgInit(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_SERVER_CERT);\r
+\r
+       LvInit(hWnd, L_CERT);\r
+       LvInsertColumn(hWnd, L_CERT, 0, _UU("CM_CERT_COLUMN_1"), 190);\r
+       LvInsertColumn(hWnd, L_CERT, 1, _UU("CM_CERT_COLUMN_2"), 190);\r
+       LvInsertColumn(hWnd, L_CERT, 2, _UU("CM_CERT_COLUMN_3"), 160);\r
+\r
+       SmCaDlgRefresh(hWnd, s);\r
+}\r
+\r
+// コントロール更新\r
+void SmCaDlgUpdate(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEnable(hWnd, B_DELETE, LvIsSelected(hWnd, L_CERT));\r
+       SetEnable(hWnd, IDOK, LvIsSelected(hWnd, L_CERT));\r
+}\r
+\r
+// OK\r
+void SmCaDlgOnOk(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+}\r
+\r
+// CA 追加ダイアログ\r
+bool SmCaDlgAdd(HWND hWnd, SM_HUB *s)\r
+{\r
+       X *x;\r
+       RPC_HUB_ADD_CA t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (CmLoadXFromFileOrSecureCard(hWnd, &x) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+       t.Cert = x;\r
+\r
+       if (CALL(hWnd, ScAddCa(s->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       FreeRpcHubAddCa(&t);\r
+\r
+       return true;\r
+}\r
+\r
+// CA 一覧ダイアログプロシージャ\r
+UINT SmCaDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       NMHDR *n;\r
+       SM_HUB *s = (SM_HUB *)param;\r
+       UINT i, key;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmCaDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_IMPORT:\r
+                       // 追加\r
+                       if (SmCaDlgAdd(hWnd, s))\r
+                       {\r
+                               SmCaDlgRefresh(hWnd, s);\r
+                       }\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       // 削除\r
+                       i = LvGetSelected(hWnd, L_CERT);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               key = (UINT)LvGetParam(hWnd, L_CERT, i);\r
+                               if (key != 0)\r
+                               {\r
+                                       if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2,\r
+                                               _UU("CM_CERT_DELETE_MSG")) == IDYES)\r
+                                       {\r
+                                               RPC_HUB_DELETE_CA t;\r
+                                               Zero(&t, sizeof(t));\r
+                                               StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+                                               t.Key = key;\r
+\r
+                                               if (CALL(hWnd, ScDeleteCa(s->Rpc, &t)))\r
+                                               {\r
+                                                       SmCaDlgRefresh(hWnd, s);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDOK:\r
+                       // 表示\r
+                       i = LvGetSelected(hWnd, L_CERT);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               key = (UINT)LvGetParam(hWnd, L_CERT, i);\r
+                               if (key != 0)\r
+                               {\r
+                                       RPC_HUB_GET_CA t;\r
+                                       Zero(&t, sizeof(t));\r
+                                       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+                                       t.Key = key;\r
+\r
+                                       if (CALL(hWnd, ScGetCa(s->Rpc, &t)))\r
+                                       {\r
+                                               CertDlg(hWnd, t.Cert, NULL, true);\r
+                                               FreeRpcHubGetCa(&t);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_CERT:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmCaDlgUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_CERT);\r
+\r
+       return 0;\r
+}\r
+\r
+// CA 一覧ダイアログ\r
+void SmCaDlg(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_SM_CA, SmCaDlgProc, s);\r
+}\r
+\r
+// 初期化\r
+void SmLogDlgInit(HWND hWnd, SM_HUB *s)\r
+{\r
+       RPC_HUB_LOG t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_LOG2);\r
+\r
+       FormatText(hWnd, S_TITLE, s->HubName);\r
+\r
+       CbSetHeight(hWnd, C_SEC_SWITCH, 18);\r
+       CbSetHeight(hWnd, C_PACKET_SWITCH, 18);\r
+\r
+       // コントロール初期化\r
+       CbAddStr(hWnd, C_SEC_SWITCH, _UU("SM_LOG_SWITCH_0"), 0);\r
+       CbAddStr(hWnd, C_SEC_SWITCH, _UU("SM_LOG_SWITCH_1"), 1);\r
+       CbAddStr(hWnd, C_SEC_SWITCH, _UU("SM_LOG_SWITCH_2"), 2);\r
+       CbAddStr(hWnd, C_SEC_SWITCH, _UU("SM_LOG_SWITCH_3"), 3);\r
+       CbAddStr(hWnd, C_SEC_SWITCH, _UU("SM_LOG_SWITCH_4"), 4);\r
+       CbAddStr(hWnd, C_SEC_SWITCH, _UU("SM_LOG_SWITCH_5"), 5);\r
+       CbAddStr(hWnd, C_PACKET_SWITCH, _UU("SM_LOG_SWITCH_0"), 0);\r
+       CbAddStr(hWnd, C_PACKET_SWITCH, _UU("SM_LOG_SWITCH_1"), 1);\r
+       CbAddStr(hWnd, C_PACKET_SWITCH, _UU("SM_LOG_SWITCH_2"), 2);\r
+       CbAddStr(hWnd, C_PACKET_SWITCH, _UU("SM_LOG_SWITCH_3"), 3);\r
+       CbAddStr(hWnd, C_PACKET_SWITCH, _UU("SM_LOG_SWITCH_4"), 4);\r
+       CbAddStr(hWnd, C_PACKET_SWITCH, _UU("SM_LOG_SWITCH_5"), 5);\r
+\r
+       // ログ設定を取得\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+       if (CALL(hWnd, ScGetHubLog(s->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       Check(hWnd, B_SEC, t.LogSetting.SaveSecurityLog);\r
+       CbSelect(hWnd, C_SEC_SWITCH, t.LogSetting.SecurityLogSwitchType);\r
+\r
+       Check(hWnd, B_PACKET, t.LogSetting.SavePacketLog);\r
+       CbSelect(hWnd, C_PACKET_SWITCH, t.LogSetting.PacketLogSwitchType);\r
+\r
+       Check(hWnd, B_PACKET_0_0, t.LogSetting.PacketLogConfig[0] == 0);\r
+       Check(hWnd, B_PACKET_0_1, t.LogSetting.PacketLogConfig[0] == 1);\r
+       Check(hWnd, B_PACKET_0_2, t.LogSetting.PacketLogConfig[0] == 2);\r
+\r
+       Check(hWnd, B_PACKET_1_0, t.LogSetting.PacketLogConfig[1] == 0);\r
+       Check(hWnd, B_PACKET_1_1, t.LogSetting.PacketLogConfig[1] == 1);\r
+       Check(hWnd, B_PACKET_1_2, t.LogSetting.PacketLogConfig[1] == 2);\r
+\r
+       Check(hWnd, B_PACKET_2_0, t.LogSetting.PacketLogConfig[2] == 0);\r
+       Check(hWnd, B_PACKET_2_1, t.LogSetting.PacketLogConfig[2] == 1);\r
+       Check(hWnd, B_PACKET_2_2, t.LogSetting.PacketLogConfig[2] == 2);\r
+\r
+       Check(hWnd, B_PACKET_3_0, t.LogSetting.PacketLogConfig[3] == 0);\r
+       Check(hWnd, B_PACKET_3_1, t.LogSetting.PacketLogConfig[3] == 1);\r
+       Check(hWnd, B_PACKET_3_2, t.LogSetting.PacketLogConfig[3] == 2);\r
+\r
+       Check(hWnd, B_PACKET_4_0, t.LogSetting.PacketLogConfig[4] == 0);\r
+       Check(hWnd, B_PACKET_4_1, t.LogSetting.PacketLogConfig[4] == 1);\r
+       Check(hWnd, B_PACKET_4_2, t.LogSetting.PacketLogConfig[4] == 2);\r
+\r
+       Check(hWnd, B_PACKET_5_0, t.LogSetting.PacketLogConfig[5] == 0);\r
+       Check(hWnd, B_PACKET_5_1, t.LogSetting.PacketLogConfig[5] == 1);\r
+       Check(hWnd, B_PACKET_5_2, t.LogSetting.PacketLogConfig[5] == 2);\r
+\r
+       Check(hWnd, B_PACKET_6_0, t.LogSetting.PacketLogConfig[6] == 0);\r
+       Check(hWnd, B_PACKET_6_1, t.LogSetting.PacketLogConfig[6] == 1);\r
+       Check(hWnd, B_PACKET_6_2, t.LogSetting.PacketLogConfig[6] == 2);\r
+\r
+       Check(hWnd, B_PACKET_7_0, t.LogSetting.PacketLogConfig[7] == 0);\r
+       Check(hWnd, B_PACKET_7_1, t.LogSetting.PacketLogConfig[7] == 1);\r
+       Check(hWnd, B_PACKET_7_2, t.LogSetting.PacketLogConfig[7] == 2);\r
+\r
+       SmLogDlgUpdate(hWnd, s);\r
+}\r
+\r
+// コントロール更新\r
+void SmLogDlgUpdate(HWND hWnd, SM_HUB *s)\r
+{\r
+       bool b;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = IsChecked(hWnd, B_SEC);\r
+       SetEnable(hWnd, S_SEC, b);\r
+       SetEnable(hWnd, C_SEC_SWITCH, b);\r
+\r
+       b = IsChecked(hWnd, B_PACKET);\r
+       SetEnable(hWnd, S_PACKET, b);\r
+       SetEnable(hWnd, C_PACKET_SWITCH, b);\r
+       SetEnable(hWnd, S_PACKET_0, b);\r
+       SetEnable(hWnd, S_PACKET_1, b);\r
+       SetEnable(hWnd, S_PACKET_2, b);\r
+       SetEnable(hWnd, S_PACKET_3, b);\r
+       SetEnable(hWnd, S_PACKET_4, b);\r
+       SetEnable(hWnd, S_PACKET_5, b);\r
+       SetEnable(hWnd, S_PACKET_6, b);\r
+       SetEnable(hWnd, S_PACKET_7, b);\r
+       SetEnable(hWnd, B_PACKET_0_0, b); SetEnable(hWnd, B_PACKET_0_1, b); SetEnable(hWnd, B_PACKET_0_2, b);\r
+       SetEnable(hWnd, B_PACKET_1_0, b); SetEnable(hWnd, B_PACKET_1_1, b); SetEnable(hWnd, B_PACKET_1_2, b);\r
+       SetEnable(hWnd, B_PACKET_2_0, b); SetEnable(hWnd, B_PACKET_2_1, b); SetEnable(hWnd, B_PACKET_2_2, b);\r
+       SetEnable(hWnd, B_PACKET_3_0, b); SetEnable(hWnd, B_PACKET_3_1, b); SetEnable(hWnd, B_PACKET_3_2, b);\r
+       SetEnable(hWnd, B_PACKET_4_0, b); SetEnable(hWnd, B_PACKET_4_1, b); SetEnable(hWnd, B_PACKET_4_2, b);\r
+       SetEnable(hWnd, B_PACKET_5_0, b); SetEnable(hWnd, B_PACKET_5_1, b); SetEnable(hWnd, B_PACKET_5_2, b);\r
+       SetEnable(hWnd, B_PACKET_6_0, b); SetEnable(hWnd, B_PACKET_6_1, b); SetEnable(hWnd, B_PACKET_6_2, b);\r
+       SetEnable(hWnd, B_PACKET_7_0, b); SetEnable(hWnd, B_PACKET_7_1, b); SetEnable(hWnd, B_PACKET_7_2, b);\r
+}\r
+\r
+// OK\r
+void SmLogDlgOnOk(HWND hWnd, SM_HUB *s)\r
+{\r
+       HUB_LOG g;\r
+       RPC_HUB_LOG t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&g, sizeof(g));\r
+       g.SaveSecurityLog = IsChecked(hWnd, B_SEC);\r
+       g.SavePacketLog = IsChecked(hWnd, B_PACKET);\r
+       g.SecurityLogSwitchType = CbGetSelect(hWnd, C_SEC_SWITCH);\r
+       g.PacketLogSwitchType = CbGetSelect(hWnd, C_PACKET_SWITCH);\r
+\r
+       g.PacketLogConfig[0] = IsChecked(hWnd, B_PACKET_0_0) ? 0 : IsChecked(hWnd, B_PACKET_0_1) ? 1 : 2;\r
+       g.PacketLogConfig[1] = IsChecked(hWnd, B_PACKET_1_0) ? 0 : IsChecked(hWnd, B_PACKET_1_1) ? 1 : 2;\r
+       g.PacketLogConfig[2] = IsChecked(hWnd, B_PACKET_2_0) ? 0 : IsChecked(hWnd, B_PACKET_2_1) ? 1 : 2;\r
+       g.PacketLogConfig[3] = IsChecked(hWnd, B_PACKET_3_0) ? 0 : IsChecked(hWnd, B_PACKET_3_1) ? 1 : 2;\r
+       g.PacketLogConfig[4] = IsChecked(hWnd, B_PACKET_4_0) ? 0 : IsChecked(hWnd, B_PACKET_4_1) ? 1 : 2;\r
+       g.PacketLogConfig[5] = IsChecked(hWnd, B_PACKET_5_0) ? 0 : IsChecked(hWnd, B_PACKET_5_1) ? 1 : 2;\r
+       g.PacketLogConfig[6] = IsChecked(hWnd, B_PACKET_6_0) ? 0 : IsChecked(hWnd, B_PACKET_6_1) ? 1 : 2;\r
+       g.PacketLogConfig[7] = IsChecked(hWnd, B_PACKET_7_0) ? 0 : IsChecked(hWnd, B_PACKET_7_1) ? 1 : 2;\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+       Copy(&t.LogSetting, &g, sizeof(HUB_LOG));\r
+\r
+       if (CALL(hWnd, ScSetHubLog(s->Rpc, &t)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// ログ保存設定ダイアログ\r
+UINT SmLogDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_HUB *s = (SM_HUB *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmLogDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case B_SEC:\r
+               case B_PACKET:\r
+                       SmLogDlgUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // OK ボタン\r
+                       SmLogDlgOnOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// カスケード接続のステータスの表示\r
+bool SmRefreshLinkStatus(HWND hWnd, SM_SERVER *s, void *param)\r
+{\r
+       SM_LINK *k = (SM_LINK *)param;\r
+       RPC_LINK_STATUS t;\r
+       LVB *b;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL || param == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), k->Hub->HubName);\r
+       UniStrCpy(t.AccountName, sizeof(t.AccountName), k->AccountName);\r
+\r
+       if (CALL(hWnd, ScGetLinkStatus(s->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       CmPrintStatusToListView(b, &t.Status);\r
+\r
+       LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+       FreeRpcLinkStatus(&t);\r
+\r
+       return true;\r
+}\r
+\r
+// リンクの編集\r
+bool SmLinkEdit(HWND hWnd, SM_HUB *s, wchar_t *name)\r
+{\r
+       CM_ACCOUNT a;\r
+       RPC_CREATE_LINK t;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&a, sizeof(a));\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+       t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), name);\r
+\r
+       if (CALL(hWnd, ScGetLink(s->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       a.Hub = s;\r
+       a.EditMode = true;\r
+       a.LinkMode = true;\r
+       a.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       a.OnlineFlag = t.Online;\r
+       Copy(a.ClientOption, t.ClientOption, sizeof(CLIENT_OPTION));\r
+       a.ClientAuth = CopyClientAuth(t.ClientAuth);\r
+       Copy(&a.Policy, &t.Policy, sizeof(POLICY));\r
+       a.CheckServerCert = t.CheckServerCert;\r
+       a.ServerCert = CloneX(t.ServerCert);\r
+       a.HideTrustCert = GetCapsBool(s->p->CapsList, "b_support_config_hub");\r
+       FreeRpcCreateLink(&t);\r
+\r
+       a.PolicyVer = s->p->PolicyVer;\r
+\r
+       if (GetCapsBool(s->p->CapsList, "b_support_cascade_client_cert") == false)\r
+       {\r
+               a.HideClientCertAuth = true;\r
+       }\r
+\r
+       a.HideSecureAuth = true;\r
+\r
+       ret = CmEditAccountDlg(hWnd, &a);\r
+\r
+       FreeX(a.ServerCert);\r
+       Free(a.ClientOption);\r
+       CiFreeClientAuth(a.ClientAuth);\r
+\r
+       return ret;\r
+}\r
+\r
+// 新しいリンクの作成\r
+bool SmLinkCreate(HWND hWnd, SM_HUB *s)\r
+{\r
+       return SmLinkCreateEx(hWnd, s, false);\r
+}\r
+bool SmLinkCreateEx(HWND hWnd, SM_HUB *s, bool connectNow)\r
+{\r
+       CM_ACCOUNT a;\r
+       bool ret = false;;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&a, sizeof(a));\r
+\r
+       a.Hub = s;\r
+       a.EditMode = false;\r
+       a.LinkMode = true;\r
+       a.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));\r
+       a.OnlineFlag = false;\r
+       a.ClientAuth = ZeroMalloc(sizeof(CLIENT_AUTH));\r
+       a.ClientAuth->AuthType = CLIENT_AUTHTYPE_PASSWORD;\r
+       Copy(&a.Policy, GetDefaultPolicy(), sizeof(POLICY));\r
+       a.ClientOption->Port = 443;     // デフォルトポート番号\r
+       a.ClientOption->NumRetry = INFINITE;\r
+       a.ClientOption->RetryInterval = 15;\r
+       a.ClientOption->MaxConnection = 8;\r
+       a.ClientOption->UseEncrypt = true;\r
+       a.ClientOption->HalfConnection = false;\r
+       a.ClientOption->AdditionalConnectionInterval = 1;\r
+       a.ClientOption->RequireBridgeRoutingMode = true;\r
+       a.Link_ConnectNow = connectNow;\r
+\r
+       a.PolicyVer = s->p->PolicyVer;\r
+\r
+       if (GetCapsBool(s->p->CapsList, "b_support_cascade_client_cert") == false)\r
+       {\r
+               a.HideClientCertAuth = true;\r
+       }\r
+\r
+       a.HideSecureAuth = true;\r
+\r
+       ret = CmEditAccountDlg(hWnd, &a);\r
+\r
+       FreeX(a.ServerCert);\r
+       Free(a.ClientOption);\r
+       CiFreeClientAuth(a.ClientAuth);\r
+\r
+       return ret;\r
+}\r
+\r
+// 初期化\r
+void SmLinkDlgInit(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_LINK);\r
+\r
+       FormatText(hWnd, 0, s->HubName);\r
+\r
+       LvInit(hWnd, L_LINK);\r
+\r
+       LvInsertColumn(hWnd, L_LINK, 0, _UU("SM_LINK_COLUMN_1"), 120);\r
+       LvInsertColumn(hWnd, L_LINK, 1, _UU("SM_LINK_COLUMN_2"), 150);\r
+       LvInsertColumn(hWnd, L_LINK, 2, _UU("SM_LINK_COLUMN_3"), 180);\r
+       LvInsertColumn(hWnd, L_LINK, 3, _UU("SM_LINK_COLUMN_4"), 130);\r
+       LvInsertColumn(hWnd, L_LINK, 4, _UU("SM_LINK_COLUMN_5"), 130);\r
+\r
+       LvSetStyle(hWnd, L_LINK, LVS_EX_GRIDLINES);\r
+\r
+       SmLinkDlgRefresh(hWnd, s);\r
+}\r
+\r
+// コントロール更新\r
+void SmLinkDlgUpdate(HWND hWnd, SM_HUB *s)\r
+{\r
+       bool ok = true;\r
+       bool online = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSelected(hWnd, L_LINK) == false || LvIsMultiMasked(hWnd, L_LINK))\r
+       {\r
+               ok = false;\r
+       }\r
+       else\r
+       {\r
+               online = (bool)LvGetParam(hWnd, L_LINK, LvGetSelected(hWnd, L_LINK));\r
+       }\r
+\r
+       SetEnable(hWnd, B_EDIT, ok);\r
+       SetEnable(hWnd, B_ONLINE, ok && (online == false));\r
+       SetEnable(hWnd, B_OFFLINE, ok && online);\r
+       SetEnable(hWnd, IDOK, ok && online);\r
+       SetEnable(hWnd, B_DELETE, ok);\r
+       SetEnable(hWnd, B_RENAME, ok);\r
+}\r
+\r
+// 内容更新\r
+void SmLinkDlgRefresh(HWND hWnd, SM_HUB *s)\r
+{\r
+       LVB *b;\r
+       RPC_ENUM_LINK t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+       if (CALL(hWnd, ScEnumLink(s->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       for (i = 0;i < t.NumLink;i++)\r
+       {\r
+               RPC_ENUM_LINK_ITEM *e = &t.Links[i];\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               wchar_t tmp3[MAX_SIZE];\r
+               wchar_t tmp4[MAX_SIZE];\r
+               UINT icon = ICO_CASCADE;\r
+\r
+               GetDateTimeStrEx64(tmp1, sizeof(tmp1), SystemToLocal64(e->ConnectedTime), NULL);\r
+               StrToUni(tmp2, sizeof(tmp2), e->Hostname);\r
+               StrToUni(tmp3, sizeof(tmp3), e->HubName);\r
+\r
+               if (e->Online == false)\r
+               {\r
+                       UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_LINK_STATUS_OFFLINE"));\r
+               }\r
+               else\r
+               {\r
+                       if (e->Connected)\r
+                       {\r
+                               UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_LINK_STATUS_ONLINE"));\r
+                       }\r
+                       else\r
+                       {\r
+                               if (e->LastError != 0)\r
+                               {\r
+                                       UniFormat(tmp4, sizeof(tmp4), _UU("SM_LINK_STATUS_ERROR"), e->LastError, _E(e->LastError));\r
+                               }\r
+                               else\r
+                               {\r
+                                       UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_LINK_CONNECTING"));\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (e->Online == false)\r
+               {\r
+                       icon = ICO_CASCADE_OFFLINE;\r
+               }\r
+               else\r
+               {\r
+                       if (e->Connected == false && e->LastError != 0)\r
+                       {\r
+                               icon = ICO_CASCADE_ERROR;\r
+                       }\r
+                       else\r
+                       {\r
+                               icon = ICO_CASCADE;\r
+                       }\r
+               }\r
+\r
+               LvInsertAdd(b,\r
+                       icon, (void *)e->Online, 5,\r
+                       e->AccountName, tmp4, tmp1, tmp2, tmp3);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_LINK);\r
+\r
+       FreeRpcEnumLink(&t);\r
+\r
+       SmLinkDlgUpdate(hWnd, s);\r
+}\r
+\r
+\r
+// リンク一覧ダイアログプロシージャ\r
+UINT SmLinkDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_HUB *s = (SM_HUB *)param;\r
+       wchar_t *str;\r
+       NMHDR *n;\r
+       NMLVDISPINFOW *disp_info;\r
+       NMLVKEYDOWN *key;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       str = LvGetSelectedStr(hWnd, L_LINK, 0);\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmLinkDlgInit(hWnd, s);\r
+\r
+               if (link_create_now)\r
+               {\r
+                       if (SmLinkCreateEx(hWnd, s, true))\r
+                       {\r
+                               SmLinkDlgRefresh(hWnd, s);\r
+                       }\r
+               }\r
+\r
+               SetTimer(hWnd, 1, 1000, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       SmLinkDlgRefresh(hWnd, s);\r
+                       SetTimer(hWnd, 1, 1000, NULL);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_CREATE:\r
+                       // 新規作成\r
+                       if (SmLinkCreate(hWnd, s))\r
+                       {\r
+                               SmLinkDlgRefresh(hWnd, s);\r
+                       }\r
+                       break;\r
+\r
+               case B_EDIT:\r
+                       // 編集\r
+                       if (str != NULL)\r
+                       {\r
+                               if (SmLinkEdit(hWnd, s, str))\r
+                               {\r
+                                       SmLinkDlgRefresh(hWnd, s);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_ONLINE:\r
+                       // オンライン\r
+                       if (str != NULL)\r
+                       {\r
+                               RPC_LINK t;\r
+                               Zero(&t, sizeof(t));\r
+                               UniStrCpy(t.AccountName, sizeof(t.AccountName), str);\r
+                               StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+\r
+                               if (CALL(hWnd, ScSetLinkOnline(s->Rpc, &t)))\r
+                               {\r
+                                       SmLinkDlgRefresh(hWnd, s);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_OFFLINE:\r
+                       // オフライン\r
+                       if (str != NULL)\r
+                       {\r
+                               RPC_LINK t;\r
+                               Zero(&t, sizeof(t));\r
+                               UniStrCpy(t.AccountName, sizeof(t.AccountName), str);\r
+                               StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+\r
+                               if (MsgBoxEx(hWnd, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2,\r
+                                       _UU("SM_LINK_OFFLINE_MSG"), t.AccountName) == IDYES)\r
+                               {\r
+                                       if (CALL(hWnd, ScSetLinkOffline(s->Rpc, &t)))\r
+                                       {\r
+                                               SmLinkDlgRefresh(hWnd, s);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDOK:\r
+                       // 状態\r
+                       if (str != NULL)\r
+                       {\r
+                               wchar_t tmp[MAX_SIZE];\r
+                               SM_LINK t;\r
+                               Zero(&t, sizeof(t));\r
+                               t.Hub = s;\r
+                               t.AccountName = str;\r
+                               UniFormat(tmp, sizeof(tmp), _UU("SM_LINK_STATUS_CAPTION"), str);\r
+                               SmStatusDlg(hWnd, s->p, &t, true, true, tmp,\r
+                                       ICO_CASCADE, NULL, SmRefreshLinkStatus);\r
+                       }\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       // 削除\r
+                       if (str != NULL)\r
+                       {\r
+                               RPC_LINK t;\r
+                               Zero(&t, sizeof(t));\r
+                               UniStrCpy(t.AccountName, sizeof(t.AccountName), str);\r
+                               StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+\r
+                               if (MsgBoxEx(hWnd, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2,\r
+                                       _UU("SM_LINK_DELETE_MSG"), t.AccountName) == IDYES)\r
+                               {\r
+                                       if (CALL(hWnd, ScDeleteLink(s->Rpc, &t)))\r
+                                       {\r
+                                               SmLinkDlgRefresh(hWnd, s);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       // 更新\r
+                       SmLinkDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_RENAME:\r
+                       // 名前の変更\r
+                       Focus(hWnd, L_LINK);\r
+                       LvRename(hWnd, L_LINK, LvGetSelected(hWnd, L_LINK));\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_LINK:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               // 選択状態の変更\r
+                               SmLinkDlgUpdate(hWnd, s);\r
+                               break;\r
+\r
+                       case LVN_ENDLABELEDITW:\r
+                               // 名前の変更\r
+                               disp_info = (NMLVDISPINFOW *)n;\r
+                               if (disp_info->item.pszText != NULL)\r
+                               {\r
+                                       wchar_t *new_name = disp_info->item.pszText;\r
+                                       wchar_t *old_name = LvGetStr(hWnd, L_LINK, disp_info->item.iItem, 0);\r
+\r
+                                       if (old_name != NULL)\r
+                                       {\r
+                                               if (UniStrCmp(new_name, old_name) != 0 && UniIsEmptyStr(new_name) == false)\r
+                                               {\r
+                                                       RPC_RENAME_LINK t;\r
+                                                       Zero(&t, sizeof(t));\r
+                                                       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+                                                       UniStrCpy(t.OldAccountName, sizeof(t.OldAccountName), old_name);\r
+                                                       UniStrCpy(t.NewAccountName, sizeof(t.NewAccountName), new_name);\r
+                                                       if (CALL(hWnd, ScRenameLink(s->Rpc, &t)))\r
+                                                       {\r
+                                                               SmLinkDlgRefresh(hWnd, s);\r
+                                                       }\r
+                                               }\r
+\r
+                                               Free(old_name);\r
+                                       }\r
+                               }\r
+                               break;\r
+\r
+                       case LVN_KEYDOWN:\r
+                               // キー押下\r
+                               key = (NMLVKEYDOWN *)n;\r
+                               if (key != NULL)\r
+                               {\r
+                                       bool ctrl, alt;\r
+                                       UINT code = key->wVKey;\r
+                                       ctrl = (GetKeyState(VK_CONTROL) & 0x8000) == 0 ? false : true;\r
+                                       alt = (GetKeyState(VK_MENU) & 0x8000) == 0 ? false : true;\r
+\r
+                                       if (code == VK_F2)\r
+                                       {\r
+                                               Command(hWnd, B_RENAME);\r
+                                       }\r
+                               }\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       Free(str);\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_LINK);\r
+\r
+       return 0;\r
+}\r
+\r
+// リンク一覧ダイアログ\r
+void SmLinkDlg(HWND hWnd, SM_HUB *s)\r
+{\r
+       SmLinkDlgEx(hWnd, s, false);\r
+}\r
+void SmLinkDlgEx(HWND hWnd, SM_HUB *s, bool createNow)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       link_create_now = createNow;\r
+\r
+       Dialog(hWnd, D_SM_LINK, SmLinkDlgProc, s);\r
+}\r
+\r
+// 初期化\r
+void SmRadiusDlgInit(HWND hWnd, SM_HUB *s)\r
+{\r
+       RPC_RADIUS t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_TOWER);\r
+\r
+       FormatText(hWnd, S_TITLE, s->HubName);\r
+       FormatText(hWnd, S_RADIUS_7, RADIUS_RETRY_INTERVAL, RADIUS_RETRY_TIMEOUT);\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+\r
+       if (CALL(hWnd, ScGetHubRadius(s->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       Check(hWnd, R_USE_RADIUS, StrLen(t.RadiusServerName) != 0);\r
+\r
+       if (StrLen(t.RadiusServerName) != 0)\r
+       {\r
+               SetTextA(hWnd, E_HOSTNAME, t.RadiusServerName);\r
+               SetIntEx(hWnd, E_PORT, t.RadiusPort);\r
+               SetTextA(hWnd, E_SECRET1, t.RadiusSecret);\r
+               SetTextA(hWnd, E_SECRET2, t.RadiusSecret);\r
+               SetIntEx(hWnd, E_RADIUS_RETRY_INTERVAL, t.RadiusRetryInterval);\r
+               FocusEx(hWnd, E_HOSTNAME);\r
+       }\r
+       else\r
+       {\r
+               SetInt(hWnd, E_PORT, RADIUS_DEFAULT_PORT);\r
+               SetInt(hWnd, E_RADIUS_RETRY_INTERVAL, RADIUS_RETRY_INTERVAL);\r
+       }\r
+\r
+       SmRadiusDlgUpdate(hWnd, s);\r
+}\r
+\r
+// コントロール更新\r
+void SmRadiusDlgUpdate(HWND hWnd, SM_HUB *s)\r
+{\r
+       bool ok = true;\r
+       bool b, b1;\r
+       char tmp1[MAX_SIZE];\r
+       char tmp2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b1 = GetCapsBool(s->p->CapsList, "b_support_radius_retry_interval_and_several_servers");\r
+       if(b1 == false)\r
+       {\r
+               Hide(hWnd, S_RADIUS_7);\r
+               Hide(hWnd, S_RADIUS_8);\r
+               Hide(hWnd, S_RADIUS_9);\r
+               Hide(hWnd, E_RADIUS_RETRY_INTERVAL);\r
+       }\r
+\r
+       b = IsChecked(hWnd, R_USE_RADIUS);\r
+\r
+       SetEnable(hWnd, S_RADIUS_1, b);\r
+       SetEnable(hWnd, S_RADIUS_2, b);\r
+       SetEnable(hWnd, S_RADIUS_3, b);\r
+       SetEnable(hWnd, S_RADIUS3, b);\r
+       SetEnable(hWnd, S_RADIUS_4, b);\r
+       SetEnable(hWnd, S_RADIUS_5, b);\r
+       SetEnable(hWnd, S_RADIUS_6, b);\r
+       SetEnable(hWnd, S_RADIUS_7, b);\r
+       SetEnable(hWnd, S_RADIUS_8, b);\r
+       SetEnable(hWnd, S_RADIUS_9, b);\r
+       SetEnable(hWnd, E_HOSTNAME, b);\r
+       SetEnable(hWnd, E_PORT, b);\r
+       SetEnable(hWnd, E_SECRET1, b);\r
+       SetEnable(hWnd, E_SECRET2, b);\r
+       SetEnable(hWnd, E_RADIUS_RETRY_INTERVAL, b);\r
+\r
+       if (b)\r
+       {\r
+               UINT p, m;\r
+               GetTxtA(hWnd, E_SECRET1, tmp1, sizeof(tmp1));\r
+               GetTxtA(hWnd, E_SECRET2, tmp2, sizeof(tmp2));\r
+\r
+               if (StrCmp(tmp1, tmp2) != 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               if (IsEmpty(hWnd, E_HOSTNAME))\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               p = GetInt(hWnd, E_PORT);\r
+\r
+               if (p == 0 || p >= 65536)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               m = GetInt(hWnd, E_RADIUS_RETRY_INTERVAL);\r
+               if (m > RADIUS_RETRY_TIMEOUT || m < RADIUS_RETRY_INTERVAL)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// OK ボタン\r
+void SmRadiusDlgOnOk(HWND hWnd, SM_HUB *s)\r
+{\r
+       RPC_RADIUS t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+\r
+       if (IsChecked(hWnd, R_USE_RADIUS))\r
+       {\r
+               GetTxtA(hWnd, E_HOSTNAME, t.RadiusServerName, sizeof(t.RadiusServerName));\r
+               t.RadiusPort = GetInt(hWnd, E_PORT);\r
+               GetTxtA(hWnd, E_SECRET1,t.RadiusSecret, sizeof(t.RadiusSecret));\r
+               t.RadiusRetryInterval = GetInt(hWnd, E_RADIUS_RETRY_INTERVAL);\r
+       }\r
+\r
+       if (CALL(hWnd, ScSetHubRadius(s->Rpc, &t)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+\r
+// Radius ダイアログ プロシージャ\r
+UINT SmRadiusDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_HUB *s = (SM_HUB *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmRadiusDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_HOSTNAME:\r
+               case E_PORT:\r
+               case E_SECRET1:\r
+               case E_SECRET2:\r
+               case E_RADIUS_RETRY_INTERVAL:\r
+               case R_USE_RADIUS:\r
+                       SmRadiusDlgUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // OK ボタン\r
+                       SmRadiusDlgOnOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case R_USE_RADIUS:\r
+                       if (IsChecked(hWnd, R_USE_RADIUS))\r
+                       {\r
+                               FocusEx(hWnd, E_HOSTNAME);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// Radius 設定ダイアログ\r
+void SmRadiusDlg(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_SM_RADIUS, SmRadiusDlgProc, s);\r
+}\r
+\r
+\r
+// 初期化\r
+void SmEditAccessInit(HWND hWnd, SM_EDIT_ACCESS *s)\r
+{\r
+       ACCESS *a;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_PASS);\r
+\r
+       GetTxt(hWnd, 0, tmp, sizeof(tmp));\r
+\r
+       UniStrCat(tmp, sizeof(tmp), s->Access->IsIPv6 ? L" (IPv6)" : L" (IPv4)");\r
+\r
+       SetText(hWnd, 0, tmp);\r
+\r
+       s->Inited = false;\r
+       a = s->Access;\r
+\r
+       SetText(hWnd, E_NOTE, a->Note);\r
+\r
+       Check(hWnd, R_DISCARD, a->Discard);\r
+       Check(hWnd, R_PASS, a->Discard == false);\r
+       SetIntEx(hWnd, E_PRIORITY, a->Priority);\r
+\r
+       if (a->IsIPv6 == false)\r
+       {\r
+               // IPv4\r
+               if (a->SrcIpAddress == 0 && a->SrcSubnetMask == 0)\r
+               {\r
+                       Check(hWnd, R_SRC_ALL, true);\r
+               }\r
+               else\r
+               {\r
+                       IpSet(hWnd, E_SRC_IP, a->SrcIpAddress);\r
+                       IpSet(hWnd, E_SRC_MASK, a->SrcSubnetMask);\r
+               }\r
+\r
+               if (a->DestIpAddress == 0 && a->DestSubnetMask == 0)\r
+               {\r
+                       Check(hWnd, R_DST_ALL, true);\r
+               }\r
+               else\r
+               {\r
+                       IpSet(hWnd, E_DST_IP, a->DestIpAddress);\r
+                       IpSet(hWnd, E_DST_MASK, a->DestSubnetMask);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // IPv6\r
+               if (IsZeroIP6Addr(&a->SrcIpAddress6) && IsZeroIP6Addr(&a->SrcSubnetMask6))\r
+               {\r
+                       Check(hWnd, R_SRC_ALL, true);\r
+               }\r
+               else\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+\r
+                       IP6AddrToStr(tmp, sizeof(tmp), &a->SrcIpAddress6);\r
+                       SetTextA(hWnd, E_SRC_IP_V6, tmp);\r
+\r
+                       Mask6AddrToStrEx(tmp, sizeof(tmp), &a->SrcSubnetMask6, false);\r
+\r
+                       if (IsNum(tmp))\r
+                       {\r
+                               StrCatLeft(tmp, sizeof(tmp), "/");\r
+                       }\r
+\r
+                       SetTextA(hWnd, E_SRC_MASK_V6, tmp);\r
+               }\r
+\r
+               if (IsZeroIP6Addr(&a->DestIpAddress6) && IsZeroIP6Addr(&a->DestSubnetMask6))\r
+               {\r
+                       Check(hWnd, R_DST_ALL, true);\r
+               }\r
+               else\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+\r
+                       IP6AddrToStr(tmp, sizeof(tmp), &a->DestIpAddress6);\r
+                       SetTextA(hWnd, E_DST_IP_V6, tmp);\r
+\r
+                       Mask6AddrToStrEx(tmp, sizeof(tmp), &a->DestSubnetMask6, false);\r
+\r
+                       if (IsNum(tmp))\r
+                       {\r
+                               StrCatLeft(tmp, sizeof(tmp), "/");\r
+                       }\r
+\r
+                       SetTextA(hWnd, E_DST_MASK_V6, tmp);\r
+               }\r
+       }\r
+\r
+       CbSetHeight(hWnd, C_PROTOCOL, 18);\r
+       CbAddStr(hWnd, C_PROTOCOL, _UU("SM_ACCESS_PROTO_1"), 0);\r
+       CbAddStr(hWnd, C_PROTOCOL, _UU("SM_ACCESS_PROTO_2"), 0);\r
+       CbAddStr(hWnd, C_PROTOCOL, _UU("SM_ACCESS_PROTO_3"), 0);\r
+       CbAddStr(hWnd, C_PROTOCOL, _UU("SM_ACCESS_PROTO_4"), 0);\r
+       CbAddStr(hWnd, C_PROTOCOL, _UU("SM_ACCESS_PROTO_5"), 0);\r
+       CbAddStr(hWnd, C_PROTOCOL, _UU("SM_ACCESS_PROTO_6"), 0);\r
+\r
+       switch (a->Protocol)\r
+       {\r
+       case 0:\r
+               CbSelectIndex(hWnd, C_PROTOCOL, 0);\r
+               break;\r
+       case 6:\r
+               CbSelectIndex(hWnd, C_PROTOCOL, 1);\r
+               break;\r
+       case 17:\r
+               CbSelectIndex(hWnd, C_PROTOCOL, 2);\r
+               break;\r
+       case 1:\r
+               CbSelectIndex(hWnd, C_PROTOCOL, 3);\r
+               break;\r
+       case 58:\r
+               CbSelectIndex(hWnd, C_PROTOCOL, 4);\r
+               break;\r
+       default:\r
+               CbSelectIndex(hWnd, C_PROTOCOL, 5);\r
+               break;\r
+       }\r
+\r
+       Check(hWnd, R_DISABLE, a->Active ? false : true);\r
+\r
+       SetIntEx(hWnd, E_IP_PROTO, a->Protocol);\r
+\r
+       SetIntEx(hWnd, E_SRC_PORT_1, a->SrcPortStart);\r
+       SetIntEx(hWnd, E_SRC_PORT_2, a->SrcPortEnd);\r
+       SetIntEx(hWnd, E_DST_PORT_1, a->DestPortStart);\r
+       SetIntEx(hWnd, E_DST_PORT_2, a->DestPortEnd);\r
+\r
+       SetTextA(hWnd, E_USERNAME1, a->SrcUsername);\r
+       SetTextA(hWnd, E_USERNAME2, a->DestUsername);\r
+\r
+       if(a->CheckSrcMac != false)\r
+       {\r
+               char mac[MAX_SIZE], mask[MAX_SIZE];\r
+               MacToStr(mac, sizeof(mac), a->SrcMacAddress);\r
+               MacToStr(mask, sizeof(mask), a->SrcMacMask);\r
+               SetTextA(hWnd, E_SRC_MAC, mac); \r
+               SetTextA(hWnd, E_SRC_MAC_MASK, mask);\r
+       }\r
+       if(a->CheckDstMac != false)\r
+       {\r
+               char mac[MAX_SIZE], mask[MAX_SIZE];\r
+               MacToStr(mac, sizeof(mac), a->DstMacAddress);\r
+               MacToStr(mask, sizeof(mask), a->DstMacMask);\r
+               SetTextA(hWnd, E_DST_MAC, mac); \r
+               SetTextA(hWnd, E_DST_MAC_MASK, mask);\r
+       }\r
+       Check(hWnd, R_CHECK_SRC_MAC, !a->CheckSrcMac);\r
+       Check(hWnd, R_CHECK_DST_MAC, !a->CheckDstMac);\r
+\r
+       Check(hWnd, R_CHECK_TCP_STATE, a->CheckTcpState);\r
+       if(a->CheckTcpState != false)\r
+       {\r
+               Check(hWnd, R_ESTABLISHED, a->Established);\r
+               Check(hWnd, R_UNESTABLISHED, !a->Established);\r
+       }\r
+\r
+       if (GetCapsBool(s->Hub->p->CapsList, "b_support_acl_group") == false)\r
+       {\r
+               SetText(hWnd, S_STATIC11, _UU("D_SM_EDIT_ACCESS@STATIC11_OLD"));\r
+               SetText(hWnd, S_STATIC12, _UU("D_SM_EDIT_ACCESS@STATIC12_OLD"));\r
+               SetText(hWnd, S_STATIC15, _UU("D_SM_EDIT_ACCESS@STATIC15_OLD"));\r
+       }\r
+\r
+       s->Inited = true;\r
+\r
+       SmEditAccessUpdate(hWnd, s);\r
+}\r
+\r
+// コントロール更新\r
+void SmEditAccessUpdate(HWND hWnd, SM_EDIT_ACCESS *s)\r
+{\r
+       bool ok = true;\r
+       bool tcp;\r
+       bool b;\r
+       bool check_srcmac, check_dstmac, support_mac;\r
+       bool check_state, support_check_state;\r
+       char srcmac[MAX_SIZE], srcmac_mask[MAX_SIZE], dstmac[MAX_SIZE], dstmac_mask[MAX_SIZE];\r
+       char tmp[MAX_SIZE];\r
+       wchar_t unitmp[MAX_SIZE];\r
+       ACCESS *a;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->Inited == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       a = s->Access;\r
+\r
+       GetTxt(hWnd, E_NOTE, a->Note, sizeof(a->Note));\r
+\r
+       a->Discard = IsChecked(hWnd, R_DISCARD);\r
+\r
+       a->Priority = GetInt(hWnd, E_PRIORITY);\r
+       if (a->Priority == 0)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+\r
+       b = IsChecked(hWnd, R_SRC_ALL) ? false : true;\r
+       if (b == false)\r
+       {\r
+               if (a->IsIPv6 == false)\r
+               {\r
+                       a->SrcIpAddress = 0;\r
+                       a->SrcSubnetMask = 0;\r
+               }\r
+               else\r
+               {\r
+                       Zero(&a->SrcIpAddress6, sizeof(IPV6_ADDR));\r
+                       Zero(&a->SrcSubnetMask6, sizeof(IPV6_ADDR));\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (a->IsIPv6 == false)\r
+               {\r
+                       if (IpIsFilled(hWnd, E_SRC_IP) == false || IpIsFilled(hWnd, E_SRC_MASK) == false)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+                       else\r
+                       {\r
+                               a->SrcIpAddress = IpGet(hWnd, E_SRC_IP);\r
+                               a->SrcSubnetMask = IpGet(hWnd, E_SRC_MASK);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       char tmp1[MAX_SIZE];\r
+                       char tmp2[MAX_SIZE];\r
+\r
+                       GetTxtA(hWnd, E_SRC_IP_V6, tmp1, sizeof(tmp1));\r
+                       GetTxtA(hWnd, E_SRC_MASK_V6, tmp2, sizeof(tmp2));\r
+\r
+                       if (StrToIP6Addr(&a->SrcIpAddress6, tmp1) == false ||\r
+                               StrToMask6Addr(&a->SrcSubnetMask6, tmp2) == false)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+               }\r
+       }\r
+       SetEnable(hWnd, S_SRC_IP_1, b);\r
+       SetEnable(hWnd, S_SRC_IP_2, b);\r
+       SetEnable(hWnd, S_SRC_IP_3, b);\r
+       SetEnable(hWnd, E_SRC_IP, b);\r
+       SetEnable(hWnd, E_SRC_MASK, b);\r
+       SetEnable(hWnd, E_SRC_IP_V6, b);\r
+       SetEnable(hWnd, E_SRC_MASK_V6, b);\r
+\r
+       b = IsChecked(hWnd, R_DST_ALL) ? false : true;\r
+       if (b == false)\r
+       {\r
+               if (a->IsIPv6 == false)\r
+               {\r
+                       a->DestIpAddress = 0;\r
+                       a->DestSubnetMask = 0;\r
+               }\r
+               else\r
+               {\r
+                       Zero(&a->DestIpAddress6, sizeof(IPV6_ADDR));\r
+                       Zero(&a->DestSubnetMask6, sizeof(IPV6_ADDR));\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (a->IsIPv6 == false)\r
+               {\r
+                       if (IpIsFilled(hWnd, E_DST_IP) == false || IpIsFilled(hWnd, E_DST_MASK) == false)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+                       else\r
+                       {\r
+                               a->DestIpAddress = IpGet(hWnd, E_DST_IP);\r
+                               a->DestSubnetMask = IpGet(hWnd, E_DST_MASK);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       char tmp1[MAX_SIZE];\r
+                       char tmp2[MAX_SIZE];\r
+\r
+                       GetTxtA(hWnd, E_DST_IP_V6, tmp1, sizeof(tmp1));\r
+                       GetTxtA(hWnd, E_DST_MASK_V6, tmp2, sizeof(tmp2));\r
+\r
+                       if (StrToIP6Addr(&a->DestIpAddress6, tmp1) == false ||\r
+                               StrToMask6Addr(&a->DestSubnetMask6, tmp2) == false)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+               }\r
+       }\r
+       SetEnable(hWnd, S_IP_DST_1, b);\r
+       SetEnable(hWnd, S_IP_DST_2, b);\r
+       SetEnable(hWnd, S_IP_DST_3, b);\r
+       SetEnable(hWnd, E_DST_IP, b);\r
+       SetEnable(hWnd, E_DST_MASK, b);\r
+       SetEnable(hWnd, E_DST_IP_V6, b);\r
+       SetEnable(hWnd, E_DST_MASK_V6, b);\r
+\r
+       a->Protocol = GetInt(hWnd, C_PROTOCOL);\r
+\r
+       GetTxtA(hWnd, C_PROTOCOL, tmp, sizeof(tmp));\r
+       GetTxt(hWnd, C_PROTOCOL, unitmp, sizeof(unitmp));\r
+\r
+       if (UniStrCmpi(unitmp, _UU("SM_ACCESS_PROTO_6")) == 0 || StrCmpi(tmp, _SS("SM_ACCESS_PROTO_6")) == 0)\r
+       {\r
+               a->Protocol = GetInt(hWnd, E_IP_PROTO);\r
+\r
+               if (IsEmpty(hWnd, E_IP_PROTO))\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               Enable(hWnd, S_PROTOID);\r
+               Enable(hWnd, E_IP_PROTO);\r
+       }\r
+       else\r
+       {\r
+               Disable(hWnd, E_IP_PROTO);\r
+               Disable(hWnd, S_PROTOID);\r
+       }\r
+\r
+       tcp = false;\r
+       if (a->Protocol == 17 || a->Protocol == 6)\r
+       {\r
+               tcp = true;\r
+       }\r
+\r
+       SetEnable(hWnd, S_TCP_1, tcp);\r
+       SetEnable(hWnd, S_TCP_2, tcp);\r
+       SetEnable(hWnd, S_TCP_3, tcp);\r
+       SetEnable(hWnd, S_TCP_4, tcp);\r
+       SetEnable(hWnd, S_TCP_5, tcp);\r
+       SetEnable(hWnd, S_TCP_6, tcp);\r
+       SetEnable(hWnd, S_TCP_7, tcp);\r
+       SetEnable(hWnd, E_SRC_PORT_1, tcp);\r
+       SetEnable(hWnd, E_SRC_PORT_2, tcp);\r
+       SetEnable(hWnd, E_DST_PORT_1, tcp);\r
+       SetEnable(hWnd, E_DST_PORT_2, tcp);\r
+\r
+       if (tcp == false)\r
+       {\r
+               a->SrcPortEnd = a->SrcPortStart = a->DestPortEnd = a->DestPortStart = 0;\r
+       }\r
+       else\r
+       {\r
+               a->SrcPortStart = GetInt(hWnd, E_SRC_PORT_1);\r
+               a->SrcPortEnd = GetInt(hWnd, E_SRC_PORT_2);\r
+               a->DestPortStart = GetInt(hWnd, E_DST_PORT_1);\r
+               a->DestPortEnd = GetInt(hWnd, E_DST_PORT_2);\r
+\r
+               if (a->SrcPortStart != 0)\r
+               {\r
+                       if (a->SrcPortEnd != 0)\r
+                       {\r
+                               if (a->SrcPortStart > a->SrcPortEnd)\r
+                               {\r
+                                       ok = false;\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if (a->SrcPortEnd != 0)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+               }\r
+\r
+               if (a->DestPortStart != 0)\r
+               {\r
+                       if (a->DestPortEnd != 0)\r
+                       {\r
+                               if (a->DestPortStart > a->DestPortEnd)\r
+                               {\r
+                                       ok = false;\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if (a->DestPortEnd != 0)\r
+                       {\r
+                               ok = false;\r
+                       }\r
+               }\r
+\r
+               if (a->DestPortEnd < a->DestPortStart)\r
+               {\r
+                       a->DestPortEnd = a->DestPortStart;\r
+               }\r
+\r
+               if (a->SrcPortEnd < a->SrcPortStart)\r
+               {\r
+                       a->SrcPortEnd = a->SrcPortStart;\r
+               }\r
+       }\r
+\r
+       a->SrcUsernameHash = a->DestUsernameHash = 0;\r
+       GetTxtA(hWnd, E_USERNAME1, a->SrcUsername, sizeof(a->SrcUsername));\r
+       GetTxtA(hWnd, E_USERNAME2, a->DestUsername, sizeof(a->DestUsername));\r
+\r
+       Trim(a->SrcUsername);\r
+       /*\r
+       if (StrLen(a->SrcUsername) != 0)\r
+       {\r
+               if (IsUserName(a->SrcUsername) == false)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }*/\r
+\r
+       Trim(a->DestUsername);\r
+       /*\r
+       if (StrLen(a->DestUsername) != 0)\r
+       {\r
+               if (IsUserName(a->DestUsername) == false)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }*/\r
+\r
+       support_mac = GetCapsBool(s->Hub->p->CapsList, "b_support_check_mac");\r
+\r
+       // 送信元 MAC アドレスの設定\r
+       check_srcmac = a->CheckSrcMac = support_mac && (IsChecked(hWnd, R_CHECK_SRC_MAC) ? false : true);\r
+       if(check_srcmac == false)\r
+       {\r
+               Zero(a->SrcMacAddress, sizeof(a->SrcMacAddress));\r
+               Zero(a->SrcMacMask, sizeof(a->SrcMacMask));\r
+       }\r
+       else\r
+       {\r
+               GetTxtA(hWnd, E_SRC_MAC, srcmac, sizeof(srcmac));\r
+               GetTxtA(hWnd, E_SRC_MAC_MASK, srcmac_mask, sizeof(srcmac_mask));\r
+               Trim(srcmac);\r
+               Trim(srcmac_mask);\r
+               if(StrLen(srcmac) != 0 && StrLen(srcmac_mask) != 0)\r
+               {\r
+                       UCHAR mac[6], mask[6];\r
+                       if(StrToMac(mac, srcmac) && StrToMac(mask, srcmac_mask))\r
+                       {\r
+                               Copy(a->SrcMacAddress, mac, 6);\r
+                               Copy(a->SrcMacMask, mask, 6);\r
+                       }\r
+                       else\r
+                       {\r
+                               ok = false;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+       SetEnable(hWnd, S_CHECK_SRC_MAC, support_mac);\r
+       SetEnable(hWnd, R_CHECK_SRC_MAC, support_mac);\r
+       SetEnable(hWnd, S_SRC_MAC, check_srcmac);\r
+       SetEnable(hWnd, S_SRC_MAC_MASK, check_srcmac);\r
+       SetEnable(hWnd, E_SRC_MAC, check_srcmac);\r
+       SetEnable(hWnd, E_SRC_MAC_MASK, check_srcmac);\r
+\r
+       // 宛先 MAC アドレスの設定\r
+       check_dstmac = a->CheckDstMac = support_mac && (IsChecked(hWnd, R_CHECK_DST_MAC) ? false : true);\r
+       if(check_dstmac == false)\r
+       {\r
+               Zero(a->DstMacAddress, sizeof(a->DstMacAddress));\r
+               Zero(a->DstMacMask, sizeof(a->DstMacMask));\r
+       }\r
+       else\r
+       {\r
+               GetTxtA(hWnd, E_DST_MAC, dstmac, sizeof(dstmac));\r
+               GetTxtA(hWnd, E_DST_MAC_MASK, dstmac_mask, sizeof(dstmac_mask));\r
+               Trim(dstmac);\r
+               Trim(dstmac_mask);\r
+               if(StrLen(dstmac) != 0 && StrLen(dstmac_mask) != 0)\r
+               {\r
+                       UCHAR mac[6], mask[6];\r
+                       if(StrToMac(mac, dstmac) && StrToMac(mask, dstmac_mask))\r
+                       {\r
+                               Copy(a->DstMacAddress, mac, 6);\r
+                               Copy(a->DstMacMask, mask, 6);\r
+                       }\r
+                       else\r
+                       {\r
+                               ok = false;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+       SetEnable(hWnd, S_CHECK_DST_MAC, support_mac);\r
+       SetEnable(hWnd, R_CHECK_DST_MAC, support_mac);\r
+       SetEnable(hWnd, S_DST_MAC, check_dstmac);\r
+       SetEnable(hWnd, S_DST_MAC_MASK, check_dstmac);\r
+       SetEnable(hWnd, E_DST_MAC, check_dstmac);\r
+       SetEnable(hWnd, E_DST_MAC_MASK, check_dstmac);\r
+\r
+       SetEnable(hWnd, S_MAC_NOTE, check_srcmac || check_dstmac);\r
+\r
+       // TCP コネクションの状態\r
+       support_check_state = GetCapsBool(s->Hub->p->CapsList, "b_support_check_tcp_state") && a->Protocol == 6;\r
+       SetEnable(hWnd, R_CHECK_TCP_STATE, support_check_state);\r
+       check_state = a->CheckTcpState = support_check_state && IsChecked(hWnd, R_CHECK_TCP_STATE);\r
+\r
+       a->Established = IsChecked(hWnd, R_ESTABLISHED) && check_state;\r
+       SetEnable(hWnd, R_ESTABLISHED, check_state);\r
+       SetEnable(hWnd, R_UNESTABLISHED, check_state);\r
+       if(check_state != false && IsChecked(hWnd, R_ESTABLISHED) == false && IsChecked(hWnd, R_UNESTABLISHED) == false)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       a->Active = IsChecked(hWnd, R_DISABLE) ? false : true;\r
+\r
+       SetEnable(hWnd, B_SIMULATION, a->Discard == false && GetCapsBool(s->Hub->p->CapsList, "b_support_ex_acl"));\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// OK クリック\r
+void SmEditAccessOnOk(HWND hWnd, SM_EDIT_ACCESS *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SmEditAccessUpdate(hWnd, s);\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+\r
+// アクセスリスト編集ダイアログ\r
+UINT SmEditAccessDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_EDIT_ACCESS *s = (SM_EDIT_ACCESS *)param;\r
+       UINT ico;\r
+       ACCESS *a;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmEditAccessInit(hWnd, s);\r
+\r
+               goto REFRESH_ICON;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_PASS:\r
+               case R_DISCARD:\r
+               case E_PRIORITY:\r
+               case R_SRC_ALL:\r
+               case E_SRC_IP:\r
+               case E_SRC_MASK:\r
+               case R_DST_ALL:\r
+               case E_DST_MASK:\r
+               case E_SRC_IP_V6:\r
+               case E_SRC_MASK_V6:\r
+               case E_DST_MASK_V6:\r
+               case E_DST_IP_V6:\r
+               case C_PROTOCOL:\r
+               case E_SRC_PORT_1:\r
+               case E_SRC_PORT_2:\r
+               case E_DST_PORT_1:\r
+               case E_DST_PORT_2:\r
+               case E_USERNAME1:\r
+               case E_USERNAME2:\r
+               case R_DISABLE:\r
+               case E_IP_PROTO:\r
+               case R_CHECK_SRC_MAC:\r
+               case E_SRC_MAC:\r
+               case E_SRC_MAC_MASK:\r
+               case R_CHECK_DST_MAC:\r
+               case E_DST_MAC:\r
+               case E_DST_MAC_MASK:\r
+               case R_CHECK_TCP_STATE:\r
+               case R_ESTABLISHED:\r
+               case R_UNESTABLISHED:\r
+                       SmEditAccessUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case B_USER1:\r
+                       if (GetTxtA(hWnd, E_USERNAME1, tmp, sizeof(tmp)))\r
+                       {\r
+                               char *ret = SmSelectUserDlgEx(hWnd, s->Hub, tmp, GetCapsBool(s->Hub->p->CapsList, "b_support_acl_group"));\r
+                               if (ret == NULL)\r
+                               {\r
+                                       SetTextA(hWnd, E_USERNAME1, "");\r
+                               }\r
+                               else\r
+                               {\r
+                                       SetTextA(hWnd, E_USERNAME1, ret);\r
+                                       Free(ret);\r
+                               }\r
+                               FocusEx(hWnd, E_USERNAME1);\r
+                       }\r
+                       break;\r
+\r
+               case B_USER2:\r
+                       if (GetTxtA(hWnd, E_USERNAME2, tmp, sizeof(tmp)))\r
+                       {\r
+                               char *ret = SmSelectUserDlgEx(hWnd, s->Hub, tmp, GetCapsBool(s->Hub->p->CapsList, "b_support_acl_group"));\r
+                               if (ret == NULL)\r
+                               {\r
+                                       SetTextA(hWnd, E_USERNAME2, "");\r
+                               }\r
+                               else\r
+                               {\r
+                                       SetTextA(hWnd, E_USERNAME2, ret);\r
+                                       Free(ret);\r
+                               }\r
+                               FocusEx(hWnd, E_USERNAME2);\r
+                       }\r
+                       break;\r
+\r
+               case IDOK:\r
+                       // OK ボタン\r
+                       SmEditAccessOnOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case R_SRC_ALL:\r
+                       if (IsChecked(hWnd, R_SRC_ALL) == false)\r
+                       {\r
+                               if (s->Access->IsIPv6)\r
+                               {\r
+                                       FocusEx(hWnd, E_SRC_IP_V6);\r
+                               }\r
+                               else\r
+                               {\r
+                                       Focus(hWnd, E_SRC_IP);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case R_DST_ALL:\r
+                       if (IsChecked(hWnd, R_DST_ALL) == false)\r
+                       {\r
+                               if (s->Access->IsIPv6)\r
+                               {\r
+                                       FocusEx(hWnd, E_DST_IP_V6);\r
+                               }\r
+                               else\r
+                               {\r
+                                       Focus(hWnd, E_DST_IP);\r
+                               }\r
+                       }\r
+                       break;\r
+               case R_CHECK_SRC_MAC:\r
+                       if(IsChecked(hWnd, R_CHECK_SRC_MAC) == false)\r
+                       {\r
+                               Focus(hWnd, E_SRC_MAC);\r
+                       }\r
+                       break;\r
+               case R_CHECK_DST_MAC:\r
+                       if(IsChecked(hWnd, R_CHECK_DST_MAC) == false)\r
+                       {\r
+                               Focus(hWnd, E_DST_MAC);\r
+                       }\r
+                       break;\r
+\r
+               case R_PASS:\r
+               case R_DISCARD:\r
+               case R_DISABLE:\r
+REFRESH_ICON:\r
+                       a = s->Access;\r
+                       if (a->Discard == false && a->Active == false)\r
+                       {\r
+                               ico = ICO_PASS_DISABLE;\r
+                       }\r
+                       else if (a->Discard == false && a->Active)\r
+                       {\r
+                               ico = ICO_PASS;\r
+                       }\r
+                       else if (a->Discard && a->Active == false)\r
+                       {\r
+                               ico = ICO_DISCARD_DISABLE;\r
+                       }\r
+                       else\r
+                       {\r
+                               ico = ICO_DISCARD;\r
+                       }\r
+\r
+                       SetIcon(hWnd, S_ICON, ico);\r
+                       break;\r
+\r
+               case B_SIMULATION:\r
+                       // シミュレーション\r
+                       Dialog(hWnd, D_SM_SIMULATION, SmSimulationDlg, s);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 遅延・ジッタ・パケットロスダイアログ\r
+UINT SmSimulationDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_EDIT_ACCESS *s = (SM_EDIT_ACCESS *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmSimulationInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_DELAY:\r
+               case E_JITTER:\r
+               case E_LOSS:\r
+                       SmSimulationUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       SmSimulationOnOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case C_DELAY:\r
+                       SmSimulationUpdate(hWnd, s);\r
+                       if (IsChecked(hWnd, C_DELAY))\r
+                       {\r
+                               FocusEx(hWnd, E_DELAY);\r
+                       }\r
+                       break;\r
+\r
+               case C_JITTER:\r
+                       SmSimulationUpdate(hWnd, s);\r
+                       if (IsChecked(hWnd, C_JITTER))\r
+                       {\r
+                               FocusEx(hWnd, E_JITTER);\r
+                       }\r
+                       break;\r
+\r
+               case C_LOSS:\r
+                       SmSimulationUpdate(hWnd, s);\r
+                       if (IsChecked(hWnd, C_LOSS))\r
+                       {\r
+                               FocusEx(hWnd, E_LOSS);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 遅延・ジッタ・パケットロスダイアログの更新\r
+void SmSimulationUpdate(HWND hWnd, SM_EDIT_ACCESS *s)\r
+{\r
+       bool b1, b2, b3;\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b1 = IsChecked(hWnd, C_DELAY);\r
+       b2 = IsChecked(hWnd, C_JITTER);\r
+       b3 = IsChecked(hWnd, C_LOSS);\r
+\r
+       SetEnable(hWnd, S_DELAY, b1);\r
+       SetEnable(hWnd, S_DELAY2, b1);\r
+       SetEnable(hWnd, E_DELAY, b1);\r
+\r
+       SetEnable(hWnd, C_JITTER, b1);\r
+\r
+       if (b1 == false)\r
+       {\r
+               b2 = false;\r
+       }\r
+\r
+       SetEnable(hWnd, S_JITTER, b2);\r
+       SetEnable(hWnd, S_JITTER2, b2);\r
+       SetEnable(hWnd, E_JITTER, b2);\r
+\r
+       SetEnable(hWnd, S_LOSS, b3);\r
+       SetEnable(hWnd, S_LOSS2, b3);\r
+       SetEnable(hWnd, E_LOSS, b3);\r
+\r
+       if (b1)\r
+       {\r
+               UINT i = GetInt(hWnd, E_DELAY);\r
+               if (i == 0 || i > HUB_ACCESSLIST_DELAY_MAX)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       if (b2)\r
+       {\r
+               UINT i = GetInt(hWnd, E_JITTER);\r
+               if (i == 0 || i > HUB_ACCESSLIST_JITTER_MAX)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       if (b3)\r
+       {\r
+               UINT i = GetInt(hWnd, E_LOSS);\r
+               if (i == 0 || i > HUB_ACCESSLIST_LOSS_MAX)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// 遅延・ジッタ・パケットロスダイアログの初期化\r
+void SmSimulationInit(HWND hWnd, SM_EDIT_ACCESS *s)\r
+{\r
+       ACCESS *a;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       a = s->Access;\r
+\r
+       Check(hWnd, C_DELAY, a->Delay != 0);\r
+       Check(hWnd, C_JITTER, a->Jitter != 0);\r
+       Check(hWnd, C_LOSS, a->Loss != 0);\r
+\r
+       SetIntEx(hWnd, E_DELAY, a->Delay);\r
+       if (a->Delay != 0)\r
+       {\r
+               SetIntEx(hWnd, E_JITTER, a->Jitter);\r
+       }\r
+       SetIntEx(hWnd, E_LOSS, a->Loss);\r
+\r
+       SmSimulationUpdate(hWnd, s);\r
+\r
+       if (a->Delay != 0)\r
+       {\r
+               FocusEx(hWnd, E_DELAY);\r
+       }\r
+       else\r
+       {\r
+               Focus(hWnd, C_DELAY);\r
+       }\r
+}\r
+\r
+// 遅延・ジッタ・パケットロスダイアログの保存\r
+void SmSimulationOnOk(HWND hWnd, SM_EDIT_ACCESS *s)\r
+{\r
+       ACCESS *a;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       a = s->Access;\r
+\r
+       a->Jitter = a->Loss = a->Delay = 0;\r
+\r
+       if (IsChecked(hWnd, C_DELAY))\r
+       {\r
+               a->Delay = GetInt(hWnd, E_DELAY);\r
+       }\r
+\r
+       if (IsChecked(hWnd, C_JITTER))\r
+       {\r
+               a->Jitter = GetInt(hWnd, E_JITTER);\r
+       }\r
+\r
+       if (IsChecked(hWnd, C_LOSS))\r
+       {\r
+               a->Loss = GetInt(hWnd, E_LOSS);\r
+       }\r
+\r
+       EndDialog(hWnd, 1);\r
+}\r
+\r
+// アクセスリストの編集\r
+bool SmEditAccess(HWND hWnd, SM_ACCESS_LIST *s, ACCESS *a)\r
+{\r
+       SM_EDIT_ACCESS edit;\r
+       bool ret;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&edit, sizeof(edit));\r
+       edit.AccessList = s;\r
+       edit.EditMode = true;\r
+       edit.Access = ZeroMalloc(sizeof(ACCESS));\r
+       edit.Hub = s->Hub;\r
+       Copy(edit.Access, a, sizeof(ACCESS));\r
+\r
+       if (edit.Access->IsIPv6 == false)\r
+       {\r
+               ret = Dialog(hWnd, D_SM_EDIT_ACCESS, SmEditAccessDlg, &edit);\r
+       }\r
+       else\r
+       {\r
+               ret = Dialog(hWnd, D_SM_EDIT_ACCESS_V6, SmEditAccessDlg, &edit);\r
+       }\r
+\r
+       if (ret)\r
+       {\r
+               Copy(a, edit.Access, sizeof(ACCESS));\r
+               Free(edit.Access);\r
+               Sort(s->AccessList);\r
+\r
+               // ID を振り直す\r
+               for (i = 0;i < LIST_NUM(s->AccessList);i++)\r
+               {\r
+                       ACCESS *a = LIST_DATA(s->AccessList, i);\r
+                       a->Id = (i + 1);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               Free(edit.Access);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// アクセスリストの追加\r
+bool SmAddAccess(HWND hWnd, SM_ACCESS_LIST *s, bool ipv6)\r
+{\r
+       SM_EDIT_ACCESS edit;\r
+       bool ret;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&edit, sizeof(edit));\r
+       edit.AccessList = s;\r
+       edit.Access = ZeroMalloc(sizeof(ACCESS));\r
+       edit.Access->Active = true;\r
+       edit.Access->Priority = 0;\r
+       edit.Access->IsIPv6 = ipv6;\r
+       edit.Hub = s->Hub;\r
+\r
+       // 新しい優先順位の取得\r
+       for (i = 0;i < LIST_NUM(s->AccessList);i++)\r
+       {\r
+               ACCESS *a = LIST_DATA(s->AccessList, i);\r
+               edit.Access->Priority = MAX(edit.Access->Priority, a->Priority);\r
+       }\r
+\r
+       if (edit.Access->Priority == 0)\r
+       {\r
+               edit.Access->Priority = 900;\r
+       }\r
+\r
+       edit.Access->Priority += 100;\r
+\r
+       if (edit.Access->IsIPv6 == false)\r
+       {\r
+               ret = Dialog(hWnd, D_SM_EDIT_ACCESS, SmEditAccessDlg, &edit);\r
+       }\r
+       else\r
+       {\r
+               ret = Dialog(hWnd, D_SM_EDIT_ACCESS_V6, SmEditAccessDlg, &edit);\r
+       }\r
+\r
+       if (ret)\r
+       {\r
+               Insert(s->AccessList, edit.Access);\r
+\r
+               // ID を振り直す\r
+               for (i = 0;i < LIST_NUM(s->AccessList);i++)\r
+               {\r
+                       ACCESS *a = LIST_DATA(s->AccessList, i);\r
+                       a->Id = (i + 1);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               Free(edit.Access);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 初期化\r
+void SmAccessListInit(HWND hWnd, SM_ACCESS_LIST *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_PASS);\r
+       FormatText(hWnd, S_TITLE, s->Hub->HubName);\r
+\r
+       LvInit(hWnd, L_ACCESS_LIST);\r
+       LvInsertColumn(hWnd, L_ACCESS_LIST, 0, _UU("SM_ACCESS_COLUMN_0"), 60);\r
+       LvInsertColumn(hWnd, L_ACCESS_LIST, 1, _UU("SM_ACCESS_COLUMN_1"), 60);\r
+       LvInsertColumn(hWnd, L_ACCESS_LIST, 2, _UU("SM_ACCESS_COLUMN_2"), 60);\r
+       LvInsertColumn(hWnd, L_ACCESS_LIST, 3, _UU("SM_ACCESS_COLUMN_3"), 70);\r
+       LvInsertColumn(hWnd, L_ACCESS_LIST, 4, _UU("SM_ACCESS_COLUMN_4"), 150);\r
+       LvInsertColumn(hWnd, L_ACCESS_LIST, 5, _UU("SM_ACCESS_COLUMN_5"), 600);\r
+\r
+       LvSetStyle(hWnd, L_ACCESS_LIST, LVS_EX_GRIDLINES);\r
+\r
+       SetEnable(hWnd, B_ADD_V6, GetCapsBool(s->Hub->p->CapsList, "b_support_ipv6_acl"));\r
+\r
+       SmAccessListRefresh(hWnd, s);\r
+}\r
+\r
+// コントロール更新\r
+void SmAccessListUpdate(HWND hWnd, SM_ACCESS_LIST *s)\r
+{\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSelected(hWnd, L_ACCESS_LIST) == false || LvIsMultiMasked(hWnd, L_ACCESS_LIST))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+       SetEnable(hWnd, B_DELETE, ok);\r
+\r
+       SetEnable(hWnd, B_CREATE, LIST_NUM(s->AccessList) < MAX_ACCESSLISTS);\r
+}\r
+\r
+// 内容更新\r
+void SmAccessListRefresh(HWND hWnd, SM_ACCESS_LIST *s)\r
+{\r
+       LVB *b;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       Sort(s->AccessList);\r
+\r
+       for (i = 0;i < LIST_NUM(s->AccessList);i++)\r
+       {\r
+               ACCESS *a = LIST_DATA(s->AccessList, i);\r
+               char tmp[MAX_SIZE];\r
+               UINT ico = ICO_PASS;\r
+               wchar_t tmp3[MAX_SIZE];\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               GetAccessListStr(tmp, sizeof(tmp), a);\r
+               UniToStru(tmp1, a->Priority);\r
+               StrToUni(tmp2, sizeof(tmp2), tmp);\r
+\r
+               if (a->Discard == false && a->Active == false)\r
+               {\r
+                       ico = ICO_PASS_DISABLE;\r
+               }\r
+               else if (a->Discard == false && a->Active)\r
+               {\r
+                       ico = ICO_PASS;\r
+               }\r
+               else if (a->Discard && a->Active == false)\r
+               {\r
+                       ico = ICO_DISCARD_DISABLE;\r
+               }\r
+               else\r
+               {\r
+                       ico = ICO_DISCARD;\r
+               }\r
+\r
+               UniToStru(tmp3, a->Id);\r
+\r
+               LvInsertAdd(b, ico, (void *)a, 6,\r
+                       tmp3,\r
+                       a->Discard ? _UU("SM_ACCESS_DISCARD") : _UU("SM_ACCESS_PASS"),\r
+                       a->Active ? _UU("SM_ACCESS_ENABLE") : _UU("SM_ACCESS_DISABLE"),\r
+                       tmp1,\r
+                       a->Note,\r
+                       tmp2);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_ACCESS_LIST);\r
+       LvSortEx(hWnd, L_ACCESS_LIST, 0, false, true);\r
+\r
+       SmAccessListUpdate(hWnd, s);\r
+}\r
+\r
+// アクセスリストダイアログプロシージャ\r
+UINT SmAccessListProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_ACCESS_LIST *s = (SM_ACCESS_LIST *)param;\r
+       NMHDR *n;\r
+       ACCESS *a;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmAccessListInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_ADD:\r
+                       // 追加 (IPv4)\r
+                       if (SmAddAccess(hWnd, s, false))\r
+                       {\r
+                               SmAccessListRefresh(hWnd, s);\r
+                       }\r
+                       break;\r
+\r
+               case B_ADD_V6:\r
+                       // 追加 (IPv6)\r
+                       if (SmAddAccess(hWnd, s, true))\r
+                       {\r
+                               SmAccessListRefresh(hWnd, s);\r
+                       }\r
+                       break;\r
+\r
+               case IDOK:\r
+                       // 編集\r
+                       a = LvGetParam(hWnd, L_ACCESS_LIST, LvGetSelected(hWnd, L_ACCESS_LIST));\r
+                       if (a != NULL)\r
+                       {\r
+                               if (SmEditAccess(hWnd, s, a))\r
+                               {\r
+                                       SmAccessListRefresh(hWnd, s);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       // 削除\r
+                       a = LvGetParam(hWnd, L_ACCESS_LIST, LvGetSelected(hWnd, L_ACCESS_LIST));\r
+                       if (a != NULL)\r
+                       {\r
+                               UINT i;\r
+                               if (IsInList(s->AccessList, a))\r
+                               {\r
+                                       Delete(s->AccessList, a);\r
+                                       Free(a);\r
+                                       // ID を振り直す\r
+                                       for (i = 0;i < LIST_NUM(s->AccessList);i++)\r
+                                       {\r
+                                               ACCESS *a = LIST_DATA(s->AccessList, i);\r
+                                               a->Id = (i + 1);\r
+                                       }\r
+                                       SmAccessListRefresh(hWnd, s);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_SAVE:\r
+                       // 保存\r
+                       {\r
+                               UINT i;\r
+                               bool ok;\r
+                               // アクセスリストを保存する\r
+                               RPC_ENUM_ACCESS_LIST t;\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.HubName, sizeof(t.HubName), s->Hub->HubName);\r
+                               t.NumAccess = LIST_NUM(s->AccessList);\r
+                               t.Accesses = ZeroMalloc(sizeof(ACCESS) * t.NumAccess);\r
+                               for (i = 0;i < LIST_NUM(s->AccessList);i++)\r
+                               {\r
+                                       ACCESS *access = LIST_DATA(s->AccessList, i);\r
+                                       Copy(&t.Accesses[i], access, sizeof(ACCESS));\r
+                               }\r
+\r
+                               ok = CALL(hWnd, ScSetAccessList(s->Rpc, &t));\r
+                               FreeRpcEnumAccessList(&t);\r
+                               if (ok)\r
+                               {\r
+                                       EndDialog(hWnd, true);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_ACCESS_LIST:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmAccessListUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_ACCESS_LIST);\r
+\r
+       return 0;\r
+}\r
+\r
+\r
+// アクセスリストダイアログ\r
+void SmAccessListDlg(HWND hWnd, SM_HUB *s)\r
+{\r
+       SM_ACCESS_LIST a;\r
+       UINT i;\r
+       RPC_ENUM_ACCESS_LIST t;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&a, sizeof(a));\r
+       a.Hub = s;\r
+       a.Rpc = s->Rpc;\r
+\r
+       // アクセスリストの取得\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+       if (CALL(hWnd, ScEnumAccess(s->Rpc, &t)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       a.AccessList = NewListFast(CmpAccessList);\r
+       // リストに追加\r
+       for (i = 0;i < t.NumAccess;i++)\r
+       {\r
+               ACCESS *access = ZeroMalloc(sizeof(ACCESS));\r
+               Copy(access, &t.Accesses[i], sizeof(ACCESS));\r
+\r
+               Add(a.AccessList, access);\r
+       }\r
+\r
+       // ソート\r
+       Sort(a.AccessList);\r
+       FreeRpcEnumAccessList(&t);\r
+\r
+       // ダイアログ表示\r
+       ret = Dialog(hWnd, D_SM_ACCESS_LIST, SmAccessListProc, &a);\r
+\r
+       for (i = 0;i < LIST_NUM(a.AccessList);i++)\r
+       {\r
+               ACCESS *access = LIST_DATA(a.AccessList, i);\r
+               Free(access);\r
+       }\r
+       ReleaseList(a.AccessList);\r
+}\r
+\r
+// 初期化\r
+void SmEditGroupDlgInit(HWND hWnd, SM_EDIT_GROUP *g)\r
+{\r
+       RPC_SET_GROUP *group;\r
+       LVB *b;\r
+       // 引数チェック\r
+       if (hWnd == NULL || g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_GROUP);\r
+\r
+       group = &g->SetGroup;\r
+\r
+       if (g->EditMode == false)\r
+       {\r
+               SetText(hWnd, 0, _UU("SM_EDIT_GROUP_CAPTION_1"));\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_EDIT_GROUP_CAPTION_2"), group->Name);\r
+               SetText(hWnd, 0, tmp);\r
+       }\r
+\r
+       SetTextA(hWnd, E_GROUPNAME, group->Name);\r
+       SetText(hWnd, E_REALNAME, group->Realname);\r
+       SetText(hWnd, E_NOTE, group->Note);\r
+\r
+       g->Inited = true;\r
+\r
+       if (g->EditMode == false)\r
+       {\r
+               Disable(hWnd, L_STATUS);\r
+       }\r
+       else\r
+       {\r
+               LvInit(hWnd, L_STATUS);\r
+               LvInsertColumn(hWnd, L_STATUS, 0, _UU("SM_STATUS_COLUMN_1"), 0);\r
+               LvInsertColumn(hWnd, L_STATUS, 1, _UU("SM_STATUS_COLUMN_2"), 0);\r
+               LvSetStyle(hWnd, L_STATUS, LVS_EX_GRIDLINES);\r
+\r
+               b = LvInsertStart();\r
+\r
+               SmInsertTrafficInfo(b, &group->Traffic);\r
+\r
+               LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+               LvAutoSize(hWnd, L_STATUS);\r
+       }\r
+\r
+       Check(hWnd, R_POLICY, group->Policy != NULL);\r
+\r
+       if (g->EditMode)\r
+       {\r
+               Disable(hWnd, E_GROUPNAME);\r
+               FocusEx(hWnd, E_REALNAME);\r
+       }\r
+\r
+       SmEditGroupDlgUpdate(hWnd, g);\r
+}\r
+\r
+// 更新\r
+void SmEditGroupDlgUpdate(HWND hWnd, SM_EDIT_GROUP *g)\r
+{\r
+       bool ok = true;\r
+       RPC_SET_GROUP *group;\r
+       // 引数チェック\r
+       if (hWnd == NULL || g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (g->Inited == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       group = &g->SetGroup;\r
+\r
+       GetTxtA(hWnd, E_GROUPNAME, group->Name, sizeof(group->Name));\r
+       Trim(group->Name);\r
+\r
+       if (IsUserName(group->Name) == false)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       GetTxt(hWnd, E_REALNAME, group->Realname, sizeof(group->Realname));\r
+       UniTrim(group->Realname);\r
+\r
+       GetTxt(hWnd, E_NOTE, group->Note, sizeof(group->Note));\r
+       UniTrim(group->Note);\r
+\r
+       SetEnable(hWnd, B_POLICY, IsChecked(hWnd, R_POLICY));\r
+\r
+       if (IsChecked(hWnd, R_POLICY))\r
+       {\r
+               if (group->Policy == NULL)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// OK\r
+void SmEditGroupDlgOnOk(HWND hWnd, SM_EDIT_GROUP *g)\r
+{\r
+       RPC_SET_GROUP *group;\r
+       RPC_SET_GROUP t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SmEditGroupDlgUpdate(hWnd, g);\r
+\r
+       group = &g->SetGroup;\r
+\r
+       if (IsChecked(hWnd, R_POLICY) == false)\r
+       {\r
+               if (group->Policy != NULL)\r
+               {\r
+                       Free(group->Policy);\r
+                       group->Policy = NULL;\r
+               }\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       Copy(&t, group, sizeof(RPC_SET_GROUP));\r
+\r
+       t.Policy = ClonePolicy(group->Policy);\r
+\r
+       if (g->EditMode == false)\r
+       {\r
+               if (CALL(hWnd, ScCreateGroup(g->Rpc, &t)) == false)\r
+               {\r
+                       FocusEx(hWnd, E_GROUPNAME);\r
+                       return;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (CALL(hWnd, ScSetGroup(g->Rpc, &t)) == false)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       FreeRpcSetGroup(&t);\r
+\r
+       if (g->EditMode == false)\r
+       {\r
+               MsgBoxEx(hWnd, MB_ICONINFORMATION, _UU("SM_GROUP_CREATED"), group->Name);\r
+       }\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// グループ編集ダイアログプロシージャ\r
+UINT SmEditGroupDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_EDIT_GROUP *g = (SM_EDIT_GROUP *)param;\r
+       wchar_t tmp[MAX_SIZE];\r
+       NMHDR *n;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmEditGroupDlgInit(hWnd, g);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_GROUPNAME:\r
+               case E_REALNAME:\r
+               case E_NOTE:\r
+               case R_POLICY:\r
+                       SmEditGroupDlgUpdate(hWnd, g);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // OK ボタン\r
+                       SmEditGroupDlgOnOk(hWnd, g);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case R_POLICY:\r
+                       if (IsChecked(hWnd, R_POLICY))\r
+                       {\r
+                               Focus(hWnd, B_POLICY);\r
+                       }\r
+                       break;\r
+\r
+               case B_POLICY:\r
+                       // セキュリティ ポリシー\r
+                       UniFormat(tmp, sizeof(tmp), _UU("SM_GROUP_POLICY_CAPTION"), g->SetGroup.Name);\r
+                       if (g->SetGroup.Policy == NULL)\r
+                       {\r
+                               POLICY *p = ClonePolicy(GetDefaultPolicy());\r
+                               if (SmPolicyDlgEx2(hWnd, p, tmp, false, g->p->PolicyVer))\r
+                               {\r
+                                       g->SetGroup.Policy = p;\r
+                                       SmEditGroupDlgUpdate(hWnd, g);\r
+                               }\r
+                               else\r
+                               {\r
+                                       Free(p);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               SmPolicyDlgEx2(hWnd, g->SetGroup.Policy, tmp, false, g->p->PolicyVer);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_STATUS:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmEditGroupDlgUpdate(hWnd, g);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// グループ編集ダイアログ\r
+bool SmEditGroupDlg(HWND hWnd, SM_GROUP *s, char *name)\r
+{\r
+       SM_EDIT_GROUP g;\r
+       RPC_SET_GROUP *group;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&g, sizeof(g));\r
+       g.EditMode = true;\r
+       g.Hub = s->Hub;\r
+       g.p = s->p;\r
+       g.Rpc = s->Rpc;\r
+\r
+       group = &g.SetGroup;\r
+\r
+       StrCpy(group->Name, sizeof(group->Name), name);\r
+       StrCpy(group->HubName, sizeof(group->HubName), s->Hub->HubName);\r
+\r
+       if (CALL(hWnd, ScGetGroup(s->Rpc, group)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = Dialog(hWnd, D_SM_EDIT_GROUP, SmEditGroupDlgProc, &g);\r
+\r
+       FreeRpcSetGroup(group);\r
+\r
+       return ret;\r
+}\r
+\r
+// グループ作成ダイアログ\r
+bool SmCreateGroupDlg(HWND hWnd, SM_GROUP *s)\r
+{\r
+       SM_EDIT_GROUP g;\r
+       RPC_SET_GROUP *group;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&g, sizeof(g));\r
+       g.EditMode = false;\r
+       g.Hub = s->Hub;\r
+       g.p = s->p;\r
+       g.Rpc = s->Rpc;\r
+\r
+       group = &g.SetGroup;\r
+\r
+       StrCpy(group->HubName, sizeof(group->HubName), s->Hub->HubName);\r
+\r
+       ret = Dialog(hWnd, D_SM_EDIT_GROUP, SmEditGroupDlgProc, &g);\r
+\r
+       FreeRpcSetGroup(group);\r
+\r
+       return ret;\r
+}\r
+\r
+// 初期化\r
+void SmGroupListDlgInit(HWND hWnd, SM_GROUP *s)\r
+{\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_GROUP);\r
+\r
+       // カラム初期化\r
+       LvInit(hWnd, L_GROUP);\r
+       LvInsertColumn(hWnd, L_GROUP, 0, _UU("SM_GROUPLIST_NAME"), 130);\r
+       LvInsertColumn(hWnd, L_GROUP, 1, _UU("SM_GROUPLIST_REALNAME"), 130);\r
+       LvInsertColumn(hWnd, L_GROUP, 2, _UU("SM_GROUPLIST_NOTE"), 170);\r
+       LvInsertColumn(hWnd, L_GROUP, 3, _UU("SM_GROUPLIST_NUMUSERS"), 80);\r
+       LvSetStyle(hWnd, L_GROUP, LVS_EX_GRIDLINES);\r
+\r
+       FormatText(hWnd, S_TITLE, s->Hub->HubName);\r
+\r
+       SmGroupListDlgRefresh(hWnd, s);\r
+\r
+       if (s->SelectMode)\r
+       {\r
+               SetStyle(hWnd, L_GROUP, LVS_SINGLESEL);\r
+       }\r
+\r
+       if (s->SelectMode)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               SetText(hWnd, IDOK, _UU("SM_SELECT_GROUP"));\r
+\r
+               if (s->SelectedGroupName != NULL)\r
+               {\r
+                       UINT i;\r
+                       StrToUni(tmp, sizeof(tmp), s->SelectedGroupName);\r
+                       i = LvSearchStr(hWnd, L_GROUP, 0, tmp);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               LvSelect(hWnd, L_GROUP, i);\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// コントロール更新\r
+void SmGroupListDlgUpdate(HWND hWnd, SM_GROUP *s)\r
+{\r
+       bool ok = true;\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSelected(hWnd, L_GROUP) == false || LvIsMultiMasked(hWnd, L_GROUP))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+       SetEnable(hWnd, B_USER, ok);\r
+       SetEnable(hWnd, B_STATUS, ok);\r
+\r
+       if (s->SelectMode == false)\r
+       {\r
+               SetEnable(hWnd, B_DELETE, ok);\r
+       }\r
+       else\r
+       {\r
+               SetEnable(hWnd, B_DELETE, false);\r
+               SetEnable(hWnd, B_USER, false);\r
+               SetText(hWnd, IDCANCEL, _UU("SM_SELECT_NO_GROUP"));\r
+       }\r
+}\r
+\r
+// 内容更新\r
+void SmGroupListDlgRefresh(HWND hWnd, SM_GROUP *s)\r
+{\r
+       RPC_ENUM_GROUP t;\r
+       UINT i;\r
+       LVB *b;\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->Hub->HubName);\r
+\r
+       if (CALL(hWnd, ScEnumGroup(s->Rpc, &t)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       for (i = 0;i < t.NumGroup;i++)\r
+       {\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               RPC_ENUM_GROUP_ITEM *e = &t.Groups[i];\r
+\r
+               StrToUni(tmp1, sizeof(tmp1), e->Name);\r
+               UniToStru(tmp2, e->NumUsers);\r
+\r
+               LvInsertAdd(b, e->DenyAccess == false ? ICO_GROUP : ICO_GROUP_DENY,\r
+                       NULL, 4, tmp1, e->Realname, e->Note, tmp2);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_GROUP);\r
+\r
+       SmGroupListDlgUpdate(hWnd, s);\r
+\r
+       FreeRpcEnumGroup(&t);\r
+}\r
+\r
+// グループリストダイアログプロシージャ\r
+UINT SmGroupListDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_GROUP *s = (SM_GROUP *)param;\r
+       NMHDR *n;\r
+       wchar_t *tmp;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmGroupListDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_CREATE:\r
+                       // 新規作成\r
+                       if (SmCreateGroupDlg(hWnd, s))\r
+                       {\r
+                               SmGroupListDlgRefresh(hWnd, s);\r
+                       }\r
+                       break;\r
+\r
+               case IDOK:\r
+                       // 編集\r
+                       tmp = LvGetSelectedStr(hWnd, L_GROUP, 0);\r
+                       if (tmp != NULL)\r
+                       {\r
+                               char name[MAX_SIZE];\r
+                               UniToStr(name, sizeof(name), tmp);\r
+\r
+                               if (s->SelectMode == false)\r
+                               {\r
+                                       if (SmEditGroupDlg(hWnd, s, name))\r
+                                       {\r
+                                               SmGroupListDlgRefresh(hWnd, s);\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       s->SelectedGroupName = CopyStr(name);\r
+                                       EndDialog(hWnd, true);\r
+                               }\r
+                               Free(tmp);\r
+                       }\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       // 削除\r
+                       tmp = LvGetSelectedStr(hWnd, L_GROUP, 0);\r
+                       if (tmp != NULL)\r
+                       {\r
+                               char name[MAX_SIZE];\r
+                               RPC_DELETE_USER t;\r
+                               UniToStr(name, sizeof(name), tmp);\r
+\r
+                               if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2,\r
+                                       _UU("SM_GROUP_DELETE_MSG"), name) == IDYES)\r
+                               {\r
+                                       Zero(&t, sizeof(t));\r
+                                       StrCpy(t.HubName, sizeof(t.HubName), s->Hub->HubName);\r
+                                       StrCpy(t.Name, sizeof(t.Name), name);\r
+\r
+                                       if (CALL(hWnd, ScDeleteGroup(s->Rpc, &t)))\r
+                                       {\r
+                                               SmGroupListDlgRefresh(hWnd, s);\r
+                                       }\r
+                               }\r
+\r
+                               Free(tmp);\r
+                       }\r
+                       break;\r
+\r
+               case B_USER:\r
+                       // メンバ一覧\r
+                       tmp = LvGetSelectedStr(hWnd, L_GROUP, 0);\r
+                       if (tmp != NULL)\r
+                       {\r
+                               char name[MAX_SIZE];\r
+                               UniToStr(name, sizeof(name), tmp);\r
+                               SmUserListDlgEx(hWnd, s->Hub, name, false);\r
+                               Free(tmp);\r
+                       }\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       // 最新情報に更新\r
+                       SmGroupListDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_GROUP:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmGroupListDlgUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_GROUP);\r
+\r
+       return 0;\r
+}\r
+\r
+// グループリストダイアログ (選択モード)\r
+char *SmSelectGroupDlg(HWND hWnd, SM_HUB *s, char *default_name)\r
+{\r
+       SM_GROUP g;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&g, sizeof(g));\r
+       g.Hub = s;\r
+       g.p = s->p;\r
+       g.Rpc = s->Rpc;\r
+       g.SelectMode = true;\r
+       g.SelectedGroupName = default_name;\r
+\r
+       if (Dialog(hWnd, D_SM_GROUP, SmGroupListDlgProc, &g) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return g.SelectedGroupName;\r
+}\r
+\r
+// グループリストダイアログ\r
+void SmGroupListDlg(HWND hWnd, SM_HUB *s)\r
+{\r
+       SM_GROUP g;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&g, sizeof(g));\r
+       g.Hub = s;\r
+       g.p = s->p;\r
+       g.Rpc = s->Rpc;\r
+       g.SelectMode = false;\r
+\r
+       Dialog(hWnd, D_SM_GROUP, SmGroupListDlgProc, &g);\r
+}\r
+\r
+// ユーザー情報の更新\r
+bool SmRefreshUserInfo(HWND hWnd, SM_SERVER *s, void *param)\r
+{\r
+       RPC_SET_USER t;\r
+       SM_USER_INFO *p = (SM_USER_INFO *)param;\r
+       LVB *b;\r
+       wchar_t tmp[MAX_SIZE];\r
+       char *username;\r
+\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL || param == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       username = p->Username;\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.HubName, sizeof(t.HubName), p->Hub->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), username);\r
+\r
+       if (CALL(hWnd, ScGetUser(s->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.Name);\r
+       LvInsertAdd(b, ICO_USER, NULL, 2, _UU("SM_USERINFO_NAME"), tmp);\r
+\r
+       if (StrLen(t.GroupName) != 0)\r
+       {\r
+               StrToUni(tmp, sizeof(tmp), t.GroupName);\r
+               LvInsertAdd(b, ICO_GROUP, NULL, 2, _UU("SM_USERINFO_GROUP"), tmp);\r
+       }\r
+\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.CreatedTime), NULL);\r
+       LvInsertAdd(b, ICO_USER_ADMIN, NULL, 2, _UU("SM_USERINFO_CREATE"), tmp);\r
+\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.UpdatedTime), NULL);\r
+       LvInsertAdd(b, ICO_USER_ADMIN, NULL, 2, _UU("SM_USERINFO_UPDATE"), tmp);\r
+\r
+       if (t.ExpireTime != 0)\r
+       {\r
+               GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.ExpireTime), NULL);\r
+               LvInsertAdd(b, ICO_WARNING, NULL, 2, _UU("SM_USERINFO_EXPIRE"), tmp);\r
+       }\r
+\r
+       SmInsertTrafficInfo(b, &t.Traffic);\r
+\r
+       UniToStru(tmp, t.NumLogin);\r
+       LvInsertAdd(b, ICO_LINK, NULL, 2, _UU("SM_USERINFO_NUMLOGIN"), tmp);\r
+\r
+       LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+       FreeRpcSetUser(&t);\r
+\r
+       return true;\r
+}\r
+\r
+// 初期化\r
+void SmPolicyDlgInit(HWND hWnd, SM_POLICY *s)\r
+{\r
+       CM_POLICY cp;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_MACHINE);\r
+       SetText(hWnd, 0, s->Caption);\r
+       SetText(hWnd, S_TITLE, s->Caption);\r
+       DlgFont(hWnd, S_BOLD, 10, true);\r
+       DlgFont(hWnd, S_BOLD2, 10, true);\r
+\r
+       DlgFont(hWnd, S_POLICY_TITLE, 11, false);\r
+       DlgFont(hWnd, E_POLICY_DESCRIPTION, 10, false);\r
+\r
+       Zero(&cp, sizeof(cp));\r
+       cp.Policy = s->Policy;\r
+       cp.Extension = true;\r
+\r
+       LvInit(hWnd, L_POLICY);\r
+       LvInsertColumn(hWnd, L_POLICY, 0, _UU("POL_TITLE_STR"), 250);\r
+       LvInsertColumn(hWnd, L_POLICY, 1, _UU("POL_VALUE_STR"), 150);\r
+       LvSetStyle(hWnd, L_POLICY, LVS_EX_GRIDLINES);\r
+\r
+       CmPolicyDlgPrintEx2(hWnd, &cp, s->CascadeMode, s->Ver);\r
+\r
+       LvSelect(hWnd, L_POLICY, 0);\r
+\r
+       s->Inited = true;\r
+       SmPolicyDlgUpdate(hWnd, s);\r
+}\r
+\r
+// 更新\r
+void SmPolicyDlgUpdate(HWND hWnd, SM_POLICY *s)\r
+{\r
+       bool ok = true;\r
+       bool value_changed = false;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->Inited == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       i = LvGetSelected(hWnd, L_POLICY);\r
+       if (i != INFINITE)\r
+       {\r
+               i = (UINT)LvGetParam(hWnd, L_POLICY, i);\r
+       }\r
+       if (i == INFINITE || i >= NUM_POLICY_ITEM)\r
+       {\r
+               SetText(hWnd, S_POLICY_TITLE, _UU("SM_POLICY_INIT_TITLE"));\r
+               SetText(hWnd, E_POLICY_DESCRIPTION, L"");\r
+               Disable(hWnd, S_POLICY_TITLE);\r
+               Disable(hWnd, S_BOLD);\r
+               Hide(hWnd, S_BOLD2);\r
+               Hide(hWnd, R_ENABLE);\r
+               Hide(hWnd, R_DISABLE);\r
+               Hide(hWnd, R_DEFINE);\r
+               Hide(hWnd, E_VALUE);\r
+               Hide(hWnd, S_TANI);\r
+               Hide(hWnd, S_LIMIT);\r
+       }\r
+       else\r
+       {\r
+               POLICY_ITEM *item = &policy_item[i];\r
+               bool changed = false;\r
+               wchar_t *tmp = GetText(hWnd, S_POLICY_TITLE);\r
+               if (UniStrCmp(tmp, GetPolicyTitle(i)) != 0)\r
+               {\r
+                       changed = true;\r
+               }\r
+               Free(tmp);\r
+               SetText(hWnd, S_POLICY_TITLE, GetPolicyTitle(i));\r
+               SetText(hWnd, E_POLICY_DESCRIPTION, GetPolicyDescription(i));\r
+               Enable(hWnd, S_POLICY_TITLE);\r
+               Enable(hWnd, S_BOLD);\r
+               Show(hWnd, S_BOLD2);\r
+\r
+               if (item->TypeInt == false)\r
+               {\r
+                       Show(hWnd, R_ENABLE);\r
+                       Show(hWnd, R_DISABLE);\r
+                       Hide(hWnd, R_DEFINE);\r
+                       Hide(hWnd, E_VALUE);\r
+                       Hide(hWnd, S_TANI);\r
+                       Hide(hWnd, S_LIMIT);\r
+\r
+                       if (changed)\r
+                       {\r
+                               if (POLICY_BOOL(s->Policy, i))\r
+                               {\r
+                                       Check(hWnd, R_ENABLE, true);\r
+                                       Check(hWnd, R_DISABLE, false);\r
+                               }\r
+                               else\r
+                               {\r
+                                       Check(hWnd, R_ENABLE, false);\r
+                                       Check(hWnd, R_DISABLE, true);\r
+                               }\r
+                       }\r
+\r
+                       if ((!(POLICY_BOOL(s->Policy, i))) != (!(IsChecked(hWnd, R_ENABLE))))\r
+                       {\r
+                               POLICY_BOOL(s->Policy, i) = IsChecked(hWnd, R_ENABLE);\r
+                               value_changed = true;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       UINT value;\r
+                       if (item->AllowZero)\r
+                       {\r
+                               if (changed)\r
+                               {\r
+                                       Check(hWnd, R_DEFINE, POLICY_INT(s->Policy, i) != 0);\r
+                                       Enable(hWnd, R_DEFINE);\r
+                                       SetIntEx(hWnd, E_VALUE, POLICY_INT(s->Policy, i));\r
+                               }\r
+\r
+                               SetEnable(hWnd, E_VALUE, IsChecked(hWnd, R_DEFINE));\r
+                               SetEnable(hWnd, S_TANI, IsChecked(hWnd, R_DEFINE));\r
+                               SetEnable(hWnd, S_LIMIT, IsChecked(hWnd, R_DEFINE));\r
+                       }\r
+                       else\r
+                       {\r
+                               if (changed)\r
+                               {\r
+                                       Check(hWnd, R_DEFINE, true);\r
+                                       Disable(hWnd, R_DEFINE);\r
+                                       SetInt(hWnd, E_VALUE, POLICY_INT(s->Policy, i));\r
+                               }\r
+\r
+                               SetEnable(hWnd, E_VALUE, IsChecked(hWnd, R_DEFINE));\r
+                               SetEnable(hWnd, S_TANI, IsChecked(hWnd, R_DEFINE));\r
+                               SetEnable(hWnd, S_LIMIT, IsChecked(hWnd, R_DEFINE));\r
+                       }\r
+\r
+                       UniReplaceStrEx(tmp, sizeof(tmp), _UU(policy_item[i].FormatStr),\r
+                               L"%u ", L"", false);\r
+                       UniReplaceStrEx(tmp, sizeof(tmp), tmp,\r
+                               L"%u", L"", false);\r
+\r
+                       SetText(hWnd, S_TANI, tmp);\r
+\r
+                       UniFormat(tmp, sizeof(tmp), _UU("SM_LIMIT_STR"), policy_item[i].MinValue, policy_item[i].MaxValue);\r
+                       SetText(hWnd, S_LIMIT, tmp);\r
+\r
+                       Hide(hWnd, R_ENABLE);\r
+                       Hide(hWnd, R_DISABLE);\r
+                       Show(hWnd, E_VALUE);\r
+                       Show(hWnd, R_DEFINE);\r
+                       Show(hWnd, S_TANI);\r
+                       Show(hWnd, S_LIMIT);\r
+\r
+                       value = GetInt(hWnd, E_VALUE);\r
+\r
+                       if (item->AllowZero && (IsChecked(hWnd, R_DEFINE) == false))\r
+                       {\r
+                               value = 0;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (value < policy_item[i].MinValue || value > policy_item[i].MaxValue)\r
+                               {\r
+                                       ok = false;\r
+                               }\r
+                       }\r
+\r
+                       if (ok)\r
+                       {\r
+                               if (POLICY_INT(s->Policy, i) != value)\r
+                               {\r
+                                       POLICY_INT(s->Policy, i) = value;\r
+                                       value_changed = true;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+       SetEnable(hWnd, L_POLICY, ok);\r
+\r
+       if (value_changed)\r
+       {\r
+               CM_POLICY cp;\r
+               Zero(&cp, sizeof(cp));\r
+               cp.Policy = s->Policy;\r
+               cp.Extension = true;\r
+\r
+               CmPolicyDlgPrintEx(hWnd, &cp, s->CascadeMode);\r
+       }\r
+}\r
+\r
+// 確定\r
+void SmPolicyDlgOk(HWND hWnd, SM_POLICY *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// ポリシー ダイアログ ボックス プロシージャ\r
+UINT SmPolicyDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_POLICY *s = (SM_POLICY *)param;\r
+       NMHDR *n;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmPolicyDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_DEFINE:\r
+               case R_ENABLE:\r
+               case R_DISABLE:\r
+               case E_VALUE:\r
+                       SmPolicyDlgUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // OK ボタン\r
+                       SmPolicyDlgOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case R_DEFINE:\r
+                       if (IsChecked(hWnd, R_DEFINE))\r
+                       {\r
+                               FocusEx(hWnd, E_VALUE);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_POLICY:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmPolicyDlgUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ポリシー ダイアログ ボックスの表示\r
+bool SmPolicyDlg(HWND hWnd, POLICY *p, wchar_t *caption)\r
+{\r
+       return SmPolicyDlgEx(hWnd, p, caption, false);\r
+}\r
+bool SmPolicyDlgEx(HWND hWnd, POLICY *p, wchar_t *caption, bool cascade_mode)\r
+{\r
+       return SmPolicyDlgEx2(hWnd, p, caption, cascade_mode, POLICY_CURRENT_VERSION);\r
+}\r
+bool SmPolicyDlgEx2(HWND hWnd, POLICY *p, wchar_t *caption, bool cascade_mode, UINT ver)\r
+{\r
+       SM_POLICY s;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (caption == NULL)\r
+       {\r
+               caption = _UU("SM_POLICY_DEF_CAPTION");\r
+       }\r
+\r
+       Zero(&s, sizeof(s));\r
+       s.Caption = caption;\r
+       s.Policy = ClonePolicy(p);\r
+       s.CascadeMode = cascade_mode;\r
+       s.Ver = ver;\r
+\r
+       ret = Dialog(hWnd, D_SM_POLICY, SmPolicyDlgProc, &s);\r
+\r
+       if (ret)\r
+       {\r
+               Copy(p, s.Policy, sizeof(POLICY));\r
+       }\r
+\r
+       Free(s.Policy);\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザー編集確定\r
+void SmEditUserDlgOk(HWND hWnd, SM_EDIT_USER *s)\r
+{\r
+       RPC_SET_USER t;\r
+       RPC_SET_USER *u;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SmEditUserDlgUpdate(hWnd, s);\r
+\r
+       Zero(&t, sizeof(t));\r
+       u = &s->SetUser;\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), u->HubName);\r
+       StrCpy(t.Name, sizeof(t.Name), u->Name);\r
+       StrCpy(t.GroupName, sizeof(t.GroupName), u->GroupName);\r
+       UniStrCpy(t.Realname, sizeof(t.Realname), u->Realname);\r
+       UniStrCpy(t.Note, sizeof(t.Note), u->Note);\r
+       t.ExpireTime = u->ExpireTime;\r
+       t.AuthType = u->AuthType;\r
+       t.AuthData = CopyAuthData(u->AuthData, t.AuthType);\r
+\r
+       if (IsChecked(hWnd, R_POLICY))\r
+       {\r
+               t.Policy = ClonePolicy(u->Policy);\r
+       }\r
+       else\r
+       {\r
+               t.Policy = NULL;\r
+       }\r
+\r
+       if (s->EditMode == false)\r
+       {\r
+               if (CALL(hWnd, ScCreateUser(s->Rpc, &t)) == false)\r
+               {\r
+                       FocusEx(hWnd, E_USERNAME);\r
+                       return;\r
+               }\r
+               FreeRpcSetUser(&t);\r
+\r
+               MsgBoxEx(hWnd, MB_ICONINFORMATION, _UU("SM_USER_CREEATE_OK"), u->Name);\r
+       }\r
+       else\r
+       {\r
+               if (CALL(hWnd, ScSetUser(s->Rpc, &t)) == false)\r
+               {\r
+                       FocusEx(hWnd, E_REALNAME);\r
+                       return;\r
+               }\r
+               FreeRpcSetUser(&t);\r
+       }\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// ユーザー編集初期化\r
+void SmEditUserDlgInit(HWND hWnd, SM_EDIT_USER *s)\r
+{\r
+       RPC_SET_USER *u;\r
+       wchar_t tmp[MAX_SIZE];\r
+       UINT i;\r
+       UINT icons[6] = {ICO_PASS, ICO_KEY, ICO_CERT, ICO_SERVER_CERT,\r
+               ICO_TOWER, ICO_LINK};\r
+       RECT rect;\r
+\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_USER);\r
+\r
+       u = &s->SetUser;\r
+\r
+       // カラム初期化\r
+       LvInit(hWnd, L_AUTH);\r
+       LvSetStyle(hWnd, L_AUTH, LVS_EX_GRIDLINES);\r
+\r
+       GetClientRect(DlgItem(hWnd, L_AUTH), &rect);\r
+       LvInsertColumn(hWnd, L_AUTH, 0, L"Name", rect.right - rect.left);\r
+\r
+       for (i = 0;i < 6;i++)\r
+       {\r
+               LvInsert(hWnd, L_AUTH, icons[i], (void *)i, 1, SmGetAuthTypeStr(i));\r
+       }\r
+\r
+       // ユーザー名など\r
+       SetTextA(hWnd, E_USERNAME, u->Name);\r
+       SetText(hWnd, E_REALNAME, u->Realname);\r
+       SetText(hWnd, E_NOTE, u->Note);\r
+\r
+\r
+       // 有効期限\r
+       if (u->ExpireTime == 0)\r
+       {\r
+               SYSTEMTIME st;\r
+               Check(hWnd, R_EXPIRES, false);\r
+               GetLocalTime(&st);\r
+               UINT64ToSystem(&st, SystemToUINT64(&st) + (60 * 60 * 24 * 1000));\r
+               st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;\r
+               DateTime_SetSystemtime(DlgItem(hWnd, E_EXPIRES_DATE), GDT_VALID, &st);\r
+               DateTime_SetSystemtime(DlgItem(hWnd, E_EXPIRES_TIME), GDT_VALID, &st);\r
+       }\r
+       else\r
+       {\r
+               SYSTEMTIME st;\r
+               UINT64ToSystem(&st, SystemToLocal64(u->ExpireTime));\r
+               Check(hWnd, R_EXPIRES, true);\r
+               DateTime_SetSystemtime(DlgItem(hWnd, E_EXPIRES_DATE), GDT_VALID, &st);\r
+               DateTime_SetSystemtime(DlgItem(hWnd, E_EXPIRES_TIME), GDT_VALID, &st);\r
+       }\r
+\r
+       SetStyle(hWnd, E_EXPIRES_DATE, DTS_LONGDATEFORMAT);\r
+       SetWindowLong(DlgItem(hWnd, E_EXPIRES_TIME), GWL_STYLE, WS_CHILDWINDOW | WS_VISIBLE | WS_TABSTOP | DTS_RIGHTALIGN | DTS_TIMEFORMAT | DTS_UPDOWN);\r
+\r
+       // グループ名\r
+       SetTextA(hWnd, E_GROUP, u->GroupName);\r
+\r
+       // 認証方法\r
+       LvSelect(hWnd, L_AUTH, u->AuthType);\r
+\r
+       SetText(hWnd, S_CERT_INFO, _UU("SM_EDIT_USER_CERT_INFO"));\r
+\r
+       switch (u->AuthType)\r
+       {\r
+       case AUTHTYPE_PASSWORD:\r
+               if (s->EditMode)\r
+               {\r
+                       SetTextA(hWnd, E_PASSWORD1, HIDDEN_PASSWORD);\r
+                       SetTextA(hWnd, E_PASSWORD2, HIDDEN_PASSWORD);\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_USERCERT:\r
+               SmGetCertInfoStr(tmp, sizeof(tmp), ((AUTHUSERCERT *)u->AuthData)->UserX);\r
+               break;\r
+\r
+       case AUTHTYPE_ROOTCERT:\r
+               if (u->AuthData != NULL)\r
+               {\r
+                       AUTHROOTCERT *c = (AUTHROOTCERT *)u->AuthData;\r
+                       if (c->CommonName != NULL && UniStrLen(c->CommonName) != 0)\r
+                       {\r
+                               Check(hWnd, R_CN, true);\r
+                               SetText(hWnd, E_CN, c->CommonName);\r
+                       }\r
+                       else\r
+                       {\r
+                               Check(hWnd, R_CN, false);\r
+                       }\r
+                       if (c->Serial != NULL && c->Serial->size != 0)\r
+                       {\r
+                               X_SERIAL *s = c->Serial;\r
+                               char *tmp;\r
+                               UINT tmp_size = s->size * 3 + 1;\r
+                               tmp = ZeroMalloc(tmp_size);\r
+                               BinToStrEx(tmp, tmp_size, s->data, s->size);\r
+                               SetTextA(hWnd, E_SERIAL, tmp);\r
+                               Free(tmp);\r
+                               Check(hWnd, R_SERIAL, true);\r
+                       }\r
+                       else\r
+                       {\r
+                               Check(hWnd, R_SERIAL, false);\r
+                       }\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_RADIUS:\r
+               if (u->AuthData != NULL)\r
+               {\r
+                       AUTHRADIUS *r = (AUTHRADIUS *)u->AuthData;\r
+                       if (UniStrLen(r->RadiusUsername) != 0)\r
+                       {\r
+                               Check(hWnd, R_SET_RADIUS_USERNAME, true);\r
+                               SetText(hWnd, E_RADIUS_USERNAME, r->RadiusUsername);\r
+                       }\r
+                       else\r
+                       {\r
+                               Check(hWnd, R_SET_RADIUS_USERNAME, false);\r
+                       }\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_NT:\r
+               if (u->AuthData != NULL)\r
+               {\r
+                       AUTHNT *n = (AUTHNT *)u->AuthData;\r
+                       if (UniStrLen(n->NtUsername) != 0)\r
+                       {\r
+                               Check(hWnd, R_SET_RADIUS_USERNAME, true);\r
+                               SetText(hWnd, E_RADIUS_USERNAME, n->NtUsername);\r
+                       }\r
+                       else\r
+                       {\r
+                               Check(hWnd, R_SET_RADIUS_USERNAME, false);\r
+                       }\r
+               }\r
+               break;\r
+       }\r
+\r
+       if (u->Policy != NULL)\r
+       {\r
+               Check(hWnd, R_POLICY, true);\r
+       }\r
+\r
+       s->Inited = true;\r
+\r
+       SmEditUserDlgUpdate(hWnd, s);\r
+\r
+       if (s->EditMode == false)\r
+       {\r
+               Focus(hWnd, E_USERNAME);\r
+               SetText(hWnd, 0, _UU("SM_EDIT_USER_CAPTION_1"));\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_EDIT_USER_CAPTION_2"), s->SetUser.Name);\r
+               SetText(hWnd, 0, tmp);\r
+\r
+               Disable(hWnd, E_USERNAME);\r
+               FocusEx(hWnd, E_REALNAME);\r
+       }\r
+}\r
+\r
+// ユーザー編集コントロール更新\r
+void SmEditUserDlgUpdate(HWND hWnd, SM_EDIT_USER *s)\r
+{\r
+       RPC_SET_USER *u;\r
+       bool ok = true;\r
+       UINT old_authtype;\r
+       char tmp1[MAX_SIZE];\r
+       char tmp2[MAX_SIZE];\r
+       bool authtype_changed = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->Inited == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       u = &s->SetUser;\r
+\r
+       // ユーザー名\r
+       GetTxtA(hWnd, E_USERNAME, u->Name, sizeof(u->Name));\r
+       Trim(u->Name);\r
+       if (StrLen(u->Name) == 0 || IsUserName(u->Name) == false)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       // 本名\r
+       GetTxt(hWnd, E_REALNAME, u->Realname, sizeof(u->Realname));\r
+       UniTrim(u->Realname);\r
+\r
+       // メモ\r
+       GetTxt(hWnd, E_NOTE, u->Note, sizeof(u->Note));\r
+       UniTrim(u->Realname);\r
+\r
+       // グループ\r
+       GetTxtA(hWnd, E_GROUP, u->GroupName, sizeof(u->GroupName));\r
+       Trim(u->GroupName);\r
+\r
+       // 有効期限\r
+       if (IsChecked(hWnd, R_EXPIRES) == false)\r
+       {\r
+               u->ExpireTime = 0;\r
+               Disable(hWnd, E_EXPIRES_DATE);\r
+               Disable(hWnd, E_EXPIRES_TIME);\r
+       }\r
+       else\r
+       {\r
+               SYSTEMTIME st1, st2;\r
+               Enable(hWnd, E_EXPIRES_DATE);\r
+               Enable(hWnd, E_EXPIRES_TIME);\r
+               DateTime_GetSystemtime(DlgItem(hWnd, E_EXPIRES_DATE), &st1);\r
+               DateTime_GetSystemtime(DlgItem(hWnd, E_EXPIRES_TIME), &st2);\r
+               st1.wHour = st2.wHour;\r
+               st1.wMinute = st2.wMinute;\r
+               st1.wSecond = st2.wSecond;\r
+               st1.wMilliseconds = st2.wMilliseconds;\r
+               u->ExpireTime = LocalToSystem64(SystemToUINT64(&st1));\r
+       }\r
+\r
+       // 認証方法\r
+       old_authtype = u->AuthType;\r
+       u->AuthType = LvGetSelected(hWnd, L_AUTH);\r
+\r
+       if (StrCmpi(u->Name, "*") == 0)\r
+       {\r
+               if (u->AuthType != AUTHTYPE_RADIUS && u->AuthType != AUTHTYPE_NT)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       if (u->AuthType == INFINITE)\r
+       {\r
+               ok = false;\r
+               u->AuthType = 0;\r
+       }\r
+       if (old_authtype != u->AuthType)\r
+       {\r
+               authtype_changed = true;\r
+       }\r
+\r
+       if (authtype_changed)\r
+       {\r
+               FreeAuthData(old_authtype, u->AuthData);\r
+               u->AuthData = NULL;\r
+               switch (u->AuthType)\r
+               {\r
+               case AUTHTYPE_ANONYMOUS:\r
+                       u->AuthData = NULL;\r
+                       break;\r
+\r
+               case AUTHTYPE_PASSWORD:\r
+                       u->AuthData = NewPasswordAuthData("", "");\r
+                       GetTxtA(hWnd, E_PASSWORD1, tmp1, sizeof(tmp1));\r
+                       if (StrCmp(tmp1, HIDDEN_PASSWORD) == 0)\r
+                       {\r
+                               SetTextA(hWnd, E_PASSWORD1, "");\r
+                       }\r
+                       GetTxtA(hWnd, E_PASSWORD2, tmp2, sizeof(tmp2));\r
+                       if (StrCmp(tmp2, HIDDEN_PASSWORD) == 0)\r
+                       {\r
+                               SetTextA(hWnd, E_PASSWORD2, "");\r
+                       }\r
+                       break;\r
+\r
+               case AUTHTYPE_USERCERT:\r
+                       u->AuthData = NewUserCertAuthData(NULL);\r
+                       SetText(hWnd, S_CERT_INFO, _UU("SM_EDIT_USER_CERT_INFO"));\r
+                       break;\r
+\r
+               case AUTHTYPE_ROOTCERT:\r
+                       u->AuthData = NewRootCertAuthData(NULL, NULL);\r
+                       break;\r
+\r
+               case AUTHTYPE_NT:\r
+                       u->AuthData = NewNTAuthData(L"");\r
+                       break;\r
+\r
+               case AUTHTYPE_RADIUS:\r
+                       u->AuthData = NewRadiusAuthData(L"");\r
+                       break;\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, S_RADIUS_3, (u->AuthType == AUTHTYPE_RADIUS) || (u->AuthType == AUTHTYPE_NT));\r
+       SetEnable(hWnd, R_SET_RADIUS_USERNAME, (u->AuthType == AUTHTYPE_RADIUS) || (u->AuthType == AUTHTYPE_NT));\r
+       SetEnable(hWnd, S_RADIUS_1, (u->AuthType == AUTHTYPE_RADIUS) || (u->AuthType == AUTHTYPE_NT));\r
+\r
+       if (StrCmp(u->Name, "*") == 0)\r
+       {\r
+               Check(hWnd, R_SET_RADIUS_USERNAME, false);\r
+               Disable(hWnd, R_SET_RADIUS_USERNAME);\r
+       }\r
+\r
+       if ((u->AuthType == AUTHTYPE_RADIUS) || (u->AuthType == AUTHTYPE_NT))\r
+       {\r
+               SetEnable(hWnd, E_RADIUS_USERNAME, IsChecked(hWnd, R_SET_RADIUS_USERNAME));\r
+               SetEnable(hWnd, S_RADIUS_2, IsChecked(hWnd, R_SET_RADIUS_USERNAME));\r
+       }\r
+       else\r
+       {\r
+               SetEnable(hWnd, E_RADIUS_USERNAME, false);\r
+               SetEnable(hWnd, S_RADIUS_2, false);\r
+       }\r
+\r
+       SetEnable(hWnd, S_PASSWORD_1, u->AuthType == AUTHTYPE_PASSWORD);\r
+       SetEnable(hWnd, S_PASSWORD_2, u->AuthType == AUTHTYPE_PASSWORD);\r
+       SetEnable(hWnd, S_PASSWORD_3, u->AuthType == AUTHTYPE_PASSWORD);\r
+       SetEnable(hWnd, E_PASSWORD1, u->AuthType == AUTHTYPE_PASSWORD);\r
+       SetEnable(hWnd, E_PASSWORD2, u->AuthType == AUTHTYPE_PASSWORD);\r
+\r
+       SetEnable(hWnd, S_USER_CERT_1, u->AuthType == AUTHTYPE_USERCERT);\r
+       SetEnable(hWnd, S_CERT_INFO, u->AuthType == AUTHTYPE_USERCERT);\r
+       SetEnable(hWnd, B_LOAD_CERT, u->AuthType == AUTHTYPE_USERCERT);\r
+\r
+       if (u->AuthType == AUTHTYPE_USERCERT)\r
+       {\r
+               SetEnable(hWnd, B_VIEW_CERT, ((AUTHUSERCERT *)u->AuthData)->UserX != NULL);\r
+       }\r
+       else\r
+       {\r
+               SetEnable(hWnd, B_VIEW_CERT, false);\r
+       }\r
+\r
+       SetEnable(hWnd, S_ROOT_CERT_1, u->AuthType == AUTHTYPE_ROOTCERT);\r
+       SetEnable(hWnd, S_ROOT_CERT_2, u->AuthType == AUTHTYPE_ROOTCERT);\r
+       SetEnable(hWnd, S_ROOT_CERT_3, u->AuthType == AUTHTYPE_ROOTCERT);\r
+       SetEnable(hWnd, R_CN, u->AuthType == AUTHTYPE_ROOTCERT);\r
+       SetEnable(hWnd, R_SERIAL, u->AuthType == AUTHTYPE_ROOTCERT);\r
+\r
+       if (u->AuthType == AUTHTYPE_ROOTCERT)\r
+       {\r
+               SetEnable(hWnd, E_CN, IsChecked(hWnd, R_CN));\r
+               SetEnable(hWnd, E_SERIAL, IsChecked(hWnd, R_SERIAL));\r
+       }\r
+       else\r
+       {\r
+               Disable(hWnd, E_CN);\r
+               Disable(hWnd, E_SERIAL);\r
+       }\r
+\r
+       switch (u->AuthType)\r
+       {\r
+       case AUTHTYPE_PASSWORD:\r
+               GetTxtA(hWnd, E_PASSWORD1, tmp1, sizeof(tmp1));\r
+               GetTxtA(hWnd, E_PASSWORD2, tmp2, sizeof(tmp2));\r
+               if (StrCmp(tmp1, tmp2) != 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+               else\r
+               {\r
+                       if (StrCmp(tmp1, HIDDEN_PASSWORD) != 0)\r
+                       {\r
+                               HashPassword(((AUTHPASSWORD *)u->AuthData)->HashedKey, u->Name, tmp1);\r
+                       }\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_USERCERT:\r
+               if (((AUTHUSERCERT *)u->AuthData)->UserX == NULL)\r
+               {\r
+                       ok = false;\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_ROOTCERT:\r
+               Free(((AUTHROOTCERT *)u->AuthData)->CommonName);\r
+               ((AUTHROOTCERT *)u->AuthData)->CommonName = NULL;\r
+               if (IsChecked(hWnd, R_CN) && (IsEmpty(hWnd, E_CN) == false))\r
+               {\r
+                       ((AUTHROOTCERT *)u->AuthData)->CommonName = GetText(hWnd, E_CN);\r
+                       UniTrim(((AUTHROOTCERT *)u->AuthData)->CommonName);\r
+               }\r
+               if (IsChecked(hWnd, R_CN) && ((AUTHROOTCERT *)u->AuthData)->CommonName == NULL)\r
+               {\r
+                       ok = false;\r
+               }\r
+               FreeXSerial(((AUTHROOTCERT *)u->AuthData)->Serial);\r
+               ((AUTHROOTCERT *)u->AuthData)->Serial = NULL;\r
+               if (IsChecked(hWnd, R_SERIAL))\r
+               {\r
+                       char *serial_str = GetTextA(hWnd, E_SERIAL);\r
+                       if (serial_str != NULL)\r
+                       {\r
+                               BUF *b = StrToBin(serial_str);\r
+                               if (b->Size >= 1)\r
+                               {\r
+                                       ((AUTHROOTCERT *)u->AuthData)->Serial = NewXSerial(b->Buf, b->Size);\r
+                               }\r
+                               FreeBuf(b);\r
+                               Free(serial_str);\r
+                       }\r
+               }\r
+               if (IsChecked(hWnd, R_SERIAL) && ((AUTHROOTCERT *)u->AuthData)->Serial == NULL)\r
+               {\r
+                       ok = false;\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_RADIUS:\r
+               Free(((AUTHRADIUS *)u->AuthData)->RadiusUsername);\r
+               ((AUTHRADIUS *)u->AuthData)->RadiusUsername = NULL;\r
+               if (IsChecked(hWnd, R_SET_RADIUS_USERNAME) && (IsEmpty(hWnd, E_RADIUS_USERNAME) == false))\r
+               {\r
+                       ((AUTHRADIUS *)u->AuthData)->RadiusUsername = GetText(hWnd, E_RADIUS_USERNAME);\r
+               }\r
+               if (IsChecked(hWnd, R_SET_RADIUS_USERNAME) && ((AUTHRADIUS *)u->AuthData)->RadiusUsername == NULL)\r
+               {\r
+                       ok = false;\r
+               }\r
+               break;\r
+\r
+       case AUTHTYPE_NT:\r
+               Free(((AUTHNT *)u->AuthData)->NtUsername);\r
+               ((AUTHNT *)u->AuthData)->NtUsername = NULL;\r
+               if (IsChecked(hWnd, R_SET_RADIUS_USERNAME) && (IsEmpty(hWnd, E_RADIUS_USERNAME) == false))\r
+               {\r
+                       ((AUTHNT *)u->AuthData)->NtUsername = GetText(hWnd, E_RADIUS_USERNAME);\r
+               }\r
+               if (IsChecked(hWnd, R_SET_RADIUS_USERNAME) && ((AUTHNT *)u->AuthData)->NtUsername == NULL)\r
+               {\r
+                       ok = false;\r
+               }\r
+               break;\r
+       }\r
+\r
+       SetEnable(hWnd, B_POLICY, IsChecked(hWnd, R_POLICY));\r
+       if (IsChecked(hWnd, R_POLICY))\r
+       {\r
+               if (u->Policy == NULL)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// ユーザー編集ダイアログプロシージャ\r
+UINT SmEditUserDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_EDIT_USER *s = (SM_EDIT_USER *)param;\r
+       NMHDR *n;\r
+       POLICY *policy;\r
+       X *x = NULL;\r
+       wchar_t tmp[MAX_SIZE];\r
+       char name[MAX_SIZE];\r
+       char *ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmEditUserDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_USERNAME:\r
+               case E_REALNAME:\r
+               case E_NOTE:\r
+               case R_EXPIRES:\r
+               case E_EXPIRES_DATE:\r
+               case E_EXPIRES_TIME:\r
+               case E_GROUP:\r
+               case L_AUTH:\r
+               case R_SET_RADIUS_USERNAME:\r
+               case E_RADIUS_USERNAME:\r
+               case R_POLICY:\r
+               case E_PASSWORD1:\r
+               case E_PASSWORD2:\r
+               case R_CN:\r
+               case E_CN:\r
+               case R_SERIAL:\r
+               case E_SERIAL:\r
+                       SmEditUserDlgUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // OK ボタン\r
+                       SmEditUserDlgOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_POLICY:\r
+                       UniFormat(tmp, sizeof(tmp), _UU("SM_EDIT_USER_POL_DLG"), s->SetUser.Name);\r
+                       // ポリシー\r
+                       if (s->SetUser.Policy == NULL)\r
+                       {\r
+                               policy = ClonePolicy(GetDefaultPolicy());\r
+                               if (SmPolicyDlgEx2(hWnd, policy, tmp, false, s->p->PolicyVer))\r
+                               {\r
+                                       s->SetUser.Policy = policy;\r
+                                       SmEditUserDlgUpdate(hWnd, s);\r
+                               }\r
+                               else\r
+                               {\r
+                                       Free(policy);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               SmPolicyDlgEx2(hWnd, s->SetUser.Policy, tmp, false, s->p->PolicyVer);\r
+                       }\r
+                       break;\r
+\r
+               case B_GROUP:\r
+                       // グループの参照\r
+                       GetTxtA(hWnd, E_GROUP, name, sizeof(name));\r
+                       Trim(name);\r
+                       ret = SmSelectGroupDlg(hWnd, s->Hub, StrLen(name) == 0 ? NULL : name);\r
+                       if (ret != NULL)\r
+                       {\r
+                               SetTextA(hWnd, E_GROUP, ret);\r
+                               Free(ret);\r
+                       }\r
+                       else\r
+                       {\r
+                               SetTextA(hWnd, E_GROUP, "");\r
+                       }\r
+                       FocusEx(hWnd, E_GROUP);\r
+                       break;\r
+\r
+               case B_LOAD_CERT:\r
+                       // 証明書の指定\r
+                       if (CmLoadXFromFileOrSecureCard(hWnd, &x))\r
+                       {\r
+UPDATE_CERT:\r
+                               if (s->SetUser.AuthType == AUTHTYPE_USERCERT)\r
+                               {\r
+                                       wchar_t tmp[MAX_SIZE];\r
+                                       FreeX(((AUTHUSERCERT *)s->SetUser.AuthData)->UserX);\r
+                                       ((AUTHUSERCERT *)s->SetUser.AuthData)->UserX = x;\r
+                                       SmGetCertInfoStr(tmp, sizeof(tmp), x);\r
+                                       SetText(hWnd, S_CERT_INFO, tmp);\r
+                                       SmEditUserDlgUpdate(hWnd, s);\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (x != NULL)\r
+                                       {\r
+                                               FreeX(x);\r
+                                               x = NULL;\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_VIEW_CERT:\r
+                       // 証明書の表示\r
+                       if (s->SetUser.AuthType == AUTHTYPE_USERCERT)\r
+                       {\r
+                               CertDlg(hWnd, ((AUTHUSERCERT *)s->SetUser.AuthData)->UserX, NULL, true);\r
+                       }\r
+                       break;\r
+\r
+               case B_CREATE:\r
+                       // 作成\r
+                       GetTxtA(hWnd, E_USERNAME, name, sizeof(name));\r
+                       Trim(name);\r
+                       if (SmCreateCert(hWnd, &x, NULL, false, name))\r
+                       {\r
+                               if (s->SetUser.AuthType != AUTHTYPE_USERCERT)\r
+                               {\r
+                                       LvSelect(hWnd, L_AUTH, 2);\r
+                               }\r
+                               goto UPDATE_CERT;\r
+                       }\r
+                       break;\r
+\r
+               case R_SET_RADIUS_USERNAME:\r
+                       if (IsChecked(hWnd, R_SET_RADIUS_USERNAME))\r
+                       {\r
+                               FocusEx(hWnd, E_RADIUS_USERNAME);\r
+                       }\r
+                       break;\r
+\r
+               case R_EXPIRES:\r
+                       if (IsChecked(hWnd, R_EXPIRES))\r
+                       {\r
+                               Focus(hWnd, E_EXPIRES_DATE);\r
+                       }\r
+                       break;\r
+\r
+               case R_POLICY:\r
+                       if (IsChecked(hWnd, R_POLICY))\r
+                       {\r
+                               Focus(hWnd, B_POLICY);\r
+                       }\r
+                       break;\r
+\r
+               case R_CN:\r
+                       if (IsChecked(hWnd, R_CN))\r
+                       {\r
+                               Focus(hWnd, E_CN);\r
+                       }\r
+                       break;\r
+\r
+               case R_SERIAL:\r
+                       if (IsChecked(hWnd, R_SERIAL))\r
+                       {\r
+                               Focus(hWnd, E_SERIAL);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_AUTH:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmEditUserDlgUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザーの編集ダイアログ\r
+bool SmEditUserDlg(HWND hWnd, SM_HUB *s, char *username)\r
+{\r
+       SM_EDIT_USER e;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL || username == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&e, sizeof(e));\r
+       e.p = s->p;\r
+       e.Rpc = s->Rpc;\r
+       e.Hub = s;\r
+\r
+       // ユーザーの取得\r
+       StrCpy(e.SetUser.HubName, sizeof(e.SetUser.HubName), e.Hub->HubName);\r
+       StrCpy(e.SetUser.Name, sizeof(e.SetUser.Name), username);\r
+\r
+       if (CALL(hWnd, ScGetUser(s->Rpc, &e.SetUser)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       e.EditMode = true;\r
+\r
+       ret = Dialog(hWnd, D_SM_EDIT_USER, SmEditUserDlgProc, &e);\r
+\r
+       FreeRpcSetUser(&e.SetUser);\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザーの新規作成ダイアログ\r
+bool SmCreateUserDlg(HWND hWnd, SM_HUB *s)\r
+{\r
+       SM_EDIT_USER e;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&e, sizeof(e));\r
+       e.EditMode = false;\r
+       e.p = s->p;\r
+       e.Rpc = s->Rpc;\r
+       e.Hub = s;\r
+\r
+       // 新しいユーザーの設定\r
+       StrCpy(e.SetUser.HubName, sizeof(e.SetUser.HubName), e.Hub->HubName);\r
+       e.SetUser.AuthType = CLIENT_AUTHTYPE_PASSWORD;\r
+       e.SetUser.AuthData = NewPasswordAuthData("", "");\r
+\r
+       ret = Dialog(hWnd, D_SM_EDIT_USER, SmEditUserDlgProc, &e);\r
+\r
+       FreeRpcSetUser(&e.SetUser);\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザー認証方法の文字列の取得\r
+wchar_t *SmGetAuthTypeStr(UINT id)\r
+{\r
+       return GetAuthTypeStr(id);\r
+}\r
+\r
+// ユーザーリスト初期化\r
+void SmUserListInit(HWND hWnd, SM_USER *s)\r
+{\r
+       wchar_t tmp1[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_USER);\r
+\r
+       // カラム初期化\r
+       LvInit(hWnd, L_USER);\r
+       LvSetStyle(hWnd, L_USER, LVS_EX_GRIDLINES);\r
+       LvInsertColumn(hWnd, L_USER, 0, _UU("SM_USER_COLUMN_1"), 120);\r
+       LvInsertColumn(hWnd, L_USER, 1, _UU("SM_USER_COLUMN_2"), 100);\r
+       LvInsertColumn(hWnd, L_USER, 2, _UU("SM_USER_COLUMN_3"), 100);\r
+       LvInsertColumn(hWnd, L_USER, 3, _UU("SM_USER_COLUMN_4"), 130);\r
+       LvInsertColumn(hWnd, L_USER, 4, _UU("SM_USER_COLUMN_5"), 100);\r
+       LvInsertColumn(hWnd, L_USER, 5, _UU("SM_USER_COLUMN_6"), 90);\r
+       LvInsertColumn(hWnd, L_USER, 6, _UU("SM_USER_COLUMN_7"), 120);\r
+\r
+       FormatText(hWnd, S_TITLE, s->Hub->HubName);\r
+\r
+       if (s->GroupName != NULL)\r
+       {\r
+               GetTxt(hWnd, 0, tmp1, sizeof(tmp1));\r
+               UniFormat(tmp2, sizeof(tmp2), _UU("SM_GROUP_MEMBER_STR"), s->GroupName);\r
+               UniStrCat(tmp1, sizeof(tmp1), tmp2);\r
+               SetText(hWnd, S_TITLE, tmp1);\r
+               Disable(hWnd, B_CREATE);\r
+       }\r
+\r
+       if (s->SelectMode)\r
+       {\r
+               SetStyle(hWnd, L_USER, LVS_SINGLESEL);\r
+       }\r
+\r
+       SmUserListRefresh(hWnd, s);\r
+\r
+       if (s->SelectMode)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               UINT i;\r
+               StrToUni(tmp, sizeof(tmp), s->SelectedName);\r
+               i = LvSearchStr(hWnd, L_USER, 0, tmp);\r
+               if (i != INFINITE)\r
+               {\r
+                       LvSelect(hWnd, L_USER, i);\r
+               }\r
+\r
+               if (s->AllowGroup)\r
+               {\r
+                       SetText(hWnd, B_DELETE, _UU("SM_SELECT_ALT_GROUP"));\r
+               }\r
+       }\r
+}\r
+\r
+// ユーザーリスト更新\r
+void SmUserListRefresh(HWND hWnd, SM_USER *s)\r
+{\r
+       LVB *b;\r
+       RPC_ENUM_USER t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       StrCpy(t.HubName, sizeof(t.HubName), s->Hub->HubName);\r
+       if (CALL(hWnd, ScEnumUser(s->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       for (i = 0;i < t.NumUser;i++)\r
+       {\r
+               RPC_ENUM_USER_ITEM *e = &t.Users[i];\r
+               wchar_t name[MAX_SIZE];\r
+               wchar_t group[MAX_SIZE];\r
+               wchar_t num[MAX_SIZE];\r
+               wchar_t time[MAX_SIZE];\r
+\r
+               if (s->GroupName != NULL)\r
+               {\r
+                       if (StrCmpi(s->GroupName, e->GroupName) != 0)\r
+                       {\r
+                               continue;\r
+                       }\r
+               }\r
+\r
+               StrToUni(name, sizeof(name), e->Name);\r
+\r
+               if (StrLen(e->GroupName) != 0)\r
+               {\r
+                       StrToUni(group, sizeof(group), e->GroupName);\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(group, sizeof(group), _UU("SM_NO_GROUP"));\r
+               }\r
+\r
+               UniToStru(num, e->NumLogin);\r
+\r
+               GetDateTimeStrEx64(time, sizeof(time), SystemToLocal64(e->LastLoginTime), NULL);\r
+\r
+               LvInsertAdd(b, e->DenyAccess ? ICO_USER_DENY : ICO_USER, NULL, 7,\r
+                       name, e->Realname, group, e->Note, SmGetAuthTypeStr(e->AuthType),\r
+                       num, time);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_USER);\r
+\r
+       FreeRpcEnumUser(&t);\r
+\r
+       SmUserListUpdate(hWnd, s);\r
+}\r
+\r
+// ユーザーリストコントロール更新\r
+void SmUserListUpdate(HWND hWnd, SM_USER *s)\r
+{\r
+       bool b = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSelected(hWnd, L_USER) == false || LvIsMultiMasked(hWnd, L_USER))\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       if (s->SelectMode)\r
+       {\r
+               SetText(hWnd, IDOK, _UU("SM_SELECT_USER"));\r
+               SetText(hWnd, IDCANCEL, _UU("SM_SELECT_NO"));\r
+               SetText(hWnd, S_TITLE, _UU("SM_PLEASE_SELECT"));\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, b);\r
+\r
+       SetEnable(hWnd, B_STATUS, b);\r
+       SetEnable(hWnd, B_DELETE, (b && s->SelectedName == false) || s->AllowGroup);\r
+       SetEnable(hWnd, B_CREATE, s->SelectedName == false);\r
+}\r
+\r
+// ユーザーリストダイアログプロシージャ\r
+UINT SmUserListProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_USER *s = (SM_USER *)param;\r
+       NMHDR *n;\r
+       wchar_t *str;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmUserListInit(hWnd, s);\r
+\r
+               if (s->CreateNow)\r
+               {\r
+                       // すぐに作成\r
+                       if (IsEnable(hWnd, B_CREATE))\r
+                       {\r
+                               Command(hWnd, B_CREATE);\r
+                       }\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       if (s->SelectMode == false)\r
+                       {\r
+                               // プロパティ\r
+                               str = LvGetSelectedStr(hWnd, L_USER, 0);\r
+                               if (str != NULL)\r
+                               {\r
+                                       char name[MAX_SIZE];\r
+                                       UniToStr(name, sizeof(name), str);\r
+\r
+                                       if (SmEditUserDlg(hWnd, s->Hub, name))\r
+                                       {\r
+                                               SmUserListRefresh(hWnd, s);\r
+                                       }\r
+\r
+                                       Free(str);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // ユーザーを選択した\r
+                               str = LvGetSelectedStr(hWnd, L_USER, 0);\r
+                               if (str != NULL)\r
+                               {\r
+                                       char name[MAX_SIZE];\r
+                                       UniToStr(name, sizeof(name), str);\r
+\r
+                                       s->SelectedName = CopyStr(name);\r
+\r
+                                       EndDialog(hWnd, true);\r
+\r
+                                       Free(str);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_CREATE:\r
+                       // 新規作成\r
+                       if (SmCreateUserDlg(hWnd, s->Hub))\r
+                       {\r
+                               SmUserListRefresh(hWnd, s);\r
+                       }\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       if (s->AllowGroup)\r
+                       {\r
+                               // グループ選択\r
+                               EndDialog(hWnd, INFINITE);\r
+                       }\r
+                       else\r
+                       {\r
+                               // 削除\r
+                               str = LvGetSelectedStr(hWnd, L_USER, 0);\r
+                               if (str != NULL)\r
+                               {\r
+                                       RPC_DELETE_USER t;\r
+                                       char name[MAX_SIZE];\r
+                                       UniToStr(name, sizeof(name), str);\r
+\r
+                                       Zero(&t, sizeof(t));\r
+                                       StrCpy(t.HubName, sizeof(t.HubName), s->Hub->HubName);\r
+                                       StrCpy(t.Name, sizeof(t.Name), name);\r
+\r
+                                       if (MsgBoxEx(hWnd, MB_YESNO | MB_DEFBUTTON2 | MB_ICONQUESTION,\r
+                                               _UU("SM_USER_DELETE_MSG"), str) == IDYES)\r
+                                       {\r
+                                               if (CALL(hWnd, ScDeleteUser(s->Rpc, &t)))\r
+                                               {\r
+                                                       SmUserListRefresh(hWnd, s);\r
+                                               }\r
+                                       }\r
+\r
+                                       Free(str);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_STATUS:\r
+                       // ユーザー情報表示\r
+                       str = LvGetSelectedStr(hWnd, L_USER, 0);\r
+                       if (str != NULL)\r
+                       {\r
+                               char name[MAX_SIZE];\r
+                               wchar_t tmp[MAX_SIZE];\r
+                               SM_USER_INFO info;\r
+                               UniToStr(name, sizeof(name), str);\r
+\r
+                               UniFormat(tmp, sizeof(tmp), _UU("SM_USERINFO_CAPTION"), name);\r
+\r
+                               Zero(&info, sizeof(info));\r
+                               info.p = s->p;\r
+                               info.Rpc = s->Rpc;\r
+                               info.Hub = s->Hub;\r
+                               info.Username = name;\r
+\r
+                               SmStatusDlg(hWnd, s->p, &info, false, true, tmp, ICO_USER, NULL, SmRefreshUserInfo);\r
+\r
+                               Free(str);\r
+                       }\r
+                       break;\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       // 更新\r
+                       SmUserListRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_USER:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               // コントロール更新\r
+                               SmUserListUpdate(hWnd, s);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_USER);\r
+\r
+       return 0;\r
+}\r
+\r
+// ユーザーリストダイアログ (選択)\r
+char *SmSelectUserDlg(HWND hWnd, SM_HUB *s, char *default_name)\r
+{\r
+       return SmSelectUserDlgEx(hWnd, s, default_name, false);\r
+}\r
+char *SmSelectUserDlgEx(HWND hWnd, SM_HUB *s, char *default_name, bool allow_group)\r
+{\r
+       UINT ret;\r
+       SM_USER user;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&user, sizeof(user));\r
+       user.Hub = s;\r
+       user.p = s->p;\r
+       user.Rpc = s->Rpc;\r
+       user.GroupName = NULL;\r
+       user.SelectedName = default_name;\r
+       user.SelectMode = true;\r
+       user.AllowGroup = allow_group;\r
+\r
+       ret = Dialog(hWnd, D_SM_USER, SmUserListProc, &user);\r
+\r
+       if (ret == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+       else if (ret == INFINITE)\r
+       {\r
+               // グループの選択\r
+               return SmSelectGroupDlg(hWnd, s, default_name);\r
+       }\r
+       else\r
+       {\r
+               return user.SelectedName;\r
+       }\r
+}\r
+\r
+// ユーザーリストダイアログ (グループ名でフィルタ)\r
+void SmUserListDlgEx(HWND hWnd, SM_HUB *s, char *groupname, bool create)\r
+{\r
+       SM_USER user;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&user, sizeof(user));\r
+       user.Hub = s;\r
+       user.p = s->p;\r
+       user.Rpc = s->Rpc;\r
+       user.GroupName = groupname;\r
+       user.CreateNow = create;\r
+\r
+       Dialog(hWnd, D_SM_USER, SmUserListProc, &user);\r
+}\r
+\r
+// ユーザーリストダイアログ\r
+void SmUserListDlg(HWND hWnd, SM_HUB *s)\r
+{\r
+       SmUserListDlgEx(hWnd, s, NULL, false);\r
+}\r
+\r
+// 初期化\r
+void SmHubDlgInit(HWND hWnd, SM_HUB *s)\r
+{\r
+       CAPSLIST *caps;\r
+       bool support_user, support_group, support_accesslist, support_cascade,\r
+               support_log, support_config_hub, support_secure_nat, support_config_radius;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FormatText(hWnd, 0, s->HubName);\r
+       FormatText(hWnd, S_TITLE, s->HubName);\r
+       SetIcon(hWnd, 0, ICO_HUB);\r
+       DlgFont(hWnd, S_TITLE, 15, true);\r
+\r
+       LvInit(hWnd, L_STATUS);\r
+       LvSetStyle(hWnd, L_STATUS, LVS_EX_GRIDLINES);\r
+       LvInsertColumn(hWnd, L_STATUS, 0, _UU("SM_STATUS_COLUMN_1"), 0);\r
+       LvInsertColumn(hWnd, L_STATUS, 1, _UU("SM_STATUS_COLUMN_2"), 0);\r
+\r
+       caps = s->p->CapsList;\r
+\r
+       support_user = GetCapsInt(caps, "i_max_users_per_hub") == 0 ? false : true;\r
+       support_group = GetCapsInt(caps, "i_max_groups_per_hub") == 0 ? false : true;\r
+       support_accesslist = GetCapsInt(caps, "i_max_access_lists") == 0 ? false : true;\r
+       support_cascade = GetCapsBool(caps, "b_support_cascade");\r
+       support_log = GetCapsBool(caps, "b_support_config_log");\r
+       support_config_hub = GetCapsBool(caps, "b_support_config_hub");\r
+       support_secure_nat = GetCapsBool(caps, "b_support_securenat");\r
+       support_config_radius = GetCapsBool(caps, "b_support_radius");\r
+\r
+       SetEnable(hWnd, B_USER, support_user);\r
+       SetEnable(hWnd, S_USER, support_user);\r
+\r
+       SetEnable(hWnd, B_GROUP, support_group);\r
+       SetEnable(hWnd, S_GROUP, support_group);\r
+\r
+       SetEnable(hWnd, B_ACCESS, support_accesslist);\r
+       SetEnable(hWnd, S_ACCESS, support_accesslist);\r
+\r
+       SetEnable(hWnd, B_PROPERTY, s->p->ServerType != SERVER_TYPE_FARM_MEMBER);\r
+       SetEnable(hWnd, S_PROPERTY, s->p->ServerType != SERVER_TYPE_FARM_MEMBER);\r
+\r
+       SetEnable(hWnd, B_RADIUS, support_config_radius);\r
+       SetEnable(hWnd, S_RADIUS, support_config_radius);\r
+\r
+       SetEnable(hWnd, B_LINK, support_cascade);\r
+       SetEnable(hWnd, S_LINK, support_cascade);\r
+\r
+       SetEnable(hWnd, B_LOG, support_log);\r
+       SetEnable(hWnd, S_LOG, support_log);\r
+\r
+       SetEnable(hWnd, B_CA, support_config_hub);\r
+       SetEnable(hWnd, S_CA, support_config_hub);\r
+\r
+       SetEnable(hWnd, B_SNAT, support_secure_nat);\r
+       SetEnable(hWnd, S_SNAT, support_secure_nat);\r
+\r
+       SetEnable(hWnd, B_CRL, GetCapsBool(caps, "b_support_crl"));\r
+\r
+       SetEnable(hWnd, B_LOG_FILE, GetCapsBool(caps, "b_support_read_log"));\r
+\r
+       SmHubDlgRefresh(hWnd, s);\r
+}\r
+\r
+// コントロール更新\r
+void SmHubDlgUpdate(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+}\r
+\r
+// 内容更新\r
+void SmHubDlgRefresh(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SmRefreshHubStatus(hWnd, s->p, (void *)s->HubName);\r
+       LvAutoSize(hWnd, L_STATUS);\r
+\r
+       SmHubDlgUpdate(hWnd, s);\r
+}\r
+\r
+// HUB 管理ダイアログ\r
+UINT SmHubDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_HUB *s = (SM_HUB *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmHubDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_USER:\r
+                       // ユーザー\r
+                       SmUserListDlg(hWnd, s);\r
+                       SmHubDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case B_GROUP:\r
+                       // グループ\r
+                       SmGroupListDlg(hWnd, s);\r
+                       SmHubDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case B_ACCESS:\r
+                       // アクセスリスト\r
+                       SmAccessListDlg(hWnd, s);\r
+                       SmHubDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case B_PROPERTY:\r
+                       // プロパティ\r
+                       if (SmEditHubDlg(hWnd, s->p, s->HubName))\r
+                       {\r
+                               SmHubDlgRefresh(hWnd, s);\r
+                       }\r
+                       break;\r
+\r
+               case B_RADIUS:\r
+                       // Radius\r
+                       SmRadiusDlg(hWnd, s);\r
+                       SmHubDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case B_LINK:\r
+                       // カスケード\r
+                       SmLinkDlg(hWnd, s);\r
+                       SmHubDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case B_SESSION:\r
+                       // セッション\r
+                       SmSessionDlg(hWnd, s);\r
+                       SmHubDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case B_LOG:\r
+                       // ログ\r
+                       Dialog(hWnd, D_SM_LOG, SmLogDlg, s);\r
+                       SmHubDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case B_CA:\r
+                       // CA\r
+                       SmCaDlg(hWnd, s);\r
+                       SmHubDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       // 更新\r
+                       SmHubDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case B_SNAT:\r
+                       // SecureNAT\r
+                       Dialog(hWnd, D_SM_SNAT, SmSNATDlgProc, s);\r
+                       SmHubDlgRefresh(hWnd, s);\r
+                       break;\r
+\r
+               case B_CRL:\r
+                       // 無効な証明書の一覧\r
+                       Dialog(hWnd, D_SM_CRL, SmCrlDlgProc, s);\r
+                       break;\r
+\r
+               case B_LOG_FILE:\r
+                       // ログファイル\r
+                       Dialog(hWnd, D_SM_LOG_FILE, SmLogFileDlgProc, s->p);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// HUB の管理\r
+void SmHubDlg(HWND hWnd, SM_HUB *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_SM_HUB, SmHubDlgProc, s);\r
+}\r
+\r
+// サーバー パスワードの変更\r
+UINT SmChangeServerPasswordDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SERVER *p = (SM_SERVER *)param;\r
+       char tmp1[MAX_SIZE];\r
+       char tmp2[MAX_SIZE];\r
+       UCHAR hash[SHA1_SIZE];\r
+       RPC_SET_PASSWORD t;\r
+       SETTING *setting;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SetIcon(hWnd, 0, ICO_USER_ADMIN);\r
+               FormatText(hWnd, 0, p->ServerName);\r
+               FormatText(hWnd, S_TITLE, p->ServerName);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // OK ボタン\r
+                       GetTxtA(hWnd, E_PASSWORD1, tmp1, sizeof(tmp1));\r
+                       GetTxtA(hWnd, E_PASSWORD2, tmp2, sizeof(tmp2));\r
+                       if (StrCmp(tmp1, tmp2) != 0)\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONSTOP, _UU("SM_CHANGE_PASSWORD_1"));\r
+                               FocusEx(hWnd, E_PASSWORD2);\r
+                               break;\r
+                       }\r
+                       if (StrLen(tmp1) == 0)\r
+                       {\r
+                               if (MsgBox(hWnd, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2, _UU("SM_CHANGE_PASSWORD_2")) == IDNO)\r
+                               {\r
+                                       Focus(hWnd, E_PASSWORD1);\r
+                                       break;\r
+                               }\r
+                       }\r
+                       Zero(&t, sizeof(t));\r
+                       Hash(t.HashedPassword, tmp1, StrLen(tmp1), true);\r
+                       Copy(hash, t.HashedPassword, sizeof(hash));\r
+                       if (CALL(hWnd, ScSetServerPassword(p->Rpc, &t)) == false)\r
+                       {\r
+                               break;\r
+                       }\r
+                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("SM_CHANGE_PASSWORD_3"));\r
+\r
+                       // 接続設定のパスワードを変更する\r
+                       setting = SmGetSetting(p->CurrentSetting->Title);\r
+                       if (setting != NULL && sm->TempSetting == NULL)\r
+                       {\r
+                               if (IsZero(setting->HashedPassword, SHA1_SIZE) == false)\r
+                               {\r
+                                       Copy(setting->HashedPassword, hash, SHA1_SIZE);\r
+                                       SmWriteSettingList();\r
+                               }\r
+                       }\r
+\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// サーバー ファーム コントローラへの接続状況更新\r
+bool SmRefreshFarmConnectionInfo(HWND hWnd, SM_SERVER *p, void *param)\r
+{\r
+       RPC_FARM_CONNECTION_STATUS t;\r
+       LVB *b;\r
+       wchar_t tmp[MAX_SIZE];\r
+       char str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CALL(hWnd, ScGetFarmConnectionStatus(p->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       if (t.Online == false)\r
+       {\r
+               LvInsertAdd(b, ICO_FARM, NULL, 2, _UU("SM_FC_IP"), _UU("SM_FC_NOT_CONNECTED"));\r
+\r
+               LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_FC_PORT"), _UU("SM_FC_NOT_CONNECTED"));\r
+       }\r
+       else\r
+       {\r
+               IPToStr32(str, sizeof(str), t.Ip);\r
+               StrToUni(tmp, sizeof(tmp), str);\r
+               LvInsertAdd(b, ICO_FARM, NULL, 2, _UU("SM_FC_IP"), tmp);\r
+\r
+               UniToStru(tmp, t.Port);\r
+               LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_FC_PORT"), tmp);\r
+       }\r
+\r
+       LvInsertAdd(b,\r
+               t.Online ? ICO_SERVER_ONLINE_EX : ICO_PROTOCOL_X, NULL, 2,\r
+               _UU("SM_FC_STATUS"),\r
+               t.Online ? _UU("SM_FC_ONLINE") : _UU("SM_FC_OFFLINE"));\r
+\r
+       if (t.Online == false)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_FC_ERROR_TAG"), _E(t.LastError), t.LastError);\r
+               LvInsertAdd(b, ICO_STOP, NULL, 2,\r
+                       _UU("SM_FC_LAST_ERROR"), tmp);\r
+       }\r
+\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.StartedTime), NULL);\r
+       LvInsertAdd(b, ICO_INFORMATION, NULL, 2, _UU("SM_FC_START_TIME"), tmp);\r
+\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.FirstConnectedTime), NULL);\r
+       LvInsertAdd(b, ICO_INFORMATION, NULL, 2, _UU("SM_FC_FIRST_TIME"), tmp);\r
+\r
+       //if (t.Online == false)\r
+       {\r
+               GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.CurrentConnectedTime), NULL);\r
+               LvInsertAdd(b, ICO_INFORMATION, NULL, 2, _UU("SM_FC_CURRENT_TIME"), tmp);\r
+       }\r
+\r
+       UniToStru(tmp, t.NumTry);\r
+       LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_FC_NUM_TRY"), tmp);\r
+\r
+       UniToStru(tmp, t.NumConnected);\r
+       LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_FC_NUM_CONNECTED"), tmp);\r
+\r
+       UniToStru(tmp, t.NumFailed);\r
+       LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_FC_NUM_FAILED"), tmp);\r
+\r
+       LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+       return true;\r
+}\r
+\r
+// 初期化\r
+void SmFarmMemberDlgInit(HWND hWnd, SM_SERVER *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_FARM);\r
+\r
+       FormatText(hWnd, S_TITLE, p->ServerName);\r
+\r
+       // カラム初期化\r
+       LvInit(hWnd, L_FARM_MEMBER);\r
+       LvSetStyle(hWnd, L_FARM_MEMBER, LVS_EX_GRIDLINES);\r
+       LvInsertColumn(hWnd, L_FARM_MEMBER, 0, _UU("SM_FM_COLUMN_1"), 90);\r
+       LvInsertColumn(hWnd, L_FARM_MEMBER, 1, _UU("SM_FM_COLUMN_2"), 150);\r
+       LvInsertColumn(hWnd, L_FARM_MEMBER, 2, _UU("SM_FM_COLUMN_3"), 140);\r
+       LvInsertColumn(hWnd, L_FARM_MEMBER, 3, _UU("SM_FM_COLUMN_4"), 60);\r
+       LvInsertColumn(hWnd, L_FARM_MEMBER, 4, _UU("SM_FM_COLUMN_5"), 80);\r
+       LvInsertColumn(hWnd, L_FARM_MEMBER, 5, _UU("SM_FM_COLUMN_6"), 80);\r
+       LvInsertColumn(hWnd, L_FARM_MEMBER, 6, _UU("SM_FM_COLUMN_7"), 80);\r
+       LvInsertColumn(hWnd, L_FARM_MEMBER, 7, _UU("SM_FM_COLUMN_8"), 160);\r
+       LvInsertColumn(hWnd, L_FARM_MEMBER, 8, _UU("SM_FM_COLUMN_9"), 160);\r
+\r
+       SmFarmMemberDlgRefresh(hWnd, p);\r
+}\r
+\r
+// 更新\r
+void SmFarmMemberDlgUpdate(HWND hWnd, SM_SERVER *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, LvIsSelected(hWnd, L_FARM_MEMBER) && (LvIsMultiMasked(hWnd, L_FARM_MEMBER) == false));\r
+       SetEnable(hWnd, B_CERT, LvIsSelected(hWnd, L_FARM_MEMBER) && (LvIsMultiMasked(hWnd, L_FARM_MEMBER) == false));\r
+}\r
+\r
+// 内容更新\r
+void SmFarmMemberDlgRefresh(HWND hWnd, SM_SERVER *p)\r
+{\r
+       RPC_ENUM_FARM t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CALL(hWnd, ScEnumFarmMember(p->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       LvReset(hWnd, L_FARM_MEMBER);\r
+\r
+       for (i = 0;i < t.NumFarm;i++)\r
+       {\r
+               RPC_ENUM_FARM_ITEM *e = &t.Farms[i];\r
+               wchar_t tmp1[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               wchar_t tmp3[64];\r
+               wchar_t tmp4[64];\r
+               wchar_t tmp5[64];\r
+               wchar_t tmp6[64];\r
+               wchar_t tmp7[64];\r
+               wchar_t tmp8[64];\r
+\r
+               GetDateTimeStrEx64(tmp1, sizeof(tmp1), SystemToLocal64(e->ConnectedTime), NULL);\r
+               StrToUni(tmp2, sizeof(tmp2), e->Hostname);\r
+               UniToStru(tmp3, e->Point);\r
+               UniToStru(tmp4, e->NumSessions);\r
+               UniToStru(tmp5, e->NumTcpConnections);\r
+               UniToStru(tmp6, e->NumHubs);\r
+               UniToStru(tmp7, e->AssignedClientLicense);\r
+               UniToStru(tmp8, e->AssignedBridgeLicense);\r
+\r
+               LvInsert(hWnd, L_FARM_MEMBER, e->Controller ? ICO_FARM : ICO_TOWER, (void *)e->Id, 9,\r
+                       e->Controller ? _UU("SM_FM_CONTROLLER") : _UU("SM_FM_MEMBER"),\r
+                       tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8);\r
+       }\r
+\r
+       FreeRpcEnumFarm(&t);\r
+\r
+       SmFarmMemberDlgUpdate(hWnd, p);\r
+}\r
+\r
+// OK ボタン\r
+void SmFarmMemberDlgOnOk(HWND hWnd, SM_SERVER *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+}\r
+\r
+// ファーム メンバ証明書の表示\r
+void SmFarmMemberCert(HWND hWnd, SM_SERVER *p, UINT id)\r
+{\r
+       RPC_FARM_INFO t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL || id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.Id = id;\r
+\r
+       if (CALL(hWnd, ScGetFarmInfo(p->Rpc, &t)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CertDlg(hWnd, t.ServerCert, NULL, true);\r
+\r
+       FreeRpcFarmInfo(&t);\r
+}\r
+\r
+// ファームメンバ情報の更新\r
+bool SmRefreshFarmMemberInfo(HWND hWnd, SM_SERVER *p, void *param)\r
+{\r
+       RPC_FARM_INFO t;\r
+       UINT id = (UINT)param;\r
+       LVB *b;\r
+       UINT i;\r
+       wchar_t tmp[MAX_SIZE];\r
+       char str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL || id == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.Id = id;\r
+\r
+       if (CALL(hWnd, ScGetFarmInfo(p->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       LvInsertAdd(b, ICO_FARM, NULL, 2, _UU("SM_FMINFO_TYPE"),\r
+               t.Controller ? _UU("SM_FARM_CONTROLLER") : _UU("SM_FARM_MEMBER"));\r
+\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.ConnectedTime), NULL);\r
+       LvInsertAdd(b, ICO_INFORMATION, NULL, 2, _UU("SM_FMINFO_CONNECT_TIME"), tmp);\r
+\r
+       IPToStr32(str, sizeof(str), t.Ip);\r
+       StrToUni(tmp, sizeof(tmp), str);\r
+       LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_FMINFO_IP"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.Hostname);\r
+       LvInsertAdd(b, ICO_TOWER, NULL, 2, _UU("SM_FMINFO_HOSTNAME"), tmp);\r
+\r
+       UniToStru(tmp, t.Point);\r
+       LvInsertAdd(b, ICO_TEST, NULL, 2, _UU("SM_FMINFO_POINT"), tmp);\r
+\r
+       UniToStru(tmp, t.Weight);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_FMINFO_WEIGHT"), tmp);\r
+\r
+       UniToStru(tmp, t.NumPort);\r
+       LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_FMINFO_NUM_PORT"), tmp);\r
+\r
+       for (i = 0;i < t.NumPort;i++)\r
+       {\r
+               wchar_t tmp2[MAX_SIZE];\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_FMINFO_PORT"), i + 1);\r
+               UniToStru(tmp2, t.Ports[i]);\r
+               LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, tmp, tmp2);\r
+       }\r
+\r
+       UniToStru(tmp, t.NumFarmHub);\r
+       LvInsertAdd(b, ICO_HUB_OFFLINE, NULL, 2, _UU("SM_FMINFO_NUM_HUB"), tmp);\r
+\r
+       for (i = 0;i < t.NumFarmHub;i++)\r
+       {\r
+               wchar_t tmp2[MAX_SIZE];\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_FMINFO_HUB"), i + 1);\r
+               UniFormat(tmp2, sizeof(tmp2),\r
+                       t.FarmHubs[i].DynamicHub ? _UU("SM_FMINFO_HUB_TAG_2") : _UU("SM_FMINFO_HUB_TAG_1"),\r
+                       t.FarmHubs[i].HubName);\r
+               LvInsertAdd(b, ICO_HUB, NULL, 2, tmp, tmp2);\r
+       }\r
+\r
+       UniToStru(tmp, t.NumSessions);\r
+       LvInsertAdd(b, ICO_VPN, NULL, 2, _UU("SM_FMINFO_NUM_SESSION"), tmp);\r
+\r
+       UniToStru(tmp, t.NumTcpConnections);\r
+       LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_FMINFO_NUN_CONNECTION"), tmp);\r
+\r
+       LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+       FreeRpcFarmInfo(&t);\r
+\r
+       return true;\r
+}\r
+\r
+// ファームメンバ一覧ダイアログ\r
+UINT SmFarmMemberDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SERVER *p = (SM_SERVER *)param;\r
+       NMHDR *n;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmFarmMemberDlgInit(hWnd, p);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // ファーム メンバの情報を表示\r
+                       i = LvGetSelected(hWnd, L_FARM_MEMBER);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               SmStatusDlg(hWnd, p, LvGetParam(hWnd, L_FARM_MEMBER, i), false, true,\r
+                                       _UU("SM_FMINFO_CAPTION"), ICO_FARM, NULL, SmRefreshFarmMemberInfo);\r
+                       }\r
+                       break;\r
+\r
+               case B_CERT:\r
+                       // サーバー証明書の表示\r
+                       i = LvGetSelected(hWnd, L_FARM_MEMBER);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               SmFarmMemberCert(hWnd, p, (UINT)LvGetParam(hWnd, L_FARM_MEMBER, i));\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       // 更新\r
+                       SmFarmMemberDlgRefresh(hWnd, p);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->code)\r
+               {\r
+               case LVN_ITEMCHANGED:\r
+                       switch (n->idFrom)\r
+                       {\r
+                       case L_FARM_MEMBER:\r
+                               SmFarmMemberDlgUpdate(hWnd, p);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_FARM_MEMBER);\r
+\r
+       return 0;\r
+}\r
+\r
+// 文字列をポートリストに変換\r
+LIST *SmStrToPortList(char *str)\r
+{\r
+       return StrToPortList(str);\r
+}\r
+\r
+// ダイアログ初期化\r
+void SmFarmDlgInit(HWND hWnd, SM_SERVER *p)\r
+{\r
+       RPC_FARM t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_FARM);\r
+\r
+       // 現在の設定を取得\r
+       Zero(&t, sizeof(t));\r
+       if (CALL(hWnd, ScGetFarmSetting(p->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       if (t.Weight == 0)\r
+       {\r
+               t.Weight = FARM_DEFAULT_WEIGHT;\r
+       }\r
+\r
+       FormatText(hWnd, S_TITLE, p->ServerName);\r
+       DlgFont(hWnd, S_CURRENT, 11, true);\r
+\r
+       SetText(hWnd, S_CURRENT, GetServerTypeStr(t.ServerType));\r
+\r
+       switch (t.ServerType)\r
+       {\r
+       case SERVER_TYPE_FARM_CONTROLLER:\r
+               Check(hWnd, R_CONTROLLER, true);\r
+               break;\r
+\r
+       case SERVER_TYPE_FARM_MEMBER:\r
+               Check(hWnd, R_MEMBER, true);\r
+               break;\r
+\r
+       default:\r
+               Check(hWnd, R_STANDALONE, true);\r
+               break;\r
+       }\r
+\r
+       SetInt(hWnd, E_WEIGHT, t.Weight);\r
+\r
+       if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               Check(hWnd, R_CONTROLLER_ONLY, t.ControllerOnly);\r
+       }\r
+\r
+       if (t.ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               char tmp[MAX_PUBLIC_PORT_NUM * 8];\r
+               UINT i;\r
+               if (t.PublicIp != 0)\r
+               {\r
+                       IpSet(hWnd, E_IP, t.PublicIp);\r
+               }\r
+               StrCpy(tmp, sizeof(tmp), "");\r
+               if (t.NumPort != 0)\r
+               {\r
+                       for (i = 0;i < t.NumPort;i++)\r
+                       {\r
+                               Format(tmp, sizeof(tmp), "%s%u", tmp, t.Ports[i]);\r
+                               if (i != (t.NumPort - 1))\r
+                               {\r
+                                       StrCat(tmp, sizeof(tmp), ", ");\r
+                               }\r
+                       }\r
+                       SetTextA(hWnd, E_PORT, tmp);\r
+               }\r
+               SetTextA(hWnd, E_CONTROLLER, t.ControllerName);\r
+               SetIntEx(hWnd, E_CONTROLLER_PORT, t.ControllerPort);\r
+               SetTextA(hWnd, E_PASSWORD, HIDDEN_PASSWORD);\r
+       }\r
+       else\r
+       {\r
+               // ポート一覧を書き込む\r
+               RPC_LISTENER_LIST t;\r
+               char tmp[MAX_PUBLIC_PORT_NUM * 8];\r
+               Zero(&t, sizeof(t));\r
+               StrCpy(tmp, sizeof(tmp), "");\r
+               if (CALL(hWnd, ScEnumListener(p->Rpc, &t)))\r
+               {\r
+                       UINT i;\r
+                       if (t.NumPort != 0)\r
+                       {\r
+                               for (i = 0;i < t.NumPort;i++)\r
+                               {\r
+                                       Format(tmp, sizeof(tmp), "%s%u", tmp, t.Ports[i]);\r
+                                       if (i != (t.NumPort - 1))\r
+                                       {\r
+                                               StrCat(tmp, sizeof(tmp), ", ");\r
+                                       }\r
+                               }\r
+                               SetTextA(hWnd, E_PORT, tmp);\r
+                       }\r
+                       FreeRpcListenerList(&t);\r
+               }\r
+       }\r
+\r
+       SmFarmDlgUpdate(hWnd, p);\r
+\r
+       FreeRpcFarm(&t);\r
+\r
+       Focus(hWnd, IDOK);\r
+}\r
+\r
+// ダイアログ更新\r
+void SmFarmDlgUpdate(HWND hWnd, SM_SERVER *p)\r
+{\r
+       bool ok = true;\r
+       bool farm_member_control = false;\r
+       char *s;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_MEMBER))\r
+       {\r
+               LIST *o;\r
+               UINT i = IpGetFilledNum(hWnd, E_IP);\r
+               if (i != 0 && i != 4)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               s = GetTextA(hWnd, E_PORT);\r
+               o = SmStrToPortList(s);\r
+               if (o == NULL)\r
+               {\r
+                       ok = false;\r
+               }\r
+               else\r
+               {\r
+                       ReleaseList(o);\r
+               }\r
+               Free(s);\r
+\r
+               if (IsEmpty(hWnd, E_CONTROLLER))\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               i = GetInt(hWnd, E_CONTROLLER_PORT);\r
+               if (i == 0 || i >= 65536)\r
+               {\r
+                       ok = false;\r
+               }\r
+\r
+               farm_member_control = true;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_STANDALONE))\r
+       {\r
+               Disable(hWnd, S_1);\r
+               Disable(hWnd, S_2);\r
+               Disable(hWnd, E_WEIGHT);\r
+       }\r
+       else\r
+       {\r
+               Enable(hWnd, S_1);\r
+               Enable(hWnd, S_2);\r
+               Enable(hWnd, E_WEIGHT);\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_CONTROLLER))\r
+       {\r
+               Enable(hWnd, R_CONTROLLER_ONLY);\r
+       }\r
+       else\r
+       {\r
+               Disable(hWnd, R_CONTROLLER_ONLY);\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_CONTROLLER) || IsChecked(hWnd, R_MEMBER))\r
+       {\r
+               if (GetInt(hWnd, E_WEIGHT) == 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, S_IP_1, farm_member_control);\r
+       SetEnable(hWnd, E_IP, farm_member_control);\r
+       SetEnable(hWnd, S_IP_2, farm_member_control);\r
+       SetEnable(hWnd, S_PORT_1, farm_member_control);\r
+       SetEnable(hWnd, E_PORT, farm_member_control);\r
+       SetEnable(hWnd, S_PORT_2, farm_member_control);\r
+       SetEnable(hWnd, S_PORT_3, farm_member_control);\r
+       SetEnable(hWnd, E_CONTROLLER, farm_member_control);\r
+       SetEnable(hWnd, S_CONTROLLER, farm_member_control);\r
+       SetEnable(hWnd, E_CONTROLLER_PORT, farm_member_control);\r
+       SetEnable(hWnd, S_CONTROLLER_PORT, farm_member_control);\r
+       SetEnable(hWnd, S_PASSWORD, farm_member_control);\r
+       SetEnable(hWnd, E_PASSWORD, farm_member_control);\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// OK ボタン\r
+void SmFarmDlgOnOk(HWND hWnd, SM_SERVER *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メッセージ表示\r
+       if (MsgBox(hWnd, MB_ICONEXCLAMATION | MB_OKCANCEL | MB_DEFBUTTON2,\r
+               _UU("SM_FARM_REBOOT_MSG")) == IDOK)\r
+       {\r
+               RPC_FARM t;\r
+               Zero(&t, sizeof(t));\r
+               t.ServerType = SERVER_TYPE_STANDALONE;\r
+               if (IsChecked(hWnd, R_CONTROLLER))\r
+               {\r
+                       t.ServerType = SERVER_TYPE_FARM_CONTROLLER;\r
+               }\r
+               if (IsChecked(hWnd, R_MEMBER))\r
+               {\r
+                       t.ServerType = SERVER_TYPE_FARM_MEMBER;\r
+               }\r
+\r
+               t.ControllerOnly = IsChecked(hWnd, R_CONTROLLER_ONLY);\r
+               t.Weight = GetInt(hWnd, E_WEIGHT);\r
+\r
+               if (t.ServerType == SERVER_TYPE_FARM_MEMBER)\r
+               {\r
+                       char *s;\r
+                       char pass[MAX_SIZE];\r
+                       t.PublicIp = IpGet(hWnd, E_IP);\r
+                       s = GetTextA(hWnd, E_PORT);\r
+                       if (s != NULL)\r
+                       {\r
+                               LIST *o = SmStrToPortList(s);\r
+                               if (o != NULL)\r
+                               {\r
+                                       UINT i;\r
+                                       t.NumPort = LIST_NUM(o);\r
+                                       t.Ports = ZeroMalloc(sizeof(UINT) * t.NumPort);\r
+                                       for (i = 0;i < t.NumPort;i++)\r
+                                       {\r
+                                               t.Ports[i] = (UINT)LIST_DATA(o, i);\r
+                                       }\r
+                                       ReleaseList(o);\r
+                               }\r
+                               Free(s);\r
+                       }\r
+                       GetTxtA(hWnd, E_CONTROLLER, t.ControllerName, sizeof(t.ControllerName));\r
+                       t.ControllerPort = GetInt(hWnd, E_CONTROLLER_PORT);\r
+                       GetTxtA(hWnd, E_PASSWORD, pass, sizeof(pass));\r
+                       if (StrCmp(pass, HIDDEN_PASSWORD) != 0)\r
+                       {\r
+                               Hash(t.MemberPassword, pass, StrLen(pass), true);\r
+                       }\r
+               }\r
+\r
+               // 設定更新\r
+               if (CALL(hWnd, ScSetFarmSetting(p->Rpc, &t)) == false)\r
+               {\r
+                       return;\r
+               }\r
+\r
+               FreeRpcFarm(&t);\r
+\r
+               EndDialog(hWnd, true);\r
+       }\r
+}\r
+\r
+// サーバー ファーム ダイアログ プロシージャ\r
+UINT SmFarmDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SERVER *p = (SM_SERVER *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmFarmDlgInit(hWnd, p);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_STANDALONE:\r
+               case R_CONTROLLER:\r
+               case R_MEMBER:\r
+               case E_IP:\r
+               case E_PORT:\r
+               case E_CONTROLLER:\r
+               case E_CONTROLLER_PORT:\r
+               case E_PASSWORD:\r
+               case R_CONTROLLER_ONLY:\r
+               case E_WEIGHT:\r
+                       SmFarmDlgUpdate(hWnd, p);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // OK ボタン\r
+                       SmFarmDlgOnOk(hWnd, p);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case R_MEMBER:\r
+                       if (IsChecked(hWnd, R_MEMBER))\r
+                       {\r
+                               Focus(hWnd, E_IP);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// サーバー ファーム構成\r
+bool SmFarmDlg(HWND hWnd, SM_SERVER *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return Dialog(hWnd, D_SM_FARM, SmFarmDlgProc, p);\r
+}\r
+\r
+// コネクション情報の更新\r
+bool SmRefreshConnectionStatus(HWND hWnd, SM_SERVER *p, void *param)\r
+{\r
+       RPC_CONNECTION_INFO t;\r
+       SM_CONNECTION_INFO *info = (SM_CONNECTION_INFO *)param;\r
+       LVB *b;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL || param == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.Name, sizeof(t.Name), info->ConnectionName);\r
+       if (CALL(hWnd, ScGetConnectionInfo(p->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.Name);\r
+       LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_CONNINFO_NAME"), tmp);\r
+\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_CONNINFO_TYPE"), SmGetConnectionTypeStr(t.Type));\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.Hostname);\r
+       LvInsertAdd(b, ICO_FARM, NULL, 2, _UU("SM_CONNINFO_HOSTNAME"), tmp);\r
+\r
+       UniToStru(tmp, t.Port);\r
+       LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_CONNINFO_PORT"), tmp);\r
+\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.ConnectedTime), NULL);\r
+       LvInsertAdd(b, ICO_INFORMATION, NULL, 2, _UU("SM_CONNINFO_TIME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.ServerStr);\r
+       LvInsertAdd(b, ICO_VPNSERVER, NULL, 2, _UU("SM_CONNINFO_SERVER_STR"), tmp);\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"%u.%02u", t.ServerVer / 100, t.ServerVer % 100);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_CONNINFO_SERVER_VER"), tmp);\r
+\r
+       UniToStru(tmp, t.ServerBuild);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_CONNINFO_SERVER_BUILD"), tmp);\r
+\r
+       if (StrLen(t.ClientStr) != 0)\r
+       {\r
+               StrToUni(tmp, sizeof(tmp), t.ClientStr);\r
+               LvInsertAdd(b, ICO_VPN, NULL, 2, _UU("SM_CONNINFO_CLIENT_STR"), tmp);\r
+\r
+               UniFormat(tmp, sizeof(tmp), L"%u.%02u", t.ClientVer / 100, t.ClientVer % 100);\r
+               LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_CONNINFO_CLIENT_VER"), tmp);\r
+\r
+               UniToStru(tmp, t.ClientBuild);\r
+               LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_CONNINFO_CLIENT_BUILD"), tmp);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+       return true;\r
+}\r
+\r
+// 初期化\r
+void SmConnectionDlgInit(HWND hWnd, SM_SERVER *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_PROTOCOL);\r
+       FormatText(hWnd, S_TITLE, p->ServerName);\r
+\r
+       // カラム初期化\r
+       LvInit(hWnd, L_LIST);\r
+       LvSetStyle(hWnd, L_LIST, LVS_EX_GRIDLINES);\r
+       LvInsertColumn(hWnd, L_LIST, 0, _UU("SM_CONN_COLUMN_1"), 90);\r
+       LvInsertColumn(hWnd, L_LIST, 1, _UU("SM_CONN_COLUMN_2"), 150);\r
+       LvInsertColumn(hWnd, L_LIST, 2, _UU("SM_CONN_COLUMN_3"), 200);\r
+       LvInsertColumn(hWnd, L_LIST, 3, _UU("SM_CONN_COLUMN_4"), 80);\r
+\r
+       SmConnectionDlgRefresh(hWnd, p);\r
+       SmConnectionDlgUpdate(hWnd, p);\r
+}\r
+\r
+// 更新\r
+void SmConnectionDlgRefresh(HWND hWnd, SM_SERVER *p)\r
+{\r
+       LVB *b;\r
+       UINT i;\r
+       RPC_ENUM_CONNECTION t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CALL(hWnd, ScEnumConnection(p->Rpc, &t)) == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       for (i = 0;i < t.NumConnection;i++)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               wchar_t name[MAX_SIZE];\r
+               wchar_t datetime[MAX_SIZE];\r
+               RPC_ENUM_CONNECTION_ITEM *e = &t.Connections[i];\r
+\r
+               StrToUni(name, sizeof(name), e->Name);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_HOSTNAME_AND_PORT"), e->Hostname, e->Port);\r
+               GetDateTimeStrEx64(datetime, sizeof(datetime), SystemToLocal64(e->ConnectedTime), NULL);\r
+\r
+               LvInsertAdd(b, ICO_PROTOCOL, NULL, 4, name, tmp, datetime,\r
+                       SmGetConnectionTypeStr(e->Type));\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_LIST);\r
+\r
+       FreeRpcEnumConnetion(&t);\r
+}\r
+\r
+// コントロール更新\r
+void SmConnectionDlgUpdate(HWND hWnd, SM_SERVER *p)\r
+{\r
+       bool b = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSelected(hWnd, L_LIST) && (LvIsMultiMasked(hWnd, L_LIST) == false))\r
+       {\r
+               b = true;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, b);\r
+       SetEnable(hWnd, B_DISCONNECT, b && p->ServerAdminMode);\r
+}\r
+\r
+// コネクション一覧プロシージャ\r
+UINT SmConnectionDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SERVER *p = (SM_SERVER *)param;\r
+       NMHDR *n;\r
+       wchar_t *s;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmConnectionDlgInit(hWnd, p);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // コネクション情報を表示\r
+                       s = LvGetSelectedStr(hWnd, L_LIST, 0);\r
+                       if (s != NULL)\r
+                       {\r
+                               wchar_t caption[MAX_SIZE];\r
+                               SM_CONNECTION_INFO info;\r
+                               UniFormat(caption, sizeof(caption), _UU("SM_CONNINFO_CAPTION"),\r
+                                       s);\r
+                               Zero(&info, sizeof(info));\r
+                               info.ConnectionName = CopyUniToStr(s);\r
+                               info.p = p;\r
+                               SmStatusDlg(hWnd, p, &info, false, false, caption, ICO_PROTOCOL,\r
+                                       NULL, SmRefreshConnectionStatus);\r
+                               Free(info.ConnectionName);\r
+                               Free(s);\r
+                       }\r
+                       break;\r
+\r
+               case B_DISCONNECT:\r
+                       // 切断\r
+                       s = LvGetSelectedStr(hWnd, L_LIST, 0);\r
+                       if (s != NULL)\r
+                       {\r
+                               if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2,\r
+                                       _UU("SM_CONN_DISCONNECT_MSG"), s) == IDYES)\r
+                               {\r
+                                       char tmp[MAX_SIZE];\r
+                                       RPC_DISCONNECT_CONNECTION t;\r
+\r
+                                       UniToStr(tmp, sizeof(tmp), s);\r
+                                       Zero(&t, sizeof(t));\r
+                                       StrCpy(t.Name, sizeof(t.Name), tmp);\r
+\r
+                                       if (CALL(hWnd, ScDisconnectConnection(p->Rpc, &t)))\r
+                                       {\r
+                                               SmConnectionDlgRefresh(hWnd, p);\r
+                                       }\r
+                               }\r
+                               Free(s);\r
+                       }\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       // 最新の状態に更新\r
+                       SmConnectionDlgRefresh(hWnd, p);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_LIST:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmConnectionDlgUpdate(hWnd, p);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_LIST);\r
+\r
+       return 0;\r
+}\r
+\r
+// コネクション一覧の表示\r
+void SmConnectionDlg(HWND hWnd, SM_SERVER *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(hWnd, D_SM_CONNECTION, SmConnectionDlgProc, p);\r
+}\r
+\r
+// コネクション種類文字列の取得\r
+wchar_t *SmGetConnectionTypeStr(UINT type)\r
+{\r
+       return GetConnectionTypeStr(type);\r
+}\r
+\r
+// サーバー情報の更新\r
+bool SmRefreshServerInfo(HWND hWnd, SM_SERVER *p, void *param)\r
+{\r
+       RPC_SERVER_INFO t;\r
+       LVB *b;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CALL(hWnd, ScGetServerInfo(p->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       // 製品名\r
+       StrToUni(tmp, sizeof(tmp), t.ServerProductName);\r
+       LvInsertAdd(b, ICO_VPNSERVER, NULL, 2, _UU("SM_INFO_PRODUCT_NAME"), tmp);\r
+\r
+       // バージョン\r
+       StrToUni(tmp, sizeof(tmp), t.ServerVersionString);\r
+       LvInsertAdd(b, ICO_INFORMATION, NULL, 2, _UU("SM_INFO_VERSION"), tmp);\r
+\r
+       // ビルド\r
+       StrToUni(tmp, sizeof(tmp), t.ServerBuildInfoString);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_INFO_BUILD"), tmp);\r
+\r
+       // ホスト名\r
+       StrToUni(tmp, sizeof(tmp), t.ServerHostName);\r
+       LvInsertAdd(b, ICO_TOWER, NULL, 2, _UU("SM_INFO_HOSTNAME"), tmp);\r
+\r
+       // 種類\r
+       LvInsertAdd(b, t.ServerType == SERVER_TYPE_STANDALONE ? ICO_SERVER_ONLINE : ICO_FARM, 0,\r
+               2, _UU("SM_ST_SERVER_TYPE"),\r
+               GetServerTypeStr(t.ServerType));\r
+\r
+       // OS\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.OsSystemName);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_SYSTEM_NAME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.OsProductName);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_PRODUCT_NAME"), tmp);\r
+\r
+       if (t.OsInfo.OsServicePack != 0)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_OS_SP_TAG"), t.OsInfo.OsServicePack);\r
+               LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_SERVICE_PACK"), tmp);\r
+       }\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.OsVendorName);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_VENDER_NAME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.OsVersion);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_VERSION"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.KernelName);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_KERNEL_NAME"), tmp);\r
+\r
+       StrToUni(tmp, sizeof(tmp), t.OsInfo.KernelVersion);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_OS_KERNEL_VERSION"), tmp);\r
+\r
+       SmAddServerCaps(b, p->CapsList);\r
+\r
+       LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+       FreeRpcServerInfo(&t);\r
+\r
+       return true;\r
+}\r
+\r
+// サーバーの Caps を画面に表示する\r
+void SmAddServerCaps(LVB *b, CAPSLIST *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (b == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(t->CapsList);i++)\r
+       {\r
+               CAPS *c = LIST_DATA(t->CapsList, i);\r
+               wchar_t title[MAX_SIZE];\r
+               char name[256];\r
+\r
+               Format(name, sizeof(name), "CT_%s", c->Name);\r
+\r
+               UniStrCpy(title, sizeof(title), _UU(name));\r
+\r
+               if (UniIsEmptyStr(title))\r
+               {\r
+                       UniFormat(title, sizeof(title), L"%S", (StrLen(c->Name) >= 2) ? c->Name + 2 : c->Name);\r
+               }\r
+\r
+               if (StartWith(c->Name, "b_"))\r
+               {\r
+                       bool icon_pass = c->Value == 0 ? false : true;\r
+                       if (StrCmpi(c->Name, "b_must_install_pcap") == 0)\r
+                       {\r
+                               // WinPcap の項目のみ反転する\r
+                               icon_pass = !icon_pass;\r
+                       }\r
+                       LvInsertAdd(b, icon_pass == false ? ICO_DISCARD : ICO_PASS,\r
+                               NULL, 2, title, c->Value == 0 ? _UU("CAPS_NO") : _UU("CAPS_YES"));\r
+               }\r
+               else\r
+               {\r
+                       wchar_t str[64];\r
+                       UniToStru(str, c->Value);\r
+                       LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, title, str);\r
+               }\r
+       }\r
+}\r
+\r
+// サーバー状態の更新\r
+bool SmRefreshServerStatus(HWND hWnd, SM_SERVER *p, void *param)\r
+{\r
+       RPC_SERVER_STATUS t;\r
+       LVB *b;\r
+       wchar_t tmp[MAX_SIZE];\r
+       char str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (CALL(hWnd, ScGetServerStatus(p->Rpc, &t)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       // サーバーの種類\r
+       LvInsertAdd(b, t.ServerType == SERVER_TYPE_STANDALONE ? ICO_SERVER_ONLINE : ICO_FARM, 0,\r
+               2, _UU("SM_ST_SERVER_TYPE"),\r
+               GetServerTypeStr(t.ServerType));\r
+\r
+       // TCP コネクション数\r
+       UniToStru(tmp, t.NumTcpConnections);\r
+       LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_ST_NUM_TCP"), tmp);\r
+\r
+       if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               // ローカル TCP コネクション数\r
+               UniToStru(tmp, t.NumTcpConnectionsLocal);\r
+               LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_ST_NUM_TCP_LOCAL"), tmp);\r
+\r
+               // リモート TCP コネクション数\r
+               UniToStru(tmp, t.NumTcpConnectionsRemote);\r
+               LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("SM_ST_NUM_TCP_REMOTE"), tmp);\r
+       }\r
+\r
+       // 仮想 HUB 数\r
+       UniToStru(tmp, t.NumHubTotal);\r
+       LvInsertAdd(b, ICO_HUB, NULL, 2, _UU("SM_ST_NUM_HUB_TOTAL"), tmp);\r
+\r
+       if (t.ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               // スタティック HUB 数\r
+               UniToStru(tmp, t.NumHubStatic);\r
+               LvInsertAdd(b, ICO_HUB, NULL, 2, _UU("SM_ST_NUM_HUB_STATIC"), tmp);\r
+\r
+               // ダイナミック HUB 数\r
+               UniToStru(tmp, t.NumHubDynamic);\r
+               LvInsertAdd(b, ICO_HUB, NULL, 2, _UU("SM_ST_NUM_HUB_DYNAMIC"), tmp);\r
+       }\r
+\r
+       // セッション数\r
+       UniToStru(tmp, t.NumSessionsTotal);\r
+       LvInsertAdd(b, ICO_VPN, NULL, 2, _UU("SM_ST_NUM_SESSION_TOTAL"), tmp);\r
+\r
+       if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               // ローカルセッション数\r
+               UniToStru(tmp, t.NumSessionsLocal);\r
+               LvInsertAdd(b, ICO_VPN, NULL, 2, _UU("SM_ST_NUM_SESSION_LOCAL"), tmp);\r
+\r
+               // ローカルセッション数\r
+               UniToStru(tmp, t.NumSessionsRemote);\r
+               LvInsertAdd(b, ICO_VPN, NULL, 2, _UU("SM_ST_NUM_SESSION_REMOTE"), tmp);\r
+       }\r
+\r
+       // MAC テーブル数\r
+       UniToStru(tmp, t.NumMacTables);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_ST_NUM_MAC_TABLE"), tmp);\r
+\r
+       // IP テーブル数\r
+       UniToStru(tmp, t.NumIpTables);\r
+       LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_ST_NUM_IP_TABLE"), tmp);\r
+\r
+       // ユーザー数\r
+       UniToStru(tmp, t.NumUsers);\r
+       LvInsertAdd(b, ICO_USER, NULL, 2, _UU("SM_ST_NUM_USERS"), tmp);\r
+\r
+       // グループ数\r
+       UniToStru(tmp, t.NumGroups);\r
+       LvInsertAdd(b, ICO_GROUP, NULL, 2, _UU("SM_ST_NUM_GROUPS"), tmp);\r
+\r
+       // 割り当て済みライセンス数\r
+       UniToStru(tmp, t.AssignedClientLicenses);\r
+       LvInsertAdd(b, ICO_CERT, NULL, 2, _UU("SM_ST_CLIENT_LICENSE"), tmp);\r
+       UniToStru(tmp, t.AssignedBridgeLicenses);\r
+       LvInsertAdd(b, ICO_CERT, NULL, 2, _UU("SM_ST_BRIDGE_LICENSE"), tmp);\r
+\r
+       if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               UniToStru(tmp, t.AssignedClientLicensesTotal);\r
+               LvInsertAdd(b, ICO_CERT, NULL, 2, _UU("SM_ST_CLIENT_LICENSE_EX"), tmp);\r
+               UniToStru(tmp, t.AssignedBridgeLicensesTotal);\r
+               LvInsertAdd(b, ICO_CERT, NULL, 2, _UU("SM_ST_BRIDGE_LICENSE_EX"), tmp);\r
+       }\r
+\r
+       // トラフィック\r
+       SmInsertTrafficInfo(b, &t.Traffic);\r
+\r
+       // サーバー起動時刻\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.StartTime), NULL);\r
+       LvInsertAdd(b, ICO_NULL, NULL, 2, _UU("SM_ST_START_TIME"), tmp);\r
+\r
+       // 現在時刻\r
+       GetDateTimeStrMilli64(str, sizeof(str), SystemToLocal64(t.CurrentTime));\r
+       StrToUni(tmp, sizeof(tmp), str);\r
+       LvInsertAdd(b, ICO_NULL, NULL, 2, _UU("SM_ST_CURRENT_TIME"), tmp);\r
+\r
+       // Tick 値\r
+       UniFormat(tmp, sizeof(tmp), L"%I64u", t.CurrentTick);\r
+       LvInsertAdd(b, ICO_NULL, NULL, 2, _UU("SM_ST_CURRENT_TICK"), tmp);\r
+\r
+       // メモリ情報\r
+       if (t.MemInfo.TotalMemory != 0)\r
+       {\r
+               char vv[128];\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.TotalMemory);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               LvInsertAdd(b, ICO_MEMORY, NULL, 2, _UU("SM_ST_TOTAL_MEMORY"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.UsedMemory);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               LvInsertAdd(b, ICO_MEMORY, NULL, 2, _UU("SM_ST_USED_MEMORY"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.FreeMemory);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               LvInsertAdd(b, ICO_MEMORY, NULL, 2, _UU("SM_ST_FREE_MEMORY"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.TotalPhys);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               LvInsertAdd(b, ICO_MEMORY, NULL, 2, _UU("SM_ST_TOTAL_PHYS"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.UsedPhys);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               LvInsertAdd(b, ICO_MEMORY, NULL, 2, _UU("SM_ST_USED_PHYS"), tmp);\r
+\r
+               ToStr3(vv, sizeof(vv), t.MemInfo.FreePhys);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);\r
+               LvInsertAdd(b, ICO_MEMORY, NULL, 2, _UU("SM_ST_FREE_PHYS"), tmp);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_STATUS);\r
+\r
+       return true;\r
+}\r
+\r
+// 初期化\r
+void SmSaveKeyPairDlgInit(HWND hWnd, SM_SAVE_KEY_PAIR *s)\r
+{\r
+       UINT current;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       current = MsRegReadInt(REG_CURRENT_USER, SM_REG_KEY, "SavePkcs12");\r
+\r
+       if (current == 1)\r
+       {\r
+               Check(hWnd, R_PKCS12, true);\r
+       }\r
+       else if (current == 2)\r
+       {\r
+               Check(hWnd, R_SECURE, true);\r
+       }\r
+       else\r
+       {\r
+               Check(hWnd, R_X509_AND_KEY, true);\r
+       }\r
+\r
+       SmSaveKeyPairDlgUpdate(hWnd, s);\r
+}\r
+\r
+// 更新\r
+void SmSaveKeyPairDlgUpdate(HWND hWnd, SM_SAVE_KEY_PAIR *s)\r
+{\r
+       SECURE_DEVICE *dev;\r
+       bool ok = true;\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       dev = GetSecureDevice(SmGetCurrentSecureIdFromReg());\r
+       if (dev == NULL)\r
+       {\r
+               UniStrCpy(tmp, sizeof(tmp), _UU("SEC_CURRENT_NO_DEVICE"));\r
+       }\r
+       else\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("SEC_CURRENT_DEVICE"), dev->DeviceName);\r
+       }\r
+\r
+       SetText(hWnd, S_INFO, tmp);\r
+\r
+       if (IsChecked(hWnd, R_USE_PASS))\r
+       {\r
+               char *s1, *s2;\r
+               s1 = GetTextA(hWnd, E_PASS1);\r
+               s2 = GetTextA(hWnd, E_PASS2);\r
+               if (StrCmp(s1, s2) != 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+               Free(s1);\r
+               Free(s2);\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_SECURE))\r
+       {\r
+               if (dev == NULL)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       SetEnable(hWnd, B_SELECT, IsChecked(hWnd, R_SECURE));\r
+       SetEnable(hWnd, B_SECURE_MANAGER, IsChecked(hWnd, R_SECURE));\r
+       SetEnable(hWnd, S_INFO, IsChecked(hWnd, R_SECURE));\r
+\r
+       SetEnable(hWnd, E_PASS1, IsChecked(hWnd, R_USE_PASS) && (IsChecked(hWnd, R_SECURE) == false));\r
+       SetEnable(hWnd, E_PASS2, IsChecked(hWnd, R_USE_PASS) && (IsChecked(hWnd, R_SECURE) == false));\r
+       SetEnable(hWnd, S_PASS1, IsChecked(hWnd, R_USE_PASS) && (IsChecked(hWnd, R_SECURE) == false));\r
+       SetEnable(hWnd, S_PASS2, IsChecked(hWnd, R_USE_PASS) && (IsChecked(hWnd, R_SECURE) == false));\r
+       SetEnable(hWnd, R_USE_PASS, (IsChecked(hWnd, R_SECURE) == false));\r
+       SetEnable(hWnd, S_PASS3, (IsChecked(hWnd, R_SECURE) == false));\r
+       SetEnable(hWnd, S_PASS4, (IsChecked(hWnd, R_SECURE) == false));\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// OK ボタン\r
+void SmSaveKeyPairDlgOnOk(HWND hWnd, SM_SAVE_KEY_PAIR *s)\r
+{\r
+       UINT pkcs12;\r
+       char pass[MAX_SIZE];\r
+       char *password;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pkcs12 = 0;\r
+\r
+       if (IsChecked(hWnd, R_PKCS12))\r
+       {\r
+               pkcs12 = 1;\r
+       }\r
+       else if (IsChecked(hWnd, R_SECURE))\r
+       {\r
+               pkcs12 = 2;\r
+       }\r
+       MsRegWriteInt(REG_CURRENT_USER, SM_REG_KEY, "SavePkcs12", pkcs12);\r
+\r
+       if (pkcs12 != 2)\r
+       {\r
+               GetTxtA(hWnd, E_PASS1, pass, sizeof(pass));\r
+\r
+               if (StrLen(pass) != 0)\r
+               {\r
+                       password = pass;\r
+               }\r
+               else\r
+               {\r
+                       password = NULL;\r
+               }\r
+\r
+               if (pkcs12 == false)\r
+               {\r
+                       // X509 と KEY に書き込む\r
+                       wchar_t *x509_name, *key_name;\r
+                       x509_name = SaveDlg(hWnd, _UU("DLG_CERT_FILES"), _UU("DLG_SAVE_CERT"), NULL, L".cer");\r
+                       if (x509_name == NULL)\r
+                       {\r
+                               // キャンセル\r
+                               return;\r
+                       }\r
+                       else\r
+                       {\r
+                               wchar_t default_key_name[MAX_SIZE];\r
+                               UniReplaceStrEx(default_key_name, sizeof(default_key_name), x509_name,\r
+                                       L".cer", L"", false);\r
+                               UniReplaceStrEx(default_key_name, sizeof(default_key_name), default_key_name,\r
+                                                               L".crt", L"", false);\r
+                               UniStrCat(default_key_name, sizeof(default_key_name), L".key");\r
+                               key_name = SaveDlg(hWnd, _UU("DLG_KEY_FILTER"), _UU("DLG_SAVE_KEY"),\r
+                                       default_key_name, L".key");\r
+                               if (key_name == NULL)\r
+                               {\r
+                                       // キャンセル\r
+                                       Free(x509_name);\r
+                                       return;\r
+                               }\r
+                               else\r
+                               {\r
+                                       bool ok = true;\r
+                                       char filename1[MAX_SIZE];\r
+                                       char filename2[MAX_SIZE];\r
+\r
+                                       UniToStr(filename1, sizeof(filename1), x509_name);\r
+                                       UniToStr(filename2, sizeof(filename2), key_name);\r
+\r
+                                       // 証明書の保存\r
+                                       if (XToFile(s->Cert, filename1, true) == false)\r
+                                       {\r
+                                               MsgBox(hWnd, MB_ICONSTOP, _UU("DLG_CERT_SAVE_ERROR"));\r
+                                               ok = false;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (KToFile(s->Key, filename2, true, password) == false)\r
+                                               {\r
+                                                       MsgBox(hWnd, MB_ICONSTOP, _UU("DLG_KEY_SAVE_ERROR"));\r
+                                                       ok = false;\r
+                                               }\r
+                                       }\r
+\r
+                                       if (ok)\r
+                                       {\r
+                                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("DLG_KEY_PAIR_SAVE_OK"));\r
+                                               EndDialog(hWnd, true);\r
+                                       }\r
+\r
+                                       Free(key_name);\r
+                               }\r
+                               Free(x509_name);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // PKCS#12 に書き込む\r
+                       wchar_t *name = SaveDlg(hWnd, _UU("DLG_PKCS12_FILTER"), _UU("DLG_SAVE_P12"), NULL, L".p12");\r
+                       if (name == NULL)\r
+                       {\r
+                               // キャンセル\r
+                               return;\r
+                       }\r
+                       else\r
+                       {\r
+                               P12 *p12;\r
+                               char filename[MAX_SIZE];\r
+                               UniToStr(filename, sizeof(filename), name);\r
+\r
+                               // PKCS#12 に変換\r
+                               p12 = NewP12(s->Cert, s->Key, pass);\r
+                               if (p12 == NULL)\r
+                               {\r
+                                       // 失敗\r
+                                       MsgBox(hWnd, MB_ICONSTOP, _UU("DLG_KEY_PAIR_SAVE_OK"));\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 保存\r
+                                       if (P12ToFile(p12, filename) == false)\r
+                                       {\r
+                                               // 失敗\r
+                                               MsgBox(hWnd, MB_ICONSTOP, _UU("DLG_KEY_PAIR_SAVE_OK"));\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // 成功\r
+                                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("DLG_KEY_PAIR_SAVE_OK"));\r
+                                               EndDialog(hWnd, true);\r
+                                       }\r
+                                       FreeP12(p12);\r
+                               }\r
+\r
+                               Free(name);\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               char default_name[MAX_SIZE];\r
+               char *object_name;\r
+               bool ok = false;\r
+               X *x;\r
+               K *k;\r
+               WINUI_SECURE_BATCH batch[] =\r
+               {\r
+                       {WINUI_SECURE_WRITE_CERT, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL},\r
+                       {WINUI_SECURE_WRITE_KEY, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL},\r
+               };\r
+\r
+               x = s->Cert;\r
+               k = s->Key;\r
+\r
+               // デフォルトの名前を生成する\r
+               GetPrintNameFromXA(default_name, sizeof(default_name), x);\r
+               ConvertSafeFileName(default_name, sizeof(default_name), default_name);\r
+\r
+               object_name = StringDlgA(hWnd, _UU("SEC_OBJECT_NAME_TITLE"),\r
+                       _UU("SEC_OBJECT_NAME_INFO"), default_name, ICO_CERT, false, false);\r
+\r
+               if (object_name != NULL)\r
+               {\r
+                       // 書き込みと列挙\r
+                       batch[0].InputX = x;\r
+                       batch[0].Name = object_name;\r
+                       batch[1].InputK = k;\r
+                       batch[1].Name = object_name;\r
+\r
+                       if (SecureDeviceWindow(hWnd, batch, sizeof(batch) / sizeof(batch[0]), SmGetCurrentSecureIdFromReg(), 0) == false)\r
+                       {\r
+                               // 失敗\r
+                       }\r
+                       else\r
+                       {\r
+                               ok = true;\r
+                       }\r
+\r
+                       Free(object_name);\r
+               }\r
+\r
+               if (ok)\r
+               {\r
+                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("SEC_NEW_CERT_IMPORT_OK"));\r
+\r
+                       EndDialog(hWnd, true);\r
+               }\r
+       }\r
+}\r
+\r
+// 証明書と秘密鍵の保存ダイアログ\r
+UINT SmSaveKeyPairDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SAVE_KEY_PAIR *s = (SM_SAVE_KEY_PAIR *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmSaveKeyPairDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_PASS1:\r
+               case E_PASS2:\r
+               case R_USE_PASS:\r
+               case R_SECURE:\r
+               case R_X509_AND_KEY:\r
+               case R_PKCS12:\r
+                       SmSaveKeyPairDlgUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // OK ボタン\r
+                       SmSaveKeyPairDlgOnOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case R_USE_PASS:\r
+                       if (IsChecked(hWnd, R_USE_PASS))\r
+                       {\r
+                               FocusEx(hWnd, E_PASS1);\r
+                       }\r
+                       break;\r
+\r
+               case B_SELECT:\r
+                       SmSelectSecureId(hWnd);\r
+                       SmSaveKeyPairDlgUpdate(hWnd, s);\r
+                       break;\r
+\r
+               case B_SECURE_MANAGER:\r
+                       CmSecureManagerEx(hWnd, SmGetCurrentSecureId(hWnd), true);\r
+                       SmSaveKeyPairDlgUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 証明書と秘密鍵を保存する\r
+bool SmSaveKeyPairDlg(HWND hWnd, X *x, K *k)\r
+{\r
+       SM_SAVE_KEY_PAIR s;\r
+       // 引数チェック\r
+       if (hWnd == NULL || x == NULL || k == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&s, sizeof(s));\r
+       s.Cert = x;\r
+       s.Key = k;\r
+\r
+       return Dialog(hWnd,     D_SM_SAVE_KEY_PAIR, SmSaveKeyPairDlgProc, &s);\r
+}\r
+\r
+// SSL 関係ダイアログで OK がクリックされた\r
+void SmSslDlgOnOk(HWND hWnd, SM_SSL *s)\r
+{\r
+       char *name;\r
+       RPC_KEEP t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->p->ServerAdminMode == false)\r
+       {\r
+               EndDialog(hWnd, false);\r
+               return;\r
+       }\r
+\r
+       name = GetTextA(hWnd, C_CIPHER);\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+       else\r
+       {\r
+               RPC_STR t;\r
+               Zero(&t, sizeof(t));\r
+               t.String = name;\r
+\r
+               // 暗号化アルゴリズムの設定\r
+               if (CALL(hWnd, ScSetServerCipher(s->p->Rpc, &t)) == false)\r
+               {\r
+                       Focus(hWnd, C_CIPHER);\r
+                       return;\r
+               }\r
+               FreeRpcStr(&t);\r
+       }\r
+\r
+       if (s->SetCertAndKey)\r
+       {\r
+               // 証明書のセット\r
+               RPC_KEY_PAIR t;\r
+               Zero(&t, sizeof(t));\r
+\r
+               t.Cert = CloneX(s->Cert);\r
+               t.Key = CloneK(s->Key);\r
+\r
+               if (CALL(hWnd, ScSetServerCert(s->p->Rpc, &t)) == false)\r
+               {\r
+                       return;\r
+               }\r
+               FreeRpcKeyPair(&t);\r
+\r
+               MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_CERT_SET_MSG"));\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.UseKeepConnect = IsChecked(hWnd, R_USE_KEEP_CONNECT);\r
+       GetTxtA(hWnd, E_HOSTNAME, t.KeepConnectHost, sizeof(t.KeepConnectHost));\r
+       t.KeepConnectPort = GetInt(hWnd, E_PORT);\r
+       t.KeepConnectInterval = GetInt(hWnd, E_INTERVAL);\r
+       t.KeepConnectProtocol = IsChecked(hWnd, R_UDP) ? 1 : 0;\r
+\r
+       CALL(hWnd, ScSetKeep(s->p->Rpc, &t));\r
+\r
+       if (GetCapsBool(s->p->CapsList, "b_support_syslog"))\r
+       {\r
+               if (s->p->ServerAdminMode)\r
+               {\r
+                       SYSLOG_SETTING set;\r
+\r
+                       Zero(&set, sizeof(set));\r
+                       GetTxtA(hWnd, E_SYSLOG_HOSTNAME, set.Hostname, sizeof(set.Hostname));\r
+                       set.Port = GetInt(hWnd, E_SYSLOG_PORT);\r
+                       set.SaveType = CbGetSelect(hWnd, C_SYSLOG);\r
+\r
+                       if (CALL(hWnd, ScSetSysLog(s->p->Rpc, &set)) == false)\r
+                       {\r
+                               return;\r
+                       }\r
+               }\r
+       }\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// SSL 関係ダイアログ初期化\r
+void SmSslDlgInit(HWND hWnd, SM_SSL *s)\r
+{\r
+       UINT i;\r
+       TOKEN_LIST *cipher_list;\r
+       RPC_KEEP t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 暗号化アルゴリズム一覧を設定する\r
+       cipher_list = GetCipherList();\r
+       CbSetHeight(hWnd, C_CIPHER, 18);\r
+       for (i = 0;i < cipher_list->NumTokens;i++)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               char *name = cipher_list->Token[i];\r
+               StrToUni(tmp, sizeof(tmp), name);\r
+               CbAddStr(hWnd, C_CIPHER, tmp, 0);\r
+       }\r
+\r
+       if (s->p != NULL)\r
+       {\r
+               // サーバーから暗号化アルゴリズム名を取得する\r
+               RPC_STR t;\r
+               Zero(&t, sizeof(t));\r
+               if (CALL(hWnd, ScGetServerCipher(s->p->Rpc, &t)))\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       StrToUni(tmp, sizeof(tmp), t.String);\r
+                       SetText(hWnd, C_CIPHER, tmp);\r
+                       FreeRpcStr(&t);\r
+               }\r
+               else\r
+               {\r
+                       EndDialog(hWnd, 0);\r
+                       return;\r
+               }\r
+       }\r
+\r
+       if (s->p != NULL)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               // サーバーから SSL 証明書と秘密鍵を取得する\r
+               RPC_KEY_PAIR t;\r
+               s->SetCertAndKey = false;\r
+               Zero(&t, sizeof(t));\r
+               if (CALL(hWnd, ScGetServerCert(s->p->Rpc, &t)))\r
+               {\r
+                       // 証明書と鍵のコピー\r
+                       s->Cert = CloneX(t.Cert);\r
+                       s->Key = CloneK(t.Key);\r
+                       FreeRpcKeyPair(&t);\r
+               }\r
+               else\r
+               {\r
+                       EndDialog(hWnd, 0);\r
+                       return;\r
+               }\r
+\r
+               // 証明書情報の表示\r
+               SmGetCertInfoStr(tmp, sizeof(tmp), s->Cert);\r
+               SetText(hWnd, S_CERT_INFO, tmp);\r
+       }\r
+\r
+       // パスワード変更\r
+       SetEnable(hWnd, B_PASSWORD, s->p->ServerAdminMode);\r
+\r
+       // ボタンの有効化 / 無効化\r
+       SetEnable(hWnd, B_IMPORT, s->p->ServerAdminMode);\r
+       SetEnable(hWnd, B_EXPORT, s->p->ServerAdminMode);\r
+       SetEnable(hWnd, R_USE_KEEP_CONNECT, s->p->ServerAdminMode);\r
+\r
+       if (s->p->ServerAdminMode == false)\r
+       {\r
+               Disable(hWnd, C_CIPHER);\r
+       }\r
+\r
+       if (CALL(hWnd, ScGetKeep(s->p->Rpc, &t)))\r
+       {\r
+               Check(hWnd, R_USE_KEEP_CONNECT, t.UseKeepConnect);\r
+               SetTextA(hWnd, E_HOSTNAME, t.KeepConnectHost);\r
+               SetIntEx(hWnd, E_PORT, t.KeepConnectPort);\r
+               SetInt(hWnd, E_INTERVAL, t.KeepConnectInterval);\r
+               Check(hWnd, R_TCP, t.KeepConnectProtocol == 0);\r
+               Check(hWnd, R_UDP, t.KeepConnectProtocol != 0);\r
+       }\r
+\r
+       CbSetHeight(hWnd, C_SYSLOG, 18);\r
+       CbReset(hWnd, C_SYSLOG);\r
+       CbAddStr(hWnd, C_SYSLOG, _UU("SM_SYSLOG_0"), SYSLOG_NONE);\r
+       CbAddStr(hWnd, C_SYSLOG, _UU("SM_SYSLOG_1"), SYSLOG_SERVER_LOG);\r
+       CbAddStr(hWnd, C_SYSLOG, _UU("SM_SYSLOG_2"), SYSLOG_SERVER_AND_HUB_SECURITY_LOG);\r
+       CbAddStr(hWnd, C_SYSLOG, _UU("SM_SYSLOG_3"), SYSLOG_SERVER_AND_HUB_ALL_LOG);\r
+\r
+       if (GetCapsBool(s->p->CapsList, "b_support_syslog"))\r
+       {\r
+               SYSLOG_SETTING set;\r
+\r
+               SetEnable(hWnd, C_SYSLOG, s->p->ServerAdminMode);\r
+               SetEnable(hWnd, E_SYSLOG_HOSTNAME, s->p->ServerAdminMode);\r
+               SetEnable(hWnd, E_SYSLOG_PORT, s->p->ServerAdminMode);\r
+               SetEnable(hWnd, S_01, s->p->ServerAdminMode);\r
+               SetEnable(hWnd, S_02, s->p->ServerAdminMode);\r
+\r
+               Zero(&set, sizeof(set));\r
+\r
+               if (CALL(hWnd, ScGetSysLog(s->p->Rpc, &set)))\r
+               {\r
+                       SetTextA(hWnd, E_SYSLOG_HOSTNAME, set.Hostname);\r
+                       SetInt(hWnd, E_SYSLOG_PORT, set.Port == 0 ? SYSLOG_PORT : set.Port);\r
+                       CbSelect(hWnd, C_SYSLOG, set.SaveType);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               Disable(hWnd, C_SYSLOG);\r
+               Disable(hWnd, E_SYSLOG_HOSTNAME);\r
+               Disable(hWnd, E_SYSLOG_PORT);\r
+               Disable(hWnd, S_01);\r
+               Disable(hWnd, S_02);\r
+       }\r
+\r
+       SmSslDlgUpdate(hWnd, s);\r
+}\r
+\r
+// SSL 関係ダイアログコントロール更新\r
+void SmSslDlgUpdate(HWND hWnd, SM_SSL *s)\r
+{\r
+       bool ok = true;\r
+       bool b;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_USE_KEEP_CONNECT))\r
+       {\r
+               UINT i;\r
+               b = true;\r
+               if (IsEmpty(hWnd, E_HOSTNAME))\r
+               {\r
+                       ok = false;\r
+               }\r
+               i = GetInt(hWnd, E_PORT);\r
+               if (i == 0 || i >= 65536)\r
+               {\r
+                       ok = false;\r
+               }\r
+               i = GetInt(hWnd, E_INTERVAL);\r
+               if (i < 5 || i > 600)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       if (IsEnable(hWnd, C_SYSLOG))\r
+       {\r
+               UINT i = CbGetSelect(hWnd, C_SYSLOG);\r
+\r
+               SetEnable(hWnd, E_SYSLOG_HOSTNAME, i != SYSLOG_NONE);\r
+               SetEnable(hWnd, E_SYSLOG_PORT, i != SYSLOG_NONE);\r
+               SetEnable(hWnd, S_01, i != SYSLOG_NONE);\r
+               SetEnable(hWnd, S_02, i != SYSLOG_NONE);\r
+       }\r
+\r
+       SetEnable(hWnd, S_HOSTNAME, b);\r
+       SetEnable(hWnd, E_HOSTNAME, b);\r
+       SetEnable(hWnd, S_PORT, b);\r
+       SetEnable(hWnd, E_PORT, b);\r
+       SetEnable(hWnd, S_INTERVAL, b);\r
+       SetEnable(hWnd, E_INTERVAL, b);\r
+       SetEnable(hWnd, S_INTERVAL2, b);\r
+       SetEnable(hWnd, S_PROTOCOL, b);\r
+       SetEnable(hWnd, R_TCP, b);\r
+       SetEnable(hWnd, R_UDP, b);\r
+       SetEnable(hWnd, S_INFO, b);\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// 証明書情報文字列の取得\r
+void SmGetCertInfoStr(wchar_t *str, UINT size, X *x)\r
+{\r
+       wchar_t subject[MAX_SIZE];\r
+       wchar_t issuer[MAX_SIZE];\r
+       wchar_t date[MAX_SIZE];\r
+       // 引数チェック\r
+       if (x == NULL || str == NULL)\r
+       {\r
+               if (str != NULL)\r
+               {\r
+                       str[0] = 0;\r
+               }\r
+               return;\r
+       }\r
+\r
+       GetPrintNameFromName(subject, sizeof(subject), x->subject_name);\r
+       GetPrintNameFromName(issuer, sizeof(issuer), x->issuer_name);\r
+       GetDateStrEx64(date, sizeof(date), x->notAfter, NULL);\r
+\r
+       UniFormat(str, size, _UU("CM_CERT_INFO"), subject, issuer, date);\r
+}\r
+\r
+// SSL 関係ダイアログプロシージャ\r
+UINT SmSslDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SSL *s = (SM_SSL *)param;\r
+       X *x;\r
+       K *k;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SmSslDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_USE_KEEP_CONNECT:\r
+               case E_HOSTNAME:\r
+               case E_PORT:\r
+               case E_INTERVAL:\r
+               case R_TCP:\r
+               case R_UDP:\r
+               case C_SYSLOG:\r
+               case E_SYSLOG_HOSTNAME:\r
+               case E_SYSLOG_PORT:\r
+                       SmSslDlgUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // OK ボタン\r
+                       SmSslDlgOnOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_IMPORT:\r
+                       // インポート\r
+                       if (CmLoadXAndK(hWnd, &x, &k))\r
+                       {\r
+                               wchar_t tmp[MAX_SIZE];\r
+                               FreeX(s->Cert);\r
+                               FreeK(s->Key);\r
+                               s->Cert = x;\r
+                               s->Key = k;\r
+                               s->SetCertAndKey = true;\r
+                               // 証明書情報の表示\r
+                               SmGetCertInfoStr(tmp, sizeof(tmp), s->Cert);\r
+                               SetText(hWnd, S_CERT_INFO, tmp);\r
+                       }\r
+                       break;\r
+\r
+               case B_EXPORT:\r
+                       // エクスポート\r
+                       SmSaveKeyPairDlg(hWnd, s->Cert, s->Key);\r
+                       break;\r
+\r
+               case B_VIEW:\r
+                       // 証明書の表示\r
+                       CertDlg(hWnd, s->Cert, NULL, true);\r
+                       break;\r
+\r
+               case B_PASSWORD:\r
+                       // パスワード変更\r
+                       Dialog(hWnd, D_SM_CHANGE_PASSWORD, SmChangeServerPasswordDlg, s->p);\r
+                       break;\r
+\r
+               case R_USE_KEEP_CONNECT:\r
+                       if (IsChecked(hWnd, R_USE_KEEP_CONNECT))\r
+                       {\r
+                               FocusEx(hWnd, E_HOSTNAME);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// SSL 関係ダイアログの表示\r
+void SmSslDlg(HWND hWnd, SM_SERVER *p)\r
+{\r
+       SM_SSL s;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&s, sizeof(s));\r
+       s.p = p;\r
+\r
+       Dialog(hWnd, D_SM_SSL, SmSslDlgProc, &s);\r
+\r
+       // クリーンアップ\r
+       FreeX(s.Cert);\r
+       FreeK(s.Key);\r
+}\r
+\r
+// リスナー作成ダイアログプロシージャ\r
+UINT SmCreateListenerDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       UINT port;\r
+       RPC_LISTENER t;\r
+       SM_SERVER *p = (SM_SERVER *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               Focus(hWnd, E_PORT);\r
+               Disable(hWnd, IDOK);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_PORT:\r
+                       port = GetInt(hWnd, E_PORT);\r
+                       if (port == 0 || port >= 65536)\r
+                       {\r
+                               Disable(hWnd, IDOK);\r
+                       }\r
+                       else\r
+                       {\r
+                               Enable(hWnd, IDOK);\r
+                       }\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       port = GetInt(hWnd, E_PORT);\r
+                       Zero(&t, sizeof(t));\r
+                       t.Enable = true;\r
+                       t.Port = port;\r
+                       if (CALL(hWnd, ScCreateListener(p->Rpc, &t)))\r
+                       {\r
+                               EndDialog(hWnd, true);\r
+                       }\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// リスナー作成ダイアログ\r
+bool SmCreateListenerDlg(HWND hWnd, SM_SERVER *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return Dialog(hWnd, D_SM_CREATE_LISTENER, SmCreateListenerDlgProc, p);\r
+}\r
+\r
+// HUB 編集 OK ボタン\r
+void SmEditHubOnOk(HWND hWnd, SM_EDIT_HUB *s)\r
+{\r
+       RPC_CREATE_HUB t;\r
+       char pass1[MAX_SIZE];\r
+       char pass2[MAX_SIZE];\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       if (s->EditMode)\r
+       {\r
+               StrCpy(hubname, sizeof(hubname), s->HubName);\r
+               StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+       }\r
+       else\r
+       {\r
+               GetTxtA(hWnd, E_HUBNAME, t.HubName, sizeof(t.HubName));\r
+               StrCpy(hubname, sizeof(hubname), t.HubName);\r
+       }\r
+\r
+       GetTxtA(hWnd, E_PASSWORD1, pass1, sizeof(pass1));\r
+       GetTxtA(hWnd, E_PASSWORD2, pass2, sizeof(pass2));\r
+\r
+       if (s->EditMode == false || StrCmp(pass1, HIDDEN_PASSWORD) != 0)\r
+       {\r
+               Hash(t.HashedPassword, pass1, StrLen(pass1), true);\r
+               HashPassword(t.SecurePassword, ADMINISTRATOR_USERNAME, pass1);\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_LIMIT_MAX_SESSION))\r
+       {\r
+               t.HubOption.MaxSession = GetInt(hWnd, E_MAX_SESSION);\r
+       }\r
+\r
+       t.Online = IsChecked(hWnd, R_ONLINE);\r
+\r
+       if (s->p->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               t.HubType = HUB_TYPE_FARM_STATIC;\r
+               if (IsChecked(hWnd, R_DYNAMIC))\r
+               {\r
+                       t.HubType = HUB_TYPE_FARM_DYNAMIC;\r
+               }\r
+       }\r
+\r
+       t.HubOption.NoEnum = IsChecked(hWnd, R_NO_ENUM);\r
+\r
+       if (s->EditMode == false)\r
+       {\r
+               if (CALL(hWnd, ScCreateHub(s->p->Rpc, &t)))\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONINFORMATION, _UU("CM_EDIT_HUB_CREATER"), hubname);\r
+                       EndDialog(hWnd, true);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (CALL(hWnd, ScSetHub(s->p->Rpc, &t)))\r
+               {\r
+                       EndDialog(hWnd, true);\r
+               }\r
+       }\r
+}\r
+\r
+// HUB 編集更新\r
+void SmEditHubUpdate(HWND hWnd, SM_EDIT_HUB *s)\r
+{\r
+       bool ok = true;\r
+       char *s1, *s2;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s1 = GetTextA(hWnd, E_PASSWORD1);\r
+       s2 = GetTextA(hWnd, E_PASSWORD2);\r
+       if (StrCmp(s1, s2) != 0)\r
+       {\r
+               ok = false;\r
+       }\r
+       Free(s1);\r
+       Free(s2);\r
+\r
+       GetTxtA(hWnd, E_HUBNAME, hubname, sizeof(hubname));\r
+       Trim(hubname);\r
+       if (StrLen(hubname) == 0 ||\r
+               IsSafeStr(hubname) == false)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_LIMIT_MAX_SESSION))\r
+       {\r
+               Enable(hWnd, E_MAX_SESSION);\r
+               Enable(hWnd, S_MAX_SESSION_1);\r
+               Enable(hWnd, S_MAX_SESSION_2);\r
+               if (GetInt(hWnd, E_MAX_SESSION) == 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               Disable(hWnd, E_MAX_SESSION);\r
+               Disable(hWnd, S_MAX_SESSION_1);\r
+               Disable(hWnd, S_MAX_SESSION_2);\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// HUB 編集初期化\r
+void SmEditHubInit(HWND hWnd, SM_EDIT_HUB *s)\r
+{\r
+       RPC_CREATE_HUB t;\r
+       bool b = false;\r
+       bool support_extoption = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_HUB);\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       if (s->EditMode == false)\r
+       {\r
+               // 新規作成\r
+               SetText(hWnd, 0, _UU("CM_EDIT_HUB_1"));\r
+               FocusEx(hWnd, E_HUBNAME);\r
+\r
+               if (s->p->ServerType == SERVER_TYPE_STANDALONE)\r
+               {\r
+                       // スタンドアロン モード\r
+                       Disable(hWnd, R_STATIC);\r
+                       Disable(hWnd, R_DYNAMIC);\r
+                       SetText(hWnd, S_FARM_INFO, _UU("CM_EDIT_HUB_STANDALONE"));\r
+               }\r
+               else\r
+               {\r
+                       Check(hWnd, R_STATIC, true);\r
+               }\r
+\r
+               Check(hWnd, R_ONLINE, true);\r
+\r
+               Hide(hWnd, B_ACL);\r
+               Hide(hWnd, S_ACL);\r
+               Hide(hWnd, S_ACL_2);\r
+               Hide(hWnd, S_ACL_3);\r
+               Hide(hWnd, S_MSG_1);\r
+               Hide(hWnd, S_MSG_4);\r
+               Hide(hWnd, S_MSG_2);\r
+               Hide(hWnd, B_MSG);\r
+       }\r
+       else\r
+       {\r
+               // 編集\r
+               wchar_t tmp[MAX_SIZE];\r
+               UniFormat(tmp, sizeof(tmp), _UU("CM_EDIT_HUB_2"), s->HubName);\r
+               SetText(hWnd, 0, tmp);\r
+               SetTextA(hWnd, E_HUBNAME, s->HubName);\r
+               Disable(hWnd, E_HUBNAME);\r
+\r
+               if (s->p->ServerType == SERVER_TYPE_STANDALONE)\r
+               {\r
+                       // スタンドアロン モード\r
+                       Disable(hWnd, R_STATIC);\r
+                       Disable(hWnd, R_DYNAMIC);\r
+                       SetText(hWnd, S_FARM_INFO, _UU("CM_EDIT_HUB_STANDALONE"));\r
+               }\r
+\r
+               if (s->p->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+               {\r
+                       // コントローラ\r
+                       if (GetCapsBool(s->p->CapsList, "b_cluster_hub_type_fixed"))\r
+                       {\r
+                               Disable(hWnd, R_STATIC);\r
+                               Disable(hWnd, R_DYNAMIC);\r
+                               SetText(hWnd, S_FARM_INFO, _UU("CM_EDIT_HUB_TYPE_FIXED"));\r
+                       }\r
+               }\r
+\r
+               // HUB 情報の取得\r
+               StrCpy(t.HubName, sizeof(t.HubName), s->HubName);\r
+               if (CALL(hWnd, ScGetHub(s->p->Rpc, &t)) == false)\r
+               {\r
+                       EndDialog(hWnd, false);\r
+                       return;\r
+               }\r
+\r
+               SetTextA(hWnd, E_PASSWORD1, HIDDEN_PASSWORD);\r
+               SetTextA(hWnd, E_PASSWORD2, HIDDEN_PASSWORD);\r
+\r
+               if (t.HubOption.MaxSession == 0)\r
+               {\r
+                       Check(hWnd, R_LIMIT_MAX_SESSION, false);\r
+               }\r
+               else\r
+               {\r
+                       Check(hWnd, R_LIMIT_MAX_SESSION, true);\r
+               }\r
+\r
+               Check(hWnd, R_NO_ENUM, t.HubOption.NoEnum);\r
+\r
+               SetIntEx(hWnd, E_MAX_SESSION, t.HubOption.MaxSession);\r
+\r
+               Check(hWnd, R_ONLINE, t.Online);\r
+               Check(hWnd, R_OFFLINE, t.Online ? false : true);\r
+\r
+               Check(hWnd, R_STATIC, t.HubType == HUB_TYPE_FARM_STATIC);\r
+               Check(hWnd, R_DYNAMIC, t.HubType == HUB_TYPE_FARM_DYNAMIC);\r
+\r
+               SetShow(hWnd, B_ACL, GetCapsBool(s->p->CapsList, "b_support_ac"));\r
+               SetShow(hWnd, S_ACL, GetCapsBool(s->p->CapsList, "b_support_ac"));\r
+               SetShow(hWnd, S_ACL_2, GetCapsBool(s->p->CapsList, "b_support_ac"));\r
+               SetShow(hWnd, S_ACL_3, GetCapsBool(s->p->CapsList, "b_support_ac"));\r
+\r
+               SetShow(hWnd, S_MSG_1, GetCapsBool(s->p->CapsList, "b_support_msg"));\r
+               SetShow(hWnd, S_MSG_4, GetCapsBool(s->p->CapsList, "b_support_msg"));\r
+               SetShow(hWnd, S_MSG_2, GetCapsBool(s->p->CapsList, "b_support_msg"));\r
+               SetShow(hWnd, B_MSG, GetCapsBool(s->p->CapsList, "b_support_msg"));\r
+       }\r
+\r
+       // 拡張オプション\r
+       if (s->EditMode)\r
+       {\r
+               support_extoption = GetCapsBool(s->p->CapsList, "b_support_hub_ext_options");\r
+       }\r
+\r
+       SetEnable(hWnd, S_STATIC, support_extoption);\r
+       SetEnable(hWnd, B_EXTOPTION, support_extoption);\r
+\r
+       SetEnable(hWnd, R_NO_ENUM, GetCapsBool(s->p->CapsList, "b_support_hide_hub"));\r
+\r
+       SmEditHubUpdate(hWnd, s);\r
+\r
+       if (s->EditMode)\r
+       {\r
+               Focus(hWnd, IDOK);\r
+       }\r
+\r
+       if (s->EditMode)\r
+       {\r
+               if (GetCapsBool(s->p->CapsList, "b_support_hub_admin_option"))\r
+               {\r
+                       b = true;\r
+               }\r
+       }\r
+\r
+       SetShow(hWnd, S_AO_1, b);\r
+       SetShow(hWnd, S_AO_2, b);\r
+       SetShow(hWnd, S_AO_3, b);\r
+       SetShow(hWnd, B_ADMINOPTION, b);\r
+}\r
+\r
+// HUB 編集プロシージャ\r
+UINT SmEditHubProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_EDIT_HUB *s = (SM_EDIT_HUB *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmEditHubInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_PASSWORD1:\r
+               case E_PASSWORD2:\r
+               case E_HUBNAME:\r
+               case R_LIMIT_MAX_SESSION:\r
+               case E_MAX_SESSION:\r
+                       SmEditHubUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       SmEditHubOnOk(hWnd, s);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case R_LIMIT_MAX_SESSION:\r
+                       if (IsChecked(hWnd, R_LIMIT_MAX_SESSION))\r
+                       {\r
+                               FocusEx(hWnd, E_MAX_SESSION);\r
+                       }\r
+                       break;\r
+\r
+               case B_ADMINOPTION:\r
+                       SmHubAdminOption(hWnd, s);\r
+                       break;\r
+\r
+               case B_EXTOPTION:\r
+                       SmHubExtOption(hWnd, s);\r
+                       break;\r
+\r
+               case B_ACL:\r
+                       SmHubAc(hWnd, s);\r
+                       break;\r
+\r
+               case B_MSG:\r
+                       SmHubMsg(hWnd, s);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// HUB 編集ダイアログ\r
+bool SmEditHubDlg(HWND hWnd, SM_SERVER *p, char *hubname)\r
+{\r
+       SM_EDIT_HUB s;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&s, sizeof(s));\r
+       s.p = p;\r
+       s.EditMode = true;\r
+       StrCpy(s.HubName, sizeof(s.HubName), hubname);\r
+\r
+       if (p->Bridge == false)\r
+       {\r
+               return Dialog(hWnd, D_SM_EDIT_HUB, SmEditHubProc, &s);\r
+       }\r
+       else\r
+       {\r
+               SmHubExtOption(hWnd, &s);\r
+               return false;\r
+       }\r
+}\r
+\r
+// HUB 作成ダイアログ\r
+bool SmCreateHubDlg(HWND hWnd, SM_SERVER *p)\r
+{\r
+       SM_EDIT_HUB s;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&s, sizeof(s));\r
+       s.p = p;\r
+       s.EditMode = false;\r
+\r
+       return Dialog(hWnd, D_SM_EDIT_HUB, SmEditHubProc, &s);\r
+}\r
+\r
+// 仮想 HUB 状態の表示\r
+bool SmRefreshHubStatus(HWND hWnd, SM_SERVER *p, void *param)\r
+{\r
+       RPC_HUB_STATUS t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL || param == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(RPC_HUB_STATUS));\r
+       StrCpy(t.HubName, sizeof(t.HubName), (char *)param);\r
+       if (CALL(hWnd, ScGetHubStatus(p->Rpc, &t)))\r
+       {\r
+               wchar_t *s;\r
+               wchar_t tmp[MAX_SIZE];\r
+               LVB *b = LvInsertStart();\r
+\r
+               // HUB 名\r
+               s = CopyStrToUni((char *)param);\r
+               LvInsertAdd(b, ICO_HUB, 0, 2, _UU("SM_HUB_STATUS_HUBNAME"), s);\r
+               Free(s);\r
+\r
+               // オンライン\r
+               LvInsertAdd(b, t.Online ? ICO_PROTOCOL : ICO_PROTOCOL_X, 0, 2, _UU("SM_HUB_STATUS_ONLINE"),\r
+                       t.Online ? _UU("SM_HUB_ONLINE") : _UU("SM_HUB_OFFLINE"));\r
+\r
+               // HUB の種類\r
+               LvInsertAdd(b, t.HubType == HUB_TYPE_STANDALONE ? ICO_TOWER : ICO_FARM, 0, 2, _UU("SM_HUB_TYPE"),\r
+                       GetHubTypeStr(t.HubType));\r
+\r
+               if (t.HubType == HUB_TYPE_STANDALONE)\r
+               {\r
+                       // SecureNAT の有効/無効\r
+                       LvInsertAdd(b, ICO_ROUTER, NULL, 2, _UU("SM_HUB_SECURE_NAT"),\r
+                               t.SecureNATEnabled ? _UU("SM_HUB_SECURE_NAT_YES") : _UU("SM_HUB_SECURE_NAT_NO"));\r
+               }\r
+\r
+               // その他の値\r
+               UniToStru(tmp, t.NumSessions);\r
+               LvInsertAdd(b, ICO_PROTOCOL, 0, 2, _UU("SM_HUB_NUM_SESSIONS"), tmp);\r
+               if (t.NumSessionsClient != 0 || t.NumSessionsBridge != 0)\r
+               {\r
+                       UniToStru(tmp, t.NumSessionsClient);\r
+                       LvInsertAdd(b, ICO_PROTOCOL, 0, 2, _UU("SM_HUB_NUM_SESSIONS_CLIENT"), tmp);\r
+                       UniToStru(tmp, t.NumSessionsBridge);\r
+                       LvInsertAdd(b, ICO_PROTOCOL, 0, 2, _UU("SM_HUB_NUM_SESSIONS_BRIDGE"), tmp);\r
+               }\r
+\r
+               UniToStru(tmp, t.NumAccessLists);\r
+               LvInsertAdd(b, ICO_DISCARD, 0, 2, _UU("SM_HUB_NUM_ACCESSES"), tmp);\r
+\r
+               if (p->ServerType != SERVER_TYPE_FARM_MEMBER)\r
+               {\r
+                       UniToStru(tmp, t.NumUsers);\r
+                       LvInsertAdd(b, ICO_USER, 0, 2, _UU("SM_HUB_NUM_USERS"), tmp);\r
+                       UniToStru(tmp, t.NumGroups);\r
+                       LvInsertAdd(b, ICO_GROUP, 0, 2, _UU("SM_HUB_NUM_GROUPS"), tmp);\r
+               }\r
+\r
+               UniToStru(tmp, t.NumMacTables);\r
+               LvInsertAdd(b, ICO_MACHINE, 0, 2, _UU("SM_HUB_NUM_MAC_TABLES"), tmp);\r
+               UniToStru(tmp, t.NumIpTables);\r
+               LvInsertAdd(b, ICO_MACHINE, 0, 2, _UU("SM_HUB_NUM_IP_TABLES"), tmp);\r
+\r
+               // 利用状況\r
+               UniToStru(tmp, t.NumLogin);\r
+               LvInsertAdd(b, ICO_KEY, NULL, 2, _UU("SM_HUB_NUM_LOGIN"), tmp);\r
+\r
+               if (t.LastLoginTime != 0)\r
+               {\r
+                       GetDateTimeStr64Uni(tmp, sizeof(tmp), SystemToLocal64(t.LastLoginTime));\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("COMMON_UNKNOWN"));\r
+               }\r
+               LvInsertAdd(b, ICO_DATETIME, NULL, 2, _UU("SM_HUB_LAST_LOGIN_TIME"), tmp);\r
+\r
+               if (t.LastCommTime != 0)\r
+               {\r
+                       GetDateTimeStr64Uni(tmp, sizeof(tmp), SystemToLocal64(t.LastCommTime));\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("COMMON_UNKNOWN"));\r
+               }\r
+               LvInsertAdd(b, ICO_DATETIME, NULL, 2, _UU("SM_HUB_LAST_COMM_TIME"), tmp);\r
+\r
+               if (t.CreatedTime != 0)\r
+               {\r
+                       GetDateTimeStr64Uni(tmp, sizeof(tmp), SystemToLocal64(t.CreatedTime));\r
+               }\r
+               else\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("COMMON_UNKNOWN"));\r
+               }\r
+               LvInsertAdd(b, ICO_DATETIME, NULL, 2, _UU("SM_HUB_CREATED_TIME"), tmp);\r
+\r
+               // トラフィック情報\r
+               SmInsertTrafficInfo(b, &t.Traffic);\r
+\r
+               LvInsertEnd(b, hWnd, L_STATUS);\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// トラフィック情報を LVB に追加\r
+void SmInsertTrafficInfo(LVB *b, TRAFFIC *t)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       char vv[128];\r
+       // 引数チェック\r
+       if (b == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 送信情報\r
+       ToStr3(vv, sizeof(vv), t->Send.UnicastCount);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_NUM_PACKET_STR"), vv);\r
+       LvInsertAdd(b, ICO_INFORMATION, 0, 2, _UU("SM_ST_SEND_UCAST_NUM"), tmp);\r
+\r
+       ToStr3(vv, sizeof(vv), t->Send.UnicastBytes);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_SIZE_BYTE_STR"), vv);\r
+       LvInsertAdd(b, ICO_INFORMATION, 0, 2, _UU("SM_ST_SEND_UCAST_SIZE"), tmp);\r
+\r
+       ToStr3(vv, sizeof(vv), t->Send.BroadcastCount);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_NUM_PACKET_STR"), vv);\r
+       LvInsertAdd(b, ICO_INFORMATION, 0, 2, _UU("SM_ST_SEND_BCAST_NUM"), tmp);\r
+\r
+       ToStr3(vv, sizeof(vv), t->Send.BroadcastBytes);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_SIZE_BYTE_STR"), vv);\r
+       LvInsertAdd(b, ICO_INFORMATION, 0, 2, _UU("SM_ST_SEND_BCAST_SIZE"), tmp);\r
+\r
+       // 受信情報\r
+       ToStr3(vv, sizeof(vv), t->Recv.UnicastCount);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_NUM_PACKET_STR"), vv);\r
+       LvInsertAdd(b, ICO_INFORMATION, 0, 2, _UU("SM_ST_RECV_UCAST_NUM"), tmp);\r
+\r
+       ToStr3(vv, sizeof(vv), t->Recv.UnicastBytes);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_SIZE_BYTE_STR"), vv);\r
+       LvInsertAdd(b, ICO_INFORMATION, 0, 2, _UU("SM_ST_RECV_UCAST_SIZE"), tmp);\r
+\r
+       ToStr3(vv, sizeof(vv), t->Recv.BroadcastCount);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_NUM_PACKET_STR"), vv);\r
+       LvInsertAdd(b, ICO_INFORMATION, 0, 2, _UU("SM_ST_RECV_BCAST_NUM"), tmp);\r
+\r
+       ToStr3(vv, sizeof(vv), t->Recv.BroadcastBytes);\r
+       UniFormat(tmp, sizeof(tmp), _UU("SM_ST_SIZE_BYTE_STR"), vv);\r
+       LvInsertAdd(b, ICO_INFORMATION, 0, 2, _UU("SM_ST_RECV_BCAST_SIZE"), tmp);\r
+}\r
+\r
+// ステータス表示ダイアログプロシージャ\r
+UINT SmStatusDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_STATUS *s = (SM_STATUS *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               LvInitEx(hWnd, L_STATUS, s->NoImage);\r
+               LvSetStyle(hWnd, L_STATUS, LVS_EX_GRIDLINES);\r
+               SetIcon(hWnd, 0, s->Icon);\r
+               SetIcon(hWnd, S_ICON, s->Icon);\r
+               SetText(hWnd, 0, s->Caption);\r
+               SetText(hWnd, S_TITLE, s->Caption);\r
+               DlgFont(hWnd, S_TITLE, 15, true);\r
+               if (s->InitProc != NULL)\r
+               {\r
+                       s->InitProc(hWnd, s->p, s->Param);\r
+               }\r
+               else\r
+               {\r
+                       // カラム初期化\r
+                       LvInsertColumn(hWnd, L_STATUS, 0, _UU("SM_STATUS_COLUMN_1"), 0);\r
+                       LvInsertColumn(hWnd, L_STATUS, 1, _UU("SM_STATUS_COLUMN_2"), 0);\r
+               }\r
+               if (s->RefreshProc(hWnd, s->p, s->Param) == false)\r
+               {\r
+                       Close(hWnd);\r
+               }\r
+               LvAutoSize(hWnd, L_STATUS);\r
+               Focus(hWnd, L_STATUS);\r
+\r
+               if (s->show_refresh_button == false)\r
+               {\r
+                       Hide(hWnd, IDOK);\r
+               }\r
+\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // 更新\r
+                       if (s->RefreshProc(hWnd, s->p, s->Param) == false)\r
+                       {\r
+                               Close(hWnd);\r
+                       }\r
+                       LvAutoSize(hWnd, L_STATUS);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_STATUS);\r
+\r
+       return 0;\r
+}\r
+\r
+// ステータス表示ダイアログ\r
+void SmStatusDlg(HWND hWnd, SM_SERVER *p, void *param, bool no_image, bool show_refresh_button, wchar_t *caption, UINT icon,\r
+                                SM_STATUS_INIT_PROC *init, SM_STATUS_REFRESH_PROC *refresh)\r
+{\r
+       SM_STATUS s;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL || refresh == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (icon == 0)\r
+       {\r
+               icon = ICO_INFORMATION;\r
+       }\r
+       if (caption == NULL)\r
+       {\r
+               caption = _UU("SM_INFORMATION");\r
+       }\r
+\r
+       Zero(&s, sizeof(s));\r
+       s.show_refresh_button = show_refresh_button;\r
+       s.p = p;\r
+       s.NoImage = no_image;\r
+       s.Param = param;\r
+       s.Icon = icon;\r
+       s.Caption = caption;\r
+       s.InitProc = init;\r
+       s.RefreshProc = refresh;\r
+\r
+       Dialog(hWnd, D_SM_STATUS, SmStatusDlgProc, &s);\r
+}\r
+\r
+// サーバー管理ダイアログ更新\r
+void SmServerDlgUpdate(HWND hWnd, SM_SERVER *p)\r
+{\r
+       bool hub_selected = false;\r
+       bool hub_selected_online = false;\r
+       bool hub_selected_offline = false;\r
+       bool hub_have_admin_right = false;\r
+       bool listener_selected = false;\r
+       bool listener_selected_enabled = false;\r
+       bool listener_selected_disabled = false;\r
+       bool two_or_more_listener = false;\r
+       bool bridge;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       bridge = GetCapsBool(p->CapsList, "b_bridge");\r
+\r
+       hub_selected = LvIsSelected(hWnd, L_HUB);\r
+\r
+       if (hub_selected)\r
+       {\r
+               if (p->ServerAdminMode)\r
+               {\r
+                       hub_have_admin_right = true;\r
+               }\r
+               i = LvGetSelected(hWnd, L_HUB);\r
+               if (i != INFINITE)\r
+               {\r
+                       wchar_t *s = LvGetStr(hWnd, L_HUB, i, 1);\r
+                       if (p->ServerAdminMode == false)\r
+                       {\r
+                               char *hubname = LvGetStrA(hWnd, L_HUB, i, 0);\r
+                               if (hubname != NULL)\r
+                               {\r
+                                       if (StrCmpi(hubname, p->HubName) == 0)\r
+                                       {\r
+                                               hub_have_admin_right = true;\r
+                                       }\r
+                                       Free(hubname);\r
+                               }\r
+                       }\r
+                       hub_selected_online = (UniStrCmpi(s, _UU("SM_HUB_ONLINE")) == 0);\r
+                       hub_selected_offline = hub_selected_online ? false : true;\r
+                       Free(s);\r
+               }\r
+       }\r
+\r
+       listener_selected = LvIsSelected(hWnd, L_LISTENER);\r
+       if (listener_selected)\r
+       {\r
+               wchar_t *s = LvGetSelectedStr(hWnd, L_LISTENER, 1);\r
+               if (UniStrCmpi(s, _UU("CM_LISTENER_OFFLINE")) == 0)\r
+               {\r
+                       listener_selected_disabled = true;\r
+               }\r
+               else\r
+               {\r
+                       listener_selected_enabled = true;\r
+               }\r
+               Free(s);\r
+       }\r
+\r
+       if (LvNum(hWnd, L_LISTENER) >= 2)\r
+       {\r
+               two_or_more_listener = true;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, bridge || (hub_selected && hub_have_admin_right));\r
+       SetEnable(hWnd, B_ONLINE, bridge == false && hub_selected_offline && hub_have_admin_right && p->ServerType != SERVER_TYPE_FARM_MEMBER);\r
+       SetEnable(hWnd, B_OFFLINE, bridge == false && hub_selected_online && hub_have_admin_right && p->ServerType != SERVER_TYPE_FARM_MEMBER);\r
+       SetEnable(hWnd, B_HUB_STATUS, hub_selected && hub_have_admin_right);\r
+       SetEnable(hWnd, B_DELETE, bridge == false && hub_selected && p->ServerAdminMode && p->ServerType != SERVER_TYPE_FARM_MEMBER);\r
+       SetEnable(hWnd, B_EDIT, hub_selected && hub_have_admin_right && p->ServerType != SERVER_TYPE_FARM_MEMBER);\r
+       SetEnable(hWnd, B_CREATE, bridge == false && p->ServerAdminMode && p->ServerType != SERVER_TYPE_FARM_MEMBER);\r
+\r
+       SetEnable(hWnd, B_CREATE_LISTENER, p->ServerAdminMode);\r
+       SetEnable(hWnd, B_DELETE_LISTENER, p->ServerAdminMode && listener_selected && two_or_more_listener);\r
+       SetEnable(hWnd, B_START, p->ServerAdminMode && listener_selected_disabled);\r
+       SetEnable(hWnd, B_STOP, p->ServerAdminMode && listener_selected_enabled);\r
+       SetEnable(hWnd, B_FARM, GetCapsBool(p->CapsList, "b_support_cluster") && p->ServerAdminMode);\r
+       SetEnable(hWnd, B_FARM_STATUS, GetCapsBool(p->CapsList, "b_support_cluster") && p->ServerType != SERVER_TYPE_STANDALONE);\r
+}\r
+\r
+// サーバー管理ダイアログ初期化\r
+void SmServerDlgInit(HWND hWnd, SM_SERVER *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // カラム初期化\r
+       LvInit(hWnd, L_HUB);\r
+       LvSetStyle(hWnd, L_HUB, LVS_EX_GRIDLINES);\r
+       LvInsertColumn(hWnd, L_HUB, 0, _UU("SM_HUB_COLUMN_1"), 150);\r
+       LvInsertColumn(hWnd, L_HUB, 1, _UU("SM_HUB_COLUMN_2"), 80);\r
+       LvInsertColumn(hWnd, L_HUB, 2, _UU("SM_HUB_COLUMN_3"), 80);\r
+       LvInsertColumn(hWnd, L_HUB, 3, _UU("SM_HUB_COLUMN_4"), 80);\r
+       LvInsertColumn(hWnd, L_HUB, 4, _UU("SM_HUB_COLUMN_5"), 80);\r
+       LvInsertColumn(hWnd, L_HUB, 5, _UU("SM_HUB_COLUMN_6"), 80);\r
+       LvInsertColumn(hWnd, L_HUB, 6, _UU("SM_HUB_COLUMN_7"), 80);\r
+       LvInsertColumn(hWnd, L_HUB, 7, _UU("SM_HUB_COLUMN_8"), 80);\r
+       LvInsertColumn(hWnd, L_HUB, 8, _UU("SM_HUB_COLUMN_9"), 80);\r
+       LvInsertColumn(hWnd, L_HUB, 9, _UU("SM_HUB_COLUMN_10"), 120);\r
+       LvInsertColumn(hWnd, L_HUB, 10, _UU("SM_HUB_COLUMN_11"), 120);\r
+\r
+       LvInit(hWnd, L_LISTENER);\r
+       LvSetStyle(hWnd, L_LISTENER, LVS_EX_GRIDLINES);\r
+       LvInsertColumn(hWnd, L_LISTENER, 0, _UU("CM_LISTENER_COLUMN_1"), 90);\r
+       LvInsertColumn(hWnd, L_LISTENER, 1, _UU("CM_LISTENER_COLUMN_2"), 80);\r
+\r
+       SmServerDlgRefresh(hWnd, p);\r
+\r
+       if (p->ServerAdminMode == false)\r
+       {\r
+               // 仮想 HUB 管理モードの場合は唯一の HUB を選択する\r
+               wchar_t *s = CopyStrToUni(p->HubName);\r
+               LvSelect(hWnd, L_HUB, LvSearchStr(hWnd, L_HUB, 0, s));\r
+               Free(s);\r
+       }\r
+       else\r
+       {\r
+               // サーバー全体の管理モードの場合\r
+               UINT num_hubs = LvNum(hWnd, L_HUB);\r
+\r
+               if (num_hubs == 1)\r
+               {\r
+                       // 仮想 HUB が 1 個の場合は必ずその仮想 HUB を選択する\r
+                       LvSelect(hWnd, L_HUB, 0);\r
+               }\r
+               else\r
+               {\r
+                       // 仮想 HUB が複数個ある場合は前回最後に選択した仮想 HUB を選択する\r
+                       char tmp[MAX_SIZE];\r
+                       char *hubname;\r
+\r
+                       Format(tmp, sizeof(tmp), "%s:%u:%s", p->CurrentSetting->ClientOption.Hostname,\r
+                               p->CurrentSetting->ClientOption.Port,\r
+                               p->CurrentSetting->ServerAdminMode ? "" : p->CurrentSetting->HubName);\r
+\r
+                       hubname = MsRegReadStr(REG_CURRENT_USER, SM_LASTHUB_REG_KEY, tmp);\r
+\r
+                       if (IsEmptyStr(hubname) == false)\r
+                       {\r
+                               LvSelect(hWnd, L_HUB, LvSearchStrA(hWnd, L_HUB, 0, hubname));\r
+                       }\r
+\r
+                       Free(hubname);\r
+               }\r
+       }\r
+\r
+       Focus(hWnd, L_HUB);\r
+\r
+       SmServerDlgUpdate(hWnd, p);\r
+\r
+       if (GetCapsBool(p->CapsList, "b_bridge"))\r
+       {\r
+               Disable(hWnd, L_HUB);\r
+       }\r
+\r
+       // ローカルブリッジボタン等はサーバーの Admin の場合に有効にする\r
+       SetEnable(hWnd, B_BRIDGE, GetCapsBool(p->CapsList, "b_local_bridge") && p->ServerAdminMode);\r
+       SetEnable(hWnd, B_CONNECTION, p->ServerAdminMode);\r
+\r
+       // Config R/W ボタン\r
+       SetEnable(hWnd, B_CONFIG, GetCapsBool(p->CapsList, "b_support_config_rw") && p->ServerAdminMode);\r
+\r
+       // レイヤ 3 ボタン\r
+       SetEnable(hWnd, B_L3, GetCapsBool(p->CapsList, "b_support_layer3") && p->ServerAdminMode);\r
+\r
+       // ライセンスボタン\r
+       SetShow(hWnd, B_LICENSE, GetCapsBool(p->CapsList, "b_support_license") && p->ServerAdminMode);\r
+       SetShow(hWnd, S_LICENSE, GetCapsBool(p->CapsList, "b_support_license") && p->ServerAdminMode);\r
+       SetShow(hWnd, S_BETA, GetCapsBool(p->CapsList, "b_beta_version") && (IsShow(hWnd, B_LICENSE) == false));\r
+\r
+       DlgFont(hWnd, S_BETA, 12, false);\r
+}\r
+\r
+// サーバー管理ダイアログ更新\r
+void SmServerDlgRefresh(HWND hWnd, SM_SERVER *p)\r
+{\r
+       RPC_ENUM_HUB t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 仮想 HUB リスト更新\r
+       Zero(&t, sizeof(t));\r
+       if (CALL(hWnd, ScEnumHub(p->Rpc, &t)))\r
+       {\r
+               LVB *b = LvInsertStart();\r
+               for (i = 0;i < t.NumHub;i++)\r
+               {\r
+                       RPC_ENUM_HUB_ITEM *e = &t.Hubs[i];\r
+                       wchar_t name[MAX_HUBNAME_LEN + 1];\r
+                       wchar_t s1[64], s2[64], s3[64], s4[64], s5[64];\r
+                       wchar_t s6[64], s7[128], s8[128];\r
+                       UniToStru(s1, e->NumUsers);\r
+                       UniToStru(s2, e->NumGroups);\r
+                       UniToStru(s3, e->NumSessions);\r
+                       UniToStru(s4, e->NumMacTables);\r
+                       UniToStru(s5, e->NumIpTables);\r
+\r
+                       UniToStru(s6, e->NumLogin);\r
+\r
+                       if (e->LastLoginTime != 0)\r
+                       {\r
+                               GetDateTimeStr64Uni(s7, sizeof(s7), SystemToLocal64(e->LastLoginTime));\r
+                       }\r
+                       else\r
+                       {\r
+                               UniStrCpy(s7, sizeof(s7), _UU("COMMON_UNKNOWN"));\r
+                       }\r
+\r
+                       if (e->LastCommTime != 0)\r
+                       {\r
+                               GetDateTimeStr64Uni(s8, sizeof(s8), SystemToLocal64(e->LastCommTime));\r
+                       }\r
+                       else\r
+                       {\r
+                               UniStrCpy(s8, sizeof(s8), _UU("COMMON_UNKNOWN"));\r
+                       }\r
+\r
+                       StrToUni(name, sizeof(name), e->HubName);\r
+\r
+                       LvInsertAdd(b,\r
+                               e->Online ? ICO_HUB : ICO_HUB_OFFLINE,\r
+                               NULL,\r
+                               11,\r
+                               name,\r
+                               e->Online ? _UU("SM_HUB_ONLINE") : _UU("SM_HUB_OFFLINE"),\r
+                               GetHubTypeStr(e->HubType),\r
+                               s1, s2, s3, s4, s5, s6, s7, s8);\r
+               }\r
+               LvInsertEnd(b, hWnd, L_HUB);\r
+               FreeRpcEnumHub(&t);\r
+       }\r
+\r
+       // リスナーリスト更新\r
+       if (p != NULL)\r
+       {\r
+               RPC_LISTENER_LIST t;\r
+               Zero(&t, sizeof(RPC_LISTENER_LIST));\r
+               if (CALL(hWnd, ScEnumListener(p->Rpc, &t)))\r
+               {\r
+                       LVB *b = LvInsertStart();\r
+                       for (i = 0;i < t.NumPort;i++)\r
+                       {\r
+                               wchar_t tmp[MAX_SIZE];\r
+                               wchar_t *status;\r
+                               UINT icon;\r
+                               UniFormat(tmp, sizeof(tmp), _UU("CM_LISTENER_TCP_PORT"), t.Ports[i]);\r
+\r
+                               status = _UU("CM_LISTENER_ONLINE");\r
+                               icon = ICO_PROTOCOL;\r
+                               if (t.Errors[i])\r
+                               {\r
+                                       status = _UU("CM_LISTENER_ERROR");\r
+                                       icon = ICO_PROTOCOL_X;\r
+                               }\r
+                               else if (t.Enables[i] == false)\r
+                               {\r
+                                       status = _UU("CM_LISTENER_OFFLINE");\r
+                                       icon = ICO_PROTOCOL_OFFLINE;\r
+                               }\r
+\r
+                               LvInsertAdd(b, icon, (void *)t.Ports[i], 2, tmp, status);\r
+                       }\r
+                       LvInsertEnd(b, hWnd, L_LISTENER);\r
+                       FreeRpcListenerList(&t);\r
+               }\r
+       }\r
+\r
+       SmServerDlgUpdate(hWnd, p);\r
+}\r
+\r
+// サーバー管理ダイアログプロシージャ\r
+UINT SmServerDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_SERVER *p = (SM_SERVER *)param;\r
+       wchar_t *s;\r
+       wchar_t tmp[MAX_SIZE];\r
+       NMHDR *n;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               FormatText(hWnd, 0, p->Title);\r
+\r
+               if (p->Bridge == false)\r
+               {\r
+                       FormatText(hWnd, S_TITLE, p->ServerName);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("SM_SERVER_BRIDGE_TITLE"), p->ServerName);\r
+                       SetText(hWnd, S_TITLE, tmp);\r
+\r
+                       SetText(hWnd, S_VHUB_BRIDGE, _UU("SM_S_VHUB_BRIDGE"));\r
+               }\r
+\r
+               DlgFont(hWnd, S_TITLE, 16, 1);\r
+\r
+               SetIcon(hWnd, 0, p->Bridge == false ? ICO_VPNSERVER : ICO_BRIDGE);\r
+\r
+               SmServerDlgInit(hWnd, p);\r
+\r
+               SetTimer(hWnd, 1, 50, NULL);\r
+\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // 管理\r
+                       if (IsEnable(hWnd, IDOK))\r
+                       {\r
+                               if (p->Bridge == false)\r
+                               {\r
+                                       s = LvGetSelectedStr(hWnd, L_HUB, 0);\r
+                               }\r
+                               else\r
+                               {\r
+                                       s = CopyUniStr(L"BRIDGE");\r
+                               }\r
+                               if (s != NULL)\r
+                               {\r
+                                       char hubname[MAX_HUBNAME_LEN + 1];\r
+                                       SM_HUB hub;\r
+                                       Zero(&hub, sizeof(hub));\r
+                                       UniToStr(hubname, sizeof(hubname), s);\r
+                                       hub.p = p;\r
+                                       hub.Rpc = p->Rpc;\r
+                                       hub.HubName = hubname;\r
+                                       SmHubDlg(hWnd, &hub);\r
+                                       //SmServerDlgRefresh(hWnd, p);\r
+                                       Free(s);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_ONLINE:\r
+                       // オンラインにする\r
+                       s = LvGetSelectedStr(hWnd, L_HUB, 0);\r
+                       if (s != NULL)\r
+                       {\r
+                               RPC_SET_HUB_ONLINE t;\r
+                               Zero(&t, sizeof(t));\r
+                               UniToStr(t.HubName, sizeof(t.HubName), s);\r
+                               t.Online = true;\r
+                               if (CALL(hWnd, ScSetHubOnline(p->Rpc, &t)))\r
+                               {\r
+                                       SmServerDlgRefresh(hWnd, p);\r
+                               }\r
+                               Free(s);\r
+                       }\r
+                       break;\r
+\r
+               case B_OFFLINE:\r
+                       // オフラインにする\r
+                       s = LvGetSelectedStr(hWnd, L_HUB, 0);\r
+                       if (s != NULL)\r
+                       {\r
+                               RPC_SET_HUB_ONLINE t;\r
+                               Zero(&t, sizeof(t));\r
+                               // 確認メッセージ\r
+                               if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2,\r
+                                       _UU("CM_OFFLINE_MSG"), s) == IDYES)\r
+                               {\r
+                                       UniToStr(t.HubName, sizeof(t.HubName), s);\r
+                                       t.Online = false;\r
+                                       if (CALL(hWnd, ScSetHubOnline(p->Rpc, &t)))\r
+                                       {\r
+                                               SmServerDlgRefresh(hWnd, p);\r
+                                       }\r
+                               }\r
+                               Free(s);\r
+                       }\r
+                       break;\r
+\r
+               case B_HUB_STATUS:\r
+                       // HUB の状態\r
+                       s = LvGetSelectedStr(hWnd, L_HUB, 0);\r
+                       if (s != NULL)\r
+                       {\r
+                               wchar_t tmp[MAX_SIZE];\r
+                               char *hubname = CopyUniToStr(s);\r
+                               UniFormat(tmp, sizeof(tmp), _UU("SM_HUB_STATUS_CAPTION"), s);\r
+                               SmStatusDlg(hWnd, p, hubname, false, true, tmp, ICO_HUB,\r
+                                       NULL, SmRefreshHubStatus);\r
+                               Free(hubname);\r
+                               Free(s);\r
+                       }\r
+                       break;\r
+\r
+               case B_CREATE:\r
+                       // HUB の作成\r
+                       if (SmCreateHubDlg(hWnd, p))\r
+                       {\r
+                               SmServerDlgRefresh(hWnd, p);\r
+                       }\r
+                       break;\r
+\r
+               case B_EDIT:\r
+                       // HUB の編集\r
+                       s = LvGetSelectedStr(hWnd, L_HUB, 0);\r
+                       if (s != NULL)\r
+                       {\r
+                               char *name = CopyUniToStr(s);\r
+                               if (SmEditHubDlg(hWnd, p, name))\r
+                               {\r
+                                       SmServerDlgRefresh(hWnd, p);\r
+                               }\r
+                               Free(name);\r
+                               Free(s);\r
+                       }\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       // HUB の削除\r
+                       s = LvGetSelectedStr(hWnd, L_HUB, 0);\r
+                       if (s != NULL)\r
+                       {\r
+                               char *name = CopyUniToStr(s);\r
+                               RPC_DELETE_HUB t;\r
+                               Zero(&t, sizeof(t));\r
+                               StrCpy(t.HubName, sizeof(t.HubName), name);\r
+                               if (MsgBoxEx(hWnd, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2, _UU("CM_DELETE_HUB_MSG"), name) == IDYES)\r
+                               {\r
+                                       if (CALL(hWnd, ScDeleteHub(p->Rpc, &t)))\r
+                                       {\r
+                                               SmServerDlgRefresh(hWnd, p);\r
+                                               MsgBoxEx(hWnd, MB_ICONINFORMATION, _UU("CM_HUB_DELETED_MSG"), name);\r
+                                       }\r
+                               }\r
+                               Free(name);\r
+                               Free(s);\r
+                       }\r
+                       break;\r
+\r
+               case B_CREATE_LISTENER:\r
+                       // リスナー作成\r
+                       if (SmCreateListenerDlg(hWnd, p))\r
+                       {\r
+                               SmServerDlgRefresh(hWnd, p);\r
+                       }\r
+                       break;\r
+\r
+               case B_DELETE_LISTENER:\r
+                       // リスナー削除\r
+                       i = LvGetSelected(hWnd, L_LISTENER);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               UINT port = (UINT)LvGetParam(hWnd, L_LISTENER, i);\r
+                               if (MsgBoxEx(hWnd, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2, _UU("CM_DELETE_LISTENER_MSG"), port) == IDYES)\r
+                               {\r
+                                       RPC_LISTENER t;\r
+                                       Zero(&t, sizeof(t));\r
+                                       t.Enable = false;\r
+                                       t.Port = port;\r
+\r
+                                       if (CALL(hWnd, ScDeleteListener(p->Rpc, &t)))\r
+                                       {\r
+                                               SmServerDlgRefresh(hWnd, p);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_START:\r
+                       // 開始\r
+                       i = LvGetSelected(hWnd, L_LISTENER);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               UINT port = (UINT)LvGetParam(hWnd, L_LISTENER, i);\r
+                               RPC_LISTENER t;\r
+                               Zero(&t, sizeof(t));\r
+                               t.Enable = true;\r
+                               t.Port = port;\r
+\r
+                               if (CALL(hWnd, ScEnableListener(p->Rpc, &t)))\r
+                               {\r
+                                       SmServerDlgRefresh(hWnd, p);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_STOP:\r
+                       // 停止\r
+                       i = LvGetSelected(hWnd, L_LISTENER);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               UINT port = (UINT)LvGetParam(hWnd, L_LISTENER, i);\r
+                               if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("CM_STOP_LISTENER_MSG"), port) == IDYES)\r
+                               {\r
+                                       RPC_LISTENER t;\r
+                                       Zero(&t, sizeof(t));\r
+                                       t.Enable = false;\r
+                                       t.Port = port;\r
+\r
+                                       if (CALL(hWnd, ScEnableListener(p->Rpc, &t)))\r
+                                       {\r
+                                               SmServerDlgRefresh(hWnd, p);\r
+                                       }\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_SSL:\r
+                       // SSL 関係\r
+                       SmSslDlg(hWnd, p);\r
+                       break;\r
+\r
+               case B_STATUS:\r
+                       // サーバー状態\r
+                       SmStatusDlg(hWnd, p, p, false, true, _UU("SM_SERVER_STATUS"), ICO_VPNSERVER,\r
+                               NULL, SmRefreshServerStatus);\r
+                       break;\r
+\r
+               case B_INFO:\r
+                       // サーバー情報\r
+                       SmStatusDlg(hWnd, p, p, false, false, _UU("SM_INFO_TITLE"), ICO_VPNSERVER,\r
+                               NULL, SmRefreshServerInfo);\r
+                       break;\r
+\r
+               case B_BRIDGE:\r
+                       // ローカルブリッジ設定\r
+                       SmBridgeDlg(hWnd, p);\r
+                       SmServerDlgRefresh(hWnd, p);\r
+                       break;\r
+\r
+               case B_FARM:\r
+                       // サーバーファーム\r
+                       if (SmFarmDlg(hWnd, p))\r
+                       {\r
+                               // サーバー ファーム構成が変更された場合はダイアログを閉じる\r
+                               Close(hWnd);\r
+                       }\r
+                       break;\r
+\r
+               case B_FARM_STATUS:\r
+                       // サーバー ファーム 状態\r
+                       if (p->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+                       {\r
+                               Dialog(hWnd, D_SM_FARM_MEMBER, SmFarmMemberDlgProc, p);\r
+                       }\r
+                       else if (p->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+                       {\r
+                               SmStatusDlg(hWnd, p, NULL, false, true, _UU("SM_FC_STATUS_CAPTION"),\r
+                                       ICO_FARM, NULL, SmRefreshFarmConnectionInfo);\r
+                       }\r
+                       break;\r
+\r
+               case B_CONNECTION:\r
+                       // TCP コネクション一覧\r
+                       SmConnectionDlg(hWnd, p);\r
+                       break;\r
+\r
+               case B_REFRESH:\r
+                       // 最新の状態に更新\r
+                       SmServerDlgRefresh(hWnd, p);\r
+                       break;\r
+\r
+               case B_CONFIG:\r
+                       // config 編集\r
+                       SmConfig(hWnd, p);\r
+                       break;\r
+\r
+               case B_L3:\r
+                       // L3 スイッチ\r
+                       SmL3(hWnd, p);\r
+                       break;\r
+\r
+               case B_LICENSE:\r
+                       // ライセンスの追加と削除\r
+                       SmLicense(hWnd, p);\r
+                       SmServerDlgUpdate(hWnd, p);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               {\r
+                       // 最後に選択されていた HUB を保存する\r
+                       char *hubname = NULL;\r
+                       char tmp[MAX_SIZE];\r
+\r
+\r
+                       Format(tmp, sizeof(tmp), "%s:%u:%s", p->CurrentSetting->ClientOption.Hostname,\r
+                               p->CurrentSetting->ClientOption.Port,\r
+                               p->CurrentSetting->ServerAdminMode ? "" : p->CurrentSetting->HubName);\r
+\r
+                       if (LvIsSingleSelected(hWnd, L_HUB))\r
+                       {\r
+                               hubname = LvGetSelectedStrA(hWnd, L_HUB, 0);\r
+                       }\r
+\r
+                       if (IsEmptyStr(hubname) == false)\r
+                       {\r
+                               MsRegWriteStr(REG_CURRENT_USER, SM_LASTHUB_REG_KEY, tmp, hubname);\r
+                       }\r
+                       else\r
+                       {\r
+                               MsRegDeleteValue(REG_CURRENT_USER, SM_LASTHUB_REG_KEY, tmp);\r
+                       }\r
+\r
+                       Free(hubname);\r
+\r
+                       EndDialog(hWnd, false);\r
+               }\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_HUB:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmServerDlgUpdate(hWnd, p);\r
+                               break;\r
+                       }\r
+                       break;\r
+               case L_LISTENER:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               SmServerDlgUpdate(hWnd, p);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+\r
+                       if (p->EmptyPassword && p->ServerAdminMode)\r
+                       {\r
+                               // パスワードが空の場合は変更を推奨する\r
+                               if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("SM_PASSWORD_MSG")) == IDYES)\r
+                               {\r
+                                       Dialog(hWnd, D_SM_CHANGE_PASSWORD, SmChangeServerPasswordDlg, p);\r
+                               }\r
+                       }\r
+\r
+                       if (p->ServerAdminMode)\r
+                       {\r
+                               // ライセンスキーが登録されていない場合は登録を促す\r
+                               RPC_LICENSE_STATUS t;\r
+\r
+                               Zero(&t, sizeof(t));\r
+                               if (p->Bridge == false && GetCapsBool(p->CapsList, "b_support_license"))\r
+                               {\r
+                                       if (ScGetLicenseStatus(p->Rpc, &t) == ERR_NO_ERROR)\r
+                                       {\r
+                                               if (t.EditionId == LICENSE_EDITION_VPN3_NO_LICENSE || (t.NeedSubscription && t.SubscriptionExpires == 0))\r
+                                               {\r
+                                                       // 有効なライセンスキーが 1 つも登録されていない\r
+\r
+                                                       if (MsgBox(hWnd, MB_YESNO | MB_ICONINFORMATION,\r
+                                                               _UU("SM_SETUP_NO_LICENSE_KEY")) == IDYES)\r
+                                                       {\r
+                                                               SmLicense(hWnd, p);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       SetTimer(hWnd, 2, 150, NULL);\r
+                       break;\r
+\r
+               case 2:\r
+                       // セットアップ\r
+                       KillTimer(hWnd, 2);\r
+\r
+                       if (SmSetupIsNew(p))\r
+                       {\r
+                               if (SmSetup(hWnd, p))\r
+                               {\r
+                                       SmServerDlgRefresh(hWnd, p);\r
+                               }\r
+                       }\r
+\r
+                       SetTimer(hWnd, 3, 150, NULL);\r
+                       break;\r
+\r
+               case 3:\r
+                       // 管理者向けメッセージ\r
+                       KillTimer(hWnd, 3);\r
+\r
+                       if (UniIsEmptyStr(p->AdminMsg) == false)\r
+                       {\r
+                               wchar_t tmp[MAX_SIZE];\r
+\r
+                               UniFormat(tmp, sizeof(tmp), _UU("SM_SERVER_ADMIN_MSG"), p->ServerName);\r
+                               OnceMsg(hWnd, tmp, p->AdminMsg, true, ICO_VPNSERVER);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       LvStandardHandler(hWnd, msg, wParam, lParam, L_HUB);\r
+\r
+       return 0;\r
+}\r
+\r
+// 接続\r
+void SmConnect(HWND hWnd, SETTING *s)\r
+{\r
+       bool ok;\r
+       RPC *rpc;\r
+       char *pass;\r
+       bool empty_password = false;\r
+       bool first_bad_password = false;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // コントロールの無効化\r
+       Disable(hWnd, L_SETTING);\r
+       Disable(hWnd, B_NEW_SETTING);\r
+       Disable(hWnd, B_EDIT_SETTING);\r
+       Disable(hWnd, B_DELETE);\r
+       Disable(hWnd, IDOK);\r
+       Disable(hWnd, B_ABOUT);\r
+       Disable(hWnd, IDCANCEL);\r
+       Disable(hWnd, B_SECURE_MANAGER);\r
+       Disable(hWnd, B_SELECT_SECURE);\r
+\r
+       ok = true;\r
+\r
+       if (IsZero(s->HashedPassword, SHA1_SIZE))\r
+       {\r
+               // パスワード入力画面\r
+ENTER_PASSWORD:\r
+               pass = SmPassword(hWnd, s->ClientOption.Hostname);\r
+               if (pass != NULL)\r
+               {\r
+                       Hash(s->HashedPassword, pass, StrLen(pass), true);\r
+                       Free(pass);\r
+                       ok = true;\r
+               }\r
+               else\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       if (ok)\r
+       {\r
+               UINT err = ERR_INTERNAL_ERROR;\r
+               // 接続\r
+               rpc = AdminConnectEx2(sm->Cedar, &s->ClientOption, s->ServerAdminMode ? "" : s->HubName, s->HashedPassword, &err, NULL,\r
+                       hWnd);\r
+               if (rpc == NULL)\r
+               {\r
+                       // エラー発生\r
+                       if (err != ERR_ACCESS_DENIED || first_bad_password)\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONSTOP, _E(err));\r
+                       }\r
+                       if (err == ERR_ACCESS_DENIED)\r
+                       {\r
+                               // パスワード間違い\r
+                               first_bad_password = true;\r
+                               goto ENTER_PASSWORD;\r
+                       }\r
+                       else\r
+                       {\r
+                               // その他のエラー\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       UCHAR test[SHA1_SIZE];\r
+                       SM_SERVER p;\r
+                       RPC_SERVER_STATUS status;\r
+                       RPC_SERVER_INFO info;\r
+                       SETTING *setting;\r
+                       RPC_MSG msg;\r
+\r
+                       Hash(test, "", 0, true);\r
+\r
+                       if (Cmp(test, s->HashedPassword, SHA1_SIZE) == 0)\r
+                       {\r
+                               empty_password = true;\r
+                       }\r
+\r
+                       if (sm->TempSetting == NULL)\r
+                       {\r
+                               setting = SmGetSetting(s->Title);\r
+                               if (setting != NULL)\r
+                               {\r
+                                       if (IsZero(setting->HashedPassword, SHA1_SIZE) == false)\r
+                                       {\r
+                                               Copy(setting->HashedPassword, s->HashedPassword, SHA1_SIZE);\r
+                                               SmWriteSettingList();\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       rpc->ServerAdminMode = s->ServerAdminMode;\r
+                       if (s->ServerAdminMode == false)\r
+                       {\r
+                               StrCpy(rpc->HubName, sizeof(rpc->HubName), s->HubName);\r
+                       }\r
+\r
+                       Zero(&p, sizeof(p));\r
+                       p.CurrentSetting = s;\r
+                       p.Rpc = rpc;\r
+                       p.EmptyPassword = empty_password;\r
+                       p.ServerAdminMode = rpc->ServerAdminMode;\r
+                       StrCpy(p.ServerName, sizeof(p.ServerName), s->ClientOption.Hostname);\r
+                       if (p.ServerAdminMode == false)\r
+                       {\r
+                               StrCpy(p.HubName, sizeof(p.HubName), rpc->HubName);\r
+                       }\r
+                       UniStrCpy(p.Title, sizeof(p.Title), s->Title);\r
+\r
+                       // サーバーの種類の取得\r
+                       Zero(&status, sizeof(status));\r
+                       ScGetServerStatus(rpc, &status);\r
+\r
+                       p.ServerType = status.ServerType;\r
+\r
+                       Zero(&info, sizeof(info));\r
+                       ScGetServerInfo(rpc, &info);\r
+\r
+                       Copy(&p.ServerInfo, &info, sizeof(RPC_SERVER_INFO));\r
+                       Copy(&p.ServerStatus, &status, sizeof(RPC_SERVER_STATUS));\r
+\r
+                       // Admin Msg の取得\r
+                       Zero(&msg, sizeof(msg));\r
+                       if (ScGetAdminMsg(rpc, &msg) == ERR_NO_ERROR)\r
+                       {\r
+                               p.AdminMsg = UniCopyStr(msg.Msg);\r
+                               FreeRpcMsg(&msg);\r
+                       }\r
+\r
+                       // Caps の取得\r
+                       p.CapsList = ScGetCapsEx(p.Rpc);\r
+\r
+                       p.Bridge = GetCapsBool(p.CapsList, "b_bridge");\r
+\r
+                       if (GetCapsBool(p.CapsList, "b_support_policy_ver_3"))\r
+                       {\r
+                               p.PolicyVer = 3;\r
+                       }\r
+                       else\r
+                       {\r
+                               p.PolicyVer = 2;\r
+                       }\r
+\r
+                       // サーバー管理画面\r
+                       Dialog(hWnd, D_SM_SERVER, SmServerDlgProc, &p);\r
+\r
+                       // 切断\r
+                       AdminDisconnect(rpc);\r
+\r
+                       // Caps の解放\r
+                       FreeCapsList(p.CapsList);\r
+\r
+                       Free(p.AdminMsg);\r
+                       p.AdminMsg = NULL;\r
+\r
+                       FreeRpcServerInfo(&info);\r
+               }\r
+       }\r
+\r
+       // コントロールの有効化\r
+       Enable(hWnd, L_SETTING);\r
+       Enable(hWnd, B_NEW_SETTING);\r
+       Enable(hWnd, B_EDIT_SETTING);\r
+       Enable(hWnd, B_DELETE);\r
+       Enable(hWnd, IDOK);\r
+       Enable(hWnd, B_ABOUT);\r
+       Enable(hWnd, IDCANCEL);\r
+       Enable(hWnd, B_SECURE_MANAGER);\r
+       Enable(hWnd, B_SELECT_SECURE);\r
+}\r
+\r
+// パスワード入力ダイアログ\r
+char *SmPassword(HWND hWnd, char *server_name)\r
+{\r
+       char *ret;\r
+       UI_PASSWORD_DLG p;\r
+       // 引数チェック\r
+       if (server_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.AdminMode = true;\r
+       StrCpy(p.ServerName, sizeof(p.ServerName), server_name);\r
+\r
+       if (PasswordDlg(hWnd, &p) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = CopyStr(p.Password);\r
+\r
+       return ret;\r
+}\r
+\r
+// 設定の編集ダイアログ初期化\r
+void SmEditSettingDlgInit(HWND hWnd, SM_EDIT_SETTING *p)\r
+{\r
+       SETTING *s;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p->Inited = false;\r
+\r
+       s = p->Setting;\r
+\r
+       // タイトル\r
+       if (p->EditMode == false)\r
+       {\r
+               SetText(hWnd, 0, _UU("SM_EDIT_CAPTION_1"));\r
+       }\r
+       else\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               UniFormat(tmp, sizeof(tmp), _UU("SM_EDIT_CAPTION_2"), s->Title);\r
+               SetText(hWnd, 0, tmp);\r
+       }\r
+\r
+       // 接続設定名\r
+       SetText(hWnd, E_ACCOUNT_NAME, s->Title);\r
+\r
+       // ホスト名\r
+       SetTextA(hWnd, E_HOSTNAME, s->ClientOption.Hostname);\r
+\r
+       // ポート番号\r
+       CbSetHeight(hWnd, C_PORT, 18);\r
+       CbAddStr(hWnd, C_PORT, _UU("CM_PORT_4"), 0);\r
+       CbAddStr(hWnd, C_PORT, _UU("CM_PORT_1"), 0);\r
+       CbAddStr(hWnd, C_PORT, _UU("CM_PORT_2"), 0);\r
+       CbAddStr(hWnd, C_PORT, _UU("CM_PORT_3"), 0);\r
+       SetIntEx(hWnd, C_PORT, s->ClientOption.Port);\r
+\r
+       // プロキシ設定\r
+       Check(hWnd, R_DIRECT_TCP, s->ClientOption.ProxyType == PROXY_DIRECT);\r
+       Check(hWnd, R_HTTPS, s->ClientOption.ProxyType == PROXY_HTTP);\r
+       Check(hWnd, R_SOCKS, s->ClientOption.ProxyType == PROXY_SOCKS);\r
+\r
+       // 管理モード設定\r
+       Check(hWnd, R_SERVER_ADMIN, s->ServerAdminMode);\r
+       Check(hWnd, R_HUB_ADMIN, s->ServerAdminMode == false ? true : false);\r
+       CbSetHeight(hWnd, C_HUBNAME, 18);\r
+       SetTextA(hWnd, C_HUBNAME, s->HubName);\r
+\r
+       // パスワード\r
+       if (IsZero(s->HashedPassword, SHA1_SIZE))\r
+       {\r
+               Check(hWnd, R_NO_SAVE, true);\r
+       }\r
+       else\r
+       {\r
+               UCHAR test[SHA1_SIZE];\r
+\r
+               Hash(test, "", 0, true);\r
+               if (Cmp(test, s->HashedPassword, SHA1_SIZE) != 0)\r
+               {\r
+                       SetTextA(hWnd, E_PASSWORD, HIDDEN_PASSWORD);\r
+               }\r
+       }\r
+\r
+       if (p->EditMode == false)\r
+       {\r
+               FocusEx(hWnd, E_ACCOUNT_NAME);\r
+       }\r
+       else\r
+       {\r
+               FocusEx(hWnd, E_HOSTNAME);\r
+       }\r
+\r
+       p->Inited = true;\r
+\r
+       // 仮想 HUB の列挙を開始\r
+       CmEnumHubStart(hWnd, &s->ClientOption);\r
+\r
+       SmEditSettingDlgUpdate(hWnd, p);\r
+}\r
+\r
+// 設定の編集ダイアログ更新\r
+void SmEditSettingDlgUpdate(HWND hWnd, SM_EDIT_SETTING *p)\r
+{\r
+       bool ok = true;\r
+       UINT delete_hub_list = 0;\r
+       SETTING *s;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL || p->Inited == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = p->Setting;\r
+\r
+       GetTxt(hWnd, E_ACCOUNT_NAME, s->Title, sizeof(s->Title));\r
+       UniTrim(s->Title);\r
+\r
+       if (UniStrLen(s->Title) == 0)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_LOCALHOST))\r
+       {\r
+               SetTextA(hWnd, E_HOSTNAME, "localhost");\r
+               Disable(hWnd, E_HOSTNAME);\r
+       }\r
+       else\r
+       {\r
+               Enable(hWnd, E_HOSTNAME);\r
+       }\r
+\r
+       GetTxtA(hWnd, E_HOSTNAME, tmp, sizeof(tmp));\r
+       Trim(tmp);\r
+\r
+       if (StrCmpi(tmp, s->ClientOption.Hostname) != 0)\r
+       {\r
+               delete_hub_list++;\r
+       }\r
+\r
+       StrCpy(s->ClientOption.Hostname, sizeof(s->ClientOption.Hostname), tmp);\r
+\r
+       if (StrLen(s->ClientOption.Hostname) == 0)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       s->ClientOption.Port = GetInt(hWnd, C_PORT);\r
+       if (s->ClientOption.Port == 0)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_DIRECT_TCP))\r
+       {\r
+               s->ClientOption.ProxyType = PROXY_DIRECT;\r
+       }\r
+       else if (IsChecked(hWnd, R_HTTPS))\r
+       {\r
+               s->ClientOption.ProxyType = PROXY_HTTP;\r
+       }\r
+       else\r
+       {\r
+               s->ClientOption.ProxyType = PROXY_SOCKS;\r
+       }\r
+\r
+       SetEnable(hWnd, B_PROXY_CONFIG, s->ClientOption.ProxyType != PROXY_DIRECT);\r
+\r
+       if (s->ClientOption.ProxyType != PROXY_DIRECT)\r
+       {\r
+               if (StrLen(s->ClientOption.ProxyName) == 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+               if (s->ClientOption.ProxyPort == 0)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       s->ServerAdminMode = IsChecked(hWnd, R_SERVER_ADMIN);\r
+\r
+       SetEnable(hWnd, C_HUBNAME, s->ServerAdminMode == false ? true : false);\r
+       SetEnable(hWnd, S_HUBNAME, s->ServerAdminMode == false ? true : false);\r
+\r
+       GetTxtA(hWnd, C_HUBNAME, s->HubName, sizeof(s->HubName));\r
+       Trim(s->HubName);\r
+       if (StrLen(s->HubName) == 0)\r
+       {\r
+               if (s->ServerAdminMode == false)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_NO_SAVE))\r
+       {\r
+               Zero(s->HashedPassword, SHA1_SIZE);\r
+               SetTextA(hWnd, E_PASSWORD, "");\r
+               Disable(hWnd, E_PASSWORD);\r
+               Disable(hWnd, S_PASSWORD);\r
+       }\r
+       else\r
+       {\r
+               char tmp[MAX_PASSWORD_LEN + 1];\r
+               Enable(hWnd, E_PASSWORD);\r
+               Enable(hWnd, S_PASSWORD);\r
+               GetTxtA(hWnd, E_PASSWORD, tmp, sizeof(tmp));\r
+               if (StrCmp(tmp, HIDDEN_PASSWORD) != 0)\r
+               {\r
+                       Hash(s->HashedPassword, tmp, StrLen(tmp), true);\r
+               }\r
+       }\r
+\r
+       if (delete_hub_list)\r
+       {\r
+               CbReset(hWnd, C_HUBNAME);\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// 設定の編集ダイアログ OK ボタン\r
+void SmEditSettingDlgOnOk(HWND hWnd, SM_EDIT_SETTING *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (p->EditMode == false)\r
+       {\r
+               // 新規登録\r
+               SETTING *s = ZeroMalloc(sizeof(SETTING));\r
+               Copy(s, p->Setting, sizeof(SETTING));\r
+               if (SmAddSetting(s) == false)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("SM_SETTING_EXISTS"), s->Title);\r
+                       Free(s);\r
+                       FocusEx(hWnd, E_ACCOUNT_NAME);\r
+                       return;\r
+               }\r
+               EndDialog(hWnd, true);\r
+       }\r
+       else\r
+       {\r
+               // 更新登録\r
+               SETTING *t = SmGetSetting(p->Setting->Title);\r
+               if (t != NULL && t != p->OldSetting)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("SM_SETTING_EXISTS"), p->Setting->Title);\r
+                       FocusEx(hWnd, E_ACCOUNT_NAME);\r
+                       return;\r
+               }\r
+\r
+               Copy(p->OldSetting, p->Setting, sizeof(SETTING));\r
+               Sort(sm->SettingList);\r
+               SmWriteSettingList();\r
+\r
+               EndDialog(hWnd, true);\r
+       }\r
+}\r
+\r
+// 設定の追加 / 編集ダイアログ\r
+UINT SmEditSettingDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SM_EDIT_SETTING *p = (SM_EDIT_SETTING *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SmEditSettingDlgInit(hWnd, p);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_LOCALHOST:\r
+               case E_ACCOUNT_NAME:\r
+               case E_HOSTNAME:\r
+               case C_PORT:\r
+               case R_DIRECT_TCP:\r
+               case R_HTTPS:\r
+               case R_SOCKS:\r
+               case R_SERVER_ADMIN:\r
+               case R_HUB_ADMIN:\r
+               case C_HUBNAME:\r
+               case E_PASSWORD:\r
+               case R_NO_SAVE:\r
+                       SmEditSettingDlgUpdate(hWnd, p);\r
+                       break;\r
+               }\r
+\r
+               if (LOWORD(wParam) == R_LOCALHOST)\r
+               {\r
+                       FocusEx(hWnd, E_HOSTNAME);\r
+               }\r
+\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_HOSTNAME:\r
+                       if (HIWORD(wParam) == EN_KILLFOCUS)\r
+                       {\r
+                               CmEnumHubStart(hWnd, &p->Setting->ClientOption);\r
+                       }\r
+                       break;\r
+               case C_PORT:\r
+                       if (HIWORD(wParam) == CBN_KILLFOCUS)\r
+                       {\r
+                               CmEnumHubStart(hWnd, &p->Setting->ClientOption);\r
+                       }\r
+                       break;\r
+               case R_DIRECT_TCP:\r
+               case R_HTTPS:\r
+               case R_SOCKS:\r
+                       if (HIWORD(wParam) == BN_CLICKED)\r
+                       {\r
+                               CmEnumHubStart(hWnd, &p->Setting->ClientOption);\r
+                       }\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       SmEditSettingDlgOnOk(hWnd, p);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_PROXY_CONFIG:\r
+                       // プロキシ設定\r
+                       if (CmProxyDlg(hWnd, &p->Setting->ClientOption))\r
+                       {\r
+                               UINT n = GetInt(hWnd, C_PORT);\r
+                               if (p->Setting->ClientOption.ProxyType == PROXY_HTTP &&\r
+                                       n != 443)\r
+                               {\r
+                                       // HTTP プロキシ経由の設定になっていて接続先が 443 番ポート\r
+                                       // 以外のポートである場合は警告を表示する\r
+                                       if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("CM_HTTP_PROXY_WARNING"), n) == IDYES)\r
+                                       {\r
+                                               // ポート番号を 443 に変更する\r
+                                               SetText(hWnd, C_PORT, _UU("CM_PORT_2"));\r
+                                       }\r
+                               }\r
+                               SmEditSettingDlgUpdate(hWnd, p);\r
+                               CmEnumHubStart(hWnd, &p->Setting->ClientOption);\r
+                       }\r
+                       break;\r
+\r
+               case R_NO_SAVE:\r
+                       if (IsChecked(hWnd, R_NO_SAVE) == false)\r
+                       {\r
+                               FocusEx(hWnd, E_PASSWORD);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 設定の追加ダイアログを表示\r
+bool SmAddSettingDlg(HWND hWnd, wchar_t *new_name, UINT new_name_size)\r
+{\r
+       SM_EDIT_SETTING p;\r
+       SETTING s;\r
+       UINT i;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || new_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       Zero(&s, sizeof(s));\r
+\r
+       s.ClientOption.Port = 443;\r
+\r
+       p.EditMode = false;\r
+       p.Setting = &s;\r
+\r
+       for (i = 1;;i++)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               if (i == 1)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_NEW_ACCOUNT_NAME_1"));\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("CM_NEW_ACCOUNT_NAME_2"), i);\r
+               }\r
+\r
+               if (SmGetSetting(tmp) == NULL)\r
+               {\r
+                       UniStrCpy(s.Title, sizeof(s.Title), tmp);\r
+                       Hash(s.HashedPassword, "", 0, true);\r
+                       s.ServerAdminMode = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       ret = Dialog(hWnd, D_SM_EDIT_SETTING, SmEditSettingDlgProc, &p);\r
+\r
+       if (ret)\r
+       {\r
+               UniStrCpy(new_name, new_name_size, s.Title);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 設定の編集ダイアログを表示\r
+bool SmEditSettingDlg(HWND hWnd)\r
+{\r
+       SM_EDIT_SETTING p;\r
+       SETTING s, *setting;\r
+       UINT i;\r
+       wchar_t *name;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       i = LvGetSelected(hWnd, L_SETTING);\r
+       if (i == INFINITE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       name = LvGetStr(hWnd, L_SETTING, i, 0);\r
+\r
+       setting = SmGetSetting(name);\r
+       if (setting == NULL)\r
+       {\r
+               Free(name);\r
+               return false;\r
+       }\r
+\r
+       Free(name);\r
+\r
+       Copy(&s, setting, sizeof(SETTING));\r
+\r
+       Zero(&p, sizeof(p));\r
+\r
+       p.EditMode = true;\r
+       p.OldSetting = setting;\r
+       p.Setting = &s;\r
+\r
+       return Dialog(hWnd, D_SM_EDIT_SETTING, SmEditSettingDlgProc, &p);\r
+}\r
+\r
+// 設定の更新\r
+bool SmCheckNewName(SETTING *s, wchar_t *new_title)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (new_title == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (s != NULL)\r
+       {\r
+               if (IsInList(sm->SettingList, s) == false)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // 他に同一の名前が無いかどうかチェック\r
+       for (i = 0;i < LIST_NUM(sm->SettingList);i++)\r
+       {\r
+               SETTING *t = LIST_DATA(sm->SettingList, i);\r
+\r
+               if (s != t)\r
+               {\r
+                       if (UniStrCmpi(t->Title, new_title) == 0)\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 設定の削除\r
+void SmDeleteSetting(wchar_t *title)\r
+{\r
+       SETTING *s;\r
+       // 引数チェック\r
+       if (title == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = SmGetSetting(title);\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Delete(sm->SettingList, s);\r
+       Free(s);\r
+       Sort(sm->SettingList);\r
+\r
+       SmWriteSettingList();\r
+}\r
+\r
+// 設定の追加\r
+bool SmAddSetting(SETTING *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (SmGetSetting(s->Title) != NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Insert(sm->SettingList, s);\r
+\r
+       SmWriteSettingList();\r
+\r
+       return true;\r
+}\r
+\r
+// 設定の取得\r
+SETTING *SmGetSetting(wchar_t *title)\r
+{\r
+       SETTING s;\r
+       // 引数チェック\r
+       if (title == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&s, sizeof(SETTING));\r
+       UniStrCpy(s.Title, sizeof(s.Title), title);\r
+\r
+       return (SETTING *)Search(sm->SettingList, &s);\r
+}\r
+\r
+// 接続設定の比較\r
+int SmCompareSetting(void *p1, void *p2)\r
+{\r
+       SETTING *s1, *s2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       s1 = *(SETTING **)p1;\r
+       s2 = *(SETTING **)p2;\r
+       if (s1 == NULL || s2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return UniStrCmpi(s1->Title, s2->Title);\r
+}\r
+\r
+// 設定リストの初期化\r
+void SmInitSettingList()\r
+{\r
+       sm->SettingList = NewList(SmCompareSetting);\r
+\r
+       SmLoadSettingList();\r
+\r
+       SmInitDefaultSettingList();\r
+}\r
+\r
+// 設定リストの解放\r
+void SmFreeSettingList()\r
+{\r
+       UINT i;\r
+\r
+       // 書き込み\r
+       SmWriteSettingList();\r
+\r
+       for (i = 0;i < LIST_NUM(sm->SettingList);i++)\r
+       {\r
+               SETTING *s = LIST_DATA(sm->SettingList, i);\r
+               Free(s);\r
+       }\r
+       ReleaseList(sm->SettingList);\r
+\r
+       sm->SettingList = NULL;\r
+}\r
+\r
+// 設定リストの書き込み\r
+void SmWriteSettingList()\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+\r
+       t = MsRegEnumValue(REG_CURRENT_USER, SM_SETTING_REG_KEY);\r
+       if (t != NULL)\r
+       {\r
+               // 既存のすべての値を削除する\r
+               for (i = 0;i < t->NumTokens;i++)\r
+               {\r
+                       char *name = t->Token[i];\r
+                       MsRegDeleteValue(REG_CURRENT_USER, SM_SETTING_REG_KEY, name);\r
+               }\r
+\r
+               FreeToken(t);\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(sm->SettingList);i++)\r
+       {\r
+               char name[MAX_SIZE];\r
+               SETTING *s = LIST_DATA(sm->SettingList, i);\r
+\r
+               // 書き込む\r
+               Format(name, sizeof(name), "Setting%u", i + 1);\r
+               MsRegWriteBin(REG_CURRENT_USER, SM_SETTING_REG_KEY, name, s, sizeof(SETTING));\r
+       }\r
+}\r
+\r
+// 接続リストの読み込み\r
+void SmLoadSettingList()\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       char *key_name = SM_SETTING_REG_KEY;\r
+\r
+       t = MsRegEnumValue(REG_CURRENT_USER, key_name);\r
+       if (t == NULL)\r
+       {\r
+               key_name = SM_SETTING_REG_KEY_OLD;\r
+               t = MsRegEnumValue(REG_CURRENT_USER, key_name);\r
+               if (t == NULL)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               char *name = t->Token[i];\r
+               BUF *b = MsRegReadBin(REG_CURRENT_USER, key_name, name);\r
+               if (b != NULL)\r
+               {\r
+                       if (b->Size == sizeof(SETTING))\r
+                       {\r
+                               SETTING *s = ZeroMalloc(sizeof(SETTING));\r
+                               Copy(s, b->Buf, sizeof(SETTING));\r
+\r
+                               Add(sm->SettingList, s);\r
+                       }\r
+                       FreeBuf(b);\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       Sort(sm->SettingList);\r
+}\r
+\r
+// デフォルトの設定リストの初期化\r
+void SmInitDefaultSettingList()\r
+{\r
+       if (LIST_NUM(sm->SettingList) == 0)\r
+       {\r
+               bool b = false;\r
+               LIST *pl = MsGetProcessList();\r
+\r
+               if (pl != NULL)\r
+               {\r
+                       UINT i;\r
+                       for (i = 0;i < LIST_NUM(pl);i++)\r
+                       {\r
+                               MS_PROCESS *p = LIST_DATA(pl, i);\r
+\r
+                               if (InStr(p->ExeFilename, "utvpnserver.exe") || InStr(p->ExeFilename, "utvpnserver_x64.exe") ||\r
+                                       InStr(p->ExeFilename, "utvpnserver_ia64.exe") ||\r
+                                       InStr(p->ExeFilename, "utvpnbridge.exe") || InStr(p->ExeFilename, "utvpnbridge_x64.exe") ||\r
+                                       InStr(p->ExeFilename, "utvpnbridge_ia64.exe"))\r
+                               {\r
+                                       b = true;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               MsFreeProcessList(pl);\r
+\r
+               if (b == false)\r
+               {\r
+                       if (MsIsServiceRunning(_SS("SVC_UTVPNSERVER_NAME")))\r
+                       {\r
+                               b = true;\r
+                       }\r
+               }\r
+\r
+               if (b)\r
+               {\r
+                       SETTING *s = ZeroMalloc(sizeof(SETTING));\r
+\r
+                       UniStrCpy(s->Title, sizeof(s->Title), _UU("SM_LOCALHOST"));\r
+                       s->ServerAdminMode = true;\r
+                       Hash(s->HashedPassword, "", 0, true);\r
+                       UniStrCpy(s->ClientOption.AccountName, sizeof(s->ClientOption.AccountName), s->Title);\r
+                       StrCpy(s->ClientOption.Hostname, sizeof(s->ClientOption.Hostname), "localhost");\r
+                       s->ClientOption.Port = 5555;\r
+\r
+                       Add(sm->SettingList, s);\r
+               }\r
+       }\r
+}\r
+\r
+// メインダイアログ初期化\r
+void SmMainDlgInit(HWND hWnd)\r
+{\r
+       wchar_t *last_select;\r
+       UINT i = INFINITE;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, ICO_VPNSERVER);\r
+\r
+       LvInit(hWnd, L_SETTING);\r
+       LvSetStyle(hWnd, L_SETTING, LVS_EX_GRIDLINES);\r
+       LvInsertColumn(hWnd, L_SETTING, 0, _UU("SM_MAIN_COLUMN_1"), 146);\r
+       LvInsertColumn(hWnd, L_SETTING, 1, _UU("SM_MAIN_COLUMN_2"), 130);\r
+       LvInsertColumn(hWnd, L_SETTING, 2, _UU("SM_MAIN_COLUMN_3"), 130);\r
+\r
+       SmRefreshSetting(hWnd);\r
+\r
+       last_select = MsRegReadStrW(REG_CURRENT_USER, SM_REG_KEY, "Last Select");\r
+       if (UniIsEmptyStr(last_select) == false)\r
+       {\r
+               i = LvSearchStr(hWnd, L_SETTING, 0, last_select);\r
+       }\r
+       Free(last_select);\r
+\r
+       if (i == INFINITE)\r
+       {\r
+               LvSelect(hWnd, L_SETTING, 0);\r
+       }\r
+       else\r
+       {\r
+               LvSelect(hWnd, L_SETTING, i);\r
+       }\r
+\r
+       Focus(hWnd, L_SETTING);\r
+\r
+       SmMainDlgUpdate(hWnd);\r
+}\r
+\r
+// 設定一覧の更新\r
+void SmRefreshSetting(HWND hWnd)\r
+{\r
+       SmRefreshSettingEx(hWnd, NULL);\r
+}\r
+void SmRefreshSettingEx(HWND hWnd, wchar_t *select_name)\r
+{\r
+       LVB *b;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = LvInsertStart();\r
+\r
+       for (i = 0;i < LIST_NUM(sm->SettingList);i++)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               SETTING *s = LIST_DATA(sm->SettingList, i);\r
+\r
+               if (s->ServerAdminMode)\r
+               {\r
+                       UniStrCpy(tmp, sizeof(tmp), _UU("SM_MODE_SERVER"));\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("SM_MODE_HUB"), s->HubName);\r
+               }\r
+\r
+               StrToUni(tmp2, sizeof(tmp2), s->ClientOption.Hostname);\r
+\r
+               LvInsertAdd(b,\r
+                       (s->ServerAdminMode ? ICO_SERVER_ONLINE : ICO_HUB),\r
+                       NULL,\r
+                       3,\r
+                       s->Title,\r
+                       tmp2,\r
+                       tmp);\r
+       }\r
+\r
+       LvInsertEnd(b, hWnd, L_SETTING);\r
+\r
+       if (UniIsEmptyStr(select_name) == false)\r
+       {\r
+               LvSelect(hWnd, L_SETTING, LvSearchStr(hWnd, L_SETTING, 0, select_name));\r
+       }\r
+}\r
+\r
+// メインダイアログ更新\r
+void SmMainDlgUpdate(HWND hWnd)\r
+{\r
+       bool ok = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSelected(hWnd, L_SETTING) == false)\r
+       {\r
+               ok = false;\r
+       }\r
+       if (LvIsMultiMasked(hWnd, L_SETTING))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+       SetEnable(hWnd, B_EDIT_SETTING, ok);\r
+       SetEnable(hWnd, B_DELETE, ok);\r
+}\r
+\r
+// メインウインドウプロシージャ\r
+UINT SmMainDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       NMHDR *n;\r
+       NMLVDISPINFOW *info;\r
+       NMLVKEYDOWN *key;\r
+       wchar_t *tmp;\r
+       UINT i;\r
+       wchar_t new_name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               ShowSplashEx(hWnd, "UT-VPN Server", 1300, SM_SPLASH_BORDER_COLOR);\r
+               SmMainDlgInit(hWnd);\r
+               SetTimer(hWnd, 4, 100, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 4:\r
+                       KillTimer(hWnd, 4);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       // 接続\r
+                       i = LvGetSelected(hWnd, L_SETTING);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               tmp = LvGetStr(hWnd, L_SETTING, i, 0);\r
+                               if (tmp != NULL)\r
+                               {\r
+                                       SETTING *setting = SmGetSetting(tmp);\r
+                                       if (setting != NULL)\r
+                                       {\r
+                                               SETTING s;\r
+\r
+                                               // レジストリに最後の選択として記録\r
+                                               MsRegWriteStrW(REG_CURRENT_USER, SM_REG_KEY, "Last Select", tmp);\r
+\r
+                                               // 設定コピー\r
+                                               Copy(&s, setting, sizeof(SETTING));\r
+                                               SmConnect(hWnd, &s);\r
+                                       }\r
+                                       Free(tmp);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case B_NEW_SETTING:\r
+                       // 追加\r
+                       if (SmAddSettingDlg(hWnd, new_name, sizeof(new_name)))\r
+                       {\r
+                               SmRefreshSettingEx(hWnd, new_name);\r
+                       }\r
+                       break;\r
+\r
+               case B_EDIT_SETTING:\r
+                       // 編集\r
+                       if (SmEditSettingDlg(hWnd))\r
+                       {\r
+                               SmWriteSettingList();\r
+                               SmRefreshSetting(hWnd);\r
+                       }\r
+\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       // 削除\r
+                       i = LvGetSelected(hWnd, L_SETTING);\r
+                       if (i != INFINITE)\r
+                       {\r
+                               tmp = LvGetStr(hWnd, L_SETTING, i, 0);\r
+                               if (tmp != NULL)\r
+                               {\r
+                                       if (MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2,\r
+                                               _UU("SM_SETTING_DELETE_MSG"), tmp) == IDYES)\r
+                                       {\r
+                                               SmDeleteSetting(tmp);\r
+                                               SmWriteSettingList();\r
+                                               SmRefreshSetting(hWnd);\r
+                                       }\r
+                                       Free(tmp);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case B_ABOUT:\r
+                       // バージョン情報\r
+                       ShowSplashEx(hWnd, "UT-VPN Server", 0, SM_SPLASH_BORDER_COLOR);\r
+                       break;\r
+\r
+               case B_SECURE_MANAGER:\r
+                       // スマートカードマネージャ\r
+                       SmSecureManager(hWnd);\r
+                       break;\r
+\r
+               case B_SELECT_SECURE:\r
+                       // スマートカード選択\r
+                       SmSelectSecureId(hWnd);\r
+                       break;\r
+               }\r
+\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_SETTING:\r
+                       switch (n->code)\r
+                       {\r
+                       case NM_DBLCLK:\r
+                               Command(hWnd, IDOK);\r
+                               break;\r
+\r
+                       case LVN_KEYDOWN:\r
+                               key = (NMLVKEYDOWN *)n;\r
+                               if (key != NULL)\r
+                               {\r
+                                       UINT code = key->wVKey;\r
+                                       switch (code)\r
+                                       {\r
+                                       case VK_F2:\r
+                                               if (LvIsSelected(hWnd, L_SETTING))\r
+                                               {\r
+                                                       LvRename(hWnd, L_SETTING, LvGetSelected(hWnd, L_SETTING));\r
+                                               }\r
+                                               break;\r
+\r
+                                       case VK_DELETE:\r
+                                               Command(hWnd, B_DELETE);\r
+                                               break;\r
+\r
+                                       case VK_RETURN:\r
+                                               Command(hWnd, IDOK);\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               break;\r
+\r
+                       case LVN_ENDLABELEDITW:\r
+                               // 名前の変更\r
+                               info = (NMLVDISPINFOW *)n;\r
+                               if (info->item.pszText != NULL)\r
+                               {\r
+                                       wchar_t *new_name = info->item.pszText;\r
+                                       wchar_t *old_name = LvGetStr(hWnd, L_SETTING, info->item.iItem, 0);\r
+\r
+                                       if (old_name != NULL)\r
+                                       {\r
+                                               if (UniStrCmp(new_name, old_name) != 0 && UniStrLen(new_name) != 0)\r
+                                               {\r
+                                                       // 名前変更の実行\r
+                                                       SETTING *s = SmGetSetting(old_name);\r
+                                                       if (s != NULL)\r
+                                                       {\r
+                                                               if (SmGetSetting(new_name) != NULL)\r
+                                                               {\r
+                                                                       MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("SM_SETTING_EXISTS"),\r
+                                                                               new_name);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       UniStrCpy(s->Title, sizeof(s->Title), new_name);\r
+                                                                       Sort(sm->SettingList);\r
+                                                                       SmWriteSettingList();\r
+                                                                       LvSetItem(hWnd, L_SETTING, info->item.iItem, 0, new_name);\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+\r
+                                               Free(old_name);\r
+                                       }\r
+                               }\r
+                               break;\r
+\r
+                       case LVN_ITEMCHANGED:\r
+                               SmMainDlgUpdate(hWnd);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       LvSortHander(hWnd, msg, wParam, lParam, L_SETTING);\r
+\r
+       return 0;\r
+}\r
+\r
+// メインウインドウ\r
+void SmMainDlg()\r
+{\r
+       Dialog(NULL, D_SM_MAIN, SmMainDlgProc, NULL);\r
+}\r
+\r
+// Server Manager メイン処理\r
+void MainSM()\r
+{\r
+       if (sm->TempSetting == NULL)\r
+       {\r
+               // メインウインドウを開く\r
+               SmMainDlg();\r
+       }\r
+       else\r
+       {\r
+               SmConnect(sm->hParentWnd, sm->TempSetting);\r
+       }\r
+}\r
+\r
+// 初期化\r
+void InitSM()\r
+{\r
+       if (sm != NULL)\r
+       {\r
+               // すでに初期化されている\r
+               return;\r
+       }\r
+\r
+       sm = ZeroMalloc(sizeof(SM));\r
+\r
+       InitWinUi(_UU("SM_TITLE"), _SS("DEFAULT_FONT"), _II("DEFAULT_FONT_SIZE"));\r
+\r
+       sm->Cedar = NewCedar(NULL, NULL);\r
+\r
+       SmInitSettingList();\r
+\r
+       InitCM();\r
+\r
+       // コマンドラインを解釈する\r
+       SmParseCommandLine();\r
+}\r
+\r
+// コマンドラインを解釈する\r
+void SmParseCommandLine()\r
+{\r
+       LIST *o;\r
+       CONSOLE *c = NewLocalConsole(NULL, NULL);\r
+       wchar_t *cmdline;\r
+       PARAM args[] =\r
+       {\r
+               {"[vpnserver]", NULL, NULL, NULL, NULL,},\r
+               {"HUB", NULL, NULL, NULL, NULL,},\r
+               {"PASSWORD", NULL, NULL, NULL, NULL,},\r
+               {"TITLE", NULL, NULL, NULL, NULL,},\r
+               {"HWND", NULL, NULL, NULL, NULL,},\r
+       };\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+       \r
+       cmdline = GetCommandLineUniStr();\r
+\r
+       if (UniIsEmptyStr(cmdline) == false)\r
+       {\r
+               o = ParseCommandList(c, "vpnsmgr", cmdline, args, sizeof(args) / sizeof(args[0]));\r
+               if (o != NULL)\r
+               {\r
+                       char *host;\r
+                       UINT port;\r
+\r
+                       if (ParseHostPort(GetParamStr(o, "[vpnserver]"), &host, &port, 443))\r
+                       {\r
+                               char *hub = GetParamStr(o, "HUB");\r
+                               char *password = GetParamStr(o, "PASSWORD");\r
+                               char *title = GetParamStr(o, "TITLE");\r
+                               char *hwndstr = GetParamStr(o, "HWND");\r
+\r
+                               if (hub == NULL || StrCmpi(hub, "\"") == 0)\r
+                               {\r
+                                       hub = CopyStr("");\r
+                               }\r
+                               if (password == NULL)\r
+                               {\r
+                                       password = CopyStr("");\r
+                               }\r
+                               if (title == NULL)\r
+                               {\r
+                                       title = CopyStr(host);\r
+                               }\r
+\r
+                               if (IsEmptyStr(host) == false)\r
+                               {\r
+                                       SETTING *s = ZeroMalloc(sizeof(SETTING));\r
+                                       BUF *b;\r
+                                       CLIENT_OPTION *o;\r
+\r
+                                       StrToUni(s->Title, sizeof(s->Title), title);\r
+\r
+                                       if (IsEmptyStr(hub))\r
+                                       {\r
+                                               s->ServerAdminMode = true;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               s->ServerAdminMode = false;\r
+                                               StrCpy(s->HubName, sizeof(s->HubName), hub);\r
+                                       }\r
+\r
+                                       b = StrToBin(password);\r
+                                       if (b == NULL || b->Size != SHA1_SIZE)\r
+                                       {\r
+                                               Hash(s->HashedPassword, password, StrLen(password), true);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               Copy(s->HashedPassword, b->Buf, SHA1_SIZE);\r
+                                       }\r
+                                       FreeBuf(b);\r
+\r
+                                       o = &s->ClientOption;\r
+\r
+                                       UniStrCpy(o->AccountName, sizeof(o->AccountName), s->Title);\r
+                                       StrCpy(o->Hostname, sizeof(o->Hostname), host);\r
+                                       o->Port = port;\r
+                                       o->ProxyType = PROXY_DIRECT;\r
+                                       StrCpy(o->DeviceName, sizeof(o->DeviceName), "DUMMY");\r
+\r
+                                       sm->TempSetting = s;\r
+\r
+                                       if (IsEmptyStr(hwndstr) == false)\r
+                                       {\r
+                                               sm->hParentWnd = (HWND)ToInt64(hwndstr);\r
+                                       }\r
+                               }\r
+\r
+                               Free(hwndstr);\r
+                               Free(title);\r
+                               Free(hub);\r
+                               Free(password);\r
+                               Free(host);\r
+                       }\r
+               }\r
+       }\r
+\r
+       Free(cmdline);\r
+\r
+       c->Free(c);\r
+}\r
+\r
+// 解放\r
+void FreeSM()\r
+{\r
+       if (sm == NULL)\r
+       {\r
+               // 初期化されていない\r
+               return;\r
+       }\r
+\r
+       FreeCM();\r
+\r
+       SmFreeSettingList();\r
+\r
+       ReleaseCedar(sm->Cedar);\r
+\r
+       FreeWinUi();\r
+\r
+       if (sm->TempSetting != NULL)\r
+       {\r
+               Free(sm->TempSetting);\r
+       }\r
+\r
+       Free(sm);\r
+       sm = NULL;\r
+}\r
+\r
+// Server Manager の実行\r
+void SMExec()\r
+{\r
+       InitSM();\r
+       MainSM();\r
+       FreeSM();\r
+}\r
+\r
+#endif // WIN32\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/SM.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/SM.h
new file mode 100644 (file)
index 0000000..bbd9aa3
--- /dev/null
@@ -0,0 +1,88 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// SM.h\r
+// SM.c のヘッダ\r
+\r
+#ifndef        SM_H\r
+#define        SM_H\r
+\r
+void SMExec();\r
+\r
+#endif // SM_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/SMInner.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/SMInner.h
new file mode 100644 (file)
index 0000000..5bccb32
--- /dev/null
@@ -0,0 +1,703 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// SMInner.h\r
+// SM.c の内部向けヘッダ\r
+\r
+// 定数\r
+#define        SM_REG_KEY                      "Software\\SoftEther Corporation\\UT-VPN\\Server Manager"\r
+#define        SM_CERT_REG_KEY         "Software\\SoftEther Corporation\\UT-VPN\\Server Manager\\Cert Tool"\r
+#define        SM_SETTING_REG_KEY      "Software\\SoftEther Corporation\\UT-VPN\\Server Manager\\Settings"\r
+#define        SM_LASTHUB_REG_KEY      "Software\\SoftEther Corporation\\UT-VPN\\Server Manager\\Last HUB Name"\r
+\r
+// 定数 (古い値)\r
+#define        SM_SETTING_REG_KEY_OLD  "Software\\SoftEther Corporation\\PacketiX VPN\\Server Manager\\Settings_Dummy"\r
+\r
+// スプラッシュスクリーンの枠線の色\r
+#define        SM_SPLASH_BORDER_COLOR  (RGB(72, 72, 72))\r
+\r
+// 接続設定\r
+typedef struct SETTING\r
+{\r
+       wchar_t Title[MAX_SIZE];        // 設定名\r
+       bool ServerAdminMode;           // サーバー管理モード\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       UCHAR HashedPassword[SHA1_SIZE];        // パスワード\r
+       CLIENT_OPTION ClientOption;     // クライアントオプション\r
+       UCHAR Reserved[10240 - sizeof(bool) * 7];       // 予約領域\r
+} SETTING;\r
+\r
+// 構造体宣言\r
+typedef struct SM\r
+{\r
+       CEDAR *Cedar;                           // Cedar\r
+       LIST *SettingList;                      // 設定リスト\r
+       SETTING *TempSetting;           // 仮設定\r
+       HWND hParentWnd;                        // 親ウインドウハンドル\r
+} SM;\r
+\r
+// 接続設定編集\r
+typedef struct SM_EDIT_SETTING\r
+{\r
+       bool EditMode;                          // 編集モード\r
+       SETTING *OldSetting;            // 以前の設定へのポインタ\r
+       SETTING *Setting;                       // 設定へのポインタ\r
+       bool Inited;                            // 初期済みフラグ\r
+} SM_EDIT_SETTING;\r
+\r
+// サーバー管理ダイアログ\r
+typedef struct SM_SERVER\r
+{\r
+       RPC *Rpc;                                       // RPC\r
+       char ServerName[MAX_HOST_NAME_LEN + 1]; // サーバー名\r
+       wchar_t Title[MAX_SIZE];        // タイトル\r
+       bool ServerAdminMode;           // サーバー管理モード\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+       UINT ServerType;                        // サーバーの種類\r
+       bool Bridge;                            // VPN Bridge 製品\r
+       UINT PolicyVer;                         // ポリシーバージョン\r
+       RPC_SERVER_STATUS ServerStatus; // サーバー状態\r
+       RPC_SERVER_INFO ServerInfo;             // サーバー情報\r
+       CAPSLIST *CapsList;                     // Caps リスト\r
+       bool EmptyPassword;                     // 空のパスワード\r
+       SETTING *CurrentSetting;        // 現在の接続設定\r
+       wchar_t *AdminMsg;                      // 管理者向けメッセージ\r
+} SM_SERVER;\r
+\r
+typedef void (SM_STATUS_INIT_PROC)(HWND hWnd, SM_SERVER *p, void *param);\r
+typedef bool (SM_STATUS_REFRESH_PROC)(HWND hWnd, SM_SERVER *p, void *param);\r
+\r
+// 情報表示ダイアログ\r
+typedef struct SM_STATUS\r
+{\r
+       SM_SERVER *p;                           // P へのポインタ\r
+       void *Param;                            // パラメータ\r
+       UINT Icon;                                      // アイコン\r
+       wchar_t *Caption;                       // タイトル\r
+       bool show_refresh_button;       // 更新ボタンの表示\r
+       bool NoImage;                           // イメージ無し\r
+       SM_STATUS_INIT_PROC *InitProc;\r
+       SM_STATUS_REFRESH_PROC *RefreshProc;\r
+} SM_STATUS;\r
+\r
+// 仮想 HUB 編集ダイアログ\r
+typedef struct SM_EDIT_HUB\r
+{\r
+       SM_SERVER *p;                           // P\r
+       bool EditMode;                          // 編集モード\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // HUB 名\r
+} SM_EDIT_HUB;\r
+\r
+// SSL 関係\r
+typedef struct SM_SSL\r
+{\r
+       SM_SERVER *p;                           // P\r
+       X *Cert;                                        // 証明書\r
+       K *Key;                                         // 秘密鍵\r
+       bool SetCertAndKey;                     // キーをセットする\r
+} SM_SSL;\r
+\r
+// 証明書保存\r
+typedef struct SM_SAVE_KEY_PAIR\r
+{\r
+       X *Cert;                                        // 証明書\r
+       K *Key;                                         // 秘密鍵\r
+       char *Pass;                                     // パスフレーズ\r
+} SM_SAVE_KEY_PAIR;\r
+\r
+// コネクション情報\r
+typedef struct SM_CONNECTION_INFO\r
+{\r
+       SM_SERVER *p;                           // P\r
+       char *ConnectionName;           // コネクション名\r
+} SM_CONNECTION_INFO;\r
+\r
+// HUB の管理\r
+typedef struct SM_HUB\r
+{\r
+       SM_SERVER *p;                           // P\r
+       RPC *Rpc;                                       // RPC\r
+       char *HubName;                          // HUB 名\r
+} SM_HUB;\r
+\r
+// ユーザーリスト表示\r
+typedef struct SM_USER\r
+{\r
+       SM_SERVER *p;                           // P\r
+       RPC *Rpc;                                       // RPC\r
+       SM_HUB *Hub;                            // HUB\r
+       char *GroupName;                        // グループ名でフィルタ\r
+       bool SelectMode;                        // 選択モード\r
+       char *SelectedName;                     // 選択されたユーザー名\r
+       bool AllowGroup;                        // グループの選択を許可\r
+       bool CreateNow;                         // すぐにユーザーを作成\r
+} SM_USER;\r
+\r
+// ユーザーの編集\r
+typedef struct SM_EDIT_USER\r
+{\r
+       bool Inited;                            // 初期化済みフラグ\r
+       bool EditMode;                          // 編集モード\r
+       SM_SERVER *p;                           // P\r
+       RPC *Rpc;                                       // RPC\r
+       SM_HUB *Hub;                            // HUB\r
+       RPC_SET_USER SetUser;           // ユーザー設定\r
+} SM_EDIT_USER;\r
+\r
+// ユーザー情報\r
+typedef struct SM_USER_INFO\r
+{\r
+       SM_SERVER *p;                           // P\r
+       RPC *Rpc;                                       // RPC\r
+       SM_HUB *Hub;                            // HUB\r
+       char *Username;                         // Username\r
+} SM_USER_INFO;\r
+\r
+// ポリシー\r
+typedef struct SM_POLICY\r
+{\r
+       bool Inited;                            // 初期化\r
+       POLICY *Policy;                         // ポリシー\r
+       wchar_t *Caption;                       // タイトル\r
+       bool CascadeMode;                       // カスケードモード\r
+       UINT Ver;                                       // バージョン\r
+} SM_POLICY;\r
+\r
+// グループリスト表示\r
+typedef struct SM_GROUP\r
+{\r
+       SM_SERVER *p;                           // P\r
+       RPC *Rpc;                                       // RPC\r
+       SM_HUB *Hub;                            // HUB\r
+       bool SelectMode;                        // 選択モード\r
+       char *SelectedGroupName;        // 選択されたグループ名\r
+} SM_GROUP;\r
+\r
+// グループの編集\r
+typedef struct SM_EDIT_GROUP\r
+{\r
+       bool Inited;                            // 初期化フラグ\r
+       bool EditMode;                          // 編集モード\r
+       SM_SERVER *p;                           // P\r
+       RPC *Rpc;                                       // RPC\r
+       SM_HUB *Hub;                            // HUB\r
+       RPC_SET_GROUP SetGroup;         // グループ設定\r
+} SM_EDIT_GROUP;\r
+\r
+// アクセスリスト一覧\r
+typedef struct SM_ACCESS_LIST\r
+{\r
+       RPC *Rpc;                                       // RPC\r
+       SM_HUB *Hub;                            // HUB\r
+       LIST *AccessList;                       // アクセスリスト\r
+} SM_ACCESS_LIST;\r
+\r
+// アクセスリストの編集\r
+typedef struct SM_EDIT_ACCESS\r
+{\r
+       SM_HUB *Hub;                            // HUB\r
+       bool Inited;                            // 初期化フラグ\r
+       bool EditMode;                          // 編集モード\r
+       SM_ACCESS_LIST *AccessList;     // アクセスリスト\r
+       ACCESS *Access;                         // アクセスリスト項目\r
+} SM_EDIT_ACCESS;\r
+\r
+// アクセスリストの状態表示\r
+typedef struct SM_LINK\r
+{\r
+       SM_HUB *Hub;                            // HUB\r
+       wchar_t *AccountName;           // アカウント名\r
+} SM_LINK;\r
+\r
+// セッション ステータス\r
+typedef struct SM_SESSION_STATUS\r
+{\r
+       SM_HUB *Hub;                            // HUB\r
+       char *SessionName;                      // セッション名\r
+} SM_SESSION_STATUS;\r
+\r
+// アドレステーブル\r
+typedef struct SM_TABLE\r
+{\r
+       SM_HUB *Hub;                            // HUB\r
+       RPC *Rpc;                                       // RPC\r
+       char *SessionName;                      // セッション名\r
+} SM_TABLE;\r
+\r
+// 証明書ツール\r
+typedef struct SM_CERT\r
+{\r
+       X *x;                                           // 生成された証明書\r
+       K *k;                                           // 生成された秘密鍵\r
+       X *root_x;                                      // ルート証明書\r
+       K *root_k;                                      // ルート証明書の秘密鍵\r
+       bool do_not_save;                       // ファイルに保存しない\r
+       char *default_cn;                       // デフォルトの CN\r
+} SM_CERT;\r
+\r
+// config 編集\r
+typedef struct SM_CONFIG\r
+{\r
+       SM_SERVER *s;                           // SM_SERVER\r
+       RPC_CONFIG Config;                      // Config 本体\r
+} SM_CONFIG;\r
+\r
+// hub_admin_option 編集\r
+typedef struct SM_EDIT_AO\r
+{\r
+       SM_EDIT_HUB *e;\r
+       bool CanChange;\r
+       RPC_ADMIN_OPTION CurrentOptions;\r
+       RPC_ADMIN_OPTION DefaultOptions;\r
+       bool NewMode;\r
+       char Name[MAX_ADMIN_OPTION_NAME_LEN + 1];\r
+       UINT Value;\r
+       bool ExtOption;\r
+} SM_EDIT_AO;\r
+\r
+// スイッチ編集\r
+typedef struct SM_L3SW\r
+{\r
+       SM_SERVER *s;\r
+       char *SwitchName;\r
+       bool Enable;\r
+} SM_L3SW;\r
+\r
+// スマートカードから証明書と秘密鍵の指定\r
+typedef struct SM_SECURE_KEYPAIR\r
+{\r
+       UINT Id;\r
+       bool UseCert;\r
+       bool UseKey;\r
+       char CertName[MAX_SIZE];\r
+       char KeyName[MAX_SIZE];\r
+       bool Flag;\r
+       UINT BitmapId;\r
+} SM_SECURE_KEYPAIR;\r
+\r
+// CRL 編集\r
+typedef struct SM_EDIT_CRL\r
+{\r
+       SM_HUB *s;\r
+       bool NewCrl;\r
+       UINT Key;\r
+} SM_EDIT_CRL;\r
+\r
+// AC リスト編集\r
+typedef struct SM_EDIT_AC_LIST\r
+{\r
+       SM_EDIT_HUB *s;\r
+       LIST *AcList;\r
+} SM_EDIT_AC_LIST;\r
+\r
+// AC 編集\r
+typedef struct SM_EDIT_AC\r
+{\r
+       SM_EDIT_AC_LIST *e;\r
+       UINT id;\r
+} SM_EDIT_AC;\r
+\r
+// ログファイルダウンロード\r
+typedef struct SM_READ_LOG_FILE\r
+{\r
+       HWND hWnd;\r
+       SM_SERVER *s;\r
+       char *server_name;\r
+       char *filepath;\r
+       UINT totalsize;\r
+       bool cancel_flag;\r
+       BUF *Buffer;\r
+} SM_READ_LOG_FILE;\r
+\r
+// セットアップダイアログ\r
+typedef struct SM_SETUP\r
+{\r
+       SM_SERVER *s;\r
+       RPC *Rpc;\r
+       bool IsBridge;\r
+       bool UseRemote;                 // リモートアクセス VPN\r
+       bool UseSite;                   // 拠点間接続 VPN\r
+       bool UseSiteEdge;               // 各拠点に設置する VPN Server / Bridge\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // 仮想 HUB 名\r
+       bool Flag1;\r
+       bool Flag2;\r
+} SM_SETUP;\r
+\r
+\r
+// 関数プロトタイプ\r
+void InitSM();\r
+void SmParseCommandLine();\r
+void MainSM();\r
+void FreeSM();\r
+void SmMainDlg();\r
+UINT SmMainDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmMainDlgInit(HWND hWnd);\r
+void SmMainDlgUpdate(HWND hWnd);\r
+void SmInitSettingList();\r
+void SmFreeSettingList();\r
+void SmWriteSettingList();\r
+void SmLoadSettingList();\r
+void SmInitDefaultSettingList();\r
+int SmCompareSetting(void *p1, void *p2);\r
+SETTING *SmGetSetting(wchar_t *title);\r
+bool SmAddSetting(SETTING *s);\r
+void SmDeleteSetting(wchar_t *title);\r
+bool SmCheckNewName(SETTING *s, wchar_t *new_title);\r
+void SmRefreshSetting(HWND hWnd);\r
+void SmRefreshSettingEx(HWND hWnd, wchar_t *select_name);\r
+bool SmAddSettingDlg(HWND hWnd, wchar_t *new_name, UINT new_name_size);\r
+bool SmEditSettingDlg(HWND hWnd);\r
+UINT SmEditSettingDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmEditSettingDlgInit(HWND hWnd, SM_EDIT_SETTING *p);\r
+void SmEditSettingDlgUpdate(HWND hWnd, SM_EDIT_SETTING *p);\r
+void SmEditSettingDlgOnOk(HWND hWnd, SM_EDIT_SETTING *p);\r
+void SmConnect(HWND hWnd, SETTING *s);\r
+char *SmPassword(HWND hWnd, char *server_name);\r
+UINT SmServerDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmServerDlgInit(HWND hWnd, SM_SERVER *p);\r
+void SmServerDlgUpdate(HWND hWnd, SM_SERVER *p);\r
+void SmServerDlgRefresh(HWND hWnd, SM_SERVER *p);\r
+void SmStatusDlg(HWND hWnd, SM_SERVER *p, void *param, bool no_image, bool show_refresh_button, wchar_t *caption, UINT icon,\r
+                                SM_STATUS_INIT_PROC *init, SM_STATUS_REFRESH_PROC *refresh);\r
+UINT SmStatusDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+bool SmRefreshHubStatus(HWND hWnd, SM_SERVER *p, void *param);\r
+void SmInsertTrafficInfo(LVB *b, TRAFFIC *t);\r
+bool SmCreateHubDlg(HWND hWnd, SM_SERVER *p);\r
+bool SmEditHubDlg(HWND hWnd, SM_SERVER *p, char *hubname);\r
+UINT SmEditHubProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmEditHubInit(HWND hWnd, SM_EDIT_HUB *s);\r
+void SmEditHubUpdate(HWND hWnd, SM_EDIT_HUB *s);\r
+void SmEditHubOnOk(HWND hWnd, SM_EDIT_HUB *s);\r
+bool SmCreateListenerDlg(HWND hWnd, SM_SERVER *p);\r
+UINT SmCreateListenerDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmSslDlg(HWND hWnd, SM_SERVER *p);\r
+UINT SmSslDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmSslDlgInit(HWND hWnd, SM_SSL *s);\r
+void SmSslDlgOnOk(HWND hWnd, SM_SSL *s);\r
+void SmSslDlgUpdate(HWND hWnd, SM_SSL *s);\r
+void SmGetCertInfoStr(wchar_t *str, UINT size, X *x);\r
+bool SmSaveKeyPairDlg(HWND hWnd, X *x, K *k);\r
+UINT SmSaveKeyPairDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmSaveKeyPairDlgInit(HWND hWnd, SM_SAVE_KEY_PAIR *s);\r
+void SmSaveKeyPairDlgUpdate(HWND hWnd, SM_SAVE_KEY_PAIR *s);\r
+void SmSaveKeyPairDlgOnOk(HWND hWnd, SM_SAVE_KEY_PAIR *s);\r
+bool SmRefreshServerStatus(HWND hWnd, SM_SERVER *p, void *param);\r
+bool SmRefreshServerInfo(HWND hWnd, SM_SERVER *p, void *param);\r
+void SmPrintNodeInfo(LVB *b, NODE_INFO *info);\r
+wchar_t *SmGetConnectionTypeStr(UINT type);\r
+void SmConnectionDlg(HWND hWnd, SM_SERVER *p);\r
+UINT SmConnectionDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmConnectionDlgInit(HWND hWnd, SM_SERVER *p);\r
+void SmConnectionDlgRefresh(HWND hWnd, SM_SERVER *p);\r
+void SmConnectionDlgUpdate(HWND hWnd, SM_SERVER *p);\r
+bool SmRefreshConnectionStatus(HWND hWnd, SM_SERVER *p, void *param);\r
+bool SmFarmDlg(HWND hWnd, SM_SERVER *p);\r
+UINT SmFarmDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmFarmDlgInit(HWND hWnd, SM_SERVER *p);\r
+void SmFarmDlgUpdate(HWND hWnd, SM_SERVER *p);\r
+void SmFarmDlgOnOk(HWND hWnd, SM_SERVER *p);\r
+LIST *SmStrToPortList(char *str);\r
+UINT SmFarmMemberDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmFarmMemberDlgInit(HWND hWnd, SM_SERVER *p);\r
+void SmFarmMemberDlgUpdate(HWND hWnd, SM_SERVER *p);\r
+void SmFarmMemberDlgRefresh(HWND hWnd, SM_SERVER *p);\r
+void SmFarmMemberDlgOnOk(HWND hWnd, SM_SERVER *p);\r
+void SmFarmMemberCert(HWND hWnd, SM_SERVER *p, UINT id);\r
+bool SmRefreshFarmMemberInfo(HWND hWnd, SM_SERVER *p, void *param);\r
+bool SmRefreshFarmConnectionInfo(HWND hWnd, SM_SERVER *p, void *param);\r
+UINT SmChangeServerPasswordDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmHubDlg(HWND hWnd, SM_HUB *s);\r
+UINT SmHubDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmHubDlgInit(HWND hWnd, SM_HUB *s);\r
+void SmHubDlgUpdate(HWND hWnd, SM_HUB *s);\r
+void SmHubDlgRefresh(HWND hWnd, SM_HUB *s);\r
+void SmUserListDlg(HWND hWnd, SM_HUB *s);\r
+UINT SmUserListProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmUserListInit(HWND hWnd, SM_USER *s);\r
+void SmUserListRefresh(HWND hWnd, SM_USER *s);\r
+void SmUserListUpdate(HWND hWnd, SM_USER *s);\r
+wchar_t *SmGetAuthTypeStr(UINT id);\r
+bool SmCreateUserDlg(HWND hWnd, SM_HUB *s);\r
+UINT SmEditUserDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmEditUserDlgInit(HWND hWnd, SM_EDIT_USER *s);\r
+void SmEditUserDlgUpdate(HWND hWnd, SM_EDIT_USER *s);\r
+void SmEditUserDlgOk(HWND hWnd, SM_EDIT_USER *s);\r
+bool SmPolicyDlg(HWND hWnd, POLICY *p, wchar_t *caption);\r
+bool SmPolicyDlgEx(HWND hWnd, POLICY *p, wchar_t *caption, bool cascade_mode);\r
+bool SmPolicyDlgEx2(HWND hWnd, POLICY *p, wchar_t *caption, bool cascade_mode, UINT ver);\r
+UINT SmPolicyDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmPolicyDlgInit(HWND hWnd, SM_POLICY *s);\r
+void SmPolicyDlgUpdate(HWND hWnd, SM_POLICY *s);\r
+void SmPolicyDlgOk(HWND hWnd, SM_POLICY *s);\r
+bool SmEditUserDlg(HWND hWnd, SM_HUB *s, char *username);\r
+bool SmRefreshUserInfo(HWND hWnd, SM_SERVER *s, void *param);\r
+void SmGroupListDlg(HWND hWnd, SM_HUB *s);\r
+char *SmSelectGroupDlg(HWND hWnd, SM_HUB *s, char *default_name);\r
+UINT SmGroupListDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmGroupListDlgInit(HWND hWnd, SM_GROUP *s);\r
+void SmGroupListDlgUpdate(HWND hWnd, SM_GROUP *s);\r
+void SmGroupListDlgRefresh(HWND hWnd, SM_GROUP *s);\r
+bool SmCreateGroupDlg(HWND hWnd, SM_GROUP *s);\r
+bool SmEditGroupDlg(HWND hWnd, SM_GROUP *s, char *name);\r
+UINT SmEditGroupDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmEditGroupDlgInit(HWND hWnd, SM_EDIT_GROUP *g);\r
+void SmEditGroupDlgUpdate(HWND hWnd, SM_EDIT_GROUP *g);\r
+void SmEditGroupDlgOnOk(HWND hWnd, SM_EDIT_GROUP *g);\r
+void SmUserListDlgEx(HWND hWnd, SM_HUB *s, char *groupname, bool create);\r
+void SmAccessListDlg(HWND hWnd, SM_HUB *s);\r
+UINT SmAccessListProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmAccessListInit(HWND hWnd, SM_ACCESS_LIST *s);\r
+void SmAccessListUpdate(HWND hWnd, SM_ACCESS_LIST *s);\r
+void SmAccessListRefresh(HWND hWnd, SM_ACCESS_LIST *s);\r
+bool SmAddAccess(HWND hWnd, SM_ACCESS_LIST *s, bool ipv6);\r
+bool SmEditAccess(HWND hWnd, SM_ACCESS_LIST *s, ACCESS *a);\r
+UINT SmEditAccessDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmEditAccessInit(HWND hWnd, SM_EDIT_ACCESS *s);\r
+void SmEditAccessUpdate(HWND hWnd, SM_EDIT_ACCESS *s);\r
+void SmEditAccessOnOk(HWND hWnd, SM_EDIT_ACCESS *s);\r
+UINT SmSimulationDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmSimulationUpdate(HWND hWnd, SM_EDIT_ACCESS *s);\r
+void SmSimulationInit(HWND hWnd, SM_EDIT_ACCESS *s);\r
+void SmSimulationOnOk(HWND hWnd, SM_EDIT_ACCESS *s);\r
+char *SmSelectUserDlg(HWND hWnd, SM_HUB *s, char *default_name);\r
+char *SmSelectUserDlgEx(HWND hWnd, SM_HUB *s, char *default_name, bool allow_group);\r
+void SmRadiusDlg(HWND hWnd, SM_HUB *s);\r
+UINT SmRadiusDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmRadiusDlgInit(HWND hWnd, SM_HUB *s);\r
+void SmRadiusDlgUpdate(HWND hWnd, SM_HUB *s);\r
+void SmRadiusDlgOnOk(HWND hWnd, SM_HUB *s);\r
+void SmLinkDlg(HWND hWnd, SM_HUB *s);\r
+void SmLinkDlgEx(HWND hWnd, SM_HUB *s, bool createNow);\r
+UINT SmLinkDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmLinkDlgInit(HWND hWnd, SM_HUB *s);\r
+void SmLinkDlgUpdate(HWND hWnd, SM_HUB *s);\r
+void SmLinkDlgRefresh(HWND hWnd, SM_HUB *s);\r
+bool SmLinkCreate(HWND hWnd, SM_HUB *s);\r
+bool SmLinkCreateEx(HWND hWnd, SM_HUB *s, bool connectNow);\r
+bool SmLinkEdit(HWND hWnd, SM_HUB *s, wchar_t *name);\r
+bool SmRefreshLinkStatus(HWND hWnd, SM_SERVER *s, void *param);\r
+UINT SmLogDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmLogDlgInit(HWND hWnd, SM_HUB *s);\r
+void SmLogDlgUpdate(HWND hWnd, SM_HUB *s);\r
+void SmLogDlgOnOk(HWND hWnd, SM_HUB *s);\r
+void SmCaDlg(HWND hWnd, SM_HUB *s);\r
+UINT SmCaDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmCaDlgInit(HWND hWnd, SM_HUB *s);\r
+void SmCaDlgRefresh(HWND hWnd, SM_HUB *s);\r
+void SmCaDlgUpdate(HWND hWnd, SM_HUB *s);\r
+void SmCaDlgOnOk(HWND hWnd, SM_HUB *s);\r
+bool SmCaDlgAdd(HWND hWnd, SM_HUB *s);\r
+void SmSessionDlg(HWND hWnd, SM_HUB *s);\r
+UINT SmSessionDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmSessionDlgInit(HWND hWnd, SM_HUB *s);\r
+void SmSessionDlgUpdate(HWND hWnd, SM_HUB *s);\r
+void SmSessionDlgRefresh(HWND hWnd, SM_HUB *s);\r
+bool SmRefreshSessionStatus(HWND hWnd, SM_SERVER *s, void *param);\r
+void SmMacTableDlg(HWND hWnd, SM_HUB *s, char *session_name);\r
+UINT SmMacTableDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmMacTableDlgInit(HWND hWnd, SM_TABLE *s);\r
+void SmMacTableDlgUpdate(HWND hWnd, SM_TABLE *s);\r
+void SmMacTableDlgRefresh(HWND hWnd, SM_TABLE *s);\r
+void SmIpTableDlg(HWND hWnd, SM_HUB *s, char *session_name);\r
+UINT SmIpTableDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmIpTableDlgInit(HWND hWnd, SM_TABLE *s);\r
+void SmIpTableDlgUpdate(HWND hWnd, SM_TABLE *s);\r
+void SmIpTableDlgRefresh(HWND hWnd, SM_TABLE *s);\r
+bool SmCreateCert(HWND hWnd, X **x, K **k, bool do_not_save, char *default_cn);\r
+UINT SmCreateCertDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmCreateCertDlgInit(HWND hWnd, SM_CERT *s);\r
+void SmCreateCertDlgUpdate(HWND hWnd, SM_CERT *s);\r
+void SmCreateCertDlgOnOk(HWND hWnd, SM_CERT *s);\r
+UINT SmSNATDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmSNATDlgUpdate(HWND hWnd, SM_HUB *s);\r
+void SmBridgeDlg(HWND hWnd, SM_SERVER *s);\r
+void SmInstallWinPcap(HWND hWnd, SM_SERVER *s);\r
+UINT SmBridgeDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmBridgeDlgInit(HWND hWnd, SM_SERVER *s);\r
+void SmBridgeDlgUpdate(HWND hWnd, SM_SERVER *s);\r
+void SmBridgeDlgRefresh(HWND hWnd, SM_SERVER *s);\r
+void SmBridgeDlgOnOk(HWND hWnd, SM_SERVER *s);\r
+void SmAddServerCaps(LVB *b, CAPSLIST *t);\r
+void SmConfig(HWND hWnd, SM_SERVER *s);\r
+UINT SmConfigDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmConfigDlgInit(HWND hWnd, SM_CONFIG *c);\r
+void SmHubAdminOption(HWND hWnd, SM_EDIT_HUB *e);\r
+void SmHubExtOption(HWND hWnd, SM_EDIT_HUB *e);\r
+UINT SmHubAdminOptionDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmHubAdminOptionDlgUpdate(HWND hWnd, SM_EDIT_AO *a);\r
+void SmHubAdminOptionDlgInit(HWND hWnd, SM_EDIT_AO *a);\r
+void SmHubAdminOptionDlgOk(HWND hWnd, SM_EDIT_AO *a);\r
+UINT SmHubAdminOptionValueDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmHubAdminOptionValueDlgUpdate(HWND hWnd, SM_EDIT_AO *a);\r
+void SmL3(HWND hWnd, SM_SERVER *s);\r
+UINT SmL3Dlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmL3DlgInit(HWND hWnd, SM_SERVER *s);\r
+void SmL3DlgUpdate(HWND hWnd, SM_SERVER *s);\r
+void SmL3DlgRefresh(HWND hWnd, SM_SERVER *s);\r
+UINT SmL3AddDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmL3AddDlgUpdate(HWND hWnd, SM_SERVER *s);\r
+UINT SmL3SwDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmL3SwDlgInit(HWND hWnd, SM_L3SW *w);\r
+void SmL3SwDlgUpdate(HWND hWnd, SM_L3SW *w);\r
+void SmL3SwDlgRefresh(HWND hWnd, SM_L3SW *w);\r
+UINT SmL3SwIfDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmL3SwIfDlgInit(HWND hWnd, SM_L3SW *w);\r
+void SmL3SwIfDlgUpdate(HWND hWnd, SM_L3SW *w);\r
+UINT SmL3SwTableDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmL3SwTableDlgInit(HWND hWnd, SM_L3SW *w);\r
+void SmL3SwTableDlgUpdate(HWND hWnd, SM_L3SW *w);\r
+bool SmL3IsSwActive(SM_SERVER *s, char *name);\r
+UINT SmGetCurrentSecureId(HWND hWnd);\r
+UINT SmGetCurrentSecureIdFromReg();\r
+UINT SmSelectSecureId(HWND hWnd);\r
+void SmWriteSelectSecureIdReg(UINT id);\r
+bool SmSelectKeyPair(HWND hWnd, char *cert_name, UINT cert_name_size, char *key_name, UINT key_name_size);\r
+bool SmSelectKeyPairEx(HWND hWnd, char *cert_name, UINT cert_name_size, char *key_name, UINT key_name_size, UINT bitmap_id);\r
+UINT SmSelectKeyPairDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmSelectKeyPairDlgInit(HWND hWnd, SM_SECURE_KEYPAIR *k);\r
+void SmSelectKeyPairDlgUpdate(HWND hWnd, SM_SECURE_KEYPAIR *k);\r
+void SmSelectKeyPairDlgRefresh(HWND hWnd, SM_SECURE_KEYPAIR *k);\r
+void SmSecureManager(HWND hWnd);\r
+UINT SmCrlDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmCrlDlgInit(HWND hWnd, SM_HUB *s);\r
+void SmCrlDlgUpdate(HWND hWnd, SM_HUB *s);\r
+void SmCrlDlgRefresh(HWND hWnd, SM_HUB *s);\r
+UINT SmEditCrlDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmEditCrlDlgInit(HWND hWnd, SM_EDIT_CRL *c);\r
+void SmEditCrlDlgUpdate(HWND hWnd, SM_EDIT_CRL *c);\r
+void SmEditCrlDlgOnOk(HWND hWnd, SM_EDIT_CRL *c);\r
+void SmEditCrlDlgOnLoad(HWND hWnd, SM_EDIT_CRL *c);\r
+void SmEditCrlDlgSetName(HWND hWnd, NAME *name);\r
+void SmEditCrlDlgSetSerial(HWND hWnd, X_SERIAL *serial);\r
+void SmEditCrlDlgSetHash(HWND hWnd, UCHAR *hash_md5, UCHAR *hash_sha1);\r
+void SmHubAc(HWND hWnd, SM_EDIT_HUB *s);\r
+UINT SmHubAcDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmHubAcDlgInit(HWND hWnd, SM_EDIT_AC_LIST *p);\r
+void SmHubAcDlgUpdate(HWND hWnd, SM_EDIT_AC_LIST *p);\r
+void SmHubAcDlgRefresh(HWND hWnd, SM_EDIT_AC_LIST *p);\r
+UINT SmHubEditAcDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmHubEditAcDlgInit(HWND hWnd, SM_EDIT_AC *p);\r
+void SmHubEditAcDlgUpdate(HWND hWnd, SM_EDIT_AC *p);\r
+void SmHubEditAcDlgOnOk(HWND hWnd, SM_EDIT_AC *p);\r
+UINT SmLogFileDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmLogFileDlgInit(HWND hWnd, SM_SERVER *p);\r
+void SmLogFileDlgRefresh(HWND hWnd, SM_SERVER *p);\r
+void SmLogFileDlgUpdate(HWND hWnd, SM_SERVER *p);\r
+void SmLogFileStartDownload(HWND hWnd, SM_SERVER *s, char *server_name, char *filepath, UINT totalsize);\r
+UINT SmReadLogFile(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+bool SmReadLogFileProc(DOWNLOAD_PROGRESS *g);\r
+UINT SmSaveLogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmLicense(HWND hWnd, SM_SERVER *s);\r
+UINT SmLicenseDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmLicenseDlgInit(HWND hWnd, SM_SERVER *s);\r
+void SmLicenseDlgRefresh(HWND hWnd, SM_SERVER *s);\r
+void SmLicenseDlgUpdate(HWND hWnd, SM_SERVER *s);\r
+bool SmLicenseAdd(HWND hWnd, SM_SERVER *s);\r
+UINT SmLicenseAddDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmLicenseAddDlgInit(HWND hWnd, SM_SERVER *s);\r
+void SmLicenseAddDlgUpdate(HWND hWnd, SM_SERVER *s);\r
+void SmLicenseAddDlgShiftTextItem(HWND hWnd, UINT id1, UINT id2, UINT *next_focus);\r
+void SmLicenseAddDlgGetText(HWND hWnd, char *str, UINT size);\r
+void SmLicenseAddDlgOnOk(HWND hWnd, SM_SERVER *s);\r
+bool SmSetup(HWND hWnd, SM_SERVER *s);\r
+UINT SmSetupDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmSetupDlgInit(HWND hWnd, SM_SETUP *s);\r
+void SmSetupDlgUpdate(HWND hWnd, SM_SETUP *s);\r
+void SmSetupDlgOnOk(HWND hWnd, SM_SETUP *s);\r
+UINT SmSetupHubDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmSetupHubDlgUpdate(HWND hWnd, SM_SETUP *s);\r
+bool SmSetupInit(HWND hWnd, SM_SETUP *s);\r
+bool SmSetupDeleteAllHub(HWND hWnd, SM_SETUP *s);\r
+bool SmSetupDeleteAllLocalBridge(HWND hWnd, SM_SETUP *s);\r
+bool SmSetupDeleteAllLayer3(HWND hWnd, SM_SETUP *s);\r
+bool SmSetupDeleteAllObjectInBridgeHub(HWND hWnd, SM_SETUP *s);\r
+void SmSetupStep(HWND hWnd, SM_SETUP *s);\r
+UINT SmSetupStepDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmSetupStepDlgInit(HWND hWnd, SM_SETUP *s);\r
+void SmSetupOnClose(HWND hWnd, SM_SETUP *s);\r
+bool SmSetupIsNew(SM_SERVER *s);\r
+void SmVLan(HWND hWnd, SM_SERVER *s);\r
+UINT SmVLanDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmVLanDlgInit(HWND hWnd, SM_SERVER *s);\r
+void SmVLanDlgRefresh(HWND hWnd, SM_SERVER *s);\r
+void SmVLanDlgUpdate(HWND hWnd, SM_SERVER *s);\r
+void SmHubMsg(HWND hWnd, SM_EDIT_HUB *s);\r
+UINT SmHubMsgDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void SmHubMsgDlgInit(HWND hWnd, SM_EDIT_HUB *s);\r
+void SmHubMsgDlgUpdate(HWND hWnd, SM_EDIT_HUB *s);\r
+void SmHubMsgDlgOnOk(HWND hWnd, SM_EDIT_HUB *s);\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Sam.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Sam.c
new file mode 100644 (file)
index 0000000..2edc304
--- /dev/null
@@ -0,0 +1,347 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Sam.c\r
+// セキュリティアカウントマネージャ\r
+\r
+// Windows NT の SAM を真似してかっこいい名前を付けてみたが、\r
+// 実装してみると結局大した処理はしていない。\r
+\r
+#include "CedarPch.h"\r
+\r
+// パスワードの暗号化\r
+void SecurePassword(void *secure_password, void *password, void *random)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (secure_password == NULL || password == NULL || random == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, password, SHA1_SIZE);\r
+       WriteBuf(b, random, SHA1_SIZE);\r
+       Hash(secure_password, b->Buf, b->Size, true);\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// 160bit 乱数の生成\r
+void GenRamdom(void *random)\r
+{\r
+       // 引数チェック\r
+       if (random == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Rand(random, SHA1_SIZE);\r
+}\r
+\r
+// ユーザーの匿名認証\r
+bool SamAuthUserByAnonymous(HUB *h, char *username)\r
+{\r
+       bool b = false;\r
+       // 引数チェック\r
+       if (h == NULL || username == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       AcLock(h);\r
+       {\r
+               USER *u = AcGetUser(h, username);\r
+               if (u)\r
+               {\r
+                       Lock(u->lock);\r
+                       {\r
+                               if (u->AuthType == AUTHTYPE_ANONYMOUS)\r
+                               {\r
+                                       b = true;\r
+                               }\r
+                       }\r
+                       Unlock(u->lock);\r
+               }\r
+               ReleaseUser(u);\r
+       }\r
+       AcUnlock(h);\r
+\r
+       return b;\r
+}\r
+\r
+// 指定した証明書を署名したルート証明書をリストから取得する\r
+X *GetIssuerFromList(LIST *cert_list, X *cert)\r
+{\r
+       UINT i;\r
+       X *ret = NULL;\r
+       // 引数チェック\r
+       if (cert_list == NULL || cert == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(cert_list);i++)\r
+       {\r
+               X *x = LIST_DATA(cert_list, i);\r
+               // 名前の比較\r
+               if (CheckXDateNow(x))\r
+               {\r
+                       if (CompareName(x->subject_name, cert->issuer_name))\r
+                       {\r
+                               // ルート証明書の公開鍵を取得\r
+                               K *k = GetKFromX(x);\r
+\r
+                               if (k != NULL)\r
+                               {\r
+                                       // 署名のチェック\r
+                                       if (CheckSignature(cert, k))\r
+                                       {\r
+                                               ret = x;\r
+                                       }\r
+                                       FreeK(k);\r
+                               }\r
+                       }\r
+               }\r
+               if (CompareX(x, cert))\r
+               {\r
+                       // 完全同一\r
+                       ret = x;\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザーに適用されるべきポリシーを取得\r
+POLICY *SamGetUserPolicy(HUB *h, char *username)\r
+{\r
+       POLICY *ret = NULL;\r
+       // 引数チェック\r
+       if (h == NULL || username == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       AcLock(h);\r
+       {\r
+               USER *u;\r
+               u = AcGetUser(h, username);\r
+               if (u)\r
+               {\r
+                       USERGROUP *g = NULL;\r
+                       Lock(u->lock);\r
+                       {\r
+                               if (u->Policy != NULL)\r
+                               {\r
+                                       ret = ClonePolicy(u->Policy);\r
+                               }\r
+\r
+                               g = u->Group;\r
+\r
+                               if (g != NULL)\r
+                               {\r
+                                       AddRef(g->ref);\r
+                               }\r
+                       }\r
+                       Unlock(u->lock);\r
+\r
+                       ReleaseUser(u);\r
+                       u = NULL;\r
+\r
+                       if (ret == NULL)\r
+                       {\r
+                               if (g != NULL)\r
+                               {\r
+                                       Lock(g->lock);\r
+                                       {\r
+                                               ret = ClonePolicy(g->Policy);\r
+                                       }\r
+                                       Unlock(g->lock);\r
+                               }\r
+                       }\r
+\r
+                       if (g != NULL)\r
+                       {\r
+                               ReleaseGroup(g);\r
+                       }\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザーのパスワード認証\r
+bool SamAuthUserByPassword(HUB *h, char *username, void *random, void *secure_password)\r
+{\r
+       bool b = false;\r
+       UCHAR secure_password_check[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (h == NULL || username == NULL || secure_password == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(username, ADMINISTRATOR_USERNAME) == 0)\r
+       {\r
+               // Administrator モード\r
+               SecurePassword(secure_password_check, h->SecurePassword, random);\r
+               if (Cmp(secure_password_check, secure_password, SHA1_SIZE) == 0)\r
+               {\r
+                       return true;\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       AcLock(h);\r
+       {\r
+               USER *u;\r
+               u = AcGetUser(h, username);\r
+               if (u)\r
+               {\r
+                       Lock(u->lock);\r
+                       {\r
+                               if (u->AuthType == AUTHTYPE_PASSWORD)\r
+                               {\r
+                                       AUTHPASSWORD *auth = (AUTHPASSWORD *)u->AuthData;\r
+                                       SecurePassword(secure_password_check, auth->HashedKey, random);\r
+                                       if (Cmp(secure_password_check, secure_password, SHA1_SIZE) == 0)\r
+                                       {\r
+                                               b = true;\r
+                                       }\r
+                               }\r
+                       }\r
+                       Unlock(u->lock);\r
+                       ReleaseUser(u);\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       return b;\r
+}\r
+\r
+// ユーザーが存在することを確認\r
+bool SamIsUser(HUB *h, char *username)\r
+{\r
+       bool b;\r
+       // 引数チェック\r
+       if (h == NULL || username == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       AcLock(h);\r
+       {\r
+               b = AcIsUser(h, username);\r
+       }\r
+       AcUnlock(h);\r
+\r
+       return b;\r
+}\r
+\r
+// ユーザーが使用する認証の種類を取得\r
+UINT SamGetUserAuthType(HUB *h, char *username)\r
+{\r
+       UINT authtype;\r
+       // 引数チェック\r
+       if (h == NULL || username == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       AcLock(h);\r
+       {\r
+               USER *u = AcGetUser(h, username);\r
+               if (u == NULL)\r
+               {\r
+                       authtype = INFINITE;\r
+               }\r
+               else\r
+               {\r
+                       authtype = u->AuthType;\r
+                       ReleaseUser(u);\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       return authtype;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Sam.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Sam.h
new file mode 100644 (file)
index 0000000..ccf26bb
--- /dev/null
@@ -0,0 +1,97 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Sam.h\r
+// Sam.c のヘッダ\r
+\r
+#ifndef        SAM_H\r
+#define        SAM_H\r
+\r
+\r
+// 関数プロトタイプ\r
+bool SamIsUser(HUB *h, char *username);\r
+UINT SamGetUserAuthType(HUB *h, char *username);\r
+bool SamAuthUserByPassword(HUB *h, char *username, void *random, void *secure_password);\r
+bool SamAuthUserByAnonymous(HUB *h, char *username);\r
+POLICY *SamGetUserPolicy(HUB *h, char *username);\r
+\r
+void GenRamdom(void *random);\r
+void SecurePassword(void *secure_password, void *password, void *random);\r
+X *GetIssuerFromList(LIST *cert_list, X *cert);\r
+\r
+#endif // SAM_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/SecureNAT.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/SecureNAT.c
new file mode 100644 (file)
index 0000000..66a4558
--- /dev/null
@@ -0,0 +1,189 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// SecureNAT.c\r
+// SecureNAT コード\r
+\r
+#include "CedarPch.h"\r
+\r
+// SecureNAT サーバー側スレッド\r
+void SnSecureNATThread(THREAD *t, void *param)\r
+{\r
+       SNAT *s;\r
+       CONNECTION *c;\r
+       SESSION *se;\r
+       POLICY *policy;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = (SNAT *)param;\r
+       // サーバーコネクションの作成\r
+       c = NewServerConnection(s->Cedar, NULL, t);\r
+       c->Protocol = CONNECTION_HUB_SECURE_NAT;\r
+\r
+       // デフォルトポリシーの適用\r
+       policy = ClonePolicy(GetDefaultPolicy());\r
+\r
+       // サーバーセッションの作成\r
+       se = NewServerSession(s->Cedar, c, s->Hub, SNAT_USER_NAME, policy);\r
+       se->SecureNATMode = true;\r
+       se->SecureNAT = s;\r
+       c->Session = se;\r
+       ReleaseConnection(c);\r
+\r
+       HLog(se->Hub, "LH_NAT_START", se->Name);\r
+\r
+       // ユーザー名\r
+       se->Username = CopyStr(SNAT_USER_NAME_PRINT);\r
+\r
+       s->Session = se;\r
+       AddRef(se->ref);\r
+\r
+       // 初期化完了を通知\r
+       NoticeThreadInit(t);\r
+\r
+       ReleaseCancel(s->Nat->Virtual->Cancel);\r
+       s->Nat->Virtual->Cancel = se->Cancel1;\r
+       AddRef(se->Cancel1->ref);\r
+\r
+       // セッションのメイン関数\r
+       Debug("SecureNAT Start.\n");\r
+       SessionMain(se);\r
+       Debug("SecureNAT Stop.\n");\r
+\r
+       HLog(se->Hub, "LH_NAT_STOP");\r
+\r
+       ReleaseSession(se);\r
+}\r
+\r
+// SecureNAT の解放\r
+void SnFreeSecureNAT(SNAT *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // セッション停止\r
+       StopSession(s->Session);\r
+       ReleaseSession(s->Session);\r
+\r
+       // 仮想マシン解放\r
+       Virtual_Free(s->Nat->Virtual);\r
+\r
+       // NAT 解放\r
+       NiFreeNat(s->Nat);\r
+\r
+       DeleteLock(s->lock);\r
+\r
+       Free(s);\r
+}\r
+\r
+// 新しい SecureNAT の作成\r
+SNAT *SnNewSecureNAT(HUB *h, VH_OPTION *o)\r
+{\r
+       SNAT *s;\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (h == NULL || o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       s = ZeroMalloc(sizeof(SNAT));\r
+       s->Cedar = h->Cedar;\r
+       s->Hub = h;\r
+       s->lock = NewLock();\r
+\r
+       // NAT の作成\r
+       s->Nat = NiNewNatEx(s, o);\r
+\r
+       // 仮想マシン初期化\r
+       VirtualInit(s->Nat->Virtual);\r
+\r
+       // スレッド作成\r
+       t = NewThread(SnSecureNATThread, s);\r
+       WaitThreadInit(t);\r
+       ReleaseThread(t);\r
+\r
+       return s;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/SecureNAT.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/SecureNAT.h
new file mode 100644 (file)
index 0000000..d746f05
--- /dev/null
@@ -0,0 +1,101 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// SecureNAT.h\r
+// SecureNAT.c のヘッダ\r
+\r
+#ifndef        SECURENAT_H\r
+#define        SECURENAT_H\r
+\r
+struct SNAT\r
+{\r
+       LOCK *lock;                                             // ロック\r
+       CEDAR *Cedar;                                   // Cedar\r
+       HUB *Hub;                                               // HUB\r
+       SESSION *Session;                               // セッション\r
+       POLICY *Policy;                                 // ポリシー\r
+       NAT *Nat;                                               // NAT\r
+};\r
+\r
+\r
+SNAT *SnNewSecureNAT(HUB *h, VH_OPTION *o);\r
+void SnFreeSecureNAT(SNAT *s);\r
+void SnSecureNATThread(THREAD *t, void *param);\r
+\r
+\r
+#endif // SECURENAT_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Server.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Server.c
new file mode 100644 (file)
index 0000000..5d83a9f
--- /dev/null
@@ -0,0 +1,9239 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Server.c\r
+// サーバーマネージャ\r
+\r
+#include "CedarPch.h"\r
+\r
+static SERVER *server = NULL;\r
+static LOCK *server_lock = NULL;\r
+char *SERVER_CONFIG_FILE_NAME = "@vpn_server.config";\r
+char *BRIDGE_CONFIG_FILE_NAME = "@vpn_bridge.config";\r
+\r
+static bool server_reset_setting = false;\r
+\r
+// VPN Server に登録されているユーザーオブジェクト数が多すぎるかどうか取得\r
+bool SiTooManyUserObjectsInServer(SERVER *s, bool oneMore)\r
+{\r
+       LICENSE_STATUS st;\r
+       UINT num;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       num = SiGetServerNumUserObjects(s);\r
+\r
+       Zero(&st, sizeof(st));\r
+\r
+       LiParseCurrentLicenseStatus(s->LicenseSystem, &st);\r
+\r
+       if (st.NumUserLicense == INFINITE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (oneMore)\r
+       {\r
+               st.NumUserLicense++;\r
+       }\r
+\r
+       if (st.NumUserLicense <= num)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// VPN Server に登録されているユーザーオブジェクト数を取得\r
+UINT SiGetServerNumUserObjects(SERVER *s)\r
+{\r
+       CEDAR *c;\r
+       UINT ret = 0;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       c = s->Cedar;\r
+\r
+       LockList(c->HubList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(c->HubList);i++)\r
+               {\r
+                       HUB *h = LIST_DATA(c->HubList, i);\r
+\r
+                       if (h->HubDb != NULL)\r
+                       {\r
+                               ret += LIST_NUM(h->HubDb->UserList);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(c->HubList);\r
+\r
+       return ret;\r
+}\r
+\r
+\r
+typedef struct SI_DEBUG_PROC_LIST\r
+{\r
+       UINT Id;\r
+       char *Description;\r
+       char *Args;\r
+       SI_DEBUG_PROC *Proc;\r
+} SI_DEBUG_PROC_LIST;\r
+\r
+// デバッグ機能\r
+UINT SiDebug(SERVER *s, RPC_TEST *ret, UINT i, char *str)\r
+{\r
+       SI_DEBUG_PROC_LIST proc_list[] =\r
+       {\r
+               {1, "Hello World", "<test string>", SiDebugProcHelloWorld},\r
+               {2, "Terminate process now", "", SiDebugProcExit},\r
+               {3, "Write memory dumpfile", "", SiDebugProcDump},\r
+               {4, "Restore process priority", "", SiDebugProcRestorePriority},\r
+               {5, "Set the process priority high", "", SiDebugProcSetHighPriority},\r
+               {6, "Get the .exe filename of the process", "", SiDebugProcGetExeFileName},\r
+               {7, "Crash the process", "", SiDebugProcCrash},\r
+       };\r
+       UINT num_proc_list = sizeof(proc_list) / sizeof(proc_list[0]);\r
+       UINT j;\r
+       UINT ret_value = ERR_NO_ERROR;\r
+       // 引数チェック\r
+       if (s == NULL || ret == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       if (i == 0)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               Zero(ret, sizeof(RPC_TEST));\r
+\r
+               StrCat(ret->StrValue, sizeof(ret->StrValue),\r
+                       "\n--- Debug Functions List --\n");\r
+\r
+               for (j = 0;j < num_proc_list;j++)\r
+               {\r
+                       SI_DEBUG_PROC_LIST *p = &proc_list[j];\r
+\r
+                       if (IsEmptyStr(p->Args) == false)\r
+                       {\r
+                               Format(tmp, sizeof(tmp),\r
+                                       " %u: %s - Usage: %u /ARGS:\"%s\"\n",\r
+                                       p->Id, p->Description, p->Id, p->Args);\r
+                       }\r
+                       else\r
+                       {\r
+                               Format(tmp, sizeof(tmp),\r
+                                       " %u: %s - Usage: %u\n",\r
+                                       p->Id, p->Description, p->Id);\r
+                       }\r
+\r
+                       StrCat(ret->StrValue, sizeof(ret->StrValue), tmp);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               ret_value = ERR_NOT_SUPPORTED;\r
+\r
+               for (j = 0;j < num_proc_list;j++)\r
+               {\r
+                       SI_DEBUG_PROC_LIST *p = &proc_list[j];\r
+\r
+                       if (p->Id == i)\r
+                       {\r
+                               ret_value = p->Proc(s, str, ret->StrValue, sizeof(ret->StrValue));\r
+\r
+                               if (ret_value == ERR_NO_ERROR && IsEmptyStr(ret->StrValue))\r
+                               {\r
+                                       StrCpy(ret->StrValue, sizeof(ret->StrValue), "Ok.");\r
+                               }\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return ret_value;\r
+}\r
+UINT SiDebugProcHelloWorld(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || in_str == NULL || ret_str == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       Format(ret_str, ret_str_size, "Hello World %s\n", in_str);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+UINT SiDebugProcExit(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || in_str == NULL || ret_str == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       _exit(1);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+UINT SiDebugProcDump(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || in_str == NULL || ret_str == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       MsWriteMinidump(NULL, NULL);\r
+#else  // OS_WIN32\r
+       return ERR_NOT_SUPPORTED;\r
+#endif // OS_WIN32\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+UINT SiDebugProcRestorePriority(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || in_str == NULL || ret_str == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       OSRestorePriority();\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+UINT SiDebugProcSetHighPriority(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || in_str == NULL || ret_str == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       OSSetHighPriority();\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+UINT SiDebugProcGetExeFileName(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || in_str == NULL || ret_str == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       GetExeName(ret_str, ret_str_size);\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+UINT SiDebugProcCrash(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || in_str == NULL || ret_str == NULL)\r
+       {\r
+               return ERR_INVALID_PARAMETER;\r
+       }\r
+\r
+       CrashNow();\r
+\r
+       return ERR_NO_ERROR;\r
+}\r
+\r
+// デバッグログの書き込み\r
+void SiDebugLog(SERVER *s, char *msg)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || msg == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->DebugLog != NULL)\r
+       {\r
+               WriteTinyLog(s->DebugLog, msg);\r
+       }\r
+}\r
+\r
+// デッドロック検査メイン\r
+void SiCheckDeadLockMain(SERVER *s, UINT timeout)\r
+{\r
+       CEDAR *cedar;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Debug("SiCheckDeadLockMain Start.\n");\r
+\r
+       cedar = s->Cedar;\r
+\r
+       if (s->ServerListenerList != NULL)\r
+       {\r
+               CheckDeadLock(s->ServerListenerList->lock, timeout, "s->ServerListenerList->lock");\r
+       }\r
+\r
+       CheckDeadLock(s->lock, timeout, "s->lock");\r
+\r
+       if (s->FarmMemberList != NULL)\r
+       {\r
+               CheckDeadLock(s->FarmMemberList->lock, timeout, "s->FarmMemberList->lock");\r
+       }\r
+\r
+       if (s->HubCreateHistoryList != NULL)\r
+       {\r
+               CheckDeadLock(s->HubCreateHistoryList->lock, timeout, "s->HubCreateHistoryList->lock");\r
+       }\r
+\r
+       CheckDeadLock(s->CapsCacheLock, timeout, "s->CapsCacheLock");\r
+\r
+       CheckDeadLock(s->TasksFromFarmControllerLock, timeout, "s->TasksFromFarmControllerLock");\r
+\r
+       if (cedar != NULL)\r
+       {\r
+               if (cedar->HubList != NULL)\r
+               {\r
+                       CheckDeadLock(cedar->HubList->lock, timeout, "cedar->HubList->lock");\r
+               }\r
+\r
+               if (cedar->ListenerList != NULL)\r
+               {\r
+                       UINT i;\r
+                       LIST *o = NewListFast(NULL);\r
+\r
+                       CheckDeadLock(cedar->ListenerList->lock, timeout, "cedar->ListenerList->lock");\r
+\r
+                       LockList(cedar->ListenerList);\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(cedar->ListenerList);i++)\r
+                               {\r
+                                       LISTENER *r = LIST_DATA(cedar->ListenerList, i);\r
+\r
+                                       AddRef(r->ref);\r
+\r
+                                       Add(o, r);\r
+                               }\r
+                       }\r
+                       UnlockList(cedar->ListenerList);\r
+\r
+                       for (i = 0;i < LIST_NUM(o);i++)\r
+                       {\r
+                               LISTENER *r = LIST_DATA(o, i);\r
+\r
+                               ReleaseListener(r);\r
+                       }\r
+\r
+                       ReleaseList(o);\r
+               }\r
+\r
+               if (cedar->ConnectionList != NULL)\r
+               {\r
+                       CheckDeadLock(cedar->ConnectionList->lock, timeout, "cedar->ConnectionList->lock");\r
+               }\r
+\r
+               if (cedar->CaList != NULL)\r
+               {\r
+                       CheckDeadLock(cedar->CaList->lock, timeout, "cedar->CaList->lock");\r
+               }\r
+\r
+               if (cedar->TrafficLock != NULL)\r
+               {\r
+                       CheckDeadLock(cedar->TrafficLock, timeout, "cedar->TrafficLock");\r
+               }\r
+\r
+               if (cedar->TrafficDiffList != NULL)\r
+               {\r
+                       CheckDeadLock(cedar->TrafficDiffList->lock, timeout, "cedar->TrafficDiffList->lock");\r
+               }\r
+\r
+               if (cedar->LocalBridgeList != NULL)\r
+               {\r
+                       CheckDeadLock(cedar->LocalBridgeList->lock, timeout, "cedar->LocalBridgeList->lock");\r
+               }\r
+\r
+               if (cedar->L3SwList != NULL)\r
+               {\r
+                       CheckDeadLock(cedar->L3SwList->lock, timeout, "cedar->L3SwList->lock");\r
+               }\r
+       }\r
+\r
+       Debug("SiCheckDeadLockMain Finish.\n");\r
+}\r
+\r
+// デッドロックチェックスレッド\r
+void SiDeadLockCheckThread(THREAD *t, void *param)\r
+{\r
+       SERVER *s = (SERVER *)param;\r
+       // 引数チェック\r
+       if (s == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               Wait(s->DeadLockWaitEvent, SERVER_DEADLOCK_CHECK_SPAN);\r
+\r
+               if (s->HaltDeadLockThread)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               SiCheckDeadLockMain(s, SERVER_DEADLOCK_CHECK_TIMEOUT);\r
+       }\r
+}\r
+\r
+// デッドロックチェックの初期化\r
+void SiInitDeadLockCheck(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (s->DisableDeadLockCheck)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s->HaltDeadLockThread = false;\r
+       s->DeadLockWaitEvent = NewEvent();\r
+       s->DeadLockCheckThread = NewThread(SiDeadLockCheckThread, s);\r
+}\r
+\r
+// デッドロックチェックの解放\r
+void SiFreeDeadLockCheck(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->DeadLockCheckThread == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s->HaltDeadLockThread = true;\r
+       Set(s->DeadLockWaitEvent);\r
+\r
+       WaitThread(s->DeadLockCheckThread, INFINITE);\r
+\r
+       ReleaseThread(s->DeadLockCheckThread);\r
+       s->DeadLockCheckThread = NULL;\r
+\r
+       ReleaseEvent(s->DeadLockWaitEvent);\r
+       s->DeadLockWaitEvent = NULL;\r
+\r
+       s->HaltDeadLockThread = false;\r
+}\r
+\r
+// 指定した仮想 HUB が作成履歴に登録されているかどうか調べる\r
+bool SiIsHubRegistedOnCreateHistory(SERVER *s, char *name)\r
+{\r
+       UINT i;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (s == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       SiDeleteOldHubCreateHistory(s);\r
+\r
+       LockList(s->HubCreateHistoryList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(s->HubCreateHistoryList);i++)\r
+               {\r
+                       SERVER_HUB_CREATE_HISTORY *h = LIST_DATA(s->HubCreateHistoryList, i);\r
+\r
+                       if (StrCmpi(h->HubName, name) == 0)\r
+                       {\r
+                               ret = true;\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(s->HubCreateHistoryList);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 HUB 作成履歴の削除\r
+void SiDelHubCreateHistory(SERVER *s, char *name)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(s->HubCreateHistoryList);\r
+       {\r
+               SERVER_HUB_CREATE_HISTORY *hh = NULL;\r
+               for (i = 0;i < LIST_NUM(s->HubCreateHistoryList);i++)\r
+               {\r
+                       SERVER_HUB_CREATE_HISTORY *h = LIST_DATA(s->HubCreateHistoryList, i);\r
+\r
+                       if (StrCmpi(h->HubName, name) == 0)\r
+                       {\r
+                               Delete(s->HubCreateHistoryList, h);\r
+                               Free(h);\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(s->HubCreateHistoryList);\r
+\r
+       SiDeleteOldHubCreateHistory(s);\r
+}\r
+\r
+// 仮想 HUB 作成履歴への登録\r
+void SiAddHubCreateHistory(SERVER *s, char *name)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(s->HubCreateHistoryList);\r
+       {\r
+               SERVER_HUB_CREATE_HISTORY *hh = NULL;\r
+               for (i = 0;i < LIST_NUM(s->HubCreateHistoryList);i++)\r
+               {\r
+                       SERVER_HUB_CREATE_HISTORY *h = LIST_DATA(s->HubCreateHistoryList, i);\r
+\r
+                       if (StrCmpi(h->HubName, name) == 0)\r
+                       {\r
+                               hh = h;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               if (hh == NULL)\r
+               {\r
+                       hh = ZeroMalloc(sizeof(SERVER_HUB_CREATE_HISTORY));\r
+                       StrCpy(hh->HubName, sizeof(hh->HubName), name);\r
+\r
+                       Add(s->HubCreateHistoryList, hh);\r
+               }\r
+\r
+               hh->CreatedTime = Tick64();\r
+       }\r
+       UnlockList(s->HubCreateHistoryList);\r
+\r
+       SiDeleteOldHubCreateHistory(s);\r
+}\r
+\r
+// 古くなった仮想 HUB 作成履歴の削除\r
+void SiDeleteOldHubCreateHistory(SERVER *s)\r
+{\r
+       UINT i;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(s->HubCreateHistoryList);\r
+       {\r
+               o = NewListFast(NULL);\r
+\r
+               for (i = 0;i < LIST_NUM(s->HubCreateHistoryList);i++)\r
+               {\r
+                       SERVER_HUB_CREATE_HISTORY *h = LIST_DATA(s->HubCreateHistoryList, i);\r
+\r
+                       if ((h->CreatedTime + ((UINT64)TICKET_EXPIRES)) <= Tick64())\r
+                       {\r
+                               // 有効期限切れ\r
+                               Add(o, h);\r
+                       }\r
+               }\r
+\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       SERVER_HUB_CREATE_HISTORY *h = LIST_DATA(o, i);\r
+\r
+                       Delete(s->HubCreateHistoryList, h);\r
+\r
+                       Free(h);\r
+               }\r
+\r
+               ReleaseList(o);\r
+       }\r
+       UnlockList(s->HubCreateHistoryList);\r
+}\r
+\r
+// 仮想 HUB 作成履歴の初期化\r
+void SiInitHubCreateHistory(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s->HubCreateHistoryList = NewList(NULL);\r
+}\r
+\r
+// 仮想 HUB 作成履歴の解放\r
+void SiFreeHubCreateHistory(SERVER *s)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(s->HubCreateHistoryList);i++)\r
+       {\r
+               SERVER_HUB_CREATE_HISTORY *h = LIST_DATA(s->HubCreateHistoryList, i);\r
+\r
+               Free(h);\r
+       }\r
+\r
+       ReleaseList(s->HubCreateHistoryList);\r
+\r
+       s->HubCreateHistoryList = NULL;\r
+}\r
+\r
+// Admin Pack のインストーラ作成キットで作成した VPN Client が\r
+// 接続可能なサーバーかどうか判別\r
+bool IsAdminPackSupportedServerProduct(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return true;\r
+\r
+#if    0\r
+       // SoftEther UT-VPN ではこの制限はなくなった\r
+       if (SearchStrEx(name, "home", 0, false) != INFINITE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (SearchStrEx(name, "soho", 0, false) != INFINITE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (SearchStrEx(name, "small business", 0, false) != INFINITE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (SearchStrEx(name, "standard", 0, false) != INFINITE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+#endif\r
+}\r
+\r
+\r
+// Server スナップショットの初期化\r
+void InitServerSnapshot(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->Cedar->Bridge)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s->SnapshotLogger = NewLog(CE_SNAPSHOT_DIR_NAME, CE_SNAPSHOT_PREFIX, LOG_SWITCH_MONTH);\r
+       s->LastSnapshotTime = SystemTime64();\r
+       s->HaltSnapshot = false;\r
+       s->SnapshotHaltEvent = NewEvent();\r
+       s->SnapshotThread = NewThread(ServerSnapshotThread, s);\r
+       s->SnapshotInited = true;\r
+}\r
+\r
+// Server スナップショットの解放\r
+void FreeServerSnapshot(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (s->SnapshotInited == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s->HaltSnapshot = true;\r
+       Set(s->SnapshotHaltEvent);\r
+\r
+       WaitThread(s->SnapshotThread, INFINITE);\r
+       ReleaseThread(s->SnapshotThread);\r
+\r
+       FreeLog(s->SnapshotLogger);\r
+       ReleaseEvent(s->SnapshotHaltEvent);\r
+}\r
+\r
+// スナップショットをバッファに書き出す\r
+BUF *ServerSnapshotToBuf(SERVER_SNAPSHOT *t)\r
+{\r
+       BUF *b = NewBuf();\r
+       char tmp[MAX_SIZE * 3];\r
+       char tmp2[MAX_SIZE];\r
+       UCHAR hash[SHA1_SIZE];\r
+       UCHAR hash2[SHA1_SIZE];\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       WriteBufLine(b, "------------------------------------------------------");\r
+       WriteBufLine(b, "[RECORD_INFO]");\r
+\r
+       GetDateTimeStr64(tmp2, sizeof(tmp2), SystemToLocal64(t->DateTime));\r
+       Format(tmp, sizeof(tmp), "DATETIME: %s", tmp2);\r
+       WriteBufLine(b, tmp);\r
+\r
+       IPToStr(tmp2, sizeof(tmp2), &t->ServerIp);\r
+       Format(tmp, sizeof(tmp), "SERVER_IP: %s", tmp2);\r
+       WriteBufLine(b, tmp);\r
+\r
+       Format(tmp, sizeof(tmp), "SERVER_HOSTNAME: %s", t->ServerHostname);\r
+       WriteBufLine(b, tmp);\r
+\r
+       Format(tmp, sizeof(tmp), "SERVER_PRODUCT: %s", t->ServerProduct);\r
+       WriteBufLine(b, tmp);\r
+\r
+       Format(tmp, sizeof(tmp), "SERVER_VERSION: %s", t->ServerVersion);\r
+       WriteBufLine(b, tmp);\r
+\r
+       Format(tmp, sizeof(tmp), "SERVER_BUILD: %s", t->ServerBuild);\r
+       WriteBufLine(b, tmp);\r
+\r
+       Format(tmp, sizeof(tmp), "SERVER_OS: %s", t->ServerOs);\r
+       WriteBufLine(b, tmp);\r
+\r
+       Format(tmp, sizeof(tmp), "SERVER_LICENSE_ID: %I64u", t->ServerLicenseId);\r
+       WriteBufLine(b, tmp);\r
+\r
+       if (t->ServerLicenseExpires != 0)\r
+       {\r
+               GetDateTimeStr64(tmp2, sizeof(tmp2), SystemToLocal64(t->ServerLicenseExpires));\r
+       }\r
+       else\r
+       {\r
+               StrCpy(tmp2, sizeof(tmp2), "None");\r
+       }\r
+       Format(tmp, sizeof(tmp), "SERVER_LICENSE_EXPIRES: %s", tmp2);\r
+       WriteBufLine(b, tmp);\r
+\r
+       Format(tmp, sizeof(tmp), "SERVER_TYPE: %u", t->ServerType);\r
+       WriteBufLine(b, tmp);\r
+\r
+       GetDateTimeStr64(tmp2, sizeof(tmp), SystemToLocal64(t->ServerStartupDatetime));\r
+       Format(tmp, sizeof(tmp), "SERVER_STARTUP_DATETIME: %s", tmp2);\r
+       WriteBufLine(b, tmp);\r
+\r
+       Format(tmp, sizeof(tmp), "NUMBER_OF_CLUSTER_NODES: %u", t->NumClusterNodes);\r
+       WriteBufLine(b, tmp);\r
+\r
+       Format(tmp, sizeof(tmp), "NUMBER_OF_HUBS: %u", LIST_NUM(t->HubList));\r
+       WriteBufLine(b, tmp);\r
+\r
+       for (i = 0;i < LIST_NUM(t->HubList);i++)\r
+       {\r
+               HUB_SNAPSHOT *h = LIST_DATA(t->HubList, i);\r
+               Format(tmp, sizeof(tmp), "[HUB%u]", i);\r
+               WriteBufLine(b, tmp);\r
+\r
+               Format(tmp, sizeof(tmp), "HUB_NAME: %s", h->HubName);\r
+               WriteBufLine(b, tmp);\r
+\r
+               Format(tmp, sizeof(tmp), "HUB_STATUS: %s",\r
+                       h->HubStatus ? "Online" : "Offline");\r
+               WriteBufLine(b, tmp);\r
+\r
+               Format(tmp, sizeof(tmp), "HUB_MAX_SESSIONS_CLIENT: %u",\r
+                       h->HubMaxSessionsClient);\r
+               WriteBufLine(b, tmp);\r
+\r
+               Format(tmp, sizeof(tmp), "HUB_MAX_SESSIONS_BRIDGE: %u",\r
+                       h->HubMaxSessionsBridge);\r
+               WriteBufLine(b, tmp);\r
+       }\r
+\r
+       // ハッシュ計算\r
+       HashSha1(hash, b->Buf, b->Size);\r
+       HashSha1(hash2, hash, sizeof(hash));\r
+\r
+       WriteBufLine(b, "[DIGITAL_SIGNATURE]");\r
+       BinToStr(tmp2, sizeof(tmp2), hash2, sizeof(hash2));\r
+       Format(tmp, sizeof(tmp), "SIGNATURE: %s", tmp2);\r
+       WriteBufLine(b, tmp);\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       return b;\r
+}\r
+\r
+// スナップショットのログを書き込む\r
+void WriteServerSnapshotLog(SERVER *s, SERVER_SNAPSHOT *t)\r
+{\r
+       BUF *b;\r
+       LOG *g;\r
+       // 引数チェック\r
+       if (s == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = ServerSnapshotToBuf(t);\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       g = s->SnapshotLogger;\r
+\r
+       WriteMultiLineLog(g, b);\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// Server スナップショットスレッド\r
+void ServerSnapshotThread(THREAD *t, void *param)\r
+{\r
+       SERVER *s;\r
+       UINT64 last_check_license = 0;\r
+       LICENSE_STATUS license;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = (SERVER *)param;\r
+\r
+       Zero(&license, sizeof(license));\r
+\r
+       while (true)\r
+       {\r
+               UINT64 now;\r
+               if (s->HaltSnapshot)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               if (last_check_license == 0 || (last_check_license + (UINT64)(CE_SNAPSHOT_POLLING_INTERVAL_LICENSE)) <= Tick64())\r
+               {\r
+                       last_check_license = Tick64();\r
+\r
+                       LiParseCurrentLicenseStatus(s->LicenseSystem, &license);\r
+               }\r
+\r
+               if (license.CarrierEdition)\r
+               {\r
+                       now = SystemTime64();\r
+\r
+                       if ((s->LastSnapshotTime / CE_SNAPSHOT_INTERVAL) !=\r
+                               (now / CE_SNAPSHOT_INTERVAL))\r
+                       {\r
+                               SERVER_SNAPSHOT t;\r
+                               if (MakeServerSnapshot(s, 0, &t))\r
+                               {\r
+                                       s->LastSnapshotTime = now;\r
+                                       WriteServerSnapshotLog(s, &t);\r
+\r
+                                       FreeSnapshot(&t);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               Wait(s->SnapshotHaltEvent, CE_SNAPSHOT_POLLING_INTERVAL);\r
+       }\r
+}\r
+\r
+// Server のスナップショットの保存\r
+bool MakeServerSnapshot(SERVER *s, UINT64 now, SERVER_SNAPSHOT *t)\r
+{\r
+       LICENSE_STATUS license;\r
+       OS_INFO *os = GetOsInfo();\r
+       CEDAR *cedar;\r
+       HUB **hubs;\r
+       UINT i, num_hubs;\r
+       // 引数チェック\r
+       if (s == NULL || t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (now == 0)\r
+       {\r
+               now = SystemTime64();\r
+       }\r
+\r
+       cedar = s->Cedar;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&license, sizeof(license));\r
+       LiParseCurrentLicenseStatus(s->LicenseSystem, &license);\r
+\r
+       if (license.CarrierEdition == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       now = (now / CE_SNAPSHOT_INTERVAL) * CE_SNAPSHOT_INTERVAL;\r
+\r
+       t->DateTime = now;\r
+       GetMachineIp(&t->ServerIp);\r
+       GetMachineName(t->ServerHostname, sizeof(t->ServerHostname));\r
+       StrCpy(t->ServerProduct, sizeof(t->ServerProduct), license.EditionStr);\r
+       t->ServerLicenseId = license.SystemId;\r
+       t->ServerLicenseExpires = license.Expires;\r
+       t->ServerType = s->ServerType;\r
+       if (t->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               LockList(s->FarmMemberList);\r
+               {\r
+                       t->NumClusterNodes = LIST_NUM(s->FarmMemberList);\r
+               }\r
+               UnlockList(s->FarmMemberList);\r
+       }\r
+\r
+       StrCpy(t->ServerVersion, sizeof(t->ServerVersion), s->Cedar->VerString);\r
+       StrCpy(t->ServerBuild, sizeof(t->ServerBuild), s->Cedar->BuildInfo);\r
+       Format(t->ServerOs, sizeof(t->ServerOs),\r
+               "%s %s %s",\r
+               os->OsVendorName, os->OsProductName, os->OsVersion);\r
+\r
+       t->ServerStartupDatetime = s->StartTime;\r
+\r
+       LockList(cedar->HubList);\r
+       {\r
+               num_hubs = LIST_NUM(cedar->HubList);\r
+               hubs = ZeroMalloc(sizeof(HUB *) * num_hubs);\r
+\r
+               for (i = 0;i < num_hubs;i++)\r
+               {\r
+                       HUB *h = LIST_DATA(cedar->HubList, i);\r
+                       hubs[i] = h;\r
+\r
+                       AddRef(h->ref);\r
+               }\r
+       }\r
+       UnlockList(cedar->HubList);\r
+\r
+       t->HubList = NewListFast(NULL);\r
+\r
+       for (i = 0;i < num_hubs;i++)\r
+       {\r
+               HUB *h = hubs[i];\r
+               UINT client, bridge;\r
+               HUB_SNAPSHOT *sn;\r
+\r
+               client = GetHubAdminOption(h, "max_sessions_client");\r
+               bridge = GetHubAdminOption(h, "max_sessions_bridge");\r
+\r
+               sn = ZeroMalloc(sizeof(HUB_SNAPSHOT));\r
+               sn->HubMaxSessionsClient = client;\r
+               sn->HubMaxSessionsBridge = bridge;\r
+               StrCpy(sn->HubName, sizeof(sn->HubName), h->Name);\r
+               sn->HubStatus = h->Offline ? false : true;\r
+\r
+               Insert(t->HubList, sn);\r
+\r
+               ReleaseHub(h);\r
+       }\r
+\r
+       Free(hubs);\r
+\r
+       return true;\r
+}\r
+\r
+// スナップショットの解放\r
+void FreeSnapshot(SERVER_SNAPSHOT *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(t->HubList);i++)\r
+       {\r
+               HUB_SNAPSHOT *h = LIST_DATA(t->HubList, i);\r
+\r
+               Free(h);\r
+       }\r
+\r
+       ReleaseList(t->HubList);\r
+\r
+       Zero(t, sizeof(SERVER_SNAPSHOT));\r
+}\r
+\r
+// サーバーの現在のライセンスステータスを取得する\r
+void SiGetServerLicenseStatus(SERVER *s, LICENSE_STATUS *st)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->LicenseSystem == NULL || s->LicenseSystem->Status == NULL)\r
+       {\r
+               Zero(st, sizeof(LICENSE_STATUS));\r
+               return;\r
+       }\r
+\r
+       Copy(st, s->LicenseSystem->Status, sizeof(LICENSE_STATUS));\r
+}\r
+\r
+// サーバー製品名を取得する\r
+void GetServerProductName(SERVER *s, char *name, UINT size)\r
+{\r
+       char *cpu;\r
+       // 引数チェック\r
+       if (s == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetServerProductNameInternal(s, name, size);\r
+\r
+#ifdef CPU_64\r
+       cpu = " (64 bit)";\r
+#else  // CPU_64\r
+       cpu = " (32 bit)";\r
+#endif // CPU_64\r
+\r
+       StrCat(name, size, cpu);\r
+}\r
+void GetServerProductNameInternal(SERVER *s, char *name, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef BETA_NUMBER\r
+       if (s->Cedar->Bridge)\r
+       {\r
+               StrCpy(name, size, CEDAR_BRIDGE_STR);\r
+       }\r
+       else\r
+       {\r
+               StrCpy(name, size, CEDAR_BETA_SERVER);\r
+       }\r
+       return;\r
+#else  // BETA_NUMBER\r
+       if (s->Cedar->Bridge)\r
+       {\r
+               StrCpy(name, size, CEDAR_BRIDGE_STR);\r
+       }\r
+       else\r
+       {\r
+               LICENSE_STATUS st;\r
+\r
+               LiParseCurrentLicenseStatus(s->LicenseSystem, &st);\r
+\r
+               StrCpy(name, size, st.EditionStr);\r
+       }\r
+#endif // BETA_NUMBER\r
+}\r
+\r
+// ログファイル列挙を結合する\r
+void AdjoinEnumLogFile(LIST *o, LIST *src)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(src);i++)\r
+       {\r
+               LOG_FILE *f = LIST_DATA(src, i);\r
+\r
+               Insert(o, Clone(f, sizeof(LOG_FILE)));\r
+       }\r
+}\r
+\r
+// 指定した名前のログファイルが列挙リストに入っているかどうか確認する\r
+bool CheckLogFileNameFromEnumList(LIST *o, char *name, char *server_name)\r
+{\r
+       LOG_FILE t;\r
+       // 引数チェック\r
+       if (o == NULL || name == NULL || server_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       StrCpy(t.Path, sizeof(t.Path), name);\r
+       StrCpy(t.ServerName, sizeof(t.ServerName), server_name);\r
+\r
+       if (Search(o, &t) == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ログファイル列挙を解放する\r
+void FreeEnumLogFile(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               LOG_FILE *f = LIST_DATA(o, i);\r
+\r
+               Free(f);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// 仮想 HUB に関連するログファイルを列挙する (サーバー管理者の場合はすべて列挙する)\r
+LIST *EnumLogFile(char *hubname)\r
+{\r
+       char exe_dir[MAX_PATH];\r
+       char tmp[MAX_PATH];\r
+       LIST *o = NewListFast(CmpLogFile);\r
+       DIRLIST *dir;\r
+\r
+       if (StrLen(hubname) == 0)\r
+       {\r
+               hubname = NULL;\r
+       }\r
+\r
+       GetExeDir(exe_dir, sizeof(exe_dir));\r
+\r
+       // server_log の下を列挙する\r
+       if (hubname == NULL)\r
+       {\r
+               EnumLogFileDir(o, "server_log");\r
+       }\r
+\r
+       // packet_log の下を列挙する\r
+       Format(tmp, sizeof(tmp), "%s/packet_log", exe_dir);\r
+       dir = EnumDir(tmp);\r
+       if (dir != NULL)\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < dir->NumFiles;i++)\r
+               {\r
+                       DIRENT *e = dir->File[i];\r
+\r
+                       if (e->Folder)\r
+                       {\r
+                               char dir_name[MAX_PATH];\r
+\r
+                               if (hubname == NULL || StrCmpi(hubname, e->FileName) == 0)\r
+                               {\r
+                                       Format(dir_name, sizeof(dir_name), "packet_log/%s", e->FileName);\r
+                                       EnumLogFileDir(o, dir_name);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               FreeDir(dir);\r
+       }\r
+\r
+       // security_log の下を列挙する\r
+       Format(tmp, sizeof(tmp), "%s/security_log", exe_dir);\r
+       dir = EnumDir(tmp);\r
+       if (dir != NULL)\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < dir->NumFiles;i++)\r
+               {\r
+                       DIRENT *e = dir->File[i];\r
+\r
+                       if (e->Folder)\r
+                       {\r
+                               char dir_name[MAX_PATH];\r
+\r
+                               if (hubname == NULL || StrCmpi(hubname, e->FileName) == 0)\r
+                               {\r
+                                       Format(dir_name, sizeof(dir_name), "security_log/%s", e->FileName);\r
+                                       EnumLogFileDir(o, dir_name);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               FreeDir(dir);\r
+       }\r
+\r
+       return o;\r
+}\r
+\r
+// 指定した名前のディレクトリのログファイルを列挙する\r
+void EnumLogFileDir(LIST *o, char *dirname)\r
+{\r
+       UINT i;\r
+       char exe_dir[MAX_PATH];\r
+       char dir_full_path[MAX_PATH];\r
+       DIRLIST *dir;\r
+       // 引数チェック\r
+       if (o == NULL || dirname == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetExeDir(exe_dir, sizeof(exe_dir));\r
+       Format(dir_full_path, sizeof(dir_full_path), "%s/%s", exe_dir, dirname);\r
+\r
+       dir = EnumDir(dir_full_path);\r
+       if (dir == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < dir->NumFiles;i++)\r
+       {\r
+               DIRENT *e = dir->File[i];\r
+\r
+               if (e->Folder == false && e->FileSize > 0)\r
+               {\r
+                       char full_path[MAX_PATH];\r
+                       char file_path[MAX_PATH];\r
+\r
+                       Format(file_path, sizeof(file_path), "%s/%s", dirname, e->FileName);\r
+                       Format(full_path, sizeof(full_path), "%s/%s", exe_dir, file_path);\r
+\r
+                       if (EndWith(file_path, ".log"))\r
+                       {\r
+                               LOG_FILE *f = ZeroMalloc(sizeof(LOG_FILE));\r
+\r
+                               StrCpy(f->Path, sizeof(f->Path), file_path);\r
+                               f->FileSize = (UINT)(MIN(e->FileSize, 0xffffffffUL));\r
+                               f->UpdatedTime = e->UpdateDate;\r
+\r
+                               GetMachineName(f->ServerName, sizeof(f->ServerName));\r
+\r
+                               Insert(o, f);\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeDir(dir);\r
+}\r
+\r
+// ログファイルリストエントリ比較\r
+int CmpLogFile(void *p1, void *p2)\r
+{\r
+       LOG_FILE *f1, *f2;\r
+       UINT i;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       f1 = *(LOG_FILE **)p1;\r
+       f2 = *(LOG_FILE **)p2;\r
+       if (f1 == NULL || f2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       i = StrCmpi(f1->Path, f2->Path);\r
+       if (i != 0)\r
+       {\r
+               return i;\r
+       }\r
+\r
+       return StrCmpi(f1->ServerName, f2->ServerName);\r
+}\r
+\r
+// サーバーの Caps を取得する\r
+UINT GetServerCapsInt(SERVER *s, char *name)\r
+{\r
+       CAPSLIST t;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (s == NULL || name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       GetServerCaps(s, &t);\r
+\r
+       ret = GetCapsInt(&t, name);\r
+\r
+       return ret;\r
+}\r
+bool GetServerCapsBool(SERVER *s, char *name)\r
+{\r
+       return (GetServerCapsInt(s, name) == 0) ? false : true;\r
+}\r
+\r
+// サーバーの Caps キャッシュの初期化\r
+void InitServerCapsCache(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s->CapsCacheLock = NewLock();\r
+       s->CapsListCache = NULL;\r
+}\r
+\r
+// サーバーの Caps キャッシュの解放\r
+void FreeServerCapsCache(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->CapsListCache != NULL)\r
+       {\r
+               FreeCapsList(s->CapsListCache);\r
+               s->CapsListCache = NULL;\r
+       }\r
+       DeleteLock(s->CapsCacheLock);\r
+}\r
+\r
+// サーバーの Caps キャッシュの廃棄\r
+void DestroyServerCapsCache(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(s->CapsCacheLock);\r
+       {\r
+               if (s->CapsListCache != NULL)\r
+               {\r
+                       FreeCapsList(s->CapsListCache);\r
+                       s->CapsListCache = NULL;\r
+               }\r
+       }\r
+       Unlock(s->CapsCacheLock);\r
+}\r
+\r
+// このサーバーの Caps リストを取得する\r
+void GetServerCaps(SERVER *s, CAPSLIST *t)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(s->CapsCacheLock);\r
+       {\r
+               if (s->CapsListCache == NULL)\r
+               {\r
+                       s->CapsListCache = ZeroMalloc(sizeof(CAPSLIST));\r
+                       GetServerCapsMain(s, s->CapsListCache);\r
+               }\r
+\r
+               Copy(t, s->CapsListCache, sizeof(s->CapsListCache));\r
+       }\r
+       Unlock(s->CapsCacheLock);\r
+}\r
+\r
+// サーバーの Caps 取得メイン\r
+void GetServerCapsMain(SERVER *s, CAPSLIST *t)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 初期化\r
+       InitCapsList(t);\r
+\r
+       // 最大 Ethernet パケットサイズ\r
+       AddCapsInt(t, "i_max_packet_size", MAX_PACKET_SIZE);\r
+\r
+       if (s->Cedar->Bridge == false)\r
+       {\r
+               LICENSE_STATUS st;\r
+               UINT max_sessions, max_clients, max_bridges, max_user_creations;\r
+\r
+               LiParseCurrentLicenseStatus(s->LicenseSystem, &st);\r
+\r
+               max_clients = st.NumClientLicense;\r
+               max_bridges = st.NumBridgeLicense;\r
+               max_sessions = st.MaxSessions;\r
+               max_user_creations = st.NumUserLicense;\r
+\r
+               // 最大仮想 HUB 数\r
+               AddCapsInt(t, "i_max_hubs", st.MaxHubs);\r
+\r
+               // 最大同時接続セッション数\r
+               AddCapsInt(t, "i_max_sessions", max_sessions);\r
+\r
+               // 最大作成可能ユーザー数\r
+               AddCapsInt(t, "i_max_user_creation", max_user_creations);\r
+\r
+               // 最大クライアント数\r
+               AddCapsInt(t, "i_max_clients", max_clients);\r
+\r
+               // 最大ブリッジ数\r
+               AddCapsInt(t, "i_max_bridges", max_bridges);\r
+\r
+               if (s->ServerType != SERVER_TYPE_FARM_MEMBER)\r
+               {\r
+                       // 登録可能な最大ユーザー数 / 仮想 HUB\r
+                       AddCapsInt(t, "i_max_users_per_hub", MAX_USERS);\r
+\r
+                       // 登録可能な最大グループ数 / 仮想 HUB\r
+                       AddCapsInt(t, "i_max_groups_per_hub", MAX_GROUPS);\r
+\r
+                       // 登録可能な最大アクセスリスト数 / 仮想 HUB\r
+                       AddCapsInt(t, "i_max_access_lists", MAX_ACCESSLISTS);\r
+               }\r
+               else\r
+               {\r
+                       // 登録可能な最大ユーザー数 / 仮想 HUB\r
+                       AddCapsInt(t, "i_max_users_per_hub", 0);\r
+\r
+                       // 登録可能な最大グループ数 / 仮想 HUB\r
+                       AddCapsInt(t, "i_max_groups_per_hub", 0);\r
+\r
+                       // 登録可能な最大アクセスリスト数 / 仮想 HUB\r
+                       AddCapsInt(t, "i_max_access_lists", 0);\r
+               }\r
+\r
+               // 多重ログインに関するポリシー\r
+               AddCapsBool(t, "b_support_limit_multilogin", true);\r
+\r
+               // QoS / VoIP\r
+               AddCapsBool(t, "b_support_qos", true);\r
+       }\r
+       else\r
+       {\r
+               // 最大仮想 HUB 数\r
+               AddCapsInt(t, "i_max_hubs", 0);\r
+\r
+               // 最大同時接続セッション数\r
+               AddCapsInt(t, "i_max_sessions", 0);\r
+\r
+               // 最大クライアント数\r
+               AddCapsInt(t, "i_max_clients", 0);\r
+\r
+               // 最大ブリッジ数\r
+               AddCapsInt(t, "i_max_bridges", 0);\r
+\r
+               // 登録可能な最大ユーザー数 / 仮想 HUB\r
+               AddCapsInt(t, "i_max_users_per_hub", 0);\r
+\r
+               // 登録可能な最大グループ数 / 仮想 HUB\r
+               AddCapsInt(t, "i_max_groups_per_hub", 0);\r
+\r
+               // 登録可能な最大アクセスリスト数 / 仮想 HUB\r
+               AddCapsInt(t, "i_max_access_lists", 0);\r
+\r
+               // QoS / VoIP\r
+               AddCapsBool(t, "b_support_qos", true);\r
+\r
+               // syslog\r
+               AddCapsBool(t, "b_support_syslog", true);\r
+       }\r
+\r
+       // syslog は使用不可\r
+       AddCapsBool(t, "b_support_syslog", false);\r
+\r
+       // クラスタ内仮想 HUB の種類の変更が禁止されている\r
+       AddCapsBool(t, "b_cluster_hub_type_fixed", true);\r
+\r
+       // MAC アドレステーブル最大サイズ / 仮想 HUB\r
+       AddCapsInt(t, "i_max_mac_tables", MAX_MAC_TABLES);\r
+\r
+       // IP アドレステーブル最大サイズ / 仮想 HUB\r
+       AddCapsInt(t, "i_max_ip_tables", MAX_IP_TABLES);\r
+\r
+       // SecureNAT 機能が使用できる\r
+       AddCapsBool(t, "b_support_securenat", true);\r
+\r
+       if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+       {\r
+               AddCapsBool(t, "b_virtual_nat_disabled", true);\r
+       }\r
+\r
+       // NAT テーブル最大サイズ / 仮想 HUB\r
+       AddCapsInt(t, "i_max_secnat_tables", NAT_MAX_SESSIONS);\r
+\r
+       // カスケード接続\r
+       if (s->ServerType == SERVER_TYPE_STANDALONE)\r
+       {\r
+               AddCapsBool(t, "b_support_cascade", true);\r
+       }\r
+       else\r
+       {\r
+               AddCapsBool(t, "b_support_cascade", false);\r
+       }\r
+\r
+       if (s->Cedar->Bridge)\r
+       {\r
+               // ブリッジ モード\r
+               AddCapsBool(t, "b_bridge", true);\r
+       }\r
+       else if (s->ServerType == SERVER_TYPE_STANDALONE)\r
+       {\r
+               // スタンドアロン モード\r
+               AddCapsBool(t, "b_standalone", true);\r
+       }\r
+       else if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               // クラスタ コントローラ モード\r
+               AddCapsBool(t, "b_cluster_controller", true);\r
+       }\r
+       else\r
+       {\r
+               // クラスタ メンバ モード\r
+               AddCapsBool(t, "b_cluster_member", true);\r
+       }\r
+\r
+       // 仮想 HUB の設定変更が可能である\r
+       AddCapsBool(t, "b_support_config_hub", s->ServerType != SERVER_TYPE_FARM_MEMBER &&\r
+               s->Cedar->Bridge == false);\r
+\r
+       // VPN クライアントが接続可能である\r
+       AddCapsBool(t, "b_vpn_client_connect", s->Cedar->Bridge == false ? true : false);\r
+\r
+       // 外部認証サーバーは使用不可\r
+       AddCapsBool(t, "b_support_radius", false);\r
+\r
+       // ローカル ブリッジ機能が使用できる\r
+       AddCapsBool(t, "b_local_bridge", IsBridgeSupported());\r
+\r
+       if (OS_IS_WINDOWS(GetOsInfo()->OsType))\r
+       {\r
+               // パケットキャプチャドライバが未インストール\r
+               AddCapsBool(t, "b_must_install_pcap", IsEthSupported() == false ? true : false);\r
+       }\r
+       else\r
+       {\r
+               // Linux 版ではドライバはインストール済みとする\r
+               AddCapsBool(t, "b_must_install_pcap", false);\r
+       }\r
+\r
+       if (IsBridgeSupported())\r
+       {\r
+               // tun/tap が使用可能 (Linux のみ)\r
+               AddCapsBool(t, "b_tap_supported", GetOsInfo()->OsType == OSTYPE_LINUX ? true : false);\r
+       }\r
+\r
+       // カスケード接続\r
+       if (s->ServerType == SERVER_TYPE_STANDALONE)\r
+       {\r
+               AddCapsBool(t, "b_support_cascade", true);\r
+       }\r
+       else\r
+       {\r
+               AddCapsBool(t, "b_support_cascade", false);\r
+       }\r
+\r
+       // カスケード接続時のサーバー認証が使用できる\r
+       AddCapsBool(t, "b_support_cascade_cert", true);\r
+\r
+       // ログファイル設定の変更ができる\r
+       AddCapsBool(t, "b_support_config_log", s->ServerType != SERVER_TYPE_FARM_MEMBER);\r
+\r
+       // ログファイルの自動削除が使用可能である\r
+       AddCapsBool(t, "b_support_autodelete", true);\r
+\r
+       // config 操作が使用可能である\r
+       AddCapsBool(t, "b_support_config_rw", true);\r
+\r
+       // 仮想 HUB ごとの属性が設定可能である\r
+       AddCapsBool(t, "b_support_hub_admin_option", true);\r
+\r
+       // カスケード接続でクライアント証明書が設定可能である\r
+       AddCapsBool(t, "b_support_cascade_client_cert", true);\r
+\r
+       // 仮想 HUB を隠すことができる\r
+       AddCapsBool(t, "b_support_hide_hub", true);\r
+\r
+       // 統合管理\r
+       AddCapsBool(t, "b_support_cluster_admin", true);\r
+\r
+       if (s->Cedar->Bridge == false)\r
+       {\r
+               LICENSE_STATUS status;\r
+               // 仮想レイヤ 3 スイッチ機能が使える\r
+               AddCapsBool(t, "b_support_layer3", true);\r
+\r
+               AddCapsInt(t, "i_max_l3_sw", MAX_NUM_L3_SWITCH);\r
+               AddCapsInt(t, "i_max_l3_if", MAX_NUM_L3_IF);\r
+               AddCapsInt(t, "i_max_l3_table", MAX_NUM_L3_TABLE);\r
+\r
+               LiParseCurrentLicenseStatus(s->LicenseSystem, &status);\r
+\r
+               if (status.AllowEnterpriseFunction || s->ServerType != SERVER_TYPE_STANDALONE)\r
+               {\r
+                       // クラスタの一部として動作できる\r
+                       AddCapsBool(t, "b_support_cluster", true);\r
+               }\r
+               else\r
+               {\r
+                       // クラスタとして動作できない\r
+                       AddCapsBool(t, "b_support_cluster", false);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               AddCapsBool(t, "b_support_layer3", false);\r
+\r
+               AddCapsInt(t, "i_max_l3_sw", 0);\r
+               AddCapsInt(t, "i_max_l3_if", 0);\r
+               AddCapsInt(t, "i_max_l3_table", 0);\r
+\r
+               AddCapsBool(t, "b_support_cluster", false);\r
+       }\r
+\r
+       if (s->ServerType != SERVER_TYPE_FARM_MEMBER && s->Cedar->Bridge == false)\r
+       {\r
+               // CRL をサポート\r
+               AddCapsBool(t, "b_support_crl", true);\r
+       }\r
+\r
+       // AC は非サポート\r
+       AddCapsBool(t, "b_support_ac", false);\r
+\r
+       // ログ ファイルのダウンロードをサポート\r
+       AddCapsBool(t, "b_support_read_log", true);\r
+\r
+       // カスケード接続の名前の変更が可能である\r
+       AddCapsBool(t, "b_support_rename_cascade", true);\r
+\r
+       // ライセンス管理は不可能\r
+       AddCapsBool(t, "b_support_license", false);\r
+\r
+       if (s->Cedar->Beta)\r
+       {\r
+               // ベータ版\r
+               AddCapsBool(t, "b_beta_version", true);\r
+       }\r
+\r
+       // ローカルブリッジにネットワーク接続の名前表示をサポート\r
+#ifdef OS_WIN32\r
+       if (IsBridgeSupported() && IsNt() && GetOsInfo()->OsType >= OSTYPE_WINDOWS_2000_PROFESSIONAL)\r
+       {\r
+               AddCapsBool(t, "b_support_network_connection_name", true);\r
+       }\r
+#else  // OS_WIN32\r
+       if (IsBridgeSupported() && EthIsInterfaceDescriptionSupportedUnix())\r
+       {\r
+               AddCapsBool(t, "b_support_network_connection_name", true);\r
+       }\r
+#endif // OS_WIN32\r
+\r
+       // MAC アドレスフィルタリングをサポート\r
+       AddCapsBool(t, "b_support_check_mac", true);\r
+\r
+       // TCP コネクションの状態チェックをサポート\r
+       AddCapsBool(t, "b_support_check_tcp_state", true);\r
+\r
+       // Radius 認証は使用不可\r
+       AddCapsBool(t, "b_support_radius_retry_interval_and_several_servers", false);\r
+\r
+       // MAC アドレステーブルでタグ付き VLAN の ID を管理できる\r
+       AddCapsBool(t, "b_support_vlan", true);\r
+\r
+       // 仮想 HUB 拡張オプションをサポート\r
+       if ((s->Cedar->Bridge == false) &&\r
+               (s->ServerType == SERVER_TYPE_STANDALONE || s->ServerType == SERVER_TYPE_FARM_CONTROLLER))\r
+       {\r
+               AddCapsBool(t, "b_support_hub_ext_options", true);\r
+       }\r
+       else\r
+       {\r
+               AddCapsBool(t, "b_support_hub_ext_options", false);\r
+       }\r
+\r
+       // セキュリティポリシー バージョン 3.0 をサポート\r
+       AddCapsBool(t, "b_support_policy_ver_3", true);\r
+\r
+       // IPv6 アクセスリストをサポート\r
+       AddCapsBool(t, "b_support_ipv6_acl", true);\r
+\r
+       // アクセスリストで遅延・ジッタ・パケットロスの設定をサポート\r
+       AddCapsBool(t, "b_support_ex_acl", true);\r
+\r
+       // アクセスリストでグループ名による指定をサポート\r
+       AddCapsBool(t, "b_support_acl_group", true);\r
+\r
+       // IPv6 接続元 IP 制限リストをサポート\r
+       AddCapsBool(t, "b_support_ipv6_ac", true);\r
+\r
+       // タグ付き VLAN パケット透過設定ツールをサポート\r
+       AddCapsBool(t, "b_support_eth_vlan", (OS_IS_WINDOWS_NT(GetOsType()) && GET_KETA(GetOsType(), 100) >= 2));\r
+\r
+       // 仮想 HUB への VPN 接続時のメッセージ表示機能をサポート\r
+       AddCapsBool(t, "b_support_msg", true);\r
+\r
+       // VPN3\r
+       AddCapsBool(t, "b_vpn3", true);\r
+\r
+       // オープンソース版\r
+       AddCapsBool(t, "b_gpl", true);\r
+}\r
+\r
+// SYSLOG_SETTING\r
+void InRpcSysLogSetting(SYSLOG_SETTING *t, PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(SYSLOG_SETTING));\r
+       t->SaveType = PackGetInt(p, "SaveType");\r
+       t->Port = PackGetInt(p, "Port");\r
+       PackGetStr(p, "Hostname", t->Hostname, sizeof(t->Hostname));\r
+}\r
+void OutRpcSysLogSetting(PACK *p, SYSLOG_SETTING *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddInt(p, "SaveType", t->SaveType);\r
+       PackAddInt(p, "Port", t->Port);\r
+       PackAddStr(p, "Hostname", t->Hostname);\r
+}\r
+\r
+// CAPSLIST\r
+void InitCapsList(CAPSLIST *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(CAPSLIST));\r
+       t->CapsList = NewListFast(NULL);\r
+}\r
+void InRpcCapsList(CAPSLIST *t, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(CAPSLIST));\r
+       t->CapsList = NewListFast(CompareCaps);\r
+\r
+       for (i = 0;i < LIST_NUM(p->elements);i++)\r
+       {\r
+               ELEMENT *e = LIST_DATA(p->elements, i);\r
+\r
+               if (StartWith(e->name, "caps_") && e->type == VALUE_INT && e->num_value == 1)\r
+               {\r
+                       CAPS *c = NewCaps(e->name + 5, e->values[0]->IntValue);\r
+                       Insert(t->CapsList, c);\r
+               }\r
+       }\r
+}\r
+void OutRpcCapsList(PACK *p, CAPSLIST *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(t->CapsList);i++)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               CAPS *c = LIST_DATA(t->CapsList, i);\r
+\r
+               Format(tmp, sizeof(tmp), "caps_%s", c->Name);\r
+               PackAddInt(p, tmp, c->Value);\r
+       }\r
+}\r
+void FreeRpcCapsList(CAPSLIST *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(t->CapsList);i++)\r
+       {\r
+               CAPS *c = LIST_DATA(t->CapsList, i);\r
+\r
+               FreeCaps(c);\r
+       }\r
+\r
+       ReleaseList(t->CapsList);\r
+}\r
+\r
+// Caps リストに bool 型を追加\r
+void AddCapsBool(CAPSLIST *caps, char *name, bool b)\r
+{\r
+       CAPS *c;\r
+       // 引数チェック\r
+       if (caps == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c = NewCaps(name, b == false ? 0 : 1);\r
+       AddCaps(caps, c);\r
+}\r
+\r
+// Caps リストに int 型を追加\r
+void AddCapsInt(CAPSLIST *caps, char *name, UINT i)\r
+{\r
+       CAPS *c;\r
+       // 引数チェック\r
+       if (caps == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c = NewCaps(name, i);\r
+       AddCaps(caps, c);\r
+}\r
+\r
+// Caps リストから int 型を取得\r
+UINT GetCapsInt(CAPSLIST *caps, char *name)\r
+{\r
+       CAPS *c;\r
+       // 引数チェック\r
+       if (caps == NULL || name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       c = GetCaps(caps, name);\r
+       if (c == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return c->Value;\r
+}\r
+\r
+// Caps リストから bool 型を取得\r
+bool GetCapsBool(CAPSLIST *caps, char *name)\r
+{\r
+       CAPS *c;\r
+       // 引数チェック\r
+       if (caps == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       c = GetCaps(caps, name);\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return c->Value == 0 ? false : true;\r
+}\r
+\r
+// Caps リストの解放\r
+void FreeCapsList(CAPSLIST *caps)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (caps == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(caps->CapsList);i++)\r
+       {\r
+               CAPS *c = LIST_DATA(caps->CapsList, i);\r
+\r
+               FreeCaps(c);\r
+       }\r
+\r
+       ReleaseList(caps->CapsList);\r
+       Free(caps);\r
+}\r
+\r
+// Caps の取得\r
+CAPS *GetCaps(CAPSLIST *caps, char *name)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (caps == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(caps->CapsList);i++)\r
+       {\r
+               CAPS *c = LIST_DATA(caps->CapsList, i);\r
+\r
+               if (StrCmpi(c->Name, name) == 0)\r
+               {\r
+                       return c;\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// Caps の追加\r
+void AddCaps(CAPSLIST *caps, CAPS *c)\r
+{\r
+       // 引数チェック\r
+       if (caps == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Insert(caps->CapsList, c);\r
+}\r
+\r
+// Caps の比較\r
+int CompareCaps(void *p1, void *p2)\r
+{\r
+       CAPS *c1, *c2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       c1 = *(CAPS **)p1;\r
+       c2 = *(CAPS **)p2;\r
+       if (c1 == NULL || c2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCmpi(c1->Name, c2->Name);\r
+}\r
+\r
+// Caps リストの作成\r
+CAPSLIST *NewCapsList()\r
+{\r
+       CAPSLIST *caps = ZeroMalloc(sizeof(CAPSLIST));\r
+\r
+       caps->CapsList = NewListFast(CompareCaps);\r
+\r
+       return caps;\r
+}\r
+\r
+// Caps の解放\r
+void FreeCaps(CAPS *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(c->Name);\r
+       Free(c);\r
+}\r
+\r
+// Caps の作成\r
+CAPS *NewCaps(char *name, UINT value)\r
+{\r
+       CAPS *c;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       c = ZeroMalloc(sizeof(CAPS));\r
+       c->Name = CopyStr(name);\r
+       c->Value = value;\r
+\r
+       return c;\r
+}\r
+\r
+// 現在の接続数と重みから得点を計算する\r
+UINT SiCalcPoint(SERVER *s, UINT num, UINT weight)\r
+{\r
+       UINT server_max_sessions = SERVER_MAX_SESSIONS;\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (weight == 0)\r
+       {\r
+               weight = 100;\r
+       }\r
+\r
+       server_max_sessions = GetServerCapsInt(s, "i_max_sessions");\r
+\r
+       return (UINT)(((double)server_max_sessions -\r
+               MIN((double)num * 100.0 / (double)weight, (double)server_max_sessions))\r
+               * (double)FARM_BASE_POINT / (double)server_max_sessions);\r
+}\r
+\r
+// サーバー得点の取得\r
+UINT SiGetPoint(SERVER *s)\r
+{\r
+       UINT num_session;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       num_session = Count(s->Cedar->CurrentSessions);\r
+\r
+       return SiCalcPoint(s, num_session, s->Weight);\r
+}\r
+\r
+// デフォルトの証明書を生成する\r
+void SiGenerateDefualtCert(X **server_x, K **server_k)\r
+{\r
+       X *x;\r
+       K *private_key, *public_key;\r
+       NAME *name;\r
+       char tmp[MAX_SIZE];\r
+       wchar_t cn[MAX_SIZE];\r
+       // 引数チェック\r
+       if (server_x == NULL || server_k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 鍵ペアの作成\r
+       RsaGen(&private_key, &public_key, 1024);\r
+\r
+       // ホスト名の取得\r
+       StrCpy(tmp, sizeof(tmp), "server.softether.vpn");\r
+       GetMachineName(tmp, sizeof(tmp));\r
+\r
+       StrToUni(cn, sizeof(cn), tmp);\r
+       name = NewName(cn, L"Default Random Certification", L"VPN Server",\r
+               L"JP", NULL, NULL);\r
+       x = NewRootX(public_key, private_key, name, MAX(GetDaysUntil2038(), SERVER_DEFAULT_CERT_DAYS), NULL);\r
+\r
+       *server_x = x;\r
+       *server_k = private_key;\r
+\r
+       FreeName(name);\r
+\r
+       FreeK(public_key);\r
+}\r
+\r
+// サーバー証明書をデフォルトにする\r
+void SiInitDefaultServerCert(SERVER *s)\r
+{\r
+       X *x = NULL;\r
+       K *k = NULL;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // サーバー証明書と秘密鍵を生成する\r
+       SiGenerateDefualtCert(&x, &k);\r
+\r
+       // 設定する\r
+       SetCedarCert(s->Cedar, x, k);\r
+\r
+       FreeX(x);\r
+       FreeK(k);\r
+}\r
+\r
+// 暗号化アルゴリズム名をデフォルトにする\r
+void SiInitCipherName(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetCedarCipherList(s->Cedar, SERVER_DEFAULT_CIPHER_NAME);\r
+}\r
+\r
+// リスナーリストを初期化する\r
+void SiInitListenerList(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SiLockListenerList(s);\r
+       {\r
+               // デフォルト ポートとして 443, 992, 5555 の 3 つのポートを登録する\r
+               SiAddListener(s, 443, true);\r
+               SiAddListener(s, 992, true);\r
+               SiAddListener(s, 5555, true);\r
+       }\r
+       SiUnlockListenerList(s);\r
+}\r
+\r
+// リスナーを削除する\r
+bool SiDeleteListener(SERVER *s, UINT port)\r
+{\r
+       SERVER_LISTENER *e;\r
+       // 引数チェック\r
+       if (s == NULL || port == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       e = SiGetListener(s, port);\r
+       if (e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // まだ動作中であれば停止する\r
+       SiDisableListener(s, port);\r
+\r
+       if (e->Listener != NULL)\r
+       {\r
+               ReleaseListener(e->Listener);\r
+       }\r
+\r
+       Delete(s->ServerListenerList, e);\r
+       Free(e);\r
+\r
+       return true;\r
+}\r
+\r
+// SERVER_LISTENER を比較する\r
+int CompareServerListener(void *p1, void *p2)\r
+{\r
+       SERVER_LISTENER *s1, *s2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       s1 = *(SERVER_LISTENER **)p1;\r
+       s2 = *(SERVER_LISTENER **)p2;\r
+       if (s1 == NULL || s2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (s1->Port > s2->Port)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (s1->Port < s2->Port)\r
+       {\r
+               return -1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+// リスナーを停止する\r
+bool SiDisableListener(SERVER *s, UINT port)\r
+{\r
+       SERVER_LISTENER *e;\r
+       // 引数チェック\r
+       if (s == NULL || port == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // リスナーを取得する\r
+       e = SiGetListener(s, port);\r
+       if (e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (e->Enabled == false || e->Listener == NULL)\r
+       {\r
+               // 停止中である\r
+               return true;\r
+       }\r
+\r
+       // リスナーを停止する\r
+       StopListener(e->Listener);\r
+\r
+       // リスナーを解放する\r
+       ReleaseListener(e->Listener);\r
+       e->Listener = NULL;\r
+\r
+       e->Enabled = false;\r
+\r
+       return true;\r
+}\r
+\r
+// リスナーを開始する\r
+bool SiEnableListener(SERVER *s, UINT port)\r
+{\r
+       SERVER_LISTENER *e;\r
+       // 引数チェック\r
+       if (s == NULL || port == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // リスナーを取得する\r
+       e = SiGetListener(s, port);\r
+       if (e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (e->Enabled)\r
+       {\r
+               // すでに開始されている\r
+               return true;\r
+       }\r
+\r
+       // リスナーを作成する\r
+       e->Listener = NewListener(s->Cedar, LISTENER_TCP, e->Port);\r
+       if (e->Listener == NULL)\r
+       {\r
+               // 失敗\r
+               return false;\r
+       }\r
+\r
+       e->Enabled = true;\r
+\r
+       return true;\r
+}\r
+\r
+// リスナーを取得する\r
+SERVER_LISTENER *SiGetListener(SERVER *s, UINT port)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || port == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(s->ServerListenerList);i++)\r
+       {\r
+               SERVER_LISTENER *e = LIST_DATA(s->ServerListenerList, i);\r
+               if (e->Port == port)\r
+               {\r
+                       return e;\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// リスナーを追加する\r
+bool SiAddListener(SERVER *s, UINT port, bool enabled)\r
+{\r
+       SERVER_LISTENER *e;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || port == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 既存のリスナーが存在していないかどうかチェックする\r
+       for (i = 0;i < LIST_NUM(s->ServerListenerList);i++)\r
+       {\r
+               e = LIST_DATA(s->ServerListenerList, i);\r
+               if (e->Port == port)\r
+               {\r
+                       // すでに存在する\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // 新しいリスナーを初期化して登録する\r
+       e = ZeroMalloc(sizeof(SERVER_LISTENER));\r
+       e->Enabled = enabled;\r
+       e->Port = port;\r
+\r
+       if (e->Enabled)\r
+       {\r
+               // リスナーを作成する\r
+               e->Listener = NewListener(s->Cedar, LISTENER_TCP, e->Port);\r
+       }\r
+\r
+       Insert(s->ServerListenerList, e);\r
+\r
+       return true;\r
+}\r
+\r
+// リスナーリストをロックする\r
+void SiLockListenerList(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(s->ServerListenerList);\r
+}\r
+\r
+// リスナーリストのロックを解除する\r
+void SiUnlockListenerList(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UnlockList(s->ServerListenerList);\r
+}\r
+\r
+// Bridge の初期化\r
+void SiInitBridge(SERVER *s)\r
+{\r
+       HUB *h;\r
+       HUB_OPTION o;\r
+       HUB_LOG g;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&o, sizeof(o));\r
+       o.MaxSession = 0;\r
+\r
+       h = NewHub(s->Cedar, SERVER_DEFAULT_BRIDGE_NAME, &o);\r
+       AddHub(s->Cedar, h);\r
+\r
+       h->Offline = true;\r
+       SetHubOnline(h);\r
+\r
+       // ログ設定\r
+       SiSetDefaultLogSetting(&g);\r
+       SetHubLogSetting(h, &g);\r
+\r
+       ReleaseHub(h);\r
+}\r
+\r
+// デフォルトの仮想 HUB を作成する\r
+void SiInitDefaultHubList(SERVER *s)\r
+{\r
+       HUB *h;\r
+       HUB_OPTION o;\r
+       HUB_LOG g;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&o, sizeof(o));\r
+       o.MaxSession = 0;\r
+       o.VlanTypeId = MAC_PROTO_TAGVLAN;\r
+       o.NoIPv6DefaultRouterInRAWhenIPv6 = true;\r
+       o.ManageOnlyPrivateIP = true;\r
+       o.ManageOnlyLocalUnicastIPv6 = true;\r
+       o.NoMacAddressLog = true;\r
+\r
+       h = NewHub(s->Cedar, s->Cedar->Bridge == false ? SERVER_DEFAULT_HUB_NAME : SERVER_DEFAULT_BRIDGE_NAME, &o);\r
+       h->CreatedTime = SystemTime64();\r
+       AddHub(s->Cedar, h);\r
+\r
+       if (s->Cedar->Bridge)\r
+       {\r
+               // パスワードを乱数にする\r
+               Rand(h->HashedPassword, sizeof(h->HashedPassword));\r
+               Rand(h->SecurePassword, sizeof(h->SecurePassword));\r
+       }\r
+\r
+       h->Offline = true;\r
+       SetHubOnline(h);\r
+\r
+       // ログ設定\r
+       SiSetDefaultLogSetting(&g);\r
+       SetHubLogSetting(h, &g);\r
+\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < 0;i++)\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+                       USER *u;\r
+                       sprintf(tmp, "user%u", i);\r
+                       AcLock(h);\r
+                       u = NewUser(tmp, L"test", L"", AUTHTYPE_ANONYMOUS, NULL);\r
+                       AcAddUser(h, u);\r
+                       ReleaseUser(u);\r
+                       AcUnlock(h);\r
+               }\r
+       }\r
+\r
+       ReleaseHub(h);\r
+}\r
+\r
+// ログ設定をデフォルトにする\r
+void SiSetDefaultLogSetting(HUB_LOG *g)\r
+{\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(g, sizeof(HUB_LOG));\r
+       g->SaveSecurityLog = true;\r
+       g->SecurityLogSwitchType = LOG_SWITCH_DAY;\r
+       g->SavePacketLog = false;\r
+       g->PacketLogSwitchType = LOG_SWITCH_DAY;\r
+       g->PacketLogConfig[PACKET_LOG_TCP_CONN] =\r
+               g->PacketLogConfig[PACKET_LOG_DHCP] = PACKET_LOG_HEADER;\r
+}\r
+\r
+// テスト\r
+void SiTest(SERVER *s)\r
+{\r
+#if    0\r
+       USER *u;\r
+       USERGROUP *g;\r
+       HUB *h;\r
+       LINK *k;\r
+       CLIENT_OPTION o;\r
+       CLIENT_AUTH a;\r
+       ACCESS *ac;\r
+       X *x;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       h = GetHub(s->Cedar, SERVER_DEFAULT_HUB_NAME);\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ユーザーを作成する\r
+       g = NewGroup("test_group", L"テスト グループ", L"テストです。");\r
+       AcAddGroup(h, g);\r
+\r
+       u = NewUser("test", L"テスト", L"はむです", AUTHTYPE_ANONYMOUS, NULL);\r
+       AcAddUser(h, u);\r
+       JoinUserToGroup(u, g);\r
+       ReleaseUser(u);\r
+\r
+       u = NewUser("anonymous", L"匿名ユーザー", L"ソフトイーサ株式会社", AUTHTYPE_ANONYMOUS, NULL);\r
+       AcAddUser(h, u);\r
+       JoinUserToGroup(u, g);\r
+       ReleaseUser(u);\r
+\r
+       u = NewUser("password", L"パスワードユーザー", L"ソフトイーサ株式会社", AUTHTYPE_PASSWORD, NewPasswordAuthData("password", "microsoft"));\r
+       AcAddUser(h, u);\r
+       ReleaseUser(u);\r
+\r
+       x = FileToX("mayaqua.cer");\r
+       u = NewUser("usercert", L"ユーザー証明書テストユーザー", L"ソフトイーサ株式会社", AUTHTYPE_USERCERT, NewUserCertAuthData(x));\r
+       AcAddUser(h, u);\r
+       ReleaseUser(u);\r
+       FreeX(x);\r
+\r
+       u = NewUser("rootcert", L"ルート証明書テストユーザー", L"ソフトイーサ株式会社", AUTHTYPE_ROOTCERT, NewRootCertAuthData(NULL, NULL));\r
+       AcAddUser(h, u);\r
+       ReleaseUser(u);\r
+\r
+       u = NewUser("*", L"*", L"すべて", AUTHTYPE_RADIUS, NewRadiusAuthData(L""));\r
+       AcAddUser(h, u);\r
+       ReleaseUser(u);\r
+\r
+       ReleaseGroup(g);\r
+\r
+       // Radius サーバーを設定する\r
+       SetRadiusServer(h, "dc.sec.softether.co.jp", RADIUS_DEFAULT_PORT, "microsoft");\r
+\r
+       // HUB 間リンクを作成する\r
+       Zero(&o, sizeof(o));\r
+       UniStrCpy(o.AccountName, sizeof(o.AccountName), L"テスト リンク");\r
+       o.MaxConnection = 8;\r
+       o.NumRetry = INFINITE;\r
+       o.UseEncrypt = true;\r
+       StrCpy(o.HubName, sizeof(o.HubName), "TEST_HUB");\r
+       o.Port = 443;\r
+       StrCpy(o.Hostname, sizeof(o.Hostname), "ts.softether.co.jp");\r
+\r
+       Zero(&a, sizeof(a));\r
+       a.AuthType = CLIENT_AUTHTYPE_ANONYMOUS;\r
+       StrCpy(a.Username, sizeof(a.Username), "anonymous_test");\r
+\r
+       k = NewLink(s->Cedar, h, &o, &a, GetDefaultPolicy());\r
+       StartLink(k);\r
+\r
+       ReleaseLink(k);\r
+\r
+       // 証明書を追加する\r
+       x = FileToX("root.cer");\r
+       AddRootCert(h, x);\r
+       FreeX(x);\r
+\r
+       // アクセスリストを追加する\r
+       ac = ZeroMalloc(sizeof(ACCESS));\r
+       ac->Id = 1;\r
+       UniStrCpy(ac->Note, sizeof(ac->Note), L"アクセスリストのテスト");\r
+       ac->Active = true;\r
+       ac->Priority = 3;\r
+       ac->Discard = true;\r
+       ac->SrcIpAddress = 0x12345678;\r
+       ac->SrcSubnetMask = 0xffffffff;\r
+       ac->DestIpAddress = 0x36547894;\r
+       ac->DestSubnetMask = 0xffffffff;\r
+       ac->Protocol = IP_PROTO_TCP;\r
+       StrCpy(ac->SrcUsername, 0, "yagi");\r
+       StrCpy(ac->DestUsername, 0, "neko");\r
+       AddAccessList(h, ac);\r
+       Free(ac);\r
+\r
+       ReleaseHub(h);\r
+#endif\r
+}\r
+\r
+// 初期コンフィグレーションを設定する\r
+void SiLoadInitialConfiguration(SERVER *s)\r
+{\r
+       RPC_KEEP k;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 自動保存間隔関係\r
+       s->AutoSaveConfigSpan = SERVER_FILE_SAVE_INTERVAL_DEFAULT;\r
+\r
+       s->Weight = FARM_DEFAULT_WEIGHT;\r
+\r
+       // KEEP 関係\r
+       Zero(&k, sizeof(k));\r
+       k.UseKeepConnect = true;\r
+       k.KeepConnectPort = 80;\r
+       StrCpy(k.KeepConnectHost, sizeof(k.KeepConnectHost), CLIENT_DEFAULT_KEEPALIVE_HOST);\r
+       k.KeepConnectInterval = KEEP_INTERVAL_DEFAULT * 1000;\r
+       k.KeepConnectProtocol = CONNECTION_UDP;\r
+\r
+       Lock(s->Keep->lock);\r
+       {\r
+               KEEP *keep = s->Keep;\r
+               keep->Enable = k.UseKeepConnect;\r
+               keep->Server = true;\r
+               StrCpy(keep->ServerName, sizeof(keep->ServerName), k.KeepConnectHost);\r
+               keep->ServerPort = k.KeepConnectPort;\r
+               keep->UdpMode = k.KeepConnectProtocol;\r
+               keep->Interval = k.KeepConnectInterval;\r
+       }\r
+       Unlock(s->Keep->lock);\r
+\r
+       // パスワードを初期化する\r
+       Hash(s->HashedPassword, "", 0, true);\r
+\r
+       // 暗号化アルゴリズム名をデフォルトにする\r
+       SiInitCipherName(s);\r
+\r
+       // サーバー証明書をデフォルトにする\r
+       SiInitDefaultServerCert(s);\r
+\r
+       // リスナーリストをデフォルト設定する\r
+       SiInitListenerList(s);\r
+\r
+       // デフォルト HUB の作成\r
+       SiInitDefaultHubList(s);\r
+\r
+       s->Eraser = NewEraser(s->Logger, 0);\r
+}\r
+\r
+// コンフィグレーションファイルを読み込む (メイン)\r
+bool SiLoadConfigurationFileMain(SERVER *s, FOLDER *root)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || root == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return SiLoadConfigurationCfg(s, root);\r
+}\r
+\r
+// コンフィグレーションファイルを読み込む\r
+bool SiLoadConfigurationFile(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       bool ret = false;\r
+       FOLDER *root;\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s->CfgRw = NewCfgRw(&root,\r
+               s->Cedar->Bridge == false ? SERVER_CONFIG_FILE_NAME : BRIDGE_CONFIG_FILE_NAME);\r
+\r
+       if (server_reset_setting)\r
+       {\r
+               CfgDeleteFolder(root);\r
+               root = NULL;\r
+               server_reset_setting = false;\r
+       }\r
+\r
+       if (root == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = SiLoadConfigurationFileMain(s, root);\r
+\r
+       CfgDeleteFolder(root);\r
+\r
+       return ret;\r
+}\r
+\r
+// コンフィグレーション初期化\r
+void SiInitConfiguration(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // Ethernet 初期化\r
+       InitEth();\r
+\r
+       s->AutoSaveConfigSpan = SERVER_FILE_SAVE_INTERVAL_DEFAULT;\r
+\r
+       SLog(s->Cedar, "LS_LOAD_CONFIG_1");\r
+       if (SiLoadConfigurationFile(s) == false)\r
+       {\r
+               SLog(s->Cedar, "LS_LOAD_CONFIG_3");\r
+               SiLoadInitialConfiguration(s);\r
+\r
+               server_reset_setting = false;\r
+       }\r
+       else\r
+       {\r
+               SLog(s->Cedar, "LS_LOAD_CONFIG_2");\r
+       }\r
+\r
+       // Linux における arp_filter\r
+       if (GetOsInfo()->OsType == OSTYPE_LINUX)\r
+       {\r
+               if (s->NoLinuxArpFilter == false)\r
+               {\r
+                       SetLinuxArpFilter();\r
+               }\r
+       }\r
+\r
+       // 保存スレッド作成\r
+       SLog(s->Cedar, "LS_INIT_SAVE_THREAD", s->AutoSaveConfigSpan / 1000);\r
+       s->SaveHaltEvent = NewEvent();\r
+       s->SaveThread = NewThread(SiSaverThread, s);\r
+}\r
+\r
+// サーバー設定を CFG から読み込む\r
+bool SiLoadConfigurationCfg(SERVER *s, FOLDER *root)\r
+{\r
+       FOLDER *f1, *f2, *f3, *f4, *f5, *f6;\r
+       // 引数チェック\r
+       if (s == NULL || root == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       f1 = CfgGetFolder(root, "ServerConfiguration");\r
+       f2 = CfgGetFolder(root, "VirtualHUB");\r
+       f3 = CfgGetFolder(root, "ListenerList");\r
+       f4 = CfgGetFolder(root, "LocalBridgeList");\r
+       f5 = CfgGetFolder(root, "VirtualLayer3SwitchList");\r
+       f6 = CfgGetFolder(root, "LicenseManager");\r
+\r
+       if (f1 == NULL)\r
+       {\r
+               SLog(s->Cedar, "LS_BAD_CONFIG");\r
+               return false;\r
+       }\r
+\r
+       s->ConfigRevision = CfgGetInt(root, "ConfigRevision");\r
+\r
+       if (s->Cedar->Bridge == false && f6 != NULL)\r
+       {\r
+               if (GetServerCapsBool(s, "b_support_license"))\r
+               {\r
+                       SiLoadLicenseManager(s, f6);\r
+               }\r
+       }\r
+\r
+       DestroyServerCapsCache(s);\r
+\r
+       SiLoadServerCfg(s, f1);\r
+\r
+       if (s->ServerType != SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               SiLoadHubs(s, f2);\r
+       }\r
+\r
+       SiLoadListeners(s, f3);\r
+\r
+       if (f4 != NULL)\r
+       {\r
+               SiLoadLocalBridges(s, f4);\r
+       }\r
+\r
+       if (s->Cedar->Bridge == false && f5 != NULL)\r
+       {\r
+               SiLoadL3Switchs(s, f5);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// リスナー設定を書き出す\r
+void SiWriteListenerCfg(FOLDER *f, SERVER_LISTENER *r)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CfgAddBool(f, "Enabled", r->Enabled);\r
+       CfgAddInt(f, "Port", r->Port);\r
+}\r
+\r
+// リスナー設定を読み込む\r
+void SiLoadListenerCfg(SERVER *s, FOLDER *f)\r
+{\r
+       bool enable;\r
+       UINT port;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       enable = CfgGetBool(f, "Enabled");\r
+       port = CfgGetInt(f, "Port");\r
+\r
+       if (port == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SiAddListener(s, port, enable);\r
+}\r
+\r
+// リスナー一覧を読み込む\r
+void SiLoadListeners(SERVER *s, FOLDER *f)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = CfgEnumFolderToTokenList(f);\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               FOLDER *ff = CfgGetFolder(f, t->Token[i]);\r
+               if (ff != NULL)\r
+               {\r
+                       SiLoadListenerCfg(s, ff);\r
+               }\r
+       }\r
+       FreeToken(t);\r
+}\r
+\r
+// リスナー一覧を書き出す\r
+void SiWriteListeners(FOLDER *f, SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(s->ServerListenerList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(s->ServerListenerList);i++)\r
+               {\r
+                       SERVER_LISTENER *r = LIST_DATA(s->ServerListenerList, i);\r
+                       char name[MAX_SIZE];\r
+                       Format(name, sizeof(name), "Listener%u", i);\r
+                       SiWriteListenerCfg(CfgCreateFolder(f, name), r);\r
+               }\r
+       }\r
+       UnlockList(s->ServerListenerList);\r
+}\r
+\r
+// ブリッジを書き出す\r
+void SiWriteLocalBridgeCfg(FOLDER *f, LOCALBRIDGE *br)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || br == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CfgAddStr(f, "DeviceName", br->DeviceName);\r
+       CfgAddStr(f, "HubName", br->HubName);\r
+       CfgAddBool(f, "NoPromiscuousMode", br->Local);\r
+       CfgAddBool(f, "MonitorMode", br->Monitor);\r
+       CfgAddBool(f, "FullBroadcastMode", br->FullBroadcast);\r
+\r
+       if (OS_IS_UNIX(GetOsInfo()->OsType))\r
+       {\r
+               CfgAddBool(f, "TapMode", br->TapMode);\r
+\r
+               if (br->TapMode)\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+                       MacToStr(tmp, sizeof(tmp), br->TapMacAddress);\r
+                       CfgAddStr(f, "TapMacAddress", tmp);\r
+               }\r
+       }\r
+}\r
+\r
+// ブリッジ一覧を書き出す\r
+void SiWriteLocalBridges(FOLDER *f, SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(s->Cedar->LocalBridgeList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(s->Cedar->LocalBridgeList);i++)\r
+               {\r
+                       LOCALBRIDGE *br = LIST_DATA(s->Cedar->LocalBridgeList, i);\r
+                       char name[MAX_SIZE];\r
+\r
+                       Format(name, sizeof(name), "LocalBridge%u", i);\r
+                       SiWriteLocalBridgeCfg(CfgCreateFolder(f, name), br);\r
+               }\r
+       }\r
+       UnlockList(s->Cedar->LocalBridgeList);\r
+}\r
+\r
+// ブリッジを読み込む\r
+void SiLoadLocalBridgeCfg(SERVER *s, FOLDER *f)\r
+{\r
+       char hub[MAX_SIZE];\r
+       char nic[MAX_SIZE];\r
+       bool tapmode = false;\r
+       UCHAR tapaddr[6];\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(hub, sizeof(hub));\r
+       Zero(nic, sizeof(nic));\r
+\r
+       CfgGetStr(f, "HubName", hub, sizeof(hub));\r
+       CfgGetStr(f, "DeviceName", nic, sizeof(nic));\r
+\r
+       if (IsEmptyStr(hub) || IsEmptyStr(nic))\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (OS_IS_UNIX(GetOsInfo()->OsType))\r
+       {\r
+               if (CfgGetBool(f, "TapMode"))\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+                       tapmode = true;\r
+                       Zero(tapaddr, sizeof(tapaddr));\r
+                       if (CfgGetStr(f, "TapMacAddress", tmp, sizeof(tmp)))\r
+                       {\r
+                               BUF *b;\r
+                               b = StrToBin(tmp);\r
+                               if (b != NULL && b->Size == 6)\r
+                               {\r
+                                       Copy(tapaddr, b->Buf, sizeof(tapaddr));\r
+                               }\r
+                               FreeBuf(b);\r
+                       }\r
+               }\r
+       }\r
+\r
+       AddLocalBridge(s->Cedar, hub, nic, CfgGetBool(f, "NoPromiscuousMode"), CfgGetBool(f, "MonitorMode"),\r
+               tapmode, tapaddr, CfgGetBool(f, "FullBroadcastMode"));\r
+}\r
+\r
+// ブリッジ一覧を読み込む\r
+void SiLoadLocalBridges(SERVER *s, FOLDER *f)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = CfgEnumFolderToTokenList(f);\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               char *name = t->Token[i];\r
+\r
+               SiLoadLocalBridgeCfg(s, CfgGetFolder(f, name));\r
+       }\r
+\r
+       FreeToken(t);\r
+}\r
+\r
+// サーバーの設定リビジョンをインクリメントする\r
+void IncrementServerConfigRevision(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s->ConfigRevision++;\r
+}\r
+\r
+// サーバー設定を CFG に書き出す\r
+FOLDER *SiWriteConfigurationToCfg(SERVER *s)\r
+{\r
+       FOLDER *root;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       root = CfgCreateFolder(NULL, TAG_ROOT);\r
+\r
+       CfgAddInt(root, "ConfigRevision", s->ConfigRevision);\r
+\r
+       SiWriteListeners(CfgCreateFolder(root, "ListenerList"), s);\r
+\r
+       SiWriteLocalBridges(CfgCreateFolder(root, "LocalBridgeList"), s);\r
+\r
+       SiWriteServerCfg(CfgCreateFolder(root, "ServerConfiguration"), s);\r
+\r
+       if (s->UpdatedServerType != SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               SiWriteHubs(CfgCreateFolder(root, "VirtualHUB"), s);\r
+       }\r
+\r
+       if (s->Cedar->Bridge == false)\r
+       {\r
+               SiWriteL3Switchs(CfgCreateFolder(root, "VirtualLayer3SwitchList"), s);\r
+\r
+               if (GetServerCapsBool(s, "b_support_license"))\r
+               {\r
+                       SiWriteLicenseManager(CfgCreateFolder(root, "LicenseManager"), s);\r
+               }\r
+       }\r
+\r
+       return root;\r
+}\r
+\r
+// ポリシーの読み込み\r
+void SiLoadPolicyCfg(POLICY *p, FOLDER *f)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(p, sizeof(POLICY));\r
+\r
+       // Ver 2\r
+       p->Access = CfgGetBool(f, "Access");\r
+       p->DHCPFilter = CfgGetBool(f, "DHCPFilter");\r
+       p->DHCPNoServer = CfgGetBool(f, "DHCPNoServer");\r
+       p->DHCPForce = CfgGetBool(f, "DHCPForce");\r
+       p->NoBridge = CfgGetBool(f, "NoBridge");\r
+       p->NoRouting = CfgGetBool(f, "NoRouting");\r
+       p->CheckMac = CfgGetBool(f, "CheckMac");\r
+       p->CheckIP = CfgGetBool(f, "CheckIP");\r
+       p->ArpDhcpOnly = CfgGetBool(f, "ArpDhcpOnly");\r
+       p->PrivacyFilter = CfgGetBool(f, "PrivacyFilter");\r
+       p->NoServer = CfgGetBool(f, "NoServer");\r
+       p->NoBroadcastLimiter = CfgGetBool(f, "NoBroadcastLimiter");\r
+       p->MonitorPort = CfgGetBool(f, "MonitorPort");\r
+       p->MaxConnection = CfgGetInt(f, "MaxConnection");\r
+       p->TimeOut = CfgGetInt(f, "TimeOut");\r
+       p->MaxMac = CfgGetInt(f, "MaxMac");\r
+       p->MaxIP = CfgGetInt(f, "MaxIP");\r
+       p->MaxUpload = CfgGetInt(f, "MaxUpload");\r
+       p->MaxDownload = CfgGetInt(f, "MaxDownload");\r
+       p->FixPassword = CfgGetBool(f, "FixPassword");\r
+       p->MultiLogins = CfgGetInt(f, "MultiLogins");\r
+       p->NoQoS = CfgGetBool(f, "NoQoS");\r
+\r
+       // Ver 3\r
+       p->RSandRAFilter = CfgGetBool(f, "RSandRAFilter");\r
+       p->RAFilter = CfgGetBool(f, "RAFilter");\r
+       p->DHCPv6Filter = CfgGetBool(f, "DHCPv6Filter");\r
+       p->DHCPv6NoServer = CfgGetBool(f, "DHCPv6NoServer");\r
+       p->NoRoutingV6 = CfgGetBool(f, "NoRoutingV6");\r
+       p->CheckIPv6 = CfgGetBool(f, "CheckIPv6");\r
+       p->NoServerV6 = CfgGetBool(f, "NoServerV6");\r
+       p->MaxIPv6 = CfgGetInt(f, "MaxIPv6");\r
+       p->NoSavePassword = CfgGetBool(f, "NoSavePassword");\r
+       p->AutoDisconnect = CfgGetInt(f, "AutoDisconnect");\r
+       p->FilterIPv4 = CfgGetBool(f, "FilterIPv4");\r
+       p->FilterIPv6 = CfgGetBool(f, "FilterIPv6");\r
+       p->FilterNonIP = CfgGetBool(f, "FilterNonIP");\r
+       p->NoIPv6DefaultRouterInRA = CfgGetBool(f, "NoIPv6DefaultRouterInRA");\r
+       p->NoIPv6DefaultRouterInRAWhenIPv6 = CfgGetBool(f, "NoIPv6DefaultRouterInRAWhenIPv6");\r
+       p->VLanId = CfgGetInt(f, "VLanId");\r
+}\r
+\r
+// ポリシーの書き込み\r
+void SiWritePolicyCfg(FOLDER *f, POLICY *p, bool cascade_mode)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // Ver 2.0\r
+       if (cascade_mode == false)\r
+       {\r
+               CfgAddBool(f, "Access", p->Access);\r
+       }\r
+\r
+       CfgAddBool(f, "DHCPFilter", p->DHCPFilter);\r
+       CfgAddBool(f, "DHCPNoServer", p->DHCPNoServer);\r
+       CfgAddBool(f, "DHCPForce", p->DHCPForce);\r
+\r
+       if (cascade_mode == false)\r
+       {\r
+               CfgAddBool(f, "NoBridge", p->NoBridge);\r
+               CfgAddBool(f, "NoRouting", p->NoRouting);\r
+       }\r
+\r
+       CfgAddBool(f, "CheckMac", p->CheckMac);\r
+       CfgAddBool(f, "CheckIP", p->CheckIP);\r
+       CfgAddBool(f, "ArpDhcpOnly", p->ArpDhcpOnly);\r
+\r
+       if (cascade_mode == false)\r
+       {\r
+               CfgAddBool(f, "PrivacyFilter", p->PrivacyFilter);\r
+       }\r
+\r
+       CfgAddBool(f, "NoServer", p->NoServer);\r
+       CfgAddBool(f, "NoBroadcastLimiter", p->NoBroadcastLimiter);\r
+\r
+       if (cascade_mode == false)\r
+       {\r
+               CfgAddBool(f, "MonitorPort", p->MonitorPort);\r
+               CfgAddInt(f, "MaxConnection", p->MaxConnection);\r
+               CfgAddInt(f, "TimeOut", p->TimeOut);\r
+       }\r
+\r
+       CfgAddInt(f, "MaxMac", p->MaxMac);\r
+       CfgAddInt(f, "MaxIP", p->MaxIP);\r
+       CfgAddInt(f, "MaxUpload", p->MaxUpload);\r
+       CfgAddInt(f, "MaxDownload", p->MaxDownload);\r
+\r
+       if (cascade_mode == false)\r
+       {\r
+               CfgAddBool(f, "FixPassword", p->FixPassword);\r
+               CfgAddInt(f, "MultiLogins", p->MultiLogins);\r
+               CfgAddBool(f, "NoQoS", p->NoQoS);\r
+       }\r
+\r
+       // Ver 3.0\r
+       CfgAddBool(f, "RSandRAFilter", p->RSandRAFilter);\r
+       CfgAddBool(f, "RAFilter", p->RAFilter);\r
+       CfgAddBool(f, "DHCPv6Filter", p->DHCPv6Filter);\r
+       CfgAddBool(f, "DHCPv6NoServer", p->DHCPv6NoServer);\r
+\r
+       if (cascade_mode == false)\r
+       {\r
+               CfgAddBool(f, "NoRoutingV6", p->NoRoutingV6);\r
+       }\r
+\r
+       CfgAddBool(f, "CheckIPv6", p->CheckIPv6);\r
+       CfgAddBool(f, "NoServerV6", p->NoServerV6);\r
+       CfgAddInt(f, "MaxIPv6", p->MaxIPv6);\r
+\r
+       if (cascade_mode == false)\r
+       {\r
+               CfgAddBool(f, "NoSavePassword", p->NoSavePassword);\r
+               CfgAddInt(f, "AutoDisconnect", p->AutoDisconnect);\r
+       }\r
+\r
+       CfgAddBool(f, "FilterIPv4", p->FilterIPv4);\r
+       CfgAddBool(f, "FilterIPv6", p->FilterIPv6);\r
+       CfgAddBool(f, "FilterNonIP", p->FilterNonIP);\r
+       CfgAddBool(f, "NoIPv6DefaultRouterInRA", p->NoIPv6DefaultRouterInRA);\r
+       CfgAddBool(f, "NoIPv6DefaultRouterInRAWhenIPv6", p->NoIPv6DefaultRouterInRAWhenIPv6);\r
+       CfgAddInt(f, "VLanId", p->VLanId);\r
+}\r
+\r
+// 仮想 HUB のリンク情報の書き込み\r
+void SiWriteHubLinkCfg(FOLDER *f, LINK *k)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(k->lock);\r
+       {\r
+               // オンライン\r
+               CfgAddBool(f, "Online", k->Offline ? false : true);\r
+\r
+               // クライアントオプション\r
+               CiWriteClientOption(CfgCreateFolder(f, "ClientOption"), k->Option);\r
+\r
+               // クライアント認証データ\r
+               CiWriteClientAuth(CfgCreateFolder(f, "ClientAuth"), k->Auth);\r
+\r
+               // ポリシー\r
+               if (k->Policy != NULL)\r
+               {\r
+                       SiWritePolicyCfg(CfgCreateFolder(f, "Policy"), k->Policy, true);\r
+               }\r
+\r
+               CfgAddBool(f, "CheckServerCert", k->CheckServerCert);\r
+\r
+               if (k->ServerCert != NULL)\r
+               {\r
+                       BUF *b = XToBuf(k->ServerCert, false);\r
+                       CfgAddBuf(f, "ServerCert", b);\r
+                       FreeBuf(b);\r
+               }\r
+       }\r
+       Unlock(k->lock);\r
+}\r
+\r
+// リンク情報の読み込み\r
+void SiLoadHubLinkCfg(FOLDER *f, HUB *h)\r
+{\r
+       bool online;\r
+       CLIENT_OPTION *o;\r
+       CLIENT_AUTH *a;\r
+       FOLDER *pf;\r
+       POLICY p;\r
+       LINK *k;\r
+       // 引数チェック\r
+       if (f == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pf = CfgGetFolder(f, "Policy");\r
+       if (pf == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SiLoadPolicyCfg(&p, pf);\r
+\r
+       online = CfgGetBool(f, "Online");\r
+\r
+       o = CiLoadClientOption(CfgGetFolder(f, "ClientOption"));\r
+       a = CiLoadClientAuth(CfgGetFolder(f, "ClientAuth"));\r
+       if (o == NULL || a == NULL)\r
+       {\r
+               Free(o);\r
+               CiFreeClientAuth(a);\r
+               return;\r
+       }\r
+\r
+       k = NewLink(h->Cedar, h, o, a, &p);\r
+       if (k != NULL)\r
+       {\r
+               BUF *b;\r
+               k->CheckServerCert = CfgGetBool(f, "CheckServerCert");\r
+               b = CfgGetBuf(f, "ServerCert");\r
+               if (b != NULL)\r
+               {\r
+                       k->ServerCert = BufToX(b, false);\r
+                       FreeBuf(b);\r
+               }\r
+\r
+               if (online)\r
+               {\r
+                       k->Offline = true;\r
+                       SetLinkOnline(k);\r
+               }\r
+               else\r
+               {\r
+                       k->Offline = false;\r
+                       SetLinkOffline(k);\r
+               }\r
+               ReleaseLink(k);\r
+       }\r
+\r
+       Free(o);\r
+       CiFreeClientAuth(a);\r
+}\r
+\r
+// 仮想 HUB の SecureNAT の書き込み\r
+void SiWriteSecureNAT(HUB *h, FOLDER *f)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CfgAddBool(f, "Disabled", h->EnableSecureNAT ? false : true);\r
+\r
+       NiWriteVhOptionEx(h->SecureNATOption, f);\r
+}\r
+\r
+// 仮想 HUB の管理オプションの読み込み\r
+void SiLoadHubAdminOptions(HUB *h, FOLDER *f)\r
+{\r
+       TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (h == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = CfgEnumItemToTokenList(f);\r
+       if (t != NULL)\r
+       {\r
+               UINT i;\r
+\r
+               LockList(h->AdminOptionList);\r
+               {\r
+                       DeleteAllHubAdminOption(h, false);\r
+\r
+                       for (i = 0;i < t->NumTokens;i++)\r
+                       {\r
+                               char *name = t->Token[i];\r
+                               ADMIN_OPTION *a;\r
+                               UINT value = CfgGetInt(f, name);;\r
+\r
+                               Trim(name);\r
+\r
+                               a = ZeroMalloc(sizeof(ADMIN_OPTION));\r
+                               StrCpy(a->Name, sizeof(a->Name), name);\r
+                               a->Value = value;\r
+\r
+                               Insert(h->AdminOptionList, a);\r
+                       }\r
+\r
+                       AddHubAdminOptionsDefaults(h, false);\r
+               }\r
+               UnlockList(h->AdminOptionList);\r
+\r
+               FreeToken(t);\r
+       }\r
+}\r
+\r
+// 仮想 HUB の管理オプションの書き込み\r
+void SiWriteHubAdminOptions(FOLDER *f, HUB *h)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(h->AdminOptionList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(h->AdminOptionList);i++)\r
+               {\r
+                       ADMIN_OPTION *a = LIST_DATA(h->AdminOptionList, i);\r
+\r
+                       CfgAddInt(f, a->Name, a->Value);\r
+               }\r
+       }\r
+       UnlockList(h->AdminOptionList);\r
+}\r
+\r
+// 仮想 HUB のリンクリストの書き込み\r
+void SiWriteHubLinks(FOLDER *f, HUB *h)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(h->LinkList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(h->LinkList);i++)\r
+               {\r
+                       LINK *k = LIST_DATA(h->LinkList, i);\r
+                       char name[MAX_SIZE];\r
+                       Format(name, sizeof(name), "Cascade%u", i);\r
+                       SiWriteHubLinkCfg(CfgCreateFolder(f, name), k);\r
+               }\r
+       }\r
+       UnlockList(h->LinkList);\r
+}\r
+\r
+// リンクリストの読み込み\r
+void SiLoadHubLinks(HUB *h, FOLDER *f)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (h == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = CfgEnumFolderToTokenList(f);\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               char *name = t->Token[i];\r
+               SiLoadHubLinkCfg(CfgGetFolder(f, name), h);\r
+       }\r
+\r
+       FreeToken(t);\r
+}\r
+\r
+// アクセスリスト項目の書き込み\r
+void SiWriteHubAccessCfg(FOLDER *f, ACCESS *a)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CfgAddUniStr(f, "Note", a->Note);\r
+       CfgAddBool(f, "Active", a->Active);\r
+       CfgAddInt(f, "Priority", a->Priority);\r
+       CfgAddBool(f, "Discard", a->Discard);\r
+       CfgAddBool(f, "IsIPv6", a->IsIPv6);\r
+\r
+       if (a->IsIPv6 == false)\r
+       {\r
+               CfgAddIp32(f, "SrcIpAddress", a->SrcIpAddress);\r
+               CfgAddIp32(f, "SrcSubnetMask", a->SrcSubnetMask);\r
+               CfgAddIp32(f, "DestIpAddress", a->DestIpAddress);\r
+               CfgAddIp32(f, "DestSubnetMask", a->DestSubnetMask);\r
+       }\r
+       else\r
+       {\r
+               CfgAddIp6Addr(f, "SrcIpAddress6", &a->SrcIpAddress6);\r
+               CfgAddIp6Addr(f, "SrcSubnetMask6", &a->SrcSubnetMask6);\r
+               CfgAddIp6Addr(f, "DestIpAddress6", &a->DestIpAddress6);\r
+               CfgAddIp6Addr(f, "DestSubnetMask6", &a->DestSubnetMask6);\r
+       }\r
+\r
+       CfgAddInt(f, "Protocol", a->Protocol);\r
+       CfgAddInt(f, "SrcPortStart", a->SrcPortStart);\r
+       CfgAddInt(f, "SrcPortEnd", a->SrcPortEnd);\r
+       CfgAddInt(f, "DestPortStart", a->DestPortStart);\r
+       CfgAddInt(f, "DestPortEnd", a->DestPortEnd);\r
+       CfgAddStr(f, "SrcUsername", a->SrcUsername);\r
+       CfgAddStr(f, "DestUsername", a->DestUsername);\r
+       CfgAddBool(f, "CheckSrcMac", a->CheckSrcMac);\r
+\r
+       if (a->CheckSrcMac)\r
+       {\r
+               char tmp[MAX_PATH];\r
+\r
+               MacToStr(tmp, sizeof(tmp), a->SrcMacAddress);\r
+               CfgAddStr(f, "SrcMacAddress", tmp);\r
+\r
+               MacToStr(tmp, sizeof(tmp), a->SrcMacMask);\r
+               CfgAddStr(f, "SrcMacMask", tmp);\r
+       }\r
+\r
+       CfgAddBool(f, "CheckDstMac", a->CheckDstMac);\r
+\r
+       if (a->CheckDstMac)\r
+       {\r
+               char tmp[MAX_PATH];\r
+\r
+               MacToStr(tmp, sizeof(tmp), a->DstMacAddress);\r
+               CfgAddStr(f, "DstMacAddress", tmp);\r
+\r
+               MacToStr(tmp, sizeof(tmp), a->DstMacMask);\r
+               CfgAddStr(f, "DstMacMask", tmp);\r
+       }\r
+\r
+       CfgAddBool(f, "CheckTcpState", a->CheckTcpState);\r
+       CfgAddBool(f, "Established", a->Established);\r
+\r
+       CfgAddInt(f, "Delay", a->Delay);\r
+       CfgAddInt(f, "Jitter", a->Jitter);\r
+       CfgAddInt(f, "Loss", a->Loss);\r
+}\r
+\r
+// アクセスリスト項目の読み込み\r
+void SiLoadHubAccessCfg(HUB *h, FOLDER *f)\r
+{\r
+       ACCESS a;\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (h == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&a, sizeof(a));\r
+\r
+       CfgGetUniStr(f, "Note", a.Note, sizeof(a.Note));\r
+       a.Active = CfgGetBool(f, "Active");\r
+       a.Priority = CfgGetInt(f, "Priority");\r
+       a.Discard = CfgGetBool(f, "Discard");\r
+       a.IsIPv6 = CfgGetBool(f, "IsIPv6");\r
+\r
+       if (a.IsIPv6 == false)\r
+       {\r
+               a.SrcIpAddress = CfgGetIp32(f, "SrcIpAddress");\r
+               a.SrcSubnetMask = CfgGetIp32(f, "SrcSubnetMask");\r
+               a.DestIpAddress = CfgGetIp32(f, "DestIpAddress");\r
+               a.DestSubnetMask = CfgGetIp32(f, "DestSubnetMask");\r
+       }\r
+       else\r
+       {\r
+               CfgGetIp6Addr(f, "SrcIpAddress6", &a.SrcIpAddress6);\r
+               CfgGetIp6Addr(f, "SrcSubnetMask6", &a.SrcSubnetMask6);\r
+               CfgGetIp6Addr(f, "DestIpAddress6", &a.DestIpAddress6);\r
+               CfgGetIp6Addr(f, "DestSubnetMask6", &a.DestSubnetMask6);\r
+       }\r
+\r
+       a.Protocol = CfgGetInt(f, "Protocol");\r
+       a.SrcPortStart = CfgGetInt(f, "SrcPortStart");\r
+       a.SrcPortEnd = CfgGetInt(f, "SrcPortEnd");\r
+       a.DestPortStart = CfgGetInt(f, "DestPortStart");\r
+       a.DestPortEnd = CfgGetInt(f, "DestPortEnd");\r
+       CfgGetStr(f, "SrcUsername", a.SrcUsername, sizeof(a.SrcUsername));\r
+       CfgGetStr(f, "DestUsername", a.DestUsername, sizeof(a.DestUsername));\r
+       a.CheckSrcMac = CfgGetBool(f, "CheckSrcMac");\r
+\r
+       if (CfgGetByte(f, "SrcMacAddress", a.SrcMacAddress, sizeof(a.SrcMacAddress)) == 0)\r
+       {\r
+               CfgGetStr(f, "SrcMacAddress", tmp, sizeof(tmp));\r
+               if (StrToMac(a.SrcMacAddress, tmp) == false)\r
+               {\r
+                       a.CheckSrcMac = false;\r
+               }\r
+       }\r
+\r
+       if (CfgGetByte(f, "SrcMacMask", a.SrcMacMask, sizeof(a.SrcMacMask)) == 0)\r
+       {\r
+               CfgGetStr(f, "SrcMacMask", tmp, sizeof(tmp));\r
+               if (StrToMac(a.SrcMacMask, tmp) == false)\r
+               {\r
+                       a.CheckSrcMac = false;\r
+               }\r
+       }\r
+\r
+       a.CheckDstMac = CfgGetBool(f, "CheckDstMac");\r
+\r
+       if (CfgGetByte(f, "DstMacAddress", a.DstMacAddress, sizeof(a.DstMacAddress)) == 0)\r
+       {\r
+               CfgGetStr(f, "DstMacAddress", tmp, sizeof(tmp));\r
+               if (StrToMac(a.DstMacAddress, tmp) == false)\r
+               {\r
+                       a.CheckDstMac = false;\r
+               }\r
+       }\r
+\r
+       if (CfgGetByte(f, "DstMacMask", a.DstMacMask, sizeof(a.DstMacMask)) == 0)\r
+       {\r
+               CfgGetStr(f, "DstMacMask", tmp, sizeof(tmp));\r
+               if (StrToMac(a.DstMacMask, tmp) == false)\r
+               {\r
+                       a.CheckDstMac = false;\r
+               }\r
+       }\r
+\r
+       a.CheckTcpState = CfgGetBool(f, "CheckTcpState");\r
+       a.Established = CfgGetBool(f, "Established");\r
+       a.Delay = MAKESURE(CfgGetInt(f, "Delay"), 0, HUB_ACCESSLIST_DELAY_MAX);\r
+       a.Jitter = MAKESURE(CfgGetInt(f, "Jitter"), 0, HUB_ACCESSLIST_JITTER_MAX);\r
+       a.Loss = MAKESURE(CfgGetInt(f, "Loss"), 0, HUB_ACCESSLIST_LOSS_MAX);\r
+\r
+       AddAccessList(h, &a);\r
+}\r
+\r
+// アクセスリストの書き込み\r
+void SiWriteHubAccessLists(FOLDER *f, HUB *h)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(h->AccessList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(h->AccessList);i++)\r
+               {\r
+                       ACCESS *a = LIST_DATA(h->AccessList, i);\r
+                       char name[MAX_SIZE];\r
+                       ToStr(name, a->Id);\r
+                       SiWriteHubAccessCfg(CfgCreateFolder(f, name), a);\r
+               }\r
+       }\r
+       UnlockList(h->AccessList);\r
+}\r
+\r
+// アクセスリストの読み込み\r
+void SiLoadHubAccessLists(HUB *h, FOLDER *f)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (f == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = CfgEnumFolderToTokenList(f);\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               char *name = t->Token[i];\r
+               UINT id = ToInt(name);\r
+               SiLoadHubAccessCfg(h, CfgGetFolder(f, name));\r
+       }\r
+\r
+       FreeToken(t);\r
+}\r
+\r
+// HUB_OPTION の読み込み\r
+void SiLoadHubOptionCfg(FOLDER *f, HUB_OPTION *o)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (f == NULL || o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o->MaxSession = CfgGetInt(f, "MaxSession");\r
+       o->NoArpPolling = CfgGetBool(f, "NoArpPolling");\r
+       o->NoIPv6AddrPolling = CfgGetBool(f, "NoIPv6AddrPolling");\r
+       o->NoIpTable = CfgGetBool(f, "NoIpTable");\r
+       o->NoEnum = CfgGetBool(f, "NoEnum");\r
+       o->FilterPPPoE = CfgGetBool(f, "FilterPPPoE");\r
+       o->FilterOSPF = CfgGetBool(f, "FilterOSPF");\r
+       o->FilterIPv4 = CfgGetBool(f, "FilterIPv4");\r
+       o->FilterIPv6 = CfgGetBool(f, "FilterIPv6");\r
+       o->FilterNonIP = CfgGetBool(f, "FilterNonIP");\r
+       o->FilterBPDU = CfgGetBool(f, "FilterBPDU");\r
+       o->NoIPv4PacketLog = CfgGetBool(f, "NoIPv4PacketLog");\r
+       o->NoIPv6PacketLog = CfgGetBool(f, "NoIPv6PacketLog");\r
+       o->NoIPv6DefaultRouterInRAWhenIPv6 = CfgGetBool(f, "NoIPv6DefaultRouterInRAWhenIPv6");\r
+       o->DisableIPParsing = CfgGetBool(f, "DisableIPParsing");\r
+       o->YieldAfterStorePacket = CfgGetBool(f, "YieldAfterStorePacket");\r
+       o->NoSpinLockForPacketDelay = CfgGetBool(f, "NoSpinLockForPacketDelay");\r
+       o->BroadcastStormDetectionThreshold = CfgGetInt(f, "BroadcastStormDetectionThreshold");\r
+       o->ClientMinimumRequiredBuild = CfgGetInt(f, "ClientMinimumRequiredBuild");\r
+       o->RequiredClientId = CfgGetInt(f, "RequiredClientId");\r
+       o->NoManageVlanId = CfgGetBool(f, "NoManageVlanId");\r
+       o->VlanTypeId = 0;\r
+       if (CfgGetStr(f, "VlanTypeId", tmp, sizeof(tmp)))\r
+       {\r
+               o->VlanTypeId = HexToInt(tmp);\r
+       }\r
+       if (o->VlanTypeId == 0)\r
+       {\r
+               o->VlanTypeId = MAC_PROTO_TAGVLAN;\r
+       }\r
+       o->FixForDLinkBPDU = CfgGetBool(f, "FixForDLinkBPDU");\r
+       o->NoLookBPDUBridgeId = CfgGetBool(f, "NoLookBPDUBridgeId");\r
+\r
+       // デフォルトで有効\r
+       if (CfgIsItem(f, "ManageOnlyPrivateIP"))\r
+       {\r
+               o->ManageOnlyPrivateIP = CfgGetBool(f, "ManageOnlyPrivateIP");\r
+       }\r
+       else\r
+       {\r
+               o->ManageOnlyPrivateIP = true;\r
+       }\r
+       if (CfgIsItem(f, "ManageOnlyLocalUnicastIPv6"))\r
+       {\r
+               o->ManageOnlyLocalUnicastIPv6 = CfgGetBool(f, "ManageOnlyLocalUnicastIPv6");\r
+       }\r
+       else\r
+       {\r
+               o->ManageOnlyLocalUnicastIPv6 = true;\r
+       }\r
+       if (CfgIsItem(f, "NoMacAddressLog"))\r
+       {\r
+               o->NoMacAddressLog = CfgGetBool(f, "NoMacAddressLog");\r
+       }\r
+       else\r
+       {\r
+               o->NoMacAddressLog = true;\r
+       }\r
+}\r
+\r
+// HUB_OPTION の書き込み\r
+void SiWriteHubOptionCfg(FOLDER *f, HUB_OPTION *o)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (f == NULL || o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CfgAddInt(f, "MaxSession", o->MaxSession);\r
+       CfgAddBool(f, "NoArpPolling", o->NoArpPolling);\r
+       CfgAddBool(f, "NoIPv6AddrPolling", o->NoIPv6AddrPolling);\r
+       CfgAddBool(f, "NoIpTable", o->NoIpTable);\r
+       CfgAddBool(f, "NoEnum", o->NoEnum);\r
+       CfgAddBool(f, "FilterPPPoE", o->FilterPPPoE);\r
+       CfgAddBool(f, "FilterOSPF", o->FilterOSPF);\r
+       CfgAddBool(f, "FilterIPv4", o->FilterIPv4);\r
+       CfgAddBool(f, "FilterIPv6", o->FilterIPv6);\r
+       CfgAddBool(f, "FilterNonIP", o->FilterNonIP);\r
+       CfgAddBool(f, "NoIPv4PacketLog", o->NoIPv4PacketLog);\r
+       CfgAddBool(f, "NoIPv6PacketLog", o->NoIPv6PacketLog);\r
+       CfgAddBool(f, "FilterBPDU", o->FilterBPDU);\r
+       CfgAddBool(f, "NoIPv6DefaultRouterInRAWhenIPv6", o->NoIPv6DefaultRouterInRAWhenIPv6);\r
+       CfgAddBool(f, "NoMacAddressLog", o->NoMacAddressLog);\r
+       CfgAddBool(f, "ManageOnlyPrivateIP", o->ManageOnlyPrivateIP);\r
+       CfgAddBool(f, "ManageOnlyLocalUnicastIPv6", o->ManageOnlyLocalUnicastIPv6);\r
+       CfgAddBool(f, "DisableIPParsing", o->DisableIPParsing);\r
+       CfgAddBool(f, "YieldAfterStorePacket", o->YieldAfterStorePacket);\r
+       CfgAddBool(f, "NoSpinLockForPacketDelay", o->NoSpinLockForPacketDelay);\r
+       CfgAddInt(f, "BroadcastStormDetectionThreshold", o->BroadcastStormDetectionThreshold);\r
+       CfgAddInt(f, "ClientMinimumRequiredBuild", o->ClientMinimumRequiredBuild);\r
+       CfgAddInt(f, "RequiredClientId", o->RequiredClientId);\r
+       CfgAddBool(f, "NoManageVlanId", o->NoManageVlanId);\r
+       Format(tmp, sizeof(tmp), "0x%x", o->VlanTypeId);\r
+       CfgAddStr(f, "VlanTypeId", tmp);\r
+       if (o->FixForDLinkBPDU)\r
+       {\r
+               CfgAddBool(f, "FixForDLinkBPDU", o->FixForDLinkBPDU);\r
+       }\r
+       CfgAddBool(f, "NoLookBPDUBridgeId", o->NoLookBPDUBridgeId);\r
+}\r
+\r
+// ユーザーの書き込み\r
+void SiWriteUserCfg(FOLDER *f, USER *u)\r
+{\r
+       AUTHPASSWORD *password;\r
+       // 引数チェック\r
+       if (f == NULL || u == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(u->lock);\r
+       {\r
+               CfgAddUniStr(f, "RealName", u->RealName);\r
+               CfgAddUniStr(f, "Note", u->Note);\r
+               if (u->Group != NULL)\r
+               {\r
+                       CfgAddStr(f, "GroupName", u->GroupName);\r
+               }\r
+               CfgAddInt64(f, "CreatedTime", u->CreatedTime);\r
+               CfgAddInt64(f, "UpdatedTime", u->UpdatedTime);\r
+               CfgAddInt64(f, "ExpireTime", u->ExpireTime);\r
+               CfgAddInt64(f, "LastLoginTime", u->LastLoginTime);\r
+               CfgAddInt(f, "NumLogin", u->NumLogin);\r
+               if (u->Policy != NULL)\r
+               {\r
+                       SiWritePolicyCfg(CfgCreateFolder(f, "Policy"), u->Policy, false);\r
+               }\r
+               SiWriteTraffic(f, "Traffic", u->Traffic);\r
+\r
+               CfgAddInt(f, "AuthType", u->AuthType);\r
+               if (u->AuthData != NULL)\r
+               {\r
+                       switch (u->AuthType)\r
+                       {\r
+                       case AUTHTYPE_ANONYMOUS:\r
+                               break;\r
+\r
+                       case AUTHTYPE_PASSWORD:\r
+                               password = (AUTHPASSWORD *)u->AuthData;\r
+                               CfgAddByte(f, "AuthPassword", password->HashedKey, sizeof(password->HashedKey));\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       Unlock(u->lock);\r
+}\r
+\r
+// ユーザーの読み込み\r
+void SiLoadUserCfg(HUB *h, FOLDER *f)\r
+{\r
+       char *username;\r
+       wchar_t realname[MAX_SIZE];\r
+       wchar_t note[MAX_SIZE];\r
+       char groupname[MAX_SIZE];\r
+       FOLDER *pf;\r
+       UINT64 created_time;\r
+       UINT64 updated_time;\r
+       UINT64 expire_time;\r
+       UINT64 last_login_time;\r
+       UINT num_login;\r
+       POLICY p;\r
+       TRAFFIC t;\r
+       UINT authtype;\r
+       void *authdata;\r
+       X_SERIAL *serial = NULL;\r
+       UCHAR hashed_password[SHA1_SIZE];\r
+       USER *u;\r
+       USERGROUP *g;\r
+       // 引数チェック\r
+       if (h == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       username = f->Name;\r
+       CfgGetUniStr(f, "RealName", realname, sizeof(realname));\r
+       CfgGetUniStr(f, "Note", note, sizeof(note));\r
+       CfgGetStr(f, "GroupName", groupname, sizeof(groupname));\r
+\r
+       created_time = CfgGetInt64(f, "CreatedTime");\r
+       updated_time = CfgGetInt64(f, "UpdatedTime");\r
+       expire_time = CfgGetInt64(f, "ExpireTime");\r
+       last_login_time = CfgGetInt64(f, "LastLoginTime");\r
+       num_login = CfgGetInt(f, "NumLogin");\r
+       pf = CfgGetFolder(f, "Policy");\r
+       if (pf != NULL)\r
+       {\r
+               SiLoadPolicyCfg(&p, pf);\r
+       }\r
+       SiLoadTraffic(f, "Traffic", &t);\r
+\r
+       authtype = CfgGetInt(f, "AuthType");\r
+       authdata = NULL;\r
+\r
+       switch (authtype)\r
+       {\r
+       case AUTHTYPE_PASSWORD:\r
+               // 通常のパスワード認証\r
+               CfgGetByte(f, "AuthPassword", hashed_password, sizeof(hashed_password));\r
+               authdata = NewPasswordAuthDataRaw(hashed_password);\r
+               break;\r
+\r
+       default:\r
+               // それ以外の認証方法が指定された\r
+               authtype = AUTHTYPE_ANONYMOUS;\r
+               authdata = NULL;\r
+               break;\r
+       }\r
+\r
+       // ユーザーの追加\r
+       AcLock(h);\r
+       {\r
+               if (StrLen(groupname) > 0)\r
+               {\r
+                       g = AcGetGroup(h, groupname);\r
+               }\r
+               else\r
+               {\r
+                       g = NULL;\r
+               }\r
+\r
+               u = NewUser(username, realname, note, authtype, authdata);\r
+               if (u != NULL)\r
+               {\r
+                       if (g != NULL)\r
+                       {\r
+                               JoinUserToGroup(u, g);\r
+                       }\r
+\r
+                       SetUserTraffic(u, &t);\r
+\r
+                       if (pf != NULL)\r
+                       {\r
+                               SetUserPolicy(u, &p);\r
+                       }\r
+\r
+                       Lock(u->lock);\r
+                       {\r
+                               u->CreatedTime = created_time;\r
+                               u->UpdatedTime = updated_time;\r
+                               u->ExpireTime = expire_time;\r
+                               u->LastLoginTime = last_login_time;\r
+                               u->NumLogin = num_login;\r
+                       }\r
+                       Unlock(u->lock);\r
+\r
+                       AcAddUser(h, u);\r
+\r
+                       ReleaseUser(u);\r
+               }\r
+\r
+               if (g != NULL)\r
+               {\r
+                       ReleaseGroup(g);\r
+               }\r
+       }\r
+       AcUnlock(h);\r
+\r
+       if (serial != NULL)\r
+       {\r
+               FreeXSerial(serial);\r
+       }\r
+}\r
+\r
+// ユーザーリストの書き込み\r
+void SiWriteUserList(FOLDER *f, LIST *o)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(o);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       USER *u = LIST_DATA(o, i);\r
+                       SiWriteUserCfg(CfgCreateFolder(f, u->Name), u);\r
+               }\r
+       }\r
+       UnlockList(o);\r
+}\r
+\r
+// ユーザーリストの読み込み\r
+void SiLoadUserList(HUB *h, FOLDER *f)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       char *name;\r
+       // 引数チェック\r
+       if (f == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = CfgEnumFolderToTokenList(f);\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               FOLDER *ff;\r
+               name = t->Token[i];\r
+               ff = CfgGetFolder(f, name);\r
+               SiLoadUserCfg(h, ff);\r
+       }\r
+\r
+       FreeToken(t);\r
+}\r
+\r
+// グループ情報の書き込み\r
+void SiWriteGroupCfg(FOLDER *f, USERGROUP *g)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(g->lock);\r
+       {\r
+               CfgAddUniStr(f, "RealName", g->RealName);\r
+               CfgAddUniStr(f, "Note", g->Note);\r
+               if (g->Policy != NULL)\r
+               {\r
+                       SiWritePolicyCfg(CfgCreateFolder(f, "Policy"), g->Policy, false);\r
+               }\r
+               SiWriteTraffic(f, "Traffic", g->Traffic);\r
+       }\r
+       Unlock(g->lock);\r
+}\r
+\r
+// グループ情報の読み込み\r
+void SiLoadGroupCfg(HUB *h, FOLDER *f)\r
+{\r
+       wchar_t realname[MAX_SIZE];\r
+       wchar_t note[MAX_SIZE];\r
+       char *name;\r
+       FOLDER *pf;\r
+       POLICY p;\r
+       TRAFFIC t;\r
+       USERGROUP *g;\r
+       // 引数チェック\r
+       if (h == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       name = f->Name;\r
+\r
+       CfgGetUniStr(f, "RealName", realname, sizeof(realname));\r
+       CfgGetUniStr(f, "Note", note, sizeof(note));\r
+\r
+       pf = CfgGetFolder(f, "Policy");\r
+       if (pf != NULL)\r
+       {\r
+               SiLoadPolicyCfg(&p, pf);\r
+       }\r
+\r
+       SiLoadTraffic(f, "Traffic", &t);\r
+\r
+       g = NewGroup(name, realname, note);\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (pf != NULL)\r
+       {\r
+               SetGroupPolicy(g, &p);\r
+       }\r
+\r
+       SetGroupTraffic(g, &t);\r
+\r
+       AcLock(h);\r
+       {\r
+               AcAddGroup(h, g);\r
+       }\r
+       AcUnlock(h);\r
+\r
+       ReleaseGroup(g);\r
+}\r
+\r
+// グループリストの書き込み\r
+void SiWriteGroupList(FOLDER *f, LIST *o)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(o);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       USERGROUP *g = LIST_DATA(o, i);\r
+                       SiWriteGroupCfg(CfgCreateFolder(f, g->Name), g);\r
+               }\r
+       }\r
+       UnlockList(o);\r
+}\r
+\r
+// グループリストの読み込み\r
+void SiLoadGroupList(HUB *h, FOLDER *f)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       char *name;\r
+       // 引数チェック\r
+       if (f == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = CfgEnumFolderToTokenList(f);\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               name = t->Token[i];\r
+               SiLoadGroupCfg(h, CfgGetFolder(f, name));\r
+       }\r
+\r
+       FreeToken(t);\r
+}\r
+\r
+// 無効な証明書リストの書き込み\r
+void SiWriteCrlList(FOLDER *f, LIST *o)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(o);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       char name[MAX_SIZE];\r
+                       CRL *crl = LIST_DATA(o, i);\r
+                       FOLDER *ff;\r
+                       NAME *n;\r
+\r
+                       Format(name, sizeof(name), "Crl%u", i);\r
+\r
+                       ff = CfgCreateFolder(f, name);\r
+                       n = crl->Name;\r
+\r
+                       if (UniIsEmptyStr(n->CommonName) == false)\r
+                       {\r
+                               CfgAddUniStr(ff, "CommonName", n->CommonName);\r
+                       }\r
+\r
+                       if (UniIsEmptyStr(n->Organization) == false)\r
+                       {\r
+                               CfgAddUniStr(ff, "Organization", n->Organization);\r
+                       }\r
+\r
+                       if (UniIsEmptyStr(n->Unit) == false)\r
+                       {\r
+                               CfgAddUniStr(ff, "Unit", n->Unit);\r
+                       }\r
+\r
+                       if (UniIsEmptyStr(n->Country) == false)\r
+                       {\r
+                               CfgAddUniStr(ff, "Country", n->Country);\r
+                       }\r
+\r
+                       if (UniIsEmptyStr(n->State) == false)\r
+                       {\r
+                               CfgAddUniStr(ff, "State", n->State);\r
+                       }\r
+\r
+                       if (UniIsEmptyStr(n->Local) == false)\r
+                       {\r
+                               CfgAddUniStr(ff, "Local", n->Local);\r
+                       }\r
+\r
+                       if (IsZero(crl->DigestMD5, MD5_SIZE) == false)\r
+                       {\r
+                               char tmp[MAX_SIZE];\r
+\r
+                               BinToStr(tmp, sizeof(tmp), crl->DigestMD5, MD5_SIZE);\r
+                               CfgAddStr(ff, "DigestMD5", tmp);\r
+                       }\r
+\r
+                       if (IsZero(crl->DigestSHA1, SHA1_SIZE) == false)\r
+                       {\r
+                               char tmp[MAX_SIZE];\r
+\r
+                               BinToStr(tmp, sizeof(tmp), crl->DigestSHA1, SHA1_SIZE);\r
+                               CfgAddStr(ff, "DigestSHA1", tmp);\r
+                       }\r
+\r
+                       if (crl->Serial != NULL)\r
+                       {\r
+                               char tmp[MAX_SIZE];\r
+\r
+                               BinToStr(tmp, sizeof(tmp), crl->Serial->data, crl->Serial->size);\r
+                               CfgAddStr(ff, "Serial", tmp);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(o);\r
+}\r
+\r
+// 無効な証明書リストの読み込み\r
+void SiLoadCrlList(LIST *o, FOLDER *f)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(o);\r
+       {\r
+               UINT i;\r
+               TOKEN_LIST *t;\r
+\r
+               t = CfgEnumFolderToTokenList(f);\r
+\r
+               for (i = 0;i < t->NumTokens;i++)\r
+               {\r
+                       CRL *crl;\r
+                       FOLDER *ff = CfgGetFolder(f, t->Token[i]);\r
+                       wchar_t cn[MAX_SIZE], org[MAX_SIZE], u[MAX_SIZE], c[MAX_SIZE],\r
+                               st[MAX_SIZE], l[MAX_SIZE];\r
+                       char tmp[MAX_SIZE];\r
+\r
+                       if (ff != NULL)\r
+                       {\r
+                               BUF *b;\r
+\r
+                               crl = ZeroMalloc(sizeof(CRL));\r
+\r
+                               CfgGetUniStr(ff, "CommonName", cn, sizeof(cn));\r
+                               CfgGetUniStr(ff, "Organization", org, sizeof(org));\r
+                               CfgGetUniStr(ff, "Unit", u, sizeof(u));\r
+                               CfgGetUniStr(ff, "Country", c, sizeof(c));\r
+                               CfgGetUniStr(ff, "State", st, sizeof(st));\r
+                               CfgGetUniStr(ff, "Local", l, sizeof(l));\r
+\r
+                               crl->Name = NewName(cn, org, u, c, st, l);\r
+\r
+                               if (CfgGetStr(ff, "Serial", tmp, sizeof(tmp)))\r
+                               {\r
+                                       b = StrToBin(tmp);\r
+\r
+                                       if (b != NULL)\r
+                                       {\r
+                                               if (b->Size >= 1)\r
+                                               {\r
+                                                       crl->Serial = NewXSerial(b->Buf, b->Size);\r
+                                               }\r
+\r
+                                               FreeBuf(b);\r
+                                       }\r
+                               }\r
+\r
+                               if (CfgGetStr(ff, "DigestMD5", tmp, sizeof(tmp)))\r
+                               {\r
+                                       b = StrToBin(tmp);\r
+\r
+                                       if (b != NULL)\r
+                                       {\r
+                                               if (b->Size == MD5_SIZE)\r
+                                               {\r
+                                                       Copy(crl->DigestMD5, b->Buf, MD5_SIZE);\r
+                                               }\r
+\r
+                                               FreeBuf(b);\r
+                                       }\r
+                               }\r
+\r
+                               if (CfgGetStr(ff, "DigestSHA1", tmp, sizeof(tmp)))\r
+                               {\r
+                                       b = StrToBin(tmp);\r
+\r
+                                       if (b != NULL)\r
+                                       {\r
+                                               if (b->Size == SHA1_SIZE)\r
+                                               {\r
+                                                       Copy(crl->DigestSHA1, b->Buf, SHA1_SIZE);\r
+                                               }\r
+\r
+                                               FreeBuf(b);\r
+                                       }\r
+                               }\r
+\r
+                               Insert(o, crl);\r
+                       }\r
+               }\r
+\r
+               FreeToken(t);\r
+       }\r
+       UnlockList(o);\r
+}\r
+\r
+// 証明書リストの書き込み\r
+void SiWriteCertList(FOLDER *f, LIST *o)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(o);\r
+       {\r
+               UINT i;\r
+               X *x;\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       char name[MAX_SIZE];\r
+                       BUF *b;\r
+                       x = LIST_DATA(o, i);\r
+                       Format(name, sizeof(name), "Cert%u", i);\r
+                       b = XToBuf(x, false);\r
+                       if (b != NULL)\r
+                       {\r
+                               CfgAddBuf(CfgCreateFolder(f, name), "X509", b);\r
+                               FreeBuf(b);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(o);\r
+}\r
+\r
+// 証明書リストの読み込み\r
+void SiLoadCertList(LIST *o, FOLDER *f)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(o);\r
+       {\r
+               UINT i;\r
+               TOKEN_LIST *t;\r
+\r
+               t = CfgEnumFolderToTokenList(f);\r
+\r
+               for (i = 0;i < t->NumTokens;i++)\r
+               {\r
+                       FOLDER *ff = CfgGetFolder(f, t->Token[i]);\r
+                       BUF *b;\r
+\r
+                       b = CfgGetBuf(ff, "X509");\r
+                       if (b != NULL)\r
+                       {\r
+                               X *x = BufToX(b, false);\r
+                               if (x != NULL)\r
+                               {\r
+                                       Insert(o, x);\r
+                               }\r
+                               FreeBuf(b);\r
+                       }\r
+               }\r
+\r
+               FreeToken(t);\r
+       }\r
+       UnlockList(o);\r
+}\r
+\r
+// データベースの書き込み\r
+void SiWriteHubDb(FOLDER *f, HUBDB *db)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || db == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SiWriteUserList(CfgCreateFolder(f, "UserList"), db->UserList);\r
+       SiWriteGroupList(CfgCreateFolder(f, "GroupList"), db->GroupList);\r
+       SiWriteCertList(CfgCreateFolder(f, "CertList"), db->RootCertList);\r
+       SiWriteCrlList(CfgCreateFolder(f, "CrlList"), db->CrlList);\r
+}\r
+\r
+// データベースの読み込み\r
+void SiLoadHubDb(HUB *h, FOLDER *f)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SiLoadGroupList(h, CfgGetFolder(f, "GroupList"));\r
+       SiLoadUserList(h, CfgGetFolder(f, "UserList"));\r
+\r
+       if (h->HubDb != NULL)\r
+       {\r
+               SiLoadCertList(h->HubDb->RootCertList, CfgGetFolder(f, "CertList"));\r
+               SiLoadCrlList(h->HubDb->CrlList, CfgGetFolder(f, "CrlList"));\r
+       }\r
+}\r
+\r
+// 仮想 HUB 設定の書き込み\r
+void SiWriteHubCfg(FOLDER *f, HUB *h)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // パスワード\r
+       CfgAddByte(f, "HashedPassword", h->HashedPassword, sizeof(h->HashedPassword));\r
+       CfgAddByte(f, "SecurePassword", h->SecurePassword, sizeof(h->SecurePassword));\r
+\r
+       // Online / Offline フラグ\r
+       if (h->Cedar->Bridge == false)\r
+       {\r
+               CfgAddBool(f, "Online", (h->Offline && (h->HubIsOnlineButHalting == false)) ? false : true);\r
+       }\r
+\r
+       // トラフィック情報\r
+       SiWriteTraffic(f, "Traffic", h->Traffic);\r
+\r
+       // HUB オプション\r
+       SiWriteHubOptionCfg(CfgCreateFolder(f, "Option"), h->Option);\r
+\r
+       // メッセージ\r
+       {\r
+               FOLDER *folder = CfgCreateFolder(f, "Message");\r
+\r
+               if (IsEmptyUniStr(h->Msg) == false)\r
+               {\r
+                       CfgAddUniStr(folder, "MessageText", h->Msg);\r
+               }\r
+       }\r
+\r
+       // HUB_LOG\r
+       SiWriteHubLogCfg(CfgCreateFolder(f, "LogSetting"), &h->LogSetting);\r
+\r
+       if (h->Type == HUB_TYPE_STANDALONE)\r
+       {\r
+               // リンクリスト\r
+               SiWriteHubLinks(CfgCreateFolder(f, "CascadeList"), h);\r
+       }\r
+\r
+       if (h->Type != HUB_TYPE_FARM_STATIC)\r
+       {\r
+               if (GetServerCapsBool(h->Cedar->Server, "b_support_securenat"))\r
+               {\r
+                       // SecureNAT\r
+                       SiWriteSecureNAT(h, CfgCreateFolder(f, "SecureNAT"));\r
+               }\r
+       }\r
+\r
+       // アクセスリスト\r
+       SiWriteHubAccessLists(CfgCreateFolder(f, "AccessList"), h);\r
+\r
+       // 管理オプション\r
+       SiWriteHubAdminOptions(CfgCreateFolder(f, "AdminOption"), h);\r
+\r
+       // HUB の種類\r
+       CfgAddInt(f, "Type", h->Type);\r
+\r
+       // データベース\r
+       if (h->Cedar->Bridge == false)\r
+       {\r
+               SiWriteHubDb(CfgCreateFolder(f, "SecurityAccountDatabase"), h->HubDb);\r
+       }\r
+\r
+       // 利用状況\r
+       CfgAddInt64(f, "LastCommTime", h->LastCommTime);\r
+       CfgAddInt64(f, "LastLoginTime", h->LastLoginTime);\r
+       CfgAddInt64(f, "CreatedTime", h->CreatedTime);\r
+       CfgAddInt(f, "NumLogin", h->NumLogin);\r
+}\r
+\r
+// ログオプションの読み込み\r
+void SiLoadHubLogCfg(HUB_LOG *g, FOLDER *f)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(g, sizeof(HUB_LOG));\r
+       g->SaveSecurityLog = CfgGetBool(f, "SaveSecurityLog");\r
+       g->SecurityLogSwitchType = CfgGetInt(f, "SecurityLogSwitchType");\r
+       g->SavePacketLog = CfgGetBool(f, "SavePacketLog");\r
+       g->PacketLogSwitchType = CfgGetInt(f, "PacketLogSwitchType");\r
+\r
+       g->PacketLogConfig[PACKET_LOG_TCP_CONN] = CfgGetInt(f, "PACKET_LOG_TCP_CONN");\r
+       g->PacketLogConfig[PACKET_LOG_TCP] = CfgGetInt(f, "PACKET_LOG_TCP");\r
+       g->PacketLogConfig[PACKET_LOG_DHCP] = CfgGetInt(f, "PACKET_LOG_DHCP");\r
+       g->PacketLogConfig[PACKET_LOG_UDP] = CfgGetInt(f, "PACKET_LOG_UDP");\r
+       g->PacketLogConfig[PACKET_LOG_ICMP] = CfgGetInt(f, "PACKET_LOG_ICMP");\r
+       g->PacketLogConfig[PACKET_LOG_IP] = CfgGetInt(f, "PACKET_LOG_IP");\r
+       g->PacketLogConfig[PACKET_LOG_ARP] = CfgGetInt(f, "PACKET_LOG_ARP");\r
+       g->PacketLogConfig[PACKET_LOG_ETHERNET] = CfgGetInt(f, "PACKET_LOG_ETHERNET");\r
+}\r
+\r
+// ログオプションの書き込み\r
+void SiWriteHubLogCfg(FOLDER *f, HUB_LOG *g)\r
+{\r
+       SiWriteHubLogCfgEx(f, g, false);\r
+}\r
+void SiWriteHubLogCfgEx(FOLDER *f, HUB_LOG *g, bool el_mode)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (el_mode == false)\r
+       {\r
+               CfgAddBool(f, "SaveSecurityLog", g->SaveSecurityLog);\r
+               CfgAddInt(f, "SecurityLogSwitchType", g->SecurityLogSwitchType);\r
+               CfgAddBool(f, "SavePacketLog", g->SavePacketLog);\r
+       }\r
+\r
+       CfgAddInt(f, "PacketLogSwitchType", g->PacketLogSwitchType);\r
+\r
+       CfgAddInt(f, "PACKET_LOG_TCP_CONN", g->PacketLogConfig[PACKET_LOG_TCP_CONN]);\r
+       CfgAddInt(f, "PACKET_LOG_TCP", g->PacketLogConfig[PACKET_LOG_TCP]);\r
+       CfgAddInt(f, "PACKET_LOG_DHCP", g->PacketLogConfig[PACKET_LOG_DHCP]);\r
+       CfgAddInt(f, "PACKET_LOG_UDP", g->PacketLogConfig[PACKET_LOG_UDP]);\r
+       CfgAddInt(f, "PACKET_LOG_ICMP", g->PacketLogConfig[PACKET_LOG_ICMP]);\r
+       CfgAddInt(f, "PACKET_LOG_IP", g->PacketLogConfig[PACKET_LOG_IP]);\r
+       CfgAddInt(f, "PACKET_LOG_ARP", g->PacketLogConfig[PACKET_LOG_ARP]);\r
+       CfgAddInt(f, "PACKET_LOG_ETHERNET", g->PacketLogConfig[PACKET_LOG_ETHERNET]);\r
+}\r
+\r
+// 仮想 HUB 設定の読み込み\r
+void SiLoadHubCfg(SERVER *s, FOLDER *f, char *name)\r
+{\r
+       HUB *h;\r
+       CEDAR *c;\r
+       HUB_OPTION o;\r
+       bool online;\r
+       UINT hub_old_type = 0;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c = s->Cedar;\r
+\r
+       // オプションの取得\r
+       Zero(&o, sizeof(o));\r
+       SiLoadHubOptionCfg(CfgGetFolder(f, "Option"), &o);\r
+\r
+       // HUB の作成\r
+       h = NewHub(c, name, &o);\r
+       if (h != NULL)\r
+       {\r
+               HUB_LOG g;\r
+\r
+               // パスワード\r
+               if (CfgGetByte(f, "HashedPassword", h->HashedPassword, sizeof(h->HashedPassword)) != sizeof(h->HashedPassword))\r
+               {\r
+                       Hash(h->HashedPassword, "", 0, true);\r
+               }\r
+               if (CfgGetByte(f, "SecurePassword", h->SecurePassword, sizeof(h->SecurePassword)) != sizeof(h->SecurePassword))\r
+               {\r
+                       HashPassword(h->SecurePassword, ADMINISTRATOR_USERNAME, "");\r
+               }\r
+\r
+               // ログ設定\r
+               Zero(&g, sizeof(g));\r
+               SiLoadHubLogCfg(&g, CfgGetFolder(f, "LogSetting"));\r
+               SetHubLogSetting(h, &g);\r
+\r
+               // Online / Offline フラグ\r
+               if (h->Cedar->Bridge == false)\r
+               {\r
+                       online = CfgGetBool(f, "Online");\r
+               }\r
+               else\r
+               {\r
+                       online = true;\r
+               }\r
+\r
+               // トラフィック情報\r
+               SiLoadTraffic(f, "Traffic", h->Traffic);\r
+\r
+               // アクセスリスト\r
+               SiLoadHubAccessLists(h, CfgGetFolder(f, "AccessList"));\r
+\r
+               // HUB の種類\r
+               hub_old_type = h->Type = CfgGetInt(f, "Type");\r
+               if (s->ServerType == SERVER_TYPE_STANDALONE)\r
+               {\r
+                       if (h->Type != HUB_TYPE_STANDALONE)\r
+                       {\r
+                               // サーバーがスタンドアロンの場合は HUB の種類をスタンドアロンに変換する\r
+                               h->Type = HUB_TYPE_STANDALONE;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if (h->Type == HUB_TYPE_STANDALONE)\r
+                       {\r
+                               // サーバーがファームコントローラの場合は HUB の種類をファーム対応にする\r
+                               h->Type = HUB_TYPE_FARM_DYNAMIC;\r
+                       }\r
+               }\r
+\r
+               // メッセージ\r
+               {\r
+                       FOLDER *folder = CfgGetFolder(f, "Message");\r
+                       if (folder != NULL)\r
+                       {\r
+                               wchar_t *tmp = Malloc(sizeof(wchar_t) * (HUB_MAXMSG_LEN + 1));\r
+                               if (CfgGetUniStr(folder, "MessageText", tmp, sizeof(wchar_t) * (HUB_MAXMSG_LEN + 1)))\r
+                               {\r
+                                       SetHubMsg(h, tmp);\r
+                               }\r
+                               Free(tmp);\r
+                       }\r
+               }\r
+\r
+               // リンクリスト\r
+               if (h->Type == HUB_TYPE_STANDALONE)\r
+               {\r
+                       // リンクリストはスタンドアロン HUB の場合しか使用しない\r
+                       SiLoadHubLinks(h, CfgGetFolder(f, "CascadeList"));\r
+               }\r
+\r
+               // SecureNAT\r
+               if (GetServerCapsBool(h->Cedar->Server, "b_support_securenat"))\r
+               {\r
+                       if (h->Type == HUB_TYPE_STANDALONE || h->Type == HUB_TYPE_FARM_DYNAMIC)\r
+                       {\r
+                               // SecureNAT はスタンドアロン HUB かダイナミック HUB の場合しか使用しない\r
+                               SiLoadSecureNAT(h, CfgGetFolder(f, "SecureNAT"));\r
+\r
+                               if (h->Type != HUB_TYPE_STANDALONE && h->Cedar != NULL && h->Cedar->Server != NULL &&\r
+                                       h->Cedar->Server->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+                               {\r
+                                       NiClearUnsupportedVhOptionForDynamicHub(h->SecureNATOption,\r
+                                               hub_old_type == HUB_TYPE_STANDALONE);\r
+                               }\r
+\r
+                       }\r
+               }\r
+\r
+               // 管理オプション\r
+               SiLoadHubAdminOptions(h, CfgGetFolder(f, "AdminOption"));\r
+\r
+               // データベース\r
+               if (h->Cedar->Bridge == false)\r
+               {\r
+                       SiLoadHubDb(h, CfgGetFolder(f, "SecurityAccountDatabase"));\r
+               }\r
+\r
+               // 利用状況\r
+               h->LastCommTime = CfgGetInt64(f, "LastCommTime");\r
+               if (h->LastCommTime == 0)\r
+               {\r
+                       h->LastCommTime = SystemTime64();\r
+               }\r
+               h->LastLoginTime = CfgGetInt64(f, "LastLoginTime");\r
+               if (h->LastLoginTime == 0)\r
+               {\r
+                       h->LastLoginTime = SystemTime64();\r
+               }\r
+               h->CreatedTime = CfgGetInt64(f, "CreatedTime");\r
+               h->NumLogin = CfgGetInt(f, "NumLogin");\r
+\r
+               // HUB の動作開始\r
+               AddHub(c, h);\r
+\r
+               if (online)\r
+               {\r
+                       h->Offline = true;\r
+                       SetHubOnline(h);\r
+               }\r
+               else\r
+               {\r
+                       h->Offline = false;\r
+                       SetHubOffline(h);\r
+               }\r
+\r
+               WaitLogFlush(h->SecurityLogger);\r
+               WaitLogFlush(h->PacketLogger);\r
+\r
+               ReleaseHub(h);\r
+       }\r
+}\r
+\r
+// SecureNAT 設定の読み込み\r
+void SiLoadSecureNAT(HUB *h, FOLDER *f)\r
+{\r
+       VH_OPTION o;\r
+       // 引数チェック\r
+       if (h == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // VH_OPTION を読み込む\r
+       NiLoadVhOptionEx(&o, f);\r
+\r
+       // VH_OPTION をセット\r
+       Copy(h->SecureNATOption, &o, sizeof(VH_OPTION));\r
+\r
+       EnableSecureNAT(h, CfgGetBool(f, "Disabled") ? false : true);\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチ設定の読み込み\r
+void SiLoadL3SwitchCfg(L3SW *sw, FOLDER *f)\r
+{\r
+       UINT i;\r
+       FOLDER *if_folder, *table_folder;\r
+       TOKEN_LIST *t;\r
+       bool active = false;\r
+       // 引数チェック\r
+       if (sw == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       active = CfgGetBool(f, "Active");\r
+\r
+       // インターフェイスリスト\r
+       if_folder = CfgGetFolder(f, "InterfaceList");\r
+       if (if_folder != NULL)\r
+       {\r
+               t = CfgEnumFolderToTokenList(if_folder);\r
+               if (t != NULL)\r
+               {\r
+                       for (i = 0;i < t->NumTokens;i++)\r
+                       {\r
+                               FOLDER *ff = CfgGetFolder(if_folder, t->Token[i]);\r
+                               char name[MAX_HUBNAME_LEN + 1];\r
+                               UINT ip, subnet;\r
+\r
+                               CfgGetStr(ff, "HubName", name, sizeof(name));\r
+                               ip = CfgGetIp32(ff, "IpAddress");\r
+                               subnet = CfgGetIp32(ff, "SubnetMask");\r
+\r
+                               L3AddIf(sw, name, ip, subnet);\r
+                       }\r
+                       FreeToken(t);\r
+               }\r
+       }\r
+\r
+       // ルーティングテーブル\r
+       table_folder = CfgGetFolder(f, "RoutingTable");\r
+       if (table_folder != NULL)\r
+       {\r
+               t = CfgEnumFolderToTokenList(table_folder);\r
+               if (t != NULL)\r
+               {\r
+                       for (i = 0;i < t->NumTokens;i++)\r
+                       {\r
+                               FOLDER *ff = CfgGetFolder(table_folder, t->Token[i]);\r
+                               L3TABLE tbl;\r
+\r
+                               Zero(&tbl, sizeof(tbl));\r
+                               tbl.NetworkAddress = CfgGetIp32(ff, "NetworkAddress");\r
+                               tbl.SubnetMask = CfgGetIp32(ff, "SubnetMask");\r
+                               tbl.GatewayAddress = CfgGetIp32(ff, "GatewayAddress");\r
+                               tbl.Metric = CfgGetInt(ff, "Metric");\r
+\r
+                               L3AddTable(sw, &tbl);\r
+                       }\r
+                       FreeToken(t);\r
+               }\r
+       }\r
+\r
+       if (active)\r
+       {\r
+               L3SwStart(sw);\r
+       }\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチ設定の書き込み\r
+void SiWriteL3SwitchCfg(FOLDER *f, L3SW *sw)\r
+{\r
+       UINT i;\r
+       FOLDER *if_folder, *table_folder;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (f == NULL || sw == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 動作フラグ\r
+       CfgAddBool(f, "Active", sw->Active);\r
+\r
+       // インターフェイスリスト\r
+       if_folder = CfgCreateFolder(f, "InterfaceList");\r
+       for (i = 0;i < LIST_NUM(sw->IfList);i++)\r
+       {\r
+               L3IF *e = LIST_DATA(sw->IfList, i);\r
+               FOLDER *ff;\r
+\r
+               Format(tmp, sizeof(tmp), "Interface%u", i);\r
+               ff = CfgCreateFolder(if_folder, tmp);\r
+\r
+               CfgAddStr(ff, "HubName", e->HubName);\r
+               CfgAddIp32(ff, "IpAddress", e->IpAddress);\r
+               CfgAddIp32(ff, "SubnetMask", e->SubnetMask);\r
+       }\r
+\r
+       // ルーティングテーブル\r
+       table_folder = CfgCreateFolder(f, "RoutingTable");\r
+       for (i = 0;i < LIST_NUM(sw->TableList);i++)\r
+       {\r
+               L3TABLE *e = LIST_DATA(sw->TableList, i);\r
+               FOLDER *ff;\r
+\r
+               Format(tmp, sizeof(tmp), "Entry%u", i);\r
+               ff = CfgCreateFolder(table_folder, tmp);\r
+\r
+               CfgAddIp32(ff, "NetworkAddress", e->NetworkAddress);\r
+               CfgAddIp32(ff, "SubnetMask", e->SubnetMask);\r
+               CfgAddIp32(ff, "GatewayAddress", e->GatewayAddress);\r
+               CfgAddInt(ff, "Metric", e->Metric);\r
+       }\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチ一覧の読み込み\r
+void SiLoadL3Switchs(SERVER *s, FOLDER *f)\r
+{\r
+       UINT i;\r
+       TOKEN_LIST *t;\r
+       CEDAR *c;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+       c = s->Cedar;\r
+\r
+       t = CfgEnumFolderToTokenList(f);\r
+       if (t != NULL)\r
+       {\r
+               for (i = 0;i < t->NumTokens;i++)\r
+               {\r
+                       char *name = t->Token[i];\r
+                       L3SW *sw = L3AddSw(c, name);\r
+\r
+                       SiLoadL3SwitchCfg(sw, CfgGetFolder(f, name));\r
+\r
+                       ReleaseL3Sw(sw);\r
+               }\r
+       }\r
+       FreeToken(t);\r
+}\r
+\r
+// 仮想レイヤ 3 スイッチ一覧の書き込み\r
+void SiWriteL3Switchs(FOLDER *f, SERVER *s)\r
+{\r
+       UINT i;\r
+       FOLDER *folder;\r
+       CEDAR *c;\r
+       // 引数チェック\r
+       if (f == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+       c = s->Cedar;\r
+\r
+       LockList(c->L3SwList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(c->L3SwList);i++)\r
+               {\r
+                       L3SW *sw = LIST_DATA(c->L3SwList, i);\r
+\r
+                       Lock(sw->lock);\r
+                       {\r
+                               folder = CfgCreateFolder(f, sw->Name);\r
+\r
+                               SiWriteL3SwitchCfg(folder, sw);\r
+                       }\r
+                       Unlock(sw->lock);\r
+               }\r
+       }\r
+       UnlockList(c->L3SwList);\r
+}\r
+\r
+// ライセンス一覧の書き込み\r
+void SiWriteLicenseManager(FOLDER *f, SERVER *s)\r
+{\r
+       LICENSE_SYSTEM *ss;\r
+       // 引数チェック\r
+       if (f == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ss = s->LicenseSystem;\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(ss->LicenseList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(ss->LicenseList);i++)\r
+               {\r
+                       LICENSE *e = LIST_DATA(ss->LicenseList, i);\r
+                       char name[MAX_SIZE];\r
+                       FOLDER *ff;\r
+\r
+                       Format(name, sizeof(name), "License%u", i);\r
+                       ff = CfgCreateFolder(f, name);\r
+                       CfgAddStr(ff, "LicenseKey", e->LicenseKeyStr);\r
+                       CfgAddInt(ff, "LicenseType", e->ProductId);\r
+               }\r
+       }\r
+       UnlockList(ss->LicenseList);\r
+}\r
+\r
+// ライセンス一覧の読み込み\r
+void SiLoadLicenseManager(SERVER *s, FOLDER *f)\r
+{\r
+       UINT i;\r
+       TOKEN_LIST *t;\r
+       CEDAR *c;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+       c = s->Cedar;\r
+\r
+       t = CfgEnumFolderToTokenList(f);\r
+       if (t != NULL)\r
+       {\r
+               for (i = 0;i < t->NumTokens;i++)\r
+               {\r
+                       char *str = t->Token[i];\r
+                       FOLDER *ff = CfgGetFolder(f, str);\r
+\r
+                       if (ff != NULL)\r
+                       {\r
+                               UINT product_id = CfgGetInt(ff, "LicenseType");\r
+                               char key[MAX_SIZE];\r
+\r
+                               if (CfgGetStr(ff, "LicenseKey", key, sizeof(key)))\r
+                               {\r
+                                       // ライセンス登録\r
+                                       //LiInputLicenseKeyEx(c, s->LicenseSystem, key, product_id, NULL);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       FreeToken(t);\r
+\r
+       DestroyServerCapsCache(s);\r
+}\r
+\r
+// 仮想 HUB 一覧の書き込み\r
+void SiWriteHubs(FOLDER *f, SERVER *s)\r
+{\r
+       UINT i;\r
+       FOLDER *hub_folder;\r
+       CEDAR *c;\r
+       UINT num;\r
+       HUB **hubs;\r
+       // 引数チェック\r
+       if (f == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+       c = s->Cedar;\r
+\r
+       LockList(c->HubList);\r
+       {\r
+               hubs = ToArray(c->HubList);\r
+               num = LIST_NUM(c->HubList);\r
+\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       AddRef(hubs[i]->ref);\r
+               }\r
+       }\r
+       UnlockList(c->HubList);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               HUB *h = hubs[i];\r
+\r
+               Lock(h->lock);\r
+               {\r
+                       hub_folder = CfgCreateFolder(f, h->Name);\r
+                       SiWriteHubCfg(hub_folder, h);\r
+               }\r
+               Unlock(h->lock);\r
+\r
+               ReleaseHub(h);\r
+\r
+               if ((i % 30) == 1)\r
+               {\r
+                       YieldCpu();\r
+               }\r
+       }\r
+\r
+       Free(hubs);\r
+}\r
+\r
+// 仮想 HUB 一覧の読み込み\r
+void SiLoadHubs(SERVER *s, FOLDER *f)\r
+{\r
+       UINT i;\r
+       FOLDER *hub_folder;\r
+       CEDAR *c;\r
+       TOKEN_LIST *t;\r
+       bool b = false;\r
+       // 引数チェック\r
+       if (f == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+       c = s->Cedar;\r
+\r
+       t = CfgEnumFolderToTokenList(f);\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               char *name = t->Token[i];\r
+               if (s->Cedar->Bridge)\r
+               {\r
+                       if (StrCmpi(name, SERVER_DEFAULT_BRIDGE_NAME) == 0)\r
+                       {\r
+                               // Bridge の場合は "BRIDGE" という名前の仮想 HUB の設定\r
+                               // しか読み込まない\r
+                               b = true;\r
+                       }\r
+                       else\r
+                       {\r
+                               continue;\r
+                       }\r
+               }\r
+               hub_folder = CfgGetFolder(f, name);\r
+               if (hub_folder != NULL)\r
+               {\r
+                       SiLoadHubCfg(s, hub_folder, name);\r
+               }\r
+       }\r
+       FreeToken(t);\r
+\r
+       if (s->Cedar->Bridge && b == false)\r
+       {\r
+               // "BRIDGE" という名前の仮想 HUB の設定が存在しない場合は新たに作成する\r
+               SiInitDefaultHubList(s);\r
+       }\r
+}\r
+\r
+// サーバー固有の設定の読み込み\r
+void SiLoadServerCfg(SERVER *s, FOLDER *f)\r
+{\r
+       BUF *b;\r
+       CEDAR *c;\r
+       char tmp[MAX_SIZE];\r
+       X *x = NULL;\r
+       K *k = NULL;\r
+       bool cluster_allowed = false;\r
+       UINT num_connections_per_ip = 0;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 保存間隔関係\r
+       s->AutoSaveConfigSpan = CfgGetInt(f, "AutoSaveConfigSpan") * 1000;\r
+       if (s->AutoSaveConfigSpan == 0)\r
+       {\r
+               s->AutoSaveConfigSpan = SERVER_FILE_SAVE_INTERVAL_DEFAULT;\r
+       }\r
+       else\r
+       {\r
+               s->AutoSaveConfigSpan = MAKESURE(s->AutoSaveConfigSpan, SERVER_FILE_SAVE_INTERVAL_MIN, SERVER_FILE_SAVE_INTERVAL_MAX);\r
+       }\r
+\r
+       c = s->Cedar;\r
+       Lock(c->lock);\r
+       {\r
+               {\r
+                       RPC_KEEP k;\r
+\r
+                       // キープアライブ関係\r
+                       Zero(&k, sizeof(k));\r
+                       k.UseKeepConnect = CfgGetBool(f, "UseKeepConnect");\r
+                       CfgGetStr(f, "KeepConnectHost", k.KeepConnectHost, sizeof(k.KeepConnectHost));\r
+                       k.KeepConnectPort = CfgGetInt(f, "KeepConnectPort");\r
+                       k.KeepConnectProtocol = CfgGetInt(f, "KeepConnectProtocol");\r
+                       k.KeepConnectInterval = CfgGetInt(f, "KeepConnectInterval") * 1000;\r
+                       if (k.KeepConnectPort == 0)\r
+                       {\r
+                               k.KeepConnectPort = 80;\r
+                       }\r
+                       if (StrLen(k.KeepConnectHost) == 0)\r
+                       {\r
+                               StrCpy(k.KeepConnectHost, sizeof(k.KeepConnectHost), CLIENT_DEFAULT_KEEPALIVE_HOST);\r
+                       }\r
+                       if (k.KeepConnectInterval == 0)\r
+                       {\r
+                               k.KeepConnectInterval = KEEP_INTERVAL_DEFAULT * 1000;\r
+                       }\r
+                       if (k.KeepConnectInterval < 5000)\r
+                       {\r
+                               k.KeepConnectInterval = 5000;\r
+                       }\r
+                       if (k.KeepConnectInterval > 600000)\r
+                       {\r
+                               k.KeepConnectInterval = 600000;\r
+                       }\r
+\r
+                       Lock(s->Keep->lock);\r
+                       {\r
+                               KEEP *keep = s->Keep;\r
+                               keep->Enable = k.UseKeepConnect;\r
+                               keep->Server = true;\r
+                               StrCpy(keep->ServerName, sizeof(keep->ServerName), k.KeepConnectHost);\r
+                               keep->ServerPort = k.KeepConnectPort;\r
+                               keep->UdpMode = k.KeepConnectProtocol;\r
+                               keep->Interval = k.KeepConnectInterval;\r
+                       }\r
+                       Unlock(s->Keep->lock);\r
+               }\r
+\r
+               // IPv6 リスナーを無効にするかどうか\r
+               s->Cedar->DisableIPv6Listener = CfgGetBool(f, "DisableIPv6Listener");\r
+\r
+               // DeadLock\r
+               s->DisableDeadLockCheck = CfgGetBool(f, "DisableDeadLockCheck");\r
+\r
+               // 自動ファイル削除器\r
+               s->Eraser = NewEraser(s->Logger, CfgGetInt64(f, "AutoDeleteCheckDiskFreeSpaceMin"));\r
+\r
+               // NoLinuxArpFilter\r
+               s->NoLinuxArpFilter = CfgGetBool(f, "NoLinuxArpFilter");\r
+\r
+               // NoHighPriorityProcess\r
+               s->NoHighPriorityProcess = CfgGetBool(f, "NoHighPriorityProcess");\r
+\r
+               // NoDebugDump\r
+               s->NoDebugDump = CfgGetBool(f, "NoDebugDump");\r
+               if (s->NoDebugDump)\r
+               {\r
+#ifdef OS_WIN32\r
+                       MsSetEnableMinidump(false);\r
+#endif // OS_WIN32\r
+               }\r
+\r
+               // クライアントにシグネチャを送信させない\r
+               s->NoSendSignature = CfgGetBool(f, "NoSendSignature");\r
+\r
+               // デバッグログ\r
+               s->SaveDebugLog = CfgGetBool(f, "SaveDebugLog");\r
+               if (s->SaveDebugLog)\r
+               {\r
+                       s->DebugLog = NewTinyLog();\r
+               }\r
+\r
+               // サーバー証明書\r
+               b = CfgGetBuf(f, "ServerCert");\r
+               if (b != NULL)\r
+               {\r
+                       x = BufToX(b, false);\r
+                       FreeBuf(b);\r
+               }\r
+\r
+               // サーバー秘密鍵\r
+               b = CfgGetBuf(f, "ServerKey");\r
+               if (b != NULL)\r
+               {\r
+                       k = BufToK(b, true, false, NULL);\r
+                       FreeBuf(b);\r
+               }\r
+\r
+               if (x == NULL || k == NULL || CheckXandK(x, k) == false)\r
+               {\r
+                       FreeX(x);\r
+                       FreeK(k);\r
+                       SiGenerateDefualtCert(&x, &k);\r
+\r
+                       SetCedarCert(c, x, k);\r
+\r
+                       FreeX(x);\r
+                       FreeK(k);\r
+               }\r
+               else\r
+               {\r
+                       SetCedarCert(c, x, k);\r
+\r
+                       FreeX(x);\r
+                       FreeK(k);\r
+               }\r
+\r
+               // 暗号化名\r
+               if (CfgGetStr(f, "CipherName", tmp, sizeof(tmp)))\r
+               {\r
+                       StrUpper(tmp);\r
+                       if (CheckCipherListName(tmp))\r
+                       {\r
+                               SetCedarCipherList(c, tmp);\r
+                       }\r
+               }\r
+\r
+               // トラフィック情報\r
+               Lock(c->TrafficLock);\r
+               {\r
+                       SiLoadTraffic(f, "ServerTraffic", c->Traffic);\r
+               }\r
+               Unlock(c->TrafficLock);\r
+\r
+               // 現在のライセンスでクラスタモードが許可されているかどうかを取得する\r
+               cluster_allowed = false;\r
+               if (s->Cedar->Bridge == false)\r
+               {\r
+                       LICENSE_STATUS status;\r
+\r
+                       LiParseCurrentLicenseStatus(s->LicenseSystem, &status);\r
+\r
+                       if (status.AllowEnterpriseFunction)\r
+                       {\r
+                               cluster_allowed = true;\r
+                       }\r
+               }\r
+\r
+               // サーバーの種類\r
+               s->UpdatedServerType = s->ServerType = \r
+                       cluster_allowed ? CfgGetInt(f, "ServerType") : SERVER_TYPE_STANDALONE;\r
+\r
+               // パスワード\r
+               if (CfgGetByte(f, "HashedPassword", s->HashedPassword, sizeof(s->HashedPassword)) != sizeof(s->HashedPassword))\r
+               {\r
+                       Hash(s->HashedPassword, "", 0, true);\r
+               }\r
+\r
+               if (s->ServerType != SERVER_TYPE_STANDALONE)\r
+               {\r
+                       // サーバーの性能基準比\r
+                       s->Weight = CfgGetInt(f, "ClusterMemberWeight");\r
+                       if (s->Weight == 0)\r
+                       {\r
+                               s->Weight = FARM_DEFAULT_WEIGHT;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       s->Weight = FARM_DEFAULT_WEIGHT;\r
+               }\r
+\r
+               if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+               {\r
+                       s->ControllerOnly = CfgGetBool(f, "ControllerOnly");\r
+               }\r
+\r
+               if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+               {\r
+                       char tmp[6 * MAX_PUBLIC_PORT_NUM + 1];\r
+                       // ファームメンバの場合の設定項目の読み込み\r
+                       CfgGetStr(f, "ControllerName", s->ControllerName, sizeof(s->ControllerName));\r
+                       s->ControllerPort = CfgGetInt(f, "ControllerPort");\r
+                       CfgGetByte(f, "MemberPassword", s->MemberPassword, SHA1_SIZE);\r
+                       s->PublicIp = CfgGetIp32(f, "PublicIp");\r
+                       if (CfgGetStr(f, "PublicPorts", tmp, sizeof(tmp)))\r
+                       {\r
+                               TOKEN_LIST *t = ParseToken(tmp, ", ");\r
+                               UINT i;\r
+                               s->NumPublicPort = t->NumTokens;\r
+                               s->PublicPorts = ZeroMalloc(s->NumPublicPort * sizeof(UINT));\r
+                               for (i = 0;i < s->NumPublicPort;i++)\r
+                               {\r
+                                       s->PublicPorts[i] = ToInt(t->Token[i]);\r
+                               }\r
+                               FreeToken(t);\r
+                       }\r
+               }\r
+       }\r
+       Unlock(c->lock);\r
+}\r
+\r
+// サーバー固有の設定の書き込み\r
+void SiWriteServerCfg(FOLDER *f, SERVER *s)\r
+{\r
+       BUF *b;\r
+       CEDAR *c;\r
+       // 引数チェック\r
+       if (f == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CfgAddInt(f, "AutoSaveConfigSpan", s->AutoSaveConfigSpan / 1000);\r
+\r
+       c = s->Cedar;\r
+\r
+       Lock(c->lock);\r
+       {\r
+               Lock(s->Keep->lock);\r
+               {\r
+                       KEEP *k = s->Keep;\r
+                       CfgAddBool(f, "UseKeepConnect", k->Enable);\r
+                       CfgAddStr(f, "KeepConnectHost", k->ServerName);\r
+                       CfgAddInt(f, "KeepConnectPort", k->ServerPort);\r
+                       CfgAddInt(f, "KeepConnectProtocol", k->UdpMode);\r
+                       CfgAddInt(f, "KeepConnectInterval", k->Interval / 1000);\r
+               }\r
+               Unlock(s->Keep->lock);\r
+\r
+               // IPv6 リスナー無効化設定\r
+               CfgAddBool(f, "DisableIPv6Listener", s->Cedar->DisableIPv6Listener);\r
+\r
+               // DeadLock\r
+               CfgAddBool(f, "DisableDeadLockCheck", s->DisableDeadLockCheck);\r
+\r
+               // 自動ファイル削除器関係\r
+               CfgAddInt64(f, "AutoDeleteCheckDiskFreeSpaceMin", s->Eraser->MinFreeSpace);\r
+\r
+               // NoLinuxArpFilter\r
+               if (GetOsInfo()->OsType == OSTYPE_LINUX)\r
+               {\r
+                       CfgAddBool(f, "NoLinuxArpFilter", s->NoLinuxArpFilter);\r
+               }\r
+\r
+               // NoHighPriorityProcess\r
+               CfgAddBool(f, "NoHighPriorityProcess", s->NoHighPriorityProcess);\r
+\r
+#ifdef OS_WIN32\r
+               CfgAddBool(f, "NoDebugDump", s->NoDebugDump);\r
+#endif // OS_WIN32\r
+\r
+               // デバッグログ\r
+               CfgAddBool(f, "SaveDebugLog", s->SaveDebugLog);\r
+\r
+               // クライアントにシグネチャを送信させない\r
+               CfgAddBool(f, "NoSendSignature", s->NoSendSignature);\r
+\r
+               // サーバー証明書\r
+               b = XToBuf(c->ServerX, false);\r
+               CfgAddBuf(f, "ServerCert", b);\r
+               FreeBuf(b);\r
+\r
+               // サーバー秘密鍵\r
+               b = KToBuf(c->ServerK, false, NULL);\r
+               CfgAddBuf(f, "ServerKey", b);\r
+               FreeBuf(b);\r
+\r
+               // トラフィック情報\r
+               Lock(c->TrafficLock);\r
+               {\r
+                       SiWriteTraffic(f, "ServerTraffic", c->Traffic);\r
+               }\r
+               Unlock(c->TrafficLock);\r
+\r
+               // サーバーの種類\r
+               if (s->Cedar->Bridge == false)\r
+               {\r
+                       CfgAddInt(f, "ServerType", s->UpdatedServerType);\r
+               }\r
+\r
+               // 暗号化\r
+               CfgAddStr(f, "CipherName", s->Cedar->CipherList);\r
+\r
+               // パスワード\r
+               CfgAddByte(f, "HashedPassword", s->HashedPassword, sizeof(s->HashedPassword));\r
+\r
+               if (s->UpdatedServerType == SERVER_TYPE_FARM_MEMBER)\r
+               {\r
+                       char tmp[6 * MAX_PUBLIC_PORT_NUM + 1];\r
+                       UINT i;\r
+                       // ファームメンバの場合の設定項目\r
+                       CfgAddStr(f, "ControllerName", s->ControllerName);\r
+                       CfgAddInt(f, "ControllerPort", s->ControllerPort);\r
+                       CfgAddByte(f, "MemberPassword", s->MemberPassword, SHA1_SIZE);\r
+                       CfgAddIp32(f, "PublicIp", s->PublicIp);\r
+                       tmp[0] = 0;\r
+                       for (i = 0;i < s->NumPublicPort;i++)\r
+                       {\r
+                               char tmp2[MAX_SIZE];\r
+                               ToStr(tmp2, s->PublicPorts[i]);\r
+                               StrCat(tmp, sizeof(tmp), tmp2);\r
+                               StrCat(tmp, sizeof(tmp), ",");\r
+                       }\r
+                       if (StrLen(tmp) >= 1)\r
+                       {\r
+                               if (tmp[StrLen(tmp) - 1] == ',')\r
+                               {\r
+                                       tmp[StrLen(tmp) - 1] = 0;\r
+                               }\r
+                       }\r
+                       CfgAddStr(f, "PublicPorts", tmp);\r
+               }\r
+\r
+               if (s->UpdatedServerType != SERVER_TYPE_STANDALONE)\r
+               {\r
+                       CfgAddInt(f, "ClusterMemberWeight", s->Weight);\r
+               }\r
+\r
+               if (s->UpdatedServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+               {\r
+                       CfgAddBool(f, "ControllerOnly", s->ControllerOnly);\r
+               }\r
+       }\r
+       Unlock(c->lock);\r
+}\r
+\r
+// トラフィック情報の読み込み\r
+void SiLoadTraffic(FOLDER *parent, char *name, TRAFFIC *t)\r
+{\r
+       FOLDER *f;\r
+       // 引数チェック\r
+       if (t != NULL)\r
+       {\r
+               Zero(t, sizeof(TRAFFIC));\r
+       }\r
+       if (parent == NULL || name == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       f = CfgGetFolder(parent, name);\r
+\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SiLoadTrafficInner(f, "SendTraffic", &t->Send);\r
+       SiLoadTrafficInner(f, "RecvTraffic", &t->Recv);\r
+}\r
+void SiLoadTrafficInner(FOLDER *parent, char *name, TRAFFIC_ENTRY *e)\r
+{\r
+       FOLDER *f;\r
+       // 引数チェック\r
+       if (e != NULL)\r
+       {\r
+               Zero(e, sizeof(TRAFFIC_ENTRY));\r
+       }\r
+       if (parent == NULL || name == NULL || e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       f = CfgGetFolder(parent, name);\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       e->BroadcastCount = CfgGetInt64(f, "BroadcastCount");\r
+       e->BroadcastBytes = CfgGetInt64(f, "BroadcastBytes");\r
+       e->UnicastCount = CfgGetInt64(f, "UnicastCount");\r
+       e->UnicastBytes = CfgGetInt64(f, "UnicastBytes");\r
+}\r
+\r
+// トラフィック情報の書き込み\r
+void SiWriteTraffic(FOLDER *parent, char *name, TRAFFIC *t)\r
+{\r
+       FOLDER *f;\r
+       // 引数チェック\r
+       if (parent == NULL || name == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       f = CfgCreateFolder(parent, name);\r
+\r
+       SiWriteTrafficInner(f, "SendTraffic", &t->Send);\r
+       SiWriteTrafficInner(f, "RecvTraffic", &t->Recv);\r
+}\r
+void SiWriteTrafficInner(FOLDER *parent, char *name, TRAFFIC_ENTRY *e)\r
+{\r
+       FOLDER *f;\r
+       // 引数チェック\r
+       if (parent == NULL || name == NULL || e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       f = CfgCreateFolder(parent, name);\r
+       CfgAddInt64(f, "BroadcastCount", e->BroadcastCount);\r
+       CfgAddInt64(f, "BroadcastBytes", e->BroadcastBytes);\r
+       CfgAddInt64(f, "UnicastCount", e->UnicastCount);\r
+       CfgAddInt64(f, "UnicastBytes", e->UnicastBytes);\r
+}\r
+\r
+// 設定ファイル書き込み用スレッド\r
+void SiSaverThread(THREAD *thread, void *param)\r
+{\r
+       SERVER *s = (SERVER *)param;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (s->Halt == false)\r
+       {\r
+               // 設定ファイル保存\r
+               SiWriteConfigurationFile(s);\r
+\r
+               Wait(s->SaveHaltEvent, s->AutoSaveConfigSpan);\r
+       }\r
+}\r
+\r
+// 設定ファイルに書き込む\r
+UINT SiWriteConfigurationFile(SERVER *s)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (s->CfgRw == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Lock(s->SaveCfgLock);\r
+       {\r
+               FOLDER *f;\r
+\r
+               Debug("save: SiWriteConfigurationToCfg() start.\n");\r
+               f = SiWriteConfigurationToCfg(s);\r
+               Debug("save: SiWriteConfigurationToCfg() finished.\n");\r
+\r
+               Debug("save: SaveCfgRw() start.\n");\r
+               ret = SaveCfgRw(s->CfgRw, f);\r
+               Debug("save: SaveCfgRw() finished.\n");\r
+\r
+               Debug("save: CfgDeleteFolder() start.\n");\r
+               CfgDeleteFolder(f);\r
+               Debug("save: CfgDeleteFolder() finished.\n");\r
+       }\r
+       Unlock(s->SaveCfgLock);\r
+\r
+       return ret;\r
+}\r
+\r
+// コンフィグレーション解放\r
+void SiFreeConfiguration(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 設定ファイルに書き込む\r
+       SiWriteConfigurationFile(s);\r
+\r
+       // 設定ファイル保存スレッドの終了\r
+       s->Halt = true;\r
+       Set(s->SaveHaltEvent);\r
+       WaitThread(s->SaveThread, INFINITE);\r
+\r
+       ReleaseEvent(s->SaveHaltEvent);\r
+       ReleaseThread(s->SaveThread);\r
+\r
+       FreeCfgRw(s->CfgRw);\r
+       s->CfgRw = NULL;\r
+\r
+       // Ethernet 解放\r
+       FreeEth();\r
+}\r
+\r
+// StXxx 関係関数の初期化\r
+void StInit()\r
+{\r
+       if (server_lock != NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       server_lock = NewLock();\r
+}\r
+\r
+// StXxx 関係関数の解放\r
+void StFree()\r
+{\r
+       DeleteLock(server_lock);\r
+       server_lock = NULL;\r
+}\r
+\r
+// サーバーの開始\r
+void StStartServer(bool bridge)\r
+{\r
+       Lock(server_lock);\r
+       {\r
+               if (server != NULL)\r
+               {\r
+                       // すでに開始されている\r
+                       Unlock(server_lock);\r
+                       return;\r
+               }\r
+\r
+               // サーバーの作成\r
+               server = SiNewServer(bridge);\r
+       }\r
+       Unlock(server_lock);\r
+\r
+//     StartCedarLog();\r
+}\r
+\r
+// サーバーの取得\r
+SERVER *StGetServer()\r
+{\r
+       if (server == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       return server;\r
+}\r
+\r
+// サーバーの停止\r
+void StStopServer()\r
+{\r
+       Lock(server_lock);\r
+       {\r
+               if (server == NULL)\r
+               {\r
+                       // 開始されていない\r
+                       Unlock(server_lock);\r
+                       return;\r
+               }\r
+\r
+               // サーバーの解放\r
+               SiReleaseServer(server);\r
+               server = NULL;\r
+       }\r
+       Unlock(server_lock);\r
+\r
+       StopCedarLog();\r
+}\r
+\r
+// サーバーの種類の設定\r
+void SiSetServerType(SERVER *s, UINT type,\r
+                                        UINT ip, UINT num_port, UINT *ports,\r
+                                        char *controller_name, UINT controller_port, UCHAR *password, UINT weight, bool controller_only)\r
+{\r
+       bool bridge;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (type == SERVER_TYPE_FARM_MEMBER &&\r
+               (num_port == 0 || ports == NULL || controller_name == NULL ||\r
+               controller_port == 0 || password == NULL || num_port > MAX_PUBLIC_PORT_NUM))\r
+       {\r
+               return;\r
+       }\r
+       if (weight == 0)\r
+       {\r
+               weight = FARM_DEFAULT_WEIGHT;\r
+       }\r
+\r
+       bridge = s->Cedar->Bridge;\r
+\r
+       Lock(s->lock);\r
+       {\r
+               // 種類の更新\r
+               s->UpdatedServerType = type;\r
+\r
+               s->Weight = weight;\r
+\r
+               // 値の設定\r
+               if (type == SERVER_TYPE_FARM_MEMBER)\r
+               {\r
+                       StrCpy(s->ControllerName, sizeof(s->ControllerName), controller_name);\r
+                       s->ControllerPort = controller_port;\r
+                       if (IsZero(password, SHA1_SIZE) == false)\r
+                       {\r
+                               Copy(s->MemberPassword, password, SHA1_SIZE);\r
+                       }\r
+                       s->PublicIp = ip;\r
+                       s->NumPublicPort = num_port;\r
+                       if (s->PublicPorts != NULL)\r
+                       {\r
+                               Free(s->PublicPorts);\r
+                       }\r
+                       s->PublicPorts = ZeroMalloc(num_port * sizeof(UINT));\r
+                       Copy(s->PublicPorts, ports, num_port * sizeof(UINT));\r
+               }\r
+\r
+               if (type == SERVER_TYPE_FARM_CONTROLLER)\r
+               {\r
+                       s->ControllerOnly = controller_only;\r
+               }\r
+       }\r
+       Unlock(s->lock);\r
+\r
+       // サーバーの再起動\r
+       SiRebootServer(bridge);\r
+}\r
+\r
+// サーバーの再起動スレッド\r
+void SiRebootServerThread(THREAD *thread, void *param)\r
+{\r
+       // 引数チェック\r
+       if (thread == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (server == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // サーバーの停止\r
+       StStopServer();\r
+\r
+       // サーバーの開始\r
+       StStartServer((bool)param);\r
+}\r
+\r
+// サーバーの再起動\r
+void SiRebootServer(bool bridge)\r
+{\r
+       SiRebootServerEx(bridge, false);\r
+}\r
+void SiRebootServerEx(bool bridge, bool reset_setting)\r
+{\r
+       THREAD *t;\r
+\r
+       server_reset_setting = reset_setting;\r
+\r
+       t = NewThread(SiRebootServerThread, (void *)bridge);\r
+       ReleaseThread(t);\r
+}\r
+\r
+// すべてのリスナーの停止\r
+void SiStopAllListener(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SiLockListenerList(s);\r
+       {\r
+               UINT i;\r
+               LIST *o = NewListFast(NULL);\r
+               for (i = 0;i < LIST_NUM(s->ServerListenerList);i++)\r
+               {\r
+                       SERVER_LISTENER *e = LIST_DATA(s->ServerListenerList, i);\r
+                       Add(o, e);\r
+               }\r
+\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       SERVER_LISTENER *e = LIST_DATA(o, i);\r
+                       SiDeleteListener(s, e->Port);\r
+               }\r
+\r
+               ReleaseList(o);\r
+       }\r
+       SiUnlockListenerList(s);\r
+\r
+       ReleaseList(s->ServerListenerList);\r
+}\r
+\r
+// サーバーのクリーンアップ\r
+void SiCleanupServer(SERVER *s)\r
+{\r
+       UINT i;\r
+       CEDAR *c;\r
+       LISTENER **listener_list;\r
+       UINT num_listener;\r
+       HUB **hub_list;\r
+       UINT num_hub;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SiFreeDeadLockCheck(s);\r
+\r
+       FreeServerSnapshot(s);\r
+\r
+       c = s->Cedar;\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               // ファームメンバの場合、ファームコントローラへの接続を停止\r
+               SLog(c, "LS_STOP_FARM_MEMBER");\r
+               SiStopConnectToController(s->FarmController);\r
+               s->FarmController = NULL;\r
+               SLog(c, "LS_STOP_FARM_MEMBER_2");\r
+       }\r
+\r
+       IncrementServerConfigRevision(s);\r
+\r
+       SLog(c, "LS_END_2");\r
+\r
+       SLog(c, "LS_STOP_ALL_LISTENER");\r
+       // すべてのリスナーを停止\r
+       LockList(c->ListenerList);\r
+       {\r
+               listener_list = ToArray(c->ListenerList);\r
+               num_listener = LIST_NUM(c->ListenerList);\r
+               for (i = 0;i < num_listener;i++)\r
+               {\r
+                       AddRef(listener_list[i]->ref);\r
+               }\r
+       }\r
+       UnlockList(c->ListenerList);\r
+\r
+       for (i = 0;i < num_listener;i++)\r
+       {\r
+               StopListener(listener_list[i]);\r
+               ReleaseListener(listener_list[i]);\r
+       }\r
+       Free(listener_list);\r
+       SLog(c, "LS_STOP_ALL_LISTENER_2");\r
+\r
+       SLog(c, "LS_STOP_ALL_HUB");\r
+       // すべての HUB を停止\r
+       LockList(c->HubList);\r
+       {\r
+               hub_list = ToArray(c->HubList);\r
+               num_hub = LIST_NUM(c->HubList);\r
+               for (i = 0;i < num_hub;i++)\r
+               {\r
+                       AddRef(hub_list[i]->ref);\r
+               }\r
+       }\r
+       UnlockList(c->HubList);\r
+\r
+       for (i = 0;i < num_hub;i++)\r
+       {\r
+               StopHub(hub_list[i]);\r
+               ReleaseHub(hub_list[i]);\r
+       }\r
+       Free(hub_list);\r
+       SLog(c, "LS_STOP_ALL_HUB_2");\r
+\r
+       // コンフィグレーション解放\r
+       SiFreeConfiguration(s);\r
+\r
+       // Cedar の停止\r
+       SLog(c, "LS_STOP_CEDAR");\r
+       StopCedar(s->Cedar);\r
+       SLog(c, "LS_STOP_CEDAR_2");\r
+\r
+       // すべてのリスナーの停止\r
+       SiStopAllListener(s);\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               // ファームコントローラの場合\r
+               UINT i;\r
+\r
+               SLog(c, "LS_STOP_FARM_CONTROL");\r
+\r
+               // ファームコントロールを停止\r
+               SiStopFarmControl(s);\r
+\r
+               // ファームメンバ情報を解放\r
+               ReleaseList(s->FarmMemberList);\r
+               s->FarmMemberList = NULL;\r
+\r
+               for (i = 0;i < LIST_NUM(s->Me->HubList);i++)\r
+               {\r
+                       Free(LIST_DATA(s->Me->HubList, i));\r
+               }\r
+               ReleaseList(s->Me->HubList);\r
+\r
+               Free(s->Me);\r
+\r
+               SLog(c, "LS_STOP_FARM_CONTROL_2");\r
+       }\r
+\r
+       if (s->PublicPorts != NULL)\r
+       {\r
+               Free(s->PublicPorts);\r
+       }\r
+\r
+       SLog(s->Cedar, "LS_END_1");\r
+       SLog(s->Cedar, "L_LINE");\r
+\r
+       ReleaseCedar(s->Cedar);\r
+       DeleteLock(s->lock);\r
+       DeleteLock(s->SaveCfgLock);\r
+\r
+       StopKeep(s->Keep);\r
+\r
+       FreeEraser(s->Eraser);\r
+\r
+       // ライセンスシステム解放\r
+       if (s->LicenseSystem != NULL)\r
+       {\r
+               LiFreeLicenseSystem(s->LicenseSystem);\r
+       }\r
+\r
+       FreeLog(s->Logger);\r
+\r
+       FreeServerCapsCache(s);\r
+\r
+       SiFreeHubCreateHistory(s);\r
+\r
+       // デバッグログの停止\r
+       FreeTinyLog(s->DebugLog);\r
+\r
+       DeleteLock(s->TasksFromFarmControllerLock);\r
+\r
+       Free(s);\r
+}\r
+\r
+// サーバーの解放\r
+void SiReleaseServer(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(s->ref) == 0)\r
+       {\r
+               SiCleanupServer(s);\r
+       }\r
+}\r
+\r
+// 次に処理をさせるファームメンバーを指定する\r
+FARM_MEMBER *SiGetNextFarmMember(SERVER *s)\r
+{\r
+       UINT i, num;\r
+       UINT min_point = 0;\r
+       FARM_MEMBER *ret = NULL;\r
+       // 引数チェック\r
+       if (s == NULL || s->ServerType != SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       num = LIST_NUM(s->FarmMemberList);\r
+       if (num == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               UINT num_sessions;\r
+               UINT max_sessions;\r
+               FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+               if (s->ControllerOnly)\r
+               {\r
+                       if (f->Me)\r
+                       {\r
+                               // ControllerOnly のとき自分自身は選定しない\r
+                               continue;\r
+                       }\r
+               }\r
+\r
+               if (f->Me == false)\r
+               {\r
+                       num_sessions = f->NumSessions;\r
+                       max_sessions = f->MaxSessions;\r
+               }\r
+               else\r
+               {\r
+                       num_sessions = Count(s->Cedar->CurrentSessions);\r
+                       max_sessions = GetServerCapsInt(s, "i_max_sessions");\r
+               }\r
+\r
+               if (max_sessions == 0)\r
+               {\r
+                       max_sessions = GetServerCapsInt(s, "i_max_sessions");\r
+               }\r
+\r
+               if (num_sessions < max_sessions)\r
+               {\r
+                       if (f->Point >= min_point)\r
+                       {\r
+                               min_point = f->Point;\r
+                               ret = f;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// HUB 列挙指令受信\r
+void SiCalledEnumHub(SERVER *s, PACK *p, PACK *req)\r
+{\r
+       UINT i;\r
+       CEDAR *c;\r
+       LICENSE_STATUS st;\r
+       UINT num = 0;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL || req == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LiParseCurrentLicenseStatus(s->LicenseSystem, &st);\r
+\r
+       c = s->Cedar;\r
+\r
+       LockList(c->HubList);\r
+       {\r
+               UINT num = LIST_NUM(c->HubList);\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       HUB *h = LIST_DATA(c->HubList, i);\r
+                       Lock(h->lock);\r
+                       {\r
+                               PackAddStrEx(p, "HubName", h->Name, i, num);\r
+                               PackAddIntEx(p, "HubType", h->Type, i, num);\r
+                               PackAddIntEx(p, "NumSession", Count(h->NumSessions), i, num);\r
+\r
+                               PackAddIntEx(p, "NumSessions", LIST_NUM(h->SessionList), i, num);\r
+                               PackAddIntEx(p, "NumSessionsClient", Count(h->NumSessionsClient), i, num);\r
+                               PackAddIntEx(p, "NumSessionsBridge", Count(h->NumSessionsBridge), i, num);\r
+\r
+                               PackAddIntEx(p, "NumMacTables", LIST_NUM(h->MacTable), i, num);\r
+\r
+                               PackAddIntEx(p, "NumIpTables", LIST_NUM(h->IpTable), i, num);\r
+\r
+                               PackAddInt64Ex(p, "LastCommTime", h->LastCommTime, i, num);\r
+                               PackAddInt64Ex(p, "CreatedTime", h->CreatedTime, i, num);\r
+                       }\r
+                       Unlock(h->lock);\r
+               }\r
+       }\r
+       UnlockList(c->HubList);\r
+\r
+       PackAddInt(p, "Point", SiGetPoint(s));\r
+       PackAddInt(p, "NumTcpConnections", Count(s->Cedar->CurrentTcpConnections));\r
+       PackAddInt(p, "NumTotalSessions", Count(s->Cedar->CurrentSessions));\r
+       PackAddInt(p, "MaxSessions", GetServerCapsInt(s, "i_max_sessions"));\r
+\r
+       PackAddInt(p, "AssignedClientLicense", Count(s->Cedar->AssignedClientLicense));\r
+       PackAddInt(p, "AssignedBridgeLicense", Count(s->Cedar->AssignedBridgeLicense));\r
+\r
+       PackAddData(p, "RandomKey", s->MyRandomKey, SHA1_SIZE);\r
+       PackAddInt64(p, "SystemId", st.SystemId);\r
+\r
+       Lock(c->TrafficLock);\r
+       {\r
+               OutRpcTraffic(p, c->Traffic);\r
+       }\r
+       Unlock(c->TrafficLock);\r
+\r
+       LockList(c->TrafficDiffList);\r
+       {\r
+               UINT num = LIST_NUM(c->TrafficDiffList);\r
+               UINT i;\r
+\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       TRAFFIC_DIFF *d = LIST_DATA(c->TrafficDiffList, i);\r
+\r
+                       PackAddIntEx(p, "TdType", d->Type, i, num);\r
+                       PackAddStrEx(p, "TdHubName", d->HubName, i, num);\r
+                       PackAddStrEx(p, "TdName", d->Name, i, num);\r
+\r
+                       OutRpcTrafficEx(&d->Traffic, p, i, num);\r
+\r
+                       Free(d->HubName);\r
+                       Free(d->Name);\r
+                       Free(d);\r
+               }\r
+\r
+               DeleteAll(c->TrafficDiffList);\r
+       }\r
+       UnlockList(c->TrafficDiffList);\r
+}\r
+\r
+// HUB 削除指令受信\r
+void SiCalledDeleteHub(SERVER *s, PACK *p)\r
+{\r
+       char name[MAX_SIZE];\r
+       HUB *h;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (PackGetStr(p, "HubName", name, sizeof(name)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockHubList(s->Cedar);\r
+\r
+       h = GetHub(s->Cedar, name);\r
+       if (h == NULL)\r
+       {\r
+               UnlockHubList(s->Cedar);\r
+               return;\r
+       }\r
+       UnlockHubList(s->Cedar);\r
+\r
+       SetHubOffline(h);\r
+\r
+       LockHubList(s->Cedar);\r
+\r
+       DelHubEx(s->Cedar, h, true);\r
+\r
+       UnlockHubList(s->Cedar);\r
+\r
+       ReleaseHub(h);\r
+}\r
+\r
+// HUB 更新指令受信\r
+void SiCalledUpdateHub(SERVER *s, PACK *p)\r
+{\r
+       char name[MAX_SIZE];\r
+       UINT type;\r
+       HUB_OPTION o;\r
+       HUB_LOG log;\r
+       bool save_packet_log;\r
+       UINT packet_log_switch_type;\r
+       UINT packet_log_config[NUM_PACKET_LOG];\r
+       bool save_security_log;\r
+       bool type_changed = false;\r
+       UINT security_log_switch_type;\r
+       UINT i;\r
+       HUB *h;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackGetStr(p, "HubName", name, sizeof(name));\r
+       type = PackGetInt(p, "HubType");\r
+       Zero(&o, sizeof(o));\r
+       o.MaxSession = PackGetInt(p, "MaxSession");\r
+       o.NoArpPolling = PackGetBool(p, "NoArpPolling");\r
+       o.NoIPv6AddrPolling = PackGetBool(p, "NoIPv6AddrPolling");\r
+       o.FilterPPPoE = PackGetBool(p, "FilterPPPoE");\r
+       o.YieldAfterStorePacket = PackGetBool(p, "YieldAfterStorePacket");\r
+       o.NoSpinLockForPacketDelay = PackGetBool(p, "NoSpinLockForPacketDelay");\r
+       o.BroadcastStormDetectionThreshold = PackGetInt(p, "BroadcastStormDetectionThreshold");\r
+       o.ClientMinimumRequiredBuild = PackGetInt(p, "ClientMinimumRequiredBuild");\r
+       o.FixForDLinkBPDU = PackGetBool(p, "FixForDLinkBPDU");\r
+       o.NoLookBPDUBridgeId = PackGetBool(p, "NoLookBPDUBridgeId");\r
+       o.NoManageVlanId = PackGetBool(p, "NoManageVlanId");\r
+       o.VlanTypeId = PackGetInt(p, "VlanTypeId");\r
+       if (o.VlanTypeId == 0)\r
+       {\r
+               o.VlanTypeId = MAC_PROTO_TAGVLAN;\r
+       }\r
+       o.FilterOSPF = PackGetBool(p, "FilterOSPF");\r
+       o.FilterIPv4 = PackGetBool(p, "FilterIPv4");\r
+       o.FilterIPv6 = PackGetBool(p, "FilterIPv6");\r
+       o.FilterNonIP = PackGetBool(p, "FilterNonIP");\r
+       o.NoIPv4PacketLog = PackGetBool(p, "NoIPv4PacketLog");\r
+       o.NoIPv6PacketLog = PackGetBool(p, "NoIPv6PacketLog");\r
+       o.FilterBPDU = PackGetBool(p, "FilterBPDU");\r
+       o.NoIPv6DefaultRouterInRAWhenIPv6 = PackGetBool(p, "NoIPv6DefaultRouterInRAWhenIPv6");\r
+       o.NoMacAddressLog = PackGetBool(p, "NoMacAddressLog");\r
+       o.ManageOnlyPrivateIP = PackGetBool(p, "ManageOnlyPrivateIP");\r
+       o.ManageOnlyLocalUnicastIPv6 = PackGetBool(p, "ManageOnlyLocalUnicastIPv6");\r
+       o.DisableIPParsing = PackGetBool(p, "DisableIPParsing");\r
+       o.NoIpTable = PackGetBool(p, "NoIpTable");\r
+       o.NoEnum = PackGetBool(p, "NoEnum");\r
+       save_packet_log = PackGetInt(p, "SavePacketLog");\r
+       packet_log_switch_type = PackGetInt(p, "PacketLogSwitchType");\r
+       for (i = 0;i < NUM_PACKET_LOG;i++)\r
+       {\r
+               packet_log_config[i] = PackGetIntEx(p, "PacketLogConfig", i);\r
+       }\r
+       save_security_log = PackGetInt(p, "SaveSecurityLog");\r
+       security_log_switch_type = PackGetInt(p, "SecurityLogSwitchType");\r
+\r
+       Zero(&log, sizeof(log));\r
+       log.SavePacketLog = save_packet_log;\r
+       log.PacketLogSwitchType = packet_log_switch_type;\r
+       Copy(log.PacketLogConfig, packet_log_config, sizeof(log.PacketLogConfig));\r
+       log.SaveSecurityLog = save_security_log;\r
+       log.SecurityLogSwitchType = security_log_switch_type;\r
+\r
+       h = GetHub(s->Cedar, name);\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       h->FarmMember_MaxSessionClient = PackGetInt(p, "MaxSessionClient");\r
+       h->FarmMember_MaxSessionBridge = PackGetInt(p, "MaxSessionBridge");\r
+       h->FarmMember_MaxSessionClientBridgeApply = PackGetBool(p, "MaxSessionClientBridgeApply");\r
+\r
+       if (h->FarmMember_MaxSessionClientBridgeApply == false)\r
+       {\r
+               h->FarmMember_MaxSessionClient = INFINITE;\r
+               h->FarmMember_MaxSessionBridge = INFINITE;\r
+       }\r
+\r
+       Lock(h->lock);\r
+       {\r
+               Copy(h->Option, &o, sizeof(HUB_OPTION));\r
+               PackGetData2(p, "SecurePassword", h->SecurePassword, SHA1_SIZE);\r
+               PackGetData2(p, "HashedPassword", h->HashedPassword, SHA1_SIZE);\r
+       }\r
+       Unlock(h->lock);\r
+\r
+       SetHubLogSetting(h, &log);\r
+\r
+       if (h->Type != type)\r
+       {\r
+               h->Type = type;\r
+               type_changed = true;\r
+       }\r
+\r
+       LockList(h->AccessList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(h->AccessList);i++)\r
+               {\r
+                       ACCESS *a = LIST_DATA(h->AccessList, i);\r
+                       Free(a);\r
+               }\r
+               DeleteAll(h->AccessList);\r
+       }\r
+       UnlockList(h->AccessList);\r
+\r
+       for (i = 0;i < SiNumAccessFromPack(p);i++)\r
+       {\r
+               ACCESS *a = SiPackToAccess(p, i);\r
+               AddAccessList(h, a);\r
+               Free(a);\r
+       }\r
+\r
+       if (PackGetBool(p, "EnableSecureNAT"))\r
+       {\r
+               VH_OPTION t;\r
+               bool changed;\r
+\r
+               InVhOption(&t, p);\r
+\r
+               changed = Cmp(h->SecureNATOption, &t, sizeof(VH_OPTION)) == 0 ? false : true;\r
+               Copy(h->SecureNATOption, &t, sizeof(VH_OPTION));\r
+\r
+               EnableSecureNAT(h, true);\r
+\r
+               if (changed)\r
+               {\r
+                       Lock(h->lock_online);\r
+                       {\r
+                               if (h->SecureNAT != NULL)\r
+                               {\r
+                                       SetVirtualHostOption(h->SecureNAT->Nat->Virtual, &t);\r
+                                       Debug("SiCalledUpdateHub: SecureNAT Updated.\n");\r
+                               }\r
+                       }\r
+                       Unlock(h->lock_online);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               EnableSecureNAT(h, false);\r
+               Debug("SiCalledUpdateHub: SecureNAT Disabled.\n");\r
+       }\r
+\r
+       if (type_changed)\r
+       {\r
+               // HUB の種類が変更されたのですべてのセッションを削除する\r
+               if (h->Offline == false)\r
+               {\r
+                       SetHubOffline(h);\r
+                       SetHubOnline(h);\r
+               }\r
+       }\r
+\r
+       ReleaseHub(h);\r
+}\r
+\r
+// チケットの検査\r
+bool SiCheckTicket(HUB *h, UCHAR *ticket, char *username, UINT username_size, char *usernamereal, UINT usernamereal_size, POLICY *policy, char *sessionname, UINT sessionname_size, char *groupname, UINT groupname_size)\r
+{\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (h == NULL || ticket == NULL || username == NULL || usernamereal == NULL || policy == NULL || sessionname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       LockList(h->TicketList);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(h->TicketList);i++)\r
+               {\r
+                       TICKET *t = LIST_DATA(h->TicketList, i);\r
+                       if (Cmp(t->Ticket, ticket, SHA1_SIZE) == 0)\r
+                       {\r
+                               ret = true;\r
+                               StrCpy(username, username_size, t->Username);\r
+                               StrCpy(usernamereal, usernamereal_size, t->UsernameReal);\r
+                               StrCpy(sessionname, sessionname_size, t->SessionName);\r
+                               StrCpy(groupname, groupname_size, t->GroupName);\r
+                               Copy(policy, &t->Policy, sizeof(POLICY));\r
+                               Delete(h->TicketList, t);\r
+                               Free(t);\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(h->TicketList);\r
+\r
+       return ret;\r
+}\r
+\r
+// MAC アドレス削除指令受信\r
+void SiCalledDeleteMacTable(SERVER *s, PACK *p)\r
+{\r
+       UINT key;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       HUB *h;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (PackGetStr(p, "HubName", hubname, sizeof(hubname)) == false)\r
+       {\r
+               return;\r
+       }\r
+       key = PackGetInt(p, "Key");\r
+\r
+       LockHubList(s->Cedar);\r
+       {\r
+               h = GetHub(s->Cedar, hubname);\r
+       }\r
+       UnlockHubList(s->Cedar);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(h->MacTable);\r
+       {\r
+               if (IsInList(h->MacTable, (void *)key))\r
+               {\r
+                       MAC_TABLE_ENTRY *e = (MAC_TABLE_ENTRY *)key;\r
+                       Delete(h->MacTable, e);\r
+                       Free(e);\r
+               }\r
+       }\r
+       UnlockList(h->MacTable);\r
+\r
+       ReleaseHub(h);\r
+}\r
+\r
+// IP アドレス削除指令受信\r
+void SiCalledDeleteIpTable(SERVER *s, PACK *p)\r
+{\r
+       UINT key;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       HUB *h;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (PackGetStr(p, "HubName", hubname, sizeof(hubname)) == false)\r
+       {\r
+               return;\r
+       }\r
+       key = PackGetInt(p, "Key");\r
+\r
+       LockHubList(s->Cedar);\r
+       {\r
+               h = GetHub(s->Cedar, hubname);\r
+       }\r
+       UnlockHubList(s->Cedar);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(h->IpTable);\r
+       {\r
+               if (IsInList(h->IpTable, (void *)key))\r
+               {\r
+                       IP_TABLE_ENTRY *e = (IP_TABLE_ENTRY *)key;\r
+                       Delete(h->IpTable, e);\r
+                       Free(e);\r
+               }\r
+       }\r
+       UnlockList(h->IpTable);\r
+\r
+       ReleaseHub(h);\r
+}\r
+\r
+// セッション削除指令受信\r
+void SiCalledDeleteSession(SERVER *s, PACK *p)\r
+{\r
+       char name[MAX_SESSION_NAME_LEN + 1];\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       HUB *h;\r
+       SESSION *sess;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (PackGetStr(p, "HubName", hubname, sizeof(hubname)) == false)\r
+       {\r
+               return;\r
+       }\r
+       if (PackGetStr(p, "SessionName", name, sizeof(name)) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockHubList(s->Cedar);\r
+       {\r
+               h = GetHub(s->Cedar, hubname);\r
+       }\r
+       UnlockHubList(s->Cedar);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       sess = GetSessionByName(h, name);\r
+\r
+       if (sess != NULL)\r
+       {\r
+               if (sess->BridgeMode == false && sess->LinkModeServer == false && sess->SecureNATMode == false)\r
+               {\r
+                       StopSession(sess);\r
+               }\r
+               ReleaseSession(sess);\r
+       }\r
+\r
+       ReleaseHub(h);\r
+}\r
+\r
+// ログファイル読み込み指令受信\r
+PACK *SiCalledReadLogFile(SERVER *s, PACK *p)\r
+{\r
+       RPC_READ_LOG_FILE t;\r
+       PACK *ret;\r
+       char filepath[MAX_PATH];\r
+       UINT offset;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       PackGetStr(p, "FilePath", filepath, sizeof(filepath));\r
+       offset = PackGetInt(p, "Offset");\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       SiReadLocalLogFile(s, filepath, offset, &t);\r
+\r
+       ret = NewPack();\r
+\r
+       OutRpcReadLogFile(ret, &t);\r
+       FreeRpcReadLogFile(&t);\r
+\r
+       return ret;\r
+}\r
+\r
+// ログファイル列挙指令受信\r
+PACK *SiCalledEnumLogFileList(SERVER *s, PACK *p)\r
+{\r
+       RPC_ENUM_LOG_FILE t;\r
+       PACK *ret;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       PackGetStr(p, "HubName", hubname, sizeof(hubname));\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       SiEnumLocalLogFileList(s, hubname, &t);\r
+\r
+       ret = NewPack();\r
+\r
+       OutRpcEnumLogFile(ret, &t);\r
+       FreeRpcEnumLogFile(&t);\r
+\r
+       return ret;\r
+}\r
+\r
+// セッション情報指令受信\r
+PACK *SiCalledGetSessionStatus(SERVER *s, PACK *p)\r
+{\r
+       RPC_SESSION_STATUS t;\r
+       ADMIN a;\r
+       PACK *ret;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       InRpcSessionStatus(&t, p);\r
+\r
+       Zero(&a, sizeof(a));\r
+       a.Server = s;\r
+       a.ServerAdmin = true;\r
+\r
+       if (StGetSessionStatus(&a, &t) != ERR_NO_ERROR)\r
+       {\r
+               FreeRpcSessionStatus(&t);\r
+               return NULL;\r
+       }\r
+\r
+       ret = NewPack();\r
+\r
+       OutRpcSessionStatus(ret, &t);\r
+\r
+       FreeRpcSessionStatus(&t);\r
+\r
+       return ret;\r
+}\r
+\r
+// IP テーブル列挙指令\r
+PACK *SiCalledEnumIpTable(SERVER *s, PACK *p)\r
+{\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       RPC_ENUM_IP_TABLE t;\r
+       PACK *ret;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return NewPack();\r
+       }\r
+       if (PackGetStr(p, "HubName", hubname, sizeof(hubname)) == false)\r
+       {\r
+               return NewPack();\r
+       }\r
+       Zero(&t, sizeof(t));\r
+\r
+       SiEnumIpTable(s, hubname, &t);\r
+\r
+       ret = NewPack();\r
+       OutRpcEnumIpTable(ret, &t);\r
+       FreeRpcEnumIpTable(&t);\r
+\r
+       return ret;\r
+}\r
+\r
+// MAC テーブル列挙指令\r
+PACK *SiCalledEnumMacTable(SERVER *s, PACK *p)\r
+{\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       RPC_ENUM_MAC_TABLE t;\r
+       PACK *ret;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return NewPack();\r
+       }\r
+       if (PackGetStr(p, "HubName", hubname, sizeof(hubname)) == false)\r
+       {\r
+               return NewPack();\r
+       }\r
+       Zero(&t, sizeof(t));\r
+\r
+       SiEnumMacTable(s, hubname, &t);\r
+\r
+       ret = NewPack();\r
+       OutRpcEnumMacTable(ret, &t);\r
+       FreeRpcEnumMacTable(&t);\r
+\r
+       return ret;\r
+}\r
+\r
+// NAT の状況取得指令\r
+PACK *SiCalledGetNatStatus(SERVER *s, PACK *p)\r
+{\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       RPC_NAT_STATUS t;\r
+       PACK *ret;\r
+       HUB *h;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return NewPack();\r
+       }\r
+       if (PackGetStr(p, "HubName", hubname, sizeof(hubname)) == false)\r
+       {\r
+               return NewPack();\r
+       }\r
+       Zero(&t, sizeof(t));\r
+\r
+       LockHubList(s->Cedar);\r
+       {\r
+               h = GetHub(s->Cedar, hubname);\r
+       }\r
+       UnlockHubList(s->Cedar);\r
+\r
+       if (h != NULL)\r
+       {\r
+               Lock(h->lock_online);\r
+               {\r
+                       if (h->SecureNAT != NULL)\r
+                       {\r
+                               NtGetStatus(h->SecureNAT->Nat, &t);\r
+                       }\r
+               }\r
+               Unlock(h->lock_online);\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       ret = NewPack();\r
+       OutRpcNatStatus(ret, &t);\r
+       FreeRpcNatStatus(&t);\r
+\r
+       return ret;\r
+}\r
+\r
+// DHCP テーブル列挙指令\r
+PACK *SiCalledEnumDhcp(SERVER *s, PACK *p)\r
+{\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       RPC_ENUM_DHCP t;\r
+       PACK *ret;\r
+       HUB *h;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return NewPack();\r
+       }\r
+       if (PackGetStr(p, "HubName", hubname, sizeof(hubname)) == false)\r
+       {\r
+               return NewPack();\r
+       }\r
+       Zero(&t, sizeof(t));\r
+\r
+       LockHubList(s->Cedar);\r
+       {\r
+               h = GetHub(s->Cedar, hubname);\r
+       }\r
+       UnlockHubList(s->Cedar);\r
+\r
+       if (h != NULL)\r
+       {\r
+               Lock(h->lock_online);\r
+               {\r
+                       if (h->SecureNAT != NULL)\r
+                       {\r
+                               NtEnumDhcpList(h->SecureNAT->Nat, &t);\r
+                       }\r
+               }\r
+               Unlock(h->lock_online);\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       ret = NewPack();\r
+       OutRpcEnumDhcp(ret, &t);\r
+       FreeRpcEnumDhcp(&t);\r
+\r
+       return ret;\r
+}\r
+\r
+// NAT テーブル列挙指令\r
+PACK *SiCalledEnumNat(SERVER *s, PACK *p)\r
+{\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       RPC_ENUM_NAT t;\r
+       PACK *ret;\r
+       HUB *h;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return NewPack();\r
+       }\r
+       if (PackGetStr(p, "HubName", hubname, sizeof(hubname)) == false)\r
+       {\r
+               return NewPack();\r
+       }\r
+       Zero(&t, sizeof(t));\r
+\r
+       LockHubList(s->Cedar);\r
+       {\r
+               h = GetHub(s->Cedar, hubname);\r
+       }\r
+       UnlockHubList(s->Cedar);\r
+\r
+       if (h != NULL)\r
+       {\r
+               Lock(h->lock_online);\r
+               {\r
+                       if (h->SecureNAT != NULL)\r
+                       {\r
+                               NtEnumNatList(h->SecureNAT->Nat, &t);\r
+                       }\r
+               }\r
+               Unlock(h->lock_online);\r
+       }\r
+\r
+       ReleaseHub(h);\r
+\r
+       ret = NewPack();\r
+       OutRpcEnumNat(ret, &t);\r
+       FreeRpcEnumNat(&t);\r
+\r
+       return ret;\r
+}\r
+\r
+// セッション列挙指令受信\r
+PACK *SiCalledEnumSession(SERVER *s, PACK *p)\r
+{\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       RPC_ENUM_SESSION t;\r
+       PACK *ret;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return NewPack();\r
+       }\r
+       if (PackGetStr(p, "HubName", hubname, sizeof(hubname)) == false)\r
+       {\r
+               return NewPack();\r
+       }\r
+       Zero(&t, sizeof(t));\r
+\r
+       SiEnumLocalSession(s, hubname, &t);\r
+\r
+       ret = NewPack();\r
+       OutRpcEnumSession(ret, &t);\r
+       FreeRpcEnumSession(&t);\r
+\r
+       return ret;\r
+}\r
+\r
+// チケット作成指令受信\r
+PACK *SiCalledCreateTicket(SERVER *s, PACK *p)\r
+{\r
+       char username[MAX_SIZE];\r
+       char hubname[MAX_SIZE];\r
+       char groupname[MAX_SIZE];\r
+       char realusername[MAX_SIZE];\r
+       char sessionname[MAX_SESSION_NAME_LEN + 1];\r
+       POLICY policy;\r
+       UCHAR ticket[SHA1_SIZE];\r
+       char ticket_str[MAX_SIZE];\r
+       HUB *h;\r
+       UINT i;\r
+       PACK *ret;\r
+       TICKET *t;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return NewPack();\r
+       }\r
+\r
+       PackGetStr(p, "UserName", username, sizeof(username));\r
+       PackGetStr(p, "GroupName", groupname, sizeof(groupname));\r
+       PackGetStr(p, "HubName", hubname, sizeof(hubname));\r
+       PackGetStr(p, "RealUserName", realusername, sizeof(realusername));\r
+       PackGetStr(p, "SessionName", sessionname, sizeof(sessionname));\r
+\r
+       InRpcPolicy(&policy, p);\r
+       if (PackGetDataSize(p, "Ticket") == SHA1_SIZE)\r
+       {\r
+               PackGetData(p, "Ticket", ticket);\r
+       }\r
+\r
+       BinToStr(ticket_str, sizeof(ticket_str), ticket, SHA1_SIZE);\r
+\r
+       SLog(s->Cedar, "LS_TICKET_2", hubname, username, realusername, sessionname,\r
+               ticket_str, TICKET_EXPIRES / 1000);\r
+\r
+       // HUB を取得\r
+       h = GetHub(s->Cedar, hubname);\r
+       if (h == NULL)\r
+       {\r
+               return NewPack();\r
+       }\r
+\r
+       LockList(h->TicketList);\r
+       {\r
+               LIST *o = NewListFast(NULL);\r
+               // 古いチケットを破棄\r
+               for (i = 0;i < LIST_NUM(h->TicketList);i++)\r
+               {\r
+                       TICKET *t = LIST_DATA(h->TicketList, i);\r
+                       if ((t->CreatedTick + TICKET_EXPIRES) < Tick64())\r
+                       {\r
+                               Add(o, t);\r
+                       }\r
+               }\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       TICKET *t = LIST_DATA(o, i);\r
+                       Delete(h->TicketList, t);\r
+                       Free(t);\r
+               }\r
+               ReleaseList(o);\r
+\r
+               // チケットを作成\r
+               t = ZeroMalloc(sizeof(TICKET));\r
+               t->CreatedTick = Tick64();\r
+               Copy(&t->Policy, &policy, sizeof(POLICY));\r
+               Copy(t->Ticket, ticket, SHA1_SIZE);\r
+               StrCpy(t->Username, sizeof(t->Username), username);\r
+               StrCpy(t->UsernameReal, sizeof(t->UsernameReal), realusername);\r
+               StrCpy(t->GroupName, sizeof(t->GroupName), groupname);\r
+               StrCpy(t->SessionName, sizeof(t->SessionName), sessionname);\r
+\r
+               Add(h->TicketList, t);\r
+       }\r
+       UnlockList(h->TicketList);\r
+\r
+       ReleaseHub(h);\r
+\r
+       ret = NewPack();\r
+\r
+       PackAddInt(ret, "Point", SiGetPoint(s));\r
+\r
+       return ret;\r
+}\r
+\r
+// HUB 作成指令受信\r
+void SiCalledCreateHub(SERVER *s, PACK *p)\r
+{\r
+       char name[MAX_SIZE];\r
+       UINT type;\r
+       HUB_OPTION o;\r
+       HUB_LOG log;\r
+       bool save_packet_log;\r
+       UINT packet_log_switch_type;\r
+       UINT packet_log_config[NUM_PACKET_LOG];\r
+       bool save_security_log;\r
+       UINT security_log_switch_type;\r
+       UINT i;\r
+       HUB *h;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackGetStr(p, "HubName", name, sizeof(name));\r
+       type = PackGetInt(p, "HubType");\r
+       Zero(&o, sizeof(o));\r
+       o.MaxSession = PackGetInt(p, "MaxSession");\r
+       save_packet_log = PackGetInt(p, "SavePacketLog");\r
+       packet_log_switch_type = PackGetInt(p, "PacketLogSwitchType");\r
+       for (i = 0;i < NUM_PACKET_LOG;i++)\r
+       {\r
+               packet_log_config[i] = PackGetIntEx(p, "PacketLogConfig", i);\r
+       }\r
+       save_security_log = PackGetInt(p, "SaveSecurityLog");\r
+       security_log_switch_type = PackGetInt(p, "SecurityLogSwitchType");\r
+\r
+       Zero(&log, sizeof(log));\r
+       log.SavePacketLog = save_packet_log;\r
+       log.PacketLogSwitchType = packet_log_switch_type;\r
+       Copy(log.PacketLogConfig, packet_log_config, sizeof(log.PacketLogConfig));\r
+       log.SaveSecurityLog = save_security_log;\r
+       log.SecurityLogSwitchType = security_log_switch_type;\r
+\r
+       h = NewHub(s->Cedar, name, &o);\r
+       h->LastCommTime = h->LastLoginTime = h->CreatedTime = 0;\r
+       SetHubLogSetting(h, &log);\r
+       h->Type = type;\r
+       h->FarmMember_MaxSessionClient = PackGetInt(p, "MaxSessionClient");\r
+       h->FarmMember_MaxSessionBridge = PackGetInt(p, "MaxSessionBridge");\r
+       h->FarmMember_MaxSessionClientBridgeApply = PackGetBool(p, "MaxSessionClientBridgeApply");\r
+\r
+       if (h->FarmMember_MaxSessionClientBridgeApply == false)\r
+       {\r
+               h->FarmMember_MaxSessionClient = INFINITE;\r
+               h->FarmMember_MaxSessionBridge = INFINITE;\r
+       }\r
+\r
+       PackGetData2(p, "SecurePassword", h->SecurePassword, SHA1_SIZE);\r
+       PackGetData2(p, "HashedPassword", h->HashedPassword, SHA1_SIZE);\r
+\r
+       for (i = 0;i < SiNumAccessFromPack(p);i++)\r
+       {\r
+               ACCESS *a = SiPackToAccess(p, i);\r
+               AddAccessList(h, a);\r
+               Free(a);\r
+       }\r
+\r
+       if (PackGetBool(p, "EnableSecureNAT"))\r
+       {\r
+               VH_OPTION t;\r
+\r
+               InVhOption(&t, p);\r
+\r
+               Copy(h->SecureNATOption, &t, sizeof(VH_OPTION));\r
+               EnableSecureNAT(h, true);\r
+\r
+               Debug("SiCalledCreateHub: SecureNAT Created.\n");\r
+       }\r
+\r
+       AddHub(s->Cedar, h);\r
+       h->Offline = true;\r
+       SetHubOnline(h);\r
+\r
+       ReleaseHub(h);\r
+}\r
+\r
+// ファームコントロールスレッド\r
+void SiFarmControlThread(THREAD *thread, void *param)\r
+{\r
+       SERVER *s;\r
+       CEDAR *c;\r
+       EVENT *e;\r
+       LIST *o;\r
+       UINT i;\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = (SERVER *)param;\r
+       c = s->Cedar;\r
+       e = s->FarmControlThreadHaltEvent;\r
+\r
+       while (true)\r
+       {\r
+               Lock(c->CedarSuperLock);\r
+\r
+               // 各ファームメンバーがホストしている HUB 一覧を列挙する\r
+               Format(tmp, sizeof(tmp), "CONTROLLER: %s %u", __FILE__, __LINE__);\r
+               SiDebugLog(s, tmp);\r
+\r
+               LockList(s->FarmMemberList);\r
+               {\r
+                       UINT i;\r
+                       UINT num;\r
+                       UINT assigned_client_license = 0;\r
+                       UINT assigned_bridge_license = 0;\r
+\r
+                       Format(tmp, sizeof(tmp), "CONTROLLER: %s %u", __FILE__, __LINE__);\r
+                       SiDebugLog(s, tmp);\r
+\r
+                       num = 0;\r
+\r
+                       for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                       {\r
+                               FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                               SiCallEnumHub(s, f);\r
+                               // サーバーファーム全体での合計セッション数を取得する\r
+                               num += f->NumSessions;\r
+\r
+                               assigned_client_license += f->AssignedClientLicense;\r
+                               assigned_bridge_license += f->AssignedBridgeLicense;\r
+                       }\r
+\r
+                       s->CurrentTotalNumSessionsOnFarm = num;\r
+\r
+                       // 割り当て済みライセンス数を更新する\r
+                       s->CurrentAssignedBridgeLicense = assigned_bridge_license;\r
+                       s->CurrentAssignedClientLicense = assigned_client_license;\r
+\r
+                       Format(tmp, sizeof(tmp), "CONTROLLER: %s %u", __FILE__, __LINE__);\r
+                       SiDebugLog(s, tmp);\r
+               }\r
+               UnlockList(s->FarmMemberList);\r
+\r
+               Format(tmp, sizeof(tmp), "CONTROLLER: %s %u", __FILE__, __LINE__);\r
+               SiDebugLog(s, tmp);\r
+\r
+               o = NewListFast(NULL);\r
+\r
+               Format(tmp, sizeof(tmp), "CONTROLLER: %s %u", __FILE__, __LINE__);\r
+               SiDebugLog(s, tmp);\r
+\r
+               // 各 HUB に対して更新通知を発する\r
+               LockList(c->HubList);\r
+               {\r
+                       UINT i;\r
+                       for (i = 0;i < LIST_NUM(c->HubList);i++)\r
+                       {\r
+                               HUB *h = LIST_DATA(c->HubList, i);\r
+                               AddRef(h->ref);\r
+                               Add(o, h);\r
+                       }\r
+               }\r
+               UnlockList(c->HubList);\r
+\r
+               Format(tmp, sizeof(tmp), "CONTROLLER: %s %u", __FILE__, __LINE__);\r
+               SiDebugLog(s, tmp);\r
+\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       HUB *h = LIST_DATA(o, i);\r
+                       SiHubUpdateProc(h);\r
+                       ReleaseHub(h);\r
+               }\r
+\r
+               Format(tmp, sizeof(tmp), "CONTROLLER: %s %u", __FILE__, __LINE__);\r
+               SiDebugLog(s, tmp);\r
+\r
+               ReleaseList(o);\r
+\r
+               Unlock(c->CedarSuperLock);\r
+\r
+               Wait(e, SERVER_FARM_CONTROL_INTERVAL);\r
+               if (s->Halt)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// ファームコントロールの開始\r
+void SiStartFarmControl(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || s->ServerType != SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s->FarmControlThreadHaltEvent = NewEvent();\r
+       s->FarmControlThread = NewThread(SiFarmControlThread, s);\r
+}\r
+\r
+// ファームコントロールの終了\r
+void SiStopFarmControl(SERVER *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || s->ServerType != SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Set(s->FarmControlThreadHaltEvent);\r
+       WaitThread(s->FarmControlThread, INFINITE);\r
+       ReleaseEvent(s->FarmControlThreadHaltEvent);\r
+       ReleaseThread(s->FarmControlThread);\r
+}\r
+\r
+// HUB 列挙指令\r
+void SiCallEnumHub(SERVER *s, FARM_MEMBER *f)\r
+{\r
+       CEDAR *c;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c = s->Cedar;\r
+\r
+       if (f->Me)\r
+       {\r
+               LICENSE_STATUS st;\r
+\r
+               LiParseCurrentLicenseStatus(s->LicenseSystem, &st);\r
+\r
+               // ローカルの HUB を列挙する\r
+               LockList(f->HubList);\r
+               {\r
+                       // ローカル HUB の場合、まず STATIC HUB リストを一旦\r
+                       // すべて消去して再列挙を行うようにする\r
+                       UINT i;\r
+                       LIST *o = NewListFast(NULL);\r
+                       for (i = 0;i < LIST_NUM(f->HubList);i++)\r
+                       {\r
+                               HUB_LIST *h = LIST_DATA(f->HubList, i);\r
+                               if (h->DynamicHub == false)\r
+                               {\r
+                                       Add(o, h);\r
+                               }\r
+                       }\r
+\r
+                       // STATIC HUB をすべて消去\r
+                       for (i = 0;i < LIST_NUM(o);i++)\r
+                       {\r
+                               HUB_LIST *h = LIST_DATA(o, i);\r
+                               Free(h);\r
+                               Delete(f->HubList, h);\r
+                       }\r
+                       ReleaseList(o);\r
+\r
+                       // 次に DYNAMIC HUB でユーザーが 1 人もいないものを停止する\r
+                       o = NewListFast(NULL);\r
+                       for (i = 0;i < LIST_NUM(f->HubList);i++)\r
+                       {\r
+                               HUB_LIST *h = LIST_DATA(f->HubList, i);\r
+                               if (h->DynamicHub == true)\r
+                               {\r
+                                       LockList(c->HubList);\r
+                                       {\r
+                                               HUB *hub = GetHub(s->Cedar, h->Name);\r
+                                               if (hub != NULL)\r
+                                               {\r
+                                                       if (Count(hub->NumSessions) == 0 || hub->Type != HUB_TYPE_FARM_DYNAMIC)\r
+                                                       {\r
+                                                               Add(o, h);\r
+                                                       }\r
+                                                       ReleaseHub(hub);\r
+                                               }\r
+                                       }\r
+                                       UnlockList(c->HubList);\r
+                               }\r
+                       }\r
+\r
+                       for (i = 0;i < LIST_NUM(o);i++)\r
+                       {\r
+                               HUB_LIST *h = LIST_DATA(o, i);\r
+                               Debug("Delete HUB: %s\n", h->Name);\r
+                               Free(h);\r
+                               Delete(f->HubList, h);\r
+                       }\r
+\r
+                       ReleaseList(o);\r
+\r
+                       // 列挙結果を設定\r
+                       LockList(c->HubList);\r
+                       {\r
+                               for (i = 0;i < LIST_NUM(c->HubList);i++)\r
+                               {\r
+                                       HUB *h = LIST_DATA(c->HubList, i);\r
+                                       if (h->Offline == false)\r
+                                       {\r
+                                               if (h->Type == HUB_TYPE_FARM_STATIC)\r
+                                               {\r
+                                                       HUB_LIST *hh = ZeroMalloc(sizeof(HUB_LIST));\r
+                                                       hh->FarmMember = f;\r
+                                                       hh->DynamicHub = false;\r
+                                                       StrCpy(hh->Name, sizeof(hh->Name), h->Name);\r
+                                                       Add(f->HubList, hh);\r
+\r
+                                                       LockList(h->SessionList);\r
+                                                       {\r
+                                                               hh->NumSessions = LIST_NUM(h->SessionList);\r
+                                                               hh->NumSessionsBridge = Count(h->NumSessionsBridge);\r
+                                                               hh->NumSessionsClient = Count(h->NumSessionsClient);\r
+                                                       }\r
+                                                       UnlockList(h->SessionList);\r
+\r
+                                                       LockList(h->MacTable);\r
+                                                       {\r
+                                                               hh->NumMacTables = LIST_NUM(h->MacTable);\r
+                                                       }\r
+                                                       UnlockList(h->MacTable);\r
+\r
+                                                       LockList(h->IpTable);\r
+                                                       {\r
+                                                               hh->NumIpTables = LIST_NUM(h->IpTable);\r
+                                                       }\r
+                                                       UnlockList(h->IpTable);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       UnlockList(c->HubList);\r
+               }\r
+               UnlockList(f->HubList);\r
+\r
+               // ポイント\r
+               f->Point = SiGetPoint(s);\r
+               f->NumSessions = Count(s->Cedar->CurrentSessions);\r
+               f->MaxSessions = GetServerCapsInt(s, "i_max_sessions");\r
+               f->NumTcpConnections = Count(s->Cedar->CurrentTcpConnections);\r
+\r
+               Lock(s->Cedar->TrafficLock);\r
+               {\r
+                       Copy(&f->Traffic, s->Cedar->Traffic, sizeof(TRAFFIC));\r
+               }\r
+               Unlock(s->Cedar->TrafficLock);\r
+\r
+               f->AssignedBridgeLicense = Count(s->Cedar->AssignedBridgeLicense);\r
+               f->AssignedClientLicense = Count(s->Cedar->AssignedClientLicense);\r
+\r
+               Copy(f->RandomKey, s->MyRandomKey, SHA1_SIZE);\r
+               f->SystemId = st.SystemId;\r
+\r
+               Debug("Server %s: Point %u\n", f->hostname, f->Point);\r
+       }\r
+       else\r
+       {\r
+               // リモートのメンバの HUB を列挙する\r
+               PACK *p = NewPack();\r
+               UINT i, num, j;\r
+               LIST *o = NewListFast(NULL);\r
+\r
+               num = 0;\r
+\r
+               for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+               {\r
+                       FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+\r
+                       if (IsZero(f->RandomKey, SHA1_SIZE) == false && f->SystemId != 0)\r
+                       {\r
+                               num++;\r
+                       }\r
+               }\r
+\r
+               j = 0;\r
+\r
+               for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+               {\r
+                       FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+\r
+                       if (IsZero(f->RandomKey, SHA1_SIZE) == false && f->SystemId != 0)\r
+                       {\r
+                               PackAddDataEx(p, "MemberRandomKey", f->RandomKey, SHA1_SIZE, j, num);\r
+                               PackAddInt64Ex(p, "MemberSystemId", f->SystemId, j, num);\r
+                               j++;\r
+                       }\r
+               }\r
+               PackAddInt(p, "MemberSystemIdNum", num);\r
+\r
+               p = SiCallTask(f, p, "enumhub");\r
+               if (p != NULL)\r
+               {\r
+                       LockList(f->HubList);\r
+                       {\r
+                               UINT i;\r
+                               // リスト消去\r
+                               for (i = 0;i < LIST_NUM(f->HubList);i++)\r
+                               {\r
+                                       HUB_LIST *hh = LIST_DATA(f->HubList, i);\r
+                                       Free(hh);\r
+                               }\r
+                               DeleteAll(f->HubList);\r
+\r
+                               for (i = 0;i < PackGetIndexCount(p, "HubName");i++)\r
+                               {\r
+                                       HUB_LIST *hh = ZeroMalloc(sizeof(HUB_LIST));\r
+                                       UINT num;\r
+                                       UINT64 LastCommTime;\r
+\r
+                                       PackGetStrEx(p, "HubName", hh->Name, sizeof(hh->Name), i);\r
+                                       num = PackGetIntEx(p, "NumSession", i);\r
+                                       hh->DynamicHub = ((PackGetIntEx(p, "HubType", i) == HUB_TYPE_FARM_DYNAMIC) ? true : false);\r
+                                       hh->FarmMember = f;\r
+                                       hh->NumSessions = PackGetIntEx(p, "NumSessions", i);\r
+                                       hh->NumSessionsClient = PackGetIntEx(p, "NumSessionsClient", i);\r
+                                       hh->NumSessionsBridge = PackGetIntEx(p, "NumSessionsBridge", i);\r
+                                       hh->NumIpTables = PackGetIntEx(p, "NumIpTables", i);\r
+                                       hh->NumMacTables = PackGetIntEx(p, "NumMacTables", i);\r
+                                       LastCommTime = PackGetInt64Ex(p, "LastCommTime", i);\r
+                                       Add(f->HubList, hh);\r
+                                       Debug("%s\n", hh->Name);\r
+\r
+                                       LockList(c->HubList);\r
+                                       {\r
+                                               HUB *h = GetHub(c, hh->Name);\r
+\r
+                                               if (h != NULL)\r
+                                               {\r
+                                                       // 仮想 HUB の LastCommTime を更新する\r
+                                                       Lock(h->lock);\r
+                                                       {\r
+                                                               if (h->LastCommTime < LastCommTime)\r
+                                                               {\r
+                                                                       h->LastCommTime = LastCommTime;\r
+                                                               }\r
+                                                       }\r
+                                                       Unlock(h->lock);\r
+\r
+                                                       ReleaseHub(h);\r
+                                               }\r
+                                       }\r
+                                       UnlockList(c->HubList);\r
+\r
+                                       if (hh->DynamicHub && num >= 1)\r
+                                       {\r
+                                               // すでにユーザーセッションが 1 以上接続されているので\r
+                                               // 仮想 HUB 作成履歴リストに登録しておく必要はない\r
+                                               // 仮想 HUB 作成履歴リストから削除する\r
+                                               SiDelHubCreateHistory(s, hh->Name);\r
+                                       }\r
+\r
+                                       if (hh->DynamicHub && num == 0)\r
+                                       {\r
+                                               // 仮想 HUB 作成履歴リストを確認する\r
+                                               // 直近 60 秒以内に作成され、まだ 1 人目のユーザーが接続\r
+                                               // していない仮想 HUB の場合は、ユーザーが 1 人もいないという\r
+                                               // 理由で削除しない\r
+                                               if (SiIsHubRegistedOnCreateHistory(s, hh->Name) == false)\r
+                                               {\r
+                                                       // ダイナミック HUB でユーザーが 1 人もいないので停止する\r
+                                                       HUB *h;\r
+                                                       LockList(c->HubList);\r
+                                                       {\r
+                                                               h = GetHub(c, hh->Name);\r
+                                                       }\r
+                                                       UnlockList(c->HubList);\r
+\r
+                                                       if (h != NULL)\r
+                                                       {\r
+                                                               Add(o, h);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       UnlockList(f->HubList);\r
+                       f->Point = PackGetInt(p, "Point");\r
+                       Debug("Server %s: Point %u\n", f->hostname, f->Point);\r
+                       f->NumSessions = PackGetInt(p, "NumTotalSessions");\r
+                       if (f->NumSessions == 0)\r
+                       {\r
+                               f->NumSessions = PackGetInt(p, "NumSessions");\r
+                       }\r
+                       f->MaxSessions = PackGetInt(p, "MaxSessions");\r
+                       f->NumTcpConnections = PackGetInt(p, "NumTcpConnections");\r
+                       InRpcTraffic(&f->Traffic, p);\r
+\r
+                       f->AssignedBridgeLicense = PackGetInt(p, "AssignedBridgeLicense");\r
+                       f->AssignedClientLicense = PackGetInt(p, "AssignedClientLicense");\r
+\r
+                       if (PackGetDataSize(p, "RandomKey") == SHA1_SIZE)\r
+                       {\r
+                               PackGetData(p, "RandomKey", f->RandomKey);\r
+                       }\r
+\r
+                       f->SystemId = PackGetInt64(p, "SystemId");\r
+\r
+                       // トラフィック差分情報を適用する\r
+                       num = PackGetIndexCount(p, "TdType");\r
+                       for (i = 0;i < num;i++)\r
+                       {\r
+                               TRAFFIC traffic;\r
+                               UINT type;\r
+                               HUB *h;\r
+                               char name[MAX_SIZE];\r
+                               char hubname[MAX_SIZE];\r
+\r
+                               type = PackGetIntEx(p, "TdType", i);\r
+                               PackGetStrEx(p, "TdName", name, sizeof(name), i);\r
+                               PackGetStrEx(p, "TdHubName", hubname, sizeof(hubname), i);\r
+                               InRpcTrafficEx(&traffic, p, i);\r
+\r
+                               LockList(c->HubList);\r
+                               {\r
+                                       h = GetHub(c, hubname);\r
+                                       if (h != NULL)\r
+                                       {\r
+                                               if (type == TRAFFIC_DIFF_HUB)\r
+                                               {\r
+                                                       Lock(h->TrafficLock);\r
+                                                       {\r
+                                                               AddTraffic(h->Traffic, &traffic);\r
+                                                       }\r
+                                                       Unlock(h->TrafficLock);\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       AcLock(h);\r
+                                                       {\r
+                                                               USER *u = AcGetUser(h, name);\r
+                                                               if (u != NULL)\r
+                                                               {\r
+                                                                       Lock(u->lock);\r
+                                                                       {\r
+                                                                               AddTraffic(u->Traffic, &traffic);\r
+                                                                       }\r
+                                                                       Unlock(u->lock);\r
+                                                                       if (u->Group != NULL)\r
+                                                                       {\r
+                                                                               Lock(u->Group->lock);\r
+                                                                               {\r
+                                                                                       AddTraffic(u->Group->Traffic, &traffic);\r
+                                                                               }\r
+                                                                               Unlock(u->Group->lock);\r
+                                                                       }\r
+                                                                       ReleaseUser(u);\r
+                                                               }\r
+                                                       }\r
+                                                       AcUnlock(h);\r
+                                               }\r
+                                               ReleaseHub(h);\r
+                                       }\r
+                                       UnlockList(c->HubList);\r
+                               }\r
+                       }\r
+\r
+                       FreePack(p);\r
+               }\r
+\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       HUB *h = LIST_DATA(o, i);\r
+                       SiCallDeleteHub(s, f, h);\r
+                       Debug("Delete HUB: %s\n", h->Name);\r
+                       ReleaseHub(h);\r
+               }\r
+\r
+               ReleaseList(o);\r
+       }\r
+}\r
+\r
+// セッション情報取得指令\r
+bool SiCallGetSessionStatus(SERVER *s, FARM_MEMBER *f, RPC_SESSION_STATUS *t)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcSessionStatus(p, t);\r
+       FreeRpcSessionStatus(t);\r
+       Zero(t, sizeof(RPC_SESSION_STATUS));\r
+\r
+       p = SiCallTask(f, p, "getsessionstatus");\r
+\r
+       if (p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       InRpcSessionStatus(t, p);\r
+       FreePack(p);\r
+\r
+       return true;\r
+}\r
+\r
+// ログファイル読み込み指令\r
+bool SiCallReadLogFile(SERVER *s, FARM_MEMBER *f, RPC_READ_LOG_FILE *t)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcReadLogFile(p, t);\r
+       FreeRpcReadLogFile(t);\r
+       Zero(t, sizeof(RPC_READ_LOG_FILE));\r
+\r
+       p = SiCallTask(f, p, "readlogfile");\r
+\r
+       if (p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       InRpcReadLogFile(t, p);\r
+       FreePack(p);\r
+\r
+       return true;\r
+}\r
+\r
+// ログファイルリスト列挙指令\r
+bool SiCallEnumLogFileList(SERVER *s, FARM_MEMBER *f, RPC_ENUM_LOG_FILE *t, char *hubname)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = NewPack();\r
+       OutRpcEnumLogFile(p, t);\r
+       FreeRpcEnumLogFile(t);\r
+       Zero(t, sizeof(RPC_ENUM_LOG_FILE));\r
+\r
+       PackAddStr(p, "HubName", hubname);\r
+\r
+       p = SiCallTask(f, p, "enumlogfilelist");\r
+\r
+       if (p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       InRpcEnumLogFile(t, p);\r
+       FreePack(p);\r
+\r
+       return true;\r
+}\r
+\r
+// HUB 削除指令\r
+void SiCallDeleteHub(SERVER *s, FARM_MEMBER *f, HUB *h)\r
+{\r
+       PACK *p;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (f->Me == false)\r
+       {\r
+               p = NewPack();\r
+\r
+               PackAddStr(p, "HubName", h->Name);\r
+\r
+               p = SiCallTask(f, p, "deletehub");\r
+               FreePack(p);\r
+       }\r
+\r
+       LockList(f->HubList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(f->HubList);i++)\r
+               {\r
+                       HUB_LIST *hh = LIST_DATA(f->HubList, i);\r
+                       if (StrCmpi(hh->Name, h->Name) == 0)\r
+                       {\r
+                               Free(hh);\r
+                               Delete(f->HubList, hh);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(f->HubList);\r
+}\r
+\r
+// HUB 更新指令送信\r
+void SiCallUpdateHub(SERVER *s, FARM_MEMBER *f, HUB *h)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (f->Me == false)\r
+       {\r
+               p = NewPack();\r
+\r
+               SiPackAddCreateHub(p, h);\r
+\r
+               p = SiCallTask(f, p, "updatehub");\r
+               FreePack(p);\r
+       }\r
+}\r
+\r
+// チケット作成指令送信\r
+void SiCallCreateTicket(SERVER *s, FARM_MEMBER *f, char *hubname, char *username, char *realusername, POLICY *policy, UCHAR *ticket, UINT counter, char *groupname)\r
+{\r
+       PACK *p;\r
+       char name[MAX_SESSION_NAME_LEN + 1];\r
+       char hub_name_upper[MAX_SIZE];\r
+       char user_name_upper[MAX_USERNAME_LEN + 1];\r
+       char ticket_str[MAX_SIZE];\r
+       UINT point;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL || realusername == NULL || hubname == NULL || username == NULL || policy == NULL || ticket == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (groupname == NULL)\r
+       {\r
+               groupname = "";\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "HubName", hubname);\r
+       PackAddStr(p, "UserName", username);\r
+       PackAddStr(p, "groupname", groupname);\r
+       PackAddStr(p, "RealUserName", realusername);\r
+       OutRpcPolicy(p, policy);\r
+       PackAddData(p, "Ticket", ticket, SHA1_SIZE);\r
+\r
+       BinToStr(ticket_str, sizeof(ticket_str), ticket, SHA1_SIZE);\r
+\r
+       StrCpy(hub_name_upper, sizeof(hub_name_upper), hubname);\r
+       StrUpper(hub_name_upper);\r
+       StrCpy(user_name_upper, sizeof(user_name_upper), username);\r
+       StrUpper(user_name_upper);\r
+       Format(name, sizeof(name), "SID-%s-%u", user_name_upper,\r
+               counter);\r
+       PackAddStr(p, "SessionName", name);\r
+\r
+       p = SiCallTask(f, p, "createticket");\r
+\r
+       SLog(s->Cedar, "LS_TICKET_1", f->hostname, hubname, username, realusername, name, ticket_str);\r
+\r
+       point = PackGetInt(p, "Point");\r
+       if (point != 0)\r
+       {\r
+               f->Point = point;\r
+               f->NumSessions++;\r
+       }\r
+\r
+       FreePack(p);\r
+}\r
+\r
+// MAC アドレス削除指令送信\r
+void SiCallDeleteMacTable(SERVER *s, FARM_MEMBER *f, char *hubname, UINT key)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL || hubname == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "HubName", hubname);\r
+       PackAddInt(p, "Key", key);\r
+\r
+       p = SiCallTask(f, p, "deletemactable");\r
+\r
+       FreePack(p);\r
+}\r
+\r
+// IP アドレス削除指令送信\r
+void SiCallDeleteIpTable(SERVER *s, FARM_MEMBER *f, char *hubname, UINT key)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL || hubname == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "HubName", hubname);\r
+       PackAddInt(p, "Key", key);\r
+\r
+       p = SiCallTask(f, p, "deleteiptable");\r
+\r
+       FreePack(p);\r
+}\r
+\r
+// セッション削除指令送信\r
+void SiCallDeleteSession(SERVER *s, FARM_MEMBER *f, char *hubname, char *session_name)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL || hubname == NULL || session_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "HubName", hubname);\r
+       PackAddStr(p, "SessionName", session_name);\r
+\r
+       p = SiCallTask(f, p, "deletesession");\r
+\r
+       FreePack(p);\r
+}\r
+\r
+// IP テーブル列挙指令送信\r
+void SiCallEnumIpTable(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_ENUM_IP_TABLE *t)\r
+{\r
+       PACK *p;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL || hubname == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "HubName", hubname);\r
+\r
+       p = SiCallTask(f, p, "enumiptable");\r
+\r
+       Zero(t, sizeof(RPC_ENUM_IP_TABLE));\r
+       InRpcEnumIpTable(t, p);\r
+\r
+       for (i = 0;i < t->NumIpTable;i++)\r
+       {\r
+               t->IpTables[i].RemoteItem = true;\r
+               StrCpy(t->IpTables[i].RemoteHostname, sizeof(t->IpTables[i].RemoteHostname),\r
+                       f->hostname);\r
+       }\r
+\r
+       FreePack(p);\r
+}\r
+\r
+// MAC テーブル列挙指令送信\r
+void SiCallEnumMacTable(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_ENUM_MAC_TABLE *t)\r
+{\r
+       PACK *p;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL || hubname == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "HubName", hubname);\r
+\r
+       p = SiCallTask(f, p, "enummactable");\r
+\r
+       Zero(t, sizeof(RPC_ENUM_MAC_TABLE));\r
+       InRpcEnumMacTable(t, p);\r
+\r
+       for (i = 0;i < t->NumMacTable;i++)\r
+       {\r
+               t->MacTables[i].RemoteItem = true;\r
+               StrCpy(t->MacTables[i].RemoteHostname, sizeof(t->MacTables[i].RemoteHostname),\r
+                       f->hostname);\r
+       }\r
+\r
+       FreePack(p);\r
+}\r
+\r
+// SecureNAT 状況の取得指令送信\r
+void SiCallGetNatStatus(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_NAT_STATUS *t)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL || hubname == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "HubName", hubname);\r
+\r
+       p = SiCallTask(f, p, "getnatstatus");\r
+\r
+       Zero(t, sizeof(RPC_NAT_STATUS));\r
+       InRpcNatStatus(t, p);\r
+\r
+       FreePack(p);\r
+}\r
+\r
+// DHCP エントリ列挙指令送信\r
+void SiCallEnumDhcp(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_ENUM_DHCP *t)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL || hubname == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "HubName", hubname);\r
+\r
+       p = SiCallTask(f, p, "enumdhcp");\r
+\r
+       Zero(t, sizeof(RPC_ENUM_DHCP));\r
+       InRpcEnumDhcp(t, p);\r
+\r
+       FreePack(p);\r
+}\r
+\r
+// NAT エントリ列挙指令送信\r
+void SiCallEnumNat(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_ENUM_NAT *t)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL || hubname == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "HubName", hubname);\r
+\r
+       p = SiCallTask(f, p, "enumnat");\r
+\r
+       Zero(t, sizeof(RPC_ENUM_NAT));\r
+       InRpcEnumNat(t, p);\r
+\r
+       FreePack(p);\r
+}\r
+\r
+// セッション列挙指令送信\r
+void SiCallEnumSession(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_ENUM_SESSION *t)\r
+{\r
+       PACK *p;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL || hubname == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = NewPack();\r
+       PackAddStr(p, "HubName", hubname);\r
+\r
+       p = SiCallTask(f, p, "enumsession");\r
+\r
+       Zero(t, sizeof(RPC_ENUM_SESSION));\r
+       InRpcEnumSession(t, p);\r
+\r
+       for (i = 0;i < t->NumSession;i++)\r
+       {\r
+               t->Sessions[i].RemoteSession = true;\r
+               StrCpy(t->Sessions[i].RemoteHostname, sizeof(t->Sessions[i].RemoteHostname),\r
+                       f->hostname);\r
+       }\r
+\r
+       FreePack(p);\r
+}\r
+\r
+// HUB 作成指令送信\r
+void SiCallCreateHub(SERVER *s, FARM_MEMBER *f, HUB *h)\r
+{\r
+       PACK *p;\r
+       HUB_LIST *hh;\r
+       // 引数チェック\r
+       if (s == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (f->Me == false)\r
+       {\r
+               p = NewPack();\r
+\r
+               SiPackAddCreateHub(p, h);\r
+\r
+               p = SiCallTask(f, p, "createhub");\r
+               FreePack(p);\r
+       }\r
+\r
+       hh = ZeroMalloc(sizeof(HUB_LIST));\r
+       hh->DynamicHub = (h->Type == HUB_TYPE_FARM_DYNAMIC ? true : false);\r
+       StrCpy(hh->Name, sizeof(hh->Name), h->Name);\r
+       hh->FarmMember = f;\r
+\r
+       LockList(f->HubList);\r
+       {\r
+               bool exists = false;\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(f->HubList);i++)\r
+               {\r
+                       HUB_LIST *t = LIST_DATA(f->HubList, i);\r
+                       if (StrCmpi(t->Name, hh->Name) == 0)\r
+                       {\r
+                               exists = true;\r
+                       }\r
+               }\r
+               if (exists == false)\r
+               {\r
+                       Add(f->HubList, hh);\r
+               }\r
+               else\r
+               {\r
+                       Free(hh);\r
+               }\r
+       }\r
+       UnlockList(f->HubList);\r
+}\r
+\r
+// HUB 作成用 PACK の書き込み\r
+void SiPackAddCreateHub(PACK *p, HUB *h)\r
+{\r
+       UINT i;\r
+       UINT max_session;\r
+       SERVER *s;\r
+       LICENSE_STATUS license;\r
+       // 引数チェック\r
+       if (p == NULL || h == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&license, sizeof(license));\r
+       s = h->Cedar->Server;\r
+       if (s != NULL)\r
+       {\r
+               LiParseCurrentLicenseStatus(s->LicenseSystem, &license);\r
+       }\r
+\r
+       PackAddStr(p, "HubName", h->Name);\r
+       PackAddInt(p, "HubType", h->Type);\r
+\r
+       max_session = h->Option->MaxSession;\r
+\r
+       if (GetHubAdminOption(h, "max_sessions") != 0)\r
+       {\r
+               if (max_session == 0)\r
+               {\r
+                       max_session = GetHubAdminOption(h, "max_sessions");\r
+               }\r
+               else\r
+               {\r
+                       max_session = MIN(max_session, GetHubAdminOption(h, "max_sessions"));\r
+               }\r
+       }\r
+\r
+       PackAddInt(p, "MaxSession", max_session);\r
+\r
+       if (GetHubAdminOption(h, "max_sessions_client_bridge_apply") != 0 || license.CarrierEdition)\r
+       {\r
+               PackAddInt(p, "MaxSessionClient", GetHubAdminOption(h, "max_sessions_client"));\r
+               PackAddInt(p, "MaxSessionBridge", GetHubAdminOption(h, "max_sessions_bridge"));\r
+               PackAddBool(p, "MaxSessionClientBridgeApply", true);\r
+       }\r
+       else\r
+       {\r
+               PackAddInt(p, "MaxSessionClient", INFINITE);\r
+               PackAddInt(p, "MaxSessionBridge", INFINITE);\r
+       }\r
+\r
+       PackAddBool(p, "NoArpPolling", h->Option->NoArpPolling);\r
+       PackAddBool(p, "NoIPv6AddrPolling", h->Option->NoIPv6AddrPolling);\r
+       PackAddBool(p, "NoIpTable", h->Option->NoIpTable);\r
+       PackAddBool(p, "NoEnum", h->Option->NoEnum);\r
+       PackAddBool(p, "FilterPPPoE", h->Option->FilterPPPoE);\r
+       PackAddBool(p, "YieldAfterStorePacket", h->Option->YieldAfterStorePacket);\r
+       PackAddBool(p, "NoSpinLockForPacketDelay", h->Option->NoSpinLockForPacketDelay);\r
+       PackAddInt(p, "BroadcastStormDetectionThreshold", h->Option->BroadcastStormDetectionThreshold);\r
+       PackAddInt(p, "ClientMinimumRequiredBuild", h->Option->ClientMinimumRequiredBuild);\r
+       PackAddBool(p, "FixForDLinkBPDU", h->Option->FixForDLinkBPDU);\r
+       PackAddBool(p, "NoLookBPDUBridgeId", h->Option->NoLookBPDUBridgeId);\r
+       PackAddBool(p, "NoManageVlanId", h->Option->NoManageVlanId);\r
+       PackAddInt(p, "VlanTypeId", h->Option->VlanTypeId);\r
+       PackAddBool(p, "FilterOSPF", h->Option->FilterOSPF);\r
+       PackAddBool(p, "FilterIPv4", h->Option->FilterIPv4);\r
+       PackAddBool(p, "FilterIPv6", h->Option->FilterIPv6);\r
+       PackAddBool(p, "FilterNonIP", h->Option->FilterNonIP);\r
+       PackAddBool(p, "NoIPv4PacketLog", h->Option->NoIPv4PacketLog);\r
+       PackAddBool(p, "NoIPv6PacketLog", h->Option->NoIPv6PacketLog);\r
+       PackAddBool(p, "FilterBPDU", h->Option->FilterBPDU);\r
+       PackAddBool(p, "NoIPv6DefaultRouterInRAWhenIPv6", h->Option->NoIPv6DefaultRouterInRAWhenIPv6);\r
+       PackAddBool(p, "NoMacAddressLog", h->Option->NoMacAddressLog);\r
+       PackAddBool(p, "ManageOnlyPrivateIP", h->Option->ManageOnlyPrivateIP);\r
+       PackAddBool(p, "ManageOnlyLocalUnicastIPv6", h->Option->ManageOnlyLocalUnicastIPv6);\r
+       PackAddBool(p, "DisableIPParsing", h->Option->DisableIPParsing);\r
+\r
+       PackAddInt(p, "SavePacketLog", h->LogSetting.SavePacketLog);\r
+       PackAddInt(p, "PacketLogSwitchType", h->LogSetting.PacketLogSwitchType);\r
+       for (i = 0;i < NUM_PACKET_LOG;i++)\r
+       {\r
+               PackAddIntEx(p, "PacketLogConfig", h->LogSetting.PacketLogConfig[i], i, NUM_PACKET_LOG);\r
+       }\r
+       PackAddInt(p, "SaveSecurityLog", h->LogSetting.SaveSecurityLog);\r
+       PackAddInt(p, "SecurityLogSwitchType", h->LogSetting.SecurityLogSwitchType);\r
+       PackAddData(p, "HashedPassword", h->HashedPassword, SHA1_SIZE);\r
+       PackAddData(p, "SecurePassword", h->SecurePassword, SHA1_SIZE);\r
+\r
+       SiAccessListToPack(p, h->AccessList);\r
+\r
+       if (h->EnableSecureNAT)\r
+       {\r
+               PackAddBool(p, "EnableSecureNAT", h->EnableSecureNAT);\r
+               OutVhOption(p, h->SecureNATOption);\r
+       }\r
+}\r
+\r
+// HUB の設定が更新された\r
+void SiHubUpdateProc(HUB *h)\r
+{\r
+       SERVER *s;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (h == NULL || h->Cedar->Server == NULL || h->Cedar->Server->ServerType != SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = h->Cedar->Server;\r
+\r
+       if (s->FarmMemberList == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (h->LastVersion != h->CurrentVersion || h->CurrentVersion == 0)\r
+       {\r
+               if (h->CurrentVersion == 0)\r
+               {\r
+                       h->CurrentVersion = 1;\r
+               }\r
+               h->LastVersion = h->CurrentVersion;\r
+\r
+               LockList(s->FarmMemberList);\r
+               {\r
+                       // すべてのメンバで HUB を更新する\r
+                       for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                       {\r
+                               FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                               if (f->Me == false)\r
+                               {\r
+                                       SiCallUpdateHub(s, f, h);\r
+                               }\r
+                       }\r
+               }\r
+               UnlockList(s->FarmMemberList);\r
+       }\r
+\r
+       if (h->Offline == false)\r
+       {\r
+               SiHubOnlineProc(h);\r
+       }\r
+}\r
+\r
+// HUB がオンラインになった\r
+void SiHubOnlineProc(HUB *h)\r
+{\r
+       SERVER *s;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (h == NULL || h->Cedar->Server == NULL || h->Cedar->Server->ServerType != SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               // ファームコントローラ以外では処理しない\r
+               return;\r
+       }\r
+\r
+       s = h->Cedar->Server;\r
+\r
+       if (s->FarmMemberList == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(s->FarmMemberList);\r
+       {\r
+               if (h->Type == HUB_TYPE_FARM_STATIC)\r
+               {\r
+                       // スタティック HUB\r
+                       // すべてのメンバで HUB を作成する\r
+                       for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                       {\r
+                               UINT j;\r
+                               bool exists = false;\r
+                               FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+\r
+                               LockList(f->HubList);\r
+                               {\r
+                                       for (j = 0;j < LIST_NUM(f->HubList);j++)\r
+                                       {\r
+                                               HUB_LIST *hh = LIST_DATA(f->HubList, j);\r
+                                               if (StrCmpi(hh->Name, h->Name) == 0)\r
+                                               {\r
+                                                       exists = true;\r
+                                               }\r
+                                       }\r
+                               }\r
+                               UnlockList(f->HubList);\r
+\r
+                               if (exists == false)\r
+                               {\r
+                                       SiCallCreateHub(s, f, h);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(s->FarmMemberList);\r
+}\r
+\r
+// HUB がオフラインになった\r
+void SiHubOfflineProc(HUB *h)\r
+{\r
+       SERVER *s;\r
+       char hubname[MAX_HUBNAME_LEN + 1];\r
+       UINT i;\r
+       // 引数チェック\r
+       if (h == NULL || h->Cedar->Server == NULL || h->Cedar->Server->ServerType != SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               // ファームコントローラ以外では処理しない\r
+               return;\r
+       }\r
+\r
+       s = h->Cedar->Server;\r
+\r
+       if (s->FarmMemberList == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(hubname, sizeof(hubname), h->Name);\r
+\r
+       LockList(s->FarmMemberList);\r
+       {\r
+               // すべてのメンバで HUB を停止する\r
+               for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+               {\r
+                       FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                       SiCallDeleteHub(s, f, h);\r
+               }\r
+       }\r
+       UnlockList(s->FarmMemberList);\r
+}\r
+\r
+// アクセスを PACK に変換する\r
+void SiAccessToPack(PACK *p, ACCESS *a, UINT i, UINT total)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PackAddUniStrEx(p, "Note", a->Note, i, total);\r
+       PackAddIntEx(p, "Active", a->Active, i, total);\r
+       PackAddIntEx(p, "Priority", a->Priority, i, total);\r
+       PackAddIntEx(p, "Discard", a->Discard, i, total);\r
+       if (a->IsIPv6)\r
+       {\r
+               PackAddIp32Ex(p, "SrcIpAddress", 0xFDFFFFDF, i, total);\r
+               PackAddIp32Ex(p, "SrcSubnetMask", 0xFFFFFFFF, i, total);\r
+               PackAddIp32Ex(p, "DestIpAddress", 0xFDFFFFDF, i, total);\r
+               PackAddIp32Ex(p, "DestSubnetMask", 0xFFFFFFFF, i, total);\r
+       }\r
+       else\r
+       {\r
+               PackAddIp32Ex(p, "SrcIpAddress", a->SrcIpAddress, i, total);\r
+               PackAddIp32Ex(p, "SrcSubnetMask", a->SrcSubnetMask, i, total);\r
+               PackAddIp32Ex(p, "DestIpAddress", a->DestIpAddress, i, total);\r
+               PackAddIp32Ex(p, "DestSubnetMask", a->DestSubnetMask, i, total);\r
+       }\r
+       PackAddIntEx(p, "Protocol", a->Protocol, i, total);\r
+       PackAddIntEx(p, "SrcPortStart", a->SrcPortStart, i, total);\r
+       PackAddIntEx(p, "SrcPortEnd", a->SrcPortEnd, i, total);\r
+       PackAddIntEx(p, "DestPortStart", a->DestPortStart, i, total);\r
+       PackAddIntEx(p, "DestPortEnd", a->DestPortEnd, i, total);\r
+       PackAddStrEx(p, "SrcUsername", a->SrcUsername, i, total);\r
+       PackAddStrEx(p, "DestUsername", a->DestUsername, i, total);\r
+       PackAddBoolEx(p, "CheckSrcMac", a->CheckSrcMac, i, total);\r
+       PackAddDataEx(p, "SrcMacAddress", a->SrcMacAddress, sizeof(a->SrcMacAddress), i, total);\r
+       PackAddDataEx(p, "SrcMacMask", a->SrcMacMask, sizeof(a->SrcMacMask), i, total);\r
+       PackAddBoolEx(p, "CheckDstMac", a->CheckDstMac, i, total);\r
+       PackAddDataEx(p, "DstMacAddress", a->DstMacAddress, sizeof(a->DstMacAddress), i, total);\r
+       PackAddDataEx(p, "DstMacMask", a->DstMacMask, sizeof(a->DstMacMask), i, total);\r
+       PackAddBoolEx(p, "CheckTcpState", a->CheckTcpState, i, total);\r
+       PackAddBoolEx(p, "Established", a->Established, i, total);\r
+       PackAddIntEx(p, "Delay", a->Delay, i, total);\r
+       PackAddIntEx(p, "Jitter", a->Jitter, i, total);\r
+       PackAddIntEx(p, "Loss", a->Loss, i, total);\r
+       PackAddBoolEx(p, "IsIPv6", a->IsIPv6, i, total);\r
+       if (a->IsIPv6)\r
+       {\r
+               PackAddIp6AddrEx(p, "SrcIpAddress6", &a->SrcIpAddress6, i, total);\r
+               PackAddIp6AddrEx(p, "SrcSubnetMask6", &a->SrcSubnetMask6, i, total);\r
+               PackAddIp6AddrEx(p, "DestIpAddress6", &a->DestIpAddress6, i, total);\r
+               PackAddIp6AddrEx(p, "DestSubnetMask6", &a->DestSubnetMask6, i, total);\r
+       }\r
+       else\r
+       {\r
+               IPV6_ADDR zero;\r
+\r
+               Zero(&zero, sizeof(zero));\r
+\r
+               PackAddIp6AddrEx(p, "SrcIpAddress6", &zero, i, total);\r
+               PackAddIp6AddrEx(p, "SrcSubnetMask6", &zero, i, total);\r
+               PackAddIp6AddrEx(p, "DestIpAddress6", &zero, i, total);\r
+               PackAddIp6AddrEx(p, "DestSubnetMask6", &zero, i, total);\r
+       }\r
+}\r
+\r
+// PACK に入っているアクセス個数を取得\r
+UINT SiNumAccessFromPack(PACK *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return PackGetIndexCount(p, "Active");\r
+}\r
+\r
+// PACK をアクセスに変換する\r
+ACCESS *SiPackToAccess(PACK *p, UINT i)\r
+{\r
+       ACCESS *a;\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       a = ZeroMalloc(sizeof(ACCESS));\r
+\r
+       PackGetUniStrEx(p, "Note", a->Note, sizeof(a->Note), i);\r
+       a->Active = PackGetIntEx(p, "Active", i);\r
+       a->Priority = PackGetIntEx(p, "Priority", i);\r
+       a->Discard = PackGetIntEx(p, "Discard", i);\r
+       a->SrcIpAddress = PackGetIp32Ex(p, "SrcIpAddress", i);\r
+       a->SrcSubnetMask = PackGetIp32Ex(p, "SrcSubnetMask", i);\r
+       a->DestIpAddress = PackGetIp32Ex(p, "DestIpAddress", i);\r
+       a->DestSubnetMask = PackGetIp32Ex(p, "DestSubnetMask", i);\r
+       a->Protocol = PackGetIntEx(p, "Protocol", i);\r
+       a->SrcPortStart = PackGetIntEx(p, "SrcPortStart", i);\r
+       a->SrcPortEnd = PackGetIntEx(p, "SrcPortEnd", i);\r
+       a->DestPortStart = PackGetIntEx(p, "DestPortStart", i);\r
+       a->DestPortEnd = PackGetIntEx(p, "DestPortEnd", i);\r
+       PackGetStrEx(p, "SrcUsername", a->SrcUsername, sizeof(a->SrcUsername), i);\r
+       PackGetStrEx(p, "DestUsername", a->DestUsername, sizeof(a->DestUsername), i);\r
+       a->CheckSrcMac = PackGetBoolEx(p, "CheckSrcMac", i);\r
+       PackGetDataEx2(p, "SrcMacAddress", a->SrcMacAddress, sizeof(a->SrcMacAddress), i);\r
+       PackGetDataEx2(p, "SrcMacMask", a->SrcMacMask, sizeof(a->SrcMacMask), i);\r
+       a->CheckDstMac = PackGetBoolEx(p, "CheckDstMac", i);\r
+       PackGetDataEx2(p, "DstMacAddress", a->DstMacAddress, sizeof(a->DstMacAddress), i);\r
+       PackGetDataEx2(p, "DstMacMask", a->DstMacMask, sizeof(a->DstMacMask), i);\r
+       a->CheckTcpState = PackGetBoolEx(p, "CheckTcpState", i);\r
+       a->Established = PackGetBoolEx(p, "Established", i);\r
+       a->Delay = PackGetIntEx(p, "Delay", i);\r
+       a->Jitter = PackGetIntEx(p, "Jitter", i);\r
+       a->Loss = PackGetIntEx(p, "Loss", i);\r
+       a->IsIPv6 = PackGetBoolEx(p, "IsIPv6", i);\r
+       if (a->IsIPv6)\r
+       {\r
+               PackGetIp6AddrEx(p, "SrcIpAddress6", &a->SrcIpAddress6, i);\r
+               PackGetIp6AddrEx(p, "SrcSubnetMask6", &a->SrcSubnetMask6, i);\r
+               PackGetIp6AddrEx(p, "DestIpAddress6", &a->DestIpAddress6, i);\r
+               PackGetIp6AddrEx(p, "DestSubnetMask6", &a->DestSubnetMask6, i);\r
+       }\r
+\r
+       return a;\r
+}\r
+\r
+// アクセスリストを PACK に変換する\r
+void SiAccessListToPack(PACK *p, LIST *o)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(o);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       ACCESS *a = LIST_DATA(o, i);\r
+                       SiAccessToPack(p, a, i, LIST_NUM(o));\r
+               }\r
+       }\r
+       UnlockList(o);\r
+}\r
+\r
+// 指定した HUB をホストしているメンバを取得する\r
+FARM_MEMBER *SiGetHubHostingMember(SERVER *s, HUB *h, bool admin_mode)\r
+{\r
+       FARM_MEMBER *ret = NULL;\r
+       char name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (s == NULL || h == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       StrCpy(name, sizeof(name), h->Name);\r
+\r
+       if (h->Type == HUB_TYPE_FARM_STATIC)\r
+       {\r
+               // スタティック HUB の場合 任意のメンバを選択すれば良い\r
+               if (admin_mode == false)\r
+               {\r
+                       ret = SiGetNextFarmMember(s);\r
+               }\r
+               else\r
+               {\r
+                       UINT i;\r
+                       ret = NULL;\r
+\r
+                       for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+                       {\r
+                               FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                               if (f->Me)\r
+                               {\r
+                                       ret = f;\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // ダイナミック HUB の場合\r
+               // すでに HUB をホストしているメンバがあるかどうか調べる\r
+               UINT i;\r
+\r
+               for (i = 0;i < LIST_NUM(s->FarmMemberList);i++)\r
+               {\r
+                       FARM_MEMBER *f = LIST_DATA(s->FarmMemberList, i);\r
+                       HUB_LIST *hh, t;\r
+                       StrCpy(t.Name, sizeof(t.Name), name);\r
+                       LockList(f->HubList);\r
+                       {\r
+                               hh = Search(f->HubList, &t);\r
+                               if (hh != NULL)\r
+                               {\r
+                                       // 発見した\r
+                                       ret = f;\r
+                               }\r
+                       }\r
+                       UnlockList(f->HubList);\r
+               }\r
+\r
+               if (ret == NULL)\r
+               {\r
+                       // 新しく HUB をホストさせる\r
+                       FARM_MEMBER *f;\r
+\r
+                       // ホストさせるメンバの選択\r
+                       ret = SiGetNextFarmMember(s);\r
+\r
+                       f = ret;\r
+                       if (f != NULL)\r
+                       {\r
+                               // HUB 作成指令\r
+                               SiAddHubCreateHistory(s, name);\r
+                               SiCallCreateHub(s, f, h);\r
+                               SiCallUpdateHub(s, f, h);\r
+                       }\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// タスクが呼び出された\r
+PACK *SiCalledTask(FARM_CONTROLLER *f, PACK *p, char *taskname)\r
+{\r
+       PACK *ret;\r
+       SERVER *s;\r
+       // 引数チェック\r
+       if (f == NULL || p == NULL || taskname == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = NULL;\r
+       s = f->Server;\r
+\r
+       if (StrCmpi(taskname, "noop") == 0)\r
+       {\r
+               // NO OPERATION\r
+               ret = NewPack();\r
+       }\r
+       else\r
+       {\r
+               Debug("Task Called: [%s].\n", taskname);\r
+               if (StrCmpi(taskname, "createhub") == 0)\r
+               {\r
+                       SiCalledCreateHub(s, p);\r
+                       ret = NewPack();\r
+               }\r
+               else if (StrCmpi(taskname, "deletehub") == 0)\r
+               {\r
+                       SiCalledDeleteHub(s, p);\r
+                       ret = NewPack();\r
+               }\r
+               else if (StrCmpi(taskname, "enumhub") == 0)\r
+               {\r
+                       ret = NewPack();\r
+                       SiCalledEnumHub(s, ret, p);\r
+               }\r
+               else if (StrCmpi(taskname, "updatehub") == 0)\r
+               {\r
+                       SiCalledUpdateHub(s, p);\r
+                       ret = NewPack();\r
+               }\r
+               else if (StrCmpi(taskname, "createticket") == 0)\r
+               {\r
+                       ret = SiCalledCreateTicket(s, p);\r
+               }\r
+               else if (StrCmpi(taskname, "enumnat") == 0)\r
+               {\r
+                       ret = SiCalledEnumNat(s, p);\r
+               }\r
+               else if (StrCmpi(taskname, "enumdhcp") == 0)\r
+               {\r
+                       ret = SiCalledEnumDhcp(s, p);\r
+               }\r
+               else if (StrCmpi(taskname, "getnatstatus") == 0)\r
+               {\r
+                       ret = SiCalledGetNatStatus(s, p);\r
+               }\r
+               else if (StrCmpi(taskname, "enumsession") == 0)\r
+               {\r
+                       ret = SiCalledEnumSession(s, p);\r
+               }\r
+               else if (StrCmpi(taskname, "deletesession") == 0)\r
+               {\r
+                       SiCalledDeleteSession(s, p);\r
+                       ret = NewPack();\r
+               }\r
+               else if (StrCmpi(taskname, "deletemactable") == 0)\r
+               {\r
+                       SiCalledDeleteMacTable(s, p);\r
+                       ret = NewPack();\r
+               }\r
+               else if (StrCmpi(taskname, "deleteiptable") == 0)\r
+               {\r
+                       SiCalledDeleteIpTable(s, p);\r
+                       ret = NewPack();\r
+               }\r
+               else if (StrCmpi(taskname, "enummactable") == 0)\r
+               {\r
+                       ret = SiCalledEnumMacTable(s, p);\r
+               }\r
+               else if (StrCmpi(taskname, "enumiptable") == 0)\r
+               {\r
+                       ret = SiCalledEnumIpTable(s, p);\r
+               }\r
+               else if (StrCmpi(taskname, "getsessionstatus") == 0)\r
+               {\r
+                       ret = SiCalledGetSessionStatus(s, p);\r
+               }\r
+               else if (StrCmpi(taskname, "enumlogfilelist") == 0)\r
+               {\r
+                       ret = SiCalledEnumLogFileList(s, p);\r
+               }\r
+               else if (StrCmpi(taskname, "readlogfile") == 0)\r
+               {\r
+                       ret = SiCalledReadLogFile(s, p);\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// タスクを呼び出す\r
+PACK *SiCallTask(FARM_MEMBER *f, PACK *p, char *taskname)\r
+{\r
+       PACK *ret;\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (f == NULL || p == NULL || taskname == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       PackAddStr(p, "taskname", taskname);\r
+\r
+       Debug("Call Task [%s] (%s)\n", taskname, f->hostname);\r
+\r
+       Format(tmp, sizeof(tmp), "CLUSTER_CALL: Entering Call [%s] to %s", taskname, f->hostname);\r
+       SiDebugLog(f->Cedar->Server, tmp);\r
+\r
+       ret = SiExecTask(f, p);\r
+\r
+       Format(tmp, sizeof(tmp), "CLUSTER_CALL: Leaving Call [%s] to %s", taskname, f->hostname);\r
+       SiDebugLog(f->Cedar->Server, tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// タスク待ちうけプロシージャ (メイン処理)\r
+void SiAcceptTasksFromControllerMain(FARM_CONTROLLER *f, SOCK *sock)\r
+{\r
+       PACK *request;\r
+       PACK *response;\r
+       char taskname[MAX_SIZE];\r
+       // 引数チェック\r
+       if (f == NULL || sock == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               bool ret;\r
+               // PACK を受信する\r
+               request = HttpClientRecv(sock);\r
+               if (request == NULL)\r
+               {\r
+                       // 切断\r
+                       return;\r
+               }\r
+\r
+               response = NULL;\r
+\r
+               // 名前の取得\r
+               if (PackGetStr(request, "taskname", taskname, sizeof(taskname)))\r
+               {\r
+                       Lock(f->Server->TasksFromFarmControllerLock);\r
+                       {\r
+                               response = SiCalledTask(f, request, taskname);\r
+                       }\r
+                       Unlock(f->Server->TasksFromFarmControllerLock);\r
+               }\r
+\r
+               FreePack(request);\r
+\r
+               // 応答を返す\r
+               if (response == NULL)\r
+               {\r
+                       response = NewPack();\r
+               }\r
+               else\r
+               {\r
+                       PackAddInt(response, "succeed", 1);\r
+               }\r
+\r
+               ret = HttpClientSend(sock, response);\r
+               FreePack(response);\r
+\r
+               if (ret == false)\r
+               {\r
+                       // 切断\r
+                       return;\r
+               }\r
+       }\r
+}\r
+\r
+// タスク待ちうけプロシージャ\r
+void SiAcceptTasksFromController(FARM_CONTROLLER *f, SOCK *sock)\r
+{\r
+       UINT i;\r
+       HUB **hubs;\r
+       UINT num_hubs;\r
+       CEDAR *c;\r
+       SERVER *s;\r
+       // 引数チェック\r
+       if (f == NULL || sock == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = f->Server;\r
+       c = s->Cedar;\r
+\r
+       // メイン処理\r
+       SiAcceptTasksFromControllerMain(f, sock);\r
+\r
+       // コントローラとの接続が切断されたためすべての仮想 HUB を停止する\r
+       LockList(c->HubList);\r
+       {\r
+               hubs = ToArray(c->HubList);\r
+               num_hubs = LIST_NUM(c->HubList);\r
+               for (i = 0;i < num_hubs;i++)\r
+               {\r
+                       AddRef(hubs[i]->ref);\r
+               }\r
+       }\r
+       UnlockList(c->HubList);\r
+\r
+       for (i = 0;i < num_hubs;i++)\r
+       {\r
+               SetHubOffline(hubs[i]);\r
+               DelHub(c, hubs[i]);\r
+               ReleaseHub(hubs[i]);\r
+       }\r
+\r
+       Free(hubs);\r
+}\r
+\r
+// タスクを実行する\r
+PACK *SiExecTask(FARM_MEMBER *f, PACK *p)\r
+{\r
+       FARM_TASK *t;\r
+       // 引数チェック\r
+       if (f == NULL || p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t = SiFarmServPostTask(f, p);\r
+       if (t == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return SiFarmServWaitTask(t);\r
+}\r
+\r
+// タスク投入\r
+FARM_TASK *SiFarmServPostTask(FARM_MEMBER *f, PACK *request)\r
+{\r
+       FARM_TASK *t;\r
+       // 引数チェック\r
+       if (f == NULL || request == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t = ZeroMalloc(sizeof(FARM_TASK));\r
+       t->CompleteEvent = NewEvent();\r
+       t->Request = request;\r
+\r
+       LockQueue(f->TaskQueue);\r
+       {\r
+               if (f->Halting)\r
+               {\r
+                       // 停止中 (失敗)\r
+                       UnlockQueue(f->TaskQueue);\r
+                       ReleaseEvent(t->CompleteEvent);\r
+                       Free(t);\r
+                       return NULL;\r
+               }\r
+\r
+               InsertQueue(f->TaskQueue, t);\r
+       }\r
+       UnlockQueue(f->TaskQueue);\r
+\r
+       Set(f->TaskPostEvent);\r
+\r
+       return t;\r
+}\r
+\r
+// タスク結果待ち\r
+PACK *SiFarmServWaitTask(FARM_TASK *t)\r
+{\r
+       PACK *response;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Wait(t->CompleteEvent, INFINITE);\r
+       ReleaseEvent(t->CompleteEvent);\r
+       FreePack(t->Request);\r
+\r
+       response = t->Response;\r
+       Free(t);\r
+\r
+       if (PackGetInt(response, "succeed") == 0)\r
+       {\r
+               // 何らかの原因でタスク呼び出しが失敗した\r
+               FreePack(response);\r
+               return NULL;\r
+       }\r
+\r
+       return response;\r
+}\r
+\r
+// ファームサーバー処理メイン\r
+void SiFarmServMain(SERVER *server, SOCK *sock, FARM_MEMBER *f)\r
+{\r
+       UINT wait_time = SERVER_CONTROL_TCP_TIMEOUT / 2;\r
+       bool send_noop = false;\r
+       UINT i;\r
+       CEDAR *c;\r
+       // 引数チェック\r
+       if (server == NULL || sock == NULL || f == NULL)\r
+       {\r
+               Debug("SiFarmServMain Failed.\n");\r
+               return;\r
+       }\r
+\r
+       Debug("SiFarmServMain Started.\n");\r
+\r
+       c = server->Cedar;\r
+\r
+       // メンバがコントローラに接続してきた段階で\r
+       // すべてのスタティック HUB の作成指令を送信する\r
+       LockList(c->HubList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(c->HubList);i++)\r
+               {\r
+                       HUB *h = LIST_DATA(c->HubList, i);\r
+                       if (h->Offline == false)\r
+                       {\r
+                               if (h->Type == HUB_TYPE_FARM_STATIC)\r
+                               {\r
+                                       PACK *p;\r
+                                       HUB_LIST *hh;\r
+                                       p = NewPack();\r
+                                       SiPackAddCreateHub(p, h);\r
+                                       PackAddStr(p, "taskname", "createhub");\r
+                                       HttpServerSend(sock, p);\r
+                                       FreePack(p);\r
+                                       p = HttpServerRecv(sock);\r
+                                       FreePack(p);\r
+\r
+                                       p = NewPack();\r
+                                       SiPackAddCreateHub(p, h);\r
+                                       PackAddStr(p, "taskname", "updatehub");\r
+                                       HttpServerSend(sock, p);\r
+                                       FreePack(p);\r
+                                       p = HttpServerRecv(sock);\r
+                                       FreePack(p);\r
+\r
+                                       hh = ZeroMalloc(sizeof(HUB_LIST));\r
+                                       hh->DynamicHub = false;\r
+                                       hh->FarmMember = f;\r
+                                       StrCpy(hh->Name, sizeof(hh->Name), h->Name);\r
+                                       LockList(f->HubList);\r
+                                       {\r
+                                               Add(f->HubList, hh);\r
+                                       }\r
+                                       UnlockList(f->HubList);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(c->HubList);\r
+\r
+       Debug("SiFarmServMain: while (true)\n");\r
+\r
+       while (true)\r
+       {\r
+               FARM_TASK *t;\r
+               UINT64 tick;\r
+\r
+               do\r
+               {\r
+                       // 新しいタスクが到着していないかどうか調べる\r
+                       LockQueue(f->TaskQueue);\r
+                       {\r
+                               t = GetNext(f->TaskQueue);\r
+                       }\r
+                       UnlockQueue(f->TaskQueue);\r
+\r
+                       if (t != NULL)\r
+                       {\r
+                               // このタスクを処理する\r
+                               PACK *p = t->Request;\r
+                               bool ret;\r
+\r
+                               // 送信\r
+                               ret = HttpServerSend(sock, p);\r
+                               send_noop = false;\r
+\r
+                               if (ret == false)\r
+                               {\r
+                                       // 接続が切れた\r
+                                       // このタスクをキャンセルする\r
+                                       Set(t->CompleteEvent);\r
+                                       goto DISCONNECTED;\r
+                               }\r
+\r
+                               // 受信\r
+                               p = HttpServerRecv(sock);\r
+\r
+                               t->Response = p;\r
+                               Set(t->CompleteEvent);\r
+\r
+                               send_noop = false;\r
+                       }\r
+               }\r
+               while (t != NULL);\r
+\r
+               if (send_noop)\r
+               {\r
+                       // NOOP を送信する\r
+                       PACK *p;\r
+                       bool ret;\r
+                       p = NewPack();\r
+                       PackAddStr(p, "taskname", "noop");\r
+\r
+                       ret = HttpServerSend(sock, p);\r
+                       FreePack(p);\r
+\r
+                       if (ret == false)\r
+                       {\r
+                               goto DISCONNECTED;\r
+                       }\r
+\r
+                       p = HttpServerRecv(sock);\r
+                       if (p == NULL)\r
+                       {\r
+                               goto DISCONNECTED;\r
+                       }\r
+\r
+                       FreePack(p);\r
+               }\r
+\r
+               tick = Tick64();\r
+\r
+               while (true)\r
+               {\r
+                       bool break_flag;\r
+                       if ((tick + wait_time) <= Tick64())\r
+                       {\r
+                               break;\r
+                       }\r
+\r
+                       Wait(f->TaskPostEvent, 250);\r
+\r
+                       break_flag = false;\r
+                       LockQueue(f->TaskQueue);\r
+                       {\r
+                               if (f->TaskQueue->num_item != 0)\r
+                               {\r
+                                       break_flag = true;\r
+                               }\r
+                       }\r
+                       UnlockQueue(f->TaskQueue);\r
+\r
+                       if (break_flag || f->Halting || server->Halt)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+               send_noop = true;\r
+       }\r
+\r
+DISCONNECTED:\r
+\r
+       Debug("SiFarmServMain: DISCONNECTED\n");\r
+\r
+       f->Halting = true;\r
+       // すべての未処理のタスクをキャンセルする\r
+       LockQueue(f->TaskQueue);\r
+       {\r
+               FARM_TASK *t;\r
+\r
+               while (t = GetNext(f->TaskQueue))\r
+               {\r
+                       Set(t->CompleteEvent);\r
+               }\r
+       }\r
+       UnlockQueue(f->TaskQueue);\r
+}\r
+\r
+// ファームメンバからの接続を処理するファームサーバー関数\r
+void SiFarmServ(SERVER *server, SOCK *sock, X *cert, UINT ip, UINT num_port, UINT *ports, char *hostname, UINT point, UINT weight, UINT max_sessions)\r
+{\r
+       PACK *p;\r
+       FARM_MEMBER *f;\r
+       UINT i;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (server == NULL || sock == NULL || cert == NULL || num_port == 0 || ports == NULL || hostname == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (weight == 0)\r
+       {\r
+               weight = FARM_DEFAULT_WEIGHT;\r
+       }\r
+\r
+       if (max_sessions == 0)\r
+       {\r
+               max_sessions = SERVER_MAX_SESSIONS;\r
+       }\r
+\r
+       if (ip == 0)\r
+       {\r
+               // 公開 IP アドレスが指定されていない場合はこのファームメンバサーバーの\r
+               // 接続元 IP アドレスを指定する\r
+               ip = IPToUINT(&sock->RemoteIP);\r
+       }\r
+\r
+       IPToStr32(tmp, sizeof(tmp), ip);\r
+       SLog(server->Cedar, "LS_FARM_SERV_START", tmp, hostname);\r
+\r
+       // 成功を知らせる\r
+       p = NewPack();\r
+       HttpServerSend(sock, p);\r
+       FreePack(p);\r
+\r
+       IPToStr32(tmp, sizeof(tmp), ip);\r
+       Debug("Farm Member %s Connected. IP: %s\n", hostname, tmp);\r
+\r
+       SetTimeout(sock, SERVER_CONTROL_TCP_TIMEOUT);\r
+\r
+       f = ZeroMalloc(sizeof(FARM_MEMBER));\r
+       f->Cedar = server->Cedar;\r
+       f->Ip = ip;\r
+       f->NumPort = num_port;\r
+       f->Ports = ports;\r
+       StrCpy(f->hostname, sizeof(f->hostname), hostname);\r
+       f->ServerCert = cert;\r
+       f->ConnectedTime = SystemTime64();\r
+       f->Weight = weight;\r
+       f->MaxSessions = max_sessions;\r
+\r
+       f->HubList = NewList(CompareHubList);\r
+       f->Point = point;\r
+\r
+       f->TaskQueue = NewQueue();\r
+       f->TaskPostEvent = NewEvent();\r
+\r
+       // リストに追加する\r
+       LockList(server->FarmMemberList);\r
+       {\r
+               Add(server->FarmMemberList, f);\r
+       }\r
+       UnlockList(server->FarmMemberList);\r
+\r
+       // メイン処理\r
+       SiFarmServMain(server, sock, f);\r
+\r
+       // リストから削除する\r
+       LockList(server->FarmMemberList);\r
+       {\r
+               Delete(server->FarmMemberList, f);\r
+       }\r
+       UnlockList(server->FarmMemberList);\r
+\r
+       ReleaseQueue(f->TaskQueue);\r
+       ReleaseEvent(f->TaskPostEvent);\r
+\r
+       for (i = 0;i < LIST_NUM(f->HubList);i++)\r
+       {\r
+               HUB_LIST *hh = LIST_DATA(f->HubList, i);\r
+               Free(hh);\r
+       }\r
+\r
+       ReleaseList(f->HubList);\r
+\r
+       Free(f);\r
+\r
+       SLog(server->Cedar, "LS_FARM_SERV_END", hostname);\r
+}\r
+\r
+// HUB リストの検索\r
+int CompareHubList(void *p1, void *p2)\r
+{\r
+       HUB_LIST *h1, *h2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       h1 = *(HUB_LIST **)p1;\r
+       h2 = *(HUB_LIST **)p2;\r
+       if (h1 == NULL || h2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return StrCmpi(h1->Name, h2->Name);\r
+}\r
+\r
+// コントローラへの接続スレッド\r
+void SiConnectToControllerThread(THREAD *thread, void *param)\r
+{\r
+       FARM_CONTROLLER *f;\r
+       SESSION *s;\r
+       CONNECTION *c;\r
+       SERVER *server;\r
+       bool first_failed;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       MsSetThreadPriorityRealtime();\r
+#endif // OS_WIN32\r
+\r
+       f = (FARM_CONTROLLER *)param;\r
+       f->Thread = thread;\r
+       AddRef(f->Thread->ref);\r
+       NoticeThreadInit(thread);\r
+\r
+       f->StartedTime = SystemTime64();\r
+\r
+       server = f->Server;\r
+\r
+       f->StartedTime = SystemTime64();\r
+\r
+       SLog(server->Cedar, "LS_FARM_CONNECT_1", server->ControllerName);\r
+\r
+       first_failed = true;\r
+\r
+       while (true)\r
+       {\r
+               // 接続を試行\r
+               CLIENT_OPTION o;\r
+\r
+               f->LastError = ERR_TRYING_TO_CONNECT;\r
+\r
+               Zero(&o, sizeof(CLIENT_OPTION));\r
+               StrCpy(o.Hostname, sizeof(o.Hostname), server->ControllerName);\r
+               o.Port = server->ControllerPort;\r
+               f->NumTry++;\r
+\r
+               Debug("Try to Connect %s (Controller).\n", server->ControllerName);\r
+\r
+               s = NewRpcSessionEx(server->Cedar, &o, NULL, CEDAR_SERVER_FARM_STR);\r
+\r
+               if (s != NULL)\r
+               {\r
+                       // 接続成功: 認証データを送信\r
+                       PACK *p = NewPack();\r
+                       UCHAR secure_password[SHA1_SIZE];\r
+                       BUF *b;\r
+\r
+                       c = s->Connection;\r
+\r
+                       Lock(f->lock);\r
+                       {\r
+                               f->Sock = c->FirstSock;\r
+                               AddRef(f->Sock->ref);\r
+                               SetTimeout(f->Sock, SERVER_CONTROL_TCP_TIMEOUT);\r
+                       }\r
+                       Unlock(f->lock);\r
+\r
+                       // メソッド\r
+                       PackAddStr(p, "method", "farm_connect");\r
+                       PackAddClientVersion(p, s->Connection);\r
+\r
+                       // パスワード\r
+                       SecurePassword(secure_password, server->MemberPassword, s->Connection->Random);\r
+                       PackAddData(p, "SecurePassword", secure_password, sizeof(secure_password));\r
+\r
+                       Lock(server->Cedar->lock);\r
+                       {\r
+                               b = XToBuf(server->Cedar->ServerX, false);\r
+                       }\r
+                       Unlock(server->Cedar->lock);\r
+\r
+                       if (b != NULL)\r
+                       {\r
+                               char tmp[MAX_SIZE];\r
+                               bool ret;\r
+                               UINT i;\r
+                               // サーバー証明書\r
+                               PackAddBuf(p, "ServerCert", b);\r
+                               FreeBuf(b);\r
+\r
+                               // 最大セッション数\r
+                               PackAddInt(p, "MaxSessions", GetServerCapsInt(server, "i_max_sessions"));\r
+\r
+                               // ポイント\r
+                               PackAddInt(p, "Point", SiGetPoint(server));\r
+                               PackAddInt(p, "Weight", server->Weight);\r
+\r
+                               // ホスト名\r
+                               GetMachineName(tmp, sizeof(tmp));\r
+                               PackAddStr(p, "HostName", tmp);\r
+\r
+                               // 公開 IP\r
+                               PackAddIp32(p, "PublicIp", server->PublicIp);\r
+\r
+                               // 公開ポート\r
+                               for (i = 0;i < server->NumPublicPort;i++)\r
+                               {\r
+                                       PackAddIntEx(p, "PublicPort", server->PublicPorts[i], i, server->NumPublicPort);\r
+                               }\r
+\r
+                               ret = HttpClientSend(c->FirstSock, p);\r
+\r
+                               if (ret)\r
+                               {\r
+                                       PACK *p;\r
+                                       UINT err = ERR_PROTOCOL_ERROR;\r
+\r
+                                       first_failed = true;\r
+                                       p = HttpClientRecv(c->FirstSock);\r
+                                       if (p != NULL && (err = GetErrorFromPack(p)) == 0)\r
+                                       {\r
+                                               // 接続成功\r
+                                               SLog(server->Cedar, "LS_FARM_START");\r
+                                               f->CurrentConnectedTime = SystemTime64();\r
+                                               if (f->FirstConnectedTime == 0)\r
+                                               {\r
+                                                       f->FirstConnectedTime = SystemTime64();\r
+                                               }\r
+                                               f->NumConnected++;\r
+                                               Debug("Connect Succeed.\n");\r
+                                               f->Online = true;\r
+\r
+                                               // メイン処理\r
+                                               SiAcceptTasksFromController(f, c->FirstSock);\r
+\r
+                                               f->Online = false;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // エラー\r
+                                               f->LastError = err;\r
+                                               SLog(server->Cedar, "LS_FARM_CONNECT_2", server->ControllerName,\r
+                                                       GetUniErrorStr(err), err);\r
+                                       }\r
+                                       FreePack(p);\r
+                               }\r
+                               else\r
+                               {\r
+                                       f->LastError = ERR_DISCONNECTED;\r
+\r
+                                       if (first_failed)\r
+                                       {\r
+                                               SLog(server->Cedar, "LS_FARM_CONNECT_3", server->ControllerName, RETRY_CONNECT_TO_CONTROLLER_INTERVAL / 1000);\r
+                                               first_failed = false;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       FreePack(p);\r
+\r
+                       // 接続切断\r
+                       Lock(f->lock);\r
+                       {\r
+                               if (f->Sock != NULL)\r
+                               {\r
+                                       ReleaseSock(f->Sock);\r
+                                       f->Sock = NULL;\r
+                               }\r
+                       }\r
+                       Unlock(f->lock);\r
+\r
+                       ReleaseSession(s);\r
+                       s = NULL;\r
+\r
+                       if (f->LastError == ERR_TRYING_TO_CONNECT)\r
+                       {\r
+                               f->LastError = ERR_DISCONNECTED;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // 接続失敗\r
+                       f->LastError = ERR_CONNECT_TO_FARM_CONTROLLER;\r
+\r
+                       if (first_failed)\r
+                       {\r
+                               SLog(server->Cedar, "LS_FARM_CONNECT_3", server->ControllerName, RETRY_CONNECT_TO_CONTROLLER_INTERVAL / 1000);\r
+                               first_failed = false;\r
+                       }\r
+               }\r
+\r
+               Debug("Controller Disconnected. ERROR = %S\n", _E(f->LastError));\r
+\r
+               f->NumFailed = f->NumTry - f->NumConnected;\r
+\r
+               // イベント待機\r
+               Wait(f->HaltEvent, RETRY_CONNECT_TO_CONTROLLER_INTERVAL);\r
+\r
+               if (f->Halt)\r
+               {\r
+                       // 停止フラグ\r
+                       break;\r
+               }\r
+       }\r
+\r
+       SLog(server->Cedar, "LS_FARM_DISCONNECT");\r
+}\r
+\r
+// コントローラへの接続を切断\r
+void SiStopConnectToController(FARM_CONTROLLER *f)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       f->Halt = true;\r
+\r
+       // 接続を停止\r
+       Lock(f->lock);\r
+       {\r
+               Disconnect(f->Sock);\r
+       }\r
+       Unlock(f->lock);\r
+\r
+       Set(f->HaltEvent);\r
+\r
+       // スレッド停止を待機\r
+       WaitThread(f->Thread, INFINITE);\r
+       ReleaseThread(f->Thread);\r
+\r
+       DeleteLock(f->lock);\r
+       ReleaseEvent(f->HaltEvent);\r
+\r
+       Free(f);\r
+}\r
+\r
+// コントローラへの接続の開始\r
+FARM_CONTROLLER *SiStartConnectToController(SERVER *s)\r
+{\r
+       FARM_CONTROLLER *f;\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       f = ZeroMalloc(sizeof(FARM_CONTROLLER));\r
+       f->Server = s;\r
+       f->LastError = ERR_TRYING_TO_CONNECT;\r
+       f->HaltEvent = NewEvent();\r
+       f->lock = NewLock();\r
+\r
+       t = NewThread(SiConnectToControllerThread, f);\r
+       WaitThreadInit(t);\r
+       ReleaseThread(t);\r
+\r
+       return f;\r
+}\r
+\r
+// サーバーの作成\r
+SERVER *SiNewServer(bool bridge)\r
+{\r
+       SERVER *s;\r
+\r
+       s = ZeroMalloc(sizeof(SERVER));\r
+\r
+       SiInitHubCreateHistory(s);\r
+\r
+       InitServerCapsCache(s);\r
+\r
+       Rand(s->MyRandomKey, sizeof(s->MyRandomKey));\r
+\r
+       s->lock = NewLock();\r
+       s->SaveCfgLock = NewLock();\r
+       s->ref = NewRef();\r
+       s->Cedar = NewCedar(NULL, NULL);\r
+       s->Cedar->Server = s;\r
+       s->Cedar->CheckExpires = true;\r
+       s->ServerListenerList = NewList(CompareServerListener);\r
+       s->StartTime = SystemTime64();\r
+       s->TasksFromFarmControllerLock = NewLock();\r
+\r
+       if (bridge)\r
+       {\r
+               SetCedarVpnBridge(s->Cedar);\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       if (IsHamMode() == false)\r
+       {\r
+               RegistWindowsFirewallAll();\r
+       }\r
+#endif\r
+\r
+       s->Keep = StartKeep();\r
+\r
+       // ログ関係\r
+       MakeDir(bridge == false ? SERVER_LOG_DIR_NAME : BRIDGE_LOG_DIR_NAME);\r
+       s->Logger = NewLog(bridge == false ? SERVER_LOG_DIR_NAME : BRIDGE_LOG_DIR_NAME, SERVER_LOG_PERFIX, LOG_SWITCH_DAY);\r
+\r
+       SLog(s->Cedar, "L_LINE");\r
+       SLog(s->Cedar, "LS_START_2", s->Cedar->ServerStr, s->Cedar->VerString);\r
+       SLog(s->Cedar, "LS_START_3", s->Cedar->BuildInfo);\r
+       SLog(s->Cedar, "LS_START_UTF8");\r
+       SLog(s->Cedar, "LS_START_1");\r
+\r
+       if (s->Cedar->Bridge == false)\r
+       {\r
+               s->LicenseSystem = LiNewLicenseSystem();\r
+       }\r
+\r
+       // コンフィグレーション初期化\r
+       SiInitConfiguration(s);\r
+\r
+       // 優先順位を上げる\r
+       if (s->NoHighPriorityProcess == false)\r
+       {\r
+               OSSetHighPriority();\r
+       }\r
+\r
+       if (s->ServerType == SERVER_TYPE_FARM_MEMBER)\r
+       {\r
+               // コントローラへの接続を開始する\r
+               s->FarmController = SiStartConnectToController(s);\r
+       }\r
+       else if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)\r
+       {\r
+               FARM_MEMBER *f;\r
+               // コントローラとしての動作を開始する\r
+               s->FarmMemberList = NewList(NULL);\r
+\r
+               f = ZeroMalloc(sizeof(FARM_MEMBER));\r
+               f->Cedar = s->Cedar;\r
+               GetMachineName(f->hostname, sizeof(f->hostname));\r
+               f->Me = true;\r
+               f->HubList = NewList(CompareHubList);\r
+               f->Weight = s->Weight;\r
+\r
+               s->Me = f;\r
+\r
+               Add(s->FarmMemberList, f);\r
+\r
+               SiStartFarmControl(s);\r
+\r
+               s->FarmControllerInited = true;\r
+       }\r
+\r
+       InitServerSnapshot(s);\r
+\r
+       SiInitDeadLockCheck(s);\r
+\r
+       return s;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Server.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Server.h
new file mode 100644 (file)
index 0000000..17b12bb
--- /dev/null
@@ -0,0 +1,580 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Server.h\r
+// Server.c のヘッダ\r
+\r
+#ifndef        SERVER_H\r
+#define        SERVER_H\r
+\r
+extern char *SERVER_CONFIG_FILE_NAME;\r
+#define        SERVER_DEFAULT_CIPHER_NAME              "RC4-MD5"\r
+#define        SERVER_DEFAULT_CERT_DAYS                (365 * 10)\r
+#define        SERVER_DEFAULT_HUB_NAME                 "DEFAULT"\r
+#define        SERVER_DEFAULT_BRIDGE_NAME              "BRIDGE"\r
+#define        SERVER_CONTROL_TCP_TIMEOUT              (60 * 1000)\r
+#define        SERVER_FARM_CONTROL_INTERVAL    (10 * 1000)\r
+\r
+#define        SERVER_FILE_SAVE_INTERVAL_DEFAULT       (5 * 60 * 1000)\r
+#define        SERVER_FILE_SAVE_INTERVAL_MIN           (5 * 1000)\r
+#define        SERVER_FILE_SAVE_INTERVAL_MAX           (3600 * 1000)\r
+\r
+#define        SERVER_LICENSE_VIOLATION_SPAN   (SERVER_FARM_CONTROL_INTERVAL * 2)\r
+\r
+\r
+#define SERVER_DEADLOCK_CHECK_SPAN             (2 * 60 * 1000)\r
+#define SERVER_DEADLOCK_CHECK_TIMEOUT  (3 * 60 * 1000)\r
+\r
+\r
+#define        RETRY_CONNECT_TO_CONTROLLER_INTERVAL    (1 * 1000)\r
+\r
+#define        MAX_PUBLIC_PORT_NUM                             128\r
+\r
+// 各ファームメンバによってホストされている仮想 HUB リスト\r
+struct HUB_LIST\r
+{\r
+       struct FARM_MEMBER *FarmMember;         // ファームメンバ\r
+       bool DynamicHub;                                        // ダイナミック HUB\r
+       char Name[MAX_HUBNAME_LEN + 1];         // HUB 名\r
+       UINT NumSessions;                                       // セッション数\r
+       UINT NumSessionsClient;                         // クライアントセッション数\r
+       UINT NumSessionsBridge;                         // ブリッジセッション数\r
+       UINT NumMacTables;                                      // MAC テーブル数\r
+       UINT NumIpTables;                                       // IP テーブル数\r
+};\r
+\r
+// タスク\r
+struct FARM_TASK\r
+{\r
+       EVENT *CompleteEvent;                           // 完了通知\r
+       PACK *Request;                                          // 要求\r
+       PACK *Response;                                         // 応答\r
+};\r
+\r
+// ファームメンバ\r
+struct FARM_MEMBER\r
+{\r
+       CEDAR *Cedar;                                           // Cedar\r
+       UINT64 ConnectedTime;                           // 接続日時\r
+       UINT Me;                                                        // 自分自身\r
+       UINT Ip;                                                        // IP アドレス\r
+       UINT NumPort;                                           // ポート番号数\r
+       UINT *Ports;                                            // ポート番号\r
+       char hostname[MAX_HOST_NAME_LEN + 1];   // ホスト名\r
+       X *ServerCert;                                          // サーバー証明書\r
+       LIST *HubList;                                          // 仮想 HUB リスト\r
+       QUEUE *TaskQueue;                                       // タスクキュー\r
+       EVENT *TaskPostEvent;                           // タスク投入イベント\r
+       UINT Point;                                                     // 点数\r
+       volatile bool Halting;                          // 停止中\r
+       UINT NumSessions;                                       // セッション数\r
+       UINT MaxSessions;                                       // 最大セッション数\r
+       UINT NumTcpConnections;                         // TCP コネクション数\r
+       TRAFFIC Traffic;                                        // トラフィック情報\r
+       UINT AssignedClientLicense;                     // 割り当て済みクライアントライセンス数\r
+       UINT AssignedBridgeLicense;                     // 割り当て済みブリッジライセンス数\r
+       UINT Weight;                                            // 性能基準比\r
+       UCHAR RandomKey[SHA1_SIZE];                     // 乱数キー (ライセンスチェック)\r
+       UINT64 SystemId;                                        // システム ID (ライセンスチェック)\r
+};\r
+\r
+// ファームコントローラへの接続\r
+struct FARM_CONTROLLER\r
+{\r
+       LOCK *lock;                                                     // ロック\r
+       struct SERVER *Server;                          // サーバー\r
+       THREAD *Thread;                                         // スレッド\r
+       SOCK *Sock;                                                     // ソケット\r
+       SESSION *Session;                                       // セッション\r
+       volatile bool Halt;                                     // 停止フラグ\r
+       EVENT *HaltEvent;                                       // 停止イベント\r
+       UINT LastError;                                         // 最終エラー\r
+       bool Online;                                            // オンライン フラグ\r
+       UINT64 StartedTime;                                     // 接続開始時刻\r
+       UINT64 CurrentConnectedTime;            // 今回の接続時刻\r
+       UINT64 FirstConnectedTime;                      // 最初の接続時刻\r
+       UINT NumConnected;                                      // 接続回数\r
+       UINT NumTry;                                            // 試行回数\r
+       UINT NumFailed;                                         // 接続失敗回数\r
+};\r
+\r
+// サーバーリスナー\r
+struct SERVER_LISTENER\r
+{\r
+       UINT Port;                                                      // ポート番号\r
+       bool Enabled;                                           // 有効フラグ\r
+       LISTENER *Listener;                                     // リスナーオブジェクト\r
+};\r
+\r
+// syslog 設定\r
+struct SYSLOG_SETTING\r
+{\r
+       UINT SaveType;                                                  // 保存種類\r
+       char Hostname[MAX_HOST_NAME_LEN + 1];   // ホスト名\r
+       UINT Port;                                                              // ポート番号\r
+};\r
+\r
+// サーバー オブジェクト\r
+struct SERVER\r
+{\r
+       UINT ServerType;                                        // サーバーの種類\r
+       UINT UpdatedServerType;                         // 更新されたサーバーの種類\r
+       LIST *ServerListenerList;                       // サーバーリスナーリスト\r
+       UCHAR HashedPassword[SHA1_SIZE];        // パスワード\r
+       char ControllerName[MAX_HOST_NAME_LEN + 1];             // コントローラ名\r
+       UINT ControllerPort;                            // コントローラポート\r
+       UINT Weight;                                            // 性能基準比\r
+       bool ControllerOnly;                            // コントローラ機能のみ\r
+       UCHAR MemberPassword[SHA1_SIZE];        // ファームメンバ用パスワード\r
+       UINT PublicIp;                                          // 公開 IP \r
+       UINT NumPublicPort;                                     // 公開ポート数\r
+       UINT *PublicPorts;                                      // 公開ポート配列\r
+       UINT64 StartTime;                                       // 起動時刻\r
+       UINT AutoSaveConfigSpan;                        // 自動保存間隔\r
+       UINT ConfigRevision;                            // 設定ファイルリビジョン\r
+       UCHAR MyRandomKey[SHA1_SIZE];           // 自分のランダムキー\r
+       bool FarmControllerInited;                      // ファームコントローラの初期化が完了した\r
+       bool DisableDeadLockCheck;                      // デッドロックチェックを無効化する\r
+       bool NoSendSignature;                           // クライアントにシグネチャを送信させない\r
+       bool SaveDebugLog;                                      // デバッグログを保存する\r
+       bool NoLinuxArpFilter;                          // Linux における arp_filter を設定しない\r
+       bool NoHighPriorityProcess;                     // プロセスの優先順位を上げない\r
+       bool NoDebugDump;                                       // デバッグダンプを出力しない\r
+\r
+       volatile bool Halt;                                     // 停止フラグ\r
+       LOCK *lock;                                                     // ロック\r
+       REF *ref;                                                       // 参照カウンタ\r
+       CEDAR *Cedar;                                           // Cedar\r
+       CFG_RW *CfgRw;                                          // 設定ファイル R/W\r
+       LOCK *SaveCfgLock;                                      // 設定保存ロック\r
+       EVENT *SaveHaltEvent;                           // 保存スレッド停止イベント\r
+       THREAD *SaveThread;                                     // 設定保存スレッド\r
+       FARM_CONTROLLER *FarmController;        // ファームコントローラ\r
+       LOCK *TasksFromFarmControllerLock;      // ファームコントローラからのタスクを処理中にかけるロック\r
+       LIST *FarmMemberList;                           // ファームメンバーリスト\r
+       FARM_MEMBER *Me;                                        // 自分自身のファームメンバ登録\r
+       THREAD *FarmControlThread;                      // ファームコントロールスレッド\r
+       EVENT *FarmControlThreadHaltEvent;      // ファームコントロールスレッド停止イベント\r
+       LIST *HubCreateHistoryList;                     // 仮想 HUB 作成履歴リスト\r
+\r
+       KEEP *Keep;                                                     // コネクション維持\r
+       LOG *Logger;                                            // サーバー ロガー\r
+       ERASER *Eraser;                                         // 自動ファイル削除器\r
+\r
+       UINT CurrentTotalNumSessionsOnFarm;     // サーバー ファーム全体での合計のセッション数\r
+       UINT CurrentAssignedClientLicense;      // 現在のクライアントライセンス割り当て数\r
+       UINT CurrentAssignedBridgeLicense;      // 現在のブリッジライセンス割り当て数\r
+       LICENSE_SYSTEM *LicenseSystem;          // ライセンスシステム\r
+\r
+       LOCK *CapsCacheLock;                            // Caps キャッシュ用ロック\r
+       CAPSLIST *CapsListCache;                        // Caps キャッシュ\r
+       UINT LicenseHash;                                       // ライセンスリストのハッシュ値\r
+\r
+       bool SnapshotInited;\r
+       EVENT *SnapshotHaltEvent;                       // スナップショット停止イベント\r
+       volatile bool HaltSnapshot;                     // スナップショット停止フラグ\r
+       THREAD *SnapshotThread;                         // スナップショットスレッド\r
+       LOG *SnapshotLogger;                            // スナップショットロガー\r
+       UINT64 LastSnapshotTime;                        // 最後にスナップショットを作成した時刻\r
+\r
+       THREAD *DeadLockCheckThread;            // デッドロックチェックスレッド\r
+       volatile bool HaltDeadLockThread;       // 停止フラグ\r
+       EVENT *DeadLockWaitEvent;                       // 待機イベント\r
+\r
+       TINY_LOG *DebugLog;                                     // デバッグログ\r
+};\r
+\r
+\r
+// セッションの列挙*\r
+struct RPC_ENUM_SESSION\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       UINT NumSession;                                                                // セッション数\r
+       struct RPC_ENUM_SESSION_ITEM *Sessions;                 // セッションリスト\r
+};\r
+\r
+// セッション状態*\r
+struct RPC_SESSION_STATUS\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];                              // HUB 名\r
+       char Name[MAX_SESSION_NAME_LEN + 1];                    // セッション名\r
+       char Username[MAX_USERNAME_LEN + 1];                    // ユーザー名\r
+       char RealUsername[MAX_USERNAME_LEN + 1];                // 本当のユーザー名\r
+       char GroupName[MAX_USERNAME_LEN + 1];                   // グループ名\r
+       bool LinkMode;                                                                  // リンクモード\r
+       RPC_CLIENT_GET_CONNECTION_STATUS Status;                // ステータス\r
+       UINT ClientIp;                                                                  // クライアント IP アドレス\r
+       UCHAR ClientIp6[16];                                                    // クライアント IPv6 アドレス\r
+       char ClientHostName[MAX_HOST_NAME_LEN + 1];             // クライアントホスト名\r
+       NODE_INFO NodeInfo;                                                             // ノード情報\r
+};\r
+\r
+\r
+// サーバーの種類\r
+#define        SERVER_TYPE_STANDALONE                  0               // スタンドアロン サーバー\r
+#define        SERVER_TYPE_FARM_CONTROLLER             1               // ファームコントローラ サーバー\r
+#define        SERVER_TYPE_FARM_MEMBER                 2               // ファームメンバ サーバー\r
+\r
+\r
+// Caps 関係\r
+struct CAPS\r
+{\r
+       char *Name;                                                     // 名前\r
+       UINT Value;                                                     // 値\r
+};\r
+struct CAPSLIST\r
+{\r
+       LIST *CapsList;                                         // Caps リスト\r
+};\r
+\r
+// ログファイル\r
+struct LOG_FILE\r
+{\r
+       char Path[MAX_PATH];                            // パス名\r
+       char ServerName[MAX_HOST_NAME_LEN + 1]; // サーバー名\r
+       UINT FileSize;                                          // ファイルサイズ\r
+       UINT64 UpdatedTime;                                     // 更新日時\r
+};\r
+\r
+// 仮想 HUB のスナップショット\r
+struct HUB_SNAPSHOT\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];\r
+       bool HubStatus;\r
+       UINT HubMaxSessionsClient;\r
+       UINT HubMaxSessionsBridge;\r
+};\r
+\r
+// Server のスナップショット\r
+struct SERVER_SNAPSHOT\r
+{\r
+       UINT64 DateTime;\r
+       IP ServerIp;\r
+       char ServerHostname[MAX_HOST_NAME_LEN + 1];\r
+       char ServerProduct[MAX_SIZE];\r
+       char ServerVersion[MAX_SIZE];\r
+       char ServerBuild[MAX_SIZE];\r
+       char ServerOs[MAX_SIZE];\r
+       UINT64 ServerLicenseId;\r
+       UINT64 ServerLicenseExpires;\r
+       UINT ServerType;\r
+       UINT64 ServerStartupDatetime;\r
+       UINT NumClusterNodes;\r
+       LIST *HubList;\r
+};\r
+\r
+// 仮想 HUB 作成履歴\r
+struct SERVER_HUB_CREATE_HISTORY\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];\r
+       UINT64 CreatedTime;\r
+};\r
+\r
+// 関数プロトタイプ宣言\r
+SERVER *SiNewServer(bool bridge);\r
+void SiReleaseServer(SERVER *s);\r
+void SiCleanupServer(SERVER *s);\r
+void StStartServer(bool bridge);\r
+void StStopServer();\r
+void SiInitConfiguration(SERVER *s);\r
+void SiFreeConfiguration(SERVER *s);\r
+UINT SiWriteConfigurationFile(SERVER *s);\r
+void SiLoadInitialConfiguration(SERVER *s);\r
+bool SiLoadConfigurationFile(SERVER *s);\r
+bool SiLoadConfigurationFileMain(SERVER *s, FOLDER *root);\r
+void SiInitDefaultServerCert(SERVER *s);\r
+void SiInitCipherName(SERVER *s);\r
+void SiGenerateDefualtCert(X **server_x, K **server_k);\r
+void SiInitListenerList(SERVER *s);\r
+void SiLockListenerList(SERVER *s);\r
+void SiUnlockListenerList(SERVER *s);\r
+bool SiAddListener(SERVER *s, UINT port, bool enabled);\r
+bool SiEnableListener(SERVER *s, UINT port);\r
+bool SiDisableListener(SERVER *s, UINT port);\r
+bool SiDeleteListener(SERVER *s, UINT port);\r
+SERVER_LISTENER *SiGetListener(SERVER *s, UINT port);\r
+int CompareServerListener(void *p1, void *p2);\r
+void SiStopAllListener(SERVER *s);\r
+void SiInitDefaultHubList(SERVER *s);\r
+void SiInitBridge(SERVER *s);\r
+void SiTest(SERVER *s);\r
+FOLDER *SiWriteConfigurationToCfg(SERVER *s);\r
+bool SiLoadConfigurationCfg(SERVER *s, FOLDER *root);\r
+void SiWriteLocalBridges(FOLDER *f, SERVER *s);\r
+void SiLoadLocalBridges(SERVER *s, FOLDER *f);\r
+void SiWriteLocalBridgeCfg(FOLDER *f, LOCALBRIDGE *br);\r
+void SiLoadLocalBridgeCfg(SERVER *s, FOLDER *f);\r
+void SiWriteListeners(FOLDER *f, SERVER *s);\r
+void SiLoadListeners(SERVER *s, FOLDER *f);\r
+void SiWriteListenerCfg(FOLDER *f, SERVER_LISTENER *r);\r
+void SiLoadListenerCfg(SERVER *s, FOLDER *f);\r
+void SiWriteServerCfg(FOLDER *f, SERVER *s);\r
+void SiLoadServerCfg(SERVER *s, FOLDER *f);\r
+void SiWriteTraffic(FOLDER *parent, char *name, TRAFFIC *t);\r
+void SiWriteTrafficInner(FOLDER *parent, char *name, TRAFFIC_ENTRY *e);\r
+void SiLoadTrafficInner(FOLDER *parent, char *name, TRAFFIC_ENTRY *e);\r
+void SiLoadTraffic(FOLDER *parent, char *name, TRAFFIC *t);\r
+void SiSaverThread(THREAD *thread, void *param);\r
+void SiLoadLicenseManager(SERVER *s, FOLDER *f);\r
+void SiWriteLicenseManager(FOLDER *f, SERVER *s);\r
+void SiLoadL3Switchs(SERVER *s, FOLDER *f);\r
+void SiLoadL3SwitchCfg(L3SW *sw, FOLDER *f);\r
+void SiWriteL3Switchs(FOLDER *f, SERVER *s);\r
+void SiWriteL3SwitchCfg(FOLDER *f, L3SW *sw);\r
+void SiWriteHubs(FOLDER *f, SERVER *s);\r
+void SiLoadHubs(SERVER *s, FOLDER *f);\r
+void SiWriteHubCfg(FOLDER *f, HUB *h);\r
+void SiLoadHubCfg(SERVER *s, FOLDER *f, char *name);\r
+void SiLoadHubLogCfg(HUB_LOG *g, FOLDER *f);\r
+void SiWriteHubOptionCfg(FOLDER *f, HUB_OPTION *o);\r
+void SiWriteHubLogCfg(FOLDER *f, HUB_LOG *g);\r
+void SiWriteHubLogCfgEx(FOLDER *f, HUB_LOG *g, bool el_mode);\r
+void SiLoadHubOptionCfg(FOLDER *f, HUB_OPTION *o);\r
+void SiWriteHubLinks(FOLDER *f, HUB *h);\r
+void SiLoadHubLinks(HUB *h, FOLDER *f);\r
+void SiWriteHubAdminOptions(FOLDER *f, HUB *h);\r
+void SiLoadHubAdminOptions(HUB *h, FOLDER *f);\r
+void SiWriteHubLinkCfg(FOLDER *f, LINK *k);\r
+void SiLoadHubLinkCfg(FOLDER *f, HUB *h);\r
+void SiWriteHubAccessLists(FOLDER *f, HUB *h);\r
+void SiLoadHubAccessLists(HUB *h, FOLDER *f);\r
+void SiWriteHubAccessCfg(FOLDER *f, ACCESS *a);\r
+void SiLoadHubAccessCfg(HUB *h, FOLDER *f);\r
+void SiWriteHubDb(FOLDER *f, HUBDB *db);\r
+void SiLoadHubDb(HUB *h, FOLDER *f);\r
+void SiWriteUserList(FOLDER *f, LIST *o);\r
+void SiLoadUserList(HUB *h, FOLDER *f);\r
+void SiWriteUserCfg(FOLDER *f, USER *u);\r
+void SiLoadUserCfg(HUB *h, FOLDER *f);\r
+void SiWriteGroupList(FOLDER *f, LIST *o);\r
+void SiLoadGroupList(HUB *h, FOLDER *f);\r
+void SiWriteGroupCfg(FOLDER *f, USERGROUP *g);\r
+void SiLoadGroupCfg(HUB *h, FOLDER *f);\r
+void SiWriteCertList(FOLDER *f, LIST *o);\r
+void SiLoadCertList(LIST *o, FOLDER *f);\r
+void SiWriteCrlList(FOLDER *f, LIST *o);\r
+void SiLoadCrlList(LIST *o, FOLDER *f);\r
+void SiWritePolicyCfg(FOLDER *f, POLICY *p, bool cascade_mode);\r
+void SiLoadPolicyCfg(POLICY *p, FOLDER *f);\r
+void SiLoadSecureNAT(HUB *h, FOLDER *f);\r
+void SiWriteSecureNAT(HUB *h, FOLDER *f);\r
+void SiRebootServerEx(bool bridge, bool reset_setting);\r
+void SiRebootServer(bool bridge);\r
+void SiRebootServerThread(THREAD *thread, void *param);\r
+void StInit();\r
+void StFree();\r
+SERVER *StGetServer();\r
+void SiSetServerType(SERVER *s, UINT type,\r
+                                        UINT ip, UINT num_port, UINT *ports,\r
+                                        char *controller_name, UINT controller_port, UCHAR *password, UINT weight, bool controller_only);\r
+FARM_CONTROLLER *SiStartConnectToController(SERVER *s);\r
+void SiStopConnectToController(FARM_CONTROLLER *f);\r
+void SiFarmServ(SERVER *server, SOCK *sock, X *cert, UINT ip, UINT num_port, UINT *ports, char *hostname, UINT point, UINT weight, UINT max_sessions);\r
+int CompareHubList(void *p1, void *p2);\r
+void SiFarmServMain(SERVER *server, SOCK *sock, FARM_MEMBER *f);\r
+FARM_TASK *SiFarmServPostTask(FARM_MEMBER *f, PACK *request);\r
+PACK *SiFarmServWaitTask(FARM_TASK *t);\r
+PACK *SiExecTask(FARM_MEMBER *f, PACK *p);\r
+PACK *SiCallTask(FARM_MEMBER *f, PACK *p, char *taskname);\r
+void SiAcceptTasksFromController(FARM_CONTROLLER *f, SOCK *sock);\r
+void SiAcceptTasksFromControllerMain(FARM_CONTROLLER *f, SOCK *sock);\r
+PACK *SiCalledTask(FARM_CONTROLLER *f, PACK *p, char *taskname);\r
+void SiHubOnlineProc(HUB *h);\r
+void SiHubOfflineProc(HUB *h);\r
+FARM_MEMBER *SiGetNextFarmMember(SERVER *s);\r
+void SiCallCreateHub(SERVER *s, FARM_MEMBER *f, HUB *h);\r
+void SiCallUpdateHub(SERVER *s, FARM_MEMBER *f, HUB *h);\r
+void SiCallDeleteHub(SERVER *s, FARM_MEMBER *f, HUB *h);\r
+void SiCallEnumSession(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_ENUM_SESSION *t);\r
+void SiCallEnumNat(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_ENUM_NAT *t);\r
+void SiCallEnumDhcp(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_ENUM_DHCP *t);\r
+void SiCallGetNatStatus(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_NAT_STATUS *t);\r
+void SiCallEnumMacTable(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_ENUM_MAC_TABLE *t);\r
+void SiCallEnumIpTable(SERVER *s, FARM_MEMBER *f, char *hubname, RPC_ENUM_IP_TABLE *t);\r
+void SiCallDeleteSession(SERVER *s, FARM_MEMBER *f, char *hubname, char *session_name);\r
+void SiCallCreateTicket(SERVER *s, FARM_MEMBER *f, char *hubname, char *username, char *realusername, POLICY *policy, UCHAR *ticket, UINT counter, char *groupname);\r
+void SiCallDeleteMacTable(SERVER *s, FARM_MEMBER *f, char *hubname, UINT key);\r
+void SiCallDeleteIpTable(SERVER *s, FARM_MEMBER *f, char *hubname, UINT key);\r
+void SiCalledCreateHub(SERVER *s, PACK *p);\r
+void SiCalledUpdateHub(SERVER *s, PACK *p);\r
+void SiCalledDeleteHub(SERVER *s, PACK *p);\r
+void SiCalledDeleteSession(SERVER *s, PACK *p);\r
+void SiCalledDeleteMacTable(SERVER *s, PACK *p);\r
+void SiCalledDeleteIpTable(SERVER *s, PACK *p);\r
+PACK *SiCalledCreateTicket(SERVER *s, PACK *p);\r
+PACK *SiCalledEnumSession(SERVER *s, PACK *p);\r
+PACK *SiCalledEnumNat(SERVER *s, PACK *p);\r
+PACK *SiCalledEnumDhcp(SERVER *s, PACK *p);\r
+PACK *SiCalledGetNatStatus(SERVER *s, PACK *p);\r
+PACK *SiCalledEnumMacTable(SERVER *s, PACK *p);\r
+PACK *SiCalledEnumIpTable(SERVER *s, PACK *p);\r
+void SiCalledEnumHub(SERVER *s, PACK *p, PACK *req);\r
+void SiPackAddCreateHub(PACK *p, HUB *h);\r
+FARM_MEMBER *SiGetHubHostingMember(SERVER *s, HUB *h, bool admin_mode);\r
+void SiCallEnumHub(SERVER *s, FARM_MEMBER *f);\r
+void SiStartFarmControl(SERVER *s);\r
+void SiStopFarmControl(SERVER *s);\r
+void SiFarmControlThread(THREAD *thread, void *param);\r
+void SiAccessListToPack(PACK *p, LIST *o);\r
+void SiAccessToPack(PACK *p, ACCESS *a, UINT i, UINT total);\r
+ACCESS *SiPackToAccess(PACK *p, UINT i);\r
+UINT SiNumAccessFromPack(PACK *p);\r
+void SiHubUpdateProc(HUB *h);\r
+bool SiCheckTicket(HUB *h, UCHAR *ticket, char *username, UINT username_size, char *usernamereal, UINT usernamereal_size, POLICY *policy, char *sessionname, UINT sessionname_size, char *groupname, UINT groupname_size);\r
+UINT SiGetPoint(SERVER *s);\r
+UINT SiCalcPoint(SERVER *s, UINT num, UINT weight);\r
+bool SiCallGetSessionStatus(SERVER *s, FARM_MEMBER *f, RPC_SESSION_STATUS *t);\r
+PACK *SiCalledGetSessionStatus(SERVER *s, PACK *p);\r
+bool SiCallEnumLogFileList(SERVER *s, FARM_MEMBER *f, RPC_ENUM_LOG_FILE *t, char *hubname);\r
+PACK *SiCalledEnumLogFileList(SERVER *s, PACK *p);\r
+bool SiCallReadLogFile(SERVER *s, FARM_MEMBER *f, RPC_READ_LOG_FILE *t);\r
+PACK *SiCalledReadLogFile(SERVER *s, PACK *p);\r
+int CmpLogFile(void *p1, void *p2);\r
+LIST *EnumLogFile(char *hubname);\r
+void EnumLogFileDir(LIST *o, char *dirname);\r
+void FreeEnumLogFile(LIST *o);\r
+bool CheckLogFileNameFromEnumList(LIST *o, char *name, char *server_name);\r
+void AdjoinEnumLogFile(LIST *o, LIST *src);\r
+void IncrementServerConfigRevision(SERVER *s);\r
+void GetServerProductName(SERVER *s, char *name, UINT size);\r
+void GetServerProductNameInternal(SERVER *s, char *name, UINT size);\r
+void SiGetServerLicenseStatus(SERVER *s, LICENSE_STATUS *st);\r
+void SiInitDeadLockCheck(SERVER *s);\r
+void SiFreeDeadLockCheck(SERVER *s);\r
+void SiDeadLockCheckThread(THREAD *t, void *param);\r
+void SiCheckDeadLockMain(SERVER *s, UINT timeout);\r
+void SiDebugLog(SERVER *s, char *msg);\r
+UINT SiDebug(SERVER *s, RPC_TEST *ret, UINT i, char *str);\r
+UINT SiDebugProcHelloWorld(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size);\r
+UINT SiDebugProcExit(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size);\r
+UINT SiDebugProcDump(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size);\r
+UINT SiDebugProcRestorePriority(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size);\r
+UINT SiDebugProcSetHighPriority(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size);\r
+UINT SiDebugProcGetExeFileName(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size);\r
+UINT SiDebugProcCrash(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size);\r
+\r
+typedef UINT (SI_DEBUG_PROC)(SERVER *s, char *in_str, char *ret_str, UINT ret_str_size);\r
+\r
+CAPS *NewCaps(char *name, UINT value);\r
+void FreeCaps(CAPS *c);\r
+CAPSLIST *NewCapsList();\r
+int CompareCaps(void *p1, void *p2);\r
+void AddCaps(CAPSLIST *caps, CAPS *c);\r
+CAPS *GetCaps(CAPSLIST *caps, char *name);\r
+void FreeCapsList(CAPSLIST *caps);\r
+bool GetCapsBool(CAPSLIST *caps, char *name);\r
+UINT GetCapsInt(CAPSLIST *caps, char *name);\r
+void AddCapsBool(CAPSLIST *caps, char *name, bool b);\r
+void AddCapsInt(CAPSLIST *caps, char *name, UINT i);\r
+void InRpcCapsList(CAPSLIST *t, PACK *p);\r
+void OutRpcCapsList(PACK *p, CAPSLIST *t);\r
+void FreeRpcCapsList(CAPSLIST *t);\r
+void InitCapsList(CAPSLIST *t);\r
+void InRpcSysLogSetting(SYSLOG_SETTING *t, PACK *p);\r
+void OutRpcSysLogSetting(PACK *p, SYSLOG_SETTING *t);\r
+\r
+void GetServerCaps(SERVER *s, CAPSLIST *t);\r
+bool GetServerCapsBool(SERVER *s, char *name);\r
+UINT GetServerCapsInt(SERVER *s, char *name);\r
+void GetServerCapsMain(SERVER *s, CAPSLIST *t);\r
+void InitServerCapsCache(SERVER *s);\r
+void FreeServerCapsCache(SERVER *s);\r
+void DestroyServerCapsCache(SERVER *s);\r
+\r
+bool MakeServerSnapshot(SERVER *s, UINT64 now, SERVER_SNAPSHOT *t);\r
+void FreeSnapshot(SERVER_SNAPSHOT *t);\r
+void InitServerSnapshot(SERVER *s);\r
+void FreeServerSnapshot(SERVER *s);\r
+void ServerSnapshotThread(THREAD *t, void *param);\r
+void WriteServerSnapshotLog(SERVER *s, SERVER_SNAPSHOT *t);\r
+BUF *ServerSnapshotToBuf(SERVER_SNAPSHOT *t);\r
+bool IsAdminPackSupportedServerProduct(char *name);\r
+\r
+void SiInitHubCreateHistory(SERVER *s);\r
+void SiFreeHubCreateHistory(SERVER *s);\r
+void SiDeleteOldHubCreateHistory(SERVER *s);\r
+void SiAddHubCreateHistory(SERVER *s, char *name);\r
+void SiDelHubCreateHistory(SERVER *s, char *name);\r
+bool SiIsHubRegistedOnCreateHistory(SERVER *s, char *name);\r
+\r
+UINT SiGetServerNumUserObjects(SERVER *s);\r
+bool SiTooManyUserObjectsInServer(SERVER *s, bool oneMore);\r
+\r
+#endif // SERVER_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Session.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Session.c
new file mode 100644 (file)
index 0000000..b2b27bb
--- /dev/null
@@ -0,0 +1,2103 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Session.c\r
+// セッションマネージャ\r
+\r
+#include "CedarPch.h"\r
+\r
+// セッションのメインルーチン\r
+void SessionMain(SESSION *s)\r
+{\r
+       CONNECTION *c;\r
+       POLICY *policy;\r
+       UINT64 now;\r
+       UINT i = 0;\r
+       PACKET_ADAPTER *pa;\r
+       bool pa_inited = false;\r
+       UINT packet_size;\r
+       void *packet;\r
+       bool packet_put;\r
+       bool pa_fail = false;\r
+       UINT test = 0;\r
+       bool update_hub_last_comm = false;\r
+       UINT err = ERR_SESSION_TIMEOUT;\r
+       UINT64 next_update_hub_last_comm = 0;\r
+       UINT64 auto_disconnect_tick = 0;\r
+       TRAFFIC t;\r
+       SOCK *msgdlg_sock = NULL;\r
+       SOCK *nicinfo_sock = NULL;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+       Debug("SessionMain: %s\n", s->Name);\r
+\r
+       Notify(s, CLIENT_NOTIFY_ACCOUNT_CHANGED);\r
+\r
+       // リトライ回数のリセット\r
+       s->CurrentRetryCount = 0;\r
+       s->ConnectSucceed = true;\r
+       s->SessionTimeOuted = false;\r
+\r
+       c = s->Connection;\r
+       policy = s->Policy;\r
+\r
+       // パケットアダプタの初期化\r
+       pa = s->PacketAdapter;\r
+       if (pa->Init(s) == false)\r
+       {\r
+               // 初期化失敗\r
+               if (s->VLanDeviceErrorCount >= 2)\r
+               {\r
+                       s->ForceStopFlag = true;\r
+               }\r
+               else\r
+               {\r
+                       s->VLanDeviceErrorCount++;\r
+               }\r
+               err = ERR_DEVICE_DRIVER_ERROR;\r
+               goto CLEANUP;\r
+       }\r
+       pa_inited = true;\r
+\r
+       if (s->BridgeMode == false)\r
+       {\r
+               s->Cancel2 = pa->GetCancel(s);\r
+       }\r
+       else\r
+       {\r
+               CANCEL *c = pa->GetCancel(s);\r
+               CANCEL *old = s->Cancel1;\r
+               s->Cancel1 = c;\r
+               ReleaseCancel(old);\r
+       }\r
+\r
+       s->RetryFlag = false;\r
+\r
+       s->LastCommTime = Tick64();\r
+       if (s->ServerMode == false)\r
+       {\r
+               s->NextConnectionTime = Tick64() + (UINT64)(s->ClientOption->AdditionalConnectionInterval * 1000);\r
+       }\r
+\r
+       s->NumConnectionsEatablished++;\r
+       s->CurrentConnectionEstablishTime = Tick64();\r
+       if (s->FirstConnectionEstablisiedTime == 0)\r
+       {\r
+               s->FirstConnectionEstablisiedTime = Tick64();\r
+       }\r
+\r
+       if (s->ServerMode == false && s->Cedar->Client != NULL)\r
+       {\r
+               if (s->Policy != NULL)\r
+               {\r
+                       if (s->Policy->AutoDisconnect)\r
+                       {\r
+                               auto_disconnect_tick = s->CurrentConnectionEstablishTime +\r
+                                       (UINT64)s->Policy->AutoDisconnect * 1000ULL;\r
+                       }\r
+               }\r
+       }\r
+\r
+       s->LastIncrementTraffic = Tick64();\r
+\r
+       c->Err = ERR_SESSION_TIMEOUT;\r
+       s->VLanDeviceErrorCount = 0;\r
+\r
+       s->LastTryAddConnectTime = Tick64();\r
+\r
+       Notify(s, CLIENT_NOTIFY_ACCOUNT_CHANGED);\r
+\r
+       if (policy != NULL)\r
+       {\r
+               // ポリシーの内容を見てモードを決定する\r
+               if (policy->MonitorPort)\r
+               {\r
+                       s->IsMonitorMode = true;\r
+               }\r
+\r
+               if (policy->NoRouting == false || policy->NoBridge == false)\r
+               {\r
+                       s->IsBridgeMode = true;\r
+               }\r
+       }\r
+\r
+       if (s->ServerMode == false && s->Cedar->Client != NULL)\r
+       {\r
+               if (IsEmptyUniStr(s->Client_Message) == false)\r
+               {\r
+                       UI_MSG_DLG dlg;\r
+\r
+                       Zero(&dlg, sizeof(dlg));\r
+                       if (s->ClientOption != NULL)\r
+                       {\r
+                               StrCpy(dlg.HubName, sizeof(dlg.HubName), s->ClientOption->HubName);\r
+                               StrCpy(dlg.ServerName, sizeof(dlg.ServerName), s->ClientOption->Hostname);\r
+                       }\r
+\r
+                       dlg.Msg = s->Client_Message;\r
+\r
+                       msgdlg_sock = CncMsgDlg(&dlg);\r
+               }\r
+\r
+               if (s->Win32HideNicInfoWindow == false)\r
+               {\r
+                       UI_NICINFO info;\r
+\r
+                       Zero(&info, sizeof(info));\r
+                       if (s->ClientOption != NULL)\r
+                       {\r
+                               StrCpy(info.NicName, sizeof(info.NicName), s->ClientOption->DeviceName);\r
+                               UniStrCpy(info.AccountName, sizeof(info.AccountName), s->ClientOption->AccountName);\r
+                       }\r
+\r
+                       nicinfo_sock = CncNicInfo(&info);\r
+               }\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               Zero(&t, sizeof(t));\r
+\r
+               if (next_update_hub_last_comm == 0 ||\r
+                       (next_update_hub_last_comm <= Tick64()))\r
+               {\r
+                       next_update_hub_last_comm = Tick64() + 1000;\r
+\r
+                       if (s->Hub != NULL)\r
+                       {\r
+                               if (update_hub_last_comm)\r
+                               {\r
+                                       Lock(s->Hub->lock);\r
+                                       {\r
+                                               s->Hub->LastCommTime = SystemTime64();\r
+                                       }\r
+                                       Unlock(s->Hub->lock);\r
+\r
+                                       update_hub_last_comm = false;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // 追加接続のチャンス\r
+               ClientAdditionalConnectChance(s);\r
+\r
+               // ブロックを受信\r
+               ConnectionReceive(c, s->Cancel1, s->Cancel2);\r
+\r
+               // 受信したブロックを PacketAdapter に渡す\r
+               LockQueue(c->ReceivedBlocks);\r
+               {\r
+                       BLOCK *b;\r
+                       packet_put = false;\r
+                       while (true)\r
+                       {\r
+                               b = GetNext(c->ReceivedBlocks);\r
+                               if (b == NULL)\r
+                               {\r
+                                       break;\r
+                               }\r
+\r
+                               PROBE_DATA2("GetNext", b->Buf, b->Size);\r
+\r
+                               update_hub_last_comm = true;\r
+\r
+                               if (s->ServerMode == false && b->Size >= 14)\r
+                               {\r
+                                       if (b->Buf[0] & 0x40)\r
+                                       {\r
+                                               t.Recv.BroadcastCount++;\r
+                                               t.Recv.BroadcastBytes += (UINT64)b->Size;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               t.Recv.UnicastCount++;\r
+                                               t.Recv.UnicastBytes += (UINT64)b->Size;\r
+                                       }\r
+                               }\r
+\r
+                               packet_put = true;\r
+                               PROBE_DATA2("pa->PutPacket", b->Buf, b->Size);\r
+                               if (pa->PutPacket(s, b->Buf, b->Size) == false)\r
+                               {\r
+                                       pa_fail = true;\r
+                                       err = ERR_DEVICE_DRIVER_ERROR;\r
+                                       Free(b->Buf);\r
+                                       Debug("  Error: pa->PutPacket(Packet) Failed.\n");\r
+                               }\r
+                               Free(b);\r
+                       }\r
+\r
+                       if (packet_put || s->ServerMode)\r
+                       {\r
+                               PROBE_DATA2("pa->PutPacket", NULL, 0);\r
+                               if (pa->PutPacket(s, NULL, 0) == false)\r
+                               {\r
+                                       Debug("  Error: pa->PutPacket(NULL) Failed.\n");\r
+                                       pa_fail = true;\r
+                                       err = ERR_DEVICE_DRIVER_ERROR;\r
+                               }\r
+                       }\r
+               }\r
+               UnlockQueue(c->ReceivedBlocks);\r
+\r
+               // 送信するべきパケットを PacketAdapter から取得して SendBlocks に追加\r
+               LockQueue(c->SendBlocks);\r
+               {\r
+                       UINT i, max_num = MAX_SEND_SOCKET_QUEUE_NUM;\r
+                       i = 0;\r
+                       while (packet_size = pa->GetNextPacket(s, &packet))\r
+                       {\r
+                               BLOCK *b;\r
+                               if (packet_size == INFINITE)\r
+                               {\r
+                                       err = ERR_DEVICE_DRIVER_ERROR;\r
+                                       pa_fail = true;\r
+                                       Debug("  Error: pa->GetNextPacket() Failed.\n");\r
+                                       break;\r
+                               }\r
+\r
+                               update_hub_last_comm = true;\r
+\r
+                               if ((c->CurrentSendQueueSize > MAX_BUFFERING_PACKET_SIZE))\r
+                               {\r
+//                                     WHERE;\r
+                                       // バッファリングサイズ制限値を超過しているので破棄\r
+                                       Free(packet);\r
+                               }\r
+                               else\r
+                               {\r
+                                       bool priority;\r
+                                       // バッファリングする\r
+                                       if (s->ServerMode == false && packet_size >= 14)\r
+                                       {\r
+                                               UCHAR *buf = (UCHAR *)packet;\r
+                                               if (buf[0] & 0x01)\r
+                                               {\r
+                                                       t.Send.BroadcastCount++;\r
+                                                       t.Send.BroadcastBytes += (UINT64)packet_size;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       t.Send.UnicastCount++;\r
+                                                       t.Send.UnicastBytes += (UINT64)packet_size;\r
+                                               }\r
+                                       }\r
+                                       priority = IsPriorityHighestPacketForQoS(packet, packet_size);\r
+                                       b = NewBlock(packet, packet_size, s->UseCompress ? 1 : 0);\r
+                                       b->PriorityQoS = priority;\r
+                                       c->CurrentSendQueueSize += b->Size;\r
+\r
+                                       if (b->PriorityQoS && c->Protocol == CONNECTION_TCP && s->QoS)\r
+                                       {\r
+                                               InsertQueue(c->SendBlocks2, b);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               InsertQueue(c->SendBlocks, b);\r
+                                       }\r
+                               }\r
+                               i++;\r
+                               if (i >= max_num)\r
+                               {\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+               UnlockQueue(c->SendBlocks);\r
+\r
+               AddTrafficForSession(s, &t);\r
+\r
+               // ブロックを送信\r
+               ConnectionSend(c);\r
+\r
+               // 自動切断判定\r
+               if (auto_disconnect_tick != 0 && auto_disconnect_tick <= Tick64())\r
+               {\r
+                       err = ERR_AUTO_DISCONNECTED;\r
+                       s->CurrentRetryCount = INFINITE;\r
+                       break;\r
+               }\r
+\r
+               // 停止判定\r
+               if (s->Halt)\r
+               {\r
+                       if (s->ForceStopFlag)\r
+                       {\r
+                               err = ERR_USER_CANCEL;\r
+                       }\r
+                       break;\r
+               }\r
+\r
+               // 現在時刻を取得\r
+               now = Tick64();\r
+\r
+               if (s->ServerMode)\r
+               {\r
+                       HUB *hub;\r
+\r
+                       // ユーザーのトラフィックデータの更新\r
+                       if ((s->LastIncrementTraffic + INCREMENT_TRAFFIC_INTERVAL) <= now)\r
+                       {\r
+                               IncrementUserTraffic(s->Hub, s->UserNameReal, s);\r
+                               s->LastIncrementTraffic = now;\r
+                       }\r
+\r
+                       hub = s->Hub;\r
+\r
+                       if (hub != NULL)\r
+                       {\r
+                               Lock(hub->lock);\r
+                               {\r
+                                       if ((hub->LastIncrementTraffic + INCREMENT_TRAFFIC_INTERVAL) <= now)\r
+                                       {\r
+                                               IncrementHubTraffic(s->Hub);\r
+                                               hub->LastIncrementTraffic = now;\r
+                                       }\r
+                               }\r
+                               Unlock(hub->lock);\r
+                       }\r
+               }\r
+\r
+               // リンクモードサーバーセッションの場合はタイムアウトしない\r
+               // それ以外のセッションの場合はタイムアウトを判定する\r
+               if (s->LinkModeServer == false && s->SecureNATMode == false && s->BridgeMode == false && s->L3SwitchMode == false)\r
+               {\r
+                       bool timeouted = false;\r
+\r
+                       if ((now > s->LastCommTime) && ((now - s->LastCommTime) >= ((UINT64)s->Timeout)))\r
+                       {\r
+                               // 一定時間通信ができていない場合\r
+                               timeouted = true;\r
+                       }\r
+\r
+                       if (s->ServerMode == false && s->ClientOption != NULL && s->ClientOption->ConnectionDisconnectSpan == 0)\r
+                       {\r
+                               if (LIST_NUM(s->Connection->Tcp->TcpSockList) < s->MaxConnection)\r
+                               {\r
+                                       if ((s->LastTryAddConnectTime +\r
+                                               (UINT64)(s->ClientOption->AdditionalConnectionInterval * 1000 * 2 + CONNECTING_TIMEOUT * 2))\r
+                                               <= Tick64())\r
+                                       {\r
+                                               timeouted = true;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       if (timeouted)\r
+                       {\r
+                               // タイムアウトが発生した\r
+                               Debug("** Session Timeouted.\n");\r
+                               s->SessionTimeOuted = true;\r
+                               err = ERR_SESSION_TIMEOUT;\r
+                       }\r
+               }\r
+\r
+               // タイムアウト判定\r
+               if (pa_fail || s->SessionTimeOuted)\r
+               {\r
+                       s->Halt = true;\r
+                       s->RetryFlag = true;    // リトライフラグ\r
+                       break;\r
+               }\r
+       }\r
+\r
+CLEANUP:\r
+       Debug("Session %s Finishing...\n", s->Name);\r
+\r
+       // HUB のセッション一覧から削除する\r
+       if (s->ServerMode)\r
+       {\r
+               // ユーザー情報を更新する\r
+               IncrementUserTraffic(s->Hub, s->UserNameReal, s);\r
+\r
+               DelSession(s->Hub, s);\r
+       }\r
+\r
+       s->ConnectSucceed = false;\r
+       Notify(s, CLIENT_NOTIFY_ACCOUNT_CHANGED);\r
+\r
+       if (s->Connection)\r
+       {\r
+               s->Connection->Halt = true;\r
+       }\r
+\r
+       // パケットアダプタの解放\r
+       if (pa_inited)\r
+       {\r
+               pa->Free(s);\r
+       }\r
+\r
+       if (s->ServerMode == false)\r
+       {\r
+               // すべての追加コネクションの作成をキャンセルする\r
+               StopAllAdditionalConnectThread(s->Connection);\r
+       }\r
+\r
+       if (s->BridgeMode)\r
+       {\r
+               // ブリッジの終了\r
+               if (s->Bridge->Active)\r
+               {\r
+                       CloseEth(s->Bridge->Eth);\r
+                       s->Bridge->Eth = NULL;\r
+               }\r
+       }\r
+\r
+       if (s->Cancel2 != NULL)\r
+       {\r
+               // キャンセル2 の解放\r
+               ReleaseCancel(s->Cancel2);\r
+               s->Cancel2 = NULL;\r
+       }\r
+\r
+       // コネクションの終了\r
+       EndTunnelingMode(c);\r
+\r
+       if (nicinfo_sock != NULL)\r
+       {\r
+               CncNicInfoFree(nicinfo_sock);\r
+       }\r
+\r
+       if (msgdlg_sock != NULL)\r
+       {\r
+               CndMsgDlgFree(msgdlg_sock);\r
+       }\r
+\r
+       c->Err = err;\r
+}\r
+\r
+// 次の遅延パケットまでの時間を取得する\r
+UINT GetNextDelayedPacketTickDiff(SESSION *s)\r
+{\r
+       UINT i;\r
+       UINT ret = 0x7fffffff;\r
+       UINT64 now;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (LIST_NUM(s->DelayedPacketList) >= 1)\r
+       {\r
+               now = TickHighres64();\r
+\r
+               LockList(s->DelayedPacketList);\r
+               {\r
+                       for (i = 0;i < LIST_NUM(s->DelayedPacketList);i++)\r
+                       {\r
+                               PKT *p = LIST_DATA(s->DelayedPacketList, i);\r
+                               UINT64 t = p->DelayedForwardTick;\r
+                               UINT d = 0x7fffffff;\r
+\r
+                               if (now >= t)\r
+                               {\r
+                                       d = 0;\r
+                               }\r
+                               else\r
+                               {\r
+                                       d = (UINT)(t - now);\r
+                               }\r
+\r
+                               ret = MIN(ret, d);\r
+                       }\r
+               }\r
+               UnlockList(s->DelayedPacketList);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// VoIP / QoS 機能で優先すべきパケットかどうか判定する\r
+bool IsPriorityHighestPacketForQoS(void *data, UINT size)\r
+{\r
+       UCHAR *buf;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       buf = (UCHAR *)data;\r
+       if (size >= 16)\r
+       {\r
+               if (buf[12] == 0x08 && buf[13] == 0x00 && buf[15] != 0x00 && buf[15] != 0x08)\r
+               {\r
+                       // IPv4 パケットかつ ToS != 0\r
+                       return true;\r
+               }\r
+\r
+               if (size >= 34 && size <= 128)\r
+               {\r
+                       if (buf[12] == 0x08 && buf[13] == 0x00 && buf[23] == 0x01)\r
+                       {\r
+                               // IMCPv4 パケット\r
+                               return true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// ユーザーのトラフィック情報を更新する\r
+void IncrementUserTraffic(HUB *hub, char *username, SESSION *s)\r
+{\r
+       TRAFFIC report_traffic;\r
+       // 引数チェック\r
+       if (hub == NULL || username == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(s->TrafficLock);\r
+       {\r
+               // 報告するトラフィック情報 (前回との差分) を計算する\r
+               Zero(&report_traffic, sizeof(report_traffic));\r
+               report_traffic.Send.BroadcastBytes =\r
+                       s->Traffic->Send.BroadcastBytes - s->OldTraffic->Send.BroadcastBytes;\r
+               report_traffic.Send.BroadcastCount =\r
+                       s->Traffic->Send.BroadcastCount - s->OldTraffic->Send.BroadcastCount;\r
+               report_traffic.Send.UnicastBytes =\r
+                       s->Traffic->Send.UnicastBytes - s->OldTraffic->Send.UnicastBytes;\r
+               report_traffic.Send.UnicastCount =\r
+                       s->Traffic->Send.UnicastCount - s->OldTraffic->Send.UnicastCount;\r
+               report_traffic.Recv.BroadcastBytes =\r
+                       s->Traffic->Recv.BroadcastBytes - s->OldTraffic->Recv.BroadcastBytes;\r
+               report_traffic.Recv.BroadcastCount =\r
+                       s->Traffic->Recv.BroadcastCount - s->OldTraffic->Recv.BroadcastCount;\r
+               report_traffic.Recv.UnicastBytes =\r
+                       s->Traffic->Recv.UnicastBytes - s->OldTraffic->Recv.UnicastBytes;\r
+               report_traffic.Recv.UnicastCount =\r
+                       s->Traffic->Recv.UnicastCount - s->OldTraffic->Recv.UnicastCount;\r
+               Copy(s->OldTraffic, s->Traffic, sizeof(TRAFFIC));\r
+\r
+               if (hub->FarmMember == false)\r
+               {\r
+                       // ファームメンバーでない場合はローカルデータベースのユーザー情報を更新する\r
+                       AcLock(hub);\r
+                       {\r
+                               USER *u = AcGetUser(hub, username);\r
+                               if (u != NULL)\r
+                               {\r
+                                       Lock(u->lock);\r
+                                       {\r
+                                               AddTraffic(u->Traffic, &report_traffic);\r
+                                       }\r
+                                       Unlock(u->lock);\r
+                                       if (u->Group != NULL)\r
+                                       {\r
+                                               Lock(u->Group->lock);\r
+                                               {\r
+                                                       AddTraffic(u->Group->Traffic, &report_traffic);\r
+                                               }\r
+                                               Unlock(u->Group->lock);\r
+                                       }\r
+                                       ReleaseUser(u);\r
+                               }\r
+                       }\r
+                       AcUnlock(hub);\r
+               }\r
+               else\r
+               {\r
+                       // ファームメンバの場合はトラフィック差分報告リストを更新する\r
+                       AddTrafficDiff(hub, username, TRAFFIC_DIFF_USER, &report_traffic);\r
+               }\r
+       }\r
+       Unlock(s->TrafficLock);\r
+}\r
+\r
+// コネクションのトラフィック情報を加算\r
+void AddTrafficForSession(SESSION *s, TRAFFIC *t)\r
+{\r
+       HUB *h;\r
+       TRAFFIC t2;\r
+       // 引数チェック\r
+       if (s == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(s->TrafficLock);\r
+       {\r
+               AddTraffic(s->Traffic, t);\r
+       }\r
+       Unlock(s->TrafficLock);\r
+\r
+       if (s->ServerMode)\r
+       {\r
+               Zero(&t2, sizeof(t2));\r
+               Copy(&t2.Recv, &t->Send, sizeof(TRAFFIC_ENTRY));\r
+               Copy(&t2.Send, &t->Recv, sizeof(TRAFFIC_ENTRY));\r
+               Lock(s->Cedar->TrafficLock);\r
+               {\r
+                       AddTraffic(s->Cedar->Traffic, &t2);\r
+               }\r
+               Unlock(s->Cedar->TrafficLock);\r
+\r
+               h = s->Hub;\r
+               Lock(h->TrafficLock);\r
+               {\r
+                       AddTraffic(h->Traffic, &t2);\r
+               }\r
+               Unlock(h->TrafficLock);\r
+       }\r
+}\r
+\r
+// クライアントの追加コネクション確立のチャンス\r
+void ClientAdditionalConnectChance(SESSION *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s->ServerMode)\r
+       {\r
+               // サーバーモードの場合は追加接続しない\r
+               return;\r
+       }\r
+       if (s->Connection->Protocol != CONNECTION_TCP)\r
+       {\r
+               // TCP プロトコル以外の場合は追加接続しない\r
+               return;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               if (s->Halt)\r
+               {\r
+                       return;\r
+               }\r
+               // 追加コネクションを張る必要があるかどうかを\r
+               // 現在張っている または 張ろうとしているコネクション数と\r
+               // MaxConnection プロパティを見て検討する。\r
+               if (Count(s->Connection->CurrentNumConnection) < s->MaxConnection)\r
+               {\r
+                       // 現在時刻を取得\r
+                       UINT64 now = Tick64();\r
+\r
+                       // NextConnectionTime を調べてその時刻を過ぎていればコネクションを\r
+                       // 張ろうとする\r
+                       if (s->NextConnectionTime == 0 ||\r
+                               s->ClientOption->AdditionalConnectionInterval == 0 ||\r
+                               (s->NextConnectionTime <= now))\r
+                       {\r
+                               // 追加コネクションを張る作業を開始する\r
+                               s->NextConnectionTime = now + (UINT64)(s->ClientOption->AdditionalConnectionInterval * 1000);\r
+                               SessionAdditionalConnect(s);\r
+                       }\r
+                       else\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// パケットアダプタの解放\r
+void FreePacketAdapter(PACKET_ADAPTER *pa)\r
+{\r
+       // 引数チェック\r
+       if (pa == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(pa);\r
+}\r
+\r
+// 新しいパケットアダプタの作成\r
+PACKET_ADAPTER *NewPacketAdapter(PA_INIT *init, PA_GETCANCEL *getcancel, PA_GETNEXTPACKET *getnext,\r
+                                                                PA_PUTPACKET *put, PA_FREE *free)\r
+{\r
+       PACKET_ADAPTER *pa;\r
+       // 引数チェック\r
+       if (init == NULL || getcancel == NULL || getnext == NULL || put == NULL || free == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       pa = ZeroMalloc(sizeof(PACKET_ADAPTER));\r
+\r
+       pa->Init = init;\r
+       pa->Free = free;\r
+       pa->GetCancel = getcancel;\r
+       pa->GetNextPacket = getnext;\r
+       pa->PutPacket = put;\r
+\r
+       return pa;\r
+}\r
+\r
+// 追加コネクションを張るためのスレッド\r
+void ClientAdditionalThread(THREAD *t, void *param)\r
+{\r
+       SESSION *s;\r
+       CONNECTION *c;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = (SESSION *)param;\r
+\r
+       // s->LastTryAddConnectTime = Tick64();\r
+\r
+       c = s->Connection;\r
+       // 接続中カウンタのインクリメント\r
+       Inc(c->CurrentNumConnection);\r
+       LockList(c->ConnectingThreads);\r
+       {\r
+               // 処理中スレッドに追加\r
+               Add(c->ConnectingThreads, t);\r
+               AddRef(t->ref);\r
+       }\r
+       UnlockList(c->ConnectingThreads);\r
+\r
+       // 初期化の完了を通知\r
+       NoticeThreadInit(t);\r
+\r
+       Debug("Additional Connection #%u\n", Count(c->CurrentNumConnection));\r
+\r
+       // 追加コネクションを張る\r
+       if (ClientAdditionalConnect(c, t) == false)\r
+       {\r
+               // 現在処理中のカウンタをデクリメントする\r
+               Dec(c->CurrentNumConnection);\r
+       }\r
+       else\r
+       {\r
+               s->LastTryAddConnectTime = Tick64();\r
+       }\r
+\r
+       // 処理中スレッドから削除\r
+       LockList(c->ConnectingThreads);\r
+       {\r
+               // 処理中スレッドから削除\r
+               if (Delete(c->ConnectingThreads, t))\r
+               {\r
+                       ReleaseThread(t);\r
+               }\r
+       }\r
+       UnlockList(c->ConnectingThreads);\r
+       ReleaseSession(s);\r
+}\r
+\r
+// クライアントからサーバーに追加コネクションを張る\r
+void SessionAdditionalConnect(SESSION *s)\r
+{\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // s->LastTryAddConnectTime = Tick64();\r
+\r
+       AddRef(s->ref);\r
+       t = NewThread(ClientAdditionalThread, (void *)s);\r
+       WaitThreadInit(t);\r
+       ReleaseThread(t);\r
+}\r
+\r
+// クライアントセッションをサーバーに接続する\r
+bool SessionConnect(SESSION *s)\r
+{\r
+       CONNECTION *c;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s->ClientStatus = CLIENT_STATUS_CONNECTING;\r
+\r
+       Debug("SessionConnect() Started.\n");\r
+\r
+       // セッションの初期化\r
+       Lock(s->lock);\r
+       {\r
+               s->Err = ERR_NO_ERROR;\r
+               if (s->Policy != NULL)\r
+               {\r
+                       Free(s->Policy);\r
+                       s->Policy = NULL;\r
+               }\r
+       }\r
+       Unlock(s->lock);\r
+\r
+       s->CancelConnect = false;\r
+\r
+       // クライアントコネクションの作成\r
+       c = NewClientConnection(s);\r
+       s->Connection = c;\r
+\r
+       // クライアントをサーバーに接続する\r
+       ret = ClientConnect(c);\r
+       s->Err = c->Err;\r
+\r
+       s->CancelConnect = false;\r
+\r
+       if (s->Cedar->Client != NULL)\r
+       {\r
+               if (s->Policy != NULL)\r
+               {\r
+                       if (s->Policy->NoSavePassword)\r
+                       {\r
+                               s->Client_NoSavePassword = true;\r
+\r
+                               if (s->Account != NULL)\r
+                               {\r
+                                       Lock(s->Account->lock);\r
+                                       {\r
+                                               if (s->Account->ClientAuth != NULL)\r
+                                               {\r
+                                                       if (s->Account->ClientAuth->AuthType == AUTHTYPE_PASSWORD ||\r
+                                                               s->Account->ClientAuth->AuthType == AUTHTYPE_RADIUS)\r
+                                                       {\r
+                                                               Zero(s->Account->ClientAuth->HashedPassword, sizeof(s->Account->ClientAuth->HashedPassword));\r
+                                                               Zero(s->Account->ClientAuth->PlainPassword, sizeof(s->Account->ClientAuth->PlainPassword));\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       Unlock(s->Account->lock);\r
+\r
+                                       CiSaveConfigurationFile(s->Cedar->Client);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (c->ClientConnectError_NoSavePassword)\r
+       {\r
+               s->Client_NoSavePassword = true;\r
+       }\r
+\r
+       // クライアントコネクションの解放\r
+       s->Connection = NULL;\r
+       ReleaseConnection(c);\r
+\r
+       Lock(s->lock);\r
+       {\r
+               if (s->Policy != NULL)\r
+               {\r
+                       Free(s->Policy);\r
+                       s->Policy = NULL;\r
+               }\r
+       }\r
+       Unlock(s->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// セッションの停止\r
+void StopSession(SESSION *s)\r
+{\r
+       StopSessionEx(s, false);\r
+}\r
+void StopSessionEx(SESSION *s, bool no_wait)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 停止フラグ\r
+       s->UserCanceled = true;\r
+       s->CancelConnect = true;\r
+       s->Halt = true;\r
+\r
+       Debug("Stop Session %s\n", s->Name);\r
+\r
+       // キャンセル\r
+       Cancel(s->Cancel1);\r
+\r
+       // イベント\r
+       Set(s->HaltEvent);\r
+\r
+       if (s->ServerMode == false)\r
+       {\r
+               // クライアントモード\r
+               if (s->Connection)\r
+               {\r
+                       StopConnection(s->Connection, no_wait);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // サーバーモード\r
+               if (s->Connection)\r
+               {\r
+                       StopConnection(s->Connection, no_wait);\r
+               }\r
+       }\r
+\r
+       // 停止まで待機\r
+       if (no_wait == false)\r
+       {\r
+               while (true)\r
+               {\r
+                       s->ForceStopFlag = true;\r
+                       s->Halt = true;\r
+                       if (WaitThread(s->Thread, 20))\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               s->ForceStopFlag = true;\r
+               s->Halt = true;\r
+       }\r
+}\r
+\r
+// セッションのクリーンアップ\r
+void CleanupSession(SESSION *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 遅延パケットリストの解放\r
+       if (s->DelayedPacketList != NULL)\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(s->DelayedPacketList);i++)\r
+               {\r
+                       PKT *p = LIST_DATA(s->DelayedPacketList, i);\r
+\r
+                       Free(p->PacketData);\r
+                       FreePacket(p);\r
+               }\r
+\r
+               ReleaseList(s->DelayedPacketList);\r
+       }\r
+\r
+       // クライアント接続オプションの解放\r
+       if (s->ClientOption != NULL)\r
+       {\r
+               Free(s->ClientOption);\r
+       }\r
+\r
+       // クライアント認証データの解放\r
+       if (s->ClientAuth != NULL)\r
+       {\r
+               if (s->ClientAuth->ClientX != NULL)\r
+               {\r
+                       FreeX(s->ClientAuth->ClientX);\r
+               }\r
+               if (s->ClientAuth->ClientX != NULL)\r
+               {\r
+                       FreeK(s->ClientAuth->ClientK);\r
+               }\r
+               Free(s->ClientAuth);\r
+       }\r
+\r
+       FreeTraffic(s->Traffic);\r
+       Free(s->Name);\r
+\r
+       if (s->Thread != NULL)\r
+       {\r
+               ReleaseThread(s->Thread);\r
+       }\r
+\r
+       DeleteLock(s->lock);\r
+\r
+       ReleaseEvent(s->HaltEvent);\r
+\r
+       if (s->Cancel1)\r
+       {\r
+               ReleaseCancel(s->Cancel1);\r
+       }\r
+\r
+       if (s->Cancel2)\r
+       {\r
+               ReleaseCancel(s->Cancel2);\r
+       }\r
+\r
+       if (s->Policy)\r
+       {\r
+               Free(s->Policy);\r
+       }\r
+\r
+       if (s->Connection)\r
+       {\r
+               ReleaseConnection(s->Connection);\r
+       }\r
+\r
+       Free(s->Username);\r
+\r
+       if (s->PacketAdapter)\r
+       {\r
+               FreePacketAdapter(s->PacketAdapter);\r
+       }\r
+\r
+       if (s->OldTraffic != NULL)\r
+       {\r
+               FreeTraffic(s->OldTraffic);\r
+       }\r
+\r
+       DeleteLock(s->TrafficLock);\r
+\r
+       if (s->CancelList != NULL)\r
+       {\r
+               ReleaseCancelList(s->CancelList);\r
+       }\r
+\r
+       if (s->Client_Message != NULL)\r
+       {\r
+               Free(s->Client_Message);\r
+       }\r
+\r
+       DeleteCounter(s->LoggingRecordCount);\r
+\r
+       Free(s);\r
+}\r
+\r
+// セッションの解放\r
+void ReleaseSession(SESSION *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(s->ref) == 0)\r
+       {\r
+               CleanupSession(s);\r
+       }\r
+}\r
+\r
+// セッションの転送データサイズ合計を表示する\r
+void PrintSessionTotalDataSize(SESSION *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Debug(\r
+               "-- SESSION TOTAL PKT INFORMATION --\n\n"\r
+               "      TotalSendSize: %I64u\n"\r
+               "  TotalSendSizeReal: %I64u\n"\r
+               "      TotalRecvSize: %I64u\n"\r
+               "  TotalRecvSizeReal: %I64u\n"\r
+               "   Compression Rate: %.2f%% (Send)\n"\r
+               "                     %.2f%% (Recv)\n",\r
+               s->TotalSendSize, s->TotalSendSizeReal,\r
+               s->TotalRecvSize, s->TotalRecvSizeReal,\r
+               (float)((double)s->TotalSendSizeReal / (double)s->TotalSendSize * 100.0f),\r
+               (float)((double)s->TotalRecvSizeReal / (double)s->TotalRecvSize * 100.0f)\r
+               );\r
+\r
+}\r
+\r
+// クライアントスレッド\r
+void ClientThread(THREAD *t, void *param)\r
+{\r
+       SESSION *s;\r
+       bool use_password_dlg;\r
+       bool no_save_password = false;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Debug("ClientThread 0x%x Started.\n", t);\r
+\r
+       s = (SESSION *)param;\r
+       AddRef(s->ref);\r
+       s->Thread = t;\r
+       AddRef(t->ref);\r
+       NoticeThreadInit(t);\r
+\r
+       s->ClientStatus = CLIENT_STATUS_CONNECTING;\r
+       s->RetryFlag = true;\r
+       s->CurrentRetryCount = 0;\r
+\r
+       Notify(s, CLIENT_NOTIFY_ACCOUNT_CHANGED);\r
+\r
+       if (s->Cedar->Client != NULL)\r
+       {\r
+               no_save_password = s->Cedar->Client->DontSavePassword;\r
+       }\r
+\r
+       s->Win32HideConnectWindow = s->ClientOption->HideStatusWindow;\r
+       s->Win32HideNicInfoWindow = s->ClientOption->HideNicInfoWindow;\r
+\r
+       while (true)\r
+       {\r
+               CLog(s->Cedar->Client, "LC_CONNECT_1", s->ClientOption->AccountName, s->CurrentRetryCount + 1);\r
+               if (s->LinkModeClient && s->Link != NULL)\r
+               {\r
+                       HLog(s->Link->Hub, "LH_CONNECT_1", s->ClientOption->AccountName, s->CurrentRetryCount + 1);\r
+               }\r
+\r
+               Debug("Trying to Connect to Server... (%u / %u)\n", s->CurrentRetryCount + 0,\r
+                       s->ClientOption->NumRetry);\r
+\r
+               // 初期化\r
+//             s->TotalRecvSize = s->TotalRecvSizeReal = \r
+//                     s->TotalSendSize = s->TotalSendSizeReal = 0;\r
+               s->NextConnectionTime = 0;\r
+\r
+               // 接続を行う\r
+               s->ClientStatus = CLIENT_STATUS_CONNECTING;\r
+               s->Halt = false;\r
+               SessionConnect(s);\r
+               if (s->UserCanceled)\r
+               {\r
+                       s->Err = ERR_USER_CANCEL;\r
+               }\r
+               Debug("Disconnected. Err = %u : %S\n", s->Err, _E(s->Err));\r
+\r
+               PrintSessionTotalDataSize(s);\r
+\r
+               CLog(s->Cedar->Client, "LC_CONNECT_ERROR", s->ClientOption->AccountName,\r
+                       GetUniErrorStr(s->Err), s->Err);\r
+\r
+               if (s->LinkModeClient && s->Link != NULL)\r
+               {\r
+                       HLog(s->Link->Hub, "LH_CONNECT_ERROR", s->ClientOption->AccountName,\r
+                               GetUniErrorStr(s->Err), s->Err);\r
+               }\r
+\r
+               s->ClientStatus = CLIENT_STATUS_RETRY;\r
+\r
+               if (s->Link != NULL)\r
+               {\r
+                       ((LINK *)s->Link)->LastError = s->Err;\r
+               }\r
+\r
+               if (s->Halt && (s->RetryFlag == false) || s->ForceStopFlag)\r
+               {\r
+                       // 中断しなければならない\r
+                       if (s->Err == ERR_DEVICE_DRIVER_ERROR)\r
+                       {\r
+#ifdef OS_WIN32\r
+                               wchar_t tmp[MAX_SIZE];\r
+                               if (s->Account != NULL && s->Cedar->Client != NULL)\r
+                               {\r
+                                       UniFormat(tmp, sizeof(tmp), _UU("ERRDLG_DEVICE_ERROR"), s->ClientOption->DeviceName,\r
+                                               s->Err, _E(s->Err));\r
+                                       MsgBox(NULL, 0x10000 | 0x40000 | 0x200000 | 0x30, tmp);\r
+                               }\r
+#endif // OS_WIN32\r
+                       }\r
+                       break;\r
+               }\r
+               // パスワード再入力ダイアログを表示するかどうか判断する\r
+               use_password_dlg = false;\r
+\r
+               if (s->Account != NULL && s->Cedar->Client != NULL)\r
+               {\r
+#ifdef OS_WIN32\r
+                       if (s->ClientAuth->AuthType == CLIENT_AUTHTYPE_PASSWORD || s->ClientAuth->AuthType == CLIENT_AUTHTYPE_PLAIN_PASSWORD)\r
+                       {\r
+                               if (s->Err == ERR_AUTH_FAILED || s->Err == ERR_PROXY_AUTH_FAILED)\r
+                               {\r
+                                       use_password_dlg = true;\r
+                               }\r
+                       }\r
+#endif // OS_WIN32\r
+               }\r
+\r
+               // 接続に失敗した または接続が切断された\r
+               // リトライ間隔の間待機する\r
+\r
+               if (use_password_dlg == false)\r
+               {\r
+                       UINT retry_interval = s->RetryInterval;\r
+\r
+                       if (s->Err == ERR_HUB_IS_BUSY || s->Err == ERR_LICENSE_ERROR ||\r
+                               s->Err == ERR_HUB_STOPPING || s->Err == ERR_TOO_MANY_USER_SESSION)\r
+                       {\r
+                               retry_interval = RETRY_INTERVAL_SPECIAL;\r
+                       }\r
+\r
+                       if (s->CurrentRetryCount >= s->ClientOption->NumRetry)\r
+                       {\r
+                               // リトライ回数超過\r
+\r
+#ifndef        OS_WIN32\r
+\r
+                               break;\r
+\r
+#else  // OS_WIN32\r
+\r
+                               if (s->Win32HideConnectWindow == false &&\r
+                                       s->Cedar->Client != NULL && s->Account != NULL)\r
+                               {\r
+                                       // 再接続ダイアログを出す\r
+                                       UI_CONNECTERROR_DLG p;\r
+                                       Zero(&p, sizeof(p));\r
+                                       UniStrCpy(p.AccountName, sizeof(p.AccountName), s->ClientOption->AccountName);\r
+                                       StrCpy(p.ServerName, sizeof(p.ServerName), s->ClientOption->Hostname);\r
+                                       p.Err = s->Err;\r
+                                       p.CurrentRetryCount = s->CurrentRetryCount + 1;\r
+                                       s->Halt = false;\r
+                                       p.RetryLimit = 0;\r
+                                       p.RetryIntervalSec = 0;\r
+                                       p.CancelEvent = s->HaltEvent;\r
+                                       p.HideWindow = s->Win32HideConnectWindow;\r
+                                       if (CncConnectErrorDlg(s, &p) == false)\r
+                                       {\r
+                                               // 中断\r
+                                               break;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               s->Win32HideConnectWindow = p.HideWindow;\r
+                                               goto SKIP;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       break;\r
+                               }\r
+\r
+#endif\r
+                       }\r
+\r
+#ifndef        OS_WIN32\r
+\r
+                       // 単純な待機\r
+                       Wait(s->HaltEvent, retry_interval);\r
+\r
+#else  // OS_WIN32\r
+\r
+                       if (s->Win32HideConnectWindow == false &&\r
+                               s->Cedar->Client != NULL && s->Account != NULL)\r
+                       {\r
+                               // 再接続ダイアログを出す\r
+                               UI_CONNECTERROR_DLG p;\r
+                               Zero(&p, sizeof(p));\r
+                               UniStrCpy(p.AccountName, sizeof(p.AccountName), s->ClientOption->AccountName);\r
+                               StrCpy(p.ServerName, sizeof(p.ServerName), s->ClientOption->Hostname);\r
+                               p.Err = s->Err;\r
+                               p.CurrentRetryCount = s->CurrentRetryCount + 1;\r
+                               p.RetryLimit = s->ClientOption->NumRetry;\r
+                               p.RetryIntervalSec = retry_interval;\r
+                               p.CancelEvent = s->HaltEvent;\r
+                               s->Halt = false;\r
+                               p.HideWindow = s->Win32HideConnectWindow;\r
+                               if (CncConnectErrorDlg(s, &p) == false)\r
+                               {\r
+                                       // 中断\r
+                                       break;\r
+                               }\r
+                               s->Win32HideConnectWindow = p.HideWindow;\r
+                       }\r
+                       else\r
+                       {\r
+                               // 単純な待機\r
+                               Wait(s->HaltEvent, s->RetryInterval);\r
+                       }\r
+\r
+#endif // OS_WIN32\r
+               }\r
+               else\r
+               {\r
+#ifdef OS_WIN32\r
+                       // パスワードの再入力を求めて待機\r
+                       UI_PASSWORD_DLG p;\r
+                       Zero(&p, sizeof(p));\r
+                       if (s->Client_NoSavePassword == false)\r
+                       {\r
+                               p.ShowNoSavePassword = true;\r
+                       }\r
+                       p.NoSavePassword = no_save_password;\r
+                       p.CancelEvent = s->HaltEvent;\r
+                       if (s->Err == ERR_PROXY_AUTH_FAILED)\r
+                       {\r
+                               p.ProxyServer = true;\r
+                       }\r
+\r
+                       if (p.ProxyServer)\r
+                       {\r
+                               StrCpy(p.Username, sizeof(p.Username), s->ClientOption->ProxyUsername);\r
+                               StrCpy(p.Password, sizeof(p.Password), s->ClientOption->ProxyPassword);\r
+                               StrCpy(p.ServerName, sizeof(p.ServerName), s->ClientOption->ProxyName);\r
+                       }\r
+                       else\r
+                       {\r
+                               bool empty = false;\r
+\r
+                               StrCpy(p.Username, sizeof(p.Username), s->ClientAuth->Username);\r
+                               if (s->ClientAuth->AuthType == AUTHTYPE_RADIUS)\r
+                               {\r
+                                       if (StrLen(s->ClientAuth->PlainPassword) == 0)\r
+                                       {\r
+                                               empty = true;\r
+                                       }\r
+                               }\r
+                               else if (s->ClientAuth->AuthType == AUTHTYPE_PASSWORD)\r
+                               {\r
+                                       if (IsZero(s->ClientAuth->HashedPassword, sizeof(s->ClientAuth->HashedPassword)))\r
+                                       {\r
+                                               empty = true;\r
+                                       }\r
+                               }\r
+\r
+                               StrCpy(p.Password, sizeof(p.Password), empty ? "" : HIDDEN_PASSWORD);\r
+                               StrCpy(p.ServerName, sizeof(p.ServerName), s->ClientOption->Hostname);\r
+                       }\r
+\r
+                       p.RetryIntervalSec = s->RetryInterval / 1000;\r
+                       p.Type = s->ClientAuth->AuthType;\r
+\r
+                       // パスワード再入力ダイアログを表示する\r
+                       if (CncPasswordDlg(s, &p) == false)\r
+                       {\r
+                               // 接続を中断する\r
+                               break;\r
+                       }\r
+                       else\r
+                       {\r
+                               // ユーザー名を上書きする\r
+                               if (p.ProxyServer)\r
+                               {\r
+                                       // プロキシのユーザー名\r
+                                       StrCpy(s->ClientOption->ProxyUsername, sizeof(s->ClientOption->ProxyUsername), p.Username);\r
+                               }\r
+                               else\r
+                               {\r
+                                       // Server への接続のためのユーザー名\r
+                                       StrCpy(s->ClientAuth->Username, sizeof(s->ClientAuth->Username), p.Username);\r
+                                       s->ClientAuth->AuthType = p.Type;\r
+                               }\r
+\r
+                               if (StrCmp(p.Password, HIDDEN_PASSWORD) != 0)\r
+                               {\r
+                                       // パスワードを再入力した\r
+                                       if (p.ProxyServer)\r
+                                       {\r
+                                               // プロキシサーバーのパスワード\r
+                                               StrCpy(s->ClientOption->ProxyPassword, sizeof(s->ClientOption->ProxyPassword), p.Password);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (s->ClientAuth->AuthType == CLIENT_AUTHTYPE_PLAIN_PASSWORD)\r
+                                               {\r
+                                                       // 平文パスワード認証\r
+                                                       StrCpy(s->ClientAuth->PlainPassword, sizeof(s->ClientAuth->PlainPassword), p.Password);\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       // 暗号化パスワード認証\r
+                                                       HashPassword(s->ClientAuth->HashedPassword, s->ClientAuth->Username, p.Password);\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               no_save_password = p.NoSavePassword;\r
+\r
+                               if (s->Account != NULL && s->Cedar->Client != NULL)\r
+                               {\r
+                                       s->Cedar->Client->DontSavePassword = no_save_password;\r
+                                       if (p.NoSavePassword == false)\r
+                                       {\r
+                                               // クライアントのアカウントデータベースを更新する\r
+                                               if (p.ProxyServer == false)\r
+                                               {\r
+                                                       // Server 接続情報の更新\r
+                                                       ACCOUNT *a = s->Account;\r
+                                                       Lock(a->lock);\r
+                                                       {\r
+                                                               CiFreeClientAuth(a->ClientAuth);\r
+                                                               a->ClientAuth = CopyClientAuth(s->ClientAuth);\r
+                                                       }\r
+                                                       Unlock(a->lock);\r
+                                                       CiSaveConfigurationFile(s->Cedar->Client);\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       // Proxy 接続情報の更新\r
+                                                       ACCOUNT *a = s->Account;\r
+                                                       Lock(a->lock);\r
+                                                       {\r
+                                                               Copy(a->ClientOption, s->ClientOption, sizeof(CLIENT_OPTION));\r
+                                                       }\r
+                                                       Unlock(a->lock);\r
+                                                       CiSaveConfigurationFile(s->Cedar->Client);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+#endif // OS_WIN32\r
+               }\r
+\r
+SKIP:\r
+               // リトライ回数増加\r
+               if (s->ConnectSucceed == false)\r
+               {\r
+                       s->CurrentRetryCount++;\r
+               }\r
+\r
+               if (s->ForceStopFlag)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       Debug("Session Halt.\n");\r
+\r
+       s->ClientStatus = CLIENT_STATUS_IDLE;\r
+\r
+       // ここでセッションは終了したとみなす\r
+       if (s->Account != NULL)\r
+       {\r
+               s->Account->ClientSession = NULL;\r
+               ReleaseSession(s);\r
+       }\r
+\r
+       Notify(s, CLIENT_NOTIFY_ACCOUNT_CHANGED);\r
+\r
+       ReleaseSession(s);\r
+}\r
+\r
+// セッションの名前比較\r
+int CompareSession(void *p1, void *p2)\r
+{\r
+       SESSION *s1, *s2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       s1 = *(SESSION **)p1;\r
+       s2 = *(SESSION **)p2;\r
+       if (s1 == NULL || s2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return StrCmpi(s1->Name, s2->Name);\r
+}\r
+\r
+// RPC セッションの作成\r
+SESSION *NewRpcSession(CEDAR *cedar, CLIENT_OPTION *option)\r
+{\r
+       return NewRpcSessionEx(cedar, option, NULL, NULL);\r
+}\r
+SESSION *NewRpcSessionEx(CEDAR *cedar, CLIENT_OPTION *option, UINT *err, char *client_str)\r
+{\r
+       return NewRpcSessionEx2(cedar, option, err, client_str, NULL);\r
+}\r
+SESSION *NewRpcSessionEx2(CEDAR *cedar, CLIENT_OPTION *option, UINT *err, char *client_str, void *hWnd)\r
+{\r
+       SESSION *s;\r
+       CONNECTION *c;\r
+       SOCK *sock;\r
+       // 引数チェック\r
+       if (cedar == NULL || option == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       s = ZeroMalloc(sizeof(SESSION));\r
+\r
+       s->LoggingRecordCount = NewCounter();\r
+       s->lock = NewLock();\r
+       s->ref = NewRef();\r
+       s->Cedar = cedar;\r
+       s->ServerMode = false;\r
+       s->Name = CopyStr("CLIENT_RPC_SESSION");\r
+       s->CreatedTime = s->LastCommTime = Tick64();\r
+       s->Traffic = NewTraffic();\r
+       s->HaltEvent = NewEvent();\r
+       s->TrafficLock = NewLock();\r
+       s->Cancel1 = NewCancel();\r
+\r
+       // クライアント接続オプションのコピー\r
+       s->ClientOption = Malloc(sizeof(CLIENT_OPTION));\r
+       Copy(s->ClientOption, option, sizeof(CLIENT_OPTION));\r
+\r
+       s->MaxConnection = option->MaxConnection;\r
+       s->UseEncrypt = option->UseEncrypt;\r
+       s->UseCompress = option->UseCompress;\r
+\r
+       // コネクションの作成\r
+       c = s->Connection = NewClientConnectionEx(s, client_str, cedar->Version, cedar->Build);\r
+       c->hWndForUI = hWnd;\r
+\r
+       // サーバーへ接続\r
+       sock = ClientConnectToServer(c);\r
+       if (sock == NULL)\r
+       {\r
+               // 接続失敗\r
+               if (err != NULL)\r
+               {\r
+                       *err = c->Err;\r
+               }\r
+               ReleaseSession(s);\r
+               return NULL;\r
+       }\r
+\r
+       // シグネチャの送信\r
+       if (ClientUploadSignature(sock) == false)\r
+       {\r
+               // 失敗\r
+               if (err != NULL)\r
+               {\r
+                       *err = c->Err;\r
+               }\r
+               ReleaseSession(s);\r
+               return NULL;\r
+       }\r
+\r
+       // Hello パケットの受信\r
+       if (ClientDownloadHello(c, sock) == false)\r
+       {\r
+               // 失敗\r
+               if (err != NULL)\r
+               {\r
+                       *err = c->Err;\r
+               }\r
+               ReleaseSession(s);\r
+               return NULL;\r
+       }\r
+\r
+       return s;\r
+}\r
+\r
+// クライアントセッションの作成\r
+SESSION *NewClientSessionEx(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *auth, PACKET_ADAPTER *pa, ACCOUNT *account)\r
+{\r
+       SESSION *s;\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (cedar == NULL || option == NULL || auth == NULL || pa == NULL ||\r
+               (auth->AuthType == CLIENT_AUTHTYPE_SECURE && auth->SecureSignProc == NULL))\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // SESSION オブジェクトの初期化\r
+       s = ZeroMalloc(sizeof(SESSION));\r
+\r
+       s->LoggingRecordCount = NewCounter();\r
+\r
+       s->lock = NewLock();\r
+       s->ref = NewRef();\r
+       s->Cedar = cedar;\r
+       s->ServerMode = false;\r
+       s->Name = CopyStr("CLIENT_SESSION");\r
+       s->CreatedTime = s->LastCommTime = Tick64();\r
+       s->Traffic = NewTraffic();\r
+       s->HaltEvent = NewEvent();\r
+       s->PacketAdapter = pa;\r
+       s->TrafficLock = NewLock();\r
+       s->OldTraffic = NewTraffic();\r
+       s->Cancel1 = NewCancel();\r
+       s->CancelList = NewCancelList();\r
+\r
+       // クライアント接続オプションのコピー\r
+       s->ClientOption = Malloc(sizeof(CLIENT_OPTION));\r
+       Copy(s->ClientOption, option, sizeof(CLIENT_OPTION));\r
+\r
+       s->MaxConnection = option->MaxConnection;\r
+       s->UseEncrypt = option->UseEncrypt;\r
+       s->UseCompress = option->UseCompress;\r
+\r
+       // リトライ間隔の設定\r
+       s->RetryInterval = MAKESURE(option->RetryInterval, 0, 4000000) * 1000;\r
+       s->RetryInterval = MAKESURE(s->RetryInterval, MIN_RETRY_INTERVAL, MAX_RETRY_INTERVAL);\r
+\r
+       // 追加コネクション作成間隔は最低 1 秒\r
+       s->ClientOption->AdditionalConnectionInterval = MAX(s->ClientOption->AdditionalConnectionInterval, 1);\r
+\r
+       // クライアントモードで仮想 LAN カードを使用しているかどうか保持\r
+       s->ClientModeAndUseVLan = (StrLen(s->ClientOption->DeviceName) == 0) ? false : true;\r
+       if (s->ClientOption->NoRoutingTracking)\r
+       {\r
+               s->ClientModeAndUseVLan = false;\r
+       }\r
+\r
+       if (StrLen(option->DeviceName) == 0)\r
+       {\r
+               // NAT モード\r
+               s->ClientModeAndUseVLan = false;\r
+               s->VirtualHost = true;\r
+       }\r
+\r
+       if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType))\r
+       {\r
+               // Win9x の場合は半二重モードを禁止する\r
+               s->ClientOption->HalfConnection = false;\r
+       }\r
+\r
+       // クライアント認証データのコピー\r
+       s->ClientAuth = Malloc(sizeof(CLIENT_AUTH));\r
+       Copy(s->ClientAuth, auth, sizeof(CLIENT_AUTH));\r
+\r
+       // 証明書と秘密鍵のクローン\r
+       if (s->ClientAuth->ClientX != NULL)\r
+       {\r
+               s->ClientAuth->ClientX = CloneX(s->ClientAuth->ClientX);\r
+       }\r
+       if (s->ClientAuth->ClientK != NULL)\r
+       {\r
+               s->ClientAuth->ClientK = CloneK(s->ClientAuth->ClientK);\r
+       }\r
+\r
+       if (StrCmpi(s->ClientOption->DeviceName, LINK_DEVICE_NAME) == 0)\r
+       {\r
+               // リンククライアントモード\r
+               s->LinkModeClient = true;\r
+               s->Link = (LINK *)s->PacketAdapter->Param;\r
+       }\r
+\r
+       if (StrCmpi(s->ClientOption->DeviceName, SNAT_DEVICE_NAME) == 0)\r
+       {\r
+               // SecureNAT モード\r
+               s->SecureNATMode = true;\r
+       }\r
+\r
+       if (StrCmpi(s->ClientOption->DeviceName, BRIDGE_DEVICE_NAME) == 0)\r
+       {\r
+               // Bridge モード\r
+               s->BridgeMode = true;\r
+       }\r
+\r
+       if (s->VirtualHost)\r
+       {\r
+               VH *v = (VH *)s->PacketAdapter->Param;\r
+\r
+               // セッションオブジェクトを VH に追加\r
+               v->Session = s;\r
+               AddRef(s->ref);\r
+       }\r
+\r
+       s->Account = account;\r
+\r
+       if (s->ClientAuth->AuthType == CLIENT_AUTHTYPE_SECURE)\r
+       {\r
+               // スマートカード認証の場合はリトライしない\r
+               s->ClientOption->NumRetry = 0;\r
+       }\r
+\r
+       // クライアントスレッドの作成\r
+       t = NewThread(ClientThread, (void *)s);\r
+       WaitThreadInit(t);\r
+       ReleaseThread(t);\r
+\r
+       return s;\r
+}\r
+SESSION *NewClientSession(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *auth, PACKET_ADAPTER *pa)\r
+{\r
+       return NewClientSessionEx(cedar, option, auth, pa, NULL);\r
+}\r
+\r
+// 32bit のセッションキーからセッションを取得\r
+SESSION *GetSessionFromKey32(CEDAR *cedar, UINT key32)\r
+{\r
+       HUB *h;\r
+       UINT i, j;\r
+       // 引数チェック\r
+       if (cedar == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       LockList(cedar->HubList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(cedar->HubList);i++)\r
+               {\r
+                       h = LIST_DATA(cedar->HubList, i);\r
+                       LockList(h->SessionList);\r
+                       {\r
+                               for (j = 0;j < LIST_NUM(h->SessionList);j++)\r
+                               {\r
+                                       SESSION *s = LIST_DATA(h->SessionList, j);\r
+                                       Lock(s->lock);\r
+                                       {\r
+                                               if (s->SessionKey32 == key32)\r
+                                               {\r
+                                                       // セッション発見\r
+                                                       AddRef(s->ref);\r
+\r
+                                                       // ロック解除\r
+                                                       Unlock(s->lock);\r
+                                                       UnlockList(h->SessionList);\r
+                                                       UnlockList(cedar->HubList);\r
+                                                       return s;\r
+                                               }\r
+                                       }\r
+                                       Unlock(s->lock);\r
+                               }\r
+                       }\r
+                       UnlockList(h->SessionList);\r
+               }\r
+       }\r
+       UnlockList(cedar->HubList);\r
+\r
+       return NULL;\r
+}\r
+\r
+// セッションキーからセッションを取得\r
+SESSION *GetSessionFromKey(CEDAR *cedar, UCHAR *session_key)\r
+{\r
+       HUB *h;\r
+       UINT i, j;\r
+       // 引数チェック\r
+       if (cedar == NULL || session_key == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       LockList(cedar->HubList);\r
+       {\r
+               for (i = 0;i < LIST_NUM(cedar->HubList);i++)\r
+               {\r
+                       h = LIST_DATA(cedar->HubList, i);\r
+                       LockList(h->SessionList);\r
+                       {\r
+                               for (j = 0;j < LIST_NUM(h->SessionList);j++)\r
+                               {\r
+                                       SESSION *s = LIST_DATA(h->SessionList, j);\r
+                                       Lock(s->lock);\r
+                                       {\r
+                                               if (Cmp(s->SessionKey, session_key, SHA1_SIZE) == 0)\r
+                                               {\r
+                                                       // セッション発見\r
+                                                       AddRef(s->ref);\r
+\r
+                                                       // ロック解除\r
+                                                       Unlock(s->lock);\r
+                                                       UnlockList(h->SessionList);\r
+                                                       UnlockList(cedar->HubList);\r
+                                                       return s;\r
+                                               }\r
+                                       }\r
+                                       Unlock(s->lock);\r
+                               }\r
+                       }\r
+                       UnlockList(h->SessionList);\r
+               }\r
+       }\r
+       UnlockList(cedar->HubList);\r
+\r
+       return NULL;\r
+}\r
+\r
+// 新しいセッションキーを作成\r
+void NewSessionKey(CEDAR *cedar, UCHAR *session_key, UINT *session_key_32)\r
+{\r
+       // 引数チェック\r
+       if (cedar == NULL || session_key == NULL || session_key_32 == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Rand(session_key, SHA1_SIZE);\r
+       *session_key_32 = Rand32();\r
+}\r
+\r
+bool if_init(SESSION *s);\r
+CANCEL *if_getcancel(SESSION *s);\r
+UINT if_getnext(SESSION *s, void **data);\r
+bool if_putpacket(SESSION *s, void *data, UINT size);\r
+void if_free(SESSION *s);\r
+\r
+\r
+// サーバーセッションの作成\r
+SESSION *NewServerSession(CEDAR *cedar, CONNECTION *c, HUB *h, char *username, POLICY *policy)\r
+{\r
+       SESSION *s;\r
+       char name[MAX_SIZE];\r
+       char hub_name_upper[MAX_SIZE];\r
+       char user_name_upper[MAX_USERNAME_LEN + 1];\r
+       // 引数チェック\r
+       if (cedar == NULL || c == NULL || h == NULL || username == NULL || policy == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // SESSION オブジェクトの初期化\r
+       s = ZeroMalloc(sizeof(SESSION));\r
+\r
+       s->LoggingRecordCount = NewCounter();\r
+       s->lock = NewLock();\r
+       s->ref = NewRef();\r
+       s->Cedar = cedar;\r
+       s->ServerMode = true;\r
+       s->CreatedTime = s->LastCommTime = Tick64();\r
+       s->Traffic = NewTraffic();\r
+       s->HaltEvent = NewEvent();\r
+       s->Cancel1 = NewCancel();\r
+       s->CancelList = NewCancelList();\r
+       s->Thread = c->Thread;\r
+       s->TrafficLock = NewLock();\r
+       s->OldTraffic = NewTraffic();\r
+       s->QoS = GetServerCapsBool(cedar->Server, "b_support_qos");\r
+       AddRef(s->Thread->ref);\r
+       s->Hub = h;\r
+       s->ClientStatus = CLIENT_STATUS_ESTABLISHED;\r
+\r
+       // 遅延パケットリスト\r
+       s->DelayedPacketList = NewList(NULL);\r
+\r
+       // HUB 用のパケットアダプタ\r
+       s->PacketAdapter = GetHubPacketAdapter();\r
+\r
+       s->Connection = c;\r
+       AddRef(c->ref);\r
+\r
+       // 新しいセッション名の決定\r
+       StrCpy(hub_name_upper, sizeof(hub_name_upper), h->Name);\r
+       StrUpper(hub_name_upper);\r
+       StrCpy(user_name_upper, sizeof(user_name_upper), username);\r
+       StrUpper(user_name_upper);\r
+\r
+       if ((StrCmpi(username, ADMINISTRATOR_USERNAME) != 0) && (StrCmpi(username, BRIDGE_USER_NAME) != 0) || (cedar->Server == NULL || cedar->Server->ServerType == SERVER_TYPE_STANDALONE))\r
+       {\r
+               Format(name, sizeof(name), "SID-%s-%u", user_name_upper, Inc(h->SessionCounter));\r
+       }\r
+       else\r
+       {\r
+               UCHAR rand[SHA1_SIZE];\r
+               char tmp[MAX_SIZE];\r
+               Rand(rand, sizeof(rand));\r
+               BinToStr(tmp, sizeof(tmp), rand, 3);\r
+\r
+               if (StrCmpi(username, BRIDGE_USER_NAME) != 0)\r
+               {\r
+                       Format(name, sizeof(name), "SID-%s-%s", user_name_upper,\r
+                               tmp);\r
+               }\r
+               else\r
+               {\r
+                       char pc_name[MAX_SIZE];\r
+                       TOKEN_LIST *t;\r
+\r
+                       GetMachineName(tmp, sizeof(tmp));\r
+                       t = ParseToken(tmp, ".");\r
+                       if (t->NumTokens >= 1)\r
+                       {\r
+                               StrCpy(pc_name, sizeof(pc_name), t->Token[0]);\r
+                       }\r
+                       else\r
+                       {\r
+                               StrCpy(pc_name, sizeof(pc_name), "pc");\r
+                       }\r
+                       FreeToken(t);\r
+\r
+                       StrUpper(pc_name);\r
+\r
+                       Format(name, sizeof(name), "SID-%s-%s-%u", user_name_upper, pc_name,\r
+                               Inc(h->SessionCounter));\r
+               }\r
+       }\r
+\r
+       s->Name = CopyStr(name);\r
+       s->Policy = policy;\r
+\r
+       // HUB に SESSION を追加\r
+       AddSession(h, s);\r
+\r
+       // キーを作成\r
+       NewSessionKey(cedar, s->SessionKey, &s->SessionKey32);\r
+\r
+       return s;\r
+}\r
+\r
+// セッションキーをデバッグ用に表示\r
+void DebugPrintSessionKey(UCHAR *session_key)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (session_key == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Bit160ToStr(tmp, session_key);\r
+       Debug("SessionKey: %s\n", tmp);\r
+}\r
+\r
+// クライアントにステータスを表示する\r
+void PrintStatus(SESSION *s, wchar_t *str)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || str == NULL || s->Account == NULL || s->Cedar->Client == NULL\r
+               || s->Account->StatusPrinter == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // コールバック関数に対してステータスを通知する\r
+       s->Account->StatusPrinter(s, str);\r
+}\r
+\r
+// キャンセルリストの作成\r
+LIST *NewCancelList()\r
+{\r
+       return NewList(NULL);\r
+}\r
+\r
+// キャンセルリストにキャンセルを追加\r
+void AddCancelList(LIST *o, CANCEL *c)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               CANCEL *t = LIST_DATA(o, i);\r
+               if (t == c)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       AddRef(c->ref);\r
+       Add(o, c);\r
+}\r
+\r
+// キャンセルリスト内の全キャンセルの発行\r
+void CancelList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               CANCEL *c = LIST_DATA(o, i);\r
+               Cancel(c);\r
+               ReleaseCancel(c);\r
+       }\r
+\r
+       DeleteAll(o);\r
+}\r
+\r
+// キャンセルリストの解放\r
+void ReleaseCancelList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               CANCEL *c = LIST_DATA(o, i);\r
+               ReleaseCancel(c);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// クライアントに通知\r
+void Notify(SESSION *s, UINT code)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || s->Account == NULL || s->Cedar->Client == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CiNotify(s->Cedar->Client);\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Session.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Session.h
new file mode 100644 (file)
index 0000000..f6fcd7a
--- /dev/null
@@ -0,0 +1,355 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Session.h\r
+// Session.c のヘッダ\r
+\r
+#ifndef        SESSION_H\r
+#define        SESSION_H\r
+\r
+\r
+\r
+// パケットアダプタ関数\r
+typedef bool (PA_INIT)(SESSION *s);\r
+typedef CANCEL *(PA_GETCANCEL)(SESSION *s);\r
+typedef UINT (PA_GETNEXTPACKET)(SESSION *s, void **data);\r
+typedef bool (PA_PUTPACKET)(SESSION *s, void *data, UINT size);\r
+typedef void (PA_FREE)(SESSION *s);\r
+\r
+// クライアント関係関数\r
+typedef void (CLIENT_STATUS_PRINTER)(SESSION *s, wchar_t *status);\r
+\r
+// ノード情報\r
+struct NODE_INFO\r
+{\r
+       char ClientProductName[64];             // クライアント製品名\r
+       UINT ClientProductVer;                  // クライアントバージョン\r
+       UINT ClientProductBuild;                // クライアントビルド番号\r
+       char ServerProductName[64];             // サーバー製品名\r
+       UINT ServerProductVer;                  // サーバーバージョン\r
+       UINT ServerProductBuild;                // サーバービルド番号\r
+       char ClientOsName[64];                  // クライアント OS 名\r
+       char ClientOsVer[128];                  // クライアント OS バージョン\r
+       char ClientOsProductId[64];             // クライアント OS プロダクト ID\r
+       char ClientHostname[64];                // クライアントホスト名\r
+       UINT ClientIpAddress;                   // クライアント IP アドレス\r
+       UINT ClientPort;                                // クライアントポート番号\r
+       char ServerHostname[64];                // サーバーホスト名\r
+       UINT ServerIpAddress;                   // サーバー IP アドレス\r
+       UINT ServerPort;                                // サーバーポート番号\r
+       char ProxyHostname[64];                 // プロキシホスト名\r
+       UINT ProxyIpAddress;                    // プロキシ IP アドレス\r
+       UINT ProxyPort;                                 // プロキシポート番号\r
+       char HubName[64];                               // HUB 名\r
+       UCHAR UniqueId[16];                             // ユニーク ID\r
+       // 以下は IPv6 対応用\r
+       UCHAR ClientIpAddress6[16];             // クライアント IPv6 アドレス\r
+       UCHAR ServerIpAddress6[16];             // サーバー IP アドレス\r
+       UCHAR ProxyIpAddress6[16];              // プロキシ IP アドレス\r
+       char Padding[304 - (16 * 3)];   // パディング\r
+};\r
+\r
+// パケットアダプタ\r
+struct PACKET_ADAPTER\r
+{\r
+       PA_INIT *Init;\r
+       PA_GETCANCEL *GetCancel;\r
+       PA_GETNEXTPACKET *GetNextPacket;\r
+       PA_PUTPACKET *PutPacket;\r
+       PA_FREE *Free;\r
+       void *Param;\r
+};\r
+\r
+// セッション構造体\r
+struct SESSION\r
+{\r
+       LOCK *lock;                                             // ロック\r
+       REF *ref;                                               // 参照カウンタ\r
+       CEDAR *Cedar;                                   // Cedar\r
+       bool LocalHostSession;                  // ローカルホストセッション\r
+       bool ServerMode;                                // サーバーモードセッション\r
+       bool LinkModeClient;                    // リンクモードクライアント\r
+       bool LinkModeServer;                    // リンクモードサーバー\r
+       bool SecureNATMode;                             // SecureNAT セッション\r
+       bool BridgeMode;                                // Bridge セッション\r
+       bool VirtualHost;                               // 仮想ホストモード\r
+       bool L3SwitchMode;                              // Layer-3 スイッチモード\r
+       THREAD *Thread;                                 // 管理スレッド\r
+       CONNECTION *Connection;                 // コネクション\r
+       CLIENT_OPTION *ClientOption;    // クライアント接続オプション\r
+       CLIENT_AUTH *ClientAuth;                // クライアント認証データ\r
+       volatile bool Halt;                             // 停止フラグ\r
+       volatile bool CancelConnect;    // 接続のキャンセル\r
+       EVENT *HaltEvent;                               // 停止イベント\r
+       UINT Err;                                               // エラー値\r
+       HUB *Hub;                                               // HUB\r
+       CANCEL *Cancel1;                                // キャンセルオブジェクト 1\r
+       CANCEL *Cancel2;                                // キャンセルオブジェクト 2\r
+       PACKET_ADAPTER *PacketAdapter;  // パケットアダプタ\r
+       UCHAR UdpSendKey[16];                   // UDP 送信用暗号化鍵\r
+       UCHAR UdpRecvKey[16];                   // UDP 受信用暗号化鍵\r
+       UINT ClientStatus;                              // クライアントステータス\r
+       bool RetryFlag;                                 // リトライフラグ (クライアント)\r
+       bool ForceStopFlag;                             // 強制停止フラグ (クライアント)\r
+       UINT CurrentRetryCount;                 // 現在のリトライカウンタ (クライアント)\r
+       UINT RetryInterval;                             // リトライ間隔 (クライアント)\r
+       bool ConnectSucceed;                    // 接続成功フラグ (クライアント)\r
+       bool SessionTimeOuted;                  // セッションがタイムアウトした\r
+       UINT Timeout;                                   // タイムアウト時間\r
+       UINT64 NextConnectionTime;              // 次に追加コネクションを張る時刻\r
+       IP ServerIP;                                    // サーバーの IP アドレス\r
+       bool ClientModeAndUseVLan;              // クライアントモードで仮想 LAN カードを使用\r
+       bool UseSSLDataEncryption;              // SSL データ暗号化を使用する\r
+       LOCK *TrafficLock;                              // トラフィックデータロック\r
+       LINK *Link;                                             // リンクオブジェクトへの参照\r
+       SNAT *SecureNAT;                                // SecureNAT オブジェクトへの参照\r
+       BRIDGE *Bridge;                                 // Bridge オブジェクトへの参照\r
+       NODE_INFO NodeInfo;                             // ノード情報\r
+       UINT64 LastIncrementTraffic;    // 最後にユーザーのトラフィックデータを更新した時刻\r
+       bool AdministratorMode;                 // 管理者モード\r
+       LIST *CancelList;                               // キャンセルリスト\r
+       L3IF *L3If;                                             // Layer-3 インターフェイス\r
+       IP DefaultDns;                                  // デフォルトの DNS サーバーの IP アドレス\r
+       bool IPv6Session;                               // IPv6 セッション (物理的な通信が IPv6 である)\r
+       UINT VLanId;                                    // VLAN ID\r
+\r
+       UINT64 CreatedTime;                             // 作成日時\r
+       UINT64 LastCommTime;                    // 最終通信日時\r
+       TRAFFIC *Traffic;                               // トラフィックデータ\r
+       TRAFFIC *OldTraffic;                    // 古いトラフィックデータ\r
+       UINT64 TotalSendSize;                   // 合計送信データサイズ\r
+       UINT64 TotalRecvSize;                   // 合計受信データサイズ\r
+       UINT64 TotalSendSizeReal;               // 合計送信データサイズ (無圧縮)\r
+       UINT64 TotalRecvSizeReal;               // 合計受信データサイズ (無圧縮)\r
+       char *Name;                                             // セッション名\r
+       char *Username;                                 // ユーザー名\r
+       char UserNameReal[MAX_USERNAME_LEN + 1];        // ユーザー名 (本物)\r
+       char GroupName[MAX_USERNAME_LEN + 1];   // グループ名\r
+       POLICY *Policy;                                 // ポリシー\r
+       UCHAR SessionKey[SHA1_SIZE];    // セッションキー\r
+       UINT SessionKey32;                              // 32bit のセッションキー\r
+       UINT MaxConnection;                             // 最大同時接続 TCP コネクション数\r
+       bool UseEncrypt;                                // 暗号化通信を使用\r
+       bool UseFastRC4;                                // 高速 RC4 暗号化を使用\r
+       bool UseCompress;                               // データ圧縮を使用\r
+       bool HalfConnection;                    // ハーフコネクションモード\r
+       bool QoS;                                               // VoIP / QoS\r
+       bool NoSendSignature;                   // シグネチャを送信しない\r
+       UINT64 FirstConnectionEstablisiedTime;  // 最初のコネクションの接続完了時刻\r
+       UINT64 CurrentConnectionEstablishTime;  // このコネクションの接続完了時刻\r
+       UINT NumConnectionsEatablished; // これまでに確立したコネクション数\r
+\r
+       ACCOUNT *Account;                               // クライアント アカウント\r
+       UINT VLanDeviceErrorCount;              // 仮想 LAN カードでエラーが発生した回数\r
+       bool Win32HideConnectWindow;    // 接続ウインドウを非表示にする\r
+       bool Win32HideNicInfoWindow;    // NIC 情報ウインドウを非表示にする\r
+       bool UserCanceled;                              // ユーザーによってキャンセルされた\r
+       UINT64 LastTryAddConnectTime;   // 最後にコネクションの追加を試行しようとした時刻\r
+\r
+       bool IsMonitorMode;                             // モニタモードか否か\r
+       bool IsBridgeMode;                              // ブリッジモードか否か\r
+       bool UseClientLicense;                  // 割り当てられたクライアントライセンス数\r
+       bool UseBridgeLicense;                  // 割り当てられたブリッジライセンス数\r
+\r
+       COUNTER *LoggingRecordCount;    // ロギング中のレコード数のカウンタ\r
+\r
+       bool Client_NoSavePassword;             // パスワードの保存を禁止\r
+       wchar_t *Client_Message;                // サーバーから送信されてきたメッセージ\r
+\r
+       LIST *DelayedPacketList;                // 遅延パケットリスト\r
+       UINT Flag1;\r
+\r
+       // D-Link バグ対策\r
+       UINT64 LastDLinkSTPPacketSendTick;      // 最後の D-Link STP パケット送出時刻\r
+       UCHAR LastDLinkSTPPacketDataHash[MD5_SIZE];     // 最後の D-Link STP パケットハッシュ\r
+};\r
+\r
+// パスワードダイアログ\r
+struct UI_PASSWORD_DLG\r
+{\r
+       UINT Type;                                              // パスワードの種類\r
+       char Username[MAX_USERNAME_LEN + 1];    // ユーザー名\r
+       char Password[MAX_PASSWORD_LEN + 1];    // パスワード\r
+       char ServerName[MAX_HOST_NAME_LEN + 1]; // サーバー名\r
+       UINT RetryIntervalSec;                  // リトライまでの時間\r
+       EVENT *CancelEvent;                             // ダイアログ表示をキャンセルするイベント\r
+       bool ProxyServer;                               // プロキシサーバーに関する認証\r
+       UINT64 StartTick;                               // 開始時刻\r
+       bool AdminMode;                                 // 管理モード\r
+       bool ShowNoSavePassword;                // パスワードを保存しないチェックボックスを表示するかどうか\r
+       bool NoSavePassword;                    // パスワードを保存しないモード\r
+       SOCK *Sock;                                             // ソケット\r
+};\r
+\r
+// メッセージダイアログ\r
+struct UI_MSG_DLG\r
+{\r
+       char ServerName[MAX_HOST_NAME_LEN + 1]; // サーバー名\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // 仮想 HUB 名\r
+       wchar_t *Msg;                                   // 本文\r
+       SOCK *Sock;                                             // ソケット\r
+       bool Halt;                                              // 閉じるフラグ\r
+};\r
+\r
+// NIC 情報\r
+struct UI_NICINFO\r
+{\r
+       wchar_t AccountName[MAX_SIZE];  // 接続設定名\r
+       char NicName[MAX_SIZE];                 // 仮想 NIC 名\r
+\r
+       SOCK *Sock;                                             // ソケット\r
+       bool Halt;                                              // 閉じるフラグ\r
+       ROUTE_CHANGE *RouteChange;              // ルーティングテーブル変更通知\r
+       UINT CurrentIcon;                               // 現在のアイコン\r
+       UINT64 CloseAfterTime;                  // 自動で閉じる\r
+};\r
+\r
+// 接続エラーダイアログ\r
+struct UI_CONNECTERROR_DLG\r
+{\r
+       EVENT *CancelEvent;                             // ダイアログ表示をキャンセルするイベント\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];  // アカウント名\r
+       char ServerName[MAX_HOST_NAME_LEN + 1]; // サーバー名\r
+       UINT Err;                                               // エラーコード\r
+       UINT CurrentRetryCount;                 // 現在のリトライ回数\r
+       UINT RetryLimit;                                // リトライ回数のリミット\r
+       UINT64 StartTick;                               // 開始時刻\r
+       UINT RetryIntervalSec;                  // リトライまでの時間\r
+       bool HideWindow;                                // ウインドウを非表示にする\r
+       SOCK *Sock;                                             // ソケット\r
+};\r
+\r
+// サーバー証明書チェックダイアログ\r
+struct UI_CHECKCERT\r
+{\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];  // アカウント名\r
+       char ServerName[MAX_HOST_NAME_LEN + 1]; // サーバー名\r
+       X *x;                                                   // サーバー証明書\r
+       X *parent_x;                                    // 親証明書\r
+       X *old_x;                                               // 前回の証明書\r
+       bool DiffWarning;                               // 証明書変造の警告を表示する\r
+       bool Ok;                                                // 接続許可フラグ\r
+       bool SaveServerCert;                    // サーバー証明書を保存する\r
+       SESSION *Session;                               // セッション\r
+       volatile bool Halt;                             // 停止フラグ\r
+       SOCK *Sock;                                             // ソケット\r
+};\r
+\r
+\r
+// 関数プロトタイプ\r
+SESSION *NewClientSessionEx(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *auth, PACKET_ADAPTER *pa, struct ACCOUNT *account);\r
+SESSION *NewClientSession(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *auth, PACKET_ADAPTER *pa);\r
+SESSION *NewRpcSession(CEDAR *cedar, CLIENT_OPTION *option);\r
+SESSION *NewRpcSessionEx(CEDAR *cedar, CLIENT_OPTION *option, UINT *err, char *client_str);\r
+SESSION *NewRpcSessionEx2(CEDAR *cedar, CLIENT_OPTION *option, UINT *err, char *client_str, void *hWnd);\r
+SESSION *NewServerSession(CEDAR *cedar, CONNECTION *c, HUB *h, char *username, POLICY *policy);\r
+void ClientThread(THREAD *t, void *param);\r
+void ReleaseSession(SESSION *s);\r
+void CleanupSession(SESSION *s);\r
+void StopSession(SESSION *s);\r
+void StopSessionEx(SESSION *s, bool no_wait);\r
+bool SessionConnect(SESSION *s);\r
+bool ClientConnect(CONNECTION *c);\r
+int CompareSession(void *p1, void *p2);\r
+PACKET_ADAPTER *NewPacketAdapter(PA_INIT *init, PA_GETCANCEL *getcancel, PA_GETNEXTPACKET *getnext,\r
+                                                                PA_PUTPACKET *put, PA_FREE *free);\r
+void FreePacketAdapter(PACKET_ADAPTER *pa);\r
+void SessionMain(SESSION *s);\r
+void NewSessionKey(CEDAR *cedar, UCHAR *session_key, UINT *session_key_32);\r
+SESSION *GetSessionFromKey(CEDAR *cedar, UCHAR *session_key);\r
+SESSION *GetSessionFromKey32(CEDAR *cedar, UINT key32);\r
+void DebugPrintSessionKey(UCHAR *session_key);\r
+void ClientAdditionalConnectChance(SESSION *s);\r
+void SessionAdditionalConnect(SESSION *s);\r
+void ClientAdditionalThread(THREAD *t, void *param);\r
+void PrintSessionTotalDataSize(SESSION *s);\r
+void AddTrafficForSession(SESSION *s, TRAFFIC *t);\r
+void IncrementUserTraffic(HUB *hub, char *username, SESSION *s);\r
+void Notify(SESSION *s, UINT code);\r
+void PrintStatus(SESSION *s, wchar_t *str);\r
+LIST *NewCancelList();\r
+void ReleaseCancelList(LIST *o);\r
+void AddCancelList(LIST *o, CANCEL *c);\r
+void CancelList(LIST *o);\r
+bool CompareNodeInfo(NODE_INFO *a, NODE_INFO *b);\r
+bool IsPriorityHighestPacketForQoS(void *data, UINT size);\r
+UINT GetNextDelayedPacketTickDiff(SESSION *s);\r
+\r
+#endif // SESSION_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/TcpIp.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/TcpIp.c
new file mode 100644 (file)
index 0000000..535f7c3
--- /dev/null
@@ -0,0 +1,1736 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// TcpIp.c\r
+// TCP/IP プロトコル パケットアナライザ\r
+\r
+#include "CedarPch.h"\r
+\r
+// パケットに VLAN タグを埋め込む\r
+void VLanInsertTag(void **packet_data, UINT *packet_size, UINT vlan_id)\r
+{\r
+       UINT dest_size;\r
+       UCHAR *dest_data;\r
+       UINT src_size;\r
+       UCHAR *src_data;\r
+       USHORT vlan_ushort = Endian16(((USHORT)vlan_id) & 0xFFF);\r
+       // 引数チェック\r
+       if (packet_data == NULL || *packet_data == NULL || packet_size == NULL ||\r
+               *packet_size < 14 || vlan_id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       src_size = *packet_size;\r
+       src_data = (UCHAR *)(*packet_data);\r
+\r
+       dest_size = src_size + 4;\r
+       dest_data = Malloc(dest_size);\r
+\r
+       dest_data[12] = 0x81;\r
+       dest_data[13] = 0x00;\r
+       Copy(&dest_data[14], &vlan_ushort, sizeof(USHORT));\r
+\r
+       Copy(&dest_data[0], &src_data[0], 12);\r
+       Copy(&dest_data[16], &src_data[12], src_size - 12);\r
+\r
+       *packet_size = dest_size;\r
+       *packet_data = dest_data;\r
+\r
+       Free(src_data);\r
+}\r
+\r
+// パケットから VLAN タグを取り除く\r
+bool VLanRemoveTag(void **packet_data, UINT *packet_size, UINT vlan_id)\r
+{\r
+       bool has_vlan_tag = false;\r
+       UCHAR *src_data;\r
+       UINT src_size;\r
+       // 引数チェック\r
+       if (packet_data == NULL || *packet_data == NULL || packet_size == NULL ||\r
+               *packet_size < 14)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       src_data = (UCHAR *)(*packet_data);\r
+       src_size = *packet_size;\r
+\r
+       if (src_data[12] == 0x81 && src_data[13] == 0x00)\r
+       {\r
+               if (src_size >= 18)\r
+               {\r
+                       USHORT vlan_ushort;\r
+\r
+                       vlan_ushort = Endian16(*((USHORT *)&src_data[14]));\r
+                       vlan_ushort = vlan_ushort & 0xFFF;\r
+\r
+                       if (vlan_id == 0 || (vlan_ushort == vlan_id))\r
+                       {\r
+                               UINT dest_size = src_size - 4;\r
+                               UINT i;\r
+\r
+                               for (i = 12;i < dest_size;i++)\r
+                               {\r
+                                       src_data[i] = src_data[i + 4];\r
+                               }\r
+\r
+                               *packet_size = dest_size;\r
+\r
+                               return true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// ICMPv6 パケットの送信\r
+BUF *BuildICMPv6(IPV6_ADDR *src_ip, IPV6_ADDR *dest_ip, UCHAR hop_limit, UCHAR type, UCHAR code, void *data, UINT size, UINT id)\r
+{\r
+       ICMP_HEADER *icmp;\r
+       void *data_buf;\r
+       BUF *ret;\r
+       // 引数チェック\r
+       if (src_ip == NULL || dest_ip == NULL || data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // ヘッダの組み立て\r
+       icmp = ZeroMalloc(sizeof(ICMP_HEADER) + size);\r
+       data_buf = ((UCHAR *)icmp) + sizeof(ICMP_HEADER);\r
+       Copy(data_buf, data, size);\r
+\r
+       icmp->Type = type;\r
+       icmp->Code = code;\r
+       icmp->Checksum = CalcChecksumForIPv6(src_ip, dest_ip, IP_PROTO_ICMPV6, icmp,\r
+               sizeof(ICMP_HEADER) + size);\r
+\r
+       ret = BuildIPv6(dest_ip, src_ip, id, IP_PROTO_ICMPV6, hop_limit, icmp,\r
+               sizeof(ICMP_HEADER) + size);\r
+\r
+       Free(icmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// ICMPv6 近隣要請パケットのビルド\r
+BUF *BuildICMPv6NeighborSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCHAR *my_mac_address, UINT id)\r
+{\r
+       ICMPV6_OPTION_LIST opt;\r
+       ICMPV6_OPTION_LINK_LAYER link;\r
+       ICMPV6_NEIGHBOR_SOLICIATION_HEADER header;\r
+       BUF *b;\r
+       BUF *b2;\r
+       BUF *ret;\r
+       // 引数チェック\r
+       if (src_ip == NULL || target_ip == NULL || my_mac_address == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&link, sizeof(link));\r
+       Copy(link.Address, my_mac_address, 6);\r
+\r
+       Zero(&opt, sizeof(opt));\r
+       opt.SourceLinkLayer = &link;\r
+\r
+       b = BuildICMPv6Options(&opt);\r
+\r
+       Zero(&header, sizeof(header));\r
+       Copy(&header.TargetAddress, target_ip, sizeof(IPV6_ADDR));\r
+\r
+       b2 = NewBuf();\r
+\r
+       WriteBuf(b2, &header, sizeof(header));\r
+       WriteBufBuf(b2, b);\r
+\r
+       ret = BuildICMPv6(src_ip, target_ip, 255,\r
+               ICMPV6_TYPE_NEIGHBOR_SOLICIATION, 0, b2->Buf, b2->Size, id);\r
+\r
+       FreeBuf(b);\r
+       FreeBuf(b2);\r
+\r
+       return ret;\r
+}\r
+\r
+// キューから次のヘッダ番号を取得\r
+UCHAR IPv6GetNextHeaderFromQueue(QUEUE *q)\r
+{\r
+       UINT *p;\r
+       UCHAR v;\r
+       // 引数チェック\r
+       if (q == NULL)\r
+       {\r
+               return IPV6_HEADER_NONE;\r
+       }\r
+\r
+       p = (UINT *)GetNext(q);\r
+       v = (UCHAR)(*p);\r
+       Free(p);\r
+\r
+       return v;\r
+}\r
+\r
+// IPv6 拡張オプションヘッダ (可変長) の追加\r
+void BuildAndAddIPv6PacketOptionHeader(BUF *b, IPV6_OPTION_HEADER *opt, UCHAR next_header, UINT size)\r
+{\r
+       IPV6_OPTION_HEADER *h;\r
+       UINT total_size;\r
+       // 引数チェック\r
+       if (b == NULL || opt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       total_size = size;\r
+       if ((total_size % 8) != 0)\r
+       {\r
+               total_size = ((total_size / 8) + 1) * 8;\r
+       }\r
+\r
+       h = ZeroMalloc(total_size);\r
+       Copy(h, opt, size);\r
+       h->Size = (total_size / 8) - 1;\r
+       h->NextHeader = next_header;\r
+\r
+       WriteBuf(b, h, total_size);\r
+\r
+       Free(h);\r
+}\r
+\r
+// IPv6 パケットのビルド\r
+BUF *BuildIPv6(IPV6_ADDR *dest_ip, IPV6_ADDR *src_ip, UINT id, UCHAR protocol, UCHAR hop_limit, void *data,\r
+                          UINT size)\r
+{\r
+       IPV6_HEADER_PACKET_INFO info;\r
+       IPV6_HEADER ip_header;\r
+       BUF *buf;\r
+       UINT size_for_headers;\r
+       // 引数チェック\r
+       if (dest_ip == NULL || src_ip == NULL || data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (hop_limit == 0)\r
+       {\r
+               hop_limit = 255;\r
+       }\r
+\r
+       // IPv6 ヘッダ\r
+       Zero(&ip_header, sizeof(ip_header));\r
+       IPV6_SET_VERSION(&ip_header, 6);\r
+       ip_header.HopLimit = hop_limit;\r
+       Copy(&ip_header.SrcAddress, src_ip, sizeof(IPV6_ADDR));\r
+       Copy(&ip_header.DestAddress, dest_ip, sizeof(IPV6_ADDR));\r
+\r
+       // ヘッダパケット情報の整理\r
+       Zero(&info, sizeof(info));\r
+       info.IPv6Header = &ip_header;\r
+       info.Protocol = protocol;\r
+       info.Payload = data;\r
+       info.PayloadSize = size;\r
+\r
+       buf = BuildIPv6PacketHeader(&info, &size_for_headers);\r
+       if (buf == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return buf;\r
+}\r
+\r
+// IPv6 パケットヘッダ部のビルド\r
+BUF *BuildIPv6PacketHeader(IPV6_HEADER_PACKET_INFO *info, UINT *bytes_before_payload)\r
+{\r
+       BUF *b;\r
+       QUEUE *q;\r
+       UINT bbp = 0;\r
+       // 引数チェック\r
+       if (info == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+       q = NewQueueFast();\r
+\r
+       // オプションヘッダの一覧を作成\r
+       if (info->HopHeader != NULL)\r
+       {\r
+               InsertQueueInt(q, IPV6_HEADER_HOP);\r
+       }\r
+       if (info->EndPointHeader != NULL)\r
+       {\r
+               InsertQueueInt(q, IPV6_HEADER_ENDPOINT);\r
+       }\r
+       if (info->RoutingHeader != NULL)\r
+       {\r
+               InsertQueueInt(q, IPV6_HEADER_ROUTING);\r
+       }\r
+       if (info->FragmentHeader != NULL)\r
+       {\r
+               InsertQueueInt(q, IPV6_HEADER_FRAGMENT);\r
+       }\r
+       InsertQueueInt(q, info->Protocol);\r
+\r
+       // IPv6 ヘッダ\r
+       info->IPv6Header->NextHeader = IPv6GetNextHeaderFromQueue(q);\r
+       WriteBuf(b, info->IPv6Header, sizeof(IPV6_HEADER));\r
+\r
+       // ホップバイホップオプションヘッダ\r
+       if (info->HopHeader != NULL)\r
+       {\r
+               BuildAndAddIPv6PacketOptionHeader(b, info->HopHeader,\r
+                       IPv6GetNextHeaderFromQueue(q), info->HopHeaderSize);\r
+       }\r
+\r
+       // 終点オプションヘッダ\r
+       if (info->EndPointHeader != NULL)\r
+       {\r
+               BuildAndAddIPv6PacketOptionHeader(b, info->EndPointHeader,\r
+                       IPv6GetNextHeaderFromQueue(q), info->EndPointHeaderSize);\r
+       }\r
+\r
+       // ルーティングヘッダ\r
+       if (info->RoutingHeader != NULL)\r
+       {\r
+               BuildAndAddIPv6PacketOptionHeader(b, info->RoutingHeader,\r
+                       IPv6GetNextHeaderFromQueue(q), info->RoutingHeaderSize);\r
+       }\r
+\r
+       // フラグメントヘッダ\r
+       if (info->FragmentHeader != NULL)\r
+       {\r
+               info->FragmentHeader->NextHeader = IPv6GetNextHeaderFromQueue(q);\r
+               WriteBuf(b, info->FragmentHeader, sizeof(IPV6_FRAGMENT_HEADER));\r
+       }\r
+\r
+       bbp = b->Size;\r
+       if (info->FragmentHeader == NULL)\r
+       {\r
+               bbp += sizeof(IPV6_FRAGMENT_HEADER);\r
+       }\r
+\r
+       // ペイロード\r
+       if (info->Protocol != IPV6_HEADER_NONE)\r
+       {\r
+               WriteBuf(b, info->Payload, info->PayloadSize);\r
+       }\r
+\r
+       ReleaseQueue(q);\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       // ペイロード長さ\r
+       ((IPV6_HEADER *)b->Buf)->PayloadLength = Endian16(b->Size - (USHORT)sizeof(IPV6_HEADER));\r
+\r
+       if (bytes_before_payload != NULL)\r
+       {\r
+               // ペイロードの直前までの長さ (ただしフラグメントヘッダは必ず含まれると仮定)\r
+               // を計算する\r
+               *bytes_before_payload = bbp;\r
+       }\r
+\r
+       return b;\r
+}\r
+\r
+// ICMPv6 パケットのオプション値のビルド\r
+void BuildICMPv6OptionValue(BUF *b, UCHAR type, void *header_pointer, UINT total_size)\r
+{\r
+       UINT packet_size;\r
+       UCHAR *packet;\r
+       ICMPV6_OPTION *opt;\r
+       // 引数チェック\r
+       if (b == NULL || header_pointer == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       packet_size = ((total_size + 7) / 8) * 8;\r
+       packet = ZeroMalloc(packet_size);\r
+\r
+       Copy(packet, header_pointer, total_size);\r
+       opt = (ICMPV6_OPTION *)packet;\r
+       opt->Length = (UCHAR)(packet_size / 8);\r
+       opt->Type = type;\r
+\r
+       WriteBuf(b, packet, packet_size);\r
+\r
+       Free(packet);\r
+}\r
+\r
+// ICMPv6 パケットのオプションのビルド\r
+BUF *BuildICMPv6Options(ICMPV6_OPTION_LIST *o)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+\r
+       if (o->SourceLinkLayer != NULL)\r
+       {\r
+               BuildICMPv6OptionValue(b, ICMPV6_OPTION_TYPE_SOURCE_LINK_LAYER, o->SourceLinkLayer, sizeof(ICMPV6_OPTION_LINK_LAYER));\r
+       }\r
+       if (o->TargetLinkLayer != NULL)\r
+       {\r
+               BuildICMPv6OptionValue(b, ICMPV6_OPTION_TYPE_TARGET_LINK_LAYER, o->TargetLinkLayer, sizeof(ICMPV6_OPTION_LINK_LAYER));\r
+       }\r
+       if (o->Prefix != NULL)\r
+       {\r
+               BuildICMPv6OptionValue(b, ICMPV6_OPTION_TYPE_PREFIX, o->Prefix, sizeof(ICMPV6_OPTION_PREFIX));\r
+       }\r
+       if (o->Mtu != NULL)\r
+       {\r
+               BuildICMPv6OptionValue(b, ICMPV6_OPTION_TYPE_MTU, o->Mtu, sizeof(ICMPV6_OPTION_MTU));\r
+       }\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       return b;\r
+}\r
+\r
+// チェックサム計算\r
+USHORT CalcChecksumForIPv6(IPV6_ADDR *src_ip, IPV6_ADDR *dest_ip, UCHAR protocol, void *data, UINT size)\r
+{\r
+       UCHAR *tmp;\r
+       UINT tmp_size;\r
+       IPV6_PSEUDO_HEADER *ph;\r
+       USHORT ret;\r
+       // 引数チェック\r
+       if (data == NULL && size != 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       tmp_size = size + sizeof(IPV6_PSEUDO_HEADER);\r
+       tmp = ZeroMalloc(tmp_size);\r
+\r
+       ph = (IPV6_PSEUDO_HEADER *)tmp;\r
+       Copy(&ph->SrcAddress, src_ip, sizeof(IPV6_ADDR));\r
+       Copy(&ph->DestAddress, dest_ip, sizeof(IPV6_ADDR));\r
+       ph->UpperLayerPacketSize = Endian32(size);\r
+       ph->NextHeader = protocol;\r
+\r
+       Copy(((UCHAR *)tmp) + sizeof(IPV6_PSEUDO_HEADER), data, size);\r
+\r
+       ret = IpChecksum(tmp, tmp_size);\r
+\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// クローンされたパケットを解放する\r
+void FreeClonePacket(PKT *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(p->IPv6HeaderPacketInfo.IPv6Header);\r
+       Free(p->IPv6HeaderPacketInfo.HopHeader);\r
+       Free(p->IPv6HeaderPacketInfo.EndPointHeader);\r
+       Free(p->IPv6HeaderPacketInfo.RoutingHeader);\r
+       Free(p->IPv6HeaderPacketInfo.FragmentHeader);\r
+       Free(p->IPv6HeaderPacketInfo.Payload);\r
+       Free(p->ICMPv6HeaderPacketInfo.Data);\r
+       Free(p->ICMPv6HeaderPacketInfo.EchoData);\r
+       Free(p->ICMPv6HeaderPacketInfo.Headers.HeaderPointer);\r
+       FreeCloneICMPv6Options(&p->ICMPv6HeaderPacketInfo.OptionList);\r
+       Free(p->L3.PointerL3);\r
+       Free(p->L4.PointerL4);\r
+       Free(p->L7.PointerL7);\r
+       Free(p->PacketData);\r
+       Free(p->MacHeader);\r
+       Free(p);\r
+}\r
+\r
+// パケットヘッダをコピーする\r
+PKT *ClonePacket(PKT *p, bool copy_data)\r
+{\r
+       PKT *ret;\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMallocFast(sizeof(PKT));\r
+       ret->PacketSize = p->PacketSize;\r
+\r
+       // MAC ヘッダのコピー\r
+       ret->MacHeader = MallocFast(sizeof(MAC_HEADER));\r
+       Copy(ret->MacHeader, p->MacHeader, sizeof(MAC_HEADER));\r
+\r
+       // MAC フラグのコピー\r
+       ret->BroadcastPacket = p->BroadcastPacket;\r
+       ret->InvalidSourcePacket = p->InvalidSourcePacket;\r
+\r
+       // IPv6 関係構造体のコピー\r
+       Copy(&ret->IPv6HeaderPacketInfo, &p->IPv6HeaderPacketInfo, sizeof(IPV6_HEADER_PACKET_INFO));\r
+       Copy(&ret->ICMPv6HeaderPacketInfo, &p->ICMPv6HeaderPacketInfo, sizeof(ICMPV6_HEADER_INFO));\r
+\r
+       // Layer 3\r
+       ret->TypeL3 = p->TypeL3;\r
+       switch (ret->TypeL3)\r
+       {\r
+       case L3_ARPV4:\r
+               // ARP パケット\r
+               ret->L3.ARPv4Header = MallocFast(sizeof(ARPV4_HEADER));\r
+               Copy(ret->L3.ARPv4Header, p->L3.ARPv4Header, sizeof(ARPV4_HEADER));\r
+               break;\r
+\r
+       case L3_IPV4:\r
+               // IPv4 パケット\r
+               ret->L3.IPv4Header = MallocFast(sizeof(IPV4_HEADER));\r
+               Copy(ret->L3.IPv4Header, p->L3.IPv4Header, sizeof(IPV4_HEADER));\r
+               break;\r
+\r
+       case L3_IPV6:\r
+               // IPv6 パケット\r
+               ret->L3.IPv6Header = MallocFast(sizeof(IPV6_HEADER));\r
+               Copy(ret->L3.IPv6Header, p->L3.IPv6Header, sizeof(IPV6_HEADER));\r
+\r
+               ret->IPv6HeaderPacketInfo.IPv6Header = Clone(p->IPv6HeaderPacketInfo.IPv6Header,\r
+                       sizeof(IPV6_HEADER));\r
+\r
+               ret->IPv6HeaderPacketInfo.HopHeader = Clone(p->IPv6HeaderPacketInfo.HopHeader,\r
+                       sizeof(IPV6_OPTION_HEADER));\r
+\r
+               ret->IPv6HeaderPacketInfo.EndPointHeader = Clone(p->IPv6HeaderPacketInfo.EndPointHeader,\r
+                       sizeof(IPV6_OPTION_HEADER));\r
+\r
+               ret->IPv6HeaderPacketInfo.RoutingHeader = Clone(p->IPv6HeaderPacketInfo.RoutingHeader,\r
+                       sizeof(IPV6_OPTION_HEADER));\r
+\r
+               ret->IPv6HeaderPacketInfo.FragmentHeader = Clone(p->IPv6HeaderPacketInfo.FragmentHeader,\r
+                       sizeof(IPV6_FRAGMENT_HEADER));\r
+\r
+               ret->IPv6HeaderPacketInfo.Payload = Clone(p->IPv6HeaderPacketInfo.Payload,\r
+                       p->IPv6HeaderPacketInfo.PayloadSize);\r
+               break;\r
+       }\r
+\r
+       // Layer 4\r
+       ret->TypeL4 = p->TypeL4;\r
+       switch (ret->TypeL4)\r
+       {\r
+       case L4_ICMPV4:\r
+               // ICMPv4 パケット\r
+               ret->L4.ICMPHeader = MallocFast(sizeof(ICMP_HEADER));\r
+               Copy(ret->L4.ICMPHeader, p->L4.ICMPHeader, sizeof(ICMP_HEADER));\r
+               break;\r
+\r
+       case L4_ICMPV6:\r
+               // ICMPv6 パケット\r
+               ret->L4.ICMPHeader = MallocFast(sizeof(ICMP_HEADER));\r
+               Copy(ret->L4.ICMPHeader, p->L4.ICMPHeader, sizeof(ICMP_HEADER));\r
+\r
+               ret->ICMPv6HeaderPacketInfo.Data = Clone(p->ICMPv6HeaderPacketInfo.Data,\r
+                       p->ICMPv6HeaderPacketInfo.DataSize);\r
+\r
+               ret->ICMPv6HeaderPacketInfo.EchoData = Clone(p->ICMPv6HeaderPacketInfo.EchoData,\r
+                       p->ICMPv6HeaderPacketInfo.EchoDataSize);\r
+\r
+               switch (ret->ICMPv6HeaderPacketInfo.Type)\r
+               {\r
+               case ICMPV6_TYPE_ECHO_REQUEST:\r
+               case ICMPV6_TYPE_ECHO_RESPONSE:\r
+                       break;\r
+\r
+               case ICMPV6_TYPE_ROUTER_SOLICIATION:\r
+                       ret->ICMPv6HeaderPacketInfo.Headers.RouterSoliciationHeader =\r
+                               Clone(p->ICMPv6HeaderPacketInfo.Headers.RouterSoliciationHeader,\r
+                               sizeof(ICMPV6_ROUTER_SOLICIATION_HEADER));\r
+                       break;\r
+\r
+               case ICMPV6_TYPE_ROUTER_ADVERTISEMENT:\r
+                       ret->ICMPv6HeaderPacketInfo.Headers.RouterAdvertisementHeader =\r
+                               Clone(p->ICMPv6HeaderPacketInfo.Headers.RouterAdvertisementHeader,\r
+                               sizeof(ICMPV6_ROUTER_ADVERTISEMENT_HEADER));\r
+                       break;\r
+\r
+               case ICMPV6_TYPE_NEIGHBOR_SOLICIATION:\r
+                       ret->ICMPv6HeaderPacketInfo.Headers.NeighborSoliciationHeader =\r
+                               Clone(p->ICMPv6HeaderPacketInfo.Headers.NeighborSoliciationHeader,\r
+                               sizeof(ICMPV6_NEIGHBOR_SOLICIATION_HEADER));\r
+                       break;\r
+\r
+               case ICMPV6_TYPE_NEIGHBOR_ADVERTISEMENT:\r
+                       ret->ICMPv6HeaderPacketInfo.Headers.NeighborAdvertisementHeader =\r
+                               Clone(p->ICMPv6HeaderPacketInfo.Headers.NeighborAdvertisementHeader,\r
+                               sizeof(ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER));\r
+                       break;\r
+               }\r
+\r
+               CloneICMPv6Options(&ret->ICMPv6HeaderPacketInfo.OptionList,\r
+                       &p->ICMPv6HeaderPacketInfo.OptionList);\r
+               break;\r
+\r
+       case L4_TCP:\r
+               // TCP パケット\r
+               ret->L4.TCPHeader = MallocFast(sizeof(TCP_HEADER));\r
+               Copy(ret->L4.TCPHeader, p->L4.TCPHeader, sizeof(TCP_HEADER));\r
+               break;\r
+\r
+       case L4_UDP:\r
+               // UDP パケット\r
+               ret->L4.UDPHeader = MallocFast(sizeof(UDP_HEADER));\r
+               Copy(ret->L4.UDPHeader, p->L4.UDPHeader, sizeof(UDP_HEADER));\r
+               break;\r
+       }\r
+\r
+       // Layer 7\r
+       ret->TypeL7 = p->TypeL7;\r
+       switch (ret->TypeL7)\r
+       {\r
+       case L7_DHCPV4:\r
+               // DHCP パケット\r
+               ret->L7.DHCPv4Header = MallocFast(sizeof(DHCPV4_HEADER));\r
+               Copy(ret->L7.DHCPv4Header, p->L7.DHCPv4Header, sizeof(DHCPV4_HEADER));\r
+               break;\r
+       }\r
+\r
+       // アドレスデータ\r
+       ret->MacAddressSrc = ret->MacHeader->SrcAddress;\r
+       ret->MacAddressDest = ret->MacHeader->DestAddress;\r
+\r
+       if (copy_data)\r
+       {\r
+               // パケット本体もコピー\r
+               ret->PacketData = MallocFast(p->PacketSize);\r
+               Copy(ret->PacketData, p->PacketData, p->PacketSize);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// パケットの中身をパースする\r
+PKT *ParsePacket(UCHAR *buf, UINT size)\r
+{\r
+       return ParsePacketEx(buf, size, false);\r
+}\r
+PKT *ParsePacketEx(UCHAR *buf, UINT size, bool no_l3)\r
+{\r
+       return ParsePacketEx2(buf, size, no_l3, 0);\r
+}\r
+PKT *ParsePacketEx2(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id)\r
+{\r
+       return ParsePacketEx3(buf, size, no_l3, vlan_type_id, true);\r
+}\r
+PKT *ParsePacketEx3(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id, bool bridge_id_as_mac_address)\r
+{\r
+       PKT *p;\r
+       // 引数チェック\r
+       if (buf == NULL || size == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (vlan_type_id == 0)\r
+       {\r
+               vlan_type_id = MAC_PROTO_TAGVLAN;\r
+       }\r
+\r
+       p = ZeroMallocFast(sizeof(PKT));\r
+\r
+       p->VlanTypeID = vlan_type_id;\r
+\r
+       // パース実行\r
+       if (ParsePacketL2Ex(p, buf, size, no_l3) == false)\r
+       {\r
+               // パース失敗\r
+               FreePacket(p);\r
+               return NULL;\r
+       }\r
+\r
+       p->PacketData = buf;\r
+       p->PacketSize = size;\r
+\r
+       p->MacAddressSrc = p->MacHeader->SrcAddress;\r
+       p->MacAddressDest = p->MacHeader->DestAddress;\r
+\r
+       if (bridge_id_as_mac_address)\r
+       {\r
+               if (p->TypeL3 == L3_BPDU)\r
+               {\r
+                       if (p->L3.BpduHeader != NULL)\r
+                       {\r
+                               p->MacAddressSrc = p->L3.BpduHeader->BridgeMacAddress;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // パース成功\r
+       return p;\r
+}\r
+\r
+\r
+// Layer-2 パース\r
+bool ParsePacketL2(PKT *p, UCHAR *buf, UINT size)\r
+{\r
+       return ParsePacketL2Ex(p, buf, size, false);\r
+}\r
+bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3)\r
+{\r
+       UINT i;\r
+       bool b1, b2;\r
+       USHORT type_id_16;\r
+       // 引数チェック\r
+       if (p == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // サイズをチェック\r
+       if (size < sizeof(MAC_HEADER))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // MAC ヘッダ\r
+       p->MacHeader = (MAC_HEADER *)buf;\r
+\r
+       buf += sizeof(MAC_HEADER);\r
+       size -= sizeof(MAC_HEADER);\r
+\r
+       // MAC ヘッダの解析\r
+       p->BroadcastPacket = true;\r
+       b1 = true;\r
+       b2 = true;\r
+       for (i = 0;i < 6;i++)\r
+       {\r
+               if (p->MacHeader->DestAddress[i] != 0xff)\r
+               {\r
+                       p->BroadcastPacket = false;\r
+               }\r
+               if (p->MacHeader->SrcAddress[i] != 0xff)\r
+               {\r
+                       b1 = false;\r
+               }\r
+               if (p->MacHeader->SrcAddress[i] != 0x00)\r
+               {\r
+                       b2 = false;\r
+               }\r
+       }\r
+       if (b1 || b2 || (Cmp(p->MacHeader->SrcAddress, p->MacHeader->DestAddress, 6) == 0))\r
+       {\r
+               p->InvalidSourcePacket = true;\r
+       }\r
+       else\r
+       {\r
+               p->InvalidSourcePacket = false;\r
+       }\r
+\r
+       if (p->MacHeader->DestAddress[0] & 0x01)\r
+       {\r
+               p->BroadcastPacket = true;\r
+       }\r
+\r
+       // L3 パケットのパース\r
+       type_id_16 = Endian16(p->MacHeader->Protocol);\r
+\r
+       if (type_id_16 > 1500)\r
+       {\r
+               // 通常の Ethernet フレーム\r
+               switch (type_id_16)\r
+               {\r
+               case MAC_PROTO_ARPV4:   // ARPv4\r
+                       if (no_l3)\r
+                       {\r
+                               return true;\r
+                       }\r
+\r
+                       return ParsePacketARPv4(p, buf, size);\r
+\r
+               case MAC_PROTO_IPV4:    // IPv4\r
+                       if (no_l3)\r
+                       {\r
+                               return true;\r
+                       }\r
+\r
+                       return ParsePacketIPv4(p, buf, size);\r
+\r
+               case MAC_PROTO_IPV6:    // IPv6\r
+                       if (no_l3)\r
+                       {\r
+                               return true;\r
+                       }\r
+\r
+                       return ParsePacketIPv6(p, buf, size);\r
+\r
+               default:                                // 不明\r
+                       if (type_id_16 == p->VlanTypeID)\r
+                       {\r
+                               // VLAN\r
+                               return ParsePacketTAGVLAN(p, buf, size);\r
+                       }\r
+                       else\r
+                       {\r
+                               return true;\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // IEEE 802.3 の古い (パケットのペイロード長が書いてある) フレーム\r
+               // (BPDU 等で使われていることがある)\r
+               UINT length = (UINT)type_id_16;\r
+               LLC_HEADER *llc;\r
+\r
+               // 長さが残っているかどうかチェック\r
+               if (size < length || size < sizeof(LLC_HEADER))\r
+               {\r
+                       return true;\r
+               }\r
+\r
+               // LLC ヘッダを読む\r
+               llc = (LLC_HEADER *)buf;\r
+               buf += sizeof(LLC_HEADER);\r
+               size -= sizeof(LLC_HEADER);\r
+\r
+               // DSAP, SSAP の値によってプロトコルを判定する\r
+               if (llc->Dsap == LLC_DSAP_BPDU && llc->Ssap == LLC_SSAP_BPDU)\r
+               {\r
+                       // BPDU (Spanning Tree) である\r
+                       return ParsePacketBPDU(p, buf, size);\r
+               }\r
+               else\r
+               {\r
+                       // 不明なプロトコルである\r
+                       return true;\r
+               }\r
+       }\r
+}\r
+\r
+// TAG VLAN パース\r
+bool ParsePacketTAGVLAN(PKT *p, UCHAR *buf, UINT size)\r
+{\r
+       USHORT vlan_ushort;\r
+       // 引数チェック\r
+       if (p == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // サイズをチェック\r
+       if (size < sizeof(TAGVLAN_HEADER))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // TAG VLAN ヘッダ\r
+       p->L3.TagVlanHeader = (TAGVLAN_HEADER *)buf;\r
+       p->TypeL3 = L3_TAGVLAN;\r
+\r
+       buf += sizeof(TAGVLAN_HEADER);\r
+       size -= sizeof(TAGVLAN_HEADER);\r
+\r
+       vlan_ushort = Endian16(*((USHORT *)p->L3.TagVlanHeader->Data));\r
+       vlan_ushort = vlan_ushort & 0xFFF;\r
+\r
+       p->VlanId = vlan_ushort;\r
+\r
+       return true;\r
+}\r
+\r
+// BPDU パース\r
+bool ParsePacketBPDU(PKT *p, UCHAR *buf, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // サイズをチェック\r
+       if (size < sizeof(BPDU_HEADER))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       // BPDU ヘッダ\r
+       p->L3.BpduHeader = (BPDU_HEADER *)buf;\r
+       p->TypeL3 = L3_BPDU;\r
+\r
+       buf += sizeof(BPDU_HEADER);\r
+       size -= sizeof(BPDU_HEADER);\r
+\r
+       return true;\r
+}\r
+\r
+// ARPv4 パース\r
+bool ParsePacketARPv4(PKT *p, UCHAR *buf, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // サイズをチェック\r
+       if (size < sizeof(ARPV4_HEADER))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ARPv4 ヘッダ\r
+       p->L3.ARPv4Header = (ARPV4_HEADER *)buf;\r
+       p->TypeL3 = L3_ARPV4;\r
+\r
+       buf += sizeof(ARPV4_HEADER);\r
+       size -= sizeof(ARPV4_HEADER);\r
+\r
+       return true;\r
+}\r
+\r
+// IPv6 拡張ヘッダの解析\r
+bool ParseIPv6ExtHeader(IPV6_HEADER_PACKET_INFO *info, UCHAR next_header, UCHAR *buf, UINT size)\r
+{\r
+       bool ret = false;\r
+       IPV6_OPTION_HEADER *option_header;\r
+       UINT option_header_size;\r
+       UCHAR next_header_2 = IPV6_HEADER_NONE;\r
+       // 引数チェック\r
+       if (info == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       info->IsFragment = false;\r
+\r
+       while (true)\r
+       {\r
+               if (size > 8)\r
+               {\r
+                       next_header_2 = *((UCHAR *)buf);\r
+               }\r
+\r
+               switch (next_header)\r
+               {\r
+               case IPV6_HEADER_HOP:\r
+               case IPV6_HEADER_ENDPOINT:\r
+               case IPV6_HEADER_ROUTING:\r
+                       // 可変長ヘッダ\r
+                       if (size < 8)\r
+                       {\r
+                               return false;\r
+                       }\r
+\r
+                       option_header = (IPV6_OPTION_HEADER *)buf;\r
+                       option_header_size = (option_header->Size + 1) * 8;\r
+                       if (size < option_header_size)\r
+                       {\r
+                               return false;\r
+                       }\r
+\r
+                       switch (next_header)\r
+                       {\r
+                       case IPV6_HEADER_HOP:\r
+                               info->HopHeader = (IPV6_OPTION_HEADER *)buf;\r
+                               info->HopHeaderSize = option_header_size;\r
+                               break;\r
+\r
+                       case IPV6_HEADER_ENDPOINT:\r
+                               info->EndPointHeader = (IPV6_OPTION_HEADER *)buf;\r
+                               info->EndPointHeaderSize = option_header_size;\r
+                               break;\r
+\r
+                       case IPV6_HEADER_ROUTING:\r
+                               info->RoutingHeader = (IPV6_OPTION_HEADER *)buf;\r
+                               info->RoutingHeaderSize = option_header_size;\r
+                               break;\r
+                       }\r
+\r
+                       buf += option_header_size;\r
+                       size -= option_header_size;\r
+                       break;\r
+\r
+               case IPV6_HEADER_FRAGMENT:\r
+                       // フラグメントヘッダ (固定長)\r
+                       if (size < sizeof(IPV6_FRAGMENT_HEADER))\r
+                       {\r
+                               return false;\r
+                       }\r
+\r
+                       info->FragmentHeader = (IPV6_FRAGMENT_HEADER *)buf;\r
+\r
+                       if (IPV6_GET_FRAGMENT_OFFSET(info->FragmentHeader) != 0)\r
+                       {\r
+                               info->IsFragment = true;\r
+                       }\r
+\r
+                       buf += sizeof(IPV6_FRAGMENT_HEADER);\r
+                       size -= sizeof(IPV6_FRAGMENT_HEADER);\r
+                       break;\r
+\r
+               default:\r
+                       // 後にペイロードが続くとみなす\r
+                       if (next_header != IPV6_HEADER_NONE)\r
+                       {\r
+                               info->Payload = buf;\r
+                               info->PayloadSize = size;\r
+                       }\r
+                       else\r
+                       {\r
+                               info->Payload = NULL;\r
+                               info->PayloadSize = 0;\r
+                       }\r
+                       info->Protocol = next_header;\r
+                       return true;\r
+               }\r
+\r
+               next_header = next_header_2;\r
+       }\r
+}\r
+\r
+// IPv6 ヘッダの解析\r
+bool ParsePacketIPv6Header(IPV6_HEADER_PACKET_INFO *info, UCHAR *buf, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (info == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(info, sizeof(IPV6_HEADER_PACKET_INFO));\r
+\r
+       // IPv6 ヘッダ\r
+       if (size < sizeof(IPV6_HEADER))\r
+       {\r
+               // サイズ不正\r
+               return false;\r
+       }\r
+\r
+       info->IPv6Header = (IPV6_HEADER *)buf;\r
+       buf += sizeof(IPV6_HEADER);\r
+       size -= sizeof(IPV6_HEADER);\r
+\r
+       if (IPV6_GET_VERSION(info->IPv6Header) != 6)\r
+       {\r
+               // バージョン不正\r
+               return false;\r
+       }\r
+\r
+       // 拡張ヘッダの解析\r
+       return ParseIPv6ExtHeader(info, info->IPv6Header->NextHeader, buf, size);\r
+}\r
+\r
+// ICMPv6 パケットのオプションの解析\r
+bool ParseICMPv6Options(ICMPV6_OPTION_LIST *o, UCHAR *buf, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(o, sizeof(ICMPV6_OPTION_LIST));\r
+\r
+       // ヘッダ部分の読み込み\r
+       while (true)\r
+       {\r
+               ICMPV6_OPTION *option_header;\r
+               UINT header_total_size;\r
+               UCHAR *header_pointer;\r
+               if (size < sizeof(ICMPV6_OPTION))\r
+               {\r
+                       // サイズ不足\r
+                       return true;\r
+               }\r
+\r
+               option_header = (ICMPV6_OPTION *)buf;\r
+               // ヘッダ全体サイズの計算\r
+               header_total_size = option_header->Length * 8;\r
+               if (header_total_size == 0)\r
+               {\r
+                       // サイズがゼロ\r
+                       return true;\r
+               }\r
+               if (size < header_total_size)\r
+               {\r
+                       // サイズ不足\r
+                       return true;\r
+               }\r
+\r
+               header_pointer = buf;\r
+               buf += header_total_size;\r
+               size -= header_total_size;\r
+\r
+               switch (option_header->Type)\r
+               {\r
+               case ICMPV6_OPTION_TYPE_SOURCE_LINK_LAYER:\r
+               case ICMPV6_OPTION_TYPE_TARGET_LINK_LAYER:\r
+                       // ソース or ターゲットリンクレイヤオプション\r
+                       if (header_total_size >= sizeof(ICMPV6_OPTION_LINK_LAYER))\r
+                       {\r
+                               if (option_header->Type == ICMPV6_OPTION_TYPE_SOURCE_LINK_LAYER)\r
+                               {\r
+                                       o->SourceLinkLayer = (ICMPV6_OPTION_LINK_LAYER *)header_pointer;\r
+                               }\r
+                               else\r
+                               {\r
+                                       o->TargetLinkLayer = (ICMPV6_OPTION_LINK_LAYER *)header_pointer;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // ICMPv6 パケット破損?\r
+                               return false;\r
+                       }\r
+                       break;\r
+\r
+               case ICMPV6_OPTION_TYPE_PREFIX:\r
+                       // プレフィックス情報\r
+                       if (header_total_size >= sizeof(ICMPV6_OPTION_PREFIX))\r
+                       {\r
+                               o->Prefix = (ICMPV6_OPTION_PREFIX *)header_pointer;\r
+                       }\r
+                       else\r
+                       {\r
+                               // ICMPv6 パケット破損?\r
+                       }\r
+                       break;\r
+\r
+               case ICMPV6_OPTION_TYPE_MTU:\r
+                       // MTU\r
+                       if (header_total_size >= sizeof(ICMPV6_OPTION_MTU))\r
+                       {\r
+                               o->Mtu = (ICMPV6_OPTION_MTU *)header_pointer;\r
+                       }\r
+                       else\r
+                       {\r
+                               // ICMPv6 パケット破損?\r
+                       }\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// ICMPv6 パース\r
+bool ParseICMPv6(PKT *p, UCHAR *buf, UINT size)\r
+{\r
+       ICMPV6_HEADER_INFO icmp_info;\r
+       ICMP_HEADER *icmp;\r
+       ICMP_ECHO *echo;\r
+       UINT msg_size;\r
+       // 引数チェック\r
+       if (p == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&icmp_info, sizeof(icmp_info));\r
+\r
+       if (size < sizeof(ICMP_HEADER))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       icmp = (ICMP_HEADER *)buf;\r
+       p->L4.ICMPHeader = icmp;\r
+\r
+       msg_size = size - sizeof(ICMP_HEADER);\r
+\r
+       icmp_info.Type = icmp->Type;\r
+       icmp_info.Code = icmp->Code;\r
+       icmp_info.Data = ((UCHAR *)buf) + sizeof(ICMP_HEADER);\r
+       icmp_info.DataSize = msg_size;\r
+\r
+       switch (icmp_info.Type)\r
+       {\r
+       case ICMPV6_TYPE_ECHO_REQUEST:\r
+       case ICMPV6_TYPE_ECHO_RESPONSE:\r
+               // ICMP Echo Request / Response\r
+               if (icmp_info.DataSize < sizeof(ICMP_ECHO))\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               echo = (ICMP_ECHO *)icmp_info.Data;\r
+\r
+               icmp_info.EchoHeader.Identifier = Endian16(echo->Identifier);\r
+               icmp_info.EchoHeader.SeqNo = Endian16(echo->SeqNo);\r
+               icmp_info.EchoData = (UCHAR *)echo + sizeof(ICMP_ECHO);\r
+               icmp_info.EchoDataSize = icmp_info.DataSize - sizeof(ICMP_ECHO);\r
+\r
+               break;\r
+\r
+       case ICMPV6_TYPE_ROUTER_SOLICIATION:\r
+               // ルータ要請\r
+               if (icmp_info.DataSize < sizeof(ICMPV6_ROUTER_SOLICIATION_HEADER))\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               icmp_info.Headers.RouterSoliciationHeader =\r
+                       (ICMPV6_ROUTER_SOLICIATION_HEADER *)(((UCHAR *)icmp_info.Data));\r
+\r
+               if (ParseICMPv6Options(&icmp_info.OptionList, ((UCHAR *)icmp_info.Headers.HeaderPointer) + sizeof(ICMPV6_ROUTER_SOLICIATION_HEADER),\r
+                       icmp_info.DataSize - sizeof(ICMPV6_ROUTER_SOLICIATION_HEADER)) == false)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               break;\r
+\r
+       case ICMPV6_TYPE_ROUTER_ADVERTISEMENT:\r
+               // ルータ広告\r
+               if (icmp_info.DataSize < sizeof(ICMPV6_ROUTER_ADVERTISEMENT_HEADER))\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               icmp_info.Headers.RouterAdvertisementHeader =\r
+                       (ICMPV6_ROUTER_ADVERTISEMENT_HEADER *)(((UCHAR *)icmp_info.Data));\r
+\r
+               if (ParseICMPv6Options(&icmp_info.OptionList, ((UCHAR *)icmp_info.Headers.HeaderPointer) + sizeof(ICMPV6_ROUTER_ADVERTISEMENT_HEADER),\r
+                       icmp_info.DataSize - sizeof(ICMPV6_ROUTER_ADVERTISEMENT_HEADER)) == false)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               break;\r
+\r
+       case ICMPV6_TYPE_NEIGHBOR_SOLICIATION:\r
+               // 近隣要請\r
+               if (icmp_info.DataSize < sizeof(ICMPV6_NEIGHBOR_SOLICIATION_HEADER))\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               icmp_info.Headers.NeighborSoliciationHeader =\r
+                       (ICMPV6_NEIGHBOR_SOLICIATION_HEADER *)(((UCHAR *)icmp_info.Data));\r
+\r
+               if (ParseICMPv6Options(&icmp_info.OptionList, ((UCHAR *)icmp_info.Headers.HeaderPointer) + sizeof(ICMPV6_NEIGHBOR_SOLICIATION_HEADER),\r
+                       icmp_info.DataSize - sizeof(ICMPV6_NEIGHBOR_SOLICIATION_HEADER)) == false)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               break;\r
+\r
+       case ICMPV6_TYPE_NEIGHBOR_ADVERTISEMENT:\r
+               // 近隣広告\r
+               if (icmp_info.DataSize < sizeof(ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER))\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               icmp_info.Headers.NeighborAdvertisementHeader =\r
+                       (ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER *)(((UCHAR *)icmp_info.Data));\r
+\r
+               if (ParseICMPv6Options(&icmp_info.OptionList, ((UCHAR *)icmp_info.Headers.HeaderPointer) + sizeof(ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER),\r
+                       icmp_info.DataSize - sizeof(ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER)) == false)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               break;\r
+       }\r
+\r
+       p->TypeL4 = L4_ICMPV6;\r
+       Copy(&p->ICMPv6HeaderPacketInfo, &icmp_info, sizeof(ICMPV6_HEADER_INFO));\r
+\r
+       return true;\r
+}\r
+\r
+// ICMPv6 オプションの解放\r
+void FreeCloneICMPv6Options(ICMPV6_OPTION_LIST *o)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(o->SourceLinkLayer);\r
+       Free(o->TargetLinkLayer);\r
+       Free(o->Prefix);\r
+       Free(o->Mtu);\r
+}\r
+\r
+// ICMPv6 オプションのクローン\r
+void CloneICMPv6Options(ICMPV6_OPTION_LIST *dst, ICMPV6_OPTION_LIST *src)\r
+{\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(dst, sizeof(ICMPV6_OPTION_LIST));\r
+\r
+       dst->SourceLinkLayer = Clone(src->SourceLinkLayer, sizeof(ICMPV6_OPTION_LINK_LAYER));\r
+       dst->TargetLinkLayer = Clone(src->TargetLinkLayer, sizeof(ICMPV6_OPTION_LINK_LAYER));\r
+       dst->Prefix = Clone(src->Prefix, sizeof(ICMPV6_OPTION_PREFIX));\r
+       dst->Mtu = Clone(src->Mtu, sizeof(ICMPV6_OPTION_MTU));\r
+}\r
+\r
+// IPv6 パース\r
+bool ParsePacketIPv6(PKT *p, UCHAR *buf, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ParsePacketIPv6Header(&p->IPv6HeaderPacketInfo, buf, size) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p->TypeL3 = L3_IPV6;\r
+       p->L3.IPv6Header = p->IPv6HeaderPacketInfo.IPv6Header;\r
+\r
+       if (p->IPv6HeaderPacketInfo.Payload == NULL)\r
+       {\r
+               // ペイロードなし\r
+               return true;\r
+       }\r
+\r
+       buf = p->IPv6HeaderPacketInfo.Payload;\r
+       size = p->IPv6HeaderPacketInfo.PayloadSize;\r
+\r
+       if (p->IPv6HeaderPacketInfo.IsFragment)\r
+       {\r
+               // フラグメントパケットであるからこれ以上解釈しない\r
+               p->TypeL4 = L4_FRAGMENT;\r
+               return true;\r
+       }\r
+\r
+       // L4 パケットのパース\r
+       switch (p->IPv6HeaderPacketInfo.Protocol)\r
+       {\r
+       case IP_PROTO_ICMPV6:   // ICMPv6\r
+               if (ParseICMPv6(p, buf, size) == false)\r
+               {\r
+                       // ICMPv6 のパースに失敗しても true を返す\r
+                       return true;\r
+               }\r
+               else\r
+               {\r
+                       return true;\r
+               }\r
+\r
+       case IP_PROTO_TCP:              // TCP\r
+               return ParseTCP(p, buf, size);\r
+\r
+       case IP_PROTO_UDP:              // UDP\r
+               return ParseUDP(p, buf, size);\r
+\r
+       default:                                // 不明\r
+               return true;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// IPv4 パース\r
+bool ParsePacketIPv4(PKT *p, UCHAR *buf, UINT size)\r
+{\r
+       UINT header_size;\r
+       // 引数チェック\r
+       if (p == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // サイズをチェック\r
+       if (size < sizeof(IPV4_HEADER))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // IPv4 ヘッダ\r
+       p->L3.IPv4Header = (IPV4_HEADER *)buf;\r
+       p->TypeL3 = L3_IPV4;\r
+\r
+       // ヘッダのチェック\r
+       header_size = IPV4_GET_HEADER_LEN(p->L3.IPv4Header) * 4;\r
+       if (header_size < sizeof(IPV4_HEADER) || size < header_size)\r
+       {\r
+               // ヘッダサイズが不正\r
+               p->L3.IPv4Header = NULL;\r
+               p->TypeL3= L3_UNKNOWN;\r
+               return true;\r
+       }\r
+\r
+       if (IPV4_GET_OFFSET(p->L3.IPv4Header) != 0)\r
+       {\r
+               // フラグメント化されているからこれ以上解析しない\r
+               p->TypeL4 = L4_FRAGMENT;\r
+               return true;\r
+       }\r
+\r
+       buf += header_size;\r
+       size -= header_size;\r
+\r
+       // L4 パケットのパース\r
+       switch (p->L3.IPv4Header->Protocol)\r
+       {\r
+       case IP_PROTO_ICMPV4:   // ICMPv4\r
+               return ParseICMPv4(p, buf, size);\r
+\r
+       case IP_PROTO_UDP:              // UDP\r
+               return ParseUDP(p, buf, size);\r
+\r
+       case IP_PROTO_TCP:              // TCP\r
+               return ParseTCP(p, buf, size);\r
+\r
+       default:                                // 不明\r
+               return true;\r
+       }\r
+}\r
+\r
+// ICMPv4 パース\r
+bool ParseICMPv4(PKT *p, UCHAR *buf, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // サイズをチェック\r
+       if (size < sizeof(ICMP_HEADER))\r
+       {\r
+               // サイズが不正\r
+               return false;\r
+       }\r
+\r
+       // ICMPv4 ヘッダ\r
+       p->L4.ICMPHeader = (ICMP_HEADER *)buf;\r
+       p->TypeL4 = L4_ICMPV4;\r
+\r
+       buf += sizeof(ICMP_HEADER);\r
+       size -= sizeof(ICMP_HEADER);\r
+\r
+       return true;\r
+}\r
+\r
+// TCP パース\r
+bool ParseTCP(PKT *p, UCHAR *buf, UINT size)\r
+{\r
+       UINT header_size;\r
+       // 引数チェック\r
+       if (p == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // サイズをチェック\r
+       if (size < sizeof(TCP_HEADER))\r
+       {\r
+               // サイズが不正\r
+               return false;\r
+       }\r
+\r
+       // TCP ヘッダ\r
+       p->L4.TCPHeader = (TCP_HEADER *)buf;\r
+       p->TypeL4 = L4_TCP;\r
+\r
+       // ヘッダサイズをチェック\r
+       header_size = TCP_GET_HEADER_SIZE(p->L4.TCPHeader) * 4;\r
+       if (header_size < sizeof(TCP_HEADER) || size < header_size)\r
+       {\r
+               // ヘッダサイズが不正\r
+               p->L4.TCPHeader = NULL;\r
+               p->TypeL4 = L4_UNKNOWN;\r
+               return true;\r
+       }\r
+\r
+       buf += header_size;\r
+       size -= header_size;\r
+\r
+       return true;\r
+}\r
+\r
+// UDP パース\r
+bool ParseUDP(PKT *p, UCHAR *buf, UINT size)\r
+{\r
+       USHORT src_port, dst_port;\r
+       // 引数チェック\r
+       if (p == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // サイズをチェック\r
+       if (size < sizeof(UDP_HEADER))\r
+       {\r
+               // サイズが不正\r
+               return false;\r
+       }\r
+\r
+       // UDP ヘッダ\r
+       p->L4.UDPHeader = (UDP_HEADER *)buf;\r
+       p->TypeL4 = L4_UDP;\r
+\r
+       buf += sizeof(UDP_HEADER);\r
+       size -= sizeof(UDP_HEADER);\r
+\r
+       // ポート番号をチェック\r
+       src_port = Endian16(p->L4.UDPHeader->SrcPort);\r
+       dst_port = Endian16(p->L4.UDPHeader->DstPort);\r
+\r
+       if ((src_port == 67 && dst_port == 68) ||\r
+               (src_port == 68 && dst_port == 67))\r
+       {\r
+               if (p->TypeL3 == L3_IPV4)\r
+               {\r
+                       // DHCP パケットを発見\r
+                       ParseDHCPv4(p, buf, size);\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// DHCPv4 パース\r
+void ParseDHCPv4(PKT *p, UCHAR *buf, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || buf == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // サイズをチェック\r
+       if (size < sizeof(DHCPV4_HEADER))\r
+       {\r
+               // サイズが不正\r
+               return;\r
+       }\r
+\r
+       // DHCPv4 ヘッダ\r
+       p->L7.DHCPv4Header = (DHCPV4_HEADER *)buf;\r
+       p->TypeL7 = L7_DHCPV4;\r
+}\r
+\r
+// パケットのメモリを解放する\r
+void FreePacket(PKT *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (p->MacHeader != NULL)\r
+       {\r
+               switch (p->TypeL3)\r
+               {\r
+               case L3_IPV4:\r
+                       FreePacketIPv4(p);\r
+                       break;\r
+\r
+               case L3_ARPV4:\r
+                       FreePacketARPv4(p);\r
+                       break;\r
+\r
+               case L3_TAGVLAN:\r
+                       FreePacketTagVlan(p);\r
+                       break;\r
+               }\r
+       }\r
+\r
+       Free(p);\r
+}\r
+\r
+// IPv4 パケットのメモリを解放する\r
+void FreePacketIPv4(PKT *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       switch (p->TypeL4)\r
+       {\r
+       case L4_ICMPV4:\r
+               FreePacketICMPv4(p);\r
+               break;\r
+\r
+       case L4_TCP:\r
+               FreePacketTCPv4(p);\r
+               break;\r
+\r
+       case L4_UDP:\r
+               FreePacketUDPv4(p);\r
+               break;\r
+       }\r
+\r
+       p->L3.IPv4Header = NULL;\r
+       p->TypeL3 = L3_UNKNOWN;\r
+}\r
+\r
+// タグ VLAN パケットのメモリを解放する\r
+void FreePacketTagVlan(PKT *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p->L3.TagVlanHeader = NULL;\r
+       p->TypeL3 = L3_UNKNOWN;\r
+}\r
+\r
+// ARPv4 パケットのメモリを解放する\r
+void FreePacketARPv4(PKT *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p->L3.ARPv4Header = NULL;\r
+       p->TypeL3 = L3_UNKNOWN;\r
+}\r
+\r
+// UDPv4 パケットのメモリを解放する\r
+void FreePacketUDPv4(PKT *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       switch (p->TypeL7)\r
+       {\r
+       case L7_DHCPV4:\r
+               FreePacketDHCPv4(p);\r
+               break;\r
+       }\r
+\r
+       p->L4.UDPHeader = NULL;\r
+       p->TypeL4 = L4_UNKNOWN;\r
+}\r
+\r
+// TCPv4 パケットのメモリを解放する\r
+void FreePacketTCPv4(PKT *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p->L4.TCPHeader = NULL;\r
+       p->TypeL4 = L4_UNKNOWN;\r
+}\r
+\r
+// ICMPv4 パケットのメモリを解放する\r
+void FreePacketICMPv4(PKT *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p->L4.ICMPHeader = NULL;\r
+       p->TypeL4 = L4_UNKNOWN;\r
+}\r
+\r
+// DHCPv4 パケットのメモリを解放する\r
+void FreePacketDHCPv4(PKT *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p->L7.DHCPv4Header = NULL;\r
+       p->TypeL7 = L7_UNKNOWN;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/TcpIp.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/TcpIp.h
new file mode 100644 (file)
index 0000000..5288814
--- /dev/null
@@ -0,0 +1,666 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// TcpIp.h\r
+// TcpIp.c のヘッダ\r
+\r
+#ifndef        TCPIP_H\r
+#define        TCPIP_H\r
+\r
+#ifdef OS_WIN32\r
+#pragma pack(push, 1)\r
+#endif // OS_WIN32\r
+\r
+// MAC ヘッダ\r
+struct MAC_HEADER\r
+{\r
+       UCHAR   DestAddress[6];                 // 送信元 MAC アドレス\r
+       UCHAR   SrcAddress[6];                  // 宛先 MAC アドレス\r
+       USHORT  Protocol;                               // プロトコル\r
+} GCC_PACKED;\r
+\r
+// MAC プロトコル\r
+#define        MAC_PROTO_ARPV4         0x0806  // ARPv4 パケット\r
+#define        MAC_PROTO_IPV4          0x0800  // IPv4 パケット\r
+#define        MAC_PROTO_IPV6          0x86dd  // IPv6 パケット\r
+#define        MAC_PROTO_TAGVLAN       0x8100  // タグ付き VLAN パケット\r
+\r
+// LLC ヘッダ\r
+struct LLC_HEADER\r
+{\r
+       UCHAR   Dsap;\r
+       UCHAR   Ssap;\r
+       UCHAR   Ctl;\r
+} GCC_PACKED;\r
+\r
+// LLC ヘッダの DSAP, SSAP の値\r
+#define        LLC_DSAP_BPDU           0x42\r
+#define        LLC_SSAP_BPDU           0x42\r
+\r
+// BPDU ヘッダ\r
+struct BPDU_HEADER\r
+{\r
+       USHORT  ProtocolId;                             // プロトコル ID (STP == 0x0000)\r
+       UCHAR   Version;                                // バージョン\r
+       UCHAR   Type;                                   // 種類\r
+       UCHAR   Flags;                                  // フラグ\r
+       USHORT  RootPriority;                   // ルートブリッジのプライオリティ\r
+       UCHAR   RootMacAddress[6];              // ルートブリッジの MAC アドレス\r
+       UINT    RootPathCost;                   // ルートブリッジまでのパスコスト\r
+       USHORT  BridgePriority;                 // 発信ブリッジのプライオリティ\r
+       UCHAR   BridgeMacAddress[6];    // 発信ブリッジの MAC アドレス\r
+       USHORT  BridgePortId;                   // 発信ブリッジのポート ID\r
+       USHORT  MessageAge;                             // 有効期限\r
+       USHORT  MaxAge;                                 // 最大有効期限\r
+       USHORT  HelloTime;                              // Hello Time\r
+       USHORT  ForwardDelay;                   // Forward Delay\r
+} GCC_PACKED;\r
+\r
+// ARPv4 ヘッダ\r
+struct ARPV4_HEADER\r
+{\r
+       USHORT  HardwareType;                   // ハードウェアタイプ\r
+       USHORT  ProtocolType;                   // プロトコルタイプ\r
+       UCHAR   HardwareSize;                   // ハードウェアサイズ\r
+       UCHAR   ProtocolSize;                   // プロトコルサイズ\r
+       USHORT  Operation;                              // オペレーション\r
+       UCHAR   SrcAddress[6];                  // 送信元 MAC アドレス\r
+       UINT    SrcIP;                                  // 送信元 IP アドレス\r
+       UCHAR   TargetAddress[6];               // ターゲット MAC アドレス\r
+       UINT    TargetIP;                               // ターゲット IP アドレス\r
+} GCC_PACKED;\r
+\r
+// ARP ハードウェア種類\r
+#define        ARP_HARDWARE_TYPE_ETHERNET              0x0001\r
+\r
+// ARP オペレーション種類\r
+#define        ARP_OPERATION_REQUEST                   1\r
+#define        ARP_OPERATION_RESPONSE                  2\r
+\r
+// タグ付き VLAN ヘッダ\r
+struct TAGVLAN_HEADER\r
+{\r
+       UCHAR Data[2];                                  // データ\r
+} GCC_PACKED;\r
+\r
+// IPv4 ヘッダ\r
+struct IPV4_HEADER\r
+{\r
+       UCHAR   VersionAndHeaderLength;         // バージョンとヘッダサイズ\r
+       UCHAR   TypeOfService;                          // サービスタイプ\r
+       USHORT  TotalLength;                            // 合計サイズ\r
+       USHORT  Identification;                         // 識別子\r
+       UCHAR   FlagsAndFlagmentOffset[2];      // フラグとフラグメントオフセット\r
+       UCHAR   TimeToLive;                                     // TTL\r
+       UCHAR   Protocol;                                       // プロトコル\r
+       USHORT  Checksum;                                       // チェックサム\r
+       UINT    SrcIP;                                          // 送信元 IP アドレス\r
+       UINT    DstIP;                                          // 宛先 IP アドレス\r
+} GCC_PACKED;\r
+\r
+// IPv4 ヘッダ操作用マクロ\r
+#define        IPV4_GET_VERSION(h)                     (((h)->VersionAndHeaderLength >> 4 & 0x0f))\r
+#define        IPV4_SET_VERSION(h, v)          ((h)->VersionAndHeaderLength |= (((v) & 0x0f) << 4))\r
+#define        IPV4_GET_HEADER_LEN(h)          ((h)->VersionAndHeaderLength & 0x0f)\r
+#define        IPV4_SET_HEADER_LEN(h, v)       ((h)->VersionAndHeaderLength |= ((v) & 0x0f))\r
+\r
+// IPv4 フラグメント関係操作用マクロ\r
+#define        IPV4_GET_FLAGS(h)                       (((h)->FlagsAndFlagmentOffset[0] >> 5) & 0x07)\r
+#define        IPV4_SET_FLAGS(h, v)            ((h)->FlagsAndFlagmentOffset[0] |= (((v) & 0x07) << 5))\r
+#define        IPV4_GET_OFFSET(h)                      (((h)->FlagsAndFlagmentOffset[0] & 0x1f) * 256 + ((h)->FlagsAndFlagmentOffset[1]))\r
+#define        IPV4_SET_OFFSET(h, v)           {(h)->FlagsAndFlagmentOffset[0] |= (UCHAR)((v) / 256); (h)->FlagsAndFlagmentOffset[1] = (UCHAR)((v) % 256);}\r
+\r
+// IPv4 プロトコル\r
+#define        IP_PROTO_ICMPV4         0x01    // ICMPv4 プロトコル\r
+\r
+// IPv6 プロトコル\r
+#define        IP_PROTO_ICMPV6         0x3a    // ICMPv6 プロトコル\r
+\r
+// IPv4 / IPv6 共通プロトコル\r
+#define        IP_PROTO_TCP            0x06    // TCP プロトコル\r
+#define        IP_PROTO_UDP            0x11    // UDP プロトコル\r
+\r
+\r
+// UDP ヘッダ\r
+struct UDP_HEADER\r
+{\r
+       USHORT  SrcPort;                                        // 送信元ポート番号\r
+       USHORT  DstPort;                                        // 宛先ポート番号\r
+       USHORT  PacketLength;                   // データ長\r
+       USHORT  Checksum;                               // チェックサム\r
+} GCC_PACKED;\r
+\r
+// UDPv4 擬似ヘッダ\r
+struct UDPV4_PSEUDO_HEADER\r
+{\r
+       UINT    SrcIP;                                  // 送信元 IP アドレス\r
+       UINT    DstIP;                                  // 宛先 IP アドレス\r
+       UCHAR   Reserved;                               // 未使用\r
+       UCHAR   Protocol;                               // プロトコル番号\r
+       USHORT  PacketLength1;                  // UDP データ長 1\r
+       USHORT  SrcPort;                                        // 送信元ポート番号\r
+       USHORT  DstPort;                                        // 宛先ポート番号\r
+       USHORT  PacketLength2;                  // UDP データ長 2\r
+       USHORT  Checksum;                               // チェックサム\r
+} GCC_PACKED;\r
+\r
+// TCPv4 擬似ヘッダ\r
+struct TCPV4_PSEUDO_HEADER\r
+{\r
+       UINT    SrcIP;                                  // 送信元 IP アドレス\r
+       UINT    DstIP;                                  // 宛先 IP アドレス\r
+       UCHAR   Reserved;                               // 未使用\r
+       UCHAR   Protocol;                               // プロトコル番号\r
+       USHORT  PacketLength;                   // UDP データ長 1\r
+} GCC_PACKED;\r
+\r
+// TCP ヘッダ\r
+struct TCP_HEADER\r
+{\r
+       USHORT  SrcPort;                                        // 送信元ポート番号\r
+       USHORT  DstPort;                                        // 宛先ポート番号\r
+       UINT    SeqNumber;                              // シーケンス番号\r
+       UINT    AckNumber;                              // 確認応答番号\r
+       UCHAR   HeaderSizeAndReserved;  // ヘッダサイズと予約領域\r
+       UCHAR   Flag;                                   // フラグ\r
+       USHORT  WindowSize;                             // ウインドウサイズ\r
+       USHORT  Checksum;                               // チェックサム\r
+       USHORT  UrgentPointer;                  // 緊急ポインタ\r
+} GCC_PACKED;\r
+\r
+// TCP マクロ\r
+#define        TCP_GET_HEADER_SIZE(h)  (((h)->HeaderSizeAndReserved >> 4) & 0x0f)\r
+#define        TCP_SET_HEADER_SIZE(h, v)       ((h)->HeaderSizeAndReserved = (((v) & 0x0f) << 4))\r
+\r
+// TCP フラグ\r
+#define        TCP_FIN                                         1\r
+#define        TCP_SYN                                         2\r
+#define        TCP_RST                                         4\r
+#define        TCP_PSH                                         8\r
+#define        TCP_ACK                                         16\r
+#define        TCP_URG                                         32\r
+\r
+// ICMP ヘッダ\r
+struct ICMP_HEADER\r
+{\r
+       UCHAR   Type;                                   // タイプ\r
+       UCHAR   Code;                                   // コード\r
+       USHORT  Checksum;                               // チェックサム\r
+} GCC_PACKED;\r
+\r
+#define        ICMP_TYPE_ECHO_REQUEST          8               // ICMP Echo 要求\r
+#define        ICMP_TYPE_ECHO_RESPONSE         0               // ICMP Echo 応答\r
+\r
+// ICMP Echo\r
+struct ICMP_ECHO\r
+{\r
+       USHORT  Identifier;                                             // ID\r
+       USHORT  SeqNo;                                                  // シーケンス番号\r
+} GCC_PACKED;\r
+\r
+// DHCPv4 ヘッダ\r
+struct DHCPV4_HEADER\r
+{\r
+       UCHAR   OpCode;                         // オペコード\r
+       UCHAR   HardwareType;           // ハードウェア種類\r
+       UCHAR   HardwareAddressSize;    // ハードウェアアドレスサイズ\r
+       UCHAR   Hops;                           // ホップ数\r
+       UINT    TransactionId;          // トランザクション ID\r
+       USHORT  Seconds;                                // 秒数\r
+       USHORT  Flags;                          // フラグ\r
+       UINT    ClientIP;                       // クライアント IP アドレス\r
+       UINT    YourIP;                         // 割り当て IP アドレス\r
+       UINT    ServerIP;                       // サーバー IP アドレス\r
+       UINT    RelayIP;                                // リレー IP アドレス\r
+       UCHAR   ClientMacAddress[6];    // クライアント MAC アドレス\r
+       UCHAR   Padding[10];                    // Ethernet 以外のためにパディング\r
+} GCC_PACKED;\r
+\r
+// DNSv4 ヘッダ\r
+struct DNSV4_HEADER\r
+{\r
+       USHORT  TransactionId;                  // トランザクション ID\r
+       UCHAR   Flag1;                                  // フラグ 1\r
+       UCHAR   Flag2;                                  // フラグ 2\r
+       USHORT  NumQuery;                               // クエリ数\r
+       USHORT  AnswerRRs;                              // 回答 RR 数\r
+       USHORT  AuthorityRRs;                   // 権威 RR 数\r
+       USHORT  AdditionalRRs;                  // 追加 RR 数\r
+} GCC_PACKED;\r
+\r
+#define        DHCP_MAGIC_COOKIE       0x63825363      // Magic Cookie (固定)\r
+\r
+// IPv6 ヘッダパケット情報\r
+struct IPV6_HEADER_PACKET_INFO\r
+{\r
+       IPV6_HEADER *IPv6Header;                                        // IPv6 ヘッダ\r
+       IPV6_OPTION_HEADER *HopHeader;                          // ホップバイホップオプションヘッダ\r
+       UINT HopHeaderSize;                                                     // ホップバイホップオプションヘッダサイズ\r
+       IPV6_OPTION_HEADER *EndPointHeader;                     // 終点オプションヘッダ\r
+       UINT EndPointHeaderSize;                                        // 終点オプションヘッダサイズ\r
+       IPV6_OPTION_HEADER *RoutingHeader;                      // ルーティングヘッダ\r
+       UINT RoutingHeaderSize;                                         // ルーティングヘッダサイズ\r
+       IPV6_FRAGMENT_HEADER *FragmentHeader;           // フラグメントヘッダ\r
+       void *Payload;                                                          // ペイロード\r
+       UINT PayloadSize;                                                       // ペイロードサイズ\r
+       UCHAR Protocol;                                                         // ペイロードプロトコル\r
+       bool IsFragment;                                                        // フラグメントパケットかどうか\r
+};\r
+\r
+// IPv6 ヘッダ\r
+struct IPV6_HEADER\r
+{\r
+       UCHAR VersionAndTrafficClass1;          // バージョン番号 (4 bit) とトラフィッククラス 1 (4 bit)\r
+       UCHAR TrafficClass2AndFlowLabel1;       // トラフィッククラス 2 (4 bit) とフローラベル 1 (4 bit)\r
+       UCHAR FlowLabel2;                                       // フローラベル 2 (8 bit)\r
+       UCHAR FlowLabel3;                                       // フローラベル 3 (8 bit)\r
+       USHORT PayloadLength;                           // ペイロードの長さ (拡張ヘッダを含む)\r
+       UCHAR NextHeader;                                       // 次のヘッダ\r
+       UCHAR HopLimit;                                         // ホップリミット\r
+       IPV6_ADDR SrcAddress;                           // ソースアドレス\r
+       IPV6_ADDR DestAddress;                          // 宛先アドレス\r
+} GCC_PACKED;\r
+\r
+\r
+// IPv6 ヘッダ操作用マクロ\r
+#define IPV6_GET_VERSION(h)                    (((h)->VersionAndTrafficClass1 >> 4) & 0x0f)\r
+#define IPV6_SET_VERSION(h, v)         ((h)->VersionAndTrafficClass1 = ((h)->VersionAndTrafficClass1 & 0x0f) | ((v) << 4) & 0xf0)\r
+#define IPV6_GET_TRAFFIC_CLASS(h)      ((((h)->VersionAndTrafficClass1 << 4) & 0xf0) | ((h)->TrafficClass2AndFlowLabel1 >> 4) & 0x0f)\r
+#define        IPV6_SET_TRAFFIC_CLASS(h, v)    ((h)->VersionAndTrafficClass1 = ((h)->VersionAndTrafficClass1 & 0xf0) | (((v) >> 4) & 0x0f),\\r
+       (h)->TrafficClass2AndFlowLabel1 = (h)->TrafficClass2AndFlowLabel1 & 0x0f | ((v) << 4) & 0xf0)\r
+#define        IPV6_GET_FLOW_LABEL(h)          ((((h)->TrafficClass2AndFlowLabel1 << 16) & 0xf0000) | (((h)->FlowLabel2 << 8) & 0xff00) |\\r
+       (((h)->FlowLabel3) & 0xff))\r
+#define IPV6_SET_FLOW_LABEL(h, v)      ((h)->TrafficClass2AndFlowLabel1 = ((h)->TrafficClass2AndFlowLabel1 & 0xf0 | ((v) >> 16) & 0x0f),\\r
+       (h)->FlowLabel2 = ((v) >> 8) & 0xff,\\r
+       (h)->FlowLabel3 = (v) & 0xff)\r
+\r
+\r
+// IPv6 ホップ最大値 (ルーティングしない)\r
+#define IPV6_HOP_MAX                                   255\r
+\r
+// IPv6 ホップ標準数\r
+#define IPV6_HOP_DEFAULT                               127\r
+\r
+// IPv6 ヘッダ番号\r
+#define IPV6_HEADER_HOP                                        0       // ホップバイホップオプションヘッダ\r
+#define IPV6_HEADER_ENDPOINT                   60      // 終点オプションヘッダ\r
+#define IPV6_HEADER_ROUTING                            43      // ルーティングヘッダ\r
+#define IPV6_HEADER_FRAGMENT                   44      // フラグメントヘッダ\r
+#define IPV6_HEADER_NONE                               59      // 次ヘッダ無し\r
+\r
+// IPv6 オプションヘッダ\r
+// (ホップオプションヘッダ、終点オプションヘッダ、ルーティングヘッダで使用される)\r
+struct IPV6_OPTION_HEADER\r
+{\r
+       UCHAR NextHeader;                                       // 次のヘッダ\r
+       UCHAR Size;                                                     // ヘッダサイズ (/8)\r
+} GCC_PACKED;\r
+\r
+// IPv6 フラグメントヘッダ\r
+// (フラグメント不可能部分は、ルーティングヘッダがある場合はその直前まで、\r
+//  ホップバイホップオプションヘッダがある場合はその直前まで、\r
+//  それ以外の場合は最初の拡張ヘッダもしくはペイロードの直前まで)\r
+struct IPV6_FRAGMENT_HEADER\r
+{\r
+       UCHAR NextHeader;                                       // 次のヘッダ\r
+       UCHAR Reserved;                                         // 予約\r
+       UCHAR FlagmentOffset1;                          // フラグメントオフセット 1 (/8, 8 bit)\r
+       UCHAR FlagmentOffset2AndFlags;          // フラグメントオフセット 2 (/8, 5 bit) + 予約 (2 bit) + More フラグ (1 bit)\r
+       UINT Identification;                            // ID\r
+} GCC_PACKED;\r
+\r
+// IPv6 フラグメントヘッダ操作用マクロ\r
+#define IPV6_GET_FRAGMENT_OFFSET(h)            (((((h)->FlagmentOffset1) << 5) & 0x1fe0) | (((h)->FlagmentOffset2AndFlags >> 3) & 0x1f))\r
+#define IPV6_SET_FRAGMENT_OFFSET(h, v) ((h)->FlagmentOffset1 = (v / 32) & 0xff,        \\r
+       ((h)->FlagmentOffset2AndFlags = ((v % 256) << 3) & 0xf8) | ((h)->FlagmentOffset2AndFlags & 0x07))\r
+#define IPV6_GET_FLAGS(h)                              ((h)->FlagmentOffset2AndFlags & 0x0f)\r
+#define IPV6_SET_FLAGS(h, v)                           ((h)->FlagmentOffset2AndFlags = (((h)->FlagmentOffset2AndFlags & 0xf8) | (v & 0x07)))\r
+\r
+// フラグ\r
+#define IPV6_FRAGMENT_HEADER_FLAG_MORE_FRAGMENTS               0x01    // 次のフラグメントがある\r
+\r
+// IPv6 仮想ヘッダ\r
+struct IPV6_PSEUDO_HEADER\r
+{\r
+       IPV6_ADDR SrcAddress;                           // ソースアドレス\r
+       IPV6_ADDR DestAddress;                          // 宛先アドレス\r
+       UINT UpperLayerPacketSize;                      // 上位レイヤのパケットサイズ\r
+       UCHAR Padding[3];                                       // パディング\r
+       UCHAR NextHeader;                                       // 次ヘッダ (TCP / UDP)\r
+} GCC_PACKED;\r
+\r
+// ICMPv6 ルータ要請ヘッダ\r
+struct ICMPV6_ROUTER_SOLICIATION_HEADER\r
+{\r
+       UINT Reserved;                                                  // 予約\r
+       // + オプション (ソースリンクレイヤアドレス[任意])\r
+} GCC_PACKED;\r
+\r
+// ICMPv6 ルータ広告ヘッダ\r
+struct ICMPV6_ROUTER_ADVERTISEMENT_HEADER\r
+{\r
+       UCHAR CurHopLimit;                                              // デフォルトのホップリミット数\r
+       UCHAR Flags;                                                    // フラグ (0)\r
+       USHORT Lifetime;                                                // 寿命\r
+       UINT ReachableTime;                                             // 0\r
+       UINT RetransTimer;                                              // 0\r
+       // + オプション (プレフィックス情報[必須], MTU[任意])\r
+} GCC_PACKED;\r
+\r
+// ICMPv6 近隣要請ヘッダ\r
+struct ICMPV6_NEIGHBOR_SOLICIATION_HEADER\r
+{\r
+       UINT Reserved;                                                  // 予約\r
+       IPV6_ADDR TargetAddress;                                // ターゲットアドレス\r
+       // + オプション (ソースリンクレイヤアドレス[必須])\r
+} GCC_PACKED;\r
+\r
+// ICMPv6 近隣広告ヘッダ\r
+struct ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER\r
+{\r
+       UCHAR Flags;                                                    // フラグ\r
+       UCHAR Reserved[3];                                              // 予約\r
+       IPV6_ADDR TargetAddress;                                // ターゲットアドレス\r
+       // + オプション (ターゲットリンクレイヤアドレス)\r
+} GCC_PACKED;\r
+\r
+#define ICMPV6_NEIGHBOR_ADVERTISEMENT_FLAG_ROUTER              0x80    // ルータ\r
+#define ICMPV6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED   0x40    // 要請フラグ\r
+#define ICMPV6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERWRITE   0x20    // 上書きフラグ\r
+\r
+// ICMPv6 オプションリスト\r
+struct ICMPV6_OPTION_LIST\r
+{\r
+       ICMPV6_OPTION_LINK_LAYER *SourceLinkLayer;              // ソースリンクレイヤアドレス\r
+       ICMPV6_OPTION_LINK_LAYER *TargetLinkLayer;              // ターゲットリンクレイヤアドレス\r
+       ICMPV6_OPTION_PREFIX *Prefix;                                   // プレフィックス情報\r
+       ICMPV6_OPTION_MTU *Mtu;                                                 // MTU\r
+} GCC_PACKED;\r
+\r
+// ICMPv6 オプション\r
+struct ICMPV6_OPTION\r
+{\r
+       UCHAR Type;                                                             // タイプ\r
+       UCHAR Length;                                                   // 長さ (/8, タイプと長さを含める)\r
+} GCC_PACKED;\r
+\r
+#define        ICMPV6_OPTION_TYPE_SOURCE_LINK_LAYER    1               // ソースリンクレイヤアドレス\r
+#define ICMPV6_OPTION_TYPE_TARGET_LINK_LAYER   2               // ターゲットリンクレイヤアドレス\r
+#define ICMPV6_OPTION_TYPE_PREFIX                              3               // プレフィックス情報\r
+#define ICMPV6_OPTION_TYPE_MTU                                 5               // MTU\r
+\r
+// ICMPv6 リンクレイヤオプション\r
+struct ICMPV6_OPTION_LINK_LAYER\r
+{\r
+       ICMPV6_OPTION IcmpOptionHeader;                 // オプションヘッダ\r
+       UCHAR Address[6];                                               // MAC アドレス\r
+} GCC_PACKED;\r
+\r
+// ICMPv6 プレフィックス情報オプション\r
+struct ICMPV6_OPTION_PREFIX\r
+{\r
+       ICMPV6_OPTION IcmpOptionHeader;                 // オプションヘッダ\r
+       UCHAR SubnetLength;                                             // サブネット長\r
+       UCHAR Flags;                                                    // フラグ\r
+       UINT ValidLifetime;                                             // 正式な寿命\r
+       UINT PreferredLifetime;                                 // 望ましい寿命\r
+       UINT Reserved;                                                  // 予約\r
+       IPV6_ADDR Prefix;                                               // プレフィックスアドレス\r
+} GCC_PACKED;\r
+\r
+#define ICMPV6_OPTION_PREFIX_FLAG_ONLINK               0x80    // リンク上\r
+#define ICMPV6_OPTION_PREFIX_FLAG_AUTO                 0x40    // 自動\r
+\r
+// ICMPv6 MTU オプション\r
+struct ICMPV6_OPTION_MTU\r
+{\r
+       ICMPV6_OPTION IcmpOptionHeader;                 // オプションヘッダ\r
+       USHORT Reserved;                                                // 予約\r
+       UINT Mtu;                                                               // MTU 値\r
+} GCC_PACKED;\r
+\r
+\r
+// IPv6 ヘッダ情報\r
+struct IPV6_HEADER_INFO\r
+{\r
+       bool IsRawIpPacket;\r
+       USHORT Size;\r
+       UINT Id;\r
+       UCHAR Protocol;\r
+       UCHAR HopLimit;\r
+       IPV6_ADDR SrcIpAddress;\r
+       IPV6_ADDR DestIpAddress;\r
+       bool UnicastForMe;\r
+       bool UnicastForRouting;\r
+       bool UnicastForRoutingWithProxyNdp;\r
+       bool IsBroadcast;\r
+       UINT TypeL4;\r
+};\r
+\r
+// ICMPv6 ヘッダ情報\r
+struct ICMPV6_HEADER_INFO\r
+{\r
+       UCHAR Type;\r
+       UCHAR Code;\r
+       USHORT DataSize;\r
+       void *Data;\r
+       ICMP_ECHO EchoHeader;\r
+       void *EchoData;\r
+       UINT EchoDataSize;\r
+\r
+       union\r
+       {\r
+               // Type の値によって意味が決まる\r
+               ICMPV6_ROUTER_SOLICIATION_HEADER *RouterSoliciationHeader;\r
+               ICMPV6_ROUTER_ADVERTISEMENT_HEADER *RouterAdvertisementHeader;\r
+               ICMPV6_NEIGHBOR_SOLICIATION_HEADER *NeighborSoliciationHeader;\r
+               ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER *NeighborAdvertisementHeader;\r
+               void *HeaderPointer;\r
+       } Headers;\r
+\r
+       ICMPV6_OPTION_LIST OptionList;\r
+};\r
+\r
+// ICMPv6 の Type の値\r
+#define ICMPV6_TYPE_ECHO_REQUEST                               128             // ICMPv6 Echo 要求\r
+#define ICMPV6_TYPE_ECHO_RESPONSE                              129             // ICMPv6 Echo 応答\r
+#define ICMPV6_TYPE_ROUTER_SOLICIATION                 133             // ルータ要請\r
+#define ICMPV6_TYPE_ROUTER_ADVERTISEMENT               134             // ルータ広告\r
+#define ICMPV6_TYPE_NEIGHBOR_SOLICIATION               135             // 近隣要請\r
+#define ICMPV6_TYPE_NEIGHBOR_ADVERTISEMENT             136             // 近隣広告\r
+\r
+// パケット\r
+struct PKT\r
+{\r
+       // このあたりは急いで実装したのでコードがあまり美しくない。\r
+       UCHAR                   *PacketData;    // パケットデータ本体\r
+       UINT                    PacketSize;             // パケットサイズ\r
+       MAC_HEADER              *MacHeader;             // MAC ヘッダ\r
+       UCHAR                   *MacAddressSrc; // 送信元 MAC アドレス\r
+       UCHAR                   *MacAddressDest;        // 宛先 MAC アドレス\r
+       bool                    BroadcastPacket;                // ブロードキャストパケット\r
+       bool                    InvalidSourcePacket;    // ソースアドレスが不正なパケット\r
+       bool                    AccessChecked;  // アクセスリストで通過が確認されたパケット\r
+       UINT                    VlanTypeID;             // タグ付き VLAN の TypeID (通常は 0x8100)\r
+       UINT                    VlanId;                 // VLAN ID\r
+       UINT                    Delay;                  // 遅延\r
+       UINT                    Jitter;                 // ジッタ\r
+       UINT                    Loss;                   // パケットロス\r
+       UINT64                  DelayedForwardTick;     // 遅延した場合における送信時刻\r
+       SESSION                 *DelayedSrcSession;     // 送信元のセッション\r
+       UINT                    TypeL3;                 // Layer-3 パケット分類\r
+       IPV6_HEADER_PACKET_INFO IPv6HeaderPacketInfo;   // IPv6 ヘッダパケット情報 (TypeL3 == L3_IPV6 の場合のみ)\r
+       ICMPV6_HEADER_INFO ICMPv6HeaderPacketInfo;              // ICMPv6 ヘッダ情報 (TypeL4 == L4_ICMPV6 の場合のみ)\r
+       union\r
+       {\r
+               IPV4_HEADER             *IPv4Header;    // IPv4 ヘッダ\r
+               ARPV4_HEADER    *ARPv4Header;   // ARPv4 ヘッダ\r
+               IPV6_HEADER             *IPv6Header;    // IPv6 ヘッダ\r
+               TAGVLAN_HEADER  *TagVlanHeader; // タグヘッダ\r
+               BPDU_HEADER             *BpduHeader;    // BPDU ヘッダ\r
+               void                    *PointerL3;\r
+       } L3;\r
+       UINT                    TypeL4;                         // Layer-4 パケット分類\r
+       union\r
+       {\r
+               UDP_HEADER      *UDPHeader;                     // UDP ヘッダ\r
+               TCP_HEADER      *TCPHeader;                     // TCP ヘッダ\r
+               ICMP_HEADER     *ICMPHeader;            // ICMP ヘッダ\r
+               void            *PointerL4;\r
+       } L4;\r
+       UINT                    TypeL7;                 // Layer-7 パケット分類\r
+       union\r
+       {\r
+               DHCPV4_HEADER   *DHCPv4Header;  // DHCPv4 ヘッダ\r
+               void                    *PointerL7;\r
+       } L7;\r
+} GCC_PACKED;\r
+\r
+// Layer-3 パケット分類\r
+#define        L3_UNKNOWN                      0               // 不明\r
+#define        L3_ARPV4                        1               // ARPv4 パケット\r
+#define        L3_IPV4                         2               // IPv4 パケット\r
+#define        L3_TAGVLAN                      3               // タグ付き VLAN パケット\r
+#define        L3_BPDU                         4               // BPDU パケット\r
+#define L3_IPV6                                5               // IPv6 パケット\r
+\r
+// Layer-4 パケット分類\r
+#define        L4_UNKNOWN                      0               // 不明\r
+#define        L4_UDP                          1               // UDPv4 パケット\r
+#define        L4_TCP                          2               // TCPv4 パケット\r
+#define        L4_ICMPV4                       3               // ICMPv4 パケット\r
+#define        L4_ICMPV6                       4               // ICMPv6 パケット\r
+#define        L4_FRAGMENT                     5               // フラグメントパケット\r
+\r
+// Layer-7 パケット分類\r
+#define        L7_UNKNOWN                      0               // 不明\r
+#define        L7_DHCPV4                       1               // DHCPv4 パケット\r
+\r
+\r
+PKT *ParsePacket(UCHAR *buf, UINT size);\r
+PKT *ParsePacketEx(UCHAR *buf, UINT size, bool no_l3);\r
+PKT *ParsePacketEx2(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id);\r
+PKT *ParsePacketEx3(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id, bool bridge_id_as_mac_address);\r
+void FreePacket(PKT *p);\r
+void FreePacketIPv4(PKT *p);\r
+void FreePacketTagVlan(PKT *p);\r
+void FreePacketARPv4(PKT *p);\r
+void FreePacketUDPv4(PKT *p);\r
+void FreePacketTCPv4(PKT *p);\r
+void FreePacketICMPv4(PKT *p);\r
+void FreePacketDHCPv4(PKT *p);\r
+bool ParsePacketL2(PKT *p, UCHAR *buf, UINT size);\r
+bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3);\r
+bool ParsePacketARPv4(PKT *p, UCHAR *buf, UINT size);\r
+bool ParsePacketIPv4(PKT *p, UCHAR *buf, UINT size);\r
+bool ParsePacketBPDU(PKT *p, UCHAR *buf, UINT size);\r
+bool ParsePacketTAGVLAN(PKT *p, UCHAR *buf, UINT size);\r
+bool ParseICMPv4(PKT *p, UCHAR *buf, UINT size);\r
+bool ParseICMPv6(PKT *p, UCHAR *buf, UINT size);\r
+bool ParseTCP(PKT *p, UCHAR *buf, UINT size);\r
+bool ParseUDP(PKT *p, UCHAR *buf, UINT size);\r
+void ParseDHCPv4(PKT *p, UCHAR *buf, UINT size);\r
+PKT *ClonePacket(PKT *p, bool copy_data);\r
+void FreeClonePacket(PKT *p);\r
+\r
+bool ParsePacketIPv6(PKT *p, UCHAR *buf, UINT size);\r
+bool ParsePacketIPv6Header(IPV6_HEADER_PACKET_INFO *info, UCHAR *buf, UINT size);\r
+bool ParseIPv6ExtHeader(IPV6_HEADER_PACKET_INFO *info, UCHAR next_header, UCHAR *buf, UINT size);\r
+bool ParseICMPv6Options(ICMPV6_OPTION_LIST *o, UCHAR *buf, UINT size);\r
+void CloneICMPv6Options(ICMPV6_OPTION_LIST *dst, ICMPV6_OPTION_LIST *src);\r
+void FreeCloneICMPv6Options(ICMPV6_OPTION_LIST *o);\r
+USHORT CalcChecksumForIPv6(IPV6_ADDR *src_ip, IPV6_ADDR *dest_ip, UCHAR protocol, void *data, UINT size);\r
+BUF *BuildICMPv6Options(ICMPV6_OPTION_LIST *o);\r
+void BuildICMPv6OptionValue(BUF *b, UCHAR type, void *header_pointer, UINT total_size);\r
+BUF *BuildIPv6(IPV6_ADDR *dest_ip, IPV6_ADDR *src_ip, UINT id, UCHAR protocol, UCHAR hop_limit, void *data,\r
+                          UINT size);\r
+BUF *BuildIPv6PacketHeader(IPV6_HEADER_PACKET_INFO *info, UINT *bytes_before_payload);\r
+UCHAR IPv6GetNextHeaderFromQueue(QUEUE *q);\r
+void BuildAndAddIPv6PacketOptionHeader(BUF *b, IPV6_OPTION_HEADER *opt, UCHAR next_header, UINT size);\r
+BUF *BuildICMPv6NeighborSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCHAR *my_mac_address, UINT id);\r
+BUF *BuildICMPv6(IPV6_ADDR *src_ip, IPV6_ADDR *dest_ip, UCHAR hop_limit, UCHAR type, UCHAR code, void *data, UINT size, UINT id);\r
+\r
+bool VLanRemoveTag(void **packet_data, UINT *packet_size, UINT vlan_id);\r
+void VLanInsertTag(void **packet_data, UINT *packet_size, UINT vlan_id);\r
+\r
+#ifdef OS_WIN32\r
+#pragma pack(pop)\r
+#endif // OS_WIN32\r
+\r
+#endif // TCPIP_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/UT.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/UT.c
new file mode 100644 (file)
index 0000000..7fba055
--- /dev/null
@@ -0,0 +1,378 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// UT.c\r
+// Win32 用 SoftEther Network Utility\r
+\r
+#ifdef WIN32\r
+\r
+#define        UT_C\r
+\r
+#define        _WIN32_WINNT            0x0502\r
+#define        WINVER                          0x0502\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+#include <wincrypt.h>\r
+#include <wininet.h>\r
+#include <shlobj.h>\r
+#include <commctrl.h>\r
+#include <Dbghelp.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+#include "../PenCore/resource.h"\r
+\r
+static char *selected_adapter = NULL;\r
+\r
+// Q. 「スピードメーター」という関数名になっているがこれはどういう意味か? 警察のオービスなのか?\r
+// A. もともとこのネットワーク情報表示ユーティリティは、通信速度を測定するために開発\r
+//    されたのである。しかし、その後「TrafficServer」、「TrafficClient」機能が別途\r
+//    開発されたため、速度測定機能はこのユーティリティからは削除された。\r
+//    関数名はその時代の名残である。\r
+\r
+// ステータスの更新\r
+void UtSpeedMeterDlgRefreshStatus(HWND hWnd)\r
+{\r
+       char *title;\r
+       MS_ADAPTER *a;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       title = selected_adapter;\r
+\r
+       a = MsGetAdapter(title);\r
+       if (a == NULL)\r
+       {\r
+               LbReset(hWnd, L_STATUS);\r
+               Disable(hWnd, L_STATUS);\r
+       }\r
+       else\r
+       {\r
+               LVB *b;\r
+               wchar_t tmp[MAX_SIZE];\r
+               wchar_t tmp2[MAX_SIZE];\r
+               char str[MAX_SIZE];\r
+               b = LvInsertStart();\r
+\r
+               StrToUni(tmp, sizeof(tmp), a->Title);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_TITLE"), tmp);\r
+\r
+               StrToUni(tmp, sizeof(tmp), a->Guid);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_GUID"), tmp);\r
+\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_TYPE"), MsGetAdapterTypeStr(a->Type));\r
+\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_STATUS"), MsGetAdapterStatusStr(a->Status));\r
+\r
+               UniToStr3(tmp, sizeof(tmp), a->Mtu);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_MTU"), tmp);\r
+\r
+               UniToStr3(tmp, sizeof(tmp), a->Speed);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_SPEED"), tmp);\r
+\r
+               Zero(str, sizeof(str));\r
+               BinToStrEx2(str, sizeof(str), a->Address, a->AddressSize, '-');\r
+               StrToUni(tmp, sizeof(tmp), str);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_ADDRESS"), tmp);\r
+\r
+               UniToStr3(tmp, sizeof(tmp), a->RecvBytes);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_RECV_BYTES"), tmp);\r
+\r
+               UniToStr3(tmp, sizeof(tmp), a->RecvPacketsBroadcast);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_RECV_BCASTS"), tmp);\r
+\r
+               UniToStr3(tmp, sizeof(tmp), a->RecvPacketsUnicast);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_RECV_UNICASTS"), tmp);\r
+\r
+               UniToStr3(tmp, sizeof(tmp), a->SendBytes);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_SEND_BYTES"), tmp);\r
+\r
+               UniToStr3(tmp, sizeof(tmp), a->SendPacketsBroadcast);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_SEND_BCASTS"), tmp);\r
+\r
+               UniToStr3(tmp, sizeof(tmp), a->SendPacketsUnicast);\r
+               LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_SEND_UNICASTS"), tmp);\r
+\r
+               for (i = 0;i < a->NumIpAddress;i++)\r
+               {\r
+                       UniFormat(tmp2, sizeof(tmp2), _UU("UT_SM_ST_IP"), i + 1);\r
+                       IPToUniStr(tmp, sizeof(tmp), &a->IpAddresses[i]);\r
+                       LvInsertAdd(b, 0, NULL, 2, tmp2, tmp);\r
+\r
+                       UniFormat(tmp2, sizeof(tmp2), _UU("UT_SM_ST_SUBNET"), i + 1);\r
+                       IPToUniStr(tmp, sizeof(tmp), &a->SubnetMasks[i]);\r
+                       LvInsertAdd(b, 0, NULL, 2, tmp2, tmp);\r
+               }\r
+\r
+               for (i = 0;i < a->NumGateway;i++)\r
+               {\r
+                       UniFormat(tmp2, sizeof(tmp2), _UU("UT_SM_ST_GATEWAY"), i + 1);\r
+                       IPToUniStr(tmp, sizeof(tmp), &a->Gateways[i]);\r
+                       LvInsertAdd(b, 0, NULL, 2, tmp2, tmp);\r
+               }\r
+\r
+               if (a->UseDhcp)\r
+               {\r
+                       IPToUniStr(tmp, sizeof(tmp), &a->DhcpServer);\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_DHCP"), tmp);\r
+\r
+                       GetDateTimeStrEx64(tmp, sizeof(tmp), a->DhcpLeaseStart, NULL);\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_DHCP_1"), tmp);\r
+\r
+                       GetDateTimeStrEx64(tmp, sizeof(tmp), a->DhcpLeaseExpires, NULL);\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_DHCP_2"), tmp);\r
+               }\r
+\r
+               if (a->UseWins)\r
+               {\r
+                       IPToUniStr(tmp, sizeof(tmp), &a->PrimaryWinsServer);\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_WINS_1"), tmp);\r
+\r
+                       IPToUniStr(tmp, sizeof(tmp), &a->SecondaryWinsServer);\r
+                       LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_WINS_2"), tmp);\r
+               }\r
+\r
+               LvInsertEnd(b, hWnd, L_STATUS);\r
+               Enable(hWnd, L_STATUS);\r
+\r
+               MsFreeAdapter(a);\r
+       }\r
+\r
+}\r
+\r
+// アダプタリストの更新\r
+void UtSpeedMeterDlgRefreshList(HWND hWnd)\r
+{\r
+       wchar_t *old;\r
+       MS_ADAPTER_LIST *o;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 現在の選択を取得\r
+       old = GetText(hWnd, E_LIST);\r
+       if (old != NULL)\r
+       {\r
+               if (UniStrLen(old) == 0)\r
+               {\r
+                       Free(old);\r
+                       old = NULL;\r
+               }\r
+       }\r
+\r
+       o = MsCreateAdapterList();\r
+       CbReset(hWnd, E_LIST);\r
+       CbSetHeight(hWnd, E_LIST, 18);\r
+\r
+       for (i = 0;i < o->Num;i++)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               MS_ADAPTER *a = o->Adapters[i];\r
+\r
+               if (a->Info)\r
+               {\r
+                       StrToUni(tmp, sizeof(tmp), a->Title);\r
+                       CbAddStr(hWnd, E_LIST, tmp, 0);\r
+               }\r
+       }\r
+\r
+\r
+       // 前回の選択を再選択\r
+       if (old != NULL)\r
+       {\r
+               CbSelectIndex(hWnd, E_LIST, CbFindStr(hWnd, E_LIST, old));\r
+               Free(old);\r
+       }\r
+\r
+       MsFreeAdapterList(o);\r
+}\r
+\r
+// スピードメーターダイアログコントロール更新\r
+void UtSpeedMeterDlgUpdate(HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+}\r
+\r
+// スピードメーターダイアログ初期化\r
+void UtSpeedMeterDlgInit(HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LvInitEx(hWnd, L_STATUS, true);\r
+       LvInsertColumn(hWnd, L_STATUS, 0, _UU("UT_SM_COLUMN_1"), 150);\r
+       LvInsertColumn(hWnd, L_STATUS, 1, _UU("UT_SM_COLUMN_2"), 290);\r
+\r
+       UtSpeedMeterDlgRefreshList(hWnd);\r
+       selected_adapter = GetTextA(hWnd, E_LIST);\r
+       UtSpeedMeterDlgRefreshStatus(hWnd);\r
+       UtSpeedMeterDlgUpdate(hWnd);\r
+}\r
+\r
+// スピードメーターダイアログ\r
+UINT UtSpeedMeterDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetIcon(hWnd, 0, ICO_NIC_ONLINE);\r
+               UtSpeedMeterDlgInit(hWnd);\r
+               SetTimer(hWnd, 1, SPEED_METER_REFRESH_INTERVAL, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       UtSpeedMeterDlgRefreshStatus(hWnd);\r
+                       UtSpeedMeterDlgUpdate(hWnd);\r
+                       SetTimer(hWnd, 1, SPEED_METER_REFRESH_INTERVAL, NULL);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               if (HIWORD(wParam) == CBN_SELCHANGE) {\r
+                       Free(selected_adapter);\r
+                       selected_adapter = GetTextA(hWnd, E_LIST);\r
+                       UtSpeedMeterDlgUpdate(hWnd);\r
+               } else {\r
+                       switch (wParam)\r
+                       {\r
+                       case B_REFRESH:\r
+                               UtSpeedMeterDlgRefreshList(hWnd);\r
+                               Free(selected_adapter);\r
+                               selected_adapter = GetTextA(hWnd, E_LIST);\r
+                               UtSpeedMeterDlgUpdate(hWnd);\r
+                               break;\r
+\r
+                       case IDCANCEL:\r
+                               Close(hWnd);\r
+                               break;\r
+                       }\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               Free(selected_adapter);\r
+               selected_adapter = NULL;\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// スピードメーター\r
+void UtSpeedMeter()\r
+{\r
+       UtSpeedMeterEx(NULL);\r
+}\r
+void UtSpeedMeterEx(void *hWnd)\r
+{\r
+       Dialog((HWND)hWnd, D_SPEEDMETER, UtSpeedMeterDlgProc, NULL);\r
+}\r
+\r
+#endif // WIN32\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/UT.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/UT.h
new file mode 100644 (file)
index 0000000..1fc25bc
--- /dev/null
@@ -0,0 +1,105 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// UT.h\r
+// UT.c のヘッダ\r
+\r
+#ifndef        UT_H\r
+#define        UT_H\r
+\r
+// 定数\r
+#define        SPEED_METER_REFRESH_INTERVAL                    500\r
+\r
+#ifdef UT_C\r
+// 内部向け宣言\r
+\r
+// 関数プロトタイプ\r
+UINT UtSpeedMeterDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void UtSpeedMeterDlgInit(HWND hWnd);\r
+void UtSpeedMeterDlgRefreshList(HWND hWnd);\r
+void UtSpeedMeterDlgRefreshStatus(HWND hWnd);\r
+void UtSpeedMeterDlgUpdate(HWND hWnd);\r
+void UtSpeedMeterDlgRefreshStatus(HWND hWnd);\r
+\r
+#endif // UT_C\r
+\r
+// 関数プロトタイプ\r
+void UtSpeedMeter();\r
+void UtSpeedMeterEx(void *hWnd);\r
+\r
+#endif // UT_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLan.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLan.c
new file mode 100644 (file)
index 0000000..f44b667
--- /dev/null
@@ -0,0 +1,99 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// VLan.c\r
+// 仮想 LAN カードアダプタ操作用ライブラリ\r
+\r
+#define        VLAN_C\r
+\r
+#ifdef WIN32\r
+#define        OS_WIN32\r
+#endif\r
+\r
+#ifdef OS_WIN32\r
+\r
+// Win32 用\r
+#include "VLanWin32.c"\r
+\r
+#else\r
+\r
+// UNIX 用\r
+#include "VLanUnix.c"\r
+\r
+#endif // OS_WIN32\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLan.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLan.h
new file mode 100644 (file)
index 0000000..1753849
--- /dev/null
@@ -0,0 +1,105 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// VLan.h\r
+// VLan.c のヘッダ\r
+\r
+#ifndef        VLAN_H\r
+#define        VLAN_H\r
+\r
+// VLAN 関係のパラメータ\r
+struct VLAN_PARAM\r
+{\r
+       UCHAR MacAddress[6];\r
+       UCHAR Padding[2];\r
+};\r
+\r
+#ifdef OS_WIN32\r
+\r
+// Win32 用\r
+#include <Cedar/VLanWin32.h>\r
+\r
+#else  // OS_WIN32\r
+\r
+// UNIX 用\r
+#include <Cedar/VLanUnix.h>\r
+\r
+#endif // OS_WIN32\r
+\r
+#endif // VLAN_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLanUnix.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLanUnix.c
new file mode 100644 (file)
index 0000000..b14efa9
--- /dev/null
@@ -0,0 +1,782 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// VLanUnix.c\r
+// UNIX 用仮想デバイスドライバライブラリ\r
+\r
+#ifdef VLAN_C\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+\r
+#ifdef OS_UNIX\r
+\r
+static LIST *unix_vlan = NULL;\r
+\r
+#ifndef        NO_VLAN\r
+\r
+// PACKET_ADAPTER の取得\r
+PACKET_ADAPTER *VLanGetPacketAdapter()\r
+{\r
+       PACKET_ADAPTER *pa;\r
+\r
+       pa = NewPacketAdapter(VLanPaInit, VLanPaGetCancel,\r
+               VLanPaGetNextPacket, VLanPaPutPacket, VLanPaFree);\r
+       if (pa == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return pa;\r
+}\r
+\r
+// PA 初期化\r
+bool VLanPaInit(SESSION *s)\r
+{\r
+       VLAN *v;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ドライバに接続\r
+       v = NewVLan(s->ClientOption->DeviceName, NULL);\r
+       if (v == NULL)\r
+       {\r
+               // 失敗\r
+               return false;\r
+       }\r
+\r
+       s->PacketAdapter->Param = v;\r
+\r
+       return true;\r
+}\r
+\r
+// キャンセルオブジェクトの取得\r
+CANCEL *VLanPaGetCancel(SESSION *s)\r
+{\r
+       VLAN *v;\r
+       // 引数チェック\r
+       if ((s == NULL) || ((v = s->PacketAdapter->Param) == NULL))\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return VLanGetCancel(v);\r
+}\r
+\r
+// パケットアダプタの解放\r
+void VLanPaFree(SESSION *s)\r
+{\r
+       VLAN *v;\r
+       // 引数チェック\r
+       if ((s == NULL) || ((v = s->PacketAdapter->Param) == NULL))\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 仮想 LAN カードの終了\r
+       FreeVLan(v);\r
+\r
+       s->PacketAdapter->Param = NULL;\r
+}\r
+\r
+// パケットの書き込み\r
+bool VLanPaPutPacket(SESSION *s, void *data, UINT size)\r
+{\r
+       VLAN *v;\r
+       // 引数チェック\r
+       if ((s == NULL) || ((v = s->PacketAdapter->Param) == NULL))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return VLanPutPacket(v, data, size);\r
+}\r
+\r
+// 次のパケットを取得\r
+UINT VLanPaGetNextPacket(SESSION *s, void **data)\r
+{\r
+       VLAN *v;\r
+       UINT size;\r
+       // 引数チェック\r
+       if (data == NULL || (s == NULL) || ((v = s->PacketAdapter->Param) == NULL))\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       if (VLanGetNextPacket(v, data, &size) == false)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return size;\r
+}\r
+\r
+// パケットを仮想 LAN カードに書き込む\r
+bool VLanPutPacket(VLAN *v, void *buf, UINT size)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (v->Halt)\r
+       {\r
+               return false;\r
+       }\r
+       if (size > MAX_PACKET_SIZE)\r
+       {\r
+               return false;\r
+       }\r
+       if (buf == NULL || size == 0)\r
+       {\r
+               if (buf != NULL)\r
+               {\r
+                       Free(buf);\r
+               }\r
+               return true;\r
+       }\r
+\r
+       ret = write(v->fd, buf, size);\r
+\r
+       if (ret >= 1)\r
+       {\r
+               Free(buf);\r
+               return true;\r
+       }\r
+\r
+       if (errno == EAGAIN || ret == 0)\r
+       {\r
+               Free(buf);\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// 仮想 LAN カードから次のパケットを取得する\r
+bool VLanGetNextPacket(VLAN *v, void **buf, UINT *size)\r
+{\r
+       UCHAR tmp[TAP_READ_BUF_SIZE];\r
+       int ret;\r
+       // 引数チェック\r
+       if (v == NULL || buf == NULL || size == 0)\r
+       {\r
+               return false;\r
+       }\r
+       if (v->Halt)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 読み込み\r
+       ret = read(v->fd, tmp, sizeof(tmp));\r
+\r
+       if (ret == 0 ||\r
+               (ret == -1 && errno == EAGAIN))\r
+       {\r
+               // パケット無し\r
+               *buf = NULL;\r
+               *size = 0;\r
+               return true;\r
+       }\r
+       else if (ret == -1 || ret > TAP_READ_BUF_SIZE)\r
+       {\r
+               // エラー\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               // パケット読み込み成功\r
+               *buf = Malloc(ret);\r
+               Copy(*buf, tmp, ret);\r
+               *size = ret;\r
+               return true;\r
+       }\r
+}\r
+\r
+// キャンセルオブジェクトの取得\r
+CANCEL *VLanGetCancel(VLAN *v)\r
+{\r
+       CANCEL *c;\r
+       int fd;\r
+       int yes = 0;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       c = NewCancel();\r
+       UnixDeletePipe(c->pipe_read, c->pipe_write);\r
+       c->pipe_read = c->pipe_write = -1;\r
+\r
+       fd = v->fd;\r
+\r
+#ifndef        UNIX_MACOS\r
+       UnixSetSocketNonBlockingMode(fd, true);\r
+#else  // UNIX_MACOS\r
+       UnixSetSocketNonBlockingMode(fd, false);\r
+#endif // UNIX_MACOS\r
+\r
+       c->SpecialFlag = true;\r
+       c->pipe_read = fd;\r
+\r
+       return c;\r
+}\r
+\r
+// 仮想 LAN カードを閉じる\r
+void FreeVLan(VLAN *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(v->InstanceName);\r
+\r
+       Free(v);\r
+}\r
+\r
+// tap の作成\r
+VLAN *NewTap(char *name, char *mac_address)\r
+{\r
+       int fd;\r
+       VLAN *v;\r
+       // 引数チェック\r
+       if (name == NULL || mac_address == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       fd = UnixCreateTapDeviceEx(name, "tap", mac_address);\r
+       if (fd == -1)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       v = ZeroMalloc(sizeof(VLAN));\r
+       v->Halt = false;\r
+       v->InstanceName = CopyStr(name);\r
+       v->fd = fd;\r
+\r
+       return v;\r
+}\r
+\r
+// tap を閉じる\r
+void FreeTap(VLAN *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       close(v->fd);\r
+       FreeVLan(v);\r
+}\r
+\r
+// 仮想 LAN カードの取得\r
+VLAN *NewVLan(char *instance_name, VLAN_PARAM *param)\r
+{\r
+       int fd;\r
+       VLAN *v;\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // tap を開く\r
+       fd = UnixVLanGet(instance_name);\r
+       if (fd == -1)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       v = ZeroMalloc(sizeof(VLAN));\r
+       v->Halt = false;\r
+       v->InstanceName = CopyStr(instance_name);\r
+       v->fd = fd;\r
+\r
+       return v;\r
+}\r
+\r
+// tap デバイスの作成\r
+int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address)\r
+{\r
+       int fd;\r
+       struct ifreq ifr;\r
+       char eth_name[MAX_SIZE];\r
+       char instance_name_lower[MAX_SIZE];\r
+       struct sockaddr sa;\r
+       char *tap_name = TAP_FILENAME_1;\r
+       int s;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return -1;\r
+       }\r
+\r
+       // デバイス名を生成\r
+       StrCpy(instance_name_lower, sizeof(instance_name_lower), name);\r
+       Trim(instance_name_lower);\r
+       StrLower(instance_name_lower);\r
+       Format(eth_name, sizeof(eth_name), "%s_%s", prefix, instance_name_lower);\r
+\r
+       eth_name[15] = 0;\r
+\r
+       // tun/tap を開く\r
+#ifndef        UNIX_MACOS\r
+       if (GetOsInfo()->OsType == OSTYPE_LINUX)\r
+       {\r
+               // Linux\r
+               if (IsFile(TAP_FILENAME_1) == false)\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+\r
+                       Format(tmp, sizeof(tmp), "%s c 10 200", TAP_FILENAME_1);\r
+                       Run("mknod", tmp, true, true);\r
+\r
+                       Format(tmp, sizeof(tmp), "600 %s", TAP_FILENAME_1);\r
+                       Run("chmod", tmp, true, true);\r
+               }\r
+       }\r
+       // MacOS X 以外\r
+       fd = open(TAP_FILENAME_1, O_RDWR);\r
+       if (fd == -1)\r
+       {\r
+               // 失敗\r
+               fd = open(TAP_FILENAME_2, O_RDWR);\r
+               if (fd == -1)\r
+               {\r
+                       return -1;\r
+               }\r
+               tap_name = TAP_FILENAME_2;\r
+       }\r
+#else  // UNIX_MACOS\r
+       // MacOS X\r
+       fd = open(TAP_MACOS_FILENAME, O_RDWR);\r
+       if (fd == -1)\r
+       {\r
+               return -1;\r
+       }\r
+       tap_name = TAP_MACOS_FILENAME;\r
+#endif // UNIX_MACOS\r
+\r
+#ifdef UNIX_LINUX\r
+       // Linux 用 tap の作成\r
+\r
+       // デバイス名設定\r
+       Zero(&ifr, sizeof(ifr));\r
+\r
+       ifr.ifr_flags = IFF_TAP | IFF_NO_PI;\r
+       StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), eth_name);\r
+\r
+       if (ioctl(fd, TUNSETIFF, &ifr) == -1)\r
+       {\r
+               // 失敗\r
+               close(fd);\r
+               return -1;\r
+       }\r
+\r
+       // MAC アドレス設定\r
+       s = socket(AF_INET, SOCK_DGRAM, 0);\r
+       if (s != -1)\r
+       {\r
+               if (mac_address != NULL)\r
+               {\r
+                       Zero(&ifr, sizeof(ifr));\r
+                       StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), eth_name);\r
+                       ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;\r
+                       Copy(&ifr.ifr_hwaddr.sa_data, mac_address, 6);\r
+                       ioctl(s, SIOCSIFHWADDR, &ifr);\r
+               }\r
+\r
+               Zero(&ifr, sizeof(ifr));\r
+               StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), eth_name);\r
+               ioctl(s, SIOCGIFFLAGS, &ifr);\r
+\r
+               ifr.ifr_flags |= IFF_UP;\r
+               ioctl(s, SIOCSIFFLAGS, &ifr);\r
+\r
+               close(s);\r
+       }\r
+\r
+#else  // UNIX_LINUX\r
+#ifdef UNIX_SOLARIS\r
+       // Solaris 用 tap の作成\r
+       {\r
+               int ip_fd;\r
+               int tun_fd;\r
+               int ppa;\r
+\r
+               tun_fd = open(tap_name, O_RDWR);\r
+               if (tun_fd == -1)\r
+               {\r
+                       // 失敗\r
+                       close(fd);\r
+                       return -1;\r
+               }\r
+\r
+               ip_fd = open("/dev/ip", O_RDWR);\r
+               if (ip_fd == -1)\r
+               {\r
+                       // 失敗\r
+                       close(tun_fd);\r
+                       close(fd);\r
+                       return -1;\r
+               }\r
+\r
+               ppa = -1;\r
+               ppa = ioctl(tun_fd, TUNNEWPPA, ppa);\r
+               if (ppa == -1)\r
+               {\r
+                       // 失敗\r
+                       close(tun_fd);\r
+                       close(fd);\r
+                       close(ip_fd);\r
+                       return -1;\r
+               }\r
+\r
+               if (ioctl(fd, I_PUSH, "ip") < 0)\r
+               {\r
+                       // 失敗\r
+                       close(tun_fd);\r
+                       close(fd);\r
+                       close(ip_fd);\r
+                       return -1;\r
+               }\r
+\r
+               if (ioctl(fd, IF_UNITSEL, (char *)&ppa) < 0)\r
+               {\r
+                       // 失敗\r
+                       close(tun_fd);\r
+                       close(fd);\r
+                       close(ip_fd);\r
+                       return -1;\r
+               }\r
+\r
+               if (ioctl(ip_fd, I_LINK, fd) < 0)\r
+               {\r
+                       // 失敗\r
+                       close(tun_fd);\r
+                       close(fd);\r
+                       close(ip_fd);\r
+                       return -1;\r
+               }\r
+\r
+               close(tun_fd);\r
+               close(ip_fd);\r
+       }\r
+\r
+#endif // UNIX_SOLARIS\r
+#endif // UNIX_LINUX\r
+\r
+       return fd;\r
+}\r
+int UnixCreateTapDevice(char *name, UCHAR *mac_address)\r
+{\r
+       return UnixCreateTapDeviceEx(name, "utvpn", mac_address);\r
+}\r
+\r
+// tap デバイスを閉じる\r
+void UnixCloseTapDevice(int fd)\r
+{\r
+       // 引数チェック\r
+       if (fd == -1)\r
+       {\r
+               return;\r
+       }\r
+\r
+       close(fd);\r
+}\r
+\r
+#else  // NO_VLAN\r
+\r
+void UnixCloseTapDevice(int fd)\r
+{\r
+}\r
+\r
+int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address)\r
+{\r
+       return -1;\r
+}\r
+int UnixCreateTapDevice(char *name, UCHAR *mac_address)\r
+{\r
+       return -1;\r
+}\r
+\r
+#endif // NO_VLAN\r
+\r
+// VLAN リストの比較\r
+int UnixCompareVLan(void *p1, void *p2)\r
+{\r
+       UNIX_VLAN_LIST *v1, *v2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       v1 = *(UNIX_VLAN_LIST **)p1;\r
+       v2 = *(UNIX_VLAN_LIST **)p2;\r
+       if (v1 == NULL || v2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCmpi(v1->Name, v2->Name);\r
+}\r
+\r
+// VLAN リストの初期化\r
+void UnixVLanInit()\r
+{\r
+       unix_vlan = NewList(UnixCompareVLan);\r
+}\r
+\r
+// VLAN の作成\r
+bool UnixVLanCreateEx(char *name, char *prefix, UCHAR *mac_address)\r
+{\r
+       // 引数チェック\r
+       char tmp[MAX_SIZE];\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), name);\r
+       Trim(tmp);\r
+       name = tmp;\r
+\r
+       LockList(unix_vlan);\r
+       {\r
+               UNIX_VLAN_LIST *t, tt;\r
+               int fd;\r
+\r
+               // 同一名のデバイスが存在していないかどうかチェック\r
+               Zero(&tt, sizeof(tt));\r
+               StrCpy(tt.Name, sizeof(tt.Name), name);\r
+\r
+               t = Search(unix_vlan, &tt);\r
+               if (t != NULL)\r
+               {\r
+                       // すでに存在する\r
+                       UnlockList(unix_vlan);\r
+                       return false;\r
+               }\r
+\r
+               // tap デバイスを作成\r
+               fd = UnixCreateTapDeviceEx(name, prefix, mac_address);\r
+               if (fd == -1)\r
+               {\r
+                       // 作成失敗\r
+                       UnlockList(unix_vlan);\r
+                       return false;\r
+               }\r
+\r
+               t = ZeroMalloc(sizeof(UNIX_VLAN_LIST));\r
+               t->fd = fd;\r
+               StrCpy(t->Name, sizeof(t->Name), name);\r
+\r
+               Insert(unix_vlan, t);\r
+       }\r
+       UnlockList(unix_vlan);\r
+\r
+       return true;\r
+}\r
+bool UnixVLanCreate(char *name, UCHAR *mac_address)\r
+{\r
+       return UnixVLanCreateEx(name, "utvpn", mac_address);\r
+}\r
+\r
+// VLAN の列挙\r
+TOKEN_LIST *UnixVLanEnum()\r
+{\r
+       TOKEN_LIST *ret;\r
+       UINT i;\r
+       if (unix_vlan == NULL)\r
+       {\r
+               return NullToken();\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(TOKEN_LIST));\r
+\r
+       LockList(unix_vlan);\r
+       {\r
+               ret->NumTokens = LIST_NUM(unix_vlan);\r
+               ret->Token = ZeroMalloc(sizeof(char *) * ret->NumTokens);\r
+\r
+               for (i = 0;i < ret->NumTokens;i++)\r
+               {\r
+                       UNIX_VLAN_LIST *t = LIST_DATA(unix_vlan, i);\r
+\r
+                       ret->Token[i] = CopyStr(t->Name);\r
+               }\r
+       }\r
+       UnlockList(unix_vlan);\r
+\r
+       return ret;\r
+}\r
+\r
+// VLAN の削除\r
+void UnixVLanDelete(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL || unix_vlan == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(unix_vlan);\r
+       {\r
+               UINT i;\r
+               UNIX_VLAN_LIST *t, tt;\r
+\r
+               Zero(&tt, sizeof(tt));\r
+               StrCpy(tt.Name, sizeof(tt.Name), name);\r
+\r
+               t = Search(unix_vlan, &tt);\r
+               if (t != NULL)\r
+               {\r
+                       UnixCloseTapDevice(t->fd);\r
+                       Delete(unix_vlan, t);\r
+                       Free(t);\r
+               }\r
+       }\r
+       UnlockList(unix_vlan);\r
+}\r
+\r
+// VLAN の取得\r
+int UnixVLanGet(char *name)\r
+{\r
+       int fd = -1;\r
+       // 引数チェック\r
+       if (name == NULL || unix_vlan == NULL)\r
+       {\r
+               return -1;\r
+       }\r
+\r
+       LockList(unix_vlan);\r
+       {\r
+               UINT i;\r
+               UNIX_VLAN_LIST *t, tt;\r
+\r
+               Zero(&tt, sizeof(tt));\r
+               StrCpy(tt.Name, sizeof(tt.Name), name);\r
+\r
+               t = Search(unix_vlan, &tt);\r
+               if (t != NULL)\r
+               {\r
+                       fd = t->fd;\r
+               }\r
+       }\r
+       UnlockList(unix_vlan);\r
+\r
+       return fd;\r
+}\r
+\r
+// VLAN リストの解放\r
+void UnixVLanFree()\r
+{\r
+       UINT i;\r
+\r
+       for (i = 0;i < LIST_NUM(unix_vlan);i++)\r
+       {\r
+               UNIX_VLAN_LIST *t = LIST_DATA(unix_vlan, i);\r
+\r
+               UnixCloseTapDevice(t->fd);\r
+               Free(t);\r
+       }\r
+\r
+       ReleaseList(unix_vlan);\r
+       unix_vlan = NULL;\r
+}\r
+\r
+#endif // OS_UNIX\r
+\r
+#endif // VLAN_C\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLanUnix.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLanUnix.h
new file mode 100644 (file)
index 0000000..4d8282c
--- /dev/null
@@ -0,0 +1,137 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// VLanUnix.h\r
+// VLanUnix.c のヘッダ\r
+\r
+#ifndef        VLANUNIX_H\r
+#define        VLANUNIX_H\r
+\r
+// 定数\r
+#define        TAP_READ_BUF_SIZE                       1600\r
+\r
+#ifndef        NO_VLAN\r
+\r
+// VLAN 構造体\r
+struct VLAN\r
+{\r
+       volatile bool Halt;                     // 停止フラグ\r
+       char *InstanceName;                     // インスタンス名\r
+       int fd;                                         // ファイル\r
+};\r
+\r
+// 関数プロトタイプ\r
+VLAN *NewVLan(char *instance_name, VLAN_PARAM *param);\r
+VLAN *NewTap(char *name, char *mac_address);\r
+void FreeVLan(VLAN *v);\r
+CANCEL *VLanGetCancel(VLAN *v);\r
+bool VLanGetNextPacket(VLAN *v, void **buf, UINT *size);\r
+bool VLanPutPacket(VLAN *v, void *buf, UINT size);\r
+\r
+PACKET_ADAPTER *VLanGetPacketAdapter();\r
+bool VLanPaInit(SESSION *s);\r
+CANCEL *VLanPaGetCancel(SESSION *s);\r
+UINT VLanPaGetNextPacket(SESSION *s, void **data);\r
+bool VLanPaPutPacket(SESSION *s, void *data, UINT size);\r
+void VLanPaFree(SESSION *s);\r
+\r
+#else  // NO_VLAN\r
+\r
+#define        VLanGetPacketAdapter    NullGetPacketAdapter\r
+\r
+#endif // NO_VLAN\r
+\r
+struct UNIX_VLAN_LIST\r
+{\r
+       char Name[MAX_SIZE];            // デバイス名\r
+       int fd;                                         // fd\r
+};\r
+\r
+int UnixCreateTapDevice(char *name, UCHAR *mac_address);\r
+int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address);\r
+void UnixCloseTapDevice(int fd);\r
+void UnixVLanInit();\r
+void UnixVLanFree();\r
+bool UnixVLanCreate(char *name, UCHAR *mac_address);\r
+bool UnixVLanCreateEx(char *name, char *prefix, UCHAR *mac_address);\r
+TOKEN_LIST *UnixVLanEnum();\r
+void UnixVLanDelete(char *name);\r
+int UnixVLanGet(char *name);\r
+int UnixCompareVLan(void *p1, void *p2);\r
+\r
+#endif // VLANUNIX_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLanWin32.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLanWin32.c
new file mode 100644 (file)
index 0000000..a95007c
--- /dev/null
@@ -0,0 +1,1406 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// VLanWin32.c\r
+// Win32 用仮想デバイスドライバライブラリ\r
+\r
+#ifdef VLAN_C\r
+\r
+#include <windows.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+\r
+#ifdef OS_WIN32\r
+\r
+typedef DWORD(CALLBACK* OPENVXDHANDLE)(HANDLE);\r
+\r
+// Windows のバージョン情報の取得\r
+void Win32GetWinVer(RPC_WINVER *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(v, sizeof(RPC_WINVER));\r
+\r
+       v->IsWindows = true;\r
+\r
+       if (OS_IS_WINDOWS_NT(GetOsType()) == false)\r
+       {\r
+               // Windows 9x\r
+               OSVERSIONINFO os;\r
+               Zero(&os, sizeof(os));\r
+               os.dwOSVersionInfoSize = sizeof(os);\r
+               GetVersionEx(&os);\r
+\r
+               v->Build = LOWORD(os.dwBuildNumber);\r
+               v->VerMajor = os.dwMajorVersion;\r
+               v->VerMinor = os.dwMinorVersion;\r
+\r
+               Format(v->Title, sizeof(v->Title), "%s %s",\r
+                       GetOsInfo()->OsProductName,\r
+                       GetOsInfo()->OsVersion);\r
+               Trim(v->Title);\r
+       }\r
+       else\r
+       {\r
+               // Windows NT 4.0 SP6 以降\r
+               OSVERSIONINFOEX os;\r
+               Zero(&os, sizeof(os));\r
+               os.dwOSVersionInfoSize = sizeof(os);\r
+               GetVersionEx((LPOSVERSIONINFOA)&os);\r
+\r
+               v->IsNT = true;\r
+               v->Build = os.dwBuildNumber;\r
+               v->ServicePack = os.wServicePackMajor;\r
+\r
+               if (os.wProductType != VER_NT_WORKSTATION)\r
+               {\r
+                       v->IsServer = true;\r
+               }\r
+               v->VerMajor = os.dwMajorVersion;\r
+               v->VerMinor = os.dwMinorVersion;\r
+\r
+               if (GetOsInfo()->OsServicePack == 0)\r
+               {\r
+                       StrCpy(v->Title, sizeof(v->Title), GetOsInfo()->OsProductName);\r
+               }\r
+               else\r
+               {\r
+                       Format(v->Title, sizeof(v->Title), "%s Service Pack %u",\r
+                               GetOsInfo()->OsProductName,\r
+                               GetOsInfo()->OsServicePack);\r
+               }\r
+               Trim(v->Title);\r
+\r
+               if (InStr(GetOsInfo()->OsVersion, "rc") ||\r
+                       InStr(GetOsInfo()->OsVersion, "beta"))\r
+               {\r
+                       v->IsBeta = true;\r
+               }\r
+       }\r
+}\r
+\r
+// すべての仮想 LAN カードの DHCP アドレスを解放する\r
+void Win32ReleaseAllDhcp9x(bool wait)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+\r
+       t = MsEnumNetworkAdapters(VLAN_ADAPTER_NAME, "---dummy-string-ut--");\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               char *name = t->Token[i];\r
+               UINT id = GetInstanceId(name);\r
+               if (id != 0)\r
+               {\r
+                       Win32ReleaseDhcp9x(id, wait);\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+}\r
+\r
+// ルーティングテーブル追跡メイン\r
+void RouteTrackingMain(SESSION *s)\r
+{\r
+       ROUTE_TRACKING *t;\r
+       UINT64 now;\r
+       ROUTE_TABLE *table;\r
+       ROUTE_ENTRY *rs;\r
+       bool changed = false;\r
+       bool check = false;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (s->ClientModeAndUseVLan == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 状態の取得\r
+       t = ((VLAN *)s->PacketAdapter->Param)->RouteState;\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 現在時刻\r
+       PROBE_STR("RouteTrackingMain 1");\r
+       now = Tick64();\r
+\r
+       if (t->RouteChange != NULL)\r
+       {\r
+               if (t->NextRouteChangeCheckTime == 0 ||\r
+                       t->NextRouteChangeCheckTime <= now)\r
+               {\r
+                       t->NextRouteChangeCheckTime = now + 1000ULL;\r
+\r
+                       check = IsRouteChanged(t->RouteChange);\r
+\r
+                       if (check)\r
+                       {\r
+                               Debug("*** Routing Table Changed ***\n");\r
+                               t->NextTrackingTime = 0;\r
+                       }\r
+               }\r
+       }\r
+       if (t->NextTrackingTime != 0 && t->NextTrackingTime > now)\r
+       {\r
+               PROBE_STR("RouteTrackingMain 2");\r
+               return;\r
+       }\r
+       PROBE_STR("RouteTrackingMain 3");\r
+\r
+       // 現在のルーティングテーブルを取得\r
+       table = GetRouteTable();\r
+       rs = t->RouteToServer;\r
+       if (table != NULL)\r
+       {\r
+               UINT i;\r
+               bool route_to_server_erased = true;\r
+               bool is_vlan_want_to_be_default_gateway = false;\r
+               UINT vlan_default_gatewat_metric = 0;\r
+               UINT other_if_default_gateway_metric_min = INFINITE;\r
+\r
+               // ルーティングテーブルが変更されたかどうか取得\r
+               if (t->LastRoutingTableHash != table->HashedValue)\r
+               {\r
+                       t->LastRoutingTableHash = table->HashedValue;\r
+                       changed = true;\r
+               }\r
+\r
+               //DebugPrintRouteTable(table);\r
+\r
+               // ルーティングテーブルを走査\r
+               for (i = 0;i < table->NumEntry;i++)\r
+               {\r
+                       ROUTE_ENTRY *e = table->Entry[i];\r
+\r
+                       if (rs != NULL)\r
+                       {\r
+                               if (CmpIpAddr(&e->DestIP, &rs->DestIP) == 0 &&\r
+                                       CmpIpAddr(&e->DestMask, &rs->DestMask) == 0\r
+//                                     && CmpIpAddr(&e->GatewayIP, &rs->GatewayIP) == 0\r
+//                                     && e->InterfaceID == rs->InterfaceID &&\r
+//                                     e->LocalRouting == rs->LocalRouting &&\r
+//                                     e->Metric == rs->Metric\r
+                                       )\r
+                               {\r
+                                       // 接続時に追加したサーバーへのルーティングテーブルが見つかった\r
+                                       route_to_server_erased = false;\r
+                               }\r
+                       }\r
+\r
+                       // デフォルトゲートウェイの検索\r
+                       if (IPToUINT(&e->DestIP) == 0 &&\r
+                               IPToUINT(&e->DestMask) == 0)\r
+                       {\r
+                               //Debug("e->InterfaceID = %u, t->VLanInterfaceId = %u\n",\r
+                               //      e->InterfaceID, t->VLanInterfaceId);\r
+\r
+                               if (e->InterfaceID == t->VLanInterfaceId)\r
+                               {\r
+                                       // 仮想 LAN カードがデフォルトゲートウェイになりたいと思っている\r
+                                       is_vlan_want_to_be_default_gateway = true;\r
+                                       vlan_default_gatewat_metric = e->Metric;\r
+\r
+                                       if (vlan_default_gatewat_metric >= 2 &&\r
+                                               t->OldDefaultGatewayMetric == (vlan_default_gatewat_metric - 1))\r
+                                       {\r
+                                               // PPP サーバーが勝手に\r
+                                               // ルーティングテーブルを書き換えたので戻す\r
+                                               DeleteRouteEntry(e);\r
+                                               e->Metric--;\r
+                                               AddRouteEntry(e);\r
+                                               Debug("** Restore metric destroyed by PPP.\n");\r
+                                       }\r
+\r
+                                       // このエントリを保存しておく\r
+                                       if (t->DefaultGatewayByVLan != NULL)\r
+                                       {\r
+                                               // 前回追加したものがあれば削除する\r
+                                               FreeRouteEntry(t->DefaultGatewayByVLan);\r
+                                       }\r
+\r
+                                       t->DefaultGatewayByVLan = ZeroMalloc(sizeof(ROUTE_ENTRY));\r
+                                       Copy(t->DefaultGatewayByVLan, e, sizeof(ROUTE_ENTRY));\r
+\r
+                                       t->OldDefaultGatewayMetric = vlan_default_gatewat_metric;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 仮想 LAN カード以外にデフォルトゲートウェイが存在している\r
+                                       // このデフォルトゲートウェイのメトリック値を記録しておく\r
+                                       if (other_if_default_gateway_metric_min > e->Metric)\r
+                                       {\r
+                                               // Windows Vista の場合はすべての PPP 接続のメトリック値は無視する\r
+                                               if (MsIsVista() == false || e->PPPConnection == false)\r
+                                               {\r
+                                                       other_if_default_gateway_metric_min = e->Metric;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       // Windows Vista を使用しており PPP を使ってネットワーク\r
+                                                       // に接続している\r
+                                                       t->VistaAndUsingPPP = true;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (t->VistaAndUsingPPP)\r
+               {\r
+                       if (t->DefaultGatewayByVLan != NULL)\r
+                       {\r
+                               if (is_vlan_want_to_be_default_gateway)\r
+                               {\r
+                                       if (t->VistaOldDefaultGatewayByVLan == NULL || Cmp(t->VistaOldDefaultGatewayByVLan, t->DefaultGatewayByVLan, sizeof(ROUTE_ENTRY)) != 0)\r
+                                       {\r
+                                               ROUTE_ENTRY *e;\r
+                                               // Windows Vista で PPP を使用して接続しており、かつ\r
+                                               // 仮想 LAN カードがデフォルトゲートウェイになるべき場合は\r
+                                               // 0.0.0.0/128.0.0.0 および 128.0.0.0/128.0.0.0 のルートを\r
+                                               // システムに追加する\r
+\r
+                                               if (t->VistaOldDefaultGatewayByVLan != NULL)\r
+                                               {\r
+                                                       FreeRouteEntry(t->VistaOldDefaultGatewayByVLan);\r
+                                               }\r
+\r
+                                               if (t->VistaDefaultGateway1 != NULL)\r
+                                               {\r
+                                                       DeleteRouteEntry(t->VistaDefaultGateway1);\r
+                                                       FreeRouteEntry(t->VistaDefaultGateway1);\r
+\r
+                                                       DeleteRouteEntry(t->VistaDefaultGateway2);\r
+                                                       FreeRouteEntry(t->VistaDefaultGateway2);\r
+                                               }\r
+\r
+                                               t->VistaOldDefaultGatewayByVLan = Clone(t->DefaultGatewayByVLan, sizeof(ROUTE_ENTRY));\r
+\r
+                                               e = Clone(t->DefaultGatewayByVLan, sizeof(ROUTE_ENTRY));\r
+                                               SetIP(&e->DestIP, 0, 0, 0, 0);\r
+                                               SetIP(&e->DestMask, 128, 0, 0, 0);\r
+                                               t->VistaDefaultGateway1 = e;\r
+\r
+                                               e = Clone(t->DefaultGatewayByVLan, sizeof(ROUTE_ENTRY));\r
+                                               SetIP(&e->DestIP, 128, 0, 0, 0);\r
+                                               SetIP(&e->DestMask, 128, 0, 0, 0);\r
+                                               t->VistaDefaultGateway2 = e;\r
+\r
+                                               AddRouteEntry(t->VistaDefaultGateway1);\r
+                                               AddRouteEntry(t->VistaDefaultGateway2);\r
+\r
+                                               Debug("Vista PPP Fix Route Table Added.\n");\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (t->VistaOldDefaultGatewayByVLan != NULL)\r
+                                       {\r
+                                               FreeRouteEntry(t->VistaOldDefaultGatewayByVLan);\r
+                                               t->VistaOldDefaultGatewayByVLan = NULL;\r
+                                       }\r
+\r
+                                       if (t->VistaDefaultGateway1 != NULL)\r
+                                       {\r
+                                               Debug("Vista PPP Fix Route Table Deleted.\n");\r
+                                               DeleteRouteEntry(t->VistaDefaultGateway1);\r
+                                               FreeRouteEntry(t->VistaDefaultGateway1);\r
+\r
+                                               DeleteRouteEntry(t->VistaDefaultGateway2);\r
+                                               FreeRouteEntry(t->VistaDefaultGateway2);\r
+\r
+                                               t->VistaDefaultGateway1 = t->VistaDefaultGateway2 = NULL;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // 仮想 LAN カードがデフォルトゲートウェイになることを希望しており\r
+               // かつ仮想 LAN カードの 0.0.0.0/0.0.0.0 のメトリック値よりも小さなメトリック値の\r
+               // LAN カードが他に 1 枚も無い場合は、他のデフォルトゲートウェイエントリを削除して\r
+               // 仮想 LAN カードをデフォルトゲートウェイに強制的に選出する\r
+               if (is_vlan_want_to_be_default_gateway && (rs != NULL && route_to_server_erased == false) &&\r
+                       other_if_default_gateway_metric_min >= vlan_default_gatewat_metric)\r
+               {\r
+                       // 再度ルーティングテーブルを走査\r
+                       for (i = 0;i < table->NumEntry;i++)\r
+                       {\r
+                               ROUTE_ENTRY *e = table->Entry[i];\r
+\r
+                               if (e->InterfaceID != t->VLanInterfaceId)\r
+                               {\r
+                                       if (IPToUINT(&e->DestIP) == 0 &&\r
+                                       IPToUINT(&e->DestMask) == 0)\r
+                                       {\r
+                                               char str[64];\r
+                                               // デフォルトゲートウェイを発見\r
+                                               ROUTE_ENTRY *r = ZeroMalloc(sizeof(ROUTE_ENTRY));\r
+\r
+                                               Copy(r, e, sizeof(ROUTE_ENTRY));\r
+\r
+                                               // キューに入れておく\r
+                                               InsertQueue(t->DeletedDefaultGateway, r);\r
+\r
+                                               // このゲートウェイエントリを一旦削除する\r
+                                               DeleteRouteEntry(e);\r
+\r
+                                               IPToStr(str, sizeof(str), &e->GatewayIP);\r
+                                               Debug("Default Gateway %s Deleted.\n", str);\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (rs != NULL && route_to_server_erased)\r
+               {\r
+                       // サーバーへの物理的なエントリが消滅している\r
+                       Debug("Route to Server entry ERASED !!!\n");\r
+\r
+                       // 強制切断 (再接続有効)\r
+                       s->RetryFlag = true;\r
+                       s->Halt = true;\r
+               }\r
+\r
+               // ルーティングテーブルを解放\r
+               FreeRouteTable(table);\r
+       }\r
+\r
+       // 次回トラッキングを行う時刻を設定\r
+       if (t->NextTrackingTimeAdd == 0 || changed)\r
+       {\r
+               t->NextTrackingTimeAdd = TRACKING_INTERVAL_INITIAL;\r
+       }\r
+       else\r
+       {\r
+               UINT64 max_value = TRACKING_INTERVAL_MAX;\r
+               if (t->RouteChange != NULL)\r
+               {\r
+                       max_value = TRACKING_INTERVAL_MAX_RC;\r
+               }\r
+\r
+               t->NextTrackingTimeAdd += TRACKING_INTERVAL_ADD;\r
+\r
+               if (t->NextTrackingTimeAdd >= max_value)\r
+               {\r
+                       t->NextTrackingTimeAdd = max_value;\r
+               }\r
+       }\r
+       //Debug("t->NextTrackingTimeAdd = %I64u\n", t->NextTrackingTimeAdd);\r
+       t->NextTrackingTime = now + t->NextTrackingTimeAdd;\r
+}\r
+\r
+// ルーティングテーブルの追跡を開始する\r
+void RouteTrackingStart(SESSION *s)\r
+{\r
+       VLAN *v;\r
+       ROUTE_TRACKING *t;\r
+       UINT if_id = 0;\r
+       ROUTE_ENTRY *e;\r
+       ROUTE_ENTRY *dns = NULL;\r
+       char tmp[64];\r
+       UINT exclude_if_id = 0;\r
+       bool already_exists = false;\r
+       bool already_exists_by_other_account = false;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v = (VLAN *)s->PacketAdapter->Param;\r
+       if (v->RouteState != NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 仮想 LAN カードのインターフェース ID を取得する\r
+       if_id = GetInstanceId(v->InstanceName);\r
+       Debug("[InstanceId of %s] = 0x%x\n", v->InstanceName, if_id);\r
+\r
+       if (MsIsVista())\r
+       {\r
+               // Windows Vista では明示的に仮想 LAN カード本体によるルーティングテーブル\r
+               // を除外しなければならない\r
+               exclude_if_id = if_id;\r
+       }\r
+\r
+       // サーバーまでのルートを取得する\r
+       e = GetBestRouteEntryEx(&s->ServerIP, exclude_if_id);\r
+       if (e == NULL)\r
+       {\r
+               // 取得失敗\r
+               Debug("Failed to get GetBestRouteEntry().\n");\r
+               return;\r
+       }\r
+       IPToStr(tmp, sizeof(tmp), &e->GatewayIP);\r
+       Debug("GetBestRouteEntry() Succeed. [Gateway: %s]\n", tmp);\r
+\r
+       // ルートを追加する\r
+       if (MsIsVista())\r
+       {\r
+               e->Metric = e->OldIfMetric;\r
+       }\r
+       if (AddRouteEntryEx(e, &already_exists) == false)\r
+       {\r
+               FreeRouteEntry(e);\r
+               e = NULL;\r
+       }\r
+       Debug("already_exists: %u\n", already_exists);\r
+\r
+       if (already_exists)\r
+       {\r
+               if (s->Cedar->Client != NULL && s->Account != NULL)\r
+               {\r
+                       UINT i;\r
+                       ACCOUNT *a;\r
+                       for (i = 0;i < LIST_NUM(s->Cedar->Client->AccountList);i++)\r
+                       {\r
+                               a = LIST_DATA(s->Cedar->Client->AccountList, i);\r
+                               Lock(a->lock);\r
+                               {\r
+                                       SESSION *sess = a->ClientSession;\r
+                                       if (sess != NULL && sess != s)\r
+                                       {\r
+                                               VLAN *v = sess->PacketAdapter->Param;\r
+                                               if (v != NULL)\r
+                                               {\r
+                                                       ROUTE_TRACKING *tr = v->RouteState;\r
+                                                       if (tr != NULL && e != NULL)\r
+                                                       {\r
+                                                               if (Cmp(tr->RouteToServer, e, sizeof(ROUTE_ENTRY)) == 0)\r
+                                                               {\r
+                                                                       already_exists_by_other_account = true;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                               Unlock(a->lock);\r
+                       }\r
+               }\r
+\r
+               if (already_exists_by_other_account)\r
+               {\r
+                       Debug("already_exists_by_other_account = %u\n", already_exists_by_other_account);\r
+                       already_exists = false;\r
+               }\r
+       }\r
+\r
+       // DNS サーバーまでのルーティングテーブルを取得する\r
+       dns = GetBestRouteEntryEx(&s->DefaultDns, exclude_if_id);\r
+       if (dns == NULL)\r
+       {\r
+               // 取得失敗\r
+               Debug("Failed to get GetBestRouteEntry DNS.\n");\r
+       }\r
+       else\r
+       {\r
+               // ルートを追加する\r
+               if (MsIsVista())\r
+               {\r
+                       dns->Metric = dns->OldIfMetric;\r
+\r
+                       if (AddRouteEntry(dns) == false)\r
+                       {\r
+                               FreeRouteEntry(dns);\r
+                               dns = NULL;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // 初期化\r
+       if (s->Cedar->Client != NULL && s->Account != NULL)\r
+       {\r
+               Lock(s->Account->lock);\r
+       }\r
+\r
+       t = ZeroMalloc(sizeof(ROUTE_TRACKING));\r
+       v->RouteState = t;\r
+\r
+       t->RouteToServerAlreadyExists = already_exists;\r
+       t->RouteToServer = e;\r
+       t->RouteToDefaultDns = dns;\r
+       t->VLanInterfaceId = if_id;\r
+       t->NextTrackingTime = 0;\r
+       t->DeletedDefaultGateway = NewQueue();\r
+       t->OldDefaultGatewayMetric = 0x7fffffff;\r
+\r
+       if (s->Cedar->Client != NULL && s->Account != NULL)\r
+       {\r
+               Unlock(s->Account->lock);\r
+       }\r
+\r
+       // ネットワーク変更を検出するために\r
+       // 現在のデフォルト DNS サーバーを取得しておく\r
+       GetDefaultDns(&t->OldDnsServer);\r
+\r
+       // DHCP を使用する場合は IP アドレスを解放してすぐに取得する\r
+       if (IsNt())\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               MS_ADAPTER *a;\r
+\r
+               Format(tmp, sizeof(tmp), VLAN_ADAPTER_NAME_TAG, v->InstanceName);\r
+               a = MsGetAdapter(tmp);\r
+\r
+               if (a != NULL)\r
+               {\r
+                       if (a->UseDhcp)\r
+                       {\r
+                               bool ret = Win32ReleaseAddressByGuidEx(a->Guid, 100);\r
+                               Debug("*** Win32ReleaseAddressByGuidEx = %u\n", ret);\r
+\r
+                               ret = Win32RenewAddressByGuidEx(a->Guid, 100);\r
+                               Debug("*** Win32RenewAddressByGuidEx = %u\n", ret);\r
+                       }\r
+\r
+                       MsFreeAdapter(a);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // Win9x の場合\r
+               Win32RenewDhcp9x(if_id);\r
+       }\r
+\r
+       // ルーティングテーブルの変更を検出 (対応 OS のみ)\r
+       t->RouteChange = NewRouteChange();\r
+       Debug("t->RouteChange = 0x%p\n", t->RouteChange);\r
+}\r
+\r
+// ルーティングテーブルの追跡を終了する\r
+void RouteTrackingStop(SESSION *s, ROUTE_TRACKING *t)\r
+{\r
+       ROUTE_ENTRY *e;\r
+       ROUTE_TABLE *table;\r
+       IP dns_ip;\r
+       bool network_has_changed = false;\r
+       bool do_not_delete_routing_entry = false;\r
+       // 引数チェック\r
+       if (s == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&dns_ip, sizeof(dns_ip));\r
+\r
+       // 仮想 LAN カードが追加したデフォルトゲートウェイを削除する\r
+       if (t->DefaultGatewayByVLan != NULL)\r
+       {\r
+               Debug("Default Gateway by VLAN was deleted.\n");\r
+               DeleteRouteEntry(t->DefaultGatewayByVLan);\r
+               FreeRouteEntry(t->DefaultGatewayByVLan);\r
+               t->DefaultGatewayByVLan = NULL;\r
+       }\r
+\r
+       if (t->VistaOldDefaultGatewayByVLan != NULL)\r
+       {\r
+               FreeRouteEntry(t->VistaOldDefaultGatewayByVLan);\r
+       }\r
+\r
+       if (t->VistaDefaultGateway1 != NULL)\r
+       {\r
+               Debug("Vista PPP Fix Route Table Deleted.\n");\r
+               DeleteRouteEntry(t->VistaDefaultGateway1);\r
+               FreeRouteEntry(t->VistaDefaultGateway1);\r
+\r
+               DeleteRouteEntry(t->VistaDefaultGateway2);\r
+               FreeRouteEntry(t->VistaDefaultGateway2);\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               // Windows 9x の場合のみ、仮想 LAN カードの DHCP アドレスを解放する\r
+               Win32ReleaseDhcp9x(t->VLanInterfaceId, false);\r
+       }\r
+\r
+       if (s->Cedar->Client != NULL && s->Account != NULL)\r
+       {\r
+               UINT i;\r
+               ACCOUNT *a;\r
+               for (i = 0;i < LIST_NUM(s->Cedar->Client->AccountList);i++)\r
+               {\r
+                       a = LIST_DATA(s->Cedar->Client->AccountList, i);\r
+                       Lock(a->lock);\r
+                       {\r
+                               SESSION *sess = a->ClientSession;\r
+                               if (sess != NULL && sess != s)\r
+                               {\r
+                                       VLAN *v = sess->PacketAdapter->Param;\r
+                                       if (v != NULL)\r
+                                       {\r
+                                               ROUTE_TRACKING *tr = v->RouteState;\r
+                                               if (tr != NULL)\r
+                                               {\r
+                                                       if (Cmp(tr->RouteToServer, t->RouteToServer, sizeof(ROUTE_ENTRY)) == 0)\r
+                                                       {\r
+                                                               do_not_delete_routing_entry = true;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       Unlock(a->lock);\r
+               }\r
+\r
+               Lock(s->Account->lock);\r
+       }\r
+\r
+       if (do_not_delete_routing_entry == false)\r
+       {\r
+               // 最初に追加したルートを削除する\r
+               if (t->RouteToServerAlreadyExists == false)\r
+               {\r
+                       DeleteRouteEntry(t->RouteToServer);\r
+               }\r
+\r
+               DeleteRouteEntry(t->RouteToDefaultDns);\r
+       }\r
+\r
+       FreeRouteEntry(t->RouteToDefaultDns);\r
+       FreeRouteEntry(t->RouteToServer);\r
+       t->RouteToDefaultDns = t->RouteToServer = NULL;\r
+\r
+       if (s->Cedar->Client != NULL && s->Account != NULL)\r
+       {\r
+               Unlock(s->Account->lock);\r
+       }\r
+\r
+#if    0\r
+       // 現在の DNS サーバーを取得する\r
+       if (GetDefaultDns(&dns_ip))\r
+       {\r
+               if (IPToUINT(&t->OldDnsServer) != 0)\r
+               {\r
+                       if (IPToUINT(&t->OldDnsServer) != IPToUINT(&dns_ip))\r
+                       {\r
+                               char s1[MAX_SIZE], s2[MAX_SIZE];\r
+                               network_has_changed = true;\r
+                               IPToStr(s1, sizeof(s1), &t->OldDnsServer);\r
+                               IPToStr(s2, sizeof(s2), &dns_ip);\r
+                               Debug("Old Dns: %s, New Dns: %s\n",\r
+                                       s1, s2);\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (network_has_changed == false)\r
+       {\r
+               Debug("Network: not changed.\n");\r
+       }\r
+       else\r
+       {\r
+               Debug("Network: Changed.\n");\r
+       }\r
+\r
+#endif\r
+\r
+       // 現在のルーティングテーブルを取得する\r
+       table = GetRouteTable();\r
+\r
+       // これまで削除してきたルーティングテーブルを復元する\r
+       while (e = GetNext(t->DeletedDefaultGateway))\r
+       {\r
+               bool restore = true;\r
+               UINT i;\r
+               // 復元しようとしているルーティングテーブルがデフォルトゲートウェイの場合\r
+               // かつ既存のルーティングテーブルでそのインターフェースによるデフォルト\r
+               // ルートが 1 つでも登録されている場合は復元しない\r
+               if (IPToUINT(&e->DestIP) == 0 && IPToUINT(&e->DestMask) == 0)\r
+               {\r
+                       for (i = 0;i < table->NumEntry;i++)\r
+                       {\r
+                               ROUTE_ENTRY *r = table->Entry[i];\r
+                               if (IPToUINT(&r->DestIP) == 0 && IPToUINT(&r->DestMask) == 0)\r
+                               {\r
+                                       if (r->InterfaceID == e->InterfaceID)\r
+                                       {\r
+                                               restore = false;\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (network_has_changed)\r
+                       {\r
+                               restore = false;\r
+                       }\r
+               }\r
+\r
+               if (restore)\r
+               {\r
+                       // ルーティングテーブル復元\r
+                       AddRouteEntry(e);\r
+               }\r
+\r
+               // メモリ解放\r
+               FreeRouteEntry(e);\r
+       }\r
+\r
+       // 解放\r
+       FreeRouteTable(table);\r
+       ReleaseQueue(t->DeletedDefaultGateway);\r
+\r
+       FreeRouteChange(t->RouteChange);\r
+\r
+       Free(t);\r
+}\r
+\r
+// 仮想 LAN カードのインスタンス ID を取得する\r
+UINT GetInstanceId(char *name)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UINT id = 0;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), VLAN_ADAPTER_NAME_TAG, name);\r
+\r
+       id = GetVLanInterfaceID(tmp);\r
+       if (id != 0)\r
+       {\r
+               return id;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 仮想 LAN カードのインスタンスリストを取得する\r
+INSTANCE_LIST *GetInstanceList()\r
+{\r
+       INSTANCE_LIST *n = ZeroMalloc(sizeof(INSTANCE_LIST));\r
+\r
+       // 列挙\r
+       char **ss = EnumVLan(VLAN_ADAPTER_NAME);\r
+\r
+       if (ss == NULL)\r
+       {\r
+               // 失敗\r
+               n->NumInstance = 0;\r
+               n->InstanceName = Malloc(0);\r
+               return n;\r
+       }\r
+       else\r
+       {\r
+               UINT i, num;\r
+               i = num = 0;\r
+               while (true)\r
+               {\r
+                       if (ss[i++] == NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+                       num++;\r
+               }\r
+               i = 0;\r
+               n->NumInstance = num;\r
+               n->InstanceName = (char **)ZeroMalloc(sizeof(char *) * n->NumInstance);\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       char *s = ss[i] + StrLen(VLAN_ADAPTER_NAME) + StrLen(" - ");\r
+                       if (StrLen(ss[i]) > StrLen(VLAN_ADAPTER_NAME) + StrLen(" - "))\r
+                       {\r
+                               n->InstanceName[i] = CopyStr(s);\r
+                       }\r
+               }\r
+               FreeEnumVLan(ss);\r
+       }\r
+\r
+       return n;\r
+}\r
+\r
+// インスタンスリストを解放する\r
+void FreeInstanceList(INSTANCE_LIST *n)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < n->NumInstance;i++)\r
+       {\r
+               Free(n->InstanceName[i]);\r
+       }\r
+       Free(n->InstanceName);\r
+       Free(n);\r
+}\r
+\r
+// パケットアダプタの解放\r
+void VLanPaFree(SESSION *s)\r
+{\r
+       VLAN *v;\r
+       ROUTE_TRACKING *t;\r
+       // 引数チェック\r
+       if ((s == NULL) || ((v = s->PacketAdapter->Param) == NULL))\r
+       {\r
+               return;\r
+       }\r
+\r
+       // DHCP を使用している場合は IP アドレスを解放する\r
+       if (IsNt())\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               MS_ADAPTER *a;\r
+\r
+               Format(tmp, sizeof(tmp), VLAN_ADAPTER_NAME_TAG, v->InstanceName);\r
+               a = MsGetAdapter(tmp);\r
+\r
+               if (a != NULL)\r
+               {\r
+                       if (a->UseDhcp)\r
+                       {\r
+                               bool ret = Win32ReleaseAddressByGuidEx(a->Guid, 50);\r
+                               Debug("*** Win32ReleaseAddressByGuid = %u\n", ret);\r
+                       }\r
+\r
+                       MsFreeAdapter(a);\r
+               }\r
+       }\r
+\r
+       t = v->RouteState;\r
+       // 仮想 LAN カードの終了\r
+       FreeVLan(v);\r
+\r
+       // ルーティングテーブル追跡終了\r
+       if (s->ClientModeAndUseVLan)\r
+       {\r
+               RouteTrackingStop(s, t);\r
+       }\r
+       s->PacketAdapter->Param = NULL;\r
+}\r
+\r
+\r
+// パケットの書き込み\r
+bool VLanPaPutPacket(SESSION *s, void *data, UINT size)\r
+{\r
+       VLAN *v;\r
+       // 引数チェック\r
+       if ((s == NULL) || ((v = s->PacketAdapter->Param) == NULL))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return VLanPutPacket(v, data, size);\r
+}\r
+\r
+// 次のパケットを取得\r
+UINT VLanPaGetNextPacket(SESSION *s, void **data)\r
+{\r
+       VLAN *v;\r
+       UINT size;\r
+       // 引数チェック\r
+       if (data == NULL || (s == NULL) || ((v = s->PacketAdapter->Param) == NULL))\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       RouteTrackingMain(s);\r
+\r
+       if (VLanGetNextPacket(v, data, &size) == false)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return size;\r
+}\r
+\r
+// キャンセルオブジェクトの取得\r
+CANCEL *VLanPaGetCancel(SESSION *s)\r
+{\r
+       VLAN *v;\r
+       // 引数チェック\r
+       if ((s == NULL) || ((v = s->PacketAdapter->Param) == NULL))\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return VLanGetCancel(v);\r
+}\r
+\r
+// パケットアダプタ初期化\r
+bool VLanPaInit(SESSION *s)\r
+{\r
+       VLAN *v;\r
+       // 引数チェック\r
+       if ((s == NULL)/* || (s->ServerMode != false) || (s->ClientOption == NULL)*/)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 接続直前の DNS サーバーの IP アドレスの取得\r
+       if (s->ClientModeAndUseVLan)\r
+       {\r
+               Zero(&s->DefaultDns, sizeof(IP));\r
+               GetDefaultDns(&s->DefaultDns);\r
+       }\r
+\r
+       // ドライバに接続\r
+       v = NewVLan(s->ClientOption->DeviceName, NULL);\r
+       if (v == NULL)\r
+       {\r
+               // 失敗\r
+               return false;\r
+       }\r
+\r
+       s->PacketAdapter->Param = v;\r
+\r
+       // ルーティングテーブル追跡開始\r
+       if (s->ClientModeAndUseVLan)\r
+       {\r
+               RouteTrackingStart(s);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// VLAN のパケットアダプタを取得\r
+PACKET_ADAPTER *VLanGetPacketAdapter()\r
+{\r
+       PACKET_ADAPTER *pa;\r
+\r
+       pa = NewPacketAdapter(VLanPaInit, VLanPaGetCancel,\r
+               VLanPaGetNextPacket, VLanPaPutPacket, VLanPaFree);\r
+       if (pa == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return pa;\r
+}\r
+\r
+\r
+// 次の受信パケットをドライバに書き込む\r
+bool VLanPutPacket(VLAN *v, void *buf, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (v->Halt)\r
+       {\r
+               return false;\r
+       }\r
+       if (size > MAX_PACKET_SIZE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // まず、現在のバッファが一杯になっているかどうか調べる\r
+       if ((SEN_NUM_PACKET(v->PutBuffer) >= SEN_MAX_PACKET_EXCHANGE) ||\r
+               (buf == NULL && SEN_NUM_PACKET(v->PutBuffer) != 0))\r
+       {\r
+#ifdef USE_PROBE\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+                       snprintf(tmp, sizeof(tmp), "VLanPutPacket: SEN_NUM_PACKET(v->PutBuffer) = %u", SEN_NUM_PACKET(v->PutBuffer));\r
+                       PROBE_DATA2(tmp, NULL, 0);\r
+               }\r
+#endif // USE_PROBE\r
+               // パケットをドライバに書き出す\r
+               if (VLanPutPacketsToDriver(v) == false)\r
+               {\r
+                       return false;\r
+               }\r
+               SEN_NUM_PACKET(v->PutBuffer) = 0;\r
+       }\r
+\r
+       // 次のパケットをバッファに追加する\r
+       if (buf != NULL)\r
+       {\r
+               UINT i = SEN_NUM_PACKET(v->PutBuffer);\r
+               SEN_NUM_PACKET(v->PutBuffer)++;\r
+\r
+               SEN_SIZE_OF_PACKET(v->PutBuffer, i) = size;\r
+               Copy(SEN_ADDR_OF_PACKET(v->PutBuffer, i), buf, size);\r
+               Free(buf);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 次の送信パケットをドライバから読み出す\r
+bool VLanGetNextPacket(VLAN *v, void **buf, UINT *size)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || buf == NULL || size == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (v->Halt)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       PROBE_STR("VLanGetNextPacket");\r
+\r
+       while (true)\r
+       {\r
+               if (v->CurrentPacketCount < SEN_NUM_PACKET(v->GetBuffer))\r
+               {\r
+                       // すでに読み込まれたパケットがまだ残っている\r
+                       *size = SEN_SIZE_OF_PACKET(v->GetBuffer, v->CurrentPacketCount);\r
+                       *buf = MallocFast(*size);\r
+                       Copy(*buf, SEN_ADDR_OF_PACKET(v->GetBuffer, v->CurrentPacketCount), *size);\r
+\r
+                       // パケット番号をインクリメントする\r
+                       v->CurrentPacketCount++;\r
+\r
+                       return true;\r
+               }\r
+               else\r
+               {\r
+                       // 次のパケットをドライバから読み込む\r
+                       if (VLanGetPacketsFromDriver(v) == false)\r
+                       {\r
+                               return false;\r
+                       }\r
+\r
+                       if (SEN_NUM_PACKET(v->GetBuffer) == 0)\r
+                       {\r
+                               // 現在パケットは届いていない\r
+                               *buf = NULL;\r
+                               *size = 0;\r
+                               return true;\r
+                       }\r
+\r
+                       v->CurrentPacketCount = 0;\r
+               }\r
+       }\r
+}\r
+\r
+// ドライバに現在のすべてのパケットを書き込む\r
+bool VLanPutPacketsToDriver(VLAN *v)\r
+{\r
+       DWORD write_size;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (v->Halt)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (v->Win9xMode == false)\r
+       {\r
+               // Windows NT\r
+               PROBE_STR("VLanPutPacketsToDriver: WriteFile");\r
+               if (WriteFile(v->Handle, v->PutBuffer, SEN_EXCHANGE_BUFFER_SIZE, &write_size,\r
+                       NULL) == false)\r
+               {\r
+                       v->Halt = true;\r
+                       return false;\r
+               }\r
+               PROBE_STR("VLanPutPacketsToDriver: WriteFile Completed.");\r
+\r
+               if (write_size != SEN_EXCHANGE_BUFFER_SIZE)\r
+               {\r
+                       v->Halt = true;\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // Windows 9x\r
+               if (DeviceIoControl(v->Handle, SEN_IOCTL_PUT_PACKET, v->PutBuffer,\r
+                       SEN_EXCHANGE_BUFFER_SIZE, NULL, 0, &write_size, NULL) == false)\r
+               {\r
+                       v->Halt = true;\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ドライバから次のパケットを読み込む\r
+bool VLanGetPacketsFromDriver(VLAN *v)\r
+{\r
+       DWORD read_size;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (v->Halt)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (v->Win9xMode == false)\r
+       {\r
+               // Windows NT\r
+               PROBE_STR("VLanGetPacketsFromDriver: ReadFile");\r
+               if (ReadFile(v->Handle, v->GetBuffer, SEN_EXCHANGE_BUFFER_SIZE,\r
+                       &read_size, NULL) == false)\r
+               {\r
+                       v->Halt = true;\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // Windows 9x\r
+               if (DeviceIoControl(v->Handle, SEN_IOCTL_GET_PACKET, NULL, 0,\r
+                       v->GetBuffer, SEN_EXCHANGE_BUFFER_SIZE, &read_size, NULL) == false)\r
+               {\r
+                       v->Halt = true;\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       if (read_size != SEN_EXCHANGE_BUFFER_SIZE)\r
+       {\r
+               v->Halt = true;\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// キャンセルオブジェクトの取得\r
+CANCEL *VLanGetCancel(VLAN *v)\r
+{\r
+       CANCEL *c;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // キャンセルオブジェクトの作成\r
+       c = NewCancel();\r
+       c->SpecialFlag = true;\r
+       CloseHandle(c->hEvent);\r
+\r
+       c->hEvent = v->Event;\r
+\r
+       return c;\r
+}\r
+\r
+// VLAN オブジェクトの解放\r
+void FreeVLan(VLAN *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ハンドルを閉じる\r
+       CloseHandle(v->Event);\r
+       CloseHandle(v->Handle);\r
+\r
+       // メモリ解放\r
+       Free(v->InstanceName);\r
+       Free(v->EventNameWin32);\r
+       Free(v->DeviceNameWin32);\r
+       Free(v->PutBuffer);\r
+       Free(v->GetBuffer);\r
+       Free(v);\r
+}\r
+\r
+// VLAN オブジェクトの作成\r
+VLAN *NewVLan(char *instance_name, VLAN_PARAM *param)\r
+{\r
+       VLAN *v;\r
+       HANDLE h = INVALID_HANDLE_VALUE;\r
+       HANDLE e = INVALID_HANDLE_VALUE;\r
+       char tmp[MAX_SIZE];\r
+       char name_upper[MAX_SIZE];\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       v = ZeroMalloc(sizeof(VLAN));\r
+\r
+       if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType))\r
+       {\r
+               v->Win9xMode = true;\r
+       }\r
+\r
+       // 名前の初期化\r
+       Format(name_upper, sizeof(name_upper), "%s", instance_name);\r
+       StrUpper(name_upper);\r
+       v->InstanceName = CopyStr(name_upper);\r
+       Format(tmp, sizeof(tmp), NDIS_SEN_DEVICE_FILE_NAME, v->InstanceName);\r
+       v->DeviceNameWin32 = CopyStr(tmp);\r
+\r
+       if (v->Win9xMode == false)\r
+       {\r
+               Format(tmp, sizeof(tmp), NDIS_SEN_EVENT_NAME_WIN32, v->InstanceName);\r
+               v->EventNameWin32 = CopyStr(tmp);\r
+       }\r
+\r
+       // デバイスに接続\r
+       h = CreateFile(v->DeviceNameWin32,\r
+               GENERIC_READ | GENERIC_WRITE,\r
+               0,\r
+               NULL,\r
+               OPEN_EXISTING,\r
+               0,\r
+               NULL);\r
+       if (h == INVALID_HANDLE_VALUE)\r
+       {\r
+               // 接続失敗\r
+               goto CLEANUP;\r
+       }\r
+\r
+       if (v->Win9xMode == false)\r
+       {\r
+               // イベントに接続\r
+               e = OpenEvent(SYNCHRONIZE, FALSE, v->EventNameWin32);\r
+               if (e == INVALID_HANDLE_VALUE)\r
+               {\r
+                       // 接続失敗\r
+                       goto CLEANUP;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               OPENVXDHANDLE OpenVxDHandle;\r
+               DWORD vxd_handle;\r
+               UINT bytes_returned;\r
+\r
+               OpenVxDHandle = (OPENVXDHANDLE)GetProcAddress(GetModuleHandleA("KERNEL32"),\r
+                       "OpenVxDHandle");\r
+\r
+               // イベントを作成してドライバに渡す\r
+               e = CreateEvent(NULL, FALSE, FALSE, NULL);\r
+               vxd_handle = (DWORD)OpenVxDHandle(e);\r
+\r
+               DeviceIoControl(h, SEN_IOCTL_SET_EVENT, &vxd_handle, sizeof(DWORD),\r
+                       NULL, 0, &bytes_returned, NULL);\r
+       }\r
+\r
+       v->Event = e;\r
+       v->Handle = h;\r
+\r
+       v->GetBuffer = ZeroMalloc(SEN_EXCHANGE_BUFFER_SIZE);\r
+       v->PutBuffer = ZeroMalloc(SEN_EXCHANGE_BUFFER_SIZE);\r
+\r
+       return v;\r
+\r
+CLEANUP:\r
+       if (h != INVALID_HANDLE_VALUE)\r
+       {\r
+               CloseHandle(h);\r
+       }\r
+       if (e != INVALID_HANDLE_VALUE)\r
+       {\r
+               CloseHandle(e);\r
+       }\r
+\r
+       Free(v->InstanceName);\r
+       Free(v->EventNameWin32);\r
+       Free(v->DeviceNameWin32);\r
+       Free(v);\r
+\r
+       return NULL;\r
+}\r
+\r
+#endif // OS_WIN32\r
+\r
+#endif //VLAN_C\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLanWin32.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/VLanWin32.h
new file mode 100644 (file)
index 0000000..cdbec76
--- /dev/null
@@ -0,0 +1,164 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// VLanWin32.h\r
+// VLanWin32.c のヘッダ\r
+\r
+#ifndef        VLANWIN32_H\r
+#define        VLANWIN32_H\r
+\r
+// ルーティングテーブル追跡タイマ\r
+#define        TRACKING_INTERVAL_INITIAL               444             // 初期\r
+#define        TRACKING_INTERVAL_ADD                   444             // 追加値\r
+#define        TRACKING_INTERVAL_MAX                   12345   // 最大値\r
+#define        TRACKING_INTERVAL_MAX_RC                87654   // 最大値 (変更検出機構有効 OS)\r
+\r
+\r
+typedef void *HANDLE;\r
+\r
+// ルーティング追跡用状態マシン\r
+struct ROUTE_TRACKING\r
+{\r
+       UINT VLanInterfaceId;\r
+       ROUTE_ENTRY *RouteToServer;\r
+       bool RouteToServerAlreadyExists;\r
+       ROUTE_ENTRY *DefaultGatewayByVLan;\r
+       ROUTE_ENTRY *VistaDefaultGateway1, *VistaDefaultGateway2, *VistaOldDefaultGatewayByVLan;\r
+       ROUTE_ENTRY *RouteToDefaultDns;\r
+       UINT64 NextTrackingTime;\r
+       UINT64 NextTrackingTimeAdd;\r
+       UINT64 NextRouteChangeCheckTime;\r
+       UINT LastRoutingTableHash;\r
+       QUEUE *DeletedDefaultGateway;\r
+       UINT OldDefaultGatewayMetric;\r
+       IP OldDnsServer;\r
+       bool VistaAndUsingPPP;\r
+       ROUTE_CHANGE *RouteChange;\r
+};\r
+\r
+// VLAN 構造体\r
+struct VLAN\r
+{\r
+       volatile bool Halt;                     // 停止フラグ\r
+       bool Win9xMode;                         // Windows 9x\r
+       char *InstanceName;                     // インスタンス名\r
+       char *DeviceNameWin32;          // Win32 デバイス名\r
+       char *EventNameWin32;           // Win32 イベント名\r
+       HANDLE Handle;                          // デバイスドライバのファイル\r
+       HANDLE Event;                           // イベントのハンドル\r
+       void *GetBuffer;                        // 送信パケット取得用バッファ\r
+       UINT CurrentPacketCount;        // 次に読み込むパケット番号\r
+       void *PutBuffer;                        // 受信パケット書き込み用バッファ\r
+       ROUTE_TRACKING *RouteState;     // ルーティング追跡用状態マシン\r
+};\r
+\r
+// インスタンスリスト\r
+struct INSTANCE_LIST\r
+{\r
+       UINT NumInstance;\r
+       char **InstanceName;\r
+};\r
+\r
+\r
+// 関数プロトタイプ\r
+VLAN *NewVLan(char *instance_name, VLAN_PARAM *param);\r
+void FreeVLan(VLAN *v);\r
+CANCEL *VLanGetCancel(VLAN *v);\r
+bool VLanGetNextPacket(VLAN *v, void **buf, UINT *size);\r
+bool VLanGetPacketsFromDriver(VLAN *v);\r
+bool VLanPutPacketsToDriver(VLAN *v);\r
+bool VLanPutPacket(VLAN *v, void *buf, UINT size);\r
+\r
+PACKET_ADAPTER *VLanGetPacketAdapter();\r
+bool VLanPaInit(SESSION *s);\r
+CANCEL *VLanPaGetCancel(SESSION *s);\r
+UINT VLanPaGetNextPacket(SESSION *s, void **data);\r
+bool VLanPaPutPacket(SESSION *s, void *data, UINT size);\r
+void VLanPaFree(SESSION *s);\r
+\r
+INSTANCE_LIST *GetInstanceList();\r
+void FreeInstanceList(INSTANCE_LIST *n);\r
+UINT GetInstanceId(char *name);\r
+\r
+void RouteTrackingStart(SESSION *s);\r
+void RouteTrackingStop(SESSION *s, ROUTE_TRACKING *t);\r
+void RouteTrackingMain(SESSION *s);\r
+void Win32ReleaseAllDhcp9x(bool wait);\r
+\r
+void Win32GetWinVer(RPC_WINVER *v);\r
+\r
+#endif // VLANWIN32_H\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Virtual.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Virtual.c
new file mode 100644 (file)
index 0000000..ce20fb7
--- /dev/null
@@ -0,0 +1,5729 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Virtual.c\r
+// ユーザーモード仮想ホストプログラム\r
+\r
+// Q. このプログラムには大変多くの TCP/IP 関係の奥の深い処理が入っていて\r
+//    さらに TCP スタックの簡易的な実装まで完結しているように見えるが\r
+//    なぜこのように気合の入ったコードを書いたのか?\r
+// A. 作者の所属していた筑波大学第三学群情報学類という学科では、\r
+//    「情報特別演習」という授業がある。なんとこれは専門基礎単位を取得\r
+//    することができる貴重なコマである。専門基礎単位を取得するための他の\r
+//    方法としては、解析学Ⅲなどという授業等がある。しかし、作者は受験勉強\r
+//    のような数学のテスト勉強は嫌いであるし、また、SoftEther に関する打ち合わせ\r
+//    のために大学の某所に駐車したときにその解析学Ⅲの当時の担当教員の車のミラー\r
+//    をこすってしまって少し怒られたのでその単位の取得は難しくなった (?) のである。\r
+//    だが、専門基礎の単位を取得しなければ、卒業することができない。\r
+//    そこで代わりに「情報特別演習」で単位をとることにしたのだが、この授業は、\r
+//    何か面白いコンピュータの作品を作ってプレゼンテーションすれば 2 単位がくる\r
+//    という名目なのであった。しかし、実際のところ、ろくな作品を 1 年間で\r
+//    作ってプレゼンする人はとても少なく、たいていが「無線 LAN の実験」とか\r
+//    そういうほとんどクリエイティブな作業を必要とせずにできるいいかげんな\r
+//    「実習」を行ったと言って結果を報告すれば 2 単位来るという程度の難易度\r
+//    であることが後になって分かった。\r
+//    作者は大変真面目なので、部類としてはかなり難しい難易度に入る TCP/IP\r
+//    スタックの開発を実習としてやってみようと思い、数週間かけていろいろ\r
+//    プログラムを書いた。その成果の一部がこの Virtual.c というコードである。\r
+//    逆にいうと、大学の授業の実習程度で開発することができるくらいの簡単な\r
+//    プログラムなので、実装は簡易的であり、効率が悪く、メンテナンス性にも欠け\r
+//    ている。結構場当たり的なプログラミングを行ったためである。\r
+//    それでも 2004 年末に本プログラムをインターネットで配布してから今まで\r
+//    一応は深刻な不具合は発生していない。ただし探せば深刻な障害が潜んでいる\r
+//    かも知れない。\r
+\r
+\r
+#include "CedarPch.h"\r
+\r
+static UCHAR broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};\r
+\r
+// Virtual Host のログをとる\r
+void VLog(VH *v, char *str)\r
+{\r
+       // とらん!!\r
+       return;\r
+}\r
+\r
+// NAT が使用可能かどうかチェック\r
+bool CanCreateNewNatEntry(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (v->UseNat == false)\r
+       {\r
+               // NAT 停止中\r
+               return false;\r
+       }\r
+\r
+       if (v->NatTable->num_item > NAT_MAX_SESSIONS)\r
+       {\r
+               // セッション数超過\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// NAT 処理スレッドのメイン関数\r
+void NatThreadMain(VH *v)\r
+{\r
+       bool halt_flag;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v->TmpBuf = Malloc(NAT_TMPBUF_SIZE);\r
+\r
+       while (true)\r
+       {\r
+               // 次のイベントがセットされるまで待機する\r
+               WaitSockEvent(v->SockEvent, SELECT_TIME);\r
+\r
+               halt_flag = false;\r
+\r
+               LockVirtual(v);\r
+               {\r
+                       // すべての NAT セッションに対して処理を行う\r
+                       UINT i, num;\r
+\r
+                       v->Now = Tick64();\r
+                       v->NatDoCancelFlag = false;\r
+\r
+LIST_ELEMENT_DELETED:\r
+                       num = LIST_NUM(v->NatTable);\r
+                       for (i = 0;i < num;i++)\r
+                       {\r
+                               NAT_ENTRY *n = LIST_DATA(v->NatTable, i);\r
+\r
+                               switch (n->Protocol)\r
+                               {\r
+                               case NAT_TCP:           // TCP\r
+                                       if (NatTransactTcp(v, n) == false)\r
+                                       {\r
+                                               goto LIST_ELEMENT_DELETED;\r
+                                       }\r
+                                       break;\r
+\r
+                               case NAT_UDP:           // UDP\r
+                                       if (NatTransactUdp(v, n) == false)\r
+                                       {\r
+                                               goto LIST_ELEMENT_DELETED;\r
+                                       }\r
+                                       break;\r
+\r
+                               case NAT_DNS:           // DNS\r
+                                       if (NatTransactDns(v, n) == false)\r
+                                       {\r
+                                               goto LIST_ELEMENT_DELETED;\r
+                                       }\r
+                                       break;\r
+                               }\r
+                       }\r
+\r
+                       if (v->NatDoCancelFlag)\r
+                       {\r
+                               // 親スレッドの Cancel を叩く\r
+                               Cancel(v->Cancel);\r
+                       }\r
+\r
+                       // 停止フラグチェック\r
+                       if (v->HaltNat)\r
+                       {\r
+                               halt_flag = true;\r
+                       }\r
+               }\r
+               UnlockVirtual(v);\r
+\r
+               if (halt_flag)\r
+               {\r
+                       // すべてのエントリを強制切断してからスレッドを終了する\r
+                       LockVirtual(v);\r
+                       {\r
+                               UINT num = LIST_NUM(v->NatTable);\r
+                               NAT_ENTRY **nn = ToArray(v->NatTable);\r
+                               UINT i;\r
+\r
+                               for (i = 0;i < num;i++)\r
+                               {\r
+                                       NAT_ENTRY *n = nn[i];\r
+                                       n->DisconnectNow = true;\r
+\r
+                                       switch (n->Protocol)\r
+                                       {\r
+                                       case NAT_TCP:           // TCP\r
+                                               NatTransactTcp(v, n);\r
+                                               break;\r
+\r
+                                       case NAT_UDP:           // UDP\r
+                                               NatTransactUdp(v, n);\r
+                                               break;\r
+\r
+                                       case NAT_DNS:           // DNS\r
+                                               NatTransactDns(v, n);\r
+                                               break;\r
+                                       }\r
+                               }\r
+\r
+                               Free(nn);\r
+                       }\r
+                       UnlockVirtual(v);\r
+                       break;\r
+               }\r
+       }\r
+\r
+       Free(v->TmpBuf);\r
+}\r
+\r
+// DNS: IP アドレスを取得するスレッド\r
+void NatGetIPThread(THREAD *t, void *param)\r
+{\r
+       NAT_DNS_QUERY *q;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       q = (NAT_DNS_QUERY *)param;\r
+       AddWaitThread(t);\r
+\r
+       q->Ok = GetIP(&q->Ip, q->Hostname);\r
+\r
+       DelWaitThread(t);\r
+\r
+       if (Release(q->ref) == 0)\r
+       {\r
+               Free(q);\r
+       }\r
+}\r
+\r
+// DNS: ホスト名から IP アドレスを取得する\r
+bool NatGetIP(IP *ip, char *hostname)\r
+{\r
+       TOKEN_LIST *t;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (ip == NULL || hostname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       t = ParseToken(hostname, ".");\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (t->NumTokens == 0)\r
+       {\r
+               FreeToken(t);\r
+               return false;\r
+       }\r
+\r
+       if (t->NumTokens == 1)\r
+       {\r
+               ret = GetIP(ip, hostname);\r
+       }\r
+       else\r
+       {\r
+               char *hostname2 = t->Token[0];\r
+               NAT_DNS_QUERY *q1, *q2;\r
+               THREAD *t1, *t2;\r
+\r
+               q1 = ZeroMalloc(sizeof(NAT_DNS_QUERY));\r
+               q2 = ZeroMalloc(sizeof(NAT_DNS_QUERY));\r
+               q1->ref = NewRef();\r
+               q2->ref = NewRef();\r
+               AddRef(q1->ref);\r
+               AddRef(q2->ref);\r
+               StrCpy(q1->Hostname, sizeof(q1->Hostname), hostname);\r
+               StrCpy(q2->Hostname, sizeof(q2->Hostname), hostname2);\r
+\r
+               t1 = NewThread(NatGetIPThread, q1);\r
+               t2 = NewThread(NatGetIPThread, q2);\r
+\r
+               WaitThread(t1, NAT_DNS_QUERY_TIMEOUT);\r
+\r
+               if (q1->Ok)\r
+               {\r
+                       ret = true;\r
+                       Copy(ip, &q1->Ip, sizeof(IP));\r
+               }\r
+               else\r
+               {\r
+                       WaitThread(t2, NAT_DNS_QUERY_TIMEOUT);\r
+                       if (q1->Ok)\r
+                       {\r
+                               ret = true;\r
+                               Copy(ip, &q1->Ip, sizeof(IP));\r
+                       }\r
+                       else if (q2->Ok)\r
+                       {\r
+                               ret = true;\r
+                               Copy(ip, &q2->Ip, sizeof(IP));\r
+                       }\r
+               }\r
+\r
+               ReleaseThread(t1);\r
+               ReleaseThread(t2);\r
+\r
+               if (Release(q1->ref) == 0)\r
+               {\r
+                       Free(q1);\r
+               }\r
+               if (Release(q2->ref) == 0)\r
+               {\r
+                       Free(q2);\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// DNS 問い合わせ関数\r
+void NatDnsThread(THREAD *t, void *param)\r
+{\r
+       NAT_ENTRY *n;\r
+       IP ip;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+       n = (NAT_ENTRY *)param;\r
+\r
+       // 初期化完了を通知\r
+       NoticeThreadInit(t);\r
+\r
+       // 処理を実行\r
+       if (EndWith(n->DnsTargetHostName, ".in-addr.arpa") == false)\r
+       {\r
+               // 正引き\r
+               if (NatGetIP(&ip, n->DnsTargetHostName))\r
+               {\r
+                       // 正引き成功\r
+                       Copy(&n->DnsResponseIp, &ip, sizeof(IP));\r
+                       n->DnsOk = true;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // 逆引き\r
+               IP ip;\r
+               n->DnsGetIpFromHost = true;             // 逆引きフラグを設定\r
+               // *.in-addr.arpa 文字列を IP アドレスに変換してもらう\r
+               if (ArpaToIP(&ip, n->DnsTargetHostName))\r
+               {\r
+                       // 逆引き処理\r
+                       char tmp[256];\r
+                       if (GetHostName(tmp, sizeof(tmp), &ip))\r
+                       {\r
+                               // 逆引き成功\r
+                               n->DnsResponseHostName = CopyStr(tmp);\r
+                               n->DnsOk = true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // 結果を通知\r
+       n->DnsFinished = true;\r
+\r
+       SetSockEvent(n->v->SockEvent);\r
+}\r
+\r
+// 逆引き用アドレスを IP アドレスに変換する\r
+bool ArpaToIP(IP *ip, char *str)\r
+{\r
+       TOKEN_LIST *token;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (ip == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // トークン変換\r
+       token = ParseToken(str, ".");\r
+       if (token->NumTokens == 6)\r
+       {\r
+               // token[0, 1, 2, 3] を IP に変換\r
+               UINT i;\r
+               Zero(ip, sizeof(IP));\r
+               for (i = 0;i < 4;i++)\r
+               {\r
+                       ip->addr[i] = (UCHAR)ToInt(token->Token[3 - i]);\r
+               }\r
+               ret = true;\r
+       }\r
+\r
+       FreeToken(token);\r
+\r
+       if (IPToUINT(ip) == 0)\r
+       {\r
+               ret = false;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// DNS エントリを処理する\r
+bool NatTransactDns(VH *v, NAT_ENTRY *n)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || n == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (n->DisconnectNow)\r
+       {\r
+               goto DISCONNECT;\r
+       }\r
+\r
+       if (n->DnsThread == NULL && n->DnsFinished == false)\r
+       {\r
+               // スレッドを作成する\r
+               THREAD *t = NewThread(NatDnsThread, (void *)n);\r
+               WaitThreadInit(t);\r
+               n->DnsThread = t;\r
+       }\r
+       else\r
+       {\r
+               // 結果を待機する\r
+               if (n->DnsFinished)\r
+               {\r
+                       // 結果が届いている\r
+                       WaitThread(n->DnsThread, INFINITE);\r
+                       ReleaseThread(n->DnsThread);\r
+                       n->DnsThread = NULL;\r
+                       // メインスレッドに通知\r
+                       v->NatDoCancelFlag = true;\r
+               }\r
+       }\r
+\r
+       return true;\r
+\r
+DISCONNECT:\r
+\r
+       // 解放処理\r
+       if (n->DnsThread != NULL)\r
+       {\r
+               WaitThread(n->DnsThread, INFINITE);\r
+               ReleaseThread(n->DnsThread);\r
+               n->DnsThread = NULL;\r
+       }\r
+\r
+       if (n->DnsTargetHostName != NULL)\r
+       {\r
+               Free(n->DnsTargetHostName);\r
+               n->DnsTargetHostName = NULL;\r
+       }\r
+\r
+       if (n->DnsResponseHostName != NULL)\r
+       {\r
+               Free(n->DnsResponseHostName);\r
+               n->DnsResponseHostName = NULL;\r
+       }\r
+\r
+       DeleteLock(n->lock);\r
+       Delete(v->NatTable, n);\r
+       Free(n);\r
+\r
+       return false;\r
+}\r
+\r
+// UDP エントリを処理する\r
+bool NatTransactUdp(VH *v, NAT_ENTRY *n)\r
+{\r
+       void *buf;\r
+       UINT recv_size;\r
+       BLOCK *block;\r
+       UINT dest_port = n->DestPort;\r
+       IP dest_ip;\r
+       // 引数チェック\r
+       if (v == NULL || n == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (n->DisconnectNow)\r
+       {\r
+               goto DISCONNECT;\r
+       }\r
+\r
+       if (n->UdpSocketCreated == false)\r
+       {\r
+               // UDP ソケットを作成する\r
+               n->Sock = NewUDP(0);\r
+               if (n->Sock == NULL)\r
+               {\r
+                       // ソケット作成失敗\r
+                       goto DISCONNECT;\r
+               }\r
+               else\r
+               {\r
+                       n->PublicIp = IPToUINT(&n->Sock->LocalIP);\r
+                       n->PublicPort = n->Sock->LocalPort;\r
+\r
+                       JoinSockToSockEvent(n->Sock, v->SockEvent);\r
+                       n->UdpSocketCreated = true;\r
+               }\r
+       }\r
+\r
+       buf = v->TmpBuf;\r
+       if (n->ProxyDns == false)\r
+       {\r
+               UINTToIP(&dest_ip, n->DestIp);\r
+       }\r
+       else\r
+       {\r
+               UINTToIP(&dest_ip, n->DestIpProxy);\r
+       }\r
+\r
+       // UDP ソケットからデータを受信してみる\r
+       while (true)\r
+       {\r
+               IP src_ip;\r
+               UINT src_port;\r
+               recv_size = RecvFrom(n->Sock, &src_ip, &src_port, buf, 65536);\r
+\r
+               if (recv_size == SOCK_LATER)\r
+               {\r
+                       // パケットが届いていない\r
+                       break;\r
+               }\r
+               else if (recv_size == 0)\r
+               {\r
+                       // エラー?\r
+                       if (n->Sock->IgnoreRecvErr == false)\r
+                       {\r
+                               // 致命的なエラーが発生した\r
+                               goto DISCONNECT;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // パケットが届いた。送信元 IP をチェック\r
+                       if (IPToUINT(&src_ip) == n->DestIp || (IPToUINT(&src_ip) == n->DestIpProxy && n->ProxyDns) && src_port == n->DestPort)\r
+                       {\r
+                               // キューに挿入\r
+                               void *data = Malloc(recv_size);\r
+                               Copy(data, buf, recv_size);\r
+                               block = NewBlock(data, recv_size, 0);\r
+                               InsertQueue(n->UdpRecvQueue, block);\r
+                               v->NatDoCancelFlag = true;\r
+                               n->LastCommTime = v->Now;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // UDP ソケットにデータを送信してみる\r
+       while (block = GetNext(n->UdpSendQueue))\r
+       {\r
+               UINT send_size = SendTo(n->Sock, &dest_ip, dest_port, block->Buf, block->Size);\r
+\r
+               FreeBlock(block);\r
+               if (send_size == 0)\r
+               {\r
+                       // 致命的なエラーかどうか判定\r
+                       if (n->Sock->IgnoreSendErr == false)\r
+                       {\r
+                               // 致命的なエラーが発生した\r
+                               goto DISCONNECT;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       n->LastCommTime = v->Now;\r
+               }\r
+       }\r
+\r
+       // このセッションがタイムアウトになっていないかどうか調べる\r
+       if ((n->LastCommTime + (UINT64)v->NatUdpTimeout) < v->Now || n->LastCommTime > v->Now)\r
+       {\r
+               // タイムアウトである\r
+               goto DISCONNECT;\r
+       }\r
+\r
+       return true;\r
+\r
+DISCONNECT:\r
+       // このセッションを切断\r
+       if (n->UdpSocketCreated)\r
+       {\r
+               // ソケットを閉じる\r
+               Disconnect(n->Sock);\r
+               ReleaseSock(n->Sock);\r
+               n->Sock = NULL;\r
+       }\r
+\r
+       // エントリを削除\r
+       DeleteNatUdp(v, n);\r
+\r
+       return false;\r
+}\r
+\r
+// TCP ホストへの接続処理を行うためのスレッド\r
+void NatTcpConnectThread(THREAD *t, void *p)\r
+{\r
+       NAT_ENTRY *n = (NAT_ENTRY *)p;\r
+       IP ip;\r
+       char hostname[MAX_SIZE];\r
+       UINT port_number;\r
+       SOCK *sock;\r
+       SOCK_EVENT *e;\r
+       // 引数チェック\r
+       if (n == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UINTToIP(&ip, n->DestIp);\r
+       IPToStr(hostname, sizeof(hostname), &ip);\r
+       port_number = n->DestPort;\r
+       e = n->v->SockEvent;\r
+       AddRef(e->ref);\r
+\r
+       // 初期化完了を通知\r
+       NoticeThreadInit(t);\r
+\r
+       // TCP ホストへの接続を試行\r
+       Debug("NatTcpConnect Connecting to %s:%u\n", hostname, port_number);\r
+       sock = Connect(hostname, port_number);\r
+       if (sock == NULL)\r
+       {\r
+               // 接続失敗\r
+               n->TcpMakeConnectionFailed = true;\r
+       }\r
+       else\r
+       {\r
+               // 接続成功\r
+               n->TcpMakeConnectionSucceed = true;\r
+       }\r
+       n->Sock = sock;\r
+       JoinSockToSockEvent(sock, e);\r
+       SetSockEvent(e);\r
+\r
+       ReleaseSockEvent(e);\r
+}\r
+\r
+// TCP ホストに接続するためのスレッドを作成する\r
+void CreateNatTcpConnectThread(VH *v, NAT_ENTRY *n)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // スレッド作成\r
+       n->NatTcpConnectThread = NewThread(NatTcpConnectThread, (void *)n);\r
+\r
+       // スレッド初期化完了を待機\r
+       WaitThreadInit(n->NatTcpConnectThread);\r
+}\r
+\r
+// TCP エントリを処理する\r
+bool NatTransactTcp(VH *v, NAT_ENTRY *n)\r
+{\r
+       char str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (v == NULL || n == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (n->DisconnectNow)\r
+       {\r
+               goto DISCONNECT;\r
+       }\r
+\r
+       // TCP の状態別に処理を行う\r
+       switch (n->TcpStatus)\r
+       {\r
+       case NAT_TCP_CONNECTING:                // 接続待機中\r
+               if (n->NatTcpConnectThread == NULL)\r
+               {\r
+                       // 接続スレッドを作成し接続を開始する\r
+                       CreateNatTcpConnectThread(v, n);\r
+               }\r
+               else\r
+               {\r
+                       // すでに開始されている接続スレッドの結果を待機\r
+                       if (n->TcpMakeConnectionFailed || n->TcpMakeConnectionSucceed)\r
+                       {\r
+                               // スレッドの動作はすでに完了しているので結果を使用する\r
+                               WaitThread(n->NatTcpConnectThread, INFINITE);\r
+                               ReleaseThread(n->NatTcpConnectThread);\r
+                               n->NatTcpConnectThread = NULL;\r
+\r
+                               if (n->TcpMakeConnectionSucceed)\r
+                               {\r
+                                       // 接続は成功し Sock が作成された\r
+                                       n->TcpStatus = NAT_TCP_CONNECTED;\r
+                                       IPToStr32(str, sizeof(str), n->DestIp);\r
+                                       NLog(v, "LH_NAT_TCP_SUCCEED", n->Id, n->Sock->RemoteHostname, str, n->DestPort);\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 接続に失敗した\r
+                                       n->TcpStatus = NAT_TCP_SEND_RESET;\r
+                                       IPToStr32(str, sizeof(str), n->DestIp);\r
+                                       NLog(v, "LH_NAT_TCP_FAILED", n->Id, str, n->DestPort);\r
+                               }\r
+                               v->NatDoCancelFlag = true;\r
+                       }\r
+               }\r
+               break;\r
+\r
+       case NAT_TCP_CONNECTED:                 // TCP ソケット接続完了 クライアントホストとの間で交渉中\r
+               break;\r
+\r
+       case NAT_TCP_SEND_RESET:                // TCP 通信切断 クライアントホストへ RST を送信\r
+               break;\r
+\r
+       case NAT_TCP_ESTABLISHED:               // TCP 接続確立済み\r
+               {\r
+                       // 受信バッファにデータがあればソケットに対して送信する\r
+                       while (n->RecvFifo->size > 0)\r
+                       {\r
+                               UINT sent_size = Send(n->Sock, ((UCHAR *)n->RecvFifo->p) + n->RecvFifo->pos,\r
+                                       n->RecvFifo->size, false);\r
+                               if (sent_size == 0)\r
+                               {\r
+                                       // 通信が切断された\r
+                                       n->TcpFinished = true;\r
+                                       v->NatDoCancelFlag = true;\r
+                                       break;\r
+                               }\r
+                               else if (sent_size == SOCK_LATER)\r
+                               {\r
+                                       // ブロッキング\r
+                                       break;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 送信成功\r
+                                       ReadFifo(n->RecvFifo, NULL, sent_size);\r
+                                       n->SendAckNext = true;\r
+                               }\r
+                       }\r
+                       // ソケットからデータを取得して送信バッファに書き込む\r
+                       while (true)\r
+                       {\r
+                               void *buf = (void *)v->TmpBuf;\r
+                               UINT want_to_recv_size = 0;\r
+                               UINT recv_size;\r
+                               // 受信したいサイズを計算する\r
+                               if (n->SendFifo->size < NAT_SEND_BUF_SIZE)\r
+                               {\r
+                                       // まだ受信できる\r
+                                       want_to_recv_size = MIN(NAT_SEND_BUF_SIZE - n->SendFifo->size, NAT_TMPBUF_SIZE);\r
+                               }\r
+                               if (want_to_recv_size == 0)\r
+                               {\r
+                                       break;\r
+                               }\r
+                               recv_size = Recv(n->Sock, buf, want_to_recv_size, false);\r
+                               if (recv_size == 0)\r
+                               {\r
+                                       // 通信が切断された\r
+                                       n->TcpFinished = true;\r
+                                       v->NatDoCancelFlag = true;\r
+                                       break;\r
+                               }\r
+                               else if (recv_size == SOCK_LATER)\r
+                               {\r
+                                       // ブロッキング\r
+                                       break;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 受信成功\r
+                                       WriteFifo(n->SendFifo, buf, recv_size);\r
+                                       v->NatDoCancelFlag = true;\r
+                               }\r
+                       }\r
+               }\r
+               break;\r
+\r
+       }\r
+\r
+       // タイムアウトの検出\r
+       if ((n->LastCommTime + (UINT64)v->NatTcpTimeout) < v->Now || n->LastCommTime > v->Now)\r
+       {\r
+               // タイムアウトが発生、セッション切断\r
+               n->TcpStatus = NAT_TCP_SEND_RESET;\r
+               v->NatDoCancelFlag = true;\r
+       }\r
+\r
+       return true;\r
+\r
+DISCONNECT:            // 切断とセッション廃棄処理\r
+       DeleteNatTcp(v, n);\r
+\r
+       return false;\r
+}\r
+\r
+// TCP NAT エントリの削除\r
+void DeleteNatTcp(VH *v, NAT_ENTRY *n)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       NLog(v, "LH_NAT_TCP_DELETED", n->Id);\r
+\r
+       // 接続スレッドのシャットダウン\r
+       if (n->NatTcpConnectThread != NULL)\r
+       {\r
+               WaitThread(n->NatTcpConnectThread, INFINITE);\r
+               ReleaseThread(n->NatTcpConnectThread);\r
+               n->NatTcpConnectThread = NULL;\r
+       }\r
+       if (n->Sock != NULL)\r
+       {\r
+               // ソケット切断\r
+               Disconnect(n->Sock);\r
+               ReleaseSock(n->Sock);\r
+               n->Sock = NULL;\r
+       }\r
+\r
+       // ウインドウメモリ解放\r
+       if (n->TcpRecvWindow != NULL)\r
+       {\r
+               ReleaseFifo(n->TcpRecvWindow);\r
+               n->TcpRecvWindow = NULL;\r
+       }\r
+\r
+       // ウインドウ受信リスト解放\r
+       if (n->TcpRecvList != NULL)\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(n->TcpRecvList);i++)\r
+               {\r
+                       IP_PART *p = LIST_DATA(n->TcpRecvList, i);\r
+                       Free(p);\r
+               }\r
+               ReleaseList(n->TcpRecvList);\r
+               n->TcpRecvList = NULL;\r
+       }\r
+\r
+       // FIFO 解放\r
+       ReleaseFifo(n->SendFifo);\r
+       ReleaseFifo(n->RecvFifo);\r
+\r
+       // NAT エントリから削除\r
+       Delete(v->NatTable, n);\r
+\r
+       DeleteLock(n->lock);\r
+\r
+       // メモリ解放\r
+       Free(n);\r
+\r
+       Debug("NAT_ENTRY: DeleteNatTcp\n");\r
+}\r
+\r
+// NAT 処理スレッド\r
+void NatThread(THREAD *t, void *param)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 初期化完了を通知\r
+       NoticeThreadInit(t);\r
+\r
+       NatThreadMain((VH *)param);\r
+}\r
+\r
+// ビーコンパケットの送信\r
+void SendBeacon(VH *v)\r
+{\r
+       UINT dest_ip;\r
+       ARPV4_HEADER arp;\r
+       static char beacon_str[] =\r
+               "SecureNAT Virtual TCP/IP Stack Beacon";\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // UDP を送信\r
+       dest_ip = (v->HostIP & v->HostMask) | (~v->HostMask);\r
+       SendUdp(v, dest_ip, 7, v->HostIP, 7, beacon_str, sizeof(beacon_str));\r
+\r
+       // ARP ヘッダを構築\r
+       arp.HardwareType = Endian16(ARP_HARDWARE_TYPE_ETHERNET);\r
+       arp.ProtocolType = Endian16(MAC_PROTO_IPV4);\r
+       arp.HardwareSize = 6;\r
+       arp.ProtocolSize = 4;\r
+       arp.Operation = Endian16(ARP_OPERATION_RESPONSE);\r
+       Copy(arp.SrcAddress, v->MacAddress, 6);\r
+       arp.SrcIP = v->HostIP;\r
+       arp.TargetAddress[0] =\r
+               arp.TargetAddress[1] =\r
+               arp.TargetAddress[2] =\r
+               arp.TargetAddress[3] =\r
+               arp.TargetAddress[4] =\r
+               arp.TargetAddress[5] = 0xff;\r
+       arp.TargetIP = dest_ip;\r
+\r
+       // 送信\r
+       VirtualLayer2Send(v, broadcast, v->MacAddress, MAC_PROTO_ARPV4, &arp, sizeof(arp));\r
+}\r
+\r
+// TCP パケットの送信\r
+void SendTcp(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, UINT seq, UINT ack, UINT flag, UINT window_size, UINT mss, void *data, UINT size)\r
+{\r
+       static UCHAR tcp_mss_option[] = {0x02, 0x04, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00};\r
+       TCPV4_PSEUDO_HEADER *vh;\r
+       TCP_HEADER *tcp;\r
+       UINT header_size = TCP_HEADER_SIZE;\r
+       UINT total_size;\r
+       // 引数チェック\r
+       if (v == NULL || (size != 0 && data == NULL))\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メモリ確保\r
+       vh = Malloc(sizeof(TCPV4_PSEUDO_HEADER) + TCP_HEADER_SIZE + size + 32);\r
+       tcp = (TCP_HEADER *)(((UCHAR *)vh) + sizeof(TCPV4_PSEUDO_HEADER));\r
+\r
+       if (mss != 0)\r
+       {\r
+               USHORT *mss_size;\r
+               mss_size = (USHORT *)(&tcp_mss_option[2]);\r
+               *mss_size = Endian16((USHORT)mss);\r
+               header_size += sizeof(tcp_mss_option);\r
+       }\r
+\r
+       total_size = header_size + size;\r
+       if (total_size > 65536)\r
+       {\r
+               // パケットが長すぎる\r
+               Free(vh);\r
+               return;\r
+       }\r
+\r
+       // 擬似ヘッダ生成\r
+       vh->SrcIP = src_ip;\r
+       vh->DstIP = dest_ip;\r
+       vh->Reserved = 0;\r
+       vh->Protocol = IP_PROTO_TCP;\r
+       vh->PacketLength = Endian16((USHORT)total_size);\r
+\r
+       // TCP ヘッダ生成\r
+       tcp->SrcPort = Endian16((USHORT)src_port);\r
+       tcp->DstPort = Endian16((USHORT)dest_port);\r
+       tcp->SeqNumber = Endian32(seq);\r
+       tcp->AckNumber = Endian32(ack);\r
+       tcp->HeaderSizeAndReserved = 0;\r
+       TCP_SET_HEADER_SIZE(tcp, (UCHAR)(header_size / 4));\r
+       tcp->Flag = (UCHAR)flag;\r
+       tcp->WindowSize = Endian16((USHORT)window_size);\r
+       tcp->Checksum = 0;\r
+       tcp->UrgentPointer = 0;\r
+\r
+       // オプション値コピー\r
+       if (mss != 0)\r
+       {\r
+               Copy(((UCHAR *)tcp) + TCP_HEADER_SIZE, tcp_mss_option, sizeof(tcp_mss_option));\r
+       }\r
+\r
+       // データコピー\r
+       Copy(((UCHAR *)tcp) + header_size, data, size);\r
+\r
+       // チェックサム計算\r
+       tcp->Checksum = IpChecksum(vh, total_size + 12);\r
+\r
+       // IP パケットとして送信\r
+       SendIp(v, dest_ip, src_ip, IP_PROTO_TCP, tcp, total_size);\r
+\r
+       // メモリ解放\r
+       Free(vh);\r
+}\r
+\r
+// TCP のポーリング処理\r
+void PollingNatTcp(VH *v, NAT_ENTRY *n)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       switch (n->TcpStatus)\r
+       {\r
+       case NAT_TCP_CONNECTING:                // ソケット接続中: 何もしない\r
+               break;\r
+\r
+       case NAT_TCP_CONNECTED:                 // ソケット接続が完了した SYN+ACK, ACK 処理\r
+               if ((n->LastSynAckSentTime > v->Now) || n->LastSynAckSentTime == 0 || ((n->LastSynAckSentTime + (UINT64)(NAT_TCP_SYNACK_SEND_TIMEOUT * (UINT64)(n->SynAckSentCount + 1)) <= v->Now)))\r
+               {\r
+                       n->LastSynAckSentTime = v->Now;\r
+                       // SYN+ACK を送信する\r
+                       SendTcp(v, n->DestIp, n->DestPort, n->SrcIp, n->SrcPort,\r
+                               (UINT)(n->SendSeqInit + n->SendSeq),\r
+                               (UINT)(n->RecvSeqInit + n->RecvSeq),\r
+                               TCP_SYN | TCP_ACK, n->TcpRecvWindowSize,\r
+                               v->TcpMss, NULL, 0);\r
+                       n->SynAckSentCount++;\r
+               }\r
+               break;\r
+\r
+       case NAT_TCP_SEND_RESET:                // コネクションのリセット\r
+               // RST を送信する\r
+               if (n->TcpFinished == false)\r
+               {\r
+                       SendTcp(v, n->DestIp, n->DestPort, n->SrcIp, n->SrcPort,\r
+                               (UINT)(n->SendSeq + n->SendSeqInit),\r
+                               (UINT)(n->SendSeq + n->SendSeqInit),\r
+                               TCP_RST, 0,\r
+                               0, NULL, 0);\r
+                       // 切断する\r
+                       n->TcpStatus = NAT_TCP_WAIT_DISCONNECT;\r
+                       n->DisconnectNow = true;\r
+               }\r
+               else\r
+               {\r
+                       // 合計 NAT_FIN_SEND_MAX_COUNT 回の FIN を送信する\r
+                       if (n->FinSentTime == 0 || (n->FinSentTime > v->Now) || (n->FinSentTime + NAT_FIN_SEND_INTERVAL * (n->FinSentCount + 1)) < v->Now)\r
+                       {\r
+                               SendTcp(v, n->DestIp, n->DestPort, n->SrcIp, n->SrcPort,\r
+                                       (UINT)(n->SendSeq + n->SendSeqInit),\r
+                                       (UINT)(n->RecvSeq + n->RecvSeqInit),\r
+                                       TCP_ACK | TCP_FIN, 0,\r
+                                       0, NULL, 0);\r
+                               n->FinSentTime = v->Now;\r
+                               n->FinSentCount++;\r
+                               if (n->FinSentCount >= NAT_FIN_SEND_MAX_COUNT)\r
+                               {\r
+                                       n->TcpFinished = false;\r
+                               }\r
+                       }\r
+               }\r
+               break;\r
+\r
+       case NAT_TCP_ESTABLISHED:               // 接続確立済み\r
+               {\r
+                       UINT send_data_size;\r
+                       UINT current_pointer;\r
+                       UINT notice_window_size_value = 0;\r
+                       UINT buf_free_bytes = 0;\r
+                       // 通知するウインドウサイズの値を決定する\r
+                       if (FifoSize(n->RecvFifo) < NAT_RECV_BUF_SIZE)\r
+                       {\r
+                               buf_free_bytes = NAT_RECV_BUF_SIZE - FifoSize(n->RecvFifo);\r
+                       }\r
+                       notice_window_size_value = MIN(n->TcpRecvWindowSize, buf_free_bytes);\r
+                       if (n->LastSentKeepAliveTime == 0 ||\r
+                               (n->LastSentKeepAliveTime + (UINT64)NAT_ACK_KEEPALIVE_SPAN) < v->Now ||\r
+                               (n->LastSentKeepAliveTime > v->Now))\r
+                       {\r
+                               if (n->LastSentKeepAliveTime != 0)\r
+                               {\r
+                                       // Keep-Alive 用 ACK パケットの送信\r
+                                       SendTcp(v, n->DestIp, n->DestPort, n->SrcIp, n->SrcPort,\r
+                                                       (UINT)(n->SendSeqInit + n->SendSeq),\r
+                                                       (UINT)(n->RecvSeqInit + n->RecvSeq) - 1,\r
+                                                       TCP_ACK,\r
+                                                       notice_window_size_value,\r
+                                                       0,\r
+                                                       NULL,\r
+                                                       0);\r
+                               }\r
+                               n->LastSentKeepAliveTime = v->Now;\r
+                       }\r
+                       if (n->TcpLastSentTime == 0 ||\r
+                               (n->TcpLastSentTime > v->Now) ||\r
+                               ((n->TcpLastSentTime + (UINT64)n->TcpSendTimeoutSpan) < v->Now) ||\r
+                               n->SendAckNext)\r
+                       {\r
+                               // 送信すべきデータがある場合は送信する\r
+                               // 送信すべきセグメントサイズを計算する\r
+                               send_data_size = n->TcpSendWindowSize;\r
+                               if (send_data_size > (n->TcpSendCWnd * n->TcpSendMaxSegmentSize))\r
+                               {\r
+                                       // cwnd 値を適用する\r
+                                       send_data_size = n->TcpSendCWnd * n->TcpSendMaxSegmentSize;\r
+                               }\r
+                               if (send_data_size > n->SendFifo->size)\r
+                               {\r
+                                       // 現在保有しているデータ以上は送れない\r
+                                       send_data_size = n->SendFifo->size;\r
+                               }\r
+                               if (send_data_size >= 1)\r
+                               {\r
+                                       // セグメントに分割して送信する\r
+                                       current_pointer = 0;\r
+                                       while (send_data_size > 0)\r
+                                       {\r
+                                               UINT send_segment_size = MIN(n->TcpSendMaxSegmentSize, send_data_size);\r
+                                               void *send_segment = (void *)(((UCHAR *)n->SendFifo->p) + n->SendFifo->pos + current_pointer);\r
+                                               SendTcp(v, n->DestIp, n->DestPort, n->SrcIp, n->SrcPort,\r
+                                                       (UINT)(n->SendSeqInit + n->SendSeq + (UINT64)current_pointer),\r
+                                                       (UINT)(n->RecvSeqInit + n->RecvSeq),\r
+                                                       TCP_ACK | TCP_PSH,\r
+                                                       notice_window_size_value,\r
+                                                       0,\r
+                                                       send_segment,\r
+                                                       send_segment_size);\r
+                                               current_pointer += send_segment_size;\r
+                                               send_data_size -= send_segment_size;\r
+                                       }\r
+                                       // 送信時刻を記録する\r
+                                       n->TcpLastSentTime = v->Now;\r
+                                       // 今回送信するストリームサイズを記録する\r
+                                       n->SendMissionSize = current_pointer;\r
+                                       n->CurrentSendingMission = true;\r
+                                       // RTT 測定\r
+                                       if (n->CalcRTTStartTime == 0)\r
+                                       {\r
+                                               n->CalcRTTStartTime = v->Now;\r
+                                               n->CalcRTTStartValue = n->SendSeq + current_pointer - 1;\r
+                                       }\r
+                                       if (n->RetransmissionUsedFlag == false)\r
+                                       {\r
+                                               n->RetransmissionUsedFlag = true;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // 輻輳発生を検出\r
+                                               if (n->TcpSendCWnd > 2)\r
+                                               {\r
+                                                       n->TcpSendCWnd--;\r
+                                               }\r
+                                       }\r
+                               }\r
+                               else if (n->SendAckNext)\r
+                               {\r
+                                       // ACK のみ送信する\r
+                                       SendTcp(v, n->DestIp, n->DestPort, n->SrcIp, n->SrcPort,\r
+                                                       (UINT)(n->SendSeqInit + n->SendSeq),\r
+                                                       (UINT)(n->RecvSeqInit + n->RecvSeq),\r
+                                                       TCP_ACK,\r
+                                                       notice_window_size_value,\r
+                                                       0,\r
+                                                       NULL,\r
+                                                       0);\r
+                               }\r
+                               n->SendAckNext = false;\r
+                       }\r
+                       if (n->TcpFinished)\r
+                       {\r
+                               // すべてのデータ送信が完了していたら切断する\r
+                               if (n->SendFifo->size == 0)\r
+                               {\r
+                                       n->TcpStatus = NAT_TCP_SEND_RESET;\r
+                               }\r
+                       }\r
+               }\r
+               break;\r
+       }\r
+}\r
+\r
+// インターネットへ向かう TCP パケットの受信処理\r
+void TcpRecvForInternet(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, TCP_HEADER *tcp, void *data, UINT size)\r
+{\r
+       NAT_ENTRY *n, t;\r
+       UINT seq, ack;\r
+       UINT64 seq64 = 0, ack64 = 0;\r
+       // 引数チェック\r
+       if (v == NULL || tcp == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // このパケットに関するセッションを NAT テーブルから検索\r
+       SetNat(&t, NAT_TCP, src_ip, src_port, dest_ip, dest_port, 0, 0);\r
+       n = SearchNat(v, &t);\r
+\r
+       if (n == NULL)\r
+       {\r
+               // 既存のセッションが存在しない\r
+               // SYN パケットのみ通過を許可する\r
+               if ((tcp->Flag & TCP_SYN) && ((tcp->Flag & TCP_ACK) == false))\r
+               {\r
+                       TCP_OPTION o;\r
+                       // 新しいセッションを作成する\r
+                       n = CreateNatTcp(v, src_ip, src_port, dest_ip, dest_port);\r
+                       if (n == NULL)\r
+                       {\r
+                               return;\r
+                       }\r
+\r
+                       // オプションの取得\r
+                       ParseTcpOption(&o, ((UCHAR *)tcp) + TCP_HEADER_SIZE, TCP_GET_HEADER_SIZE(tcp) * 4 - TCP_HEADER_SIZE);\r
+                       if (o.MaxSegmentSize == 0)\r
+                       {\r
+                               o.MaxSegmentSize = v->TcpMss;\r
+                       }\r
+\r
+                       Debug("TCP SYN: MSS=%u, WS=%u\n", o.MaxSegmentSize, o.WindowScaling);\r
+\r
+                       // 初期シーケンス番号\r
+                       n->RecvSeqInit = (UINT64)Endian32(tcp->SeqNumber);\r
+                       n->RecvSeq = 1;\r
+\r
+                       n->TcpSendMaxSegmentSize = o.MaxSegmentSize;\r
+                       n->TcpRecvWindowSize = NAT_TCP_RECV_WINDOW_SIZE;\r
+                       n->TcpSendWindowSize = (UINT)Endian16(tcp->WindowSize);\r
+                       if (o.WindowScaling != 0)\r
+                       {\r
+                               if (o.WindowScaling > 14)\r
+                               {\r
+                                       o.WindowScaling = 14;\r
+                               }\r
+                               n->TcpSendWindowSize = (n->TcpSendWindowSize << o.WindowScaling);\r
+                       }\r
+               }\r
+       }\r
+\r
+       seq = Endian32(tcp->SeqNumber);\r
+       ack = Endian32(tcp->AckNumber);\r
+\r
+       if (n == NULL)\r
+       {\r
+               // NAT エントリに登録されていないパケットが届いたので RST を返す\r
+               SendTcp(v, dest_ip, dest_port, src_ip, src_port,\r
+                       ack, ack, TCP_RST, 0, 0, NULL, 0);\r
+               return;\r
+       }\r
+\r
+       switch (n->TcpStatus)\r
+       {\r
+       case NAT_TCP_SEND_RESET:                // リセットを送信してコネクションを切断\r
+               break;\r
+\r
+       case NAT_TCP_CONNECTED:                 // ソケット接続完了 SYN+ACK, ACK 処理\r
+               if ((tcp->Flag & TCP_ACK) && ((tcp->Flag & TCP_SYN) == false))\r
+               {\r
+                       if (seq == (UINT)(n->RecvSeqInit + n->RecvSeq) &&\r
+                               ack == (UINT)(n->SendSeqInit + n->SendSeq + 1))\r
+                       {\r
+                               // ACK パケットが戻ってきたのでハンドシェイク完了\r
+                               n->SendSeq++;           // SYN パケットは seq を 1 消費する\r
+                               Debug("TCP Connection Established.\n");\r
+                               n->TcpStatus = NAT_TCP_ESTABLISHED;\r
+                               // 輻輳ウインドウサイズを初期化\r
+                               n->TcpSendCWnd = 1;\r
+                               n->LastCommTime = v->Now;\r
+                       }\r
+                       else\r
+                       {\r
+                               goto TCP_RESET;\r
+                       }\r
+               }\r
+               else if (tcp->Flag & TCP_RST)\r
+               {\r
+TCP_RESET:\r
+                       // RST を受信\r
+                       Debug("TCP Connection Reseted.\n");\r
+                       n->TcpStatus = NAT_TCP_SEND_RESET;\r
+               }\r
+               break;\r
+\r
+       case NAT_TCP_ESTABLISHED:               // 接続確立済み\r
+               if (tcp->Flag & TCP_FIN)\r
+               {\r
+                       // 接続を完了させる\r
+                       n->TcpFinished = true;\r
+               }\r
+               if (tcp->Flag & TCP_RST)\r
+               {\r
+                       // RST を受信\r
+                       goto TCP_RESET;\r
+               }\r
+               else if (tcp->Flag & TCP_ACK)\r
+               {\r
+                       TCP_OPTION opt;\r
+                       n->LastCommTime = v->Now;\r
+                       // ウインドウサイズなどのオプションの取得\r
+                       n->TcpSendWindowSize = Endian16(tcp->WindowSize);\r
+                       ParseTcpOption(&opt, ((UCHAR *)tcp) + TCP_HEADER_SIZE, TCP_GET_HEADER_SIZE(tcp) * 4 - TCP_HEADER_SIZE);\r
+                       if (opt.WindowScaling != 0)\r
+                       {\r
+                               if (opt.WindowScaling > 14)\r
+                               {\r
+                                       opt.WindowScaling = 14;\r
+                               }\r
+                               n->TcpSendWindowSize = (n->TcpSendWindowSize << opt.WindowScaling);\r
+                       }\r
+                       // まず受信した ACK の処理を行う\r
+                       // ack64 に応答確認を受けたストリームの終端位置を格納する\r
+                       ack64 = n->SendSeq + (UINT64)ack - (n->SendSeqInit + n->SendSeq) % X32;\r
+                       if ((n->SendSeqInit + n->SendSeq) % X32 > ack)\r
+                       {\r
+                               if (((n->SendSeqInit + n->SendSeq) % X32 - ack) >= 0x80000000)\r
+                               {\r
+                                       ack64 = n->SendSeq + (UINT64)ack + X32 - (n->SendSeqInit + n->SendSeq) % X32;\r
+                               }\r
+                       }\r
+                       if (ack64 > n->SendSeq)\r
+                       {\r
+                               // クライアントによって 1 バイト以上の受信が完了したらしい\r
+                               UINT slide_offset = (UINT)(ack64 - n->SendSeq); // ウインドウのスライド量\r
+                               if (slide_offset == 0 || slide_offset > n->TcpSendWindowSize || slide_offset > n->SendFifo->size)\r
+                               {\r
+                                       // 確認応答のオフセット値がこれまでに送信したはずのサイズ\r
+                                       // よりも大きいので無視する\r
+                               }\r
+                               else\r
+                               {\r
+                                       // RTT 測定\r
+                                       if (n->CalcRTTStartTime != 0)\r
+                                       {\r
+                                               if (n->CalcRTTStartValue < ack64)\r
+                                               {\r
+                                                       UINT time_span;\r
+                                                       if (v->Now > n->CalcRTTStartTime)\r
+                                                       {\r
+                                                               time_span = (UINT)(v->Now - n->CalcRTTStartTime);\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               time_span = 100;\r
+                                                       }\r
+                                                       n->CalcRTTStartTime = 0;\r
+\r
+                                                       // 平滑化\r
+                                                       n->CurrentRTT =\r
+                                                               (UINT)\r
+                                                               (\r
+                                                                       ((UINT64)n->CurrentRTT * (UINT64)9 +\r
+                                                                       (UINT64)time_span * (UINT64)1) / (UINT64)10\r
+                                                               );\r
+                                                       n->TcpSendTimeoutSpan = n->CurrentRTT * 2;\r
+                                               }\r
+                                       }\r
+                                       // 送信サイズを減少させる\r
+                                       n->SendMissionSize -= slide_offset;\r
+                                       if (n->SendMissionSize == 0)\r
+                                       {\r
+                                               // 今回送信する予定であったすべてのセグメントの送受信が完了した\r
+                                               // より送信セグメントサイズを大きくしてみる\r
+                                               if (n->TcpSendCWnd < 65536)\r
+                                               {\r
+                                                       n->TcpSendCWnd++;\r
+                                               }\r
+                                               n->CurrentSendingMission = false;\r
+                                               n->TcpLastSentTime = 0;\r
+                                               n->RetransmissionUsedFlag = false;\r
+                                       }\r
+                                       // バッファをスライディングする\r
+                                       n->SendSeq += slide_offset;\r
+                                       ReadFifo(n->SendFifo, NULL, slide_offset);\r
+                                       // 今回 ACK によって送信完了が確認できたサイズだけ、さらに送信を実行する\r
+                                       if (n->SendMissionSize != 0 && false)\r
+                                       {\r
+                                               UINT notice_window_size_value = 0;\r
+                                               UINT send_data_size;\r
+                                               UINT buf_free_bytes;\r
+                                               UINT send_offset = n->SendMissionSize;\r
+                                               // 通知するウインドウサイズの値を決定する\r
+                                               if (FifoSize(n->RecvFifo) < NAT_RECV_BUF_SIZE)\r
+                                               {\r
+                                                       buf_free_bytes = NAT_RECV_BUF_SIZE - FifoSize(n->RecvFifo);\r
+                                               }\r
+                                               notice_window_size_value = MIN(n->TcpRecvWindowSize, buf_free_bytes);\r
+                                               // 送信すべきセグメントサイズを計算する\r
+                                               send_data_size = n->TcpSendWindowSize;\r
+                                               if (send_data_size > (n->TcpSendCWnd * n->TcpSendMaxSegmentSize))\r
+                                               {\r
+                                                       // cwnd 値を適用する\r
+                                                       send_data_size = n->TcpSendCWnd * n->TcpSendMaxSegmentSize;\r
+                                               }\r
+                                               if (n->SendFifo->size > send_offset)\r
+                                               {\r
+                                                       send_data_size = MIN(send_data_size, n->SendFifo->size - send_offset);\r
+                                                       send_data_size = MIN(send_data_size, slide_offset);\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       send_data_size = 0;\r
+                                               }\r
+                                               if (send_data_size >= 1)\r
+                                               {\r
+                                                       // セグメントに分割して送信する\r
+                                                       UINT current_pointer = 0;\r
+                                                       while (send_data_size > 0)\r
+                                                       {\r
+                                                               UINT send_segment_size = MIN(n->TcpSendMaxSegmentSize, send_data_size);\r
+                                                               void *send_segment = (void *)((\r
+                                                                       (UCHAR *)n->SendFifo->p) + n->SendFifo->pos +\r
+                                                                       current_pointer + send_offset);\r
+\r
+                                                               SendTcp(v, n->DestIp, n->DestPort, n->SrcIp, n->SrcPort,\r
+                                                                       (UINT)(n->SendSeqInit + n->SendSeq + (UINT64)current_pointer\r
+                                                                       + (UINT)send_offset),\r
+                                                                       (UINT)(n->RecvSeqInit + n->RecvSeq),\r
+                                                                       TCP_ACK | TCP_PSH,\r
+                                                                       notice_window_size_value,\r
+                                                                       0,\r
+                                                                       send_segment,\r
+                                                                       send_segment_size);\r
+                                                               current_pointer += send_segment_size;\r
+                                                               send_data_size -= send_segment_size;\r
+                                                       }\r
+                                                       n->SendMissionSize += current_pointer;\r
+                                                       n->CurrentSendingMission = true;\r
+                                                       n->TcpLastSentTime = v->Now;\r
+                                                       // RTT 測定\r
+                                                       if (n->CalcRTTStartTime == 0)\r
+                                                       {\r
+                                                               n->CalcRTTStartTime = v->Now;\r
+                                                               n->CalcRTTStartValue = n->SendSeq + current_pointer - 1;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       // イベント発生\r
+                                       SetSockEvent(v->SockEvent);\r
+                               }\r
+                       }\r
+                       // 次にデータの受信処理を行う\r
+                       seq64 = n->RecvSeq + (UINT64)seq - (n->RecvSeqInit + n->RecvSeq) % X32;\r
+                       if ((n->RecvSeqInit + n->RecvSeq) % X32 > seq)\r
+                       {\r
+                               if (((n->RecvSeqInit + n->RecvSeq) % X32 - ack) >= 0x80000000)\r
+                               {\r
+                                       seq64 = n->RecvSeq + (UINT64)seq + X32 - (n->RecvSeqInit + n->RecvSeq) % X32;\r
+                               }\r
+                       }\r
+                       // この時点で seq64 にはクライアントからのデータ開始点の位置が入っている\r
+                       if (seq64 >= n->RecvSeq && (seq64 + size) <= (n->RecvSeq + n->TcpRecvWindowSize))\r
+                       {\r
+                               if (size >= 1)\r
+                               {\r
+                                       // 受信ウインドウの範囲内に 1 バイト以上のデータが届いた\r
+                                       UINT offset = (UINT)(seq64 - n->RecvSeq);\r
+                                       UINT i;\r
+                                       IP_PART *me;\r
+                                       if (n->TcpRecvWindow == NULL)\r
+                                       {\r
+                                               n->TcpRecvWindow = NewFifo();\r
+                                       }\r
+                                       if (n->TcpRecvList == NULL)\r
+                                       {\r
+                                               n->TcpRecvList = NewListFast(NULL);\r
+                                       }\r
+                                       // 届いたパケットをバッファに上書きしリストに追加する\r
+                                       if (FifoSize(n->TcpRecvWindow) < (offset + size))\r
+                                       {\r
+                                               // バッファサイズ拡張\r
+                                               WriteFifo(n->TcpRecvWindow, NULL, offset + size - FifoSize(n->TcpRecvWindow));\r
+                                       }\r
+                                       Copy(((UCHAR *)n->TcpRecvWindow->p) + n->TcpRecvWindow->pos +\r
+                                               offset, data, size);\r
+                                       me = ZeroMalloc(sizeof(IP_PART));\r
+                                       me->Offset = offset;\r
+                                       me->Size = size;\r
+                                       for (i = 0;i < LIST_NUM(n->TcpRecvList);i++)\r
+                                       {\r
+                                               IP_PART *p = LIST_DATA(n->TcpRecvList, i);\r
+                                               // 重なる領域があれば重なっている部分があれば除去する\r
+                                               if (p->Size != 0)\r
+                                               {\r
+                                                       if (me->Offset <= p->Offset && (me->Offset + me->Size) >= (p->Offset + p->Size))\r
+                                                       {\r
+                                                               // このパケットが既存パケットを完全に上書きする\r
+                                                               p->Size = 0;\r
+                                                       }\r
+                                                       else if (me->Offset >= p->Offset && (me->Offset + me->Size) <= (p->Offset + p->Size))\r
+                                                       {\r
+                                                               // 既存パケットがこのパケットを完全に上書きする\r
+                                                               me->Size = 0;\r
+                                                       }\r
+                                                       else if (me->Offset > p->Offset && me->Offset < (p->Offset + p->Size) &&\r
+                                                               (me->Offset + me->Size) > (p->Offset + p->Size))\r
+                                                       {\r
+                                                               // 一部重なっている\r
+                                                               p->Size -= p->Offset + p->Size - me->Offset;\r
+                                                       }\r
+                                                       else if (me->Offset < p->Offset && (me->Offset + size) > p->Offset && (me->Offset + size) < (p->Offset + p->Size))\r
+                                                       {\r
+                                                               // 一部重なっている\r
+                                                               me->Size -= me->Offset + me->Size - p->Offset;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       if (me->Size == 0)\r
+                                       {\r
+                                               Free(me);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               Add(n->TcpRecvList, me);\r
+                                       }\r
+KILL_NULL_FIRST:\r
+                                       // 受信リストから中身が空白のものをすべて削除する\r
+                                       for (i = 0;i < LIST_NUM(n->TcpRecvList);i++)\r
+                                       {\r
+                                               IP_PART *p = LIST_DATA(n->TcpRecvList, i);\r
+                                               if (p->Size == 0)\r
+                                               {\r
+                                                       Delete(n->TcpRecvList, p);\r
+                                                       Free(p);\r
+                                                       goto KILL_NULL_FIRST;\r
+                                               }\r
+                                       }\r
+SCAN_FIRST:\r
+                                       // 受信リストのうちオフセット 0 から始まるものがあれば抽出する\r
+                                       for (i = 0;i < LIST_NUM(n->TcpRecvList);i++)\r
+                                       {\r
+                                               IP_PART *p = LIST_DATA(n->TcpRecvList, i);\r
+                                               UINT sz;\r
+                                               if (p->Offset == 0)\r
+                                               {\r
+                                                       // 0 から始まるデータブロックを発見したので\r
+                                                       // この分だけ左側にスライドさせてデータを抜き出す\r
+                                                       // バッファを FIFO に書き出す\r
+                                                       sz = p->Size;\r
+                                                       WriteFifo(n->RecvFifo, ((UCHAR *)n->TcpRecvWindow->p) + n->TcpRecvWindow->pos, sz);\r
+                                                       // リストから解放する\r
+                                                       Delete(n->TcpRecvList, p);\r
+                                                       Free(p);\r
+                                                       ReadFifo(n->TcpRecvWindow, NULL, sz);\r
+                                                       // すべての項目を左側にスライドする\r
+                                                       for (i = 0;i < LIST_NUM(n->TcpRecvList);i++)\r
+                                                       {\r
+                                                               p = LIST_DATA(n->TcpRecvList, i);\r
+                                                               p->Offset -= sz;\r
+                                                       }\r
+                                                       // TCB のパラメータを更新\r
+                                                       n->RecvSeq += (UINT64)sz;\r
+                                                       SetSockEvent(v->SockEvent);\r
+                                                       n->SendAckNext = true;\r
+                                                       // 最初からスキャンし直す\r
+                                                       goto SCAN_FIRST;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               break;\r
+       }\r
+\r
+       SetSockEvent(v->SockEvent);\r
+}\r
+\r
+// TCP オプションのパース\r
+void ParseTcpOption(TCP_OPTION *o, void *data, UINT size)\r
+{\r
+       UCHAR *buf = (UCHAR *)data;\r
+       UINT i;\r
+       UINT value_size = 0;\r
+       UINT value_id = 0;\r
+       UCHAR value[128];\r
+       // 引数チェック\r
+       if (o == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(o, sizeof(TCP_OPTION));\r
+\r
+       for (i = 0;i < size;i++)\r
+       {\r
+               if (buf[i] == 0)\r
+               {\r
+                       return;\r
+               }\r
+               if (buf[i] != 1)\r
+               {\r
+                       value_id = buf[i];\r
+                       i++;\r
+                       if (i >= size)\r
+                       {\r
+                               return;\r
+                       }\r
+                       value_size = buf[i];\r
+                       if (value_size <= 1 || value_size > sizeof(value))\r
+                       {\r
+                               return;\r
+                       }\r
+                       i++;\r
+                       if (i >= size)\r
+                       {\r
+                               return;\r
+                       }\r
+                       value_size -= 2;\r
+                       Copy(value, &buf[i], value_size);\r
+                       i += value_size;\r
+                       if (i >= size)\r
+                       {\r
+                               return;\r
+                       }\r
+                       switch (value_id)\r
+                       {\r
+                       case 2: // MSS\r
+                               if (value_size == 2)\r
+                               {\r
+                                       USHORT *mss = (USHORT *)value;\r
+                                       o->MaxSegmentSize = Endian16(*mss);\r
+                               }\r
+                               break;\r
+\r
+                       case 3: // WSS\r
+                               if (value_size == 1)\r
+                               {\r
+                                       UCHAR *wss = (UCHAR *)value;\r
+                                       o->WindowScaling = Endian16(*wss);\r
+                               }\r
+                               break;\r
+\r
+                       }\r
+               }\r
+       }\r
+\r
+}\r
+\r
+// 新しい NAT TCP セッションの作成\r
+NAT_ENTRY *CreateNatTcp(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port)\r
+{\r
+       NAT_ENTRY *n;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (CanCreateNewNatEntry(v) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // NAT エントリの作成\r
+       n = ZeroMalloc(sizeof(NAT_ENTRY));\r
+       n->Id = Inc(v->Counter);\r
+       n->v = v;\r
+       n->lock = NewLock();\r
+       n->Protocol = NAT_TCP;\r
+       n->SrcIp = src_ip;\r
+       n->SrcPort = src_port;\r
+       n->DestIp = dest_ip;\r
+       n->DestPort = dest_port;\r
+       n->CreatedTime = n->LastCommTime = v->Now;\r
+       n->Sock = NULL;\r
+       n->DisconnectNow = false;\r
+       n->TcpSendMaxSegmentSize = n->TcpRecvMaxSegmentSize = v->TcpMss;\r
+\r
+       n->SendFifo = NewFifo();\r
+       n->RecvFifo = NewFifo();\r
+\r
+       n->TcpStatus = NAT_TCP_CONNECTING;\r
+\r
+       n->SendSeqInit = Rand32();\r
+       n->CurrentRTT = NAT_INITIAL_RTT_VALUE;\r
+       n->TcpSendTimeoutSpan = n->CurrentRTT * 2;\r
+\r
+       // NAT テーブルに追加\r
+       Add(v->NatTable, n);\r
+\r
+\r
+#if    1\r
+       {\r
+               IP ip1, ip2;\r
+               char s1[MAX_SIZE], s2[MAX_SIZE];\r
+               UINTToIP(&ip1, src_ip);\r
+               UINTToIP(&ip2, dest_ip);\r
+               IPToStr(s1, 0, &ip1);\r
+               IPToStr(s2, 0, &ip2);\r
+               Debug("NAT_ENTRY: CreateNatTcp %s %u -> %s %u\n", s1, src_port, s2, dest_port);\r
+\r
+               NLog(v, "LH_NAT_TCP_CREATED", n->Id, s1, src_port, s2, dest_port);\r
+       }\r
+#endif\r
+\r
+       return n;\r
+}\r
+\r
+// TCP パケットを仮想ネットワークから受信した\r
+void VirtualTcpReceived(VH *v, UINT src_ip, UINT dest_ip, void *data, UINT size)\r
+{\r
+       TCP_HEADER *tcp;\r
+       UINT src_port, dest_port;\r
+       UINT header_size, buf_size;\r
+       void *buf;\r
+       IP ip1, ip2;\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ヘッダを取得\r
+       if (size < TCP_HEADER_SIZE)\r
+       {\r
+               // サイズが小さすぎる\r
+               return;\r
+       }\r
+       tcp = (TCP_HEADER *)data;\r
+       src_port = Endian16(tcp->SrcPort);\r
+       dest_port = Endian16(tcp->DstPort);\r
+       if (src_port == 0 || dest_port == 0)\r
+       {\r
+               // ポート番号が不正\r
+               return;\r
+       }\r
+       if (src_ip == dest_ip || src_ip == 0 || src_ip == 0xffffffff || dest_ip == 0 || dest_ip == 0xffffffff)\r
+       {\r
+               // IP アドレスが不正\r
+               return;\r
+       }\r
+       UINTToIP(&ip1, src_ip);\r
+       UINTToIP(&ip2, dest_ip);\r
+       if (ip1.addr[0] == 127 || ip2.addr[0] == 127)\r
+       {\r
+               // ループバック IP アドレスは指定できない\r
+               return;\r
+       }\r
+       if (IsInNetwork(dest_ip, v->HostIP, v->HostMask))\r
+       {\r
+               // 仮想 LAN 側のネットワーク向けのパケットは無視する\r
+               return;\r
+       }\r
+       // ヘッダサイズを取得\r
+       header_size = TCP_GET_HEADER_SIZE(tcp) * 4;\r
+       if (size < header_size)\r
+       {\r
+               // ヘッダサイズが不正\r
+               return;\r
+       }\r
+       // バッファのサイズとアドレスを取得\r
+       buf_size = size - header_size;\r
+       buf = (void *)(((UCHAR *)data) + header_size);\r
+\r
+       TcpRecvForInternet(v, src_ip, src_port, dest_ip, dest_port, tcp, buf, buf_size);\r
+}\r
+\r
+// NAT UDP ポーリング\r
+void PoolingNatUdp(VH *v, NAT_ENTRY *n)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 受信キューにパケットが 1 つ以上あれば処理する\r
+       if (n->UdpRecvQueue->num_item != 0)\r
+       {\r
+               BLOCK *block;\r
+\r
+               // すべての UDP パケットを仮想ネットワークに送信する\r
+               while (block = GetNext(n->UdpRecvQueue))\r
+               {\r
+                       SendUdp(v, n->SrcIp, n->SrcPort, n->DestIp, n->DestPort,\r
+                               block->Buf, block->Size);\r
+\r
+                       FreeBlock(block);\r
+               }\r
+       }\r
+}\r
+\r
+// NAT ポーリング\r
+void PoolingNat(VH *v)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // すべての NAT エントリを走査し処理を行う\r
+       for (i = 0;i < LIST_NUM(v->NatTable);i++)\r
+       {\r
+               NAT_ENTRY *n = LIST_DATA(v->NatTable, i);\r
+\r
+               switch (n->Protocol)\r
+               {\r
+               case NAT_TCP:\r
+                       PollingNatTcp(v, n);\r
+                       break;\r
+\r
+               case NAT_UDP:\r
+                       PoolingNatUdp(v, n);\r
+                       break;\r
+\r
+               case NAT_DNS:\r
+                       PollingNatDns(v, n);\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// NAT テーブルの比較関数\r
+int CompareNat(void *p1, void *p2)\r
+{\r
+       NAT_ENTRY *n1, *n2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       n1 = *(NAT_ENTRY **)p1;\r
+       n2 = *(NAT_ENTRY **)p2;\r
+       if (n1 == n2)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (n1->SrcIp > n2->SrcIp) return 1;\r
+       else if (n1->SrcIp < n2->SrcIp) return -1;\r
+       else if (n1->DestIp > n2->DestIp) return 1;\r
+       else if (n1->DestIp < n2->DestIp) return -1;\r
+       else if (n1->SrcPort > n2->SrcPort) return 1;\r
+       else if (n1->SrcPort < n2->SrcPort) return -1;\r
+       else if (n1->DestPort > n2->DestPort) return 1;\r
+       else if (n1->DestPort < n2->DestPort) return -1;\r
+       else if (n1->Protocol > n2->Protocol) return 1;\r
+       else if (n1->Protocol < n2->Protocol) return -1;\r
+       else return 0;\r
+}\r
+\r
+// NAT 構造体の設定\r
+void SetNat(NAT_ENTRY *n, UINT protocol, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, UINT public_ip, UINT public_port)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       n->Protocol = protocol;\r
+       n->SrcIp = src_ip;\r
+       n->SrcPort = src_port;\r
+       n->DestIp = dest_ip;\r
+       n->DestPort = dest_port;\r
+       n->PublicIp = public_ip;\r
+       n->PublicPort = public_port;\r
+}\r
+\r
+// NAT の初期化\r
+void InitNat(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // NAT テーブルの作成\r
+       v->NatTable = NewList(CompareNat);\r
+\r
+       // ソケットイベントの作成\r
+       v->SockEvent = NewSockEvent();\r
+\r
+       // NAT 用スレッドの作成\r
+       v->HaltNat = false;\r
+       v->NatThread = NewThread(NatThread, (void *)v);\r
+       WaitThreadInit(v->NatThread);\r
+}\r
+\r
+// NAT の解放\r
+void FreeNat(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // NAT 用スレッドの停止\r
+       v->HaltNat = true;\r
+       SetSockEvent(v->SockEvent);\r
+       WaitThread(v->NatThread, INFINITE);\r
+       ReleaseThread(v->NatThread);\r
+       v->NatThread = NULL;\r
+       ReleaseSockEvent(v->SockEvent);\r
+       v->SockEvent = NULL;\r
+\r
+       // NAT テーブルの解放\r
+       ReleaseList(v->NatTable);\r
+}\r
+\r
+// NAT テーブルの検索\r
+NAT_ENTRY *SearchNat(VH *v, NAT_ENTRY *target)\r
+{\r
+       NAT_ENTRY *n;\r
+       // 引数チェック\r
+       if (v == NULL || target == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // バイナリサーチ\r
+       n = (NAT_ENTRY *)Search(v->NatTable, target);\r
+\r
+       return n;\r
+}\r
+\r
+// UDP NAT エントリの削除\r
+void DeleteNatUdp(VH *v, NAT_ENTRY *n)\r
+{\r
+       BLOCK *block;\r
+       // 引数チェック\r
+       if (v == NULL || n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       NLog(v, "LH_NAT_UDP_DELETED", n->Id);\r
+\r
+       // すべてのキューを解放\r
+       while (block = GetNext(n->UdpRecvQueue))\r
+       {\r
+               FreeBlock(block);\r
+       }\r
+       ReleaseQueue(n->UdpRecvQueue);\r
+       while (block = GetNext(n->UdpSendQueue))\r
+       {\r
+               FreeBlock(block);\r
+       }\r
+       ReleaseQueue(n->UdpSendQueue);\r
+\r
+       // ソケットを解放\r
+       if (n->Sock != NULL)\r
+       {\r
+               Disconnect(n->Sock);\r
+               ReleaseSock(n->Sock);\r
+               n->Sock = NULL;\r
+       }\r
+\r
+       DeleteLock(n->lock);\r
+\r
+       // テーブルから削除\r
+       Delete(v->NatTable, n);\r
+\r
+       // メモリ解放\r
+       Free(n);\r
+\r
+       Debug("NAT: DeleteNatUdp\n");\r
+\r
+}\r
+\r
+// NAT UDP エントリを作成\r
+NAT_ENTRY *CreateNatUdp(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, UINT dns_proxy_ip)\r
+{\r
+       NAT_ENTRY *n;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (CanCreateNewNatEntry(v) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       n = ZeroMalloc(sizeof(NAT_ENTRY));\r
+       n->Id = Inc(v->Counter);\r
+       n->v = v;\r
+       n->lock = NewLock();\r
+       n->Protocol = NAT_UDP;\r
+       n->SrcIp = src_ip;\r
+       n->SrcPort = src_port;\r
+       n->DestIp = dest_ip;\r
+       n->DestPort = dest_port;\r
+\r
+       if (dns_proxy_ip != 0)\r
+       {\r
+               n->ProxyDns = true;\r
+               n->DestIpProxy = dns_proxy_ip;\r
+       }\r
+\r
+       n->CreatedTime = n->LastCommTime = v->Now;\r
+\r
+       n->UdpSendQueue = NewQueue();\r
+       n->UdpRecvQueue = NewQueue();\r
+\r
+       n->UdpSocketCreated = false;\r
+\r
+       SetSockEvent(v->SockEvent);\r
+\r
+#if    1\r
+       {\r
+               IP ip1, ip2;\r
+               char s1[MAX_SIZE], s2[MAX_SIZE];\r
+               UINTToIP(&ip1, src_ip);\r
+               UINTToIP(&ip2, dest_ip);\r
+               IPToStr(s1, 0, &ip1);\r
+               IPToStr(s2, 0, &ip2);\r
+               Debug("NAT_ENTRY: CreateNatUdp %s %u -> %s %u\n", s1, src_port, s2, dest_port);\r
+\r
+               NLog(v, "LH_NAT_UDP_CREATED", n->Id, s1, src_port, s2, dest_port);\r
+       }\r
+#endif\r
+\r
+       Add(v->NatTable, n);\r
+\r
+       return n;\r
+}\r
+\r
+// インターネットへの UDP パケットの処理\r
+void UdpRecvForInternet(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, void *data, UINT size, bool dns_proxy)\r
+{\r
+       NAT_ENTRY *n, t;\r
+       BLOCK *block;\r
+       void *buf;\r
+       UINT dns_ip = 0;\r
+       // 引数チェック\r
+       if (data == NULL || v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (dns_proxy)\r
+       {\r
+               // プロキシ接続先の DNS サーバーを取得する\r
+               IP ip;\r
+               char tmp[MAX_SIZE];\r
+               if (GetDefaultDns(&ip) == false)\r
+               {\r
+                       // 失敗\r
+                       Debug("Failed to GetDefaultDns()\n");\r
+                       return;\r
+               }\r
+               dns_ip = IPToUINT(&ip);\r
+               IPToStr(tmp, sizeof(tmp), &ip);\r
+               Debug("Redirect to DNS Server %s\n", tmp);\r
+       }\r
+\r
+       // このパケットに関する NAT エントリがすでに作成されているかどうかを調べる\r
+       SetNat(&t, NAT_UDP, src_ip, src_port, dest_ip, dest_port, 0, 0);\r
+       n = SearchNat(v, &t);\r
+\r
+       if (n == NULL)\r
+       {\r
+               // 最初のパケットなので NAT エントリを作成する\r
+               n = CreateNatUdp(v, src_ip, src_port, dest_ip, dest_port, dns_proxy ? dns_ip : 0);\r
+               if (n == NULL)\r
+               {\r
+                       // エントリ作成失敗\r
+                       return;\r
+               }\r
+\r
+               if (dns_proxy)\r
+               {\r
+                       n->ProxyDns = true;\r
+                       n->DestIpProxy = dns_ip;\r
+               }\r
+       }\r
+\r
+       // キューにパケットを挿入してイベントを呼び出す\r
+       buf = Malloc(size);\r
+       Copy(buf, data, size);\r
+       block = NewBlock(buf, size, 0);\r
+       InsertQueue(n->UdpSendQueue, block);\r
+\r
+       SetSockEvent(v->SockEvent);\r
+}\r
+\r
+// DNS パケットの解釈を試行する\r
+bool ParseDnsPacket(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, void *data, UINT size)\r
+{\r
+       DNSV4_HEADER *dns;\r
+       NAT_ENTRY *nat;\r
+       UINT transaction_id;\r
+       void *query_data;\r
+       UINT query_data_size;\r
+       char hostname[256];\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL || size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ヘッダサイズのチェック\r
+       if (size < sizeof(DNSV4_HEADER))\r
+       {\r
+               // サイズ不足\r
+               return false;\r
+       }\r
+\r
+       // DNS ヘッダ取得\r
+       dns = (DNSV4_HEADER *)data;\r
+       transaction_id = Endian16(dns->TransactionId);\r
+       if ((dns->Flag1 & 78) != 0 || (dns->Flag1 & 0x80) != 0)\r
+       {\r
+               // オペコード不正\r
+               return false;\r
+       }\r
+       if (Endian16(dns->NumQuery) != 1)\r
+       {\r
+               // クエリ数不正\r
+               return false;\r
+       }\r
+\r
+       query_data = ((UCHAR *)dns) + sizeof(DNSV4_HEADER);\r
+       query_data_size = size - sizeof(DNSV4_HEADER);\r
+\r
+       // クエリの解釈\r
+       if (ParseDnsQuery(hostname, sizeof(hostname), query_data, query_data_size) == false)\r
+       {\r
+               // 解釈失敗\r
+               return false;\r
+       }\r
+\r
+       // DNS エントリの作成\r
+       nat = CreateNatDns(v, src_ip, src_port, dest_ip, dest_port, transaction_id,\r
+               false, hostname);\r
+\r
+       if (nat == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// NAT DNS 応答パケットの送信\r
+void SendNatDnsResponse(VH *v, NAT_ENTRY *n)\r
+{\r
+       BUF *b;\r
+       UINT dns_header_size;\r
+       DNSV4_HEADER *dns;\r
+       // 引数チェック\r
+       if (n == NULL || v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // データの生成\r
+       b = NewBuf();\r
+\r
+       // Query の追加\r
+       if (n->DnsGetIpFromHost == false)\r
+       {\r
+               BuildDnsQueryPacket(b, n->DnsTargetHostName, false);\r
+       }\r
+       else\r
+       {\r
+               BuildDnsQueryPacket(b, n->DnsTargetHostName, true);\r
+       }\r
+\r
+       // Response の追加\r
+       if (n->DnsOk)\r
+       {\r
+               if (n->DnsGetIpFromHost == false)\r
+               {\r
+                       BuildDnsResponsePacketA(b, &n->DnsResponseIp);\r
+               }\r
+               else\r
+               {\r
+                       BuildDnsResponsePacketPtr(b, n->DnsResponseHostName);\r
+               }\r
+       }\r
+\r
+       // DNS ヘッダの生成\r
+       dns_header_size = sizeof(DNSV4_HEADER) + b->Size;\r
+\r
+       dns = ZeroMalloc(dns_header_size);\r
+       dns->TransactionId = Endian16((USHORT)n->DnsTransactionId);\r
+\r
+       // 応答フラグの生成\r
+       if (n->DnsOk)\r
+       {\r
+               dns->Flag1 = 0x85;\r
+               dns->Flag2 = 0x80;\r
+       }\r
+       else\r
+       {\r
+               dns->Flag1 = 0x85;\r
+               dns->Flag2 = 0x83;\r
+       }\r
+\r
+       dns->NumQuery = Endian16(1);\r
+       dns->AnswerRRs = Endian16(n->DnsOk != false ? 1 : 0);\r
+       dns->AuthorityRRs = 0;\r
+       dns->AdditionalRRs = 0;\r
+\r
+       // データのコピー\r
+       Copy(((UCHAR *)dns) + sizeof(DNSV4_HEADER), b->Buf, b->Size);\r
+\r
+       // このパケットを送信\r
+       SendUdp(v, n->SrcIp, n->SrcPort, n->DestIp, n->DestPort, dns, dns_header_size);\r
+\r
+       // メモリ解放\r
+       Free(dns);\r
+       FreeBuf(b);\r
+}\r
+\r
+// DNS 応答パケット (ホスト名) の生成\r
+void BuildDnsResponsePacketPtr(BUF *b, char *hostname)\r
+{\r
+       USHORT magic;\r
+       USHORT type, clas;\r
+       UINT ttl;\r
+       USHORT len;\r
+       BUF *c;\r
+       // 引数チェック\r
+       if (b == NULL || hostname == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       magic = Endian16(0xc00c);\r
+       type = Endian16(0x000c);\r
+       clas = Endian16(0x0001);\r
+       ttl = Endian32(NAT_DNS_RESPONSE_TTL);\r
+\r
+       c = BuildDnsHostName(hostname);\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+       len = Endian16((USHORT)c->Size);\r
+\r
+       WriteBuf(b, &magic, 2);\r
+       WriteBuf(b, &type, 2);\r
+       WriteBuf(b, &clas, 2);\r
+       WriteBuf(b, &ttl, 4);\r
+       WriteBuf(b, &len, 2);\r
+       WriteBuf(b, c->Buf, c->Size);\r
+       FreeBuf(c);\r
+}\r
+\r
+// DNS 応答パケット (ホスト IP アドレス) の生成\r
+void BuildDnsResponsePacketA(BUF *b, IP *ip)\r
+{\r
+       UINT ip_addr;\r
+       USHORT magic;\r
+       USHORT type, clas;\r
+       UINT ttl;\r
+       USHORT len;\r
+       // 引数チェック\r
+       if (b == NULL || ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ip_addr = IPToUINT(ip);\r
+       magic = Endian16(0xc00c);\r
+       type = Endian16(0x0001);\r
+       clas = Endian16(0x0001);\r
+       ttl = Endian32(NAT_DNS_RESPONSE_TTL);\r
+       len = Endian16((USHORT)sizeof(ttl));\r
+\r
+       WriteBuf(b, &magic, sizeof(magic));\r
+       WriteBuf(b, &type, sizeof(type));\r
+       WriteBuf(b, &clas, sizeof(clas));\r
+       WriteBuf(b, &ttl, sizeof(ttl));\r
+       WriteBuf(b, &len, sizeof(len));\r
+       WriteBuf(b, &ip_addr, sizeof(ip_addr));\r
+}\r
+\r
+// DNS クエリデータパケットの生成\r
+void BuildDnsQueryPacket(BUF *b, char *hostname, bool ptr)\r
+{\r
+       USHORT val;\r
+       BUF *c;\r
+       // 引数チェック\r
+       if (b == NULL || hostname == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ホスト名をバッファに変換\r
+       c = BuildDnsHostName(hostname);\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       WriteBuf(b, c->Buf, c->Size);\r
+       FreeBuf(c);\r
+\r
+       // 種類とクラス\r
+       if (ptr == false)\r
+       {\r
+               val = Endian16(0x0001);\r
+       }\r
+       else\r
+       {\r
+               val = Endian16(0x000c);\r
+       }\r
+       WriteBuf(b, &val, 2);\r
+\r
+       val = Endian16(0x0001);\r
+       WriteBuf(b, &val, 2);\r
+}\r
+\r
+// DNS ホスト名バッファの生成\r
+BUF *BuildDnsHostName(char *hostname)\r
+{\r
+       UINT i;\r
+       UCHAR size;\r
+       TOKEN_LIST *token;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (hostname == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // ホスト名をトークンに分割\r
+       token = ParseToken(hostname, ".");\r
+       if (token == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+\r
+       // ホスト文字列を追加\r
+       for (i = 0;i < token->NumTokens;i++)\r
+       {\r
+               size = (UCHAR)StrLen(token->Token[i]);\r
+               WriteBuf(b, &size, 1);\r
+               WriteBuf(b, token->Token[i], size);\r
+       }\r
+\r
+       // NULL 文字\r
+       size = 0;\r
+       WriteBuf(b, &size, 1);\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       FreeToken(token);\r
+\r
+       return b;\r
+}\r
+\r
+// NAT DNS エントリの処理\r
+void PollingNatDns(VH *v, NAT_ENTRY *n)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (n->DnsFinished)\r
+       {\r
+               if (n->DnsPollingFlag == false)\r
+               {\r
+                       n->DnsPollingFlag = true;\r
+                       // 処理が完了した\r
+                       SendNatDnsResponse(v, n);\r
+\r
+                       // 終了処理\r
+                       n->DisconnectNow = true;\r
+               }\r
+       }\r
+}\r
+\r
+// NAT DNS エントリの作成\r
+NAT_ENTRY *CreateNatDns(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port,\r
+                                 UINT transaction_id, bool dns_get_ip_from_host, char *dns_target_host_name)\r
+{\r
+       NAT_ENTRY *n;\r
+       // 引数チェック\r
+       if (v == NULL || dns_target_host_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (CanCreateNewNatEntry(v) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       n = ZeroMalloc(sizeof(NAT_ENTRY));\r
+       n->Id = Inc(v->Counter);\r
+       n->v = v;\r
+       n->lock = NewLock();\r
+       n->Protocol = NAT_DNS;\r
+       n->SrcIp = src_ip;\r
+       n->SrcPort = src_port;\r
+       n->DestIp = dest_ip;\r
+       n->DestPort = dest_port;\r
+       n->DnsTransactionId = transaction_id;\r
+       n->CreatedTime = n->LastCommTime = v->Now;\r
+       n->DisconnectNow = false;\r
+\r
+       n->DnsGetIpFromHost = false;\r
+       n->DnsTargetHostName = CopyStr(dns_target_host_name);\r
+\r
+       Add(v->NatTable, n);\r
+\r
+#if    1\r
+       {\r
+               IP ip1, ip2;\r
+               char s1[MAX_SIZE], s2[MAX_SIZE];\r
+               UINTToIP(&ip1, src_ip);\r
+               UINTToIP(&ip2, dest_ip);\r
+               IPToStr(s1, 0, &ip1);\r
+               IPToStr(s2, 0, &ip2);\r
+               Debug("NAT_ENTRY: CreateNatDns %s %u -> %s %u\n", s1, src_port, s2, dest_port);\r
+       }\r
+#endif\r
+\r
+\r
+       return n;\r
+}\r
+\r
+// 次のバイトを取得\r
+UCHAR GetNextByte(BUF *b)\r
+{\r
+       UCHAR c = 0;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (ReadBuf(b, &c, 1) != 1)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return c;\r
+}\r
+\r
+// DNS クエリの解釈\r
+bool ParseDnsQuery(char *name, UINT name_size, void *data, UINT data_size)\r
+{\r
+       BUF *b;\r
+       char tmp[257];\r
+       bool ok = true;\r
+       USHORT val;\r
+       // 引数チェック\r
+       if (name == NULL || data == NULL || data_size == 0)\r
+       {\r
+               return false;\r
+       }\r
+       StrCpy(name, name_size, "");\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, data, data_size);\r
+       SeekBuf(b, 0, 0);\r
+\r
+       while (true)\r
+       {\r
+               UINT next_len = (UINT)GetNextByte(b);\r
+               if (next_len > 0)\r
+               {\r
+                       // 指定した文字だけ読む\r
+                       Zero(tmp, sizeof(tmp));\r
+                       if (ReadBuf(b, tmp, next_len) != next_len)\r
+                       {\r
+                               ok = false;\r
+                               break;\r
+                       }\r
+                       // 追記\r
+                       if (StrLen(name) != 0)\r
+                       {\r
+                               StrCat(name, name_size, ".");\r
+                       }\r
+                       StrCat(name, name_size, tmp);\r
+               }\r
+               else\r
+               {\r
+                       // すべて読み終えた\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (ReadBuf(b, &val, sizeof(val)) != sizeof(val))\r
+       {\r
+               ok = false;\r
+       }\r
+       else\r
+       {\r
+               if (Endian16(val) != 0x01 && Endian16(val) != 0x0c)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       if (ReadBuf(b, &val, sizeof(val)) != sizeof(val))\r
+       {\r
+               ok = false;\r
+       }\r
+       else\r
+       {\r
+               if (Endian16(val) != 0x01)\r
+               {\r
+                       ok = false;\r
+               }\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       if (ok == false || StrLen(name) == 0)\r
+       {\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               return true;\r
+       }\r
+}\r
+\r
+// DNS プロキシとして動作する\r
+void DnsProxy(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, void *data, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL || size == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // まず DNS クエリを解釈することができるかどうか試してみる\r
+       //if (ParseDnsPacket(v, src_ip, src_port, dest_ip, dest_port, data, size) == false)\r
+       {\r
+               // うまくいかない場合は要求をそのまま投げる\r
+               UdpRecvForInternet(v, src_ip, src_port, dest_ip, dest_port, data, size, true);\r
+       }\r
+}\r
+\r
+// 仮想ホストへの UDP パケットの処理\r
+void UdpRecvForMe(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, void *data, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (data == NULL || v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (dest_port == NAT_DNS_PROXY_PORT)\r
+       {\r
+               // DNS プロキシ起動\r
+               DnsProxy(v, src_ip, src_port, dest_ip, dest_port, data, size);\r
+       }\r
+}\r
+\r
+// ブロードキャスト UDP パケットの処理\r
+void UdpRecvForBroadcast(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, void *data, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (data == NULL || v == NULL)\r
+       {\r
+               return;\r
+       }\r
+}\r
+\r
+// UDP パケットを受信した\r
+void VirtualUdpReceived(VH *v, UINT src_ip, UINT dest_ip, void *data, UINT size, bool mac_broadcast)\r
+{\r
+       UDP_HEADER *udp;\r
+       UINT packet_length;\r
+       void *buf;\r
+       UINT buf_size;\r
+       UINT src_port, dest_port;\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ヘッダのチェック\r
+       udp = (UDP_HEADER *)data;\r
+       if (size < UDP_HEADER_SIZE)\r
+       {\r
+               return;\r
+       }\r
+       packet_length = Endian16(udp->PacketLength);\r
+       if (packet_length != size)\r
+       {\r
+               return;\r
+       }\r
+       buf = ((UCHAR *)data) + UDP_HEADER_SIZE;\r
+       buf_size = size - UDP_HEADER_SIZE;\r
+       src_port = Endian16(udp->SrcPort);\r
+       dest_port = Endian16(udp->DstPort);\r
+       // ポート番号をチェック\r
+       if (dest_port == 0)\r
+       {\r
+               // ポート番号が不正\r
+               return;\r
+       }\r
+\r
+       // 自分宛のパケットまたはブロードキャストパケットかどうか判別する\r
+       if (dest_ip == v->HostIP)\r
+       {\r
+               // 自分宛のパケットが届いた\r
+               UdpRecvForMe(v, src_ip, src_port, dest_ip, dest_port, buf, buf_size);\r
+       }\r
+       else if (mac_broadcast || dest_ip == 0xffffffff || dest_ip == GetBroadcastAddress(v->HostIP, v->HostMask))\r
+       {\r
+               // ブロードキャストパケットが届いた\r
+               UdpRecvForBroadcast(v, src_ip, src_port, dest_ip, dest_port, buf, buf_size);\r
+       }\r
+       else if (IsInNetwork(dest_ip, v->HostIP, v->HostMask) == false)\r
+       {\r
+               // ローカルアドレス以外 (つまりインターネット上) へのパケットが届いた\r
+               UdpRecvForInternet(v, src_ip, src_port, dest_ip, dest_port, buf, buf_size, false);\r
+       }\r
+       else\r
+       {\r
+               // ローカルアドレスが届いた。無視\r
+       }\r
+}\r
+\r
+// 指定した IP アドレスの属するサブネットのネットワークアドレスを求める\r
+UINT GetNetworkAddress(UINT addr, UINT mask)\r
+{\r
+       return (addr & mask);\r
+}\r
+\r
+// 指定した IP アドレスの属するサブネットのブロードキャストアドレスを求める\r
+UINT GetBroadcastAddress(UINT addr, UINT mask)\r
+{\r
+       return ((addr & mask) | (~mask));\r
+}\r
+\r
+// 指定した IP アドレスが別の指定したアドレスとサブネットマスクによって表現される\r
+// サブネットワークに所属しているかどうか判別する\r
+bool IsInNetwork(UINT uni_addr, UINT network_addr, UINT mask)\r
+{\r
+       if (GetNetworkAddress(uni_addr, mask) == GetNetworkAddress(network_addr, mask))\r
+       {\r
+               return true;\r
+       }\r
+       return false;\r
+}\r
+\r
+// UDP パケットの送信\r
+void SendUdp(VH *v, UINT dest_ip, UINT dest_port, UINT src_ip, UINT src_port, void *data, UINT size)\r
+{\r
+       UDPV4_PSEUDO_HEADER *vh;\r
+       UDP_HEADER *udp;\r
+       UINT udp_packet_length = UDP_HEADER_SIZE + size;\r
+       USHORT checksum;\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (udp_packet_length > 65536)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 仮想ヘッダを生成\r
+       vh = Malloc(sizeof(UDPV4_PSEUDO_HEADER) + size);\r
+       udp = (UDP_HEADER *)(((UCHAR *)vh) + 12);\r
+\r
+       vh->SrcIP = src_ip;\r
+       vh->DstIP = dest_ip;\r
+       vh->Reserved = 0;\r
+       vh->Protocol = IP_PROTO_UDP;\r
+       vh->PacketLength1 = Endian16((USHORT)udp_packet_length);\r
+       udp->SrcPort = Endian16((USHORT)src_port);\r
+       udp->DstPort = Endian16((USHORT)dest_port);\r
+       udp->PacketLength = Endian16((USHORT)udp_packet_length);\r
+       udp->Checksum = 0;\r
+\r
+       // データをコピー\r
+       Copy(((UCHAR *)udp) + UDP_HEADER_SIZE, data, size);\r
+\r
+       // チェックサムを計算\r
+       checksum = IpChecksum(vh, udp_packet_length + 12);\r
+       if (checksum == 0x0000)\r
+       {\r
+               checksum = 0xffff;\r
+       }\r
+       udp->Checksum = checksum;\r
+\r
+       // パケットを送信\r
+       SendIp(v, dest_ip, src_ip, IP_PROTO_UDP, udp, udp_packet_length);\r
+\r
+       // メモリ解放\r
+       Free(vh);\r
+}\r
+\r
+// IP 結合オブジェクトのポーリング\r
+void PollingIpCombine(VH *v)\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 古い結合オブジェクトを破棄する\r
+       o = NULL;\r
+       for (i = 0;i < LIST_NUM(v->IpCombine);i++)\r
+       {\r
+               IP_COMBINE *c = LIST_DATA(v->IpCombine, i);\r
+\r
+               if (c->Expire < v->Now)\r
+               {\r
+                       if (o == NULL)\r
+                       {\r
+                               o = NewListFast(NULL);\r
+                       }\r
+                       Add(o, c);\r
+               }\r
+       }\r
+\r
+       if (o != NULL)\r
+       {\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       IP_COMBINE *c = LIST_DATA(o, i);\r
+\r
+                       // リストから削除\r
+                       Delete(v->IpCombine, c);\r
+\r
+                       // メモリ解放\r
+                       FreeIpCombine(v, c);\r
+               }\r
+               ReleaseList(o);\r
+       }\r
+}\r
+\r
+// ICMP パケットを送信する\r
+void VirtualIcmpSend(VH *v, UINT src_ip, UINT dst_ip, void *data, UINT size)\r
+{\r
+       ICMP_HEADER *icmp;\r
+       void *data_buf;\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ヘッダ組み立て\r
+       icmp = ZeroMalloc(sizeof(ICMP_HEADER) + size);\r
+       // データコピー\r
+       data_buf = ((UCHAR *)icmp) + sizeof(ICMP_HEADER);\r
+       Copy(data_buf, data, size);\r
+       // その他\r
+       icmp->Checksum = 0;\r
+       icmp->Code = 0;\r
+       icmp->Type = ICMP_TYPE_ECHO_RESPONSE;\r
+       // チェックサム\r
+       icmp->Checksum = IpChecksum(icmp, sizeof(ICMP_HEADER) + size);\r
+\r
+       // IP パケット送信\r
+       SendIp(v, dst_ip, src_ip, IP_PROTO_ICMPV4, icmp, sizeof(ICMP_HEADER) + size);\r
+\r
+       // メモリ解放\r
+       Free(icmp);\r
+}\r
+\r
+// ICMP Echo Response パケットを送信する\r
+void VirtualIcmpEchoSendResponse(VH *v, UINT src_ip, UINT dst_ip, USHORT id, USHORT seq_no, void *data, UINT size)\r
+{\r
+       ICMP_ECHO *e;\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ヘッダ組み立て\r
+       e = ZeroMalloc(sizeof(ICMP_ECHO) + size);\r
+       e->Identifier = Endian16(id);\r
+       e->SeqNo = Endian16(seq_no);\r
+\r
+       // データコピー\r
+       Copy(((UCHAR *)e) + sizeof(ICMP_ECHO), data, size);\r
+\r
+       // ICMP 送信\r
+       VirtualIcmpSend(v, src_ip, dst_ip, e, sizeof(ICMP_ECHO) + size);\r
+\r
+       // メモリ解放\r
+       Free(e);\r
+}\r
+\r
+// ICMP Echo Request パケットを受信した\r
+void VirtualIcmpEchoRequestReceived(VH *v, UINT src_ip, UINT dst_ip, void *data, UINT size)\r
+{\r
+       ICMP_ECHO *echo;\r
+       UINT data_size;\r
+       void *data_buf;\r
+       USHORT id, seq_no;\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       echo = (ICMP_ECHO *)data;\r
+\r
+       // エコーサイズチェック\r
+       if (size < sizeof(ICMP_ECHO))\r
+       {\r
+               // データが足らない\r
+               return;\r
+       }\r
+\r
+       id = Endian16(echo->Identifier);\r
+       seq_no = Endian16(echo->SeqNo);\r
+\r
+       // データサイズ\r
+       data_size = size - sizeof(ICMP_ECHO);\r
+\r
+       // データ本体\r
+       data_buf = ((UCHAR *)data) + sizeof(ICMP_ECHO);\r
+\r
+       // ICMP Echo Response を返す\r
+       VirtualIcmpEchoSendResponse(v, dst_ip, src_ip, id, seq_no, data_buf, data_size);\r
+}\r
+\r
+// ICMP パケットを受信した\r
+void VirtualIcmpReceived(VH *v, UINT src_ip, UINT dst_ip, void *data, UINT size)\r
+{\r
+       ICMP_HEADER *icmp;\r
+       UINT msg_size;\r
+       USHORT checksum_calc, checksum_original;\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // サイズチェック\r
+       if (size < sizeof(ICMP_HEADER))\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ICMP ヘッダ\r
+       icmp = (ICMP_HEADER *)data;\r
+\r
+       // ICMP メッセージサイズの取得\r
+       msg_size = size - sizeof(ICMP_HEADER);\r
+\r
+       // ICMP ヘッダのチェックサムをチェックする\r
+       checksum_original = icmp->Checksum;\r
+       icmp->Checksum = 0;\r
+       checksum_calc = IpChecksum(data, size);\r
+       icmp->Checksum = checksum_original;\r
+\r
+       if (checksum_calc != checksum_original)\r
+       {\r
+               // チェックサムが不正\r
+               Debug("ICMP CheckSum Failed.\n");\r
+               return;\r
+       }\r
+\r
+       // オペコードによって識別\r
+       switch (icmp->Type)\r
+       {\r
+       case ICMP_TYPE_ECHO_REQUEST:    // ICMP Echo 要求\r
+               VirtualIcmpEchoRequestReceived(v, src_ip, dst_ip, ((UCHAR *)data) + sizeof(ICMP_HEADER), msg_size);\r
+               break;\r
+\r
+       case ICMP_TYPE_ECHO_RESPONSE:   // ICMP Echo 応答\r
+               // 何もしない\r
+               break;\r
+       }\r
+}\r
+\r
+// IP パケットを受信した\r
+void IpReceived(VH *v, UINT src_ip, UINT dest_ip, UINT protocol, void *data, UINT size, bool mac_broadcast)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // サポートされている上位プロトコルにデータを渡す\r
+       switch (protocol)\r
+       {\r
+       case IP_PROTO_ICMPV4:   // ICMPv4\r
+               VirtualIcmpReceived(v, src_ip, dest_ip, data, size);\r
+               break;\r
+\r
+       case IP_PROTO_TCP:              // TCP\r
+               if (mac_broadcast == false)\r
+               {\r
+                       VirtualTcpReceived(v, src_ip, dest_ip, data, size);\r
+               }\r
+               break;\r
+\r
+       case IP_PROTO_UDP:              // UDP\r
+               VirtualUdpReceived(v, src_ip, dest_ip, data, size, mac_broadcast);\r
+               break;\r
+       }\r
+}\r
+\r
+// IP ヘッダのチェックサムを確認する\r
+bool IpCheckChecksum(IPV4_HEADER *ip)\r
+{\r
+       UINT header_size;\r
+       USHORT checksum_original, checksum_calc;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       header_size = IPV4_GET_HEADER_LEN(ip) * 4;\r
+       checksum_original = ip->Checksum;\r
+       ip->Checksum = 0;\r
+       checksum_calc = IpChecksum(ip, header_size);\r
+       ip->Checksum = checksum_original;\r
+\r
+       if (checksum_original == checksum_calc)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// チェックサムを計算する\r
+USHORT IpChecksum(void *buf, UINT size)\r
+{\r
+       int sum = 0;\r
+       USHORT *addr = (USHORT *)buf;\r
+       int len = (int)size;\r
+       USHORT *w = addr;\r
+       int nleft = len;\r
+       USHORT answer = 0;\r
+\r
+       while (nleft > 1)\r
+       {\r
+               sum += *w++;\r
+               nleft -= 2;\r
+       }\r
+\r
+       if (nleft == 1)\r
+       {\r
+               *(UCHAR *)(&answer) = *(UCHAR *)w;\r
+               sum += answer;\r
+       }\r
+\r
+       sum = (sum >> 16) + (sum & 0xffff);\r
+       sum += (sum >> 16);\r
+\r
+       answer = ~sum;\r
+       \r
+       return answer;\r
+}\r
+\r
+// IP 結合オブジェクトに新しく受信した IP パケットを結合する\r
+void CombineIp(VH *v, IP_COMBINE *c, UINT offset, void *data, UINT size, bool last_packet)\r
+{\r
+       UINT i;\r
+       IP_PART *p;\r
+       UINT need_size;\r
+       UINT data_size_delta;\r
+       // 引数チェック\r
+       if (c == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // オフセットとサイズをチェック\r
+       if ((offset + size) > 65535)\r
+       {\r
+               // 64Kbytes を超えるパケットは処理しない\r
+               return;\r
+       }\r
+\r
+       if (last_packet == false && c->Size != 0)\r
+       {\r
+               if ((offset + size) > c->Size)\r
+               {\r
+                       // パケットサイズより大きいパケットは処理しない\r
+                       return;\r
+               }\r
+       }\r
+\r
+       need_size = offset + size;\r
+       data_size_delta = c->DataReserved;\r
+       // バッファが不足している場合は十分確保する\r
+       while (c->DataReserved < need_size)\r
+       {\r
+               c->DataReserved = c->DataReserved * 4;\r
+               c->Data = ReAlloc(c->Data, c->DataReserved);\r
+       }\r
+       data_size_delta = c->DataReserved - data_size_delta;\r
+       v->CurrentIpQuota += data_size_delta;\r
+\r
+       // データをバッファに上書きする\r
+       Copy(((UCHAR *)c->Data) + offset, data, size);\r
+\r
+       if (last_packet)\r
+       {\r
+               // No More Flagment パケットが届いた場合、このデータグラムのサイズが確定する\r
+               c->Size = offset + size;\r
+       }\r
+\r
+       // オフセットとサイズによって表現されている領域と既存の受信済みリストの\r
+       // オフセットとサイズによって表現されている領域との間の重複をチェックする\r
+       for (i = 0;i < LIST_NUM(c->IpParts);i++)\r
+       {\r
+               UINT moving_size;\r
+               IP_PART *p = LIST_DATA(c->IpParts, i);\r
+\r
+               // 先頭領域と既存領域との重複をチェック\r
+               if ((p->Offset <= offset) && ((p->Offset + p->Size) > offset))\r
+               {\r
+                       // このパケットと既存パケットとの間で先頭部分に重複が見つかったので\r
+                       // このパケットのオフセットを後方に圧縮する\r
+\r
+                       if ((offset + size) <= (p->Offset + p->Size))\r
+                       {\r
+                               // このパケットは既存のパケットの中に埋もれている\r
+                               size = 0;\r
+                       }\r
+                       else\r
+                       {\r
+                               // 後方領域は重なっていない\r
+                               moving_size = p->Offset + p->Size - offset;\r
+                               offset += moving_size;\r
+                               size -= moving_size;\r
+                       }\r
+               }\r
+               if ((p->Offset < (offset + size)) && ((p->Offset + p->Size) >= (offset + size)))\r
+               {\r
+                       // このパケットと既存パケットとの間で後方部分に重複が見つかったので\r
+                       // このパケットのサイズを前方に圧縮する\r
+\r
+                       moving_size = p->Offset + p->Size - offset - size;\r
+                       size -= moving_size;\r
+               }\r
+\r
+               if ((p->Offset >= offset) && ((p->Offset + p->Size) <= (offset + size)))\r
+               {\r
+                       // このパケットが既存のパケットを完全に覆いかぶさるように上書きされた\r
+                       p->Size = 0;\r
+               }\r
+       }\r
+\r
+       if (size != 0)\r
+       {\r
+               // このパケットを登録する\r
+               p = ZeroMalloc(sizeof(IP_PART));\r
+\r
+               p->Offset = offset;\r
+               p->Size = size;\r
+\r
+               Add(c->IpParts, p);\r
+       }\r
+\r
+       if (c->Size != 0)\r
+       {\r
+               // すでに受信したデータ部分リストの合計サイズを取得する\r
+               UINT total_size = 0;\r
+               UINT i;\r
+\r
+               for (i = 0;i < LIST_NUM(c->IpParts);i++)\r
+               {\r
+                       IP_PART *p = LIST_DATA(c->IpParts, i);\r
+\r
+                       total_size += p->Size;\r
+               }\r
+\r
+               if (total_size == c->Size)\r
+               {\r
+                       // IP パケットをすべて受信した\r
+                       IpReceived(v, c->SrcIP, c->DestIP, c->Protocol, c->Data, c->Size, c->MacBroadcast);\r
+\r
+                       // 結合オブジェクトの解放\r
+                       FreeIpCombine(v, c);\r
+\r
+                       // 結合オブジェクトをリストから削除\r
+                       Delete(v->IpCombine, c);\r
+               }\r
+       }\r
+}\r
+\r
+// IP 結合オブジェクトの解放\r
+void FreeIpCombine(VH *v, IP_COMBINE *c)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // データ解放\r
+       v->CurrentIpQuota -= c->DataReserved;\r
+       Free(c->Data);\r
+\r
+       // 部分リスト解放\r
+       for (i = 0;i < LIST_NUM(c->IpParts);i++)\r
+       {\r
+               IP_PART *p = LIST_DATA(c->IpParts, i);\r
+\r
+               Free(p);\r
+       }\r
+\r
+       ReleaseList(c->IpParts);\r
+       Free(c);\r
+}\r
+\r
+// IP 結合リストを検索\r
+IP_COMBINE *SearchIpCombine(VH *v, UINT src_ip, UINT dest_ip, USHORT id, UCHAR protocol)\r
+{\r
+       IP_COMBINE *c, t;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t.DestIP = dest_ip;\r
+       t.SrcIP = src_ip;\r
+       t.Id = id;\r
+       t.Protocol = protocol;\r
+\r
+       c = Search(v->IpCombine, &t);\r
+\r
+       return c;\r
+}\r
+\r
+// IP 結合リストに新しいオブジェクトを作成して挿入\r
+IP_COMBINE *InsertIpCombine(VH *v, UINT src_ip, UINT dest_ip, USHORT id, UCHAR protocol, bool mac_broadcast)\r
+{\r
+       IP_COMBINE *c;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // クォータを調べる\r
+       if ((v->CurrentIpQuota + IP_COMBINE_INITIAL_BUF_SIZE) > IP_COMBINE_WAIT_QUEUE_SIZE_QUOTA)\r
+       {\r
+               // これ以上 IP パケットを格納できない\r
+               return NULL;\r
+       }\r
+\r
+       c = ZeroMalloc(sizeof(IP_COMBINE));\r
+       c->DestIP = dest_ip;\r
+       c->SrcIP = src_ip;\r
+       c->Id = id;\r
+       c->Expire = v->Now + (UINT64)IP_COMBINE_TIMEOUT;\r
+       c->Size = 0;\r
+       c->IpParts = NewList(NULL);\r
+       c->Protocol = protocol;\r
+       c->MacBroadcast = mac_broadcast;\r
+\r
+       // メモリを確保\r
+       c->DataReserved = IP_COMBINE_INITIAL_BUF_SIZE;\r
+       c->Data = Malloc(c->DataReserved);\r
+       v->CurrentIpQuota += c->DataReserved;\r
+\r
+       Insert(v->IpCombine, c);\r
+\r
+       return c;\r
+}\r
+\r
+// IP 結合リストの初期化\r
+void InitIpCombineList(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v->IpCombine = NewList(CompareIpCombine);\r
+}\r
+\r
+// IP 結合リストの解放\r
+void FreeIpCombineList(VH *v)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(v->IpCombine);i++)\r
+       {\r
+               IP_COMBINE *c = LIST_DATA(v->IpCombine, i);\r
+\r
+               FreeIpCombine(v, c);\r
+       }\r
+\r
+       ReleaseList(v->IpCombine);\r
+}\r
+\r
+// IP 結合リストの比較\r
+int CompareIpCombine(void *p1, void *p2)\r
+{\r
+       IP_COMBINE *c1, *c2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       c1 = *(IP_COMBINE **)p1;\r
+       c2 = *(IP_COMBINE **)p2;\r
+       if (c1 == NULL || c2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (c1->Id > c2->Id)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (c1->Id < c2->Id)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (c1->DestIP > c2->DestIP)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (c1->DestIP < c2->DestIP)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (c1->SrcIP > c2->SrcIP)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (c1->SrcIP < c2->SrcIP)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (c1->Protocol > c2->Protocol)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (c1->Protocol < c2->Protocol)\r
+       {\r
+               return -1;\r
+       }\r
+       return 0;\r
+}\r
+\r
+// IP パケットを受信した\r
+void VirtualIpReceived(VH *v, PKT *packet)\r
+{\r
+       IPV4_HEADER *ip;\r
+       void *data;\r
+       UINT data_size_recved;\r
+       UINT size;\r
+       UINT ipv4_header_size;\r
+       bool last_packet;\r
+       // 引数チェック\r
+       if (v == NULL || packet == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ip = packet->L3.IPv4Header;\r
+\r
+       // IPv4 ヘッダのサイズを取得する\r
+       ipv4_header_size = IPV4_GET_HEADER_LEN(packet->L3.IPv4Header) * 4;\r
+\r
+       // IPv4 ヘッダのチェックサムを計算する\r
+       if (IpCheckChecksum(ip) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // データへのポインタを取得する\r
+       data = ((UCHAR *)packet->L3.PointerL3) + ipv4_header_size;\r
+\r
+       // ARP テーブルに登録しておく\r
+       ArpIpWasKnown(v, packet->L3.IPv4Header->SrcIP, packet->MacAddressSrc);\r
+\r
+       // データサイズを取得する\r
+       size = Endian16(ip->TotalLength);\r
+       if (size <= ipv4_header_size)\r
+       {\r
+               // データが無い\r
+               return;\r
+       }\r
+       size -= ipv4_header_size;\r
+\r
+       // 実際に受信したデータサイズを取得する\r
+       data_size_recved = packet->PacketSize - (ipv4_header_size + MAC_HEADER_SIZE);\r
+       if (data_size_recved < size)\r
+       {\r
+               // データが足りない (途中で欠落しているかも知れない)\r
+               return;\r
+       }\r
+\r
+       if (IPV4_GET_OFFSET(ip) == 0 && (IPV4_GET_FLAGS(ip) & 0x01) == 0)\r
+       {\r
+               // このパケットは分割されていないので直ちに上位層に渡すことができる\r
+               IpReceived(v, ip->SrcIP, ip->DstIP, ip->Protocol, data, size, packet->BroadcastPacket);\r
+       }\r
+       else\r
+       {\r
+               // このパケットは分割されているので結合する必要がある\r
+\r
+               UINT offset = IPV4_GET_OFFSET(ip) * 8;\r
+               IP_COMBINE *c = SearchIpCombine(v, ip->SrcIP, ip->DstIP, Endian16(ip->Identification), ip->Protocol);\r
+\r
+               last_packet = ((IPV4_GET_FLAGS(ip) & 0x01) == 0 ? true : false);\r
+\r
+               if (c != NULL)\r
+               {\r
+                       // 2 個目移行のパケットである\r
+                       CombineIp(v, c, offset, data, size, last_packet);\r
+               }\r
+               else\r
+               {\r
+                       // 最初のパケットなので結合オブジェクトを作成する\r
+                       c = InsertIpCombine(\r
+                               v, ip->SrcIP, ip->DstIP, Endian16(ip->Identification), ip->Protocol, packet->BroadcastPacket);\r
+                       if (c != NULL)\r
+                       {\r
+                               CombineIp(v, c, offset, data, size, last_packet);\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// 待機している IP パケットのうち指定した IP アドレスからのものを送信する\r
+void SendWaitingIp(VH *v, UCHAR *mac, UINT dest_ip)\r
+{\r
+       UINT i;\r
+       LIST *o = NULL;\r
+       // 引数チェック\r
+       if (v == NULL || mac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 対象リストを取得する\r
+       for (i = 0;i < LIST_NUM(v->IpWaitTable);i++)\r
+       {\r
+               IP_WAIT *w = LIST_DATA(v->IpWaitTable, i);\r
+\r
+               if (w->DestIP == dest_ip)\r
+               {\r
+                       if (o == NULL)\r
+                       {\r
+                               o = NewListFast(NULL);\r
+                       }\r
+                       Add(o, w);\r
+               }\r
+       }\r
+\r
+       // 対象となったパケットを一気に送信する\r
+       if (o != NULL)\r
+       {\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       IP_WAIT *w = LIST_DATA(o, i);\r
+\r
+                       // 送信処理\r
+                       VirtualIpSend(v, mac, w->Data, w->Size);\r
+\r
+                       // リストから削除\r
+                       Delete(v->IpWaitTable, w);\r
+\r
+                       // メモリ解放\r
+                       Free(w->Data);\r
+                       Free(w);\r
+               }\r
+\r
+               ReleaseList(o);\r
+       }\r
+}\r
+\r
+// 古い IP 待ちテーブルを削除する\r
+void DeleteOldIpWaitTable(VH *v)\r
+{\r
+       UINT i;\r
+       LIST *o = NULL;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 削除対象リストを取得する\r
+       for (i = 0;i < LIST_NUM(v->IpWaitTable);i++)\r
+       {\r
+               IP_WAIT *w = LIST_DATA(v->IpWaitTable, i);\r
+\r
+               if (w->Expire < v->Now)\r
+               {\r
+                       if (o == NULL)\r
+                       {\r
+                               o = NewListFast(NULL);\r
+                       }\r
+                       Add(o, w);\r
+               }\r
+       }\r
+\r
+       // 一気に削除する\r
+       if (o != NULL)\r
+       {\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       IP_WAIT *w = LIST_DATA(o, i);\r
+\r
+                       // リストから削除\r
+                       Delete(v->IpWaitTable, w);\r
+\r
+                       // メモリ解放\r
+                       Free(w->Data);\r
+                       Free(w);\r
+               }\r
+               ReleaseList(o);\r
+       }\r
+}\r
+\r
+// IP 待ちテーブルのポーリング\r
+void PollingIpWaitTable(VH *v)\r
+{\r
+       // 古いテーブルの削除\r
+       DeleteOldIpWaitTable(v);\r
+}\r
+\r
+// IP 待ちテーブルに IP パケットを挿入する\r
+void InsertIpWaitTable(VH *v, UINT dest_ip, UINT src_ip, void *data, UINT size)\r
+{\r
+       IP_WAIT *w;\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL || size == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       w = ZeroMalloc(sizeof(IP_WAIT));\r
+       w->Data = data;\r
+       w->Size = size;\r
+       w->SrcIP = src_ip;\r
+       w->DestIP = dest_ip;\r
+       w->Expire = v->Now + (UINT64)IP_WAIT_FOR_ARP_TIMEOUT;\r
+\r
+       Add(v->IpWaitTable, w);\r
+}\r
+\r
+// IP 待ちテーブルを初期化する\r
+void InitIpWaitTable(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v->IpWaitTable = NewList(NULL);\r
+}\r
+\r
+// IP 待ちテーブルを解放する\r
+void FreeIpWaitTable(VH *v)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(v->IpWaitTable);i++)\r
+       {\r
+               IP_WAIT *w = LIST_DATA(v->IpWaitTable, i);\r
+\r
+               Free(w->Data);\r
+               Free(w);\r
+       }\r
+\r
+       ReleaseList(v->IpWaitTable);\r
+}\r
+\r
+// ARP Response が到着するなどして IP アドレスに対する MAC アドレスが判明した\r
+void ArpIpWasKnown(VH *v, UINT ip, UCHAR *mac)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || mac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ARP 待ち行列にこの IP アドレスに対する問い合わせがあった場合は削除する\r
+       DeleteArpWaitTable(v, ip);\r
+\r
+       // ARP テーブルに登録または更新する\r
+       InsertArpTable(v, mac, ip);\r
+\r
+       // IP 待機リストで待機している IP パケットを送信する\r
+       SendWaitingIp(v, mac, ip);\r
+}\r
+\r
+// ARP 待ちリストをチェックし適時 ARP を再発行する\r
+void PollingArpWaitTable(VH *v)\r
+{\r
+       UINT i;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 削除リストの初期化\r
+       o = NULL;\r
+\r
+       // すべての ARP 待ちリストを走査\r
+       for (i = 0;i < LIST_NUM(v->ArpWaitTable);i++)\r
+       {\r
+               ARP_WAIT *w = LIST_DATA(v->ArpWaitTable, i);\r
+\r
+               if (w->GiveupTime < v->Now || (w->GiveupTime - 100 * 1000) > v->Now)\r
+               {\r
+                       // ARP の送信を諦める\r
+                       if (o == NULL)\r
+                       {\r
+                               o = NewListFast(NULL);\r
+                       }\r
+                       Add(o, w);\r
+               }\r
+               else\r
+               {\r
+                       if (w->TimeoutTime < v->Now)\r
+                       {\r
+                               // ARP を再度送信する\r
+                               VirtualArpSendRequest(v, w->IpAddress);\r
+\r
+                               // 次のタイムアウト時刻をセット\r
+                               w->TimeoutTime = v->Now + (UINT64)w->NextTimeoutTimeValue;\r
+                               // 2 回目以降の ARP 送信間隔は増やしていく\r
+                               w->NextTimeoutTimeValue = w->NextTimeoutTimeValue + ARP_REQUEST_TIMEOUT;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // 削除対象の ARP 待ちレコードがある場合は削除する\r
+       if (o != NULL)\r
+       {\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       ARP_WAIT *w = LIST_DATA(o, i);\r
+\r
+                       DeleteArpWaitTable(v, w->IpAddress);\r
+               }\r
+               ReleaseList(o);\r
+       }\r
+}\r
+\r
+// ARP を発行する\r
+void SendArp(VH *v, UINT ip)\r
+{\r
+       ARP_WAIT *w;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // まず ARP 待ちリストに宛先 IP アドレスが登録されているかどうか調べる\r
+       w = SearchArpWaitTable(v, ip);\r
+       if (w != NULL)\r
+       {\r
+               // すでに登録されているので何もしない\r
+               return;\r
+       }\r
+\r
+       // まず ARP パケットを送信する\r
+       VirtualArpSendRequest(v, ip);\r
+\r
+       // ARP 待ちリストに登録する\r
+       w = ZeroMalloc(sizeof(ARP_WAIT));\r
+       w->GiveupTime = v->Now + (UINT64)ARP_REQUEST_GIVEUP;\r
+       w->TimeoutTime = v->Now + (UINT64)ARP_REQUEST_TIMEOUT;\r
+       w->NextTimeoutTimeValue = ARP_REQUEST_TIMEOUT;\r
+       w->IpAddress = ip;\r
+\r
+       InsertArpWaitTable(v, w);\r
+}\r
+\r
+// ARP 待ちテーブルの削除\r
+void DeleteArpWaitTable(VH *v, UINT ip)\r
+{\r
+       ARP_WAIT *w;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       w = SearchArpWaitTable(v, ip);\r
+       if (w == NULL)\r
+       {\r
+               return;\r
+       }\r
+       Delete(v->ArpWaitTable, w);\r
+\r
+       Free(w);\r
+}\r
+\r
+// ARP 待ちテーブルの検索\r
+ARP_WAIT *SearchArpWaitTable(VH *v, UINT ip)\r
+{\r
+       ARP_WAIT *w, t;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t.IpAddress = ip;\r
+       w = Search(v->ArpWaitTable, &t);\r
+\r
+       return w;\r
+}\r
+\r
+// ARP 待ちテーブルに登録\r
+void InsertArpWaitTable(VH *v, ARP_WAIT *w)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || w == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Add(v->ArpWaitTable, w);\r
+}\r
+\r
+// ARP 待ちテーブルの初期化\r
+void InitArpWaitTable(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v->ArpWaitTable = NewList(CompareArpWaitTable);\r
+}\r
+\r
+// ARP 待ちテーブルの解放\r
+void FreeArpWaitTable(VH *v)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(v->ArpWaitTable);i++)\r
+       {\r
+               ARP_WAIT *w = LIST_DATA(v->ArpWaitTable, i);\r
+\r
+               Free(w);\r
+       }\r
+\r
+       ReleaseList(v->ArpWaitTable);\r
+}\r
+\r
+// MAC アドレスが不正かどうかチェック\r
+bool IsMacInvalid(UCHAR *mac)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (mac == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < 6;i++)\r
+       {\r
+               if (mac[i] != 0x00)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+       return true;\r
+}\r
+\r
+// MAC アドレスがブロードキャストアドレスかどうかチェック\r
+bool IsMacBroadcast(UCHAR *mac)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (mac == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < 6;i++)\r
+       {\r
+               if (mac[i] != 0xff)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+       return true;\r
+}\r
+\r
+// ARP テーブルにエントリを挿入する\r
+void InsertArpTable(VH *v, UCHAR *mac, UINT ip)\r
+{\r
+       ARP_ENTRY *e, t;\r
+       // 引数チェック\r
+       if (v == NULL || mac == NULL || ip == 0 || ip == 0xffffffff || IsMacBroadcast(mac) || IsMacInvalid(mac))\r
+       {\r
+               return;\r
+       }\r
+\r
+       // すでに同じ IP アドレスが登録されていないかどうかチェック\r
+       t.IpAddress = ip;\r
+       e = Search(v->ArpTable, &t);\r
+       if (e != NULL)\r
+       {\r
+               // 登録されていたのでこれを上書きするだけ\r
+               if (Cmp(e->MacAddress, mac, 6) != 0)\r
+               {\r
+                       e->Created = v->Now;\r
+                       Copy(e->MacAddress, mac, 6);\r
+               }\r
+               e->Expire = v->Now + (UINT64)ARP_ENTRY_EXPIRES;\r
+       }\r
+       else\r
+       {\r
+               // 新しくエントリを作成する\r
+               e = ZeroMalloc(sizeof(ARP_ENTRY));\r
+\r
+               e->Created = v->Now;\r
+               e->Expire = v->Now + (UINT64)ARP_ENTRY_EXPIRES;\r
+               Copy(e->MacAddress, mac, 6);\r
+               e->IpAddress = ip;\r
+\r
+               Add(v->ArpTable, e);\r
+       }\r
+}\r
+\r
+// ARP テーブルのポーリング\r
+void PollingArpTable(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (v->Now > v->NextArpTablePolling)\r
+       {\r
+               v->NextArpTablePolling = v->Now + (UINT64)ARP_ENTRY_POLLING_TIME;\r
+               RefreshArpTable(v);\r
+       }\r
+}\r
+\r
+// 古い ARP エントリを削除する\r
+void RefreshArpTable(VH *v)\r
+{\r
+       UINT i;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+       for (i = 0;i < LIST_NUM(v->ArpTable);i++)\r
+       {\r
+               ARP_ENTRY *e = LIST_DATA(v->ArpTable, i);\r
+\r
+               // 有効期限が切れたものを調べる\r
+               if (e->Expire < v->Now)\r
+               {\r
+                       // 有効期限が切れている\r
+                       Add(o, e);\r
+               }\r
+       }\r
+\r
+       // 有効期限が切れているものを一括して削除する\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               ARP_ENTRY *e = LIST_DATA(o, i);\r
+\r
+               Delete(v->ArpTable, e);\r
+               Free(e);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// ARP テーブルの検索\r
+ARP_ENTRY *SearchArpTable(VH *v, UINT ip)\r
+{\r
+       ARP_ENTRY *e, t;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t.IpAddress = ip;\r
+       e = Search(v->ArpTable, &t);\r
+\r
+       return e;\r
+}\r
+\r
+// ARP テーブルの初期化\r
+void InitArpTable(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       v->ArpTable = NewList(CompareArpTable);\r
+}\r
+\r
+// ARP テーブルの解放\r
+void FreeArpTable(VH *v)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // すべてのエントリを削除する\r
+       for (i = 0;i < LIST_NUM(v->ArpTable);i++)\r
+       {\r
+               ARP_ENTRY *e = LIST_DATA(v->ArpTable, i);\r
+               Free(e);\r
+       }\r
+       ReleaseList(v->ArpTable);\r
+}\r
+\r
+// ARP 待ちテーブルの比較\r
+int CompareArpWaitTable(void *p1, void *p2)\r
+{\r
+       ARP_WAIT *e1, *e2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       e1 = *(ARP_WAIT **)p1;\r
+       e2 = *(ARP_WAIT **)p2;\r
+       if (e1 == NULL || e2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (e1->IpAddress > e2->IpAddress)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (e1->IpAddress < e2->IpAddress)\r
+       {\r
+               return -1;\r
+       }\r
+       return 0;\r
+}\r
+\r
+// ARP テーブルの比較\r
+int CompareArpTable(void *p1, void *p2)\r
+{\r
+       ARP_ENTRY *e1, *e2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       e1 = *(ARP_ENTRY **)p1;\r
+       e2 = *(ARP_ENTRY **)p2;\r
+       if (e1 == NULL || e2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (e1->IpAddress > e2->IpAddress)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (e1->IpAddress < e2->IpAddress)\r
+       {\r
+               return -1;\r
+       }\r
+       return 0;\r
+}\r
+\r
+// 仮想ホストの初期化\r
+bool VirtualInit(VH *v)\r
+{\r
+       // ログ初期化\r
+       v->Logger = NULL;\r
+\r
+       LockVirtual(v);\r
+       {\r
+               // 初期化\r
+               v->Cancel = NewCancel();\r
+               v->SendQueue = NewQueue();\r
+       }\r
+       UnlockVirtual(v);\r
+\r
+       // カウンタリセット\r
+       v->Counter->c = 0;\r
+       v->DhcpId = 0;\r
+\r
+       // ARP テーブルの初期化\r
+       InitArpTable(v);\r
+\r
+       // ARP 待ちテーブルの初期化\r
+       InitArpWaitTable(v);\r
+\r
+       // IP 待ちテーブルの初期化\r
+       InitIpWaitTable(v);\r
+\r
+       // IP 結合リストの初期化\r
+       InitIpCombineList(v);\r
+\r
+       // NAT の初期化\r
+       InitNat(v);\r
+\r
+       // DHCP サーバーの初期化\r
+       InitDhcpServer(v);\r
+\r
+       // その他初期化\r
+       v->flag1 = false;\r
+       v->NextArpTablePolling = Tick64() + (UINT64)ARP_ENTRY_POLLING_TIME;\r
+       v->CurrentIpQuota = 0;\r
+       v->Active = true;\r
+\r
+       return true;\r
+}\r
+bool VirtualPaInit(SESSION *s)\r
+{\r
+       VH *v;\r
+       // 引数チェック\r
+       if (s == NULL || (v = (VH *)s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return VirtualInit(v);\r
+}\r
+\r
+// 仮想ホストのキャンセルオブジェクトを取得\r
+CANCEL *VirtualPaGetCancel(SESSION *s)\r
+{\r
+       VH *v;\r
+       // 引数チェック\r
+       if (s == NULL || (v = (VH *)s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       AddRef(v->Cancel->ref);\r
+       return v->Cancel;\r
+}\r
+\r
+// 仮想ホストから次のパケットを取得\r
+UINT VirtualGetNextPacket(VH *v, void **data)\r
+{\r
+       UINT ret = 0;\r
+\r
+START:\r
+       // 送信キューを調べる\r
+       LockQueue(v->SendQueue);\r
+       {\r
+               BLOCK *block = GetNext(v->SendQueue);\r
+\r
+               if (block != NULL)\r
+               {\r
+                       // パケットがあった\r
+                       ret = block->Size;\r
+                       *data = block->Buf;\r
+                       // 構造体は破棄する\r
+                       Free(block);\r
+               }\r
+       }\r
+       UnlockQueue(v->SendQueue);\r
+\r
+       if (ret == 0)\r
+       {\r
+               LockVirtual(v);\r
+               {\r
+                       v->Now = Tick64();\r
+                       // ポーリング処理\r
+                       VirtualPolling(v);\r
+               }\r
+               UnlockVirtual(v);\r
+               if (v->SendQueue->num_item != 0)\r
+               {\r
+                       goto START;\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+UINT VirtualPaGetNextPacket(SESSION *s, void **data)\r
+{\r
+       VH *v;\r
+       // 引数チェック\r
+       if (s == NULL || (v = (VH *)s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return VirtualGetNextPacket(v, data);\r
+}\r
+\r
+// ポーリング処理 (SessionMain ループ中に 1 回必ず呼ばれる)\r
+void VirtualPolling(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // DHCP ポーリング\r
+       PollingDhcpServer(v);\r
+\r
+       // NAT ポーリング\r
+       PoolingNat(v);\r
+\r
+       // 古い ARP テーブルの清掃\r
+       PollingArpTable(v);\r
+\r
+       // ARP 待ちリストのポーリング\r
+       PollingArpWaitTable(v);\r
+\r
+       // IP 待ちリストのポーリング\r
+       PollingIpWaitTable(v);\r
+\r
+       // IP 結合リストのポーリング\r
+       PollingIpCombine(v);\r
+\r
+       // ビーコン送信プロシージャ\r
+       PollingBeacon(v);\r
+}\r
+\r
+// ビーコン送信プロシージャ\r
+void PollingBeacon(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (v->LastSendBeacon == 0 ||\r
+               ((v->LastSendBeacon + BEACON_SEND_INTERVAL) <= Tick64()))\r
+       {\r
+               v->LastSendBeacon = Tick64();\r
+\r
+               SendBeacon(v);\r
+       }\r
+}\r
+\r
+// Layer-2 パケットを送信する\r
+void VirtualLayer2Send(VH *v, UCHAR *dest_mac, UCHAR *src_mac, USHORT protocol, void *data, UINT size)\r
+{\r
+       MAC_HEADER *mac_header;\r
+       UCHAR *buf;\r
+       BLOCK *block;\r
+       // 引数チェック\r
+       if (v == NULL || dest_mac == NULL || src_mac == NULL || data == NULL || size > (MAX_PACKET_SIZE - sizeof(MAC_HEADER)))\r
+       {\r
+               return;\r
+       }\r
+\r
+       // バッファ生成\r
+       buf = Malloc(MAC_HEADER_SIZE + size);\r
+\r
+       // MAC ヘッダ\r
+       mac_header = (MAC_HEADER *)&buf[0];\r
+       Copy(mac_header->DestAddress, dest_mac, 6);\r
+       Copy(mac_header->SrcAddress, src_mac, 6);\r
+       mac_header->Protocol = Endian16(protocol);\r
+\r
+       // データのコピー\r
+       Copy(&buf[sizeof(MAC_HEADER)], data, size);\r
+\r
+       // サイズ\r
+       size += sizeof(MAC_HEADER);\r
+\r
+       // パケット生成\r
+       block = NewBlock(buf, size, 0);\r
+\r
+       // キューに挿入する\r
+       LockQueue(v->SendQueue);\r
+       {\r
+               InsertQueue(v->SendQueue, block);\r
+       }\r
+       UnlockQueue(v->SendQueue);\r
+\r
+       // キャンセル\r
+       Cancel(v->Cancel);\r
+}\r
+\r
+// IP パケットを送信する (自動的に分割処理を行う)\r
+void SendIp(VH *v, UINT dest_ip, UINT src_ip, UCHAR protocol, void *data, UINT size)\r
+{\r
+       UINT mss;\r
+       UCHAR *buf;\r
+       USHORT offset;\r
+       USHORT id;\r
+       USHORT total_size;\r
+       UINT size_of_this_packet;\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL || size == 0 || size > MAX_IP_DATA_SIZE_TOTAL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 最大セグメントサイズ\r
+       mss = v->IpMss;\r
+\r
+       // バッファ\r
+       buf = (UCHAR *)data;\r
+\r
+       // ID\r
+       id = (v->NextId++);\r
+\r
+       // 合計サイズ\r
+       total_size = (USHORT)size;\r
+\r
+       // 分割作業を開始\r
+       offset = 0;\r
+\r
+       while (true)\r
+       {\r
+               bool last_packet = false;\r
+               // このパケットのサイズを取得\r
+               size_of_this_packet = MIN((USHORT)mss, (total_size - offset));\r
+               if ((offset + (USHORT)size_of_this_packet) == total_size)\r
+               {\r
+                       last_packet = true;\r
+               }\r
+\r
+               // 分割されたパケットの送信処理\r
+               SendFragmentedIp(v, dest_ip, src_ip, id,\r
+                       total_size, offset, protocol, buf + offset, size_of_this_packet, NULL);\r
+               if (last_packet)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               offset += (USHORT)size_of_this_packet;\r
+       }\r
+}\r
+\r
+// 分割済みの IP パケットを送信予約する\r
+void SendFragmentedIp(VH *v, UINT dest_ip, UINT src_ip, USHORT id, USHORT total_size, USHORT offset, UCHAR protocol, void *data, UINT size, UCHAR *dest_mac)\r
+{\r
+       UCHAR *buf;\r
+       IPV4_HEADER *ip;\r
+       ARP_ENTRY *arp;\r
+       // 引数チェック\r
+       if (v == NULL || data == NULL || size == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メモリ確保\r
+       buf = Malloc(size + IP_HEADER_SIZE);\r
+       ip = (IPV4_HEADER *)&buf[0];\r
+\r
+       // IP ヘッダ構築\r
+       ip->VersionAndHeaderLength = 0;\r
+       IPV4_SET_VERSION(ip, 4);\r
+       IPV4_SET_HEADER_LEN(ip, (IP_HEADER_SIZE / 4));\r
+       ip->TypeOfService = DEFAULT_IP_TOS;\r
+       ip->TotalLength = Endian16((USHORT)(size + IP_HEADER_SIZE));\r
+       ip->Identification = Endian16(id);\r
+       ip->FlagsAndFlagmentOffset[0] = ip->FlagsAndFlagmentOffset[1] = 0;\r
+       IPV4_SET_OFFSET(ip, (offset / 8));\r
+       if ((offset + size) >= total_size)\r
+       {\r
+               IPV4_SET_FLAGS(ip, 0x00);\r
+       }\r
+       else\r
+       {\r
+               IPV4_SET_FLAGS(ip, 0x01);\r
+       }\r
+       ip->TimeToLive = DEFAULT_IP_TTL;\r
+       ip->Protocol = protocol;\r
+       ip->Checksum = 0;\r
+       ip->SrcIP = src_ip;\r
+       ip->DstIP = dest_ip;\r
+\r
+       // チェックサム計算\r
+       ip->Checksum = IpChecksum(ip, IP_HEADER_SIZE);\r
+\r
+       // データコピー\r
+       Copy(buf + IP_HEADER_SIZE, data, size);\r
+\r
+       if (dest_mac == NULL)\r
+       {\r
+               if (ip->DstIP == 0xffffffff ||\r
+                       (IsInNetwork(ip->DstIP, v->HostIP, v->HostMask) && (ip->DstIP & (~v->HostMask)) == (~v->HostMask)))\r
+               {\r
+                       // ブロードキャストアドレス\r
+                       dest_mac = broadcast;\r
+               }\r
+               else\r
+               {\r
+                       // 宛先 MAC アドレスが不明な場合は ARP 問い合わせ\r
+                       arp = SearchArpTable(v, dest_ip);\r
+                       if (arp != NULL)\r
+                       {\r
+                               dest_mac = arp->MacAddress;\r
+                       }\r
+               }\r
+       }\r
+       if (dest_mac != NULL)\r
+       {\r
+               // 直ちにパケットを送信する\r
+               VirtualIpSend(v, dest_mac, buf, size + IP_HEADER_SIZE);\r
+\r
+               // パケットデータは解放して良い\r
+               Free(buf);\r
+       }\r
+       else\r
+       {\r
+               // このパケットはまだ転送できないので IP 待ちテーブルに追加する\r
+               InsertIpWaitTable(v, dest_ip, src_ip, buf, size + IP_HEADER_SIZE);\r
+\r
+               // ARP を発行する\r
+               SendArp(v, dest_ip);\r
+       }\r
+}\r
+\r
+// IP パケット (分割済み) を送信する\r
+void VirtualIpSend(VH *v, UCHAR *dest_mac, void *data, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || dest_mac == NULL || data == NULL || size == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 送信\r
+       VirtualLayer2Send(v, dest_mac, v->MacAddress, MAC_PROTO_IPV4, data, size);\r
+}\r
+\r
+// ARP リクエストパケットを送信する\r
+void VirtualArpSendRequest(VH *v, UINT dest_ip)\r
+{\r
+       ARPV4_HEADER arp;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ARP ヘッダを構築\r
+       arp.HardwareType = Endian16(ARP_HARDWARE_TYPE_ETHERNET);\r
+       arp.ProtocolType = Endian16(MAC_PROTO_IPV4);\r
+       arp.HardwareSize = 6;\r
+       arp.ProtocolSize = 4;\r
+       arp.Operation = Endian16(ARP_OPERATION_REQUEST);\r
+       Copy(arp.SrcAddress, v->MacAddress, 6);\r
+       arp.SrcIP = v->HostIP;\r
+       Zero(&arp.TargetAddress, 6);\r
+       arp.TargetIP = dest_ip;\r
+\r
+       // 送信\r
+       VirtualLayer2Send(v, broadcast, v->MacAddress, MAC_PROTO_ARPV4, &arp, sizeof(arp));\r
+}\r
+\r
+// ARP レスポンスパケットを送信する\r
+void VirtualArpSendResponse(VH *v, UCHAR *dest_mac, UINT dest_ip, UINT src_ip)\r
+{\r
+       ARPV4_HEADER arp;\r
+       // 引数チェック\r
+       if (v == NULL || dest_mac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ARP ヘッダを構築\r
+       arp.HardwareType = Endian16(ARP_HARDWARE_TYPE_ETHERNET);\r
+       arp.ProtocolType = Endian16(MAC_PROTO_IPV4);\r
+       arp.HardwareSize = 6;\r
+       arp.ProtocolSize = 4;\r
+       arp.Operation = Endian16(ARP_OPERATION_RESPONSE);\r
+       Copy(arp.SrcAddress, v->MacAddress, 6);\r
+       Copy(arp.TargetAddress, dest_mac, 6);\r
+       arp.SrcIP = src_ip;\r
+       arp.TargetIP = dest_ip;\r
+\r
+       // 送信\r
+       VirtualLayer2Send(v, dest_mac, v->MacAddress, MAC_PROTO_ARPV4, &arp, sizeof(ARPV4_HEADER));\r
+}\r
+\r
+// ARP リクエストパケットを受信した\r
+void VirtualArpResponseRequest(VH *v, PKT *packet)\r
+{\r
+       ARPV4_HEADER *arp;\r
+       // 引数チェック\r
+       if (v == NULL || packet == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       arp = packet->L3.ARPv4Header;\r
+\r
+       // 相手のホスト IP アドレスと MAC アドレスを既知の情報とする\r
+       ArpIpWasKnown(v, arp->SrcIP, arp->SrcAddress);\r
+\r
+       // 自分のホスト IP アドレスと一致するかどうか検索\r
+       if (v->HostIP == arp->TargetIP)\r
+       {\r
+               // 一致したので応答する\r
+               VirtualArpSendResponse(v, arp->SrcAddress, arp->SrcIP, v->HostIP);\r
+               return;\r
+       }\r
+       // 一致しない場合は何もしない\r
+}\r
+\r
+// ARP レスポンスパケットを受信した\r
+void VirtualArpResponseReceived(VH *v, PKT *packet)\r
+{\r
+       ARPV4_HEADER *arp;\r
+       // 引数チェック\r
+       if (v == NULL || packet == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       arp = packet->L3.ARPv4Header;\r
+\r
+       // この情報を既知の情報とする\r
+       ArpIpWasKnown(v, arp->SrcIP, arp->SrcAddress);\r
+}\r
+\r
+// ARP パケットを受信した\r
+void VirtualArpReceived(VH *v, PKT *packet)\r
+{\r
+       ARPV4_HEADER *arp;\r
+       // 引数チェック\r
+       if (v == NULL || packet == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       arp = packet->L3.ARPv4Header;\r
+\r
+       if (Endian16(arp->HardwareType) != ARP_HARDWARE_TYPE_ETHERNET)\r
+       {\r
+               // ハードウェア種類が Ethernet 以外の場合は無視\r
+               return;\r
+       }\r
+       if (Endian16(arp->ProtocolType) != MAC_PROTO_IPV4)\r
+       {\r
+               // プロトコル種類が IPv4 以外の場合は無視\r
+               return;\r
+       }\r
+       if (arp->HardwareSize != 6 || arp->ProtocolSize != 4)\r
+       {\r
+               // ハードウェアアドレスまたはプロトコルアドレスのサイズが不正なので無視\r
+               return;\r
+       }\r
+       // 送信元 MAC アドレスをチェック\r
+       if (Cmp(arp->SrcAddress, packet->MacAddressSrc, 6) != 0)\r
+       {\r
+               // ARP パケットの MAC アドレスと MAC ヘッダの MAC アドレスが異なる\r
+               return;\r
+       }\r
+\r
+       switch (Endian16(arp->Operation))\r
+       {\r
+       case ARP_OPERATION_REQUEST:             // ARP リクエスト\r
+               VirtualArpResponseRequest(v, packet);\r
+               break;\r
+\r
+       case ARP_OPERATION_RESPONSE:    // ARP レスポンス\r
+               VirtualArpResponseReceived(v, packet);\r
+               break;\r
+       }\r
+}\r
+\r
+// DHCP サーバーの解放\r
+void FreeDhcpServer(VH *v)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // すべてのリースエントリを削除する\r
+       for (i = 0;i < LIST_NUM(v->DhcpLeaseList);i++)\r
+       {\r
+               DHCP_LEASE *d = LIST_DATA(v->DhcpLeaseList, i);\r
+               FreeDhcpLease(d);\r
+       }\r
+\r
+       ReleaseList(v->DhcpLeaseList);\r
+       v->DhcpLeaseList = NULL;\r
+}\r
+\r
+// DHCP サーバーの初期化\r
+void InitDhcpServer(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // リスト作成\r
+       v->DhcpLeaseList = NewList(CompareDhcpLeaseList);\r
+}\r
+\r
+// DHCP リース項目を IP アドレスで検索\r
+DHCP_LEASE *SearchDhcpLeaseByIp(VH *v, UINT ip)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(v->DhcpLeaseList);i++)\r
+       {\r
+               DHCP_LEASE *d = LIST_DATA(v->DhcpLeaseList, i);\r
+               if (d->IpAddress == ip)\r
+               {\r
+                       return d;\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// DHCP リース項目を MAC アドレスで検索\r
+DHCP_LEASE *SearchDhcpLeaseByMac(VH *v, UCHAR *mac)\r
+{\r
+       DHCP_LEASE *d, t;\r
+       // 引数チェック\r
+       if (v == NULL || mac == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Copy(&t.MacAddress, mac, 6);\r
+       d = Search(v->DhcpLeaseList, &t);\r
+\r
+       return d;\r
+}\r
+\r
+// DHCP リース項目の解放\r
+void FreeDhcpLease(DHCP_LEASE *d)\r
+{\r
+       // 引数チェック\r
+       if (d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(d->Hostname);\r
+       Free(d);\r
+}\r
+\r
+// DHCP リース項目の作成\r
+DHCP_LEASE *NewDhcpLease(UINT expire, UCHAR *mac_address, UINT ip, UINT mask, char *hostname)\r
+{\r
+       DHCP_LEASE *d;\r
+       // 引数チェック\r
+       if (mac_address == NULL || hostname == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       d = ZeroMalloc(sizeof(DHCP_LEASE));\r
+       d->LeasedTime = (UINT64)Tick64();\r
+       if (expire == INFINITE)\r
+       {\r
+               d->ExpireTime = INFINITE;\r
+       }\r
+       else\r
+       {\r
+               d->ExpireTime = d->LeasedTime + (UINT64)expire;\r
+       }\r
+       d->IpAddress = ip;\r
+       d->Mask = mask;\r
+       d->Hostname = CopyStr(hostname);\r
+       Copy(d->MacAddress, mac_address, 6);\r
+\r
+\r
+       return d;\r
+}\r
+\r
+// DHCP リストの項目の比較\r
+int CompareDhcpLeaseList(void *p1, void *p2)\r
+{\r
+       DHCP_LEASE *d1, *d2;\r
+       // 引数チェック\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       d1 = *(DHCP_LEASE **)p1;\r
+       d2 = *(DHCP_LEASE **)p2;\r
+       if (d1 == NULL || d2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return Cmp(d1->MacAddress, d2->MacAddress, 6);\r
+}\r
+\r
+// DHCP サーバーのポーリング\r
+void PollingDhcpServer(VH *v)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (v->LastDhcpPolling != 0)\r
+       {\r
+               if ((v->LastDhcpPolling + (UINT64)DHCP_POLLING_INTERVAL) < v->Now ||\r
+                       v->LastDhcpPolling > v->Now)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+       v->LastDhcpPolling = v->Now;\r
+\r
+       // 有効期限の切れたエントリを削除\r
+FIRST_LIST:\r
+       for (i = 0;i < LIST_NUM(v->DhcpLeaseList);i++)\r
+       {\r
+               DHCP_LEASE *d = LIST_DATA(v->DhcpLeaseList, i);\r
+\r
+               if (d->ExpireTime < v->Now)\r
+               {\r
+                       FreeDhcpLease(d);\r
+                       Delete(v->DhcpLeaseList, d);\r
+                       goto FIRST_LIST;\r
+               }\r
+       }\r
+}\r
+\r
+// DHCP REQUEST に対応する\r
+UINT ServeDhcpRequest(VH *v, UCHAR *mac, UINT request_ip)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (v == NULL || mac == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = ServeDhcpDiscover(v, mac, request_ip);\r
+       if (ret != request_ip)\r
+       {\r
+               if (request_ip != 0)\r
+               {\r
+                       // 要求されている IP アドレスを割り当てることができない場合はエラー\r
+                       return 0;\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// DHCP DISCOVER に対応する\r
+UINT ServeDhcpDiscover(VH *v, UCHAR *mac, UINT request_ip)\r
+{\r
+       UINT ret = 0;\r
+       // 引数チェック\r
+       if (v == NULL || mac == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (request_ip != 0)\r
+       {\r
+               // IP アドレスが指定されている\r
+               DHCP_LEASE *d = SearchDhcpLeaseByIp(v, request_ip);\r
+               if (d != NULL)\r
+               {\r
+                       // 同じ IP アドレスのエントリがすでに存在している場合は\r
+                       // 同じ MAC アドレスからの要求であることを調べる\r
+                       if (Cmp(mac, d->MacAddress, 6) == 0)\r
+                       {\r
+                               // 指定された IP アドレスが割り当て範囲内にあるかどうか調べる\r
+                               if (Endian32(v->DhcpIpStart) <= Endian32(request_ip) &&\r
+                                       Endian32(request_ip) <= Endian32(v->DhcpIpEnd))\r
+                               {\r
+                                       // 範囲内にあるなら承諾する\r
+                                       ret = request_ip;\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // 指定された IP アドレスが割り当て範囲内にあるかどうか調べる\r
+                       if (Endian32(v->DhcpIpStart) <= Endian32(request_ip) &&\r
+                               Endian32(request_ip) <= Endian32(v->DhcpIpEnd))\r
+                       {\r
+                               // 範囲内にあるなら承諾する\r
+                               ret = request_ip;\r
+                       }\r
+                       else\r
+                       {\r
+                               // 範囲外であるが Discover なので範囲内の IP を 1 つ提案する\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (ret == 0)\r
+       {\r
+               // すでに登録されているエントリで同じ MAC アドレスのものがあれば\r
+               // それを優先して使用する\r
+               DHCP_LEASE *d = SearchDhcpLeaseByMac(v, mac);\r
+               if (d != NULL)\r
+               {\r
+                       // 見つかった IP アドレスが割り当て範囲内にあるかどうか調べる\r
+                       if (Endian32(v->DhcpIpStart) <= Endian32(d->IpAddress) &&\r
+                               Endian32(d->IpAddress) <= Endian32(v->DhcpIpEnd))\r
+                       {\r
+                               // 範囲内にあるなら見つかったIPアドレスを使用する\r
+                               ret = d->IpAddress;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (ret == 0)\r
+       {\r
+               // 新しく割り当てることが可能な IP アドレスを適当に取る\r
+               ret = GetFreeDhcpIpAddress(v);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 新しく割り当てることが可能な IP アドレスを適当に 1 つ取る\r
+UINT GetFreeDhcpIpAddress(VH *v)\r
+{\r
+       UINT ip_start, ip_end;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ip_start = Endian32(v->DhcpIpStart);\r
+       ip_end = Endian32(v->DhcpIpEnd);\r
+\r
+       for (i = ip_start; i <= ip_end;i++)\r
+       {\r
+               UINT ip = Endian32(i);\r
+               if (SearchDhcpLeaseByIp(v, ip) == NULL)\r
+               {\r
+                       // 空き IP アドレスを発見した\r
+                       return ip;\r
+               }\r
+       }\r
+\r
+       // 空きが無い\r
+       return 0;\r
+}\r
+\r
+// 仮想 DHCP サーバー\r
+void VirtualDhcpServer(VH *v, PKT *p)\r
+{\r
+       DHCPV4_HEADER *dhcp;\r
+       UCHAR *data;\r
+       UINT size;\r
+       UINT dhcp_header_size;\r
+       UINT dhcp_data_offset;\r
+       UINT tran_id;\r
+       UINT magic_cookie = Endian32(DHCP_MAGIC_COOKIE);\r
+       bool ok;\r
+       DHCP_OPTION_LIST *opt;\r
+       // 引数チェック\r
+       if (v == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       dhcp = p->L7.DHCPv4Header;\r
+\r
+       tran_id = Endian32(dhcp->TransactionId);\r
+\r
+       // DHCP データとサイズを取得する\r
+       dhcp_header_size = sizeof(DHCPV4_HEADER);\r
+       dhcp_data_offset = (UINT)(((UCHAR *)p->L7.DHCPv4Header) - ((UCHAR *)p->MacHeader) + dhcp_header_size);\r
+       data = ((UCHAR *)dhcp) + dhcp_header_size;\r
+       size = p->PacketSize - dhcp_data_offset;\r
+       if (dhcp_header_size < 5)\r
+       {\r
+               // データサイズが不正\r
+               return;\r
+       }\r
+\r
+       // Magic Cookie を検索する\r
+       ok = false;\r
+       while (size >= 5)\r
+       {\r
+               if (Cmp(data, &magic_cookie, sizeof(magic_cookie)) == 0)\r
+               {\r
+                       // 発見\r
+                       data += 4;\r
+                       size -= 4;\r
+                       ok = true;\r
+                       break;\r
+               }\r
+               data++;\r
+               size--;\r
+       }\r
+\r
+       if (ok == false)\r
+       {\r
+               // パケット不正\r
+               return;\r
+       }\r
+\r
+       // DHCP オプションリストのパース\r
+       opt = ParseDhcpOptionList(data, size);\r
+       if (opt == NULL)\r
+       {\r
+               // パケット不正\r
+               return;\r
+       }\r
+\r
+       if (dhcp->OpCode == 1 && (opt->Opcode == DHCP_DISCOVER || opt->Opcode == DHCP_REQUEST))\r
+       {\r
+               // サーバーとしての動作を行う\r
+               UINT ip;\r
+               if (opt->RequestedIp == 0)\r
+               {\r
+                       opt->RequestedIp = p->L3.IPv4Header->SrcIP;\r
+               }\r
+               if (opt->Opcode == DHCP_DISCOVER)\r
+               {\r
+                       // 利用できる IP アドレスを 1 つ返す\r
+                       ip = ServeDhcpDiscover(v, p->MacAddressSrc, opt->RequestedIp);\r
+               }\r
+               else\r
+               {\r
+                       // IP アドレスを確定する\r
+                       ip = ServeDhcpRequest(v, p->MacAddressSrc, opt->RequestedIp);\r
+               }\r
+               if (ip != 0)\r
+               {\r
+                       // 提供可能な IP アドレスがある場合は応答してやる\r
+\r
+                       if (opt->Opcode == DHCP_REQUEST)\r
+                       {\r
+                               DHCP_LEASE *d;\r
+                               char mac[MAX_SIZE];\r
+                               char str[MAX_SIZE];\r
+                               // 同じ IP アドレスで古いレコードがあれば削除する\r
+                               d = SearchDhcpLeaseByIp(v, ip);\r
+                               if (d != NULL)\r
+                               {\r
+                                       FreeDhcpLease(d);\r
+                                       Delete(v->DhcpLeaseList, d);\r
+                               }\r
+\r
+                               // 新しいエントリを作成する\r
+                               d = NewDhcpLease(v->DhcpExpire, p->MacAddressSrc,\r
+                                       ip, v->DhcpMask,\r
+                                       opt->Hostname);\r
+                               d->Id = ++v->DhcpId;\r
+                               Add(v->DhcpLeaseList, d);\r
+                               MacToStr(mac, sizeof(mac), d->MacAddress);\r
+\r
+                               IPToStr32(str, sizeof(str), d->IpAddress);\r
+\r
+                               NLog(v, "LH_NAT_DHCP_CREATED", d->Id, mac, str, d->Hostname, v->DhcpExpire / 1000);\r
+                       }\r
+\r
+                       // 応答する\r
+                       if (ip != 0)\r
+                       {\r
+                               DHCP_OPTION_LIST ret;\r
+                               LIST *o;\r
+                               Zero(&ret, sizeof(ret));\r
+\r
+                               ret.Opcode = (opt->Opcode == DHCP_DISCOVER ? DHCP_OFFER : DHCP_ACK);\r
+                               ret.ServerAddress = v->HostIP;\r
+                               if (v->DhcpExpire == INFINITE)\r
+                               {\r
+                                       ret.LeaseTime = INFINITE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       ret.LeaseTime = Endian32(v->DhcpExpire / 1000);\r
+                               }\r
+                               StrCpy(ret.DomainName, sizeof(ret.DomainName), v->DhcpDomain);\r
+                               ret.SubnetMask = v->DhcpMask;\r
+                               ret.DnsServer = v->DhcpDns;\r
+                               ret.Gateway = v->DhcpGateway;\r
+\r
+                               if (1)\r
+                               {\r
+                                       char client_mac[MAX_SIZE];\r
+                                       char client_ip[64];\r
+                                       IP ips;\r
+                                       BinToStr(client_mac, sizeof(client_mac), p->MacAddressSrc, 6);\r
+                                       UINTToIP(&ips, ip);\r
+                                       IPToStr(client_ip, sizeof(client_ip), &ips);\r
+                                       Debug("DHCP %s : %s given %s\n",\r
+                                               ret.Opcode == DHCP_OFFER ? "DHCP_OFFER" : "DHCP_ACK",\r
+                                               client_mac, client_ip);\r
+                               }\r
+\r
+                               // DHCP オプションのビルド\r
+                               o = BuildDhcpOption(&ret);\r
+                               if (o != NULL)\r
+                               {\r
+                                       BUF *b = BuildDhcpOptionsBuf(o);\r
+                                       if (b != NULL)\r
+                                       {\r
+                                               UINT dest_ip = p->L3.IPv4Header->SrcIP;\r
+                                               if (dest_ip == 0)\r
+                                               {\r
+                                                       dest_ip = 0xffffffff;\r
+                                               }\r
+                                               // 送信\r
+                                               VirtualDhcpSend(v, tran_id, dest_ip, Endian16(p->L4.UDPHeader->SrcPort),\r
+                                                       ip, dhcp->ClientMacAddress, b);\r
+\r
+                                               // メモリ解放\r
+                                               FreeBuf(b);\r
+                                       }\r
+                                       FreeDhcpOptions(o);\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // 提供できる IP アドレスが無い\r
+                       DHCP_OPTION_LIST ret;\r
+                       LIST *o;\r
+                       Zero(&ret, sizeof(ret));\r
+\r
+                       ret.Opcode = DHCP_NACK;\r
+                       ret.ServerAddress = v->HostIP;\r
+                       StrCpy(ret.DomainName, sizeof(ret.DomainName), v->DhcpDomain);\r
+                       ret.SubnetMask = v->DhcpMask;\r
+\r
+                       // DHCP オプションのビルド\r
+                       o = BuildDhcpOption(&ret);\r
+                       if (o != NULL)\r
+                       {\r
+                               BUF *b = BuildDhcpOptionsBuf(o);\r
+                               if (b != NULL)\r
+                               {\r
+                                       UINT dest_ip = p->L3.IPv4Header->SrcIP;\r
+                                       if (dest_ip == 0)\r
+                                       {\r
+                                               dest_ip = 0xffffffff;\r
+                                       }\r
+                                       // 送信\r
+                                       VirtualDhcpSend(v, tran_id, dest_ip, Endian16(p->L4.UDPHeader->SrcPort),\r
+                                               ip, dhcp->ClientMacAddress, b);\r
+\r
+                                       // メモリ解放\r
+                                       FreeBuf(b);\r
+                               }\r
+                               FreeDhcpOptions(o);\r
+                       }\r
+               }\r
+       }\r
+\r
+       // メモリ解放\r
+       Free(opt);\r
+}\r
+\r
+// DHCP 応答パケットの送信\r
+void VirtualDhcpSend(VH *v, UINT tran_id, UINT dest_ip, UINT dest_port,\r
+                                        UINT new_ip, UCHAR *client_mac, BUF *b)\r
+{\r
+       UINT blank_size = 128 + 64;\r
+       UINT dhcp_packet_size;\r
+       UINT magic = Endian32(DHCP_MAGIC_COOKIE);\r
+       DHCPV4_HEADER *dhcp;\r
+       void *magic_cookie_addr;\r
+       void *buffer_addr;\r
+       // 引数チェック\r
+       if (v == NULL || b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // DHCP パケットサイズを求める\r
+       dhcp_packet_size = blank_size + sizeof(DHCPV4_HEADER) + sizeof(magic) + b->Size;\r
+\r
+       // ヘッダ作成\r
+       dhcp = ZeroMalloc(dhcp_packet_size);\r
+\r
+       dhcp->OpCode = 2;\r
+       dhcp->HardwareType = 1;\r
+       dhcp->HardwareAddressSize = 6;\r
+       dhcp->Hops = 0;\r
+       dhcp->TransactionId = Endian32(tran_id);\r
+       dhcp->Seconds = 0;\r
+       dhcp->Flags = 0;\r
+       dhcp->YourIP = new_ip;\r
+       dhcp->ServerIP = v->HostIP;\r
+       Copy(dhcp->ClientMacAddress, client_mac, 6);\r
+\r
+       // アドレスを求める\r
+       magic_cookie_addr = (((UCHAR *)dhcp) + sizeof(DHCPV4_HEADER) + blank_size);\r
+       buffer_addr = ((UCHAR *)magic_cookie_addr) + sizeof(magic);\r
+\r
+       // Magic Cookie\r
+       Copy(magic_cookie_addr, &magic, sizeof(magic));\r
+\r
+       // Buffer\r
+       Copy(buffer_addr, b->Buf, b->Size);\r
+\r
+       // 送信\r
+       SendUdp(v, dest_ip, dest_port, v->HostIP, NAT_DHCP_SERVER_PORT, dhcp, dhcp_packet_size);\r
+\r
+       Free(dhcp);\r
+}\r
+\r
+// DHCP オプション リストをバッファに変換する\r
+BUF *BuildDhcpOptionsBuf(LIST *o)\r
+{\r
+       BUF *b;\r
+       UINT i;\r
+       UCHAR id;\r
+       UCHAR sz;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               DHCP_OPTION *d = LIST_DATA(o, i);\r
+               id = (UCHAR)d->Id;\r
+               sz = (UCHAR)d->Size;\r
+               WriteBuf(b, &id, 1);\r
+               WriteBuf(b, &sz, 1);\r
+               WriteBuf(b, d->Data, d->Size);\r
+       }\r
+\r
+       id = 0xff;\r
+       WriteBuf(b, &id, 1);\r
+\r
+       return b;\r
+}\r
+\r
+// DHCP オプション リストを DHCP オプションに変換する\r
+LIST *BuildDhcpOption(DHCP_OPTION_LIST *opt)\r
+{\r
+       LIST *o;\r
+       UCHAR opcode;\r
+       // 引数チェック\r
+       if (opt == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       // オペコード\r
+       opcode = (UCHAR)opt->Opcode;\r
+       Add(o, NewDhcpOption(DHCP_ID_MESSAGE_TYPE, &opcode, sizeof(opcode)));\r
+       Add(o, NewDhcpOption(DHCP_ID_SERVER_ADDRESS, &opt->ServerAddress, sizeof(opt->ServerAddress)));\r
+       Add(o, NewDhcpOption(DHCP_ID_LEASE_TIME, &opt->LeaseTime, sizeof(opt->LeaseTime)));\r
+       if (StrLen(opt->DomainName) != 0 && opt->DnsServer != 0)\r
+       {\r
+               Add(o, NewDhcpOption(DHCP_ID_DOMAIN_NAME, opt->DomainName, StrLen(opt->DomainName)));\r
+       }\r
+       if (opt->SubnetMask != 0)\r
+       {\r
+               Add(o, NewDhcpOption(DHCP_ID_SUBNET_MASK, &opt->SubnetMask, sizeof(opt->SubnetMask)));\r
+       }\r
+       if (opt->Gateway != 0)\r
+       {\r
+               Add(o, NewDhcpOption(DHCP_ID_GATEWAY_ADDR, &opt->Gateway, sizeof(opt->Gateway)));\r
+       }\r
+       if (opt->DnsServer != 0)\r
+       {\r
+               Add(o, NewDhcpOption(DHCP_ID_DNS_ADDR, &opt->DnsServer, sizeof(opt->DnsServer)));\r
+       }\r
+\r
+       return o;\r
+}\r
+\r
+// 新しい DHCP オプション項目の作成\r
+DHCP_OPTION *NewDhcpOption(UINT id, void *data, UINT size)\r
+{\r
+       DHCP_OPTION *ret;\r
+       if (size != 0 && data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(DHCP_OPTION));\r
+       ret->Data = ZeroMalloc(size);\r
+       Copy(ret->Data, data, size);\r
+       ret->Size = (UCHAR)size;\r
+       ret->Id = (UCHAR)id;\r
+\r
+       return ret;\r
+}\r
+\r
+// DHCP オプションリストのパース\r
+DHCP_OPTION_LIST *ParseDhcpOptionList(void *data, UINT size)\r
+{\r
+       DHCP_OPTION_LIST *ret;\r
+       LIST *o;\r
+       DHCP_OPTION *a;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // リストのパース\r
+       o = ParseDhcpOptions(data, size);\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(DHCP_OPTION_LIST));\r
+\r
+       // オペコードの取得\r
+       a = GetDhcpOption(o, DHCP_ID_MESSAGE_TYPE);\r
+       if (a != NULL)\r
+       {\r
+               if (a->Size == 1)\r
+               {\r
+                       ret->Opcode = *((UCHAR *)a->Data);\r
+               }\r
+       }\r
+\r
+       switch (ret->Opcode)\r
+       {\r
+       case DHCP_DISCOVER:\r
+       case DHCP_REQUEST:\r
+               // クライアント要求なのでより細かくパースする\r
+               // 要求された IP アドレス\r
+               a = GetDhcpOption(o, DHCP_ID_REQUEST_IP_ADDRESS);\r
+               if (a != NULL && a->Size == 4)\r
+               {\r
+                       Copy(&ret->RequestedIp, a->Data, 4);\r
+               }\r
+               // ホスト名\r
+               a = GetDhcpOption(o, DHCP_ID_HOST_NAME);\r
+               if (a != NULL)\r
+               {\r
+                       if (a->Size > 1)\r
+                       {\r
+                               Copy(ret->Hostname, a->Data, MIN(a->Size, sizeof(ret->Hostname) - 1));\r
+                       }\r
+               }\r
+               break;\r
+\r
+       case DHCP_OFFER:\r
+       case DHCP_ACK:\r
+               // 今のところこの 2 つのオプションをパースする必要は無い\r
+               break;\r
+       }\r
+\r
+       // リストの解放\r
+       FreeDhcpOptions(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// DHCP オプションの検索\r
+DHCP_OPTION *GetDhcpOption(LIST *o, UINT id)\r
+{\r
+       UINT i;\r
+       DHCP_OPTION *ret = NULL;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               DHCP_OPTION *opt = LIST_DATA(o, i);\r
+               if (opt->Id == id)\r
+               {\r
+                       ret = opt;\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// DHCP オプションの解放\r
+void FreeDhcpOptions(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               DHCP_OPTION *opt = LIST_DATA(o, i);\r
+               Free(opt->Data);\r
+               Free(opt);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// DHCP オプションのパース\r
+LIST *ParseDhcpOptions(void *data, UINT size)\r
+{\r
+       BUF *b;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, data, size);\r
+       SeekBuf(b, 0, 0);\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       while (true)\r
+       {\r
+               UCHAR c = 0;\r
+               UCHAR sz = 0;\r
+               DHCP_OPTION *opt;\r
+               if (ReadBuf(b, &c, 1) != 1)\r
+               {\r
+                       break;\r
+               }\r
+               if (c == 0xff)\r
+               {\r
+                       break;\r
+               }\r
+               if (ReadBuf(b, &sz, 1) != 1)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               opt = ZeroMalloc(sizeof(DHCP_OPTION));\r
+               opt->Id = (UINT)c;\r
+               opt->Size = (UINT)sz;\r
+               opt->Data = ZeroMalloc((UINT)sz);\r
+               ReadBuf(b, opt->Data, sz);\r
+               Add(o, opt);\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return o;\r
+}\r
+\r
+// 仮想ホスト - Layer2 の処理\r
+void VirtualLayer2(VH *v, PKT *packet)\r
+{\r
+       bool ok;\r
+       // 引数チェック\r
+       if (packet == NULL || v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // パケットフィルタ\r
+       if (VirtualLayer2Filter(v, packet) == false)\r
+       {\r
+               // パケットは無視された\r
+               return;\r
+       }\r
+\r
+       ok = false;\r
+       if (packet->TypeL3 == L3_IPV4 && packet->TypeL4 == L4_UDP && packet->TypeL7 == L7_DHCPV4)\r
+       {\r
+               if (v->UseDhcp)\r
+               {\r
+                       // DHCP パケットに関する特殊な処理\r
+                       if (packet->BroadcastPacket || Cmp(packet->MacAddressDest, v->MacAddress, 6) == 0)\r
+                       {\r
+                               // 仮想 DHCP サーバー処理\r
+                               VirtualDhcpServer(v, packet);\r
+                               ok = true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (ok == false)\r
+       {\r
+               // サポートしているプロトコルごとに処理\r
+               switch (packet->TypeL3)\r
+               {\r
+               case L3_ARPV4:  // ARPv4\r
+                       VirtualArpReceived(v, packet);\r
+                       break;\r
+\r
+               case L3_IPV4:   // IPv4\r
+                       VirtualIpReceived(v, packet);\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// パケットフィルタ (自分以外へのパケットを遮断)\r
+bool VirtualLayer2Filter(VH *v, PKT *packet)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL || packet == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ブロードキャストパケットなら通過\r
+       if (packet->BroadcastPacket)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       // 送信元が自分のパケットなら無視\r
+       if (Cmp(packet->MacAddressSrc, v->MacAddress, 6) == 0)\r
+       {\r
+               return false;\r
+       }\r
+       // 自分宛のパケットなら通過\r
+       if (Cmp(packet->MacAddressDest, v->MacAddress, 6) == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       // それ以外のパケットなら破棄\r
+       return false;\r
+}\r
+\r
+// 仮想ホストにパケットを受信させる\r
+bool VirtualPutPacket(VH *v, void *data, UINT size)\r
+{\r
+       if (data == NULL)\r
+       {\r
+               // フラッシュ\r
+               v->flag1 = false;\r
+       }\r
+       else\r
+       {\r
+               // 受信したパケットを解釈する\r
+               PKT *packet = ParsePacket(data, size);\r
+\r
+               if (v->flag1 == false)\r
+               {\r
+                       v->flag1 = true;\r
+                       v->Now = Tick64();\r
+               }\r
+\r
+               // ここの中は仮想マシン全体をロックする\r
+               LockVirtual(v);\r
+               {\r
+                       if (packet != NULL)\r
+                       {\r
+                               // Layer-2 の処理を行う\r
+                               VirtualLayer2(v, packet);\r
+\r
+                               // パケット構造体の解放\r
+                               FreePacket(packet);\r
+                       }\r
+               }\r
+               UnlockVirtual(v);\r
+\r
+               Free(data);\r
+       }\r
+\r
+       return true;\r
+}\r
+bool VirtualPaPutPacket(SESSION *s, void *data, UINT size)\r
+{\r
+       VH *v;\r
+       // 引数チェック\r
+       if (s == NULL || (v = (VH *)s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return VirtualPutPacket(v, data, size);\r
+}\r
+\r
+// 仮想ホストのオプションを取得する\r
+void GetVirtualHostOption(VH *v, VH_OPTION *o)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockVirtual(v);\r
+       {\r
+               Zero(o, sizeof(VH_OPTION));\r
+\r
+               // MAC アドレス\r
+               Copy(o->MacAddress, v->MacAddress, 6);\r
+\r
+               // ホスト情報\r
+               UINTToIP(&o->Ip, v->HostIP);\r
+               UINTToIP(&o->Mask, v->HostMask);\r
+\r
+               o->Mtu = v->Mtu;\r
+\r
+               // NAT タイムアウト情報\r
+               o->NatTcpTimeout = v->NatTcpTimeout / 1000;\r
+               o->NatUdpTimeout = v->NatUdpTimeout / 1000;\r
+\r
+               // NAT 使用フラグ\r
+               o->UseNat = v->UseNat;\r
+\r
+               // DHCP 使用フラグ\r
+               o->UseDhcp = v->UseDhcp;\r
+\r
+               // DHCP 配布 IP アドレス範囲\r
+               UINTToIP(&o->DhcpLeaseIPStart, v->DhcpIpStart);\r
+               UINTToIP(&o->DhcpLeaseIPEnd, v->DhcpIpEnd);\r
+\r
+               // サブネットマスク\r
+               UINTToIP(&o->DhcpSubnetMask, v->DhcpMask);\r
+\r
+               // 有効期限\r
+               if (v->DhcpExpire != INFINITE)\r
+               {\r
+                       o->DhcpExpireTimeSpan = v->DhcpExpire / 1000;\r
+               }\r
+               else\r
+               {\r
+                       o->DhcpExpireTimeSpan = INFINITE;\r
+               }\r
+\r
+               // ゲートウェイアドレス\r
+               UINTToIP(&o->DhcpGatewayAddress, v->DhcpGateway);\r
+\r
+               // DNS サーバーアドレス\r
+               UINTToIP(&o->DhcpDnsServerAddress, v->DhcpDns);\r
+\r
+               // ドメイン名\r
+               StrCpy(o->DhcpDomainName, sizeof(o->DhcpDomainName), v->DhcpDomain);\r
+\r
+               // ログの保存\r
+               o->SaveLog = v->SaveLog;\r
+       }\r
+       UnlockVirtual(v);\r
+}\r
+\r
+// 仮想ホストにオプションを設定する\r
+void SetVirtualHostOption(VH *v, VH_OPTION *vo)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (v == NULL || vo == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockVirtual(v);\r
+       {\r
+               // MAC アドレスを設定する\r
+               for (i = 0;i < 6;i++)\r
+               {\r
+                       if (vo->MacAddress[i] != 0)\r
+                       {\r
+                               Copy(v->MacAddress, vo->MacAddress, 6);\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               // ホスト情報リストを設定する\r
+               v->HostIP = IPToUINT(&vo->Ip);\r
+               v->HostMask = IPToUINT(&vo->Mask);\r
+\r
+               // MTU, MMS を設定する\r
+               v->Mtu = MIN(vo->Mtu, MAX_L3_DATA_SIZE);\r
+               if (v->Mtu == 0)\r
+               {\r
+                       v->Mtu = MAX_L3_DATA_SIZE;\r
+               }\r
+               v->Mtu = MAX(v->Mtu, TCP_HEADER_SIZE + IP_HEADER_SIZE + MAC_HEADER_SIZE + 8);\r
+               v->IpMss = ((v->Mtu - IP_HEADER_SIZE) / 8) * 8;\r
+               v->TcpMss = ((v->IpMss - TCP_HEADER_SIZE) / 8) * 8;\r
+               v->UdpMss = ((v->IpMss - UDP_HEADER_SIZE) / 8) * 8;\r
+\r
+               if (vo->NatTcpTimeout != 0)\r
+               {\r
+                       v->NatTcpTimeout = MIN(vo->NatTcpTimeout, 4000000) * 1000;\r
+               }\r
+               if (vo->NatUdpTimeout != 0)\r
+               {\r
+                       v->NatUdpTimeout = MIN(vo->NatUdpTimeout, 4000000) * 1000;\r
+               }\r
+               v->NatTcpTimeout = MAKESURE(v->NatTcpTimeout, NAT_TCP_MIN_TIMEOUT, NAT_TCP_MAX_TIMEOUT);\r
+               v->NatUdpTimeout = MAKESURE(v->NatUdpTimeout, NAT_UDP_MIN_TIMEOUT, NAT_UDP_MAX_TIMEOUT);\r
+               Debug("Timeout: %d , %d\n", v->NatTcpTimeout, v->NatUdpTimeout);\r
+\r
+               // NAT 使用フラグ\r
+               v->UseNat = vo->UseNat;\r
+\r
+               // DHCP 使用フラグ\r
+               v->UseDhcp = vo->UseDhcp;\r
+\r
+               // 有効期限\r
+               if (vo->DhcpExpireTimeSpan == 0 || vo->DhcpExpireTimeSpan == INFINITE)\r
+               {\r
+                       v->DhcpExpire = INFINITE;\r
+               }\r
+               else\r
+               {\r
+                       v->DhcpExpire = MAKESURE(DHCP_MIN_EXPIRE_TIMESPAN,\r
+                               MIN(vo->DhcpExpireTimeSpan * 1000, 2000000000),\r
+                               INFINITE);\r
+               }\r
+\r
+               // 配布するアドレス範囲\r
+               v->DhcpIpStart = IPToUINT(&vo->DhcpLeaseIPStart);\r
+               v->DhcpIpEnd = IPToUINT(&vo->DhcpLeaseIPEnd);\r
+               if (Endian32(v->DhcpIpEnd) < Endian32(v->DhcpIpStart))\r
+               {\r
+                       v->DhcpIpEnd = v->DhcpIpStart;\r
+               }\r
+\r
+               // サブネットマスク\r
+               v->DhcpMask = IPToUINT(&vo->DhcpSubnetMask);\r
+\r
+               // ゲートウェイアドレス\r
+               v->DhcpGateway = IPToUINT(&vo->DhcpGatewayAddress);\r
+\r
+               // DNS サーバーアドレス\r
+               v->DhcpDns = IPToUINT(&vo->DhcpDnsServerAddress);\r
+\r
+               // ドメイン名\r
+               StrCpy(v->DhcpDomain, sizeof(v->DhcpDomain), vo->DhcpDomainName);\r
+\r
+               // ログの保存\r
+               v->SaveLog = vo->SaveLog;\r
+       }\r
+       UnlockVirtual(v);\r
+}\r
+\r
+// 仮想ホストの解放\r
+void Virtual_Free(VH *v)\r
+{\r
+       // DHCP サーバー解放\r
+       FreeDhcpServer(v);\r
+\r
+       // NAT 解放\r
+       FreeNat(v);\r
+\r
+       LockVirtual(v);\r
+       {\r
+               // IP 結合リスト解放\r
+               FreeIpCombineList(v);\r
+\r
+               // IP 待ちテーブル解放\r
+               FreeIpWaitTable(v);\r
+\r
+               // ARP 待ちテーブル解放\r
+               FreeArpWaitTable(v);\r
+\r
+               // ARP テーブル解放\r
+               FreeArpTable(v);\r
+\r
+               // 送信キュー解放\r
+               LockQueue(v->SendQueue);\r
+               {\r
+                       BLOCK *block;\r
+\r
+                       // すべてのキューを解放する\r
+                       while (block = GetNext(v->SendQueue))\r
+                       {\r
+                               FreeBlock(block);\r
+                       }\r
+               }\r
+               UnlockQueue(v->SendQueue);\r
+               ReleaseQueue(v->SendQueue);\r
+               v->SendQueue = NULL;\r
+\r
+               // キャンセルオブジェクト解放\r
+               ReleaseCancel(v->Cancel);\r
+\r
+               v->Active = false;\r
+       }\r
+       UnlockVirtual(v);\r
+\r
+       // ロガー解放\r
+       FreeLog(v->Logger);\r
+}\r
+void VirtualPaFree(SESSION *s)\r
+{\r
+       VH *v;\r
+       // 引数チェック\r
+       if (s == NULL || (v = (VH *)s->PacketAdapter->Param) == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Virtual_Free(v);\r
+}\r
+\r
+// 仮想ホストの解放\r
+void ReleaseVirtual(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(v->ref) == 0)\r
+       {\r
+               CleanupVirtual(v);\r
+       }\r
+}\r
+\r
+// 仮想ホストのロック\r
+void LockVirtual(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(v->lock);\r
+}\r
+\r
+// 仮想ホストのロック解除\r
+void UnlockVirtual(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Unlock(v->lock);\r
+}\r
+\r
+// 仮想ホストのクリーンアップ\r
+void CleanupVirtual(VH *v)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (v->Session != NULL)\r
+       {\r
+               ReleaseSession(v->Session);\r
+       }\r
+\r
+       DeleteCounter(v->Counter);\r
+       DeleteLock(v->lock);\r
+\r
+       Free(v);\r
+}\r
+\r
+// 仮想ホストの停止\r
+void StopVirtualHost(VH *v)\r
+{\r
+       SESSION *s;\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 仮想ホストに対応したセッションの取得\r
+       LockVirtual(v);\r
+       {\r
+               s = v->Session;\r
+               if (s != NULL)\r
+               {\r
+                       AddRef(s->ref);\r
+               }\r
+       }\r
+       UnlockVirtual(v);\r
+\r
+       if (s == NULL)\r
+       {\r
+               // すでにこのセッションは停止している\r
+               return;\r
+       }\r
+\r
+       // セッションの停止\r
+       StopSession(s);\r
+\r
+       ReleaseSession(s);\r
+}\r
+\r
+// 新しい仮想ホストの作成\r
+VH *NewVirtualHost(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *auth, VH_OPTION *vh_option)\r
+{\r
+       return NewVirtualHostEx(cedar, option, auth, vh_option, NULL);\r
+}\r
+VH *NewVirtualHostEx(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *auth, VH_OPTION *vh_option, NAT *nat)\r
+{\r
+       VH *v;\r
+       // 引数チェック\r
+       if (vh_option == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // VH の作成\r
+       v = ZeroMalloc(sizeof(VH));\r
+       v->ref = NewRef();\r
+       v->lock = NewLock();\r
+       v->Counter = NewCounter();\r
+\r
+       v->nat = nat;\r
+\r
+       // オプションの設定\r
+       SetVirtualHostOption(v, vh_option);\r
+\r
+       return v;\r
+}\r
+\r
+// ランダムな MAC アドレスを生成する\r
+void GenMacAddress(UCHAR *mac)\r
+{\r
+       UCHAR rand_data[32];\r
+       UINT64 now;\r
+       BUF *b;\r
+       UCHAR hash[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (mac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 現在時刻を取得\r
+       now = SystemTime64();\r
+\r
+       // 乱数を生成\r
+       Rand(rand_data, sizeof(rand_data));\r
+\r
+       // バッファに追加\r
+       b = NewBuf();\r
+       WriteBuf(b, &now, sizeof(now));\r
+       WriteBuf(b, rand_data, sizeof(rand_data));\r
+\r
+       // ハッシュ\r
+       Hash(hash, b->Buf, b->Size, true);\r
+\r
+       // MAC アドレスを生成\r
+       mac[0] = 0x00;\r
+       mac[1] = 0xAC;          // AC 万歳\r
+       mac[2] = hash[0];\r
+       mac[3] = hash[1];\r
+       mac[4] = hash[2];\r
+       mac[5] = hash[3];\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// 仮想ホストのパケットアダプタを取得\r
+PACKET_ADAPTER *VirtualGetPacketAdapter()\r
+{\r
+       return NewPacketAdapter(VirtualPaInit, VirtualPaGetCancel,\r
+               VirtualPaGetNextPacket, VirtualPaPutPacket, VirtualPaFree);\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Virtual.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Virtual.h
new file mode 100644 (file)
index 0000000..454adc8
--- /dev/null
@@ -0,0 +1,504 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Virtual.h\r
+// Virtual.c のヘッダ\r
+\r
+#ifndef        VIRTUAL_H\r
+#define        VIRTUAL_H\r
+\r
+\r
+// ARP エントリ\r
+struct ARP_ENTRY\r
+{\r
+       UINT IpAddress;                                 // IP アドレス\r
+       UCHAR MacAddress[6];                    // MAC アドレス\r
+       UCHAR Padding[2];\r
+       UINT64 Created;                                 // 作成日時\r
+       UINT64 Expire;                                  // 有効期限\r
+};\r
+\r
+// ARP 待機リスト\r
+struct ARP_WAIT\r
+{\r
+       UINT IpAddress;                                 // 解決しようとしている IP アドレス\r
+       UINT NextTimeoutTimeValue;              // 次にタイムアウトするまでの時間\r
+       UINT64 TimeoutTime;                             // 現在の送信のタイムアウト時刻\r
+       UINT64 GiveupTime;                              // 送信を諦める時刻\r
+};\r
+\r
+// IP 待機リスト\r
+struct IP_WAIT\r
+{\r
+       UINT DestIP;                                    // 宛先 IP アドレス\r
+       UINT SrcIP;                                             // 送信元 IP アドレス\r
+       UINT64 Expire;                                  // 保管期限\r
+       void *Data;                                             // データ\r
+       UINT Size;                                              // サイズ\r
+};\r
+\r
+// IP 部分リスト\r
+struct IP_PART\r
+{\r
+       UINT Offset;                                    // オフセット\r
+       UINT Size;                                              // サイズ\r
+};\r
+\r
+// IP 復元リスト\r
+struct IP_COMBINE\r
+{\r
+       UINT DestIP;                                    // 宛先 IP アドレス\r
+       UINT SrcIP;                                             // 送信元 IP アドレス\r
+       USHORT Id;                                              // IP パケット ID\r
+       UINT64 Expire;                                  // 保管期限\r
+       void *Data;                                             // パケットデータ\r
+       UINT DataReserved;                              // データ用に確保された領域\r
+       UINT Size;                                              // パケットサイズ (トータル)\r
+       LIST *IpParts;                                  // IP 部分リスト\r
+       UCHAR Protocol;                                 // プロトコル番号\r
+       bool MacBroadcast;                              // MAC レベルでのブロードキャストパケット\r
+};\r
+\r
+#define        IP_COMBINE_INITIAL_BUF_SIZE             (MAX_IP_DATA_SIZE)              // 初期バッファサイズ\r
+\r
+// NAT セッションテーブル\r
+struct NAT_ENTRY\r
+{\r
+       // TCP | UDP 共通項目\r
+       struct VH *v;                                   // 仮想マシン\r
+       UINT Id;                                                // ID\r
+       LOCK *lock;                                             // ロック\r
+       UINT Protocol;                                  // プロトコル\r
+       UINT SrcIp;                                             // 接続元 IP アドレス\r
+       UINT SrcPort;                                   // 接続元ポート番号\r
+       UINT DestIp;                                    // 接続先 IP アドレス\r
+       UINT DestPort;                                  // 接続先ポート番号\r
+       UINT PublicIp;                                  // 公衆 IP アドレス\r
+       UINT PublicPort;                                // 公衆ポート番号\r
+       UINT64 CreatedTime;                             // 接続時刻\r
+       UINT64 LastCommTime;                    // 最終通信時刻\r
+       SOCK *Sock;                                             // ソケット\r
+       bool DisconnectNow;                             // すぐに停止せよフラグ\r
+       UINT tag1;\r
+       bool ProxyDns;                                  // プロキシ DNS\r
+       UINT DestIpProxy;                               // プロキシ DNS アドレス\r
+\r
+       // DNS NAT 項目\r
+       THREAD *DnsThread;                              // DNS 問い合わせ用スレッド\r
+       bool DnsGetIpFromHost;                  // 逆引きフラグ\r
+       char *DnsTargetHostName;                // ターゲットホスト名\r
+       IP DnsResponseIp;                               // 応答 IP アドレス\r
+       char *DnsResponseHostName;              // 応答ホスト名\r
+       UINT DnsTransactionId;                  // DNS トランザクション ID\r
+       bool DnsFinished;                               // DNS 問い合わせ完了フラグ\r
+       bool DnsOk;                                             // DNS 成功フラグ\r
+       bool DnsPollingFlag;                    // DNS ポーリング完了フラグ\r
+\r
+       // UDP 項目\r
+       QUEUE *UdpSendQueue;                    // UDP 送信キュー\r
+       QUEUE *UdpRecvQueue;                    // UDP 受信キュー\r
+       bool UdpSocketCreated;                  // UDP のソケットが作成されたかどうか\r
+\r
+       // TCP 項目\r
+       FIFO *SendFifo;                                 // 送信 FIFO\r
+       FIFO *RecvFifo;                                 // 受信 FIFO\r
+       UINT TcpStatus;                                 // TCP 状態\r
+       THREAD *NatTcpConnectThread;    // TCP ソケット接続スレッド\r
+       bool TcpMakeConnectionFailed;   // 接続スレッドによる接続に失敗した\r
+       bool TcpMakeConnectionSucceed;  // 接続スレッドによる接続に成功した\r
+       UINT TcpSendMaxSegmentSize;             // 最大送信セグメントサイズ\r
+       UINT TcpRecvMaxSegmentSize;             // 最大受信セグメントサイズ\r
+       UINT64 LastSynAckSentTime;              // 最後に SYN + ACK を送信した時刻\r
+       UINT SynAckSentCount;                   // SYN + ACK 送信回数\r
+       UINT TcpSendWindowSize;                 // 送信ウインドウサイズ\r
+       UINT TcpSendCWnd;                               // 送信用輻輳ウインドウサイズ (/mss)\r
+       UINT TcpRecvWindowSize;                 // 受信ウインドウサイズ\r
+       UINT TcpSendTimeoutSpan;                // 送信タイムアウト時間\r
+       UINT64 TcpLastSentTime;                 // TCP で最後に送信を行った時刻\r
+       UINT64 LastSentKeepAliveTime;   // 最後にキープアライブ ACK を送信した時刻\r
+       FIFO *TcpRecvWindow;                    // TCP 受信ウインドウ\r
+       LIST *TcpRecvList;                              // TCP 受信リスト\r
+       bool SendAckNext;                               // 次の送信時に ACK を送信する\r
+       UINT LastSentWindowSize;                // 最後に送信した自分のウインドウサイズ\r
+\r
+       UINT64 SendSeqInit;                             // 初期送信シーケンス番号\r
+       UINT64 SendSeq;                                 // 送信シーケンス番号\r
+       UINT64 RecvSeqInit;                             // 初期受信シーケンス番号\r
+       UINT64 RecvSeq;                                 // 受信シーケンス番号\r
+\r
+       bool CurrentSendingMission;             // バースト送信実施中\r
+       UINT SendMissionSize;                   // 今回の送信サイズ\r
+       bool RetransmissionUsedFlag;    // 再送信使用記録フラグ\r
+\r
+       UINT CurrentRTT;                                // 現在の RTT 値\r
+       UINT64 CalcRTTStartTime;                // RTT 測定開始時刻\r
+       UINT64 CalcRTTStartValue;               // RTT 測定開始値\r
+\r
+       bool TcpFinished;                               // TCP のデータ通信終了フラグ\r
+       UINT64 FinSentTime;                             // 最後に FIN を送信した時刻\r
+       UINT FinSentCount;                              // FIN 送信回数\r
+};\r
+\r
+\r
+// TCP オプション\r
+struct TCP_OPTION\r
+{\r
+       UINT MaxSegmentSize;                    // 最大セグメントサイズ\r
+       UINT WindowScaling;                             // ウインドウスケーリング\r
+};\r
+\r
+// 仮想ホスト構造体\r
+struct VH\r
+{\r
+       REF *ref;                                               // 参照カウンタ\r
+       LOCK *lock;                                             // ロック\r
+       SESSION *Session;                               // セッション\r
+       CANCEL *Cancel;                                 // キャンセルオブジェクト\r
+       QUEUE *SendQueue;                               // 送信キュー\r
+       bool Active;                                    // アクティブフラグ\r
+       volatile bool HaltNat;                  // NAT 停止フラグ\r
+       LIST *ArpTable;                                 // ARP テーブル\r
+       LIST *ArpWaitTable;                             // ARP 待ちテーブル\r
+       LIST *IpWaitTable;                              // IP 待ちテーブル\r
+       LIST *IpCombine;                                // IP 結合テーブル\r
+       UINT64 Now;                                             // 現在時刻\r
+       UINT64 NextArpTablePolling;             // 次に ARP テーブルをポーリングする時刻\r
+       UINT Mtu;                                               // MTU 値\r
+       UINT IpMss;                                             // IP 最大データサイズ\r
+       UINT TcpMss;                                    // TCP 最大データサイズ\r
+       UINT UdpMss;                                    // UDP 最大データサイズ\r
+       bool flag1;                                             // フラグ 1\r
+       bool flag2;                                             // フラグ 2\r
+       USHORT NextId;                                  // IP パケットの ID\r
+       UINT CurrentIpQuota;                    // IP パケットメモリクォータ\r
+       LIST *NatTable;                                 // NAT テーブル\r
+       SOCK_EVENT *SockEvent;                  // ソケットイベント\r
+       THREAD *NatThread;                              // NAT 用スレッド\r
+       void *TmpBuf;                                   // 一時的に使用できるバッファ\r
+       bool NatDoCancelFlag;                   // キャンセルを叩くかどうかのフラグ\r
+       UCHAR MacAddress[6];                    // MAC アドレス\r
+       UCHAR Padding[2];\r
+       UINT HostIP;                                    // ホスト IP\r
+       UINT HostMask;                                  // ホストサブネットマスク\r
+       UINT NatTcpTimeout;                             // NAT TCP タイムアウト秒数\r
+       UINT NatUdpTimeout;                             // NAT UDP タイムアウト秒数\r
+       bool UseNat;                                    // NAT 使用フラグ\r
+       bool UseDhcp;                                   // DHCP 使用フラグ\r
+       UINT DhcpIpStart;                               // 配布開始アドレス\r
+       UINT DhcpIpEnd;                                 // 配布終了アドレス\r
+       UINT DhcpMask;                                  // サブネットマスク\r
+       UINT DhcpExpire;                                // アドレス配布有効期限\r
+       UINT DhcpGateway;                               // ゲートウェイアドレス\r
+       UINT DhcpDns;                                   // DNS サーバーアドレス\r
+       char DhcpDomain[MAX_HOST_NAME_LEN + 1]; // 割り当てドメイン名\r
+       LIST *DhcpLeaseList;                    // DHCP リースリスト\r
+       UINT64 LastDhcpPolling;                 // 最後に DHCP リストをポーリングした時刻\r
+       bool SaveLog;                                   // ログの保存\r
+       COUNTER *Counter;                               // セッションカウンタ\r
+       UINT DhcpId;                                    // DHCP ID\r
+       UINT64 LastSendBeacon;                  // 最後にビーコンを発信した時刻\r
+       LOG *Logger;                                    // ロガー\r
+       NAT *nat;                                               // NAT オブジェクトへの参照\r
+};\r
+\r
+// 仮想ホストオプション\r
+struct VH_OPTION\r
+{\r
+       char HubName[MAX_HUBNAME_LEN + 1];      // 操作対象の仮想 HUB 名\r
+       UCHAR MacAddress[6];                    // MAC アドレス\r
+       UCHAR Padding[2];\r
+       IP Ip;                                                  // IP アドレス\r
+       IP Mask;                                                // サブネットマスク\r
+       bool UseNat;                                    // NAT 機能の使用フラグ\r
+       UINT Mtu;                                               // MTU 値\r
+       UINT NatTcpTimeout;                             // NAT TCP タイムアウト秒数\r
+       UINT NatUdpTimeout;                             // NAT UDP タイムアウト秒数\r
+       bool UseDhcp;                                   // DHCP 機能の使用フラグ\r
+       IP DhcpLeaseIPStart;                    // DHCP 配布 IP 開始アドレス\r
+       IP DhcpLeaseIPEnd;                              // DHCP 配布 IP 終了アドレス\r
+       IP DhcpSubnetMask;                              // DHCP サブネットマスク\r
+       UINT DhcpExpireTimeSpan;                // DHCP 有効期限\r
+       IP DhcpGatewayAddress;                  // 割り当てゲートウェイアドレス\r
+       IP DhcpDnsServerAddress;                // 割り当て DNS サーバーアドレス\r
+       char DhcpDomainName[MAX_HOST_NAME_LEN + 1];     // 割り当てドメイン名\r
+       bool SaveLog;                                   // ログの保存\r
+};\r
+\r
+// DHCP オプション\r
+struct DHCP_OPTION\r
+{\r
+       UINT Id;                                                // ID\r
+       UINT Size;                                              // サイズ\r
+       void *Data;                                             // データ\r
+};\r
+\r
+// DHCP オプションリスト\r
+struct DHCP_OPTION_LIST\r
+{\r
+       // 共通項目\r
+       UINT Opcode;                                    // DHCP オペコード\r
+\r
+       // クライアント要求\r
+       UINT RequestedIp;                               // 要求された IP アドレス\r
+       char Hostname[MAX_HOST_NAME_LEN + 1]; // ホスト名\r
+\r
+       // サーバー応答\r
+       UINT ServerAddress;                             // DHCP サーバーアドレス\r
+       UINT LeaseTime;                                 // リース時間\r
+       char DomainName[MAX_HOST_NAME_LEN + 1]; // ドメイン名\r
+       UINT SubnetMask;                                // サブネットマスク\r
+       UINT Gateway;                                   // ゲートウェイアドレス\r
+       UINT DnsServer;                                 // DNS サーバーアドレス\r
+};\r
+\r
+\r
+// DHCP リース エントリ\r
+struct DHCP_LEASE\r
+{\r
+       UINT Id;                                                // ID\r
+       UINT64 LeasedTime;                              // リースした時刻\r
+       UINT64 ExpireTime;                              // 有効期限\r
+       UCHAR MacAddress[6];                    // MAC アドレス\r
+       UCHAR Padding[2];                               // Padding\r
+       UINT IpAddress;                                 // IP アドレス\r
+       UINT Mask;                                              // サブネットマスク\r
+       char *Hostname;                                 // ホスト名\r
+};\r
+\r
+// DNS 問い合わせ\r
+typedef struct NAT_DNS_QUERY\r
+{\r
+       REF *ref;                                               // 参照カウンタ\r
+       char Hostname[256];                             // ホスト名\r
+       bool Ok;                                                // 結果の成功フラグ\r
+       IP Ip;                                                  // 結果 IP アドレス\r
+} NAT_DNS_QUERY;\r
+\r
+\r
+// 仮想ホストの仮想 LAN カード\r
+PACKET_ADAPTER *VirtualGetPacketAdapter();\r
+bool VirtualPaInit(SESSION *s);\r
+CANCEL *VirtualPaGetCancel(SESSION *s);\r
+UINT VirtualPaGetNextPacket(SESSION *s, void **data);\r
+bool VirtualPaPutPacket(SESSION *s, void *data, UINT size);\r
+void VirtualPaFree(SESSION *s);\r
+\r
+bool VirtualInit(VH *v);\r
+UINT VirtualGetNextPacket(VH *v, void **data);\r
+bool VirtualPutPacket(VH *v, void *data, UINT size);\r
+void Virtual_Free(VH *v);\r
+\r
+VH *NewVirtualHost(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *auth, VH_OPTION *vh_option);\r
+VH *NewVirtualHostEx(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *auth, VH_OPTION *vh_option, NAT *nat);\r
+void LockVirtual(VH *v);\r
+void UnlockVirtual(VH *v);\r
+void ReleaseVirtual(VH *v);\r
+void CleanupVirtual(VH *v);\r
+void StopVirtualHost(VH *v);\r
+void SetVirtualHostOption(VH *v, VH_OPTION *vo);\r
+void GenMacAddress(UCHAR *mac);\r
+void GetVirtualHostOption(VH *v, VH_OPTION *o);\r
+\r
+void VirtualLayer2(VH *v, PKT *packet);\r
+bool VirtualLayer2Filter(VH *v, PKT *packet);\r
+void VirtualArpReceived(VH *v, PKT *packet);\r
+void VirtualArpResponseRequest(VH *v, PKT *packet);\r
+void VirtualArpResponseReceived(VH *v, PKT *packet);\r
+void VirtualArpSendResponse(VH *v, UCHAR *dest_mac, UINT dest_ip, UINT src_ip);\r
+void VirtualArpSendRequest(VH *v, UINT dest_ip);\r
+void VirtualIpSend(VH *v, UCHAR *dest_mac, void *data, UINT size);\r
+void VirtualLayer2Send(VH *v, UCHAR *dest_mac, UCHAR *src_mac, USHORT protocol, void *data, UINT size);\r
+void VirtualPolling(VH *v);\r
+void InitArpTable(VH *v);\r
+void FreeArpTable(VH *v);\r
+int CompareArpTable(void *p1, void *p2);\r
+ARP_ENTRY *SearchArpTable(VH *v, UINT ip);\r
+void RefreshArpTable(VH *v);\r
+void PollingArpTable(VH *v);\r
+void InsertArpTable(VH *v, UCHAR *mac, UINT ip);\r
+bool IsMacBroadcast(UCHAR *mac);\r
+bool IsMacInvalid(UCHAR *mac);\r
+void InitArpWaitTable(VH *v);\r
+void FreeArpWaitTable(VH *v);\r
+int CompareArpWaitTable(void *p1, void *p2);\r
+ARP_WAIT *SearchArpWaitTable(VH *v, UINT ip);\r
+void DeleteArpWaitTable(VH *v, UINT ip);\r
+void SendArp(VH *v, UINT ip);\r
+void InsertArpWaitTable(VH *v, ARP_WAIT *w);\r
+void PollingArpWaitTable(VH *v);\r
+void ArpIpWasKnown(VH *v, UINT ip, UCHAR *mac);\r
+void InitIpWaitTable(VH *v);\r
+void FreeIpWaitTable(VH *v);\r
+void InsertIpWaitTable(VH *v, UINT dest_ip, UINT src_ip, void *data, UINT size);\r
+void SendFragmentedIp(VH *v, UINT dest_ip, UINT src_ip, USHORT id, USHORT total_size, USHORT offset, UCHAR protocol, void *data, UINT size, UCHAR *dest_mac);\r
+void SendIp(VH *v, UINT dest_ip, UINT src_ip, UCHAR protocol, void *data, UINT size);\r
+void PollingIpWaitTable(VH *v);\r
+void DeleteOldIpWaitTable(VH *v);\r
+void SendWaitingIp(VH *v, UCHAR *mac, UINT dest_ip);\r
+void VirtualIpReceived(VH *v, PKT *packet);\r
+void InitIpCombineList(VH *v);\r
+void FreeIpCombineList(VH *v);\r
+int CompareIpCombine(void *p1, void *p2);\r
+void CombineIp(VH *v, IP_COMBINE *c, UINT offset, void *data, UINT size, bool last_packet);\r
+void IpReceived(VH *v, UINT src_ip, UINT dest_ip, UINT protocol, void *data, UINT size, bool mac_broadcast);\r
+void FreeIpCombine(VH *v, IP_COMBINE *c);\r
+void PollingIpCombine(VH *v);\r
+IP_COMBINE *InsertIpCombine(VH *v, UINT src_ip, UINT dest_ip, USHORT id, UCHAR protocol, bool mac_broadcast);\r
+IP_COMBINE *SearchIpCombine(VH *v, UINT src_ip, UINT dest_ip, USHORT id, UCHAR protocol);\r
+USHORT IpChecksum(void *buf, UINT size);\r
+bool IpCheckChecksum(IPV4_HEADER *ip);\r
+void VirtualIcmpReceived(VH *v, UINT src_ip, UINT dst_ip, void *data, UINT size);\r
+void VirtualIcmpEchoRequestReceived(VH *v, UINT src_ip, UINT dst_ip, void *data, UINT size);\r
+void VirtualIcmpEchoSendResponse(VH *v, UINT src_ip, UINT dst_ip, USHORT id, USHORT seq_no, void *data, UINT size);\r
+void VirtualIcmpSend(VH *v, UINT src_ip, UINT dst_ip, void *data, UINT size);\r
+void VirtualUdpReceived(VH *v, UINT src_ip, UINT dest_ip, void *data, UINT size, bool mac_broadcast);\r
+void SendUdp(VH *v, UINT dest_ip, UINT dest_port, UINT src_ip, UINT src_port, void *data, UINT size);\r
+UINT GetNetworkAddress(UINT addr, UINT mask);\r
+UINT GetBroadcastAddress(UINT addr, UINT mask);\r
+bool IsInNetwork(UINT uni_addr, UINT network_addr, UINT mask);\r
+void UdpRecvForMe(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, void *data, UINT size);\r
+void UdpRecvForBroadcast(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, void *data, UINT size);\r
+void UdpRecvForInternet(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, void *data, UINT size, bool dns_proxy);\r
+void InitNat(VH *v);\r
+void FreeNat(VH *v);\r
+int CompareNat(void *p1, void *p2);\r
+NAT_ENTRY *SearchNat(VH *v, NAT_ENTRY *target);\r
+void SetNat(NAT_ENTRY *n, UINT protocol, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, UINT public_ip, UINT public_port);\r
+void DeleteNatTcp(VH *v, NAT_ENTRY *n);\r
+void DeleteNatUdp(VH *v, NAT_ENTRY *n);\r
+NAT_ENTRY *CreateNatUdp(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, UINT dns_proxy_ip);\r
+void NatThread(THREAD *t, void *param);\r
+void NatThreadMain(VH *v);\r
+bool NatTransactUdp(VH *v, NAT_ENTRY *n);\r
+void PoolingNat(VH *v);\r
+void PoolingNatUdp(VH *v, NAT_ENTRY *n);\r
+void VirtualTcpReceived(VH *v, UINT src_ip, UINT dest_ip, void *data, UINT size);\r
+void TcpRecvForInternet(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, TCP_HEADER *tcp, void *data, UINT size);\r
+NAT_ENTRY *CreateNatTcp(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port);\r
+bool NatTransactTcp(VH *v, NAT_ENTRY *n);\r
+void CreateNatTcpConnectThread(VH *v, NAT_ENTRY *n);\r
+void NatTcpConnectThread(THREAD *t, void *p);\r
+void PollingNatTcp(VH *v, NAT_ENTRY *n);\r
+void ParseTcpOption(TCP_OPTION *o, void *data, UINT size);\r
+void SendTcp(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, UINT seq, UINT ack, UINT flag, UINT window_size, UINT mss, void *data, UINT size);\r
+void DnsProxy(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, void *data, UINT size);\r
+bool ParseDnsPacket(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port, void *data, UINT size);\r
+bool ParseDnsQuery(char *name, UINT name_size, void *data, UINT data_size);\r
+UCHAR GetNextByte(BUF *b);\r
+bool NatTransactDns(VH *v, NAT_ENTRY *n);\r
+void NatDnsThread(THREAD *t, void *param);\r
+bool NatGetIP(IP *ip, char *hostname);\r
+void NatGetIPThread(THREAD *t, void *param);\r
+NAT_ENTRY *CreateNatDns(VH *v, UINT src_ip, UINT src_port, UINT dest_ip, UINT dest_port,\r
+                                 UINT transaction_id, bool dns_get_ip_from_host, char *dns_target_host_name);\r
+void PollingNatDns(VH *v, NAT_ENTRY *n);\r
+void SendNatDnsResponse(VH *v, NAT_ENTRY *n);\r
+void BuildDnsQueryPacket(BUF *b, char *hostname, bool ptr);\r
+void BuildDnsResponsePacketA(BUF *b, IP *ip);\r
+void BuildDnsResponsePacketPtr(BUF *b, char *hostname);\r
+bool ArpaToIP(IP *ip, char *str);\r
+BUF *BuildDnsHostName(char *hostname);\r
+bool CanCreateNewNatEntry(VH *v);\r
+void VirtualDhcpServer(VH *v, PKT *p);\r
+LIST *ParseDhcpOptions(void *data, UINT size);\r
+void FreeDhcpOptions(LIST *o);\r
+DHCP_OPTION *GetDhcpOption(LIST *o, UINT id);\r
+DHCP_OPTION_LIST *ParseDhcpOptionList(void *data, UINT size);\r
+void InitDhcpServer(VH *v);\r
+void FreeDhcpServer(VH *v);\r
+void PollingDhcpServer(VH *v);\r
+int CompareDhcpLeaseList(void *p1, void *p2);\r
+DHCP_LEASE *NewDhcpLease(UINT expire, UCHAR *mac_address, UINT ip, UINT mask, char *hostname);\r
+void FreeDhcpLease(DHCP_LEASE *d);\r
+DHCP_LEASE *SearchDhcpLeaseByMac(VH *v, UCHAR *mac);\r
+DHCP_LEASE *SearchDhcpLeaseByIp(VH *v, UINT ip);\r
+UINT ServeDhcpDiscover(VH *v, UCHAR *mac, UINT request_ip);\r
+UINT GetFreeDhcpIpAddress(VH *v);\r
+UINT ServeDhcpRequest(VH *v, UCHAR *mac, UINT request_ip);\r
+LIST *BuildDhcpOption(DHCP_OPTION_LIST *opt);\r
+DHCP_OPTION *NewDhcpOption(UINT id, void *data, UINT size);\r
+BUF *BuildDhcpOptionsBuf(LIST *o);\r
+void VirtualDhcpSend(VH *v, UINT tran_id, UINT dest_ip, UINT dest_port,\r
+                                        UINT new_ip, UCHAR *client_mac, BUF *b);\r
+void VLog(VH *v, char *str);\r
+void SendBeacon(VH *v);\r
+void PollingBeacon(VH *v);\r
+\r
+\r
+#endif // VIRTUAL_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Win32Html.cpp b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Win32Html.cpp
new file mode 100644 (file)
index 0000000..24d19bd
--- /dev/null
@@ -0,0 +1,731 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Win32Html.c\r
+// Win32 用 HTML 表示モジュール\r
+\r
+// Q. ソースコード名が「HTML」となっているが、どう見ても HTML に関係のない処理\r
+//    が入っているように見える。\r
+// A. はい。\r
+\r
+#ifdef WIN32\r
+\r
+#define        WIN32HTML_CPP\r
+\r
+//#define      _WIN32_WINNT            0x0502\r
+//#define      WINVER                          0x0502\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+#include <wincrypt.h>\r
+#include <wininet.h>\r
+#include <comdef.h>\r
+#include <Mshtmhst.h>\r
+#include <shlobj.h>\r
+#include <commctrl.h>\r
+#include <Dbghelp.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+extern "C"\r
+{\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+}\r
+#include "../PenCore/resource.h"\r
+\r
+typedef struct FOLDER_DLG_INNER_DATA\r
+{\r
+       wchar_t *default_dir;\r
+} FOLDER_DLG_INNER_DATA;\r
+\r
+int CALLBACK FolderDlgInnerCallbackA(HWND hWnd, UINT msg, LPARAM lParam, LPARAM lData)\r
+{\r
+       FOLDER_DLG_INNER_DATA *data = (FOLDER_DLG_INNER_DATA *)lData;\r
+       LPITEMIDLIST pidl;\r
+\r
+       switch (msg)\r
+       {\r
+       case BFFM_INITIALIZED:\r
+               if (data->default_dir != NULL)\r
+               {\r
+                       char *default_dir_a = CopyUniToStr(data->default_dir);\r
+\r
+                       SendMessage(hWnd, BFFM_SETSELECTIONA, true, (LPARAM)default_dir_a);\r
+\r
+                       Free(default_dir_a);\r
+               }\r
+               break;\r
+\r
+       case BFFM_SELCHANGED:\r
+               pidl = (LPITEMIDLIST)lParam;\r
+\r
+               if (pidl)\r
+               {\r
+                       char tmp[MAX_PATH];\r
+\r
+                       Zero(tmp, sizeof(tmp));\r
+                       if (SHGetPathFromIDListA(pidl, tmp))\r
+                       {\r
+                               SendMessage(hWnd, BFFM_ENABLEOK, 0, 1);\r
+                       }\r
+                       else\r
+                       {\r
+                               SendMessage(hWnd, BFFM_ENABLEOK, 0, 0);\r
+                       }\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+char *FolderDlgInnerA(HWND hWnd, wchar_t *title, char *default_dir)\r
+{\r
+       BROWSEINFOA info;\r
+       char display_name[MAX_PATH];\r
+       FOLDER_DLG_INNER_DATA data;\r
+       LPMALLOC pMalloc;\r
+       char *ret = NULL;\r
+       char *title_a;\r
+       if (UniIsEmptyStr(title))\r
+       {\r
+               title = NULL;\r
+       }\r
+       if (IsEmptyStr(default_dir))\r
+       {\r
+               default_dir = NULL;\r
+       }\r
+\r
+       Zero(&data, sizeof(data));\r
+       data.default_dir = CopyStrToUni(default_dir);\r
+\r
+       Zero(display_name, sizeof(display_name));\r
+       Zero(&info, sizeof(info));\r
+       info.hwndOwner = hWnd;\r
+       info.pidlRoot = NULL;\r
+       info.pszDisplayName = display_name;\r
+       title_a = CopyUniToStr(title);\r
+       info.lpszTitle = title_a;\r
+       info.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_VALIDATE | BIF_SHAREABLE;\r
+       info.lpfn = FolderDlgInnerCallbackA;\r
+       info.lParam = (LPARAM)&data;\r
+\r
+       if (SUCCEEDED(SHGetMalloc(&pMalloc)))\r
+       {\r
+               LPITEMIDLIST pidl;\r
+\r
+               pidl = SHBrowseForFolderA(&info);\r
+\r
+               if (pidl)\r
+               {\r
+                       char tmp[MAX_PATH];\r
+\r
+                       if (SHGetPathFromIDListA(pidl, tmp))\r
+                       {\r
+                               ret = CopyStr(tmp);\r
+                       }\r
+\r
+                       pMalloc->Free(pidl);\r
+               }\r
+\r
+               pMalloc->Release();\r
+       }\r
+\r
+       Free(data.default_dir);\r
+       Free(title_a);\r
+\r
+       return ret;\r
+}\r
+\r
+int CALLBACK FolderDlgInnerCallbackW(HWND hWnd, UINT msg, LPARAM lParam, LPARAM lData)\r
+{\r
+       FOLDER_DLG_INNER_DATA *data = (FOLDER_DLG_INNER_DATA *)lData;\r
+       LPITEMIDLIST pidl;\r
+\r
+       switch (msg)\r
+       {\r
+       case BFFM_INITIALIZED:\r
+               if (data->default_dir != NULL)\r
+               {\r
+                       SendMessage(hWnd, BFFM_SETSELECTIONW, true, (LPARAM)data->default_dir);\r
+               }\r
+               break;\r
+\r
+       case BFFM_SELCHANGED:\r
+               pidl = (LPITEMIDLIST)lParam;\r
+\r
+               if (pidl)\r
+               {\r
+                       wchar_t tmp[MAX_PATH];\r
+\r
+                       Zero(tmp, sizeof(tmp));\r
+                       if (SHGetPathFromIDListW(pidl, tmp))\r
+                       {\r
+                               SendMessage(hWnd, BFFM_ENABLEOK, 0, 1);\r
+                       }\r
+                       else\r
+                       {\r
+                               SendMessage(hWnd, BFFM_ENABLEOK, 0, 0);\r
+                       }\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+wchar_t *FolderDlgInnerW(HWND hWnd, wchar_t *title, wchar_t *default_dir)\r
+{\r
+       BROWSEINFOW info;\r
+       wchar_t display_name[MAX_PATH];\r
+       FOLDER_DLG_INNER_DATA data;\r
+       LPMALLOC pMalloc;\r
+       wchar_t *ret = NULL;\r
+       if (UniIsEmptyStr(title))\r
+       {\r
+               title = NULL;\r
+       }\r
+       if (UniIsEmptyStr(default_dir))\r
+       {\r
+               default_dir = NULL;\r
+       }\r
+\r
+       Zero(&data, sizeof(data));\r
+       data.default_dir = default_dir;\r
+\r
+       Zero(display_name, sizeof(display_name));\r
+       Zero(&info, sizeof(info));\r
+       info.hwndOwner = hWnd;\r
+       info.pidlRoot = NULL;\r
+       info.pszDisplayName = display_name;\r
+       info.lpszTitle = title;\r
+       info.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_VALIDATE | BIF_SHAREABLE;\r
+       info.lpfn = FolderDlgInnerCallbackW;\r
+       info.lParam = (LPARAM)&data;\r
+\r
+       if (SUCCEEDED(SHGetMalloc(&pMalloc)))\r
+       {\r
+               LPITEMIDLIST pidl;\r
+\r
+               pidl = SHBrowseForFolderW(&info);\r
+\r
+               if (pidl)\r
+               {\r
+                       wchar_t tmp[MAX_PATH];\r
+\r
+                       if (SHGetPathFromIDListW(pidl, tmp))\r
+                       {\r
+                               ret = CopyUniStr(tmp);\r
+                       }\r
+\r
+                       pMalloc->Free(pidl);\r
+               }\r
+\r
+               pMalloc->Release();\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+\r
+class CModule\r
+{\r
+public:\r
+    CModule()\r
+    {\r
+        m_hInstLib = NULL;\r
+    }\r
+    CModule( HINSTANCE hInstLib )\r
+    {\r
+        m_hInstLib = NULL;\r
+        this->Attach( hInstLib );\r
+    }\r
+    CModule( LPCTSTR pszModuleName )\r
+    {\r
+        m_hInstLib = NULL;\r
+        this->LoadLibrary( pszModuleName );\r
+    }\r
+    virtual ~CModule()\r
+    {\r
+        this->FreeLibrary();\r
+    }\r
+\r
+public:\r
+    BOOL Attach( HINSTANCE hInstLib )\r
+    {\r
+        this->FreeLibrary();\r
+        m_hInstLib = hInstLib;\r
+       \r
+        return TRUE;\r
+    }\r
+    BOOL Detach()\r
+    {\r
+        m_hInstLib = NULL;\r
+       \r
+        return TRUE;\r
+    }\r
+\r
+public:\r
+    HMODULE GetHandle()\r
+    {\r
+        return m_hInstLib;\r
+    }\r
+    // DLLのロード\r
+    HINSTANCE LoadLibrary( LPCTSTR pszModuleName )\r
+    {\r
+        this->FreeLibrary();\r
+        m_hInstLib = ::LoadLibrary( pszModuleName );\r
+       \r
+        return m_hInstLib;\r
+    }\r
+    // DLLの開放\r
+    BOOL FreeLibrary()\r
+    {\r
+        if (m_hInstLib == NULL)\r
+        {\r
+            return FALSE;\r
+        }\r
+       \r
+        BOOL bResult = ::FreeLibrary( m_hInstLib );\r
+        m_hInstLib = NULL;\r
+       \r
+        return bResult;\r
+    }\r
+    // 関数のアドレスの取得\r
+    FARPROC GetProcAddress( LPCTSTR pszProcName )\r
+    {\r
+        if (m_hInstLib == NULL)\r
+        {\r
+            return NULL;\r
+        }\r
+       \r
+        return ::GetProcAddress(m_hInstLib, pszProcName);\r
+    }\r
+    // 指定されたタイプおよび名前を持つリソースの情報ブロックのハンドルを取得\r
+    HRSRC FindResource(LPCTSTR lpName, LPCTSTR lpType)\r
+    {\r
+        if (m_hInstLib == NULL)\r
+        {\r
+            return NULL;\r
+        }\r
+       \r
+        return ::FindResource(m_hInstLib, lpName, lpType);\r
+    }\r
+    // 指定されたリソースのロード\r
+    HGLOBAL LoadResource(HRSRC hResInfo)\r
+    {\r
+        if (m_hInstLib == NULL)\r
+        {\r
+            return NULL;\r
+        }\r
+       \r
+        return ::LoadResource(m_hInstLib, hResInfo);\r
+    }\r
+\r
+protected:\r
+    HINSTANCE m_hInstLib;\r
+};\r
+\r
+\r
+\r
+static HRESULT _ShowHTMLDialog(\r
+    HWND hwndParent,\r
+    IMoniker* pMk,\r
+    VARIANT* pvarArgIn = NULL,\r
+    WCHAR* pchOptions = NULL,\r
+    VARIANT* pvarArgOut = NULL)\r
+{\r
+    HRESULT hr = S_OK;\r
+   \r
+    try\r
+    {\r
+        CModule Module("MSHTML.DLL");\r
+        if (Module.GetHandle() == NULL)\r
+        {\r
+            return E_FAIL;\r
+        }\r
+       \r
+        SHOWHTMLDIALOGFN* fnShowHTMLDialog =\r
+            (SHOWHTMLDIALOGFN*)Module.GetProcAddress("ShowHTMLDialog");\r
+        if (fnShowHTMLDialog == NULL)\r
+        {\r
+            return E_FAIL;\r
+        }\r
+       \r
+        hr = (*fnShowHTMLDialog)(hwndParent, pMk, pvarArgIn, pchOptions, pvarArgOut);\r
+        if (FAILED(hr))\r
+        {\r
+            return hr;\r
+        }\r
+    }\r
+    catch (...)\r
+    {\r
+        return E_FAIL;\r
+    }\r
+   \r
+    return hr;\r
+}\r
+\r
+HRESULT ShowHTMLDialogFromURL(HWND hwndParent,wchar_t *szURL,VARIANT* pvarArgIn,WCHAR* pchOptions,VARIANT* pvarArgOut)\r
+{\r
+    HRESULT hr = S_OK;\r
+   \r
+    try\r
+    {\r
+        IMonikerPtr spMoniker;\r
+        hr = ::CreateURLMoniker(NULL, szURL, &spMoniker);\r
+        if (FAILED(hr))\r
+        {\r
+            return hr;\r
+        }\r
+       \r
+        hr = ::_ShowHTMLDialog(hwndParent, spMoniker, pvarArgIn, pchOptions, pvarArgOut);\r
+        if (FAILED(hr))\r
+        {\r
+            return hr;\r
+        }\r
+    }\r
+    catch (...)\r
+    {\r
+        return E_FAIL;\r
+    }\r
+   \r
+    return hr;\r
+}\r
+\r
+// ショートカットの作成\r
+bool CreateLinkInnerA(char *filename, char *target, char *workdir, char *args,\r
+                                    char *comment, char *icon, UINT icon_index)\r
+{\r
+       HRESULT r;\r
+       wchar_t tmp[MAX_SIZE];\r
+       IShellLinkA* pShellLink;\r
+       IPersistFile* pPersistFile;\r
+\r
+       r = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkA, (void **)&pShellLink);\r
+       if (FAILED(r))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       r = pShellLink->QueryInterface(IID_IPersistFile,(void **)&pPersistFile);\r
+       if (FAILED(r))\r
+       {\r
+               pShellLink->Release();\r
+               return false;\r
+       }\r
+\r
+       r = pShellLink->SetPath(target);\r
+       if (FAILED(r))\r
+       {\r
+               pShellLink->Release();\r
+               pPersistFile->Release();\r
+               return false;\r
+       }\r
+\r
+       if (workdir != NULL)\r
+       {\r
+               r = pShellLink->SetWorkingDirectory(workdir);\r
+               if (FAILED(r))\r
+               {\r
+                       pShellLink->Release();\r
+                       pPersistFile->Release();\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       if (args != NULL)\r
+       {\r
+               r = pShellLink->SetArguments(args);\r
+               if (FAILED(r))\r
+               {\r
+                       pShellLink->Release();\r
+                       pPersistFile->Release();\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       if (comment != NULL)\r
+       {\r
+               r = pShellLink->SetDescription(comment);\r
+               if (FAILED(r))\r
+               {\r
+                       pShellLink->Release();\r
+                       pPersistFile->Release();\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       if (icon != NULL)\r
+       {\r
+               r = pShellLink->SetIconLocation(icon, icon_index);\r
+               if (FAILED(r))\r
+               {\r
+                       pShellLink->Release();\r
+                       pPersistFile->Release();\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       StrToUni(tmp, sizeof(tmp), filename);\r
+       r = pPersistFile->Save(tmp, true);\r
+       if (FAILED(r))\r
+       {\r
+               pShellLink->Release();\r
+               pPersistFile->Release();\r
+               return false;\r
+       }\r
+\r
+       pShellLink->Release();\r
+       pPersistFile->Release();\r
+       return true;\r
+}\r
+bool CreateLinkInner(wchar_t *filename, wchar_t *target, wchar_t *workdir, wchar_t *args,\r
+                                    wchar_t *comment, wchar_t *icon, UINT icon_index)\r
+{\r
+       HRESULT r;\r
+       bool ret;\r
+       IShellLinkW* pShellLink;\r
+       IPersistFile* pPersistFile;\r
+\r
+       if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType))\r
+       {\r
+               char *a1, *a2, *a3, *a4, *a5, *a6;\r
+               a1 = CopyUniToStr(filename);\r
+               a2 = CopyUniToStr(target);\r
+               a3 = CopyUniToStr(workdir);\r
+               a4 = CopyUniToStr(args);\r
+               a5 = CopyUniToStr(icon);\r
+               a6 = CopyUniToStr(comment);\r
+\r
+               ret = CreateLinkInnerA(a1, a2, a3, a4, a6, a5, icon_index);\r
+\r
+               Free(a1);\r
+               Free(a2);\r
+               Free(a3);\r
+               Free(a4);\r
+               Free(a5);\r
+               Free(a6);\r
+\r
+               return ret;\r
+       }\r
+\r
+       r = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (void **)&pShellLink);\r
+       if (FAILED(r))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       r = pShellLink->QueryInterface(IID_IPersistFile,(void **)&pPersistFile);\r
+       if (FAILED(r))\r
+       {\r
+               pShellLink->Release();\r
+               return false;\r
+       }\r
+\r
+       r = pShellLink->SetPath(target);\r
+       if (FAILED(r))\r
+       {\r
+               pShellLink->Release();\r
+               pPersistFile->Release();\r
+               return false;\r
+       }\r
+\r
+       if (workdir != NULL)\r
+       {\r
+               r = pShellLink->SetWorkingDirectory(workdir);\r
+               if (FAILED(r))\r
+               {\r
+                       pShellLink->Release();\r
+                       pPersistFile->Release();\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       if (comment != NULL)\r
+       {\r
+               r = pShellLink->SetDescription(comment);\r
+               if (FAILED(r))\r
+               {\r
+                       pShellLink->Release();\r
+                       pPersistFile->Release();\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       if (args != NULL)\r
+       {\r
+               r = pShellLink->SetArguments(args);\r
+               if (FAILED(r))\r
+               {\r
+                       pShellLink->Release();\r
+                       pPersistFile->Release();\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       if (icon != NULL)\r
+       {\r
+               r = pShellLink->SetIconLocation(icon, icon_index);\r
+               if (FAILED(r))\r
+               {\r
+                       pShellLink->Release();\r
+                       pPersistFile->Release();\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       r = pPersistFile->Save(filename, true);\r
+       if (FAILED(r))\r
+       {\r
+               pShellLink->Release();\r
+               pPersistFile->Release();\r
+               return false;\r
+       }\r
+\r
+       pShellLink->Release();\r
+       pPersistFile->Release();\r
+       return true;\r
+}\r
+\r
+extern "C"\r
+{\r
+\r
+// フォルダ選択ダイアログの表示\r
+wchar_t *FolderDlgW(HWND hWnd, wchar_t *title, wchar_t *default_dir)\r
+{\r
+       wchar_t *ret;\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *default_dir_a = CopyUniToStr(default_dir);\r
+               char *ret_a = FolderDlgA(hWnd, title, default_dir_a);\r
+\r
+               ret = CopyStrToUni(ret_a);\r
+               Free(ret_a);\r
+               Free(default_dir_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       ret = FolderDlgInnerW(hWnd, title, default_dir);\r
+\r
+       return ret;\r
+}\r
+char *FolderDlgA(HWND hWnd, wchar_t *title, char *default_dir)\r
+{\r
+       char *ret;\r
+\r
+       ret = FolderDlgInnerA(hWnd, title, default_dir);\r
+\r
+       return ret;\r
+}\r
+\r
+// ショートカットの作成\r
+bool CreateLink(wchar_t *filename, wchar_t *target, wchar_t *workdir, wchar_t *args,\r
+                               wchar_t *comment, wchar_t *icon, UINT icon_index)\r
+{\r
+       if (filename == NULL || target == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return CreateLinkInner(filename, target, workdir, args, comment, icon, icon_index);\r
+}\r
+\r
+// HTML の表示\r
+void ShowHtml(HWND hWnd, char *url, wchar_t *option)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (url == NULL || option == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrToUni(tmp, sizeof(tmp), url);\r
+\r
+       ShowHTMLDialogFromURL(hWnd, tmp, NULL, option, NULL);\r
+}\r
+\r
+}\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Win32Html.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/Win32Html.h
new file mode 100644 (file)
index 0000000..88752d8
--- /dev/null
@@ -0,0 +1,247 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Win32Html.h\r
+// Win32Html.c のヘッダ\r
+\r
+#ifndef        WIN32HTML_H\r
+#define        WIN32HTML_H\r
+\r
+#ifdef WIN32HTML_CPP\r
+\r
+// 内部向け関数\r
+\r
+#endif // WIN32HTML_CPP\r
+\r
+// 外部向け関数\r
+\r
+#pragma comment(lib,"htmlhelp.lib")\r
+#pragma comment(lib,"Urlmon.lib")\r
+\r
+#if    defined(__cplusplus)\r
+extern "C"\r
+{\r
+#endif\r
+\r
+       void ShowHtml(HWND hWnd, char *url, wchar_t *option);\r
+       bool CreateLink(wchar_t *filename, wchar_t *target, wchar_t *workdir, wchar_t *args,\r
+               wchar_t *comment, wchar_t *icon, UINT icon_index);\r
+       wchar_t *FolderDlgW(HWND hWnd, wchar_t *title, wchar_t *default_dir);\r
+       char *FolderDlgA(HWND hWnd, wchar_t *title, char *default_dir);\r
+\r
+       //////////////////////////////////////////////////////////////////////////\r
+       //JumpList\r
+\r
+\r
+       typedef void* JL_PCustomDestinationList;\r
+       typedef void* JL_PObjectArray;\r
+       typedef void* JL_PShellLink;\r
+       typedef void* JL_PObjectCollection;\r
+       typedef long JL_HRESULT;\r
+\r
+       JL_HRESULT JL_CreateCustomDestinationList(JL_PCustomDestinationList* poc, wchar_t* appID);\r
+       JL_HRESULT JL_ReleaseCustomDestinationList(JL_PCustomDestinationList poc);\r
+\r
+       JL_HRESULT JL_BeginList(JL_PCustomDestinationList poc, JL_PObjectArray* oaRemoved);\r
+       JL_HRESULT JL_CommitList(JL_PCustomDestinationList cdl);\r
+\r
+\r
+       JL_HRESULT JL_CreateObjectCollection(JL_PObjectCollection* poc);\r
+       JL_HRESULT JL_ReleaseObjectCollection(JL_PObjectCollection poc);\r
+       JL_HRESULT JL_ObjectCollectionAddShellLink(JL_PObjectCollection poc, JL_PShellLink ppsl);\r
+\r
+       JL_HRESULT JL_AddCategoryToList(JL_PCustomDestinationList pcdl, \r
+               JL_PObjectCollection poc, \r
+               wchar_t* categoryName,\r
+               JL_PObjectArray poaRemoved);\r
+       JL_HRESULT JL_DeleteJumpList(JL_PCustomDestinationList jpcdl,wchar_t* appID);\r
+\r
+\r
+       JL_HRESULT JL_CreateShellLink(\r
+               wchar_t* pszPath, \r
+               wchar_t* pszArguments, \r
+               wchar_t* pszTitle, \r
+               wchar_t* iconLocation,\r
+               int iconIndex,\r
+               wchar_t* description, JL_PShellLink *ppsl);\r
+       JL_HRESULT JL_ReleaseShellLink(JL_PShellLink ppsl);\r
+\r
+\r
+       //SetApplicationID for Windows 7\r
+       JL_HRESULT JL_SetCurrentProcessExplicitAppUserModelID(wchar_t* appID);\r
+\r
+#if    defined(__cplusplus)\r
+}\r
+#endif\r
+\r
+\r
+#if defined(__cplusplus)\r
+\r
+// 注意: このあたりの宣言文は Windows SDK からのコピーである。\r
+//       しかし創作性に乏しい (単なる宣言であるため) ので GPL のコード中にペーストしても\r
+//       支障はないと解釈している。\r
+\r
+#ifndef        __IObjectArray_INTERFACE_DEFINED__\r
+#define        __IObjectArray_INTERFACE_DEFINED__\r
+\r
+MIDL_INTERFACE("92CA9DCD-5622-4bba-A805-5E9F541BD8C9")\r
+IObjectArray : public IUnknown\r
+{\r
+public:\r
+       virtual HRESULT STDMETHODCALLTYPE GetCount( \r
+               /* [out] */ __RPC__out UINT *pcObjects) = 0;\r
+\r
+       virtual HRESULT STDMETHODCALLTYPE GetAt( \r
+               /* [in] */ UINT uiIndex,\r
+               /* [in] */ __RPC__in REFIID riid,\r
+               /* [iid_is][out] */ __RPC__deref_out_opt void **ppv) = 0;\r
+\r
+};\r
+\r
+MIDL_INTERFACE("5632b1a4-e38a-400a-928a-d4cd63230295")\r
+IObjectCollection : public IObjectArray\r
+{\r
+public:\r
+       virtual HRESULT STDMETHODCALLTYPE AddObject( \r
+               /* [in] */ __RPC__in_opt IUnknown *punk) = 0;\r
+\r
+       virtual HRESULT STDMETHODCALLTYPE AddFromArray( \r
+               /* [in] */ __RPC__in_opt IObjectArray *poaSource) = 0;\r
+\r
+       virtual HRESULT STDMETHODCALLTYPE RemoveObjectAt( \r
+               /* [in] */ UINT uiIndex) = 0;\r
+\r
+       virtual HRESULT STDMETHODCALLTYPE Clear( void) = 0;\r
+\r
+};\r
+\r
+#endif // __IObjectArray_INTERFACE_DEFINED__\r
+\r
+#ifndef        __ICustomDestinationList_INTERFACE_DEFINED__\r
+#define        __ICustomDestinationList_INTERFACE_DEFINED__\r
+\r
+typedef /* [v1_enum] */ \r
+enum KNOWNDESTCATEGORY\r
+{      \r
+       KDC_FREQUENT    = 1,\r
+       KDC_RECENT      = ( KDC_FREQUENT + 1 ) \r
+}      KNOWNDESTCATEGORY;\r
+\r
+MIDL_INTERFACE("6332debf-87b5-4670-90c0-5e57b408a49e")\r
+ICustomDestinationList : public IUnknown\r
+{\r
+public:\r
+       virtual HRESULT STDMETHODCALLTYPE SetAppID( \r
+               /* [string][in] */ __RPC__in_string LPCWSTR pszAppID) = 0;\r
+\r
+       virtual HRESULT STDMETHODCALLTYPE BeginList( \r
+               /* [out] */ __RPC__out UINT *pcMinSlots,\r
+               /* [in] */ __RPC__in REFIID riid,\r
+               /* [iid_is][out] */ __RPC__deref_out_opt void **ppv) = 0;\r
+\r
+       virtual HRESULT STDMETHODCALLTYPE AppendCategory( \r
+               /* [string][in] */ __RPC__in_string LPCWSTR pszCategory,\r
+               /* [in] */ __RPC__in_opt IObjectArray *poa) = 0;\r
+\r
+       virtual HRESULT STDMETHODCALLTYPE AppendKnownCategory( \r
+               /* [in] */ KNOWNDESTCATEGORY category) = 0;\r
+\r
+       virtual HRESULT STDMETHODCALLTYPE AddUserTasks( \r
+               /* [in] */ __RPC__in_opt IObjectArray *poa) = 0;\r
+\r
+       virtual HRESULT STDMETHODCALLTYPE CommitList( void) = 0;\r
+\r
+       virtual HRESULT STDMETHODCALLTYPE GetRemovedDestinations( \r
+               /* [in] */ __RPC__in REFIID riid,\r
+               /* [iid_is][out] */ __RPC__deref_out_opt void **ppv) = 0;\r
+\r
+       virtual HRESULT STDMETHODCALLTYPE DeleteList( \r
+               /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszAppID) = 0;\r
+\r
+       virtual HRESULT STDMETHODCALLTYPE AbortList( void) = 0;\r
+\r
+};\r
+\r
+\r
+#endif // __ICustomDestinationList_INTERFACE_DEFINED__\r
+\r
+\r
+#endif //defined(__cplusplus)\r
+\r
+\r
+\r
+#endif // WIN32HTML_H\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/WinJumpList.cpp b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/WinJumpList.cpp
new file mode 100644 (file)
index 0000000..ecaf0eb
--- /dev/null
@@ -0,0 +1,440 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// WinJumpList.cpp\r
+// Windows7用 ジャンプリスト ソースコード\r
+\r
+// Q. このソースコードだけ他と違ってコメントが少ないように見える。\r
+// A. はい。\r
+\r
+#ifdef WIN32\r
+\r
+//#define NTDDI_WIN7                          0x06010000\r
+//#define      _WIN32_WINNT    _WIN32_WINNT_VISTA\r
+//#define NTDDI_VERSION NTDDI_VISTA  // Specifies that the minimum required platform is Windows 7.\r
+#define WIN32_LEAN_AND_MEAN       // Exclude rarely-used stuff from Windows headers\r
+#define STRICT_TYPED_ITEMIDS      // Utilize strictly typed IDLists\r
+\r
+//#include <objectarray.h>\r
+#include <shobjidl.h>\r
+#include <propkey.h>\r
+#include <propvarutil.h>\r
+//#include <knownfolders.h>\r
+//#include <shlobj.h>\r
+\r
+\r
+#ifdef StrCpy\r
+#undef StrCpy\r
+#endif\r
+\r
+#ifdef StrCat\r
+#undef StrCat\r
+#endif\r
+\r
+#ifdef StrCmp\r
+#undef StrCmp\r
+#endif\r
+\r
+\r
+#define        WIN32HTML_CPP\r
+\r
+//#define      _WIN32_WINNT            0x0502\r
+//#define      WINVER                          0x0502\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+#include <wincrypt.h>\r
+#include <wininet.h>\r
+#include <comdef.h>\r
+#include <Mshtmhst.h>\r
+//#include <shlobj.h>\r
+#include <commctrl.h>\r
+#include <Dbghelp.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+\r
+extern "C"\r
+{\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+}\r
+#include "../PenCore/resource.h"\r
+\r
+extern "C"\r
+{\r
+\r
+       //////////////////////////////////////////////////////////////////////////\r
+       //JumpList\r
+       // 注意: このあたりのコードは Win32 ヘッダファイル等からコピーした部分がある。\r
+       //       ただしコピーしたのは単純な部分のみであり、創造的かつ複雑な部分ではないので\r
+       //       GPL のコードの一部としてペーストしてあっても問題にはならないものと解釈\r
+       //       している。\r
+\r
+       #define CREATE_PROPERTYKEY(l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }, pid }\r
+\r
+\r
+       JL_HRESULT JL_CreateCustomDestinationList(JL_PCustomDestinationList* poc, wchar_t* appID)\r
+       {\r
+               ICustomDestinationList *pcdl;\r
+\r
+               //CLSID_DestinationList = 6332DEBF-87B5-4670-90C0-5E57-B408-A49E\r
+\r
+               GUID destList;\r
+\r
+               destList.Data1 = 2012286192;\r
+               destList.Data2 = 15797;\r
+               destList.Data3 = 18790;\r
+\r
+               destList.Data4[0] = 181;\r
+               destList.Data4[1] = 32;\r
+               destList.Data4[2] = 183;\r
+               destList.Data4[3] = 197;\r
+               destList.Data4[4] = 79;\r
+               destList.Data4[5] = 211;\r
+               destList.Data4[6] = 94;\r
+               destList.Data4[7] = 214;\r
+\r
+               HRESULT hr = CoCreateInstance(destList, \r
+                       NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pcdl));\r
+\r
+               if (SUCCEEDED(hr))\r
+               {\r
+                       pcdl->SetAppID(appID);\r
+                       (*poc) = (void*)pcdl;\r
+               }\r
+               else\r
+               {\r
+                       (*poc) = NULL;\r
+               }\r
+\r
+               return hr;\r
+       }\r
+\r
+       JL_HRESULT JL_ReleaseCustomDestinationList(JL_PCustomDestinationList poc)\r
+       {\r
+               ICustomDestinationList *pcdl = (ICustomDestinationList*)poc;\r
+               if(pcdl != NULL)\r
+               {\r
+                       pcdl->Release();\r
+               }\r
+\r
+               return 0;\r
+       }\r
+\r
+       JL_HRESULT JL_BeginList(JL_PCustomDestinationList poc, JL_PObjectArray* oaRemoved)\r
+       {\r
+               UINT cMinSlots;\r
+               IObjectArray *poaRemoved;\r
+\r
+               ICustomDestinationList *pcdl = (ICustomDestinationList*)poc;\r
+\r
+               HRESULT hr = pcdl->BeginList(&cMinSlots, IID_PPV_ARGS(&poaRemoved));\r
+\r
+               (*oaRemoved) = poaRemoved;\r
+\r
+               return hr;\r
+       }\r
+\r
+       JL_HRESULT JL_CommitList(JL_PCustomDestinationList cdl)\r
+       {\r
+               ICustomDestinationList *pcdl = (ICustomDestinationList*)cdl;\r
+\r
+               return pcdl->CommitList();\r
+       }\r
+\r
+       JL_HRESULT JL_CreateObjectCollection(JL_PObjectCollection* jpoc)\r
+       {\r
+\r
+               //CLSID_EnumerableObjectCollection = 2D3468C1-36A7-43B6-AC24-D3F0-2FD9-607A\r
+\r
+\r
+               GUID enumObjCol;\r
+\r
+               enumObjCol.Data1 = 758409409;\r
+               enumObjCol.Data2 = 13991;\r
+               enumObjCol.Data3 = 17334;\r
+\r
+               enumObjCol.Data4[0] = 172;\r
+               enumObjCol.Data4[1] = 36;\r
+               enumObjCol.Data4[2] = 211;\r
+               enumObjCol.Data4[3] = 240;\r
+               enumObjCol.Data4[4] = 47;\r
+               enumObjCol.Data4[5] = 217;\r
+               enumObjCol.Data4[6] = 96;\r
+               enumObjCol.Data4[7] = 122;\r
+\r
+               IObjectCollection *poc;\r
+               HRESULT hr = CoCreateInstance(enumObjCol,\r
+                       NULL, CLSCTX_INPROC, IID_PPV_ARGS(&poc));\r
+\r
+               if (SUCCEEDED(hr))\r
+               {\r
+                       (*jpoc) = poc;\r
+               }\r
+               else{\r
+                       (*jpoc) = NULL;\r
+               }\r
+               return hr;\r
+       }\r
+\r
+       JL_HRESULT JL_ReleaseObjectCollection(JL_PObjectCollection jpoc)\r
+       {\r
+               IObjectCollection *poc = (IObjectCollection *)jpoc;\r
+               if(poc != NULL)\r
+               {\r
+                       return poc->Release();\r
+               }\r
+\r
+               return 0;\r
+       }\r
+\r
+       JL_HRESULT JL_ObjectCollectionAddShellLink(JL_PObjectCollection jpoc, JL_PShellLink jpsl)\r
+       {\r
+               IObjectCollection *poc = (IObjectCollection *)jpoc;\r
+               IShellLink *psl = (IShellLink *) jpsl;\r
+\r
+               return poc->AddObject(psl);\r
+\r
+       }\r
+\r
+\r
+       JL_HRESULT JL_AddCategoryToList(JL_PCustomDestinationList jpcdl, \r
+               JL_PObjectCollection jpoc, \r
+               wchar_t* categoryName,\r
+               JL_PObjectArray jpoaRemoved)\r
+       {\r
+               ICustomDestinationList *pcdl = (ICustomDestinationList*)jpcdl;\r
+               IObjectCollection *poc = (IObjectCollection *)jpoc;\r
+                IObjectArray *poaRemoved = (IObjectArray*)jpoaRemoved;\r
+\r
+               IObjectArray *poa;\r
+               HRESULT hr = poc->QueryInterface(IID_PPV_ARGS(&poa));\r
+               if (SUCCEEDED(hr))\r
+               {\r
+               \r
+                       hr = pcdl->AppendCategory(categoryName, poa);\r
+                       poa->Release();\r
+\r
+                       if (SUCCEEDED(hr))\r
+                       {\r
+                       }\r
+                       else\r
+                       {\r
+                               Print("Failed AppendCategory\n");\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       Print("Failed QueryInterface\n");\r
+               }\r
+               \r
+\r
+               return hr;\r
+       }\r
+\r
+\r
+\r
+       JL_HRESULT JL_CreateShellLink(\r
+               wchar_t* pszPath, \r
+               wchar_t* pszArguments, \r
+               wchar_t* pszTitle, \r
+               wchar_t* iconLocation,\r
+               int iconIndex, \r
+               wchar_t* description, JL_PShellLink *ppsl)\r
+       {\r
+               IShellLinkW *psl;\r
+               HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl));\r
+               if (SUCCEEDED(hr))\r
+               {\r
+                       psl->SetPath(pszPath);\r
+                       psl->SetArguments(pszArguments);\r
+                       if(iconLocation != NULL)\r
+                       {\r
+                               psl->SetIconLocation(iconLocation,iconIndex);\r
+                       }\r
+\r
+                       if(description != NULL)\r
+                       {\r
+                               psl->SetDescription(description);\r
+                       }\r
+                               if (SUCCEEDED(hr))\r
+                               {\r
+                                       IPropertyStore *pps;\r
+                                       hr = psl->QueryInterface(IID_PPV_ARGS(&pps));\r
+                                       if (SUCCEEDED(hr))\r
+                                       {\r
+                                               PROPVARIANT propvar;\r
+                                               hr = InitPropVariantFromString(pszTitle, &propvar);\r
+                                               if (SUCCEEDED(hr))\r
+                                               {\r
+\r
+                                                       PROPERTYKEY pkey_title = \r
+                                                               CREATE_PROPERTYKEY(0xF29F85E0, 0x4FF9, 0x1068, 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9, 2);\r
+\r
+                                                       hr = pps->SetValue(pkey_title, propvar);\r
+\r
+\r
+                                                       if (SUCCEEDED(hr))\r
+                                                       {\r
+                                                               hr = pps->Commit();\r
+                                                               if (SUCCEEDED(hr))\r
+                                                               {\r
+                                                                       IShellLink *tpsl;\r
+                                                                       hr = psl->QueryInterface(IID_PPV_ARGS(&tpsl));\r
+                                                                       (*ppsl) = tpsl;\r
+                                                               }\r
+                                                       }\r
+                                                       PropVariantClear(&propvar);\r
+                                               }\r
+                                               pps->Release();\r
+                                       }\r
+                               }\r
+                       psl->Release();\r
+               }\r
+               return hr;\r
+       }\r
+\r
+       JL_HRESULT JL_ReleaseShellLink(JL_PShellLink jpsl)\r
+       {\r
+               IShellLink *psl = (IShellLink *) jpsl;\r
+\r
+               if(psl != NULL)\r
+               {\r
+                       return psl->Release();\r
+               }\r
+\r
+               return 0;\r
+       }\r
+\r
+       JL_HRESULT JL_DeleteJumpList(JL_PCustomDestinationList jpcdl,wchar_t* appID)\r
+       {\r
+               ICustomDestinationList *pcdl = (ICustomDestinationList *)jpcdl;\r
+\r
+               HRESULT hr = pcdl->DeleteList(appID);\r
+\r
+\r
+               return hr;\r
+       }\r
+\r
+\r
+\r
+       //////////////////////////////////////////////////////////////////////////\r
+       //SetApplicationID for Windows 7\r
+       JL_HRESULT JL_SetCurrentProcessExplicitAppUserModelID(wchar_t* appID)\r
+       {\r
+#ifdef UNICODE\r
+               HMODULE hModule = LoadLibraryW( L"shell32.dll");\r
+#else\r
+               HMODULE hModule = LoadLibraryA( "shell32.dll");\r
+#endif\r
+               HRESULT (__stdcall *SetAppID) (PCWSTR);\r
+\r
+               if( hModule == NULL )\r
+               {\r
+                       Print("Not Found shell32.dll");\r
+               }\r
+               else\r
+               {\r
+                       SetAppID = (HRESULT (__stdcall *)(PCWSTR))\r
+                               GetProcAddress( hModule, "SetCurrentProcessExplicitAppUserModelID" );\r
+                       if( SetAppID != NULL )\r
+                       {\r
+                               FreeLibrary( hModule );\r
+                               return SetAppID(appID);\r
+                       }\r
+                       else\r
+                       {\r
+                               Print("Not Found SetCurrentProcessExplicitAppUserModelID");\r
+\r
+                       }\r
+\r
+                       FreeLibrary( hModule );\r
+               }\r
+               return 0;\r
+\r
+\r
+       }\r
+\r
+\r
+\r
+}\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/WinUi.c b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/WinUi.c
new file mode 100644 (file)
index 0000000..98385ea
--- /dev/null
@@ -0,0 +1,9920 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// WinUi.c\r
+// Win32 用ユーザーインターフェースコード\r
+\r
+#ifdef WIN32\r
+\r
+#define        WINUI_C\r
+\r
+#define        _WIN32_WINNT            0x0502\r
+#define        WINVER                          0x0502\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+#include <wincrypt.h>\r
+#include <wininet.h>\r
+#include <Iphlpapi.h>\r
+#include <shlobj.h>\r
+#include <commctrl.h>\r
+#include <Dbghelp.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+#include "../PenCore/resource.h"\r
+\r
+char cached_pin_code[MAX_SIZE] = {0};\r
+UINT64 cached_pin_code_expires = 0;\r
+\r
+static HINSTANCE hDll = NULL;\r
+static wchar_t *title_bar = NULL;\r
+static char *font_name = NULL;\r
+static UINT font_size = 9;\r
+static HIMAGELIST large_image_list = NULL, small_image_list = NULL;\r
+static LIST *icon_list = NULL;\r
+static HINSTANCE hMsHtml = NULL;\r
+static UINT init_winui_counter = 0;\r
+static bool new_style_mode = false;\r
+\r
+bool UseAlpha = false;\r
+UINT AlphaValue = 100;\r
+\r
+static THREAD *led_thread = NULL;\r
+static bool thread_stop = false;\r
+static bool g_led_special = false;\r
+static bool g_tcpip_topmost = false;\r
+\r
+typedef struct GDI_CACHE\r
+{\r
+       bool IsInited;\r
+       COLORREF BackgroundColor;\r
+       COLORREF ForegroundColor;\r
+       COLORREF TextBoxBackgroundColor;\r
+       HBRUSH BlackBrush;\r
+       HBRUSH WhiteBrush;\r
+       HBRUSH BackgroundColorBrush;\r
+       HBRUSH ForegroundColorBrush;\r
+       HBRUSH TextBoxBackgroundColorBrush;\r
+} GDI_CACHE;\r
+\r
+static GDI_CACHE gdi_cache = { false, };\r
+\r
+// スプラッシュウインドウデータ\r
+typedef struct SPLASH\r
+{\r
+       HWND hWnd;\r
+       HWND hWndParent;\r
+       WINBMP *Bmp;\r
+       void *Param;\r
+       UINT64 Ticks;\r
+       UINT64 StartTick;\r
+       char *Title;\r
+       wchar_t *Caption;\r
+       HPEN LinePen;\r
+       WINMEMDC *BackDC;\r
+} SPLASH;\r
+\r
+// 画面がフルカラーモードかどうか取得\r
+bool IsFullColor()\r
+{\r
+       bool ret = false;\r
+       HDC hDC = CreateCompatibleDC(0);\r
+\r
+       if (GetDeviceCaps(hDC, BITSPIXEL) >= 16)\r
+       {\r
+               ret = true;\r
+       }\r
+\r
+       DeleteDC(hDC);\r
+\r
+       return ret;\r
+}\r
+\r
+// リストビューの背景に画像を表示する\r
+void LvSetBkImage(HWND hWnd, UINT id, char *bmp_file_name)\r
+{\r
+       LVBKIMAGE t;\r
+       char *tmp;\r
+       // 引数チェック\r
+       if (hWnd == NULL || bmp_file_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (IsFullColor() == false)\r
+       {\r
+               // 256 色モードの場合は表示しない\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       tmp = MsCreateTempFileNameByExt(".bmp");\r
+\r
+       FileCopy(bmp_file_name, tmp);\r
+\r
+       t.ulFlags = LVBKIF_SOURCE_URL | LVBKIF_STYLE_NORMAL;\r
+       t.pszImage = tmp;\r
+       t.xOffsetPercent = 100;\r
+       t.yOffsetPercent = 100;\r
+\r
+       ListView_SetBkImage(DlgItem(hWnd, id), &t);\r
+\r
+       Free(tmp);\r
+}\r
+\r
+// メモリ DC を解放する\r
+void FreeMemDC(WINMEMDC *m)\r
+{\r
+       // 引数チェック\r
+       if (m == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DeleteDC(m->hDC);\r
+       DeleteObject(m->hBitmap);\r
+\r
+       Free(m);\r
+}\r
+\r
+// メモリ DC を作成する\r
+WINMEMDC *NewMemDC(UINT width, UINT height)\r
+{\r
+       WINMEMDC *m = ZeroMalloc(sizeof(WINMEMDC));\r
+       BITMAPINFOHEADER h;\r
+       BITMAPINFO bi;\r
+\r
+       m->Width = width;\r
+       m->Height = height;\r
+\r
+       m->hDC = CreateCompatibleDC(0);\r
+\r
+       Zero(&h, sizeof(h));\r
+       h.biSize = sizeof(h);\r
+       h.biWidth = width;\r
+       h.biHeight = height;\r
+       h.biPlanes = 1;\r
+       h.biBitCount = 24;\r
+       h.biXPelsPerMeter = 2834;\r
+       h.biYPelsPerMeter = 2834;\r
+\r
+       Zero(&bi, sizeof(bi));\r
+       Copy(&bi.bmiHeader, &h, sizeof(BITMAPINFOHEADER));\r
+\r
+       m->hBitmap = CreateDIBSection(m->hDC, &bi, DIB_RGB_COLORS,\r
+               &m->Data, NULL, 0);\r
+\r
+       SelectObject(m->hDC, m->hBitmap);\r
+\r
+       return m;\r
+}\r
+\r
+// スプラッシュ画面を表示する (毎回絵が変わる)\r
+void ShowSplashEx(HWND hWndParent, char *software_name, UINT ticks, UINT line_color)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t caption[MAX_SIZE];\r
+       UINT id = MsRegReadInt(REG_CURRENT_USER, SPLASH_BMP_REGKEY, SPLASH_BMP_REGVALUE);\r
+       id++;\r
+       if (id > 20)\r
+       {\r
+               id = 1;\r
+       }\r
+       MsRegWriteInt(REG_CURRENT_USER, SPLASH_BMP_REGKEY, SPLASH_BMP_REGVALUE, id);\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"|Splash%02u.bmp", id);\r
+\r
+       StrToUni(caption, sizeof(caption), software_name);\r
+\r
+       ShowSplash(hWndParent, tmp, software_name, caption, ticks, line_color, NULL);\r
+}\r
+\r
+// フォント描画\r
+void DrawFont(HDC hDC, wchar_t *text, UINT x, UINT y, HFONT font, UINT fore_color,\r
+                         UINT back_color, UINT back_width)\r
+{\r
+       int i, j;\r
+\r
+       SelectObject(hDC, font);\r
+       SetBkMode(hDC, TRANSPARENT);\r
+\r
+       // 背景の描画\r
+       SetTextColor(hDC, back_color);\r
+       for (i = -((int)back_width);i <= (int)back_width;i++)\r
+       {\r
+               for (j = -((int)back_width); j <= (int)back_width;j++)\r
+               {\r
+                       if (i != 0 || j != 0)\r
+                       {\r
+                               TextOutW(hDC, (int)x + i, (int)y + j, text, UniStrLen(text));\r
+                       }\r
+               }\r
+       }\r
+\r
+       // 文字の描画\r
+       SetTextColor(hDC, fore_color);\r
+       TextOutW(hDC, x, y, text, UniStrLen(text));\r
+}\r
+\r
+// スプラッシュウインドウを開く\r
+LRESULT CALLBACK SplashProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)\r
+{\r
+       SPLASH *splash;\r
+       CREATESTRUCT *cs = (CREATESTRUCT *)lParam;\r
+       UINT64 now = Tick64();\r
+       UINT64 current_span = 0;\r
+       UINT a;\r
+       UINT fade = 8;\r
+\r
+       if (msg == WM_CREATE)\r
+       {\r
+               splash = (SPLASH *)cs->lpCreateParams;\r
+               current_span = 0;\r
+       }\r
+       else\r
+       {\r
+               splash = (SPLASH *)GetWindowLongPtrA(hWnd, GWLP_USERDATA);\r
+               if (splash != NULL)\r
+               {\r
+                       current_span = now - splash->StartTick;\r
+               }\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_CREATE:\r
+               SetWindowLongPtrA(hWnd, GWLP_USERDATA, (LONG_PTR)splash);\r
+\r
+               CenterParent(hWnd);\r
+\r
+               if (splash->Ticks != 0)\r
+               {\r
+                       SetTimer(hWnd, 1, 1, NULL);\r
+\r
+                       splash->StartTick = now;\r
+\r
+                       SetAplha(hWnd, 0);\r
+\r
+                       Top(hWnd);\r
+               }\r
+\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+\r
+                       a = 0;\r
+\r
+                       if (current_span < (splash->Ticks / fade))\r
+                       {\r
+                               // フェードイン\r
+                               a = (UINT)((double)current_span * 255.0 / (double)(splash->Ticks / fade));\r
+                       }\r
+                       else if (current_span < (splash->Ticks * (fade - 1) / fade))\r
+                       {\r
+                               // 通常表示\r
+                               a = 255;\r
+                       }\r
+                       else if (current_span < splash->Ticks)\r
+                       {\r
+                               // フェードアウト\r
+                               a = 255 - (UINT)(((double)(current_span - (splash->Ticks * (fade - 1) / fade))) * 255.0 / (double)(splash->Ticks / fade));\r
+                       }\r
+                       else\r
+                       {\r
+                               // 閉じる\r
+                               goto LABEL_CLOSE;\r
+                       }\r
+\r
+                       SetAplha(hWnd, a);\r
+\r
+                       SetTimer(hWnd, 1, 1, NULL);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_PAINT:\r
+               if (true)\r
+               {\r
+                       PAINTSTRUCT ps;\r
+                       HDC hDC, hWndDC;\r
+\r
+                       Zero(&ps, sizeof(ps));\r
+                       hWndDC = BeginPaint(hWnd, &ps);\r
+                       if (hWndDC != NULL)\r
+                       {\r
+                               POINT points[5];\r
+                               wchar_t tmp[MAX_SIZE];\r
+\r
+                               hDC = splash->BackDC->hDC;\r
+\r
+                               // ビットマップ画像\r
+                               BitBlt(hDC, 0, 0, splash->Bmp->Width, splash->Bmp->Height,\r
+                                       splash->Bmp->hDC, 0, 0, SRCCOPY);\r
+\r
+                               // 線\r
+                               Zero(points, sizeof(points));\r
+                               points[0].x = 0; points[0].y = 0;\r
+                               points[1].x = splash->Bmp->Width - 1; points[1].y = 0;\r
+                               points[2].x = splash->Bmp->Width - 1; points[2].y = splash->Bmp->Height - 1;\r
+                               points[3].x = 0; points[3].y = splash->Bmp->Height - 1;\r
+                               points[4].x = 0; points[4].y = 0;\r
+\r
+                               SelectObject(hDC, splash->LinePen);\r
+                               Polyline(hDC, points, 5);\r
+\r
+                               // ソフトウェアのタイトルの描画\r
+                               DrawFont(hDC, splash->Caption, 114, 136,\r
+                                       GetFont("Arial", 36, true, false, false, false),\r
+                                       RGB(0, 0, 0),\r
+                                       RGB(255, 255, 255),\r
+                                       3);\r
+\r
+                               // ソフトウェアのバージョン情報の描画\r
+                               UniFormat(tmp, sizeof(tmp),\r
+                                       L"Version %u.%02u Build %u, Compiled in %04u/%02u/%02u.",\r
+                                       CEDAR_VER / 100, CEDAR_VER - (CEDAR_VER / 100) * 100,\r
+                                       CEDAR_BUILD, BUILD_DATE_Y, BUILD_DATE_M, BUILD_DATE_D);\r
+                               DrawFont(hDC, tmp, 200, 202,\r
+                                       GetFont("Arial", 8, true, false, false, false),\r
+                                       RGB(0, 0, 0),\r
+                                       RGB(255, 255, 255),\r
+                                       1);\r
+\r
+                               // 画面に描画\r
+                               BitBlt(hWndDC, 0, 0, splash->Bmp->Width, splash->Bmp->Height,\r
+                                       hDC, 0, 0, SRCCOPY);\r
+\r
+                               EndPaint(hWnd, &ps);\r
+                       }\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               if (splash->Ticks != 0)\r
+               {\r
+                       return 0;\r
+               }\r
+LABEL_CLOSE:\r
+               if (splash->hWndParent != NULL)\r
+               {\r
+                       Enable(splash->hWndParent, 0);\r
+               }\r
+               DestroyWindow(hWnd);\r
+               return 0;\r
+\r
+       case WM_KEYDOWN:\r
+               switch (wParam)\r
+               {\r
+               case VK_ESCAPE:\r
+               case VK_RETURN:\r
+               case VK_SPACE:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_LBUTTONUP:\r
+       case WM_RBUTTONUP:\r
+       case WM_MBUTTONUP:\r
+               Close(hWnd);\r
+               break;\r
+\r
+       case WM_DESTROY:\r
+               if (splash->hWndParent != NULL)\r
+               {\r
+                       Enable(splash->hWndParent, 0);\r
+               }\r
+               PostQuitMessage(0);\r
+               return 0;\r
+       }\r
+\r
+       return DefWindowProc(hWnd, msg, wParam, lParam);\r
+}\r
+\r
+// スプラッシュウインドウ\r
+void ShowSplash(HWND hWndParent, wchar_t *bmp_file_name, char *title, wchar_t *caption, UINT ticks, UINT line_color, void *param)\r
+{\r
+       SPLASH *p;\r
+       WNDCLASSA wc;\r
+       char wndclass_name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (bmp_file_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (IsEmptyStr(title))\r
+       {\r
+               title = "Splash Window";\r
+       }\r
+\r
+       p = ZeroMalloc(sizeof(SPLASH));\r
+\r
+       p->Bmp = LoadBmpFromFileW(bmp_file_name);\r
+       if (p->Bmp == NULL)\r
+       {\r
+               Free(p);\r
+               return;\r
+       }\r
+\r
+       p->BackDC = NewMemDC(p->Bmp->Width, p->Bmp->Height);\r
+\r
+       p->LinePen = CreatePen(PS_SOLID, 1, line_color);\r
+\r
+       p->hWndParent = hWndParent;\r
+\r
+       p->Title = title;\r
+       p->Caption = caption;\r
+       p->Ticks = ticks;\r
+\r
+       p->Param = param;\r
+\r
+       Zero(&wc, sizeof(wc));\r
+       wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);\r
+       wc.hCursor = LoadCursor(NULL, ticks == 0 ? IDC_ARROW : IDC_APPSTARTING);\r
+       wc.hInstance = GetModuleHandleA(NULL);\r
+       wc.lpfnWndProc = SplashProc;\r
+\r
+       Format(wndclass_name, sizeof(wndclass_name), "WINUI_SPLASH_CLASS_%I64u", Rand64());\r
+       wc.lpszClassName = wndclass_name;\r
+\r
+       RegisterClassA(&wc);\r
+\r
+       p->hWnd = CreateWindowA(wndclass_name, title,\r
+               WS_POPUP, 0, 0,\r
+               p->Bmp->Width, p->Bmp->Height,\r
+               hWndParent, NULL, GetModuleHandleA(NULL), p);\r
+       if (p->hWnd == NULL)\r
+       {\r
+               Debug("CreateWindowA Error: %u\n", GetLastError());\r
+       }\r
+\r
+       if (hWndParent != NULL)\r
+       {\r
+               Disable(hWndParent, 0);\r
+       }\r
+\r
+       ShowWindow(p->hWnd, SW_SHOW);\r
+\r
+       if (p->hWnd != NULL)\r
+       {\r
+               MSG msg;\r
+\r
+               while (true)\r
+               {\r
+                       Zero(&msg, sizeof(msg));\r
+\r
+                       if (GetMessageA(&msg, NULL, 0, 0) == 0)\r
+                       {\r
+                               break;\r
+                       }\r
+\r
+                       TranslateMessage(&msg);\r
+                       DispatchMessageA(&msg);\r
+               }\r
+       }\r
+\r
+       if (hWndParent != NULL)\r
+       {\r
+               Enable(hWndParent, 0);\r
+               SetActiveWindow(hWndParent);\r
+               BringWindowToTop(hWndParent);\r
+       }\r
+\r
+       UnregisterClassA(wndclass_name, GetModuleHandleA(NULL));\r
+\r
+       FreeMemDC(p->BackDC);\r
+\r
+       FreeBmp(p->Bmp);\r
+\r
+       DeleteObject(p->LinePen);\r
+\r
+       Free(p);\r
+}\r
+\r
+// GDI オブジェクトのキャッシュがまだ作成されていない場合は作成する\r
+void InitGdiCache()\r
+{\r
+       if (gdi_cache.IsInited)\r
+       {\r
+               return;\r
+       }\r
+\r
+       gdi_cache.BlackBrush = GetStockObject(BLACK_BRUSH);\r
+       gdi_cache.WhiteBrush = GetStockObject(WHITE_BRUSH);\r
+\r
+       gdi_cache.BackgroundColor = RGB(247, 238, 255);\r
+       gdi_cache.BackgroundColorBrush = CreateSolidBrush(gdi_cache.BackgroundColor);\r
+\r
+       gdi_cache.ForegroundColor = RGB(0, 0, 0);\r
+       gdi_cache.ForegroundColorBrush = CreateSolidBrush(gdi_cache.ForegroundColor);\r
+\r
+       gdi_cache.TextBoxBackgroundColor = RGB(255, 255, 255);\r
+       gdi_cache.TextBoxBackgroundColorBrush = CreateSolidBrush(gdi_cache.TextBoxBackgroundColor);\r
+\r
+       gdi_cache.IsInited = true;\r
+}\r
+\r
+// ビットマップをリソースから読む\r
+WINBMP *LoadBmpFromResource(UINT id)\r
+{\r
+       HANDLE h;\r
+       // 引数チェック\r
+       if (id == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       h = LoadImageA(hDll, MAKEINTRESOURCEA(id), IMAGE_BITMAP, 0, 0,\r
+               LR_CREATEDIBSECTION | LR_VGACOLOR);\r
+\r
+       if (h == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return LoadBmpMain(h);\r
+}\r
+\r
+// ビットマップをファイルから読む\r
+WINBMP *LoadBmpFromFileW(wchar_t *filename)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       char *tmpa;\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 一時ファイルにコピー\r
+       tmpa = MsCreateTempFileNameByExt("bmp");\r
+\r
+       StrToUni(tmp, sizeof(tmp), tmpa);\r
+\r
+       Free(tmpa);\r
+\r
+       if (FileCopyW(filename, tmp) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return LoadBmpFromFileInnerW(tmp);\r
+}\r
+WINBMP *LoadBmpFromFileInnerW(wchar_t *filename)\r
+{\r
+       HANDLE h;\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (MsIsNt())\r
+       {\r
+               h = LoadImageW(NULL, filename, IMAGE_BITMAP, 0, 0,\r
+                       LR_CREATEDIBSECTION | LR_LOADFROMFILE | LR_VGACOLOR);\r
+       }\r
+       else\r
+       {\r
+               char tmp[MAX_SIZE];\r
+\r
+               UniToStr(tmp, sizeof(tmp), filename);\r
+\r
+               h = LoadImageA(NULL, tmp, IMAGE_BITMAP, 0, 0,\r
+                       LR_CREATEDIBSECTION | LR_LOADFROMFILE | LR_VGACOLOR);\r
+       }\r
+\r
+       if (h == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return LoadBmpMain(h);\r
+}\r
+WINBMP *LoadBmpFromFileA(char *filename)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       StrToUni(tmp, sizeof(tmp), filename);\r
+\r
+       return LoadBmpFromFileW(tmp);\r
+}\r
+\r
+// ビットマップ読み込みメイン\r
+WINBMP *LoadBmpMain(void *hBitmap)\r
+{\r
+       WINBMP *b;\r
+       BITMAP d;\r
+       HDC hDC;\r
+       // 引数チェック\r
+       if (hBitmap == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&d, sizeof(d));\r
+\r
+       if (GetObject((HANDLE)hBitmap, sizeof(d), &d) == 0)\r
+       {\r
+               DeleteObject((HANDLE)hBitmap);\r
+               return NULL;\r
+       }\r
+\r
+       b = ZeroMalloc(sizeof(WINBMP));\r
+       b->Bits = d.bmBitsPixel;\r
+       b->hBitmap = hBitmap;\r
+       b->Height = d.bmHeight;\r
+       b->Width = d.bmWidth;\r
+\r
+       hDC = CreateCompatibleDC(0);\r
+\r
+       SelectObject(hDC, hBitmap);\r
+\r
+       b->hDC = hDC;\r
+\r
+       return b;\r
+}\r
+\r
+// ビットマップを解放する\r
+void FreeBmp(WINBMP *b)\r
+{\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DeleteDC(b->hDC);\r
+       DeleteObject(b->hBitmap);\r
+\r
+       Free(b);\r
+}\r
+\r
+// 新しいスタイルを開始\r
+void EnableNewStyleMode()\r
+{\r
+       InitGdiCache();\r
+\r
+       new_style_mode = true;\r
+}\r
+\r
+// 新しいスタイルを終了\r
+void DisableNewStyleMode()\r
+{\r
+       new_style_mode = false;\r
+}\r
+\r
+// 新しいスタイルが有効になっているかどうかチェック\r
+bool IsNewStyleModeEnabled()\r
+{\r
+       return new_style_mode;\r
+}\r
+\r
+// NIC 情報ダイアログプロシージャ\r
+UINT NicInfoProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       UI_NICINFO *info = (UI_NICINFO *)param;\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               NicInfoInit(hWnd, info);\r
+\r
+               SetTimer(hWnd, 1, 50, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+\r
+                       NicInfoOnTimer(hWnd, info);\r
+\r
+                       SetTimer(hWnd, 1, 50, NULL);\r
+                       break;\r
+\r
+               case 2:\r
+                       KillTimer(hWnd, 2);\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               KillTimer(hWnd, 1);\r
+               KillTimer(hWnd, 2);\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+void NicInfoCloseAfterTime(HWND hWnd, UI_NICINFO *info, UINT tick)\r
+{\r
+       UINT64 now;\r
+       UINT64 closetime;\r
+       // 引数チェック\r
+       if (hWnd == NULL || info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       now = Tick64();\r
+       closetime = now + (UINT64)tick;\r
+\r
+       if (info->CloseAfterTime == 0 || info->CloseAfterTime >= closetime)\r
+       {\r
+               info->CloseAfterTime = closetime;\r
+               KillTimer(hWnd, 2);\r
+               SetTimer(hWnd, 2, tick, NULL);\r
+       }\r
+}\r
+void NicInfoShowStatus(HWND hWnd, UI_NICINFO *info, wchar_t *msg1, wchar_t *msg2, UINT icon, bool animate)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || info == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (icon == 0)\r
+       {\r
+               icon = ICO_TEST;\r
+       }\r
+       if (msg1 == NULL)\r
+       {\r
+               msg1 = L"";\r
+       }\r
+       if (msg2 == NULL)\r
+       {\r
+               msg2 = L"";\r
+       }\r
+\r
+       if (info->CurrentIcon != icon)\r
+       {\r
+               SetIcon(hWnd, S_ICON, icon);\r
+               info->CurrentIcon = icon;\r
+       }\r
+\r
+       SetText(hWnd, S_STATUS1, msg1);\r
+       SetText(hWnd, S_STATUS2, msg2);\r
+\r
+       SetShow(hWnd, P_BAR, animate && MsIsWinXPOrWinVista());\r
+}\r
+void NicInfoRefresh(HWND hWnd, UI_NICINFO *info)\r
+{\r
+       MS_ADAPTER *a;\r
+       IP ip;\r
+       char ip_str[MAX_SIZE];\r
+       char title[MAX_SIZE];\r
+       UINT i;\r
+       wchar_t tmp[MAX_SIZE];\r
+       bool has_ip = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL || info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(title, sizeof(title), VLAN_ADAPTER_NAME_TAG, info->NicName);\r
+\r
+       a = MsGetAdapter(title);\r
+       if (a == NULL)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       // IP アドレスが割り当てら割れているかどうかチェック\r
+       Zero(&ip, sizeof(ip));\r
+       for (i = 0;i < MAX_MS_ADAPTER_IP_ADDRESS;i++)\r
+       {\r
+               if (IsZeroIP(&a->IpAddresses[i]) == false)\r
+               {\r
+                       Copy(&ip, &a->IpAddresses[i], sizeof(IP));\r
+\r
+                       if (!(ip.addr[0] == 169 && ip.addr[1] == 254))\r
+                       {\r
+                               has_ip = true;\r
+                       }\r
+               }\r
+       }\r
+       IPToStr(ip_str, sizeof(ip_str), &ip);\r
+\r
+       if (has_ip == false)\r
+       {\r
+               if (a->UseDhcp)\r
+               {\r
+                       NicInfoShowStatus(hWnd, info, _UU("NICINFO_1"), _UU("NICINFO_1_1"), ICO_NIC_OFFLINE, true);\r
+               }\r
+               else\r
+               {\r
+                       NicInfoShowStatus(hWnd, info, _UU("NICINFO_1"), _UU("NICINFO_1_2"), ICO_NIC_OFFLINE, true);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (a->UseDhcp)\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("NICINFO_2_1"), ip_str);\r
+                       NicInfoShowStatus(hWnd, info, _UU("NICINFO_2"), tmp, ICO_NIC_ONLINE, false);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), _UU("NICINFO_3_1"), ip_str);\r
+                       NicInfoShowStatus(hWnd, info, _UU("NICINFO_3"), tmp, ICO_NIC_ONLINE, false);\r
+               }\r
+\r
+               NicInfoCloseAfterTime(hWnd, info, NICINFO_AUTOCLOSE_TIME_2);\r
+       }\r
+\r
+       MsFreeAdapter(a);\r
+}\r
+void NicInfoInit(HWND hWnd, UI_NICINFO *info)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsWinXPOrWinVista())\r
+       {\r
+               // Windows XP 以降の場合はプログレスバーを表示する\r
+               SendMsg(hWnd, P_BAR, PBM_SETMARQUEE, TRUE, 150);\r
+               SetStyle(hWnd, P_BAR, PBS_MARQUEE);\r
+       }\r
+\r
+       DlgFont(hWnd, S_STATUS1, 9, false);\r
+       DlgFont(hWnd, S_STATUS2, 11, false);\r
+\r
+       SetIcon(hWnd, 0, ICO_NIC_ONLINE);\r
+\r
+       FormatText(hWnd, 0, info->NicName);\r
+\r
+       NicInfoRefresh(hWnd, info);\r
+\r
+       NicInfoCloseAfterTime(hWnd, info, NICINFO_AUTOCLOSE_TIME_1);\r
+}\r
+void NicInfoOnTimer(HWND hWnd, UI_NICINFO *info)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (info->Halt)\r
+       {\r
+               Close(hWnd);\r
+               return;\r
+       }\r
+\r
+       if (info->RouteChange != NULL &&\r
+               IsRouteChanged(info->RouteChange) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       NicInfoRefresh(hWnd, info);\r
+}\r
+\r
+// NIC 情報ダイアログの表示\r
+void NicInfo(UI_NICINFO *info)\r
+{\r
+       // 引数チェック\r
+       if (info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       info->RouteChange = NewRouteChange();\r
+\r
+       DialogEx2(NULL, D_NICINFO, NicInfoProc, info, true, true);\r
+\r
+       FreeRouteChange(info->RouteChange);\r
+       info->RouteChange = NULL;\r
+}\r
+\r
+// TCP 接続スレッド\r
+void WinConnectDlgThread(THREAD *thread, void *param)\r
+{\r
+       SOCK *s;\r
+       WINCONNECT_DLG_DATA *d = (WINCONNECT_DLG_DATA *)param;\r
+       // 引数チェック\r
+       if (d == NULL || thread == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ソケット接続\r
+       s = ConnectEx2(d->hostname, d->port, d->timeout, &d->cancel);\r
+\r
+       d->ret_sock = s;\r
+\r
+       PostMessageA(d->hWnd, WM_APP + 68, 0, 0);\r
+}\r
+\r
+// TCP 接続ダイアログプロシージャ\r
+UINT WinConnectDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       WINCONNECT_DLG_DATA *d = (WINCONNECT_DLG_DATA *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL || d == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // UI 設定\r
+               CenterParent(hWnd);\r
+               SetText(hWnd, 0, d->caption);\r
+               SetText(hWnd, S_INFO, d->info);\r
+               SetIcon(hWnd, S_ICON, d->icon_id);\r
+               d->hWnd = hWnd;\r
+\r
+               if (MsIsWinXPOrWinVista())\r
+               {\r
+                       // Windows XP 以降の場合はプログレスバーを表示する\r
+                       SendMsg(hWnd, IDC_PROGRESS1, PBM_SETMARQUEE, TRUE, 100);\r
+                       SetStyle(hWnd, IDC_PROGRESS1, PBS_MARQUEE);\r
+               }\r
+               else\r
+               {\r
+                       // Windows 2000 以前の場合はプログレスバーを非表示にする\r
+                       Hide(hWnd, IDC_PROGRESS1);\r
+               }\r
+\r
+               // スレッドの作成\r
+               d->thread = NewThread(WinConnectDlgThread, d);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_APP + 68:\r
+       case WM_CLOSE:\r
+               if (d->cancel == false)\r
+               {\r
+                       d->cancel = true;\r
+                       Disable(hWnd, IDCANCEL);\r
+                       if (d->ret_sock == NULL)\r
+                       {\r
+                               SetText(hWnd, S_INFO, _UU("CONNECTDLG_CANCELING"));\r
+                       }\r
+                       DoEvents(hWnd);\r
+                       Refresh(hWnd);\r
+                       WaitThread(d->thread, INFINITE);\r
+                       ReleaseThread(d->thread);\r
+                       EndDialog(hWnd, 0);\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// TCP 接続を UI を表示しながら実施\r
+SOCK *WinConnectEx2(HWND hWnd, char *server, UINT port, UINT timeout, UINT icon_id, wchar_t *caption, wchar_t *info)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       WINCONNECT_DLG_DATA d;\r
+       // 引数チェック\r
+       if (server == NULL || port == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (icon_id == 0)\r
+       {\r
+               icon_id = ICO_USER_ADMIN;\r
+       }\r
+       if (caption == NULL)\r
+       {\r
+               if (hWnd == NULL)\r
+               {\r
+                       caption = _UU("CONNECTDLG_CAPTION");\r
+               }\r
+               else\r
+               {\r
+                       GetTxt(hWnd, 0, tmp2, sizeof(tmp2));\r
+                       caption = tmp2;\r
+               }\r
+       }\r
+       if (info == NULL)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("CONNECTDLG_MESSAGE"), server, port);\r
+\r
+               info = tmp;\r
+       }\r
+\r
+       Zero(&d, sizeof(d));\r
+\r
+       d.cancel = false;\r
+       d.caption = caption;\r
+       d.icon_id = icon_id;\r
+       d.info = info;\r
+       d.timeout = timeout;\r
+       d.hostname = server;\r
+       d.port = port;\r
+\r
+       Dialog(hWnd, D_CONNECT, WinConnectDlgProc, &d);\r
+\r
+       return d.ret_sock;\r
+}\r
+\r
+// Windows ネットワーク設定画面の表示\r
+bool ShowWindowsNetworkConnectionDialog()\r
+{\r
+       wchar_t exe_name[MAX_SIZE];\r
+       void *proc;\r
+\r
+       CombinePathW(exe_name, sizeof(exe_name), MsGetSystem32DirW(), L"control.exe");\r
+\r
+       proc = Win32RunEx2W(exe_name, L"netconnections", false, NULL);\r
+\r
+       if (proc == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Win32CloseProcess(proc);\r
+\r
+       return true;\r
+}\r
+\r
+// メイリオフォントの取得\r
+HFONT GetMeiryoFont()\r
+{\r
+       return GetMeiryoFontEx(0);\r
+}\r
+HFONT GetMeiryoFontEx(UINT font_size)\r
+{\r
+       // 少し適当な処理。日本語版では Meiryo, 中文版では Microsoft YaHei を使用する。\r
+       if (_GETLANG() == 0)\r
+       {\r
+               return GetFont("Meiryo", font_size, false, false, false, false);\r
+       }\r
+       else if (_GETLANG() == 2)\r
+       {\r
+               return GetFont("Microsoft YaHei", font_size, false, false, false, false);\r
+       }\r
+       else\r
+       {\r
+               return GetFont(NULL, font_size, false, false, false, false);\r
+       }\r
+}\r
+\r
+// メイリオフォントに設定\r
+void SetFontMeiryo(HWND hWnd, UINT id)\r
+{\r
+       SetFont(hWnd, id, GetMeiryoFont());\r
+}\r
+\r
+// デフォルトフォントに設定\r
+void SetFontDefault(HWND hWnd, UINT id)\r
+{\r
+       SetFont(hWnd, id, GetDialogDefaultFont());\r
+}\r
+\r
+// 悪いプロセスに関する警告メッセージの表示\r
+void ShowBadProcessWarning(HWND hWnd, BAD_PROCESS *bad)\r
+{\r
+       wchar_t title[MAX_SIZE];\r
+       wchar_t message[8192];\r
+       // 引数チェック\r
+       if (bad == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniFormat(title, sizeof(title), _UU("BAD_PROCESS_TITLE"), bad->Title);\r
+       UniFormat(message, sizeof(message), _UU("BAD_PROCESS_MESSAGE"),\r
+               bad->Title, bad->Title, bad->Title, bad->Title);\r
+\r
+       OnceMsg(hWnd, title, message, true, ICO_WARNING);\r
+}\r
+\r
+// 競合するアンチウイルスソフトの一覧を検索し、該当するものがあれば表示する\r
+bool CheckBadProcesses(HWND hWnd)\r
+{\r
+       bool ret = true;\r
+       UINT i;\r
+       LIST *o;\r
+\r
+       o = MsGetProcessList();\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               MS_PROCESS *p = LIST_DATA(o, i);\r
+               char exe[MAX_PATH];\r
+               BAD_PROCESS *bad;\r
+\r
+               GetFileNameFromFilePath(exe, sizeof(exe), p->ExeFilename);\r
+\r
+               bad = IsBadProcess(exe);\r
+\r
+               if (bad != NULL)\r
+               {\r
+                       // 悪いプロセスを発見したのでメッセージを表示する\r
+                       ret = false;\r
+\r
+                       ShowBadProcessWarning(hWnd, bad);\r
+               }\r
+       }\r
+\r
+       MsFreeProcessList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 指定したプロセス名が悪いプロセスに該当するかどうか検索する\r
+BAD_PROCESS *IsBadProcess(char *exe)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (exe == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < num_bad_processes;i++)\r
+       {\r
+               BAD_PROCESS *bad = &bad_processes[i];\r
+\r
+               if (StrCmpi(bad->ExeName, exe) == 0)\r
+               {\r
+                       return bad;\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// メッセージ表示プロシージャ\r
+UINT OnceMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       ONCEMSG_DLG *d = (ONCEMSG_DLG *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetText(hWnd, 0, d->Title);\r
+               SetText(hWnd, E_TEXT, d->Message);\r
+               SetShow(hWnd, C_DONTSHOWAGAIN, d->ShowCheckbox);\r
+               //DisableClose(hWnd);\r
+               Focus(hWnd, IDCANCEL);\r
+               if (d->Icon != 0)\r
+               {\r
+                       SetIcon(hWnd, 0, d->Icon);\r
+               }\r
+\r
+               if (MsIsVista())\r
+               {\r
+                       SetFont(hWnd, E_TEXT, GetMeiryoFont());\r
+               }\r
+               else\r
+               {\r
+                       DlgFont(hWnd, E_TEXT, 11, false);\r
+               }\r
+\r
+               SetTimer(hWnd, 1, 50, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       if (*d->halt)\r
+                       {\r
+                               Close(hWnd);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               KillTimer(hWnd, 1);\r
+               d->Checked = IsChecked(hWnd, C_DONTSHOWAGAIN);\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// メッセージを表示する\r
+void OnceMsg(HWND hWnd, wchar_t *title, wchar_t *message, bool show_checkbox, UINT icon)\r
+{\r
+       OnceMsgEx(hWnd, title, message, show_checkbox, icon, NULL);\r
+}\r
+void OnceMsgEx(HWND hWnd, wchar_t *title, wchar_t *message, bool show_checkbox, UINT icon, bool *halt)\r
+{\r
+       ONCEMSG_DLG d;\r
+       UINT hash;\r
+       char valuename[MAX_PATH];\r
+       bool b_dummy = false;\r
+       // 引数チェック\r
+       if (title == NULL)\r
+       {\r
+               title = title_bar;\r
+       }\r
+       if (message == NULL)\r
+       {\r
+               message = L"message";\r
+       }\r
+       if (halt == NULL)\r
+       {\r
+               halt = &b_dummy;\r
+       }\r
+\r
+       Zero(&d, sizeof(d));\r
+       d.Message = message;\r
+       d.Title = title;\r
+       d.ShowCheckbox = show_checkbox;\r
+       d.Icon = icon;\r
+       d.halt = halt;\r
+\r
+       hash = GetOnceMsgHash(title, message);\r
+       Format(valuename, sizeof(valuename), ONCE_MSG_REGVALUE, hash);\r
+\r
+       if (MsRegReadInt(REG_CURRENT_USER, ONCE_MSG_REGKEY, valuename) == 0)\r
+       {\r
+               switch (icon)\r
+               {\r
+               case ICO_WARNING:\r
+                       MessageBeep(MB_ICONEXCLAMATION);\r
+                       break;\r
+\r
+               case ICO_INFORMATION:\r
+                       MessageBeep(MB_ICONASTERISK);\r
+                       break;\r
+               }\r
+\r
+               Dialog(hWnd, D_ONCEMSG, OnceMsgProc, &d);\r
+\r
+               if (show_checkbox)\r
+               {\r
+                       if (d.Checked)\r
+                       {\r
+                               MsRegWriteInt(REG_CURRENT_USER, ONCE_MSG_REGKEY, valuename, 1);\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// メッセージハッシュの取得\r
+UINT GetOnceMsgHash(wchar_t *title, wchar_t *message)\r
+{\r
+       BUF *b;\r
+       UCHAR hash[SHA1_SIZE];\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (title == NULL)\r
+       {\r
+               title = title_bar;\r
+       }\r
+       if (message == NULL)\r
+       {\r
+               message = L"message";\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, title, UniStrSize(title));\r
+       WriteBuf(b, message, UniStrSize(message));\r
+       HashSha1(hash, b->Buf, b->Size);\r
+       FreeBuf(b);\r
+\r
+       Copy(&ret, hash, sizeof(UINT));\r
+\r
+       return ret;\r
+}\r
+\r
+// Windows Vista のテーマを設定する\r
+void InitVistaWindowTheme(HWND hWnd)\r
+{\r
+       static HINSTANCE hInstDll = NULL;\r
+       HRESULT (WINAPI *_SetWindowTheme)(HWND, LPCWSTR, LPCWSTR) = NULL;\r
+\r
+       if (MsIsVista() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (hInstDll == NULL)\r
+       {\r
+               hInstDll = LoadLibraryA("uxtheme.dll");\r
+       }\r
+\r
+       if (hInstDll == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (_SetWindowTheme == NULL)\r
+       {\r
+               _SetWindowTheme = (HRESULT (WINAPI *)(HWND,LPCWSTR,LPCWSTR))GetProcAddress(hInstDll, "SetWindowTheme");\r
+       }\r
+\r
+       if (_SetWindowTheme == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       _SetWindowTheme(hWnd, L"explorer", NULL);\r
+}\r
+\r
+// 現在のディレクトリに存在する可能性のある Windows ファイアウォールに登録すべき\r
+// すべてのアプリケーションを登録する\r
+// Q. 行儀が悪いのではないか?\r
+// A. 確かに行儀が悪いが、Windows Firewall でブロックされていることが原因で\r
+//    VPN ソフトウェアが使用できないという苦情メールがよく来ていたので\r
+//    やむを得ずこのように行うことにした。\r
+//    なお、Microsoft 純正のサーバーソフトや他社のサーバーソフト等もこのように\r
+//    して対応しているようであるから、良いのではないか。\r
+void RegistWindowsFirewallAll()\r
+{\r
+       MsRegistWindowsFirewallEx2(CEDAR_CLIENT_STR, "utvpnclient.exe");\r
+       MsRegistWindowsFirewallEx2(CEDAR_CLIENT_STR, "utvpnclient_x64.exe");\r
+       MsRegistWindowsFirewallEx2(CEDAR_CLIENT_STR, "utvpnclient_ia64.exe");\r
+\r
+       MsRegistWindowsFirewallEx2(CEDAR_CLIENT_MANAGER_STR, "utvpncmgr.exe");\r
+       MsRegistWindowsFirewallEx2(CEDAR_CLIENT_MANAGER_STR, "utvpncmgr_x64.exe");\r
+       MsRegistWindowsFirewallEx2(CEDAR_CLIENT_MANAGER_STR, "utvpncmgr_ia64.exe");\r
+\r
+       MsRegistWindowsFirewallEx2(CEDAR_SERVER_STR, "utvpnserver.exe");\r
+       MsRegistWindowsFirewallEx2(CEDAR_SERVER_STR, "utvpnserver_x64.exe");\r
+       MsRegistWindowsFirewallEx2(CEDAR_SERVER_STR, "utvpnserver_ia64.exe");\r
+\r
+       MsRegistWindowsFirewallEx2(CEDAR_CUI_STR, "utvpncmd.exe");\r
+       MsRegistWindowsFirewallEx2(CEDAR_CUI_STR, "utvpncmd_x64.exe");\r
+       MsRegistWindowsFirewallEx2(CEDAR_CUI_STR, "utvpncmd_ia64.exe");\r
+\r
+       MsRegistWindowsFirewallEx2(CEDAR_PRODUCT_STR, "ham.exe");\r
+       MsRegistWindowsFirewallEx2(CEDAR_PRODUCT_STR, "ham_x64.exe");\r
+       MsRegistWindowsFirewallEx2(CEDAR_PRODUCT_STR, "ham_ia64.exe");\r
+}\r
+\r
+// すでに通知サービスが動作しているかどうかチェックする\r
+bool Win32CnCheckAlreadyExists(bool lock)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       HANDLE hMutex;\r
+\r
+       HashInstanceNameLocal(tmp, sizeof(tmp), CLIENT_NOTIFY_SERVICE_INSTANCENAME);\r
+\r
+       hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, tmp);\r
+       if (hMutex != NULL)\r
+       {\r
+               CloseHandle(hMutex);\r
+               return true;\r
+       }\r
+\r
+       if (lock == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       hMutex = CreateMutex(NULL, FALSE, tmp);\r
+       if (hMutex == NULL)\r
+       {\r
+               CloseHandle(hMutex);\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// hamcore 内の EXE の実行\r
+bool ExecuteHamcoreExe(char *name)\r
+{\r
+       BUF *b;\r
+       wchar_t tmp[MAX_PATH];\r
+       char tmp2[MAX_PATH];\r
+       UCHAR hash[MD5_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = ReadDump(name);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Hash(hash, name, StrLen(name), false);\r
+       BinToStr(tmp2, sizeof(tmp2), hash, sizeof(hash));\r
+       UniFormat(tmp, sizeof(tmp), L"%s\\tmp_%S.exe", MsGetMyTempDirW(), tmp2);\r
+       SeekBuf(b, 0, 0);\r
+       DumpBufW(b, tmp);\r
+\r
+       FreeBuf(b);\r
+\r
+       return RunW(tmp, NULL, false, false);\r
+}\r
+\r
+// イースターエッグの表示\r
+void ShowEasterEgg(HWND hWnd)\r
+{\r
+}\r
+\r
+void KakushiThread(THREAD *thread, void *param)\r
+{\r
+       KAKUSHI *k;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       k = (KAKUSHI *)param;\r
+\r
+       k->Thread = thread;\r
+       AddRef(k->Thread->ref);\r
+       NoticeThreadInit(thread);\r
+\r
+       Dialog(NULL, D_CM_KAKUSHI, KakushiDlgProc, k);\r
+       k->hWnd = NULL;\r
+}\r
+\r
+KAKUSHI *InitKakushi()\r
+{\r
+       THREAD *t;\r
+       KAKUSHI *k = ZeroMalloc(sizeof(KAKUSHI));\r
+\r
+       t = NewThread(KakushiThread, k);\r
+\r
+       WaitThreadInit(t);\r
+       ReleaseThread(t);\r
+\r
+       return k;\r
+}\r
+\r
+UINT KakushiDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       KAKUSHI *k = (KAKUSHI *)param;\r
+       UINT64 now;\r
+       bool b;\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetText(hWnd, S_INFO, _UU("CM_VLAN_CREATING"));\r
+\r
+               b = false;\r
+\r
+               if (MsIsVista())\r
+               {\r
+                       if (_GETLANG() == 0)\r
+                       {\r
+                               SetFont(hWnd, S_INFO, GetFont("Meiryo", 11, false, false, false, false));\r
+                               b = true;\r
+                       }\r
+                       else if (_GETLANG() == 2)\r
+                       {\r
+                               SetFont(hWnd, S_INFO, GetFont("Microsoft YaHei", 11, false, false, false, false));\r
+                               b = true;\r
+                       }\r
+               }\r
+\r
+               if (b == false)\r
+               {\r
+                       DlgFont(hWnd, S_INFO, 11, false);\r
+               }\r
+\r
+               SetTimer(hWnd, 1, 50, NULL);\r
+               k->hWnd = hWnd;\r
+\r
+               k->Span = 20 * 1000;\r
+               k->StartTick = Tick64();\r
+\r
+               SetRange(hWnd, P_PROGRESS, 0, (UINT)k->Span);\r
+\r
+       case WM_APP + 9821:\r
+               now = Tick64();\r
+\r
+               if (((k->StartTick + k->Span) <= now) || k->Halt)\r
+               {\r
+                       EndDialog(hWnd, 0);\r
+                       break;\r
+               }\r
+\r
+               SetPos(hWnd, P_PROGRESS, (UINT)(now - k->StartTick));\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       AllowSetForegroundWindow(ASFW_ANY);\r
+                       SetForegroundWindow(hWnd);\r
+                       SetActiveWindow(hWnd);\r
+\r
+                       now = Tick64();\r
+\r
+                       if (((k->StartTick + k->Span) <= now) || k->Halt)\r
+                       {\r
+                               EndDialog(hWnd, 0);\r
+                               break;\r
+                       }\r
+\r
+                       SetPos(hWnd, P_PROGRESS, (UINT)(now - k->StartTick));\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               return 1;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 隠し画面解放\r
+void FreeKakushi(KAKUSHI *k)\r
+{\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       k->Halt = true;\r
+\r
+       if (k->hWnd != NULL)\r
+       {\r
+               PostMessage(k->hWnd, WM_APP + 9821, 0, 0);\r
+       }\r
+\r
+       WaitThread(k->Thread, INFINITE);\r
+       ReleaseThread(k->Thread);\r
+\r
+       Free(k);\r
+}\r
+\r
+// TCP/IP 最適化選択ダイアログプロシージャ\r
+UINT TcpMsgDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetIcon(hWnd, 0, ICO_SETUP);\r
+               //DlgFont(hWnd, R_OPTIMIZE, 0, true);\r
+\r
+               Check(hWnd, R_NO, true);\r
+\r
+               if (g_tcpip_topmost)\r
+               {\r
+                       Top(hWnd);\r
+               }\r
+\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       ret = 1;\r
+                       if (IsChecked(hWnd, R_MANUAL))\r
+                       {\r
+                               ret = 2;\r
+                       }\r
+                       else if (IsChecked(hWnd, R_NO))\r
+                       {\r
+                               ret = 0;\r
+                       }\r
+\r
+                       EndDialog(hWnd, ret);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               return 1;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ダイアログ初期化\r
+void TcpIpDlgInit(HWND hWnd)\r
+{\r
+       MS_TCP tcp;\r
+\r
+       SetIcon(hWnd, 0, ICO_SETUP);\r
+\r
+       MsGetTcpConfig(&tcp);\r
+\r
+       Check(hWnd, R_RECV_DISABLE, tcp.RecvWindowSize == 0);\r
+       Check(hWnd, R_RECV_ENABLE, tcp.RecvWindowSize != 0);\r
+       SetInt(hWnd, E_RECV, tcp.RecvWindowSize != 0 ? tcp.RecvWindowSize : DEFAULT_TCP_MAX_WINDOW_SIZE_RECV);\r
+\r
+       Check(hWnd, R_SEND_DISABLE, tcp.SendWindowSize == 0);\r
+       Check(hWnd, R_SEND_ENABLE, tcp.SendWindowSize != 0);\r
+       SetInt(hWnd, E_SEND, tcp.SendWindowSize != 0 ? tcp.SendWindowSize : DEFAULT_TCP_MAX_WINDOW_SIZE_SEND);\r
+\r
+       TcpIpDlgUpdate(hWnd);\r
+}\r
+\r
+// ダイアログ更新\r
+void TcpIpDlgUpdate(HWND hWnd)\r
+{\r
+       bool ok = true;\r
+\r
+       SetEnable(hWnd, E_RECV, IsChecked(hWnd, R_RECV_ENABLE));\r
+       SetEnable(hWnd, S_RECV, IsChecked(hWnd, R_RECV_ENABLE));\r
+       SetEnable(hWnd, E_SEND, IsChecked(hWnd, R_SEND_ENABLE));\r
+       SetEnable(hWnd, S_SEND, IsChecked(hWnd, R_SEND_ENABLE));\r
+\r
+       if (IsChecked(hWnd, R_RECV_ENABLE) && GetInt(hWnd, E_RECV) < 1454)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       if (IsChecked(hWnd, R_SEND_ENABLE) && GetInt(hWnd, E_SEND) < 1454)\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// TCP/IP ダイアログプロシージャ\r
+UINT TcpIpDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       MS_TCP tcp, old;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               TcpIpDlgInit(hWnd);\r
+\r
+               if (g_tcpip_topmost)\r
+               {\r
+                       Top(hWnd);\r
+               }\r
+\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_RECV_DISABLE:\r
+               case R_RECV_ENABLE:\r
+               case R_SEND_DISABLE:\r
+               case R_SEND_ENABLE:\r
+               case E_RECV:\r
+               case E_SEND:\r
+                       TcpIpDlgUpdate(hWnd);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       Zero(&tcp, sizeof(tcp));\r
+\r
+                       if (IsChecked(hWnd, R_RECV_ENABLE))\r
+                       {\r
+                               tcp.RecvWindowSize = GetInt(hWnd, E_RECV);\r
+                       }\r
+\r
+                       if (IsChecked(hWnd, R_SEND_ENABLE))\r
+                       {\r
+                               tcp.SendWindowSize = GetInt(hWnd, E_SEND);\r
+                       }\r
+\r
+                       MsGetTcpConfig(&old);\r
+\r
+                       MsSetTcpConfig(&tcp);\r
+                       MsSaveTcpConfigReg(&tcp);\r
+\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+\r
+               case R_RECV_ENABLE:\r
+                       FocusEx(hWnd, E_RECV);\r
+                       break;\r
+\r
+               case R_SEND_ENABLE:\r
+                       FocusEx(hWnd, E_SEND);\r
+                       break;\r
+\r
+               case B_RECV:\r
+                       SetInt(hWnd, E_RECV, DEFAULT_TCP_MAX_WINDOW_SIZE_RECV);\r
+                       Check(hWnd, R_RECV_DISABLE, false);\r
+                       Check(hWnd, R_RECV_ENABLE, true);\r
+                       TcpIpDlgUpdate(hWnd);\r
+                       FocusEx(hWnd, E_RECV);\r
+                       break;\r
+\r
+               case B_SEND:\r
+                       SetInt(hWnd, E_SEND, DEFAULT_TCP_MAX_WINDOW_SIZE_SEND);\r
+                       Check(hWnd, R_SEND_DISABLE, false);\r
+                       Check(hWnd, R_SEND_ENABLE, true);\r
+                       TcpIpDlgUpdate(hWnd);\r
+                       FocusEx(hWnd, E_SEND);\r
+                       break;\r
+\r
+               case B_DELETE:\r
+                       Zero(&tcp, sizeof(tcp));\r
+                       MsSetTcpConfig(&tcp);\r
+                       MsDeleteTcpConfigReg();\r
+                       EndDialog(hWnd, 0);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 64 bit に関する警告ダイアログ\r
+UINT Cpu64DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetIcon(hWnd, 0, ICO_WARNING);\r
+               DlgFont(hWnd, S_BOLD, 9, true);\r
+               SetTimer(hWnd, 1, 30 * 1000, NULL);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       Command(hWnd, IDOK);\r
+                       break;\r
+               }\r
+\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 64 bit に関する警告ダイアログの表示\r
+void ShowCpu64Warning()\r
+{\r
+       Dialog(NULL, D_CPU64_WARNING, Cpu64DlgProc, NULL);\r
+}\r
+\r
+// TCP/IP 設定ユーティリティの表示\r
+void ShowTcpIpConfigUtil(HWND hWnd, bool util_mode)\r
+{\r
+       if (MsIsTcpConfigSupported() == false)\r
+       {\r
+               if (util_mode)\r
+               {\r
+                       // 現在の OS ではサポートされていない旨のメッセージを表示\r
+                       if (MsIsAdmin() == false)\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("TCPOPT_NOT_ADMIN"));\r
+                       }\r
+                       else\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONINFORMATION, _UU("TCPOPT_NOT_SUPPORTED"));\r
+                       }\r
+               }\r
+               return;\r
+       }\r
+\r
+       if (util_mode == false)\r
+       {\r
+               // utvpncmd を起動してすぐに終了する\r
+               wchar_t tmp[MAX_PATH];\r
+               wchar_t exedir[MAX_PATH];\r
+               HANDLE h;\r
+\r
+               GetExeDirW(exedir, sizeof(exedir));\r
+\r
+               if (IsX64())\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), L"%s\\utvpncmd_x64.exe", exedir);\r
+               }\r
+               else if (IsIA64())\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), L"%s\\utvpncmd_ia64.exe", exedir);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(tmp, sizeof(tmp), L"%s\\utvpncmd.exe", exedir);\r
+               }\r
+\r
+               if (IsFileW(tmp))\r
+               {\r
+                       RunW(tmp, L"/tool /cmd:exit", true, false);\r
+               }\r
+\r
+               // netsh によるタスクオフローディングの無効化\r
+               if (MsIsVista())\r
+               {\r
+                       char netsh_exe[MAX_SIZE];\r
+                       DIRLIST *dl;\r
+                       UINT i;\r
+                       bool b = false;\r
+\r
+                       dl = EnumDirW(exedir);\r
+\r
+                       for (i = 0;i < dl->NumFiles;i++)\r
+                       {\r
+                               if (UniInStr(dl->File[i]->FileNameW, L"utvpnbridge") || \r
+                                       UniInStr(dl->File[i]->FileNameW, L"utvpnserver"))\r
+                               {\r
+                                       b = true;\r
+                               }\r
+                       }\r
+\r
+                       FreeDir(dl);\r
+\r
+                       if (b)\r
+                       {\r
+                               CombinePath(netsh_exe, sizeof(netsh_exe), MsGetSystem32Dir(), "netsh.exe");\r
+\r
+                               Run(netsh_exe, "netsh int ipv6 set global taskoffload=disabled", true, false);\r
+                               Run(netsh_exe, "netsh int ipv4 set global taskoffload=disabled", true, false);\r
+                       }\r
+               }\r
+\r
+               // Windows Firewall 登録\r
+               RegistWindowsFirewallAll();\r
+\r
+               SleepThread(1000);\r
+\r
+               // utvpnclient.exe /uihelp の起動\r
+               h = CmExecUiHelperMain();\r
+               if (h != NULL)\r
+               {\r
+                       CloseHandle(h);\r
+               }\r
+\r
+               if (Is64() == false)\r
+               {\r
+                       if (MsIs64BitWindows())\r
+                       {\r
+                               // 32 bit 版を 64 bit Windows 上で使用している場合は\r
+                               // 警告メッセージを表示する\r
+                               ShowCpu64Warning();\r
+                       }\r
+               }\r
+\r
+               if (MsIsAdmin())\r
+               {\r
+                       if (MsIsVista())\r
+                       {\r
+                               // Windows Vista でインストールする場合は\r
+                               // MMCSS のネットワーク制限を解除する\r
+                               if (MsIsMMCSSNetworkThrottlingEnabled())\r
+                               {\r
+                                       MsSetMMCSSNetworkThrottlingEnable(false);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (util_mode == false && MsIsShouldShowTcpConfigApp() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (util_mode == false)\r
+       {\r
+               // 2006.07.04 nobori\r
+               // インストーラ上では TCP/IP 最適化ユーティリティは表示しないことにした\r
+               return;\r
+       }\r
+\r
+       g_tcpip_topmost = util_mode ? false : true;\r
+\r
+       if (util_mode == false)\r
+       {\r
+               UINT ret = Dialog(hWnd, D_TCP_MSG, TcpMsgDlgProc, NULL);\r
+\r
+               if (ret == 0)\r
+               {\r
+                       MS_TCP tcp;\r
+\r
+                       Zero(&tcp, sizeof(tcp));\r
+                       MsGetTcpConfig(&tcp);\r
+                       MsSaveTcpConfigReg(&tcp);\r
+                       return;\r
+               }\r
+               else if (ret == 1)\r
+               {\r
+                       MS_TCP tcp;\r
+\r
+                       Zero(&tcp, sizeof(tcp));\r
+\r
+                       tcp.RecvWindowSize = DEFAULT_TCP_MAX_WINDOW_SIZE_RECV;\r
+                       tcp.SendWindowSize = DEFAULT_TCP_MAX_WINDOW_SIZE_SEND;\r
+                       MsSetTcpConfig(&tcp);\r
+                       MsSaveTcpConfigReg(&tcp);\r
+\r
+                       return;\r
+               }\r
+       }\r
+\r
+       Dialog(hWnd, D_TCP, TcpIpDlgProc, NULL);\r
+}\r
+\r
+// メニューの国際化対応処理を行う (Unicode)\r
+void InitMenuInternationalUni(HMENU hMenu, char *prefix)\r
+{\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (hMenu == NULL || prefix == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メニューの項目数を取得する\r
+       num = GetMenuItemCount(hMenu);\r
+\r
+       // メニューを列挙する\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               HMENU hSubMenu = GetSubMenu(hMenu, i);\r
+               MENUITEMINFOW info;\r
+               wchar_t tmp[MAX_SIZE];\r
+\r
+               if (hSubMenu != NULL)\r
+               {\r
+                       // サブメニューがある場合再帰呼び出しする\r
+                       InitMenuInternational(hSubMenu, prefix);\r
+               }\r
+\r
+               // メニュー項目を取得する\r
+               Zero(&info, sizeof(info));\r
+               info.cbSize = sizeof(info);\r
+               info.cch = sizeof(tmp);\r
+               info.dwTypeData = tmp;\r
+               info.fMask = MIIM_STRING;\r
+               Zero(tmp, sizeof(tmp));\r
+\r
+               if (GetMenuItemInfoW(hMenu, i, true, &info))\r
+               {\r
+                       if (tmp[0] == L'@')\r
+                       {\r
+                               char name[256];\r
+                               wchar_t *ret;\r
+\r
+                               Format(name, sizeof(name), "%s@%S", prefix, &tmp[1]);\r
+\r
+                               ret = _UU(name);\r
+                               if (UniIsEmptyStr(ret) == false)\r
+                               {\r
+                                       UniStrCpy(tmp, sizeof(tmp), ret);\r
+                                       info.cch = UniStrLen(tmp);\r
+\r
+                                       SetMenuItemInfoW(hMenu, i, true, &info);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// メニューの国際化対応処理を行う\r
+void InitMenuInternational(HMENU hMenu, char *prefix)\r
+{\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (hMenu == NULL || prefix == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsNt())\r
+       {\r
+               InitMenuInternationalUni(hMenu, prefix);\r
+               return;\r
+       }\r
+\r
+       // メニューの項目数を取得する\r
+       num = GetMenuItemCount(hMenu);\r
+\r
+       // メニューを列挙する\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               HMENU hSubMenu = GetSubMenu(hMenu, i);\r
+               MENUITEMINFO info;\r
+               char tmp[MAX_SIZE];\r
+\r
+               if (hSubMenu != NULL)\r
+               {\r
+                       // サブメニューがある場合再帰呼び出しする\r
+                       InitMenuInternational(hSubMenu, prefix);\r
+               }\r
+\r
+               // メニュー項目を取得する\r
+               Zero(&info, sizeof(info));\r
+               info.cbSize = sizeof(info);\r
+               info.cch = sizeof(tmp);\r
+               info.dwTypeData = tmp;\r
+               info.fMask = MIIM_STRING;\r
+               Zero(tmp, sizeof(tmp));\r
+\r
+               if (GetMenuItemInfo(hMenu, i, true, &info))\r
+               {\r
+                       if (tmp[0] == '@')\r
+                       {\r
+                               char name[256];\r
+                               char *ret;\r
+\r
+                               Format(name, sizeof(name), "%s@%s", prefix, &tmp[1]);\r
+\r
+                               ret = _SS(name);\r
+                               if (IsEmptyStr(ret) == false)\r
+                               {\r
+                                       StrCpy(tmp, sizeof(tmp), ret);\r
+                                       info.cch = StrLen(tmp);\r
+\r
+                                       SetMenuItemInfo(hMenu, i, true, &info);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// ダイアログボックス用のデフォルトのフォントを取得する\r
+HFONT GetDialogDefaultFont()\r
+{\r
+       return GetDialogDefaultFontEx(false);\r
+}\r
+HFONT GetDialogDefaultFontEx(bool meiryo)\r
+{\r
+       char *default_font_name = _SS("DEFAULT_FONT");\r
+       UINT default_font_size = _II("DEFAULT_FONT_SIZE");\r
+\r
+       if (meiryo)\r
+       {\r
+               if (_GETLANG() == 2)\r
+               {\r
+                       default_font_name = "Microsoft YaHei";\r
+               }\r
+               else\r
+               {\r
+                       default_font_name = "Meiryo";\r
+               }\r
+       }\r
+\r
+       if (IsEmptyStr(default_font_name))\r
+       {\r
+               default_font_name = font_name;\r
+       }\r
+\r
+       if (default_font_size == 0)\r
+       {\r
+               default_font_size = 9;\r
+       }\r
+\r
+       return GetFont(default_font_name, default_font_size, false, false, false, false);\r
+}\r
+\r
+// ウインドウサイズとコントロールサイズを調整する\r
+void AdjustWindowAndControlSize(HWND hWnd)\r
+{\r
+       HFONT hDlgFont;\r
+       UINT dlgfont_x, dlgfont_y;\r
+       RECT rect, rect2;\r
+       LIST *o;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 現在のウインドウのフォントを取得する\r
+       hDlgFont = (HFONT)SendMsg(hWnd, 0, WM_GETFONT, 0, 0);\r
+\r
+       // 現在のウインドウのフォントの幅と高さを取得する\r
+       CalcFontSize(hDlgFont, &dlgfont_x, &dlgfont_y);\r
+\r
+       if ((dlgfont_x == WINUI_DEFAULT_DIALOG_UNIT_X) &&\r
+               (dlgfont_y == WINUI_DEFAULT_DIALOG_UNIT_Y))\r
+       {\r
+               // 調整する必要が無い\r
+               return;\r
+       }\r
+\r
+       // ウインドウのサイズを調整する\r
+       if (GetWindowRect(hWnd, &rect))\r
+       {\r
+               if (GetClientRect(hWnd, &rect2))\r
+               {\r
+                       UINT width = rect2.right - rect2.left;\r
+                       UINT height = rect2.bottom - rect2.top;\r
+\r
+                       AdjustDialogXY(&width, &height, dlgfont_x, dlgfont_y);\r
+\r
+                       width += (rect.right - rect.left) - (rect2.right - rect2.left);\r
+                       height += (rect.bottom - rect.top) - (rect2.bottom - rect2.top);\r
+\r
+                       if (true)\r
+                       {\r
+                               HWND hParent = GetParent(hWnd);\r
+\r
+                               if (hParent != NULL)\r
+                               {\r
+                                       RECT r;\r
+\r
+                                       Zero(&r, sizeof(r));\r
+\r
+                                       if (GetWindowRect(hParent, &r))\r
+                                       {\r
+                                               RECT r2;\r
+\r
+                                               rect.top = r.top + GetSystemMetrics(SM_CYCAPTION);\r
+\r
+                                               Zero(&r2, sizeof(r2));\r
+                                               if (SystemParametersInfo(SPI_GETWORKAREA, 0, &r2, 0))\r
+                                               {\r
+                                                       if (r2.bottom < (rect.top + (int)height))\r
+                                                       {\r
+                                                               rect.top -= (rect.top + (int)height) - r2.bottom;\r
+\r
+                                                               if (rect.top < 0)\r
+                                                               {\r
+                                                                       rect.top = 0;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       MoveWindow(hWnd, rect.left, rect.top, width, height, false);\r
+               }\r
+       }\r
+\r
+       // 子ウインドウを列挙する\r
+       o = EnumAllChildWindowEx(hWnd, false, true, true);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               // 子ウインドウのサイズを調整する\r
+               HWND h = *((HWND *)LIST_DATA(o, i));\r
+               HWND hWndParent = GetParent(h);\r
+               RECT current_rect;\r
+               char class_name[MAX_PATH];\r
+               bool is_image = false;\r
+\r
+               // クラス名を取得\r
+               Zero(class_name, sizeof(class_name));\r
+               GetClassNameA(h, class_name, sizeof(class_name));\r
+\r
+               if (StrCmpi(class_name, "static") == 0)\r
+               {\r
+                       if (SendMsg(h, 0, STM_GETIMAGE, IMAGE_BITMAP, 0) != 0 ||\r
+                               SendMsg(h, 0, STM_GETIMAGE, IMAGE_ICON, 0) != 0 ||\r
+                               SendMsg(h, 0, STM_GETICON, 0, 0) != 0)\r
+                       {\r
+                               is_image = true;\r
+                       }\r
+               }\r
+\r
+               // 位置を取得\r
+               if (GetWindowRect(h, &current_rect))\r
+               {\r
+                       // クライアント座標に変換\r
+                       POINT p1, p2;\r
+\r
+                       p1.x = current_rect.left;\r
+                       p1.y = current_rect.top;\r
+\r
+                       p2.x = current_rect.right;\r
+                       p2.y = current_rect.bottom;\r
+\r
+                       ScreenToClient(hWndParent, &p1);\r
+                       ScreenToClient(hWndParent, &p2);\r
+\r
+                       // 位置を調整\r
+                       AdjustDialogXY(&p1.x, &p1.y, dlgfont_x, dlgfont_y);\r
+                       AdjustDialogXY(&p2.x, &p2.y, dlgfont_x, dlgfont_y);\r
+\r
+                       if (is_image)\r
+                       {\r
+                               p2.x = p1.x + (current_rect.right - current_rect.left);\r
+                               p2.y = p1.y + (current_rect.bottom - current_rect.top);\r
+                       }\r
+\r
+                       // 移動\r
+                       MoveWindow(h, p1.x, p1.y, p2.x - p1.x, p2.y - p1.y, false);\r
+               }\r
+       }\r
+\r
+       FreeWindowList(o);\r
+}\r
+\r
+// x と y の値をフォントに応じて調整する\r
+void AdjustDialogXY(UINT *x, UINT *y, UINT dlgfont_x, UINT dlgfont_y)\r
+{\r
+       if (x != NULL)\r
+       {\r
+               *x = (UINT)(((double)*x) * (double)WINUI_DEFAULT_DIALOG_UNIT_X / (double)dlgfont_x);\r
+       }\r
+\r
+       if (y != NULL)\r
+       {\r
+               *y = (UINT)(((double)*y) * (double)WINUI_DEFAULT_DIALOG_UNIT_Y / (double)dlgfont_y);\r
+       }\r
+}\r
+\r
+// ダイアログボックスの国際化対応処理を行う\r
+void InitDialogInternational(HWND hWnd, void *param)\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       bool is_managed_dialog = false;\r
+       char caption[MAX_PATH];\r
+       char *dialog_name;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       AdjustWindowAndControlSize(hWnd);\r
+\r
+       GetTxtA(hWnd, 0, caption, sizeof(caption));\r
+       if (caption[0] == '@')\r
+       {\r
+               dialog_name = &caption[1];\r
+\r
+               is_managed_dialog = true;\r
+       }\r
+\r
+       // すべてのウインドウハンドルを列挙する\r
+       o = EnumAllChildWindow(hWnd);\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               HWND hControl = *((HWND *)LIST_DATA(o, i));\r
+\r
+               if (hControl != NULL)\r
+               {\r
+                       HFONT hFont = GetDialogDefaultFontEx(param && ((DIALOG_PARAM *)param)->meiryo);\r
+\r
+                       SetFont(hControl, 0, hFont);\r
+\r
+                       if (MsIsVista())\r
+                       {\r
+                               char classname[MAX_PATH];\r
+                               GetClassNameA(hControl, classname, sizeof(classname));\r
+\r
+                               if (StrCmpi(classname, "syslistview32") == 0)\r
+                               {\r
+                                       InitVistaWindowTheme(hControl);\r
+                               }\r
+                       }\r
+\r
+                       if (is_managed_dialog)\r
+                       {\r
+                               char str[MAX_PATH];\r
+\r
+                               GetTxtA(hControl, 0, str, sizeof(str));\r
+                               if (str[0] == '@')\r
+                               {\r
+                                       char *control_name = &str[1];\r
+                                       char tmp[MAX_PATH];\r
+                                       wchar_t *ret;\r
+\r
+                                       StrCpy(tmp, sizeof(tmp), dialog_name);\r
+                                       StrCat(tmp, sizeof(tmp), "@");\r
+\r
+                                       if (hWnd == hControl)\r
+                                       {\r
+                                               StrCat(tmp, sizeof(tmp), "CAPTION");\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               StrCat(tmp, sizeof(tmp), control_name);\r
+                                       }\r
+\r
+                                       ret = _UU(tmp);\r
+\r
+                                       if (ret != NULL && UniIsEmptyStr(ret) == false)\r
+                                       {\r
+                                               SetText(hControl, 0, ret);\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeWindowList(o);\r
+}\r
+\r
+// 子ウインドウ列挙プロシージャ\r
+// ダイアログ初期化\r
+void StringDlgInit(HWND hWnd, STRING_DLG *s)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetText(hWnd, E_STRING, s->String);\r
+\r
+       SetIcon(hWnd, S_ICON, s->Icon);\r
+       SetText(hWnd, S_INFO, s->Info);\r
+       SetText(hWnd, 0, s->Title);\r
+\r
+       FocusEx(hWnd, E_STRING);\r
+\r
+       StringDlgUpdate(hWnd, s);\r
+}\r
+\r
+// ダイアログコントロール更新\r
+void StringDlgUpdate(HWND hWnd, STRING_DLG *s)\r
+{\r
+       wchar_t *tmp;\r
+       bool b = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tmp = GetText(hWnd, E_STRING);\r
+\r
+       if (tmp != NULL)\r
+       {\r
+               if (s->AllowEmpty == false)\r
+               {\r
+                       if (UniIsEmptyStr(tmp))\r
+                       {\r
+                               b = false;\r
+                       }\r
+               }\r
+\r
+               if (s->AllowUnsafe == false)\r
+               {\r
+                       if (IsSafeUniStr(tmp) == false)\r
+                       {\r
+                               b = false;\r
+                       }\r
+               }\r
+\r
+               Free(tmp);\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, b);\r
+}\r
+\r
+// 文字列ダイアログプロシージャ\r
+UINT StringDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       STRING_DLG *s = (STRING_DLG *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               StringDlgInit(hWnd, s);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_STRING:\r
+                       StringDlgUpdate(hWnd, s);\r
+                       break;\r
+               }\r
+\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       GetTxt(hWnd, E_STRING, s->String, sizeof(s->String));\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 文字列ダイアログを表示する\r
+wchar_t *StringDlg(HWND hWnd, wchar_t *title, wchar_t *info, wchar_t *def, UINT icon, bool allow_empty, bool allow_unsafe)\r
+{\r
+       STRING_DLG s;\r
+       // 引数チェック\r
+       if (title == NULL)\r
+       {\r
+               title = _UU("DLG_STRING_DEFTITLE");\r
+       }\r
+       if (info == NULL)\r
+       {\r
+               info = _UU("DLG_STRING_DEFINFO");\r
+       }\r
+       if (def == NULL)\r
+       {\r
+               def = L"";\r
+       }\r
+       if (icon == 0)\r
+       {\r
+               icon = ICO_NULL;\r
+       }\r
+\r
+       Zero(&s, sizeof(s));\r
+       s.Icon = icon;\r
+       s.Info = info;\r
+       s.Title = title;\r
+       s.Icon = icon;\r
+       UniStrCpy(s.String, sizeof(s.String), def);\r
+       s.AllowEmpty = allow_empty;\r
+       s.AllowUnsafe = allow_unsafe;\r
+\r
+       if (Dialog(hWnd, D_STRING, StringDlgProc, &s) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+       else\r
+       {\r
+               return CopyUniStr(s.String);\r
+       }\r
+}\r
+char *StringDlgA(HWND hWnd, wchar_t *title, wchar_t *info, char *def, UINT icon, bool allow_empty, bool allow_unsafe)\r
+{\r
+       wchar_t unidef[MAX_SIZE];\r
+       wchar_t *tmp;\r
+       char *ret;\r
+       if (def == NULL)\r
+       {\r
+               def = "";\r
+       }\r
+\r
+       StrToUni(unidef, sizeof(unidef), def);\r
+\r
+       tmp = StringDlg(hWnd, title, info, unidef, icon, allow_empty, allow_unsafe);\r
+       if (tmp == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = CopyUniToStr(tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// 再起動ダイアログ\r
+UINT Win9xRebootDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       WIN9X_REBOOT_DLG *d = (WIN9X_REBOOT_DLG *)param;\r
+       UINT64 now;\r
+       wchar_t tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               d->StartTime = Tick64();\r
+               SetRange(hWnd, P_PROGRESS, 0, d->TotalTime);\r
+               SetTimer(hWnd, 1, 100, NULL);\r
+               goto UPDATE;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+UPDATE:\r
+                       now = Tick64();\r
+                       if ((d->StartTime + (UINT64)d->TotalTime) <= now)\r
+                       {\r
+                               KillTimer(hWnd, 1);\r
+                               UniStrCpy(tmp, sizeof(tmp), _UU("DLG_REBOOT_INFO_2"));\r
+                               SetText(hWnd, S_INFO, tmp);\r
+                               if (MsShutdown(true, false) == false)\r
+                               {\r
+                                       MsgBox(hWnd, MB_ICONSTOP, _UU("DLG_REBOOT_ERROR"));\r
+                               }\r
+                               EndDialog(hWnd, 0);\r
+                       }\r
+                       else\r
+                       {\r
+                               SetPos(hWnd, P_PROGRESS, (UINT)(now - d->StartTime));\r
+                               UniFormat(tmp, sizeof(tmp), _UU("DLG_REBOOT_INFO"),\r
+                                       (UINT)((UINT64)d->TotalTime - (now - d->StartTime)) / 1000 + 1);\r
+                               SetText(hWnd, S_INFO, tmp);\r
+                       }\r
+\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+       return 0;\r
+}\r
+\r
+// 再起動用スレッド\r
+void Win9xRebootThread(THREAD *t, void *p)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Win9xReboot(NULL);\r
+}\r
+\r
+// 自動的に再起動する\r
+void Win9xReboot(HWND hWnd)\r
+{\r
+       WIN9X_REBOOT_DLG d;\r
+\r
+       Zero(&d, sizeof(d));\r
+       d.TotalTime = 10 * 1000;\r
+\r
+       Dialog(hWnd, D_WIN9X_REBOOT, Win9xRebootDlgProc, &d);\r
+}\r
+\r
+// バージョン情報の初期化\r
+void AboutDlgInit(HWND hWnd, WINUI_ABOUT *a)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniFormat(tmp, sizeof(tmp), _UU("ABOUT_CAPTION"), a->ProductName);\r
+       SetText(hWnd, 0, tmp);\r
+\r
+       SetFont(hWnd, S_VERSION, GetFont(NULL, 15, true, false, false, false));\r
+\r
+       SetTextA(hWnd, S_VERSION, a->ProductName);\r
+\r
+       SetFont(hWnd, S_VERSION2, GetFont("Verdana", 13, false, false, false, false));\r
+       UniFormat(tmp, sizeof(tmp),\r
+               L"Version %u.%02u Build %u ",\r
+               a->Cedar->Version / 100, a->Cedar->Version % 100,\r
+               a->Cedar->Build);\r
+       SetText(hWnd, S_VERSION2, tmp);\r
+\r
+       SetFont(hWnd, S_BUILD, GetFont("Verdana", 11, false, false, true, false));\r
+       SetTextA(hWnd, S_BUILD, a->Cedar->BuildInfo);\r
+\r
+       SendMsg(hWnd, S_LOGO, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)LoadBitmap(hDll, MAKEINTRESOURCE(a->Bitmap)));\r
+}\r
+\r
+// バージョン情報プロシージャ\r
+UINT AboutDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       WINUI_ABOUT *a = (WINUI_ABOUT *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               AboutDlgInit(hWnd, a);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+               case IDCANCEL:\r
+                       if ((GetKeyState(VK_SHIFT) & 0x8000) &&\r
+                               (GetKeyState(VK_CONTROL) & 0x8000) &&\r
+                               (GetKeyState(VK_MENU) & 0x8000))\r
+                       {\r
+                               ShowEasterEgg(hWnd);\r
+                       }\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+               case B_WEB:\r
+                       ShellExecute(hWnd, "open", _SS("SE_COMPANY_URL"), NULL, NULL, SW_SHOW);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// バージョン情報 (古い形式)\r
+void About(HWND hWnd, CEDAR *cedar, char *product_name, UINT bitmap)\r
+{\r
+       WINUI_ABOUT a;\r
+       // 引数チェック\r
+       if (cedar == NULL || product_name == NULL || bitmap == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&a, sizeof(a));\r
+       a.Bitmap = bitmap;\r
+       a.Cedar = cedar;\r
+       a.ProductName = product_name;\r
+\r
+       Dialog(hWnd, D_ABOUT, AboutDlgProc, &a);\r
+}\r
+\r
+// テスト\r
+void UiTest()\r
+{\r
+}\r
+\r
+// IP アドレスが入力されているフィルード数を調べる\r
+UINT IpGetFilledNum(HWND hWnd, UINT id)\r
+{\r
+       UINT ret;\r
+       DWORD value;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, IPM_GETADDRESS, 0, (LPARAM)&value);\r
+\r
+       return ret;\r
+}\r
+\r
+// IP アドレスが入力されているかどうか調べる\r
+bool IpIsFilled(HWND hWnd, UINT id)\r
+{\r
+       UINT ret;\r
+       DWORD value;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, IPM_GETADDRESS, 0, (LPARAM)&value);\r
+\r
+       if (ret != 4)\r
+       {\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               return true;\r
+       }\r
+}\r
+\r
+// IP アドレスのクリア\r
+void IpClear(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMsg(hWnd, id, IPM_CLEARADDRESS, 0, 0);\r
+}\r
+\r
+// IP アドレスの取得\r
+UINT IpGet(HWND hWnd, UINT id)\r
+{\r
+       UINT ret;\r
+       DWORD value;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, IPM_GETADDRESS, 0, (LPARAM)&value);\r
+\r
+       if (ret != 4)\r
+       {\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               return Endian32((UINT)value);\r
+       }\r
+}\r
+\r
+// IP アドレスのセット\r
+void IpSet(HWND hWnd, UINT id, UINT ip)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMsg(hWnd, id, IPM_SETADDRESS, 0, Endian32(ip));\r
+}\r
+\r
+// レジストリに候補を書き込む\r
+void WriteCandidateToReg(UINT root, char *key, LIST *o, char *name)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (key == NULL || o == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = CandidateToBuf(o);\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsRegWriteBin(root, key, name, b->Buf, b->Size);\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// レジストリから候補を読み込む\r
+LIST *ReadCandidateFromReg(UINT root, char *key, char *name)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (key == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = MsRegReadBin(root, key, name);\r
+       if (b == NULL)\r
+       {\r
+               return NewCandidateList();\r
+       }\r
+       else\r
+       {\r
+               LIST *o = BufToCandidate(b);\r
+               FreeBuf(b);\r
+\r
+               return o;\r
+       }\r
+}\r
+\r
+// リモート接続ダイアログ初期化\r
+void RemoteDlgInit(HWND hWnd, WINUI_REMOTE *r)\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIcon(hWnd, 0, r->Icon);\r
+\r
+       SetText(hWnd, 0, r->Caption);\r
+       SetText(hWnd, S_TITLE, r->Title);\r
+       SetIcon(hWnd, S_ICON, r->Icon);\r
+\r
+       // 候補を読み込む\r
+       o = ReadCandidateFromReg(REG_CURRENT_USER, r->RegKeyName, "RemoteHostCandidate");\r
+       r->CandidateList = o;\r
+\r
+       // 候補を表示する\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               CANDIDATE *c = LIST_DATA(o, i);\r
+               CbAddStr(hWnd, C_HOSTNAME, c->Str, 0);\r
+       }\r
+\r
+       if (r->DefaultHostname != NULL)\r
+       {\r
+               SetTextA(hWnd, C_HOSTNAME, r->DefaultHostname);\r
+       }\r
+\r
+       FocusEx(hWnd, C_HOSTNAME);\r
+\r
+       RemoteDlgRefresh(hWnd, r);\r
+}\r
+\r
+// リモート接続ダイアログ更新\r
+void RemoteDlgRefresh(HWND hWnd, WINUI_REMOTE *r)\r
+{\r
+       char *s;\r
+       bool ok = true;\r
+       bool localhost_mode = false;\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = GetTextA(hWnd, C_HOSTNAME);\r
+       if (s != NULL)\r
+       {\r
+               Trim(s);\r
+               if (StrCmpi(s, "localhost") == 0 || StartWith(s, "127."))\r
+               {\r
+                       localhost_mode = true;\r
+               }\r
+               Free(s);\r
+       }\r
+\r
+       if (localhost_mode == false)\r
+       {\r
+               Enable(hWnd, C_HOSTNAME);\r
+               Enable(hWnd, S_HOSTNAME);\r
+               Check(hWnd, R_LOCAL, false);\r
+       }\r
+       else\r
+       {\r
+               if (r->Title != _UU("NM_CONNECT_TITLE"))\r
+               {\r
+                       Disable(hWnd, C_HOSTNAME);\r
+                       Disable(hWnd, S_HOSTNAME);\r
+               }\r
+               Check(hWnd, R_LOCAL, true);\r
+               SetTextA(hWnd, C_HOSTNAME, "localhost");\r
+\r
+               if (r->flag1 == false)\r
+               {\r
+                       Focus(hWnd, IDOK);\r
+               }\r
+       }\r
+\r
+       if (IsEmpty(hWnd, C_HOSTNAME))\r
+       {\r
+               ok = false;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+\r
+       r->flag1 = true;\r
+}\r
+\r
+// リモート接続ダイアログ OK ボタン\r
+void RemoteDlgOnOk(HWND hWnd, WINUI_REMOTE *r)\r
+{\r
+       char *hostname;\r
+       wchar_t *s;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (hWnd == NULL || r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 入力されているホスト名を取得\r
+       hostname = GetTextA(hWnd, C_HOSTNAME);\r
+       if (hostname == NULL)\r
+       {\r
+               return;\r
+       }\r
+       Trim(hostname);\r
+\r
+       // 候補を追加\r
+       o = r->CandidateList;\r
+       s = CopyStrToUni(hostname);\r
+       AddCandidate(o, s, 64);\r
+       Free(s);\r
+\r
+       // 候補を書き込む\r
+       WriteCandidateToReg(REG_CURRENT_USER, r->RegKeyName, o, "RemoteHostCandidate");\r
+       FreeCandidateList(o);\r
+\r
+       r->Hostname = hostname;\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// リモート接続ダイアログプロシージャ\r
+UINT RemoteDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       WINUI_REMOTE *r = (WINUI_REMOTE *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               RemoteDlgInit(hWnd, r);\r
+               SetTimer(hWnd, 1, 100, NULL);\r
+               break;\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       RemoteDlgRefresh(hWnd, r);\r
+                       SetTimer(hWnd, 1, 100, NULL);\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case R_LOCAL:\r
+                       if (IsChecked(hWnd, R_LOCAL) == false)\r
+                       {\r
+                               SetTextA(hWnd, C_HOSTNAME, "");\r
+                               RemoteDlgRefresh(hWnd, r);\r
+                               FocusEx(hWnd, C_HOSTNAME);\r
+                       }\r
+                       else\r
+                       {\r
+                               SetTextA(hWnd, C_HOSTNAME, "localhost");\r
+                               RemoteDlgRefresh(hWnd, r);\r
+                               Focus(hWnd, IDOK);\r
+                       }\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               case IDOK:\r
+                       RemoteDlgOnOk(hWnd, r);\r
+                       break;\r
+               }\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_LOCAL:\r
+               case C_HOSTNAME:\r
+                       RemoteDlgRefresh(hWnd, r);\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CLOSE:\r
+               FreeCandidateList(r->CandidateList);\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// リモート接続ダイアログ\r
+char *RemoteDlg(HWND hWnd, char *regkey, UINT icon, wchar_t *caption, wchar_t *title, char *default_host)\r
+{\r
+       WINUI_REMOTE r;\r
+       // 引数チェック\r
+       if (regkey == NULL)\r
+       {\r
+               regkey = "Software\\SoftEther Corporation\\SoftEther UT-VPN\\WinUI Common Module";\r
+       }\r
+       if (caption == NULL)\r
+       {\r
+               caption = _UU("REMOTE_DEF_CAPTION");\r
+       }\r
+       if (title == NULL)\r
+       {\r
+               title = _UU("REMOTE_DEF_TITLE");\r
+       }\r
+       if (icon == 0)\r
+       {\r
+               icon = ICO_INTERNET;\r
+       }\r
+\r
+       Zero(&r, sizeof(r));\r
+       r.RegKeyName = regkey;\r
+       r.Caption = caption;\r
+       r.Title = title;\r
+       r.Icon = icon;\r
+       r.DefaultHostname = default_host;\r
+\r
+       if (Dialog(hWnd, D_REMOTE, RemoteDlgProc, &r) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return r.Hostname;\r
+}\r
+\r
+// ウインドウの検索プロシージャ\r
+bool CALLBACK SearchWindowEnumProc(HWND hWnd, LPARAM lParam)\r
+{\r
+       if (hWnd != NULL && lParam != 0)\r
+       {\r
+               wchar_t *s = GetText(hWnd, 0);\r
+               SEARCH_WINDOW_PARAM *p = (SEARCH_WINDOW_PARAM *)lParam;\r
+               if (s != NULL)\r
+               {\r
+                       if (UniStrCmpi(p->caption, s) == 0)\r
+                       {\r
+                               p->hWndFound = hWnd;\r
+                       }\r
+                       Free(s);\r
+               }\r
+       }\r
+       return true;\r
+}\r
+\r
+// ウインドウの検索\r
+HWND SearchWindow(wchar_t *caption)\r
+{\r
+       SEARCH_WINDOW_PARAM p;\r
+       // 引数チェック\r
+       if (caption == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.caption = caption;\r
+       p.hWndFound = NULL;\r
+\r
+       EnumWindows(SearchWindowEnumProc, (LPARAM)&p);\r
+\r
+       return p.hWndFound;\r
+}\r
+\r
+// 指定したプロセスにフォアグラウンドウインドウになることを許可\r
+void AllowFGWindow(UINT process_id)\r
+{\r
+       if (process_id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType) &&\r
+               GET_KETA(GetOsInfo()->OsType, 100) >= 2)\r
+       {\r
+               AllowSetForegroundWindow(process_id);\r
+       }\r
+}\r
+\r
+// アイテムのリネーム\r
+void LvRename(HWND hWnd, UINT id, UINT pos)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || pos == INFINITE)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ListView_EditLabel(DlgItem(hWnd, id), pos);\r
+}\r
+\r
+// メニューを表示する\r
+void PrintMenu(HWND hWnd, HMENU hMenu)\r
+{\r
+       POINT p;\r
+       // 引数チェック\r
+       if (hMenu == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetCursorPos(&p);\r
+\r
+       TrackPopupMenu(hMenu, TPM_LEFTALIGN, p.x, p.y, 0, hWnd, NULL);\r
+}\r
+\r
+// メニューからショートカット文字列を削除する\r
+void RemoveShortcutKeyStrFromMenu(HMENU hMenu)\r
+{\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (hMenu == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       num = GetMenuNum(hMenu);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               wchar_t *str = GetMenuStr(hMenu, i);\r
+               if (str != NULL)\r
+               {\r
+                       UINT j, len;\r
+                       len = UniStrLen(str);\r
+                       for (j = 0;j < len;j++)\r
+                       {\r
+                               if (str[j] == L'\t')\r
+                               {\r
+                                       str[j] = 0;\r
+                               }\r
+                       }\r
+                       SetMenuStr(hMenu, i, str);\r
+                       Free(str);\r
+               }\r
+       }\r
+}\r
+\r
+// メニュー内の項目数を取得する\r
+UINT GetMenuNum(HMENU hMenu)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hMenu == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = GetMenuItemCount(hMenu);\r
+       if (ret == INFINITE)\r
+       {\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               return ret;\r
+       }\r
+}\r
+\r
+// メニュー内の文字列を設定する\r
+void SetMenuStr(HMENU hMenu, UINT pos, wchar_t *str)\r
+{\r
+       MENUITEMINFOW info;\r
+       // 引数チェック\r
+       if (hMenu == NULL || pos == INFINITE || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = CopyUniToStr(str);\r
+               SetMenuStrA(hMenu, pos, s);\r
+               Free(s);\r
+               return;\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       info.cbSize = sizeof(info);\r
+       info.fMask = MIIM_STRING;\r
+       info.dwTypeData = str;\r
+       SetMenuItemInfoW(hMenu, pos, true, &info);\r
+}\r
+void SetMenuStrA(HMENU hMenu, UINT pos, char *str)\r
+{\r
+       MENUITEMINFOA info;\r
+       // 引数チェック\r
+       if (hMenu == NULL || pos == INFINITE || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       info.cbSize = sizeof(info);\r
+       info.fMask = MIIM_STRING;\r
+       info.dwTypeData = str;\r
+       SetMenuItemInfoA(hMenu, pos, true, &info);\r
+}\r
+\r
+// メニュー内の文字列を取得する\r
+wchar_t *GetMenuStr(HMENU hMenu, UINT pos)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hMenu == NULL || pos == INFINITE)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = GetMenuStrA(hMenu, pos);\r
+               if (s == NULL)\r
+               {\r
+                       return NULL;\r
+               }\r
+               else\r
+               {\r
+                       wchar_t *ret = CopyStrToUni(s);\r
+                       Free(s);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       if (GetMenuStringW(hMenu, pos, tmp, sizeof(tmp), MF_BYPOSITION) == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return UniCopyStr(tmp);\r
+}\r
+char *GetMenuStrA(HMENU hMenu, UINT pos)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hMenu == NULL || pos == INFINITE)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (GetMenuString(hMenu, pos, tmp, sizeof(tmp), MF_BYPOSITION) == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return CopyStr(tmp);\r
+}\r
+\r
+// メニュー項目を太字にする\r
+void SetMenuItemBold(HMENU hMenu, UINT pos, bool bold)\r
+{\r
+       MENUITEMINFO info;\r
+       // 引数チェック\r
+       if (hMenu == NULL || pos == INFINITE)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       info.cbSize = sizeof(info);\r
+       info.fMask = MIIM_STATE;\r
+\r
+       if (GetMenuItemInfo(hMenu, pos, true, &info) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (bold)\r
+       {\r
+               info.fState |= MFS_DEFAULT;\r
+       }\r
+       else\r
+       {\r
+               info.fState = info.fState & ~MFS_DEFAULT;\r
+       }\r
+\r
+       SetMenuItemInfo(hMenu, pos, true, &info);\r
+}\r
+\r
+// メニュー項目を有効 / 無効にする\r
+void SetMenuItemEnable(HMENU hMenu, UINT pos, bool enable)\r
+{\r
+       MENUITEMINFO info;\r
+       // 引数チェック\r
+       if (hMenu == NULL || pos == INFINITE)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       info.cbSize = sizeof(info);\r
+       info.fMask = MIIM_STATE;\r
+\r
+       if (GetMenuItemInfo(hMenu, pos, true, &info) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (enable)\r
+       {\r
+               info.fState |= MFS_ENABLED;\r
+               info.fState = info.fState & ~MFS_DISABLED;\r
+       }\r
+       else\r
+       {\r
+               info.fState |= MFS_DISABLED;\r
+               info.fState = info.fState & ~MFS_ENABLED;\r
+       }\r
+\r
+       SetMenuItemInfo(hMenu, pos, true, &info);\r
+}\r
+\r
+// メニュー項目を削除する\r
+void DeleteMenuItem(HMENU hMenu, UINT pos)\r
+{\r
+       // 引数チェック\r
+       if (hMenu == NULL || pos == INFINITE)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DeleteMenu(hMenu, pos, MF_BYPOSITION);\r
+}\r
+\r
+// メニュー内の ID から位置を取得する\r
+UINT GetMenuItemPos(HMENU hMenu, UINT id)\r
+{\r
+       UINT num, i;\r
+       // 引数チェック\r
+       if (hMenu == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       num = GetMenuItemCount(hMenu);\r
+       if (num == INFINITE)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               if (GetMenuItemID(hMenu, i) == id)\r
+               {\r
+                       return i;\r
+               }\r
+       }\r
+\r
+       return INFINITE;\r
+}\r
+\r
+// サブメニューを取得\r
+HMENU LoadSubMenu(UINT menu_id, UINT pos, HMENU *parent_menu)\r
+{\r
+       HMENU h = LoadMenu(hDll, MAKEINTRESOURCE(menu_id));\r
+       HMENU ret;\r
+       if (h == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = GetSubMenu(h, pos);\r
+\r
+       if (parent_menu != NULL)\r
+       {\r
+               *parent_menu = h;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ユーザーインターフェイスの DLL を取得\r
+HINSTANCE GetUiDll()\r
+{\r
+       return hDll;\r
+}\r
+\r
+// 接続エラーダイアログプロシージャ\r
+UINT ConnectErrorDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       UI_CONNECTERROR_DLG *p = (UI_CONNECTERROR_DLG *)param;\r
+       wchar_t tmp[1024];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               if (p->Err == ERR_DISCONNECTED || p->Err == ERR_SESSION_TIMEOUT)\r
+               {\r
+                       // 接続が切断された旨のメッセージ\r
+                       SetText(hWnd, S_TITLE, _UU("ERRDLG_DISCONNECTED_MSG"));\r
+               }\r
+               if (p->HideWindow)\r
+               {\r
+                       Hide(hWnd, R_HIDE);\r
+               }\r
+               FormatText(hWnd, 0, p->AccountName);\r
+               FormatText(hWnd, S_TITLE, p->ServerName);\r
+               UniFormat(tmp, sizeof(tmp), _UU("ERRDLG_ERRMSG"), p->Err, _E(p->Err));\r
+               SetText(hWnd, E_ERROR, tmp);\r
+\r
+               SetIcon(hWnd, 0, ICO_SERVER_OFFLINE);\r
+\r
+               if (p->RetryIntervalSec == 0)\r
+               {\r
+                       SetText(hWnd, S_COUNTDOWN, _UU("ERRDLG_INFORMATION"));\r
+                       Hide(hWnd, P_PROGRESS);\r
+                       Hide(hWnd, S_RETRYINFO);\r
+               }\r
+               else\r
+               {\r
+                       if (p->RetryLimit != INFINITE)\r
+                       {\r
+                               UniFormat(tmp, sizeof(tmp), _UU("ERRDLG_RETRY_INFO_1"), p->CurrentRetryCount, p->RetryLimit);\r
+                       }\r
+                       else\r
+                       {\r
+                               UniFormat(tmp, sizeof(tmp), _UU("ERRDLG_RETRY_INFO_2"), p->CurrentRetryCount);\r
+                       }\r
+                       SetText(hWnd, S_RETRYINFO, tmp);\r
+                       SetRange(hWnd, P_PROGRESS, 0, p->RetryIntervalSec);\r
+                       SetPos(hWnd, P_PROGRESS, 0);\r
+                       SetTimer(hWnd, 1, 10, NULL);\r
+                       p->StartTick = Tick64();\r
+               }\r
+               SetTimer(hWnd, 2, 10, NULL);\r
+               Focus(hWnd, IDOK);\r
+               break;\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       if (p->RetryIntervalSec != 0)\r
+                       {\r
+                               UINT64 start, end, now;\r
+                               now = Tick64();\r
+                               start = p->StartTick;\r
+                               end = start + (UINT64)p->RetryIntervalSec;\r
+\r
+                               if (end > now)\r
+                               {\r
+                                       SetPos(hWnd, P_PROGRESS, (UINT)(now - start));\r
+                                       UniFormat(tmp, sizeof(tmp), _UU("ERRDLG_RETRYCOUNT"), ((UINT)(end - now)) / 1000);\r
+                                       SetText(hWnd, S_COUNTDOWN, tmp);\r
+                               }\r
+                               else\r
+                               {\r
+                                       Command(hWnd, IDOK);\r
+                               }\r
+                       }\r
+                       break;\r
+               case 2:\r
+                       if (p->CancelEvent != NULL)\r
+                       {\r
+                               if (WaitForSingleObject((HANDLE)p->CancelEvent->pData, 0) != WAIT_TIMEOUT)\r
+                               {\r
+                                       // 強制キャンセル\r
+                                       Close(hWnd);\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case R_HIDE:\r
+                       p->HideWindow = IsChecked(hWnd, R_HIDE);\r
+                       break;\r
+               }\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 接続エラーダイアログを表示\r
+bool ConnectErrorDlg(UI_CONNECTERROR_DLG *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return DialogEx2(NULL, D_CONNECTERROR, ConnectErrorDlgProc, p, true, true);\r
+}\r
+\r
+// 証明書の内容を表示する\r
+void PrintCheckCertInfo(HWND hWnd, UI_CHECKCERT *p)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       char tmp2[MAX_SIZE];\r
+       UCHAR md5[MD5_SIZE];\r
+       UCHAR sha1[SHA1_SIZE];\r
+       X *x;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       x = p->x;\r
+\r
+       GetAllNameFromNameEx(tmp, sizeof(tmp), x->subject_name);\r
+       SetText(hWnd, E_SUBJECT, tmp);\r
+\r
+       GetAllNameFromNameEx(tmp, sizeof(tmp), x->issuer_name);\r
+       SetText(hWnd, E_ISSUER, tmp);\r
+\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(x->notAfter), NULL);\r
+       SetText(hWnd, E_EXPIRES, tmp);\r
+\r
+       GetXDigest(x, md5, false);\r
+       BinToStr(tmp2, sizeof(tmp2), md5, sizeof(md5));\r
+       SetTextA(hWnd, E_MD5, tmp2);\r
+\r
+       GetXDigest(x, sha1, true);\r
+       BinToStr(tmp2, sizeof(tmp2), sha1, sizeof(sha1));\r
+       SetTextA(hWnd, E_SHA1, tmp2);\r
+\r
+       SetFont(hWnd, E_MD5, GetFont("Arial", 8, false, false, false, false));\r
+       SetFont(hWnd, E_SHA1, GetFont("Arial", 8, false, false, false, false));\r
+}\r
+\r
+// 証明書が相違する旨を警告する\r
+void ShowDlgDiffWarning(HWND hWnd, UI_CHECKCERT *p)\r
+{\r
+       UCHAR sha1_new[SHA1_SIZE], sha1_old[SHA1_SIZE];\r
+       UCHAR md5_new[MD5_SIZE], md5_old[MD5_SIZE];\r
+       char sha1_new_str[MAX_SIZE], sha1_old_str[MAX_SIZE];\r
+       char md5_new_str[MAX_SIZE], md5_old_str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL || p->x == NULL || p->old_x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetXDigest(p->x, sha1_new, true);\r
+       GetXDigest(p->x, md5_new, false);\r
+\r
+       GetXDigest(p->old_x, sha1_old, true);\r
+       GetXDigest(p->old_x, md5_old, false);\r
+\r
+       BinToStrEx(sha1_new_str, sizeof(sha1_new_str), sha1_new, sizeof(sha1_new));\r
+       BinToStrEx(md5_new_str, sizeof(md5_new_str), md5_new, sizeof(md5_new));\r
+       BinToStrEx(sha1_old_str, sizeof(sha1_old_str), sha1_old, sizeof(sha1_old));\r
+       BinToStrEx(md5_old_str, sizeof(md5_old_str), md5_old, sizeof(md5_old));\r
+\r
+       MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("CC_DANGEROUS_MSG"),\r
+               p->ServerName, md5_old_str, sha1_old_str, md5_new_str, sha1_new_str);\r
+}\r
+\r
+// [OK] ボタンが押された\r
+void CheckCertDialogOnOk(HWND hWnd, UI_CHECKCERT *p)\r
+{\r
+       UCHAR sha1_new[SHA1_SIZE];\r
+       UCHAR md5_new[MD5_SIZE];\r
+       char sha1_new_str[MAX_SIZE];\r
+       char md5_new_str[MAX_SIZE];\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetXDigest(p->x, sha1_new, true);\r
+       GetXDigest(p->x, md5_new, false);\r
+       BinToStrEx(sha1_new_str, sizeof(sha1_new_str), sha1_new, sizeof(sha1_new));\r
+       BinToStrEx(md5_new_str, sizeof(md5_new_str), md5_new, sizeof(md5_new));\r
+\r
+       ret = MsgBoxEx(hWnd, MB_ICONQUESTION | MB_YESNOCANCEL | MB_DEFBUTTON2,\r
+               _UU("CC_WARNING_MSG"),\r
+               p->AccountName, sha1_new_str, md5_new_str);\r
+\r
+       if (ret == IDYES)\r
+       {\r
+               p->SaveServerCert = true;\r
+       }\r
+\r
+       if (ret == IDCANCEL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p->Ok = true;\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// 証明書ダイアログプロシージャ\r
+UINT CheckCertDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       UI_CHECKCERT *p = (UI_CHECKCERT *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL || param == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               FormatText(hWnd, 0, p->AccountName);\r
+               FormatText(hWnd, S_TITLE, p->ServerName);\r
+               FormatText(hWnd, S_MSG1, p->ServerName);\r
+\r
+               PrintCheckCertInfo(hWnd, p);\r
+\r
+               Focus(hWnd, IDCANCEL);\r
+\r
+               SetIcon(hWnd, 0, ICO_WARNING);\r
+\r
+               if (p->DiffWarning)\r
+               {\r
+                       SetTimer(hWnd, 1, 1, NULL);\r
+               }\r
+\r
+               SetTimer(hWnd, 2, 100, NULL);\r
+\r
+               break;\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       ShowDlgDiffWarning(hWnd, p);\r
+                       break;\r
+               case 2:\r
+                       if ((p->Session != NULL && p->Session->Halt) ||\r
+                               (p->Halt))\r
+                       {\r
+                               p->Ok = false;\r
+                               EndDialog(hWnd, false);\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_SHOW:\r
+                       CertDlg(hWnd, p->x, p->parent_x, false);\r
+                       break;\r
+               case IDOK:\r
+                       CheckCertDialogOnOk(hWnd, p);\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CLOSE:\r
+               p->Ok = false;\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 証明書のチェックダイアログ\r
+void CheckCertDlg(UI_CHECKCERT *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Dialog(NULL, D_CHECKCERT, CheckCertDlgProc, p);\r
+}\r
+\r
+// アイコン ID からイメージリスト ID を取得する\r
+UINT GetIcon(UINT icon_id)\r
+{\r
+       IMAGELIST_ICON *c, t;\r
+       t.id = icon_id;\r
+\r
+       c = Search(icon_list, &t);\r
+       if (c == NULL)\r
+       {\r
+               if (icon_id != ICO_NULL)\r
+               {\r
+                       return GetIcon(ICO_NULL);\r
+               }\r
+               else\r
+               {\r
+                       return INFINITE;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               return c->Index;\r
+       }\r
+}\r
+\r
+// イメージリスト用にアイコンをロードする\r
+IMAGELIST_ICON *LoadIconForImageList(UINT id)\r
+{\r
+       IMAGELIST_ICON *ret = ZeroMalloc(sizeof(IMAGELIST_ICON));\r
+       HICON small_icon, large_icon;\r
+\r
+       ret->id = id;\r
+\r
+       large_icon = LoadLargeIcon(id);\r
+       if (large_icon == NULL)\r
+       {\r
+               large_icon = LoadSmallIcon(id);\r
+       }\r
+\r
+       small_icon = LoadSmallIcon(id);\r
+       if (small_icon == NULL)\r
+       {\r
+               small_icon = LoadLargeIcon(id);\r
+       }\r
+\r
+       ret->hSmallImage = small_icon;\r
+       ret->hLargeImage = large_icon;\r
+       ret->Index = ImageList_AddIcon(large_image_list, large_icon);\r
+       ImageList_AddIcon(small_image_list, small_icon);\r
+\r
+       return ret;\r
+}\r
+\r
+// イメージリストアイコンの比較\r
+int CompareImageListIcon(void *p1, void *p2)\r
+{\r
+       IMAGELIST_ICON *c1, *c2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       c1 = *(IMAGELIST_ICON **)p1;\r
+       c2 = *(IMAGELIST_ICON **)p2;\r
+       if (c1 == NULL || c2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (c1->id > c2->id)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (c1->id < c2->id)\r
+       {\r
+               return -1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+// イメージリストの初期化\r
+void InitImageList()\r
+{\r
+       large_image_list = ImageList_Create(32, 32, ILC_COLOR32 | ILC_MASK, 1, 0);\r
+       ImageList_SetBkColor(large_image_list, RGB(255, 255, 255));\r
+       small_image_list = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 1, 0);\r
+       ImageList_SetBkColor(small_image_list, RGB(255, 255, 255));\r
+       icon_list = NewList(CompareImageListIcon);\r
+\r
+       // 列挙\r
+       EnumResourceNames(hDll, RT_GROUP_ICON, EnumResNameProc, 0);\r
+}\r
+\r
+// アイコンリソース列挙プロシージャ\r
+BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)\r
+{\r
+       if (IS_INTRESOURCE(lpszName))\r
+       {\r
+               UINT icon_id = (UINT)lpszName;\r
+               IMAGELIST_ICON *img = LoadIconForImageList(icon_id);\r
+\r
+               Add(icon_list, img);\r
+       }\r
+\r
+       return TRUE;\r
+}\r
+\r
+// イメージリストの解放\r
+void FreeImageList()\r
+{\r
+       UINT i;\r
+       ImageList_Destroy(large_image_list);\r
+       ImageList_Destroy(small_image_list);\r
+       large_image_list = small_image_list = NULL;\r
+\r
+       for (i = 0;i < LIST_NUM(icon_list);i++)\r
+       {\r
+               IMAGELIST_ICON *c = LIST_DATA(icon_list, i);\r
+               Free(c);\r
+       }\r
+\r
+       ReleaseList(icon_list);\r
+       icon_list = NULL;\r
+}\r
+\r
+// カラムの横幅の取得\r
+UINT LvGetColumnWidth(HWND hWnd, UINT id, UINT index)\r
+{\r
+       return ListView_GetColumnWidth(DlgItem(hWnd, id), index);\r
+}\r
+\r
+// カラムの挿入\r
+void LvInsertColumn(HWND hWnd, UINT id, UINT index, wchar_t *str, UINT width)\r
+{\r
+       LVCOLUMNW c;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&c, sizeof(c));\r
+       c.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;\r
+\r
+       c.pszText = str;\r
+       c.iSubItem = index;\r
+       c.cx = width;\r
+\r
+       SendMsg(hWnd, id, LVM_INSERTCOLUMNW, index, (LPARAM)&c);\r
+}\r
+\r
+// すべてのアイテムを削除\r
+void LvReset(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ListView_DeleteAllItems(DlgItem(hWnd, id));\r
+}\r
+\r
+// リストビューを初期化\r
+void LvInitEx(HWND hWnd, UINT id, bool no_image)\r
+{\r
+       LvInitEx2(hWnd, id, no_image, false);\r
+}\r
+void LvInitEx2(HWND hWnd, UINT id, bool no_image, bool large_icon)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ListView_SetUnicodeFormat(DlgItem(hWnd, id), true);\r
+\r
+       if (no_image == false)\r
+       {\r
+               ListView_SetImageList(DlgItem(hWnd, id), large_image_list, LVSIL_NORMAL);\r
+               ListView_SetImageList(DlgItem(hWnd, id), large_icon ? large_image_list : small_image_list, LVSIL_SMALL);\r
+       }\r
+\r
+       ListView_SetExtendedListViewStyle(DlgItem(hWnd, id), LVS_EX_FULLROWSELECT);\r
+\r
+       if (MsIsVista())\r
+       {\r
+               LvSetStyle(hWnd, id, LVS_EX_DOUBLEBUFFER);\r
+       }\r
+}\r
+void LvInit(HWND hWnd, UINT id)\r
+{\r
+       LvInitEx(hWnd, id, false);\r
+}\r
+\r
+// バッチ追加処理完了 (高速)\r
+void LvInsertEnd(LVB *b, HWND hWnd, UINT id)\r
+{\r
+       LvInsertEndEx(b, hWnd, id, false);\r
+}\r
+void LvInsertEndEx(LVB *b, HWND hWnd, UINT id, bool force_reset)\r
+{\r
+       UINT i, num;\r
+       LIST *new_list, *exist_list;\r
+       wchar_t *last_selected = NULL;\r
+       // 引数チェック\r
+       if (b == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       new_list = NewListFast(CompareUniStr);\r
+\r
+       for (i = 0;i < LIST_NUM(b->ItemList);i++)\r
+       {\r
+               LVB_ITEM *t = LIST_DATA(b->ItemList, i);\r
+               Add(new_list, t->Strings[0]);\r
+       }\r
+\r
+       Sort(new_list);\r
+\r
+       if ((LIST_NUM(b->ItemList) >= LV_INSERT_RESET_ALL_ITEM_MIN) || force_reset)\r
+       {\r
+               last_selected = LvGetFocusedStr(hWnd, id, 0);\r
+               LvReset(hWnd, id);\r
+       }\r
+\r
+       exist_list = NewListFast(CompareUniStr);\r
+\r
+       num = LvNum(hWnd, id);\r
+\r
+       // 既存項目のうちバッチリスト内に存在していない項目を削除する\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               bool exists = false;\r
+               wchar_t *s = LvGetStr(hWnd, id, i, 0);\r
+               if (Search(new_list, s) != NULL)\r
+               {\r
+                       exists = true;\r
+               }\r
+               if (exists == false)\r
+               {\r
+                       // 追加予定バッチリスト内に存在しない項目はリストビューから削除する\r
+                       LvDeleteItem(hWnd, id, i);\r
+                       num = LvNum(hWnd, id);\r
+                       i--;\r
+                       Free(s);\r
+               }\r
+               else\r
+               {\r
+                       Add(exist_list, s);\r
+               }\r
+       }\r
+\r
+       Sort(exist_list);\r
+\r
+       // バッチ内の項目を 1 つずつ追加していく\r
+       for (i = 0;i < LIST_NUM(b->ItemList);i++)\r
+       {\r
+               LVB_ITEM *t = LIST_DATA(b->ItemList, i);\r
+               UINT index;\r
+               UINT j;\r
+               bool exists = false;\r
+\r
+               if (Search(exist_list, t->Strings[0]) != NULL)\r
+               {\r
+                       index = LvSearchStr(hWnd, id, 0, t->Strings[0]);\r
+               }\r
+               else\r
+               {\r
+                       index = INFINITE;\r
+               }\r
+\r
+               if (index != INFINITE)\r
+               {\r
+                       UINT j;\r
+                       // 追加しようとする項目と同じ文字列の項目がすでに存在する場合は\r
+                       // 追加ではなく更新を行う\r
+                       for (j = 0;j < t->NumStrings;j++)\r
+                       {\r
+                               LvSetItem(hWnd, id, index, j, t->Strings[j]);\r
+                       }\r
+                       LvSetItemImageByImageListId(hWnd, id, index, t->Image);\r
+                       LvSetItemParam(hWnd, id, index, t->Param);\r
+               }\r
+               else\r
+               {\r
+                       // 新しく追加を行う\r
+                       UINT index = INFINITE;\r
+                       UINT j;\r
+                       for (j = 0;j < t->NumStrings;j++)\r
+                       {\r
+                               if (j == 0)\r
+                               {\r
+                                       index = LvInsertItemByImageListId(hWnd, id, t->Image, t->Param, t->Strings[j]);\r
+                               }\r
+                               else\r
+                               {\r
+                                       LvSetItem(hWnd, id, index, j, t->Strings[j]);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // メモリを解放する\r
+               for (j = 0;j < t->NumStrings;j++)\r
+               {\r
+                       Free(t->Strings[j]);\r
+               }\r
+               Free(t->Strings);\r
+               Free(t);\r
+       }\r
+\r
+       // リストを解放する\r
+       ReleaseList(b->ItemList);\r
+\r
+       // メモリを解放する\r
+       Free(b);\r
+\r
+       ReleaseList(new_list);\r
+\r
+       for (i = 0;i < LIST_NUM(exist_list);i++)\r
+       {\r
+               Free(LIST_DATA(exist_list, i));\r
+       }\r
+       ReleaseList(exist_list);\r
+\r
+       if (last_selected != NULL)\r
+       {\r
+               UINT pos = LvSearchStr(hWnd, id, 0, last_selected);\r
+\r
+               if (pos != INFINITE)\r
+               {\r
+                       LvSelect(hWnd, id, pos);\r
+               }\r
+\r
+               Free(last_selected);\r
+       }\r
+}\r
+\r
+// カラム数の取得\r
+UINT LvGetColumnNum(HWND hWnd, UINT id)\r
+{\r
+       UINT i;\r
+       LVCOLUMN c;\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       for (i = 0;;i++)\r
+       {\r
+               Zero(&c, sizeof(c));\r
+               c.mask = LVCF_SUBITEM;\r
+               if (ListView_GetColumn(DlgItem(hWnd, id), i, &c) == false)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       return i;\r
+}\r
+\r
+// ソート関数\r
+int CALLBACK LvSortProc(LPARAM param1, LPARAM param2, LPARAM sort_param)\r
+{\r
+       WINUI_LV_SORT *sort = (WINUI_LV_SORT *)sort_param;\r
+       HWND hWnd;\r
+       UINT id;\r
+       UINT i1, i2;\r
+       int ret = 0;\r
+       wchar_t *s1, *s2;\r
+       if (sort == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       hWnd = sort->hWnd;\r
+       id = sort->id;\r
+\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       i1 = (UINT)param1;\r
+       i2 = (UINT)param2;\r
+\r
+       s1 = LvGetStr(hWnd, id, i1, sort->subitem);\r
+       if (s1 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       s2 = LvGetStr(hWnd, id, i2, sort->subitem);\r
+       if (s2 == NULL)\r
+       {\r
+               Free(s1);\r
+               return 0;\r
+       }\r
+\r
+       if (sort->numeric == false)\r
+       {\r
+               if (UniStrCmpi(s1, _UU("CM_NEW_ICON")) == 0)\r
+               {\r
+                       ret = -1;\r
+               }\r
+               else if (UniStrCmpi(s1, _UU("CM_ASP")) == 0)\r
+               {\r
+                       ret = -1;\r
+               }\r
+               else if (UniStrCmpi(s2, _UU("CM_NEW_ICON")) == 0)\r
+               {\r
+                       ret = 1;\r
+               }\r
+               else if (UniStrCmpi(s2, _UU("CM_ASP")) == 0)\r
+               {\r
+                       return 1;\r
+               }\r
+               else\r
+               {\r
+                       ret = UniStrCmpi(s1, s2);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               UINT64 v1, v2;\r
+               v1 = UniToInt64(s1);\r
+               v2 = UniToInt64(s2);\r
+               if (v1 > v2)\r
+               {\r
+                       ret = 1;\r
+               }\r
+               else if (v1 < v2)\r
+               {\r
+                       ret = -1;\r
+               }\r
+               else\r
+               {\r
+                       ret = 0;\r
+               }\r
+       }\r
+\r
+       Free(s1);\r
+       Free(s2);\r
+\r
+       if (sort->desc)\r
+       {\r
+               ret = -ret;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 標準的なハンドラ\r
+void LvStandardHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT id)\r
+{\r
+       NMHDR *n;\r
+       NMLVKEYDOWN *key;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LvSortHander(hWnd, msg, wParam, lParam, id);\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               if (n->idFrom == id)\r
+               {\r
+                       switch (n->code)\r
+                       {\r
+                       case NM_DBLCLK:\r
+                               Command(hWnd, IDOK);\r
+                               break;\r
+                       case LVN_KEYDOWN:\r
+                               key = (NMLVKEYDOWN *)n;\r
+                               if (key != NULL)\r
+                               {\r
+                                       UINT code = key->wVKey;\r
+                                       switch (code)\r
+                                       {\r
+                                       case VK_DELETE:\r
+                                               Command(hWnd, B_DELETE);\r
+                                               break;\r
+\r
+                                       case VK_RETURN:\r
+                                               Command(hWnd, IDOK);\r
+                                               break;\r
+\r
+                                       case VK_F5:\r
+                                               Command(hWnd, B_REFRESH);\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               break;\r
+                       }\r
+               }\r
+               break;\r
+       }\r
+}\r
+\r
+// ソートヘッダハンドラ\r
+void LvSortHander(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT id)\r
+{\r
+       NMHDR *nmhdr;\r
+       UINT subitem;\r
+       bool desc;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_NOTIFY:\r
+               nmhdr = (NMHDR *)lParam;\r
+\r
+               if (nmhdr != NULL)\r
+               {\r
+                       if (nmhdr->idFrom == id)\r
+                       {\r
+                               NMLISTVIEW *v;\r
+                               switch (nmhdr->code)\r
+                               {\r
+                               case LVN_COLUMNCLICK:\r
+                                       desc = false;\r
+                                       v = (NMLISTVIEW *)lParam;\r
+                                       subitem = v->iSubItem;\r
+\r
+                                       if ((GetStyle(hWnd, id) & LVS_SORTDESCENDING) == 0)\r
+                                       {\r
+                                               desc = true;\r
+                                               SetStyle(hWnd, id, LVS_SORTDESCENDING);\r
+                                               RemoveStyle(hWnd, id, LVS_SORTASCENDING);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               SetStyle(hWnd, id, LVS_SORTASCENDING);\r
+                                               RemoveStyle(hWnd, id, LVS_SORTDESCENDING);\r
+                                       }\r
+\r
+                                       LvSort(hWnd, id, subitem, desc);\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+               break;\r
+       }\r
+}\r
+\r
+// ソートを行う\r
+void LvSort(HWND hWnd, UINT id, UINT subitem, bool desc)\r
+{\r
+       UINT i, num;\r
+       bool numeric = true;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       num = LvNum(hWnd, id);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               wchar_t *s = LvGetStr(hWnd, id, i, subitem);\r
+               if (s != NULL)\r
+               {\r
+                       if (UniIsNum(s) == false)\r
+                       {\r
+                               numeric = false;\r
+                               Free(s);\r
+                               break;\r
+                       }\r
+                       Free(s);\r
+               }\r
+               else\r
+               {\r
+                       numeric = false;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       LvSortEx(hWnd, id, subitem, desc, numeric);\r
+}\r
+\r
+void LvSortEx(HWND hWnd, UINT id, UINT subitem, bool desc, bool numeric)\r
+{\r
+       WINUI_LV_SORT s;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (subitem >= LvGetColumnNum(hWnd, id))\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&s, sizeof(s));\r
+       s.desc = desc;\r
+       s.numeric = numeric;\r
+       s.id = id;\r
+       s.hWnd = hWnd;\r
+       s.subitem = subitem;\r
+\r
+       ListView_SortItemsEx(DlgItem(hWnd, id), LvSortProc, (LPARAM)&s);\r
+}\r
+\r
+// 項目追加バッチへの追加\r
+void LvInsertAdd(LVB *b, UINT icon, void *param, UINT num_str, ...)\r
+{\r
+       UINT i;\r
+       va_list va;\r
+       UINT index = 0;\r
+       LVB_ITEM *t;\r
+       // 引数チェック\r
+       if (b == NULL || num_str == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = ZeroMalloc(sizeof(LVB_ITEM));\r
+\r
+       va_start(va, num_str);\r
+\r
+       t->Strings = (wchar_t **)ZeroMalloc(sizeof(wchar_t *) * num_str);\r
+       t->NumStrings = num_str;\r
+\r
+       for (i = 0;i < num_str;i++)\r
+       {\r
+               wchar_t *s = va_arg(va, wchar_t *);\r
+\r
+               t->Strings[i] = UniCopyStr(s);\r
+       }\r
+\r
+       t->Param = param;\r
+       t->Image = GetIcon(icon);\r
+\r
+       Add(b->ItemList, t);\r
+\r
+       va_end(va);\r
+}\r
+\r
+// 項目追加バッチの開始\r
+LVB *LvInsertStart()\r
+{\r
+       LVB *b = ZeroMalloc(sizeof(LVB));\r
+       b->ItemList = NewListFast(NULL);\r
+\r
+       return b;\r
+}\r
+\r
+// リストビューに項目を追加する\r
+void LvInsert(HWND hWnd, UINT id, UINT icon, void *param, UINT num_str, ...)\r
+{\r
+       UINT i;\r
+       va_list va;\r
+       UINT index = 0;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(va, num_str);\r
+\r
+       for (i = 0;i < num_str;i++)\r
+       {\r
+               wchar_t *s = va_arg(va, wchar_t *);\r
+               if (i == 0)\r
+               {\r
+                       index = LvInsertItem(hWnd, id, icon, param, s);\r
+               }\r
+               else\r
+               {\r
+                       LvSetItem(hWnd, id, index, i, s);\r
+               }\r
+       }\r
+\r
+       va_end(va);\r
+}\r
+\r
+// アイテムのサイズを自動調整する\r
+void LvAutoSize(HWND hWnd, UINT id)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       i = 0;\r
+       while (true)\r
+       {\r
+               if (ListView_SetColumnWidth(DlgItem(hWnd, id), i, LVSCW_AUTOSIZE) == false)\r
+               {\r
+                       break;\r
+               }\r
+               i++;\r
+       }\r
+}\r
+\r
+// アイテムを追加する\r
+UINT LvInsertItem(HWND hWnd, UINT id, UINT icon, void *param, wchar_t *str)\r
+{\r
+       return LvInsertItemByImageListId(hWnd, id, GetIcon(icon), param, str);\r
+}\r
+UINT LvInsertItemByImageListId(HWND hWnd, UINT id, UINT image, void *param, wchar_t *str)\r
+{\r
+       LVITEMW t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = CopyUniToStr(str);\r
+               UINT ret;\r
+               ret = LvInsertItemByImageListIdA(hWnd, id, image, param, s);\r
+               Free(s);\r
+               return ret;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_TEXT;\r
+       t.pszText = str;\r
+       t.iImage = image;\r
+       t.lParam = (LPARAM)param;\r
+       t.iItem = LvNum(hWnd, id);\r
+\r
+       return SendMsg(hWnd, id, LVM_INSERTITEMW, 0, (LPARAM)&t);\r
+}\r
+UINT LvInsertItemByImageListIdA(HWND hWnd, UINT id, UINT image, void *param, char *str)\r
+{\r
+       LVITEM t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_TEXT;\r
+       t.pszText = str;\r
+       t.iImage = image;\r
+       t.lParam = (LPARAM)param;\r
+       t.iItem = LvNum(hWnd, id);\r
+\r
+       return SendMsg(hWnd, id, LVM_INSERTITEM, 0, (LPARAM)&t);\r
+}\r
+\r
+// イメージを変更する\r
+void LvSetItemImage(HWND hWnd, UINT id, UINT index, UINT icon)\r
+{\r
+       LvSetItemImageByImageListId(hWnd, id, index, GetIcon(icon));\r
+}\r
+void LvSetItemImageByImageListId(HWND hWnd, UINT id, UINT index, UINT image)\r
+{\r
+       LVITEM t;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.mask = LVIF_IMAGE;\r
+       t.iImage = image;\r
+       t.iItem = index;\r
+\r
+       SendMsg(hWnd, id, LVM_SETITEM, 0, (LPARAM)&t);\r
+}\r
+\r
+// アイテムのパラメータを設定する\r
+void LvSetItemParam(HWND hWnd, UINT id, UINT index, void *param)\r
+{\r
+       LvSetItemParamEx(hWnd, id, index, 0, param);\r
+}\r
+void LvSetItemParamEx(HWND hWnd, UINT id, UINT index, UINT subitem, void *param)\r
+{\r
+       LVITEM t;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.mask = LVIF_PARAM;\r
+       t.iItem = index;\r
+       t.iSubItem = subitem;\r
+       t.lParam = (LPARAM)param;\r
+\r
+       SendMsg(hWnd, id, LVM_SETITEM, 0, (LPARAM)&t);\r
+}\r
+\r
+// アイテムを設定する\r
+void LvSetItem(HWND hWnd, UINT id, UINT index, UINT pos, wchar_t *str)\r
+{\r
+       LVITEMW t;\r
+       wchar_t *old_str;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = CopyUniToStr(str);\r
+               LvSetItemA(hWnd, id, index, pos, s);\r
+               Free(s);\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.mask = LVIF_TEXT;\r
+       t.pszText = str;\r
+       t.iItem = index;\r
+       t.iSubItem = pos;\r
+\r
+       old_str = LvGetStr(hWnd, id, index, pos);\r
+\r
+       if (UniStrCmp(old_str, str) != 0)\r
+       {\r
+               SendMsg(hWnd, id, LVM_SETITEMW, 0, (LPARAM)&t);\r
+       }\r
+\r
+       Free(old_str);\r
+}\r
+void LvSetItemA(HWND hWnd, UINT id, UINT index, UINT pos, char *str)\r
+{\r
+       LVITEM t;\r
+       wchar_t *old_str;\r
+       char *old_str_2;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.mask = LVIF_TEXT;\r
+       t.pszText = str;\r
+       t.iItem = index;\r
+       t.iSubItem = pos;\r
+\r
+       old_str = LvGetStr(hWnd, id, index, pos);\r
+       old_str_2 = CopyUniToStr(old_str);\r
+\r
+       if (StrCmp(old_str_2, str) != 0)\r
+       {\r
+               SendMsg(hWnd, id, LVM_SETITEM, 0, (LPARAM)&t);\r
+       }\r
+\r
+       Free(old_str_2);\r
+       Free(old_str);\r
+}\r
+\r
+// リストボックスのビューを設定\r
+void LvSetView(HWND hWnd, UINT id, bool details)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (details)\r
+       {\r
+               RemoveStyle(hWnd, id, LVS_ICON);\r
+               SetStyle(hWnd, id, LVS_REPORT);\r
+       }\r
+       else\r
+       {\r
+               RemoveStyle(hWnd, id, LVS_REPORT);\r
+               SetStyle(hWnd, id, LVS_ICON);\r
+       }\r
+}\r
+\r
+// 指定したアイテムが必ず表示されるようにする\r
+void LvShow(HWND hWnd, UINT id, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ListView_EnsureVisible(DlgItem(hWnd, id), index, false);\r
+}\r
+\r
+// 現在選択されている項目が存在するかどうかを取得する\r
+bool LvIsSelected(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (LvGetSelected(hWnd, id) == INFINITE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 現在選択されている項目を取得する\r
+UINT LvGetFocused(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return ListView_GetNextItem(DlgItem(hWnd, id), -1, LVNI_FOCUSED);\r
+}\r
+\r
+// 現在選択されている文字列を取得する\r
+wchar_t *LvGetFocusedStr(HWND hWnd, UINT id, UINT pos)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       i = LvGetFocused(hWnd, id);\r
+       if (i == INFINITE)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return LvGetStr(hWnd, id, i, pos);\r
+}\r
+\r
+// 現在選択されている項目を取得する\r
+UINT LvGetSelected(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return ListView_GetNextItem(DlgItem(hWnd, id), -1, LVNI_FOCUSED | LVNI_SELECTED);\r
+}\r
+\r
+// 現在選択されている文字列を取得する\r
+wchar_t *LvGetSelectedStr(HWND hWnd, UINT id, UINT pos)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       i = LvGetSelected(hWnd, id);\r
+       if (i == INFINITE)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return LvGetStr(hWnd, id, i, pos);\r
+}\r
+char *LvGetSelectedStrA(HWND hWnd, UINT id, UINT pos)\r
+{\r
+       char *ret;\r
+       wchar_t *tmp = LvGetSelectedStr(hWnd, id, pos);\r
+       if (tmp == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       ret = CopyUniToStr(tmp);\r
+       Free(tmp);\r
+       return ret;\r
+}\r
+\r
+// 2 つ以上の項目がマスクされているかどうかを取得する\r
+bool LvIsMultiMasked(HWND hWnd, UINT id)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       i = INFINITE;\r
+       i = LvGetNextMasked(hWnd, id, i);\r
+       if (i != INFINITE)\r
+       {\r
+               if (LvGetNextMasked(hWnd, id, i) != INFINITE)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// ただ 1 つの項目だけが選択されているかどうか調べる\r
+bool LvIsSingleSelected(HWND hWnd, UINT id)\r
+{\r
+       return LvIsSelected(hWnd, id) && (LvIsMultiMasked(hWnd, id) == false);\r
+}\r
+\r
+// 現在マスクされている項目が存在するかどうかを取得する\r
+bool LvIsMasked(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (LvGetNextMasked(hWnd, id, INFINITE) == INFINITE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 現在マスクされている項目数を取得する\r
+UINT LvGetMaskedNum(HWND hWnd, UINT id)\r
+{\r
+       UINT i = INFINITE;\r
+       UINT num = 0;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               i = LvGetNextMasked(hWnd, id, i);\r
+               if (i == INFINITE)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               num++;\r
+       }\r
+\r
+       return num;\r
+}\r
+\r
+// 現在マスクされている項目を取得する\r
+UINT LvGetNextMasked(HWND hWnd, UINT id, UINT start)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return ListView_GetNextItem(DlgItem(hWnd, id), start, LVNI_SELECTED);\r
+}\r
+\r
+// 指定した文字列を持つ項目を検索する\r
+UINT LvSearchStr_(HWND hWnd, UINT id, UINT pos, wchar_t *str)\r
+{\r
+       UINT ret;\r
+       LVFINDINFOW t;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.flags = LVFI_STRING;\r
+       t.psz = str;\r
+       t.vkDirection = VK_DOWN;\r
+\r
+       ret = SendMsg(hWnd, id, LVM_FINDITEMW, -1, (LPARAM)&t);\r
+\r
+       return ret;\r
+}\r
+\r
+// 指定した文字列を持つ項目を検索する\r
+UINT LvSearchStr(HWND hWnd, UINT id, UINT pos, wchar_t *str)\r
+{\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       num = LvNum(hWnd, id);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               wchar_t *s = LvGetStr(hWnd, id, i, pos);\r
+               if (s != NULL)\r
+               {\r
+                       if (UniStrCmpi(s, str) == 0)\r
+                       {\r
+                               Free(s);\r
+                               return i;\r
+                       }\r
+                       else\r
+                       {\r
+                               Free(s);\r
+                       }\r
+               }\r
+       }\r
+\r
+       return INFINITE;\r
+}\r
+UINT LvSearchStrA(HWND hWnd, UINT id, UINT pos, char *str)\r
+{\r
+       wchar_t *tmp = CopyStrToUni(str);\r
+       UINT ret = LvSearchStr(hWnd, id, pos, tmp);\r
+       Free(tmp);\r
+       return ret;\r
+}\r
+\r
+// 指定した param を持つ項目を検索する\r
+UINT LvSearchParam(HWND hWnd, UINT id, void *param)\r
+{\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       num = LvNum(hWnd, id);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               if (LvGetParam(hWnd, id, i) == param)\r
+               {\r
+                       return i;\r
+               }\r
+       }\r
+\r
+       return INFINITE;\r
+}\r
+\r
+// 項目数を取得する\r
+UINT LvNum(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return ListView_GetItemCount(DlgItem(hWnd, id));\r
+}\r
+\r
+// 項目を削除する\r
+void LvDeleteItem(HWND hWnd, UINT id, UINT index)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ListView_DeleteItem(DlgItem(hWnd, id), index);\r
+\r
+       i = LvGetSelected(hWnd, id);\r
+       if (i != INFINITE)\r
+       {\r
+               LvSelect(hWnd, id, i);\r
+       }\r
+}\r
+\r
+// 項目からデータを取得する\r
+void *LvGetParam(HWND hWnd, UINT id, UINT index)\r
+{\r
+       return LvGetParamEx(hWnd, id, index, 0);\r
+}\r
+void *LvGetParamEx(HWND hWnd, UINT id, UINT index, UINT subitem)\r
+{\r
+       LVITEM t;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (index == INFINITE)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.mask = LVIF_PARAM;\r
+       t.iItem = index;\r
+       t.iSubItem = subitem;\r
+\r
+       if (ListView_GetItem(DlgItem(hWnd, id), &t) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return (void *)t.lParam;\r
+}\r
+\r
+// 項目の文字列を取得する\r
+wchar_t *LvGetStr(HWND hWnd, UINT id, UINT index, UINT pos)\r
+{\r
+       wchar_t *tmp;\r
+       UINT size;\r
+       LVITEMW t;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = LvGetStrA(hWnd, id, index, pos);\r
+               if (s == NULL)\r
+               {\r
+                       return NULL;\r
+               }\r
+               else\r
+               {\r
+                       wchar_t *ret = CopyStrToUni(s);\r
+                       Free(s);\r
+\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       size = 65536;\r
+       tmp = Malloc(size);\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.mask = LVIF_TEXT;\r
+       t.iItem = index;\r
+       t.iSubItem = pos;\r
+       t.pszText = tmp;\r
+       t.cchTextMax = size;\r
+\r
+       if (SendMsg(hWnd, id, LVM_GETITEMTEXTW, index, (LPARAM)&t) <= 0)\r
+       {\r
+               Free(tmp);\r
+               return UniCopyStr(L"");\r
+       }\r
+       else\r
+       {\r
+               wchar_t *ret = UniCopyStr(tmp);\r
+               Free(tmp);\r
+               return ret;\r
+       }\r
+}\r
+char *LvGetStrA(HWND hWnd, UINT id, UINT index, UINT pos)\r
+{\r
+       char *tmp;\r
+       UINT size;\r
+       LVITEM t;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = 65536;\r
+       tmp = Malloc(size);\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.mask = LVIF_TEXT;\r
+       t.iItem = index;\r
+       t.iSubItem = pos;\r
+       t.pszText = tmp;\r
+       t.cchTextMax = size;\r
+\r
+       if (SendMsg(hWnd, id, LVM_GETITEMTEXT, index, (LPARAM)&t) <= 0)\r
+       {\r
+               Free(tmp);\r
+               return CopyStr("");\r
+       }\r
+       else\r
+       {\r
+               char *ret = CopyStr(tmp);\r
+               Free(tmp);\r
+               return ret;\r
+       }\r
+}\r
+\r
+// スタイルを設定する\r
+void LvSetStyle(HWND hWnd, UINT id, UINT style)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if ((ListView_GetExtendedListViewStyle(DlgItem(hWnd, id)) & style) == 0)\r
+       {\r
+               ListView_SetExtendedListViewStyleEx(DlgItem(hWnd, id), style, style);\r
+       }\r
+}\r
+\r
+// スタイルを削除する\r
+void LvRemoveStyle(HWND hWnd, UINT id, UINT style)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if ((ListView_GetExtendedListViewStyle(DlgItem(hWnd, id)) & style) != 0)\r
+       {\r
+               ListView_SetExtendedListViewStyleEx(DlgItem(hWnd, id), style, 0);\r
+       }\r
+}\r
+\r
+// 項目の選択を反転する\r
+void LvSwitchSelect(HWND hWnd, UINT id)\r
+{\r
+       UINT i, num;\r
+       bool *states;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       num = LvNum(hWnd, id);\r
+       states = ZeroMalloc(sizeof(bool) * num);\r
+\r
+       i = INFINITE;\r
+       while (true)\r
+       {\r
+               i = LvGetNextMasked(hWnd, id, i);\r
+               if (i == INFINITE)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               states[i] = true;\r
+       }\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               if (states[i] == false)\r
+               {\r
+                       ListView_SetItemState(DlgItem(hWnd, id), i, LVIS_SELECTED, LVIS_SELECTED);\r
+               }\r
+               else\r
+               {\r
+                       ListView_SetItemState(DlgItem(hWnd, id), i, 0, LVIS_SELECTED);\r
+               }\r
+       }\r
+\r
+       Free(states);\r
+}\r
+\r
+// すべての項目を選択する\r
+void LvSelectAll(HWND hWnd, UINT id)\r
+{\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       num = LvNum(hWnd, id);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               ListView_SetItemState(DlgItem(hWnd, id), i, LVIS_SELECTED, LVIS_SELECTED);\r
+       }\r
+}\r
+\r
+// 項目を選択する\r
+void LvSelect(HWND hWnd, UINT id, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (index == INFINITE)\r
+       {\r
+               UINT i, num;\r
+               // すべて選択解除する\r
+               num = LvNum(hWnd, id);\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       ListView_SetItemState(DlgItem(hWnd, id), i, 0, LVIS_SELECTED);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // 選択する\r
+               ListView_SetItemState(DlgItem(hWnd, id), index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);\r
+               ListView_EnsureVisible(DlgItem(hWnd, id), index, true);\r
+       }\r
+}\r
+\r
+// 証明書情報を表示する\r
+void PrintCertInfo(HWND hWnd, CERT_DLG *p)\r
+{\r
+       X *x;\r
+       char *serial_tmp;\r
+       UINT serial_size;\r
+       wchar_t *wchar_tmp;\r
+       wchar_t tmp[1024 * 5];\r
+       UCHAR md5[MD5_SIZE];\r
+       UCHAR sha1[SHA1_SIZE];\r
+       char *s_tmp;\r
+       K *k;\r
+       // 引数チェック\r
+       if (p == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       x = p->x;\r
+\r
+       // シリアル番号\r
+       if (x->serial != NULL)\r
+       {\r
+               serial_size = x->serial->size * 3 + 1;\r
+               serial_tmp = ZeroMalloc(serial_size);\r
+               BinToStrEx(serial_tmp, serial_size, x->serial->data, x->serial->size);\r
+               wchar_tmp = CopyStrToUni(serial_tmp);\r
+               Free(serial_tmp);\r
+       }\r
+       else\r
+       {\r
+               wchar_tmp = CopyUniStr(_UU("CERT_NO_SERIAL"));\r
+       }\r
+       LvInsert(hWnd, L_CERTINFO, ICO_CERT, NULL, 2, _UU("CERT_SERIAL"), wchar_tmp);\r
+\r
+       // 発行者\r
+       GetAllNameFromName(tmp, sizeof(tmp), x->issuer_name);\r
+       LvInsert(hWnd, L_CERTINFO, ICO_CERT, NULL, 2, _UU("CERT_ISSUER"), tmp);\r
+\r
+       // サブジェクト\r
+       GetAllNameFromName(tmp, sizeof(tmp), x->subject_name);\r
+       LvInsert(hWnd, L_CERTINFO, ICO_CERT, NULL, 2, _UU("CERT_SUBJECT"), tmp);\r
+\r
+       // 有効期限の開始\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(x->notBefore), NULL);\r
+       LvInsert(hWnd, L_CERTINFO, ICO_CERT, NULL, 2, _UU("CERT_NOT_BEFORE"), tmp);\r
+\r
+       // 有効期限の終了\r
+       GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(x->notAfter), NULL);\r
+       LvInsert(hWnd, L_CERTINFO, ICO_CERT, NULL, 2, _UU("CERT_NOT_AFTER"), tmp);\r
+\r
+       // ビット数\r
+       if (x->is_compatible_bit)\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), _UU("CERT_BITS_FORMAT"), x->bits);\r
+               LvInsert(hWnd, L_CERTINFO, ICO_CERT, NULL, 2, _UU("CERT_BITS"), tmp);\r
+       }\r
+\r
+       // 公開鍵\r
+       k = GetKFromX(x);\r
+       if (k != NULL)\r
+       {\r
+               BUF *b = KToBuf(k, false, NULL);\r
+               s_tmp = CopyBinToStrEx(b->Buf, b->Size);\r
+               StrToUni(tmp, sizeof(tmp), s_tmp);\r
+               Free(s_tmp);\r
+               LvInsert(hWnd, L_CERTINFO, ICO_KEY, NULL, 2, _UU("CERT_PUBLIC_KEY"), tmp);\r
+               FreeBuf(b);\r
+       }\r
+       FreeK(k);\r
+\r
+       GetXDigest(x, md5, false);\r
+       GetXDigest(x, sha1, true);\r
+\r
+       // ダイジェスト (MD5)\r
+       s_tmp = CopyBinToStrEx(md5, sizeof(md5));\r
+       StrToUni(tmp, sizeof(tmp), s_tmp);\r
+       Free(s_tmp);\r
+       LvInsert(hWnd, L_CERTINFO, ICO_KEY, NULL, 2, _UU("CERT_DIGEST_MD5"), tmp);\r
+\r
+       // ダイジェスト (SHA-1)\r
+       s_tmp = CopyBinToStrEx(sha1, sizeof(sha1));\r
+       StrToUni(tmp, sizeof(tmp), s_tmp);\r
+       Free(s_tmp);\r
+       LvInsert(hWnd, L_CERTINFO, ICO_KEY, NULL, 2, _UU("CERT_DIGEST_SHA1"), tmp);\r
+\r
+       Free(wchar_tmp);\r
+\r
+       LvSelect(hWnd, L_CERTINFO, 0);\r
+}\r
+\r
+// 表示の更新\r
+void CertDlgUpdate(HWND hWnd, CERT_DLG *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (LvIsSelected(hWnd, L_CERTINFO) == false)\r
+       {\r
+               SetText(hWnd, E_DETAIL, L"");\r
+       }\r
+       else\r
+       {\r
+               UINT i = LvGetSelected(hWnd, L_CERTINFO);\r
+               wchar_t *tmp = LvGetStr(hWnd, L_CERTINFO, i, 1);\r
+               SetText(hWnd, E_DETAIL, tmp);\r
+               Free(tmp);\r
+       }\r
+}\r
+\r
+// 証明書の保存\r
+void CertDlgSave(HWND hWnd, CERT_DLG *p)\r
+{\r
+       wchar_t *name;\r
+       X *x;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 保存\r
+       name = SaveDlg(hWnd, _UU("DLG_CERT_FILES"), _UU("DLG_SAVE_CERT"), NULL, L".cer");\r
+       x = p->x;\r
+       if (name != NULL)\r
+       {\r
+               char str[MAX_SIZE];\r
+               UniToStr(str, sizeof(str), name);\r
+               if (XToFile(x, str, true))\r
+               {\r
+                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("DLG_CERT_SAVE_OK"));\r
+               }\r
+               else\r
+               {\r
+                       MsgBox(hWnd, MB_ICONSTOP, _UU("DLG_CERT_SAVE_ERROR"));\r
+               }\r
+               Free(name);\r
+       }\r
+}\r
+\r
+// 証明書表示ダイアログプロシージャ\r
+UINT CertDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       CERT_DLG *p = (CERT_DLG *)param;\r
+       X *x;\r
+       wchar_t tmp[MAX_SIZE];\r
+       NMHDR *n;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetIcon(hWnd, 0, ICO_CERT);\r
+               x = p->x;\r
+               GetAllNameFromNameEx(tmp, sizeof(tmp), x->subject_name);\r
+               SetText(hWnd, E_SUBJECT, tmp);\r
+               GetAllNameFromNameEx(tmp, sizeof(tmp), x->issuer_name);\r
+               SetText(hWnd, E_ISSUER, tmp);\r
+               GetDateStrEx64(tmp, sizeof(tmp), SystemToLocal64(x->notAfter), NULL);\r
+               SetText(hWnd, E_EXPIRES, tmp);\r
+               SetFont(hWnd, E_SUBJECT, Font(0, 1));\r
+               SetFont(hWnd, E_ISSUER, Font(0, 1));\r
+               SetFont(hWnd, E_EXPIRES, Font(0, 1));\r
+               SetIcon(hWnd, B_PARENT, ICO_CERT);\r
+               if (x->root_cert)\r
+               {\r
+                       // ルート証明書\r
+                       Hide(hWnd, S_WARNING_ICON);\r
+                       SetText(hWnd, S_PARENT, _UU("CERT_ROOT"));\r
+                       Hide(hWnd, B_PARENT);\r
+                       Hide(hWnd, S_PARENT_BUTTON_STR);\r
+               }\r
+               else if (p->issuer_x != NULL)\r
+               {\r
+                       // 親証明書がある\r
+                       Hide(hWnd, S_WARNING_ICON);\r
+               }\r
+               else\r
+               {\r
+                       // 親証明書が無い\r
+                       Hide(hWnd, S_CERT_ICON);\r
+                       Hide(hWnd, B_PARENT);\r
+                       Hide(hWnd, S_PARENT_BUTTON_STR);\r
+                       SetText(hWnd, S_PARENT, _UU("CERT_NOT_FOUND"));\r
+                       if (p->ManagerMode)\r
+                       {\r
+                               Hide(hWnd, IDC_STATIC1);\r
+                               Hide(hWnd, S_PARENT);\r
+                               Hide(hWnd, S_WARNING_ICON);\r
+                               Hide(hWnd, S_CERT_ICON);\r
+                               Hide(hWnd, B_PARENT);\r
+                               Hide(hWnd, S_PARENT_BUTTON_STR);\r
+                       }\r
+               }\r
+\r
+\r
+               LvInit(hWnd, L_CERTINFO);\r
+               LvInsertColumn(hWnd, L_CERTINFO, 0, _UU("CERT_LV_C1"), 130);\r
+               LvInsertColumn(hWnd, L_CERTINFO, 1, _UU("CERT_LV_C2"), 250);\r
+\r
+               PrintCertInfo(hWnd, p);\r
+               Focus(hWnd, L_CERTINFO);\r
+\r
+               CertDlgUpdate(hWnd, p);\r
+\r
+               if (p->ManagerMode)\r
+               {\r
+                       Show(hWnd, B_SAVE);\r
+               }\r
+               else\r
+               {\r
+                       // セキュリティのため非表示にする\r
+                       Hide(hWnd, B_SAVE);\r
+               }\r
+\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               case B_PARENT:\r
+                       CertDlg(hWnd, p->issuer_x, NULL, p->ManagerMode);\r
+                       break;\r
+               case B_SAVE:\r
+                       // ファイルに保存\r
+                       CertDlgSave(hWnd, p);\r
+                       break;\r
+               }\r
+               break;\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       case WM_NOTIFY:\r
+               n = (NMHDR *)lParam;\r
+               switch (n->idFrom)\r
+               {\r
+               case L_CERTINFO:\r
+                       switch (n->code)\r
+                       {\r
+                       case LVN_ITEMCHANGED:\r
+                               CertDlgUpdate(hWnd, p);\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       LvSortHander(hWnd, msg, wParam, lParam, L_CERTINFO);\r
+\r
+       return 0;\r
+}\r
+\r
+// 証明書表示ダイアログ\r
+void CertDlg(HWND hWnd, X *x, X *issuer_x, bool manager)\r
+{\r
+       CERT_DLG p;\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.x = x;\r
+       if (CompareX(x, issuer_x) == false)\r
+       {\r
+               p.issuer_x = issuer_x;\r
+       }\r
+       p.ManagerMode = manager;\r
+       Dialog(hWnd, D_CERT, CertDlgProc, &p);\r
+}\r
+\r
+// ステータスウインドウダイアログ\r
+UINT StatusPrinterWindowDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       STATUS_WINDOW_PARAM *p = (STATUS_WINDOW_PARAM *)param;\r
+       PACK *pack;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               // 初期化\r
+               SetIcon(hWnd, 0, ICO_SERVER_ONLINE);\r
+               RemoveExStyle(hWnd, 0, WS_EX_APPWINDOW);\r
+               p->hWnd = hWnd;\r
+               NoticeThreadInit(p->Thread);\r
+               FormatText(hWnd, 0, p->AccountName);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+               case IDCANCEL:\r
+                       // キャンセルボタン\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+\r
+               break;\r
+\r
+       case WM_APP + 1:\r
+               // 文字列を設定\r
+               SetText(hWnd, S_STATUS, (wchar_t *)lParam);\r
+               break;\r
+\r
+       case WM_APP + 2:\r
+               // このウインドウを閉じる\r
+               EndDialog(hWnd, false);\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               // セッションを終了する\r
+               pack = NewPack();\r
+               SendPack(p->Sock, pack);\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ステータスウインドウ制御用スレッド\r
+void StatusPrinterWindowThread(THREAD *thread, void *param)\r
+{\r
+       STATUS_WINDOW_PARAM *p = (STATUS_WINDOW_PARAM *)param;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p->Thread = thread;\r
+       DialogEx2(NULL, D_STATUS, StatusPrinterWindowDlg, p, true, true);\r
+\r
+       Free(p);\r
+}\r
+\r
+// ステータスウインドウにメッセージを表示する\r
+void StatusPrinterWindowPrint(STATUS_WINDOW *sw, wchar_t *str)\r
+{\r
+       // 引数チェック\r
+       if (sw == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMessage(sw->hWnd, WM_APP + 1, 0, (LPARAM)str);\r
+}\r
+\r
+// ステータスウインドウの終了と解放\r
+void StatusPrinterWindowStop(STATUS_WINDOW *sw)\r
+{\r
+       // 引数チェック\r
+       if (sw == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 停止メッセージを送信\r
+       SendMessage(sw->hWnd, WM_APP + 2, 0, 0);\r
+\r
+       // スレッド停止まで待機\r
+       WaitThread(sw->Thread, INFINITE);\r
+\r
+       // メモリ解放\r
+       ReleaseThread(sw->Thread);\r
+       Free(sw);\r
+}\r
+\r
+// ステータスウインドウの初期化\r
+STATUS_WINDOW *StatusPrinterWindowStart(SOCK *s, wchar_t *account_name)\r
+{\r
+       STATUS_WINDOW_PARAM *p;\r
+       STATUS_WINDOW *sw;\r
+       THREAD *t;\r
+       // 引数チェック\r
+       if (s == NULL || account_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = ZeroMalloc(sizeof(STATUS_WINDOW_PARAM));\r
+       p->Sock = s;\r
+       UniStrCpy(p->AccountName, sizeof(p->AccountName), account_name);\r
+\r
+       // スレッド作成\r
+       t = NewThread(StatusPrinterWindowThread, p);\r
+       WaitThreadInit(t);\r
+\r
+       sw = ZeroMalloc(sizeof(STATUS_WINDOW));\r
+       sw->hWnd = p->hWnd;\r
+       sw->Thread = t;\r
+\r
+       return sw;\r
+}\r
+\r
+// 文字列を取得\r
+wchar_t *LbGetStr(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return GetText(hWnd, id);\r
+}\r
+\r
+// 文字列検索\r
+UINT LbFindStr(HWND hWnd, UINT id, wchar_t *str)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, LB_FINDSTRING, -1, (LPARAM)str);\r
+\r
+       return ret;\r
+}\r
+\r
+// 項目数を取得\r
+UINT LbNum(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return SendMsg(hWnd, id, LB_GETCOUNT, 0, 0);\r
+}\r
+\r
+// 文字列追加\r
+UINT LbAddStr(HWND hWnd, UINT id, wchar_t *str, UINT data)\r
+{\r
+       UINT ret;\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = CopyUniToStr(str);\r
+               ret = LbAddStrA(hWnd, id, s, data);\r
+               Free(s);\r
+               return ret;\r
+       }\r
+\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, LB_ADDSTRING, 0, (LPARAM)str);\r
+       SendMsg(hWnd, id, LB_SETITEMDATA, ret, (LPARAM)data);\r
+\r
+       if (LbNum(hWnd, id) == 1)\r
+       {\r
+               LbSelectIndex(hWnd, id, 0);\r
+       }\r
+\r
+       return ret;\r
+}\r
+UINT LbAddStrA(HWND hWnd, UINT id, char *str, UINT data)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, LB_ADDSTRING, 0, (LPARAM)str);\r
+       SendMsg(hWnd, id, LB_SETITEMDATA, ret, (LPARAM)data);\r
+\r
+       if (LbNum(hWnd, id) == 1)\r
+       {\r
+               LbSelectIndex(hWnd, id, 0);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 文字列挿入\r
+UINT LbInsertStr(HWND hWnd, UINT id, UINT index, wchar_t *str, UINT data)\r
+{\r
+       UINT ret;\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = CopyUniToStr(str);\r
+               ret = LbInsertStrA(hWnd, id, index, s, data);\r
+               Free(s);\r
+               return ret;\r
+       }\r
+\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, LB_INSERTSTRING, index, (LPARAM)str);\r
+       SendMsg(hWnd, id, LB_SETITEMDATA, ret, (LPARAM)data);\r
+\r
+       if (LbNum(hWnd, id) == 1)\r
+       {\r
+               LbSelect(hWnd, id, 0);\r
+       }\r
+\r
+       return ret;\r
+}\r
+UINT LbInsertStrA(HWND hWnd, UINT id, UINT index, char *str, UINT data)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, LB_INSERTSTRING, index, (LPARAM)str);\r
+       SendMsg(hWnd, id, LB_SETITEMDATA, ret, (LPARAM)data);\r
+\r
+       if (LbNum(hWnd, id) == 1)\r
+       {\r
+               LbSelect(hWnd, id, 0);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// すべて削除\r
+void LbReset(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMsg(hWnd, id, LB_RESETCONTENT, 0, 0);\r
+}\r
+\r
+// インデックスを指定して選択\r
+void LbSelectIndex(HWND hWnd, UINT id, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMsg(hWnd, id, LB_SETCURSEL, index, 0);\r
+}\r
+\r
+// データを取得\r
+UINT LbGetData(HWND hWnd, UINT id, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || index == INFINITE)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return SendMsg(hWnd, id, LB_GETITEMDATA, index, 0);\r
+}\r
+\r
+// データを検索\r
+UINT LbFindData(HWND hWnd, UINT id, UINT data)\r
+{\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       num = LbNum(hWnd, id);\r
+       if (num == INFINITE)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               if (LbGetData(hWnd, id, i) == data)\r
+               {\r
+                       return i;\r
+               }\r
+       }\r
+\r
+       return INFINITE;\r
+}\r
+\r
+// アイテムの高さを設定\r
+void LbSetHeight(HWND hWnd, UINT id, UINT value)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMsg(hWnd, id, LB_SETITEMHEIGHT, 0, value);\r
+}\r
+\r
+// データを指定して検索\r
+void LbSelect(HWND hWnd, UINT id, int data)\r
+{\r
+       UINT index;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (data == INFINITE)\r
+       {\r
+               // 最初の項目を取得\r
+               LbSelectIndex(hWnd, id, 0);\r
+               return;\r
+       }\r
+\r
+       index = LbFindData(hWnd, id, data);\r
+       if (index == INFINITE)\r
+       {\r
+               // 発見できなかった\r
+               return;\r
+       }\r
+\r
+       // 選択する\r
+       LbSelectIndex(hWnd, id, index);\r
+}\r
+\r
+// 現在選択されている項目を取得\r
+UINT LbGetSelectIndex(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return SendMsg(hWnd, id, LB_GETCURSEL, 0, 0);\r
+}\r
+\r
+// 現在選択されている値を取得\r
+UINT LbGetSelect(HWND hWnd, UINT id)\r
+{\r
+       UINT index;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       index = LbGetSelectIndex(hWnd, id);\r
+       if (index == INFINITE)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return LbGetData(hWnd, id, index);\r
+}\r
+\r
+// パスワード入力ダイアログ状態変化\r
+void PasswordDlgProcChange(HWND hWnd, UI_PASSWORD_DLG *p)\r
+{\r
+       bool b;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = true;\r
+       if (IsEmpty(hWnd, E_USERNAME))\r
+       {\r
+               b = false;\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, b);\r
+\r
+       p->StartTick = Tick64();\r
+       if (p->RetryIntervalSec)\r
+       {\r
+               KillTimer(hWnd, 1);\r
+               Hide(hWnd, P_PROGRESS);\r
+               Hide(hWnd, S_COUNTDOWN);\r
+       }\r
+}\r
+\r
+// 文字列を取得\r
+wchar_t *CbGetStr(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return GetText(hWnd, id);\r
+}\r
+\r
+// 文字列検索\r
+UINT CbFindStr(HWND hWnd, UINT id, wchar_t *str)\r
+{\r
+       UINT ret;\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *tmp = CopyUniToStr(str);\r
+               ret = CbFindStr9xA(hWnd, id, tmp);\r
+               Free(tmp);\r
+               return ret;\r
+       }\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, CB_FINDSTRINGEXACT, -1, (LPARAM)str);\r
+\r
+       return ret;\r
+}\r
+UINT CbFindStr9xA(HWND hWnd, UINT id, char *str)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, CB_FINDSTRINGEXACT, -1, (LPARAM)str);\r
+\r
+       return ret;\r
+}\r
+\r
+// 項目数を取得\r
+UINT CbNum(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return SendMsg(hWnd, id, CB_GETCOUNT, 0, 0);\r
+}\r
+\r
+// 文字列追加\r
+UINT CbAddStrA(HWND hWnd, UINT id, char *str, UINT data)\r
+{\r
+       wchar_t *tmp;\r
+       UINT ret;\r
+       // 引く数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+       tmp = CopyStrToUni(str);\r
+       ret = CbAddStr(hWnd, id, tmp, data);\r
+       Free(tmp);\r
+       return ret;\r
+}\r
+UINT CbAddStr(HWND hWnd, UINT id, wchar_t *str, UINT data)\r
+{\r
+       UINT ret;\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = CopyUniToStr(str);\r
+               ret = CbAddStr9xA(hWnd, id, s, data);\r
+               Free(s);\r
+               return ret;\r
+       }\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, CB_ADDSTRING, 0, (LPARAM)str);\r
+       SendMsg(hWnd, id, CB_SETITEMDATA, ret, (LPARAM)data);\r
+\r
+       if (CbNum(hWnd, id) == 1)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               GetTxt(hWnd, id, tmp, sizeof(tmp));\r
+               if (UniStrLen(tmp) == 0)\r
+               {\r
+                       CbSelectIndex(hWnd, id, 0);\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+UINT CbAddStr9xA(HWND hWnd, UINT id, char *str, UINT data)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, CB_ADDSTRING, 0, (LPARAM)str);\r
+       SendMsg(hWnd, id, CB_SETITEMDATA, ret, (LPARAM)data);\r
+\r
+       if (CbNum(hWnd, id) == 1)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               GetTxt(hWnd, id, tmp, sizeof(tmp));\r
+               if (UniStrLen(tmp) == 0)\r
+               {\r
+                       CbSelectIndex(hWnd, id, 0);\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 文字列挿入\r
+UINT CbInsertStrA(HWND hWnd, UINT id, UINT index, char *str, UINT data)\r
+{\r
+       wchar_t *tmp;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+       tmp = CopyStrToUni(str);\r
+       ret = CbInsertStr(hWnd, id, index, tmp, data);\r
+       Free(tmp);\r
+       return ret;\r
+}\r
+UINT CbInsertStr(HWND hWnd, UINT id, UINT index, wchar_t *str, UINT data)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = CopyUniToStr(str);\r
+               ret = CbInsertStr9xA(hWnd, id, index, s, data);\r
+               Free(s);\r
+               return ret;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, CB_INSERTSTRING, index, (LPARAM)str);\r
+       SendMsg(hWnd, id, CB_SETITEMDATA, ret, (LPARAM)data);\r
+\r
+       if (CbNum(hWnd, id) == 1)\r
+       {\r
+               CbSelect(hWnd, id, 0);\r
+       }\r
+\r
+       return ret;\r
+}\r
+UINT CbInsertStr9xA(HWND hWnd, UINT id, UINT index, char *str, UINT data)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       ret = SendMsg(hWnd, id, CB_INSERTSTRING, index, (LPARAM)str);\r
+       SendMsg(hWnd, id, CB_SETITEMDATA, ret, (LPARAM)data);\r
+\r
+       if (CbNum(hWnd, id) == 1)\r
+       {\r
+               CbSelect(hWnd, id, 0);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// すべて削除\r
+void CbReset(HWND hWnd, UINT id)\r
+{\r
+       wchar_t *s;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = GetText(hWnd, id);\r
+\r
+       SendMsg(hWnd, id, CB_RESETCONTENT, 0, 0);\r
+\r
+       if (s != NULL)\r
+       {\r
+               SetText(hWnd, id, s);\r
+               Free(s);\r
+       }\r
+}\r
+\r
+// インデックスを指定して選択\r
+void CbSelectIndex(HWND hWnd, UINT id, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMsg(hWnd, id, CB_SETCURSEL, index, 0);\r
+}\r
+\r
+// データを取得\r
+UINT CbGetData(HWND hWnd, UINT id, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || index == INFINITE)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return SendMsg(hWnd, id, CB_GETITEMDATA, index, 0);\r
+}\r
+\r
+// データを検索\r
+UINT CbFindData(HWND hWnd, UINT id, UINT data)\r
+{\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       num = CbNum(hWnd, id);\r
+       if (num == INFINITE)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               if (CbGetData(hWnd, id, i) == data)\r
+               {\r
+                       return i;\r
+               }\r
+       }\r
+\r
+       return INFINITE;\r
+}\r
+\r
+// アイテムの高さを設定\r
+void CbSetHeight(HWND hWnd, UINT id, UINT value)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMsg(hWnd, id, CB_SETITEMHEIGHT, 0, value);\r
+}\r
+\r
+// データを指定して検索\r
+void CbSelect(HWND hWnd, UINT id, int data)\r
+{\r
+       UINT index;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (data == INFINITE)\r
+       {\r
+               // 最初の項目を取得\r
+               CbSelectIndex(hWnd, id, 0);\r
+               return;\r
+       }\r
+\r
+       index = CbFindData(hWnd, id, data);\r
+       if (index == INFINITE)\r
+       {\r
+               // 発見できなかった\r
+               return;\r
+       }\r
+\r
+       // 選択する\r
+       CbSelectIndex(hWnd, id, index);\r
+}\r
+\r
+// 現在選択されている項目を取得\r
+UINT CbGetSelectIndex(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return SendMsg(hWnd, id, CB_GETCURSEL, 0, 0);\r
+}\r
+\r
+// 現在選択されている値を取得\r
+UINT CbGetSelect(HWND hWnd, UINT id)\r
+{\r
+       UINT index;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       index = CbGetSelectIndex(hWnd, id);\r
+       if (index == INFINITE)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return CbGetData(hWnd, id, index);\r
+}\r
+\r
+// OK ボタンが押された\r
+void PasswordDlgOnOk(HWND hWnd, UI_PASSWORD_DLG *p)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetTxtA(hWnd, E_USERNAME, p->Username, sizeof(p->Username));\r
+       GetTxtA(hWnd, E_PASSWORD, p->Password, sizeof(p->Password));\r
+       p->Type = CbGetSelect(hWnd, C_TYPE);\r
+\r
+       if (p->ShowNoSavePassword)\r
+       {\r
+               p->NoSavePassword = IsChecked(hWnd, R_NO_SAVE_PASSWORD);\r
+       }\r
+\r
+       EndDialog(hWnd, true);\r
+}\r
+\r
+// パスワード入力ダイアログプロシージャ\r
+UINT PasswordDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       UI_PASSWORD_DLG *p = (UI_PASSWORD_DLG *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               SetIcon(hWnd, 0, ICO_KEY);\r
+               CbSetHeight(hWnd, C_TYPE, 18);\r
+               if (p->ServerName != NULL)\r
+               {\r
+                       FormatText(hWnd, 0, p->ServerName);\r
+               }\r
+               else\r
+               {\r
+                       SetText(hWnd, 0, _UU("PW_LOGIN_DLG_TITLE"));\r
+               }\r
+\r
+               if (p->ProxyServer == false)\r
+               {\r
+                       FormatText(hWnd, S_TITLE, p->ServerName == NULL ? "" : p->ServerName);\r
+               }\r
+               else\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+                       UniFormat(tmp, sizeof(tmp), _UU("PW_MSG_PROXY"), p->ServerName == NULL ? "" : p->ServerName);\r
+                       SetText(hWnd, S_TITLE, tmp);\r
+               }\r
+\r
+               // 接続方法の列挙\r
+               SendMsg(hWnd, C_TYPE, CBEM_SETUNICODEFORMAT, true, 0);\r
+\r
+               if (StrCmpi(p->Username, WINUI_PASSWORD_NULL_USERNAME) != 0)\r
+               {\r
+                       SetTextA(hWnd, E_USERNAME, p->Username);\r
+                       SetTextA(hWnd, E_PASSWORD, p->Password);\r
+               }\r
+               else\r
+               {\r
+                       p->RetryIntervalSec = 0;\r
+                       SetTextA(hWnd, E_USERNAME, "");\r
+                       SetTextA(hWnd, E_PASSWORD, "");\r
+               }\r
+\r
+               if (p->AdminMode == false)\r
+               {\r
+                       if (p->ProxyServer == false)\r
+                       {\r
+                               CbAddStr(hWnd, C_TYPE, _UU("PW_TYPE_1"), CLIENT_AUTHTYPE_PASSWORD);\r
+                               CbAddStr(hWnd, C_TYPE, _UU("PW_TYPE_2"), CLIENT_AUTHTYPE_PLAIN_PASSWORD);\r
+                       }\r
+                       else\r
+                       {\r
+                               CbAddStr(hWnd, C_TYPE, _UU("PW_TYPE_PROXY"), 0);\r
+                               Disable(hWnd, C_TYPE);\r
+                       }\r
+\r
+                       CbSelect(hWnd, C_TYPE, p->Type);\r
+               }\r
+               else\r
+               {\r
+                       CbAddStr(hWnd, C_TYPE, _UU("SM_PASSWORD_TYPE_STR"), 0);\r
+                       Disable(hWnd, C_TYPE);\r
+                       SetTextA(hWnd, E_USERNAME, "Administrator");\r
+                       Disable(hWnd, E_USERNAME);\r
+               }\r
+\r
+               if (IsEmpty(hWnd, E_USERNAME))\r
+               {\r
+                       FocusEx(hWnd, E_USERNAME);\r
+               }\r
+               else\r
+               {\r
+                       FocusEx(hWnd, E_PASSWORD);\r
+               }\r
+               LimitText(hWnd, E_USERNAME, MAX_USERNAME_LEN);\r
+               LimitText(hWnd, E_PASSWORD, MAX_PASSWORD_LEN);\r
+\r
+               PasswordDlgProcChange(hWnd, p);\r
+\r
+               if (p->RetryIntervalSec != 0)\r
+               {\r
+                       SetTimer(hWnd, 1, 50, NULL);\r
+                       FormatText(hWnd, S_COUNTDOWN, p->RetryIntervalSec);\r
+                       Show(hWnd, S_COUNTDOWN);\r
+                       Show(hWnd, P_PROGRESS);\r
+                       SetRange(hWnd, P_PROGRESS, 0, p->RetryIntervalSec * 1000);\r
+               }\r
+               else\r
+               {\r
+                       Hide(hWnd, S_COUNTDOWN);\r
+                       Hide(hWnd, P_PROGRESS);\r
+               }\r
+\r
+               if (p->ShowNoSavePassword)\r
+               {\r
+                       Show(hWnd, R_NO_SAVE_PASSWORD);\r
+                       Check(hWnd, R_NO_SAVE_PASSWORD, p->NoSavePassword);\r
+               }\r
+               else\r
+               {\r
+                       Hide(hWnd, R_NO_SAVE_PASSWORD);\r
+               }\r
+\r
+               p->StartTick = Tick64();\r
+\r
+               if (p->CancelEvent != NULL)\r
+               {\r
+                       SetTimer(hWnd, 2, 50, NULL);\r
+               }\r
+\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       if (p->RetryIntervalSec != 0)\r
+                       {\r
+                               wchar_t tmp[MAX_SIZE];\r
+                               UINT64 end, now, start;\r
+                               start = p->StartTick;\r
+                               end = p->StartTick + (UINT64)(p->RetryIntervalSec * 1000);\r
+                               now = Tick64();\r
+\r
+                               if (now <= end)\r
+                               {\r
+                                       UniFormat(tmp, sizeof(tmp), _UU("PW_RETRYCOUNT"), (UINT)((end - now) / 1000));\r
+                                       SetText(hWnd, S_COUNTDOWN, tmp);\r
+                                       SetPos(hWnd, P_PROGRESS, (UINT)(now - start));\r
+                               }\r
+                               else\r
+                               {\r
+                                       EndDialog(hWnd, true);\r
+                               }\r
+                       }\r
+                       break;\r
+\r
+               case 2:\r
+                       if (p->CancelEvent != NULL)\r
+                       {\r
+                               // 終了イベントを待機する\r
+                               HANDLE hEvent = (HANDLE)p->CancelEvent->pData;\r
+                               UINT ret = WaitForSingleObject(hEvent, 0);\r
+                               if (ret != WAIT_TIMEOUT)\r
+                               {\r
+                                       // 強制終了イベントがセットされた\r
+                                       Close(hWnd);\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       PasswordDlgOnOk(hWnd, p);\r
+                       break;\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               switch (HIWORD(wParam))\r
+               {\r
+               case EN_CHANGE:\r
+                       switch (LOWORD(wParam))\r
+                       {\r
+                       case E_USERNAME:\r
+                       case E_PASSWORD:\r
+                               PasswordDlgProcChange(hWnd, p);\r
+                               break;\r
+                       }\r
+                       break;\r
+               case CBN_SELCHANGE:\r
+                       switch (LOWORD(wParam))\r
+                       {\r
+                       case C_TYPE:\r
+                               PasswordDlgProcChange(hWnd, p);\r
+                               if (IsEmpty(hWnd, E_USERNAME))\r
+                               {\r
+                                       FocusEx(hWnd, E_USERNAME);\r
+                               }\r
+                               else\r
+                               {\r
+                                       FocusEx(hWnd, E_PASSWORD);\r
+                               }\r
+                               break;\r
+                       }\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// プログレスバーの位置を設定\r
+void SetPos(HWND hWnd, UINT id, UINT pos)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMsg(hWnd, id, PBM_SETPOS, pos, 0);\r
+}\r
+\r
+// プログレスバーの範囲を設定\r
+void SetRange(HWND hWnd, UINT id, UINT start, UINT end)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMsg(hWnd, id, PBM_SETRANGE32, start, end);\r
+}\r
+\r
+// パスワード入力ダイアログ\r
+bool PasswordDlg(HWND hWnd, UI_PASSWORD_DLG *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p->StartTick = Tick64();\r
+\r
+       return Dialog(hWnd, D_PASSWORD, PasswordDlgProc, p);\r
+}\r
+\r
+// パスフレーズ入力ダイアログ\r
+bool PassphraseDlg(HWND hWnd, char *pass, UINT pass_size, BUF *buf, bool p12)\r
+{\r
+       PASSPHRASE_DLG p;\r
+       // 引数チェック\r
+       if (pass == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&p, sizeof(PASSPHRASE_DLG));\r
+\r
+       p.buf = buf;\r
+       p.p12 = p12;\r
+\r
+       // まず暗号化されているかどうかを調べる\r
+       if (p12 == false)\r
+       {\r
+               // 秘密鍵\r
+               if (IsEncryptedK(buf, true) == false)\r
+               {\r
+                       // 暗号化されていない\r
+                       StrCpy(pass, pass_size, "");\r
+                       return true;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // PKCS#12\r
+               P12 *p12 = BufToP12(buf);\r
+               if (p12 == NULL)\r
+               {\r
+                       // 不明な形式だが暗号化されていない\r
+                       StrCpy(pass, pass_size, "");\r
+                       return true;\r
+               }\r
+\r
+               if (IsEncryptedP12(p12) == false)\r
+               {\r
+                       // 暗号化されていない\r
+                       StrCpy(pass, pass_size, "");\r
+                       FreeP12(p12);\r
+                       return true;\r
+               }\r
+               FreeP12(p12);\r
+       }\r
+\r
+       // ダイアログ表示\r
+       if (Dialog(hWnd, D_PASSPHRASE, PassphraseDlgProc, &p) == false)\r
+       {\r
+               // キャンセル\r
+               return false;\r
+       }\r
+\r
+       StrCpy(pass, pass_size, p.pass);\r
+\r
+       return true;\r
+}\r
+\r
+// WM_COMMAND ハンドラ\r
+void PassphraseDlgProcCommand(HWND hWnd, PASSPHRASE_DLG *p)\r
+{\r
+       char *pass;\r
+       bool ok;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pass = GetTextA(hWnd, E_PASSPHRASE);\r
+       if (pass == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ok = false;\r
+\r
+       if (p->p12 == false)\r
+       {\r
+               K *k;\r
+               k = BufToK(p->buf, true, true, pass);\r
+               if (k != NULL)\r
+               {\r
+                       ok = true;\r
+                       FreeK(k);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               X *x;\r
+               K *k;\r
+               P12 *p12;\r
+               p12 = BufToP12(p->buf);\r
+               if (p12 != NULL)\r
+               {\r
+                       if (ParseP12(p12, &x, &k, pass))\r
+                       {\r
+                               FreeX(x);\r
+                               FreeK(k);\r
+                               ok = true;\r
+                       }\r
+                       FreeP12(p12);\r
+               }\r
+       }\r
+\r
+       Free(pass);\r
+\r
+       SetEnable(hWnd, IDOK, ok);\r
+}\r
+\r
+// パスフレーズ入力ダイアログプロシージャ\r
+UINT PassphraseDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       PASSPHRASE_DLG *p = (PASSPHRASE_DLG *)param;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               PassphraseDlgProcCommand(hWnd, p);\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       GetTxtA(hWnd, E_PASSPHRASE, p->pass, sizeof(p->pass));\r
+                       EndDialog(hWnd, true);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+\r
+               switch (LOWORD(wParam))\r
+               {\r
+               case E_PASSPHRASE:\r
+                       PassphraseDlgProcCommand(hWnd, p);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, false);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// PKCS ユーティリティ\r
+void PkcsUtil()\r
+{\r
+       InitWinUi(_UU("PKCS_UTIL_TITLE"), _SS("DEFAULT_FONT"), _II("DEFAULT_FONT_SIZE"));\r
+       Dialog(NULL, D_PKCSUTIL, PkcsUtilProc, NULL);\r
+       FreeWinUi();\r
+}\r
+\r
+// PKCS 書き込み\r
+void PkcsUtilWrite(HWND hWnd)\r
+{\r
+       wchar_t *filename;\r
+       BUF *in_buf;\r
+       char filename_ansi[MAX_SIZE];\r
+       char pass[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       filename = OpenDlg(hWnd, _UU("DLG_PKCS12_FILTER"), _UU("PKCS_UTIL_SAVEDLG_TITLE"));\r
+       if (filename == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniToStr(filename_ansi, sizeof(filename_ansi), filename);\r
+\r
+       in_buf = ReadDump(filename_ansi);\r
+\r
+       if (in_buf == NULL)\r
+       {\r
+               MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("PKCS_UTIL_READ_ERROR"), filename);\r
+       }\r
+       else\r
+       {\r
+               if (PassphraseDlg(hWnd, pass, sizeof(pass), in_buf, true))\r
+               {\r
+                       P12 *p12 = BufToP12(in_buf);\r
+                       if (p12 == NULL)\r
+                       {\r
+                               MsgBox(hWnd, MB_ICONEXCLAMATION, _UU("PKCS_UTIL_BAD_FILE"));\r
+                       }\r
+                       else\r
+                       {\r
+                               X *x = NULL;\r
+                               K *k = NULL;\r
+                               BUF *b;\r
+                               ParseP12(p12, &x, &k, pass);\r
+                               FreeP12(p12);\r
+                               p12 = NewP12(x, k, NULL);\r
+                               FreeX(x);\r
+                               FreeK(k);\r
+                               b = P12ToBuf(p12);\r
+                               FreeP12(p12);\r
+                               if (b != NULL)\r
+                               {\r
+                                       // バッチ処理\r
+                                       WINUI_SECURE_BATCH batch[] =\r
+                                       {\r
+                                               {WINUI_SECURE_WRITE_DATA, _SS("PKCS_UTIL_SECA_FILENAME"), false,\r
+                                                       b, NULL, NULL, NULL, NULL, NULL},\r
+                                       };\r
+\r
+                                       if (SecureDeviceWindow(hWnd, batch, sizeof(batch) / sizeof(batch[0]), 2, 0))\r
+                                       {\r
+                                               MsgBoxEx(hWnd, MB_ICONINFORMATION, _UU("PKCS_UTIL_WRITE_OK_MSG"), filename);\r
+                                       }\r
+                               }\r
+                               FreeBuf(b);\r
+                       }\r
+               }\r
+\r
+               FreeBuf(in_buf);\r
+       }\r
+\r
+       Free(filename);\r
+}\r
+\r
+// PKCS 消去\r
+void PkcsUtilErase(HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2,\r
+               _UU("PKCS_MAKE_SURE")) == IDYES)\r
+       {\r
+               // バッチ処理\r
+               WINUI_SECURE_BATCH batch[] =\r
+               {\r
+                       {WINUI_SECURE_DELETE_OBJECT, _SS("PKCS_UTIL_SECA_FILENAME"), false,\r
+                               NULL, NULL, NULL, NULL, NULL, NULL},\r
+               };\r
+\r
+               if (SecureDeviceWindow(hWnd, batch, sizeof(batch) / sizeof(batch[0]), 2, 0))\r
+               {\r
+                       MsgBox(hWnd, MB_ICONINFORMATION, _UU("PKCS_UTIL_DELETE_OK_MSG"));\r
+               }\r
+       }\r
+}\r
+\r
+// PKCS ユーティリティ ダイアログ\r
+UINT PkcsUtilProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               DlgFont(hWnd, S_TITLE, 12, true);\r
+               SetIcon(hWnd, 0, ICO_CERT);\r
+               SetFont(hWnd, S_COPYRIGHT, GetFont("Arial", 8, false, false, false, false));\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case B_WRITE:\r
+                       PkcsUtilWrite(hWnd);\r
+                       break;\r
+\r
+               case B_ERASE:\r
+                       PkcsUtilErase(hWnd);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               EndDialog(hWnd, 0);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// [ファイルを保存する] ダイアログ\r
+wchar_t *SaveDlg(HWND hWnd, wchar_t *filter, wchar_t *title, wchar_t *default_name, wchar_t *default_ext)\r
+{\r
+       wchar_t *filter_str;\r
+       wchar_t tmp[MAX_SIZE];\r
+       OPENFILENAMEW o;\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *ret, *s1, *s2, *s3, *s4;\r
+               wchar_t *wr;\r
+               s1 = CopyUniToStr(filter);\r
+               s2 = CopyUniToStr(title);\r
+               s3 = CopyUniToStr(default_name);\r
+               s4 = CopyUniToStr(default_ext);\r
+               ret = SaveDlgA(hWnd, s1, s2, s3, s4);\r
+               Free(s1);\r
+               Free(s2);\r
+               Free(s3);\r
+               Free(s4);\r
+               wr = CopyStrToUni(ret);\r
+               Free(ret);\r
+               return wr;\r
+       }\r
+\r
+       // 引数チェック\r
+       if (filter == NULL)\r
+       {\r
+               filter = _UU("DLG_ALL_FILES");\r
+       }\r
+\r
+       filter_str = MakeFilter(filter);\r
+\r
+       Zero(&o, sizeof(o));\r
+       Zero(tmp, sizeof(tmp));\r
+\r
+       if (default_name != NULL)\r
+       {\r
+               UniStrCpy(tmp, sizeof(tmp), default_name);\r
+       }\r
+\r
+       o.lStructSize = sizeof(o);\r
+       \r
+       if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType) || (OS_IS_WINDOWS_NT(GetOsInfo()->OsType) && GET_KETA(GetOsInfo()->OsType, 100) <= 1))\r
+       {\r
+               o.lStructSize = OPENFILENAME_SIZE_VERSION_400W;\r
+       }\r
+\r
+       o.hwndOwner = hWnd;\r
+       o.hInstance = GetModuleHandleA(NULL);\r
+       o.lpstrFile = tmp;\r
+       o.lpstrTitle = title;\r
+       o.lpstrFilter = filter_str;\r
+       o.nMaxFile = sizeof(tmp);\r
+       o.Flags = OFN_OVERWRITEPROMPT;\r
+       o.lpstrDefExt = default_ext;\r
+\r
+       if (GetSaveFileNameW(&o) == false)\r
+       {\r
+               Free(filter_str);\r
+               return NULL;\r
+       }\r
+\r
+       Free(filter_str);\r
+\r
+       return UniCopyStr(tmp);\r
+}\r
+char *SaveDlgA(HWND hWnd, char *filter, char *title, char *default_name, char *default_ext)\r
+{\r
+       char *filter_str;\r
+       char tmp[MAX_SIZE];\r
+       OPENFILENAME o;\r
+       // 引数チェック\r
+       if (filter == NULL)\r
+       {\r
+               filter = _SS("DLG_ALL_FILES");\r
+       }\r
+\r
+       filter_str = MakeFilterA(filter);\r
+\r
+       Zero(&o, sizeof(o));\r
+       Zero(tmp, sizeof(tmp));\r
+\r
+       if (default_name != NULL)\r
+       {\r
+               StrCpy(tmp, sizeof(tmp), default_name);\r
+       }\r
+\r
+       o.lStructSize = sizeof(o);\r
+       \r
+       if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType) || (OS_IS_WINDOWS_NT(GetOsInfo()->OsType) && GET_KETA(GetOsInfo()->OsType, 100) <= 1))\r
+       {\r
+               o.lStructSize = OPENFILENAME_SIZE_VERSION_400A;\r
+       }\r
+\r
+       o.hwndOwner = hWnd;\r
+       o.hInstance = GetModuleHandleA(NULL);\r
+       o.lpstrFile = tmp;\r
+       o.lpstrTitle = title;\r
+       o.lpstrFilter = filter_str;\r
+       o.nMaxFile = sizeof(tmp);\r
+       o.Flags = OFN_OVERWRITEPROMPT;\r
+       o.lpstrDefExt = default_ext;\r
+\r
+       if (GetSaveFileName(&o) == false)\r
+       {\r
+               Free(filter_str);\r
+               return NULL;\r
+       }\r
+\r
+       Free(filter_str);\r
+\r
+       return CopyStr(tmp);\r
+}\r
+\r
+// [ファイルを開く] ダイアログ\r
+wchar_t *OpenDlg(HWND hWnd, wchar_t *filter, wchar_t *title)\r
+{\r
+       wchar_t *filter_str;\r
+       wchar_t tmp[MAX_SIZE];\r
+       OPENFILENAMEW o;\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *ret;\r
+               char *filter_a;\r
+               char *title_a;\r
+               wchar_t *w;\r
+               filter_a = CopyUniToStr(filter);\r
+               title_a = CopyUniToStr(title);\r
+               ret = OpenDlgA(hWnd, filter_a, title_a);\r
+               Free(filter_a);\r
+               Free(title_a);\r
+               w = CopyStrToUni(ret);\r
+               Free(ret);\r
+               return w;\r
+       }\r
+\r
+       // 引数チェック\r
+       if (filter == NULL)\r
+       {\r
+               filter = _UU("DLG_ALL_FILES");\r
+       }\r
+\r
+       filter_str = MakeFilter(filter);\r
+\r
+       Zero(&o, sizeof(OPENFILENAMEW));\r
+       Zero(tmp, sizeof(tmp));\r
+\r
+       o.lStructSize = sizeof(o);\r
+\r
+\r
+       if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType) || (OS_IS_WINDOWS_NT(GetOsInfo()->OsType) && GET_KETA(GetOsInfo()->OsType, 100) <= 1))\r
+       {\r
+               o.lStructSize = OPENFILENAME_SIZE_VERSION_400W;\r
+       }\r
+\r
+\r
+       o.hwndOwner = hWnd;\r
+       o.hInstance = GetModuleHandleA(NULL);\r
+       o.lpstrFilter = filter_str;\r
+       o.lpstrFile = tmp;\r
+       o.nMaxFile = sizeof(tmp);\r
+       o.lpstrTitle = title;\r
+       o.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;\r
+\r
+       if (GetOpenFileNameW(&o) == false)\r
+       {\r
+               Free(filter_str);\r
+               return NULL;\r
+       }\r
+\r
+       Free(filter_str);\r
+\r
+       return UniCopyStr(tmp);\r
+}\r
+char *OpenDlgA(HWND hWnd, char *filter, char *title)\r
+{\r
+       char *filter_str;\r
+       char tmp[MAX_SIZE];\r
+       OPENFILENAME o;\r
+       // 引数チェック\r
+       if (filter == NULL)\r
+       {\r
+               filter = _SS("DLG_ALL_FILES");\r
+       }\r
+\r
+       filter_str = MakeFilterA(filter);\r
+\r
+       Zero(&o, sizeof(OPENFILENAME));\r
+       Zero(tmp, sizeof(tmp));\r
+\r
+       o.lStructSize = sizeof(o);\r
+\r
+       if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType) || (OS_IS_WINDOWS_NT(GetOsInfo()->OsType) && GET_KETA(GetOsInfo()->OsType, 100) <= 1))\r
+       {\r
+               o.lStructSize = OPENFILENAME_SIZE_VERSION_400A;\r
+       }\r
+\r
+       o.hwndOwner = hWnd;\r
+       o.hInstance = GetModuleHandleA(NULL);\r
+       o.lpstrFilter = filter_str;\r
+       o.lpstrFile = tmp;\r
+       o.nMaxFile = sizeof(tmp);\r
+       o.lpstrTitle = title;\r
+       o.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;\r
+\r
+       if (GetOpenFileName(&o) == false)\r
+       {\r
+               Free(filter_str);\r
+               return NULL;\r
+       }\r
+\r
+       Free(filter_str);\r
+\r
+       return CopyStr(tmp);\r
+}\r
+\r
+// フィルタ文字列の生成\r
+wchar_t *MakeFilter(wchar_t *str)\r
+{\r
+       UINT i;\r
+       wchar_t *ret;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(UniStrSize(str) + 32);\r
+\r
+       for (i = 0;i < UniStrLen(str);i++)\r
+       {\r
+               if (str[i] == L'|')\r
+               {\r
+                       ret[i] = L'\0';\r
+               }\r
+               else\r
+               {\r
+                       ret[i] = str[i];\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+char *MakeFilterA(char *str)\r
+{\r
+       UINT i;\r
+       char *ret;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(StrSize(str) + 32);\r
+\r
+       for (i = 0;i < StrLen(str);i++)\r
+       {\r
+               if (str[i] == '|')\r
+               {\r
+                       ret[i] = '\0';\r
+               }\r
+               else\r
+               {\r
+                       ret[i] = str[i];\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// バッチの実行\r
+bool ExecuteSecureDeviceBatch(HWND hWnd, SECURE *sec, SECURE_DEVICE_THREAD *p, SECURE_DEVICE *dev, WINUI_SECURE_BATCH *batch)\r
+{\r
+       LIST *o;\r
+       void *buf;\r
+       UINT size = 10 * 1024;          // データの最大サイズ\r
+       UINT type = INFINITE;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL || dev == NULL || batch == NULL || sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       switch (batch->Type)\r
+       {\r
+       case WINUI_SECURE_DELETE_CERT:\r
+               type = SEC_X;\r
+               goto DELETE_OBJECT;\r
+\r
+       case WINUI_SECURE_DELETE_KEY:\r
+               type = SEC_K;\r
+               goto DELETE_OBJECT;\r
+\r
+       case WINUI_SECURE_DELETE_DATA:\r
+               type = SEC_DATA;\r
+               goto DELETE_OBJECT;\r
+\r
+       case WINUI_SECURE_DELETE_OBJECT:\r
+               // オブジェクトの削除\r
+DELETE_OBJECT:\r
+               SetText(hWnd, S_STATUS, _UU("SEC_DELETE"));\r
+               if (DeleteSecObjectByName(sec, batch->Name, type) == false)\r
+               {\r
+                       p->ErrorMessage = UniCopyStr(_UU("SEC_ERROR_DELETE"));\r
+                       return false;\r
+               }\r
+               break;\r
+\r
+       case WINUI_SECURE_ENUM_OBJECTS:\r
+               // オブジェクトの列挙\r
+               SetText(hWnd, S_STATUS, _UU("SEC_ENUM"));\r
+               o = EnumSecObject(sec);\r
+               if (o == NULL)\r
+               {\r
+                       p->ErrorMessage = UniCopyStr(_UU("SEC_ERROR_ENUM"));\r
+                       return false;\r
+               }\r
+\r
+               batch->EnumList = o;\r
+               break;\r
+\r
+       case WINUI_SECURE_WRITE_DATA:\r
+               // データの書き込み\r
+               SetText(hWnd, S_STATUS, _UU("SEC_WRITE_DATA"));\r
+               if (WriteSecData(sec, batch->Private, batch->Name, batch->InputData->Buf, batch->InputData->Size) == false)\r
+               {\r
+                       p->ErrorMessage = UniCopyStr(dev->Type != SECURE_USB_TOKEN ?\r
+                               _UU("SEC_ERROR_WRITE_1") : _UU("SEC_ERROR_WRITE_2"));\r
+                       return false;\r
+               }\r
+               break;\r
+\r
+       case WINUI_SECURE_READ_DATA:\r
+               // データの読み込み\r
+               SetText(hWnd, S_STATUS, _UU("SEC_READ_DATA"));\r
+               buf = MallocEx(size, true);\r
+               size = ReadSecData(sec, batch->Name, buf, size);\r
+               if (size == 0)\r
+               {\r
+                       Free(buf);\r
+                       p->ErrorMessage = UniCopyStr(dev->Type != SECURE_USB_TOKEN ?\r
+                               _UU("SEC_ERROR_NOT_FOUND_1") : _UU("SEC_ERROR_NOT_FOUND_2"));\r
+                       return false;\r
+               }\r
+               batch->OutputData = NewBuf();\r
+               WriteBuf(batch->OutputData, buf, size);\r
+               SeekBuf(batch->OutputData, 0, 0);\r
+               Free(buf);\r
+               break;\r
+\r
+       case WINUI_SECURE_WRITE_CERT:\r
+               // 証明書の書き込み\r
+               SetText(hWnd, S_STATUS, _UU("SEC_WRITE_CERT"));\r
+               if (WriteSecCert(sec, batch->Private, batch->Name, batch->InputX) == false)\r
+               {\r
+                       p->ErrorMessage = UniCopyStr(dev->Type != SECURE_USB_TOKEN ?\r
+                               _UU("SEC_ERROR_WRITE_1") : _UU("SEC_ERROR_WRITE_2"));\r
+                       return false;\r
+               }\r
+               break;\r
+\r
+       case WINUI_SECURE_READ_CERT:\r
+               // 証明書の読み込み\r
+               SetText(hWnd, S_STATUS, _UU("SEC_READ_CERT"));\r
+               batch->OutputX = ReadSecCert(sec, batch->Name);\r
+               if (batch->OutputX == NULL)\r
+               {\r
+                       p->ErrorMessage = UniCopyStr(dev->Type != SECURE_USB_TOKEN ?\r
+                               _UU("SEC_ERROR_NOT_FOUND_1") : _UU("SEC_ERROR_NOT_FOUND_2"));\r
+                       return false;\r
+               }\r
+               break;\r
+\r
+       case WINUI_SECURE_WRITE_KEY:\r
+               // 秘密鍵の書き込み\r
+               SetText(hWnd, S_STATUS, _UU("SEC_WRITE_KEY"));\r
+               if (WriteSecKey(sec, batch->Private, batch->Name, batch->InputK) == false)\r
+               {\r
+                       p->ErrorMessage = UniCopyStr(dev->Type != SECURE_USB_TOKEN ?\r
+                               _UU("SEC_ERROR_WRITE_1") : _UU("SEC_ERROR_WRITE_2"));\r
+                       return false;\r
+               }\r
+               break;\r
+\r
+       case WINUI_SECURE_SIGN_WITH_KEY:\r
+               // 署名\r
+               SetText(hWnd, S_STATUS, _UU("SEC_SIGN"));\r
+               if (SignSec(sec, batch->Name, batch->OutputSign, batch->InputData->Buf, batch->InputData->Size) == false)\r
+               {\r
+                       p->ErrorMessage = UniCopyStr(dev->Type != SECURE_USB_TOKEN ?\r
+                               _UU("SEC_ERROR_SIGN_1") : _UU("SEC_ERROR_SIGN_2"));\r
+                       return false;\r
+               }\r
+               break;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// セキュアデバイス操作をバッチ処理で実行する\r
+void SecureDeviceBatch(HWND hWnd, SECURE *sec, SECURE_DEVICE_THREAD *p, SECURE_DEVICE *dev)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL || dev == NULL || sec == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 逐次処理を行う\r
+       for (i = 0;i < p->w->num_batch;i++)\r
+       {\r
+               WINUI_SECURE_BATCH *batch = &p->w->batch[i];\r
+\r
+               if (ExecuteSecureDeviceBatch(hWnd, sec, p, dev, batch) == false)\r
+               {\r
+                       // 1 つでも失敗したら直ちに中断する\r
+                       return;\r
+               }\r
+       }\r
+\r
+       // すべてのバッチ処理が成功した\r
+       p->Succeed = true;\r
+}\r
+\r
+// セキュアデバイス操作を行うスレッド\r
+void SecureDeviceThread(THREAD *t, void *param)\r
+{\r
+       SECURE *sec;\r
+       SECURE_DEVICE_THREAD *p = (SECURE_DEVICE_THREAD *)param;\r
+       SECURE_DEVICE *dev;\r
+       HWND hWnd;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p->Succeed = false;\r
+       p->ErrorMessage = NULL;\r
+\r
+       hWnd = p->hWnd;\r
+\r
+       // デバイスを開く\r
+       dev = GetSecureDevice(p->w->device_id);\r
+       SetText(hWnd, S_STATUS, _UU("SEC_OPENING"));\r
+       sec = OpenSec(p->w->device_id);\r
+       if (sec == NULL)\r
+       {\r
+               // デバイスオープン失敗\r
+               if (p->w->device_id != 9)\r
+               {\r
+                       p->ErrorMessage = CopyUniFormat(_UU("SEC_ERROR_OPEN_DEVICE"), dev->DeviceName);\r
+               }\r
+               else\r
+               {\r
+                       p->ErrorMessage = CopyUniFormat(_UU("SEC_ERROR_OPEN_DEVICEEX"), dev->DeviceName);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // セッションを開く\r
+               SetText(hWnd, S_STATUS, _UU("SEC_OPEN_SESSION"));\r
+               if (OpenSecSession(sec, 0) == false)\r
+               {\r
+                       // セッション初期化失敗\r
+                       p->ErrorMessage = CopyUniFormat(_UU("SEC_ERROR_OPEN_SESSION"), dev->DeviceName);\r
+               }\r
+               else\r
+               {\r
+                       // ログイン\r
+                       SetText(hWnd, S_STATUS, _UU("SEC_LOGIN"));\r
+                       if (LoginSec(sec, p->pin) == false)\r
+                       {\r
+                               // ログイン失敗\r
+                               p->ErrorMessage =UniCopyStr(_UU("SEC_ERROR_LOGIN"));\r
+                       }\r
+                       else\r
+                       {\r
+                               // バッチ処理メイン\r
+                               SetText(hWnd, S_STATUS, _UU("SEC_INIT_BATCH"));\r
+                               SecureDeviceBatch(hWnd, sec, p, dev);\r
+\r
+                               // ログアウト\r
+                               SetText(hWnd, S_STATUS, _UU("SEC_LOGOUT"));\r
+                               LogoutSec(sec);\r
+                       }\r
+\r
+                       // セッションを閉じる\r
+                       SetText(hWnd, S_STATUS, _UU("SEC_CLOSE_SESSION"));\r
+                       CloseSecSession(sec);\r
+               }\r
+\r
+               // デバイスを閉じる\r
+               SetText(hWnd, S_STATUS, _UU("SEC_CLOSING"));\r
+               CloseSec(sec);\r
+       }\r
+\r
+       if (p->Succeed)\r
+       {\r
+               // 成功した場合は 150ms メッセージを表示する (サービス)\r
+               SetText(hWnd, S_STATUS, _UU("SEC_FINISHED"));\r
+               SleepThread(150);\r
+       }\r
+\r
+       SendMessage(p->hWnd, WM_APP + 1, 0, 0);\r
+}\r
+\r
+// セキュアデバイス操作を開始する\r
+void StartSecureDevice(HWND hWnd, SECURE_DEVICE_WINDOW *w)\r
+{\r
+       SECURE_DEVICE_THREAD *p;\r
+       // 引数チェック\r
+       if (hWnd == NULL || w == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // コントロールを無効にする\r
+       EnableSecureDeviceWindowControls(hWnd, false);\r
+\r
+       // スレッドを開始する\r
+       p = ZeroMalloc(sizeof(SECURE_DEVICE_THREAD));\r
+       p->w = w;\r
+       p->hWnd = hWnd;\r
+       w->p = p;\r
+       p->pin = GetTextA(hWnd, E_PIN);\r
+       ReleaseThread(NewThread(SecureDeviceThread, p));\r
+}\r
+\r
+// セキュアデバイス操作用ウインドウのコントロールを有効・無効化する\r
+void EnableSecureDeviceWindowControls(HWND hWnd, bool enable)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (enable)\r
+       {\r
+               Show(hWnd, S_PIN_CODE);\r
+               Show(hWnd, E_PIN);\r
+               Show(hWnd, S_WARNING);\r
+       }\r
+       else\r
+       {\r
+               Hide(hWnd, S_PIN_CODE);\r
+               Hide(hWnd, E_PIN);\r
+               Hide(hWnd, S_WARNING);\r
+       }\r
+\r
+       SetEnable(hWnd, IDOK, enable);\r
+       SetEnable(hWnd, IDCANCEL, enable);\r
+       SetEnable(hWnd, S_TITLE, enable);\r
+       SetEnable(hWnd, S_DEVICE_INFO, enable);\r
+       SetEnable(hWnd, S_INSERT_SECURE, enable);\r
+\r
+       if (enable == false)\r
+       {\r
+               DisableClose(hWnd);\r
+               SetText(hWnd, S_STATUS, L"");\r
+               Show(hWnd, S_STATUS);\r
+               PlayAvi(hWnd, A_PROGRESS, true);\r
+       }\r
+       else\r
+       {\r
+               EnableClose(hWnd);\r
+               SetText(hWnd, S_STATUS, L"");\r
+               Hide(hWnd, S_STATUS);\r
+               StopAvi(hWnd, A_PROGRESS);\r
+       }\r
+}\r
+\r
+// セキュアデバイス操作用ウインドウプロシージャ\r
+UINT SecureDeviceWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)\r
+{\r
+       SECURE_DEVICE_WINDOW *w = (SECURE_DEVICE_WINDOW *)param;\r
+       SECURE_DEVICE *dev = GetSecureDevice(w->device_id);\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               if (dev == NULL)\r
+               {\r
+                       MsgBoxEx(hWnd, MB_ICONEXCLAMATION, _UU("SEC_ERROR_INVALID_ID"), w->device_id);\r
+                       EndDialog(hWnd, 0);\r
+                       break;\r
+               }\r
+\r
+               if (IsJPKI(dev->Id))\r
+               {\r
+                       // 住基カード\r
+                       Hide(hWnd, S_IMAGE);\r
+                       Show(hWnd, S_IMAGE2);\r
+                       Hide(hWnd, S_IMAGE_TSUKUBA);\r
+               }\r
+               else\r
+               {\r
+                       // 普通のカード\r
+                       Hide(hWnd, S_IMAGE2);\r
+\r
+                       if (w->BitmapId != 0)\r
+                       {\r
+                               // 筑波大学用\r
+                               Hide(hWnd, S_IMAGE);\r
+                               Show(hWnd, S_IMAGE_TSUKUBA);\r
+                       }\r
+                       else\r
+                       {\r
+                               // 一般用\r
+                               Show(hWnd, S_IMAGE);\r
+                               Hide(hWnd, S_IMAGE_TSUKUBA);\r
+                       }\r
+               }\r
+\r
+               FormatText(hWnd, 0, dev->Type != SECURE_USB_TOKEN ? _UU("SEC_SMART_CARD") : _UU("SEC_USB_TOKEN"),\r
+                       dev->DeviceName);\r
+               FormatText(hWnd, S_TITLE, dev->DeviceName);\r
+               FormatText(hWnd, S_INSERT_SECURE,\r
+                       dev->Type != SECURE_USB_TOKEN ? _UU("SEC_INIT_MSG_1") : _UU("SEC_INIT_MSG_2"));\r
+               FormatText(hWnd, S_DEVICE_INFO,\r
+                       dev->DeviceName, dev->Manufacturer, dev->ModuleName);\r
+\r
+               DlgFont(hWnd, S_SOFTWARE_TITLE, 11, 0);\r
+               SetText(hWnd, S_SOFTWARE_TITLE, title_bar);\r
+\r
+               DlgFont(hWnd, S_TITLE, 14, true);\r
+               DlgFont(hWnd, S_DEVICE_INFO, 11, false);\r
+               DlgFont(hWnd, S_STATUS, 13, true);\r
+               EnableSecureDeviceWindowControls(hWnd, true);\r
+               OpenAvi(hWnd, A_PROGRESS, AVI_PROGRESS);\r
+\r
+               SetIcon(hWnd, 0, ICO_KEY);\r
+\r
+               // 初期 PIN\r
+               if ((w->default_pin != NULL && StrLen(w->default_pin) != 0) || (cached_pin_code_expires >= Tick64()))\r
+               {\r
+                       if (w->default_pin != NULL && StrLen(w->default_pin) != 0)\r
+                       {\r
+                               SetTextA(hWnd, E_PIN, w->default_pin);\r
+                       }\r
+                       else\r
+                       {\r
+                               SetTextA(hWnd, E_PIN, cached_pin_code);\r
+                       }\r
+                       SetTimer(hWnd, 1, 1, NULL);\r
+               }\r
+\r
+               break;\r
+\r
+       case WM_TIMER:\r
+               switch (wParam)\r
+               {\r
+               case 1:\r
+                       KillTimer(hWnd, 1);\r
+                       Command(hWnd, IDOK);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case IDOK:\r
+                       StartSecureDevice(hWnd, w);\r
+                       break;\r
+\r
+               case IDCANCEL:\r
+                       Close(hWnd);\r
+                       break;\r
+               }\r
+               break;\r
+\r
+       case WM_CLOSE:\r
+               if (IsEnable(hWnd, IDCANCEL))\r
+               {\r
+                       CloseAvi(hWnd, A_PROGRESS);\r
+                       EndDialog(hWnd, false);\r
+               }\r
+               break;\r
+\r
+       case WM_APP + 1:\r
+               // スレッドから応答があった\r
+               if (w->p != NULL)\r
+               {\r
+                       if (w->p->Succeed)\r
+                       {\r
+                               // 成功\r
+                               if (w->default_pin != NULL)\r
+                               {\r
+                                       StrCpy(w->default_pin, 128, w->p->pin);\r
+                               }\r
+                               StrCpy(cached_pin_code, sizeof(cached_pin_code), w->p->pin);\r
+                               cached_pin_code_expires = Tick64() + (UINT64)WINUI_SECUREDEVICE_PIN_CACHE_TIME;\r
+                               Free(w->p->pin);\r
+                               Free(w->p);\r
+                               EndDialog(hWnd, true);\r
+                       }\r
+                       else\r
+                       {\r
+                               // 失敗\r
+                               cached_pin_code_expires = 0;\r
+                               EnableSecureDeviceWindowControls(hWnd, true);\r
+                               FocusEx(hWnd, E_PIN);\r
+                               MsgBox(hWnd, MB_ICONEXCLAMATION, w->p->ErrorMessage);\r
+                               Free(w->p->pin);\r
+                               Free(w->p->ErrorMessage);\r
+                               Free(w->p);\r
+                       }\r
+               }\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// WM_COMMAND を送信する\r
+void Command(HWND hWnd, UINT id)\r
+{\r
+       SendMessage(hWnd, WM_COMMAND, id, 0);\r
+}\r
+\r
+// セキュアデバイスウインドウを表示する\r
+bool SecureDeviceWindow(HWND hWnd, WINUI_SECURE_BATCH *batch, UINT num_batch, UINT device_id, UINT bitmap_id)\r
+{\r
+       SECURE_DEVICE_WINDOW w;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (batch == NULL || num_batch == 0 || device_id == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 成功フラグを初期化\r
+       for (i = 0;i < num_batch;i++)\r
+       {\r
+               batch[i].Succeed = false;\r
+       }\r
+\r
+       Zero(&w, sizeof(w));\r
+       w.batch = batch;\r
+       w.device_id = device_id;\r
+       w.num_batch = num_batch;\r
+       w.BitmapId = bitmap_id;\r
+\r
+       // ダイアログを開く\r
+       return (bool)Dialog(hWnd, D_SECURE, SecureDeviceWindowProc, &w);\r
+}\r
+\r
+// AVI を停止する\r
+void StopAvi(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Animate_Stop(DlgItem(hWnd, id));\r
+       Hide(hWnd, id);\r
+}\r
+\r
+// AVI を再生する\r
+void PlayAvi(HWND hWnd, UINT id, bool repeat)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Show(hWnd, id);\r
+       Animate_Play(DlgItem(hWnd, id), 0, -1, (repeat ? -1 : 0));\r
+}\r
+\r
+// AVI ファイルを閉じる\r
+void CloseAvi(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StopAvi(hWnd, id);\r
+       Animate_Close(DlgItem(hWnd, id));\r
+}\r
+\r
+// AVI ファイルを開く\r
+void OpenAvi(HWND hWnd, UINT id, UINT avi_id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || avi_id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Hide(hWnd, id);\r
+       Animate_OpenEx(DlgItem(hWnd, id), hDll, MAKEINTRESOURCE(avi_id));\r
+}\r
+\r
+// フォントをコントロールに設定する\r
+void DlgFont(HWND hWnd, UINT id, UINT size, UINT bold)\r
+{\r
+       DIALOG_PARAM *param = (DIALOG_PARAM *)GetParam(hWnd);\r
+\r
+       if (param == NULL || param->meiryo == false)\r
+       {\r
+               SetFont(hWnd, id, Font(size, bold));\r
+       }\r
+       else\r
+       {\r
+               SetFont(hWnd, id, GetFont((_GETLANG() == 2 ? "Microsoft YaHei" : "Meiryo"), size, bold, false, false, false));\r
+       }\r
+}\r
+\r
+// 標準的なフォントを生成する\r
+HFONT Font(UINT size, UINT bold)\r
+{\r
+       return GetFont(NULL, size, bold, false, false, false);\r
+}\r
+\r
+// 内部管理用ダイアログプロシージャ\r
+UINT CALLBACK InternalDialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)\r
+{\r
+       DIALOG_PARAM *param = (DIALOG_PARAM *)GetParam(hWnd);\r
+       void *app_param = NULL;\r
+       bool white_flag = false;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (msg == WM_INITDIALOG)\r
+       {\r
+               DoEvents(hWnd);\r
+       }\r
+\r
+       if (param == NULL)\r
+       {\r
+               if (msg == WM_INITDIALOG)\r
+               {\r
+                       param = (void *)lParam;\r
+                       InitDialogInternational(hWnd, param);\r
+               }\r
+       }\r
+       if (param != NULL)\r
+       {\r
+               app_param = param->param;\r
+               white_flag = param->white;\r
+       }\r
+\r
+       ret = DlgProc(hWnd, msg, wParam, lParam, white_flag);\r
+       if (ret != 0)\r
+       {\r
+               return ret;\r
+       }\r
+\r
+       ret = 0;\r
+\r
+       if (param != NULL)\r
+       {\r
+               if (param->proc != NULL)\r
+               {\r
+                       ret = param->proc(hWnd, msg, wParam, lParam, app_param);\r
+               }\r
+               else\r
+               {\r
+                       if (msg == WM_CLOSE)\r
+                       {\r
+                               EndDialog(hWnd, 0);\r
+                       }\r
+                       else if (msg == WM_COMMAND && (wParam == IDOK || wParam == IDCANCEL))\r
+                       {\r
+                               Close(hWnd);\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (msg == WM_INITDIALOG)\r
+       {\r
+               SetForegroundWindow(hWnd);\r
+               SetActiveWindow(hWnd);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ダイアログ ボックスを表示する\r
+UINT Dialog(HWND hWnd, UINT id, WINUI_DIALOG_PROC *proc, void *param)\r
+{\r
+       bool white = true;\r
+\r
+       return DialogEx(hWnd, id, proc, param, white);\r
+}\r
+UINT DialogEx(HWND hWnd, UINT id, WINUI_DIALOG_PROC *proc, void *param, bool white)\r
+{\r
+       return DialogEx2(hWnd, id, proc, param, white, false);\r
+}\r
+UINT DialogEx2(HWND hWnd, UINT id, WINUI_DIALOG_PROC *proc, void *param, bool white, bool meiryo)\r
+{\r
+       UINT ret;\r
+       DIALOG_PARAM p;\r
+       // 引数チェック\r
+       if (id == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.param = param;\r
+       p.white = white;\r
+       p.proc = proc;\r
+\r
+       if (MsIsVista())\r
+       {\r
+               p.meiryo = meiryo;\r
+       }\r
+\r
+       ret = DialogInternal(hWnd, id, InternalDialogProc, &p);\r
+\r
+       return ret;\r
+}\r
+\r
+// モードレスダイアログを作成する\r
+HWND DialogCreateEx(HWND hWnd, UINT id, WINUI_DIALOG_PROC *proc, void *param, bool white)\r
+{\r
+       HWND ret = NULL;\r
+       DIALOG_PARAM p;\r
+       // 引数チェック\r
+       if (id == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.param = param;\r
+       p.white = white;\r
+       p.proc = proc;\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               // Win9x\r
+               ret = CreateDialogParamA(hDll, MAKEINTRESOURCEA(id), hWnd,\r
+                       (DLGPROC)proc, (LPARAM)param);\r
+       }\r
+       else\r
+       {\r
+               // WinNT\r
+               ret = CreateDialogParamW(hDll, MAKEINTRESOURCEW(id), hWnd,\r
+                       (DLGPROC)proc, (LPARAM)param);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ビットマップをボタンに設定する\r
+void SetBitmap(HWND hWnd, UINT id, UINT bmp_id)\r
+{\r
+       HBITMAP bmp;\r
+       char *class_name;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       bmp = LoadImage(hDll, MAKEINTRESOURCE(bmp_id), IMAGE_BITMAP, 0, 0, (MsIsNt() ? LR_SHARED : 0) | LR_VGACOLOR);\r
+       if (bmp == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       class_name = GetClassA(hWnd, id);\r
+\r
+       if (StrCmpi(class_name, "Static") != 0)\r
+       {\r
+               SendMsg(hWnd, id, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp);\r
+       }\r
+       else\r
+       {\r
+               SendMsg(hWnd, id, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp);\r
+       }\r
+\r
+       Free(class_name);\r
+}\r
+\r
+// アイコンキャッシュの初期化\r
+void InitIconCache()\r
+{\r
+       if (icon_cache_list != NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       icon_cache_list = NewList(NULL);\r
+}\r
+\r
+// アイコンキャッシュの解放\r
+void FreeIconCache()\r
+{\r
+       UINT i;\r
+       if (icon_cache_list == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(icon_cache_list);i++)\r
+       {\r
+               ICON_CACHE *c = LIST_DATA(icon_cache_list, i);\r
+               DestroyIcon(c->hIcon);\r
+               Free(c);\r
+       }\r
+\r
+       ReleaseList(icon_cache_list);\r
+       icon_cache_list = NULL;\r
+}\r
+\r
+// アイコン取得\r
+HICON LoadIconEx(UINT id, bool small_icon)\r
+{\r
+       HICON h = NULL;\r
+       UINT i;\r
+       if (icon_cache_list == NULL)\r
+       {\r
+               return small_icon == false ? LoadLargeIconInner(id) : LoadSmallIconInner(id);\r
+       }\r
+\r
+       LockList(icon_cache_list);\r
+       {\r
+               for (i = 0;i < LIST_NUM(icon_cache_list);i++)\r
+               {\r
+                       ICON_CACHE *c = LIST_DATA(icon_cache_list, i);\r
+                       if (c->id == id && c->small_icon == small_icon)\r
+                       {\r
+                               h = c->hIcon;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               if (h == NULL)\r
+               {\r
+                       h = small_icon == false ? LoadLargeIconInner(id) : LoadSmallIconInner(id);\r
+                       if (h != NULL)\r
+                       {\r
+                               ICON_CACHE *c = ZeroMalloc(sizeof(ICON_CACHE));\r
+                               c->hIcon = h;\r
+                               c->id = id;\r
+                               c->small_icon = small_icon;\r
+                               Add(icon_cache_list, c);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(icon_cache_list);\r
+\r
+       return h;\r
+}\r
+\r
+// 大きいアイコン取得\r
+HICON LoadLargeIcon(UINT id)\r
+{\r
+       return LoadIconEx(id, false);\r
+}\r
+\r
+// 小さいアイコン取得\r
+HICON LoadSmallIcon(UINT id)\r
+{\r
+       return LoadIconEx(id, true);\r
+}\r
+\r
+// 大きいアイコンを取得する\r
+HICON LoadLargeIconInner(UINT id)\r
+{\r
+       HICON ret;\r
+       ret = LoadImage(hDll, MAKEINTRESOURCE(id), IMAGE_ICON, 32, 32, 0);\r
+       if (ret == NULL)\r
+       {\r
+               ret = LoadImage(hDll, MAKEINTRESOURCE(id), IMAGE_ICON, 32, 32, LR_VGACOLOR);\r
+               if (ret == NULL)\r
+               {\r
+                       ret = LoadImage(hDll, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, 0);\r
+                       if (ret == NULL)\r
+                       {\r
+                               ret = LoadImage(hDll, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_VGACOLOR);\r
+                               if (ret == NULL)\r
+                               {\r
+                                       ret = LoadIcon(hDll, MAKEINTRESOURCE(id));\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       return ret;\r
+}\r
+\r
+// 小さいアイコンを取得する\r
+HICON LoadSmallIconInner(UINT id)\r
+{\r
+       HICON ret;\r
+       ret = LoadImage(hDll, MAKEINTRESOURCE(id), IMAGE_ICON, 16, 16, 0);\r
+       if (ret == NULL)\r
+       {\r
+               ret = LoadImage(hDll, MAKEINTRESOURCE(id), IMAGE_ICON, 16, 16, LR_VGACOLOR);\r
+               if (ret == NULL)\r
+               {\r
+                       ret = LoadImage(hDll, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, 0);\r
+                       if (ret == NULL)\r
+                       {\r
+                               ret = LoadImage(hDll, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_VGACOLOR);\r
+                               if (ret == NULL)\r
+                               {\r
+                                       ret = LoadLargeIconInner(id);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       return ret;\r
+}\r
+\r
+// アイコンをウインドウまたはボタンに設定する\r
+void SetIcon(HWND hWnd, UINT id, UINT icon_id)\r
+{\r
+       HICON icon1, icon2;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       icon1 = LoadLargeIcon(icon_id);\r
+       if (icon1 == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (id == 0)\r
+       {\r
+               SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)icon1);\r
+               icon2 = LoadSmallIcon(icon_id);\r
+               if (icon2 == NULL)\r
+               {\r
+                       icon2 = icon1;\r
+               }\r
+               SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)icon2);\r
+       }\r
+       else\r
+       {\r
+               bool is_btn = true;\r
+               wchar_t *s = GetClass(hWnd, id);\r
+               if (s != NULL)\r
+               {\r
+                       if (UniStrCmpi(s, L"Static") == 0)\r
+                       {\r
+                               is_btn = false;\r
+                       }\r
+                       Free(s);\r
+               }\r
+\r
+               if (is_btn)\r
+               {\r
+                       SendMsg(hWnd, id, BM_SETIMAGE, IMAGE_ICON, (LPARAM)icon1);\r
+               }\r
+               else\r
+               {\r
+                       SendMsg(hWnd, id, STM_SETICON, (WPARAM)icon1, 0);\r
+               }\r
+       }\r
+}\r
+\r
+// ラジオボタンがチェックされているか確認する\r
+bool IsChecked(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return IsDlgButtonChecked(hWnd, id) == BST_CHECKED ? true : false;\r
+}\r
+\r
+// ラジオボタンをチェック\r
+void Check(HWND hWnd, UINT id, bool b)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if ((!(!IsChecked(hWnd, id))) != (!(!b)))\r
+       {\r
+               CheckDlgButton(hWnd, id, b ? BST_CHECKED : BST_UNCHECKED);\r
+       }\r
+}\r
+\r
+// テキストボックスの文字サイズが指定されたサイズ以下であることを確認する\r
+bool CheckTextSize(HWND hWnd, UINT id, UINT size, bool unicode)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GetTextSize(hWnd, id, unicode) <= size)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// テキストボックスに入っている文字列数が指定された文字列数以下であることを確認する\r
+bool CheckTextLen(HWND hWnd, UINT id, UINT len, bool unicode)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GetTextLen(hWnd, id, unicode) <= len)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// テキストボックスに入力できる文字数を制限する\r
+void LimitText(HWND hWnd, UINT id, UINT count)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMsg(hWnd, id, EM_LIMITTEXT, count, 0);\r
+}\r
+\r
+// フォントの設定\r
+void SetFont(HWND hWnd, UINT id, HFONT hFont)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || hFont == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMessage(DlgItem(hWnd, id), WM_SETFONT, (WPARAM)hFont, true);\r
+}\r
+\r
+// フォントサイズの取得\r
+bool GetFontSize(HFONT hFont, UINT *x, UINT *y)\r
+{\r
+       bool ret = false;\r
+       UINT xx = 0;\r
+       UINT yy = 0;\r
+\r
+       // フォントハンドルを検索\r
+       LockList(font_list);\r
+       {\r
+               UINT i;\r
+\r
+               for (i = 0;i < LIST_NUM(font_list);i++)\r
+               {\r
+                       FONT *f = LIST_DATA(font_list, i);\r
+\r
+                       if (f->hFont == hFont)\r
+                       {\r
+                               xx = f->x;\r
+                               yy = f->y;\r
+\r
+                               ret = true;\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(font_list);\r
+\r
+       if (ret == false)\r
+       {\r
+               ret = CalcFontSize(hFont, &xx, &yy);\r
+       }\r
+\r
+       if (xx == 0 || yy == 0)\r
+       {\r
+               xx = 8;\r
+               yy = 16;\r
+       }\r
+\r
+       if (x != NULL)\r
+       {\r
+               *x = xx;\r
+       }\r
+\r
+       if (y != NULL)\r
+       {\r
+               *y = yy;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// フォントサイズの計算\r
+bool CalcFontSize(HFONT hFont, UINT *x, UINT *y)\r
+{\r
+       UINT xx = 0, yy = 0;\r
+       TEXTMETRIC tm;\r
+       SIZE sz;\r
+       bool ret = false;\r
+       HDC hDC;\r
+\r
+       hDC = CreateCompatibleDC(NULL);\r
+\r
+       SelectObject(hDC, hFont);\r
+\r
+       Zero(&tm, sizeof(tm));\r
+       Zero(&sz, sizeof(sz));\r
+\r
+       if (GetTextMetrics(hDC, &tm))\r
+       {\r
+               xx = tm.tmAveCharWidth;\r
+               yy = tm.tmHeight;\r
+\r
+               ret = true;\r
+\r
+               if (GetTextExtentPoint32(hDC,\r
+                       "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",\r
+                       52, &sz))\r
+               {\r
+                       xx = (sz.cx / 26 + 1) / 2;\r
+               }\r
+       }\r
+\r
+       if (x != NULL)\r
+       {\r
+               *x = xx;\r
+       }\r
+\r
+       if (y != NULL)\r
+       {\r
+               *y = yy;\r
+       }\r
+\r
+       DeleteDC(hDC);\r
+\r
+       return ret;\r
+}\r
+\r
+// フォントの取得\r
+HFONT GetFont(char *name, UINT size, bool bold, bool italic, bool underline, bool strikeout)\r
+{\r
+       HFONT hFont;\r
+       HDC hDC;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               name = font_name;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               size = font_size;\r
+               if (size == 0)\r
+               {\r
+                       size = 9;\r
+               }\r
+       }\r
+\r
+       // 既存のフォントを探す\r
+       LockList(font_list);\r
+       {\r
+               FONT *f, t;\r
+               DWORD font_quality = ANTIALIASED_QUALITY;\r
+               OS_INFO *os = GetOsInfo();\r
+               UINT x = 0;\r
+               UINT y = 0;\r
+               int rotate = 0;\r
+\r
+               Zero(&t, sizeof(t));\r
+               t.Bold = bold;\r
+               t.Italic = italic;\r
+               t.Size = size;\r
+               t.StrikeOut = strikeout;\r
+               t.UnderLine = underline;\r
+               t.Name = CopyStr(name);\r
+               f = Search(font_list, &t);\r
+               Free(t.Name);\r
+\r
+               if (f != NULL)\r
+               {\r
+                       // フォントを発見した\r
+                       UnlockList(font_list);\r
+                       return f->hFont;\r
+               }\r
+\r
+               // 新しいフォントを作成する\r
+               hDC = CreateCompatibleDC(NULL);\r
+\r
+               // Windows XP 以降では ClearType を指定する\r
+               if (OS_IS_WINDOWS_NT(os->OsType) && GET_KETA(os->OsType, 100) >= 3)\r
+               {\r
+                       font_quality = CLEARTYPE_NATURAL_QUALITY;\r
+                       rotate = 3600;\r
+               }\r
+\r
+               // フォント作成\r
+               hFont = CreateFontA(-MulDiv(size, GetDeviceCaps(hDC, LOGPIXELSY), 72),\r
+                       0, rotate, rotate, (bold == false ? 500 : FW_BOLD),\r
+                       italic, underline, strikeout, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,\r
+                       CLIP_DEFAULT_PRECIS, font_quality, DEFAULT_PITCH, name);\r
+\r
+               if (hFont == NULL)\r
+               {\r
+                       // 失敗\r
+                       DeleteDC(hDC);\r
+                       UnlockList(font_list);\r
+\r
+                       return NULL;\r
+               }\r
+\r
+               CalcFontSize(hFont, &x, &y);\r
+\r
+               // テーブルに追加\r
+               f = ZeroMalloc(sizeof(FONT));\r
+               f->Bold = bold;\r
+               f->hFont = hFont;\r
+               f->Italic = italic;\r
+               f->Name = CopyStr(name);\r
+               f->Size = size;\r
+               f->StrikeOut = strikeout;\r
+               f->UnderLine = underline;\r
+               f->x = x;\r
+               f->y = y;\r
+\r
+               Insert(font_list, f);\r
+\r
+               DeleteDC(hDC);\r
+       }\r
+       UnlockList(font_list);\r
+\r
+       return hFont;\r
+}\r
+\r
+// フォントの比較\r
+int CompareFont(void *p1, void *p2)\r
+{\r
+       FONT *f1, *f2;\r
+       UINT r;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       f1 = *(FONT **)p1;\r
+       f2 = *(FONT **)p2;\r
+       if (f1 == NULL || f2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       r = StrCmpi(f1->Name, f2->Name);\r
+       if (r != 0)\r
+       {\r
+               return r;\r
+       }\r
+       else\r
+       {\r
+               if (f1->Bold > f2->Bold)\r
+               {\r
+                       return 1;\r
+               }\r
+               else if (f1->Bold < f2->Bold)\r
+               {\r
+                       return -1;\r
+               }\r
+               else if (f1->Italic > f2->Italic)\r
+               {\r
+                       return 1;\r
+               }\r
+               else if (f1->Italic < f2->Italic)\r
+               {\r
+                       return -1;\r
+               }\r
+               else if (f1->Size > f2->Size)\r
+               {\r
+                       return 1;\r
+               }\r
+               else if (f1->Size < f2->Size)\r
+               {\r
+                       return -1;\r
+               }\r
+               else if (f1->StrikeOut > f2->StrikeOut)\r
+               {\r
+                       return 1;\r
+               }\r
+               else if (f1->StrikeOut < f2->StrikeOut)\r
+               {\r
+                       return -1;\r
+               }\r
+               else if (f1->UnderLine > f2->UnderLine)\r
+               {\r
+                       return 1;\r
+               }\r
+               else if (f1->UnderLine < f2->UnderLine)\r
+               {\r
+                       return -1;\r
+               }\r
+               else\r
+               {\r
+                       return 0;\r
+               }\r
+       }\r
+}\r
+\r
+// フォントの初期化\r
+void InitFont()\r
+{\r
+       if (font_list != NULL)\r
+       {\r
+               return;\r
+       }\r
+       font_list = NewList(CompareFont);\r
+}\r
+\r
+// フォントの解放\r
+void FreeFont()\r
+{\r
+       UINT i;\r
+       if (font_list == NULL)\r
+       {\r
+               return;\r
+       }\r
+       for (i = 0;i < LIST_NUM(font_list);i++)\r
+       {\r
+               FONT *f = LIST_DATA(font_list, i);\r
+               Free(f->Name);\r
+               DeleteObject((HGDIOBJ)f->hFont);\r
+               Free(f);\r
+       }\r
+       ReleaseList(font_list);\r
+       font_list = NULL;\r
+}\r
+\r
+// ウインドウを閉じるボタンを出す\r
+void EnableClose(HWND hWnd)\r
+{\r
+       HMENU h;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       h = GetSystemMenu(hWnd, false);\r
+       EnableMenuItem(h, SC_CLOSE, MF_ENABLED);\r
+       DrawMenuBar(hWnd);\r
+}\r
+\r
+// ウインドウを閉じるボタンを消す\r
+void DisableClose(HWND hWnd)\r
+{\r
+       HMENU h;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       h = GetSystemMenu(hWnd, false);\r
+       EnableMenuItem(h, SC_CLOSE, MF_GRAYED);\r
+       DrawMenuBar(hWnd);\r
+}\r
+\r
+// 親ウインドウの中央に移動する\r
+void CenterParent(HWND hWnd)\r
+{\r
+       RECT rp;\r
+       RECT r;\r
+       HWND hWndParent = GetParent(hWnd);\r
+       int win_x, win_y;\r
+       int x, y;\r
+\r
+       if (hWndParent == NULL || IsHide(hWndParent, 0) || IsIconic(hWndParent))\r
+       {\r
+               Center(hWnd);\r
+               return;\r
+       }\r
+\r
+       if (GetWindowRect(hWndParent, &rp) == false)\r
+       {\r
+               Center(hWnd);\r
+               return;\r
+       }\r
+\r
+       GetWindowRect(hWnd, &r);\r
+\r
+       win_x = r.right - r.left;\r
+       win_y = r.bottom - r.top;\r
+\r
+       x = (rp.right - rp.left - win_x) / 2 + rp.left;\r
+       y = (rp.bottom - rp.top - win_y) / 2 + rp.top;\r
+\r
+       x = MAX(x, 0);\r
+       y = MAX(y, 0);\r
+\r
+       SetWindowPos(hWnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);\r
+}\r
+\r
+// ウインドウを中央に移動する\r
+void Center(HWND hWnd)\r
+{\r
+       RECT screen;\r
+       RECT win;\r
+       UINT x, y;\r
+       UINT win_x, win_y;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (SystemParametersInfo(SPI_GETWORKAREA, 0, &screen, 0) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetWindowRect(hWnd, &win);\r
+       win_x = win.right - win.left;\r
+       win_y = win.bottom - win.top;\r
+\r
+       if (win_x < (UINT)(screen.right - screen.left))\r
+       {\r
+               x = (screen.right - screen.left - win_x) / 2;\r
+       }\r
+       else\r
+       {\r
+               x = 0;\r
+       }\r
+\r
+       if (win_y < (UINT)(screen.bottom - screen.top))\r
+       {\r
+               y = (screen.bottom - screen.top - win_y) / 2;\r
+       }\r
+       else\r
+       {\r
+               y = 0;\r
+       }\r
+\r
+       SetWindowPos(hWnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);\r
+}\r
+\r
+// ウインドウを中央に移動する 2\r
+void Center2(HWND hWnd)\r
+{\r
+       RECT screen;\r
+       RECT win;\r
+       UINT x, y;\r
+       UINT win_x, win_y;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (SystemParametersInfo(SPI_GETWORKAREA, 0, &screen, 0) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetWindowRect(hWnd, &win);\r
+       win_x = win.right - win.left;\r
+       win_y = win.bottom - win.top;\r
+\r
+       if (win_x < (UINT)(screen.right - screen.left))\r
+       {\r
+               x = (screen.right - screen.left - win_x) / 2;\r
+       }\r
+       else\r
+       {\r
+               x = 0;\r
+       }\r
+\r
+       if (win_y < (UINT)(screen.bottom - screen.top))\r
+       {\r
+               y = (screen.bottom - screen.top - win_y) / 4;\r
+       }\r
+       else\r
+       {\r
+               y = 0;\r
+       }\r
+\r
+       SetWindowPos(hWnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);\r
+}\r
+\r
+// モニタのサイズを取得する\r
+void GetMonitorSize(UINT *width, UINT *height)\r
+{\r
+       // 引数チェック\r
+       if (width == NULL || height == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       *width = GetSystemMetrics(SM_CXSCREEN);\r
+       *height = GetSystemMetrics(SM_CYSCREEN);\r
+}\r
+\r
+// ウインドウ内の文字列をフォーマットする\r
+void FormatText(HWND hWnd, UINT id, ...)\r
+{\r
+       va_list args;\r
+       wchar_t *buf;\r
+       UINT size;\r
+       wchar_t *str;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       str = GetText(hWnd, id);\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       size = MAX(UniStrSize(str) * 10, MAX_SIZE * 10);\r
+       buf = MallocEx(size, true);\r
+\r
+       va_start(args, id);\r
+       UniFormatArgs(buf, size, str, args);\r
+\r
+       SetText(hWnd, id, buf);\r
+\r
+       Free(buf);\r
+\r
+       Free(str);\r
+       va_end(args);\r
+}\r
+void FormatTextA(HWND hWnd, UINT id, ...)\r
+{\r
+       va_list args;\r
+       char *buf;\r
+       UINT size;\r
+       char *str;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       str = GetTextA(hWnd, id);\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       size = MAX(StrSize(str) * 10, MAX_SIZE * 10);\r
+       buf = MallocEx(size, true);\r
+\r
+       va_start(args, id);\r
+       FormatArgs(buf, size, str, args);\r
+\r
+       SetTextA(hWnd, id, buf);\r
+\r
+       Free(buf);\r
+\r
+       Free(str);\r
+       va_end(args);\r
+}\r
+\r
+// 可変長引数の文字列をウインドウに設定\r
+void SetTextEx(HWND hWnd, UINT id, wchar_t *str, ...)\r
+{\r
+       va_list args;\r
+       wchar_t *buf;\r
+       UINT size;\r
+       // 引数チェック\r
+       if (str == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       size = MAX(UniStrSize(str) * 10, MAX_SIZE * 10);\r
+       buf = MallocEx(size, true);\r
+\r
+       va_start(args, str);\r
+       UniFormatArgs(buf, size, str, args);\r
+\r
+       SetText(hWnd, id, buf);\r
+\r
+       Free(buf);\r
+       va_end(args);\r
+}\r
+void SetTextExA(HWND hWnd, UINT id, char *str, ...)\r
+{\r
+       va_list args;\r
+       char *buf;\r
+       UINT size;\r
+       // 引数チェック\r
+       if (str == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       size = MAX(StrSize(str) * 10, MAX_SIZE * 10);\r
+       buf = MallocEx(size, true);\r
+\r
+       va_start(args, str);\r
+       FormatArgs(buf, size, str, args);\r
+\r
+       SetTextA(hWnd, id, buf);\r
+\r
+       Free(buf);\r
+       va_end(args);\r
+}\r
+\r
+// 可変長メッセージボックスの表示\r
+UINT MsgBoxEx(HWND hWnd, UINT flag, wchar_t *msg, ...)\r
+{\r
+       va_list args;\r
+       wchar_t *buf;\r
+       UINT size;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (msg == NULL)\r
+       {\r
+               msg = L"MessageBox";\r
+       }\r
+\r
+       size = MAX(UniStrSize(msg) * 10, MAX_SIZE * 10);\r
+       buf = MallocEx(size, true);\r
+\r
+       va_start(args, msg);\r
+       UniFormatArgs(buf, size, msg, args);\r
+\r
+       ret = MsgBox(hWnd, flag, buf);\r
+       Free(buf);\r
+       va_end(args);\r
+\r
+       return ret;\r
+}\r
+\r
+// メッセージボックスの表示\r
+UINT MsgBox(HWND hWnd, UINT flag, wchar_t *msg)\r
+{\r
+       UINT ret;\r
+       wchar_t *title;\r
+       // 引数チェック\r
+       if (msg == NULL)\r
+       {\r
+               msg = L"MessageBox";\r
+       }\r
+\r
+       if (title_bar != NULL)\r
+       {\r
+               title = CopyUniStr(title_bar);\r
+       }\r
+       else\r
+       {\r
+               title = CopyStrToUni(CEDAR_PRODUCT_STR);\r
+       }\r
+\r
+       if (hWnd)\r
+       {\r
+               // 親ウインドウが最上位ウインドウの場合はメッセージボックスも最上位にする\r
+               if (GetExStyle(hWnd, 0) & WS_EX_TOPMOST)\r
+               {\r
+                       flag |= MB_SYSTEMMODAL;\r
+               }\r
+       }\r
+\r
+       ret = MessageBoxW(hWnd, msg, title, flag);\r
+\r
+       Free(title);\r
+\r
+       return ret;\r
+}\r
+\r
+// ダイアログの作成 (内部)\r
+UINT DialogInternal(HWND hWnd, UINT id, DIALOG_PROC *proc, void *param)\r
+{\r
+       // 引数チェック\r
+       if (proc == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               // Win9x\r
+               return (UINT)DialogBoxParam(hDll, MAKEINTRESOURCE(id), hWnd, (DLGPROC)proc, (LPARAM)param);\r
+       }\r
+       else\r
+       {\r
+               // WinNT\r
+               return (UINT)DialogBoxParamW(hDll, MAKEINTRESOURCEW(id), hWnd, (DLGPROC)proc, (LPARAM)param);\r
+       }\r
+}\r
+\r
+// システム設定が更新されたことを通知する\r
+void NoticeSettingChange()\r
+{\r
+       PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);\r
+       DoEvents(NULL);\r
+}\r
+\r
+// ウインドウを半透明にする\r
+void SetAplha(HWND hWnd, UINT value0_255)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       value0_255 = MAKESURE(value0_255, 0, 255);\r
+\r
+       if (true)\r
+       {\r
+               UINT os_type = GetOsInfo()->OsType;\r
+               if (OS_IS_WINDOWS_NT(os_type) && GET_KETA(os_type, 100) >= 2)\r
+               {\r
+                       bool (WINAPI *_SetLayeredWindowAttributes)(HWND, COLORREF, BYTE, DWORD);\r
+                       HINSTANCE hInst;\r
+\r
+                       hInst = LoadLibrary("user32.dll");\r
+\r
+                       _SetLayeredWindowAttributes =\r
+                               (bool (__stdcall *)(HWND,COLORREF,BYTE,DWORD))\r
+                               GetProcAddress(hInst, "SetLayeredWindowAttributes");\r
+\r
+                       if (_SetLayeredWindowAttributes != NULL)\r
+                       {\r
+                               // Windows 2000 以降でのみ対応\r
+                               SetExStyle(hWnd, 0, WS_EX_LAYERED);\r
+                               _SetLayeredWindowAttributes(hWnd, 0, value0_255, LWA_ALPHA);\r
+                       }\r
+\r
+                       FreeLibrary(hInst);\r
+               }\r
+       }\r
+}\r
+\r
+// WinUi が管理するダイアログボックスプロシージャ\r
+UINT DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, bool white_color)\r
+{\r
+       void *param;\r
+       HWND hWndParent;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_INITDIALOG:\r
+               param = (void *)lParam;\r
+               SetParam(hWnd, param);\r
+\r
+               // 親ウインドウが存在するかどうか調べる\r
+               hWndParent = GetParent(hWnd);\r
+               if (hWndParent == NULL || IsShow(hWndParent, 0) == false)\r
+               {\r
+                       // 存在しない場合は中央に配置する\r
+                       Center(hWnd);\r
+               }\r
+\r
+               if (UseAlpha)\r
+               {\r
+                       SetAplha(hWnd, AlphaValue * 255 / 100);\r
+               }\r
+\r
+               break;\r
+       }\r
+\r
+       if (white_color)\r
+       {\r
+               if (IsNewStyleModeEnabled() == false)\r
+               {\r
+                       switch (msg)\r
+                       {\r
+                       case WM_CTLCOLORBTN:\r
+                       case WM_CTLCOLORDLG:\r
+                       case WM_CTLCOLOREDIT:\r
+                       case WM_CTLCOLORLISTBOX:\r
+                       case WM_CTLCOLORMSGBOX:\r
+                       case WM_CTLCOLORSCROLLBAR:\r
+                       case WM_CTLCOLORSTATIC:\r
+                               return (UINT)GetStockObject(WHITE_BRUSH);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       switch (msg)\r
+                       {\r
+                       case WM_CTLCOLORDLG:\r
+                               // ダイアログの背景色\r
+                               return (UINT)gdi_cache.BackgroundColorBrush;\r
+\r
+                       case WM_CTLCOLORBTN:\r
+                               // ボタンの背景色\r
+                               SetTextColor((HDC)wParam, gdi_cache.ForegroundColor);\r
+                               SetBkColor((HDC)wParam, gdi_cache.BackgroundColor);\r
+                               return (UINT)gdi_cache.BackgroundColorBrush;\r
+\r
+                       case WM_CTLCOLORSTATIC:\r
+                               // ラベルの色\r
+                               SetTextColor((HDC)wParam, gdi_cache.ForegroundColor);\r
+                               SetBkColor((HDC)wParam, gdi_cache.BackgroundColor);\r
+                               return (UINT)gdi_cache.BackgroundColorBrush;\r
+\r
+                       case WM_CTLCOLOREDIT:\r
+                               // エディットコントロールの色\r
+                               return (UINT)gdi_cache.TextBoxBackgroundColorBrush;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ダイアログボックスのパラメータの設定\r
+void SetParam(HWND hWnd, void *param)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)param);\r
+}\r
+\r
+// ダイアログボックスのパラメータの取得\r
+void *GetParam(HWND hWnd)\r
+{\r
+       void *ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = (void *)GetWindowLongPtr(hWnd, DWLP_USER);\r
+       return ret;\r
+}\r
+\r
+// ウインドウを最前面でなくする\r
+void NoTop(HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);\r
+}\r
+\r
+// ウインドウを最前面に表示する\r
+void Top(HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);\r
+}\r
+\r
+// ウインドウを隠す\r
+void Hide(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsShow(hWnd, id))\r
+       {\r
+               ShowWindow(DlgItem(hWnd, id), SW_HIDE);\r
+       }\r
+}\r
+\r
+// ウインドウを表示する\r
+void Show(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsHide(hWnd, id))\r
+       {\r
+               ShowWindow(DlgItem(hWnd, id), SW_SHOW);\r
+       }\r
+}\r
+\r
+// 表示設定の変更\r
+void SetShow(HWND hWnd, UINT id, bool b)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (b)\r
+       {\r
+               Show(hWnd, id);\r
+       }\r
+       else\r
+       {\r
+               Hide(hWnd, id);\r
+       }\r
+}\r
+\r
+// ウインドウが表示されているかどうか取得する\r
+bool IsShow(HWND hWnd, UINT id)\r
+{\r
+       return IsHide(hWnd, id) ? false : true;\r
+}\r
+\r
+// ウインドウが隠れているかどうか取得する\r
+bool IsHide(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (GetStyle(hWnd, id) & WS_VISIBLE)\r
+       {\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               return true;\r
+       }\r
+}\r
+\r
+// ウインドウスタイルを削除する\r
+void RemoveExStyle(HWND hWnd, UINT id, UINT style)\r
+{\r
+       UINT old;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       old = GetExStyle(hWnd, id);\r
+       if ((old & style) == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetWindowLong(DlgItem(hWnd, id), GWL_EXSTYLE, old & ~style);\r
+       Refresh(DlgItem(hWnd, id));\r
+}\r
+\r
+// ウインドウスタイルを設定する\r
+void SetExStyle(HWND hWnd, UINT id, UINT style)\r
+{\r
+       UINT old;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       old = GetExStyle(hWnd, id);\r
+       if (old & style)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetWindowLong(DlgItem(hWnd, id), GWL_EXSTYLE, old | style);\r
+       Refresh(DlgItem(hWnd, id));\r
+}\r
+\r
+// ウインドウスタイルを取得する\r
+UINT GetExStyle(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return GetWindowLong(DlgItem(hWnd, id), GWL_EXSTYLE);\r
+}\r
+\r
+// ウインドウスタイルを削除する\r
+void RemoveStyle(HWND hWnd, UINT id, UINT style)\r
+{\r
+       UINT old;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       old = GetStyle(hWnd, id);\r
+       if ((old & style) == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetWindowLong(DlgItem(hWnd, id), GWL_STYLE, old & ~style);\r
+       Refresh(DlgItem(hWnd, id));\r
+}\r
+\r
+// ウインドウスタイルを設定する\r
+void SetStyle(HWND hWnd, UINT id, UINT style)\r
+{\r
+       UINT old;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       old = GetStyle(hWnd, id);\r
+       if (old & style)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetWindowLong(DlgItem(hWnd, id), GWL_STYLE, old | style);\r
+       Refresh(DlgItem(hWnd, id));\r
+}\r
+\r
+// ウインドウスタイルを取得する\r
+UINT GetStyle(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return GetWindowLong(DlgItem(hWnd, id), GWL_STYLE);\r
+}\r
+\r
+// テキストのバイト数を取得する\r
+UINT GetTextSize(HWND hWnd, UINT id, bool unicode)\r
+{\r
+       UINT len;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       len = GetTextLen(hWnd, id, unicode);\r
+\r
+       return len + (unicode ? 2 : 1);\r
+}\r
+\r
+// テキストの文字数を取得する\r
+UINT GetTextLen(HWND hWnd, UINT id, bool unicode)\r
+{\r
+       wchar_t *s;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       s = GetText(hWnd, id);\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (unicode)\r
+       {\r
+               ret = UniStrLen(s);\r
+       }\r
+       else\r
+       {\r
+               char *tmp = CopyUniToStr(s);\r
+               ret = StrLen(tmp);\r
+               Free(tmp);\r
+       }\r
+\r
+       Free(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// テキストが空白かどうかチェックする\r
+bool IsEmpty(HWND hWnd, UINT id)\r
+{\r
+       bool ret;\r
+       wchar_t *s;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       s = GetText(hWnd, id);\r
+\r
+       UniTrim(s);\r
+       if (UniStrLen(s) == 0)\r
+       {\r
+               ret = true;\r
+       }\r
+       else\r
+       {\r
+               ret = false;\r
+       }\r
+\r
+       Free(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// ウインドウクラスを取得する\r
+wchar_t *GetClass(HWND hWnd, UINT id)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               wchar_t *ret;\r
+               char *s;\r
+               s = GetClassA(hWnd, id);\r
+               ret = CopyStrToUni(s);\r
+               Free(s);\r
+               return ret;\r
+       }\r
+\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return CopyUniStr(L"");\r
+       }\r
+\r
+       GetClassNameW(DlgItem(hWnd, id), tmp, sizeof(tmp));\r
+\r
+       return UniCopyStr(tmp);\r
+}\r
+char *GetClassA(HWND hWnd, UINT id)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return CopyStr("");\r
+       }\r
+\r
+       GetClassName(DlgItem(hWnd, id), tmp, sizeof(tmp));\r
+\r
+       return CopyStr(tmp);\r
+}\r
+\r
+// コントロールにメッセージを送信する\r
+UINT SendMsg(HWND hWnd, UINT id, UINT msg, WPARAM wParam, LPARAM lParam)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (MsIsNt())\r
+       {\r
+               return (UINT)SendMessageW(DlgItem(hWnd, id), msg, wParam, lParam);\r
+       }\r
+       else\r
+       {\r
+               return (UINT)SendMessageA(DlgItem(hWnd, id), msg, wParam, lParam);\r
+       }\r
+}\r
+\r
+// EDIT のテキストをすべて選択する\r
+void SelectEdit(HWND hWnd, UINT id)\r
+{\r
+       wchar_t *class_name;\r
+\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       class_name = GetClass(hWnd, id);\r
+\r
+       if (class_name != NULL)\r
+       {\r
+               if (UniStrCmpi(class_name, L"edit") == 0)\r
+               {\r
+                       SendMsg(hWnd, id, EM_SETSEL, 0, -1);\r
+               }\r
+               Free(class_name);\r
+       }\r
+}\r
+\r
+// EDIT のテキストの選択を解除する\r
+void UnselectEdit(HWND hWnd, UINT id)\r
+{\r
+       wchar_t *class_name;\r
+\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       class_name = GetClass(hWnd, id);\r
+\r
+       if (class_name != NULL)\r
+       {\r
+               if (UniStrCmpi(class_name, L"edit") == 0)\r
+               {\r
+                       SendMsg(hWnd, id, EM_SETSEL, -1, 0);\r
+               }\r
+               Free(class_name);\r
+       }\r
+}\r
+\r
+// EDIT にフォーカスを設定してすべて選択する\r
+void FocusEx(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsEnable(hWnd, id) == false || IsShow(hWnd, id) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SelectEdit(hWnd, id);\r
+\r
+       Focus(hWnd, id);\r
+}\r
+\r
+// 指定したウインドウがフォーカスを持っているかどうか取得する\r
+bool IsFocus(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GetFocus() == DlgItem(hWnd, id))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// フォーカスを設定する\r
+void Focus(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsEnable(hWnd, id) == false || IsShow(hWnd, id) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetFocus(DlgItem(hWnd, id));\r
+}\r
+\r
+// int 型の値を設定する\r
+void SetInt(HWND hWnd, UINT id, UINT value)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniToStru(tmp, value);\r
+       SetText(hWnd, id, tmp);\r
+}\r
+void SetIntEx(HWND hWnd, UINT id, UINT value)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (value == 0)\r
+       {\r
+               // 0 の場合は空欄にする\r
+               SetText(hWnd, id, L"");\r
+       }\r
+       else\r
+       {\r
+               SetInt(hWnd, id, value);\r
+       }\r
+}\r
+\r
+// int 型の値を取得する\r
+UINT GetInt(HWND hWnd, UINT id)\r
+{\r
+       wchar_t *s;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       s = GetText(hWnd, id);\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = UniToInt(s);\r
+       Free(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// ウインドウ表示を更新する\r
+void Refresh(HWND hWnd)\r
+{\r
+       HWND parent;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DoEvents(hWnd);\r
+       UpdateWindow(hWnd);\r
+       DoEvents(hWnd);\r
+\r
+       parent = GetParent(hWnd);\r
+       if (parent != NULL)\r
+       {\r
+               Refresh(parent);\r
+       }\r
+}\r
+\r
+// イベントを処理する\r
+void DoEvents(HWND hWnd)\r
+{\r
+       MSG msg;\r
+\r
+       if (PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE))\r
+       {\r
+               TranslateMessage(&msg);\r
+               DispatchMessage(&msg);\r
+       }\r
+       UpdateWindow(hWnd);\r
+\r
+       if (hWnd)\r
+       {\r
+               DoEvents(NULL);\r
+       }\r
+}\r
+\r
+// ウインドウを閉じる\r
+void Close(HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SendMessage(hWnd, WM_CLOSE, 0, 0);\r
+}\r
+\r
+// ウインドウを無効にする\r
+void Disable(HWND hWnd, UINT id)\r
+{\r
+       SetEnable(hWnd, id, false);\r
+}\r
+\r
+// ウインドウを有効にする\r
+void Enable(HWND hWnd, UINT id)\r
+{\r
+       SetEnable(hWnd, id, true);\r
+}\r
+\r
+// ウインドウの有効状態を設定する\r
+void SetEnable(HWND hWnd, UINT id, bool b)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (b == false)\r
+       {\r
+               if (IsEnable(hWnd, id))\r
+               {\r
+                       if (id != 0 && IsFocus(hWnd, id))\r
+                       {\r
+                               Focus(hWnd, IDCANCEL);\r
+                               Focus(hWnd, IDOK);\r
+                       }\r
+                       EnableWindow(DlgItem(hWnd, id), false);\r
+                       Refresh(DlgItem(hWnd, id));\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (IsDisable(hWnd, id))\r
+               {\r
+                       EnableWindow(DlgItem(hWnd, id), true);\r
+                       Refresh(DlgItem(hWnd, id));\r
+               }\r
+       }\r
+}\r
+\r
+// ウインドウが無効かどうか調べる\r
+bool IsDisable(HWND hWnd, UINT id)\r
+{\r
+       return IsEnable(hWnd, id) ? false : true;\r
+}\r
+\r
+// ウインドウが有効かどうか調べる\r
+bool IsEnable(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return IsWindowEnabled(DlgItem(hWnd, id));\r
+}\r
+\r
+static LOCK *winui_debug_lock = NULL;\r
+\r
+// デバッグの初期化\r
+void WinUiDebugInit()\r
+{\r
+       winui_debug_lock = NewLock();\r
+}\r
+\r
+// デバッグの解放\r
+void WinUiDebugFree()\r
+{\r
+       DeleteLock(winui_debug_lock);\r
+}\r
+\r
+// デバッグファイルに文字列を書き込む\r
+void WinUiDebug(wchar_t *str)\r
+{\r
+       wchar_t tmp[1024];\r
+       char dtstr[256];\r
+       char *buf;\r
+       wchar_t exename[MAX_PATH];\r
+       UINT tid;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tid = GetCurrentThreadId();\r
+\r
+       GetExeNameW(exename, sizeof(exename));\r
+       GetFileNameFromFilePathW(exename, sizeof(exename), exename);\r
+\r
+       GetDateTimeStrMilli64(dtstr, sizeof(dtstr), LocalTime64());\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"[%S] (%s:%u) %s\r\n", dtstr, exename, tid, str);\r
+\r
+       buf = CopyUniToUtf(tmp);\r
+\r
+       Lock(winui_debug_lock);\r
+       {\r
+               IO *o = FileOpenEx(WINUI_DEBUG_TEXT, true, true);\r
+               if (o == NULL)\r
+               {\r
+                       o = FileCreate(WINUI_DEBUG_TEXT);\r
+               }\r
+\r
+               if (o != NULL)\r
+               {\r
+                       UINT size = FileSize(o);\r
+\r
+                       FileSeek(o, FILE_BEGIN, size);\r
+\r
+                       FileWrite(o, buf, StrLen(buf));\r
+                       FileFlush(o);\r
+\r
+                       FileClose(o);\r
+               }\r
+       }\r
+       Unlock(winui_debug_lock);\r
+\r
+       Free(buf);\r
+}\r
+\r
+\r
+// テキスト文字列の設定\r
+void SetText(HWND hWnd, UINT id, wchar_t *str)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetTextInner(hWnd, id, str);\r
+}\r
+void SetTextInner(HWND hWnd, UINT id, wchar_t *str)\r
+{\r
+       wchar_t *old;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 古い文字列を取得\r
+       old = GetText(hWnd, id);\r
+       if (UniStrCmp(str, old) == 0)\r
+       {\r
+               // 同一\r
+               Free(old);\r
+               return;\r
+       }\r
+\r
+       Free(old);\r
+\r
+       if (MsIsNt())\r
+       {\r
+               SetWindowTextW(DlgItem(hWnd, id), str);\r
+       }\r
+       else\r
+       {\r
+               char *tmp = CopyUniToStr(str);\r
+\r
+               if (MsIsNt() == false && StrLen(tmp) >= 32000)\r
+               {\r
+                       // 32k 以下にきりつめる\r
+                       tmp[32000] = 0;\r
+               }\r
+\r
+               SetWindowTextA(DlgItem(hWnd, id), tmp);\r
+               Free(tmp);\r
+       }\r
+\r
+       if (id != 0)\r
+       {\r
+               Refresh(DlgItem(hWnd, id));\r
+       }\r
+}\r
+void SetTextA(HWND hWnd, UINT id, char *str)\r
+{\r
+       wchar_t *s;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = CopyStrToUni(str);\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetText(hWnd, id, s);\r
+\r
+       Free(s);\r
+}\r
+\r
+// テキスト文字列をバッファへ取得\r
+bool GetTxt(HWND hWnd, UINT id, wchar_t *str, UINT size)\r
+{\r
+       wchar_t *s;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s = GetText(hWnd, id);\r
+       if (s == NULL)\r
+       {\r
+               UniStrCpy(str, size, L"");\r
+               return false;\r
+       }\r
+\r
+       UniStrCpy(str, size, s);\r
+       Free(s);\r
+\r
+       return true;\r
+}\r
+bool GetTxtA(HWND hWnd, UINT id, char *str, UINT size)\r
+{\r
+       char *s;\r
+       // 引数チェック\r
+       if (hWnd == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s = GetTextA(hWnd, id);\r
+       if (s == NULL)\r
+       {\r
+               StrCpy(str, size, "");\r
+               return false;\r
+       }\r
+\r
+       StrCpy(str, size, s);\r
+       Free(s);\r
+\r
+       return true;\r
+}\r
+\r
+// テキスト文字列の取得\r
+wchar_t *GetText(HWND hWnd, UINT id)\r
+{\r
+       wchar_t *ret;\r
+       UINT size, len;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = GetTextA(hWnd, id);\r
+               ret = CopyStrToUni(s);\r
+               Free(s);\r
+\r
+               return ret;\r
+       }\r
+\r
+       len = GetWindowTextLengthW(DlgItem(hWnd, id));\r
+       if (len == 0)\r
+       {\r
+               return CopyUniStr(L"");\r
+       }\r
+\r
+       size = (len + 1) * 2;\r
+       ret = ZeroMallocEx(size, true);\r
+\r
+       GetWindowTextW(DlgItem(hWnd, id), ret, size);\r
+\r
+       return ret;\r
+}\r
+char *GetTextA(HWND hWnd, UINT id)\r
+{\r
+       char *ret;\r
+       UINT size, len;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       len = GetWindowTextLengthA(DlgItem(hWnd, id));\r
+       if (len == 0)\r
+       {\r
+               return CopyStr("");\r
+       }\r
+\r
+       size = len + 1;\r
+       ret = ZeroMallocEx(size, true);\r
+\r
+       GetWindowTextA(DlgItem(hWnd, id), ret, size);\r
+\r
+       return ret;\r
+}\r
+\r
+// ダイアログ内のアイテムの取得\r
+HWND DlgItem(HWND hWnd, UINT id)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (id == 0)\r
+       {\r
+               return hWnd;\r
+       }\r
+       else\r
+       {\r
+               return GetDlgItem(hWnd, id);\r
+       }\r
+}\r
+\r
+// タイトルの設定\r
+void SetWinUiTitle(wchar_t *title)\r
+{\r
+       // 引数チェック\r
+       if (title == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(title_bar);\r
+       title_bar = CopyUniStr(title);\r
+}\r
+\r
+// WinUi の初期化\r
+void InitWinUi(wchar_t *software_name, char *font, UINT fontsize)\r
+{\r
+       if ((init_winui_counter++) != 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (hDll != NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       WinUiDebugInit();\r
+\r
+       if (MayaquaIsMinimalMode() == false)\r
+       {\r
+               if (Is64())\r
+               {\r
+                       hDll = MsLoadLibraryAsDataFile(MsGetPenCoreDllFileName());\r
+               }\r
+               else\r
+               {\r
+                       hDll = MsLoadLibrary(MsGetPenCoreDllFileName());\r
+               }\r
+\r
+               if (hDll == NULL)\r
+               {\r
+                       Alert(PENCORE_DLL_NAME " not found. SoftEther UT-VPN couldn't start.\r\n\r\n"\r
+                               "Please reinstall all files with SoftEther UT-VPN Installer.",\r
+                               NULL);\r
+                       exit(0);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               hDll = LoadLibrary(MsGetExeFileName());\r
+\r
+               if (hDll == NULL)\r
+               {\r
+                       Alert("MsLoadLibrary() Error.",\r
+                               NULL);\r
+                       exit(0);\r
+               }\r
+       }\r
+\r
+       if (software_name != NULL)\r
+       {\r
+               title_bar = CopyUniStr(software_name);\r
+       }\r
+       else\r
+       {\r
+               title_bar = CopyUniStr(L"SoftEther UT-VPN");\r
+       }\r
+\r
+       if (font != NULL)\r
+       {\r
+               font_name = CopyStr(font);\r
+       }\r
+       else\r
+       {\r
+               font_name = CopyStr(_SS("DEFAULT_FONT"));\r
+       }\r
+\r
+       if (fontsize != 0)\r
+       {\r
+               font_size = fontsize;\r
+       }\r
+       else\r
+       {\r
+               font_size = _II("DEFAULT_FONT_SIZE");\r
+               if (font_size == 0)\r
+               {\r
+                       font_size = 9;\r
+               }\r
+       }\r
+\r
+       InitIconCache();\r
+\r
+       InitFont();\r
+\r
+       InitImageList();\r
+\r
+       InitGdiCache();\r
+\r
+       EnableNewStyleMode();\r
+}\r
+\r
+// WinUi の解放\r
+void FreeWinUi()\r
+{\r
+       if ((--init_winui_counter) != 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (hDll == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeImageList();\r
+\r
+       FreeFont();\r
+\r
+       FreeIconCache();\r
+\r
+       FreeLibrary(hDll);\r
+       hDll = NULL;\r
+\r
+       Free(title_bar);\r
+       title_bar = NULL;\r
+\r
+       Free(font_name);\r
+       font_name = NULL;\r
+\r
+       WinUiDebugFree();\r
+}\r
+\r
+#endif // WIN32\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Cedar/WinUi.h b/utvpn/utvpn-unix-v101-7101-public/src/Cedar/WinUi.h
new file mode 100644 (file)
index 0000000..a3745db
--- /dev/null
@@ -0,0 +1,774 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// WinUi.h\r
+// Win32 用ユーザーインターフェースコード\r
+\r
+#ifdef OS_WIN32\r
+\r
+#define        WINUI_DEBUG_TEXT                                                        "@winui_debug.txt"\r
+\r
+#define        LV_INSERT_RESET_ALL_ITEM_MIN                            500\r
+\r
+#define WINUI_PASSWORD_NULL_USERNAME                           "NULL"\r
+\r
+#define WINUI_DEFAULT_DIALOG_UNIT_X                                    7\r
+#define WINUI_DEFAULT_DIALOG_UNIT_Y                                    12\r
+\r
+// Windows 用の型が windows.h をインクルードしていなくても使えるようにする\r
+#ifndef        _WINDEF_\r
+\r
+typedef void *HWND;\r
+typedef void *HFONT;\r
+typedef void *HICON;\r
+typedef void *HMENU;\r
+typedef UINT_PTR WPARAM;\r
+typedef LONG_PTR LPARAM;\r
+typedef void *HINSTANCE;\r
+\r
+#endif // _WINDEF_\r
+\r
+\r
+// 定数\r
+#define        FREE_REGKEY                             "Software\\SoftEther Corporation\\UT-VPN Client\\Free Edition Info"\r
+#define ONCE_MSG_REGKEY                        "Software\\SoftEther Corporation\\UT-VPN\\Common"\r
+#define ONCE_MSG_REGVALUE              "HideMessage_%u"\r
+\r
+#define        SPLASH_BMP_REGKEY               "Software\\SoftEther Corporation\\UT-VPN\\SplashScreen"\r
+#define        SPLASH_BMP_REGVALUE             "LastId"\r
+\r
+#define        NICINFO_AUTOCLOSE_TIME_1        (20 * 1000)\r
+#define        NICINFO_AUTOCLOSE_TIME_2        1800\r
+\r
+extern bool UseAlpha;\r
+extern UINT AlphaValue;\r
+\r
+\r
+// マクロ\r
+#define        DIALOG                  DIALOGEX(false)\r
+#define        DIALOG_WHITE    DIALOGEX(true)\r
+#define        DIALOGEX(white)                                                         \\r
+       void *param = GetParam(hWnd);                                   \\r
+       {                                                                                               \\r
+               UINT ret;                                                                       \\r
+               ret = DlgProc(hWnd, msg, wParam, lParam, white);        \\r
+               if (ret != 0) return ret;                                       \\r
+       }\r
+\r
+typedef UINT (__stdcall DIALOG_PROC)(HWND, UINT, WPARAM, LPARAM);\r
+\r
+typedef UINT (WINUI_DIALOG_PROC)(HWND, UINT, WPARAM, LPARAM, void *);\r
+\r
+\r
+// セキュア操作内容\r
+#define        WINUI_SECURE_ENUM_OBJECTS               1                       // オブジェクトの列挙\r
+#define        WINUI_SECURE_WRITE_DATA                 2                       // データの書き込み\r
+#define        WINUI_SECURE_READ_DATA                  3                       // データの読み込み\r
+#define        WINUI_SECURE_WRITE_CERT                 4                       // 証明書の書き込み\r
+#define        WINUI_SECURE_READ_CERT                  5                       // 証明書の読み込み\r
+#define        WINUI_SECURE_WRITE_KEY                  6                       // 秘密鍵の書き込み\r
+#define        WINUI_SECURE_SIGN_WITH_KEY              7                       // 秘密鍵による署名\r
+#define        WINUI_SECURE_DELETE_OBJECT              8                       // オブジェクトの削除\r
+#define        WINUI_SECURE_DELETE_CERT                9                       // 証明書の削除\r
+#define        WINUI_SECURE_DELETE_KEY                 10                      // 秘密鍵の削除\r
+#define        WINUI_SECURE_DELETE_DATA                11                      // データの削除\r
+\r
+// セキュア操作構造体\r
+typedef struct WINUI_SECURE_BATCH\r
+{\r
+       UINT Type;                                                                              // 動作の種類\r
+       char *Name;                                                                             // 名前\r
+       bool Private;                                                                   // プライベートモード\r
+       BUF *InputData;                                                                 // 入力データ\r
+       BUF *OutputData;                                                                // 出力データ\r
+       X *InputX;                                                                              // 入力証明書\r
+       X *OutputX;                                                                             // 出力証明書\r
+       K *InputK;                                                                              // 入力秘密鍵\r
+       LIST *EnumList;                                                                 // 列挙リスト\r
+       UCHAR OutputSign[128];                                                  // 出力署名\r
+       bool Succeed;                                                                   // 成功フラグ\r
+} WINUI_SECURE_BATCH;\r
+\r
+// ステータスウインドウ\r
+typedef struct STATUS_WINDOW\r
+{\r
+       HWND hWnd;\r
+       THREAD *Thread;\r
+} STATUS_WINDOW;\r
+\r
+// バッチ処理アイテム\r
+typedef struct LVB_ITEM\r
+{\r
+       UINT NumStrings;                                // 文字列数\r
+       wchar_t **Strings;                              // 文字列バッファ\r
+       UINT Image;                                             // 画像番号\r
+       void *Param;                                    // パラメータ\r
+} LVB_ITEM;\r
+\r
+// LV 挿入バッチ処理\r
+typedef struct LVB\r
+{\r
+       LIST *ItemList;                                 // アイテムリスト\r
+} LVB;\r
+\r
+\r
+#ifdef CreateWindow\r
+\r
+// 内部用コード\r
+\r
+// フォント\r
+typedef struct FONT\r
+{\r
+       UINT Size;                                              // サイズ\r
+       bool Bold;                                              // 太字\r
+       bool Italic;                                    // 斜体\r
+       bool UnderLine;                                 // 下線\r
+       bool StrikeOut;                                 // 取り消し線\r
+       char *Name;                                             // フォント名\r
+       HFONT hFont;                                    // フォント\r
+       UINT x, y;                                              // フォントサイズ\r
+} FONT;\r
+\r
+// フォントキャッシュリスト\r
+static LIST *font_list = NULL;\r
+\r
+// ダイアログ関係\r
+typedef struct DIALOG_PARAM\r
+{\r
+       bool white;\r
+       void *param;\r
+       WINUI_DIALOG_PROC *proc;\r
+       bool meiryo;\r
+} DIALOG_PARAM;\r
+\r
+// セキュアデバイスウインドウ関係\r
+typedef struct SECURE_DEVICE_WINDOW\r
+{\r
+       WINUI_SECURE_BATCH *batch;\r
+       UINT num_batch;\r
+       UINT device_id;\r
+       struct SECURE_DEVICE_THREAD *p;\r
+       char *default_pin;\r
+       UINT BitmapId;\r
+} SECURE_DEVICE_WINDOW;\r
+\r
+// スレッド\r
+typedef struct SECURE_DEVICE_THREAD\r
+{\r
+       SECURE_DEVICE_WINDOW *w;\r
+       HWND hWnd;\r
+       bool Succeed;\r
+       wchar_t *ErrorMessage;\r
+       char *pin;\r
+} SECURE_DEVICE_THREAD;\r
+\r
+void StartSecureDevice(HWND hWnd, SECURE_DEVICE_WINDOW *w);\r
+\r
+// パスフレーズ\r
+typedef struct PASSPHRASE_DLG\r
+{\r
+       char pass[MAX_SIZE];\r
+       BUF *buf;\r
+       bool p12;\r
+} PASSPHRASE_DLG;\r
+\r
+void PassphraseDlgProcCommand(HWND hWnd, PASSPHRASE_DLG *p);\r
+\r
+// ステータスウインドウ\r
+typedef struct STATUS_WINDOW_PARAM\r
+{\r
+       HWND hWnd;\r
+       SOCK *Sock;\r
+       THREAD *Thread;\r
+       wchar_t AccountName[MAX_ACCOUNT_NAME_LEN + 1];\r
+} STATUS_WINDOW_PARAM;\r
+\r
+// 証明書表示ダイアログ\r
+typedef struct CERT_DLG\r
+{\r
+       X *x, *issuer_x;\r
+       bool ManagerMode;\r
+} CERT_DLG;\r
+\r
+\r
+typedef struct IMAGELIST_ICON\r
+{\r
+       UINT id;\r
+       HICON hSmallImage;\r
+       HICON hLargeImage;\r
+       UINT Index;\r
+} IMAGELIST_ICON;\r
+\r
+typedef struct SEARCH_WINDOW_PARAM\r
+{\r
+       wchar_t *caption;\r
+       HWND hWndFound;\r
+} SEARCH_WINDOW_PARAM;\r
+\r
+// リモート接続画面設定\r
+typedef struct WINUI_REMOTE\r
+{\r
+       bool flag1;\r
+       char *RegKeyName;                                       // レジストリキー名\r
+       UINT Icon;                                                      // アイコン\r
+       wchar_t *Caption;                                       // キャプション\r
+       wchar_t *Title;                                         // タイトル\r
+       char *Hostname;                                         // ホスト名\r
+       char *DefaultHostname;                          // デフォルトホスト名\r
+       LIST *CandidateList;                            // 候補リスト\r
+} WINUI_REMOTE;\r
+\r
+void InitImageList();\r
+void FreeImageList();\r
+IMAGELIST_ICON *LoadIconForImageList(UINT id);\r
+int CompareImageListIcon(void *p1, void *p2);\r
+BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam);\r
+void PrintCertInfo(HWND hWnd, CERT_DLG *p);\r
+void CertDlgUpdate(HWND hWnd, CERT_DLG *p);\r
+bool CALLBACK SearchWindowEnumProc(HWND hWnd, LPARAM lParam);\r
+UINT RemoteDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void RemoteDlgInit(HWND hWnd, WINUI_REMOTE *r);\r
+void RemoteDlgRefresh(HWND hWnd, WINUI_REMOTE *r);\r
+void RemoteDlgOnOk(HWND hWnd, WINUI_REMOTE *r);\r
+int CALLBACK LvSortProc(LPARAM param1, LPARAM param2, LPARAM sort_param);\r
+\r
+// アイコンキャッシュ\r
+typedef struct ICON_CACHE\r
+{\r
+       UINT id;\r
+       bool small_icon;\r
+       HICON hIcon;\r
+} ICON_CACHE;\r
+\r
+static LIST *icon_cache_list = NULL;\r
+\r
+// ソート関係\r
+typedef struct WINUI_LV_SORT\r
+{\r
+       HWND hWnd;\r
+       UINT id;\r
+       UINT subitem;\r
+       bool desc;\r
+       bool numeric;\r
+} WINUI_LV_SORT;\r
+\r
+// バージョン情報\r
+typedef struct WINUI_ABOUT\r
+{\r
+       CEDAR *Cedar;\r
+       char *ProductName;\r
+       UINT Bitmap;\r
+} WINUI_ABOUT;\r
+\r
+UINT AboutDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void AboutDlgInit(HWND hWnd, WINUI_ABOUT *a);\r
+\r
+typedef struct WIN9X_REBOOT_DLG\r
+{\r
+       UINT64 StartTime;\r
+       UINT TotalTime;\r
+} WIN9X_REBOOT_DLG;\r
+\r
+\r
+\r
+// STRING\r
+typedef struct STRING_DLG\r
+{\r
+       wchar_t String[MAX_SIZE];\r
+       wchar_t *Title;\r
+       wchar_t *Info;\r
+       UINT Icon;\r
+       bool AllowEmpty;\r
+       bool AllowUnsafe;\r
+} STRING_DLG;\r
+\r
+void StringDlgInit(HWND hWnd, STRING_DLG *s);\r
+void StringDlgUpdate(HWND hWnd, STRING_DLG *s);\r
+\r
+// PIN コードは 5 分間キャッシュされる\r
+#define        WINUI_SECUREDEVICE_PIN_CACHE_TIME               (5 * 60 * 1000)\r
+extern char cached_pin_code[MAX_SIZE];\r
+extern UINT64 cached_pin_code_expires;\r
+\r
+// TCP 接続ダイアログ関係\r
+typedef struct WINCONNECT_DLG_DATA\r
+{\r
+       wchar_t *caption;\r
+       wchar_t *info;\r
+       UINT icon_id;\r
+       UINT timeout;\r
+       char *hostname;\r
+       UINT port;\r
+       bool cancel;\r
+       SOCK *ret_sock;\r
+       THREAD *thread;\r
+       HWND hWnd;\r
+} WINCONNECT_DLG_DATA;\r
+\r
+#endif // WINUI_C\r
+\r
+// 隠し\r
+typedef struct KAKUSHI\r
+{\r
+       HWND hWnd;\r
+       THREAD *Thread;\r
+       volatile bool Halt;\r
+       UINT64 StartTick, Span;\r
+} KAKUSHI;\r
+\r
+// フリー版に関する情報画面\r
+typedef struct FREEINFO\r
+{\r
+       char ServerName[MAX_SERVER_STR_LEN + 1];\r
+       HWND hWnd;\r
+       THREAD *Thread;\r
+       EVENT *Event;\r
+} FREEINFO;\r
+\r
+// メッセージ\r
+typedef struct ONCEMSG_DLG\r
+{\r
+       UINT Icon;\r
+       wchar_t *Title;\r
+       wchar_t *Message;\r
+       bool ShowCheckbox;\r
+       bool Checked;\r
+       UINT MessageHash;\r
+       bool *halt;\r
+} ONCEMSG_DLG;\r
+\r
+// 悪いプロセスの定義\r
+typedef struct BAD_PROCESS\r
+{\r
+       char *ExeName;\r
+       char *Title;\r
+} BAD_PROCESS;\r
+\r
+// ビットマップ\r
+typedef struct WINBMP\r
+{\r
+       void *hBitmap;\r
+       UINT Width, Height, Bits;\r
+       void *hDC;\r
+} WINBMP;\r
+\r
+// メモリ DC\r
+typedef struct WINMEMDC\r
+{\r
+       void *hDC;\r
+       UINT Width, Height;\r
+       void *hBitmap;\r
+       UCHAR *Data;\r
+} WINMEMDC;\r
+\r
+#ifdef WINUI_C\r
+\r
+// 競合するアンチウイルスソフトのプロセス名一覧\r
+static BAD_PROCESS bad_processes[] =\r
+{\r
+       {"nod32krn.exe", "NOD32 Antivirus",},\r
+};\r
+\r
+static UINT num_bad_processes = sizeof(bad_processes) / sizeof(bad_processes[0]);\r
+\r
+#endif // WINUI_C\r
+\r
+// 関数プロトタイプ\r
+void InitWinUi(wchar_t *software_name, char *font, UINT fontsize);\r
+void SetWinUiTitle(wchar_t *title);\r
+void FreeWinUi();\r
+HWND DlgItem(HWND hWnd, UINT id);\r
+void SetText(HWND hWnd, UINT id, wchar_t *str);\r
+void SetTextInner(HWND hWnd, UINT id, wchar_t *str);\r
+void SetTextA(HWND hWnd, UINT id, char *str);\r
+wchar_t *GetText(HWND hWnd, UINT id);\r
+char *GetTextA(HWND hWnd, UINT id);\r
+bool GetTxt(HWND hWnd, UINT id, wchar_t *str, UINT size);\r
+bool GetTxtA(HWND hWnd, UINT id, char *str, UINT size);\r
+bool IsEnable(HWND hWnd, UINT id);\r
+bool IsDisable(HWND hWnd, UINT id);\r
+void Enable(HWND hWnd, UINT id);\r
+void Disable(HWND hWnd, UINT id);\r
+void SetEnable(HWND hWnd, UINT id, bool b);\r
+void Close(HWND hWnd);\r
+void DoEvents(HWND hWnd);\r
+void Refresh(HWND hWnd);\r
+UINT GetInt(HWND hWnd, UINT id);\r
+void SetInt(HWND hWnd, UINT id, UINT value);\r
+void SetIntEx(HWND hWnd, UINT id, UINT value);\r
+void Focus(HWND hWnd, UINT id);\r
+void FocusEx(HWND hWnd, UINT id);\r
+bool IsFocus(HWND hWnd, UINT id);\r
+wchar_t *GetClass(HWND hWnd, UINT id);\r
+char *GetClassA(HWND hWnd, UINT id);\r
+void SelectEdit(HWND hWnd, UINT id);\r
+void UnselectEdit(HWND hWnd, UINT id);\r
+UINT SendMsg(HWND hWnd, UINT id, UINT msg, WPARAM wParam, LPARAM lParam);\r
+bool IsEmpty(HWND hWnd, UINT id);\r
+UINT GetTextLen(HWND hWnd, UINT id, bool unicode);\r
+UINT GetTextSize(HWND hWnd, UINT id, bool unicode);\r
+UINT GetStyle(HWND hWnd, UINT id);\r
+void SetStyle(HWND hWnd, UINT id, UINT style);\r
+void RemoveStyle(HWND hWnd, UINT id, UINT style);\r
+UINT GetExStyle(HWND hWnd, UINT id);\r
+void SetExStyle(HWND hWnd, UINT id, UINT style);\r
+void RemoveExStyle(HWND hWnd, UINT id, UINT style);\r
+void Hide(HWND hWnd, UINT id);\r
+void Show(HWND hWnd, UINT id);\r
+void SetShow(HWND hWnd, UINT id, bool b);\r
+bool IsHide(HWND hWnd, UINT id);\r
+bool IsShow(HWND hWnd, UINT id);\r
+void Top(HWND hWnd);\r
+void NoTop(HWND hWnd);\r
+void *GetParam(HWND hWnd);\r
+void SetParam(HWND hWnd, void *param);\r
+UINT DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, bool white_color);\r
+void SetAplha(HWND hWnd, UINT value0_255);\r
+void NoticeSettingChange();\r
+void UiTest();\r
+UINT DialogInternal(HWND hWnd, UINT id, DIALOG_PROC *proc, void *param);\r
+UINT MsgBox(HWND hWnd, UINT flag, wchar_t *msg);\r
+UINT MsgBoxEx(HWND hWnd, UINT flag, wchar_t *msg, ...);\r
+void SetTextEx(HWND hWnd, UINT id, wchar_t *str, ...);\r
+void SetTextExA(HWND hWnd, UINT id, char *str, ...);\r
+void FormatText(HWND hWnd, UINT id, ...);\r
+void FormatTextA(HWND hWnd, UINT id, ...);\r
+void Center(HWND hWnd);\r
+void Center2(HWND hWnd);\r
+void CenterParent(HWND hWnd);\r
+void GetMonitorSize(UINT *width, UINT *height);\r
+void DisableClose(HWND hWnd);\r
+void EnableClose(HWND hWnd);\r
+void InitFont();\r
+void FreeFont();\r
+int CompareFont(void *p1, void *p2);\r
+HFONT GetFont(char *name, UINT size, bool bold, bool italic, bool underline, bool strikeout);\r
+bool CalcFontSize(HFONT hFont, UINT *x, UINT *y);\r
+bool GetFontSize(HFONT hFont, UINT *x, UINT *y);\r
+void SetFont(HWND hWnd, UINT id, HFONT hFont);\r
+void LimitText(HWND hWnd, UINT id, UINT count);\r
+bool CheckTextLen(HWND hWnd, UINT id, UINT len, bool unicode);\r
+bool CheckTextSize(HWND hWnd, UINT id, UINT size, bool unicode);\r
+void Check(HWND hWnd, UINT id, bool b);\r
+bool IsChecked(HWND hWnd, UINT id);\r
+void SetIcon(HWND hWnd, UINT id, UINT icon_id);\r
+void SetBitmap(HWND hWnd, UINT id, UINT bmp_id);\r
+bool SecureDeviceWindow(HWND hWnd, WINUI_SECURE_BATCH *batch, UINT num_batch, UINT device_id, UINT bitmap_id);\r
+UINT Dialog(HWND hWnd, UINT id, WINUI_DIALOG_PROC *proc, void *param);\r
+UINT DialogEx(HWND hWnd, UINT id, WINUI_DIALOG_PROC *proc, void *param, bool white);\r
+UINT DialogEx2(HWND hWnd, UINT id, WINUI_DIALOG_PROC *proc, void *param, bool white, bool meiryo);\r
+HWND DialogCreateEx(HWND hWnd, UINT id, WINUI_DIALOG_PROC *proc, void *param, bool white);\r
+UINT __stdcall InternalDialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);\r
+UINT SecureDeviceWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+HFONT Font(UINT size, UINT bold);\r
+void DlgFont(HWND hWnd, UINT id, UINT size, UINT bold);\r
+void OpenAvi(HWND hWnd, UINT id, UINT avi_id);\r
+void CloseAvi(HWND hWnd, UINT id);\r
+void PlayAvi(HWND hWnd, UINT id, bool repeat);\r
+void StopAvi(HWND hWnd, UINT id);\r
+void EnableSecureDeviceWindowControls(HWND hWnd, bool enable);\r
+void SecureDeviceThread(THREAD *t, void *param);\r
+void Command(HWND hWnd, UINT id);\r
+wchar_t *OpenDlg(HWND hWnd, wchar_t *filter, wchar_t *title);\r
+char *OpenDlgA(HWND hWnd, char *filter, char *title);\r
+wchar_t *SaveDlg(HWND hWnd, wchar_t *filter, wchar_t *title, wchar_t *default_name, wchar_t *default_ext);\r
+char *SaveDlgA(HWND hWnd, char *filter, char *title, char *default_name, char *default_ext);\r
+wchar_t *MakeFilter(wchar_t *str);\r
+char *MakeFilterA(char *str);\r
+void PkcsUtil();\r
+UINT PkcsUtilProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void PkcsUtilWrite(HWND hWnd);\r
+void PkcsUtilErase(HWND hWnd);\r
+bool PassphraseDlg(HWND hWnd, char *pass, UINT pass_size, BUF *buf, bool p12);\r
+UINT PassphraseDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+bool PasswordDlg(HWND hWnd, UI_PASSWORD_DLG *p);\r
+void PasswordDlgOnOk(HWND hWnd, UI_PASSWORD_DLG *p);\r
+UINT PasswordDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void PasswordDlgProcChange(HWND hWnd, UI_PASSWORD_DLG *p);\r
+UINT CbAddStr(HWND hWnd, UINT id, wchar_t *str, UINT data);\r
+UINT CbAddStrA(HWND hWnd, UINT id, char *str, UINT data);\r
+UINT CbAddStr9xA(HWND hWnd, UINT id, char *str, UINT data);\r
+UINT CbInsertStr(HWND hWnd, UINT id, UINT index, wchar_t *str, UINT data);\r
+UINT CbInsertStrA(HWND hWnd, UINT id, UINT index, char *str, UINT data);\r
+UINT CbInsertStr9xA(HWND hWnd, UINT id, UINT index, char *str, UINT data);\r
+void CbSelectIndex(HWND hWnd, UINT id, UINT index);\r
+UINT CbNum(HWND hWnd, UINT id);\r
+UINT CbFindStr(HWND hWnd, UINT id, wchar_t *str);\r
+UINT CbFindStr9xA(HWND hWnd, UINT id, char *str);\r
+wchar_t *CbGetStr(HWND hWnd, UINT id);\r
+UINT CbFindData(HWND hWnd, UINT id, UINT data);\r
+UINT CbGetData(HWND hWnd, UINT id, UINT index);\r
+void CbSelect(HWND hWnd, UINT id, int data);\r
+void CbReset(HWND hWnd, UINT id);\r
+void CbSetHeight(HWND hWnd, UINT id, UINT value);\r
+UINT CbGetSelectIndex(HWND hWnd, UINT id);\r
+UINT CbGetSelect(HWND hWnd, UINT id);\r
+void SetRange(HWND hWnd, UINT id, UINT start, UINT end);\r
+void SetPos(HWND hWnd, UINT id, UINT pos);\r
+UINT LbAddStr(HWND hWnd, UINT id, wchar_t *str, UINT data);\r
+UINT LbAddStrA(HWND hWnd, UINT id, char *str, UINT data);\r
+UINT LbInsertStr(HWND hWnd, UINT id, UINT index, wchar_t *str, UINT data);\r
+UINT LbInsertStrA(HWND hWnd, UINT id, UINT index, char *str, UINT data);\r
+void LbSelectIndex(HWND hWnd, UINT id, UINT index);\r
+UINT LbNum(HWND hWnd, UINT id);\r
+UINT LbFindStr(HWND hWnd, UINT id, wchar_t *str);\r
+wchar_t *LbGetStr(HWND hWnd, UINT id);\r
+UINT LbFindData(HWND hWnd, UINT id, UINT data);\r
+UINT LbGetData(HWND hWnd, UINT id, UINT index);\r
+void LbSelect(HWND hWnd, UINT id, int data);\r
+void LbReset(HWND hWnd, UINT id);\r
+void LbSetHeight(HWND hWnd, UINT id, UINT value);\r
+UINT LbGetSelectIndex(HWND hWnd, UINT id);\r
+UINT LbGetSelect(HWND hWnd, UINT id);\r
+STATUS_WINDOW *StatusPrinterWindowStart(SOCK *s, wchar_t *account_name);\r
+void StatusPrinterWindowStop(STATUS_WINDOW *sw);\r
+void StatusPrinterWindowPrint(STATUS_WINDOW *sw, wchar_t *str);\r
+void StatusPrinterWindowThread(THREAD *thread, void *param);\r
+UINT StatusPrinterWindowDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void CertDlg(HWND hWnd, X *x, X *issuer_x, bool manager);\r
+UINT CertDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void LvInit(HWND hWnd, UINT id);\r
+void LvInitEx(HWND hWnd, UINT id, bool no_image);\r
+void LvInitEx2(HWND hWnd, UINT id, bool no_image, bool large_icon);\r
+void LvReset(HWND hWnd, UINT id);\r
+void LvInsertColumn(HWND hWnd, UINT id, UINT index, wchar_t *str, UINT width);\r
+UINT GetIcon(UINT icon_id);\r
+void LvInsert(HWND hWnd, UINT id, UINT icon, void *param, UINT num_str, ...);\r
+UINT LvInsertItem(HWND hWnd, UINT id, UINT icon, void *param, wchar_t *str);\r
+UINT LvInsertItemByImageListId(HWND hWnd, UINT id, UINT image, void *param, wchar_t *str);\r
+UINT LvInsertItemByImageListIdA(HWND hWnd, UINT id, UINT image, void *param, char *str);\r
+void LvSetItem(HWND hWnd, UINT id, UINT index, UINT pos, wchar_t *str);\r
+void LvSetItemA(HWND hWnd, UINT id, UINT index, UINT pos, char *str);\r
+void LvSetItemParam(HWND hWnd, UINT id, UINT index, void *param);\r
+void LvSetItemImage(HWND hWnd, UINT id, UINT index, UINT icon);\r
+void LvSetItemImageByImageListId(HWND hWnd, UINT id, UINT index, UINT image);\r
+void LvDeleteItem(HWND hWnd, UINT id, UINT index);\r
+UINT LvNum(HWND hWnd, UINT id);\r
+void *LvGetParam(HWND hWnd, UINT id, UINT index);\r
+wchar_t *LvGetStr(HWND hWnd, UINT id, UINT index, UINT pos);\r
+char *LvGetStrA(HWND hWnd, UINT id, UINT index, UINT pos);\r
+void LvShow(HWND hWnd, UINT id, UINT index);\r
+UINT LvSearchParam(HWND hWnd, UINT id, void *param);\r
+UINT LvSearchStr(HWND hWnd, UINT id, UINT pos, wchar_t *str);\r
+UINT LvSearchStrA(HWND hWnd, UINT id, UINT pos, char *str);\r
+UINT LvGetSelected(HWND hWnd, UINT id);\r
+UINT LvGetFocused(HWND hWnd, UINT id);\r
+wchar_t *LvGetFocusedStr(HWND hWnd, UINT id, UINT pos);\r
+wchar_t *LvGetSelectedStr(HWND hWnd, UINT id, UINT pos);\r
+char *LvGetSelectedStrA(HWND hWnd, UINT id, UINT pos);\r
+bool LvIsSelected(HWND hWnd, UINT id);\r
+UINT LvGetNextMasked(HWND hWnd, UINT id, UINT start);\r
+bool LvIsMasked(HWND hWnd, UINT id);\r
+bool LvIsSingleSelected(HWND hWnd, UINT id);\r
+bool LvIsMultiMasked(HWND hWnd, UINT id);\r
+UINT LvGetMaskedNum(HWND hWnd, UINT id);\r
+void LvAutoSize(HWND hWnd, UINT id);\r
+void LvSelect(HWND hWnd, UINT id, UINT index);\r
+void LvSelectAll(HWND hWnd, UINT id);\r
+void LvSwitchSelect(HWND hWnd, UINT id);\r
+void LvSetView(HWND hWnd, UINT id, bool details);\r
+UINT LvGetColumnWidth(HWND hWnd, UINT id, UINT index);\r
+void CheckCertDlg(UI_CHECKCERT *p);\r
+UINT CheckCertDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void PrintCheckCertInfo(HWND hWnd, UI_CHECKCERT *p);\r
+void ShowDlgDiffWarning(HWND hWnd, UI_CHECKCERT *p);\r
+void CheckCertDialogOnOk(HWND hWnd, UI_CHECKCERT *p);\r
+bool ConnectErrorDlg(UI_CONNECTERROR_DLG *p);\r
+UINT ConnectErrorDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+HINSTANCE GetUiDll();\r
+HICON LoadLargeIconInner(UINT id);\r
+HICON LoadSmallIconInner(UINT id);\r
+HICON LoadLargeIcon(UINT id);\r
+HICON LoadSmallIcon(UINT id);\r
+HICON LoadIconEx(UINT id, bool small_icon);\r
+void InitIconCache();\r
+void FreeIconCache();\r
+LVB *LvInsertStart();\r
+void LvInsertAdd(LVB *b, UINT icon, void *param, UINT num_str, ...);\r
+void LvInsertEnd(LVB *b, HWND hWnd, UINT id);\r
+void LvInsertEndEx(LVB *b, HWND hWnd, UINT id, bool force_reset);\r
+void LvSetStyle(HWND hWnd, UINT id, UINT style);\r
+void LvRemoveStyle(HWND hWnd, UINT id, UINT style);\r
+HMENU LoadSubMenu(UINT menu_id, UINT pos, HMENU *parent_menu);\r
+UINT GetMenuItemPos(HMENU hMenu, UINT id);\r
+void DeleteMenuItem(HMENU hMenu, UINT pos);\r
+void SetMenuItemEnable(HMENU hMenu, UINT pos, bool enable);\r
+void SetMenuItemBold(HMENU hMenu, UINT pos, bool bold);\r
+wchar_t *GetMenuStr(HMENU hMenu, UINT pos);\r
+char *GetMenuStrA(HMENU hMenu, UINT pos);\r
+void SetMenuStr(HMENU hMenu, UINT pos, wchar_t *str);\r
+void SetMenuStrA(HMENU hMenu, UINT pos, char *str);\r
+void RemoveShortcutKeyStrFromMenu(HMENU hMenu);\r
+UINT GetMenuNum(HMENU hMenu);\r
+void PrintMenu(HWND hWnd, HMENU hMenu);\r
+void LvRename(HWND hWnd, UINT id, UINT pos);\r
+void AllowFGWindow(UINT process_id);\r
+HWND SearchWindow(wchar_t *caption);\r
+char *RemoteDlg(HWND hWnd, char *regkey, UINT icon, wchar_t *caption, wchar_t *title, char *default_host);\r
+LIST *ReadCandidateFromReg(UINT root, char *key, char *name);\r
+void WriteCandidateToReg(UINT root, char *key, LIST *o, char *name);\r
+UINT LvGetColumnNum(HWND hWnd, UINT id);\r
+void LvSetItemParamEx(HWND hWnd, UINT id, UINT index, UINT subitem, void *param);\r
+void LvSortEx(HWND hWnd, UINT id, UINT subitem, bool desc, bool numeric);\r
+void LvSort(HWND hWnd, UINT id, UINT subitem, bool desc);\r
+void *LvGetParamEx(HWND hWnd, UINT id, UINT index, UINT subitem);\r
+void LvSortHander(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT id);\r
+void LvStandardHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT id);\r
+void IpSet(HWND hWnd, UINT id, UINT ip);\r
+UINT IpGet(HWND hWnd, UINT id);\r
+void IpClear(HWND hWnd, UINT id);\r
+bool IpIsFilled(HWND hWnd, UINT id);\r
+UINT IpGetFilledNum(HWND hWnd, UINT id);\r
+void About(HWND hWnd, CEDAR *cedar, char *product_name, UINT bitmap);\r
+void Win9xReboot(HWND hWnd);\r
+void Win9xRebootThread(THREAD *t, void *p);\r
+UINT Win9xRebootDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+wchar_t *StringDlg(HWND hWnd, wchar_t *title, wchar_t *info, wchar_t *def, UINT icon, bool allow_empty, bool allow_unsafe);\r
+char *StringDlgA(HWND hWnd, wchar_t *title, wchar_t *info, char *def, UINT icon, bool allow_empty, bool allow_unsafe);\r
+UINT StringDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void InitDialogInternational(HWND hWnd, void *param);\r
+void AdjustWindowAndControlSize(HWND hWnd);\r
+void AdjustDialogXY(UINT *x, UINT *y, UINT dlgfont_x, UINT dlgfont_y);\r
+HFONT GetDialogDefaultFont();\r
+HFONT GetDialogDefaultFontEx(bool meiryo);\r
+void InitMenuInternational(HMENU hMenu, char *prefix);\r
+void InitMenuInternationalUni(HMENU hMenu, char *prefix);\r
+void ShowTcpIpConfigUtil(HWND hWnd, bool util_mode);\r
+void ShowCpu64Warning();\r
+UINT Cpu64DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+UINT TcpIpDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void TcpIpDlgInit(HWND hWnd);\r
+void TcpIpDlgUpdate(HWND hWnd);\r
+UINT TcpMsgDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+UINT KakushiDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void KakushiThread(THREAD *thread, void *param);\r
+KAKUSHI *InitKakushi();\r
+void FreeKakushi(KAKUSHI *k);\r
+void ShowEasterEgg(HWND hWnd);\r
+bool ExecuteHamcoreExe(char *name);\r
+bool Win32CnCheckAlreadyExists(bool lock);\r
+void RegistWindowsFirewallAll();\r
+void InitVistaWindowTheme(HWND hWnd);\r
+void WinUiDebug(wchar_t *str);\r
+void WinUiDebugInit();\r
+void WinUiDebugFree();\r
+void OnceMsg(HWND hWnd, wchar_t *title, wchar_t *message, bool show_checkbox, UINT icon);\r
+void OnceMsgEx(HWND hWnd, wchar_t *title, wchar_t *message, bool show_checkbox, UINT icon, bool *halt);\r
+UINT GetOnceMsgHash(wchar_t *title, wchar_t *message);\r
+UINT OnceMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+bool CheckBadProcesses(HWND hWnd);\r
+BAD_PROCESS *IsBadProcess(char *exe);\r
+void ShowBadProcessWarning(HWND hWnd, BAD_PROCESS *bad);\r
+void SetFontMeiryo(HWND hWnd, UINT id);\r
+void SetFontDefault(HWND hWnd, UINT id);\r
+HFONT GetMeiryoFont();\r
+HFONT GetMeiryoFontEx(UINT font_size);\r
+bool ShowWindowsNetworkConnectionDialog();\r
+SOCK *WinConnectEx2(HWND hWnd, char *server, UINT port, UINT timeout, UINT icon_id, wchar_t *caption, wchar_t *info);\r
+UINT WinConnectDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void WinConnectDlgThread(THREAD *thread, void *param);\r
+void NicInfo(UI_NICINFO *info);\r
+UINT NicInfoProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param);\r
+void NicInfoInit(HWND hWnd, UI_NICINFO *info);\r
+void NicInfoOnTimer(HWND hWnd, UI_NICINFO *info);\r
+void NicInfoRefresh(HWND hWnd, UI_NICINFO *info);\r
+void NicInfoShowStatus(HWND hWnd, UI_NICINFO *info, wchar_t *msg1, wchar_t *msg2, UINT icon, bool animate);\r
+void NicInfoCloseAfterTime(HWND hWnd, UI_NICINFO *info, UINT tick);\r
+bool IsNewStyleModeEnabled();\r
+void DisableNewStyleMode();\r
+void EnableNewStyleMode();\r
+void InitGdiCache();\r
+WINBMP *LoadBmpFromFileW(wchar_t *filename);\r
+WINBMP *LoadBmpFromFileInnerW(wchar_t *filename);\r
+WINBMP *LoadBmpFromFileA(char *filename);\r
+WINBMP *LoadBmpFromResource(UINT id);\r
+WINBMP *LoadBmpMain(void *hBitmap);\r
+void FreeBmp(WINBMP *b);\r
+void ShowSplash(HWND hWndParent, wchar_t *bmp_file_name, char *title, wchar_t *caption, UINT ticks, UINT line_color, void *param);\r
+void ShowSplashEx(HWND hWndParent, char *software_name, UINT ticks, UINT line_color);\r
+WINMEMDC *NewMemDC(UINT width, UINT height);\r
+void FreeMemDC(WINMEMDC *m);\r
+void LvSetBkImage(HWND hWnd, UINT id, char *bmp_file_name);\r
+bool IsFullColor();\r
+\r
+#endif // OS_WIN32\r
+\r
+\r
+\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Ham/Ham.c b/utvpn/utvpn-unix-v101-7101-public/src/Ham/Ham.c
new file mode 100644 (file)
index 0000000..8545dd9
--- /dev/null
@@ -0,0 +1,525 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Ham.c\r
+// Hamster テストプログラム\r
+// (UT-VPN の動作テストを行うための CUI プログラム。)\r
+\r
+\r
+\r
+#define        HAM_C\r
+\r
+#ifdef WIN32\r
+#define        HAM_WIN32\r
+#define        _WIN32_WINNT            0x0502\r
+#define        WINVER                          0x0502\r
+#include <winsock2.h>\r
+#include <Ws2tcpip.h>\r
+#include <windows.h>\r
+#include <DbgHelp.h>\r
+#include <Iphlpapi.h>\r
+#include <wtsapi32.h>\r
+#include "../pencore/resource.h"\r
+#endif\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <math.h>\r
+#include <openssl/ssl.h>\r
+#include <openssl/err.h>\r
+#include <openssl/rand.h>\r
+#include <openssl/engine.h>\r
+#include <openssl/bio.h>\r
+#include <openssl/x509.h>\r
+#include <openssl/pkcs7.h>\r
+#include <openssl/pkcs12.h>\r
+#include <openssl/rc4.h>\r
+#include <openssl/md5.h>\r
+#include <openssl/sha.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+#include "Ham.h"\r
+\r
+// テスト関数一覧定義\r
+typedef void (TEST_PROC)(UINT num, char **arg);\r
+\r
+typedef struct TEST_LIST\r
+{\r
+       char *command_str;\r
+       TEST_PROC *proc;\r
+} TEST_LIST;\r
+\r
+typedef struct TESTST\r
+{\r
+       USHORT a:4, b:4;\r
+} TESTST;\r
+\r
+void test(UINT num, char **arg)\r
+{\r
+}\r
+\r
+// デバッグ\r
+void debug(UINT num, char **arg)\r
+{\r
+       // カーネル状態の表示\r
+       if (g_debug)\r
+       {\r
+               PrintKernelStatus();\r
+       }\r
+\r
+       // デバッグ情報の表示\r
+       if (g_memcheck)\r
+       {\r
+               PrintDebugInformation();\r
+       }\r
+}\r
+\r
+void client_test(UINT num, char **arg)\r
+{\r
+#ifdef OS_WIN32\r
+       MsWriteCallingServiceManagerProcessId("utvpnclient", MsGetCurrentProcessId());\r
+#endif // OS_WIN32\r
+\r
+       Print("Client Test.\n");\r
+       CtStartClient();\r
+       GetLine(NULL, 0);\r
+       CtStopClient();\r
+\r
+#ifdef OS_WIN32\r
+       MsWriteCallingServiceManagerProcessId("utvpnclient", 0);\r
+#endif // OS_WIN32\r
+}\r
+\r
+void server_test(UINT num, char **arg)\r
+{\r
+       UINT p[] = {52, 80, 8080, 3128};\r
+       Print("Server Test.\n");\r
+\r
+       if (num != 0)\r
+       {\r
+               SERVER_CONFIG_FILE_NAME = "@vpn_member_server.config";\r
+       }\r
+\r
+       StInit();\r
+\r
+       StStartServer(false);\r
+\r
+       GetLine(NULL, 0);\r
+\r
+       if (0 && num != 0)\r
+       {\r
+               UINT ports[] = {443, 992};\r
+               UCHAR password[SHA1_SIZE];\r
+               Hash(password, "", 0, true);\r
+               SiSetServerType(StGetServer(), SERVER_TYPE_FARM_MEMBER, 0x0100007f,\r
+                       sizeof(ports) / sizeof(ports[0]), ports, "pc1.sec.softether.co.jp", 5555, password, 0, false);\r
+               GetLine(NULL, 0);\r
+       }\r
+\r
+       if (0 && num == 0)\r
+       {\r
+               HUB *h = GetHub(StGetServer()->Cedar, "DEFAULT");\r
+               SetHubOffline(h);\r
+               GetLine(NULL, 0);\r
+               SetHubOnline(h);\r
+               GetLine(NULL, 0);\r
+               ReleaseHub(h);\r
+       }\r
+\r
+       StStopServer();\r
+\r
+       StFree();\r
+}\r
+\r
+void disablevlan(UINT num, char **arg)\r
+{\r
+#ifdef OS_WIN32\r
+       bool ok;\r
+       if (num < 1)\r
+       {\r
+               Print("NO NAME.\n");\r
+               return;\r
+       }\r
+\r
+       ok = MsDisableVLan(arg[0]);\r
+\r
+#ifdef VISTA_HAM\r
+       if (ok == false)\r
+       {\r
+               _exit(1);\r
+       }\r
+       else\r
+       {\r
+               _exit(0);\r
+       }\r
+#endif\r
+#endif // OS_WIN32\r
+}\r
+\r
+void enablevlan(UINT num, char **arg)\r
+{\r
+#ifdef OS_WIN32\r
+       bool ok;\r
+       if (num < 1)\r
+       {\r
+               Print("NO NAME.\n");\r
+               return;\r
+       }\r
+\r
+       ok = MsEnableVLan(arg[0]);\r
+\r
+#ifdef VISTA_HAM\r
+       if (ok == false)\r
+       {\r
+               _exit(1);\r
+       }\r
+       else\r
+       {\r
+               _exit(0);\r
+       }\r
+#endif\r
+#endif // OS_WIN32\r
+}\r
+\r
+void instvlan(UINT num, char **arg)\r
+{\r
+#ifdef OS_WIN32\r
+       KAKUSHI *k = NULL;\r
+       bool ok;\r
+       if (num < 1)\r
+       {\r
+               Print("NO NAME.\n");\r
+               return;\r
+       }\r
+\r
+       InitWinUi(L"VPN", _SS("DEFAULT_FONT"), _II("DEFAULT_FONT_SIZE"));\r
+\r
+       if (MsIsNt())\r
+       {\r
+               k = InitKakushi();\r
+       }\r
+\r
+       ok = MsInstallVLan(VLAN_ADAPTER_NAME_TAG, VLAN_CONNECTION_NAME, arg[0]);\r
+\r
+       FreeKakushi(k);\r
+\r
+       FreeWinUi();\r
+\r
+#ifdef VISTA_HAM\r
+       if (ok == false)\r
+       {\r
+               _exit(1);\r
+       }\r
+       else\r
+       {\r
+               _exit(0);\r
+       }\r
+#endif\r
+#endif\r
+}\r
+\r
+void upgradevlan(UINT num, char **arg)\r
+{\r
+#ifdef OS_WIN32\r
+       bool ok;\r
+       KAKUSHI *k = NULL;\r
+       if (num < 1)\r
+       {\r
+               Print("NO NAME.\n");\r
+               return;\r
+       }\r
+\r
+       InitWinUi(L"VPN", _SS("DEFAULT_FONT"), _II("DEFAULT_FONT_SIZE"));\r
+\r
+       if (MsIsNt())\r
+       {\r
+               k = InitKakushi();\r
+       }\r
+\r
+       ok = MsUpgradeVLan(VLAN_ADAPTER_NAME_TAG, VLAN_CONNECTION_NAME, arg[0]);\r
+\r
+       FreeKakushi(k);\r
+\r
+       FreeWinUi();\r
+\r
+#ifdef VISTA_HAM\r
+       if (ok == false)\r
+       {\r
+               _exit(1);\r
+       }\r
+       else\r
+       {\r
+               _exit(0);\r
+       }\r
+#endif\r
+#endif\r
+}\r
+\r
+void uninstvlan(UINT num, char **arg)\r
+{\r
+#ifdef OS_WIN32\r
+       bool ok;\r
+       if (num < 1)\r
+       {\r
+               Print("NO NAME.\n");\r
+               return;\r
+       }\r
+\r
+       ok = MsUninstallVLan(arg[0]);\r
+\r
+#ifdef VISTA_HAM\r
+       if (ok == false)\r
+       {\r
+               _exit(1);\r
+       }\r
+       else\r
+       {\r
+               _exit(0);\r
+       }\r
+#endif\r
+#endif\r
+}\r
+\r
+void sm_test(UINT num, char **arg)\r
+{\r
+#ifdef OS_WIN32\r
+       SMExec();\r
+#endif\r
+}\r
+\r
+void cm_test(UINT num, char **arg)\r
+{\r
+#ifdef OS_WIN32\r
+       CMExec();\r
+#endif\r
+}\r
+\r
+TEST_LIST test_list[] =\r
+{\r
+       {"cc", client_test},\r
+       {"ss", server_test},\r
+       {"instvlan", instvlan},\r
+       {"uninstvlan", uninstvlan},\r
+       {"upgradevlan", upgradevlan},\r
+       {"enablevlan", enablevlan},\r
+       {"disablevlan", disablevlan},\r
+       {"cm", cm_test},\r
+       {"sm", sm_test},\r
+       {"test", test},\r
+};\r
+\r
+// テスト関数\r
+void TestMain(char *cmd)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       bool first = true;\r
+       bool exit_now = false;\r
+\r
+       Print("SoftEther UT-VPN Hamster Tester\n\n"\r
+               "Copyright (C) 2004-2010 SoftEther Corporation.\nCopyright (C) 2004-2010 University of Tsukuba, Japan.\n"\r
+               "Copyright (C) 2003-2010 Daiyuu Nobori.\nAll Rights Reserved.\n\n");\r
+\r
+#ifdef OS_WIN32\r
+       MsSetEnableMinidump(false);\r
+#endif // OS_WIN32\r
+\r
+       while (true)\r
+       {\r
+               Print("TEST>");\r
+               if (first && StrLen(cmd) != 0 && g_memcheck == false)\r
+               {\r
+                       first = false;\r
+                       StrCpy(tmp, sizeof(tmp), cmd);\r
+                       exit_now = true;\r
+                       Print("%s\n", cmd);\r
+               }\r
+               else\r
+               {\r
+                       GetLine(tmp, sizeof(tmp));\r
+               }\r
+               Trim(tmp);\r
+               if (StrLen(tmp) != 0)\r
+               {\r
+                       UINT i, num;\r
+                       bool b = false;\r
+                       TOKEN_LIST *token = ParseCmdLine(tmp);\r
+                       char *cmd = token->Token[0];\r
+                       if (!StrCmpi(cmd, "exit") || !StrCmpi(cmd, "quit") || !StrCmpi(cmd, "q"))\r
+                       {\r
+                               FreeToken(token);\r
+                               break;\r
+                       }\r
+                       if (StartWith(tmp, "utvpncmd"))\r
+                       {\r
+                               wchar_t *s = CopyStrToUni(tmp);\r
+                               CommandMain(s);\r
+                               Free(s);\r
+                       }\r
+                       else\r
+                       {\r
+                               num = sizeof(test_list) / sizeof(TEST_LIST);\r
+                               for (i = 0;i < num;i++)\r
+                               {\r
+                                       if (!StrCmpi(test_list[i].command_str, cmd))\r
+                                       {\r
+                                               char **arg = Malloc(sizeof(char *) * (token->NumTokens - 1));\r
+                                               UINT j;\r
+                                               for (j = 0;j < token->NumTokens - 1;j++)\r
+                                               {\r
+                                                       arg[j] = CopyStr(token->Token[j + 1]);\r
+                                               }\r
+                                               test_list[i].proc(token->NumTokens - 1, arg);\r
+                                               for (j = 0;j < token->NumTokens - 1;j++)\r
+                                               {\r
+                                                       Free(arg[j]);\r
+                                               }\r
+                                               Free(arg);\r
+                                               b = true;\r
+                                               Print("\n");\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               if (b == false)\r
+                               {\r
+                                       Print("Invalid Command: %s\n\n", cmd);\r
+                               }\r
+                       }\r
+                       FreeToken(token);\r
+\r
+                       if (exit_now)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       Print("Exiting...\n\n");\r
+}\r
+\r
+#ifdef WIN32\r
+// winmain 関数\r
+int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, char *CmdLine, int CmdShow)\r
+{\r
+       main(0, NULL);\r
+}\r
+#endif\r
+\r
+// main 関数\r
+int main(int argc, char *argv[])\r
+{\r
+       bool memchk = false;\r
+       UINT i;\r
+       char cmd[MAX_SIZE];\r
+       char *s;\r
+\r
+       printf("Starting Test Program...\n");\r
+\r
+       cmd[0] = 0;\r
+       if (argc >= 2)\r
+       {\r
+               for (i = 1;i < (UINT)argc;i++)\r
+               {\r
+                       s = argv[i];\r
+                       if (s[0] == '/')\r
+                       {\r
+                               if (!StrCmpi(s, "/memcheck"))\r
+                               {\r
+                                       memchk = true;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               StrCpy(cmd, sizeof(cmd), &s[0]);\r
+                       }\r
+               }\r
+       }\r
+\r
+       InitMayaqua(memchk, true, argc, argv);\r
+       EnableProbe(true);\r
+       InitCedar();\r
+       SetHamMode();\r
+       TestMain(cmdline);\r
+       FreeCedar();\r
+       FreeMayaqua();\r
+\r
+       return 0;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Ham/Ham.h b/utvpn/utvpn-unix-v101-7101-public/src/Ham/Ham.h
new file mode 100644 (file)
index 0000000..59fc598
--- /dev/null
@@ -0,0 +1,85 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Ham.h\r
+// Ham.c のヘッダファイル\r
+\r
+\r
+// 関数プロトタイプ\r
+int main(int argc, char *argv[]);\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Cfg.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Cfg.c
new file mode 100644 (file)
index 0000000..d7fcd0d
--- /dev/null
@@ -0,0 +1,2280 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Cfg.c\r
+// 設定情報操作モジュール\r
+\r
+#define        CFG_C\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+// 設定ファイルのバックアップの作成\r
+void BackupCfg(FOLDER *f, char *original)\r
+{\r
+       wchar_t *original_w = CopyStrToUni(original);\r
+\r
+       BackupCfgW(f, original_w);\r
+\r
+       Free(original_w);\r
+}\r
+void BackupCfgW(FOLDER *f, wchar_t *original)\r
+{\r
+       wchar_t dirname[MAX_PATH];\r
+       wchar_t filename[MAX_PATH];\r
+       wchar_t fullpath[MAX_PATH];\r
+       SYSTEMTIME st;\r
+       // 引数チェック\r
+       if (f == NULL || filename == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ディレクトリ名を決定\r
+       UniFormat(dirname, sizeof(dirname), L"@backup.%s", original[0] == L'@' ? original + 1 : original);\r
+\r
+       // ファイル名を決定\r
+       LocalTime(&st);\r
+       UniFormat(filename, sizeof(filename), L"%04u%02u%02u%02u_%s",\r
+               st.wYear, st.wMonth, st.wDay, st.wHour, original[0] == L'@' ? original + 1 : original);\r
+\r
+       // このファイル名が存在するかどうかチェックする\r
+       if (IsFileExistsW(filename))\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ディレクトリ作成\r
+       MakeDirW(dirname);\r
+\r
+       // ファイル保存\r
+       UniFormat(fullpath, sizeof(fullpath), L"%s/%s", dirname, filename);\r
+       CfgSaveW(f, fullpath);\r
+}\r
+\r
+// 設定ファイル R/W を閉じる\r
+void FreeCfgRw(CFG_RW *rw)\r
+{\r
+       // 引数チェック\r
+       if (rw == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (rw->Io != NULL)\r
+       {\r
+               FileClose(rw->Io);\r
+       }\r
+\r
+       DeleteLock(rw->lock);\r
+       Free(rw->FileNameW);\r
+       Free(rw->FileName);\r
+       Free(rw);\r
+}\r
+\r
+// 設定ファイルの書き込み\r
+UINT SaveCfgRw(CFG_RW *rw, FOLDER *f)\r
+{\r
+       UINT ret = 0;\r
+       // 引数チェック\r
+       if (rw == NULL || f == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Lock(rw->lock);\r
+       {\r
+               if (rw->Io != NULL)\r
+               {\r
+                       FileClose(rw->Io);\r
+                       rw->Io = NULL;\r
+               }\r
+\r
+               if (CfgSaveExW2(rw, f, rw->FileNameW, &ret))\r
+               {\r
+                       if (rw->DontBackup == false)\r
+                       {\r
+                               BackupCfgW(f, rw->FileNameW);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       ret = 0;\r
+               }\r
+\r
+               rw->Io = FileOpenW(rw->FileNameW, false);\r
+       }\r
+       Unlock(rw->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// 設定ファイル R/W の作成\r
+CFG_RW *NewCfgRw(FOLDER **root, char *cfg_name)\r
+{\r
+       return NewCfgRwEx(root, cfg_name, false);\r
+}\r
+CFG_RW *NewCfgRwW(FOLDER **root, wchar_t *cfg_name)\r
+{\r
+       return NewCfgRwExW(root, cfg_name, false);\r
+}\r
+CFG_RW *NewCfgRwEx(FOLDER **root, char *cfg_name, bool dont_backup)\r
+{\r
+       wchar_t *cfg_name_w = CopyStrToUni(cfg_name);\r
+       CFG_RW *ret = NewCfgRwExW(root, cfg_name_w, dont_backup);\r
+\r
+       Free(cfg_name_w);\r
+\r
+       return ret;\r
+}\r
+CFG_RW *NewCfgRwExW(FOLDER **root, wchar_t *cfg_name, bool dont_backup)\r
+{\r
+       CFG_RW *rw;\r
+       FOLDER *f;\r
+       // 引数チェック\r
+       if (cfg_name == NULL || root == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       f = CfgReadW(cfg_name);\r
+       if (f == NULL)\r
+       {\r
+               rw = ZeroMalloc(sizeof(CFG_RW));\r
+               rw->lock = NewLock();\r
+               rw->FileNameW = CopyUniStr(cfg_name);\r
+               rw->FileName = CopyUniToStr(cfg_name);\r
+               rw->Io = FileCreateW(cfg_name);\r
+               *root = NULL;\r
+               rw->DontBackup = dont_backup;\r
+\r
+               return rw;\r
+       }\r
+\r
+       rw = ZeroMalloc(sizeof(CFG_RW));\r
+       rw->FileNameW = CopyUniStr(cfg_name);\r
+       rw->FileName = CopyUniToStr(cfg_name);\r
+       rw->Io = FileOpenW(cfg_name, false);\r
+       rw->lock = NewLock();\r
+\r
+       *root = f;\r
+\r
+       rw->DontBackup = dont_backup;\r
+\r
+       return rw;\r
+}\r
+\r
+// ファイルをコピーする\r
+bool FileCopy(char *src, char *dst)\r
+{\r
+       BUF *b;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (src == NULL || dst == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = ReadDump(src);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       ret = DumpBuf(b, dst);\r
+\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+bool FileCopyW(wchar_t *src, wchar_t *dst)\r
+{\r
+       BUF *b;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (src == NULL || dst == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = ReadDumpW(src);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       ret = DumpBufW(b, dst);\r
+\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// ファイルへ設定を保存する\r
+void CfgSave(FOLDER *f, char *name)\r
+{\r
+       CfgSaveEx(NULL, f, name);\r
+}\r
+void CfgSaveW(FOLDER *f, wchar_t *name)\r
+{\r
+       CfgSaveExW(NULL, f, name);\r
+}\r
+bool CfgSaveEx(CFG_RW *rw, FOLDER *f, char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       bool ret = CfgSaveExW(rw, f, name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+bool CfgSaveExW(CFG_RW *rw, FOLDER *f, wchar_t *name)\r
+{\r
+       return CfgSaveExW2(rw, f, name, NULL);\r
+}\r
+bool CfgSaveExW2(CFG_RW *rw, FOLDER *f, wchar_t *name, UINT *written_size)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       bool text = true;\r
+       UCHAR hash[SHA1_SIZE];\r
+       BUF *b;\r
+       IO *o;\r
+       bool ret = true;\r
+       UINT dummy_int = 0;\r
+       // 引数チェック\r
+       if (name == NULL || f == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (written_size == NULL)\r
+       {\r
+               written_size = &dummy_int;\r
+       }\r
+\r
+       // 同じディレクトリにある SAVE_BINARY_FILE_NAME_SWITCH ファイルがあるかどうか確認\r
+       if (IsFileExistsW(SAVE_BINARY_FILE_NAME_SWITCH))\r
+       {\r
+               text = false;\r
+       }\r
+\r
+       // バッファに変換\r
+       b = CfgFolderToBuf(f, text);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       // 内容をハッシュする\r
+       Hash(hash, b->Buf, b->Size, true);\r
+\r
+       // 最後に書き込んだ内容と書き込む内容を比較する\r
+       if (rw != NULL)\r
+       {\r
+               if (Cmp(hash, rw->LashHash, SHA1_SIZE) == 0)\r
+               {\r
+                       // 内容が変更されていない\r
+                       ret = false;\r
+               }\r
+               else\r
+               {\r
+                       Copy(rw->LashHash, hash, SHA1_SIZE);\r
+               }\r
+       }\r
+\r
+       if (ret || OS_IS_UNIX(GetOsInfo()->OsType))\r
+       {\r
+               // 一時的なファイル名の生成\r
+               UniFormat(tmp, sizeof(tmp), L"%s.log", name);\r
+               // 現在存在するファイルを一時ファイルにコピー\r
+               FileCopyW(name, tmp);\r
+\r
+               // 新しいファイルを保存\r
+               o = FileCreateW(name);\r
+               if (o != NULL)\r
+               {\r
+                       if (FileWrite(o, b->Buf, b->Size) == false)\r
+                       {\r
+                               // ファイル保存失敗\r
+                               FileClose(o);\r
+                               FileDeleteW(name);\r
+                               FileRenameW(tmp, name);\r
+\r
+                               if (rw != NULL)\r
+                               {\r
+                                       Zero(rw->LashHash, sizeof(rw->LashHash));\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // ファイル保存成功\r
+                               FileClose(o);\r
+                               // 一時ファイルの削除\r
+                               FileDeleteW(tmp);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // ファイル保存失敗\r
+                       FileRenameW(tmp, name);\r
+\r
+                       if (rw != NULL)\r
+                       {\r
+                               Zero(rw->LashHash, sizeof(rw->LashHash));\r
+                       }\r
+               }\r
+       }\r
+\r
+       *written_size = b->Size;\r
+\r
+       // メモリ解放\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// ファイルから設定を読み込む\r
+FOLDER *CfgRead(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       FOLDER *ret = CfgReadW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+FOLDER *CfgReadW(wchar_t *name)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t newfile[MAX_SIZE];\r
+       BUF *b;\r
+       IO *o;\r
+       UINT size;\r
+       void *buf;\r
+       FOLDER *f;\r
+       bool delete_new = false;\r
+       bool binary_file = false;\r
+       bool invalid_file = false;\r
+       UCHAR header[8];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 新しいファイル名の生成\r
+       UniFormat(newfile, sizeof(newfile), L"%s.new", name);\r
+       // 一時的なファイル名の生成\r
+       UniFormat(tmp, sizeof(tmp), L"%s.log", name);\r
+\r
+       // 新しいファイルが存在していれば読み込む\r
+       o = FileOpenW(newfile, false);\r
+       if (o == NULL)\r
+       {\r
+               // 一時的なファイルを読む\r
+               o = FileOpenW(tmp, false);\r
+       }\r
+       else\r
+       {\r
+               delete_new = true;\r
+       }\r
+       if (o == NULL)\r
+       {\r
+               // 一時的なファイルが無い場合は本来のファイルを読む\r
+               o = FileOpenW(name, false);\r
+       }\r
+       else\r
+       {\r
+               // 一時的なファイルのサイズが 0 の場合も本来のファイルを読み込む\r
+               if (FileSize(o) == 0)\r
+               {\r
+                       invalid_file = true;\r
+               }\r
+\r
+               if (invalid_file)\r
+               {\r
+                       FileClose(o);\r
+                       o = FileOpenW(name, false);\r
+               }\r
+       }\r
+       if (o == NULL)\r
+       {\r
+               // 読み込みに失敗した\r
+               return NULL;\r
+       }\r
+\r
+       // バッファに読み込む\r
+       size = FileSize(o);\r
+       buf = Malloc(size);\r
+       FileRead(o, buf, size);\r
+       b = NewBuf();\r
+       WriteBuf(b, buf, size);\r
+       SeekBuf(b, 0, 0);\r
+\r
+       // ファイルを閉じる\r
+       FileClose(o);\r
+\r
+       if (delete_new)\r
+       {\r
+               // 新しいファイルを削除する\r
+               FileDeleteW(newfile);\r
+       }\r
+\r
+       // バッファの先頭 8 文字が "SEVPN_DB" の場合はバイナリファイル\r
+       ReadBuf(b, header, sizeof(header));\r
+       if (Cmp(header, TAG_BINARY, 8) == 0)\r
+       {\r
+               UCHAR hash1[SHA1_SIZE], hash2[SHA1_SIZE];\r
+               binary_file = true;\r
+\r
+               // ハッシュチェック\r
+               ReadBuf(b, hash1, sizeof(hash1));\r
+\r
+               Hash(hash2, ((UCHAR *)b->Buf) + 8 + SHA1_SIZE, b->Size - 8 - SHA1_SIZE, true);\r
+\r
+               if (Cmp(hash1, hash2, SHA1_SIZE) != 0)\r
+               {\r
+                       // 破損ファイル\r
+                       invalid_file = true;\r
+                       FreeBuf(b);\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       if (binary_file)\r
+       {\r
+               SeekBuf(b, 8 + SHA1_SIZE, 0);\r
+       }\r
+\r
+       // バッファからフォルダに変換\r
+       if (binary_file == false)\r
+       {\r
+               // テキストモード\r
+               f = CfgBufTextToFolder(b);\r
+       }\r
+       else\r
+       {\r
+               // バイナリモード\r
+               f = CfgBufBinToFolder(b);\r
+       }\r
+\r
+       // メモリ解放\r
+       Free(buf);\r
+       FreeBuf(b);\r
+\r
+       FileDeleteW(newfile);\r
+\r
+       return f;\r
+}\r
+\r
+// Cfg のテスト\r
+void CfgTest2(FOLDER *f, UINT n)\r
+{\r
+}\r
+\r
+void CfgTest()\r
+{\r
+#if    0\r
+       FOLDER *root;\r
+       BUF *b;\r
+       Debug("\nCFG Test Begin\n");\r
+\r
+       root = CfgCreateFolder(NULL, TAG_ROOT);\r
+       CfgTest2(root, 5);\r
+\r
+       b = CfgFolderToBufText(root);\r
+       //Print("%s\n", b->Buf);\r
+       SeekBuf(b, 0, 0);\r
+\r
+       CfgDeleteFolder(root);\r
+\r
+       DumpBuf(b, "test1.config");\r
+\r
+       root = CfgBufTextToFolder(b);\r
+\r
+       FreeBuf(b);\r
+\r
+       b = CfgFolderToBufText(root);\r
+//     Print("%s\n", b->Buf);\r
+       DumpBuf(b, "test2.config");\r
+       FreeBuf(b);\r
+\r
+       CfgSave(root, "test.txt");\r
+\r
+       CfgDeleteFolder(root);\r
+\r
+       Debug("\nCFG Test End\n");\r
+#endif\r
+}\r
+\r
+// 1 行読み込む\r
+char *CfgReadNextLine(BUF *b)\r
+{\r
+       char *tmp;\r
+       char *buf;\r
+       UINT len;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 次の改行までの文字数を調査\r
+       tmp = (char *)b->Buf + b->Current;\r
+       if ((b->Size - b->Current) == 0)\r
+       {\r
+               // 最後まで読んだ\r
+               return NULL;\r
+       }\r
+       len = 0;\r
+       while (true)\r
+       {\r
+               if (tmp[len] == 13 || tmp[len] == 10)\r
+               {\r
+                       if (tmp[len] == 13)\r
+                       {\r
+                               if (len < (b->Size - b->Current))\r
+                               {\r
+                                       len++;\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+               len++;\r
+               if (len >= (b->Size - b->Current))\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       // len だけ読み込む\r
+       buf = ZeroMalloc(len + 1);\r
+       ReadBuf(b, buf, len);\r
+       SeekBuf(b, 1, 1);\r
+\r
+       if (StrLen(buf) >= 1)\r
+       {\r
+               if (buf[StrLen(buf) - 1] == 13)\r
+               {\r
+                       buf[StrLen(buf) - 1] = 0;\r
+               }\r
+       }\r
+\r
+       return buf;\r
+}\r
+\r
+// テキストストリームを読み込む\r
+bool CfgReadNextTextBUF(BUF *b, FOLDER *current)\r
+{\r
+       char *buf;\r
+       TOKEN_LIST *token;\r
+       char *name;\r
+       char *string;\r
+       char *data;\r
+       bool ret;\r
+       FOLDER *f;\r
+\r
+       // 引数チェック\r
+       if (b == NULL || current == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = true;\r
+\r
+       // 1 行読み込む\r
+       buf = CfgReadNextLine(b);\r
+       if (buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // この行を解析\r
+       token = ParseToken(buf, "\t ");\r
+       if (token == NULL)\r
+       {\r
+               Free(buf);\r
+               return false;\r
+       }\r
+\r
+       if (token->NumTokens >= 1)\r
+       {\r
+               if (!StrCmpi(token->Token[0], TAG_DECLARE))\r
+               {\r
+                       if (token->NumTokens >= 2)\r
+                       {\r
+                               // declare\r
+                               name = CfgUnescape(token->Token[1]);\r
+\r
+                               // フォルダの作成\r
+                               f = CfgCreateFolder(current, name);\r
+\r
+                               // 次のフォルダを読み込む\r
+                               while (true)\r
+                               {\r
+                                       if (CfgReadNextTextBUF(b, f) == false)\r
+                                       {\r
+                                               break;\r
+                                       }\r
+                               }\r
+\r
+                               Free(name);\r
+                       }\r
+               }\r
+               if (!StrCmpi(token->Token[0], "}"))\r
+               {\r
+                       // end\r
+                       ret = false;\r
+               }\r
+               if (token->NumTokens >= 3)\r
+               {\r
+                       name = CfgUnescape(token->Token[1]);\r
+                       data = token->Token[2];\r
+\r
+                       if (!StrCmpi(token->Token[0], TAG_STRING))\r
+                       {\r
+                               // string\r
+                               wchar_t *uni;\r
+                               UINT uni_size;\r
+                               string = CfgUnescape(data);\r
+                               uni_size = CalcUtf8ToUni(string, StrLen(string));\r
+                               if (uni_size != 0)\r
+                               {\r
+                                       uni = Malloc(uni_size);\r
+                                       Utf8ToUni(uni, uni_size, string, StrLen(string));\r
+                                       CfgAddUniStr(current, name, uni);\r
+                                       Free(uni);\r
+                               }\r
+                               Free(string);\r
+                       }\r
+                       if (!StrCmpi(token->Token[0], TAG_INT))\r
+                       {\r
+                               // uint\r
+                               CfgAddInt(current, name, ToInt(data));\r
+                       }\r
+                       if (!StrCmpi(token->Token[0], TAG_INT64))\r
+                       {\r
+                               // uint64\r
+                               CfgAddInt64(current, name, ToInt64(data));\r
+                       }\r
+                       if (!StrCmpi(token->Token[0], TAG_BOOL))\r
+                       {\r
+                               // bool\r
+                               bool b = false;\r
+                               if (!StrCmpi(data, TAG_TRUE))\r
+                               {\r
+                                       b = true;\r
+                               }\r
+                               else if (ToInt(data) != 0)\r
+                               {\r
+                                       b = true;\r
+                               }\r
+                               CfgAddBool(current, name, b);\r
+                       }\r
+                       if (!StrCmpi(token->Token[0], TAG_BYTE))\r
+                       {\r
+                               // byte\r
+                               char *unescaped_b64 = CfgUnescape(data);\r
+                               void *tmp = Malloc(StrLen(unescaped_b64) * 4 + 64);\r
+                               int size = B64_Decode(tmp, unescaped_b64, StrLen(unescaped_b64));\r
+                               CfgAddByte(current, name, tmp, size);\r
+                               Free(tmp);\r
+                               Free(unescaped_b64);\r
+                       }\r
+\r
+                       Free(name);\r
+               }\r
+       }\r
+\r
+       // トークンの解放\r
+       FreeToken(token);\r
+\r
+       Free(buf);\r
+\r
+       return ret;\r
+}\r
+\r
+// ストリームテキストをフォルダに変換\r
+FOLDER *CfgBufTextToFolder(BUF *b)\r
+{\r
+       FOLDER *f, *c;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // root フォルダから再帰的に読み込む\r
+       c = CfgCreateFolder(NULL, "tmp");\r
+\r
+       while (true)\r
+       {\r
+               // テキストストリームを読み込む\r
+               if (CfgReadNextTextBUF(b, c) == false)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       // root フォルダの取得\r
+       f = CfgGetFolder(c, TAG_ROOT);\r
+       if (f == NULL)\r
+       {\r
+               // root フォルダが見つからない\r
+               CfgDeleteFolder(c);\r
+               return NULL;\r
+       }\r
+\r
+       // tmp フォルダから root への参照を削除\r
+       Delete(c->Folders, f);\r
+       f->Parent = NULL;\r
+\r
+       // tmp フォルダを削除\r
+       CfgDeleteFolder(c);\r
+\r
+       // root フォルダを返す\r
+       return f;\r
+}\r
+\r
+// 次のフォルダを読み込む\r
+void CfgReadNextFolderBin(BUF *b, FOLDER *parent)\r
+{\r
+       char name[MAX_SIZE];\r
+       FOLDER *f;\r
+       UINT n, i;\r
+       UINT size;\r
+       UCHAR *buf;\r
+       wchar_t *string;\r
+       // 引数チェック\r
+       if (b == NULL || parent == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // フォルダ名\r
+       ReadBufStr(b, name, sizeof(name));\r
+       f = CfgCreateFolder(parent, name);\r
+\r
+       // サブフォルダ数\r
+       n = ReadBufInt(b);\r
+       for (i = 0;i < n;i++)\r
+       {\r
+               // サブフォルダ\r
+               CfgReadNextFolderBin(b, f);\r
+       }\r
+\r
+       // アイテム数\r
+       n = ReadBufInt(b);\r
+       for (i = 0;i < n;i++)\r
+       {\r
+               UINT type;\r
+\r
+               // 名前\r
+               ReadBufStr(b, name, sizeof(name));\r
+               // 種類\r
+               type = ReadBufInt(b);\r
+\r
+               switch (type)\r
+               {\r
+               case ITEM_TYPE_INT:\r
+                       // int\r
+                       CfgAddInt(f, name, ReadBufInt(b));\r
+                       break;\r
+\r
+               case ITEM_TYPE_INT64:\r
+                       // int64\r
+                       CfgAddInt64(f, name, ReadBufInt64(b));\r
+                       break;\r
+\r
+               case ITEM_TYPE_BYTE:\r
+                       // data\r
+                       size = ReadBufInt(b);\r
+                       buf = ZeroMalloc(size);\r
+                       ReadBuf(b, buf, size);\r
+                       CfgAddByte(f, name, buf, size);\r
+                       Free(buf);\r
+                       break;\r
+\r
+               case ITEM_TYPE_STRING:\r
+                       // string\r
+                       size = ReadBufInt(b);\r
+                       buf = ZeroMalloc(size + 1);\r
+                       ReadBuf(b, buf, size);\r
+                       string = ZeroMalloc(CalcUtf8ToUni(buf, StrLen(buf)) + 4);\r
+                       Utf8ToUni(string, 0, buf, StrLen(buf));\r
+                       CfgAddUniStr(f, name, string);\r
+                       Free(string);\r
+                       Free(buf);\r
+                       break;\r
+\r
+               case ITEM_TYPE_BOOL:\r
+                       // bool\r
+                       CfgAddBool(f, name, ReadBufInt(b) == 0 ? false : true);\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// バイナリをフォルダに変換\r
+FOLDER *CfgBufBinToFolder(BUF *b)\r
+{\r
+       FOLDER *f, *c;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 一時フォルダを作成\r
+       c = CfgCreateFolder(NULL, "tmp");\r
+\r
+       // バイナリを読み込む\r
+       CfgReadNextFolderBin(b, c);\r
+\r
+       // root の取得\r
+       f = CfgGetFolder(c, TAG_ROOT);\r
+       if (f == NULL)\r
+       {\r
+               // 見つからない\r
+               CfgDeleteFolder(c);\r
+               return NULL;\r
+       }\r
+\r
+       Delete(c->Folders, f);\r
+       f->Parent = NULL;\r
+\r
+       CfgDeleteFolder(c);\r
+\r
+       return f;\r
+}\r
+\r
+// フォルダをバイナリに変換\r
+BUF *CfgFolderToBufBin(FOLDER *f)\r
+{\r
+       BUF *b;\r
+       UCHAR hash[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+\r
+       // ヘッダ\r
+       WriteBuf(b, TAG_BINARY, 8);\r
+\r
+       // ハッシュ領域\r
+       Zero(hash, sizeof(hash));\r
+       WriteBuf(b, hash, sizeof(hash));\r
+\r
+       // ルートフォルダを出力 (再帰)\r
+       CfgOutputFolderBin(b, f);\r
+\r
+       // ハッシュ\r
+       Hash(((UCHAR *)b->Buf) + 8, ((UCHAR *)b->Buf) + 8 + SHA1_SIZE, b->Size - 8 - SHA1_SIZE, true);\r
+\r
+       return b;\r
+}\r
+\r
+// フォルダをストリームテキストに変換\r
+BUF *CfgFolderToBufText(FOLDER *f)\r
+{\r
+       return CfgFolderToBufTextEx(f, false);\r
+}\r
+BUF *CfgFolderToBufTextEx(FOLDER *f, bool no_banner)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // ストリーム作成\r
+       b = NewBuf();\r
+\r
+       // 著作権情報\r
+       if (no_banner == false)\r
+       {\r
+               WriteBuf(b, TAG_CPYRIGHT, StrLen(TAG_CPYRIGHT));\r
+       }\r
+\r
+       // ルートフォルダを出力 (再帰)\r
+       CfgOutputFolderText(b, f, 0);\r
+\r
+       return b;\r
+}\r
+\r
+// フォルダ内容を出力 (フォルダを列挙)\r
+bool CfgEnumFolderProc(FOLDER *f, void *param)\r
+{\r
+       CFG_ENUM_PARAM *p;\r
+       // 引数チェック\r
+       if (f == NULL || param == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = (CFG_ENUM_PARAM *)param;\r
+       // フォルダ内容を出力 (再帰)\r
+       CfgOutputFolderText(p->b, f, p->depth);\r
+\r
+       return true;\r
+}\r
+\r
+// アイテム内容を出力 (列挙)\r
+bool CfgEnumItemProc(ITEM *t, void *param)\r
+{\r
+       CFG_ENUM_PARAM *p;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = (CFG_ENUM_PARAM *)param;\r
+       CfgAddItemText(p->b, t, p->depth);\r
+\r
+       return true;\r
+}\r
+\r
+// フォルダ内容を出力 (再帰、バイナリ)\r
+void CfgOutputFolderBin(BUF *b, FOLDER *f)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (b == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // フォルダ名\r
+       WriteBufStr(b, f->Name);\r
+\r
+       // サブフォルダ個数\r
+       WriteBufInt(b, LIST_NUM(f->Folders));\r
+\r
+       // サブフォルダ\r
+       for (i = 0;i < LIST_NUM(f->Folders);i++)\r
+       {\r
+               FOLDER *sub = LIST_DATA(f->Folders, i);\r
+               CfgOutputFolderBin(b, sub);\r
+\r
+               if ((i % 100) == 99)\r
+               {\r
+                       YieldCpu();\r
+               }\r
+       }\r
+\r
+       // アイテム個数\r
+       WriteBufInt(b, LIST_NUM(f->Items));\r
+\r
+       // アイテム\r
+       for (i = 0;i < LIST_NUM(f->Items);i++)\r
+       {\r
+               char *utf8;\r
+               UINT utf8_size;\r
+               ITEM *t = LIST_DATA(f->Items, i);\r
+\r
+               // アイテム名\r
+               WriteBufStr(b, t->Name);\r
+\r
+               // 型\r
+               WriteBufInt(b, t->Type);\r
+\r
+               switch (t->Type)\r
+               {\r
+               case ITEM_TYPE_INT:\r
+                       // 整数\r
+                       WriteBufInt(b, *((UINT *)t->Buf));\r
+                       break;\r
+\r
+               case ITEM_TYPE_INT64:\r
+                       // 64bit 整数\r
+                       WriteBufInt64(b, *((UINT64 *)t->Buf));\r
+                       break;\r
+\r
+               case ITEM_TYPE_BYTE:\r
+                       // データサイズ\r
+                       WriteBufInt(b, t->size);\r
+                       // データ\r
+                       WriteBuf(b, t->Buf, t->size);\r
+                       break;\r
+\r
+               case ITEM_TYPE_STRING:\r
+                       // 文字列\r
+                       utf8_size = CalcUniToUtf8((wchar_t *)t->Buf) + 1;\r
+                       utf8 = ZeroMalloc(utf8_size);\r
+                       UniToUtf8(utf8, utf8_size, (wchar_t *)t->Buf);\r
+                       WriteBufInt(b, StrLen(utf8));\r
+                       WriteBuf(b, utf8, StrLen(utf8));\r
+                       Free(utf8);\r
+                       break;\r
+\r
+               case ITEM_TYPE_BOOL:\r
+                       // ブール型\r
+                       if (*((bool *)t->Buf) == false)\r
+                       {\r
+                               WriteBufInt(b, 0);\r
+                       }\r
+                       else\r
+                       {\r
+                               WriteBufInt(b, 1);\r
+                       }\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// フォルダ内容を出力 (再帰、テキスト)\r
+void CfgOutputFolderText(BUF *b, FOLDER *f, UINT depth)\r
+{\r
+       CFG_ENUM_PARAM p;\r
+       // 引数チェック\r
+       if (b == NULL || f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // フォルダの開始を出力\r
+       CfgAddDeclare(b, f->Name, depth);\r
+       depth++;\r
+\r
+       Zero(&p, sizeof(CFG_ENUM_PARAM));\r
+       p.depth = depth;\r
+       p.b = b;\r
+       p.f = f;\r
+\r
+       // アイテム一覧を列挙\r
+       CfgEnumItem(f, CfgEnumItemProc, &p);\r
+\r
+       if (LIST_NUM(f->Folders) != 0 && LIST_NUM(f->Items) != 0)\r
+       {\r
+               WriteBuf(b, "\r\n", 2);\r
+       }\r
+\r
+       // フォルダ一覧を列挙\r
+       CfgEnumFolder(f, CfgEnumFolderProc, &p);\r
+       // フォルダの終了を出力\r
+       depth--;\r
+       CfgAddEnd(b, depth);\r
+\r
+       //WriteBuf(b, "\r\n", 2);\r
+}\r
+\r
+// アイテム内容を出力\r
+void CfgAddItemText(BUF *b, ITEM *t, UINT depth)\r
+{\r
+       char *data;\r
+       char *sub = NULL;\r
+       UINT len;\r
+       UINT size;\r
+       char *utf8;\r
+       UINT utf8_size;\r
+       wchar_t *string;\r
+       // 引数チェック\r
+       if (b == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // データ種類別に処理をする\r
+       data = NULL;\r
+       switch (t->Type)\r
+       {\r
+       case ITEM_TYPE_INT:\r
+               data = Malloc(32);\r
+               ToStr(data, *((UINT *)t->Buf));\r
+               break;\r
+\r
+       case ITEM_TYPE_INT64:\r
+               data = Malloc(64);\r
+               ToStr64(data, *((UINT64 *)t->Buf));\r
+               break;\r
+\r
+       case ITEM_TYPE_BYTE:\r
+               data = ZeroMalloc(t->size * 4 + 32);\r
+               len = B64_Encode(data, t->Buf, t->size);\r
+               data[len] = 0;\r
+               break;\r
+\r
+       case ITEM_TYPE_STRING:\r
+               string = t->Buf;\r
+               utf8_size = CalcUniToUtf8(string);\r
+               utf8_size++;\r
+               utf8 = ZeroMalloc(utf8_size);\r
+               utf8[0] = 0;\r
+               UniToUtf8(utf8, utf8_size, string);\r
+               size = utf8_size;\r
+               data = utf8;\r
+               break;\r
+\r
+       case ITEM_TYPE_BOOL:\r
+               size = 32;\r
+               data = Malloc(size);\r
+               if (*((bool *)t->Buf) == false)\r
+               {\r
+                       StrCpy(data, size, TAG_FALSE);\r
+               }\r
+               else\r
+               {\r
+                       StrCpy(data, size, TAG_TRUE);\r
+               }\r
+               break;\r
+       }\r
+       if (data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // データ行を出力\r
+       CfgAddData(b, t->Type, t->Name, data, sub, depth);\r
+\r
+       // メモリ解放\r
+       Free(data);\r
+       if (sub != NULL)\r
+       {\r
+               Free(sub);\r
+       }\r
+}\r
+\r
+// データ行を出力\r
+void CfgAddData(BUF *b, UINT type, char *name, char *data, char *sub, UINT depth)\r
+{\r
+       char *tmp;\r
+       char *name2;\r
+       char *data2;\r
+       char *sub2 = NULL;\r
+       UINT tmp_size;\r
+       // 引数チェック\r
+       if (b == NULL || type == 0 || name == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       name2 = CfgEscape(name);\r
+       data2 = CfgEscape(data);\r
+       if (sub != NULL)\r
+       {\r
+               sub2 = CfgEscape(sub);\r
+       }\r
+\r
+       tmp_size = StrLen(name2) + StrLen(data2) + 2 + 64 + 1;\r
+       tmp = Malloc(tmp_size);\r
+\r
+       if (sub2 != NULL)\r
+       {\r
+               StrCpy(tmp, tmp_size, CfgTypeToStr(type));\r
+               StrCat(tmp, tmp_size, " ");\r
+               StrCat(tmp, tmp_size, name2);\r
+               StrCat(tmp, tmp_size, " ");\r
+               StrCat(tmp, tmp_size, data2);\r
+               StrCat(tmp, tmp_size, " ");\r
+               StrCat(tmp, tmp_size, sub2);\r
+       }\r
+       else\r
+       {\r
+               StrCpy(tmp, tmp_size, CfgTypeToStr(type));\r
+               StrCat(tmp, tmp_size, " ");\r
+               StrCat(tmp, tmp_size, name2);\r
+               StrCat(tmp, tmp_size, " ");\r
+               StrCat(tmp, tmp_size, data2);\r
+       }\r
+\r
+       Free(name2);\r
+       Free(data2);\r
+       if (sub2 != NULL)\r
+       {\r
+               Free(sub2);\r
+       }\r
+       CfgAddLine(b, tmp, depth);\r
+       Free(tmp);\r
+}\r
+\r
+// データ種類文字列を整数値に変換\r
+UINT CfgStrToType(char *str)\r
+{\r
+       if (!StrCmpi(str, TAG_INT)) return ITEM_TYPE_INT;\r
+       if (!StrCmpi(str, TAG_INT64)) return ITEM_TYPE_INT64;\r
+       if (!StrCmpi(str, TAG_BYTE)) return ITEM_TYPE_BYTE;\r
+       if (!StrCmpi(str, TAG_STRING)) return ITEM_TYPE_STRING;\r
+       if (!StrCmpi(str, TAG_BOOL)) return ITEM_TYPE_BOOL;\r
+       return 0;\r
+}\r
+\r
+// データの種類を文字列に変換\r
+char *CfgTypeToStr(UINT type)\r
+{\r
+       switch (type)\r
+       {\r
+       case ITEM_TYPE_INT:\r
+               return TAG_INT;\r
+       case ITEM_TYPE_INT64:\r
+               return TAG_INT64;\r
+       case ITEM_TYPE_BYTE:\r
+               return TAG_BYTE;\r
+       case ITEM_TYPE_STRING:\r
+               return TAG_STRING;\r
+       case ITEM_TYPE_BOOL:\r
+               return TAG_BOOL;\r
+       }\r
+       return NULL;\r
+}\r
+\r
+// End 行を出力\r
+void CfgAddEnd(BUF *b, UINT depth)\r
+{\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CfgAddLine(b, "}", depth);\r
+//     CfgAddLine(b, TAG_END, depth);\r
+}\r
+\r
+// Declare 行を出力\r
+void CfgAddDeclare(BUF *b, char *name, UINT depth)\r
+{\r
+       char *tmp;\r
+       char *name2;\r
+       UINT tmp_size;\r
+       // 引数チェック\r
+       if (b == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       name2 = CfgEscape(name);\r
+\r
+       tmp_size = StrLen(name2) + 2 + StrLen(TAG_DECLARE);\r
+       tmp = Malloc(tmp_size);\r
+\r
+       Format(tmp, 0, "%s %s", TAG_DECLARE, name2);\r
+       CfgAddLine(b, tmp, depth);\r
+       CfgAddLine(b, "{", depth);\r
+       Free(tmp);\r
+       Free(name2);\r
+}\r
+\r
+// 1 行を出力\r
+void CfgAddLine(BUF *b, char *str, UINT depth)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < depth;i++)\r
+       {\r
+               WriteBuf(b, "\t", 1);\r
+       }\r
+       WriteBuf(b, str, StrLen(str));\r
+       WriteBuf(b, "\r\n", 2);\r
+}\r
+\r
+// フォルダをストリームに変換\r
+BUF *CfgFolderToBuf(FOLDER *f, bool textmode)\r
+{\r
+       return CfgFolderToBufEx(f, textmode, false);\r
+}\r
+BUF *CfgFolderToBufEx(FOLDER *f, bool textmode, bool no_banner)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (textmode)\r
+       {\r
+               return CfgFolderToBufTextEx(f, no_banner);\r
+       }\r
+       else\r
+       {\r
+               return CfgFolderToBufBin(f);;\r
+       }\r
+}\r
+\r
+// 文字列のエスケープ復元\r
+char *CfgUnescape(char *str)\r
+{\r
+       char *tmp;\r
+       char *ret;\r
+       char tmp2[16];\r
+       UINT len, wp, i;\r
+       UINT code;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       tmp = ZeroMalloc(len + 1);\r
+       wp = 0;\r
+       if (len == 1 && str[0] == '$')\r
+       {\r
+               // 空文字\r
+               tmp[0] = 0;\r
+       }\r
+       else\r
+       {\r
+               for (i = 0;i < len;i++)\r
+               {\r
+                       if (str[i] != '$')\r
+                       {\r
+                               tmp[wp++] = str[i];\r
+                       }\r
+                       else\r
+                       {\r
+                               tmp2[0] = '0';\r
+                               tmp2[1] = 'x';\r
+                               tmp2[2] = str[i + 1];\r
+                               tmp2[3] = str[i + 2];\r
+                               i += 2;\r
+                               tmp2[4] = 0;\r
+                               code = ToInt(tmp2);\r
+                               tmp[wp++] = (char)code;\r
+                       }\r
+               }\r
+       }\r
+       ret = Malloc(StrLen(tmp) + 1);\r
+       StrCpy(ret, StrLen(tmp) + 1, tmp);\r
+       Free(tmp);\r
+       return ret;\r
+}\r
+\r
+// 文字列のエスケープ\r
+char *CfgEscape(char *str)\r
+{\r
+       char *tmp;\r
+       char *ret;\r
+       char tmp2[16];\r
+       UINT len;\r
+       UINT wp, i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       tmp = ZeroMalloc(len * 3 + 2);\r
+       if (len == 0)\r
+       {\r
+               // 空文字\r
+               StrCpy(tmp, (len * 3 + 2), "$");\r
+       }\r
+       else\r
+       {\r
+               // 空文字以外\r
+               wp = 0;\r
+               for (i = 0;i < len;i++)\r
+               {\r
+                       if (CfgCheckCharForName(str[i]))\r
+                       {\r
+                               tmp[wp++] = str[i];\r
+                       }\r
+                       else\r
+                       {\r
+                               tmp[wp++] = '$';\r
+                               Format(tmp2, sizeof(tmp2), "%02X", (UINT)str[i]);\r
+                               tmp[wp++] = tmp2[0];\r
+                               tmp[wp++] = tmp2[1];\r
+                       }\r
+               }\r
+       }\r
+       ret = Malloc(StrLen(tmp) + 1);\r
+       StrCpy(ret, 0, tmp);\r
+       Free(tmp);\r
+       return ret;\r
+}\r
+\r
+// 名前に使用することができる文字かどうかチェック\r
+bool CfgCheckCharForName(char c)\r
+{\r
+       if (c >= 0 && c <= 31)\r
+       {\r
+               return false;\r
+       }\r
+       if (c == ' ' || c == '\t')\r
+       {\r
+               return false;\r
+       }\r
+       if (c == '$')\r
+       {\r
+               return false;\r
+       }\r
+       return true;\r
+}\r
+\r
+// string 型の値の取得\r
+bool CfgGetStr(FOLDER *f, char *name, char *str, UINT size)\r
+{\r
+       wchar_t *tmp;\r
+       UINT tmp_size;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       str[0] = 0;\r
+\r
+       // unicode 文字列を一時的に取得する\r
+       tmp_size = size * 4 + 10; // 一応これくらいとっておく\r
+       tmp = Malloc(tmp_size);\r
+       if (CfgGetUniStr(f, name, tmp, tmp_size) == false)\r
+       {\r
+               // 失敗\r
+               Free(tmp);\r
+               return false;\r
+       }\r
+\r
+       // ANSI 文字列にコピー\r
+       UniToStr(str, size, tmp);\r
+       Free(tmp);\r
+\r
+       return true;\r
+}\r
+\r
+// unicode_string 型の値の取得\r
+bool CfgGetUniStr(FOLDER *f, char *name, wchar_t *str, UINT size)\r
+{\r
+       ITEM *t;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       str[0] = 0;\r
+\r
+       t = CfgFindItem(f, name);\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (t->Type != ITEM_TYPE_STRING)\r
+       {\r
+               return false;\r
+       }\r
+       UniStrCpy(str, size, t->Buf);\r
+       return true;\r
+}\r
+\r
+// フォルダの存在を確認\r
+bool CfgIsFolder(FOLDER *f, char *name)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return (CfgGetFolder(f, name) == NULL) ? false : true;\r
+}\r
+\r
+// アイテムの存在を確認\r
+bool CfgIsItem(FOLDER *f, char *name)\r
+{\r
+       ITEM *t;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       t = CfgFindItem(f, name);\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// byte[] 型を BUF で取得\r
+BUF *CfgGetBuf(FOLDER *f, char *name)\r
+{\r
+       ITEM *t;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t = CfgFindItem(f, name);\r
+       if (t == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, t->Buf, t->size);\r
+       SeekBuf(b, 0, 0);\r
+\r
+       return b;\r
+}\r
+\r
+// byte[] 型の値の取得\r
+UINT CfgGetByte(FOLDER *f, char *name, void *buf, UINT size)\r
+{\r
+       ITEM *t;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL || buf == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       t = CfgFindItem(f, name);\r
+       if (t == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (t->Type != ITEM_TYPE_BYTE)\r
+       {\r
+               return 0;\r
+       }\r
+       if (t->size <= size)\r
+       {\r
+               Copy(buf, t->Buf, t->size);\r
+               return t->size;\r
+       }\r
+       else\r
+       {\r
+               Copy(buf, t->Buf, size);\r
+               return t->size;\r
+       }\r
+}\r
+\r
+// int64 型の値の取得\r
+UINT64 CfgGetInt64(FOLDER *f, char *name)\r
+{\r
+       ITEM *t;\r
+       UINT64 *ret;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       t = CfgFindItem(f, name);\r
+       if (t == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (t->Type != ITEM_TYPE_INT64)\r
+       {\r
+               return 0;\r
+       }\r
+       if (t->size != sizeof(UINT64))\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = (UINT64 *)t->Buf;\r
+       return *ret;\r
+}\r
+\r
+// bool 型の値の取得\r
+bool CfgGetBool(FOLDER *f, char *name)\r
+{\r
+       ITEM *t;\r
+       bool *ret;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       t = CfgFindItem(f, name);\r
+       if (t == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (t->Type != ITEM_TYPE_BOOL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (t->size != sizeof(bool))\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = (bool *)t->Buf;\r
+       if (*ret == false)\r
+       {\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               return true;\r
+       }\r
+}\r
+\r
+// int 型の値の取得\r
+UINT CfgGetInt(FOLDER *f, char *name)\r
+{\r
+       ITEM *t;\r
+       UINT *ret;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       t = CfgFindItem(f, name);\r
+       if (t == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (t->Type != ITEM_TYPE_INT)\r
+       {\r
+               return 0;\r
+       }\r
+       if (t->size != sizeof(UINT))\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = (UINT *)t->Buf;\r
+       return *ret;\r
+}\r
+\r
+// アイテムの検索\r
+ITEM *CfgFindItem(FOLDER *parent, char *name)\r
+{\r
+       ITEM *t, tt;\r
+       // 引数チェック\r
+       if (parent == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       tt.Name = ZeroMalloc(StrLen(name) + 1);\r
+       StrCpy(tt.Name, 0, name);\r
+       t = Search(parent->Items, &tt);\r
+       Free(tt.Name);\r
+\r
+       return t;\r
+}\r
+\r
+// フォルダの取得\r
+FOLDER *CfgGetFolder(FOLDER *parent, char *name)\r
+{\r
+       return CfgFindFolder(parent, name);\r
+}\r
+\r
+// フォルダの検索\r
+FOLDER *CfgFindFolder(FOLDER *parent, char *name)\r
+{\r
+       FOLDER *f, ff;\r
+       // 引数チェック\r
+       if (parent == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ff.Name = ZeroMalloc(StrLen(name) + 1);\r
+       StrCpy(ff.Name, 0, name);\r
+       f = Search(parent->Folders, &ff);\r
+       Free(ff.Name);\r
+\r
+       return f;\r
+}\r
+\r
+// string 型の追加\r
+ITEM *CfgAddStr(FOLDER *f, char *name, char *str)\r
+{\r
+       wchar_t *tmp;\r
+       UINT tmp_size;\r
+       ITEM *t;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL || str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // Unicode 文字列に変換\r
+       tmp_size = CalcStrToUni(str);\r
+       if (tmp_size == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+       tmp = Malloc(tmp_size);\r
+       StrToUni(tmp, tmp_size, str);\r
+       t = CfgAddUniStr(f, name, tmp);\r
+       Free(tmp);\r
+\r
+       return t;\r
+}\r
+\r
+// unicode_string 型の追加\r
+ITEM *CfgAddUniStr(FOLDER *f, char *name, wchar_t *str)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL || str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return CfgCreateItem(f, name, ITEM_TYPE_STRING, str, UniStrSize(str));\r
+}\r
+\r
+// バイナリの追加\r
+ITEM *CfgAddBuf(FOLDER *f, char *name, BUF *b)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL || b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       return CfgAddByte(f, name, b->Buf, b->Size);\r
+}\r
+\r
+// バイト型の追加\r
+ITEM *CfgAddByte(FOLDER *f, char *name, void *buf, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL || buf == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       return CfgCreateItem(f, name, ITEM_TYPE_BYTE, buf, size);\r
+}\r
+\r
+// 64bit 整数型の追加\r
+ITEM *CfgAddInt64(FOLDER *f, char *name, UINT64 i)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       return CfgCreateItem(f, name, ITEM_TYPE_INT64, &i, sizeof(UINT64));\r
+}\r
+\r
+// IP アドレス型の取得\r
+bool CfgGetIp(FOLDER *f, char *name, struct IP *ip)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL || ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(ip, sizeof(IP));\r
+\r
+       if (CfgGetStr(f, name, tmp, sizeof(tmp)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrToIP(ip, tmp) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+UINT CfgGetIp32(FOLDER *f, char *name)\r
+{\r
+       IP p;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (CfgGetIp(f, name, &p) == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return IPToUINT(&p);\r
+}\r
+bool CfgGetIp6Addr(FOLDER *f, char *name, IPV6_ADDR *addr)\r
+{\r
+       IP ip;\r
+       // 引数チェック\r
+       Zero(addr, sizeof(IPV6_ADDR));\r
+       if (f == NULL || name == NULL || addr == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (CfgGetIp(f, name, &ip) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsIP6(&ip) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IPToIPv6Addr(addr, &ip) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// IP アドレス型の追加\r
+ITEM *CfgAddIp(FOLDER *f, char *name, struct IP *ip)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL || ip == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       IPToStr(tmp, sizeof(tmp), ip);\r
+\r
+       return CfgAddStr(f, name, tmp);\r
+}\r
+ITEM *CfgAddIp32(FOLDER *f, char *name, UINT ip)\r
+{\r
+       IP p;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       UINTToIP(&p, ip);\r
+\r
+       return CfgAddIp(f, name, &p);\r
+}\r
+ITEM *CfgAddIp6Addr(FOLDER *f, char *name, IPV6_ADDR *addr)\r
+{\r
+       IP ip;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL || addr == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       IPv6AddrToIP(&ip, addr);\r
+\r
+       return CfgAddIp(f, name, &ip);\r
+}\r
+\r
+// 整数型の追加\r
+ITEM *CfgAddInt(FOLDER *f, char *name, UINT i)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       return CfgCreateItem(f, name, ITEM_TYPE_INT, &i, sizeof(UINT));\r
+}\r
+\r
+// bool 型の追加\r
+ITEM *CfgAddBool(FOLDER *f, char *name, bool b)\r
+{\r
+       bool v;\r
+       // 引数チェック\r
+       if (f == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       v = b ? 1 : 0;\r
+       return CfgCreateItem(f, name, ITEM_TYPE_BOOL, &b, sizeof(bool));\r
+}\r
+\r
+// アイテム名の比較関数\r
+int CmpItemName(void *p1, void *p2)\r
+{\r
+       ITEM *f1, *f2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       f1 = *(ITEM **)p1;\r
+       f2 = *(ITEM **)p2;\r
+       if (f1 == NULL || f2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return StrCmpi(f1->Name, f2->Name);\r
+}\r
+\r
+// フォルダ名の比較関数\r
+int CmpFolderName(void *p1, void *p2)\r
+{\r
+       FOLDER *f1, *f2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       f1 = *(FOLDER **)p1;\r
+       f2 = *(FOLDER **)p2;\r
+       if (f1 == NULL || f2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return StrCmpi(f1->Name, f2->Name);\r
+}\r
+\r
+// アイテムの列挙\r
+void CfgEnumItem(FOLDER *f, ENUM_ITEM proc, void *param)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (f == NULL || proc == NULL)\r
+       {\r
+               return;\r
+       }\r
+       \r
+       for (i = 0;i < LIST_NUM(f->Items);i++)\r
+       {\r
+               ITEM *tt = LIST_DATA(f->Items, i);\r
+               if (proc(tt, param) == false)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// フォルダを列挙してトークンリストに格納\r
+TOKEN_LIST *CfgEnumFolderToTokenList(FOLDER *f)\r
+{\r
+       TOKEN_LIST *t, *ret;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(f->Folders);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               FOLDER *ff = LIST_DATA(f->Folders, i);\r
+               t->Token[i] = CopyStr(ff->Name);\r
+       }\r
+\r
+       ret = UniqueToken(t);\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// アイテムを列挙してトークンリストに格納\r
+TOKEN_LIST *CfgEnumItemToTokenList(FOLDER *f)\r
+{\r
+       TOKEN_LIST *t, *ret;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(f->Items);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               FOLDER *ff = LIST_DATA(f->Items, i);\r
+               t->Token[i] = CopyStr(ff->Name);\r
+       }\r
+\r
+       ret = UniqueToken(t);\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// フォルダの列挙\r
+void CfgEnumFolder(FOLDER *f, ENUM_FOLDER proc, void *param)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (f == NULL || proc == NULL)\r
+       {\r
+               return;\r
+       }\r
+       \r
+       for (i = 0;i < LIST_NUM(f->Folders);i++)\r
+       {\r
+               FOLDER *ff = LIST_DATA(f->Folders, i);\r
+               if (proc(ff, param) == false)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               if ((i % 100) == 99)\r
+               {\r
+                       YieldCpu();\r
+               }\r
+       }\r
+}\r
+\r
+// アイテムの作成\r
+ITEM *CfgCreateItem(FOLDER *parent, char *name, UINT type, void *buf, UINT size)\r
+{\r
+       UINT name_size;\r
+       ITEM *t;\r
+#ifdef CHECK_CFG_NAME_EXISTS\r
+       ITEM tt;\r
+#endif // CHECK_CFG_NAME_EXISTS\r
+       // 引数チェック\r
+       if (parent == NULL || name == NULL || type == 0 || buf == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       name_size = StrLen(name) + 1;\r
+\r
+#ifdef CHECK_CFG_NAME_EXISTS\r
+\r
+       // すでに同名のアイテムが無いかどうか確認\r
+       tt.Name = ZeroMalloc(name_size);\r
+       StrCpy(tt.Name, 0, name);\r
+       t = Search(parent->Items, &tt);\r
+       Free(tt.Name);\r
+       if (t != NULL)\r
+       {\r
+               // 重複している\r
+               return NULL;\r
+       }\r
+\r
+#endif // CHECK_CFG_NAME_EXISTS\r
+\r
+       t = ZeroMalloc(sizeof(ITEM));\r
+       t->Buf = Malloc(size);\r
+       Copy(t->Buf, buf, size);\r
+       t->Name = ZeroMalloc(name_size);\r
+       StrCpy(t->Name, 0, name);\r
+       t->Type = type;\r
+       t->size = size;\r
+       t->Parent = parent;\r
+       \r
+       // 親のリストに追加\r
+       Insert(parent->Items, t);\r
+\r
+       return t;\r
+}\r
+\r
+// アイテムの削除\r
+void CfgDeleteItem(ITEM *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 親のリストから削除\r
+       Delete(t->Parent->Items, t);\r
+\r
+       // メモリ解放\r
+       Free(t->Buf);\r
+       Free(t->Name);\r
+       Free(t);\r
+}\r
+\r
+\r
+// フォルダの削除\r
+void CfgDeleteFolder(FOLDER *f)\r
+{\r
+       FOLDER **ff;\r
+       ITEM **tt;\r
+       UINT num, i;\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // サブフォルダをすべて削除\r
+       num = LIST_NUM(f->Folders);\r
+       ff = Malloc(sizeof(FOLDER *) * num);\r
+       Copy(ff, f->Folders->p, sizeof(FOLDER *) * num);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               CfgDeleteFolder(ff[i]);\r
+       }\r
+       Free(ff);\r
+\r
+       // アイテムをすべて削除\r
+       num = LIST_NUM(f->Items);\r
+       tt = Malloc(sizeof(ITEM *) * num);\r
+       Copy(tt, f->Items->p, sizeof(ITEM *) * num);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               CfgDeleteItem(tt[i]);\r
+       }\r
+       Free(tt);\r
+\r
+       // メモリ解放\r
+       Free(f->Name);\r
+       // 親のリストから削除\r
+       if (f->Parent != NULL)\r
+       {\r
+               Delete(f->Parent->Folders, f);\r
+       }\r
+       // リストの解放\r
+       ReleaseList(f->Folders);\r
+       ReleaseList(f->Items);\r
+\r
+       // 本体のメモリの解放\r
+       Free(f);\r
+}\r
+\r
+// ルートの作成\r
+FOLDER *CfgCreateRoot()\r
+{\r
+       return CfgCreateFolder(NULL, TAG_ROOT);\r
+}\r
+\r
+// フォルダの作成\r
+FOLDER *CfgCreateFolder(FOLDER *parent, char *name)\r
+{\r
+       UINT size;\r
+       FOLDER *f;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = StrLen(name) + 1;\r
+\r
+#ifdef CHECK_CFG_NAME_EXISTS\r
+\r
+       // 親のリストの名前を検査\r
+       if (parent != NULL)\r
+       {\r
+               FOLDER ff;\r
+               ff.Name = ZeroMalloc(size);\r
+               StrCpy(ff.Name, 0, name);\r
+               f = Search(parent->Folders, &ff);\r
+               Free(ff.Name);\r
+               if (f != NULL)\r
+               {\r
+                       // 既に同じ名前のフォルダが存在する\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+#endif // CHECK_CFG_NAME_EXISTS\r
+\r
+       f = ZeroMalloc(sizeof(FOLDER));\r
+       f->Items = NewListFast(CmpItemName);\r
+       f->Folders = NewListFast(CmpFolderName);\r
+       f->Name = ZeroMalloc(size);\r
+       StrCpy(f->Name, 0, name);\r
+       f->Parent = parent;\r
+\r
+       // 親のリストに追加\r
+       if (f->Parent != NULL)\r
+       {\r
+               Insert(f->Parent->Folders, f);\r
+       }\r
+       return f;\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Cfg.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Cfg.h
new file mode 100644 (file)
index 0000000..a2febb0
--- /dev/null
@@ -0,0 +1,239 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Cfg.h\r
+// Cfg.c のヘッダ\r
+\r
+#ifndef        CFG_H\r
+#define        CFG_H\r
+\r
+// マクロ\r
+//#define      CHECK_CFG_NAME_EXISTS                   // 既存の名前との重複チェックを行う\r
+\r
+#define        SAVE_BINARY_FILE_NAME_SWITCH    L"@save_binary"\r
+\r
+// 定数\r
+#define        TAG_DECLARE                     "declare"\r
+#define        TAG_STRING                      "string"\r
+#define        TAG_INT                         "uint"\r
+#define        TAG_INT64                       "uint64"\r
+#define        TAG_BOOL                        "bool"\r
+#define        TAG_BYTE                        "byte"\r
+#define        TAG_TRUE                        "true"\r
+#define        TAG_FALSE                       "false"\r
+#define        TAG_END                         "end"\r
+#define        TAG_ROOT                        "root"\r
+\r
+#define        TAG_CPYRIGHT            "\xef\xbb\xbf# SoftEther UT-VPN Software Configuration File\r\n# \r\n# You can edit this file when the program is not working.\r\n# \r\n"\r
+#define        TAG_BINARY                      "SEVPN_DB"\r
+\r
+// データ型\r
+#define        ITEM_TYPE_INT           1               // int\r
+#define        ITEM_TYPE_INT64         2               // int64\r
+#define        ITEM_TYPE_BYTE          3               // byte\r
+#define        ITEM_TYPE_STRING        4               // string\r
+#define        ITEM_TYPE_BOOL          5               // bool\r
+\r
+// フォルダ\r
+struct FOLDER\r
+{\r
+       char *Name;                             // フォルダ名\r
+       LIST *Items;                    // アイテムのリスト\r
+       LIST *Folders;                  // サブフォルダ\r
+       struct FOLDER *Parent;  // 親フォルダ\r
+};\r
+\r
+// アイテム\r
+struct ITEM\r
+{\r
+       char *Name;                             // アイテム名\r
+       UINT Type;                              // データ型\r
+       void *Buf;                              // データ\r
+       UINT size;                              // データサイズ\r
+       FOLDER *Parent;                 // 親フォルダ\r
+};\r
+\r
+// 設定ファイルリーダライタ\r
+struct CFG_RW\r
+{\r
+       LOCK *lock;                             // ロック\r
+       char *FileName;                 // ファイル名 (ANSI)\r
+       wchar_t *FileNameW;             // ファイル名 (Unicode)\r
+       IO *Io;                                 // IO\r
+       UCHAR LashHash[SHA1_SIZE];      // 最後に書き込んだハッシュ値\r
+       bool DontBackup;                // バックアップを使用しない\r
+};\r
+\r
+typedef bool (*ENUM_FOLDER)(FOLDER *f, void *param);\r
+typedef bool (*ENUM_ITEM)(ITEM *t, void *param);\r
+\r
+// 列挙用のパラメータ\r
+struct CFG_ENUM_PARAM\r
+{\r
+       BUF *b;\r
+       FOLDER *f;\r
+       UINT depth;\r
+};\r
+\r
+int CmpItemName(void *p1, void *p2);\r
+int CmpFolderName(void *p1, void *p2);\r
+ITEM *CfgCreateItem(FOLDER *parent, char *name, UINT type, void *buf, UINT size);\r
+void CfgDeleteFolder(FOLDER *f);\r
+FOLDER *CfgCreateFolder(FOLDER *parent, char *name);\r
+void CfgEnumFolder(FOLDER *f, ENUM_FOLDER proc, void *param);\r
+TOKEN_LIST *CfgEnumFolderToTokenList(FOLDER *f);\r
+TOKEN_LIST *CfgEnumItemToTokenList(FOLDER *f);\r
+void CfgEnumItem(FOLDER *f, ENUM_ITEM proc, void *param);\r
+FOLDER *CfgFindFolder(FOLDER *parent, char *name);\r
+ITEM *CfgFindItem(FOLDER *parent, char *name);\r
+ITEM *CfgAddInt(FOLDER *f, char *name, UINT i);\r
+ITEM *CfgAddBool(FOLDER *f, char *name, bool b);\r
+ITEM *CfgAddInt64(FOLDER *f, char *name, UINT64 i);\r
+ITEM *CfgAddByte(FOLDER *f, char *name, void *buf, UINT size);\r
+ITEM *CfgAddBuf(FOLDER *f, char *name, BUF *b);\r
+ITEM *CfgAddStr(FOLDER *f, char *name, char *str);\r
+ITEM *CfgAddUniStr(FOLDER *f, char *name, wchar_t *str);\r
+FOLDER *CfgGetFolder(FOLDER *parent, char *name);\r
+UINT CfgGetInt(FOLDER *f, char *name);\r
+bool CfgGetBool(FOLDER *f, char *name);\r
+UINT64 CfgGetInt64(FOLDER *f, char *name);\r
+UINT CfgGetByte(FOLDER *f, char *name, void *buf, UINT size);\r
+BUF *CfgGetBuf(FOLDER *f, char *name);\r
+bool CfgGetStr(FOLDER *f, char *name, char *str, UINT size);\r
+bool CfgGetUniStr(FOLDER *f, char *name, wchar_t *str, UINT size);\r
+bool CfgIsItem(FOLDER *f, char *name);\r
+bool CfgIsFolder(FOLDER *f, char *name);\r
+void CfgTest();\r
+void CfgTest2(FOLDER *f, UINT n);\r
+char *CfgEscape(char *name);\r
+bool CfgCheckCharForName(char c);\r
+char *CfgUnescape(char *str);\r
+BUF *CfgFolderToBuf(FOLDER *f, bool textmode);\r
+BUF *CfgFolderToBufEx(FOLDER *f, bool textmode, bool no_banner);\r
+BUF *CfgFolderToBufText(FOLDER *f);\r
+BUF *CfgFolderToBufTextEx(FOLDER *f, bool no_banner);\r
+BUF *CfgFolderToBufBin(FOLDER *f);\r
+void CfgOutputFolderText(BUF *b, FOLDER *f, UINT depth);\r
+void CfgOutputFolderBin(BUF *b, FOLDER *f);\r
+void CfgAddLine(BUF *b, char *str, UINT depth);\r
+void CfgAddDeclare(BUF *b, char *name, UINT depth);\r
+void CfgAddEnd(BUF *b, UINT depth);\r
+void CfgAddData(BUF *b, UINT type, char *name, char *data, char *sub, UINT depth);\r
+UINT CfgStrToType(char *str);\r
+char *CfgTypeToStr(UINT type);\r
+void CfgAddItemText(BUF *b, ITEM *t, UINT depth);\r
+bool CfgEnumFolderProc(FOLDER *f, void *param);\r
+bool CfgEnumItemProc(ITEM *t, void *param);\r
+FOLDER *CfgBufTextToFolder(BUF *b);\r
+FOLDER *CfgBufBinToFolder(BUF *b);\r
+void CfgReadNextFolderBin(BUF *b, FOLDER *parent);\r
+char *CfgReadNextLine(BUF *b);\r
+bool CfgReadNextTextBuf(BUF *b, FOLDER *current);\r
+void CfgSave(FOLDER *f, char *name);\r
+void CfgSaveW(FOLDER *f, wchar_t *name);\r
+bool CfgSaveEx(CFG_RW *rw, FOLDER *f, char *name);\r
+bool CfgSaveExW(CFG_RW *rw, FOLDER *f, wchar_t *name);\r
+bool CfgSaveExW2(CFG_RW *rw, FOLDER *f, wchar_t *name, UINT *written_size);\r
+FOLDER *CfgRead(char *name);\r
+FOLDER *CfgReadW(wchar_t *name);\r
+FOLDER *CfgCreateRoot();\r
+void CfgTest();\r
+void CfgTest2(FOLDER *f, UINT n);\r
+CFG_RW *NewCfgRw(FOLDER **root, char *cfg_name);\r
+CFG_RW *NewCfgRwW(FOLDER **root, wchar_t *cfg_name);\r
+CFG_RW *NewCfgRwEx(FOLDER **root, char *cfg_name, bool dont_backup);\r
+CFG_RW *NewCfgRwExW(FOLDER **root, wchar_t *cfg_name, bool dont_backup);\r
+UINT SaveCfgRw(CFG_RW *rw, FOLDER *f);\r
+void FreeCfgRw(CFG_RW *rw);\r
+ITEM *CfgAddIp32(FOLDER *f, char *name, UINT ip);\r
+UINT CfgGetIp32(FOLDER *f, char *name);\r
+bool CfgGetIp6Addr(FOLDER *f, char *name, IPV6_ADDR *addr);\r
+ITEM *CfgAddIp6Addr(FOLDER *f, char *name, IPV6_ADDR *addr);\r
+bool FileCopy(char *src, char *dst);\r
+bool FileCopyW(wchar_t *src, wchar_t *dst);\r
+void BackupCfg(FOLDER *f, char *original);\r
+void BackupCfgW(FOLDER *f, wchar_t *original);\r
+\r
+#if    (!defined(CFG_C)) || (!defined(OS_UNIX))\r
+bool CfgGetIp(FOLDER *f, char *name, struct IP *ip);\r
+ITEM *CfgAddIp(FOLDER *f, char *name, struct IP *ip);\r
+#endif\r
+\r
+#endif // CFG_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Encrypt.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Encrypt.c
new file mode 100644 (file)
index 0000000..864b803
--- /dev/null
@@ -0,0 +1,3545 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Encrypt.c\r
+// 暗号化および電子証明書ルーチン\r
+\r
+#define        ENCRYPT_C\r
+\r
+#define        __WINCRYPT_H__\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <openssl/ssl.h>\r
+#include <openssl/err.h>\r
+#include <openssl/rand.h>\r
+#include <openssl/engine.h>\r
+#include <openssl/bio.h>\r
+#include <openssl/x509.h>\r
+#include <openssl/pkcs7.h>\r
+#include <openssl/pkcs12.h>\r
+#include <openssl/rc4.h>\r
+#include <openssl/md5.h>\r
+#include <openssl/sha.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+LOCK *openssl_lock = NULL;\r
+\r
+LOCK **ssl_lock_obj = NULL;\r
+UINT ssl_lock_num;\r
+static bool openssl_inited = false;\r
+\r
+// コールバック関数用\r
+typedef struct CB_PARAM\r
+{\r
+       char *password;\r
+} CB_PARAM;\r
+\r
+// 証明書が特定のディレクトリの CRL によって無効化されているかどうか確認する\r
+bool IsXRevoked(X *x)\r
+{\r
+       char dirname[MAX_PATH];\r
+       UINT i;\r
+       bool ret = false;\r
+       DIRLIST *t;\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       GetExeDir(dirname, sizeof(dirname));\r
+\r
+       // CRL ファイルの検索\r
+       t = EnumDir(dirname);\r
+\r
+       for (i = 0;i < t->NumFiles;i++)\r
+       {\r
+               char *name = t->File[i]->FileName;\r
+               if (t->File[i]->Folder == false)\r
+               {\r
+                       if (EndWith(name, ".crl"))\r
+                       {\r
+                               char filename[MAX_PATH];\r
+                               X_CRL *r;\r
+\r
+                               ConbinePath(filename, sizeof(filename), dirname, name);\r
+\r
+                               r = FileToXCrl(filename);\r
+\r
+                               if (r != NULL)\r
+                               {\r
+                                       if (IsXRevokedByXCrl(x, r))\r
+                                       {\r
+                                               ret = true;\r
+                                       }\r
+\r
+                                       FreeXCrl(r);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeDir(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// 証明書が CRL によって無効化されているかどうか確認する\r
+bool IsXRevokedByXCrl(X *x, X_CRL *r)\r
+{\r
+#ifdef OS_WIN32\r
+       X509_REVOKED tmp;\r
+       X509_CRL_INFO *info;\r
+       int index;\r
+       // 引数チェック\r
+       if (x == NULL || r == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&tmp, sizeof(tmp));\r
+       tmp.serialNumber = X509_get_serialNumber(x->x509);\r
+\r
+       info = r->Crl->crl;\r
+\r
+       if (sk_X509_REVOKED_is_sorted(info->revoked) == false)\r
+       {\r
+               sk_X509_REVOKED_sort(info->revoked);\r
+       }\r
+\r
+       index = sk_X509_REVOKED_find(info->revoked, &tmp);\r
+\r
+       if (index < 0)\r
+       {\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               return true;\r
+       }\r
+#else  // OS_WIN32\r
+       return false;\r
+#endif // OS_WIN32\r
+}\r
+\r
+// CRL の解放\r
+void FreeXCrl(X_CRL *r)\r
+{\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       X509_CRL_free(r->Crl);\r
+\r
+       Free(r);\r
+}\r
+\r
+// ファイルを CRL に変換\r
+X_CRL *FileToXCrl(char *filename)\r
+{\r
+       wchar_t *filename_w = CopyStrToUni(filename);\r
+       X_CRL *ret = FileToXCrlW(filename_w);\r
+\r
+       Free(filename_w);\r
+\r
+       return ret;\r
+}\r
+X_CRL *FileToXCrlW(wchar_t *filename)\r
+{\r
+       BUF *b;\r
+       X_CRL *r;\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = ReadDumpW(filename);\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       r = BufToXCrl(b);\r
+\r
+       FreeBuf(b);\r
+\r
+       return r;\r
+}\r
+\r
+// バッファを CRL に変換\r
+X_CRL *BufToXCrl(BUF *b)\r
+{\r
+       X_CRL *r;\r
+       X509_CRL *x509crl;\r
+       BIO *bio;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       bio = BufToBio(b);\r
+       if (bio == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       x509crl = NULL;\r
+\r
+       if (d2i_X509_CRL_bio(bio, &x509crl) == NULL || x509crl == NULL)\r
+       {\r
+               FreeBio(bio);\r
+               return NULL;\r
+       }\r
+\r
+       r = ZeroMalloc(sizeof(X_CRL));\r
+       r->Crl = x509crl;\r
+\r
+       FreeBio(bio);\r
+\r
+       return r;\r
+}\r
+\r
+// バッファを公開鍵に変換\r
+K *RsaBinToPublic(void *data, UINT size)\r
+{\r
+       RSA *rsa;\r
+       K *k;\r
+       BIO *bio;\r
+       // 引数チェック\r
+       if (data == NULL || size < 4)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       rsa = RSA_new();\r
+\r
+       if (rsa->e != NULL)\r
+       {\r
+               BN_free(rsa->e);\r
+       }\r
+\r
+       rsa->e = BN_new();\r
+       BN_set_word(rsa->e, RSA_F4);\r
+\r
+       if (rsa->n != NULL)\r
+       {\r
+               BN_free(rsa->n);\r
+       }\r
+\r
+       rsa->n = BinToBigNum(data, size);\r
+\r
+       bio = NewBio();\r
+       Lock(openssl_lock);\r
+       {\r
+               i2d_RSA_PUBKEY_bio(bio, rsa);\r
+       }\r
+       Unlock(openssl_lock);\r
+       BIO_seek(bio, 0);\r
+       k = BioToK(bio, false, false, NULL);\r
+       FreeBio(bio);\r
+\r
+       RSA_free(rsa);\r
+\r
+       return k;\r
+}\r
+\r
+// 公開鍵をバッファに変換\r
+BUF *RsaPublicToBuf(K *k)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (k == NULL || k->pkey == NULL || k->pkey->pkey.rsa == NULL\r
+               || k->pkey->pkey.rsa->n == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = BigNumToBuf(k->pkey->pkey.rsa->n);\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return b;\r
+}\r
+\r
+// 公開鍵をバイナリに変換\r
+void RsaPublicToBin(K *k, void *data)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (k == NULL || k->pkey == NULL || k->pkey->pkey.rsa == NULL\r
+               || k->pkey->pkey.rsa->n == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b = BigNumToBuf(k->pkey->pkey.rsa->n);\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Copy(data, b->Buf, b->Size);\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// 公開鍵サイズの取得\r
+UINT RsaPublicSize(K *k)\r
+{\r
+       BUF *b;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (k == NULL || k->pkey == NULL || k->pkey->pkey.rsa == NULL\r
+               || k->pkey->pkey.rsa->n == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       b = BigNumToBuf(k->pkey->pkey.rsa->n);\r
+       if (b == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = b->Size;\r
+\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// ポインタを 32 ビットにハッシュする\r
+UINT HashPtrToUINT(void *p)\r
+{\r
+       UCHAR hash_data[MD5_SIZE];\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Hash(hash_data, &p, sizeof(p), false);\r
+\r
+       Copy(&ret, hash_data, sizeof(ret));\r
+\r
+       return ret;\r
+}\r
+\r
+// NAME のコピー\r
+NAME *CopyName(NAME *n)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return NewName(n->CommonName, n->Organization, n->Unit,\r
+               n->Country, n->State, n->Local);\r
+}\r
+\r
+// バイナリを BIGNUM に変換\r
+BIGNUM *BinToBigNum(void *data, UINT size)\r
+{\r
+       BIGNUM *bn;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       bn = BN_new();\r
+       BN_bin2bn(data, size, bn);\r
+\r
+       return bn;\r
+}\r
+\r
+// バッファを BIGNUM に変換\r
+BIGNUM *BufToBigNum(BUF *b)\r
+{\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return BinToBigNum(b->Buf, b->Size);\r
+}\r
+\r
+// BIGNUM をバッファに変換\r
+BUF *BigNumToBuf(BIGNUM *bn)\r
+{\r
+       UINT size;\r
+       UCHAR *tmp;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (bn == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = BN_num_bytes(bn);\r
+       tmp = ZeroMalloc(size);\r
+       BN_bn2bin(bn, tmp);\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, tmp, size);\r
+       Free(tmp);\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       return b;\r
+}\r
+\r
+// OpenSSL のロックの初期化\r
+void OpenSSL_InitLock()\r
+{\r
+       UINT i;\r
+\r
+       // ロックオブジェクトの初期化\r
+       ssl_lock_num = CRYPTO_num_locks();\r
+       ssl_lock_obj = Malloc(sizeof(LOCK *) * ssl_lock_num);\r
+       for (i = 0;i < ssl_lock_num;i++)\r
+       {\r
+               ssl_lock_obj[i] = NewLock();\r
+       }\r
+\r
+       // ロック関数の設定\r
+       CRYPTO_set_locking_callback(OpenSSL_Lock);\r
+       CRYPTO_set_id_callback(OpenSSL_Id);\r
+}\r
+\r
+// OpenSSL のロックの解放\r
+void OpenSSL_FreeLock()\r
+{\r
+       UINT i;\r
+\r
+       for (i = 0;i < ssl_lock_num;i++)\r
+       {\r
+               DeleteLock(ssl_lock_obj[i]);\r
+       }\r
+       Free(ssl_lock_obj);\r
+       ssl_lock_obj = NULL;\r
+\r
+       CRYPTO_set_locking_callback(NULL);\r
+       CRYPTO_set_id_callback(NULL);\r
+}\r
+\r
+// OpenSSL のロック関数\r
+void OpenSSL_Lock(int mode, int n, const char *file, int line)\r
+{\r
+       LOCK *lock = ssl_lock_obj[n];\r
+\r
+       if (mode & CRYPTO_LOCK)\r
+       {\r
+               // ロック\r
+               Lock(lock);\r
+       }\r
+       else\r
+       {\r
+               // ロック解除\r
+               Unlock(lock);\r
+       }\r
+}\r
+\r
+// スレッド ID の返却\r
+unsigned long OpenSSL_Id(void)\r
+{\r
+       return (unsigned long)ThreadId();\r
+}\r
+\r
+// 証明書の表示名を取得\r
+void GetPrintNameFromX(wchar_t *str, UINT size, X *x)\r
+{\r
+       // 引数チェック\r
+       if (x == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetPrintNameFromName(str, size, x->subject_name);\r
+}\r
+void GetPrintNameFromXA(char *str, UINT size, X *x)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (str == NULL || x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetPrintNameFromX(tmp, sizeof(tmp), x);\r
+\r
+       UniToStr(str, size, tmp);\r
+}\r
+void GetAllNameFromXEx(wchar_t *str, UINT size, X *x)\r
+{\r
+       // 引数チェック\r
+       if (x == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetAllNameFromNameEx(str, size, x->subject_name);\r
+}\r
+void GetAllNameFromXExA(char *str, UINT size, X *x)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (str == NULL || x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetAllNameFromXEx(tmp, sizeof(tmp), x);\r
+\r
+       UniToStr(str, size, tmp);\r
+}\r
+\r
+// NAME から表示名を取得\r
+void GetPrintNameFromName(wchar_t *str, UINT size, NAME *name)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (name->CommonName != NULL)\r
+       {\r
+               UniStrCpy(str, size, name->CommonName);\r
+       }\r
+       else if (name->Organization != NULL)\r
+       {\r
+               UniStrCpy(str, size, name->Organization);\r
+       }\r
+       else if (name->Unit != NULL)\r
+       {\r
+               UniStrCpy(str, size, name->Unit);\r
+       }\r
+       else if (name->State != NULL)\r
+       {\r
+               UniStrCpy(str, size, name->State);\r
+       }\r
+       else if (name->Local != NULL)\r
+       {\r
+               UniStrCpy(str, size, name->Local);\r
+       }\r
+       else if (name->Country != NULL)\r
+       {\r
+               UniStrCpy(str, size, name->Country);\r
+       }\r
+       else\r
+       {\r
+               UniStrCpy(str, size, L"untitled");\r
+       }\r
+}\r
+\r
+// 証明書からすべての名前文字列を取得\r
+void GetAllNameFromX(wchar_t *str, UINT size, X *x)\r
+{\r
+       UCHAR md5[MD5_SIZE], sha1[SHA1_SIZE];\r
+       char tmp1[MD5_SIZE * 3 + 8], tmp2[SHA1_SIZE * 3 + 8];\r
+       wchar_t tmp3[sizeof(tmp1) + sizeof(tmp2) + 64];\r
+       // 引数チェック\r
+       if (str == NULL || x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetAllNameFromName(str, size, x->subject_name);\r
+\r
+       if (x->serial != NULL && x->serial->size >= 1)\r
+       {\r
+               char tmp[128];\r
+               wchar_t tmp2[128];\r
+\r
+               BinToStr(tmp, sizeof(tmp), x->serial->data, x->serial->size);\r
+               UniFormat(tmp2, sizeof(tmp2), L", SERIAL=\"%S\"", tmp);\r
+\r
+               UniStrCat(str, size, tmp2);\r
+       }\r
+\r
+       // ダイジェスト値\r
+       GetXDigest(x, md5, false);\r
+       GetXDigest(x, sha1, true);\r
+\r
+       BinToStr(tmp1, sizeof(tmp1), md5, MD5_SIZE);\r
+       BinToStr(tmp2, sizeof(tmp2), sha1, SHA1_SIZE);\r
+\r
+       UniFormat(tmp3, sizeof(tmp3), L" (Digest: MD5=\"%S\", SHA1=\"%S\")", tmp1, tmp2);\r
+       UniStrCat(str, size, tmp3);\r
+}\r
+void GetAllNameFromA(char *str, UINT size, X *x)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (str == NULL || x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetAllNameFromX(tmp, sizeof(tmp), x);\r
+       UniToStr(str, size, tmp);\r
+}\r
+\r
+// NAME からすべての名前文字列を取得\r
+void GetAllNameFromName(wchar_t *str, UINT size, NAME *name)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniStrCpy(str, size, L"");\r
+       if (name->CommonName != NULL)\r
+       {\r
+               UniFormat(str, size, L"%sCN=%s, ", str, name->CommonName);\r
+       }\r
+       if (name->Organization != NULL)\r
+       {\r
+               UniFormat(str, size, L"%sO=%s, ", str, name->Organization);\r
+       }\r
+       if (name->Unit != NULL)\r
+       {\r
+               UniFormat(str, size, L"%sOU=%s, ", str, name->Unit);\r
+       }\r
+       if (name->State != NULL)\r
+       {\r
+               UniFormat(str, size, L"%sS=%s, ", str, name->State);\r
+       }\r
+       if (name->Local != NULL)\r
+       {\r
+               UniFormat(str, size, L"%sL=%s, ", str, name->Local);\r
+       }\r
+       if (name->Country != NULL)\r
+       {\r
+               UniFormat(str, size, L"%sC=%s, ", str, name->Country);\r
+       }\r
+\r
+       if (UniStrLen(str) >= 3)\r
+       {\r
+               UINT len = UniStrLen(str);\r
+               if (str[len - 2] == L',' &&\r
+                       str[len - 1] == L' ')\r
+               {\r
+                       str[len - 2] = 0;\r
+               }\r
+       }\r
+}\r
+void GetAllNameFromNameEx(wchar_t *str, UINT size, NAME *name)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniStrCpy(str, size, L"");\r
+       if (name->CommonName != NULL)\r
+       {\r
+               UniFormat(str, size, L"%s%s, ", str, name->CommonName);\r
+       }\r
+       if (name->Organization != NULL)\r
+       {\r
+               UniFormat(str, size, L"%s%s, ", str, name->Organization);\r
+       }\r
+       if (name->Unit != NULL)\r
+       {\r
+               UniFormat(str, size, L"%s%s, ", str, name->Unit);\r
+       }\r
+       if (name->State != NULL)\r
+       {\r
+               UniFormat(str, size, L"%s%s, ", str, name->State);\r
+       }\r
+       if (name->Local != NULL)\r
+       {\r
+               UniFormat(str, size, L"%s%s, ", str, name->Local);\r
+       }\r
+       if (name->Country != NULL)\r
+       {\r
+               UniFormat(str, size, L"%s%s, ", str, name->Country);\r
+       }\r
+\r
+       if (UniStrLen(str) >= 3)\r
+       {\r
+               UINT len = UniStrLen(str);\r
+               if (str[len - 2] == L',' &&\r
+                       str[len - 1] == L' ')\r
+               {\r
+                       str[len - 2] = 0;\r
+               }\r
+       }\r
+}\r
+\r
+// 鍵のクローン\r
+K *CloneK(K *k)\r
+{\r
+       BUF *b;\r
+       K *ret;\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = KToBuf(k, false, NULL);\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = BufToK(b, k->private_key, false, NULL);\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// 証明書のクローン\r
+X *CloneX(X *x)\r
+{\r
+       BUF *b;\r
+       X *ret;\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = XToBuf(x, false);\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = BufToX(b, false);\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// P12 を生成する\r
+P12 *NewP12(X *x, K *k, char *password)\r
+{\r
+       PKCS12 *pkcs12;\r
+       P12 *p12;\r
+       // 引数チェック\r
+       if (x == NULL || k == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (password && StrLen(password) == 0)\r
+       {\r
+               password = NULL;\r
+       }\r
+\r
+       Lock(openssl_lock);\r
+       {\r
+               pkcs12 = PKCS12_create(password, NULL, k->pkey, x->x509, NULL, 0, 0, 0, 0, 0);\r
+               if (pkcs12 == NULL)\r
+               {\r
+                       Unlock(openssl_lock);\r
+                       return NULL;\r
+               }\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       p12 = PKCS12ToP12(pkcs12);\r
+\r
+       return p12;\r
+}\r
+\r
+// P12 が暗号化されているかどうかチェックする\r
+bool IsEncryptedP12(P12 *p12)\r
+{\r
+       X *x;\r
+       K *k;\r
+       // 引数チェック\r
+       if (p12 == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ParseP12(p12, &x, &k, NULL) == true)\r
+       {\r
+               FreeX(x);\r
+               FreeK(k);\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// P12 から X と K を取り出す\r
+bool ParseP12(P12 *p12, X **x, K **k, char *password)\r
+{\r
+       EVP_PKEY *pkey;\r
+       X509 *x509;\r
+       // 引数チェック\r
+       if (p12 == NULL || x == NULL || k == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (password && StrLen(password) == 0)\r
+       {\r
+               password = NULL;\r
+       }\r
+       if (password == NULL)\r
+       {\r
+               password = "";\r
+       }\r
+\r
+       // パスワード確認\r
+       Lock(openssl_lock);\r
+       {\r
+               if (PKCS12_verify_mac(p12->pkcs12, password, -1) == false &&\r
+                       PKCS12_verify_mac(p12->pkcs12, NULL, -1) == false)\r
+               {\r
+                       Unlock(openssl_lock);\r
+                       return false;\r
+               }\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       // 抽出\r
+       Lock(openssl_lock);\r
+       {\r
+               if (PKCS12_parse(p12->pkcs12, password, &pkey, &x509, NULL) == false)\r
+               {\r
+                       if (PKCS12_parse(p12->pkcs12, NULL, &pkey, &x509, NULL) == false)\r
+                       {\r
+                               Unlock(openssl_lock);\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       // 変換\r
+       *x = X509ToX(x509);\r
+\r
+       if (*x == NULL)\r
+       {\r
+               FreePKey(pkey);\r
+               return false;\r
+       }\r
+\r
+       *k = ZeroMalloc(sizeof(K));\r
+       (*k)->private_key = true;\r
+       (*k)->pkey = pkey;\r
+\r
+       return true;\r
+}\r
+\r
+// P12 をファイルに書き出す\r
+bool P12ToFile(P12 *p12, char *filename)\r
+{\r
+       wchar_t *filename_w = CopyStrToUni(filename);\r
+       bool ret = P12ToFileW(p12, filename_w);\r
+\r
+       return ret;\r
+}\r
+bool P12ToFileW(P12 *p12, wchar_t *filename)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (p12 == NULL || filename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = P12ToBuf(p12);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (DumpBufW(b, filename) == false)\r
+       {\r
+               FreeBuf(b);\r
+               return false;\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return true;\r
+}\r
+\r
+// ファイルから P12 を読み込む\r
+P12 *FileToP12(char *filename)\r
+{\r
+       wchar_t *filename_w = CopyStrToUni(filename);\r
+       P12 *ret = FileToP12W(filename_w);\r
+\r
+       Free(filename_w);\r
+\r
+       return ret;\r
+}\r
+P12 *FileToP12W(wchar_t *filename)\r
+{\r
+       BUF *b;\r
+       P12 *p12;\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = ReadDumpW(filename);\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p12 = BufToP12(b);\r
+       FreeBuf(b);\r
+\r
+       return p12;\r
+}\r
+\r
+// P12 の解放\r
+void FreeP12(P12 *p12)\r
+{\r
+       // 引数チェック\r
+       if (p12 == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreePKCS12(p12->pkcs12);\r
+       Free(p12);\r
+}\r
+\r
+// PKCS12 の解放\r
+void FreePKCS12(PKCS12 *pkcs12)\r
+{\r
+       // 引数チェック\r
+       if (pkcs12 == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PKCS12_free(pkcs12);\r
+}\r
+\r
+// P12 を BUF に変換する\r
+BUF *P12ToBuf(P12 *p12)\r
+{\r
+       BIO *bio;\r
+       BUF *buf;\r
+       // 引数チェック\r
+       if (p12 == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       bio = P12ToBio(p12);\r
+       if (bio == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       buf = BioToBuf(bio);\r
+       FreeBio(bio);\r
+\r
+       SeekBuf(buf, 0, 0);\r
+\r
+       return buf;\r
+}\r
+\r
+// P12 を BIO に変換する\r
+BIO *P12ToBio(P12 *p12)\r
+{\r
+       BIO *bio;\r
+       // 引数チェック\r
+       if (p12 == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       bio = NewBio();\r
+       Lock(openssl_lock);\r
+       {\r
+               i2d_PKCS12_bio(bio, p12->pkcs12);\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       return bio;\r
+}\r
+\r
+// BUF から P12 を読み込む\r
+P12 *BufToP12(BUF *b)\r
+{\r
+       P12 *p12;\r
+       BIO *bio;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       bio = BufToBio(b);\r
+       if (bio == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p12 = BioToP12(bio);\r
+       FreeBio(bio);\r
+\r
+       return p12;\r
+}\r
+\r
+// BIO から P12 を読み込む\r
+P12 *BioToP12(BIO *bio)\r
+{\r
+       PKCS12 *pkcs12;\r
+       // 引数チェック\r
+       if (bio == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 変換\r
+       Lock(openssl_lock);\r
+       {\r
+               pkcs12 = d2i_PKCS12_bio(bio, NULL);\r
+       }\r
+       Unlock(openssl_lock);\r
+       if (pkcs12 == NULL)\r
+       {\r
+               // 失敗\r
+               return NULL;\r
+       }\r
+\r
+       return PKCS12ToP12(pkcs12);\r
+}\r
+\r
+// PKCS12 から P12 を生成する\r
+P12 *PKCS12ToP12(PKCS12 *pkcs12)\r
+{\r
+       P12 *p12;\r
+       // 引数チェック\r
+       if (pkcs12 == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p12 = ZeroMalloc(sizeof(P12));\r
+       p12->pkcs12 = pkcs12;\r
+\r
+       return p12;\r
+}\r
+\r
+// バイナリを文字列に変換する\r
+char *ByteToStr(BYTE *src, UINT src_size)\r
+{\r
+       UINT size;\r
+       char *dst;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = MAX(src_size * 3, 1);\r
+       dst = Malloc(size);\r
+       dst[size - 1] = 0;\r
+       for (i = 0;i < src_size;i++)\r
+       {\r
+               char tmp[3];\r
+               Format(tmp, sizeof(tmp), "%02x", src[i]);\r
+               dst[i * 3 + 0] = tmp[0];\r
+               dst[i * 3 + 1] = tmp[1];\r
+               dst[i * 3 + 2] = ((i == (src_size - 1) ? 0 : ' '));\r
+       }\r
+\r
+       return dst;\r
+}\r
+\r
+// X_SERIAL の解放\r
+void FreeXSerial(X_SERIAL *serial)\r
+{\r
+       // 引数チェック\r
+       if (serial == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(serial->data);\r
+       Free(serial);\r
+}\r
+\r
+// X_SERIAL の比較\r
+bool CompareXSerial(X_SERIAL *s1, X_SERIAL *s2)\r
+{\r
+       // 引数チェック\r
+       if (s1 == NULL || s2 == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (s1->size != s2->size)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (Cmp(s1->data, s2->data, s1->size) != 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// X_SERIAL のコピー\r
+X_SERIAL *CloneXSerial(X_SERIAL *src)\r
+{\r
+       X_SERIAL *s;\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       s = ZeroMalloc(sizeof(X_SERIAL));\r
+       s->data = ZeroMalloc(src->size);\r
+       Copy(s->data, src->data, src->size);\r
+       s->size = src->size;\r
+\r
+       return s;\r
+}\r
+\r
+// X_SERIAL の初期化\r
+X_SERIAL *NewXSerial(void *data, UINT size)\r
+{\r
+       X_SERIAL *serial;\r
+       UCHAR *buf = (UCHAR *)data;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (data == NULL || size == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < size;i++)\r
+       {\r
+               if (buf[i] != 0)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+       if (i == size)\r
+       {\r
+               i = size - 1;\r
+       }\r
+       buf += i;\r
+\r
+       serial = Malloc(sizeof(X_SERIAL));\r
+       serial->size = size - i;\r
+       serial->data = ZeroMalloc(size + 16);\r
+       Copy(serial->data, buf, size - i);\r
+\r
+       return serial;\r
+}\r
+\r
+// 2038 年 1 月 1 日までの日数を取得する\r
+UINT GetDaysUntil2038()\r
+{\r
+       UINT64 now = SystemTime64();\r
+       UINT64 target;\r
+       SYSTEMTIME st;\r
+\r
+       Zero(&st, sizeof(st));\r
+       st.wYear = 2038;\r
+       st.wMonth = 1;\r
+       st.wDay = 1;\r
+\r
+       target = SystemToUINT64(&st);\r
+\r
+       if (now >= target)\r
+       {\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               return (UINT)((target - now) / (UINT64)(1000 * 60 * 60 * 24));\r
+       }\r
+}\r
+\r
+// X509 証明書を発行する\r
+X *NewX(K *pub, K *priv, X *ca, NAME *name, UINT days, X_SERIAL *serial)\r
+{\r
+       X509 *x509;\r
+       X *x;\r
+       // 引数チェック\r
+       if (pub == NULL || priv == NULL || name == NULL || ca == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       x509 = NewX509(pub, priv, ca, name, days, serial);\r
+       if (x509 == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       x = X509ToX(x509);\r
+\r
+       if (x == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return x;\r
+}\r
+\r
+// ルート証明書を作成する\r
+X *NewRootX(K *pub, K *priv, NAME *name, UINT days, X_SERIAL *serial)\r
+{\r
+       X509 *x509;\r
+       X *x, *x2;\r
+       // 引数チェック\r
+       if (pub == NULL || priv == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       x509 = NewRootX509(pub, priv, name, days, serial);\r
+       if (x509 == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       x = X509ToX(x509);\r
+       if (x == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       x2 = CloneX(x);\r
+       FreeX(x);\r
+\r
+       return x2;\r
+}\r
+\r
+// X509 証明書を発行する\r
+X509 *NewX509(K *pub, K *priv, X *ca, NAME *name, UINT days, X_SERIAL *serial)\r
+{\r
+       X509 *x509;\r
+       UINT64 notBefore, notAfter;\r
+       ASN1_TIME *t1, *t2;\r
+       X509_NAME *subject_name, *issuer_name;\r
+       // 引数チェック\r
+       if (pub == NULL || name == NULL || ca == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (pub->private_key != false)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (priv->private_key == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       notBefore = SystemTime64();\r
+       notAfter = notBefore + (UINT64)days * (UINT64)3600 * (UINT64)24 * (UINT64)1000;\r
+\r
+\r
+       // X509 の作成\r
+       x509 = X509_new();\r
+       if (x509 == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 有効期限の設定\r
+       t1 = X509_get_notBefore(x509);\r
+       t2 = X509_get_notAfter(x509);\r
+       if (!UINT64ToAsn1Time(t1, notBefore))\r
+       {\r
+               FreeX509(x509);\r
+               return NULL;\r
+       }\r
+       if (!UINT64ToAsn1Time(t2, notAfter))\r
+       {\r
+               FreeX509(x509);\r
+               return NULL;\r
+       }\r
+\r
+       // 名前の設定\r
+       subject_name = NameToX509Name(name);\r
+       if (subject_name == NULL)\r
+       {\r
+               FreeX509(x509);\r
+               return NULL;\r
+       }\r
+       issuer_name = X509_get_subject_name(ca->x509);\r
+       if (issuer_name == NULL)\r
+       {\r
+               FreeX509Name(subject_name);\r
+               FreeX509(x509);\r
+               return NULL;\r
+       }\r
+\r
+       X509_set_issuer_name(x509, issuer_name);\r
+       X509_set_subject_name(x509, subject_name);\r
+\r
+       FreeX509Name(subject_name);\r
+\r
+       // シリアル番号の設定\r
+       if (serial == NULL)\r
+       {\r
+               char zero = 0;\r
+               ASN1_INTEGER *s = x509->cert_info->serialNumber;\r
+               OPENSSL_free(s->data);\r
+               s->data = OPENSSL_malloc(sizeof(char));\r
+               Copy(s->data, &zero, sizeof(char));\r
+               s->length = sizeof(char);\r
+       }\r
+       else\r
+       {\r
+               ASN1_INTEGER *s = x509->cert_info->serialNumber;\r
+               OPENSSL_free(s->data);\r
+               s->data = OPENSSL_malloc(serial->size);\r
+               Copy(s->data, serial->data, serial->size);\r
+               s->length = serial->size;\r
+       }\r
+\r
+       Lock(openssl_lock);\r
+       {\r
+               // 公開鍵の設定\r
+               X509_set_pubkey(x509, pub->pkey);\r
+\r
+               // 署名\r
+               X509_sign(x509, priv->pkey, EVP_sha1());\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       return x509;\r
+}\r
+\r
+// ルート X509 証明書を作成する\r
+X509 *NewRootX509(K *pub, K *priv, NAME *name, UINT days, X_SERIAL *serial)\r
+{\r
+       X509 *x509;\r
+       UINT64 notBefore, notAfter;\r
+       ASN1_TIME *t1, *t2;\r
+       X509_NAME *subject_name, *issuer_name;\r
+       // 引数チェック\r
+       if (pub == NULL || name == NULL || priv == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (days == 0)\r
+       {\r
+               days = 365;\r
+       }\r
+       if (priv->private_key == false)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (pub->private_key != false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       notBefore = SystemTime64();\r
+       notAfter = notBefore + (UINT64)days * (UINT64)3600 * (UINT64)24 * (UINT64)1000;\r
+\r
+       // X509 の作成\r
+       x509 = X509_new();\r
+       if (x509 == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 有効期限の設定\r
+       t1 = X509_get_notBefore(x509);\r
+       t2 = X509_get_notAfter(x509);\r
+       if (!UINT64ToAsn1Time(t1, notBefore))\r
+       {\r
+               FreeX509(x509);\r
+               return NULL;\r
+       }\r
+       if (!UINT64ToAsn1Time(t2, notAfter))\r
+       {\r
+               FreeX509(x509);\r
+               return NULL;\r
+       }\r
+\r
+       // 名前の設定\r
+       subject_name = NameToX509Name(name);\r
+       if (subject_name == NULL)\r
+       {\r
+               FreeX509(x509);\r
+               return NULL;\r
+       }\r
+       issuer_name = NameToX509Name(name);\r
+       if (issuer_name == NULL)\r
+       {\r
+               FreeX509Name(subject_name);\r
+               FreeX509(x509);\r
+               return NULL;\r
+       }\r
+\r
+       X509_set_issuer_name(x509, issuer_name);\r
+       X509_set_subject_name(x509, subject_name);\r
+\r
+       FreeX509Name(subject_name);\r
+       FreeX509Name(issuer_name);\r
+\r
+       // シリアル番号の設定\r
+       if (serial == NULL)\r
+       {\r
+               char zero = 0;\r
+               ASN1_INTEGER *s = x509->cert_info->serialNumber;\r
+               OPENSSL_free(s->data);\r
+               s->data = OPENSSL_malloc(sizeof(char));\r
+               Copy(s->data, &zero, sizeof(char));\r
+               s->length = sizeof(char);\r
+       }\r
+       else\r
+       {\r
+               ASN1_INTEGER *s = x509->cert_info->serialNumber;\r
+               OPENSSL_free(s->data);\r
+               s->data = OPENSSL_malloc(serial->size);\r
+               Copy(s->data, serial->data, serial->size);\r
+               s->length = serial->size;\r
+       }\r
+\r
+       Lock(openssl_lock);\r
+       {\r
+               // 公開鍵の設定\r
+               X509_set_pubkey(x509, pub->pkey);\r
+\r
+               // 署名\r
+               X509_sign(x509, priv->pkey, EVP_sha1());\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       return x509;\r
+}\r
+\r
+// NAME を X509_NAME に変換\r
+void *NameToX509Name(NAME *nm)\r
+{\r
+       X509_NAME *xn;\r
+       // 引数チェック\r
+       if (nm == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       xn = X509_NAME_new();\r
+       if (xn == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // エントリの追加\r
+       AddX509Name(xn, NID_commonName, nm->CommonName);\r
+       AddX509Name(xn, NID_organizationName, nm->Organization);\r
+       AddX509Name(xn, NID_organizationalUnitName, nm->Unit);\r
+       AddX509Name(xn, NID_countryName, nm->Country);\r
+       AddX509Name(xn, NID_stateOrProvinceName, nm->State);\r
+       AddX509Name(xn, NID_localityName, nm->Local);\r
+\r
+       return xn;\r
+}\r
+\r
+// X509_NAME にエントリを追加する\r
+bool AddX509Name(void *xn, int nid, wchar_t *str)\r
+{\r
+       X509_NAME *x509_name;\r
+       UINT utf8_size;\r
+       BYTE *utf8;\r
+       // 引数チェック\r
+       if (xn == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // UTF-8 に変換\r
+       utf8_size = CalcUniToUtf8(str);\r
+       if (utf8_size == 0)\r
+       {\r
+               return false;\r
+       }\r
+       utf8 = ZeroMalloc(utf8_size + 1);\r
+       UniToUtf8(utf8, utf8_size, str);\r
+       utf8[utf8_size] = 0;\r
+\r
+       // 追加\r
+       x509_name = (X509_NAME *)xn;\r
+       Lock(openssl_lock);\r
+       {\r
+               X509_NAME_add_entry_by_NID(x509_name, nid, MBSTRING_ASC, utf8, utf8_size, -1, 0);\r
+       }\r
+       Unlock(openssl_lock);\r
+       Free(utf8);\r
+\r
+       return true;\r
+}\r
+\r
+// X509_NAME を解放\r
+void FreeX509Name(void *xn)\r
+{\r
+       X509_NAME *x509_name;\r
+       // 引数チェック\r
+       if (xn == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       x509_name = (X509_NAME *)xn;\r
+       X509_NAME_free(x509_name);\r
+}\r
+\r
+// NAME の作成\r
+NAME *NewName(wchar_t *common_name, wchar_t *organization, wchar_t *unit,\r
+                         wchar_t *country, wchar_t *state, wchar_t *local)\r
+{\r
+       NAME *nm = ZeroMalloc(sizeof(NAME));\r
+\r
+       if (UniIsEmptyStr(common_name) == false)\r
+       {\r
+               nm->CommonName = CopyUniStr(common_name);\r
+       }\r
+\r
+       if (UniIsEmptyStr(organization) == false)\r
+       {\r
+               nm->Organization = CopyUniStr(organization);\r
+       }\r
+\r
+       if (UniIsEmptyStr(unit) == false)\r
+       {\r
+               nm->Unit = CopyUniStr(unit);\r
+       }\r
+\r
+       if (UniIsEmptyStr(country) == false)\r
+       {\r
+               nm->Country = CopyUniStr(country);\r
+       }\r
+\r
+       if (UniIsEmptyStr(state) == false)\r
+       {\r
+               nm->State = CopyUniStr(state);\r
+       }\r
+\r
+       if (UniIsEmptyStr(local) == false)\r
+       {\r
+               nm->Local = CopyUniStr(local);\r
+       }\r
+\r
+       return nm;\r
+}\r
+\r
+// 証明書の有効期限を現在時刻で確認する\r
+bool CheckXDateNow(X *x)\r
+{\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return CheckXDate(x, SystemTime64());\r
+}\r
+\r
+// 証明書の有効期限を確認する\r
+bool CheckXDate(X *x, UINT64 current_system_time)\r
+{\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (x->notBefore >= current_system_time || x->notAfter <= current_system_time)\r
+       {\r
+               return false;\r
+       }\r
+       return true;\r
+}\r
+\r
+// 証明書の有効期限情報を読み込む\r
+void LoadXDates(X *x)\r
+{\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       x->notBefore = Asn1TimeToUINT64(x->x509->cert_info->validity->notBefore);\r
+       x->notAfter = Asn1TimeToUINT64(x->x509->cert_info->validity->notAfter);\r
+}\r
+\r
+// 64bit システム時刻を ASN1 時刻に変換する\r
+bool UINT64ToAsn1Time(void *asn1_time, UINT64 t)\r
+{\r
+       SYSTEMTIME st;\r
+       // 引数チェック\r
+       if (asn1_time == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UINT64ToSystem(&st, t);\r
+       return SystemToAsn1Time(asn1_time, &st);\r
+}\r
+\r
+// システム時刻を ASN1 時刻に変換する\r
+bool SystemToAsn1Time(void *asn1_time, SYSTEMTIME *s)\r
+{\r
+       char tmp[20];\r
+       ASN1_TIME *t;\r
+       // 引数チェック\r
+       if (asn1_time == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (SystemToStr(tmp, sizeof(tmp), s) == false)\r
+       {\r
+               return false;\r
+       }\r
+       t = (ASN1_TIME *)asn1_time;\r
+       if (t->data == NULL || t->length < sizeof(tmp))\r
+       {\r
+               t->data = OPENSSL_malloc(sizeof(tmp));\r
+       }\r
+       StrCpy((char *)t->data, t->length, tmp);\r
+       t->length = StrLen(tmp);\r
+       t->type = V_ASN1_UTCTIME;\r
+\r
+       return true;\r
+}\r
+\r
+// システム時刻を文字列に変換する\r
+bool SystemToStr(char *str, UINT size, SYSTEMTIME *s)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Format(str, size, "%02u%02u%02u%02u%02u%02uZ",\r
+               s->wYear % 100, s->wMonth, s->wDay,\r
+               s->wHour, s->wMinute, s->wSecond);\r
+\r
+       return true;\r
+}\r
+\r
+// ASN1 時刻を UINT64 時刻に変換する\r
+UINT64 Asn1TimeToUINT64(void *asn1_time)\r
+{\r
+       SYSTEMTIME st;\r
+       // 引数チェック\r
+       if (asn1_time == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (Asn1TimeToSystem(&st, asn1_time) == false)\r
+       {\r
+               return 0;\r
+       }\r
+       return SystemToUINT64(&st);\r
+}\r
+\r
+// ASN1 時刻をシステム時刻に変換する\r
+bool Asn1TimeToSystem(SYSTEMTIME *s, void *asn1_time)\r
+{\r
+       ASN1_TIME *t;\r
+       // 引数チェック\r
+       if (s == NULL || asn1_time == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       t = (ASN1_TIME *)asn1_time;\r
+       if (StrToSystem(s, (char *)t->data) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (t->type == V_ASN1_GENERALIZEDTIME)\r
+       {\r
+               LocalToSystem(s, s);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 文字列をシステム時刻に変換する\r
+bool StrToSystem(SYSTEMTIME *s, char *str)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (StrLen(str) != 13)\r
+       {\r
+               return false;\r
+       }\r
+       if (str[12] != 'Z')\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 変換\r
+       {\r
+               char year[3] = {str[0], str[1], 0},\r
+                       month[3] = {str[2], str[3], 0},\r
+                       day[3] = {str[4], str[5], 0},\r
+                       hour[3] = {str[6], str[7], 0},\r
+                       minute[3] = {str[8], str[9], 0},\r
+                       second[3] = {str[10], str[11], 0};\r
+               Zero(s, sizeof(SYSTEMTIME));\r
+               s->wYear = ToInt(year);\r
+               if (s->wYear >= 60)\r
+               {\r
+                       s->wYear += 1900;\r
+               }\r
+               else\r
+               {\r
+                       s->wYear += 2000;\r
+               }\r
+               s->wMonth = ToInt(month);\r
+               s->wDay = ToInt(day);\r
+               s->wHour = ToInt(hour);\r
+               s->wMinute = ToInt(minute);\r
+               s->wSecond = ToInt(second);\r
+               NormalizeSystem(s);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// RSA 署名の検査\r
+bool RsaVerify(void *data, UINT data_size, void *sign, K *k)\r
+{\r
+       return RsaVerifyEx(data, data_size, sign, k, 0);\r
+}\r
+bool RsaVerifyEx(void *data, UINT data_size, void *sign, K *k, UINT bits)\r
+{\r
+       UCHAR hash_data[SIGN_HASH_SIZE];\r
+       UCHAR decrypt_data[SIGN_HASH_SIZE];\r
+       // 引数チェック\r
+       if (data == NULL || sign == NULL || k == NULL || k->private_key != false)\r
+       {\r
+               return false;\r
+       }\r
+       if (bits == 0)\r
+       {\r
+               bits = 1024;\r
+       }\r
+\r
+       // データをハッシュ\r
+       if (HashForSign(hash_data, sizeof(hash_data), data, data_size) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 署名を解読\r
+       if (RSA_public_decrypt(bits / 8, sign, decrypt_data, k->pkey->pkey.rsa, RSA_PKCS1_PADDING) <= 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 比較\r
+       if (Cmp(decrypt_data, hash_data, sizeof(SIGN_HASH_SIZE)) != 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// RSA 署名\r
+bool RsaSign(void *dst, void *src, UINT size, K *k)\r
+{\r
+       return RsaSignEx(dst, src, size, k, 0);\r
+}\r
+bool RsaSignEx(void *dst, void *src, UINT size, K *k, UINT bits)\r
+{\r
+       UCHAR hash[SIGN_HASH_SIZE];\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL || k == NULL || k->pkey->type != EVP_PKEY_RSA)\r
+       {\r
+               return false;\r
+       }\r
+       if (bits == 0)\r
+       {\r
+               bits = 1024;\r
+       }\r
+\r
+       Zero(dst, bits / 8);\r
+\r
+       // ハッシュ\r
+       if (HashForSign(hash, sizeof(hash), src, size) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 署名\r
+       if (RSA_private_encrypt(sizeof(hash), hash, dst, k->pkey->pkey.rsa, RSA_PKCS1_PADDING) <= 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// SHA-1 による署名データの生成\r
+bool HashForSign(void *dst, UINT dst_size, void *src, UINT src_size)\r
+{\r
+       UCHAR *buf = (UCHAR *)dst;\r
+       UCHAR sign_data[] =\r
+       {\r
+               0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E,\r
+               0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14,\r
+       };\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL || src_size == 0 || MIN_SIGN_HASH_SIZE > dst_size)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ヘッダ部分\r
+       Copy(buf, sign_data, sizeof(sign_data));\r
+\r
+       // ハッシュ\r
+       HashSha1(HASHED_DATA(buf), src, src_size);\r
+\r
+       return true;\r
+}\r
+\r
+// RSA 公開鍵による復号化\r
+bool RsaPublicDecrypt(void *dst, void *src, UINT size, K *k)\r
+{\r
+       void *tmp;\r
+       int ret;\r
+       // 引数チェック\r
+       if (src == NULL || size == 0 || k == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       tmp = ZeroMalloc(size);\r
+       Lock(openssl_lock);\r
+       {\r
+               ret = RSA_public_decrypt(size, src, tmp, k->pkey->pkey.rsa, RSA_NO_PADDING);\r
+       }\r
+       Unlock(openssl_lock);\r
+       if (ret <= 0)\r
+       {\r
+/*             Debug("RSA Error: 0x%x\n",\r
+                       ERR_get_error());\r
+*/             Free(tmp);\r
+               return false;\r
+       }\r
+\r
+       Copy(dst, tmp, size);\r
+       Free(tmp);\r
+\r
+       return true;\r
+}\r
+\r
+// RSA 秘密鍵による暗号化\r
+bool RsaPrivateEncrypt(void *dst, void *src, UINT size, K *k)\r
+{\r
+       void *tmp;\r
+       int ret;\r
+       // 引数チェック\r
+       if (src == NULL || size == 0 || k == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       tmp = ZeroMalloc(size);\r
+       Lock(openssl_lock);\r
+       {\r
+               ret = RSA_private_encrypt(size, src, tmp, k->pkey->pkey.rsa, RSA_NO_PADDING);\r
+       }\r
+       Unlock(openssl_lock);\r
+       if (ret <= 0)\r
+       {\r
+/*             Debug("RSA Error: %u\n",\r
+                       ERR_GET_REASON(ERR_get_error()));\r
+*/             Free(tmp);\r
+               return false;\r
+       }\r
+\r
+       Copy(dst, tmp, size);\r
+       Free(tmp);\r
+\r
+       return true;\r
+}\r
+\r
+// RSA 秘密鍵による復号化\r
+bool RsaPrivateDecrypt(void *dst, void *src, UINT size, K *k)\r
+{\r
+       void *tmp;\r
+       int ret;\r
+       // 引数チェック\r
+       if (src == NULL || size == 0 || k == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       tmp = ZeroMalloc(size);\r
+       Lock(openssl_lock);\r
+       {\r
+               ret = RSA_private_decrypt(size, src, tmp, k->pkey->pkey.rsa, RSA_NO_PADDING);\r
+       }\r
+       Unlock(openssl_lock);\r
+       if (ret <= 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Copy(dst, tmp, size);\r
+       Free(tmp);\r
+\r
+       return true;\r
+}\r
+\r
+// RSA 公開鍵による暗号化\r
+bool RsaPublicEncrypt(void *dst, void *src, UINT size, K *k)\r
+{\r
+       void *tmp;\r
+       int ret;\r
+       // 引数チェック\r
+       if (src == NULL || size == 0 || k == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       tmp = ZeroMalloc(size);\r
+       Lock(openssl_lock);\r
+       {\r
+               ret = RSA_public_encrypt(size, src, tmp, k->pkey->pkey.rsa, RSA_NO_PADDING);\r
+       }\r
+       Unlock(openssl_lock);\r
+       if (ret <= 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Copy(dst, tmp, size);\r
+       Free(tmp);\r
+\r
+       return true;\r
+}\r
+\r
+// RSA 動作環境チェック\r
+bool RsaCheckEx()\r
+{\r
+       UINT num = 20;\r
+       UINT i;\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               if (RsaCheck())\r
+               {\r
+                       return true;\r
+               }\r
+\r
+               SleepThread(100);\r
+       }\r
+\r
+       return false;\r
+}\r
+bool RsaCheck()\r
+{\r
+       RSA *rsa;\r
+       K *priv_key, *pub_key;\r
+       BIO *bio;\r
+       char errbuf[MAX_SIZE];\r
+       UINT size = 0;\r
+       UINT bit = 32;\r
+       // 引数チェック\r
+\r
+       // 鍵生成\r
+       Lock(openssl_lock);\r
+       {\r
+               rsa = RSA_generate_key(bit, RSA_F4, NULL, NULL);\r
+       }\r
+       Unlock(openssl_lock);\r
+       if (rsa == NULL)\r
+       {\r
+               Debug("RSA_generate_key: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));\r
+               return false;\r
+       }\r
+\r
+       // 秘密鍵\r
+       bio = NewBio();\r
+       Lock(openssl_lock);\r
+       {\r
+               i2d_RSAPrivateKey_bio(bio, rsa);\r
+       }\r
+       Unlock(openssl_lock);\r
+       BIO_seek(bio, 0);\r
+       priv_key = BioToK(bio, true, false, NULL);\r
+       FreeBio(bio);\r
+\r
+       // 公開鍵\r
+       bio = NewBio();\r
+       Lock(openssl_lock);\r
+       {\r
+               i2d_RSA_PUBKEY_bio(bio, rsa);\r
+       }\r
+       Unlock(openssl_lock);\r
+       BIO_seek(bio, 0);\r
+       pub_key = BioToK(bio, false, false, NULL);\r
+       FreeBio(bio);\r
+\r
+       RSA_free(rsa);\r
+\r
+       size = RsaPublicSize(pub_key);\r
+\r
+       if (size != ((bit + 7) / 8))\r
+       {\r
+               FreeK(priv_key);\r
+               FreeK(pub_key);\r
+\r
+               return false;\r
+       }\r
+\r
+       FreeK(priv_key);\r
+       FreeK(pub_key);\r
+\r
+       return true;\r
+}\r
+\r
+// RSA 鍵の生成\r
+bool RsaGen(K **priv, K **pub, UINT bit)\r
+{\r
+       RSA *rsa;\r
+       K *priv_key, *pub_key;\r
+       BIO *bio;\r
+       char errbuf[MAX_SIZE];\r
+       UINT size = 0;\r
+       // 引数チェック\r
+       if (priv == NULL || pub == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (bit == 0)\r
+       {\r
+               bit = 1024;\r
+       }\r
+\r
+       // 鍵生成\r
+       Lock(openssl_lock);\r
+       {\r
+               rsa = RSA_generate_key(bit, RSA_F4, NULL, NULL);\r
+       }\r
+       Unlock(openssl_lock);\r
+       if (rsa == NULL)\r
+       {\r
+               Debug("RSA_generate_key: err=%s\n", ERR_error_string(ERR_get_error(), errbuf));\r
+               return false;\r
+       }\r
+\r
+       // 秘密鍵\r
+       bio = NewBio();\r
+       Lock(openssl_lock);\r
+       {\r
+               i2d_RSAPrivateKey_bio(bio, rsa);\r
+       }\r
+       Unlock(openssl_lock);\r
+       BIO_seek(bio, 0);\r
+       priv_key = BioToK(bio, true, false, NULL);\r
+       FreeBio(bio);\r
+\r
+       // 公開鍵\r
+       bio = NewBio();\r
+       Lock(openssl_lock);\r
+       {\r
+               i2d_RSA_PUBKEY_bio(bio, rsa);\r
+       }\r
+       Unlock(openssl_lock);\r
+       BIO_seek(bio, 0);\r
+       pub_key = BioToK(bio, false, false, NULL);\r
+       FreeBio(bio);\r
+\r
+       *priv = priv_key;\r
+       *pub = pub_key;\r
+\r
+       RSA_free(rsa);\r
+\r
+       size = RsaPublicSize(*pub);\r
+\r
+       if (size != ((bit + 7) / 8))\r
+       {\r
+               FreeK(*priv);\r
+               FreeK(*pub);\r
+\r
+               return RsaGen(priv, pub, bit);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 証明書 X が証明書 x_issuer の発行者によって署名されているかどうか確認する\r
+bool CheckX(X *x, X *x_issuer)\r
+{\r
+       K *k;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (x == NULL || x_issuer == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       k = GetKFromX(x_issuer);\r
+       if (k == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = CheckSignature(x, k);\r
+       FreeK(k);\r
+\r
+       return ret;\r
+}\r
+\r
+// 証明書 X の署名を公開鍵 K で確認する\r
+bool CheckSignature(X *x, K *k)\r
+{\r
+       // 引数チェック\r
+       if (x == NULL || k == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(openssl_lock);\r
+       {\r
+               if (X509_verify(x->x509, k->pkey) == 0)\r
+               {\r
+                       Unlock(openssl_lock);\r
+                       return false;\r
+               }\r
+       }\r
+       Unlock(openssl_lock);\r
+       return true;\r
+}\r
+\r
+// 証明書から公開鍵を取得する\r
+K *GetKFromX(X *x)\r
+{\r
+       EVP_PKEY *pkey;\r
+       K *k;\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Lock(openssl_lock);\r
+       {\r
+               pkey = X509_get_pubkey(x->x509);\r
+       }\r
+       Unlock(openssl_lock);\r
+       if (pkey == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       k = ZeroMalloc(sizeof(K));\r
+       k->pkey = pkey;\r
+\r
+       return k;\r
+}\r
+\r
+// 名前の比較\r
+bool CompareName(NAME *n1, NAME *n2)\r
+{\r
+       // 引数チェック\r
+       if (n1 == NULL || n2 == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 名前比較\r
+       if (UniStrCmpi(n1->CommonName, n2->CommonName) == 0 &&\r
+               UniStrCmpi(n1->Organization, n2->Organization) == 0 &&\r
+               UniStrCmpi(n1->Unit, n2->Unit) == 0 &&\r
+               UniStrCmpi(n1->Country, n2->Country) == 0 &&\r
+               UniStrCmpi(n1->State, n2->State) == 0 &&\r
+               UniStrCmpi(n1->Local, n2->Local) == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// X の名前の解放\r
+void FreeXNames(X *x)\r
+{\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeName(x->issuer_name);\r
+       x->issuer_name = NULL;\r
+\r
+       FreeName(x->subject_name);\r
+       x->subject_name = NULL;\r
+}\r
+\r
+// 名前の解放\r
+void FreeName(NAME *n)\r
+{\r
+       // 引数チェック\r
+       if (n == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 文字列を解放\r
+       Free(n->CommonName);\r
+       Free(n->Organization);\r
+       Free(n->Unit);\r
+       Free(n->Country);\r
+       Free(n->State);\r
+       Free(n->Local);\r
+\r
+       // オブジェクトを解放\r
+       Free(n);\r
+\r
+       return;\r
+}\r
+\r
+// 証明書の名前を取得する\r
+void LoadXNames(X *x)\r
+{\r
+       X509 *x509;\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       x509 = x->x509;\r
+       x->issuer_name = X509NameToName(X509_get_issuer_name(x509));\r
+       x->subject_name = X509NameToName(X509_get_subject_name(x509));\r
+}\r
+\r
+// X509_NAME 構造体を NAME 構造体に変換\r
+NAME *X509NameToName(void *xn)\r
+{\r
+       NAME *n;\r
+       // 引数チェック\r
+       if (xn == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       n = ZeroMalloc(sizeof(NAME));\r
+\r
+       // 文字列を順番に取得する\r
+       n->CommonName = GetUniStrFromX509Name(xn, NID_commonName);\r
+       n->Organization = GetUniStrFromX509Name(xn, NID_organizationName);\r
+       n->Unit = GetUniStrFromX509Name(xn, NID_organizationalUnitName);\r
+       n->Country = GetUniStrFromX509Name(xn, NID_countryName);\r
+       n->State = GetUniStrFromX509Name(xn, NID_stateOrProvinceName);\r
+       n->Local = GetUniStrFromX509Name(xn, NID_localityName);\r
+\r
+       return n;\r
+}\r
+\r
+// X509_NAME 構造体の中から Unicode 文字列を読み込む\r
+wchar_t *GetUniStrFromX509Name(void *xn, int nid)\r
+{\r
+       UCHAR txt[1024];\r
+       bool b = false;\r
+       UINT i, size;\r
+       int index;\r
+       bool unicode = false;\r
+       bool is_utf_8 = false;\r
+       ASN1_OBJECT *obj;\r
+       ASN1_STRING *data;\r
+       // 引数チェック\r
+       if (xn == NULL || nid == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(txt, sizeof(txt));\r
+       if (X509_NAME_get_text_by_NID(xn, nid, (char *)txt, sizeof(txt) - 2) <= 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       obj = OBJ_nid2obj(nid);\r
+       if (obj == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       index = X509_NAME_get_index_by_OBJ(xn, obj, -1);\r
+       if (index < 0)\r
+       {\r
+               return NULL;\r
+       }\r
+       data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(xn, index));\r
+       if (data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (data->type == V_ASN1_BMPSTRING)\r
+       {\r
+               unicode = true;\r
+       }\r
+       if (data->type == V_ASN1_UTF8STRING || data->type == V_ASN1_T61STRING)\r
+       {\r
+               is_utf_8 = true;\r
+       }\r
+\r
+       size = UniStrLen((wchar_t *)txt) * 4 + 8;\r
+       for (i = 0;i < size;i++)\r
+       {\r
+               if (txt[i] >= 0x80)\r
+               {\r
+                       unicode = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (is_utf_8)\r
+       {\r
+               wchar_t *ret;\r
+               UINT ret_size;\r
+\r
+               ret_size = CalcUtf8ToUni(txt, StrLen(txt));\r
+               ret = ZeroMalloc(ret_size + 8);\r
+               Utf8ToUni(ret, ret_size, txt, StrLen(txt));\r
+\r
+               return ret;\r
+       }\r
+       else if (unicode == false)\r
+       {\r
+               wchar_t tmp[1024];\r
+               StrToUni(tmp, sizeof(tmp), (char *)txt);\r
+               return CopyUniStr(tmp);\r
+       }\r
+       else\r
+       {\r
+               EndianUnicode((wchar_t *)txt);\r
+               return CopyUniStr((wchar_t *)txt);\r
+       }\r
+}\r
+\r
+// 証明書 x1 と x2 が等しいかどうかチェックする\r
+bool CompareX(X *x1, X *x2)\r
+{\r
+       // 引数チェック\r
+       if (x1 == NULL || x2 == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(openssl_lock);\r
+       if (X509_cmp(x1->x509, x2->x509) == 0)\r
+       {\r
+               Unlock(openssl_lock);\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               Unlock(openssl_lock);\r
+               return false;\r
+       }\r
+}\r
+\r
+// K が X の秘密鍵かどうかチェックする\r
+bool CheckXandK(X *x, K *k)\r
+{\r
+       // 引数チェック\r
+       if (x == NULL || k == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(openssl_lock);\r
+       if (X509_check_private_key(x->x509, k->pkey) != 0)\r
+       {\r
+               Unlock(openssl_lock);\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               Unlock(openssl_lock);\r
+               return false;\r
+       }\r
+}\r
+\r
+// ファイルから X を読み込む\r
+X *FileToX(char *filename)\r
+{\r
+       wchar_t *filename_w = CopyStrToUni(filename);\r
+       X *ret = FileToXW(filename_w);\r
+\r
+       Free(filename_w);\r
+\r
+       return ret;\r
+}\r
+X *FileToXW(wchar_t *filename)\r
+{\r
+       bool text;\r
+       BUF *b;\r
+       X *x;\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = ReadDumpW(filename);\r
+       text = IsBase64(b);\r
+\r
+       x = BufToX(b, text);\r
+       FreeBuf(b);\r
+\r
+       return x;\r
+}\r
+\r
+// X をファイルに書き出す\r
+bool XToFile(X *x, char *filename, bool text)\r
+{\r
+       wchar_t *filename_w = CopyStrToUni(filename);\r
+       bool ret = XToFileW(x, filename_w, text);\r
+\r
+       Free(filename_w);\r
+\r
+       return ret;\r
+}\r
+bool XToFileW(X *x, wchar_t *filename, bool text)\r
+{\r
+       BUF *b;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (x == NULL || filename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = XToBuf(x, text);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = DumpBufW(b, filename);\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// ファイルから K を読み込む\r
+K *FileToK(char *filename, bool private_key, char *password)\r
+{\r
+       wchar_t *filename_w = CopyStrToUni(filename);\r
+       K *ret;\r
+\r
+       ret = FileToKW(filename_w, private_key, password);\r
+\r
+       Free(filename_w);\r
+\r
+       return ret;\r
+}\r
+K *FileToKW(wchar_t *filename, bool private_key, char *password)\r
+{\r
+       bool text;\r
+       BUF *b;\r
+       K *k;\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = ReadDumpW(filename);\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       text = IsBase64(b);\r
+       if (text == false)\r
+       {\r
+               k = BufToK(b, private_key, false, NULL);\r
+       }\r
+       else\r
+       {\r
+               k = BufToK(b, private_key, true, NULL);\r
+               if (k == NULL)\r
+               {\r
+                       k = BufToK(b, private_key, true, password);\r
+               }\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return k;\r
+}\r
+\r
+// K をファイルに保存する\r
+bool KToFile(K *k, char *filename, bool text, char *password)\r
+{\r
+       wchar_t *filename_w = CopyStrToUni(filename);\r
+       bool ret = KToFileW(k, filename_w, text, password);\r
+\r
+       Free(filename_w);\r
+\r
+       return ret;\r
+}\r
+bool KToFileW(K *k, wchar_t *filename, bool text, char *password)\r
+{\r
+       BUF *b;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (k == NULL || filename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = KToBuf(k, text, password);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = DumpBufW(b, filename);\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// K を BUF に変換する\r
+BUF *KToBuf(K *k, bool text, char *password)\r
+{\r
+       BUF *buf;\r
+       BIO *bio;\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       bio = KToBio(k, text, password);\r
+       if (bio == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       buf = BioToBuf(bio);\r
+       FreeBio(bio);\r
+\r
+       SeekBuf(buf, 0, 0);\r
+\r
+       return buf;\r
+}\r
+\r
+// K を BIO に変換する\r
+BIO *KToBio(K *k, bool text, char *password)\r
+{\r
+       BIO *bio;\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       bio = NewBio();\r
+\r
+       if (k->private_key)\r
+       {\r
+               // 秘密鍵\r
+               if (text == false)\r
+               {\r
+                       // バイナリ形式\r
+                       Lock(openssl_lock);\r
+                       {\r
+                               i2d_PrivateKey_bio(bio, k->pkey);\r
+                       }\r
+                       Unlock(openssl_lock);\r
+               }\r
+               else\r
+               {\r
+                       // テキスト形式\r
+                       if (password == 0 || StrLen(password) == 0)\r
+                       {\r
+                               // 暗号化無し\r
+                               Lock(openssl_lock);\r
+                               {\r
+                                       PEM_write_bio_PrivateKey(bio, k->pkey, NULL, NULL, 0, NULL, NULL);\r
+                               }\r
+                               Unlock(openssl_lock);\r
+                       }\r
+                       else\r
+                       {\r
+                               // 暗号化する\r
+                               CB_PARAM cb;\r
+                               cb.password = password;\r
+                               Lock(openssl_lock);\r
+                               {\r
+                                       PEM_write_bio_PrivateKey(bio, k->pkey, EVP_des_ede3_cbc(),\r
+                                               NULL, 0, (pem_password_cb *)PKeyPasswordCallbackFunction, &cb);\r
+                               }\r
+                               Unlock(openssl_lock);\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // 公開鍵\r
+               if (text == false)\r
+               {\r
+                       // バイナリ形式\r
+                       Lock(openssl_lock);\r
+                       {\r
+                               i2d_PUBKEY_bio(bio, k->pkey);\r
+                       }\r
+                       Unlock(openssl_lock);\r
+               }\r
+               else\r
+               {\r
+                       // テキスト形式\r
+                       Lock(openssl_lock);\r
+                       {\r
+                               PEM_write_bio_PUBKEY(bio, k->pkey);\r
+                       }\r
+                       Unlock(openssl_lock);\r
+               }\r
+       }\r
+\r
+       return bio;\r
+}\r
+\r
+// BUF が Base64 エンコードされているかどうか調べる\r
+bool IsBase64(BUF *b)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < b->Size;i++)\r
+       {\r
+               char c = ((char *)b->Buf)[i];\r
+               bool b = false;\r
+               if ('a' <= c && c <= 'z')\r
+               {\r
+                       b = true;\r
+               }\r
+               else if ('A' <= c && c <= 'Z')\r
+               {\r
+                       b = true;\r
+               }\r
+               else if ('0' <= c && c <= '9')\r
+               {\r
+                       b = true;\r
+               }\r
+               else if (c == ':' || c == '.' || c == ';' || c == ',')\r
+               {\r
+                       b = true;\r
+               }\r
+               else if (c == '!' || c == '&' || c == '#' || c == '(' || c == ')')\r
+               {\r
+                       b = true;\r
+               }\r
+               else if (c == '-' || c == ' ')\r
+               {\r
+                       b = true;\r
+               }\r
+               else if (c == 13 || c == 10 || c == EOF)\r
+               {\r
+                       b = true;\r
+               }\r
+               else if (c == '\t' || c == '=' || c == '+' || c == '/')\r
+               {\r
+                       b = true;\r
+               }\r
+               if (b == false)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+       return true;\r
+}\r
+\r
+// BUF に含まれている K が暗号化されているかどうか調べる\r
+bool IsEncryptedK(BUF *b, bool private_key)\r
+{\r
+       K *k;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (IsBase64(b) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       k = BufToK(b, private_key, true, NULL);\r
+       if (k != NULL)\r
+       {\r
+               FreeK(k);\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// BUF を K に変換\r
+K *BufToK(BUF *b, bool private_key, bool text, char *password)\r
+{\r
+       BIO *bio;\r
+       K *k;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       bio = BufToBio(b);\r
+       k = BioToK(bio, private_key, text, password);\r
+       FreeBio(bio);\r
+\r
+       return k;\r
+}\r
+\r
+// K を解放\r
+void FreeK(K *k)\r
+{\r
+       // 引数チェック\r
+       if (k == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreePKey(k->pkey);\r
+       Free(k);\r
+}\r
+\r
+// 秘密鍵を解放\r
+void FreePKey(EVP_PKEY *pkey)\r
+{\r
+       // 引数チェック\r
+       if (pkey == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       EVP_PKEY_free(pkey);\r
+}\r
+\r
+// BIO を K に変換する\r
+K *BioToK(BIO *bio, bool private_key, bool text, char *password)\r
+{\r
+       EVP_PKEY *pkey;\r
+       K *k;\r
+       // 引数チェック\r
+       if (bio == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (password != NULL && StrLen(password) == 0)\r
+       {\r
+               password = NULL;\r
+       }\r
+\r
+       if (private_key == false)\r
+       {\r
+               // 公開鍵\r
+               if (text == false)\r
+               {\r
+                       // バイナリ形式\r
+                       pkey = d2i_PUBKEY_bio(bio, NULL);\r
+                       if (pkey == NULL)\r
+                       {\r
+                               return NULL;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // テキスト形式\r
+                       CB_PARAM cb;\r
+                       cb.password = password;\r
+                       Lock(openssl_lock);\r
+                       {\r
+                               pkey = PEM_read_bio_PUBKEY(bio, NULL, (pem_password_cb *)PKeyPasswordCallbackFunction, &cb);\r
+                       }\r
+                       Unlock(openssl_lock);\r
+                       if (pkey == NULL)\r
+                       {\r
+                               return NULL;\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (text == false)\r
+               {\r
+                       // バイナリ形式\r
+                       Lock(openssl_lock);\r
+                       {\r
+                               pkey = d2i_PrivateKey_bio(bio, NULL);\r
+                       }\r
+                       Unlock(openssl_lock);\r
+                       if (pkey == NULL)\r
+                       {\r
+                               return NULL;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // テキスト形式\r
+                       CB_PARAM cb;\r
+                       cb.password = password;\r
+                       Lock(openssl_lock);\r
+                       {\r
+                               pkey = PEM_read_bio_PrivateKey(bio, NULL, (pem_password_cb *)PKeyPasswordCallbackFunction, &cb);\r
+                       }\r
+                       Unlock(openssl_lock);\r
+                       if (pkey == NULL)\r
+                       {\r
+                               return NULL;\r
+                       }\r
+               }\r
+       }\r
+\r
+       k = ZeroMalloc(sizeof(K));\r
+       k->pkey = pkey;\r
+       k->private_key = private_key;\r
+\r
+       return k;\r
+}\r
+\r
+// パスワードコールバック関数\r
+int PKeyPasswordCallbackFunction(char *buf, int bufsize, int verify, void *param)\r
+{\r
+       CB_PARAM *cb;\r
+       // 引数チェック\r
+       if (buf == NULL || param == NULL || bufsize == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       cb = (CB_PARAM *)param;\r
+       if (cb->password == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCpy(buf, bufsize, cb->password);\r
+}\r
+\r
+// X を BUF に変換する\r
+BUF *XToBuf(X *x, bool text)\r
+{\r
+       BIO *bio;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       bio = XToBio(x, text);\r
+       if (bio == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = BioToBuf(bio);\r
+       FreeBio(bio);\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       return b;\r
+}\r
+\r
+// X を BIO に変換する\r
+BIO *XToBio(X *x, bool text)\r
+{\r
+       BIO *bio;\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       bio = NewBio();\r
+\r
+       Lock(openssl_lock);\r
+       {\r
+               if (text == false)\r
+               {\r
+                       // バイナリ形式\r
+                       i2d_X509_bio(bio, x->x509);\r
+               }\r
+               else\r
+               {\r
+                       // テキスト形式\r
+                       PEM_write_bio_X509(bio, x->x509);\r
+               }\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       return bio;\r
+}\r
+\r
+// X の解放\r
+void FreeX(X *x)\r
+{\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 名前解放\r
+       FreeXNames(x);\r
+\r
+\r
+       // シリアル解放\r
+       FreeXSerial(x->serial);\r
+\r
+       if (x->do_not_free == false)\r
+       {\r
+               FreeX509(x->x509);\r
+       }\r
+       Free(x);\r
+}\r
+\r
+// X509 の解放\r
+void FreeX509(X509 *x509)\r
+{\r
+       // 引数チェック\r
+       if (x509 == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(openssl_lock);\r
+       {\r
+               X509_free(x509);\r
+       }\r
+       Unlock(openssl_lock);\r
+}\r
+\r
+// BUF を X に変換する\r
+X *BufToX(BUF *b, bool text)\r
+{\r
+       X *x;\r
+       BIO *bio;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       bio = BufToBio(b);\r
+       if (bio == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       x = BioToX(bio, text);\r
+\r
+       FreeBio(bio);\r
+\r
+       return x;\r
+}\r
+\r
+// X のダイジェストを取得する\r
+void GetXDigest(X *x, UCHAR *buf, bool sha1)\r
+{\r
+       // 引数チェック\r
+       if (x == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (sha1 == false)\r
+       {\r
+               UINT size = MD5_SIZE;\r
+               X509_digest(x->x509, EVP_md5(), buf, (unsigned int *)&size);\r
+       }\r
+       else\r
+       {\r
+               UINT size = SHA1_SIZE;\r
+               X509_digest(x->x509, EVP_sha1(), buf, (unsigned int *)&size);\r
+       }\r
+}\r
+\r
+// BIO を X に変換する\r
+X *BioToX(BIO *bio, bool text)\r
+{\r
+       X *x;\r
+       X509 *x509;\r
+       // 引数チェック\r
+       if (bio == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Lock(openssl_lock);\r
+       {\r
+               // x509 の読み込み\r
+               if (text == false)\r
+               {\r
+                       // バイナリモード\r
+                       x509 = d2i_X509_bio(bio, NULL);\r
+               }\r
+               else\r
+               {\r
+                       // テキストモード\r
+                       x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL);\r
+               }\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       if (x509 == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       x = X509ToX(x509);\r
+\r
+       if (x == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return x;\r
+}\r
+\r
+// X509 を X に変換する\r
+X *X509ToX(X509 *x509)\r
+{\r
+       X *x;\r
+       K *k;\r
+       BUF *b;\r
+       UINT size;\r
+       UINT type;\r
+       // 引数チェック\r
+       if (x509 == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       x = ZeroMalloc(sizeof(X));\r
+       x->x509 = x509;\r
+\r
+       // 名前\r
+       LoadXNames(x);\r
+\r
+       // 有効期限\r
+       LoadXDates(x);\r
+\r
+       // ルート証明書かどうかチェックする\r
+       if (CompareName(x->issuer_name, x->subject_name))\r
+       {\r
+               K *pubkey = GetKFromX(x);\r
+               if (pubkey != NULL)\r
+               {\r
+                       if (CheckXandK(x, pubkey))\r
+                       {\r
+                               x->root_cert = true;\r
+                       }\r
+                       FreeK(pubkey);\r
+               }\r
+       }\r
+\r
+       // シリアル番号の取得\r
+       x->serial = NewXSerial(x509->cert_info->serialNumber->data,\r
+               x509->cert_info->serialNumber->length);\r
+       if (x->serial == NULL)\r
+       {\r
+               char zero = 0;\r
+               x->serial = NewXSerial(&zero, sizeof(char));\r
+       }\r
+\r
+       k = GetKFromX(x);\r
+       if (k == NULL)\r
+       {\r
+               FreeX(x);\r
+               return NULL;\r
+       }\r
+\r
+       b = KToBuf(k, false, NULL);\r
+\r
+       size = b->Size;\r
+       type = k->pkey->type;\r
+\r
+       FreeBuf(b);\r
+\r
+       FreeK(k);\r
+\r
+       if (type == EVP_PKEY_RSA)\r
+       {\r
+               x->is_compatible_bit = true;\r
+\r
+               switch (size)\r
+               {\r
+               case 162:\r
+                       x->bits = 1024;\r
+                       break;\r
+\r
+               case 226:\r
+                       x->bits = 1536;\r
+                       break;\r
+\r
+               case 294:\r
+                       x->bits = 2048;\r
+                       break;\r
+\r
+               case 442:\r
+                       x->bits = 3072;\r
+                       break;\r
+\r
+               case 550:\r
+                       x->bits = 4096;\r
+                       break;\r
+\r
+               default:\r
+                       x->is_compatible_bit = false;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       return x;\r
+}\r
+\r
+// BIO を作成する\r
+BIO *NewBio()\r
+{\r
+       return BIO_new(BIO_s_mem());\r
+}\r
+\r
+// BIO を解放する\r
+void FreeBio(BIO *bio)\r
+{\r
+       // 引数チェック\r
+       if (bio == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       BIO_free(bio);\r
+}\r
+\r
+// BIO を BUF に変換する\r
+BUF *BioToBuf(BIO *bio)\r
+{\r
+       BUF *b;\r
+       UINT size;\r
+       void *tmp;\r
+       // 引数チェック\r
+       if (bio == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       BIO_seek(bio, 0);\r
+       size = bio->num_write;\r
+       tmp = Malloc(size);\r
+       BIO_read(bio, tmp, size);\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, tmp, size);\r
+       Free(tmp);\r
+\r
+       return b;\r
+}\r
+\r
+// BUF を BIO に変換する\r
+BIO *BufToBio(BUF *b)\r
+{\r
+       BIO *bio;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Lock(openssl_lock);\r
+       {\r
+               bio = BIO_new(BIO_s_mem());\r
+               if (bio == NULL)\r
+               {\r
+                       Unlock(openssl_lock);\r
+                       return NULL;\r
+               }\r
+               BIO_write(bio, b->Buf, b->Size);\r
+               BIO_seek(bio, 0);\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       return bio;\r
+}\r
+\r
+// 128bit 乱数生成\r
+void Rand128(void *buf)\r
+{\r
+       Rand(buf, 16);\r
+}\r
+\r
+// 64bit 乱数生成\r
+UINT64 Rand64()\r
+{\r
+       UINT64 i;\r
+       Rand(&i, sizeof(i));\r
+       return i;\r
+}\r
+\r
+// 32bit 乱数生成\r
+UINT Rand32()\r
+{\r
+       UINT i;\r
+       Rand(&i, sizeof(i));\r
+       return i;\r
+}\r
+\r
+// 16bit 乱数生成\r
+USHORT Rand16()\r
+{\r
+       USHORT i;\r
+       Rand(&i, sizeof(i));\r
+       return i;\r
+}\r
+\r
+// 8bit 乱数生成\r
+UCHAR Rand8()\r
+{\r
+       UCHAR i;\r
+       Rand(&i, sizeof(i));\r
+       return i;\r
+}\r
+\r
+// 1bit 乱数生成\r
+bool Rand1()\r
+{\r
+       return (Rand32() % 2) == 0 ? false : true;\r
+}\r
+\r
+// 乱数生成\r
+void Rand(void *buf, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (buf == NULL || size == 0)\r
+       {\r
+               return;\r
+       }\r
+       RAND_bytes(buf, size);\r
+}\r
+\r
+// OpenSSL が確保しているスレッド固有情報を削除する\r
+void FreeOpenSSLThreadState()\r
+{\r
+       ERR_remove_state(0);\r
+}\r
+\r
+// 暗号化ライブラリの解放\r
+void FreeCryptLibrary()\r
+{\r
+       openssl_inited = false;\r
+\r
+       DeleteLock(openssl_lock);\r
+       openssl_lock = NULL;\r
+//     RAND_Free_For_SoftEther();\r
+       OpenSSL_FreeLock();\r
+}\r
+\r
+// 暗号化ライブラリの初期化\r
+void InitCryptLibrary()\r
+{\r
+       char tmp[16];\r
+//     RAND_Init_For_SoftEther()\r
+       openssl_lock = NewLock();\r
+       SSL_library_init();\r
+       //OpenSSL_add_all_algorithms();\r
+       OpenSSL_add_all_ciphers();\r
+       SSLeay_add_all_digests();\r
+       ERR_load_crypto_strings();\r
+       SSL_load_error_strings();\r
+\r
+#ifdef OS_UNIX\r
+       {\r
+               char *name1 = "/dev/random";\r
+               char *name2 = "/dev/urandom";\r
+               IO *o;\r
+               o = FileOpen(name1, false);\r
+               if (o == NULL)\r
+               {\r
+                       o = FileOpen(name2, false);\r
+                       if (o == NULL)\r
+                       {\r
+                               UINT64 now = SystemTime64();\r
+                               BUF *b;\r
+                               UINT i;\r
+                               b = NewBuf();\r
+                               for (i = 0;i < 4096;i++)\r
+                               {\r
+                                       UCHAR c = rand() % 256;\r
+                                       WriteBuf(b, &c, 1);\r
+                               }\r
+                               WriteBuf(b, &now, sizeof(now));\r
+                               RAND_seed(b->Buf, b->Size);\r
+                               FreeBuf(b);\r
+                       }\r
+                       else\r
+                       {\r
+                               FileClose(o);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       FileClose(o);\r
+               }\r
+       }\r
+#endif // OS_UNIX\r
+\r
+       RAND_poll();\r
+\r
+#ifdef OS_WIN32\r
+//     RAND_screen();\r
+#endif\r
+       Rand(tmp, sizeof(tmp));\r
+       OpenSSL_InitLock();\r
+\r
+       openssl_inited = true;\r
+}\r
+\r
+// 内部ハッシュ関数\r
+void InternalHash(void *dst, void *src, UINT size, bool sha1)\r
+{\r
+       // 引数チェック\r
+       if (dst == NULL || (src == NULL && size != 0))\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (sha1 == false)\r
+       {\r
+               // MD5 ハッシュ\r
+               MD5(src, size, dst);\r
+       }\r
+       else\r
+       {\r
+               // SHA ハッシュ\r
+               SHA(src, size, dst);\r
+       }\r
+}\r
+\r
+// SHA-1 専用ハッシュ関数\r
+void HashSha1(void *dst, void *src, UINT size)\r
+{\r
+       SHA1(src, size, dst);\r
+}\r
+\r
+// ハッシュ関数\r
+void Hash(void *dst, void *src, UINT size, bool sha1)\r
+{\r
+       InternalHash(dst, src, size, sha1);\r
+}\r
+\r
+// 新しい CRYPT オブジェクトの作成\r
+CRYPT *NewCrypt(void *key, UINT size)\r
+{\r
+       CRYPT *c = ZeroMalloc(sizeof(CRYPT));\r
+\r
+       SetKey(c, key, size);\r
+\r
+       return c;\r
+}\r
+\r
+// CRYPT オブジェクトの解放\r
+void FreeCrypt(CRYPT *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メモリ解放\r
+       Free(c);\r
+}\r
+\r
+// 暗号化と解読\r
+void InternalEncrypt(CRYPT *c, void *dst, void *src, UINT size)\r
+{\r
+       UINT x, y, sx, sy;\r
+       UINT *state;\r
+       UCHAR *endsrc;\r
+       UCHAR *s = (UCHAR *)src;\r
+       UCHAR *d = (UCHAR *)dst;\r
+       // 引数チェック\r
+       if (c == NULL || dst == NULL || src == NULL || size == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       state = (UINT *)c->state;\r
+       x = c->x;\r
+       y = c->y;\r
+\r
+       for (endsrc = s + size;s != endsrc;s++, d++)\r
+       {\r
+               x = (x + 1) & 0xff;\r
+               sx = state[x];\r
+               y = (sx + y) & 0xff;\r
+               state[x] = sy = state[y];\r
+               state[y] = sx;\r
+               *d = *s ^ state[(sx + sy) & 0xff];\r
+       }\r
+       c->x = x;\r
+       c->y = y;\r
+}\r
+void Encrypt(CRYPT *c, void *dst, void *src, UINT size)\r
+{\r
+       InternalEncrypt(c, dst, src, size);\r
+}\r
+\r
+// 鍵の更新\r
+void SetKey(CRYPT *c, void *key, UINT size)\r
+{\r
+       UINT i, t, u, ki, si;\r
+       UINT *state;\r
+       UCHAR *k = (UCHAR *)key;\r
+       // 引数チェック\r
+       if (c == NULL || key == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 鍵のセット\r
+       state = (UINT *)c->state;\r
+       c->x = c->y = 0;\r
+       for (i = 0;i < 256;i++)\r
+       {\r
+               state[i] = i;\r
+       }\r
+       ki = si = 0;\r
+\r
+       for (i = 0;i < 256;i++)\r
+       {\r
+               t = state[i];\r
+               si = (si + k[ki] + t) & 0xff;\r
+               u = state[si];\r
+               state[si] = t;\r
+               state[i] = u;\r
+               if (++ki >= size)\r
+               {\r
+                       ki = 0;\r
+               }\r
+       }\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Encrypt.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Encrypt.h
new file mode 100644 (file)
index 0000000..753c1ea
--- /dev/null
@@ -0,0 +1,320 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Encrypt.h\r
+// Encrypt.c のヘッダ\r
+\r
+#ifndef        ENCRYPT_H\r
+#define        ENCRYPT_H\r
+\r
+// OpenSSL の関数\r
+void RAND_Init_For_SoftEther();\r
+void RAND_Free_For_SoftEther();\r
+\r
+\r
+\r
+// 定数\r
+#define        MIN_SIGN_HASH_SIZE              (15 + SHA1_SIZE)\r
+#define        SIGN_HASH_SIZE                  (MIN_SIGN_HASH_SIZE)\r
+\r
+// マクロ\r
+#define        HASHED_DATA(p)                  (((UCHAR *)p) + 15)\r
+\r
+\r
+\r
+// 暗号化コンテキスト\r
+struct CRYPT\r
+{\r
+       int x, y;\r
+       int state[256];\r
+};\r
+\r
+// 証明書内の名前\r
+struct NAME\r
+{\r
+       wchar_t *CommonName;            // CN\r
+       wchar_t *Organization;          // O\r
+       wchar_t *Unit;                          // OU\r
+       wchar_t *Country;                       // C\r
+       wchar_t *State;                         // ST\r
+       wchar_t *Local;                         // L\r
+};\r
+\r
+// シリアル番号\r
+struct X_SERIAL\r
+{\r
+       UINT size;\r
+       UCHAR *data;\r
+};\r
+\r
+// 証明書\r
+struct X\r
+{\r
+       X509 *x509;\r
+       NAME *issuer_name;\r
+       NAME *subject_name;\r
+       bool root_cert;\r
+       UINT64 notBefore;\r
+       UINT64 notAfter;\r
+       X_SERIAL *serial;\r
+       bool do_not_free;\r
+       bool is_compatible_bit;\r
+       UINT bits;\r
+};\r
+\r
+// 鍵\r
+struct K\r
+{\r
+       EVP_PKEY *pkey;\r
+       bool private_key;\r
+};\r
+\r
+// PKCS#12\r
+struct P12\r
+{\r
+       PKCS12 *pkcs12;\r
+};\r
+\r
+// CEL\r
+struct X_CRL\r
+{\r
+       X509_CRL *Crl;\r
+};\r
+\r
+// 定数\r
+#define        MD5_SIZE        16\r
+#define        SHA1_SIZE       20\r
+\r
+// OpenSSL のロック\r
+extern LOCK **ssl_lock_obj;\r
+\r
+// 関数プロトタイプ\r
+CRYPT *NewCrypt(void *key, UINT size);\r
+void FreeCrypt(CRYPT *c);\r
+void SetKey(CRYPT *c, void *key, UINT size);\r
+void Encrypt(CRYPT *c, void *dst, void *src, UINT size);\r
+void InternalEncrypt(CRYPT *c, void *dst, void *src, UINT size);\r
+void Hash(void *dst, void *src, UINT size, bool sha1);\r
+void HashSha1(void *dst, void *src, UINT size);\r
+void InternalHash(void *dst, void *src, UINT size, bool sha1);\r
+void InitCryptLibrary();\r
+void Rand(void *buf, UINT size);\r
+void Rand128(void *buf);\r
+UINT64 Rand64();\r
+UINT Rand32();\r
+USHORT Rand16();\r
+UCHAR Rand8();\r
+bool Rand1();\r
+UINT HashPtrToUINT(void *p);\r
+\r
+void CertTest();\r
+BIO *BufToBio(BUF *b);\r
+BUF *BioToBuf(BIO *bio);\r
+BIO *NewBio();\r
+void FreeBio(BIO *bio);\r
+X *BioToX(BIO *bio, bool text);\r
+X *BufToX(BUF *b, bool text);\r
+void FreeX509(X509 *x509);\r
+void FreeX(X *x);\r
+BIO *XToBio(X *x, bool text);\r
+BUF *XToBuf(X *x, bool text);\r
+K *BioToK(BIO *bio, bool private_key, bool text, char *password);\r
+int PKeyPasswordCallbackFunction(char *buf, int bufsize, int verify, void *param);\r
+void FreePKey(EVP_PKEY *pkey);\r
+void FreeK(K *k);\r
+K *BufToK(BUF *b, bool private_key, bool text, char *password);\r
+bool IsEncryptedK(BUF *b, bool private_key);\r
+bool IsBase64(BUF *b);\r
+BIO *KToBio(K *k, bool text, char *password);\r
+BUF *KToBuf(K *k, bool text, char *password);\r
+X *FileToX(char *filename);\r
+X *FileToXW(wchar_t *filename);\r
+bool XToFile(X *x, char *filename, bool text);\r
+bool XToFileW(X *x, wchar_t *filename, bool text);\r
+K *FileToK(char *filename, bool private_key, char *password);\r
+K *FileToKW(wchar_t *filename, bool private_key, char *password);\r
+bool KToFile(K *k, char *filename, bool text, char *password);\r
+bool KToFileW(K *k, wchar_t *filename, bool text, char *password);\r
+bool CheckXandK(X *x, K *k);\r
+bool CompareX(X *x1, X *x2);\r
+NAME *X509NameToName(void *xn);\r
+wchar_t *GetUniStrFromX509Name(void *xn, int nid);\r
+void LoadXNames(X *x);\r
+void FreeXNames(X *x);\r
+void FreeName(NAME *n);\r
+bool CompareName(NAME *n1, NAME *n2);\r
+K *GetKFromX(X *x);\r
+bool CheckSignature(X *x, K *k);\r
+X *X509ToX(X509 *x509);\r
+bool CheckX(X *x, X *x_issuer);\r
+bool Asn1TimeToSystem(SYSTEMTIME *s, void *asn1_time);\r
+bool StrToSystem(SYSTEMTIME *s, char *str);\r
+UINT64 Asn1TimeToUINT64(void *asn1_time);\r
+bool SystemToAsn1Time(void *asn1_time, SYSTEMTIME *s);\r
+bool UINT64ToAsn1Time(void *asn1_time, UINT64 t);\r
+bool SystemToStr(char *str, UINT size, SYSTEMTIME *s);\r
+void LoadXDates(X *x);\r
+bool CheckXDate(X *x, UINT64 current_system_time);\r
+bool CheckXDateNow(X *x);\r
+NAME *NewName(wchar_t *common_name, wchar_t *organization, wchar_t *unit,\r
+                         wchar_t *country, wchar_t *state, wchar_t *local);\r
+void *NameToX509Name(NAME *nm);\r
+void FreeX509Name(void *xn);\r
+bool AddX509Name(void *xn, int nid, wchar_t *str);\r
+X509 *NewRootX509(K *pub, K *priv, NAME *name, UINT days, X_SERIAL *serial);\r
+X *NewRootX(K *pub, K *priv, NAME *name, UINT days, X_SERIAL *serial);\r
+X509 *NewX509(K *pub, K *priv, X *ca, NAME *name, UINT days, X_SERIAL *serial);\r
+X *NewX(K *pub, K *priv, X *ca, NAME *name, UINT days, X_SERIAL *serial);\r
+UINT GetDaysUntil2038();\r
+X_SERIAL *NewXSerial(void *data, UINT size);\r
+void FreeXSerial(X_SERIAL *serial);\r
+char *ByteToStr(BYTE *src, UINT src_size);\r
+P12 *BioToP12(BIO *bio);\r
+P12 *PKCS12ToP12(PKCS12 *pkcs12);\r
+P12 *BufToP12(BUF *b);\r
+BIO *P12ToBio(P12 *p12);\r
+BUF *P12ToBuf(P12 *p12);\r
+void FreePKCS12(PKCS12 *pkcs12);\r
+void FreeP12(P12 *p12);\r
+P12 *FileToP12(char *filename);\r
+P12 *FileToP12W(wchar_t *filename);\r
+bool P12ToFile(P12 *p12, char *filename);\r
+bool P12ToFileW(P12 *p12, wchar_t *filename);\r
+bool ParseP12(P12 *p12, X **x, K **k, char *password);\r
+bool IsEncryptedP12(P12 *p12);\r
+P12 *NewP12(X *x, K *k, char *password);\r
+X *CloneX(X *x);\r
+K *CloneK(K *k);\r
+void FreeCryptLibrary();\r
+void GetPrintNameFromX(wchar_t *str, UINT size, X *x);\r
+void GetPrintNameFromXA(char *str, UINT size, X *x);\r
+void GetPrintNameFromName(wchar_t *str, UINT size, NAME *name);\r
+void GetAllNameFromX(wchar_t *str, UINT size, X *x);\r
+void GetAllNameFromA(char *str, UINT size, X *x);\r
+void GetAllNameFromName(wchar_t *str, UINT size, NAME *name);\r
+void GetAllNameFromNameEx(wchar_t *str, UINT size, NAME *name);\r
+void GetAllNameFromXEx(wchar_t *str, UINT size, X *x);\r
+void GetAllNameFromXExA(char *str, UINT size, X *x);\r
+BUF *BigNumToBuf(BIGNUM *bn);\r
+BIGNUM *BinToBigNum(void *data, UINT size);\r
+BIGNUM *BufToBigNum(BUF *b);\r
+X_SERIAL *CloneXSerial(X_SERIAL *src);\r
+bool CompareXSerial(X_SERIAL *s1, X_SERIAL *s2);\r
+void GetXDigest(X *x, UCHAR *buf, bool sha1);\r
+NAME *CopyName(NAME *n);\r
+\r
+\r
+bool RsaGen(K **priv, K **pub, UINT bit);\r
+bool RsaCheck();\r
+bool RsaCheckEx();\r
+bool RsaPublicEncrypt(void *dst, void *src, UINT size, K *k);\r
+bool RsaPrivateDecrypt(void *dst, void *src, UINT size, K *k);\r
+bool RsaPrivateEncrypt(void *dst, void *src, UINT size, K *k);\r
+bool RsaPublicDecrypt(void *dst, void *src, UINT size, K *k);\r
+bool RsaSign(void *dst, void *src, UINT size, K *k);\r
+bool RsaSignEx(void *dst, void *src, UINT size, K *k, UINT bits);\r
+bool HashForSign(void *dst, UINT dst_size, void *src, UINT src_size);\r
+bool RsaVerify(void *data, UINT data_size, void *sign, K *k);\r
+bool RsaVerifyEx(void *data, UINT data_size, void *sign, K *k, UINT bits);\r
+UINT RsaPublicSize(K *k);\r
+void RsaPublicToBin(K *k, void *data);\r
+BUF *RsaPublicToBuf(K *k);\r
+K *RsaBinToPublic(void *data, UINT size);\r
+\r
+X_CRL *FileToXCrl(char *filename);\r
+X_CRL *FileToXCrlW(wchar_t *filename);\r
+X_CRL *BufToXCrl(BUF *b);\r
+void FreeXCrl(X_CRL *r);\r
+bool IsXRevokedByXCrl(X *x, X_CRL *r);\r
+bool IsXRevoked(X *x);\r
+\r
+\r
+\r
+void OpenSSL_InitLock();\r
+void OpenSSL_FreeLock();\r
+void OpenSSL_Lock(int mode, int n, const char *file, int line);\r
+unsigned long OpenSSL_Id(void);\r
+void FreeOpenSSLThreadState();\r
+\r
+#ifdef ENCRYPT_C\r
+// 内部関数\r
+\r
+\r
+#endif // ENCRYPT_C\r
+\r
+#endif // ENCRYPT_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/FileIO.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/FileIO.c
new file mode 100644 (file)
index 0000000..b667620
--- /dev/null
@@ -0,0 +1,2234 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// FileIO.c\r
+// ファイル入出力コード\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+static char exe_file_name[MAX_SIZE] = "/tmp/a.out";\r
+static wchar_t exe_file_name_w[MAX_SIZE] = L"/tmp/a.out";\r
+static LIST *hamcore = NULL;\r
+static IO *hamcore_io = NULL;\r
+\r
+\r
+// ファイルを保存する\r
+bool SaveFileW(wchar_t *name, void *data, UINT size)\r
+{\r
+       IO *io;\r
+       // 引数チェック\r
+       if (name == NULL || (data == NULL && size != 0))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       io = FileCreateW(name);\r
+       if (io == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (FileWrite(io, data, size) == false)\r
+       {\r
+               FileClose(io);\r
+               return false;\r
+       }\r
+\r
+       FileClose(io);\r
+\r
+       return true;\r
+}\r
+bool SaveFile(char *name, void *data, UINT size)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       bool ret = SaveFileW(name_w, data, size);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+\r
+// ファイルが存在するかどうか確認する\r
+bool IsFile(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       bool ret = IsFileW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+bool IsFileW(wchar_t *name)\r
+{\r
+       IO *io;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       io = FileOpenExW(name, false, false);\r
+       if (io == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       FileClose(io);\r
+\r
+       return true;\r
+}\r
+\r
+// ファイルを置換してリネームする\r
+bool FileReplaceRename(char *old_name, char *new_name)\r
+{\r
+       wchar_t *old_name_w = CopyStrToUni(old_name);\r
+       wchar_t *new_name_w = CopyStrToUni(new_name);\r
+       bool ret = FileReplaceRenameW(old_name_w, new_name_w);\r
+\r
+       Free(old_name_w);\r
+       Free(new_name_w);\r
+\r
+       return ret;\r
+}\r
+bool FileReplaceRenameW(wchar_t *old_name, wchar_t *new_name)\r
+{\r
+       // 引数チェック\r
+       if (old_name == NULL || new_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (FileCopyW(old_name, new_name) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       FileDeleteW(old_name);\r
+\r
+       return true;\r
+}\r
+\r
+// ファイル名を安全な名前にする\r
+void ConvertSafeFileName(char *dst, UINT size, char *src)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(dst, size, src);\r
+       for (i = 0;i < StrLen(dst);i++)\r
+       {\r
+               if (IsSafeChar(dst[i]) == false)\r
+               {\r
+                       dst[i] = '_';\r
+               }\r
+       }\r
+}\r
+void ConvertSafeFileNameW(wchar_t *dst, UINT size, wchar_t *src)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniStrCpy(dst, size, src);\r
+       for (i = 0;i < UniStrLen(dst);i++)\r
+       {\r
+               if (UniIsSafeChar(dst[i]) == false)\r
+               {\r
+                       dst[i] = L'_';\r
+               }\r
+       }\r
+}\r
+\r
+// ディスクの空き容量を取得する\r
+bool GetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size)\r
+{\r
+       bool ret;\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               path = "./";\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       ret = Win32GetDiskFree(path, free_size, used_size, total_size);\r
+#else  // OS_WIN32\r
+       ret = UnixGetDiskFree(path, free_size, used_size, total_size);\r
+#endif // OS_WIN32\r
+\r
+       return ret;\r
+}\r
+bool GetDiskFreeW(wchar_t *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size)\r
+{\r
+       bool ret;\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               path = L"./";\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       ret = Win32GetDiskFreeW(path, free_size, used_size, total_size);\r
+#else  // OS_WIN32\r
+       ret = UnixGetDiskFreeW(path, free_size, used_size, total_size);\r
+#endif // OS_WIN32\r
+\r
+       return ret;\r
+}\r
+\r
+// ディレクトリの列挙\r
+DIRLIST *EnumDirEx(char *dirname, COMPARE *compare)\r
+{\r
+       wchar_t *dirname_w = CopyStrToUni(dirname);\r
+       DIRLIST *ret = EnumDirExW(dirname_w, compare);\r
+\r
+       Free(dirname_w);\r
+\r
+       return ret;\r
+}\r
+DIRLIST *EnumDirExW(wchar_t *dirname, COMPARE *compare)\r
+{\r
+       DIRLIST *d = NULL;\r
+       // 引数チェック\r
+       if (dirname == NULL)\r
+       {\r
+               dirname = L"./";\r
+       }\r
+\r
+       if (compare == NULL)\r
+       {\r
+               compare = CompareDirListByName;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       d = Win32EnumDirExW(dirname, compare);\r
+#else  // OS_WIN32\r
+       d = UnixEnumDirExW(dirname, compare);\r
+#endif // OS_WIN32\r
+\r
+       return d;\r
+}\r
+DIRLIST *EnumDir(char *dirname)\r
+{\r
+       return EnumDirEx(dirname, NULL);\r
+}\r
+DIRLIST *EnumDirW(wchar_t *dirname)\r
+{\r
+       return EnumDirExW(dirname, NULL);\r
+}\r
+\r
+// DIRLIST リストの比較\r
+int CompareDirListByName(void *p1, void *p2)\r
+{\r
+       DIRENT *d1, *d2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       d1 = *(DIRENT **)p1;\r
+       d2 = *(DIRENT **)p2;\r
+       if (d1 == NULL || d2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return UniStrCmpi(d1->FileNameW, d2->FileNameW);\r
+}\r
+\r
+// ディレクトリ列挙の解放\r
+void FreeDir(DIRLIST *d)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (d == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < d->NumFiles;i++)\r
+       {\r
+               DIRENT *f = d->File[i];\r
+               Free(f->FileName);\r
+               Free(f->FileNameW);\r
+               Free(f);\r
+       }\r
+       Free(d->File);\r
+       Free(d);\r
+}\r
+\r
+\r
+// ファイル名を安全にする\r
+void UniSafeFileName(wchar_t *name)\r
+{\r
+       UINT i, len, dlen;\r
+       static wchar_t *danger_str = L"\\/:*?\"<>|";\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       dlen = UniStrLen(danger_str);\r
+       len = UniStrLen(name);\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               wchar_t c = name[i];\r
+               UINT j;\r
+               for (j = 0;j < dlen;j++)\r
+               {\r
+                       if (c == danger_str[j])\r
+                       {\r
+                               c = L'_';\r
+                       }\r
+               }\r
+               name[i] = c;\r
+       }\r
+}\r
+void SafeFileNameW(wchar_t *name)\r
+{\r
+       UniSafeFileName(name);\r
+}\r
+\r
+// HamCore の読み込み\r
+BUF *ReadHamcoreW(wchar_t *filename)\r
+{\r
+       char *filename_a = CopyUniToStr(filename);\r
+       BUF *ret;\r
+\r
+       ret = ReadHamcore(filename_a);\r
+\r
+       Free(filename_a);\r
+\r
+       return ret;\r
+}\r
+BUF *ReadHamcore(char *name)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t exe_dir[MAX_SIZE];\r
+       BUF *b;\r
+       char filename[MAX_PATH];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (name[0] == '|')\r
+       {\r
+               name++;\r
+       }\r
+\r
+       if (name[0] == '/' || name[0] == '\\')\r
+       {\r
+               name++;\r
+       }\r
+\r
+       StrCpy(filename, sizeof(filename), name);\r
+\r
+       ReplaceStrEx(filename, sizeof(filename), filename, "/", "\\", true);\r
+\r
+       if (MayaquaIsMinimalMode())\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // ローカルディスクの hamcore/ ディレクトリにファイルがあればそれを読み込む\r
+       GetExeDirW(exe_dir, sizeof(exe_dir));\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"%s/%S/%S", exe_dir, HAMCORE_DIR_NAME, filename);\r
+\r
+       b = ReadDumpW(tmp);\r
+       if (b != NULL)\r
+       {\r
+               return b;\r
+       }\r
+\r
+       // 無い場合は HamCore ファイルシステムから探す\r
+       LockList(hamcore);\r
+       {\r
+               HC t, *c;\r
+               UINT i;\r
+\r
+               Zero(&t, sizeof(t));\r
+               t.FileName = filename;\r
+               c = Search(hamcore, &t);\r
+\r
+               if (c == NULL)\r
+               {\r
+                       // ファイルが存在しない\r
+                       b = NULL;\r
+               }\r
+               else\r
+               {\r
+                       // ファイルが存在する\r
+                       if (c->Buffer != NULL)\r
+                       {\r
+                               // 既に読み込まれている\r
+                               b = NewBuf();\r
+                               WriteBuf(b, c->Buffer, c->Size);\r
+                               SeekBuf(b, 0, 0);\r
+                               c->LastAccess = Tick64();\r
+                       }\r
+                       else\r
+                       {\r
+                               // 読み込まれていないのでファイルから読み込む\r
+                               if (FileSeek(hamcore_io, 0, c->Offset) == false)\r
+                               {\r
+                                       // シークに失敗した\r
+                                       b = NULL;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 圧縮データを読み込む\r
+                                       void *data = Malloc(c->SizeCompressed);\r
+                                       if (FileRead(hamcore_io, data, c->SizeCompressed) == false)\r
+                                       {\r
+                                               // 読み込みに失敗した\r
+                                               Free(data);\r
+                                               b = NULL;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // 展開する\r
+                                               c->Buffer = ZeroMalloc(c->Size);\r
+                                               if (Uncompress(c->Buffer, c->Size, data, c->SizeCompressed) != c->Size)\r
+                                               {\r
+                                                       // 展開に失敗した\r
+                                                       Free(data);\r
+                                                       Free(c->Buffer);\r
+                                                       b = NULL;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       // 成功した\r
+                                                       Free(data);\r
+                                                       b = NewBuf();\r
+                                                       WriteBuf(b, c->Buffer, c->Size);\r
+                                                       SeekBuf(b, 0, 0);\r
+                                                       c->LastAccess = Tick64();\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // 有効期限の切れたキャッシュを削除する\r
+               for (i = 0;i < LIST_NUM(hamcore);i++)\r
+               {\r
+                       HC *c = LIST_DATA(hamcore, i);\r
+\r
+                       if (c->Buffer != NULL)\r
+                       {\r
+                               if (((c->LastAccess + HAMCORE_CACHE_EXPIRES) <= Tick64()) ||\r
+                                       (StartWith(c->FileName, "Li")))\r
+                               {\r
+                                       Free(c->Buffer);\r
+                                       c->Buffer = NULL;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(hamcore);\r
+\r
+       return b;\r
+}\r
+\r
+// HamCore ファイルシステムの初期化\r
+void InitHamcore()\r
+{\r
+       wchar_t tmp[MAX_PATH];\r
+       wchar_t tmp2[MAX_PATH];\r
+       wchar_t exe_dir[MAX_PATH];\r
+       UINT i, num;\r
+       char header[HAMCORE_HEADER_SIZE];\r
+\r
+       hamcore = NewList(CompareHamcore);\r
+\r
+       if (MayaquaIsMinimalMode())\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetExeDirW(exe_dir, sizeof(exe_dir));\r
+       UniFormat(tmp, sizeof(tmp), L"%s/%S", exe_dir, HAMCORE_FILE_NAME);\r
+\r
+       UniFormat(tmp2, sizeof(tmp2), L"%s/%S", exe_dir, HAMCORE_FILE_NAME_2);\r
+\r
+       // _hamcore.utvpn がある場合は hamcore.utvpn に上書きする\r
+       FileReplaceRenameW(tmp2, tmp);\r
+\r
+       // hamcore.utvpn ファイルがあれば読み込む\r
+       hamcore_io = FileOpenW(tmp, false);\r
+       if (hamcore_io == NULL)\r
+       {\r
+               // 無い場合は別の場所を探す\r
+#ifdef OS_WIN32\r
+               UniFormat(tmp, sizeof(tmp), L"%S/%S", MsGetSystem32Dir(), HAMCORE_FILE_NAME);\r
+#else  // OS_WIN32\r
+               UniFormat(tmp, sizeof(tmp), L"/bin/%S", HAMCORE_FILE_NAME);\r
+#endif // OS_WIN32\r
+\r
+               hamcore_io = FileOpenW(tmp, false);\r
+               if (hamcore_io == NULL)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       // ファイルヘッダを読み込む\r
+       Zero(header, sizeof(header));\r
+       FileRead(hamcore_io, header, HAMCORE_HEADER_SIZE);\r
+\r
+       if (Cmp(header, HAMCORE_HEADER_DATA, HAMCORE_HEADER_SIZE) != 0)\r
+       {\r
+               // ヘッダ不正\r
+               FileClose(hamcore_io);\r
+               hamcore_io = NULL;\r
+               return;\r
+       }\r
+\r
+       // ファイル個数\r
+       num = 0;\r
+       FileRead(hamcore_io, &num, sizeof(num));\r
+       num = Endian32(num);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               // ファイル名\r
+               char tmp[MAX_SIZE];\r
+               UINT str_size = 0;\r
+               HC *c;\r
+\r
+               FileRead(hamcore_io, &str_size, sizeof(str_size));\r
+               str_size = Endian32(str_size);\r
+               if (str_size >= 1)\r
+               {\r
+                       str_size--;\r
+               }\r
+\r
+               Zero(tmp, sizeof(tmp));\r
+               FileRead(hamcore_io, tmp, str_size);\r
+\r
+               c = ZeroMalloc(sizeof(HC));\r
+               c->FileName = CopyStr(tmp);\r
+\r
+               FileRead(hamcore_io, &c->Size, sizeof(UINT));\r
+               c->Size = Endian32(c->Size);\r
+\r
+               FileRead(hamcore_io, &c->SizeCompressed, sizeof(UINT));\r
+               c->SizeCompressed = Endian32(c->SizeCompressed);\r
+\r
+               FileRead(hamcore_io, &c->Offset, sizeof(UINT));\r
+               c->Offset = Endian32(c->Offset);\r
+\r
+               Insert(hamcore, c);\r
+       }\r
+}\r
+\r
+// HamCore ファイルシステムの解放\r
+void FreeHamcore()\r
+{\r
+       UINT i;\r
+       for (i = 0;i < LIST_NUM(hamcore);i++)\r
+       {\r
+               HC *c = LIST_DATA(hamcore, i);\r
+               Free(c->FileName);\r
+               if (c->Buffer != NULL)\r
+               {\r
+                       Free(c->Buffer);\r
+               }\r
+               Free(c);\r
+       }\r
+       ReleaseList(hamcore);\r
+\r
+       FileClose(hamcore_io);\r
+       hamcore_io = NULL;\r
+       hamcore = NULL;\r
+}\r
+\r
+// Hamcore のビルド\r
+void BuildHamcore()\r
+{\r
+       BUF *b;\r
+       char tmp[MAX_SIZE];\r
+       char exe_dir[MAX_SIZE];\r
+       char *s;\r
+       bool ok = true;\r
+       LIST *o;\r
+       UINT i;\r
+\r
+       GetExeDir(exe_dir, sizeof(exe_dir));\r
+       Format(tmp, sizeof(tmp), "%s/%s", exe_dir, HAMCORE_TEXT_NAME);\r
+\r
+       b = ReadDump(tmp);\r
+       if (b == NULL)\r
+       {\r
+               Print("Failed to open %s.\n", tmp);\r
+               return;\r
+       }\r
+\r
+       o = NewListFast(CompareHamcore);\r
+\r
+       while ((s = CfgReadNextLine(b)) != NULL)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               BUF *b;\r
+               Trim(s);\r
+\r
+               Format(tmp, sizeof(tmp), "%s/%s/%s", exe_dir, HAMCORE_DIR_NAME, s);\r
+\r
+               b = ReadDump(tmp);\r
+               if (b == NULL)\r
+               {\r
+                       Print("Failed to open %s.\n", s);\r
+                       ok = false;\r
+               }\r
+               else\r
+               {\r
+                       HC *c = ZeroMalloc(sizeof(HC));\r
+                       UINT tmp_size;\r
+                       void *tmp;\r
+                       c->FileName = CopyStr(s);\r
+                       c->Size = b->Size;\r
+                       tmp_size = CalcCompress(c->Size);\r
+                       tmp = Malloc(tmp_size);\r
+                       c->SizeCompressed = Compress(tmp, tmp_size, b->Buf, b->Size);\r
+                       c->Buffer = tmp;\r
+                       Insert(o, c);\r
+                       Print("%s: %u -> %u\n", s, c->Size, c->SizeCompressed);\r
+                       FreeBuf(b);\r
+               }\r
+\r
+               Free(s);\r
+       }\r
+\r
+       if (ok)\r
+       {\r
+               // 各ファイルのバッファのオフセットを計算する\r
+               UINT i, z;\r
+               char tmp[MAX_SIZE];\r
+               BUF *b;\r
+               z = 0;\r
+               z += HAMCORE_HEADER_SIZE;\r
+               // ファイルの個数\r
+               z += sizeof(UINT);\r
+               // まずファイルテーブル\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       HC *c = LIST_DATA(o, i);\r
+                       // ファイル名\r
+                       z += StrLen(c->FileName) + sizeof(UINT);\r
+                       // ファイルサイズ\r
+                       z += sizeof(UINT);\r
+                       z += sizeof(UINT);\r
+                       // オフセットデータ\r
+                       z += sizeof(UINT);\r
+               }\r
+               // ファイル本体\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       HC *c = LIST_DATA(o, i);\r
+                       // バッファ本体\r
+                       c->Offset = z;\r
+                       printf("%s: offset: %u\n", c->FileName, c->Offset);\r
+                       z += c->SizeCompressed;\r
+               }\r
+               // 書き込み\r
+               b = NewBuf();\r
+               // ヘッダ\r
+               WriteBuf(b, HAMCORE_HEADER_DATA, HAMCORE_HEADER_SIZE);\r
+               WriteBufInt(b, LIST_NUM(o));\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       HC *c = LIST_DATA(o, i);\r
+                       // ファイル名\r
+                       WriteBufStr(b, c->FileName);\r
+                       // ファイルサイズ\r
+                       WriteBufInt(b, c->Size);\r
+                       WriteBufInt(b, c->SizeCompressed);\r
+                       // オフセット\r
+                       WriteBufInt(b, c->Offset);\r
+               }\r
+               // 本体\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       HC *c = LIST_DATA(o, i);\r
+                       WriteBuf(b, c->Buffer, c->SizeCompressed);\r
+               }\r
+               // 書き込み\r
+               Format(tmp, sizeof(tmp), "%s/%s", exe_dir, HAMCORE_FILE_NAME "__");\r
+               Print("Writing %s...\n", tmp);\r
+               FileDelete(tmp);\r
+               DumpBuf(b, tmp);\r
+               FreeBuf(b);\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               HC *c = LIST_DATA(o, i);\r
+               Free(c->Buffer);\r
+               Free(c->FileName);\r
+               Free(c);\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// HC の比較\r
+int CompareHamcore(void *p1, void *p2)\r
+{\r
+       HC *c1, *c2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       c1 = *(HC **)p1;\r
+       c2 = *(HC **)p2;\r
+       if (c1 == NULL || c2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return StrCmpi(c1->FileName, c2->FileName);\r
+}\r
+\r
+// EXE ファイルがあるディレクトリ名の取得\r
+void GetExeDir(char *name, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetDirNameFromFilePath(name, size, exe_file_name);\r
+}\r
+void GetExeDirW(wchar_t *name, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetDirNameFromFilePathW(name, size, exe_file_name_w);\r
+}\r
+\r
+// EXE ファイル名の取得\r
+void GetExeName(char *name, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(name, size, exe_file_name);\r
+}\r
+void GetExeNameW(wchar_t *name, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniStrCpy(name, size, exe_file_name_w);\r
+}\r
+\r
+// EXE ファイル名の取得初期化\r
+void InitGetExeName(char *arg)\r
+{\r
+       wchar_t *arg_w = NULL;\r
+       // 引数チェック\r
+       if (arg == NULL)\r
+       {\r
+               arg = "./a.out";\r
+       }\r
+\r
+       arg_w = CopyUtfToUni(arg);\r
+\r
+#ifdef OS_WIN32\r
+       Win32GetExeNameW(exe_file_name_w, sizeof(exe_file_name_w));\r
+#else  // OS_WIN32\r
+       UnixGetExeNameW(exe_file_name_w, sizeof(exe_file_name_w), arg_w);\r
+#endif // OS_WIN32\r
+\r
+       UniToStr(exe_file_name, sizeof(exe_file_name), exe_file_name_w);\r
+\r
+       Free(arg_w);\r
+}\r
+\r
+// Unix における実行可能バイナリファイルのフルパスの取得\r
+void UnixGetExeNameW(wchar_t *name, UINT size, wchar_t *arg)\r
+{\r
+       UNI_TOKEN_LIST *t;\r
+       char *path_str;\r
+       wchar_t *path_str_w;\r
+       bool ok = false;\r
+       // 引数チェック\r
+       if (name == NULL || arg == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       path_str = GetCurrentPathEnvStr();\r
+       path_str_w = CopyUtfToUni(path_str);\r
+\r
+       t = ParseSplitedPathW(path_str_w);\r
+\r
+       if (t != NULL)\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < t->NumTokens;i++)\r
+               {\r
+                       wchar_t *s = t->Token[i];\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       ConbinePathW(tmp, sizeof(tmp), s, arg);\r
+\r
+                       if (IsFileExistsInnerW(tmp))\r
+                       {\r
+#ifdef OS_UNIX\r
+                               if (UnixCheckExecAccessW(tmp) == false)\r
+                               {\r
+                                       continue;\r
+                               }\r
+#endif // OS_UNIX\r
+                               ok = true;\r
+                               UniStrCpy(name, size, tmp);\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               UniFreeToken(t);\r
+       }\r
+\r
+       Free(path_str);\r
+       Free(path_str_w);\r
+\r
+       if (ok == false)\r
+       {\r
+               // パスの検索に失敗した場合\r
+#ifdef OS_UNIX\r
+               UnixGetCurrentDirW(name, size);\r
+#else  // OS_UNIX\r
+               Win32GetCurrentDirW(name, size);\r
+#endif // OS_UNIX\r
+               ConbinePathW(name, size, name, arg);\r
+       }\r
+}\r
+\r
+// 安全なファイル名を生成する\r
+void MakeSafeFileName(char *dst, UINT size, char *src)\r
+{\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), src);\r
+       ReplaceStrEx(tmp, sizeof(tmp), tmp, "..", "__", false);\r
+       ReplaceStrEx(tmp, sizeof(tmp), tmp, "/", "_", false);\r
+       ReplaceStrEx(tmp, sizeof(tmp), tmp, "\\", "_", false);\r
+       ReplaceStrEx(tmp, sizeof(tmp), tmp, "@", "_", false);\r
+       ReplaceStrEx(tmp, sizeof(tmp), tmp, "|", "_", false);\r
+\r
+       StrCpy(dst, size, tmp);\r
+}\r
+void MakeSafeFileNameW(wchar_t *dst, UINT size, wchar_t *src)\r
+{\r
+       wchar_t tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniStrCpy(tmp, sizeof(tmp), src);\r
+       UniReplaceStrEx(tmp, sizeof(tmp), tmp, L"..", L"__", false);\r
+       UniReplaceStrEx(tmp, sizeof(tmp), tmp, L"/", L"_", false);\r
+       UniReplaceStrEx(tmp, sizeof(tmp), tmp, L"\\", L"_", false);\r
+       UniReplaceStrEx(tmp, sizeof(tmp), tmp, L"@", L"_", false);\r
+       UniReplaceStrEx(tmp, sizeof(tmp), tmp, L"|", L"_", false);\r
+\r
+       UniStrCpy(dst, size, tmp);\r
+}\r
+\r
+// ファイルパスからファイル名を取得する\r
+void GetFileNameFromFilePathW(wchar_t *dst, UINT size, wchar_t *filepath)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       UINT i, len, wp;\r
+       // 引数チェック\r
+       if (dst == NULL || filepath == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       len = MIN(UniStrLen(filepath), (MAX_SIZE - 2));\r
+       wp = 0;\r
+\r
+       for (i = 0;i < (len + 1);i++)\r
+       {\r
+               wchar_t c = filepath[i];\r
+\r
+               switch (c)\r
+               {\r
+               case L'\\':\r
+               case L'/':\r
+               case 0:\r
+                       tmp[wp] = 0;\r
+                       wp = 0;\r
+                       break;\r
+\r
+               default:\r
+                       tmp[wp] = c;\r
+                       wp++;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       UniStrCpy(dst, size, tmp);\r
+}\r
+void GetFileNameFromFilePath(char *dst, UINT size, char *filepath)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UINT i, len, wp;\r
+       // 引数チェック\r
+       if (dst == NULL || filepath == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       len = MIN(StrLen(filepath), (MAX_SIZE - 2));\r
+       wp = 0;\r
+\r
+       for (i = 0;i < (len + 1);i++)\r
+       {\r
+               char c = filepath[i];\r
+\r
+               switch (c)\r
+               {\r
+               case '\\':\r
+               case '/':\r
+               case 0:\r
+                       tmp[wp] = 0;\r
+                       wp = 0;\r
+                       break;\r
+\r
+               default:\r
+                       tmp[wp] = c;\r
+                       wp++;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       StrCpy(dst, size, tmp);\r
+}\r
+void GetDirNameFromFilePathW(wchar_t *dst, UINT size, wchar_t *filepath)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       UINT wp;\r
+       UINT i;\r
+       UINT len;\r
+       // 引数チェック\r
+       if (dst == NULL || filepath == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniStrCpy(tmp, sizeof(tmp), filepath);\r
+       if (UniEndWith(tmp, L"\\") || UniEndWith(tmp, L"/"))\r
+       {\r
+               tmp[UniStrLen(tmp) - 1] = 0;\r
+       }\r
+\r
+       len = UniStrLen(tmp);\r
+\r
+       UniStrCpy(dst, size, L"");\r
+\r
+       wp = 0;\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               wchar_t c = tmp[i];\r
+               if (c == L'/' || c == L'\\')\r
+               {\r
+                       tmp[wp++] = 0;\r
+                       wp = 0;\r
+                       UniStrCat(dst, size, tmp);\r
+                       tmp[wp++] = c;\r
+               }\r
+               else\r
+               {\r
+                       tmp[wp++] = c;\r
+               }\r
+       }\r
+\r
+       if (UniStrLen(dst) == 0)\r
+       {\r
+               UniStrCpy(dst, size, L"/");\r
+       }\r
+\r
+       NormalizePathW(dst, size, dst);\r
+}\r
+\r
+// ファイルパスからディレクトリ名を取得する\r
+void GetDirNameFromFilePath(char *dst, UINT size, char *filepath)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UINT wp;\r
+       UINT i;\r
+       UINT len;\r
+       // 引数チェック\r
+       if (dst == NULL || filepath == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), filepath);\r
+       if (EndWith(tmp, "\\") || EndWith(tmp, "/"))\r
+       {\r
+               tmp[StrLen(tmp) - 1] = 0;\r
+       }\r
+\r
+       len = StrLen(tmp);\r
+\r
+       StrCpy(dst, size, "");\r
+\r
+       wp = 0;\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               char c = tmp[i];\r
+               if (c == '/' || c == '\\')\r
+               {\r
+                       tmp[wp++] = 0;\r
+                       wp = 0;\r
+                       StrCat(dst, size, tmp);\r
+                       tmp[wp++] = c;\r
+               }\r
+               else\r
+               {\r
+                       tmp[wp++] = c;\r
+               }\r
+       }\r
+\r
+       if (StrLen(dst) == 0)\r
+       {\r
+               StrCpy(dst, size, "/");\r
+       }\r
+\r
+       NormalizePath(dst, size, dst);\r
+}\r
+\r
+// 2 つのパスを結合する\r
+void ConbinePath(char *dst, UINT size, char *dirname, char *filename)\r
+{\r
+       wchar_t dst_w[MAX_PATH];\r
+       wchar_t *dirname_w = CopyStrToUni(dirname);\r
+       wchar_t *filename_w = CopyStrToUni(filename);\r
+\r
+       ConbinePathW(dst_w, sizeof(dst_w), dirname_w, filename_w);\r
+\r
+       Free(dirname_w);\r
+       Free(filename_w);\r
+\r
+       UniToStr(dst, size, dst_w);\r
+}\r
+void ConbinePathW(wchar_t *dst, UINT size, wchar_t *dirname, wchar_t *filename)\r
+{\r
+       bool is_full_path;\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t filename_ident[MAX_SIZE];\r
+       // 引数チェック\r
+       if (dst == NULL || dirname == NULL || filename == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       NormalizePathW(filename_ident, sizeof(filename_ident), filename);\r
+\r
+       is_full_path = false;\r
+\r
+       if (UniStartWith(filename_ident, L"\\") || UniStartWith(filename_ident, L"/"))\r
+       {\r
+               is_full_path = true;\r
+       }\r
+\r
+       filename = &filename_ident[0];\r
+\r
+#ifdef OS_WIN32\r
+       if (UniStrLen(filename) >= 2)\r
+       {\r
+               if ((L'a' <= filename[0] && filename[0] <= L'z') || (L'A' <= filename[0] && filename[0] <= L'Z'))\r
+               {\r
+                       if (filename[1] == L':')\r
+                       {\r
+                               is_full_path = true;\r
+                       }\r
+               }\r
+       }\r
+#endif // OS_WIN32\r
+\r
+       if (is_full_path == false)\r
+       {\r
+               UniStrCpy(tmp, sizeof(tmp), dirname);\r
+               if (UniEndWith(tmp, L"/") == false && UniEndWith(tmp, L"\\") == false)\r
+               {\r
+                       UniStrCat(tmp, sizeof(tmp), L"/");\r
+               }\r
+               UniStrCat(tmp, sizeof(tmp), filename);\r
+       }\r
+       else\r
+       {\r
+               UniStrCpy(tmp, sizeof(tmp), filename);\r
+       }\r
+\r
+       NormalizePathW(dst, size, tmp);\r
+}\r
+void CombinePath(char *dst, UINT size, char *dirname, char *filename)\r
+{\r
+       ConbinePath(dst, size, dirname, filename);\r
+}\r
+void CombinePathW(wchar_t *dst, UINT size, wchar_t *dirname, wchar_t *filename)\r
+{\r
+       ConbinePathW(dst, size, dirname, filename);\r
+}\r
+\r
+// ファイルが存在するかどうか確認する\r
+bool IsFileExists(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       bool ret = IsFileExistsW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+bool IsFileExistsW(wchar_t *name)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       InnerFilePathW(tmp, sizeof(tmp), name);\r
+\r
+       return IsFileExistsInnerW(tmp);\r
+}\r
+bool IsFileExistsInner(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       bool ret = IsFileExistsInnerW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+bool IsFileExistsInnerW(wchar_t *name)\r
+{\r
+       IO *o;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       o = FileOpenInnerW(name, false, false);\r
+       if (o == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       FileClose(o);\r
+\r
+       return true;\r
+}\r
+\r
+// 現在の環境変数 PATH の内容を取得\r
+char *GetCurrentPathEnvStr()\r
+{\r
+       char tmp[1024];\r
+       char *tag_name;\r
+\r
+#ifdef OS_WIN32\r
+       tag_name = "Path";\r
+#else  // OS_WIN32\r
+       tag_name = "PATH";\r
+#endif // OS_WIN32\r
+\r
+       if (GetEnv(tag_name, tmp, sizeof(tmp)) == false)\r
+       {\r
+#ifdef OS_WIN32\r
+               Win32GetCurrentDir(tmp, sizeof(tmp));\r
+#else  // OS_WIN32\r
+               UnixGetCurrentDir(tmp, sizeof(tmp));\r
+#endif // OS_WIN32\r
+       }\r
+\r
+       return CopyStr(tmp);\r
+}\r
+\r
+// コロン文字列で区切られた複数のパスを取得する\r
+UNI_TOKEN_LIST *ParseSplitedPathW(wchar_t *path)\r
+{\r
+       UNI_TOKEN_LIST *ret;\r
+       wchar_t *tmp = UniCopyStr(path);\r
+       wchar_t *split_str;\r
+       UINT i;\r
+\r
+       UniTrim(tmp);\r
+       UniTrimCrlf(tmp);\r
+       UniTrim(tmp);\r
+       UniTrimCrlf(tmp);\r
+\r
+#ifdef OS_WIN32\r
+       split_str = L";";\r
+#else  // OS_WIN32\r
+       split_str = L":";\r
+#endif // OS_WIN32\r
+\r
+       ret = UniParseToken(tmp, split_str);\r
+\r
+       if (ret != NULL)\r
+       {\r
+               for (i = 0;i < ret->NumTokens;i++)\r
+               {\r
+                       UniTrim(ret->Token[i]);\r
+                       UniTrimCrlf(ret->Token[i]);\r
+                       UniTrim(ret->Token[i]);\r
+                       UniTrimCrlf(ret->Token[i]);\r
+               }\r
+       }\r
+\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+TOKEN_LIST *ParseSplitedPath(char *path)\r
+{\r
+       TOKEN_LIST *ret;\r
+       char *tmp = CopyStr(path);\r
+       char *split_str;\r
+       UINT i;\r
+\r
+       Trim(tmp);\r
+       TrimCrlf(tmp);\r
+       Trim(tmp);\r
+       TrimCrlf(tmp);\r
+\r
+#ifdef OS_WIN32\r
+       split_str = ";";\r
+#else  // OS_WIN32\r
+       split_str = ":";\r
+#endif // OS_WIN32\r
+\r
+       ret = ParseToken(tmp, split_str);\r
+\r
+       if (ret != NULL)\r
+       {\r
+               for (i = 0;i < ret->NumTokens;i++)\r
+               {\r
+                       Trim(ret->Token[i]);\r
+                       TrimCrlf(ret->Token[i]);\r
+                       Trim(ret->Token[i]);\r
+                       TrimCrlf(ret->Token[i]);\r
+               }\r
+       }\r
+\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// 現在のディレクトリを取得する\r
+void GetCurrentDirW(wchar_t *name, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       Win32GetCurrentDirW(name, size);\r
+#else  // OS_WIN32\r
+       UnixGetCurrentDirW(name, size);\r
+#endif // OS_WIN32\r
+}\r
+void GetCurrentDir(char *name, UINT size)\r
+{\r
+       wchar_t name_w[MAX_PATH];\r
+\r
+       GetCurrentDirW(name_w, sizeof(name_w));\r
+\r
+       UniToStr(name, size, name_w);\r
+}\r
+\r
+// ファイルパスを正規化する\r
+void NormalizePathW(wchar_t *dst, UINT size, wchar_t *src)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       UNI_TOKEN_LIST *t;\r
+       bool first_double_slash = false;\r
+       bool first_single_slash = false;\r
+       wchar_t win32_drive_char = 0;\r
+       bool is_full_path = false;\r
+       UINT i;\r
+       SK *sk;\r
+       // 引数チェック\r
+       if (dst == NULL || src == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // パスを変換する (Win32, UNIX 変換)\r
+       UniStrCpy(tmp, sizeof(tmp), src);\r
+       ConvertPathW(tmp);\r
+       UniTrim(tmp);\r
+\r
+       // 先頭が "./" や "../" で始まっている場合はカレントディレクトリに置換する\r
+       if (UniStartWith(tmp, L"./") || UniStartWith(tmp, L".\\") ||\r
+               UniStartWith(tmp, L"../") || UniStartWith(tmp, L"..\\") ||\r
+               UniStrCmpi(tmp, L".") == 0 || UniStrCmpi(tmp, L"..") == 0)\r
+       {\r
+               wchar_t cd[MAX_SIZE];\r
+               Zero(cd, sizeof(cd));\r
+\r
+#ifdef OS_WIN32\r
+               Win32GetCurrentDirW(cd, sizeof(cd));\r
+#else  // OS_WIN32\r
+               UnixGetCurrentDirW(cd, sizeof(cd));\r
+#endif // OS_WIN32\r
+\r
+               if (UniStartWith(tmp, L".."))\r
+               {\r
+                       UniStrCat(cd, sizeof(cd), L"/../");\r
+                       UniStrCat(cd, sizeof(cd), tmp + 2);\r
+               }\r
+               else\r
+               {\r
+                       UniStrCat(cd, sizeof(cd), L"/");\r
+                       UniStrCat(cd, sizeof(cd), tmp);\r
+               }\r
+\r
+               UniStrCpy(tmp, sizeof(tmp), cd);\r
+       }\r
+\r
+       // 先頭が "~/" で始まっている場合はホームディレクトリに置換する\r
+       if (UniStartWith(tmp, L"~/") || UniStartWith(tmp, L"~\\"))\r
+       {\r
+               wchar_t tmp2[MAX_SIZE];\r
+               GetHomeDirW(tmp2, sizeof(tmp2));\r
+               UniStrCat(tmp2, sizeof(tmp2), L"/");\r
+               UniStrCat(tmp2, sizeof(tmp2), tmp + 2);\r
+               UniStrCpy(tmp, sizeof(tmp), tmp2);\r
+       }\r
+\r
+       if (UniStartWith(tmp, L"//") || UniStartWith(tmp, L"\\\\"))\r
+       {\r
+               // 最初が "//" または "\\" で始まる\r
+               first_double_slash = true;\r
+               is_full_path = true;\r
+       }\r
+       else if (UniStartWith(tmp, L"/") || UniStartWith(tmp, L"\\"))\r
+       {\r
+               // 最初が "\" で始まる\r
+               first_single_slash = true;\r
+               is_full_path = true;\r
+       }\r
+\r
+       if (UniStrLen(tmp) >= 2)\r
+       {\r
+               if (tmp[1] == L':')\r
+               {\r
+                       if (OS_IS_WINDOWS(GetOsInfo()->OsType))\r
+                       {\r
+                               // Win32 のドライブ文字列表記\r
+                               wchar_t tmp2[MAX_SIZE];\r
+                               is_full_path = true;\r
+                               win32_drive_char = tmp[0];\r
+                               UniStrCpy(tmp2, sizeof(tmp2), tmp + 2);\r
+                               UniStrCpy(tmp, sizeof(tmp), tmp2);\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (UniStrLen(tmp) == 1 && (tmp[0] == L'/' || tmp[0] == L'\\'))\r
+       {\r
+               tmp[0] = 0;\r
+       }\r
+\r
+       // トークン分割\r
+       t = UniParseToken(tmp, L"/\\");\r
+\r
+       sk = NewSk();\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               wchar_t *s = t->Token[i];\r
+\r
+               if (UniStrCmpi(s, L".") == 0)\r
+               {\r
+                       continue;\r
+               }\r
+               else if (UniStrCmpi(s, L"..") == 0)\r
+               {\r
+                       if (sk->num_item >= 1 && (first_double_slash == false || sk->num_item >= 2))\r
+                       {\r
+                               Pop(sk);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       Push(sk, s);\r
+               }\r
+       }\r
+\r
+       // トークン結合\r
+       UniStrCpy(tmp, sizeof(tmp), L"");\r
+\r
+       if (first_double_slash)\r
+       {\r
+               UniStrCat(tmp, sizeof(tmp), L"//");\r
+       }\r
+       else if (first_single_slash)\r
+       {\r
+               UniStrCat(tmp, sizeof(tmp), L"/");\r
+       }\r
+\r
+       if (win32_drive_char != 0)\r
+       {\r
+               wchar_t d[2];\r
+               d[0] = win32_drive_char;\r
+               d[1] = 0;\r
+               UniStrCat(tmp, sizeof(tmp), d);\r
+               UniStrCat(tmp, sizeof(tmp), L":/");\r
+       }\r
+\r
+       for (i = 0;i < sk->num_item;i++)\r
+       {\r
+               UniStrCat(tmp, sizeof(tmp), (wchar_t *)sk->p[i]);\r
+               if (i != (sk->num_item - 1))\r
+               {\r
+                       UniStrCat(tmp, sizeof(tmp), L"/");\r
+               }\r
+       }\r
+\r
+       ReleaseSk(sk);\r
+\r
+       UniFreeToken(t);\r
+\r
+       ConvertPathW(tmp);\r
+\r
+       UniStrCpy(dst, size, tmp);\r
+}\r
+void NormalizePath(char *dst, UINT size, char *src)\r
+{\r
+       wchar_t dst_w[MAX_SIZE];\r
+       wchar_t *src_w = CopyStrToUni(src);\r
+\r
+       NormalizePathW(dst_w, sizeof(dst_w), src_w);\r
+\r
+       Free(src_w);\r
+\r
+       UniToStr(dst, size, dst_w);\r
+}\r
+\r
+// ファイルを閉じて削除する\r
+void FileCloseAndDelete(IO *o)\r
+{\r
+       wchar_t *name;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       name = CopyUniStr(o->NameW);\r
+       FileClose(o);\r
+\r
+       FileDeleteW(name);\r
+\r
+       Free(name);\r
+}\r
+\r
+// ファイル名の変更\r
+bool FileRename(char *old_name, char *new_name)\r
+{\r
+       wchar_t *old_name_w = CopyStrToUni(old_name);\r
+       wchar_t *new_name_w = CopyStrToUni(new_name);\r
+       bool ret = FileRenameW(old_name_w, new_name_w);\r
+\r
+       Free(old_name_w);\r
+       Free(new_name_w);\r
+\r
+       return ret;\r
+}\r
+bool FileRenameW(wchar_t *old_name, wchar_t *new_name)\r
+{\r
+       wchar_t tmp1[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (old_name == NULL || new_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       InnerFilePathW(tmp1, sizeof(tmp1), old_name);\r
+       InnerFilePathW(tmp2, sizeof(tmp2), new_name);\r
+\r
+       return FileRenameInnerW(tmp1, tmp2);\r
+}\r
+bool FileRenameInner(char *old_name, char *new_name)\r
+{\r
+       wchar_t *old_name_w = CopyStrToUni(old_name);\r
+       wchar_t *new_name_w = CopyStrToUni(new_name);\r
+       bool ret = FileRenameInnerW(old_name_w, new_name_w);\r
+\r
+       Free(old_name_w);\r
+       Free(new_name_w);\r
+\r
+       return ret;\r
+}\r
+bool FileRenameInnerW(wchar_t *old_name, wchar_t *new_name)\r
+{\r
+       // 引数チェック\r
+       if (old_name == NULL || new_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return OSFileRenameW(old_name, new_name);\r
+}\r
+\r
+// パスの変換\r
+void ConvertPath(char *path)\r
+{\r
+       UINT i, len;\r
+#ifdef PATH_BACKSLASH\r
+       char new_char = '\\';\r
+#else\r
+       char new_char = '/';\r
+#endif\r
+\r
+       len = StrLen(path);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (path[i] == '\\' || path[i] == '/')\r
+               {\r
+                       path[i] = new_char;\r
+               }\r
+       }\r
+}\r
+void ConvertPathW(wchar_t *path)\r
+{\r
+       UINT i, len;\r
+#ifdef PATH_BACKSLASH\r
+       wchar_t new_char = L'\\';\r
+#else\r
+       wchar_t new_char = L'/';\r
+#endif\r
+\r
+       len = UniStrLen(path);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (path[i] == L'\\' || path[i] == L'/')\r
+               {\r
+                       path[i] = new_char;\r
+               }\r
+       }\r
+}\r
+\r
+// ディレクトリの削除\r
+bool DeleteDir(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       bool ret = DeleteDirW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+bool DeleteDirW(wchar_t *name)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       InnerFilePathW(tmp, sizeof(tmp), name);\r
+\r
+       return DeleteDirInnerW(tmp);\r
+}\r
+bool DeleteDirInner(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       bool ret = DeleteDirInnerW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+bool DeleteDirInnerW(wchar_t *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return OSDeleteDirW(name);\r
+}\r
+\r
+// 内部ファイルパスの生成\r
+void InnerFilePathW(wchar_t *dst, UINT size, wchar_t *src)\r
+{\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (src[0] != L'@')\r
+       {\r
+               NormalizePathW(dst, size, src);\r
+       }\r
+       else\r
+       {\r
+               wchar_t dir[MAX_SIZE];\r
+               GetExeDirW(dir, sizeof(dir));\r
+               ConbinePathW(dst, size, dir, &src[1]);\r
+       }\r
+}\r
+void InnerFilePath(char *dst, UINT size, char *src)\r
+{\r
+       wchar_t dst_w[MAX_PATH];\r
+       wchar_t *src_w = CopyStrToUni(src);\r
+\r
+       InnerFilePathW(dst_w, sizeof(dst_w), src_w);\r
+\r
+       Free(src_w);\r
+\r
+       UniToStr(dst, size, dst_w);\r
+}\r
+\r
+// ディレクトリの再帰作成\r
+void MakeDirEx(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+\r
+       MakeDirExW(name_w);\r
+\r
+       Free(name_w);\r
+}\r
+void MakeDirExW(wchar_t *name)\r
+{\r
+       LIST *o;\r
+       wchar_t tmp[MAX_PATH];\r
+       wchar_t tmp2[MAX_PATH];\r
+       UINT i;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       UniStrCpy(tmp, sizeof(tmp), name);\r
+       while (true)\r
+       {\r
+               wchar_t *s = CopyUniStr(tmp);\r
+\r
+               Add(o, s);\r
+\r
+               GetDirNameFromFilePathW(tmp2, sizeof(tmp2), tmp);\r
+\r
+               if (UniStrCmpi(tmp2, tmp) == 0)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               UniStrCpy(tmp, sizeof(tmp), tmp2);\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               UINT j = LIST_NUM(o) - i - 1;\r
+               wchar_t *s = LIST_DATA(o, j);\r
+\r
+               if (UniStrCmpi(s, L"\\") != 0 && UniStrCmpi(s, L"/") != 0)\r
+               {\r
+                       MakeDirW(s);\r
+               }\r
+       }\r
+\r
+       UniFreeStrList(o);\r
+}\r
+\r
+// ディレクトリの作成\r
+bool MakeDir(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       bool ret = MakeDirW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+bool MakeDirW(wchar_t *name)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       InnerFilePathW(tmp, sizeof(tmp), name);\r
+\r
+       return MakeDirInnerW(tmp);\r
+}\r
+bool MakeDirInner(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       bool ret = MakeDirInnerW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+bool MakeDirInnerW(wchar_t *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return OSMakeDirW(name);\r
+}\r
+\r
+// ファイルの削除\r
+bool FileDelete(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       bool ret = FileDeleteW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+bool FileDeleteW(wchar_t *name)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       InnerFilePathW(tmp, sizeof(tmp), name);\r
+\r
+       return FileDeleteInnerW(tmp);\r
+}\r
+bool FileDeleteInner(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       bool ret = FileDeleteInnerW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+bool FileDeleteInnerW(wchar_t *name)\r
+{\r
+       wchar_t name2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniStrCpy(name2, sizeof(name2), name);\r
+       ConvertPathW(name2);\r
+\r
+       return OSFileDeleteW(name2);\r
+}\r
+\r
+// ファイルをシークする\r
+bool FileSeek(IO *o, UINT mode, int offset)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (o->HamMode == false)\r
+       {\r
+               return OSFileSeek(o->pData, mode, offset);\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// ファイル名を指定してファイルサイズを取得する\r
+UINT FileSizeEx(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       UINT ret = FileSizeExW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+UINT FileSizeExW(wchar_t *name)\r
+{\r
+       IO *io;\r
+       UINT size;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       io = FileOpenW(name, false);\r
+       if (io == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       size = FileSize(io);\r
+\r
+       FileClose(io);\r
+\r
+       return size;\r
+}\r
+\r
+// ファイルサイズを取得する\r
+UINT64 FileSize64(IO *o)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (o->HamMode == false)\r
+       {\r
+               return OSFileSize(o->pData);\r
+       }\r
+       else\r
+       {\r
+               return (UINT64)o->HamBuf->Size;\r
+       }\r
+}\r
+UINT FileSize(IO *o)\r
+{\r
+       UINT64 size = (UINT)(FileSize64(o));\r
+\r
+       if (size >= 4294967296ULL)\r
+       {\r
+               size = 4294967295ULL;\r
+       }\r
+\r
+       return (UINT)size;\r
+}\r
+\r
+// ファイルから読み込む\r
+bool FileRead(IO *o, void *buf, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_IO_READ_COUNT);\r
+       KS_ADD(KS_IO_TOTAL_READ_SIZE, size);\r
+\r
+       if (size == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (o->HamMode == false)\r
+       {\r
+               return OSFileRead(o->pData, buf, size);\r
+       }\r
+       else\r
+       {\r
+               return ReadBuf(o->HamBuf, buf, size) == size ? true : false;\r
+       }\r
+}\r
+\r
+// ファイルに書き込む\r
+bool FileWrite(IO *o, void *buf, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || buf == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (o->WriteMode == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_IO_WRITE_COUNT);\r
+       KS_ADD(KS_IO_TOTAL_WRITE_SIZE, size);\r
+\r
+       if (size == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return OSFileWrite(o->pData, buf, size);\r
+}\r
+\r
+// ファイルをフラッシュする\r
+void FileFlush(IO *o)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (o->HamMode)\r
+       {\r
+               return;\r
+       }\r
+\r
+       OSFileFlush(o->pData);\r
+}\r
+\r
+// ファイルを閉じる\r
+void FileClose(IO *o)\r
+{\r
+       FileCloseEx(o, false);\r
+}\r
+void FileCloseEx(IO *o, bool no_flush)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (o->HamMode == false)\r
+       {\r
+               OSFileClose(o->pData, no_flush);\r
+       }\r
+       else\r
+       {\r
+               FreeBuf(o->HamBuf);\r
+       }\r
+       Free(o);\r
+\r
+       // KS\r
+       KS_INC(KS_IO_CLOSE_COUNT);\r
+}\r
+\r
+// ファイルを作成する\r
+IO *FileCreateInner(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       IO *ret = FileCreateInnerW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+IO *FileCreateInnerW(wchar_t *name)\r
+{\r
+       IO *o;\r
+       void *p;\r
+       wchar_t name2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       UniStrCpy(name2, sizeof(name2), name);\r
+       ConvertPathW(name2);\r
+\r
+       p = OSFileCreateW(name2);\r
+       if (p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = ZeroMalloc(sizeof(IO));\r
+       o->pData = p;\r
+       UniStrCpy(o->NameW, sizeof(o->NameW), name2);\r
+       UniToStr(o->Name, sizeof(o->Name), o->NameW);\r
+       o->WriteMode = true;\r
+\r
+       // KS\r
+       KS_INC(KS_IO_CREATE_COUNT);\r
+\r
+       return o;\r
+}\r
+IO *FileCreate(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       IO *ret = FileCreateW(name_w);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+IO *FileCreateW(wchar_t *name)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       InnerFilePathW(tmp, sizeof(tmp), name);\r
+\r
+       return FileCreateInnerW(tmp);\r
+}\r
+\r
+// ファイルにすべてのデータを書き込む\r
+bool FileWriteAll(char *name, void *data, UINT size)\r
+{\r
+       IO *io;\r
+       // 引数チェック\r
+       if (name == NULL || (data == NULL && size != 0))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       io = FileCreate(name);\r
+\r
+       if (io == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       FileWrite(io, data, size);\r
+\r
+       FileClose(io);\r
+\r
+       return true;\r
+}\r
+bool FileWriteAllW(wchar_t *name, void *data, UINT size)\r
+{\r
+       IO *io;\r
+       // 引数チェック\r
+       if (name == NULL || (data == NULL && size != 0))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       io = FileCreateW(name);\r
+\r
+       if (io == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       FileWrite(io, data, size);\r
+\r
+       FileClose(io);\r
+\r
+       return true;\r
+}\r
+\r
+// ファイルを開く\r
+IO *FileOpenInner(char *name, bool write_mode, bool read_lock)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       IO *ret = FileOpenInnerW(name_w, write_mode, read_lock);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+IO *FileOpenInnerW(wchar_t *name, bool write_mode, bool read_lock)\r
+{\r
+       IO *o;\r
+       void *p;\r
+       wchar_t name2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       UniStrCpy(name2, sizeof(name2), name);\r
+       ConvertPathW(name2);\r
+\r
+       p = OSFileOpenW(name2, write_mode, read_lock);\r
+       if (p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = ZeroMalloc(sizeof(IO));\r
+       o->pData = p;\r
+       UniStrCpy(o->NameW, sizeof(o->NameW), name2);\r
+       UniToStr(o->Name, sizeof(o->Name), o->NameW);\r
+       o->WriteMode = write_mode;\r
+\r
+       // KS\r
+       KS_INC(KS_IO_OPEN_COUNT);\r
+\r
+       return o;\r
+}\r
+IO *FileOpen(char *name, bool write_mode)\r
+{\r
+       return FileOpenEx(name, write_mode, true);\r
+}\r
+IO *FileOpenW(wchar_t *name, bool write_mode)\r
+{\r
+       return FileOpenExW(name, write_mode, true);\r
+}\r
+IO *FileOpenEx(char *name, bool write_mode, bool read_lock)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+       IO *ret = FileOpenExW(name_w, write_mode, read_lock);\r
+\r
+       Free(name_w);\r
+\r
+       return ret;\r
+}\r
+IO *FileOpenExW(wchar_t *name, bool write_mode, bool read_lock)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       InnerFilePathW(tmp, sizeof(tmp), name);\r
+\r
+       if (name[0] == L'|')\r
+       {\r
+               IO *o = ZeroMalloc(sizeof(IO));\r
+               name++;\r
+               UniStrCpy(o->NameW, sizeof(o->NameW), name);\r
+               UniToStr(o->Name, sizeof(o->Name), o->NameW);\r
+               o->HamMode = true;\r
+               o->HamBuf = ReadHamcoreW(name);\r
+               if (o->HamBuf == NULL)\r
+               {\r
+                       Free(o);\r
+                       return NULL;\r
+               }\r
+               return o;\r
+       }\r
+       else\r
+       {\r
+               return FileOpenInnerW(tmp, write_mode, read_lock);\r
+       }\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/FileIO.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/FileIO.h
new file mode 100644 (file)
index 0000000..277c068
--- /dev/null
@@ -0,0 +1,235 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// FileIO.h\r
+// FileIO.c のヘッダ\r
+\r
+#ifndef        FILEIO_H\r
+#define        FILEIO_H\r
+\r
+// 定数\r
+#define        HAMCORE_DIR_NAME                        "hamcore"\r
+#define        HAMCORE_FILE_NAME                       "hamcore.utvpn"\r
+#define        HAMCORE_FILE_NAME_2                     "_hamcore.utvpn"\r
+#define        HAMCORE_TEXT_NAME                       "hamcore.txt"\r
+#define        HAMCORE_HEADER_DATA                     "HamCore"\r
+#define        HAMCORE_HEADER_SIZE                     7\r
+#define        HAMCORE_CACHE_EXPIRES           (5 * 60 * 1000)\r
+\r
+// IO 構造体\r
+struct IO\r
+{\r
+       char Name[MAX_SIZE];\r
+       wchar_t NameW[MAX_SIZE];\r
+       void *pData;\r
+       bool WriteMode;\r
+       bool HamMode;\r
+       BUF *HamBuf;\r
+};\r
+\r
+// HC 構造体\r
+typedef struct HC\r
+{\r
+       char *FileName;                         // ファイル名\r
+       UINT Size;                                      // ファイルサイズ\r
+       UINT SizeCompressed;            // 圧縮されたファイルサイズ\r
+       UINT Offset;                            // オフセット\r
+       void *Buffer;                           // バッファ\r
+       UINT64 LastAccess;                      // 最後にアクセスした日時\r
+} HC;\r
+\r
+// DIRENT 構造体\r
+struct DIRENT\r
+{\r
+       bool Folder;                            // フォルダ\r
+       char *FileName;                         // ファイル名 (ANSI)\r
+       wchar_t *FileNameW;                     // ファイル名 (Unicode)\r
+       UINT64 FileSize;                        // ファイルサイズ\r
+       UINT64 CreateDate;                      // 作成日時\r
+       UINT64 UpdateDate;                      // 更新日時\r
+};\r
+\r
+// DIRLIST 構造体\r
+struct DIRLIST\r
+{\r
+       UINT NumFiles;                          // ファイル数\r
+       struct DIRENT **File;                   // ファイル配列\r
+};\r
+\r
+bool DeleteDirInner(char *name);\r
+bool DeleteDirInnerW(wchar_t *name);\r
+bool DeleteDir(char *name);\r
+bool DeleteDirW(wchar_t *name);\r
+bool MakeDirInner(char *name);\r
+bool MakeDirInnerW(wchar_t *name);\r
+bool MakeDir(char *name);\r
+bool MakeDirW(wchar_t *name);\r
+void MakeDirEx(char *name);\r
+void MakeDirExW(wchar_t *name);\r
+bool FileDeleteInner(char *name);\r
+bool FileDeleteInnerW(wchar_t *name);\r
+bool FileDelete(char *name);\r
+bool FileDeleteW(wchar_t *name);\r
+bool FileSeek(IO *o, UINT mode, int offset);\r
+UINT FileSize(IO *o);\r
+UINT64 FileSize64(IO *o);\r
+UINT FileSizeEx(char *name);\r
+UINT FileSizeExW(wchar_t *name);\r
+UINT FileRead(IO *o, void *buf, UINT size);\r
+UINT FileWrite(IO *o, void *buf, UINT size);\r
+void FileFlush(IO *o);\r
+void FileClose(IO *o);\r
+void FileCloseEx(IO *o, bool no_flush);\r
+void FileCloseAndDelete(IO *o);\r
+IO *FileCreateInner(char *name);\r
+IO *FileCreateInnerW(wchar_t *name);\r
+IO *FileCreate(char *name);\r
+IO *FileCreateW(wchar_t *name);\r
+bool FileWriteAll(char *name, void *data, UINT size);\r
+bool FileWriteAllW(wchar_t *name, void *data, UINT size);\r
+IO *FileOpenInner(char *name, bool write_mode, bool read_lock);\r
+IO *FileOpenInnerW(wchar_t *name, bool write_mode, bool read_lock);\r
+IO *FileOpen(char *name, bool write_mode);\r
+IO *FileOpenW(wchar_t *name, bool write_mode);\r
+IO *FileOpenEx(char *name, bool write_mode, bool read_lock);\r
+IO *FileOpenExW(wchar_t *name, bool write_mode, bool read_lock);\r
+void ConvertPath(char *path);\r
+void ConvertPathW(wchar_t *path);\r
+bool FileRenameInner(char *old_name, char *new_name);\r
+bool FileRenameInnerW(wchar_t *old_name, wchar_t *new_name);\r
+bool FileRename(char *old_name, char *new_name);\r
+bool FileRenameW(wchar_t *old_name, wchar_t *new_name);\r
+void NormalizePath(char *dst, UINT size, char *src);\r
+void NormalizePathW(wchar_t *dst, UINT size, wchar_t *src);\r
+TOKEN_LIST *ParseSplitedPath(char *path);\r
+UNI_TOKEN_LIST *ParseSplitedPathW(wchar_t *path);\r
+char *GetCurrentPathEnvStr();\r
+bool IsFileExistsInner(char *name);\r
+bool IsFileExistsInnerW(wchar_t *name);\r
+bool IsFileExists(char *name);\r
+bool IsFileExistsW(wchar_t *name);\r
+void InnerFilePath(char *dst, UINT size, char *src);\r
+void InnerFilePathW(wchar_t *dst, UINT size, wchar_t *src);\r
+void ConbinePath(char *dst, UINT size, char *dirname, char *filename);\r
+void ConbinePathW(wchar_t *dst, UINT size, wchar_t *dirname, wchar_t *filename);\r
+void CombinePath(char *dst, UINT size, char *dirname, char *filename);\r
+void CombinePathW(wchar_t *dst, UINT size, wchar_t *dirname, wchar_t *filename);\r
+void GetDirNameFromFilePath(char *dst, UINT size, char *filepath);\r
+void GetDirNameFromFilePathW(wchar_t *dst, UINT size, wchar_t *filepath);\r
+void GetFileNameFromFilePath(char *dst, UINT size, char *filepath);\r
+void GetFileNameFromFilePathW(wchar_t *dst, UINT size, wchar_t *filepath);\r
+void MakeSafeFileName(char *dst, UINT size, char *src);\r
+void MakeSafeFileNameW(wchar_t *dst, UINT size, wchar_t *src);\r
+void InitGetExeName(char *arg);\r
+void UnixGetExeNameW(wchar_t *name, UINT size, wchar_t *arg);\r
+void GetExeName(char *name, UINT size);\r
+void GetExeNameW(wchar_t *name, UINT size);\r
+void GetExeDir(char *name, UINT size);\r
+void GetExeDirW(wchar_t *name, UINT size);\r
+void BuildHamcore();\r
+int CompareHamcore(void *p1, void *p2);\r
+void InitHamcore();\r
+void FreeHamcore();\r
+BUF *ReadHamcore(char *name);\r
+BUF *ReadHamcoreW(wchar_t *filename);\r
+void SafeFileName(char *name);\r
+void SafeFileNameW(wchar_t *name);\r
+void UniSafeFileName(wchar_t *name);\r
+DIRLIST *EnumDir(char *dirname);\r
+DIRLIST *EnumDirW(wchar_t *dirname);\r
+DIRLIST *EnumDirEx(char *dirname, COMPARE *compare);\r
+DIRLIST *EnumDirExW(wchar_t *dirname, COMPARE *compare);\r
+void FreeDir(DIRLIST *d);\r
+int CompareDirListByName(void *p1, void *p2);\r
+bool GetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size);\r
+bool GetDiskFreeW(wchar_t *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size);\r
+void ConvertSafeFileName(char *dst, UINT size, char *src);\r
+void ConvertSafeFileNameW(wchar_t *dst, UINT size, wchar_t *src);\r
+bool FileReplaceRename(char *old_name, char *new_name);\r
+bool FileReplaceRenameW(wchar_t *old_name, wchar_t *new_name);\r
+bool IsFile(char *name);\r
+bool IsFileW(wchar_t *name);\r
+void GetCurrentDirW(wchar_t *name, UINT size);\r
+void GetCurrentDir(char *name, UINT size);\r
+bool SaveFileW(wchar_t *name, void *data, UINT size);\r
+bool SaveFile(char *name, void *data, UINT size);\r
+\r
+\r
+#endif // FILEIO_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Internat.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Internat.c
new file mode 100644 (file)
index 0000000..6b2400d
--- /dev/null
@@ -0,0 +1,3396 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Internat.c\r
+// 国際化のための文字列変換ライブラリ\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+extern LOCK *token_lock;\r
+static char charset[MAX_SIZE] = "EUCJP";\r
+static LOCK *iconv_lock = NULL;\r
+void *iconv_cache_wide_to_str = 0;\r
+void *iconv_cache_str_to_wide = 0;\r
+\r
+// 文字列が含まれているかどうかチェック\r
+bool UniInStr(wchar_t *str, wchar_t *keyword)\r
+{\r
+       return UniInStrEx(str, keyword, false);\r
+}\r
+bool UniInStrEx(wchar_t *str, wchar_t *keyword, bool case_sensitive)\r
+{\r
+       // 引数チェック\r
+       if (UniIsEmptyStr(str) || UniIsEmptyStr(keyword))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (UniSearchStrEx(str, keyword, 0, case_sensitive) == INFINITE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// バイナリデータに変換\r
+BUF *UniStrToBin(wchar_t *str)\r
+{\r
+       char *str_a = CopyUniToStr(str);\r
+       BUF *ret;\r
+\r
+       ret = StrToBin(str_a);\r
+\r
+       Free(str_a);\r
+\r
+       return ret;\r
+}\r
+\r
+// 指定した文字の列を生成する\r
+wchar_t *UniMakeCharArray(wchar_t c, UINT count)\r
+{\r
+       UINT i;\r
+       wchar_t *ret = Malloc(sizeof(wchar_t) * (count + 1));\r
+\r
+       for (i = 0;i < count;i++)\r
+       {\r
+               ret[i] = c;\r
+       }\r
+\r
+       ret[count] = 0;\r
+\r
+       return ret;\r
+}\r
+\r
+// 安全な文字かどうかチェック\r
+bool UniIsSafeChar(wchar_t c)\r
+{\r
+       UINT i, len;\r
+       wchar_t *check_str =\r
+               L"ABCDEFGHIJKLMNOPQRSTUVWXYZ"\r
+               L"abcdefghijklmnopqrstuvwxyz"\r
+               L"0123456789"\r
+               L" ()-_#%&.";\r
+\r
+       len = UniStrLen(check_str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (c == check_str[i])\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+       return false;\r
+}\r
+\r
+// トークンリストを文字列リストに変換する\r
+LIST *UniTokenListToList(UNI_TOKEN_LIST *t)\r
+{\r
+       UINT i;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               Insert(o, UniCopyStr(t->Token[i]));\r
+       }\r
+\r
+       return o;\r
+}\r
+\r
+// 文字列リストをトークンリストに変換する\r
+UNI_TOKEN_LIST *UniListToTokenList(LIST *o)\r
+{\r
+       UINT i;\r
+       UNI_TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t = ZeroMalloc(sizeof(UNI_TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(wchar_t *) * t->NumTokens);\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               t->Token[i] = UniCopyStr(LIST_DATA(o, i));\r
+       }\r
+\r
+       return t;\r
+}\r
+\r
+// 文字列リストを解放する\r
+void UniFreeStrList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               wchar_t *s = LIST_DATA(o, i);\r
+               Free(s);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// 文字列リストを文字列に変換する\r
+BUF *UniStrListToStr(LIST *o)\r
+{\r
+       BUF *b;\r
+       UINT i;\r
+       wchar_t c;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       b = NewBuf();\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               wchar_t *s = LIST_DATA(o, i);\r
+               WriteBuf(b, s, UniStrSize(s));\r
+       }\r
+\r
+       c = 0;\r
+       WriteBuf(b, &c, sizeof(c));\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       return b;\r
+}\r
+\r
+// 文字列 (NULL区切り) をリストに変換する\r
+LIST *UniStrToStrList(wchar_t *str, UINT size)\r
+{\r
+       LIST *o;\r
+       wchar_t *tmp;\r
+       UINT tmp_size;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       i = 0;\r
+       while (true)\r
+       {\r
+               if (i >= size)\r
+               {\r
+                       break;\r
+               }\r
+               if (*str == 0)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               tmp_size = UniStrSize(str);\r
+               tmp = ZeroMalloc(tmp_size);\r
+               UniStrCpy(tmp, tmp_size, str);\r
+               Add(o, tmp);\r
+               str += UniStrLen(str) + 1;\r
+               i++;\r
+       }\r
+\r
+       return o;\r
+}\r
+\r
+// 改行コードを正規化する\r
+wchar_t *UniNormalizeCrlf(wchar_t *str)\r
+{\r
+       wchar_t *ret;\r
+       UINT ret_size, i, len, wp;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       len = UniStrLen(str);\r
+       ret_size = sizeof(wchar_t) * (len + 32) * 2;\r
+       ret = Malloc(ret_size);\r
+\r
+       wp = 0;\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               wchar_t c = str[i];\r
+\r
+               switch (c)\r
+               {\r
+               case L'\r':\r
+                       if (str[i + 1] == L'\n')\r
+                       {\r
+                               i++;\r
+                       }\r
+                       ret[wp++] = L'\r';\r
+                       ret[wp++] = L'\n';\r
+                       break;\r
+\r
+               case L'\n':\r
+                       ret[wp++] = L'\r';\r
+                       ret[wp++] = L'\n';\r
+                       break;\r
+\r
+               default:\r
+                       ret[wp++] = c;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       ret[wp++] = 0;\r
+\r
+       return ret;\r
+}\r
+\r
+// str が key で終了するかどうかチェック\r
+bool UniEndWith(wchar_t *str, wchar_t *key)\r
+{\r
+       UINT str_len;\r
+       UINT key_len;\r
+       // 引数チェック\r
+       if (str == NULL || key == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 比較\r
+       str_len = UniStrLen(str);\r
+       key_len = UniStrLen(key);\r
+       if (str_len < key_len)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (UniStrCmpi(str + (str_len - key_len), key) == 0)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// str が key で始まるかどうかチェック\r
+bool UniStartWith(wchar_t *str, wchar_t *key)\r
+{\r
+       UINT str_len;\r
+       UINT key_len;\r
+       wchar_t *tmp;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (str == NULL || key == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 比較\r
+       str_len = UniStrLen(str);\r
+       key_len = UniStrLen(key);\r
+       if (str_len < key_len)\r
+       {\r
+               return false;\r
+       }\r
+       if (str_len == 0 || key_len == 0)\r
+       {\r
+               return false;\r
+       }\r
+       tmp = CopyUniStr(str);\r
+       tmp[key_len] = 0;\r
+\r
+       if (UniStrCmpi(tmp, key) == 0)\r
+       {\r
+               ret = true;\r
+       }\r
+       else\r
+       {\r
+               ret = false;\r
+       }\r
+\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// 整数をカンマ区切り文字列に変換する\r
+void UniToStr3(wchar_t *str, UINT size, UINT64 value)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ToStr3(tmp, sizeof(tmp), value);\r
+\r
+       StrToUni(str, size, tmp);\r
+}\r
+\r
+// 文字列のフォーマット (内部関数)\r
+wchar_t *InternalFormatArgs(wchar_t *fmt, va_list args, bool ansi_mode)\r
+{\r
+       UINT i, len;\r
+       wchar_t *tmp;\r
+       UINT tmp_size;\r
+       LIST *o;\r
+       UINT mode = 0;\r
+       UINT wp;\r
+       UINT total_size;\r
+       wchar_t *ret;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       len = UniStrLen(fmt);\r
+       tmp_size = UniStrSize(fmt);\r
+       tmp = Malloc(tmp_size);\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       mode = 0;\r
+\r
+       wp = 0;\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               wchar_t c = fmt[i];\r
+\r
+               if (mode == 0)\r
+               {\r
+                       // 通常の文字モード\r
+                       switch (c)\r
+                       {\r
+                       case L'%':\r
+                               // 書式指定の開始\r
+                               if (fmt[i + 1] == L'%')\r
+                               {\r
+                                       // 次の文字も % の場合は % を一文字出力するだけ\r
+                                       i++;\r
+                                       tmp[wp++] = c;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 次の文字が % でない場合は状態遷移を行う\r
+                                       mode = 1;\r
+                                       tmp[wp++] = 0;\r
+                                       wp = 0;\r
+                                       Add(o, CopyUniStr(tmp));\r
+                                       tmp[wp++] = c;\r
+                               }\r
+                               break;\r
+                       default:\r
+                               // 通常の文字\r
+                               tmp[wp++] = c;\r
+                               break;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       char *tag;\r
+                       char dst[MAX_SIZE];\r
+                       wchar_t *target_str;\r
+                       wchar_t *padding_str;\r
+                       bool left_padding;\r
+                       UINT target_str_len;\r
+                       UINT total_len;\r
+                       wchar_t *output_str;\r
+                       UINT padding;\r
+                       // 書式指定モード\r
+                       switch (c)\r
+                       {\r
+                       case L'c':\r
+                       case L'C':\r
+                       case L'd':\r
+                       case L'i':\r
+                       case L'o':\r
+                       case L'u':\r
+                       case L'x':\r
+                       case L'X':\r
+                               // int 型\r
+                               tmp[wp++] = c;\r
+                               tmp[wp++] = 0;\r
+                               tag = CopyUniToStr(tmp);\r
+\r
+                               #ifdef  OS_WIN32\r
+                                       ReplaceStrEx(tag, 0, tag, "ll", "I64", false);\r
+                               #else   // OS_WIN32\r
+                                       ReplaceStrEx(tag, 0, tag, "I64", "ll", false);\r
+                               #endif  // OS_WIN32\r
+\r
+                               if ((UniStrLen(tmp) >= 5 && tmp[UniStrLen(tmp) - 4] == L'I' &&\r
+                                       tmp[UniStrLen(tmp) - 3] == L'6' &&\r
+                                       tmp[UniStrLen(tmp) - 2] == L'4') ||\r
+                                       (\r
+                                       UniStrLen(tmp) >= 4 && tmp[UniStrLen(tmp) - 3] == L'l' &&\r
+                                       tmp[UniStrLen(tmp) - 2] == L'l'))\r
+                               {\r
+                                       #ifdef  OS_WIN32\r
+                                               _snprintf(dst, sizeof(dst), tag, va_arg(args, UINT64));\r
+                                       #else   // OS_WIN32\r
+                                               snprintf(dst, sizeof(dst), tag, va_arg(args, UINT64));\r
+                                       #endif  // OS_WIN32\r
+                               }\r
+                               else\r
+                               {\r
+                                       #ifdef  OS_WIN32\r
+                                               _snprintf(dst, sizeof(dst), tag, va_arg(args, int));\r
+                                       #else   // OS_WIN32\r
+                                               snprintf(dst, sizeof(dst), tag, va_arg(args, int));\r
+                                       #endif  // OS_WIN32\r
+                               }\r
+\r
+                               Free(tag);\r
+                               Add(o, CopyStrToUni(dst));\r
+\r
+                               wp = 0;\r
+                               mode = 0;\r
+                               break;\r
+                       case L'e':\r
+                       case L'E':\r
+                       case L'f':\r
+                       case L'g':\r
+                       case L'G':\r
+                               // double 型\r
+                               tmp[wp++] = c;\r
+                               tmp[wp++] = 0;\r
+                               tag = CopyUniToStr(tmp);\r
+\r
+                               #ifdef  OS_WIN32\r
+                                       _snprintf(dst, sizeof(dst), tag, va_arg(args, double));\r
+                               #else   // OS_WIN32\r
+                                       snprintf(dst, sizeof(dst), tag, va_arg(args, double));\r
+                               #endif  // OS_WIN32\r
+\r
+                               Free(tag);\r
+                               Add(o, CopyStrToUni(dst));\r
+\r
+                               wp = 0;\r
+                               mode = 0;\r
+                               break;\r
+                       case L'n':\r
+                       case L'p':\r
+                               // ポインタ型\r
+                               tmp[wp++] = c;\r
+                               tmp[wp++] = 0;\r
+                               tag = ZeroMalloc(UniStrSize(tmp) + 32);\r
+                               UniToStr(tag, 0, tmp);\r
+\r
+                               #ifdef  OS_WIN32\r
+                                       _snprintf(dst, sizeof(dst), tag, va_arg(args, void *));\r
+                               #else   // OS_WIN32\r
+                                       snprintf(dst, sizeof(dst), tag, va_arg(args, void *));\r
+                               #endif  // OS_WIN32\r
+\r
+                               Free(tag);\r
+                               Add(o, CopyStrToUni(dst));\r
+\r
+                               wp = 0;\r
+                               mode = 0;\r
+                               break;\r
+                       case L's':\r
+                       case L'S':\r
+                               // 文字列型\r
+                               tmp[wp++] = c;\r
+                               tmp[wp++] = 0;\r
+\r
+                               if (ansi_mode == false)\r
+                               {\r
+                                       if (c == L'S')\r
+                                       {\r
+                                               c = L's';\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               c = L'S';\r
+                                       }\r
+                               }\r
+\r
+                               if (c == L's')\r
+                               {\r
+                                       target_str = CopyStrToUni(va_arg(args, char *));\r
+                               }\r
+                               else\r
+                               {\r
+                                       target_str = CopyUniStr(va_arg(args, wchar_t *));\r
+                               }\r
+\r
+                               if (target_str == NULL)\r
+                               {\r
+                                       target_str = CopyUniStr(L"(null)");\r
+                               }\r
+\r
+                               padding = 0;\r
+                               left_padding = false;\r
+                               if (tmp[1] == L'-')\r
+                               {\r
+                                       // 左詰め\r
+                                       if (UniStrLen(tmp) >= 3)\r
+                                       {\r
+                                               padding = UniToInt(&tmp[2]);\r
+                                       }\r
+                                       left_padding = true;\r
+                               }\r
+                               else\r
+                               {\r
+                                       // 右詰め\r
+                                       if (UniStrLen(tmp) >= 2)\r
+                                       {\r
+                                               padding = UniToInt(&tmp[1]);\r
+                                       }\r
+                               }\r
+\r
+                               target_str_len = UniStrWidth(target_str);\r
+\r
+                               if (padding > target_str_len)\r
+                               {\r
+                                       UINT len = padding - target_str_len;\r
+                                       UINT i;\r
+                                       padding_str = ZeroMalloc(sizeof(wchar_t) * (len + 1));\r
+                                       for (i = 0;i < len;i++)\r
+                                       {\r
+                                               padding_str[i] = L' ';\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       padding_str = ZeroMalloc(sizeof(wchar_t));\r
+                               }\r
+\r
+                               total_len = sizeof(wchar_t) * (UniStrLen(padding_str) + UniStrLen(target_str) + 1);\r
+                               output_str = ZeroMalloc(total_len);\r
+                               output_str[0] = 0;\r
+\r
+                               if (left_padding == false)\r
+                               {\r
+                                       UniStrCat(output_str, total_len, padding_str);\r
+                               }\r
+                               UniStrCat(output_str, total_len, target_str);\r
+                               if (left_padding)\r
+                               {\r
+                                       UniStrCat(output_str, total_len, padding_str);\r
+                               }\r
+\r
+                               Add(o, output_str);\r
+\r
+                               Free(target_str);\r
+                               Free(padding_str);\r
+\r
+                               wp = 0;\r
+                               mode = 0;\r
+                               break;\r
+                       default:\r
+                               // 通常の文字列\r
+                               tmp[wp++] = c;\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       tmp[wp++] = 0;\r
+       wp = 0;\r
+\r
+       if (UniStrLen(tmp) >= 1)\r
+       {\r
+               Add(o, CopyUniStr(tmp));\r
+       }\r
+\r
+       total_size = sizeof(wchar_t);\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               wchar_t *s = LIST_DATA(o, i);\r
+               total_size += UniStrLen(s) * sizeof(wchar_t);\r
+       }\r
+\r
+       ret = ZeroMalloc(total_size);\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               wchar_t *s = LIST_DATA(o, i);\r
+               UniStrCat(ret, total_size, s);\r
+               Free(s);\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// 文字列の横幅サイズを取得する\r
+UINT UniStrWidth(wchar_t *str)\r
+{\r
+       UINT i, len, ret;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = 0;\r
+       len = UniStrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (str[i] <= 255)\r
+               {\r
+                       ret++;\r
+               }\r
+               else\r
+               {\r
+                       ret += 2;\r
+               }\r
+       }\r
+       return ret;\r
+}\r
+\r
+// Unicode 文字列をダンプ表示する\r
+void DumpUniStr(wchar_t *str)\r
+{\r
+       UINT i, len;\r
+       char *s;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = CopyUniToStr(str);\r
+\r
+       Print("DumpUniStr: %s\n  ", s);\r
+\r
+       len = UniStrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               Print("0x%04X ", str[i]);\r
+       }\r
+       Print("\n");\r
+\r
+       Free(s);\r
+}\r
+\r
+// 文字列をダンプ表示する\r
+void DumpStr(char *str)\r
+{\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Print("DumpStr: %s\n  ", str);\r
+\r
+       len = StrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               Print("0x%02X ", str[i]);\r
+       }\r
+       Print("\n");\r
+}\r
+\r
+// 1 文字 2 バイトの文字列を 1 文字 4 場合の wchar_t に変換する\r
+wchar_t *Utf16ToWide(USHORT *str)\r
+{\r
+       wchar_t *ret;\r
+       UINT len, i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       len = 0;\r
+       while (true)\r
+       {\r
+               if (str[len] == 0)\r
+               {\r
+                       break;\r
+               }\r
+               len++;\r
+       }\r
+\r
+       ret = Malloc((len + 1) * sizeof(wchar_t));\r
+       for (i = 0;i < len + 1;i++)\r
+       {\r
+               ret[i] = (wchar_t)str[i];\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 1 文字 4 バイトの wchar_t 文字列を 1 文字 2 バイトに変換する\r
+USHORT *WideToUtf16(wchar_t *str)\r
+{\r
+       USHORT *ret;\r
+       UINT len;\r
+       UINT ret_size;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       len = UniStrLen(str);\r
+\r
+       ret_size = (len + 1) * 2;\r
+       ret = Malloc(ret_size);\r
+\r
+       for (i = 0;i < len + 1;i++)\r
+       {\r
+               ret[i] = (USHORT)str[i];\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 国際ライブラリの初期化\r
+void InitInternational()\r
+{\r
+#ifdef OS_UNIX\r
+       void *d;\r
+\r
+       if (iconv_lock != NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetCurrentCharSet(charset, sizeof(charset));\r
+       d = IconvWideToStrInternal();\r
+       if (d == (void *)-1)\r
+       {\r
+#ifdef UNIX_MACOS\r
+               StrCpy(charset, sizeof(charset), "utf8");\r
+#else  // UNIX_MACOS\r
+               StrCpy(charset, sizeof(charset), "EUCJP");\r
+#endif // UNIX_MACOS\r
+               d = IconvWideToStrInternal();\r
+               if (d == (void *)-1)\r
+               {\r
+                       StrCpy(charset, sizeof(charset), "US");\r
+               }\r
+               else\r
+               {\r
+                       IconvFreeInternal(d);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               IconvFreeInternal(d);\r
+       }\r
+\r
+       iconv_lock = NewLockMain();\r
+\r
+       iconv_cache_wide_to_str = IconvWideToStrInternal();\r
+       iconv_cache_str_to_wide = IconvStrToWideInternal();\r
+#endif // OS_UNIX\r
+}\r
+\r
+// 国際ライブラリの解放\r
+void FreeInternational()\r
+{\r
+#ifdef OS_UNIX\r
+#endif // OS_UNIX\r
+}\r
+\r
+#ifdef OS_UNIX\r
+\r
+// 文字列を Unicode に変換した場合のサイズを計算する\r
+UINT UnixCalcStrToUni(char *str)\r
+{\r
+       wchar_t *tmp;\r
+       UINT len, tmp_size;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       tmp_size = len * 5 + 10;\r
+       tmp = ZeroMalloc(tmp_size);\r
+       UnixStrToUni(tmp, tmp_size, str);\r
+       ret = UniStrLen(tmp);\r
+       Free(tmp);\r
+\r
+       return (ret + 1) * sizeof(wchar_t);\r
+}\r
+\r
+// 文字列を Unicode に変換する\r
+UINT UnixStrToUni(wchar_t *s, UINT size, char *str)\r
+{\r
+       void *d;\r
+       char *inbuf;\r
+       size_t insize;\r
+       char *outbuf;\r
+       char *outbuf_orig;\r
+       size_t outsize;\r
+       wchar_t *tmp;\r
+       // 引数チェック\r
+       if (s == NULL || str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       d = IconvStrToWide();\r
+       if (d == (void *)-1)\r
+       {\r
+               UniStrCpy(s, size, L"");\r
+               return 0;\r
+       }\r
+\r
+       inbuf = (char *)str;\r
+       insize = StrLen(str) + 1;\r
+       outsize = insize * 5 + 10;\r
+       outbuf_orig = outbuf = ZeroMalloc(outsize);\r
+\r
+       if (iconv((iconv_t)d, (char **)&inbuf, (size_t *)&insize, (char **)&outbuf, (size_t *)&outsize) == (size_t)(-1))\r
+       {\r
+               Free(outbuf_orig);\r
+               UniStrCpy(s, size, L"");\r
+               IconvFree(d);\r
+               return 0;\r
+       }\r
+\r
+       tmp = Utf16ToWide((USHORT *)outbuf_orig);\r
+       Free(outbuf_orig);\r
+\r
+       UniStrCpy(s, size, tmp);\r
+       IconvFree(d);\r
+\r
+       Free(tmp);\r
+\r
+       return UniStrLen(s);\r
+}\r
+\r
+// Unicode を文字列にした場合のサイズを計算する\r
+UINT UnixCalcUniToStr(wchar_t *s)\r
+{\r
+       char *tmp;\r
+       UINT tmp_size;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       tmp_size = UniStrLen(s) * 5 + 10;\r
+       tmp = ZeroMalloc(tmp_size);\r
+       UnixUniToStr(tmp, tmp_size, s);\r
+\r
+       ret = StrSize(tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// Unicode を文字列に変換する\r
+UINT UnixUniToStr(char *str, UINT size, wchar_t *s)\r
+{\r
+       USHORT *tmp;\r
+       char *inbuf;\r
+       size_t insize;\r
+       char *outbuf;\r
+       char *outbuf_orig;\r
+       size_t outsize;\r
+       void *d;\r
+       // 引数チェック\r
+       if (str == NULL || s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // まず wchar_t 文字列を 2 バイトの並びに変換する\r
+       tmp = WideToUtf16(s);\r
+       inbuf = (char *)tmp;\r
+       insize = (UniStrLen(s) + 1) * 2;\r
+       outsize = insize * 5 + 10;\r
+       outbuf_orig = outbuf = ZeroMalloc(outsize);\r
+\r
+       d = IconvWideToStr();\r
+       if (d == (void *)-1)\r
+       {\r
+               StrCpy(str, size, "");\r
+               Free(outbuf);\r
+               Free(tmp);\r
+               return 0;\r
+       }\r
+\r
+       if (iconv((iconv_t)d, (char **)&inbuf, (size_t *)&insize, (char **)&outbuf, (size_t *)&outsize) == (size_t)(-1))\r
+       {\r
+               Free(outbuf_orig);\r
+               IconvFree(d);\r
+               StrCpy(str, size, "");\r
+               Free(tmp);\r
+               return 0;\r
+       }\r
+\r
+       StrCpy(str, size, outbuf_orig);\r
+\r
+       Free(outbuf_orig);\r
+       IconvFree(d);\r
+       Free(tmp);\r
+\r
+       return StrLen(str);\r
+}\r
+\r
+// whcar_t を char に変換する\r
+void *IconvWideToStrInternal()\r
+{\r
+       return (void *)iconv_open(charset, IsBigEndian() ? "UTF-16BE" : "UTF-16LE");\r
+}\r
+\r
+// char を wchar_t に変換する\r
+void *IconvStrToWideInternal()\r
+{\r
+       return (void *)iconv_open(IsBigEndian() ? "UTF-16BE" : "UTF-16LE", charset);\r
+}\r
+\r
+// ハンドルを閉じる\r
+int IconvFreeInternal(void *d)\r
+{\r
+       iconv_close((iconv_t)d);\r
+       return 0;\r
+}\r
+\r
+void *IconvWideToStr()\r
+{\r
+       if (iconv_cache_wide_to_str == (void *)-1)\r
+       {\r
+               return (void *)-1;\r
+       }\r
+\r
+       Lock(iconv_lock);\r
+\r
+       return iconv_cache_wide_to_str;\r
+}\r
+\r
+void *IconvStrToWide()\r
+{\r
+       if (iconv_cache_str_to_wide == (void *)-1)\r
+       {\r
+               return (void *)-1;\r
+       }\r
+\r
+       Lock(iconv_lock);\r
+\r
+       return iconv_cache_str_to_wide;\r
+}\r
+\r
+int IconvFree(void *d)\r
+{\r
+       Unlock(iconv_lock);\r
+\r
+       return 0;\r
+}\r
+\r
+// 現在使用されている文字セットを環境変数から取得する\r
+void GetCurrentCharSet(char *name, UINT size)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (GetEnv("LANG", tmp, sizeof(tmp)) == false)\r
+       {\r
+               if (GetEnv("LOCATION", tmp, sizeof(tmp)) == false)\r
+               {\r
+                       StrCpy(tmp, sizeof(tmp), "ja_JP.eucJP");\r
+               }\r
+       }\r
+\r
+       Trim(tmp);\r
+\r
+       t = ParseToken(tmp, ".");\r
+       if (t->NumTokens >= 2)\r
+       {\r
+               StrCpy(name, size, t->Token[1]);\r
+       }\r
+       else\r
+       {\r
+               if (t->NumTokens == 1)\r
+               {\r
+                       StrCpy(name, size, t->Token[0]);\r
+               }\r
+               else\r
+               {\r
+                       StrCpy(name, size, "eucJP");\r
+               }\r
+       }\r
+       FreeToken(t);\r
+\r
+       StrUpper(name);\r
+}\r
+\r
+#endif // OS_UNIX\r
+\r
+// 指定された文字列が空白かどうかチェック\r
+bool UniIsEmptyStr(wchar_t *str)\r
+{\r
+       return IsEmptyUniStr(str);\r
+}\r
+bool IsEmptyUniStr(wchar_t *str)\r
+{\r
+       bool ret;\r
+       wchar_t *s;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       s = UniCopyStr(str);\r
+\r
+       UniTrim(s);\r
+       if (UniStrLen(s) == 0)\r
+       {\r
+               ret = true;\r
+       }\r
+       else\r
+       {\r
+               ret = false;\r
+       }\r
+\r
+       Free(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// 指定された文字列が数字かどうかチェック\r
+bool UniIsNum(wchar_t *str)\r
+{\r
+       char tmp[MAX_SIZE];\r
+\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       return IsNum(tmp);\r
+}\r
+\r
+\r
+// 中身が無い Unicode トークンリスト\r
+UNI_TOKEN_LIST *UniNullToken()\r
+{\r
+       UNI_TOKEN_LIST *ret = ZeroMalloc(sizeof(UNI_TOKEN_LIST));\r
+       ret->Token = ZeroMalloc(0);\r
+\r
+       return ret;\r
+}\r
+\r
+// 中身が無い Unicode トークンリスト (別名)\r
+UNI_TOKEN_LIST *NullUniToken()\r
+{\r
+       return UniNullToken();\r
+}\r
+\r
+// トークンリストを Unicode トークンリストに変換する\r
+UNI_TOKEN_LIST *TokenListToUniTokenList(TOKEN_LIST *src)\r
+{\r
+       UNI_TOKEN_LIST *ret;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(UNI_TOKEN_LIST));\r
+       ret->NumTokens = src->NumTokens;\r
+       ret->Token = ZeroMalloc(sizeof(wchar_t *) * ret->NumTokens);\r
+\r
+       for (i = 0;i < ret->NumTokens;i++)\r
+       {\r
+               ret->Token[i] = CopyStrToUni(src->Token[i]);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// Unicode トークンリストをトークンリストに変換する\r
+TOKEN_LIST *UniTokenListToTokenList(UNI_TOKEN_LIST *src)\r
+{\r
+       TOKEN_LIST *ret;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       ret->NumTokens = src->NumTokens;\r
+       ret->Token = ZeroMalloc(sizeof(char *) * ret->NumTokens);\r
+\r
+       for (i = 0;i < ret->NumTokens;i++)\r
+       {\r
+               ret->Token[i] = CopyUniToStr(src->Token[i]);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// Unicode 文字列コピー\r
+wchar_t *UniCopyStr(wchar_t *str)\r
+{\r
+       return CopyUniStr(str);\r
+}\r
+\r
+// トークンリストのコピー\r
+UNI_TOKEN_LIST *UniCopyToken(UNI_TOKEN_LIST *src)\r
+{\r
+       UNI_TOKEN_LIST *ret;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       ret->NumTokens = src->NumTokens;\r
+       ret->Token = ZeroMalloc(sizeof(wchar_t *) * ret->NumTokens);\r
+       for (i = 0;i < ret->NumTokens;i++)\r
+       {\r
+               ret->Token[i] = CopyUniStr(src->Token[i]);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// コマンドライン文字列をパースする\r
+UNI_TOKEN_LIST *UniParseCmdLine(wchar_t *str)\r
+{\r
+       UNI_TOKEN_LIST *t;\r
+       LIST *o;\r
+       UINT i, len, wp, mode;\r
+       wchar_t c;\r
+       wchar_t *tmp;\r
+       bool ignore_space = false;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               // トークン無し\r
+               return UniNullToken();\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+       tmp = Malloc(UniStrSize(str) + 32);\r
+\r
+       wp = 0;\r
+       mode = 0;\r
+\r
+       len = UniStrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               c = str[i];\r
+\r
+               switch (mode)\r
+               {\r
+               case 0:\r
+                       // 次のトークンを発見するモード\r
+                       if (c == L' ' || c == L'\t')\r
+                       {\r
+                               // 次の文字へ進める\r
+                       }\r
+                       else\r
+                       {\r
+                               // トークンの開始\r
+                               if (c == L'\"')\r
+                               {\r
+                                       if (str[i + 1] == L'\"')\r
+                                       {\r
+                                               // 2 重の " は 1 個の " 文字として見なす\r
+                                               tmp[wp++] = L'\"';\r
+                                               i++;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // 1 個の " はスペース無視フラグを有効にする\r
+                                               ignore_space = true;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       tmp[wp++] = c;\r
+                               }\r
+\r
+                               mode = 1;\r
+                       }\r
+                       break;\r
+\r
+               case 1:\r
+                       if (ignore_space == false && (c == L' ' || c == L'\t'))\r
+                       {\r
+                               // トークンの終了\r
+                               tmp[wp++] = 0;\r
+                               wp = 0;\r
+\r
+                               Insert(o, UniCopyStr(tmp));\r
+                               mode = 0;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (c == L'\"')\r
+                               {\r
+                                       if (str[i + 1] == L'\"')\r
+                                       {\r
+                                               // 2 重の " は 1 個の " 文字として見なす\r
+                                               tmp[wp++] = L'\"';\r
+                                               i++;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (ignore_space == false)\r
+                                               {\r
+                                                       // 1 個の " はスペース無視フラグを有効にする\r
+                                                       ignore_space = true;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       // スペース無視フラグを無効にする\r
+                                                       ignore_space = false;\r
+                                               }\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       tmp[wp++] = c;\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (wp != 0)\r
+       {\r
+               tmp[wp++] = 0;\r
+               Insert(o, UniCopyStr(tmp));\r
+       }\r
+\r
+       Free(tmp);\r
+\r
+       t = ZeroMalloc(sizeof(UNI_TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(wchar_t *) * t->NumTokens);\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               t->Token[i] = LIST_DATA(o, i);\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       return t;\r
+}\r
+\r
+// Unicode 文字列を 64bit 整数に変換する\r
+UINT64 UniToInt64(wchar_t *str)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       return ToInt64(tmp);\r
+}\r
+\r
+// 64bit 整数を Unicode 文字列に変換する\r
+void UniToStr64(wchar_t *str, UINT64 value)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ToStr64(tmp, value);\r
+\r
+       StrToUni(str, 0, tmp);\r
+}\r
+\r
+// ANSI を UTF に変換する\r
+UINT StrToUtf(char *utfstr, UINT size, char *str)\r
+{\r
+       char *tmp;\r
+       // 引数チェック\r
+       if (utfstr == NULL || str == NULL)\r
+       {\r
+               StrCpy(utfstr, size, "");\r
+               return 0;\r
+       }\r
+\r
+       tmp = CopyStrToUtf(str);\r
+\r
+       StrCpy(utfstr, size, tmp);\r
+\r
+       Free(tmp);\r
+\r
+       return StrLen(utfstr);\r
+}\r
+\r
+// UTF を ANSI に変換する\r
+UINT UtfToStr(char *str, UINT size, char *utfstr)\r
+{\r
+       char *tmp;\r
+       // 引数チェック\r
+       if (str == NULL || utfstr == NULL)\r
+       {\r
+               StrCpy(str, size, "");\r
+               return 0;\r
+       }\r
+\r
+       tmp = CopyUtfToStr(utfstr);\r
+\r
+       StrCpy(str, size, tmp);\r
+\r
+       Free(tmp);\r
+\r
+       return StrLen(str);\r
+}\r
+\r
+// Unicode を UTF に変換する\r
+UINT UniToUtf(char *utfstr, UINT size, wchar_t *unistr)\r
+{\r
+       char *tmp;\r
+       // 引数チェック\r
+       if (utfstr == NULL || unistr == NULL)\r
+       {\r
+               StrCpy(utfstr, size, "");\r
+               return 0;\r
+       }\r
+\r
+       tmp = CopyUniToStr(unistr);\r
+\r
+       StrCpy(utfstr, size, tmp);\r
+\r
+       Free(tmp);\r
+\r
+       return StrLen(utfstr);\r
+}\r
+\r
+// UTF を Unicode に変換する\r
+UINT UtfToUni(wchar_t *unistr, UINT size, char *utfstr)\r
+{\r
+       wchar_t *tmp;\r
+       // 引数チェック\r
+       if (unistr == NULL || utfstr == NULL)\r
+       {\r
+               UniStrCpy(unistr, size, L"");\r
+               return 0;\r
+       }\r
+\r
+       tmp = CopyUtfToUni(utfstr);\r
+\r
+       UniStrCpy(unistr, size, tmp);\r
+\r
+       Free(tmp);\r
+\r
+       return UniStrLen(unistr);\r
+}\r
+\r
+// UTF8 文字列を Unicode 文字列にコピーする\r
+wchar_t *CopyUtfToUni(char *utfstr)\r
+{\r
+       UINT size;\r
+       wchar_t *ret;\r
+       UINT utfstr_len;\r
+       // 引数チェック\r
+       if (utfstr == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       utfstr_len = StrLen(utfstr);\r
+\r
+       size = CalcUtf8ToUni((BYTE *)utfstr, utfstr_len);\r
+       ret = ZeroMalloc(size + sizeof(wchar_t));\r
+       Utf8ToUni(ret, size, (BYTE *)utfstr, utfstr_len);\r
+\r
+       return ret;\r
+}\r
+\r
+// UTF8 文字列を ANSI 文字列にコピーする\r
+char *CopyUtfToStr(char *utfstr)\r
+{\r
+       wchar_t *uni;\r
+       char *ret;\r
+       // 引数チェック\r
+       if (utfstr == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       uni = CopyUtfToUni(utfstr);\r
+       if (uni == NULL)\r
+       {\r
+               return CopyStr("");\r
+       }\r
+\r
+       ret = CopyUniToStr(uni);\r
+\r
+       Free(uni);\r
+\r
+       return ret;\r
+}\r
+\r
+// Unicode 文字列を ANSI 文字列にコピーする\r
+char *CopyUniToStr(wchar_t *unistr)\r
+{\r
+       char *str;\r
+       UINT str_size;\r
+       // 引数チェック\r
+       if (unistr == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       str_size = CalcUniToStr(unistr);\r
+       if (str_size == 0)\r
+       {\r
+               return CopyStr("");\r
+       }\r
+       str = Malloc(str_size);\r
+       UniToStr(str, str_size, unistr);\r
+\r
+       return str;\r
+}\r
+\r
+// ANSI 文字列を Unicode 文字列にコピーする\r
+wchar_t *CopyStrToUni(char *str)\r
+{\r
+       wchar_t *uni;\r
+       UINT uni_size;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       uni_size = CalcStrToUni(str);\r
+       if (uni_size == 0)\r
+       {\r
+               return CopyUniStr(L"");\r
+       }\r
+       uni = Malloc(uni_size);\r
+       StrToUni(uni, uni_size, str);\r
+\r
+       return uni;\r
+}\r
+\r
+// Unicode 文字列を UTF8 文字列にコピーする\r
+char *CopyUniToUtf(wchar_t *unistr)\r
+{\r
+       UINT size;\r
+       char *ret;\r
+       // 引数チェック\r
+       if (unistr == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = CalcUniToUtf8(unistr);\r
+       ret = ZeroMalloc(size + sizeof(char));\r
+\r
+       UniToUtf8((char *)ret, size, unistr);\r
+\r
+       return ret;\r
+}\r
+\r
+// ANSI 文字列を UTF8 文字列にコピーする\r
+char *CopyStrToUtf(char *str)\r
+{\r
+       wchar_t *unistr;\r
+       char *ret;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       unistr = CopyStrToUni(str);\r
+       if (unistr == NULL)\r
+       {\r
+               return CopyStr("");\r
+       }\r
+\r
+       ret = CopyUniToUtf(unistr);\r
+\r
+       Free(unistr);\r
+\r
+       return ret;\r
+}\r
+\r
+// Unicode 文字列をコピーする\r
+wchar_t *CopyUniStr(wchar_t *str)\r
+{\r
+       UINT len;\r
+       wchar_t *dst;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       len = UniStrLen(str);\r
+       dst = Malloc((len + 1) * sizeof(wchar_t));\r
+       UniStrCpy(dst, 0, str);\r
+\r
+       return dst;\r
+}\r
+\r
+// 安全な文字列かどうかチェック\r
+bool IsSafeUniStr(wchar_t *str)\r
+{\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       len = UniStrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (IsSafeUniChar(str[i]) == false)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+       if (str[0] == L' ')\r
+       {\r
+               return false;\r
+       }\r
+       if (len != 0)\r
+       {\r
+               if (str[len - 1] == L' ')\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+       return true;\r
+}\r
+\r
+// 安全な文字かどうかチェック\r
+bool IsSafeUniChar(wchar_t c)\r
+{\r
+       UINT i, len;\r
+       wchar_t *check_str =\r
+               L"ABCDEFGHIJKLMNOPQRSTUVWXYZ"\r
+               L"abcdefghijklmnopqrstuvwxyz"\r
+               L"0123456789"\r
+               L" ()-_#%&.";\r
+\r
+       len = UniStrLen(check_str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (c == check_str[i])\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+       return false;\r
+}\r
+\r
+// UTF-8 文字列を ANSI 文字列に変換する\r
+UINT Utf8ToStr(char *str, UINT str_size, BYTE *u, UINT size)\r
+{\r
+       UINT ret, uni_size;\r
+       wchar_t *tmp;\r
+       // 引数チェック\r
+       if (u == NULL || str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // Unicode に変換する\r
+       uni_size = CalcUtf8ToUni(u, size);\r
+       if (uni_size == 0)\r
+       {\r
+               if (str_size >= 1)\r
+               {\r
+                       StrCpy(str, 0, "");\r
+                       return 0;\r
+               }\r
+       }\r
+       tmp = Malloc(uni_size);\r
+       Utf8ToUni(tmp, uni_size, u, size);\r
+\r
+       // ANSI に変換する\r
+       ret = UniToStr(str, str_size, tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// UTF-8 文字列を ANSI 文字列に変換した場合に必要なサイズを取得する\r
+UINT CalcUtf8ToStr(BYTE *u, UINT size)\r
+{\r
+       UINT ret, uni_size;\r
+       wchar_t *tmp;\r
+       // 引数チェック\r
+       if (u == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // Unicode に変換する\r
+       uni_size = CalcUtf8ToUni(u, size);\r
+       if (uni_size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+       tmp = Malloc(uni_size);\r
+       Utf8ToUni(tmp, uni_size, u, size);\r
+\r
+       // ANSI に変換する\r
+       ret = CalcUniToStr(tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// ANSI 文字列を UTF-8 文字列に変換する\r
+UINT StrToUtf8(BYTE *u, UINT size, char *str)\r
+{\r
+       UINT ret, uni_size;\r
+       wchar_t *tmp;\r
+       // 引数チェック\r
+       if (u == NULL || str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // Unicode に変換する\r
+       uni_size = CalcStrToUni(str);\r
+       if (uni_size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+       tmp = Malloc(uni_size);\r
+       StrToUni(tmp, uni_size, str);\r
+\r
+       // UTF-8 に変換する\r
+       ret = UniToUtf8(u, size, tmp);\r
+\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// ANSI 文字列を UTF-8 文字列に変換するために必要なサイズを取得する\r
+UINT CalcStrToUtf8(char *str)\r
+{\r
+       UINT ret;\r
+       UINT uni_size;\r
+       wchar_t *tmp;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // Unicode に変換する\r
+       uni_size = CalcStrToUni(str);\r
+       if (uni_size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+       tmp = Malloc(uni_size);\r
+       StrToUni(tmp, uni_size, str);\r
+\r
+       // UTF-8 に変換した場合のサイズを取得する\r
+       ret = CalcUniToUtf8(tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// Unicode 文字列を ANSI 文字列に変換する\r
+UINT UniToStr(char *str, UINT size, wchar_t *s)\r
+{\r
+#ifdef OS_WIN32\r
+       UINT ret;\r
+       char *tmp;\r
+       UINT new_size;\r
+       // 引数チェック\r
+       if (s == NULL || str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       new_size = CalcUniToStr(s);\r
+       if (new_size == 0)\r
+       {\r
+               if (size >= 1)\r
+               {\r
+                       StrCpy(str, 0, "");\r
+               }\r
+               return 0;\r
+       }\r
+       tmp = Malloc(new_size);\r
+       tmp[0] = 0;\r
+       wcstombs(tmp, s, new_size);\r
+       tmp[new_size - 1] = 0;\r
+       ret = StrCpy(str, size, tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+#else  // OS_WIN32\r
+       return UnixUniToStr(str, size, s);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// Unicode 文字列を ANSI 文字列に変換するための必要なバイト数を取得する\r
+UINT CalcUniToStr(wchar_t *s)\r
+{\r
+#ifdef OS_WIN32\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = (UINT)wcstombs(NULL, s, UniStrLen(s));\r
+       if (ret == (UINT)-1)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return ret + 1;\r
+#else  // OS_WIN32\r
+       return UnixCalcUniToStr(s);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// ANSI 文字列を Unicode 文字列に変換する\r
+UINT StrToUni(wchar_t *s, UINT size, char *str)\r
+{\r
+#ifdef OS_WIN32\r
+       UINT ret;\r
+       wchar_t *tmp;\r
+       UINT new_size;\r
+       // 引数チェック\r
+       if (s == NULL || str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       new_size = CalcStrToUni(str);\r
+       if (new_size == 0)\r
+       {\r
+               if (size >= 2)\r
+               {\r
+                       UniStrCpy(s, 0, L"");\r
+               }\r
+               return 0;\r
+       }\r
+       tmp = Malloc(new_size);\r
+       tmp[0] = 0;\r
+       mbstowcs(tmp, str, StrLen(str));\r
+       tmp[(new_size - 1) / sizeof(wchar_t)] = 0;\r
+       ret = UniStrCpy(s, size, tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+#else  // OS_WIN32\r
+       return UnixStrToUni(s, size, str);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// ANSI 文字列を Unicode 文字列に変換するための必要なバイト数を取得する\r
+UINT CalcStrToUni(char *str)\r
+{\r
+#ifdef OS_WIN32\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = (UINT)mbstowcs(NULL, str, StrLen(str));\r
+       if (ret == (UINT)-1)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return (ret + 1) * sizeof(wchar_t);\r
+#else  // OS_WIN32\r
+       return UnixCalcStrToUni(str);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// UTF-8 文字列を Unicode 文字列に変換する\r
+UINT Utf8ToUni(wchar_t *s, UINT size, BYTE *u, UINT u_size)\r
+{\r
+       UINT i, wp, num;\r
+       // 引数チェック\r
+       if (s == NULL || u == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               size = 0x3fffffff;\r
+       }\r
+       if (u_size == 0)\r
+       {\r
+               u_size = StrLen((char *)u);\r
+       }\r
+\r
+       i = 0;\r
+       wp = 0;\r
+       num = 0;\r
+       while (true)\r
+       {\r
+               UINT type;\r
+               wchar_t c;\r
+               BYTE c1, c2;\r
+\r
+               type = GetUtf8Type(u, u_size, i);\r
+               if (type == 0)\r
+               {\r
+                       break;\r
+               }\r
+               switch (type)\r
+               {\r
+               case 1:\r
+                       c1 = 0;\r
+                       c2 = u[i];\r
+                       break;\r
+               case 2:\r
+                       c1 = (((u[i] & 0x1c) >> 2) & 0x07);\r
+                       c2 = (((u[i] & 0x03) << 6) & 0xc0) | (u[i + 1] & 0x3f);\r
+                       break;\r
+               case 3:\r
+                       c1 = ((((u[i] & 0x0f) << 4) & 0xf0)) | (((u[i + 1] & 0x3c) >> 2) & 0x0f);\r
+                       c2 = (((u[i + 1] & 0x03) << 6) & 0xc0) | (u[i + 2] & 0x3f);\r
+                       break;\r
+               }\r
+               i += type;\r
+\r
+               c = 0;\r
+\r
+               if (IsBigEndian())\r
+               {\r
+                       if (sizeof(wchar_t) == 2)\r
+                       {\r
+                               ((BYTE *)&c)[0] = c1;\r
+                               ((BYTE *)&c)[1] = c2;\r
+                       }\r
+                       else\r
+                       {\r
+                               ((BYTE *)&c)[2] = c1;\r
+                               ((BYTE *)&c)[3] = c2;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       ((BYTE *)&c)[0] = c2;\r
+                       ((BYTE *)&c)[1] = c1;\r
+               }\r
+\r
+               if (wp < ((size / sizeof(wchar_t)) - 1))\r
+               {\r
+                       s[wp++] = c;\r
+                       num++;\r
+               }\r
+               else\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (wp < (size / sizeof(wchar_t)))\r
+       {\r
+               s[wp++] = 0;\r
+       }\r
+\r
+       return num;\r
+}\r
+\r
+// UTF-8 を Unicode に変換した場合のバッファサイズを取得する\r
+UINT CalcUtf8ToUni(BYTE *u, UINT u_size)\r
+{\r
+       // 引数チェック\r
+       if (u == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (u_size == 0)\r
+       {\r
+               u_size = StrLen((char *)u);\r
+       }\r
+\r
+       return (Utf8Len(u, u_size) + 1) * sizeof(wchar_t);\r
+}\r
+\r
+// UTF-8 文字列の文字数を取得する\r
+UINT Utf8Len(BYTE *u, UINT size)\r
+{\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (u == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               size = StrLen((char *)u);\r
+       }\r
+\r
+       i = num = 0;\r
+       while (true)\r
+       {\r
+               UINT type;\r
+\r
+               type = GetUtf8Type(u, size, i);\r
+               if (type == 0)\r
+               {\r
+                       break;\r
+               }\r
+               i += type;\r
+               num++;\r
+       }\r
+\r
+       return num;\r
+}\r
+\r
+// Unicode 文字列を UTF-8 文字列に変換する\r
+UINT UniToUtf8(BYTE *u, UINT size, wchar_t *s)\r
+{\r
+       UINT i, len, type, wp;\r
+       // 引数チェック\r
+       if (u == NULL || s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               size = 0x3fffffff;\r
+       }\r
+\r
+       len = UniStrLen(s);\r
+       wp = 0;\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               BYTE c1, c2;\r
+               wchar_t c = s[i];\r
+\r
+               if (IsBigEndian())\r
+               {\r
+                       if (sizeof(wchar_t) == 2)\r
+                       {\r
+                               c1 = ((BYTE *)&c)[0];\r
+                               c2 = ((BYTE *)&c)[1];\r
+                       }\r
+                       else\r
+                       {\r
+                               c1 = ((BYTE *)&c)[2];\r
+                               c2 = ((BYTE *)&c)[3];\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       c1 = ((BYTE *)&c)[1];\r
+                       c2 = ((BYTE *)&c)[0];\r
+               }\r
+\r
+               type = GetUniType(s[i]);\r
+               switch (type)\r
+               {\r
+               case 1:\r
+                       if (wp < size)\r
+                       {\r
+                               u[wp++] = c2;\r
+                       }\r
+                       break;\r
+               case 2:\r
+                       if (wp < size)\r
+                       {\r
+                               u[wp++] = 0xc0 | (((((c1 & 0x07) << 2) & 0x1c)) | (((c2 & 0xc0) >> 6) & 0x03));\r
+                       }\r
+                       if (wp < size)\r
+                       {\r
+                               u[wp++] = 0x80 | (c2 & 0x3f);\r
+                       }\r
+                       break;\r
+               case 3:\r
+                       if (wp < size)\r
+                       {\r
+                               u[wp++] = 0xe0 | (((c1 & 0xf0) >> 4) & 0x0f);\r
+                       }\r
+                       if (wp < size)\r
+                       {\r
+                               u[wp++] = 0x80 | (((c1 & 0x0f) << 2) & 0x3c) | (((c2 & 0xc0) >> 6) & 0x03);\r
+                       }\r
+                       if (wp < size)\r
+                       {\r
+                               u[wp++] = 0x80 | (c2 & 0x3f);\r
+                       }\r
+                       break;\r
+               }\r
+       }\r
+       if (wp < size)\r
+       {\r
+               u[wp] = 0;\r
+       }\r
+       return wp;\r
+}\r
+\r
+// Unicode 文字列を UTF-8 文字列に変換した場合の文字列長を計算する\r
+UINT CalcUniToUtf8(wchar_t *s)\r
+{\r
+       UINT i, len, size;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       size = 0;\r
+       len = UniStrLen(s);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               size += GetUniType(s[i]);\r
+       }\r
+\r
+       return size;\r
+}\r
+\r
+// s で始まる UTF-8 文字列の offset 番地の最初の 1 文字が何バイトで構成されているかを取得\r
+UINT GetUtf8Type(BYTE *s, UINT size, UINT offset)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if ((offset + 1) > size)\r
+       {\r
+               return 0;\r
+       }\r
+       if ((s[offset] & 0x80) == 0)\r
+       {\r
+               // 1 バイト\r
+               return 1;\r
+       }\r
+       if ((s[offset] & 0x20) == 0)\r
+       {\r
+               // 2 バイト\r
+               if ((offset + 2) > size)\r
+               {\r
+                       return 0;\r
+               }\r
+               return 2;\r
+       }\r
+       // 3 バイト\r
+       if ((offset + 3) > size)\r
+       {\r
+               return 0;\r
+       }\r
+       return 3;\r
+}\r
+\r
+// 文字 c を UTF-8 に変換した場合の種類 (バイト数)\r
+UINT GetUniType(wchar_t c)\r
+{\r
+       BYTE c1, c2;\r
+\r
+       if (IsBigEndian())\r
+       {\r
+               if (sizeof(wchar_t) == 2)\r
+               {\r
+                       c1 = ((BYTE *)&c)[0];\r
+                       c2 = ((BYTE *)&c)[1];\r
+               }\r
+               else\r
+               {\r
+                       c1 = ((BYTE *)&c)[2];\r
+                       c2 = ((BYTE *)&c)[3];\r
+               }\r
+       }\r
+       else\r
+       {\r
+               c1 = ((BYTE *)&c)[1];\r
+               c2 = ((BYTE *)&c)[0];\r
+       }\r
+\r
+       if (c1 == 0)\r
+       {\r
+               if (c2 <= 0x7f)\r
+               {\r
+                       // 1 バイト\r
+                       return 1;\r
+               }\r
+               else\r
+               {\r
+                       // 2 バイト\r
+                       return 2;\r
+               }\r
+       }\r
+       if ((c1 & 0xf8) == 0)\r
+       {\r
+               // 2 バイト\r
+               return 2;\r
+       }\r
+       // 3 バイト\r
+       return 3;\r
+}\r
+\r
+// 文字列の置換 (大文字小文字を区別しない)\r
+UINT UniReplaceStri(wchar_t *dst, UINT size, wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword)\r
+{\r
+       return UniReplaceStrEx(dst, size, string, old_keyword, new_keyword, false);\r
+}\r
+\r
+// 文字列の置換 (大文字小文字を区別する)\r
+UINT UniReplaceStr(wchar_t *dst, UINT size, wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword)\r
+{\r
+       return UniReplaceStrEx(dst, size, string, old_keyword, new_keyword, true);\r
+}\r
+\r
+// 文字列の置換\r
+UINT UniReplaceStrEx(wchar_t *dst, UINT size, wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword, bool case_sensitive)\r
+{\r
+       UINT i, j, num, len_string, len_old, len_new, len_ret, wp;\r
+       wchar_t *ret;\r
+       // 引数チェック\r
+       if (string == NULL || old_keyword == NULL || new_keyword == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // 文字列長の取得\r
+       len_string = UniStrLen(string);\r
+       len_old = UniStrLen(old_keyword);\r
+       len_new = UniStrLen(new_keyword);\r
+\r
+       // 最終文字列長の取得\r
+       len_ret = UniCalcReplaceStrEx(string, old_keyword, new_keyword, case_sensitive);\r
+       // メモリ確保\r
+       ret = Malloc((len_ret + 1) * sizeof(wchar_t));\r
+       ret[len_ret] = 0;\r
+\r
+       // 検索と置換\r
+       i = j = num = wp = 0;\r
+       while (true)\r
+       {\r
+               i = UniSearchStrEx(string, old_keyword, i, case_sensitive);\r
+               if (i == INFINITE)\r
+               {\r
+                       Copy(&ret[wp], &string[j], (len_string - j) * sizeof(wchar_t));\r
+                       wp += len_string - j;\r
+                       break;\r
+               }\r
+               num++;\r
+               Copy(&ret[wp], &string[j], (i - j) * sizeof(wchar_t));\r
+               wp += i - j;\r
+               Copy(&ret[wp], new_keyword, len_new * sizeof(wchar_t));\r
+               wp += len_new;\r
+               i += len_old;\r
+               j = i;\r
+       }\r
+\r
+       // 検索結果のコピー\r
+       UniStrCpy(dst, size, ret);\r
+\r
+       // メモリ解放\r
+       Free(ret);\r
+\r
+       return num;\r
+}\r
+\r
+// 文字列の置換後の文字列長を計算する\r
+UINT UniCalcReplaceStrEx(wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword, bool case_sensitive)\r
+{\r
+       UINT i, num;\r
+       UINT len_string, len_old, len_new;\r
+       // 引数チェック\r
+       if (string == NULL || old_keyword == NULL || new_keyword == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // 文字列長の取得\r
+       len_string = UniStrLen(string);\r
+       len_old = UniStrLen(old_keyword);\r
+       len_new = UniStrLen(new_keyword);\r
+\r
+       if (len_old == len_new)\r
+       {\r
+               return len_string;\r
+       }\r
+\r
+       // 検索処理\r
+       num = 0;\r
+       i = 0;\r
+       while (true)\r
+       {\r
+               i = UniSearchStrEx(string, old_keyword, i, case_sensitive);\r
+               if (i == INFINITE)\r
+               {\r
+                       break;\r
+               }\r
+               i += len_old;\r
+               num++;\r
+       }\r
+\r
+       // 計算\r
+       return len_string + len_new * num - len_old * num;\r
+}\r
+\r
+// 文字列の検索 (大文字 / 小文字を区別する)\r
+UINT UniSearchStr(wchar_t *string, wchar_t *keyword, UINT start)\r
+{\r
+       return UniSearchStrEx(string, keyword, start, true);\r
+}\r
+\r
+// 文字列の検索 (大文字 / 小文字を区別しない)\r
+UINT UniSearchStri(wchar_t *string, wchar_t *keyword, UINT start)\r
+{\r
+       return UniSearchStrEx(string, keyword, start, false);\r
+}\r
+\r
+// 文字列 string から文字列 keyword を検索して最初に見つかった文字の場所を返す\r
+// (1文字目に見つかったら 0, 見つからなかったら INFINITE)\r
+UINT UniSearchStrEx(wchar_t *string, wchar_t *keyword, UINT start, bool case_sensitive)\r
+{\r
+       UINT len_string, len_keyword;\r
+       UINT i;\r
+       wchar_t *cmp_string, *cmp_keyword;\r
+       bool found;\r
+       // 引数チェック\r
+       if (string == NULL || keyword == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       // string の長さを取得\r
+       len_string = UniStrLen(string);\r
+       if (len_string <= start)\r
+       {\r
+               // start の値が不正\r
+               return INFINITE;\r
+       }\r
+\r
+       // keyword の長さを取得\r
+       len_keyword = UniStrLen(keyword);\r
+       if (len_keyword == 0)\r
+       {\r
+               // キーワードが無い\r
+               return INFINITE;\r
+       }\r
+\r
+       if (len_string < len_keyword)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       if (len_string == len_keyword)\r
+       {\r
+               if (case_sensitive)\r
+               {\r
+                       if (UniStrCmp(string, keyword) == 0)\r
+                       {\r
+                               return 0;\r
+                       }\r
+                       else\r
+                       {\r
+                               return INFINITE;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if (UniStrCmpi(string, keyword) == 0)\r
+                       {\r
+                               return 0;\r
+                       }\r
+                       else\r
+                       {\r
+                               return INFINITE;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (case_sensitive)\r
+       {\r
+               cmp_string = string;\r
+               cmp_keyword = keyword;\r
+       }\r
+       else\r
+       {\r
+               cmp_string = Malloc((len_string + 1) * sizeof(wchar_t));\r
+               UniStrCpy(cmp_string, (len_string + 1) * sizeof(wchar_t), string);\r
+               cmp_keyword = Malloc((len_keyword + 1) * sizeof(wchar_t));\r
+               UniStrCpy(cmp_keyword, (len_keyword + 1) * sizeof(wchar_t), keyword);\r
+               UniStrUpper(cmp_string);\r
+               UniStrUpper(cmp_keyword);\r
+       }\r
+\r
+       // 検索\r
+       found = false;\r
+       for (i = start;i < (len_string - len_keyword + 1);i++)\r
+       {\r
+               // 比較する\r
+               if (!wcsncmp(&cmp_string[i], cmp_keyword, len_keyword))\r
+               {\r
+                       // 発見した\r
+                       found = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (case_sensitive == false)\r
+       {\r
+               // メモリ解放\r
+               Free(cmp_keyword);\r
+               Free(cmp_string);\r
+       }\r
+\r
+       if (found == false)\r
+       {\r
+               return INFINITE;\r
+       }\r
+       return i;\r
+}\r
+\r
+// トークンリストの解放\r
+void UniFreeToken(UNI_TOKEN_LIST *tokens)\r
+{\r
+       UINT i;\r
+       if (tokens == NULL)\r
+       {\r
+               return;\r
+       }\r
+       for (i = 0;i < tokens->NumTokens;i++)\r
+       {\r
+               Free(tokens->Token[i]);\r
+       }\r
+       Free(tokens->Token);\r
+       Free(tokens);\r
+}\r
+\r
+// UNIX 版トークンのパース\r
+UNI_TOKEN_LIST *UnixUniParseToken(wchar_t *src, wchar_t *separator)\r
+{\r
+       UNI_TOKEN_LIST *ret;\r
+       TOKEN_LIST *t;\r
+       char *src_s;\r
+       char *sep_s;\r
+\r
+       // 引数チェック\r
+       if (src == NULL || separator == NULL)\r
+       {\r
+               ret = ZeroMalloc(sizeof(UNI_TOKEN_LIST));\r
+               ret->Token = ZeroMalloc(0);\r
+               return ret;\r
+       }\r
+\r
+       src_s = CopyUniToStr(src);\r
+       sep_s = CopyUniToStr(separator);\r
+\r
+       t = ParseToken(src_s, sep_s);\r
+\r
+       ret = TokenListToUniTokenList(t);\r
+       FreeToken(t);\r
+\r
+       Free(src_s);\r
+       Free(sep_s);\r
+\r
+       return ret;\r
+}\r
+\r
+// トークンのパース\r
+UNI_TOKEN_LIST *UniParseToken(wchar_t *src, wchar_t *separator)\r
+{\r
+#ifdef OS_WIN32\r
+       UNI_TOKEN_LIST *ret;\r
+       wchar_t *tmp;\r
+       wchar_t *str1, *str2;\r
+       UINT len, num;\r
+\r
+#ifdef OS_UNIX\r
+       wchar_t *state = NULL;\r
+#endif // OS_UNIX\r
+\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               ret = ZeroMalloc(sizeof(UNI_TOKEN_LIST));\r
+               ret->Token = ZeroMalloc(0);\r
+               return ret;\r
+       }\r
+       if (separator == NULL)\r
+       {\r
+               separator = L" .\t\r\n";\r
+       }\r
+       len = UniStrLen(src);\r
+       str1 = Malloc((len + 1) * sizeof(wchar_t));\r
+       str2 = Malloc((len + 1) * sizeof(wchar_t));\r
+       UniStrCpy(str1, 0, src);\r
+       UniStrCpy(str2, 0, src);\r
+\r
+       Lock(token_lock);\r
+       {\r
+               tmp = wcstok(str1, separator\r
+#ifdef OS_UNIX\r
+                       , &state\r
+#endif // OS_UNIX\r
+                       );\r
+               num = 0;\r
+               while (tmp != NULL)\r
+               {\r
+                       num++;\r
+                       tmp = wcstok(NULL, separator\r
+#ifdef OS_UNIX\r
+                               , &state\r
+#endif // OS_UNIX\r
+                               );\r
+               }\r
+               ret = Malloc(sizeof(UNI_TOKEN_LIST));\r
+               ret->NumTokens = num;\r
+               ret->Token = (wchar_t **)Malloc(sizeof(wchar_t *) * num);\r
+               num = 0;\r
+               tmp = wcstok(str2, separator\r
+#ifdef OS_UNIX\r
+                       , &state\r
+#endif // OS_UNIX\r
+                       );\r
+               while (tmp != NULL)\r
+               {\r
+                       ret->Token[num] = (wchar_t *)Malloc((UniStrLen(tmp) + 1) * sizeof(wchar_t));\r
+                       UniStrCpy(ret->Token[num], 0, tmp);\r
+                       num++;\r
+                       tmp = wcstok(NULL, separator\r
+#ifdef OS_UNIX\r
+                               , &state\r
+#endif // OS_UNIX\r
+                               );\r
+               }\r
+       }\r
+       Unlock(token_lock);\r
+\r
+       Free(str1);\r
+       Free(str2);\r
+       return ret;\r
+#else  // OS_WIN32\r
+       return UnixUniParseToken(src, separator);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// 1 行を標準入力から取得\r
+bool UniGetLine(wchar_t *str, UINT size)\r
+{\r
+#ifdef OS_WIN32\r
+       return UniGetLineWin32(str, size);\r
+#else  // OS_WIN32\r
+       return UniGetLineUnix(str, size);\r
+#endif // OS_WIN32\r
+}\r
+void AnsiGetLineUnix(char *str, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               fgets(tmp, sizeof(tmp) - 1, stdin);\r
+               return;\r
+       }\r
+       if (size <= 1)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 標準入力からデータを読み込み\r
+       fgets(str, (int)(size - 1), stdin);\r
+\r
+       TrimCrlf(str);\r
+}\r
+bool UniGetLineUnix(wchar_t *str, UINT size)\r
+{\r
+       char *str_a;\r
+       UINT str_a_size = size;\r
+       if (str == NULL || size < sizeof(wchar_t))\r
+       {\r
+               return false;\r
+       }\r
+       if (str_a_size >= 0x7fffffff)\r
+       {\r
+               str_a_size = MAX_SIZE;\r
+       }\r
+       str_a_size *= 2;\r
+\r
+       str_a = ZeroMalloc(str_a_size);\r
+\r
+       AnsiGetLineUnix(str_a, str_a_size);\r
+\r
+       StrToUni(str, size, str_a);\r
+\r
+       Free(str_a);\r
+\r
+       return true;\r
+}\r
+bool UniGetLineWin32(wchar_t *str, UINT size)\r
+{\r
+       bool ret = false;\r
+\r
+#ifdef OS_WIN32\r
+       ret = Win32InputW(str, size);\r
+#endif // OS_WIN32\r
+\r
+       return ret;\r
+}\r
+\r
+// 末尾の \r \n を削除\r
+void UniTrimCrlf(wchar_t *str)\r
+{\r
+       UINT len;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+       len = UniStrLen(str);\r
+       if (len == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (str[len - 1] == L'\n')\r
+       {\r
+               if (len >= 2 && str[len - 2] == L'\r')\r
+               {\r
+                       str[len - 2] = 0;\r
+               }\r
+               str[len - 1] = 0;\r
+       }\r
+       else if(str[len - 1] == L'\r')\r
+       {\r
+               str[len - 1] = 0;\r
+       }\r
+}\r
+\r
+// 文字列の左右の空白を削除\r
+void UniTrim(wchar_t *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniTrimLeft(str);\r
+       UniTrimRight(str);\r
+}\r
+\r
+// 文字列の右側の空白を削除\r
+void UniTrimRight(wchar_t *str)\r
+{\r
+       wchar_t *buf, *tmp;\r
+       UINT len, i, wp, wp2;\r
+       bool flag;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+       len = UniStrLen(str);\r
+       if (len == 0)\r
+       {\r
+               return;\r
+       }\r
+       if (str[len - 1] != L' ' && str[len - 1] != L'\t')\r
+       {\r
+               return;\r
+       }\r
+\r
+       buf = Malloc((len + 1) * sizeof(wchar_t));\r
+       tmp = Malloc((len + 1) * sizeof(wchar_t));\r
+       flag = false;\r
+       wp = wp2 = 0;\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (str[i] != L' ' && str[i] != L'\t')\r
+               {\r
+                       Copy(&buf[wp], tmp, wp2 * sizeof(wchar_t));\r
+                       wp += wp2;\r
+                       wp2 = 0;\r
+                       buf[wp++] = str[i];\r
+               }\r
+               else\r
+               {\r
+                       tmp[wp2++] = str[i];\r
+               }\r
+       }\r
+       buf[wp] = 0;\r
+       UniStrCpy(str, 0, buf);\r
+       Free(buf);\r
+       Free(tmp);\r
+}\r
+\r
+// 文字列の左側の空白を削除\r
+void UniTrimLeft(wchar_t *str)\r
+{\r
+       wchar_t *buf;\r
+       UINT len, i, wp;\r
+       bool flag;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+       len = UniStrLen(str);\r
+       if (len == 0)\r
+       {\r
+               return;\r
+       }\r
+       if (str[0] != L' ' && str[0] != L'\t')\r
+       {\r
+               return;\r
+       }\r
+\r
+       buf = Malloc((len + 1) * sizeof(wchar_t));\r
+       flag = false;\r
+       wp = 0;\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (str[i] != L' ' && str[i] != L'\t')\r
+               {\r
+                       flag = true;\r
+               }\r
+               if (flag)\r
+               {\r
+                       buf[wp++] = str[i];\r
+               }\r
+       }\r
+       buf[wp] = 0;\r
+       UniStrCpy(str, 0, buf);\r
+       Free(buf);\r
+}\r
+\r
+// 整数を 16 進文字列に変換 (8桁固定)\r
+void UniToStrx8(wchar_t *str, UINT i)\r
+{\r
+       UniFormat(str, 0, L"0x%08x", i);\r
+}\r
+\r
+// 整数を 16 進文字列に変換\r
+void UniToStrx(wchar_t *str, UINT i)\r
+{\r
+       UniFormat(str, 0, L"0x%02x", i);\r
+}\r
+\r
+// 符号付整数を文字列に変換\r
+void UniToStri(wchar_t *str, int i)\r
+{\r
+       UniFormat(str, 0, L"%i", i);\r
+}\r
+\r
+// 整数を文字列に変換\r
+void UniToStru(wchar_t *str, UINT i)\r
+{\r
+       UniFormat(str, 0, L"%u", i);\r
+}\r
+\r
+// 文字列を符号付整数に変換\r
+int UniToInti(wchar_t *str)\r
+{\r
+       char tmp[128];\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       return ToInt(tmp);\r
+}\r
+\r
+// 文字列を整数に変換\r
+UINT UniToInt(wchar_t *str)\r
+{\r
+       char tmp[128];\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       UniToStr(tmp, sizeof(tmp), str);\r
+\r
+       return ToInti(tmp);\r
+}\r
+\r
+// 64bit 用フォーマット文字列置換\r
+wchar_t *UniReplaceFormatStringFor64(wchar_t *fmt)\r
+{\r
+       wchar_t *tmp;\r
+       wchar_t *ret;\r
+       UINT tmp_size;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       tmp_size = UniStrSize(fmt) * 2;\r
+       tmp = ZeroMalloc(tmp_size);\r
+\r
+#ifdef OS_WIN32\r
+       UniReplaceStrEx(tmp, tmp_size, fmt, L"%ll", L"%I64", false);\r
+#else  // OS_WIN32\r
+       UniReplaceStrEx(tmp, tmp_size, fmt, L"%I64", L"%ll", false);\r
+\r
+       if (1)\r
+       {\r
+               UINT i, len;\r
+               bool f = false;\r
+               len = UniStrLen(tmp);\r
+               for (i = 0;i < len;i++)\r
+               {\r
+                       if (tmp[i] == L'%')\r
+                       {\r
+                               f = true;\r
+                       }\r
+\r
+                       if (f)\r
+                       {\r
+                               switch (tmp[i])\r
+                               {\r
+                               case L'c':\r
+                               case L'C':\r
+                               case L'd':\r
+                               case L'i':\r
+                               case L'o':\r
+                               case L'u':\r
+                               case L'x':\r
+                               case L'X':\r
+                               case L'e':\r
+                               case L'E':\r
+                               case L'f':\r
+                               case L'g':\r
+                               case L'G':\r
+                               case L'n':\r
+                               case L'p':\r
+                               case L's':\r
+                               case L'S':\r
+                                       if (tmp[i] == L's')\r
+                                       {\r
+                                               tmp[i] = L'S';\r
+                                       }\r
+                                       else if (tmp[i] == L'S')\r
+                                       {\r
+                                               tmp[i] = L's';\r
+                                       }\r
+                                       f = false;\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+#endif // OS_WIN32\r
+\r
+       ret = CopyUniStr(tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// 文字列を画面に表示する\r
+void UniPrintStr(wchar_t *string)\r
+{\r
+       // 引数チェック\r
+       if (string == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_UNIX\r
+       if (true)\r
+       {\r
+               char *str = CopyUniToStr(string);\r
+\r
+               if (str != NULL)\r
+               {\r
+                       fputs(str, stdout);\r
+               }\r
+               else\r
+               {\r
+                       fputs("", stdout);\r
+               }\r
+\r
+               Free(str);\r
+       }\r
+#else  // OS_UNIX\r
+       Win32PrintW(string);\r
+#endif // OS_UNIX\r
+}\r
+\r
+// 文字列を引数付きで表示する\r
+void UniPrintArgs(wchar_t *fmt, va_list args)\r
+{\r
+       wchar_t *str;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       str = InternalFormatArgs(fmt, args, false);\r
+\r
+       UniPrintStr(str);\r
+\r
+       Free(str);\r
+}\r
+\r
+// 文字列を表示する\r
+void UniPrint(wchar_t *fmt, ...)\r
+{\r
+       va_list args;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, fmt);\r
+       UniPrintArgs(fmt, args);\r
+       va_end(args);\r
+}\r
+\r
+// デバッグ文字列を引数付きで表示する\r
+void UniDebugArgs(wchar_t *fmt, va_list args)\r
+{\r
+       if (g_debug == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniPrintArgs(fmt, args);\r
+}\r
+\r
+// デバッグ文字列を表示する\r
+void UniDebug(wchar_t *fmt, ...)\r
+{\r
+       va_list args;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, fmt);\r
+       UniDebugArgs(fmt, args);\r
+       va_end(args);\r
+}\r
+\r
+// 文字列をフォーマットする (引数リスト)\r
+void UniFormatArgs(wchar_t *buf, UINT size, wchar_t *fmt, va_list args)\r
+{\r
+       wchar_t *ret;\r
+       // 引数チェック\r
+       if (buf == NULL || fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (size == 1)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_FORMAT_COUNT);\r
+\r
+       ret = InternalFormatArgs(fmt, args, false);\r
+\r
+       UniStrCpy(buf, size, ret);\r
+\r
+       Free(ret);\r
+}\r
+\r
+// 文字列をフォーマットして結果をコピーする\r
+wchar_t *CopyUniFormat(wchar_t *fmt, ...)\r
+{\r
+       wchar_t *ret, *str;\r
+       UINT size;\r
+       va_list args;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = MAX(UniStrSize(fmt) * 10, MAX_SIZE * 10);\r
+       str = Malloc(size);\r
+\r
+       va_start(args, fmt);\r
+       UniFormatArgs(str, size, fmt, args);\r
+\r
+       ret = UniCopyStr(str);\r
+       Free(str);\r
+       va_end(args);\r
+\r
+       return ret;\r
+}\r
+\r
+// 文字列をフォーマットする\r
+void UniFormat(wchar_t *buf, UINT size, wchar_t *fmt, ...)\r
+{\r
+       va_list args;\r
+       // 引数チェック\r
+       if (buf == NULL || fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, fmt);\r
+       UniFormatArgs(buf, size, fmt, args);\r
+       va_end(args);\r
+}\r
+\r
+// 柔軟な文字列比較\r
+int UniSoftStrCmp(wchar_t *str1, wchar_t *str2)\r
+{\r
+       UINT ret;\r
+       wchar_t *tmp1, *tmp2;\r
+       // 引数チェック\r
+       if (str1 == NULL && str2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (str1 == NULL)\r
+       {\r
+               return 1;\r
+       }\r
+       if (str2 == NULL)\r
+       {\r
+               return -1;\r
+       }\r
+\r
+       tmp1 = CopyUniStr(str1);\r
+       tmp2 = CopyUniStr(str2);\r
+\r
+       UniTrim(tmp1);\r
+       UniTrim(tmp2);\r
+\r
+       ret = UniStrCmpi(tmp1, tmp2);\r
+\r
+       Free(tmp1);\r
+       Free(tmp2);\r
+\r
+       return ret;\r
+}\r
+\r
+// 文字列を大文字・小文字を区別せずに比較する\r
+int UniStrCmpi(wchar_t *str1, wchar_t *str2)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str1 == NULL && str2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (str1 == NULL)\r
+       {\r
+               return 1;\r
+       }\r
+       if (str2 == NULL)\r
+       {\r
+               return -1;\r
+       }\r
+\r
+       // 文字列比較\r
+       i = 0;\r
+       while (true)\r
+       {\r
+               wchar_t c1, c2;\r
+               c1 = UniToUpper(str1[i]);\r
+               c2 = UniToUpper(str2[i]);\r
+               if (c1 > c2)\r
+               {\r
+                       return 1;\r
+               }\r
+               else if (c1 < c2)\r
+               {\r
+                       return -1;\r
+               }\r
+               if (str1[i] == 0 || str2[i] == 0)\r
+               {\r
+                       return 0;\r
+               }\r
+               i++;\r
+       }\r
+}\r
+\r
+// 文字列を比較する\r
+int UniStrCmp(wchar_t *str1, wchar_t *str2)\r
+{\r
+       // 引数チェック\r
+       if (str1 == NULL && str2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (str1 == NULL)\r
+       {\r
+               return 1;\r
+       }\r
+       if (str2 == NULL)\r
+       {\r
+               return -1;\r
+       }\r
+\r
+       return wcscmp(str1, str2);\r
+}\r
+\r
+// 文字列を小文字にする\r
+void UniStrLower(wchar_t *str)\r
+{\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       len = UniStrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               str[i] = UniToLower(str[i]);\r
+       }\r
+}\r
+\r
+// 文字列を大文字にする\r
+void UniStrUpper(wchar_t *str)\r
+{\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       len = UniStrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               str[i] = UniToUpper(str[i]);\r
+       }\r
+}\r
+\r
+// 文字を小文字にする\r
+wchar_t UniToLower(wchar_t c)\r
+{\r
+       if (c >= L'A' && c <= L'Z')\r
+       {\r
+               c += L'a' - L'A';\r
+       }\r
+\r
+       return c;\r
+}\r
+\r
+// 文字を大文字にする\r
+wchar_t UniToUpper(wchar_t c)\r
+{\r
+       if (c >= L'a' && c <= L'z')\r
+       {\r
+               c -= L'a' - L'A';\r
+       }\r
+\r
+       return c;\r
+}\r
+\r
+// 文字列結合\r
+UINT UniStrCat(wchar_t *dst, UINT size, wchar_t *src)\r
+{\r
+       UINT len1, len2, len_test;\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (size != 0 && size < sizeof(wchar_t))\r
+       {\r
+               return 0;\r
+       }\r
+       if (size == sizeof(wchar_t))\r
+       {\r
+               wcscpy(dst, L"");\r
+               return 0;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               // 長さ無視\r
+               size = 0x3fffffff;\r
+       }\r
+\r
+       len1 = UniStrLen(dst);\r
+       len2 = UniStrLen(src);\r
+       len_test = len1 + len2 + 1;\r
+       if (len_test > (size / sizeof(wchar_t)))\r
+       {\r
+               if (len2 <= (len_test - (size / sizeof(wchar_t))))\r
+               {\r
+                       return 0;\r
+               }\r
+               len2 -= len_test - (size / sizeof(wchar_t));\r
+       }\r
+       Copy(&dst[len1], src, len2 * sizeof(wchar_t));\r
+       dst[len1 + len2] = 0;\r
+\r
+       return len1 + len2;\r
+}\r
+UINT UniStrCatLeft(wchar_t *dst, UINT size, wchar_t *src)\r
+{\r
+       wchar_t *s;\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       s = UniCopyStr(dst);\r
+       UniStrCpy(dst, size, s);\r
+       UniStrCat(dst, size, src);\r
+       Free(s);\r
+\r
+       return UniStrLen(dst);\r
+}\r
+\r
+// 文字列コピー\r
+UINT UniStrCpy(wchar_t *dst, UINT size, wchar_t *src)\r
+{\r
+       UINT len;\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               if (src == NULL && dst != NULL)\r
+               {\r
+                       if (size >= sizeof(wchar_t))\r
+                       {\r
+                               dst[0] = L'\0';\r
+                       }\r
+               }\r
+               return 0;\r
+       }\r
+       if (dst == src)\r
+       {\r
+               return UniStrLen(src);\r
+       }\r
+       if (size != 0 && size < sizeof(wchar_t))\r
+       {\r
+               return 0;\r
+       }\r
+       if (size == sizeof(wchar_t))\r
+       {\r
+               wcscpy(dst, L"");\r
+               return 0;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               // 長さ無視\r
+               size = 0x3fffffff;\r
+       }\r
+\r
+       // 長さをチェック\r
+       len = UniStrLen(src);\r
+       if (len <= (size / sizeof(wchar_t) - 1))\r
+       {\r
+               Copy(dst, src, (len + 1) * sizeof(wchar_t));\r
+       }\r
+       else\r
+       {\r
+               len = size / 2 - 1;\r
+               Copy(dst, src, len * sizeof(wchar_t));\r
+               dst[len] = 0;\r
+       }\r
+\r
+       return len;\r
+}\r
+\r
+// 文字が指定されたバッファサイズ以内かどうかチェック\r
+bool UniCheckStrSize(wchar_t *str, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || size <= 1)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return UniCheckStrLen(str, size / sizeof(wchar_t) - 1);\r
+}\r
+\r
+// 文字数が指定された長さ以内かどうかチェック\r
+bool UniCheckStrLen(wchar_t *str, UINT len)\r
+{\r
+       UINT count = 0;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;;i++)\r
+       {\r
+               if (str[i] == 0)\r
+               {\r
+                       return true;\r
+               }\r
+               count++;\r
+               if (count > len)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+}\r
+\r
+// 文字列の格納に必要なバッファサイズの取得\r
+UINT UniStrSize(wchar_t *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return (UniStrLen(str) + 1) * sizeof(wchar_t);\r
+}\r
+\r
+// 文字列の長さの取得\r
+UINT UniStrLen(wchar_t *str)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       i = 0;\r
+       while (true)\r
+       {\r
+               if (str[i] == 0)\r
+               {\r
+                       break;\r
+               }\r
+               i++;\r
+       }\r
+\r
+       return i;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Internat.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Internat.h
new file mode 100644 (file)
index 0000000..3bdab44
--- /dev/null
@@ -0,0 +1,217 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Internat.h\r
+// Internat.c のヘッダ\r
+\r
+#ifndef        INTERNAT_H\r
+#define        INTERNAT_H\r
+\r
+// 文字列トークン\r
+struct UNI_TOKEN_LIST\r
+{\r
+       UINT NumTokens;\r
+       wchar_t **Token;\r
+};\r
+\r
+UINT UniStrLen(wchar_t *str);\r
+UINT UniStrSize(wchar_t *str);\r
+UINT UniStrCpy(wchar_t *dst, UINT size, wchar_t *src);\r
+bool UniCheckStrSize(wchar_t *str, UINT size);\r
+bool UniCheckStrLen(wchar_t *str, UINT len);\r
+UINT UniStrCat(wchar_t *dst, UINT size, wchar_t *src);\r
+UINT UniStrCatLeft(wchar_t *dst, UINT size, wchar_t *src);\r
+wchar_t UniToLower(wchar_t c);\r
+wchar_t UniToUpper(wchar_t c);\r
+void UniStrLower(wchar_t *str);\r
+void UniStrUpper(wchar_t *str);\r
+int UniStrCmp(wchar_t *str1, wchar_t *str2);\r
+int UniStrCmpi(wchar_t *str1, wchar_t *str2);\r
+int UniSoftStrCmp(wchar_t *str1, wchar_t *str2);\r
+void UniFormat(wchar_t *buf, UINT size, wchar_t *fmt, ...);\r
+wchar_t *CopyUniFormat(wchar_t *fmt, ...);\r
+void UniFormatArgs(wchar_t *buf, UINT size, wchar_t *fmt, va_list args);\r
+void UniDebugArgs(wchar_t *fmt, va_list args);\r
+void UniDebug(wchar_t *fmt, ...);\r
+void UniPrint(wchar_t *fmt, ...);\r
+void UniPrintArgs(wchar_t *fmt, va_list args);\r
+void UniPrintStr(wchar_t *string);\r
+void UniToStrx8(wchar_t *str, UINT i);\r
+void UniToStrx(wchar_t *str, UINT i);\r
+void UniToStri(wchar_t *str, int i);\r
+void UniToStru(wchar_t *str, UINT i);\r
+int UniToInti(wchar_t *str);\r
+UINT UniToInt(wchar_t *str);\r
+void UniTrim(wchar_t *str);\r
+void UniTrimLeft(wchar_t *str);\r
+void UniTrimRight(wchar_t *str);\r
+void UniTrimCrlf(wchar_t *str);\r
+bool UniGetLine(wchar_t *str, UINT size);\r
+bool UniGetLineWin32(wchar_t *str, UINT size);\r
+bool UniGetLineUnix(wchar_t *str, UINT size);\r
+void UniFreeToken(UNI_TOKEN_LIST *tokens);\r
+UNI_TOKEN_LIST *UniParseToken(wchar_t *src, wchar_t *separator);\r
+UINT UniSearchStrEx(wchar_t *string, wchar_t *keyword, UINT start, bool case_sensitive);\r
+UINT UniSearchStri(wchar_t *string, wchar_t *keyword, UINT start);\r
+UINT UniSearchStr(wchar_t *string, wchar_t *keyword, UINT start);\r
+UINT UniCalcReplaceStrEx(wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword, bool case_sensitive);\r
+UINT UniReplaceStrEx(wchar_t *dst, UINT size, wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword, bool case_sensitive);\r
+UINT UniReplaceStri(wchar_t *dst, UINT size, wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword);\r
+UINT UniReplaceStr(wchar_t *dst, UINT size, wchar_t *string, wchar_t *old_keyword, wchar_t *new_keyword);\r
+UINT GetUniType(wchar_t c);\r
+UINT GetUtf8Type(BYTE *s, UINT size, UINT offset);\r
+UINT CalcUniToUtf8(wchar_t *s);\r
+UINT UniToUtf8(BYTE *u, UINT size, wchar_t *s);\r
+UINT Utf8Len(BYTE *u, UINT size);\r
+UINT CalcUtf8ToUni(BYTE *u, UINT u_size);\r
+UINT Utf8ToUni(wchar_t *s, UINT size, BYTE *u, UINT u_size);\r
+UINT CalcStrToUni(char *str);\r
+UINT StrToUni(wchar_t *s, UINT size, char *str);\r
+UINT CalcUniToStr(wchar_t *s);\r
+UINT UniToStr(char *str, UINT size, wchar_t *s);\r
+UINT CalcStrToUtf8(char *str);\r
+UINT StrToUtf8(BYTE *u, UINT size, char *str);\r
+UINT CalcUtf8ToStr(BYTE *u, UINT size);\r
+UINT Utf8ToStr(char *str, UINT str_size, BYTE *u, UINT size);\r
+bool IsSafeUniStr(wchar_t *str);\r
+bool IsSafeUniChar(wchar_t c);\r
+wchar_t *CopyUniStr(wchar_t *str);\r
+wchar_t *CopyStrToUni(char *str);\r
+UINT StrToUtf(char *utfstr, UINT size, char *str);\r
+UINT UtfToStr(char *str, UINT size, char *utfstr);\r
+UINT UniToUtf(char *utfstr, UINT size, wchar_t *unistr);\r
+UINT UtfToUni(wchar_t *unistr, UINT size, char *utfstr);\r
+char *CopyUniToUtf(wchar_t *unistr);\r
+char *CopyStrToUtf(char *str);\r
+char *CopyUniToStr(wchar_t *unistr);\r
+wchar_t *CopyUtfToUni(char *utfstr);\r
+char *CopyUtfToStr(char *utfstr);\r
+wchar_t *UniReplaceFormatStringFor64(wchar_t *fmt);\r
+void UniToStr64(wchar_t *str, UINT64 value);\r
+UINT64 UniToInt64(wchar_t *str);\r
+UNI_TOKEN_LIST *UniParseCmdLine(wchar_t *str);\r
+UNI_TOKEN_LIST *UniCopyToken(UNI_TOKEN_LIST *src);\r
+wchar_t *UniCopyStr(wchar_t *str);\r
+TOKEN_LIST *UniTokenListToTokenList(UNI_TOKEN_LIST *src);\r
+UNI_TOKEN_LIST *TokenListToUniTokenList(TOKEN_LIST *src);\r
+UNI_TOKEN_LIST *UniNullToken();\r
+UNI_TOKEN_LIST *NullUniToken();\r
+bool UniIsNum(wchar_t *str);\r
+bool IsEmptyUniStr(wchar_t *str);\r
+bool UniIsEmptyStr(wchar_t *str);\r
+void InitInternational();\r
+void FreeInternational();\r
+USHORT *WideToUtf16(wchar_t *str);\r
+wchar_t *Utf16ToWide(USHORT *str);\r
+void DumpUniStr(wchar_t *str);\r
+void DumpStr(char *str);\r
+wchar_t *InternalFormatArgs(wchar_t *fmt, va_list args, bool ansi_mode);\r
+UINT UniStrWidth(wchar_t *str);\r
+UNI_TOKEN_LIST *UnixUniParseToken(wchar_t *src, wchar_t *separator);\r
+void UniToStr3(wchar_t *str, UINT size, UINT64 value);\r
+bool UniEndWith(wchar_t *str, wchar_t *key);\r
+bool UniStartWith(wchar_t *str, wchar_t *key);\r
+wchar_t *UniNormalizeCrlf(wchar_t *str);\r
+LIST *UniStrToStrList(wchar_t *str, UINT size);\r
+BUF *UniStrListToStr(LIST *o);\r
+void UniFreeStrList(LIST *o);\r
+UNI_TOKEN_LIST *UniListToTokenList(LIST *o);\r
+LIST *UniTokenListToList(UNI_TOKEN_LIST *t);\r
+bool UniIsSafeChar(wchar_t c);\r
+wchar_t *UniMakeCharArray(wchar_t c, UINT count);\r
+BUF *UniStrToBin(wchar_t *str);\r
+bool UniInStr(wchar_t *str, wchar_t *keyword);\r
+bool UniInStrEx(wchar_t *str, wchar_t *keyword, bool case_sensitive);\r
+\r
+#ifdef OS_UNIX\r
+void GetCurrentCharSet(char *name, UINT size);\r
+UINT UnixCalcStrToUni(char *str);\r
+UINT UnixStrToUni(wchar_t *s, UINT size, char *str);\r
+UINT UnixCalcUniToStr(wchar_t *s);\r
+UINT UnixUniToStr(char *str, UINT size, wchar_t *s);\r
+void *IconvWideToStr();\r
+void *IconvStrToWide();\r
+int IconvFree(void *d);\r
+void *IconvWideToStrInternal();\r
+void *IconvStrToWideInternal();\r
+int IconvFreeInternal(void *d);\r
+#endif // OS_UNIX\r
+\r
+#endif // INTERNAT_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Kernel.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Kernel.c
new file mode 100644 (file)
index 0000000..c7ccd16
--- /dev/null
@@ -0,0 +1,1903 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Kernel.c\r
+// システムサービス処理ルーチン\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+#ifndef TM_YEAR_MAX\r
+#define TM_YEAR_MAX         2106\r
+#endif\r
+#ifndef TM_MON_MAX\r
+#define TM_MON_MAX          1\r
+#endif\r
+#ifndef TM_MDAY_MAX\r
+#define TM_MDAY_MAX         7\r
+#endif\r
+#ifndef TM_HOUR_MAX\r
+#define TM_HOUR_MAX         6\r
+#endif\r
+#ifndef TM_MIN_MAX\r
+#define TM_MIN_MAX          28\r
+#endif\r
+#ifndef TM_SEC_MAX\r
+#define TM_SEC_MAX          14\r
+#endif\r
+\r
+/* free mktime function\r
+   Copyright 1988, 1989 by David MacKenzie <djm@ai.mit.edu>\r
+   and Michael Haertel <mike@ai.mit.edu>\r
+   Unlimited distribution permitted provided this copyright notice is\r
+   retained and any functional modifications are prominently identified.  */\r
+#define ADJUST_TM(tm_member, tm_carry, modulus) \\r
+       if ((tm_member) < 0){ \\r
+               tm_carry -= (1 - ((tm_member)+1) / (modulus)); \\r
+               tm_member = (modulus-1) + (((tm_member)+1) % (modulus)); \\r
+       } else if ((tm_member) >= (modulus)) { \\r
+               tm_carry += (tm_member) / (modulus); \\r
+               tm_member = (tm_member) % (modulus); \\r
+       }\r
+#define leap(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)\r
+#define nleap(y) (((y) - 1969) / 4 - ((y) - 1901) / 100 + ((y) - 1601) / 400)\r
+#define leapday(m, y) ((m) == 1 && leap (y))\r
+#define monthlen(m, y) (ydays[(m)+1] - ydays[m] + leapday (m, y))\r
+static int ydays[] =\r
+{\r
+       0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365\r
+};\r
+\r
+\r
+static wchar_t *default_locale_str =\r
+L"- - $ : : $ Sun Mon Tue Wed Thu Fri Sat : : : $ (None)";\r
+\r
+static LOCALE current_locale;\r
+LOCK *tick_manual_lock = NULL;\r
+UINT g_zero = 0;\r
+\r
+// リアルタイムシステムタイマの取得\r
+UINT TickRealtime()\r
+{\r
+#if    defined(OS_WIN32) || defined(CLOCK_REALTIME) || defined(CLOCK_MONOTONIC) || defined(CLOCK_HIGHRES)\r
+       return Tick() + 1;\r
+#else\r
+       return TickRealtimeManual() + 1;\r
+#endif\r
+}\r
+\r
+#ifndef        OS_WIN32\r
+\r
+static UINT64 last_manual_tick = 0;\r
+static UINT64 manual_tick_add_value = 0;\r
+\r
+// clock_gettime が無いシステム向け (MacOS X など)\r
+UINT TickRealtimeManual()\r
+{\r
+       UINT64 ret;\r
+       Lock(tick_manual_lock);\r
+       {\r
+               ret = TickGetRealtimeTickValue64();\r
+\r
+               if (last_manual_tick != 0 && (last_manual_tick > ret))\r
+               {\r
+                       manual_tick_add_value += (last_manual_tick - ret);\r
+               }\r
+\r
+               last_manual_tick = ret;\r
+       }\r
+       Unlock(tick_manual_lock);\r
+\r
+       return (UINT)(ret + manual_tick_add_value);\r
+}\r
+\r
+// 現在時刻から適当な値を返す\r
+UINT64 TickGetRealtimeTickValue64()\r
+{\r
+       struct timeval tv;\r
+       struct timezone tz;\r
+       UINT64 ret;\r
+\r
+       memset(&tv, 0, sizeof(tv));\r
+       memset(&tz, 0, sizeof(tz));\r
+\r
+       gettimeofday(&tv, &tz);\r
+\r
+       ret = (UINT64)tv.tv_sec * 1000ULL + (UINT64)tv.tv_usec / 1000ULL;\r
+\r
+       return ret;\r
+}\r
+\r
+#endif // OS_WIN32\r
+\r
+// ホームディレクトリを取得\r
+void GetHomeDirW(wchar_t *path, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (GetEnvW(L"HOME", path, size) == false)\r
+       {\r
+               wchar_t drive[MAX_SIZE];\r
+               wchar_t hpath[MAX_SIZE];\r
+               if (GetEnvW(L"HOMEDRIVE", drive, sizeof(drive)) &&\r
+                       GetEnvW(L"HOMEPATH", hpath, sizeof(hpath)))\r
+               {\r
+                       UniFormat(path, sizeof(path), L"%s%s", drive, hpath);\r
+               }\r
+               else\r
+               {\r
+#ifdef OS_WIN32\r
+                       Win32GetCurrentDirW(path, size);\r
+#else  // OS_WIN32\r
+                       UnixGetCurrentDirW(path, size);\r
+#endif // OS_WIN32\r
+               }\r
+       }\r
+}\r
+void GetHomeDir(char *path, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (GetEnv("HOME", path, size) == false)\r
+       {\r
+               char drive[MAX_SIZE];\r
+               char hpath[MAX_SIZE];\r
+               if (GetEnv("HOMEDRIVE", drive, sizeof(drive)) &&\r
+                       GetEnv("HOMEPATH", hpath, sizeof(hpath)))\r
+               {\r
+                       Format(path, sizeof(path), "%s%s", drive, hpath);\r
+               }\r
+               else\r
+               {\r
+#ifdef OS_WIN32\r
+                       Win32GetCurrentDir(path, size);\r
+#else  // OS_WIN32\r
+                       UnixGetCurrentDir(path, size);\r
+#endif // OS_WIN32\r
+               }\r
+       }\r
+}\r
+\r
+// 環境変数文字列を取得\r
+bool GetEnv(char *name, char *data, UINT size)\r
+{\r
+       char *ret;\r
+       // 引数チェック\r
+       if (name == NULL || data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(data, size, "");\r
+\r
+       ret = getenv(name);\r
+       if (ret == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(data, size, ret);\r
+\r
+       return true;\r
+}\r
+bool GetEnvW(wchar_t *name, wchar_t *data, UINT size)\r
+{\r
+#ifdef OS_WIN32\r
+       return GetEnvW_ForWin32(name, data, size);\r
+#else  // OS_WIN32\r
+       return GetEnvW_ForUnix(name, data, size);\r
+#endif // OS_WIN32\r
+}\r
+\r
+#ifdef OS_WIN32\r
+bool GetEnvW_ForWin32(wchar_t *name, wchar_t *data, UINT size)\r
+{\r
+       wchar_t *ret;\r
+       // 引数チェック\r
+       if (name == NULL || data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               bool ret;\r
+               char *name_a = CopyUniToStr(name);\r
+               char data_a[MAX_SIZE];\r
+\r
+               ret = GetEnv(name_a, data_a, sizeof(data_a));\r
+\r
+               if (ret)\r
+               {\r
+                       StrToUni(data, size, data_a);\r
+               }\r
+\r
+               Free(name_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       UniStrCpy(data, size, L"");\r
+\r
+       ret = _wgetenv(name);\r
+       if (ret == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniStrCpy(data, size, ret);\r
+\r
+       return true;\r
+}\r
+\r
+#endif // OS_WIN32\r
+\r
+#ifdef OS_UNIX\r
+\r
+bool GetEnvW_ForUnix(wchar_t *name, wchar_t *data, UINT size)\r
+{\r
+       char *name_a;\r
+       bool ret;\r
+       char data_a[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL || data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       name_a = CopyUniToUtf(name);\r
+\r
+       ret = GetEnv(name_a, data_a, sizeof(data_a));\r
+\r
+       if (ret)\r
+       {\r
+               UtfToUni(data, size, data_a);\r
+       }\r
+\r
+       Free(name_a);\r
+\r
+       return ret;\r
+}\r
+\r
+#endif // OS_UNIX\r
+\r
+// メモリ情報取得\r
+void GetMemInfo(MEMINFO *info)\r
+{\r
+       OSGetMemInfo(info);\r
+}\r
+\r
+// シングルインスタンスの開始\r
+INSTANCE *NewSingleInstance(char *instance_name)\r
+{\r
+       return NewSingleInstanceEx(instance_name, false);\r
+}\r
+INSTANCE *NewSingleInstanceEx(char *instance_name, bool user_local)\r
+{\r
+       char name[MAX_SIZE];\r
+       INSTANCE *ret;\r
+       void *data;\r
+\r
+       if (instance_name != NULL)\r
+       {\r
+               if (user_local == false)\r
+               {\r
+                       HashInstanceName(name, sizeof(name), instance_name);\r
+               }\r
+               else\r
+               {\r
+                       HashInstanceNameLocal(name, sizeof(name), instance_name);\r
+               }\r
+\r
+               data = OSNewSingleInstance(name);\r
+       }\r
+       else\r
+       {\r
+               data = OSNewSingleInstance(NULL);\r
+       }\r
+\r
+       if (data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(INSTANCE));\r
+       if (instance_name != NULL)\r
+       {\r
+               ret->Name = CopyStr(instance_name);\r
+       }\r
+\r
+       ret->pData = data;\r
+\r
+       return ret;\r
+}\r
+\r
+// シングルインスタンスの解放\r
+void FreeSingleInstance(INSTANCE *inst)\r
+{\r
+       // 引数チェック\r
+       if (inst == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       OSFreeSingleInstance(inst->pData);\r
+\r
+       if (inst->Name != NULL)\r
+       {\r
+               Free(inst->Name);\r
+       }\r
+       Free(inst);\r
+}\r
+\r
+// インスタンス名をハッシュする\r
+void HashInstanceName(char *name, UINT size, char *instance_name)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UCHAR hash[SHA1_SIZE];\r
+       char key[11];\r
+       // 引数チェック\r
+       if (name == NULL || instance_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), instance_name);\r
+       Trim(tmp);\r
+       StrUpper(tmp);\r
+\r
+       Hash(hash, tmp, StrLen(tmp), SHA1_SIZE);\r
+       BinToStr(key, sizeof(key), hash, 5);\r
+       key[10] = 0;\r
+\r
+       Format(name, size, "VPN-%s", key);\r
+\r
+       if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType))\r
+       {\r
+               if (GET_KETA(GetOsInfo()->OsType, 100) >= 2 ||\r
+                       GetOsInfo()->OsType == OSTYPE_WINDOWS_NT_4_TERMINAL_SERVER)\r
+               {\r
+                       StrCpy(tmp, sizeof(tmp), name);\r
+                       Format(name, size, "Global\\%s", tmp);\r
+               }\r
+       }\r
+}\r
+void HashInstanceNameLocal(char *name, UINT size, char *instance_name)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UCHAR hash[SHA1_SIZE];\r
+       char key[11];\r
+       // 引数チェック\r
+       if (name == NULL || instance_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), instance_name);\r
+       Trim(tmp);\r
+       StrUpper(tmp);\r
+\r
+       Hash(hash, tmp, StrLen(tmp), SHA1_SIZE);\r
+       BinToStr(key, sizeof(key), hash, 5);\r
+       key[10] = 0;\r
+\r
+       Format(name, size, "VPN-%s", key);\r
+\r
+       if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType))\r
+       {\r
+               if (GET_KETA(GetOsInfo()->OsType, 100) >= 2 ||\r
+                       GetOsInfo()->OsType == OSTYPE_WINDOWS_NT_4_TERMINAL_SERVER)\r
+               {\r
+                       StrCpy(tmp, sizeof(tmp), name);\r
+                       Format(name, size, "Local\\%s", tmp);\r
+               }\r
+       }\r
+}\r
+\r
+// プロセスの起動\r
+bool Run(char *filename, char *arg, bool hide, bool wait)\r
+{\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return OSRun(filename, arg, hide, wait);\r
+}\r
+bool RunW(wchar_t *filename, wchar_t *arg, bool hide, bool wait)\r
+{\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return OSRunW(filename, arg, hide, wait);\r
+}\r
+\r
+// 日付・時刻関係の関数\r
+void GetDateTimeStr64Uni(wchar_t *str, UINT size, UINT64 sec64)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetDateTimeStr64(tmp, sizeof(tmp), sec64);\r
+       StrToUni(str, size, tmp);\r
+}\r
+void GetDateTimeStr64(char *str, UINT size, UINT64 sec64)\r
+{\r
+       SYSTEMTIME st;\r
+       UINT64ToSystem(&st, sec64);\r
+       GetDateTimeStr(str, size, &st);\r
+}\r
+void GetDateTimeStrMilli64(char *str, UINT size, UINT64 sec64)\r
+{\r
+       SYSTEMTIME st;\r
+       UINT64ToSystem(&st, sec64);\r
+       GetDateTimeStrMilli(str, size, &st);\r
+}\r
+void GetDateStr64(char *str, UINT size, UINT64 sec64)\r
+{\r
+       SYSTEMTIME st;\r
+       if (sec64 == 0)\r
+       {\r
+               StrCpy(str, size, "(Unknown)");\r
+               return;\r
+       }\r
+       UINT64ToSystem(&st, sec64);\r
+       GetDateStr(str, size, &st);\r
+}\r
+void GetDateTimeStrEx64(wchar_t *str, UINT size, UINT64 sec64, LOCALE *locale)\r
+{\r
+       SYSTEMTIME st;\r
+       if (locale == NULL)\r
+       {\r
+               locale = &current_locale;\r
+       }\r
+       if (sec64 == 0 || SystemToLocal64(sec64) == 0 || LocalToSystem64(sec64) == 0)\r
+       {\r
+               UniStrCpy(str, size, locale->Unknown);\r
+               return;\r
+       }\r
+       UINT64ToSystem(&st, sec64);\r
+       GetDateTimeStrEx(str, size, &st, locale);\r
+}\r
+void GetTimeStrEx64(wchar_t *str, UINT size, UINT64 sec64, LOCALE *locale)\r
+{\r
+       SYSTEMTIME st;\r
+       if (locale == NULL)\r
+       {\r
+               locale = &current_locale;\r
+       }\r
+       if (sec64 == 0 || SystemToLocal64(sec64) == 0 || LocalToSystem64(sec64) == 0)\r
+       {\r
+               UniStrCpy(str, size, locale->Unknown);\r
+               return;\r
+       }\r
+       UINT64ToSystem(&st, sec64);\r
+       GetTimeStrEx(str, size, &st, locale);\r
+}\r
+void GetDateStrEx64(wchar_t *str, UINT size, UINT64 sec64, LOCALE *locale)\r
+{\r
+       SYSTEMTIME st;\r
+       if (locale == NULL)\r
+       {\r
+               locale = &current_locale;\r
+       }\r
+       if (sec64 == 0 || SystemToLocal64(sec64) == 0 || LocalToSystem64(sec64) == 0)\r
+       {\r
+               UniStrCpy(str, size, locale->Unknown);\r
+               return;\r
+       }\r
+       UINT64ToSystem(&st, sec64);\r
+       GetDateStrEx(str, size, &st, locale);\r
+}\r
+void GetTimeStrMilli64(char *str, UINT size, UINT64 sec64)\r
+{\r
+       SYSTEMTIME st;\r
+       if (sec64 == 0 || SystemToLocal64(sec64) == 0 || LocalToSystem64(sec64) == 0)\r
+       {\r
+               StrCpy(str, size, "(Unknown)");\r
+               return;\r
+       }\r
+       UINT64ToSystem(&st, sec64);\r
+       GetTimeStrMilli(str, size, &st);\r
+}\r
+void GetTimeStr64(char *str, UINT size, UINT64 sec64)\r
+{\r
+       SYSTEMTIME st;\r
+       if (sec64 == 0 || SystemToLocal64(sec64) == 0 || LocalToSystem64(sec64) == 0)\r
+       {\r
+               StrCpy(str, size, "(Unknown)");\r
+               return;\r
+       }\r
+       UINT64ToSystem(&st, sec64);\r
+       GetTimeStr(str, size, &st);\r
+}\r
+\r
+// 現在の POSIX 実装で使用しても安全な時刻に変換する\r
+UINT64 SafeTime64(UINT64 sec64)\r
+{\r
+       return MAKESURE(sec64, 0, 2115947647000ULL);\r
+}\r
+\r
+// スレッドプール\r
+static SK *thread_pool = NULL;\r
+static COUNTER *thread_count = NULL;\r
+\r
+// スレッドプールの初期化\r
+void InitThreading()\r
+{\r
+       thread_pool = NewSk();\r
+       thread_count = NewCounter();\r
+}\r
+\r
+// スレッドプールの解放\r
+void FreeThreading()\r
+{\r
+       while (true)\r
+       {\r
+               if (Count(thread_count) == 0)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               SleepThread(25);\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               THREAD_POOL_DATA *pd;\r
+               THREAD *t = Pop(thread_pool);\r
+\r
+               if (t == NULL)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               pd = (THREAD_POOL_DATA *)t->param;\r
+\r
+               pd->ThreadProc = NULL;\r
+               Set(pd->Event);\r
+\r
+               WaitThreadInternal(t);\r
+\r
+               pd = (THREAD_POOL_DATA *)t->param;\r
+               ReleaseEvent(pd->Event);\r
+               ReleaseEvent(pd->InitFinishEvent);\r
+\r
+               ReleaseThreadInternal(t);\r
+\r
+               Free(pd);\r
+       }\r
+\r
+       ReleaseSk(thread_pool);\r
+\r
+       DeleteCounter(thread_count);\r
+       thread_count = NULL;\r
+}\r
+\r
+// スレッドプールプロシージャ\r
+void ThreadPoolProc(THREAD *t, void *param)\r
+{\r
+       THREAD_POOL_DATA *pd;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pd = (THREAD_POOL_DATA *)param;\r
+\r
+       NoticeThreadInitInternal(t);\r
+\r
+       while (true)\r
+       {\r
+               THREAD *thread;\r
+               UINT i, num;\r
+               EVENT **ee;\r
+\r
+               // 次の仕事を待つ\r
+               Wait(pd->Event, INFINITE);\r
+\r
+               if (pd->ThreadProc == NULL)\r
+               {\r
+                       // プールスレッドの動作停止\r
+                       break;\r
+               }\r
+\r
+               thread = pd->Thread;\r
+               thread->ThreadId = ThreadId();\r
+\r
+               // 初期化完了\r
+               Set(pd->InitFinishEvent);\r
+\r
+               // スレッドプロシージャの実行\r
+               pd->ThreadProc(pd->Thread, thread->param);\r
+\r
+               thread->PoolHalting = true;\r
+\r
+               // 待機イベントリストを叩く\r
+               LockList(thread->PoolWaitList);\r
+               {\r
+                       num = LIST_NUM(thread->PoolWaitList);\r
+                       ee = ToArray(thread->PoolWaitList);\r
+\r
+                       DeleteAll(thread->PoolWaitList);\r
+               }\r
+               UnlockList(thread->PoolWaitList);\r
+\r
+               for (i = 0;i < num;i++)\r
+               {\r
+                       EVENT *e = ee[i];\r
+\r
+                       Set(e);\r
+                       ReleaseEvent(e);\r
+               }\r
+\r
+               Free(ee);\r
+\r
+               while (true)\r
+               {\r
+                       if (Count(thread->ref->c) <= 1)\r
+                       {\r
+                               break;\r
+                       }\r
+\r
+                       Wait(thread->release_event, 256);\r
+               }\r
+\r
+               ReleaseThread(thread);\r
+\r
+#ifdef OS_WIN32\r
+               // Win32 の場合: スレッドの優先順位を元に戻す\r
+               MsRestoreThreadPriority();\r
+#endif // OS_WIN32\r
+\r
+               // スレッドプールに自分自身を登録する\r
+               LockSk(thread_pool);\r
+               {\r
+                       Push(thread_pool, t);\r
+               }\r
+               UnlockSk(thread_pool);\r
+\r
+               Dec(thread_count);\r
+       }\r
+}\r
+\r
+// 何もしない\r
+UINT DoNothing()\r
+{\r
+       return g_zero;\r
+}\r
+\r
+// スレッド作成 (プール)\r
+THREAD *NewThread(THREAD_PROC *thread_proc, void *param)\r
+{\r
+       THREAD *host = NULL;\r
+       THREAD_POOL_DATA *pd = NULL;\r
+       THREAD *ret;\r
+       bool new_thread = false;\r
+       // 引数チェック\r
+       if (thread_proc == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (IsTrackingEnabled() == false)\r
+       {\r
+               DoNothing();\r
+       }\r
+\r
+       Inc(thread_count);\r
+\r
+       LockSk(thread_pool);\r
+       {\r
+               // 現在プールに空いているスレッドがあるかどうか調べる\r
+               host = Pop(thread_pool);\r
+       }\r
+       UnlockSk(thread_pool);\r
+\r
+       if (host == NULL)\r
+       {\r
+               // 空いているスレッドが見つからなかったので新しいスレッドを作成する\r
+               pd = ZeroMalloc(sizeof(THREAD_POOL_DATA));\r
+               pd->Event = NewEvent();\r
+               pd->InitFinishEvent = NewEvent();\r
+               host = NewThreadInternal(ThreadPoolProc, pd);\r
+               WaitThreadInitInternal(host);\r
+\r
+               new_thread = true;\r
+       }\r
+       else\r
+       {\r
+               pd = (THREAD_POOL_DATA *)host->param;\r
+       }\r
+\r
+       // プールスレッドの作成\r
+       ret = ZeroMalloc(sizeof(THREAD));\r
+       ret->ref = NewRef();\r
+       ret->thread_proc = thread_proc;\r
+       ret->param = param;\r
+       ret->pData = NULL;\r
+       ret->init_finished_event = NewEvent();\r
+       ret->PoolThread = true;\r
+       ret->PoolWaitList = NewList(NULL);\r
+       ret->PoolHostThread = host;\r
+       ret->release_event = NewEvent();\r
+\r
+       // 実行\r
+       pd->ThreadProc = thread_proc;\r
+       pd->Thread = ret;\r
+       AddRef(ret->ref);\r
+\r
+       Set(pd->Event);\r
+\r
+       Wait(pd->InitFinishEvent, INFINITE);\r
+\r
+       return ret;\r
+}\r
+\r
+// スレッドのクリーンアップ (プール)\r
+void CleanupThread(THREAD *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ReleaseEvent(t->init_finished_event);\r
+       ReleaseEvent(t->release_event);\r
+       ReleaseList(t->PoolWaitList);\r
+\r
+       Free(t);\r
+}\r
+\r
+// スレッド解放 (プール)\r
+void ReleaseThread(THREAD *t)\r
+{\r
+       UINT ret;\r
+       EVENT *e;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       e = t->release_event;\r
+       if (e != NULL)\r
+       {\r
+               AddRef(e->ref);\r
+       }\r
+\r
+       ret = Release(t->ref);\r
+       Set(e);\r
+\r
+       ReleaseEvent(e);\r
+\r
+       if (ret == 0)\r
+       {\r
+               CleanupThread(t);\r
+       }\r
+}\r
+\r
+// スレッドの初期化完了を通知 (プール)\r
+void NoticeThreadInit(THREAD *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 通知\r
+       Set(t->init_finished_event);\r
+}\r
+\r
+// スレッドの初期化完了を待機 (プール)\r
+void WaitThreadInit(THREAD *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_WAITFORTHREAD_COUNT);\r
+\r
+       // 待機\r
+       Wait(t->init_finished_event, INFINITE);\r
+}\r
+\r
+// スレッドの終了を待機 (プール)\r
+bool WaitThread(THREAD *t, UINT timeout)\r
+{\r
+       bool ret = false;\r
+       EVENT *e = NULL;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       LockList(t->PoolWaitList);\r
+       {\r
+               if (t->PoolHalting)\r
+               {\r
+                       // 既に停止済み\r
+                       ret = true;\r
+               }\r
+               else\r
+               {\r
+                       // 終了時通知イベントをリストに登録する\r
+                       e = NewEvent();\r
+                       AddRef(e->ref);\r
+                       Insert(t->PoolWaitList, e);\r
+               }\r
+       }\r
+       UnlockList(t->PoolWaitList);\r
+\r
+       if (e != NULL)\r
+       {\r
+               // イベント待機\r
+               ret = Wait(e, timeout);\r
+\r
+               LockList(t->PoolWaitList);\r
+               {\r
+                       if (Delete(t->PoolWaitList, e))\r
+                       {\r
+                               ReleaseEvent(e);\r
+                       }\r
+               }\r
+               UnlockList(t->PoolWaitList);\r
+\r
+               ReleaseEvent(e);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// スレッド ID の取得\r
+UINT ThreadId()\r
+{\r
+       return OSThreadId();\r
+}\r
+\r
+// スレッドの作成\r
+THREAD *NewThreadInternal(THREAD_PROC *thread_proc, void *param)\r
+{\r
+       THREAD *t;\r
+       UINT retry = 0;\r
+       // 引数チェック\r
+       if (thread_proc == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // スレッドオブジェクト初期化\r
+       t = ZeroMalloc(sizeof(THREAD));\r
+       t->init_finished_event = NewEvent();\r
+\r
+       t->param = param;\r
+       t->ref = NewRef();\r
+       t->thread_proc = thread_proc;\r
+\r
+       // OS がスレッドを初期化するまで待機\r
+       while (true)\r
+       {\r
+               if ((retry++) > 60)\r
+               {\r
+                       printf("\n\n*** error: new thread create failed.\n\n");\r
+                       AbortExit();\r
+               }\r
+               if (OSInitThread(t))\r
+               {\r
+                       break;\r
+               }\r
+               SleepThread(500);\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_NEWTHREAD_COUNT);\r
+\r
+       return t;\r
+}\r
+\r
+// スレッドの解放\r
+void ReleaseThreadInternal(THREAD *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(t->ref) == 0)\r
+       {\r
+               CleanupThreadInternal(t);\r
+       }\r
+}\r
+\r
+// スレッドのクリーンアップ\r
+void CleanupThreadInternal(THREAD *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // スレッドの解放\r
+       OSFreeThread(t);\r
+\r
+       // イベント解放\r
+       ReleaseEvent(t->init_finished_event);\r
+       // メモリ解放\r
+       Free(t);\r
+\r
+       // KS\r
+       KS_INC(KS_FREETHREAD_COUNT);\r
+}\r
+\r
+// スレッドの終了を待機する\r
+bool WaitThreadInternal(THREAD *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return OSWaitThread(t);\r
+}\r
+\r
+// スレッドの初期化が完了したことを通知する\r
+void NoticeThreadInitInternal(THREAD *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 通知\r
+       Set(t->init_finished_event);\r
+}\r
+\r
+// スレッドの初期化が完了するまで待機する\r
+void WaitThreadInitInternal(THREAD *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_WAITFORTHREAD_COUNT);\r
+\r
+       // 待機\r
+       Wait(t->init_finished_event, INFINITE);\r
+}\r
+\r
+// 日時文字列をロケール情報を使用して取得\r
+void GetDateTimeStrEx(wchar_t *str, UINT size, SYSTEMTIME *st, LOCALE *locale)\r
+{\r
+       wchar_t tmp1[MAX_SIZE];\r
+       wchar_t tmp2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (str == NULL || st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetDateStrEx(tmp1, sizeof(tmp1), st, locale);\r
+       GetTimeStrEx(tmp2, sizeof(tmp2), st, locale);\r
+       UniFormat(str, size, L"%s %s", tmp1, tmp2);\r
+}\r
+\r
+// 時刻文字列をロケール情報を使用して取得\r
+void GetTimeStrEx(wchar_t *str, UINT size, SYSTEMTIME *st, LOCALE *locale)\r
+{\r
+       wchar_t *tag = L"%02u%s%02u%s%02u%s";\r
+       // 引数チェック\r
+       if (str == NULL || st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (_GETLANG() == SE_LANG_JAPANESE || _GETLANG() == SE_LANG_CHINESE_ZH)\r
+       {\r
+               tag = L"%2u%s%2u%s%2u%s";\r
+       }\r
+\r
+       locale = (locale != NULL ? locale : &current_locale);\r
+       UniFormat(str, size,\r
+               tag,\r
+               st->wHour, locale->HourStr,\r
+               st->wMinute, locale->MinuteStr,\r
+               st->wSecond, locale->SecondStr);\r
+}\r
+\r
+// 日付文字列をロケール情報を使用して取得\r
+void GetDateStrEx(wchar_t *str, UINT size, SYSTEMTIME *st, LOCALE *locale)\r
+{\r
+       wchar_t *tag = L"%04u%s%02u%s%02u%s (%s)";\r
+       // 引数チェック\r
+       if (str == NULL || st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (_GETLANG() == SE_LANG_JAPANESE || _GETLANG() == SE_LANG_CHINESE_ZH)\r
+       {\r
+               tag = L"%4u%s%2u%s%2u%s(%s)";\r
+       }\r
+\r
+       locale = (locale != NULL ? locale : &current_locale);\r
+       UniFormat(str, size,\r
+               tag,\r
+               st->wYear, locale->YearStr,\r
+               st->wMonth, locale->MonthStr,\r
+               st->wDay, locale->DayStr,\r
+               locale->DayOfWeek[st->wDayOfWeek]);\r
+}\r
+\r
+// 時刻文字列をミリ秒単位で取得 (例: 12:34:56.789)\r
+void GetTimeStrMilli(char *str, UINT size, SYSTEMTIME *st)\r
+{\r
+       // 引数チェック\r
+       if (st == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(str, size, "%02u:%02u:%02u.%03u",\r
+               st->wHour, st->wMinute, st->wSecond, st->wMilliseconds);\r
+}\r
+\r
+// 時刻文字列を取得 (例: 12:34:56)\r
+void GetTimeStr(char *str, UINT size, SYSTEMTIME *st)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(str, size, "%02u:%02u:%02u",\r
+               st->wHour, st->wMinute, st->wSecond);\r
+}\r
+\r
+// 日付文字列を取得 (例: 2004/07/23)\r
+void GetDateStr(char *str, UINT size, SYSTEMTIME *st)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(str, size, "%04u-%02u-%02u",\r
+               st->wYear, st->wMonth, st->wDay);\r
+}\r
+\r
+// 日時文字列を取得 (例: 2004/07/23 12:34:56)\r
+void GetDateTimeStr(char *str, UINT size, SYSTEMTIME *st)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(str, size, "%04u-%02u-%02u %02u:%02u:%02u",\r
+               st->wYear, st->wMonth, st->wDay,\r
+               st->wHour, st->wMinute, st->wSecond);\r
+}\r
+\r
+// 日時文字列をミリ秒単位で取得 (例: 2004/07/23 12:34:56.789)\r
+void GetDateTimeStrMilli(char *str, UINT size, SYSTEMTIME *st)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(str, size, "%04u-%02u-%02u %02u:%02u:%02u.%03u",\r
+               st->wYear, st->wMonth, st->wDay,\r
+               st->wHour, st->wMinute, st->wSecond,\r
+               st->wMilliseconds);\r
+}\r
+\r
+// 時間文字列の取得\r
+void GetSpanStr(char *str, UINT size, UINT64 sec64)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), "");\r
+       if (sec64 >= (UINT64)(1000 * 3600 * 24))\r
+       {\r
+               Format(tmp, sizeof(tmp), "%u:", (UINT)(sec64 / (UINT64)(1000 * 3600 * 24)));\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), "%s%02u:%02u:%02u", tmp,\r
+               (UINT)(sec64 % (UINT64)(1000 * 60 * 60 * 24)) / (1000 * 60 * 60),\r
+               (UINT)(sec64 % (UINT64)(1000 * 60 * 60)) / (1000 * 60),\r
+               (UINT)(sec64 % (UINT64)(1000 * 60)) / 1000);\r
+\r
+       Trim(tmp);\r
+       StrCpy(str, size, tmp);\r
+}\r
+\r
+// 時間文字列の取得 (ミリ秒単位)\r
+void GetSpanStrMilli(char *str, UINT size, UINT64 sec64)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), "");\r
+       if (sec64 >= (UINT64)(1000 * 3600 * 24))\r
+       {\r
+               Format(tmp, sizeof(tmp), "%u:", (UINT)(sec64 / (UINT64)(1000 * 3600 * 24)));\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), "%s%02u:%02u:%02u.%03u", tmp,\r
+               (UINT)(sec64 % (UINT64)(1000 * 60 * 60 * 24)) / (1000 * 60 * 60),\r
+               (UINT)(sec64 % (UINT64)(1000 * 60 * 60)) / (1000 * 60),\r
+               (UINT)(sec64 % (UINT64)(1000 * 60)) / 1000,\r
+               (UINT)(sec64 % (UINT64)(1000)));\r
+\r
+       Trim(tmp);\r
+       StrCpy(str, size, tmp);\r
+}\r
+\r
+// 時間文字列の取得 (拡張)\r
+void GetSpanStrEx(wchar_t *str, UINT size, UINT64 sec64, LOCALE *locale)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       locale = (locale != NULL ? locale : &current_locale);\r
+\r
+       UniStrCpy(tmp, sizeof(tmp), L"");\r
+       if (sec64 >= (UINT64)(1000 * 3600 * 24))\r
+       {\r
+               UniFormat(tmp, sizeof(tmp), L"%u%s ", (UINT)(sec64 / (UINT64)(1000 * 3600 * 24)),\r
+                       locale->SpanDay);\r
+       }\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"%s%u%s %02u%s %02u%s", tmp,\r
+               (UINT)(sec64 % (UINT64)(1000 * 60 * 60 * 24)) / (1000 * 60 * 60),\r
+               locale->SpanHour,\r
+               (UINT)(sec64 % (UINT64)(1000 * 60 * 60)) / (1000 * 60),\r
+               locale->SpanMinute,\r
+               (UINT)(sec64 % (UINT64)(1000 * 60)) / 1000,\r
+               locale->SpanSecond);\r
+\r
+       UniTrim(tmp);\r
+       UniStrCpy(str, size, tmp);\r
+}\r
+\r
+// 現在のロケール情報を取得\r
+void GetCurrentLocale(LOCALE *locale)\r
+{\r
+       // 引数チェック\r
+       if (locale == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Copy(locale, &current_locale, sizeof(LOCALE));\r
+}\r
+\r
+// ロケール情報を設定\r
+void SetLocale(wchar_t *str)\r
+{\r
+       wchar_t *set_locale_str;\r
+       LOCALE tmp;\r
+\r
+       if (str != NULL)\r
+       {\r
+               set_locale_str = str;\r
+       }\r
+       else\r
+       {\r
+               set_locale_str = default_locale_str;\r
+       }\r
+\r
+       if (LoadLocale(&tmp, set_locale_str) == false)\r
+       {\r
+               if (LoadLocale(&tmp, default_locale_str) == false)\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+\r
+       Copy(&current_locale, &tmp, sizeof(LOCALE));\r
+}\r
+\r
+#define        COPY_LOCALE_STR(dest, size, src)        UniStrCpy(dest, size, UniStrCmp(src, L"$") == 0 ? L"" : src)\r
+\r
+// ロケール情報の読み込み\r
+bool LoadLocale(LOCALE *locale, wchar_t *str)\r
+{\r
+       UNI_TOKEN_LIST *tokens;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (locale == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // トークンの解析\r
+       tokens = UniParseToken(str, L" ");\r
+       if (tokens->NumTokens != 18)\r
+       {\r
+               UniFreeToken(tokens);\r
+               return false;\r
+       }\r
+\r
+       // 構造体にセット\r
+       Zero(locale, sizeof(LOCALE));\r
+       COPY_LOCALE_STR(locale->YearStr, sizeof(locale->YearStr), tokens->Token[0]);\r
+       COPY_LOCALE_STR(locale->MonthStr, sizeof(locale->MonthStr), tokens->Token[1]);\r
+       COPY_LOCALE_STR(locale->DayStr, sizeof(locale->DayStr), tokens->Token[2]);\r
+       COPY_LOCALE_STR(locale->HourStr, sizeof(locale->HourStr), tokens->Token[3]);\r
+       COPY_LOCALE_STR(locale->MinuteStr, sizeof(locale->MinuteStr), tokens->Token[4]);\r
+       COPY_LOCALE_STR(locale->SecondStr, sizeof(locale->SecondStr), tokens->Token[5]);\r
+\r
+       for (i = 0;i < 7;i++)\r
+       {\r
+               COPY_LOCALE_STR(locale->DayOfWeek[i], sizeof(locale->DayOfWeek[i]),\r
+                       tokens->Token[6 + i]);\r
+       }\r
+\r
+       COPY_LOCALE_STR(locale->SpanDay, sizeof(locale->SpanDay), tokens->Token[13]);\r
+       COPY_LOCALE_STR(locale->SpanHour, sizeof(locale->SpanHour), tokens->Token[14]);\r
+       COPY_LOCALE_STR(locale->SpanMinute, sizeof(locale->SpanMinute), tokens->Token[15]);\r
+       COPY_LOCALE_STR(locale->SpanSecond, sizeof(locale->SpanSecond), tokens->Token[16]);\r
+\r
+       COPY_LOCALE_STR(locale->Unknown, sizeof(locale->Unknown), tokens->Token[17]);\r
+\r
+       UniFreeToken(tokens);\r
+       return true;\r
+}\r
+\r
+// tm を SYSTEMTIME に変換\r
+void TmToSystem(SYSTEMTIME *st, struct tm *t)\r
+{\r
+       struct tm tmp;\r
+       // 引数チェック\r
+       if (st == NULL || t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Copy(&tmp, t, sizeof(struct tm));\r
+       NormalizeTm(&tmp);\r
+\r
+       Zero(st, sizeof(SYSTEMTIME));\r
+       st->wYear = MAKESURE(tmp.tm_year + 1900, 1970, 2037);\r
+       st->wMonth = MAKESURE(tmp.tm_mon + 1, 1, 12);\r
+       st->wDay = MAKESURE(tmp.tm_mday, 1, 31);\r
+       st->wDayOfWeek = MAKESURE(tmp.tm_wday, 0, 6);\r
+       st->wHour = MAKESURE(tmp.tm_hour, 0, 23);\r
+       st->wMinute = MAKESURE(tmp.tm_min, 0, 59);\r
+       st->wSecond = MAKESURE(tmp.tm_sec, 0, 59);\r
+       st->wMilliseconds = 0;\r
+}\r
+\r
+// SYSTEMTIME を tm に変換\r
+void SystemToTm(struct tm *t, SYSTEMTIME *st)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL || st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(t, sizeof(struct tm));\r
+       t->tm_year = MAKESURE(st->wYear, 1970, 2037) - 1900;\r
+       t->tm_mon = MAKESURE(st->wMonth, 1, 12) - 1;\r
+       t->tm_mday = MAKESURE(st->wDay, 1, 31);\r
+       t->tm_hour = MAKESURE(st->wHour, 0, 23);\r
+       t->tm_min = MAKESURE(st->wMinute, 0, 59);\r
+       t->tm_sec = MAKESURE(st->wSecond, 0, 59);\r
+\r
+       t->tm_isdst = -1;\r
+       NormalizeTm(t);\r
+}\r
+\r
+// time_t を SYSTEMTIME に変換\r
+void TimeToSystem(SYSTEMTIME *st, time_t t)\r
+{\r
+       struct tm tmp;\r
+       // 引数チェック\r
+       if (st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       TimeToTm(&tmp, t);\r
+       TmToSystem(st, &tmp);\r
+}\r
+\r
+// SYSTEMTIME を time_t に変換\r
+time_t SystemToTime(SYSTEMTIME *st)\r
+{\r
+       struct tm t;\r
+       // 引数チェック\r
+       if (st == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       SystemToTm(&t, st);\r
+       return TmToTime(&t);\r
+}\r
+\r
+// tm を time_t に変換\r
+time_t TmToTime(struct tm *t)\r
+{\r
+       time_t tmp;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       tmp = c_mkgmtime(t);\r
+       if (tmp == (time_t)-1)\r
+       {\r
+               return 0;\r
+       }\r
+       return tmp;\r
+}\r
+\r
+// time_t を tm に変換\r
+void TimeToTm(struct tm *t, time_t time)\r
+{\r
+       struct tm *ret;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifndef        OS_UNIX\r
+       ret = gmtime(&time);\r
+#else  // OS_UNIX\r
+       ret = malloc(sizeof(struct tm));\r
+       memset(ret, 0, sizeof(ret));\r
+       gmtime_r(&time, ret);\r
+#endif // OS_UNIX\r
+\r
+       if (ret == NULL)\r
+       {\r
+               Zero(t, sizeof(struct tm));\r
+       }\r
+       else\r
+       {\r
+               Copy(t, ret, sizeof(struct tm));\r
+       }\r
+\r
+#ifdef OS_UNIX\r
+       free(ret);\r
+#endif // OS_UNIX\r
+}\r
+\r
+// tm を正規化\r
+void NormalizeTm(struct tm *t)\r
+{\r
+       struct tm *ret;\r
+       time_t tmp;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tmp = c_mkgmtime(t);\r
+       if (tmp == (time_t)-1)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifndef        OS_UNIX\r
+       ret = gmtime(&tmp);\r
+#else  // OS_UNIX\r
+       ret = malloc(sizeof(struct tm));\r
+       memset(ret, 0, sizeof(ret));\r
+       gmtime_r(&tmp, ret);\r
+#endif // OS_UNIX\r
+\r
+       if (ret == NULL)\r
+       {\r
+               Zero(t, sizeof(struct tm));\r
+       }\r
+       else\r
+       {\r
+               Copy(t, ret, sizeof(struct tm));\r
+       }\r
+\r
+#ifdef OS_UNIX\r
+       free(ret);\r
+#endif // OS_UNIX\r
+}\r
+\r
+// SYSTEMTIME を正規化\r
+void NormalizeSystem(SYSTEMTIME *st)\r
+{\r
+       UINT64 sec64;\r
+       // 引数チェック\r
+       if (st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       sec64 = SystemToUINT64(st);\r
+       UINT64ToSystem(st, sec64);\r
+}\r
+\r
+// 64bit ローカル時刻をシステム時刻に変換\r
+UINT64 LocalToSystem64(UINT64 t)\r
+{\r
+       SYSTEMTIME st;\r
+       UINT64ToSystem(&st, t);\r
+       LocalToSystem(&st, &st);\r
+       return SystemToUINT64(&st);\r
+}\r
+\r
+// 64bit システム時刻をローカル時刻に変換\r
+UINT64 SystemToLocal64(UINT64 t)\r
+{\r
+       SYSTEMTIME st;\r
+       UINT64ToSystem(&st, t);\r
+       SystemToLocal(&st, &st);\r
+       return SystemToUINT64(&st);\r
+}\r
+\r
+// ローカル時刻をシステム時刻に変換\r
+void LocalToSystem(SYSTEMTIME *system, SYSTEMTIME *local)\r
+{\r
+       UINT64 sec64;\r
+       // 引数チェック\r
+       if (local == NULL || system == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       sec64 = (UINT64)((INT64)SystemToUINT64(local) - GetTimeDiffEx(local, true));\r
+       UINT64ToSystem(system, sec64);\r
+}\r
+\r
+// システム時刻をローカル時刻に変換\r
+void SystemToLocal(SYSTEMTIME *local, SYSTEMTIME *system)\r
+{\r
+       UINT64 sec64;\r
+       // 引数チェック\r
+       if (local == NULL || system == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       sec64 = (UINT64)((INT64)SystemToUINT64(system) + GetTimeDiffEx(system, false));\r
+       UINT64ToSystem(local, sec64);\r
+}\r
+\r
+// 指定時刻をベースにしてシステム時刻とローカル時刻との間の時差を取得\r
+INT64 GetTimeDiffEx(SYSTEMTIME *basetime, bool local_time)\r
+{\r
+       time_t tmp;\r
+       struct tm t1, t2;\r
+       SYSTEMTIME snow;\r
+       struct tm now;\r
+       SYSTEMTIME s1, s2;\r
+       INT64 ret;\r
+\r
+       Copy(&snow, basetime, sizeof(SYSTEMTIME));\r
+\r
+       SystemToTm(&now, &snow);\r
+       if (local_time == false)\r
+       {\r
+               tmp = c_mkgmtime(&now);\r
+       }\r
+       else\r
+       {\r
+               tmp = mktime(&now);\r
+       }\r
+\r
+       if (tmp == (time_t)-1)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Copy(&t1, localtime(&tmp), sizeof(struct tm));\r
+       Copy(&t2, gmtime(&tmp), sizeof(struct tm));\r
+       TmToSystem(&s1, &t1);\r
+       TmToSystem(&s2, &t2);\r
+\r
+       ret = (INT)SystemToUINT64(&s1) - (INT)SystemToUINT64(&s2);\r
+\r
+       return ret;\r
+}\r
+\r
+// システム時刻とローカル時刻との間の時差を取得\r
+INT64 GetTimeDiff()\r
+{\r
+       time_t tmp;\r
+       struct tm t1, t2;\r
+       SYSTEMTIME snow;\r
+       struct tm now;\r
+       SYSTEMTIME s1, s2;\r
+       INT64 ret;\r
+\r
+       static INT64 cache = INFINITE;\r
+\r
+       if (cache != INFINITE)\r
+       {\r
+               // 1 度測定したらキャッシュデータを返す\r
+               return cache;\r
+       }\r
+\r
+       SystemTime(&snow);\r
+       SystemToTm(&now, &snow);\r
+       tmp = c_mkgmtime(&now);\r
+       if (tmp == (time_t)-1)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Copy(&t1, localtime(&tmp), sizeof(struct tm));\r
+       Copy(&t2, gmtime(&tmp), sizeof(struct tm));\r
+       TmToSystem(&s1, &t1);\r
+       TmToSystem(&s2, &t2);\r
+\r
+       cache = ret = (INT)SystemToUINT64(&s1) - (INT)SystemToUINT64(&s2);\r
+\r
+       return ret;\r
+}\r
+\r
+// UINT64 を SYSTEMTIME に変換\r
+void UINT64ToSystem(SYSTEMTIME *st, UINT64 sec64)\r
+{\r
+       UINT64 tmp64;\r
+       UINT sec, millisec;\r
+       time_t time;\r
+       // 引数チェック\r
+       if (st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       sec64 = SafeTime64(sec64 + 32400000ULL);\r
+       tmp64 = sec64 / (UINT64)1000;\r
+       millisec = (UINT)(sec64 - tmp64 * (UINT64)1000);\r
+       sec = (UINT)tmp64;\r
+       time = (time_t)sec;\r
+       TimeToSystem(st, time);\r
+       st->wMilliseconds = (WORD)millisec;\r
+}\r
+\r
+// SYSTEMTIME を UINT64 に変換\r
+UINT64 SystemToUINT64(SYSTEMTIME *st)\r
+{\r
+       UINT64 sec64;\r
+       time_t time;\r
+       // 引数チェック\r
+       if (st == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       time = SystemToTime(st);\r
+       sec64 = (UINT64)time * (UINT64)1000;\r
+       sec64 += st->wMilliseconds;\r
+\r
+       return sec64 - 32400000ULL;\r
+}\r
+\r
+// ローカル時刻を UINT64 で取得\r
+UINT64 LocalTime64()\r
+{\r
+       SYSTEMTIME s;\r
+       LocalTime(&s);\r
+       return SystemToUINT64(&s);\r
+}\r
+\r
+// システム時刻を UINT64 で取得\r
+UINT64 SystemTime64()\r
+{\r
+       SYSTEMTIME s;\r
+       SystemTime(&s);\r
+       return SystemToUINT64(&s);\r
+}\r
+\r
+// ローカル時刻の取得\r
+void LocalTime(SYSTEMTIME *st)\r
+{\r
+       SYSTEMTIME tmp;\r
+       // 引数チェック\r
+       if (st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SystemTime(&tmp);\r
+       SystemToLocal(st, &tmp);\r
+}\r
+\r
+// システム時刻の取得\r
+void SystemTime(SYSTEMTIME *st)\r
+{\r
+       // 引数チェック\r
+       if (st == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       OSGetSystemTime(st);\r
+\r
+       // KS\r
+       KS_INC(KS_GETTIME_COUNT);\r
+}\r
+\r
+/* free mktime function\r
+   Copyright 1988, 1989 by David MacKenzie <djm@ai.mit.edu>\r
+   and Michael Haertel <mike@ai.mit.edu>\r
+   Unlimited distribution permitted provided this copyright notice is\r
+   retained and any functional modifications are prominently identified.  */\r
+time_t c_mkgmtime(struct tm *tm)\r
+{\r
+       int years, months, days, hours, minutes, seconds;\r
+\r
+       years = tm->tm_year + 1900;   /* year - 1900 -> year */\r
+       months = tm->tm_mon;          /* 0..11 */\r
+       days = tm->tm_mday - 1;       /* 1..31 -> 0..30 */\r
+       hours = tm->tm_hour;          /* 0..23 */\r
+       minutes = tm->tm_min;         /* 0..59 */\r
+       seconds = tm->tm_sec;         /* 0..61 in ANSI C. */\r
+\r
+       ADJUST_TM(seconds, minutes, 60);\r
+       ADJUST_TM(minutes, hours, 60);\r
+       ADJUST_TM(hours, days, 24);\r
+       ADJUST_TM(months, years, 12);\r
+       if (days < 0)\r
+               do {\r
+                       if (--months < 0) {\r
+                               --years;\r
+                               months = 11;\r
+                       }\r
+                       days += monthlen(months, years);\r
+               } while (days < 0);\r
+       else\r
+               while (days >= monthlen(months, years)) {\r
+                       days -= monthlen(months, years);\r
+                       if (++months >= 12) {\r
+                               ++years;\r
+                               months = 0;\r
+                       }\r
+               }\r
+\r
+               /* Restore adjusted values in tm structure */\r
+               tm->tm_year = years - 1900;\r
+               tm->tm_mon = months;\r
+               tm->tm_mday = days + 1;\r
+               tm->tm_hour = hours;\r
+               tm->tm_min = minutes;\r
+               tm->tm_sec = seconds;\r
+\r
+               /* Set `days' to the number of days into the year. */\r
+               days += ydays[months] + (months > 1 && leap (years));\r
+               tm->tm_yday = days;\r
+\r
+               /* Now calculate `days' to the number of days since Jan 1, 1970. */\r
+               days = (unsigned)days + 365 * (unsigned)(years - 1970) +\r
+                       (unsigned)(nleap (years));\r
+               tm->tm_wday = ((unsigned)days + 4) % 7; /* Jan 1, 1970 was Thursday. */\r
+               tm->tm_isdst = 0;\r
+\r
+               if (years < 1970)\r
+                       return (time_t)-1;\r
+\r
+#if (defined(TM_YEAR_MAX) && defined(TM_MON_MAX) && defined(TM_MDAY_MAX))\r
+#if (defined(TM_HOUR_MAX) && defined(TM_MIN_MAX) && defined(TM_SEC_MAX))\r
+               if (years > TM_YEAR_MAX ||\r
+                       (years == TM_YEAR_MAX &&\r
+                       (tm->tm_yday > ydays[TM_MON_MAX] + (TM_MDAY_MAX - 1) +\r
+                       (TM_MON_MAX > 1 && leap (TM_YEAR_MAX)) ||\r
+                       (tm->tm_yday == ydays[TM_MON_MAX] + (TM_MDAY_MAX - 1) +\r
+                       (TM_MON_MAX > 1 && leap (TM_YEAR_MAX)) &&\r
+                       (hours > TM_HOUR_MAX ||\r
+                       (hours == TM_HOUR_MAX &&\r
+                       (minutes > TM_MIN_MAX ||\r
+                       (minutes == TM_MIN_MAX && seconds > TM_SEC_MAX) )))))))\r
+                       return (time_t)-1;\r
+#endif\r
+#endif\r
+\r
+               return (time_t)(86400L * (unsigned long)(unsigned)days +\r
+                       3600L * (unsigned long)hours +\r
+                       (unsigned long)(60 * minutes + seconds));\r
+}\r
+\r
+// システムタイマの取得\r
+UINT Tick()\r
+{\r
+       // KS\r
+       KS_INC(KS_GETTICK_COUNT);\r
+       return OSGetTick();\r
+}\r
+\r
+// スレッドのスリープ\r
+void SleepThread(UINT time)\r
+{\r
+       // KS\r
+       KS_INC(KS_SLEEPTHREAD_COUNT);\r
+\r
+       OSSleep(time);\r
+}\r
+\r
+// イールド\r
+void YieldCpu()\r
+{\r
+       OSYield();\r
+}\r
+\r
+// システム停止 (異常終了)\r
+void AbortExit()\r
+{\r
+#ifdef OS_WIN32\r
+       _exit(1);\r
+#else  // OS_WIN32\r
+\r
+#ifdef RLIMIT_CORE\r
+       UnixSetResourceLimit(RLIMIT_CORE, 0);\r
+#endif // RLIMIT_CORE\r
+\r
+       abort();\r
+#endif // OS_WIN32\r
+}\r
+\r
+\r
+void AbortExitEx(char *msg)\r
+{\r
+       FILE *f;\r
+       // 引数チェック\r
+       if (msg == NULL)\r
+       {\r
+               msg = "Unknown Error";\r
+       }\r
+\r
+       f = fopen("abort_error_log.txt", "w");\r
+       if (f != NULL)\r
+       {\r
+               fwrite(msg, 1, strlen(msg), f);\r
+               fclose(f);\r
+       }\r
+\r
+       fputs("Fatal Error: ", stdout);\r
+       fputs(msg, stdout);\r
+       fputs("\r\n", stdout);\r
+\r
+#ifdef OS_WIN32\r
+       _exit(1);\r
+#else  // OS_WIN32\r
+\r
+#ifdef RLIMIT_CORE\r
+       UnixSetResourceLimit(RLIMIT_CORE, 0);\r
+#endif // RLIMIT_CORE\r
+\r
+       abort();\r
+#endif // OS_WIN32\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Kernel.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Kernel.h
new file mode 100644 (file)
index 0000000..e05aec5
--- /dev/null
@@ -0,0 +1,227 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+#ifndef        KERNEL_H\r
+#define        KERNEL_H\r
+\r
+// メモリ使用情報\r
+struct MEMINFO\r
+{\r
+       UINT64 TotalMemory;\r
+       UINT64 UsedMemory;\r
+       UINT64 FreeMemory;\r
+       UINT64 TotalPhys;\r
+       UINT64 UsedPhys;\r
+       UINT64 FreePhys;\r
+};\r
+\r
+// ロケール情報\r
+struct LOCALE\r
+{\r
+       wchar_t YearStr[16], MonthStr[16], DayStr[16];\r
+       wchar_t HourStr[16], MinuteStr[16], SecondStr[16];\r
+       wchar_t DayOfWeek[7][16];\r
+       wchar_t SpanDay[16], SpanHour[16], SpanMinute[16], SpanSecond[16];\r
+       wchar_t Unknown[32];\r
+};\r
+\r
+\r
+// スレッドプロシージャ\r
+typedef void (THREAD_PROC)(THREAD *thread, void *param);\r
+\r
+// スレッド\r
+struct THREAD\r
+{\r
+       REF *ref;\r
+       THREAD_PROC *thread_proc;\r
+       void *param;\r
+       void *pData;\r
+       EVENT *init_finished_event;\r
+       void *AppData1, *AppData2, *AppData3;\r
+       UINT AppInt1, AppInt2, AppInt3;\r
+       UINT ThreadId;\r
+       bool PoolThread;\r
+       THREAD *PoolHostThread;\r
+       LIST *PoolWaitList;                                             // スレッド停止待機リスト\r
+       volatile bool PoolHalting;                              // スレッド停止中\r
+       EVENT *release_event;\r
+};\r
+\r
+// スレッドプールデータ\r
+struct THREAD_POOL_DATA\r
+{\r
+       EVENT *Event;                                           // 待機イベント\r
+       EVENT *InitFinishEvent;                         // 初期化完了イベント\r
+       THREAD *Thread;                                         // 現在割り当てられているスレッド\r
+       THREAD_PROC *ThreadProc;                        // 現在割り当てられているスレッドプロシージャ\r
+};\r
+\r
+// インスタンス\r
+struct INSTANCE\r
+{\r
+       char *Name;                                                     // 名前\r
+       void *pData;                                            // データ\r
+};\r
+\r
+// 関数プロトタイプ\r
+void SleepThread(UINT time);\r
+THREAD *NewThreadInternal(THREAD_PROC *thread_proc, void *param);\r
+void ReleaseThreadInternal(THREAD *t);\r
+void CleanupThreadInternal(THREAD *t);\r
+void NoticeThreadInitInternal(THREAD *t);\r
+void WaitThreadInitInternal(THREAD *t);\r
+bool WaitThreadInternal(THREAD *t);\r
+THREAD *NewThread(THREAD_PROC *thread_proc, void *param);\r
+void ReleaseThread(THREAD *t);\r
+void CleanupThread(THREAD *t);\r
+void NoticeThreadInit(THREAD *t);\r
+void WaitThreadInit(THREAD *t);\r
+bool WaitThread(THREAD *t, UINT timeout);\r
+void InitThreading();\r
+void FreeThreading();\r
+void ThreadPoolProc(THREAD *t, void *param);\r
+\r
+time_t c_mkgmtime(struct tm *tm);\r
+void TmToSystem(SYSTEMTIME *st, struct tm *t);\r
+void SystemToTm(struct tm *t, SYSTEMTIME *st);\r
+void TimeToSystem(SYSTEMTIME *st, time_t t);\r
+time_t SystemToTime(SYSTEMTIME *st);\r
+time_t TmToTime(struct tm *t);\r
+void TimeToTm(struct tm *t, time_t time);\r
+void NormalizeTm(struct tm *t);\r
+void NormalizeSystem(SYSTEMTIME *st);\r
+void LocalToSystem(SYSTEMTIME *system, SYSTEMTIME *local);\r
+void SystemToLocal(SYSTEMTIME *local, SYSTEMTIME *system);\r
+INT64 GetTimeDiffEx(SYSTEMTIME *basetime, bool local_time);\r
+void UINT64ToSystem(SYSTEMTIME *st, UINT64 sec64);\r
+UINT64 SystemToUINT64(SYSTEMTIME *st);\r
+UINT64 LocalTime64();\r
+UINT64 SystemTime64();\r
+void LocalTime(SYSTEMTIME *st);\r
+void SystemTime(SYSTEMTIME *st);\r
+void SetLocale(wchar_t *str);\r
+bool LoadLocale(LOCALE *locale, wchar_t *str);\r
+void GetCurrentLocale(LOCALE *locale);\r
+void GetDateTimeStr(char *str, UINT size, SYSTEMTIME *st);\r
+void GetDateTimeStrMilli(char *str, UINT size, SYSTEMTIME *st);\r
+void GetDateStr(char *str, UINT size, SYSTEMTIME *st);\r
+void GetDateTimeStrEx(wchar_t *str, UINT size, SYSTEMTIME *st, LOCALE *locale);\r
+void GetTimeStrEx(wchar_t *str, UINT size, SYSTEMTIME *st, LOCALE *locale);\r
+void GetDateStrEx(wchar_t *str, UINT size, SYSTEMTIME *st, LOCALE *locale);\r
+void GetTimeStrMilli(char *str, UINT size, SYSTEMTIME *st);\r
+void GetTimeStr(char *str, UINT size, SYSTEMTIME *st);\r
+UINT Tick();\r
+UINT TickRealtime();\r
+UINT TickRealtimeManual();\r
+UINT64 TickGetRealtimeTickValue64();\r
+UINT64 SystemToLocal64(UINT64 t);\r
+UINT64 LocalToSystem64(UINT64 t);\r
+UINT ThreadId();\r
+void GetDateTimeStr64(char *str, UINT size, UINT64 sec64);\r
+void GetDateTimeStr64Uni(wchar_t *str, UINT size, UINT64 sec64);\r
+void GetDateTimeStrMilli64(char *str, UINT size, UINT64 sec64);\r
+void GetDateStr64(char *str, UINT size, UINT64 sec64);\r
+void GetDateTimeStrEx64(wchar_t *str, UINT size, UINT64 sec64, LOCALE *locale);\r
+void GetTimeStrEx64(wchar_t *str, UINT size, UINT64 sec64, LOCALE *locale);\r
+void GetDateStrEx64(wchar_t *str, UINT size, UINT64 sec64, LOCALE *locale);\r
+void GetTimeStrMilli64(char *str, UINT size, UINT64 sec64);\r
+void GetTimeStr64(char *str, UINT size, UINT64 sec64);\r
+UINT64 SafeTime64(UINT64 sec64);\r
+bool Run(char *filename, char *arg, bool hide, bool wait);\r
+bool RunW(wchar_t *filename, wchar_t *arg, bool hide, bool wait);\r
+void HashInstanceName(char *name, UINT size, char *instance_name);\r
+void HashInstanceNameLocal(char *name, UINT size, char *instance_name);\r
+INSTANCE *NewSingleInstance(char *instance_name);\r
+INSTANCE *NewSingleInstanceEx(char *instance_name, bool user_local);\r
+void FreeSingleInstance(INSTANCE *inst);\r
+void GetSpanStr(char *str, UINT size, UINT64 sec64);\r
+void GetSpanStrEx(wchar_t *str, UINT size, UINT64 sec64, LOCALE *locale);\r
+void GetSpanStrMilli(char *str, UINT size, UINT64 sec64);\r
+void GetMemInfo(MEMINFO *info);\r
+bool GetEnv(char *name, char *data, UINT size);\r
+bool GetEnvW(wchar_t *name, wchar_t *data, UINT size);\r
+bool GetEnvW_ForWin32(wchar_t *name, wchar_t *data, UINT size);\r
+bool GetEnvW_ForUnix(wchar_t *name, wchar_t *data, UINT size);\r
+void GetHomeDir(char *path, UINT size);\r
+void GetHomeDirW(wchar_t *path, UINT size);\r
+void AbortExit();\r
+void AbortExitEx(char *msg);\r
+void YieldCpu();\r
+UINT DoNothing();\r
+\r
+#endif // KERNEL_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/MayaType.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/MayaType.h
new file mode 100644 (file)
index 0000000..652d2bd
--- /dev/null
@@ -0,0 +1,432 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// MayaType.h\r
+// Mayaqua Kernel 型宣言ヘッダファイル\r
+\r
+#ifndef        MAYATYPE_H\r
+#define        MAYATYPE_H\r
+\r
+// windows.h ヘッダが include されているかどうかをチェック\r
+#ifndef        WINDOWS_H\r
+#ifdef _WINDOWS_\r
+#define        WINDOWS_H\r
+#endif // _WINDOWS_\r
+#endif // WINDOWS_H\r
+\r
+\r
+#if    !defined(ENCRYPT_C) && !defined(HAM_C)\r
+// OpenSSL が使用する構造体\r
+typedef struct x509_st X509;\r
+typedef struct evp_pkey_st EVP_PKEY;\r
+typedef struct bio_st BIO;\r
+typedef struct ssl_st SSL;\r
+typedef struct ssl_ctx_st SSL_CTX;\r
+typedef struct X509_req_st X509_REQ;\r
+typedef struct PKCS12 PKCS12;\r
+typedef struct bignum_st BIGNUM;\r
+typedef struct x509_crl_st X509_CRL;\r
+#endif // ENCRYPT_C\r
+\r
+// \r
+// 定数\r
+// \r
+\r
+// 標準のバッファサイズ\r
+#define        STD_SIZE                        512\r
+#define        MAX_SIZE                        512\r
+#define        BUF_SIZE                        512\r
+\r
+// 対応 Windows OS 一覧\r
+#define        SUPPORTED_WINDOWS_LIST          "Windows 98 / 98 SE / ME / NT 4.0 SP6a / 2000 SP4 / XP SP2, SP3 / Server 2003 SP2 / SBS 2003 SP2 / Storage Server 2003 SP2 / Vista SP1, SP2 / Server 2008 SP1, SP2 / Storage Server 2008 SP1, SP2 / Home Server / 7 / Server 2008 R2"\r
+\r
+// 無限\r
+#ifndef        WINDOWS_H\r
+#define        INFINITE                        (0xFFFFFFFF)\r
+#endif\r
+\r
+\r
+#define        SRC_NAME                        __FILE__        // ソースコードのファイル名\r
+#define        SRC_LINE                        __LINE__        // ソースコード中の行番号\r
+\r
+// 最大パスサイズ\r
+#ifndef        WINDOWS_H\r
+#define        MAX_PATH                        260\r
+#endif // WINDOWS_H\r
+\r
+// シークの種類\r
+#ifndef        FILE_BEGIN\r
+#define        FILE_BEGIN      SEEK_SET\r
+#endif // FILE_BEGIN\r
+#ifndef        FILE_END\r
+#define        FILE_END        SEEK_END\r
+#endif // FILE_END\r
+#ifndef        FILE_CURRENT\r
+#define        FILE_CURRENT    SEEK_CUR\r
+#endif // FILE_CURRENT\r
+\r
+#ifndef        INVALID_SOCKET\r
+#define        INVALID_SOCKET          (-1)\r
+#endif // INVALID_SOCKET\r
+\r
+#ifndef        SOCKET_ERROR\r
+#define        SOCKET_ERROR            (-1)\r
+#endif //SOCKET_ERROR\r
+\r
+// 比較関数\r
+typedef int (COMPARE)(void *p1, void *p2);\r
+\r
+// \r
+// マクロ\r
+\r
+\r
+#ifdef MAX\r
+#undef MAX\r
+#endif // MAX\r
+\r
+#ifdef MIN\r
+#undef MIN\r
+#endif // MIN\r
+\r
+// a と b の最小値を求める\r
+#define        MIN(a, b)                       ((a) >= (b) ? (b) : (a))\r
+// a と b の最大値を求める\r
+#define        MAX(a, b)                       ((a) >= (b) ? (a) : (b))\r
+\r
+// int を bool にする\r
+#define        INT_TO_BOOL(i)          (((i) == 0) ? false : true)\r
+#define        MAKEBOOL(i)                     INT_TO_BOOL(i)\r
+#define        BOOL_TO_INT(i)          (((i) == false) ? 0 : 1)\r
+\r
+// max_value よりも小さい a を返す\r
+#define        LESS(a, max_value)      ((a) <= (max_value) ? (a) : (max_value))\r
+// min_value よりも大きい a を返す\r
+#define        MORE(a, min_value)      ((a) >= (min_value) ? (a) : (min_value))\r
+// a が b と c の内部にある値かどうか調べる\r
+#define        INNER(a, b, c)          (((b) <= (c) && (a) >= (b) && (a) <= (c)) || ((b) >= (c) && (a) >= (c) && (a) <= (b)))\r
+// a が b と c の外部にある値かどうか調べる\r
+#define        OUTER(a, b, c)          (!INNER((a), (b), (c)))\r
+// a を b と c の間にある値となるように調整する\r
+#define        MAKESURE(a, b, c)               (((b) <= (c)) ? (MORE(LESS((a), (c)), (b))) : (MORE(LESS((a), (b)), (c))))\r
+\r
+// ポインタを UINT にする\r
+#define        POINTER_TO_KEY(p)               ((sizeof(void *) == sizeof(UINT)) ? (UINT)(p) : HashPtrToUINT(p))\r
+// UINT とポインタを比較する\r
+#define        COMPARE_POINTER_AND_KEY(p, i)   (POINTER_TO_KEY(p) == (i))\r
+// ポインタを UINT64 にする\r
+#define        POINTER_TO_UINT64(p)    (((sizeof(void *) == sizeof(UINT64)) ? (UINT64)(p) : (UINT64)((UINT)(p))))\r
+// UINT64 をポインタにする\r
+#define        UINT64_TO_POINTER(i)    ((sizeof(void *) == sizeof(UINT64)) ? (void *)(i) : (void *)((UINT)(i)))\r
+\r
+// \r
+// 型宣言\r
+// \r
+\r
+// BOOL 型\r
+#ifndef        WINDOWS_H\r
+typedef        unsigned int            BOOL;\r
+#define        TRUE                            1\r
+#define        FALSE                           0\r
+#endif // WINDOWS_H\r
+\r
+// bool 型\r
+#ifndef        WIN32HTML_CPP\r
+typedef        unsigned int            bool;\r
+#define        true                            1\r
+#define        false                           0\r
+#endif // WIN32HTML_CPP\r
+\r
+// 32bit 整数型\r
+#ifndef        WINDOWS_H\r
+typedef        unsigned int            UINT;\r
+typedef        unsigned int            UINT32;\r
+typedef        unsigned int            DWORD;\r
+typedef        signed int                      INT;\r
+typedef        signed int                      INT32;\r
+\r
+typedef        int                                     UINT_PTR;\r
+typedef        long                            LONG_PTR;\r
+\r
+#endif\r
+\r
+// 16bit 整数型\r
+typedef        unsigned short          WORD;\r
+typedef        unsigned short          USHORT;\r
+typedef        signed short            SHORT;\r
+\r
+// 8bit 整数型\r
+typedef        unsigned char           BYTE;\r
+typedef        unsigned char           UCHAR;\r
+\r
+#ifndef        WIN32HTML_CPP\r
+typedef signed char                    CHAR;\r
+#endif // WIN32HTML_CPP\r
+\r
+\r
+// 64bit 整数型\r
+typedef        unsigned long long      UINT64;\r
+typedef signed long long       INT64;\r
+\r
+#ifdef OS_UNIX\r
+// コンパイルエラーの回避\r
+#define        __cdecl\r
+#define        __declspec(x)\r
+// socket 型\r
+typedef        int SOCKET;\r
+#else  // OS_UNIX\r
+#ifndef        _WINSOCK2API_\r
+typedef UINT_PTR SOCKET;\r
+#endif // _WINSOCK2API_\r
+#endif // OS_UNIX\r
+\r
+// OS の種類\r
+#define        OSTYPE_WINDOWS_95                                               1100    // Windows 95\r
+#define        OSTYPE_WINDOWS_98                                               1200    // Windows 98\r
+#define        OSTYPE_WINDOWS_ME                                               1300    // Windows Me\r
+#define        OSTYPE_WINDOWS_UNKNOWN                                  1400    // Windows (不明)\r
+#define        OSTYPE_WINDOWS_NT_4_WORKSTATION                 2100    // Windows NT 4.0 Workstation\r
+#define        OSTYPE_WINDOWS_NT_4_SERVER                              2110    // Windows NT 4.0 Server\r
+#define        OSTYPE_WINDOWS_NT_4_SERVER_ENTERPRISE   2111    // Windows NT 4.0 Server, Enterprise Edition\r
+#define        OSTYPE_WINDOWS_NT_4_TERMINAL_SERVER             2112    // Windows NT 4.0 Terminal Server\r
+#define        OSTYPE_WINDOWS_NT_4_BACKOFFICE                  2113    // BackOffice Server 4.5\r
+#define        OSTYPE_WINDOWS_NT_4_SMS                                 2114    // Small Business Server 4.5\r
+#define        OSTYPE_WINDOWS_2000_PROFESSIONAL                2200    // Windows 2000 Professional\r
+#define        OSTYPE_WINDOWS_2000_SERVER                              2211    // Windows 2000 Server\r
+#define        OSTYPE_WINDOWS_2000_ADVANCED_SERVER             2212    // Windows 2000 Advanced Server\r
+#define        OSTYPE_WINDOWS_2000_DATACENTER_SERVER   2213    // Windows 2000 Datacenter Server\r
+#define        OSTYPE_WINDOWS_2000_BACKOFFICE                  2214    // BackOffice Server 2000\r
+#define        OSTYPE_WINDOWS_2000_SBS                                 2215    // Small Business Server 2000\r
+#define        OSTYPE_WINDOWS_XP_HOME                                  2300    // Windows XP Home Edition\r
+#define        OSTYPE_WINDOWS_XP_PROFESSIONAL                  2301    // Windows XP Professional\r
+#define        OSTYPE_WINDOWS_2003_WEB                                 2410    // Windows Server 2003 Web Edition\r
+#define        OSTYPE_WINDOWS_2003_STANDARD                    2411    // Windows Server 2003 Standard Edition\r
+#define        OSTYPE_WINDOWS_2003_ENTERPRISE                  2412    // Windows Server 2003 Enterprise Edition\r
+#define        OSTYPE_WINDOWS_2003_DATACENTER                  2413    // Windows Server 2003 DataCenter Edition\r
+#define        OSTYPE_WINDOWS_2003_BACKOFFICE                  2414    // BackOffice Server 2003\r
+#define        OSTYPE_WINDOWS_2003_SBS                                 2415    // Small Business Server 2003\r
+#define        OSTYPE_WINDOWS_LONGHORN_PROFESSIONAL    2500    // Windows Vista\r
+#define        OSTYPE_WINDOWS_LONGHORN_SERVER                  2510    // Windows Server 2008\r
+#define        OSTYPE_WINDOWS_7                                                2600    // Windows 7\r
+#define        OSTYPE_WINDOWS_SERVER_2008_R2                   2610    // Windows Server 2008 R2\r
+#define        OSTYPE_WINDOWS_8                                                2700    // Windows 8\r
+#define        OSTYPE_WINDOWS_SERVER_8                                 2710    // Windows Server 8\r
+#define        OSTYPE_UNIX_UNKNOWN                                             3000    // 不明な UNIX\r
+#define        OSTYPE_LINUX                                                    3100    // Linux\r
+#define        OSTYPE_SOLARIS                                                  3200    // Solaris\r
+#define        OSTYPE_CYGWIN                                                   3300    // Cygwin\r
+#define        OSTYPE_BSD                                                              3400    // BSD\r
+#define        OSTYPE_MACOS_X                                                  3500    // MacOS X\r
+\r
+\r
+// OS 判別用マクロ\r
+#define        GET_KETA(t, i)                  (((t) % (i * 10)) / i)\r
+#define        OS_IS_WINDOWS_9X(t)             (GET_KETA(t, 1000) == 1)\r
+#define        OS_IS_WINDOWS_NT(t)             (GET_KETA(t, 1000) == 2)\r
+#define        OS_IS_WINDOWS(t)                (OS_IS_WINDOWS_9X(t) || OS_IS_WINDOWS_NT(t))\r
+#define        OS_IS_SERVER(t)                 (OS_IS_WINDOWS_NT(t) && GET_KETA(t, 10))\r
+#define        OS_IS_WORKSTATION(t)    ((OS_IS_WINDOWS_NT(t) && (!(GET_KETA(t, 10)))) || OS_IS_WINDOWS_9X(t))\r
+#define        OS_IS_UNIX(t)                   (GET_KETA(t, 1000) == 3)\r
+\r
+\r
+// OS 情報\r
+typedef struct OS_INFO\r
+{\r
+       UINT OsType;                                                            // OS の種類\r
+       UINT OsServicePack;                                                     // サービスパック番号\r
+       char *OsSystemName;                                                     // OS システム名\r
+       char *OsProductName;                                            // OS 製品名\r
+       char *OsVendorName;                                                     // OS ベンダ名\r
+       char *OsVersion;                                                        // OS バージョン\r
+       char *KernelName;                                                       // カーネル名\r
+       char *KernelVersion;                                            // カーネルバージョン\r
+} OS_INFO;\r
+\r
+// 時刻型\r
+#ifndef        WINDOWS_H\r
+typedef struct SYSTEMTIME\r
+{\r
+       WORD wYear;\r
+       WORD wMonth;\r
+       WORD wDayOfWeek;\r
+       WORD wDay;\r
+       WORD wHour;\r
+       WORD wMinute;\r
+       WORD wSecond;\r
+       WORD wMilliseconds;\r
+} SYSTEMTIME;\r
+#endif // WINDOWS_H\r
+\r
+\r
+// Object.h\r
+typedef struct LOCK LOCK;\r
+typedef struct COUNTER COUNTER;\r
+typedef struct REF REF;\r
+typedef struct EVENT EVENT;\r
+typedef struct DEADCHECK DEADCHECK;\r
+\r
+// Tracking.h\r
+typedef struct CALLSTACK_DATA CALLSTACK_DATA;\r
+typedef struct TRACKING_OBJECT TRACKING_OBJECT;\r
+typedef struct MEMORY_STATUS MEMORY_STATUS;\r
+typedef struct TRACKING_LIST TRACKING_LIST;\r
+\r
+// FileIO.h\r
+typedef struct IO IO;\r
+\r
+// Memory.h\r
+typedef struct MEMTAG MEMTAG;\r
+typedef struct BUF BUF;\r
+typedef struct FIFO FIFO;\r
+typedef struct LIST LIST;\r
+typedef struct QUEUE QUEUE;\r
+typedef struct SK SK;\r
+typedef struct CANDIDATE CANDIDATE;\r
+typedef struct STRMAP_ENTRY STRMAP_ENTRY;\r
+\r
+// Str.h\r
+typedef struct TOKEN_LIST TOKEN_LIST;\r
+typedef struct INI_ENTRY INI_ENTRY;\r
+\r
+// Internat.h\r
+typedef struct UNI_TOKEN_LIST UNI_TOKEN_LIST;\r
+\r
+// Encrypt.h\r
+typedef struct CRYPT CRYPT;\r
+typedef struct NAME NAME;\r
+typedef struct X_SERIAL X_SERIAL;\r
+typedef struct X X;\r
+typedef struct K K;\r
+typedef struct P12 P12;\r
+typedef struct X_CRL X_CRL;\r
+\r
+// Secure.h\r
+typedef struct SECURE_DEVICE SECURE_DEVICE;\r
+typedef struct SEC_INFO SEC_INFO;\r
+typedef struct SECURE SECURE;\r
+typedef struct SEC_OBJ SEC_OBJ;\r
+\r
+// Kernel.h\r
+typedef struct MEMINFO MEMINFO;\r
+typedef struct LOCALE LOCALE;\r
+typedef struct THREAD THREAD;\r
+typedef struct THREAD_POOL_DATA THREAD_POOL_DATA;\r
+typedef struct INSTANCE INSTANCE;\r
+\r
+// Pack.h\r
+typedef struct VALUE VALUE;\r
+typedef struct ELEMENT ELEMENT;\r
+typedef struct PACK PACK;\r
+\r
+// Cfg.h\r
+typedef struct FOLDER FOLDER;\r
+typedef struct ITEM ITEM;\r
+typedef struct CFG_RW CFG_RW;\r
+typedef struct CFG_ENUM_PARAM CFG_ENUM_PARAM;\r
+\r
+// Table.h\r
+typedef struct TABLE TABLE;\r
+\r
+// Network.h\r
+typedef struct IP IP;\r
+typedef struct DNSCACHE DNSCACHE;\r
+typedef struct SOCK_EVENT SOCK_EVENT;\r
+typedef struct SOCK SOCK;\r
+typedef struct SOCKSET SOCKSET;\r
+typedef struct CANCEL CANCEL;\r
+typedef struct ROUTE_ENTRY ROUTE_ENTRY;\r
+typedef struct ROUTE_TABLE ROUTE_TABLE;\r
+//typedef struct SOCKLIST SOCKLIST;\r
+typedef struct IP_CLIENT IP_CLIENT;\r
+typedef struct ROUTE_CHANGE ROUTE_CHANGE;\r
+typedef struct ROUTE_CHANGE_DATA ROUTE_CHANGE_DATA;\r
+typedef struct GETIP_THREAD_PARAM GETIP_THREAD_PARAM;\r
+typedef struct WIN32_RELEASEADDRESS_THREAD_PARAM WIN32_RELEASEADDRESS_THREAD_PARAM;\r
+typedef struct IPV6_ADDR IPV6_ADDR;\r
+\r
+// Tick64.h\r
+typedef struct ADJUST_TIME ADJUST_TIME;\r
+typedef struct TICK64 TICK64;\r
+\r
+// FileIO.h\r
+typedef struct DIRENT DIRENT;\r
+typedef struct DIRLIST DIRLIST;\r
+\r
+\r
+\r
+\r
+#endif // MAYATYPE_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Mayaqua.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Mayaqua.c
new file mode 100644 (file)
index 0000000..eff8e54
--- /dev/null
@@ -0,0 +1,1174 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Mayaqua.c\r
+// Mayaqua Kernel プログラム\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <locale.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+// グローバル変数\r
+bool g_memcheck;                                                               // メモリチェックの有効化\r
+bool g_debug;                                                                  // デバッグモード\r
+UINT64 kernel_status[NUM_KERNEL_STATUS];               // カーネル状態\r
+UINT64 kernel_status_max[NUM_KERNEL_STATUS];   // カーネル状態 (最大値)\r
+LOCK *kernel_status_lock[NUM_KERNEL_STATUS];   // カーネル状態ロック\r
+BOOL kernel_status_inited = false;                             // カーネル状態初期化フラグ\r
+bool g_little_endian = true;\r
+char *cmdline = NULL;                                                  // コマンドライン\r
+wchar_t *uni_cmdline = NULL;                                   // Unicode コマンドライン\r
+\r
+// スタティック変数\r
+static char *exename = NULL;                                           // EXE ファイル名 (ANSI)\r
+static wchar_t *exename_w = NULL;                                      // EXE ファイル名 (Unicode)\r
+static TOKEN_LIST *cmdline_token = NULL;                       // コマンドライントークン\r
+static UNI_TOKEN_LIST *cmdline_uni_token = NULL;       // コマンドライントークン (Unicode)\r
+static OS_INFO *os_info = NULL;                                                // OS 情報\r
+static bool dot_net_mode = false;\r
+static bool minimal_mode = false;\r
+static UINT last_time_check = 0;\r
+static UINT first_time_check = 0;\r
+static bool is_nt = false;\r
+static bool is_ham_mode = false;\r
+static UINT init_mayaqua_counter = 0;\r
+static bool use_probe = false;\r
+static BUF *probe_buf = NULL;\r
+static LOCK *probe_lock = NULL;\r
+static UINT64 probe_start = 0;\r
+static UINT64 probe_last = 0;\r
+static bool probe_enabled = false;\r
+\r
+// チェックサムを計算する\r
+USHORT CalcChecksum16(void *buf, UINT size)\r
+{\r
+       int sum = 0;\r
+       USHORT *addr = (USHORT *)buf;\r
+       int len = (int)size;\r
+       USHORT *w = addr;\r
+       int nleft = len;\r
+       USHORT answer = 0;\r
+\r
+       while (nleft > 1)\r
+       {\r
+               sum += *w++;\r
+               nleft -= 2;\r
+       }\r
+\r
+       if (nleft == 1)\r
+       {\r
+               *(UCHAR *)(&answer) = *(UCHAR *)w;\r
+               sum += answer;\r
+       }\r
+\r
+       sum = (sum >> 16) + (sum & 0xffff);\r
+       sum += (sum >> 16);\r
+\r
+       answer = ~sum;\r
+\r
+       return answer;\r
+}\r
+\r
+// データ付き Probe の書き込み\r
+void WriteProbeData(char *filename, UINT line, char *str, void *data, UINT size)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       USHORT cs;\r
+\r
+       if (IsProbeEnabled() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // データのチェックサムをとる\r
+       if (size != 0)\r
+       {\r
+               cs = CalcChecksum16(data, size);\r
+       }\r
+       else\r
+       {\r
+               cs = 0;\r
+       }\r
+\r
+       // 文字列の生成\r
+       snprintf(tmp, sizeof(tmp), "\"%s\" (Size=%5u, Crc=0x%04X)", str, size, cs);\r
+\r
+       WriteProbe(filename, line, tmp);\r
+}\r
+\r
+// Probe の書き込み\r
+void WriteProbe(char *filename, UINT line, char *str)\r
+{\r
+#ifdef OS_WIN32\r
+       char *s;\r
+       char tmp[MAX_SIZE];\r
+       char tmp2[MAX_SIZE];\r
+       UINT64 now = 0;\r
+       UINT64 time;\r
+\r
+       if (IsProbeEnabled() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       now = MsGetHiResCounter();\r
+\r
+       Lock(probe_lock);\r
+       {\r
+               UINT64 diff;\r
+               \r
+               time = MsGetHiResTimeSpanUSec(now - probe_start);\r
+\r
+               diff = time - probe_last;\r
+\r
+               if (time < probe_last)\r
+               {\r
+                       diff = 0;\r
+               }\r
+\r
+               probe_last = time;\r
+\r
+               ToStr64(tmp, time);\r
+               MakeCharArray2(tmp2, ' ', (UINT)(MIN(12, (int)12 - (int)StrLen(tmp))));\r
+               WriteBuf(probe_buf, tmp2, StrLen(tmp2));\r
+               WriteBuf(probe_buf, tmp, StrLen(tmp));\r
+\r
+               s = " [+";\r
+               WriteBuf(probe_buf, s, StrLen(s));\r
+\r
+               ToStr64(tmp, diff);\r
+               MakeCharArray2(tmp2, ' ', (UINT)(MIN(12, (int)12 - (int)StrLen(tmp))));\r
+               WriteBuf(probe_buf, tmp2, StrLen(tmp2));\r
+               WriteBuf(probe_buf, tmp, StrLen(tmp));\r
+\r
+               s = "] - ";\r
+               WriteBuf(probe_buf, s, StrLen(s));\r
+\r
+               WriteBuf(probe_buf, filename, StrLen(filename));\r
+\r
+               s = "(";\r
+               WriteBuf(probe_buf, s, StrLen(s));\r
+\r
+               ToStr64(tmp, (UINT64)line);\r
+               WriteBuf(probe_buf, tmp, StrLen(tmp));\r
+\r
+               s = "): ";\r
+               WriteBuf(probe_buf, s, StrLen(s));\r
+\r
+               WriteBuf(probe_buf, str, StrLen(str));\r
+\r
+               s = "\r\n";\r
+               WriteBuf(probe_buf, s, StrLen(s));\r
+       }\r
+       Unlock(probe_lock);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// Probe の初期化\r
+void InitProbe()\r
+{\r
+       probe_buf = NewBuf();\r
+       probe_lock = NewLock();\r
+       probe_enabled = false;\r
+\r
+       probe_start = 0;\r
+\r
+#ifdef OS_WIN32\r
+       probe_start = MsGetHiResCounter();\r
+#endif // OS_WIN32\r
+}\r
+\r
+// Probe の解放\r
+void FreeProbe()\r
+{\r
+       if (probe_buf->Size >= 1)\r
+       {\r
+               SYSTEMTIME st;\r
+               char filename[MAX_SIZE];\r
+\r
+               // ファイルにすべて書き出す\r
+               MakeDirEx("@probe_log");\r
+\r
+               LocalTime(&st);\r
+\r
+               snprintf(filename, sizeof(filename), "@probe_log/%04u%02u%02u_%02u%02u%02u.log",\r
+                       st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);\r
+\r
+               DumpBuf(probe_buf, filename);\r
+       }\r
+\r
+       FreeBuf(probe_buf);\r
+       DeleteLock(probe_lock);\r
+}\r
+\r
+// Probe を有効 / 無効にする\r
+void EnableProbe(bool enable)\r
+{\r
+       probe_enabled = enable;\r
+}\r
+\r
+// Probe が有効かどうか取得する\r
+bool IsProbeEnabled()\r
+{\r
+#ifndef        USE_PROBE\r
+       return false;\r
+#else  // USE_PROBE\r
+       return probe_enabled;\r
+#endif // USE_PROBE\r
+}\r
+\r
+// Ham モードに設定する\r
+void SetHamMode()\r
+{\r
+       is_ham_mode = true;\r
+}\r
+\r
+// Ham モードかどうか取得する\r
+bool IsHamMode()\r
+{\r
+       return is_ham_mode;\r
+}\r
+\r
+// 前回の呼び出しから現在までにかかった時間を表示\r
+void TimeCheck()\r
+{\r
+#ifdef OS_WIN32\r
+       UINT now, ret, total;\r
+       now = Win32GetTick();\r
+       if (last_time_check == 0)\r
+       {\r
+               ret = 0;\r
+       }\r
+       else\r
+       {\r
+               ret = now - last_time_check;\r
+       }\r
+       last_time_check = now;\r
+\r
+       if (first_time_check == 0)\r
+       {\r
+               first_time_check = now;\r
+       }\r
+\r
+       total = now - first_time_check;\r
+\r
+       printf(" -- %3.3f / %3.3f\n", (double)ret / 1000.0f, (double)total / 1000.0f);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// IA64 かどうか\r
+bool IsIA64()\r
+{\r
+       if (Is64() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifndef        MAYAQUA_IA_64\r
+       return false;\r
+#else  // MAYAQUA_IA_64\r
+       return true;\r
+#endif // MAYAQUA_IA_64\r
+}\r
+\r
+// x64 かどうか\r
+bool IsX64()\r
+{\r
+       if (Is64() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifndef        MAYAQUA_IA_64\r
+       return true;\r
+#else  // MAYAQUA_IA_64\r
+       return false;\r
+#endif // MAYAQUA_IA_64\r
+}\r
+\r
+// 64bit かどうか\r
+bool Is64()\r
+{\r
+#ifdef CPU_64\r
+       return true;\r
+#else  // CPU_64\r
+       return false;\r
+#endif // CPU_64\r
+}\r
+\r
+// 32bit かどうか\r
+bool Is32()\r
+{\r
+       return Is64() ? false : true;\r
+}\r
+\r
+// .NET モード\r
+void MayaquaDotNetMode()\r
+{\r
+       dot_net_mode = true;\r
+}\r
+\r
+// .NET モードかどうか取得\r
+bool MayaquaIsDotNetMode()\r
+{\r
+       return dot_net_mode;\r
+}\r
+\r
+// エンディアンチェック\r
+void CheckEndian()\r
+{\r
+       unsigned short test;\r
+       UCHAR *buf;\r
+\r
+       test = 0x1234;\r
+       buf = (UCHAR *)&test;\r
+       if (buf[0] == 0x12)\r
+       {\r
+               g_little_endian = false;\r
+       }\r
+       else\r
+       {\r
+               g_little_endian = true;\r
+       }\r
+}\r
+\r
+// 最小モードにする\r
+void MayaquaMinimalMode()\r
+{\r
+       minimal_mode = true;\r
+}\r
+bool MayaquaIsMinimalMode()\r
+{\r
+       return minimal_mode;\r
+}\r
+\r
+// NT かどうか\r
+bool IsNt()\r
+{\r
+       return is_nt;\r
+}\r
+\r
+// Unicode をサポートしているかどうか\r
+bool IsUnicode()\r
+{\r
+#ifdef OS_WIN32\r
+       // Windows\r
+       return IsNt();\r
+#else  // OS_WIN32\r
+       // UNIX\r
+       return true;\r
+#endif // OS_WIN32\r
+}\r
+\r
+// Mayaqua ライブラリの初期化\r
+void InitMayaqua(bool memcheck, bool debug, int argc, char **argv)\r
+{\r
+       wchar_t tmp[MAX_PATH];\r
+\r
+       if ((init_mayaqua_counter++) > 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       g_memcheck = memcheck;\r
+       g_debug = debug;\r
+       cmdline = NULL;\r
+       if (dot_net_mode == false)\r
+       {\r
+               // .NET モードでこれを呼ぶとなぜか落ちる\r
+               setbuf(stdout, NULL);\r
+       }\r
+\r
+       // NT かどうか取得\r
+#ifdef OS_WIN32\r
+       is_nt = Win32IsNt();\r
+#endif // OS_WIN32\r
+\r
+       // エンディアンチェック\r
+       CheckEndian();\r
+\r
+#ifdef OS_WIN32\r
+       _configthreadlocale(_DISABLE_PER_THREAD_LOCALE);\r
+#endif // OS_WIN32\r
+\r
+       // CRT のロケール情報を日本語にする\r
+       setlocale(LC_ALL, "");\r
+\r
+       // OS の初期化\r
+       OSInit();\r
+\r
+       // 乱数の初期化\r
+       srand((UINT)SystemTime64());\r
+\r
+       tick_manual_lock = NewLock();\r
+\r
+       // FIFO システムの初期化\r
+       InitFifo();\r
+\r
+       // カーネルステータスの初期化\r
+       InitKernelStatus();\r
+\r
+       // トラッキングの初期化\r
+       InitTracking();\r
+\r
+       // スレッドプールの初期化\r
+       InitThreading();\r
+\r
+       // 文字列ライブラリの初期化\r
+       InitStringLibrary();\r
+\r
+       // ロケール情報の初期化\r
+       SetLocale(NULL);\r
+\r
+       // 暗号化ライブラリの初期化\r
+       InitCryptLibrary();\r
+\r
+       // リアルタイムクロックの初期化\r
+       InitTick64();\r
+\r
+       // ネットワーク通信モジュールの初期化\r
+       InitNetwork();\r
+\r
+       // EXE ファイル名の取得の初期化\r
+       InitGetExeName(argc >= 1 ? argv[0] : NULL);\r
+\r
+       // コマンドライン文字列の初期化\r
+       InitCommandLineStr(argc, argv);\r
+\r
+       // OS 情報の初期化\r
+       InitOsInfo();\r
+\r
+       // オペレーティングシステム固有の初期化\r
+#ifdef OS_WIN32\r
+       MsInit();       // Microsoft Win32\r
+#endif // OS_WIN32\r
+\r
+       // セキュリティトークンモジュールの初期化\r
+       InitSecure();\r
+\r
+       if (OSIsSupportedOs() == false)\r
+       {\r
+               // 強制終了\r
+               exit(0);\r
+       }\r
+\r
+       // RSA チェック\r
+       if (RsaCheckEx() == false)\r
+       {\r
+               // 強制終了\r
+               Alert("OpenSSL Library Init Failed. (too old?)\nPlease install the latest version of OpenSSL.\n\n", "RsaCheck()");\r
+               exit(0);\r
+       }\r
+\r
+       // HamCore ファイルシステムの初期化\r
+       InitHamcore();\r
+\r
+       // デフォルトで japanese.stb を読み込む\r
+       LoadTable(DEFAULT_TABLE_FILE_NAME);\r
+\r
+       if (exename == NULL)\r
+       {\r
+               // 実行可能ファイル名\r
+               exename = CopyStr("unknown");\r
+       }\r
+\r
+       // 自分自身の実行可能ファイル名が見つかるかどうか検査する\r
+       // (見つからない場合は変なパスで起動されているので終了する)\r
+       GetExeNameW(tmp, sizeof(tmp));\r
+       if (IsFileExistsW(tmp) == false)\r
+       {\r
+               wchar_t tmp2[MAX_SIZE];\r
+\r
+               UniFormat(tmp2, sizeof(tmp2),\r
+                       L"Error: Executable binary file \"%s\" not found.\r\n\r\n"\r
+                       L"Please execute program with full path.\r\n",\r
+                       tmp);\r
+\r
+               AlertW(tmp2, NULL);\r
+               _exit(0);\r
+       }\r
+\r
+       CheckUnixTempDir();\r
+\r
+       // Probe の初期化\r
+       InitProbe();\r
+}\r
+\r
+// Mayaqua ライブラリの解放\r
+void FreeMayaqua()\r
+{\r
+       if ((--init_mayaqua_counter) > 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // Probe の解放\r
+       FreeProbe();\r
+\r
+       // テーブルを削除\r
+       FreeTable();\r
+\r
+       // セキュリティトークンモジュールの解放\r
+       FreeSecure();\r
+\r
+       // オペレーティングシステム固有の解放\r
+#ifdef OS_WIN32\r
+       MsFree();\r
+#endif // OS_WIN32\r
+\r
+       // OS 情報の解放\r
+       FreeOsInfo();\r
+\r
+       // HamCore ファイルシステムの解放\r
+       FreeHamcore();\r
+\r
+       // コマンドライン文字列の解放\r
+       FreeCommandLineStr();\r
+\r
+       // コマンドライントークンの解放\r
+       FreeCommandLineTokens();\r
+\r
+       // ネットワーク通信モジュールの解放\r
+       FreeNetwork();\r
+\r
+       // リアルタイムクロックの解放\r
+       FreeTick64();\r
+\r
+       // 暗号化ライブラリの解放\r
+       FreeCryptLibrary();\r
+\r
+       // 文字列ライブラリの解放\r
+       FreeStringLibrary();\r
+\r
+       // スレッドプールの解放\r
+       FreeThreading();\r
+\r
+#ifndef        VPN_SPEED\r
+       // カーネル状態の表示\r
+       if (g_debug)\r
+       {\r
+               PrintKernelStatus();\r
+       }\r
+\r
+       // デバッグ情報の表示\r
+       if (g_memcheck)\r
+       {\r
+               PrintDebugInformation();\r
+       }\r
+#endif // VPN_SPEED\r
+\r
+       // トラッキングの解放\r
+       FreeTracking();\r
+\r
+       // カーネルステータスの解放\r
+       FreeKernelStatus();\r
+\r
+       DeleteLock(tick_manual_lock);\r
+       tick_manual_lock = NULL;\r
+\r
+       // OS の解放\r
+       OSFree();\r
+}\r
+\r
+// UNIX で /tmp が使用できるかどうか確認する\r
+void CheckUnixTempDir()\r
+{\r
+       if (OS_IS_UNIX(GetOsInfo()->OsType))\r
+       {\r
+               char tmp[128], tmp2[64];\r
+               UINT64 now = SystemTime64();\r
+               IO *o;\r
+\r
+               MakeDir("/tmp");\r
+\r
+               Format(tmp2, sizeof(tmp2), "%I64u", now);\r
+\r
+               Format(tmp, sizeof(tmp), "/tmp/.%s", tmp2);\r
+\r
+               o = FileCreate(tmp);\r
+               if (o == NULL)\r
+               {\r
+                       o = FileOpen(tmp, false);\r
+                       if (o == NULL)\r
+                       {\r
+                               Print("Unable to use /tmp.\n\n");\r
+                               exit(0);\r
+                               return;\r
+                       }\r
+               }\r
+\r
+               FileClose(o);\r
+\r
+               FileDelete(tmp);\r
+       }\r
+}\r
+\r
+// アラートの表示\r
+void Alert(char *msg, char *caption)\r
+{\r
+       OSAlert(msg, caption);\r
+}\r
+void AlertW(wchar_t *msg, wchar_t *caption)\r
+{\r
+       OSAlertW(msg, caption);\r
+}\r
+\r
+// OS 情報の表示\r
+void PrintOsInfo(OS_INFO *info)\r
+{\r
+       // 引数チェック\r
+       if (info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Print(\r
+               "OS Type          : %u\n"\r
+               "OS Service Pack  : %u\n"\r
+               "os_is_windows    : %s\n"\r
+               "os_is_windows_nt : %s\n"\r
+               "OS System Name   : %s\n"\r
+               "OS Product Name  : %s\n"\r
+               "OS Vendor Name   : %s\n"\r
+               "OS Version       : %s\n"\r
+               "Kernel Name      : %s\n"\r
+               "Kernel Version   : %s\n",\r
+               info->OsType,\r
+               info->OsServicePack,\r
+               OS_IS_WINDOWS(info->OsType) ? "true" : "false",\r
+               OS_IS_WINDOWS_NT(info->OsType) ? "true" : "false",\r
+               info->OsSystemName,\r
+               info->OsProductName,\r
+               info->OsVendorName,\r
+               info->OsVersion,\r
+               info->KernelName,\r
+               info->KernelVersion);\r
+\r
+#ifdef OS_WIN32\r
+       {\r
+               char *exe, *dir;\r
+               exe = MsGetExeFileName();\r
+               dir = MsGetExeDirName();\r
+\r
+               Print(\r
+                       "EXE File Path    : %s\n"\r
+                       "EXE Dir Path     : %s\n"\r
+                       "Process Id       : %u\n"\r
+                       "Process Handle   : 0x%X\n",\r
+                       exe, dir, MsGetCurrentProcessId(), MsGetCurrentProcess());\r
+       }\r
+#endif // OS_WIN32\r
+}\r
+\r
+// OS 種類の取得\r
+UINT GetOsType()\r
+{\r
+       OS_INFO *i = GetOsInfo();\r
+\r
+       if (i == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return i->OsType;\r
+}\r
+\r
+// OS 情報の取得\r
+OS_INFO *GetOsInfo()\r
+{\r
+       return os_info;\r
+}\r
+\r
+// OS 情報の初期化\r
+void InitOsInfo()\r
+{\r
+       if (os_info != NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       os_info = ZeroMalloc(sizeof(OS_INFO));\r
+\r
+       OSGetOsInfo(os_info);\r
+}\r
+\r
+// OS 情報の解放\r
+void FreeOsInfo()\r
+{\r
+       if (os_info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(os_info->OsSystemName);\r
+       Free(os_info->OsProductName);\r
+       Free(os_info->OsVendorName);\r
+       Free(os_info->OsVersion);\r
+       Free(os_info->KernelName);\r
+       Free(os_info->KernelVersion);\r
+       Free(os_info);\r
+\r
+       os_info = NULL;\r
+}\r
+\r
+// Unicode コマンドライントークンの取得\r
+UNI_TOKEN_LIST *GetCommandLineUniToken()\r
+{\r
+       if (cmdline_uni_token == NULL)\r
+       {\r
+               return UniNullToken();\r
+       }\r
+       else\r
+       {\r
+               return UniCopyToken(cmdline_uni_token);\r
+       }\r
+}\r
+\r
+// コマンドライントークンの取得\r
+TOKEN_LIST *GetCommandLineToken()\r
+{\r
+       if (cmdline_token == NULL)\r
+       {\r
+               return NullToken();\r
+       }\r
+       else\r
+       {\r
+               return CopyToken(cmdline_token);\r
+       }\r
+}\r
+\r
+// コマンドライン文字列をトークンに変換する\r
+void ParseCommandLineTokens()\r
+{\r
+       if (cmdline_token != NULL)\r
+       {\r
+               FreeToken(cmdline_token);\r
+       }\r
+       cmdline_token = ParseCmdLine(cmdline);\r
+\r
+       if (cmdline_uni_token != NULL)\r
+       {\r
+               UniFreeToken(cmdline_uni_token);\r
+       }\r
+       cmdline_uni_token = UniParseCmdLine(uni_cmdline);\r
+}\r
+\r
+// コマンドライントークンを解放する\r
+void FreeCommandLineTokens()\r
+{\r
+       if (cmdline_token != NULL)\r
+       {\r
+               FreeToken(cmdline_token);\r
+       }\r
+       cmdline_token = NULL;\r
+\r
+       if (cmdline_uni_token != NULL)\r
+       {\r
+               UniFreeToken(cmdline_uni_token);\r
+       }\r
+       cmdline_uni_token = NULL;\r
+}\r
+\r
+// コマンドライン文字列の初期化\r
+void InitCommandLineStr(int argc, char **argv)\r
+{\r
+       if (argc >= 1)\r
+       {\r
+#ifdef OS_UNIX\r
+               exename_w = CopyUtfToUni(argv[0]);\r
+               exename = CopyUniToStr(exename_w);\r
+#else  // OS_UNIX\r
+               exename = CopyStr(argv[0]);\r
+               exename_w = CopyStrToUni(exename);\r
+#endif // OS_UNIX\r
+       }\r
+       if (argc < 2 || argv == NULL)\r
+       {\r
+               // コマンドライン文字列無し\r
+               SetCommandLineStr(NULL);\r
+       }\r
+       else\r
+       {\r
+               // コマンドライン文字列有り\r
+               int i, total_len = 1;\r
+               char *tmp;\r
+\r
+               for (i = 1;i < argc;i++)\r
+               {\r
+                       total_len += StrLen(argv[i]) * 2 + 32;\r
+               }\r
+               tmp = ZeroMalloc(total_len);\r
+\r
+               for (i = 1;i < argc;i++)\r
+               {\r
+                       UINT s_size = StrLen(argv[i]) * 2;\r
+                       char *s = ZeroMalloc(s_size);\r
+                       bool dq = (SearchStrEx(argv[i], " ", 0, true) != INFINITE);\r
+                       ReplaceStrEx(s, s_size, argv[i], "\"", "\"\"", true);\r
+                       if (dq)\r
+                       {\r
+                               StrCat(tmp, total_len, "\"");\r
+                       }\r
+                       StrCat(tmp, total_len, s);\r
+                       if (dq)\r
+                       {\r
+                               StrCat(tmp, total_len, "\"");\r
+                       }\r
+                       StrCat(tmp, total_len, " ");\r
+                       Free(s);\r
+               }\r
+\r
+               Trim(tmp);\r
+               SetCommandLineStr(tmp);\r
+               Free(tmp);\r
+       }\r
+}\r
+\r
+// コマンドライン文字列の解放\r
+void FreeCommandLineStr()\r
+{\r
+       SetCommandLineStr(NULL);\r
+\r
+       if (exename != NULL)\r
+       {\r
+               Free(exename);\r
+               exename = NULL;\r
+       }\r
+\r
+       if (exename_w != NULL)\r
+       {\r
+               Free(exename_w);\r
+               exename_w = NULL;\r
+       }\r
+}\r
+\r
+// Unicode コマンドライン文字列の取得\r
+wchar_t *GetCommandLineUniStr()\r
+{\r
+       if (uni_cmdline == NULL)\r
+       {\r
+               return UniCopyStr(L"");\r
+       }\r
+       else\r
+       {\r
+               return UniCopyStr(uni_cmdline);\r
+       }\r
+}\r
+\r
+// コマンドライン文字列の取得\r
+char *GetCommandLineStr()\r
+{\r
+       if (cmdline == NULL)\r
+       {\r
+               return CopyStr("");\r
+       }\r
+       else\r
+       {\r
+               return CopyStr(cmdline);\r
+       }\r
+}\r
+\r
+// Unicode コマンドライン文字列の設定\r
+void SetCommandLineUniStr(wchar_t *str)\r
+{\r
+       if (uni_cmdline != NULL)\r
+       {\r
+               Free(uni_cmdline);\r
+       }\r
+       if (str == NULL)\r
+       {\r
+               uni_cmdline = NULL;\r
+       }\r
+       else\r
+       {\r
+               uni_cmdline = CopyUniStr(str);\r
+       }\r
+\r
+       ParseCommandLineTokens();\r
+}\r
+\r
+// コマンドライン文字列の設定\r
+void SetCommandLineStr(char *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               if (cmdline != NULL)\r
+               {\r
+                       Free(cmdline);\r
+               }\r
+               cmdline = NULL;\r
+       }\r
+       else\r
+       {\r
+               if (cmdline != NULL)\r
+               {\r
+                       Free(cmdline);\r
+               }\r
+               cmdline = CopyStr(str);\r
+       }\r
+\r
+       if (cmdline == NULL)\r
+       {\r
+               if (uni_cmdline != NULL)\r
+               {\r
+                       Free(uni_cmdline);\r
+                       uni_cmdline = NULL;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (uni_cmdline != NULL)\r
+               {\r
+                       Free(uni_cmdline);\r
+               }\r
+               uni_cmdline = CopyStrToUni(cmdline);\r
+       }\r
+\r
+       ParseCommandLineTokens();\r
+}\r
+\r
+// カーネルステータスの表示\r
+void PrintKernelStatus()\r
+{\r
+       bool leaked = false;\r
+\r
+       Print("\n");\r
+       Print(\r
+               "     --------- Mayaqua Kernel Status ---------\n"\r
+               "        Malloc Count ............... %u\n"\r
+               "        ReAlloc Count .............. %u\n"\r
+               "        Free Count ................. %u\n"\r
+               "        Total Memory Size .......... %I64u bytes\n"\r
+               "      * Current Memory Blocks ...... %u Blocks (Peek: %u)\n"\r
+               "        Total Memory Blocks ........ %u Blocks\n"\r
+               "      * Current MemPool Blocks ..... %u Blocks (Peek: %u)\n"\r
+               "        Total MemPool Mallocs ...... %u Mallocs\n"\r
+               "        Total MemPool ReAllocs ..... %u ReAllocs\n"\r
+               "        NewLock Count .............. %u\n"\r
+               "        DeleteLock Count ........... %u\n"\r
+               "      * Current Lock Objects ....... %u Objects\n"\r
+               "      * Current Locked Objects ..... %u Objects\n"\r
+               "        NewRef Count ............... %u\n"\r
+               "        FreeRef Count .............. %u\n"\r
+               "      * Current Ref Objects ........ %u Objects\n"\r
+               "      * Current Ref Count .......... %u Refs\n"\r
+               "        GetTime Count .............. %u\n"\r
+               "        GetTick Count .............. %u\n"\r
+               "        NewThread Count ............ %u\n"\r
+               "        FreeThread Count ........... %u\n"\r
+               "      * Current Threads ............ %u Threads\n"\r
+               "        Wait For Event Count ....... %u\n\n",\r
+               KS_GET(KS_MALLOC_COUNT),\r
+               KS_GET(KS_REALLOC_COUNT),\r
+               KS_GET(KS_FREE_COUNT),\r
+               KS_GET64(KS_TOTAL_MEM_SIZE),\r
+               KS_GET(KS_CURRENT_MEM_COUNT),\r
+               KS_GETMAX(KS_CURRENT_MEM_COUNT),\r
+               KS_GET(KS_TOTAL_MEM_COUNT),\r
+               KS_GET(KS_MEMPOOL_CURRENT_NUM),\r
+               KS_GETMAX(KS_MEMPOOL_CURRENT_NUM),\r
+               KS_GET(KS_MEMPOOL_MALLOC_COUNT),\r
+               KS_GET(KS_MEMPOOL_REALLOC_COUNT),\r
+               KS_GET(KS_NEWLOCK_COUNT),\r
+               KS_GET(KS_DELETELOCK_COUNT),\r
+               KS_GET(KS_CURRENT_LOCK_COUNT),\r
+               KS_GET(KS_CURRENT_LOCKED_COUNT),\r
+               KS_GET(KS_NEWREF_COUNT),\r
+               KS_GET(KS_FREEREF_COUNT),\r
+               KS_GET(KS_CURRENT_REF_COUNT),\r
+               KS_GET(KS_CURRENT_REFED_COUNT),\r
+               KS_GET(KS_GETTIME_COUNT),\r
+               KS_GET(KS_GETTICK_COUNT),\r
+               KS_GET(KS_NEWTHREAD_COUNT),\r
+               KS_GET(KS_FREETHREAD_COUNT),\r
+               KS_GET(KS_NEWTHREAD_COUNT) - KS_GET(KS_FREETHREAD_COUNT),\r
+               KS_GET(KS_WAIT_COUNT)\r
+               );\r
+\r
+       if (KS_GET(KS_CURRENT_MEM_COUNT) != 0 || KS_GET(KS_CURRENT_LOCK_COUNT) != 0 ||\r
+               KS_GET(KS_MEMPOOL_CURRENT_NUM) != 0 ||\r
+               KS_GET(KS_CURRENT_LOCKED_COUNT) != 0 || KS_GET(KS_CURRENT_REF_COUNT) != 0)\r
+       {\r
+               leaked = true;\r
+       }\r
+\r
+       if (leaked)\r
+       {\r
+               Print("      !!! MEMORY LEAKS DETECTED !!!\n\n");\r
+               if (g_memcheck == false)\r
+               {\r
+                       GetLine(NULL, 0);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               Print("        @@@ NO MEMORY LEAKS @@@\n\n");\r
+       }\r
+}\r
+\r
+// カーネルステータスの初期化\r
+void InitKernelStatus()\r
+{\r
+       UINT i;\r
+\r
+       // メモリ初期化\r
+       Zero(kernel_status, sizeof(kernel_status));\r
+       Zero(kernel_status_max, sizeof(kernel_status_max));\r
+\r
+       // ロック初期化\r
+       for (i = 0;i < NUM_KERNEL_STATUS;i++)\r
+       {\r
+               kernel_status_lock[i] = OSNewLock();\r
+       }\r
+\r
+       kernel_status_inited = true;\r
+}\r
+\r
+// カーネルステータスの解放\r
+void FreeKernelStatus()\r
+{\r
+       UINT i;\r
+\r
+       kernel_status_inited = false;\r
+\r
+       // ロック解放\r
+       for (i = 0;i < NUM_KERNEL_STATUS;i++)\r
+       {\r
+               OSDeleteLock(kernel_status_lock[i]);\r
+       }\r
+}\r
+\r
+// カーネルステータスのロック\r
+void LockKernelStatus(UINT id)\r
+{\r
+       // 引数チェック\r
+       if (id >= NUM_KERNEL_STATUS)\r
+       {\r
+               return;\r
+       }\r
+\r
+       OSLock(kernel_status_lock[id]);\r
+}\r
+\r
+// カーネルステータスのロック解除\r
+void UnlockKernelStatus(UINT id)\r
+{\r
+       // 引数チェック\r
+       if (id >= NUM_KERNEL_STATUS)\r
+       {\r
+               return;\r
+       }\r
+\r
+       OSUnlock(kernel_status_lock[id]);\r
+}\r
+\r
+// デバッグ情報の表示\r
+void PrintDebugInformation()\r
+{\r
+       MEMORY_STATUS memory_status;\r
+       GetMemoryStatus(&memory_status);\r
+\r
+       // ヘッダ\r
+       Print("====== SoftEther UT-VPN System Debug Information ======\n");\r
+\r
+       // メモリ情報\r
+       Print(" <Memory Status>\n"\r
+               "       Number of Allocated Memory Blocks: %u\n"\r
+               "   Total Size of Allocated Memory Blocks: %u bytes\n",\r
+               memory_status.MemoryBlocksNum, memory_status.MemorySize);\r
+\r
+       // フッタ\r
+       Print("====================================================\n");\r
+\r
+       if (KS_GET(KS_CURRENT_MEM_COUNT) != 0 || KS_GET(KS_CURRENT_LOCK_COUNT) != 0 ||\r
+               KS_GET(KS_CURRENT_LOCKED_COUNT) != 0 || KS_GET(KS_CURRENT_REF_COUNT) != 0)\r
+       {\r
+               // メモリリークしている可能性があるのでデバッグメニューを出す\r
+               MemoryDebugMenu();\r
+       }\r
+}\r
+\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Mayaqua.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Mayaqua.h
new file mode 100644 (file)
index 0000000..f221a53
--- /dev/null
@@ -0,0 +1,554 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Mayaqua.h\r
+// Mayaqua Kernel ヘッダファイル\r
+\r
+#ifndef        MAYAQUA_H\r
+#define        MAYAQUA_H\r
+\r
+// PenCore.dll 関係\r
+#define        PENCORE_DLL_NAME                "|PenCore.dll"\r
+\r
+//#define      USE_PROBE                                               // Probe を使う\r
+\r
+// リリースフラグ用マクロ\r
+#ifdef VPN_SPEED\r
+\r
+#define        DONT_USE_KERNEL_STATUS                  // カーネルステータスを更新しない\r
+#define        WIN32_USE_HEAP_API_FOR_MEMORY   // メモリ確保にヒープ API を使用する\r
+#define        WIN32_NO_DEBUG_HELP_DLL                 // デバッグ用 DLL を呼び出さない\r
+#define        DONT_CHECK_HEAP                                 // ヒープの状態をチェックしない\r
+\r
+#endif // VPN_SPEED\r
+\r
+#ifdef VPN_EXE\r
+// 実行可能ファイルビルド用\r
+#ifdef WIN32\r
+#include <windows.h>\r
+#include "../PenCore/resource.h"\r
+int main(int argc, char *argv[]);\r
+int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, char *CmdLine, int CmdShow)\r
+{\r
+       return main(0, NULL);\r
+}\r
+#endif // WIN32\r
+#endif // VPN_EXE\r
+\r
+// 定数\r
+#define        DEFAULT_TABLE_FILE_NAME         "|strtable.stb"         // デフォルト文字列テーブル\r
+#define        STRTABLE_ID                                     "UT_VPN_20100520"       // 文字列テーブル識別子\r
+\r
+// OS の判別\r
+#ifdef WIN32\r
+#define        OS_WIN32                // Microsoft Windows\r
+#else\r
+#define        OS_UNIX                 // UNIX\r
+#endif // WIN32\r
+\r
+// ディレクトリ区切り\r
+#ifdef OS_WIN32\r
+#define        PATH_BACKSLASH  // バックスラッシュ (\)\r
+#else  // WIN32\r
+#define        PATH_SLASH              // スラッシュ (/)\r
+#endif // WIN32\r
+\r
+// 文字コード\r
+#ifdef OS_WIN32\r
+#define        CODE_SHIFTJIS   // Shift_JIS コード\r
+#else  // WIN32\r
+#define        CODE_EUC                // euc-jp コード\r
+#endif // WIN32\r
+\r
+// エンディアン\r
+#define        IsBigEndian()           (g_little_endian ? false : true)\r
+#define        IsLittleEndian()        (g_little_endian)\r
+\r
+#ifdef OS_WIN32\r
+// snprintf 関数の置換\r
+#define        snprintf        _snprintf\r
+#endif // OS_WIN32\r
+\r
+// コンパイラ依存\r
+#ifndef        OS_WIN32\r
+// gcc コンパイラ\r
+#define        GCC_PACKED              __attribute__ ((__packed__))\r
+#else  // OS_WIN32\r
+// VC++ コンパイラ\r
+#define        GCC_PACKED\r
+#endif // OS_WIN32\r
+\r
+// 現在のファイルと行番号を表示するマクロ\r
+#define        WHERE                   printf("%s: %u\n", __FILE__, __LINE__); SleepThread(10);\r
+#define        WHERE32                 {       \\r
+       char tmp[128]; sprintf(tmp, "%s: %u", __FILE__, __LINE__); Win32DebugAlert(tmp);        \\r
+       }\r
+#define TIMECHECK              printf("%-12s:%5u", __FILE__, __LINE__);TimeCheck();\r
+\r
+// プローブ関係\r
+#ifdef USE_PROBE\r
+#define        PROBE_WHERE                                             WriteProbe(__FILE__, __LINE__, "");\r
+#define        PROBE_STR(str)                                  WriteProbe(__FILE__, __LINE__, (str));\r
+#define        PROBE_DATA2(str, data, size)    WriteProbeData(__FILE__, __LINE__, (str), (data), (size));\r
+#define        PROBE_DATA(data, size)                  WriteProbeData(__FILE__, __LINE__, "", (data), (size));\r
+#else  // USE_PROBE\r
+#define        PROBE_WHERE\r
+#define        PROBE_STR(str)\r
+#define        PROBE_DATA2(str, data, size)\r
+#define        PROBE_DATA(data, size)\r
+#endif // USE_PROBE\r
+\r
+// 現在の時間を表示するマクロ\r
+#ifdef WIN32\r
+#define        WHEN                    {WHERE; MsPrintTick();}\r
+#else  // WIN32\r
+#define        WHEN\r
+#endif // WIN32\r
+\r
+#ifdef OS_UNIX\r
+// UNIX 系 OS にのみ必要なヘッダ\r
+#include <sys/types.h>\r
+#include <unistd.h>\r
+#include <termios.h>\r
+#include <dirent.h>\r
+#ifdef UNIX_LINUX\r
+#include <sys/vfs.h>\r
+#elif  UNIX_BSD\r
+#include <sys/param.h>\r
+#include <sys/mount.h>\r
+#endif\r
+#ifdef UNIX_SOLARIS\r
+#include <sys/statvfs.h>\r
+#define        USE_STATVFS\r
+#endif // UNIX_SOLARIS\r
+#include <sys/stat.h>\r
+#include <sys/file.h>\r
+#include <sys/socket.h>\r
+#include <sys/time.h>\r
+#include <sys/resource.h>\r
+#include <sys/wait.h>\r
+#include <sys/ioctl.h>\r
+#ifdef UNIX_SOLARIS\r
+#include <sys/filio.h>\r
+#endif // UNIX_SOLARIS\r
+#include <sys/poll.h>\r
+#include <sys/resource.h>\r
+#include <pthread.h>\r
+#include <signal.h>\r
+#include <fcntl.h>\r
+#include <netinet/in.h>\r
+#include <netinet/tcp.h>\r
+//#include <netinet/ip.h>\r
+#include <netdb.h>\r
+#include <net/if.h>\r
+#include <net/if_arp.h>\r
+#include <readline/readline.h>\r
+#include <readline/history.h>\r
+//#include <curses.h>\r
+\r
+#ifdef UNIX_LINUX\r
+typedef void *iconv_t;\r
+iconv_t iconv_open (__const char *__tocode, __const char *__fromcode);\r
+size_t iconv (iconv_t __cd, char **__restrict __inbuf,\r
+                     size_t *__restrict __inbytesleft,\r
+                     char **__restrict __outbuf,\r
+                     size_t *__restrict __outbytesleft);\r
+int iconv_close (iconv_t __cd);\r
+#else  // UNIX_LINUX\r
+#include <iconv.h>\r
+#endif // UNIX_LINUX\r
+\r
+\r
+#ifdef UNIX_LINUX\r
+#include <netinet/if_ether.h>\r
+#include <net/ethernet.h>\r
+#include <netpacket/packet.h>\r
+#endif // UNIX_LINUX\r
+\r
+#ifdef UNIX_SOLARIS\r
+#include <sys/dlpi.h>\r
+#include <sys/stropts.h>\r
+#include <sys/stream.h>\r
+#endif // UNIX_SOLARIS\r
+\r
+#ifndef        NO_VLAN\r
+\r
+#include <Mayaqua/TunTap.h>\r
+\r
+#endif // NO_VLAN\r
+\r
+#define        closesocket(s)          close(s)\r
+\r
+#else  // Win32 のみ\r
+\r
+#include <conio.h>\r
+\r
+#endif // OS_UNIX\r
+\r
+// IPv6 サポートフラグ\r
+#ifndef        WIN32\r
+#ifndef        AF_INET6\r
+#define        NO_IPV6\r
+#endif // AF_INET6\r
+#endif // WIN32\r
+\r
+// 基本型宣言\r
+#include <Mayaqua/MayaType.h>\r
+\r
+// オブジェクト管理\r
+#include <Mayaqua/Object.h>\r
+\r
+// オブジェクト追跡\r
+#include <Mayaqua/Tracking.h>\r
+\r
+// ファイル入出力\r
+#include <Mayaqua/FileIO.h>\r
+\r
+// メモリ管理\r
+#include <Mayaqua/Memory.h>\r
+\r
+// 文字列処理\r
+#include <Mayaqua/Str.h>\r
+\r
+// 国際化文字列処理\r
+#include <Mayaqua/Internat.h>\r
+\r
+// 暗号化処理\r
+#include <Mayaqua/Encrypt.h>\r
+\r
+// セキュアトークン\r
+#include <Mayaqua/Secure.h>\r
+\r
+// カーネル\r
+#include <Mayaqua/Kernel.h>\r
+\r
+// パッケージ\r
+#include <Mayaqua/Pack.h>\r
+\r
+// 設定ファイル\r
+#include <Mayaqua/Cfg.h>\r
+\r
+// 文字列テーブル\r
+#include <Mayaqua/Table.h>\r
+\r
+// ネットワーク通信\r
+#include <Mayaqua/Network.h>\r
+\r
+// 64 bit リアルタイムクロック\r
+#include <Mayaqua/Tick64.h>\r
+\r
+// OS 依存コード\r
+#include <Mayaqua/OS.h>\r
+\r
+// Microsoft Windows 用コード\r
+#include <Mayaqua/Microsoft.h>\r
+\r
+\r
+// グローバル変数\r
+extern bool g_memcheck;\r
+extern bool g_debug;\r
+extern char *cmdline;\r
+extern wchar_t *uni_cmdline;\r
+extern bool g_little_endian;\r
+extern LOCK *tick_manual_lock;\r
+\r
+// カーネル状態\r
+#define        NUM_KERNEL_STATUS       128\r
+extern UINT64 kernel_status[NUM_KERNEL_STATUS];\r
+extern UINT64 kernel_status_max[NUM_KERNEL_STATUS];\r
+extern LOCK *kernel_status_lock[NUM_KERNEL_STATUS];\r
+extern BOOL kernel_status_inited;\r
+\r
+// カーネル状態操作マクロ\r
+#define        KS_LOCK(id)             LockKernelStatus(id)\r
+#define        KS_UNLOCK(id)   UnlockKernelStatus(id)\r
+#define        KS_GET64(id)    (kernel_status[id])\r
+#define        KS_GET(id)              ((UINT)KS_GET64(id))\r
+#define        KS_GETMAX64(id) (kernel_status_max[id])\r
+#define        KS_GETMAX(id)   ((UINT)KS_GETMAX64(id))\r
+\r
+#ifdef DONT_USE_KERNEL_STATUS\r
+// カーネルステータス操作を無効にする\r
+#define        KS_INC(id)\r
+#define        KS_DEC(id)\r
+#define        KS_ADD(id, n)\r
+#define        KS_SUB(id, n)\r
+#else  // DONT_USE_KERNEL_STATUS\r
+// カーネルステータス操作を有効にする\r
+#define        KS_INC(id)                                                      \\r
+if (kernel_status_inited) {                                    \\r
+       KS_LOCK(id);                                                    \\r
+       kernel_status[id]++;                                    \\r
+       kernel_status_max[id] = MAX(kernel_status_max[id], kernel_status[id]);  \\r
+       KS_UNLOCK(id);                                                  \\r
+}\r
+#define        KS_DEC(id)                                                      \\r
+if (kernel_status_inited) {                                    \\r
+       KS_LOCK(id);                                                    \\r
+       kernel_status[id]--;                                    \\r
+       kernel_status_max[id] = MAX(kernel_status_max[id], kernel_status[id]);  \\r
+       KS_UNLOCK(id);                                                  \\r
+}\r
+#define        KS_ADD(id, n)                                           \\r
+if (kernel_status_inited) {                                    \\r
+       KS_LOCK(id);                                                    \\r
+       kernel_status[id] += n;                                 \\r
+       kernel_status_max[id] = MAX(kernel_status_max[id], kernel_status[id]);  \\r
+       KS_UNLOCK(id);                                                  \\r
+}\r
+#define        KS_SUB(id, n)                                           \\r
+if (kernel_status_inited) {                                    \\r
+       KS_LOCK(id);                                                    \\r
+       kernel_status[id] -= n;                                 \\r
+       kernel_status_max[id] = MAX(kernel_status_max[id], kernel_status[id]);  \\r
+       KS_UNLOCK(id);                                                  \\r
+}\r
+#endif // DONT_USE_KERNEL_STATUS\r
+\r
+// カーネル状態一覧\r
+// 文字列関係\r
+#define        KS_STRCPY_COUNT                 0               // StrCpy 呼び出し回数\r
+#define        KS_STRLEN_COUNT                 1               // StrLen 呼び出し回数\r
+#define        KS_STRCHECK_COUNT               2               // StrCheck 呼び出し回数\r
+#define        KS_STRCAT_COUNT                 3               // StrCat 呼び出し回数\r
+#define        KS_FORMAT_COUNT                 4               // Format 呼び出し回数\r
+// メモリ関係\r
+#define        KS_MALLOC_COUNT                 5               // Malloc 呼び出し回数\r
+#define        KS_REALLOC_COUNT                6               // ReAlloc 呼び出し回数\r
+#define        KS_FREE_COUNT                   7               // Free 呼び出し回数\r
+#define        KS_TOTAL_MEM_SIZE               8               // これまでに確保したメモリの合計サイズ\r
+#define        KS_CURRENT_MEM_COUNT    9               // 現在確保しているメモリブロック数\r
+#define        KS_TOTAL_MEM_COUNT              10              // これまでに確保したメモリブロック数の合計\r
+#define        KS_ZERO_COUNT                   11              // Zero 呼び出し回数\r
+#define        KS_COPY_COUNT                   12              // Copy 呼び出し回数\r
+// ロック関係\r
+#define        KS_NEWLOCK_COUNT                13              // NewLock を呼び出した回数\r
+#define        KS_DELETELOCK_COUNT             14              // DeleteLock を呼び出した回数\r
+#define        KS_LOCK_COUNT                   15              // Lock を呼び出した回数\r
+#define        KS_UNLOCK_COUNT                 16              // Unlock を呼び出した回数\r
+#define        KS_CURRENT_LOCK_COUNT   17              // 現在の LOCK オブジェクト数\r
+#define        KS_CURRENT_LOCKED_COUNT 18              // 現在のロックされている LOCK オブジェクト数\r
+// カウンタ情報\r
+#define        KS_NEW_COUNTER_COUNT    19              // NewCounter を呼び出した回数\r
+#define        KS_DELETE_COUNTER_COUNT 20              // DeleteCounter を呼び出した回数\r
+#define        KS_INC_COUNT                    21              // Inc を呼び出した回数\r
+#define        KS_DEC_COUNT                    22              // Dec を呼び出した回数\r
+#define        KS_CURRENT_COUNT                23              // 現在のカウント数の合計\r
+// 参照カウンタ情報\r
+#define        KS_NEWREF_COUNT                 24              // NewRef を呼び出した回数\r
+#define        KS_FREEREF_COUNT                72              // REF オブジェクトを削除した回数\r
+#define        KS_ADDREF_COUNT                 25              // AddRef を呼び出した回数\r
+#define        KS_RELEASE_COUNT                26              // Release を呼び出した回数\r
+#define        KS_CURRENT_REF_COUNT    27              // 現在の REF オブジェクト数\r
+#define        KS_CURRENT_REFED_COUNT  28              // 現在の参照数の合計\r
+// バッファ情報\r
+#define        KS_NEWBUF_COUNT                 29              // NewBuf を呼び出した回数\r
+#define        KS_FREEBUF_COUNT                30              // FreeBuf を呼び出した回数\r
+#define        KS_CURRENT_BUF_COUNT    31              // 現在の BUF オブジェクトの数\r
+#define        KS_READ_BUF_COUNT               32              // ReadBuf を呼び出した回数\r
+#define        KS_WRITE_BUF_COUNT              33              // WriteBuf を呼び出した回数\r
+#define        KS_ADJUST_BUFSIZE_COUNT 34              // バッファサイズを調整した回数\r
+#define        KS_SEEK_BUF_COUNT               35              // SeekBuf を呼び出した回数\r
+// FIFO 情報\r
+#define        KS_NEWFIFO_COUNT                36              // NewFifo を呼び出した回数\r
+#define        KS_FREEFIFO_COUNT               37              // FIFO オブジェクトを削除した回数\r
+#define        KS_READ_FIFO_COUNT              38              // ReadFifo を呼び出した回数\r
+#define        KS_WRITE_FIFO_COUNT             39              // WriteFifo を呼び出した回数\r
+#define        KS_PEEK_FIFO_COUNT              40              // PeekFifo を呼び出した回数\r
+// リスト関係\r
+#define        KS_NEWLIST_COUNT                41              // NewList を呼び出した回数\r
+#define        KS_FREELIST_COUNT               42              // LIST オブジェクトを削除した回数\r
+#define        KS_INSERT_COUNT                 43              // Add を呼び出した回数\r
+#define        KS_DELETE_COUNT                 44              // Delete を呼び出した回数\r
+#define        KS_SORT_COUNT                   45              // Sort を呼び出した回数\r
+#define        KS_SEARCH_COUNT                 46              // Search を呼び出した回数\r
+#define        KS_TOARRAY_COUNT                47              // ToArray を呼び出した回数\r
+// キュー関係\r
+#define        KS_NEWQUEUE_COUNT               48              // NewQueue を呼び出した回数\r
+#define        KS_FREEQUEUE_COUNT              49              // QUEUE オブジェクトを削除した回数\r
+#define        KS_PUSH_COUNT                   50              // Push を呼び出した回数\r
+#define        KS_POP_COUNT                    51              // POP を呼び出した回数\r
+// スタック関係\r
+#define        KS_NEWSK_COUNT                  52              // NewSk を呼び出した回数\r
+#define        KS_FREESK_COUNT                 53              // SK オブジェクトを削除した回数\r
+#define        KS_INSERT_QUEUE_COUNT   54              // InsertQueue を呼び出した回数\r
+#define        KS_GETNEXT_COUNT                55              // GetNext を呼び出した回数\r
+// カーネル関係\r
+#define        KS_GETTIME_COUNT                56              // 時刻を取得した回数\r
+#define        KS_GETTICK_COUNT                57              // システムタイマを取得した回数\r
+#define        KS_NEWTHREAD_COUNT              58              // NewThread を呼び出した回数\r
+#define        KS_FREETHREAD_COUNT             59              // THREAD オブジェクトを削除した回数\r
+#define        KS_WAITFORTHREAD_COUNT  60              // WaitForThread を呼び出した回数\r
+#define        KS_NEWEVENT_COUNT               61              // NewEvent を呼び出した回数\r
+#define        KS_FREEEVENT_COUNT              62              // EVENT オブジェクトを削除した回数\r
+#define        KS_WAIT_COUNT                   63              // Wait を呼び出した回数\r
+#define        KS_SLEEPTHREAD_COUNT    64              // SleepThread を呼び出した回数\r
+// IO 関係\r
+#define        KS_IO_OPEN_COUNT                65              // ファイルを開いた回数\r
+#define        KS_IO_CREATE_COUNT              66              // ファイルを作成した回数\r
+#define        KS_IO_CLOSE_COUNT               67              // ファイルを閉じた回数\r
+#define        KS_IO_READ_COUNT                68              // ファイルから読み込んだ回数\r
+#define        KS_IO_WRITE_COUNT               69              // ファイルに書き込んだ回数\r
+#define        KS_IO_TOTAL_READ_SIZE   70              // ファイルから読み込んだ合計バイト数\r
+#define        KS_IO_TOTAL_WRITE_SIZE  71              // ファイルに書き込んだ合計バイト数\r
+// メモリプール関係\r
+#define        KS_MEMPOOL_MALLOC_COUNT 75              // メモリプールを確保した回数\r
+#define        KS_MEMPOOL_FREE_COUNT   73              // メモリプールを解放した回数\r
+#define        KS_MEMPOOL_CURRENT_NUM  74              // 現在のメモリプールの個数\r
+#define        KS_MEMPOOL_REALLOC_COUNT        76      // メモリプールを ReAlloc した回数\r
+\r
+\r
+// マクロ\r
+#define        IsDebug()               (g_debug)               // デバッグモード\r
+#define        IsMemCheck()    (g_memcheck)    // メモリチェックモード\r
+\r
+// 関数プロトタイプ\r
+void InitMayaqua(bool memcheck, bool debug, int argc, char **argv);\r
+void FreeMayaqua();\r
+bool IsNt();\r
+bool IsUnicode();\r
+void MayaquaDotNetMode();\r
+bool MayaquaIsDotNetMode();\r
+void MayaquaMinimalMode();\r
+bool MayaquaIsMinimalMode();\r
+bool Is64();\r
+bool Is32();\r
+bool IsIA64();\r
+bool IsX64();\r
+void InitKernelStatus();\r
+void FreeKernelStatus();\r
+void PrintDebugInformation();\r
+void LockKernelStatus(UINT id);\r
+void UnlockKernelStatus(UINT id);\r
+void PrintKernelStatus();\r
+void InitCommandLineStr(int argc, char **argv);\r
+void FreeCommandLineStr();\r
+void SetCommandLineStr(char *str);\r
+void SetCommandLineUniStr(wchar_t *str);\r
+char *GetCommandLineStr();\r
+wchar_t *GetCommandLineUniStr();\r
+void ParseCommandLineTokens();\r
+void FreeCommandLineTokens();\r
+TOKEN_LIST *GetCommandLineToken();\r
+UNI_TOKEN_LIST *GetCommandLineUniToken();\r
+void InitOsInfo();\r
+void FreeOsInfo();\r
+void Alert(char *msg, char *caption);\r
+void AlertW(wchar_t *msg, wchar_t *caption);\r
+OS_INFO *GetOsInfo();\r
+UINT GetOsType();\r
+void PrintOsInfo(OS_INFO *info);\r
+void CheckEndian();\r
+void CheckUnixTempDir();\r
+void TimeCheck();\r
+void SetHamMode();\r
+bool IsHamMode();\r
+void InitProbe();\r
+void FreeProbe();\r
+void EnableProbe(bool enable);\r
+bool IsProbeEnabled();\r
+void WriteProbe(char *filename, UINT line, char *str);\r
+void WriteProbeData(char *filename, UINT line, char *str, void *data, UINT size);\r
+USHORT CalcChecksum16(void *buf, UINT size);\r
+\r
+#ifdef OS_WIN32\r
+// インポートライブラリ (for Win32)\r
+#pragma comment(lib, "Ws2_32.lib")\r
+#pragma comment(lib, "winmm.lib")\r
+#pragma comment(lib, "kernel32.lib")\r
+#pragma comment(lib, "user32.lib")\r
+#pragma comment(lib, "gdi32.lib")\r
+#pragma comment(lib, "shell32.lib")\r
+#pragma comment(lib, "comctl32.lib")\r
+#pragma comment(lib, "dbghelp.lib")\r
+#pragma comment(lib, "Iphlpapi.lib")\r
+#pragma comment(lib, "setupapi.lib")\r
+#pragma comment(lib, "version.lib")\r
+#pragma comment(lib, "Netapi32.lib")\r
+#pragma comment(lib, "shlwapi.lib")\r
+#pragma warning( disable : 4099 )\r
+#endif // OS_WIN32\r
+\r
+// デバッグ用\r
+#ifndef        ENCRYPT_C\r
+//#define      Disconnect(s)           {Debug("Disconnect() Called: %s %u\n", __FILE__, __LINE__);Disconnect(s);}\r
+#endif\r
+\r
+\r
+#endif // MAYAQUA_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Memory.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Memory.c
new file mode 100644 (file)
index 0000000..630faf3
--- /dev/null
@@ -0,0 +1,2868 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Memory.c\r
+// メモリ管理プログラム\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <zlib/zlib.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+#define        MEMORY_SLEEP_TIME               150\r
+#define        MEMORY_MAX_RETRY                30\r
+#define        INIT_BUF_SIZE                   10240\r
+\r
+#define        FIFO_INIT_MEM_SIZE              4096\r
+#define        FIFO_REALLOC_MEM_SIZE   (65536 * 10)    // 絶妙な値\r
+#define FIFO_REALLOC_MEM_SIZE_SMALL    65536\r
+\r
+#define        INIT_NUM_RESERVED               32\r
+static UINT fifo_default_realloc_mem_size = FIFO_REALLOC_MEM_SIZE;\r
+\r
+// バイナリを検索\r
+UINT SearchBin(void *data, UINT data_start, UINT data_size, void *key, UINT key_size)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (data == NULL || key == NULL || key_size == 0 || data_size == 0 ||\r
+               (data_start >= data_size) || (data_start + key_size > data_size))\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       for (i = data_start;i < (data_size - key_size + 1);i++)\r
+       {\r
+               UCHAR *p = ((UCHAR *)data) + i;\r
+\r
+               if (Cmp(p, key, key_size) == 0)\r
+               {\r
+                       return i;\r
+               }\r
+       }\r
+\r
+       return INFINITE;\r
+}\r
+\r
+// すぐにクラッシュする\r
+void CrashNow()\r
+{\r
+       // これでとりあえずどのような OS 上でもプロセスは落ちるはずである\r
+       while (true)\r
+       {\r
+               UINT r = Rand32();\r
+               UCHAR *c = (UCHAR *)r;\r
+\r
+               *c = Rand8();\r
+       }\r
+}\r
+\r
+// バッファを候補に変換\r
+LIST *BufToCandidate(BUF *b)\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       UINT num;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       num = ReadBufInt(b);\r
+       o = NewCandidateList();\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               CANDIDATE *c;\r
+               wchar_t *s;\r
+               UINT64 sec64;\r
+               UINT len, size;\r
+               sec64 = ReadBufInt64(b);\r
+               len = ReadBufInt(b);\r
+               if (len >= 65536)\r
+               {\r
+                       break;\r
+               }\r
+               size = (len + 1) * 2;\r
+               s = ZeroMalloc(size);\r
+               if (ReadBuf(b, s, size) != size)\r
+               {\r
+                       Free(s);\r
+                       break;\r
+               }\r
+               else\r
+               {\r
+                       c = ZeroMalloc(sizeof(CANDIDATE));\r
+                       c->LastSelectedTime = sec64;\r
+                       c->Str = s;\r
+                       Add(o, c);\r
+               }\r
+       }\r
+\r
+       Sort(o);\r
+       return o;\r
+}\r
+\r
+// 候補をバッファに変換\r
+BUF *CandidateToBuf(LIST *o)\r
+{\r
+       BUF *b;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WriteBufInt(b, LIST_NUM(o));\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               CANDIDATE *c = LIST_DATA(o, i);\r
+               WriteBufInt64(b, c->LastSelectedTime);\r
+               WriteBufInt(b, UniStrLen(c->Str));\r
+               WriteBuf(b, c->Str, UniStrSize(c->Str));\r
+       }\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       return b;\r
+}\r
+\r
+// 候補の追加\r
+void AddCandidate(LIST *o, wchar_t *str, UINT num_max)\r
+{\r
+       UINT i;\r
+       bool exists;\r
+       // 引数チェック\r
+       if (o == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (num_max == 0)\r
+       {\r
+               num_max = 0x7fffffff;\r
+       }\r
+\r
+       // 文字列コピー\r
+       str = UniCopyStr(str);\r
+       UniTrim(str);\r
+\r
+       exists = false;\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               CANDIDATE *c = LIST_DATA(o, i);\r
+               if (UniStrCmpi(c->Str, str) == 0)\r
+               {\r
+                       // 既存のものを発見したので時刻を更新する\r
+                       c->LastSelectedTime = SystemTime64();\r
+                       exists = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (exists == false)\r
+       {\r
+               // 新しく挿入する\r
+               CANDIDATE *c = ZeroMalloc(sizeof(CANDIDATE));\r
+               c->LastSelectedTime = SystemTime64();\r
+               c->Str = UniCopyStr(str);\r
+               Insert(o, c);\r
+       }\r
+\r
+       // 文字列解放\r
+       Free(str);\r
+\r
+       // 現在の候補数を調べて、num_max より多ければ\r
+       // 古いものから順に削除する\r
+       if (LIST_NUM(o) > num_max)\r
+       {\r
+               while (LIST_NUM(o) > num_max)\r
+               {\r
+                       UINT index = LIST_NUM(o) - 1;\r
+                       CANDIDATE *c = LIST_DATA(o, index);\r
+                       Delete(o, c);\r
+                       Free(c->Str);\r
+                       Free(c);\r
+               }\r
+       }\r
+}\r
+\r
+// 候補の比較\r
+int ComapreCandidate(void *p1, void *p2)\r
+{\r
+       CANDIDATE *c1, *c2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       c1 = *(CANDIDATE **)p1;\r
+       c2 = *(CANDIDATE **)p2;\r
+       if (c1 == NULL || c2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (c1->LastSelectedTime > c2->LastSelectedTime)\r
+       {\r
+               return -1;\r
+       }\r
+       else if (c1->LastSelectedTime < c2->LastSelectedTime)\r
+       {\r
+               return 1;\r
+       }\r
+       else\r
+       {\r
+               return UniStrCmpi(c1->Str, c2->Str);\r
+       }\r
+}\r
+\r
+// 候補リストの解放\r
+void FreeCandidateList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               CANDIDATE *c = LIST_DATA(o, i);\r
+               Free(c->Str);\r
+               Free(c);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// 新しい候補リストの作成\r
+LIST *NewCandidateList()\r
+{\r
+       return NewList(ComapreCandidate);\r
+}\r
+\r
+// 指定したアドレスがすべてゼロかどうか調べる\r
+bool IsZero(void *data, UINT size)\r
+{\r
+       UINT i;\r
+       UCHAR *c = (UCHAR *)data;\r
+       // 引数チェック\r
+       if (data == NULL || size == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       for (i = 0;i < size;i++)\r
+       {\r
+               if (c[i] != 0)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// データを展開する\r
+UINT Uncompress(void *dst, UINT dst_size, void *src, UINT src_size)\r
+{\r
+       unsigned long dst_size_long = dst_size;\r
+       // 引数チェック\r
+       if (dst == NULL || dst_size_long == 0 || src == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (uncompress(dst, &dst_size_long, src, src_size) != Z_OK)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return (UINT)dst_size_long;\r
+}\r
+\r
+// データを圧縮する\r
+UINT Compress(void *dst, UINT dst_size, void *src, UINT src_size)\r
+{\r
+       return CompressEx(dst, dst_size, src, src_size, Z_DEFAULT_COMPRESSION);\r
+}\r
+\r
+// データをオプション付きで圧縮する\r
+UINT CompressEx(void *dst, UINT dst_size, void *src, UINT src_size, UINT level)\r
+{\r
+       unsigned long dst_size_long = dst_size;\r
+       // 引数チェック\r
+       if (dst == NULL || dst_size_long == 0 || src == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (compress2(dst, &dst_size_long, src, src_size, (int)level) != Z_OK)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return dst_size_long;\r
+}\r
+\r
+// src_size データを圧縮した場合の最大サイズを取得する\r
+UINT CalcCompress(UINT src_size)\r
+{\r
+       // あっ これは いい加減!\r
+       return src_size * 2 + 100;\r
+}\r
+\r
+// スタックの作成\r
+SK *NewSk()\r
+{\r
+       return NewSkEx(false);\r
+}\r
+SK *NewSkEx(bool no_compact)\r
+{\r
+       SK *s;\r
+\r
+       s = Malloc(sizeof(SK));\r
+       s->lock = NewLock();\r
+       s->ref = NewRef();\r
+       s->num_item = 0;\r
+       s->num_reserved = INIT_NUM_RESERVED;\r
+       s->p = Malloc(sizeof(void *) * s->num_reserved);\r
+       s->no_compact = no_compact;\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackNewObj(POINTER_TO_UINT64(s), "SK", 0);\r
+#endif // DONT_USE_KERNEL_STATUS\r
+\r
+       // KS\r
+       KS_INC(KS_NEWSK_COUNT);\r
+\r
+       return s;\r
+}\r
+\r
+// スタックの解放\r
+void ReleaseSk(SK *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(s->ref) == 0)\r
+       {\r
+               CleanupSk(s);\r
+       }\r
+}\r
+\r
+// スタックのクリーンアップ\r
+void CleanupSk(SK *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メモリ解放\r
+       Free(s->p);\r
+       DeleteLock(s->lock);\r
+       Free(s);\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackDeleteObj(POINTER_TO_UINT64(s));\r
+#endif // DONT_USE_KERNEL_STATUS\r
+\r
+       // KS\r
+       KS_INC(KS_FREESK_COUNT);\r
+}\r
+\r
+// スタックのロック\r
+void LockSk(SK *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(s->lock);\r
+}\r
+\r
+// スタックのロック解除\r
+void UnlockSk(SK *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Unlock(s->lock);\r
+}\r
+\r
+// スタックの Push\r
+void Push(SK *s, void *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       i = s->num_item;\r
+       s->num_item++;\r
+\r
+       // サイズ拡大\r
+       if (s->num_item > s->num_reserved)\r
+       {\r
+               s->num_reserved = s->num_reserved * 2;\r
+               s->p = ReAlloc(s->p, sizeof(void *) * s->num_reserved);\r
+       }\r
+       s->p[i] = p;\r
+\r
+       // KS\r
+       KS_INC(KS_PUSH_COUNT);\r
+}\r
+\r
+// スタックの Pop\r
+void *Pop(SK *s)\r
+{\r
+       void *ret;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (s->num_item == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+       ret = s->p[s->num_item - 1];\r
+       s->num_item--;\r
+\r
+       // サイズ縮小\r
+       if (s->no_compact == false)\r
+       {\r
+               // no_compact が true の場合は縮小しない\r
+               if ((s->num_item * 2) <= s->num_reserved)\r
+               {\r
+                       if (s->num_reserved >= (INIT_NUM_RESERVED * 2))\r
+                       {\r
+                               s->num_reserved = s->num_reserved / 2;\r
+                               s->p = ReAlloc(s->p, sizeof(void *) * s->num_reserved);\r
+                       }\r
+               }\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_POP_COUNT);\r
+\r
+       return ret;\r
+}\r
+\r
+// 1 つ取得\r
+void *GetNext(QUEUE *q)\r
+{\r
+       void *p = NULL;\r
+       // 引数チェック\r
+       if (q == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (q->num_item == 0)\r
+       {\r
+               // アイテム無し\r
+               return NULL;\r
+       }\r
+\r
+       // FIFO から読み込む\r
+       ReadFifo(q->fifo, &p, sizeof(void *));\r
+       q->num_item--;\r
+\r
+       // KS\r
+       KS_INC(KS_GETNEXT_COUNT);\r
+\r
+       return p;\r
+}\r
+\r
+// キューに Int 型を挿入\r
+void InsertQueueInt(QUEUE *q, UINT value)\r
+{\r
+       UINT *p;\r
+       // 引数チェック\r
+       if (q == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = Clone(&value, sizeof(UINT));\r
+\r
+       InsertQueue(q, p);\r
+}\r
+\r
+// キューに挿入\r
+void InsertQueue(QUEUE *q, void *p)\r
+{\r
+       // 引数チェック\r
+       if (q == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // FIFO に書き込む\r
+       WriteFifo(q->fifo, &p, sizeof(void *));\r
+\r
+       q->num_item++;\r
+\r
+       // KS\r
+       KS_INC(KS_INSERT_QUEUE_COUNT);\r
+}\r
+\r
+// キューのロック\r
+void LockQueue(QUEUE *q)\r
+{\r
+       // 引数チェック\r
+       if (q == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(q->lock);\r
+}\r
+\r
+// キューのロック解除\r
+void UnlockQueue(QUEUE *q)\r
+{\r
+       // 引数チェック\r
+       if (q == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Unlock(q->lock);\r
+}\r
+\r
+// キューの解放\r
+void ReleaseQueue(QUEUE *q)\r
+{\r
+       // 引数チェック\r
+       if (q == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (q->ref == NULL || Release(q->ref) == 0)\r
+       {\r
+               CleanupQueue(q);\r
+       }\r
+}\r
+\r
+// キューのクリーンアップ\r
+void CleanupQueue(QUEUE *q)\r
+{\r
+       // 引数チェック\r
+       if (q == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メモリ解放\r
+       ReleaseFifo(q->fifo);\r
+       DeleteLock(q->lock);\r
+       Free(q);\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackDeleteObj(POINTER_TO_UINT64(q));\r
+#endif // DONT_USE_KERNEL_STATUS\r
+\r
+       // KS\r
+       KS_INC(KS_FREEQUEUE_COUNT);\r
+}\r
+\r
+// キューの作成\r
+QUEUE *NewQueue()\r
+{\r
+       QUEUE *q;\r
+\r
+       q = ZeroMalloc(sizeof(QUEUE));\r
+       q->lock = NewLock();\r
+       q->ref = NewRef();\r
+       q->num_item = 0;\r
+       q->fifo = NewFifo();\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackNewObj(POINTER_TO_UINT64(q), "QUEUE", 0);\r
+#endif // DONT_USE_KERNEL_STATUS\r
+\r
+       // KS\r
+       KS_INC(KS_NEWQUEUE_COUNT);\r
+\r
+       return q;\r
+}\r
+QUEUE *NewQueueFast()\r
+{\r
+       QUEUE *q;\r
+\r
+       q = ZeroMalloc(sizeof(QUEUE));\r
+       q->lock = NULL;\r
+       q->ref = NULL;\r
+       q->num_item = 0;\r
+       q->fifo = NewFifoFast();\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackNewObj(POINTER_TO_UINT64(q), "QUEUE", 0);\r
+#endif // DONT_USE_KERNEL_STATUS\r
+\r
+       // KS\r
+       KS_INC(KS_NEWQUEUE_COUNT);\r
+\r
+       return q;\r
+}\r
+\r
+// リストに比較関数をセットする\r
+void SetCmp(LIST *o, COMPARE *cmp)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || cmp == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (o->cmp != cmp)\r
+       {\r
+               o->cmp = cmp;\r
+               o->sorted = false;\r
+       }\r
+}\r
+\r
+// リストのクローン\r
+LIST *CloneList(LIST *o)\r
+{\r
+       LIST *n = NewList(o->cmp);\r
+\r
+       // メモリ再確保\r
+       Free(n->p);\r
+       n->p = ToArray(o);\r
+       n->num_item = n->num_reserved = LIST_NUM(o);\r
+       n->sorted = o->sorted;\r
+\r
+       return n;\r
+}\r
+\r
+// リストを配列にコピー\r
+void CopyToArray(LIST *o, void *p)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_TOARRAY_COUNT);\r
+\r
+       Copy(p, o->p, sizeof(void *) * o->num_item);\r
+}\r
+\r
+// リストを配列化する\r
+void *ToArray(LIST *o)\r
+{\r
+       return ToArrayEx(o, false);\r
+}\r
+void *ToArrayEx(LIST *o, bool fast)\r
+{\r
+       void *p;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // メモリ確保\r
+       if (fast == false)\r
+       {\r
+               p = Malloc(sizeof(void *) * LIST_NUM(o));\r
+       }\r
+       else\r
+       {\r
+               p = MallocFast(sizeof(void *) * LIST_NUM(o));\r
+       }\r
+       // コピー\r
+       CopyToArray(o, p);\r
+\r
+       return p;\r
+}\r
+\r
+// リストのサーチ\r
+void *Search(LIST *o, void *target)\r
+{\r
+       void **ret;\r
+       // 引数チェック\r
+       if (o == NULL || target == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (o->cmp == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // ソートのチェック\r
+       if (o->sorted == false)\r
+       {\r
+               // 未ソートなのでソートを行う\r
+               Sort(o);\r
+       }\r
+\r
+       // なんだ C ライブラリのバイナリサーチ関数を呼んでいるだけか\r
+       ret = (void **)bsearch(&target, o->p, o->num_item, sizeof(void *),\r
+               (int(*)(const void *, const void *))o->cmp);\r
+\r
+       // KS\r
+       KS_INC(KS_SEARCH_COUNT);\r
+\r
+       if (ret != NULL)\r
+       {\r
+               return *ret;\r
+       }\r
+       else\r
+       {\r
+               return NULL;\r
+       }\r
+}\r
+\r
+// リストに項目を挿入\r
+// 本当はもうちょっとましなデータ構造 & アルゴリズムにするべき\r
+void Insert(LIST *o, void *p)\r
+{\r
+       int low, high, middle;\r
+       UINT pos;\r
+       int i;\r
+       // 引数チェック\r
+       if (o == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (o->cmp == NULL)\r
+       {\r
+               // ソート関数が無い場合は単純に追加する\r
+               Add(o, p);\r
+               return;\r
+       }\r
+\r
+       // ソートされていない場合は直ちにソートする\r
+       if (o->sorted == false)\r
+       {\r
+               Sort(o);\r
+       }\r
+\r
+       low = 0;\r
+       high = LIST_NUM(o) - 1;\r
+\r
+       pos = INFINITE;\r
+\r
+       while (low <= high)\r
+       {\r
+               int ret;\r
+\r
+               middle = (low + high) / 2;\r
+               ret = o->cmp(&(o->p[middle]), &p);\r
+\r
+               if (ret == 0)\r
+               {\r
+                       pos = middle;\r
+                       break;\r
+               }\r
+               else if (ret > 0)\r
+               {\r
+                       high = middle - 1;\r
+               }\r
+               else\r
+               {\r
+                       low = middle + 1;\r
+               }\r
+       }\r
+\r
+       if (pos == INFINITE)\r
+       {\r
+               pos = low;\r
+       }\r
+\r
+       o->num_item++;\r
+       if (o->num_item > o->num_reserved)\r
+       {\r
+               o->num_reserved *= 2;\r
+               o->p = ReAlloc(o->p, sizeof(void *) * o->num_reserved);\r
+       }\r
+\r
+       if (LIST_NUM(o) >= 2)\r
+       {\r
+               for (i = (LIST_NUM(o) - 2);i >= (int)pos;i--)\r
+               {\r
+                       o->p[i + 1] = o->p[i];\r
+               }\r
+       }\r
+\r
+       o->p[pos] = p;\r
+\r
+       // KS\r
+       KS_INC(KS_INSERT_COUNT);\r
+}\r
+\r
+// ソートフラグの設定\r
+void SetSortFlag(LIST *o, bool sorted)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o->sorted = sorted;\r
+}\r
+\r
+// リストのソート\r
+void Sort(LIST *o)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || o->cmp == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       qsort(o->p, o->num_item, sizeof(void *), (int(*)(const void *, const void *))o->cmp);\r
+       o->sorted = true;\r
+\r
+       // KS\r
+       KS_INC(KS_SORT_COUNT);\r
+}\r
+\r
+// ある文字列項目がリスト内に存在しているかどうか調べる (Unicode 版)\r
+bool IsInListUniStr(LIST *o, wchar_t *str)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               wchar_t *s = LIST_DATA(o, i);\r
+\r
+               if (UniStrCmpi(s, str) == 0)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// リスト内のポインタを置換する\r
+bool ReplaceListPointer(LIST *o, void *oldptr, void *newptr)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL || oldptr == NULL || newptr == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               void *p = LIST_DATA(o, i);\r
+\r
+               if (p == oldptr)\r
+               {\r
+                       o->p[i] = newptr;\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// ある文字列項目がリスト内に存在しているかどうか調べる\r
+bool IsInListStr(LIST *o, char *str)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               char *s = LIST_DATA(o, i);\r
+\r
+               if (StrCmpi(s, str) == 0)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// リスト内を UINT 形式のポインタで走査してポインタを取得する\r
+void *ListKeyToPointer(LIST *o, UINT key)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL || key == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               void *p = LIST_DATA(o, i);\r
+\r
+               if (POINTER_TO_KEY(p) == key)\r
+               {\r
+                       return p;\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// あるキーがリスト内に存在するかどうか調べる\r
+bool IsInListKey(LIST *o, UINT key)\r
+{\r
+       void *p;\r
+       // 引数チェック\r
+       if (o == NULL || key == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = ListKeyToPointer(o, key);\r
+       if (p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ある項目がリスト内に存在するかどうか調べる\r
+bool IsInList(LIST *o, void *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               void *q = LIST_DATA(o, i);\r
+               if (p == q)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// リストへの要素の追加\r
+void Add(LIST *o, void *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       i = o->num_item;\r
+       o->num_item++;\r
+\r
+       if (o->num_item > o->num_reserved)\r
+       {\r
+               o->num_reserved = o->num_reserved * 2;\r
+               o->p = ReAlloc(o->p, sizeof(void *) * o->num_reserved);\r
+       }\r
+\r
+       o->p[i] = p;\r
+       o->sorted = false;\r
+\r
+       // KS\r
+       KS_INC(KS_INSERT_COUNT);\r
+}\r
+\r
+// リストからキーで指定した要素の削除\r
+bool DeleteKey(LIST *o, UINT key)\r
+{\r
+       void *p;\r
+       // 引数チェック\r
+       if (o == NULL || key == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = ListKeyToPointer(o, key);\r
+       if (p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return Delete(o, p);\r
+}\r
+\r
+// リストから要素の削除\r
+bool Delete(LIST *o, void *p)\r
+{\r
+       UINT i, n;\r
+       // 引数チェック\r
+       if (o == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < o->num_item;i++)\r
+       {\r
+               if (o->p[i] == p)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+       if (i == o->num_item)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       n = i;\r
+       for (i = n;i < (o->num_item - 1);i++)\r
+       {\r
+               o->p[i] = o->p[i + 1];\r
+       }\r
+       o->num_item--;\r
+       if ((o->num_item * 2) <= o->num_reserved)\r
+       {\r
+               if (o->num_reserved > (INIT_NUM_RESERVED * 2))\r
+               {\r
+                       o->num_reserved = o->num_reserved / 2;\r
+                       o->p = ReAlloc(o->p, sizeof(void *) * o->num_reserved);\r
+               }\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_DELETE_COUNT);\r
+\r
+       return true;\r
+}\r
+\r
+// リストからすべての要素の削除\r
+void DeleteAll(LIST *o)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o->num_item = 0;\r
+       o->num_reserved = INIT_NUM_RESERVED;\r
+       o->p = ReAlloc(o->p, sizeof(void *) * INIT_NUM_RESERVED);\r
+}\r
+\r
+// リストのロック\r
+void LockList(LIST *o)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(o->lock);\r
+}\r
+\r
+// リストのロック解除\r
+void UnlockList(LIST *o)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Unlock(o->lock);\r
+}\r
+\r
+// リストの解放\r
+void ReleaseList(LIST *o)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (o->ref == NULL || Release(o->ref) == 0)\r
+       {\r
+               CleanupList(o);\r
+       }\r
+}\r
+\r
+// リストのクリーンアップ\r
+void CleanupList(LIST *o)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(o->p);\r
+       if (o->lock != NULL)\r
+       {\r
+               DeleteLock(o->lock);\r
+       }\r
+       Free(o);\r
+\r
+       // KS\r
+       KS_INC(KS_FREELIST_COUNT);\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackDeleteObj(POINTER_TO_UINT64(o));\r
+#endif // DONT_USE_KERNEL_STATUS\r
+}\r
+\r
+// 文字列比較関数 (Unicode)\r
+int CompareUniStr(void *p1, void *p2)\r
+{\r
+       wchar_t *s1, *s2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       s1 = *(wchar_t **)p1;\r
+       s2 = *(wchar_t **)p2;\r
+\r
+       return UniStrCmp(s1, s2);\r
+}\r
+\r
+// 文字列をリストに挿入する\r
+bool InsertStr(LIST *o, char *str)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (Search(o, str) == NULL)\r
+       {\r
+               Insert(o, str);\r
+\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// 文字列比較関数\r
+int CompareStr(void *p1, void *p2)\r
+{\r
+       char *s1, *s2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       s1 = *(char **)p1;\r
+       s2 = *(char **)p2;\r
+\r
+       return StrCmpi(s1, s2);\r
+}\r
+\r
+// 高速リスト (ロック無し) の作成\r
+LIST *NewListFast(COMPARE *cmp)\r
+{\r
+       return NewListEx(cmp, true);\r
+}\r
+\r
+// リストの作成\r
+LIST *NewList(COMPARE *cmp)\r
+{\r
+       return NewListEx(cmp, false);\r
+}\r
+LIST *NewListEx(COMPARE *cmp, bool fast)\r
+{\r
+       return NewListEx2(cmp, fast, false);\r
+}\r
+LIST *NewListEx2(COMPARE *cmp, bool fast, bool fast_malloc)\r
+{\r
+       LIST *o;\r
+\r
+       if (fast_malloc == false)\r
+       {\r
+               o = Malloc(sizeof(LIST));\r
+       }\r
+       else\r
+       {\r
+               o = MallocFast(sizeof(LIST));\r
+       }\r
+\r
+       if (fast == false)\r
+       {\r
+               o->lock = NewLock();\r
+               o->ref = NewRef();\r
+       }\r
+       else\r
+       {\r
+               o->lock = NULL;\r
+               o->ref = NULL;\r
+       }\r
+       o->num_item = 0;\r
+       o->num_reserved = INIT_NUM_RESERVED;\r
+\r
+       if (fast_malloc == false)\r
+       {\r
+               o->p = Malloc(sizeof(void *) * o->num_reserved);\r
+       }\r
+       else\r
+       {\r
+               o->p = MallocFast(sizeof(void *) * o->num_reserved);\r
+       }\r
+\r
+       o->cmp = cmp;\r
+       o->sorted = true;\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackNewObj(POINTER_TO_UINT64(o), "LIST", 0);\r
+#endif //DONT_USE_KERNEL_STATUS\r
+\r
+       // KS\r
+       KS_INC(KS_NEWLIST_COUNT);\r
+\r
+       return o;\r
+}\r
+\r
+// FIFO から peek する\r
+UINT PeekFifo(FIFO *f, void *p, UINT size)\r
+{\r
+       UINT read_size;\r
+       if (f == NULL || size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_PEEK_FIFO_COUNT);\r
+\r
+       read_size = MIN(size, f->size);\r
+       if (read_size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (p != NULL)\r
+       {\r
+               Copy(p, (UCHAR *)f->p + f->pos, read_size);\r
+       }\r
+\r
+       return read_size;\r
+}\r
+\r
+// FIFO から読み取る\r
+UINT ReadFifo(FIFO *f, void *p, UINT size)\r
+{\r
+       UINT read_size;\r
+       // 引数チェック\r
+       if (f == NULL || size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       read_size = MIN(size, f->size);\r
+       if (read_size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+       if (p != NULL)\r
+       {\r
+               Copy(p, (UCHAR *)f->p + f->pos, read_size);\r
+       }\r
+       f->pos += read_size;\r
+       f->size -= read_size;\r
+\r
+       if (f->size == 0)\r
+       {\r
+               f->pos = 0;\r
+       }\r
+\r
+       // メモリの詰め直し\r
+       if (f->pos >= FIFO_INIT_MEM_SIZE &&\r
+               f->memsize >= f->realloc_mem_size &&\r
+               (f->memsize / 2) > f->size)\r
+       {\r
+               void *new_p;\r
+               UINT new_size;\r
+\r
+               new_size = MAX(f->memsize / 2, FIFO_INIT_MEM_SIZE);\r
+               new_p = Malloc(new_size);\r
+               Copy(new_p, (UCHAR *)f->p + f->pos, f->size);\r
+\r
+               Free(f->p);\r
+\r
+               f->memsize = new_size;\r
+               f->p = new_p;\r
+               f->pos = 0;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_READ_FIFO_COUNT);\r
+\r
+       return read_size;\r
+}\r
+\r
+// FIFO に書き込む\r
+void WriteFifo(FIFO *f, void *p, UINT size)\r
+{\r
+       UINT i, need_size;\r
+       bool realloc_flag;\r
+       // 引数チェック\r
+       if (f == NULL || size == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       i = f->size;\r
+       f->size += size;\r
+       need_size = f->pos + f->size;\r
+       realloc_flag = false;\r
+\r
+       // メモリ拡張\r
+       while (need_size > f->memsize)\r
+       {\r
+               f->memsize = MAX(f->memsize, FIFO_INIT_MEM_SIZE) * 3;\r
+               realloc_flag = true;\r
+       }\r
+\r
+       if (realloc_flag)\r
+       {\r
+               f->p = ReAlloc(f->p, f->memsize);\r
+       }\r
+\r
+       // データ書き込み\r
+       if (p != NULL)\r
+       {\r
+               Copy((UCHAR *)f->p + f->pos + i, p, size);\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_WRITE_FIFO_COUNT);\r
+}\r
+\r
+// FIFO のクリア\r
+void ClearFifo(FIFO *f)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       f->size = f->pos = 0;\r
+       f->memsize = FIFO_INIT_MEM_SIZE;\r
+       f->p = ReAlloc(f->p, f->memsize);\r
+}\r
+\r
+// FIFO のサイズ取得\r
+UINT FifoSize(FIFO *f)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return f->size;\r
+}\r
+\r
+// FIFO のロック\r
+void LockFifo(FIFO *f)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(f->lock);\r
+}\r
+\r
+// FIFO のロック解除\r
+void UnlockFifo(FIFO *f)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Unlock(f->lock);\r
+}\r
+\r
+// FIFO の解放\r
+void ReleaseFifo(FIFO *f)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (f->ref == NULL || Release(f->ref) == 0)\r
+       {\r
+               CleanupFifo(f);\r
+       }\r
+}\r
+\r
+// FIFO のクリーンアップ\r
+void CleanupFifo(FIFO *f)\r
+{\r
+       // 引数チェック\r
+       if (f == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       DeleteLock(f->lock);\r
+       Free(f->p);\r
+       Free(f);\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackDeleteObj(POINTER_TO_UINT64(f));\r
+#endif //DONT_USE_KERNEL_STATUS\r
+\r
+       // KS\r
+       KS_INC(KS_FREEFIFO_COUNT);\r
+}\r
+\r
+// FIFO システムの初期化\r
+void InitFifo()\r
+{\r
+       fifo_default_realloc_mem_size = FIFO_REALLOC_MEM_SIZE;\r
+}\r
+\r
+// FIFO の作成\r
+FIFO *NewFifo()\r
+{\r
+       return NewFifoEx(0, false);\r
+}\r
+FIFO *NewFifoFast()\r
+{\r
+       return NewFifoEx(0, true);\r
+}\r
+FIFO *NewFifoEx(UINT realloc_mem_size, bool fast)\r
+{\r
+       FIFO *f;\r
+\r
+       // メモリ確保\r
+       f = Malloc(sizeof(FIFO));\r
+\r
+       if (fast == false)\r
+       {\r
+               f->lock = NewLock();\r
+               f->ref = NewRef();\r
+       }\r
+       else\r
+       {\r
+               f->lock = NULL;\r
+               f->ref = NULL;\r
+       }\r
+\r
+       f->size = f->pos = 0;\r
+       f->memsize = FIFO_INIT_MEM_SIZE;\r
+       f->p = Malloc(FIFO_INIT_MEM_SIZE);\r
+\r
+       if (realloc_mem_size == 0)\r
+       {\r
+               realloc_mem_size = fifo_default_realloc_mem_size;\r
+       }\r
+\r
+       f->realloc_mem_size = realloc_mem_size;\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackNewObj(POINTER_TO_UINT64(f), "FIFO", 0);\r
+#endif // DONT_USE_KERNEL_STATUS\r
+\r
+       // KS\r
+       KS_INC(KS_NEWFIFO_COUNT);\r
+\r
+       return f;\r
+}\r
+\r
+// FIFO のデフォルトのメモリ再確保サイズを取得する\r
+UINT GetFifoDefaultReallocMemSize()\r
+{\r
+       return fifo_default_realloc_mem_size;\r
+}\r
+\r
+// FIFO のデフォルトのメモリ再確保サイズを設定する\r
+void SetFifoDefaultReallocMemSize(UINT size)\r
+{\r
+       if (size == 0)\r
+       {\r
+               size = FIFO_REALLOC_MEM_SIZE;\r
+       }\r
+\r
+       fifo_default_realloc_mem_size = size;\r
+}\r
+\r
+// バッファをファイルから読み込む\r
+BUF *FileToBuf(IO *o)\r
+{\r
+       UCHAR hash1[MD5_SIZE], hash2[MD5_SIZE];\r
+       UINT size;\r
+       void *buf;\r
+       BUF *b;\r
+\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // サイズを読み込む\r
+       if (FileRead(o, &size, sizeof(size)) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+       size = Endian32(size);\r
+\r
+       if (size > FileSize(o))\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // ハッシュを読み込む\r
+       if (FileRead(o, hash1, sizeof(hash1)) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // バッファを読み込む\r
+       buf = Malloc(size);\r
+       if (FileRead(o, buf, size) == false)\r
+       {\r
+               Free(buf);\r
+               return NULL;\r
+       }\r
+\r
+       // ハッシュをとる\r
+       Hash(hash2, buf, size, false);\r
+\r
+       // ハッシュを比較する\r
+       if (Cmp(hash1, hash2, sizeof(hash1)) != 0)\r
+       {\r
+               // ハッシュが異なる\r
+               Free(buf);\r
+               return NULL;\r
+       }\r
+\r
+       // バッファを作成する\r
+       b = NewBuf();\r
+       WriteBuf(b, buf, size);\r
+       Free(buf);\r
+       b->Current = 0;\r
+\r
+       return b;\r
+}\r
+\r
+// ダンプファイルをバッファに読み込む\r
+BUF *ReadDump(char *filename)\r
+{\r
+       IO *o;\r
+       BUF *b;\r
+       UINT size;\r
+       void *data;\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = FileOpen(filename, false);\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = FileSize(o);\r
+       data = Malloc(size);\r
+       FileRead(o, data, size);\r
+       FileClose(o);\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, data, size);\r
+       b->Current = 0;\r
+       Free(data);\r
+\r
+       return b;\r
+}\r
+BUF *ReadDumpW(wchar_t *filename)\r
+{\r
+       IO *o;\r
+       BUF *b;\r
+       UINT size;\r
+       void *data;\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = FileOpenW(filename, false);\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = FileSize(o);\r
+       data = Malloc(size);\r
+       FileRead(o, data, size);\r
+       FileClose(o);\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, data, size);\r
+       b->Current = 0;\r
+       Free(data);\r
+\r
+       return b;\r
+}\r
+\r
+// バッファ内容をファイルにダンプする\r
+bool DumpBuf(BUF *b, char *filename)\r
+{\r
+       IO *o;\r
+       // 引数チェック\r
+       if (b == NULL || filename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       o = FileCreate(filename);\r
+       if (o == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       FileWrite(o, b->Buf, b->Size);\r
+       FileClose(o);\r
+\r
+       return true;\r
+}\r
+bool DumpBufW(BUF *b, wchar_t *filename)\r
+{\r
+       IO *o;\r
+       // 引数チェック\r
+       if (b == NULL || filename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       o = FileCreateW(filename);\r
+       if (o == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       FileWrite(o, b->Buf, b->Size);\r
+       FileClose(o);\r
+\r
+       return true;\r
+}\r
+\r
+// バッファをファイルに書き込む\r
+bool BufToFile(IO *o, BUF *b)\r
+{\r
+       UCHAR hash[MD5_SIZE];\r
+       UINT size;\r
+\r
+       // 引数チェック\r
+       if (o == NULL || b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // データをハッシュする\r
+       Hash(hash, b->Buf, b->Size, false);\r
+\r
+       size = Endian32(b->Size);\r
+\r
+       // サイズを書き込む\r
+       if (FileWrite(o, &size, sizeof(size)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ハッシュを書き込む\r
+       if (FileWrite(o, hash, sizeof(hash)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // データを書き込む\r
+       if (FileWrite(o, b->Buf, b->Size) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// バッファの作成\r
+BUF *NewBuf()\r
+{\r
+       BUF *b;\r
+\r
+       // メモリ確保\r
+       b = Malloc(sizeof(BUF));\r
+       b->Buf = Malloc(INIT_BUF_SIZE);\r
+       b->Size = 0;\r
+       b->Current = 0;\r
+       b->SizeReserved = INIT_BUF_SIZE;\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackNewObj(POINTER_TO_UINT64(b), "BUF", 0);\r
+#endif // DONT_USE_KERNEL_STATUS\r
+\r
+       // KS\r
+       KS_INC(KS_NEWBUF_COUNT);\r
+       KS_INC(KS_CURRENT_BUF_COUNT);\r
+\r
+       return b;\r
+}\r
+\r
+// バッファのクリア\r
+void ClearBuf(BUF *b)\r
+{\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       b->Size = 0;\r
+       b->Current = 0;\r
+}\r
+\r
+// バッファへ書き込み\r
+void WriteBuf(BUF *b, void *buf, UINT size)\r
+{\r
+       UINT new_size;\r
+       // 引数チェック\r
+       if (b == NULL || buf == NULL || size == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       new_size = b->Current + size;\r
+       if (new_size > b->Size)\r
+       {\r
+               // サイズを調整する\r
+               AdjustBufSize(b, new_size);\r
+       }\r
+       if (b->Buf != NULL)\r
+       {\r
+               Copy((UCHAR *)b->Buf + b->Current, buf, size);\r
+       }\r
+       b->Current += size;\r
+       b->Size = new_size;\r
+\r
+       // KS\r
+       KS_INC(KS_WRITE_BUF_COUNT);\r
+}\r
+\r
+// バッファに文字列を追記\r
+void AddBufStr(BUF *b, char *str)\r
+{\r
+       // 引数チェック\r
+       if (b == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       WriteBuf(b, str, StrLen(str));\r
+}\r
+\r
+// バッファに 1 行書き込む\r
+void WriteBufLine(BUF *b, char *str)\r
+{\r
+       char *crlf = "\r\n";\r
+       // 引数チェック\r
+       if (b == NULL || str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       WriteBuf(b, str, StrLen(str));\r
+       WriteBuf(b, crlf, StrLen(crlf));\r
+}\r
+\r
+// バッファに文字列を書き込む\r
+bool WriteBufStr(BUF *b, char *str)\r
+{\r
+       UINT len;\r
+       // 引数チェック\r
+       if (b == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 文字列長\r
+       len = StrLen(str);\r
+       if (WriteBufInt(b, len + 1) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 文字列本体\r
+       WriteBuf(b, str, len);\r
+\r
+       return true;\r
+}\r
+\r
+// バッファから文字列を読み込む\r
+bool ReadBufStr(BUF *b, char *str, UINT size)\r
+{\r
+       UINT len;\r
+       UINT read_size;\r
+       // 引数チェック\r
+       if (b == NULL || str == NULL || size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 文字列長を読み込む\r
+       len = ReadBufInt(b);\r
+       if (len == 0)\r
+       {\r
+               return false;\r
+       }\r
+       len--;\r
+       if (len <= (size - 1))\r
+       {\r
+               size = len + 1;\r
+       }\r
+\r
+       read_size = MIN(len, (size - 1));\r
+\r
+       // 文字列本体を読み込む\r
+       if (ReadBuf(b, str, read_size) != read_size)\r
+       {\r
+               return false;\r
+       }\r
+       if (read_size < len)\r
+       {\r
+               ReadBuf(b, NULL, len - read_size);\r
+       }\r
+       str[read_size] = 0;\r
+\r
+       return true;\r
+}\r
+\r
+// バッファに 64 bit 整数を書き込む\r
+bool WriteBufInt64(BUF *b, UINT64 value)\r
+{\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       value = Endian64(value);\r
+\r
+       WriteBuf(b, &value, sizeof(UINT64));\r
+       return true;\r
+}\r
+\r
+// バッファに整数を書き込む\r
+bool WriteBufInt(BUF *b, UINT value)\r
+{\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       value = Endian32(value);\r
+\r
+       WriteBuf(b, &value, sizeof(UINT));\r
+       return true;\r
+}\r
+\r
+// バッファから 64bit 整数を読み込む\r
+UINT64 ReadBufInt64(BUF *b)\r
+{\r
+       UINT64 value;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (ReadBuf(b, &value, sizeof(UINT64)) != sizeof(UINT64))\r
+       {\r
+               return 0;\r
+       }\r
+       return Endian64(value);\r
+}\r
+\r
+// バッファから整数を読み込む\r
+UINT ReadBufInt(BUF *b)\r
+{\r
+       UINT value;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (ReadBuf(b, &value, sizeof(UINT)) != sizeof(UINT))\r
+       {\r
+               return 0;\r
+       }\r
+       return Endian32(value);\r
+}\r
+\r
+// バッファにバッファを書き込み\r
+void WriteBufBuf(BUF *b, BUF *bb)\r
+{\r
+       // 引数チェック\r
+       if (b == NULL || bb == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       WriteBuf(b, bb->Buf, bb->Size);\r
+}\r
+\r
+// バッファからバッファを読み込み\r
+BUF *ReadBufFromBuf(BUF *b, UINT size)\r
+{\r
+       BUF *ret;\r
+       UCHAR *data;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       data = Malloc(size);\r
+       if (ReadBuf(b, data, size) != size)\r
+       {\r
+               Free(data);\r
+               return NULL;\r
+       }\r
+\r
+       ret = NewBuf();\r
+       WriteBuf(ret, data, size);\r
+       SeekBuf(ret, 0, 0);\r
+\r
+       Free(data);\r
+\r
+       return ret;\r
+}\r
+\r
+// バッファから読み込み\r
+UINT ReadBuf(BUF *b, void *buf, UINT size)\r
+{\r
+       UINT size_read;\r
+       // 引数チェック\r
+       if (b == NULL || size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (b->Buf == NULL)\r
+       {\r
+               Zero(buf, size);\r
+               return 0;\r
+       }\r
+       size_read = size;\r
+       if ((b->Current + size) >= b->Size)\r
+       {\r
+               size_read = b->Size - b->Current;\r
+               if (buf != NULL)\r
+               {\r
+                       Zero((UCHAR *)buf + size_read, size - size_read);\r
+               }\r
+       }\r
+\r
+       if (buf != NULL)\r
+       {\r
+               Copy(buf, (UCHAR *)b->Buf + b->Current, size_read);\r
+       }\r
+\r
+       b->Current += size_read;\r
+\r
+       // KS\r
+       KS_INC(KS_READ_BUF_COUNT);\r
+\r
+       return size_read;\r
+}\r
+\r
+// バッファサイズの調整\r
+void AdjustBufSize(BUF *b, UINT new_size)\r
+{\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (b->SizeReserved >= new_size)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (b->SizeReserved < new_size)\r
+       {\r
+               b->SizeReserved = b->SizeReserved * 2;\r
+       }\r
+       b->Buf = ReAlloc(b->Buf, b->SizeReserved);\r
+\r
+       // KS\r
+       KS_INC(KS_ADJUST_BUFSIZE_COUNT);\r
+}\r
+\r
+// バッファのシーク\r
+void SeekBuf(BUF *b, UINT offset, int mode)\r
+{\r
+       UINT new_pos;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (mode == 0)\r
+       {\r
+               // 絶対位置\r
+               new_pos = offset;\r
+       }\r
+       else\r
+       {\r
+               if (mode > 0)\r
+               {\r
+                       // 右へ移動\r
+                       new_pos = b->Current + offset;\r
+               }\r
+               else\r
+               {\r
+                       // 左へ移動\r
+                       if (b->Current >= offset)\r
+                       {\r
+                               new_pos = b->Current - offset;\r
+                       }\r
+                       else\r
+                       {\r
+                               new_pos = 0;\r
+                       }\r
+               }\r
+       }\r
+       b->Current = MAKESURE(new_pos, 0, b->Size);\r
+\r
+       KS_INC(KS_SEEK_BUF_COUNT);\r
+}\r
+\r
+// バッファの解放\r
+void FreeBuf(BUF *b)\r
+{\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メモリ解放\r
+       Free(b->Buf);\r
+       Free(b);\r
+\r
+       // KS\r
+       KS_INC(KS_FREEBUF_COUNT);\r
+       KS_DEC(KS_CURRENT_BUF_COUNT);\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackDeleteObj(POINTER_TO_UINT64(b));\r
+#endif // DONT_USE_KERNEL_STATUS\r
+}\r
+\r
+// Unicode 文字列のエンディアン変換\r
+void EndianUnicode(wchar_t *str)\r
+{\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+       len = UniStrLen(str);\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               str[i] = Endian16(str[i]);\r
+       }\r
+}\r
+\r
+// エンディアン変換 16bit\r
+USHORT Endian16(USHORT src)\r
+{\r
+       int x = 1;\r
+       if (*((char *)&x))\r
+       {\r
+               return Swap16(src);\r
+       }\r
+       else\r
+       {\r
+               return src;\r
+       }\r
+}\r
+\r
+// エンディアン変換 32bit\r
+UINT Endian32(UINT src)\r
+{\r
+       int x = 1;\r
+       if (*((char *)&x))\r
+       {\r
+               return Swap32(src);\r
+       }\r
+       else\r
+       {\r
+               return src;\r
+       }\r
+}\r
+\r
+// エンディアン変換 64bit\r
+UINT64 Endian64(UINT64 src)\r
+{\r
+       int x = 1;\r
+       if (*((char *)&x))\r
+       {\r
+               return Swap64(src);\r
+       }\r
+       else\r
+       {\r
+               return src;\r
+       }\r
+}\r
+\r
+// 任意のデータのスワップ\r
+void Swap(void *buf, UINT size)\r
+{\r
+       UCHAR *tmp, *src;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (buf == NULL || size == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       src = (UCHAR *)buf;\r
+       tmp = Malloc(size);\r
+       for (i = 0;i < size;i++)\r
+       {\r
+               tmp[size - i - 1] = src[i];\r
+       }\r
+\r
+       Copy(buf, tmp, size);\r
+       Free(buf);\r
+}\r
+\r
+// 16bit スワップ\r
+USHORT Swap16(USHORT value)\r
+{\r
+       USHORT r;\r
+       // 汚いコード\r
+       ((BYTE *)&r)[0] = ((BYTE *)&value)[1];\r
+       ((BYTE *)&r)[1] = ((BYTE *)&value)[0];\r
+       return r;\r
+}\r
+\r
+// 32bit スワップ\r
+UINT Swap32(UINT value)\r
+{\r
+       UINT r;\r
+       // 汚いコード\r
+       ((BYTE *)&r)[0] = ((BYTE *)&value)[3];\r
+       ((BYTE *)&r)[1] = ((BYTE *)&value)[2];\r
+       ((BYTE *)&r)[2] = ((BYTE *)&value)[1];\r
+       ((BYTE *)&r)[3] = ((BYTE *)&value)[0];\r
+       return r;\r
+}\r
+\r
+// 64bit スワップ\r
+UINT64 Swap64(UINT64 value)\r
+{\r
+       UINT64 r;\r
+       // 汚いコード\r
+       ((BYTE *)&r)[0] = ((BYTE *)&value)[7];\r
+       ((BYTE *)&r)[1] = ((BYTE *)&value)[6];\r
+       ((BYTE *)&r)[2] = ((BYTE *)&value)[5];\r
+       ((BYTE *)&r)[3] = ((BYTE *)&value)[4];\r
+       ((BYTE *)&r)[4] = ((BYTE *)&value)[3];\r
+       ((BYTE *)&r)[5] = ((BYTE *)&value)[2];\r
+       ((BYTE *)&r)[6] = ((BYTE *)&value)[1];\r
+       ((BYTE *)&r)[7] = ((BYTE *)&value)[0];\r
+       return r;\r
+}\r
+\r
+// Base64 エンコード\r
+UINT Encode64(char *dst, char *src)\r
+{\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return B64_Encode(dst, src, StrLen(src));\r
+}\r
+\r
+// Base64 デコード\r
+UINT Decode64(char *dst, char *src)\r
+{\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return B64_Decode(dst, src, StrLen(src));\r
+}\r
+\r
+// Base64 エンコード\r
+int B64_Encode(char *set, char *source, int len)\r
+{\r
+       BYTE *src;\r
+       int i,j;\r
+       src = (BYTE *)source;\r
+       j = 0;\r
+       i = 0;\r
+       if (!len)\r
+       {\r
+               return 0;\r
+       }\r
+       while (TRUE)\r
+       {\r
+               if (i >= len)\r
+               {\r
+                       return j;\r
+               }\r
+               if (set)\r
+               {\r
+                       set[j] = B64_CodeToChar((src[i]) >> 2);\r
+               }\r
+               if (i + 1 >= len)\r
+               {\r
+                       if (set)\r
+                       {\r
+                               set[j + 1] = B64_CodeToChar((src[i] & 0x03) << 4);\r
+                               set[j + 2] = '=';\r
+                               set[j + 3] = '=';\r
+                       }\r
+                       return j + 4;\r
+               }\r
+               if (set)\r
+               {\r
+                       set[j + 1] = B64_CodeToChar(((src[i] & 0x03) << 4) + ((src[i + 1] >> 4)));\r
+               }\r
+               if (i + 2 >= len)\r
+               {\r
+                       if (set)\r
+                       {\r
+                               set[j + 2] = B64_CodeToChar((src[i + 1] & 0x0f) << 2);\r
+                               set[j + 3] = '=';\r
+                       }\r
+                       return j + 4;\r
+               }\r
+               if (set)\r
+               {\r
+                       set[j + 2] = B64_CodeToChar(((src[i + 1] & 0x0f) << 2) + ((src[i + 2] >> 6)));\r
+                       set[j + 3] = B64_CodeToChar(src[i + 2] & 0x3f);\r
+               }\r
+               i += 3;\r
+               j += 4;\r
+       }\r
+}\r
+\r
+// Base64 デコード\r
+int B64_Decode(char *set, char *source, int len)\r
+{\r
+       int i,j;\r
+       char a1,a2,a3,a4;\r
+       char *src;\r
+       int f1,f2,f3,f4;\r
+       src = source;\r
+       i = 0;\r
+       j = 0;\r
+       while (TRUE)\r
+       {\r
+               f1 = f2 = f3 = f4 = 0;\r
+               if (i >= len)\r
+               {\r
+                       break;\r
+               }\r
+               f1 = 1;\r
+               a1 = B64_CharToCode(src[i]);\r
+               if (a1 == -1)\r
+               {\r
+                       f1 = 0;\r
+               }\r
+               if (i >= len + 1)\r
+               {\r
+                       a2 = 0;\r
+               }\r
+               else\r
+               {\r
+                       a2 = B64_CharToCode(src[i + 1]);\r
+                       f2 = 1;\r
+                       if (a2 == -1)\r
+                       {\r
+                               f2 = 0;\r
+                       }\r
+               }\r
+               if (i >= len + 2)\r
+               {\r
+                       a3 = 0;\r
+               }\r
+               else\r
+               {\r
+                       a3 = B64_CharToCode(src[i + 2]);\r
+                       f3 = 1;\r
+                       if (a3 == -1)\r
+                       {\r
+                               f3 = 0;\r
+                       }\r
+               }\r
+               if (i >= len + 3)\r
+               {\r
+                       a4 = 0;\r
+               }\r
+               else\r
+               {\r
+                       a4 = B64_CharToCode(src[i + 3]);\r
+                       f4 = 1;\r
+                       if (a4 == -1)\r
+                       {\r
+                               f4 = 0;\r
+                       }\r
+               }\r
+               if (f1 && f2)\r
+               {\r
+                       if (set)\r
+                       {\r
+                               set[j] = (a1 << 2) + (a2 >> 4);\r
+                       }\r
+                       j++;\r
+               }\r
+               if (f2 && f3)\r
+               {\r
+                       if (set)\r
+                       {\r
+                               set[j] = (a2 << 4) + (a3 >> 2);\r
+                       }\r
+                       j++;\r
+               }\r
+               if (f3 && f4)\r
+               {\r
+                       if (set)\r
+                       {\r
+                               set[j] = (a3 << 6) + a4;\r
+                       }\r
+                       j++;\r
+               }\r
+               i += 4;\r
+       }\r
+       return j;\r
+}\r
+\r
+// Base64 - コードを文字に変換\r
+char B64_CodeToChar(BYTE c)\r
+{\r
+       BYTE r;\r
+       r = '=';\r
+       if (c <= 0x19)\r
+       {\r
+               r = c + 'A';\r
+       }\r
+       if (c >= 0x1a && c <= 0x33)\r
+       {\r
+               r = c - 0x1a + 'a';\r
+       }\r
+       if (c >= 0x34 && c <= 0x3d)\r
+       {\r
+               r = c - 0x34 + '0';\r
+       }\r
+       if (c == 0x3e)\r
+       {\r
+               r = '+';\r
+       }\r
+       if (c == 0x3f)\r
+       {\r
+               r = '/';\r
+       }\r
+       return r;\r
+}\r
+\r
+// Base64 - 文字をコードに変換\r
+char B64_CharToCode(char c)\r
+{\r
+       if (c >= 'A' && c <= 'Z')\r
+       {\r
+               return c - 'A';\r
+       }\r
+       if (c >= 'a' && c <= 'z')\r
+       {\r
+               return c - 'a' + 0x1a;\r
+       }\r
+       if (c >= '0' && c <= '9')\r
+       {\r
+               return c - '0' + 0x34;\r
+       }\r
+       if (c == '+')\r
+       {\r
+               return 0x3e;\r
+       }\r
+       if (c == '/')\r
+       {\r
+               return 0x3f;\r
+       }\r
+       if (c == '=')\r
+       {\r
+               return -1;\r
+       }\r
+       return 0;\r
+}\r
+\r
+// 高速な Malloc (現在未実装)\r
+// 実は小さなバッファをたくさんまとめておいてそれを動的に割り当てるコードを昔\r
+// 書いたのだが、Windows, Linux, Solaris で試しても普通の malloc() と比べて\r
+// ほとんど速度に影響がなかったので、やめにした。\r
+void *MallocFast(UINT size)\r
+{\r
+       return Malloc(size);\r
+}\r
+\r
+// Malloc\r
+void *Malloc(UINT size)\r
+{\r
+       return MallocEx(size, false);\r
+}\r
+void *MallocEx(UINT size, bool zero_clear_when_free)\r
+{\r
+       MEMTAG *tag;\r
+       UINT real_size;\r
+\r
+       real_size = CALC_MALLOCSIZE(size);\r
+\r
+       tag = InternalMalloc(real_size);\r
+\r
+       Zero(tag, sizeof(MEMTAG));\r
+       tag->Magic = MEMTAG_MAGIC;\r
+       tag->Size = size;\r
+       tag->ZeroFree = zero_clear_when_free;\r
+\r
+       return MEMTAG_TO_POINTER(tag);\r
+}\r
+\r
+// ReAlloc\r
+void *ReAlloc(void *addr, UINT size)\r
+{\r
+       MEMTAG *tag;\r
+       bool zerofree;\r
+       // 引数チェック\r
+       if (IS_NULL_POINTER(addr))\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       tag = POINTER_TO_MEMTAG(addr);\r
+       CheckMemTag(tag);\r
+\r
+       zerofree = tag->ZeroFree;\r
+\r
+       if (tag->Size == size)\r
+       {\r
+               // サイズ変更無し\r
+               return addr;\r
+       }\r
+       else\r
+       {\r
+               if (zerofree)\r
+               {\r
+                       // サイズ変更有り (ゼロクリア必須)\r
+                       void *new_p = MallocEx(size, true);\r
+\r
+                       if (tag->Size <= size)\r
+                       {\r
+                               // サイズ拡大\r
+                               Copy(new_p, addr, tag->Size);\r
+                       }\r
+                       else\r
+                       {\r
+                               // サイズ縮小\r
+                               Copy(new_p, addr, size);\r
+                       }\r
+\r
+                       // 古いブロックの解放\r
+                       Free(addr);\r
+\r
+                       return new_p;\r
+               }\r
+               else\r
+               {\r
+                       // サイズ変更有り\r
+                       MEMTAG *tag2 = InternalReAlloc(tag, CALC_MALLOCSIZE(size));\r
+\r
+                       Zero(tag2, sizeof(MEMTAG));\r
+                       tag2->Magic = MEMTAG_MAGIC;\r
+                       tag2->Size = size;\r
+\r
+                       return MEMTAG_TO_POINTER(tag2);\r
+               }\r
+       }\r
+}\r
+\r
+// Free\r
+void Free(void *addr)\r
+{\r
+       MEMTAG *tag;\r
+       // 引数チェック\r
+       if (IS_NULL_POINTER(addr))\r
+       {\r
+               return;\r
+       }\r
+\r
+       tag = POINTER_TO_MEMTAG(addr);\r
+       CheckMemTag(tag);\r
+\r
+       if (tag->ZeroFree)\r
+       {\r
+               // ゼロクリア\r
+               Zero(addr, tag->Size);\r
+       }\r
+\r
+       // メモリ解放\r
+       tag->Magic = 0;\r
+       InternalFree(tag);\r
+}\r
+\r
+// memtag をチェック\r
+void CheckMemTag(MEMTAG *tag)\r
+{\r
+#ifndef        DONT_CHECK_HEAP\r
+       // 引数チェック\r
+       if (tag == NULL)\r
+       {\r
+               AbortExitEx("CheckMemTag: tag == NULL");\r
+               return;\r
+       }\r
+\r
+       if (tag->Magic != MEMTAG_MAGIC)\r
+       {\r
+               AbortExitEx("CheckMemTag: tag->Magic != MEMTAG_MAGIC");\r
+               return;\r
+       }\r
+#endif // DONT_CHECK_HEAP\r
+}\r
+\r
+// ZeroMalloc\r
+void *ZeroMalloc(UINT size)\r
+{\r
+       return ZeroMallocEx(size, false);\r
+}\r
+void *ZeroMallocEx(UINT size, bool zero_clear_when_free)\r
+{\r
+       void *p = MallocEx(size, zero_clear_when_free);\r
+       Zero(p, size);\r
+       return p;\r
+}\r
+void *ZeroMallocFast(UINT size)\r
+{\r
+       void *p = MallocFast(size);\r
+       Zero(p, size);\r
+       return p;\r
+}\r
+\r
+// メモリ確保\r
+void *InternalMalloc(UINT size)\r
+{\r
+       void *addr;\r
+       UINT retry = 0;\r
+       size = MORE(size, 1);\r
+\r
+       // KS\r
+       KS_INC(KS_MALLOC_COUNT);\r
+       KS_INC(KS_TOTAL_MEM_COUNT);\r
+       KS_ADD(KS_TOTAL_MEM_SIZE, size);\r
+       KS_INC(KS_CURRENT_MEM_COUNT);\r
+\r
+       // メモリが確保されるまで試行する\r
+       while (true)\r
+       {\r
+               if ((retry++) > MEMORY_MAX_RETRY)\r
+               {\r
+                       AbortExitEx("InternalMalloc: error: malloc() failed.\n\n");\r
+               }\r
+               addr = OSMemoryAlloc(size);\r
+               if (addr != NULL)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               OSSleep(MEMORY_SLEEP_TIME);\r
+       }\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackNewObj(POINTER_TO_UINT64(addr), "MEM", size);\r
+#endif //DONT_USE_KERNEL_STATUS\r
+\r
+       return addr;\r
+}\r
+\r
+// メモリ解放\r
+void InternalFree(void *addr)\r
+{\r
+       // 引数チェック\r
+       if (addr == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // KS\r
+       KS_DEC(KS_CURRENT_MEM_COUNT);\r
+       KS_INC(KS_FREE_COUNT);\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackDeleteObj(POINTER_TO_UINT64(addr));\r
+#endif // DONT_USE_KERNEL_STATUS\r
+\r
+       // メモリ解放\r
+       OSMemoryFree(addr);\r
+}\r
+\r
+// メモリ再確保\r
+void *InternalReAlloc(void *addr, UINT size)\r
+{\r
+       void *new_addr;\r
+       UINT retry = 0;\r
+       size = MORE(size, 1);\r
+\r
+       // KS\r
+       KS_INC(KS_REALLOC_COUNT);\r
+       KS_ADD(KS_TOTAL_MEM_SIZE, size);\r
+\r
+       // メモリが確保されるまで試行する\r
+       while (true)\r
+       {\r
+               if ((retry++) > MEMORY_MAX_RETRY)\r
+               {\r
+                       AbortExitEx("InternalReAlloc: error: realloc() failed.\n\n");\r
+               }\r
+               new_addr = OSMemoryReAlloc(addr, size);\r
+               if (new_addr != NULL)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               OSSleep(MEMORY_SLEEP_TIME);\r
+       }\r
+\r
+#ifndef        DONT_USE_KERNEL_STATUS\r
+       TrackChangeObjSize((DWORD)addr, size, (DWORD)new_addr);\r
+#endif // DONT_USE_KERNEL_STATUS\r
+\r
+       return new_addr;\r
+}\r
+\r
+// メモリ領域のクローン\r
+void *Clone(void *addr, UINT size)\r
+{\r
+       void *ret;\r
+       // 引数チェック\r
+       if (addr == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = Malloc(size);\r
+       Copy(ret, addr, size);\r
+\r
+       return ret;\r
+}\r
+\r
+// メモリコピー\r
+void Copy(void *dst, void *src, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL || size == 0 || dst == src)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_COPY_COUNT);\r
+\r
+       memcpy(dst, src, size);\r
+}\r
+\r
+// メモリ比較\r
+int Cmp(void *p1, void *p2, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (p1 == NULL || p2 == NULL || size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return memcmp(p1, p2, (size_t)size);\r
+}\r
+\r
+// メモリのゼロクリア\r
+void Zero(void *addr, UINT size)\r
+{\r
+       ZeroMem(addr, size);\r
+}\r
+void ZeroMem(void *addr, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (addr == NULL || size == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_ZERO_COUNT);\r
+\r
+       memset(addr, 0, size);\r
+}\r
+\r
+// 文字列マップエントリの比較\r
+int StrMapCmp(void *p1, void *p2)\r
+{\r
+       STRMAP_ENTRY *s1, *s2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       s1 = *(STRMAP_ENTRY **)p1;\r
+       s2 = *(STRMAP_ENTRY **)p2;\r
+       if (s1 == NULL || s2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       return StrCmpi(s1->Name, s2->Name);\r
+}\r
+\r
+// 文字列マップ(文字列で検索できるデータ)の作成\r
+LIST *NewStrMap()\r
+{\r
+       return NewList(StrMapCmp);\r
+}\r
+\r
+// 文字列マップの検索\r
+void *StrMapSearch(LIST *map, char *key)\r
+{\r
+       STRMAP_ENTRY tmp, *result;\r
+       tmp.Name = key;\r
+       result = (STRMAP_ENTRY*)Search(map, &tmp);\r
+       if(result != NULL)\r
+       {\r
+               return result->Value;\r
+       }\r
+       return NULL;\r
+}\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Memory.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Memory.h
new file mode 100644 (file)
index 0000000..08efaaf
--- /dev/null
@@ -0,0 +1,325 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Memory.h\r
+// Memory.c のヘッダ\r
+\r
+#ifndef        MEMORY_H\r
+#define        MEMORY_H\r
+\r
+// 一度にカーネルに渡すことができるメモリサイズ\r
+#define        MAX_SEND_BUF_MEM_SIZE                           (10 * 1024 * 1024)\r
+\r
+// メモリタグ用マジックナンバー\r
+#define        MEMTAG_MAGIC                                            0x49414449\r
+\r
+#define        CALC_MALLOCSIZE(size)                           ((MAX(size, 1)) + sizeof(MEMTAG))\r
+#define        MEMTAG_TO_POINTER(p)                            ((void *)(((UCHAR *)(p)) + sizeof(MEMTAG)))\r
+#define        POINTER_TO_MEMTAG(p)                            ((MEMTAG *)(((UCHAR *)(p)) - sizeof(MEMTAG)))\r
+#define        IS_NULL_POINTER(p)                                      (((p) == NULL) || ((POINTER_TO_UINT64(p) == (UINT64)sizeof(MEMTAG))))\r
+\r
+// メモリプールの 1 ブロックの固定サイズ\r
+#define        MEMPOOL_MAX_SIZE                                        3000\r
+\r
+\r
+// メモリタグ\r
+struct MEMTAG\r
+{\r
+       UINT Magic;\r
+       UINT Size;\r
+       bool ZeroFree;\r
+       UINT Padding;\r
+};\r
+\r
+// バッファ\r
+struct BUF\r
+{\r
+       void *Buf;\r
+       UINT Size;\r
+       UINT SizeReserved;\r
+       UINT Current;\r
+};\r
+\r
+// FIFO\r
+struct FIFO\r
+{\r
+       REF *ref;\r
+       LOCK *lock;\r
+       void *p;\r
+       UINT pos, size, memsize;\r
+       UINT realloc_mem_size;\r
+};\r
+\r
+// リスト\r
+struct LIST\r
+{\r
+       REF *ref;\r
+       UINT num_item, num_reserved;\r
+       void **p;\r
+       LOCK *lock;\r
+       COMPARE *cmp;\r
+       bool sorted;\r
+};\r
+\r
+// キュー\r
+struct QUEUE\r
+{\r
+       REF *ref;\r
+       UINT num_item;\r
+       FIFO *fifo;\r
+       LOCK *lock;\r
+};\r
+\r
+// スタック\r
+struct SK\r
+{\r
+       REF *ref;\r
+       UINT num_item, num_reserved;\r
+       void **p;\r
+       LOCK *lock;\r
+       bool no_compact;\r
+};\r
+\r
+// 候補リスト\r
+struct CANDIDATE\r
+{\r
+       wchar_t *Str;                                           // 文字列\r
+       UINT64 LastSelectedTime;                        // 最後に選択された日時\r
+};\r
+\r
+struct STRMAP_ENTRY\r
+{\r
+       char *Name;\r
+       void *Value;\r
+};\r
+\r
+// マクロ\r
+#define        LIST_DATA(o, i)         (((o) != NULL) ? ((o)->p[(i)]) : NULL)\r
+#define        LIST_NUM(o)                     (((o) != NULL) ? (o)->num_item : 0)\r
+\r
+\r
+// 関数プロトタイプ\r
+LIST *NewCandidateList();\r
+void FreeCandidateList(LIST *o);\r
+int ComapreCandidate(void *p1, void *p2);\r
+void AddCandidate(LIST *o, wchar_t *str, UINT num_max);\r
+BUF *CandidateToBuf(LIST *o);\r
+LIST *BufToCandidate(BUF *b);\r
+\r
+void *Malloc(UINT size);\r
+void *MallocEx(UINT size, bool zero_clear_when_free);\r
+void *MallocFast(UINT size);\r
+void *ZeroMalloc(UINT size);\r
+void *ZeroMallocFast(UINT size);\r
+void *ZeroMallocEx(UINT size, bool zero_clear_when_free);\r
+void *ReAlloc(void *addr, UINT size);\r
+void Free(void *addr);\r
+void CheckMemTag(MEMTAG *tag);\r
+\r
+void *InternalMalloc(UINT size);\r
+void *InternalReAlloc(void *addr, UINT size);\r
+void InternalFree(void *addr);\r
+\r
+void Copy(void *dst, void *src, UINT size);\r
+int Cmp(void *p1, void *p2, UINT size);\r
+void ZeroMem(void *addr, UINT size);\r
+void Zero(void *addr, UINT size);\r
+void *Clone(void *addr, UINT size);\r
+\r
+char B64_CodeToChar(BYTE c);\r
+char B64_CharToCode(char c);\r
+int B64_Encode(char *set, char *source, int len);\r
+int B64_Decode(char *set, char *source, int len);\r
+UINT Encode64(char *dst, char *src);\r
+UINT Decode64(char *dst, char *src);\r
+\r
+void Swap(void *buf, UINT size);\r
+USHORT Swap16(USHORT value);\r
+UINT Swap32(UINT value);\r
+UINT64 Swap64(UINT64 value);\r
+USHORT Endian16(USHORT src);\r
+UINT Endian32(UINT src);\r
+UINT64 Endian64(UINT64 src);\r
+void EndianUnicode(wchar_t *str);\r
+\r
+BUF *NewBuf();\r
+void ClearBuf(BUF *b);\r
+void WriteBuf(BUF *b, void *buf, UINT size);\r
+void WriteBufBuf(BUF *b, BUF *bb);\r
+UINT ReadBuf(BUF *b, void *buf, UINT size);\r
+BUF *ReadBufFromBuf(BUF *b, UINT size);\r
+void AdjustBufSize(BUF *b, UINT new_size);\r
+void SeekBuf(BUF *b, UINT offset, int mode);\r
+void FreeBuf(BUF *b);\r
+bool BufToFile(IO *o, BUF *b);\r
+BUF *FileToBuf(IO *o);\r
+UINT ReadBufInt(BUF *b);\r
+UINT64 ReadBufInt64(BUF *b);\r
+bool WriteBufInt(BUF *b, UINT value);\r
+bool WriteBufInt64(BUF *b, UINT64 value);\r
+bool ReadBufStr(BUF *b, char *str, UINT size);\r
+bool WriteBufStr(BUF *b, char *str);\r
+void WriteBufLine(BUF *b, char *str);\r
+void AddBufStr(BUF *b, char *str);\r
+bool DumpBuf(BUF *b, char *filename);\r
+bool DumpBufW(BUF *b, wchar_t *filename);\r
+BUF *ReadDump(char *filename);\r
+BUF *ReadDumpW(wchar_t *filename);\r
+\r
+UINT PeekFifo(FIFO *f, void *p, UINT size);\r
+UINT ReadFifo(FIFO *f, void *p, UINT size);\r
+void WriteFifo(FIFO *f, void *p, UINT size);\r
+void ClearFifo(FIFO *f);\r
+UINT FifoSize(FIFO *f);\r
+void LockFifo(FIFO *f);\r
+void UnlockFifo(FIFO *f);\r
+void ReleaseFifo(FIFO *f);\r
+void CleanupFifo(FIFO *f);\r
+FIFO *NewFifo();\r
+FIFO *NewFifoFast();\r
+FIFO *NewFifoEx(UINT realloc_mem_size, bool fast);\r
+void InitFifo();\r
+UINT GetFifoDefaultReallocMemSize();\r
+void SetFifoDefaultReallocMemSize(UINT size);\r
+\r
+void *Search(LIST *o, void *target);\r
+void Sort(LIST *o);\r
+void Add(LIST *o, void *p);\r
+void Insert(LIST *o, void *p);\r
+bool Delete(LIST *o, void *p);\r
+bool DeleteKey(LIST *o, UINT key);\r
+void DeleteAll(LIST *o);\r
+void LockList(LIST *o);\r
+void UnlockList(LIST *o);\r
+void ReleaseList(LIST *o);\r
+void CleanupList(LIST *o);\r
+LIST *NewList(COMPARE *cmp);\r
+LIST *NewListFast(COMPARE *cmp);\r
+LIST *NewListEx(COMPARE *cmp, bool fast);\r
+LIST *NewListEx2(COMPARE *cmp, bool fast, bool fast_malloc);\r
+void CopyToArray(LIST *o, void *p);\r
+void *ToArray(LIST *o);\r
+void *ToArrayEx(LIST *o, bool fast);\r
+LIST *CloneList(LIST *o);\r
+void SetCmp(LIST *o, COMPARE *cmp);\r
+void SetSortFlag(LIST *o, bool sorted);\r
+int CompareStr(void *p1, void *p2);\r
+bool InsertStr(LIST *o, char *str);\r
+int CompareUniStr(void *p1, void *p2);\r
+bool IsInList(LIST *o, void *p);\r
+bool IsInListKey(LIST *o, UINT key);\r
+void *ListKeyToPointer(LIST *o, UINT key);\r
+bool IsInListStr(LIST *o, char *str);\r
+bool IsInListUniStr(LIST *o, wchar_t *str);\r
+bool ReplaceListPointer(LIST *o, void *oldptr, void *newptr);\r
+\r
+void *GetNext(QUEUE *q);\r
+void InsertQueue(QUEUE *q, void *p);\r
+void InsertQueueInt(QUEUE *q, UINT value);\r
+void LockQueue(QUEUE *q);\r
+void UnlockQueue(QUEUE *q);\r
+void ReleaseQueue(QUEUE *q);\r
+void CleanupQueue(QUEUE *q);\r
+QUEUE *NewQueue();\r
+QUEUE *NewQueueFast();\r
+\r
+SK *NewSk();\r
+SK *NewSkEx(bool no_compact);\r
+void ReleaseSk(SK *s);\r
+void CleanupSk(SK *s);\r
+void LockSk(SK *s);\r
+void UnlockSk(SK *s);\r
+void Push(SK *s, void *p);\r
+void *Pop(SK *s);\r
+\r
+UINT Uncompress(void *dst, UINT dst_size, void *src, UINT src_size);\r
+UINT Compress(void *dst, UINT dst_size, void *src, UINT src_size);\r
+UINT CompressEx(void *dst, UINT dst_size, void *src, UINT src_size, UINT level);\r
+UINT CalcCompress(UINT src_size);\r
+\r
+bool IsZero(void *data, UINT size);\r
+\r
+void Crash();\r
+\r
+LIST *NewStrMap();\r
+void *StrMapSearch(LIST *map, char *key);\r
+\r
+UINT SearchBin(void *data, UINT data_start, UINT data_size, void *key, UINT key_size);\r
+void CrashNow();\r
+\r
+#endif // MEMORY_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Microsoft.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Microsoft.c
new file mode 100644 (file)
index 0000000..f9d1ec8
--- /dev/null
@@ -0,0 +1,12112 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Microsoft.c\r
+// Microsoft Windows 用コード\r
+// (Windows 以外の環境ではコンパイルされない)\r
+\r
+#ifdef WIN32\r
+\r
+#define        MICROSOFT_C\r
+\r
+typedef enum    _PNP_VETO_TYPE {\r
+    PNP_VetoTypeUnknown,            // Name is unspecified\r
+    PNP_VetoLegacyDevice,           // Name is an Instance Path\r
+    PNP_VetoPendingClose,           // Name is an Instance Path\r
+    PNP_VetoWindowsApp,             // Name is a Module\r
+    PNP_VetoWindowsService,         // Name is a Service\r
+    PNP_VetoOutstandingOpen,        // Name is an Instance Path\r
+    PNP_VetoDevice,                 // Name is an Instance Path\r
+    PNP_VetoDriver,                 // Name is a Driver Service Name\r
+    PNP_VetoIllegalDeviceRequest,   // Name is an Instance Path\r
+    PNP_VetoInsufficientPower,      // Name is unspecified\r
+    PNP_VetoNonDisableable,         // Name is an Instance Path\r
+    PNP_VetoLegacyDriver,           // Name is a Service\r
+    PNP_VetoInsufficientRights      // Name is unspecified\r
+}   PNP_VETO_TYPE, *PPNP_VETO_TYPE;\r
+\r
+#define        _WIN32_IE                       0x0600\r
+#define        _WIN32_WINNT            0x0502\r
+#define        WINVER                          0x0502\r
+#define   SECURITY_WIN32\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+#include <Wintrust.h>\r
+#include <Softpub.h>\r
+#include <Iphlpapi.h>\r
+#include <tlhelp32.h>\r
+#include <wincon.h>\r
+#include <Nb30.h>\r
+#include <shlobj.h>\r
+#include <commctrl.h>\r
+#include <Dbghelp.h>\r
+#include <setupapi.h>\r
+#include <regstr.h>\r
+#include <process.h>\r
+#include <psapi.h>\r
+#include <wtsapi32.h>\r
+#include <security.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <cfgmgr32.h>\r
+#include <sddl.h>\r
+#include <Aclapi.h>\r
+\r
+\r
+static MS *ms = NULL;\r
+\r
+// 関数プロトタイプ\r
+UINT MsgBox(HWND hWnd, UINT flag, wchar_t *msg);\r
+UINT MsgBoxEx(HWND hWnd, UINT flag, wchar_t *msg, ...);\r
+void ShowTcpIpConfigUtil(HWND hWnd, bool util_mode);\r
+void CmTraffic(HWND hWnd);\r
+void CnStart();\r
+void InitCedar();\r
+void FreeCedar();\r
+void InitWinUi(wchar_t *software_name, char *font, UINT fontsize);\r
+void FreeWinUi();\r
+\r
+// グローバル変数\r
+void *ms_critical_section = NULL;\r
+UINT64 ms_uint64_1 = 0;\r
+\r
+// アダプタリスト関係\r
+static LOCK *lock_adapter_list = NULL;\r
+static MS_ADAPTER_LIST *last_adapter_list = NULL;\r
+\r
+// サービス関係\r
+static SERVICE_STATUS_HANDLE ssh = NULL;\r
+static SERVICE_STATUS status;\r
+static char g_service_name[MAX_SIZE];\r
+static SERVICE_FUNCTION *g_start, *g_stop;\r
+static bool exiting = false;\r
+static bool wnd_end;\r
+static bool is_usermode = false;\r
+static HICON tray_icon;\r
+static NOTIFYICONDATA nid;\r
+static NOTIFYICONDATAW nid_nt;\r
+static bool service_for_9x_mode = false;\r
+static THREAD *starter_thread = NULL;\r
+static EVENT *server_stopped_event = NULL;\r
+static THREAD *service_stopper_thread = NULL;\r
+static bool tray_inited = false;\r
+static HWND hWndUsermode = NULL;\r
+\r
+// [ネットワーク接続] を開くためのショートカット (最新版では未使用)\r
+static UCHAR network_connection_link[] =\r
+{\r
+       0x4C, 0x00, 0x00, 0x00, 0x01, 0x14, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, \r
+       0x00, 0x00, 0x00, 0x46, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, \r
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x14, 0x00, \r
+       0x1F, 0x50, 0xE0, 0x4F, 0xD0, 0x20, 0xEA, 0x3A, 0x69, 0x10, 0xA2, 0xD8, 0x08, 0x00, 0x2B, 0x30, \r
+       0x30, 0x9D, 0x14, 0x00, 0x2E, 0x00, 0x20, 0x20, 0xEC, 0x21, 0xEA, 0x3A, 0x69, 0x10, 0xA2, 0xDD, \r
+       0x08, 0x00, 0x2B, 0x30, 0x30, 0x9D, 0x14, 0x00, 0x70, 0x00, 0xC7, 0xAC, 0x07, 0x70, 0x02, 0x32, \r
+       0xD1, 0x11, 0xAA, 0xD2, 0x00, 0x80, 0x5F, 0xC1, 0x27, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
+};\r
+\r
+// Windows Vista 関係の新しいセキュリティ構造体等\r
+#if    0\r
+typedef struct _TOKEN_MANDATORY_LABEL\r
+{\r
+       SID_AND_ATTRIBUTES Label;\r
+} TOKEN_MANDATORY_LABEL, *PTOKEN_MANDATORY_LABEL;\r
+#endif\r
+\r
+#define SE_GROUP_INTEGRITY                 (0x00000020L)\r
+\r
+typedef enum _TOKEN_INFORMATION_CLASS_VISTA\r
+{\r
+       VistaTokenUser = 1,\r
+       VistaTokenGroups,\r
+       VistaTokenPrivileges,\r
+       VistaTokenOwner,\r
+       VistaTokenPrimaryGroup,\r
+       VistaTokenDefaultDacl,\r
+       VistaTokenSource,\r
+       VistaTokenType,\r
+       VistaTokenImpersonationLevel,\r
+       VistaTokenStatistics,\r
+       VistaTokenRestrictedSids,\r
+       VistaTokenSessionId,\r
+       VistaTokenGroupsAndPrivileges,\r
+       VistaTokenSessionReference,\r
+       VistaTokenSandBoxInert,\r
+       VistaTokenAuditPolicy,\r
+       VistaTokenOrigin,\r
+       VistaTokenElevationType,\r
+       VistaTokenLinkedToken,\r
+       VistaTokenElevation,\r
+       VistaTokenHasRestrictions,\r
+       VistaTokenAccessInformation,\r
+       VistaTokenVirtualizationAllowed,\r
+       VistaTokenVirtualizationEnabled,\r
+       VistaTokenIntegrityLevel,\r
+       VistaTokenUIAccess,\r
+       VistaTokenMandatoryPolicy,\r
+       VistaTokenLogonSid,\r
+       VistaMaxTokenInfoClass\r
+} TOKEN_INFORMATION_CLASS_VISTA, *PTOKEN_INFORMATION_CLASS_VISTA;\r
+\r
+// エラーを表示しないモードにする\r
+void MsSetErrorModeToSilent()\r
+{\r
+       SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);\r
+}\r
+\r
+// ファイル情報の取得\r
+bool MsGetFileInformation(void *h, void *info)\r
+{\r
+       // 引数チェック\r
+       if (h == INVALID_HANDLE_VALUE || info == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ms->nt->GetFileInformationByHandle == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return ms->nt->GetFileInformationByHandle(h, info);\r
+}\r
+\r
+// プロセスのシャットダウンパラメータの設定\r
+void MsSetShutdownParameters(UINT level, UINT flag)\r
+{\r
+       if (MsIsNt() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (ms->nt == false || ms->nt->SetProcessShutdownParameters == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ms->nt->SetProcessShutdownParameters(level, flag);\r
+}\r
+\r
+// OS のバージョンが Windows XP または Windows Vista 以降かどうか取得する\r
+bool MsIsWinXPOrWinVista()\r
+{\r
+       OS_INFO *info = GetOsInfo();\r
+       if (info == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (OS_IS_WINDOWS_NT(info->OsType) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GET_KETA(info->OsType, 100) >= 3)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// イベントログに書き込む\r
+bool MsWriteEventLog(void *p, UINT type, wchar_t *str)\r
+{\r
+       MS_EVENTLOG *g = (MS_EVENTLOG *)p;\r
+       wchar_t *strings[2];\r
+       UINT id = 0;\r
+       UINT typeapi = 0;\r
+       // 引数チェック\r
+       if (g == NULL || type >= 5 || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       strings[0] = str;\r
+\r
+       switch (type)\r
+       {\r
+       case MS_EVENTLOG_TYPE_INFORMATION:\r
+               id = MS_RC_EVENTLOG_TYPE_INFORMATION;\r
+               typeapi = EVENTLOG_INFORMATION_TYPE;\r
+               break;\r
+\r
+       case MS_EVENTLOG_TYPE_WARNING:\r
+               id = MS_RC_EVENTLOG_TYPE_WARNING;\r
+               typeapi = EVENTLOG_WARNING_TYPE;\r
+               break;\r
+\r
+       case MS_EVENTLOG_TYPE_ERROR:\r
+               id = MS_RC_EVENTLOG_TYPE_ERROR;\r
+               typeapi = EVENTLOG_ERROR_TYPE;\r
+               break;\r
+       }\r
+\r
+       return ms->nt->ReportEventW(g->hEventLog, typeapi, 0, id, NULL, 1, 0, strings, NULL);\r
+}\r
+\r
+// イベントログの解放\r
+void MsFreeEventLog(void *p)\r
+{\r
+       MS_EVENTLOG *g = (MS_EVENTLOG *)p;\r
+       // 引数チェック\r
+       if (g == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ms->nt->DeregisterEventSource(g->hEventLog);\r
+\r
+       Free(g);\r
+}\r
+\r
+// イベントログの初期化\r
+void *MsInitEventLog(wchar_t *src_name)\r
+{\r
+       MS_EVENTLOG *g;\r
+       HANDLE h;\r
+       wchar_t keyname[MAX_PATH];\r
+       char keyname_a[MAX_PATH];\r
+       wchar_t *exename;\r
+       // 引数チェック\r
+       if (src_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // レジストリにキーを書き込む\r
+       exename = MsGetExeFileNameW();\r
+       UniFormat(keyname, sizeof(keyname),\r
+               L"SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\%s",\r
+               src_name);\r
+       UniToStr(keyname_a, sizeof(keyname_a), keyname);\r
+\r
+       MsRegWriteStrExpandExW(REG_LOCAL_MACHINE, keyname_a, "EventMessageFile",\r
+               exename, false);\r
+\r
+       MsRegWriteIntEx(REG_LOCAL_MACHINE, keyname_a, "TypesSupported", 7, false);\r
+\r
+       h = ms->nt->RegisterEventSourceW(NULL, src_name);\r
+       if (h == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       g = ZeroMalloc(sizeof(MS_EVENTLOG));\r
+\r
+       g->hEventLog = h;\r
+\r
+       return (void *)g;\r
+}\r
+\r
+// クリップボードを空にする\r
+void MsDeleteClipboard()\r
+{\r
+       OpenClipboard(NULL);\r
+\r
+       EmptyClipboard();\r
+\r
+       CloseClipboard();\r
+}\r
+\r
+// クリップボード所有者のプロセス ID を取得する\r
+UINT MsGetClipboardOwnerProcessId()\r
+{\r
+       HWND hWnd = GetClipboardOwner();\r
+       DWORD pid = 0;\r
+\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       GetWindowThreadProcessId(hWnd, &pid);\r
+\r
+       return pid;\r
+}\r
+\r
+// MMCSS の再起動\r
+// 注意: この実装は完璧ではない。\r
+void MsRestartMMCSS()\r
+{\r
+       MsStopService("CTAudSvcService");\r
+       MsStopService("audiosrv");\r
+       MsStopService("MMCSS");\r
+       MsStartService("MMCSS");\r
+       MsStartService("audiosrv");\r
+       MsStartService("CTAudSvcService");\r
+}\r
+\r
+// MMCSS によるネットワークスロットリングを有効 / 無効にする\r
+void MsSetMMCSSNetworkThrottlingEnable(bool enable)\r
+{\r
+       UINT value;\r
+       if (MsIsVista() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (enable)\r
+       {\r
+               value = 0x0000000a;\r
+       }\r
+       else\r
+       {\r
+               value = 0xffffffff;\r
+       }\r
+\r
+       MsRegWriteIntEx2(REG_LOCAL_MACHINE, MMCSS_PROFILE_KEYNAME, "NetworkThrottlingIndex",\r
+               value,\r
+               false, true);\r
+\r
+       MsRestartMMCSS();\r
+}\r
+\r
+// MMCSS によるネットワークスロットリングが有効になっているかどうか調査\r
+bool MsIsMMCSSNetworkThrottlingEnabled()\r
+{\r
+       UINT value;\r
+       if (MsIsVista() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsRegIsKeyEx2(REG_LOCAL_MACHINE, MMCSS_PROFILE_KEYNAME, false, true) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       value = MsRegReadIntEx2(REG_LOCAL_MACHINE, MMCSS_PROFILE_KEYNAME,\r
+               "NetworkThrottlingIndex", false, true);\r
+\r
+       if (value == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (value == 0x0000000a)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// サブキーをすべて削除する\r
+void MsRegDeleteSubkeys(UINT root, char *keyname, bool force32bit, bool force64bit)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (keyname == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = MsRegEnumKeyEx2(root, keyname, force32bit, force64bit);\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               char tmp[MAX_PATH];\r
+\r
+               Format(tmp, sizeof(tmp), "%s\\%s", keyname, t->Token[i]);\r
+\r
+               MsRegDeleteKeyEx2(root, tmp, force32bit, force64bit);\r
+       }\r
+\r
+       FreeToken(t);\r
+}\r
+\r
+// バッファのデータをレジストリのサブキーに変換する\r
+void MsBufToRegSubkeys(UINT root, char *keyname, BUF *b, bool overwrite, bool force32bit, bool force64bit)\r
+{\r
+       UINT i;\r
+       UINT a;\r
+       UINT num_keys;\r
+       // 引数チェック\r
+       if (keyname == NULL || b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       num_keys = ReadBufInt(b);\r
+\r
+       for (i = 0;i < num_keys;i++)\r
+       {\r
+               char subkeyname[MAX_PATH];\r
+               char fullkeyname[MAX_PATH];\r
+               UINT j;\r
+               UINT num_values;\r
+\r
+               Zero(subkeyname, sizeof(subkeyname));\r
+               ReadBufStr(b, subkeyname, sizeof(subkeyname));\r
+\r
+               Format(fullkeyname, sizeof(fullkeyname), "%s\\%s", keyname, subkeyname);\r
+\r
+               num_values = ReadBufInt(b);\r
+\r
+               for (j = 0;j < num_values;j++)\r
+               {\r
+                       char valuename[MAX_PATH];\r
+                       char data[MAX_SIZE];\r
+\r
+                       Zero(valuename, sizeof(valuename));\r
+                       ReadBufStr(b, valuename, sizeof(valuename));\r
+\r
+                       a = ReadBufInt(b);\r
+\r
+                       if (a == 0)\r
+                       {\r
+                               Zero(data, sizeof(data));\r
+                               ReadBufStr(b, data, sizeof(data));\r
+\r
+                               if (overwrite || MsRegIsValueEx2(root, fullkeyname, valuename, force32bit, force64bit) == false)\r
+                               {\r
+                                       MsRegWriteStrEx2(root, fullkeyname, valuename, data, force32bit, force64bit);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               if (overwrite || MsRegIsValueEx2(root, fullkeyname, valuename, force32bit, force64bit) == false)\r
+                               {\r
+                                       MsRegWriteIntEx2(root, fullkeyname, valuename, ReadBufInt(b), force32bit, force64bit);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// レジストリのサブキーのデータをバッファに変換する\r
+BUF *MsRegSubkeysToBuf(UINT root, char *keyname, bool force32bit, bool force64bit)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (keyname == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t = MsRegEnumKeyEx2(root, keyname, force32bit, force64bit);\r
+\r
+       if (t == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+\r
+       WriteBufInt(b, t->NumTokens);\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               char *name = t->Token[i];\r
+               char tmp[MAX_PATH];\r
+               TOKEN_LIST *v;\r
+\r
+               Format(tmp, sizeof(tmp), "%s\\%s", keyname, name);\r
+\r
+               WriteBufStr(b, name);\r
+\r
+               v = MsRegEnumValueEx2(root, tmp, force32bit, force64bit);\r
+               if (v == NULL)\r
+               {\r
+                       WriteBufInt(b, 0);\r
+               }\r
+               else\r
+               {\r
+                       UINT j;\r
+\r
+                       WriteBufInt(b, v->NumTokens);\r
+\r
+                       for (j = 0;j < v->NumTokens;j++)\r
+                       {\r
+                               char *valuename = v->Token[j];\r
+                               char *str;\r
+\r
+                               WriteBufStr(b, valuename);\r
+\r
+                               str = MsRegReadStrEx2(root, tmp, valuename, force32bit, force64bit);\r
+                               if (str != NULL)\r
+                               {\r
+                                       WriteBufInt(b, 0);\r
+                                       WriteBufStr(b, str);\r
+                                       Free(str);\r
+                               }\r
+                               else\r
+                               {\r
+                                       WriteBufInt(b, 1);\r
+                                       WriteBufInt(b, MsRegReadIntEx2(root, tmp, valuename, force32bit, force64bit));\r
+                               }\r
+                       }\r
+\r
+                       FreeToken(v);\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return b;\r
+}\r
+\r
+// 指定した EXE ファイル名のプロセスが存在しているかどうかチェック\r
+bool MsIsProcessExists(char *exename)\r
+{\r
+       LIST *o;\r
+       bool ret = false;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (exename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       o = MsGetProcessList();\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               MS_PROCESS *proc = LIST_DATA(o, i);\r
+               char exe[MAX_PATH];\r
+\r
+               GetFileNameFromFilePath(exe, sizeof(exe), proc->ExeFilename);\r
+\r
+               if (StrCmpi(exename, exe) == 0)\r
+               {\r
+                       ret = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       MsFreeProcessList(o);\r
+\r
+       return ret;\r
+}\r
+bool MsIsProcessExistsW(wchar_t *exename)\r
+{\r
+       LIST *o;\r
+       bool ret = false;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (exename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       o = MsGetProcessList();\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               MS_PROCESS *proc = LIST_DATA(o, i);\r
+               wchar_t exe[MAX_PATH];\r
+\r
+               GetFileNameFromFilePathW(exe, sizeof(exe), proc->ExeFilenameW);\r
+\r
+               if (UniStrCmpi(exename, exe) == 0)\r
+               {\r
+                       ret = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       MsFreeProcessList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+typedef struct _ASTAT_\r
+{\r
+       ADAPTER_STATUS adapt;\r
+       NAME_BUFFER    NameBuff[30];\r
+} ASTAT, *PASTAT;\r
+\r
+// 高精度カウンタの値から精密な時間を取得する\r
+double MsGetHiResTimeSpan(UINT64 diff)\r
+{\r
+       LARGE_INTEGER t;\r
+       UINT64 freq;\r
+\r
+       if (QueryPerformanceFrequency(&t) == false)\r
+       {\r
+               freq = 1000ULL;\r
+       }\r
+       else\r
+       {\r
+               Copy(&freq, &t, sizeof(UINT64));\r
+       }\r
+\r
+       return (double)diff / (double)freq;\r
+}\r
+UINT64 MsGetHiResTimeSpanUSec(UINT64 diff)\r
+{\r
+       LARGE_INTEGER t;\r
+       UINT64 freq;\r
+\r
+       if (QueryPerformanceFrequency(&t) == false)\r
+       {\r
+               freq = 1000ULL;\r
+       }\r
+       else\r
+       {\r
+               Copy(&freq, &t, sizeof(UINT64));\r
+       }\r
+\r
+       return (UINT64)(diff) * 1000ULL * 1000ULL / (UINT64)freq;\r
+}\r
+\r
+// 高精度カウンタを取得する\r
+UINT64 MsGetHiResCounter()\r
+{\r
+       LARGE_INTEGER t;\r
+       UINT64 ret;\r
+\r
+       if (QueryPerformanceCounter(&t) == false)\r
+       {\r
+               return Tick64();\r
+       }\r
+\r
+       Copy(&ret, &t, sizeof(UINT64));\r
+\r
+       return ret;\r
+}\r
+\r
+// ようこそ画面を使用しているかどうか\r
+bool MsIsUseWelcomeLogin()\r
+{\r
+       UINT os_type;\r
+       if (MsIsNt() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       os_type = GetOsInfo()->OsType;\r
+\r
+       if (OS_IS_WINDOWS_NT(os_type))\r
+       {\r
+               if (GET_KETA(os_type, 100) == 3)\r
+               {\r
+                       if (MsRegReadIntEx2(REG_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",\r
+                               "LogonType", false, true) == 0)\r
+                       {\r
+                               return false;\r
+                       }\r
+                       else\r
+                       {\r
+                               return true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// コンピュータの物理的な MAC アドレスを 1 つ取得する\r
+bool MsGetPhysicalMacAddress(void *address)\r
+{\r
+       // 引数チェック\r
+       if (address == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsGetPhysicalMacAddressFromApi(address))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (MsGetPhysicalMacAddressFromNetbios(address))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// 物理的な MAC アドレスを取得する (API から)\r
+bool MsGetPhysicalMacAddressFromApi(void *address)\r
+{\r
+       MS_ADAPTER_LIST *o;\r
+       UINT i;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (address == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(address, 6);\r
+\r
+       o = MsCreateAdapterList();\r
+\r
+       for (i = 0;i < o->Num;i++)\r
+       {\r
+               MS_ADAPTER *a = o->Adapters[i];\r
+\r
+               if (a->AddressSize == 6 && a->Mtu == 1500)\r
+               {\r
+                       bool b = false;\r
+                       switch (a->Type)\r
+                       {\r
+                       case MIB_IF_TYPE_OTHER:\r
+                       case MIB_IF_TYPE_ETHERNET:\r
+                               b = true;\r
+                               break;\r
+\r
+                       case MIB_IF_TYPE_TOKENRING:\r
+                       case MIB_IF_TYPE_FDDI:\r
+                       case MIB_IF_TYPE_PPP:\r
+                       case MIB_IF_TYPE_LOOPBACK:\r
+                       case MIB_IF_TYPE_SLIP:\r
+                               b = false;\r
+                               break;\r
+\r
+                       default:\r
+                               b = true;\r
+                               break;\r
+                       }\r
+\r
+                       if (b)\r
+                       {\r
+                               if (SearchStrEx(a->Title, "WAN", 0, false) == INFINITE)\r
+                               {\r
+                                       if (a->Status == MIB_IF_OPER_STATUS_CONNECTED || a->Status == MIB_IF_OPER_STATUS_OPERATIONAL)\r
+                                       {\r
+                                               if (a->AddressSize == 6)\r
+                                               {\r
+                                                       if (IsZero(a->Address, 6) == false)\r
+                                                       {\r
+                                                               if (Cmp(address, a->Address, 6) <= 0)\r
+                                                               {\r
+                                                                       Copy(address, a->Address, 6);\r
+                                                                       ret = true;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       MsFreeAdapterList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 物理的な MAC アドレスを取得する (NetBIOS から)\r
+bool MsGetPhysicalMacAddressFromNetbios(void *address)\r
+{\r
+       NCB ncb;\r
+       UCHAR ret;\r
+       LANA_ENUM lenum;\r
+       UINT i;\r
+       ASTAT adapter;\r
+       bool b = false;\r
+       // 引数チェック\r
+       if (address == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&ncb, sizeof(ncb));\r
+       Zero(&lenum, sizeof(lenum));\r
+\r
+       ncb.ncb_command = NCBENUM;\r
+       ncb.ncb_buffer = (UCHAR *)&lenum;\r
+       ncb.ncb_length = sizeof(lenum);\r
+       ret = Netbios(&ncb);\r
+\r
+       Zero(address, 6);\r
+\r
+       for (i = 0;i < lenum.length;i++)\r
+       {\r
+               Zero(&ncb, sizeof(ncb));\r
+               ncb.ncb_command = NCBRESET;\r
+               ncb.ncb_lana_num = lenum.lana[i];\r
+\r
+               ret = Netbios(&ncb);\r
+\r
+               Zero(&ncb, sizeof(ncb));\r
+               ncb.ncb_command = NCBASTAT;\r
+               ncb.ncb_lana_num = lenum.lana[i];\r
+\r
+               StrCpy(ncb.ncb_callname, sizeof(ncb.ncb_callname), "*               ");\r
+               Zero(&adapter, sizeof(adapter));\r
+               ncb.ncb_buffer = (char *)&adapter;\r
+               ncb.ncb_length = sizeof(adapter);\r
+\r
+               ret = Netbios(&ncb);\r
+\r
+               if (ret == 0)\r
+               {\r
+                       if (Cmp(address, adapter.adapt.adapter_address, 6) <= 0)\r
+                       {\r
+                               Copy(address, adapter.adapt.adapter_address, 6);\r
+                               b = true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return b;\r
+}\r
+\r
+// システム全体のアップデート通知\r
+void MsUpdateSystem()\r
+{\r
+       static DWORD dw = 0;\r
+\r
+       SendMessageTimeoutA(HWND_BROADCAST, WM_WININICHANGE, 0, 0, SMTO_NORMAL, 1, (PDWORD_PTR)&dw);\r
+}\r
+\r
+// 指定されたパスがローカルドライブかどうか取得する\r
+bool MsIsLocalDrive(char *name)\r
+{\r
+       char tmp[MAX_PATH];\r
+       UINT ret;\r
+\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(tmp, sizeof(tmp));\r
+       InnerFilePath(tmp, sizeof(tmp), name);\r
+\r
+       if (StartWith(tmp, "\\\\"))\r
+       {\r
+               // ネットワークディレクトリ\r
+               return false;\r
+       }\r
+\r
+       if (tmp[1] != ':' || tmp[2] != '\\')\r
+       {\r
+               // ドライブ名でない\r
+               return false;\r
+       }\r
+\r
+       tmp[3] = 0;\r
+\r
+       ret = GetDriveType(tmp);\r
+\r
+       if (ret == DRIVE_REMOTE || ret == DRIVE_CDROM || ret == DRIVE_RAMDISK)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+bool MsIsLocalDriveW(wchar_t *name)\r
+{\r
+       char name_a[MAX_PATH];\r
+\r
+       UniToStr(name_a, sizeof(name_a), name);\r
+\r
+       return MsIsLocalDrive(name_a);\r
+}\r
+\r
+// 指定されたファイルがロックされているかどうか取得する\r
+bool MsIsFileLocked(char *name)\r
+{\r
+       HANDLE h;\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       InnerFilePath(tmp, sizeof(tmp), name);\r
+\r
+       h = CreateFile(tmp, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, NULL);\r
+       if (h == INVALID_HANDLE_VALUE)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       CloseHandle(h);\r
+\r
+       return false;\r
+}\r
+bool MsIsFileLockedW(wchar_t *name)\r
+{\r
+       HANDLE h;\r
+       wchar_t tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char name_a[MAX_SIZE];\r
+\r
+               UniToStr(name_a, sizeof(name_a), name);\r
+\r
+               return MsIsFileLocked(name_a);\r
+       }\r
+\r
+       InnerFilePathW(tmp, sizeof(tmp), name);\r
+\r
+       h = CreateFileW(tmp, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, NULL);\r
+       if (h == INVALID_HANDLE_VALUE)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       CloseHandle(h);\r
+\r
+       return false;\r
+}\r
+\r
+// プロセスの終了を待機\r
+UINT MsWaitProcessExit(void *process_handle)\r
+{\r
+       HANDLE h = (HANDLE)process_handle;\r
+       UINT ret = 1;\r
+\r
+       if (h == NULL)\r
+       {\r
+               return 1;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               WaitForSingleObject(h, INFINITE);\r
+\r
+               ret = 1;\r
+               if (GetExitCodeProcess(h, &ret) == false)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               if (ret != STILL_ACTIVE)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       CloseHandle(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// ファイルの実行 (プロセスハンドル取得)\r
+bool MsExecuteEx(char *exe, char *arg, void **process_handle)\r
+{\r
+       SHELLEXECUTEINFO info;\r
+       HANDLE h;\r
+       // 引数チェック\r
+       if (exe == NULL || process_handle == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       info.cbSize = sizeof(info);\r
+       info.lpVerb = "open";\r
+       info.lpFile = exe;\r
+       info.fMask = SEE_MASK_NOCLOSEPROCESS;\r
+       info.lpParameters = arg;\r
+       info.nShow = SW_SHOWNORMAL;\r
+       if (ShellExecuteEx(&info) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       h = info.hProcess;\r
+\r
+       *process_handle = (void *)h;\r
+\r
+       return true;\r
+}\r
+bool MsExecuteExW(wchar_t *exe, wchar_t *arg, void **process_handle)\r
+{\r
+       SHELLEXECUTEINFOW info;\r
+       HANDLE h;\r
+       // 引数チェック\r
+       if (exe == NULL || process_handle == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char exe_a[MAX_SIZE];\r
+               char arg_a[MAX_SIZE];\r
+\r
+               UniToStr(exe_a, sizeof(exe_a), exe);\r
+               UniToStr(arg_a, sizeof(arg_a), arg);\r
+\r
+               return MsExecuteEx(exe_a, arg_a, process_handle);\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       info.cbSize = sizeof(info);\r
+       info.lpVerb = L"open";\r
+       info.lpFile = exe;\r
+       info.fMask = SEE_MASK_NOCLOSEPROCESS;\r
+       info.lpParameters = arg;\r
+       info.nShow = SW_SHOWNORMAL;\r
+       if (ShellExecuteExW(&info) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       h = info.hProcess;\r
+\r
+       *process_handle = (void *)h;\r
+\r
+       return true;\r
+}\r
+\r
+// ファイルの実行\r
+bool MsExecute(char *exe, char *arg)\r
+{\r
+       DWORD d;\r
+       // 引数チェック\r
+       if (exe == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       d = (DWORD)ShellExecuteA(NULL, "open", exe, arg, MsGetExeDirName(), SW_SHOWNORMAL);\r
+\r
+       if (d > 32)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+bool MsExecuteW(wchar_t *exe, wchar_t *arg)\r
+{\r
+       DWORD d;\r
+       // 引数チェック\r
+       if (exe == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char exe_a[MAX_SIZE];\r
+               char arg_a[MAX_SIZE];\r
+\r
+               UniToStr(exe_a, sizeof(exe_a), exe);\r
+               UniToStr(arg_a, sizeof(arg_a), arg);\r
+\r
+               return MsExecute(exe_a, arg_a);\r
+       }\r
+\r
+       d = (DWORD)ShellExecuteW(NULL, L"open", exe, arg, MsGetExeDirNameW(), SW_SHOWNORMAL);\r
+\r
+       if (d > 32)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// ディレクトリの再帰作成\r
+void MsUniMakeDirEx(wchar_t *name)\r
+{\r
+       UINT wp;\r
+       wchar_t *tmp;\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tmp = ZeroMalloc(UniStrSize(name) * 2);\r
+       wp = 0;\r
+       len = UniStrLen(name);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               wchar_t c = name[i];\r
+\r
+               if (c == '\\')\r
+               {\r
+                       if (UniStrCmpi(tmp, L"\\\\") != 0 && UniStrCmpi(tmp, L"\\") != 0)\r
+                       {\r
+                               MsUniMakeDir(tmp);\r
+                       }\r
+               }\r
+\r
+               tmp[wp++] = c;\r
+       }\r
+\r
+       Free(tmp);\r
+\r
+       MsUniMakeDir(name);\r
+}\r
+void MsMakeDirEx(char *name)\r
+{\r
+       wchar_t *name_w = CopyStrToUni(name);\r
+\r
+       MsUniMakeDirEx(name_w);\r
+\r
+       Free(name_w);\r
+}\r
+\r
+// ディレクトリの作成\r
+bool MsUniMakeDir(wchar_t *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = CopyUniToStr(name);\r
+               bool ret = MsMakeDir(s);\r
+               Free(s);\r
+               return ret;\r
+       }\r
+\r
+       return CreateDirectoryW(name, NULL);\r
+}\r
+bool MsMakeDir(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return CreateDirectoryA(name, NULL);\r
+}\r
+\r
+// ディレクトリの削除\r
+bool MsUniDirectoryDelete(wchar_t *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = CopyUniToStr(name);\r
+               bool ret = MsDirectoryDelete(s);\r
+               Free(s);\r
+               return ret;\r
+       }\r
+\r
+       return RemoveDirectoryW(name);\r
+}\r
+bool MsDirectoryDelete(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return RemoveDirectoryA(name);\r
+}\r
+\r
+// ファイルの削除\r
+bool MsUniFileDelete(wchar_t *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               bool ret;\r
+               char *s = CopyUniToStr(name);\r
+               ret = MsFileDelete(s);\r
+               Free(s);\r
+               return ret;\r
+       }\r
+\r
+       return DeleteFileW(name);\r
+}\r
+bool MsFileDelete(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return DeleteFileA(name);\r
+}\r
+\r
+// 指定したファイル名がディレクトリかどうか取得する\r
+bool MsUniIsDirectory(wchar_t *name)\r
+{\r
+       DWORD ret;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               char *s = CopyUniToStr(name);\r
+               ret = MsIsDirectory(s);\r
+               Free(s);\r
+\r
+               return ret;\r
+       }\r
+\r
+       ret = GetFileAttributesW(name);\r
+       if (ret == 0xffffffff)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ret & FILE_ATTRIBUTE_DIRECTORY)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+bool MsIsDirectoryW(wchar_t *name)\r
+{\r
+       return MsUniIsDirectory(name);\r
+}\r
+bool MsIsDirectory(char *name)\r
+{\r
+       DWORD ret;\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       InnerFilePath(tmp, sizeof(tmp), name);\r
+\r
+       ret = GetFileAttributesA(tmp);\r
+       if (ret == 0xffffffff)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ret & FILE_ATTRIBUTE_DIRECTORY)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// MSI ファイルから Cabinet を取り出す\r
+bool MsExtractCabFromMsi(char *msi, char *cab)\r
+{\r
+       wchar_t msi_w[MAX_PATH];\r
+       wchar_t cab_w[MAX_PATH];\r
+\r
+       StrToUni(msi_w, sizeof(msi_w), msi);\r
+       StrToUni(cab_w, sizeof(cab_w), cab);\r
+\r
+       return MsExtractCabFromMsiW(msi_w, cab_w);\r
+}\r
+bool MsExtractCabFromMsiW(wchar_t *msi, wchar_t *cab)\r
+{\r
+       BUF *b;\r
+       bool ret = false;\r
+       UINT i;\r
+       char sign[] = {'M', 'S', 'C', 'F', 0, 0, 0, 0,};\r
+       void *pointer = NULL;\r
+       UINT current_pos = 0;\r
+       UINT sign_size;\r
+       // 引数チェック\r
+       if (msi == NULL || cab == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // MSI を読み込む\r
+       b = ReadDumpW(msi);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (b->Size < 128)\r
+       {\r
+               FreeBuf(b);\r
+               return false;\r
+       }\r
+\r
+       sign_size = sizeof(sign);\r
+\r
+       // "MSCF" を検索する\r
+       for (i = 0;i < (b->Size - sign_size);i++)\r
+       {\r
+               char *p = ((UCHAR *)b->Buf) + i;\r
+\r
+               if (Cmp(p, sign, sign_size) == 0)\r
+               {\r
+                       pointer = p;\r
+                       current_pos = i;\r
+               }\r
+       }\r
+\r
+       if (pointer != NULL)\r
+       {\r
+               UINT size = b->Size - current_pos;\r
+               BUF *b2 = NewBuf();\r
+\r
+               WriteBuf(b2, pointer, size);\r
+\r
+               ret = DumpBufW(b2, cab);\r
+\r
+               FreeBuf(b2);\r
+\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// Cabinet ファイルからファイルを取り出す\r
+bool MsExtractCab(char *cab_name, char *dest_dir_name)\r
+{\r
+       wchar_t cab_name_w[MAX_SIZE];\r
+       wchar_t dest_dir_name_w[MAX_SIZE];\r
+\r
+       StrToUni(cab_name_w, sizeof(cab_name_w), cab_name);\r
+       StrToUni(dest_dir_name_w, sizeof(dest_dir_name_w), dest_dir_name);\r
+\r
+       return MsExtractCabW(cab_name_w, dest_dir_name_w);\r
+}\r
+bool MsExtractCabW(wchar_t *cab_name, wchar_t *dest_dir_name)\r
+{\r
+       wchar_t cabarc[MAX_PATH];\r
+       wchar_t arg[MAX_PATH * 2];\r
+       wchar_t tmp[MAX_PATH];\r
+\r
+       // 引数チェック\r
+       if (cab_name == NULL || dest_dir_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsGetCabarcExeFilenameW(cabarc, sizeof(cabarc)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniStrCpy(tmp, sizeof(tmp), dest_dir_name);\r
+       if (UniEndWith(tmp, L"\\"))\r
+       {\r
+               tmp[UniStrLen(tmp) - 1] = 0;\r
+       }\r
+\r
+       UniFormat(arg, sizeof(arg),\r
+               L"-o X \"%s\" * \"%s\"\\",\r
+               cab_name,\r
+               tmp);\r
+\r
+       MakeDirW(dest_dir_name);\r
+\r
+       if (RunW(cabarc, arg, true, true) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// cabarc.exe の展開\r
+bool MsGetCabarcExeFilename(char *name, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ConbinePath(name, size, MsGetMyTempDir(), "cabarc.exe");\r
+\r
+       if (IsFileExists(name))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (FileCopy("|cabarc.exe", name) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+bool MsGetCabarcExeFilenameW(wchar_t *name, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ConbinePathW(name, size, MsGetMyTempDirW(), L"cabarc.exe");\r
+\r
+       if (IsFileExistsW(name))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (FileCopyW(L"|cabarc.exe", name) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// EXE ファイルから Cabinet ファイルを取り出す\r
+bool MsExtractCabinetFileFromExe(char *exe, char *cab)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (exe == NULL || cab == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = MsExtractResourceFromExe(exe, RT_RCDATA, "CABINET");\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (DumpBuf(b, cab) == false)\r
+       {\r
+               FreeBuf(b);\r
+\r
+               return false;\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return true;\r
+}\r
+bool MsExtractCabinetFileFromExeW(wchar_t *exe, wchar_t *cab)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (exe == NULL || cab == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = MsExtractResourceFromExeW(exe, RT_RCDATA, "CABINET");\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (DumpBufW(b, cab) == false)\r
+       {\r
+               FreeBuf(b);\r
+\r
+               return false;\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return true;\r
+}\r
+\r
+// EXE ファイルからリソースを取り出す\r
+BUF *MsExtractResourceFromExe(char *exe, char *type, char *name)\r
+{\r
+       HINSTANCE h;\r
+       HRSRC hr;\r
+       HGLOBAL hg;\r
+       UINT size;\r
+       void *data;\r
+       BUF *buf;\r
+       // 引数チェック\r
+       if (exe == NULL || type == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       h = LoadLibraryExA(exe, NULL, LOAD_LIBRARY_AS_DATAFILE);\r
+       if (h == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       hr = FindResourceA(h, name, type);\r
+       if (hr == NULL)\r
+       {\r
+               FreeLibrary(h);\r
+               return NULL;\r
+       }\r
+\r
+       hg = LoadResource(h, hr);\r
+       if (hg == NULL)\r
+       {\r
+               FreeLibrary(h);\r
+               return NULL;\r
+       }\r
+\r
+       size = SizeofResource(h, hr);\r
+       data = (void *)LockResource(hg);\r
+\r
+       buf = NewBuf();\r
+       WriteBuf(buf, data, size);\r
+\r
+       FreeResource(hg);\r
+       FreeLibrary(h);\r
+\r
+       SeekBuf(buf, 0, 0);\r
+\r
+       return buf;\r
+}\r
+BUF *MsExtractResourceFromExeW(wchar_t *exe, char *type, char *name)\r
+{\r
+       HINSTANCE h;\r
+       HRSRC hr;\r
+       HGLOBAL hg;\r
+       UINT size;\r
+       void *data;\r
+       BUF *buf;\r
+       // 引数チェック\r
+       if (exe == NULL || type == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char exe_a[MAX_PATH];\r
+\r
+               UniToStr(exe_a, sizeof(exe_a), exe);\r
+\r
+               return MsExtractResourceFromExe(exe_a, type, name);\r
+       }\r
+\r
+       h = LoadLibraryExW(exe, NULL, LOAD_LIBRARY_AS_DATAFILE);\r
+       if (h == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       hr = FindResource(h, name, type);\r
+       if (hr == NULL)\r
+       {\r
+               FreeLibrary(h);\r
+               return NULL;\r
+       }\r
+\r
+       hg = LoadResource(h, hr);\r
+       if (hg == NULL)\r
+       {\r
+               FreeLibrary(h);\r
+               return NULL;\r
+       }\r
+\r
+       size = SizeofResource(h, hr);\r
+       data = (void *)LockResource(hg);\r
+\r
+       buf = NewBuf();\r
+       WriteBuf(buf, data, size);\r
+\r
+       FreeResource(hg);\r
+       FreeLibrary(h);\r
+\r
+       SeekBuf(buf, 0, 0);\r
+\r
+       return buf;\r
+}\r
+\r
+// ファイルのバージョン情報を取得する\r
+bool MsGetFileVersion(char *name, UINT *v1, UINT *v2, UINT *v3, UINT *v4)\r
+{\r
+       void *data;\r
+       UINT size;\r
+       DWORD h;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       h = 0;\r
+       size = GetFileVersionInfoSize(name, &h);\r
+       if (size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       data = ZeroMalloc(size);\r
+\r
+       if (GetFileVersionInfoA(name, 0, size, data))\r
+       {\r
+               VS_FIXEDFILEINFO *info = NULL;\r
+               UINT info_size = 0;\r
+               if (VerQueryValueA(data, "\\", &info, &info_size))\r
+               {\r
+                       if (v1 != NULL)\r
+                       {\r
+                               *v1 = HIWORD(info->dwFileVersionMS);\r
+                       }\r
+\r
+                       if (v2 != NULL)\r
+                       {\r
+                               *v2 = LOWORD(info->dwFileVersionMS);\r
+                       }\r
+\r
+                       if (v3 != NULL)\r
+                       {\r
+                               *v3 = HIWORD(info->dwFileVersionLS);\r
+                       }\r
+\r
+                       if (v4 != NULL)\r
+                       {\r
+                               *v4 = LOWORD(info->dwFileVersionLS);\r
+                       }\r
+\r
+                       ret = true;\r
+               }\r
+       }\r
+\r
+       Free(data);\r
+\r
+       return ret;\r
+}\r
+bool MsGetFileVersionW(wchar_t *name, UINT *v1, UINT *v2, UINT *v3, UINT *v4)\r
+{\r
+       void *data;\r
+       UINT size;\r
+       DWORD h;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char name_a[MAX_PATH];\r
+\r
+               UniToStr(name_a, sizeof(name_a), name);\r
+\r
+               return MsGetFileVersion(name_a, v1, v2, v3, v4);\r
+       }\r
+\r
+       h = 0;\r
+       size = GetFileVersionInfoSizeW(name, &h);\r
+       if (size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       data = ZeroMalloc(size);\r
+\r
+       if (GetFileVersionInfoW(name, 0, size, data))\r
+       {\r
+               VS_FIXEDFILEINFO *info = NULL;\r
+               UINT info_size = 0;\r
+               if (VerQueryValue(data, "\\", &info, &info_size))\r
+               {\r
+                       if (v1 != NULL)\r
+                       {\r
+                               *v1 = HIWORD(info->dwFileVersionMS);\r
+                       }\r
+\r
+                       if (v2 != NULL)\r
+                       {\r
+                               *v2 = LOWORD(info->dwFileVersionMS);\r
+                       }\r
+\r
+                       if (v3 != NULL)\r
+                       {\r
+                               *v3 = HIWORD(info->dwFileVersionLS);\r
+                       }\r
+\r
+                       if (v4 != NULL)\r
+                       {\r
+                               *v4 = LOWORD(info->dwFileVersionLS);\r
+                       }\r
+\r
+                       ret = true;\r
+               }\r
+       }\r
+\r
+       Free(data);\r
+\r
+       return ret;\r
+}\r
+\r
+// ファイルを隠しファイルにする\r
+void MsSetFileToHidden(char *name)\r
+{\r
+       char tmp[MAX_PATH];\r
+       DWORD d;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       NormalizePath(tmp, sizeof(tmp), name);\r
+\r
+       d = GetFileAttributesA(tmp);\r
+       if (d != INVALID_FILE_ATTRIBUTES)\r
+       {\r
+               d |= FILE_ATTRIBUTE_HIDDEN;\r
+\r
+               SetFileAttributesA(tmp, d);\r
+       }\r
+}\r
+void MsSetFileToHiddenW(wchar_t *name)\r
+{\r
+       wchar_t tmp[MAX_PATH];\r
+       DWORD d;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char name_a[MAX_SIZE];\r
+\r
+               UniToStr(name_a, sizeof(name_a), name);\r
+\r
+               MsSetFileToHidden(name_a);\r
+\r
+               return;\r
+       }\r
+\r
+       NormalizePathW(tmp, sizeof(tmp), name);\r
+\r
+       d = GetFileAttributesW(tmp);\r
+       if (d != INVALID_FILE_ATTRIBUTES)\r
+       {\r
+               d |= FILE_ATTRIBUTE_HIDDEN;\r
+\r
+               SetFileAttributesW(tmp, d);\r
+       }\r
+}\r
+\r
+// スリープ防止用スレッド\r
+void MsNoSleepThread(THREAD *thread, void *param)\r
+{\r
+       MS_NOSLEEP *e;\r
+       EXECUTION_STATE (WINAPI *_SetThreadExecutionState)(EXECUTION_STATE);\r
+       HINSTANCE hKernel32;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       hKernel32 = LoadLibrary("kernel32.dll");\r
+\r
+       _SetThreadExecutionState =\r
+               (EXECUTION_STATE (__stdcall *)(EXECUTION_STATE))\r
+               GetProcAddress(hKernel32, "SetThreadExecutionState");\r
+\r
+       e = (MS_NOSLEEP *)param;\r
+\r
+       while (e->Halt == false)\r
+       {\r
+               DWORD flag = ES_SYSTEM_REQUIRED;\r
+\r
+               if (e->NoScreenSaver)\r
+               {\r
+                       flag |= ES_DISPLAY_REQUIRED;\r
+               }\r
+\r
+               if (_SetThreadExecutionState != NULL)\r
+               {\r
+                       _SetThreadExecutionState(flag);\r
+               }\r
+\r
+               Wait(e->HaltEvent, 30 * 1000);\r
+       }\r
+\r
+       FreeLibrary(hKernel32);\r
+}\r
+\r
+// スリープ防止用スレッド (Windows Vista 用)\r
+void MsNoSleepThreadVista(THREAD *thread, void *param)\r
+{\r
+       MS_NOSLEEP *e;\r
+       char *key = "Control Panel\\Desktop";\r
+       UINT64 last_set_flag = 0;\r
+       UINT last_c_x = INFINITE, last_c_y = INFINITE;\r
+       UINT64 last_mouse_move_time = 0;\r
+       EXECUTION_STATE (WINAPI *_SetThreadExecutionState)(EXECUTION_STATE);\r
+       HINSTANCE hKernel32;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       hKernel32 = LoadLibrary("kernel32.dll");\r
+\r
+       _SetThreadExecutionState =\r
+               (EXECUTION_STATE (__stdcall *)(EXECUTION_STATE))\r
+               GetProcAddress(hKernel32, "SetThreadExecutionState");\r
+\r
+       e = (MS_NOSLEEP *)param;\r
+\r
+       while (e->Halt == false)\r
+       {\r
+               DWORD flag = ES_SYSTEM_REQUIRED;\r
+               UINT64 now = Tick64();\r
+               POINT p;\r
+               bool mouse_move = false;\r
+\r
+               Zero(&p, sizeof(p));\r
+               GetCursorPos(&p);\r
+\r
+               if (p.x != last_c_x || p.y != last_c_y)\r
+               {\r
+                       if (last_c_x != INFINITE && last_c_y != INFINITE)\r
+                       {\r
+                               mouse_move = true;\r
+                       }\r
+\r
+                       last_c_x = p.x;\r
+                       last_c_y = p.y;\r
+               }\r
+\r
+               if (mouse_move)\r
+               {\r
+                       last_mouse_move_time = now;\r
+               }\r
+\r
+               if (last_mouse_move_time == 0 || (now > (last_mouse_move_time + 50000ULL)))\r
+               {\r
+                       wchar_t *active;\r
+                       wchar_t *exe;\r
+                       // マウスが 50 秒以上動かない場合はスクリーンセーバーの設定を削除する\r
+\r
+                       active = MsRegReadStrW(REG_CURRENT_USER, key, "ScreenSaveActive");\r
+                       exe = MsRegReadStrW(REG_CURRENT_USER, key, "SCRNSAVE.EXE");\r
+\r
+                       if (UniToInt(active) != 0 && UniIsEmptyStr(exe) == false)\r
+                       {\r
+                               // スクリーンセーバーが設定されている\r
+                               UniStrCpy(e->ScreenSaveActive, sizeof(e->ScreenSaveActive), active);\r
+                               UniStrCpy(e->SCRNSAVE_EXE, sizeof(e->SCRNSAVE_EXE), exe);\r
+\r
+                               MsRegWriteStrW(REG_CURRENT_USER, key, "ScreenSaveActive", L"0");\r
+                               MsRegDeleteValue(REG_CURRENT_USER, key, "SCRNSAVE.EXE");\r
+\r
+                               Debug("Push SS Settings.\n");\r
+                       }\r
+\r
+                       Free(active);\r
+                       Free(exe);\r
+\r
+                       last_mouse_move_time = now;\r
+               }\r
+               else\r
+               {\r
+                       if (mouse_move)\r
+                       {\r
+                               if (UniIsEmptyStr(e->ScreenSaveActive) == false && UniIsEmptyStr(e->SCRNSAVE_EXE) == false)\r
+                               {\r
+                                       // マウスが動いた場合でスクリーンセーバーが設定されていない場合は\r
+                                       // スクリーンセーバーの設定を復元する\r
+                                       wchar_t *active;\r
+                                       wchar_t *exe;\r
+\r
+                                       active = MsRegReadStrW(REG_CURRENT_USER, key, "ScreenSaveActive");\r
+                                       exe = MsRegReadStrW(REG_CURRENT_USER, key, "SCRNSAVE.EXE");\r
+\r
+                                       if (UniToInt(active) != 0 && UniIsEmptyStr(exe) == false)\r
+                                       {\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               MsRegWriteStrW(REG_CURRENT_USER, key, "ScreenSaveActive", e->ScreenSaveActive);\r
+                                               MsRegWriteStrW(REG_CURRENT_USER, key, "SCRNSAVE.EXE", e->SCRNSAVE_EXE);\r
+\r
+                                               Zero(e->ScreenSaveActive, sizeof(e->ScreenSaveActive));\r
+                                               Zero(e->SCRNSAVE_EXE, sizeof(e->SCRNSAVE_EXE));\r
+\r
+                                               Debug("Pop SS Settings.\n");\r
+                                       }\r
+\r
+                                       Free(active);\r
+                                       Free(exe);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (last_set_flag == 0 || (now > (last_set_flag + 50000ULL)))\r
+               {\r
+                       // フラグセット (50 秒間隔)\r
+                       last_set_flag = now;\r
+\r
+                       if (_SetThreadExecutionState != NULL)\r
+                       {\r
+                               _SetThreadExecutionState(flag);\r
+                       }\r
+               }\r
+\r
+               Wait(e->HaltEvent, 512);\r
+       }\r
+\r
+       if (true)\r
+       {\r
+               // スクリーンセーバーの設定を復元する\r
+               wchar_t *active;\r
+               wchar_t *exe;\r
+\r
+               if (UniIsEmptyStr(e->ScreenSaveActive) == false && UniIsEmptyStr(e->SCRNSAVE_EXE) == false)\r
+               {\r
+                       active = MsRegReadStrW(REG_CURRENT_USER, key, "ScreenSaveActive");\r
+                       exe = MsRegReadStrW(REG_CURRENT_USER, key, "SCRNSAVE.EXE");\r
+\r
+                       if (UniToInt(active) != 0 && UniIsEmptyStr(exe) != 0)\r
+                       {\r
+                       }\r
+                       else\r
+                       {\r
+                               MsRegWriteStrW(REG_CURRENT_USER, key, "ScreenSaveActive", e->ScreenSaveActive);\r
+                               MsRegWriteStrW(REG_CURRENT_USER, key, "SCRNSAVE.EXE", e->SCRNSAVE_EXE);\r
+\r
+                               Zero(e->ScreenSaveActive, sizeof(e->ScreenSaveActive));\r
+                               Zero(e->SCRNSAVE_EXE, sizeof(e->SCRNSAVE_EXE));\r
+\r
+                               Debug("Pop SS Settings.\n");\r
+                       }\r
+\r
+                       Free(active);\r
+                       Free(exe);\r
+               }\r
+       }\r
+\r
+       FreeLibrary(hKernel32);\r
+}\r
+\r
+// スリープ防止の開始\r
+void *MsNoSleepStart(bool no_screensaver)\r
+{\r
+       MS_NOSLEEP *e;\r
+       bool is_vista = MsIsVista();\r
+       bool is_nt_4 = false;\r
+       UINT os_type = GetOsInfo()->OsType;\r
+\r
+       if (OS_IS_WINDOWS_NT(os_type))\r
+       {\r
+               if (GET_KETA(os_type, 100) == 1)\r
+               {\r
+                       is_nt_4 = true;\r
+               }\r
+       }\r
+\r
+       e = ZeroMalloc(sizeof(MS_NOSLEEP));\r
+\r
+       e->HaltEvent = NewEvent();\r
+       e->NoScreenSaver = no_screensaver;\r
+\r
+       if (e->NoScreenSaver == false || (is_vista == false && is_nt_4 == false))\r
+       {\r
+               e->Thread = NewThread(MsNoSleepThread, e);\r
+       }\r
+       else\r
+       {\r
+               e->Thread = NewThread(MsNoSleepThreadVista, e);\r
+       }\r
+\r
+       return (void *)e;\r
+}\r
+\r
+// スリープ防止の停止\r
+void MsNoSleepEnd(void *p)\r
+{\r
+       MS_NOSLEEP *e;\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       e = (MS_NOSLEEP *)p;\r
+\r
+       e->Halt = true;\r
+       Set(e->HaltEvent);\r
+\r
+       WaitThread(e->Thread, INFINITE);\r
+       ReleaseThread(e->Thread);\r
+       ReleaseEvent(e->HaltEvent);\r
+\r
+       Free(e);\r
+}\r
+\r
+// コンピュータ名の取得\r
+void MsGetComputerName(char *name, UINT size)\r
+{\r
+       DWORD sz;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       sz = size;\r
+       GetComputerName(name, &sz);\r
+}\r
+\r
+// マウスカーソルの位置のハッシュ値を取得\r
+UINT MsGetCursorPosHash()\r
+{\r
+       POINT p;\r
+\r
+       Zero(&p, sizeof(p));\r
+\r
+       if (GetCursorPos(&p) == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return MAKELONG((USHORT)p.x, (USHORT)p.y);\r
+}\r
+\r
+// 一般ユーザー権限としてのプロセスの起動\r
+void *MsRunAsUserEx(char *filename, char *arg, bool hide)\r
+{\r
+       void *ret = MsRunAsUserExInner(filename, arg, hide);\r
+\r
+       if (ret == NULL)\r
+       {\r
+               Debug("MsRunAsUserExInner Failed.\n");\r
+               ret = Win32RunEx(filename, arg, hide);\r
+       }\r
+\r
+       return ret;\r
+}\r
+void *MsRunAsUserExW(wchar_t *filename, wchar_t *arg, bool hide)\r
+{\r
+       void *ret = MsRunAsUserExInnerW(filename, arg, hide);\r
+\r
+       if (ret == NULL)\r
+       {\r
+               Debug("MsRunAsUserExInner Failed.\n");\r
+               ret = Win32RunExW(filename, arg, hide);\r
+       }\r
+\r
+       return ret;\r
+}\r
+void *MsRunAsUserExInner(char *filename, char *arg, bool hide)\r
+{\r
+       void *ret;\r
+       wchar_t *filename_w;\r
+       wchar_t *arg_w;\r
+\r
+       filename_w = CopyStrToUni(filename);\r
+       arg_w = CopyStrToUni(arg);\r
+\r
+       ret = MsRunAsUserExInnerW(filename_w, arg_w, hide);\r
+\r
+       Free(filename_w);\r
+       Free(arg_w);\r
+\r
+       return ret;\r
+}\r
+void *MsRunAsUserExInnerW(wchar_t *filename, wchar_t *arg, bool hide)\r
+{\r
+       STARTUPINFOW info;\r
+       PROCESS_INFORMATION ret;\r
+       wchar_t cmdline[MAX_SIZE];\r
+       wchar_t name[MAX_PATH];\r
+       HANDLE hToken;\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (MsIsVista() == false)\r
+       {\r
+               // Windows Vista 以外では使用できない\r
+               return NULL;\r
+       }\r
+\r
+       UniStrCpy(name, sizeof(name), filename);\r
+       UniTrim(name);\r
+\r
+       if (UniSearchStr(name, L"\"", 0) == INFINITE)\r
+       {\r
+               if (arg == NULL)\r
+               {\r
+                       UniFormat(cmdline, sizeof(cmdline), L"%s", name);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(cmdline, sizeof(cmdline), L"%s %s", name, arg);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (arg == NULL)\r
+               {\r
+                       UniFormat(cmdline, sizeof(cmdline), L"\"%s\"", name);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(cmdline, sizeof(cmdline), L"\"%s\" %s", name, arg);\r
+               }\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       Zero(&ret, sizeof(ret));\r
+       info.cb = sizeof(info);\r
+       info.dwFlags = STARTF_USESHOWWINDOW;\r
+       info.wShowWindow = (hide == false ? SW_SHOWDEFAULT : SW_HIDE);\r
+\r
+       UniTrim(cmdline);\r
+\r
+       hToken = MsCreateUserToken();\r
+\r
+       if (hToken == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (ms->nt->CreateProcessAsUserW(hToken, NULL, cmdline, NULL, NULL, FALSE,\r
+               (hide == false ? CREATE_NEW_CONSOLE : CREATE_NO_WINDOW | CREATE_NEW_CONSOLE) | NORMAL_PRIORITY_CLASS,\r
+               NULL, NULL, &info, &ret) == FALSE)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       CloseHandle(hToken);\r
+\r
+       CloseHandle(ret.hThread);\r
+       return ret.hProcess;\r
+}\r
+\r
+// アカウント名から SID を取得する\r
+SID *MsGetSidFromAccountName(char *name)\r
+{\r
+       SID *sid;\r
+       UINT sid_size = 4096;\r
+       char *domain_name;\r
+       UINT domain_name_size = 4096;\r
+       SID_NAME_USE use = SidTypeUser;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       sid = ZeroMalloc(sid_size);\r
+       domain_name = ZeroMalloc(domain_name_size);\r
+\r
+       if (ms->nt->LookupAccountNameA(NULL, name, sid, &sid_size, domain_name, &domain_name_size, &use) == false)\r
+       {\r
+               Free(sid);\r
+               Free(domain_name);\r
+               return NULL;\r
+       }\r
+\r
+       Free(domain_name);\r
+\r
+       return sid;\r
+}\r
+\r
+// SID を解放する\r
+void MsFreeSid(SID *sid)\r
+{\r
+       // 引数チェック\r
+       if (sid == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(sid);\r
+}\r
+\r
+// 一般ユーザーのトークンを作成する\r
+HANDLE MsCreateUserToken()\r
+{\r
+       char *medium_sid = "S-1-16-8192";\r
+       char *administrators_sid = "S-1-5-32-544";\r
+       SID *sid = NULL;\r
+       TOKEN_MANDATORY_LABEL til;\r
+       HANDLE hCurrentToken, hNewToken;\r
+       if (MsIsNt() == false)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (ms->nt->ConvertStringSidToSidA == NULL ||\r
+               ms->nt->OpenProcessToken == NULL ||\r
+               ms->nt->DuplicateTokenEx == NULL ||\r
+               ms->nt->GetTokenInformation == NULL ||\r
+               ms->nt->SetTokenInformation == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&til, sizeof(til));\r
+\r
+       if (ms->nt->ConvertStringSidToSidA(medium_sid, &sid) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       til.Label.Attributes = SE_GROUP_INTEGRITY;\r
+       til.Label.Sid = sid;\r
+\r
+       if (ms->nt->OpenProcessToken(GetCurrentProcess(), MAXIMUM_ALLOWED, &hCurrentToken) == false)\r
+       {\r
+               LocalFree(sid);\r
+               return NULL;\r
+       }\r
+\r
+       if (ms->nt->DuplicateTokenEx(hCurrentToken, MAXIMUM_ALLOWED, NULL,\r
+               SecurityImpersonation, TokenPrimary, &hNewToken) == false)\r
+       {\r
+               CloseHandle(hCurrentToken);\r
+               LocalFree(sid);\r
+               return NULL;\r
+       }\r
+\r
+       if (ms->nt->SetTokenInformation(hNewToken, VistaTokenIntegrityLevel, &til,\r
+               sizeof(TOKEN_MANDATORY_LABEL) + GetLengthSid(sid)) == false)\r
+       {\r
+               CloseHandle(hNewToken);\r
+               CloseHandle(hCurrentToken);\r
+               LocalFree(sid);\r
+               return NULL;\r
+       }\r
+\r
+       CloseHandle(hCurrentToken);\r
+       LocalFree(sid);\r
+\r
+       return hNewToken;\r
+}\r
+\r
+// ファイルのデジタル署名をチェック\r
+bool MsCheckFileDigitalSignature(HWND hWnd, char *name, bool *danger)\r
+{\r
+       wchar_t tmp[MAX_PATH];\r
+\r
+       swprintf(tmp, sizeof(tmp), L"%S", name);\r
+\r
+       return MsCheckFileDigitalSignatureW(hWnd, tmp, danger);\r
+}\r
+bool MsCheckFileDigitalSignatureW(HWND hWnd, wchar_t *name, bool *danger)\r
+{\r
+       HRESULT ret = S_OK;\r
+       wchar_t *tmp;\r
+       LONG (WINAPI *_WinVerifyTrust)(HWND, GUID *, LPVOID) = NULL;\r
+       HINSTANCE hDll;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (danger != NULL)\r
+       {\r
+               *danger = false;\r
+       }\r
+\r
+       tmp = name;\r
+\r
+       hDll = LoadLibrary("Wintrust.dll");\r
+       if (hDll == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       _WinVerifyTrust =\r
+               (LONG (__stdcall *)(HWND,GUID *,LPVOID))\r
+               GetProcAddress(hDll, "WinVerifyTrust");\r
+       if (_WinVerifyTrust == NULL)\r
+       {\r
+               FreeLibrary(hDll);\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               GUID action_id = WINTRUST_ACTION_GENERIC_VERIFY_V2;\r
+               WINTRUST_FILE_INFO file;\r
+               WINTRUST_DATA data;\r
+\r
+               Zero(&file, sizeof(file));\r
+               file.cbStruct = sizeof(file);\r
+               file.pcwszFilePath = tmp;\r
+\r
+               Zero(&data, sizeof(data));\r
+               data.cbStruct = sizeof(data);\r
+               data.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;\r
+               data.dwUIChoice = (hWnd != NULL ? WTD_UI_NOGOOD : WTD_UI_NONE);\r
+               data.dwProvFlags = WTD_REVOCATION_CHECK_CHAIN;\r
+               data.dwUnionChoice = WTD_CHOICE_FILE;\r
+               data.pFile = &file;\r
+\r
+               ret = _WinVerifyTrust(hWnd, &action_id, &data);\r
+\r
+               if (ret == ERROR_SUCCESS && danger != NULL)\r
+               {\r
+                       if (hWnd != NULL)\r
+                       {\r
+                               if (MsCheckFileDigitalSignatureW(NULL, name, NULL) == false)\r
+                               {\r
+                                       // 危険なファイルだがユーザーが [OK] を選択してしまった\r
+                                       *danger = true;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeLibrary(hDll);\r
+\r
+       if (ret != ERROR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// WoW64 リダイレクションを有効または無効にする\r
+void MsSetWow64FileSystemRedirectionEnable(bool enable)\r
+{\r
+       if (MsIs64BitWindows() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (ms->nt->Wow64EnableWow64FsRedirection == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ms->nt->Wow64EnableWow64FsRedirection(enable ? 1 : 0);\r
+}\r
+\r
+// WoW64 リダイレクションを無効にする\r
+void *MsDisableWow64FileSystemRedirection()\r
+{\r
+       void *p = NULL;\r
+       if (MsIs64BitWindows() == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (ms->nt->Wow64DisableWow64FsRedirection == NULL ||\r
+               ms->nt->Wow64RevertWow64FsRedirection == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (ms->nt->Wow64DisableWow64FsRedirection(&p) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (p == NULL)\r
+       {\r
+               p = (void *)0x12345678;\r
+       }\r
+\r
+       return p;\r
+}\r
+\r
+// WoW64 リダイレクションを元に戻す\r
+void MsRestoreWow64FileSystemRedirection(void *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (p == (void *)0x12345678)\r
+       {\r
+               p = NULL;\r
+       }\r
+       if (MsIs64BitWindows() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (ms->nt->Wow64DisableWow64FsRedirection == NULL ||\r
+               ms->nt->Wow64RevertWow64FsRedirection == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ms->nt->Wow64RevertWow64FsRedirection(p);\r
+}\r
+\r
+// 現在 x64 版 Windows が動作しているかどうか取得\r
+bool MsIsX64()\r
+{\r
+       SYSTEM_INFO info;\r
+\r
+       if (MsIs64BitWindows() == false)\r
+       {\r
+               return false;\r
+       }\r
+       if (ms->nt->GetNativeSystemInfo == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       ms->nt->GetNativeSystemInfo(&info);\r
+\r
+       if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// 現在 IA64 版 Windows が動作しているかどうか取得\r
+bool MsIsIA64()\r
+{\r
+       if (MsIs64BitWindows() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsX64())\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 64bit Windows かどうか取得\r
+bool MsIs64BitWindows()\r
+{\r
+       if (Is64())\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               if (MsIsNt() == false)\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       if (ms == NULL || ms->nt == NULL)\r
+                       {\r
+                               return false;\r
+                       }\r
+\r
+                       if (ms->nt->IsWow64Process == NULL)\r
+                       {\r
+                               return false;\r
+                       }\r
+                       else\r
+                       {\r
+                               bool b = false;\r
+                               if (ms->nt->IsWow64Process(GetCurrentProcess(), &b) == false)\r
+                               {\r
+                                       return false;\r
+                               }\r
+                               return b;\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// Windows ファイアウォール登録\r
+void MsRegistWindowsFirewallEx2(char *title, char *exe)\r
+{\r
+       char *dir = MsGetExeDirName();\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (title == NULL || exe == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ConbinePath(tmp, sizeof(tmp), dir, exe);\r
+\r
+       if (IsFileExists(tmp) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsRegistWindowsFirewallEx(title, tmp);\r
+}\r
+void MsRegistWindowsFirewall(char *title)\r
+{\r
+       // 引数チェック\r
+       if (title == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsRegistWindowsFirewallEx(title, MsGetExeFileName());\r
+}\r
+void MsRegistWindowsFirewallEx(char *title, char *exe)\r
+{\r
+       char *data =\r
+               "Option Explicit\r\nConst NET_FW_PROFILE_DOMAIN = 0\r\nConst NET_FW_PROFILE_STANDARD = 1\r\n"\r
+               "Const NET_FW_SCOPE_ALL = 0\r\nConst NET_FW_IP_VERSION_ANY = 2\r\nDim fwMgr\r\n"\r
+               "Set fwMgr = CreateObject(\"HNetCfg.FwMgr\")\r\nDim profile\r\n"\r
+               "Set profile = fwMgr.LocalPolicy.CurrentProfile\r\nDim app\r\n"\r
+               "Set app = CreateObject(\"HNetCfg.FwAuthorizedApplication\")\r\n"\r
+               "app.ProcessImageFileName = \"$PATH$\"\r\napp.Name = \"$TITLE$\"\r\n"\r
+               "app.Scope = NET_FW_SCOPE_ALL\r\napp.IpVersion = NET_FW_IP_VERSION_ANY\r\n"\r
+               "app.Enabled = TRUE\r\nOn Error Resume Next\r\nprofile.AuthorizedApplications."\r
+               "Add app\r\n";\r
+       char *tmp;\r
+       UINT tmp_size;\r
+       char filename[MAX_PATH];\r
+       char cscript[MAX_PATH];\r
+       char arg[MAX_PATH];\r
+       UINT ostype;\r
+       IO *o;\r
+       char hash[MAX_PATH];\r
+       UCHAR hashbin[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (title == NULL || exe == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // OS チェック (Windows XP, Windows Server 2003, Windows Vista, Windows 7 以外では実施しない)\r
+       ostype = GetOsInfo()->OsType;\r
+       if (OS_IS_WINDOWS_NT(ostype) == false)\r
+       {\r
+               return;\r
+       }\r
+       if (GET_KETA(ostype, 100) != 3 && GET_KETA(ostype, 100) != 4 && GET_KETA(ostype, 100) != 5 && GET_KETA(ostype, 100) != 6)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tmp_size = StrLen(data) * 4;\r
+       tmp = ZeroMalloc(tmp_size);\r
+\r
+       HashSha1(hashbin, exe, StrLen(exe));\r
+       BinToStr(hash, sizeof(hash), hashbin, 6);\r
+\r
+       ReplaceStrEx(tmp, tmp_size, data, "$TITLE$", title, false);\r
+       ReplaceStrEx(tmp, tmp_size, tmp, "$PATH$", exe, false);\r
+\r
+       Format(filename, sizeof(filename), "%s\\winfire_%s.vbs", MsGetMyTempDir(), hash);\r
+       o = FileCreate(filename);\r
+       FileWrite(o, tmp, StrLen(tmp));\r
+       FileClose(o);\r
+\r
+       Format(cscript, sizeof(cscript), "%s\\cscript.exe", MsGetSystem32Dir());\r
+       Format(arg, sizeof(arg), "\"%s\"", filename);\r
+\r
+       Run(cscript, arg, true, false);\r
+\r
+       Debug("cscript %s\n", arg);\r
+\r
+       Free(tmp);\r
+}\r
+\r
+// Vista 用ドライバインストーラの実行\r
+bool MsExecDriverInstaller(char *arg)\r
+{\r
+       wchar_t tmp[MAX_PATH];\r
+       wchar_t hamcore_dst[MAX_PATH];\r
+       wchar_t hamcore_src[MAX_PATH];\r
+       HANDLE h;\r
+       UINT retcode;\r
+       SHELLEXECUTEINFOW info;\r
+       wchar_t *src_exe;\r
+       wchar_t *arg_w;\r
+       // 引数チェック\r
+       if (arg == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniFormat(hamcore_dst, sizeof(hamcore_dst), L"%s\\hamcore.utvpn", MsGetMyTempDirW());\r
+       UniFormat(hamcore_src, sizeof(hamcore_src), L"%s\\hamcore.utvpn", MsGetExeDirNameW());\r
+\r
+       // ファイル展開\r
+       src_exe = VISTA_DRIVER_INSTALLER_SRC;\r
+\r
+       if (MsIsX64())\r
+       {\r
+               src_exe = VISTA_DRIVER_INSTALLER_SRC_X64;\r
+       }\r
+       if (MsIsIA64())\r
+       {\r
+               src_exe = VISTA_DRIVER_INSTALLER_SRC_IA64;\r
+       }\r
+\r
+       UniFormat(tmp, sizeof(tmp), VISTA_DRIVER_INSTALLER_DST, MsGetMyTempDirW());\r
+\r
+       if (FileCopyW(src_exe, tmp) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (FileCopyW(hamcore_src, hamcore_dst) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       arg_w = CopyStrToUni(arg);\r
+\r
+       // 実行\r
+       Zero(&info, sizeof(info));\r
+       info.cbSize = sizeof(info);\r
+       info.lpVerb = L"open";\r
+       info.lpFile = tmp;\r
+       info.fMask = SEE_MASK_NOCLOSEPROCESS;\r
+       info.lpParameters = arg_w;\r
+       info.nShow = SW_SHOWNORMAL;\r
+       if (ShellExecuteExW(&info) == false)\r
+       {\r
+               Free(arg_w);\r
+               return false;\r
+       }\r
+\r
+       Free(arg_w);\r
+\r
+       h = info.hProcess;\r
+       retcode = 1;\r
+\r
+       while (true)\r
+       {\r
+               // 完了まで待機\r
+               WaitForSingleObject(h, INFINITE);\r
+\r
+               // 終了コードを取得\r
+               retcode = 1;\r
+               if (GetExitCodeProcess(h, &retcode) == false)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               if (retcode != STILL_ACTIVE)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       CloseHandle(h);\r
+\r
+       if (retcode & 1)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 現在のスレッドのロケールを取得\r
+UINT MsGetThreadLocale()\r
+{\r
+       return (UINT)GetThreadLocale();\r
+}\r
+\r
+// 現在のコンソールの横幅を設定する\r
+UINT MsSetConsoleWidth(UINT size)\r
+{\r
+       HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);\r
+       CONSOLE_SCREEN_BUFFER_INFO info;\r
+       COORD c;\r
+       UINT old_x, old_y;\r
+       // 引数チェック\r
+       if (size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+       if (h == INVALID_HANDLE_VALUE)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       if (GetConsoleScreenBufferInfo(h, &info) == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       old_x = info.dwSize.X;\r
+       old_y = info.dwSize.Y;\r
+\r
+       c.X = size;\r
+       c.Y = old_y;\r
+\r
+       SetConsoleScreenBufferSize(h, c);\r
+\r
+       return old_x;\r
+}\r
+\r
+// 現在のコンソールの横幅を取得する\r
+UINT MsGetConsoleWidth()\r
+{\r
+       HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);\r
+       CONSOLE_SCREEN_BUFFER_INFO info;\r
+\r
+       if (h == INVALID_HANDLE_VALUE)\r
+       {\r
+               return 80;\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       if (GetConsoleScreenBufferInfo(h, &info) == false)\r
+       {\r
+               return 80;\r
+       }\r
+\r
+       return info.dwSize.X;\r
+}\r
+\r
+// MS-IME を無効にする\r
+bool MsDisableIme()\r
+{\r
+       HINSTANCE h;\r
+       bool ret = false;\r
+       char dll_name[MAX_PATH];\r
+       BOOL (WINAPI *_ImmDisableIME)(DWORD);\r
+\r
+       Format(dll_name, sizeof(dll_name), "%s\\imm32.dll", MsGetSystem32Dir());\r
+       h = MsLoadLibrary(dll_name);\r
+       if (h == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       _ImmDisableIME = (BOOL (__stdcall *)(DWORD))GetProcAddress(h, "ImmDisableIME");\r
+\r
+       if (_ImmDisableIME != NULL)\r
+       {\r
+               ret = _ImmDisableIME(-1);\r
+       }\r
+\r
+       FreeLibrary(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// 現在時刻を表示する\r
+void MsPrintTick()\r
+{\r
+       UINT tick = timeGetTime();\r
+       static UINT tick_init = 0;\r
+       if (tick_init == 0)\r
+       {\r
+               tick_init = tick;\r
+               tick = 0;\r
+       }\r
+       else\r
+       {\r
+               tick -= tick_init;\r
+       }\r
+\r
+       printf("[%u]\n", tick);\r
+}\r
+\r
+// LoadLibrary の hamcore 対応版 (データファイルとして読み込み)\r
+void *MsLoadLibraryAsDataFileW(wchar_t *name)\r
+{\r
+       BUF *b;\r
+       wchar_t tmp_dll_name[MAX_SIZE];\r
+       char hash_str[MAX_SIZE];\r
+       UCHAR hash[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Hash(hash, name, UniStrLen(name), true);\r
+\r
+       BinToStr(hash_str, sizeof(hash_str), hash, 4);\r
+\r
+       UniFormat(tmp_dll_name, sizeof(tmp_dll_name), L"%s\\%S.dll", MsGetMyTempDirW(), hash_str);\r
+\r
+       if (IsFileExistsW(tmp_dll_name) == false)\r
+       {\r
+               b = ReadDumpW(name);\r
+               if (b == NULL)\r
+               {\r
+                       return NULL;\r
+               }\r
+\r
+               DumpBufW(b, tmp_dll_name);\r
+               FreeBuf(b);\r
+       }\r
+\r
+       return LoadLibraryExW(tmp_dll_name, NULL, LOAD_LIBRARY_AS_DATAFILE);\r
+}\r
+void *MsLoadLibraryAsDataFile(char *name)\r
+{\r
+       wchar_t name_w[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       StrToUni(name_w, sizeof(name_w), name);\r
+\r
+       return MsLoadLibraryAsDataFileW(name_w);\r
+}\r
+\r
+// LoadLibrary の hamcore 対応版\r
+void *MsLoadLibraryW(wchar_t *name)\r
+{\r
+       BUF *b;\r
+       wchar_t tmp_dll_name[MAX_SIZE];\r
+       char hash_str[MAX_SIZE];\r
+       UCHAR hash[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Hash(hash, name, UniStrSize(name), true);\r
+\r
+       BinToStr(hash_str, sizeof(hash_str), hash, 4);\r
+\r
+       UniFormat(tmp_dll_name, sizeof(tmp_dll_name), L"%s\\%S.dll", MsGetMyTempDirW(), hash_str);\r
+\r
+       if (IsFileExistsW(tmp_dll_name) == false)\r
+       {\r
+               b = ReadDumpW(name);\r
+               if (b == NULL)\r
+               {\r
+                       return NULL;\r
+               }\r
+\r
+               DumpBufW(b, tmp_dll_name);\r
+               FreeBuf(b);\r
+       }\r
+\r
+       if (IsNt())\r
+       {\r
+               return LoadLibraryW(tmp_dll_name);\r
+       }\r
+       else\r
+       {\r
+               char tmp_dll_name_a[MAX_SIZE];\r
+               HINSTANCE ret;\r
+\r
+               UniToStr(tmp_dll_name_a, sizeof(tmp_dll_name_a), tmp_dll_name);\r
+\r
+               ret = LoadLibraryA(tmp_dll_name_a);\r
+\r
+               return ret;\r
+       }\r
+}\r
+void *MsLoadLibrary(char *name)\r
+{\r
+       wchar_t name_w[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       StrToUni(name_w, sizeof(name_w), name);\r
+\r
+       return MsLoadLibraryW(name_w);\r
+}\r
+\r
+// 単一のアダプタの取得\r
+MS_ADAPTER *MsGetAdapter(char *title)\r
+{\r
+       MS_ADAPTER_LIST *o;\r
+       MS_ADAPTER *ret = NULL;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (title == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = MsCreateAdapterList();\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < o->Num;i++)\r
+       {\r
+               if (StrCmpi(o->Adapters[i]->Title, title) == 0)\r
+               {\r
+                       ret = MsCloneAdapter(o->Adapters[i]);\r
+                       break;\r
+               }\r
+       }\r
+\r
+       MsFreeAdapterList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 32 ビットオーバーフローチェック\r
+#define        CHECK_32BIT_OVERFLOW(old_value, new_value)                              \\r
+{                                                                                                                              \\r
+       if ((old_value) > (new_value))                                                          \\r
+       {                                                                                                                       \\r
+               (new_value) += ((UINT64)4294967296ULL);                                 \\r
+       }                                                                                                                       \\r
+}\r
+\r
+// 指定したアダプタの TCP/IP 情報を取得する\r
+void MsGetAdapterTcpIpInformation(MS_ADAPTER *a)\r
+{\r
+       IP_ADAPTER_INFO *info, *info_top;\r
+       UINT info_size;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (w32net->GetAdaptersInfo == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       info_top = ZeroMalloc(sizeof(IP_ADAPTER_INFO));\r
+       info_size = sizeof(IP_ADAPTER_INFO);\r
+\r
+       ret = w32net->GetAdaptersInfo(info_top, &info_size);\r
+       if (ret == ERROR_INSUFFICIENT_BUFFER || ret == ERROR_BUFFER_OVERFLOW)\r
+       {\r
+               Free(info_top);\r
+               info_size *= 2;\r
+               info_top = ZeroMalloc(info_size);\r
+\r
+               if (w32net->GetAdaptersInfo(info_top, &info_size) != NO_ERROR)\r
+               {\r
+                       Free(info_top);\r
+                       return;\r
+               }\r
+       }\r
+       else if (ret != NO_ERROR)\r
+       {\r
+               Free(info_top);\r
+               return;\r
+       }\r
+\r
+       // 自分のエントリを検索する\r
+       info = info_top;\r
+\r
+       while (info != NULL)\r
+       {\r
+               if (info->Index == a->Index)\r
+               {\r
+                       IP_ADDR_STRING *s;\r
+\r
+                       // IP アドレス\r
+                       a->NumIpAddress = 0;\r
+                       s = &info->IpAddressList;\r
+                       while (s != NULL)\r
+                       {\r
+                               if (a->NumIpAddress < MAX_MS_ADAPTER_IP_ADDRESS)\r
+                               {\r
+                                       StrToIP(&a->IpAddresses[a->NumIpAddress], s->IpAddress.String);\r
+                                       StrToIP(&a->SubnetMasks[a->NumIpAddress], s->IpMask.String);\r
+                                       a->NumIpAddress++;\r
+                               }\r
+                               s = s->Next;\r
+                       }\r
+\r
+                       // ゲートウェイ\r
+                       a->NumGateway = 0;\r
+                       s = &info->GatewayList;\r
+                       while (s != NULL)\r
+                       {\r
+                               if (a->NumGateway < MAX_MS_ADAPTER_IP_ADDRESS)\r
+                               {\r
+                                       StrToIP(&a->Gateways[a->NumGateway], s->IpAddress.String);\r
+                                       a->NumGateway++;\r
+                               }\r
+                               s = s->Next;\r
+                       }\r
+\r
+                       // DHCP サーバー\r
+                       a->UseDhcp = (info->DhcpEnabled == 0 ? false : true);\r
+                       if (a->UseDhcp)\r
+                       {\r
+                               SYSTEMTIME st;\r
+\r
+                               StrToIP(&a->DhcpServer, info->DhcpServer.IpAddress.String);\r
+                               TimeToSystem(&st, info->LeaseObtained);\r
+                               a->DhcpLeaseStart = SystemToUINT64(&st);\r
+\r
+                               TimeToSystem(&st, info->LeaseExpires);\r
+                               a->DhcpLeaseExpires = SystemToUINT64(&st);\r
+                       }\r
+\r
+                       // WINS サーバー\r
+                       a->UseWins = info->HaveWins;\r
+                       if (a->UseWins)\r
+                       {\r
+                               StrToIP(&a->PrimaryWinsServer, info->PrimaryWinsServer.IpAddress.String);\r
+                               StrToIP(&a->SecondaryWinsServer, info->SecondaryWinsServer.IpAddress.String);\r
+                       }\r
+\r
+                       StrCpy(a->Guid, sizeof(a->Guid), info->AdapterName);\r
+\r
+                       a->Info = true;\r
+\r
+                       break;\r
+               }\r
+\r
+               info = info->Next;\r
+       }\r
+\r
+       Free(info_top);\r
+}\r
+\r
+// アダプタリストの生成\r
+MS_ADAPTER_LIST *MsCreateAdapterList()\r
+{\r
+       return MsCreateAdapterListEx(false);\r
+}\r
+MS_ADAPTER_LIST *MsCreateAdapterListEx(bool no_info)\r
+{\r
+       MS_ADAPTER_LIST *ret;\r
+\r
+       if (no_info)\r
+       {\r
+               ret = MsCreateAdapterListInnerEx(true);\r
+\r
+               return ret;\r
+       }\r
+\r
+       Lock(lock_adapter_list);\r
+       {\r
+               MS_ADAPTER_LIST *old = last_adapter_list;\r
+               UINT i;\r
+\r
+               // 新しくアダプタリストを取ってくる\r
+               ret = MsCreateAdapterListInner();\r
+\r
+               if (ret == NULL)\r
+               {\r
+                       Unlock(lock_adapter_list);\r
+                       return NULL;\r
+               }\r
+\r
+               // 取ってきたアダプタリストの各エントリについて、前回取得したものが\r
+               // 存在するかどうかチェックする\r
+               for (i = 0;i < ret->Num;i++)\r
+               {\r
+                       UINT j;\r
+                       for (j = 0;j < old->Num;j++)\r
+                       {\r
+                               MS_ADAPTER *o = old->Adapters[j];\r
+                               MS_ADAPTER *n = ret->Adapters[i];\r
+\r
+                               if (StrCmpi(o->Title, n->Title) == 0)\r
+                               {\r
+                                       // 古いもののほうが値が小さい場合、インクリメントする\r
+                                       CHECK_32BIT_OVERFLOW(o->RecvBytes, n->RecvBytes);\r
+                                       CHECK_32BIT_OVERFLOW(o->RecvPacketsBroadcast, n->RecvPacketsBroadcast);\r
+                                       CHECK_32BIT_OVERFLOW(o->RecvPacketsUnicast, n->RecvPacketsUnicast);\r
+                                       CHECK_32BIT_OVERFLOW(o->SendBytes, n->SendBytes);\r
+                                       CHECK_32BIT_OVERFLOW(o->SendPacketsBroadcast, n->SendPacketsBroadcast);\r
+                                       CHECK_32BIT_OVERFLOW(o->SendPacketsUnicast, n->SendPacketsUnicast);\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // 古いアダプタリストを解放する\r
+               MsFreeAdapterList(old);\r
+\r
+               // 新しく取得したアダプタリストのクローンを保存しておく\r
+               last_adapter_list = MsCloneAdapterList(ret);\r
+       }\r
+       Unlock(lock_adapter_list);\r
+\r
+       return ret;\r
+}\r
+\r
+// アダプタリストモジュールの初期化\r
+void MsInitAdapterListModule()\r
+{\r
+       lock_adapter_list = NewLock(NULL);\r
+\r
+       last_adapter_list = MsCreateAdapterListInner();\r
+}\r
+\r
+// アダプタリストモジュールの解放\r
+void MsFreeAdapterListModule()\r
+{\r
+       if (last_adapter_list != NULL)\r
+       {\r
+               MsFreeAdapterList(last_adapter_list);\r
+               last_adapter_list = NULL;\r
+       }\r
+\r
+       DeleteLock(lock_adapter_list);\r
+       lock_adapter_list = NULL;\r
+}\r
+\r
+// アダプタリストのクローン\r
+MS_ADAPTER_LIST *MsCloneAdapterList(MS_ADAPTER_LIST *o)\r
+{\r
+       MS_ADAPTER_LIST *ret;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(MS_ADAPTER_LIST));\r
+       ret->Num = o->Num;\r
+       ret->Adapters = ZeroMalloc(sizeof(MS_ADAPTER *) * ret->Num);\r
+\r
+       for (i = 0;i < ret->Num;i++)\r
+       {\r
+               ret->Adapters[i] = ZeroMalloc(sizeof(MS_ADAPTER));\r
+               Copy(ret->Adapters[i], o->Adapters[i], sizeof(MS_ADAPTER));\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// アダプタのクローン\r
+MS_ADAPTER *MsCloneAdapter(MS_ADAPTER *a)\r
+{\r
+       MS_ADAPTER *ret;\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(MS_ADAPTER));\r
+       Copy(ret, a, sizeof(MS_ADAPTER));\r
+\r
+       return ret;\r
+}\r
+\r
+// アダプタリストの作成\r
+MS_ADAPTER_LIST *MsCreateAdapterListInner()\r
+{\r
+       return MsCreateAdapterListInnerEx(false);\r
+}\r
+MS_ADAPTER_LIST *MsCreateAdapterListInnerEx(bool no_info)\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       UINT retcode;\r
+       MIB_IFTABLE *table;\r
+       UINT table_size = sizeof(MIB_IFTABLE);\r
+       MS_ADAPTER_LIST *ret;\r
+\r
+       table = ZeroMalloc(table_size);\r
+\r
+       if (w32net->GetIfTable == NULL)\r
+       {\r
+               return ZeroMalloc(sizeof(MS_ADAPTER_LIST));\r
+       }\r
+\r
+       retcode = w32net->GetIfTable(table, &table_size, TRUE);\r
+       if (retcode == ERROR_INSUFFICIENT_BUFFER || retcode == ERROR_BUFFER_OVERFLOW)\r
+       {\r
+               Free(table);\r
+               table_size *= 2;\r
+               table = ZeroMalloc(table_size);\r
+               if (w32net->GetIfTable(table, &table_size, TRUE) != NO_ERROR)\r
+               {\r
+                       Free(table);\r
+                       return NULL;\r
+               }\r
+       }\r
+       else if (retcode != NO_ERROR)\r
+       {\r
+               Free(table);\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       for (i = 0;i < table->dwNumEntries;i++)\r
+       {\r
+               MIB_IFROW *r = &table->table[i];\r
+               char title[MAX_PATH];\r
+               UINT num = 0;\r
+               MS_ADAPTER *a;\r
+               UINT j;\r
+\r
+               //if (r->dwOperStatus == MIB_IF_OPER_STATUS_CONNECTED || r->dwOperStatus == MIB_IF_OPER_STATUS_OPERATIONAL)\r
+               {\r
+                       //if (r->dwType & IF_TYPE_ETHERNET_CSMACD)\r
+                       {\r
+                               for (j = 1;;j++)\r
+                               {\r
+                                       UINT k;\r
+                                       bool exists;\r
+                                       if (j == 1)\r
+                                       {\r
+                                               StrCpy(title, sizeof(title), (char *)r->bDescr);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               Format(title, sizeof(title), "%s (%u)", (char *)r->bDescr, j);\r
+                                       }\r
+\r
+                                       exists = false;\r
+\r
+                                       for (k = 0;k < LIST_NUM(o);k++)\r
+                                       {\r
+                                               MS_ADAPTER *a = LIST_DATA(o, k);\r
+\r
+                                               if (StrCmpi(a->Title, title) == 0)\r
+                                               {\r
+                                                       exists = true;\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+\r
+                                       if (exists == false)\r
+                                       {\r
+                                               break;\r
+                                       }\r
+                               }\r
+\r
+                               a = ZeroMalloc(sizeof(MS_ADAPTER));\r
+\r
+                               // アダプタ情報作成\r
+                               StrCpy(a->Title, sizeof(a->Title), title);\r
+                               a->Index = r->dwIndex;\r
+                               a->Type = r->dwType;\r
+                               a->Status = r->dwOperStatus;\r
+                               a->Mtu = r->dwMtu;\r
+                               a->Speed = r->dwSpeed;\r
+                               a->AddressSize = MIN(sizeof(a->Address), r->dwPhysAddrLen);\r
+                               Copy(a->Address, r->bPhysAddr, a->AddressSize);\r
+                               a->RecvBytes = r->dwInOctets;\r
+                               a->RecvPacketsBroadcast = r->dwInNUcastPkts;\r
+                               a->RecvPacketsUnicast = r->dwInUcastPkts;\r
+                               a->SendBytes = r->dwOutOctets;\r
+                               a->SendPacketsBroadcast = r->dwOutNUcastPkts;\r
+                               a->SendPacketsUnicast = r->dwOutUcastPkts;\r
+\r
+                               // TCP/IP 情報取得\r
+                               if (no_info == false)\r
+                               {\r
+                                       MsGetAdapterTcpIpInformation(a);\r
+                               }\r
+\r
+                               Add(o, a);\r
+                       }\r
+               }\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(MS_ADAPTER_LIST));\r
+       ret->Num = LIST_NUM(o);\r
+       ret->Adapters = ToArray(o);\r
+\r
+       ReleaseList(o);\r
+       Free(table);\r
+\r
+       return ret;\r
+}\r
+\r
+// アダプタリストの解放\r
+void MsFreeAdapterList(MS_ADAPTER_LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < o->Num;i++)\r
+       {\r
+               MsFreeAdapter(o->Adapters[i]);\r
+       }\r
+       Free(o->Adapters);\r
+\r
+       Free(o);\r
+}\r
+\r
+// アダプタ情報の解放\r
+void MsFreeAdapter(MS_ADAPTER *a)\r
+{\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(a);\r
+}\r
+\r
+// アダプタの状態文字列を取得する\r
+wchar_t *MsGetAdapterStatusStr(UINT status)\r
+{\r
+       wchar_t *ret;\r
+\r
+       switch (status)\r
+       {\r
+       case MIB_IF_OPER_STATUS_NON_OPERATIONAL:\r
+               ret = _UU("MS_NON_OPERATIONAL");\r
+               break;\r
+\r
+       case MIB_IF_OPER_STATUS_UNREACHABLE:\r
+               ret = _UU("MS_UNREACHABLE");\r
+               break;\r
+\r
+       case MIB_IF_OPER_STATUS_DISCONNECTED:\r
+               ret = _UU("MS_DISCONNECTED");\r
+               break;\r
+\r
+       case MIB_IF_OPER_STATUS_CONNECTING:\r
+               ret = _UU("MS_CONNECTING");\r
+               break;\r
+\r
+       case MIB_IF_OPER_STATUS_CONNECTED:\r
+               ret = _UU("MS_CONNECTED");\r
+               break;\r
+\r
+       default:\r
+               ret = _UU("MS_OPERATIONAL");\r
+               break;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// アダプタの種類文字列を取得する\r
+wchar_t *MsGetAdapterTypeStr(UINT type)\r
+{\r
+       wchar_t *ret;\r
+\r
+       switch (type)\r
+       {\r
+       case MIB_IF_TYPE_ETHERNET:\r
+               ret = _UU("MS_ETHERNET");\r
+               break;\r
+\r
+       case MIB_IF_TYPE_TOKENRING:\r
+               ret = _UU("MS_TOKENRING");\r
+               break;\r
+\r
+       case MIB_IF_TYPE_FDDI:\r
+               ret = _UU("MS_FDDI");\r
+               break;\r
+\r
+       case MIB_IF_TYPE_PPP:\r
+               ret = _UU("MS_PPP");\r
+               break;\r
+\r
+       case MIB_IF_TYPE_LOOPBACK:\r
+               ret = _UU("MS_LOOPBACK");\r
+               break;\r
+\r
+       case MIB_IF_TYPE_SLIP:\r
+               ret = _UU("MS_SLIP");\r
+               break;\r
+\r
+       default:\r
+               ret = _UU("MS_OTHER");\r
+               break;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 自分自身の EXE の自分以外のインスタンスをすべて終了する\r
+void MsKillOtherInstance()\r
+{\r
+       MsKillOtherInstanceEx(NULL);\r
+}\r
+void MsKillOtherInstanceEx(char *exclude_svcname)\r
+{\r
+       UINT me, i;\r
+       wchar_t me_path[MAX_PATH];\r
+       wchar_t me_path_short[MAX_PATH];\r
+       LIST *o = MsGetProcessList();\r
+       UINT e_procid = 0;\r
+       UINT e_procid2 = 0;\r
+\r
+       if (exclude_svcname != NULL)\r
+       {\r
+               e_procid = MsReadCallingServiceManagerProcessId(exclude_svcname, false);\r
+               e_procid2 = MsReadCallingServiceManagerProcessId(exclude_svcname, true);\r
+       }\r
+\r
+       me = MsGetProcessId();\r
+\r
+       MsGetCurrentProcessExeNameW(me_path, sizeof(me_path));\r
+       MsGetShortPathNameW(me_path, me_path_short, sizeof(me_path_short));\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               MS_PROCESS *p = LIST_DATA(o, i);\r
+               if (p->ProcessId != me)\r
+               {\r
+                       if ((e_procid == 0 || (e_procid != p->ProcessId)) && (e_procid2 == 0 || (e_procid2 != p->ProcessId)))\r
+                       {\r
+                               wchar_t tmp[MAX_PATH];\r
+                               MsGetShortPathNameW(p->ExeFilenameW, tmp, sizeof(tmp));\r
+                               if (UniStrCmpi(me_path_short, tmp) == 0)\r
+                               {\r
+                                       MsKillProcess(p->ProcessId);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       MsFreeProcessList(o);\r
+}\r
+\r
+// 短いファイル名を取得する\r
+bool MsGetShortPathNameA(char *long_path, char *short_path, UINT short_path_size)\r
+{\r
+       // 引数チェック\r
+       if (long_path == NULL || short_path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GetShortPathNameA(long_path, short_path, short_path_size) == 0)\r
+       {\r
+               StrCpy(short_path, short_path_size, long_path);\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+bool MsGetShortPathNameW(wchar_t *long_path, wchar_t *short_path, UINT short_path_size)\r
+{\r
+       // 引数チェック\r
+       if (long_path == NULL || short_path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char short_path_a[MAX_SIZE];\r
+               char long_path_a[MAX_SIZE];\r
+               bool ret;\r
+\r
+               UniToStr(long_path_a, sizeof(long_path_a), long_path);\r
+\r
+               ret = MsGetShortPathNameA(long_path_a, short_path_a, sizeof(short_path_a));\r
+\r
+               StrToUni(short_path, short_path_size, short_path_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       if (GetShortPathNameW(long_path, short_path, short_path_size) == 0)\r
+       {\r
+               UniStrCpy(short_path, short_path_size, long_path);\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 指定したプロセスの強制終了\r
+bool MsKillProcess(UINT id)\r
+{\r
+       HANDLE h;\r
+       // 引数チェック\r
+       if (id == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       h = OpenProcess(PROCESS_TERMINATE, FALSE, id);\r
+       if (h == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (TerminateProcess(h, 0) == FALSE)\r
+       {\r
+               CloseHandle(h);\r
+               return false;\r
+       }\r
+\r
+       CloseHandle(h);\r
+\r
+       return true;\r
+}\r
+\r
+// 現在の EXE ファイル名を取得\r
+void MsGetCurrentProcessExeName(char *name, UINT size)\r
+{\r
+       UINT id;\r
+       LIST *o;\r
+       MS_PROCESS *p;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       id = MsGetCurrentProcessId();\r
+       o = MsGetProcessList();\r
+       p = MsSearchProcessById(o, id);\r
+       if (p != NULL)\r
+       {\r
+               p = MsSearchProcessById(o, id);\r
+               StrCpy(name, size, p->ExeFilename);\r
+       }\r
+       else\r
+       {\r
+               StrCpy(name, size, MsGetExeFileName());\r
+       }\r
+       MsFreeProcessList(o);\r
+}\r
+void MsGetCurrentProcessExeNameW(wchar_t *name, UINT size)\r
+{\r
+       UINT id;\r
+       LIST *o;\r
+       MS_PROCESS *p;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       id = MsGetCurrentProcessId();\r
+       o = MsGetProcessList();\r
+       p = MsSearchProcessById(o, id);\r
+       if (p != NULL)\r
+       {\r
+               p = MsSearchProcessById(o, id);\r
+               UniStrCpy(name, size, p->ExeFilenameW);\r
+       }\r
+       else\r
+       {\r
+               UniStrCpy(name, size, MsGetExeFileNameW());\r
+       }\r
+       MsFreeProcessList(o);\r
+}\r
+\r
+// プロセスをプロセス ID から検索する\r
+MS_PROCESS *MsSearchProcessById(LIST *o, UINT id)\r
+{\r
+       MS_PROCESS *p, t;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.ProcessId = id;\r
+\r
+       p = Search(o, &t);\r
+\r
+       return p;\r
+}\r
+\r
+// プロセスリスト比較\r
+int MsCompareProcessList(void *p1, void *p2)\r
+{\r
+       MS_PROCESS *e1, *e2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       e1 = *(MS_PROCESS **)p1;\r
+       e2 = *(MS_PROCESS **)p2;\r
+       if (e1 == NULL || e2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (e1->ProcessId > e2->ProcessId)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (e1->ProcessId < e2->ProcessId)\r
+       {\r
+               return -1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+// プロセスリストの表示\r
+void MsPrintProcessList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               MS_PROCESS *p = LIST_DATA(o, i);\r
+               UniPrint(L"%-4u: %s\n", p->ProcessId, p->ExeFilenameW);\r
+       }\r
+}\r
+\r
+// プロセスリストの解放\r
+void MsFreeProcessList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               MS_PROCESS *p = LIST_DATA(o, i);\r
+               Free(p);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// プロセスリストの取得 (WinNT 用)\r
+LIST *MsGetProcessListNt()\r
+{\r
+       LIST *o;\r
+       UINT max = 16384;\r
+       DWORD *processes;\r
+       UINT needed, num;\r
+       UINT i;\r
+\r
+       o = NewListFast(MsCompareProcessList);\r
+\r
+       if (ms->nt->EnumProcesses == NULL)\r
+       {\r
+               return o;\r
+       }\r
+\r
+       processes = ZeroMalloc(sizeof(DWORD) * max);\r
+\r
+       if (ms->nt->EnumProcesses(processes, sizeof(DWORD) * max, &needed) == FALSE)\r
+       {\r
+               Free(processes);\r
+               return NULL;\r
+       }\r
+\r
+       num = needed / sizeof(DWORD);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               UINT id = processes[i];\r
+               HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\r
+                       false, id);\r
+\r
+               if (h != NULL)\r
+               {\r
+                       HINSTANCE hInst = NULL;\r
+                       DWORD needed;\r
+                       if (ms->nt->EnumProcessModules(h, &hInst, sizeof(hInst), &needed))\r
+                       {\r
+                               MS_PROCESS *p = ZeroMalloc(sizeof(MS_PROCESS));\r
+                               ms->nt->GetModuleFileNameExA(h, hInst, p->ExeFilename, sizeof(p->ExeFilename) - 1);\r
+                               ms->nt->GetModuleFileNameExW(h, hInst, p->ExeFilenameW, sizeof(p->ExeFilenameW) / sizeof(wchar_t) - 1);\r
+                               p->ProcessId = id;\r
+                               Add(o, p);\r
+                       }\r
+                       CloseHandle(h);\r
+               }\r
+       }\r
+\r
+       Sort(o);\r
+\r
+       Free(processes);\r
+\r
+       return o;\r
+}\r
+\r
+// プロセスリストの取得 (Win9x 用)\r
+LIST *MsGetProcessList9x()\r
+{\r
+       HANDLE h;\r
+       LIST *o;\r
+       HANDLE (WINAPI *CreateToolhelp32Snapshot)(DWORD, DWORD);\r
+       BOOL (WINAPI *Process32First)(HANDLE, LPPROCESSENTRY32);\r
+       BOOL (WINAPI *Process32Next)(HANDLE, LPPROCESSENTRY32);\r
+\r
+       CreateToolhelp32Snapshot =\r
+               (HANDLE (__stdcall *)(DWORD,DWORD))\r
+               GetProcAddress(ms->hKernel32, "CreateToolhelp32Snapshot");\r
+       Process32First =\r
+               (BOOL (__stdcall *)(HANDLE,LPPROCESSENTRY32))\r
+               GetProcAddress(ms->hKernel32, "Process32First");\r
+       Process32Next =\r
+               (BOOL (__stdcall *)(HANDLE,LPPROCESSENTRY32))\r
+               GetProcAddress(ms->hKernel32, "Process32Next");\r
+\r
+       o = NewListFast(MsCompareProcessList);\r
+\r
+       if (CreateToolhelp32Snapshot != NULL && Process32First != NULL && Process32Next != NULL)\r
+       {\r
+               h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\r
+               if (h != INVALID_HANDLE_VALUE)\r
+               {\r
+                       PROCESSENTRY32 e;\r
+                       Zero(&e, sizeof(e));\r
+                       e.dwSize = sizeof(e);\r
+\r
+                       if (Process32First(h, &e))\r
+                       {\r
+                               while (true)\r
+                               {\r
+                                       MS_PROCESS *p = ZeroMalloc(sizeof(MS_PROCESS));\r
+                                       StrCpy(p->ExeFilename, sizeof(p->ExeFilename), e.szExeFile);\r
+                                       StrToUni(p->ExeFilenameW, sizeof(p->ExeFilenameW), p->ExeFilename);\r
+                                       p->ProcessId = e.th32ProcessID;\r
+                                       Add(o, p);\r
+                                       if (Process32Next(h, &e) == false)\r
+                                       {\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+                       CloseHandle(h);\r
+               }\r
+       }\r
+\r
+       Sort(o);\r
+\r
+       return o;\r
+}\r
+\r
+// プロセスリストの取得\r
+LIST *MsGetProcessList()\r
+{\r
+       if (MsIsNt() == false)\r
+       {\r
+               // Windows 9x\r
+               return MsGetProcessList9x();\r
+       }\r
+       else\r
+       {\r
+               // Windows NT, 2000, XP\r
+               return MsGetProcessListNt();\r
+       }\r
+}\r
+\r
+// 現在のスレッドを 1 つの CPU で動作するように強制する\r
+void MsSetThreadSingleCpu()\r
+{\r
+       SetThreadAffinityMask(GetCurrentThread(), 1);\r
+}\r
+\r
+// サウンドの再生\r
+void MsPlaySound(char *name)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       char wav[MAX_SIZE];\r
+       char *temp;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), "|%s", name);\r
+\r
+       b = ReadDump(tmp);\r
+       if (b == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       temp = MsGetMyTempDir();\r
+       Format(wav, sizeof(tmp), "%s\\%s", temp, name);\r
+       DumpBuf(b, wav);\r
+\r
+       PlaySound(wav, NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// タスクトレイにアイコンを表示する\r
+void MsShowIconOnTray(HWND hWnd, HICON icon, wchar_t *tooltip, UINT msg)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL || icon == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               Zero(&nid, sizeof(nid));\r
+               nid.cbSize = sizeof(nid);\r
+               nid.hWnd = hWnd;\r
+               nid.uID = 1;\r
+               nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO;\r
+               nid.uCallbackMessage = msg;\r
+               nid.hIcon = icon;\r
+               UniToStr(nid.szTip, sizeof(nid.szTip), tooltip);\r
+               Shell_NotifyIcon(NIM_ADD, &nid);\r
+       }\r
+       else\r
+       {\r
+               Zero(&nid_nt, sizeof(nid_nt));\r
+               nid_nt.cbSize = sizeof(nid_nt);\r
+               nid_nt.hWnd = hWnd;\r
+               nid_nt.uID = 1;\r
+               nid_nt.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO;\r
+               nid_nt.uCallbackMessage = msg;\r
+               nid_nt.hIcon = icon;\r
+               UniStrCpy(nid_nt.szTip, sizeof(nid_nt.szTip), tooltip);\r
+               Shell_NotifyIconW(NIM_ADD, &nid_nt);\r
+       }\r
+\r
+       tray_inited = true;\r
+}\r
+\r
+// タスクトレイが初期化されているかどうか確認する\r
+bool MsIsTrayInited()\r
+{\r
+       return tray_inited;\r
+}\r
+\r
+// タスクトレイのアイコンを復元する\r
+void MsRestoreIconOnTray()\r
+{\r
+       if (tray_inited == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               Shell_NotifyIcon(NIM_ADD, &nid);\r
+       }\r
+       else\r
+       {\r
+               Shell_NotifyIconW(NIM_ADD, &nid_nt);\r
+       }\r
+}\r
+\r
+// タスクトレイのアイコンを変更する (いけー)\r
+void MsChangeIconOnTrayEx2(void *icon, wchar_t *tooltip, wchar_t *info_title, wchar_t *info, UINT info_flags)\r
+{\r
+       MsChangeIconOnTrayEx((HICON)icon, tooltip, info_title, info, info_flags);\r
+}\r
+\r
+// タスクトレイのアイコンを変更する\r
+void MsChangeIconOnTray(HICON icon, wchar_t *tooltip)\r
+{\r
+       MsChangeIconOnTrayEx(icon, tooltip, NULL, NULL, NIIF_NONE);\r
+}\r
+void MsChangeIconOnTrayEx(HICON icon, wchar_t *tooltip, wchar_t *info_title, wchar_t *info, UINT info_flags)\r
+{\r
+       bool changed = false;\r
+\r
+       if (tray_inited == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (icon != NULL)\r
+       {\r
+               if (MsIsNt() == false)\r
+               {\r
+                       if (nid.hIcon != icon)\r
+                       {\r
+                               changed = true;\r
+                               nid.hIcon = icon;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if (nid_nt.hIcon != icon)\r
+                       {\r
+                               changed = true;\r
+                               nid_nt.hIcon = icon;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (tooltip != NULL)\r
+       {\r
+               if (MsIsNt() == false)\r
+               {\r
+                       char tmp[MAX_SIZE];\r
+\r
+                       UniToStr(tmp, sizeof(tmp), tooltip);\r
+\r
+                       if (StrCmp(nid.szTip, tmp) != 0)\r
+                       {\r
+                               StrCpy(nid.szTip, sizeof(nid.szTip), tmp);\r
+                               changed = true;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       wchar_t tmp[MAX_SIZE];\r
+\r
+                       UniStrCpy(tmp, sizeof(tmp), tooltip);\r
+\r
+                       if (UniStrCmp(nid_nt.szTip, tmp) != 0)\r
+                       {\r
+                               UniStrCpy(nid_nt.szTip, sizeof(nid_nt.szTip), tmp);\r
+                               changed = true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (info_title != NULL && info != NULL)\r
+       {\r
+               if (MsIsNt() == false)\r
+               {\r
+                       char tmp1[MAX_SIZE];\r
+                       char tmp2[MAX_PATH];\r
+\r
+                       UniToStr(tmp1, sizeof(tmp1), info_title);\r
+                       UniToStr(tmp2, sizeof(tmp2), info);\r
+\r
+                       if (StrCmp(nid.szInfo, tmp1) != 0 ||\r
+                               StrCmp(nid.szInfoTitle, tmp2) != 0)\r
+                       {\r
+                               StrCpy(nid.szInfo, sizeof(nid.szInfo), tmp1);\r
+                               StrCpy(nid.szInfoTitle, sizeof(nid.szInfoTitle), tmp2);\r
+                               nid.dwInfoFlags = info_flags;\r
+\r
+                               changed = true;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       wchar_t tmp1[MAX_SIZE];\r
+                       wchar_t tmp2[MAX_PATH];\r
+\r
+                       UniStrCpy(tmp1, sizeof(tmp1), info_title);\r
+                       UniStrCpy(tmp2, sizeof(tmp2), info);\r
+\r
+                       if (UniStrCmp(nid_nt.szInfo, tmp1) != 0 ||\r
+                               UniStrCmp(nid_nt.szInfoTitle, tmp2) != 0)\r
+                       {\r
+                               UniStrCpy(nid_nt.szInfo, sizeof(nid_nt.szInfo), tmp1);\r
+                               UniStrCpy(nid_nt.szInfoTitle, sizeof(nid_nt.szInfoTitle), tmp2);\r
+                               nid_nt.dwInfoFlags = info_flags;\r
+\r
+                               changed = true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (changed)\r
+       {\r
+               if (MsIsNt() == false)\r
+               {\r
+                       Shell_NotifyIcon(NIM_MODIFY, &nid);\r
+               }\r
+               else\r
+               {\r
+                       Shell_NotifyIconW(NIM_MODIFY, &nid_nt);\r
+               }\r
+       }\r
+}\r
+\r
+// タスクトレイのアイコンを削除する\r
+void MsHideIconOnTray()\r
+{\r
+       if (MsIsNt() == false)\r
+       {\r
+               Shell_NotifyIcon(NIM_DELETE, &nid);\r
+       }\r
+       else\r
+       {\r
+               Shell_NotifyIconW(NIM_DELETE, &nid_nt);\r
+       }\r
+\r
+       tray_inited = false;\r
+}\r
+\r
+// メニュー項目の挿入\r
+bool MsInsertMenu(HMENU hMenu, UINT pos, UINT flags, UINT_PTR id_new_item, wchar_t *lp_new_item)\r
+{\r
+       bool ret;\r
+\r
+       if (MsIsNt())\r
+       {\r
+               ret = InsertMenuW(hMenu, pos, flags, id_new_item, lp_new_item);\r
+       }\r
+       else\r
+       {\r
+               char *s = CopyUniToStr(lp_new_item);\r
+               ret = InsertMenuA(hMenu, pos, flags, id_new_item, s);\r
+               Free(s);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// メニュー項目の追加\r
+bool MsAppendMenu(HMENU hMenu, UINT flags, UINT_PTR id, wchar_t *str)\r
+{\r
+       bool ret;\r
+\r
+       if (MsIsNt())\r
+       {\r
+               ret = AppendMenuW(hMenu, flags, id, str);\r
+       }\r
+       else\r
+       {\r
+               char *s = CopyUniToStr(str);\r
+               ret = AppendMenuA(hMenu, flags, id, s);\r
+               Free(s);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// メニュー表示\r
+void MsUserModeTrayMenu(HWND hWnd)\r
+{\r
+       HMENU h;\r
+       POINT p;\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t caption[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メニューを作成する\r
+       h = CreatePopupMenu();\r
+       MsAppendMenu(h, MF_ENABLED | MF_STRING, 10001, _UU("SVC_USERMODE_MENU_1"));\r
+       MsAppendMenu(h, MF_SEPARATOR, 10002, NULL);\r
+\r
+       if (MsIsNt())\r
+       {\r
+               GetWindowTextW(hWnd, caption, sizeof(caption));\r
+       }\r
+       else\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               GetWindowTextA(hWnd, tmp, sizeof(tmp));\r
+               StrToUni(caption, sizeof(caption), tmp);\r
+       }\r
+\r
+       UniFormat(tmp, sizeof(tmp), _UU("SVC_USERMODE_MENU_2"), caption);\r
+       MsAppendMenu(h, MF_ENABLED | MF_STRING, 10003, tmp);\r
+\r
+       // メニューを表示する\r
+       GetCursorPos(&p);\r
+\r
+       SetForegroundWindow(hWnd);\r
+       TrackPopupMenu(h, TPM_LEFTALIGN, p.x, p.y, 0, hWnd, NULL);\r
+       PostMessage(hWnd, WM_NULL, 0, 0);\r
+\r
+       DestroyMenu(h);\r
+}\r
+\r
+// ユーザーモード用ウインドウプロシージャ\r
+LRESULT CALLBACK MsUserModeWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       char title[MAX_SIZE];\r
+       wchar_t title_w[MAX_SIZE];\r
+       char value_name[MAX_SIZE];\r
+       static UINT taskbar_msg = 0;\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (msg == taskbar_msg && taskbar_msg != 0)\r
+       {\r
+               // タスクバーが再生成された\r
+               if (MsRegReadInt(REG_CURRENT_USER, SVC_USERMODE_SETTING_KEY, value_name) == 0 &&\r
+                       service_for_9x_mode == false)\r
+               {\r
+                       MsRestoreIconOnTray();\r
+               }\r
+       }\r
+\r
+       switch (msg)\r
+       {\r
+       case WM_ENDSESSION:\r
+               // 再開\r
+               if (wParam == false)\r
+               {\r
+                       break;\r
+               }\r
+       case WM_CREATE:\r
+               // 開始\r
+               exiting = false;\r
+               g_start();\r
+               GetWindowText(hWnd, title, sizeof(title));\r
+               StrToUni(title_w, sizeof(title_w), title);\r
+               UniFormat(tmp, sizeof(tmp), _UU("SVC_TRAY_TOOLTIP"), title);\r
+\r
+               if (taskbar_msg == 0)\r
+               {\r
+                       taskbar_msg = RegisterWindowMessage("TaskbarCreated");\r
+               }\r
+\r
+               Format(value_name, sizeof(value_name), SVC_HIDETRAY_REG_VALUE, title_w);\r
+               if (MsRegReadInt(REG_CURRENT_USER, SVC_USERMODE_SETTING_KEY, value_name) == 0 &&\r
+                       service_for_9x_mode == false)\r
+               {\r
+                       MsShowIconOnTray(hWnd, tray_icon, tmp, WM_APP + 33);\r
+               }\r
+\r
+               break;\r
+       case WM_APP + 33:\r
+               if (wParam == 1)\r
+               {\r
+                       // タスクトレイのアイコンに対する操作\r
+                       switch (lParam)\r
+                       {\r
+                       case WM_RBUTTONDOWN:\r
+                               // 右クリック\r
+                               MsUserModeTrayMenu(hWnd);\r
+                               break;\r
+                       case WM_LBUTTONDBLCLK:\r
+                               // 左ダブルクリック\r
+                               break;\r
+                       }\r
+               }\r
+               break;\r
+       case WM_LBUTTONDOWN:\r
+               MsUserModeTrayMenu(hWnd);\r
+               break;\r
+       case WM_QUERYENDSESSION:\r
+               if (exiting == false)\r
+               {\r
+                       exiting = true;\r
+                       MsHideIconOnTray();\r
+                       g_stop();\r
+                       DestroyWindow(hWnd);\r
+               }\r
+               return TRUE;\r
+       case WM_CLOSE:\r
+               // 停止\r
+               if (exiting == false)\r
+               {\r
+                       exiting = true;\r
+                       g_stop();\r
+                       MsHideIconOnTray();\r
+                       DestroyWindow(hWnd);\r
+               }\r
+               break;\r
+       case WM_DESTROY:\r
+               wnd_end = true;\r
+               break;\r
+       case WM_COMMAND:\r
+               switch (wParam)\r
+               {\r
+               case 10001:\r
+                       GetWindowText(hWnd, title, sizeof(title));\r
+                       StrToUni(title_w, sizeof(title_w), title);\r
+                       // 確認メッセージの表示\r
+                       if (MsgBoxEx(hWnd, MB_ICONINFORMATION | MB_OKCANCEL | MB_DEFBUTTON2 |\r
+                               MB_SYSTEMMODAL, _UU("SVC_HIDE_TRAY_MSG"), title, title) == IDOK)\r
+                       {\r
+                               char tmp[MAX_SIZE];\r
+                               Format(tmp, sizeof(tmp), SVC_HIDETRAY_REG_VALUE, title_w);\r
+                               // レジストリに書き込む\r
+                               MsRegWriteInt(REG_CURRENT_USER, SVC_USERMODE_SETTING_KEY, tmp, 1);\r
+                               // アイコンを消す\r
+                               MsHideIconOnTray();\r
+                       }\r
+                       break;\r
+               case 10003:\r
+                       SendMessage(hWnd, WM_CLOSE, 0, 0);\r
+                       break;\r
+               }\r
+               break;\r
+       }\r
+       return DefWindowProc(hWnd, msg, wParam, lParam);\r
+}\r
+\r
+// PenCore.dll の名前の取得\r
+char *MsGetPenCoreDllFileName()\r
+{\r
+       return PENCORE_DLL_NAME;\r
+}\r
+\r
+// これがユーザーモードかどうか取得\r
+bool MsIsUserMode()\r
+{\r
+       return is_usermode;\r
+}\r
+\r
+// サービス側からユーザーモードの終了を指示\r
+void MsStopUserModeFromService()\r
+{\r
+       if (hWndUsermode != NULL)\r
+       {\r
+               PostMessage(hWndUsermode, WM_CLOSE, 0, 0);\r
+       }\r
+}\r
+\r
+// テストのみ実行 (デバッグ用)\r
+void MsTestOnly()\r
+{\r
+       g_start();\r
+       GetLine(NULL, 0);\r
+       g_stop();\r
+\r
+       _exit(0);\r
+}\r
+\r
+// ユーザーモードとして起動\r
+void MsUserMode(char *title, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop, UINT icon)\r
+{\r
+       wchar_t *title_w = CopyStrToUni(title);\r
+\r
+       MsUserModeW(title_w, start, stop, icon);\r
+\r
+       Free(title_w);\r
+}\r
+void MsUserModeW(wchar_t *title, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop, UINT icon)\r
+{\r
+       WNDCLASS wc;\r
+       HINSTANCE hDll;\r
+       HWND hWnd;\r
+       MSG msg;\r
+       INSTANCE *inst;\r
+       char title_a[MAX_PATH];\r
+       // 引数チェック\r
+       if (title == NULL || start == NULL || stop == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniToStr(title_a, sizeof(title_a), title);\r
+\r
+       is_usermode = true;\r
+       g_start = start;\r
+       g_stop = stop;\r
+\r
+       inst = NewSingleInstance(NULL);\r
+       if (inst == NULL)\r
+       {\r
+               if (service_for_9x_mode == false)\r
+               {\r
+                       // Win9x サービスモードの場合はエラーを表示しない\r
+                       MsgBoxEx(NULL, MB_ICONINFORMATION, _UU("SVC_USERMODE_MUTEX"), ms->ExeFileNameW);\r
+               }\r
+               return;\r
+       }\r
+\r
+       if (Is64())\r
+       {\r
+               hDll = MsLoadLibraryAsDataFile(MsGetPenCoreDllFileName());\r
+       }\r
+       else\r
+       {\r
+               hDll = MsLoadLibrary(MsGetPenCoreDllFileName());\r
+       }\r
+\r
+       // アイコン読み込み\r
+       tray_icon = LoadImage(hDll, MAKEINTRESOURCE(icon), IMAGE_ICON, 16, 16,\r
+               (MsIsNt() ? LR_SHARED : 0) | LR_VGACOLOR);\r
+\r
+       // メインウインドウの作成\r
+       Zero(&wc, sizeof(wc));\r
+       wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);\r
+       wc.hCursor = LoadCursor(NULL,IDC_ARROW);\r
+       wc.hIcon = LoadIcon(hDll, MAKEINTRESOURCE(icon));\r
+       wc.hInstance = ms->hInst;\r
+       wc.lpfnWndProc = MsUserModeWindowProc;\r
+       wc.lpszClassName = title_a;\r
+       if (RegisterClass(&wc) == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       hWnd = CreateWindow(title_a, title_a, WS_OVERLAPPEDWINDOW,\r
+               CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,\r
+               NULL, NULL, ms->hInst, NULL);\r
+\r
+       if (hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       hWndUsermode = hWnd;\r
+\r
+       wnd_end = false;\r
+       // ウインドウループ\r
+       while (wnd_end == false)\r
+       {\r
+               GetMessage(&msg, NULL, 0, 0);\r
+               TranslateMessage(&msg);\r
+               DispatchMessage(&msg);\r
+       }\r
+\r
+       FreeSingleInstance(inst);\r
+\r
+       hWndUsermode = NULL;\r
+\r
+       // 強制終了して良い\r
+       _exit(0);\r
+}\r
+\r
+// サービス停止処理メインスレッド\r
+void MsServiceStoperMainThread(THREAD *t, void *p)\r
+{\r
+       // 停止処理\r
+       g_stop();\r
+}\r
+\r
+// サービス停止処理用スレッド\r
+void MsServiceStoperThread(THREAD *t, void *p)\r
+{\r
+       THREAD *thread;\r
+       UINT64 selfkill_timeout = Tick64() + SVC_SELFKILL_TIMEOUT;\r
+\r
+       thread = NewThread(MsServiceStoperMainThread, NULL);\r
+\r
+       // まだ開始中の場合は開始スレッドの終了を待つ\r
+       while (WaitThread(starter_thread, 250) == false)\r
+       {\r
+               if (Tick64() >= selfkill_timeout)\r
+               {\r
+                       // フリーズ時用の自殺\r
+                       _exit(0);\r
+               }\r
+               // 開始処理が完了するまでの間、一定時間ごとに SetServiceStatus を呼び出す\r
+               status.dwWin32ExitCode = 0;\r
+               status.dwWaitHint = 100000;\r
+               status.dwCheckPoint++;\r
+               status.dwCurrentState = SERVICE_STOP_PENDING;\r
+               ms->nt->SetServiceStatus(ssh, &status);\r
+       }\r
+\r
+       ReleaseThread(starter_thread);\r
+       starter_thread = NULL;\r
+\r
+       while (WaitThread(thread, 250) == false)\r
+       {\r
+               if (Tick64() >= selfkill_timeout)\r
+               {\r
+                       // フリーズ時用の自殺\r
+                       _exit(0);\r
+               }\r
+               // 停止処理が完了するまでの間、一定時間ごとに SetServiceStatus を呼び出す\r
+               status.dwWin32ExitCode = 0;\r
+               status.dwWaitHint = 100000;\r
+               status.dwCheckPoint++;\r
+               status.dwCurrentState = SERVICE_STOP_PENDING;\r
+               ms->nt->SetServiceStatus(ssh, &status);\r
+       }\r
+\r
+       ReleaseThread(thread);\r
+\r
+       // 停止が完了したことを報告する\r
+       status.dwWin32ExitCode = 0;\r
+       status.dwWaitHint = 0;\r
+       status.dwCheckPoint = 0;\r
+       status.dwCurrentState = SERVICE_STOPPED;\r
+       ms->nt->SetServiceStatus(ssh, &status);\r
+\r
+       Set(server_stopped_event);\r
+}\r
+\r
+// サービスハンドラ\r
+void CALLBACK MsServiceHandler(DWORD opcode)\r
+{\r
+       switch (opcode)\r
+       {\r
+       case SERVICE_CONTROL_SHUTDOWN:\r
+       case SERVICE_CONTROL_STOP:\r
+               // 停止要求\r
+               status.dwWin32ExitCode = 0;\r
+               status.dwWaitHint = 100000;\r
+               status.dwCheckPoint = 0;\r
+               status.dwCurrentState = SERVICE_STOP_PENDING;\r
+\r
+               // 停止用スレッドを立てる\r
+               service_stopper_thread = NewThread(MsServiceStoperThread, NULL);\r
+               break;\r
+       }\r
+\r
+       ms->nt->SetServiceStatus(ssh, &status);\r
+}\r
+\r
+// サービス開始用スレッド\r
+void MsServiceStarterMainThread(THREAD *t, void *p)\r
+{\r
+       // 開始\r
+       g_start();\r
+}\r
+\r
+// サービスのディスパッチ関数\r
+void CALLBACK MsServiceDispatcher(DWORD argc, LPTSTR *argv)\r
+{\r
+       // サービスの準備\r
+       Zero(&status, sizeof(status));\r
+       status.dwServiceType = SERVICE_WIN32;\r
+       status.dwCurrentState = SERVICE_START_PENDING;\r
+       status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;\r
+\r
+       ssh = ms->nt->RegisterServiceCtrlHandler(g_service_name, MsServiceHandler);\r
+\r
+       if (ssh == NULL)\r
+       {\r
+               Alert("RegisterServiceCtrlHandler() Failed.", "MsServiceDispatcher()");\r
+               return;\r
+       }\r
+\r
+       status.dwWaitHint = 10000;\r
+       status.dwCheckPoint = 0;\r
+       status.dwCurrentState = SERVICE_START_PENDING;\r
+       ms->nt->SetServiceStatus(ssh, &status);\r
+\r
+       // サービス開始用スレッドを作成する\r
+       starter_thread = NewThread(MsServiceStarterMainThread, NULL);\r
+\r
+       // 開始完了を報告する\r
+       status.dwWaitHint = 0;\r
+       status.dwCheckPoint = 0;\r
+       status.dwCurrentState = SERVICE_RUNNING;\r
+       ms->nt->SetServiceStatus(ssh, &status);\r
+}\r
+\r
+// サービスとして動作\r
+void MsServiceMode(SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop)\r
+{\r
+       SERVICE_TABLE_ENTRY dispatch_table[] =\r
+       {\r
+               {"", MsServiceDispatcher},\r
+               {NULL, NULL},\r
+       };\r
+       INSTANCE *inst;\r
+       // 引数チェック\r
+       if (start == NULL || stop == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsSetErrorModeToSilent();\r
+\r
+       g_start = start;\r
+       g_stop = stop;\r
+\r
+       server_stopped_event = NewEvent();\r
+\r
+       inst = NewSingleInstance(NULL);\r
+       if (inst == NULL)\r
+       {\r
+               MsgBoxEx(NULL, MB_SETFOREGROUND | MB_TOPMOST | MB_SERVICE_NOTIFICATION | MB_OK | MB_ICONEXCLAMATION,\r
+                       _UU("SVC_SERVICE_MUTEX"), g_service_name, ms->ExeFileNameW);\r
+               return;\r
+       }\r
+\r
+       // サービス設定を更新する\r
+       MsUpdateServiceConfig(g_service_name);\r
+\r
+       if (ms->nt->StartServiceCtrlDispatcher(dispatch_table) == false)\r
+       {\r
+               Alert("StartServiceCtrlDispatcher() Failed.", "MsServiceMode()");\r
+               return;\r
+       }\r
+\r
+       MsUpdateServiceConfig(g_service_name);\r
+\r
+       FreeSingleInstance(inst);\r
+\r
+       // サービス終了後は直ちにプロセスを終了する\r
+       Wait(server_stopped_event, INFINITE);\r
+       ReleaseEvent(server_stopped_event);\r
+       WaitThread(service_stopper_thread, INFINITE);\r
+       ReleaseThread(service_stopper_thread);\r
+       server_stopped_event = NULL;\r
+\r
+       _exit(0);\r
+}\r
+\r
+// テストモードとして起動\r
+void MsTestMode(char *title, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop)\r
+{\r
+       wchar_t *title_w = CopyStrToUni(title);\r
+\r
+       MsTestModeW(title_w, start, stop);\r
+       Free(title_w);\r
+}\r
+void MsTestModeW(wchar_t *title, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop)\r
+{\r
+       INSTANCE *inst;\r
+       // 引数チェック\r
+       if (title == NULL || start == NULL || stop == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       is_usermode = true;\r
+\r
+       inst = NewSingleInstance(NULL);\r
+       if (inst == NULL)\r
+       {\r
+               // すでに起動している\r
+               MsgBoxEx(NULL, MB_ICONINFORMATION, _UU("SVC_TEST_MUTEX"), ms->ExeFileNameW);\r
+               return;\r
+       }\r
+\r
+       // 起動\r
+       start();\r
+\r
+       // メッセージ表示\r
+       MsgBoxEx(NULL, MB_ICONINFORMATION | MB_SYSTEMMODAL, _UU("SVC_TEST_MSG"), title);\r
+\r
+       // 停止\r
+       stop();\r
+\r
+       FreeSingleInstance(inst);\r
+}\r
+\r
+// サービスマネージャを呼び出し中のプロセスのプロセス ID を書き込む\r
+void MsWriteCallingServiceManagerProcessId(char *svcname, UINT pid)\r
+{\r
+       char tmp[MAX_PATH];\r
+\r
+       Format(tmp, sizeof(tmp), SVC_CALLING_SM_PROCESS_ID_KEY, svcname);\r
+\r
+       if (pid != 0)\r
+       {\r
+               MsRegWriteInt(REG_LOCAL_MACHINE, tmp, SVC_CALLING_SM_PROCESS_ID_VALUE, pid);\r
+               MsRegWriteInt(REG_CURRENT_USER, tmp, SVC_CALLING_SM_PROCESS_ID_VALUE, pid);\r
+       }\r
+       else\r
+       {\r
+               MsRegDeleteValue(REG_LOCAL_MACHINE, tmp, SVC_CALLING_SM_PROCESS_ID_VALUE);\r
+               MsRegDeleteKey(REG_LOCAL_MACHINE, tmp);\r
+\r
+               MsRegDeleteValue(REG_CURRENT_USER, tmp, SVC_CALLING_SM_PROCESS_ID_VALUE);\r
+               MsRegDeleteKey(REG_CURRENT_USER, tmp);\r
+       }\r
+}\r
+\r
+// サービスマネージャを呼び出し中のプロセス ID を取得する\r
+UINT MsReadCallingServiceManagerProcessId(char *svcname, bool current_user)\r
+{\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (svcname == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), SVC_CALLING_SM_PROCESS_ID_KEY, svcname);\r
+\r
+       return MsRegReadInt(current_user ? REG_CURRENT_USER : REG_LOCAL_MACHINE, tmp, SVC_CALLING_SM_PROCESS_ID_VALUE);\r
+}\r
+\r
+// サービスメイン関数\r
+UINT MsService(char *name, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop, UINT icon)\r
+{\r
+       UINT mode;\r
+       UINT ret = 0;\r
+       char *arg;\r
+       wchar_t *arg_w;\r
+       TOKEN_LIST *t = NULL;\r
+       UNI_TOKEN_LIST *ut = NULL;\r
+       char *service_name;\r
+       wchar_t *service_title;\r
+       wchar_t *service_description;\r
+       wchar_t *service_title_uni;\r
+       char tmp[MAX_SIZE];\r
+       bool restoreReg = false;\r
+       bool silent = false;\r
+       // 引数チェック\r
+       if (name == NULL || start == NULL || stop == NULL)\r
+       {\r
+               return ret;\r
+       }\r
+\r
+       // Mayaqua の開始\r
+       InitMayaqua(false, false, 0, NULL);\r
+\r
+       // MS-IME の停止\r
+       MsDisableIme();\r
+\r
+       // サービスに関する情報を string table から取得\r
+       Format(tmp, sizeof(tmp), SVC_NAME, name);\r
+       service_name = _SS(tmp);\r
+       Format(tmp, sizeof(tmp), SVC_TITLE, name);\r
+       service_title = _UU(tmp);\r
+       service_title_uni = _UU(tmp);\r
+       Format(tmp, sizeof(tmp), SVC_DESCRIPT, name);\r
+       service_description = _UU(tmp);\r
+\r
+       if (StrLen(service_name) == 0 || UniStrLen(service_title) == 0)\r
+       {\r
+               // サービス情報が見つからない\r
+               MsgBoxEx(NULL, MB_ICONSTOP, _UU("SVC_NOT_FOUND"), name);\r
+       }\r
+       else\r
+       {\r
+               wchar_t path[MAX_SIZE];\r
+               // 引数のチェック\r
+               mode = SVC_MODE_NONE;\r
+\r
+               t = GetCommandLineToken();\r
+               arg = NULL;\r
+\r
+               ut = GetCommandLineUniToken();\r
+               arg_w = NULL;\r
+\r
+               if (t->NumTokens >= 1)\r
+               {\r
+                       arg = t->Token[0];\r
+               }\r
+               if(t->NumTokens >= 2)\r
+               {\r
+                       if(StrCmpi(t->Token[1], SVC_ARG_SILENT) == 0)\r
+                       {\r
+                               silent = true;\r
+                       }\r
+               }\r
+\r
+               if (ut->NumTokens >= 1)\r
+               {\r
+                       arg_w = ut->Token[0];\r
+               }\r
+\r
+               if (arg != NULL)\r
+               {\r
+                       if (StrCmpi(arg, SVC_ARG_INSTALL) == 0)\r
+                       {\r
+                               mode = SVC_MODE_INSTALL;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_UNINSTALL) == 0)\r
+                       {\r
+                               mode = SVC_MODE_UNINSTALL;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_START) == 0)\r
+                       {\r
+                               mode = SVC_MODE_START;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_STOP) == 0)\r
+                       {\r
+                               mode = SVC_MODE_STOP;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_TEST) == 0)\r
+                       {\r
+                               mode = SVC_MODE_TEST;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_USERMODE) == 0)\r
+                       {\r
+                               mode = SVC_MODE_USERMODE;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_SETUP_INSTALL) == 0)\r
+                       {\r
+                               mode = SVC_MODE_SETUP_INSTALL;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_SETUP_UNINSTALL) == 0)\r
+                       {\r
+                               mode = SVC_MODE_SETUP_UNINSTALL;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_WIN9X_SERVICE) == 0)\r
+                       {\r
+                               mode = SVC_MODE_WIN9X_SERVICE;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_WIN9X_INSTALL) == 0)\r
+                       {\r
+                               mode = SVC_MODE_WIN9X_INSTALL;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_WIN9X_UNINSTALL) == 0)\r
+                       {\r
+                               mode = SVC_MODE_WIN9X_UNINSTALL;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_TCP) == 0)\r
+                       {\r
+                               mode = SVC_MODE_TCP;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_TCP_SETUP) == 0)\r
+                       {\r
+                               mode = SVC_MODE_TCPSETUP;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_TRAFFIC) == 0)\r
+                       {\r
+                               mode = SVC_MODE_TRAFFIC;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_UIHELP) == 0)\r
+                       {\r
+                               mode = SVC_MODE_UIHELP;\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_USERMODE_SHOWTRAY) == 0)\r
+                       {\r
+                               char tmp[MAX_SIZE];\r
+                               mode = SVC_MODE_USERMODE;\r
+                               Format(tmp, sizeof(tmp), SVC_HIDETRAY_REG_VALUE, service_title);\r
+                               MsRegDeleteValue(REG_CURRENT_USER, SVC_USERMODE_SETTING_KEY, tmp);\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_USERMODE_HIDETRAY) == 0)\r
+                       {\r
+                               char tmp[MAX_SIZE];\r
+                               mode = SVC_MODE_USERMODE;\r
+                               Format(tmp, sizeof(tmp), SVC_HIDETRAY_REG_VALUE, service_title);\r
+                               MsRegWriteInt(REG_CURRENT_USER, SVC_USERMODE_SETTING_KEY, tmp, 1);\r
+                       }\r
+                       if (StrCmpi(arg, SVC_ARG_SERVICE) == 0)\r
+                       {\r
+                               mode = SVC_MODE_SERVICE;\r
+                       }\r
+\r
+                       if (mode != SVC_MODE_NONE)\r
+                       {\r
+                               // Network Config\r
+                               MsInitGlobalNetworkConfig();\r
+                       }\r
+               }\r
+\r
+               // サービスとして実行する際のコマンドライン名を取得する\r
+               UniFormat(path, sizeof(path), SVC_RUN_COMMANDLINE, ms->ExeFileNameW);\r
+\r
+               if ((mode == SVC_MODE_INSTALL || mode == SVC_MODE_UNINSTALL || mode == SVC_MODE_START ||\r
+                       mode == SVC_MODE_STOP || mode == SVC_MODE_SERVICE) &&\r
+                       (ms->IsNt == false))\r
+               {\r
+                       // Windows NT 以外で NT 系のコマンドを使用しようとした\r
+                       MsgBox(NULL, MB_ICONSTOP, _UU("SVC_NT_ONLY"));\r
+               }\r
+               else if ((mode == SVC_MODE_INSTALL || mode == SVC_MODE_UNINSTALL || mode == SVC_MODE_START ||\r
+                       mode == SVC_MODE_STOP || mode == SVC_MODE_SERVICE) &&\r
+                       (ms->IsAdmin == false))\r
+               {\r
+                       // Administrators 権限が無い\r
+                       MsgBox(NULL, MB_ICONEXCLAMATION, _UU("SVC_NOT_ADMIN"));\r
+               }\r
+               else\r
+               {\r
+                       // モードごとに処理を行う\r
+                       switch (mode)\r
+                       {\r
+                       case SVC_MODE_NONE:\r
+                               // 案内メッセージを表示して終了する\r
+                               if (arg_w != NULL && UniEndWith(arg_w, L".uvpn"))\r
+                               {\r
+                                       if (MsgBox(NULL, MB_ICONQUESTION | MB_YESNO, _UU("CM_VPN_FILE_CLICKED")) == IDYES)\r
+                                       {\r
+                                               wchar_t vpncmgr[MAX_PATH];\r
+                                               wchar_t filename[MAX_PATH];\r
+\r
+                                               UniFormat(filename, sizeof(filename), L"\"%s\"", arg_w);\r
+\r
+                                               if (Is64() == false)\r
+                                               {\r
+                                                       UniFormat(vpncmgr, sizeof(vpncmgr), L"%s\\utvpncmgr.exe", MsGetExeDirNameW());\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       UniFormat(vpncmgr, sizeof(vpncmgr), L"%s\\utvpncmgr_x64.exe", MsGetExeDirNameW());\r
+                                               }\r
+\r
+                                               RunW(vpncmgr, filename, false, false);\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       MsgBoxEx(NULL, MB_ICONINFORMATION, _UU("SVC_HELP"),\r
+                                               service_title, service_name, service_title, service_title, service_name, service_title, service_name, service_title, service_name, service_title, service_name, service_title, service_title);\r
+                               }\r
+                               break;\r
+\r
+                       case SVC_MODE_SETUP_INSTALL:\r
+                               // setup.exe インストール モード\r
+                               // 古いものをアンインストールする\r
+                               MsWriteCallingServiceManagerProcessId(service_name, MsGetCurrentProcessId());\r
+                               restoreReg = true;\r
+\r
+                               if (MsIsServiceInstalled(service_name))\r
+                               {\r
+                                       if (MsIsServiceRunning(service_name))\r
+                                       {\r
+                                               MsStopService(service_name);\r
+                                       }\r
+                                       MsUninstallService(service_name);\r
+                               }\r
+                               if (MsInstallServiceW(service_name, service_title, service_description, path) == false)\r
+                               {\r
+                                       ret = 1;\r
+                               }\r
+                               MsStartService(service_name);\r
+                               MsWriteCallingServiceManagerProcessId(service_name, 0);\r
+                               break;\r
+\r
+                       case SVC_MODE_SETUP_UNINSTALL:\r
+                               // setup.exe アンインストール モード\r
+                               MsWriteCallingServiceManagerProcessId(service_name, MsGetCurrentProcessId());\r
+                               restoreReg = true;\r
+\r
+                               if (MsIsServiceInstalled(service_name))\r
+                               {\r
+                                       if (MsIsServiceRunning(service_name))\r
+                                       {\r
+                                               MsStopService(service_name);\r
+                                       }\r
+                                       if (MsUninstallService(service_name) == false)\r
+                                       {\r
+                                               ret = 1;\r
+                                       }\r
+                               }\r
+                               break;\r
+\r
+                       case SVC_MODE_INSTALL:\r
+                               // サービスのインストール\r
+                               // すでにインストールされているかどうか確認する\r
+                               MsWriteCallingServiceManagerProcessId(service_name, MsGetCurrentProcessId());\r
+                               restoreReg = true;\r
+\r
+                               if (MsIsServiceInstalled(service_name))\r
+                               {\r
+                                       // すでにインストールされている\r
+                                       // アンインストールするかどうか確認のメッセージを表示する\r
+                                       if (silent == false)\r
+                                       {\r
+                                               if (MsgBoxEx(NULL, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("SVC_ALREADY_INSTALLED"),\r
+                                                       service_title, service_name) == IDNO)\r
+                                               {\r
+                                                       // 処理をキャンセルする\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                                       // 既存のサービスが動作しているか?\r
+                                       if (MsIsServiceRunning(service_name))\r
+                                       {\r
+                                               // 停止を試みる\r
+                                               if (MsStopService(service_name) == false)\r
+                                               {\r
+                                                       // 停止に失敗した\r
+                                                       MsgBoxEx(NULL, MB_ICONSTOP, _UU("SVC_STOP_FAILED"),\r
+                                                               service_title, service_name);\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                                       // アンインストールする\r
+                                       if (MsUninstallService(service_name) == false)\r
+                                       {\r
+                                               // アンインストールに失敗した\r
+                                               MsgBoxEx(NULL, MB_ICONSTOP, _UU("SVC_UNINSTALL_FAILED"),\r
+                                                       service_title, service_name);\r
+                                               break;\r
+                                       }\r
+                               }\r
+\r
+                               // インストールを行う\r
+                               if (MsInstallServiceW(service_name, service_title, service_description, path) == false)\r
+                               {\r
+                                       // インストールに失敗した\r
+                                       MsgBoxEx(NULL, MB_ICONSTOP, _UU("SVC_INSTALL_FAILED"),\r
+                                               service_title, service_name);\r
+                                       break;\r
+                               }\r
+\r
+                               // サービスを開始する\r
+                               if (MsStartService(service_name) == false)\r
+                               {\r
+                                       // 開始に失敗した\r
+                                       MsgBoxEx(NULL, MB_ICONEXCLAMATION, _UU("SVC_INSTALL_FAILED_2"),\r
+                                               service_title, service_name, path);\r
+                                       break;\r
+                               }\r
+\r
+                               // すべて成功した\r
+                               if(silent == false)\r
+                               {\r
+                                       MsgBoxEx(NULL, MB_ICONINFORMATION, _UU("SVC_INSTALL_OK"),\r
+                                               service_title, service_name, path);\r
+                               }\r
+                               break;\r
+\r
+                       case SVC_MODE_UNINSTALL:\r
+                               // サービスのアンインストール\r
+                               // すでにインストールされているかどうか確認する\r
+                               MsWriteCallingServiceManagerProcessId(service_name, MsGetCurrentProcessId());\r
+                               restoreReg = true;\r
+\r
+                               if (MsIsServiceInstalled(service_name) == false)\r
+                               {\r
+                                       if(silent == false)\r
+                                       {\r
+                                               MsgBoxEx(NULL, MB_ICONEXCLAMATION, _UU("SVC_NOT_INSTALLED"),\r
+                                                       service_title, service_name, path);\r
+                                       }\r
+                                       break;\r
+                               }\r
+\r
+                               // サービスが起動中の場合は停止する\r
+                               if (MsIsServiceRunning(service_name))\r
+                               {\r
+                                       // サービスを停止する\r
+                                       if (MsStopService(service_name) == false)\r
+                                       {\r
+                                               // 停止に失敗した\r
+                                               MsgBoxEx(NULL, MB_ICONSTOP, _UU("SVC_STOP_FAILED"),\r
+                                                       service_title, service_name);\r
+                                               break;\r
+                                       }\r
+                               }\r
+\r
+                               // サービスをアンインストールする\r
+                               if (MsUninstallService(service_name) == false)\r
+                               {\r
+                                       MsgBoxEx(NULL, MB_ICONSTOP, _UU("SVC_UNINSTALL_FAILED"),\r
+                                               service_title, service_name);\r
+                                       break;\r
+                               }\r
+\r
+                               // すべて成功した\r
+                               if(silent == false)\r
+                               {\r
+                                       MsgBoxEx(NULL, MB_ICONINFORMATION, _UU("SVC_UNINSTALL_OK"),\r
+                                               service_title, service_name);\r
+                               }\r
+                               break;\r
+\r
+                       case SVC_MODE_START:\r
+                               // サービスの開始\r
+                               MsWriteCallingServiceManagerProcessId(service_name, MsGetCurrentProcessId());\r
+                               restoreReg = true;\r
+\r
+                               if (MsIsServiceInstalled(service_name) == false)\r
+                               {\r
+                                       // サービスはインストールされていない\r
+                                       MsgBoxEx(NULL, MB_ICONEXCLAMATION, _UU("SVC_NOT_INSTALLED"),\r
+                                               service_title, service_name);\r
+                                       break;\r
+                               }\r
+\r
+                               // サービスが起動中かどうか確認する\r
+                               if (MsIsServiceRunning(service_name))\r
+                               {\r
+                                       // サービスが起動中\r
+                                       if(silent == false)\r
+                                       {\r
+                                               MsgBoxEx(NULL, MB_ICONINFORMATION, _UU("SVR_ALREADY_START"),\r
+                                                       service_title, service_name);\r
+                                       }\r
+                                       break;\r
+                               }\r
+\r
+                               // サービスを起動する\r
+                               if (MsStartService(service_name) == false)\r
+                               {\r
+                                       // 開始に失敗した\r
+                                       MsgBoxEx(NULL, MB_ICONEXCLAMATION, _UU("SVC_START_FAILED"),\r
+                                               service_title, service_name);\r
+                                       break;\r
+                               }\r
+\r
+                               // すべて成功した\r
+                               if(silent == false)\r
+                               {\r
+                                       MsgBoxEx(NULL, MB_ICONINFORMATION, _UU("SVC_START_OK"),\r
+                                               service_title, service_name);\r
+                               }\r
+                               break;\r
+\r
+                       case SVC_MODE_STOP:\r
+                               // サービスの停止\r
+                               MsWriteCallingServiceManagerProcessId(service_name, MsGetCurrentProcessId());\r
+                               restoreReg = true;\r
+\r
+                               if (MsIsServiceInstalled(service_name) == false)\r
+                               {\r
+                                       // サービスはインストールされていない\r
+                                       if(silent == false)\r
+                                       {\r
+                                               MsgBoxEx(NULL, MB_ICONEXCLAMATION, _UU("SVC_NOT_INSTALLED"),\r
+                                                       service_title, service_name);\r
+                                       }\r
+                                       break;\r
+                               }\r
+\r
+                               // サービスが起動中かどうか確認する\r
+                               if (MsIsServiceRunning(service_name) == false)\r
+                               {\r
+                                       // サービスが停止中\r
+                                       if(silent == false)\r
+                                       {\r
+                                               MsgBoxEx(NULL, MB_ICONINFORMATION, _UU("SVC_ALREADY_STOP"),\r
+                                                       service_title, service_name);\r
+                                       }\r
+                                       break;\r
+                               }\r
+                               // サービスを停止する\r
+                               if (MsStopService(service_name) == false)\r
+                               {\r
+                                       // 停止に失敗した\r
+                                       MsgBoxEx(NULL, MB_ICONEXCLAMATION, _UU("SVC_STOP_FAILED"),\r
+                                               service_title, service_name);\r
+                                       break;\r
+                               }\r
+\r
+                               // すべて成功した\r
+                               if(silent == false)\r
+                               {\r
+                                       MsgBoxEx(NULL, MB_ICONINFORMATION, _UU("SVC_STOP_OK"),\r
+                                               service_title, service_name);\r
+                               }\r
+                               break;\r
+\r
+                       case SVC_MODE_TEST:\r
+                               // テストモード\r
+                               MsTestModeW(service_title, start, stop);\r
+                               break;\r
+\r
+                       case SVC_MODE_WIN9X_SERVICE:\r
+                               // Win9x サービスモード\r
+                               // (タスクトレイのアイコンを無条件で非表示にする)\r
+                               if (MsIsNt())\r
+                               {\r
+                                       // Windows 2000 以降では動作させない\r
+                                       break;\r
+                               }\r
+                               service_for_9x_mode = true;\r
+                       case SVC_MODE_USERMODE:\r
+                               // ユーザーモード\r
+                               MsUserModeW(service_title, start, stop, icon);\r
+                               break;\r
+\r
+                       case SVC_MODE_WIN9X_INSTALL:\r
+                               // Win9x インストールモード\r
+                               MsWriteCallingServiceManagerProcessId(service_name, MsGetCurrentProcessId());\r
+                               restoreReg = true;\r
+\r
+                               if (MsIsNt() == false)\r
+                               {\r
+                                       // レジストリキーの追加\r
+                                       char cmdline[MAX_PATH];\r
+                                       Format(cmdline, sizeof(cmdline), "\"%s\" %s",\r
+                                               MsGetExeFileName(), SVC_ARG_WIN9X_SERVICE);\r
+                                       MsRegWriteStr(REG_LOCAL_MACHINE, WIN9X_SVC_REGKEY_1,\r
+                                               name, cmdline);\r
+                                       MsRegWriteStr(REG_LOCAL_MACHINE, WIN9X_SVC_REGKEY_2,\r
+                                               name, cmdline);\r
+\r
+                                       // 実行\r
+                                       Run(MsGetExeFileName(), SVC_ARG_WIN9X_SERVICE, false, false);\r
+                               }\r
+                               break;\r
+\r
+                       case SVC_MODE_WIN9X_UNINSTALL:\r
+                               // Win9x アンインストールモード\r
+                               MsWriteCallingServiceManagerProcessId(service_name, MsGetCurrentProcessId());\r
+                               restoreReg = true;\r
+\r
+                               if (MsIsNt() == false)\r
+                               {\r
+                                       // レジストリキーの削除\r
+                                       MsRegDeleteValue(REG_LOCAL_MACHINE, WIN9X_SVC_REGKEY_1,\r
+                                               name);\r
+                                       MsRegDeleteValue(REG_LOCAL_MACHINE, WIN9X_SVC_REGKEY_2,\r
+                                               name);\r
+\r
+                                       // 自分以外のすべてのプロセスを終了\r
+                                       MsKillOtherInstance();\r
+                               }\r
+                               break;\r
+\r
+                       case SVC_MODE_SERVICE:\r
+                               // サービスとして動作\r
+                               StrCpy(g_service_name, sizeof(g_service_name), service_name);\r
+                               MsServiceMode(start, stop);\r
+                               break;\r
+\r
+                       case SVC_MODE_TCP:\r
+                               // TCP ユーティリティ\r
+                               InitCedar();\r
+                               InitWinUi(service_title_uni, NULL, 0);\r
+                               ShowTcpIpConfigUtil(NULL, true);\r
+                               FreeWinUi();\r
+                               FreeCedar();\r
+                               break;\r
+\r
+                       case SVC_MODE_TCPSETUP:\r
+                               // TCP 最適化モード (インストーラから呼ばれる)\r
+                               InitCedar();\r
+                               InitWinUi(service_title_uni, NULL, 0);\r
+                               ShowTcpIpConfigUtil(NULL, false);\r
+                               FreeWinUi();\r
+                               FreeCedar();\r
+                               break;\r
+\r
+                       case SVC_MODE_TRAFFIC:\r
+                               // 通信スループット測定ツール\r
+                               InitCedar();\r
+                               InitWinUi(service_title_uni, NULL, 0);\r
+                               CmTraffic(NULL);\r
+                               FreeWinUi();\r
+                               FreeCedar();\r
+                               break;\r
+\r
+                       case SVC_MODE_UIHELP:\r
+                               // UI Helper の起動\r
+                               CnStart();\r
+                               break;\r
+                       }\r
+\r
+               }\r
+               FreeToken(t);\r
+               UniFreeToken(ut);\r
+\r
+               if (restoreReg)\r
+               {\r
+                       MsWriteCallingServiceManagerProcessId(service_name, 0);\r
+               }\r
+       }\r
+\r
+       FreeMayaqua();\r
+\r
+       return 0;\r
+}\r
+\r
+// 指定したセッションのユーザー名を取得する\r
+wchar_t *MsGetSessionUserName(UINT session_id)\r
+{\r
+       if (MsIsTerminalServiceInstalled() || MsIsUserSwitchingInstalled())\r
+       {\r
+               wchar_t *ret;\r
+               wchar_t *name;\r
+               UINT size = 0;\r
+               if (ms->nt->WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, session_id,\r
+                       WTSUserName, (wchar_t *)&name, &size) == false)\r
+               {\r
+                       return NULL;\r
+               }\r
+\r
+               if (name == NULL || UniStrLen(name) == 0)\r
+               {\r
+                       ret = NULL;\r
+               }\r
+               else\r
+               {\r
+                       ret = UniCopyStr(name);\r
+               }\r
+\r
+               ms->nt->WTSFreeMemory(name);\r
+\r
+               return ret;\r
+       }\r
+       return NULL;\r
+}\r
+\r
+// 現在のデスクトップが VNC で利用可能かどうか取得する\r
+bool MsIsCurrentDesktopAvailableForVnc()\r
+{\r
+       if (MsIsNt() == false)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (MsIsCurrentTerminalSessionActive() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ms->nt->OpenDesktopA == NULL ||\r
+               ms->nt->CloseDesktop == NULL ||\r
+               ms->nt->SwitchDesktop == NULL)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               HDESK hDesk = ms->nt->OpenDesktopA("default", 0, false, DESKTOP_SWITCHDESKTOP);\r
+               bool ret;\r
+\r
+               if (hDesk == NULL)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               ret = ms->nt->SwitchDesktop(hDesk);\r
+               ms->nt->CloseDesktop(hDesk);\r
+\r
+               return ret;\r
+       }\r
+}\r
+\r
+// 現在のターミナルセッションがアクティブかどうか取得する\r
+bool MsIsCurrentTerminalSessionActive()\r
+{\r
+       return MsIsTerminalSessionActive(MsGetCurrentTerminalSessionId());\r
+}\r
+\r
+// 指定したターミナルセッションがアクティブかどうか取得する\r
+bool MsIsTerminalSessionActive(UINT session_id)\r
+{\r
+       if (MsIsTerminalServiceInstalled() || MsIsUserSwitchingInstalled())\r
+       {\r
+               UINT *status = NULL;\r
+               UINT size = sizeof(status);\r
+               bool active = true;\r
+\r
+               if (ms->nt->WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, session_id,\r
+                       WTSConnectState, (wchar_t *)&status, &size) == false)\r
+               {\r
+                       return true;\r
+               }\r
+\r
+               switch (*status)\r
+               {\r
+               case WTSDisconnected:\r
+               case WTSShadow:\r
+               case WTSIdle:\r
+               case WTSDown:\r
+               case WTSReset:\r
+                       active = false;\r
+                       break;\r
+               }\r
+\r
+               ms->nt->WTSFreeMemory(status);\r
+\r
+               return active;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 現在のターミナルセッション ID を取得する\r
+UINT MsGetCurrentTerminalSessionId()\r
+{\r
+       if (MsIsTerminalServiceInstalled() || MsIsUserSwitchingInstalled())\r
+       {\r
+               UINT ret;\r
+               UINT *session_id = NULL;\r
+               UINT size = sizeof(session_id);\r
+               if (ms->nt->WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION,\r
+                       WTSSessionId, (wchar_t *)&session_id, &size) == false)\r
+               {\r
+                       return 0;\r
+               }\r
+\r
+               ret = *session_id;\r
+\r
+               ms->nt->WTSFreeMemory(session_id);\r
+\r
+               return ret;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// ターミナルサービスがインストールされていて複数セッションがログイン可能かどうか調べる\r
+bool MsIsTerminalServiceMultiUserInstalled()\r
+{\r
+       OS_INFO *info = GetOsInfo();\r
+       OSVERSIONINFOEX i;\r
+       if (MsIsTerminalServiceInstalled() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (OS_IS_SERVER(info->OsType) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&i, sizeof(i));\r
+       i.dwOSVersionInfoSize = sizeof(i);\r
+       if (GetVersionEx((OSVERSIONINFO *)&i) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (i.wSuiteMask & VER_SUITE_SINGLEUSERTS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ユーザー切り替えがインストールされているかどうか調べる\r
+bool MsIsUserSwitchingInstalled()\r
+{\r
+       OS_INFO *info = GetOsInfo();\r
+       OSVERSIONINFOEX i;\r
+\r
+       if (OS_IS_WINDOWS_NT(info->OsType) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ms->nt->WTSDisconnectSession == NULL ||\r
+               ms->nt->WTSFreeMemory == NULL ||\r
+               ms->nt->WTSQuerySessionInformation == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GET_KETA(info->OsType, 100) < 2)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&i, sizeof(i));\r
+       i.dwOSVersionInfoSize = sizeof(i);\r
+       if (GetVersionEx((OSVERSIONINFO *)&i) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (i.wSuiteMask & VER_SUITE_SINGLEUSERTS)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// リモートデスクトップを有効にする\r
+bool MsEnableRemoteDesktop()\r
+{\r
+       OS_INFO *info = GetOsInfo();\r
+\r
+       if (MsIsRemoteDesktopAvailable() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsRemoteDesktopEnabled())\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (GET_KETA(info->OsType, 100) == 2)\r
+       {\r
+               // Windows 2000\r
+               return false;\r
+       }\r
+\r
+       if (MsRegWriteInt(REG_LOCAL_MACHINE,\r
+               "SYSTEM\\CurrentControlSet\\Control\\Terminal Server",\r
+               "fDenyTSConnections", 0) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsVista())\r
+       {\r
+               if (MsRegWriteInt(REG_LOCAL_MACHINE,\r
+                       "SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp",\r
+                       "UserAuthentication", 0) == false)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// リモートデスクトップが有効かどうか調べる\r
+bool MsIsRemoteDesktopEnabled()\r
+{\r
+       OS_INFO *info = GetOsInfo();\r
+\r
+       if (MsIsRemoteDesktopAvailable() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GET_KETA(info->OsType, 100) == 2)\r
+       {\r
+               // Windows 2000\r
+               return MsIsServiceRunning("TermService");\r
+       }\r
+       else\r
+       {\r
+               // Windows XP 以降\r
+               bool b = MsRegReadInt(REG_LOCAL_MACHINE,\r
+                       "SYSTEM\\CurrentControlSet\\Control\\Terminal Server",\r
+                       "fDenyTSConnections");\r
+\r
+               if (MsIsVista() == false)\r
+               {\r
+                       return b ? false : true;\r
+               }\r
+               else\r
+               {\r
+                       if (b)\r
+                       {\r
+                               return false;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (MsRegReadInt(REG_LOCAL_MACHINE,\r
+                                       "SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp",\r
+                                       "UserAuthentication"))\r
+                               {\r
+                                       return false;\r
+                               }\r
+                               else\r
+                               {\r
+                                       return true;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// レジストリ操作によってリモートデスクトップが利用可能になるかどうか調べる\r
+bool MsIsRemoteDesktopCanEnableByRegistory()\r
+{\r
+       OS_INFO *info = GetOsInfo();\r
+       if (MsIsRemoteDesktopAvailable() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GET_KETA(info->OsType, 100) == 2)\r
+       {\r
+               // Windows 2000\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               // それ以外\r
+               return true;\r
+       }\r
+}\r
+\r
+// Windows 2000 かどうか調べる\r
+bool MsIsWin2000()\r
+{\r
+       OS_INFO *info = GetOsInfo();\r
+\r
+       if (OS_IS_WINDOWS_NT(info->OsType) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GET_KETA(info->OsType, 100) == 2)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// Windows 2000 以降かどうか調べる\r
+bool MsIsWin2000OrGreater()\r
+{\r
+       OS_INFO *info = GetOsInfo();\r
+\r
+       if (OS_IS_WINDOWS_NT(info->OsType) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GET_KETA(info->OsType, 100) >= 2)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// リモートデスクトップが利用可能かどうか調べる\r
+bool MsIsRemoteDesktopAvailable()\r
+{\r
+       OS_INFO *info = GetOsInfo();\r
+       if (MsIsTerminalServiceInstalled() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GET_KETA(info->OsType, 100) == 2)\r
+       {\r
+               // Windows 2000\r
+               if (info->OsType == 2200)\r
+               {\r
+                       // Windows 2000 Professional\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       // Windows 2000 サーバー系\r
+                       return true;\r
+               }\r
+       }\r
+       else if (GET_KETA(info->OsType, 100) == 3)\r
+       {\r
+               // Windows XP\r
+               if (info->OsType == OSTYPE_WINDOWS_XP_HOME)\r
+               {\r
+                       // Home Edition\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       // Professional Edition\r
+                       return true;\r
+               }\r
+       }\r
+       else if (GET_KETA(info->OsType, 100) == 4)\r
+       {\r
+               // Windows Server 2003\r
+               return true;\r
+       }\r
+       else if (GET_KETA(info->OsType, 100) >= 5)\r
+       {\r
+               // Windows Vista 以降\r
+               OSVERSIONINFOEX i;\r
+\r
+               Zero(&i, sizeof(i));\r
+               i.dwOSVersionInfoSize = sizeof(i);\r
+               if (GetVersionEx((OSVERSIONINFO *)&i) == false)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               if (i.wSuiteMask & VER_SUITE_PERSONAL)\r
+               {\r
+                       // Home 系\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// ターミナルサービスがインストールされているかどうか調べる\r
+bool MsIsTerminalServiceInstalled()\r
+{\r
+       OS_INFO *info = GetOsInfo();\r
+       OSVERSIONINFOEX i;\r
+\r
+       if (OS_IS_WINDOWS_NT(info->OsType) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ms->nt->WTSDisconnectSession == NULL ||\r
+               ms->nt->WTSFreeMemory == NULL ||\r
+               ms->nt->WTSQuerySessionInformation == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GET_KETA(info->OsType, 100) < 2)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&i, sizeof(i));\r
+       i.dwOSVersionInfoSize = sizeof(i);\r
+       if (GetVersionEx((OSVERSIONINFO *)&i) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (i.wSuiteMask & VER_SUITE_TERMINAL || i.wSuiteMask & VER_SUITE_SINGLEUSERTS)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// サービスを停止する\r
+bool MsStopService(char *name)\r
+{\r
+       SC_HANDLE sc, service;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (ms->IsNt == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       sc = ms->nt->OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);\r
+       if (sc == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       service = ms->nt->OpenService(sc, name, SERVICE_ALL_ACCESS);\r
+       if (service != NULL)\r
+       {\r
+               SERVICE_STATUS st;\r
+               ret = ms->nt->ControlService(service, SERVICE_CONTROL_STOP, &st);\r
+\r
+               ms->nt->CloseServiceHandle(service);\r
+       }\r
+\r
+       if (ret)\r
+       {\r
+               UINT64 end = Tick64() + 10000ULL;\r
+               while (Tick64() < end)\r
+               {\r
+                       if (MsIsServiceRunning(name) == false)\r
+                       {\r
+                               break;\r
+                       }\r
+\r
+                       SleepThread(250);\r
+               }\r
+       }\r
+\r
+       ms->nt->CloseServiceHandle(sc);\r
+       return ret;\r
+}\r
+\r
+// サービスを起動する\r
+bool MsStartService(char *name)\r
+{\r
+       return MsStartServiceEx(name, NULL);\r
+}\r
+bool MsStartServiceEx(char *name, UINT *error_code)\r
+{\r
+       SC_HANDLE sc, service;\r
+       bool ret = false;\r
+       static UINT dummy = 0;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (ms->IsNt == false)\r
+       {\r
+               return false;\r
+       }\r
+       if (error_code == NULL)\r
+       {\r
+               error_code = &dummy;\r
+       }\r
+\r
+       *error_code = 0;\r
+\r
+       sc = ms->nt->OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);\r
+       if (sc == NULL)\r
+       {\r
+               *error_code = GetLastError();\r
+               return false;\r
+       }\r
+\r
+       service = ms->nt->OpenService(sc, name, SERVICE_ALL_ACCESS);\r
+       if (service != NULL)\r
+       {\r
+               ret = ms->nt->StartService(service, 0, NULL);\r
+\r
+               ms->nt->CloseServiceHandle(service);\r
+       }\r
+       else\r
+       {\r
+               *error_code = GetLastError();\r
+       }\r
+\r
+       if (ret)\r
+       {\r
+               UINT64 end = Tick64() + 10000ULL;\r
+               while (Tick64() < end)\r
+               {\r
+                       if (MsIsServiceRunning(name))\r
+                       {\r
+                               break;\r
+                       }\r
+\r
+                       SleepThread(250);\r
+               }\r
+       }\r
+\r
+       ms->nt->CloseServiceHandle(sc);\r
+       return ret;\r
+}\r
+\r
+// サービスが起動しているかどうか取得する\r
+bool MsIsServiceRunning(char *name)\r
+{\r
+       SC_HANDLE sc, service;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (name == NULL || IsEmptyStr(name))\r
+       {\r
+               return false;\r
+       }\r
+       if (ms->IsNt == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       sc = ms->nt->OpenSCManager(NULL, NULL, GENERIC_READ);\r
+       if (sc == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       service = ms->nt->OpenService(sc, name, GENERIC_READ);\r
+       if (service != NULL)\r
+       {\r
+               SERVICE_STATUS st;\r
+               Zero(&st, sizeof(st));\r
+               if (ms->nt->QueryServiceStatus(service, &st))\r
+               {\r
+                       switch (st.dwCurrentState)\r
+                       {\r
+                       case SERVICE_CONTINUE_PENDING:\r
+                       case SERVICE_PAUSE_PENDING:\r
+                       case SERVICE_PAUSED:\r
+                       case SERVICE_RUNNING:\r
+                       case SERVICE_START_PENDING:\r
+                       case SERVICE_STOP_PENDING:\r
+                               ret = true;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               ms->nt->CloseServiceHandle(service);\r
+       }\r
+\r
+       ms->nt->CloseServiceHandle(sc);\r
+       return ret;\r
+}\r
+\r
+// サービスをアンインストールする\r
+bool MsUninstallService(char *name)\r
+{\r
+       SC_HANDLE sc, service;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (ms->IsNt == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       MsStopService(name);\r
+\r
+       sc = ms->nt->OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);\r
+       if (sc == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       service = ms->nt->OpenService(sc, name, SERVICE_ALL_ACCESS);\r
+       if (service != NULL)\r
+       {\r
+               if (ms->nt->DeleteService(service))\r
+               {\r
+                       ret = true;\r
+               }\r
+               ms->nt->CloseServiceHandle(service);\r
+       }\r
+\r
+       ms->nt->CloseServiceHandle(sc);\r
+\r
+       if (ret)\r
+       {\r
+               SleepThread(2000);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// サービス設定を更新する\r
+bool MsUpdateServiceConfig(char *name)\r
+{\r
+       SC_HANDLE sc, service;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // Windows 起動直後かどうか (デッドロック防止)\r
+       if (timeGetTime() <= (60 * 30 * 1000))\r
+       {\r
+               if (MsRegReadInt(REG_LOCAL_MACHINE, "Software\\SoftEther Corporation\\Update Service Config", name) != 0)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       sc = ms->nt->OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);\r
+       if (sc == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       service = ms->nt->OpenService(sc, name, SERVICE_ALL_ACCESS);\r
+       if (service != NULL)\r
+       {\r
+               if (GET_KETA(GetOsInfo()->OsType, 100) >= 2)\r
+               {\r
+                       SERVICE_FAILURE_ACTIONS action;\r
+                       SC_ACTION *e;\r
+                       Zero(&action, sizeof(action));\r
+                       e = ZeroMalloc(sizeof(SC_ACTION) * 3);\r
+                       e[0].Delay = 10000; e[0].Type = SC_ACTION_RESTART;\r
+                       e[1].Delay = 10000; e[1].Type = SC_ACTION_RESTART;\r
+                       e[2].Delay = 10000; e[2].Type = SC_ACTION_RESTART;\r
+                       action.cActions = 3;\r
+                       action.lpsaActions = e;\r
+                       action.dwResetPeriod = 1 * 60 * 60 * 24;\r
+                       ms->nt->ChangeServiceConfig2(service, SERVICE_CONFIG_FAILURE_ACTIONS, &action);\r
+\r
+                       MsRegWriteInt(REG_LOCAL_MACHINE, "Software\\SoftEther Corporation\\Update Service Config", name, 1);\r
+               }\r
+               ms->nt->CloseServiceHandle(service);\r
+       }\r
+\r
+       ms->nt->CloseServiceHandle(sc);\r
+\r
+       return true;\r
+}\r
+\r
+// サービスをインストールする\r
+bool MsInstallService(char *name, char *title, wchar_t *description, char *path)\r
+{\r
+       wchar_t title_w[MAX_PATH];\r
+       wchar_t path_w[MAX_PATH];\r
+       // 引数チェック\r
+       if (name == NULL || title == NULL || path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrToUni(title_w, sizeof(title_w), title);\r
+       StrToUni(path_w, sizeof(path_w), path);\r
+\r
+       return MsInstallServiceW(name, title_w, description, path_w);\r
+}\r
+bool MsInstallServiceW(char *name, wchar_t *title, wchar_t *description, wchar_t *path)\r
+{\r
+       return MsInstallServiceExW(name, title, description, path, NULL);\r
+}\r
+bool MsInstallServiceExW(char *name, wchar_t *title, wchar_t *description, wchar_t *path, UINT *error_code)\r
+{\r
+       SC_HANDLE sc, service;\r
+       bool ret = false;\r
+       wchar_t name_w[MAX_SIZE];\r
+       static UINT temp_int = 0;\r
+       // 引数チェック\r
+       if (name == NULL || title == NULL || path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (ms->IsNt == false)\r
+       {\r
+               return false;\r
+       }\r
+       if (error_code == NULL)\r
+       {\r
+               error_code = &temp_int;\r
+       }\r
+\r
+       *error_code = 0;\r
+\r
+       StrToUni(name_w, sizeof(name_w), name);\r
+\r
+       sc = ms->nt->OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);\r
+       if (sc == NULL)\r
+       {\r
+               *error_code = GetLastError();\r
+               return false;\r
+       }\r
+\r
+       service = ms->nt->CreateServiceW(sc, name_w, title, SERVICE_ALL_ACCESS,\r
+               SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS , SERVICE_AUTO_START,\r
+               SERVICE_ERROR_NORMAL, path, NULL, NULL, NULL, NULL, NULL);\r
+\r
+       if (service != NULL)\r
+       {\r
+               ret = true;\r
+\r
+               if (GET_KETA(GetOsInfo()->OsType, 100) >= 2)\r
+               {\r
+                       SERVICE_DESCRIPTIONW d;\r
+                       SERVICE_FAILURE_ACTIONS action;\r
+                       SC_ACTION *e;\r
+                       Zero(&d, sizeof(d));\r
+                       d.lpDescription = description;\r
+                       ms->nt->ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &d);\r
+                       Zero(&action, sizeof(action));\r
+                       e = ZeroMalloc(sizeof(SC_ACTION) * 3);\r
+                       e[0].Delay = 10000; e[0].Type = SC_ACTION_RESTART;\r
+                       e[1].Delay = 10000; e[1].Type = SC_ACTION_RESTART;\r
+                       e[2].Delay = 10000; e[2].Type = SC_ACTION_RESTART;\r
+                       action.cActions = 3;\r
+                       action.lpsaActions = e;\r
+                       action.dwResetPeriod = 1 * 60 * 60 * 24;\r
+                       ms->nt->ChangeServiceConfig2(service, SERVICE_CONFIG_FAILURE_ACTIONS, &action);\r
+\r
+                       Free(e);\r
+               }\r
+\r
+               ms->nt->CloseServiceHandle(service);\r
+       }\r
+       else\r
+       {\r
+               *error_code = GetLastError();\r
+       }\r
+\r
+       ms->nt->CloseServiceHandle(sc);\r
+\r
+       if (ret)\r
+       {\r
+               SleepThread(2000);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 指定したサービスがインストールされているかどうか調べる\r
+bool MsIsServiceInstalled(char *name)\r
+{\r
+       SC_HANDLE sc;\r
+       SC_HANDLE service;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (ms->IsNt == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       sc = ms->nt->OpenSCManager(NULL, NULL, GENERIC_READ);\r
+       if (sc == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       service = ms->nt->OpenService(sc, name, GENERIC_READ);\r
+       if (service != NULL)\r
+       {\r
+               ret = true;\r
+       }\r
+\r
+       ms->nt->CloseServiceHandle(service);\r
+       ms->nt->CloseServiceHandle(sc);\r
+\r
+       return ret;\r
+}\r
+\r
+// プロセスの強制終了\r
+void MsTerminateProcess()\r
+{\r
+       TerminateProcess(GetCurrentProcess(), 0);\r
+       _exit(0);\r
+}\r
+\r
+// プロセス ID の取得\r
+UINT MsGetProcessId()\r
+{\r
+       return GetCurrentProcessId();\r
+}\r
+\r
+// MS 構造体の取得\r
+MS *MsGetMs()\r
+{\r
+       return ms;\r
+}\r
+\r
+// スレッドの優先順位を最低にする\r
+void MsSetThreadPriorityIdle()\r
+{\r
+       SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE);\r
+}\r
+\r
+// スレッドの優先順位を上げる\r
+void MsSetThreadPriorityHigh()\r
+{\r
+       SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);\r
+}\r
+\r
+// スレッドの優先順位を下げる\r
+void MsSetThreadPriorityLow()\r
+{\r
+       SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);\r
+}\r
+\r
+// スレッドの優先順位を最高にする\r
+void MsSetThreadPriorityRealtime()\r
+{\r
+       SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);\r
+       SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);\r
+       SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);\r
+}\r
+\r
+// スレッドの優先順位を戻す\r
+void MsRestoreThreadPriority()\r
+{\r
+       SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);\r
+}\r
+\r
+// TCP 設定アプリケーションを表示するべきかどうかチェックする\r
+bool MsIsShouldShowTcpConfigApp()\r
+{\r
+       MS_TCP tcp1, tcp2;\r
+       if (MsIsTcpConfigSupported() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       MsGetTcpConfig(&tcp1);\r
+       if (MsLoadTcpConfigReg(&tcp2) == false)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (Cmp(&tcp1, &tcp2, sizeof(MS_TCP) != 0))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// レジストリの一時設定内容データを Windows の TCP パラメータに適用する\r
+void MsApplyTcpConfig()\r
+{\r
+       if (MsIsTcpConfigSupported())\r
+       {\r
+               MS_TCP tcp;\r
+\r
+               if (MsLoadTcpConfigReg(&tcp))\r
+               {\r
+                       MsSetTcpConfig(&tcp);\r
+               }\r
+       }\r
+}\r
+\r
+// 現在の状態で TCP の動的構成がサポートされているかどうかチェックする\r
+bool MsIsTcpConfigSupported()\r
+{\r
+       if (MsIsNt() && MsIsAdmin())\r
+       {\r
+               UINT type = GetOsInfo()->OsType;\r
+\r
+               if (GET_KETA(type, 100) >= 2)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// TCP 設定をレジストリ設定から読み込む\r
+bool MsLoadTcpConfigReg(MS_TCP *tcp)\r
+{\r
+       // 引数チェック\r
+       if (tcp == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt())\r
+       {\r
+               Zero(tcp, sizeof(MS_TCP));\r
+\r
+               if (MsRegIsValueEx(REG_LOCAL_MACHINE, MS_REG_TCP_SETTING_KEY, "RecvWindowSize", true) == false ||\r
+                       MsRegIsValueEx(REG_LOCAL_MACHINE, MS_REG_TCP_SETTING_KEY, "SendWindowSize", true) == false)\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               tcp->RecvWindowSize = MsRegReadIntEx(REG_LOCAL_MACHINE, MS_REG_TCP_SETTING_KEY, "RecvWindowSize", true);\r
+               tcp->SendWindowSize = MsRegReadIntEx(REG_LOCAL_MACHINE, MS_REG_TCP_SETTING_KEY, "SendWindowSize", true);\r
+\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// TCP 設定をレジストリから削除する\r
+void MsDeleteTcpConfigReg()\r
+{\r
+       if (MsIsNt() && MsIsAdmin())\r
+       {\r
+               MsRegDeleteKeyEx(REG_LOCAL_MACHINE, MS_REG_TCP_SETTING_KEY, true);\r
+       }\r
+}\r
+\r
+// TCP 設定をレジストリ設定に書き込む\r
+void MsSaveTcpConfigReg(MS_TCP *tcp)\r
+{\r
+       // 引数チェック\r
+       if (tcp == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsNt() && MsIsAdmin())\r
+       {\r
+               MsRegWriteIntEx(REG_LOCAL_MACHINE, MS_REG_TCP_SETTING_KEY, "RecvWindowSize", tcp->RecvWindowSize, true);\r
+               MsRegWriteIntEx(REG_LOCAL_MACHINE, MS_REG_TCP_SETTING_KEY, "SendWindowSize", tcp->SendWindowSize, true);\r
+       }\r
+}\r
+\r
+// 現在の TCP 設定を取得する\r
+void MsGetTcpConfig(MS_TCP *tcp)\r
+{\r
+       // 引数チェック\r
+       if (tcp == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(tcp, sizeof(MS_TCP));\r
+\r
+       if (MsIsNt())\r
+       {\r
+               // ネットワーク設定初期化\r
+               MsInitGlobalNetworkConfig();\r
+\r
+               // GlobalMaxTcpWindowSize または TcpWindowSize の値が存在すれば読み込む\r
+               tcp->RecvWindowSize = MAX(tcp->RecvWindowSize, MsRegReadInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", "TcpWindowSize"));\r
+               tcp->RecvWindowSize = MAX(tcp->RecvWindowSize, MsRegReadInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", "GlobalMaxTcpWindowSize"));\r
+               tcp->RecvWindowSize = MAX(tcp->RecvWindowSize, MsRegReadInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\AFD\\Parameters", "DefaultReceiveWindow"));\r
+\r
+               // DefaultSendWindow の値が存在すれば読み込む\r
+               tcp->SendWindowSize = MsRegReadInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\AFD\\Parameters", "DefaultSendWindow");\r
+       }\r
+}\r
+\r
+// TCP 設定を書き込む\r
+void MsSetTcpConfig(MS_TCP *tcp)\r
+{\r
+       // 引数チェック\r
+       if (tcp == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsNt() && MsIsAdmin())\r
+       {\r
+               bool window_scaling = false;\r
+               UINT tcp1323opts;\r
+\r
+               if (tcp->RecvWindowSize >= 65536 || tcp->SendWindowSize >= 65536)\r
+               {\r
+                       window_scaling = true;\r
+               }\r
+\r
+               // Tcp1323Opts の設定\r
+               tcp1323opts = MsRegReadInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", "Tcp1323Opts");\r
+               if (window_scaling)\r
+               {\r
+                       if (tcp1323opts == 0)\r
+                       {\r
+                               tcp1323opts = 1;\r
+                       }\r
+                       if (tcp1323opts == 2)\r
+                       {\r
+                               tcp1323opts = 3;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if (tcp1323opts == 1)\r
+                       {\r
+                               tcp1323opts = 0;\r
+                       }\r
+                       if (tcp1323opts == 3)\r
+                       {\r
+                               tcp1323opts = 2;\r
+                       }\r
+               }\r
+               MsRegWriteInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", "Tcp1323Opts", tcp1323opts);\r
+\r
+               // 受信ウインドウの設定\r
+               if (tcp->RecvWindowSize == 0)\r
+               {\r
+                       MsRegDeleteValue(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\AFD\\Parameters",\r
+                               "DefaultReceiveWindow");\r
+                       MsRegDeleteValue(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",\r
+                               "TcpWindowSize");\r
+                       MsRegDeleteValue(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",\r
+                               "GlobalMaxTcpWindowSize");\r
+               }\r
+               else\r
+               {\r
+                       MsRegWriteInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\AFD\\Parameters",\r
+                               "DefaultReceiveWindow", tcp->RecvWindowSize);\r
+                       MsRegWriteInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",\r
+                               "TcpWindowSize", tcp->RecvWindowSize);\r
+                       MsRegWriteInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",\r
+                               "GlobalMaxTcpWindowSize", tcp->RecvWindowSize);\r
+               }\r
+\r
+               // 送信ウインドウの設定\r
+               if (tcp->SendWindowSize == 0)\r
+               {\r
+                       MsRegDeleteValue(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\AFD\\Parameters",\r
+                               "DefaultSendWindow");\r
+               }\r
+               else\r
+               {\r
+                       MsRegWriteInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\AFD\\Parameters",\r
+                               "DefaultSendWindow", tcp->SendWindowSize);\r
+               }\r
+       }\r
+}\r
+\r
+// グローバルなネットワーク設定を初期化する\r
+void MsInitGlobalNetworkConfig()\r
+{\r
+       if (MsIsNt())\r
+       {\r
+               UINT current_window_size;\r
+\r
+               if (MsRegReadInt(REG_LOCAL_MACHINE,\r
+                       "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",\r
+                       "packetix_no_optimize") == 0)\r
+\r
+               {\r
+                       // TCP コネクション数を最大にする\r
+                       MsRegWriteInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",\r
+                               "TcpNumConnections", TCP_MAX_NUM_CONNECTIONS);\r
+\r
+                       // タスク オフロードを無効化する\r
+                       MsRegWriteInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",\r
+                               "DisableTaskOffload", 1);\r
+               }\r
+\r
+               current_window_size = MsRegReadInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", "TcpWindowSize");\r
+\r
+               if (current_window_size == 65535 || current_window_size == 5980160 ||\r
+                       current_window_size == 16777216 || current_window_size == 16777214)\r
+               {\r
+                       // 古いバージョンの VPN が書き込んでしまった変な値を削除する\r
+                       MsRegDeleteValue(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\AFD\\Parameters",\r
+                               "DefaultReceiveWindow");\r
+                       MsRegDeleteValue(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\AFD\\Parameters",\r
+                               "DefaultSendWindow");\r
+                       MsRegDeleteValue(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",\r
+                               "Tcp1323Opts");\r
+                       MsRegDeleteValue(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",\r
+                               "TcpWindowSize");\r
+                       MsRegDeleteValue(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",\r
+                               "GlobalMaxTcpWindowSize");\r
+\r
+                       // vpn_no_change = true にする\r
+                       MsRegWriteInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", "vpn_no_change", 1);\r
+                       MsRegWriteInt(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\AFD\\Parameters", "vpn_no_change", 1);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (MsRegReadInt(REG_LOCAL_MACHINE,\r
+                       "System\\CurrentControlSet\\Services\\VxD\\MSTCP",\r
+                       "packetix_no_optimize") == 0)\r
+               {\r
+                       // DeadGWDetect を無効にする\r
+                       MsRegWriteStr(REG_LOCAL_MACHINE, "System\\CurrentControlSet\\Services\\VxD\\MSTCP",\r
+                               "DeadGWDetect", "0");\r
+               }\r
+       }\r
+\r
+       MsApplyTcpConfig();\r
+}\r
+\r
+// 仮想 LAN カードをアップグレードする\r
+bool MsUpgradeVLan(char *tag_name, char *connection_tag_name, char *instance_name)\r
+{\r
+       wchar_t infpath[MAX_PATH];\r
+       char hwid[MAX_PATH];\r
+       wchar_t hwid_w[MAX_PATH];\r
+       bool ret = false;\r
+       bool need_reboot;\r
+       bool before_status;\r
+       UCHAR old_mac_address[6];\r
+       char *s;\r
+       NO_WARNING *nw;\r
+       char sen_sys[MAX_PATH];\r
+       // 引数チェック\r
+       if (instance_name == NULL || tag_name == NULL || connection_tag_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               // Windows 9x ではアップグレードできない\r
+               return false;\r
+       }\r
+\r
+       Zero(hwid, sizeof(hwid));\r
+       Format(hwid, sizeof(hwid), DRIVER_DEVICE_ID_TAG, instance_name);\r
+       StrToUni(hwid_w, sizeof(hwid_w), hwid);\r
+\r
+       // 指定された名前の仮想 LAN カードがすでに登録されているかどうかを調べる\r
+       if (MsIsVLanExists(tag_name, instance_name) == false)\r
+       {\r
+               // 登録されていない\r
+               return false;\r
+       }\r
+\r
+       // 現在使用している .sys ファイル名を取得する\r
+       if (MsGetSenDeiverFilename(sen_sys, sizeof(sen_sys), instance_name) == false)\r
+       {\r
+               // 不明なので新しいファイル名を作成する\r
+               if (MsMakeNewSenDriverFilename(sen_sys, sizeof(sen_sys)) == false)\r
+               {\r
+                       // 失敗\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // 現在の動作状況を取得する\r
+       before_status = MsIsVLanEnabled(instance_name);\r
+\r
+       // 以前の MAC アドレスを取得する\r
+       s = MsGetMacAddress(tag_name, instance_name);\r
+       if (s == NULL)\r
+       {\r
+               Zero(old_mac_address, 6);\r
+       }\r
+       else\r
+       {\r
+               BUF *b;\r
+               b = StrToBin(s);\r
+               Free(s);\r
+\r
+               if (b->Size == 6)\r
+               {\r
+                       Copy(old_mac_address, b->Buf, b->Size);\r
+               }\r
+               else\r
+               {\r
+                       Zero(old_mac_address, 6);\r
+               }\r
+\r
+               FreeBuf(b);\r
+       }\r
+\r
+       // インストール開始\r
+       if (MsStartDriverInstall(instance_name, IsZero(old_mac_address, 6) ? NULL : old_mac_address, sen_sys) == false)\r
+       {\r
+               return false;\r
+       }\r
+       MsGetDriverPath(instance_name, NULL, NULL, infpath, NULL, sen_sys);\r
+\r
+       nw = NULL;\r
+\r
+       //if (MsIsVista() == false)\r
+       {\r
+               nw = MsInitNoWarning();\r
+       }\r
+\r
+       // インストールを行う\r
+       if (ms->nt->UpdateDriverForPlugAndPlayDevicesW(\r
+               NULL, hwid_w, infpath, 1, &need_reboot))\r
+       {\r
+               ret = true;\r
+       }\r
+       MsFreeNoWarning(nw);\r
+\r
+       // インストール完了\r
+       MsFinishDriverInstall(instance_name, sen_sys);\r
+\r
+       MsInitNetworkConfig(tag_name, instance_name, connection_tag_name);\r
+\r
+       // 動作を復元する\r
+       if (before_status)\r
+       {\r
+               MsEnableVLan(instance_name);\r
+       }\r
+       else\r
+       {\r
+               MsDisableVLan(instance_name);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// Windows 9x 用テスト\r
+void MsWin9xTest()\r
+{\r
+}\r
+\r
+// 仮想 LAN カードの CompatibleIDs を更新する\r
+void MsUpdateCompatibleIDs(char *instance_name)\r
+{\r
+       TOKEN_LIST *t;\r
+       char id[MAX_SIZE];\r
+       char device_title[MAX_SIZE];\r
+       char device_title_old[MAX_SIZE];\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(id, sizeof(id), DRIVER_DEVICE_ID_TAG, instance_name);\r
+       Format(device_title, sizeof(device_title), VLAN_ADAPTER_NAME_TAG, instance_name);\r
+       Format(device_title_old, sizeof(device_title_old), "---dummy-string-ut--", instance_name);\r
+\r
+       t = MsRegEnumKey(REG_LOCAL_MACHINE, "Enum\\Root\\Net");\r
+       if (t != NULL)\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < t->NumTokens;i++)\r
+               {\r
+                       char keyname[MAX_PATH];\r
+                       char *str;\r
+                       char *title;\r
+\r
+                       Format(keyname, sizeof(keyname), "Enum\\Root\\Net\\%s", t->Token[i]);\r
+\r
+                       title = MsRegReadStr(REG_LOCAL_MACHINE, keyname, "DeviceDesc");\r
+\r
+                       if (title != NULL)\r
+                       {\r
+                               if (StrCmpi(title, device_title) == 0 || StrCmpi(title, device_title_old) == 0)\r
+                               {\r
+                                       Format(keyname, sizeof(keyname), "Enum\\Root\\Net\\%s",t->Token[i]);\r
+                                       str = MsRegReadStr(REG_LOCAL_MACHINE, keyname, "CompatibleIDs");\r
+                                       if (str != NULL)\r
+                                       {\r
+                                               Free(str);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               MsRegWriteStr(REG_LOCAL_MACHINE, keyname, "CompatibleIDs", id);\r
+                                       }\r
+                               }\r
+                               Free(title);\r
+                       }\r
+               }\r
+\r
+               FreeToken(t);\r
+       }\r
+\r
+       MsRegWriteStr(REG_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", "SourcePath",\r
+               ms->System32Dir);\r
+}\r
+\r
+// 仮想 LAN カードをインストールする (Win9x 用)\r
+bool MsInstallVLan9x(char *instance_name)\r
+{\r
+       char sysdir[MAX_PATH];\r
+       char infdir[MAX_PATH];\r
+       char otherdir[MAX_PATH];\r
+       char syspath[MAX_PATH];\r
+       char syspath2[MAX_PATH];\r
+       char infpath[MAX_PATH];\r
+       char vpn16[MAX_PATH];\r
+       char infpath_src[MAX_PATH];\r
+       char syspath_src[MAX_PATH];\r
+       char sen_sys[MAX_PATH];\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(sysdir, sizeof(sysdir), MsGetSystem32Dir());\r
+       Format(infdir, sizeof(infdir), "%s\\inf", MsGetWindowsDir());\r
+       Format(otherdir, sizeof(otherdir), "%s\\other", infdir);\r
+       Format(syspath, sizeof(syspath), "%s\\Sen_%s.sys", sysdir, instance_name);\r
+       Format(syspath2, sizeof(syspath2), "%s\\Sen_%s.sys", infdir, instance_name);\r
+       Format(infpath, sizeof(infpath), "%s\\Sen_%s.inf", infdir, instance_name);\r
+       Format(vpn16, sizeof(vpn16), "%s\\vpn16.exe", MsGetMyTempDir());\r
+\r
+       MakeDir(otherdir);\r
+\r
+       Format(sen_sys, sizeof(sen_sys), DRIVER_INSTALL_SYS_NAME_TAG, instance_name);\r
+\r
+       // vpn16.exe のコピー\r
+       FileCopy("|vpn16.exe", vpn16);\r
+\r
+       // インストール開始\r
+       if (MsStartDriverInstall(instance_name, NULL, sen_sys) == false)\r
+       {\r
+               return false;\r
+       }\r
+       MsGetDriverPathA(instance_name, NULL, NULL, infpath_src, syspath_src, sen_sys);\r
+\r
+       // inf ファイルのコピー\r
+       FileCopy(infpath_src, infpath);\r
+\r
+       // sys ファイルのコピー\r
+       FileCopy(syspath_src, syspath);\r
+\r
+       // デバイスドライバのインストール\r
+       if (Run(vpn16, instance_name, false, true) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // CompatibleIDs の更新\r
+       MsUpdateCompatibleIDs(instance_name);\r
+\r
+       return true;\r
+}\r
+\r
+// 子ウインドウ列挙プロシージャ\r
+bool CALLBACK MsEnumChildWindowProc(HWND hWnd, LPARAM lParam)\r
+{\r
+       LIST *o = (LIST *)lParam;\r
+\r
+       if (o != NULL)\r
+       {\r
+               MsEnumChildWindows(o, hWnd);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 指定したウインドウとその子ウインドウをすべて列挙する\r
+LIST *MsEnumChildWindows(LIST *o, HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (hWnd == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (o == NULL)\r
+       {\r
+               o = NewListFast(NULL);\r
+       }\r
+\r
+       MsAddWindowToList(o, hWnd);\r
+\r
+       EnumChildWindows(hWnd, MsEnumChildWindowProc, (LPARAM)o);\r
+\r
+       return o;\r
+}\r
+\r
+// ウインドウをリストに追加する\r
+void MsAddWindowToList(LIST *o, HWND hWnd)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsInList(o, hWnd) == false)\r
+       {\r
+               Add(o, hWnd);\r
+       }\r
+}\r
+\r
+// スレッドの所有するウインドウの列挙\r
+bool CALLBACK MsEnumThreadWindowProc(HWND hWnd, LPARAM lParam)\r
+{\r
+       LIST *o = (LIST *)lParam;\r
+\r
+       if (o == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       MsEnumChildWindows(o, hWnd);\r
+\r
+       return true;\r
+}\r
+\r
+// ウインドウ列挙プロシージャ\r
+BOOL CALLBACK EnumTopWindowProc(HWND hWnd, LPARAM lParam)\r
+{\r
+       LIST *o = (LIST *)lParam;\r
+       HWND hParent;\r
+       char c1[MAX_SIZE], c2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || o == NULL)\r
+       {\r
+               return TRUE;\r
+       }\r
+\r
+       Zero(c1, sizeof(c1));\r
+       Zero(c2, sizeof(c2));\r
+\r
+       hParent = GetParent(hWnd);\r
+\r
+       GetClassName(hWnd, c1, sizeof(c1));\r
+\r
+       if (hParent != NULL)\r
+       {\r
+               GetClassName(hParent, c2, sizeof(c2));\r
+       }\r
+\r
+       if (StrCmpi(c1, "SysIPAddress32") != 0 && (IsEmptyStr(c2) || StrCmpi(c2, "SysIPAddress32") != 0))\r
+       {\r
+               AddWindow(o, hWnd);\r
+       }\r
+\r
+       return TRUE;\r
+}\r
+\r
+// 子ウインドウ列挙プロシージャ\r
+BOOL CALLBACK EnumChildWindowProc(HWND hWnd, LPARAM lParam)\r
+{\r
+       ENUM_CHILD_WINDOW_PARAM *p = (ENUM_CHILD_WINDOW_PARAM *)lParam;\r
+       LIST *o;\r
+       HWND hParent;\r
+       char c1[MAX_SIZE], c2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (hWnd == NULL || p == NULL)\r
+       {\r
+               return TRUE;\r
+       }\r
+\r
+       o = p->o;\r
+\r
+       Zero(c1, sizeof(c1));\r
+       Zero(c2, sizeof(c2));\r
+\r
+       hParent = GetParent(hWnd);\r
+\r
+       GetClassName(hWnd, c1, sizeof(c1));\r
+\r
+       if (hParent != NULL)\r
+       {\r
+               GetClassName(hParent, c2, sizeof(c2));\r
+       }\r
+\r
+       if (p->include_ipcontrol || (StrCmpi(c1, "SysIPAddress32") != 0 && (IsEmptyStr(c2) || StrCmpi(c2, "SysIPAddress32") != 0)))\r
+       {\r
+               AddWindow(o, hWnd);\r
+\r
+               if (p->no_recursion == false)\r
+               {\r
+                       EnumChildWindows(hWnd, EnumChildWindowProc, (LPARAM)p);\r
+               }\r
+       }\r
+\r
+       return TRUE;\r
+}\r
+LIST *EnumAllWindow()\r
+{\r
+       return EnumAllWindowEx(false, false);\r
+}\r
+LIST *EnumAllWindowEx(bool no_recursion, bool include_ipcontrol)\r
+{\r
+       ENUM_CHILD_WINDOW_PARAM p;\r
+       LIST *o = NewWindowList();\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.o = o;\r
+       p.no_recursion = no_recursion;\r
+       p.include_ipcontrol = include_ipcontrol;\r
+\r
+       EnumWindows(EnumChildWindowProc, (LPARAM)&p);\r
+\r
+       return o;\r
+}\r
+LIST *EnumAllTopWindow()\r
+{\r
+       LIST *o = NewWindowList();\r
+\r
+       EnumWindows(EnumTopWindowProc, (LPARAM)o);\r
+\r
+       return o;\r
+}\r
+\r
+// 特定のウインドウの中にあるすべての子ウインドウを列挙する\r
+LIST *EnumAllChildWindow(HWND hWnd)\r
+{\r
+       return EnumAllChildWindowEx(hWnd, false, false, false);\r
+}\r
+LIST *EnumAllChildWindowEx(HWND hWnd, bool no_recursion, bool include_ipcontrol, bool no_self)\r
+{\r
+       ENUM_CHILD_WINDOW_PARAM p;\r
+       LIST *o = NewWindowList();\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.include_ipcontrol = include_ipcontrol;\r
+       p.no_recursion = no_recursion;\r
+       p.o = o;\r
+\r
+       if (no_self == false)\r
+       {\r
+               AddWindow(o, hWnd);\r
+       }\r
+\r
+       EnumChildWindows(hWnd, EnumChildWindowProc, (LPARAM)&p);\r
+\r
+       return o;\r
+}\r
+\r
+// ウインドウリストの解放\r
+void FreeWindowList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               HWND *e = LIST_DATA(o, i);\r
+\r
+               Free(e);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// ウインドウリストにウインドウを追加\r
+void AddWindow(LIST *o, HWND hWnd)\r
+{\r
+       HWND t, *e;\r
+       // 引数チェック\r
+       if (o == NULL || hWnd == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = hWnd;\r
+\r
+       if (Search(o, &t) != NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       e = ZeroMalloc(sizeof(HWND));\r
+       *e = hWnd;\r
+\r
+       Insert(o, e);\r
+}\r
+\r
+// ウインドウリストの比較\r
+int CmpWindowList(void *p1, void *p2)\r
+{\r
+       HWND *h1, *h2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       h1 = *(HWND **)p1;\r
+       h2 = *(HWND **)p2;\r
+       if (h1 == NULL || h2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return Cmp(h1, h2, sizeof(HWND));\r
+}\r
+\r
+// 新しいウインドウリストの作成\r
+LIST *NewWindowList()\r
+{\r
+       return NewListFast(CmpWindowList);\r
+}\r
+\r
+// Windows Vista かどうか判別\r
+bool MsIsVista()\r
+{\r
+       OS_INFO *info = GetOsInfo();\r
+\r
+       if (info == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (OS_IS_WINDOWS_NT(info->OsType))\r
+       {\r
+               if (GET_KETA(info->OsType, 100) >= 5)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// ウインドウの所有者のプロセスパスを取得する\r
+bool MsGetWindowOwnerProcessExeName(char *path, UINT size, HWND hWnd)\r
+{\r
+       DWORD procId = 0;\r
+       // 引数チェック\r
+       if (path == NULL || hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       GetWindowThreadProcessId(hWnd, &procId);\r
+       if (procId == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsGetProcessExeName(path, size, procId) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+bool MsGetWindowOwnerProcessExeNameW(wchar_t *path, UINT size, HWND hWnd)\r
+{\r
+       DWORD procId = 0;\r
+       // 引数チェック\r
+       if (path == NULL || hWnd == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       GetWindowThreadProcessId(hWnd, &procId);\r
+       if (procId == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsGetProcessExeNameW(path, size, procId) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// プロセス ID からプロセスパスを取得する\r
+bool MsGetProcessExeName(char *path, UINT size, UINT id)\r
+{\r
+       LIST *o;\r
+       MS_PROCESS *proc;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       o = MsGetProcessList();\r
+       proc = MsSearchProcessById(o, id);\r
+\r
+       if (proc != NULL)\r
+       {\r
+               ret = true;\r
+               StrCpy(path, size, proc->ExeFilename);\r
+       }\r
+\r
+       MsFreeProcessList(o);\r
+\r
+       return ret;\r
+}\r
+bool MsGetProcessExeNameW(wchar_t *path, UINT size, UINT id)\r
+{\r
+       LIST *o;\r
+       MS_PROCESS *proc;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       o = MsGetProcessList();\r
+       proc = MsSearchProcessById(o, id);\r
+\r
+       if (proc != NULL)\r
+       {\r
+               ret = true;\r
+               UniStrCpy(path, size, proc->ExeFilenameW);\r
+       }\r
+\r
+       MsFreeProcessList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// 警告ダイアログを閉じる\r
+bool MsCloseWarningWindow(UINT thread_id)\r
+{\r
+       UINT i;\r
+       LIST *o;\r
+       bool ret = false;\r
+\r
+       if (MsIsVista() == false)\r
+       {\r
+               o = NewListFast(NULL);\r
+               EnumThreadWindows(thread_id, MsEnumThreadWindowProc, (LPARAM)o);\r
+       }\r
+       else\r
+       {\r
+               o = EnumAllTopWindow();\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               HWND hWnd;\r
+               \r
+               if (MsIsVista() == false)\r
+               {\r
+                       hWnd = LIST_DATA(o, i);\r
+               }\r
+               else\r
+               {\r
+                       hWnd = *((HWND *)LIST_DATA(o, i));\r
+               }\r
+\r
+               if (hWnd != NULL)\r
+               {\r
+                       OS_INFO *info = GetOsInfo();\r
+\r
+                       if (MsIsNt())\r
+                       {\r
+                               // このウインドウがドライバの警告画面かどうかを取得する\r
+                               if (MsIsVista() == false)\r
+                               {\r
+                                       // Windows Vista 以外\r
+                                       HWND hStatic, hOk, hCancel, hDetail;\r
+\r
+                                       hStatic = GetDlgItem(hWnd, 0x14C1);\r
+                                       hOk = GetDlgItem(hWnd, 0x14B7);\r
+                                       hCancel = GetDlgItem(hWnd, 0x14BA);\r
+                                       hDetail = GetDlgItem(hWnd, 0x14B9);\r
+\r
+                                       if ((hStatic != NULL || hDetail != NULL) && hOk != NULL && hCancel != NULL)\r
+                                       {\r
+                                               char tmp[MAX_SIZE];\r
+                                               bool b = false;\r
+\r
+                                               if (GetClassName(hStatic, tmp, sizeof(tmp)) != 0)\r
+                                               {\r
+                                                       if (StrCmpi(tmp, "static") == 0)\r
+                                                       {\r
+                                                               b = true;\r
+                                                       }\r
+                                               }\r
+\r
+                                               if (GetClassName(hDetail, tmp, sizeof(tmp)) != 0)\r
+                                               {\r
+                                                       if (StrCmpi(tmp, "button") == 0)\r
+                                                       {\r
+                                                               b = true;\r
+                                                       }\r
+                                               }\r
+\r
+                                               if (b)\r
+                                               {\r
+                                                       if (GetClassName(hOk, tmp, sizeof(tmp)) != 0)\r
+                                                       {\r
+                                                               if (StrCmpi(tmp, "button") == 0)\r
+                                                               {\r
+                                                                       if (GetClassName(hCancel, tmp, sizeof(tmp)) != 0)\r
+                                                                       {\r
+                                                                               if (StrCmpi(tmp, "button") == 0)\r
+                                                                               {\r
+                                                                                       // 発見したので OK ボタンを押す\r
+                                                                                       PostMessage(hWnd, WM_COMMAND, 0x14B7, 0);\r
+\r
+                                                                                       ret = true;\r
+                                                                               }\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       // Windows Vista\r
+                                       char exe[MAX_PATH];\r
+\r
+                                       if (MsGetWindowOwnerProcessExeName(exe, sizeof(exe), hWnd))\r
+                                       {\r
+                                               if (EndWith(exe, "rundll32.exe"))\r
+                                               {\r
+                                                       LIST *o;\r
+                                                       HWND h;\r
+                                                       UINT i;\r
+\r
+                                                       o = EnumAllChildWindow(hWnd);\r
+\r
+                                                       if (o != NULL)\r
+                                                       {\r
+                                                               for (i = 0;i < LIST_NUM(o);i++)\r
+                                                               {\r
+                                                                       char tmp[MAX_SIZE];\r
+\r
+                                                                       h = *((HWND *)LIST_DATA(o, i));\r
+\r
+                                                                       Zero(tmp, sizeof(tmp));\r
+                                                                       GetClassNameA(h, tmp, sizeof(tmp));\r
+\r
+                                                                       if (StrCmpi(tmp, "DirectUIHWND") == 0)\r
+                                                                       {\r
+                                                                               LIST *o = EnumAllChildWindow(h);\r
+\r
+                                                                               if (o != NULL)\r
+                                                                               {\r
+                                                                                       UINT j;\r
+                                                                                       UINT numDirectUIHWND = 0;\r
+                                                                                       UINT numButton = 0;\r
+                                                                                       HWND hButton1 = NULL;\r
+                                                                                       HWND hButton2 = NULL;\r
+\r
+                                                                                       for (j = 0;j < LIST_NUM(o);j++)\r
+                                                                                       {\r
+                                                                                               HWND hh;\r
+                                                                                               char tmp[MAX_SIZE];\r
+\r
+                                                                                               hh = *((HWND *)LIST_DATA(o, j));\r
+\r
+                                                                                               Zero(tmp, sizeof(tmp));\r
+                                                                                               GetClassNameA(hh, tmp, sizeof(tmp));\r
+\r
+                                                                                               if (StrCmpi(tmp, "DirectUIHWND") == 0)\r
+                                                                                               {\r
+                                                                                                       numDirectUIHWND++;\r
+                                                                                               }\r
+\r
+                                                                                               if (StrCmpi(tmp, "button") == 0)\r
+                                                                                               {\r
+                                                                                                       numButton++;\r
+                                                                                                       if (hButton1 == NULL)\r
+                                                                                                       {\r
+                                                                                                               hButton1 = hh;\r
+                                                                                                       }\r
+                                                                                                       else\r
+                                                                                                       {\r
+                                                                                                               hButton2 = hh;\r
+                                                                                                       }\r
+                                                                                               }\r
+                                                                                       }\r
+\r
+                                                                                       if (numDirectUIHWND == 1 && numButton == 2)\r
+                                                                                       {\r
+                                                                                               if (hButton1 != NULL && hButton2 != NULL)\r
+                                                                                               {\r
+                                                                                                       HWND hButton;\r
+                                                                                                       HWND hParent;\r
+                                                                                                       RECT r1, r2;\r
+\r
+                                                                                                       GetWindowRect(hButton1, &r1);\r
+                                                                                                       GetWindowRect(hButton2, &r2);\r
+\r
+                                                                                                       hButton = hButton1;\r
+\r
+                                                                                                       if (r1.top < r2.top)\r
+                                                                                                       {\r
+                                                                                                               hButton = hButton2;\r
+                                                                                                       }\r
+\r
+                                                                                                       hParent = GetParent(hButton);\r
+\r
+                                                                                                       // 発見したので OK ボタンを押す\r
+                                                                                                       PostMessage(hParent, WM_COMMAND, 1, 0);\r
+\r
+                                                                                                       ret = true;\r
+                                                                                               }\r
+                                                                                       }\r
+\r
+                                                                                       FreeWindowList(o);\r
+                                                                               }\r
+                                                                       }\r
+                                                               }\r
+\r
+                                                               FreeWindowList(o);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (MsIsVista() == false)\r
+       {\r
+               ReleaseList(o);\r
+       }\r
+       else\r
+       {\r
+               FreeWindowList(o);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 警告を出さないようにするためのスレッド\r
+void MsNoWarningThreadProc(THREAD *thread, void *param)\r
+{\r
+       NO_WARNING *nw;\r
+       UINT interval;\r
+       UINT i;\r
+       bool found0 = false;\r
+       // 引数チェック\r
+       if (thread == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       nw = (NO_WARNING *)param;\r
+\r
+       nw->NoWarningThread = thread;\r
+       AddRef(thread->ref);\r
+\r
+       NoticeThreadInit(thread);\r
+\r
+       interval = 50;\r
+\r
+       if (MsIsVista())\r
+       {\r
+               interval = 1000;\r
+       }\r
+\r
+       i = 0;\r
+\r
+       while (nw->Halt == false)\r
+       {\r
+               bool found;\r
+\r
+               // 警告ダイアログを閉じる\r
+               found = MsCloseWarningWindow(nw->ThreadId);\r
+               if (i == 0)\r
+               {\r
+                       found0 = found;\r
+               }\r
+               else\r
+               {\r
+                       if (found0 == false && found)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+               i++;\r
+\r
+               // 親スレッドが指示するまでループする\r
+               Wait(nw->HaltEvent, interval);\r
+       }\r
+}\r
+\r
+// 警告音を消す処理の初期化\r
+char *MsNoWarningSoundInit()\r
+{\r
+       char *ret = MsRegReadStr(REG_CURRENT_USER, "AppEvents\\Schemes\\Apps\\.Default\\SystemAsterisk\\.Current", "");\r
+\r
+       if (IsEmptyStr(ret))\r
+       {\r
+               Free(ret);\r
+               ret = NULL;\r
+       }\r
+       else\r
+       {\r
+               MsRegWriteStr(REG_CURRENT_USER,\r
+                       "AppEvents\\Schemes\\Apps\\.Default\\SystemAsterisk\\.Current",\r
+                       "", "");\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 警告音を消す処理の解放\r
+void MsNoWarningSoundFree(char *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsRegWriteStrExpand(REG_CURRENT_USER,\r
+               "AppEvents\\Schemes\\Apps\\.Default\\SystemAsterisk\\.Current",\r
+               "", s);\r
+\r
+       Free(s);\r
+}\r
+\r
+// 警告を出さないようにする処理の開始\r
+NO_WARNING *MsInitNoWarning()\r
+{\r
+       wchar_t *tmp;\r
+       THREAD *thread;\r
+       NO_WARNING *nw = ZeroMalloc(sizeof(NO_WARNING));\r
+\r
+       // 現在のサウンドファイル名を取得する\r
+       tmp = MsRegReadStrW(REG_CURRENT_USER, "AppEvents\\Schemes\\Apps\\.Default\\SystemAsterisk\\.Current", "");\r
+       if (UniIsEmptyStr(tmp) == false)\r
+       {\r
+               nw->SoundFileName = CopyUniStr(tmp);\r
+\r
+               MsRegWriteStrW(REG_CURRENT_USER,\r
+                       "AppEvents\\Schemes\\Apps\\.Default\\SystemAsterisk\\.Current",\r
+                       "", L"");\r
+       }\r
+\r
+       Free(tmp);\r
+\r
+       nw->ThreadId = GetCurrentThreadId();\r
+       nw->HaltEvent = NewEvent();\r
+\r
+       thread = NewThread(MsNoWarningThreadProc, nw);\r
+       WaitThreadInit(thread);\r
+\r
+       ReleaseThread(thread);\r
+\r
+       return nw;\r
+}\r
+\r
+// 警告を出さないようにする処理の終了\r
+void MsFreeNoWarning(NO_WARNING *nw)\r
+{\r
+       // 引数チェック\r
+       if (nw == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       nw->Halt = true;\r
+       Set(nw->HaltEvent);\r
+\r
+       WaitThread(nw->NoWarningThread, INFINITE);\r
+       ReleaseThread(nw->NoWarningThread);\r
+\r
+       ReleaseEvent(nw->HaltEvent);\r
+\r
+       if (nw->SoundFileName != NULL)\r
+       {\r
+               MsRegWriteStrExpandW(REG_CURRENT_USER,\r
+                       "AppEvents\\Schemes\\Apps\\.Default\\SystemAsterisk\\.Current",\r
+                       "", nw->SoundFileName);\r
+\r
+               Free(nw->SoundFileName);\r
+       }\r
+\r
+       Free(nw);\r
+}\r
+\r
+// 仮想 LAN カードをインストールする\r
+bool MsInstallVLan(char *tag_name, char *connection_tag_name, char *instance_name)\r
+{\r
+       wchar_t infpath[MAX_PATH];\r
+       wchar_t inf_class_name[MAX_PATH];\r
+       GUID inf_class_guid;\r
+       HDEVINFO device_info;\r
+       SP_DEVINFO_DATA device_info_data;\r
+       char hwid[MAX_PATH];\r
+       wchar_t hwid_w[MAX_PATH];\r
+       bool ret = false;\r
+       bool need_reboot;\r
+       char sen_sys[MAX_PATH];\r
+       UINT i;\r
+       // 引数チェック\r
+       if (instance_name == NULL || tag_name == NULL || connection_tag_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               // Windows 9x 用\r
+               return MsInstallVLan9x(instance_name);\r
+       }\r
+\r
+       Zero(hwid, sizeof(hwid));\r
+       Format(hwid, sizeof(hwid), DRIVER_DEVICE_ID_TAG, instance_name);\r
+       StrToUni(hwid_w, sizeof(hwid_w), hwid);\r
+\r
+       // 指定された名前の仮想 LAN カードがすでに登録されているかどうかを調べる\r
+       if (MsIsVLanExists(tag_name, instance_name))\r
+       {\r
+               // すでに登録されている\r
+               return false;\r
+       }\r
+\r
+       // インストール先 .sys ファイル名の決定\r
+       if (MsMakeNewSenDriverFilename(sen_sys, sizeof(sen_sys)) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // インストール開始\r
+       if (MsStartDriverInstall(instance_name, NULL, sen_sys) == false)\r
+       {\r
+               return false;\r
+       }\r
+       MsGetDriverPath(instance_name, NULL, NULL, infpath, NULL, sen_sys);\r
+\r
+       // inf ファイルのクラス GUID を取得する\r
+       if (SetupDiGetINFClassW(infpath, &inf_class_guid, inf_class_name, sizeof(inf_class_name), NULL))\r
+       {\r
+               // デバイス情報セットを取得する\r
+               device_info = SetupDiCreateDeviceInfoList(&inf_class_guid, NULL);\r
+               if (device_info != INVALID_HANDLE_VALUE)\r
+               {\r
+                       // Windows 2000 以降\r
+                       Zero(&device_info_data, sizeof(device_info_data));\r
+                       device_info_data.cbSize = sizeof(device_info_data);\r
+                       if (SetupDiCreateDeviceInfoW(device_info, inf_class_name, &inf_class_guid,\r
+                               NULL, NULL, DICD_GENERATE_ID, &device_info_data))\r
+                       {\r
+                               // レジストリ情報を設定する\r
+                               if (SetupDiSetDeviceRegistryProperty(device_info, &device_info_data,\r
+                                       SPDRP_HARDWAREID, (BYTE *)hwid, sizeof(hwid)))\r
+                               {\r
+                                       NO_WARNING *nw = NULL;\r
+                                       \r
+                                       //if (MsIsVista() == false)\r
+                                       {\r
+                                               nw = MsInitNoWarning();\r
+                                       }\r
+\r
+                                       // クラスインストーラを起動する\r
+                                       if (SetupDiCallClassInstaller(DIF_REGISTERDEVICE, device_info,\r
+                                               &device_info_data))\r
+                                       {\r
+                                               // インストールを行う\r
+                                               if (ms->nt->UpdateDriverForPlugAndPlayDevicesW(\r
+                                                       NULL, hwid_w, infpath, 1, &need_reboot))\r
+                                               {\r
+                                                       ret = true;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       // インストール失敗\r
+                                                       SetupDiCallClassInstaller(DIF_REMOVE, device_info,\r
+                                                               &device_info_data);\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               Debug("SetupDiCallClassInstaller Error: %X\n", GetLastError());\r
+                                       }\r
+\r
+                                       MsFreeNoWarning(nw);\r
+                               }\r
+                       }\r
+                       // デバイス情報セットを削除する\r
+                       SetupDiDestroyDeviceInfoList(device_info);\r
+               }\r
+       }\r
+\r
+       // インストール完了\r
+       MsFinishDriverInstall(instance_name, sen_sys);\r
+\r
+       for (i = 0;i < 5;i++)\r
+       {\r
+               MsInitNetworkConfig(tag_name, instance_name, connection_tag_name);\r
+               SleepThread(MsIsVista() ? 1000 : 300);\r
+       }\r
+\r
+       if (ret)\r
+       {\r
+               MsDisableVLan(instance_name);\r
+               MsEnableVLan(instance_name);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// デバイス ID からデバイス情報を取得する\r
+HDEVINFO MsGetDevInfoFromDeviceId(SP_DEVINFO_DATA *dev_info_data, char *device_id)\r
+{\r
+       HDEVINFO dev_info;\r
+       SP_DEVINFO_LIST_DETAIL_DATA detail_data;\r
+       SP_DEVINFO_DATA data;\r
+       UINT i;\r
+       bool found;\r
+       char target_name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (dev_info_data == NULL || device_id == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       StrCpy(target_name, sizeof(target_name), device_id);\r
+\r
+       // デバイス情報リストを作成\r
+       dev_info = SetupDiGetClassDevsEx(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT, NULL, NULL, NULL);\r
+       if (dev_info == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&detail_data, sizeof(detail_data));\r
+       detail_data.cbSize = sizeof(detail_data);\r
+       if (SetupDiGetDeviceInfoListDetail(dev_info, &detail_data) == false)\r
+       {\r
+               MsDestroyDevInfo(dev_info);\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&data, sizeof(data));\r
+       data.cbSize = sizeof(data);\r
+\r
+       // 列挙開始\r
+       found = false;\r
+       for (i = 0;SetupDiEnumDeviceInfo(dev_info, i, &data);i++)\r
+       {\r
+               char *buffer;\r
+               UINT buffer_size = 8092;\r
+               DWORD data_type;\r
+\r
+               buffer = ZeroMalloc(buffer_size);\r
+\r
+               if (SetupDiGetDeviceRegistryProperty(dev_info, &data, SPDRP_HARDWAREID, &data_type, (PBYTE)buffer, buffer_size, NULL))\r
+               {\r
+                       if (StrCmpi(buffer, target_name) == 0)\r
+                       {\r
+                               // 発見\r
+                               found = true;\r
+                       }\r
+               }\r
+\r
+               Free(buffer);\r
+\r
+               if (found)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (found == false)\r
+       {\r
+               MsDestroyDevInfo(dev_info);\r
+               return NULL;\r
+       }\r
+       else\r
+       {\r
+               Copy(dev_info_data, &data, sizeof(data));\r
+               return dev_info;\r
+       }\r
+}\r
+\r
+// 指定したデバイスが動作中かどうかを調べる\r
+bool MsIsDeviceRunning(HDEVINFO info, SP_DEVINFO_DATA *dev_info_data)\r
+{\r
+       SP_DEVINFO_LIST_DETAIL_DATA detail;\r
+       UINT status = 0, problem = 0;\r
+       // 引数チェック\r
+       if (info == NULL || dev_info_data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&detail, sizeof(detail));\r
+       detail.cbSize = sizeof(detail);\r
+\r
+       if (SetupDiGetDeviceInfoListDetail(info, &detail) == false ||\r
+               ms->nt->CM_Get_DevNode_Status_Ex(&status, &problem, dev_info_data->DevInst,\r
+               0, detail.RemoteMachineHandle) != CR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (status & 8)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// 指定したデバイスを開始させる\r
+bool MsStartDevice(HDEVINFO info, SP_DEVINFO_DATA *dev_info_data)\r
+{\r
+       SP_PROPCHANGE_PARAMS p;\r
+       // 引数チェック\r
+       if (info == NULL || dev_info_data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);\r
+       p.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;\r
+       p.StateChange = DICS_ENABLE;\r
+       p.Scope = DICS_FLAG_GLOBAL;\r
+       if (SetupDiSetClassInstallParams(info, dev_info_data, &p.ClassInstallHeader, sizeof(p)))\r
+       {\r
+               SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, info, dev_info_data);\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);\r
+       p.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;\r
+       p.StateChange = DICS_ENABLE;\r
+       p.Scope = DICS_FLAG_CONFIGSPECIFIC;\r
+\r
+       if (SetupDiSetClassInstallParams(info, dev_info_data, &p.ClassInstallHeader, sizeof(p)) == false ||\r
+               SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, info, dev_info_data) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 指定したデバイスを停止させる\r
+bool MsStopDevice(HDEVINFO info, SP_DEVINFO_DATA *dev_info_data)\r
+{\r
+       SP_PROPCHANGE_PARAMS p;\r
+       // 引数チェック\r
+       if (info == NULL || dev_info_data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);\r
+       p.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;\r
+       p.StateChange = DICS_DISABLE;\r
+       p.Scope = DICS_FLAG_CONFIGSPECIFIC;\r
+\r
+       if (SetupDiSetClassInstallParams(info, dev_info_data, &p.ClassInstallHeader, sizeof(p)) == false ||\r
+               SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, info, dev_info_data) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 指定したデバイスを削除する\r
+bool MsDeleteDevice(HDEVINFO info, SP_DEVINFO_DATA *dev_info_data)\r
+{\r
+       SP_REMOVEDEVICE_PARAMS p;\r
+       SP_DEVINFO_LIST_DETAIL_DATA detail;\r
+       char device_id[MAX_PATH];\r
+       // 引数チェック\r
+       if (info == NULL || dev_info_data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&detail, sizeof(detail));\r
+       detail.cbSize = sizeof(detail);\r
+\r
+       if (SetupDiGetDeviceInfoListDetail(info, &detail) == false ||\r
+               ms->nt->CM_Get_Device_ID_Ex(dev_info_data->DevInst, device_id, sizeof(device_id),\r
+               0, detail.RemoteMachineHandle) != CR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&p, sizeof(p));\r
+       p.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);\r
+       p.ClassInstallHeader.InstallFunction = DIF_REMOVE;\r
+       p.Scope = DI_REMOVEDEVICE_GLOBAL;\r
+\r
+       if (SetupDiSetClassInstallParams(info, dev_info_data, &p.ClassInstallHeader, sizeof(p)) == false)\r
+       {\r
+               Debug("SetupDiSetClassInstallParams Failed. Err=%u\n", GetLastError());\r
+               return false;\r
+       }\r
+\r
+       if (SetupDiCallClassInstaller(DIF_REMOVE, info, dev_info_data) == false)\r
+       {\r
+               Debug("SetupDiCallClassInstaller Failed. Err=%u\n", GetLastError());\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 仮想 LAN カードを有効にする\r
+bool MsEnableVLan(char *instance_name)\r
+{\r
+       char tmp[MAX_PATH];\r
+       HDEVINFO h;\r
+       bool ret;\r
+       SP_DEVINFO_DATA data;\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), DRIVER_DEVICE_ID_TAG, instance_name);\r
+\r
+       h = MsGetDevInfoFromDeviceId(&data, tmp);\r
+       if (h == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = MsStartDevice(h, &data);\r
+\r
+       MsDestroyDevInfo(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カードを無効にする\r
+bool MsDisableVLan(char *instance_name)\r
+{\r
+       char tmp[MAX_PATH];\r
+       HDEVINFO h;\r
+       bool ret;\r
+       SP_DEVINFO_DATA data;\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), DRIVER_DEVICE_ID_TAG, instance_name);\r
+\r
+       h = MsGetDevInfoFromDeviceId(&data, tmp);\r
+       if (h == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = MsStopDevice(h, &data);\r
+\r
+       MsDestroyDevInfo(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カードを再起動する\r
+void MsRestartVLan(char *instance_name)\r
+{\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsVLanEnabled(instance_name) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsDisableVLan(instance_name);\r
+       MsEnableVLan(instance_name);\r
+}\r
+\r
+// 仮想 LAN カードが動作しているかどうか取得する\r
+bool MsIsVLanEnabled(char *instance_name)\r
+{\r
+       char tmp[MAX_PATH];\r
+       HDEVINFO h;\r
+       bool ret;\r
+       SP_DEVINFO_DATA data;\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), DRIVER_DEVICE_ID_TAG, instance_name);\r
+\r
+       h = MsGetDevInfoFromDeviceId(&data, tmp);\r
+       if (h == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = MsIsDeviceRunning(h, &data);\r
+\r
+       MsDestroyDevInfo(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カードをアンインストールする\r
+bool MsUninstallVLan(char *instance_name)\r
+{\r
+       char tmp[MAX_PATH];\r
+       HDEVINFO h;\r
+       bool ret;\r
+       SP_DEVINFO_DATA data;\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), DRIVER_DEVICE_ID_TAG, instance_name);\r
+\r
+       h = MsGetDevInfoFromDeviceId(&data, tmp);\r
+       if (h == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = MsDeleteDevice(h, &data);\r
+\r
+       MsDestroyDevInfo(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// 汎用テスト関数\r
+void MsTest()\r
+{\r
+}\r
+\r
+// デバイス情報の破棄\r
+void MsDestroyDevInfo(HDEVINFO info)\r
+{\r
+       // 引数チェック\r
+       if (info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetupDiDestroyDeviceInfoList(info);\r
+}\r
+\r
+// ドライバインストールの開始\r
+bool MsStartDriverInstall(char *instance_name, UCHAR *mac_address, char *sen_sys)\r
+{\r
+       wchar_t src_inf[MAX_PATH];\r
+       wchar_t src_sys[MAX_PATH];\r
+       wchar_t dest_inf[MAX_PATH];\r
+       wchar_t dest_sys[MAX_PATH];\r
+       UCHAR mac_address_bin[6];\r
+       char mac_address_str[32];\r
+       UINT size;\r
+       char *tmp;\r
+       BUF *b;\r
+       IO *io;\r
+       // 引数チェック\r
+       if (instance_name == NULL || sen_sys == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       MsGetDriverPath(instance_name, src_inf, src_sys, dest_inf, dest_sys, sen_sys);\r
+\r
+       // INF ファイルの処理\r
+       io = FileOpenW(src_inf, false);\r
+       if (io == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       size = FileSize(io);\r
+       tmp = ZeroMalloc(size * 2);\r
+       if (FileRead(io, tmp, size) == false)\r
+       {\r
+               FileClose(io);\r
+               Free(tmp);\r
+               return false;\r
+       }\r
+\r
+       FileClose(io);\r
+\r
+       if (mac_address == NULL)\r
+       {\r
+               MsGenMacAddress(mac_address_bin);\r
+       }\r
+       else\r
+       {\r
+               Copy(mac_address_bin, mac_address, 6);\r
+       }\r
+\r
+       BinToStr(mac_address_str, sizeof(mac_address_str), mac_address_bin, sizeof(mac_address_bin));\r
+\r
+       //ReplaceStrEx(tmp, size * 2, tmp, "$TAG_DRIVER_VER$", DRIVER_VER_STR, false);\r
+       ReplaceStrEx(tmp, size * 2, tmp, "$TAG_INSTANCE_NAME$", instance_name, false);\r
+       ReplaceStrEx(tmp, size * 2, tmp, "$TAG_MAC_ADDRESS$", mac_address_str, false);\r
+       ReplaceStrEx(tmp, size * 2, tmp, "$TAG_SYS_NAME$", sen_sys, false);\r
+\r
+       if (MsIsVista())\r
+       {\r
+               //ReplaceStrEx(tmp, size * 2, tmp, "\"100\"", "\"2000\"", false);\r
+       }\r
+\r
+       io = FileCreateW(dest_inf);\r
+       if (io == NULL)\r
+       {\r
+               Free(tmp);\r
+               return false;\r
+       }\r
+\r
+       FileWrite(io, tmp, StrLen(tmp));\r
+       FileClose(io);\r
+\r
+       Free(tmp);\r
+\r
+       // SYS ファイルの処理\r
+       b = ReadDumpW(src_sys);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (DumpBufW(b, dest_sys) == false)\r
+       {\r
+               FreeBuf(b);\r
+               return false;\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return true;\r
+}\r
+\r
+// MAC アドレスの生成\r
+void MsGenMacAddress(UCHAR *mac)\r
+{\r
+       UCHAR hash_src[40];\r
+       UCHAR hash[20];\r
+       UINT64 now;\r
+       // 引数チェック\r
+       if (mac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Rand(hash_src, 40);\r
+       now = SystemTime64();\r
+       Copy(hash_src, &now, sizeof(now));\r
+\r
+       Hash(hash, hash_src, sizeof(hash_src), true);\r
+\r
+       mac[0] = 0x00;\r
+       mac[1] = 0xAC;\r
+       mac[2] = hash[0];\r
+       mac[3] = hash[1];\r
+       mac[4] = hash[2];\r
+       mac[5] = hash[3];\r
+}\r
+\r
+// ドライバインストールの完了\r
+void MsFinishDriverInstall(char *instance_name, char *sen_sys)\r
+{\r
+       wchar_t src_inf[MAX_PATH];\r
+       wchar_t src_sys[MAX_PATH];\r
+       wchar_t dest_inf[MAX_PATH];\r
+       wchar_t dest_sys[MAX_PATH];\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsGetDriverPath(instance_name, src_inf, src_sys, dest_inf, dest_sys, sen_sys);\r
+\r
+       // ファイル削除\r
+       FileDeleteW(dest_inf);\r
+       FileDeleteW(dest_sys);\r
+}\r
+\r
+// ドライバファイルのパスの取得\r
+void MsGetDriverPath(char *instance_name, wchar_t *src_inf, wchar_t *src_sys, wchar_t *dest_inf, wchar_t *dest_sys, char *sen_sys)\r
+{\r
+       wchar_t *src_filename;\r
+       wchar_t *src_sys_filename;\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       src_filename = DRIVER_INF_FILE_NAME;\r
+       src_sys_filename = DRIVER_SYS_FILE_NAME;\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               src_filename = DRIVER_INF_FILE_NAME_9X;\r
+               src_sys_filename = DRIVER_SYS_FILE_NAME_9X;\r
+       }\r
+       else if (MsIsIA64() || MsIsX64())\r
+       {\r
+               if (MsIsX64())\r
+               {\r
+                       src_filename = DRIVER_INF_FILE_NAME_X64;\r
+                       src_sys_filename = DRIVER_SYS_FILE_NAME_X64;\r
+               }\r
+               else\r
+               {\r
+                       src_filename = DRIVER_INF_FILE_NAME_IA64;\r
+                       src_sys_filename = DRIVER_SYS_FILE_NAME_IA64;\r
+               }\r
+       }\r
+\r
+       if (src_inf != NULL)\r
+       {\r
+               UniStrCpy(src_inf, MAX_PATH, src_filename);\r
+       }\r
+\r
+       if (src_sys != NULL)\r
+       {\r
+               UniStrCpy(src_sys, MAX_PATH, src_sys_filename);\r
+       }\r
+\r
+       if (dest_inf != NULL)\r
+       {\r
+               char inf_name[MAX_PATH];\r
+               Format(inf_name, sizeof(inf_name), DRIVER_INSTALL_INF_NAME_TAG, instance_name);\r
+               UniFormat(dest_inf, MAX_PATH, L"%s\\%S", ms->MyTempDirW, inf_name);\r
+       }\r
+\r
+       if (dest_sys != NULL)\r
+       {\r
+               char sys_name[MAX_PATH];\r
+               StrCpy(sys_name, sizeof(sys_name), sen_sys);\r
+               UniFormat(dest_sys, MAX_PATH, L"%s\\%S", ms->MyTempDirW, sys_name);\r
+       }\r
+}\r
+void MsGetDriverPathA(char *instance_name, char *src_inf, char *src_sys, char *dest_inf, char *dest_sys, char *sen_sys)\r
+{\r
+       wchar_t src_inf_w[MAX_PATH];\r
+       wchar_t src_sys_w[MAX_PATH];\r
+       wchar_t dest_inf_w[MAX_PATH];\r
+       wchar_t dest_sys_w[MAX_PATH];\r
+\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       MsGetDriverPath(instance_name, src_inf_w, src_sys_w, dest_inf_w, dest_sys_w, sen_sys);\r
+\r
+       UniToStr(src_inf, MAX_PATH, src_inf_w);\r
+       UniToStr(src_sys, MAX_PATH, src_sys_w);\r
+       UniToStr(dest_inf, MAX_PATH, dest_inf_w);\r
+       UniToStr(dest_sys, MAX_PATH, dest_sys_w);\r
+}\r
+\r
+// 指定された名前の仮想 LAN カードがすでに登録されているかどうかを調べる\r
+bool MsIsVLanExists(char *tag_name, char *instance_name)\r
+{\r
+       char *guid;\r
+       // 引数チェック\r
+       if (instance_name == NULL || tag_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       guid = MsGetNetworkAdapterGuid(tag_name, instance_name);\r
+       if (guid == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Free(guid);\r
+       return true;\r
+}\r
+\r
+// ネットワーク設定ダイアログを表示する\r
+// ※ これはもう使っていない。うまく動かないからである。\r
+//    代わりに ShowWindowsNetworkConnectionDialog() を使うこと。\r
+bool MsShowNetworkConfiguration(HWND hWnd)\r
+{\r
+       IO *link_file = MsCreateTempFileByExt(".lnk");\r
+       char name[MAX_PATH];\r
+       SHELLEXECUTEINFO info;\r
+\r
+       // ファイル名確保\r
+       StrCpy(name, sizeof(name), link_file->Name);\r
+\r
+       // ショートカット作成\r
+       if (FileWrite(link_file, network_connection_link, sizeof(network_connection_link)) == false)\r
+       {\r
+               FileCloseAndDelete(link_file);\r
+               return false;\r
+       }\r
+\r
+       FileClose(link_file);\r
+\r
+       // ショートカットの実行\r
+       Zero(&info, sizeof(info));\r
+       info.cbSize = sizeof(info);\r
+       info.hwnd = (HWND)hWnd;\r
+       info.lpVerb = "open";\r
+       info.lpFile = name;\r
+       info.nShow = SW_SHOWDEFAULT;\r
+       info.fMask = SEE_MASK_NOCLOSEPROCESS;\r
+       if (ShellExecuteEx(&info) == false)\r
+       {\r
+               FileDelete(name);\r
+               return false;\r
+       }\r
+\r
+       // プロセス終了まで待機\r
+       WaitForSingleObject(info.hProcess, INFINITE);\r
+       CloseHandle(info.hProcess);\r
+\r
+       // ファイルの削除\r
+       FileDelete(name);\r
+\r
+       return true;\r
+}\r
+\r
+// 拡張子を元に一時ファイルを作成する\r
+IO *MsCreateTempFileByExt(char *ext)\r
+{\r
+       char *tmp = MsCreateTempFileNameByExt(ext);\r
+       IO *ret;\r
+\r
+       if (tmp == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = FileCreate(tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// 拡張子を指定するとその拡張子を持つ一時ファイルを作成する\r
+char *MsCreateTempFileNameByExt(char *ext)\r
+{\r
+       UCHAR rand[2];\r
+       char *ret = NULL;\r
+       // 引数チェック\r
+       if (ext == NULL)\r
+       {\r
+               ext = "tmp";\r
+       }\r
+       if (ext[0] == '.')\r
+       {\r
+               ext++;\r
+       }\r
+       if (StrLen(ext) == 0)\r
+       {\r
+               ext = "tmp";\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               char new_filename[MAX_PATH];\r
+               char *fullpath;\r
+               char rand_str[MAX_PATH];\r
+               IO *io;\r
+               Rand(rand, sizeof(rand));\r
+\r
+               BinToStr(rand_str, sizeof(rand_str), rand, sizeof(rand));\r
+               Format(new_filename, sizeof(new_filename), "__%s.%s", rand_str, ext);\r
+\r
+               fullpath = MsCreateTempFileName(new_filename);\r
+               io = FileOpen(fullpath, false);\r
+               if (io == NULL)\r
+               {\r
+                       ret = fullpath;\r
+                       break;\r
+               }\r
+               FileClose(io);\r
+\r
+               Free(fullpath);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 一時ファイルを作成する\r
+IO *MsCreateTempFile(char *name)\r
+{\r
+       IO *ret;\r
+       char *tmp;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       tmp = MsCreateTempFileName(name);\r
+       if (tmp == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = FileCreate(tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// 一時ファイル名を作成する\r
+char *MsCreateTempFileName(char *name)\r
+{\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), "%s\\%s", ms->MyTempDir, name);\r
+\r
+       return CopyStr(tmp);\r
+}\r
+\r
+// システムに残っているが使用されていない VPN 用一時ディレクトリを削除する\r
+void MsDeleteTempDir()\r
+{\r
+       HANDLE h;\r
+       wchar_t dir_mask[MAX_PATH];\r
+       WIN32_FIND_DATAA data_a;\r
+       WIN32_FIND_DATAW data_w;\r
+\r
+       Zero(&data_a, sizeof(data_a));\r
+       Zero(&data_w, sizeof(data_w));\r
+\r
+       UniFormat(dir_mask, sizeof(dir_mask), L"%s\\*", ms->TempDirW);\r
+\r
+       if (IsNt())\r
+       {\r
+               h = FindFirstFileW(dir_mask, &data_w);\r
+       }\r
+       else\r
+       {\r
+               char *tmp_a = CopyUniToStr(dir_mask);\r
+\r
+               h = FindFirstFileA(tmp_a, &data_a);\r
+\r
+               Free(tmp_a);\r
+       }\r
+\r
+       if (h != INVALID_HANDLE_VALUE)\r
+       {\r
+               bool b = true;\r
+\r
+               do\r
+               {\r
+                       if (IsNt() == false)\r
+                       {\r
+                               Zero(&data_w, sizeof(data_w));\r
+                               StrToUni(data_w.cFileName, sizeof(data_w.cFileName), data_a.cFileName);\r
+                               data_w.dwFileAttributes = data_a.dwFileAttributes;\r
+                               data_w.ftCreationTime = data_a.ftCreationTime;\r
+                               data_w.ftLastWriteTime = data_a.ftLastWriteTime;\r
+                               data_w.nFileSizeHigh = data_a.nFileSizeHigh;\r
+                               data_w.nFileSizeLow = data_a.nFileSizeLow;\r
+                       }\r
+\r
+                       if (UniStrCmpi(data_w.cFileName, L".") != 0 &&\r
+                               UniStrCmpi(data_w.cFileName, L"..") != 0)\r
+                       {\r
+                               if (data_w.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)\r
+                               {\r
+                                       if (UniStartWith(data_w.cFileName, L"VPN_") && UniStrLen(data_w.cFileName) == 8)\r
+                                       {\r
+                                               wchar_t lock_file_name[MAX_PATH];\r
+                                               wchar_t dir_name[MAX_PATH];\r
+                                               bool delete_now = false;\r
+                                               IO *io;\r
+\r
+                                               UniFormat(dir_name, sizeof(dir_name), L"%s\\%s",\r
+                                                       ms->TempDirW, data_w.cFileName);\r
+                                               MsGenLockFile(lock_file_name, sizeof(lock_file_name), dir_name);\r
+\r
+                                               io = FileOpenExW(lock_file_name, false, false);\r
+                                               if (io != NULL)\r
+                                               {\r
+                                                       // ロックファイルがロックされていなければ削除マーク\r
+                                                       FileClose(io);\r
+                                                       io = FileOpenW(lock_file_name, true);\r
+                                                       if (io != NULL)\r
+                                                       {\r
+                                                               delete_now = true;\r
+                                                               FileClose(io);\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       DIRLIST *d;\r
+\r
+                                                       // 中にあるすべてのファイルがロックされていなければ削除マーク\r
+                                                       delete_now = true;\r
+\r
+                                                       d = EnumDirW(dir_name);\r
+                                                       if (d != NULL)\r
+                                                       {\r
+                                                               UINT i;\r
+\r
+                                                               for (i = 0;i < d->NumFiles;i++)\r
+                                                               {\r
+                                                                       wchar_t full_path[MAX_PATH];\r
+\r
+                                                                       UniFormat(full_path, sizeof(full_path), L"%s\\%s", dir_name, d->File[i]->FileNameW);\r
+\r
+                                                                       io = FileOpenW(full_path, true);\r
+                                                                       if (io != NULL)\r
+                                                                       {\r
+                                                                               delete_now = true;\r
+                                                                               FileClose(io);\r
+                                                                       }\r
+                                                               }\r
+                                                               FreeDir(d);\r
+                                                       }\r
+                                               }\r
+                                               if (delete_now)\r
+                                               {\r
+                                                       MsDeleteAllFileW(dir_name);\r
+\r
+                                                       Win32DeleteDirW(dir_name);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+\r
+                       Zero(&data_w, sizeof(data_w));\r
+                       Zero(&data_a, sizeof(data_a));\r
+\r
+                       if (IsNt())\r
+                       {\r
+                               b = FindNextFileW(h, &data_w);\r
+                       }\r
+                       else\r
+                       {\r
+                               b = FindNextFileA(h, &data_a);\r
+                       }\r
+               }\r
+               while (b);\r
+\r
+               FindClose(h);\r
+       }\r
+}\r
+\r
+// 指定したディレクトリ内のファイルをすべて削除する\r
+void MsDeleteAllFile(char *dir)\r
+{\r
+       HANDLE h;\r
+       char file_mask[MAX_PATH];\r
+       WIN32_FIND_DATA data;\r
+       // 引数チェック\r
+       if (dir == NULL || IsEmptyStr(dir))\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(file_mask, sizeof(file_mask), "%s\\*.*", dir);\r
+\r
+       h = FindFirstFile(file_mask, &data);\r
+       if (h != INVALID_HANDLE_VALUE)\r
+       {\r
+               do\r
+               {\r
+                       if (StrCmpi(data.cFileName, ".") != 0 &&\r
+                               StrCmpi(data.cFileName, "..") != 0)\r
+                       {\r
+                               char fullpath[MAX_PATH];\r
+                               Format(fullpath, sizeof(fullpath), "%s\\%s", dir, data.cFileName);\r
+                               if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == false)\r
+                               {\r
+                                       DeleteFile(fullpath);\r
+                               }\r
+                               else\r
+                               {\r
+                                       MsDeleteAllFile(fullpath);\r
+                                       RemoveDirectory(fullpath);\r
+                               }\r
+                       }\r
+               }\r
+               while (FindNextFile(h, &data));\r
+\r
+               FindClose(h);\r
+       }\r
+}\r
+void MsDeleteAllFileW(wchar_t *dir)\r
+{\r
+       HANDLE h;\r
+       wchar_t file_mask[MAX_PATH];\r
+       WIN32_FIND_DATAW data;\r
+       // 引数チェック\r
+       if (dir == NULL || UniIsEmptyStr(dir))\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char *dir_a = CopyUniToStr(dir);\r
+\r
+               MsDeleteAllFile(dir_a);\r
+\r
+               Free(dir_a);\r
+\r
+               return;\r
+       }\r
+\r
+       UniFormat(file_mask, sizeof(file_mask), L"%s\\*.*", dir);\r
+\r
+       h = FindFirstFileW(file_mask, &data);\r
+       if (h != INVALID_HANDLE_VALUE)\r
+       {\r
+               do\r
+               {\r
+                       if (UniStrCmpi(data.cFileName, L".") != 0 &&\r
+                               UniStrCmpi(data.cFileName, L"..") != 0)\r
+                       {\r
+                               wchar_t fullpath[MAX_PATH];\r
+\r
+                               UniFormat(fullpath, sizeof(fullpath), L"%s\\%s", dir, data.cFileName);\r
+\r
+                               if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == false)\r
+                               {\r
+                                       DeleteFileW(fullpath);\r
+                               }\r
+                               else\r
+                               {\r
+                                       MsDeleteAllFileW(fullpath);\r
+                                       RemoveDirectoryW(fullpath);\r
+                               }\r
+                       }\r
+               }\r
+               while (FindNextFileW(h, &data));\r
+\r
+               FindClose(h);\r
+       }\r
+}\r
+\r
+// 一時ディレクトリを初期化する\r
+void MsInitTempDir()\r
+{\r
+       wchar_t tmp[MAX_PATH];\r
+       wchar_t tmp2[16];\r
+       UCHAR random[2];\r
+       wchar_t lockfilename[MAX_PATH];\r
+       UINT num = 0;\r
+\r
+       // 使われていない一時ディレクトリの削除\r
+       MsDeleteTempDir();\r
+\r
+       // 一時ディレクトリ名の決定\r
+       while (true)\r
+       {\r
+               random[0] = rand() % 256;\r
+               random[1] = rand() % 256;\r
+               BinToStrW(tmp2, sizeof(tmp2), random, sizeof(random));\r
+\r
+               UniFormat(tmp, sizeof(tmp), L"%s\\VPN_%s", ms->TempDirW, tmp2);\r
+\r
+               // ディレクトリの作成\r
+               if (MakeDirW(tmp))\r
+               {\r
+                       break;\r
+               }\r
+\r
+               if ((num++) >= 100)\r
+               {\r
+                       // 何度も失敗する\r
+                       char msg[MAX_SIZE];\r
+                       Format(msg, sizeof(msg),\r
+                               "Couldn't create Temporary Directory: %s\r\n\r\n"\r
+                               "Please contact your system administrator.",\r
+                               tmp);\r
+                       exit(0);\r
+               }\r
+       }\r
+\r
+       ms->MyTempDirW = CopyUniStr(tmp);\r
+       ms->MyTempDir = CopyUniToStr(tmp);\r
+\r
+       // ロックファイルの作成\r
+       MsGenLockFile(lockfilename, sizeof(lockfilename), ms->MyTempDirW);\r
+       ms->LockFile = FileCreateW(lockfilename);\r
+}\r
+\r
+// 一時ディレクトリを解放する\r
+void MsFreeTempDir()\r
+{\r
+       wchar_t lock_file_name[MAX_SIZE];\r
+\r
+       // ロックファイルの削除\r
+       MsGenLockFile(lock_file_name, sizeof(lock_file_name), ms->MyTempDirW);\r
+       FileClose(ms->LockFile);\r
+\r
+       // メモリ解放\r
+       Free(ms->MyTempDir);\r
+       Free(ms->MyTempDirW);\r
+       ms->MyTempDir = NULL;\r
+       ms->MyTempDirW = NULL;\r
+\r
+       // ディレクトリ削除\r
+       MsDeleteTempDir();\r
+}\r
+\r
+// ロックファイル名の生成\r
+void MsGenLockFile(wchar_t *name, UINT size, wchar_t *temp_dir)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL || temp_dir == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UniFormat(name, size, L"%s\\VPN_Lock.dat", temp_dir);\r
+}\r
+\r
+// ネットワーク設定の初期化\r
+void MsInitNetworkConfig(char *tag_name, char *instance_name, char *connection_tag_name)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       char *config_str;\r
+       // 引数チェック\r
+       if (tag_name == NULL || instance_name == NULL || connection_tag_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 文字列などの設定\r
+       Format(tmp, sizeof(tmp), connection_tag_name, instance_name);\r
+       MsSetNetworkConfig(tag_name, instance_name, tmp, true);\r
+\r
+       // インターフェイス・メトリック値の設定\r
+       config_str = MsGetNetworkAdapterGuid(tag_name, instance_name);\r
+       if (config_str != NULL)\r
+       {\r
+               Format(tmp, sizeof(tmp), "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%s",\r
+                       config_str);\r
+\r
+               MsRegWriteInt(REG_LOCAL_MACHINE, tmp, "InterfaceMetric", 1);\r
+               MsRegWriteInt(REG_LOCAL_MACHINE, tmp, "EnableDeadGWDetect", 0);\r
+\r
+               if (MsRegReadInt(REG_LOCAL_MACHINE,\r
+                       "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",\r
+                       "packetix_no_optimize") == 0)\r
+               {\r
+                       MsRegWriteInt(REG_LOCAL_MACHINE,\r
+                               "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",\r
+                               "EnableDeadGWDetect",\r
+                               0);\r
+               }\r
+\r
+               Free(config_str);\r
+       }\r
+}\r
+\r
+// ネットワーク設定を行う\r
+void MsSetNetworkConfig(char *tag_name, char *instance_name, char *friendly_name, bool show_icon)\r
+{\r
+       char *key;\r
+       char *old_name;\r
+       // 引数チェック\r
+       if (tag_name == NULL || instance_name == NULL || friendly_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       key = MsGetNetworkConfigRegKeyNameFromInstanceName(tag_name, instance_name);\r
+       if (key == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       old_name = MsRegReadStr(REG_LOCAL_MACHINE, key, "Name");\r
+       if (old_name != NULL)\r
+       {\r
+               if (MsIsVista())\r
+               {\r
+                       char arg[MAX_PATH];\r
+                       char netsh[MAX_PATH];\r
+\r
+                       Format(netsh, sizeof(netsh), "%s\\netsh.exe", MsGetSystem32Dir());\r
+\r
+                       if (StrCmp(old_name, friendly_name) != 0)\r
+                       {\r
+                               Format(arg, sizeof(arg), "interface set interface name=\"%s\" newname=\"%s\"",\r
+                                       old_name, friendly_name);\r
+\r
+                               Run(netsh, arg, true, true);\r
+                       }\r
+\r
+                       Format(arg, sizeof(arg), "netsh interface ipv4 set interface interface=\"%s\" metric=1",\r
+                               friendly_name);\r
+\r
+                       Run(netsh, arg, true, true);\r
+               }\r
+       }\r
+\r
+       if (StrCmp(old_name, friendly_name) != 0)\r
+       {\r
+               MsRegWriteStr(REG_LOCAL_MACHINE, key, "Name", friendly_name);\r
+       }\r
+\r
+       MsRegWriteInt(REG_LOCAL_MACHINE, key, "ShowIcon", show_icon ? 1 : 0);\r
+\r
+       Free(key);\r
+\r
+       Free(old_name);\r
+}\r
+\r
+// ネットワーク設定キー名をインスタンス名から取得\r
+char *MsGetNetworkConfigRegKeyNameFromInstanceName(char *tag_name, char *instance_name)\r
+{\r
+       char *guid, *ret;\r
+       // 引数チェック\r
+       if (tag_name == NULL || instance_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       guid = MsGetNetworkAdapterGuid(tag_name, instance_name);\r
+       if (guid == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = MsGetNetworkConfigRegKeyNameFromGuid(guid);\r
+\r
+       Free(guid);\r
+\r
+       return ret;\r
+}\r
+\r
+// ネットワーク設定キー名を GUID から取得\r
+char *MsGetNetworkConfigRegKeyNameFromGuid(char *guid)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (guid == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp),\r
+               "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection",\r
+               guid);\r
+\r
+       return CopyStr(tmp);\r
+}\r
+\r
+// MAC アドレスの設定\r
+void MsSetMacAddress(char *tag_name, char *instance_name, char *mac_address)\r
+{\r
+       TOKEN_LIST *key_list;\r
+       UINT i;\r
+       char dest_name[MAX_SIZE];\r
+       char mac_str[MAX_SIZE];\r
+       // 引数チェック\r
+       if (tag_name == NULL || instance_name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // MAC アドレスの正規化\r
+       if (NormalizeMacAddress(mac_str, sizeof(mac_str), mac_address) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 目的の名前を生成\r
+       Format(dest_name, sizeof(dest_name), tag_name, instance_name);\r
+\r
+       // キーを列挙\r
+       if (MsIsNt())\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}");\r
+       }\r
+       else\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "System\\CurrentControlSet\\Services\\Class\\Net");\r
+       }\r
+       if (key_list == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < key_list->NumTokens;i++)\r
+       {\r
+               char *key_name = key_list->Token[i];\r
+               char full_key_name[MAX_SIZE];\r
+               char *driver_desc;\r
+\r
+               if (MsIsNt())\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\%s",\r
+                               key_name);\r
+               }\r
+               else\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "System\\CurrentControlSet\\Services\\Class\\Net\\%s",\r
+                               key_name);\r
+               }\r
+\r
+               // DriverDesc を読み込む\r
+               driver_desc = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "DriverDesc");\r
+               if (driver_desc != NULL)\r
+               {\r
+                       if (StrCmpi(dest_name, driver_desc) == 0)\r
+                       {\r
+                               // MAC アドレスの書き込み\r
+                               MsRegWriteStr(REG_LOCAL_MACHINE, full_key_name, "NetworkAddress", mac_str);\r
+                               Free(driver_desc);\r
+\r
+                               // ドライバの再起動\r
+                               MsRestartVLan(instance_name);\r
+                               break;\r
+                       }\r
+                       Free(driver_desc);\r
+               }\r
+       }\r
+\r
+       FreeToken(key_list);\r
+\r
+       return;\r
+}\r
+\r
+// デバイスドライバのファイル名の取得\r
+char *MsGetDriverFileName(char *tag_name, char *instance_name)\r
+{\r
+       TOKEN_LIST *key_list;\r
+       UINT i;\r
+       char *ret = NULL;\r
+       char dest_name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (tag_name == NULL || instance_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 目的の名前を生成\r
+       Format(dest_name, sizeof(dest_name), tag_name, instance_name);\r
+\r
+       // キーを列挙\r
+       if (MsIsNt())\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}");\r
+       }\r
+       else\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "System\\CurrentControlSet\\Services\\Class\\Net");\r
+       }\r
+       if (key_list == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < key_list->NumTokens;i++)\r
+       {\r
+               char *key_name = key_list->Token[i];\r
+               char full_key_name[MAX_SIZE];\r
+               char *driver_desc;\r
+\r
+               if (MsIsNt())\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\%s",\r
+                               key_name);\r
+               }\r
+               else\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "System\\CurrentControlSet\\Services\\Class\\Net\\%s",\r
+                               key_name);\r
+               }\r
+\r
+               // DriverDesc を読み込む\r
+               driver_desc = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "DriverDesc");\r
+               if (driver_desc != NULL)\r
+               {\r
+                       if (StrCmpi(dest_name, driver_desc) == 0)\r
+                       {\r
+                               // ファイル名を読み込む\r
+                               ret = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "DeviceVxDs");\r
+                               Free(driver_desc);\r
+                               break;\r
+                       }\r
+                       Free(driver_desc);\r
+               }\r
+       }\r
+\r
+       FreeToken(key_list);\r
+\r
+       return ret;\r
+}\r
+\r
+// デバイスドライバのバージョンの取得\r
+char *MsGetDriverVersion(char *tag_name, char *instance_name)\r
+{\r
+       TOKEN_LIST *key_list;\r
+       TOKEN_LIST *t;\r
+       UINT i;\r
+       char *ret = NULL;\r
+       char dest_name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (tag_name == NULL || instance_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 目的の名前を生成\r
+       Format(dest_name, sizeof(dest_name), tag_name, instance_name);\r
+\r
+       // キーを列挙\r
+       if (MsIsNt())\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}");\r
+       }\r
+       else\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "System\\CurrentControlSet\\Services\\Class\\Net");\r
+       }\r
+       if (key_list == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < key_list->NumTokens;i++)\r
+       {\r
+               char *key_name = key_list->Token[i];\r
+               char full_key_name[MAX_SIZE];\r
+               char *driver_desc;\r
+\r
+               if (MsIsNt())\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\%s",\r
+                               key_name);\r
+               }\r
+               else\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "System\\CurrentControlSet\\Services\\Class\\Net\\%s",\r
+                               key_name);\r
+               }\r
+\r
+               // DriverDesc を読み込む\r
+               driver_desc = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "DriverDesc");\r
+               if (driver_desc != NULL)\r
+               {\r
+                       if (StrCmpi(dest_name, driver_desc) == 0)\r
+                       {\r
+                               // バージョン情報を読み込む\r
+                               ret = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "DriverVersion");\r
+                               if (ret == NULL)\r
+                               {\r
+                                       ret = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "SenVersion");\r
+                               }\r
+                               Free(driver_desc);\r
+                               break;\r
+                       }\r
+                       Free(driver_desc);\r
+               }\r
+       }\r
+\r
+       FreeToken(key_list);\r
+\r
+       if (ret == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t = ParseToken(ret, ", ");\r
+       if (t->NumTokens == 2)\r
+       {\r
+               Free(ret);\r
+               ret = CopyStr(t->Token[1]);\r
+       }\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// MAC アドレスの取得\r
+char *MsGetMacAddress(char *tag_name, char *instance_name)\r
+{\r
+       TOKEN_LIST *key_list;\r
+       UINT i;\r
+       char *ret = NULL;\r
+       char dest_name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (tag_name == NULL || instance_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 目的の名前を生成\r
+       Format(dest_name, sizeof(dest_name), tag_name, instance_name);\r
+\r
+       // キーを列挙\r
+       if (MsIsNt())\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}");\r
+       }\r
+       else\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "System\\CurrentControlSet\\Services\\Class\\Net");\r
+       }\r
+\r
+       if (key_list == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < key_list->NumTokens;i++)\r
+       {\r
+               char *key_name = key_list->Token[i];\r
+               char full_key_name[MAX_SIZE];\r
+               char *driver_desc;\r
+\r
+               if (MsIsNt())\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\%s",\r
+                               key_name);\r
+               }\r
+               else\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "System\\CurrentControlSet\\Services\\Class\\Net\\%s",\r
+                               key_name);\r
+               }\r
+\r
+               // DriverDesc を読み込む\r
+               driver_desc = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "DriverDesc");\r
+               if (driver_desc != NULL)\r
+               {\r
+                       if (StrCmpi(dest_name, driver_desc) == 0)\r
+                       {\r
+                               // MAC アドレスを読み込む\r
+                               ret = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "NetworkAddress");\r
+\r
+                               if (IsEmptyStr(ret) == false)\r
+                               {\r
+                                       // MAC アドレスにハイフンを入れる\r
+                                       BUF *b = StrToBin(ret);\r
+                                       if (b != NULL && b->Size == 6)\r
+                                       {\r
+                                               char tmp[MAX_SIZE];\r
+                                               MacToStr(tmp, sizeof(tmp), b->Buf);\r
+\r
+                                               Free(ret);\r
+                                               ret = CopyStr(tmp);\r
+                                       }\r
+                                       FreeBuf(b);\r
+                               }\r
+\r
+                               Free(driver_desc);\r
+                               break;\r
+                       }\r
+                       Free(driver_desc);\r
+               }\r
+       }\r
+\r
+       FreeToken(key_list);\r
+\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カードのデバイス名が本当に存在するかどうかチェックする\r
+bool MsCheckVLanDeviceIdFromRootEnum(char *name)\r
+{\r
+       TOKEN_LIST *t;\r
+       char *root;\r
+       char *keyname;\r
+       UINT i;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt())\r
+       {\r
+               root = "SYSTEM\\CurrentControlSet\\Enum\\Root\\NET";\r
+               keyname = "HardwareID";\r
+       }\r
+       else\r
+       {\r
+               root = "Enum\\Root\\Net";\r
+               keyname = "CompatibleIDs";\r
+       }\r
+\r
+       t = MsRegEnumKey(REG_LOCAL_MACHINE, root);\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = false;\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               char *subname = t->Token[i];\r
+               char fullname[MAX_SIZE];\r
+               char *value;\r
+\r
+               Format(fullname, sizeof(fullname), "%s\\%s", root, subname);\r
+\r
+               value = MsRegReadStr(REG_LOCAL_MACHINE, fullname, keyname);\r
+               if (value != NULL)\r
+               {\r
+                       if (StrCmpi(value, name) == 0)\r
+                       {\r
+                               ret = true;\r
+                       }\r
+                       Free(value);\r
+               }\r
+\r
+               if (ret)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// ネットワークアダプタの GUID の取得\r
+char *MsGetNetworkAdapterGuid(char *tag_name, char *instance_name)\r
+{\r
+       TOKEN_LIST *key_list;\r
+       UINT i;\r
+       char *ret = NULL;\r
+       char dest_name[MAX_SIZE];\r
+       // 引数チェック\r
+       if (tag_name == NULL || instance_name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 目的の名前を生成\r
+       Format(dest_name, sizeof(dest_name), tag_name, instance_name);\r
+\r
+       // キーを列挙\r
+       if (MsIsNt())\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}");\r
+       }\r
+       else\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "System\\CurrentControlSet\\Services\\Class\\Net");\r
+       }\r
+       if (key_list == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < key_list->NumTokens;i++)\r
+       {\r
+               char *key_name = key_list->Token[i];\r
+               char full_key_name[MAX_SIZE];\r
+               char *driver_desc;\r
+               char *device_id;\r
+\r
+               if (MsIsNt())\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\%s",\r
+                               key_name);\r
+               }\r
+               else\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "System\\CurrentControlSet\\Services\\Class\\Net\\%s",\r
+                               key_name);\r
+               }\r
+\r
+               device_id = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "MatchingDeviceId");\r
+\r
+               if (device_id != NULL)\r
+               {\r
+                       if (MsCheckVLanDeviceIdFromRootEnum(device_id))\r
+                       {\r
+                               // DriverDesc を読み込む\r
+                               driver_desc = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "DriverDesc");\r
+                               if (driver_desc != NULL)\r
+                               {\r
+                                       if (StrCmpi(dest_name, driver_desc) == 0)\r
+                                       {\r
+                                               // NetCfgInstanceId を読み込む\r
+                                               if (MsIsNt())\r
+                                               {\r
+                                                       ret = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "NetCfgInstanceId");\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       ret = CopyStr("");\r
+                                               }\r
+                                               Free(driver_desc);\r
+                                               Free(device_id);\r
+                                               break;\r
+                                       }\r
+                                       Free(driver_desc);\r
+                               }\r
+                       }\r
+                       Free(device_id);\r
+               }\r
+       }\r
+\r
+       FreeToken(key_list);\r
+\r
+       return ret;\r
+}\r
+// ネットワーク接続名の取得\r
+wchar_t *MsGetNetworkConnectionName(char *guid)\r
+{\r
+       wchar_t *ncname = NULL;\r
+       // 引数チェック\r
+       if (guid == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // ネットワーク接続名を取得\r
+       if (IsNt() != false && GetOsInfo()->OsType >= OSTYPE_WINDOWS_2000_PROFESSIONAL)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               Format(tmp, sizeof(tmp), "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", guid);\r
+               ncname = MsRegReadStrW(REG_LOCAL_MACHINE, tmp, "Name");\r
+       }\r
+\r
+       return ncname;\r
+}\r
+\r
+// 新しい Sen のドライバファイル名を生成\r
+bool MsMakeNewSenDriverFilename(char *name, UINT size)\r
+{\r
+       TOKEN_LIST *t = MsEnumSenDriverFilenames();\r
+       UINT i;\r
+       bool ret = false;\r
+\r
+       i = 0;\r
+       while (true)\r
+       {\r
+               char tmp[MAX_PATH];\r
+               UINT n;\r
+\r
+               i++;\r
+               if (i >= 10000)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               n = Rand32() % DRIVER_INSTALL_SYS_NAME_TAG_MAXID;\r
+\r
+               MsGenerateSenDriverFilenameFromInt(tmp, sizeof(tmp), n);\r
+\r
+               if (IsInToken(t, tmp) == false)\r
+               {\r
+                       StrCpy(name, size, tmp);\r
+                       ret = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// Sen のドライバファイル名を整数から生成\r
+void MsGenerateSenDriverFilenameFromInt(char *name, UINT size, UINT n)\r
+{\r
+       Format(name, size, DRIVER_INSTALL_SYS_NAME_TAG_NEW, n);\r
+}\r
+\r
+// インストールされている Sen のドライバファイル名の列挙\r
+TOKEN_LIST *MsEnumSenDriverFilenames()\r
+{\r
+       TOKEN_LIST *neos = MsEnumNetworkAdaptersSen();\r
+       LIST *o = NewListFast(NULL);\r
+       TOKEN_LIST *ret;\r
+       UINT i;\r
+\r
+       for (i = 0;i < neos->NumTokens;i++)\r
+       {\r
+               char filename[MAX_PATH];\r
+               if (MsGetSenDeiverFilename(filename, sizeof(filename), neos->Token[i]))\r
+               {\r
+                       Add(o, CopyStr(filename));\r
+               }\r
+       }\r
+\r
+       FreeToken(neos);\r
+\r
+       ret = ListToTokenList(o);\r
+       FreeStrList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// Sen のドライバファイル名を取得\r
+bool MsGetSenDeiverFilename(char *name, UINT size, char *instance_name)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       char *ret;\r
+       // 引数チェック\r
+       if (name == NULL || instance_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), "SYSTEM\\CurrentControlSet\\Services\\Sen_%s", instance_name);\r
+\r
+       ret = MsRegReadStr(REG_LOCAL_MACHINE, tmp, "ImagePath");\r
+       if (ret == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       GetFileNameFromFilePath(name, size, ret);\r
+       Free(ret);\r
+\r
+       return true;\r
+}\r
+\r
+// ネットワークアダプタの列挙 (Sen のみ)\r
+TOKEN_LIST *MsEnumNetworkAdaptersSen()\r
+{\r
+       TOKEN_LIST *key_list;\r
+       TOKEN_LIST *ret;\r
+       LIST *o;\r
+       UINT i;\r
+\r
+       // キーを列挙\r
+       if (MsIsNt())\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}");\r
+       }\r
+       else\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "System\\CurrentControlSet\\Services\\Class\\Net");\r
+       }\r
+       if (key_list == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListFast(CompareStr);\r
+\r
+       for (i = 0;i < key_list->NumTokens;i++)\r
+       {\r
+               char *key_name = key_list->Token[i];\r
+               char full_key_name[MAX_SIZE];\r
+               char *driver_desc;\r
+               char *device_id;\r
+\r
+               if (MsIsNt())\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\%s",\r
+                               key_name);\r
+               }\r
+               else\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "System\\CurrentControlSet\\Services\\Class\\Net\\%s",\r
+                               key_name);\r
+               }\r
+\r
+               // DriverDesc を読み込む\r
+               driver_desc = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "DriverDesc");\r
+               if (driver_desc != NULL)\r
+               {\r
+                       // 特定の名前で始まっているかどうか確認する\r
+                       device_id = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "MatchingDeviceId");\r
+\r
+                       if (device_id != NULL)\r
+                       {\r
+                               if (MsCheckVLanDeviceIdFromRootEnum(device_id))\r
+                               {\r
+                                       char *tag = "senadapter_";\r
+                                       if (StartWith(device_id, tag))\r
+                                       {\r
+                                               char tmp[MAX_SIZE];\r
+                                               StrCpy(tmp, sizeof(tmp), &device_id[StrLen(tag)]);\r
+\r
+                                               Add(o, CopyStr(tmp));\r
+                                       }\r
+                               }\r
+                               Free(device_id);\r
+                       }\r
+\r
+                       Free(driver_desc);\r
+               }\r
+       }\r
+\r
+       FreeToken(key_list);\r
+\r
+       ret = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       ret->NumTokens = LIST_NUM(o);\r
+       ret->Token = ZeroMalloc(sizeof(char *) * ret->NumTokens);\r
+       for (i = 0;i < ret->NumTokens;i++)\r
+       {\r
+               ret->Token[i] = LIST_DATA(o, i);\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// ネットワークアダプタの列挙\r
+TOKEN_LIST *MsEnumNetworkAdapters(char *start_with_name, char *start_with_name_2)\r
+{\r
+       TOKEN_LIST *key_list;\r
+       TOKEN_LIST *ret;\r
+       LIST *o;\r
+       UINT i;\r
+\r
+       // キーを列挙\r
+       if (MsIsNt())\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}");\r
+       }\r
+       else\r
+       {\r
+               key_list = MsRegEnumKey(REG_LOCAL_MACHINE,\r
+                       "System\\CurrentControlSet\\Services\\Class\\Net");\r
+       }\r
+       if (key_list == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListFast(CompareStr);\r
+\r
+       for (i = 0;i < key_list->NumTokens;i++)\r
+       {\r
+               char *key_name = key_list->Token[i];\r
+               char full_key_name[MAX_SIZE];\r
+               char *driver_desc;\r
+               char *device_id;\r
+\r
+               if (MsIsNt())\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\%s",\r
+                               key_name);\r
+               }\r
+               else\r
+               {\r
+                       Format(full_key_name, sizeof(full_key_name),\r
+                               "System\\CurrentControlSet\\Services\\Class\\Net\\%s",\r
+                               key_name);\r
+               }\r
+\r
+               // DriverDesc を読み込む\r
+               driver_desc = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "DriverDesc");\r
+               if (driver_desc != NULL)\r
+               {\r
+                       // 特定の名前で始まっているかどうか確認する\r
+                       if ((IsEmptyStr(start_with_name) && IsEmptyStr(start_with_name_2)) ||\r
+                               (StartWith(driver_desc, start_with_name) || StartWith(driver_desc, start_with_name_2)))\r
+                       {\r
+                               device_id = MsRegReadStr(REG_LOCAL_MACHINE, full_key_name, "MatchingDeviceId");\r
+\r
+                               if (device_id != NULL)\r
+                               {\r
+                                       if (MsCheckVLanDeviceIdFromRootEnum(device_id))\r
+                                       {\r
+                                               char instance_name[MAX_SIZE];\r
+                                               // 名前からインスタンス名だけを抽出する\r
+                                               if (StartWith(driver_desc, start_with_name))\r
+                                               {\r
+                                                       if (StrLen(driver_desc) > (StrLen(start_with_name) + 3))\r
+                                                       {\r
+                                                               StrCpy(instance_name, sizeof(instance_name),\r
+                                                                       driver_desc + StrLen(start_with_name) + 3);\r
+                                                               Add(o, CopyStr(instance_name));\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       if (StrLen(driver_desc) > (StrLen(start_with_name_2) + 3))\r
+                                                       {\r
+                                                               StrCpy(instance_name, sizeof(instance_name),\r
+                                                                       driver_desc + StrLen(start_with_name_2) + 3);\r
+                                                               Add(o, CopyStr(instance_name));\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       Free(device_id);\r
+                               }\r
+                       }\r
+\r
+                       Free(driver_desc);\r
+               }\r
+       }\r
+\r
+       FreeToken(key_list);\r
+\r
+       ret = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       ret->NumTokens = LIST_NUM(o);\r
+       ret->Token = ZeroMalloc(sizeof(char *) * ret->NumTokens);\r
+       for (i = 0;i < ret->NumTokens;i++)\r
+       {\r
+               ret->Token[i] = LIST_DATA(o, i);\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+// ドメインへのログオンを試行する\r
+bool MsCheckLogon(wchar_t *username, char *password)\r
+{\r
+       wchar_t password_unicode[MAX_SIZE];\r
+       HANDLE h;\r
+       // 引数チェック\r
+       if (username == NULL || password == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrToUni(password_unicode, sizeof(password_unicode), password);\r
+\r
+       if (GET_KETA(GetOsInfo()->OsType, 100) >= 2)\r
+       {\r
+               if (ms->nt->LogonUserW(username, NULL, password_unicode, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &h) == false)\r
+               {\r
+                       // ログオン失敗\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               char username_ansi[MAX_SIZE];\r
+               UniToStr(username_ansi, sizeof(username_ansi), username);\r
+\r
+               if (ms->nt->LogonUserA(username_ansi, NULL, password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &h) == false)\r
+               {\r
+                       // ログオン失敗\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       CloseHandle(h);\r
+\r
+       return true;\r
+}\r
+\r
+// ドメインへのログオンを試行する\r
+bool MsIsPasswordEmpty(wchar_t *username)\r
+{\r
+       HANDLE h;\r
+       // 引数チェック\r
+       if (username == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GET_KETA(GetOsInfo()->OsType, 100) >= 2)\r
+       {\r
+               if (ms->nt->LogonUserW(username, NULL, L"", LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &h) == false)\r
+               {\r
+                       // ログオン失敗\r
+                       if (GetLastError() == 1327)\r
+                       {\r
+                               // パスワードが空\r
+                               return true;\r
+                       }\r
+                       else\r
+                       {\r
+                               // パスワードが間違っている\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               char username_ansi[MAX_SIZE];\r
+               UniToStr(username_ansi, sizeof(username_ansi), username);\r
+\r
+               if (ms->nt->LogonUserA(username_ansi, NULL, "", LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &h) == false)\r
+               {\r
+                       // ログオン失敗\r
+                       if (GetLastError() == 1327)\r
+                       {\r
+                               // パスワードが空\r
+                               return true;\r
+                       }\r
+                       else\r
+                       {\r
+                               // パスワードが間違っている\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+\r
+       CloseHandle(h);\r
+\r
+       // ログオン成功ということはパスワードが空ということになる\r
+       return false;\r
+}\r
+\r
+// シャットダウンの実行 (NT)\r
+bool MsShutdownEx(bool reboot, bool force, UINT time_limit, char *message)\r
+{\r
+       if (MsIsNt() == false)\r
+       {\r
+               return MsShutdown(reboot, force);\r
+       }\r
+\r
+       // 特権の取得\r
+       if (MsEnablePrivilege(SE_SHUTDOWN_NAME, true) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // シャットダウンの実行\r
+       if (ms->nt->InitiateSystemShutdown(NULL, message, time_limit, force, reboot) == false)\r
+       {\r
+               MsEnablePrivilege(SE_SHUTDOWN_NAME, false);\r
+               return false;\r
+       }\r
+\r
+       // 特権の解放\r
+       MsEnablePrivilege(SE_SHUTDOWN_NAME, false);\r
+\r
+       return true;\r
+}\r
+\r
+// シャットダウンの実行\r
+bool MsShutdown(bool reboot, bool force)\r
+{\r
+       UINT flag = 0;\r
+       // 特権の取得\r
+       if (MsEnablePrivilege(SE_SHUTDOWN_NAME, true) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       flag |= (reboot ? EWX_REBOOT : EWX_SHUTDOWN);\r
+       flag |= (force ? EWX_FORCE : 0);\r
+\r
+       // シャットダウンの実行\r
+       if (ExitWindowsEx(flag, 0) == false)\r
+       {\r
+               MsEnablePrivilege(SE_SHUTDOWN_NAME, false);\r
+               return false;\r
+       }\r
+\r
+       // 特権の解放\r
+       MsEnablePrivilege(SE_SHUTDOWN_NAME, false);\r
+\r
+       return true;\r
+}\r
+\r
+// 特権を有効または無効にする\r
+bool MsEnablePrivilege(char *name, bool enable)\r
+{\r
+       HANDLE hToken;\r
+       NT_API *nt = ms->nt;\r
+       LUID luid;\r
+       TOKEN_PRIVILEGES *tp;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (MsIsNt() == false)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       // プロセストークンを開く\r
+       if (nt->OpenProcessToken(ms->hCurrentProcess, TOKEN_ADJUST_PRIVILEGES, &hToken) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ローカル一意識別子を取得する\r
+       if (nt->LookupPrivilegeValue(NULL, name, &luid) == FALSE)\r
+       {\r
+               CloseHandle(hToken);\r
+               return false;\r
+       }\r
+\r
+       // 特権を有効 / 無効にするための構造体を作成する\r
+       tp = ZeroMalloc(sizeof(TOKEN_PRIVILEGES));\r
+       tp->PrivilegeCount = 1;\r
+       tp->Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED : 0;\r
+       Copy(&tp->Privileges[0].Luid, &luid, sizeof(LUID));\r
+\r
+       // 特権を操作する\r
+       ret = nt->AdjustTokenPrivileges(hToken, false, tp, sizeof(TOKEN_PRIVILEGES), 0, 0);\r
+\r
+       Free(tp);\r
+       CloseHandle(hToken);\r
+\r
+       return ret;\r
+}\r
+\r
+// 現在の OS が NT 系かどうか取得\r
+bool MsIsNt()\r
+{\r
+       if (ms == NULL)\r
+       {\r
+               OSVERSIONINFO os;\r
+               Zero(&os, sizeof(os));\r
+               os.dwOSVersionInfoSize = sizeof(os);\r
+               GetVersionEx(&os);\r
+               if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)\r
+               {\r
+                       return true;\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       return ms->IsNt;\r
+}\r
+\r
+// 現在のユーザーが Admin かどうか取得\r
+bool MsIsAdmin()\r
+{\r
+       return ms->IsAdmin;\r
+}\r
+\r
+// NT 系関数のロード\r
+NT_API *MsLoadNtApiFunctions()\r
+{\r
+       NT_API *nt = ZeroMalloc(sizeof(NT_API));\r
+       OSVERSIONINFO info;\r
+\r
+       Zero(&info, sizeof(info));\r
+       info.dwOSVersionInfoSize = sizeof(info);\r
+       GetVersionEx(&info);\r
+\r
+       nt->hKernel32 = LoadLibrary("kernel32.dll");\r
+       if (nt->hKernel32 == NULL)\r
+       {\r
+               Free(nt);\r
+               return NULL;\r
+       }\r
+\r
+       nt->hAdvapi32 = LoadLibrary("advapi32.dll");\r
+       if (nt->hAdvapi32 == NULL)\r
+       {\r
+               Free(nt);\r
+               return NULL;\r
+       }\r
+\r
+       nt->hShell32 = LoadLibrary("shell32.dll");\r
+       if (nt->hShell32 == NULL)\r
+       {\r
+               FreeLibrary(nt->hAdvapi32);\r
+               Free(nt);\r
+               return NULL;\r
+       }\r
+\r
+       nt->hPsApi = LoadLibrary("psapi.dll");\r
+\r
+       if (info.dwMajorVersion >= 5)\r
+       {\r
+               nt->hNewDev = LoadLibrary("newdev.dll");\r
+               if (nt->hNewDev == NULL)\r
+               {\r
+                       FreeLibrary(nt->hShell32);\r
+                       FreeLibrary(nt->hAdvapi32);\r
+                       Free(nt);\r
+                       return NULL;\r
+               }\r
+\r
+               nt->hSetupApi = LoadLibrary("setupapi.dll");\r
+       }\r
+\r
+       nt->hSecur32 = LoadLibrary("secur32.dll");\r
+\r
+       nt->hUser32 = LoadLibrary("user32.dll");\r
+\r
+       nt->hDbgHelp = LoadLibrary("dbghelp.dll");\r
+\r
+       // 関数の読み込み\r
+       nt->IsWow64Process =\r
+               (BOOL (__stdcall *)(HANDLE,BOOL *))\r
+               GetProcAddress(nt->hKernel32, "IsWow64Process");\r
+\r
+       nt->GetFileInformationByHandle =\r
+               (BOOL (__stdcall *)(HANDLE,LPBY_HANDLE_FILE_INFORMATION))\r
+               GetProcAddress(nt->hKernel32, "GetFileInformationByHandle");\r
+\r
+       nt->GetProcessHeap =\r
+               (HANDLE (__stdcall *)())\r
+               GetProcAddress(nt->hKernel32, "GetProcessHeap");\r
+\r
+       nt->SetProcessShutdownParameters =\r
+               (BOOL (__stdcall *)(DWORD,DWORD))\r
+               GetProcAddress(nt->hKernel32, "SetProcessShutdownParameters");\r
+\r
+       nt->GetNativeSystemInfo =\r
+               (void (__stdcall *)(SYSTEM_INFO *))\r
+               GetProcAddress(nt->hKernel32, "GetNativeSystemInfo");\r
+\r
+       nt->AdjustTokenPrivileges =\r
+               (BOOL (__stdcall *)(HANDLE,BOOL,PTOKEN_PRIVILEGES,DWORD,PTOKEN_PRIVILEGES,PDWORD))\r
+               GetProcAddress(nt->hAdvapi32, "AdjustTokenPrivileges");\r
+\r
+       nt->LookupPrivilegeValue =\r
+               (BOOL (__stdcall *)(char *,char *,PLUID))\r
+               GetProcAddress(nt->hAdvapi32, "LookupPrivilegeValueA");\r
+\r
+       nt->OpenProcessToken =\r
+               (BOOL (__stdcall *)(HANDLE,DWORD,PHANDLE))\r
+               GetProcAddress(nt->hAdvapi32, "OpenProcessToken");\r
+\r
+       nt->InitiateSystemShutdown =\r
+               (BOOL (__stdcall *)(LPTSTR,LPTSTR,DWORD,BOOL,BOOL))\r
+               GetProcAddress(nt->hAdvapi32, "InitiateSystemShutdownA");\r
+\r
+       nt->LogonUserW =\r
+               (BOOL (__stdcall *)(wchar_t *,wchar_t *,wchar_t *,DWORD,DWORD,HANDLE *))\r
+               GetProcAddress(nt->hAdvapi32, "LogonUserW");\r
+\r
+       nt->LogonUserA =\r
+               (BOOL (__stdcall *)(char *,char *,char *,DWORD,DWORD,HANDLE * ))\r
+               GetProcAddress(nt->hAdvapi32, "LogonUserA");\r
+\r
+       nt->DuplicateTokenEx =\r
+               (BOOL (__stdcall *)(HANDLE,DWORD,SECURITY_ATTRIBUTES *,SECURITY_IMPERSONATION_LEVEL,TOKEN_TYPE,HANDLE *))\r
+               GetProcAddress(nt->hAdvapi32, "DuplicateTokenEx");\r
+\r
+       nt->ConvertStringSidToSidA =\r
+               (BOOL (__stdcall *)(LPCSTR,PSID *))\r
+               GetProcAddress(nt->hAdvapi32, "ConvertStringSidToSidA");\r
+\r
+       nt->GetTokenInformation =\r
+               (BOOL (__stdcall *)(HANDLE,TOKEN_INFORMATION_CLASS,void *,DWORD,PDWORD))\r
+               GetProcAddress(nt->hAdvapi32, "GetTokenInformation");\r
+\r
+       nt->SetTokenInformation =\r
+               (BOOL (__stdcall *)(HANDLE,TOKEN_INFORMATION_CLASS,void *,DWORD))\r
+               GetProcAddress(nt->hAdvapi32, "SetTokenInformation");\r
+\r
+       nt->CreateProcessAsUserA =\r
+               (BOOL (__stdcall *)(HANDLE,LPCSTR,LPSTR,LPSECURITY_ATTRIBUTES,LPSECURITY_ATTRIBUTES,BOOL,DWORD,void *,LPCSTR,LPSTARTUPINFOA,LPPROCESS_INFORMATION))\r
+               GetProcAddress(nt->hAdvapi32, "CreateProcessAsUserA");\r
+\r
+       nt->CreateProcessAsUserW =\r
+               (BOOL (__stdcall *)(HANDLE,LPCWSTR,LPWSTR,LPSECURITY_ATTRIBUTES,LPSECURITY_ATTRIBUTES,BOOL,DWORD,void *,LPCWSTR,LPSTARTUPINFOW,LPPROCESS_INFORMATION))\r
+               GetProcAddress(nt->hAdvapi32, "CreateProcessAsUserW");\r
+\r
+       nt->LookupAccountSidA =\r
+               (BOOL (__stdcall *)(LPCSTR,PSID,LPSTR,LPDWORD,LPSTR,LPDWORD,PSID_NAME_USE))\r
+               GetProcAddress(nt->hAdvapi32, "LookupAccountSidA");\r
+\r
+       nt->LookupAccountNameA =\r
+               (BOOL (__stdcall *)(LPCSTR,LPCSTR,PSID,LPDWORD,LPSTR,LPDWORD,PSID_NAME_USE))\r
+               GetProcAddress(nt->hAdvapi32, "LookupAccountNameA");\r
+\r
+       if (info.dwMajorVersion >= 5)\r
+       {\r
+               nt->UpdateDriverForPlugAndPlayDevicesW =\r
+                       (BOOL (__stdcall *)(HWND,wchar_t *,wchar_t *,UINT,BOOL *))\r
+                       GetProcAddress(nt->hNewDev, "UpdateDriverForPlugAndPlayDevicesW");\r
+\r
+               nt->CM_Get_Device_ID_ExA =\r
+                       (UINT (__stdcall *)(DWORD,char *,UINT,UINT,HANDLE))\r
+                       GetProcAddress(nt->hSetupApi, "CM_Get_Device_ID_ExA");\r
+\r
+               nt->CM_Get_DevNode_Status_Ex =\r
+                       (UINT (__stdcall *)(UINT *,UINT *,DWORD,UINT,HANDLE))\r
+                       GetProcAddress(nt->hSetupApi, "CM_Get_DevNode_Status_Ex");\r
+       }\r
+\r
+       nt->hWtsApi32 = LoadLibrary("wtsapi32.dll");\r
+       if (nt->hWtsApi32 != NULL)\r
+       {\r
+               // ターミナルサービス関係の API\r
+               nt->WTSQuerySessionInformation =\r
+                       (UINT (__stdcall *)(HANDLE,DWORD,WTS_INFO_CLASS,wchar_t *,DWORD *))\r
+                       GetProcAddress(nt->hWtsApi32, "WTSQuerySessionInformationW");\r
+               nt->WTSFreeMemory =\r
+                       (void (__stdcall *)(void *))\r
+                       GetProcAddress(nt->hWtsApi32, "WTSFreeMemory");\r
+               nt->WTSDisconnectSession =\r
+                       (BOOL (__stdcall *)(HANDLE,DWORD,BOOL))\r
+                       GetProcAddress(nt->hWtsApi32, "WTSDisconnectSession");\r
+               nt->WTSEnumerateSessionsA =\r
+                       (BOOL (__stdcall *)(HANDLE,DWORD,DWORD,PWTS_SESSION_INFOA *,DWORD *))\r
+                       GetProcAddress(nt->hWtsApi32, "WTSEnumerateSessionsA");\r
+       }\r
+\r
+       // サービス系 API\r
+       nt->OpenSCManager =\r
+               (SC_HANDLE (__stdcall *)(LPCTSTR,LPCTSTR,DWORD))\r
+               GetProcAddress(nt->hAdvapi32, "OpenSCManagerA");\r
+       nt->CreateServiceA =\r
+               (SC_HANDLE (__stdcall *)(SC_HANDLE,LPCTSTR,LPCTSTR,DWORD,DWORD,DWORD,DWORD,LPCTSTR,LPCTSTR,LPDWORD,LPCTSTR,LPCTSTR,LPCTSTR))\r
+               GetProcAddress(nt->hAdvapi32, "CreateServiceA");\r
+       nt->CreateServiceW =\r
+               (SC_HANDLE (__stdcall *)(SC_HANDLE,LPCWSTR,LPCWSTR,DWORD,DWORD,DWORD,DWORD,LPCWSTR,LPCWSTR,LPDWORD,LPCWSTR,LPCWSTR,LPCWSTR))\r
+               GetProcAddress(nt->hAdvapi32, "CreateServiceW");\r
+       nt->ChangeServiceConfig2 =\r
+               (BOOL (__stdcall *)(SC_HANDLE,DWORD,LPVOID))\r
+               GetProcAddress(nt->hAdvapi32, "ChangeServiceConfig2W");\r
+       nt->CloseServiceHandle =\r
+               (BOOL (__stdcall *)(SC_HANDLE))\r
+               GetProcAddress(nt->hAdvapi32, "CloseServiceHandle");\r
+       nt->OpenService =\r
+               (SC_HANDLE (__stdcall *)(SC_HANDLE,LPCTSTR,DWORD))\r
+               GetProcAddress(nt->hAdvapi32, "OpenServiceA");\r
+       nt->QueryServiceStatus =\r
+               (BOOL (__stdcall *)(SC_HANDLE,LPSERVICE_STATUS))\r
+               GetProcAddress(nt->hAdvapi32, "QueryServiceStatus");\r
+       nt->StartService =\r
+               (BOOL (__stdcall *)(SC_HANDLE,DWORD,LPCTSTR))\r
+               GetProcAddress(nt->hAdvapi32, "StartServiceA");\r
+       nt->ControlService =\r
+               (BOOL (__stdcall *)(SC_HANDLE,DWORD,LPSERVICE_STATUS))\r
+               GetProcAddress(nt->hAdvapi32, "ControlService");\r
+       nt->SetServiceStatus =\r
+               (BOOL (__stdcall *)(SERVICE_STATUS_HANDLE,LPSERVICE_STATUS))\r
+               GetProcAddress(nt->hAdvapi32, "SetServiceStatus");\r
+       nt->RegisterServiceCtrlHandler =\r
+               (SERVICE_STATUS_HANDLE (__stdcall *)(LPCTSTR,LPHANDLER_FUNCTION))\r
+               GetProcAddress(nt->hAdvapi32, "RegisterServiceCtrlHandlerW");\r
+       nt->StartServiceCtrlDispatcher =\r
+               (BOOL (__stdcall *)(const LPSERVICE_TABLE_ENTRY))\r
+               GetProcAddress(nt->hAdvapi32, "StartServiceCtrlDispatcherW");\r
+       nt->DeleteService =\r
+               (BOOL (__stdcall *)(SC_HANDLE))\r
+               GetProcAddress(nt->hAdvapi32, "DeleteService");\r
+       nt->RegisterEventSourceW =\r
+               (HANDLE (__stdcall *)(LPCWSTR,LPCWSTR))\r
+               GetProcAddress(nt->hAdvapi32, "RegisterEventSourceW");\r
+       nt->ReportEventW =\r
+               (BOOL (__stdcall *)(HANDLE,WORD,WORD,DWORD,PSID,WORD,DWORD,LPCWSTR *,LPVOID))\r
+               GetProcAddress(nt->hAdvapi32, "ReportEventW");\r
+       nt->DeregisterEventSource =\r
+               (BOOL (__stdcall *)(HANDLE))\r
+               GetProcAddress(nt->hAdvapi32, "DeregisterEventSource");\r
+       nt->Wow64DisableWow64FsRedirection =\r
+               (BOOL (__stdcall *)(void **))\r
+               GetProcAddress(nt->hKernel32, "Wow64DisableWow64FsRedirection");\r
+       nt->Wow64EnableWow64FsRedirection =\r
+               (BOOLEAN (__stdcall *)(BOOLEAN))\r
+               GetProcAddress(nt->hKernel32, "Wow64EnableWow64FsRedirection");\r
+       nt->Wow64RevertWow64FsRedirection =\r
+               (BOOL (__stdcall *)(void *))\r
+               GetProcAddress(nt->hKernel32, "Wow64RevertWow64FsRedirection");\r
+\r
+       if (nt->hPsApi != NULL)\r
+       {\r
+               // プロセス系 API\r
+               nt->EnumProcesses =\r
+                       (BOOL (__stdcall *)(DWORD *,DWORD,DWORD *))\r
+                       GetProcAddress(nt->hPsApi, "EnumProcesses");\r
+\r
+               nt->EnumProcessModules =\r
+                       (BOOL (__stdcall *)(HANDLE,HMODULE * ,DWORD,DWORD *))\r
+                       GetProcAddress(nt->hPsApi, "EnumProcessModules");\r
+\r
+               nt->GetModuleFileNameExA =\r
+                       (DWORD (__stdcall *)(HANDLE,HMODULE,LPSTR,DWORD))\r
+                       GetProcAddress(nt->hPsApi, "GetModuleFileNameExA");\r
+\r
+               nt->GetModuleFileNameExW =\r
+                       (DWORD (__stdcall *)(HANDLE,HMODULE,LPWSTR,DWORD))\r
+                       GetProcAddress(nt->hPsApi, "GetModuleFileNameExW");\r
+       }\r
+\r
+       // レジストリ系 API\r
+       nt->RegDeleteKeyExA =\r
+               (LONG (__stdcall *)(HKEY,LPCTSTR,REGSAM,DWORD))\r
+               GetProcAddress(nt->hAdvapi32, "RegDeleteKeyExA");\r
+\r
+       // セキュリティ系 API\r
+       if (nt->hSecur32 != NULL)\r
+       {\r
+               nt->GetUserNameExA =\r
+                       (BOOL (__stdcall *)(EXTENDED_NAME_FORMAT,LPSTR,PULONG))\r
+                       GetProcAddress(nt->hSecur32, "GetUserNameExA");\r
+\r
+               nt->GetUserNameExW =\r
+                       (BOOL (__stdcall *)(EXTENDED_NAME_FORMAT,LPWSTR,PULONG))\r
+                       GetProcAddress(nt->hSecur32, "GetUserNameExW");\r
+       }\r
+\r
+       // デスクトップ系 API\r
+       if (nt->hUser32 != NULL)\r
+       {\r
+               nt->SwitchDesktop =\r
+                       (BOOL (__stdcall *)(HDESK))\r
+                       GetProcAddress(nt->hUser32, "SwitchDesktop");\r
+               nt->OpenDesktopA =\r
+                       (HDESK (__stdcall *)(LPTSTR,DWORD,BOOL,ACCESS_MASK))\r
+                       GetProcAddress(nt->hUser32, "OpenDesktopA");\r
+               nt->CloseDesktop =\r
+                       (BOOL (__stdcall *)(HDESK))\r
+                       GetProcAddress(nt->hUser32, "CloseDesktop");\r
+       }\r
+\r
+       // デバッグ系 API\r
+       if (nt->hDbgHelp != NULL)\r
+       {\r
+               nt->MiniDumpWriteDump =\r
+                       (BOOL (__stdcall *)(HANDLE,DWORD,HANDLE,MINIDUMP_TYPE,PMINIDUMP_EXCEPTION_INFORMATION,PMINIDUMP_USER_STREAM_INFORMATION,PMINIDUMP_CALLBACK_INFORMATION))\r
+                       GetProcAddress(nt->hDbgHelp, "MiniDumpWriteDump");\r
+       }\r
+\r
+       return nt;\r
+}\r
+\r
+// NT 系関数の解放\r
+void MsFreeNtApiFunctions(NT_API *nt)\r
+{\r
+       // 引数チェック\r
+       if (nt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (nt->hSecur32 != NULL)\r
+       {\r
+               FreeLibrary(nt->hSecur32);\r
+       }\r
+\r
+       if (nt->hNewDev != NULL)\r
+       {\r
+               FreeLibrary(nt->hSetupApi);\r
+               FreeLibrary(nt->hNewDev);\r
+       }\r
+\r
+       FreeLibrary(nt->hAdvapi32);\r
+\r
+       FreeLibrary(nt->hShell32);\r
+\r
+       if (nt->hWtsApi32 != NULL)\r
+       {\r
+               FreeLibrary(nt->hWtsApi32);\r
+       }\r
+\r
+       if (nt->hPsApi != NULL)\r
+       {\r
+               FreeLibrary(nt->hPsApi);\r
+       }\r
+\r
+       if (nt->hUser32 != NULL)\r
+       {\r
+               FreeLibrary(nt->hUser32);\r
+       }\r
+\r
+       if (nt->hDbgHelp != NULL)\r
+       {\r
+               FreeLibrary(nt->hDbgHelp);\r
+       }\r
+\r
+       FreeLibrary(nt->hKernel32);\r
+\r
+       Free(nt);\r
+}\r
+\r
+// 64 bit アプリケーションのために 32 bit レジストリキーへのアクセスを強制するアクセスマスクを生成する\r
+DWORD MsRegAccessMaskFor64Bit(bool force32bit)\r
+{\r
+       return MsRegAccessMaskFor64BitEx(force32bit, false);\r
+}\r
+DWORD MsRegAccessMaskFor64BitEx(bool force32bit, bool force64bit)\r
+{\r
+       if (MsIs64BitWindows() == false)\r
+       {\r
+               return 0;\r
+       }\r
+       if (force32bit)\r
+       {\r
+               return KEY_WOW64_32KEY;\r
+       }\r
+       if (force64bit)\r
+       {\r
+               return KEY_WOW64_64KEY;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+// 値の削除\r
+bool MsRegDeleteValue(UINT root, char *keyname, char *valuename)\r
+{\r
+       return MsRegDeleteValueEx(root, keyname, valuename, false);\r
+}\r
+bool MsRegDeleteValueEx(UINT root, char *keyname, char *valuename, bool force32bit)\r
+{\r
+       return MsRegDeleteValueEx2(root, keyname, valuename, force32bit, false);\r
+}\r
+bool MsRegDeleteValueEx2(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit)\r
+{\r
+       HKEY h;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (keyname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (RegOpenKeyEx(MsGetRootKeyFromInt(root), keyname, 0, KEY_ALL_ACCESS | MsRegAccessMaskFor64BitEx(force32bit, force64bit), &h) != ERROR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (RegDeleteValue(h, valuename) != ERROR_SUCCESS)\r
+       {\r
+               ret = false;\r
+       }\r
+       else\r
+       {\r
+               ret = true;\r
+       }\r
+\r
+       RegCloseKey(h);\r
+\r
+       return ret;\r
+}\r
+\r
+// キーの削除\r
+bool MsRegDeleteKey(UINT root, char *keyname)\r
+{\r
+       return MsRegDeleteKeyEx(root, keyname, false);\r
+}\r
+bool MsRegDeleteKeyEx(UINT root, char *keyname, bool force32bit)\r
+{\r
+       return MsRegDeleteKeyEx2(root, keyname, force32bit, false);\r
+}\r
+bool MsRegDeleteKeyEx2(UINT root, char *keyname, bool force32bit, bool force64bit)\r
+{\r
+       // 引数チェック\r
+       if (keyname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MsIsNt() && ms->nt->RegDeleteKeyExA != NULL)\r
+       {\r
+               if (ms->nt->RegDeleteKeyExA(MsGetRootKeyFromInt(root), keyname, MsRegAccessMaskFor64BitEx(force32bit, force64bit), 0) != ERROR_SUCCESS)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (RegDeleteKey(MsGetRootKeyFromInt(root), keyname) != ERROR_SUCCESS)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 値の列挙\r
+TOKEN_LIST *MsRegEnumValue(UINT root, char *keyname)\r
+{\r
+       return MsRegEnumValueEx(root, keyname, false);\r
+}\r
+TOKEN_LIST *MsRegEnumValueEx(UINT root, char *keyname, bool force32bit)\r
+{\r
+       return MsRegEnumValueEx2(root, keyname, force32bit, false);\r
+}\r
+TOKEN_LIST *MsRegEnumValueEx2(UINT root, char *keyname, bool force32bit, bool force64bit)\r
+{\r
+       HKEY h;\r
+       UINT i;\r
+       TOKEN_LIST *t;\r
+       LIST *o;\r
+\r
+       if (keyname == NULL)\r
+       {\r
+               h = MsGetRootKeyFromInt(root);\r
+       }\r
+       else\r
+       {\r
+               if (RegOpenKeyEx(MsGetRootKeyFromInt(root), keyname, 0, KEY_READ | MsRegAccessMaskFor64BitEx(force32bit, force64bit), &h) != ERROR_SUCCESS)\r
+               {\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       o = NewListFast(CompareStr);\r
+\r
+       for (i = 0;;i++)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               UINT ret;\r
+               UINT size = sizeof(tmp);\r
+\r
+               Zero(tmp, sizeof(tmp));\r
+               ret = RegEnumValue(h, i, tmp, &size, NULL, NULL, NULL, NULL);\r
+               if (ret == ERROR_NO_MORE_ITEMS)\r
+               {\r
+                       break;\r
+               }\r
+               else if (ret != ERROR_SUCCESS)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               Add(o, CopyStr(tmp));\r
+       }\r
+\r
+       Sort(o);\r
+\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               t->Token[i] = LIST_DATA(o, i);\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       if (keyname != NULL)\r
+       {\r
+               RegCloseKey(h);\r
+       }\r
+\r
+       return t;\r
+}\r
+\r
+// キーの列挙\r
+TOKEN_LIST *MsRegEnumKey(UINT root, char *keyname)\r
+{\r
+       return MsRegEnumKeyEx(root, keyname, false);\r
+}\r
+TOKEN_LIST *MsRegEnumKeyEx(UINT root, char *keyname, bool force32bit)\r
+{\r
+       return MsRegEnumKeyEx2(root, keyname, force32bit, false);\r
+}\r
+TOKEN_LIST *MsRegEnumKeyEx2(UINT root, char *keyname, bool force32bit, bool force64bit)\r
+{\r
+       HKEY h;\r
+       UINT i;\r
+       TOKEN_LIST *t;\r
+       LIST *o;\r
+\r
+       if (keyname == NULL)\r
+       {\r
+               h = MsGetRootKeyFromInt(root);\r
+       }\r
+       else\r
+       {\r
+               if (RegOpenKeyEx(MsGetRootKeyFromInt(root), keyname, 0, KEY_READ | MsRegAccessMaskFor64BitEx(force32bit, force64bit), &h) != ERROR_SUCCESS)\r
+               {\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       o = NewListFast(CompareStr);\r
+\r
+       for (i = 0;;i++)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               UINT ret;\r
+               UINT size = sizeof(tmp);\r
+               FILETIME ft;\r
+\r
+               Zero(tmp, sizeof(tmp));\r
+               ret = RegEnumKeyEx(h, i, tmp, &size, NULL, NULL, NULL, &ft);\r
+               if (ret == ERROR_NO_MORE_ITEMS)\r
+               {\r
+                       break;\r
+               }\r
+               else if (ret != ERROR_SUCCESS)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               Add(o, CopyStr(tmp));\r
+       }\r
+\r
+       Sort(o);\r
+\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               t->Token[i] = LIST_DATA(o, i);\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       if (keyname != NULL)\r
+       {\r
+               RegCloseKey(h);\r
+       }\r
+\r
+       return t;\r
+}\r
+\r
+// バイナリデータを設定する\r
+bool MsRegWriteBin(UINT root, char *keyname, char *valuename, void *data, UINT size)\r
+{\r
+       return MsRegWriteBinEx(root, keyname, valuename, data, size, false);\r
+}\r
+bool MsRegWriteBinEx(UINT root, char *keyname, char *valuename, void *data, UINT size, bool force32bit)\r
+{\r
+       return MsRegWriteBinEx2(root, keyname, valuename, data, size, force32bit, false);\r
+}\r
+bool MsRegWriteBinEx2(UINT root, char *keyname, char *valuename, void *data, UINT size, bool force32bit, bool force64bit)\r
+{\r
+       // 引数チェック\r
+       if (keyname == NULL || (size != 0 && data == NULL))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return MsRegWriteValueEx2(root, keyname, valuename, REG_BINARY, data, size, force32bit, force64bit);\r
+}\r
+\r
+// 整数値を設定する\r
+bool MsRegWriteInt(UINT root, char *keyname, char *valuename, UINT value)\r
+{\r
+       return MsRegWriteIntEx(root, keyname, valuename, value, false);\r
+}\r
+bool MsRegWriteIntEx(UINT root, char *keyname, char *valuename, UINT value, bool force32bit)\r
+{\r
+       return MsRegWriteIntEx2(root, keyname, valuename, value, force32bit, false);\r
+}\r
+bool MsRegWriteIntEx2(UINT root, char *keyname, char *valuename, UINT value, bool force32bit, bool force64bit)\r
+{\r
+       // 引数チェック\r
+       if (keyname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // エンディアン補正\r
+       if (IsBigEndian())\r
+       {\r
+               value = Swap32(value);\r
+       }\r
+\r
+       return MsRegWriteValueEx2(root, keyname, valuename, REG_DWORD_LITTLE_ENDIAN, &value, sizeof(UINT), force32bit, force64bit);\r
+}\r
+\r
+// 文字列を設定する\r
+bool MsRegWriteStrExpand(UINT root, char *keyname, char *valuename, char *str)\r
+{\r
+       return MsRegWriteStrExpandEx(root, keyname, valuename, str, false);\r
+}\r
+bool MsRegWriteStrExpandEx(UINT root, char *keyname, char *valuename, char *str, bool force32bit)\r
+{\r
+       return MsRegWriteStrExpandEx2(root, keyname, valuename, str, force32bit, false);\r
+}\r
+bool MsRegWriteStrExpandEx2(UINT root, char *keyname, char *valuename, char *str, bool force32bit, bool force64bit)\r
+{\r
+       // 引数チェック\r
+       if (keyname == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return MsRegWriteValueEx2(root, keyname, valuename, REG_EXPAND_SZ, str, StrSize(str), force32bit, force64bit);\r
+}\r
+bool MsRegWriteStrExpandW(UINT root, char *keyname, char *valuename, wchar_t *str)\r
+{\r
+       return MsRegWriteStrExpandExW(root, keyname, valuename, str, false);\r
+}\r
+bool MsRegWriteStrExpandExW(UINT root, char *keyname, char *valuename, wchar_t *str, bool force32bit)\r
+{\r
+       return MsRegWriteStrExpandEx2W(root, keyname, valuename, str, force32bit, false);\r
+}\r
+bool MsRegWriteStrExpandEx2W(UINT root, char *keyname, char *valuename, wchar_t *str, bool force32bit, bool force64bit)\r
+{\r
+       // 引数チェック\r
+       if (keyname == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return MsRegWriteValueEx2W(root, keyname, valuename, REG_EXPAND_SZ, str, UniStrSize(str), force32bit, force64bit);\r
+}\r
+\r
+bool MsRegWriteStr(UINT root, char *keyname, char *valuename, char *str)\r
+{\r
+       return MsRegWriteStrEx(root, keyname, valuename, str, false);\r
+}\r
+bool MsRegWriteStrEx(UINT root, char *keyname, char *valuename, char *str, bool force32bit)\r
+{\r
+       return MsRegWriteStrEx2(root, keyname, valuename, str, force32bit, false);\r
+}\r
+bool MsRegWriteStrEx2(UINT root, char *keyname, char *valuename, char *str, bool force32bit, bool force64bit)\r
+{\r
+       // 引数チェック\r
+       if (keyname == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return MsRegWriteValueEx2(root, keyname, valuename, REG_SZ, str, StrSize(str), force32bit, force64bit);\r
+}\r
+bool MsRegWriteStrW(UINT root, char *keyname, char *valuename, wchar_t *str)\r
+{\r
+       return MsRegWriteStrExW(root, keyname, valuename, str, false);\r
+}\r
+bool MsRegWriteStrExW(UINT root, char *keyname, char *valuename, wchar_t *str, bool force32bit)\r
+{\r
+       return MsRegWriteStrEx2W(root, keyname, valuename, str, force32bit, false);\r
+}\r
+bool MsRegWriteStrEx2W(UINT root, char *keyname, char *valuename, wchar_t *str, bool force32bit, bool force64bit)\r
+{\r
+       // 引数チェック\r
+       if (keyname == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return MsRegWriteValueEx2W(root, keyname, valuename, REG_SZ, str, UniStrSize(str), force32bit, force64bit);\r
+}\r
+\r
+// 値を設定する\r
+bool MsRegWriteValue(UINT root, char *keyname, char *valuename, UINT type, void *data, UINT size)\r
+{\r
+       return MsRegWriteValueEx(root, keyname, valuename, type, data, size, false);\r
+}\r
+bool MsRegWriteValueEx(UINT root, char *keyname, char *valuename, UINT type, void *data, UINT size, bool force32bit)\r
+{\r
+       return MsRegWriteValueEx2(root, keyname, valuename, type, data, size, force32bit, false);\r
+}\r
+bool MsRegWriteValueEx2(UINT root, char *keyname, char *valuename, UINT type, void *data, UINT size, bool force32bit, bool force64bit)\r
+{\r
+       HKEY h;\r
+       // 引数チェック\r
+       if (keyname == NULL || (size != 0 && data == NULL))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // キーを作成する\r
+       MsRegNewKeyEx2(root, keyname, force32bit, force64bit);\r
+\r
+       // キーを開く\r
+       if (RegOpenKeyEx(MsGetRootKeyFromInt(root), keyname, 0, KEY_ALL_ACCESS | MsRegAccessMaskFor64BitEx(force32bit, force64bit), &h) != ERROR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 値を書き込む\r
+       if (RegSetValueEx(h, valuename, 0, type, data, size) != ERROR_SUCCESS)\r
+       {\r
+               RegCloseKey(h);\r
+               return false;\r
+       }\r
+\r
+       // キーを閉じる\r
+       RegCloseKey(h);\r
+\r
+       return true;\r
+}\r
+bool MsRegWriteValueW(UINT root, char *keyname, char *valuename, UINT type, void *data, UINT size)\r
+{\r
+       return MsRegWriteValueExW(root, keyname, valuename, type, data, size, false);\r
+}\r
+bool MsRegWriteValueExW(UINT root, char *keyname, char *valuename, UINT type, void *data, UINT size, bool force32bit)\r
+{\r
+       return MsRegWriteValueEx2W(root, keyname, valuename, type, data, size, force32bit, false);\r
+}\r
+bool MsRegWriteValueEx2W(UINT root, char *keyname, char *valuename, UINT type, void *data, UINT size, bool force32bit, bool force64bit)\r
+{\r
+       HKEY h;\r
+       wchar_t valuename_w[MAX_SIZE];\r
+       // 引数チェック\r
+       if (keyname == NULL || (size != 0 && data == NULL))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               UINT size_a;\r
+               void *data_a;\r
+               bool ret;\r
+\r
+               if (type == REG_SZ || type == REG_MULTI_SZ || type == REG_EXPAND_SZ)\r
+               {\r
+                       data_a = CopyUniToStr(data);\r
+                       size_a = StrSize(data_a);\r
+               }\r
+               else\r
+               {\r
+                       data_a = Clone(data, size);\r
+                       size_a = size;\r
+               }\r
+\r
+               ret = MsRegWriteValueEx2(root, keyname, valuename, type, data_a, size_a, force32bit, force64bit);\r
+\r
+               Free(data_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       StrToUni(valuename_w, sizeof(valuename_w), valuename);\r
+\r
+       // キーを作成する\r
+       MsRegNewKeyEx2(root, keyname, force32bit, force64bit);\r
+\r
+       // キーを開く\r
+       if (RegOpenKeyEx(MsGetRootKeyFromInt(root), keyname, 0, KEY_ALL_ACCESS | MsRegAccessMaskFor64BitEx(force32bit, force64bit), &h) != ERROR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 値を書き込む\r
+       if (RegSetValueExW(h, valuename_w, 0, type, data, size) != ERROR_SUCCESS)\r
+       {\r
+               RegCloseKey(h);\r
+               return false;\r
+       }\r
+\r
+       // キーを閉じる\r
+       RegCloseKey(h);\r
+\r
+       return true;\r
+}\r
+\r
+// バイナリデータを取得する\r
+BUF *MsRegReadBin(UINT root, char *keyname, char *valuename)\r
+{\r
+       return MsRegReadBinEx(root, keyname, valuename, false);\r
+}\r
+BUF *MsRegReadBinEx(UINT root, char *keyname, char *valuename, bool force32bit)\r
+{\r
+       return MsRegReadBinEx2(root, keyname, valuename, force32bit, false);\r
+}\r
+BUF *MsRegReadBinEx2(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit)\r
+{\r
+       char *ret;\r
+       UINT type, size;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (keyname == NULL || valuename == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // 値を読み込む\r
+       if (MsRegReadValueEx2(root, keyname, valuename, &ret, &type, &size, force32bit, force64bit) == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       b = NewBuf();\r
+\r
+       WriteBuf(b, ret, size);\r
+       SeekBuf(b, 0, 0);\r
+\r
+       Free(ret);\r
+\r
+       return b;\r
+}\r
+\r
+// 整数値を取得する\r
+UINT MsRegReadInt(UINT root, char *keyname, char *valuename)\r
+{\r
+       return MsRegReadIntEx(root, keyname, valuename, false);\r
+}\r
+UINT MsRegReadIntEx(UINT root, char *keyname, char *valuename, bool force32bit)\r
+{\r
+       return MsRegReadIntEx2(root, keyname, valuename, force32bit, false);\r
+}\r
+UINT MsRegReadIntEx2(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit)\r
+{\r
+       char *ret;\r
+       UINT type, size;\r
+       UINT value;\r
+       // 引数チェック\r
+       if (keyname == NULL || valuename == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // 値を読み込む\r
+       if (MsRegReadValueEx2(root, keyname, valuename, &ret, &type, &size, force32bit, force64bit) == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // 種類をチェックする\r
+       if (type != REG_DWORD_LITTLE_ENDIAN && type != REG_DWORD_BIG_ENDIAN)\r
+       {\r
+               // DWORD 以外である\r
+               Free(ret);\r
+               return 0;\r
+       }\r
+\r
+       // サイズをチェックする\r
+       if (size != sizeof(UINT))\r
+       {\r
+               Free(ret);\r
+               return 0;\r
+       }\r
+\r
+       Copy(&value, ret, sizeof(UINT));\r
+\r
+       Free(ret);\r
+\r
+       // エンディアン変換\r
+       if (IsLittleEndian())\r
+       {\r
+#ifdef REG_DWORD_BIG_ENDIAN\r
+               if (type == REG_DWORD_BIG_ENDIAN)\r
+               {\r
+                       value = Swap32(value);\r
+               }\r
+#endif // REG_DWORD_BIG_ENDIAN\r
+       }\r
+       else\r
+       {\r
+#ifdef REG_DWORD_LITTLE_ENDIAN_FLAG\r
+               if (type == REG_DWORD_LITTLE_ENDIAN_FLAG)\r
+               {\r
+                       value = Swap32(value);\r
+               }\r
+#endif // REG_DWORD_LITTLE_ENDIAN_FLAG\r
+       }\r
+\r
+       return value;\r
+}\r
+\r
+// 文字列リストを取得する\r
+LIST *MsRegReadStrList(UINT root, char *keyname, char *valuename)\r
+{\r
+       return MsRegReadStrListEx(root, keyname, valuename, false);\r
+}\r
+LIST *MsRegReadStrListEx(UINT root, char *keyname, char *valuename, bool force32bit)\r
+{\r
+       return MsRegReadStrListEx2(root, keyname, valuename, force32bit, false);\r
+}\r
+LIST *MsRegReadStrListEx2(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit)\r
+{\r
+       LIST *o;\r
+       char *ret;\r
+       UINT type, size;\r
+       // 引数チェック\r
+       if (keyname == NULL || valuename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 値を読み込む\r
+       if (MsRegReadValueEx2(root, keyname, valuename, &ret, &type, &size, force32bit, force64bit) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 種類をチェックする\r
+       if (type != REG_MULTI_SZ)\r
+       {\r
+               // 文字列リスト以外である\r
+               Free(ret);\r
+               return NULL;\r
+       }\r
+\r
+       if (size < 2)\r
+       {\r
+               // サイズ不正\r
+               Free(ret);\r
+               return NULL;\r
+       }\r
+\r
+       if (ret[size - 1] != 0)\r
+       {\r
+               // データ不正\r
+               Free(ret);\r
+               return NULL;\r
+       }\r
+\r
+       // リスト作成\r
+       o = StrToStrList(ret, size);\r
+\r
+       Free(ret);\r
+\r
+       return o;\r
+}\r
+\r
+// 文字列を取得する\r
+char *MsRegReadStr(UINT root, char *keyname, char *valuename)\r
+{\r
+       return MsRegReadStrEx(root, keyname, valuename, false);\r
+}\r
+char *MsRegReadStrEx(UINT root, char *keyname, char *valuename, bool force32bit)\r
+{\r
+       return MsRegReadStrEx2(root, keyname, valuename, force32bit, false);\r
+}\r
+char *MsRegReadStrEx2(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit)\r
+{\r
+       char *ret;\r
+       UINT type, size;\r
+       // 引数チェック\r
+       if (keyname == NULL || valuename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 値を読み込む\r
+       if (MsRegReadValueEx2(root, keyname, valuename, &ret, &type, &size, force32bit, force64bit) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 種類をチェックする\r
+       if (type != REG_SZ && type != REG_EXPAND_SZ && type != REG_MULTI_SZ)\r
+       {\r
+               // 文字列以外である\r
+               Free(ret);\r
+\r
+               if (type == REG_MULTI_SZ)\r
+               {\r
+                       // 文字列リストである\r
+                       LIST *o = MsRegReadStrList(root, keyname, valuename);\r
+                       if (o != NULL)\r
+                       {\r
+                               if (LIST_NUM(o) >= 1)\r
+                               {\r
+                                       ret = CopyStr(LIST_DATA(o, 0));\r
+                                       FreeStrList(o);\r
+                                       return ret;\r
+                               }\r
+                       }\r
+               }\r
+               return NULL;\r
+       }\r
+\r
+       if (size == 0)\r
+       {\r
+               // サイズ不正\r
+               Free(ret);\r
+\r
+               return CopyStr("");\r
+       }\r
+\r
+       if (ret[size - 1] != 0)\r
+       {\r
+               // データ不正\r
+               Free(ret);\r
+               return NULL;\r
+       }\r
+\r
+       return ret;\r
+}\r
+wchar_t *MsRegReadStrW(UINT root, char *keyname, char *valuename)\r
+{\r
+       return MsRegReadStrExW(root, keyname, valuename, false);\r
+}\r
+wchar_t *MsRegReadStrExW(UINT root, char *keyname, char *valuename, bool force32bit)\r
+{\r
+       return MsRegReadStrEx2W(root, keyname, valuename, force32bit, false);\r
+}\r
+wchar_t *MsRegReadStrEx2W(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit)\r
+{\r
+       wchar_t *ret;\r
+       UINT type, size;\r
+       // 引数チェック\r
+       if (keyname == NULL || valuename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 値を読み込む\r
+       if (MsRegReadValueEx2W(root, keyname, valuename, &ret, &type, &size, force32bit, force64bit) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 種類をチェックする\r
+       if (type != REG_SZ && type != REG_EXPAND_SZ)\r
+       {\r
+               // 文字列以外である\r
+               Free(ret);\r
+\r
+               return NULL;\r
+       }\r
+\r
+       if (ret[size / sizeof(wchar_t) - 1] != 0)\r
+       {\r
+               // データ不正\r
+               Free(ret);\r
+               return NULL;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 値を読み込む\r
+bool MsRegReadValue(UINT root, char *keyname, char *valuename, void **data, UINT *type, UINT *size)\r
+{\r
+       return MsRegReadValueEx(root, keyname, valuename, data, type, size, false);\r
+}\r
+bool MsRegReadValueEx(UINT root, char *keyname, char *valuename, void **data, UINT *type, UINT *size, bool force32bit)\r
+{\r
+       return MsRegReadValueEx2(root, keyname, valuename, data, type, size, force32bit, false);\r
+}\r
+bool MsRegReadValueEx2(UINT root, char *keyname, char *valuename, void **data, UINT *type, UINT *size, bool force32bit, bool force64bit)\r
+{\r
+       HKEY h;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (keyname == NULL || data == NULL || type == NULL || size == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       *type = 0;\r
+       *size = 0;\r
+\r
+       // キーを開く\r
+       if (RegOpenKeyEx(MsGetRootKeyFromInt(root), keyname, 0, KEY_READ | MsRegAccessMaskFor64BitEx(force32bit, force64bit), &h) != ERROR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 値を開く\r
+       *data = ZeroMalloc(*size);\r
+       ret = RegQueryValueEx(h, valuename, 0, type, *data, size);\r
+\r
+       if (ret == ERROR_SUCCESS)\r
+       {\r
+               // 読み取り完了\r
+               RegCloseKey(h);\r
+               return true;\r
+       }\r
+\r
+       if (ret != ERROR_MORE_DATA)\r
+       {\r
+               // 変なエラーが発生した\r
+               Free(*data);\r
+               *data = NULL;\r
+               RegCloseKey(h);\r
+               return false;\r
+       }\r
+\r
+       // メモリを再確保してデータを取得\r
+       *data = ReAlloc(*data, *size);\r
+       ret = RegQueryValueEx(h, valuename, 0, type, *data, size);\r
+       if (ret != ERROR_SUCCESS)\r
+       {\r
+               // エラー発生\r
+               Free(*data);\r
+               *data = NULL;\r
+               RegCloseKey(h);\r
+       }\r
+\r
+       RegCloseKey(h);\r
+\r
+       return true;\r
+}\r
+bool MsRegReadValueW(UINT root, char *keyname, char *valuename, void **data, UINT *type, UINT *size)\r
+{\r
+       return MsRegReadValueExW(root, keyname, valuename, data, type, size, false);\r
+}\r
+bool MsRegReadValueExW(UINT root, char *keyname, char *valuename, void **data, UINT *type, UINT *size, bool force32bit)\r
+{\r
+       return MsRegReadValueEx2W(root, keyname, valuename, data, type, size, force32bit, false);\r
+}\r
+bool MsRegReadValueEx2W(UINT root, char *keyname, char *valuename, void **data, UINT *type, UINT *size, bool force32bit, bool force64bit)\r
+{\r
+       HKEY h;\r
+       UINT ret;\r
+       wchar_t valuename_w[MAX_SIZE];\r
+       // 引数チェック\r
+       if (keyname == NULL || data == NULL || type == NULL || size == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       *type = 0;\r
+       *size = 0;\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               bool ret;\r
+               void *data_a = NULL;\r
+               UINT type_a = 0, size_a = 0;\r
+\r
+               ret = MsRegReadValueEx2(root, keyname, valuename, &data_a, &type_a, &size_a, force32bit, force64bit);\r
+\r
+               if (ret != false)\r
+               {\r
+                       if (type_a == REG_SZ || type_a == REG_MULTI_SZ || type_a == REG_EXPAND_SZ)\r
+                       {\r
+                               *data = CopyStrToUni(data_a);\r
+                               Free(data_a);\r
+\r
+                               size_a = UniStrSize(*data);\r
+                       }\r
+                       else\r
+                       {\r
+                               *data = data_a;\r
+                       }\r
+\r
+                       *type = type_a;\r
+                       *size = size_a;\r
+               }\r
+\r
+               return ret;\r
+       }\r
+\r
+       StrToUni(valuename_w, sizeof(valuename_w), valuename);\r
+\r
+       // キーを開く\r
+       if (RegOpenKeyEx(MsGetRootKeyFromInt(root), keyname, 0, KEY_READ | MsRegAccessMaskFor64BitEx(force32bit, force64bit), &h) != ERROR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 値を開く\r
+       *data = ZeroMalloc(*size);\r
+       ret = RegQueryValueExW(h, valuename_w, 0, type, *data, size);\r
+\r
+       if (ret == ERROR_SUCCESS)\r
+       {\r
+               // 読み取り完了\r
+               RegCloseKey(h);\r
+               return true;\r
+       }\r
+\r
+       if (ret != ERROR_MORE_DATA)\r
+       {\r
+               // 変なエラーが発生した\r
+               Free(*data);\r
+               *data = NULL;\r
+               RegCloseKey(h);\r
+               return false;\r
+       }\r
+\r
+       // メモリを再確保してデータを取得\r
+       *data = ReAlloc(*data, *size);\r
+       ret = RegQueryValueExW(h, valuename_w, 0, type, *data, size);\r
+       if (ret != ERROR_SUCCESS)\r
+       {\r
+               // エラー発生\r
+               Free(*data);\r
+               *data = NULL;\r
+               RegCloseKey(h);\r
+       }\r
+\r
+       RegCloseKey(h);\r
+\r
+       return true;\r
+}\r
+\r
+// 値の種類とサイズを取得する\r
+bool MsRegGetValueTypeAndSize(UINT root, char *keyname, char *valuename, UINT *type, UINT *size)\r
+{\r
+       return MsRegGetValueTypeAndSizeEx(root, keyname, valuename, type, size, false);\r
+}\r
+bool MsRegGetValueTypeAndSizeEx(UINT root, char *keyname, char *valuename, UINT *type, UINT *size, bool force32bit)\r
+{\r
+       return MsRegGetValueTypeAndSizeEx2(root, keyname, valuename, type, size, force32bit, false);\r
+}\r
+bool MsRegGetValueTypeAndSizeEx2(UINT root, char *keyname, char *valuename, UINT *type, UINT *size, bool force32bit, bool force64bit)\r
+{\r
+       HKEY h;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (keyname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (type != NULL)\r
+       {\r
+               *type = 0;\r
+       }\r
+       if (size != NULL)\r
+       {\r
+               *size = 0;\r
+       }\r
+\r
+       // キーを開く\r
+       if (RegOpenKeyEx(MsGetRootKeyFromInt(root), keyname, 0, KEY_READ | MsRegAccessMaskFor64BitEx(force32bit, force64bit), &h) != ERROR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 値を開く\r
+       ret = RegQueryValueEx(h, valuename, 0, type, NULL, size);\r
+\r
+       if (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA)\r
+       {\r
+               RegCloseKey(h);\r
+               return true;\r
+       }\r
+\r
+       RegCloseKey(h);\r
+\r
+       return false;\r
+}\r
+bool MsRegGetValueTypeAndSizeW(UINT root, char *keyname, char *valuename, UINT *type, UINT *size)\r
+{\r
+       return MsRegGetValueTypeAndSizeExW(root, keyname, valuename, type, size, false);\r
+}\r
+bool MsRegGetValueTypeAndSizeExW(UINT root, char *keyname, char *valuename, UINT *type, UINT *size, bool force32bit)\r
+{\r
+       return MsRegGetValueTypeAndSizeEx2W(root, keyname, valuename, type, size, force32bit, false);\r
+}\r
+bool MsRegGetValueTypeAndSizeEx2W(UINT root, char *keyname, char *valuename, UINT *type, UINT *size, bool force32bit, bool force64bit)\r
+{\r
+       HKEY h;\r
+       UINT ret;\r
+       wchar_t valuename_w[MAX_SIZE];\r
+       // 引数チェック\r
+       if (keyname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (type != NULL)\r
+       {\r
+               *type = 0;\r
+       }\r
+       if (size != NULL)\r
+       {\r
+               *size = 0;\r
+       }\r
+       if (IsNt() == false)\r
+       {\r
+               UINT type_a = 0;\r
+               UINT size_a = 0;\r
+\r
+               bool ret = MsRegGetValueTypeAndSizeEx2(root, keyname, valuename, &type_a, &size_a, force32bit, force64bit);\r
+\r
+               if (type_a == REG_SZ || type_a == REG_MULTI_SZ || type_a == REG_EXPAND_SZ)\r
+               {\r
+                       size_a = size_a * sizeof(wchar_t);\r
+               }\r
+\r
+               if (type != NULL)\r
+               {\r
+                       *type = type_a;\r
+               }\r
+\r
+               if (size != NULL)\r
+               {\r
+                       *size = size_a;\r
+               }\r
+\r
+               return ret;\r
+       }\r
+\r
+       StrToUni(valuename_w, sizeof(valuename_w), valuename);\r
+\r
+       // キーを開く\r
+       if (RegOpenKeyEx(MsGetRootKeyFromInt(root), keyname, 0, KEY_READ | MsRegAccessMaskFor64BitEx(force32bit, force64bit), &h) != ERROR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 値を開く\r
+       ret = RegQueryValueExW(h, valuename_w, 0, type, NULL, size);\r
+\r
+       if (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA)\r
+       {\r
+               RegCloseKey(h);\r
+               return true;\r
+       }\r
+\r
+       RegCloseKey(h);\r
+\r
+       return false;\r
+}\r
+\r
+// 指定された値がレジストリに存在するかどうか確認する\r
+bool MsRegIsValue(UINT root, char *keyname, char *valuename)\r
+{\r
+       return MsRegIsValueEx(root, keyname, valuename, false);\r
+}\r
+bool MsRegIsValueEx(UINT root, char *keyname, char *valuename, bool force32bit)\r
+{\r
+       return MsRegIsValueEx2(root, keyname, valuename, force32bit, false);\r
+}\r
+bool MsRegIsValueEx2(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit)\r
+{\r
+       HKEY h;\r
+       UINT type, size;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (keyname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // キーを開く\r
+       if (RegOpenKeyEx(MsGetRootKeyFromInt(root), keyname, 0, KEY_READ | MsRegAccessMaskFor64BitEx(force32bit, force64bit), &h) != ERROR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 値を開く\r
+       size = 0;\r
+       ret = RegQueryValueEx(h, valuename, 0, &type, NULL, &size);\r
+\r
+       if (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA)\r
+       {\r
+               RegCloseKey(h);\r
+               return true;\r
+       }\r
+\r
+       RegCloseKey(h);\r
+\r
+       return false;\r
+}\r
+\r
+// レジストリにキーを作成する\r
+bool MsRegNewKey(UINT root, char *keyname)\r
+{\r
+       return MsRegNewKeyEx(root, keyname, false);\r
+}\r
+bool MsRegNewKeyEx(UINT root, char *keyname, bool force32bit)\r
+{\r
+       return MsRegNewKeyEx2(root, keyname, force32bit, false);\r
+}\r
+bool MsRegNewKeyEx2(UINT root, char *keyname, bool force32bit, bool force64bit)\r
+{\r
+       HKEY h;\r
+       // 引数チェック\r
+       if (keyname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // キーが存在するかどうか確認する\r
+       if (MsRegIsKeyEx2(root, keyname, force32bit, force64bit))\r
+       {\r
+               // すでに存在している\r
+               return true;\r
+       }\r
+\r
+       // キーを作成する\r
+       if (RegCreateKeyEx(MsGetRootKeyFromInt(root), keyname, 0, NULL, REG_OPTION_NON_VOLATILE,\r
+               KEY_ALL_ACCESS | MsRegAccessMaskFor64BitEx(force32bit, force64bit), NULL, &h, NULL) != ERROR_SUCCESS)\r
+       {\r
+               // 失敗\r
+               return false;\r
+       }\r
+\r
+       RegCloseKey(h);\r
+\r
+       return true;\r
+}\r
+\r
+// 指定されたキーがレジストリに存在するかどうか確認する\r
+bool MsRegIsKey(UINT root, char *name)\r
+{\r
+       return MsRegIsKeyEx(root, name, false);\r
+}\r
+bool MsRegIsKeyEx(UINT root, char *name, bool force32bit)\r
+{\r
+       return MsRegIsKeyEx2(root, name, force32bit, false);\r
+}\r
+bool MsRegIsKeyEx2(UINT root, char *name, bool force32bit, bool force64bit)\r
+{\r
+       HKEY h;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (RegOpenKeyEx(MsGetRootKeyFromInt(root), name, 0, KEY_READ | MsRegAccessMaskFor64BitEx(force32bit, force64bit), &h) != ERROR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       RegCloseKey(h);\r
+\r
+       return true;\r
+}\r
+\r
+// ルートキーハンドルの取得\r
+HKEY MsGetRootKeyFromInt(UINT root)\r
+{\r
+       switch (root)\r
+       {\r
+       case REG_CLASSES_ROOT:\r
+               return HKEY_CLASSES_ROOT;\r
+\r
+       case REG_LOCAL_MACHINE:\r
+               return HKEY_LOCAL_MACHINE;\r
+\r
+       case REG_CURRENT_USER:\r
+               return HKEY_CURRENT_USER;\r
+\r
+       case REG_USERS:\r
+               return HKEY_USERS;\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// コマンドライン文字列から実行ファイル名の部分をカットする (Unicode 版)\r
+wchar_t *MsCutExeNameFromUniCommandLine(wchar_t *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (str[0] != L'\"')\r
+       {\r
+               UINT i = UniSearchStrEx(str, L" ", 0, true);\r
+               if (i == INFINITE)\r
+               {\r
+                       return str + UniStrLen(str);\r
+               }\r
+               else\r
+               {\r
+                       return str + i + 1;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               str++;\r
+               while (true)\r
+               {\r
+                       if ((*str) == 0)\r
+                       {\r
+                               return str + UniStrLen(str);\r
+                       }\r
+                       if ((*str) == L'\"')\r
+                       {\r
+                               break;\r
+                       }\r
+                       str++;\r
+               }\r
+\r
+               while (true)\r
+               {\r
+                       if ((*str) == 0)\r
+                       {\r
+                               return str + UniStrLen(str);\r
+                       }\r
+                       if ((*str) == L' ')\r
+                       {\r
+                               return str + 1;\r
+                       }\r
+                       str++;\r
+               }\r
+       }\r
+}\r
+\r
+// コマンドライン文字列から実行ファイル名の部分をカットする\r
+char *MsCutExeNameFromCommandLine(char *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (str[0] != '\"')\r
+       {\r
+               UINT i = SearchStrEx(str, " ", 0, true);\r
+               if (i == INFINITE)\r
+               {\r
+                       return str + StrLen(str);\r
+               }\r
+               else\r
+               {\r
+                       return str + i + 1;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               str++;\r
+               while (true)\r
+               {\r
+                       if ((*str) == 0)\r
+                       {\r
+                               return str + StrLen(str);\r
+                       }\r
+                       if ((*str) == '\"')\r
+                       {\r
+                               break;\r
+                       }\r
+                       str++;\r
+               }\r
+\r
+               while (true)\r
+               {\r
+                       if ((*str) == 0)\r
+                       {\r
+                               return str + StrLen(str);\r
+                       }\r
+                       if ((*str) == ' ')\r
+                       {\r
+                               return str + 1;\r
+                       }\r
+                       str++;\r
+               }\r
+       }\r
+}\r
+\r
+// プロセスハンドルの取得\r
+void *MsGetCurrentProcess()\r
+{\r
+       return ms->hCurrentProcess;\r
+}\r
+\r
+// プロセス ID の取得\r
+UINT MsGetCurrentProcessId()\r
+{\r
+       return ms->CurrentProcessId;\r
+}\r
+\r
+// EXE ファイル名の取得\r
+char *MsGetExeFileName()\r
+{\r
+       return ms == NULL ? "Unknown" : ms->ExeFileName;\r
+}\r
+\r
+// EXE ファイルが置いてあるディレクトリ名の取得\r
+char *MsGetExeDirName()\r
+{\r
+       return ms->ExeFileDir;\r
+}\r
+wchar_t *MsGetExeDirNameW()\r
+{\r
+       return ms->ExeFileDirW;\r
+}\r
+\r
+// 特殊なディレクトリ名の取得\r
+char *MsGetSpecialDir(int id)\r
+{\r
+       LPITEMIDLIST t = NULL;\r
+       char tmp[MAX_PATH];\r
+\r
+       if (SHGetSpecialFolderLocation(NULL, id, &t) != S_OK)\r
+       {\r
+               return CopyStr(ms->ExeFileDir);\r
+       }\r
+\r
+       if (SHGetPathFromIDList(t, tmp) == false)\r
+       {\r
+               return CopyStr(ms->ExeFileDir);\r
+       }\r
+\r
+       Win32NukuEn(tmp, sizeof(tmp), tmp);\r
+\r
+       return CopyStr(tmp);\r
+}\r
+wchar_t *MsGetSpecialDirW(int id)\r
+{\r
+       LPITEMIDLIST t = NULL;\r
+       wchar_t tmp[MAX_PATH];\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char *tmp = MsGetSpecialDir(id);\r
+               wchar_t *ret = CopyStrToUni(tmp);\r
+\r
+               Free(tmp);\r
+\r
+               return ret;\r
+       }\r
+\r
+       if (SHGetSpecialFolderLocation(NULL, id, &t) != S_OK)\r
+       {\r
+               return UniCopyStr(ms->ExeFileDirW);\r
+       }\r
+\r
+       if (SHGetPathFromIDListW(t, tmp) == false)\r
+       {\r
+               return UniCopyStr(ms->ExeFileDirW);\r
+       }\r
+\r
+       Win32NukuEnW(tmp, sizeof(tmp), tmp);\r
+\r
+       return UniCopyStr(tmp);\r
+}\r
+\r
+// 特殊なディレクトリをすべて取得する\r
+void MsGetSpecialDirs()\r
+{\r
+       char tmp[MAX_PATH];\r
+\r
+       // System32\r
+       GetSystemDirectory(tmp, sizeof(tmp));\r
+       Win32NukuEn(tmp, sizeof(tmp), tmp);\r
+       ms->System32Dir = CopyStr(tmp);\r
+       ms->System32DirW = CopyStrToUni(tmp);\r
+\r
+       // Windows ディレクトリは System32 ディレクトリの 1 つ上にある\r
+       Win32GetDirFromPath(tmp, sizeof(tmp), tmp);\r
+       Win32NukuEn(tmp, sizeof(tmp), tmp);\r
+       ms->WindowsDir = CopyStr(tmp);\r
+       ms->WindowsDirW = CopyStrToUni(tmp);\r
+\r
+       // Windows ディレクトリの下の Temp ディレクトリ\r
+       Format(tmp, sizeof(tmp), "%s\\Temp", ms->WindowsDir);\r
+       ms->WinTempDir = CopyStr(tmp);\r
+       ms->WinTempDirW = CopyStrToUni(tmp);\r
+       MsUniMakeDirEx(ms->WinTempDirW);\r
+\r
+       // システムドライブ\r
+       tmp[2] = 0;\r
+       ms->WindowsDrive = CopyStr(tmp);\r
+       ms->WindowsDriveW = CopyStrToUni(tmp);\r
+\r
+       // Temp\r
+       GetTempPath(MAX_PATH, tmp);\r
+       Win32NukuEn(tmp, sizeof(tmp), tmp);\r
+       ms->TempDir = CopyStr(tmp);\r
+\r
+       // Temp (Unicode) の取得\r
+       if (IsNt())\r
+       {\r
+               wchar_t tmp_w[MAX_PATH];\r
+\r
+               GetTempPathW(MAX_PATH, tmp_w);\r
+               Win32NukuEnW(tmp_w, sizeof(tmp_w), tmp_w);\r
+\r
+               ms->TempDirW = CopyUniStr(tmp_w);\r
+       }\r
+       else\r
+       {\r
+               ms->TempDirW = CopyStrToUni(tmp);\r
+       }\r
+       MakeDirExW(ms->TempDirW);\r
+       MakeDirEx(ms->TempDir);\r
+\r
+       // Program Files\r
+       ms->ProgramFilesDir = MsGetSpecialDir(CSIDL_PROGRAM_FILES);\r
+       if (StrCmpi(ms->ProgramFilesDir, ms->ExeFileDir) == 0)\r
+       {\r
+               char tmp[MAX_PATH];\r
+               Format(tmp, sizeof(tmp), "%s\\Program Files", ms->WindowsDrive);\r
+\r
+               Free(ms->ProgramFilesDir);\r
+               ms->ProgramFilesDir = CopyStr(tmp);\r
+       }\r
+\r
+       ms->ProgramFilesDirW = MsGetSpecialDirW(CSIDL_PROGRAM_FILES);\r
+       if (UniStrCmpi(ms->ProgramFilesDirW, ms->ExeFileDirW) == 0)\r
+       {\r
+               wchar_t tmp[MAX_PATH];\r
+               UniFormat(tmp, sizeof(tmp), L"%s\\Program Files", ms->WindowsDriveW);\r
+\r
+               Free(ms->ProgramFilesDirW);\r
+               ms->ProgramFilesDirW = UniCopyStr(tmp);\r
+       }\r
+\r
+       if (MsIsNt())\r
+       {\r
+               // 共通のスタートメニュー\r
+               ms->CommonStartMenuDir = MsGetSpecialDir(CSIDL_COMMON_STARTMENU);\r
+               ms->CommonStartMenuDirW = MsGetSpecialDirW(CSIDL_COMMON_STARTMENU);\r
+\r
+               // 共通のプログラム\r
+               ms->CommonProgramsDir = MsGetSpecialDir(CSIDL_COMMON_PROGRAMS);\r
+               ms->CommonProgramsDirW = MsGetSpecialDirW(CSIDL_COMMON_PROGRAMS);\r
+\r
+               // 共通のスタートアップ\r
+               ms->CommonStartupDir = MsGetSpecialDir(CSIDL_COMMON_STARTUP);\r
+               ms->CommonStartupDirW = MsGetSpecialDirW(CSIDL_COMMON_STARTUP);\r
+\r
+               // 共通のアプリケーションデータ\r
+               ms->CommonAppDataDir = MsGetSpecialDir(CSIDL_COMMON_APPDATA);\r
+               ms->CommonAppDataDirW = MsGetSpecialDirW(CSIDL_COMMON_APPDATA);\r
+\r
+               // 共通のデスクトップ\r
+               ms->CommonDesktopDir = MsGetSpecialDir(CSIDL_COMMON_DESKTOPDIRECTORY);\r
+               ms->CommonDesktopDirW = MsGetSpecialDirW(CSIDL_COMMON_DESKTOPDIRECTORY);\r
+\r
+               // Local Settings\r
+               ms->LocalAppDataDir = MsGetSpecialDir(CSIDL_LOCAL_APPDATA);\r
+               ms->LocalAppDataDirW = MsGetSpecialDirW(CSIDL_LOCAL_APPDATA);\r
+       }\r
+       else\r
+       {\r
+               // 個別のスタートメニュー\r
+               ms->PersonalStartMenuDir = MsGetSpecialDir(CSIDL_STARTMENU);\r
+               ms->CommonStartMenuDir = CopyStr(ms->PersonalStartMenuDir);\r
+               ms->PersonalStartMenuDirW = MsGetSpecialDirW(CSIDL_STARTMENU);\r
+               ms->CommonStartMenuDirW = CopyUniStr(ms->PersonalStartMenuDirW);\r
+\r
+               // 個別のプログラム\r
+               ms->PersonalProgramsDir = MsGetSpecialDir(CSIDL_PROGRAMS);\r
+               ms->CommonProgramsDir = CopyStr(ms->PersonalProgramsDir);\r
+               ms->PersonalProgramsDirW = MsGetSpecialDirW(CSIDL_PROGRAMS);\r
+               ms->CommonProgramsDirW = CopyUniStr(ms->PersonalProgramsDirW);\r
+\r
+               // 個別のスタートアップ\r
+               ms->PersonalStartupDir = MsGetSpecialDir(CSIDL_STARTUP);\r
+               ms->CommonStartupDir = CopyStr(ms->PersonalStartupDir);\r
+               ms->PersonalStartupDirW = MsGetSpecialDirW(CSIDL_STARTUP);\r
+               ms->CommonStartupDirW = CopyUniStr(ms->PersonalStartupDirW);\r
+\r
+               // 個別のアプリケーションデータ\r
+               ms->PersonalAppDataDir = MsGetSpecialDir(CSIDL_APPDATA);\r
+               ms->CommonAppDataDir = CopyStr(ms->PersonalAppDataDir);\r
+               ms->PersonalAppDataDirW = MsGetSpecialDirW(CSIDL_APPDATA);\r
+               ms->CommonAppDataDirW = CopyUniStr(ms->PersonalAppDataDirW);\r
+\r
+               // 個別のデスクトップ\r
+               ms->PersonalDesktopDir = MsGetSpecialDir(CSIDL_DESKTOP);\r
+               ms->CommonDesktopDir = CopyStr(ms->PersonalDesktopDir);\r
+               ms->PersonalDesktopDirW = MsGetSpecialDirW(CSIDL_DESKTOP);\r
+               ms->CommonDesktopDirW = CopyUniStr(ms->PersonalDesktopDirW);\r
+\r
+               // Local Settings\r
+               ms->LocalAppDataDir = CopyStr(ms->PersonalAppDataDir);\r
+               ms->LocalAppDataDirW = CopyUniStr(ms->PersonalAppDataDirW);\r
+       }\r
+}\r
+\r
+// 現在のユーザーが Administrators かどうかチェックする\r
+bool MsCheckIsAdmin()\r
+{\r
+       UCHAR test_bit[32];\r
+       UCHAR tmp[32];\r
+       char *name = "Vpn_Check_Admin_Key";\r
+       DWORD type;\r
+       DWORD size;\r
+       Rand(test_bit, sizeof(test_bit));\r
+\r
+       if (RegSetValueEx(HKEY_LOCAL_MACHINE, name, 0, REG_BINARY, test_bit, sizeof(test_bit)) != ERROR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       size = sizeof(tmp);\r
+       if (RegQueryValueEx(HKEY_LOCAL_MACHINE, name, 0, &type, tmp, &size) != ERROR_SUCCESS)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       RegDeleteValue(HKEY_LOCAL_MACHINE, name);\r
+\r
+       if (Cmp(test_bit, tmp, 32) != 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ライブラリの初期化\r
+void MsInit()\r
+{\r
+       char *str_ansi;\r
+       wchar_t *str_unicode;\r
+       OSVERSIONINFO os;\r
+       char tmp[MAX_SIZE];\r
+       UINT size;\r
+       if (ms != NULL)\r
+       {\r
+               // すでに初期化されている\r
+               return;\r
+       }\r
+\r
+       ms = ZeroMalloc(sizeof(MS));\r
+\r
+       // インスタンスハンドルの取得\r
+       ms->hInst = GetModuleHandleA(NULL);\r
+\r
+       // KERNEL32.DLL の取得\r
+       ms->hKernel32 = LoadLibrary("kernel32.dll");\r
+\r
+       // OS からコマンドライン文字列を取得する\r
+       str_ansi = CopyStr(GetCommandLineA());\r
+       Trim(str_ansi);\r
+       str_unicode = UniCopyStr(GetCommandLineW());\r
+       UniTrim(str_unicode);\r
+\r
+       SetCommandLineStr(MsCutExeNameFromCommandLine(str_ansi));\r
+       SetCommandLineUniStr(MsCutExeNameFromUniCommandLine(str_unicode));\r
+\r
+       Free(str_unicode);\r
+       Free(str_ansi);\r
+\r
+       // OS のバージョンを取得する\r
+       Zero(&os, sizeof(os));\r
+       os.dwOSVersionInfoSize = sizeof(os);\r
+       GetVersionEx(&os);\r
+\r
+       if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)\r
+       {\r
+               // NT 系\r
+               ms->IsNt = true;\r
+\r
+               ms->nt = MsLoadNtApiFunctions();\r
+\r
+               if (ms->nt == NULL)\r
+               {\r
+                       ms->IsNt = false;\r
+                       ms->IsAdmin = true;\r
+               }\r
+               else\r
+               {\r
+                       // Administrators 判定\r
+                       ms->IsAdmin = MsCheckIsAdmin();\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // 9x 系: 常に Administrators を偽装\r
+               ms->IsAdmin = true;\r
+       }\r
+\r
+       // 現在のプロセスに関する情報を取得する\r
+       ms->hCurrentProcess = GetCurrentProcess();\r
+       ms->CurrentProcessId = GetCurrentProcessId();\r
+\r
+       // EXE ファイル名を取得\r
+       GetModuleFileName(NULL, tmp, sizeof(tmp));\r
+       ms->ExeFileName = CopyStr(tmp);\r
+       Win32GetDirFromPath(tmp, sizeof(tmp), tmp);\r
+       ms->ExeFileDir = CopyStr(tmp);\r
+\r
+       // EXE ファイル名 (Unicode) を取得\r
+       if (IsNt())\r
+       {\r
+               wchar_t tmp_w[MAX_PATH];\r
+\r
+               GetModuleFileNameW(NULL, tmp_w, sizeof(tmp_w));\r
+               ms->ExeFileNameW = CopyUniStr(tmp_w);\r
+\r
+               Win32GetDirFromPathW(tmp_w, sizeof(tmp_w), tmp_w);\r
+               ms->ExeFileDirW = CopyUniStr(tmp_w);\r
+       }\r
+       else\r
+       {\r
+               ms->ExeFileNameW = CopyStrToUni(ms->ExeFileName);\r
+               ms->ExeFileDirW = CopyStrToUni(ms->ExeFileDir);\r
+       }\r
+\r
+       // 特殊なディレクトリを取得\r
+       MsGetSpecialDirs();\r
+\r
+       // 一時ディレクトリの初期化\r
+       MsInitTempDir();\r
+\r
+       // ユーザー名の取得\r
+       size = sizeof(tmp);\r
+       GetUserName(tmp, &size);\r
+       ms->UserName = CopyStr(tmp);\r
+\r
+       // ユーザー名の取得 (Unicode)\r
+       if (IsNt())\r
+       {\r
+               wchar_t tmp_w[MAX_PATH];\r
+\r
+               size = sizeof(tmp_w);\r
+\r
+               GetUserNameW(tmp_w, &size);\r
+               ms->UserNameW = CopyUniStr(tmp_w);\r
+       }\r
+       else\r
+       {\r
+               ms->UserNameW = CopyStrToUni(ms->UserName);\r
+       }\r
+\r
+       // フルユーザー名の取得\r
+       if (ms->nt != NULL && ms->nt->GetUserNameExA != NULL)\r
+       {\r
+               wchar_t tmp_w[MAX_PATH];\r
+\r
+               size = sizeof(tmp);\r
+               if (ms->nt->GetUserNameExA(NameSamCompatible, tmp, &size))\r
+               {\r
+                       ms->UserNameEx = CopyStr(tmp);\r
+               }\r
+\r
+               size = sizeof(tmp_w);\r
+               if (ms->nt->GetUserNameExW(NameSamCompatible, tmp_w, &size))\r
+               {\r
+                       ms->UserNameExW = CopyUniStr(tmp_w);\r
+               }\r
+       }\r
+\r
+       if (ms->UserNameEx == NULL)\r
+       {\r
+               ms->UserNameEx = CopyStr(ms->UserName);\r
+       }\r
+       if (ms->UserNameExW == NULL)\r
+       {\r
+               ms->UserNameExW = CopyUniStr(ms->UserNameW);\r
+       }\r
+\r
+       ms_critical_section = ZeroMalloc(sizeof(CRITICAL_SECTION));\r
+       InitializeCriticalSection(ms_critical_section);\r
+\r
+       // アダプタリストの初期化\r
+       MsInitAdapterListModule();\r
+\r
+       // minidump ベースファイル名の初期化\r
+       if (true)\r
+       {\r
+               wchar_t tmp[MAX_PATH];\r
+               if (MsIsAdmin())\r
+               {\r
+                       CombinePathW(tmp, sizeof(tmp), ms->ExeFileDirW, L"vpn_debug\\dump");\r
+               }\r
+               else\r
+               {\r
+                       CombinePathW(tmp, sizeof(tmp), ms->TempDirW, L"vpn_debug\\dump");\r
+               }\r
+               ms->MinidumpBaseFileNameW = CopyUniStr(tmp);\r
+       }\r
+\r
+       MsSetEnableMinidump(true);\r
+\r
+       if (MsIsNt())\r
+       {\r
+               if (ms->nt->MiniDumpWriteDump != NULL)\r
+               {\r
+                       SetUnhandledExceptionFilter(MsExceptionHandler);\r
+               }\r
+       }\r
+}\r
+\r
+// minidump を作成するかどうか選択する\r
+void MsSetEnableMinidump(bool enabled)\r
+{\r
+       ms->MiniDumpEnabled = enabled;\r
+}\r
+\r
+// minidump を出力する\r
+void MsWriteMinidump(wchar_t *filename, void *ex)\r
+{\r
+       wchar_t tmp[MAX_PATH];\r
+       wchar_t dir[MAX_PATH];\r
+       HANDLE h;\r
+       MINIDUMP_EXCEPTION_INFORMATION info;\r
+       struct _EXCEPTION_POINTERS *exp = (struct _EXCEPTION_POINTERS *)ex;\r
+\r
+       if (filename != NULL)\r
+       {\r
+               UniStrCpy(tmp, sizeof(tmp), filename);\r
+       }\r
+       else\r
+       {\r
+               SYSTEMTIME tm;\r
+\r
+               Zero(&tm, sizeof(tm));\r
+               GetLocalTime(&tm);\r
+\r
+               UniFormat(tmp, sizeof(tmp), L"%s_%04u%02u%02u_%02u%02u%02u.dmp",\r
+                       ms->MinidumpBaseFileNameW,\r
+                       tm.wYear, tm.wMonth, tm.wDay, tm.wHour, tm.wMinute, tm.wSecond);\r
+       }\r
+\r
+       GetDirNameFromFilePathW(dir, sizeof(dir), tmp);\r
+\r
+       CreateDirectoryW(dir, NULL);\r
+\r
+       Zero(&info, sizeof(info));\r
+\r
+       if (exp != NULL)\r
+       {\r
+               info.ThreadId = GetCurrentThreadId();\r
+               info.ExceptionPointers = exp;\r
+               info.ClientPointers = true;\r
+       }\r
+\r
+       h = CreateFileW(tmp, GENERIC_READ | GENERIC_WRITE,\r
+               FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,\r
+               NULL);\r
+       if (h != INVALID_HANDLE_VALUE)\r
+       {\r
+               ms->nt->MiniDumpWriteDump(ms->hCurrentProcess, ms->CurrentProcessId,\r
+                       h,\r
+                       MiniDumpNormal | MiniDumpWithFullMemory | MiniDumpWithDataSegs |\r
+                       MiniDumpWithHandleData\r
+                       ,\r
+                       info.ThreadId == 0 ? NULL : &info, NULL, NULL);\r
+\r
+               FlushFileBuffers(h);\r
+               CloseHandle(h);\r
+       }\r
+}\r
+\r
+// 例外ハンドラ\r
+LONG CALLBACK MsExceptionHandler(struct _EXCEPTION_POINTERS *ExceptionInfo)\r
+{\r
+       if (ms->MiniDumpEnabled)\r
+       {\r
+               MsWriteMinidump(NULL, ExceptionInfo);\r
+       }\r
+\r
+       return EXCEPTION_CONTINUE_SEARCH;\r
+}\r
+\r
+// ライブラリの解放\r
+void MsFree()\r
+{\r
+       if (ms == NULL)\r
+       {\r
+               // 初期化されていない\r
+               return;\r
+       }\r
+\r
+       // アダプタリストの解放\r
+       MsFreeAdapterListModule();\r
+\r
+       // 一時ディレクトリの解放\r
+       MsFreeTempDir();\r
+\r
+       if (ms->IsNt)\r
+       {\r
+               // NT 系 API の解放\r
+               MsFreeNtApiFunctions(ms->nt);\r
+       }\r
+\r
+       // メモリ解放\r
+       // ANSI\r
+       Free(ms->WindowsDir);\r
+       Free(ms->System32Dir);\r
+       Free(ms->TempDir);\r
+       Free(ms->WinTempDir);\r
+       Free(ms->WindowsDrive);\r
+       Free(ms->ProgramFilesDir);\r
+       Free(ms->CommonStartMenuDir);\r
+       Free(ms->CommonProgramsDir);\r
+       Free(ms->CommonStartupDir);\r
+       Free(ms->CommonAppDataDir);\r
+       Free(ms->CommonDesktopDir);\r
+       Free(ms->PersonalStartMenuDir);\r
+       Free(ms->PersonalProgramsDir);\r
+       Free(ms->PersonalStartupDir);\r
+       Free(ms->PersonalAppDataDir);\r
+       Free(ms->PersonalDesktopDir);\r
+       Free(ms->MyDocumentsDir);\r
+       Free(ms->ExeFileDir);\r
+       Free(ms->ExeFileName);\r
+       Free(ms->UserName);\r
+       Free(ms->UserNameEx);\r
+       Free(ms->LocalAppDataDir);\r
+       // Unicode\r
+       Free(ms->WindowsDirW);\r
+       Free(ms->System32DirW);\r
+       Free(ms->TempDirW);\r
+       Free(ms->WinTempDirW);\r
+       Free(ms->WindowsDriveW);\r
+       Free(ms->ProgramFilesDirW);\r
+       Free(ms->CommonStartMenuDirW);\r
+       Free(ms->CommonProgramsDirW);\r
+       Free(ms->CommonStartupDirW);\r
+       Free(ms->CommonAppDataDirW);\r
+       Free(ms->CommonDesktopDirW);\r
+       Free(ms->PersonalStartMenuDirW);\r
+       Free(ms->PersonalProgramsDirW);\r
+       Free(ms->PersonalStartupDirW);\r
+       Free(ms->PersonalAppDataDirW);\r
+       Free(ms->PersonalDesktopDirW);\r
+       Free(ms->MyDocumentsDirW);\r
+       Free(ms->ExeFileDirW);\r
+       Free(ms->ExeFileNameW);\r
+       Free(ms->UserNameW);\r
+       Free(ms->UserNameExW);\r
+       Free(ms->LocalAppDataDirW);\r
+       Free(ms->MinidumpBaseFileNameW);\r
+       Free(ms);\r
+       ms = NULL;\r
+\r
+       Free(ms_critical_section);\r
+       ms_critical_section = NULL;\r
+}\r
+\r
+// ディレクトリ取得関係\r
+char *MsGetCommonAppDataDir()\r
+{\r
+       return ms->CommonAppDataDir;\r
+}\r
+char *MsGetLocalAppDataDir()\r
+{\r
+       return ms->LocalAppDataDir;\r
+}\r
+char *MsGetWindowsDir()\r
+{\r
+       return ms->WindowsDir;\r
+}\r
+wchar_t *MsGetWindowsDirW()\r
+{\r
+       return ms->WindowsDirW;\r
+}\r
+char *MsGetSystem32Dir()\r
+{\r
+       return ms->System32Dir;\r
+}\r
+char *MsGetTempDir()\r
+{\r
+       return ms->TempDir;\r
+}\r
+char *MsGetWindowsDrive()\r
+{\r
+       return ms->WindowsDrive;\r
+}\r
+char *MsGetProgramFilesDir()\r
+{\r
+       return ms->ProgramFilesDir;\r
+}\r
+char *MsGetCommonStartMenuDir()\r
+{\r
+       return ms->CommonStartMenuDir;\r
+}\r
+char *MsGetCommonProgramsDir()\r
+{\r
+       return ms->CommonProgramsDir;\r
+}\r
+char *MsGetCommonStartupDir()\r
+{\r
+       return ms->CommonStartupDir;\r
+}\r
+char *MsGetCommonDesktopDir()\r
+{\r
+       return ms->CommonDesktopDir;\r
+}\r
+char *MsGetPersonalStartMenuDir()\r
+{\r
+       if (ms->PersonalStartMenuDir == NULL)\r
+       {\r
+               ms->PersonalStartMenuDir = MsGetSpecialDir(CSIDL_STARTMENU);\r
+       }\r
+       return ms->PersonalStartMenuDir;\r
+}\r
+char *MsGetPersonalProgramsDir()\r
+{\r
+       if (ms->PersonalProgramsDir == NULL)\r
+       {\r
+               ms->PersonalProgramsDir = MsGetSpecialDir(CSIDL_PROGRAMS);\r
+       }\r
+       return ms->PersonalProgramsDir;\r
+}\r
+char *MsGetPersonalStartupDir()\r
+{\r
+       if (ms->PersonalStartupDir == NULL)\r
+       {\r
+               ms->PersonalStartupDir = MsGetSpecialDir(CSIDL_STARTUP);\r
+       }\r
+       return ms->PersonalStartupDir;\r
+}\r
+char *MsGetPersonalAppDataDir()\r
+{\r
+       if (ms->PersonalAppDataDir == NULL)\r
+       {\r
+               ms->PersonalAppDataDir = MsGetSpecialDir(CSIDL_APPDATA);\r
+       }\r
+       return ms->PersonalAppDataDir;\r
+}\r
+char *MsGetPersonalDesktopDir()\r
+{\r
+       if (ms->PersonalDesktopDir == NULL)\r
+       {\r
+               ms->PersonalDesktopDir = MsGetSpecialDir(CSIDL_DESKTOP);\r
+       }\r
+       return ms->PersonalDesktopDir;\r
+}\r
+char *MsGetMyDocumentsDir()\r
+{\r
+       if (ms->MyDocumentsDir == NULL)\r
+       {\r
+               ms->MyDocumentsDir = MsGetSpecialDir(CSIDL_PERSONAL);\r
+       }\r
+       return ms->MyDocumentsDir;\r
+}\r
+char *MsGetMyTempDir()\r
+{\r
+       return ms->MyTempDir;\r
+}\r
+char *MsGetUserName()\r
+{\r
+       return ms->UserName;\r
+}\r
+char *MsGetUserNameEx()\r
+{\r
+       return ms->UserNameEx;\r
+}\r
+char *MsGetWinTempDir()\r
+{\r
+       return ms->WinTempDir;\r
+}\r
+\r
+wchar_t *MsGetExeFileNameW()\r
+{\r
+       return ms == NULL ? L"Unknown" : ms->ExeFileNameW;\r
+}\r
+wchar_t *MsGetExeFileDirW()\r
+{\r
+       return ms->ExeFileDirW;\r
+}\r
+wchar_t *MsGetWindowDirW()\r
+{\r
+       return ms->WindowsDirW;\r
+}\r
+wchar_t *MsGetSystem32DirW()\r
+{\r
+       return ms->System32DirW;\r
+}\r
+wchar_t *MsGetTempDirW()\r
+{\r
+       return ms->TempDirW;\r
+}\r
+wchar_t *MsGetWindowsDriveW()\r
+{\r
+       return ms->WindowsDriveW;\r
+}\r
+wchar_t *MsGetProgramFilesDirW()\r
+{\r
+       return ms->ProgramFilesDirW;\r
+}\r
+wchar_t *MsGetCommonStartMenuDirW()\r
+{\r
+       return ms->CommonStartMenuDirW;\r
+}\r
+wchar_t *MsGetCommonProgramsDirW()\r
+{\r
+       return ms->CommonProgramsDirW;\r
+}\r
+wchar_t *MsGetCommonStartupDirW()\r
+{\r
+       return ms->CommonStartupDirW;\r
+}\r
+wchar_t *MsGetCommonAppDataDirW()\r
+{\r
+       return ms->CommonAppDataDirW;\r
+}\r
+wchar_t *MsGetCommonDesktopDirW()\r
+{\r
+       return ms->CommonDesktopDirW;\r
+}\r
+wchar_t *MsGetPersonalStartMenuDirW()\r
+{\r
+       if (ms->PersonalStartMenuDirW == NULL)\r
+       {\r
+               ms->PersonalStartMenuDirW = MsGetSpecialDirW(CSIDL_STARTMENU);\r
+       }\r
+\r
+       return ms->PersonalStartMenuDirW;\r
+}\r
+wchar_t *MsGetPersonalProgramsDirW()\r
+{\r
+       if (ms->PersonalProgramsDirW == NULL)\r
+       {\r
+               ms->PersonalProgramsDirW = MsGetSpecialDirW(CSIDL_PROGRAMS);\r
+       }\r
+\r
+       return ms->PersonalProgramsDirW;\r
+}\r
+wchar_t *MsGetPersonalStartupDirW()\r
+{\r
+       if (ms->PersonalStartupDirW == NULL)\r
+       {\r
+               ms->PersonalStartupDirW = MsGetSpecialDirW(CSIDL_STARTUP);\r
+       }\r
+\r
+       return ms->PersonalStartupDirW;\r
+}\r
+wchar_t *MsGetPersonalAppDataDirW()\r
+{\r
+       if (ms->PersonalAppDataDirW == NULL)\r
+       {\r
+               ms->PersonalAppDataDirW = MsGetSpecialDirW(CSIDL_APPDATA);\r
+       }\r
+\r
+       return ms->PersonalAppDataDirW;\r
+}\r
+wchar_t *MsGetPersonalDesktopDirW()\r
+{\r
+       if (ms->PersonalDesktopDirW == NULL)\r
+       {\r
+               ms->PersonalDesktopDirW = MsGetSpecialDirW(CSIDL_DESKTOP);\r
+       }\r
+\r
+       return ms->PersonalDesktopDirW;\r
+}\r
+wchar_t *MsGetMyDocumentsDirW()\r
+{\r
+       if (ms->MyDocumentsDirW == NULL)\r
+       {\r
+               ms->MyDocumentsDirW = MsGetSpecialDirW(CSIDL_PERSONAL);\r
+       }\r
+\r
+       return ms->MyDocumentsDirW;\r
+}\r
+wchar_t *MsGetLocalAppDataDirW()\r
+{\r
+       return ms->LocalAppDataDirW;\r
+}\r
+wchar_t *MsGetMyTempDirW()\r
+{\r
+       return ms->MyTempDirW;\r
+}\r
+wchar_t *MsGetUserNameW()\r
+{\r
+       return ms->UserNameW;\r
+}\r
+wchar_t *MsGetUserNameExW()\r
+{\r
+       return ms->UserNameExW;\r
+}\r
+wchar_t *MsGetWinTempDirW()\r
+{\r
+       return ms->WinTempDirW;\r
+}\r
+\r
+\r
+#endif // WIN32\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Microsoft.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Microsoft.h
new file mode 100644 (file)
index 0000000..1a2b64b
--- /dev/null
@@ -0,0 +1,952 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Microsoft.h\r
+// Microsoft.c のヘッダ\r
+\r
+#ifdef OS_WIN32\r
+\r
+// Windows 用の型が windows.h をインクルードしていなくても使えるようにする\r
+#ifndef        _WINDEF_\r
+\r
+typedef void *HWND;\r
+\r
+#endif // _WINDEF_\r
+\r
+#ifndef        MICROSOFT_H\r
+#define        MICROSOFT_H\r
+\r
+\r
+// イベントログ定数\r
+#define        MS_EVENTLOG_TYPE_INFORMATION            0\r
+#define        MS_EVENTLOG_TYPE_WARNING                        1\r
+#define        MS_EVENTLOG_TYPE_ERROR                          2\r
+\r
+#define        MS_RC_EVENTLOG_TYPE_INFORMATION         0x40000001L\r
+#define        MS_RC_EVENTLOG_TYPE_WARNING                     0x80000002L\r
+#define        MS_RC_EVENTLOG_TYPE_ERROR                       0xC0000003L\r
+\r
+\r
+// TCP/IP レジストリ値\r
+#define        TCP_MAX_NUM_CONNECTIONS                         16777214\r
+\r
+#define        DEFAULT_TCP_MAX_WINDOW_SIZE_RECV        5955584\r
+#define        DEFAULT_TCP_MAX_WINDOW_SIZE_SEND        131072\r
+#define        DEFAULT_TCP_MAX_NUM_CONNECTIONS         16777214\r
+\r
+// 定数\r
+#define        SVC_ARG_INSTALL                         "/install"\r
+#define        SVC_ARG_UNINSTALL                       "/uninstall"\r
+#define        SVC_ARG_START                           "/start"\r
+#define        SVC_ARG_STOP                            "/stop"\r
+#define        SVC_ARG_TEST                            "/test"\r
+#define        SVC_ARG_USERMODE                        "/usermode"\r
+#define        SVC_ARG_USERMODE_SHOWTRAY       "/usermode_showtray"\r
+#define        SVC_ARG_USERMODE_HIDETRAY       "/usermode_hidetray"\r
+#define        SVC_ARG_SERVICE                         "/service"\r
+#define        SVC_ARG_SETUP_INSTALL           "/setup_install"\r
+#define        SVC_ARG_SETUP_UNINSTALL         "/setup_uninstall"\r
+#define        SVC_ARG_WIN9X_SERVICE           "/win9x_service"\r
+#define        SVC_ARG_WIN9X_INSTALL           "/win9x_install"\r
+#define        SVC_ARG_WIN9X_UNINSTALL         "/win9x_uninstall"\r
+#define        SVC_ARG_TCP                                     "/tcp"\r
+#define        SVC_ARG_TCP_SETUP                       "/tcpsetup"\r
+#define        SVC_ARG_TRAFFIC                         "/traffic"\r
+#define        SVC_ARG_UIHELP                          "/uihelp"\r
+#define        SVC_ARG_UIHELP_W                        L"/uihelp"\r
+#define SVC_ARG_SILENT                         "/silent"\r
+\r
+// サービスがフリーズした場合の自殺までの時間\r
+#define        SVC_SELFKILL_TIMEOUT            (5 * 60 * 1000)\r
+\r
+// Win32 版仮想 LAN カードのデバイスドライバの名称 (先頭部分)\r
+#define        VLAN_ADAPTER_NAME                       "UT-VPN Client Adapter"\r
+\r
+// Win32 版仮想 LAN カードのデバイスドライバの名称 (フルネーム)\r
+#define        VLAN_ADAPTER_NAME_TAG           "UT-VPN Client Adapter - %s"\r
+\r
+// Win32 版仮想 LAN カードの [ネットワーク接続] における表示名 (フルネーム)\r
+#define        VLAN_CONNECTION_NAME            "%s - UT-VPN Client"\r
+\r
+\r
+// サービス時のコマンドライン書式\r
+#define        SVC_RUN_COMMANDLINE                     L"\"%s\" /service"\r
+\r
+// モード値\r
+#define        SVC_MODE_NONE                           0\r
+#define        SVC_MODE_INSTALL                        1\r
+#define        SVC_MODE_UNINSTALL                      2\r
+#define        SVC_MODE_START                          3\r
+#define        SVC_MODE_STOP                           4\r
+#define        SVC_MODE_TEST                           5\r
+#define        SVC_MODE_USERMODE                       6\r
+#define        SVC_MODE_SERVICE                        7\r
+#define        SVC_MODE_SETUP_INSTALL          8\r
+#define        SVC_MODE_SETUP_UNINSTALL        9\r
+#define        SVC_MODE_WIN9X_SERVICE          10\r
+#define        SVC_MODE_WIN9X_INSTALL          11\r
+#define        SVC_MODE_WIN9X_UNINSTALL        12\r
+#define        SVC_MODE_TCP                            13\r
+#define        SVC_MODE_TCPSETUP                       14\r
+#define        SVC_MODE_TRAFFIC                        15\r
+#define        SVC_MODE_UIHELP                         16\r
+\r
+\r
+#define        WIN9X_SVC_REGKEY_1                      "Software\\Microsoft\\Windows\\CurrentVersion\\RunServices"\r
+#define        WIN9X_SVC_REGKEY_2                      "Software\\Microsoft\\Windows\\CurrentVersion\\Run"\r
+\r
+#define        VISTA_MMCSS_KEYNAME                     "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Multimedia\\SystemProfile\\Tasks"\r
+#define        VISTA_MMCSS_FILENAME            "mmcss_backup.dat"\r
+\r
+#define        SVC_NAME                                        "SVC_%s_NAME"\r
+#define        SVC_TITLE                                       "SVC_%s_TITLE"\r
+#define        SVC_DESCRIPT                            "SVC_%s_DESCRIPT"\r
+\r
+#define        SVC_USERMODE_SETTING_KEY        "Software\\SoftEther Corporation\\UT-VPN\\UserMode Settings"\r
+#define        SVC_HIDETRAY_REG_VALUE          "HideTray_%S"\r
+\r
+#define        SVC_CALLING_SM_PROCESS_ID_KEY   "Software\\SoftEther Corporation\\UT-VPN\\Service Control\\%s"\r
+#define SVC_CALLING_SM_PROCESS_ID_VALUE        "ProcessId"\r
+\r
+#define        MMCSS_PROFILE_KEYNAME           "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Multimedia\\SystemProfile"\r
+\r
+// その他の定数\r
+#define        MS_REG_TCP_SETTING_KEY          "Software\\SoftEther Corporation\\Network Settings"\r
+\r
+\r
+\r
+// ドライバ関係の定数\r
+#define        DRIVER_INF_FILE_NAME            L"|vpn_driver.inf"\r
+#define        DRIVER_INF_FILE_NAME_X64        L"|vpn_driver_x64.inf"\r
+#define        DRIVER_INF_FILE_NAME_IA64       L"|vpn_driver_ia64.inf"\r
+#define        DRIVER_INF_FILE_NAME_9X         L"|vpn_driver_9x.inf"\r
+#define        DRIVER_SYS_FILE_NAME            L"|vpn_driver.sys"\r
+#define        DRIVER_SYS_FILE_NAME_X64        L"|vpn_driver_x64.sys"\r
+#define        DRIVER_SYS_FILE_NAME_IA64       L"|vpn_driver_ia64.sys"\r
+#define        DRIVER_SYS_FILE_NAME_9X         L"|vpn_driver_9x.sys"\r
+#define        DRIVER_INSTALL_INF_NAME_TAG     "Sen_%s.inf"\r
+#define        DRIVER_INSTALL_SYS_NAME_TAG     "Sen_%s.sys"\r
+#define        DRIVER_INSTALL_SYS_NAME_TAG_NEW "Sen_%04u.sys"\r
+#define        DRIVER_INSTALL_SYS_NAME_TAG_MAXID       128\r
+\r
+// Vista 用ドライバインストーラ関係\r
+#define        VISTA_DRIVER_INSTALLER_SRC      L"|driver_installer.exe"\r
+#define        VISTA_DRIVER_INSTALLER_SRC_X64  L"|driver_installer_x64.exe"\r
+#define        VISTA_DRIVER_INSTALLER_SRC_IA64 L"|driver_installer_ia64.exe"\r
+#define        VISTA_DRIVER_INSTALLER_DST      L"%s\\driver_installer.exe"\r
+\r
+#define        DRIVER_DEVICE_ID_TAG            "SenAdapter_%s"\r
+\r
+\r
+#if            (defined(MICROSOFT_C) || defined(NETWORK_C)) && (defined(OS_WIN32))\r
+\r
+typedef enum __TCP_TABLE_CLASS {\r
+       _TCP_TABLE_BASIC_LISTENER,\r
+       _TCP_TABLE_BASIC_CONNECTIONS,\r
+       _TCP_TABLE_BASIC_ALL,\r
+       _TCP_TABLE_OWNER_PID_LISTENER,\r
+       _TCP_TABLE_OWNER_PID_CONNECTIONS,\r
+       _TCP_TABLE_OWNER_PID_ALL,\r
+       _TCP_TABLE_OWNER_MODULE_LISTENER,\r
+       _TCP_TABLE_OWNER_MODULE_CONNECTIONS,\r
+       _TCP_TABLE_OWNER_MODULE_ALL\r
+} _TCP_TABLE_CLASS, *_PTCP_TABLE_CLASS;\r
+\r
+// Win32 ネットワーク関係の API 関数へのポインタ\r
+typedef struct NETWORK_WIN32_FUNCTIONS\r
+{\r
+       HINSTANCE hIpHlpApi32;\r
+       DWORD (WINAPI *DeleteIpForwardEntry)(PMIB_IPFORWARDROW);\r
+       DWORD (WINAPI *CreateIpForwardEntry)(PMIB_IPFORWARDROW);\r
+       DWORD (WINAPI *GetIpForwardTable)(PMIB_IPFORWARDTABLE, PULONG, BOOL);\r
+       DWORD (WINAPI *GetNetworkParams)(PFIXED_INFO, PULONG);\r
+       DWORD (WINAPI *GetIfTable)(PMIB_IFTABLE, PULONG, BOOL);\r
+       DWORD (WINAPI *IpRenewAddress)(PIP_ADAPTER_INDEX_MAP);\r
+       DWORD (WINAPI *IpReleaseAddress)(PIP_ADAPTER_INDEX_MAP);\r
+       DWORD (WINAPI *GetInterfaceInfo)(PIP_INTERFACE_INFO, PULONG);\r
+       DWORD (WINAPI *GetAdaptersInfo)(PIP_ADAPTER_INFO, PULONG);\r
+       DWORD (WINAPI *GetExtendedTcpTable)(PVOID, PDWORD, BOOL, ULONG, _TCP_TABLE_CLASS, ULONG);\r
+       DWORD (WINAPI *AllocateAndGetTcpExTableFromStack)(PVOID *, BOOL, HANDLE, DWORD, DWORD);\r
+       DWORD (WINAPI *GetTcpTable)(PMIB_TCPTABLE, PDWORD, BOOL);\r
+       DWORD (WINAPI *NotifyRouteChange)(PHANDLE, LPOVERLAPPED);\r
+       BOOL (WINAPI *CancelIPChangeNotify)(LPOVERLAPPED);\r
+       DWORD (WINAPI *NhpAllocateAndGetInterfaceInfoFromStack)(IP_INTERFACE_NAME_INFO **,\r
+               PDWORD, BOOL, HANDLE, DWORD);\r
+} NETWORK_WIN32_FUNCTIONS;\r
+#endif\r
+\r
+\r
+#ifdef MICROSOFT_C\r
+// 内部用構造体\r
+typedef struct MS\r
+{\r
+       HINSTANCE hInst;\r
+       HINSTANCE hKernel32;\r
+       bool IsNt;\r
+       bool IsAdmin;\r
+       struct NT_API *nt;\r
+       HANDLE hCurrentProcess;\r
+       UINT CurrentProcessId;\r
+       bool MiniDumpEnabled;\r
+       char *ExeFileName;\r
+       char *ExeFileDir;\r
+       char *WindowsDir;\r
+       char *System32Dir;\r
+       char *TempDir;\r
+       char *WinTempDir;\r
+       char *WindowsDrive;\r
+       char *ProgramFilesDir;\r
+       char *CommonStartMenuDir;\r
+       char *CommonProgramsDir;\r
+       char *CommonStartupDir;\r
+       char *CommonAppDataDir;\r
+       char *CommonDesktopDir;\r
+       char *PersonalStartMenuDir;\r
+       char *PersonalProgramsDir;\r
+       char *PersonalStartupDir;\r
+       char *PersonalAppDataDir;\r
+       char *PersonalDesktopDir;\r
+       char *MyDocumentsDir;\r
+       char *LocalAppDataDir;\r
+       char *MyTempDir;\r
+       char *UserName;\r
+       char *UserNameEx;\r
+       wchar_t *ExeFileNameW;\r
+       wchar_t *ExeFileDirW;\r
+       wchar_t *WindowsDirW;\r
+       wchar_t *System32DirW;\r
+       wchar_t *TempDirW;\r
+       wchar_t *WinTempDirW;\r
+       wchar_t *WindowsDriveW;\r
+       wchar_t *ProgramFilesDirW;\r
+       wchar_t *CommonStartMenuDirW;\r
+       wchar_t *CommonProgramsDirW;\r
+       wchar_t *CommonStartupDirW;\r
+       wchar_t *CommonAppDataDirW;\r
+       wchar_t *CommonDesktopDirW;\r
+       wchar_t *PersonalStartMenuDirW;\r
+       wchar_t *PersonalProgramsDirW;\r
+       wchar_t *PersonalStartupDirW;\r
+       wchar_t *PersonalAppDataDirW;\r
+       wchar_t *PersonalDesktopDirW;\r
+       wchar_t *MyDocumentsDirW;\r
+       wchar_t *LocalAppDataDirW;\r
+       wchar_t *MyTempDirW;\r
+       wchar_t *UserNameW;\r
+       wchar_t *UserNameExW;\r
+       wchar_t *MinidumpBaseFileNameW;\r
+       IO *LockFile;\r
+} MS;\r
+\r
+// Windows NT 用 API\r
+typedef struct NT_API\r
+{\r
+       HINSTANCE hAdvapi32;\r
+       HINSTANCE hShell32;\r
+       HINSTANCE hNewDev;\r
+       HINSTANCE hSetupApi;\r
+       HINSTANCE hWtsApi32;\r
+       HINSTANCE hPsApi;\r
+       HINSTANCE hKernel32;\r
+       HINSTANCE hSecur32;\r
+       HINSTANCE hUser32;\r
+       HINSTANCE hDbgHelp;\r
+       BOOL (WINAPI *OpenProcessToken)(HANDLE, DWORD, PHANDLE);\r
+       BOOL (WINAPI *LookupPrivilegeValue)(char *, char *, PLUID);\r
+       BOOL (WINAPI *AdjustTokenPrivileges)(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);\r
+       BOOL (WINAPI *InitiateSystemShutdown)(LPTSTR, LPTSTR, DWORD, BOOL, BOOL);\r
+       BOOL (WINAPI *LogonUserW)(wchar_t *, wchar_t *, wchar_t *, DWORD, DWORD, HANDLE *);\r
+       BOOL (WINAPI *LogonUserA)(char *, char *, char *, DWORD, DWORD, HANDLE *);\r
+       BOOL (WINAPI *UpdateDriverForPlugAndPlayDevicesW)(HWND hWnd, wchar_t *hardware_id, wchar_t *inf_path, UINT flag, BOOL *need_reboot);\r
+       UINT (WINAPI *CM_Get_DevNode_Status_Ex)(UINT *, UINT *, DWORD, UINT, HANDLE);\r
+       UINT (WINAPI *CM_Get_Device_ID_ExA)(DWORD, char *, UINT, UINT, HANDLE);\r
+       UINT (WINAPI *WTSQuerySessionInformation)(HANDLE, DWORD, WTS_INFO_CLASS, wchar_t *, DWORD *);\r
+       void (WINAPI *WTSFreeMemory)(void *);\r
+       BOOL (WINAPI *WTSDisconnectSession)(HANDLE, DWORD, BOOL);\r
+       BOOL (WINAPI *WTSEnumerateSessions)(HANDLE, DWORD, DWORD, PWTS_SESSION_INFO *, DWORD *);\r
+       SC_HANDLE (WINAPI *OpenSCManager)(LPCTSTR, LPCTSTR, DWORD);\r
+       SC_HANDLE (WINAPI *CreateServiceA)(SC_HANDLE, LPCTSTR, LPCTSTR, DWORD, DWORD, DWORD, DWORD, LPCTSTR, LPCTSTR, LPDWORD, LPCTSTR, LPCTSTR, LPCTSTR);\r
+       SC_HANDLE (WINAPI *CreateServiceW)(SC_HANDLE, LPCWSTR, LPCWSTR, DWORD, DWORD, DWORD, DWORD, LPCWSTR, LPCWSTR, LPDWORD, LPCWSTR, LPCWSTR, LPCWSTR);\r
+       BOOL (WINAPI *ChangeServiceConfig2)(SC_HANDLE, DWORD, LPVOID);\r
+       BOOL (WINAPI *CloseServiceHandle)(SC_HANDLE);\r
+       SC_HANDLE (WINAPI *OpenService)(SC_HANDLE, LPCTSTR, DWORD);\r
+       BOOL (WINAPI *QueryServiceStatus)(SC_HANDLE, LPSERVICE_STATUS);\r
+       BOOL (WINAPI *StartService)(SC_HANDLE, DWORD, LPCTSTR);\r
+       BOOL (WINAPI *ControlService)(SC_HANDLE, DWORD, LPSERVICE_STATUS);\r
+       BOOL (WINAPI *SetServiceStatus)(SERVICE_STATUS_HANDLE, LPSERVICE_STATUS);\r
+       SERVICE_STATUS_HANDLE (WINAPI *RegisterServiceCtrlHandler)(LPCTSTR, LPHANDLER_FUNCTION);\r
+       BOOL (WINAPI *StartServiceCtrlDispatcher)(CONST LPSERVICE_TABLE_ENTRY);\r
+       BOOL (WINAPI *DeleteService)(SC_HANDLE);\r
+       BOOL (WINAPI *EnumProcesses)(DWORD *, DWORD, DWORD *);\r
+       BOOL (WINAPI *EnumProcessModules)(HANDLE, HMODULE *, DWORD, DWORD *);\r
+       DWORD (WINAPI *GetModuleFileNameExA)(HANDLE, HMODULE, LPSTR, DWORD);\r
+       DWORD (WINAPI *GetModuleFileNameExW)(HANDLE, HMODULE, LPWSTR, DWORD);\r
+       LONG (WINAPI *RegDeleteKeyExA)(HKEY, LPCTSTR, REGSAM, DWORD);\r
+       BOOL (WINAPI *IsWow64Process)(HANDLE, BOOL *);\r
+       void (WINAPI *GetNativeSystemInfo)(SYSTEM_INFO *);\r
+       BOOL (WINAPI *DuplicateTokenEx)(HANDLE, DWORD, SECURITY_ATTRIBUTES *, SECURITY_IMPERSONATION_LEVEL, TOKEN_TYPE, HANDLE *);\r
+       BOOL (WINAPI *ConvertStringSidToSidA)(LPCSTR, PSID *);\r
+       BOOL (WINAPI *SetTokenInformation)(HANDLE, TOKEN_INFORMATION_CLASS, void *, DWORD);\r
+       BOOL (WINAPI *GetTokenInformation)(HANDLE, TOKEN_INFORMATION_CLASS, void *, DWORD, PDWORD);\r
+       BOOL (WINAPI *CreateProcessAsUserA)(HANDLE, LPCSTR, LPSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, void *, LPCSTR, LPSTARTUPINFOA, LPPROCESS_INFORMATION);\r
+       BOOL (WINAPI *CreateProcessAsUserW)(HANDLE, LPCWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, void *, LPCWSTR, LPSTARTUPINFOW, LPPROCESS_INFORMATION);\r
+       BOOL (WINAPI *LookupAccountSidA)(LPCSTR,PSID,LPSTR,LPDWORD,LPSTR,LPDWORD,PSID_NAME_USE);\r
+       BOOL (WINAPI *LookupAccountNameA)(LPCSTR,LPCSTR,PSID,LPDWORD,LPSTR,LPDWORD,PSID_NAME_USE);\r
+       BOOL (WINAPI *GetUserNameExA)(EXTENDED_NAME_FORMAT, LPSTR, PULONG);\r
+       BOOL (WINAPI *GetUserNameExW)(EXTENDED_NAME_FORMAT, LPWSTR, PULONG);\r
+       BOOL (WINAPI *SwitchDesktop)(HDESK);\r
+       HDESK (WINAPI *OpenDesktopA)(LPTSTR, DWORD, BOOL, ACCESS_MASK);\r
+       BOOL (WINAPI *CloseDesktop)(HDESK);\r
+       BOOL (WINAPI *SetProcessShutdownParameters)(DWORD, DWORD);\r
+       HANDLE (WINAPI *RegisterEventSourceW)(LPCWSTR, LPCWSTR);\r
+       BOOL (WINAPI *ReportEventW)(HANDLE, WORD, WORD, DWORD, PSID, WORD, DWORD, LPCWSTR *, LPVOID);\r
+       BOOL (WINAPI *DeregisterEventSource)(HANDLE);\r
+       BOOL (WINAPI *Wow64DisableWow64FsRedirection)(void **);\r
+       BOOLEAN (WINAPI *Wow64EnableWow64FsRedirection)(BOOLEAN);\r
+       BOOL (WINAPI *Wow64RevertWow64FsRedirection)(void *);\r
+       BOOL (WINAPI *GetFileInformationByHandle)(HANDLE, LPBY_HANDLE_FILE_INFORMATION);\r
+       HANDLE (WINAPI *GetProcessHeap)();\r
+       BOOL (WINAPI *MiniDumpWriteDump)(HANDLE, DWORD, HANDLE, MINIDUMP_TYPE,\r
+               PMINIDUMP_EXCEPTION_INFORMATION, PMINIDUMP_USER_STREAM_INFORMATION,\r
+               PMINIDUMP_CALLBACK_INFORMATION);\r
+} NT_API;\r
+\r
+typedef struct MS_EVENTLOG\r
+{\r
+       HANDLE hEventLog;\r
+} MS_EVENTLOG;\r
+\r
+extern NETWORK_WIN32_FUNCTIONS *w32net;\r
+\r
+#endif // MICROSOFT_C\r
+\r
+// 警告を出さないようにするための構造体\r
+typedef struct NO_WARNING\r
+{\r
+       DWORD ThreadId;\r
+       THREAD *NoWarningThread;\r
+       EVENT *HaltEvent;\r
+       volatile bool Halt;\r
+       wchar_t *SoundFileName;\r
+} NO_WARNING;\r
+\r
+// ルートキーの ID\r
+#define        REG_CLASSES_ROOT                0       // HKEY_CLASSES_ROOT\r
+#define        REG_LOCAL_MACHINE               1       // HKEY_LOCAL_MACHINE\r
+#define        REG_CURRENT_USER                2       // HKEY_CURRENT_USER\r
+#define        REG_USERS                               3       // HKEY_USERS\r
+\r
+// サービス関数\r
+typedef void (SERVICE_FUNCTION)();\r
+\r
+// プロセスリスト項目\r
+typedef struct MS_PROCESS\r
+{\r
+       char ExeFilename[MAX_PATH];             // EXE ファイル名\r
+       wchar_t ExeFilenameW[MAX_PATH]; // EXE ファイル名 (Unicode)\r
+       UINT ProcessId;                                 // プロセス ID\r
+} MS_PROCESS;\r
+\r
+#define        MAX_MS_ADAPTER_IP_ADDRESS       64\r
+\r
+// ネットワークアダプタ\r
+typedef struct MS_ADAPTER\r
+{\r
+       char Title[MAX_PATH];                   // 表示名\r
+       UINT Index;                                             // インデックス\r
+       UINT Type;                                              // 種類\r
+       UINT Status;                                    // ステータス\r
+       UINT Mtu;                                               // MTU\r
+       UINT Speed;                                             // 速度\r
+       UINT AddressSize;                               // アドレスサイズ\r
+       UCHAR Address[8];                               // アドレス\r
+       UINT64 RecvBytes;                               // 受信バイト数\r
+       UINT64 RecvPacketsBroadcast;    // 受信ブロードキャストパケット数\r
+       UINT64 RecvPacketsUnicast;              // 受信ユニキャストパケット数\r
+       UINT64 SendBytes;                               // 送信バイト数\r
+       UINT64 SendPacketsBroadcast;    // 送信ブロードキャストパケット数\r
+       UINT64 SendPacketsUnicast;              // 送信ユニキャストパケット数\r
+       bool Info;                                              // 詳しい情報があるかどうか\r
+       char Guid[MAX_SIZE];                    // GUID\r
+       UINT NumIpAddress;                              // IP アドレス個数\r
+       IP IpAddresses[MAX_MS_ADAPTER_IP_ADDRESS];      // IP アドレス\r
+       IP SubnetMasks[MAX_MS_ADAPTER_IP_ADDRESS];      // サブネット マスク\r
+       UINT NumGateway;                                // ゲートウェイ個数\r
+       IP Gateways[MAX_MS_ADAPTER_IP_ADDRESS]; // ゲートウェイ\r
+       bool UseDhcp;                                   // DHCP 使用フラグ\r
+       IP DhcpServer;                                  // DHCP サーバー\r
+       UINT64 DhcpLeaseStart;                  // DHCP リース開始日時\r
+       UINT64 DhcpLeaseExpires;                // DHCP リース期限日時\r
+       bool UseWins;                                   // WINS 使用フラグ\r
+       IP PrimaryWinsServer;                   // プライマリ WINS サーバー\r
+       IP SecondaryWinsServer;                 // セカンダリ WINS サーバー\r
+} MS_ADAPTER;\r
+\r
+// ネットワークアダプタリスト\r
+typedef struct MS_ADAPTER_LIST\r
+{\r
+       UINT Num;                                               // 個数\r
+       MS_ADAPTER **Adapters;                  // 内容\r
+} MS_ADAPTER_LIST;\r
+\r
+// TCP 設定\r
+typedef struct MS_TCP\r
+{\r
+       UINT RecvWindowSize;                    // 受信ウインドウサイズ\r
+       UINT SendWindowSize;                    // 送信ウインドウサイズ\r
+} MS_TCP;\r
+\r
+// スリープ防止\r
+typedef struct MS_NOSLEEP\r
+{\r
+       THREAD *Thread;                                 // スレッド\r
+       EVENT *HaltEvent;                               // 停止イベント\r
+       volatile bool Halt;                             // 停止フラグ\r
+       bool NoScreenSaver;                             // スクリーンセーバーも防止\r
+\r
+       // 以下 Windows Vista 用\r
+       wchar_t ScreenSaveActive[MAX_PATH];\r
+       wchar_t SCRNSAVE_EXE[MAX_PATH];\r
+} MS_NOSLEEP;\r
+\r
+// 子ウインドウ列挙\r
+typedef struct ENUM_CHILD_WINDOW_PARAM\r
+{\r
+       LIST *o;\r
+       bool no_recursion;\r
+       bool include_ipcontrol;\r
+} ENUM_CHILD_WINDOW_PARAM;\r
+\r
+// 関数プロトタイプ\r
+void MsInit();\r
+void MsFree();\r
+char *MsCutExeNameFromCommandLine(char *str);\r
+wchar_t *MsCutExeNameFromUniCommandLine(wchar_t *str);\r
+\r
+DWORD MsRegAccessMaskFor64Bit(bool force32bit);\r
+DWORD MsRegAccessMaskFor64BitEx(bool force32bit, bool force64bit);\r
+\r
+bool MsRegIsKey(UINT root, char *name);\r
+bool MsRegIsKeyEx(UINT root, char *name, bool force32bit);\r
+bool MsRegIsKeyEx2(UINT root, char *name, bool force32bit, bool force64bit);\r
+\r
+bool MsRegIsValue(UINT root, char *keyname, char *valuename);\r
+bool MsRegIsValueEx(UINT root, char *keyname, char *valuename, bool force32bit);\r
+bool MsRegIsValueEx2(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit);\r
+\r
+bool MsRegGetValueTypeAndSize(UINT root, char *keyname, char *valuename, UINT *type, UINT *size);\r
+bool MsRegGetValueTypeAndSizeEx(UINT root, char *keyname, char *valuename, UINT *type, UINT *size, bool force32bit);\r
+bool MsRegGetValueTypeAndSizeEx2(UINT root, char *keyname, char *valuename, UINT *type, UINT *size, bool force32bit, bool force64bit);\r
+bool MsRegGetValueTypeAndSizeW(UINT root, char *keyname, char *valuename, UINT *type, UINT *size);\r
+bool MsRegGetValueTypeAndSizeExW(UINT root, char *keyname, char *valuename, UINT *type, UINT *size, bool force32bit);\r
+bool MsRegGetValueTypeAndSizeEx2W(UINT root, char *keyname, char *valuename, UINT *type, UINT *size, bool force32bit, bool force64bit);\r
+\r
+bool MsRegReadValue(UINT root, char *keyname, char *valuename, void **data, UINT *type, UINT *size);\r
+bool MsRegReadValueEx(UINT root, char *keyname, char *valuename, void **data, UINT *type, UINT *size, bool force32bit);\r
+bool MsRegReadValueEx2(UINT root, char *keyname, char *valuename, void **data, UINT *type, UINT *size, bool force32bit, bool force64bit);\r
+bool MsRegReadValueW(UINT root, char *keyname, char *valuename, void **data, UINT *type, UINT *size);\r
+bool MsRegReadValueExW(UINT root, char *keyname, char *valuename, void **data, UINT *type, UINT *size, bool force32bit);\r
+bool MsRegReadValueEx2W(UINT root, char *keyname, char *valuename, void **data, UINT *type, UINT *size, bool force32bit, bool force64bit);\r
+\r
+char *MsRegReadStr(UINT root, char *keyname, char *valuename);\r
+char *MsRegReadStrEx(UINT root, char *keyname, char *valuename, bool force32bit);\r
+char *MsRegReadStrEx2(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit);\r
+wchar_t *MsRegReadStrW(UINT root, char *keyname, char *valuename);\r
+wchar_t *MsRegReadStrExW(UINT root, char *keyname, char *valuename, bool force32bit);\r
+wchar_t *MsRegReadStrEx2W(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit);\r
+\r
+UINT MsRegReadInt(UINT root, char *keyname, char *valuename);\r
+UINT MsRegReadIntEx(UINT root, char *keyname, char *valuename, bool force32bit);\r
+UINT MsRegReadIntEx2(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit);\r
+LIST *MsRegReadStrList(UINT root, char *keyname, char *valuename);\r
+LIST *MsRegReadStrListEx(UINT root, char *keyname, char *valuename, bool force32bit);\r
+LIST *MsRegReadStrListEx2(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit);\r
+\r
+BUF *MsRegReadBin(UINT root, char *keyname, char *valuename);\r
+BUF *MsRegReadBinEx(UINT root, char *keyname, char *valuename, bool force32bit);\r
+BUF *MsRegReadBinEx2(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit);\r
+\r
+bool MsRegNewKey(UINT root, char *keyname);\r
+bool MsRegNewKeyEx(UINT root, char *keyname, bool force32bit);\r
+bool MsRegNewKeyEx2(UINT root, char *keyname, bool force32bit, bool force64bit);\r
+\r
+bool MsRegWriteValue(UINT root, char *keyname, char *valuename, UINT type, void *data, UINT size);\r
+bool MsRegWriteValueEx(UINT root, char *keyname, char *valuename, UINT type, void *data, UINT size, bool force32bit);\r
+bool MsRegWriteValueEx2(UINT root, char *keyname, char *valuename, UINT type, void *data, UINT size, bool force32bit, bool force64bit);\r
+bool MsRegWriteValueW(UINT root, char *keyname, char *valuename, UINT type, void *data, UINT size);\r
+bool MsRegWriteValueExW(UINT root, char *keyname, char *valuename, UINT type, void *data, UINT size, bool force32bit);\r
+bool MsRegWriteValueEx2W(UINT root, char *keyname, char *valuename, UINT type, void *data, UINT size, bool force32bit, bool force64bit);\r
+\r
+bool MsRegWriteStr(UINT root, char *keyname, char *valuename, char *str);\r
+bool MsRegWriteStrEx(UINT root, char *keyname, char *valuename, char *str, bool force32bit);\r
+bool MsRegWriteStrEx2(UINT root, char *keyname, char *valuename, char *str, bool force32bit, bool force64bit);\r
+bool MsRegWriteStrExpand(UINT root, char *keyname, char *valuename, char *str);\r
+bool MsRegWriteStrExpandEx(UINT root, char *keyname, char *valuename, char *str, bool force32bit);\r
+bool MsRegWriteStrExpandEx2(UINT root, char *keyname, char *valuename, char *str, bool force32bit, bool force64bit);\r
+bool MsRegWriteStrW(UINT root, char *keyname, char *valuename, wchar_t *str);\r
+bool MsRegWriteStrExW(UINT root, char *keyname, char *valuename, wchar_t *str, bool force32bit);\r
+bool MsRegWriteStrEx2W(UINT root, char *keyname, char *valuename, wchar_t *str, bool force32bit, bool force64bit);\r
+bool MsRegWriteStrExpandW(UINT root, char *keyname, char *valuename, wchar_t *str);\r
+bool MsRegWriteStrExpandExW(UINT root, char *keyname, char *valuename, wchar_t *str, bool force32bit);\r
+bool MsRegWriteStrExpandEx2W(UINT root, char *keyname, char *valuename, wchar_t *str, bool force32bit, bool force64bit);\r
+\r
+bool MsRegWriteInt(UINT root, char *keyname, char *valuename, UINT value);\r
+bool MsRegWriteIntEx(UINT root, char *keyname, char *valuename, UINT value, bool force32bit);\r
+bool MsRegWriteIntEx2(UINT root, char *keyname, char *valuename, UINT value, bool force32bit, bool force64bit);\r
+bool MsRegWriteBin(UINT root, char *keyname, char *valuename, void *data, UINT size);\r
+bool MsRegWriteBinEx(UINT root, char *keyname, char *valuename, void *data, UINT size, bool force32bit);\r
+bool MsRegWriteBinEx2(UINT root, char *keyname, char *valuename, void *data, UINT size, bool force32bit, bool force64bit);\r
+\r
+TOKEN_LIST *MsRegEnumKey(UINT root, char *keyname);\r
+TOKEN_LIST *MsRegEnumKeyEx(UINT root, char *keyname, bool force32bit);\r
+TOKEN_LIST *MsRegEnumKeyEx2(UINT root, char *keyname, bool force32bit, bool force64bit);\r
+TOKEN_LIST *MsRegEnumValue(UINT root, char *keyname);\r
+TOKEN_LIST *MsRegEnumValueEx(UINT root, char *keyname, bool force32bit);\r
+TOKEN_LIST *MsRegEnumValueEx2(UINT root, char *keyname, bool force32bit, bool force64bit);\r
+\r
+bool MsRegDeleteKey(UINT root, char *keyname);\r
+bool MsRegDeleteKeyEx(UINT root, char *keyname, bool force32bit);\r
+bool MsRegDeleteKeyEx2(UINT root, char *keyname, bool force32bit, bool force64bit);\r
+bool MsRegDeleteValue(UINT root, char *keyname, char *valuename);\r
+bool MsRegDeleteValueEx(UINT root, char *keyname, char *valuename, bool force32bit);\r
+bool MsRegDeleteValueEx2(UINT root, char *keyname, char *valuename, bool force32bit, bool force64bit);\r
+\r
+bool MsIsNt();\r
+bool MsIsAdmin();\r
+bool MsEnablePrivilege(char *name, bool enable);\r
+void *MsGetCurrentProcess();\r
+UINT MsGetCurrentProcessId();\r
+char *MsGetExeFileName();\r
+char *MsGetExeDirName();\r
+wchar_t *MsGetExeDirNameW();\r
+\r
+bool MsShutdown(bool reboot, bool force);\r
+bool MsShutdownEx(bool reboot, bool force, UINT time_limit, char *message);\r
+bool MsCheckLogon(wchar_t *username, char *password);\r
+bool MsIsPasswordEmpty(wchar_t *username);\r
+TOKEN_LIST *MsEnumNetworkAdapters(char *start_with_name, char *start_with_name_2);\r
+TOKEN_LIST *MsEnumNetworkAdaptersSen();\r
+bool MsGetSenDeiverFilename(char *name, UINT size, char *instance_name);\r
+bool MsMakeNewSenDriverFilename(char *name, UINT size);\r
+void MsGenerateSenDriverFilenameFromInt(char *name, UINT size, UINT n);\r
+TOKEN_LIST *MsEnumSenDriverFilenames();\r
+char *MsGetNetworkAdapterGuid(char *tag_name, char *instance_name);\r
+wchar_t *MsGetNetworkConnectionName(char *guid);\r
+char *MsGetNetworkConfigRegKeyNameFromGuid(char *guid);\r
+char *MsGetNetworkConfigRegKeyNameFromInstanceName(char *tag_name, char *instance_name);\r
+void MsSetNetworkConfig(char *tag_name, char *instance_name, char *friendly_name, bool show_icon);\r
+void MsInitNetworkConfig(char *tag_name, char *instance_name, char *connection_tag_name);\r
+\r
+char *MsGetSpecialDir(int id);\r
+wchar_t *MsGetSpecialDirW(int id);\r
+void MsGetSpecialDirs();\r
+bool MsCheckIsAdmin();\r
+void MsInitTempDir();\r
+void MsFreeTempDir();\r
+void MsGenLockFile(wchar_t *name, UINT size, wchar_t *temp_dir);\r
+void MsDeleteTempDir();\r
+void MsDeleteAllFile(char *dir);\r
+void MsDeleteAllFileW(wchar_t *dir);\r
+char *MsCreateTempFileName(char *name);\r
+char *MsCreateTempFileNameByExt(char *ext);\r
+IO *MsCreateTempFile(char *name);\r
+IO *MsCreateTempFileByExt(char *ext);\r
+\r
+bool MsShowNetworkConfiguration(HWND hWnd);\r
+\r
+bool MsInstallVLan(char *tag_name, char *connection_tag_name, char *instance_name);\r
+bool MsUpgradeVLan(char *tag_name, char *connection_tag_name, char *instance_name);\r
+bool MsEnableVLan(char *instance_name);\r
+bool MsDisableVLan(char *instance_name);\r
+bool MsUninstallVLan(char *instance_name);\r
+bool MsIsVLanEnabled(char *instance_name);\r
+void MsRestartVLan(char *instance_name);\r
+bool MsIsVLanExists(char *tag_name, char *instance_name);\r
+bool MsStartDriverInstall(char *instance_name, UCHAR *mac_address, char *sen_sys);\r
+void MsFinishDriverInstall(char *instance_name, char *sen_sys);\r
+void MsGetDriverPath(char *instance_name, wchar_t *src_inf, wchar_t *src_sys, wchar_t *dest_inf, wchar_t *dest_sys, char *sen_sys);\r
+void MsGetDriverPathA(char *instance_name, char *src_inf, char *src_sys, char *dest_inf, char *dest_sys, char *sen_sys);\r
+void MsGenMacAddress(UCHAR *mac);\r
+char *MsGetMacAddress(char *tag_name, char *instance_name);\r
+void MsSetMacAddress(char *tag_name, char *instance_name, char *mac_address);\r
+char *MsGetDriverVersion(char *tag_name, char *instance_name);\r
+char *MsGetDriverFileName(char *tag_name, char *instance_name);\r
+void MsTest();\r
+void MsInitGlobalNetworkConfig();\r
+void MsSetThreadPriorityHigh();\r
+void MsSetThreadPriorityLow();\r
+void MsSetThreadPriorityIdle();\r
+void MsSetThreadPriorityRealtime();\r
+void MsRestoreThreadPriority();\r
+char *MsGetLocalAppDataDir();\r
+char *MsGetCommonAppDataDir();\r
+char *MsGetWindowsDir();\r
+char *MsGetSystem32Dir();\r
+char *MsGetTempDir();\r
+char *MsGetWindowsDrive();\r
+char *MsGetProgramFilesDir();\r
+char *MsGetCommonStartMenuDir();\r
+char *MsGetCommonProgramsDir();\r
+char *MsGetCommonStartupDir();\r
+char *MsGetCommonAppDataDir();\r
+char *MsGetCommonDesktopDir();\r
+char *MsGetPersonalStartMenuDir();\r
+char *MsGetPersonalProgramsDir();\r
+char *MsGetPersonalStartupDir();\r
+char *MsGetPersonalAppDataDir();\r
+char *MsGetPersonalDesktopDir();\r
+char *MsGetMyDocumentsDir();\r
+char *MsGetMyTempDir();\r
+char *MsGetUserName();\r
+char *MsGetUserNameEx();\r
+char *MsGetWinTempDir();\r
+wchar_t *MsGetWindowsDirW();\r
+wchar_t *MsGetExeFileNameW();\r
+wchar_t *MsGetExeFileDirW();\r
+wchar_t *MsGetWindowDirW();\r
+wchar_t *MsGetSystem32DirW();\r
+wchar_t *MsGetTempDirW();\r
+wchar_t *MsGetWindowsDriveW();\r
+wchar_t *MsGetProgramFilesDirW();\r
+wchar_t *MsGetCommonStartMenuDirW();\r
+wchar_t *MsGetCommonProgramsDirW();\r
+wchar_t *MsGetCommonStartupDirW();\r
+wchar_t *MsGetCommonAppDataDirW();\r
+wchar_t *MsGetCommonDesktopDirW();\r
+wchar_t *MsGetPersonalStartMenuDirW();\r
+wchar_t *MsGetPersonalProgramsDirW();\r
+wchar_t *MsGetPersonalStartupDirW();\r
+wchar_t *MsGetPersonalAppDataDirW();\r
+wchar_t *MsGetPersonalDesktopDirW();\r
+wchar_t *MsGetMyDocumentsDirW();\r
+wchar_t *MsGetLocalAppDataDirW();\r
+wchar_t *MsGetMyTempDirW();\r
+wchar_t *MsGetUserNameW();\r
+wchar_t *MsGetUserNameExW();\r
+wchar_t *MsGetWinTempDirW();\r
+UINT MsGetProcessId();\r
+void MsTerminateProcess();\r
+bool MsIsServiceInstalled(char *name);\r
+bool MsInstallService(char *name, char *title, wchar_t *description, char *path);\r
+bool MsInstallServiceExW(char *name, wchar_t *title, wchar_t *description, wchar_t *path, UINT *error_code);\r
+bool MsInstallServiceW(char *name, wchar_t *title, wchar_t *description, wchar_t *path);\r
+bool MsUpdateServiceConfig(char *name);\r
+bool MsUninstallService(char *name);\r
+bool MsStartService(char *name);\r
+bool MsStartServiceEx(char *name, UINT *error_code);\r
+bool MsStopService(char *name);\r
+bool MsIsServiceRunning(char *name);\r
+bool MsIsTerminalServiceInstalled();\r
+bool MsIsUserSwitchingInstalled();\r
+bool MsIsTerminalServiceMultiUserInstalled();\r
+UINT MsGetCurrentTerminalSessionId();\r
+bool MsIsTerminalSessionActive(UINT session_id);\r
+bool MsIsCurrentTerminalSessionActive();\r
+bool MsIsCurrentDesktopAvailableForVnc();\r
+wchar_t *MsGetSessionUserName(UINT session_id);\r
+UINT MsService(char *name, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop, UINT icon);\r
+void MsTestModeW(wchar_t *title, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop);\r
+void MsTestMode(char *title, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop);\r
+void MsServiceMode(SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop);\r
+void MsUserModeW(wchar_t *title, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop, UINT icon);\r
+void MsUserMode(char *title, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop, UINT icon);\r
+bool MsIsUserMode();\r
+void MsTestOnly();\r
+void MsStopUserModeFromService();\r
+char *MsGetPenCoreDllFileName();\r
+void MsPlaySound(char *name);\r
+void MsSetThreadSingleCpu();\r
+void MsWin9xTest();\r
+bool MsCheckVLanDeviceIdFromRootEnum(char *name);\r
+bool MsInstallVLan9x(char *instance_name);\r
+void MsUpdateCompatibleIDs(char *instance_name);\r
+LIST *MsGetProcessList();\r
+LIST *MsGetProcessList9x();\r
+LIST *MsGetProcessListNt();\r
+void MsFreeProcessList(LIST *o);\r
+void MsPrintProcessList(LIST *o);\r
+int MsCompareProcessList(void *p1, void *p2);\r
+MS_PROCESS *MsSearchProcessById(LIST *o, UINT id);\r
+void MsGetCurrentProcessExeName(char *name, UINT size);\r
+void MsGetCurrentProcessExeNameW(wchar_t *name, UINT size);\r
+bool MsKillProcess(UINT id);\r
+void MsKillOtherInstance();\r
+void MsKillOtherInstanceEx(char *exclude_svcname);\r
+bool MsGetShortPathNameA(char *long_path, char *short_path, UINT short_path_size);\r
+bool MsGetShortPathNameW(wchar_t *long_path, wchar_t *short_path, UINT short_path_size);\r
+void MsWriteCallingServiceManagerProcessId(char *svcname, UINT pid);\r
+UINT MsReadCallingServiceManagerProcessId(char *svcname, bool current_user);\r
+\r
+\r
+MS_ADAPTER_LIST *MsCreateAdapterListInner();\r
+MS_ADAPTER_LIST *MsCreateAdapterListInnerEx(bool no_info);\r
+void MsFreeAdapter(MS_ADAPTER *a);\r
+void MsFreeAdapterList(MS_ADAPTER_LIST *o);\r
+wchar_t *MsGetAdapterTypeStr(UINT type);\r
+wchar_t *MsGetAdapterStatusStr(UINT status);\r
+MS_ADAPTER *MsCloneAdapter(MS_ADAPTER *a);\r
+MS_ADAPTER_LIST *MsCloneAdapterList(MS_ADAPTER_LIST *o);\r
+void MsInitAdapterListModule();\r
+void MsFreeAdapterListModule();\r
+MS_ADAPTER_LIST *MsCreateAdapterList();\r
+MS_ADAPTER_LIST *MsCreateAdapterListEx(bool no_info);\r
+void MsGetAdapterTcpIpInformation(MS_ADAPTER *a);\r
+MS_ADAPTER *MsGetAdapter(char *title);\r
+\r
+void *MsLoadLibrary(char *name);\r
+void *MsLoadLibraryW(wchar_t *name);\r
+void *MsLoadLibraryAsDataFile(char *name);\r
+void *MsLoadLibraryAsDataFileW(wchar_t *name);\r
+\r
+void MsPrintTick();\r
+bool MsDisableIme();\r
+\r
+void MsGetTcpConfig(MS_TCP *tcp);\r
+void MsSetTcpConfig(MS_TCP *tcp);\r
+void MsSaveTcpConfigReg(MS_TCP *tcp);\r
+bool MsLoadTcpConfigReg(MS_TCP *tcp);\r
+bool MsIsTcpConfigSupported();\r
+void MsApplyTcpConfig();\r
+bool MsIsShouldShowTcpConfigApp();\r
+void MsDeleteTcpConfigReg();\r
+\r
+UINT MsGetConsoleWidth();\r
+UINT MsSetConsoleWidth(UINT size);\r
+NO_WARNING *MsInitNoWarning();\r
+void MsFreeNoWarning(NO_WARNING *nw);\r
+void MsNoWarningThreadProc(THREAD *thread, void *param);\r
+char *MsNoWarningSoundInit();\r
+void MsNoWarningSoundFree(char *s);\r
+bool MsCloseWarningWindow(UINT thread_id);\r
+LIST *MsEnumChildWindows(LIST *o, HWND hWnd);\r
+void MsAddWindowToList(LIST *o, HWND hWnd);\r
+UINT MsGetThreadLocale();\r
+LIST *NewWindowList();\r
+int CmpWindowList(void *p1, void *p2);\r
+void AddWindow(LIST *o, HWND hWnd);\r
+void FreeWindowList(LIST *o);\r
+LIST *EnumAllChildWindow(HWND hWnd);\r
+LIST *EnumAllChildWindowEx(HWND hWnd, bool no_recursion, bool include_ipcontrol, bool no_self);\r
+LIST *EnumAllWindow();\r
+LIST *EnumAllWindowEx(bool no_recursion, bool include_ipcontrol);\r
+LIST *EnumAllTopWindow();\r
+\r
+bool MsExecDriverInstaller(char *arg);\r
+bool MsIsVista();\r
+bool MsIsWin2000();\r
+bool MsIsWin2000OrGreater();\r
+void MsRegistWindowsFirewall(char *title);\r
+void MsRegistWindowsFirewallEx(char *title, char *exe);\r
+void MsRegistWindowsFirewallEx2(char *title, char *exe);\r
+bool MsIs64BitWindows();\r
+bool MsIsX64();\r
+bool MsIsIA64();\r
+void *MsDisableWow64FileSystemRedirection();\r
+void MsRestoreWow64FileSystemRedirection(void *p);\r
+void MsSetWow64FileSystemRedirectionEnable(bool enable);\r
+\r
+bool MsCheckFileDigitalSignature(HWND hWnd, char *name, bool *danger);\r
+bool MsCheckFileDigitalSignatureW(HWND hWnd, wchar_t *name, bool *danger);\r
+\r
+bool MsGetProcessExeName(char *path, UINT size, UINT id);\r
+bool MsGetProcessExeNameW(wchar_t *path, UINT size, UINT id);\r
+bool MsGetWindowOwnerProcessExeName(char *path, UINT size, HWND hWnd);\r
+bool MsGetWindowOwnerProcessExeNameW(wchar_t *path, UINT size, HWND hWnd);\r
+\r
+void *MsRunAsUserEx(char *filename, char *arg, bool hide);\r
+void *MsRunAsUserExW(wchar_t *filename, wchar_t *arg, bool hide);\r
+void *MsRunAsUserExInner(char *filename, char *arg, bool hide);\r
+void *MsRunAsUserExInnerW(wchar_t *filename, wchar_t *arg, bool hide);\r
+\r
+UINT MsGetCursorPosHash();\r
+bool MsIsProcessExists(char *exename);\r
+bool MsIsProcessExistsW(wchar_t *exename);\r
+\r
+void MsGetComputerName(char *name, UINT size);\r
+void MsNoSleepThread(THREAD *thread, void *param);\r
+void MsNoSleepThreadVista(THREAD *thread, void *param);\r
+UINT64 MsGetScreenSaverTimeout();\r
+void *MsNoSleepStart(bool no_screensaver);\r
+void MsNoSleepEnd(void *p);\r
+bool MsIsRemoteDesktopAvailable();\r
+bool MsIsRemoteDesktopCanEnableByRegistory();\r
+bool MsIsRemoteDesktopEnabled();\r
+bool MsEnableRemoteDesktop();\r
+\r
+void MsSetFileToHidden(char *name);\r
+void MsSetFileToHiddenW(wchar_t *name);\r
+bool MsGetFileVersion(char *name, UINT *v1, UINT *v2, UINT *v3, UINT *v4);\r
+bool MsGetFileVersionW(wchar_t *name, UINT *v1, UINT *v2, UINT *v3, UINT *v4);\r
+\r
+bool MsExtractCabinetFileFromExe(char *exe, char *cab);\r
+bool MsExtractCabinetFileFromExeW(wchar_t *exe, wchar_t *cab);\r
+BUF *MsExtractResourceFromExe(char *exe, char *type, char *name);\r
+BUF *MsExtractResourceFromExeW(wchar_t *exe, char *type, char *name);\r
+bool MsExtractCab(char *cab_name, char *dest_dir_name);\r
+bool MsExtractCabW(wchar_t *cab_name, wchar_t *dest_dir_name);\r
+bool MsGetCabarcExeFilename(char *name, UINT size);\r
+bool MsGetCabarcExeFilenameW(wchar_t *name, UINT size);\r
+bool MsExtractCabFromMsi(char *msi, char *cab);\r
+bool MsExtractCabFromMsiW(wchar_t *msi, wchar_t *cab);\r
+bool MsIsDirectory(char *name);\r
+bool MsIsDirectoryW(wchar_t *name);\r
+bool MsUniIsDirectory(wchar_t *name);\r
+bool MsUniFileDelete(wchar_t *name);\r
+bool MsUniDirectoryDelete(wchar_t *name);\r
+bool MsUniMakeDir(wchar_t *name);\r
+void MsUniMakeDirEx(wchar_t *name);\r
+void MsMakeDirEx(char *name);\r
+bool MsMakeDir(char *name);\r
+bool MsDirectoryDelete(char *name);\r
+bool MsFileDelete(char *name);\r
+bool MsExecute(char *exe, char *arg);\r
+bool MsExecuteW(wchar_t *exe, wchar_t *arg);\r
+bool MsExecuteEx(char *exe, char *arg, void **process_handle);\r
+bool MsExecuteExW(wchar_t *exe, wchar_t *arg, void **process_handle);\r
+UINT MsWaitProcessExit(void *process_handle);\r
+bool MsIsFileLocked(char *name);\r
+bool MsIsFileLockedW(wchar_t *name);\r
+bool MsIsLocalDrive(char *name);\r
+bool MsIsLocalDriveW(wchar_t *name);\r
+void MsUpdateSystem();\r
+bool MsGetPhysicalMacAddressFromNetbios(void *address);\r
+bool MsGetPhysicalMacAddressFromApi(void *address);\r
+bool MsGetPhysicalMacAddress(void *address);\r
+bool MsIsUseWelcomeLogin();\r
+UINT64 MsGetHiResCounter();\r
+double MsGetHiResTimeSpan(UINT64 diff);\r
+UINT64 MsGetHiResTimeSpanUSec(UINT64 diff);\r
+BUF *MsRegSubkeysToBuf(UINT root, char *keyname, bool force32bit, bool force64bit);\r
+void MsBufToRegSubkeys(UINT root, char *keyname, BUF *b, bool overwrite, bool force32bit, bool force64bit);\r
+void MsRegDeleteSubkeys(UINT root, char *keyname, bool force32bit, bool force64bit);\r
+void MsRestartMMCSS();\r
+bool MsIsMMCSSNetworkThrottlingEnabled();\r
+void MsSetMMCSSNetworkThrottlingEnable(bool enable);\r
+void MsSetShutdownParameters(UINT level, UINT flag);\r
+void MsChangeIconOnTrayEx2(void *icon, wchar_t *tooltip, wchar_t *info_title, wchar_t *info, UINT info_flags);\r
+bool MsIsTrayInited();\r
+UINT MsGetClipboardOwnerProcessId();\r
+void MsDeleteClipboard();\r
+void *MsInitEventLog(wchar_t *src_name);\r
+void MsFreeEventLog(void *p);\r
+bool MsWriteEventLog(void *p, UINT type, wchar_t *str);\r
+bool MsIsWinXPOrWinVista();\r
+bool MsGetFileInformation(void *h, void *info);\r
+void MsSetErrorModeToSilent();\r
+void MsSetEnableMinidump(bool enabled);\r
+void MsWriteMinidump(wchar_t *filename, void *ex);\r
+\r
+// 内部関数\r
+#ifdef MICROSOFT_C\r
+\r
+LONG CALLBACK MsExceptionHandler(struct _EXCEPTION_POINTERS *ExceptionInfo);\r
+HKEY MsGetRootKeyFromInt(UINT root);\r
+NT_API *MsLoadNtApiFunctions();\r
+void MsFreeNtApiFunctions(NT_API *nt);\r
+void MsDestroyDevInfo(HDEVINFO info);\r
+HDEVINFO MsGetDevInfoFromDeviceId(SP_DEVINFO_DATA *dev_info_data, char *device_id);\r
+bool MsStartDevice(HDEVINFO info, SP_DEVINFO_DATA *dev_info_data);\r
+bool MsStopDevice(HDEVINFO info, SP_DEVINFO_DATA *dev_info_data);\r
+bool MsDeleteDevice(HDEVINFO info, SP_DEVINFO_DATA *dev_info_data);\r
+bool MsIsDeviceRunning(HDEVINFO info, SP_DEVINFO_DATA *dev_info_data);\r
+void CALLBACK MsServiceDispatcher(DWORD argc, LPTSTR *argv);\r
+void CALLBACK MsServiceHandler(DWORD opcode);\r
+void MsServiceStoperThread(THREAD *t, void *p);\r
+void MsServiceStoperMainThread(THREAD *t, void *p);\r
+void MsServiceStarterMainThread(THREAD *t, void *p);\r
+LRESULT CALLBACK MsUserModeWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);\r
+void MsShowIconOnTray(HWND hWnd, HICON icon, wchar_t *tooltip, UINT msg);\r
+void MsRestoreIconOnTray();\r
+void MsChangeIconOnTray(HICON icon, wchar_t *tooltip);\r
+void MsChangeIconOnTrayEx(HICON icon, wchar_t *tooltip, wchar_t *info_title, wchar_t *info, UINT info_flags);\r
+void MsHideIconOnTray();\r
+void MsUserModeTrayMenu(HWND hWnd);\r
+bool MsAppendMenu(HMENU hMenu, UINT flags, UINT_PTR id, wchar_t *str);\r
+bool MsInsertMenu(HMENU hMenu, UINT pos, UINT flags, UINT_PTR id_new_item, wchar_t *lp_new_item);\r
+bool CALLBACK MsEnumChildWindowProc(HWND hWnd, LPARAM lParam);\r
+BOOL CALLBACK EnumTopWindowProc(HWND hWnd, LPARAM lParam);\r
+bool CALLBACK MsEnumThreadWindowProc(HWND hWnd, LPARAM lParam);\r
+HANDLE MsCreateUserToken();\r
+SID *MsGetSidFromAccountName(char *name);\r
+void MsFreeSid(SID *sid);\r
+\r
+#endif // MICROSOFT_C\r
+\r
+#endif // MICROSOFT_H\r
+\r
+#endif // OS_WIN32\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Network.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Network.c
new file mode 100644 (file)
index 0000000..c297632
--- /dev/null
@@ -0,0 +1,9389 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Network.c\r
+// ネットワーク通信モジュール\r
+\r
+#define        ENCRYPT_C\r
+#define        NETWORK_C\r
+\r
+#define        __WINCRYPT_H__\r
+\r
+#ifdef WIN32\r
+// Socket API のために windows.h をインクルード\r
+#define        _WIN32_WINNT            0x0502\r
+#define        WINVER                          0x0502\r
+#include <Ws2tcpip.h>\r
+#include <Wspiapi.h>\r
+#include <winsock2.h>\r
+#include <Ws2tcpip.h>\r
+#include <windows.h>\r
+#include <Iphlpapi.h>\r
+#endif // WIN32\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <openssl/ssl.h>\r
+#include <openssl/err.h>\r
+#include <openssl/rand.h>\r
+#include <openssl/engine.h>\r
+#include <openssl/bio.h>\r
+#include <openssl/x509.h>\r
+#include <openssl/pkcs7.h>\r
+#include <openssl/pkcs12.h>\r
+#include <openssl/rc4.h>\r
+#include <openssl/md5.h>\r
+#include <openssl/sha.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+#ifdef OS_WIN32\r
+NETWORK_WIN32_FUNCTIONS *w32net;\r
+struct ROUTE_CHANGE_DATA\r
+{\r
+       OVERLAPPED Overlapped;\r
+       HANDLE Handle;\r
+       UINT NumCalled;\r
+};\r
+#endif // OS_WIN32\r
+\r
+// SSL でブロッキングするかどうか\r
+#if    defined(UNIX_BSD)\r
+#define        FIX_SSL_BLOCKING\r
+#endif\r
+\r
+// IPV6_V6ONLY 定数\r
+#ifdef UNIX_LINUX\r
+#ifndef        IPV6_V6ONLY\r
+#define        IPV6_V6ONLY     26\r
+#endif // IPV6_V6ONLY\r
+#endif // UNIX_LINUX\r
+\r
+#ifdef UNIX_SOLARIS\r
+#ifndef        IPV6_V6ONLY\r
+#define        IPV6_V6ONLY     0x27\r
+#endif // IPV6_V6ONLY\r
+#endif // UNIX_SOLARIS\r
+\r
+// SSL_CTX\r
+static SSL_CTX *ssl_ctx = NULL;\r
+\r
+// DNS キャッシュリスト\r
+static LIST *DnsCache;\r
+\r
+// ロック関係\r
+static LOCK *machine_name_lock = NULL;\r
+static LOCK *disconnect_function_lock = NULL;\r
+static LOCK *aho = NULL;\r
+static LOCK *socket_library_lock = NULL;\r
+extern LOCK *openssl_lock;\r
+static LOCK *ssl_accept_lock = NULL;\r
+static LOCK *ssl_connect_lock = NULL;\r
+static TOKEN_LIST *cipher_list_token = NULL;\r
+static COUNTER *num_tcp_connections = NULL;\r
+static LOCK *dns_lock = NULL;\r
+static LOCK *unix_dns_server_addr_lock = NULL;\r
+static IP unix_dns_server;\r
+static LIST *HostCacheList = NULL;\r
+static LIST *WaitThreadList = NULL;\r
+static bool disable_cache = false;\r
+static bool NetworkReleaseMode = false;                        // ネットワークリリースモード\r
+\r
+static char *cipher_list = "RC4-MD5 RC4-SHA AES128-SHA AES256-SHA DES-CBC-SHA DES-CBC3-SHA";\r
+static LIST *ip_clients = NULL;\r
+\r
+// ルーティングテーブル変更検出を初期化\r
+ROUTE_CHANGE *NewRouteChange()\r
+{\r
+#ifdef OS_WIN32\r
+       return Win32NewRouteChange();\r
+#else  // OS_WIN32\r
+       return NULL;\r
+#endif // OS_WIN32\r
+}\r
+\r
+// ルーティングテーブル変更検出を解放\r
+void FreeRouteChange(ROUTE_CHANGE *r)\r
+{\r
+#ifdef OS_WIN32\r
+       Win32FreeRouteChange(r);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// ルーティングテーブルが変更されたかどうか取得\r
+bool IsRouteChanged(ROUTE_CHANGE *r)\r
+{\r
+#ifdef OS_WIN32\r
+       return Win32IsRouteChanged(r);\r
+#else  // OS_WIN32\r
+       return false;\r
+#endif // OS_WIN32\r
+}\r
+\r
+// ルーティングテーブル変更検出機能 (Win32)\r
+#ifdef OS_WIN32\r
+ROUTE_CHANGE *Win32NewRouteChange()\r
+{\r
+       ROUTE_CHANGE *r;\r
+       bool ret;\r
+\r
+       if (MsIsNt() == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (w32net->CancelIPChangeNotify == NULL ||\r
+               w32net->NotifyRouteChange == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       r = ZeroMalloc(sizeof(ROUTE_CHANGE));\r
+\r
+       r->Data = ZeroMalloc(sizeof(ROUTE_CHANGE_DATA));\r
+\r
+       r->Data->Overlapped.hEvent = CreateEventA(NULL, false, true, NULL);\r
+\r
+       ret = w32net->NotifyRouteChange(&r->Data->Handle, &r->Data->Overlapped);\r
+       if (!(ret == NO_ERROR || ret == WSA_IO_PENDING || WSAGetLastError() == WSA_IO_PENDING))\r
+       {\r
+               Free(r->Data);\r
+               Free(r);\r
+\r
+               return NULL;\r
+       }\r
+\r
+       return r;\r
+}\r
+\r
+void Win32FreeRouteChange(ROUTE_CHANGE *r)\r
+{\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       w32net->CancelIPChangeNotify(&r->Data->Overlapped);\r
+       CloseHandle(r->Data->Overlapped.hEvent);\r
+\r
+       Free(r->Data);\r
+       Free(r);\r
+}\r
+\r
+bool Win32IsRouteChanged(ROUTE_CHANGE *r)\r
+{\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if ((r->Data->NumCalled++) == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (WaitForSingleObject(r->Data->Overlapped.hEvent, 0) == WAIT_OBJECT_0)\r
+       {\r
+               w32net->NotifyRouteChange(&r->Data->Handle, &r->Data->Overlapped);\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+#endif // OS_WIN32\r
+\r
+\r
+// TCP コネクションのプロセス ID の取得が成功するかどうかを取得\r
+bool CanGetTcpProcessId()\r
+{\r
+       UINT i;\r
+       bool ret = false;\r
+       LIST *o = GetTcpTableList();\r
+\r
+       if (o == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               TCPTABLE *t = LIST_DATA(o, i);\r
+\r
+               if (t->ProcessId != 0)\r
+               {\r
+                       ret = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       FreeTcpTableList(o);\r
+\r
+       return ret;\r
+}\r
+\r
+\r
+\r
+\r
+#define        USE_OLD_GETIP\r
+\r
+// Linux における arp_filter を設定する\r
+void SetLinuxArpFilter()\r
+{\r
+       char *filename = "/proc/sys/net/ipv4/conf/all/arp_filter";\r
+       char *data = "1\n";\r
+       IO *o;\r
+\r
+       o = FileCreate(filename);\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FileWrite(o, data, StrLen(data));\r
+       FileFlush(o);\r
+\r
+       FileClose(o);\r
+}\r
+\r
+// 指定された文字列が IPv6 マスクかどうか判定する\r
+bool IsIpMask6(char *str)\r
+{\r
+       IP mask;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return StrToMask6(&mask, str);\r
+}\r
+\r
+// 指定された文字列が IPv6 アドレスかどうか判定する\r
+bool IsStrIPv6Address(char *str)\r
+{\r
+       IP ip;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrToIP6(&ip, str) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// サブネットマスクを整数に変換する\r
+UINT SubnetMaskToInt6(IP *a)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (IsIP6(a) == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       for (i = 0;i <= 128;i++)\r
+       {\r
+               IP tmp;\r
+\r
+               IntToSubnetMask6(&tmp, i);\r
+\r
+               if (CmpIpAddr(a, &tmp) == 0)\r
+               {\r
+                       return i;\r
+               }\r
+       }\r
+\r
+       return 0;\r
+}\r
+UINT SubnetMaskToInt4(IP *a)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (IsIP4(a) == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       for (i = 0;i <= 32;i++)\r
+       {\r
+               IP tmp;\r
+\r
+               IntToSubnetMask4(&tmp, i);\r
+\r
+               if (CmpIpAddr(a, &tmp) == 0)\r
+               {\r
+                       return i;\r
+               }\r
+       }\r
+\r
+       return 0;\r
+}\r
+UINT SubnetMaskToInt(IP *a)\r
+{\r
+       if (IsIP6(a))\r
+       {\r
+               return SubnetMaskToInt6(a);\r
+       }\r
+       else\r
+       {\r
+               return SubnetMaskToInt4(a);\r
+       }\r
+}\r
+\r
+// 指定した IP アドレスがサブネットマスクかどうか調べる\r
+bool IsSubnetMask6(IP *a)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (IsIP6(a) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i <= 128;i++)\r
+       {\r
+               IP tmp;\r
+\r
+               IntToSubnetMask6(&tmp, i);\r
+\r
+               if (CmpIpAddr(a, &tmp) == 0)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// MAC アドレスからグローバルアドレスを生成する\r
+void GenerateEui64GlobalAddress(IP *ip, IP *prefix, IP *subnet, UCHAR *mac)\r
+{\r
+       UCHAR tmp[8];\r
+       IP a;\r
+       IP subnet_not;\r
+       IP or1, or2;\r
+       // 引数チェック\r
+       if (ip == NULL || prefix == NULL || subnet == NULL || mac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GenerateEui64Address6(tmp, mac);\r
+\r
+       ZeroIP6(&a);\r
+\r
+       Copy(&a.ipv6_addr[8], tmp, 8);\r
+\r
+       IPNot6(&subnet_not, subnet);\r
+       IPAnd6(&or1, &a, &subnet_not);\r
+       IPAnd6(&or2, prefix, subnet);\r
+\r
+       IPOr6(ip, &or1, &or2);\r
+}\r
+\r
+// MAC アドレスからローカルアドレスを生成する\r
+void GenerateEui64LocalAddress(IP *a, UCHAR *mac)\r
+{\r
+       UCHAR tmp[8];\r
+       // 引数チェック\r
+       if (a == NULL || mac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GenerateEui64Address6(tmp, mac);\r
+\r
+       ZeroIP6(a);\r
+       a->ipv6_addr[0] = 0xfe;\r
+       a->ipv6_addr[1] = 0x80;\r
+\r
+       Copy(&a->ipv6_addr[8], tmp, 8);\r
+}\r
+\r
+// MAC アドレスから EUI-64 アドレスを生成する\r
+void GenerateEui64Address6(UCHAR *dst, UCHAR *mac)\r
+{\r
+       // 引数チェック\r
+       if (dst == NULL || mac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Copy(dst, mac, 3);\r
+       Copy(dst + 5, mac, 3);\r
+\r
+       dst[3] = 0xff;\r
+       dst[4] = 0xfe;\r
+       dst[0] = ((~(dst[0] & 0x02)) & 0x02) | (dst[0] & 0xfd);\r
+}\r
+\r
+// 同一のネットワークかどうか調べる\r
+bool IsInSameNetwork6(IP *a1, IP *a2, IP *subnet)\r
+{\r
+       IP prefix1, prefix2;\r
+       // 引数チェック\r
+       if (IsIP6(a1) == false || IsIP6(a2) == false || IsIP6(subnet) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (a1->ipv6_scope_id != a2->ipv6_scope_id)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       GetPrefixAddress6(&prefix1, a1, subnet);\r
+       GetPrefixAddress6(&prefix2, a2, subnet);\r
+\r
+       if (CmpIpAddr(&prefix1, &prefix2) == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// ネットワークプレフィックスアドレスかどうかチェックする\r
+bool IsNetworkAddress6(IP *ip, IP *subnet)\r
+{\r
+       return IsNetworkPrefixAddress6(ip, subnet);\r
+}\r
+bool IsNetworkPrefixAddress6(IP *ip, IP *subnet)\r
+{\r
+       IP host;\r
+       // 引数チェック\r
+       if (ip == NULL || subnet == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsIP6(ip) == false || IsIP6(subnet) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       GetHostAddress6(&host, ip, subnet);\r
+\r
+       if (IsZeroIp(&host))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// ユニキャストアドレスが有効かどうかチェックする\r
+bool CheckUnicastAddress(IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if ((GetIPAddrType6(ip) & IPV6_ADDR_UNICAST) == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ホストアドレスの取得\r
+void GetHostAddress6(IP *dst, IP *ip, IP *subnet)\r
+{\r
+       IP not;\r
+       // 引数チェック\r
+       if (dst == NULL || ip == NULL || subnet == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       IPNot6(&not, subnet);\r
+\r
+       IPAnd6(dst, ip, &not);\r
+\r
+       dst->ipv6_scope_id = ip->ipv6_scope_id;\r
+}\r
+\r
+// プレフィックスアドレスの取得\r
+void GetPrefixAddress6(IP *dst, IP *ip, IP *subnet)\r
+{\r
+       // 引数チェック\r
+       if (dst == NULL || ip == NULL || subnet == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       IPAnd6(dst, ip, subnet);\r
+\r
+       dst->ipv6_scope_id = ip->ipv6_scope_id;\r
+}\r
+\r
+// 要請ノードマルチキャストアドレスを取得\r
+void GetSoliciationMulticastAddr6(IP *dst, IP *src)\r
+{\r
+       IP prefix;\r
+       IP mask104;\r
+       IP or1, or2;\r
+\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ZeroIP6(&prefix);\r
+       prefix.ipv6_addr[0] = 0xff;\r
+       prefix.ipv6_addr[1] = 0x02;\r
+       prefix.ipv6_addr[11] = 0x01;\r
+       prefix.ipv6_addr[12] = 0xff;\r
+\r
+       IntToSubnetMask6(&mask104, 104);\r
+\r
+       IPAnd6(&or1, &prefix, &mask104);\r
+       IPAnd6(&or2, src, &mask104);\r
+\r
+       IPOr6(dst, &or1, &or2);\r
+\r
+       dst->ipv6_scope_id = src->ipv6_scope_id;\r
+}\r
+\r
+// マルチキャストアドレスに対応した MAC アドレスの生成\r
+void GenerateMulticastMacAddress6(UCHAR *mac, IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (mac == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       mac[0] = 0x33;\r
+       mac[1] = 0x33;\r
+       mac[2] = ip->ipv6_addr[12];\r
+       mac[3] = ip->ipv6_addr[13];\r
+       mac[4] = ip->ipv6_addr[14];\r
+       mac[5] = ip->ipv6_addr[15];\r
+}\r
+\r
+// IPv6 アドレスのタイプの取得\r
+UINT GetIPv6AddrType(IPV6_ADDR *addr)\r
+{\r
+       IP ip;\r
+       // 引数チェック\r
+       if (addr == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       IPv6AddrToIP(&ip, addr);\r
+\r
+       return GetIPAddrType6(&ip);\r
+}\r
+UINT GetIPAddrType6(IP *ip)\r
+{\r
+       UINT ret = 0;\r
+       // 引数チェック\r
+       if (IsIP6(ip) == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (ip->ipv6_addr[0] == 0xff)\r
+       {\r
+               IP all_node, all_router;\r
+\r
+               GetAllNodeMulticaseAddress6(&all_node);\r
+\r
+               GetAllRouterMulticastAddress6(&all_router);\r
+\r
+               ret |= IPV6_ADDR_MULTICAST;\r
+\r
+               if (Cmp(ip->ipv6_addr, all_node.ipv6_addr, 16) == 0)\r
+               {\r
+                       ret |= IPV6_ADDR_ALL_NODE_MULTICAST;\r
+               }\r
+               else if (Cmp(ip->ipv6_addr, all_router.ipv6_addr, 16) == 0)\r
+               {\r
+                       ret |= IPV6_ADDR_ALL_ROUTER_MULTICAST;\r
+               }\r
+               else\r
+               {\r
+                       if (ip->ipv6_addr[1] == 0x02 && ip->ipv6_addr[2] == 0 && ip->ipv6_addr[3] == 0 &&\r
+                               ip->ipv6_addr[4] == 0 && ip->ipv6_addr[5] == 0 && ip->ipv6_addr[6] == 0 &&\r
+                               ip->ipv6_addr[7] == 0 && ip->ipv6_addr[8] == 0 && ip->ipv6_addr[9] == 0 &&\r
+                               ip->ipv6_addr[10] == 0 && ip->ipv6_addr[11] == 0x01 && ip->ipv6_addr[12] == 0xff)\r
+                       {\r
+                               ret |= IPV6_ADDR_SOLICIATION_MULTICAST;\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               ret |= IPV6_ADDR_UNICAST;\r
+\r
+               if (ip->ipv6_addr[0] == 0xfe && (ip->ipv6_addr[1] & 0xc0) == 0x80)\r
+               {\r
+                       ret |= IPV6_ADDR_LOCAL_UNICAST;\r
+               }\r
+               else\r
+               {\r
+                       ret |= IPV6_ADDR_GLOBAL_UNICAST;\r
+\r
+                       if (IsZero(&ip->ipv6_addr, 16))\r
+                       {\r
+                               ret |= IPV6_ADDR_ZERO;\r
+                       }\r
+                       else\r
+                       {\r
+                               IP loopback;\r
+\r
+                               GetLoopbackAddress6(&loopback);\r
+\r
+                               if (Cmp(ip->ipv6_addr, loopback.ipv6_addr, 16) == 0)\r
+                               {\r
+                                       ret |= IPV6_ADDR_LOOPBACK;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// すべてのビットが立っているアドレス\r
+void GetAllFilledAddress6(IP *ip)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ZeroIP6(ip);\r
+\r
+       for (i = 0;i < 15;i++)\r
+       {\r
+               ip->ipv6_addr[i] = 0xff;\r
+       }\r
+}\r
+\r
+// ループバックアドレス\r
+void GetLoopbackAddress6(IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ZeroIP6(ip);\r
+\r
+       ip->ipv6_addr[15] = 0x01;\r
+}\r
+\r
+// 全ノードマルチキャストアドレス\r
+void GetAllNodeMulticaseAddress6(IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ZeroIP6(ip);\r
+\r
+       ip->ipv6_addr[0] = 0xff;\r
+       ip->ipv6_addr[1] = 0x02;\r
+       ip->ipv6_addr[15] = 0x01;\r
+}\r
+\r
+// 全ルータマルチキャストアドレス\r
+void GetAllRouterMulticastAddress6(IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ZeroIP6(ip);\r
+\r
+       ip->ipv6_addr[0] = 0xff;\r
+       ip->ipv6_addr[1] = 0x02;\r
+       ip->ipv6_addr[15] = 0x02;\r
+}\r
+\r
+// IPv6 アドレスの論理演算\r
+void IPAnd6(IP *dst, IP *a, IP *b)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (dst == NULL || IsIP6(a) == false || IsIP6(b) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ZeroIP6(dst);\r
+       for (i = 0;i < 16;i++)\r
+       {\r
+               dst->ipv6_addr[i] = a->ipv6_addr[i] & b->ipv6_addr[i];\r
+       }\r
+}\r
+void IPOr6(IP *dst, IP *a, IP *b)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (dst == NULL || IsIP6(a) == false || IsIP6(b) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ZeroIP6(dst);\r
+       for (i = 0;i < 16;i++)\r
+       {\r
+               dst->ipv6_addr[i] = a->ipv6_addr[i] | b->ipv6_addr[i];\r
+       }\r
+}\r
+void IPNot6(IP *dst, IP *a)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (dst == NULL || IsIP6(a) == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ZeroIP6(dst);\r
+       for (i = 0;i < 16;i++)\r
+       {\r
+               dst->ipv6_addr[i] = ~(a->ipv6_addr[i]);\r
+       }\r
+}\r
+\r
+// サブネットマスクの作成\r
+void IntToSubnetMask6(IP *ip, UINT i)\r
+{\r
+       UINT j = i / 8;\r
+       UINT k = i % 8;\r
+       UINT z;\r
+       IP a;\r
+\r
+       ZeroIP6(&a);\r
+\r
+       for (z = 0;z < 16;z++)\r
+       {\r
+               if (z < j)\r
+               {\r
+                       a.ipv6_addr[z] = 0xff;\r
+               }\r
+               else if (z == j)\r
+               {\r
+                       a.ipv6_addr[z] = ~(0xff >> k);\r
+               }\r
+       }\r
+\r
+       Copy(ip, &a, sizeof(IP));\r
+}\r
+\r
+// IP アドレスを文字列に変換\r
+void IP6AddrToStr(char *str, UINT size, IPV6_ADDR *addr)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || addr == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       IPToStr6Array(str, size, addr->Value);\r
+}\r
+void IPToStr6Array(char *str, UINT size, UCHAR *bytes)\r
+{\r
+       IP ip;\r
+       // 引数チェック\r
+       if (str == NULL || bytes == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIP6(&ip, bytes);\r
+\r
+       IPToStr6(str, size, &ip);\r
+}\r
+void IPToStr6(char *str, UINT size, IP *ip)\r
+{\r
+       char tmp[MAX_SIZE];\r
+\r
+       IPToStr6Inner(tmp, ip);\r
+\r
+       StrCpy(str, size, tmp);\r
+}\r
+void IPToStr6Inner(char *str, IP *ip)\r
+{\r
+       UINT i;\r
+       USHORT values[8];\r
+       UINT zero_started_index;\r
+       UINT max_zero_len;\r
+       UINT max_zero_start;\r
+       IP a;\r
+       // 引数チェック\r
+       if (str == NULL || ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Copy(&a, ip, sizeof(IP));\r
+\r
+       for (i = 0;i < 8;i++)\r
+       {\r
+               Copy(&values[i], &a.ipv6_addr[i * 2], sizeof(USHORT));\r
+               values[i] = Endian16(values[i]);\r
+       }\r
+\r
+       // 省略できる場所があるかどうか検索\r
+       zero_started_index = INFINITE;\r
+       max_zero_len = 0;\r
+       max_zero_start = INFINITE;\r
+       for (i = 0;i < 9;i++)\r
+       {\r
+               USHORT v = (i != 8 ? values[i] : 1);\r
+\r
+               if (values[i] == 0)\r
+               {\r
+                       if (zero_started_index == INFINITE)\r
+                       {\r
+                               zero_started_index = i;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       UINT zero_len;\r
+\r
+                       if (zero_started_index != INFINITE)\r
+                       {\r
+                               zero_len = i - zero_started_index;\r
+                               if (zero_len >= 2)\r
+                               {\r
+                                       if (max_zero_len < zero_len)\r
+                                       {\r
+                                               max_zero_start = zero_started_index;\r
+                                               max_zero_len = zero_len;\r
+                                       }\r
+                               }\r
+\r
+                               zero_started_index = INFINITE;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // 文字列を形成\r
+       StrCpy(str, 0, "");\r
+       for (i = 0;i < 8;i++)\r
+       {\r
+               char tmp[16];\r
+\r
+               ToHex(tmp, values[i]);\r
+               StrLower(tmp);\r
+\r
+               if (i == max_zero_start)\r
+               {\r
+                       if (i == 0)\r
+                       {\r
+                               StrCat(str, 0, "::");\r
+                       }\r
+                       else\r
+                       {\r
+                               StrCat(str, 0, ":");\r
+                       }\r
+                       i += max_zero_len - 1;\r
+               }\r
+               else\r
+               {\r
+                       StrCat(str, 0, tmp);\r
+                       if (i != 7)\r
+                       {\r
+                               StrCat(str, 0, ":");\r
+                       }\r
+               }\r
+       }\r
+\r
+       // スコープ ID\r
+       if (ip->ipv6_scope_id != 0)\r
+       {\r
+               char tmp[64];\r
+\r
+               StrCat(str, 0, "%");\r
+               ToStr(tmp, ip->ipv6_scope_id);\r
+\r
+               StrCat(str, 0, tmp);\r
+       }\r
+}\r
+\r
+// 文字列を IP アドレスに変換\r
+bool StrToIP6(IP *ip, char *str)\r
+{\r
+       TOKEN_LIST *t;\r
+       char tmp[MAX_PATH];\r
+       IP a;\r
+       UINT i;\r
+       UINT scope_id = 0;\r
+       // 引数チェック\r
+       if (str == NULL || ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ZeroIP6(&a);\r
+\r
+       StrCpy(tmp, sizeof(tmp), str);\r
+       Trim(tmp);\r
+\r
+       if (StartWith(tmp, "[") && EndWith(tmp, "]"))\r
+       {\r
+               // かぎかっこで囲まれている場合はそれを除去\r
+               StrCpy(tmp, sizeof(tmp), &tmp[1]);\r
+\r
+               if (StrLen(tmp) >= 1)\r
+               {\r
+                       tmp[StrLen(tmp) - 1] = 0;\r
+               }\r
+       }\r
+\r
+       // スコープ ID がある場合はそれを解析して除去\r
+       i = SearchStrEx(tmp, "%", 0, false);\r
+       if (i != INFINITE)\r
+       {\r
+               char ss[MAX_PATH];\r
+\r
+               StrCpy(ss, sizeof(ss), &tmp[i + 1]);\r
+\r
+               tmp[i] = 0;\r
+\r
+               Trim(tmp);\r
+\r
+               Trim(ss);\r
+\r
+               scope_id = ToInt(ss);\r
+       }\r
+\r
+       // トークン分割\r
+       t = ParseTokenWithNullStr(tmp, ":");\r
+       if (t->NumTokens >= 3 && t->NumTokens <= 8)\r
+       {\r
+               UINT i, n;\r
+               bool b = true;\r
+               UINT k = 0;\r
+\r
+               n = 0;\r
+\r
+               for (i = 0;i < t->NumTokens;i++)\r
+               {\r
+                       char *str = t->Token[i];\r
+\r
+                       if (i != 0 && i != (t->NumTokens - 1) && StrLen(str) == 0)\r
+                       {\r
+                               n++;\r
+                               if (n == 1)\r
+                               {\r
+                                       k += 2 * (8 - t->NumTokens + 1);\r
+                               }\r
+                               else\r
+                               {\r
+                                       b = false;\r
+                                       break;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               UCHAR chars[2];\r
+\r
+                               if (CheckIPItemStr6(str) == false)\r
+                               {\r
+                                       b = false;\r
+                                       break;\r
+                               }\r
+\r
+                               IPItemStrToChars6(chars, str);\r
+\r
+                               a.ipv6_addr[k++] = chars[0];\r
+                               a.ipv6_addr[k++] = chars[1];\r
+                       }\r
+               }\r
+\r
+               if (n != 0 && n != 1)\r
+               {\r
+                       b = false;\r
+               }\r
+               else if (n == 0 && t->NumTokens != 8)\r
+               {\r
+                       b = false;\r
+               }\r
+\r
+               if (b == false)\r
+               {\r
+                       FreeToken(t);\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               FreeToken(t);\r
+               return false;\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       Copy(ip, &a, sizeof(IP));\r
+\r
+       ip->ipv6_scope_id = scope_id;\r
+\r
+       return true;\r
+}\r
+bool StrToIP6Addr(IPV6_ADDR *ip, char *str)\r
+{\r
+       IP ip2;\r
+       // 引数チェック\r
+       if (ip == NULL || str == NULL)\r
+       {\r
+               Zero(ip, sizeof(IPV6_ADDR));\r
+               return false;\r
+       }\r
+\r
+       if (StrToIP6(&ip2, str) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IPToIPv6Addr(ip, &ip2) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// IP アドレスの文字から UCHAR 型に変換\r
+void IPItemStrToChars6(UCHAR *chars, char *str)\r
+{\r
+       char tmp[5];\r
+       BUF *b;\r
+       UINT len;\r
+       // 引数チェック\r
+       if (chars == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(tmp, sizeof(tmp));\r
+\r
+       len = StrLen(str);\r
+       switch (len)\r
+       {\r
+       case 0:\r
+               tmp[0] = tmp[1] = tmp[2] = tmp[3] = '0';\r
+               break;\r
+\r
+       case 1:\r
+               tmp[0] = tmp[1] = tmp[2] = '0';\r
+               tmp[3] = str[0];\r
+               break;\r
+\r
+       case 2:\r
+               tmp[0] = tmp[1] = '0';\r
+               tmp[2] = str[0];\r
+               tmp[3] = str[1];\r
+               break;\r
+\r
+       case 3:\r
+               tmp[0] = '0';\r
+               tmp[1] = str[0];\r
+               tmp[2] = str[1];\r
+               tmp[3] = str[2];\r
+               break;\r
+\r
+       case 4:\r
+               tmp[0] = str[0];\r
+               tmp[1] = str[1];\r
+               tmp[2] = str[2];\r
+               tmp[3] = str[3];\r
+               break;\r
+       }\r
+\r
+       b = StrToBin(tmp);\r
+\r
+       chars[0] = ((UCHAR *)b->Buf)[0];\r
+       chars[1] = ((UCHAR *)b->Buf)[1];\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// IP アドレスの要素文字列の中に不正な文字が含まれていないかどうかチェックする\r
+bool CheckIPItemStr6(char *str)\r
+{\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       if (len >= 5)\r
+       {\r
+               // 長さ不正\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               char c = str[i];\r
+\r
+               if ((c >= 'a' && c <= 'f') ||\r
+                       (c >= 'A' && c <= 'F') ||\r
+                       (c >= '0' && c <= '9'))\r
+               {\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ゼロの IPv4 アドレスを作成する\r
+void ZeroIP4(IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(ip, sizeof(IP));\r
+}\r
+\r
+// ゼロの IPv6 アドレスを作成する\r
+void ZeroIP6(IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIP6(ip, NULL);\r
+}\r
+\r
+// localhost の IP アドレスを取得する\r
+void GetLocalHostIP6(IP *ip)\r
+{\r
+       ZeroIP6(ip);\r
+\r
+       ip->ipv6_addr[15] = 1;\r
+}\r
+\r
+// IPV6_ADDR を IP に変換\r
+void IPv6AddrToIP(IP *ip, IPV6_ADDR *addr)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL || addr == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIP6(ip, addr->Value);\r
+}\r
+\r
+// IP を IPV6_ADDR に変換\r
+bool IPToIPv6Addr(IPV6_ADDR *addr, IP *ip)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (addr == NULL || ip == NULL)\r
+       {\r
+               Zero(addr, sizeof(IPV6_ADDR));\r
+               return false;\r
+       }\r
+\r
+       if (IsIP6(ip) == false)\r
+       {\r
+               Zero(addr, sizeof(IPV6_ADDR));\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < 16;i++)\r
+       {\r
+               addr->Value[i] = ip->ipv6_addr[i];\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// IPv6 アドレスをセットする\r
+void SetIP6(IP *ip, UCHAR *value)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(ip, sizeof(IP));\r
+\r
+       ip->addr[0] = 223;\r
+       ip->addr[1] = 255;\r
+       ip->addr[2] = 255;\r
+       ip->addr[3] = 254;\r
+\r
+       if (value != NULL)\r
+       {\r
+               UINT i;\r
+\r
+               for (i = 0;i < 16;i++)\r
+               {\r
+                       ip->ipv6_addr[i] = value[i];\r
+               }\r
+       }\r
+}\r
+\r
+// 指定されたアドレスが IPv6 アドレスかどうかチェックする\r
+bool IsIP6(IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ip->addr[0] == 223 && ip->addr[1] == 255 && ip->addr[2] == 255 && ip->addr[3] == 254)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+bool IsIP4(IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return (IsIP6(ip) ? false : true);\r
+}\r
+\r
+// IPv6 のサブネット長をチェック\r
+bool CheckSubnetLength6(UINT i)\r
+{\r
+       if (i >= 1 && i <= 127)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// ソケットから対応する TCP コネクションのプロセス ID を取得\r
+UINT GetTcpProcessIdFromSocket(SOCK *s)\r
+{\r
+       LIST *o;\r
+       TCPTABLE *t;\r
+       UINT pid = 0;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       o = GetTcpTableList();\r
+       if (o == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       t = GetTcpTableFromEndPoint(o, &s->LocalIP, s->LocalPort,\r
+               &s->RemoteIP, s->RemotePort);\r
+\r
+       if (t != NULL)\r
+       {\r
+               pid = t->ProcessId;\r
+       }\r
+\r
+       FreeTcpTableList(o);\r
+\r
+       return pid;\r
+}\r
+UINT GetTcpProcessIdFromSocketReverse(SOCK *s)\r
+{\r
+       LIST *o;\r
+       TCPTABLE *t;\r
+       UINT pid = 0;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       o = GetTcpTableList();\r
+       if (o == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       t = GetTcpTableFromEndPoint(o, &s->RemoteIP, s->RemotePort,\r
+               &s->LocalIP, s->LocalPort);\r
+\r
+       if (t != NULL)\r
+       {\r
+               pid = t->ProcessId;\r
+       }\r
+\r
+       FreeTcpTableList(o);\r
+\r
+       return pid;\r
+}\r
+\r
+// エンドポイントから TCP テーブルを検索\r
+TCPTABLE *GetTcpTableFromEndPoint(LIST *o, IP *local_ip, UINT local_port, IP *remote_ip, UINT remote_port)\r
+{\r
+       IP local;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       SetIP(&local, 127, 0, 0, 1);\r
+\r
+       if (local_ip == NULL)\r
+       {\r
+               local_ip = &local;\r
+       }\r
+\r
+       if (remote_ip == NULL)\r
+       {\r
+               remote_ip = &local;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               TCPTABLE *t = LIST_DATA(o, i);\r
+\r
+               if (t->Status == TCP_STATE_SYN_SENT || t->Status == TCP_STATE_SYN_RCVD ||\r
+                       t->Status == TCP_STATE_ESTAB)\r
+               {\r
+                       if (CmpIpAddr(&t->LocalIP, local_ip) == 0)\r
+                       {\r
+                               if (CmpIpAddr(&t->RemoteIP, remote_ip) == 0)\r
+                               {\r
+                                       if (t->LocalPort == local_port)\r
+                                       {\r
+                                               if (t->RemotePort == remote_port)\r
+                                               {\r
+                                                       return t;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// TCP テーブルリストを取得 (Win32)\r
+#ifdef OS_WIN32\r
+LIST *Win32GetTcpTableList()\r
+{\r
+       LIST *o;\r
+\r
+       // Windows XP SP2 以降用\r
+       o = Win32GetTcpTableListByGetExtendedTcpTable();\r
+       if (o != NULL)\r
+       {\r
+               return o;\r
+       }\r
+\r
+       // Windows XP 以降用\r
+       o = Win32GetTcpTableListByAllocateAndGetTcpExTableFromStack();\r
+       if (o != NULL)\r
+       {\r
+               return o;\r
+       }\r
+\r
+       // 古い Windows 用\r
+       return Win32GetTcpTableListByGetTcpTable();\r
+}\r
+\r
+// TCP テーブルリストを取得: Windows XP SP2 以降用\r
+LIST *Win32GetTcpTableListByGetExtendedTcpTable()\r
+{\r
+       UINT need_size;\r
+       UINT i;\r
+       MIB_TCPTABLE_OWNER_PID *table;\r
+       bool ok = false;\r
+       LIST *o;\r
+       if (w32net->GetExtendedTcpTable == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < 128;i++)\r
+       {\r
+               UINT ret;\r
+               table = MallocFast(sizeof(MIB_TCPTABLE_OWNER_PID));\r
+               need_size = sizeof(MIB_TCPTABLE_OWNER_PID);\r
+               ret = w32net->GetExtendedTcpTable(table, &need_size, true, AF_INET, _TCP_TABLE_OWNER_PID_ALL, 0);\r
+               if (ret == NO_ERROR)\r
+               {\r
+                       ok = true;\r
+                       break;\r
+               }\r
+               else\r
+               {\r
+                       Free(table);\r
+                       if (ret != ERROR_INSUFFICIENT_BUFFER)\r
+                       {\r
+                               return NULL;\r
+                       }\r
+               }\r
+\r
+               table = MallocFast(need_size);\r
+\r
+               ret = w32net->GetExtendedTcpTable(table, &need_size, true, AF_INET, _TCP_TABLE_OWNER_PID_ALL, 0);\r
+               if (ret == NO_ERROR)\r
+               {\r
+                       ok = true;\r
+                       break;\r
+               }\r
+               else\r
+               {\r
+                       Free(table);\r
+\r
+                       if (ret != ERROR_INSUFFICIENT_BUFFER)\r
+                       {\r
+                               return NULL;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (ok == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListEx(NULL, true);\r
+\r
+       for (i = 0;i < table->dwNumEntries;i++)\r
+       {\r
+               MIB_TCPROW_OWNER_PID *r = &table->table[i];\r
+               TCPTABLE *t = ZeroMallocFast(sizeof(TCPTABLE));\r
+\r
+               UINTToIP(&t->LocalIP, r->dwLocalAddr);\r
+               t->LocalPort = Endian16((USHORT)r->dwLocalPort);\r
+\r
+               if (r->dwState != TCP_STATE_LISTEN)\r
+               {\r
+                       UINTToIP(&t->RemoteIP, r->dwRemoteAddr);\r
+                       t->RemotePort = Endian16((USHORT)r->dwRemotePort);\r
+               }\r
+\r
+               t->Status = r->dwState;\r
+               t->ProcessId = r->dwOwningPid;\r
+\r
+               Add(o, t);\r
+       }\r
+\r
+       Free(table);\r
+\r
+       return o;\r
+}\r
+\r
+// TCP テーブルリストを取得: Windows XP 以降用\r
+LIST *Win32GetTcpTableListByAllocateAndGetTcpExTableFromStack()\r
+{\r
+       HANDLE heap;\r
+       UINT i;\r
+       MIB_TCPTABLE_OWNER_PID *table;\r
+       bool ok = false;\r
+       LIST *o;\r
+       if (w32net->AllocateAndGetTcpExTableFromStack == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       heap = GetProcessHeap();\r
+\r
+       if (w32net->AllocateAndGetTcpExTableFromStack(&table, true, heap, HEAP_GROWABLE, AF_INET) != ERROR_SUCCESS)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListEx(NULL, true);\r
+\r
+       for (i = 0;i < table->dwNumEntries;i++)\r
+       {\r
+               MIB_TCPROW_OWNER_PID *r = &table->table[i];\r
+               TCPTABLE *t = ZeroMallocFast(sizeof(TCPTABLE));\r
+\r
+               UINTToIP(&t->LocalIP, r->dwLocalAddr);\r
+               t->LocalPort = Endian16((USHORT)r->dwLocalPort);\r
+\r
+               if (r->dwState != TCP_STATE_LISTEN)\r
+               {\r
+                       UINTToIP(&t->RemoteIP, r->dwRemoteAddr);\r
+                       t->RemotePort = Endian16((USHORT)r->dwRemotePort);\r
+               }\r
+\r
+               t->ProcessId = r->dwOwningPid;\r
+               t->Status = r->dwState;\r
+\r
+               Add(o, t);\r
+       }\r
+\r
+       HeapFree(heap, 0, table);\r
+\r
+       return o;\r
+}\r
+\r
+// TCP テーブルリストを取得: 古い Windows 用\r
+LIST *Win32GetTcpTableListByGetTcpTable()\r
+{\r
+       UINT need_size;\r
+       UINT i;\r
+       MIB_TCPTABLE *table;\r
+       bool ok = false;\r
+       LIST *o;\r
+       if (w32net->GetTcpTable == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < 128;i++)\r
+       {\r
+               UINT ret;\r
+               table = MallocFast(sizeof(MIB_TCPTABLE));\r
+               need_size = sizeof(MIB_TCPTABLE);\r
+               ret = w32net->GetTcpTable(table, &need_size, true);\r
+               if (ret == NO_ERROR)\r
+               {\r
+                       ok = true;\r
+                       break;\r
+               }\r
+               else\r
+               {\r
+                       Free(table);\r
+                       if (ret != ERROR_INSUFFICIENT_BUFFER)\r
+                       {\r
+                               return NULL;\r
+                       }\r
+               }\r
+\r
+               table = MallocFast(need_size);\r
+\r
+               ret = w32net->GetTcpTable(table, &need_size, true);\r
+               if (ret == NO_ERROR)\r
+               {\r
+                       ok = true;\r
+                       break;\r
+               }\r
+               else\r
+               {\r
+                       Free(table);\r
+\r
+                       if (ret != ERROR_INSUFFICIENT_BUFFER)\r
+                       {\r
+                               return NULL;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (ok == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListEx(NULL, true);\r
+\r
+       for (i = 0;i < table->dwNumEntries;i++)\r
+       {\r
+               MIB_TCPROW *r = &table->table[i];\r
+               TCPTABLE *t = ZeroMallocFast(sizeof(TCPTABLE));\r
+\r
+               UINTToIP(&t->LocalIP, r->dwLocalAddr);\r
+               t->LocalPort = Endian16((USHORT)r->dwLocalPort);\r
+\r
+               if (r->dwState != TCP_STATE_LISTEN)\r
+               {\r
+                       UINTToIP(&t->RemoteIP, r->dwRemoteAddr);\r
+                       t->RemotePort = Endian16((USHORT)r->dwRemotePort);\r
+               }\r
+\r
+               t->Status = r->dwState;\r
+\r
+               Add(o, t);\r
+       }\r
+\r
+       Free(table);\r
+\r
+       return o;\r
+}\r
+\r
+#endif // OS_WIN32\r
+\r
+// TCP テーブルの表示\r
+void PrintTcpTableList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               Print("o == NULL\n\n");\r
+               return;\r
+       }\r
+\r
+       Print("--- TCPTABLE: %u Entries ---\n", LIST_NUM(o));\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               char tmp1[MAX_PATH], tmp2[MAX_PATH];\r
+               TCPTABLE *t = LIST_DATA(o, i);\r
+\r
+               IPToStr(tmp1, sizeof(tmp1), &t->LocalIP);\r
+               IPToStr(tmp2, sizeof(tmp2), &t->RemoteIP);\r
+\r
+               Print("%s:%u <--> %s:%u  state=%u  pid=%u\n",\r
+                       tmp1, t->LocalPort,\r
+                       tmp2, t->RemotePort,\r
+                       t->Status,\r
+                       t->ProcessId);\r
+       }\r
+       Print("------\n\n");\r
+}\r
+\r
+// TCP テーブルの比較\r
+int CompareTcpTable(void *p1, void *p2)\r
+{\r
+       TCPTABLE *t1, *t2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       t1 = *(TCPTABLE **)p1;\r
+       t2 = *(TCPTABLE **)p2;\r
+       if (t1 == NULL || t2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return Cmp(t1, t2, sizeof(TCPTABLE));\r
+}\r
+\r
+// TCP テーブルリストを取得\r
+LIST *GetTcpTableList()\r
+{\r
+#ifdef OS_WIN32\r
+       return Win32GetTcpTableList();\r
+#else  // OS_WIN32\r
+       return NULL;\r
+#endif // OS_WIN32\r
+}\r
+\r
+// TCP テーブルリストを解放\r
+void FreeTcpTableList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               TCPTABLE *t = LIST_DATA(o, i);\r
+\r
+               Free(t);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// 指定された IP アドレスから接続中のクライアント数の取得\r
+UINT GetNumIpClient(IP *ip)\r
+{\r
+       IP_CLIENT *c;\r
+       UINT ret = 0;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       LockList(ip_clients);\r
+       {\r
+               c = SearchIpClient(ip);\r
+\r
+               if (c != NULL)\r
+               {\r
+                       ret = c->NumConnections;\r
+               }\r
+       }\r
+       UnlockList(ip_clients);\r
+\r
+       return ret;\r
+}\r
+\r
+// IP クライアントエントリに追加\r
+void AddIpClient(IP *ip)\r
+{\r
+       IP_CLIENT *c;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(ip_clients);\r
+       {\r
+               c = SearchIpClient(ip);\r
+\r
+               if (c == NULL)\r
+               {\r
+                       c = ZeroMallocFast(sizeof(IP_CLIENT));\r
+                       Copy(&c->IpAddress, ip, sizeof(IP));\r
+                       c->NumConnections = 0;\r
+\r
+                       Add(ip_clients, c);\r
+               }\r
+\r
+               c->NumConnections++;\r
+       }\r
+       UnlockList(ip_clients);\r
+}\r
+\r
+// IP クライアントリストから削除\r
+void DelIpClient(IP *ip)\r
+{\r
+       IP_CLIENT *c;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(ip_clients);\r
+       {\r
+               c = SearchIpClient(ip);\r
+\r
+               if (c != NULL)\r
+               {\r
+                       c->NumConnections--;\r
+\r
+                       if (c->NumConnections == 0)\r
+                       {\r
+                               Delete(ip_clients, c);\r
+                               Free(c);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(ip_clients);\r
+}\r
+\r
+// IP クライアントエントリの検索\r
+IP_CLIENT *SearchIpClient(IP *ip)\r
+{\r
+       IP_CLIENT t;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+       Copy(&t.IpAddress, ip, sizeof(IP));\r
+\r
+       return Search(ip_clients, &t);\r
+}\r
+\r
+// クライアントリストの初期化\r
+void InitIpClientList()\r
+{\r
+       ip_clients = NewList(CompareIpClientList);\r
+}\r
+\r
+// クライアントリストの解放\r
+void FreeIpClientList()\r
+{\r
+       UINT i;\r
+\r
+       for (i = 0;i < LIST_NUM(ip_clients);i++)\r
+       {\r
+               IP_CLIENT *c = LIST_DATA(ip_clients, i);\r
+\r
+               Free(c);\r
+       }\r
+\r
+       ReleaseList(ip_clients);\r
+       ip_clients = NULL;\r
+}\r
+\r
+// クライアントリストエントリの比較\r
+int CompareIpClientList(void *p1, void *p2)\r
+{\r
+       IP_CLIENT *c1, *c2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       c1 = *(IP_CLIENT **)p1;\r
+       c2 = *(IP_CLIENT **)p2;\r
+       if (c1 == NULL || c2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return CmpIpAddr(&c1->IpAddress, &c2->IpAddress);\r
+}\r
+\r
+// MAC アドレスの正規化\r
+bool NormalizeMacAddress(char *dst, UINT size, char *src)\r
+{\r
+       BUF *b;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = StrToBin(src);\r
+\r
+       if (b != NULL && b->Size == 6)\r
+       {\r
+               ret = true;\r
+\r
+               BinToStr(dst, size, b->Buf, b->Size);\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// IP アドレスが空かどうか識別する\r
+bool IsZeroIP(IP *ip)\r
+{\r
+       return IsZeroIp(ip);\r
+}\r
+bool IsZeroIp(IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (IsIP6(ip) == false)\r
+       {\r
+               return IsZero(ip->addr, sizeof(ip->addr));\r
+       }\r
+       else\r
+       {\r
+               return IsZero(ip->ipv6_addr, sizeof(ip->ipv6_addr));\r
+       }\r
+}\r
+bool IsZeroIP6Addr(IPV6_ADDR *addr)\r
+{\r
+       // 引数チェック\r
+       if (addr == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return IsZero(addr, sizeof(IPV6_ADDR));\r
+}\r
+\r
+// 指定された IP アドレスがホストとして意味があるかどうかを調べる\r
+bool IsHostIPAddress4(IP *ip)\r
+{\r
+       UINT a;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       a = IPToUINT(ip);\r
+\r
+       if (a == 0 || a == 0xffffffff)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+bool IsHostIPAddress32(UINT ip)\r
+{\r
+       IP p;\r
+\r
+       UINTToIP(&p, ip);\r
+\r
+       return IsHostIPAddress4(&p);\r
+}\r
+\r
+// 指定された IP アドレスとサブネットマスクが正しくネットワークを示すかどうか調べる\r
+bool IsNetworkAddress(IP *ip, IP *mask)\r
+{\r
+       if (IsIP4(ip))\r
+       {\r
+               return IsNetworkAddress4(ip, mask);\r
+       }\r
+       else\r
+       {\r
+               return IsNetworkAddress6(ip, mask);\r
+       }\r
+}\r
+bool IsNetworkAddress4(IP *ip, IP *mask)\r
+{\r
+       UINT a, b;\r
+       // 引数チェック\r
+       if (ip == NULL || mask == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsIP4(ip) == false || IsIP4(mask) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsSubnetMask4(mask) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       a = IPToUINT(ip);\r
+       b = IPToUINT(mask);\r
+\r
+       if ((a & b) == a)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+bool IsNetworkAddress32(UINT ip, UINT mask)\r
+{\r
+       IP a, b;\r
+\r
+       UINTToIP(&a, ip);\r
+       UINTToIP(&b, mask);\r
+\r
+       return IsNetworkAddress4(&a, &b);\r
+}\r
+\r
+// 整数をサブネットマスクに変換する\r
+UINT IntToSubnetMask32(UINT i)\r
+{\r
+       UINT ret = 0xFFFFFFFF;\r
+\r
+       // 汚いコード\r
+       switch (i)\r
+       {\r
+       case 0:         ret = 0x00000000;       break;\r
+       case 1:         ret = 0x80000000;       break;\r
+       case 2:         ret = 0xC0000000;       break;\r
+       case 3:         ret = 0xE0000000;       break;\r
+       case 4:         ret = 0xF0000000;       break;\r
+       case 5:         ret = 0xF8000000;       break;\r
+       case 6:         ret = 0xFC000000;       break;\r
+       case 7:         ret = 0xFE000000;       break;\r
+       case 8:         ret = 0xFF000000;       break;\r
+       case 9:         ret = 0xFF800000;       break;\r
+       case 10:        ret = 0xFFC00000;       break;\r
+       case 11:        ret = 0xFFE00000;       break;\r
+       case 12:        ret = 0xFFF00000;       break;\r
+       case 13:        ret = 0xFFF80000;       break;\r
+       case 14:        ret = 0xFFFC0000;       break;\r
+       case 15:        ret = 0xFFFE0000;       break;\r
+       case 16:        ret = 0xFFFF0000;       break;\r
+       case 17:        ret = 0xFFFF8000;       break;\r
+       case 18:        ret = 0xFFFFC000;       break;\r
+       case 19:        ret = 0xFFFFE000;       break;\r
+       case 20:        ret = 0xFFFFF000;       break;\r
+       case 21:        ret = 0xFFFFF800;       break;\r
+       case 22:        ret = 0xFFFFFC00;       break;\r
+       case 23:        ret = 0xFFFFFE00;       break;\r
+       case 24:        ret = 0xFFFFFF00;       break;\r
+       case 25:        ret = 0xFFFFFF80;       break;\r
+       case 26:        ret = 0xFFFFFFC0;       break;\r
+       case 27:        ret = 0xFFFFFFE0;       break;\r
+       case 28:        ret = 0xFFFFFFF0;       break;\r
+       case 29:        ret = 0xFFFFFFF8;       break;\r
+       case 30:        ret = 0xFFFFFFFC;       break;\r
+       case 31:        ret = 0xFFFFFFFE;       break;\r
+       case 32:        ret = 0xFFFFFFFF;       break;\r
+       }\r
+\r
+       if (IsLittleEndian())\r
+       {\r
+               ret = Swap32(ret);\r
+       }\r
+\r
+       return ret;\r
+}\r
+void IntToSubnetMask4(IP *ip, UINT i)\r
+{\r
+       UINT m;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       m = IntToSubnetMask32(i);\r
+\r
+       UINTToIP(ip, m);\r
+}\r
+\r
+// 指定された IP アドレスがサブネットマスクかどうか調べる\r
+bool IsSubnetMask(IP *ip)\r
+{\r
+       if (IsIP6(ip))\r
+       {\r
+               return IsSubnetMask6(ip);\r
+       }\r
+       else\r
+       {\r
+               return IsSubnetMask4(ip);\r
+       }\r
+}\r
+bool IsSubnetMask4(IP *ip)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsIP6(ip))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       i = IPToUINT(ip);\r
+\r
+       if (IsLittleEndian())\r
+       {\r
+               i = Swap32(i);\r
+       }\r
+\r
+       // 汚いコード\r
+       switch (i)\r
+       {\r
+       case 0x00000000:\r
+       case 0x80000000:\r
+       case 0xC0000000:\r
+       case 0xE0000000:\r
+       case 0xF0000000:\r
+       case 0xF8000000:\r
+       case 0xFC000000:\r
+       case 0xFE000000:\r
+       case 0xFF000000:\r
+       case 0xFF800000:\r
+       case 0xFFC00000:\r
+       case 0xFFE00000:\r
+       case 0xFFF00000:\r
+       case 0xFFF80000:\r
+       case 0xFFFC0000:\r
+       case 0xFFFE0000:\r
+       case 0xFFFF0000:\r
+       case 0xFFFF8000:\r
+       case 0xFFFFC000:\r
+       case 0xFFFFE000:\r
+       case 0xFFFFF000:\r
+       case 0xFFFFF800:\r
+       case 0xFFFFFC00:\r
+       case 0xFFFFFE00:\r
+       case 0xFFFFFF00:\r
+       case 0xFFFFFF80:\r
+       case 0xFFFFFFC0:\r
+       case 0xFFFFFFE0:\r
+       case 0xFFFFFFF0:\r
+       case 0xFFFFFFF8:\r
+       case 0xFFFFFFFC:\r
+       case 0xFFFFFFFE:\r
+       case 0xFFFFFFFF:\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+bool IsSubnetMask32(UINT ip)\r
+{\r
+       IP p;\r
+\r
+       UINTToIP(&p, ip);\r
+\r
+       return IsSubnetMask4(&p);\r
+}\r
+\r
+// ネットワークリリースモード\r
+void SetNetworkReleaseMode()\r
+{\r
+       NetworkReleaseMode = true;\r
+}\r
+\r
+#ifdef OS_UNIX                 // UNIX 用コード\r
+\r
+// ソケットをノンブロッキングモードにしたり解除したりする\r
+void UnixSetSocketNonBlockingMode(int fd, bool nonblock)\r
+{\r
+       UINT flag = 0;\r
+       // 引数チェック\r
+       if (fd == INVALID_SOCKET)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (nonblock)\r
+       {\r
+               flag = 1;\r
+       }\r
+\r
+#ifdef FIONBIO\r
+       ioctl(fd, FIONBIO, &flag);\r
+#else  // FIONBIO\r
+       {\r
+               int flag = fcntl(fd, F_GETFL, 0);\r
+               if (flag != -1)\r
+               {\r
+                       if (nonblock)\r
+                       {\r
+                               flag |= O_NONBLOCK;\r
+                       }\r
+                       else\r
+                       {\r
+                               flag = flag & ~O_NONBLOCK;\r
+\r
+                               fcntl(fd, F_SETFL, flag);\r
+                       }\r
+               }\r
+       }\r
+#endif // FIONBIO\r
+}\r
+\r
+// 何もしない\r
+void UnixIpForwardRowToRouteEntry(ROUTE_ENTRY *entry, void *ip_forward_row)\r
+{\r
+}\r
+\r
+// 何もしない\r
+void UnixRouteEntryToIpForwardRow(void *ip_forward_row, ROUTE_ENTRY *entry)\r
+{\r
+}\r
+\r
+// 何もしない\r
+int UnixCompareRouteEntryByMetric(void *p1, void *p2)\r
+{\r
+       return 1;\r
+}\r
+\r
+// 何もしない\r
+ROUTE_TABLE *UnixGetRouteTable()\r
+{\r
+       ROUTE_TABLE *ret = ZeroMalloc(sizeof(ROUTE_TABLE));\r
+       ret->NumEntry = 0;\r
+       ret->Entry = ZeroMalloc(0);\r
+\r
+       return ret;\r
+}\r
+\r
+// 何もしない\r
+bool UnixAddRouteEntry(ROUTE_ENTRY *e, bool *already_exists)\r
+{\r
+       return true;\r
+}\r
+\r
+// 何もしない\r
+void UnixDeleteRouteEntry(ROUTE_ENTRY *e)\r
+{\r
+       return;\r
+}\r
+\r
+// 何もしない\r
+UINT UnixGetVLanInterfaceID(char *instance_name)\r
+{\r
+       return 1;\r
+}\r
+\r
+// 何もしない\r
+char **UnixEnumVLan(char *tag_name)\r
+{\r
+       char **list;\r
+\r
+       list = ZeroMalloc(sizeof(char *));\r
+\r
+       return list;\r
+}\r
+\r
+// 何もしない\r
+void UnixRenewDhcp()\r
+{\r
+}\r
+\r
+// デフォルトの DNS サーバーの IP アドレスを取得\r
+bool UnixGetDefaultDns(IP *ip)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Lock(unix_dns_server_addr_lock);\r
+       {\r
+               if (IsZero(&unix_dns_server, sizeof(IP)) == false)\r
+               {\r
+                       Copy(ip, &unix_dns_server, sizeof(IP));\r
+                       Unlock(unix_dns_server_addr_lock);\r
+                       return true;\r
+               }\r
+\r
+               ip->addr[0] = 127;\r
+               ip->addr[1] = 0;\r
+               ip->addr[2] = 0;\r
+               ip->addr[3] = 1;\r
+\r
+               b = ReadDump("/etc/resolv.conf");\r
+               if (b != NULL)\r
+               {\r
+                       char *s;\r
+                       bool f = false;\r
+                       while ((s = CfgReadNextLine(b)) != NULL)\r
+                       {\r
+                               TOKEN_LIST *t = ParseToken(s, "\" \t,");\r
+                               if (t->NumTokens == 2)\r
+                               {\r
+                                       if (StrCmpi(t->Token[0], "nameserver") == 0)\r
+                                       {\r
+                                               StrToIP(ip, t->Token[1]);\r
+                                               f = true;\r
+                                       }\r
+                               }\r
+                               FreeToken(t);\r
+\r
+                               Free(s);\r
+\r
+                               if (f)\r
+                               {\r
+                                       break;\r
+                               }\r
+                       }\r
+                       FreeBuf(b);\r
+               }\r
+               Copy(&unix_dns_server, ip, sizeof(IP));\r
+       }\r
+       Unlock(unix_dns_server_addr_lock);\r
+\r
+       return true;\r
+}\r
+\r
+\r
+// Select 処理\r
+void UnixSelect(SOCKSET *set, UINT timeout, CANCEL *c1, CANCEL *c2)\r
+{\r
+       UINT reads[MAXIMUM_WAIT_OBJECTS];\r
+       UINT writes[MAXIMUM_WAIT_OBJECTS];\r
+       UINT num_read, num_write, i;\r
+       UINT p1, p2;\r
+       SOCK *s;\r
+       UCHAR tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (timeout == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 配列の初期化\r
+       Zero(reads, sizeof(reads));\r
+       Zero(writes, sizeof(writes));\r
+       num_read = num_write = 0;\r
+\r
+       // イベント配列の設定\r
+       if (set != NULL)\r
+       {\r
+               for (i = 0;i < set->NumSocket;i++)\r
+               {\r
+                       s = set->Sock[i];\r
+                       if (s != NULL)\r
+                       {\r
+                               UnixInitAsyncSocket(s);\r
+                               reads[num_read++] = s->socket;\r
+                               if (s->WriteBlocked)\r
+                               {\r
+                                       writes[num_write++] = s->socket;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       p1 = p2 = -1;\r
+\r
+       if (c1 != NULL)\r
+       {\r
+               reads[num_read++] = p1 = c1->pipe_read;\r
+       }\r
+       if (c2 != NULL)\r
+       {\r
+               reads[num_read++] = p2 = c2->pipe_read;\r
+       }\r
+\r
+       // select を呼び出す\r
+       UnixSelectInner(num_read, reads, num_write, writes, timeout);\r
+\r
+       // pipe から読んでおく\r
+       if (c1 != NULL && c1->SpecialFlag == false && p1 != -1)\r
+       {\r
+               read(p1, tmp, sizeof(tmp));\r
+       }\r
+       if (c2 != NULL && c2->SpecialFlag == false && p2 != -1)\r
+       {\r
+               read(p2, tmp, sizeof(tmp));\r
+       }\r
+}\r
+\r
+// キャンセル\r
+void UnixCancel(CANCEL *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UnixWritePipe(c->pipe_write);\r
+}\r
+\r
+// キャンセルオブジェクトの解放\r
+void UnixCleanupCancel(CANCEL *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (c->SpecialFlag == false)\r
+       {\r
+               UnixDeletePipe(c->pipe_read, c->pipe_write);\r
+       }\r
+\r
+       Free(c);\r
+}\r
+\r
+// 新しいキャンセルオブジェクトの作成\r
+CANCEL *UnixNewCancel()\r
+{\r
+       CANCEL *c = ZeroMallocFast(sizeof(CANCEL));\r
+\r
+       c->ref = NewRef();\r
+       c->SpecialFlag = false;\r
+\r
+       UnixNewPipe(&c->pipe_read, &c->pipe_write);\r
+\r
+       return c;\r
+}\r
+\r
+// ソケットをソケットイベントに追加する\r
+void UnixJoinSockToSockEvent(SOCK *sock, SOCK_EVENT *event)\r
+{\r
+       // 引数チェック\r
+       if (sock == NULL || event == NULL || sock->AsyncMode)\r
+       {\r
+               return;\r
+       }\r
+       if (sock->ListenMode != false || (sock->Type == SOCK_TCP && sock->Connected == false))\r
+       {\r
+               return;\r
+       }\r
+\r
+       sock->AsyncMode = true;\r
+\r
+       LockList(event->SockList);\r
+       {\r
+               Add(event->SockList, sock);\r
+               AddRef(sock->ref);\r
+       }\r
+       UnlockList(event->SockList);\r
+\r
+       // ソケットを非同期にする\r
+       UnixSetSocketNonBlockingMode(sock->socket, true);\r
+\r
+       // SOCK_EVENT の参照カウンタを増加\r
+       AddRef(event->ref);\r
+       sock->SockEvent = event;\r
+\r
+       // ソケットイベントを叩く\r
+       SetSockEvent(event);\r
+}\r
+\r
+// ソケットイベントを待機する\r
+bool UnixWaitSockEvent(SOCK_EVENT *event, UINT timeout)\r
+{\r
+       UINT num_read, num_write;\r
+       UINT *reads, *writes;\r
+       UINT n;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (event == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       LockList(event->SockList);\r
+       {\r
+               UINT i;\r
+               num_read = LIST_NUM(event->SockList) + 1;\r
+               reads = ZeroMallocFast(sizeof(SOCK *) * num_read);\r
+\r
+               num_write = 0;\r
+\r
+               for (i = 0;i < (num_read - 1);i++)\r
+               {\r
+                       SOCK *s = LIST_DATA(event->SockList, i);\r
+                       reads[i] = s->socket;\r
+                       if (s->WriteBlocked)\r
+                       {\r
+                               num_write++;\r
+                       }\r
+               }\r
+\r
+               reads[num_read - 1] = event->pipe_read;\r
+\r
+               writes = ZeroMallocFast(sizeof(SOCK *) * num_write);\r
+\r
+               n = 0;\r
+\r
+               for (i = 0;i < (num_read - 1);i++)\r
+               {\r
+                       SOCK *s = LIST_DATA(event->SockList, i);\r
+                       if (s->WriteBlocked)\r
+                       {\r
+                               writes[n++] = s->socket;\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(event->SockList);\r
+\r
+       if (0)\r
+       {\r
+               UINT i;\r
+               Print("UnixSelectInner: ");\r
+               for (i = 0;i < num_read;i++)\r
+               {\r
+                       Print("%u ", reads[i]);\r
+               }\r
+               Print("\n");\r
+       }\r
+\r
+       UnixSelectInner(num_read, reads, num_write, writes, timeout);\r
+\r
+       read(event->pipe_read, tmp, sizeof(tmp));\r
+\r
+       Free(reads);\r
+       Free(writes);\r
+\r
+       return true;\r
+}\r
+\r
+// ソケットイベントをセットする\r
+void UnixSetSockEvent(SOCK_EVENT *event)\r
+{\r
+       // 引数チェック\r
+       if (event == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UnixWritePipe(event->pipe_write);\r
+}\r
+\r
+// ソケットの select の実行\r
+void UnixSelectInner(UINT num_read, UINT *reads, UINT num_write, UINT *writes, UINT timeout)\r
+{\r
+       struct pollfd *p;\r
+       UINT num;\r
+       UINT i;\r
+       UINT n;\r
+       UINT num_read_total, num_write_total;\r
+\r
+       if (num_read != 0 && reads == NULL)\r
+       {\r
+               num_read = 0;\r
+       }\r
+       if (num_write != 0 && writes == NULL)\r
+       {\r
+               num_write = 0;\r
+       }\r
+\r
+       if (timeout == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       num_read_total = num_write_total = 0;\r
+       for (i = 0;i < num_read;i++)\r
+       {\r
+               if (reads[i] != INVALID_SOCKET)\r
+               {\r
+                       num_read_total++;\r
+               }\r
+       }\r
+       for (i = 0;i < num_write;i++)\r
+       {\r
+               if (writes[i] != INVALID_SOCKET)\r
+               {\r
+                       num_write_total++;\r
+               }\r
+       }\r
+\r
+       num = num_read_total + num_write_total;\r
+       p = ZeroMallocFast(sizeof(struct pollfd) * num);\r
+\r
+       n = 0;\r
+\r
+       for (i = 0;i < num_read;i++)\r
+       {\r
+               if (reads[i] != INVALID_SOCKET)\r
+               {\r
+                       struct pollfd *pfd = &p[n++];\r
+                       pfd->fd = reads[i];\r
+                       pfd->events = POLLIN | POLLPRI | POLLERR | POLLHUP;\r
+               }\r
+       }\r
+\r
+       for (i = 0;i < num_write;i++)\r
+       {\r
+               if (writes[i] != INVALID_SOCKET)\r
+               {\r
+                       struct pollfd *pfd = &p[n++];\r
+                       pfd->fd = writes[i];\r
+                       pfd->events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLOUT;\r
+               }\r
+       }\r
+\r
+       if (num != 0)\r
+       {\r
+               poll(p, num, timeout == INFINITE ? -1 : (int)timeout);\r
+       }\r
+       else\r
+       {\r
+               SleepThread(timeout);\r
+       }\r
+\r
+       Free(p);\r
+}\r
+\r
+// ソケットイベントのクリーンアップ\r
+void UnixCleanupSockEvent(SOCK_EVENT *event)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (event == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(event->SockList);i++)\r
+       {\r
+               SOCK *s = LIST_DATA(event->SockList, i);\r
+\r
+               ReleaseSock(s);\r
+       }\r
+\r
+       ReleaseList(event->SockList);\r
+\r
+       UnixDeletePipe(event->pipe_read, event->pipe_write);\r
+\r
+       Free(event);\r
+}\r
+\r
+// ソケットイベントを作成する\r
+SOCK_EVENT *UnixNewSockEvent()\r
+{\r
+       SOCK_EVENT *e = ZeroMallocFast(sizeof(SOCK_EVENT));\r
+\r
+       e->SockList = NewList(NULL);\r
+       e->ref = NewRef();\r
+\r
+       UnixNewPipe(&e->pipe_read, &e->pipe_write);\r
+\r
+       return e;\r
+}\r
+\r
+// パイプを閉じる\r
+void UnixDeletePipe(int p1, int p2)\r
+{\r
+       if (p1 != -1)\r
+       {\r
+               close(p1);\r
+       }\r
+\r
+       if (p2 != -1)\r
+       {\r
+               close(p2);\r
+       }\r
+}\r
+\r
+// パイプに書き込む\r
+void UnixWritePipe(int pipe_write)\r
+{\r
+       char c = 1;\r
+       write(pipe_write, &c, 1);\r
+}\r
+\r
+// 新しいパイプを作成する\r
+void UnixNewPipe(int *pipe_read, int *pipe_write)\r
+{\r
+       int fd[2];\r
+       // 引数チェック\r
+       if (pipe_read == NULL || pipe_write == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       fd[0] = fd[1] = 0;\r
+\r
+       pipe(fd);\r
+\r
+       *pipe_read = fd[0];\r
+       *pipe_write = fd[1];\r
+\r
+       UnixSetSocketNonBlockingMode(*pipe_write, true);\r
+       UnixSetSocketNonBlockingMode(*pipe_read, true);\r
+}\r
+\r
+// 非同期ソケットの解放\r
+void UnixFreeAsyncSocket(SOCK *sock)\r
+{\r
+       UINT p;\r
+       // 引数チェック\r
+       if (sock == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(sock->lock);\r
+       {\r
+               if (sock->AsyncMode == false)\r
+               {\r
+                       Unlock(sock->lock);\r
+                       return;\r
+               }\r
+\r
+               sock->AsyncMode = false;\r
+\r
+               // このソケットが SockEvent に関連付けられているかどうか調べる\r
+               if (sock->SockEvent != NULL)\r
+               {\r
+                       SOCK_EVENT *e = sock->SockEvent;\r
+\r
+                       AddRef(e->ref);\r
+\r
+                       p = e->pipe_write;\r
+                       LockList(e->SockList);\r
+                       {\r
+                               if (Delete(e->SockList, sock))\r
+                               {\r
+                                       ReleaseSock(sock);\r
+                               }\r
+                       }\r
+                       UnlockList(e->SockList);\r
+\r
+                       // ソケットイベントを解放する\r
+                       ReleaseSockEvent(sock->SockEvent);\r
+                       sock->SockEvent = NULL;\r
+\r
+                       SetSockEvent(e);\r
+\r
+                       ReleaseSockEvent(e);\r
+               }\r
+       }\r
+       Unlock(sock->lock);\r
+}\r
+\r
+// ソケットを非同期に設定する\r
+void UnixInitAsyncSocket(SOCK *sock)\r
+{\r
+       // 引数チェック\r
+       if (sock == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (sock->AsyncMode)\r
+       {\r
+               // すでに非同期ソケットになっている\r
+               return;\r
+       }\r
+       if (sock->ListenMode != false || (sock->Type == SOCK_TCP && sock->Connected == false))\r
+       {\r
+               return;\r
+       }\r
+\r
+       sock->AsyncMode = true;\r
+\r
+       UnixSetSocketNonBlockingMode(sock->socket, true);\r
+}\r
+\r
+// ソケットライブラリの初期化\r
+void UnixInitSocketLibrary()\r
+{\r
+       // 特に何もしない\r
+}\r
+\r
+// ソケットライブラリの解放\r
+void UnixFreeSocketLibrary()\r
+{\r
+       // 特に何もしない\r
+}\r
+\r
+#endif // OS_UNIX\r
+\r
+#ifdef OS_WIN32                // Windows 用コード\r
+\r
+NETWORK_WIN32_FUNCTIONS *w32net;\r
+\r
+// IP_ADAPTER_INDEX_MAP の比較\r
+int CompareIpAdapterIndexMap(void *p1, void *p2)\r
+{\r
+       IP_ADAPTER_INDEX_MAP *a1, *a2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       a1 = *(IP_ADAPTER_INDEX_MAP **)p1;\r
+       a2 = *(IP_ADAPTER_INDEX_MAP **)p2;\r
+       if (a1 == NULL || a2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (a1->Index > a2->Index)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (a1->Index < a2->Index)\r
+       {\r
+               return -1;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+// アダプタの IP アドレスを更新\r
+bool Win32RenewAddressByGuid(char *guid)\r
+{\r
+       IP_ADAPTER_INDEX_MAP a;\r
+       // 引数チェック\r
+       if (guid == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&a, sizeof(a));\r
+       if (Win32GetAdapterFromGuid(&a, guid) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return Win32RenewAddress(&a);\r
+}\r
+bool Win32RenewAddress(void *a)\r
+{\r
+       DWORD ret;\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (w32net->IpRenewAddress == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = w32net->IpRenewAddress(a);\r
+\r
+       if (ret == NO_ERROR)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               Debug("IpRenewAddress: Error: %u\n", ret);\r
+               return false;\r
+       }\r
+}\r
+\r
+// アダプタの IP アドレスを解放\r
+bool Win32ReleaseAddress(void *a)\r
+{\r
+       DWORD ret;\r
+       // 引数チェック\r
+       if (a == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (w32net->IpReleaseAddress == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = w32net->IpReleaseAddress(a);\r
+\r
+       if (ret == NO_ERROR)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               Debug("IpReleaseAddress: Error: %u\n", ret);\r
+               return false;\r
+       }\r
+}\r
+bool Win32ReleaseAddressByGuid(char *guid)\r
+{\r
+       IP_ADAPTER_INDEX_MAP a;\r
+       // 引数チェック\r
+       if (guid == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&a, sizeof(a));\r
+       if (Win32GetAdapterFromGuid(&a, guid) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return Win32ReleaseAddress(&a);\r
+}\r
+void Win32ReleaseAddressByGuidExThread(THREAD *t, void *param)\r
+{\r
+       WIN32_RELEASEADDRESS_THREAD_PARAM *p;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = (WIN32_RELEASEADDRESS_THREAD_PARAM *)param;\r
+\r
+       AddRef(p->Ref);\r
+\r
+       NoticeThreadInit(t);\r
+\r
+       AddWaitThread(t);\r
+\r
+       if (p->Renew == false)\r
+       {\r
+               p->Ok = Win32ReleaseAddressByGuid(p->Guid);\r
+       }\r
+       else\r
+       {\r
+               p->Ok = Win32RenewAddressByGuid(p->Guid);\r
+       }\r
+\r
+       ReleaseWin32ReleaseAddressByGuidThreadParam(p);\r
+\r
+       DelWaitThread(t);\r
+}\r
+bool Win32RenewAddressByGuidEx(char *guid, UINT timeout)\r
+{\r
+       return Win32ReleaseOrRenewAddressByGuidEx(guid, timeout, true);\r
+}\r
+bool Win32ReleaseAddressByGuidEx(char *guid, UINT timeout)\r
+{\r
+       return Win32ReleaseOrRenewAddressByGuidEx(guid, timeout, false);\r
+}\r
+bool Win32ReleaseOrRenewAddressByGuidEx(char *guid, UINT timeout, bool renew)\r
+{\r
+       THREAD *t;\r
+       WIN32_RELEASEADDRESS_THREAD_PARAM *p;\r
+       bool ret = false;\r
+       UINT64 start_tick = 0;\r
+       UINT64 end_tick = 0;\r
+       // 引数チェック\r
+       if (guid == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (timeout == 0)\r
+       {\r
+               timeout = INFINITE;\r
+       }\r
+\r
+       p = ZeroMalloc(sizeof(WIN32_RELEASEADDRESS_THREAD_PARAM));\r
+       p->Ref = NewRef();\r
+       StrCpy(p->Guid, sizeof(p->Guid), guid);\r
+       p->Timeout = timeout;\r
+       p->Renew = renew;\r
+\r
+       t = NewThread(Win32ReleaseAddressByGuidExThread, p);\r
+       WaitThreadInit(t);\r
+       start_tick = Tick64();\r
+       end_tick = start_tick + (UINT64)timeout;\r
+\r
+       while (true)\r
+       {\r
+               UINT64 now = Tick64();\r
+               UINT64 remain;\r
+               UINT remain32;\r
+\r
+               if (now >= end_tick)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               remain = end_tick - now;\r
+               remain32 = MIN((UINT)remain, 100);\r
+\r
+               if (WaitThread(t, remain32))\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       ReleaseThread(t);\r
+\r
+       if (p->Ok)\r
+       {\r
+               ret = true;\r
+       }\r
+\r
+       ReleaseWin32ReleaseAddressByGuidThreadParam(p);\r
+\r
+       return ret;\r
+}\r
+void ReleaseWin32ReleaseAddressByGuidThreadParam(WIN32_RELEASEADDRESS_THREAD_PARAM *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(p->Ref) == 0)\r
+       {\r
+               Free(p);\r
+       }\r
+}\r
+\r
+// アダプタを GUID から取得\r
+bool Win32GetAdapterFromGuid(void *a, char *guid)\r
+{\r
+       bool ret = false;\r
+       IP_INTERFACE_INFO *info;\r
+       UINT size;\r
+       int i;\r
+       LIST *o;\r
+       wchar_t tmp[MAX_SIZE];\r
+\r
+       // 引数チェック\r
+       if (a == NULL || guid == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (w32net->GetInterfaceInfo == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"\\DEVICE\\TCPIP_%S", guid);\r
+\r
+       size = sizeof(IP_INTERFACE_INFO);\r
+       info = ZeroMallocFast(size);\r
+\r
+       if (w32net->GetInterfaceInfo(info, &size) == ERROR_INSUFFICIENT_BUFFER)\r
+       {\r
+               Free(info);\r
+               info = ZeroMallocFast(size);\r
+       }\r
+\r
+       if (w32net->GetInterfaceInfo(info, &size) != NO_ERROR)\r
+       {\r
+               Free(info);\r
+               return false;\r
+       }\r
+\r
+       o = NewListFast(CompareIpAdapterIndexMap);\r
+\r
+       for (i = 0;i < info->NumAdapters;i++)\r
+       {\r
+               IP_ADAPTER_INDEX_MAP *a = &info->Adapter[i];\r
+\r
+               Add(o, a);\r
+       }\r
+\r
+       Sort(o);\r
+\r
+       for (i = 0;i < (int)(LIST_NUM(o));i++)\r
+       {\r
+               IP_ADAPTER_INDEX_MAP *e = LIST_DATA(o, i);\r
+\r
+               if (UniStrCmpi(e->Name, tmp) == 0)\r
+               {\r
+                       Copy(a, e, sizeof(IP_ADAPTER_INDEX_MAP));\r
+                       ret = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       Free(info);\r
+\r
+       return ret;\r
+}\r
+\r
+// テスト\r
+void Win32NetworkTest()\r
+{\r
+       IP_INTERFACE_INFO *info;\r
+       UINT size;\r
+       int i;\r
+       LIST *o;\r
+\r
+       size = sizeof(IP_INTERFACE_INFO);\r
+       info = ZeroMallocFast(size);\r
+\r
+       if (w32net->GetInterfaceInfo(info, &size) == ERROR_INSUFFICIENT_BUFFER)\r
+       {\r
+               Free(info);\r
+               info = ZeroMallocFast(size);\r
+       }\r
+\r
+       if (w32net->GetInterfaceInfo(info, &size) != NO_ERROR)\r
+       {\r
+               Free(info);\r
+               return;\r
+       }\r
+\r
+       o = NewListFast(CompareIpAdapterIndexMap);\r
+\r
+       for (i = 0;i < info->NumAdapters;i++)\r
+       {\r
+               IP_ADAPTER_INDEX_MAP *a = &info->Adapter[i];\r
+\r
+               Add(o, a);\r
+       }\r
+\r
+       Sort(o);\r
+\r
+       for (i = 0;i < (int)(LIST_NUM(o));i++)\r
+       {\r
+               IP_ADAPTER_INDEX_MAP *a = LIST_DATA(o, i);\r
+\r
+               DoNothing();\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       Free(info);\r
+}\r
+\r
+// 指定された LAN カードの DHCP アドレスを更新する\r
+void Win32RenewDhcp9x(UINT if_id)\r
+{\r
+       IP_INTERFACE_INFO *info;\r
+       UINT size;\r
+       int i;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (if_id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       size = sizeof(IP_INTERFACE_INFO);\r
+       info = ZeroMallocFast(size);\r
+\r
+       if (w32net->GetInterfaceInfo(info, &size) == ERROR_INSUFFICIENT_BUFFER)\r
+       {\r
+               Free(info);\r
+               info = ZeroMallocFast(size);\r
+       }\r
+\r
+       if (w32net->GetInterfaceInfo(info, &size) != NO_ERROR)\r
+       {\r
+               Free(info);\r
+               return;\r
+       }\r
+\r
+       o = NewListFast(CompareIpAdapterIndexMap);\r
+\r
+       for (i = 0;i < info->NumAdapters;i++)\r
+       {\r
+               IP_ADAPTER_INDEX_MAP *a = &info->Adapter[i];\r
+\r
+               Add(o, a);\r
+       }\r
+\r
+       Sort(o);\r
+\r
+       for (i = 0;i < (int)(LIST_NUM(o));i++)\r
+       {\r
+               IP_ADAPTER_INDEX_MAP *a = LIST_DATA(o, i);\r
+\r
+               if (a->Index == if_id)\r
+               {\r
+                       char arg[MAX_PATH];\r
+                       Format(arg, sizeof(arg), "/renew %u", i);\r
+                       Run("ipconfig.exe", arg, true, false);\r
+               }\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       Free(info);\r
+}\r
+\r
+// 指定された LAN カードの DHCP アドレスを解放する\r
+void Win32ReleaseDhcp9x(UINT if_id, bool wait)\r
+{\r
+       IP_INTERFACE_INFO *info;\r
+       UINT size;\r
+       int i;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (if_id == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       size = sizeof(IP_INTERFACE_INFO);\r
+       info = ZeroMallocFast(size);\r
+\r
+       if (w32net->GetInterfaceInfo(info, &size) == ERROR_INSUFFICIENT_BUFFER)\r
+       {\r
+               Free(info);\r
+               info = ZeroMallocFast(size);\r
+       }\r
+\r
+       if (w32net->GetInterfaceInfo(info, &size) != NO_ERROR)\r
+       {\r
+               Free(info);\r
+               return;\r
+       }\r
+\r
+       o = NewListFast(CompareIpAdapterIndexMap);\r
+\r
+       for (i = 0;i < info->NumAdapters;i++)\r
+       {\r
+               IP_ADAPTER_INDEX_MAP *a = &info->Adapter[i];\r
+\r
+               Add(o, a);\r
+       }\r
+\r
+       Sort(o);\r
+\r
+       for (i = 0;i < (int)(LIST_NUM(o));i++)\r
+       {\r
+               IP_ADAPTER_INDEX_MAP *a = LIST_DATA(o, i);\r
+\r
+               if (a->Index == if_id)\r
+               {\r
+                       char arg[MAX_PATH];\r
+                       Format(arg, sizeof(arg), "/release %u", i);\r
+                       Run("ipconfig.exe", arg, true, wait);\r
+               }\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       Free(info);\r
+}\r
+\r
+// DHCP サーバーから IP アドレスを再取得する\r
+void Win32RenewDhcp()\r
+{\r
+       if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType))\r
+       {\r
+               Run("ipconfig.exe", "/renew", true, false);\r
+               if (MsIsVista())\r
+               {\r
+                       Run("ipconfig.exe", "/renew6", true, false);\r
+               }\r
+               else\r
+               {\r
+                       Run("netsh.exe", "int ipv6 renew", true, false);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               Run("ipconfig.exe", "/renew_all", true, false);\r
+       }\r
+}\r
+\r
+// 指定された文字列を含む仮想 LAN カードの一覧を列挙する\r
+char **Win32EnumVLan(char *tag_name)\r
+{\r
+       MIB_IFTABLE *p;\r
+       UINT ret;\r
+       UINT size_needed;\r
+       UINT num_retry = 0;\r
+       UINT i;\r
+       LIST *o;\r
+       char **ss;\r
+       // 引数チェック\r
+       if (tag_name == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+RETRY:\r
+       p = ZeroMallocFast(sizeof(MIB_IFTABLE));\r
+       size_needed = 0;\r
+\r
+       // 必要なサイズを調べる\r
+       ret = w32net->GetIfTable(p, &size_needed, 0);\r
+       if (ret == ERROR_INSUFFICIENT_BUFFER)\r
+       {\r
+               // 必要なサイズ分のメモリブロックを再確保\r
+               Free(p);\r
+               p = ZeroMallocFast(size_needed);\r
+       }\r
+       else if (ret != NO_ERROR)\r
+       {\r
+               // 取得失敗\r
+FAILED:\r
+               Free(p);\r
+               return NULL;\r
+       }\r
+\r
+       // 実際に取得する\r
+       ret = w32net->GetIfTable(p, &size_needed, FALSE);\r
+       if (ret != NO_ERROR)\r
+       {\r
+               // 取得失敗\r
+               if ((++num_retry) >= 5)\r
+               {\r
+                       goto FAILED;\r
+               }\r
+               Free(p);\r
+               goto RETRY;\r
+       }\r
+\r
+       // 検索\r
+       ret = 0;\r
+       o = NewListFast(CompareStr);\r
+       for (i = 0;i < p->dwNumEntries;i++)\r
+       {\r
+               MIB_IFROW *r = &p->table[i];\r
+               if (SearchStrEx(r->bDescr, tag_name, 0, false) != INFINITE)\r
+               {\r
+                       char *s = CopyStr(r->bDescr);\r
+                       Add(o, s);\r
+               }\r
+       }\r
+\r
+       Free(p);\r
+\r
+       // ソート\r
+       Sort(o);\r
+\r
+       // 文字列に変換\r
+       ss = ZeroMallocFast(sizeof(char *) * (LIST_NUM(o) + 1));\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               ss[i] = LIST_DATA(o, i);\r
+       }\r
+       ss[LIST_NUM(o)] = NULL;\r
+\r
+       ReleaseList(o);\r
+\r
+       return ss;\r
+}\r
+\r
+// 仮想 LAN カードのインスタンス名から仮想 LAN カードの ID を取得する\r
+UINT Win32GetVLanInterfaceID(char *instance_name)\r
+{\r
+       MIB_IFTABLE *p;\r
+       UINT ret;\r
+       UINT size_needed;\r
+       UINT num_retry = 0;\r
+       UINT i;\r
+       char ps_miniport_str[MAX_SIZE];\r
+       char ps_miniport_str2[MAX_SIZE];\r
+       // 引数チェック\r
+       if (instance_name == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+RETRY:\r
+       p = ZeroMallocFast(sizeof(MIB_IFTABLE));\r
+       size_needed = 0;\r
+\r
+       // 必要なサイズを調べる\r
+       ret = w32net->GetIfTable(p, &size_needed, 0);\r
+       if (ret == ERROR_INSUFFICIENT_BUFFER)\r
+       {\r
+               // 必要なサイズ分のメモリブロックを再確保\r
+               Free(p);\r
+               p = ZeroMallocFast(size_needed);\r
+       }\r
+       else if (ret != NO_ERROR)\r
+       {\r
+               // 取得失敗\r
+FAILED:\r
+               Free(p);\r
+               Debug("******** GetIfTable Failed 1. Err = %u\n", ret);\r
+               return 0;\r
+       }\r
+\r
+       // 実際に取得する\r
+       ret = w32net->GetIfTable(p, &size_needed, FALSE);\r
+       if (ret != NO_ERROR)\r
+       {\r
+               // 取得失敗\r
+               if ((++num_retry) >= 5)\r
+               {\r
+                       goto FAILED;\r
+               }\r
+               Free(p);\r
+               Debug("******** GetIfTable Failed 2. Err = %u\n", ret);\r
+               goto RETRY;\r
+       }\r
+\r
+       // "%s - パケット スケジューラ ミニポート"\r
+       Format(ps_miniport_str, sizeof(ps_miniport_str), "%s - ", instance_name);\r
+       Format(ps_miniport_str2, sizeof(ps_miniport_str2), "%s (Microsoft", instance_name);\r
+\r
+       // 検索\r
+       ret = 0;\r
+       for (i = 0;i < p->dwNumEntries;i++)\r
+       {\r
+               MIB_IFROW *r = &p->table[i];\r
+               if (instance_name[0] != '@')\r
+               {\r
+                       if (StrCmpi(r->bDescr, instance_name) == 0 || StartWith(r->bDescr, ps_miniport_str) || StartWith(r->bDescr, ps_miniport_str2))\r
+                       {\r
+                               ret = r->dwIndex;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if (SearchStrEx(r->bDescr, &instance_name[1], 0, false) != INFINITE)\r
+                       {\r
+                               ret = r->dwIndex;\r
+                       }\r
+               }\r
+\r
+               Debug("if[%u] (0x%x): %s\n", i, r->dwIndex, r->bDescr);\r
+       }\r
+\r
+       Free(p);\r
+\r
+       return ret;\r
+}\r
+\r
+// デフォルトの DNS サーバーアドレスを取得する\r
+bool Win32GetDefaultDns(IP *ip, char *domain, UINT size)\r
+{\r
+       FIXED_INFO *info;\r
+       UINT info_size;\r
+       char *dns_name;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       Zero(ip, sizeof(IP));\r
+       info_size = 0;\r
+       info = ZeroMallocFast(sizeof(FIXED_INFO));\r
+       if (w32net->GetNetworkParams(info, &info_size) == ERROR_BUFFER_OVERFLOW)\r
+       {\r
+               Free(info);\r
+               info = ZeroMallocFast(info_size);\r
+       }\r
+       if (w32net->GetNetworkParams(info, &info_size) != NO_ERROR)\r
+       {\r
+               Free(info);\r
+               return false;\r
+       }\r
+\r
+       if (info->DnsServerList.IpAddress.String == NULL)\r
+       {\r
+               Free(info);\r
+               return false;\r
+       }\r
+\r
+       dns_name = info->DnsServerList.IpAddress.String;\r
+       StrToIP(ip, dns_name);\r
+\r
+       if (domain != NULL)\r
+       {\r
+               StrCpy(domain, size, info->DomainName);\r
+               Trim(domain);\r
+       }\r
+\r
+       Free(info);\r
+\r
+       return true;\r
+}\r
+\r
+// Win32 用 IP 変換関数\r
+void Win32UINTToIP(IP *ip, UINT i)\r
+{\r
+       UINTToIP(ip, i);\r
+}\r
+\r
+// Win32 用 IP 変換関数\r
+UINT Win32IPToUINT(IP *ip)\r
+{\r
+       return IPToUINT(ip);\r
+}\r
+\r
+// ルーティングテーブルからルーティングエントリを削除\r
+void Win32DeleteRouteEntry(ROUTE_ENTRY *e)\r
+{\r
+       MIB_IPFORWARDROW *p;\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = ZeroMallocFast(sizeof(MIB_IPFORWARDROW));\r
+       Win32RouteEntryToIpForwardRow(p, e);\r
+\r
+       // 削除\r
+       w32net->DeleteIpForwardEntry(p);\r
+\r
+       Free(p);\r
+}\r
+\r
+// ルーティングテーブルにルーティングエントリを追加\r
+bool Win32AddRouteEntry(ROUTE_ENTRY *e, bool *already_exists)\r
+{\r
+       bool ret = false;\r
+       bool dummy = false;\r
+       MIB_IPFORWARDROW *p;\r
+       UINT err = 0;\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (already_exists == NULL)\r
+       {\r
+               already_exists = &dummy;\r
+       }\r
+\r
+       *already_exists = false;\r
+\r
+       p = ZeroMallocFast(sizeof(MIB_IPFORWARDROW));\r
+       Win32RouteEntryToIpForwardRow(p, e);\r
+\r
+       // 追加\r
+       err = w32net->CreateIpForwardEntry(p);\r
+       if (err != 0)\r
+       {\r
+               if (err == ERROR_OBJECT_ALREADY_EXISTS)\r
+               {\r
+                       Debug("CreateIpForwardEntry: Already Exists\n");\r
+                       *already_exists = true;\r
+                       ret = true;\r
+               }\r
+               else\r
+               {\r
+                       Debug("CreateIpForwardEntry Error: %u\n", err);\r
+                       ret = false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               ret = true;\r
+       }\r
+\r
+       Free(p);\r
+\r
+       return ret;\r
+}\r
+\r
+// ルーティングテーブルの取得\r
+ROUTE_TABLE *Win32GetRouteTable()\r
+{\r
+       ROUTE_TABLE *t = ZeroMallocFast(sizeof(ROUTE_TABLE));\r
+       MIB_IPFORWARDTABLE *p;\r
+       UINT ret;\r
+       UINT size_needed;\r
+       UINT num_retry = 0;\r
+       LIST *o;\r
+       UINT i;\r
+       ROUTE_ENTRY *e;\r
+\r
+RETRY:\r
+       p = ZeroMallocFast(sizeof(MIB_IFTABLE));\r
+       size_needed = 0;\r
+\r
+       // 必要なサイズを調べる\r
+       ret = w32net->GetIpForwardTable(p, &size_needed, 0);\r
+       if (ret == ERROR_INSUFFICIENT_BUFFER)\r
+       {\r
+               // 必要なサイズ分のメモリブロックを再確保\r
+               Free(p);\r
+               p = ZeroMallocFast(size_needed);\r
+       }\r
+       else if (ret != NO_ERROR)\r
+       {\r
+               // 取得失敗\r
+FAILED:\r
+               Free(p);\r
+               t->Entry = MallocFast(0);\r
+               return t;\r
+       }\r
+\r
+       // 実際に取得する\r
+       ret = w32net->GetIpForwardTable(p, &size_needed, FALSE);\r
+       if (ret != NO_ERROR)\r
+       {\r
+               // 取得失敗\r
+               if ((++num_retry) >= 5)\r
+               {\r
+                       goto FAILED;\r
+               }\r
+               Free(p);\r
+               goto RETRY;\r
+       }\r
+\r
+       // リストに追加していく\r
+       o = NewListFast(Win32CompareRouteEntryByMetric);\r
+       for (i = 0;i < p->dwNumEntries;i++)\r
+       {\r
+               e = ZeroMallocFast(sizeof(ROUTE_ENTRY));\r
+               Win32IpForwardRowToRouteEntry(e, &p->table[i]);\r
+               Add(o, e);\r
+       }\r
+       Free(p);\r
+\r
+       // メトリック順にソート\r
+       Sort(o);\r
+\r
+       // 結果を結合\r
+       t->NumEntry = LIST_NUM(o);\r
+       t->Entry = ToArrayEx(o, true);\r
+       ReleaseList(o);\r
+\r
+       return t;\r
+}\r
+\r
+// ルーティングエントリをメトリックによってソートする\r
+int Win32CompareRouteEntryByMetric(void *p1, void *p2)\r
+{\r
+       ROUTE_ENTRY *e1, *e2;\r
+       // 引数チェック\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       e1 = *(ROUTE_ENTRY **)p1;\r
+       e2 = *(ROUTE_ENTRY **)p2;\r
+       if (e1 == NULL || e2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (e1->Metric > e2->Metric)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (e1->Metric == e2->Metric)\r
+       {\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               return -1;\r
+       }\r
+}\r
+\r
+// ROUTE_ENTRY を MIB_IPFORWARDROW に変換\r
+void Win32RouteEntryToIpForwardRow(void *ip_forward_row, ROUTE_ENTRY *entry)\r
+{\r
+       MIB_IPFORWARDROW *r;\r
+       // 引数チェック\r
+       if (entry == NULL || ip_forward_row == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       r = (MIB_IPFORWARDROW *)ip_forward_row;\r
+       Zero(r, sizeof(MIB_IPFORWARDROW));\r
+\r
+       // IP アドレス\r
+       r->dwForwardDest = Win32IPToUINT(&entry->DestIP);\r
+       // サブネットマスク\r
+       r->dwForwardMask = Win32IPToUINT(&entry->DestMask);\r
+       // ゲートウェイ IP アドレス\r
+       r->dwForwardNextHop = Win32IPToUINT(&entry->GatewayIP);\r
+       // ローカルルーティングフラグ\r
+       if (entry->LocalRouting)\r
+       {\r
+               // ローカル\r
+               r->dwForwardType = 3;\r
+       }\r
+       else\r
+       {\r
+               // リモートルータ\r
+               r->dwForwardType = 4;\r
+       }\r
+       // プロトコル\r
+       r->dwForwardProto = r->dwForwardType - 1;       // 大抵の場合 1 引けば良い\r
+       if (entry->PPPConnection)\r
+       {\r
+               // PPP ちゃうかな? 危険!\r
+               r->dwForwardProto++;\r
+       }\r
+       // メトリック\r
+       r->dwForwardMetric1 = entry->Metric;\r
+\r
+       if (MsIsVista() == false)\r
+       {\r
+               r->dwForwardMetric2 = r->dwForwardMetric3 = r->dwForwardMetric4 = r->dwForwardMetric5 = INFINITE;\r
+       }\r
+       else\r
+       {\r
+               r->dwForwardMetric2 = r->dwForwardMetric3 = r->dwForwardMetric4 = r->dwForwardMetric5 = 0;\r
+               r->dwForwardAge = 163240;\r
+       }\r
+\r
+       // インターフェイス ID\r
+       r->dwForwardIfIndex = entry->InterfaceID;\r
+\r
+       Debug("Win32RouteEntryToIpForwardRow()\n");\r
+       Debug(" r->dwForwardDest=%X\n", r->dwForwardDest);\r
+       Debug(" r->dwForwardMask=%X\n", r->dwForwardMask);\r
+       Debug(" r->dwForwardNextHop=%X\n", r->dwForwardNextHop);\r
+       Debug(" r->dwForwardType=%u\n", r->dwForwardType);\r
+       Debug(" r->dwForwardProto=%u\n", r->dwForwardProto);\r
+       Debug(" r->dwForwardMetric1=%u\n", r->dwForwardMetric1);\r
+       Debug(" r->dwForwardMetric2=%u\n", r->dwForwardMetric2);\r
+       Debug(" r->dwForwardIfIndex=%u\n", r->dwForwardIfIndex);\r
+}\r
+\r
+// MIB_IPFORWARDROW を ROUTE_ENTRY に変換\r
+void Win32IpForwardRowToRouteEntry(ROUTE_ENTRY *entry, void *ip_forward_row)\r
+{\r
+       MIB_IPFORWARDROW *r;\r
+       // 引数チェック\r
+       if (entry == NULL || ip_forward_row == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       r = (MIB_IPFORWARDROW *)ip_forward_row;\r
+\r
+       Zero(entry, sizeof(ROUTE_ENTRY));\r
+       // IP アドレス\r
+       Win32UINTToIP(&entry->DestIP, r->dwForwardDest);\r
+       // サブネットマスク\r
+       Win32UINTToIP(&entry->DestMask, r->dwForwardMask);\r
+       // ゲートウェイ IP アドレス\r
+       Win32UINTToIP(&entry->GatewayIP, r->dwForwardNextHop);\r
+       // ローカルルーティングフラグ\r
+       if (r->dwForwardType == 3)\r
+       {\r
+               entry->LocalRouting = true;\r
+       }\r
+       else\r
+       {\r
+               entry->LocalRouting = false;\r
+       }\r
+       if (entry->LocalRouting && r->dwForwardProto == 3)\r
+       {\r
+               // PPP。危険!\r
+               entry->PPPConnection = true;\r
+       }\r
+       // メトリック\r
+       entry->Metric = r->dwForwardMetric1;\r
+       // インターフェイス ID\r
+       entry->InterfaceID = r->dwForwardIfIndex;\r
+}\r
+\r
+// ソケットライブラリの初期化\r
+void Win32InitSocketLibrary()\r
+{\r
+       WSADATA data;\r
+       Zero(&data, sizeof(data));\r
+       WSAStartup(MAKEWORD(2, 2), &data);\r
+\r
+       // DLL 関数の読み込み\r
+       w32net = ZeroMalloc(sizeof(NETWORK_WIN32_FUNCTIONS));\r
+       w32net->hIpHlpApi32 = LoadLibrary("iphlpapi.dll");\r
+\r
+       if (w32net->hIpHlpApi32 != NULL)\r
+       {\r
+               w32net->CreateIpForwardEntry =\r
+                       (DWORD (__stdcall *)(PMIB_IPFORWARDROW))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "CreateIpForwardEntry");\r
+\r
+               w32net->DeleteIpForwardEntry =\r
+                       (DWORD (__stdcall *)(PMIB_IPFORWARDROW))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "DeleteIpForwardEntry");\r
+\r
+               w32net->GetIfTable =\r
+                       (DWORD (__stdcall *)(PMIB_IFTABLE, PULONG, BOOL))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "GetIfTable");\r
+\r
+               w32net->GetIpForwardTable =\r
+                       (DWORD (__stdcall *)(PMIB_IPFORWARDTABLE, PULONG, BOOL))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "GetIpForwardTable");\r
+\r
+               w32net->GetNetworkParams =\r
+                       (DWORD (__stdcall *)(PFIXED_INFO,PULONG))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "GetNetworkParams");\r
+\r
+               w32net->IpRenewAddress =\r
+                       (DWORD (__stdcall *)(PIP_ADAPTER_INDEX_MAP))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "IpRenewAddress");\r
+\r
+               w32net->IpReleaseAddress =\r
+                       (DWORD (__stdcall *)(PIP_ADAPTER_INDEX_MAP))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "IpReleaseAddress");\r
+\r
+               w32net->GetInterfaceInfo =\r
+                       (DWORD (__stdcall *)(PIP_INTERFACE_INFO, PULONG))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "GetInterfaceInfo");\r
+\r
+               w32net->GetAdaptersInfo =\r
+                       (DWORD (__stdcall *)(PIP_ADAPTER_INFO, PULONG))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "GetAdaptersInfo");\r
+\r
+               w32net->GetExtendedTcpTable =\r
+                       (DWORD (__stdcall *)(PVOID,PDWORD,BOOL,ULONG,_TCP_TABLE_CLASS,ULONG))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "GetExtendedTcpTable");\r
+\r
+               w32net->AllocateAndGetTcpExTableFromStack =\r
+                       (DWORD (__stdcall *)(PVOID *,BOOL,HANDLE,DWORD,DWORD))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "AllocateAndGetTcpExTableFromStack");\r
+\r
+               w32net->GetTcpTable =\r
+                       (DWORD (__stdcall *)(PMIB_TCPTABLE,PDWORD,BOOL))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "GetTcpTable");\r
+\r
+               w32net->NotifyRouteChange =\r
+                       (DWORD (__stdcall *)(PHANDLE,LPOVERLAPPED))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "NotifyRouteChange");\r
+\r
+               w32net->CancelIPChangeNotify =\r
+                       (BOOL (__stdcall *)(LPOVERLAPPED))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "CancelIPChangeNotify");\r
+\r
+               w32net->NhpAllocateAndGetInterfaceInfoFromStack =\r
+                       (DWORD (__stdcall *)(IP_INTERFACE_NAME_INFO **,PDWORD,BOOL,HANDLE,DWORD))\r
+                       GetProcAddress(w32net->hIpHlpApi32, "NhpAllocateAndGetInterfaceInfoFromStack");\r
+       }\r
+}\r
+\r
+// ソケットライブラリの解放\r
+void Win32FreeSocketLibrary()\r
+{\r
+       if (w32net != NULL)\r
+       {\r
+               FreeLibrary(w32net->hIpHlpApi32);\r
+\r
+               Free(w32net);\r
+               w32net = NULL;\r
+       }\r
+\r
+       WSACleanup();\r
+}\r
+\r
+// キャンセル\r
+void Win32Cancel(CANCEL *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEvent((HANDLE)c->hEvent);\r
+}\r
+\r
+// キャンセルのクリーンアップ\r
+void Win32CleanupCancel(CANCEL *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (c->SpecialFlag == false)\r
+       {\r
+               CloseHandle(c->hEvent);\r
+       }\r
+\r
+       Free(c);\r
+}\r
+\r
+// 新しいキャンセルオブジェクト\r
+CANCEL *Win32NewCancel()\r
+{\r
+       CANCEL *c = ZeroMallocFast(sizeof(CANCEL));\r
+       c->ref = NewRef();\r
+       c->SpecialFlag = false;\r
+       c->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);\r
+\r
+       return c;\r
+}\r
+\r
+// ソケットイベントの待機\r
+bool Win32WaitSockEvent(SOCK_EVENT *event, UINT timeout)\r
+{\r
+       // 引数チェック\r
+       if (event == NULL || timeout == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (WaitForSingleObject((HANDLE)event->hEvent, timeout) == WAIT_OBJECT_0)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// ソケットイベントのクリーンアップ\r
+void Win32CleanupSockEvent(SOCK_EVENT *event)\r
+{\r
+       // 引数チェック\r
+       if (event == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CloseHandle((HANDLE)event->hEvent);\r
+\r
+       Free(event);\r
+}\r
+\r
+// ソケットイベントのセット\r
+void Win32SetSockEvent(SOCK_EVENT *event)\r
+{\r
+       // 引数チェック\r
+       if (event == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEvent((HANDLE)event->hEvent);\r
+}\r
+\r
+// ソケットイベントの作成\r
+SOCK_EVENT *Win32NewSockEvent()\r
+{\r
+       SOCK_EVENT *e = ZeroMallocFast(sizeof(SOCK_EVENT));\r
+\r
+       e->ref = NewRef();\r
+       e->hEvent = (void *)CreateEvent(NULL, FALSE, FALSE, NULL);\r
+\r
+       return e;\r
+}\r
+\r
+// ソケットをソケットイベントに関連付けして非同期に設定する\r
+void Win32JoinSockToSockEvent(SOCK *sock, SOCK_EVENT *event)\r
+{\r
+       HANDLE hEvent;\r
+       // 引数チェック\r
+       if (sock == NULL || event == NULL || sock->AsyncMode)\r
+       {\r
+               return;\r
+       }\r
+       if (sock->ListenMode != false || (sock->Type != SOCK_UDP && sock->Connected == false))\r
+       {\r
+               return;\r
+       }\r
+\r
+       sock->AsyncMode = true;\r
+\r
+       hEvent = event->hEvent;\r
+\r
+       // 関連付け\r
+       WSAEventSelect(sock->socket, hEvent, FD_READ | FD_WRITE | FD_CLOSE);\r
+\r
+       // SOCK_EVENT の参照カウンタを増加\r
+       AddRef(event->ref);\r
+       sock->SockEvent = event;\r
+}\r
+\r
+// ソケットを非同期に設定する\r
+void Win32InitAsyncSocket(SOCK *sock)\r
+{\r
+       // 引数チェック\r
+       if (sock == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (sock->AsyncMode)\r
+       {\r
+               // すでに非同期ソケットになっている\r
+               return;\r
+       }\r
+       if (sock->ListenMode != false || (sock->Type == SOCK_TCP && sock->Connected == false))\r
+       {\r
+               return;\r
+       }\r
+\r
+       sock->AsyncMode = true;\r
+\r
+       // イベントの作成\r
+       sock->hEvent = (void *)CreateEvent(NULL, FALSE, FALSE, NULL);\r
+\r
+       // 関連付け\r
+       WSAEventSelect(sock->socket, sock->hEvent, FD_READ | FD_WRITE | FD_CLOSE);\r
+}\r
+\r
+// 非同期ソケットを解放\r
+void Win32FreeAsyncSocket(SOCK *sock)\r
+{\r
+       // 引数チェック\r
+       if (sock == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 非同期ソケット\r
+       if (sock->hEvent != NULL)\r
+       {\r
+               CloseHandle((HANDLE)sock->hEvent);\r
+       }\r
+       sock->hEvent = NULL;\r
+       sock->AsyncMode = false;\r
+\r
+       // ソケットイベント\r
+       if (sock->SockEvent != NULL)\r
+       {\r
+               ReleaseSockEvent(sock->SockEvent);\r
+               sock->SockEvent = NULL;\r
+       }\r
+}\r
+\r
+// Win32 版 Select 関数\r
+void Win32Select(SOCKSET *set, UINT timeout, CANCEL *c1, CANCEL *c2)\r
+{\r
+       HANDLE array[MAXIMUM_WAIT_OBJECTS];\r
+       UINT n, i;\r
+       SOCK *s;\r
+       // 引数チェック\r
+       if (timeout == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 配列の初期化\r
+       Zero(array, sizeof(array));\r
+       n = 0;\r
+\r
+       // イベント配列の設定\r
+       if (set != NULL)\r
+       {\r
+               for (i = 0;i < set->NumSocket;i++)\r
+               {\r
+                       s = set->Sock[i];\r
+                       if (s != NULL)\r
+                       {\r
+                               Win32InitAsyncSocket(s);\r
+                               if (s->hEvent != NULL)\r
+                               {\r
+                                       array[n++] = (HANDLE)s->hEvent;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       if (c1 != NULL && c1->hEvent != NULL)\r
+       {\r
+               array[n++] = c1->hEvent;\r
+       }\r
+       if (c2 != NULL && c2->hEvent != NULL)\r
+       {\r
+               array[n++] = c2->hEvent;\r
+       }\r
+\r
+       if (n == 0)\r
+       {\r
+               // 待つイベントが 1 つも登録されていない場合は\r
+               // 通常の待ち関数を呼ぶ\r
+               SleepThread(timeout);\r
+       }\r
+       else\r
+       {\r
+               // イベントが 1 つ以上登録されている場合はイベントを待つ\r
+               if (n == 1)\r
+               {\r
+                       // イベントが 1 つの場合は軽量版を呼び出す\r
+                       WaitForSingleObject(array[0], timeout);\r
+               }\r
+               else\r
+               {\r
+                       // イベントが複数の場合\r
+                       WaitForMultipleObjects(n, array, false, timeout);\r
+               }\r
+       }\r
+}\r
+\r
+#endif // OS_WIN32\r
+\r
+// IPv6 がサポートされているかどうか調べる\r
+bool IsIPv6Supported()\r
+{\r
+#ifdef NO_IPV6\r
+       return false;\r
+#else  // NO_IPV6\r
+       SOCKET s;\r
+\r
+       s = socket(AF_INET6, SOCK_STREAM, 0);\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       closesocket(s);\r
+\r
+       return true;\r
+#endif // NO_IPV6\r
+}\r
+\r
+// ホストキャッシュからホスト名の取得\r
+bool GetHostCache(char *hostname, UINT size, IP *ip)\r
+{\r
+       bool ret;\r
+       // 引数チェック\r
+       if (hostname == NULL || ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = false;\r
+\r
+       LockList(HostCacheList);\r
+       {\r
+               HOSTCACHE t, *c;\r
+               Zero(&t, sizeof(t));\r
+               Copy(&t.IpAddress, ip, sizeof(IP));\r
+\r
+               c = Search(HostCacheList, &t);\r
+               if (c != NULL)\r
+               {\r
+                       if (IsEmptyStr(c->HostName) == false)\r
+                       {\r
+                               ret = true;\r
+                               StrCpy(hostname, size, c->HostName);\r
+                       }\r
+                       else\r
+                       {\r
+                               ret = true;\r
+                               StrCpy(hostname, size, "");\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(HostCacheList);\r
+\r
+       return ret;\r
+}\r
+\r
+// ホスト名キャッシュへ追加\r
+void AddHostCache(IP *ip, char *hostname)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL || hostname == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (IsNetworkNameCacheEnabled() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(HostCacheList);\r
+       {\r
+               HOSTCACHE t, *c;\r
+               UINT i;\r
+               LIST *o;\r
+\r
+               Zero(&t, sizeof(t));\r
+               Copy(&t.IpAddress, ip, sizeof(IP));\r
+\r
+               c = Search(HostCacheList, &t);\r
+               if (c == NULL)\r
+               {\r
+                       c = ZeroMalloc(sizeof(HOSTCACHE));\r
+                       Copy(&c->IpAddress, ip, sizeof(IP));\r
+                       Add(HostCacheList, c);\r
+               }\r
+\r
+               StrCpy(c->HostName, sizeof(c->HostName), hostname);\r
+               c->Expires = Tick64() + (UINT64)EXPIRES_HOSTNAME;\r
+\r
+               o = NewListFast(NULL);\r
+\r
+               for (i = 0;i < LIST_NUM(HostCacheList);i++)\r
+               {\r
+                       HOSTCACHE *c = LIST_DATA(HostCacheList, i);\r
+\r
+                       if (c->Expires <= Tick64())\r
+                       {\r
+                               Add(o, c);\r
+                       }\r
+               }\r
+\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       HOSTCACHE *c = LIST_DATA(o, i);\r
+\r
+                       if (Delete(HostCacheList, c))\r
+                       {\r
+                               Free(c);\r
+                       }\r
+               }\r
+\r
+               ReleaseList(o);\r
+       }\r
+       UnlockList(HostCacheList);\r
+}\r
+\r
+// ホスト名キャッシュの比較\r
+int CompareHostCache(void *p1, void *p2)\r
+{\r
+       HOSTCACHE *c1, *c2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       c1 = *(HOSTCACHE **)p1;\r
+       c2 = *(HOSTCACHE **)p2;\r
+       if (c1 == NULL || c2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return CmpIpAddr(&c1->IpAddress, &c2->IpAddress);\r
+}\r
+\r
+// ホスト名キャッシュの解放\r
+void FreeHostCache()\r
+{\r
+       UINT i;\r
+\r
+       for (i = 0;i < LIST_NUM(HostCacheList);i++)\r
+       {\r
+               HOSTCACHE *c = LIST_DATA(HostCacheList, i);\r
+\r
+               Free(c);\r
+       }\r
+\r
+       ReleaseList(HostCacheList);\r
+       HostCacheList = NULL;\r
+}\r
+\r
+// ホスト名キャッシュの初期化\r
+void InitHostCache()\r
+{\r
+       HostCacheList = NewList(CompareHostCache);\r
+}\r
+\r
+// スレッドをスレッド待機リストに追加する\r
+void AddWaitThread(THREAD *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       AddRef(t->ref);\r
+\r
+       LockList(WaitThreadList);\r
+       {\r
+               Add(WaitThreadList, t);\r
+       }\r
+       UnlockList(WaitThreadList);\r
+}\r
+\r
+// スレッドを待機リストから削除する\r
+void DelWaitThread(THREAD *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(WaitThreadList);\r
+       {\r
+               if (Delete(WaitThreadList, t))\r
+               {\r
+                       ReleaseThread(t);\r
+               }\r
+       }\r
+       UnlockList(WaitThreadList);\r
+}\r
+\r
+// スレッド待機リストの作成\r
+void InitWaitThread()\r
+{\r
+       WaitThreadList = NewList(NULL);\r
+}\r
+\r
+// スレッド待機リストの解放\r
+void FreeWaitThread()\r
+{\r
+       UINT i, num;\r
+       THREAD **threads;\r
+\r
+       LockList(WaitThreadList);\r
+       {\r
+               num = LIST_NUM(WaitThreadList);\r
+               threads = ToArray(WaitThreadList);\r
+               DeleteAll(WaitThreadList);\r
+       }\r
+       UnlockList(WaitThreadList);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               THREAD *t = threads[i];\r
+               WaitThread(t, INFINITE);\r
+               ReleaseThread(t);\r
+       }\r
+\r
+       Free(threads);\r
+\r
+       ReleaseList(WaitThreadList);\r
+       WaitThreadList = NULL;\r
+}\r
+\r
+// 暗号リスト名をチェックする\r
+bool CheckCipherListName(char *name)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < cipher_list_token->NumTokens;i++)\r
+       {\r
+               if (StrCmpi(cipher_list_token->Token[i], name) == 0)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// DHCP サーバーの IP アドレス更新\r
+void RenewDhcp()\r
+{\r
+#ifdef OS_WIN32\r
+       Win32RenewDhcp();\r
+#else\r
+       UnixRenewDhcp();\r
+#endif\r
+}\r
+\r
+// UNIX 用ドメイン名を取得\r
+bool UnixGetDomainName(char *name, UINT size)\r
+{\r
+       bool ret = false;\r
+       BUF *b = ReadDump("/etc/resolv.conf");\r
+\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               char *s = CfgReadNextLine(b);\r
+               TOKEN_LIST *t;\r
+\r
+               if (s == NULL)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               Trim(s);\r
+\r
+               t = ParseToken(s, " \t");\r
+               if (t != NULL)\r
+               {\r
+                       if (t->NumTokens == 2)\r
+                       {\r
+                               if (StrCmpi(t->Token[0], "domain") == 0)\r
+                               {\r
+                                       StrCpy(name, size, t->Token[1]);\r
+                                       ret = true;\r
+                               }\r
+                       }\r
+                       FreeToken(t);\r
+               }\r
+\r
+               Free(s);\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// ドメイン名を取得\r
+bool GetDomainName(char *name, UINT size)\r
+{\r
+       bool ret = false;\r
+       IP ip;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       ret = Win32GetDefaultDns(&ip, name, size);\r
+#else  // OS_WIN32\r
+       ret = UnixGetDomainName(name, size);\r
+#endif // OS_WIN32\r
+\r
+       return ret;\r
+}\r
+\r
+// デフォルトの DNS サーバーの取得\r
+bool GetDefaultDns(IP *ip)\r
+{\r
+       bool ret = false;\r
+#ifdef OS_WIN32\r
+       ret = Win32GetDefaultDns(ip, NULL, 0);\r
+#else\r
+       ret = UnixGetDefaultDns(ip);\r
+#endif // OS_WIN32\r
+       return ret;\r
+}\r
+\r
+// ソケットイベントの作成\r
+SOCK_EVENT *NewSockEvent()\r
+{\r
+       SOCK_EVENT *e = NULL;\r
+#ifdef OS_WIN32\r
+       e = Win32NewSockEvent();\r
+#else\r
+       e = UnixNewSockEvent();\r
+#endif // OS_WIN32\r
+       return e;\r
+}\r
+\r
+// ソケットイベントのセット\r
+void SetSockEvent(SOCK_EVENT *event)\r
+{\r
+#ifdef OS_WIN32\r
+       Win32SetSockEvent(event);\r
+#else\r
+       UnixSetSockEvent(event);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// ソケットイベントのクリーンアップ\r
+void CleanupSockEvent(SOCK_EVENT *event)\r
+{\r
+#ifdef OS_WIN32\r
+       Win32CleanupSockEvent(event);\r
+#else\r
+       UnixCleanupSockEvent(event);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// ソケットイベントの待機\r
+bool WaitSockEvent(SOCK_EVENT *event, UINT timeout)\r
+{\r
+       bool ret = false;\r
+#ifdef OS_WIN32\r
+       ret = Win32WaitSockEvent(event, timeout);\r
+#else\r
+       ret = UnixWaitSockEvent(event, timeout);\r
+#endif // OS_WIN32\r
+       return ret;\r
+}\r
+\r
+// ソケットイベントの解放\r
+void ReleaseSockEvent(SOCK_EVENT *event)\r
+{\r
+       // 引数チェック\r
+       if (event == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(event->ref) == 0)\r
+       {\r
+               CleanupSockEvent(event);\r
+       }\r
+}\r
+\r
+// ソケットをソケットイベントに所属させる\r
+void JoinSockToSockEvent(SOCK *sock, SOCK_EVENT *event)\r
+{\r
+#ifdef OS_WIN32\r
+       Win32JoinSockToSockEvent(sock, event);\r
+#else\r
+       UnixJoinSockToSockEvent(sock, event);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// 新しい特殊キャンセルオブジェクト\r
+CANCEL *NewCancelSpecial(void *hEvent)\r
+{\r
+       CANCEL *c;\r
+       // 引数チェック\r
+       if (hEvent == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       c = ZeroMalloc(sizeof(CANCEL));\r
+       c->ref = NewRef();\r
+       c->SpecialFlag = true;\r
+\r
+#ifdef OS_WIN32\r
+       c->hEvent = (HANDLE)hEvent;\r
+#else  // OS_WIN32\r
+       c->pipe_read = (int)hEvent;\r
+       c->pipe_write = -1;\r
+#endif // OS_WIN32\r
+\r
+       return c;\r
+}\r
+\r
+// キャンセルオブジェクトの作成\r
+CANCEL *NewCancel()\r
+{\r
+       CANCEL *c = NULL;\r
+#ifdef OS_WIN32\r
+       c = Win32NewCancel();\r
+#else\r
+       c = UnixNewCancel();\r
+#endif // OS_WIN32\r
+       return c;\r
+}\r
+\r
+// キャンセルオブジェクトの解放\r
+void ReleaseCancel(CANCEL *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(c->ref) == 0)\r
+       {\r
+               CleanupCancel(c);\r
+       }\r
+}\r
+\r
+// キャンセルオブジェクトのクリーンアップ\r
+void CleanupCancel(CANCEL *c)\r
+{\r
+#ifdef OS_WIN32\r
+       Win32CleanupCancel(c);\r
+#else\r
+       UnixCleanupCancel(c);\r
+#endif\r
+}\r
+\r
+// キャンセル発動\r
+void Cancel(CANCEL *c)\r
+{\r
+#ifdef OS_WIN32\r
+       Win32Cancel(c);\r
+#else\r
+       UnixCancel(c);\r
+#endif\r
+}\r
+\r
+// 指定されたルーティングテーブルから最適なルートを計算する\r
+ROUTE_ENTRY *GetBestRouteEntryFromRouteTable(ROUTE_TABLE *table, IP *ip)\r
+{\r
+       return GetBestRouteEntryFromRouteTableEx(table, ip, 0);\r
+}\r
+ROUTE_ENTRY *GetBestRouteEntryFromRouteTableEx(ROUTE_TABLE *table, IP *ip, UINT exclude_if_id)\r
+{\r
+       UINT i;\r
+       UINT max_mask = 0;\r
+       UINT min_metric = INFINITE;\r
+       ROUTE_ENTRY *ret = NULL;\r
+       ROUTE_ENTRY *tmp = NULL;\r
+       // 引数チェック\r
+       if (ip == NULL || table == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (IsIP6(ip))\r
+       {\r
+               // IPv6 は非サポート\r
+               return NULL;\r
+       }\r
+\r
+       // 対象となるルーティングテーブルのうち、\r
+       //  第一条件: サブネットマスクが最も大きい\r
+       //  第二条件: メトリック値が最も小さい\r
+       // ものを選択する\r
+       for (i = 0;i < table->NumEntry;i++)\r
+       {\r
+               ROUTE_ENTRY *e = table->Entry[i];\r
+               UINT dest, net, mask;\r
+\r
+               dest = IPToUINT(ip);\r
+               net = IPToUINT(&e->DestIP);\r
+               mask = IPToUINT(&e->DestMask);\r
+\r
+               if (exclude_if_id != 0)\r
+               {\r
+                       if (e->InterfaceID == exclude_if_id)\r
+                       {\r
+                               continue;\r
+                       }\r
+               }\r
+\r
+               // マスクテスト\r
+               if ((dest & mask) == (net & mask))\r
+               {\r
+                       // これはルーティングの対象となり得る\r
+                       if (mask >= max_mask)\r
+                       {\r
+                               max_mask = mask;\r
+                               if (min_metric >= e->Metric)\r
+                               {\r
+                                       min_metric = e->Metric;\r
+                                       tmp = e;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (tmp != NULL)\r
+       {\r
+               UINT dest, gateway, mask;\r
+\r
+               // エントリを生成\r
+               ret = ZeroMallocFast(sizeof(ROUTE_ENTRY));\r
+\r
+               Copy(&ret->DestIP, ip, sizeof(IP));\r
+               ret->DestMask.addr[0] = 255;\r
+               ret->DestMask.addr[1] = 255;\r
+               ret->DestMask.addr[2] = 255;\r
+               ret->DestMask.addr[3] = 255;\r
+               Copy(&ret->GatewayIP, &tmp->GatewayIP, sizeof(IP));\r
+               ret->InterfaceID = tmp->InterfaceID;\r
+               ret->LocalRouting = tmp->LocalRouting;\r
+               ret->OldIfMetric = tmp->Metric;\r
+               ret->Metric = 1;\r
+               ret->PPPConnection = tmp->PPPConnection;\r
+\r
+               // ルーティング制御関係の計算\r
+               dest = IPToUINT(&tmp->DestIP);\r
+               gateway = IPToUINT(&tmp->GatewayIP);\r
+               mask = IPToUINT(&tmp->DestMask);\r
+               if ((dest & mask) == (gateway & mask))\r
+               {\r
+#ifdef OS_WIN32\r
+                       if (MsIsVista() == false)\r
+                       {\r
+                               // Windows 用調整\r
+                               ret->PPPConnection = true;\r
+                       }\r
+#endif // OS_WIN32\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ルーティングエントリを解放する\r
+void FreeRouteEntry(ROUTE_ENTRY *e)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(e);\r
+}\r
+\r
+// 現在のルーティングテーブルを解析して最適なルートエントリを取得する\r
+ROUTE_ENTRY *GetBestRouteEntry(IP *ip)\r
+{\r
+       return GetBestRouteEntryEx(ip, 0);\r
+}\r
+ROUTE_ENTRY *GetBestRouteEntryEx(IP *ip, UINT exclude_if_id)\r
+{\r
+       ROUTE_TABLE *table;\r
+       ROUTE_ENTRY *e = NULL;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       table = GetRouteTable();\r
+       if (table == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       e = GetBestRouteEntryFromRouteTableEx(table, ip, exclude_if_id);\r
+       FreeRouteTable(table);\r
+\r
+       return e;\r
+}\r
+\r
+// 仮想 LAN カードのインターフェース ID の取得\r
+UINT GetVLanInterfaceID(char *tag_name)\r
+{\r
+       UINT ret = 0;\r
+#ifdef OS_WIN32\r
+       ret = Win32GetVLanInterfaceID(tag_name);\r
+#else  // OS_WIN32\r
+       ret = UnixGetVLanInterfaceID(tag_name);\r
+#endif // OS_WIN32\r
+       return ret;\r
+}\r
+\r
+// 仮想 LAN カードの列挙変数の解放\r
+void FreeEnumVLan(char **s)\r
+{\r
+       char *a;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       i = 0;\r
+       while (true)\r
+       {\r
+               a = s[i++];\r
+               if (a == NULL)\r
+               {\r
+                       break;\r
+               }\r
+               Free(a);\r
+       }\r
+\r
+       Free(s);\r
+}\r
+\r
+// 仮想 LAN カードの列挙\r
+char **EnumVLan(char *tag_name)\r
+{\r
+       char **ret = NULL;\r
+#ifdef OS_WIN32\r
+       ret = Win32EnumVLan(tag_name);\r
+#else  // OS_WIN32\r
+       ret = UnixEnumVLan(tag_name);\r
+#endif // OS_WIN32\r
+       return ret;\r
+}\r
+\r
+// ルーティングテーブルを表示する\r
+void DebugPrintRouteTable(ROUTE_TABLE *r)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (r == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsDebug() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Debug("---- Routing Table (%u Entries) ----\n", r->NumEntry);\r
+\r
+       for (i = 0;i < r->NumEntry;i++)\r
+       {\r
+               Debug("   ");\r
+\r
+               DebugPrintRoute(r->Entry[i]);\r
+       }\r
+\r
+       Debug("------------------------------------\n");\r
+}\r
+\r
+// ルーティングテーブルエントリを表示する\r
+void DebugPrintRoute(ROUTE_ENTRY *e)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsDebug() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       RouteToStr(tmp, sizeof(tmp), e);\r
+\r
+       Debug("%s\n", tmp);\r
+}\r
+\r
+// ルーティングテーブルエントリを文字列にする\r
+void RouteToStr(char *str, UINT str_size, ROUTE_ENTRY *e)\r
+{\r
+       char dest_ip[MAX_PATH];\r
+       char dest_mask[MAX_PATH];\r
+       char gateway_ip[MAX_PATH];\r
+       // 引数チェック\r
+       if (str == NULL || e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       IPToStr(dest_ip, sizeof(dest_ip), &e->DestIP);\r
+       IPToStr(dest_mask, sizeof(dest_mask), &e->DestMask);\r
+       IPToStr(gateway_ip, sizeof(gateway_ip), &e->GatewayIP);\r
+\r
+       Format(str, str_size, "%s/%s %s m=%u oif=%u if=%u lo=%u p=%u",\r
+               dest_ip, dest_mask, gateway_ip,\r
+               e->Metric, e->OldIfMetric, e->InterfaceID,\r
+               e->LocalRouting, e->PPPConnection);\r
+}\r
+\r
+// ルーティングテーブルの削除\r
+void DeleteRouteEntry(ROUTE_ENTRY *e)\r
+{\r
+       Debug("DeleteRouteEntry();\n");\r
+#ifdef OS_WIN32\r
+       Win32DeleteRouteEntry(e);\r
+#else  // OS_WIN32\r
+       UnixDeleteRouteEntry(e);\r
+#endif\r
+}\r
+\r
+// ルーティングテーブルの追加\r
+bool AddRouteEntry(ROUTE_ENTRY *e)\r
+{\r
+       bool dummy = false;\r
+       return AddRouteEntryEx(e, &dummy);\r
+}\r
+bool AddRouteEntryEx(ROUTE_ENTRY *e, bool *already_exists)\r
+{\r
+       bool ret = false;\r
+       Debug("AddRouteEntryEx();\n");\r
+#ifdef OS_WIN32\r
+       ret = Win32AddRouteEntry(e, already_exists);\r
+#else  // OS_WIN32\r
+       ret = UnixAddRouteEntry(e, already_exists);\r
+#endif\r
+       return ret;\r
+}\r
+\r
+// ルーティングテーブルの取得\r
+ROUTE_TABLE *GetRouteTable()\r
+{\r
+       ROUTE_TABLE *t = NULL;\r
+       UINT i;\r
+       BUF *buf = NewBuf();\r
+       UCHAR hash[MD5_SIZE];\r
+\r
+#ifdef OS_WIN32\r
+       t = Win32GetRouteTable();\r
+#else  //OS_WIN32\r
+       t = UnixGetRouteTable();\r
+#endif // OS_WIN32\r
+\r
+       WriteBuf(buf, &t->NumEntry, sizeof(t->NumEntry));\r
+\r
+       for (i = 0;i < t->NumEntry;i++)\r
+       {\r
+               ROUTE_ENTRY *e = t->Entry[i];\r
+\r
+               WriteBuf(buf, e, sizeof(ROUTE_ENTRY));\r
+       }\r
+\r
+       Hash(hash, buf->Buf, buf->Size, false);\r
+\r
+       FreeBuf(buf);\r
+\r
+       Copy(&t->HashedValue, hash, sizeof(t->HashedValue));\r
+\r
+       return t;\r
+}\r
+\r
+// ルーティングテーブルの解放\r
+void FreeRouteTable(ROUTE_TABLE *t)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < t->NumEntry;i++)\r
+       {\r
+               Free(t->Entry[i]);\r
+       }\r
+       Free(t->Entry);\r
+       Free(t);\r
+}\r
+\r
+// UDP 受信\r
+UINT RecvFrom(SOCK *sock, IP *src_addr, UINT *src_port, void *data, UINT size)\r
+{\r
+       SOCKET s;\r
+       int ret, sz;\r
+       struct sockaddr_in addr;\r
+       // 引数チェック\r
+       if (sock == NULL || src_addr == NULL || src_port == NULL || data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (sock->Type != SOCK_UDP || sock->socket == INVALID_SOCKET)\r
+       {\r
+               return false;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (sock->IPv6)\r
+       {\r
+               return RecvFrom6(sock, src_addr, src_port, data, size);\r
+       }\r
+\r
+       s = sock->socket;\r
+\r
+       sz = sizeof(addr);\r
+       ret = recvfrom(s, data, size, 0, (struct sockaddr *)&addr, (int *)&sz);\r
+       if (ret > 0)\r
+       {\r
+               InAddrToIP(src_addr, &addr.sin_addr);\r
+               *src_port = (UINT)ntohs(addr.sin_port);\r
+\r
+               Lock(sock->lock);\r
+               {\r
+                       sock->RecvNum++;\r
+                       sock->RecvSize += (UINT64)ret;\r
+               }\r
+               Unlock(sock->lock);\r
+\r
+               // Debug("UDP RecvFrom: %u\n", ret);\r
+\r
+               return (UINT)ret;\r
+       }\r
+       else\r
+       {\r
+               sock->IgnoreRecvErr = false;\r
+\r
+#ifdef OS_WIN32\r
+               if (WSAGetLastError() == WSAECONNRESET)\r
+               {\r
+                       sock->IgnoreRecvErr = true;\r
+               }\r
+               else if (WSAGetLastError() == WSAEWOULDBLOCK)\r
+               {\r
+                       return SOCK_LATER;\r
+               }\r
+               else\r
+               {\r
+                       UINT e = WSAGetLastError();\r
+//                     Debug("RecvFrom Error: %u\n", e);\r
+               }\r
+#else  // OS_WIN32\r
+               if (errno == ECONNREFUSED || errno == ECONNRESET)\r
+               {\r
+                       sock->IgnoreRecvErr = true;\r
+               }\r
+               else if (errno == EAGAIN)\r
+               {\r
+                       return SOCK_LATER;\r
+               }\r
+#endif // OS_WIN32\r
+               return 0;\r
+       }\r
+}\r
+UINT RecvFrom6(SOCK *sock, IP *src_addr, UINT *src_port, void *data, UINT size)\r
+{\r
+       SOCKET s;\r
+       int ret, sz;\r
+       struct sockaddr_in6 addr;\r
+       // 引数チェック\r
+       if (sock == NULL || src_addr == NULL || src_port == NULL || data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (sock->Type != SOCK_UDP || sock->socket == INVALID_SOCKET)\r
+       {\r
+               return false;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       s = sock->socket;\r
+\r
+       sz = sizeof(addr);\r
+       ret = recvfrom(s, data, size, 0, (struct sockaddr *)&addr, (int *)&sz);\r
+       if (ret > 0)\r
+       {\r
+               InAddrToIP6(src_addr, &addr.sin6_addr);\r
+               src_addr->ipv6_scope_id = addr.sin6_scope_id;\r
+               *src_port = (UINT)ntohs(addr.sin6_port);\r
+\r
+               Lock(sock->lock);\r
+               {\r
+                       sock->RecvNum++;\r
+                       sock->RecvSize += (UINT64)ret;\r
+               }\r
+               Unlock(sock->lock);\r
+\r
+               // Debug("UDP RecvFrom: %u\n", ret);\r
+\r
+               return (UINT)ret;\r
+       }\r
+       else\r
+       {\r
+               sock->IgnoreRecvErr = false;\r
+\r
+#ifdef OS_WIN32\r
+               if (WSAGetLastError() == WSAECONNRESET)\r
+               {\r
+                       sock->IgnoreRecvErr = true;\r
+               }\r
+               else if (WSAGetLastError() == WSAEWOULDBLOCK)\r
+               {\r
+                       return SOCK_LATER;\r
+               }\r
+               else\r
+               {\r
+                       UINT e = WSAGetLastError();\r
+                       //                      Debug("RecvFrom Error: %u\n", e);\r
+               }\r
+#else  // OS_WIN32\r
+               if (errno == ECONNREFUSED || errno == ECONNRESET)\r
+               {\r
+                       sock->IgnoreRecvErr = true;\r
+               }\r
+               else if (errno == EAGAIN)\r
+               {\r
+                       return SOCK_LATER;\r
+               }\r
+#endif // OS_WIN32\r
+               return 0;\r
+       }\r
+}\r
+\r
+// OpenSSL のロック\r
+void LockOpenSSL()\r
+{\r
+       Lock(openssl_lock);\r
+}\r
+\r
+// OpenSSL のロック解除\r
+void UnlockOpenSSL()\r
+{\r
+       Unlock(openssl_lock);\r
+}\r
+\r
+\r
+// UDP 送信\r
+UINT SendTo(SOCK *sock, IP *dest_addr, UINT dest_port, void *data, UINT size)\r
+{\r
+       SOCKET s;\r
+       int ret;\r
+       struct sockaddr_in addr;\r
+       // 引数チェック\r
+       if (sock == NULL || dest_addr == NULL || dest_port == 0 || data == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (dest_port >= 65536)\r
+       {\r
+               return 0;\r
+       }\r
+       if (sock->Type != SOCK_UDP || sock->socket == INVALID_SOCKET)\r
+       {\r
+               return 0;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (sock->IPv6)\r
+       {\r
+               return SendTo6(sock, dest_addr, dest_port, data, size);\r
+       }\r
+\r
+       if (IsIP4(dest_addr) == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       s = sock->socket;\r
+       Zero(&addr, sizeof(addr));\r
+       addr.sin_family = AF_INET;\r
+       addr.sin_port = htons((USHORT)dest_port);\r
+       IPToInAddr(&addr.sin_addr, dest_addr);\r
+\r
+       if (dest_addr->addr[0] == 255 && dest_addr->addr[1] == 255 && \r
+               dest_addr->addr[2] == 255 && dest_addr->addr[3] == 255)\r
+       {\r
+               if (sock->UdpBroadcast == false)\r
+               {\r
+                       bool yes = true;\r
+\r
+                       sock->UdpBroadcast = true;\r
+\r
+                       setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&yes, sizeof(yes));\r
+               }\r
+       }\r
+\r
+       ret = sendto(s, data, size, 0, (struct sockaddr *)&addr, sizeof(addr));\r
+       if (ret != (int)size)\r
+       {\r
+               sock->IgnoreSendErr = false;\r
+\r
+#ifdef OS_WIN32\r
+               if (WSAGetLastError() == WSAECONNRESET)\r
+               {\r
+                       sock->IgnoreSendErr = true;\r
+               }\r
+               else if (WSAGetLastError() == WSAEWOULDBLOCK)\r
+               {\r
+                       return SOCK_LATER;\r
+               }\r
+               else\r
+               {\r
+                       UINT e = WSAGetLastError();\r
+               }\r
+#else  // OS_WIN32\r
+               if (errno == ECONNREFUSED || errno == ECONNRESET)\r
+               {\r
+                       sock->IgnoreRecvErr = true;\r
+               }\r
+               else if (errno == EAGAIN)\r
+               {\r
+                       return SOCK_LATER;\r
+               }\r
+#endif // OS_WIN32\r
+               return 0;\r
+       }\r
+\r
+       Lock(sock->lock);\r
+       {\r
+               sock->SendSize += (UINT64)size;\r
+               sock->SendNum++;\r
+       }\r
+       Unlock(sock->lock);\r
+\r
+       return ret;\r
+}\r
+UINT SendTo6(SOCK *sock, IP *dest_addr, UINT dest_port, void *data, UINT size)\r
+{\r
+       SOCKET s;\r
+       int ret;\r
+       struct sockaddr_in6 addr;\r
+       UINT type;\r
+       // 引数チェック\r
+       if (sock == NULL || dest_addr == NULL || dest_port == 0 || data == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (dest_port >= 65536)\r
+       {\r
+               return 0;\r
+       }\r
+       if (sock->Type != SOCK_UDP || sock->socket == INVALID_SOCKET)\r
+       {\r
+               return 0;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (IsIP6(dest_addr) == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       s = sock->socket;\r
+       Zero(&addr, sizeof(addr));\r
+       addr.sin6_family = AF_INET6;\r
+       addr.sin6_port = htons((USHORT)dest_port);\r
+       IPToInAddr6(&addr.sin6_addr, dest_addr);\r
+       addr.sin6_scope_id = dest_addr->ipv6_scope_id;\r
+\r
+       type = GetIPAddrType6(dest_addr);\r
+\r
+       if (type & IPV6_ADDR_MULTICAST)\r
+       {\r
+               if (sock->UdpBroadcast == false)\r
+               {\r
+                       bool yes = true;\r
+\r
+                       sock->UdpBroadcast = true;\r
+\r
+                       setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&yes, sizeof(yes));\r
+               }\r
+       }\r
+\r
+       ret = sendto(s, data, size, 0, (struct sockaddr *)&addr, sizeof(addr));\r
+       if (ret != (int)size)\r
+       {\r
+               sock->IgnoreSendErr = false;\r
+\r
+#ifdef OS_WIN32\r
+               if (WSAGetLastError() == WSAECONNRESET)\r
+               {\r
+                       sock->IgnoreSendErr = true;\r
+               }\r
+               else if (WSAGetLastError() == WSAEWOULDBLOCK)\r
+               {\r
+                       return SOCK_LATER;\r
+               }\r
+               else\r
+               {\r
+                       UINT e = WSAGetLastError();\r
+               }\r
+#else  // OS_WIN32\r
+               if (errno == ECONNREFUSED || errno == ECONNRESET)\r
+               {\r
+                       sock->IgnoreRecvErr = true;\r
+               }\r
+               else if (errno == EAGAIN)\r
+               {\r
+                       return SOCK_LATER;\r
+               }\r
+#endif // OS_WIN32\r
+               return 0;\r
+       }\r
+\r
+       Lock(sock->lock);\r
+       {\r
+               sock->SendSize += (UINT64)size;\r
+               sock->SendNum++;\r
+       }\r
+       Unlock(sock->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// UDP ソケットの作成と初期化\r
+// port が 0 の場合は OS がランダムに割り当てる\r
+SOCK *NewUDP(UINT port)\r
+{\r
+       return NewUDPEx(port, false);\r
+}\r
+SOCK *NewUDPEx(UINT port, bool ipv6)\r
+{\r
+       if (ipv6 == false)\r
+       {\r
+               return NewUDP4(port);\r
+       }\r
+       else\r
+       {\r
+               return NewUDP6(port);\r
+       }\r
+}\r
+SOCK *NewUDP4(UINT port)\r
+{\r
+       SOCK *sock;\r
+       SOCKET s;\r
+       struct sockaddr_in addr;\r
+\r
+       s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&addr, sizeof(addr));\r
+       addr.sin_family = AF_INET;\r
+       addr.sin_addr.s_addr = htonl(INADDR_ANY);\r
+       if (port == 0)\r
+       {\r
+               addr.sin_port = 0;\r
+       }\r
+       else\r
+       {\r
+               addr.sin_port = htons((USHORT)port);\r
+       }\r
+\r
+       if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) != 0)\r
+       {\r
+               // 失敗\r
+               closesocket(s);\r
+               return NULL;\r
+       }\r
+\r
+       sock = NewSock();\r
+\r
+       sock->Type = SOCK_UDP;\r
+       sock->Connected = false;\r
+       sock->AsyncMode = false;\r
+       sock->ServerMode = false;\r
+       if (port != 0)\r
+       {\r
+               sock->ServerMode = true;\r
+       }\r
+\r
+       sock->socket = s;\r
+\r
+       QuerySocketInformation(sock);\r
+\r
+       return sock;\r
+}\r
+SOCK *NewUDP6(UINT port)\r
+{\r
+       SOCK *sock;\r
+       SOCKET s;\r
+       struct sockaddr_in6 addr;\r
+\r
+       s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&addr, sizeof(addr));\r
+       addr.sin6_family = AF_INET6;\r
+       if (port == 0)\r
+       {\r
+               addr.sin6_port = 0;\r
+       }\r
+       else\r
+       {\r
+               addr.sin6_port = htons((USHORT)port);\r
+       }\r
+\r
+       if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) != 0)\r
+       {\r
+               // 失敗\r
+               closesocket(s);\r
+               return NULL;\r
+       }\r
+\r
+       sock = NewSock();\r
+\r
+       sock->Type = SOCK_UDP;\r
+       sock->Connected = false;\r
+       sock->AsyncMode = false;\r
+       sock->ServerMode = false;\r
+       sock->IPv6 = true;\r
+       if (port != 0)\r
+       {\r
+               sock->ServerMode = true;\r
+       }\r
+\r
+       sock->socket = s;\r
+\r
+       QuerySocketInformation(sock);\r
+\r
+       return sock;\r
+}\r
+\r
+// Select 関数\r
+void Select(SOCKSET *set, UINT timeout, CANCEL *c1, CANCEL *c2)\r
+{\r
+#ifdef OS_WIN32\r
+       Win32Select(set, timeout, c1, c2);\r
+#else\r
+       UnixSelect(set, timeout, c1, c2);\r
+#endif // OS_WIN32\r
+}\r
+\r
+// ソケットセットにソケットを追加\r
+void AddSockSet(SOCKSET *set, SOCK *sock)\r
+{\r
+       // 引数チェック\r
+       if (set == NULL || sock == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (sock->Type == SOCK_TCP && sock->Connected == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (set->NumSocket >= MAX_SOCKSET_NUM)\r
+       {\r
+               // 上限\r
+               return;\r
+       }\r
+       set->Sock[set->NumSocket++] = sock;\r
+}\r
+\r
+// ソケットセットの初期化\r
+void InitSockSet(SOCKSET *set)\r
+{\r
+       // 引数チェック\r
+       if (set == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(set, sizeof(SOCKSET));\r
+}\r
+\r
+// TCP すべて受信\r
+bool RecvAll(SOCK *sock, void *data, UINT size, bool secure)\r
+{\r
+       UINT recv_size, sz, ret;\r
+       // 引数チェック\r
+       if (sock == NULL || data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               return true;\r
+       }\r
+       if (sock->AsyncMode)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       recv_size = 0;\r
+\r
+       while (true)\r
+       {\r
+               sz = size - recv_size;\r
+               ret = Recv(sock, (UCHAR *)data + recv_size, sz, secure);\r
+               if (ret == 0)\r
+               {\r
+                       return false;\r
+               }\r
+               recv_size += ret;\r
+               if (recv_size >= size)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+}\r
+\r
+// TCP 送信バッファを送信する\r
+bool SendNow(SOCK *sock, int secure)\r
+{\r
+       bool ret;\r
+       // 引数チェック\r
+       if (sock == NULL || sock->AsyncMode != false)\r
+       {\r
+               return false;\r
+       }\r
+       if (sock->SendBuf->Size == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       ret = SendAll(sock, sock->SendBuf->Buf, sock->SendBuf->Size, secure);\r
+       ClearBuf(sock->SendBuf);\r
+\r
+       return ret;\r
+}\r
+\r
+// TCP 送信バッファ追加\r
+void SendAdd(SOCK *sock, void *data, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (sock == NULL || data == NULL || size == 0 || sock->AsyncMode != false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       WriteBuf(sock->SendBuf, data, size);\r
+}\r
+\r
+// TCP すべて送信\r
+bool SendAll(SOCK *sock, void *data, UINT size, bool secure)\r
+{\r
+       UCHAR *buf;\r
+       UINT sent_size;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (sock == NULL || data == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (sock->AsyncMode)\r
+       {\r
+               return false;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       buf = (UCHAR *)data;\r
+       sent_size = 0;\r
+\r
+       while (true)\r
+       {\r
+               ret = Send(sock, buf, size - sent_size, secure);\r
+               if (ret == 0)\r
+               {\r
+                       return false;\r
+               }\r
+               sent_size += ret;\r
+               buf += ret;\r
+               if (sent_size >= size)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+}\r
+\r
+// 使用したい暗号化アルゴリズム名を設定する\r
+void SetWantToUseCipher(SOCK *sock, char *name)\r
+{\r
+       // 引数チェック\r
+       if (sock == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (sock->WaitToUseCipher)\r
+       {\r
+               Free(sock->WaitToUseCipher);\r
+       }\r
+       sock->WaitToUseCipher = CopyStr(name);\r
+}\r
+\r
+// TCP-SSL 通信を開始する\r
+bool StartSSL(SOCK *sock, X *x, K *priv)\r
+{\r
+       return StartSSLEx(sock, x, priv, false);\r
+}\r
+bool StartSSLEx(SOCK *sock, X *x, K *priv, bool client_tls)\r
+{\r
+       X509 *x509;\r
+       EVP_PKEY *key;\r
+       UINT prev_timeout = 1024;\r
+\r
+#ifdef UNIX_SOLARIS\r
+       SOCKET_TIMEOUT_PARAM *ttparam;\r
+#endif //UNIX_SOLARIS\r
+\r
+       // 引数チェック\r
+       if (sock == NULL)\r
+       {\r
+               Debug("StartSSL Error: #0\n");\r
+               return false;\r
+       }\r
+       if (sock->Connected == false || sock->socket == INVALID_SOCKET ||\r
+               sock->ListenMode != false)\r
+       {\r
+               Debug("StartSSL Error: #1\n");\r
+               return false;\r
+       }\r
+       if (x != NULL && priv == NULL)\r
+       {\r
+               Debug("StartSSL Error: #2\n");\r
+               return false;\r
+       }\r
+\r
+       if (sock->SecureMode)\r
+       {\r
+               Debug("StartSSL Error: #3\n");\r
+               // すでに SSL 通信が開始されている\r
+               return true;\r
+       }\r
+\r
+       Lock(sock->ssl_lock);\r
+       if (sock->SecureMode)\r
+       {\r
+               Debug("StartSSL Error: #4\n");\r
+               // すでに SSL 通信が開始されている\r
+               Unlock(sock->ssl_lock);\r
+               return true;\r
+       }\r
+\r
+       Lock(openssl_lock);\r
+       {\r
+               if (sock->ServerMode)\r
+               {\r
+                       SSL_CTX_set_ssl_version(ssl_ctx, SSLv23_method());\r
+               }\r
+               else\r
+               {\r
+                       if (client_tls == false)\r
+                       {\r
+                               SSL_CTX_set_ssl_version(ssl_ctx, SSLv3_method());\r
+                       }\r
+                       else\r
+                       {\r
+                               SSL_CTX_set_ssl_version(ssl_ctx, TLSv1_client_method());\r
+                       }\r
+               }\r
+               sock->ssl = SSL_new(ssl_ctx);\r
+               SSL_set_fd(sock->ssl, (int)sock->socket);\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       if (x != NULL)\r
+       {\r
+               // 証明書と秘密鍵のチェック\r
+               if (CheckXandK(x, priv))\r
+               {\r
+                       // 証明書を使用する\r
+                       x509 = x->x509;\r
+                       key = priv->pkey;\r
+\r
+                       Lock(openssl_lock);\r
+                       {\r
+                               SSL_use_certificate(sock->ssl, x509);\r
+                               SSL_use_PrivateKey(sock->ssl, key);\r
+                       }\r
+                       Unlock(openssl_lock);\r
+               }\r
+       }\r
+\r
+       if (sock->WaitToUseCipher != NULL)\r
+       {\r
+               // 使用したい暗号化アルゴリズム名を設定する\r
+               Lock(openssl_lock);\r
+               {\r
+                       SSL_set_cipher_list(sock->ssl, sock->WaitToUseCipher);\r
+               }\r
+               Unlock(openssl_lock);\r
+       }\r
+\r
+       if (sock->ServerMode)\r
+       {\r
+//             Lock(ssl_connect_lock);\r
+\r
+// SOLARIS用タイムアウトスレッドの起動\r
+#ifdef UNIX_SOLARIS\r
+               ttparam = NewSocketTimeout(sock);\r
+#endif // UNIX_SOLARIS\r
+\r
+               // サーバーモード\r
+               if (SSL_accept(sock->ssl) <= 0)\r
+               {\r
+\r
+// タイムアウトスレッドの停止\r
+#ifdef UNIX_SOLARIS\r
+                       FreeSocketTimeout(ttparam);\r
+#endif // UNIX_SOLARIS\r
+\r
+                       //                      Unlock(ssl_connect_lock);\r
+                       // SSL-Accept 失敗\r
+                       Lock(openssl_lock);\r
+                       {\r
+                               SSL_free(sock->ssl);\r
+                       }\r
+                       Unlock(openssl_lock);\r
+\r
+                       Unlock(sock->ssl_lock);\r
+                       Debug("StartSSL Error: #5\n");\r
+                       return false;\r
+               }\r
+\r
+// タイムアウトスレッドの停止\r
+#ifdef UNIX_SOLARIS\r
+               FreeSocketTimeout(ttparam);\r
+#endif // UNIX_SOLARIS\r
+\r
+               //              Unlock(ssl_connect_lock);\r
+       }\r
+       else\r
+       {\r
+               prev_timeout = GetTimeout(sock);\r
+               SetTimeout(sock, TIMEOUT_SSL_CONNECT);\r
+               Lock(ssl_connect_lock);\r
+               // クライアントモード\r
+               if (SSL_connect(sock->ssl) <= 0)\r
+               {\r
+                       Unlock(ssl_connect_lock);\r
+                       // SSL-connect 失敗\r
+                       Lock(openssl_lock);\r
+                       {\r
+                               SSL_free(sock->ssl);\r
+                       }\r
+                       Unlock(openssl_lock);\r
+\r
+                       Unlock(sock->ssl_lock);\r
+                       Debug("StartSSL Error: #5\n");\r
+                       SetTimeout(sock, prev_timeout);\r
+                       return false;\r
+               }\r
+               Unlock(ssl_connect_lock);\r
+               SetTimeout(sock, prev_timeout);\r
+       }\r
+\r
+       // SSL 通信が開始された\r
+       sock->SecureMode = true;\r
+\r
+       // リモートホストの証明書を取得する\r
+       Lock(openssl_lock);\r
+       {\r
+               x509 = SSL_get_peer_certificate(sock->ssl);\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       if (x509 == NULL)\r
+       {\r
+               // リモートホストに証明書は存在しない\r
+               sock->RemoteX = NULL;\r
+       }\r
+       else\r
+       {\r
+               // 証明書を取得できた\r
+               sock->RemoteX = X509ToX(x509);\r
+       }\r
+\r
+       // ローカルホストの証明書を取得する\r
+       Lock(openssl_lock);\r
+       {\r
+               x509 = SSL_get_certificate(sock->ssl);\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       if (x509 == NULL)\r
+       {\r
+               // リモートホストに証明書は存在しない\r
+               sock->LocalX = NULL;\r
+       }\r
+       else\r
+       {\r
+               X *local_x;\r
+               // 証明書を取得できた\r
+               local_x = X509ToX(x509);\r
+               local_x->do_not_free = true;\r
+               sock->LocalX = CloneX(local_x);\r
+               FreeX(local_x);\r
+       }\r
+\r
+       // 自動再試行モード\r
+       SSL_set_mode(sock->ssl, SSL_MODE_AUTO_RETRY);\r
+\r
+       // へんなフラグ\r
+       SSL_set_mode(sock->ssl, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);\r
+\r
+       // 暗号化に使用しているアルゴリズム名を取得\r
+       Lock(openssl_lock);\r
+       {\r
+               sock->CipherName = CopyStr((char *)SSL_get_cipher(sock->ssl));\r
+       }\r
+       Unlock(openssl_lock);\r
+\r
+       Unlock(sock->ssl_lock);\r
+\r
+       return true;\r
+}\r
+\r
+// TCP-SSL 受信\r
+UINT SecureRecv(SOCK *sock, void *data, UINT size)\r
+{\r
+       SOCKET s;\r
+       int ret, e = 0;\r
+       SSL *ssl;\r
+\r
+#ifdef UNIX_SOLARIS\r
+       SOCKET_TIMEOUT_PARAM *ttparam;\r
+#endif //UNIX_SOLARIS\r
+\r
+       s = sock->socket;\r
+       ssl = sock->ssl;\r
+\r
+       if (sock->AsyncMode)\r
+       {\r
+               // 非同期モードの場合はデータが 1 バイトでも読み出し可能かどうか確認する。\r
+               // 読み出し可能なデータが無い場合に read をしてしまうとブロッキングするため\r
+               // それは避けなければならない。\r
+               char c;\r
+               Lock(sock->ssl_lock);\r
+               {\r
+                       if (sock->Connected == false)\r
+                       {\r
+                               Unlock(sock->ssl_lock);\r
+                               Debug("%s %u SecureRecv() Disconnect\n", __FILE__, __LINE__);\r
+                               return 0;\r
+                       }\r
+                       ret = SSL_peek(ssl, &c, sizeof(c));\r
+               }\r
+               Unlock(sock->ssl_lock);\r
+               if (ret == 0)\r
+               {\r
+                       // 通信が切れておる\r
+                       Disconnect(sock);\r
+                       Debug("%s %u SecureRecv() Disconnect\n", __FILE__, __LINE__);\r
+                       return 0;\r
+               }\r
+               if (ret < 0)\r
+               {\r
+                       // エラーが発生した\r
+                       e = SSL_get_error(ssl, ret);\r
+                       if (e == SSL_ERROR_WANT_READ || e == SSL_ERROR_WANT_WRITE || e == SSL_ERROR_SSL)\r
+                       {\r
+                               // パケットがまだ届いていない、つまり read してはいけない\r
+                               return SOCK_LATER;\r
+                       }\r
+               }\r
+       }\r
+\r
+       // 受信する\r
+       Lock(sock->ssl_lock);\r
+       {\r
+               if (sock->Connected == false)\r
+               {\r
+                       Unlock(sock->ssl_lock);\r
+                       Debug("%s %u SecureRecv() Disconnect\n", __FILE__, __LINE__);\r
+                       return 0;\r
+               }\r
+\r
+#ifdef OS_UNIX\r
+               if (sock->AsyncMode == false)\r
+               {\r
+                       sock->CallingThread = pthread_self();\r
+               }\r
+#endif // OS_UNIX\r
+\r
+// SOLARIS用タイムアウトスレッドの起動\r
+#ifdef UNIX_SOLARIS\r
+               ttparam = NewSocketTimeout(sock);\r
+#endif // UNIX_SOLARIS\r
+\r
+               ret = SSL_read(ssl, data, size);\r
+\r
+// タイムアウトスレッドの停止\r
+#ifdef UNIX_SOLARIS\r
+               FreeSocketTimeout(ttparam);\r
+#endif // UNIX_SOLARIS\r
+\r
+\r
+#ifdef OS_UNIX\r
+               if (sock->AsyncMode == false)\r
+               {\r
+                       sock->CallingThread = 0;\r
+               }\r
+#endif // OS_UNIX\r
+\r
+               if (ret < 0)\r
+               {\r
+                       e = SSL_get_error(ssl, ret);\r
+               }\r
+\r
+       }\r
+       Unlock(sock->ssl_lock);\r
+       if (ret > 0)\r
+       {\r
+               // 受信成功\r
+               sock->RecvSize += (UINT64)ret;\r
+               sock->RecvNum++;\r
+               return (UINT)ret;\r
+       }\r
+       if (ret == 0)\r
+       {\r
+               // 通信切断\r
+               Disconnect(sock);\r
+               Debug("%s %u SecureRecv() Disconnect\n", __FILE__, __LINE__);\r
+               return 0;\r
+       }\r
+       if (sock->AsyncMode)\r
+       {\r
+               if (e == SSL_ERROR_WANT_READ || e == SSL_ERROR_WANT_WRITE || e == SSL_ERROR_SSL)\r
+               {\r
+                       // パケットがまだ届いていない\r
+                       return SOCK_LATER;\r
+               }\r
+       }\r
+       Disconnect(sock);\r
+       Debug("%s %u SecureRecv() Disconnect\n", __FILE__, __LINE__);\r
+       return 0;\r
+}\r
+\r
+// TCP-SSL 送信\r
+UINT SecureSend(SOCK *sock, void *data, UINT size)\r
+{\r
+       SOCKET s;\r
+       int ret, e;\r
+       SSL *ssl;\r
+       s = sock->socket;\r
+       ssl = sock->ssl;\r
+\r
+       if (sock->AsyncMode)\r
+       {\r
+               // 非同期モード\r
+               SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE);\r
+       }\r
+\r
+       // 送信\r
+       Lock(sock->ssl_lock);\r
+       {\r
+               if (sock->Connected == false)\r
+               {\r
+                       Unlock(sock->ssl_lock);\r
+                       Debug("%s %u SecureRecv() Disconnect\n", __FILE__, __LINE__);\r
+                       return 0;\r
+               }\r
+\r
+               ret = SSL_write(ssl, data, size);\r
+               if (ret < 0)\r
+               {\r
+                       e = SSL_get_error(ssl, ret);\r
+               }\r
+       }\r
+       Unlock(sock->ssl_lock);\r
+\r
+       if (ret > 0)\r
+       {\r
+               // 送信成功\r
+               sock->SendSize += (UINT64)ret;\r
+               sock->SendNum++;\r
+               sock->WriteBlocked = false;\r
+               return (UINT)ret;\r
+       }\r
+       if (ret == 0)\r
+       {\r
+               // 切断\r
+               Debug("%s %u SecureRecv() Disconnect\n", __FILE__, __LINE__);\r
+               Disconnect(sock);\r
+               return 0;\r
+       }\r
+\r
+       if (sock->AsyncMode)\r
+       {\r
+               // エラー値の確認\r
+               if (e == SSL_ERROR_WANT_READ || e == SSL_ERROR_WANT_WRITE || e == SSL_ERROR_SSL)\r
+               {\r
+                       sock->WriteBlocked = true;\r
+                       return SOCK_LATER;\r
+               }\r
+               Debug("%s %u e=%u\n", __FILE__, __LINE__, e);\r
+       }\r
+       //Debug("%s %u SecureRecv() Disconnect\n", __FILE__, __LINE__);\r
+       Disconnect(sock);\r
+       return 0;\r
+}\r
+\r
+// TCP 受信\r
+UINT Recv(SOCK *sock, void *data, UINT size, bool secure)\r
+{\r
+       SOCKET s;\r
+       int ret;\r
+\r
+#ifdef UNIX_SOLARIS\r
+       SOCKET_TIMEOUT_PARAM *ttparam;\r
+#endif //UNIX_SOLARIS\r
+\r
+       // 引数チェック\r
+       if (sock == NULL || data == NULL || size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+       if (sock->Type != SOCK_TCP || sock->Connected == false || sock->ListenMode != false ||\r
+               sock->socket == INVALID_SOCKET)\r
+       {\r
+               return 0;\r
+       }\r
+       if (secure != false && sock->SecureMode == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (secure)\r
+       {\r
+               return SecureRecv(sock, data, size);\r
+       }\r
+\r
+       // 受信\r
+       s = sock->socket;\r
+\r
+\r
+#ifdef OS_UNIX\r
+       if (sock->AsyncMode == false)\r
+       {\r
+               sock->CallingThread = pthread_self();\r
+       }\r
+#endif // OS_UNIX\r
+\r
+// SOLARIS用タイムアウトスレッドの開始\r
+#ifdef UNIX_SOLARIS\r
+       ttparam = NewSocketTimeout(sock);\r
+#endif // UNIX_SOLARIS\r
+\r
+       ret = recv(s, data, size, 0);\r
+\r
+// タイムアウトスレッドの停止\r
+#ifdef UNIX_SOLARIS\r
+       FreeSocketTimeout(ttparam);\r
+#endif // UNIX_SOLARIS\r
+\r
+#ifdef OS_UNIX\r
+       if (sock->AsyncMode == false)\r
+       {\r
+               sock->CallingThread = 0;\r
+       }\r
+#endif // OS_UNIX\r
+\r
+       if (ret > 0)\r
+       {\r
+               // 受信成功\r
+               Lock(sock->lock);\r
+               {\r
+                       sock->RecvSize += (UINT64)ret;\r
+                       sock->SendNum++;\r
+               }\r
+               Unlock(sock->lock);\r
+               return (UINT)ret;\r
+       }\r
+\r
+       // 送信失敗\r
+       if (sock->AsyncMode)\r
+       {\r
+               // 非同期モードの場合、エラーを調べる\r
+               if (ret == SOCKET_ERROR)\r
+               {\r
+#ifdef OS_WIN32\r
+                       if (WSAGetLastError() == WSAEWOULDBLOCK)\r
+                       {\r
+                               // ブロッキングしている\r
+                               return SOCK_LATER;\r
+                       }\r
+                       else\r
+                       {\r
+                               Debug("Socket Error: %u\n", WSAGetLastError());\r
+                       }\r
+#else  // OS_WIN32\r
+                       if (errno == EAGAIN)\r
+                       {\r
+                               // ブロッキングしている\r
+                               return SOCK_LATER;\r
+                       }\r
+#endif // OS_WIN32\r
+               }\r
+       }\r
+\r
+       // 切断された\r
+       Disconnect(sock);\r
+       return 0;\r
+}\r
+\r
+// TCP 送信\r
+UINT Send(SOCK *sock, void *data, UINT size, bool secure)\r
+{\r
+       SOCKET s;\r
+       int ret;\r
+       // 引数チェック\r
+       if (sock == NULL || data == NULL || size == 0)\r
+       {\r
+               return 0;\r
+       }\r
+       size = MIN(size, MAX_SEND_BUF_MEM_SIZE);\r
+       if (sock->Type != SOCK_TCP || sock->Connected == false || sock->ListenMode != false ||\r
+               sock->socket == INVALID_SOCKET)\r
+       {\r
+               return 0;\r
+       }\r
+       if (secure != false && sock->SecureMode == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (secure)\r
+       {\r
+               return SecureSend(sock, data, size);\r
+       }\r
+\r
+       // 送信\r
+       s = sock->socket;\r
+       ret = send(s, data, size, 0);\r
+       if (ret > 0)\r
+       {\r
+               // 送信成功\r
+               Lock(sock->lock);\r
+               {\r
+                       sock->SendSize += (UINT64)ret;\r
+                       sock->SendNum++;\r
+               }\r
+               Unlock(sock->lock);\r
+               sock->WriteBlocked = false;\r
+               return (UINT)ret;\r
+       }\r
+\r
+       // 送信失敗\r
+       if (sock->AsyncMode)\r
+       {\r
+               // 非同期モードの場合、エラーを調べる\r
+               if (ret == SOCKET_ERROR)\r
+               {\r
+#ifdef OS_WIN32\r
+                       if (WSAGetLastError() == WSAEWOULDBLOCK)\r
+                       {\r
+                               // ブロッキングしている\r
+                               sock->WriteBlocked = true;\r
+                               return SOCK_LATER;\r
+                       }\r
+                       else\r
+                       {\r
+                               Debug("Socket Error: %u\n", WSAGetLastError());\r
+                       }\r
+#else  // OS_WIN32\r
+                       if (errno == EAGAIN)\r
+                       {\r
+                               // ブロッキングしている\r
+                               sock->WriteBlocked = true;\r
+                               return SOCK_LATER;\r
+                       }\r
+#endif // OS_WIN32\r
+               }\r
+       }\r
+\r
+       // 切断された\r
+       Disconnect(sock);\r
+       return 0;\r
+}\r
+\r
+// タイムアウトの取得 (ミリ秒)\r
+UINT GetTimeout(SOCK *sock)\r
+{\r
+       // 引数チェック\r
+       if (sock == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+       if (sock->Type != SOCK_TCP)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       return sock->TimeOut;\r
+}\r
+\r
+// タイムアウト時間の設定 (ミリ秒)\r
+void SetTimeout(SOCK *sock, UINT timeout)\r
+{\r
+       // 引数チェック\r
+       if (sock == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (sock->Type != SOCK_TCP)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (timeout == INFINITE)\r
+       {\r
+               timeout = TIMEOUT_INFINITE;\r
+       }\r
+\r
+       sock->TimeOut = timeout;\r
+\r
+//     Debug("SetTimeout(%u)\n",timeout);\r
+\r
+#ifdef OS_WIN32\r
+       setsockopt(sock->socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(UINT));\r
+       setsockopt(sock->socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(UINT));\r
+#endif\r
+\r
+#ifdef OS_UNIX\r
+#ifndef UNIX_SOLARIS\r
+       {\r
+               struct timeval tv_timeout;\r
+\r
+               tv_timeout.tv_sec = timeout / 1000; // miliseconds to seconds\r
+               tv_timeout.tv_usec = (timeout % 1000) * 1000; // miliseconds to microseconds\r
+\r
+               setsockopt(sock->socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv_timeout, sizeof(tv_timeout));\r
+               setsockopt(sock->socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv_timeout, sizeof(tv_timeout));\r
+       }\r
+#endif // UNIX_SOLARIS\r
+#endif // OS_UNIX\r
+}\r
+\r
+// 接続受諾初期化\r
+void AcceptInit(SOCK *s)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(tmp, sizeof(tmp));\r
+       if (GetHostName(tmp, sizeof(tmp), &s->RemoteIP) == false ||\r
+               IsEmptyStr(tmp))\r
+       {\r
+               IPToStr(tmp, sizeof(tmp), &s->RemoteIP);\r
+       }\r
+\r
+       s->RemoteHostname = CopyStr(tmp);\r
+}\r
+\r
+// TCP 接続受諾\r
+SOCK *Accept(SOCK *sock)\r
+{\r
+       SOCK *ret;\r
+       SOCKET s, new_socket;\r
+       int size;\r
+       struct sockaddr_in addr;\r
+       bool true_flag = true;\r
+       // 引数チェック\r
+       if (sock == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (sock->ListenMode == false || sock->Type != SOCK_TCP || sock->ServerMode == false)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (sock->CancelAccept)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (sock->IPv6)\r
+       {\r
+               return Accept6(sock);\r
+       }\r
+\r
+       s = sock->socket;\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               return NULL;\r
+       }\r
+       Zero(&addr, sizeof(addr));\r
+       size = sizeof(addr);\r
+\r
+#ifdef OS_UNIX\r
+       sock->CallingThread = pthread_self();\r
+#endif // OS_UNIX\r
+\r
+       new_socket = accept(s, (struct sockaddr *)&addr,(int *)&size);\r
+\r
+#ifdef OS_UNIX\r
+       sock->CallingThread = 0;\r
+#endif // OS_UNIX\r
+\r
+       if (new_socket == INVALID_SOCKET)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (sock->CancelAccept)\r
+       {\r
+               closesocket(new_socket);\r
+               return NULL;\r
+       }\r
+\r
+       ret = NewSock();\r
+       ret->socket = new_socket;\r
+       ret->Connected = true;\r
+       ret->AsyncMode = false;\r
+       ret->Type = SOCK_TCP;\r
+       ret->ServerMode = true;\r
+       ret->SecureMode = false;\r
+\r
+       // TCP オプションの設定\r
+       setsockopt(ret->socket, IPPROTO_TCP, TCP_NODELAY, (char *)&true_flag, sizeof(bool));\r
+\r
+       SetSockPriorityHigh(ret);\r
+\r
+       // タイムアウト値の初期化\r
+       SetTimeout(ret, TIMEOUT_INFINITE);\r
+\r
+       // ソケット情報\r
+       QuerySocketInformation(ret);\r
+\r
+       AddIpClient(&ret->RemoteIP);\r
+\r
+       return ret;\r
+}\r
+SOCK *Accept6(SOCK *sock)\r
+{\r
+       SOCK *ret;\r
+       SOCKET s, new_socket;\r
+       int size;\r
+       struct sockaddr_in6 addr;\r
+       bool true_flag = true;\r
+       // 引数チェック\r
+       if (sock == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (sock->ListenMode == false || sock->Type != SOCK_TCP || sock->ServerMode == false)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (sock->CancelAccept)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (sock->IPv6 == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       s = sock->socket;\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               return NULL;\r
+       }\r
+       Zero(&addr, sizeof(addr));\r
+       size = sizeof(addr);\r
+\r
+#ifdef OS_UNIX\r
+       sock->CallingThread = pthread_self();\r
+#endif // OS_UNIX\r
+\r
+       new_socket = accept(s, (struct sockaddr *)&addr,(int *)&size);\r
+\r
+#ifdef OS_UNIX\r
+       sock->CallingThread = 0;\r
+#endif // OS_UNIX\r
+\r
+       if (new_socket == INVALID_SOCKET)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (sock->CancelAccept)\r
+       {\r
+               closesocket(new_socket);\r
+               return NULL;\r
+       }\r
+\r
+       ret = NewSock();\r
+       ret->socket = new_socket;\r
+       ret->Connected = true;\r
+       ret->AsyncMode = false;\r
+       ret->Type = SOCK_TCP;\r
+       ret->ServerMode = true;\r
+       ret->SecureMode = false;\r
+\r
+       // TCP オプションの設定\r
+       setsockopt(ret->socket, IPPROTO_TCP, TCP_NODELAY, (char *)&true_flag, sizeof(bool));\r
+\r
+       SetSockPriorityHigh(ret);\r
+\r
+       // タイムアウト値の初期化\r
+       SetTimeout(ret, TIMEOUT_INFINITE);\r
+\r
+       // ソケット情報\r
+       QuerySocketInformation(ret);\r
+\r
+       AddIpClient(&ret->RemoteIP);\r
+\r
+       return ret;\r
+}\r
+\r
+// TCP 待ち受け (IPv6)\r
+SOCK *Listen6(UINT port)\r
+{\r
+       return ListenEx6(port, false);\r
+}\r
+SOCK *ListenEx6(UINT port, bool local_only)\r
+{\r
+       SOCKET s;\r
+       SOCK *sock;\r
+       struct sockaddr_in6 addr;\r
+       struct in6_addr in;\r
+       bool true_flag = true;\r
+       IP localhost;\r
+       // 引数チェック\r
+       if (port == 0 || port >= 65536)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 初期化\r
+       Zero(&addr, sizeof(addr));\r
+       Zero(&in, sizeof(in));\r
+       GetLocalHostIP6(&localhost);\r
+\r
+       addr.sin6_port = htons((UINT)port);\r
+       addr.sin6_family = AF_INET6;\r
+\r
+       if (local_only)\r
+       {\r
+               IPToInAddr6(&addr.sin6_addr, &localhost);\r
+       }\r
+\r
+       // ソケットの作成\r
+       s = socket(AF_INET6, SOCK_STREAM, 0);\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+#ifdef OS_UNIX\r
+       // UNIX 系では IPv6 Only フラグを立てる必要がある\r
+       setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &true_flag, sizeof(true_flag));\r
+#endif // OS_UNIX\r
+\r
+       //SetSocketSendRecvBufferSize(s, SOCKET_BUFFER_SIZE);\r
+\r
+#ifdef OS_UNIX\r
+       // Windows 系 OS は REUSEADDR の実装にバグがあるっぽいので\r
+       // UNIX 系のみ有効にした。\r
+       setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&true_flag, sizeof(bool));\r
+#endif // OS_UNIX\r
+\r
+       if (bind(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_in6)) != 0)\r
+       {\r
+               // bind 失敗\r
+               closesocket(s);\r
+               return NULL;\r
+       }\r
+       if (listen(s, SOMAXCONN))\r
+       {\r
+               // listen 失敗\r
+               closesocket(s);\r
+               return NULL;\r
+       }\r
+\r
+       // 成功\r
+       sock = NewSock();\r
+       sock->Connected = false;\r
+       sock->AsyncMode = false;\r
+       sock->ServerMode = true;\r
+       sock->Type = SOCK_TCP;\r
+       sock->socket = s;\r
+       sock->ListenMode = true;\r
+       sock->SecureMode = false;\r
+       sock->LocalPort = port;\r
+       sock->IPv6 = true;\r
+\r
+       return sock;\r
+}\r
+\r
+// TCP 待ち受け\r
+SOCK *Listen(UINT port)\r
+{\r
+       return ListenEx(port, false);\r
+}\r
+SOCK *ListenEx(UINT port, bool local_only)\r
+{\r
+       SOCKET s;\r
+       SOCK *sock;\r
+       struct sockaddr_in addr;\r
+       struct in_addr in;\r
+       bool true_flag = true;\r
+       IP localhost;\r
+       // 引数チェック\r
+       if (port == 0 || port >= 65536)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 初期化\r
+       Zero(&addr, sizeof(addr));\r
+       Zero(&in, sizeof(in));\r
+       SetIP(&localhost, 127, 0, 0, 1);\r
+\r
+       addr.sin_port = htons((UINT)port);\r
+       *((UINT *)&addr.sin_addr) = htonl(INADDR_ANY);\r
+       addr.sin_family = AF_INET;\r
+\r
+       if (local_only)\r
+       {\r
+               IPToInAddr(&addr.sin_addr, &localhost);\r
+       }\r
+\r
+       // ソケットの作成\r
+       s = socket(AF_INET, SOCK_STREAM, 0);\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       //SetSocketSendRecvBufferSize(s, SOCKET_BUFFER_SIZE);\r
+\r
+#ifdef OS_UNIX\r
+       // Windows 系 OS は REUSEADDR の実装にバグがあるっぽいので\r
+       // UNIX 系のみ有効にした。\r
+       setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&true_flag, sizeof(bool));\r
+#endif // OS_UNIX\r
+\r
+       if (bind(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0)\r
+       {\r
+               // bind 失敗\r
+               closesocket(s);\r
+               return NULL;\r
+       }\r
+       if (listen(s, SOMAXCONN))\r
+       {\r
+               // listen 失敗\r
+               closesocket(s);\r
+               return NULL;\r
+       }\r
+\r
+       // 成功\r
+       sock = NewSock();\r
+       sock->Connected = false;\r
+       sock->AsyncMode = false;\r
+       sock->ServerMode = true;\r
+       sock->Type = SOCK_TCP;\r
+       sock->socket = s;\r
+       sock->ListenMode = true;\r
+       sock->SecureMode = false;\r
+       sock->LocalPort = port;\r
+\r
+       return sock;\r
+}\r
+\r
+// TCP 切断\r
+void Disconnect(SOCK *sock)\r
+{\r
+       SOCKET s;\r
+       bool true_flag = true;\r
+       bool false_flag = false;\r
+       // 引数チェック\r
+       if (sock == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       sock->Disconnecting = true;\r
+\r
+#ifdef OS_UNIX\r
+       UnixFreeAsyncSocket(sock);\r
+#endif // UnixFreeAsyncSocket\r
+\r
+       if (sock->Type == SOCK_TCP && sock->ListenMode)\r
+       {\r
+               // Listen 中のソケットの場合は localhost に対して接続する\r
+               sock->CancelAccept = true;\r
+\r
+               if (sock->IPv6 == false)\r
+               {\r
+                       CheckTCPPort("127.0.0.1", sock->LocalPort);\r
+               }\r
+               else\r
+               {\r
+                       CheckTCPPort("::1", sock->LocalPort);\r
+               }\r
+       }\r
+\r
+       Lock(disconnect_function_lock);\r
+\r
+       Lock(sock->disconnect_lock);\r
+\r
+       if (sock->Type == SOCK_TCP)\r
+       {\r
+               if (sock->socket != INVALID_SOCKET)\r
+               {\r
+                       // 強制切断フラグ\r
+                       #ifdef  SO_DONTLINGER\r
+                               setsockopt(sock->socket, SOL_SOCKET, SO_DONTLINGER, (char *)&true_flag, sizeof(bool));\r
+                       #else   // SO_DONTLINGER\r
+                               setsockopt(sock->socket, SOL_SOCKET, SO_LINGER, (char *)&false_flag, sizeof(bool));\r
+                       #endif  // SO_DONTLINGER\r
+//                     setsockopt(sock->socket, SOL_SOCKET, SO_REUSEADDR, (char *)&true_flag, sizeof(bool));\r
+               }\r
+\r
+               // TCP ソケット\r
+               Lock(sock->lock);\r
+               {\r
+                       if (sock->socket == INVALID_SOCKET)\r
+                       {\r
+                               Unlock(sock->lock);\r
+                               Unlock(sock->disconnect_lock);\r
+                               Unlock(disconnect_function_lock);\r
+                               return;\r
+                       }\r
+                       s = sock->socket;\r
+\r
+                       if (sock->Connected)\r
+                       {\r
+                               struct linger ling;\r
+                               Zero(&ling, sizeof(ling));\r
+\r
+\r
+#if    0\r
+                               // SSL 切断\r
+                               Lock(sock->ssl_lock);\r
+                               {\r
+                                       if (sock->SecureMode)\r
+                                       {\r
+                                               SSL_shutdown(sock->ssl);\r
+                                       }\r
+                               }\r
+                               Unlock(sock->ssl_lock);\r
+#endif\r
+                               // 切断\r
+                               shutdown(s, 2);\r
+                       }\r
+\r
+                       // ソケットを閉じる\r
+                       closesocket(s);\r
+\r
+#ifdef OS_UNIX\r
+#ifdef FIX_SSL_BLOCKING\r
+                       if (sock->CallingThread != NULL)\r
+                       {\r
+                               pthread_kill(sock->CallingThread, 64);\r
+                       }\r
+#endif // FIX_SSL_BLOCKING\r
+#endif // OS_UNIX\r
+\r
+                       // SSL を解放\r
+                       Lock(sock->ssl_lock);\r
+                       {\r
+                               if (sock->SecureMode)\r
+                               {\r
+                                       if (sock->ssl != NULL)\r
+                                       {\r
+                                               Lock(openssl_lock);\r
+                                               {\r
+                                                       SSL_free(sock->ssl);\r
+                                               }\r
+                                               Unlock(openssl_lock);\r
+                                               sock->ssl = NULL;\r
+                                       }\r
+                                       sock->Connected = false;\r
+                                       // 証明書を解放\r
+                                       if (sock->RemoteX != NULL)\r
+                                       {\r
+                                               FreeX(sock->RemoteX);\r
+                                               sock->RemoteX = NULL;\r
+                                       }\r
+                                       if (sock->LocalX != NULL)\r
+                                       {\r
+                                               FreeX(sock->LocalX);\r
+                                               sock->LocalX = NULL;\r
+                                       }\r
+\r
+                                       // 暗号化アルゴリズム名\r
+                                       if (sock->CipherName != NULL)\r
+                                       {\r
+                                               Free(sock->CipherName);\r
+                                               sock->CipherName = NULL;\r
+                                       }\r
+                                       sock->SecureMode = false;\r
+                               }\r
+                       }\r
+                       Unlock(sock->ssl_lock);\r
+\r
+                       // 初期化\r
+                       sock->socket = INVALID_SOCKET;\r
+                       sock->Type = 0;\r
+                       sock->AsyncMode = false;\r
+                       sock->Connected = false;\r
+                       sock->ListenMode = false;\r
+                       sock->SecureMode = false;\r
+\r
+                       if (sock->ServerMode && sock->ListenMode == false)\r
+                       {\r
+                               DelIpClient(&sock->RemoteIP);\r
+                       }\r
+               }\r
+               Unlock(sock->lock);\r
+       }\r
+       else if (sock->Type == SOCK_UDP)\r
+       {\r
+               // UDP ソケット\r
+               Lock(sock->lock);\r
+               {\r
+                       if (sock->socket == INVALID_SOCKET)\r
+                       {\r
+                               Unlock(sock->lock);\r
+                               Unlock(sock->disconnect_lock);\r
+                               Unlock(disconnect_function_lock);\r
+                               return;\r
+                       }\r
+\r
+                       s = sock->socket;\r
+\r
+                       // ソケットを閉じる\r
+                       closesocket(s);\r
+\r
+                       // 初期化\r
+                       sock->socket = INVALID_SOCKET;\r
+                       sock->Type = 0;\r
+                       sock->AsyncMode = false;\r
+                       sock->Connected = false;\r
+                       sock->ListenMode = false;\r
+                       sock->SecureMode = false;\r
+               }\r
+               Unlock(sock->lock);\r
+       }\r
+       Unlock(sock->disconnect_lock);\r
+\r
+       Unlock(disconnect_function_lock);\r
+}\r
+\r
+typedef struct TCP_PORT_CHECK\r
+{\r
+       REF *ref;\r
+       char hostname[MAX_SIZE];\r
+       UINT port;\r
+       bool ok;\r
+} TCP_PORT_CHECK;\r
+\r
+// TCP ポートチェック用スレッド\r
+void CheckTCPPortThread(THREAD *thread, void *param)\r
+{\r
+       TCP_PORT_CHECK *c;\r
+       SOCK *s;\r
+       // 引数チェック\r
+       if (thread == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       c = (TCP_PORT_CHECK *)param;\r
+       AddRef(c->ref);\r
+       NoticeThreadInit(thread);\r
+\r
+       AddWaitThread(thread);\r
+\r
+       s = Connect(c->hostname, c->port);\r
+       if (s != NULL)\r
+       {\r
+               c->ok = true;\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+       }\r
+\r
+       if (Release(c->ref) == 0)\r
+       {\r
+               Free(c);\r
+       }\r
+\r
+       DelWaitThread(thread);\r
+}\r
+\r
+// TCP ポートに接続可能かどうかチェックする\r
+bool CheckTCPPortEx(char *hostname, UINT port, UINT timeout)\r
+{\r
+       SOCK *s;\r
+       // 引数チェック\r
+       if (hostname == NULL || port == 0 || port >= 65536)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (timeout == 0)\r
+       {\r
+               timeout = TIMEOUT_TCP_PORT_CHECK;\r
+       }\r
+\r
+       s = ConnectEx(hostname, port, timeout);\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+               return true;\r
+       }\r
+}\r
+bool CheckTCPPort(char *hostname, UINT port)\r
+{\r
+       return CheckTCPPortEx(hostname, port, TIMEOUT_TCP_PORT_CHECK);\r
+}\r
+\r
+#ifdef OS_UNIX\r
+// タイムアウト付き接続 (UNIX 版)\r
+int connect_timeout(SOCKET s, struct sockaddr *addr, int size, int timeout, bool *cancel_flag)\r
+{\r
+       SOCKSET set;\r
+       bool ok = false;\r
+       UINT64 start_time;\r
+       // 引数チェック\r
+       if (s == INVALID_SOCKET || addr == NULL)\r
+       {\r
+               return -1;\r
+       }\r
+       if (timeout == 0)\r
+       {\r
+               timeout = TIMEOUT_TCP_PORT_CHECK;\r
+       }\r
+\r
+       UnixSetSocketNonBlockingMode(s, true);\r
+\r
+       start_time = Tick64();\r
+\r
+       while (true)\r
+       {\r
+               int ret;\r
+               ret = connect(s, addr, size);\r
+               if (ret == 0 || errno == EISCONN)\r
+               {\r
+                       ok = true;\r
+                       break;\r
+               }\r
+               else\r
+               {\r
+                       if (((start_time + (UINT64)timeout) <= Tick64()) || (errno != EAGAIN && errno != EINPROGRESS && errno != EALREADY))\r
+                       {\r
+                               // 失敗\r
+                               break;\r
+                       }\r
+                       else if (*cancel_flag)\r
+                       {\r
+                               // キャンセル\r
+                               break;\r
+                       }\r
+                       else\r
+                       {\r
+                               // 接続中\r
+                               SleepThread(50);\r
+                               UnixSelectInner(1, (UINT *)&s, 1, (UINT *)&s, 100);\r
+                       }\r
+               }\r
+       }\r
+\r
+       UnixSetSocketNonBlockingMode(s, false);\r
+\r
+       if (ok)\r
+       {\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               return -1;\r
+       }\r
+}\r
+#else\r
+// タイムアウト付き接続 (Win32 版)\r
+int connect_timeout(SOCKET s, struct sockaddr *addr, int size, int timeout, bool *cancel_flag)\r
+{\r
+       UINT64 start_time;\r
+       bool ok = false;\r
+       bool timeouted = false;\r
+       WSAEVENT hEvent;\r
+       UINT zero = 0;\r
+       UINT tmp = 0;\r
+       UINT ret_size = 0;\r
+       bool is_nt = false;\r
+       // 引数チェック\r
+       if (s == INVALID_SOCKET || addr == NULL)\r
+       {\r
+               return -1;\r
+       }\r
+       if (timeout == 0)\r
+       {\r
+               timeout = TIMEOUT_TCP_PORT_CHECK;\r
+       }\r
+\r
+       is_nt = OS_IS_WINDOWS_NT(GetOsInfo()->OsType);\r
+\r
+       // イベントを作成\r
+       hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);\r
+\r
+       // ソケットをイベントに関連付ける\r
+       WSAEventSelect(s, hEvent, FD_CONNECT);\r
+\r
+       start_time = Tick64();\r
+\r
+       while (true)\r
+       {\r
+               int ret;\r
+               \r
+               ret = connect(s, addr, size);\r
+\r
+               if (ret == 0)\r
+               {\r
+                       ok = true;\r
+                       break;\r
+               }\r
+               else\r
+               {\r
+                       int err = WSAGetLastError();\r
+                       //Debug("err=%u\n", err);\r
+                       //Debug("cancel_flag=%u\n", *cancel_flag);\r
+                       if (timeouted && ((err == WSAEALREADY) || (err == WSAEWOULDBLOCK && !is_nt)))\r
+                       {\r
+                               // タイムアウト\r
+                               ok = false;\r
+                               break;\r
+                       }\r
+                       if (*cancel_flag)\r
+                       {\r
+                               // キャンセル\r
+                               ok = false;\r
+                               break;\r
+                       }\r
+                       if (err == WSAEISCONN || (err == WSAEINVAL && is_nt))\r
+                       {\r
+                               ok = true;\r
+                               break;\r
+                       }\r
+                       if (((start_time + (UINT64)timeout) <= Tick64()) || (err != WSAEWOULDBLOCK && err != WSAEALREADY && (is_nt || err != WSAEINVAL)))\r
+                       {\r
+                               // 失敗 (タイムアウト)\r
+                               break;\r
+                       }\r
+                       else\r
+                       {\r
+                               SleepThread(10);\r
+                               // 接続中\r
+                               if (WaitForSingleObject(hEvent, 100) == WAIT_OBJECT_0)\r
+                               {\r
+                                       timeouted = true;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       // ソケットをイベントから外す\r
+       WSAEventSelect(s, hEvent, 0);\r
+\r
+       // 同期ソケットに戻す\r
+       WSAIoctl(s, FIONBIO, &zero, sizeof(zero), &tmp, sizeof(tmp), &ret_size, NULL, NULL);\r
+\r
+       // イベントを閉じる\r
+       CloseHandle(hEvent);\r
+\r
+       if (ok)\r
+       {\r
+               return 0;\r
+       }\r
+       else\r
+       {\r
+               return -1;\r
+       }\r
+}\r
+#endif // OS_UNIX\r
+\r
+// ソケットのパケットの優先順位を向上させる (未使用)\r
+void SetSockPriorityHigh(SOCK *s)\r
+{\r
+       int value;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       value = 16;\r
+\r
+#ifdef IP_TOS\r
+       //setsockopt(s->socket, IPPROTO_IP, IP_TOS, (char *)&value, sizeof(int));\r
+#endif // IP_TOS\r
+}\r
+\r
+// TCP 接続\r
+SOCK *Connect(char *hostname, UINT port)\r
+{\r
+       return ConnectEx(hostname, port, 0);\r
+}\r
+SOCK *ConnectEx(char *hostname, UINT port, UINT timeout)\r
+{\r
+       return ConnectEx2(hostname, port, timeout, NULL);\r
+}\r
+SOCK *ConnectEx2(char *hostname, UINT port, UINT timeout, bool *cancel_flag)\r
+{\r
+       SOCK *sock;\r
+       SOCKET s;\r
+       struct linger ling;\r
+       struct sockaddr_in sockaddr4;\r
+       struct in_addr addr4;\r
+       IP ip4;\r
+       struct sockaddr_in6 sockaddr6;\r
+       struct in6_addr addr6;\r
+       IP ip6;\r
+       bool true_flag = true;\r
+       bool false_flag = false;\r
+       char tmp[MAX_SIZE];\r
+       IP current_ip;\r
+       bool is_ipv6 = false;\r
+       bool dummy = false;\r
+       // 引数チェック\r
+       if (hostname == NULL || port == 0 || port >= 65536)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (timeout == 0)\r
+       {\r
+               timeout = TIMEOUT_TCP_PORT_CHECK;\r
+       }\r
+       if (cancel_flag == NULL)\r
+       {\r
+               cancel_flag = &dummy;\r
+       }\r
+\r
+       Zero(&current_ip, sizeof(current_ip));\r
+\r
+       Zero(&sockaddr4, sizeof(sockaddr4));\r
+       Zero(&addr4, sizeof(addr4));\r
+       Zero(&ip4, sizeof(ip4));\r
+\r
+       Zero(&sockaddr6, sizeof(sockaddr6));\r
+       Zero(&addr6, sizeof(addr6));\r
+       Zero(&ip6, sizeof(ip6));\r
+\r
+       // 正引き\r
+       if (GetIP46Ex(&ip4, &ip6, hostname, 0, cancel_flag) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       s = INVALID_SOCKET;\r
+\r
+       // IPv4 で接続を試行する\r
+       if (IsZeroIp(&ip4) == false)\r
+       {\r
+               // sockaddr_in の生成\r
+               IPToInAddr(&addr4, &ip4);\r
+               sockaddr4.sin_port = htons((USHORT)port);\r
+               sockaddr4.sin_family = AF_INET;\r
+               sockaddr4.sin_addr.s_addr = addr4.s_addr;\r
+\r
+               // ソケット作成\r
+               s = socket(AF_INET, SOCK_STREAM, 0);\r
+               if (s != INVALID_SOCKET)\r
+               {\r
+                       // 接続\r
+                       if (connect_timeout(s, (struct sockaddr *)&sockaddr4, sizeof(struct sockaddr_in), timeout, cancel_flag) != 0)\r
+                       {\r
+                               // 接続失敗\r
+                               closesocket(s);\r
+                               s = INVALID_SOCKET;\r
+                       }\r
+                       else\r
+                       {\r
+                               Copy(&current_ip, &ip4, sizeof(IP));\r
+                       }\r
+               }\r
+       }\r
+\r
+       // IPv6 で接続を試行する\r
+       if (s == INVALID_SOCKET && IsZeroIp(&ip6) == false)\r
+       {\r
+               // sockaddr_in6 の生成\r
+               IPToInAddr6(&addr6, &ip6);\r
+               sockaddr6.sin6_port = htons((USHORT)port);\r
+               sockaddr6.sin6_family = AF_INET6;\r
+               sockaddr6.sin6_scope_id = ip6.ipv6_scope_id;\r
+               Copy(&sockaddr6.sin6_addr, &addr6, sizeof(addr6));\r
+\r
+               // ソケット作成\r
+               s = socket(AF_INET6, SOCK_STREAM, 0);\r
+               if (s != INVALID_SOCKET)\r
+               {\r
+                       // 接続\r
+                       if (connect_timeout(s, (struct sockaddr *)&sockaddr6, sizeof(struct sockaddr_in6), timeout, cancel_flag) != 0)\r
+                       {\r
+                               // 接続失敗\r
+                               closesocket(s);\r
+                               s = INVALID_SOCKET;\r
+                       }\r
+                       else\r
+                       {\r
+                               Copy(&current_ip, &ip6, sizeof(IP));\r
+\r
+                               is_ipv6 = true;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               // IPv4, IPv6 の両方で接続失敗\r
+               return NULL;\r
+       }\r
+\r
+       // SOCK の作成\r
+       sock = NewSock();\r
+       sock->socket = s;\r
+       sock->Type = SOCK_TCP;\r
+       sock->ServerMode = false;\r
+\r
+       SetSockPriorityHigh(sock);\r
+\r
+       // ホスト名解決\r
+       if (GetHostName(tmp, sizeof(tmp), &current_ip) == false)\r
+       {\r
+               StrCpy(tmp, sizeof(tmp), hostname);\r
+       }\r
+\r
+       //Debug("PTR: %s\n", tmp);\r
+\r
+       sock->RemoteHostname = CopyStr(tmp);\r
+\r
+//     Debug("new socket: %u\n", s);\r
+\r
+       Zero(&ling, sizeof(ling));\r
+       // 強制切断フラグ\r
+#ifdef SO_DONTLINGER\r
+       setsockopt(sock->socket, SOL_SOCKET, SO_DONTLINGER, (char *)&true_flag, sizeof(bool));\r
+#else  // SO_DONTLINGER\r
+       setsockopt(sock->socket, SOL_SOCKET, SO_LINGER, (char *)&false_flag, sizeof(bool));\r
+#endif // SO_DONTLINGER\r
+//     setsockopt(sock->socket, SOL_SOCKET, SO_REUSEADDR, (char *)&true_flag, sizeof(bool));\r
+\r
+       // TCP オプションの設定\r
+       setsockopt(sock->socket, IPPROTO_TCP, TCP_NODELAY, (char *)&true_flag, sizeof(bool));\r
+\r
+       // タイムアウト値の初期化\r
+       SetTimeout(sock, TIMEOUT_INFINITE);\r
+\r
+       // ソケット情報の取得\r
+       QuerySocketInformation(sock);\r
+\r
+       sock->Connected = true;\r
+       sock->AsyncMode = false;\r
+       sock->SecureMode = false;\r
+       sock->IPv6 = is_ipv6;\r
+\r
+       return sock;\r
+}\r
+\r
+// ソケットの送受信バッファサイズを最大にする\r
+void SetSocketSendRecvBufferSize(int s, UINT size)\r
+{\r
+       int value = (int)size;\r
+       // 引数チェック\r
+       if (s == INVALID_SOCKET)\r
+       {\r
+               return;\r
+       }\r
+\r
+       setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&value, sizeof(int));\r
+       setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&value, sizeof(int));\r
+}\r
+\r
+// ソケット情報の取得\r
+void QuerySocketInformation(SOCK *sock)\r
+{\r
+       // 引数チェック\r
+       if (sock == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(sock->lock);\r
+       {\r
+               struct sockaddr_in6 sockaddr6;\r
+               struct in6_addr *addr6;\r
+               int size;\r
+\r
+               if (sock->Type == SOCK_TCP)\r
+               {\r
+                       // リモートホストの情報を取得\r
+                       size = sizeof(sockaddr6);\r
+                       if (getpeername(sock->socket, (struct sockaddr *)&sockaddr6, (int *)&size) == 0)\r
+                       {\r
+                               if (size >= sizeof(struct sockaddr_in6))\r
+                               {\r
+                                       sock->RemotePort = (UINT)ntohs(sockaddr6.sin6_port);\r
+                                       addr6 = &sockaddr6.sin6_addr;\r
+                                       InAddrToIP6(&sock->RemoteIP, addr6);\r
+                                       sock->RemoteIP.ipv6_scope_id = sockaddr6.sin6_scope_id;\r
+                               }\r
+                               else\r
+                               {\r
+                                       struct sockaddr_in *sockaddr;\r
+                                       struct in_addr *addr;\r
+\r
+                                       sockaddr = (struct sockaddr_in *)&sockaddr6;\r
+                                       sock->RemotePort = (UINT)ntohs(sockaddr->sin_port);\r
+                                       addr = &sockaddr->sin_addr;\r
+                                       InAddrToIP(&sock->RemoteIP, addr);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // ローカルホストの情報を取得\r
+               size = sizeof(sockaddr6);\r
+               if (getsockname(sock->socket, (struct sockaddr *)&sockaddr6, (int *)&size) == 0)\r
+               {\r
+                       if (size >= sizeof(struct sockaddr_in6))\r
+                       {\r
+                               sock->LocalPort = (UINT)ntohs(sockaddr6.sin6_port);\r
+                               addr6 = &sockaddr6.sin6_addr;\r
+                               InAddrToIP6(&sock->LocalIP, addr6);\r
+                               sock->LocalIP.ipv6_scope_id = sockaddr6.sin6_scope_id;\r
+                       }\r
+                       else\r
+                       {\r
+                               struct sockaddr_in *sockaddr;\r
+                               struct in_addr *addr;\r
+\r
+                               sockaddr = (struct sockaddr_in *)&sockaddr6;\r
+                               sock->LocalPort = (UINT)ntohs(sockaddr->sin_port);\r
+                               addr = &sockaddr->sin_addr;\r
+                               InAddrToIP(&sock->LocalIP, addr);\r
+                       }\r
+               }\r
+       }\r
+       Unlock(sock->lock);\r
+}\r
+\r
+// ソケットの解放\r
+void ReleaseSock(SOCK *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(s->ref) == 0)\r
+       {\r
+               if (s->ListenMode == false && s->ServerMode)\r
+               {\r
+                       Print("");\r
+               }\r
+               CleanupSock(s);\r
+       }\r
+}\r
+\r
+// ソケットのクリーンアップ\r
+void CleanupSock(SOCK *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+//     {Debug("CleanupSock: Disconnect() Called: %s %u\n", __FILE__, __LINE__);Disconnect(s);}\r
+       Disconnect(s);\r
+\r
+#ifdef OS_WIN32\r
+       Win32FreeAsyncSocket(s);\r
+#else  // OS_WIN32\r
+       UnixFreeAsyncSocket(s);\r
+#endif // OS_WIN32\r
+\r
+       FreeBuf(s->SendBuf);\r
+       if (s->socket != INVALID_SOCKET)\r
+       {\r
+#ifdef OS_WIN32\r
+               closesocket(s->socket);\r
+#else  // OS_WIN32\r
+               close(s->socket);\r
+#endif // OS_WIN32\r
+       }\r
+       Free(s->RemoteHostname);\r
+\r
+       Free(s->WaitToUseCipher);\r
+       DeleteLock(s->lock);\r
+       DeleteLock(s->ssl_lock);\r
+       DeleteLock(s->disconnect_lock);\r
+\r
+       Dec(num_tcp_connections);\r
+\r
+       Free(s);\r
+}\r
+\r
+// 新しいソケットの作成\r
+SOCK *NewSock()\r
+{\r
+       SOCK *s = ZeroMallocFast(sizeof(SOCK));\r
+\r
+       s->ref = NewRef();\r
+       s->lock = NewLock();\r
+       s->SendBuf = NewBuf();\r
+       s->socket = INVALID_SOCKET;\r
+       s->ssl_lock = NewLock();\r
+       s->disconnect_lock = NewLock();\r
+\r
+       Inc(num_tcp_connections);\r
+\r
+       return s;\r
+}\r
+\r
+// IP を UINT に変換する\r
+UINT IPToUINT(IP *ip)\r
+{\r
+       UCHAR *b;\r
+       UINT i, value = 0;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       b = (UCHAR *)&value;\r
+       for (i = 0;i < 4;i++)\r
+       {\r
+               b[i] = ip->addr[i];\r
+       }\r
+\r
+       return value;\r
+}\r
+\r
+// UNIT を IP に変換する\r
+void UINTToIP(IP *ip, UINT value)\r
+{\r
+       UCHAR *b;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ZeroIP4(ip);\r
+\r
+       b = (UCHAR *)&value;\r
+       for (i = 0;i < 4;i++)\r
+       {\r
+               ip->addr[i] = b[i];\r
+       }\r
+}\r
+\r
+// コンピュータのホスト名を取得\r
+void GetMachineHostName(char *name, UINT size)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetMachineName(tmp, sizeof(tmp));\r
+\r
+       len = StrLen(tmp);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (tmp[i] == '.')\r
+               {\r
+                       tmp[i] = 0;\r
+               }\r
+       }\r
+\r
+       ConvertSafeFileName(name, size, tmp);\r
+}\r
+\r
+// このコンピュータの IP アドレスを取得\r
+void GetMachineIp(IP *ip)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(ip, sizeof(IP));\r
+       SetIP(ip, 127, 0, 0, 1);\r
+\r
+       GetMachineName(tmp, sizeof(tmp));\r
+       GetIP(ip, tmp);\r
+}\r
+\r
+// コンピュータ名を hosts から取得\r
+bool GetMachineNameFromHosts(char *name, UINT size)\r
+{\r
+       bool ret = false;\r
+       char *s;\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = ReadDump("/etc/hosts");\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               s = CfgReadNextLine(b);\r
+               if (s == NULL)\r
+               {\r
+                       break;\r
+               }\r
+               else\r
+               {\r
+                       TOKEN_LIST *t = ParseToken(s, " \t");\r
+\r
+                       if (t != NULL)\r
+                       {\r
+                               if (t->NumTokens >= 2)\r
+                               {\r
+                                       if (StrCmpi(t->Token[0], "127.0.0.1") == 0)\r
+                                       {\r
+                                               UINT i;\r
+\r
+                                               for (i = 1;i < t->NumTokens;i++)\r
+                                               {\r
+                                                       if (StartWith(t->Token[i], "localhost") == false)\r
+                                                       {\r
+                                                               StrCpy(name, size, t->Token[i]);\r
+                                                               ret = true;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       FreeToken(t);\r
+               }\r
+\r
+               Free(s);\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// このコンピュータのコンピュータ名を取得\r
+void GetMachineName(char *name, UINT size)\r
+{\r
+       GetMachineNameEx(name, size, false);\r
+}\r
+void GetMachineNameEx(char *name, UINT size, bool no_load_hosts)\r
+{\r
+       static char name_cache[MAX_SIZE];\r
+       static bool name_cached = false;\r
+       char tmp[MAX_SIZE];\r
+       char tmp2[MAX_SIZE];\r
+       IP ip;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Lock(machine_name_lock);\r
+       {\r
+               if (name_cached != false)\r
+               {\r
+                       StrCpy(name, size, name_cache);\r
+                       Unlock(machine_name_lock);\r
+                       return;\r
+               }\r
+               if (gethostname(tmp, MAX_SIZE) != 0)\r
+               {\r
+                       StrCpy(name, size, "Unknown");\r
+                       Unlock(machine_name_lock);\r
+                       return;\r
+               }\r
+               if (GetIP(&ip, tmp) == false)\r
+               {\r
+                       StrCpy(name, size, tmp);\r
+                       Unlock(machine_name_lock);\r
+                       return;\r
+               }\r
+               if (GetHostNameInner(name, size, &ip) == false || StartWith(name, "localhost"))\r
+               {\r
+                       StrCpy(name, size, tmp);\r
+               }\r
+               if (StartWith(name, "localhost"))\r
+               {\r
+                       if (no_load_hosts == false && OS_IS_UNIX(GetOsInfo()->OsType))\r
+                       {\r
+                               if (GetMachineNameFromHosts(tmp2, sizeof(tmp2)))\r
+                               {\r
+                                       StrCpy(name, sizeof(name), tmp2);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               StrCpy(name_cache, sizeof(name_cache), name);\r
+               name_cached = true;\r
+       }\r
+       Unlock(machine_name_lock);\r
+}\r
+\r
+// ホスト名取得スレッド\r
+void GetHostNameThread(THREAD *t, void *p)\r
+{\r
+       IP *ip;\r
+       char hostname[256];\r
+       // 引数チェック\r
+       if (t == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ip = (IP *)p;\r
+\r
+       AddWaitThread(t);\r
+\r
+       NoticeThreadInit(t);\r
+\r
+       if (GetHostNameInner(hostname, sizeof(hostname), ip))\r
+       {\r
+               AddHostCache(ip, hostname);\r
+       }\r
+\r
+       Free(ip);\r
+\r
+       DelWaitThread(t);\r
+}\r
+\r
+// ホスト名の取得\r
+bool GetHostName(char *hostname, UINT size, IP *ip)\r
+{\r
+       THREAD *t;\r
+       IP *p_ip;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (hostname == NULL || ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GetHostCache(hostname, size, ip))\r
+       {\r
+               if (IsEmptyStr(hostname) == false)\r
+               {\r
+                       return true;\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       p_ip = ZeroMalloc(sizeof(IP));\r
+       Copy(p_ip, ip, sizeof(IP));\r
+\r
+       t = NewThread(GetHostNameThread, p_ip);\r
+\r
+       WaitThreadInit(t);\r
+\r
+       WaitThread(t, TIMEOUT_HOSTNAME);\r
+\r
+       ReleaseThread(t);\r
+\r
+       ret = GetHostCache(hostname, size, ip);\r
+       if (ret == false)\r
+       {\r
+               if (IsIP4(ip))\r
+               {\r
+                       ret = GetNetBiosName(hostname, size, ip);\r
+                       if (ret)\r
+                       {\r
+                               AddHostCache(ip, hostname);\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (IsEmptyStr(hostname))\r
+               {\r
+                       ret = false;\r
+               }\r
+       }\r
+       if (ret == false)\r
+       {\r
+               AddHostCache(ip, "");\r
+               StrCpy(hostname, size, "");\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// DNS 逆引きクエリを行う\r
+bool GetHostNameInner(char *hostname, UINT size, IP *ip)\r
+{\r
+       struct in_addr addr;\r
+       struct sockaddr_in sa;\r
+       char tmp[MAX_SIZE];\r
+       char ip_str[64];\r
+       // 引数チェック\r
+       if (hostname == NULL || ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsIP6(ip))\r
+       {\r
+               return GetHostNameInner6(hostname, size, ip);\r
+       }\r
+\r
+       // 逆引き\r
+       IPToInAddr(&addr, ip);\r
+       Zero(&sa, sizeof(sa));\r
+       sa.sin_family = AF_INET;\r
+\r
+#if    defined(UNIX_BSD) || defined(UNIX_MACOS)\r
+       sa.sin_len = INET_ADDRSTRLEN;\r
+#endif // UNIX_BSD || UNIX_MACOS\r
+\r
+       Copy(&sa.sin_addr, &addr, sizeof(struct in_addr));\r
+       sa.sin_port = 0;\r
+\r
+       if (getnameinfo((struct sockaddr *)&sa, sizeof(sa), tmp, sizeof(tmp), NULL, 0, 0) != 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       IPToStr(ip_str, sizeof(ip_str), ip);\r
+\r
+       if (StrCmpi(tmp, ip_str) == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsEmptyStr(tmp))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(hostname, size, tmp);\r
+\r
+       return true;\r
+}\r
+bool GetHostNameInner6(char *hostname, UINT size, IP *ip)\r
+{\r
+       struct in6_addr addr;\r
+       struct sockaddr_in6 sa;\r
+       char tmp[MAX_SIZE];\r
+       char ip_str[256];\r
+       // 引数チェック\r
+       if (hostname == NULL || ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 逆引き\r
+       IPToInAddr6(&addr, ip);\r
+       Zero(&sa, sizeof(sa));\r
+       sa.sin6_family = AF_INET6;\r
+\r
+#if    defined(UNIX_BSD) || defined(UNIX_MACOS)\r
+       sa.sin6_len = INET6_ADDRSTRLEN;\r
+#endif // UNIX_BSD || UNIX_MACOS\r
+\r
+       Copy(&sa.sin6_addr, &addr, sizeof(struct in6_addr));\r
+       sa.sin6_port = 0;\r
+\r
+       if (getnameinfo((struct sockaddr *)&sa, sizeof(sa), tmp, sizeof(tmp), NULL, 0, 0) != 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       IPToStr(ip_str, sizeof(ip_str), ip);\r
+\r
+       if (StrCmpi(tmp, ip_str) == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsEmptyStr(tmp))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(hostname, size, tmp);\r
+\r
+       return true;\r
+}\r
+\r
+#define        NUM_NBT_QUERYS_SEND                     3\r
+\r
+// IP アドレスからそのマシンの NetBIOS 名を取得する\r
+bool GetNetBiosName(char *name, UINT size, IP *ip)\r
+{\r
+       SOCK *s;\r
+       UINT i, j;\r
+       bool flag = false;\r
+       bool ok = false;\r
+       NBTREQUEST req;\r
+       UCHAR buf[1024];\r
+       USHORT tran_id[NUM_NBT_QUERYS_SEND];\r
+       UINT64 timeout_tick;\r
+       // 引数チェック\r
+       if (name == NULL || ip == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       IPToStr(name, size, ip);\r
+\r
+       for (i = 0;i < NUM_NBT_QUERYS_SEND;i++)\r
+       {\r
+               tran_id[i] = Rand16();\r
+       }\r
+\r
+       s = NewUDP(0);\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (j = 0;j < NUM_NBT_QUERYS_SEND;j++)\r
+       {\r
+               Zero(&req, sizeof(req));\r
+               req.TransactionId = Endian16(tran_id[j]);\r
+               req.NumQuestions = Endian16(1);\r
+               req.Query[0] = 0x20;\r
+               req.Query[1] = 0x43;\r
+               req.Query[2] = 0x4b;\r
+               for (i = 3;i <= 32;i++)\r
+               {\r
+                       req.Query[i] = 0x41;\r
+               }\r
+               req.Query[35] = 0x21;\r
+               req.Query[37] = 0x01;\r
+\r
+               if (SendTo(s, ip, 137, &req, sizeof(req)) == 0)\r
+               {\r
+                       ReleaseSock(s);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       timeout_tick = Tick() + (UINT64)TIMEOUT_NETBIOS_HOSTNAME;\r
+\r
+       while (1)\r
+       {\r
+               UINT ret;\r
+               IP src_ip;\r
+               UINT src_port;\r
+               SOCKSET set;\r
+               if (Tick() >= timeout_tick)\r
+               {\r
+                       break;\r
+               }\r
+               InitSockSet(&set);\r
+               AddSockSet(&set, s);\r
+               Select(&set, 100, NULL, NULL);\r
+\r
+               if (flag == false)\r
+               {\r
+                       flag = true;\r
+               }\r
+               else\r
+               {\r
+                       SleepThread(10);\r
+               }\r
+\r
+               ret = RecvFrom(s, &src_ip, &src_port, buf, sizeof(buf));\r
+\r
+               if (ret == SOCK_LATER)\r
+               {\r
+                       continue;\r
+               }\r
+               else if (ret == 0)\r
+               {\r
+                       break;\r
+               }\r
+               else\r
+               {\r
+                       if (ret >= sizeof(NBTRESPONSE))\r
+                       {\r
+                               NBTRESPONSE *r = (NBTRESPONSE *)buf;\r
+                               bool b = false;\r
+                               UINT i;\r
+                               USHORT id = Endian16(r->TransactionId);\r
+                               for (i = 0;i < NUM_NBT_QUERYS_SEND;i++)\r
+                               {\r
+                                       if (id == tran_id[i])\r
+                                       {\r
+                                               b = true;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               if (b)\r
+                               {\r
+                                       if (r->Flags != 0 && r->NumQuestions == 0 && r->AnswerRRs >= 1)\r
+                                       {\r
+                                               if (r->Response[0] == 0x20 && r->Response[1] == 0x43 &&\r
+                                                       r->Response[2] == 0x4b)\r
+                                               {\r
+                                                       if (r->Response[34] == 0x00 && r->Response[35] == 0x21 &&\r
+                                                               r->Response[36] == 0x00 && r->Response[37] == 0x01)\r
+                                                       {\r
+                                                               char *a = (char *)(&r->Response[45]);\r
+                                                               if (StrCheckLen(a, 15))\r
+                                                               {\r
+                                                                       if (IsEmptyStr(a) == false)\r
+                                                                       {\r
+                                                                               StrCpy(name, size, a);\r
+                                                                               Trim(name);\r
+                                                                               ok = true;\r
+                                                                       }\r
+                                                                       else\r
+                                                                       {\r
+                                                                               ok = false;\r
+                                                                               break;\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       ReleaseSock(s);\r
+       return ok;\r
+}\r
+\r
+// IP アドレスを設定する\r
+void SetIP(IP *ip, UCHAR a1, UCHAR a2, UCHAR a3, UCHAR a4)\r
+{\r
+       // 引数チェック\r
+       if (ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(ip, sizeof(IP));\r
+       ip->addr[0] = a1;\r
+       ip->addr[1] = a2;\r
+       ip->addr[2] = a3;\r
+       ip->addr[3] = a4;\r
+}\r
+\r
+// DNS 正引きを行って結果を v4 と v6 のどちらかで得る (両方の場合は IPv4 優先)\r
+bool GetIP46Any4(IP *ip, char *hostname)\r
+{\r
+       IP ip4, ip6;\r
+       bool b = false;\r
+       // 引数チェック\r
+       if (ip == NULL || hostname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GetIP46(&ip4, &ip6, hostname) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsZeroIp(&ip6) == false)\r
+       {\r
+               Copy(ip, &ip6, sizeof(IP));\r
+\r
+               b = true;\r
+       }\r
+\r
+       if (IsZeroIp(&ip4) == false)\r
+       {\r
+               Copy(ip, &ip4, sizeof(IP));\r
+\r
+               b = true;\r
+       }\r
+\r
+       return b;\r
+}\r
+\r
+// DNS 正引きを行って結果を v4 と v6 のどちらかで得る (両方の場合は IPv6 優先)\r
+bool GetIP46Any6(IP *ip, char *hostname)\r
+{\r
+       IP ip4, ip6;\r
+       bool b = false;\r
+       // 引数チェック\r
+       if (ip == NULL || hostname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (GetIP46(&ip4, &ip6, hostname) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsZeroIp(&ip4) == false)\r
+       {\r
+               Copy(ip, &ip4, sizeof(IP));\r
+\r
+               b = true;\r
+       }\r
+\r
+       if (IsZeroIp(&ip6) == false)\r
+       {\r
+               Copy(ip, &ip6, sizeof(IP));\r
+\r
+               b = true;\r
+       }\r
+\r
+       return b;\r
+}\r
+\r
+// DNS 正引きを行って結果を v4 と v6 の両方で得る\r
+bool GetIP46(IP *ip4, IP *ip6, char *hostname)\r
+{\r
+       return GetIP46Ex(ip4, ip6, hostname, 0, NULL);\r
+}\r
+bool GetIP46Ex(IP *ip4, IP *ip6, char *hostname, UINT timeout, bool *cancel)\r
+{\r
+       IP a, b;\r
+       bool ok_a, ok_b;\r
+       // 引数チェック\r
+       if (ip4 == NULL || ip6 == NULL || hostname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ZeroIP4(ip4);\r
+       ZeroIP6(ip6);\r
+\r
+       ok_a = ok_b = false;\r
+\r
+       if (GetIP6Ex(&a, hostname, timeout, cancel))\r
+       {\r
+               ok_a = true;\r
+       }\r
+\r
+       if (GetIP4Ex(&b, hostname, timeout, cancel))\r
+       {\r
+               ok_b = true;\r
+       }\r
+\r
+       if (ok_a)\r
+       {\r
+               if (IsIP4(&a))\r
+               {\r
+                       Copy(ip4, &a, sizeof(IP));\r
+               }\r
+       }\r
+       if (ok_b)\r
+       {\r
+               if (IsIP4(&b))\r
+               {\r
+                       Copy(ip4, &b, sizeof(IP));\r
+               }\r
+\r
+               if (IsIP6(&b))\r
+               {\r
+                       Copy(ip6, &b, sizeof(IP));\r
+               }\r
+       }\r
+       if (ok_a)\r
+       {\r
+               if (IsIP6(&a))\r
+               {\r
+                       Copy(ip6, &a, sizeof(IP));\r
+               }\r
+       }\r
+\r
+       if (IsZeroIp(ip4) && IsZeroIp(ip6))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// GetIP 用スレッドのパラメータのクリーンアップ\r
+void CleanupGetIPThreadParam(GETIP_THREAD_PARAM *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(p);\r
+}\r
+\r
+// GetIP 用スレッドのパラメータの解放\r
+void ReleaseGetIPThreadParam(GETIP_THREAD_PARAM *p)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(p->Ref) == 0)\r
+       {\r
+               CleanupGetIPThreadParam(p);\r
+       }\r
+}\r
+\r
+// DNS 正引きクエリ (タイムアウト付き) を行うスレッド\r
+void GetIP4Ex6ExThread(THREAD *t, void *param)\r
+{\r
+       GETIP_THREAD_PARAM *p;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = (GETIP_THREAD_PARAM *)param;\r
+\r
+       AddRef(p->Ref);\r
+\r
+       NoticeThreadInit(t);\r
+\r
+       AddWaitThread(t);\r
+\r
+       // 解決の実行\r
+       if (p->IPv6 == false)\r
+       {\r
+               // IPv4\r
+               p->Ok = GetIP4Inner(&p->Ip, p->HostName);\r
+       }\r
+       else\r
+       {\r
+               // IPv6\r
+               p->Ok = GetIP6Inner(&p->Ip, p->HostName);\r
+       }\r
+\r
+       ReleaseGetIPThreadParam(p);\r
+\r
+       DelWaitThread(t);\r
+}\r
+\r
+// DNS 正引きクエリ (タイムアウト付き) を行う\r
+bool GetIP4Ex6Ex(IP *ip, char *hostname, UINT timeout, bool ipv6, bool *cancel)\r
+{\r
+       GETIP_THREAD_PARAM *p;\r
+       THREAD *t;\r
+       bool ret = false;\r
+       UINT64 start_tick = 0;\r
+       UINT64 end_tick = 0;\r
+       // 引数チェック\r
+       if (ip == NULL || hostname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (timeout == 0)\r
+       {\r
+               timeout = TIMEOUT_GETIP;\r
+       }\r
+\r
+       p = ZeroMalloc(sizeof(GETIP_THREAD_PARAM));\r
+       p->Ref = NewRef();\r
+       StrCpy(p->HostName, sizeof(p->HostName), hostname);\r
+       p->IPv6 = ipv6;\r
+       p->Timeout = timeout;\r
+       p->Ok = false;\r
+\r
+       t = NewThread(GetIP4Ex6ExThread, p);\r
+       WaitThreadInit(t);\r
+\r
+       if (cancel == NULL)\r
+       {\r
+               WaitThread(t, timeout);\r
+       }\r
+       else\r
+       {\r
+               start_tick = Tick64();\r
+               end_tick = start_tick + (UINT64)timeout;\r
+\r
+               while (true)\r
+               {\r
+                       UINT64 now = Tick64();\r
+                       UINT64 remain;\r
+                       UINT remain32;\r
+\r
+                       if (*cancel)\r
+                       {\r
+                               break;\r
+                       }\r
+\r
+                       if (now >= end_tick)\r
+                       {\r
+                               break;\r
+                       }\r
+\r
+                       remain = end_tick - now;\r
+                       remain32 = MIN((UINT)remain, 100);\r
+\r
+                       if (WaitThread(t, remain32))\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+\r
+       ReleaseThread(t);\r
+\r
+       if (p->Ok)\r
+       {\r
+               ret = true;\r
+               Copy(ip, &p->Ip, sizeof(IP));\r
+       }\r
+\r
+       ReleaseGetIPThreadParam(p);\r
+\r
+       return ret;\r
+}\r
+bool GetIP4Ex(IP *ip, char *hostname, UINT timeout, bool *cancel)\r
+{\r
+       return GetIP4Ex6Ex(ip, hostname, timeout, false, cancel);\r
+}\r
+bool GetIP6Ex(IP *ip, char *hostname, UINT timeout, bool *cancel)\r
+{\r
+       return GetIP4Ex6Ex(ip, hostname, timeout, true, cancel);\r
+}\r
+bool GetIP4(IP *ip, char *hostname)\r
+{\r
+       return GetIP4Ex(ip, hostname, 0, NULL);\r
+}\r
+bool GetIP6(IP *ip, char *hostname)\r
+{\r
+       return GetIP6Ex(ip, hostname, 0, NULL);\r
+}\r
+\r
+// DNS 正引きクエリを行う\r
+bool GetIP(IP *ip, char *hostname)\r
+{\r
+       return GetIPEx(ip, hostname, false);\r
+}\r
+bool GetIPEx(IP *ip, char *hostname, bool ipv6)\r
+{\r
+       if (ipv6 == false)\r
+       {\r
+               return GetIP4(ip, hostname);\r
+       }\r
+       else\r
+       {\r
+               return GetIP6(ip, hostname);\r
+       }\r
+}\r
+bool GetIP6Inner(IP *ip, char *hostname)\r
+{\r
+       struct sockaddr_in6 in;\r
+       struct in6_addr addr;\r
+       struct addrinfo hint;\r
+       struct addrinfo *info;\r
+       // 引数チェック\r
+       if (ip == NULL || hostname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsEmptyStr(hostname))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(hostname, "localhost") == 0)\r
+       {\r
+               GetLocalHostIP6(ip);\r
+               return true;\r
+       }\r
+\r
+       if (StrToIP6(ip, hostname) == false && StrToIP(ip, hostname) == false)\r
+       {\r
+               // 正引き\r
+               Zero(&hint, sizeof(hint));\r
+               hint.ai_family = AF_INET6;\r
+               hint.ai_socktype = SOCK_STREAM;\r
+               hint.ai_protocol = IPPROTO_TCP;\r
+               info = NULL;\r
+\r
+               if (getaddrinfo(hostname, NULL, &hint, &info) != 0 ||\r
+                       info->ai_family != AF_INET6)\r
+               {\r
+                       if (info)\r
+                       {\r
+                               freeaddrinfo(info);\r
+                       }\r
+                       return QueryDnsCacheEx(ip, hostname, true);\r
+               }\r
+               // 正引き成功\r
+               Copy(&in, info->ai_addr, sizeof(struct sockaddr_in6));\r
+               freeaddrinfo(info);\r
+\r
+               Copy(&addr, &in.sin6_addr, sizeof(addr));\r
+               InAddrToIP6(ip, &addr);\r
+       }\r
+\r
+       // キャッシュ保存\r
+       NewDnsCache(hostname, ip);\r
+\r
+       return true;\r
+}\r
+bool GetIP4Inner(IP *ip, char *hostname)\r
+{\r
+       struct sockaddr_in in;\r
+       struct in_addr addr;\r
+       struct addrinfo hint;\r
+       struct addrinfo *info;\r
+       // 引数チェック\r
+       if (ip == NULL || hostname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsEmptyStr(hostname))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(hostname, "localhost") == 0)\r
+       {\r
+               SetIP(ip, 127, 0, 0, 1);\r
+               return true;\r
+       }\r
+\r
+       if (StrToIP6(ip, hostname) == false && StrToIP(ip, hostname) == false)\r
+       {\r
+               // 正引き\r
+               Zero(&hint, sizeof(hint));\r
+               hint.ai_family = AF_INET;\r
+               hint.ai_socktype = SOCK_STREAM;\r
+               hint.ai_protocol = IPPROTO_TCP;\r
+               info = NULL;\r
+\r
+               if (getaddrinfo(hostname, NULL, &hint, &info) != 0 ||\r
+                       info->ai_family != AF_INET)\r
+               {\r
+                       if (info)\r
+                       {\r
+                               freeaddrinfo(info);\r
+                       }\r
+                       return QueryDnsCache(ip, hostname);\r
+               }\r
+               // 正引き成功\r
+               Copy(&in, info->ai_addr, sizeof(struct sockaddr_in));\r
+               freeaddrinfo(info);\r
+               Copy(&addr, &in.sin_addr, sizeof(addr));\r
+               InAddrToIP(ip, &addr);\r
+       }\r
+\r
+       // キャッシュ保存\r
+       NewDnsCache(hostname, ip);\r
+\r
+       return true;\r
+}\r
+\r
+// DNS キャッシュを検索する\r
+bool QueryDnsCache(IP *ip, char *hostname)\r
+{\r
+       return QueryDnsCacheEx(ip, hostname, false);\r
+}\r
+bool QueryDnsCacheEx(IP *ip, char *hostname, bool ipv6)\r
+{\r
+       DNSCACHE *c;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (ip == NULL || hostname == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       GenDnsCacheKeyName(tmp, sizeof(tmp), hostname, ipv6);\r
+\r
+       c = FindDnsCache(tmp);\r
+       if (c == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Copy(ip, &c->IpAddress, sizeof(IP));\r
+\r
+       return true;\r
+}\r
+\r
+// IP を文字列に変換\r
+void IPToUniStr(wchar_t *str, UINT size, IP *ip)\r
+{\r
+       char tmp[128];\r
+\r
+       IPToStr(tmp, sizeof(tmp), ip);\r
+       StrToUni(str, size, tmp);\r
+}\r
+\r
+// IP を文字列に変換 (32bit UINT)\r
+void IPToUniStr32(wchar_t *str, UINT size, UINT ip)\r
+{\r
+       char tmp[128];\r
+\r
+       IPToStr32(tmp, sizeof(tmp), ip);\r
+       StrToUni(str, size, tmp);\r
+}\r
+\r
+// IP を文字列に変換 (128bit byte array)\r
+void IPToStr128(char *str, UINT size, UCHAR *ip_bytes)\r
+{\r
+       IP ip_st;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetIP6(&ip_st, ip_bytes);\r
+       IPToStr(str, size, &ip_st);\r
+}\r
+\r
+// IP を文字列に変換 (32bit UINT)\r
+void IPToStr32(char *str, UINT size, UINT ip)\r
+{\r
+       IP ip_st;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UINTToIP(&ip_st, ip);\r
+       IPToStr(str, size, &ip_st);\r
+}\r
+\r
+// IPv4 または IPv6 を文字列に変換\r
+void IPToStr4or6(char *str, UINT size, UINT ip_4_uint, UCHAR *ip_6_bytes)\r
+{\r
+       IP ip4;\r
+       IP ip6;\r
+       IP ip;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&ip, sizeof(ip));\r
+\r
+       UINTToIP(&ip4, ip_4_uint);\r
+       SetIP6(&ip6, ip_6_bytes);\r
+\r
+       if (IsIP6(&ip4) || (IsZeroIp(&ip4) && (IsZeroIp(&ip6) == false)))\r
+       {\r
+               Copy(&ip, &ip6, sizeof(IP));\r
+       }\r
+       else\r
+       {\r
+               Copy(&ip, &ip4, sizeof(IP));\r
+       }\r
+\r
+       IPToStr(str, size, &ip);\r
+}\r
+\r
+// IP を文字列に変換\r
+void IPToStr(char *str, UINT size, IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsIP6(ip))\r
+       {\r
+               IPToStr6(str, size, ip);\r
+       }\r
+       else\r
+       {\r
+               IPToStr4(str, size, ip);\r
+       }\r
+}\r
+\r
+// IPv4 を文字列に変換\r
+void IPToStr4(char *str, UINT size, IP *ip)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 変換\r
+       snprintf(str, size != 0 ? size : 64, "%u.%u.%u.%u", ip->addr[0], ip->addr[1], ip->addr[2], ip->addr[3]);\r
+}\r
+\r
+// 文字列を IP に変換\r
+bool StrToIP(IP *ip, char *str)\r
+{\r
+       TOKEN_LIST *token;\r
+       char *tmp;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (ip == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrToIP6(ip, str))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       Zero(ip, sizeof(IP));\r
+\r
+       tmp = CopyStr(str);\r
+       Trim(tmp);\r
+       token = ParseToken(tmp, ".");\r
+       Free(tmp);\r
+\r
+       if (token->NumTokens != 4)\r
+       {\r
+               FreeToken(token);\r
+               return false;\r
+       }\r
+       for (i = 0;i < 4;i++)\r
+       {\r
+               char *s = token->Token[i];\r
+               if (s[0] < '0' || s[0] > '9' ||\r
+                       (ToInt(s) >= 256))\r
+               {\r
+                       FreeToken(token);\r
+                       return false;\r
+               }\r
+       }\r
+       Zero(ip, sizeof(IP));\r
+       for (i = 0;i < 4;i++)\r
+       {\r
+               ip->addr[i] = (UCHAR)ToInt(token->Token[i]);\r
+       }\r
+\r
+       FreeToken(token);\r
+\r
+       return true;\r
+}\r
+UINT StrToIP32(char *str)\r
+{\r
+       IP ip;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (StrToIP(&ip, str) == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return IPToUINT(&ip);\r
+}\r
+bool UniStrToIP(IP *ip, wchar_t *str)\r
+{\r
+       char *tmp;\r
+       bool ret;\r
+\r
+       tmp = CopyUniToStr(str);\r
+       ret = StrToIP(ip, tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+UINT UniStrToIP32(wchar_t *str)\r
+{\r
+       UINT ret;\r
+       char *tmp;\r
+\r
+       tmp = CopyUniToStr(str);\r
+       ret = StrToIP32(tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// IP を in_addr に変換\r
+void IPToInAddr(struct in_addr *addr, IP *ip)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (addr == NULL || ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(addr, sizeof(struct in_addr));\r
+\r
+       if (IsIP6(ip) == false)\r
+       {\r
+               for (i = 0;i < 4;i++)\r
+               {\r
+                       ((UCHAR *)addr)[i] = ip->addr[i];\r
+               }\r
+       }\r
+}\r
+\r
+// IP を in6_addr に変換\r
+void IPToInAddr6(struct in6_addr *addr, IP *ip)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (addr == NULL || ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(addr, sizeof(struct in_addr));\r
+\r
+       if (IsIP6(ip))\r
+       {\r
+               for (i = 0;i < 16;i++)\r
+               {\r
+                       ((UCHAR *)addr)[i] = ip->ipv6_addr[i];\r
+               }\r
+       }\r
+}\r
+\r
+// in_addr を IP に変換\r
+void InAddrToIP(IP *ip, struct in_addr *addr)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (ip == NULL || addr == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(ip, sizeof(IP));\r
+\r
+       for (i = 0;i < 4;i++)\r
+       {\r
+               ip->addr[i] = ((UCHAR *)addr)[i];\r
+       }\r
+}\r
+\r
+// in6_addr を IP に変換\r
+void InAddrToIP6(IP *ip, struct in6_addr *addr)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (ip == NULL || addr == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ZeroIP6(ip);\r
+       for (i = 0;i < 16;i++)\r
+       {\r
+               ip->ipv6_addr[i] = ((UCHAR *)addr)[i];\r
+       }\r
+}\r
+\r
+// DNS キャッシュの検索\r
+DNSCACHE *FindDnsCache(char *hostname)\r
+{\r
+       return FindDnsCacheEx(hostname, false);\r
+}\r
+DNSCACHE *FindDnsCacheEx(char *hostname, bool ipv6)\r
+{\r
+       DNSCACHE *c;\r
+       char tmp[MAX_SIZE];\r
+       if (hostname == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       GenDnsCacheKeyName(tmp, sizeof(tmp), hostname, ipv6);\r
+\r
+       LockDnsCache();\r
+       {\r
+               DNSCACHE t;\r
+               t.HostName = tmp;\r
+               c = Search(DnsCache, &t);\r
+       }\r
+       UnlockDnsCache();\r
+\r
+       return c;\r
+}\r
+\r
+// DNS キャッシュ用の IPv4 / IPv6 キー名を生成\r
+void GenDnsCacheKeyName(char *dst, UINT size, char *src, bool ipv6)\r
+{\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (ipv6 == false)\r
+       {\r
+               StrCpy(dst, size, src);\r
+       }\r
+       else\r
+       {\r
+               Format(dst, size, "%s@ipv6", src);\r
+       }\r
+}\r
+\r
+// 新しい DNS キャッシュの登録\r
+void NewDnsCache(char *hostname, IP *ip)\r
+{\r
+       NewDnsCacheEx(hostname, ip, IsIP6(ip));\r
+}\r
+void NewDnsCacheEx(char *hostname, IP *ip, bool ipv6)\r
+{\r
+       DNSCACHE *c;\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (hostname == NULL || ip == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsNetworkNameCacheEnabled() == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GenDnsCacheKeyName(tmp, sizeof(tmp), hostname, ipv6);\r
+\r
+       LockDnsCache();\r
+       {\r
+               DNSCACHE t;\r
+\r
+               // まず hostname に該当するものがあるかどうか検索してみる\r
+               t.HostName = tmp;\r
+               c = Search(DnsCache, &t);\r
+\r
+               if (c == NULL)\r
+               {\r
+                       // 新規登録\r
+                       c = ZeroMalloc(sizeof(DNSCACHE));\r
+                       c->HostName = CopyStr(tmp);\r
+\r
+                       Copy(&c->IpAddress, ip, sizeof(IP));\r
+\r
+                       Add(DnsCache, c);\r
+               }\r
+               else\r
+               {\r
+                       // 更新\r
+                       Copy(&c->IpAddress, ip, sizeof(IP));\r
+               }\r
+       }\r
+       UnlockDnsCache();\r
+}\r
+\r
+// DNS キャッシュの名前比較\r
+int CompareDnsCache(void *p1, void *p2)\r
+{\r
+       DNSCACHE *c1, *c2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       c1 = *(DNSCACHE **)p1;\r
+       c2 = *(DNSCACHE **)p2;\r
+       if (c1 == NULL || c2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCmpi(c1->HostName, c2->HostName);\r
+}\r
+\r
+// DNS キャッシュの初期化\r
+void InitDnsCache()\r
+{\r
+       // リスト作成\r
+       DnsCache = NewList(CompareDnsCache);\r
+}\r
+\r
+// DNS キャッシュの解放\r
+void FreeDnsCache()\r
+{\r
+       LockDnsCache();\r
+       {\r
+               DNSCACHE *c;\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(DnsCache);i++)\r
+               {\r
+                       // エントリのメモリ解放\r
+                       c = LIST_DATA(DnsCache, i);\r
+                       Free(c->HostName);\r
+                       Free(c);\r
+               }\r
+       }\r
+       UnlockDnsCache();\r
+\r
+       // リスト解放\r
+       ReleaseList(DnsCache);\r
+       DnsCache = NULL;\r
+}\r
+\r
+// DNS キャッシュのロック\r
+void LockDnsCache()\r
+{\r
+       LockList(DnsCache);\r
+}\r
+\r
+// DNS キャッシュのロック解除\r
+void UnlockDnsCache()\r
+{\r
+       UnlockList(DnsCache);\r
+}\r
+\r
+// ネットワーク通信モジュールの初期化\r
+void InitNetwork()\r
+{\r
+       num_tcp_connections = NewCounter();\r
+\r
+       // クライアントリストの初期化\r
+       InitIpClientList();\r
+\r
+       // スレッド関係の初期化\r
+       InitWaitThread();\r
+\r
+       // ホスト名キャッシュの初期化\r
+       InitHostCache();\r
+\r
+#ifdef OS_WIN32\r
+       // ソケットライブラリの初期化\r
+       Win32InitSocketLibrary();\r
+#else\r
+       UnixInitSocketLibrary();\r
+#endif // OS_WIN32\r
+\r
+       // DNS キャッシュの初期化\r
+       InitDnsCache();\r
+\r
+       // OpenSSL の初期化\r
+       ssl_ctx = SSL_CTX_new(SSLv23_method());\r
+\r
+       // ロック初期化\r
+       machine_name_lock = NewLock();\r
+       disconnect_function_lock = NewLock();\r
+       aho = NewLock();\r
+       socket_library_lock = NewLock();\r
+       ssl_connect_lock = NewLock();\r
+//     ssl_accept_lock = NewLock();\r
+       dns_lock = NewLock();\r
+       unix_dns_server_addr_lock = NewLock();\r
+       Zero(&unix_dns_server, sizeof(unix_dns_server));\r
+\r
+       cipher_list_token = ParseToken(cipher_list, " ");\r
+\r
+       disable_cache = false;\r
+}\r
+\r
+// ネットワーク名キャッシュの有効化\r
+void EnableNetworkNameCache()\r
+{\r
+       disable_cache = false;\r
+}\r
+\r
+// ネットワーク名キャッシュの無効化\r
+void DisableNetworkNameCache()\r
+{\r
+       disable_cache = true;\r
+}\r
+\r
+// ネットワーク名キャッシュが有効かどうか取得\r
+bool IsNetworkNameCacheEnabled()\r
+{\r
+       return !disable_cache;\r
+}\r
+\r
+// 暗号化アルゴリズムリストを取得\r
+TOKEN_LIST *GetCipherList()\r
+{\r
+       return cipher_list_token;\r
+}\r
+\r
+// TCP コネクション数カウンタを取得\r
+COUNTER *GetNumTcpConnectionsCounter()\r
+{\r
+       return num_tcp_connections;\r
+}\r
+\r
+// ネットワーク通信モジュールの解放\r
+void FreeNetwork()\r
+{\r
+       FreeToken(cipher_list_token);\r
+       cipher_list_token = NULL;\r
+\r
+       Zero(&unix_dns_server, sizeof(unix_dns_server));\r
+\r
+       // ロック解放\r
+       DeleteLock(unix_dns_server_addr_lock);\r
+       DeleteLock(dns_lock);\r
+       DeleteLock(ssl_accept_lock);\r
+       DeleteLock(machine_name_lock);\r
+       DeleteLock(disconnect_function_lock);\r
+       DeleteLock(aho);\r
+       DeleteLock(socket_library_lock);\r
+       DeleteLock(ssl_connect_lock);\r
+       machine_name_lock = NULL;\r
+       ssl_accept_lock = machine_name_lock = disconnect_function_lock =\r
+               aho = socket_library_lock = ssl_connect_lock = NULL;\r
+\r
+       // OpenSSL の解放\r
+       SSL_CTX_free(ssl_ctx);\r
+       ssl_ctx = NULL;\r
+\r
+       // スレッド関係の解放\r
+       FreeWaitThread();\r
+\r
+       // DNS キャッシュの解放\r
+       FreeDnsCache();\r
+\r
+       // ホスト名キャッシュの解放\r
+       FreeHostCache();\r
+\r
+#ifdef OS_WIN32\r
+       // ソケットライブラリの解放\r
+       Win32FreeSocketLibrary();\r
+#else\r
+       UnixFreeSocketLibrary();\r
+#endif // OS_WIN32\r
+\r
+       DeleteCounter(num_tcp_connections);\r
+       num_tcp_connections = NULL;\r
+\r
+       // クライアントリストの解放\r
+       FreeIpClientList();\r
+}\r
+\r
+// ソケットリストにソケットを追加する\r
+void AddSockList(SOCKLIST *sl, SOCK *s)\r
+{\r
+       // 引数チェック\r
+       if (sl == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(sl->SockList);\r
+       {\r
+               if (IsInList(sl->SockList, s) == false)\r
+               {\r
+                       AddRef(s->ref);\r
+\r
+                       Insert(sl->SockList, s);\r
+               }\r
+       }\r
+       UnlockList(sl->SockList);\r
+}\r
+\r
+// ソケットリストからソケットを削除する\r
+void DelSockList(SOCKLIST *sl, SOCK *s)\r
+{\r
+       // 引数チェック\r
+       if (sl == NULL || s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(sl->SockList);\r
+       {\r
+               if (Delete(sl->SockList, s))\r
+               {\r
+                       ReleaseSock(s);\r
+               }\r
+       }\r
+       UnlockList(sl->SockList);\r
+}\r
+\r
+// ソケットリストのソケットをすべて停止させて削除する\r
+void StopSockList(SOCKLIST *sl)\r
+{\r
+       SOCK **ss;\r
+       UINT num, i;\r
+       // 引数チェック\r
+       if (sl == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockList(sl->SockList);\r
+       {\r
+               num = LIST_NUM(sl->SockList);\r
+               ss = ToArray(sl->SockList);\r
+\r
+               DeleteAll(sl->SockList);\r
+       }\r
+       UnlockList(sl->SockList);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               SOCK *s = ss[i];\r
+\r
+               Disconnect(s);\r
+               ReleaseSock(s);\r
+       }\r
+\r
+       Free(ss);\r
+}\r
+\r
+// ソケットリストの削除\r
+void FreeSockList(SOCKLIST *sl)\r
+{\r
+       // 引数チェック\r
+       if (sl == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StopSockList(sl);\r
+\r
+       ReleaseList(sl->SockList);\r
+\r
+       Free(sl);\r
+}\r
+\r
+// ソケットリストの作成\r
+SOCKLIST *NewSockList()\r
+{\r
+       SOCKLIST *sl = ZeroMallocFast(sizeof(SOCKLIST));\r
+\r
+       sl->SockList = NewList(NULL);\r
+\r
+       return sl;\r
+}\r
+\r
+// Solarisでのソケットのタイムアウト用スレッド\r
+void SocketTimeoutThread(THREAD *t, void *param)\r
+{\r
+       SOCKET_TIMEOUT_PARAM *ttparam;\r
+       ttparam = (SOCKET_TIMEOUT_PARAM *)param;\r
+\r
+       // タイムアウト時間だけ待つ\r
+       Select(NULL, ttparam->sock->TimeOut, ttparam->cancel, NULL);\r
+\r
+       // ブロック中ならディスコネクトする\r
+       if(! ttparam->unblocked)\r
+       {\r
+//             Debug("Socket timeouted\n");\r
+               closesocket(ttparam->sock->socket);\r
+       }\r
+       else\r
+       {\r
+//             Debug("Socket timeout cancelled\n");\r
+       }\r
+}\r
+\r
+// タイムアウト用スレッドの初期化と開始\r
+SOCKET_TIMEOUT_PARAM *NewSocketTimeout(SOCK *sock)\r
+{\r
+       SOCKET_TIMEOUT_PARAM *ttp;\r
+       if(! sock->AsyncMode && sock->TimeOut != TIMEOUT_INFINITE)\r
+       {\r
+//             Debug("NewSockTimeout(%u)\n",sock->TimeOut);\r
+\r
+               ttp = (SOCKET_TIMEOUT_PARAM*)Malloc(sizeof(SOCKET_TIMEOUT_PARAM));\r
+\r
+               // タイムアウトスレッド用のパラメータをセット\r
+               ttp->cancel = NewCancel();\r
+               ttp->sock = sock;\r
+               ttp->unblocked = false;\r
+               ttp->thread = NewThread(SocketTimeoutThread, ttp);\r
+               return ttp;\r
+       }\r
+       return NULL;\r
+}\r
+\r
+// タイムアウト用スレッドの停止と開放\r
+void FreeSocketTimeout(SOCKET_TIMEOUT_PARAM *ttp)\r
+{\r
+       if(ttp == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ttp->unblocked = true;\r
+       Cancel(ttp->cancel);\r
+       WaitThread(ttp->thread, INFINITE);\r
+       ReleaseCancel(ttp->cancel);\r
+       ReleaseThread(ttp->thread);\r
+       Free(ttp);\r
+//     Debug("FreeSocketTimeout succeed\n");\r
+       return;\r
+}\r
+\r
+// IP アドレスとサブネット マスクのパース\r
+bool ParseIpAndSubnetMask46(char *src, IP *ip, IP *mask)\r
+{\r
+       // 引数チェック\r
+       if (src == NULL || ip == NULL || mask == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ParseIpAndMask46(src, ip, mask) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsIP4(ip))\r
+       {\r
+               return IsSubnetMask4(mask);\r
+       }\r
+       else\r
+       {\r
+               return IsSubnetMask6(mask);\r
+       }\r
+}\r
+bool ParseIpAndSubnetMask6(char *src, IP *ip, IP *mask)\r
+{\r
+       if (ParseIpAndSubnetMask46(src, ip, mask) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsIP6(ip) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+bool ParseIpAndSubnetMask4(char *src, UINT *ip, UINT *mask)\r
+{\r
+       IP ip2, mask2;\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ParseIpAndSubnetMask46(src, &ip2, &mask2) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsIP4(&ip2) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ip != NULL)\r
+       {\r
+               *ip = IPToUINT(&ip2);\r
+       }\r
+\r
+       if (mask != NULL)\r
+       {\r
+               *mask = IPToUINT(&mask2);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+\r
+// IP アドレスとマスクのパース\r
+bool ParseIpAndMask46(char *src, IP *ip, IP *mask)\r
+{\r
+       TOKEN_LIST *t;\r
+       char *ipstr;\r
+       char *subnetstr;\r
+       bool ret = false;\r
+       IP ip2;\r
+       IP mask2;\r
+       // 引数チェック\r
+       if (src == NULL || ip == NULL || mask == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&ip2, sizeof(IP));\r
+       Zero(&mask2, sizeof(IP));\r
+\r
+       t = ParseToken(src, "/");\r
+       if (t->NumTokens != 2)\r
+       {\r
+               FreeToken(t);\r
+               return false;\r
+       }\r
+\r
+       ipstr = t->Token[0];\r
+       subnetstr = t->Token[1];\r
+       Trim(ipstr);\r
+       Trim(subnetstr);\r
+\r
+       if (StrToIP(&ip2, ipstr))\r
+       {\r
+               if (StrToIP(&mask2, subnetstr))\r
+               {\r
+                       // IP アドレス部とマスク部が同一の種類かどうか比較する\r
+                       if (IsIP6(&ip2) && IsIP6(&mask2))\r
+                       {\r
+                               // 両方とも IPv6\r
+                               ret = true;\r
+                               Copy(ip, &ip2, sizeof(IP));\r
+                               Copy(mask, &mask2, sizeof(IP));\r
+                       }\r
+                       else if (IsIP4(&ip2) && IsIP4(&mask2))\r
+                       {\r
+                               // 両方とも IPv4\r
+                               ret = true;\r
+                               Copy(ip, &ip2, sizeof(IP));\r
+                               Copy(mask, &mask2, sizeof(IP));\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if (IsNum(subnetstr))\r
+                       {\r
+                               UINT i = ToInt(subnetstr);\r
+                               // マスク部が数値\r
+                               if (IsIP6(&ip2) && i <= 128)\r
+                               {\r
+                                       ret = true;\r
+                                       Copy(ip, &ip2, sizeof(IP));\r
+                                       IntToSubnetMask6(mask, i);\r
+                               }\r
+                               else if (i <= 32)\r
+                               {\r
+                                       ret = true;\r
+                                       Copy(ip, &ip2, sizeof(IP));\r
+                                       IntToSubnetMask4(mask, i);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+bool ParseIpAndMask4(char *src, UINT *ip, UINT *mask)\r
+{\r
+       IP ip_ip, ip_mask;\r
+       if (ParseIpAndMask46(src, &ip_ip, &ip_mask) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsIP4(&ip_ip) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ip != NULL)\r
+       {\r
+               *ip = IPToUINT(&ip_ip);\r
+       }\r
+\r
+       if (mask != NULL)\r
+       {\r
+               *mask = IPToUINT(&ip_mask);\r
+       }\r
+\r
+       return true;\r
+}\r
+bool ParseIpAndMask6(char *src, IP *ip, IP *mask)\r
+{\r
+       if (ParseIpAndMask46(src, ip, mask) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsIP6(ip) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+\r
+// IPv4 アドレスの指定が正しいかどうかチェックする\r
+bool IsIpStr4(char *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrToIP32(str) == 0 && StrCmpi(str, "0.0.0.0") != 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// IPv6 アドレスの指定が正しいかどうかチェックする\r
+bool IsIpStr6(char *str)\r
+{\r
+       IP ip;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrToIP6(&ip, str) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// IP アドレスの指定が正しいかどうかチェックする\r
+bool IsIpStr46(char *str)\r
+{\r
+       if (IsIpStr4(str) || IsIpStr6(str))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+\r
+// 文字列を IPv4 マスクに変換\r
+bool StrToMask4(IP *mask, char *str)\r
+{\r
+       // 引数チェック\r
+       if (mask == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (str[0] == '/')\r
+       {\r
+               str++;\r
+       }\r
+\r
+       if (IsNum(str))\r
+       {\r
+               UINT n = ToInt(str);\r
+\r
+               if (n <= 32)\r
+               {\r
+                       IntToSubnetMask4(mask, n);\r
+                       return true;\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (StrToIP(mask, str) == false)\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       return IsIP4(mask);\r
+               }\r
+       }\r
+}\r
+\r
+// 文字列を IPv6 マスクに変換\r
+bool StrToMask6(IP *mask, char *str)\r
+{\r
+       // 引数チェック\r
+       if (mask == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (str[0] == '/')\r
+       {\r
+               str++;\r
+       }\r
+\r
+       if (IsNum(str))\r
+       {\r
+               UINT n = ToInt(str);\r
+\r
+               if (n <= 128)\r
+               {\r
+                       IntToSubnetMask6(mask, n);\r
+                       return true;\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (StrToIP(mask, str) == false)\r
+               {\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       return IsIP6(mask);\r
+               }\r
+       }\r
+}\r
+bool StrToMask6Addr(IPV6_ADDR *mask, char *str)\r
+{\r
+       IP ip;\r
+\r
+       if (StrToMask6(&ip, str) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IPToIPv6Addr(mask, &ip) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 文字列を IPv4 / IPv6 マスクに変換\r
+bool StrToMask46(IP *mask, char *str, bool ipv6)\r
+{\r
+       if (ipv6)\r
+       {\r
+               return StrToMask6(mask, str);\r
+       }\r
+       else\r
+       {\r
+               return StrToMask4(mask, str);\r
+       }\r
+}\r
+\r
+\r
+// IPv4 / IPv6 マスクを文字列に変換\r
+void MaskToStr(char *str, UINT size, IP *mask)\r
+{\r
+       MaskToStrEx(str, size, mask, false);\r
+}\r
+void MaskToStrEx(char *str, UINT size, IP *mask, bool always_full_address)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || mask == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (always_full_address == false && IsSubnetMask(mask))\r
+       {\r
+               ToStr(str, SubnetMaskToInt(mask));\r
+       }\r
+       else\r
+       {\r
+               IPToStr(str, size, mask);\r
+       }\r
+}\r
+void MaskToStr32(char *str, UINT size, UINT mask)\r
+{\r
+       MaskToStr32Ex(str, size, mask, false);\r
+}\r
+void MaskToStr32Ex(char *str, UINT size, UINT mask, bool always_full_address)\r
+{\r
+       IP ip;\r
+\r
+       UINTToIP(&ip, mask);\r
+\r
+       MaskToStrEx(str, size, &ip, always_full_address);\r
+}\r
+void Mask6AddrToStrEx(char *str, UINT size, IPV6_ADDR *mask, bool always_full_address)\r
+{\r
+       IP ip;\r
+\r
+       // 引数チェック\r
+       if (str == NULL || mask == NULL)\r
+       {\r
+               StrCpy(str, size, "");\r
+               return;\r
+       }\r
+\r
+       IPv6AddrToIP(&ip, mask);\r
+\r
+       MaskToStrEx(str, size, &ip, always_full_address);\r
+}\r
+void Mask6AddrToStr(char *str, UINT size, IPV6_ADDR *mask)\r
+{\r
+       Mask6AddrToStrEx(str, size, mask, false);\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Network.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Network.h
new file mode 100644 (file)
index 0000000..32d14a3
--- /dev/null
@@ -0,0 +1,703 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Network.h\r
+// Network.c のヘッダ\r
+\r
+#ifndef        NETWORK_H\r
+#define        NETWORK_H\r
+\r
+#define        TIMEOUT_GETIP                           2300\r
+\r
+#define        TIMEOUT_INFINITE                        (0x7fffffff)\r
+#define        TIMEOUT_TCP_PORT_CHECK          (10 * 1000)\r
+#define        TIMEOUT_SSL_CONNECT                     (15 * 1000)\r
+\r
+#define        TIMEOUT_HOSTNAME                        (500)\r
+#define        TIMEOUT_NETBIOS_HOSTNAME        (100)\r
+#define        EXPIRES_HOSTNAME                        (10 * 60 * 1000)\r
+\r
+#define        SOCKET_BUFFER_SIZE                      0x10000000\r
+\r
+#define        IPV6_DUMMY_FOR_IPV4                     0xFEFFFFDF\r
+\r
+\r
+// IP アドレス\r
+struct IP\r
+{\r
+       UCHAR addr[4];                                  // IPv4 アドレス, ※ 223.255.255.254 = IPv6 を意味する\r
+       UCHAR ipv6_addr[16];                    // IPv6 アドレス\r
+       UINT ipv6_scope_id;                             // IPv6 スコープ ID\r
+};\r
+\r
+// IP 構造体をアドレス部分のみで比較する際のサイズ\r
+#define        SIZE_OF_IP_FOR_ADDR                     (sizeof(UCHAR) * 20)\r
+\r
+// IP アドレス部を比較\r
+#define        CmpIpAddr(ip1, ip2)                     (Cmp((ip1), (ip2), SIZE_OF_IP_FOR_ADDR))\r
+\r
+// IPv6 アドレス (異形式)\r
+struct IPV6_ADDR\r
+{\r
+       UCHAR Value[16];                                // 値\r
+} GCC_PACKED;\r
+\r
+// IPv6アドレスの種類\r
+#define IPV6_ADDR_UNICAST                                              1       // ユニキャスト\r
+#define IPV6_ADDR_LOCAL_UNICAST                                        2       // ローカルユニキャスト\r
+#define IPV6_ADDR_GLOBAL_UNICAST                               4       // グローバルユニキャスト\r
+#define IPV6_ADDR_MULTICAST                                            8       // マルチキャスト\r
+#define IPV6_ADDR_ALL_NODE_MULTICAST                   16      // 全ノードマルチキャスト\r
+#define IPV6_ADDR_ALL_ROUTER_MULTICAST                 32      // 全ルータマルチキャスト\r
+#define IPV6_ADDR_SOLICIATION_MULTICAST                        64      // 要請ノードマルチキャスト\r
+#define        IPV6_ADDR_ZERO                                                  128     // オールゼロ\r
+#define        IPV6_ADDR_LOOPBACK                                              256     // ループバック\r
+\r
+\r
+// DNS キャッシュリスト\r
+struct DNSCACHE\r
+{\r
+       char *HostName;\r
+       IP IpAddress;\r
+};\r
+\r
+// クライアントリスト\r
+struct IP_CLIENT\r
+{\r
+       IP IpAddress;                                   // IP アドレス\r
+       UINT NumConnections;                    // 接続個数\r
+};\r
+\r
+// ソケットイベント\r
+struct SOCK_EVENT\r
+{\r
+       REF *ref;                                               // 参照カウンタ\r
+#ifdef OS_WIN32\r
+       void *hEvent;                                   // Win32 イベントハンドルへのポインタ\r
+#else  // OS_WIN32\r
+       LIST *SockList;                                 // ソケットリスト\r
+       int pipe_read, pipe_write;              // パイプ\r
+#endif // OS_WIN32\r
+};\r
+\r
+// ソケットの種類\r
+#define        SOCK_TCP                                1\r
+#define        SOCK_UDP                                2\r
+\r
+// ソケット\r
+struct SOCK\r
+{\r
+       REF *ref;                                       // 参照カウンタ\r
+       LOCK *lock;                                     // ロック\r
+       LOCK *ssl_lock;                         // SSL 関係のロック\r
+       LOCK *disconnect_lock;          // 切断用ロック\r
+       SOCKET socket;                          // ソケット番号\r
+       SSL *ssl;                                       // SSL オブジェクト\r
+       UINT Type;                                      // ソケットの種類\r
+       bool Connected;                         // 接続中フラグ\r
+       bool ServerMode;                        // サーバーモード\r
+       bool AsyncMode;                         // 非同期モード\r
+       bool SecureMode;                        // SSL 通信モード\r
+       bool ListenMode;                        // Listen 中\r
+       BUF *SendBuf;                           // 送信バッファ\r
+       IP RemoteIP;                            // リモートホストの IP アドレス\r
+       IP LocalIP;                                     // ローカルホストの IP アドレス\r
+       char *RemoteHostname;           // リモートホスト名\r
+       UINT RemotePort;                        // リモート側のポート番号\r
+       UINT LocalPort;                         // ローカル側のポート番号\r
+       UINT64 SendSize;                        // 送信したデータサイズの合計\r
+       UINT64 RecvSize;                        // 受信したデータサイズの合計\r
+       UINT64 SendNum;                         // 送信したデータブロック数\r
+       UINT64 RecvNum;                         // 受信したデータブロック数\r
+       X *RemoteX;                                     // リモートホストの証明書\r
+       X *LocalX;                                      // ローカルホストの証明書\r
+       char *CipherName;                       // 暗号化アルゴリズム名\r
+       char *WaitToUseCipher;          // 使用したいアルゴリズム名を設定する\r
+       bool IgnoreRecvErr;                     // RecvFrom エラーを無視できるかどうか\r
+       bool IgnoreSendErr;                     // SendTo エラーを無視できるかどうか\r
+       UINT TimeOut;                           // タイムアウト値\r
+       SOCK_EVENT *SockEvent;          // 関連付けられているソケットイベント\r
+       bool CancelAccept;                      // Accept のキャンセルフラグ\r
+       bool WriteBlocked;                      // 前回の書き込みがブロックされた\r
+       bool Disconnecting;                     // 切断しようとしている\r
+       bool UdpBroadcast;                      // UDP ブロードキャストモード\r
+       void *Param;                            // 任意のパラメータ\r
+       bool IPv6;                                      // IPv6\r
+\r
+#ifdef OS_UNIX\r
+       pthread_t CallingThread;        // システムコールを呼び出しているスレッド\r
+#endif // OS_UNIX\r
+\r
+#ifdef OS_WIN32\r
+       void *hEvent;                           // 非同期モードの場合のイベント\r
+#endif // OS_WIN32\r
+};\r
+\r
+// 戻り値の定数\r
+#define        SOCK_LATER      (0xffffffff)    // ブロッキング中\r
+\r
+// ソケットセット\r
+#define        MAX_SOCKSET_NUM         60              // ソケットセットに格納できるソケット数\r
+struct SOCKSET\r
+{\r
+       UINT NumSocket;                                 // ソケット数\r
+       SOCK *Sock[MAX_SOCKSET_NUM];    // ソケットへのポインタの配列\r
+};\r
+\r
+// キャンセルオブジェクト\r
+struct CANCEL\r
+{\r
+       REF *ref;                                               // 参照カウンタ\r
+       bool SpecialFlag;                               // 特殊フラグ (Win32 ドライバが生成したイベントを関連付ける)\r
+#ifdef OS_WIN32\r
+       void *hEvent;                                   // Win32 イベントハンドルへのポインタ\r
+#else  // OS_WIN32\r
+       int pipe_read, pipe_write;              // パイプ\r
+#endif // OS_WIN32\r
+};\r
+\r
+// ルーティングテーブルエントリ\r
+struct ROUTE_ENTRY\r
+{\r
+       IP DestIP;\r
+       IP DestMask;\r
+       IP GatewayIP;\r
+       bool LocalRouting;\r
+       bool PPPConnection;\r
+       UINT Metric;\r
+       UINT OldIfMetric;\r
+       UINT InterfaceID;\r
+};\r
+\r
+// ルーティングテーブル\r
+struct ROUTE_TABLE\r
+{\r
+       UINT NumEntry;\r
+       UINT HashedValue;\r
+       ROUTE_ENTRY **Entry;\r
+};\r
+\r
+// ホスト名キャッシュリスト\r
+typedef struct HOSTCACHE\r
+{\r
+       UINT64 Expires;                                                 // 有効期限\r
+       IP IpAddress;                                                   // IP アドレス\r
+       char HostName[256];                                             // ホスト名\r
+} HOSTCACHE;\r
+\r
+// NETBIOS 名前要求\r
+typedef struct NBTREQUEST\r
+{\r
+       USHORT TransactionId;\r
+       USHORT Flags;\r
+       USHORT NumQuestions;\r
+       USHORT AnswerRRs;\r
+       USHORT AuthorityRRs;\r
+       USHORT AdditionalRRs;\r
+       UCHAR Query[38];\r
+} NBTREQUEST;\r
+\r
+// NETBIOS 名前応答\r
+typedef struct NBTRESPONSE\r
+{\r
+       USHORT TransactionId;\r
+       USHORT Flags;\r
+       USHORT NumQuestions;\r
+       USHORT AnswerRRs;\r
+       USHORT AuthorityRRs;\r
+       USHORT AdditionalRRs;\r
+       UCHAR Response[61];\r
+} NBTRESPONSE;\r
+\r
+// ソケットリスト\r
+typedef struct SOCKLIST\r
+{\r
+       LIST *SockList;\r
+} SOCKLIST;\r
+\r
+\r
+// Solaris 用タイムアウトスレッドのパラメータ\r
+typedef struct SOCKET_TIMEOUT_PARAM{\r
+       SOCK *sock;\r
+       CANCEL *cancel;\r
+       THREAD *thread;\r
+       bool unblocked;\r
+} SOCKET_TIMEOUT_PARAM;\r
+\r
+// GetIP 用スレッドのパラメータ\r
+struct GETIP_THREAD_PARAM\r
+{\r
+       REF *Ref;\r
+       char HostName[MAX_PATH];\r
+       bool IPv6;\r
+       UINT Timeout;\r
+       IP Ip;\r
+       bool Ok;\r
+};\r
+\r
+// IP アドレスリリース用スレッドのパラメータ\r
+struct WIN32_RELEASEADDRESS_THREAD_PARAM\r
+{\r
+       REF *Ref;\r
+       char Guid[MAX_SIZE];\r
+       UINT Timeout;\r
+       bool Ok;\r
+       bool Renew;\r
+};\r
+\r
+// TCP テーブルエントリ\r
+typedef struct TCPTABLE\r
+{\r
+       UINT Status;\r
+       IP LocalIP;\r
+       UINT LocalPort;\r
+       IP RemoteIP;\r
+       UINT RemotePort;\r
+       UINT ProcessId;\r
+} TCPTABLE;\r
+\r
+// TCP の状態\r
+#define        TCP_STATE_CLOSED                                1\r
+#define        TCP_STATE_LISTEN                                2\r
+#define        TCP_STATE_SYN_SENT                              3\r
+#define        TCP_STATE_SYN_RCVD                              4\r
+#define        TCP_STATE_ESTAB                                 5\r
+#define        TCP_STATE_FIN_WAIT1                             6\r
+#define        TCP_STATE_FIN_WAIT2                             7\r
+#define        TCP_STATE_CLOSE_WAIT                    8\r
+#define        TCP_STATE_CLOSING                               9\r
+#define        TCP_STATE_LAST_ACK                              10\r
+#define        TCP_STATE_TIME_WAIT                             11\r
+#define        TCP_STATE_DELETE_TCB                    12\r
+\r
+// ルーティングテーブル変化通知\r
+struct ROUTE_CHANGE\r
+{\r
+       ROUTE_CHANGE_DATA *Data;\r
+};\r
+\r
+\r
+#ifdef OS_WIN32\r
+\r
+// Win32 用関数プロトタイプ\r
+void Win32InitSocketLibrary();\r
+void Win32FreeSocketLibrary();\r
+void Win32Select(SOCKSET *set, UINT timeout, CANCEL *c1, CANCEL *c2);\r
+void Win32InitAsyncSocket(SOCK *sock);\r
+void Win32JoinSockToSockEvent(SOCK *sock, SOCK_EVENT *event);\r
+void Win32FreeAsyncSocket(SOCK *sock);\r
+void Win32IpForwardRowToRouteEntry(ROUTE_ENTRY *entry, void *ip_forward_row);\r
+void Win32RouteEntryToIpForwardRow(void *ip_forward_row, ROUTE_ENTRY *entry);\r
+int Win32CompareRouteEntryByMetric(void *p1, void *p2);\r
+ROUTE_TABLE *Win32GetRouteTable();\r
+bool Win32AddRouteEntry(ROUTE_ENTRY *e, bool *already_exists);\r
+void Win32DeleteRouteEntry(ROUTE_ENTRY *e);\r
+void Win32UINTToIP(IP *ip, UINT i);\r
+UINT Win32IPToUINT(IP *ip);\r
+UINT Win32GetVLanInterfaceID(char *instance_name);\r
+char **Win32EnumVLan(char *tag_name);\r
+void Win32Cancel(CANCEL *c);\r
+void Win32CleanupCancel(CANCEL *c);\r
+CANCEL *Win32NewCancel();\r
+SOCK_EVENT *Win32NewSockEvent();\r
+void Win32SetSockEvent(SOCK_EVENT *event);\r
+void Win32CleanupSockEvent(SOCK_EVENT *event);\r
+bool Win32WaitSockEvent(SOCK_EVENT *event, UINT timeout);\r
+bool Win32GetDefaultDns(IP *ip, char *domain, UINT size);\r
+void Win32RenewDhcp();\r
+void Win32RenewDhcp9x(UINT if_id);\r
+void Win32ReleaseDhcp9x(UINT if_id, bool wait);\r
+int CompareIpAdapterIndexMap(void *p1, void *p2);\r
+LIST *Win32GetTcpTableList();\r
+LIST *Win32GetTcpTableListByGetExtendedTcpTable();\r
+LIST *Win32GetTcpTableListByAllocateAndGetTcpExTableFromStack();\r
+LIST *Win32GetTcpTableListByGetTcpTable();\r
+ROUTE_CHANGE *Win32NewRouteChange();\r
+void Win32FreeRouteChange(ROUTE_CHANGE *r);\r
+bool Win32IsRouteChanged(ROUTE_CHANGE *r);\r
+bool Win32GetAdapterFromGuid(void *a, char *guid);\r
+\r
+bool Win32ReleaseAddress(void *a);\r
+bool Win32ReleaseAddressByGuid(char *guid);\r
+bool Win32ReleaseAddressByGuidEx(char *guid, UINT timeout);\r
+void Win32ReleaseAddressByGuidExThread(THREAD *t, void *param);\r
+void ReleaseWin32ReleaseAddressByGuidThreadParam(WIN32_RELEASEADDRESS_THREAD_PARAM *p);\r
+bool Win32ReleaseOrRenewAddressByGuidEx(char *guid, UINT timeout, bool renew);\r
+bool Win32RenewAddress(void *a);\r
+bool Win32RenewAddressByGuid(char *guid);\r
+bool Win32RenewAddressByGuidEx(char *guid, UINT timeout);\r
+\r
+\r
+#else  // OS_WIN32\r
+\r
+// UNIX 用関数プロトタイプ\r
+void UnixInitSocketLibrary();\r
+void UnixFreeSocketLibrary();\r
+void UnixSelect(SOCKSET *set, UINT timeout, CANCEL *c1, CANCEL *c2);\r
+void UnixInitAsyncSocket(SOCK *sock);\r
+void UnixJoinSockToSockEvent(SOCK *sock, SOCK_EVENT *event);\r
+void UnixFreeAsyncSocket(SOCK *sock);\r
+void UnixIpForwardRowToRouteEntry(ROUTE_ENTRY *entry, void *ip_forward_row);\r
+void UnixRouteEntryToIpForwardRow(void *ip_forward_row, ROUTE_ENTRY *entry);\r
+int UnixCompareRouteEntryByMetric(void *p1, void *p2);\r
+ROUTE_TABLE *UnixGetRouteTable();\r
+bool UnixAddRouteEntry(ROUTE_ENTRY *e, bool *already_exists);\r
+void UnixDeleteRouteEntry(ROUTE_ENTRY *e);\r
+UINT UnixGetVLanInterfaceID(char *instance_name);\r
+char **UnixEnumVLan(char *tag_name);\r
+void UnixCancel(CANCEL *c);\r
+void UnixCleanupCancel(CANCEL *c);\r
+CANCEL *UnixNewCancel();\r
+SOCK_EVENT *UnixNewSockEvent();\r
+void UnixSetSockEvent(SOCK_EVENT *event);\r
+void UnixCleanupSockEvent(SOCK_EVENT *event);\r
+bool UnixWaitSockEvent(SOCK_EVENT *event, UINT timeout);\r
+bool UnixGetDefaultDns(IP *ip);\r
+void UnixRenewDhcp();\r
+void UnixNewPipe(int *pipe_read, int *pipe_write);\r
+void UnixWritePipe(int pipe_write);\r
+void UnixDeletePipe(int p1, int p2);\r
+void UnixSelectInner(UINT num_read, UINT *reads, UINT num_write, UINT *writes, UINT timeout);\r
+void UnixSetSocketNonBlockingMode(int fd, bool nonblock);\r
+\r
+#endif // OS_WIN32\r
+\r
+// 関数プロトタイプ\r
+void InitNetwork();\r
+void FreeNetwork();\r
+void InitDnsCache();\r
+void FreeDnsCache();\r
+void LockDnsCache();\r
+void UnlockDnsCache();\r
+int CompareDnsCache(void *p1, void *p2);\r
+void GenDnsCacheKeyName(char *dst, UINT size, char *src, bool ipv6);\r
+void NewDnsCacheEx(char *hostname, IP *ip, bool ipv6);\r
+DNSCACHE *FindDnsCacheEx(char *hostname, bool ipv6);\r
+bool QueryDnsCacheEx(IP *ip, char *hostname, bool ipv6);\r
+void NewDnsCache(char *hostname, IP *ip);\r
+DNSCACHE *FindDnsCache(char *hostname);\r
+bool QueryDnsCache(IP *ip, char *hostname);\r
+void InAddrToIP(IP *ip, struct in_addr *addr);\r
+void InAddrToIP6(IP *ip, struct in6_addr *addr);\r
+void IPToInAddr(struct in_addr *addr, IP *ip);\r
+void IPToInAddr6(struct in6_addr *addr, IP *ip);\r
+bool StrToIP(IP *ip, char *str);\r
+UINT StrToIP32(char *str);\r
+bool UniStrToIP(IP *ip, wchar_t *str);\r
+UINT UniStrToIP32(wchar_t *str);\r
+void IPToStr(char *str, UINT size, IP *ip);\r
+void IPToStr4(char *str, UINT size, IP *ip);\r
+void IPToStr32(char *str, UINT size, UINT ip);\r
+void IPToStr128(char *str, UINT size, UCHAR *ip_bytes);\r
+void IPToStr4or6(char *str, UINT size, UINT ip_4_uint, UCHAR *ip_6_bytes);\r
+void IPToUniStr(wchar_t *str, UINT size, IP *ip);\r
+void IPToUniStr32(wchar_t *str, UINT size, UINT ip);\r
+bool GetIPEx(IP *ip, char *hostname, bool ipv6);\r
+bool GetIP46(IP *ip4, IP *ip6, char *hostname);\r
+bool GetIP46Ex(IP *ip4, IP *ip6, char *hostname, UINT timeout, bool *cancel);\r
+bool GetIP46Any4(IP *ip, char *hostname);\r
+bool GetIP46Any6(IP *ip, char *hostname);\r
+bool GetIP(IP *ip, char *hostname);\r
+bool GetIP4(IP *ip, char *hostname);\r
+bool GetIP6(IP *ip, char *hostname);\r
+bool GetIP4Ex(IP *ip, char *hostname, UINT timeout, bool *cancel);\r
+bool GetIP6Ex(IP *ip, char *hostname, UINT timeout, bool *cancel);\r
+bool GetIP4Ex6Ex(IP *ip, char *hostname, UINT timeout, bool ipv6, bool *cancel);\r
+void GetIP4Ex6ExThread(THREAD *t, void *param);\r
+void ReleaseGetIPThreadParam(GETIP_THREAD_PARAM *p);\r
+void CleanupGetIPThreadParam(GETIP_THREAD_PARAM *p);\r
+bool GetIP4Inner(IP *ip, char *hostname);\r
+bool GetIP6Inner(IP *ip, char *hostname);\r
+bool GetHostNameInner(char *hostname, UINT size, IP *ip);\r
+bool GetHostNameInner6(char *hostname, UINT size, IP *ip);\r
+bool GetHostName(char *hostname, UINT size, IP *ip);\r
+void GetHostNameThread(THREAD *t, void *p);\r
+void GetMachineName(char *name, UINT size);\r
+void GetMachineNameEx(char *name, UINT size, bool no_load_hosts);\r
+bool GetMachineNameFromHosts(char *name, UINT size);\r
+void GetMachineIp(IP *ip);\r
+void GetMachineHostName(char *name, UINT size);\r
+void UINTToIP(IP *ip, UINT value);\r
+UINT IPToUINT(IP *ip);\r
+SOCK *NewSock();\r
+void ReleaseSock(SOCK *s);\r
+void CleanupSock(SOCK *s);\r
+SOCK *Connect(char *hostname, UINT port);\r
+SOCK *ConnectEx(char *hostname, UINT port, UINT timeout);\r
+SOCK *ConnectEx2(char *hostname, UINT port, UINT timeout, bool *cancel_flag);\r
+void SetSocketSendRecvBufferSize(int s, UINT size);\r
+void QuerySocketInformation(SOCK *sock);\r
+void Disconnect(SOCK *sock);\r
+SOCK *Listen(UINT port);\r
+SOCK *ListenEx(UINT port, bool local_only);\r
+SOCK *Listen6(UINT port);\r
+SOCK *ListenEx6(UINT port, bool local_only);\r
+SOCK *Accept(SOCK *sock);\r
+SOCK *Accept6(SOCK *sock);\r
+UINT Send(SOCK *sock, void *data, UINT size, bool secure);\r
+UINT Recv(SOCK *sock, void *data, UINT size, bool secure);\r
+UINT SecureSend(SOCK *sock, void *data, UINT size);\r
+UINT SecureRecv(SOCK *sock, void *data, UINT size);\r
+bool StartSSL(SOCK *sock, X *x, K *priv);\r
+bool StartSSLEx(SOCK *sock, X *x, K *priv, bool client_tls);\r
+bool SendAll(SOCK *sock, void *data, UINT size, bool secure);\r
+void SendAdd(SOCK *sock, void *data, UINT size);\r
+bool SendNow(SOCK *sock, int secure);\r
+bool RecvAll(SOCK *sock, void *data, UINT size, bool secure);\r
+void InitSockSet(SOCKSET *set);\r
+void AddSockSet(SOCKSET *set, SOCK *sock);\r
+CANCEL *NewCancel();\r
+CANCEL *NewCancelSpecial(void *hEvent);\r
+void ReleaseCancel(CANCEL *c);\r
+void CleanupCancel(CANCEL *c);\r
+void Cancel(CANCEL *c);\r
+void Select(SOCKSET *set, UINT timeout, CANCEL *c1, CANCEL *c2);\r
+void SetWantToUseCipher(SOCK *sock, char *name);\r
+SOCK *NewUDP(UINT port);\r
+SOCK *NewUDPEx(UINT port, bool ipv6);\r
+SOCK *NewUDP4(UINT port);\r
+SOCK *NewUDP6(UINT port);\r
+UINT SendTo(SOCK *sock, IP *dest_addr, UINT dest_port, void *data, UINT size);\r
+UINT SendTo6(SOCK *sock, IP *dest_addr, UINT dest_port, void *data, UINT size);\r
+UINT RecvFrom(SOCK *sock, IP *src_addr, UINT *src_port, void *data, UINT size);\r
+UINT RecvFrom6(SOCK *sock, IP *src_addr, UINT *src_port, void *data, UINT size);\r
+void SetTimeout(SOCK *sock, UINT timeout);\r
+UINT GetTimeout(SOCK *sock);\r
+void LockOpenSSL();\r
+void UnlockOpenSSL();\r
+bool CheckTCPPort(char *hostname, UINT port);\r
+bool CheckTCPPortEx(char *hostname, UINT port, UINT timeout);\r
+void CheckTCPPortThread(THREAD *thread, void *param);\r
+ROUTE_TABLE *GetRouteTable();\r
+void FreeRouteTable(ROUTE_TABLE *t);\r
+bool AddRouteEntryEx(ROUTE_ENTRY *e, bool *already_exists);\r
+bool AddRouteEntry(ROUTE_ENTRY *e);\r
+void DeleteRouteEntry(ROUTE_ENTRY *e);\r
+char **EnumVLan(char *tag_name);\r
+void FreeEnumVLan(char **s);\r
+UINT GetVLanInterfaceID(char *tag_name);\r
+ROUTE_ENTRY *GetBestRouteEntry(IP *ip);\r
+ROUTE_ENTRY *GetBestRouteEntryEx(IP *ip, UINT exclude_if_id);\r
+ROUTE_ENTRY *GetBestRouteEntryFromRouteTable(ROUTE_TABLE *table, IP *ip);\r
+ROUTE_ENTRY *GetBestRouteEntryFromRouteTableEx(ROUTE_TABLE *table, IP *ip, UINT exclude_if_id);\r
+void FreeRouteEntry(ROUTE_ENTRY *e);\r
+void JoinSockToSockEvent(SOCK *sock, SOCK_EVENT *event);\r
+SOCK_EVENT *NewSockEvent();\r
+void SetSockEvent(SOCK_EVENT *event);\r
+void CleanupSockEvent(SOCK_EVENT *event);\r
+bool WaitSockEvent(SOCK_EVENT *event, UINT timeout);\r
+void ReleaseSockEvent(SOCK_EVENT *event);\r
+void SetIP(IP *ip, UCHAR a1, UCHAR a2, UCHAR a3, UCHAR a4);\r
+bool GetDefaultDns(IP *ip);\r
+bool GetDomainName(char *name, UINT size);\r
+bool UnixGetDomainName(char *name, UINT size);\r
+void RenewDhcp();\r
+void AcceptInit(SOCK *s);\r
+bool CheckCipherListName(char *name);\r
+TOKEN_LIST *GetCipherList();\r
+COUNTER *GetNumTcpConnectionsCounter();\r
+void InitWaitThread();\r
+void FreeWaitThread();\r
+void AddWaitThread(THREAD *t);\r
+void DelWaitThread(THREAD *t);\r
+void InitHostCache();\r
+void FreeHostCache();\r
+int CompareHostCache(void *p1, void *p2);\r
+void AddHostCache(IP *ip, char *hostname);\r
+bool GetHostCache(char *hostname, UINT size, IP *ip);\r
+bool IsSubnetMask(IP *ip);\r
+bool IsSubnetMask4(IP *ip);\r
+bool IsSubnetMask32(UINT ip);\r
+bool IsNetworkAddress(IP *ip, IP *mask);\r
+bool IsNetworkAddress4(IP *ip, IP *mask);\r
+bool IsNetworkAddress32(UINT ip, UINT mask);\r
+bool IsHostIPAddress4(IP *ip);\r
+bool IsHostIPAddress32(UINT ip);\r
+bool IsZeroIp(IP *ip);\r
+bool IsZeroIP(IP *ip);\r
+bool IsZeroIP6Addr(IPV6_ADDR *addr);\r
+UINT IntToSubnetMask32(UINT i);\r
+void IntToSubnetMask4(IP *ip, UINT i);\r
+bool GetNetBiosName(char *name, UINT size, IP *ip);\r
+bool NormalizeMacAddress(char *dst, UINT size, char *src);\r
+SOCKLIST *NewSockList();\r
+void AddSockList(SOCKLIST *sl, SOCK *s);\r
+void DelSockList(SOCKLIST *sl, SOCK *s);\r
+void StopSockList(SOCKLIST *sl);\r
+void FreeSockList(SOCKLIST *sl);\r
+bool IsIPv6Supported();\r
+void SetSockPriorityHigh(SOCK *s);\r
+void InitIpClientList();\r
+void FreeIpClientList();\r
+int CompareIpClientList(void *p1, void *p2);\r
+void AddIpClient(IP *ip);\r
+void DelIpClient(IP *ip);\r
+IP_CLIENT *SearchIpClient(IP *ip);\r
+UINT GetNumIpClient(IP *ip);\r
+void SetLinuxArpFilter();\r
+LIST *GetTcpTableList();\r
+void FreeTcpTableList(LIST *o);\r
+int CompareTcpTable(void *p1, void *p2);\r
+void PrintTcpTableList(LIST *o);\r
+TCPTABLE *GetTcpTableFromEndPoint(LIST *o, IP *local_ip, UINT local_port, IP *remote_ip, UINT remote_port);\r
+UINT GetTcpProcessIdFromSocket(SOCK *s);\r
+UINT GetTcpProcessIdFromSocketReverse(SOCK *s);\r
+bool CanGetTcpProcessId();\r
+int connect_timeout(SOCKET s, struct sockaddr *addr, int size, int timeout, bool *cancel_flag);\r
+void EnableNetworkNameCache();\r
+void DisableNetworkNameCache();\r
+bool IsNetworkNameCacheEnabled();\r
+ROUTE_CHANGE *NewRouteChange();\r
+void FreeRouteChange(ROUTE_CHANGE *r);\r
+bool IsRouteChanged(ROUTE_CHANGE *r);\r
+void RouteToStr(char *str, UINT str_size, ROUTE_ENTRY *e);\r
+void DebugPrintRoute(ROUTE_ENTRY *e);\r
+void DebugPrintRouteTable(ROUTE_TABLE *r);\r
+\r
+void SocketTimeoutThread(THREAD *t, void *param);\r
+SOCKET_TIMEOUT_PARAM *NewSocketTimeout(SOCK *sock);\r
+void FreeSocketTimeout(SOCKET_TIMEOUT_PARAM *ttp);\r
+\r
+bool CheckSubnetLength6(UINT i);\r
+bool IsIP6(IP *ip);\r
+bool IsIP4(IP *ip);\r
+void IPv6AddrToIP(IP *ip, IPV6_ADDR *addr);\r
+bool IPToIPv6Addr(IPV6_ADDR *addr, IP *ip);\r
+void SetIP6(IP *ip, UCHAR *value);\r
+void GetLocalHostIP6(IP *ip);\r
+void ZeroIP6(IP *ip);\r
+void ZeroIP4(IP *ip);\r
+bool CheckIPItemStr6(char *str);\r
+void IPItemStrToChars6(UCHAR *chars, char *str);\r
+bool StrToIP6(IP *ip, char *str);\r
+bool StrToIP6Addr(IPV6_ADDR *ip, char *str);\r
+void IPToStr6(char *str, UINT size, IP *ip);\r
+void IP6AddrToStr(char *str, UINT size, IPV6_ADDR *addr);\r
+void IPToStr6Array(char *str, UINT size, UCHAR *bytes);\r
+void IPToStr6Inner(char *str, IP *ip);\r
+void IntToSubnetMask6(IP *ip, UINT i);\r
+void IPNot6(IP *dst, IP *a);\r
+void IPOr6(IP *dst, IP *a, IP *b);\r
+void IPAnd6(IP *dst, IP *a, IP *b);\r
+void GetAllRouterMulticastAddress6(IP *ip);\r
+void GetAllNodeMulticaseAddress6(IP *ip);\r
+void GetLoopbackAddress6(IP *ip);\r
+void GetAllFilledAddress6(IP *ip);\r
+UINT GetIPAddrType6(IP *ip);\r
+UINT GetIPv6AddrType(IPV6_ADDR *addr);\r
+void GenerateMulticastMacAddress6(UCHAR *mac, IP *ip);\r
+void GetSoliciationMulticastAddr6(IP *dst, IP *src);\r
+bool CheckUnicastAddress(IP *ip);\r
+bool IsNetworkPrefixAddress6(IP *ip, IP *subnet);\r
+bool IsNetworkAddress6(IP *ip, IP *subnet);\r
+void GetHostAddress6(IP *dst, IP *ip, IP *subnet);\r
+void GetPrefixAddress6(IP *dst, IP *ip, IP *subnet);\r
+bool IsNetworkPrefixAddress6(IP *ip, IP *subnet);\r
+bool IsInSameNetwork6(IP *a1, IP *a2, IP *subnet);\r
+void GenerateEui64Address6(UCHAR *dst, UCHAR *mac);\r
+void GenerateEui64LocalAddress(IP *a, UCHAR *mac);\r
+void GenerateEui64GlobalAddress(IP *ip, IP *prefix, IP *subnet, UCHAR *mac);\r
+bool IsSubnetMask6(IP *a);\r
+UINT SubnetMaskToInt(IP *a);\r
+UINT SubnetMaskToInt6(IP *a);\r
+UINT SubnetMaskToInt4(IP *a);\r
+bool IsStrIPv6Address(char *str);\r
+\r
+bool ParseIpAndSubnetMask4(char *src, UINT *ip, UINT *mask);\r
+bool ParseIpAndSubnetMask6(char *src, IP *ip, IP *mask);\r
+bool ParseIpAndSubnetMask46(char *src, IP *ip, IP *mask);\r
+bool ParseIpAndMask4(char *src, UINT *ip, UINT *mask);\r
+bool ParseIpAndMask6(char *src, IP *ip, IP *mask);\r
+bool ParseIpAndMask46(char *src, IP *ip, IP *mask);\r
+bool IsIpStr4(char *str);\r
+bool IsIpStr6(char *str);\r
+bool IsIpMask6(char *str);\r
+bool IsIpStr46(char *str);\r
+bool StrToMask4(IP *mask, char *str);\r
+bool StrToMask6(IP *mask, char *str);\r
+bool StrToMask6Addr(IPV6_ADDR *mask, char *str);\r
+bool StrToMask46(IP *mask, char *str, bool ipv6);\r
+void MaskToStr(char *str, UINT size, IP *mask);\r
+void Mask6AddrToStrEx(char *str, UINT size, IPV6_ADDR *mask, bool always_full_address);\r
+void Mask6AddrToStr(char *str, UINT size, IPV6_ADDR *mask);\r
+void MaskToStr32(char *str, UINT size, UINT mask);\r
+void MaskToStr32Ex(char *str, UINT size, UINT mask, bool always_full_address);\r
+void MaskToStrEx(char *str, UINT size, IP *mask, bool always_full_address);\r
+\r
+\r
+#endif // NETWORK_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/OS.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/OS.c
new file mode 100644 (file)
index 0000000..cb3c17f
--- /dev/null
@@ -0,0 +1,510 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// OS.c\r
+// オペレーティングシステム依存コード\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+#undef Lock\r
+#undef Unlock\r
+\r
+// ディスパッチテーブル\r
+static OS_DISPATCH_TABLE *os = NULL;\r
+\r
+// OS 種類を文字列に変換\r
+char *OsTypeToStr(UINT type)\r
+{\r
+       switch (type)\r
+       {\r
+       case 0:\r
+               return "Unsupported OS by SoftEther Corporation\0\n";\r
+       case OSTYPE_WINDOWS_95:\r
+               return "Windows 95\0\n";\r
+       case OSTYPE_WINDOWS_98:\r
+               return "Windows 98\0\n";\r
+       case OSTYPE_WINDOWS_ME:\r
+               return "Windows Millennium Edition\0\n";\r
+       case OSTYPE_WINDOWS_UNKNOWN:\r
+               return "Windows 9x Unknown Version\0\n";\r
+       case OSTYPE_WINDOWS_NT_4_WORKSTATION:\r
+               return "Windows NT 4.0 Workstation\0\n";\r
+       case OSTYPE_WINDOWS_NT_4_SERVER:\r
+               return "Windows NT 4.0 Server\0\n";\r
+       case OSTYPE_WINDOWS_NT_4_SERVER_ENTERPRISE:\r
+               return "Windows NT 4.0 Server, Enterprise Edition\0\n";\r
+       case OSTYPE_WINDOWS_NT_4_BACKOFFICE:\r
+               return "BackOffice Server 4.5\0\n";\r
+       case OSTYPE_WINDOWS_NT_4_SMS:\r
+               return "Small Business Server 4.5\0\n";\r
+       case OSTYPE_WINDOWS_2000_PROFESSIONAL:\r
+               return "Windows 2000 Professional\0\n";\r
+       case OSTYPE_WINDOWS_2000_SERVER:\r
+               return "Windows 2000 Server\0\n";\r
+       case OSTYPE_WINDOWS_2000_ADVANCED_SERVER:\r
+               return "Windows 2000 Advanced Server\0\n";\r
+       case OSTYPE_WINDOWS_2000_DATACENTER_SERVER:\r
+               return "Windows 2000 Datacenter Server\0\n";\r
+       case OSTYPE_WINDOWS_2000_BACKOFFICE:\r
+               return "BackOffice Server 2000\0\n";\r
+       case OSTYPE_WINDOWS_2000_SBS:\r
+               return "Small Business Server 2000\0\n";\r
+       case OSTYPE_WINDOWS_XP_HOME:\r
+               return "Windows XP Home Edition\0\n";\r
+       case OSTYPE_WINDOWS_XP_PROFESSIONAL:\r
+               return "Windows XP Professional\0\n";\r
+       case OSTYPE_WINDOWS_2003_WEB:\r
+               return "Windows Server 2003 Web Edition\0\n";\r
+       case OSTYPE_WINDOWS_2003_STANDARD:\r
+               return "Windows Server 2003 Standard Edition\0\n";\r
+       case OSTYPE_WINDOWS_2003_ENTERPRISE:\r
+               return "Windows Server 2003 Enterprise Edition\0\n";\r
+       case OSTYPE_WINDOWS_2003_DATACENTER:\r
+               return "Windows Server 2003 Datacenter Edition\0\n";\r
+       case OSTYPE_WINDOWS_2003_BACKOFFICE:\r
+               return "BackOffice Server 2003\0\n";\r
+       case OSTYPE_WINDOWS_2003_SBS:\r
+               return "Small Business Server 2003\0\n";\r
+       case OSTYPE_WINDOWS_LONGHORN_PROFESSIONAL:\r
+               return "Windows Vista\0\n";\r
+       case OSTYPE_WINDOWS_LONGHORN_SERVER:\r
+               return "Windows Server 2008\0\n";\r
+       case OSTYPE_WINDOWS_7:\r
+               return "Windows 7\0\n";\r
+       case OSTYPE_WINDOWS_SERVER_2008_R2:\r
+               return "Windows Server 2008 R2\0\n";\r
+       case OSTYPE_WINDOWS_8:\r
+               return "Windows 8 or greater\0\n";\r
+       case OSTYPE_WINDOWS_SERVER_8:\r
+               return "Windows Server 8 or greater\0\n";\r
+       case OSTYPE_UNIX_UNKNOWN:\r
+               return "UNIX System\0\n";\r
+       case OSTYPE_LINUX:\r
+               return "Linux\0\n";\r
+       case OSTYPE_SOLARIS:\r
+               return "Sun Solaris\0\n";\r
+       case OSTYPE_CYGWIN:\r
+               return "Gnu Sygwin\0\n";\r
+       case OSTYPE_BSD:\r
+               return "BSD System\0\n";\r
+       case OSTYPE_MACOS_X:\r
+               return "Mac OS X\0\n";\r
+       }\r
+\r
+       return "Unknown OS";\r
+}\r
+\r
+// 初期化\r
+void OSInit()\r
+{\r
+       // ディスパッチテーブルの取得\r
+#ifdef OS_WIN32\r
+       os = Win32GetDispatchTable();\r
+#else  // OS_WIN32\r
+       os = UnixGetDispatchTable();\r
+#endif // OS_WIN32\r
+\r
+       // OS 固有の初期化関数の呼び出し\r
+       os->Init();\r
+}\r
+\r
+// 解放\r
+void OSFree()\r
+{\r
+       os->Free();\r
+}\r
+\r
+// メモリ情報取得\r
+void OSGetMemInfo(MEMINFO *info)\r
+{\r
+       // 引数チェック\r
+       if (info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       os->GetMemInfo(info);\r
+}\r
+\r
+// イールド\r
+void OSYield()\r
+{\r
+       os->Yield();\r
+}\r
+\r
+// シングルインスタンス開始\r
+void *OSNewSingleInstance(char *instance_name)\r
+{\r
+       return os->NewSingleInstance(instance_name);\r
+}\r
+\r
+void OSFreeSingleInstance(void *data)\r
+{\r
+       os->FreeSingleInstance(data);\r
+}\r
+\r
+// 優先順位を上げる\r
+void OSSetHighPriority()\r
+{\r
+       os->SetHighPriority();\r
+}\r
+\r
+// 優先順位を戻す\r
+void OSRestorePriority()\r
+{\r
+       os->RestorePriority();\r
+}\r
+\r
+// プロダクト ID の取得\r
+char* OSGetProductId()\r
+{\r
+       return os->GetProductId();\r
+}\r
+\r
+// OS がサポートされているかどうかチェックする\r
+bool OSIsSupportedOs()\r
+{\r
+       return os->IsSupportedOs();\r
+}\r
+\r
+// OS 情報の取得\r
+void OSGetOsInfo(OS_INFO *info)\r
+{\r
+       os->GetOsInfo(info);\r
+}\r
+\r
+// アラートの表示\r
+void OSAlert(char *msg, char *caption)\r
+{\r
+       os->Alert(msg, caption);\r
+}\r
+void OSAlertW(wchar_t *msg, wchar_t *caption)\r
+{\r
+       os->AlertW(msg, caption);\r
+}\r
+\r
+// プロセス起動\r
+bool OSRun(char *filename, char *arg, bool hide, bool wait)\r
+{\r
+       return os->Run(filename, arg, hide, wait);\r
+}\r
+bool OSRunW(wchar_t *filename, wchar_t *arg, bool hide, bool wait)\r
+{\r
+       return os->RunW(filename, arg, hide, wait);\r
+}\r
+\r
+// スレッド ID の取得\r
+UINT OSThreadId()\r
+{\r
+       return os->ThreadId();\r
+}\r
+\r
+// リネーム\r
+bool OSFileRename(char *old_name, char *new_name)\r
+{\r
+       return os->FileRename(old_name, new_name);\r
+}\r
+bool OSFileRenameW(wchar_t *old_name, wchar_t *new_name)\r
+{\r
+       return os->FileRenameW(old_name, new_name);\r
+}\r
+\r
+// ファイルサイズを取得する\r
+UINT64 OSFileSize(void *pData)\r
+{\r
+       return os->FileSize(pData);\r
+}\r
+\r
+// ファイルをシークする\r
+bool OSFileSeek(void *pData, UINT mode, int offset)\r
+{\r
+       return os->FileSeek(pData, mode, offset);\r
+}\r
+\r
+// ファイルを削除する\r
+bool OSFileDelete(char *name)\r
+{\r
+       return os->FileDelete(name);\r
+}\r
+bool OSFileDeleteW(wchar_t *name)\r
+{\r
+       return os->FileDeleteW(name);\r
+}\r
+\r
+// ディレクトリを作成する\r
+bool OSMakeDir(char *name)\r
+{\r
+       return os->MakeDir(name);\r
+}\r
+bool OSMakeDirW(wchar_t *name)\r
+{\r
+       return os->MakeDirW(name);\r
+}\r
+\r
+// ディレクトリを削除する\r
+bool OSDeleteDir(char *name)\r
+{\r
+       return os->DeleteDir(name);\r
+}\r
+bool OSDeleteDirW(wchar_t *name)\r
+{\r
+       return os->DeleteDirW(name);\r
+}\r
+\r
+// ファイルを開く\r
+void *OSFileOpen(char *name, bool write_mode, bool read_lock)\r
+{\r
+       return os->FileOpen(name, write_mode, read_lock);\r
+}\r
+void *OSFileOpenW(wchar_t *name, bool write_mode, bool read_lock)\r
+{\r
+       return os->FileOpenW(name, write_mode, read_lock);\r
+}\r
+\r
+// ファイルを作成する\r
+void *OSFileCreate(char *name)\r
+{\r
+       return os->FileCreate(name);\r
+}\r
+void *OSFileCreateW(wchar_t *name)\r
+{\r
+       return os->FileCreateW(name);\r
+}\r
+\r
+// ファイルに書き込む\r
+bool OSFileWrite(void *pData, void *buf, UINT size)\r
+{\r
+       return os->FileWrite(pData, buf, size);\r
+}\r
+\r
+// ファイルから読み込む\r
+bool OSFileRead(void *pData, void *buf, UINT size)\r
+{\r
+       return os->FileRead(pData, buf, size);\r
+}\r
+\r
+// ファイルを閉じる\r
+void OSFileClose(void *pData, bool no_flush)\r
+{\r
+       os->FileClose(pData, no_flush);\r
+}\r
+\r
+// ファイルのフラッシュ\r
+void OSFileFlush(void *pData)\r
+{\r
+       os->FileFlush(pData);\r
+}\r
+\r
+// コールスタックの取得\r
+CALLSTACK_DATA *OSGetCallStack()\r
+{\r
+       return os->GetCallStack();\r
+}\r
+\r
+// シンボル情報の取得\r
+bool OSGetCallStackSymbolInfo(CALLSTACK_DATA *s)\r
+{\r
+       return os->GetCallStackSymbolInfo(s);\r
+}\r
+\r
+// スレッドの終了を待機\r
+bool OSWaitThread(THREAD *t)\r
+{\r
+       return os->WaitThread(t);\r
+}\r
+\r
+// スレッドの解放\r
+void OSFreeThread(THREAD *t)\r
+{\r
+       os->FreeThread(t);\r
+}\r
+\r
+// スレッドの初期化\r
+bool OSInitThread(THREAD *t)\r
+{\r
+       return os->InitThread(t);\r
+}\r
+\r
+// メモリ確保\r
+void *OSMemoryAlloc(UINT size)\r
+{\r
+       return os->MemoryAlloc(size);\r
+}\r
+\r
+// メモリ再確保\r
+void *OSMemoryReAlloc(void *addr, UINT size)\r
+{\r
+       return os->MemoryReAlloc(addr, size);\r
+}\r
+\r
+// メモリ解放\r
+void OSMemoryFree(void *addr)\r
+{\r
+       os->MemoryFree(addr);\r
+}\r
+\r
+// システムタイマの取得\r
+UINT OSGetTick()\r
+{\r
+       return os->GetTick();\r
+}\r
+\r
+// システム時刻の取得\r
+void OSGetSystemTime(SYSTEMTIME *system_time)\r
+{\r
+       os->GetSystemTime(system_time);\r
+}\r
+\r
+// 32bit インクリメント\r
+void OSInc32(UINT *value)\r
+{\r
+       os->Inc32(value);\r
+}\r
+\r
+// 32bit デクリメント\r
+void OSDec32(UINT *value)\r
+{\r
+       os->Dec32(value);\r
+}\r
+\r
+// スレッドの休止\r
+void OSSleep(UINT time)\r
+{\r
+       os->Sleep(time);\r
+}\r
+\r
+// ロック作成\r
+LOCK *OSNewLock()\r
+{\r
+       return os->NewLock();\r
+}\r
+\r
+// ロック\r
+bool OSLock(LOCK *lock)\r
+{\r
+       return os->Lock(lock);\r
+}\r
+\r
+// ロック解除\r
+void OSUnlock(LOCK *lock)\r
+{\r
+       os->Unlock(lock);\r
+}\r
+\r
+// ロック削除\r
+void OSDeleteLock(LOCK *lock)\r
+{\r
+       os->DeleteLock(lock);\r
+}\r
+\r
+// イベント初期化\r
+void OSInitEvent(EVENT *event)\r
+{\r
+       os->InitEvent(event);\r
+}\r
+\r
+// イベントのセット\r
+void OSSetEvent(EVENT *event)\r
+{\r
+       os->SetEvent(event);\r
+}\r
+\r
+// イベントのリセット\r
+void OSResetEvent(EVENT *event)\r
+{\r
+       os->ResetEvent(event);\r
+}\r
+\r
+// イベントの待機\r
+bool OSWaitEvent(EVENT *event, UINT timeout)\r
+{\r
+       return os->WaitEvent(event, timeout);\r
+}\r
+\r
+// イベントの解放\r
+void OSFreeEvent(EVENT *event)\r
+{\r
+       os->FreeEvent(event);\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/OS.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/OS.h
new file mode 100644 (file)
index 0000000..d187878
--- /dev/null
@@ -0,0 +1,213 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// OS.h\r
+// OS.c のヘッダ\r
+\r
+#ifndef        OS_H\r
+#define        OS_H\r
+\r
+// 関数プロトタイプ\r
+char *OsTypeToStr(UINT type);\r
+\r
+void OSInit();\r
+void OSFree();\r
+void *OSMemoryAlloc(UINT size);\r
+void *OSMemoryReAlloc(void *addr, UINT size);\r
+void OSMemoryFree(void *addr);\r
+UINT OSGetTick();\r
+void OSGetSystemTime(SYSTEMTIME *system_time);\r
+void OSInc32(UINT *value);\r
+void OSDec32(UINT *value);\r
+void OSSleep(UINT time);\r
+LOCK *OSNewLock();\r
+bool OSLock(LOCK *lock);\r
+void OSUnlock(LOCK *lock);\r
+void OSDeleteLock(LOCK *lock);\r
+void OSInitEvent(EVENT *event);\r
+void OSSetEvent(EVENT *event);\r
+void OSResetEvent(EVENT *event);\r
+bool OSWaitEvent(EVENT *event, UINT timeout);\r
+void OSFreeEvent(EVENT *event);\r
+bool OSWaitThread(THREAD *t);\r
+void OSFreeThread(THREAD *t);\r
+bool OSInitThread(THREAD *t);\r
+void *OSFileOpen(char *name, bool write_mode, bool read_lock);\r
+void *OSFileOpenW(wchar_t *name, bool write_mode, bool read_lock);\r
+void *OSFileCreate(char *name);\r
+void *OSFileCreateW(wchar_t *name);\r
+bool OSFileWrite(void *pData, void *buf, UINT size);\r
+bool OSFileRead(void *pData, void *buf, UINT size);\r
+void OSFileClose(void *pData, bool no_flush);\r
+void OSFileFlush(void *pData);\r
+UINT64 OSFileSize(void *pData);\r
+bool OSFileSeek(void *pData, UINT mode, int offset);\r
+bool OSFileDelete(char *name);\r
+bool OSFileDeleteW(wchar_t *name);\r
+bool OSMakeDir(char *name);\r
+bool OSMakeDirW(wchar_t *name);\r
+bool OSDeleteDir(char *name);\r
+bool OSDeleteDirW(wchar_t *name);\r
+CALLSTACK_DATA *OSGetCallStack();\r
+bool OSGetCallStackSymbolInfo(CALLSTACK_DATA *s);\r
+bool OSFileRename(char *old_name, char *new_name);\r
+bool OSFileRenameW(wchar_t *old_name, wchar_t *new_name);\r
+UINT OSThreadId();\r
+bool OSRun(char *filename, char *arg, bool hide, bool wait);\r
+bool OSRunW(wchar_t *filename, wchar_t *arg, bool hide, bool wait);\r
+bool OSIsSupportedOs();\r
+void OSGetOsInfo(OS_INFO *info);\r
+void OSAlert(char *msg, char *caption);\r
+void OSAlertW(wchar_t *msg, wchar_t *caption);\r
+char* OSGetProductId();\r
+void OSSetHighPriority();\r
+void OSRestorePriority();\r
+void *OSNewSingleInstance(char *instance_name);\r
+void OSFreeSingleInstance(void *data);\r
+void OSGetMemInfo(MEMINFO *info);\r
+void OSYield();\r
+\r
+// ディスパッチテーブル\r
+typedef struct OS_DISPATCH_TABLE\r
+{\r
+       void (*Init)();\r
+       void (*Free)();\r
+       void *(*MemoryAlloc)(UINT size);\r
+       void *(*MemoryReAlloc)(void *addr, UINT size);\r
+       void (*MemoryFree)(void *addr);\r
+       UINT (*GetTick)();\r
+       void (*GetSystemTime)(SYSTEMTIME *system_time);\r
+       void (*Inc32)(UINT *value);\r
+       void (*Dec32)(UINT *value);\r
+       void (*Sleep)(UINT time);\r
+       LOCK *(*NewLock)();\r
+       bool (*Lock)(LOCK *lock);\r
+       void (*Unlock)(LOCK *lock);\r
+       void (*DeleteLock)(LOCK *lock);\r
+       void (*InitEvent)(EVENT *event);\r
+       void (*SetEvent)(EVENT *event);\r
+       void (*ResetEvent)(EVENT *event);\r
+       bool (*WaitEvent)(EVENT *event, UINT timeout);\r
+       void (*FreeEvent)(EVENT *event);\r
+       bool (*WaitThread)(THREAD *t);\r
+       void (*FreeThread)(THREAD *t);\r
+       bool (*InitThread)(THREAD *t);\r
+       UINT (*ThreadId)();\r
+       void *(*FileOpen)(char *name, bool write_mode, bool read_lock);\r
+       void *(*FileOpenW)(wchar_t *name, bool write_mode, bool read_lock);\r
+       void *(*FileCreate)(char *name);\r
+       void *(*FileCreateW)(wchar_t *name);\r
+       bool (*FileWrite)(void *pData, void *buf, UINT size);\r
+       bool (*FileRead)(void *pData, void *buf, UINT size);\r
+       void (*FileClose)(void *pData, bool no_flush);\r
+       void (*FileFlush)(void *pData);\r
+       UINT64 (*FileSize)(void *pData);\r
+       bool (*FileSeek)(void *pData, UINT mode, int offset);\r
+       bool (*FileDelete)(char *name);\r
+       bool (*FileDeleteW)(wchar_t *name);\r
+       bool (*MakeDir)(char *name);\r
+       bool (*MakeDirW)(wchar_t *name);\r
+       bool (*DeleteDir)(char *name);\r
+       bool (*DeleteDirW)(wchar_t *name);\r
+       CALLSTACK_DATA *(*GetCallStack)();\r
+       bool (*GetCallStackSymbolInfo)(CALLSTACK_DATA *s);\r
+       bool (*FileRename)(char *old_name, char *new_name);\r
+       bool (*FileRenameW)(wchar_t *old_name, wchar_t *new_name);\r
+       bool (*Run)(char *filename, char *arg, bool hide, bool wait);\r
+       bool (*RunW)(wchar_t *filename, wchar_t *arg, bool hide, bool wait);\r
+       bool (*IsSupportedOs)();\r
+       void (*GetOsInfo)(OS_INFO *info);\r
+       void (*Alert)(char *msg, char *caption);\r
+       void (*AlertW)(wchar_t *msg, wchar_t *caption);\r
+       char *(*GetProductId)();\r
+       void (*SetHighPriority)();\r
+       void (*RestorePriority)();\r
+       void *(*NewSingleInstance)(char *instance_name);\r
+       void (*FreeSingleInstance)(void *data);\r
+       void (*GetMemInfo)(MEMINFO *info);\r
+       void (*Yield)();\r
+} OS_DISPATCH_TABLE;\r
+\r
+// OS 固有ヘッダのインクルード\r
+#ifdef OS_WIN32\r
+#include <Mayaqua/Win32.h>\r
+#else  //OS_WIN32\r
+#include <Mayaqua/Unix.h>\r
+#endif // OS_WIN32\r
+\r
+#endif // OS_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Object.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Object.c
new file mode 100644 (file)
index 0000000..f1ef886
--- /dev/null
@@ -0,0 +1,525 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Object.c\r
+// オブジェクト管理コード\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+// 試しにロックをかけてみるスレッド\r
+void CheckDeadLockThread(THREAD *t, void *param)\r
+{\r
+       DEADCHECK *c = (DEADCHECK *)param;\r
+\r
+       if (t == NULL || c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       NoticeThreadInit(t);\r
+\r
+       Lock(c->Lock);\r
+       Unlock(c->Lock);\r
+       c->Unlocked = true;\r
+}\r
+\r
+// デッドロックの検出\r
+void CheckDeadLock(LOCK *lock, UINT timeout, char *name)\r
+{\r
+       DEADCHECK c;\r
+       THREAD *t;\r
+       char msg[MAX_PATH];\r
+\r
+       if (lock == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (name == NULL)\r
+       {\r
+               name = "Unknown";\r
+       }\r
+\r
+       Format(msg, sizeof(msg), "error: CheckDeadLock() Failed: %s\n", name);\r
+\r
+       Zero(&c, sizeof(c));\r
+       c.Lock = lock;\r
+       c.Timeout = timeout;\r
+       c.Unlocked = false;\r
+\r
+       t = NewThread(CheckDeadLockThread, &c);\r
+       WaitThreadInit(t);\r
+       if (WaitThread(t, timeout) == false)\r
+       {\r
+               if (c.Unlocked == false)\r
+               {\r
+                       // デッドロック発生\r
+                       AbortExitEx(msg);\r
+               }\r
+               else\r
+               {\r
+                       WaitThread(t, INFINITE);\r
+               }\r
+       }\r
+\r
+       ReleaseThread(t);\r
+}\r
+\r
+// ロックオブジェクトの作成\r
+LOCK *NewLockMain()\r
+{\r
+       LOCK *lock;\r
+       UINT retry = 0;\r
+\r
+       while (true)\r
+       {\r
+               if ((retry++) > OBJECT_ALLOC__MAX_RETRY)\r
+               {\r
+                       AbortExitEx("error: OSNewLock() failed.\n\n");\r
+               }\r
+               lock = OSNewLock();\r
+               if (lock != NULL)\r
+               {\r
+                       break;\r
+               }\r
+               SleepThread(OBJECT_ALLOC_FAIL_SLEEP_TIME);\r
+       }\r
+\r
+       return lock;\r
+}\r
+LOCK *NewLock()\r
+{\r
+       LOCK *lock = NewLockMain();\r
+\r
+       // KS\r
+       KS_INC(KS_NEWLOCK_COUNT);\r
+       KS_INC(KS_CURRENT_LOCK_COUNT);\r
+\r
+       return lock;\r
+}\r
+\r
+// ロックオブジェクトの削除\r
+void DeleteLock(LOCK *lock)\r
+{\r
+       // 引数チェック\r
+       if (lock == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_DELETELOCK_COUNT);\r
+       KS_DEC(KS_CURRENT_LOCK_COUNT);\r
+\r
+       OSDeleteLock(lock);\r
+}\r
+\r
+// ロック\r
+bool LockInner(LOCK *lock)\r
+{\r
+       // 引数チェック\r
+       if (lock == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_LOCK_COUNT);\r
+       KS_INC(KS_CURRENT_LOCKED_COUNT);\r
+\r
+       return OSLock(lock);\r
+}\r
+\r
+// ロック解除\r
+void UnlockInner(LOCK *lock)\r
+{\r
+       // 引数チェック\r
+       if (lock == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_UNLOCK_COUNT);\r
+       KS_DEC(KS_CURRENT_LOCKED_COUNT);\r
+\r
+       OSUnlock(lock);\r
+}\r
+\r
+// カウンタの作成\r
+COUNTER *NewCounter()\r
+{\r
+       COUNTER *c;\r
+\r
+       // メモリ確保\r
+       c = Malloc(sizeof(COUNTER));\r
+\r
+       // 初期化\r
+       c->Ready = true;\r
+       c->c = 0;\r
+\r
+       // ロック作成\r
+       c->lock = NewLock();\r
+\r
+       // KS\r
+       KS_INC(KS_NEW_COUNTER_COUNT);\r
+\r
+       return c;\r
+}\r
+\r
+// カウンタの削除\r
+void DeleteCounter(COUNTER *c)\r
+{\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_DELETE_COUNTER_COUNT);\r
+       KS_SUB(KS_CURRENT_COUNT, c->c);\r
+\r
+       DeleteLock(c->lock);\r
+       Free(c);\r
+}\r
+\r
+// カウント値の取得\r
+UINT Count(COUNTER *c)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (c->Ready == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Lock(c->lock);\r
+       {\r
+               if (c->Ready == false)\r
+               {\r
+                       ret = 0;\r
+               }\r
+               else\r
+               {\r
+                       ret = c->c;\r
+               }\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// インクリメント\r
+UINT Inc(COUNTER *c)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (c->Ready == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Lock(c->lock);\r
+       {\r
+               if (c->Ready == false)\r
+               {\r
+                       ret = 0;\r
+               }\r
+               else\r
+               {\r
+                       c->c++;\r
+                       ret = c->c;\r
+               }\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       // KS\r
+       KS_INC(KS_INC_COUNT);\r
+       KS_INC(KS_CURRENT_COUNT);\r
+\r
+       return ret;\r
+}\r
+\r
+// デクリメント\r
+UINT Dec(COUNTER *c)\r
+{\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (c == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (c->Ready == false)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Lock(c->lock);\r
+       {\r
+               if (c->Ready == false)\r
+               {\r
+                       ret = 0;\r
+               }\r
+               else\r
+               {\r
+                       if (c->c != 0)\r
+                       {\r
+                               c->c--;\r
+                               ret = c->c;\r
+                       }\r
+                       else\r
+                       {\r
+                               ret = 0;\r
+                       }\r
+               }\r
+       }\r
+       Unlock(c->lock);\r
+\r
+       // KS\r
+       KS_INC(KS_DEC_COUNT);\r
+       KS_DEC(KS_CURRENT_COUNT);\r
+\r
+       return ret;\r
+}\r
+\r
+\r
+// 参照カウンタの解放\r
+UINT Release(REF *ref)\r
+{\r
+       UINT c;\r
+       // 引数チェック\r
+       if (ref == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_RELEASE_COUNT);\r
+       KS_DEC(KS_CURRENT_REFED_COUNT);\r
+\r
+       c = Dec(ref->c);\r
+       if (c == 0)\r
+       {\r
+               // KS\r
+               KS_DEC(KS_CURRENT_REF_COUNT);\r
+               KS_INC(KS_FREEREF_COUNT);\r
+\r
+               DeleteCounter(ref->c);\r
+               ref->c = 0;\r
+               Free(ref);\r
+       }\r
+       return c;\r
+}\r
+\r
+// 参照カウンタの増加\r
+UINT AddRef(REF *ref)\r
+{\r
+       UINT c;\r
+       // 引数チェック\r
+       if (ref == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       c = Inc(ref->c);\r
+\r
+       // KS\r
+       KS_INC(KS_ADDREF_COUNT);\r
+       KS_INC(KS_CURRENT_REFED_COUNT);\r
+\r
+       return c;\r
+}\r
+\r
+// 参照カウンタ作成\r
+REF *NewRef()\r
+{\r
+       REF *ref;\r
+\r
+       // メモリ確保\r
+       ref = Malloc(sizeof(REF));\r
+\r
+       // カウンタ作成\r
+       ref->c = NewCounter();\r
+\r
+       // 1 回だけインクリメント\r
+       Inc(ref->c);\r
+\r
+       // KS\r
+       KS_INC(KS_NEWREF_COUNT);\r
+       KS_INC(KS_CURRENT_REF_COUNT);\r
+       KS_INC(KS_ADDREF_COUNT);\r
+       KS_INC(KS_CURRENT_REFED_COUNT);\r
+\r
+       return ref;\r
+}\r
+\r
+// イベントオブジェクトの作成\r
+EVENT *NewEvent()\r
+{\r
+       // メモリ確保\r
+       EVENT *e = Malloc(sizeof(EVENT));\r
+\r
+       // 参照カウンタ\r
+       e->ref = NewRef();\r
+\r
+       // イベント初期化\r
+       OSInitEvent(e);\r
+\r
+       // KS\r
+       KS_INC(KS_NEWEVENT_COUNT);\r
+\r
+       return e;\r
+}\r
+\r
+// イベントの解放\r
+void ReleaseEvent(EVENT *e)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (Release(e->ref) == 0)\r
+       {\r
+               CleanupEvent(e);\r
+       }\r
+}\r
+\r
+// イベントの削除\r
+void CleanupEvent(EVENT *e)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // イベント解放\r
+       OSFreeEvent(e);\r
+\r
+       // メモリ解放\r
+       Free(e);\r
+\r
+       // KS\r
+       KS_INC(KS_FREEEVENT_COUNT);\r
+}\r
+\r
+// イベントのセット\r
+void Set(EVENT *e)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       OSSetEvent(e);\r
+}\r
+\r
+// イベントの待機\r
+bool Wait(EVENT *e, UINT timeout)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_WAIT_COUNT);\r
+\r
+       return OSWaitEvent(e, timeout);\r
+}\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Object.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Object.h
new file mode 100644 (file)
index 0000000..fe109ad
--- /dev/null
@@ -0,0 +1,181 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Object.h\r
+// Object.c のヘッダ\r
+\r
+#ifndef        OBJECT_H\r
+#define        OBJECT_H\r
+\r
+\r
+// 定数\r
+#define        OBJECT_ALLOC_FAIL_SLEEP_TIME            150\r
+#define        OBJECT_ALLOC__MAX_RETRY                         30\r
+\r
+// ロックオブジェクト\r
+struct LOCK\r
+{\r
+       void *pData;\r
+       BOOL Ready;\r
+#ifdef OS_UNIX\r
+       UINT thread_id;\r
+       UINT locked_count;\r
+#endif // OS_UNIX\r
+#ifdef _DEBUG\r
+       char *FileName;\r
+       UINT Line;\r
+       UINT ThreadId;\r
+#endif // _DEBUG\r
+};\r
+\r
+// カウンタオブジェクト\r
+struct COUNTER\r
+{\r
+       LOCK *lock;\r
+       UINT c;\r
+       bool Ready;\r
+};\r
+\r
+// 参照カウンタ\r
+struct REF\r
+{\r
+       COUNTER *c;\r
+};\r
+\r
+// イベントオブジェクト\r
+struct EVENT\r
+{\r
+       REF *ref;\r
+       void *pData;\r
+};\r
+\r
+// デッドロック検出\r
+struct DEADCHECK\r
+{\r
+       LOCK *Lock;\r
+       UINT Timeout;\r
+       bool Unlocked;\r
+};\r
+\r
+\r
+// ロック関数\r
+#ifndef        _DEBUG\r
+\r
+#define        Lock(lock)              LockInner((lock))\r
+#define        Unlock(lock)    UnlockInner((lock))\r
+\r
+#else  // _DEBUG\r
+\r
+#define        Lock(lock)                      \\r
+       {                                               \\r
+               LockInner(lock);        \\r
+               if (lock != NULL) { lock->FileName = __FILE__; lock->Line = __LINE__; lock->ThreadId = ThreadId();}     \\r
+       }\r
+\r
+#define        Unlock(lock)            \\r
+       {                                               \\r
+               if (lock != NULL) { lock->FileName = NULL; lock->Line = 0; lock->ThreadId = 0;} \\r
+               UnlockInner(lock);      \\r
+       }\r
+\r
+#endif // _DEBUG\r
+\r
+\r
+// 関数プロトタイプ\r
+LOCK *NewLock();\r
+LOCK *NewLockMain();\r
+void DeleteLock(LOCK *lock);\r
+COUNTER *NewCounter();\r
+void UnlockInner(LOCK *lock);\r
+bool LockInner(LOCK *lock);\r
+void DeleteCounter(COUNTER *c);\r
+UINT Count(COUNTER *c);\r
+UINT Inc(COUNTER *c);\r
+UINT Dec(COUNTER *c);\r
+UINT Release(REF *ref);\r
+UINT AddRef(REF *ref);\r
+REF *NewRef();\r
+EVENT *NewEvent();\r
+void ReleaseEvent(EVENT *e);\r
+void CleanupEvent(EVENT *e);\r
+void Set(EVENT *e);\r
+bool Wait(EVENT *e, UINT timeout);\r
+void CheckDeadLock(LOCK *lock, UINT timeout, char *name);\r
+void CheckDeadLockThread(THREAD *t, void *param);\r
+\r
+#endif // OBJECT_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Pack.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Pack.c
new file mode 100644 (file)
index 0000000..9a14e67
--- /dev/null
@@ -0,0 +1,815 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Pack.c\r
+// データパッケージコード\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+// BUF を PACK に変換\r
+PACK *BufToPack(BUF *b)\r
+{\r
+       PACK *p;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       p = NewPack();\r
+       if (ReadPack(b, p) == false)\r
+       {\r
+               FreePack(p);\r
+               return NULL;\r
+       }\r
+\r
+       return p;\r
+}\r
+\r
+// PACK を BUF に変換\r
+BUF *PackToBuf(PACK *p)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       b = NewBuf();\r
+       WritePack(b, p);\r
+\r
+       return b;\r
+}\r
+\r
+// PACK を読み込む\r
+bool ReadPack(BUF *b, PACK *p)\r
+{\r
+       UINT i, num;\r
+       // 引数チェック\r
+       if (b == NULL || p == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // ELEMENT 数\r
+       num = ReadBufInt(b);\r
+       if (num > MAX_ELEMENT_NUM)\r
+       {\r
+               // 個数オーバー\r
+               return false;\r
+       }\r
+\r
+       // ELEMENT を読み込む\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               ELEMENT *e;\r
+               e = ReadElement(b);\r
+               if (AddElement(p, e) == false)\r
+               {\r
+                       // 追加エラー\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// PACK を書き出す\r
+void WritePack(BUF *b, PACK *p)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (b == NULL || p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ELEMENT 数\r
+       WriteBufInt(b, LIST_NUM(p->elements));\r
+\r
+       // ELEMENT を書き出す\r
+       for (i = 0;i < LIST_NUM(p->elements);i++)\r
+       {\r
+               ELEMENT *e = LIST_DATA(p->elements, i);\r
+               WriteElement(b, e);\r
+       }\r
+}\r
+\r
+// ELEMENT を読み込む\r
+ELEMENT *ReadElement(BUF *b)\r
+{\r
+       UINT i;\r
+       char name[MAX_ELEMENT_NAME_LEN + 1];\r
+       UINT type, num_value;\r
+       VALUE **values;\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 名前\r
+       if (ReadBufStr(b, name, sizeof(name)) == false)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 項目の種類\r
+       type = ReadBufInt(b);\r
+\r
+       // 項目数\r
+       num_value = ReadBufInt(b);\r
+       if (num_value > MAX_VALUE_NUM)\r
+       {\r
+               // 個数オーバー\r
+               return NULL;\r
+       }\r
+\r
+       // VALUE\r
+       values = (VALUE **)Malloc(sizeof(VALUE *) * num_value);\r
+       for (i = 0;i < num_value;i++)\r
+       {\r
+               values[i] = ReadValue(b, type);\r
+       }\r
+\r
+       // ELEMENT を作成\r
+       e = NewElement(name, type, num_value, values);\r
+\r
+       Free(values);\r
+\r
+       return e;\r
+}\r
+\r
+// ELEMENT を書き出す\r
+void WriteElement(BUF *b, ELEMENT *e)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (b == NULL || e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 名前\r
+       WriteBufStr(b, e->name);\r
+       // 項目の種類\r
+       WriteBufInt(b, e->type);\r
+       // 項目数\r
+       WriteBufInt(b, e->num_value);\r
+       // VALUE\r
+       for (i = 0;i < e->num_value;i++)\r
+       {\r
+               VALUE *v = e->values[i];\r
+               WriteValue(b, v, e->type);\r
+       }\r
+}\r
+\r
+// VALUE を読み込む\r
+VALUE *ReadValue(BUF *b, UINT type)\r
+{\r
+       UINT len;\r
+       BYTE *u;\r
+       void *data;\r
+       char *str;\r
+       wchar_t *unistr;\r
+       UINT unistr_size;\r
+       UINT size;\r
+       UINT u_size;\r
+       VALUE *v = NULL;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // データ項目\r
+       switch (type)\r
+       {\r
+       case VALUE_INT:                 // 整数\r
+               v = NewIntValue(ReadBufInt(b));\r
+               break;\r
+       case VALUE_INT64:\r
+               v = NewInt64Value(ReadBufInt64(b));\r
+               break;\r
+       case VALUE_DATA:                // データ\r
+               size = ReadBufInt(b);\r
+               if (size > MAX_VALUE_SIZE)\r
+               {\r
+                       // サイズオーバー\r
+                       break;\r
+               }\r
+               data = Malloc(size);\r
+               if (ReadBuf(b, data, size) != size)\r
+               {\r
+                       // 読み込み失敗\r
+                       Free(data);\r
+                       break;\r
+               }\r
+               v = NewDataValue(data, size);\r
+               Free(data);\r
+               break;\r
+       case VALUE_STR:                 // ANSI 文字列\r
+               len = ReadBufInt(b);\r
+               if ((len + 1) > MAX_VALUE_SIZE)\r
+               {\r
+                       // サイズオーバー\r
+                       break;\r
+               }\r
+               str = Malloc(len + 1);\r
+               // 文字列本体\r
+               if (ReadBuf(b, str, len) != len)\r
+               {\r
+                       // 読み込み失敗\r
+                       Free(str);\r
+                       break;\r
+               }\r
+               str[len] = 0;\r
+               v = NewStrValue(str);\r
+               Free(str);\r
+               break;\r
+       case VALUE_UNISTR:              // Unicode 文字列\r
+               u_size = ReadBufInt(b);\r
+               if (u_size > MAX_VALUE_SIZE)\r
+               {\r
+                       // サイズオーバー\r
+                       break;\r
+               }\r
+               // UTF-8 の読み込み\r
+               u = ZeroMalloc(u_size + 1);\r
+               if (ReadBuf(b, u, u_size) != u_size)\r
+               {\r
+                       // 読み込み失敗\r
+                       Free(u);\r
+                       break;\r
+               }\r
+               // Unicode 文字列に変換\r
+               unistr_size = CalcUtf8ToUni(u, u_size);\r
+               if (unistr_size == 0)\r
+               {\r
+                       Free(u);\r
+                       break;\r
+               }\r
+               unistr = Malloc(unistr_size);\r
+               Utf8ToUni(unistr, unistr_size, u, u_size);\r
+               Free(u);\r
+               v = NewUniStrValue(unistr);\r
+               Free(unistr);\r
+               break;\r
+       }\r
+\r
+       return v;\r
+}\r
+\r
+// VALUE を書き出す\r
+void WriteValue(BUF *b, VALUE *v, UINT type)\r
+{\r
+       UINT len;\r
+       BYTE *u;\r
+       UINT u_size;\r
+       // 引数チェック\r
+       if (b == NULL || v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // データ項目\r
+       switch (type)\r
+       {\r
+       case VALUE_INT:                 // 整数\r
+               WriteBufInt(b, v->IntValue);\r
+               break;\r
+       case VALUE_INT64:               // 64 bit 整数\r
+               WriteBufInt64(b, v->Int64Value);\r
+               break;\r
+       case VALUE_DATA:                // データ\r
+               // サイズ\r
+               WriteBufInt(b, v->Size);\r
+               // 本体\r
+               WriteBuf(b, v->Data, v->Size);\r
+               break;\r
+       case VALUE_STR:                 // ANSI 文字列\r
+               len = StrLen(v->Str);\r
+               // 長さ\r
+               WriteBufInt(b, len);\r
+               // 文字列本体\r
+               WriteBuf(b, v->Str, len);\r
+               break;\r
+       case VALUE_UNISTR:              // Unicode 文字列\r
+               // UTF-8 に変換する\r
+               u_size = CalcUniToUtf8(v->UniStr) + 1;\r
+               u = ZeroMalloc(u_size);\r
+               UniToUtf8(u, u_size, v->UniStr);\r
+               // サイズ\r
+               WriteBufInt(b, u_size);\r
+               // UTF-8 文字列本体\r
+               WriteBuf(b, u, u_size);\r
+               Free(u);\r
+               break;\r
+       }\r
+}\r
+\r
+// データサイズの取得\r
+UINT GetDataValueSize(ELEMENT *e, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (e->values == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (index >= e->num_value)\r
+       {\r
+               return 0;\r
+       }\r
+       if (e->values[index] == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return e->values[index]->Size;\r
+}\r
+\r
+// データの取得\r
+void *GetDataValue(ELEMENT *e, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (e->values == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (index >= e->num_value)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (e->values[index] == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       return e->values[index]->Data;\r
+}\r
+\r
+// Unicode 文字列型の取得\r
+wchar_t *GetUniStrValue(ELEMENT *e, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (index >= e->num_value)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return e->values[index]->UniStr;\r
+}\r
+\r
+// ANSI 文字列型の取得\r
+char *GetStrValue(ELEMENT *e, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (index >= e->num_value)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return e->values[index]->Str;\r
+}\r
+\r
+// 64 bit 整数型値の取得\r
+UINT64 GetInt64Value(ELEMENT *e, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (index >= e->num_value)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return e->values[index]->Int64Value;\r
+}\r
+\r
+// 整数型値の取得\r
+UINT GetIntValue(ELEMENT *e, UINT index)\r
+{\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (index >= e->num_value)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return e->values[index]->IntValue;\r
+}\r
+\r
+// PACK のソート関数\r
+int ComparePackName(void *p1, void *p2)\r
+{\r
+       ELEMENT *o1, *o2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       o1 = *(ELEMENT **)p1;\r
+       o2 = *(ELEMENT **)p2;\r
+       if (o1 == NULL || o2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCmpi(o1->name, o2->name);\r
+}\r
+\r
+// VALUE の削除\r
+void FreeValue(VALUE *v, UINT type)\r
+{\r
+       // 引数チェック\r
+       if (v == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       switch (type)\r
+       {\r
+       case VALUE_INT:\r
+       case VALUE_INT64:\r
+               break;\r
+       case VALUE_DATA:\r
+               Free(v->Data);\r
+               break;\r
+       case VALUE_STR:\r
+               Free(v->Str);\r
+               break;\r
+       case VALUE_UNISTR:\r
+               Free(v->UniStr);\r
+               break;\r
+       }\r
+\r
+       // メモリ解放\r
+       Free(v);\r
+}\r
+\r
+// Unicode 文字列型の VALUE の作成\r
+VALUE *NewUniStrValue(wchar_t *str)\r
+{\r
+       VALUE *v;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // メモリ確保\r
+       v = Malloc(sizeof(VALUE));\r
+\r
+       // 文字列コピー\r
+       v->Size = UniStrSize(str);\r
+       v->UniStr = Malloc(v->Size);\r
+       UniStrCpy(v->UniStr, v->Size, str);\r
+\r
+       UniTrim(v->UniStr);\r
+\r
+       return v;\r
+}\r
+\r
+// ANSI 文字列型の VALUE の作成\r
+VALUE *NewStrValue(char *str)\r
+{\r
+       VALUE *v;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // メモリ確保\r
+       v = Malloc(sizeof(VALUE));\r
+\r
+       // 文字列コピー\r
+       v->Size = StrLen(str) + 1;\r
+       v->Str = Malloc(v->Size);\r
+       StrCpy(v->Str, v->Size, str);\r
+\r
+       Trim(v->Str);\r
+\r
+       return v;\r
+}\r
+\r
+// データ型の VALUE の作成\r
+VALUE *NewDataValue(void *data, UINT size)\r
+{\r
+       VALUE *v;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // メモリ確保\r
+       v = Malloc(sizeof(VALUE));\r
+\r
+       // データコピー\r
+       v->Size = size;\r
+       v->Data = Malloc(v->Size);\r
+       Copy(v->Data, data, size);\r
+\r
+       return v;\r
+}\r
+\r
+// 64 bit 整数型の VALUE の作成\r
+VALUE *NewInt64Value(UINT64 i)\r
+{\r
+       VALUE *v;\r
+\r
+       v = Malloc(sizeof(VALUE));\r
+       v->Int64Value = i;\r
+       v->Size = sizeof(UINT64);\r
+\r
+       return v;\r
+}\r
+\r
+// 整数型の VALUE の作成\r
+VALUE *NewIntValue(UINT i)\r
+{\r
+       VALUE *v;\r
+\r
+       // メモリ確保\r
+       v = Malloc(sizeof(VALUE));\r
+       v->IntValue = i;\r
+       v->Size = sizeof(UINT);\r
+\r
+       return v;\r
+}\r
+\r
+// ELEMENT の削除\r
+void FreeElement(ELEMENT *e)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (e == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < e->num_value;i++)\r
+       {\r
+               FreeValue(e->values[i], e->type);\r
+       }\r
+       Free(e->values);\r
+\r
+       Free(e);\r
+}\r
+\r
+// ELEMENT の作成\r
+ELEMENT *NewElement(char *name, UINT type, UINT num_value, VALUE **values)\r
+{\r
+       ELEMENT *e;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (name == NULL || num_value == 0 || values == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // メモリ確保\r
+       e = Malloc(sizeof(ELEMENT));\r
+       StrCpy(e->name, sizeof(e->name), name);\r
+       e->num_value = num_value;\r
+       e->type = type;\r
+\r
+       // 要素へのポインタリストのコピー\r
+       e->values = (VALUE **)Malloc(sizeof(VALUE *) * num_value);\r
+       for (i = 0;i < e->num_value;i++)\r
+       {\r
+               e->values[i] = values[i];\r
+       }\r
+\r
+       return e;\r
+}\r
+\r
+// PACK から ELEMENT を検索して取得\r
+ELEMENT *GetElement(PACK *p, char *name, UINT type)\r
+{\r
+       ELEMENT t;\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 検索\r
+       StrCpy(t.name, sizeof(t.name), name);\r
+       e = Search(p->elements, &t);\r
+\r
+       if (e == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 型検査\r
+       if (type != INFINITE)\r
+       {\r
+               if (e->type != type)\r
+               {\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       return e;\r
+}\r
+\r
+// PACK から ELEMENT を削除\r
+void DelElement(PACK *p, char *name)\r
+{\r
+       ELEMENT *e;\r
+       // 引数チェック\r
+       if (p == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       e = GetElement(p, name, INFINITE);\r
+       if (e != NULL)\r
+       {\r
+               Delete(p->elements, e);\r
+\r
+               FreeElement(e);\r
+       }\r
+}\r
+\r
+// PACK に ELEMENT を追加\r
+bool AddElement(PACK *p, ELEMENT *e)\r
+{\r
+       // 引数チェック\r
+       if (p == NULL || e == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // サイズチェック\r
+       if (LIST_NUM(p->elements) >= MAX_ELEMENT_NUM)\r
+       {\r
+               // これ以上追加できない\r
+               FreeElement(e);\r
+               return false;\r
+       }\r
+\r
+       // 同じ名前が存在しないかどうかチェック\r
+       if (GetElement(p, e->name, INFINITE))\r
+       {\r
+               // 存在している\r
+               FreeElement(e);\r
+               return false;\r
+       }\r
+\r
+       if (e->num_value == 0)\r
+       {\r
+               // 項目が 1 つも存在していない VALUE は追加できない\r
+               FreeElement(e);\r
+               return false;\r
+       }\r
+\r
+       // 追加\r
+       Add(p->elements, e);\r
+       return true;\r
+}\r
+\r
+// PACK オブジェクトの解放\r
+void FreePack(PACK *p)\r
+{\r
+       UINT i;\r
+       ELEMENT **elements;\r
+       // 引数チェック\r
+       if (p == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       elements = ToArray(p->elements);\r
+       for (i = 0;i < LIST_NUM(p->elements);i++)\r
+       {\r
+               FreeElement(elements[i]);\r
+       }\r
+       Free(elements);\r
+\r
+       ReleaseList(p->elements);\r
+       Free(p);\r
+}\r
+\r
+// PACK オブジェクトの作成\r
+PACK *NewPack()\r
+{\r
+       PACK *p;\r
+\r
+       // メモリ確保\r
+       p = MallocEx(sizeof(PACK), true);\r
+\r
+       // リスト作成\r
+       p->elements = NewListFast(ComparePackName);\r
+\r
+       return p;\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Pack.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Pack.h
new file mode 100644 (file)
index 0000000..992f21d
--- /dev/null
@@ -0,0 +1,170 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Pack.h\r
+// Pack.c のヘッダ\r
+\r
+#ifndef        PACK_H\r
+#define        PACK_H\r
+\r
+// 定数\r
+#ifdef CPU_64\r
+\r
+#define        MAX_VALUE_SIZE                  (384 * 1024 * 1024)     // 1 つの VALUE に格納できるデータサイズ\r
+#define        MAX_VALUE_NUM                   262144  // 1 つの ELEMENT に格納できる最大 VALUE 数\r
+#define        MAX_ELEMENT_NAME_LEN    63              // ELEMENT に付けることのできる名前の長さ\r
+#define        MAX_ELEMENT_NUM                 262144  // 1 つの PACK に格納できる最大 ELEMENT 数\r
+#define        MAX_PACK_SIZE                   (512 * 1024 * 1024)     // シリアル化された PACK の最大サイズ\r
+\r
+#else  // CPU_64\r
+\r
+#define        MAX_VALUE_SIZE                  (96 * 1024 * 1024)      // 1 つの VALUE に格納できるデータサイズ\r
+#define        MAX_VALUE_NUM                   65536   // 1 つの ELEMENT に格納できる最大 VALUE 数\r
+#define        MAX_ELEMENT_NAME_LEN    63              // ELEMENT に付けることのできる名前の長さ\r
+#define        MAX_ELEMENT_NUM                 131072  // 1 つの PACK に格納できる最大 ELEMENT 数\r
+#define        MAX_PACK_SIZE                   (128 * 1024 * 1024)     // シリアル化された PACK の最大サイズ\r
+\r
+#endif // CPU_64\r
+\r
+// VALUE の種類\r
+#define        VALUE_INT                       0               // 整数型\r
+#define        VALUE_DATA                      1               // データ型\r
+#define        VALUE_STR                       2               // ANSI 文字列型\r
+#define        VALUE_UNISTR            3               // Unicode 文字列型\r
+#define        VALUE_INT64                     4               // 64 bit 整数型\r
+\r
+// VALUE オブジェクト\r
+struct VALUE\r
+{\r
+       UINT Size;                              // サイズ\r
+       UINT IntValue;                  // 整数値\r
+       void *Data;                             // データ\r
+       char *Str;                              // ANSI 文字列\r
+       wchar_t *UniStr;                // Unicode 文字列\r
+       UINT64 Int64Value;              // 64 bit 整数型\r
+};\r
+\r
+// ELEMENT オブジェクト\r
+struct ELEMENT\r
+{\r
+       char name[MAX_ELEMENT_NAME_LEN + 1];    // 要素名\r
+       UINT num_value;                 // 値の数 (>=1)\r
+       UINT type;                              // 型\r
+       VALUE **values;                 // 値へのポインタのリスト\r
+};\r
+\r
+// PACK オブジェクト\r
+struct PACK\r
+{\r
+       LIST *elements;                 // 要素リスト\r
+};\r
+\r
+\r
+// 関数プロトタイプ\r
+PACK *NewPack();\r
+bool AddElement(PACK *p, ELEMENT *e);\r
+void DelElement(PACK *p, char *name);\r
+ELEMENT *GetElement(PACK *p, char *name, UINT type);\r
+void FreePack(PACK *p);\r
+ELEMENT *NewElement(char *name, UINT type, UINT num_value, VALUE **values);\r
+VALUE *NewIntValue(UINT i);\r
+VALUE *NewDataValue(void *data, UINT size);\r
+VALUE *NewStrValue(char *str);\r
+VALUE *NewUniStrValue(wchar_t *str);\r
+void FreeValue(VALUE *v, UINT type);\r
+int ComparePackName(void *p1, void *p2);\r
+void FreeElement(ELEMENT *e);\r
+UINT GetValueNum(ELEMENT *e);\r
+UINT GetIntValue(ELEMENT *e, UINT index);\r
+UINT64 GetInt64Value(ELEMENT *e, UINT index);\r
+char *GetStrValue(ELEMENT *e, UINT index);\r
+wchar_t *GetUniStrValue(ELEMENT *e, UINT index);\r
+UINT GetDataValueSize(ELEMENT *e, UINT index);\r
+void *GetDataValue(ELEMENT *e, UINT index);\r
+BUF *PackToBuf(PACK *p);\r
+void WritePack(BUF *b, PACK *p);\r
+void WriteElement(BUF *b, ELEMENT *e);\r
+void WriteValue(BUF *b, VALUE *v, UINT type);\r
+PACK *BufToPack(BUF *b);\r
+bool ReadPack(BUF *b, PACK *p);\r
+ELEMENT *ReadElement(BUF *b);\r
+VALUE *ReadValue(BUF *b, UINT type);\r
+void Bit160ToStr(char *str, UCHAR *data);\r
+void Bit128ToStr(char *str, UCHAR *data);\r
+VALUE *NewInt64Value(UINT64 i);\r
+\r
+#endif // PACK_H\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Secure.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Secure.c
new file mode 100644 (file)
index 0000000..91800a2
--- /dev/null
@@ -0,0 +1,2188 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Secure.c\r
+// セキュリティトークン管理モジュール\r
+\r
+#define        SECURE_C\r
+#define        ENCRYPT_C\r
+\r
+#ifdef WIN32\r
+#include <windows.h>\r
+#endif // WIN32\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <openssl/ssl.h>\r
+#include <openssl/err.h>\r
+#include <openssl/rand.h>\r
+#include <openssl/engine.h>\r
+#include <openssl/bio.h>\r
+#include <openssl/x509.h>\r
+#include <openssl/pkcs7.h>\r
+#include <openssl/pkcs12.h>\r
+#include <openssl/rc4.h>\r
+#include <openssl/md5.h>\r
+#include <openssl/sha.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Mayaqua/cryptoki.h>\r
+\r
+\r
+#define        MAX_OBJ                         1024            // ハードウェア内の最大オブジェクト数 (想定)\r
+\r
+#define        A_SIZE(a, i)            (a[(i)].ulValueLen)\r
+#define        A_SET(a, i, value, size)        (a[i].pValue = value;a[i].ulValueLen = size;)\r
+\r
+#ifdef OS_WIN32\r
+// Win32 用コード\r
+\r
+// Win32 用 DLL 読み込み\r
+HINSTANCE Win32SecureLoadLibraryEx(char *dllname, DWORD flags)\r
+{\r
+       char tmp1[MAX_PATH];\r
+       char tmp2[MAX_PATH];\r
+       char tmp3[MAX_PATH];\r
+       HINSTANCE h;\r
+       // 引数チェック\r
+       if (dllname == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       Format(tmp1, sizeof(tmp1), "%s\\%s", MsGetSystem32Dir(), dllname);\r
+       Format(tmp2, sizeof(tmp2), "%s\\JPKI\\%s", MsGetProgramFilesDir(), dllname);\r
+       Format(tmp3, sizeof(tmp3), "%s\\LGWAN\\%s", MsGetProgramFilesDir(), dllname);\r
+\r
+       h = LoadLibraryEx(dllname, NULL, flags);\r
+       if (h != NULL)\r
+       {\r
+               return h;\r
+       }\r
+\r
+       h = LoadLibraryEx(tmp1, NULL, flags);\r
+       if (h != NULL)\r
+       {\r
+               return h;\r
+       }\r
+\r
+       h = LoadLibraryEx(tmp2, NULL, flags);\r
+       if (h != NULL)\r
+       {\r
+               return h;\r
+       }\r
+\r
+       h = LoadLibraryEx(tmp3, NULL, flags);\r
+       if (h != NULL)\r
+       {\r
+               return h;\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// 指定したデバイスがインストールされているか調査\r
+bool Win32IsDeviceSupported(SECURE_DEVICE *dev)\r
+{\r
+       HINSTANCE hInst;\r
+       // 引数チェック\r
+       if (dev == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // DLL が読み込み可能かチェック\r
+       hInst = Win32SecureLoadLibraryEx(dev->ModuleName, DONT_RESOLVE_DLL_REFERENCES);\r
+       if (hInst == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       FreeLibrary(hInst);\r
+\r
+       return true;\r
+}\r
+\r
+// デバイスモジュールの読み込み\r
+bool Win32LoadSecModule(SECURE *sec)\r
+{\r
+       SEC_DATA_WIN32 *w;\r
+       HINSTANCE hInst;\r
+       CK_FUNCTION_LIST_PTR api = NULL;\r
+       CK_RV (*get_function_list)(CK_FUNCTION_LIST_PTR_PTR);\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (sec->Dev->Id == 9)\r
+       {\r
+               char username[MAX_SIZE];\r
+               DWORD size;\r
+               // 住基ネットのデバイスドライバでは、Software\JPKI レジストリキーの内容を\r
+               // SYSTEM の HKLU でも持っていなければならないので、もし持っていない場合は\r
+               // 別のユーザーの値からコピーする\r
+//             if (MsRegIsValue(REG_CURRENT_USER, "Software\\JPKI", "Name") == false ||\r
+//                     MsRegIsValue(REG_CURRENT_USER, "Software\\JPKI", "RWType") == false)\r
+               size = sizeof(username);\r
+               GetUserName(username, &size);\r
+               if (StrCmpi(username, "System") == 0)\r
+               {\r
+                       TOKEN_LIST *t = MsRegEnumKey(REG_USERS, NULL);\r
+\r
+                       if (t != NULL)\r
+                       {\r
+                               UINT i;\r
+\r
+                               for (i = 0;i < t->NumTokens;i++)\r
+                               {\r
+                                       char tmp[MAX_PATH];\r
+\r
+                                       if (StrCmpi(t->Token[i], ".DEFAULT") != 0 && StrCmpi(t->Token[i], "S-1-5-18") != 0)\r
+                                       {\r
+                                               Format(tmp, sizeof(tmp), "%s\\Software\\JPKI", t->Token[i]);\r
+\r
+                                               if (MsRegIsValue(REG_USERS, tmp, "Name") && MsRegIsValue(REG_USERS, tmp, "RWType"))\r
+                                               {\r
+                                                       char *name = MsRegReadStr(REG_USERS, tmp, "Name");\r
+                                                       char *port = MsRegReadStr(REG_USERS, tmp, "Port");\r
+                                                       UINT type = MsRegReadInt(REG_USERS, tmp, "RWType");\r
+\r
+                                                       MsRegWriteStr(REG_CURRENT_USER, "Software\\JPKI", "Name", name);\r
+                                                       MsRegWriteStr(REG_CURRENT_USER, "Software\\JPKI", "Port", port);\r
+                                                       MsRegWriteInt(REG_CURRENT_USER, "Software\\JPKI", "RWType", type);\r
+\r
+                                                       Free(name);\r
+                                                       Free(port);\r
+                                                       break;\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               FreeToken(t);\r
+                       }\r
+               }\r
+       }\r
+\r
+       // ライブラリのロード\r
+       hInst = Win32SecureLoadLibraryEx(sec->Dev->ModuleName, 0);\r
+       if (hInst == NULL)\r
+       {\r
+               // 失敗\r
+               return false;\r
+       }\r
+\r
+       // API の取得\r
+       get_function_list = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR))\r
+               GetProcAddress(hInst, "C_GetFunctionList");\r
+\r
+       if (get_function_list == NULL)\r
+       {\r
+               // 失敗\r
+               FreeLibrary(hInst);\r
+               return false;\r
+       }\r
+\r
+       get_function_list(&api);\r
+       if (api == NULL)\r
+       {\r
+               // 失敗\r
+               FreeLibrary(hInst);\r
+               return false;\r
+       }\r
+\r
+       sec->Data = ZeroMalloc(sizeof(SEC_DATA_WIN32));\r
+       w = sec->Data;\r
+\r
+       w->hInst = hInst;\r
+       sec->Api = api;\r
+\r
+       return true;\r
+}\r
+\r
+// デバイスモジュールのアンロード\r
+void Win32FreeSecModule(SECURE *sec)\r
+{\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (sec->Data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // アンロード\r
+       FreeLibrary(sec->Data->hInst);\r
+       Free(sec->Data);\r
+\r
+       sec->Data = NULL;\r
+}\r
+\r
+#endif // OS_WIN32\r
+\r
+\r
+// 指定されたデバイスが JPKI かどうか\r
+bool IsJPKI(bool id)\r
+{\r
+       if (id == 9 || id == 13)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// セキュアデバイスの秘密鍵を名前を指定して署名\r
+bool SignSec(SECURE *sec, char *name, void *dst, void *src, UINT size)\r
+{\r
+       SEC_OBJ *obj;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (name == NULL || dst == NULL || src == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+\r
+       obj = FindSecObject(sec, name, SEC_K);\r
+       if (obj == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       ret = SignSecByObject(sec, obj, dst, src, size);\r
+\r
+       FreeSecObject(obj);\r
+\r
+       return ret;\r
+}\r
+\r
+// セキュアデバイスの秘密鍵で署名\r
+bool SignSecByObject(SECURE *sec, SEC_OBJ *obj, void *dst, void *src, UINT size)\r
+{\r
+       CK_MECHANISM mechanism = {CKM_RSA_PKCS, NULL, 0};\r
+       UINT ret;\r
+       UCHAR hash[SIGN_HASH_SIZE];\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (obj == NULL || dst == NULL || src == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return false;\r
+       }\r
+       if (sec->LoginFlag == false && obj->Private)\r
+       {\r
+               sec->Error = SEC_ERROR_NOT_LOGIN;\r
+               return false;\r
+       }\r
+       if (obj->Type != SEC_K)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+\r
+       // ハッシュ\r
+       HashForSign(hash, sizeof(hash), src, size);\r
+\r
+       // 署名初期化\r
+       ret = sec->Api->C_SignInit(sec->SessionId, &mechanism, obj->Object);\r
+       if (ret != CKR_OK)\r
+       {\r
+               // 失敗\r
+               sec->Error = SEC_ERROR_HARDWARE_ERROR;\r
+               Debug("C_SignInit Error: 0x%x\n", ret);\r
+               return false;\r
+       }\r
+\r
+       // 署名実行\r
+       size = 128;\r
+       ret = sec->Api->C_Sign(sec->SessionId, hash, sizeof(hash), dst, &size);\r
+       if (ret != CKR_OK || size != 128)\r
+       {\r
+               // 失敗\r
+               sec->Error = SEC_ERROR_HARDWARE_ERROR;\r
+               Debug("C_Sign Error: 0x%x\n", ret);\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// PIN コードの変更\r
+bool ChangePin(SECURE *sec, char *old_pin, char *new_pin)\r
+{\r
+       // 引数チェック\r
+       if (sec == NULL || old_pin == NULL || new_pin == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return false;\r
+       }\r
+       if (sec->LoginFlag == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NOT_LOGIN;\r
+               return false;\r
+       }\r
+       if (sec->IsReadOnly)\r
+       {\r
+               sec->Error = SEC_ERROR_OPEN_SESSION;\r
+               return false;\r
+       }\r
+\r
+       // PIN 変更\r
+       if (sec->Api->C_SetPIN(sec->SessionId, old_pin, StrLen(old_pin),\r
+               new_pin, StrLen(new_pin)) != CKR_OK)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 秘密鍵オブジェクトの書き込み\r
+bool WriteSecKey(SECURE *sec, bool private_obj, char *name, K *k)\r
+{\r
+       UINT key_type = CKK_RSA;\r
+       CK_BBOOL b_true = true, b_false = false, b_private_obj = private_obj;\r
+       UINT obj_class = CKO_PRIVATE_KEY;\r
+       UINT object;\r
+       UINT ret;\r
+       BUF *b;\r
+       RSA *rsa;\r
+       UCHAR modules[MAX_SIZE], pub[MAX_SIZE], pri[MAX_SIZE], prime1[MAX_SIZE], prime2[MAX_SIZE];\r
+       CK_ATTRIBUTE a[] =\r
+       {\r
+               {CKA_MODULUS,                   modules,                0},             // 0\r
+               {CKA_PUBLIC_EXPONENT,   pub,                    0},             // 1\r
+               {CKA_PRIVATE_EXPONENT,  pri,                    0},             // 2\r
+               {CKA_PRIME_1,                   prime1,                 0},             // 3\r
+               {CKA_PRIME_2,                   prime2,                 0},             // 4\r
+               {CKA_CLASS,                             &obj_class,             sizeof(obj_class)},\r
+               {CKA_TOKEN,                             &b_true,                sizeof(b_true)},\r
+               {CKA_PRIVATE,                   &b_private_obj, sizeof(b_private_obj)},\r
+               {CKA_LABEL,                             name,                   StrLen(name)},\r
+               {CKA_KEY_TYPE,                  &key_type,              sizeof(key_type)},\r
+               {CKA_DERIVE,                    &b_false,               sizeof(b_false)},\r
+               {CKA_SUBJECT,                   name,                   StrLen(name)},\r
+               {CKA_SENSITIVE,                 &b_true,                sizeof(b_true)},\r
+               {CKA_DECRYPT,                   &b_true,                sizeof(b_true)},\r
+               {CKA_SIGN,                              &b_true,                sizeof(b_true)},\r
+               {CKA_SIGN_RECOVER,              &b_false,               sizeof(b_false)},\r
+               {CKA_EXTRACTABLE,               &b_false,               sizeof(b_false)},\r
+               {CKA_MODIFIABLE,                &b_false,               sizeof(b_false)},\r
+       };\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (name == NULL || k == NULL || k->private_key == false)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return false;\r
+       }\r
+       if (sec->LoginFlag == false && private_obj)\r
+       {\r
+               sec->Error = SEC_ERROR_NOT_LOGIN;\r
+               return false;\r
+       }\r
+\r
+       // 数値データ生成\r
+       rsa = k->pkey->pkey.rsa;\r
+       if (rsa == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+       b = BigNumToBuf(rsa->n);\r
+       ReadBuf(b, modules, sizeof(modules));\r
+       A_SIZE(a, 0) = b->Size;\r
+       FreeBuf(b);\r
+\r
+       b = BigNumToBuf(rsa->e);\r
+       ReadBuf(b, pub, sizeof(pub));\r
+       A_SIZE(a, 1) = b->Size;\r
+       FreeBuf(b);\r
+\r
+       b = BigNumToBuf(rsa->d);\r
+       ReadBuf(b, pri, sizeof(pri));\r
+       A_SIZE(a, 2) = b->Size;\r
+       FreeBuf(b);\r
+\r
+       b = BigNumToBuf(rsa->p);\r
+       ReadBuf(b, prime1, sizeof(prime1));\r
+       A_SIZE(a, 3) = b->Size;\r
+       FreeBuf(b);\r
+\r
+       b = BigNumToBuf(rsa->q);\r
+       ReadBuf(b, prime2, sizeof(prime2));\r
+       A_SIZE(a, 4) = b->Size;\r
+       FreeBuf(b);\r
+\r
+       // 古い鍵があれば削除\r
+       if (CheckSecObject(sec, name, SEC_K))\r
+       {\r
+               DeleteSecKey(sec, name);\r
+       }\r
+\r
+       // 作成\r
+       if ((ret = sec->Api->C_CreateObject(sec->SessionId, a, sizeof(a) / sizeof(a[0]), &object)) != CKR_OK)\r
+       {\r
+               // 失敗\r
+               sec->Error = SEC_ERROR_HARDWARE_ERROR;\r
+               Debug("ret: 0x%x\n", ret);\r
+               return false;\r
+       }\r
+\r
+       // キャッシュ消去\r
+       EraseEnumSecObjectCache(sec);\r
+\r
+       return true;\r
+}\r
+\r
+// 証明書オブジェクトを名前を指定して読み込み\r
+X *ReadSecCert(SECURE *sec, char *name)\r
+{\r
+       SEC_OBJ *obj;\r
+       X *x;\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return false;\r
+       }\r
+\r
+       // 検索\r
+       obj = FindSecObject(sec, name, SEC_X);\r
+       if (obj == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 取得\r
+       x = ReadSecCertFromObject(sec, obj);\r
+\r
+       FreeSecObject(obj);\r
+\r
+       return x;\r
+}\r
+\r
+// 証明書オブジェクトの読み込み\r
+X *ReadSecCertFromObject(SECURE *sec, SEC_OBJ *obj)\r
+{\r
+       UINT size;\r
+       X *x;\r
+       UCHAR value[4096];\r
+       BUF *b;\r
+       CK_ATTRIBUTE get[] =\r
+       {\r
+               {CKA_VALUE,             value,          sizeof(value)},\r
+       };\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return false;\r
+       }\r
+       if (sec->LoginFlag == false && obj->Private)\r
+       {\r
+               sec->Error = SEC_ERROR_NOT_LOGIN;\r
+               return false;\r
+       }\r
+       if (obj->Type != SEC_X)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+\r
+       // 取得\r
+       if (sec->Api->C_GetAttributeValue(\r
+               sec->SessionId, obj->Object, get, sizeof(get) / sizeof(get[0])) != CKR_OK)\r
+       {\r
+               sec->Error = SEC_ERROR_HARDWARE_ERROR;\r
+               return 0;\r
+       }\r
+\r
+       size = A_SIZE(get, 0);\r
+\r
+       // 変換\r
+       b = NewBuf();\r
+       WriteBuf(b, value, size);\r
+       SeekBuf(b, 0, 0);\r
+\r
+       x = BufToX(b, false);\r
+       if (x == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_INVALID_CERT;\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return x;\r
+}\r
+\r
+// 証明書オブジェクトの書き込み\r
+bool WriteSecCert(SECURE *sec, bool private_obj, char *name, X *x)\r
+{\r
+       UINT obj_class = CKO_CERTIFICATE;\r
+       CK_BBOOL b_true = true, b_false = false, b_private_obj = private_obj;\r
+       UINT cert_type = CKC_X_509;\r
+       CK_DATE start_date, end_date;\r
+       UCHAR subject[MAX_SIZE];\r
+       UCHAR issuer[MAX_SIZE];\r
+       wchar_t w_subject[MAX_SIZE];\r
+       wchar_t w_issuer[MAX_SIZE];\r
+       UCHAR serial_number[MAX_SIZE];\r
+       UCHAR value[4096];\r
+       UINT ret;\r
+       BUF *b;\r
+       UINT object;\r
+       CK_ATTRIBUTE a[] =\r
+       {\r
+               {CKA_SUBJECT,                   subject,                0},                     // 0\r
+               {CKA_ISSUER,                    issuer,                 0},                     // 1\r
+               {CKA_SERIAL_NUMBER,             serial_number,  0},                     // 2\r
+               {CKA_VALUE,                             value,                  0},                     // 3\r
+               {CKA_CLASS,                             &obj_class,             sizeof(obj_class)},\r
+               {CKA_TOKEN,                             &b_true,                sizeof(b_true)},\r
+               {CKA_PRIVATE,                   &b_private_obj, sizeof(b_private_obj)},\r
+               {CKA_LABEL,                             name,                   StrLen(name)},\r
+               {CKA_CERTIFICATE_TYPE,  &cert_type,             sizeof(cert_type)},\r
+#if    0               // 失敗するトークンがあるのでこれは使わない\r
+               {CKA_START_DATE,                &start_date,    sizeof(start_date)},\r
+               {CKA_END_DATE,                  &end_date,              sizeof(end_date)},\r
+#endif\r
+       };\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (name == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return false;\r
+       }\r
+       if (sec->LoginFlag == false && private_obj)\r
+       {\r
+               sec->Error = SEC_ERROR_NOT_LOGIN;\r
+               return false;\r
+       }\r
+\r
+       // 証明書をバッファにコピー\r
+       b = XToBuf(x, false);\r
+       if (b == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_INVALID_CERT;\r
+               return false;\r
+       }\r
+       if (b->Size > sizeof(value))\r
+       {\r
+               // サイズが大きすぎる\r
+               FreeBuf(b);\r
+               sec->Error = SEC_ERROR_DATA_TOO_BIG;\r
+               return false;\r
+       }\r
+       Copy(value, b->Buf, b->Size);\r
+       A_SIZE(a, 3) = b->Size;\r
+       FreeBuf(b);\r
+\r
+       // Subject と Issuer を UTF-8 にエンコードして格納\r
+       GetPrintNameFromName(w_subject, sizeof(w_subject), x->subject_name);\r
+       UniToUtf8(subject, sizeof(subject), w_subject);\r
+       A_SIZE(a, 0) = StrLen(subject);\r
+       if (x->root_cert == false)\r
+       {\r
+               GetPrintNameFromName(w_issuer, sizeof(w_issuer), x->issuer_name);\r
+               UniToUtf8(issuer, sizeof(issuer), w_issuer);\r
+               A_SIZE(a, 1) = StrLen(issuer);\r
+       }\r
+\r
+       // シリアル番号をコピー\r
+       Copy(serial_number, x->serial->data, MIN(x->serial->size, sizeof(serial_number)));\r
+       A_SIZE(a, 2) = MIN(x->serial->size, sizeof(serial_number));\r
+\r
+       // 有効期限情報\r
+       UINT64ToCkDate(&start_date, SystemToLocal64(x->notBefore));\r
+       UINT64ToCkDate(&end_date, SystemToLocal64(x->notAfter));\r
+\r
+       // 同一の名前のオブジェクトがあれば削除\r
+       if (CheckSecObject(sec, name, SEC_X))\r
+       {\r
+               DeleteSecCert(sec, name);\r
+       }\r
+\r
+       // 作成\r
+       if ((ret = sec->Api->C_CreateObject(sec->SessionId, a, sizeof(a) / sizeof(a[0]), &object)) != CKR_OK)\r
+       {\r
+               // 失敗\r
+               sec->Error = SEC_ERROR_HARDWARE_ERROR;\r
+               Debug("Error: 0x%02x\n", ret);\r
+               return false;\r
+       }\r
+\r
+       // キャッシュ消去\r
+       EraseEnumSecObjectCache(sec);\r
+\r
+       return true;\r
+}\r
+\r
+// 秘密鍵オブジェクトの削除\r
+bool DeleteSecKey(SECURE *sec, char *name)\r
+{\r
+       return DeleteSecObjectByName(sec, name, SEC_K);\r
+}\r
+\r
+// 証明書オブジェクトの削除\r
+bool DeleteSecCert(SECURE *sec, char *name)\r
+{\r
+       return DeleteSecObjectByName(sec, name, SEC_X);\r
+}\r
+\r
+// CK_DATE を 64 bit 時刻に変換\r
+UINT64 CkDateToUINT64(struct CK_DATE *ck_date)\r
+{\r
+       SYSTEMTIME st;\r
+       char year[32], month[32], day[32];\r
+       // 引数チェック\r
+       if (ck_date == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Zero(year, sizeof(year));\r
+       Zero(month, sizeof(month));\r
+       Zero(day, sizeof(day));\r
+\r
+       Copy(year, ck_date->year, 4);\r
+       Copy(month, ck_date->month, 2);\r
+       Copy(day, ck_date->day, 2);\r
+\r
+       st.wYear = ToInt(year);\r
+       st.wMonth = ToInt(month);\r
+       st.wDay = ToInt(day);\r
+\r
+       return SystemToUINT64(&st);\r
+}\r
+\r
+// 64 bit 時刻を CK_DATE に変換\r
+void UINT64ToCkDate(void *p_ck_date, UINT64 time64)\r
+{\r
+       SYSTEMTIME st;\r
+       char year[32], month[32], day[32];\r
+       struct CK_DATE *ck_date = (CK_DATE *)p_ck_date;\r
+       // 引数チェック\r
+       if (ck_date == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UINT64ToSystem(&st, time64);\r
+\r
+       Format(year, sizeof(year), "%04u", st.wYear);\r
+       Format(month, sizeof(month), "%04u", st.wMonth);\r
+       Format(day, sizeof(day), "%04u", st.wDay);\r
+\r
+       Zero(ck_date, sizeof(CK_DATE));\r
+\r
+       Copy(ck_date->year, year, 4);\r
+       Copy(ck_date->month, month, 2);\r
+       Copy(ck_date->day, day, 2);\r
+}\r
+\r
+// オブジェクトを名前で指定して削除\r
+bool DeleteSecObjectByName(SECURE *sec, char *name, UINT type)\r
+{\r
+       bool ret;\r
+       SEC_OBJ *obj;\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (name == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return false;\r
+       }\r
+\r
+       // オブジェクト取得\r
+       obj = FindSecObject(sec, name, type);\r
+       if (obj == NULL)\r
+       {\r
+               // 失敗\r
+               return false;\r
+       }\r
+\r
+       // オブジェクト削除\r
+       ret = DeleteSecObject(sec, obj);\r
+\r
+       // メモリ解放\r
+       FreeSecObject(obj);\r
+\r
+       return ret;\r
+}\r
+\r
+// データの削除\r
+bool DeleteSecData(SECURE *sec, char *name)\r
+{\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (name == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+\r
+       return DeleteSecObjectByName(sec, name, SEC_DATA);\r
+}\r
+\r
+// セキュアオブジェクトの削除\r
+bool DeleteSecObject(SECURE *sec, SEC_OBJ *obj)\r
+{\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (obj == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return false;\r
+       }\r
+       if (sec->LoginFlag == false && obj->Private)\r
+       {\r
+               sec->Error = SEC_ERROR_NOT_LOGIN;\r
+               return false;\r
+       }\r
+\r
+       // オブジェクト消去\r
+       if (sec->Api->C_DestroyObject(sec->SessionId, obj->Object) != CKR_OK)\r
+       {\r
+               sec->Error = SEC_ERROR_HARDWARE_ERROR;\r
+               return false;\r
+       }\r
+\r
+       // キャッシュ消去\r
+       DeleteSecObjFromEnumCache(sec, obj->Name, obj->Type);\r
+\r
+       return true;\r
+}\r
+\r
+// キャッシュから指定した名前のオブジェクトを削除する\r
+void DeleteSecObjFromEnumCache(SECURE *sec, char *name, UINT type)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (sec == NULL || name == NULL || sec->EnumCache == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(sec->EnumCache);i++)\r
+       {\r
+               SEC_OBJ *obj = LIST_DATA(sec->EnumCache, i);\r
+\r
+               if (StrCmpi(obj->Name, name) == 0)\r
+               {\r
+                       if (obj->Type == type)\r
+                       {\r
+                               Delete(sec->EnumCache, obj);\r
+                               FreeSecObject(obj);\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// セキュアオブジェクトを名前で検索して読み込む\r
+int ReadSecData(SECURE *sec, char *name, void *data, UINT size)\r
+{\r
+       UINT ret = 0;\r
+       SEC_OBJ *obj;\r
+       // 引数チェック\r
+       if (sec == NULL || name == NULL || data == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return 0;\r
+       }\r
+\r
+       // 読み込み\r
+       obj = FindSecObject(sec, name, SEC_DATA);\r
+       if (obj == NULL)\r
+       {\r
+               // 見つからない\r
+               return 0;\r
+       }\r
+\r
+       // 読み込む\r
+       ret = ReadSecDataFromObject(sec, obj, data, size);\r
+\r
+       FreeSecObject(obj);\r
+\r
+       return ret;\r
+}\r
+\r
+// キャッシュ消去\r
+void EraseEnumSecObjectCache(SECURE *sec)\r
+{\r
+       // 引数チェック\r
+       if (sec == NULL || sec->EnumCache == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeEnumSecObject(sec->EnumCache);\r
+       sec->EnumCache = NULL;\r
+}\r
+\r
+// セキュアオブジェクトの存在をチェックする\r
+bool CheckSecObject(SECURE *sec, char *name, UINT type)\r
+{\r
+       SEC_OBJ *obj;\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (name == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return 0;\r
+       }\r
+\r
+       obj = FindSecObject(sec, name, type);\r
+\r
+       if (obj == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               FreeSecObject(obj);\r
+               return true;\r
+       }\r
+}\r
+\r
+// セキュアオブジェクト構造体のクローンの作成\r
+SEC_OBJ *CloneSecObject(SEC_OBJ *obj)\r
+{\r
+       SEC_OBJ *ret;\r
+       // 引数チェック\r
+       if (obj == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(SEC_OBJ));\r
+       ret->Name = CopyStr(obj->Name);\r
+       ret->Object = obj->Object;\r
+       ret->Private = obj->Private;\r
+       ret->Type = obj->Type;\r
+\r
+       return ret;\r
+}\r
+\r
+// セキュアオブジェクトを名前で検索して取得する\r
+SEC_OBJ *FindSecObject(SECURE *sec, char *name, UINT type)\r
+{\r
+       LIST *o;\r
+       UINT i;\r
+       SEC_OBJ *ret = NULL;\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (name == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return NULL;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return 0;\r
+       }\r
+\r
+       // 列挙\r
+       o = EnumSecObject(sec);\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               SEC_OBJ *obj = LIST_DATA(o, i);\r
+\r
+               if (obj->Type == type || type == INFINITE)\r
+               {\r
+                       if (StrCmpi(obj->Name, name) == 0)\r
+                       {\r
+                               ret = CloneSecObject(obj);\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       FreeEnumSecObject(o);\r
+\r
+       if (ret == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_OBJ_NOT_FOUND;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// セキュアオブジェクトの読み込み\r
+int ReadSecDataFromObject(SECURE *sec, SEC_OBJ *obj, void *data, UINT size)\r
+{\r
+       UCHAR buf[MAX_SEC_DATA_SIZE];\r
+       UINT i;\r
+       CK_ATTRIBUTE get[] =\r
+       {\r
+               {CKA_VALUE,      buf,   sizeof(buf)},\r
+       };\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (obj == NULL || data == NULL || size == 0)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return 0;\r
+       }\r
+       if (obj->Type != SEC_DATA)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return 0;\r
+       }\r
+       if (sec->LoginFlag == false && obj->Private)\r
+       {\r
+               sec->Error = SEC_ERROR_NOT_LOGIN;\r
+               return 0;\r
+       }\r
+\r
+       // 取得\r
+       if (sec->Api->C_GetAttributeValue(\r
+               sec->SessionId, obj->Object, get, sizeof(get) / sizeof(get[0])) != CKR_OK)\r
+       {\r
+               sec->Error = SEC_ERROR_HARDWARE_ERROR;\r
+               return 0;\r
+       }\r
+\r
+       // 結果の返却\r
+       i = get[0].ulValueLen;\r
+       if (i > MAX_SEC_DATA_SIZE || i > size)\r
+       {\r
+               // データが大きすぎる\r
+               sec->Error = SEC_ERROR_DATA_TOO_BIG;\r
+               return 0;\r
+       }\r
+\r
+       // メモリコピー\r
+       Copy(data, buf, i);\r
+\r
+       return i;\r
+}\r
+\r
+// セキュアオブジェクトの列挙結果の解放\r
+void FreeEnumSecObject(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               SEC_OBJ *obj = LIST_DATA(o, i);\r
+\r
+               FreeSecObject(obj);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// セキュアオブジェクトの解放\r
+void FreeSecObject(SEC_OBJ *obj)\r
+{\r
+       // 引数チェック\r
+       if (obj == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(obj->Name);\r
+       Free(obj);\r
+}\r
+\r
+// セキュアオブジェクト列挙結果のクローン\r
+LIST *CloneEnumSecObject(LIST *o)\r
+{\r
+       LIST *ret;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = NewListFast(NULL);\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               SEC_OBJ *obj = LIST_DATA(o, i);\r
+\r
+               Add(ret, CloneSecObject(obj));\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// セキュアオブジェクトの列挙\r
+LIST *EnumSecObject(SECURE *sec)\r
+{\r
+       CK_BBOOL b_true = true, b_false = false;\r
+       UINT objects[MAX_OBJ];\r
+       UINT i;\r
+       UINT ret;\r
+       LIST *o;\r
+       CK_ATTRIBUTE dummy[1];\r
+       CK_ATTRIBUTE a[] =\r
+       {\r
+               {CKA_TOKEN,             &b_true,                sizeof(b_true)},\r
+       };\r
+       UINT num_objects = MAX_OBJ;\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return NULL;\r
+       }\r
+\r
+       Zero(dummy, sizeof(dummy));\r
+\r
+       // キャッシュがあればキャッシュを返す\r
+       if (sec->EnumCache != NULL)\r
+       {\r
+               return CloneEnumSecObject(sec->EnumCache);\r
+       }\r
+\r
+       // 列挙\r
+//     if (sec->Dev->Id != 2 && sec->Dev->Id != 14)\r
+//     {\r
+               // 通常のトークン\r
+               ret = sec->Api->C_FindObjectsInit(sec->SessionId, a, sizeof(a) / sizeof(a[0]));\r
+//     }\r
+//     else\r
+//     {\r
+               // ePass と SafeSign\r
+//             ret = sec->Api->C_FindObjectsInit(sec->SessionId, dummy, 0);\r
+//     }\r
+\r
+       if (ret != CKR_OK)\r
+       {\r
+               sec->Error = SEC_ERROR_HARDWARE_ERROR;\r
+               return NULL;\r
+       }\r
+       if (sec->Api->C_FindObjects(sec->SessionId, objects, sizeof(objects) / sizeof(objects[0]), &num_objects) != CKR_OK)\r
+       {\r
+               sec->Api->C_FindObjectsFinal(sec->SessionId);\r
+               sec->Error = SEC_ERROR_HARDWARE_ERROR;\r
+               return NULL;\r
+       }\r
+       sec->Api->C_FindObjectsFinal(sec->SessionId);\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       for (i = 0;i < num_objects;i++)\r
+       {\r
+               char label[MAX_SIZE];\r
+               UINT obj_class = 0;\r
+               bool priv = false;\r
+               CK_ATTRIBUTE get[] =\r
+               {\r
+                       {CKA_LABEL, label, sizeof(label) - 1},\r
+                       {CKA_CLASS, &obj_class, sizeof(obj_class)},\r
+                       {CKA_PRIVATE, &priv, sizeof(priv)},\r
+               };\r
+\r
+               Zero(label, sizeof(label));\r
+\r
+               if (sec->Api->C_GetAttributeValue(sec->SessionId, objects[i],\r
+                       get, sizeof(get) / sizeof(get[0])) == CKR_OK)\r
+               {\r
+                       UINT type = INFINITE;\r
+\r
+                       switch (obj_class)\r
+                       {\r
+                       case CKO_DATA:\r
+                               // データ\r
+                               type = SEC_DATA;\r
+                               break;\r
+\r
+                       case CKO_CERTIFICATE:\r
+                               // 証明書\r
+                               type = SEC_X;\r
+                               break;\r
+\r
+                       case CKO_PUBLIC_KEY:\r
+                               // 公開鍵\r
+                               type = SEC_P;\r
+                               break;\r
+\r
+                       case CKO_PRIVATE_KEY:\r
+                               // 秘密鍵\r
+                               type = SEC_K;\r
+                               break;\r
+                       }\r
+\r
+                       if (type != INFINITE)\r
+                       {\r
+                               SEC_OBJ *obj = ZeroMalloc(sizeof(SEC_OBJ));\r
+\r
+                               obj->Type = type;\r
+                               obj->Object = objects[i];\r
+                               obj->Private = (priv == false) ? false : true;\r
+                               EnSafeStr(label, '?');\r
+                               TruncateCharFromStr(label, '?');\r
+                               obj->Name = CopyStr(label);\r
+\r
+                               Add(o, obj);\r
+                       }\r
+               }\r
+       }\r
+\r
+       // キャッシュ作成\r
+       sec->EnumCache = CloneEnumSecObject(o);\r
+\r
+       return o;\r
+}\r
+\r
+// データを書き込む\r
+bool WriteSecData(SECURE *sec, bool private_obj, char *name, void *data, UINT size)\r
+{\r
+       UINT object_class = CKO_DATA;\r
+       CK_BBOOL b_true = true, b_false = false, b_private_obj = private_obj;\r
+       UINT object;\r
+       CK_ATTRIBUTE a[] =\r
+       {\r
+               {CKA_TOKEN,             &b_true,                sizeof(b_true)},\r
+               {CKA_CLASS,             &object_class,  sizeof(object_class)},\r
+               {CKA_PRIVATE,   &b_private_obj, sizeof(b_private_obj)},\r
+               {CKA_LABEL,             name,                   StrLen(name)},\r
+               {CKA_VALUE,             data,                   size},\r
+       };\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return false;\r
+       }\r
+       if (private_obj && sec->LoginFlag == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NOT_LOGIN;\r
+               return false;\r
+       }\r
+       if (name == NULL || data == NULL || size == 0)\r
+       {\r
+               sec->Error = SEC_ERROR_BAD_PARAMETER;\r
+               return false;\r
+       }\r
+       if (size > MAX_SEC_DATA_SIZE)\r
+       {\r
+               sec->Error = SEC_ERROR_DATA_TOO_BIG;\r
+               return false;\r
+       }\r
+\r
+       // 同名のオブジェクトがあれば削除\r
+       if (CheckSecObject(sec, name, SEC_DATA))\r
+       {\r
+               DeleteSecData(sec, name);\r
+       }\r
+\r
+       // オブジェクト作成\r
+       if (sec->Api->C_CreateObject(sec->SessionId, a, sizeof(a) / sizeof(a[0]), &object) != CKR_OK)\r
+       {\r
+               sec->Error = SEC_ERROR_HARDWARE_ERROR;\r
+               return false;\r
+       }\r
+\r
+       // キャッシュ消去\r
+       EraseEnumSecObjectCache(sec);\r
+\r
+       return true;\r
+}\r
+\r
+// キャッシュに新規作成したオブジェクトの情報を追加する\r
+void AddSecObjToEnumCache(SECURE *sec, char *name, UINT type, bool private_obj, UINT object)\r
+{\r
+       SEC_OBJ *obj;\r
+       // 引数チェック\r
+       if (sec == NULL || name == NULL || sec->EnumCache == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       obj = ZeroMalloc(sizeof(SEC_OBJ));\r
+       obj->Name = CopyStr(name);\r
+       obj->Object = object;\r
+       obj->Private = private_obj;\r
+       obj->Type = type;\r
+\r
+       Add(sec->EnumCache, obj);\r
+}\r
+\r
+// トークン情報を表示\r
+void PrintSecInfo(SECURE *sec)\r
+{\r
+       SEC_INFO *s;\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       s = sec->Info;\r
+       if (s == NULL)\r
+       {\r
+               Print("No Token Info.\n");\r
+               return;\r
+       }\r
+\r
+       Print(\r
+               "               Label: %S\n"\r
+               "      ManufacturerId: %S\n"\r
+               "               Model: %S\n"\r
+               "        SerialNumber: %S\n"\r
+               "          MaxSession: %u\n"\r
+               "        MaxRWSession: %u\n"\r
+               "           MinPinLen: %u\n"\r
+               "           MaxPinLen: %u\n"\r
+               "   TotalPublicMemory: %u\n"\r
+               "    FreePublicMemory: %u\n"\r
+               "  TotalPrivateMemory: %u\n"\r
+               "   FreePrivateMemory: %u\n"\r
+               "     HardwareVersion: %s\n"\r
+               "     FirmwareVersion: %s\n",\r
+               s->Label, s->ManufacturerId, s->Model, s->SerialNumber,\r
+               s->MaxSession, s->MaxRWSession, s->MinPinLen, s->MaxPinLen,\r
+               s->TotalPublicMemory, s->FreePublicMemory, s->TotalPrivateMemory,\r
+               s->FreePrivateMemory, s->HardwareVersion, s->FirmwareVersion\r
+               );\r
+}\r
+\r
+// トークン情報を取得\r
+void GetSecInfo(SECURE *sec)\r
+{\r
+       CK_TOKEN_INFO token_info;\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (sec->Info != NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 取得\r
+       Zero(&token_info, sizeof(token_info));\r
+       if (sec->Api->C_GetTokenInfo(sec->SlotIdList[sec->SessionSlotNumber], &token_info) != CKR_OK)\r
+       {\r
+               // 失敗\r
+               return;\r
+       }\r
+\r
+       sec->Info = TokenInfoToSecInfo(&token_info);\r
+}\r
+\r
+// トークン情報を解放\r
+void FreeSecInfo(SECURE *sec)\r
+{\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (sec->Info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       FreeSecInfoMemory(sec->Info);\r
+       sec->Info = NULL;\r
+}\r
+\r
+// トークン情報を SEC_INFO に変換\r
+SEC_INFO *TokenInfoToSecInfo(void *p_t)\r
+{\r
+       SEC_INFO *s;\r
+       char buf[MAX_SIZE];\r
+       CK_TOKEN_INFO *t = (CK_TOKEN_INFO *)p_t;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       s = ZeroMalloc(sizeof(SEC_INFO));\r
+\r
+       // Label\r
+       Zero(buf, sizeof(buf));\r
+       Copy(buf, t->label, sizeof(t->label));\r
+       s->Label = ZeroMalloc(CalcUtf8ToUni(buf, 0));\r
+       Utf8ToUni(s->Label, 0, buf, 0);\r
+\r
+       // ManufacturerId\r
+       Zero(buf, sizeof(buf));\r
+       Copy(buf, t->manufacturerID, sizeof(t->manufacturerID));\r
+       s->ManufacturerId = ZeroMalloc(CalcUtf8ToUni(buf, 0));\r
+       Utf8ToUni(s->ManufacturerId, 0, buf, 0);\r
+\r
+       // Model\r
+       Zero(buf, sizeof(buf));\r
+       Copy(buf, t->model, sizeof(t->model));\r
+       s->Model = ZeroMalloc(CalcUtf8ToUni(buf, 0));\r
+       Utf8ToUni(s->Model, 0, buf, 0);\r
+\r
+       // SerialNumber\r
+       Zero(buf, sizeof(buf));\r
+       Copy(buf, t->serialNumber, sizeof(t->serialNumber));\r
+       s->SerialNumber = ZeroMalloc(CalcUtf8ToUni(buf, 0));\r
+       Utf8ToUni(s->SerialNumber, 0, buf, 0);\r
+\r
+       // 数値\r
+       s->MaxSession = t->ulMaxSessionCount;\r
+       s->MaxRWSession = t->ulMaxRwSessionCount;\r
+       s->MinPinLen = t->ulMinPinLen;\r
+       s->MaxPinLen = t->ulMaxPinLen;\r
+       s->TotalPublicMemory = t->ulTotalPublicMemory;\r
+       s->FreePublicMemory = t->ulFreePublicMemory;\r
+       s->TotalPrivateMemory = t->ulTotalPrivateMemory;\r
+       s->FreePrivateMemory = t->ulFreePrivateMemory;\r
+\r
+       // ハードウェアバージョン\r
+       Format(buf, sizeof(buf), "%u.%02u", t->hardwareVersion.major, t->hardwareVersion.minor);\r
+       s->HardwareVersion = CopyStr(buf);\r
+\r
+       // ファームウェアバージョン\r
+       Format(buf, sizeof(buf), "%u.%02u", t->firmwareVersion.major, t->firmwareVersion.minor);\r
+       s->FirmwareVersion = CopyStr(buf);\r
+\r
+       return s;\r
+}\r
+\r
+// SEC_INFO のメモリを解放\r
+void FreeSecInfoMemory(SEC_INFO *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Free(s->Label);\r
+       Free(s->ManufacturerId);\r
+       Free(s->Model);\r
+       Free(s->SerialNumber);\r
+       Free(s->HardwareVersion);\r
+       Free(s->FirmwareVersion);\r
+       Free(s);\r
+}\r
+\r
+// ログアウトする\r
+void LogoutSec(SECURE *sec)\r
+{\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (sec->LoginFlag == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ログアウト\r
+       sec->Api->C_Logout(sec->SessionId);\r
+\r
+       // キャッシュ消去\r
+       EraseEnumSecObjectCache(sec);\r
+\r
+       sec->LoginFlag = false;\r
+}\r
+\r
+// ログインする\r
+bool LoginSec(SECURE *sec, char *pin)\r
+{\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_SESSION;\r
+               return false;\r
+\r
+       }\r
+       if (sec->LoginFlag)\r
+       {\r
+               sec->Error = SEC_ERROR_ALREADY_LOGIN;\r
+               return false;\r
+       }\r
+       if (pin == NULL)\r
+       {\r
+               sec->Error = SEC_ERROR_NO_PIN_STR;\r
+               return false;\r
+       }\r
+\r
+       // ログイン\r
+       if (sec->Api->C_Login(sec->SessionId, CKU_USER, pin, StrLen(pin)) != CKR_OK)\r
+       {\r
+               // ログイン失敗\r
+               sec->Error = SEC_ERROR_BAD_PIN_CODE;\r
+               return false;\r
+       }\r
+\r
+       // キャッシュ消去\r
+       EraseEnumSecObjectCache(sec);\r
+\r
+       sec->LoginFlag = true;\r
+\r
+       return true;\r
+}\r
+\r
+// セッションを閉じる\r
+void CloseSecSession(SECURE *sec)\r
+{\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (sec->SessionCreated == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // セッションを閉じる\r
+       sec->Api->C_CloseSession(sec->SessionId);\r
+\r
+       sec->SessionCreated = false;\r
+       sec->SessionId = 0;\r
+       sec->SessionSlotNumber = 0;\r
+\r
+       FreeSecInfo(sec);\r
+\r
+       // キャッシュ消去\r
+       EraseEnumSecObjectCache(sec);\r
+}\r
+\r
+// セッションを開く\r
+bool OpenSecSession(SECURE *sec, UINT slot_number)\r
+{\r
+       UINT err = 0;\r
+       UINT session;\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (sec->SessionCreated)\r
+       {\r
+               // すでに作成されている\r
+               sec->Error = SEC_ERROR_SESSION_EXISTS;\r
+               return false;\r
+       }\r
+       if (slot_number >= sec->NumSlot)\r
+       {\r
+               // スロット番号不正\r
+               sec->Error = SEC_ERROR_INVALID_SLOT_NUMBER;\r
+               return false;\r
+       }\r
+\r
+       // セッション作成\r
+       if ((err = sec->Api->C_OpenSession(sec->SlotIdList[slot_number],\r
+               CKF_RW_SESSION | CKF_SERIAL_SESSION, NULL, NULL, &session)) != CKR_OK)\r
+       {\r
+               // 読み書きモードでのセッション初期化に失敗した\r
+               // 読み取り専用モードかな?\r
+               if ((err = sec->Api->C_OpenSession(sec->SlotIdList[slot_number],\r
+                       CKF_SERIAL_SESSION, NULL, NULL, &session)) != CKR_OK)\r
+               {\r
+                       // 作成失敗\r
+                       sec->Error = SEC_ERROR_OPEN_SESSION;\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       sec->IsReadOnly = true;\r
+               }\r
+       }\r
+\r
+       sec->SessionCreated = true;\r
+       sec->SessionId = session;\r
+       sec->SessionSlotNumber = slot_number;\r
+\r
+       // トークン情報を取得\r
+       GetSecInfo(sec);\r
+\r
+       return true;\r
+}\r
+\r
+// セキュアデバイスを閉じる\r
+void CloseSec(SECURE *sec)\r
+{\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ログアウトする\r
+       LogoutSec(sec);\r
+\r
+       // セッションを閉じる\r
+       CloseSecSession(sec);\r
+\r
+       // トークン情報を解放\r
+       FreeSecInfo(sec);\r
+\r
+       // スロットリストメモリの解放\r
+       if (sec->SlotIdList != NULL)\r
+       {\r
+               Free(sec->SlotIdList);\r
+               sec->SlotIdList = NULL;\r
+       }\r
+\r
+       // モジュールのアンロード\r
+       FreeSecModule(sec);\r
+\r
+       // メモリ解放\r
+       DeleteLock(sec->lock);\r
+       Free(sec);\r
+}\r
+\r
+// セキュアデバイスを開く\r
+SECURE *OpenSec(UINT id)\r
+{\r
+       SECURE_DEVICE *dev = GetSecureDevice(id);\r
+       SECURE *sec;\r
+       UINT err;\r
+\r
+       if (dev == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       sec = ZeroMalloc(sizeof(SECURE));\r
+\r
+       sec->lock = NewLock();\r
+       sec->Error = SEC_ERROR_NOERROR;\r
+       sec->Dev = dev;\r
+\r
+       // ePass かどうか取得する\r
+       if (SearchStrEx(dev->DeviceName, "epass", 0, false) != INFINITE)\r
+       {\r
+               sec->IsEPass1000 = true;\r
+       }\r
+\r
+       // モジュールのロード\r
+       if (LoadSecModule(sec) == false)\r
+       {\r
+               CloseSec(sec);\r
+               return NULL;\r
+       }\r
+\r
+       // スロット一覧の取得\r
+       sec->NumSlot = 0;\r
+       if ((err = sec->Api->C_GetSlotList(true, NULL, &sec->NumSlot)) != CKR_OK || sec->NumSlot == 0)\r
+       {\r
+               // 失敗\r
+               FreeSecModule(sec);\r
+               CloseSec(sec);\r
+               return NULL;\r
+       }\r
+\r
+       sec->SlotIdList = (UINT *)ZeroMalloc(sizeof(UINT *) * sec->NumSlot);\r
+\r
+       if (sec->Api->C_GetSlotList(TRUE, sec->SlotIdList, &sec->NumSlot) != CKR_OK)\r
+       {\r
+               // 失敗\r
+               Free(sec->SlotIdList);\r
+               sec->SlotIdList = NULL;\r
+               FreeSecModule(sec);\r
+               CloseSec(sec);\r
+               return NULL;\r
+       }\r
+\r
+       return sec;\r
+}\r
+\r
+// セキュアデバイスのモジュールをロードする\r
+bool LoadSecModule(SECURE *sec)\r
+{\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       ret = Win32LoadSecModule(sec);\r
+#endif // OS_WIN32\r
+\r
+       // 初期化\r
+       if (sec->Api->C_Initialize(NULL) != CKR_OK)\r
+       {\r
+               // 初期化失敗\r
+               FreeSecModule(sec);\r
+               return false;\r
+       }\r
+\r
+       sec->Initialized = true;\r
+\r
+       return ret;\r
+}\r
+\r
+// セキュアデバイスのモジュールをアンロードする\r
+void FreeSecModule(SECURE *sec)\r
+{\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (sec->Initialized)\r
+       {\r
+               // 初期化済みなので解放する\r
+               sec->Api->C_Finalize(NULL);\r
+               sec->Initialized = false;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       Win32FreeSecModule(sec);\r
+#endif // OS_WIN32\r
+\r
+}\r
+\r
+\r
+// セキュアデバイスを取得する\r
+SECURE_DEVICE *GetSecureDevice(UINT id)\r
+{\r
+       UINT i;\r
+\r
+       if (id == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(SecureDeviceList);i++)\r
+       {\r
+               SECURE_DEVICE *dev = LIST_DATA(SecureDeviceList, i);\r
+\r
+               if (dev->Id == id)\r
+               {\r
+                       return dev;\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// セキュアデバイスの ID を確認する\r
+bool CheckSecureDeviceId(UINT id)\r
+{\r
+       UINT i;\r
+\r
+       for (i = 0;i < LIST_NUM(SecureDeviceList);i++)\r
+       {\r
+               SECURE_DEVICE *dev = LIST_DATA(SecureDeviceList, i);\r
+\r
+               if (dev->Id == id)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// サポートされているデバイスリストを取得する\r
+LIST *GetSecureDeviceList()\r
+{\r
+       return GetSupportedDeviceList();\r
+}\r
+\r
+// サポートされているデバイスリストを取得する\r
+LIST *GetSupportedDeviceList()\r
+{\r
+       // 参照カウントの増加\r
+       AddRef(SecureDeviceList->ref);\r
+\r
+       return SecureDeviceList;\r
+}\r
+\r
+// 指定したデバイスがインストールされていて利用可能かどうか調べる\r
+bool IsDeviceSupported(SECURE_DEVICE *dev)\r
+{\r
+       bool b = false;\r
+#ifdef OS_WIN32\r
+       b = Win32IsDeviceSupported(dev);\r
+#endif // OS_WIN32\r
+       return b;\r
+}\r
+\r
+// セキュアデバイスリストの初期化\r
+void InitSecureDeviceList()\r
+{\r
+       UINT i, num_supported_list;\r
+       SecureDeviceList = NewList(NULL);\r
+\r
+       num_supported_list = sizeof(SupportedList) / sizeof(SECURE_DEVICE);\r
+       for (i = 0; i < num_supported_list;i++)\r
+       {\r
+               SECURE_DEVICE *dev = &SupportedList[i];\r
+\r
+               // サポートチェック\r
+               if (IsDeviceSupported(dev))\r
+               {\r
+                       // サポートされているのでリストに追加\r
+                       Add(SecureDeviceList, dev);\r
+               }\r
+       }\r
+}\r
+\r
+// テストメイン処理\r
+void TestSecMain(SECURE *sec)\r
+{\r
+       char *test_str = "SoftEther UT-VPN";\r
+       K *public_key, *private_key;\r
+       // 引数チェック\r
+       if (sec == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Print("test_str: \"%s\"\n", test_str);\r
+\r
+       Print("Writing Data...\n");\r
+       if (WriteSecData(sec, true, "test_str", test_str, StrLen(test_str)) == false)\r
+       {\r
+               Print("WriteSecData() Failed.\n");\r
+       }\r
+       else\r
+       {\r
+               char data[MAX_SIZE];\r
+               Zero(data, sizeof(data));\r
+               Print("Reading Data...\n");\r
+               if (ReadSecData(sec, "test_str", data, sizeof(data)) == false)\r
+               {\r
+                       Print("ReadSecData() Failed.\n");\r
+               }\r
+               else\r
+               {\r
+                       Print("test_str: \"%s\"\n", data);\r
+               }\r
+               Print("Deleting Data...\n");\r
+               DeleteSecData(sec, "test_str");\r
+       }\r
+\r
+       Print("Generating Key...\n");\r
+       if (RsaGen(&private_key, &public_key, 1024) == false)\r
+       {\r
+               Print("RsaGen() Failed.\n");\r
+       }\r
+       else\r
+       {\r
+               X *cert;\r
+               NAME *name;\r
+               X_SERIAL *serial;\r
+               UINT num = 0x11220000;\r
+\r
+               Print("Creating Cert...\n");\r
+               serial = NewXSerial(&num, sizeof(UINT));\r
+               name = NewName(L"Test", L"Test", L"Test", L"JP", L"Test", L"Test");\r
+               cert = NewRootX(public_key, private_key, name, 365, NULL);\r
+               FreeXSerial(serial);\r
+               if (cert == NULL)\r
+               {\r
+                       Print("NewRootX() Failed.\n");\r
+               }\r
+               else\r
+               {\r
+                       Print("Writing Cert...\n");\r
+                       DeleteSecData(sec, "test_cer");\r
+                       if (WriteSecCert(sec, true, "test_cer", cert) == false)\r
+                       {\r
+                               Print("WriteSecCert() Failed.\n");\r
+                       }\r
+                       else\r
+                       {\r
+                               X *x;\r
+                               Print("Reading Cert...\n");\r
+                               x = ReadSecCert(sec, "test_cer");\r
+                               if (x == NULL)\r
+                               {\r
+                                       Print("ReadSecCert() Failed.\n");\r
+                               }\r
+                               else\r
+                               {\r
+                                       Print("Checking two Certs... ");\r
+                                       if (CompareX(x, cert) == false)\r
+                                       {\r
+                                               Print("[FAILED]\n");\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               Print("Ok.\n");\r
+                                       }\r
+                                       FreeX(x);\r
+                               }\r
+                               if (cert != NULL)\r
+                               {\r
+                                       X *x;\r
+                                       XToFile(cert, "cert_tmp.cer", true);\r
+                                       x = FileToX("cert_tmp.cer");\r
+                                       if (CompareX(x, cert) == false)\r
+                                       {\r
+                                               Print("[FAILED]\n");\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               Print("Ok.\n");\r
+                                               Print("Writing Private Key...\n");\r
+                                               DeleteSecKey(sec, "test_key");\r
+                                               if (WriteSecKey(sec, true, "test_key", private_key) == false)\r
+                                               {\r
+                                                       Print("WriteSecKey() Failed.\n");\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       UCHAR sign_cpu[128];\r
+                                                       UCHAR sign_sec[128];\r
+                                                       K *pub = GetKFromX(cert);\r
+                                                       Print("Ok.\n");\r
+                                                       Print("Signing Data by CPU...\n");\r
+                                                       if (RsaSign(sign_cpu, test_str, StrLen(test_str), private_key) == false)\r
+                                                       {\r
+                                                               Print("RsaSign() Failed.\n");\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               Print("Ok.\n");\r
+                                                               Print("sign_cpu: ");\r
+                                                               PrintBin(sign_cpu, sizeof(sign_cpu));\r
+                                                               Print("Signing Data by %s..\n", sec->Dev->DeviceName);\r
+                                                               if (SignSec(sec, "test_key", sign_sec, test_str, StrLen(test_str)) == false)\r
+                                                               {\r
+                                                                       Print("SignSec() Failed.\n");\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       Print("Ok.\n");\r
+                                                                       Print("sign_sec: ");\r
+                                                                       PrintBin(sign_sec, sizeof(sign_sec));\r
+                                                                       Print("Compare...");\r
+                                                                       if (Cmp(sign_sec, sign_cpu, sizeof(sign_cpu)) == 0)\r
+                                                                       {\r
+                                                                               Print("Ok.\n");\r
+                                                                               Print("Verify...");\r
+                                                                               if (RsaVerify(test_str, StrLen(test_str),\r
+                                                                                       sign_sec, pub) == false)\r
+                                                                               {\r
+                                                                                       Print("[FAILED]\n");\r
+                                                                               }\r
+                                                                               else\r
+                                                                               {\r
+                                                                                       Print("Ok.\n");\r
+                                                                               }\r
+                                                                       }\r
+                                                                       else\r
+                                                                       {\r
+                                                                               Print("[DIFFIRENT]\n");\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+                                                       Print("Deleting test_key...\n");\r
+//                                                     DeleteSecKey(sec, "test_key");\r
+                                                       FreeK(pub);\r
+                                               }\r
+                                       }\r
+                                       FreeX(x);\r
+                               }\r
+                       }\r
+                       Print("Deleting Cert..\n");\r
+//                     DeleteSecCert(sec, "test_cer");\r
+                       FreeX(cert);\r
+               }\r
+               FreeName(name);\r
+               FreeK(private_key);\r
+               FreeK(public_key);\r
+       }\r
+}\r
+\r
+// セキュリティデバイスのテスト\r
+void TestSec()\r
+{\r
+       UINT i;\r
+       LIST *secure_device_list;\r
+       Print("Secure Device Test Program\n"\r
+               "Copyright (C) 2004-2010 SoftEther Corporation. All Rights Reserved.\n\n");\r
+\r
+       // セキュアデバイスリストの取得\r
+       secure_device_list = GetSecureDeviceList();\r
+       if (secure_device_list != NULL)\r
+       {\r
+               UINT use_device_id;\r
+               char tmp[MAX_SIZE];\r
+               Print("--- Secure Device List ---\n");\r
+               for (i = 0;i < LIST_NUM(secure_device_list);i++)\r
+               {\r
+                       SECURE_DEVICE *dev = LIST_DATA(secure_device_list, i);\r
+                       Print("%2u - %s\n", dev->Id, dev->DeviceName);\r
+               }\r
+               Print("\n");\r
+               Print("Device ID >");\r
+               GetLine(tmp, sizeof(tmp));\r
+               use_device_id = ToInt(tmp);\r
+               if (use_device_id == 0)\r
+               {\r
+                       Print("Canceled.\n");\r
+               }\r
+               else\r
+               {\r
+                       SECURE *sec = OpenSec(use_device_id);\r
+                       Print("Opening Device...\n");\r
+                       if (sec == NULL)\r
+                       {\r
+                               Print("OpenSec() Failed.\n");\r
+                       }\r
+                       else\r
+                       {\r
+                               Print("Opening Session...\n");\r
+                               if (OpenSecSession(sec, 0) == false)\r
+                               {\r
+                                       Print("OpenSecSession() Failed.\n");\r
+                               }\r
+                               else\r
+                               {\r
+                                       while (true)\r
+                                       {\r
+                                               char pin[MAX_SIZE];\r
+                                               Print("PIN Code >");\r
+                                               GetLine(pin, sizeof(pin));\r
+                                               Trim(pin);\r
+                                               if (StrLen(pin) == 0)\r
+                                               {\r
+                                                       Print("Canceled.\n");\r
+                                                       break;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       Print("Login...\n");\r
+                                                       if (LoginSec(sec, pin))\r
+                                                       {\r
+                                                               TestSecMain(sec);\r
+                                                               Print("Logout...\n");\r
+                                                               LogoutSec(sec);\r
+                                                               break;\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               Print("Login Failed. Please Try Again.\n");\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       Print("Closing Session...\n");\r
+                                       CloseSecSession(sec);\r
+                               }\r
+                               Print("Closing Device...\n");\r
+                               CloseSec(sec);\r
+                       }\r
+               }\r
+               ReleaseList(secure_device_list);\r
+       }\r
+       else\r
+       {\r
+               Print("GetSecureDeviceList() Error.\n");\r
+       }\r
+}\r
+\r
+// セキュアデバイスリストの解放\r
+void FreeSecureDeviceList()\r
+{\r
+       ReleaseList(SecureDeviceList);\r
+}\r
+\r
+// セキュリティトークンモジュールの初期化\r
+void InitSecure()\r
+{\r
+       // セキュアデバイスリストの初期化\r
+       InitSecureDeviceList();\r
+}\r
+\r
+// セキュリティトークンモジュールの解放\r
+void FreeSecure()\r
+{\r
+       // セキュアデバイスリストの解放\r
+       FreeSecureDeviceList();\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Secure.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Secure.h
new file mode 100644 (file)
index 0000000..d194d14
--- /dev/null
@@ -0,0 +1,294 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Secure.h\r
+// Secure.c のヘッダ\r
+\r
+#ifndef        SECURE_H\r
+#define        SECURE_H\r
+\r
+// 定数\r
+#define        MAX_SEC_DATA_SIZE               4096\r
+\r
+// PKCS#11 関係の型宣言\r
+#ifndef        SECURE_C\r
+typedef struct CK_FUNCTION_LIST *CK_FUNCTION_LIST_PTR;\r
+typedef struct SEC_DATA_WIN32  SEC_DATA_WIN32;\r
+typedef struct CK_TOKEN_INFO   CK_TOKEN_INFO;\r
+typedef struct CK_DATE                 CK_DATE;\r
+#endif // SECURE_C\r
+\r
+// セキュアデバイス\r
+struct SECURE_DEVICE\r
+{\r
+       UINT Id;                                                                // デバイス ID\r
+       UINT Type;                                                              // 種類\r
+       char *DeviceName;                                               // デバイス名\r
+       char *Manufacturer;                                             // 製造元\r
+       char *ModuleName;                                               // モジュール名\r
+};\r
+\r
+// セキュアデバイスの種類\r
+#define        SECURE_IC_CARD                          0               // IC カード\r
+#define        SECURE_USB_TOKEN                        1               // USB トークン\r
+\r
+// セキュアデバイス情報\r
+struct SEC_INFO\r
+{\r
+       wchar_t *Label;                                                 // ラベル\r
+       wchar_t *ManufacturerId;                                        // 製造元 ID\r
+       wchar_t *Model;                                                 // モデル\r
+       wchar_t *SerialNumber;                                          // シリアル番号\r
+       UINT MaxSession;                                                // 最大セッション数\r
+       UINT MaxRWSession;                                              // 最大 R/W セッション数\r
+       UINT MinPinLen;                                                 // 最小 PIN 文字列長\r
+       UINT MaxPinLen;                                                 // 最大 PIN 文字列長\r
+       UINT TotalPublicMemory;                                 // 合計メモリ容量 (Public)\r
+       UINT FreePublicMemory;                                  // 空きメモリ容量 (Private)\r
+       UINT TotalPrivateMemory;                                // 合計メモリ容量 (Public)\r
+       UINT FreePrivateMemory;                                 // 空きメモリ容量 (Private)\r
+       char *HardwareVersion;                                  // ハードウェアバージョン\r
+       char *FirmwareVersion;                                  // ファームウェアバージョン\r
+};\r
+\r
+// セキュアデバイス構造体\r
+struct SECURE\r
+{\r
+       LOCK *lock;                                                             // ロック\r
+       SECURE_DEVICE *Dev;                                             // デバイス情報\r
+       UINT Error;                                                             // 最後に発生したエラー\r
+       struct CK_FUNCTION_LIST *Api;                   // API\r
+       bool Initialized;                                               // 初期化フラグ\r
+       UINT NumSlot;                                                   // スロット数\r
+       UINT *SlotIdList;                                               // スロット ID リスト\r
+       bool SessionCreated;                                    // セッション作成フラグ\r
+       UINT SessionId;                                                 // セッション ID\r
+       UINT SessionSlotNumber;                                 // セッションのスロット ID\r
+       bool LoginFlag;                                                 // ログイン済みフラグ\r
+       SEC_INFO *Info;                                                 // トークン情報\r
+       LIST *EnumCache;                                                // 列挙キャッシュ\r
+\r
+       // ドライバごとに異なる挙動をするための属性値\r
+       bool IsEPass1000;                                               // ePass 1000\r
+       bool IsReadOnly;                                                // 読み取り専用モード\r
+\r
+#ifdef OS_WIN32\r
+       struct SEC_DATA_WIN32 *Data;                    // データ\r
+#endif // OS_WIN32\r
+};\r
+\r
+// セキュアデバイスオブジェクト構造体\r
+struct SEC_OBJ\r
+{\r
+       UINT Type;                                                              // オブジェクトの種類\r
+       UINT Object;                                                    // オブジェクトハンドル\r
+       bool Private;                                                   // プライベートフラグ\r
+       char *Name;                                                             // 名前\r
+};\r
+\r
+#define        SEC_ERROR_NOERROR                               0       // エラー無し\r
+#define        SEC_ERROR_INVALID_SLOT_NUMBER   1       // スロット番号が不正\r
+#define        SEC_ERROR_OPEN_SESSION                  2       // セッション作成失敗\r
+#define        SEC_ERROR_SESSION_EXISTS                3       // すでにセッションが存在する\r
+#define        SEC_ERROR_NO_PIN_STR                    4       // PIN 文字列が指定されていない\r
+#define        SEC_ERROR_ALREADY_LOGIN                 5       // すでにログインしている\r
+#define        SEC_ERROR_BAD_PIN_CODE                  6       // PIN コードが不正\r
+#define        SEC_ERROR_NO_SESSION                    7       // セッションが存在しない\r
+#define        SEC_ERROR_DATA_TOO_BIG                  8       // データが大きすぎる\r
+#define        SEC_ERROR_NOT_LOGIN                             9       // ログインしていない\r
+#define        SEC_ERROR_BAD_PARAMETER                 10      // パラメータ不正\r
+#define        SEC_ERROR_HARDWARE_ERROR                11      // ハードウェアエラー\r
+#define        SEC_ERROR_OBJ_NOT_FOUND                 12      // オブジェクトが見つからない\r
+#define        SEC_ERROR_INVALID_CERT                  13      // 証明書が不正\r
+\r
+\r
+#define        SEC_DATA                                                0       // データ\r
+#define        SEC_X                                                   1       // 証明書\r
+#define        SEC_K                                                   2       // 秘密鍵\r
+#define        SEC_P                                                   3       // 公開鍵\r
+\r
+\r
+\r
+// 関数プロトタイプ\r
+void InitSecure();\r
+void FreeSecure();\r
+void InitSecureDeviceList();\r
+void FreeSecureDeviceList();\r
+bool IsDeviceSupported(SECURE_DEVICE *dev);\r
+LIST *GetSupportedDeviceList();\r
+LIST *GetSecureDeviceList();\r
+bool CheckSecureDeviceId(UINT id);\r
+SECURE_DEVICE *GetSecureDevice(UINT id);\r
+SECURE *OpenSec(UINT id);\r
+void CloseSec(SECURE *sec);\r
+bool OpenSecSession(SECURE *sec, UINT slot_number);\r
+void CloseSecSession(SECURE *sec);\r
+bool LoginSec(SECURE *sec, char *pin);\r
+void LogoutSec(SECURE *sec);\r
+void PrintSecInfo(SECURE *sec);\r
+LIST *EnumSecObject(SECURE *sec);\r
+void FreeSecObject(SEC_OBJ *obj);\r
+void FreeEnumSecObject(LIST *o);\r
+SEC_OBJ *FindSecObject(SECURE *sec, char *name, UINT type);\r
+bool CheckSecObject(SECURE *sec, char *name, UINT type);\r
+bool DeleteSecObjectByName(SECURE *sec, char *name, UINT type);\r
+SEC_OBJ *CloneSecObject(SEC_OBJ *obj);\r
+LIST *CloneEnumSecObject(LIST *o);\r
+void EraseEnumSecObjectCache(SECURE *sec);\r
+void DeleteSecObjFromEnumCache(SECURE *sec, char *name, UINT type);\r
+void AddSecObjToEnumCache(SECURE *sec, char *name, UINT type, bool private_obj, UINT object);\r
+bool WriteSecData(SECURE *sec, bool private_obj, char *name, void *data, UINT size);\r
+int ReadSecDataFromObject(SECURE *sec, SEC_OBJ *obj, void *data, UINT size);\r
+int ReadSecData(SECURE *sec, char *name, void *data, UINT size);\r
+bool DeleteSecObject(SECURE *sec, SEC_OBJ *obj);\r
+bool DeleteSecData(SECURE *sec, char *name);\r
+void UINT64ToCkDate(void *p_ck_date, UINT64 time64);\r
+bool WriteSecCert(SECURE *sec, bool private_obj, char *name, X *x);\r
+bool DeleteSecCert(SECURE *sec, char *name);\r
+X *ReadSecCertFromObject(SECURE *sec, SEC_OBJ *obj);\r
+X *ReadSecCert(SECURE *sec, char *name);\r
+bool WriteSecKey(SECURE *sec, bool private_obj, char *name, K *k);\r
+bool DeleteSecKey(SECURE *sec, char *name);\r
+bool SignSecByObject(SECURE *sec, SEC_OBJ *obj, void *dst, void *src, UINT size);\r
+bool SignSec(SECURE *sec, char *name, void *dst, void *src, UINT size);\r
+bool ChangePin(SECURE *sec, char *old_pin, char *new_pin);\r
+void TestSec();\r
+void TestSecMain(SECURE *sec);\r
+bool IsJPKI(bool id);\r
+\r
+bool LoadSecModule(SECURE *sec);\r
+void FreeSecModule(SECURE *sec);\r
+void GetSecInfo(SECURE *sec);\r
+void FreeSecInfo(SECURE *sec);\r
+SEC_INFO *TokenInfoToSecInfo(void *p_t);\r
+void FreeSecInfoMemory(SEC_INFO *s);\r
+\r
+#ifdef OS_WIN32\r
+\r
+bool Win32IsDeviceSupported(SECURE_DEVICE *dev);\r
+bool Win32LoadSecModule(SECURE *sec);\r
+void Win32FreeSecModule(SECURE *sec);\r
+\r
+#endif // OS_WIN32\r
+\r
+\r
+#ifdef SECURE_C\r
+// 内部データ構造関連\r
+\r
+// サポートしているセキュアデバイスリスト\r
+static LIST *SecureDeviceList = NULL;\r
+\r
+// サポートしているハードウェアリスト\r
+// Q. なぜこのような静的なリストになっているのか? 動的に追加できないのか?\r
+// A. 今のところ、手抜きのためこのような実装になっている。\r
+SECURE_DEVICE SupportedList[] =\r
+{\r
+       {1,             SECURE_IC_CARD,         "Standard-9 IC Card",   "Dai Nippon Printing",  "DNPS9P11.DLL"},\r
+       {2,             SECURE_USB_TOKEN,       "ePass 1000",                   "Feitian Technologies", "EP1PK111.DLL"},\r
+       {3,             SECURE_IC_CARD,         "DNP Felica",                   "Dai Nippon Printing",  "DNPFP11.DLL"},\r
+       {4,             SECURE_USB_TOKEN,       "eToken",                               "Aladdin",                              "ETPKCS11.DLL"},\r
+       {5,             SECURE_IC_CARD,         "Standard-9 IC Card",   "Fujitsu",                              "F3EZSCL2.DLL"},\r
+       {6,             SECURE_IC_CARD,         "ASECard",                              "Athena",                               "ASEPKCS.DLL"},\r
+       {7,             SECURE_IC_CARD,         "Gemplus IC Card",              "Gemplus",                              "PK2PRIV.DLL"},\r
+       {8,             SECURE_IC_CARD,         "1-Wire & iButton",             "DALLAS SEMICONDUCTOR", "DSPKCS.DLL"},\r
+       {9,             SECURE_IC_CARD,         "JPKI IC Card",                 "Japanese Government",  "JPKIPKCS11.DLL"},\r
+       {10,    SECURE_IC_CARD,         "LGWAN IC Card",                "Japanese Government",  "P11STD9.DLL"},\r
+       {11,    SECURE_IC_CARD,         "LGWAN IC Card",                "Japanese Government",  "P11STD9A.DLL"},\r
+       {12,    SECURE_USB_TOKEN,       "iKey 1000",                    "Rainbow Technologies", "K1PK112.DLL"},\r
+       {13,    SECURE_IC_CARD,         "JPKI IC Card #2",              "Japanese Government",  "libmusclepkcs11.dll"},\r
+       {14,    SECURE_USB_TOKEN,       "SafeSign",                             "A.E.T.",                               "aetpkss1.dll"},\r
+       {15,    SECURE_USB_TOKEN,       "LOCK STAR-PKI",                "Logicaltech Co.,LTD",  "LTPKCS11.dll"},\r
+       {16,    SECURE_USB_TOKEN,       "ePass 2000",                   "Feitian Technologies", "ep2pk11.dll"},\r
+       {17,    SECURE_IC_CARD,         "myuToken",                             "iCanal Inc.",                  "icardmodpk.dll"},\r
+};\r
+\r
+#ifdef OS_WIN32\r
+\r
+// Win32 用内部データ\r
+typedef struct SEC_DATA_WIN32\r
+{\r
+       HINSTANCE hInst;\r
+} SEC_DATA_WIN32;\r
+\r
+#endif // OS_WIN32\r
+\r
+#endif // SECURE_C\r
+\r
+#endif // SECURE_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Str.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Str.c
new file mode 100644 (file)
index 0000000..10beb3c
--- /dev/null
@@ -0,0 +1,3068 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Str.c\r
+// 文字列処理ルーチン\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+// トークン関数の呼び出し用ロック処理\r
+LOCK *token_lock = NULL;\r
+static char *default_spliter = " ,\t\r\n";\r
+\r
+typedef struct BYTESTR\r
+{\r
+       UINT64 base_value;\r
+       char *string;\r
+} BYTESTR;\r
+\r
+static BYTESTR bytestr[] =\r
+{\r
+       {0, "PBytes"},\r
+       {0, "TBytes"},\r
+       {0, "GBytes"},\r
+       {0, "MBytes"},\r
+       {0, "KBytes"},\r
+       {0, "Bytes"},\r
+};\r
+\r
+// HEX 文字列を 64 bit 整数に変換\r
+UINT64 HexToInt64(char *str)\r
+{\r
+       UINT len, i;\r
+       UINT64 ret = 0;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))\r
+       {\r
+               str += 2;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               char c = str[i];\r
+\r
+               if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))\r
+               {\r
+                       ret = ret * 16ULL + (UINT64)HexTo4Bit(c);\r
+               }\r
+               else\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// HEX 文字列を 32 bit 整数に変換\r
+UINT HexToInt(char *str)\r
+{\r
+       UINT len, i;\r
+       UINT ret = 0;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))\r
+       {\r
+               str += 2;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               char c = str[i];\r
+\r
+               if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))\r
+               {\r
+                       ret = ret * 16 + (UINT)HexTo4Bit(c);\r
+               }\r
+               else\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// 64 bit 整数を HEX に変換\r
+void ToHex64(char *str, UINT64 value)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UINT wp = 0;\r
+       UINT len, i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 空文字に設定\r
+       StrCpy(tmp, 0, "");\r
+\r
+       // 末尾桁から追加する\r
+       while (true)\r
+       {\r
+               UINT a = (UINT)(value % (UINT64)16);\r
+               value = value / (UINT)16;\r
+               tmp[wp++] = FourBitToHex(a);\r
+               if (value == 0)\r
+               {\r
+                       tmp[wp++] = 0;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       // 逆順にする\r
+       len = StrLen(tmp);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               str[len - i - 1] = tmp[i];\r
+       }\r
+       str[len] = 0;\r
+}\r
+\r
+// 32 bit 整数を HEX に変換\r
+void ToHex(char *str, UINT value)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UINT wp = 0;\r
+       UINT len, i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 空文字に設定\r
+       StrCpy(tmp, 0, "");\r
+\r
+       // 末尾桁から追加する\r
+       while (true)\r
+       {\r
+               UINT a = (UINT)(value % (UINT)16);\r
+               value = value / (UINT)16;\r
+               tmp[wp++] = FourBitToHex(a);\r
+               if (value == 0)\r
+               {\r
+                       tmp[wp++] = 0;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       // 逆順にする\r
+       len = StrLen(tmp);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               str[len - i - 1] = tmp[i];\r
+       }\r
+       str[len] = 0;\r
+}\r
+\r
+// 4 bit 数値を 16 進文字列に変換\r
+char FourBitToHex(UINT value)\r
+{\r
+       value = value % 16;\r
+\r
+       if (value <= 9)\r
+       {\r
+               return '0' + value;\r
+       }\r
+       else\r
+       {\r
+               return 'a' + (value - 10);\r
+       }\r
+}\r
+\r
+// 16 進文字列を 4 bit 整数に変換\r
+UINT HexTo4Bit(char c)\r
+{\r
+       if ('0' <= c && c <= '9')\r
+       {\r
+               return c - '0';\r
+       }\r
+       else if ('a' <= c && c <= 'f')\r
+       {\r
+               return c - 'a' + 10;\r
+       }\r
+       else if ('A' <= c && c <= 'F')\r
+       {\r
+               return c - 'A' + 10;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
+// 標準のトークン区切り文字を取得する\r
+char *DefaultTokenSplitChars()\r
+{\r
+       return " ,\t\r\n";\r
+}\r
+\r
+// 指定された文字が文字列に含まれるかどうかチェック\r
+bool IsCharInStr(char *str, char c)\r
+{\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (str[i] == c)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// 文字列からトークンを切り出す (区切り文字間の空間を無視しない)\r
+TOKEN_LIST *ParseTokenWithNullStr(char *str, char *split_chars)\r
+{\r
+       LIST *o;\r
+       UINT i, len;\r
+       BUF *b;\r
+       char zero = 0;\r
+       TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NullToken();\r
+       }\r
+       if (split_chars == NULL)\r
+       {\r
+               split_chars = DefaultTokenSplitChars();\r
+       }\r
+\r
+       b = NewBuf();\r
+       o = NewListFast(NULL);\r
+\r
+       len = StrLen(str);\r
+\r
+       for (i = 0;i < (len + 1);i++)\r
+       {\r
+               char c = str[i];\r
+               bool flag = IsCharInStr(split_chars, c);\r
+\r
+               if (c == '\0')\r
+               {\r
+                       flag = true;\r
+               }\r
+\r
+               if (flag == false)\r
+               {\r
+                       WriteBuf(b, &c, sizeof(char));\r
+               }\r
+               else\r
+               {\r
+                       WriteBuf(b, &zero, sizeof(char));\r
+\r
+                       Insert(o, CopyStr((char *)b->Buf));\r
+                       ClearBuf(b);\r
+               }\r
+       }\r
+\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               t->Token[i] = LIST_DATA(o, i);\r
+       }\r
+\r
+       ReleaseList(o);\r
+       FreeBuf(b);\r
+\r
+       return t;\r
+}\r
+\r
+// 文字列からトークンを切り出す (区切り文字間の空間を無視する)\r
+TOKEN_LIST *ParseTokenWithoutNullStr(char *str, char *split_chars)\r
+{\r
+       LIST *o;\r
+       UINT i, len;\r
+       bool last_flag;\r
+       BUF *b;\r
+       char zero = 0;\r
+       TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NullToken();\r
+       }\r
+       if (split_chars == NULL)\r
+       {\r
+               split_chars = DefaultTokenSplitChars();\r
+       }\r
+\r
+       b = NewBuf();\r
+       o = NewListFast(NULL);\r
+\r
+       len = StrLen(str);\r
+       last_flag = false;\r
+\r
+       for (i = 0;i < (len + 1);i++)\r
+       {\r
+               char c = str[i];\r
+               bool flag = IsCharInStr(split_chars, c);\r
+\r
+               if (c == '\0')\r
+               {\r
+                       flag = true;\r
+               }\r
+\r
+               if (flag == false)\r
+               {\r
+                       WriteBuf(b, &c, sizeof(char));\r
+               }\r
+               else\r
+               {\r
+                       if (last_flag == false)\r
+                       {\r
+                               WriteBuf(b, &zero, sizeof(char));\r
+\r
+                               if ((StrLen((char *)b->Buf)) != 0)\r
+                               {\r
+                                       Insert(o, CopyStr((char *)b->Buf));\r
+                               }\r
+                               ClearBuf(b);\r
+                       }\r
+               }\r
+\r
+               last_flag = flag;\r
+       }\r
+\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               t->Token[i] = LIST_DATA(o, i);\r
+       }\r
+\r
+       ReleaseList(o);\r
+       FreeBuf(b);\r
+\r
+       return t;\r
+}\r
+\r
+// 文字列が含まれているかどうかチェック\r
+bool InStr(char *str, char *keyword)\r
+{\r
+       return InStrEx(str, keyword, false);\r
+}\r
+bool InStrEx(char *str, char *keyword, bool case_sensitive)\r
+{\r
+       // 引数チェック\r
+       if (IsEmptyStr(str) || IsEmptyStr(keyword))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (SearchStrEx(str, keyword, 0, case_sensitive) == INFINITE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// INI から値を取得\r
+UINT IniIntValue(LIST *o, char *key)\r
+{\r
+       INI_ENTRY *e;\r
+       // 引数チェック\r
+       if (o == NULL || key == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       e = GetIniEntry(o, key);\r
+       if (e == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return ToInt(e->Value);\r
+}\r
+UINT64 IniInt64Value(LIST *o, char *key)\r
+{\r
+       INI_ENTRY *e;\r
+       // 引数チェック\r
+       if (o == NULL || key == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       e = GetIniEntry(o, key);\r
+       if (e == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return ToInt64(e->Value);\r
+}\r
+char *IniStrValue(LIST *o, char *key)\r
+{\r
+       INI_ENTRY *e;\r
+       // 引数チェック\r
+       if (o == NULL || key == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       e = GetIniEntry(o, key);\r
+       if (e == NULL)\r
+       {\r
+               return "";\r
+       }\r
+\r
+       return e->Value;\r
+}\r
+wchar_t *IniUniStrValue(LIST *o, char *key)\r
+{\r
+       INI_ENTRY *e;\r
+       // 引数チェック\r
+       if (o == NULL || key == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       e = GetIniEntry(o, key);\r
+       if (e == NULL)\r
+       {\r
+               return L"";\r
+       }\r
+\r
+       return e->UnicodeValue;\r
+}\r
+\r
+// INI を解放する\r
+void FreeIni(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               INI_ENTRY *e = LIST_DATA(o, i);\r
+\r
+               Free(e->Key);\r
+               Free(e->Value);\r
+               Free(e->UnicodeValue);\r
+\r
+               Free(e);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// INI ファイルのエントリを取得する\r
+INI_ENTRY *GetIniEntry(LIST *o, char *key)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL || key == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               INI_ENTRY *e = LIST_DATA(o, i);\r
+\r
+               if (StrCmpi(e->Key, key) == 0)\r
+               {\r
+                       return e;\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// INI ファイルを読み込む\r
+LIST *ReadIni(BUF *b)\r
+{\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       while (true)\r
+       {\r
+               char *line = CfgReadNextLine(b);\r
+\r
+               if (line == NULL)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               Trim(line);\r
+\r
+               if (IsEmptyStr(line) == false)\r
+               {\r
+                       if (StartWith(line, "#") == false &&\r
+                               StartWith(line, "//") == false &&\r
+                               StartWith(line, ";") == false)\r
+                       {\r
+                               char *key, *value;\r
+                               UINT size = StrLen(line) + 1;\r
+\r
+                               key = ZeroMalloc(size);\r
+                               value = ZeroMalloc(size);\r
+\r
+                               if (GetKeyAndValue(line, key, size, value, size, NULL))\r
+                               {\r
+                                       UINT uni_size;\r
+                                       INI_ENTRY *e = ZeroMalloc(sizeof(INI_ENTRY));\r
+                                       e->Key = CopyStr(key);\r
+                                       e->Value = CopyStr(value);\r
+\r
+                                       uni_size = CalcUtf8ToUni((BYTE *)value, StrLen(value));\r
+                                       e->UnicodeValue = ZeroMalloc(uni_size);\r
+                                       Utf8ToUni(e->UnicodeValue, uni_size, (BYTE *)value, StrLen(value));\r
+\r
+                                       Add(o, e);\r
+                               }\r
+\r
+                               Free(key);\r
+                               Free(value);\r
+                       }\r
+               }\r
+\r
+               Free(line);\r
+       }\r
+\r
+       return o;\r
+}\r
+\r
+// 指定された文字が区切り文字かどうかチェック\r
+bool IsSplitChar(char c, char *split_str)\r
+{\r
+       UINT i, len;\r
+       char c_upper = ToUpper(c);\r
+       if (split_str == NULL)\r
+       {\r
+               split_str = default_spliter;\r
+       }\r
+\r
+       len = StrLen(split_str);\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (ToUpper(split_str[i]) == c_upper)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// 文字列からキーと値を取得する\r
+bool GetKeyAndValue(char *str, char *key, UINT key_size, char *value, UINT value_size, char *split_str)\r
+{\r
+       UINT mode = 0;\r
+       UINT wp1 = 0, wp2 = 0;\r
+       UINT i, len;\r
+       char *key_tmp, *value_tmp;\r
+       bool ret = false;\r
+       if (split_str == NULL)\r
+       {\r
+               split_str = default_spliter;\r
+       }\r
+\r
+       len = StrLen(str);\r
+\r
+       key_tmp = ZeroMalloc(len + 1);\r
+       value_tmp = ZeroMalloc(len + 1);\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               char c = str[i];\r
+\r
+               switch (mode)\r
+               {\r
+               case 0:\r
+                       if (IsSplitChar(c, split_str) == false)\r
+                       {\r
+                               mode = 1;\r
+                               key_tmp[wp1] = c;\r
+                               wp1++;\r
+                       }\r
+                       break;\r
+\r
+               case 1:\r
+                       if (IsSplitChar(c, split_str) == false)\r
+                       {\r
+                               key_tmp[wp1] = c;\r
+                               wp1++;\r
+                       }\r
+                       else\r
+                       {\r
+                               mode = 2;\r
+                       }\r
+                       break;\r
+\r
+               case 2:\r
+                       if (IsSplitChar(c, split_str) == false)\r
+                       {\r
+                               mode = 3;\r
+                               value_tmp[wp2] = c;\r
+                               wp2++;\r
+                       }\r
+                       break;\r
+\r
+               case 3:\r
+                       value_tmp[wp2] = c;\r
+                       wp2++;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (mode != 0)\r
+       {\r
+               ret = true;\r
+               StrCpy(key, key_size, key_tmp);\r
+               StrCpy(value, value_size, value_tmp);\r
+       }\r
+\r
+       Free(key_tmp);\r
+       Free(value_tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// 指定した文字の列を生成する\r
+char *MakeCharArray(char c, UINT count)\r
+{\r
+       UINT i;\r
+       char *ret = Malloc(count + 1);\r
+\r
+       for (i = 0;i < count;i++)\r
+       {\r
+               ret[i] = c;\r
+       }\r
+\r
+       ret[count] = 0;\r
+\r
+       return ret;\r
+}\r
+void MakeCharArray2(char *str, char c, UINT count)\r
+{\r
+       UINT i;\r
+\r
+       for (i = 0;i < count;i++)\r
+       {\r
+               str[i] = c;\r
+       }\r
+\r
+       str[count] = 0;\r
+}\r
+\r
+// 指定した文字列の横幅を取得する\r
+UINT StrWidth(char *str)\r
+{\r
+       wchar_t *s;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       s = CopyStrToUni(str);\r
+       ret = UniStrWidth(s);\r
+       Free(s);\r
+\r
+       return ret;\r
+}\r
+\r
+// 指定した文字列がすべて大文字かどうかチェックする\r
+bool IsAllUpperStr(char *str)\r
+{\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       len = StrLen(str);\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               char c = str[i];\r
+\r
+               if ((c >= '0' && c <= '9') ||\r
+                       (c >= 'A' && c <= 'Z'))\r
+               {\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 改行コードを正規化する\r
+char *NormalizeCrlf(char *str)\r
+{\r
+       char *ret;\r
+       UINT ret_size, i, len, wp;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       ret_size = sizeof(char) * (len + 32) * 2;\r
+       ret = Malloc(ret_size);\r
+\r
+       wp = 0;\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               char c = str[i];\r
+\r
+               switch (c)\r
+               {\r
+               case '\r':\r
+                       if (str[i + 1] == '\n')\r
+                       {\r
+                               i++;\r
+                       }\r
+                       ret[wp++] = '\r';\r
+                       ret[wp++] = '\n';\r
+                       break;\r
+\r
+               case '\n':\r
+                       ret[wp++] = '\r';\r
+                       ret[wp++] = '\n';\r
+                       break;\r
+\r
+               default:\r
+                       ret[wp++] = c;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       ret[wp++] = 0;\r
+\r
+       return ret;\r
+}\r
+\r
+// トークンリストを重複の無いものに変換する\r
+TOKEN_LIST *UniqueToken(TOKEN_LIST *t)\r
+{\r
+       UINT i, num, j, n;\r
+       TOKEN_LIST *ret;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       num = 0;\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               bool exists = false;\r
+\r
+               for (j = 0;j < i;j++)\r
+               {\r
+                       if (StrCmpi(t->Token[j], t->Token[i]) == 0)\r
+                       {\r
+                               exists = true;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               if (exists == false)\r
+               {\r
+                       num++;\r
+               }\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       ret->Token = ZeroMalloc(sizeof(char *) * num);\r
+       ret->NumTokens = num;\r
+\r
+       n = 0;\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               bool exists = false;\r
+\r
+               for (j = 0;j < i;j++)\r
+               {\r
+                       if (StrCmpi(t->Token[j], t->Token[i]) == 0)\r
+                       {\r
+                               exists = true;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               if (exists == false)\r
+               {\r
+                       ret->Token[n++] = CopyStr(t->Token[i]);\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// バイト文字列に変換する (1,000 単位)\r
+void ToStrByte1000(char *str, UINT size, UINT64 v)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // gcc での警告対策\r
+       bytestr[0].base_value = 1000000000UL;\r
+       bytestr[0].base_value *= 1000UL;\r
+       bytestr[0].base_value *= 1000UL;\r
+       bytestr[1].base_value = 1000000000UL;\r
+       bytestr[1].base_value *= 1000UL;\r
+       bytestr[2].base_value = 1000000000UL;\r
+       bytestr[3].base_value = 1000000UL;\r
+       bytestr[4].base_value = 1000UL;\r
+       bytestr[5].base_value = 0UL;\r
+\r
+       for (i = 0;i < sizeof(bytestr) / sizeof(bytestr[0]);i++)\r
+       {\r
+               BYTESTR *b = &bytestr[i];\r
+\r
+               if ((v * 11UL) / 10UL >= b->base_value)\r
+               {\r
+                       if (b->base_value != 0)\r
+                       {\r
+                               double d = (double)v / (double)b->base_value;\r
+                               Format(str, size, "%.2f %s", d, b->string);\r
+                       }\r
+                       else\r
+                       {\r
+                               Format(str, size, "%I64u %s", v, b->string);\r
+                       }\r
+\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// バイト文字列に変換する\r
+void ToStrByte(char *str, UINT size, UINT64 v)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // gcc での警告対策\r
+       bytestr[0].base_value = 1073741824UL;\r
+       bytestr[0].base_value *= 1024UL;\r
+       bytestr[0].base_value *= 1024UL;\r
+       bytestr[1].base_value = 1073741824UL;\r
+       bytestr[1].base_value *= 1024UL;\r
+       bytestr[2].base_value = 1073741824UL;\r
+       bytestr[3].base_value = 1048576UL;\r
+       bytestr[4].base_value = 1024UL;\r
+       bytestr[5].base_value = 0UL;\r
+\r
+       for (i = 0;i < sizeof(bytestr) / sizeof(bytestr[0]);i++)\r
+       {\r
+               BYTESTR *b = &bytestr[i];\r
+\r
+               if ((v * 11UL) / 10UL >= b->base_value)\r
+               {\r
+                       if (b->base_value != 0)\r
+                       {\r
+                               double d = (double)v / (double)b->base_value;\r
+                               Format(str, size, "%.2f %s", d, b->string);\r
+                       }\r
+                       else\r
+                       {\r
+                               Format(str, size, "%I64u %s", v, b->string);\r
+                       }\r
+\r
+                       break;\r
+               }\r
+       }\r
+}\r
+\r
+// 数字を文字列に変換して 3 桁ずつカンマで区切る\r
+void ToStr3(char *str, UINT size, UINT64 v)\r
+{\r
+       char tmp[128];\r
+       char tmp2[128];\r
+       UINT i, len, wp;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ToStr64(tmp, v);\r
+\r
+       wp = 0;\r
+       len = StrLen(tmp);\r
+\r
+       for (i = len - 1;((int)i) >= 0;i--)\r
+       {\r
+               tmp2[wp++] = tmp[i];\r
+       }\r
+       tmp2[wp++] = 0;\r
+\r
+       wp = 0;\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (i != 0 && (i % 3) == 0)\r
+               {\r
+                       tmp[wp++] = ',';\r
+               }\r
+               tmp[wp++] = tmp2[i];\r
+       }\r
+       tmp[wp++] = 0;\r
+       wp = 0;\r
+       len = StrLen(tmp);\r
+\r
+       for (i = len - 1;((int)i) >= 0;i--)\r
+       {\r
+               tmp2[wp++] = tmp[i];\r
+       }\r
+       tmp2[wp++] = 0;\r
+\r
+       StrCpy(str, size, tmp2);\r
+}\r
+\r
+// MAC アドレスを文字列にする\r
+void MacToStr(char *str, UINT size, UCHAR *mac_address)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || mac_address == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(str, size, "%02X-%02X-%02X-%02X-%02X-%02X",\r
+               mac_address[0],\r
+               mac_address[1],\r
+               mac_address[2],\r
+               mac_address[3],\r
+               mac_address[4],\r
+               mac_address[5]);\r
+}\r
+\r
+// 文字列が空かどうか調べる\r
+bool IsEmptyStr(char *str)\r
+{\r
+       char *s;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       s = CopyStr(str);\r
+       Trim(s);\r
+\r
+       if (StrLen(s) == 0)\r
+       {\r
+               Free(s);\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               Free(s);\r
+               return false;\r
+       }\r
+}\r
+\r
+// トークンリストを文字列リストに変換する\r
+LIST *TokenListToList(TOKEN_LIST *t)\r
+{\r
+       UINT i;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               Insert(o, CopyStr(t->Token[i]));\r
+       }\r
+\r
+       return o;\r
+}\r
+\r
+// 文字列リストをトークンリストに変換する\r
+TOKEN_LIST *ListToTokenList(LIST *o)\r
+{\r
+       UINT i;\r
+       TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               t->Token[i] = CopyStr(LIST_DATA(o, i));\r
+       }\r
+\r
+       return t;\r
+}\r
+\r
+// 文字列リストを解放する\r
+void FreeStrList(LIST *o)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               char *s = LIST_DATA(o, i);\r
+               Free(s);\r
+       }\r
+\r
+       ReleaseList(o);\r
+}\r
+\r
+// 文字列リストを文字列に変換する\r
+BUF *StrListToStr(LIST *o)\r
+{\r
+       BUF *b;\r
+       UINT i;\r
+       char c;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       b = NewBuf();\r
+\r
+       for (i = 0;i < LIST_NUM(o);i++)\r
+       {\r
+               char *s = LIST_DATA(o, i);\r
+               WriteBuf(b, s, StrLen(s) + 1);\r
+       }\r
+\r
+       c = 0;\r
+       WriteBuf(b, &c, 1);\r
+\r
+       SeekBuf(b, 0, 0);\r
+\r
+       return b;\r
+}\r
+\r
+// 文字列 (NULL区切り) をリストに変換する\r
+LIST *StrToStrList(char *str, UINT size)\r
+{\r
+       LIST *o;\r
+       char *tmp;\r
+       UINT tmp_size;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       i = 0;\r
+       while (true)\r
+       {\r
+               if (i >= size)\r
+               {\r
+                       break;\r
+               }\r
+               if (*str == 0)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               tmp_size = StrSize(str);\r
+               tmp = ZeroMalloc(tmp_size);\r
+               StrCpy(tmp, tmp_size, str);\r
+               Add(o, tmp);\r
+               str += StrLen(str) + 1;\r
+               i++;\r
+       }\r
+\r
+       return o;\r
+}\r
+\r
+// 指定された文字列が数字かどうかチェック\r
+bool IsNum(char *str)\r
+{\r
+       char c;\r
+       UINT i, len;\r
+       UINT n = 0;\r
+       char tmp[MAX_SIZE];\r
+       TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), str);\r
+       Trim(tmp);\r
+\r
+       if (StrLen(tmp) == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       t = ParseToken(tmp, " ");\r
+\r
+       if (t->NumTokens >= 1)\r
+       {\r
+               StrCpy(tmp, sizeof(tmp), t->Token[0]);\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       len = StrLen(tmp);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               bool b = false;\r
+               c = tmp[i];\r
+               if (('0' <= c && c <= '9') || (c == '+') || (c == '-') || (c == ','))\r
+               {\r
+                       b = true;\r
+               }\r
+\r
+               if (b == false)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               c = tmp[i];\r
+               if (c == '-')\r
+               {\r
+                       n++;\r
+               }\r
+       }\r
+       if (n >= 2)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 中身が無いトークンリスト\r
+TOKEN_LIST *NullToken()\r
+{\r
+       TOKEN_LIST *ret = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       ret->Token = ZeroMalloc(0);\r
+\r
+       return ret;\r
+}\r
+\r
+// トークンリストのコピー\r
+TOKEN_LIST *CopyToken(TOKEN_LIST *src)\r
+{\r
+       TOKEN_LIST *ret;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       ret = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       ret->NumTokens = src->NumTokens;\r
+       ret->Token = ZeroMalloc(sizeof(char *) * ret->NumTokens);\r
+       for (i = 0;i < ret->NumTokens;i++)\r
+       {\r
+               ret->Token[i] = CopyStr(src->Token[i]);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// コマンドラインをパースする\r
+TOKEN_LIST *ParseCmdLine(char *str)\r
+{\r
+       TOKEN_LIST *t;\r
+       LIST *o;\r
+       UINT i, len, wp, mode;\r
+       char c;\r
+       char *tmp;\r
+       bool ignore_space = false;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               // トークン無し\r
+               return NullToken();\r
+       }\r
+\r
+       o = NewListFast(NULL);\r
+       tmp = Malloc(StrSize(str) + 32);\r
+\r
+       wp = 0;\r
+       mode = 0;\r
+\r
+       len = StrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               c = str[i];\r
+\r
+               switch (mode)\r
+               {\r
+               case 0:\r
+                       // 次のトークンを発見するモード\r
+                       if (c == ' ' || c == '\t')\r
+                       {\r
+                               // 次の文字へ進める\r
+                       }\r
+                       else\r
+                       {\r
+                               // トークンの開始\r
+                               if (c == '\"')\r
+                               {\r
+                                       if (str[i + 1] == '\"')\r
+                                       {\r
+                                               // 2 重の " は 1 個の " 文字として見なす\r
+                                               tmp[wp++] = '\"';\r
+                                               i++;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // 1 個の " はスペース無視フラグを有効にする\r
+                                               ignore_space = true;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       tmp[wp++] = c;\r
+                               }\r
+\r
+                               mode = 1;\r
+                       }\r
+                       break;\r
+\r
+               case 1:\r
+                       if (ignore_space == false && (c == ' ' || c == '\t'))\r
+                       {\r
+                               // トークンの終了\r
+                               tmp[wp++] = 0;\r
+                               wp = 0;\r
+\r
+                               Insert(o, CopyStr(tmp));\r
+                               mode = 0;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (c == '\"')\r
+                               {\r
+                                       if (str[i + 1] == '\"')\r
+                                       {\r
+                                               // 2 重の " は 1 個の " 文字として見なす\r
+                                               tmp[wp++] = L'\"';\r
+                                               i++;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (ignore_space == false)\r
+                                               {\r
+                                                       // 1 個の " はスペース無視フラグを有効にする\r
+                                                       ignore_space = true;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       // スペース無視フラグを無効にする\r
+                                                       ignore_space = false;\r
+                                               }\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       tmp[wp++] = c;\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (wp != 0)\r
+       {\r
+               tmp[wp++] = 0;\r
+               Insert(o, CopyStr(tmp));\r
+       }\r
+\r
+       Free(tmp);\r
+\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               t->Token[i] = LIST_DATA(o, i);\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       return t;\r
+}\r
+\r
+// 64bit 整数を文字列に変換\r
+void ToStr64(char *str, UINT64 value)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UINT wp = 0;\r
+       UINT len, i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 空文字に設定\r
+       StrCpy(tmp, 0, "");\r
+\r
+       // 末尾桁から追加する\r
+       while (true)\r
+       {\r
+               UINT a = (UINT)(value % (UINT64)10);\r
+               value = value / (UINT64)10;\r
+               tmp[wp++] = (char)('0' + a);\r
+               if (value == 0)\r
+               {\r
+                       tmp[wp++] = 0;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       // 逆順にする\r
+       len = StrLen(tmp);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               str[len - i - 1] = tmp[i];\r
+       }\r
+       str[len] = 0;\r
+}\r
+\r
+// 文字列を 64bit 整数に変換\r
+UINT64 ToInt64(char *str)\r
+{\r
+       UINT len, i;\r
+       UINT64 ret = 0;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               char c = str[i];\r
+               if (c != ',')\r
+               {\r
+                       if ('0' <= c && c <= '9')\r
+                       {\r
+                               ret = ret * (UINT64)10 + (UINT64)(c - '0');\r
+                       }\r
+                       else\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// str が key で終了するかどうかチェック\r
+bool EndWith(char *str, char *key)\r
+{\r
+       UINT str_len;\r
+       UINT key_len;\r
+       // 引数チェック\r
+       if (str == NULL || key == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 比較\r
+       str_len = StrLen(str);\r
+       key_len = StrLen(key);\r
+       if (str_len < key_len)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (StrCmpi(str + (str_len - key_len), key) == 0)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r
+\r
+// str が key で始まるかどうかチェック\r
+bool StartWith(char *str, char *key)\r
+{\r
+       UINT str_len;\r
+       UINT key_len;\r
+       char *tmp;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (str == NULL || key == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // 比較\r
+       str_len = StrLen(str);\r
+       key_len = StrLen(key);\r
+       if (str_len < key_len)\r
+       {\r
+               return false;\r
+       }\r
+       if (str_len == 0 || key_len == 0)\r
+       {\r
+               return false;\r
+       }\r
+       tmp = CopyStr(str);\r
+       tmp[key_len] = 0;\r
+\r
+       if (StrCmpi(tmp, key) == 0)\r
+       {\r
+               ret = true;\r
+       }\r
+       else\r
+       {\r
+               ret = false;\r
+       }\r
+\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// バイナリデータを表示\r
+void PrintBin(void *data, UINT size)\r
+{\r
+       char *tmp;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       i = size * 3 + 1;\r
+       tmp = Malloc(i);\r
+       BinToStrEx(tmp, i, data, size);\r
+       Print("%s\n", tmp);\r
+       Free(tmp);\r
+}\r
+\r
+// 文字列を MAC アドレスに変換する\r
+bool StrToMac(UCHAR *mac_address, char *str)\r
+{\r
+       BUF *b;\r
+       // 引数チェック\r
+       if (mac_address == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = StrToBin(str);\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (b->Size != 6)\r
+       {\r
+               FreeBuf(b);\r
+               return false;\r
+       }\r
+\r
+       Copy(mac_address, b->Buf, 6);\r
+\r
+       FreeBuf(b);\r
+\r
+       return true;\r
+}\r
+\r
+// 16 進文字列をバイナリデータに変換する\r
+BUF *StrToBin(char *str)\r
+{\r
+       BUF *b;\r
+       UINT len, i;\r
+       char tmp[3];\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       tmp[0] = 0;\r
+       b = NewBuf();\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               char c = str[i];\r
+               c = ToUpper(c);\r
+               if (('0' <= c && c <= '9') || ('A' <= c && c <= 'F'))\r
+               {\r
+                       if (tmp[0] == 0)\r
+                       {\r
+                               tmp[0] = c;\r
+                               tmp[1] = 0;\r
+                       }\r
+                       else if (tmp[1] == 0)\r
+                       {\r
+                               UCHAR data;\r
+                               char tmp2[64];\r
+                               tmp[1] = c;\r
+                               tmp[2] = 0;\r
+                               StrCpy(tmp2, sizeof(tmp2), "0x");\r
+                               StrCat(tmp2, sizeof(tmp2), tmp);\r
+                               data = (UCHAR)strtoul(tmp2, NULL, 0);\r
+                               WriteBuf(b, &data, 1);\r
+                               Zero(tmp, sizeof(tmp)); \r
+                       }\r
+               }\r
+               else if (c == ' ' || c == ',' || c == '-' || c == ':')\r
+               {\r
+                       // 何もしない\r
+               }\r
+               else\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       return b;\r
+}\r
+\r
+// バイナリデータを 16 進文字列に変換する (スペースも入れる)\r
+void BinToStrEx(char *str, UINT str_size, void *data, UINT data_size)\r
+{\r
+       char *tmp;\r
+       UCHAR *buf = (UCHAR *)data;\r
+       UINT size;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // サイズの計算\r
+       size = data_size * 3 + 1;\r
+       // メモリ確保\r
+       tmp = ZeroMalloc(size);\r
+       // 変換\r
+       for (i = 0;i < data_size;i++)\r
+       {\r
+               Format(&tmp[i * 3], 0, "%02X ", buf[i]);\r
+       }\r
+       Trim(tmp);\r
+       // コピー\r
+       StrCpy(str, str_size, tmp);\r
+       // メモリ解放\r
+       Free(tmp);\r
+}\r
+void BinToStrEx2(char *str, UINT str_size, void *data, UINT data_size, char padding_char)\r
+{\r
+       char *tmp;\r
+       UCHAR *buf = (UCHAR *)data;\r
+       UINT size;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // サイズの計算\r
+       size = data_size * 3 + 1;\r
+       // メモリ確保\r
+       tmp = ZeroMalloc(size);\r
+       // 変換\r
+       for (i = 0;i < data_size;i++)\r
+       {\r
+               Format(&tmp[i * 3], 0, "%02X%c", buf[i], padding_char);\r
+       }\r
+       if (StrLen(tmp) >= 1)\r
+       {\r
+               if (tmp[StrLen(tmp) - 1] == padding_char)\r
+               {\r
+                       tmp[StrLen(tmp) - 1] = 0;\r
+               }\r
+       }\r
+       // コピー\r
+       StrCpy(str, str_size, tmp);\r
+       // メモリ解放\r
+       Free(tmp);\r
+}\r
+// バイナリデータを文字列に変換してコピーする\r
+char *CopyBinToStrEx(void *data, UINT data_size)\r
+{\r
+       char *ret;\r
+       UINT size;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = data_size * 3 + 1;\r
+       ret = ZeroMalloc(size);\r
+\r
+       BinToStrEx(ret, size, data, data_size);\r
+\r
+       return ret;\r
+}\r
+char *CopyBinToStr(void *data, UINT data_size)\r
+{\r
+       char *ret;\r
+       UINT size;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = data_size * 2 + 1;\r
+       ret = ZeroMalloc(size);\r
+\r
+       BinToStr(ret, size, data, data_size);\r
+\r
+       return ret;\r
+}\r
+\r
+// バイナリデータを 16 進文字列に変換する\r
+void BinToStr(char *str, UINT str_size, void *data, UINT data_size)\r
+{\r
+       char *tmp;\r
+       UCHAR *buf = (UCHAR *)data;\r
+       UINT size;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str == NULL || data == NULL)\r
+       {\r
+               if (str != NULL)\r
+               {\r
+                       str[0] = 0;\r
+               }\r
+               return;\r
+       }\r
+\r
+       // サイズの計算\r
+       size = data_size * 2 + 1;\r
+       // メモリ確保\r
+       tmp = ZeroMalloc(size);\r
+       // 変換\r
+       for (i = 0;i < data_size;i++)\r
+       {\r
+               sprintf(&tmp[i * 2], "%02X", buf[i]);\r
+       }\r
+       // コピー\r
+       StrCpy(str, str_size, tmp);\r
+       // メモリ解放\r
+       Free(tmp);\r
+}\r
+void BinToStrW(wchar_t *str, UINT str_size, void *data, UINT data_size)\r
+{\r
+       char *tmp;\r
+       UINT tmp_size;\r
+       // 引数チェック\r
+       if (str == NULL || data == NULL)\r
+       {\r
+               if (str != NULL)\r
+               {\r
+                       str[0] = 0;\r
+               }\r
+               return;\r
+       }\r
+\r
+       tmp_size = (data_size * 2 + 4) * sizeof(wchar_t);\r
+       tmp = ZeroMalloc(tmp_size);\r
+\r
+       BinToStr(tmp, tmp_size, data, data_size);\r
+\r
+       StrToUni(str, str_size, tmp);\r
+\r
+       Free(tmp);\r
+}\r
+\r
+// 160 ビット列を文字列にする\r
+void Bit160ToStr(char *str, UCHAR *data)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(str, 0,\r
+               "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",\r
+               data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], \r
+               data[10], data[11], data[12], data[13], data[14], data[15], data[16], data[17], data[18], data[19]);\r
+}\r
+\r
+// 128 ビット列を文字列にする\r
+void Bit128ToStr(char *str, UCHAR *data)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(str, 0,\r
+               "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",\r
+               data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], \r
+               data[10], data[11], data[12], data[13], data[14], data[15]);\r
+}\r
+\r
+// 文字列をコピーする\r
+char *CopyStr(char *str)\r
+{\r
+       UINT len;\r
+       char *dst;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       dst = Malloc(len + 1);\r
+       StrCpy(dst, len + 1, str);\r
+       return dst;\r
+}\r
+\r
+// 安全な文字列かどうかチェック\r
+bool IsSafeStr(char *str)\r
+{\r
+       UINT i, len;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (IsSafeChar(str[i]) == false)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+       if (str[0] == ' ')\r
+       {\r
+               return false;\r
+       }\r
+       if (len != 0)\r
+       {\r
+               if (str[len - 1] == ' ')\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+       return true;\r
+}\r
+\r
+// 安全な文字かどうかチェック\r
+bool IsSafeChar(char c)\r
+{\r
+       UINT i, len;\r
+       char *check_str =\r
+               "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\r
+               "abcdefghijklmnopqrstuvwxyz"\r
+               "0123456789"\r
+               " ()-_#%&.";\r
+\r
+       len = StrLen(check_str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (c == check_str[i])\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+       return false;\r
+}\r
+\r
+// 文字列から指定した文字を削除する\r
+void TruncateCharFromStr(char *str, char replace)\r
+{\r
+       char *src,*dst;\r
+\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       src = dst = str;\r
+\r
+       while(*src != '\0')\r
+       {\r
+               if(*src != replace)\r
+               {\r
+                       *dst = *src;\r
+                       dst++;\r
+               }\r
+               src++;\r
+       }\r
+       *dst = *src;\r
+\r
+       //BUF *b = NewBuf();\r
+       //UINT i, len;\r
+       //char zero = 0;\r
+\r
+       //len = StrLen(str);\r
+       //for (i = 0;i < len;i++)\r
+       //{\r
+       //      char c = str[i];\r
+\r
+       //      if (c != replace)\r
+       //      {\r
+       //              WriteBuf(b, &c, 1);\r
+       //      }\r
+       //}\r
+\r
+       //if (b->Size == 0)\r
+       //{\r
+       //      char c = '_';\r
+       //      WriteBuf(b, &c, 1);\r
+       //}\r
+\r
+       //WriteBuf(b, &zero, 1);\r
+\r
+       //StrCpy(str, 0, b->Buf);\r
+\r
+       //FreeBuf(b);\r
+}\r
+\r
+// 安全な文字以外を置き換える\r
+void EnSafeStr(char *str, char replace)\r
+{\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while(*str != '\0')\r
+       {\r
+               if(IsSafeChar(*str) == false)\r
+               {\r
+                       *str = replace;\r
+               }\r
+               str++;\r
+       }\r
+}\r
+\r
+// 文字列ライブラリの動作チェック\r
+bool CheckStringLibrary()\r
+{\r
+       wchar_t *compare_str = L"TEST_TEST_123_123456789012345";\r
+       char *teststr = "TEST";\r
+       wchar_t *testunistr = L"TEST";\r
+       wchar_t tmp[64];\r
+       UINT i1 = 123;\r
+       UINT64 i2 = 123456789012345ULL;\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"%S_%s_%u_%I64u", teststr, testunistr,\r
+               i1, i2);\r
+\r
+       if (UniStrCmpi(tmp, compare_str) != 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 文字列ライブラリの初期化\r
+void InitStringLibrary()\r
+{\r
+       // トークン用ロックの作成\r
+       token_lock = NewLock();\r
+\r
+       // 国際ライブラリの初期化\r
+       InitInternational();\r
+\r
+       // 動作チェック\r
+       if (CheckStringLibrary() == false)\r
+       {\r
+#ifdef OS_WIN32\r
+               Alert("String Library Init Failed.\r\nPlease check your locale settings.", NULL);\r
+#else  // OS_WIN32\r
+               Alert("String Library Init Failed.\r\nPlease check your locale settings and iconv() libraries.", NULL);\r
+#endif // OS_WIN32\r
+               exit(0);\r
+       }\r
+}\r
+\r
+// 文字列ライブラリの解放\r
+void FreeStringLibrary()\r
+{\r
+       // 国際ライブラリの解放\r
+       FreeInternational();\r
+\r
+       // トークン用ロックの解放\r
+       DeleteLock(token_lock);\r
+       token_lock = NULL;\r
+}\r
+\r
+// 文字列の置換 (大文字小文字を区別しない)\r
+UINT ReplaceStri(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword)\r
+{\r
+       return ReplaceStrEx(dst, size, string, old_keyword, new_keyword, false);\r
+}\r
+\r
+// 文字列の置換 (大文字小文字を区別する)\r
+UINT ReplaceStr(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword)\r
+{\r
+       return ReplaceStrEx(dst, size, string, old_keyword, new_keyword, true);\r
+}\r
+\r
+// 文字列の置換\r
+UINT ReplaceStrEx(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword, bool case_sensitive)\r
+{\r
+       UINT i, j, num;\r
+       UINT len_string, len_old, len_new;\r
+       UINT len_ret;\r
+       UINT wp;\r
+       char *ret;\r
+       // 引数チェック\r
+       if (string == NULL || old_keyword == NULL || new_keyword == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // 文字列長の取得\r
+       len_string = StrLen(string);\r
+       len_old = StrLen(old_keyword);\r
+       len_new = StrLen(new_keyword);\r
+\r
+       // 最終文字列長の計算\r
+       len_ret = CalcReplaceStrEx(string, old_keyword, new_keyword, case_sensitive);\r
+       // メモリ確保\r
+       ret = Malloc(len_ret + 1);\r
+       ret[len_ret] = '\0';\r
+\r
+       // 検索と置換\r
+       i = 0;\r
+       j = 0;\r
+       num = 0;\r
+       wp = 0;\r
+       while (true)\r
+       {\r
+               i = SearchStrEx(string, old_keyword, i, case_sensitive);\r
+               if (i == INFINITE)\r
+               {\r
+                       Copy(ret + wp, string + j, len_string - j);\r
+                       wp += len_string - j;\r
+                       break;\r
+               }\r
+               num++;\r
+               Copy(ret + wp, string + j, i - j);\r
+               wp += i - j;\r
+               Copy(ret + wp, new_keyword, len_new);\r
+               wp += len_new;\r
+               i += len_old;\r
+               j = i;\r
+       }\r
+\r
+       // 検索結果のコピー\r
+       StrCpy(dst, size, ret);\r
+\r
+       // メモリ解放\r
+       Free(ret);\r
+\r
+       return num;\r
+}\r
+\r
+// 文字列の置換後の文字列長を計算する\r
+UINT CalcReplaceStrEx(char *string, char *old_keyword, char *new_keyword, bool case_sensitive)\r
+{\r
+       UINT i, num;\r
+       UINT len_string, len_old, len_new;\r
+       // 引数チェック\r
+       if (string == NULL || old_keyword == NULL || new_keyword == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // 文字列長の取得\r
+       len_string = StrLen(string);\r
+       len_old = StrLen(old_keyword);\r
+       len_new = StrLen(new_keyword);\r
+\r
+       if (len_old == len_new)\r
+       {\r
+               return len_string;\r
+       }\r
+\r
+       // 検索処理\r
+       num = 0;\r
+       i = 0;\r
+       while (true)\r
+       {\r
+               i = SearchStrEx(string, old_keyword, i, case_sensitive);\r
+               if (i == INFINITE)\r
+               {\r
+                       break;\r
+               }\r
+               i += len_old;\r
+               num++;\r
+       }\r
+\r
+       // 計算\r
+       return len_string + len_new * num - len_old * num;\r
+}\r
+\r
+// 文字列の検索 (大文字 / 小文字を区別する)\r
+UINT SearchStr(char *string, char *keyword, UINT start)\r
+{\r
+       return SearchStrEx(string, keyword, start, true);\r
+}\r
+\r
+// 文字列の検索 (大文字 / 小文字を区別しない)\r
+UINT SearchStri(char *string, char *keyword, UINT start)\r
+{\r
+       return SearchStrEx(string, keyword, start, false);\r
+}\r
+\r
+// 文字列 string から文字列 keyword を検索して最初に見つかった文字の場所を返す\r
+// (1文字目に見つかったら 0, 見つからなかったら INFINITE)\r
+UINT SearchStrEx(char *string, char *keyword, UINT start, bool case_sensitive)\r
+{\r
+       UINT len_string, len_keyword;\r
+       UINT i;\r
+       char *cmp_string, *cmp_keyword;\r
+       bool found;\r
+       // 引数チェック\r
+       if (string == NULL || keyword == NULL)\r
+       {\r
+               return INFINITE;\r
+       }\r
+\r
+       // string の長さを取得\r
+       len_string = StrLen(string);\r
+       if (len_string <= start)\r
+       {\r
+               // start の値が不正\r
+               return INFINITE;\r
+       }\r
+\r
+       // keyword の長さを取得\r
+       len_keyword = StrLen(keyword);\r
+       if (len_keyword == 0)\r
+       {\r
+               // キーワードが無い\r
+               return INFINITE;\r
+       }\r
+\r
+       if ((len_string - start) < len_keyword)\r
+       {\r
+               // キーワードの長さのほうが長い\r
+               return INFINITE;\r
+       }\r
+\r
+       if (case_sensitive)\r
+       {\r
+               cmp_string = string;\r
+               cmp_keyword = keyword;\r
+       }\r
+       else\r
+       {\r
+               cmp_string = Malloc(len_string + 1);\r
+               StrCpy(cmp_string, len_string + 1, string);\r
+               cmp_keyword = Malloc(len_keyword + 1);\r
+               StrCpy(cmp_keyword, len_keyword + 1, keyword);\r
+               StrUpper(cmp_string);\r
+               StrUpper(cmp_keyword);\r
+       }\r
+\r
+       // 検索\r
+       found = false;\r
+       for (i = start;i < (len_string - len_keyword + 1);i++)\r
+       {\r
+               // 比較する\r
+               if (!strncmp(&cmp_string[i], cmp_keyword, len_keyword))\r
+               {\r
+                       // 発見した\r
+                       found = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (case_sensitive == false)\r
+       {\r
+               // メモリ解放\r
+               Free(cmp_keyword);\r
+               Free(cmp_string);\r
+       }\r
+\r
+       if (found == false)\r
+       {\r
+               return INFINITE;\r
+       }\r
+       return i;\r
+}\r
+\r
+// 指定した文字がトークンリスト内にあるかどうか調べる\r
+bool IsInToken(TOKEN_LIST *t, char *str)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (t == NULL || str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               if (StrCmpi(t->Token[i], str) == 0)\r
+               {\r
+                       return true;\r
+               }\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// トークンリストの解放\r
+void FreeToken(TOKEN_LIST *tokens)\r
+{\r
+       UINT i;\r
+       if (tokens == NULL)\r
+       {\r
+               return;\r
+       }\r
+       for (i = 0;i < tokens->NumTokens;i++)\r
+       {\r
+               if (tokens->Token[i] != 0)\r
+               {\r
+                       Free(tokens->Token[i]);\r
+               }\r
+       }\r
+       Free(tokens->Token);\r
+       Free(tokens);\r
+}\r
+\r
+// トークンのパース\r
+TOKEN_LIST *ParseToken(char *src, char *separator)\r
+{\r
+       TOKEN_LIST *ret;\r
+       char *tmp;\r
+       char *str1, *str2;\r
+       UINT len;\r
+       UINT num;\r
+       if (src == NULL)\r
+       {\r
+               ret = ZeroMalloc(sizeof(TOKEN_LIST));\r
+               ret->Token = ZeroMalloc(0);\r
+               return ret;\r
+       }\r
+       if (separator == NULL)\r
+       {\r
+               separator = " ,\t\r\n";\r
+       }\r
+       len = StrLen(src);\r
+       str1 = Malloc(len + 1);\r
+       str2 = Malloc(len + 1);\r
+       StrCpy(str1, 0, src);\r
+       StrCpy(str2, 0, src);\r
+\r
+       Lock(token_lock);\r
+       {\r
+               tmp = strtok(str1, separator);\r
+               num = 0;\r
+               while (tmp != NULL)\r
+               {\r
+                       num++;\r
+                       tmp = strtok(NULL, separator);\r
+               }\r
+               ret = Malloc(sizeof(TOKEN_LIST));\r
+               ret->NumTokens = num;\r
+               ret->Token = (char **)Malloc(sizeof(char *) * num);\r
+               num = 0;\r
+               tmp = strtok(str2, separator);\r
+               while (tmp != NULL)\r
+               {\r
+                       ret->Token[num] = (char *)Malloc(StrLen(tmp) + 1);\r
+                       StrCpy(ret->Token[num], 0, tmp);\r
+                       num++;\r
+                       tmp = strtok(NULL, separator);\r
+               }\r
+       }\r
+       Unlock(token_lock);\r
+\r
+       Free(str1);\r
+       Free(str2);\r
+       return ret;\r
+}\r
+\r
+// 1 行を標準入力から取得\r
+bool GetLine(char *str, UINT size)\r
+{\r
+       bool ret;\r
+       wchar_t *unistr;\r
+       UINT unistr_size = (size + 1) * sizeof(wchar_t);\r
+\r
+       unistr = Malloc(unistr_size);\r
+\r
+       ret = UniGetLine(unistr, unistr_size);\r
+\r
+       UniToStr(str, size, unistr);\r
+\r
+       Free(unistr);\r
+\r
+       return ret;\r
+}\r
+\r
+// 末尾の \r \n を削除\r
+void TrimCrlf(char *str)\r
+{\r
+       UINT len;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+       len = StrLen(str);\r
+       if (len == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (str[len - 1] == '\n')\r
+       {\r
+               if (len >= 2 && str[len - 2] == '\r')\r
+               {\r
+                       str[len - 2] = 0;\r
+               }\r
+               str[len - 1] = 0;\r
+       }\r
+       else if (str[len - 1] == '\r')\r
+       {\r
+               str[len - 1] = 0;\r
+       }\r
+}\r
+\r
+// 文字列の左右の空白を削除\r
+void Trim(char *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 左側を trim\r
+       TrimLeft(str);\r
+\r
+       // 右側を trim\r
+       TrimRight(str);\r
+}\r
+\r
+// 文字列の右側の空白を削除\r
+void TrimRight(char *str)\r
+{\r
+       char *buf, *tmp;\r
+       UINT len, i, wp, wp2;\r
+       BOOL flag;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+       len = StrLen(str);\r
+       if (len == 0)\r
+       {\r
+               return;\r
+       }\r
+       if (str[len - 1] != ' ' && str[len - 1] != '\t')\r
+       {\r
+               return;\r
+       }\r
+\r
+       buf = Malloc(len + 1);\r
+       tmp = Malloc(len + 1);\r
+       flag = FALSE;\r
+       wp = 0;\r
+       wp2 = 0;\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (str[i] != ' ' && str[i] != '\t')\r
+               {\r
+                       Copy(buf + wp, tmp, wp2);\r
+                       wp += wp2;\r
+                       wp2 = 0;\r
+                       buf[wp++] = str[i];\r
+               }\r
+               else\r
+               {\r
+                       tmp[wp2++] = str[i];\r
+               }\r
+       }\r
+       buf[wp] = 0;\r
+       StrCpy(str, 0, buf);\r
+       Free(buf);\r
+       Free(tmp);\r
+}\r
+\r
+// 文字列の左側の空白を削除\r
+void TrimLeft(char *str)\r
+{\r
+       char *buf;\r
+       UINT len, i, wp;\r
+       BOOL flag;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+       len = StrLen(str);\r
+       if (len == 0)\r
+       {\r
+               return;\r
+       }\r
+       if (str[0] != ' ' && str[0] != '\t')\r
+       {\r
+               return;\r
+       }\r
+\r
+       buf = Malloc(len + 1);\r
+       flag = FALSE;\r
+       wp = 0;\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (str[i] != ' ' && str[i] != '\t')\r
+               {\r
+                       flag = TRUE;\r
+               }\r
+               if (flag)\r
+               {\r
+                       buf[wp++] = str[i];\r
+               }\r
+       }\r
+       buf[wp] = 0;\r
+       StrCpy(str, 0, buf);\r
+       Free(buf);\r
+}\r
+\r
+// 整数を 16 進文字列に変換 (8桁固定)\r
+void ToStrx8(char *str, UINT i)\r
+{\r
+       sprintf(str, "0x%08x", i);\r
+}\r
+\r
+// 整数を 16 進文字列に変換\r
+void ToStrx(char *str, UINT i)\r
+{\r
+       sprintf(str, "0x%02x", i);\r
+}\r
+\r
+// 符号付整数を文字列に変換\r
+void ToStri(char *str, int i)\r
+{\r
+       sprintf(str, "%i", i);\r
+}\r
+\r
+// 整数を文字列に変換\r
+void ToStr(char *str, UINT i)\r
+{\r
+       sprintf(str, "%u", i);\r
+}\r
+\r
+// 文字列を符号付整数に変換\r
+int ToInti(char *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return (int)ToInt(str);\r
+}\r
+\r
+// 文字列を bool に変換\r
+bool ToBool(char *str)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), str);\r
+       Trim(tmp);\r
+\r
+       if (IsEmptyStr(tmp))\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (ToInt(tmp) != 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (StartWith("true", tmp))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (StartWith("yes", tmp))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (StartWith(tmp, "true"))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (StartWith(tmp, "yes"))\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+\r
+// 文字列を整数に変換\r
+UINT ToInt(char *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // 8 進数表記を無視する\r
+       while (true)\r
+       {\r
+               if (*str != '0')\r
+               {\r
+                       break;\r
+               }\r
+               if ((*(str + 1) == 'x') || (*(str + 1) == 'X'))\r
+               {\r
+                       break;\r
+               }\r
+               str++;\r
+       }\r
+\r
+       return (UINT)strtoul(str, NULL, 0);\r
+}\r
+\r
+// 64bit 整数のためのフォーマット文字列を置換する\r
+char *ReplaceFormatStringFor64(char *fmt)\r
+{\r
+       char *tmp;\r
+       char *ret;\r
+       UINT tmp_size;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       tmp_size = StrSize(fmt) * 2;\r
+       tmp = ZeroMalloc(tmp_size);\r
+\r
+#ifdef OS_WIN32\r
+       ReplaceStrEx(tmp, tmp_size, fmt, "%ll", "%I64", false);\r
+#else  // OS_WIN32\r
+       ReplaceStrEx(tmp, tmp_size, fmt, "%I64", "%ll", false);\r
+#endif // OS_WIN32\r
+\r
+       ret = CopyStr(tmp);\r
+       Free(tmp);\r
+\r
+       return ret;\r
+}\r
+\r
+// 文字列を画面に表示する\r
+void PrintStr(char *str)\r
+{\r
+       wchar_t *unistr = NULL;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_UNIX\r
+       fputs(str, stdout);\r
+#else  // OS_UNIX\r
+       unistr = CopyStrToUni(str);\r
+       UniPrintStr(unistr);\r
+       Free(unistr);\r
+#endif // OS_UNIX\r
+}\r
+\r
+// 文字列を引数付きで表示する\r
+void PrintArgs(char *fmt, va_list args)\r
+{\r
+       wchar_t *ret;\r
+       wchar_t *fmt_wchar;\r
+       char *tmp;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       fmt_wchar = CopyStrToUni(fmt);\r
+       ret = InternalFormatArgs(fmt_wchar, args, true);\r
+\r
+       tmp = CopyUniToStr(ret);\r
+       PrintStr(tmp);\r
+       Free(tmp);\r
+\r
+       Free(ret);\r
+       Free(fmt_wchar);\r
+}\r
+\r
+// 文字列を表示する\r
+void Print(char *fmt, ...)\r
+{\r
+       va_list args;\r
+       if (fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, fmt);\r
+       PrintArgs(fmt, args);\r
+       va_end(args);\r
+}\r
+\r
+// デバッグ文字列を引数付きで表示する\r
+void DebugArgs(char *fmt, va_list args)\r
+{\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (g_debug == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       PrintArgs(fmt, args);\r
+}\r
+\r
+// デバッグ文字列を表示する\r
+void Debug(char *fmt, ...)\r
+{\r
+       va_list args;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+       if (g_debug == false)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, fmt);\r
+\r
+       DebugArgs(fmt, args);\r
+\r
+       va_end(args);\r
+}\r
+\r
+// 文字列をフォーマットして結果を返す\r
+char *CopyFormat(char *fmt, ...)\r
+{\r
+       char *buf;\r
+       char *ret;\r
+       UINT size;\r
+       va_list args;\r
+       // 引数チェック\r
+       if (fmt == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       size = MAX(StrSize(fmt) * 10, MAX_SIZE * 10);\r
+       buf = Malloc(size);\r
+\r
+       va_start(args, fmt);\r
+       FormatArgs(buf, size, fmt, args);\r
+\r
+       ret = CopyStr(buf);\r
+       Free(buf);\r
+\r
+       va_end(args);\r
+       return ret;\r
+}\r
+\r
+// 文字列をフォーマットする\r
+void Format(char *buf, UINT size, char *fmt, ...)\r
+{\r
+       va_list args;\r
+       // 引数チェック\r
+       if (buf == NULL || fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       va_start(args, fmt);\r
+       FormatArgs(buf, size, fmt, args);\r
+       va_end(args);\r
+}\r
+\r
+// 文字列をフォーマットする (引数リスト)\r
+void FormatArgs(char *buf, UINT size, char *fmt, va_list args)\r
+{\r
+       wchar_t *tag;\r
+       wchar_t *ret;\r
+       // 引数チェック\r
+       if (buf == NULL || fmt == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       tag = CopyStrToUni(fmt);\r
+       ret = InternalFormatArgs(tag, args, true);\r
+\r
+       UniToStr(buf, size, ret);\r
+       Free(ret);\r
+       Free(tag);\r
+}\r
+\r
+// 文字列を大文字・小文字を区別せずに比較する\r
+int StrCmpi(char *str1, char *str2)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str1 == NULL && str2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (str1 == NULL)\r
+       {\r
+               return 1;\r
+       }\r
+       if (str2 == NULL)\r
+       {\r
+               return -1;\r
+       }\r
+\r
+       // 文字列比較\r
+       i = 0;\r
+       while (true)\r
+       {\r
+               char c1, c2;\r
+               c1 = ToUpper(str1[i]);\r
+               c2 = ToUpper(str2[i]);\r
+               if (c1 > c2)\r
+               {\r
+                       return 1;\r
+               }\r
+               else if (c1 < c2)\r
+               {\r
+                       return -1;\r
+               }\r
+               if (str1[i] == 0 || str2[i] == 0)\r
+               {\r
+                       return 0;\r
+               }\r
+               i++;\r
+       }\r
+}\r
+\r
+// 文字列を比較する\r
+int StrCmp(char *str1, char *str2)\r
+{\r
+       // 引数チェック\r
+       if (str1 == NULL && str2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (str1 == NULL)\r
+       {\r
+               return 1;\r
+       }\r
+       if (str2 == NULL)\r
+       {\r
+               return -1;\r
+       }\r
+\r
+       return strcmp(str1, str2);\r
+}\r
+\r
+// 文字列を小文字にする\r
+void StrLower(char *str)\r
+{\r
+       UINT len, i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               str[i] = ToLower(str[i]);\r
+       }\r
+}\r
+\r
+// 文字列を大文字にする\r
+void StrUpper(char *str)\r
+{\r
+       UINT len, i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       len = StrLen(str);\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               str[i] = ToUpper(str[i]);\r
+       }\r
+}\r
+\r
+// 文字を小文字にする\r
+char ToLower(char c)\r
+{\r
+       if ('A' <= c && c <= 'Z')\r
+       {\r
+               c += 'z' - 'Z';\r
+       }\r
+       return c;\r
+}\r
+\r
+// 文字を大文字にする\r
+char ToUpper(char c)\r
+{\r
+       if ('a' <= c && c <= 'z')\r
+       {\r
+               c += 'Z' - 'z';\r
+       }\r
+       return c;\r
+}\r
+\r
+// 文字列を結合\r
+UINT StrCat(char *dst, UINT size, char *src)\r
+{\r
+       UINT len1, len2, len_test;\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_STRCAT_COUNT);\r
+\r
+       if (size == 0)\r
+       {\r
+               // 長さを無視\r
+               size = 0x7fffffff;\r
+       }\r
+\r
+       len1 = StrLen(dst);\r
+       len2 = StrLen(src);\r
+       len_test = len1 + len2 + 1;\r
+       if (len_test > size)\r
+       {\r
+               if (len2 <= (len_test - size))\r
+               {\r
+                       return 0;\r
+               }\r
+               len2 -= len_test - size;\r
+       }\r
+       Copy(dst + len1, src, len2);\r
+       dst[len1 + len2] = 0;\r
+\r
+       return len1 + len2;\r
+}\r
+UINT StrCatLeft(char *dst, UINT size, char *src)\r
+{\r
+       char *s;\r
+       // 引数チェック\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       s = CopyStr(dst);\r
+       StrCpy(dst, size, src);\r
+       StrCat(dst, size, s);\r
+\r
+       Free(s);\r
+\r
+       return StrLen(dst);\r
+}\r
+\r
+// 文字列をコピー\r
+UINT StrCpy(char *dst, UINT size, char *src)\r
+{\r
+       UINT len;\r
+       // 引数チェック\r
+       if (dst == src)\r
+       {\r
+               return StrLen(src);\r
+       }\r
+       if (dst == NULL || src == NULL)\r
+       {\r
+               if (src == NULL && dst != NULL)\r
+               {\r
+                       if (size >= 1)\r
+                       {\r
+                               dst[0] = '\0';\r
+                       }\r
+               }\r
+               return 0;\r
+       }\r
+       if (size == 1)\r
+       {\r
+               dst[0] = '\0';\r
+               return 0;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               // 長さを無視\r
+               size = 0x7fffffff;\r
+       }\r
+\r
+       // 長さをチェック\r
+       len = StrLen(src);\r
+       if (len <= (size - 1))\r
+       {\r
+               Copy(dst, src, len + 1);\r
+       }\r
+       else\r
+       {\r
+               len = size - 1;\r
+               Copy(dst, src, len);\r
+               dst[len] = '\0';\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_STRCPY_COUNT);\r
+\r
+       return len;\r
+}\r
+\r
+// 文字列バッファが指定されたサイズに収まっているかどうかを確認\r
+bool StrCheckSize(char *str, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL || size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return StrCheckLen(str, size - 1);\r
+}\r
+\r
+// 文字列が指定された長さ以内であることを確認\r
+bool StrCheckLen(char *str, UINT len)\r
+{\r
+       UINT count = 0;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_STRCHECK_COUNT);\r
+\r
+       for (i = 0;;i++)\r
+       {\r
+               if (str[i] == '\0')\r
+               {\r
+                       return true;\r
+               }\r
+               count++;\r
+               if (count > len)\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+}\r
+\r
+// 文字列を格納するために必要なメモリサイズを取得\r
+UINT StrSize(char *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrLen(str) + 1;\r
+}\r
+\r
+// 文字列の長さを取得\r
+UINT StrLen(char *str)\r
+{\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       // KS\r
+       KS_INC(KS_STRLEN_COUNT);\r
+\r
+       return (UINT)strlen(str);\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Str.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Str.h
new file mode 100644 (file)
index 0000000..68a772a
--- /dev/null
@@ -0,0 +1,209 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Str.h\r
+// Str.c のヘッダ\r
+\r
+#ifndef        STR_H\r
+#define        STR_H\r
+\r
+// 文字列トークン\r
+struct TOKEN_LIST\r
+{\r
+       UINT NumTokens;\r
+       char **Token;\r
+};\r
+\r
+// INI_ENTRY\r
+struct INI_ENTRY\r
+{\r
+       char *Key;\r
+       char *Value;\r
+       wchar_t *UnicodeValue;\r
+};\r
+\r
+// 関数プロトタイプ\r
+UINT StrLen(char *str);\r
+UINT StrSize(char *str);\r
+bool StrCheckLen(char *str, UINT len);\r
+bool StrCheckSize(char *str, UINT size);\r
+UINT StrCpy(char *dst, UINT size, char *src);\r
+UINT StrCat(char *dst, UINT size, char *src);\r
+UINT StrCatLeft(char *dst, UINT size, char *src);\r
+char ToLower(char c);\r
+char ToUpper(char c);\r
+void StrUpper(char *str);\r
+void StrLower(char *str);\r
+int StrCmp(char *str1, char *str2);\r
+int StrCmpi(char *str1, char *str2);\r
+void FormatArgs(char *buf, UINT size, char *fmt, va_list args);\r
+void Format(char *buf, UINT size, char *fmt, ...);\r
+char *CopyFormat(char *fmt, ...);\r
+void Print(char *fmt, ...);\r
+void PrintArgs(char *fmt, va_list args);\r
+void PrintStr(char *str);\r
+void Debug(char *fmt, ...);\r
+void DebugArgs(char *fmt, va_list args);\r
+UINT ToInt(char *str);\r
+bool ToBool(char *str);\r
+int ToInti(char *str);\r
+void ToStr(char *str, UINT i);\r
+void ToStri(char *str, int i);\r
+void ToStrx(char *str, UINT i);\r
+void ToStrx8(char *str, UINT i);\r
+void TrimCrlf(char *str);\r
+void Trim(char *str);\r
+void TrimRight(char *str);\r
+void TrimLeft(char *str);\r
+bool GetLine(char *str, UINT size);\r
+void FreeToken(TOKEN_LIST *tokens);\r
+bool IsInToken(TOKEN_LIST *t, char *str);\r
+TOKEN_LIST *ParseToken(char *src, char *separator);\r
+void InitStringLibrary();\r
+void FreeStringLibrary();\r
+bool CheckStringLibrary();\r
+UINT SearchStrEx(char *string, char *keyword, UINT start, bool case_sensitive);\r
+UINT SearchStri(char *string, char *keyword, UINT start);\r
+UINT SearchStr(char *string, char *keyword, UINT start);\r
+UINT CalcReplaceStrEx(char *string, char *old_keyword, char *new_keyword, bool case_sensitive);\r
+UINT ReplaceStrEx(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword, bool case_sensitive);\r
+UINT ReplaceStr(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword);\r
+UINT ReplaceStri(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword);\r
+bool IsSafeChar(char c);\r
+bool IsSafeStr(char *str);\r
+void EnSafeStr(char *str, char replace);\r
+void TruncateCharFromStr(char *str, char replace);\r
+char *CopyStr(char *str);\r
+void BinToStr(char *str, UINT str_size, void *data, UINT data_size);\r
+void BinToStrW(wchar_t *str, UINT str_size, void *data, UINT data_size);\r
+void PrintBin(void *data, UINT size);\r
+bool StartWith(char *str, char *key);\r
+bool EndWith(char *str, char *key);\r
+UINT64 ToInt64(char *str);\r
+void ToStr64(char *str, UINT64 value);\r
+char *ReplaceFormatStringFor64(char *fmt);\r
+TOKEN_LIST *ParseCmdLine(char *str);\r
+TOKEN_LIST *CopyToken(TOKEN_LIST *src);\r
+TOKEN_LIST *NullToken();\r
+bool IsNum(char *str);\r
+LIST *StrToStrList(char *str, UINT size);\r
+BUF *StrListToStr(LIST *o);\r
+void FreeStrList(LIST *o);\r
+TOKEN_LIST *ListToTokenList(LIST *o);\r
+LIST *TokenListToList(TOKEN_LIST *t);\r
+bool IsEmptyStr(char *str);\r
+void BinToStrEx(char *str, UINT str_size, void *data, UINT data_size);\r
+void BinToStrEx2(char *str, UINT str_size, void *data, UINT data_size, char padding_char);\r
+char *CopyBinToStrEx(void *data, UINT data_size);\r
+char *CopyBinToStr(void *data, UINT data_size);\r
+BUF *StrToBin(char *str);\r
+void MacToStr(char *str, UINT size, UCHAR *mac_address);\r
+void ToStr3(char *str, UINT size, UINT64 v);\r
+void ToStrByte(char *str, UINT size, UINT64 v);\r
+void ToStrByte1000(char *str, UINT size, UINT64 v);\r
+TOKEN_LIST *UniqueToken(TOKEN_LIST *t);\r
+char *NormalizeCrlf(char *str);\r
+bool IsAllUpperStr(char *str);\r
+UINT StrWidth(char *str);\r
+char *MakeCharArray(char c, UINT count);\r
+void MakeCharArray2(char *str, char c, UINT count);\r
+bool StrToMac(UCHAR *mac_address, char *str);\r
+bool IsSplitChar(char c, char *split_str);\r
+bool GetKeyAndValue(char *str, char *key, UINT key_size, char *value, UINT value_size, char *split_str);\r
+LIST *ReadIni(BUF *b);\r
+INI_ENTRY *GetIniEntry(LIST *o, char *key);\r
+void FreeIni(LIST *o);\r
+UINT IniIntValue(LIST *o, char *key);\r
+UINT64 IniInt64Value(LIST *o, char *key);\r
+char *IniStrValue(LIST *o, char *key);\r
+wchar_t *IniUniStrValue(LIST *o, char *key);\r
+bool InStr(char *str, char *keyword);\r
+bool InStrEx(char *str, char *keyword, bool case_sensitive);\r
+TOKEN_LIST *ParseTokenWithoutNullStr(char *str, char *split_chars);\r
+TOKEN_LIST *ParseTokenWithNullStr(char *str, char *split_chars);\r
+char *DefaultTokenSplitChars();\r
+bool IsCharInStr(char *str, char c);\r
+UINT HexTo4Bit(char c);\r
+char FourBitToHex(UINT value);\r
+void ToHex(char *str, UINT value);\r
+void ToHex64(char *str, UINT64 value);\r
+UINT HexToInt(char *str);\r
+UINT64 HexToInt64(char *str);\r
+\r
+\r
+#endif // STR_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Table.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Table.c
new file mode 100644 (file)
index 0000000..1735784
--- /dev/null
@@ -0,0 +1,865 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Table.c\r
+// 文字列テーブル読み込み & 管理ルーチン\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+// TABLE のリスト\r
+static LIST *TableList = NULL;\r
+static wchar_t old_table_name[MAX_SIZE] = {0};         // 古いテーブル名\r
+\r
+// エラー文字列を Unicode で取得する\r
+wchar_t *GetUniErrorStr(UINT err)\r
+{\r
+       wchar_t *ret;\r
+       char name[MAX_SIZE];\r
+       Format(name, sizeof(name), "ERR_%u", err);\r
+\r
+       ret = GetTableUniStr(name);\r
+       if (UniStrLen(ret) != 0)\r
+       {\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               return _UU("ERR_UNKNOWN");\r
+       }\r
+}\r
+\r
+// エラー文字列を取得する\r
+char *GetErrorStr(UINT err)\r
+{\r
+       char *ret;\r
+       char name[MAX_SIZE];\r
+       Format(name, sizeof(name), "ERR_%u", err);\r
+\r
+       ret = GetTableStr(name);\r
+       if (StrLen(ret) != 0)\r
+       {\r
+               return ret;\r
+       }\r
+       else\r
+       {\r
+               return _SS("ERR_UNKNOWN");\r
+       }\r
+}\r
+\r
+// テーブルから整数値をロードする\r
+UINT GetTableInt(char *name)\r
+{\r
+       char *str;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       str = GetTableStr(name);\r
+       return ToInt(str);\r
+}\r
+\r
+// テーブルから Unicode 文字列をロードする\r
+wchar_t *GetTableUniStr(char *name)\r
+{\r
+       TABLE *t;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+//             Debug("%s: ************\n", name);\r
+               return L"";\r
+       }\r
+\r
+       // 検索\r
+       t = FindTable(name);\r
+       if (t == NULL)\r
+       {\r
+//             Debug("%s: UNICODE STRING NOT FOUND\n", name);\r
+               return L"";\r
+       }\r
+\r
+       return t->unistr;\r
+}\r
+\r
+// テーブルから文字列をロードする\r
+char *GetTableStr(char *name)\r
+{\r
+       TABLE *t;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return "";\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       if (StrCmpi(name, "DEFAULT_FONT") == 0)\r
+       {\r
+               if (_II("LANG") == 2)\r
+               {\r
+                       UINT os_type = GetOsType();\r
+                       if (OS_IS_WINDOWS_9X(os_type) ||\r
+                               GET_KETA(os_type, 100) <= 4)\r
+                       {\r
+                               // Windows 9x, Windows NT 4.0, Windows 2000, Windows XP, Windows Server 2003 の場合は SimSun フォントを利用する\r
+                               return "SimSun";\r
+                       }\r
+               }\r
+       }\r
+#endif // OS_WIN32\r
+\r
+       // 検索\r
+       t = FindTable(name);\r
+       if (t == NULL)\r
+       {\r
+//             Debug("%s: ANSI STRING NOT FOUND\n", name);\r
+               return "";\r
+       }\r
+\r
+       return t->str;\r
+}\r
+\r
+// 指定した名前で始まる文字列名を取得する\r
+TOKEN_LIST *GetTableNameStartWith(char *str)\r
+{\r
+       UINT i;\r
+       UINT len;\r
+       LIST *o;\r
+       TOKEN_LIST *t;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return NullToken();\r
+       }\r
+\r
+       StrCpy(tmp, sizeof(tmp), str);\r
+       StrUpper(tmp);\r
+\r
+       len = StrLen(tmp);\r
+\r
+       o = NewListFast(NULL);\r
+\r
+       for (i = 0;i < LIST_NUM(TableList);i++)\r
+       {\r
+               TABLE *t = LIST_DATA(TableList, i);\r
+               UINT len2 = StrLen(t->name);\r
+\r
+               if (len2 >= len)\r
+               {\r
+                       if (Cmp(t->name, tmp, len) == 0)\r
+                       {\r
+                               Insert(o, CopyStr(t->name));\r
+                       }\r
+               }\r
+       }\r
+\r
+       t = ZeroMalloc(sizeof(TOKEN_LIST));\r
+       t->NumTokens = LIST_NUM(o);\r
+       t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);\r
+\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               t->Token[i] = LIST_DATA(o, i);\r
+       }\r
+\r
+       ReleaseList(o);\r
+\r
+       return t;\r
+}\r
+\r
+// テーブルを検索する\r
+TABLE *FindTable(char *name)\r
+{\r
+       TABLE *t, tt;\r
+       // 引数チェック\r
+       if (name == NULL || TableList == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       tt.name = CopyStr(name);\r
+       t = Search(TableList, &tt);\r
+       Free(tt.name);\r
+\r
+       return t;\r
+}\r
+\r
+// テーブル名を比較する関数\r
+int CmpTableName(void *p1, void *p2)\r
+{\r
+       TABLE *t1, *t2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       t1 = *(TABLE **)p1;\r
+       t2 = *(TABLE **)p2;\r
+       if (t1 == NULL || t2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return StrCmpi(t1->name, t2->name);\r
+}\r
+\r
+// 1 行を解釈する\r
+TABLE *ParseTableLine(char *line, char *prefix, UINT prefix_size)\r
+{\r
+       UINT i, len;\r
+       UINT len_name;\r
+       UINT string_start;\r
+       char *name;\r
+       char *name2;\r
+       UINT name2_size;\r
+       wchar_t *unistr;\r
+       char *str;\r
+       UINT unistr_size, str_size;\r
+       TABLE *t;\r
+       // 引数チェック\r
+       if (line == NULL || prefix == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+       TrimLeft(line);\r
+\r
+       // 行無し\r
+       len = StrLen(line);\r
+       if (len == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // コメント\r
+       if (line[0] == '#' || (line[0] == '/' && line[1] == '/'))\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // 名前の終了位置まで検索\r
+       len_name = 0;\r
+       for (i = 0;;i++)\r
+       {\r
+               if (line[i] == 0)\r
+               {\r
+                       // トークンが 1 つしか無い\r
+                       return NULL;\r
+               }\r
+               if (line[i] == ' ' || line[i] == '\t')\r
+               {\r
+                       break;\r
+               }\r
+               len_name++;\r
+       }\r
+\r
+       name = Malloc(len_name + 1);\r
+       StrCpy(name, len_name + 1, line);\r
+\r
+       string_start = len_name;\r
+       for (i = len_name;i < len;i++)\r
+       {\r
+               if (line[i] != ' ' && line[i] != '\t')\r
+               {\r
+                       break;\r
+               }\r
+               string_start++;\r
+       }\r
+       if (i == len)\r
+       {\r
+               Free(name);\r
+               return NULL;\r
+       }\r
+\r
+       // アンエスケープ\r
+       UnescapeStr(&line[string_start]);\r
+\r
+       // Unicode に変換する\r
+       unistr_size = CalcUtf8ToUni(&line[string_start], StrLen(&line[string_start]));\r
+       if (unistr_size == 0)\r
+       {\r
+               Free(name);\r
+               return NULL;\r
+       }\r
+       unistr = Malloc(unistr_size);\r
+       Utf8ToUni(unistr, unistr_size, &line[string_start], StrLen(&line[string_start]));\r
+\r
+       // ANSI に変換する\r
+       str_size = CalcUniToStr(unistr);\r
+       if (str_size == 0)\r
+       {\r
+               str_size = 1;\r
+               str = Malloc(1);\r
+               str[0] = 0;\r
+       }\r
+       else\r
+       {\r
+               str = Malloc(str_size);\r
+               UniToStr(str, str_size, unistr);\r
+       }\r
+\r
+       if (StrCmpi(name, "PREFIX") == 0)\r
+       {\r
+               // プレフィックスが指定された\r
+               StrCpy(prefix, prefix_size, str);\r
+               Trim(prefix);\r
+\r
+               if (StrCmpi(prefix, "$") == 0 || StrCmpi(prefix, "NULL") == 0)\r
+               {\r
+                       prefix[0] = 0;\r
+               }\r
+\r
+               Free(name);\r
+               Free(str);\r
+               Free(unistr);\r
+\r
+               return NULL;\r
+       }\r
+\r
+       name2_size = StrLen(name) + StrLen(prefix) + 2;\r
+       name2 = ZeroMalloc(name2_size);\r
+\r
+       if (prefix[0] != 0)\r
+       {\r
+               StrCat(name2, name2_size, prefix);\r
+               StrCat(name2, name2_size, "@");\r
+       }\r
+\r
+       StrCat(name2, name2_size, name);\r
+\r
+       Free(name);\r
+\r
+       // TABLE を作成する\r
+       t = Malloc(sizeof(TABLE));\r
+       StrUpper(name2);\r
+       t->name = name2;\r
+       t->str = str;\r
+       t->unistr = unistr;\r
+\r
+       return t;\r
+}\r
+\r
+// 文字列のアンエスケープ\r
+void UnescapeStr(char *src)\r
+{\r
+       UINT i, len, wp;\r
+       char *tmp;\r
+       // 引数チェック\r
+       if (src == NULL)\r
+       {\r
+               return;\r
+       }\r
+       \r
+       len = StrLen(src);\r
+       tmp = Malloc(len + 1);\r
+       wp = 0;\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (src[i] == '\\')\r
+               {\r
+                       i++;\r
+                       switch (src[i])\r
+                       {\r
+                       case 0:\r
+                               goto FINISH;\r
+                       case '\\':\r
+                               tmp[wp++] = '\\';\r
+                               break;\r
+                       case ' ':\r
+                               tmp[wp++] = ' ';\r
+                               break;\r
+                       case 'n':\r
+                       case 'N':\r
+                               tmp[wp++] = '\n';\r
+                               break;\r
+                       case 'r':\r
+                       case 'R':\r
+                               tmp[wp++] = '\r';\r
+                               break;\r
+                       case 't':\r
+                       case 'T':\r
+                               tmp[wp++] = '\t';\r
+                               break;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       tmp[wp++] = src[i];\r
+               }\r
+       }\r
+FINISH:\r
+       tmp[wp++] = 0;\r
+       StrCpy(src, 0, tmp);\r
+       Free(tmp);\r
+}\r
+\r
+// テーブルを解放する\r
+void FreeTable()\r
+{\r
+       UINT i, num;\r
+       TABLE **tables;\r
+       if (TableList == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       TrackingDisable();\r
+\r
+       num = LIST_NUM(TableList);\r
+       tables = ToArray(TableList);\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               TABLE *t = tables[i];\r
+               Free(t->name);\r
+               Free(t->str);\r
+               Free(t->unistr);\r
+               Free(t);\r
+       }\r
+       ReleaseList(TableList);\r
+       TableList = NULL;\r
+       Free(tables);\r
+\r
+       Zero(old_table_name, sizeof(old_table_name));\r
+\r
+       TrackingEnable();\r
+}\r
+\r
+// バッファから文字列テーブルを読み込む\r
+bool LoadTableFromBuf(BUF *b)\r
+{\r
+       char *tmp;\r
+       char prefix[MAX_SIZE];\r
+       // 引数チェック\r
+       if (b == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // すでにテーブルがある場合は削除する\r
+       FreeTable();\r
+\r
+       // リストを作成する\r
+       TableList = NewList(CmpTableName);\r
+\r
+       Zero(prefix, sizeof(prefix));\r
+\r
+       // バッファの内容を 1 行ずつ読んでいく\r
+       while (true)\r
+       {\r
+               TABLE *t;\r
+               tmp = CfgReadNextLine(b);\r
+               if (tmp == NULL)\r
+               {\r
+                       break;\r
+               }\r
+               t = ParseTableLine(tmp, prefix, sizeof(prefix));\r
+               if (t != NULL)\r
+               {\r
+                       // 登録する\r
+                       Insert(TableList, t);\r
+               }\r
+               Free(tmp);\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// Unicode 文字列キャッシュファイル名の生成\r
+void GenerateUnicodeCacheFileName(wchar_t *name, UINT size, wchar_t *strfilename, UINT strfilesize, UCHAR *filehash)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       wchar_t hashstr[64];\r
+       wchar_t hashtemp[MAX_SIZE];\r
+       wchar_t exe[MAX_SIZE];\r
+       UCHAR hash[SHA1_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL || strfilename == NULL || filehash == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetExeDirW(exe, sizeof(exe));\r
+       UniStrCpy(hashtemp, sizeof(hashtemp), strfilename);\r
+       BinToStrW(tmp, sizeof(tmp), filehash, MD5_SIZE);\r
+       UniStrCat(hashtemp, sizeof(hashtemp), tmp);\r
+       UniStrCat(hashtemp, sizeof(hashtemp), exe);\r
+       UniStrLower(hashtemp);\r
+\r
+       Hash(hash, hashtemp, UniStrLen(hashtemp) * sizeof(wchar_t), true);\r
+       BinToStrW(hashstr, sizeof(hashstr), hash, 4);\r
+       UniFormat(tmp, sizeof(tmp), UNICODE_CACHE_FILE, hashstr);\r
+       UniStrLower(tmp);\r
+\r
+#ifndef        OS_WIN32\r
+       UniStrCpy(exe, sizeof(exe), L"/tmp");\r
+#else  // OS_WIN32\r
+       StrToUni(exe, sizeof(exe), MsGetTempDir());\r
+#endif // OS_WIN32\r
+\r
+       UniFormat(name, size, L"%s/%s", exe, tmp);\r
+       NormalizePathW(name, size, name);\r
+}\r
+\r
+// Unicode キャッシュの保存\r
+void SaveUnicodeCache(wchar_t *strfilename, UINT strfilesize, UCHAR *hash)\r
+{\r
+       UNICODE_CACHE c;\r
+       BUF *b;\r
+       UINT i;\r
+       IO *io;\r
+       wchar_t name[MAX_PATH];\r
+       UCHAR binhash[MD5_SIZE];\r
+       // 引数チェック\r
+       if (strfilename == NULL || hash == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&c, sizeof(c));\r
+       UniToStr(c.StrFileName, sizeof(c.StrFileName), strfilename);\r
+       c.StrFileSize = strfilesize;\r
+       GetMachineName(c.MachineName, sizeof(c.MachineName));\r
+       c.OsType = GetOsInfo()->OsType;\r
+       Copy(c.hash, hash, MD5_SIZE);\r
+\r
+#ifdef OS_UNIX\r
+       GetCurrentCharSet(c.CharSet, sizeof(c.CharSet));\r
+#else  // OS_UNIX\r
+       {\r
+               UINT id = MsGetThreadLocale();\r
+               Copy(c.CharSet, &id, sizeof(id));\r
+       }\r
+#endif // OS_UNIX\r
+\r
+       b = NewBuf();\r
+       WriteBuf(b, &c, sizeof(c));\r
+\r
+       WriteBufInt(b, LIST_NUM(TableList));\r
+       for (i = 0;i < LIST_NUM(TableList);i++)\r
+       {\r
+               TABLE *t = LIST_DATA(TableList, i);\r
+               WriteBufInt(b, StrLen(t->name));\r
+               WriteBuf(b, t->name, StrLen(t->name));\r
+               WriteBufInt(b, StrLen(t->str));\r
+               WriteBuf(b, t->str, StrLen(t->str));\r
+               WriteBufInt(b, UniStrLen(t->unistr));\r
+               WriteBuf(b, t->unistr, UniStrLen(t->unistr) * sizeof(wchar_t));\r
+       }\r
+\r
+       Hash(binhash, b->Buf, b->Size, false);\r
+       WriteBuf(b, binhash, MD5_SIZE);\r
+\r
+       GenerateUnicodeCacheFileName(name, sizeof(name), strfilename, strfilesize, hash);\r
+\r
+       io = FileCreateW(name);\r
+       if (io != NULL)\r
+       {\r
+               SeekBuf(b, 0, 0);\r
+               BufToFile(io, b);\r
+               FileClose(io);\r
+       }\r
+\r
+       FreeBuf(b);\r
+}\r
+\r
+// Unicode キャッシュの読み込み\r
+bool LoadUnicodeCache(wchar_t *strfilename, UINT strfilesize, UCHAR *hash)\r
+{\r
+       UNICODE_CACHE c, t;\r
+       BUF *b;\r
+       UINT i, num;\r
+       IO *io;\r
+       wchar_t name[MAX_PATH];\r
+       UCHAR binhash[MD5_SIZE];\r
+       UCHAR binhash_2[MD5_SIZE];\r
+       // 引数チェック\r
+       if (strfilename == NULL || hash == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       GenerateUnicodeCacheFileName(name, sizeof(name), strfilename, strfilesize, hash);\r
+\r
+       io = FileOpenW(name, false);\r
+       if (io == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       b = FileToBuf(io);\r
+       if (b == NULL)\r
+       {\r
+               FileClose(io);\r
+               return false;\r
+       }\r
+\r
+       SeekBuf(b, 0, 0);\r
+       FileClose(io);\r
+\r
+       Hash(binhash, b->Buf, b->Size >= MD5_SIZE ? (b->Size - MD5_SIZE) : 0, false);\r
+       Copy(binhash_2, ((UCHAR *)b->Buf) + (b->Size >= MD5_SIZE ? (b->Size - MD5_SIZE) : 0), MD5_SIZE);\r
+       if (Cmp(binhash, binhash_2, MD5_SIZE) != 0)\r
+       {\r
+               FreeBuf(b);\r
+               return false;\r
+       }\r
+\r
+       Zero(&c, sizeof(c));\r
+       UniToStr(c.StrFileName, sizeof(c.StrFileName), strfilename);\r
+       c.StrFileSize = strfilesize;\r
+       DisableNetworkNameCache();\r
+       GetMachineName(c.MachineName, sizeof(c.MachineName));\r
+       EnableNetworkNameCache();\r
+       c.OsType = GetOsInfo()->OsType;\r
+       Copy(c.hash, hash, MD5_SIZE);\r
+\r
+#ifdef OS_UNIX\r
+       GetCurrentCharSet(c.CharSet, sizeof(c.CharSet));\r
+#else  // OS_UNIX\r
+       {\r
+               UINT id = MsGetThreadLocale();\r
+               Copy(c.CharSet, &id, sizeof(id));\r
+       }\r
+#endif // OS_UNIX\r
+\r
+       Zero(&t, sizeof(t));\r
+       ReadBuf(b, &t, sizeof(t));\r
+\r
+       if (Cmp(&c, &t, sizeof(UNICODE_CACHE)) != 0)\r
+       {\r
+               FreeBuf(b);\r
+               return false;\r
+       }\r
+\r
+       num = ReadBufInt(b);\r
+\r
+       FreeTable();\r
+       TableList = NewList(CmpTableName);\r
+\r
+       for (i = 0;i < num;i++)\r
+       {\r
+               UINT len;\r
+               TABLE *t = ZeroMalloc(sizeof(TABLE));\r
+\r
+               len = ReadBufInt(b);\r
+               t->name = ZeroMalloc(len + 1);\r
+               ReadBuf(b, t->name, len);\r
+\r
+               len = ReadBufInt(b);\r
+               t->str = ZeroMalloc(len + 1);\r
+               ReadBuf(b, t->str, len);\r
+\r
+               len = ReadBufInt(b);\r
+               t->unistr = ZeroMalloc((len + 1) * sizeof(wchar_t));\r
+               ReadBuf(b, t->unistr, len * sizeof(wchar_t));\r
+\r
+               Add(TableList, t);\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       Sort(TableList);\r
+\r
+       return true;\r
+}\r
+\r
+// 文字列テーブルを読み込む\r
+bool LoadTableMain(wchar_t *filename)\r
+{\r
+       BUF *b;\r
+       UINT64 t1, t2;\r
+       UCHAR hash[MD5_SIZE];\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (MayaquaIsMinimalMode())\r
+       {\r
+               return true;\r
+       }\r
+\r
+       if (UniStrCmpi(old_table_name, filename) == 0)\r
+       {\r
+               // すでに読み込まれている\r
+               return true;\r
+       }\r
+\r
+       t1 = Tick64();\r
+\r
+       // ファイルを開く\r
+       b = ReadDumpW(filename);\r
+       if (b == NULL)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               StrCpy(tmp, sizeof(tmp), "Error: Can't read string tables (file not found).\r\nPlease check hamcore.utvpn.\r\n\r\n(First, reboot the computer. If this problem occurs again, please reinstall VPN software files.)");\r
+               Alert(tmp, NULL);\r
+               exit(0);\r
+               return false;\r
+       }\r
+\r
+       Hash(hash, b->Buf, b->Size, false);\r
+\r
+       if (LoadUnicodeCache(filename, b->Size, hash) == false)\r
+       {\r
+               if (LoadTableFromBuf(b) == false)\r
+               {\r
+                       FreeBuf(b);\r
+                       return false;\r
+               }\r
+\r
+               SaveUnicodeCache(filename, b->Size, hash);\r
+\r
+               Debug("Unicode Source: strtable.stb\n");\r
+       }\r
+       else\r
+       {\r
+               Debug("Unicode Source: unicode_cache\n");\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       SetLocale(_UU("DEFAULE_LOCALE"));\r
+\r
+       UniStrCpy(old_table_name, sizeof(old_table_name), filename);\r
+\r
+       t2 = Tick64();\r
+\r
+       if (StrCmpi(_SS("STRTABLE_ID"), STRTABLE_ID) != 0)\r
+       {\r
+               char tmp[MAX_SIZE];\r
+               StrCpy(tmp, sizeof(tmp), "Error: Can't read string tables (invalid version).\r\nPlease check hamcore.utvpn.\r\n\r\n(First, reboot the computer. If this problem occurs again, please reinstall VPN software files.)");\r
+               Alert(tmp, NULL);\r
+               exit(0);\r
+               return false;\r
+       }\r
+\r
+       Debug("Unicode File Read Cost: %u (%u Lines)\n", (UINT)(t2 - t1), LIST_NUM(TableList));\r
+\r
+       return true;\r
+}\r
+bool LoadTable(char *filename)\r
+{\r
+       wchar_t *filename_a = CopyStrToUni(filename);\r
+       bool ret = LoadTableW(filename_a);\r
+\r
+       Free(filename_a);\r
+\r
+       return ret;\r
+}\r
+bool LoadTableW(wchar_t *filename)\r
+{\r
+       bool ret;\r
+       BUF *b;\r
+       wchar_t replace_name[MAX_PATH];\r
+\r
+       Zero(replace_name, sizeof(replace_name));\r
+\r
+       TrackingDisable();\r
+\r
+       b = ReadDump("@table_name.txt");\r
+       if (b != NULL)\r
+       {\r
+               char *s = CfgReadNextLine(b);\r
+               if (s != NULL)\r
+               {\r
+                       if (IsEmptyStr(s) == false)\r
+                       {\r
+                               StrToUni(replace_name, sizeof(replace_name), s);\r
+                               filename = replace_name;\r
+                       }\r
+\r
+                       Free(s);\r
+               }\r
+               FreeBuf(b);\r
+       }\r
+\r
+       ret = LoadTableMain(filename);\r
+\r
+       TrackingEnable();\r
+\r
+       return ret;\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Table.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Table.h
new file mode 100644 (file)
index 0000000..3860a6b
--- /dev/null
@@ -0,0 +1,143 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Table.h\r
+// Table.c のヘッダ\r
+\r
+#ifndef        TABLE_H\r
+#define        TABLE_H\r
+\r
+#define        UNICODE_CACHE_FILE              L".unicode_cache_%s.dat"\r
+\r
+// 言語定数\r
+#define SE_LANG_JAPANESE                       0       // 日本語\r
+#define SE_LANG_ENGLISH                                1       // 英語\r
+#define SE_LANG_CHINESE_ZH                     2       // 中文 (簡体字)\r
+\r
+\r
+// 文字列テーブル\r
+struct TABLE\r
+{\r
+       char *name;\r
+       char *str;\r
+       wchar_t *unistr;\r
+};\r
+\r
+// Unicode キャッシュ構造体\r
+typedef struct UNICODE_CACHE\r
+{\r
+       char StrFileName[256];  // 文字列ファイル名\r
+       UINT StrFileSize;               // 文字列ファイルサイズ\r
+       char MachineName[256];  // マシン名\r
+       UINT OsType;                    // OS の種類\r
+       UCHAR hash[MD5_SIZE];   // ハッシュ\r
+       UCHAR CharSet[64];              // 文字コードの種類\r
+} UNICODE_CACHE;\r
+\r
+// マクロ\r
+#define        _SS(name)               (GetTableStr((char *)(name)))\r
+#define        _UU(name)               (GetTableUniStr((char *)(name)))\r
+#define        _II(name)               (GetTableInt((char *)(name)))\r
+#define        _E(name)                (GetUniErrorStr((UINT)(name)))\r
+#define        _EA(name)               (GetErrorStr((UINT)(name)))\r
+#define _GETLANG()             (_II("LANG"))\r
+\r
+\r
+// 関数プロトタイプ\r
+bool LoadTable(char *filename);\r
+bool LoadTableW(wchar_t *filename);\r
+bool LoadTableMain(wchar_t *filename);\r
+bool LoadTableFromBuf(BUF *b);\r
+void FreeTable();\r
+TABLE *ParseTableLine(char *line, char *prefix, UINT prefix_size);\r
+void UnescapeStr(char *src);\r
+int CmpTableName(void *p1, void *p2);\r
+TABLE *FindTable(char *name);\r
+TOKEN_LIST *GetTableNameStartWith(char *str);\r
+char *GetTableStr(char *name);\r
+wchar_t *GetTableUniStr(char *name);\r
+char *GetErrorStr(UINT err);\r
+wchar_t *GetUniErrorStr(UINT err);\r
+UINT GetTableInt(char *name);\r
+void GenerateUnicodeCacheFileName(wchar_t *name, UINT size, wchar_t *strfilename, UINT strfilesize, UCHAR *filehash);\r
+void SaveUnicodeCache(wchar_t *strfilename, UINT strfilesize, UCHAR *hash);\r
+bool LoadUnicodeCache(wchar_t *strfilename, UINT strfilesize, UCHAR *hash);\r
+\r
+#endif // TABLE_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Tick64.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Tick64.c
new file mode 100644 (file)
index 0000000..21869b0
--- /dev/null
@@ -0,0 +1,370 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Tick64.c\r
+// 64bit リアルタイムクロックプログラム\r
+\r
+#ifdef WIN32\r
+#include <windows.h>\r
+#endif // WIN32\r
+\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <locale.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+static TICK64 *tk64 = NULL;\r
+static EVENT *halt_tick_event = NULL;\r
+\r
+// 高解像度時刻を取得\r
+UINT64 TickHighres64()\r
+{\r
+       UINT64 ret = 0;\r
+\r
+#ifdef OS_WIN32\r
+\r
+       ret = (UINT64)(MsGetHiResTimeSpan(MsGetHiResCounter()) * 1000.0f);\r
+\r
+#else  // OS_WIN32\r
+\r
+       return Tick64();\r
+\r
+#endif // OS_WIN32\r
+\r
+       return ret;\r
+}\r
+\r
+// Tick 値を時刻に変換\r
+UINT64 Tick64ToTime64(UINT64 tick)\r
+{\r
+       UINT64 ret = 0;\r
+       if (tick == 0)\r
+       {\r
+               return 0;\r
+       }\r
+       LockList(tk64->AdjustTime);\r
+       {\r
+               UINT i;\r
+               for (i = 0;i < LIST_NUM(tk64->AdjustTime);i++)\r
+               {\r
+                       ADJUST_TIME *t = LIST_DATA(tk64->AdjustTime, i);\r
+                       if (t->Tick <= tick)\r
+                       {\r
+                               ret = t->Time + (tick - t->Tick);\r
+                       }\r
+               }\r
+       }\r
+       UnlockList(tk64->AdjustTime);\r
+       if (ret == 0)\r
+       {\r
+               ret++;\r
+       }\r
+       return ret;\r
+}\r
+\r
+// Tick 値を時刻に変換\r
+UINT64 TickToTime(UINT64 tick)\r
+{\r
+       return Tick64ToTime64(tick);\r
+}\r
+\r
+// Tick 値を取得\r
+UINT64 Tick64()\r
+{\r
+#ifdef OS_WIN32\r
+       return Win32FastTick64();\r
+#else  // OS_WIN32\r
+       UINT64 tick64;\r
+       if (tk64 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       Lock(tk64->TickLock);\r
+       {\r
+               tick64 = tk64->Tick;\r
+       }\r
+       Unlock(tk64->TickLock);\r
+       return tick64;\r
+#endif // OS_WIN32\r
+}\r
+\r
+// リアルタイムクロック測定用スレッド\r
+void Tick64Thread(THREAD *thread, void *param)\r
+{\r
+       UINT n = 0;\r
+       bool first = false;\r
+       bool create_first_entry = true;\r
+       UINT tick_span;\r
+       // 引数チェック\r
+       if (thread == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+\r
+       // Win32 スレッドの優先順位を上げる\r
+       MsSetThreadPriorityRealtime();\r
+\r
+       tick_span = TICK64_SPAN_WIN32;\r
+\r
+#else  // OS_WIN32\r
+\r
+       // POSIX スレッドの優先順位を上げる\r
+       UnixSetThreadPriorityRealtime();\r
+\r
+       tick_span = TICK64_SPAN;\r
+\r
+#endif // OS_WIN32\r
+\r
+       while (true)\r
+       {\r
+               UINT tick;\r
+               UINT64 tick64;\r
+\r
+#ifndef        OS_WIN32\r
+               tick = TickRealtime();          // 現在のシステムクロックを取得\r
+\r
+               if (tk64->LastTick > tick)\r
+               {\r
+                       if ((tk64->LastTick - tick) >= (UINT64)0x0fffffff)\r
+                       {\r
+                               // tick の値が 1 周した\r
+                               tk64->RoundCount++;\r
+                       }\r
+                       else\r
+                       {\r
+                               // tick の値が逆戻りした (システム管理者がハードウェア時計を変更した)\r
+                               // 通常これは 1 秒以内の誤差として発生する\r
+                               tick = tk64->LastTick;\r
+                       }\r
+               }\r
+               tk64->LastTick = tick;\r
+\r
+               tick64 = (UINT64)tk64->RoundCount * (UINT64)4294967296LL + (UINT64)tick;\r
+\r
+               Lock(tk64->TickLock);\r
+               {\r
+                       if (tk64->TickStart == 0)\r
+                       {\r
+                               tk64->TickStart = tick64;\r
+                       }\r
+                       tick64 = tk64->Tick = tick64 - tk64->TickStart + (UINT64)1;\r
+               }\r
+               Unlock(tk64->TickLock);\r
+#else  // OS_WIN32\r
+               tick64 = Win32FastTick64();\r
+               tick = (UINT)tick64;\r
+#endif // OS_WIN32\r
+\r
+               if (create_first_entry)\r
+               {\r
+                       ADJUST_TIME *t = ZeroMalloc(sizeof(ADJUST_TIME));\r
+                       t->Tick = tick64;\r
+                       t->Time = SystemTime64();\r
+                       tk64->Tick64WithTime64 = tick64;\r
+                       tk64->Time64 = t->Time;\r
+                       Add(tk64->AdjustTime, t);\r
+\r
+                       // 初期化完了を通知\r
+                       NoticeThreadInit(thread);\r
+                       create_first_entry = false;\r
+               }\r
+\r
+               // 時刻補正\r
+               n += tick_span;\r
+               if (n >= 1000 || first == false)\r
+               {\r
+                       UINT64 now = SystemTime64();\r
+\r
+                       if (now < tk64->Time64 ||\r
+                               Diff64((now - tk64->Time64) + tk64->Tick64WithTime64, tick64) >= tick_span)\r
+                       {\r
+                               ADJUST_TIME *t = ZeroMalloc(sizeof(ADJUST_TIME));\r
+                               LockList(tk64->AdjustTime);\r
+                               {\r
+                                       t->Tick = tick64;\r
+                                       t->Time = now;\r
+                                       Add(tk64->AdjustTime, t);\r
+                                       Debug("Adjust Time: Tick = %I64u, Time = %I64u\n",\r
+                                               t->Tick, t->Time);\r
+\r
+                                       // 時計が狂っているシステムでメモリを無限に食わないように\r
+                                       if (LIST_NUM(tk64->AdjustTime) > MAX_ADJUST_TIME)\r
+                                       {\r
+                                               // 2 個目を削除する\r
+                                               ADJUST_TIME *t2 = LIST_DATA(tk64->AdjustTime, 1);\r
+\r
+                                               Delete(tk64->AdjustTime, t2);\r
+\r
+                                               Debug("NUM_ADJUST TIME: %u\n", LIST_NUM(tk64->AdjustTime));\r
+\r
+                                               Free(t2);\r
+                                       }\r
+                               }\r
+                               UnlockList(tk64->AdjustTime);\r
+                               tk64->Time64 = now;\r
+                               tk64->Tick64WithTime64 = tick64;\r
+                       }\r
+                       first = true;\r
+                       n = 0;\r
+               }\r
+\r
+               if (tk64->Halt)\r
+               {\r
+                       break;\r
+               }\r
+\r
+#ifdef OS_WIN32\r
+               Wait(halt_tick_event, tick_span);\r
+#else  // OS_WIN32\r
+               SleepThread(tick_span);\r
+#endif // OS_WIN32\r
+       }\r
+}\r
+\r
+// 2 つの 64 bit 整数の差の絶対値を取得\r
+UINT64 Diff64(UINT64 a, UINT64 b)\r
+{\r
+       if (a > b)\r
+       {\r
+               return a - b;\r
+       }\r
+       else\r
+       {\r
+               return b - a;\r
+       }\r
+}\r
+\r
+// Tick64 の初期化\r
+void InitTick64()\r
+{\r
+       if (tk64 != NULL)\r
+       {\r
+               // すでに初期化されている\r
+               return;\r
+       }\r
+\r
+       halt_tick_event = NewEvent();\r
+\r
+       // 構造体の初期化\r
+       tk64 = ZeroMalloc(sizeof(TICK64));\r
+       tk64->TickLock = NewLock();\r
+       tk64->AdjustTime = NewList(NULL);\r
+\r
+       // スレッドの作成\r
+       tk64->Thread = NewThread(Tick64Thread, NULL);\r
+       WaitThreadInit(tk64->Thread);\r
+}\r
+\r
+// Tick64 の解放\r
+void FreeTick64()\r
+{\r
+       UINT i;\r
+       if (tk64 == NULL)\r
+       {\r
+               // 初期化されていない\r
+               return;\r
+       }\r
+\r
+       // 終了処理\r
+       tk64->Halt = true;\r
+       Set(halt_tick_event);\r
+       WaitThread(tk64->Thread, INFINITE);\r
+       ReleaseThread(tk64->Thread);\r
+\r
+       // 解放処理\r
+       for (i = 0;i < LIST_NUM(tk64->AdjustTime);i++)\r
+       {\r
+               ADJUST_TIME *t = LIST_DATA(tk64->AdjustTime, i);\r
+               Free(t);\r
+       }\r
+       ReleaseList(tk64->AdjustTime);\r
+       DeleteLock(tk64->TickLock);\r
+       Free(tk64);\r
+       tk64 = NULL;\r
+\r
+       ReleaseEvent(halt_tick_event);\r
+       halt_tick_event = NULL;\r
+}\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Tick64.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Tick64.h
new file mode 100644 (file)
index 0000000..2b299ca
--- /dev/null
@@ -0,0 +1,127 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Tick64.h\r
+// Tick64.c のヘッダ\r
+\r
+#ifndef        TICK64_H\r
+#define        TICK64_H\r
+\r
+// 最大の補正リストエントリ数\r
+#define        MAX_ADJUST_TIME                         5000\r
+\r
+// 補正リストエントリ\r
+struct ADJUST_TIME\r
+{\r
+       UINT64 Tick;\r
+       UINT64 Time;\r
+};\r
+\r
+// TICK64 構造体\r
+struct TICK64\r
+{\r
+       THREAD *Thread;\r
+       UINT64 Tick;\r
+       UINT64 TickStart;\r
+       UINT64 Time64;\r
+       UINT64 Tick64WithTime64;\r
+       UINT LastTick;\r
+       UINT RoundCount;\r
+       LOCK *TickLock;\r
+       volatile bool Halt;\r
+       LIST *AdjustTime;\r
+};\r
+\r
+// 定数\r
+#define        TICK64_SPAN                     10              // 測定間隔 (通常は 10ms以下)\r
+#define        TICK64_SPAN_WIN32       1000    // Win32 での測定間隔\r
+#define        TICK64_ADJUST_SPAN      5000    // この値以上時計がずれたら補正する\r
+\r
+// 関数プロトタイプ\r
+void InitTick64();\r
+void FreeTick64();\r
+void Tick64Thread(THREAD *thread, void *param);\r
+UINT64 Tick64();\r
+UINT64 Diff64(UINT64 a, UINT64 b);\r
+UINT64 Tick64ToTime64(UINT64 tick);\r
+UINT64 TickToTime(UINT64 tick);\r
+UINT64 TickHighres64();\r
+\r
+#endif // TICK64_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Tracking.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Tracking.c
new file mode 100644 (file)
index 0000000..0d11a74
--- /dev/null
@@ -0,0 +1,966 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Tracking.c\r
+// オブジェクト追跡モジュール\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+// グローバル変数\r
+static LOCK *obj_lock;\r
+static LOCK *obj_id_lock;\r
+static UINT obj_id;\r
+static LOCK *cs_lock;\r
+static bool disable_tracking = false;\r
+static TRACKING_LIST **hashlist;\r
+\r
+static bool do_not_get_callstack;\r
+\r
+// 追跡を有効にする\r
+void TrackingEnable()\r
+{\r
+       disable_tracking = false;\r
+}\r
+\r
+// 追跡を無効にする\r
+void TrackingDisable()\r
+{\r
+       disable_tracking = true;\r
+}\r
+\r
+// 追跡が有効かどうか取得\r
+bool IsTrackingEnabled()\r
+{\r
+       return !disable_tracking;\r
+}\r
+\r
+// メモリデバッグメニュー\r
+void MemoryDebugMenu()\r
+{\r
+       char tmp[MAX_SIZE];\r
+       TOKEN_LIST *t;\r
+       char *cmd;\r
+       Print("Mayaqua Kernel Memory Debug Tools\n"\r
+               "Copyright (C) SoftEther Corporation. All Rights Reserved.\n\n");\r
+       g_memcheck = false;\r
+       while (true)\r
+       {\r
+               Print("debug>");\r
+               GetLine(tmp, sizeof(tmp));\r
+               t = ParseToken(tmp, " \t");\r
+               if (t->NumTokens == 0)\r
+               {\r
+                       FreeToken(t);\r
+                       DebugPrintAllObjects();\r
+                       continue;\r
+               }\r
+               cmd = t->Token[0];\r
+               if (!StrCmpi(cmd, "?"))\r
+               {\r
+                       DebugPrintCommandList();\r
+               }\r
+               else if (!StrCmpi(cmd, "a"))\r
+               {\r
+                       DebugPrintAllObjects();\r
+               }\r
+               else if (!StrCmpi(cmd, "i"))\r
+               {\r
+                       if (t->NumTokens == 1)\r
+                       {\r
+                               Print("Usage: i <obj_id>\n\n");\r
+                       }\r
+                       else\r
+                       {\r
+                               DebugPrintObjectInfo(ToInt(t->Token[1]));\r
+                       }\r
+               }\r
+               else if (!StrCmpi(cmd, "q"))\r
+               {\r
+                       break;\r
+               }\r
+               else if (ToInt(cmd) != 0)\r
+               {\r
+                       DebugPrintObjectInfo(ToInt(t->Token[0]));\r
+               }\r
+               else\r
+               {\r
+                       Print("Command Not Found,\n\n");\r
+               }\r
+               FreeToken(t);\r
+       }\r
+       FreeToken(t);\r
+       g_memcheck = true;\r
+}\r
+\r
+// オブジェクトを時間順にソートする\r
+int SortObjectView(void *p1, void *p2)\r
+{\r
+       TRACKING_OBJECT *o1, *o2;\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       o1 = *(TRACKING_OBJECT **)p1;\r
+       o2 = *(TRACKING_OBJECT **)p2;\r
+       if (o1 == NULL || o2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (o1->Id > o2->Id)\r
+       {\r
+               return 1;\r
+       }\r
+       else if (o1->Id == o2->Id)\r
+       {\r
+               return 0;\r
+       }\r
+       return -1;\r
+}\r
+\r
+// オブジェクト情報の表示\r
+void PrintObjectInfo(TRACKING_OBJECT *o)\r
+{\r
+       SYSTEMTIME t;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       UINT64ToSystem(&t, o->CreatedDate);\r
+       GetDateTimeStrMilli(tmp, sizeof(tmp), &t);\r
+\r
+       Print("    TRACKING_OBJECT ID: %u\n"\r
+               "  TRACKING_OBJECT TYPE: %s\n"\r
+               "      ADDRESS: 0x%p\n"\r
+               "  TRACKING_OBJECT SIZE: %u bytes\n"\r
+               " CREATED DATE: %s\n",\r
+               o->Id, o->Name, UINT64_TO_POINTER(o->Address), o->Size, tmp);\r
+\r
+       PrintCallStack(o->CallStack);\r
+}\r
+\r
+// オブジェクト情報を表示する\r
+void DebugPrintObjectInfo(UINT id)\r
+{\r
+       UINT i;\r
+       TRACKING_OBJECT *o;\r
+\r
+       // 検索\r
+       o = NULL;\r
+       LockTrackingList();\r
+       {\r
+               for (i = 0;i < TRACKING_NUM_ARRAY;i++)\r
+               {\r
+                       if (hashlist[i] != NULL)\r
+                       {\r
+                               TRACKING_LIST *t = hashlist[i];\r
+\r
+                               while (true)\r
+                               {\r
+                                       if (t->Object->Id == id)\r
+                                       {\r
+                                               o = t->Object;\r
+                                               break;\r
+                                       }\r
+\r
+                                       if (t->Next == NULL)\r
+                                       {\r
+                                               break;\r
+                                       }\r
+\r
+                                       t = t->Next;\r
+                               }\r
+\r
+                               if (o != NULL)\r
+                               {\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       UnlockTrackingList();\r
+\r
+       if (o == NULL)\r
+       {\r
+               // ID が発見できなかった\r
+               Print("obj_id %u Not Found.\n\n", id);\r
+               return;\r
+       }\r
+\r
+       PrintObjectInfo(o);\r
+       Print("\n");\r
+}\r
+\r
+// オブジェクトのサマリーの表示\r
+void PrintObjectList(TRACKING_OBJECT *o)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       SYSTEMTIME t;\r
+       UINT64ToSystem(&t, o->CreatedDate);\r
+       GetTimeStrMilli(tmp, sizeof(tmp), &t);\r
+       TrackGetObjSymbolInfo(o);\r
+       Print("%-4u - [%-6s] %s 0x%p size=%-5u %11s %u\n",\r
+               o->Id, o->Name, tmp, UINT64_TO_POINTER(o->Address), o->Size, o->FileName, o->LineNumber);\r
+}\r
+\r
+// すべてのオブジェクトの表示\r
+void DebugPrintAllObjects()\r
+{\r
+       UINT i;\r
+       LIST *view;\r
+\r
+       // リスト作成\r
+       view = NewListFast(SortObjectView);\r
+       LockTrackingList();\r
+       {\r
+               for (i = 0;i < TRACKING_NUM_ARRAY;i++)\r
+               {\r
+                       if (hashlist[i] != NULL)\r
+                       {\r
+                               TRACKING_LIST *t = hashlist[i];\r
+\r
+                               while (true)\r
+                               {\r
+                                       Add(view, t->Object);\r
+\r
+                                       if (t->Next == NULL)\r
+                                       {\r
+                                               break;\r
+                                       }\r
+\r
+                                       t = t->Next;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       UnlockTrackingList();\r
+\r
+       // ソート\r
+       Sort(view);\r
+\r
+       // 描画\r
+       for (i = 0;i < LIST_NUM(view);i++)\r
+       {\r
+               TRACKING_OBJECT *o = (TRACKING_OBJECT *)LIST_DATA(view, i);\r
+               PrintObjectList(o);\r
+       }\r
+\r
+       // リスト解放\r
+       ReleaseList(view);\r
+\r
+       Print("\n");\r
+}\r
+\r
+// コマンド一覧\r
+void DebugPrintCommandList()\r
+{\r
+       Print(\r
+               "a - All Objects\n"\r
+               "i - Object Information\n"\r
+               "? - Help\n"\r
+               "q - Quit\n\n"\r
+               );\r
+}\r
+\r
+// メモリの使用状態を表示する\r
+void PrintMemoryStatus()\r
+{\r
+       MEMORY_STATUS s;\r
+       GetMemoryStatus(&s);\r
+       Print("MEMORY STATUS:\n"\r
+               " NUM_OF_MEMORY_BLOCKS: %u\n"\r
+               " SIZE_OF_TOTAL_MEMORY: %u bytes\n",\r
+               s.MemoryBlocksNum, s.MemorySize);\r
+}\r
+\r
+// メモリの使用状態を取得する\r
+void GetMemoryStatus(MEMORY_STATUS *status)\r
+{\r
+       UINT i, num, size;\r
+       // 引数チェック\r
+       if (status == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockTrackingList();\r
+       {\r
+               size = num = 0;\r
+\r
+               for (i = 0;i < TRACKING_NUM_ARRAY;i++)\r
+               {\r
+                       if (hashlist[i] != NULL)\r
+                       {\r
+                               TRACKING_LIST *t = hashlist[i];\r
+\r
+                               while (true)\r
+                               {\r
+                                       TRACKING_OBJECT *o = t->Object;\r
+\r
+                                       if (StrCmpi(o->Name, "MEM") == 0)\r
+                                       {\r
+                                               num++;\r
+                                               size += o->Size;\r
+                                       }\r
+\r
+                                       if (t->Next == NULL)\r
+                                       {\r
+                                               break;\r
+                                       }\r
+\r
+                                       t = t->Next;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       UnlockTrackingList();\r
+\r
+       status->MemoryBlocksNum = num;\r
+       status->MemorySize = size;\r
+}\r
+\r
+// オブジェクトからシンボル情報を取得する\r
+void TrackGetObjSymbolInfo(TRACKING_OBJECT *o)\r
+{\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (!(o->LineNumber == 0 && o->FileName[0] == 0))\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (o->CallStack != NULL)\r
+       {\r
+               GetCallStackSymbolInfo(o->CallStack);\r
+               if (StrLen(o->CallStack->filename) != 0 && o->CallStack->line != 0)\r
+               {\r
+                       StrCpy(o->FileName, sizeof(o->FileName), o->CallStack->filename);\r
+                       o->LineNumber = o->CallStack->line;\r
+               }\r
+       }\r
+}\r
+\r
+// 新しいオブジェクトを追跡リストに入れる\r
+void TrackNewObj(UINT64 addr, char *name, UINT size)\r
+{\r
+       TRACKING_OBJECT *o;\r
+       UINT new_id;\r
+       // 引数チェック\r
+       if (addr == 0 || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsMemCheck() == false)\r
+       {\r
+               // リリースモードでは追跡しない\r
+               return;\r
+       }\r
+\r
+       if (disable_tracking)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 新しい ID の生成\r
+       OSLock(obj_id_lock);\r
+       {\r
+               new_id = ++obj_id;\r
+       }\r
+       OSUnlock(obj_id_lock);\r
+\r
+       o = OSMemoryAlloc(sizeof(TRACKING_OBJECT));\r
+       o->Id = new_id;\r
+       o->Address = addr;\r
+       o->Name = name;\r
+       o->Size = size;\r
+       o->CreatedDate = LocalTime64();\r
+       o->CallStack = WalkDownCallStack(GetCallStack(), 2);\r
+\r
+       o->FileName[0] = 0;\r
+       o->LineNumber = 0;\r
+\r
+       LockTrackingList();\r
+       {\r
+               InsertTrackingList(o);\r
+       }\r
+       UnlockTrackingList();\r
+}\r
+\r
+// 追跡リストからオブジェクトを削除する\r
+void TrackDeleteObj(UINT64 addr)\r
+{\r
+       TRACKING_OBJECT *o;\r
+       // 引数チェック\r
+       if (addr == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsMemCheck() == false)\r
+       {\r
+               // リリースモードでは追跡しない\r
+               return;\r
+       }\r
+\r
+       if (disable_tracking)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockTrackingList();\r
+       {\r
+               o = SearchTrackingList(addr);\r
+               if (o == NULL)\r
+               {\r
+                       UnlockTrackingList();\r
+\r
+                       if (IsDebug())\r
+                       {\r
+                               printf("TrackDeleteObj: 0x%x is not Object!!\n", (void *)addr);\r
+                       }\r
+                       return;\r
+               }\r
+               DeleteTrackingList(o, true);\r
+       }\r
+       UnlockTrackingList();\r
+}\r
+\r
+// 追跡しているオブジェクトのサイズを変更する\r
+void TrackChangeObjSize(UINT64 addr, UINT size, UINT64 new_addr)\r
+{\r
+       TRACKING_OBJECT *o;\r
+       // 引数チェック\r
+       if (addr == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsMemCheck() == false)\r
+       {\r
+               // リリースモードでは追跡しない\r
+               return;\r
+       }\r
+\r
+       if (disable_tracking)\r
+       {\r
+               return;\r
+       }\r
+\r
+       LockTrackingList();\r
+       {\r
+               o = SearchTrackingList(addr);\r
+               if (o == NULL)\r
+               {\r
+                       UnlockTrackingList();\r
+                       return;\r
+               }\r
+\r
+               DeleteTrackingList(o, false);\r
+\r
+               o->Size = size;\r
+               o->Address = new_addr;\r
+\r
+               InsertTrackingList(o);\r
+       }\r
+       UnlockTrackingList();\r
+}\r
+\r
+// メモリアドレス比較関数\r
+int CompareTrackingObject(const void *p1, const void *p2)\r
+{\r
+       TRACKING_OBJECT *o1, *o2;\r
+       // 引数チェック\r
+       if (p1 == NULL || p2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       o1 = *(TRACKING_OBJECT **)p1;\r
+       o2 = *(TRACKING_OBJECT **)p2;\r
+       if (o1 == NULL || o2 == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (o1->Address > o2->Address)\r
+       {\r
+               return 1;\r
+       }\r
+       if (o1->Address == o2->Address)\r
+       {\r
+               return 0;\r
+       }\r
+       return -1;\r
+}\r
+\r
+// オブジェクトをトラッキングリストから検索\r
+TRACKING_OBJECT *SearchTrackingList(UINT64 Address)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (Address == 0)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       i = TRACKING_HASH(Address);\r
+\r
+       if (hashlist[i] != NULL)\r
+       {\r
+               TRACKING_LIST *tt = hashlist[i];\r
+\r
+               while (true)\r
+               {\r
+                       if (tt->Object->Address == Address)\r
+                       {\r
+                               return tt->Object;\r
+                       }\r
+\r
+                       tt = tt->Next;\r
+\r
+                       if (tt == NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return NULL;\r
+}\r
+\r
+// オブジェクトをトラッキングリストから削除\r
+void DeleteTrackingList(TRACKING_OBJECT *o, bool free_object_memory)\r
+{\r
+       UINT i;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       i = TRACKING_HASH(o->Address);\r
+\r
+       if (hashlist[i] != NULL)\r
+       {\r
+               TRACKING_LIST *ft = NULL;\r
+\r
+               if (hashlist[i]->Object == o)\r
+               {\r
+                       ft = hashlist[i];\r
+                       hashlist[i] = hashlist[i]->Next;\r
+               }\r
+               else\r
+               {\r
+                       TRACKING_LIST *tt = hashlist[i];\r
+                       TRACKING_LIST *prev = NULL;\r
+\r
+                       while (true)\r
+                       {\r
+                               if (tt->Object == o)\r
+                               {\r
+                                       prev->Next = tt->Next;\r
+                                       ft = tt;\r
+                                       break;\r
+                               }\r
+\r
+                               if (tt->Next == NULL)\r
+                               {\r
+                                       break;\r
+                               }\r
+\r
+                               prev = tt;\r
+                               tt = tt->Next;\r
+                       }\r
+               }\r
+\r
+               if (ft != NULL)\r
+               {\r
+                       OSMemoryFree(ft);\r
+\r
+                       if (free_object_memory)\r
+                       {\r
+                               FreeCallStack(o->CallStack);\r
+                               OSMemoryFree(o);\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// オブジェクトをトラッキングリストに挿入\r
+void InsertTrackingList(TRACKING_OBJECT *o)\r
+{\r
+       UINT i;\r
+       TRACKING_LIST *t;\r
+       // 引数チェック\r
+       if (o == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       t = OSMemoryAlloc(sizeof(TRACKING_LIST));\r
+       t->Object = o;\r
+       t->Next = NULL;\r
+\r
+       i = TRACKING_HASH(o->Address);\r
+\r
+       if (hashlist[i] == NULL)\r
+       {\r
+               hashlist[i] = t;\r
+       }\r
+       else\r
+       {\r
+               TRACKING_LIST *tt = hashlist[i];\r
+               while (true)\r
+               {\r
+                       if (tt->Next == NULL)\r
+                       {\r
+                               tt->Next = t;\r
+                               break;\r
+                       }\r
+\r
+                       tt = tt->Next;\r
+               }\r
+       }\r
+}\r
+\r
+// トラッキングリストのロック\r
+void LockTrackingList()\r
+{\r
+       OSLock(obj_lock);\r
+}\r
+\r
+// トラッキングリストのロック解除\r
+void UnlockTrackingList()\r
+{\r
+       OSUnlock(obj_lock);\r
+}\r
+\r
+// トラッキングの初期化\r
+void InitTracking()\r
+{\r
+       UINT i;\r
+       CALLSTACK_DATA *s;\r
+\r
+       // ハッシュリスト初期化\r
+       hashlist = (TRACKING_LIST **)OSMemoryAlloc(sizeof(TRACKING_LIST *) * TRACKING_NUM_ARRAY);\r
+\r
+       for (i = 0;i < TRACKING_NUM_ARRAY;i++)\r
+       {\r
+               hashlist[i] = NULL;\r
+       }\r
+\r
+       obj_id = 0;\r
+\r
+       // ロック作成\r
+       obj_lock = OSNewLock();\r
+       obj_id_lock = OSNewLock();\r
+       cs_lock = OSNewLock();\r
+\r
+       s = GetCallStack();\r
+       if (s == NULL)\r
+       {\r
+               do_not_get_callstack = true;\r
+       }\r
+       else\r
+       {\r
+               do_not_get_callstack = false;\r
+               FreeCallStack(s);\r
+       }\r
+}\r
+\r
+// トラッキングの解放\r
+void FreeTracking()\r
+{\r
+       UINT i;\r
+       // ロック削除\r
+       OSDeleteLock(obj_lock);\r
+       OSDeleteLock(obj_id_lock);\r
+       OSDeleteLock(cs_lock);\r
+       cs_lock = NULL;\r
+       obj_id_lock = NULL;\r
+       obj_lock = NULL;\r
+\r
+       // すべての要素を解放\r
+       for (i = 0;i < TRACKING_NUM_ARRAY;i++)\r
+       {\r
+               if (hashlist[i] != NULL)\r
+               {\r
+                       TRACKING_LIST *t = hashlist[i];\r
+\r
+                       while (true)\r
+                       {\r
+                               TRACKING_LIST *t2 = t;\r
+                               TRACKING_OBJECT *o = t->Object;\r
+\r
+                               FreeCallStack(o->CallStack);\r
+                               OSMemoryFree(o);\r
+\r
+                               t = t->Next;\r
+\r
+                               OSMemoryFree(t2);\r
+\r
+                               if (t == NULL)\r
+                               {\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       // リスト解放\r
+       OSMemoryFree(hashlist);\r
+}\r
+\r
+// コールスタックを表示する\r
+void PrintCallStack(CALLSTACK_DATA *s)\r
+{\r
+       char tmp[MAX_SIZE * 2];\r
+\r
+       GetCallStackStr(tmp, sizeof(tmp), s);\r
+       Print("%s", tmp);\r
+}\r
+\r
+// コールスタックを文字列に変換する\r
+void GetCallStackStr(char *str, UINT size, CALLSTACK_DATA *s)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       char tmp2[MAX_SIZE];\r
+       char tmp3[MAX_SIZE];\r
+       UINT num, i;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (s == NULL)\r
+       {\r
+               StrCpy(str, size, "(Unknown)\n");\r
+       }\r
+       else\r
+       {\r
+               num = 0;\r
+               str[0] = 0;\r
+               while (true)\r
+               {\r
+                       if (s == NULL)\r
+                       {\r
+                               break;\r
+                       }\r
+\r
+                       GetCallStackSymbolInfo(s);\r
+\r
+                       if (s->name == NULL)\r
+                       {\r
+                               Format(tmp, sizeof(tmp), "0x%p ---", UINT64_TO_POINTER(s->offset));\r
+                       }\r
+                       else\r
+                       {\r
+                               Format(tmp, sizeof(tmp), "0x%p %s() + 0x%02x",\r
+                                       (void *)s->offset, s->name, UINT64_TO_POINTER(s->disp));\r
+                       }\r
+                       for (i = 0;i < num;i++)\r
+                       {\r
+                               tmp2[i] = ' ';\r
+                       }\r
+                       tmp2[i] = '\0';\r
+                       StrCpy(tmp3, sizeof(tmp3), tmp2);\r
+                       StrCat(tmp3, sizeof(tmp3), tmp);\r
+                       Format(tmp, sizeof(tmp), "%-55s %11s %u\n", tmp3, s->filename, s->line);\r
+                       StrCat(str, size, tmp);\r
+                       num++;\r
+                       s = s->next;\r
+               }\r
+       }\r
+}\r
+\r
+// 現在のコールスタックの取得\r
+CALLSTACK_DATA *GetCallStack()\r
+{\r
+       CALLSTACK_DATA *s;\r
+       if (do_not_get_callstack)\r
+       {\r
+               // コールスタックは取得しない\r
+               return NULL;\r
+       }\r
+\r
+       OSLock(cs_lock);\r
+       {\r
+               // コールスタックの取得\r
+               s = OSGetCallStack();\r
+       }\r
+       OSUnlock(cs_lock);\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // コールスタックを 3 つ分だけ下降する\r
+       s = WalkDownCallStack(s, 3);\r
+\r
+       return s;\r
+}\r
+\r
+// コールスタックのシンボル情報を取得\r
+bool GetCallStackSymbolInfo(CALLSTACK_DATA *s)\r
+{\r
+       bool ret;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       OSLock(cs_lock);\r
+       {\r
+               ret = OSGetCallStackSymbolInfo(s);\r
+       }\r
+       OSUnlock(cs_lock);\r
+\r
+       return ret;\r
+}\r
+\r
+// コールスタックを指定された数だけ下降する\r
+CALLSTACK_DATA *WalkDownCallStack(CALLSTACK_DATA *s, UINT num)\r
+{\r
+       CALLSTACK_DATA *cs, *tmp;\r
+       UINT i;\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       cs = s;\r
+       i = 0;\r
+\r
+       while (true)\r
+       {\r
+               if (i >= num)\r
+               {\r
+                       return cs;\r
+               }\r
+               i++;\r
+               tmp = cs;\r
+               cs = tmp->next;\r
+               OSMemoryFree(tmp->name);\r
+               OSMemoryFree(tmp);\r
+\r
+               if (cs == NULL)\r
+               {\r
+                       return NULL;\r
+               }\r
+       }\r
+}\r
+\r
+// コールスタックの解放\r
+void FreeCallStack(CALLSTACK_DATA *s)\r
+{\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       while (true)\r
+       {\r
+               CALLSTACK_DATA *next = s->next;\r
+               OSMemoryFree(s->name);\r
+               OSMemoryFree(s);\r
+               if (next == NULL)\r
+               {\r
+                       break;\r
+               }\r
+               s = next;\r
+       }\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Tracking.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Tracking.h
new file mode 100644 (file)
index 0000000..121d348
--- /dev/null
@@ -0,0 +1,164 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Tracking.h\r
+// Tracking.c のヘッダ\r
+\r
+#ifndef        TRACKING_H\r
+#define        TRACKING_H\r
+\r
+// 配列の数\r
+#define        TRACKING_NUM_ARRAY      1048576\r
+\r
+// ポインタから配列番号をハッシュ\r
+#define        TRACKING_HASH(p)        (UINT)(((((UINT64)(p)) / (UINT64)(sizeof(void *))) % ((UINT64)TRACKING_NUM_ARRAY)))\r
+\r
+// コールスタック\r
+struct CALLSTACK_DATA\r
+{\r
+       bool symbol_cache;\r
+       UINT64 offset, disp;\r
+       char *name;\r
+       struct CALLSTACK_DATA *next;\r
+       char filename[MAX_PATH];\r
+       UINT line;\r
+};\r
+\r
+// オブジェクト\r
+struct TRACKING_OBJECT\r
+{\r
+       UINT Id;\r
+       char *Name;\r
+       UINT64 Address;\r
+       UINT Size;\r
+       UINT64 CreatedDate;\r
+       CALLSTACK_DATA *CallStack;\r
+       char FileName[MAX_PATH];\r
+       UINT LineNumber;\r
+};\r
+\r
+// メモリの使用状態\r
+struct MEMORY_STATUS\r
+{\r
+       UINT MemoryBlocksNum;\r
+       UINT MemorySize;\r
+};\r
+\r
+// トラッキングリスト\r
+struct TRACKING_LIST\r
+{\r
+       struct TRACKING_LIST *Next;\r
+       struct TRACKING_OBJECT *Object;\r
+};\r
+\r
+CALLSTACK_DATA *GetCallStack();\r
+bool GetCallStackSymbolInfo(CALLSTACK_DATA *s);\r
+void FreeCallStack(CALLSTACK_DATA *s);\r
+CALLSTACK_DATA *WalkDownCallStack(CALLSTACK_DATA *s, UINT num);\r
+void GetCallStackStr(char *str, UINT size, CALLSTACK_DATA *s);\r
+void PrintCallStack(CALLSTACK_DATA *s);\r
+void InitTracking();\r
+void FreeTracking();\r
+int CompareTrackingObject(const void *p1, const void *p2);\r
+void LockTrackingList();\r
+void UnlockTrackingList();\r
+void InsertTrackingList(TRACKING_OBJECT *o);\r
+void DeleteTrackingList(TRACKING_OBJECT *o, bool free_object_memory);\r
+TRACKING_OBJECT *SearchTrackingList(UINT64 Address);\r
+\r
+void TrackNewObj(UINT64 addr, char *name, UINT size);\r
+void TrackGetObjSymbolInfo(TRACKING_OBJECT *o);\r
+void TrackDeleteObj(UINT64 addr);\r
+void TrackChangeObjSize(UINT64 addr, UINT size, UINT64 new_addr);\r
+\r
+void GetMemoryStatus(MEMORY_STATUS *status);\r
+void PrintMemoryStatus();\r
+void MemoryDebugMenu();\r
+int SortObjectView(void *p1, void *p2);\r
+void DebugPrintAllObjects();\r
+void DebugPrintCommandList();\r
+void PrintObjectList(TRACKING_OBJECT *o);\r
+void PrintObjectInfo(TRACKING_OBJECT *o);\r
+void DebugPrintObjectInfo(UINT id);\r
+\r
+void TrackingEnable();\r
+void TrackingDisable();\r
+bool IsTrackingEnabled();\r
+\r
+#endif // TRACKING_H\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/TunTap.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/TunTap.h
new file mode 100644 (file)
index 0000000..9b3c200
--- /dev/null
@@ -0,0 +1,308 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+#ifndef        TUNTAP_H\r
+#define        TUNTAP_H\r
+\r
+#ifdef UNIX_LINUX\r
+\r
+// -----------------------------------------------------------------\r
+// Linux 用 tap ヘッダ\r
+// -----------------------------------------------------------------\r
+/*\r
+ *  Universal TUN/TAP device driver.\r
+ *  Copyright (C) 1999-2000 Maxim Krasnyansky <max_mk@yahoo.com>\r
+ *\r
+ *  This program is free software; you can redistribute it and/or modify\r
+ *  it under the terms of the GNU General Public License as published by\r
+ *  the Free Software Foundation; either version 2 of the License, or\r
+ *  (at your option) any later version.\r
+ *\r
+ *  This program is distributed in the hope that it will be useful,\r
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ *  GNU General Public License for more details.\r
+ *\r
+ *  $Id: if_tun.h,v 1.2 2001/10/31 15:27:57 arjanv Exp $\r
+ */\r
+\r
+#ifndef __IF_TUN_H\r
+#define __IF_TUN_H\r
+\r
+/* Uncomment to enable debugging */\r
+/* #define TUN_DEBUG 1 */\r
+\r
+\r
+\r
+/* Read queue size */\r
+#define TUN_READQ_SIZE  10\r
+\r
+/* TUN device flags */\r
+#define TUN_TUN_DEV     0x0001  \r
+#define TUN_TAP_DEV     0x0002\r
+#define TUN_TYPE_MASK   0x000f\r
+\r
+#define TUN_FASYNC      0x0010\r
+#define TUN_NOCHECKSUM  0x0020\r
+#define TUN_NO_PI       0x0040\r
+#define TUN_ONE_QUEUE   0x0080\r
+#define TUN_PERSIST     0x0100  \r
+\r
+/* Ioctl defines */\r
+#define TUNSETNOCSUM  _IOW('T', 200, int) \r
+#define TUNSETDEBUG   _IOW('T', 201, int) \r
+#define TUNSETIFF     _IOW('T', 202, int) \r
+#define TUNSETPERSIST _IOW('T', 203, int) \r
+#define TUNSETOWNER   _IOW('T', 204, int)\r
+\r
+/* TUNSETIFF ifr flags */\r
+#define IFF_TUN         0x0001\r
+#define IFF_TAP         0x0002\r
+#define IFF_NO_PI       0x1000\r
+#define IFF_ONE_QUEUE   0x2000\r
+\r
+struct tun_pi {\r
+        unsigned short flags;\r
+        unsigned short proto;\r
+};\r
+#define TUN_PKT_STRIP   0x0001\r
+\r
+#endif /* __IF_TUN_H */\r
+#else  // UNIX_LINUX\r
+\r
+#ifdef UNIX_SOLARIS\r
+\r
+// -----------------------------------------------------------------\r
+// Solaris 用 tap ヘッダ\r
+// -----------------------------------------------------------------\r
+/*\r
+ *  Universal TUN/TAP device driver.\r
+ *\r
+ *  Multithreaded STREAMS tun pseudo device driver.\r
+ *\r
+ *  Copyright (C) 1999-2000 Maxim Krasnyansky <max_mk@yahoo.com>\r
+ *  \r
+ *  This program is free software; you can redistribute it and/or modify\r
+ *  it under the terms of the GNU General Public License as published by\r
+ *  the Free Software Foundation; either version 2 of the License, or\r
+ *  (at your option) any later version.\r
+ *  \r
+ *  This program is distributed in the hope that it will be useful,\r
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ *  GNU General Public License for more details.\r
+ *\r
+ *  $Id: if_tun.h,v 1.4 2000/05/01 12:23:27 maxk Exp $\r
+ */\r
+\r
+#ifndef _SYS_IF_TUN_H\r
+#define _SYS_IF_TUN_H\r
+\r
+#ifdef _KERNEL\r
+/* Uncomment to enable debuging */\r
+/* #define TUN_DEBUG 1 */\r
+\r
+#ifdef TUN_DEBUG\r
+#define DBG      cmn_err\r
+#else\r
+#define DBG( a... )\r
+#endif\r
+\r
+/* PPA structure, one per TUN iface */ \r
+struct tunppa {\r
+  unsigned int id;              /* Iface number         */\r
+  queue_t *rq;                  /* Control Stream RQ    */\r
+  struct tunstr * p_str;        /* Protocol Streams     */\r
+}; \r
+#define TUNMAXPPA       20\r
+\r
+/* Stream structure, one per Stream */\r
+struct tunstr {\r
+  struct tunstr *s_next;        /* next in streams list */\r
+  struct tunstr *p_next;        /* next in ppa list */\r
+  queue_t *rq;                  /* pointer to rq */\r
+\r
+  struct tunppa *ppa;           /* assigned PPA */\r
+  u_long flags;                 /* flags */\r
+  u_long state;                 /* DL state */\r
+  u_long sap;                   /* bound sap */\r
+  u_long minor;                 /* minor device number */\r
+};\r
+\r
+/* Flags */\r
+#define TUN_CONTROL     0x0001\r
+\r
+#define TUN_RAW         0x0100\r
+#define TUN_FAST        0x0200\r
+\r
+#define TUN_ALL_PHY     0x0010\r
+#define TUN_ALL_SAP     0x0020\r
+#define TUN_ALL_MUL     0x0040\r
+\r
+#define SNIFFER(a) ( (a & TUN_ALL_SAP) || (a & TUN_ALL_PHY) )\r
+\r
+struct tundladdr {\r
+  u_short sap;\r
+};\r
+#define TUN_ADDR_LEN    (sizeof(struct tundladdr))\r
+\r
+#define TUN_QUEUE       0\r
+#define TUN_DROP        1\r
+\r
+#endif /* _KERNEL */\r
+\r
+/* IOCTL defines */\r
+#define TUNNEWPPA       (('T'<<16) | 0x0001)\r
+#define TUNSETPPA       (('T'<<16) | 0x0002)\r
+\r
+#endif  /* _SYS_IF_TUN_H */\r
+\r
+#else  // UNIX_SOLARIS\r
+\r
+#ifdef UNIX_BSD\r
+\r
+// -----------------------------------------------------------------\r
+// FreeBSD 用 tap ヘッダ\r
+// -----------------------------------------------------------------\r
+/*      $NetBSD: if_tun.h,v 1.5 1994/06/29 06:36:27 cgd Exp $   */\r
+\r
+/*\r
+ * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>\r
+ * Nottingham University 1987.\r
+ *\r
+ * This source may be freely distributed, however I would be interested\r
+ * in any changes that are made.\r
+ *\r
+ * This driver takes packets off the IP i/f and hands them up to a\r
+ * user process to have its wicked way with. This driver has it's\r
+ * roots in a similar driver written by Phil Cockcroft (formerly) at\r
+ * UCL. This driver is based much more on read/write/select mode of\r
+ * operation though.\r
+ *\r
+ * $FreeBSD: src/sys/net/if_tun.h,v 1.17 2000/01/23 01:47:12 brian Exp $\r
+ */\r
+\r
+#ifndef _NET_IF_TUN_H_\r
+#define _NET_IF_TUN_H_\r
+\r
+/* Refer to if_tunvar.h for the softc stuff */\r
+\r
+/* Maximum transmit packet size (default) */\r
+#define TUNMTU          1500\r
+\r
+/* Maximum receive packet size (hard limit) */\r
+#define TUNMRU          16384\r
+\r
+struct tuninfo {\r
+        int     baudrate;               /* linespeed */\r
+        short   mtu;                    /* maximum transmission unit */\r
+        u_char  type;                   /* ethernet, tokenring, etc. */\r
+        u_char  dummy;                  /* place holder */\r
+};\r
+\r
+/* ioctl's for get/set debug */\r
+#define TUNSDEBUG       _IOW('t', 90, int)\r
+#define TUNGDEBUG       _IOR('t', 89, int)\r
+#define TUNSIFINFO      _IOW('t', 91, struct tuninfo)\r
+#define TUNGIFINFO      _IOR('t', 92, struct tuninfo)\r
+#define TUNSLMODE       _IOW('t', 93, int)\r
+#define TUNSIFMODE      _IOW('t', 94, int)\r
+#define TUNSIFPID       _IO('t', 95)\r
+#define TUNSIFHEAD      _IOW('t', 96, int)\r
+#define TUNGIFHEAD      _IOR('t', 97, int)\r
+\r
+#endif /* !_NET_IF_TUN_H_ */\r
+\r
+#else  // UNIX_BSD\r
+\r
+#ifdef UNIX_MACOS\r
+\r
+// -----------------------------------------------------------------\r
+// MacOS 用 tap ヘッダ\r
+// -----------------------------------------------------------------\r
+\r
+#else  // UNIX_MACOS\r
+\r
+#endif // UNIX_MACOS\r
+\r
+#endif // UNIX_BSD\r
+\r
+#endif // UNIX_SOLARIS\r
+\r
+#endif // UNIX_LINUX\r
+\r
+#endif // TUNTAP_H\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Unix.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Unix.c
new file mode 100644 (file)
index 0000000..8d6c7e4
--- /dev/null
@@ -0,0 +1,2438 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Unix.c\r
+// UNIX 依存コード\r
+\r
+#ifdef UNIX\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+// MacOS X 用の struct statfs\r
+#ifdef UNIX_MACOS\r
+typedef struct fsid { int32_t val[2]; } fsid_t;\r
+struct statfs {\r
+        short   f_otype;                /* TEMPORARY SHADOW COPY OF f_type */\r
+        short   f_oflags;               /* TEMPORARY SHADOW COPY OF f_flags */\r
+        long    f_bsize;                /* fundamental file system block size */\r
+        long    f_iosize;               /* optimal transfer block size */\r
+        long    f_blocks;               /* total data blocks in file system */\r
+        long    f_bfree;                /* free blocks in fs */\r
+        long    f_bavail;               /* free blocks avail to non-superuser */\r
+        long    f_files;                /* total file nodes in file system */\r
+        long    f_ffree;                /* free file nodes in fs */\r
+        fsid_t  f_fsid;                 /* file system id */\r
+        uid_t   f_owner;                /* user that mounted the filesystem */\r
+        short   f_reserved1;    /* spare for later */\r
+        short   f_type;                 /* type of filesystem */\r
+    long        f_flags;                /* copy of mount exported flags */\r
+        long    f_reserved2[2]; /* reserved for future use */\r
+        char    f_fstypename[15]; /* fs type name */\r
+        char    f_mntonname[90];  /* directory on which mounted */\r
+        char    f_mntfromname[90];/* mounted filesystem */\r
+};\r
+#endif // UNIX_MACOS\r
+\r
+// Solaris 用の scandir() 関数\r
+#ifdef UNIX_SOLARIS\r
+#define scandir local_scandir\r
+#define        alphasort local_alphasort\r
+\r
+/*******************************************\r
+ * Copyright Free の互換ルーチン (local_scandir)\r
+ * コピー元: http://www005.upp.so-net.ne.jp/yoga/compile.html\r
+ *******************************************/\r
+\r
+int local_scandir(const char *dir, struct dirent ***namelist,\r
+            int (*select)(const struct dirent *),\r
+            int (*compar)(const struct dirent **, const struct dirent **))\r
+{\r
+  DIR *d;\r
+  struct dirent *entry;\r
+  register int i=0;\r
+  size_t entrysize;\r
+\r
+  if ((d=opendir(dir)) == NULL)\r
+     return(-1);\r
+\r
+  *namelist=NULL;\r
+  while ((entry=readdir(d)) != NULL)\r
+  {\r
+    if (select == NULL || (select != NULL && (*select)(entry)))\r
+    {\r
+      *namelist=(struct dirent **)realloc((void *)(*namelist),\r
+                 (size_t)((i+1)*sizeof(struct dirent *)));\r
+       if (*namelist == NULL) return(-1);\r
+       entrysize=sizeof(struct dirent)-sizeof(entry->d_name)+strlen(entry->d_name)+1;\r
+       (*namelist)[i]=(struct dirent *)malloc(entrysize);\r
+       if ((*namelist)[i] == NULL) return(-1);\r
+       memcpy((*namelist)[i], entry, entrysize);\r
+       i++;\r
+    }\r
+  }\r
+  if (closedir(d)) return(-1);\r
+  if (i == 0) return(-1);\r
+  if (compar != NULL)\r
+    qsort((void *)(*namelist), (size_t)i, sizeof(struct dirent *), compar);\r
+    \r
+  return(i);\r
+}\r
+\r
+int local_alphasort(const struct dirent **a, const struct dirent **b)\r
+{\r
+  return(strcmp((*a)->d_name, (*b)->d_name));\r
+}\r
+\r
+\r
+#endif // UNIX_SOLARIS\r
+\r
+// UNIX 用スレッドデータ\r
+typedef struct UNIXTHREAD\r
+{\r
+       pthread_t thread;\r
+       bool finished;\r
+} UNIXTHREAD;\r
+\r
+// UNIX 用スレッド起動情報\r
+typedef struct UNIXTHREADSTARTUPINFO\r
+{\r
+       THREAD_PROC *thread_proc;\r
+       void *param;\r
+       THREAD *thread;\r
+} UNIXTHREADSTARTUPINFO;\r
+\r
+// UNIX 用スレッド関数プロトタイプ\r
+void *UnixDefaultThreadProc(void *param);\r
+\r
+// 現在のプロセス ID\r
+static pid_t current_process_id = 0;\r
+\r
+// UNIX 用ファイル I/O データ\r
+typedef struct UNIXIO\r
+{\r
+       int fd;\r
+       bool write_mode;\r
+} UNIXIO;\r
+\r
+// UNIX 用ロックファイルデータ\r
+typedef struct UNIXLOCKFILE\r
+{\r
+       char FileName[MAX_SIZE];\r
+       int fd;\r
+} UNIXLOCKFILE;\r
+\r
+// UNIX 用イベントデータ\r
+typedef struct UNIXEVENT\r
+{\r
+       pthread_mutex_t mutex;\r
+       pthread_cond_t cond;\r
+       bool signal;\r
+} UNIXEVENT;\r
+\r
+static pthread_mutex_t get_time_lock;\r
+static pthread_mutex_t malloc_lock;\r
+static bool high_process = false;\r
+\r
+static bool unix_svc_terminate = false;\r
+static int solaris_sleep_p1 = -1, solaris_sleep_p2 = -1;\r
+\r
+// ディスパッチテーブルの作成\r
+OS_DISPATCH_TABLE *UnixGetDispatchTable()\r
+{\r
+       static OS_DISPATCH_TABLE t =\r
+       {\r
+               UnixInit,\r
+               UnixFree,\r
+               UnixMemoryAlloc,\r
+               UnixMemoryReAlloc,\r
+               UnixMemoryFree,\r
+               UnixGetTick,\r
+               UnixGetSystemTime,\r
+               UnixInc32,\r
+               UnixDec32,\r
+               UnixSleep,\r
+               UnixNewLock,\r
+               UnixLock,\r
+               UnixUnlock,\r
+               UnixDeleteLock,\r
+               UnixInitEvent,\r
+               UnixSetEvent,\r
+               UnixResetEvent,\r
+               UnixWaitEvent,\r
+               UnixFreeEvent,\r
+               UnixWaitThread,\r
+               UnixFreeThread,\r
+               UnixInitThread,\r
+               UnixThreadId,\r
+               UnixFileOpen,\r
+               UnixFileOpenW,\r
+               UnixFileCreate,\r
+               UnixFileCreateW,\r
+               UnixFileWrite,\r
+               UnixFileRead,\r
+               UnixFileClose,\r
+               UnixFileFlush,\r
+               UnixFileSize,\r
+               UnixFileSeek,\r
+               UnixFileDelete,\r
+               UnixFileDeleteW,\r
+               UnixMakeDir,\r
+               UnixMakeDirW,\r
+               UnixDeleteDir,\r
+               UnixDeleteDirW,\r
+               UnixGetCallStack,\r
+               UnixGetCallStackSymbolInfo,\r
+               UnixFileRename,\r
+               UnixFileRenameW,\r
+               UnixRun,\r
+               UnixRunW,\r
+               UnixIsSupportedOs,\r
+               UnixGetOsInfo,\r
+               UnixAlert,\r
+               UnixAlertW,\r
+               UnixGetProductId,\r
+               UnixSetHighPriority,\r
+               UnixRestorePriority,\r
+               UnixNewSingleInstance,\r
+               UnixFreeSingleInstance,\r
+               UnixGetMemInfo,\r
+               UnixYield,\r
+       };\r
+\r
+       return &t;\r
+}\r
+\r
+// Solaris 用 Sleep の初期化\r
+void UnixInitSolarisSleep()\r
+{\r
+       char tmp[MAX_SIZE];\r
+\r
+       UnixNewPipe(&solaris_sleep_p1, &solaris_sleep_p2);\r
+       read(solaris_sleep_p1, tmp, sizeof(tmp));\r
+}\r
+\r
+// Solaris 用 Sleep の解放\r
+void UnixFreeSolarisSleep()\r
+{\r
+       UnixDeletePipe(solaris_sleep_p1, solaris_sleep_p2);\r
+       solaris_sleep_p1 = -1;\r
+       solaris_sleep_p2 = -1;\r
+}\r
+\r
+// Solaris 用 Sleep\r
+void UnixSolarisSleep(UINT msec)\r
+{\r
+       struct pollfd p;\r
+\r
+       memset(&p, 0, sizeof(p));\r
+       p.fd = solaris_sleep_p1;\r
+       p.events = POLLIN;\r
+\r
+       poll(&p, 1, msec == INFINITE ? -1 : (int)msec);\r
+}\r
+\r
+// ディスクの空き容量を取得する\r
+bool UnixGetDiskFreeW(wchar_t *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size)\r
+{\r
+       char *path_a = CopyUniToStr(path);\r
+       bool ret;\r
+\r
+       ret = UnixGetDiskFree(path_a, free_size, used_size, total_size);\r
+\r
+       Free(path_a);\r
+\r
+       return ret;\r
+}\r
+bool UnixGetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size)\r
+{\r
+       char tmp[MAX_PATH];\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       NormalizePath(tmp, sizeof(tmp), path);\r
+\r
+       while ((ret = UnixGetDiskFreeMain(tmp, free_size, used_size, total_size)) == false)\r
+       {\r
+               if (StrCmpi(tmp, "/") == 0)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               GetDirNameFromFilePath(tmp, sizeof(tmp), tmp);\r
+       }\r
+\r
+       return ret;\r
+}\r
+bool UnixGetDiskFreeMain(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size)\r
+{\r
+#ifndef        USE_STATVFS\r
+       struct statfs st;\r
+       char tmp[MAX_PATH];\r
+       UINT64 v1 = 0, v2 = 0;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       NormalizePath(tmp, sizeof(tmp), path);\r
+\r
+       Zero(&st, sizeof(st));\r
+       if (statfs(tmp, &st) == 0)\r
+       {\r
+               v1 = (UINT64)st.f_bsize * (UINT64)st.f_bavail;\r
+               v2 = (UINT64)st.f_bsize * (UINT64)st.f_blocks;\r
+               ret = true;\r
+       }\r
+\r
+       if (free_size != NULL)\r
+       {\r
+               *free_size = v1;\r
+       }\r
+\r
+       if (total_size != NULL)\r
+       {\r
+               *total_size = v2;\r
+       }\r
+\r
+       if (used_size != NULL)\r
+       {\r
+               *used_size = v2 - v1;\r
+       }\r
+\r
+       return ret;\r
+#else  // USE_STATVFS\r
+       struct statvfs st;\r
+       char tmp[MAX_PATH];\r
+       UINT64 v1 = 0, v2 = 0;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       NormalizePath(tmp, sizeof(tmp), path);\r
+\r
+       Zero(&st, sizeof(st));\r
+\r
+       if (statvfs(tmp, &st) == 0)\r
+       {\r
+               v1 = (UINT64)st.f_bsize * (UINT64)st.f_bavail;\r
+               v2 = (UINT64)st.f_bsize * (UINT64)st.f_blocks;\r
+               ret = true;\r
+       }\r
+\r
+       if (free_size != NULL)\r
+       {\r
+               *free_size = v1;\r
+       }\r
+\r
+       if (total_size != NULL)\r
+       {\r
+               *total_size = v2;\r
+       }\r
+\r
+       if (used_size != NULL)\r
+       {\r
+               *used_size = v2 - v1;\r
+       }\r
+\r
+       return ret;\r
+#endif // USE_STATVFS\r
+}\r
+\r
+// ディレクトリ列挙\r
+DIRLIST *UnixEnumDirEx(char *dirname, COMPARE *compare)\r
+{\r
+       char tmp[MAX_PATH];\r
+       DIRLIST *d;\r
+       int n;\r
+       struct dirent **e;\r
+       LIST *o;\r
+       // 引数チェック\r
+       if (dirname == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       o = NewListFast(compare);\r
+\r
+       NormalizePath(tmp, sizeof(tmp), dirname);\r
+\r
+       if (StrLen(tmp) >= 1 && tmp[StrLen(tmp) - 1] != '/')\r
+       {\r
+               StrCat(tmp, sizeof(tmp), "/");\r
+       }\r
+\r
+       e = NULL;\r
+       n = scandir(tmp, &e, 0, alphasort);\r
+\r
+       if (StrLen(tmp) >= 1 && tmp[StrLen(tmp) - 1] == '/')\r
+       {\r
+               tmp[StrLen(tmp) - 1] = 0;\r
+       }\r
+\r
+       if (n >= 0 && e != NULL)\r
+       {\r
+               UINT i;\r
+\r
+               for (i = 0;i < (UINT)n;i++)\r
+               {\r
+                       char *filename = e[i]->d_name;\r
+\r
+                       if (filename != NULL)\r
+                       {\r
+                               if (StrCmpi(filename, "..") != 0 && StrCmpi(filename, ".") != 0)\r
+                               {\r
+                                       char fullpath[MAX_PATH];\r
+                                       struct stat st;\r
+                                       Format(fullpath, sizeof(fullpath), "%s/%s", tmp, filename);\r
+\r
+                                       Zero(&st, sizeof(st));\r
+\r
+                                       if (stat(fullpath, &st) == 0)\r
+                                       {\r
+                                               DIRENT *f = ZeroMalloc(sizeof(DIRENT));\r
+                                               SYSTEMTIME t;\r
+\r
+                                               f->Folder = S_ISDIR(st.st_mode) ? true : false;\r
+                                               f->FileName = CopyStr(filename);\r
+                                               f->FileNameW = CopyUtfToUni(f->FileName);\r
+\r
+                                               Zero(&t, sizeof(t));\r
+                                               TimeToSystem(&t, st.st_ctime);\r
+                                               f->CreateDate = LocalToSystem64(SystemToUINT64(&t));\r
+\r
+                                               Zero(&t, sizeof(t));\r
+                                               TimeToSystem(&t, st.st_mtime);\r
+                                               f->UpdateDate = LocalToSystem64(SystemToUINT64(&t));\r
+\r
+                                               if (f->Folder == false)\r
+                                               {\r
+                                                       f->FileSize = st.st_size;\r
+                                               }\r
+\r
+                                               Add(o, f);\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       free(e[i]);\r
+               }\r
+\r
+               free(e);\r
+       }\r
+\r
+       Sort(o);\r
+\r
+       d = ZeroMalloc(sizeof(DIRLIST));\r
+       d->NumFiles = LIST_NUM(o);\r
+       d->File = ToArray(o);\r
+\r
+       ReleaseList(o);\r
+\r
+       return d;\r
+}\r
+DIRLIST *UnixEnumDirExW(wchar_t *dirname, COMPARE *compare)\r
+{\r
+       char *dirname_a = CopyUniToUtf(dirname);\r
+       DIRLIST *ret;\r
+\r
+       ret = UnixEnumDirEx(dirname_a, compare);\r
+\r
+       Free(dirname_a);\r
+\r
+       return ret;\r
+}\r
+\r
+// 指定したファイルの実行権限をチェックする\r
+bool UnixCheckExecAccess(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (access(name, X_OK) == 0)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       return false;\r
+}\r
+bool UnixCheckExecAccessW(wchar_t *name)\r
+{\r
+       char *name_a;\r
+       bool ret;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       name_a = CopyUniToUtf(name);\r
+\r
+       ret = UnixCheckExecAccess(name_a);\r
+\r
+       Free(name_a);\r
+\r
+       return ret;\r
+}\r
+\r
+// スレッドの優先順位を最高にする\r
+void UnixSetThreadPriorityRealtime()\r
+{\r
+       struct sched_param p;\r
+       Zero(&p, sizeof(p));\r
+       p.sched_priority = 255;\r
+       pthread_setschedparam(pthread_self(), SCHED_RR, &p);\r
+}\r
+\r
+// スレッドの優先順位を低くする\r
+void UnixSetThreadPriorityLow()\r
+{\r
+       struct sched_param p;\r
+       Zero(&p, sizeof(p));\r
+       p.sched_priority = 32;\r
+       pthread_setschedparam(pthread_self(), SCHED_OTHER, &p);\r
+}\r
+\r
+// スレッドの優先順位を高くする\r
+void UnixSetThreadPriorityHigh()\r
+{\r
+       struct sched_param p;\r
+       Zero(&p, sizeof(p));\r
+       p.sched_priority = 127;\r
+       pthread_setschedparam(pthread_self(), SCHED_RR, &p);\r
+}\r
+\r
+// スレッドの優先順位をアイドルにする\r
+void UnixSetThreadPriorityIdle()\r
+{\r
+       struct sched_param p;\r
+       Zero(&p, sizeof(p));\r
+       p.sched_priority = 1;\r
+       pthread_setschedparam(pthread_self(), SCHED_OTHER, &p);\r
+}\r
+\r
+// スレッドの優先順位を標準に戻す\r
+void UnixRestoreThreadPriority()\r
+{\r
+       struct sched_param p;\r
+       Zero(&p, sizeof(p));\r
+       p.sched_priority = 64;\r
+       pthread_setschedparam(pthread_self(), SCHED_OTHER, &p);\r
+}\r
+\r
+// 現在のディレクトリの取得\r
+void UnixGetCurrentDir(char *dir, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (dir == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       getcwd(dir, size);\r
+}\r
+void UnixGetCurrentDirW(wchar_t *dir, UINT size)\r
+{\r
+       char dir_a[MAX_PATH];\r
+\r
+       UnixGetCurrentDir(dir_a, sizeof(dir_a));\r
+\r
+       UtfToUni(dir, size, dir_a);\r
+}\r
+\r
+// イールド\r
+void UnixYield()\r
+{\r
+#ifdef UNIX_SOLARIS\r
+       UnixSolarisSleep(1);\r
+#else\r
+       sleep(1);\r
+#endif\r
+}\r
+\r
+// メモリ情報の取得\r
+void UnixGetMemInfo(MEMINFO *info)\r
+{\r
+       // 引数チェック\r
+       if (info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // 知らん!!\r
+       Zero(info, sizeof(MEMINFO));\r
+}\r
+\r
+// シングルインスタンスの解放\r
+void UnixFreeSingleInstance(void *data)\r
+{\r
+       UNIXLOCKFILE *o;\r
+       struct flock lock;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       o = (UNIXLOCKFILE *)data;\r
+\r
+       Zero(&lock, sizeof(lock));\r
+       lock.l_type = F_UNLCK;\r
+       lock.l_whence = SEEK_SET;\r
+\r
+       fcntl(o->fd, F_SETLK, &lock);\r
+       close(o->fd);\r
+\r
+       remove(o->FileName);\r
+\r
+       Free(data);\r
+}\r
+\r
+// シングルインスタンスの作成\r
+void *UnixNewSingleInstance(char *instance_name)\r
+{\r
+       UNIXLOCKFILE *ret;\r
+       char tmp[MAX_SIZE];\r
+       char name[MAX_SIZE];\r
+       char dir[MAX_PATH];\r
+       int fd;\r
+       struct flock lock;\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               GetExeName(tmp, sizeof(tmp));\r
+               HashInstanceName(tmp, sizeof(tmp), tmp);\r
+       }\r
+       else\r
+       {\r
+               StrCpy(tmp, sizeof(tmp), instance_name);\r
+       }\r
+\r
+       GetExeDir(dir, sizeof(dir));\r
+\r
+       // ファイル名の生成\r
+       Format(name, sizeof(name), "%s/.%s", dir, tmp);\r
+\r
+       fd = open(name, O_WRONLY);\r
+       if (fd == -1)\r
+       {\r
+               fd = creat(name, 0600);\r
+       }\r
+       if (fd == -1)\r
+       {\r
+               Format(tmp, sizeof(tmp), "Unable to create %s.", name);\r
+               Alert(tmp, NULL);\r
+               exit(0);\r
+               return NULL;\r
+       }\r
+\r
+       Zero(&lock, sizeof(lock));\r
+       lock.l_type = F_WRLCK;\r
+       lock.l_whence = SEEK_SET;\r
+\r
+       if (fcntl(fd, F_SETLK, &lock) == -1)\r
+       {\r
+               return NULL;\r
+       }\r
+       else\r
+       {\r
+               ret = ZeroMalloc(sizeof(UNIXLOCKFILE));\r
+               ret->fd = fd;\r
+               StrCpy(ret->FileName, sizeof(ret->FileName), name);\r
+               return (void *)ret;\r
+       }\r
+}\r
+\r
+// プロセスの優先順位を上げる\r
+void UnixSetHighPriority()\r
+{\r
+       if (high_process == false)\r
+       {\r
+               UINT pid = getpid();\r
+               UINT pgid = getpgid(pid);\r
+\r
+               high_process = true;\r
+               nice(-20);\r
+\r
+               setpriority(PRIO_PROCESS, pid, -20);\r
+               setpriority(PRIO_PGRP, pgid, -20);\r
+       }\r
+}\r
+\r
+// プロセスの優先順位を戻す\r
+void UnixRestorePriority()\r
+{\r
+       if (high_process != false)\r
+       {\r
+               high_process = false;\r
+               nice(20);\r
+       }\r
+}\r
+\r
+// プロダクト ID を取得する\r
+char *UnixGetProductId()\r
+{\r
+       return CopyStr("--");\r
+}\r
+\r
+// アラートを表示する\r
+void UnixAlertW(wchar_t *msg, wchar_t *caption)\r
+{\r
+       char *msg8 = CopyUniToUtf(msg);\r
+       char *caption8 = CopyUniToUtf(caption);\r
+\r
+       UnixAlert(msg8, caption8);\r
+\r
+       Free(msg8);\r
+       Free(caption8);\r
+}\r
+void UnixAlert(char *msg, char *caption)\r
+{\r
+       char *tag =\r
+               "-- Alert: %s --\n%s\n";\r
+       // 引数チェック\r
+       if (msg == NULL)\r
+       {\r
+               msg = "Alert";\r
+       }\r
+       if (caption == NULL)\r
+       {\r
+               caption = "SoftEther UT-VPN Kernel";\r
+       }\r
+\r
+       printf(tag, caption, msg);\r
+}\r
+\r
+// 現在の OS の情報を取得する\r
+void UnixGetOsInfo(OS_INFO *info)\r
+{\r
+       // 引数チェック\r
+       if (info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(info, sizeof(OS_INFO));\r
+       info->OsType = OSTYPE_UNIX_UNKNOWN;\r
+\r
+#ifdef UNIX_SOLARIS\r
+       info->OsType = OSTYPE_SOLARIS;\r
+#endif // UNIX_SOLARIS\r
+\r
+#ifdef UNIX_CYGWIN\r
+       info->OsType = OSTYPE_CYGWIN;\r
+#endif // UNIX_CYGWIN\r
+\r
+#ifdef UNIX_MACOS\r
+       info->OsType = OSTYPE_MACOS_X;\r
+#endif // UNIX_MACOS\r
+\r
+#ifdef UNIX_BSD\r
+       info->OsType = OSTYPE_BSD;\r
+#endif // UNIX_BSD\r
+\r
+#ifdef UNIX_LINUX\r
+       info->OsType = OSTYPE_LINUX;\r
+#endif // UNIX_LINUX\r
+\r
+       info->OsServicePack = 0;\r
+\r
+       if (info->OsType != OSTYPE_LINUX)\r
+       {\r
+               info->OsSystemName = CopyStr("UNIX");\r
+               info->OsProductName = CopyStr("UNIX");\r
+       }\r
+       else\r
+       {\r
+               info->OsSystemName = CopyStr("Linux");\r
+               info->OsProductName = CopyStr("Linux");\r
+       }\r
+\r
+       if (info->OsType == OSTYPE_LINUX)\r
+       {\r
+               // Linux の場合 ディストリビューション名を取得する\r
+               BUF *b;\r
+               b = ReadDump("/etc/redhat-release");\r
+               if (b != NULL)\r
+               {\r
+                       info->OsVersion = CfgReadNextLine(b);\r
+                       info->OsVendorName = CopyStr("Red Hat, Inc.");\r
+                       FreeBuf(b);\r
+               }\r
+               else\r
+               {\r
+                       b = ReadDump("/etc/turbolinux-release");\r
+                       if (b != NULL)\r
+                       {\r
+                               info->OsVersion = CfgReadNextLine(b);\r
+                               info->OsVendorName = CopyStr("Turbolinux, Inc.");\r
+                               FreeBuf(b);\r
+                       }\r
+                       else\r
+                       {\r
+                               info->OsVersion = CopyStr("Unknown Liunx Version");\r
+                               info->OsVendorName = CopyStr("Unknown Vendor");\r
+                       }\r
+               }\r
+\r
+               info->KernelName = CopyStr("Linux Kernel");\r
+\r
+               b = ReadDump("/proc/sys/kernel/osrelease");\r
+               if (b != NULL)\r
+               {\r
+                       info->KernelVersion = CfgReadNextLine(b);\r
+                       FreeBuf(b);\r
+               }\r
+               else\r
+               {\r
+                       info->KernelVersion = CopyStr("Unknown Version");\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // その他の場合\r
+               info->OsProductName = CopyStr(OsTypeToStr(info->OsType));\r
+               info->OsVersion = CopyStr("Unknown Version");\r
+               info->KernelName = CopyStr(OsTypeToStr(info->OsType));\r
+               info->KernelVersion = CopyStr("Unknown Version");\r
+       }\r
+}\r
+\r
+// 現在の OS が SoftEther UT-VPN Kernel によってサポートされているかどうか調べる\r
+bool UnixIsSupportedOs()\r
+{\r
+       // すべての起動可能な UNIX OS をサポートしている\r
+       return true;\r
+}\r
+\r
+// 指定したコマンドを実行する\r
+bool UnixRunW(wchar_t *filename, wchar_t *arg, bool hide, bool wait)\r
+{\r
+       char *filename8 = CopyUniToUtf(filename);\r
+       char *arg8 = CopyUniToUtf(arg);\r
+       bool ret = UnixRun(filename8, arg8, hide, wait);\r
+\r
+       Free(filename8);\r
+       Free(arg8);\r
+\r
+       return ret;\r
+}\r
+bool UnixRun(char *filename, char *arg, bool hide, bool wait)\r
+{\r
+       TOKEN_LIST *t;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (arg == NULL)\r
+       {\r
+               arg = "";\r
+       }\r
+\r
+       // 子プロセス作成\r
+       ret = fork();\r
+       if (ret == -1)\r
+       {\r
+               // 子プロセス作成失敗\r
+               return false;\r
+       }\r
+\r
+       if (ret == 0)\r
+       {\r
+               Print("", filename, arg);\r
+               // 子プロセス\r
+               if (hide)\r
+               {\r
+                       // 標準入出力を閉じる\r
+                       UnixCloseIO();\r
+               }\r
+\r
+               t = ParseToken(arg, " ");\r
+               if (t == NULL)\r
+               {\r
+                       AbortExit();\r
+               }\r
+               else\r
+               {\r
+                       char **args;\r
+                       UINT num_args;\r
+                       UINT i;\r
+                       num_args = t->NumTokens + 2;\r
+                       args = ZeroMalloc(sizeof(char *) * num_args);\r
+                       args[0] = filename;\r
+                       for (i = 1;i < num_args - 1;i++)\r
+                       {\r
+                               args[i] = t->Token[i - 1];\r
+                       }\r
+                       execvp(filename, args);\r
+                       AbortExit();\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // 親プロセス\r
+               pid_t pid = (pid_t)ret;\r
+\r
+               if (wait)\r
+               {\r
+                       int status = 0;\r
+                       // 子プロセスの終了を待機する\r
+                       if (waitpid(pid, &status, 0) == -1)\r
+                       {\r
+                               return false;\r
+                       }\r
+\r
+                       if (WEXITSTATUS(status) == 0)\r
+                       {\r
+                               return true;\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               return true;\r
+       }\r
+}\r
+\r
+// デーモンの初期化\r
+void UnixDaemon(bool debug_mode)\r
+{\r
+       UINT ret;\r
+\r
+       if (debug_mode)\r
+       {\r
+               // デバッグモード\r
+               signal(SIGHUP, SIG_IGN);\r
+               return;\r
+       }\r
+\r
+       ret = fork();\r
+\r
+       if (ret == -1)\r
+       {\r
+               // エラー\r
+               return;\r
+       }\r
+       else if (ret == 0)\r
+       {\r
+               // 子プロセス用に新しいセッションを作成する\r
+               setsid();\r
+\r
+               // 標準入出力をクローズする\r
+               UnixCloseIO();\r
+\r
+               // 不要なシグナルを停止する\r
+               signal(SIGHUP, SIG_IGN);\r
+       }\r
+       else\r
+       {\r
+               // 親プロセスを終了する\r
+               exit(0);\r
+       }\r
+}\r
+\r
+// 標準入出力をクローズする\r
+void UnixCloseIO()\r
+{\r
+       static bool close_io_first = false;\r
+\r
+       // 1 回しか実行できない\r
+       if (close_io_first)\r
+       {\r
+               return;\r
+       }\r
+       else\r
+       {\r
+               close(0);\r
+               close(1);\r
+               close(2);\r
+               open("/dev/null", O_RDWR);\r
+               dup2(0, 1);\r
+               dup2(0, 2);\r
+               close_io_first = false;\r
+       }\r
+}\r
+\r
+// ファイル名を変更する\r
+bool UnixFileRenameW(wchar_t *old_name, wchar_t *new_name)\r
+{\r
+       char *old_name8 = CopyUniToUtf(old_name);\r
+       char *new_name8 = CopyUniToUtf(new_name);\r
+       bool ret = UnixFileRename(old_name8, new_name8);\r
+\r
+       Free(old_name8);\r
+       Free(new_name8);\r
+\r
+       return ret;\r
+}\r
+bool UnixFileRename(char *old_name, char *new_name)\r
+{\r
+       // 引数チェック\r
+       if (old_name == NULL || new_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (rename(old_name, new_name) != 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// コールスタックを取得する\r
+CALLSTACK_DATA *UnixGetCallStack()\r
+{\r
+       // Win32 以外ではサポートされていない\r
+       return NULL;\r
+}\r
+\r
+// コールスタックからシンボル情報を取得\r
+bool UnixGetCallStackSymbolInfo(CALLSTACK_DATA *s)\r
+{\r
+       // Win32 以外ではサポートされていない\r
+       return false;\r
+}\r
+\r
+// ディレクトリを削除する\r
+bool UnixDeleteDirW(wchar_t *name)\r
+{\r
+       char *name8 = CopyUniToUtf(name);\r
+       bool ret = UnixDeleteDir(name8);\r
+\r
+       Free(name8);\r
+\r
+       return ret;\r
+}\r
+bool UnixDeleteDir(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (rmdir(name) != 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ディレクトリを作成する\r
+bool UnixMakeDirW(wchar_t *name)\r
+{\r
+       char *name8 = CopyUniToUtf(name);\r
+       bool ret = UnixMakeDir(name8);\r
+\r
+       Free(name8);\r
+\r
+       return ret;\r
+}\r
+bool UnixMakeDir(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (mkdir(name, 0700) != 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ファイルを削除する\r
+bool UnixFileDeleteW(wchar_t *name)\r
+{\r
+       bool ret;\r
+       char *name8 = CopyUniToUtf(name);\r
+\r
+       ret = UnixFileDelete(name8);\r
+\r
+       Free(name8);\r
+\r
+       return ret;\r
+}\r
+bool UnixFileDelete(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (remove(name) != 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ファイルをシークする\r
+bool UnixFileSeek(void *pData, UINT mode, int offset)\r
+{\r
+       UNIXIO *p;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (pData == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+       if (mode != FILE_BEGIN && mode != FILE_END && mode != FILE_CURRENT)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = (UNIXIO *)pData;\r
+\r
+       ret = lseek(p->fd, offset, mode);\r
+\r
+       if (ret == -1)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ファイルサイズを取得する\r
+UINT64 UnixFileSize(void *pData)\r
+{\r
+       struct stat st;\r
+       UNIXIO *p;\r
+       // 引数チェック\r
+       if (pData == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       p = (UNIXIO *)pData;\r
+\r
+       if (fstat(p->fd, &st) != 0)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       return (UINT64)st.st_size;\r
+}\r
+\r
+// ファイルに書き込む\r
+bool UnixFileWrite(void *pData, void *buf, UINT size)\r
+{\r
+       UNIXIO *p;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (pData == NULL || buf == NULL || size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = (UNIXIO *)pData;\r
+\r
+       ret = write(p->fd, buf, size);\r
+       if (ret != size)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ファイルから読み込む\r
+bool UnixFileRead(void *pData, void *buf, UINT size)\r
+{\r
+       UNIXIO *p;\r
+       UINT ret;\r
+       // 引数チェック\r
+       if (pData == NULL || buf == NULL || size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = (UNIXIO *)pData;\r
+\r
+       ret = read(p->fd, buf, size);\r
+       if (ret != size)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ファイルをフラッシュする\r
+void UnixFileFlush(void *pData)\r
+{\r
+       UNIXIO *p;\r
+       bool write_mode;\r
+       // 引数チェック\r
+       if (pData == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = (UNIXIO *)pData;\r
+\r
+       write_mode = p->write_mode;\r
+\r
+       if (write_mode)\r
+       {\r
+               fsync(p->fd);\r
+       }\r
+}\r
+\r
+// ファイルを閉じる\r
+void UnixFileClose(void *pData, bool no_flush)\r
+{\r
+       UNIXIO *p;\r
+       bool write_mode;\r
+       // 引数チェック\r
+       if (pData == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = (UNIXIO *)pData;\r
+\r
+       write_mode = p->write_mode;\r
+\r
+       if (write_mode && no_flush == false)\r
+       {\r
+               fsync(p->fd);\r
+       }\r
+\r
+       close(p->fd);\r
+\r
+       UnixMemoryFree(p);\r
+\r
+       if (write_mode)\r
+       {\r
+               //sync();\r
+       }\r
+}\r
+\r
+// ファイルを作成する\r
+void *UnixFileCreateW(wchar_t *name)\r
+{\r
+       void *ret;\r
+       char *name8 = CopyUniToUtf(name);\r
+\r
+       ret = UnixFileCreate(name8);\r
+\r
+       Free(name8);\r
+\r
+       return ret;\r
+}\r
+void *UnixFileCreate(char *name)\r
+{\r
+       UNIXIO *p;\r
+       int fd;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       fd = creat(name, 0600);\r
+       if (fd == -1)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // メモリ確保\r
+       p = UnixMemoryAlloc(sizeof(UNIXIO));\r
+       p->fd = fd;\r
+       p->write_mode = true;\r
+\r
+       return (void *)p;\r
+}\r
+\r
+// ファイルを開く\r
+void *UnixFileOpenW(wchar_t *name, bool write_mode, bool read_lock)\r
+{\r
+       char *name8 = CopyUniToUtf(name);\r
+       void *ret;\r
+\r
+       ret = UnixFileOpen(name8, write_mode, read_lock);\r
+\r
+       Free(name8);\r
+\r
+       return ret;\r
+}\r
+void *UnixFileOpen(char *name, bool write_mode, bool read_lock)\r
+{\r
+       UNIXIO *p;\r
+       int fd;\r
+       int mode;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (write_mode == false)\r
+       {\r
+               mode = O_RDONLY;\r
+       }\r
+       else\r
+       {\r
+               mode = O_RDWR;\r
+       }\r
+\r
+       // ファイルを開く\r
+       fd = open(name, mode);\r
+       if (fd == -1)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // メモリ確保\r
+       p = UnixMemoryAlloc(sizeof(UNIXIO));\r
+       p->fd = fd;\r
+       p->write_mode = write_mode;\r
+\r
+       return (void *)p;\r
+}\r
+\r
+// 現在のスレッド ID を返す\r
+UINT UnixThreadId()\r
+{\r
+       UINT ret;\r
+\r
+       ret = (UINT)pthread_self();\r
+\r
+       return ret;\r
+}\r
+\r
+// スレッド関数\r
+void *UnixDefaultThreadProc(void *param)\r
+{\r
+       UNIXTHREAD *ut;\r
+       UNIXTHREADSTARTUPINFO *info = (UNIXTHREADSTARTUPINFO *)param;\r
+       if (info == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ut = (UNIXTHREAD *)info->thread->pData;\r
+\r
+       // スレッド関数の呼び出し\r
+       info->thread_proc(info->thread, info->param);\r
+\r
+       // 終了フラグを立てる\r
+       ut->finished = true;\r
+\r
+       // 参照の解放\r
+       ReleaseThread(info->thread);\r
+\r
+       UnixMemoryFree(info);\r
+\r
+       FreeOpenSSLThreadState();\r
+\r
+       return 0;\r
+}\r
+\r
+// スレッドの解放\r
+void UnixFreeThread(THREAD *t)\r
+{\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // メモリの解放\r
+       UnixMemoryFree(t->pData);\r
+}\r
+\r
+// スレッドの終了を待機\r
+bool UnixWaitThread(THREAD *t)\r
+{\r
+       UNIXTHREAD *ut;\r
+       void *retcode = NULL;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       ut = (UNIXTHREAD *)t->pData;\r
+       if (ut == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       pthread_join(ut->thread, &retcode);\r
+\r
+       return true;\r
+}\r
+\r
+// スレッドの初期化\r
+bool UnixInitThread(THREAD *t)\r
+{\r
+       UNIXTHREAD *ut;\r
+       UNIXTHREADSTARTUPINFO *info;\r
+       pthread_attr_t attr;\r
+       // 引数チェック\r
+       if (t == NULL || t->thread_proc == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // スレッドデータ作成\r
+       ut = UnixMemoryAlloc(sizeof(UNIXTHREAD));\r
+       Zero(ut, sizeof(UNIXTHREAD));\r
+\r
+       // 起動情報作成\r
+       info = UnixMemoryAlloc(sizeof(UNIXTHREADSTARTUPINFO));\r
+       Zero(info, sizeof(UNIXTHREADSTARTUPINFO));\r
+       info->param = t->param;\r
+       info->thread_proc = t->thread_proc;\r
+       info->thread = t;\r
+       AddRef(t->ref);\r
+\r
+       // スレッド作成\r
+       pthread_attr_init(&attr);\r
+       pthread_attr_setstacksize(&attr, UNIX_THREAD_STACK_SIZE);\r
+\r
+       t->pData = (void *)ut;\r
+\r
+       if (pthread_create(&ut->thread, &attr, UnixDefaultThreadProc, info) != 0)\r
+       {\r
+               // エラー発生\r
+               t->pData = NULL;\r
+               Release(t->ref);\r
+               UnixMemoryFree(ut);\r
+               UnixMemoryFree(info);\r
+               pthread_attr_destroy(&attr);\r
+               return false;\r
+       }\r
+\r
+       pthread_attr_destroy(&attr);\r
+\r
+       return true;\r
+}\r
+\r
+// イベントの解放\r
+void UnixFreeEvent(EVENT *event)\r
+{\r
+       UNIXEVENT *ue = (UNIXEVENT *)event->pData;\r
+       if (ue == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pthread_cond_destroy(&ue->cond);\r
+       pthread_mutex_destroy(&ue->mutex);\r
+\r
+       UnixMemoryFree(ue);\r
+}\r
+\r
+// イベントの待機\r
+bool UnixWaitEvent(EVENT *event, UINT timeout)\r
+{\r
+       UNIXEVENT *ue = (UNIXEVENT *)event->pData;\r
+       struct timeval now;\r
+       struct timespec to;\r
+       bool ret;\r
+       if (ue == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       pthread_mutex_lock(&ue->mutex);\r
+       gettimeofday(&now, NULL);\r
+       to.tv_sec = now.tv_sec + timeout / 1000;\r
+       to.tv_nsec = now.tv_usec * 1000 + (timeout % 1000) * 1000 * 1000;\r
+       if ((to.tv_nsec / 1000000000) >= 1)\r
+       {\r
+               to.tv_sec += to.tv_nsec / 1000000000;\r
+               to.tv_nsec = to.tv_nsec % 1000000000;\r
+       }\r
+\r
+       ret = true;\r
+\r
+       while (ue->signal == false)\r
+       {\r
+               if (timeout != INFINITE)\r
+               {\r
+                       if (pthread_cond_timedwait(&ue->cond, &ue->mutex, &to))\r
+                       {\r
+                               ret = false;\r
+                               break;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       pthread_cond_wait(&ue->cond, &ue->mutex);\r
+               }\r
+       }\r
+       ue->signal = false;\r
+\r
+       pthread_mutex_unlock(&ue->mutex);\r
+\r
+       return ret;\r
+}\r
+\r
+// イベントのリセット\r
+void UnixResetEvent(EVENT *event)\r
+{\r
+       UNIXEVENT *ue = (UNIXEVENT *)event->pData;\r
+       if (ue == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pthread_mutex_lock(&ue->mutex);\r
+       ue->signal = false;\r
+       pthread_cond_signal(&ue->cond);\r
+       pthread_mutex_unlock(&ue->mutex);\r
+}\r
+\r
+// イベントのセット\r
+void UnixSetEvent(EVENT *event)\r
+{\r
+       UNIXEVENT *ue = (UNIXEVENT *)event->pData;\r
+       if (ue == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pthread_mutex_lock(&ue->mutex);\r
+       ue->signal = true;\r
+       pthread_cond_signal(&ue->cond);\r
+       pthread_mutex_unlock(&ue->mutex);\r
+}\r
+\r
+// イベントの初期化\r
+void UnixInitEvent(EVENT *event)\r
+{\r
+       UNIXEVENT *ue = UnixMemoryAlloc(sizeof(UNIXEVENT));\r
+\r
+       Zero(ue, sizeof(UNIXEVENT));\r
+\r
+       pthread_cond_init(&ue->cond, NULL);\r
+       pthread_mutex_init(&ue->mutex, NULL);\r
+       ue->signal = false;\r
+\r
+       event->pData = (void *)ue;\r
+}\r
+\r
+// ロックの削除\r
+void UnixDeleteLock(LOCK *lock)\r
+{\r
+       pthread_mutex_t *mutex;\r
+       // Ready フラグを安全に解除する\r
+       UnixLock(lock);\r
+       lock->Ready = false;\r
+       UnixUnlockEx(lock, true);\r
+\r
+       // mutex の削除\r
+       mutex = (pthread_mutex_t *)lock->pData;\r
+       pthread_mutex_destroy(mutex);\r
+\r
+       // メモリ解放\r
+       UnixMemoryFree(mutex);\r
+       UnixMemoryFree(lock);\r
+}\r
+\r
+// ロック解除\r
+void UnixUnlock(LOCK *lock)\r
+{\r
+       UnixUnlockEx(lock, false);\r
+}\r
+void UnixUnlockEx(LOCK *lock, bool inner)\r
+{\r
+       pthread_mutex_t *mutex;\r
+       if (lock->Ready == false && inner == false)\r
+       {\r
+               // 状態が不正\r
+               return;\r
+       }\r
+       mutex = (pthread_mutex_t *)lock->pData;\r
+\r
+       if ((--lock->locked_count) > 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       lock->thread_id = INFINITE;\r
+\r
+       pthread_mutex_unlock(mutex);\r
+\r
+       return;\r
+}\r
+\r
+// ロック\r
+bool UnixLock(LOCK *lock)\r
+{\r
+       pthread_mutex_t *mutex;\r
+       UINT thread_id = UnixThreadId();\r
+       if (lock->Ready == false)\r
+       {\r
+               // 状態が不正\r
+               return false;\r
+       }\r
+\r
+       if (lock->thread_id == thread_id)\r
+       {\r
+               lock->locked_count++;\r
+               return true;\r
+       }\r
+\r
+       mutex = (pthread_mutex_t *)lock->pData;\r
+\r
+       pthread_mutex_lock(mutex);\r
+\r
+       lock->thread_id = thread_id;\r
+       lock->locked_count++;\r
+\r
+       return true;\r
+}\r
+\r
+// 新しいロックの作成\r
+LOCK *UnixNewLock()\r
+{\r
+       pthread_mutex_t *mutex;\r
+       // メモリ確保\r
+       LOCK *lock = UnixMemoryAlloc(sizeof(LOCK));\r
+\r
+       // mutex 作成\r
+       mutex = UnixMemoryAlloc(sizeof(pthread_mutex_t));\r
+\r
+       // mutex 初期化\r
+       pthread_mutex_init(mutex, NULL);\r
+\r
+       lock->pData = (void *)mutex;\r
+       lock->Ready = true;\r
+\r
+       lock->thread_id = INFINITE;\r
+       lock->locked_count = 0;\r
+\r
+       return lock;\r
+}\r
+\r
+// スリープ\r
+void UnixSleep(UINT time)\r
+{\r
+       UINT sec = 0, millisec = 0;\r
+       // 引数チェック\r
+       if (time == 0)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (time == INFINITE)\r
+       {\r
+               // 無限に待機する\r
+               while (true)\r
+               {\r
+#ifdef UNIX_SOLARIS\r
+                       UnixSolarisSleep(time);\r
+#else\r
+                       sleep(1000000);\r
+#endif\r
+               }\r
+       }\r
+\r
+#ifdef UNIX_SOLARIS\r
+       UnixSolarisSleep(time);\r
+#else\r
+\r
+       // 桁あふれ防止\r
+       sec = time / 1000;\r
+       millisec = time % 1000;\r
+\r
+       if (sec != 0)\r
+       {\r
+               sleep(sec);\r
+       }\r
+       if (millisec != 0)\r
+       {\r
+               usleep(millisec * 1000);\r
+       }\r
+#endif\r
+}\r
+\r
+// デクリメント\r
+void UnixDec32(UINT *value)\r
+{\r
+       if (value != NULL)\r
+       {\r
+               (*value)--;\r
+       }\r
+}\r
+\r
+// インクリメント\r
+void UnixInc32(UINT *value)\r
+{\r
+       if (value != NULL)\r
+       {\r
+               (*value)++;\r
+       }\r
+}\r
+\r
+// システム時刻の取得\r
+void UnixGetSystemTime(SYSTEMTIME *system_time)\r
+{\r
+       time_t now = 0;\r
+       struct tm tm;\r
+       struct timeval tv;\r
+       struct timezone tz;\r
+       // 引数チェック\r
+       if (system_time == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       pthread_mutex_lock(&get_time_lock);\r
+\r
+       Zero(system_time, sizeof(SYSTEMTIME));\r
+       Zero(&tv, sizeof(tv));\r
+       Zero(&tz, sizeof(tz));\r
+\r
+       time(&now);\r
+\r
+       gmtime_r(&now, &tm);\r
+\r
+       TmToSystem(system_time, &tm);\r
+\r
+       gettimeofday(&tv, &tz);\r
+\r
+       system_time->wMilliseconds = tv.tv_usec / 1000;\r
+\r
+       pthread_mutex_unlock(&get_time_lock);\r
+}\r
+\r
+// システムタイマの取得 (64bit)\r
+UINT64 UnixGetTick64()\r
+{\r
+#if    defined(OS_WIN32) || defined(CLOCK_REALTIME) || defined(CLOCK_MONOTONIC) || defined(CLOCK_HIGHRES)\r
+\r
+       struct timespec t;\r
+       UINT64 ret;\r
+       static bool akirame = false;\r
+\r
+       if (akirame)\r
+       {\r
+               return TickRealtimeManual();\r
+       }\r
+\r
+       Zero(&t, sizeof(t));\r
+\r
+       // システムの起動時刻を取得する関数\r
+       // システムによって実装が異なるので注意\r
+#ifdef CLOCK_HIGHRES\r
+       clock_gettime(CLOCK_HIGHRES, &t);\r
+#else  // CLOCK_HIGHRES\r
+#ifdef CLOCK_MONOTONIC\r
+       clock_gettime(CLOCK_MONOTONIC, &t);\r
+#else  // CLOCK_MONOTONIC\r
+       clock_gettime(CLOCK_REALTIME, &t);\r
+#endif // CLOCK_MONOTONIC\r
+#endif // CLOCK_HIGHRES\r
+\r
+       ret = (UINT64)t.tv_sec * 1000LL + (UINT64)t.tv_nsec / 1000000LL;\r
+\r
+       if (akirame == false && ret == 0)\r
+       {\r
+               ret = TickRealtimeManual();\r
+               akirame = true;\r
+       }\r
+\r
+       return ret;\r
+\r
+#else\r
+\r
+       return TickRealtimeManual();\r
+\r
+#endif\r
+}\r
+\r
+// システムタイマの取得\r
+UINT UnixGetTick()\r
+{\r
+       return (UINT)UnixGetTick64();\r
+}\r
+\r
+// メモリの確保\r
+void *UnixMemoryAlloc(UINT size)\r
+{\r
+       void *r;\r
+       pthread_mutex_lock(&malloc_lock);\r
+       r = malloc(size);\r
+       pthread_mutex_unlock(&malloc_lock);\r
+       return r;\r
+}\r
+\r
+// メモリの再確保\r
+void *UnixMemoryReAlloc(void *addr, UINT size)\r
+{\r
+       void *r;\r
+       pthread_mutex_lock(&malloc_lock);\r
+       r = realloc(addr, size);\r
+       pthread_mutex_unlock(&malloc_lock);\r
+       return r;\r
+}\r
+\r
+// メモリの解放\r
+void UnixMemoryFree(void *addr)\r
+{\r
+       pthread_mutex_lock(&malloc_lock);\r
+       free(addr);\r
+       pthread_mutex_unlock(&malloc_lock);\r
+}\r
+\r
+// SIGCHLD ハンドラ\r
+void UnixSigChldHandler(int sig)\r
+{\r
+       // ゾンビプロセスの回収\r
+       while (waitpid(-1, NULL, WNOHANG) > 0);\r
+       signal(SIGCHLD, UnixSigChldHandler);\r
+}\r
+\r
+// UNIX 用ライブラリの初期化\r
+void UnixInit()\r
+{\r
+       UNIXIO *o;\r
+\r
+       UnixInitSolarisSleep();\r
+\r
+       // グローバルロック\r
+       pthread_mutex_init(&get_time_lock, NULL);\r
+       pthread_mutex_init(&malloc_lock, NULL);\r
+\r
+       // プロセス ID の取得\r
+       current_process_id = getpid();\r
+\r
+#ifdef RLIMIT_CORE\r
+       UnixSetResourceLimit(RLIMIT_CORE, UNIX_MAX_MEMORY);\r
+#endif // RLIMIT_CORE\r
+\r
+#ifdef RLIMIT_DATA\r
+       UnixSetResourceLimit(RLIMIT_DATA, UNIX_MAX_MEMORY);\r
+#endif // RLIMIT_DATA\r
+\r
+#ifdef RLIMIT_NOFILE\r
+       UnixSetResourceLimit(RLIMIT_NOFILE, UNIX_MAX_FD);\r
+#endif // RLIMIT_NOFILE\r
+\r
+#ifdef RLIMIT_STACK\r
+//     UnixSetResourceLimit(RLIMIT_STACK, UNIX_MAX_MEMORY);\r
+#endif // RLIMIT_STACK\r
+\r
+#ifdef RLIMIT_RSS\r
+       UnixSetResourceLimit(RLIMIT_RSS, UNIX_MAX_MEMORY);\r
+#endif // RLIMIT_RSS\r
+\r
+#ifdef RLIMIT_LOCKS\r
+       UnixSetResourceLimit(RLIMIT_LOCKS, UNIX_MAX_LOCKS);\r
+#endif // RLIMIT_LOCKS\r
+\r
+#ifdef RLIMIT_MEMLOCK\r
+       UnixSetResourceLimit(RLIMIT_MEMLOCK, UNIX_MAX_MEMORY);\r
+#endif // RLIMIT_MEMLOCK\r
+\r
+#ifdef RLIMIT_NPROC\r
+       UnixSetResourceLimit(RLIMIT_NPROC, UNIX_MAX_CHILD_PROCESSES);\r
+#endif // RLIMIT_NPROC\r
+\r
+       // proc ファイルシステムの threads-max に値を書き込む\r
+       o = UnixFileCreate("/proc/sys/kernel/threads-max");\r
+       if (o != NULL)\r
+       {\r
+               char tmp[128];\r
+               sprintf(tmp, "%u\n", UNIX_LINUX_MAX_THREADS);\r
+               UnixFileWrite(o, tmp, strlen(tmp));\r
+               UnixFileClose(o, false);\r
+       }\r
+\r
+       // 無視するシグナルを設定\r
+       signal(SIGPIPE, SIG_IGN);\r
+       signal(SIGALRM, SIG_IGN);\r
+\r
+#ifdef UNIX_BSD\r
+       signal(64, SIG_IGN);\r
+#endif // UNIX_BSD\r
+\r
+#ifdef SIGXFSZ\r
+       signal(SIGXFSZ, SIG_IGN);\r
+#endif // SIGXFSZ\r
+\r
+       // 子プロセス回収用シグナルハンドラの設定\r
+       signal(SIGCHLD, UnixSigChldHandler);\r
+}\r
+\r
+// UNIX 用ライブラリの解放\r
+void UnixFree()\r
+{\r
+       UnixFreeSolarisSleep();\r
+\r
+       current_process_id = 0;\r
+\r
+       pthread_mutex_destroy(&get_time_lock);\r
+}\r
+\r
+// 占有することができる資源の上限値を調整\r
+void UnixSetResourceLimit(UINT id, UINT value)\r
+{\r
+       struct rlimit t;\r
+       UINT hard_limit;\r
+\r
+       Zero(&t, sizeof(t));\r
+       getrlimit(id, &t);\r
+\r
+       hard_limit = t.rlim_max;\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.rlim_cur = MIN(value, hard_limit);\r
+       t.rlim_max = hard_limit;\r
+       setrlimit(id, &t);\r
+\r
+       Zero(&t, sizeof(t));\r
+       t.rlim_cur = value;\r
+       t.rlim_max = value;\r
+       setrlimit(id, &t);\r
+}\r
+\r
+// PID ファイル名を生成する\r
+void UnixGenPidFileName(char *name, UINT size)\r
+{\r
+       char exe_name[MAX_PATH];\r
+       UCHAR hash[MD5_SIZE];\r
+       char tmp1[64];\r
+       char dir[MAX_PATH];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetExeDir(dir, sizeof(dir));\r
+\r
+       GetExeName(exe_name, sizeof(exe_name));\r
+       StrCat(exe_name, sizeof(exe_name), ":pid_hash");\r
+       StrUpper(exe_name);\r
+\r
+       Hash(hash, exe_name, StrLen(exe_name), false);\r
+       BinToStr(tmp1, sizeof(tmp1), hash, sizeof(hash));\r
+\r
+       Format(name, size, "%s/.pid_%s", dir, tmp1);\r
+}\r
+\r
+// PID ファイルを削除する\r
+void UnixDeletePidFile()\r
+{\r
+       char tmp[MAX_PATH];\r
+\r
+       UnixGenPidFileName(tmp, sizeof(tmp));\r
+\r
+       UnixFileDelete(tmp);\r
+}\r
+\r
+// PID ファイルに書き込む\r
+void UnixWritePidFile(UINT pid)\r
+{\r
+       char tmp[MAX_PATH];\r
+       char tmp2[64];\r
+       IO *o;\r
+\r
+       UnixGenPidFileName(tmp, sizeof(tmp));\r
+       Format(tmp2, sizeof(tmp2), "%u\n", pid);\r
+\r
+       o = FileCreate(tmp);\r
+       if (o != NULL)\r
+       {\r
+               FileWrite(o, tmp2, StrLen(tmp2));\r
+               FileClose(o);\r
+       }\r
+}\r
+\r
+// PID ファイルを読み込む\r
+UINT UnixReadPidFile()\r
+{\r
+       char tmp[MAX_PATH];\r
+       BUF *buf;\r
+\r
+       UnixGenPidFileName(tmp, sizeof(tmp));\r
+\r
+       buf = ReadDump(tmp);\r
+       if (buf == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Zero(tmp, sizeof(tmp));\r
+       Copy(tmp, buf->Buf, MIN(buf->Size, sizeof(tmp)));\r
+       FreeBuf(buf);\r
+\r
+       return ToInt(tmp);\r
+}\r
+\r
+// サービスの開始\r
+void UnixStartService(char *name)\r
+{\r
+       char *svc_name, *svc_title;\r
+       char tmp[128];\r
+       INSTANCE *inst;\r
+       char exe[MAX_PATH];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetExeName(exe, sizeof(exe));\r
+\r
+       Format(tmp, sizeof(tmp), SVC_NAME, name);\r
+       svc_name = _SS(tmp);\r
+       Format(tmp, sizeof(tmp), SVC_TITLE, name);\r
+       svc_title = _SS(tmp);\r
+\r
+       // すでにサービスが起動していないかどうか調べる\r
+       inst = NewSingleInstance(NULL);\r
+       if (inst == NULL)\r
+       {\r
+               // すでにサービスが起動している\r
+               UniPrint(_UU("UNIX_SVC_ALREADY_START"), svc_title, svc_name);\r
+       }\r
+       else\r
+       {\r
+               int pid;\r
+               // サービスの起動を開始する\r
+               UniPrint(_UU("UNIX_SVC_STARTED"), svc_title);\r
+               FreeSingleInstance(inst);\r
+\r
+               // 子プロセスを作成する\r
+               pid = fork();\r
+               if (pid == -1)\r
+               {\r
+                       UniPrint(_UU("UNIX_SVC_ERROR_FORK"), svc_title);\r
+               }\r
+               else\r
+               {\r
+                       if (pid == 0)\r
+                       {\r
+                               // 子プロセス\r
+                               char *param = UNIX_SVC_ARG_EXEC_SVC;\r
+                               char **args;\r
+\r
+                               // デーモン化する\r
+                               setsid();\r
+                               UnixCloseIO();\r
+                               signal(SIGHUP, SIG_IGN);\r
+\r
+                               // 引数を準備\r
+                               args = ZeroMalloc(sizeof(char *) * 3);\r
+                               args[0] = exe;\r
+                               args[1] = param;\r
+                               args[2] = NULL;\r
+\r
+                               execvp(exe, args);\r
+                               AbortExit();\r
+                       }\r
+                       else\r
+                       {\r
+                               // 子プロセス番号をファイルに書き込まない\r
+//                             UnixWritePidFile(pid);\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+// サービスの停止\r
+void UnixStopService(char *name)\r
+{\r
+       char *svc_name, *svc_title;\r
+       char tmp[128];\r
+       INSTANCE *inst;\r
+       char exe[MAX_PATH];\r
+       UINT pid;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetExeName(exe, sizeof(exe));\r
+\r
+       Format(tmp, sizeof(tmp), SVC_NAME, name);\r
+       svc_name = _SS(tmp);\r
+       Format(tmp, sizeof(tmp), SVC_TITLE, name);\r
+       svc_title = _SS(tmp);\r
+\r
+       inst = NewSingleInstance(NULL);\r
+       pid = UnixReadPidFile();\r
+       if (inst != NULL || pid == 0)\r
+       {\r
+               // まだサービスが起動していない\r
+               UniPrint(_UU("UNIX_SVC_NOT_STARTED"), svc_title, svc_name);\r
+       }\r
+       else\r
+       {\r
+               int status;\r
+\r
+               // サービスを停止する\r
+               UniPrint(_UU("UNIX_SVC_STOPPING"), svc_title);\r
+\r
+               // プロセスを終了する\r
+               kill(pid, SIGTERM);\r
+               if (UnixWaitProcessEx(pid, UNIX_SERVICE_STOP_TIMEOUT_2))\r
+               {\r
+                       UniPrint(_UU("UNIX_SVC_STOPPED"), svc_title);\r
+               }\r
+               else\r
+               {\r
+                       UniPrint(_UU("UNIX_SVC_STOP_FAILED"), svc_title);\r
+               }\r
+       }\r
+\r
+       FreeSingleInstance(inst);\r
+}\r
+\r
+// プロセスへの停止シグナルのハンドラ\r
+void UnixSigTermHandler(int signum)\r
+{\r
+       if (signum == SIGTERM)\r
+       {\r
+               unix_svc_terminate = true;\r
+       }\r
+}\r
+\r
+// サービス停止用スレッド\r
+void UnixStopThread(THREAD *t, void *param)\r
+{\r
+       SERVICE_FUNCTION *stop = (SERVICE_FUNCTION *)param;\r
+       // 引数チェック\r
+       if (t == NULL || param == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       stop();\r
+}\r
+\r
+// サービスの内容の実行\r
+void UnixExecService(char *name, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop)\r
+{\r
+       char *svc_name, *svc_title;\r
+       char tmp[128];\r
+       INSTANCE *inst;\r
+       UINT yobi_size = 1024 * 128;\r
+       void *yobi1, *yobi2;\r
+       // 引数チェック\r
+       if (start == NULL || stop == NULL || name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), SVC_NAME, name);\r
+       svc_name = _SS(tmp);\r
+       Format(tmp, sizeof(tmp), SVC_TITLE, name);\r
+       svc_title = _SS(tmp);\r
+\r
+       inst = NewSingleInstance(NULL);\r
+       if (inst != NULL)\r
+       {\r
+               THREAD *t;\r
+\r
+               yobi1 = ZeroMalloc(yobi_size);\r
+               yobi2 = ZeroMalloc(yobi_size);\r
+\r
+               // 起動\r
+               UnixWritePidFile(getpid());\r
+\r
+               start();\r
+\r
+               // 起動完了 別のプロセスから SIGTERM が送られてくるのを待つ\r
+               signal(SIGTERM, &UnixSigTermHandler);\r
+               while (unix_svc_terminate == false)\r
+               {\r
+                       pause();\r
+               }\r
+\r
+               // 停止\r
+               Free(yobi1);\r
+               t = NewThread(UnixStopThread, stop);\r
+               if (t == NULL || (WaitThread(t, UNIX_SERVICE_STOP_TIMEOUT_1) == false))\r
+               {\r
+                       // 停止用スレッドの作成に失敗したか、タイムアウトした場合は\r
+                       // 強制終了する\r
+                       Free(yobi2);\r
+                       FreeSingleInstance(inst);\r
+                       UnixDeletePidFile();\r
+                       _exit(0);\r
+               }\r
+               ReleaseThread(t);\r
+\r
+               // PID ファイルを削除\r
+               UnixDeletePidFile();\r
+\r
+               FreeSingleInstance(inst);\r
+\r
+               Free(yobi2);\r
+       }\r
+}\r
+\r
+// 指定した pid のプロセスが存在するかどうか取得する\r
+bool UnixIsProcess(UINT pid)\r
+{\r
+       if (getsid((pid_t)pid) == -1)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// 指定したプロセスの終了を待機する\r
+bool UnixWaitProcessEx(UINT pid,  UINT timeout)\r
+{\r
+       UINT64 start_tick = Tick64();\r
+       UINT64 end_tick = start_tick + (UINT64)timeout;\r
+       if (timeout == INFINITE)\r
+       {\r
+               end_tick = 0;\r
+       }\r
+       while (UnixIsProcess(pid))\r
+       {\r
+               if (end_tick != 0)\r
+               {\r
+                       if (end_tick < Tick64())\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+               SleepThread(100);\r
+       }\r
+       return true;\r
+}\r
+void UnixWaitProcess(UINT pid)\r
+{\r
+       UnixWaitProcessEx(pid, INFINITE);\r
+}\r
+\r
+// 起動方法の説明\r
+void UnixUsage(char *name)\r
+{\r
+       char *svc_name, *svc_title;\r
+       char tmp[128];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Format(tmp, sizeof(tmp), SVC_NAME, name);\r
+       svc_name = _SS(tmp);\r
+       Format(tmp, sizeof(tmp), SVC_TITLE, name);\r
+       svc_title = _SS(tmp);\r
+\r
+       UniPrint(_UU("UNIX_SVC_HELP"), svc_title, svc_name, svc_name, svc_title, svc_name, svc_title);\r
+}\r
+\r
+// UNIX サービスのメイン関数\r
+UINT UnixService(int argc, char *argv[], char *name, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL || start == NULL || stop == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (argc >= 2 && StrCmpi(argv[1], UNIX_SVC_ARG_EXEC_SVC) == 0)\r
+       {\r
+               UINT pid;\r
+               // 子プロセスを生成して開始する\r
+               // もし子プロセスが正しく終了しなかった場合は再起動する\r
+\r
+RESTART_PROCESS:\r
+               pid = fork();\r
+               if ((int)pid != -1)\r
+               {\r
+                       if (pid == 0)\r
+                       {\r
+                               // メイン処理の実行\r
+                               UnixServiceMain(argc, argv, name, start, stop);\r
+                       }\r
+                       else\r
+                       {\r
+                               int status = 0, ret;\r
+\r
+                               // 子プロセスの終了を待機する\r
+                               ret = waitpid(pid, &status, 0);\r
+\r
+                               if (WIFEXITED(status) == 0)\r
+                               {\r
+                                       // 異常終了した\r
+                                       UnixSleep(100);\r
+                                       goto RESTART_PROCESS;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // 通常に開始する\r
+               UnixServiceMain(argc, argv, name, start, stop);\r
+       }\r
+\r
+       return 0;\r
+}\r
+void UnixServiceMain(int argc, char *argv[], char *name, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop)\r
+{\r
+       UINT mode = 0;\r
+       // Mayaqua の開始\r
+       InitMayaqua(false, false, argc, argv);\r
+\r
+       if (argc >= 2)\r
+       {\r
+               if (StrCmpi(argv[1], UNIX_SVC_ARG_START) == 0)\r
+               {\r
+                       mode = UNIX_SVC_MODE_START;\r
+               }\r
+               if (StrCmpi(argv[1], UNIX_SVC_ARG_STOP) == 0)\r
+               {\r
+                       mode = UNIX_SVC_MODE_STOP;\r
+               }\r
+               if (StrCmpi(argv[1], UNIX_SVC_ARG_EXEC_SVC) == 0)\r
+               {\r
+                       mode = UNIX_SVC_MODE_EXEC_SVC;\r
+               }\r
+               if (StrCmpi(argv[1], UNIX_ARG_EXIT) == 0)\r
+               {\r
+                       mode = UNIX_SVC_MODE_EXIT;\r
+               }\r
+       }\r
+\r
+       switch (mode)\r
+       {\r
+       case UNIX_SVC_MODE_EXIT:\r
+               break;\r
+\r
+       case UNIX_SVC_MODE_START:\r
+               UnixStartService(name);\r
+               break;\r
+\r
+       case UNIX_SVC_MODE_STOP:\r
+               UnixStopService(name);\r
+               break;\r
+\r
+       case UNIX_SVC_MODE_EXEC_SVC:\r
+               UnixExecService(name, start, stop);\r
+               break;\r
+\r
+       default:\r
+               UnixUsage(name);\r
+               break;\r
+       }\r
+\r
+       // Mayaquq の終了\r
+       FreeMayaqua();\r
+\r
+       return;\r
+}\r
+\r
+#endif // UNIX\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Unix.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Unix.h
new file mode 100644 (file)
index 0000000..9607213
--- /dev/null
@@ -0,0 +1,219 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Unix.h\r
+// Unix.c のヘッダ\r
+\r
+#ifdef OS_UNIX\r
+\r
+#ifndef        UNIX_H\r
+#define        UNIX_H\r
+\r
+// 定数\r
+#define        UNIX_THREAD_STACK_SIZE                  (200 * 1000)    // スタックサイズ\r
+#define        UNIX_MAX_CHILD_PROCESSES                2000000                 // 最大子プロセス数\r
+#define        UNIX_LINUX_MAX_THREADS                  200000000               // 最大スレッド数\r
+#define        UNIX_MAX_LOCKS                                  65536                   // 最大ロック数\r
+#define        UNIX_MAX_MEMORY                                 (2147483648UL)  // 最大メモリ容量\r
+#define        UNIX_MAX_FD                                             (655360)                // 最大 FD 数\r
+#define        MAXIMUM_WAIT_OBJECTS                    64                              // 最大 select 数\r
+\r
+#define        UNIX_SERVICE_STOP_TIMEOUT_1             (600 * 1000)    // サービス停止までのタイムアウト\r
+#define        UNIX_SERVICE_STOP_TIMEOUT_2             (900 * 1000)    // サービス停止までのタイムアウト (親プロセス)\r
+\r
+\r
+// サービス関係\r
+typedef void (SERVICE_FUNCTION)();\r
+\r
+#define        SVC_NAME                                        "SVC_%s_NAME"\r
+#define        SVC_TITLE                                       "SVC_%s_TITLE"\r
+\r
+#define        UNIX_SVC_ARG_START                              "start"\r
+#define        UNIX_SVC_ARG_STOP                               "stop"\r
+#define        UNIX_SVC_ARG_EXEC_SVC                   "execsvc"\r
+#define        UNIX_ARG_EXIT                                   "exit"\r
+\r
+#define        UNIX_SVC_MODE_START                             1\r
+#define        UNIX_SVC_MODE_STOP                              2\r
+#define        UNIX_SVC_MODE_EXEC_SVC                  3\r
+#define        UNIX_SVC_MODE_EXIT                              4\r
+\r
+\r
+// 関数プロトタイプ\r
+OS_DISPATCH_TABLE *UnixGetDispatchTable();\r
+void UnixInit();\r
+void UnixFree();\r
+void *UnixMemoryAlloc(UINT size);\r
+void *UnixMemoryReAlloc(void *addr, UINT size);\r
+void UnixMemoryFree(void *addr);\r
+UINT UnixGetTick();\r
+void UnixGetSystemTime(SYSTEMTIME *system_time);\r
+void UnixInc32(UINT *value);\r
+void UnixDec32(UINT *value);\r
+void UnixSleep(UINT time);\r
+LOCK *UnixNewLock();\r
+bool UnixLock(LOCK *lock);\r
+void UnixUnlock(LOCK *lock);\r
+void UnixUnlockEx(LOCK *lock, bool inner);\r
+void UnixDeleteLock(LOCK *lock);\r
+void UnixInitEvent(EVENT *event);\r
+void UnixSetEvent(EVENT *event);\r
+void UnixResetEvent(EVENT *event);\r
+bool UnixWaitEvent(EVENT *event, UINT timeout);\r
+void UnixFreeEvent(EVENT *event);\r
+bool UnixWaitThread(THREAD *t);\r
+void UnixFreeThread(THREAD *t);\r
+bool UnixInitThread(THREAD *t);\r
+UINT UnixThreadId();\r
+void *UnixFileOpen(char *name, bool write_mode, bool read_lock);\r
+void *UnixFileOpenW(wchar_t *name, bool write_mode, bool read_lock);\r
+void *UnixFileCreate(char *name);\r
+void *UnixFileCreateW(wchar_t *name);\r
+bool UnixFileWrite(void *pData, void *buf, UINT size);\r
+bool UnixFileRead(void *pData, void *buf, UINT size);\r
+void UnixFileClose(void *pData, bool no_flush);\r
+void UnixFileFlush(void *pData);\r
+UINT64 UnixFileSize(void *pData);\r
+bool UnixFileSeek(void *pData, UINT mode, int offset);\r
+bool UnixFileDelete(char *name);\r
+bool UnixFileDeleteW(wchar_t *name);\r
+bool UnixMakeDir(char *name);\r
+bool UnixMakeDirW(wchar_t *name);\r
+bool UnixDeleteDir(char *name);\r
+bool UnixDeleteDirW(wchar_t *name);\r
+CALLSTACK_DATA *UnixGetCallStack();\r
+bool UnixGetCallStackSymbolInfo(CALLSTACK_DATA *s);\r
+bool UnixFileRename(char *old_name, char *new_name);\r
+bool UnixFileRenameW(wchar_t *old_name, wchar_t *new_name);\r
+bool UnixRun(char *filename, char *arg, bool hide, bool wait);\r
+bool UnixRunW(wchar_t *filename, wchar_t *arg, bool hide, bool wait);\r
+bool UnixIsSupportedOs();\r
+void UnixGetOsInfo(OS_INFO *info);\r
+void UnixAlert(char *msg, char *caption);\r
+void UnixAlertW(wchar_t *msg, wchar_t *caption);\r
+char *UnixGetProductId();\r
+void UnixSetHighPriority();\r
+void UnixRestorePriority();\r
+void *UnixNewSingleInstance(char *instance_name);\r
+void UnixFreeSingleInstance(void *data);\r
+void UnixGetMemInfo(MEMINFO *info);\r
+void UnixYield();\r
+\r
+\r
+void UnixSetThreadPriorityRealtime();\r
+void UnixSetThreadPriorityLow();\r
+void UnixSetThreadPriorityHigh();\r
+void UnixSetThreadPriorityIdle();\r
+void UnixRestoreThreadPriority();\r
+void UnixSetResourceLimit(UINT id, UINT value);\r
+UINT64 UnixGetTick64();\r
+void UnixSigChldHandler(int sig);\r
+void UnixCloseIO();\r
+void UnixDaemon(bool debug_mode);\r
+void UnixGetCurrentDir(char *dir, UINT size);\r
+void UnixGetCurrentDirW(wchar_t *dir, UINT size);\r
+bool UnixCheckExecAccess(char *name);\r
+bool UnixCheckExecAccessW(wchar_t *name);\r
+DIRLIST *UnixEnumDirEx(char *dirname, COMPARE *compare);\r
+DIRLIST *UnixEnumDirExW(wchar_t *dirname, COMPARE *compare);\r
+bool UnixGetDiskFreeMain(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size);\r
+bool UnixGetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size);\r
+bool UnixGetDiskFreeW(wchar_t *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size);\r
+void UnixInitSolarisSleep();\r
+void UnixFreeSolarisSleep();\r
+void UnixSolarisSleep(UINT msec);\r
+\r
+UINT UnixService(int argc, char *argv[], char *name, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop);\r
+void UnixServiceMain(int argc, char *argv[], char *name, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop);\r
+void UnixGenPidFileName(char *name, UINT size);\r
+void UnixStartService(char *name);\r
+void UnixStopService(char *name);\r
+void UnixExecService(char *name, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop);\r
+void UnixUsage(char *name);\r
+void UnixWritePidFile(UINT pid);\r
+UINT UnixReadPidFile();\r
+bool UnixIsProcess(UINT pid);\r
+bool UnixWaitProcessEx(UINT pid, UINT timeout);\r
+void UnixWaitProcess(UINT pid);\r
+void UnixDeletePidFile();\r
+void UnixStopThread(THREAD *t, void *param);\r
+\r
+\r
+#endif // UNIX_H\r
+\r
+#endif // OS_UNIX\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Win32.c b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Win32.c
new file mode 100644 (file)
index 0000000..7c9f7d4
--- /dev/null
@@ -0,0 +1,3165 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Win32.c\r
+// Microsoft Windows 依存コード\r
+\r
+#ifdef WIN32\r
+\r
+#define        _WIN32_WINNT            0x0502\r
+#define        WINVER                          0x0502\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+#include <Dbghelp.h>\r
+#include <commctrl.h>\r
+#include <process.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <errno.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+\r
+static HANDLE heap_handle = NULL;\r
+static HANDLE hstdout = INVALID_HANDLE_VALUE;\r
+static HANDLE hstdin = INVALID_HANDLE_VALUE;\r
+\r
+// Win32 用スレッドデータ\r
+typedef struct WIN32THREAD\r
+{\r
+       HANDLE hThread;\r
+       DWORD thread_id;\r
+} WIN32THREAD;\r
+\r
+// Win32 用スレッド起動情報\r
+typedef struct WIN32THREADSTARTUPINFO\r
+{\r
+       THREAD_PROC *thread_proc;\r
+       void *param;\r
+       THREAD *thread;\r
+} WIN32THREADSTARTUPINFO;\r
+\r
+// Win32 用関数プロトタイプ\r
+DWORD CALLBACK Win32DefaultThreadProc(void *param);\r
+\r
+// 現在のプロセスハンドル\r
+static HANDLE hCurrentProcessHandle = NULL;\r
+static CRITICAL_SECTION fasttick_lock;\r
+static UINT64 start_tick = 0;\r
+static bool use_heap_api = false;\r
+static bool win32_is_nt = false;\r
+\r
+// Win32 用ファイル I/O データ\r
+typedef struct WIN32IO\r
+{\r
+       HANDLE hFile;\r
+       bool WriteMode;\r
+} WIN32IO;\r
+\r
+// Win32 用ミューテックスデータ\r
+typedef struct WIN32MUTEX\r
+{\r
+       HANDLE hMutex;\r
+} WIN32MUTEX;\r
+\r
+// ディスパッチテーブルの作成\r
+OS_DISPATCH_TABLE *Win32GetDispatchTable()\r
+{\r
+       static OS_DISPATCH_TABLE t =\r
+       {\r
+               Win32Init,\r
+               Win32Free,\r
+               Win32MemoryAlloc,\r
+               Win32MemoryReAlloc,\r
+               Win32MemoryFree,\r
+               Win32GetTick,\r
+               Win32GetSystemTime,\r
+               Win32Inc32,\r
+               Win32Dec32,\r
+               Win32Sleep,\r
+               Win32NewLock,\r
+               Win32Lock,\r
+               Win32Unlock,\r
+               Win32DeleteLock,\r
+               Win32InitEvent,\r
+               Win32SetEvent,\r
+               Win32ResetEvent,\r
+               Win32WaitEvent,\r
+               Win32FreeEvent,\r
+               Win32WaitThread,\r
+               Win32FreeThread,\r
+               Win32InitThread,\r
+               Win32ThreadId,\r
+               Win32FileOpen,\r
+               Win32FileOpenW,\r
+               Win32FileCreate,\r
+               Win32FileCreateW,\r
+               Win32FileWrite,\r
+               Win32FileRead,\r
+               Win32FileClose,\r
+               Win32FileFlush,\r
+               Win32FileSize,\r
+               Win32FileSeek,\r
+               Win32FileDelete,\r
+               Win32FileDeleteW,\r
+               Win32MakeDir,\r
+               Win32MakeDirW,\r
+               Win32DeleteDir,\r
+               Win32DeleteDirW,\r
+               Win32GetCallStack,\r
+               Win32GetCallStackSymbolInfo,\r
+               Win32FileRename,\r
+               Win32FileRenameW,\r
+               Win32Run,\r
+               Win32RunW,\r
+               Win32IsSupportedOs,\r
+               Win32GetOsInfo,\r
+               Win32Alert,\r
+               Win32AlertW,\r
+               Win32GetProductId,\r
+               Win32SetHighPriority,\r
+               Win32RestorePriority,\r
+               Win32NewSingleInstance,\r
+               Win32FreeSingleInstance,\r
+               Win32GetMemInfo,\r
+               Win32Yield,\r
+       };\r
+\r
+       return &t;\r
+}\r
+\r
+// 新しいスレッド用の初期化関数\r
+void Win32InitNewThread()\r
+{\r
+       static HINSTANCE hDll = NULL;\r
+       static bool (WINAPI *_SetThreadLocale)(LCID) = NULL;\r
+\r
+       if (hDll == NULL)\r
+       {\r
+               hDll = LoadLibrary("kernel32.dll");\r
+\r
+               _SetThreadLocale =\r
+                       (bool (__stdcall *)(LCID))\r
+                       GetProcAddress(hDll, "SetThreadLocale");\r
+       }\r
+\r
+       if (_SetThreadLocale != NULL)\r
+       {\r
+               _SetThreadLocale(LOCALE_USER_DEFAULT);\r
+       }\r
+}\r
+\r
+// フォルダの圧縮フラグを設定する\r
+bool Win32SetFolderCompressW(wchar_t *path, bool compressed)\r
+{\r
+       HANDLE h;\r
+       UINT retsize = 0;\r
+       USHORT flag;\r
+       wchar_t tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char *path_a = CopyUniToStr(path);\r
+               bool ret = Win32SetFolderCompress(path_a, compressed);\r
+\r
+               Free(path_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       InnerFilePathW(tmp, sizeof(tmp), path);\r
+\r
+       // フォルダを開く\r
+       h = CreateFileW(tmp, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r
+\r
+       if (h == INVALID_HANDLE_VALUE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       flag = compressed ? COMPRESSION_FORMAT_DEFAULT : COMPRESSION_FORMAT_NONE;\r
+\r
+       if (DeviceIoControl(h, FSCTL_SET_COMPRESSION, &flag, sizeof(USHORT),\r
+               NULL, 0, &retsize, NULL) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       CloseHandle(h);\r
+\r
+       return true;\r
+}\r
+bool Win32SetFolderCompress(char *path, bool compressed)\r
+{\r
+       HANDLE h;\r
+       UINT retsize = 0;\r
+       USHORT flag;\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       InnerFilePath(tmp, sizeof(tmp), path);\r
+\r
+       // フォルダを開く\r
+       h = CreateFile(tmp, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r
+\r
+       if (h == INVALID_HANDLE_VALUE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       flag = compressed ? COMPRESSION_FORMAT_DEFAULT : COMPRESSION_FORMAT_NONE;\r
+\r
+       if (DeviceIoControl(h, FSCTL_SET_COMPRESSION, &flag, sizeof(USHORT),\r
+               NULL, 0, &retsize, NULL) == false)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       CloseHandle(h);\r
+\r
+       return true;\r
+}\r
+\r
+// ディスクの空き容量を取得する\r
+bool Win32GetDiskFreeW(wchar_t *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size)\r
+{\r
+       wchar_t tmp[MAX_SIZE];\r
+       UINT count = 0;\r
+       UINT i, n, len;\r
+       ULARGE_INTEGER v1, v2, v3;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               bool ret;\r
+               char *path_a = CopyUniToStr(path);\r
+\r
+               ret = Win32GetDiskFree(path_a, free_size, used_size, total_size);\r
+\r
+               Free(path_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       Zero(&v1, sizeof(v1));\r
+       Zero(&v2, sizeof(v2));\r
+       Zero(&v3, sizeof(v3));\r
+\r
+       NormalizePathW(tmp, sizeof(tmp), path);\r
+\r
+       // ディレクトリ名を取得\r
+       if (UniStartWith(path, L"\\\\"))\r
+       {\r
+               count = 4;\r
+       }\r
+       else\r
+       {\r
+               count = 1;\r
+       }\r
+\r
+       len = UniStrLen(tmp);\r
+       n = 0;\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (tmp[i] == L'\\')\r
+               {\r
+                       n++;\r
+                       if (n >= count)\r
+                       {\r
+                               tmp[i + 1] = 0;\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (GetDiskFreeSpaceExW(tmp, &v1, &v2, &v3))\r
+       {\r
+               ret = true;\r
+       }\r
+\r
+       if (free_size != NULL)\r
+       {\r
+               *free_size = v1.QuadPart;\r
+       }\r
+\r
+       if (total_size != NULL)\r
+       {\r
+               *total_size = v2.QuadPart;\r
+       }\r
+\r
+       if (used_size != NULL)\r
+       {\r
+               *used_size = v2.QuadPart - v1.QuadPart;\r
+       }\r
+\r
+       return ret;\r
+}\r
+bool Win32GetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size)\r
+{\r
+       char tmp[MAX_SIZE];\r
+       UINT count = 0;\r
+       UINT i, n, len;\r
+       ULARGE_INTEGER v1, v2, v3;\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (path == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       Zero(&v1, sizeof(v1));\r
+       Zero(&v2, sizeof(v2));\r
+       Zero(&v3, sizeof(v3));\r
+\r
+       NormalizePath(tmp, sizeof(tmp), path);\r
+\r
+       // ディレクトリ名を取得\r
+       if (StartWith(path, "\\\\"))\r
+       {\r
+               count = 4;\r
+       }\r
+       else\r
+       {\r
+               count = 1;\r
+       }\r
+\r
+       len = StrLen(tmp);\r
+       n = 0;\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               if (tmp[i] == '\\')\r
+               {\r
+                       n++;\r
+                       if (n >= count)\r
+                       {\r
+                               tmp[i + 1] = 0;\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (GetDiskFreeSpaceEx(tmp, &v1, &v2, &v3))\r
+       {\r
+               ret = true;\r
+       }\r
+\r
+       if (free_size != NULL)\r
+       {\r
+               *free_size = v1.QuadPart;\r
+       }\r
+\r
+       if (total_size != NULL)\r
+       {\r
+               *total_size = v2.QuadPart;\r
+       }\r
+\r
+       if (used_size != NULL)\r
+       {\r
+               *used_size = v2.QuadPart - v1.QuadPart;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ディレクトリの列挙\r
+DIRLIST *Win32EnumDirEx(char *dirname, COMPARE *compare)\r
+{\r
+       DIRLIST *ret;\r
+       wchar_t *dirname_w = CopyStrToUni(dirname);\r
+\r
+       ret = Win32EnumDirExW(dirname_w, compare);\r
+\r
+       Free(dirname_w);\r
+\r
+       return ret;\r
+}\r
+DIRLIST *Win32EnumDirExW(wchar_t *dirname, COMPARE *compare)\r
+{\r
+       WIN32_FIND_DATAA data_a;\r
+       WIN32_FIND_DATAW data_w;\r
+       HANDLE h;\r
+       wchar_t tmp[MAX_PATH];\r
+       wchar_t tmp2[MAX_PATH];\r
+       wchar_t dirname2[MAX_PATH];\r
+       LIST *o;\r
+       DIRLIST *d;\r
+\r
+       UniStrCpy(tmp2, sizeof(tmp2), dirname);\r
+\r
+       if (UniStrLen(tmp2) >= 1 && tmp[UniStrLen(tmp2) - 1] == L'\\')\r
+       {\r
+               tmp2[UniStrLen(tmp2) - 1] = 0;\r
+       }\r
+\r
+       UniFormat(tmp, sizeof(tmp), L"%s\\*.*", tmp2);\r
+       NormalizePathW(tmp, sizeof(tmp), tmp);\r
+       NormalizePathW(dirname2, sizeof(dirname2), tmp2);\r
+\r
+       o = NewListFast(compare);\r
+\r
+       Zero(&data_a, sizeof(data_a));\r
+       Zero(&data_w, sizeof(data_w));\r
+\r
+       if (IsNt())\r
+       {\r
+               h = FindFirstFileW(tmp, &data_w);\r
+       }\r
+       else\r
+       {\r
+               char *tmp_a = CopyUniToStr(tmp);\r
+\r
+               h = FindFirstFileA(tmp_a, &data_a);\r
+\r
+               Free(tmp_a);\r
+       }\r
+\r
+       if (h != INVALID_HANDLE_VALUE)\r
+       {\r
+               bool b = true;\r
+\r
+               do\r
+               {\r
+                       if (IsNt() == false)\r
+                       {\r
+                               Zero(&data_w, sizeof(data_w));\r
+                               StrToUni(data_w.cFileName, sizeof(data_w.cFileName), data_a.cFileName);\r
+                               data_w.dwFileAttributes = data_a.dwFileAttributes;\r
+                               data_w.ftCreationTime = data_a.ftCreationTime;\r
+                               data_w.ftLastWriteTime = data_a.ftLastWriteTime;\r
+                               data_w.nFileSizeHigh = data_a.nFileSizeHigh;\r
+                               data_w.nFileSizeLow = data_a.nFileSizeLow;\r
+                       }\r
+\r
+                       if (UniStrCmpi(data_w.cFileName, L"..") != 0 &&\r
+                               UniStrCmpi(data_w.cFileName, L".") != 0)\r
+                       {\r
+                               DIRENT *f = ZeroMalloc(sizeof(DIRENT));\r
+                               SYSTEMTIME t1, t2;\r
+                               wchar_t fullpath[MAX_SIZE];\r
+                               bool ok = false;\r
+\r
+                               f->FileNameW = UniCopyStr(data_w.cFileName);\r
+                               f->FileName = CopyUniToStr(f->FileNameW);\r
+                               f->Folder = (data_w.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false;\r
+\r
+                               CombinePathW(fullpath, sizeof(fullpath), dirname2, f->FileNameW);\r
+\r
+                               // ファイル情報の取得を試行する\r
+                               if (MsIsNt())\r
+                               {\r
+                                       HANDLE h = CreateFileW(fullpath, 0,\r
+                                               FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,\r
+                                               NULL, OPEN_EXISTING, 0, NULL);\r
+\r
+                                       if (h != INVALID_HANDLE_VALUE)\r
+                                       {\r
+                                               BY_HANDLE_FILE_INFORMATION info;\r
+\r
+                                               Zero(&info, sizeof(info));\r
+\r
+                                               if (MsGetFileInformation(h, &info))\r
+                                               {\r
+                                                       Zero(&t1, sizeof(t1));\r
+                                                       Zero(&t2, sizeof(t2));\r
+                                                       FileTimeToSystemTime(&info.ftCreationTime, &t1);\r
+                                                       FileTimeToSystemTime(&info.ftLastWriteTime, &t2);\r
+                                                       f->CreateDate = SystemToUINT64(&t1);\r
+                                                       f->UpdateDate = SystemToUINT64(&t2);\r
+\r
+                                                       if (f->Folder == false)\r
+                                                       {\r
+                                                               f->FileSize = ((UINT64)info.nFileSizeHigh * (UINT64)((UINT64)MAXDWORD + (UINT64)1)) + (UINT64)info.nFileSizeLow;\r
+                                                       }\r
+\r
+                                                       ok = true;\r
+                                               }\r
+\r
+                                               CloseHandle(h);\r
+                                       }\r
+                               }\r
+\r
+                               if (ok == false)\r
+                               {\r
+                                       Zero(&t1, sizeof(t1));\r
+                                       Zero(&t2, sizeof(t2));\r
+                                       FileTimeToSystemTime(&data_w.ftCreationTime, &t1);\r
+                                       FileTimeToSystemTime(&data_w.ftLastWriteTime, &t2);\r
+                                       f->CreateDate = SystemToUINT64(&t1);\r
+                                       f->UpdateDate = SystemToUINT64(&t2);\r
+\r
+                                       if (f->Folder == false)\r
+                                       {\r
+                                               f->FileSize = ((UINT64)data_w.nFileSizeHigh * (UINT64)((UINT64)MAXDWORD + (UINT64)1)) + (UINT64)data_w.nFileSizeLow;\r
+                                       }\r
+                               }\r
+\r
+                               Add(o, f);\r
+                       }\r
+\r
+                       Zero(&data_w, sizeof(data_w));\r
+                       Zero(&data_a, sizeof(data_a));\r
+\r
+                       if (IsNt())\r
+                       {\r
+                               b = FindNextFileW(h, &data_w);\r
+                       }\r
+                       else\r
+                       {\r
+                               b = FindNextFileA(h, &data_a);\r
+                       }\r
+               }\r
+               while (b);\r
+\r
+               FindClose(h);\r
+       }\r
+\r
+       Sort(o);\r
+\r
+       d = ZeroMalloc(sizeof(DIRLIST));\r
+       d->NumFiles = LIST_NUM(o);\r
+       d->File = ToArray(o);\r
+\r
+       ReleaseList(o);\r
+\r
+       return d;\r
+}\r
+\r
+// EXE ファイル名を取得\r
+void Win32GetExeNameW(wchar_t *name, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char name_a[MAX_PATH];\r
+\r
+               Win32GetExeName(name_a, sizeof(name_a));\r
+\r
+               StrToUni(name, size, name_a);\r
+\r
+               return;\r
+       }\r
+\r
+       UniStrCpy(name, size, L"");\r
+\r
+       GetModuleFileNameW(NULL, name, size);\r
+}\r
+void Win32GetExeName(char *name, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       StrCpy(name, size, "");\r
+\r
+       GetModuleFileName(NULL, name, size);\r
+}\r
+\r
+// 現在のディレクトリの取得\r
+void Win32GetCurrentDirW(wchar_t *dir, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (dir == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char dir_a[MAX_PATH];\r
+\r
+               Win32GetCurrentDir(dir_a, sizeof(dir_a));\r
+\r
+               StrToUni(dir, size, dir_a);\r
+\r
+               return;\r
+       }\r
+\r
+       GetCurrentDirectoryW(size, dir);\r
+}\r
+void Win32GetCurrentDir(char *dir, UINT size)\r
+{\r
+       // 引数チェック\r
+       if (dir == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       GetCurrentDirectory(size, dir);\r
+}\r
+\r
+// イールド\r
+void Win32Yield()\r
+{\r
+       Sleep(0);\r
+}\r
+\r
+// メモリ情報の取得\r
+void Win32GetMemInfo(MEMINFO *info)\r
+{\r
+       MEMORYSTATUS st;\r
+       // 引数チェック\r
+       if (info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(info, sizeof(MEMINFO));\r
+       Zero(&st, sizeof(st));\r
+       st.dwLength = sizeof(st);\r
+\r
+       GlobalMemoryStatus(&st);\r
+\r
+       // 論理メモリ量\r
+       info->TotalMemory = (UINT64)st.dwTotalPageFile;\r
+       info->FreeMemory = (UINT64)st.dwAvailPageFile;\r
+       info->UsedMemory = info->TotalMemory - info->FreeMemory;\r
+\r
+       // 物理メモリ量\r
+       info->TotalPhys = (UINT64)st.dwTotalPhys;\r
+       info->FreePhys = (UINT64)st.dwAvailPhys;\r
+       info->UsedPhys = info->TotalPhys - info->FreePhys;\r
+}\r
+\r
+// シングルインスタンスの作成\r
+void *Win32NewSingleInstance(char *instance_name)\r
+{\r
+       WIN32MUTEX *ret;\r
+       char tmp[MAX_SIZE];\r
+       HANDLE hMutex;\r
+       // 引数チェック\r
+       if (instance_name == NULL)\r
+       {\r
+               char exe_path[MAX_PATH];\r
+               GetModuleFileName(NULL, exe_path, sizeof(exe_path));\r
+               HashInstanceName(tmp, sizeof(tmp), exe_path);\r
+               instance_name = tmp;\r
+       }\r
+\r
+       hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, instance_name);\r
+       if (hMutex != NULL)\r
+       {\r
+               CloseHandle(hMutex);\r
+               return NULL;\r
+       }\r
+\r
+       hMutex = CreateMutex(NULL, FALSE, instance_name);\r
+       if (hMutex == NULL)\r
+       {\r
+               CloseHandle(hMutex);\r
+               return NULL;\r
+       }\r
+\r
+       ret = Win32MemoryAlloc(sizeof(WIN32MUTEX));\r
+       ret->hMutex = hMutex;\r
+\r
+       return (void *)ret;\r
+}\r
+\r
+// シングルインスタンスの解放\r
+void Win32FreeSingleInstance(void *data)\r
+{\r
+       WIN32MUTEX *m;\r
+       // 引数チェック\r
+       if (data == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       m = (WIN32MUTEX *)data;\r
+       ReleaseMutex(m->hMutex);\r
+       CloseHandle(m->hMutex);\r
+\r
+       Win32MemoryFree(m);\r
+}\r
+\r
+// 優先順位を高くする\r
+void Win32SetHighPriority()\r
+{\r
+       SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);\r
+}\r
+\r
+// 優先順位を戻す\r
+void Win32RestorePriority()\r
+{\r
+       SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);\r
+}\r
+\r
+// ノード情報を取得\r
+char* Win32GetProductId()\r
+{\r
+       char *product_id;\r
+\r
+       return CopyStr("--");\r
+\r
+       // プロダクト ID\r
+       product_id = MsRegReadStr(REG_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductId");\r
+       if (product_id == NULL)\r
+       {\r
+               product_id = MsRegReadStr(REG_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProductId");\r
+       }\r
+\r
+       return product_id;\r
+}\r
+\r
+// 現在サポートされている OS かどうか取得\r
+bool Win32IsSupportedOs()\r
+{\r
+       if (Win32GetOsType() == 0)\r
+       {\r
+               Win32Alert(\r
+                       "SoftEther UT-VPN doesn't support this Windows Operating System.\n"\r
+                       "SoftEther UT-VPN requires " SUPPORTED_WINDOWS_LIST ".\n\n"\r
+                       "Please contact your system administrator.", NULL);\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// アラートの表示\r
+void Win32AlertW(wchar_t *msg, wchar_t *caption)\r
+{\r
+       char *s;\r
+       // 引数チェック\r
+       if (msg == NULL)\r
+       {\r
+               msg = L"Alert";\r
+       }\r
+       if (caption == NULL)\r
+       {\r
+               caption = L"SoftEther UT-VPN Kernel";\r
+       }\r
+\r
+       s = GetCommandLineStr();\r
+\r
+       if (SearchStr(s, "win9x_uninstall", 0) == INFINITE && SearchStr(s, "win9x_install", 0) == INFINITE)\r
+       {\r
+               // Win9x サービスモードのアンインストール時には非表示とする\r
+               MessageBoxW(NULL, msg, caption, MB_SETFOREGROUND | MB_TOPMOST | MB_SERVICE_NOTIFICATION | MB_OK | MB_ICONEXCLAMATION);\r
+       }\r
+\r
+       Free(s);\r
+}\r
+void Win32Alert(char *msg, char *caption)\r
+{\r
+       char *s;\r
+       // 引数チェック\r
+       if (msg == NULL)\r
+       {\r
+               msg = "Alert";\r
+       }\r
+       if (caption == NULL)\r
+       {\r
+               caption = "SoftEther UT-VPN Kernel";\r
+       }\r
+\r
+       s = GetCommandLineStr();\r
+\r
+       if (SearchStr(s, "win9x_uninstall", 0) == INFINITE && SearchStr(s, "win9x_install", 0) == INFINITE)\r
+       {\r
+               // Win9x サービスモードのアンインストール時には非表示とする\r
+               MessageBox(NULL, msg, caption, MB_SETFOREGROUND | MB_TOPMOST | MB_SERVICE_NOTIFICATION | MB_OK | MB_ICONEXCLAMATION);\r
+       }\r
+\r
+       Free(s);\r
+}\r
+void Win32DebugAlert(char *msg)\r
+{\r
+       // 引数チェック\r
+       if (msg == NULL)\r
+       {\r
+               msg = "Alert";\r
+       }\r
+\r
+       MessageBox(NULL, msg, "Debug", MB_SETFOREGROUND | MB_TOPMOST | MB_SERVICE_NOTIFICATION | MB_OK | MB_ICONEXCLAMATION);\r
+}\r
+\r
+// OS 情報の取得\r
+void Win32GetOsInfo(OS_INFO *info)\r
+{\r
+       UINT type = Win32GetOsType();\r
+       OSVERSIONINFOEX os;\r
+       char tmp[MAX_SIZE];\r
+       // 引数チェック\r
+       if (info == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       Zero(&os, sizeof(os));\r
+       os.dwOSVersionInfoSize = sizeof(os);\r
+       GetVersionEx((LPOSVERSIONINFOA)&os);\r
+\r
+       info->OsType = Win32GetOsType();\r
+       info->OsServicePack = os.wServicePackMajor;\r
+       if (OS_IS_WINDOWS_NT(info->OsType))\r
+       {\r
+               char *s;\r
+               char *keyname = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";\r
+               info->OsSystemName = CopyStr("Windows NT");\r
+               Format(tmp, sizeof(tmp), "Build %u", os.dwBuildNumber);\r
+               if (s = MsRegReadStr(REG_LOCAL_MACHINE, keyname, "CurrentType"))\r
+               {\r
+                       char str[MAX_SIZE];\r
+                       Format(str, sizeof(str), ", %s", s);\r
+                       StrCat(tmp, sizeof(tmp), str);\r
+                       Free(s);\r
+               }\r
+               if (os.wServicePackMajor != 0)\r
+               {\r
+                       char str[MAX_SIZE];\r
+                       Format(str, sizeof(str), ", Service Pack %u", os.wServicePackMajor);\r
+                       StrCat(tmp, sizeof(tmp), str);\r
+               }\r
+               if (s = MsRegReadStr(REG_LOCAL_MACHINE, keyname, "BuildLab"))\r
+               {\r
+                       char str[MAX_SIZE];\r
+                       Format(str, sizeof(str), " (%s)", s);\r
+                       StrCat(tmp, sizeof(tmp), str);\r
+                       Free(s);\r
+               }\r
+               info->OsVersion = CopyStr(tmp);\r
+               info->KernelName = CopyStr("NTOS Kernel");\r
+               Format(tmp, sizeof(tmp), "Build %u", os.dwBuildNumber);\r
+               if (s = MsRegReadStr(REG_LOCAL_MACHINE, keyname, "CurrentType"))\r
+               {\r
+                       char str[MAX_SIZE];\r
+                       Format(str, sizeof(str), " %s", s);\r
+                       StrCat(tmp, sizeof(tmp), str);\r
+                       Free(s);\r
+               }\r
+               info->KernelVersion = CopyStr(tmp);\r
+       }\r
+       else\r
+       {\r
+               OSVERSIONINFO os;\r
+               Zero(&os, sizeof(os));\r
+               os.dwOSVersionInfoSize = sizeof(os);\r
+               GetVersionEx(&os);\r
+               Format(tmp, sizeof(tmp), "Build %u %s", LOWORD(os.dwBuildNumber), os.szCSDVersion);\r
+               Trim(tmp);\r
+               info->OsVersion = CopyStr(tmp);\r
+               info->OsSystemName = CopyStr("Windows");\r
+               info->KernelName = CopyStr("Windows 9x Kernel");\r
+               info->KernelVersion = CopyStr(tmp);\r
+       }\r
+\r
+       info->OsProductName = CopyStr(OsTypeToStr(info->OsType));\r
+       info->OsVendorName = CopyStr("Microsoft Corporation");\r
+}\r
+\r
+// Windows NT かどうか取得\r
+bool Win32IsNt()\r
+{\r
+       OSVERSIONINFO os;\r
+       Zero(&os, sizeof(os));\r
+       os.dwOSVersionInfoSize = sizeof(os);\r
+\r
+       if (GetVersionEx(&os) == FALSE)\r
+       {\r
+               // 失敗?\r
+               return false;\r
+       }\r
+\r
+       if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)\r
+       {\r
+               // NT\r
+               return true;\r
+       }\r
+\r
+       // 9x\r
+       return false;\r
+}\r
+\r
+// OS 種類の取得\r
+UINT Win32GetOsType()\r
+{\r
+       OSVERSIONINFO os;\r
+       Zero(&os, sizeof(os));\r
+       os.dwOSVersionInfoSize = sizeof(os);\r
+\r
+       if (GetVersionEx(&os) == FALSE)\r
+       {\r
+               // 失敗?\r
+               return 0;\r
+       }\r
+\r
+       if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)\r
+       {\r
+               // Windows 9x 系\r
+               if (os.dwMajorVersion == 4)\r
+               {\r
+                       if (os.dwMinorVersion == 0)\r
+                       {\r
+                               return OSTYPE_WINDOWS_95;\r
+                       }\r
+                       else if (os.dwMinorVersion == 10)\r
+                       {\r
+                               return OSTYPE_WINDOWS_98;\r
+                       }\r
+                       else if (os.dwMinorVersion == 90)\r
+                       {\r
+                               return OSTYPE_WINDOWS_ME;\r
+                       }\r
+                       else\r
+                       {\r
+                               return OSTYPE_WINDOWS_UNKNOWN;\r
+                       }\r
+               }\r
+               else if (os.dwMajorVersion >= 5)\r
+               {\r
+                       return OSTYPE_WINDOWS_UNKNOWN;\r
+               }\r
+       }\r
+       else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)\r
+       {\r
+               UINT sp = Win32GetSpVer(os.szCSDVersion);\r
+               if (os.dwMajorVersion == 4)\r
+               {\r
+                       if (sp < 6)\r
+                       {\r
+                               // SP6 以前\r
+                               return 0;\r
+                       }\r
+               }\r
+               if (os.dwMajorVersion < 4)\r
+               {\r
+                       // NT 3.51 以前\r
+                       return 0;\r
+               }\r
+               else\r
+               {\r
+                       OSVERSIONINFOEX os;\r
+                       Zero(&os, sizeof(os));\r
+                       os.dwOSVersionInfoSize = sizeof(os);\r
+                       GetVersionEx((LPOSVERSIONINFOA)&os);\r
+\r
+                       if (os.dwMajorVersion == 4)\r
+                       {\r
+                               // Windows NT 4.0\r
+                               if (os.wProductType == VER_NT_DOMAIN_CONTROLLER || os.wProductType == VER_NT_SERVER)\r
+                               {\r
+                                       if ((os.wSuiteMask & VER_SUITE_TERMINAL) || (os.wSuiteMask & VER_SUITE_SINGLEUSERTS))\r
+                                       {\r
+                                               return OSTYPE_WINDOWS_NT_4_TERMINAL_SERVER;\r
+                                       }\r
+                                       if (os.wSuiteMask & VER_SUITE_ENTERPRISE)\r
+                                       {\r
+                                               return OSTYPE_WINDOWS_NT_4_SERVER_ENTERPRISE;\r
+                                       }\r
+                                       if (os.wSuiteMask & VER_SUITE_BACKOFFICE)\r
+                                       {\r
+                                               return OSTYPE_WINDOWS_NT_4_BACKOFFICE;\r
+                                       }\r
+                                       if ((os.wSuiteMask & VER_SUITE_SMALLBUSINESS) || (os.wSuiteMask & VER_SUITE_SMALLBUSINESS_RESTRICTED))\r
+                                       {\r
+                                               return OSTYPE_WINDOWS_NT_4_SMS;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               return OSTYPE_WINDOWS_NT_4_SERVER;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       return OSTYPE_WINDOWS_NT_4_WORKSTATION;\r
+                               }\r
+                       }\r
+                       else if (os.dwMajorVersion == 5)\r
+                       {\r
+                               // Windows 2000, XP, Server 2003\r
+                               if (os.dwMinorVersion == 0)\r
+                               {\r
+                                       // Windows 2000\r
+                                       if (os.wProductType == VER_NT_DOMAIN_CONTROLLER || os.wProductType == VER_NT_SERVER)\r
+                                       {\r
+                                               // Server\r
+                                               if (os.wSuiteMask & VER_SUITE_DATACENTER)\r
+                                               {\r
+                                                       return OSTYPE_WINDOWS_2000_DATACENTER_SERVER;\r
+                                               }\r
+                                               else if ((os.wSuiteMask & VER_SUITE_SMALLBUSINESS) || (os.wSuiteMask & VER_SUITE_SMALLBUSINESS_RESTRICTED))\r
+                                               {\r
+                                                       return OSTYPE_WINDOWS_2000_SBS;\r
+                                               }\r
+                                               else if (os.wSuiteMask & VER_SUITE_BACKOFFICE)\r
+                                               {\r
+                                                       return OSTYPE_WINDOWS_2000_BACKOFFICE;\r
+                                               }\r
+                                               else if (os.wSuiteMask & VER_SUITE_ENTERPRISE)\r
+                                               {\r
+                                                       return OSTYPE_WINDOWS_2000_ADVANCED_SERVER;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       return OSTYPE_WINDOWS_2000_SERVER;\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // Client\r
+                                               return OSTYPE_WINDOWS_2000_PROFESSIONAL;\r
+                                       }\r
+                               }\r
+                               else if (os.dwMinorVersion == 1)\r
+                               {\r
+                                       // Windows XP\r
+                                       if (os.wSuiteMask & VER_SUITE_PERSONAL)\r
+                                       {\r
+                                               return OSTYPE_WINDOWS_XP_HOME;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               return OSTYPE_WINDOWS_XP_PROFESSIONAL;\r
+                                       }\r
+                               }\r
+                               else if (os.dwMinorVersion == 2)\r
+                               {\r
+                                       // Windows Server 2003\r
+                                       if (os.wProductType == VER_NT_DOMAIN_CONTROLLER || os.wProductType == VER_NT_SERVER)\r
+                                       {\r
+                                               // Server\r
+                                               if (os.wSuiteMask & VER_SUITE_DATACENTER)\r
+                                               {\r
+                                                       return OSTYPE_WINDOWS_2003_DATACENTER;\r
+                                               }\r
+                                               else if ((os.wSuiteMask & VER_SUITE_SMALLBUSINESS) || (os.wSuiteMask & VER_SUITE_SMALLBUSINESS_RESTRICTED))\r
+                                               {\r
+                                                       return OSTYPE_WINDOWS_2003_SBS;\r
+                                               }\r
+                                               else if (os.wSuiteMask & VER_SUITE_BACKOFFICE)\r
+                                               {\r
+                                                       return OSTYPE_WINDOWS_2003_BACKOFFICE;\r
+                                               }\r
+                                               else if (os.wSuiteMask & VER_SUITE_ENTERPRISE)\r
+                                               {\r
+                                                       return OSTYPE_WINDOWS_2003_ENTERPRISE;\r
+                                               }\r
+                                               else if (os.wSuiteMask & VER_SUITE_BLADE)\r
+                                               {\r
+                                                       return OSTYPE_WINDOWS_2003_WEB;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       return OSTYPE_WINDOWS_2003_STANDARD;\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // Client (Unknown XP?)\r
+                                               return OSTYPE_WINDOWS_XP_PROFESSIONAL;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       // Windows Longhorn\r
+                                       if (os.wProductType == VER_NT_DOMAIN_CONTROLLER || os.wProductType == VER_NT_SERVER)\r
+                                       {\r
+                                               return OSTYPE_WINDOWS_LONGHORN_SERVER;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               return OSTYPE_WINDOWS_LONGHORN_PROFESSIONAL;\r
+                                       }\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               if (os.dwMajorVersion == 6 && os.dwMinorVersion == 0)\r
+                               {\r
+                                       // Windows Vista, Server 2008\r
+                                       if (os.wProductType == VER_NT_DOMAIN_CONTROLLER || os.wProductType == VER_NT_SERVER)\r
+                                       {\r
+                                               return OSTYPE_WINDOWS_LONGHORN_SERVER;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               return OSTYPE_WINDOWS_LONGHORN_PROFESSIONAL;\r
+                                       }\r
+                               }\r
+                               else if (os.dwMajorVersion == 6 && os.dwMinorVersion == 1)\r
+                               {\r
+                                       if (os.wProductType == VER_NT_WORKSTATION)\r
+                                       {\r
+                                               // Windows 7\r
+                                               return OSTYPE_WINDOWS_7;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // Windows Server 2008 R2\r
+                                               return OSTYPE_WINDOWS_SERVER_2008_R2;\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       if (os.wProductType == VER_NT_WORKSTATION)\r
+                                       {\r
+                                               // Windows 8\r
+                                               return OSTYPE_WINDOWS_8;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // Windows Server 8\r
+                                               return OSTYPE_WINDOWS_SERVER_2008_R2;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       // 判別できない\r
+       return 0;\r
+}\r
+\r
+// 文字列から SP のバージョンを取得する\r
+UINT Win32GetSpVer(char *str)\r
+{\r
+       UINT ret, i;\r
+       TOKEN_LIST *t;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       t = ParseToken(str, NULL);\r
+       if (t == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       ret = 0;\r
+       for (i = 0;i < t->NumTokens;i++)\r
+       {\r
+               ret = ToInt(t->Token[i]);\r
+               if (ret != 0)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       FreeToken(t);\r
+\r
+       return ret;\r
+}\r
+\r
+// プロセスの強制終了\r
+bool Win32TerminateProcess(void *handle)\r
+{\r
+       HANDLE h;\r
+       // 引数チェック\r
+       if (handle == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       h = (HANDLE)handle;\r
+\r
+       TerminateProcess(h, 0);\r
+\r
+       return true;\r
+}\r
+\r
+// プロセスを閉じる\r
+void Win32CloseProcess(void *handle)\r
+{\r
+       // 引数チェック\r
+       if (handle == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CloseHandle((HANDLE)handle);\r
+}\r
+\r
+// 指定されたプロセスが生きているかどうかチェック\r
+bool Win32IsProcessAlive(void *handle)\r
+{\r
+       HANDLE h;\r
+       // 引数チェック\r
+       if (handle == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       h = (HANDLE)handle;\r
+\r
+       if (WaitForSingleObject(h, 0) == WAIT_OBJECT_0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// プロセスの終了を待機する\r
+bool Win32WaitProcess(void *h, UINT timeout)\r
+{\r
+       // 引数チェック\r
+       if (h == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (timeout == 0)\r
+       {\r
+               timeout = INFINITE;\r
+       }\r
+\r
+       if (WaitForSingleObject((HANDLE)h, timeout) == WAIT_TIMEOUT)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// プロセスの起動 (ハンドルを返す)\r
+void *Win32RunExW(wchar_t *filename, wchar_t *arg, bool hide)\r
+{\r
+       return Win32RunEx2W(filename, arg, hide, NULL);\r
+}\r
+void *Win32RunEx2W(wchar_t *filename, wchar_t *arg, bool hide, UINT *process_id)\r
+{\r
+       return Win32RunEx3W(filename, arg, hide, process_id, false);\r
+}\r
+void *Win32RunEx3W(wchar_t *filename, wchar_t *arg, bool hide, UINT *process_id, bool disableWow)\r
+{\r
+       STARTUPINFOW info;\r
+       PROCESS_INFORMATION ret;\r
+       wchar_t cmdline[MAX_SIZE];\r
+       wchar_t name[MAX_PATH];\r
+       void *p;\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char *filename_a = CopyUniToStr(filename);\r
+               char *arg_a = CopyUniToStr(arg);\r
+               void *ret = Win32RunEx(filename_a, arg_a, hide);\r
+\r
+               Free(filename_a);\r
+               Free(arg_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       UniStrCpy(name, sizeof(name), filename);\r
+       UniTrim(name);\r
+\r
+       if (UniSearchStr(name, L"\"", 0) == INFINITE)\r
+       {\r
+               if (arg == NULL)\r
+               {\r
+                       UniFormat(cmdline, sizeof(cmdline), L"%s", name);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(cmdline, sizeof(cmdline), L"%s %s", name, arg);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (arg == NULL)\r
+               {\r
+                       UniFormat(cmdline, sizeof(cmdline), L"\"%s\"", name);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(cmdline, sizeof(cmdline), L"\"%s\" %s", name, arg);\r
+               }\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       Zero(&ret, sizeof(ret));\r
+       info.cb = sizeof(info);\r
+       info.dwFlags = STARTF_USESHOWWINDOW;\r
+       info.wShowWindow = (hide == false ? SW_SHOWDEFAULT : SW_HIDE);\r
+\r
+       UniTrim(cmdline);\r
+\r
+       if (disableWow)\r
+       {\r
+               p = MsDisableWow64FileSystemRedirection();\r
+       }\r
+\r
+       if (CreateProcessW(NULL, cmdline, NULL, NULL, FALSE,\r
+               (hide == false ? CREATE_NEW_CONSOLE : CREATE_NO_WINDOW | CREATE_NEW_CONSOLE) | NORMAL_PRIORITY_CLASS,\r
+               NULL, NULL, &info, &ret) == FALSE)\r
+       {\r
+               if (disableWow)\r
+               {\r
+                       MsRestoreWow64FileSystemRedirection(p);\r
+               }\r
+               return NULL;\r
+       }\r
+\r
+       if (disableWow)\r
+       {\r
+               MsRestoreWow64FileSystemRedirection(p);\r
+       }\r
+\r
+       if (process_id != NULL)\r
+       {\r
+               *process_id = ret.dwProcessId;\r
+       }\r
+\r
+       CloseHandle(ret.hThread);\r
+       return ret.hProcess;\r
+}\r
+void *Win32RunEx(char *filename, char *arg, bool hide)\r
+{\r
+       return Win32RunEx2(filename, arg, hide, NULL);\r
+}\r
+void *Win32RunEx2(char *filename, char *arg, bool hide, UINT *process_id)\r
+{\r
+       return Win32RunEx3(filename, arg, hide, process_id, false);\r
+}\r
+void *Win32RunEx3(char *filename, char *arg, bool hide, UINT *process_id, bool disableWow)\r
+{\r
+       STARTUPINFO info;\r
+       PROCESS_INFORMATION ret;\r
+       char cmdline[MAX_SIZE];\r
+       char name[MAX_PATH];\r
+       void *p = NULL;\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       StrCpy(name, sizeof(name), filename);\r
+       Trim(name);\r
+\r
+       if (SearchStr(name, "\"", 0) == INFINITE)\r
+       {\r
+               if (arg == NULL)\r
+               {\r
+                       Format(cmdline, sizeof(cmdline), "%s", name);\r
+               }\r
+               else\r
+               {\r
+                       Format(cmdline, sizeof(cmdline), "%s %s", name, arg);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (arg == NULL)\r
+               {\r
+                       Format(cmdline, sizeof(cmdline), "\"%s\"", name);\r
+               }\r
+               else\r
+               {\r
+                       Format(cmdline, sizeof(cmdline), "\"%s\" %s", name, arg);\r
+               }\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       Zero(&ret, sizeof(ret));\r
+       info.cb = sizeof(info);\r
+       info.dwFlags = STARTF_USESHOWWINDOW;\r
+       info.wShowWindow = (hide == false ? SW_SHOWDEFAULT : SW_HIDE);\r
+\r
+       Trim(cmdline);\r
+\r
+       if (disableWow)\r
+       {\r
+               p = MsDisableWow64FileSystemRedirection();\r
+       }\r
+\r
+       if (CreateProcess(NULL, cmdline, NULL, NULL, FALSE,\r
+               (hide == false ? CREATE_NEW_CONSOLE : CREATE_NO_WINDOW | CREATE_NEW_CONSOLE) | NORMAL_PRIORITY_CLASS,\r
+               NULL, NULL, &info, &ret) == FALSE)\r
+       {\r
+               if (disableWow)\r
+               {\r
+                       MsRestoreWow64FileSystemRedirection(p);\r
+               }\r
+               return NULL;\r
+       }\r
+       if (disableWow)\r
+       {\r
+               MsRestoreWow64FileSystemRedirection(p);\r
+       }\r
+\r
+       if (process_id != NULL)\r
+       {\r
+               *process_id = ret.dwProcessId;\r
+       }\r
+\r
+       CloseHandle(ret.hThread);\r
+       return ret.hProcess;\r
+}\r
+\r
+// プロセスの起動\r
+bool Win32RunW(wchar_t *filename, wchar_t *arg, bool hide, bool wait)\r
+{\r
+       STARTUPINFOW info;\r
+       PROCESS_INFORMATION ret;\r
+       wchar_t cmdline[MAX_SIZE];\r
+       wchar_t name[MAX_PATH];\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char *filename_a = CopyUniToStr(filename);\r
+               char *arg_a = CopyUniToStr(arg);\r
+               bool ret;\r
+\r
+               ret = Win32Run(filename_a, arg_a, hide, wait);\r
+\r
+               Free(filename_a);\r
+               Free(arg_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       UniStrCpy(name, sizeof(name), filename);\r
+       UniTrim(name);\r
+\r
+       if (UniSearchStr(name, L"\"", 0) == INFINITE)\r
+       {\r
+               if (arg == NULL)\r
+               {\r
+                       UniFormat(cmdline, sizeof(cmdline), L"%s", name);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(cmdline, sizeof(cmdline), L"%s %s", name, arg);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (arg == NULL)\r
+               {\r
+                       UniFormat(cmdline, sizeof(cmdline), L"\"%s\"", name);\r
+               }\r
+               else\r
+               {\r
+                       UniFormat(cmdline, sizeof(cmdline), L"\"%s\" %s", name, arg);\r
+               }\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       Zero(&ret, sizeof(ret));\r
+       info.cb = sizeof(info);\r
+       info.dwFlags = STARTF_USESHOWWINDOW;\r
+       info.wShowWindow = (hide == false ? SW_SHOWDEFAULT : SW_HIDE);\r
+\r
+       UniTrim(cmdline);\r
+\r
+       if (CreateProcessW(NULL, cmdline, NULL, NULL, FALSE,\r
+               (hide == false ? CREATE_NEW_CONSOLE : CREATE_NO_WINDOW | CREATE_NEW_CONSOLE) | NORMAL_PRIORITY_CLASS,\r
+               NULL, NULL, &info, &ret) == FALSE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (wait)\r
+       {\r
+               WaitForSingleObject(ret.hProcess, INFINITE);\r
+       }\r
+\r
+       CloseHandle(ret.hThread);\r
+       CloseHandle(ret.hProcess);\r
+\r
+       return true;\r
+}\r
+bool Win32Run(char *filename, char *arg, bool hide, bool wait)\r
+{\r
+       STARTUPINFO info;\r
+       PROCESS_INFORMATION ret;\r
+       char cmdline[MAX_SIZE];\r
+       char name[MAX_PATH];\r
+       // 引数チェック\r
+       if (filename == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       StrCpy(name, sizeof(name), filename);\r
+       Trim(name);\r
+\r
+       if (SearchStr(name, "\"", 0) == INFINITE)\r
+       {\r
+               if (arg == NULL)\r
+               {\r
+                       Format(cmdline, sizeof(cmdline), "%s", name);\r
+               }\r
+               else\r
+               {\r
+                       Format(cmdline, sizeof(cmdline), "%s %s", name, arg);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if (arg == NULL)\r
+               {\r
+                       Format(cmdline, sizeof(cmdline), "\"%s\"", name);\r
+               }\r
+               else\r
+               {\r
+                       Format(cmdline, sizeof(cmdline), "\"%s\" %s", name, arg);\r
+               }\r
+       }\r
+\r
+       Zero(&info, sizeof(info));\r
+       Zero(&ret, sizeof(ret));\r
+       info.cb = sizeof(info);\r
+       info.dwFlags = STARTF_USESHOWWINDOW;\r
+       info.wShowWindow = (hide == false ? SW_SHOWDEFAULT : SW_HIDE);\r
+\r
+       Trim(cmdline);\r
+\r
+       if (CreateProcess(NULL, cmdline, NULL, NULL, FALSE,\r
+               (hide == false ? CREATE_NEW_CONSOLE : CREATE_NO_WINDOW | CREATE_NEW_CONSOLE) | NORMAL_PRIORITY_CLASS,\r
+               NULL, NULL, &info, &ret) == FALSE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (wait)\r
+       {\r
+               WaitForSingleObject(ret.hProcess, INFINITE);\r
+       }\r
+\r
+       CloseHandle(ret.hThread);\r
+       CloseHandle(ret.hProcess);\r
+\r
+       return true;\r
+}\r
+\r
+// スレッド ID の取得\r
+UINT Win32ThreadId()\r
+{\r
+       return GetCurrentThreadId();\r
+}\r
+\r
+// ファイル名の変更\r
+bool Win32FileRenameW(wchar_t *old_name, wchar_t *new_name)\r
+{\r
+       // 引数チェック\r
+       if (old_name == NULL || new_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char *old_name_a = CopyUniToStr(old_name);\r
+               char *new_name_a = CopyUniToStr(new_name);\r
+               bool ret = Win32FileRename(old_name_a, new_name_a);\r
+\r
+               Free(old_name_a);\r
+               Free(new_name_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       // リネーム\r
+       if (MoveFileW(old_name, new_name) == FALSE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+bool Win32FileRename(char *old_name, char *new_name)\r
+{\r
+       // 引数チェック\r
+       if (old_name == NULL || new_name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // リネーム\r
+       if (MoveFile(old_name, new_name) == FALSE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// EXE ファイルが存在しているディレクトリ名を取得する\r
+void Win32GetExeDirW(wchar_t *name, UINT size)\r
+{\r
+       wchar_t exe_path[MAX_SIZE];\r
+       wchar_t exe_dir[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char name_a[MAX_PATH];\r
+\r
+               Win32GetExeDir(name_a, sizeof(name_a));\r
+\r
+               StrToUni(name, size, name_a);\r
+\r
+               return;\r
+       }\r
+\r
+       // EXE ファイル名を取得\r
+       GetModuleFileNameW(NULL, exe_path, sizeof(exe_path));\r
+\r
+       // ディレクトリ名を取得\r
+       Win32GetDirFromPathW(exe_dir, sizeof(exe_dir), exe_path);\r
+\r
+       UniStrCpy(name, size, exe_dir);\r
+}\r
+void Win32GetExeDir(char *name, UINT size)\r
+{\r
+       char exe_path[MAX_SIZE];\r
+       char exe_dir[MAX_SIZE];\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // EXE ファイル名を取得\r
+       GetModuleFileName(NULL, exe_path, sizeof(exe_path));\r
+\r
+       // ディレクトリ名を取得\r
+       Win32GetDirFromPath(exe_dir, sizeof(exe_dir), exe_path);\r
+\r
+       StrCpy(name, size, exe_dir);\r
+}\r
+\r
+// 終端の \ を抜く\r
+void Win32NukuEnW(wchar_t *dst, UINT size, wchar_t *src)\r
+{\r
+       wchar_t str[MAX_SIZE];\r
+       int i;\r
+       if (src)\r
+       {\r
+               UniStrCpy(str, sizeof(str), src);\r
+       }\r
+       else\r
+       {\r
+               UniStrCpy(str, sizeof(str), dst);\r
+       }\r
+       i = UniStrLen(str);\r
+       if (str[i - 1] == L'\\')\r
+       {\r
+               str[i - 1] = 0;\r
+       }\r
+       UniStrCpy(dst, size, str);\r
+}\r
+void Win32NukuEn(char *dst, UINT size, char *src)\r
+{\r
+       char str[MAX_SIZE];\r
+       int i;\r
+       if (src)\r
+       {\r
+               StrCpy(str, sizeof(str), src);\r
+       }\r
+       else\r
+       {\r
+               StrCpy(str, sizeof(str), dst);\r
+       }\r
+       i = StrLen(str);\r
+       if (str[i - 1] == '\\')\r
+       {\r
+               str[i - 1] = 0;\r
+       }\r
+       StrCpy(dst, size, str);\r
+}\r
+\r
+// ディレクトリ名をパスから取得\r
+void Win32GetDirFromPathW(wchar_t *dst, UINT size, wchar_t *src)\r
+{\r
+       wchar_t str[MAX_SIZE];\r
+       int i,len;\r
+       wchar_t c;\r
+       wchar_t tmp[MAX_SIZE];\r
+       int wp;\r
+       if (src)\r
+       {\r
+               UniStrCpy(str, sizeof(str), src);\r
+       }\r
+       else\r
+       {\r
+               UniStrCpy(str, sizeof(str), dst);\r
+       }\r
+       Win32NukuEnW(str, sizeof(str), NULL);\r
+       wp = 0;\r
+       len = UniStrLen(str);\r
+       dst[0] = 0;\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               c = str[i];\r
+               switch (c)\r
+               {\r
+               case L'\\':\r
+                       tmp[wp] = 0;\r
+                       wp = 0;\r
+                       UniStrCat(dst, size, tmp);\r
+                       UniStrCat(dst, size, L"\\");\r
+                       break;\r
+               default:\r
+                       tmp[wp] = c;\r
+                       wp++;\r
+                       break;\r
+               }\r
+       }\r
+       Win32NukuEnW(dst, size, NULL);\r
+}\r
+void Win32GetDirFromPath(char *dst, UINT size, char *src)\r
+{\r
+       char str[MAX_SIZE];\r
+       int i,len;\r
+       char c;\r
+       char tmp[MAX_SIZE];\r
+       int wp;\r
+       if (src)\r
+       {\r
+               StrCpy(str, sizeof(str), src);\r
+       }\r
+       else\r
+       {\r
+               StrCpy(str, sizeof(str), dst);\r
+       }\r
+       Win32NukuEn(str, sizeof(str), NULL);\r
+       wp = 0;\r
+       len = StrLen(str);\r
+       dst[0] = 0;\r
+       for (i = 0;i < len;i++)\r
+       {\r
+               c = str[i];\r
+               switch (c)\r
+               {\r
+               case '\\':\r
+                       tmp[wp] = 0;\r
+                       wp = 0;\r
+                       StrCat(dst, size, tmp);\r
+                       StrCat(dst, size, "\\");\r
+                       break;\r
+               default:\r
+                       tmp[wp] = c;\r
+                       wp++;\r
+                       break;\r
+               }\r
+       }\r
+       Win32NukuEn(dst, size, NULL);\r
+}\r
+\r
+// ディレクトリの削除\r
+bool Win32DeleteDirW(wchar_t *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char *name_a = CopyUniToStr(name);\r
+               bool ret = Win32DeleteDir(name_a);\r
+\r
+               Free(name_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       if (RemoveDirectoryW(name) == FALSE)\r
+       {\r
+               return false;\r
+       }\r
+       return true;\r
+}\r
+bool Win32DeleteDir(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (RemoveDirectory(name) == FALSE)\r
+       {\r
+               return false;\r
+       }\r
+       return true;\r
+}\r
+\r
+// ディレクトリの作成\r
+bool Win32MakeDirW(wchar_t *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               char *name_a = CopyUniToStr(name);\r
+               bool ret = Win32MakeDir(name_a);\r
+\r
+               Free(name_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       if (CreateDirectoryW(name, NULL) == FALSE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+bool Win32MakeDir(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (CreateDirectory(name, NULL) == FALSE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ファイルの削除\r
+bool Win32FileDeleteW(wchar_t *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               bool ret;\r
+               char *name_a = CopyUniToStr(name);\r
+\r
+               ret = Win32FileDelete(name_a);\r
+\r
+               Free(name_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       if (DeleteFileW(name) == FALSE)\r
+       {\r
+               return false;\r
+       }\r
+       return true;\r
+}\r
+bool Win32FileDelete(char *name)\r
+{\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (DeleteFile(name) == FALSE)\r
+       {\r
+               return false;\r
+       }\r
+       return true;\r
+}\r
+\r
+// ファイルのシーク\r
+bool Win32FileSeek(void *pData, UINT mode, int offset)\r
+{\r
+       WIN32IO *p;\r
+       DWORD ret;\r
+       // 引数チェック\r
+       if (pData == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (mode != FILE_BEGIN && mode != FILE_END && mode != FILE_CURRENT)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = (WIN32IO *)pData;\r
+       ret = SetFilePointer(p->hFile, (LONG)offset, NULL, mode);\r
+       if (ret == INVALID_SET_FILE_POINTER || ret == ERROR_NEGATIVE_SEEK)\r
+       {\r
+               return false;\r
+       }\r
+       return true;\r
+}\r
+\r
+// ファイルサイズの取得\r
+UINT64 Win32FileSize(void *pData)\r
+{\r
+       WIN32IO *p;\r
+       UINT64 ret;\r
+       DWORD tmp;\r
+       // 引数チェック\r
+       if (pData == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       p = (WIN32IO *)pData;\r
+       tmp = 0;\r
+       ret = GetFileSize(p->hFile, &tmp);\r
+       if (ret == (DWORD)-1)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       if (tmp != 0)\r
+       {\r
+               ret += (UINT64)tmp * 4294967296ULL;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ファイルに書き込む\r
+bool Win32FileWrite(void *pData, void *buf, UINT size)\r
+{\r
+       WIN32IO *p;\r
+       DWORD write_size;\r
+       // 引数チェック\r
+       if (pData == NULL || buf == NULL || size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = (WIN32IO *)pData;\r
+       if (WriteFile(p->hFile, buf, size, &write_size, NULL) == FALSE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (write_size != size)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+// ファイルから読み込む\r
+bool Win32FileRead(void *pData, void *buf, UINT size)\r
+{\r
+       WIN32IO *p;\r
+       DWORD read_size;\r
+       // 引数チェック\r
+       if (pData == NULL || buf == NULL || size == 0)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       p = (WIN32IO *)pData;\r
+       if (ReadFile(p->hFile, buf, size, &read_size, NULL) == FALSE)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (read_size != size)\r
+       {\r
+               return false;\r
+       }\r
+       \r
+       return true;;\r
+}\r
+\r
+// ファイルを閉じる\r
+void Win32FileClose(void *pData, bool no_flush)\r
+{\r
+       WIN32IO *p;\r
+       // 引数チェック\r
+       if (pData == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = (WIN32IO *)pData;\r
+       if (p->WriteMode && no_flush == false)\r
+       {\r
+               FlushFileBuffers(p->hFile);\r
+       }\r
+       CloseHandle(p->hFile);\r
+       p->hFile = NULL;\r
+\r
+       // メモリ解放\r
+       Win32MemoryFree(p);\r
+}\r
+\r
+// ファイルをフラッシュする\r
+void Win32FileFlush(void *pData)\r
+{\r
+       WIN32IO *p;\r
+       // 引数チェック\r
+       if (pData == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       p = (WIN32IO *)pData;\r
+       if (p->WriteMode)\r
+       {\r
+               FlushFileBuffers(p->hFile);\r
+       }\r
+}\r
+\r
+// ファイルを開く\r
+void *Win32FileOpenW(wchar_t *name, bool write_mode, bool read_lock)\r
+{\r
+       WIN32IO *p;\r
+       HANDLE h;\r
+       DWORD lock_mode;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               void *ret;\r
+               char *name_a = CopyUniToStr(name);\r
+\r
+               ret = Win32FileOpen(name_a, write_mode, read_lock);\r
+\r
+               Free(name_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       if (write_mode)\r
+       {\r
+               lock_mode = FILE_SHARE_READ;\r
+       }\r
+       else\r
+       {\r
+               if (read_lock == false)\r
+               {\r
+                       lock_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;\r
+               }\r
+               else\r
+               {\r
+                       lock_mode = FILE_SHARE_READ;\r
+               }\r
+       }\r
+\r
+       // ファイルを開く\r
+       h = CreateFileW(name,\r
+               (write_mode ? GENERIC_READ | GENERIC_WRITE : GENERIC_READ),\r
+               lock_mode,\r
+               NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\r
+       if (h == INVALID_HANDLE_VALUE)\r
+       {\r
+               UINT ret = GetLastError();\r
+               // 失敗\r
+               return NULL;\r
+       }\r
+\r
+       // メモリ確保\r
+       p = Win32MemoryAlloc(sizeof(WIN32IO));\r
+       // ハンドル格納\r
+       p->hFile = h;\r
+\r
+       p->WriteMode = write_mode;\r
+\r
+       return (void *)p;\r
+}\r
+void *Win32FileOpen(char *name, bool write_mode, bool read_lock)\r
+{\r
+       WIN32IO *p;\r
+       HANDLE h;\r
+       DWORD lock_mode;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (write_mode)\r
+       {\r
+               lock_mode = FILE_SHARE_READ;\r
+       }\r
+       else\r
+       {\r
+               if (read_lock == false)\r
+               {\r
+                       lock_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;\r
+               }\r
+               else\r
+               {\r
+                       lock_mode = FILE_SHARE_READ;\r
+               }\r
+       }\r
+\r
+       // ファイルを開く\r
+       h = CreateFile(name,\r
+               (write_mode ? GENERIC_READ | GENERIC_WRITE : GENERIC_READ),\r
+               lock_mode,\r
+               NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\r
+       if (h == INVALID_HANDLE_VALUE)\r
+       {\r
+               UINT ret = GetLastError();\r
+               // 失敗\r
+               return NULL;\r
+       }\r
+\r
+       // メモリ確保\r
+       p = Win32MemoryAlloc(sizeof(WIN32IO));\r
+       // ハンドル格納\r
+       p->hFile = h;\r
+\r
+       p->WriteMode = write_mode;\r
+\r
+       return (void *)p;\r
+}\r
+\r
+// ファイルを作成する\r
+void *Win32FileCreateW(wchar_t *name)\r
+{\r
+       WIN32IO *p;\r
+       HANDLE h;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               void *ret;\r
+               char *name_a = CopyUniToStr(name);\r
+\r
+               ret = Win32FileCreate(name_a);\r
+\r
+               Free(name_a);\r
+\r
+               return ret;\r
+       }\r
+\r
+       // ファイルを作成する\r
+       h = CreateFileW(name, GENERIC_READ | GENERIC_WRITE,\r
+               FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,\r
+               NULL);\r
+       if (h == INVALID_HANDLE_VALUE)\r
+       {\r
+               h = CreateFileW(name, GENERIC_READ | GENERIC_WRITE,\r
+                       FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN,\r
+                       NULL);\r
+               if (h == INVALID_HANDLE_VALUE)\r
+               {\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       // メモリ確保\r
+       p = Win32MemoryAlloc(sizeof(WIN32IO));\r
+       // ハンドル格納\r
+       p->hFile = h;\r
+\r
+       p->WriteMode = true;\r
+\r
+       return (void *)p;\r
+}\r
+void *Win32FileCreate(char *name)\r
+{\r
+       WIN32IO *p;\r
+       HANDLE h;\r
+       // 引数チェック\r
+       if (name == NULL)\r
+       {\r
+               return NULL;\r
+       }\r
+\r
+       // ファイルを作成する\r
+       h = CreateFile(name, GENERIC_READ | GENERIC_WRITE,\r
+               FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,\r
+               NULL);\r
+       if (h == INVALID_HANDLE_VALUE)\r
+       {\r
+               h = CreateFile(name, GENERIC_READ | GENERIC_WRITE,\r
+                       FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN,\r
+                       NULL);\r
+               if (h == INVALID_HANDLE_VALUE)\r
+               {\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       // メモリ確保\r
+       p = Win32MemoryAlloc(sizeof(WIN32IO));\r
+       // ハンドル格納\r
+       p->hFile = h;\r
+\r
+       p->WriteMode = true;\r
+\r
+       return (void *)p;\r
+}\r
+\r
+#define        SIZE_OF_CALLSTACK_SYM   10000\r
+#define        CALLSTACK_DEPTH                 12\r
+\r
+// コールスタックの取得\r
+CALLSTACK_DATA *Win32GetCallStack()\r
+{\r
+#ifndef        WIN32_NO_DEBUG_HELP_DLL\r
+       DWORD current_eip32 = 0, current_esp32 = 0, current_ebp32 = 0;\r
+       UINT64 current_eip = 0, current_esp = 0, current_ebp = 0;\r
+       STACKFRAME64 sf;\r
+       CALLSTACK_DATA *cs = NULL, *s;\r
+\r
+#ifdef CPU_64\r
+       CONTEXT context;\r
+#endif // CPU_64\r
+\r
+       bool ret;\r
+       UINT depth = 0;\r
+\r
+#ifndef        CPU_64\r
+       // レジスタ取得 (32 bit)\r
+       __asm\r
+       {\r
+               mov current_esp32, esp\r
+               mov current_ebp32, ebp\r
+       };\r
+\r
+       current_eip32 = (DWORD)Win32GetCallStack;\r
+\r
+       current_eip = (UINT64)current_eip32;\r
+       current_esp = (UINT64)current_esp32;\r
+       current_ebp = (UINT64)current_ebp32;\r
+#else  // CPU_64\r
+       // レジスタ取得 (64 bit)\r
+       Zero(&context, sizeof(context));\r
+       context.ContextFlags = CONTEXT_FULL;\r
+       RtlCaptureContext(&context);\r
+#endif // CPU_64\r
+\r
+       Zero(&sf, sizeof(sf));\r
+\r
+#ifndef        CPU_64\r
+       sf.AddrPC.Offset = current_eip;\r
+       sf.AddrStack.Offset = current_esp;\r
+       sf.AddrFrame.Offset = current_ebp;\r
+#else  // CPU_64\r
+       sf.AddrPC.Offset = context.Rip;\r
+       sf.AddrStack.Offset = context.Rsp;\r
+       sf.AddrFrame.Offset = context.Rsp;\r
+#endif // CPU_64\r
+\r
+       sf.AddrPC.Mode = AddrModeFlat;\r
+       sf.AddrStack.Mode = AddrModeFlat;\r
+       sf.AddrFrame.Mode = AddrModeFlat;\r
+\r
+       while (true)\r
+       {\r
+               DWORD type = IMAGE_FILE_MACHINE_I386;\r
+\r
+#ifdef CPU_64\r
+               type = IMAGE_FILE_MACHINE_AMD64;\r
+#endif // CPU_64\r
+\r
+               if ((depth++) >= CALLSTACK_DEPTH)\r
+               {\r
+                       break;\r
+               }\r
+\r
+#ifndef        CPU_64\r
+               ret = StackWalk64(type,\r
+                       hCurrentProcessHandle,\r
+                       GetCurrentThread(),\r
+                       &sf,\r
+                       NULL, NULL, SymFunctionTableAccess64, SymGetModuleBase64, NULL);\r
+#else  // CPU_64\r
+               ret = StackWalk64(type,\r
+                       hCurrentProcessHandle,\r
+                       GetCurrentThread(),\r
+                       &sf,\r
+                       &context, NULL, SymFunctionTableAccess64, SymGetModuleBase64, NULL);\r
+#endif // CPU_64\r
+               if (ret == false || sf.AddrFrame.Offset == 0)\r
+               {\r
+                       break;\r
+               }\r
+\r
+               if (cs == NULL)\r
+               {\r
+                       cs = OSMemoryAlloc(sizeof(CALLSTACK_DATA));\r
+                       s = cs;\r
+               }\r
+               else\r
+               {\r
+                       s->next = OSMemoryAlloc(sizeof(CALLSTACK_DATA));\r
+                       s = s->next;\r
+               }\r
+               s->symbol_cache = false;\r
+               s->next = NULL;\r
+               s->offset = sf.AddrPC.Offset;\r
+               s->disp = 0;\r
+               s->name = NULL;\r
+               s->line = 0;\r
+               s->filename[0] = 0;\r
+       }\r
+\r
+       return cs;\r
+#else  // WIN32_NO_DEBUG_HELP_DLL\r
+       return NULL;\r
+#endif // WIN32_NO_DEBUG_HELP_DLL\r
+}\r
+\r
+// コールスタックからシンボル情報を取得\r
+bool Win32GetCallStackSymbolInfo(CALLSTACK_DATA *s)\r
+{\r
+#ifdef WIN32_NO_DEBUG_HELP_DLL\r
+       return false;\r
+#else  // WIN32_NO_DEBUG_HELP_DLL\r
+       UINT64 disp;\r
+       UINT disp32, len;\r
+       IMAGEHLP_SYMBOL64 *sym;\r
+       IMAGEHLP_LINE64 line;\r
+       char tmp[MAX_PATH];\r
+       // 引数チェック\r
+       if (s == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       if (s->symbol_cache)\r
+       {\r
+               return true;\r
+       }\r
+\r
+       sym = OSMemoryAlloc(SIZE_OF_CALLSTACK_SYM);\r
+       sym->SizeOfStruct = SIZE_OF_CALLSTACK_SYM;\r
+       sym->MaxNameLength = SIZE_OF_CALLSTACK_SYM - sizeof(IMAGEHLP_SYMBOL64);\r
+\r
+       if (SymGetSymFromAddr64(hCurrentProcessHandle, s->offset, &disp, sym))\r
+       {\r
+               s->disp = disp;\r
+               s->name = OSMemoryAlloc((UINT)strlen(sym->Name) + 1);\r
+               lstrcpy(s->name, sym->Name);\r
+       }\r
+       else\r
+       {\r
+               s->disp = 0;\r
+               s->name = NULL;\r
+       }\r
+\r
+       Zero(&line, sizeof(line));\r
+       line.SizeOfStruct = sizeof(line);\r
+       if (SymGetLineFromAddr64(hCurrentProcessHandle, s->offset, &disp32, &line))\r
+       {\r
+               disp = (UINT64)disp32;\r
+               s->line = line.LineNumber;\r
+               lstrcpy(s->filename, line.FileName);\r
+               Win32GetDirFromPath(tmp, sizeof(tmp), s->filename);\r
+               len = lstrlen(tmp);\r
+               lstrcpy(tmp, &s->filename[len + 1]);\r
+               lstrcpy(s->filename, tmp);\r
+       }\r
+       else\r
+       {\r
+               s->line = 0;\r
+               s->filename[0] = 0;\r
+       }\r
+\r
+       OSMemoryFree(sym);\r
+\r
+       s->symbol_cache = true;\r
+\r
+       return true;\r
+#endif // WIN32_NO_DEBUG_HELP_DLL\r
+}\r
+\r
+// デフォルトの Win32 スレッド\r
+DWORD CALLBACK Win32DefaultThreadProc(void *param)\r
+{\r
+       WIN32THREADSTARTUPINFO *info = (WIN32THREADSTARTUPINFO *)param;\r
+       // 引数チェック\r
+       if (info == NULL)\r
+       {\r
+               return 0;\r
+       }\r
+\r
+       Win32InitNewThread();\r
+\r
+       // スレッド関数の呼び出し\r
+       info->thread_proc(info->thread, info->param);\r
+\r
+       // 参照の解放\r
+       ReleaseThread(info->thread);\r
+\r
+       Win32MemoryFree(info);\r
+\r
+       FreeOpenSSLThreadState();\r
+\r
+       _endthreadex(0);\r
+       return 0;\r
+}\r
+\r
+// スレッドの終了を待機\r
+bool Win32WaitThread(THREAD *t)\r
+{\r
+       WIN32THREAD *w;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       w = (WIN32THREAD *)t->pData;\r
+       if (w == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // スレッドイベントを待機する\r
+       if (WaitForSingleObject(w->hThread, INFINITE) == WAIT_OBJECT_0)\r
+       {\r
+               // スレッドがシグナル状態になった\r
+               return true;\r
+       }\r
+\r
+       // 待機失敗 (タイムアウト等)\r
+       return false;\r
+}\r
+\r
+// スレッドの解放\r
+void Win32FreeThread(THREAD *t)\r
+{\r
+       WIN32THREAD *w;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return;\r
+       }\r
+       w = (WIN32THREAD *)t->pData;\r
+       if (w == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       // ハンドルを閉じる\r
+       CloseHandle(w->hThread);\r
+\r
+       // メモリ解放\r
+       Win32MemoryFree(t->pData);\r
+       t->pData = NULL;\r
+}\r
+\r
+// スレッドの初期化\r
+bool Win32InitThread(THREAD *t)\r
+{\r
+       WIN32THREAD *w;\r
+       HANDLE hThread;\r
+       DWORD thread_id;\r
+       WIN32THREADSTARTUPINFO *info;\r
+       // 引数チェック\r
+       if (t == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (t->thread_proc == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // スレッドデータ生成\r
+       w = Win32MemoryAlloc(sizeof(WIN32THREAD));\r
+\r
+       // 起動情報生成\r
+       info = Win32MemoryAlloc(sizeof(WIN32THREADSTARTUPINFO));\r
+       info->param = t->param;\r
+       info->thread_proc = t->thread_proc;\r
+       info->thread = t;\r
+       AddRef(t->ref);\r
+\r
+       // スレッド作成\r
+       t->pData = w;\r
+       hThread = (HANDLE)_beginthreadex(NULL, 0, Win32DefaultThreadProc, info, 0, &thread_id);\r
+       if (hThread == NULL)\r
+       {\r
+               // スレッド作成失敗\r
+               t->pData = NULL;\r
+               Release(t->ref);\r
+               Win32MemoryFree(info);\r
+               Win32MemoryFree(w);\r
+               return false;\r
+       }\r
+\r
+       // スレッド情報の保存\r
+       w->hThread = hThread;\r
+       w->thread_id = thread_id;\r
+\r
+       return true;\r
+}\r
+\r
+// Win32 用ライブラリの初期化\r
+void Win32Init()\r
+{\r
+       INITCOMMONCONTROLSEX c;\r
+       OSVERSIONINFO os;\r
+\r
+       // Windows NT かどうか取得する\r
+       Zero(&os, sizeof(os));\r
+       os.dwOSVersionInfoSize = sizeof(os);\r
+       GetVersionEx(&os);\r
+\r
+       if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)\r
+       {\r
+               // NT 系\r
+               win32_is_nt = true;\r
+       }\r
+       else\r
+       {\r
+               // 9x 系\r
+               win32_is_nt = false;\r
+       }\r
+\r
+       // stdout を開く\r
+       if (hstdout == INVALID_HANDLE_VALUE)\r
+       {\r
+               hstdout = GetStdHandle(STD_OUTPUT_HANDLE);\r
+       }\r
+\r
+       // stdin を開く\r
+       if (hstdin == INVALID_HANDLE_VALUE)\r
+       {\r
+               hstdin = GetStdHandle(STD_INPUT_HANDLE);\r
+       }\r
+\r
+       Win32InitNewThread();\r
+\r
+       CoInitialize(NULL);\r
+\r
+       InitializeCriticalSection(&fasttick_lock);\r
+\r
+#ifdef WIN32_USE_HEAP_API_FOR_MEMORY\r
+       use_heap_api = true;\r
+#else  // WIN32_USE_HEAP_API_FOR_MEMORY\r
+       use_heap_api = false;\r
+#endif // WIN32_USE_HEAP_API_FOR_MEMORY\r
+\r
+       if (MayaquaIsDotNetMode())\r
+       {\r
+               // .NET API 内からヒープ関係の API を呼び出すとクラッシュする\r
+               use_heap_api = false;\r
+       }\r
+\r
+       if (IsNt() == false)\r
+       {\r
+               // Win9x ではヒープ関係の API は使用しない\r
+               use_heap_api = false;\r
+       }\r
+\r
+       if (use_heap_api)\r
+       {\r
+               heap_handle = HeapCreate(0, 0, 0);\r
+       }\r
+\r
+       // プロセス擬似ハンドルの取得\r
+       hCurrentProcessHandle = GetCurrentProcess();\r
+\r
+       // カレントディレクトリの初期化\r
+       // Win32InitCurrentDir(); /* 行わない */\r
+\r
+       // シンボルハンドラの初期化\r
+       if (IsMemCheck())\r
+       {\r
+#ifndef        WIN32_NO_DEBUG_HELP_DLL\r
+               SymInitialize(hCurrentProcessHandle, NULL, TRUE);\r
+#endif // WIN32_NO_DEBUG_HELP_DLL\r
+       }\r
+\r
+       // Common Control の初期化\r
+       Zero(&c, sizeof(INITCOMMONCONTROLSEX));\r
+       c.dwSize = sizeof(INITCOMMONCONTROLSEX);\r
+       c.dwICC = ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES |\r
+               ICC_DATE_CLASSES | ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES |\r
+               ICC_LISTVIEW_CLASSES | ICC_NATIVEFNTCTL_CLASS |\r
+               ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |\r
+               ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS | ICC_USEREX_CLASSES |\r
+               ICC_WIN95_CLASSES;\r
+       InitCommonControlsEx(&c);\r
+}\r
+\r
+// Win32 用ライブラリの解放\r
+void Win32Free()\r
+{\r
+       // シンボルハンドラを閉じる\r
+       if (IsMemCheck())\r
+       {\r
+#ifndef        WIN32_NO_DEBUG_HELP_DLL\r
+               SymCleanup(hCurrentProcessHandle);\r
+#endif // WIN32_NO_DEBUG_HELP_DLL\r
+       }\r
+\r
+       if (use_heap_api)\r
+       {\r
+               HeapDestroy(heap_handle);\r
+               heap_handle = NULL;\r
+       }\r
+\r
+       CoUninitialize();\r
+\r
+       DeleteCriticalSection(&fasttick_lock);\r
+}\r
+\r
+// メモリ確保\r
+void *Win32MemoryAlloc(UINT size)\r
+{\r
+       if (use_heap_api)\r
+       {\r
+               return HeapAlloc(heap_handle, 0, size);\r
+       }\r
+       else\r
+       {\r
+               return malloc(size);\r
+       }\r
+}\r
+\r
+// メモリ再確保\r
+void *Win32MemoryReAlloc(void *addr, UINT size)\r
+{\r
+       if (use_heap_api)\r
+       {\r
+               return HeapReAlloc(heap_handle, 0, addr, size);\r
+       }\r
+       else\r
+       {\r
+               return realloc(addr, size);\r
+       }\r
+}\r
+\r
+// メモリ確報\r
+void Win32MemoryFree(void *addr)\r
+{\r
+       if (use_heap_api)\r
+       {\r
+               HeapFree(heap_handle, 0, addr);\r
+       }\r
+       else\r
+       {\r
+               free(addr);\r
+       }\r
+}\r
+\r
+// システムタイマの取得\r
+UINT Win32GetTick()\r
+{\r
+       return (UINT)timeGetTime();\r
+}\r
+\r
+// システム時刻の取得\r
+void Win32GetSystemTime(SYSTEMTIME *system_time)\r
+{\r
+       // システム時刻の取得\r
+       GetSystemTime(system_time);\r
+}\r
+\r
+// 32bit 整数のインクリメント\r
+void Win32Inc32(UINT *value)\r
+{\r
+       InterlockedIncrement(value);\r
+}\r
+\r
+// 32bit 整数のデクリメント\r
+void Win32Dec32(UINT *value)\r
+{\r
+       InterlockedDecrement(value);\r
+}\r
+\r
+// スレッドの休止\r
+void Win32Sleep(UINT time)\r
+{\r
+       Sleep(time);\r
+}\r
+\r
+// ロックの作成\r
+LOCK *Win32NewLock()\r
+{\r
+       // メモリ確保\r
+       LOCK *lock = Win32MemoryAlloc(sizeof(LOCK));\r
+\r
+       // クリティカルセクション確保\r
+       CRITICAL_SECTION *critical_section = Win32MemoryAlloc(sizeof(CRITICAL_SECTION));\r
+\r
+       if (lock == NULL || critical_section == NULL)\r
+       {\r
+               Win32MemoryFree(lock);\r
+               Win32MemoryFree(critical_section);\r
+               return NULL;\r
+       }\r
+\r
+       // クリティカルセクション初期化\r
+       InitializeCriticalSection(critical_section);\r
+\r
+       lock->pData = (void *)critical_section;\r
+       lock->Ready = true;\r
+\r
+       return lock;\r
+}\r
+\r
+// ロック\r
+bool Win32Lock(LOCK *lock)\r
+{\r
+       CRITICAL_SECTION *critical_section;\r
+       if (lock->Ready == false)\r
+       {\r
+               // 状態が不正\r
+               return false;\r
+       }\r
+\r
+       // クリティカルセクションに入る\r
+       critical_section = (CRITICAL_SECTION *)lock->pData;\r
+       EnterCriticalSection(critical_section);\r
+\r
+       return true;\r
+}\r
+\r
+// ロック解除\r
+void Win32Unlock(LOCK *lock)\r
+{\r
+       Win32UnlockEx(lock, false);\r
+}\r
+void Win32UnlockEx(LOCK *lock, bool inner)\r
+{\r
+       CRITICAL_SECTION *critical_section;\r
+       if (lock->Ready == false && inner == false)\r
+       {\r
+               // 状態が不正\r
+               return;\r
+       }\r
+\r
+       // クリティカルセクションから出る\r
+       critical_section = (CRITICAL_SECTION *)lock->pData;\r
+       LeaveCriticalSection(critical_section);\r
+}\r
+\r
+// ロックの削除\r
+void Win32DeleteLock(LOCK *lock)\r
+{\r
+       CRITICAL_SECTION *critical_section;\r
+       // Ready フラグを安全に解除する\r
+       Win32Lock(lock);\r
+       lock->Ready = false;\r
+       Win32UnlockEx(lock, true);\r
+\r
+       // クリティカルセクションの削除\r
+       critical_section = (CRITICAL_SECTION *)lock->pData;\r
+       DeleteCriticalSection(critical_section);\r
+\r
+       // メモリ解放\r
+       Win32MemoryFree(critical_section);\r
+       Win32MemoryFree(lock);\r
+}\r
+\r
+// イベントの初期化\r
+void Win32InitEvent(EVENT *event)\r
+{\r
+       // 自動リセットイベントの作成\r
+       HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);\r
+\r
+       event->pData = hEvent;\r
+}\r
+\r
+// イベントのセット\r
+void Win32SetEvent(EVENT *event)\r
+{\r
+       HANDLE hEvent = (HANDLE)event->pData;\r
+       if (hEvent == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       SetEvent(hEvent);\r
+}\r
+\r
+// イベントのリセット\r
+void Win32ResetEvent(EVENT *event)\r
+{\r
+       HANDLE hEvent = (HANDLE)event->pData;\r
+       if (hEvent == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       ResetEvent(hEvent);\r
+}\r
+\r
+// イベントを待機する\r
+bool Win32WaitEvent(EVENT *event, UINT timeout)\r
+{\r
+       HANDLE hEvent = (HANDLE)event->pData;\r
+       UINT ret;\r
+       if (hEvent == NULL)\r
+       {\r
+               return false;\r
+       }\r
+\r
+       // オブジェクトを待機\r
+       ret = WaitForSingleObject(hEvent, timeout);\r
+       if (ret == WAIT_TIMEOUT)\r
+       {\r
+               // タイムアウト\r
+               return false;\r
+       }\r
+       else\r
+       {\r
+               // シグナル状態\r
+               return true;\r
+       }\r
+}\r
+\r
+// イベントの解放\r
+void Win32FreeEvent(EVENT *event)\r
+{\r
+       HANDLE hEvent = (HANDLE)event->pData;\r
+       if (hEvent == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       CloseHandle(hEvent);\r
+}\r
+\r
+// Win32 専用の高速な 64 bit Tick 取得関数\r
+UINT64 Win32FastTick64()\r
+{\r
+       static UINT last_tick = 0;\r
+       static UINT counter = 0;\r
+       UINT64 ret;\r
+       UINT tick;\r
+\r
+       EnterCriticalSection(&fasttick_lock);\r
+\r
+       // 現在の tick 値を取得する\r
+       tick = Win32GetTick();\r
+\r
+       if (last_tick > tick)\r
+       {\r
+               // 前回取得した tick 値のほうが今回取得した値よりも大きい場合\r
+               // カウンタが 1 回りしたと考えることができる\r
+\r
+               counter++;\r
+       }\r
+\r
+       last_tick = tick;\r
+\r
+       ret = (UINT64)tick + (UINT64)counter * 4294967296ULL;\r
+\r
+       LeaveCriticalSection(&fasttick_lock);\r
+\r
+       if (start_tick == 0)\r
+       {\r
+               start_tick = ret;\r
+               ret = 0;\r
+       }\r
+       else\r
+       {\r
+               ret -= start_tick;\r
+       }\r
+\r
+       return ret + 1;\r
+}\r
+\r
+// 文字列をコンソールから読み込む\r
+bool Win32InputW(wchar_t *str, UINT size)\r
+{\r
+       bool ret = false;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return false;\r
+       }\r
+       if (size == 0)\r
+       {\r
+               size = 0x7fffffff;\r
+       }\r
+\r
+       if (str == NULL || size <= sizeof(wchar_t))\r
+       {\r
+               if (str != NULL)\r
+               {\r
+                       Zero(str, size);\r
+               }\r
+\r
+               return Win32InputFromFileW(NULL, 0);\r
+       }\r
+\r
+       if (IsNt())\r
+       {\r
+               DWORD read_size = 0;\r
+\r
+               if (ReadConsoleW(hstdin, str, (size - sizeof(wchar_t)), &read_size, NULL))\r
+               {\r
+                       str[read_size] = 0;\r
+\r
+                       UniTrimCrlf(str);\r
+\r
+                       ret = true;\r
+               }\r
+               else\r
+               {\r
+                       ret = Win32InputFromFileW(str, size);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               DWORD read_size = 0;\r
+               UINT a_size = size / sizeof(wchar_t) + 16;\r
+               char *a;\r
+\r
+               a = ZeroMalloc(a_size);\r
+\r
+               if (ReadConsoleA(hstdin, a, a_size - 1, &read_size, NULL))\r
+               {\r
+                       a[read_size] = 0;\r
+\r
+                       StrToUni(str, size, a);\r
+\r
+                       UniTrimCrlf(str);\r
+\r
+                       ret = true;\r
+               }\r
+               else\r
+               {\r
+                       ret = Win32InputFromFileW(str, size);\r
+               }\r
+\r
+               Free(a);\r
+       }\r
+\r
+       return ret;\r
+}\r
+// 1 行を標準入力から取得\r
+bool Win32InputFromFileW(wchar_t *str, UINT size)\r
+{\r
+       char *a;\r
+       if (str == NULL)\r
+       {\r
+               wchar_t tmp[MAX_SIZE];\r
+               Win32InputFromFileW(tmp, sizeof(tmp));\r
+               return false;\r
+       }\r
+\r
+       a = Win32InputFromFileLineA();\r
+       if (a == NULL)\r
+       {\r
+               UniStrCpy(str, size, L"");\r
+               return false;\r
+       }\r
+\r
+       UtfToUni(str, size, a);\r
+\r
+       UniTrimCrlf(str);\r
+\r
+       Free(a);\r
+\r
+       return true;\r
+}\r
+char *Win32InputFromFileLineA()\r
+{\r
+       BUF *b = NewBuf();\r
+       char zero = 0;\r
+       char *ret = NULL;\r
+       bool ok = true;\r
+\r
+       while (true)\r
+       {\r
+               char c;\r
+               UINT read_size = 0;\r
+\r
+               if (ReadFile(hstdin, &c, 1, &read_size, NULL) == false)\r
+               {\r
+                       ok = false;\r
+                       break;\r
+               }\r
+               if (read_size != 1)\r
+               {\r
+                       ok = false;\r
+                       break;\r
+               }\r
+\r
+               WriteBuf(b, &c, 1);\r
+\r
+               if (c == 10)\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       WriteBuf(b, &zero, 1);\r
+\r
+       if (ok)\r
+       {\r
+               ret = CopyStr(b->Buf);\r
+       }\r
+\r
+       FreeBuf(b);\r
+\r
+       return ret;\r
+}\r
+\r
+// 文字列をコンソールにプリントする\r
+void Win32PrintW(wchar_t *str)\r
+{\r
+       DWORD write_size = 0;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (IsNt())\r
+       {\r
+               if (WriteConsoleW(hstdout, str, UniStrLen(str), &write_size, NULL) == false)\r
+               {\r
+                       Win32PrintToFileW(str);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               char *ansi_str = CopyUniToStr(str);\r
+\r
+               if (WriteConsoleA(hstdout, ansi_str, StrLen(ansi_str), &write_size, NULL) == false)\r
+               {\r
+                       Win32PrintToFileW(str);\r
+               }\r
+\r
+               Free(ansi_str);\r
+       }\r
+}\r
+void Win32PrintToFileW(wchar_t *str)\r
+{\r
+       char *utf;\r
+       DWORD size = 0;\r
+       // 引数チェック\r
+       if (str == NULL)\r
+       {\r
+               return;\r
+       }\r
+\r
+       utf = CopyUniToUtf(str);\r
+\r
+       WriteFile(hstdout, utf, StrLen(utf), &size, NULL);\r
+\r
+       Free(utf);\r
+}\r
+\r
+\r
+#endif // WIN32\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Win32.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/Win32.h
new file mode 100644 (file)
index 0000000..9cf8ac1
--- /dev/null
@@ -0,0 +1,190 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// Win32.h\r
+// Win32.c のヘッダ\r
+\r
+#ifdef OS_WIN32\r
+\r
+#ifndef        WIN32_H\r
+#define        WIN32_H\r
+\r
+// 関数プロトタイプ\r
+OS_DISPATCH_TABLE *Win32GetDispatchTable();\r
+\r
+void Win32Init();\r
+void Win32Free();\r
+void *Win32MemoryAlloc(UINT size);\r
+void *Win32MemoryReAlloc(void *addr, UINT size);\r
+void Win32MemoryFree(void *addr);\r
+UINT Win32GetTick();\r
+void Win32GetSystemTime(SYSTEMTIME *system_time);\r
+void Win32Inc32(UINT *value);\r
+void Win32Dec32(UINT *value);\r
+void Win32Sleep(UINT time);\r
+LOCK *Win32NewLock();\r
+bool Win32Lock(LOCK *lock);\r
+void Win32Unlock(LOCK *lock);\r
+void Win32DeleteLock(LOCK *lock);\r
+void Win32InitEvent(EVENT *event);\r
+void Win32SetEvent(EVENT *event);\r
+void Win32ResetEvent(EVENT *event);\r
+bool Win32WaitEvent(EVENT *event, UINT timeout);\r
+void Win32FreeEvent(EVENT *event);\r
+bool Win32WaitThread(THREAD *t);\r
+void Win32FreeThread(THREAD *t);\r
+bool Win32InitThread(THREAD *t);\r
+UINT Win32ThreadId();\r
+void *Win32FileOpen(char *name, bool write_mode, bool read_lock);\r
+void *Win32FileOpenW(wchar_t *name, bool write_mode, bool read_lock);\r
+void *Win32FileCreate(char *name);\r
+void *Win32FileCreateW(wchar_t *name);\r
+bool Win32FileWrite(void *pData, void *buf, UINT size);\r
+bool Win32FileRead(void *pData, void *buf, UINT size);\r
+void Win32FileClose(void *pData, bool no_flush);\r
+void Win32FileFlush(void *pData);\r
+UINT64 Win32FileSize(void *pData);\r
+bool Win32FileSeek(void *pData, UINT mode, int offset);\r
+bool Win32FileDelete(char *name);\r
+bool Win32FileDeleteW(wchar_t *name);\r
+bool Win32MakeDir(char *name);\r
+bool Win32MakeDirW(wchar_t *name);\r
+bool Win32DeleteDir(char *name);\r
+bool Win32DeleteDirW(wchar_t *name);\r
+CALLSTACK_DATA *Win32GetCallStack();\r
+bool Win32GetCallStackSymbolInfo(CALLSTACK_DATA *s);\r
+bool Win32FileRename(char *old_name, char *new_name);\r
+bool Win32FileRenameW(wchar_t *old_name, wchar_t *new_name);\r
+bool Win32Run(char *filename, char *arg, bool hide, bool wait);\r
+bool Win32RunW(wchar_t *filename, wchar_t *arg, bool hide, bool wait);\r
+void *Win32RunEx(char *filename, char *arg, bool hide);\r
+void *Win32RunEx2(char *filename, char *arg, bool hide, UINT *process_id);\r
+void *Win32RunEx3(char *filename, char *arg, bool hide, UINT *process_id, bool disableWow);\r
+void *Win32RunExW(wchar_t *filename, wchar_t *arg, bool hide);\r
+void *Win32RunEx2W(wchar_t *filename, wchar_t *arg, bool hide, UINT *process_id);\r
+void *Win32RunEx3W(wchar_t *filename, wchar_t *arg, bool hide, UINT *process_id, bool disableWow);\r
+bool Win32WaitProcess(void *h, UINT timeout);\r
+bool Win32IsProcessAlive(void *handle);\r
+bool Win32TerminateProcess(void *handle);\r
+void Win32CloseProcess(void *handle);\r
+bool Win32IsSupportedOs();\r
+void Win32GetOsInfo(OS_INFO *info);\r
+void Win32Alert(char *msg, char *caption);\r
+void Win32AlertW(wchar_t *msg, wchar_t *caption);\r
+void Win32DebugAlert(char *msg);\r
+char* Win32GetProductId();\r
+void Win32SetHighPriority();\r
+void Win32RestorePriority();\r
+void *Win32NewSingleInstance(char *instance_name);\r
+void Win32FreeSingleInstance(void *data);\r
+void Win32GetMemInfo(MEMINFO *info);\r
+void Win32Yield();\r
+\r
+void Win32UnlockEx(LOCK *lock, bool inner);\r
+UINT Win32GetOsType();\r
+UINT Win32GetSpVer(char *str);\r
+UINT Win32GetOsSpVer();\r
+void Win32NukuEn(char *dst, UINT size, char *src);\r
+void Win32NukuEnW(wchar_t *dst, UINT size, wchar_t *src);\r
+void Win32GetDirFromPath(char *dst, UINT size, char *src);\r
+void Win32GetDirFromPathW(wchar_t *dst, UINT size, wchar_t *src);\r
+void Win32GetExeDir(char *name, UINT size);\r
+void Win32GetExeDirW(wchar_t *name, UINT size);\r
+void Win32GetCurrentDir(char *dir, UINT size);\r
+void Win32GetCurrentDirW(wchar_t *dir, UINT size);\r
+void Win32GetExeName(char *name, UINT size);\r
+void Win32GetExeNameW(wchar_t *name, UINT size);\r
+DIRLIST *Win32EnumDirEx(char *dirname, COMPARE *compare);\r
+DIRLIST *Win32EnumDirExW(wchar_t *dirname, COMPARE *compare);\r
+bool Win32GetDiskFreeW(wchar_t *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size);\r
+bool Win32GetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size);\r
+bool Win32SetFolderCompress(char *path, bool compressed);\r
+bool Win32SetFolderCompressW(wchar_t *path, bool compressed);\r
+UINT64 Win32FastTick64();\r
+void Win32InitNewThread();\r
+bool Win32IsNt();\r
+bool Win32InputW(wchar_t *str, UINT size);\r
+bool Win32InputFromFileW(wchar_t *str, UINT size);\r
+char *Win32InputFromFileLineA();\r
+void Win32PrintW(wchar_t *str);\r
+void Win32PrintToFileW(wchar_t *str);\r
+\r
+#endif // WIN32_H\r
+\r
+#endif // OS_WIN32\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/cryptoki.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/cryptoki.h
new file mode 100644 (file)
index 0000000..7d85ca8
--- /dev/null
@@ -0,0 +1,66 @@
+/* cryptoki.h include file for PKCS #11. */\r
+/* $Revision: 1.4 $ */\r
+\r
+/* License to copy and use this software is granted provided that it is\r
+ * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface\r
+ * (Cryptoki)" in all material mentioning or referencing this software.\r
+\r
+ * License is also granted to make and use derivative works provided that\r
+ * such works are identified as "derived from the RSA Security Inc. PKCS #11\r
+ * Cryptographic Token Interface (Cryptoki)" in all material mentioning or \r
+ * referencing the derived work.\r
+\r
+ * RSA Security Inc. makes no representations concerning either the \r
+ * merchantability of this software or the suitability of this software for\r
+ * any particular purpose. It is provided "as is" without express or implied\r
+ * warranty of any kind.\r
+ */\r
+\r
+/* This is a sample file containing the top level include directives\r
+ * for building Win32 Cryptoki libraries and applications.\r
+ */\r
+\r
+#ifndef ___CRYPTOKI_H_INC___\r
+#define ___CRYPTOKI_H_INC___\r
+\r
+#pragma pack(push, cryptoki, 1)\r
+\r
+/* Specifies that the function is a DLL entry point. */\r
+#define CK_IMPORT_SPEC __declspec(dllimport)\r
+\r
+/* Define CRYPTOKI_EXPORTS during the build of cryptoki libraries. Do\r
+ * not define it in applications.\r
+ */\r
+#ifdef CRYPTOKI_EXPORTS\r
+/* Specified that the function is an exported DLL entry point. */\r
+#define CK_EXPORT_SPEC __declspec(dllexport) \r
+#else\r
+#define CK_EXPORT_SPEC CK_IMPORT_SPEC \r
+#endif\r
+\r
+/* Ensures the calling convention for Win32 builds */\r
+#define CK_CALL_SPEC __cdecl\r
+\r
+#define CK_PTR *\r
+\r
+#define CK_DEFINE_FUNCTION(returnType, name) \\r
+  returnType CK_EXPORT_SPEC CK_CALL_SPEC name\r
+\r
+#define CK_DECLARE_FUNCTION(returnType, name) \\r
+  returnType CK_EXPORT_SPEC CK_CALL_SPEC name\r
+\r
+#define CK_DECLARE_FUNCTION_POINTER(returnType, name) \\r
+  returnType CK_IMPORT_SPEC (CK_CALL_SPEC CK_PTR name)\r
+\r
+#define CK_CALLBACK_FUNCTION(returnType, name) \\r
+  returnType (CK_CALL_SPEC CK_PTR name)\r
+\r
+#ifndef NULL_PTR\r
+#define NULL_PTR 0\r
+#endif\r
+\r
+#include "pkcs11.h"\r
+\r
+#pragma pack(pop, cryptoki)\r
+\r
+#endif /* ___CRYPTOKI_H_INC___ */\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/aes.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/aes.h
new file mode 100644 (file)
index 0000000..f846ce1
--- /dev/null
@@ -0,0 +1,127 @@
+/* crypto/aes/aes.h -*- mode:C; c-file-style: "eay" -*- */\r
+/* ====================================================================\r
+ * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_AES_H\r
+#define HEADER_AES_H\r
+\r
+#include <openssl/opensslconf.h>\r
+\r
+#ifdef OPENSSL_NO_AES\r
+#error AES is disabled.\r
+#endif\r
+\r
+#define AES_ENCRYPT    1\r
+#define AES_DECRYPT    0\r
+\r
+/* Because array size can't be a const in C, the following two are macros.\r
+   Both sizes are in bytes. */\r
+#define AES_MAXNR 14\r
+#define AES_BLOCK_SIZE 16\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* This should be a hidden type, but EVP requires that the size be known */\r
+struct aes_key_st {\r
+#ifdef AES_LONG\r
+    unsigned long rd_key[4 *(AES_MAXNR + 1)];\r
+#else\r
+    unsigned int rd_key[4 *(AES_MAXNR + 1)];\r
+#endif\r
+    int rounds;\r
+};\r
+typedef struct aes_key_st AES_KEY;\r
+\r
+const char *AES_options(void);\r
+\r
+int AES_set_encrypt_key(const unsigned char *userKey, const int bits,\r
+       AES_KEY *key);\r
+int AES_set_decrypt_key(const unsigned char *userKey, const int bits,\r
+       AES_KEY *key);\r
+\r
+void AES_encrypt(const unsigned char *in, unsigned char *out,\r
+       const AES_KEY *key);\r
+void AES_decrypt(const unsigned char *in, unsigned char *out,\r
+       const AES_KEY *key);\r
+\r
+void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,\r
+       const AES_KEY *key, const int enc);\r
+void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,\r
+       const unsigned long length, const AES_KEY *key,\r
+       unsigned char *ivec, const int enc);\r
+void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,\r
+       const unsigned long length, const AES_KEY *key,\r
+       unsigned char *ivec, int *num, const int enc);\r
+void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,\r
+       const unsigned long length, const AES_KEY *key,\r
+       unsigned char *ivec, int *num, const int enc);\r
+void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,\r
+       const unsigned long length, const AES_KEY *key,\r
+       unsigned char *ivec, int *num, const int enc);\r
+void AES_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,\r
+                           const int nbits,const AES_KEY *key,\r
+                           unsigned char *ivec,const int enc);\r
+void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,\r
+       const unsigned long length, const AES_KEY *key,\r
+       unsigned char *ivec, int *num);\r
+void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,\r
+       const unsigned long length, const AES_KEY *key,\r
+       unsigned char ivec[AES_BLOCK_SIZE],\r
+       unsigned char ecount_buf[AES_BLOCK_SIZE],\r
+       unsigned int *num);\r
+\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* !HEADER_AES_H */\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/asn1.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/asn1.h
new file mode 100644 (file)
index 0000000..1626a9e
--- /dev/null
@@ -0,0 +1,1230 @@
+/* crypto/asn1/asn1.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_ASN1_H\r
+#define HEADER_ASN1_H\r
+\r
+#include <time.h>\r
+#include <openssl/e_os2.h>\r
+#ifndef OPENSSL_NO_BIO\r
+#include <openssl/bio.h>\r
+#endif\r
+#include <openssl/stack.h>\r
+#include <openssl/safestack.h>\r
+\r
+#include <openssl/symhacks.h>\r
+\r
+#include <openssl/ossl_typ.h>\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#include <openssl/bn.h>\r
+#endif\r
+\r
+#ifdef OPENSSL_BUILD_SHLIBCRYPTO\r
+# undef OPENSSL_EXTERN\r
+# define OPENSSL_EXTERN OPENSSL_EXPORT\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define V_ASN1_UNIVERSAL               0x00\r
+#define        V_ASN1_APPLICATION              0x40\r
+#define V_ASN1_CONTEXT_SPECIFIC                0x80\r
+#define V_ASN1_PRIVATE                 0xc0\r
+\r
+#define V_ASN1_CONSTRUCTED             0x20\r
+#define V_ASN1_PRIMITIVE_TAG           0x1f\r
+#define V_ASN1_PRIMATIVE_TAG           0x1f\r
+\r
+#define V_ASN1_APP_CHOOSE              -2      /* let the recipient choose */\r
+#define V_ASN1_OTHER                   -3      /* used in ASN1_TYPE */\r
+#define V_ASN1_ANY                     -4      /* used in ASN1 template code */\r
+\r
+#define V_ASN1_NEG                     0x100   /* negative flag */\r
+\r
+#define V_ASN1_UNDEF                   -1\r
+#define V_ASN1_EOC                     0\r
+#define V_ASN1_BOOLEAN                 1       /**/\r
+#define V_ASN1_INTEGER                 2\r
+#define V_ASN1_NEG_INTEGER             (2 | V_ASN1_NEG)\r
+#define V_ASN1_BIT_STRING              3\r
+#define V_ASN1_OCTET_STRING            4\r
+#define V_ASN1_NULL                    5\r
+#define V_ASN1_OBJECT                  6\r
+#define V_ASN1_OBJECT_DESCRIPTOR       7\r
+#define V_ASN1_EXTERNAL                        8\r
+#define V_ASN1_REAL                    9\r
+#define V_ASN1_ENUMERATED              10\r
+#define V_ASN1_NEG_ENUMERATED          (10 | V_ASN1_NEG)\r
+#define V_ASN1_UTF8STRING              12\r
+#define V_ASN1_SEQUENCE                        16\r
+#define V_ASN1_SET                     17\r
+#define V_ASN1_NUMERICSTRING           18      /**/\r
+#define V_ASN1_PRINTABLESTRING         19\r
+#define V_ASN1_T61STRING               20\r
+#define V_ASN1_TELETEXSTRING           20      /* alias */\r
+#define V_ASN1_VIDEOTEXSTRING          21      /**/\r
+#define V_ASN1_IA5STRING               22\r
+#define V_ASN1_UTCTIME                 23\r
+#define V_ASN1_GENERALIZEDTIME         24      /**/\r
+#define V_ASN1_GRAPHICSTRING           25      /**/\r
+#define V_ASN1_ISO64STRING             26      /**/\r
+#define V_ASN1_VISIBLESTRING           26      /* alias */\r
+#define V_ASN1_GENERALSTRING           27      /**/\r
+#define V_ASN1_UNIVERSALSTRING         28      /**/\r
+#define V_ASN1_BMPSTRING               30\r
+\r
+/* For use with d2i_ASN1_type_bytes() */\r
+#define B_ASN1_NUMERICSTRING   0x0001\r
+#define B_ASN1_PRINTABLESTRING 0x0002\r
+#define B_ASN1_T61STRING       0x0004\r
+#define B_ASN1_TELETEXSTRING   0x0004\r
+#define B_ASN1_VIDEOTEXSTRING  0x0008\r
+#define B_ASN1_IA5STRING       0x0010\r
+#define B_ASN1_GRAPHICSTRING   0x0020\r
+#define B_ASN1_ISO64STRING     0x0040\r
+#define B_ASN1_VISIBLESTRING   0x0040\r
+#define B_ASN1_GENERALSTRING   0x0080\r
+#define B_ASN1_UNIVERSALSTRING 0x0100\r
+#define B_ASN1_OCTET_STRING    0x0200\r
+#define B_ASN1_BIT_STRING      0x0400\r
+#define B_ASN1_BMPSTRING       0x0800\r
+#define B_ASN1_UNKNOWN         0x1000\r
+#define B_ASN1_UTF8STRING      0x2000\r
+#define B_ASN1_UTCTIME         0x4000\r
+#define B_ASN1_GENERALIZEDTIME 0x8000\r
+\r
+/* For use with ASN1_mbstring_copy() */\r
+#define MBSTRING_FLAG          0x1000\r
+#define MBSTRING_UTF8          (MBSTRING_FLAG)\r
+#define MBSTRING_ASC           (MBSTRING_FLAG|1)\r
+#define MBSTRING_BMP           (MBSTRING_FLAG|2)\r
+#define MBSTRING_UNIV          (MBSTRING_FLAG|4)\r
+\r
+struct X509_algor_st;\r
+\r
+#define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */\r
+#define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */\r
+\r
+/* We MUST make sure that, except for constness, asn1_ctx_st and\r
+   asn1_const_ctx are exactly the same.  Fortunately, as soon as\r
+   the old ASN1 parsing macros are gone, we can throw this away\r
+   as well... */\r
+typedef struct asn1_ctx_st\r
+       {\r
+       unsigned char *p;/* work char pointer */\r
+       int eos;        /* end of sequence read for indefinite encoding */\r
+       int error;      /* error code to use when returning an error */\r
+       int inf;        /* constructed if 0x20, indefinite is 0x21 */\r
+       int tag;        /* tag from last 'get object' */\r
+       int xclass;     /* class from last 'get object' */\r
+       long slen;      /* length of last 'get object' */\r
+       unsigned char *max; /* largest value of p allowed */\r
+       unsigned char *q;/* temporary variable */\r
+       unsigned char **pp;/* variable */\r
+       int line;       /* used in error processing */\r
+       } ASN1_CTX;\r
+\r
+typedef struct asn1_const_ctx_st\r
+       {\r
+       const unsigned char *p;/* work char pointer */\r
+       int eos;        /* end of sequence read for indefinite encoding */\r
+       int error;      /* error code to use when returning an error */\r
+       int inf;        /* constructed if 0x20, indefinite is 0x21 */\r
+       int tag;        /* tag from last 'get object' */\r
+       int xclass;     /* class from last 'get object' */\r
+       long slen;      /* length of last 'get object' */\r
+       const unsigned char *max; /* largest value of p allowed */\r
+       const unsigned char *q;/* temporary variable */\r
+       const unsigned char **pp;/* variable */\r
+       int line;       /* used in error processing */\r
+       } ASN1_const_CTX;\r
+\r
+/* These are used internally in the ASN1_OBJECT to keep track of\r
+ * whether the names and data need to be free()ed */\r
+#define ASN1_OBJECT_FLAG_DYNAMIC        0x01   /* internal use */\r
+#define ASN1_OBJECT_FLAG_CRITICAL       0x02   /* critical x509v3 object id */\r
+#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04  /* internal use */\r
+#define ASN1_OBJECT_FLAG_DYNAMIC_DATA   0x08   /* internal use */\r
+typedef struct asn1_object_st\r
+       {\r
+       const char *sn,*ln;\r
+       int nid;\r
+       int length;\r
+       unsigned char *data;\r
+       int flags;      /* Should we free this one */\r
+       } ASN1_OBJECT;\r
+\r
+#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */\r
+/* This indicates that the ASN1_STRING is not a real value but just a place\r
+ * holder for the location where indefinite length constructed data should\r
+ * be inserted in the memory buffer \r
+ */\r
+#define ASN1_STRING_FLAG_NDEF 0x010 \r
+/* This is the base type that holds just about everything :-) */\r
+typedef struct asn1_string_st\r
+       {\r
+       int length;\r
+       int type;\r
+       unsigned char *data;\r
+       /* The value of the following field depends on the type being\r
+        * held.  It is mostly being used for BIT_STRING so if the\r
+        * input data has a non-zero 'unused bits' value, it will be\r
+        * handled correctly */\r
+       long flags;\r
+       } ASN1_STRING;\r
+\r
+/* ASN1_ENCODING structure: this is used to save the received\r
+ * encoding of an ASN1 type. This is useful to get round\r
+ * problems with invalid encodings which can break signatures.\r
+ */\r
+\r
+typedef struct ASN1_ENCODING_st\r
+       {\r
+       unsigned char *enc;     /* DER encoding */\r
+       long len;               /* Length of encoding */\r
+       int modified;            /* set to 1 if 'enc' is invalid */\r
+       } ASN1_ENCODING;\r
+\r
+/* Used with ASN1 LONG type: if a long is set to this it is omitted */\r
+#define ASN1_LONG_UNDEF        0x7fffffffL\r
+\r
+#define STABLE_FLAGS_MALLOC    0x01\r
+#define STABLE_NO_MASK         0x02\r
+#define DIRSTRING_TYPE \\r
+ (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)\r
+#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)\r
+\r
+typedef struct asn1_string_table_st {\r
+       int nid;\r
+       long minsize;\r
+       long maxsize;\r
+       unsigned long mask;\r
+       unsigned long flags;\r
+} ASN1_STRING_TABLE;\r
+\r
+DECLARE_STACK_OF(ASN1_STRING_TABLE)\r
+\r
+/* size limits: this stuff is taken straight from RFC2459 */\r
+\r
+#define ub_name                                32768\r
+#define ub_common_name                 64\r
+#define ub_locality_name               128\r
+#define ub_state_name                  128\r
+#define ub_organization_name           64\r
+#define ub_organization_unit_name      64\r
+#define ub_title                       64\r
+#define ub_email_address               128\r
+\r
+/* Declarations for template structures: for full definitions\r
+ * see asn1t.h\r
+ */\r
+typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE;\r
+typedef struct ASN1_ITEM_st ASN1_ITEM;\r
+typedef struct ASN1_TLC_st ASN1_TLC;\r
+/* This is just an opaque pointer */\r
+typedef struct ASN1_VALUE_st ASN1_VALUE;\r
+\r
+/* Declare ASN1 functions: the implement macro in in asn1t.h */\r
+\r
+#define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type)\r
+\r
+#define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \\r
+       DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, type)\r
+\r
+#define DECLARE_ASN1_FUNCTIONS_name(type, name) \\r
+       DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \\r
+       DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name)\r
+\r
+#define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \\r
+       DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \\r
+       DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)\r
+\r
+#define        DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \\r
+       type *d2i_##name(type **a, const unsigned char **in, long len); \\r
+       int i2d_##name(type *a, unsigned char **out); \\r
+       DECLARE_ASN1_ITEM(itname)\r
+\r
+#define        DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \\r
+       type *d2i_##name(type **a, const unsigned char **in, long len); \\r
+       int i2d_##name(const type *a, unsigned char **out); \\r
+       DECLARE_ASN1_ITEM(name)\r
+\r
+#define        DECLARE_ASN1_NDEF_FUNCTION(name) \\r
+       int i2d_##name##_NDEF(name *a, unsigned char **out);\r
+\r
+#define DECLARE_ASN1_FUNCTIONS_const(name) \\r
+       name *name##_new(void); \\r
+       void name##_free(name *a);\r
+\r
+#define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \\r
+       type *name##_new(void); \\r
+       void name##_free(type *a);\r
+\r
+#define D2I_OF(type) type *(*)(type **,const unsigned char **,long)\r
+#define I2D_OF(type) int (*)(type *,unsigned char **)\r
+#define I2D_OF_const(type) int (*)(const type *,unsigned char **)\r
+\r
+#define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long)\r
+#define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(type *,unsigned char **)\r
+#define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type)\r
+\r
+TYPEDEF_D2I2D_OF(void);\r
+\r
+/* The following macros and typedefs allow an ASN1_ITEM\r
+ * to be embedded in a structure and referenced. Since\r
+ * the ASN1_ITEM pointers need to be globally accessible\r
+ * (possibly from shared libraries) they may exist in\r
+ * different forms. On platforms that support it the\r
+ * ASN1_ITEM structure itself will be globally exported.\r
+ * Other platforms will export a function that returns\r
+ * an ASN1_ITEM pointer.\r
+ *\r
+ * To handle both cases transparently the macros below\r
+ * should be used instead of hard coding an ASN1_ITEM\r
+ * pointer in a structure.\r
+ *\r
+ * The structure will look like this:\r
+ *\r
+ * typedef struct SOMETHING_st {\r
+ *      ...\r
+ *      ASN1_ITEM_EXP *iptr;\r
+ *      ...\r
+ * } SOMETHING; \r
+ *\r
+ * It would be initialised as e.g.:\r
+ *\r
+ * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...};\r
+ *\r
+ * and the actual pointer extracted with:\r
+ *\r
+ * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr);\r
+ *\r
+ * Finally an ASN1_ITEM pointer can be extracted from an\r
+ * appropriate reference with: ASN1_ITEM_rptr(X509). This\r
+ * would be used when a function takes an ASN1_ITEM * argument.\r
+ *\r
+ */\r
+\r
+#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION\r
+\r
+/* ASN1_ITEM pointer exported type */\r
+typedef const ASN1_ITEM ASN1_ITEM_EXP;\r
+\r
+/* Macro to obtain ASN1_ITEM pointer from exported type */\r
+#define ASN1_ITEM_ptr(iptr) (iptr)\r
+\r
+/* Macro to include ASN1_ITEM pointer from base type */\r
+#define ASN1_ITEM_ref(iptr) (&(iptr##_it))\r
+\r
+#define ASN1_ITEM_rptr(ref) (&(ref##_it))\r
+\r
+#define DECLARE_ASN1_ITEM(name) \\r
+       OPENSSL_EXTERN const ASN1_ITEM name##_it;\r
+\r
+#else\r
+\r
+/* Platforms that can't easily handle shared global variables are declared\r
+ * as functions returning ASN1_ITEM pointers.\r
+ */\r
+\r
+/* ASN1_ITEM pointer exported type */\r
+typedef const ASN1_ITEM * ASN1_ITEM_EXP(void);\r
+\r
+/* Macro to obtain ASN1_ITEM pointer from exported type */\r
+#define ASN1_ITEM_ptr(iptr) (iptr())\r
+\r
+/* Macro to include ASN1_ITEM pointer from base type */\r
+#define ASN1_ITEM_ref(iptr) (iptr##_it)\r
+\r
+#define ASN1_ITEM_rptr(ref) (ref##_it())\r
+\r
+#define DECLARE_ASN1_ITEM(name) \\r
+       const ASN1_ITEM * name##_it(void);\r
+\r
+#endif\r
+\r
+/* Parameters used by ASN1_STRING_print_ex() */\r
+\r
+/* These determine which characters to escape:\r
+ * RFC2253 special characters, control characters and\r
+ * MSB set characters\r
+ */\r
+\r
+#define ASN1_STRFLGS_ESC_2253          1\r
+#define ASN1_STRFLGS_ESC_CTRL          2\r
+#define ASN1_STRFLGS_ESC_MSB           4\r
+\r
+\r
+/* This flag determines how we do escaping: normally\r
+ * RC2253 backslash only, set this to use backslash and\r
+ * quote.\r
+ */\r
+\r
+#define ASN1_STRFLGS_ESC_QUOTE         8\r
+\r
+\r
+/* These three flags are internal use only. */\r
+\r
+/* Character is a valid PrintableString character */\r
+#define CHARTYPE_PRINTABLESTRING       0x10\r
+/* Character needs escaping if it is the first character */\r
+#define CHARTYPE_FIRST_ESC_2253                0x20\r
+/* Character needs escaping if it is the last character */\r
+#define CHARTYPE_LAST_ESC_2253         0x40\r
+\r
+/* NB the internal flags are safely reused below by flags\r
+ * handled at the top level.\r
+ */\r
+\r
+/* If this is set we convert all character strings\r
+ * to UTF8 first \r
+ */\r
+\r
+#define ASN1_STRFLGS_UTF8_CONVERT      0x10\r
+\r
+/* If this is set we don't attempt to interpret content:\r
+ * just assume all strings are 1 byte per character. This\r
+ * will produce some pretty odd looking output!\r
+ */\r
+\r
+#define ASN1_STRFLGS_IGNORE_TYPE       0x20\r
+\r
+/* If this is set we include the string type in the output */\r
+#define ASN1_STRFLGS_SHOW_TYPE         0x40\r
+\r
+/* This determines which strings to display and which to\r
+ * 'dump' (hex dump of content octets or DER encoding). We can\r
+ * only dump non character strings or everything. If we\r
+ * don't dump 'unknown' they are interpreted as character\r
+ * strings with 1 octet per character and are subject to\r
+ * the usual escaping options.\r
+ */\r
+\r
+#define ASN1_STRFLGS_DUMP_ALL          0x80\r
+#define ASN1_STRFLGS_DUMP_UNKNOWN      0x100\r
+\r
+/* These determine what 'dumping' does, we can dump the\r
+ * content octets or the DER encoding: both use the\r
+ * RFC2253 #XXXXX notation.\r
+ */\r
+\r
+#define ASN1_STRFLGS_DUMP_DER          0x200\r
+\r
+/* All the string flags consistent with RFC2253,\r
+ * escaping control characters isn't essential in\r
+ * RFC2253 but it is advisable anyway.\r
+ */\r
+\r
+#define ASN1_STRFLGS_RFC2253   (ASN1_STRFLGS_ESC_2253 | \\r
+                               ASN1_STRFLGS_ESC_CTRL | \\r
+                               ASN1_STRFLGS_ESC_MSB | \\r
+                               ASN1_STRFLGS_UTF8_CONVERT | \\r
+                               ASN1_STRFLGS_DUMP_UNKNOWN | \\r
+                               ASN1_STRFLGS_DUMP_DER)\r
+\r
+DECLARE_STACK_OF(ASN1_INTEGER)\r
+DECLARE_ASN1_SET_OF(ASN1_INTEGER)\r
+\r
+DECLARE_STACK_OF(ASN1_GENERALSTRING)\r
+\r
+typedef struct asn1_type_st\r
+       {\r
+       int type;\r
+       union   {\r
+               char *ptr;\r
+               ASN1_BOOLEAN            boolean;\r
+               ASN1_STRING *           asn1_string;\r
+               ASN1_OBJECT *           object;\r
+               ASN1_INTEGER *          integer;\r
+               ASN1_ENUMERATED *       enumerated;\r
+               ASN1_BIT_STRING *       bit_string;\r
+               ASN1_OCTET_STRING *     octet_string;\r
+               ASN1_PRINTABLESTRING *  printablestring;\r
+               ASN1_T61STRING *        t61string;\r
+               ASN1_IA5STRING *        ia5string;\r
+               ASN1_GENERALSTRING *    generalstring;\r
+               ASN1_BMPSTRING *        bmpstring;\r
+               ASN1_UNIVERSALSTRING *  universalstring;\r
+               ASN1_UTCTIME *          utctime;\r
+               ASN1_GENERALIZEDTIME *  generalizedtime;\r
+               ASN1_VISIBLESTRING *    visiblestring;\r
+               ASN1_UTF8STRING *       utf8string;\r
+               /* set and sequence are left complete and still\r
+                * contain the set or sequence bytes */\r
+               ASN1_STRING *           set;\r
+               ASN1_STRING *           sequence;\r
+               } value;\r
+       } ASN1_TYPE;\r
+\r
+DECLARE_STACK_OF(ASN1_TYPE)\r
+DECLARE_ASN1_SET_OF(ASN1_TYPE)\r
+\r
+typedef struct asn1_method_st\r
+       {\r
+       i2d_of_void *i2d;\r
+       d2i_of_void *d2i;\r
+       void *(*create)(void);\r
+       void (*destroy)(void *);\r
+       } ASN1_METHOD;\r
+\r
+/* This is used when parsing some Netscape objects */\r
+typedef struct asn1_header_st\r
+       {\r
+       ASN1_OCTET_STRING *header;\r
+       void *data;\r
+       ASN1_METHOD *meth;\r
+       } ASN1_HEADER;\r
+\r
+/* This is used to contain a list of bit names */\r
+typedef struct BIT_STRING_BITNAME_st {\r
+       int bitnum;\r
+       const char *lname;\r
+       const char *sname;\r
+} BIT_STRING_BITNAME;\r
+\r
+\r
+#define M_ASN1_STRING_length(x)        ((x)->length)\r
+#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))\r
+#define M_ASN1_STRING_type(x)  ((x)->type)\r
+#define M_ASN1_STRING_data(x)  ((x)->data)\r
+\r
+/* Macros for string operations */\r
+#define M_ASN1_BIT_STRING_new()        (ASN1_BIT_STRING *)\\r
+               ASN1_STRING_type_new(V_ASN1_BIT_STRING)\r
+#define M_ASN1_BIT_STRING_free(a)      ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\\r
+               ASN1_STRING_dup((ASN1_STRING *)a)\r
+#define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\\r
+               (ASN1_STRING *)a,(ASN1_STRING *)b)\r
+#define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)\r
+\r
+#define M_ASN1_INTEGER_new()   (ASN1_INTEGER *)\\r
+               ASN1_STRING_type_new(V_ASN1_INTEGER)\r
+#define M_ASN1_INTEGER_free(a)         ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)\r
+#define M_ASN1_INTEGER_cmp(a,b)        ASN1_STRING_cmp(\\r
+               (ASN1_STRING *)a,(ASN1_STRING *)b)\r
+\r
+#define M_ASN1_ENUMERATED_new()        (ASN1_ENUMERATED *)\\r
+               ASN1_STRING_type_new(V_ASN1_ENUMERATED)\r
+#define M_ASN1_ENUMERATED_free(a)      ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)\r
+#define M_ASN1_ENUMERATED_cmp(a,b)     ASN1_STRING_cmp(\\r
+               (ASN1_STRING *)a,(ASN1_STRING *)b)\r
+\r
+#define M_ASN1_OCTET_STRING_new()      (ASN1_OCTET_STRING *)\\r
+               ASN1_STRING_type_new(V_ASN1_OCTET_STRING)\r
+#define M_ASN1_OCTET_STRING_free(a)    ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\\r
+               ASN1_STRING_dup((ASN1_STRING *)a)\r
+#define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\\r
+               (ASN1_STRING *)a,(ASN1_STRING *)b)\r
+#define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)\r
+#define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)\r
+#define M_i2d_ASN1_OCTET_STRING(a,pp) \\r
+               i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\\r
+               V_ASN1_UNIVERSAL)\r
+\r
+#define B_ASN1_TIME \\r
+                       B_ASN1_UTCTIME | \\r
+                       B_ASN1_GENERALIZEDTIME\r
+\r
+#define B_ASN1_PRINTABLE \\r
+                       B_ASN1_PRINTABLESTRING| \\r
+                       B_ASN1_T61STRING| \\r
+                       B_ASN1_IA5STRING| \\r
+                       B_ASN1_BIT_STRING| \\r
+                       B_ASN1_UNIVERSALSTRING|\\r
+                       B_ASN1_BMPSTRING|\\r
+                       B_ASN1_UTF8STRING|\\r
+                       B_ASN1_UNKNOWN\r
+\r
+#define B_ASN1_DIRECTORYSTRING \\r
+                       B_ASN1_PRINTABLESTRING| \\r
+                       B_ASN1_TELETEXSTRING|\\r
+                       B_ASN1_BMPSTRING|\\r
+                       B_ASN1_UNIVERSALSTRING|\\r
+                       B_ASN1_UTF8STRING\r
+\r
+#define B_ASN1_DISPLAYTEXT \\r
+                       B_ASN1_IA5STRING| \\r
+                       B_ASN1_VISIBLESTRING| \\r
+                       B_ASN1_BMPSTRING|\\r
+                       B_ASN1_UTF8STRING\r
+\r
+#define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)\r
+#define M_ASN1_PRINTABLE_free(a)       ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\\r
+               pp,a->type,V_ASN1_UNIVERSAL)\r
+#define M_d2i_ASN1_PRINTABLE(a,pp,l) \\r
+               d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \\r
+                       B_ASN1_PRINTABLE)\r
+\r
+#define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)\r
+#define M_DIRECTORYSTRING_free(a)      ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\\r
+                                               pp,a->type,V_ASN1_UNIVERSAL)\r
+#define M_d2i_DIRECTORYSTRING(a,pp,l) \\r
+               d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \\r
+                       B_ASN1_DIRECTORYSTRING)\r
+\r
+#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)\r
+#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\\r
+                                               pp,a->type,V_ASN1_UNIVERSAL)\r
+#define M_d2i_DISPLAYTEXT(a,pp,l) \\r
+               d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \\r
+                       B_ASN1_DISPLAYTEXT)\r
+\r
+#define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\\r
+               ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)\r
+#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \\r
+               i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\\r
+               V_ASN1_UNIVERSAL)\r
+#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \\r
+               (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\\r
+               ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)\r
+\r
+#define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\\r
+               ASN1_STRING_type_new(V_ASN1_T61STRING)\r
+#define M_ASN1_T61STRING_free(a)       ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_i2d_ASN1_T61STRING(a,pp) \\r
+               i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\\r
+               V_ASN1_UNIVERSAL)\r
+#define M_d2i_ASN1_T61STRING(a,pp,l) \\r
+               (ASN1_T61STRING *)d2i_ASN1_type_bytes\\r
+               ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)\r
+\r
+#define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\\r
+               ASN1_STRING_type_new(V_ASN1_IA5STRING)\r
+#define M_ASN1_IA5STRING_free(a)       ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_ASN1_IA5STRING_dup(a)        \\r
+                       (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a)\r
+#define M_i2d_ASN1_IA5STRING(a,pp) \\r
+               i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\\r
+                       V_ASN1_UNIVERSAL)\r
+#define M_d2i_ASN1_IA5STRING(a,pp,l) \\r
+               (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\\r
+                       B_ASN1_IA5STRING)\r
+\r
+#define M_ASN1_UTCTIME_new()   (ASN1_UTCTIME *)\\r
+               ASN1_STRING_type_new(V_ASN1_UTCTIME)\r
+#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)\r
+\r
+#define M_ASN1_GENERALIZEDTIME_new()   (ASN1_GENERALIZEDTIME *)\\r
+               ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)\r
+#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\\r
+       (ASN1_STRING *)a)\r
+\r
+#define M_ASN1_TIME_new()      (ASN1_TIME *)\\r
+               ASN1_STRING_type_new(V_ASN1_UTCTIME)\r
+#define M_ASN1_TIME_free(a)    ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)\r
+\r
+#define M_ASN1_GENERALSTRING_new()     (ASN1_GENERALSTRING *)\\r
+               ASN1_STRING_type_new(V_ASN1_GENERALSTRING)\r
+#define M_ASN1_GENERALSTRING_free(a)   ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_i2d_ASN1_GENERALSTRING(a,pp) \\r
+               i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\\r
+                       V_ASN1_UNIVERSAL)\r
+#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \\r
+               (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\\r
+               ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)\r
+\r
+#define M_ASN1_UNIVERSALSTRING_new()   (ASN1_UNIVERSALSTRING *)\\r
+               ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)\r
+#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \\r
+               i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\\r
+                       V_ASN1_UNIVERSAL)\r
+#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \\r
+               (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\\r
+               ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)\r
+\r
+#define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\\r
+               ASN1_STRING_type_new(V_ASN1_BMPSTRING)\r
+#define M_ASN1_BMPSTRING_free(a)       ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_i2d_ASN1_BMPSTRING(a,pp) \\r
+               i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\\r
+                       V_ASN1_UNIVERSAL)\r
+#define M_d2i_ASN1_BMPSTRING(a,pp,l) \\r
+               (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\\r
+               ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)\r
+\r
+#define M_ASN1_VISIBLESTRING_new()     (ASN1_VISIBLESTRING *)\\r
+               ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)\r
+#define M_ASN1_VISIBLESTRING_free(a)   ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_i2d_ASN1_VISIBLESTRING(a,pp) \\r
+               i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\\r
+                       V_ASN1_UNIVERSAL)\r
+#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \\r
+               (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\\r
+               ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)\r
+\r
+#define M_ASN1_UTF8STRING_new()        (ASN1_UTF8STRING *)\\r
+               ASN1_STRING_type_new(V_ASN1_UTF8STRING)\r
+#define M_ASN1_UTF8STRING_free(a)      ASN1_STRING_free((ASN1_STRING *)a)\r
+#define M_i2d_ASN1_UTF8STRING(a,pp) \\r
+               i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\\r
+                       V_ASN1_UNIVERSAL)\r
+#define M_d2i_ASN1_UTF8STRING(a,pp,l) \\r
+               (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\\r
+               ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)\r
+\r
+  /* for the is_set parameter to i2d_ASN1_SET */\r
+#define IS_SEQUENCE    0\r
+#define IS_SET         1\r
+\r
+DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)\r
+\r
+int ASN1_TYPE_get(ASN1_TYPE *a);\r
+void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);\r
+\r
+ASN1_OBJECT *  ASN1_OBJECT_new(void );\r
+void           ASN1_OBJECT_free(ASN1_OBJECT *a);\r
+int            i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);\r
+ASN1_OBJECT *  c2i_ASN1_OBJECT(ASN1_OBJECT **a,const unsigned char **pp,\r
+                       long length);\r
+ASN1_OBJECT *  d2i_ASN1_OBJECT(ASN1_OBJECT **a,const unsigned char **pp,\r
+                       long length);\r
+\r
+DECLARE_ASN1_ITEM(ASN1_OBJECT)\r
+\r
+DECLARE_STACK_OF(ASN1_OBJECT)\r
+DECLARE_ASN1_SET_OF(ASN1_OBJECT)\r
+\r
+ASN1_STRING *  ASN1_STRING_new(void);\r
+void           ASN1_STRING_free(ASN1_STRING *a);\r
+ASN1_STRING *  ASN1_STRING_dup(ASN1_STRING *a);\r
+ASN1_STRING *  ASN1_STRING_type_new(int type );\r
+int            ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);\r
+  /* Since this is used to store all sorts of things, via macros, for now, make\r
+     its data void * */\r
+int            ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);\r
+int ASN1_STRING_length(ASN1_STRING *x);\r
+void ASN1_STRING_length_set(ASN1_STRING *x, int n);\r
+int ASN1_STRING_type(ASN1_STRING *x);\r
+unsigned char * ASN1_STRING_data(ASN1_STRING *x);\r
+\r
+DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)\r
+int            i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);\r
+ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,const unsigned char **pp,\r
+                       long length);\r
+int            ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,\r
+                       int length );\r
+int            ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);\r
+int            ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,\r
+                               BIT_STRING_BITNAME *tbl, int indent);\r
+#endif\r
+int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl);\r
+int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,\r
+                               BIT_STRING_BITNAME *tbl);\r
+\r
+int            i2d_ASN1_BOOLEAN(int a,unsigned char **pp);\r
+int            d2i_ASN1_BOOLEAN(int *a,const unsigned char **pp,long length);\r
+\r
+DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)\r
+int            i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);\r
+ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,const unsigned char **pp,\r
+                       long length);\r
+ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,const unsigned char **pp,\r
+                       long length);\r
+ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x);\r
+int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y);\r
+\r
+DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)\r
+\r
+int ASN1_UTCTIME_check(ASN1_UTCTIME *a);\r
+ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);\r
+int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str);\r
+int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);\r
+#if 0\r
+time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);\r
+#endif\r
+\r
+int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);\r
+ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);\r
+int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str);\r
+\r
+DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)\r
+ASN1_OCTET_STRING *    ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a);\r
+int    ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b);\r
+int    ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data, int len);\r
+\r
+DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)\r
+DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)\r
+DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)\r
+DECLARE_ASN1_FUNCTIONS(ASN1_NULL)\r
+DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)\r
+\r
+int UTF8_getc(const unsigned char *str, int len, unsigned long *val);\r
+int UTF8_putc(unsigned char *str, int len, unsigned long value);\r
+\r
+DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)\r
+\r
+DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)\r
+DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)\r
+DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)\r
+DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING)\r
+DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING)\r
+DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING)\r
+DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)\r
+DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)\r
+DECLARE_ASN1_FUNCTIONS(ASN1_TIME)\r
+\r
+DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)\r
+\r
+ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);\r
+int ASN1_TIME_check(ASN1_TIME *t);\r
+ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);\r
+\r
+int i2d_ASN1_SET(STACK *a, unsigned char **pp,\r
+                i2d_of_void *i2d, int ex_tag, int ex_class, int is_set);\r
+STACK *        d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length,\r
+                    d2i_of_void *d2i, void (*free_func)(void *),\r
+                    int ex_tag, int ex_class);\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);\r
+int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);\r
+int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);\r
+int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size);\r
+int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);\r
+int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);\r
+int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);\r
+#endif\r
+int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);\r
+\r
+int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num);\r
+ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,\r
+       const char *sn, const char *ln);\r
+\r
+int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);\r
+long ASN1_INTEGER_get(ASN1_INTEGER *a);\r
+ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);\r
+BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);\r
+\r
+int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);\r
+long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);\r
+ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);\r
+BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);\r
+\r
+/* General */\r
+/* given a string, return the correct type, max is the maximum length */\r
+int ASN1_PRINTABLE_type(const unsigned char *s, int max);\r
+\r
+int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);\r
+ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,\r
+       long length, int Ptag, int Pclass);\r
+unsigned long ASN1_tag2bit(int tag);\r
+/* type is one or more of the B_ASN1_ values. */\r
+ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,const unsigned char **pp,\r
+               long length,int type);\r
+\r
+/* PARSING */\r
+int asn1_Finish(ASN1_CTX *c);\r
+int asn1_const_Finish(ASN1_const_CTX *c);\r
+\r
+/* SPECIALS */\r
+int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,\r
+       int *pclass, long omax);\r
+int ASN1_check_infinite_end(unsigned char **p,long len);\r
+int ASN1_const_check_infinite_end(const unsigned char **p,long len);\r
+void ASN1_put_object(unsigned char **pp, int constructed, int length,\r
+       int tag, int xclass);\r
+int ASN1_put_eoc(unsigned char **pp);\r
+int ASN1_object_size(int constructed, int length, int tag);\r
+\r
+/* Used to implement other functions */\r
+void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, char *x);\r
+#define ASN1_dup_of(type,i2d,d2i,x) \\r
+       ((type *(*)(I2D_OF(type),D2I_OF(type),type *))openssl_fcast(ASN1_dup))(i2d,d2i,x)\r
+#define ASN1_dup_of_const(type,i2d,d2i,x) \\r
+       ((type *(*)(I2D_OF_const(type),D2I_OF(type),type *))openssl_fcast(ASN1_dup))(i2d,d2i,x)\r
+\r
+void *ASN1_item_dup(const ASN1_ITEM *it, void *x);\r
+\r
+#ifndef OPENSSL_NO_FP_API\r
+void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x);\r
+#define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \\r
+       ((type *(*)(type *(*)(void),D2I_OF(type),FILE *,type **))openssl_fcast(ASN1_d2i_fp))(xnew,d2i,in,x)\r
+void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);\r
+int ASN1_i2d_fp(i2d_of_void *i2d,FILE *out,void *x);\r
+#define ASN1_i2d_fp_of(type,i2d,out,x) \\r
+       ((int (*)(I2D_OF(type),FILE *,type *))openssl_fcast(ASN1_i2d_fp))(i2d,out,x)\r
+#define ASN1_i2d_fp_of_const(type,i2d,out,x) \\r
+       ((int (*)(I2D_OF_const(type),FILE *,type *))openssl_fcast(ASN1_i2d_fp))(i2d,out,x)\r
+int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x);\r
+int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);\r
+#endif\r
+\r
+int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+void *ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x);\r
+#define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \\r
+       ((type *(*)(type *(*)(void),D2I_OF(type),BIO *,type **))openssl_fcast(ASN1_d2i_bio))(xnew,d2i,in,x)\r
+void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x);\r
+int ASN1_i2d_bio(i2d_of_void *i2d,BIO *out, unsigned char *x);\r
+#define ASN1_i2d_bio_of(type,i2d,out,x) \\r
+       ((int (*)(I2D_OF(type),BIO *,type *))openssl_fcast(ASN1_i2d_bio))(i2d,out,x)\r
+#define ASN1_i2d_bio_of_const(type,i2d,out,x) \\r
+       ((int (*)(I2D_OF_const(type),BIO *,const type *))openssl_fcast(ASN1_i2d_bio))(i2d,out,x)\r
+int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x);\r
+int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);\r
+int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);\r
+int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);\r
+int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);\r
+int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);\r
+int ASN1_parse(BIO *bp,const unsigned char *pp,long len,int indent);\r
+int ASN1_parse_dump(BIO *bp,const unsigned char *pp,long len,int indent,int dump);\r
+#endif\r
+const char *ASN1_tag2str(int tag);\r
+\r
+/* Used to load and write netscape format cert/key */\r
+int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);\r
+ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,const unsigned char **pp, long length);\r
+ASN1_HEADER *ASN1_HEADER_new(void );\r
+void ASN1_HEADER_free(ASN1_HEADER *a);\r
+\r
+int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);\r
+\r
+/* Not used that much at this point, except for the first two */\r
+ASN1_METHOD *X509_asn1_meth(void);\r
+ASN1_METHOD *RSAPrivateKey_asn1_meth(void);\r
+ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);\r
+ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);\r
+\r
+int ASN1_TYPE_set_octetstring(ASN1_TYPE *a,\r
+       unsigned char *data, int len);\r
+int ASN1_TYPE_get_octetstring(ASN1_TYPE *a,\r
+       unsigned char *data, int max_len);\r
+int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,\r
+       unsigned char *data, int len);\r
+int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,\r
+       unsigned char *data, int max_len);\r
+\r
+STACK *ASN1_seq_unpack(const unsigned char *buf, int len,\r
+                      d2i_of_void *d2i, void (*free_func)(void *));\r
+unsigned char *ASN1_seq_pack(STACK *safes, i2d_of_void *i2d,\r
+                            unsigned char **buf, int *len );\r
+void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i);\r
+void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it);\r
+ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d,\r
+                             ASN1_OCTET_STRING **oct);\r
+#define ASN1_pack_string_of(type,obj,i2d,oct) \\r
+       ((ASN1_STRING *(*)(type *,I2D_OF(type),ASN1_OCTET_STRING **))openssl_fcast(ASN1_pack_string))(obj,i2d,oct)\r
+ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct);\r
+\r
+void ASN1_STRING_set_default_mask(unsigned long mask);\r
+int ASN1_STRING_set_default_mask_asc(char *p);\r
+unsigned long ASN1_STRING_get_default_mask(void);\r
+int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,\r
+                                       int inform, unsigned long mask);\r
+int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,\r
+                                       int inform, unsigned long mask, \r
+                                       long minsize, long maxsize);\r
+\r
+ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, \r
+               const unsigned char *in, int inlen, int inform, int nid);\r
+ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);\r
+int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);\r
+void ASN1_STRING_TABLE_cleanup(void);\r
+\r
+/* ASN1 template functions */\r
+\r
+/* Old API compatible functions */\r
+ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);\r
+void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);\r
+ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it);\r
+int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);\r
+int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);\r
+\r
+void ASN1_add_oid_module(void);\r
+\r
+ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf);\r
+ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf);\r
+       \r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_ASN1_strings(void);\r
+\r
+/* Error codes for the ASN1 functions. */\r
+\r
+/* Function codes. */\r
+#define ASN1_F_A2D_ASN1_OBJECT                          100\r
+#define ASN1_F_A2I_ASN1_ENUMERATED                      101\r
+#define ASN1_F_A2I_ASN1_INTEGER                                 102\r
+#define ASN1_F_A2I_ASN1_STRING                          103\r
+#define ASN1_F_APPEND_EXP                               176\r
+#define ASN1_F_ASN1_BIT_STRING_SET_BIT                  183\r
+#define ASN1_F_ASN1_CB                                  177\r
+#define ASN1_F_ASN1_CHECK_TLEN                          104\r
+#define ASN1_F_ASN1_COLLATE_PRIMITIVE                   105\r
+#define ASN1_F_ASN1_COLLECT                             106\r
+#define ASN1_F_ASN1_D2I_EX_PRIMITIVE                    108\r
+#define ASN1_F_ASN1_D2I_FP                              109\r
+#define ASN1_F_ASN1_D2I_READ_BIO                        107\r
+#define ASN1_F_ASN1_DIGEST                              184\r
+#define ASN1_F_ASN1_DO_ADB                              110\r
+#define ASN1_F_ASN1_DUP                                         111\r
+#define ASN1_F_ASN1_ENUMERATED_SET                      112\r
+#define ASN1_F_ASN1_ENUMERATED_TO_BN                    113\r
+#define ASN1_F_ASN1_EX_C2I                              204\r
+#define ASN1_F_ASN1_FIND_END                            190\r
+#define ASN1_F_ASN1_GENERALIZEDTIME_SET                         185\r
+#define ASN1_F_ASN1_GENERATE_V3                                 178\r
+#define ASN1_F_ASN1_GET_OBJECT                          114\r
+#define ASN1_F_ASN1_HEADER_NEW                          115\r
+#define ASN1_F_ASN1_I2D_BIO                             116\r
+#define ASN1_F_ASN1_I2D_FP                              117\r
+#define ASN1_F_ASN1_INTEGER_SET                                 118\r
+#define ASN1_F_ASN1_INTEGER_TO_BN                       119\r
+#define ASN1_F_ASN1_ITEM_D2I_FP                                 190\r
+#define ASN1_F_ASN1_ITEM_DUP                            191\r
+#define ASN1_F_ASN1_ITEM_EX_COMBINE_NEW                         121\r
+#define ASN1_F_ASN1_ITEM_EX_D2I                                 120\r
+#define ASN1_F_ASN1_ITEM_I2D_BIO                        192\r
+#define ASN1_F_ASN1_ITEM_I2D_FP                                 193\r
+#define ASN1_F_ASN1_ITEM_PACK                           198\r
+#define ASN1_F_ASN1_ITEM_SIGN                           195\r
+#define ASN1_F_ASN1_ITEM_UNPACK                                 199\r
+#define ASN1_F_ASN1_ITEM_VERIFY                                 197\r
+#define ASN1_F_ASN1_MBSTRING_NCOPY                      122\r
+#define ASN1_F_ASN1_OBJECT_NEW                          123\r
+#define ASN1_F_ASN1_PACK_STRING                                 124\r
+#define ASN1_F_ASN1_PKCS5_PBE_SET                       125\r
+#define ASN1_F_ASN1_SEQ_PACK                            126\r
+#define ASN1_F_ASN1_SEQ_UNPACK                          127\r
+#define ASN1_F_ASN1_SIGN                                128\r
+#define ASN1_F_ASN1_STR2TYPE                            179\r
+#define ASN1_F_ASN1_STRING_SET                          186\r
+#define ASN1_F_ASN1_STRING_TABLE_ADD                    129\r
+#define ASN1_F_ASN1_STRING_TYPE_NEW                     130\r
+#define ASN1_F_ASN1_TEMPLATE_EX_D2I                     132\r
+#define ASN1_F_ASN1_TEMPLATE_NEW                        133\r
+#define ASN1_F_ASN1_TEMPLATE_NOEXP_D2I                  131\r
+#define ASN1_F_ASN1_TIME_SET                            175\r
+#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING            134\r
+#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING                135\r
+#define ASN1_F_ASN1_UNPACK_STRING                       136\r
+#define ASN1_F_ASN1_UTCTIME_SET                                 187\r
+#define ASN1_F_ASN1_VERIFY                              137\r
+#define ASN1_F_BITSTR_CB                                180\r
+#define ASN1_F_BN_TO_ASN1_ENUMERATED                    138\r
+#define ASN1_F_BN_TO_ASN1_INTEGER                       139\r
+#define ASN1_F_C2I_ASN1_BIT_STRING                      189\r
+#define ASN1_F_C2I_ASN1_INTEGER                                 194\r
+#define ASN1_F_C2I_ASN1_OBJECT                          196\r
+#define ASN1_F_COLLECT_DATA                             140\r
+#define ASN1_F_D2I_ASN1_BIT_STRING                      141\r
+#define ASN1_F_D2I_ASN1_BOOLEAN                                 142\r
+#define ASN1_F_D2I_ASN1_BYTES                           143\r
+#define ASN1_F_D2I_ASN1_GENERALIZEDTIME                         144\r
+#define ASN1_F_D2I_ASN1_HEADER                          145\r
+#define ASN1_F_D2I_ASN1_INTEGER                                 146\r
+#define ASN1_F_D2I_ASN1_OBJECT                          147\r
+#define ASN1_F_D2I_ASN1_SET                             148\r
+#define ASN1_F_D2I_ASN1_TYPE_BYTES                      149\r
+#define ASN1_F_D2I_ASN1_UINTEGER                        150\r
+#define ASN1_F_D2I_ASN1_UTCTIME                                 151\r
+#define ASN1_F_D2I_NETSCAPE_RSA                                 152\r
+#define ASN1_F_D2I_NETSCAPE_RSA_2                       153\r
+#define ASN1_F_D2I_PRIVATEKEY                           154\r
+#define ASN1_F_D2I_PUBLICKEY                            155\r
+#define ASN1_F_D2I_RSA_NET                              200\r
+#define ASN1_F_D2I_RSA_NET_2                            201\r
+#define ASN1_F_D2I_X509                                         156\r
+#define ASN1_F_D2I_X509_CINF                            157\r
+#define ASN1_F_D2I_X509_PKEY                            159\r
+#define ASN1_F_I2D_ASN1_SET                             188\r
+#define ASN1_F_I2D_ASN1_TIME                            160\r
+#define ASN1_F_I2D_DSA_PUBKEY                           161\r
+#define ASN1_F_I2D_EC_PUBKEY                            181\r
+#define ASN1_F_I2D_PRIVATEKEY                           163\r
+#define ASN1_F_I2D_PUBLICKEY                            164\r
+#define ASN1_F_I2D_RSA_NET                              162\r
+#define ASN1_F_I2D_RSA_PUBKEY                           165\r
+#define ASN1_F_LONG_C2I                                         166\r
+#define ASN1_F_OID_MODULE_INIT                          174\r
+#define ASN1_F_PARSE_TAGGING                            182\r
+#define ASN1_F_PKCS5_PBE2_SET                           167\r
+#define ASN1_F_PKCS5_PBE_SET                            202\r
+#define ASN1_F_X509_CINF_NEW                            168\r
+#define ASN1_F_X509_CRL_ADD0_REVOKED                    169\r
+#define ASN1_F_X509_INFO_NEW                            170\r
+#define ASN1_F_X509_NAME_ENCODE                                 203\r
+#define ASN1_F_X509_NAME_EX_D2I                                 158\r
+#define ASN1_F_X509_NAME_EX_NEW                                 171\r
+#define ASN1_F_X509_NEW                                         172\r
+#define ASN1_F_X509_PKEY_NEW                            173\r
+\r
+/* Reason codes. */\r
+#define ASN1_R_ADDING_OBJECT                            171\r
+#define ASN1_R_AUX_ERROR                                100\r
+#define ASN1_R_BAD_CLASS                                101\r
+#define ASN1_R_BAD_OBJECT_HEADER                        102\r
+#define ASN1_R_BAD_PASSWORD_READ                        103\r
+#define ASN1_R_BAD_TAG                                  104\r
+#define ASN1_R_BN_LIB                                   105\r
+#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH                  106\r
+#define ASN1_R_BUFFER_TOO_SMALL                                 107\r
+#define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER          108\r
+#define ASN1_R_DATA_IS_WRONG                            109\r
+#define ASN1_R_DECODE_ERROR                             110\r
+#define ASN1_R_DECODING_ERROR                           111\r
+#define ASN1_R_DEPTH_EXCEEDED                           174\r
+#define ASN1_R_ENCODE_ERROR                             112\r
+#define ASN1_R_ERROR_GETTING_TIME                       173\r
+#define ASN1_R_ERROR_LOADING_SECTION                    172\r
+#define ASN1_R_ERROR_PARSING_SET_ELEMENT                113\r
+#define ASN1_R_ERROR_SETTING_CIPHER_PARAMS              114\r
+#define ASN1_R_EXPECTING_AN_INTEGER                     115\r
+#define ASN1_R_EXPECTING_AN_OBJECT                      116\r
+#define ASN1_R_EXPECTING_A_BOOLEAN                      117\r
+#define ASN1_R_EXPECTING_A_TIME                                 118\r
+#define ASN1_R_EXPLICIT_LENGTH_MISMATCH                         119\r
+#define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED             120\r
+#define ASN1_R_FIELD_MISSING                            121\r
+#define ASN1_R_FIRST_NUM_TOO_LARGE                      122\r
+#define ASN1_R_HEADER_TOO_LONG                          123\r
+#define ASN1_R_ILLEGAL_BITSTRING_FORMAT                         175\r
+#define ASN1_R_ILLEGAL_BOOLEAN                          176\r
+#define ASN1_R_ILLEGAL_CHARACTERS                       124\r
+#define ASN1_R_ILLEGAL_FORMAT                           177\r
+#define ASN1_R_ILLEGAL_HEX                              178\r
+#define ASN1_R_ILLEGAL_IMPLICIT_TAG                     179\r
+#define ASN1_R_ILLEGAL_INTEGER                          180\r
+#define ASN1_R_ILLEGAL_NESTED_TAGGING                   181\r
+#define ASN1_R_ILLEGAL_NULL                             125\r
+#define ASN1_R_ILLEGAL_NULL_VALUE                       182\r
+#define ASN1_R_ILLEGAL_OBJECT                           183\r
+#define ASN1_R_ILLEGAL_OPTIONAL_ANY                     126\r
+#define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE                 170\r
+#define ASN1_R_ILLEGAL_TAGGED_ANY                       127\r
+#define ASN1_R_ILLEGAL_TIME_VALUE                       184\r
+#define ASN1_R_INTEGER_NOT_ASCII_FORMAT                         185\r
+#define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG               128\r
+#define ASN1_R_INVALID_BMPSTRING_LENGTH                         129\r
+#define ASN1_R_INVALID_DIGIT                            130\r
+#define ASN1_R_INVALID_MODIFIER                                 186\r
+#define ASN1_R_INVALID_NUMBER                           187\r
+#define ASN1_R_INVALID_SEPARATOR                        131\r
+#define ASN1_R_INVALID_TIME_FORMAT                      132\r
+#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH           133\r
+#define ASN1_R_INVALID_UTF8STRING                       134\r
+#define ASN1_R_IV_TOO_LARGE                             135\r
+#define ASN1_R_LENGTH_ERROR                             136\r
+#define ASN1_R_LIST_ERROR                               188\r
+#define ASN1_R_MISSING_EOC                              137\r
+#define ASN1_R_MISSING_SECOND_NUMBER                    138\r
+#define ASN1_R_MISSING_VALUE                            189\r
+#define ASN1_R_MSTRING_NOT_UNIVERSAL                    139\r
+#define ASN1_R_MSTRING_WRONG_TAG                        140\r
+#define ASN1_R_NESTED_ASN1_STRING                       197\r
+#define ASN1_R_NON_HEX_CHARACTERS                       141\r
+#define ASN1_R_NOT_ASCII_FORMAT                                 190\r
+#define ASN1_R_NOT_ENOUGH_DATA                          142\r
+#define ASN1_R_NO_MATCHING_CHOICE_TYPE                  143\r
+#define ASN1_R_NULL_IS_WRONG_LENGTH                     144\r
+#define ASN1_R_OBJECT_NOT_ASCII_FORMAT                  191\r
+#define ASN1_R_ODD_NUMBER_OF_CHARS                      145\r
+#define ASN1_R_PRIVATE_KEY_HEADER_MISSING               146\r
+#define ASN1_R_SECOND_NUMBER_TOO_LARGE                  147\r
+#define ASN1_R_SEQUENCE_LENGTH_MISMATCH                         148\r
+#define ASN1_R_SEQUENCE_NOT_CONSTRUCTED                         149\r
+#define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG             192\r
+#define ASN1_R_SHORT_LINE                               150\r
+#define ASN1_R_STRING_TOO_LONG                          151\r
+#define ASN1_R_STRING_TOO_SHORT                                 152\r
+#define ASN1_R_TAG_VALUE_TOO_HIGH                       153\r
+#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154\r
+#define ASN1_R_TIME_NOT_ASCII_FORMAT                    193\r
+#define ASN1_R_TOO_LONG                                         155\r
+#define ASN1_R_TYPE_NOT_CONSTRUCTED                     156\r
+#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY                         157\r
+#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY                 158\r
+#define ASN1_R_UNEXPECTED_EOC                           159\r
+#define ASN1_R_UNKNOWN_FORMAT                           160\r
+#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM                 161\r
+#define ASN1_R_UNKNOWN_OBJECT_TYPE                      162\r
+#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE                  163\r
+#define ASN1_R_UNKNOWN_TAG                              194\r
+#define ASN1_R_UNKOWN_FORMAT                            195\r
+#define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE          164\r
+#define ASN1_R_UNSUPPORTED_CIPHER                       165\r
+#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM                 166\r
+#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE              167\r
+#define ASN1_R_UNSUPPORTED_TYPE                                 196\r
+#define ASN1_R_WRONG_TAG                                168\r
+#define ASN1_R_WRONG_TYPE                               169\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/asn1_mac.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/asn1_mac.h
new file mode 100644 (file)
index 0000000..1ac54cf
--- /dev/null
@@ -0,0 +1,571 @@
+/* crypto/asn1/asn1_mac.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_ASN1_MAC_H\r
+#define HEADER_ASN1_MAC_H\r
+\r
+#include <openssl/asn1.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifndef ASN1_MAC_ERR_LIB\r
+#define ASN1_MAC_ERR_LIB       ERR_LIB_ASN1\r
+#endif \r
+\r
+#define ASN1_MAC_H_err(f,r,line) \\r
+       ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line))\r
+\r
+#define M_ASN1_D2I_vars(a,type,func) \\r
+       ASN1_const_CTX c; \\r
+       type ret=NULL; \\r
+       \\r
+       c.pp=(const unsigned char **)pp; \\r
+       c.q= *(const unsigned char **)pp; \\r
+       c.error=ERR_R_NESTED_ASN1_ERROR; \\r
+       if ((a == NULL) || ((*a) == NULL)) \\r
+               { if ((ret=(type)func()) == NULL) \\r
+                       { c.line=__LINE__; goto err; } } \\r
+       else    ret=(*a);\r
+\r
+#define M_ASN1_D2I_Init() \\r
+       c.p= *(const unsigned char **)pp; \\r
+       c.max=(length == 0)?0:(c.p+length);\r
+\r
+#define M_ASN1_D2I_Finish_2(a) \\r
+       if (!asn1_const_Finish(&c)) \\r
+               { c.line=__LINE__; goto err; } \\r
+       *(const unsigned char **)pp=c.p; \\r
+       if (a != NULL) (*a)=ret; \\r
+       return(ret);\r
+\r
+#define M_ASN1_D2I_Finish(a,func,e) \\r
+       M_ASN1_D2I_Finish_2(a); \\r
+err:\\r
+       ASN1_MAC_H_err((e),c.error,c.line); \\r
+       asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \\r
+       if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \\r
+       return(NULL)\r
+\r
+#define M_ASN1_D2I_start_sequence() \\r
+       if (!asn1_GetSequence(&c,&length)) \\r
+               { c.line=__LINE__; goto err; }\r
+/* Begin reading ASN1 without a surrounding sequence */\r
+#define M_ASN1_D2I_begin() \\r
+       c.slen = length;\r
+\r
+/* End reading ASN1 with no check on length */\r
+#define M_ASN1_D2I_Finish_nolen(a, func, e) \\r
+       *pp=c.p; \\r
+       if (a != NULL) (*a)=ret; \\r
+       return(ret); \\r
+err:\\r
+       ASN1_MAC_H_err((e),c.error,c.line); \\r
+       asn1_add_error(*pp,(int)(c.q- *pp)); \\r
+       if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \\r
+       return(NULL)\r
+\r
+#define M_ASN1_D2I_end_sequence() \\r
+       (((c.inf&1) == 0)?(c.slen <= 0): \\r
+               (c.eos=ASN1_const_check_infinite_end(&c.p,c.slen)))\r
+\r
+/* Don't use this with d2i_ASN1_BOOLEAN() */\r
+#define M_ASN1_D2I_get(b, func) \\r
+       c.q=c.p; \\r
+       if (func(&(b),&c.p,c.slen) == NULL) \\r
+               {c.line=__LINE__; goto err; } \\r
+       c.slen-=(c.p-c.q);\r
+\r
+/* Don't use this with d2i_ASN1_BOOLEAN() */\r
+#define M_ASN1_D2I_get_x(type,b,func) \\r
+       c.q=c.p; \\r
+       if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \\r
+               {c.line=__LINE__; goto err; } \\r
+       c.slen-=(c.p-c.q);\r
+\r
+/* use this instead () */\r
+#define M_ASN1_D2I_get_int(b,func) \\r
+       c.q=c.p; \\r
+       if (func(&(b),&c.p,c.slen) < 0) \\r
+               {c.line=__LINE__; goto err; } \\r
+       c.slen-=(c.p-c.q);\r
+\r
+#define M_ASN1_D2I_get_opt(b,func,type) \\r
+       if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \\r
+               == (V_ASN1_UNIVERSAL|(type)))) \\r
+               { \\r
+               M_ASN1_D2I_get(b,func); \\r
+               }\r
+\r
+#define M_ASN1_D2I_get_imp(b,func, type) \\r
+       M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \\r
+       c.q=c.p; \\r
+       if (func(&(b),&c.p,c.slen) == NULL) \\r
+               {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \\r
+       c.slen-=(c.p-c.q);\\r
+       M_ASN1_next_prev=_tmp;\r
+\r
+#define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \\r
+       if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \\r
+               (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \\r
+               { \\r
+               unsigned char _tmp = M_ASN1_next; \\r
+               M_ASN1_D2I_get_imp(b,func, type);\\r
+               }\r
+\r
+#define M_ASN1_D2I_get_set(r,func,free_func) \\r
+               M_ASN1_D2I_get_imp_set(r,func,free_func, \\r
+                       V_ASN1_SET,V_ASN1_UNIVERSAL);\r
+\r
+#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \\r
+               M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \\r
+                       V_ASN1_SET,V_ASN1_UNIVERSAL);\r
+\r
+#define M_ASN1_D2I_get_set_opt(r,func,free_func) \\r
+       if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \\r
+               V_ASN1_CONSTRUCTED|V_ASN1_SET)))\\r
+               { M_ASN1_D2I_get_set(r,func,free_func); }\r
+\r
+#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \\r
+       if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \\r
+               V_ASN1_CONSTRUCTED|V_ASN1_SET)))\\r
+               { M_ASN1_D2I_get_set_type(type,r,func,free_func); }\r
+\r
+#define M_ASN1_I2D_len_SET_opt(a,f) \\r
+       if ((a != NULL) && (sk_num(a) != 0)) \\r
+               M_ASN1_I2D_len_SET(a,f);\r
+\r
+#define M_ASN1_I2D_put_SET_opt(a,f) \\r
+       if ((a != NULL) && (sk_num(a) != 0)) \\r
+               M_ASN1_I2D_put_SET(a,f);\r
+\r
+#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \\r
+       if ((a != NULL) && (sk_num(a) != 0)) \\r
+               M_ASN1_I2D_put_SEQUENCE(a,f);\r
+\r
+#define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \\r
+       if ((a != NULL) && (sk_##type##_num(a) != 0)) \\r
+               M_ASN1_I2D_put_SEQUENCE_type(type,a,f);\r
+\r
+#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \\r
+       if ((c.slen != 0) && \\r
+               (M_ASN1_next == \\r
+               (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\\r
+               { \\r
+               M_ASN1_D2I_get_imp_set(b,func,free_func,\\r
+                       tag,V_ASN1_CONTEXT_SPECIFIC); \\r
+               }\r
+\r
+#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \\r
+       if ((c.slen != 0) && \\r
+               (M_ASN1_next == \\r
+               (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\\r
+               { \\r
+               M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\\r
+                       tag,V_ASN1_CONTEXT_SPECIFIC); \\r
+               }\r
+\r
+#define M_ASN1_D2I_get_seq(r,func,free_func) \\r
+               M_ASN1_D2I_get_imp_set(r,func,free_func,\\r
+                       V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);\r
+\r
+#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \\r
+               M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\\r
+                                           V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)\r
+\r
+#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \\r
+       if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \\r
+               V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\\r
+               { M_ASN1_D2I_get_seq(r,func,free_func); }\r
+\r
+#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \\r
+       if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \\r
+               V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\\r
+               { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }\r
+\r
+#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \\r
+               M_ASN1_D2I_get_imp_set(r,func,free_func,\\r
+                       x,V_ASN1_CONTEXT_SPECIFIC);\r
+\r
+#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \\r
+               M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\\r
+                       x,V_ASN1_CONTEXT_SPECIFIC);\r
+\r
+#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \\r
+       c.q=c.p; \\r
+       if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\\r
+               (void (*)())free_func,a,b) == NULL) \\r
+               { c.line=__LINE__; goto err; } \\r
+       c.slen-=(c.p-c.q);\r
+\r
+#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \\r
+       c.q=c.p; \\r
+       if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\\r
+                                  free_func,a,b) == NULL) \\r
+               { c.line=__LINE__; goto err; } \\r
+       c.slen-=(c.p-c.q);\r
+\r
+#define M_ASN1_D2I_get_set_strings(r,func,a,b) \\r
+       c.q=c.p; \\r
+       if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \\r
+               { c.line=__LINE__; goto err; } \\r
+       c.slen-=(c.p-c.q);\r
+\r
+#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \\r
+       if ((c.slen != 0L) && (M_ASN1_next == \\r
+               (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \\r
+               { \\r
+               int Tinf,Ttag,Tclass; \\r
+               long Tlen; \\r
+               \\r
+               c.q=c.p; \\r
+               Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \\r
+               if (Tinf & 0x80) \\r
+                       { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \\r
+                       c.line=__LINE__; goto err; } \\r
+               if (Tinf == (V_ASN1_CONSTRUCTED+1)) \\r
+                                       Tlen = c.slen - (c.p - c.q) - 2; \\r
+               if (func(&(r),&c.p,Tlen) == NULL) \\r
+                       { c.line=__LINE__; goto err; } \\r
+               if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \\r
+                       Tlen = c.slen - (c.p - c.q); \\r
+                       if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \\r
+                               { c.error=ERR_R_MISSING_ASN1_EOS; \\r
+                               c.line=__LINE__; goto err; } \\r
+               }\\r
+               c.slen-=(c.p-c.q); \\r
+               }\r
+\r
+#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \\r
+       if ((c.slen != 0) && (M_ASN1_next == \\r
+               (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \\r
+               { \\r
+               int Tinf,Ttag,Tclass; \\r
+               long Tlen; \\r
+               \\r
+               c.q=c.p; \\r
+               Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \\r
+               if (Tinf & 0x80) \\r
+                       { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \\r
+                       c.line=__LINE__; goto err; } \\r
+               if (Tinf == (V_ASN1_CONSTRUCTED+1)) \\r
+                                       Tlen = c.slen - (c.p - c.q) - 2; \\r
+               if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \\r
+                       (void (*)())free_func, \\r
+                       b,V_ASN1_UNIVERSAL) == NULL) \\r
+                       { c.line=__LINE__; goto err; } \\r
+               if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \\r
+                       Tlen = c.slen - (c.p - c.q); \\r
+                       if(!ASN1_check_infinite_end(&c.p, Tlen)) \\r
+                               { c.error=ERR_R_MISSING_ASN1_EOS; \\r
+                               c.line=__LINE__; goto err; } \\r
+               }\\r
+               c.slen-=(c.p-c.q); \\r
+               }\r
+\r
+#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \\r
+       if ((c.slen != 0) && (M_ASN1_next == \\r
+               (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \\r
+               { \\r
+               int Tinf,Ttag,Tclass; \\r
+               long Tlen; \\r
+               \\r
+               c.q=c.p; \\r
+               Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \\r
+               if (Tinf & 0x80) \\r
+                       { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \\r
+                       c.line=__LINE__; goto err; } \\r
+               if (Tinf == (V_ASN1_CONSTRUCTED+1)) \\r
+                                       Tlen = c.slen - (c.p - c.q) - 2; \\r
+               if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \\r
+                       free_func,b,V_ASN1_UNIVERSAL) == NULL) \\r
+                       { c.line=__LINE__; goto err; } \\r
+               if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \\r
+                       Tlen = c.slen - (c.p - c.q); \\r
+                       if(!ASN1_check_infinite_end(&c.p, Tlen)) \\r
+                               { c.error=ERR_R_MISSING_ASN1_EOS; \\r
+                               c.line=__LINE__; goto err; } \\r
+               }\\r
+               c.slen-=(c.p-c.q); \\r
+               }\r
+\r
+/* New macros */\r
+#define M_ASN1_New_Malloc(ret,type) \\r
+       if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \\r
+               { c.line=__LINE__; goto err2; }\r
+\r
+#define M_ASN1_New(arg,func) \\r
+       if (((arg)=func()) == NULL) return(NULL)\r
+\r
+#define M_ASN1_New_Error(a) \\r
+/*     err:    ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \\r
+               return(NULL);*/ \\r
+       err2:   ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \\r
+               return(NULL)\r
+\r
+\r
+/* BIG UGLY WARNING!  This is so damn ugly I wanna puke.  Unfortunately,\r
+   some macros that use ASN1_const_CTX still insist on writing in the input\r
+   stream.  ARGH!  ARGH!  ARGH!  Let's get rid of this macro package.\r
+   Please?                                             -- Richard Levitte */\r
+#define M_ASN1_next            (*((unsigned char *)(c.p)))\r
+#define M_ASN1_next_prev       (*((unsigned char *)(c.q)))\r
+\r
+/*************************************************/\r
+\r
+#define M_ASN1_I2D_vars(a)     int r=0,ret=0; \\r
+                               unsigned char *p; \\r
+                               if (a == NULL) return(0)\r
+\r
+/* Length Macros */\r
+#define M_ASN1_I2D_len(a,f)    ret+=f(a,NULL)\r
+#define M_ASN1_I2D_len_IMP_opt(a,f)    if (a != NULL) M_ASN1_I2D_len(a,f)\r
+\r
+#define M_ASN1_I2D_len_SET(a,f) \\r
+               ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);\r
+\r
+#define M_ASN1_I2D_len_SET_type(type,a,f) \\r
+               ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \\r
+                                           V_ASN1_UNIVERSAL,IS_SET);\r
+\r
+#define M_ASN1_I2D_len_SEQUENCE(a,f) \\r
+               ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \\r
+                                 IS_SEQUENCE);\r
+\r
+#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \\r
+               ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \\r
+                                           V_ASN1_UNIVERSAL,IS_SEQUENCE)\r
+\r
+#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \\r
+               if ((a != NULL) && (sk_num(a) != 0)) \\r
+                       M_ASN1_I2D_len_SEQUENCE(a,f);\r
+\r
+#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \\r
+               if ((a != NULL) && (sk_##type##_num(a) != 0)) \\r
+                       M_ASN1_I2D_len_SEQUENCE_type(type,a,f);\r
+\r
+#define M_ASN1_I2D_len_IMP_SET(a,f,x) \\r
+               ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);\r
+\r
+#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \\r
+               ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \\r
+                                           V_ASN1_CONTEXT_SPECIFIC,IS_SET);\r
+\r
+#define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \\r
+               if ((a != NULL) && (sk_num(a) != 0)) \\r
+                       ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \\r
+                                         IS_SET);\r
+\r
+#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \\r
+               if ((a != NULL) && (sk_##type##_num(a) != 0)) \\r
+                       ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \\r
+                                              V_ASN1_CONTEXT_SPECIFIC,IS_SET);\r
+\r
+#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \\r
+               ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \\r
+                                 IS_SEQUENCE);\r
+\r
+#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \\r
+               if ((a != NULL) && (sk_num(a) != 0)) \\r
+                       ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \\r
+                                         IS_SEQUENCE);\r
+\r
+#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \\r
+               if ((a != NULL) && (sk_##type##_num(a) != 0)) \\r
+                       ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \\r
+                                                   V_ASN1_CONTEXT_SPECIFIC, \\r
+                                                   IS_SEQUENCE);\r
+\r
+#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \\r
+               if (a != NULL)\\r
+                       { \\r
+                       v=f(a,NULL); \\r
+                       ret+=ASN1_object_size(1,v,mtag); \\r
+                       }\r
+\r
+#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \\r
+               if ((a != NULL) && (sk_num(a) != 0))\\r
+                       { \\r
+                       v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \\r
+                       ret+=ASN1_object_size(1,v,mtag); \\r
+                       }\r
+\r
+#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \\r
+               if ((a != NULL) && (sk_num(a) != 0))\\r
+                       { \\r
+                       v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \\r
+                                      IS_SEQUENCE); \\r
+                       ret+=ASN1_object_size(1,v,mtag); \\r
+                       }\r
+\r
+#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \\r
+               if ((a != NULL) && (sk_##type##_num(a) != 0))\\r
+                       { \\r
+                       v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \\r
+                                                V_ASN1_UNIVERSAL, \\r
+                                                IS_SEQUENCE); \\r
+                       ret+=ASN1_object_size(1,v,mtag); \\r
+                       }\r
+\r
+/* Put Macros */\r
+#define M_ASN1_I2D_put(a,f)    f(a,&p)\r
+\r
+#define M_ASN1_I2D_put_IMP_opt(a,f,t)  \\r
+               if (a != NULL) \\r
+                       { \\r
+                       unsigned char *q=p; \\r
+                       f(a,&p); \\r
+                       *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\\r
+                       }\r
+\r
+#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\\r
+                       V_ASN1_UNIVERSAL,IS_SET)\r
+#define M_ASN1_I2D_put_SET_type(type,a,f) \\r
+     i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)\r
+#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\\r
+                       V_ASN1_CONTEXT_SPECIFIC,IS_SET)\r
+#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \\r
+     i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)\r
+#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\\r
+                       V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)\r
+\r
+#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\\r
+                                            V_ASN1_UNIVERSAL,IS_SEQUENCE)\r
+\r
+#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \\r
+     i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \\r
+                           IS_SEQUENCE)\r
+\r
+#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \\r
+               if ((a != NULL) && (sk_num(a) != 0)) \\r
+                       M_ASN1_I2D_put_SEQUENCE(a,f);\r
+\r
+#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \\r
+               if ((a != NULL) && (sk_num(a) != 0)) \\r
+                       { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \\r
+                                      IS_SET); }\r
+\r
+#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \\r
+               if ((a != NULL) && (sk_##type##_num(a) != 0)) \\r
+                       { i2d_ASN1_SET_OF_##type(a,&p,f,x, \\r
+                                                V_ASN1_CONTEXT_SPECIFIC, \\r
+                                                IS_SET); }\r
+\r
+#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \\r
+               if ((a != NULL) && (sk_num(a) != 0)) \\r
+                       { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \\r
+                                      IS_SEQUENCE); }\r
+\r
+#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \\r
+               if ((a != NULL) && (sk_##type##_num(a) != 0)) \\r
+                       { i2d_ASN1_SET_OF_##type(a,&p,f,x, \\r
+                                                V_ASN1_CONTEXT_SPECIFIC, \\r
+                                                IS_SEQUENCE); }\r
+\r
+#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \\r
+               if (a != NULL) \\r
+                       { \\r
+                       ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \\r
+                       f(a,&p); \\r
+                       }\r
+\r
+#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \\r
+               if ((a != NULL) && (sk_num(a) != 0)) \\r
+                       { \\r
+                       ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \\r
+                       i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \\r
+                       }\r
+\r
+#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \\r
+               if ((a != NULL) && (sk_num(a) != 0)) \\r
+                       { \\r
+                       ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \\r
+                       i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \\r
+                       }\r
+\r
+#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \\r
+               if ((a != NULL) && (sk_##type##_num(a) != 0)) \\r
+                       { \\r
+                       ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \\r
+                       i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \\r
+                                              IS_SEQUENCE); \\r
+                       }\r
+\r
+#define M_ASN1_I2D_seq_total() \\r
+               r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \\r
+               if (pp == NULL) return(r); \\r
+               p= *pp; \\r
+               ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)\r
+\r
+#define M_ASN1_I2D_INF_seq_start(tag,ctx) \\r
+               *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \\r
+               *(p++)=0x80\r
+\r
+#define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00\r
+\r
+#define M_ASN1_I2D_finish()    *pp=p; \\r
+                               return(r);\r
+\r
+int asn1_GetSequence(ASN1_const_CTX *c, long *length);\r
+void asn1_add_error(const unsigned char *address,int offset);\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/asn1t.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/asn1t.h
new file mode 100644 (file)
index 0000000..2f18d03
--- /dev/null
@@ -0,0 +1,886 @@
+/* asn1t.h */\r
+/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL\r
+ * project 2000.\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    licensing@OpenSSL.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+#ifndef HEADER_ASN1T_H\r
+#define HEADER_ASN1T_H\r
+\r
+#include <stddef.h>\r
+#include <openssl/e_os2.h>\r
+#include <openssl/asn1.h>\r
+\r
+#ifdef OPENSSL_BUILD_SHLIBCRYPTO\r
+# undef OPENSSL_EXTERN\r
+# define OPENSSL_EXTERN OPENSSL_EXPORT\r
+#endif\r
+\r
+/* ASN1 template defines, structures and functions */\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION\r
+\r
+/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */\r
+#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))\r
+\r
+\r
+/* Macros for start and end of ASN1_ITEM definition */\r
+\r
+#define ASN1_ITEM_start(itname) \\r
+       OPENSSL_GLOBAL const ASN1_ITEM itname##_it = {\r
+\r
+#define ASN1_ITEM_end(itname) \\r
+               };\r
+\r
+#else\r
+\r
+/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */\r
+#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr()))\r
+\r
+\r
+/* Macros for start and end of ASN1_ITEM definition */\r
+\r
+#define ASN1_ITEM_start(itname) \\r
+       const ASN1_ITEM * itname##_it(void) \\r
+       { \\r
+               static const ASN1_ITEM local_it = { \\r
+\r
+#define ASN1_ITEM_end(itname) \\r
+               }; \\r
+       return &local_it; \\r
+       }\r
+\r
+#endif\r
+\r
+\r
+/* Macros to aid ASN1 template writing */\r
+\r
+#define ASN1_ITEM_TEMPLATE(tname) \\r
+       static const ASN1_TEMPLATE tname##_item_tt \r
+\r
+#define ASN1_ITEM_TEMPLATE_END(tname) \\r
+       ;\\r
+       ASN1_ITEM_start(tname) \\r
+               ASN1_ITYPE_PRIMITIVE,\\r
+               -1,\\r
+               &tname##_item_tt,\\r
+               0,\\r
+               NULL,\\r
+               0,\\r
+               #tname \\r
+       ASN1_ITEM_end(tname)\r
+\r
+\r
+/* This is a ASN1 type which just embeds a template */\r
\r
+/* This pair helps declare a SEQUENCE. We can do:\r
+ *\r
+ *     ASN1_SEQUENCE(stname) = {\r
+ *             ... SEQUENCE components ...\r
+ *     } ASN1_SEQUENCE_END(stname)\r
+ *\r
+ *     This will produce an ASN1_ITEM called stname_it\r
+ *     for a structure called stname.\r
+ *\r
+ *     If you want the same structure but a different\r
+ *     name then use:\r
+ *\r
+ *     ASN1_SEQUENCE(itname) = {\r
+ *             ... SEQUENCE components ...\r
+ *     } ASN1_SEQUENCE_END_name(stname, itname)\r
+ *\r
+ *     This will create an item called itname_it using\r
+ *     a structure called stname.\r
+ */\r
+\r
+#define ASN1_SEQUENCE(tname) \\r
+       static const ASN1_TEMPLATE tname##_seq_tt[] \r
+\r
+#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)\r
+\r
+#define ASN1_SEQUENCE_END_name(stname, tname) \\r
+       ;\\r
+       ASN1_ITEM_start(tname) \\r
+               ASN1_ITYPE_SEQUENCE,\\r
+               V_ASN1_SEQUENCE,\\r
+               tname##_seq_tt,\\r
+               sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\\r
+               NULL,\\r
+               sizeof(stname),\\r
+               #stname \\r
+       ASN1_ITEM_end(tname)\r
+\r
+#define ASN1_NDEF_SEQUENCE(tname) \\r
+       ASN1_SEQUENCE(tname)\r
+\r
+#define ASN1_SEQUENCE_cb(tname, cb) \\r
+       static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \\r
+       ASN1_SEQUENCE(tname)\r
+\r
+#define ASN1_BROKEN_SEQUENCE(tname) \\r
+       static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \\r
+       ASN1_SEQUENCE(tname)\r
+\r
+#define ASN1_SEQUENCE_ref(tname, cb, lck) \\r
+       static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \\r
+       ASN1_SEQUENCE(tname)\r
+\r
+#define ASN1_SEQUENCE_enc(tname, enc, cb) \\r
+       static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \\r
+       ASN1_SEQUENCE(tname)\r
+\r
+#define ASN1_NDEF_SEQUENCE_END(tname) \\r
+       ;\\r
+       ASN1_ITEM_start(tname) \\r
+               ASN1_ITYPE_NDEF_SEQUENCE,\\r
+               V_ASN1_SEQUENCE,\\r
+               tname##_seq_tt,\\r
+               sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\\r
+               NULL,\\r
+               sizeof(tname),\\r
+               #tname \\r
+       ASN1_ITEM_end(tname)\r
+\r
+#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)\r
+\r
+#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)\r
+\r
+#define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)\r
+\r
+#define ASN1_SEQUENCE_END_ref(stname, tname) \\r
+       ;\\r
+       ASN1_ITEM_start(tname) \\r
+               ASN1_ITYPE_SEQUENCE,\\r
+               V_ASN1_SEQUENCE,\\r
+               tname##_seq_tt,\\r
+               sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\\r
+               &tname##_aux,\\r
+               sizeof(stname),\\r
+               #stname \\r
+       ASN1_ITEM_end(tname)\r
+\r
+\r
+/* This pair helps declare a CHOICE type. We can do:\r
+ *\r
+ *     ASN1_CHOICE(chname) = {\r
+ *             ... CHOICE options ...\r
+ *     ASN1_CHOICE_END(chname)\r
+ *\r
+ *     This will produce an ASN1_ITEM called chname_it\r
+ *     for a structure called chname. The structure\r
+ *     definition must look like this:\r
+ *     typedef struct {\r
+ *             int type;\r
+ *             union {\r
+ *                     ASN1_SOMETHING *opt1;\r
+ *                     ASN1_SOMEOTHER *opt2;\r
+ *             } value;\r
+ *     } chname;\r
+ *     \r
+ *     the name of the selector must be 'type'.\r
+ *     to use an alternative selector name use the\r
+ *      ASN1_CHOICE_END_selector() version.\r
+ */\r
+\r
+#define ASN1_CHOICE(tname) \\r
+       static const ASN1_TEMPLATE tname##_ch_tt[] \r
+\r
+#define ASN1_CHOICE_cb(tname, cb) \\r
+       static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \\r
+       ASN1_CHOICE(tname)\r
+\r
+#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)\r
+\r
+#define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)\r
+\r
+#define ASN1_CHOICE_END_selector(stname, tname, selname) \\r
+       ;\\r
+       ASN1_ITEM_start(tname) \\r
+               ASN1_ITYPE_CHOICE,\\r
+               offsetof(stname,selname) ,\\r
+               tname##_ch_tt,\\r
+               sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\\r
+               NULL,\\r
+               sizeof(stname),\\r
+               #stname \\r
+       ASN1_ITEM_end(tname)\r
+\r
+#define ASN1_CHOICE_END_cb(stname, tname, selname) \\r
+       ;\\r
+       ASN1_ITEM_start(tname) \\r
+               ASN1_ITYPE_CHOICE,\\r
+               offsetof(stname,selname) ,\\r
+               tname##_ch_tt,\\r
+               sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\\r
+               &tname##_aux,\\r
+               sizeof(stname),\\r
+               #stname \\r
+       ASN1_ITEM_end(tname)\r
+\r
+/* This helps with the template wrapper form of ASN1_ITEM */\r
+\r
+#define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \\r
+       (flags), (tag), 0,\\r
+       #name, ASN1_ITEM_ref(type) }\r
+\r
+/* These help with SEQUENCE or CHOICE components */\r
+\r
+/* used to declare other types */\r
+\r
+#define ASN1_EX_TYPE(flags, tag, stname, field, type) { \\r
+       (flags), (tag), offsetof(stname, field),\\r
+       #field, ASN1_ITEM_ref(type) }\r
+\r
+/* used when the structure is combined with the parent */\r
+\r
+#define ASN1_EX_COMBINE(flags, tag, type) { \\r
+       (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }\r
+\r
+/* implicit and explicit helper macros */\r
+\r
+#define ASN1_IMP_EX(stname, field, type, tag, ex) \\r
+               ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)\r
+\r
+#define ASN1_EXP_EX(stname, field, type, tag, ex) \\r
+               ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)\r
+\r
+/* Any defined by macros: the field used is in the table itself */\r
+\r
+#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION\r
+#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }\r
+#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }\r
+#else\r
+#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }\r
+#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }\r
+#endif\r
+/* Plain simple type */\r
+#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)\r
+\r
+/* OPTIONAL simple type */\r
+#define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)\r
+\r
+/* IMPLICIT tagged simple type */\r
+#define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)\r
+\r
+/* IMPLICIT tagged OPTIONAL simple type */\r
+#define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)\r
+\r
+/* Same as above but EXPLICIT */\r
+\r
+#define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)\r
+#define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)\r
+\r
+/* SEQUENCE OF type */\r
+#define ASN1_SEQUENCE_OF(stname, field, type) \\r
+               ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)\r
+\r
+/* OPTIONAL SEQUENCE OF */\r
+#define ASN1_SEQUENCE_OF_OPT(stname, field, type) \\r
+               ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)\r
+\r
+/* Same as above but for SET OF */\r
+\r
+#define ASN1_SET_OF(stname, field, type) \\r
+               ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)\r
+\r
+#define ASN1_SET_OF_OPT(stname, field, type) \\r
+               ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)\r
+\r
+/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */\r
+\r
+#define ASN1_IMP_SET_OF(stname, field, type, tag) \\r
+                       ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)\r
+\r
+#define ASN1_EXP_SET_OF(stname, field, type, tag) \\r
+                       ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)\r
+\r
+#define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \\r
+                       ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)\r
+\r
+#define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \\r
+                       ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)\r
+\r
+#define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \\r
+                       ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)\r
+\r
+#define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \\r
+                       ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)\r
+\r
+#define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \\r
+                       ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)\r
+\r
+#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \\r
+                       ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)\r
+\r
+/* EXPLICIT OPTIONAL using indefinite length constructed form */\r
+#define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \\r
+                       ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF)\r
+\r
+/* Macros for the ASN1_ADB structure */\r
+\r
+#define ASN1_ADB(name) \\r
+       static const ASN1_ADB_TABLE name##_adbtbl[] \r
+\r
+#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION\r
+\r
+#define ASN1_ADB_END(name, flags, field, app_table, def, none) \\r
+       ;\\r
+       static const ASN1_ADB name##_adb = {\\r
+               flags,\\r
+               offsetof(name, field),\\r
+               app_table,\\r
+               name##_adbtbl,\\r
+               sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\\r
+               def,\\r
+               none\\r
+       }\r
+\r
+#else\r
+\r
+#define ASN1_ADB_END(name, flags, field, app_table, def, none) \\r
+       ;\\r
+       static const ASN1_ITEM *name##_adb(void) \\r
+       { \\r
+       static const ASN1_ADB internal_adb = \\r
+               {\\r
+               flags,\\r
+               offsetof(name, field),\\r
+               app_table,\\r
+               name##_adbtbl,\\r
+               sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\\r
+               def,\\r
+               none\\r
+               }; \\r
+               return (const ASN1_ITEM *) &internal_adb; \\r
+       } \\r
+       void dummy_function(void)\r
+\r
+#endif\r
+\r
+#define ADB_ENTRY(val, template) {val, template}\r
+\r
+#define ASN1_ADB_TEMPLATE(name) \\r
+       static const ASN1_TEMPLATE name##_tt \r
+\r
+/* This is the ASN1 template structure that defines\r
+ * a wrapper round the actual type. It determines the\r
+ * actual position of the field in the value structure,\r
+ * various flags such as OPTIONAL and the field name.\r
+ */\r
+\r
+struct ASN1_TEMPLATE_st {\r
+unsigned long flags;           /* Various flags */\r
+long tag;                      /* tag, not used if no tagging */\r
+unsigned long offset;          /* Offset of this field in structure */\r
+#ifndef NO_ASN1_FIELD_NAMES\r
+const char *field_name;                /* Field name */\r
+#endif\r
+ASN1_ITEM_EXP *item;           /* Relevant ASN1_ITEM or ASN1_ADB */\r
+};\r
+\r
+/* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */\r
+\r
+#define ASN1_TEMPLATE_item(t) (t->item_ptr)\r
+#define ASN1_TEMPLATE_adb(t) (t->item_ptr)\r
+\r
+typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;\r
+typedef struct ASN1_ADB_st ASN1_ADB;\r
+\r
+struct ASN1_ADB_st {\r
+       unsigned long flags;    /* Various flags */\r
+       unsigned long offset;   /* Offset of selector field */\r
+       STACK_OF(ASN1_ADB_TABLE) **app_items; /* Application defined items */\r
+       const ASN1_ADB_TABLE *tbl;      /* Table of possible types */\r
+       long tblcount;          /* Number of entries in tbl */\r
+       const ASN1_TEMPLATE *default_tt;  /* Type to use if no match */\r
+       const ASN1_TEMPLATE *null_tt;  /* Type to use if selector is NULL */\r
+};\r
+\r
+struct ASN1_ADB_TABLE_st {\r
+       long value;             /* NID for an object or value for an int */\r
+       const ASN1_TEMPLATE tt;         /* item for this value */\r
+};\r
+\r
+/* template flags */\r
+\r
+/* Field is optional */\r
+#define ASN1_TFLG_OPTIONAL     (0x1)\r
+\r
+/* Field is a SET OF */\r
+#define ASN1_TFLG_SET_OF       (0x1 << 1)\r
+\r
+/* Field is a SEQUENCE OF */\r
+#define ASN1_TFLG_SEQUENCE_OF  (0x2 << 1)\r
+\r
+/* Special case: this refers to a SET OF that\r
+ * will be sorted into DER order when encoded *and*\r
+ * the corresponding STACK will be modified to match\r
+ * the new order.\r
+ */\r
+#define ASN1_TFLG_SET_ORDER    (0x3 << 1)\r
+\r
+/* Mask for SET OF or SEQUENCE OF */\r
+#define ASN1_TFLG_SK_MASK      (0x3 << 1)\r
+\r
+/* These flags mean the tag should be taken from the\r
+ * tag field. If EXPLICIT then the underlying type\r
+ * is used for the inner tag.\r
+ */\r
+\r
+/* IMPLICIT tagging */\r
+#define ASN1_TFLG_IMPTAG       (0x1 << 3)\r
+\r
+\r
+/* EXPLICIT tagging, inner tag from underlying type */\r
+#define ASN1_TFLG_EXPTAG       (0x2 << 3)\r
+\r
+#define ASN1_TFLG_TAG_MASK     (0x3 << 3)\r
+\r
+/* context specific IMPLICIT */\r
+#define ASN1_TFLG_IMPLICIT     ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT\r
+\r
+/* context specific EXPLICIT */\r
+#define ASN1_TFLG_EXPLICIT     ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT\r
+\r
+/* If tagging is in force these determine the\r
+ * type of tag to use. Otherwise the tag is\r
+ * determined by the underlying type. These \r
+ * values reflect the actual octet format.\r
+ */\r
+\r
+/* Universal tag */ \r
+#define ASN1_TFLG_UNIVERSAL    (0x0<<6)\r
+/* Application tag */ \r
+#define ASN1_TFLG_APPLICATION  (0x1<<6)\r
+/* Context specific tag */ \r
+#define ASN1_TFLG_CONTEXT      (0x2<<6)\r
+/* Private tag */ \r
+#define ASN1_TFLG_PRIVATE      (0x3<<6)\r
+\r
+#define ASN1_TFLG_TAG_CLASS    (0x3<<6)\r
+\r
+/* These are for ANY DEFINED BY type. In this case\r
+ * the 'item' field points to an ASN1_ADB structure\r
+ * which contains a table of values to decode the\r
+ * relevant type\r
+ */\r
+\r
+#define ASN1_TFLG_ADB_MASK     (0x3<<8)\r
+\r
+#define ASN1_TFLG_ADB_OID      (0x1<<8)\r
+\r
+#define ASN1_TFLG_ADB_INT      (0x1<<9)\r
+\r
+/* This flag means a parent structure is passed\r
+ * instead of the field: this is useful is a\r
+ * SEQUENCE is being combined with a CHOICE for\r
+ * example. Since this means the structure and\r
+ * item name will differ we need to use the\r
+ * ASN1_CHOICE_END_name() macro for example.\r
+ */\r
+\r
+#define ASN1_TFLG_COMBINE      (0x1<<10)\r
+\r
+/* This flag when present in a SEQUENCE OF, SET OF\r
+ * or EXPLICIT causes indefinite length constructed\r
+ * encoding to be used if required.\r
+ */\r
+\r
+#define ASN1_TFLG_NDEF         (0x1<<11)\r
+\r
+/* This is the actual ASN1 item itself */\r
+\r
+struct ASN1_ITEM_st {\r
+char itype;                    /* The item type, primitive, SEQUENCE, CHOICE or extern */\r
+long utype;                    /* underlying type */\r
+const ASN1_TEMPLATE *templates;        /* If SEQUENCE or CHOICE this contains the contents */\r
+long tcount;                   /* Number of templates if SEQUENCE or CHOICE */\r
+const void *funcs;             /* functions that handle this type */\r
+long size;                     /* Structure size (usually)*/\r
+#ifndef NO_ASN1_FIELD_NAMES\r
+const char *sname;             /* Structure name */\r
+#endif\r
+};\r
+\r
+/* These are values for the itype field and\r
+ * determine how the type is interpreted.\r
+ *\r
+ * For PRIMITIVE types the underlying type\r
+ * determines the behaviour if items is NULL.\r
+ *\r
+ * Otherwise templates must contain a single \r
+ * template and the type is treated in the\r
+ * same way as the type specified in the template.\r
+ *\r
+ * For SEQUENCE types the templates field points\r
+ * to the members, the size field is the\r
+ * structure size.\r
+ *\r
+ * For CHOICE types the templates field points\r
+ * to each possible member (typically a union)\r
+ * and the 'size' field is the offset of the\r
+ * selector.\r
+ *\r
+ * The 'funcs' field is used for application\r
+ * specific functions. \r
+ *\r
+ * For COMPAT types the funcs field gives a\r
+ * set of functions that handle this type, this\r
+ * supports the old d2i, i2d convention.\r
+ *\r
+ * The EXTERN type uses a new style d2i/i2d.\r
+ * The new style should be used where possible\r
+ * because it avoids things like the d2i IMPLICIT\r
+ * hack.\r
+ *\r
+ * MSTRING is a multiple string type, it is used\r
+ * for a CHOICE of character strings where the\r
+ * actual strings all occupy an ASN1_STRING\r
+ * structure. In this case the 'utype' field\r
+ * has a special meaning, it is used as a mask\r
+ * of acceptable types using the B_ASN1 constants.\r
+ *\r
+ * NDEF_SEQUENCE is the same as SEQUENCE except\r
+ * that it will use indefinite length constructed\r
+ * encoding if requested.\r
+ *\r
+ */\r
+\r
+#define ASN1_ITYPE_PRIMITIVE           0x0\r
+\r
+#define ASN1_ITYPE_SEQUENCE            0x1\r
+\r
+#define ASN1_ITYPE_CHOICE              0x2\r
+\r
+#define ASN1_ITYPE_COMPAT              0x3\r
+\r
+#define ASN1_ITYPE_EXTERN              0x4\r
+\r
+#define ASN1_ITYPE_MSTRING             0x5\r
+\r
+#define ASN1_ITYPE_NDEF_SEQUENCE       0x6\r
+\r
+/* Cache for ASN1 tag and length, so we\r
+ * don't keep re-reading it for things\r
+ * like CHOICE\r
+ */\r
+\r
+struct ASN1_TLC_st{\r
+       char valid;     /* Values below are valid */\r
+       int ret;        /* return value */\r
+       long plen;      /* length */\r
+       int ptag;       /* class value */\r
+       int pclass;     /* class value */\r
+       int hdrlen;     /* header length */\r
+};\r
+\r
+/* Typedefs for ASN1 function pointers */\r
+\r
+typedef ASN1_VALUE * ASN1_new_func(void);\r
+typedef void ASN1_free_func(ASN1_VALUE *a);\r
+typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in, long length);\r
+typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in);\r
+\r
+typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it,\r
+                                       int tag, int aclass, char opt, ASN1_TLC *ctx);\r
+\r
+typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);\r
+typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
+typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
+\r
+typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);\r
+typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);\r
+\r
+typedef struct ASN1_COMPAT_FUNCS_st {\r
+       ASN1_new_func *asn1_new;\r
+       ASN1_free_func *asn1_free;\r
+       ASN1_d2i_func *asn1_d2i;\r
+       ASN1_i2d_func *asn1_i2d;\r
+} ASN1_COMPAT_FUNCS;\r
+\r
+typedef struct ASN1_EXTERN_FUNCS_st {\r
+       void *app_data;\r
+       ASN1_ex_new_func *asn1_ex_new;\r
+       ASN1_ex_free_func *asn1_ex_free;\r
+       ASN1_ex_free_func *asn1_ex_clear;\r
+       ASN1_ex_d2i *asn1_ex_d2i;\r
+       ASN1_ex_i2d *asn1_ex_i2d;\r
+} ASN1_EXTERN_FUNCS;\r
+\r
+typedef struct ASN1_PRIMITIVE_FUNCS_st {\r
+       void *app_data;\r
+       unsigned long flags;\r
+       ASN1_ex_new_func *prim_new;\r
+       ASN1_ex_free_func *prim_free;\r
+       ASN1_ex_free_func *prim_clear;\r
+       ASN1_primitive_c2i *prim_c2i;\r
+       ASN1_primitive_i2c *prim_i2c;\r
+} ASN1_PRIMITIVE_FUNCS;\r
+\r
+/* This is the ASN1_AUX structure: it handles various\r
+ * miscellaneous requirements. For example the use of\r
+ * reference counts and an informational callback.\r
+ *\r
+ * The "informational callback" is called at various\r
+ * points during the ASN1 encoding and decoding. It can\r
+ * be used to provide minor customisation of the structures\r
+ * used. This is most useful where the supplied routines\r
+ * *almost* do the right thing but need some extra help\r
+ * at a few points. If the callback returns zero then\r
+ * it is assumed a fatal error has occurred and the \r
+ * main operation should be abandoned.\r
+ *\r
+ * If major changes in the default behaviour are required\r
+ * then an external type is more appropriate.\r
+ */\r
+\r
+typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it);\r
+\r
+typedef struct ASN1_AUX_st {\r
+       void *app_data;\r
+       int flags;\r
+       int ref_offset;         /* Offset of reference value */\r
+       int ref_lock;           /* Lock type to use */\r
+       ASN1_aux_cb *asn1_cb;\r
+       int enc_offset;         /* Offset of ASN1_ENCODING structure */\r
+} ASN1_AUX;\r
+\r
+/* Flags in ASN1_AUX */\r
+\r
+/* Use a reference count */\r
+#define ASN1_AFLG_REFCOUNT     1\r
+/* Save the encoding of structure (useful for signatures) */\r
+#define ASN1_AFLG_ENCODING     2\r
+/* The Sequence length is invalid */\r
+#define ASN1_AFLG_BROKEN       4\r
+\r
+/* operation values for asn1_cb */\r
+\r
+#define ASN1_OP_NEW_PRE                0\r
+#define ASN1_OP_NEW_POST       1\r
+#define ASN1_OP_FREE_PRE       2\r
+#define ASN1_OP_FREE_POST      3\r
+#define ASN1_OP_D2I_PRE                4\r
+#define ASN1_OP_D2I_POST       5\r
+#define ASN1_OP_I2D_PRE                6\r
+#define ASN1_OP_I2D_POST       7\r
+\r
+/* Macro to implement a primitive type */\r
+#define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)\r
+#define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \\r
+                               ASN1_ITEM_start(itname) \\r
+                                       ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \\r
+                               ASN1_ITEM_end(itname)\r
+\r
+/* Macro to implement a multi string type */\r
+#define IMPLEMENT_ASN1_MSTRING(itname, mask) \\r
+                               ASN1_ITEM_start(itname) \\r
+                                       ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \\r
+                               ASN1_ITEM_end(itname)\r
+\r
+/* Macro to implement an ASN1_ITEM in terms of old style funcs */\r
+\r
+#define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE)\r
+\r
+#define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \\r
+       static const ASN1_COMPAT_FUNCS sname##_ff = { \\r
+               (ASN1_new_func *)sname##_new, \\r
+               (ASN1_free_func *)sname##_free, \\r
+               (ASN1_d2i_func *)d2i_##sname, \\r
+               (ASN1_i2d_func *)i2d_##sname, \\r
+       }; \\r
+       ASN1_ITEM_start(sname) \\r
+               ASN1_ITYPE_COMPAT, \\r
+               tag, \\r
+               NULL, \\r
+               0, \\r
+               &sname##_ff, \\r
+               0, \\r
+               #sname \\r
+       ASN1_ITEM_end(sname)\r
+\r
+#define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \\r
+       ASN1_ITEM_start(sname) \\r
+               ASN1_ITYPE_EXTERN, \\r
+               tag, \\r
+               NULL, \\r
+               0, \\r
+               &fptrs, \\r
+               0, \\r
+               #sname \\r
+       ASN1_ITEM_end(sname)\r
+\r
+/* Macro to implement standard functions in terms of ASN1_ITEM structures */\r
+\r
+#define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)\r
+\r
+#define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)\r
+\r
+#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \\r
+                       IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)\r
+\r
+#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \\r
+               IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)\r
+\r
+#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \\r
+       stname *fname##_new(void) \\r
+       { \\r
+               return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \\r
+       } \\r
+       void fname##_free(stname *a) \\r
+       { \\r
+               ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \\r
+       }\r
+\r
+#define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \\r
+       IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \\r
+       IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)\r
+\r
+#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \\r
+       stname *d2i_##fname(stname **a, const unsigned char **in, long len) \\r
+       { \\r
+               return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\\r
+       } \\r
+       int i2d_##fname(stname *a, unsigned char **out) \\r
+       { \\r
+               return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\\r
+       } \r
+\r
+#define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \\r
+       int i2d_##stname##_NDEF(stname *a, unsigned char **out) \\r
+       { \\r
+               return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\\r
+       } \r
+\r
+/* This includes evil casts to remove const: they will go away when full\r
+ * ASN1 constification is done.\r
+ */\r
+#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \\r
+       stname *d2i_##fname(stname **a, const unsigned char **in, long len) \\r
+       { \\r
+               return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\\r
+       } \\r
+       int i2d_##fname(const stname *a, unsigned char **out) \\r
+       { \\r
+               return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\\r
+       } \r
+\r
+#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \\r
+       stname * stname##_dup(stname *x) \\r
+        { \\r
+        return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \\r
+        }\r
+\r
+#define IMPLEMENT_ASN1_FUNCTIONS_const(name) \\r
+               IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)\r
+\r
+#define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \\r
+       IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \\r
+       IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)\r
+\r
+/* external definitions for primitive types */\r
+\r
+DECLARE_ASN1_ITEM(ASN1_BOOLEAN)\r
+DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)\r
+DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)\r
+DECLARE_ASN1_ITEM(ASN1_SEQUENCE)\r
+DECLARE_ASN1_ITEM(CBIGNUM)\r
+DECLARE_ASN1_ITEM(BIGNUM)\r
+DECLARE_ASN1_ITEM(LONG)\r
+DECLARE_ASN1_ITEM(ZLONG)\r
+\r
+DECLARE_STACK_OF(ASN1_VALUE)\r
+\r
+/* Functions used internally by the ASN1 code */\r
+\r
+int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
+void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
+int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);\r
+int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
+\r
+void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);\r
+int ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_TEMPLATE *tt);\r
+int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it,\r
+                               int tag, int aclass, char opt, ASN1_TLC *ctx);\r
+\r
+int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);\r
+int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt);\r
+void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
+\r
+int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);\r
+int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);\r
+\r
+int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
+int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it);\r
+\r
+ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);\r
+\r
+const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr);\r
+\r
+int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);\r
+\r
+void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
+void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);\r
+int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it);\r
+int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const ASN1_ITEM *it);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/bio.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/bio.h
new file mode 100644 (file)
index 0000000..38b6f27
--- /dev/null
@@ -0,0 +1,767 @@
+/* crypto/bio/bio.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_BIO_H\r
+#define HEADER_BIO_H\r
+\r
+#include <openssl/e_os2.h>\r
+\r
+#ifndef OPENSSL_NO_FP_API\r
+# include <stdio.h>\r
+#endif\r
+#include <stdarg.h>\r
+\r
+#include <openssl/crypto.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* These are the 'types' of BIOs */\r
+#define BIO_TYPE_NONE          0\r
+#define BIO_TYPE_MEM           (1|0x0400)\r
+#define BIO_TYPE_FILE          (2|0x0400)\r
+\r
+#define BIO_TYPE_FD            (4|0x0400|0x0100)\r
+#define BIO_TYPE_SOCKET                (5|0x0400|0x0100)\r
+#define BIO_TYPE_NULL          (6|0x0400)\r
+#define BIO_TYPE_SSL           (7|0x0200)\r
+#define BIO_TYPE_MD            (8|0x0200)              /* passive filter */\r
+#define BIO_TYPE_BUFFER                (9|0x0200)              /* filter */\r
+#define BIO_TYPE_CIPHER                (10|0x0200)             /* filter */\r
+#define BIO_TYPE_BASE64                (11|0x0200)             /* filter */\r
+#define BIO_TYPE_CONNECT       (12|0x0400|0x0100)      /* socket - connect */\r
+#define BIO_TYPE_ACCEPT                (13|0x0400|0x0100)      /* socket for accept */\r
+#define BIO_TYPE_PROXY_CLIENT  (14|0x0200)             /* client proxy BIO */\r
+#define BIO_TYPE_PROXY_SERVER  (15|0x0200)             /* server proxy BIO */\r
+#define BIO_TYPE_NBIO_TEST     (16|0x0200)             /* server proxy BIO */\r
+#define BIO_TYPE_NULL_FILTER   (17|0x0200)\r
+#define BIO_TYPE_BER           (18|0x0200)             /* BER -> bin filter */\r
+#define BIO_TYPE_BIO           (19|0x0400)             /* (half a) BIO pair */\r
+#define BIO_TYPE_LINEBUFFER    (20|0x0200)             /* filter */\r
+#define BIO_TYPE_DGRAM         (21|0x0400|0x0100)\r
+\r
+#define BIO_TYPE_DESCRIPTOR    0x0100  /* socket, fd, connect or accept */\r
+#define BIO_TYPE_FILTER                0x0200\r
+#define BIO_TYPE_SOURCE_SINK   0x0400\r
+\r
+/* BIO_FILENAME_READ|BIO_CLOSE to open or close on free.\r
+ * BIO_set_fp(in,stdin,BIO_NOCLOSE); */\r
+#define BIO_NOCLOSE            0x00\r
+#define BIO_CLOSE              0x01\r
+\r
+/* These are used in the following macros and are passed to\r
+ * BIO_ctrl() */\r
+#define BIO_CTRL_RESET         1  /* opt - rewind/zero etc */\r
+#define BIO_CTRL_EOF           2  /* opt - are we at the eof */\r
+#define BIO_CTRL_INFO          3  /* opt - extra tit-bits */\r
+#define BIO_CTRL_SET           4  /* man - set the 'IO' type */\r
+#define BIO_CTRL_GET           5  /* man - get the 'IO' type */\r
+#define BIO_CTRL_PUSH          6  /* opt - internal, used to signify change */\r
+#define BIO_CTRL_POP           7  /* opt - internal, used to signify change */\r
+#define BIO_CTRL_GET_CLOSE     8  /* man - set the 'close' on free */\r
+#define BIO_CTRL_SET_CLOSE     9  /* man - set the 'close' on free */\r
+#define BIO_CTRL_PENDING       10  /* opt - is their more data buffered */\r
+#define BIO_CTRL_FLUSH         11  /* opt - 'flush' buffered output */\r
+#define BIO_CTRL_DUP           12  /* man - extra stuff for 'duped' BIO */\r
+#define BIO_CTRL_WPENDING      13  /* opt - number of bytes still to write */\r
+/* callback is int cb(BIO *bio,state,ret); */\r
+#define BIO_CTRL_SET_CALLBACK  14  /* opt - set callback function */\r
+#define BIO_CTRL_GET_CALLBACK  15  /* opt - set callback function */\r
+\r
+#define BIO_CTRL_SET_FILENAME  30      /* BIO_s_file special */\r
+\r
+/* dgram BIO stuff */\r
+#define BIO_CTRL_DGRAM_CONNECT       31  /* BIO dgram special */\r
+#define BIO_CTRL_DGRAM_SET_CONNECTED 32  /* allow for an externally\r
+                                                                                 * connected socket to be\r
+                                                                                 * passed in */ \r
+#define BIO_CTRL_DGRAM_SET_RECV_TIMEOUT 33 /* setsockopt, essentially */\r
+#define BIO_CTRL_DGRAM_GET_RECV_TIMEOUT 34 /* getsockopt, essentially */\r
+#define BIO_CTRL_DGRAM_SET_SEND_TIMEOUT 35 /* setsockopt, essentially */\r
+#define BIO_CTRL_DGRAM_GET_SEND_TIMEOUT 36 /* getsockopt, essentially */\r
+\r
+#define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37 /* flag whether the last */\r
+#define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38 /* I/O operation tiemd out */\r
+                                       \r
+/* #ifdef IP_MTU_DISCOVER */\r
+#define BIO_CTRL_DGRAM_MTU_DISCOVER       39 /* set DF bit on egress packets */\r
+/* #endif */\r
+\r
+#define BIO_CTRL_DGRAM_QUERY_MTU          40 /* as kernel for current MTU */\r
+#define BIO_CTRL_DGRAM_GET_MTU            41 /* get cached value for MTU */\r
+#define BIO_CTRL_DGRAM_SET_MTU            42 /* set cached value for\r
+                                                                                         * MTU. want to use this\r
+                                              * if asking the kernel\r
+                                              * fails */\r
+\r
+#define BIO_CTRL_DGRAM_MTU_EXCEEDED       43 /* check whether the MTU\r
+                                                                                         * was exceed in the\r
+                                                                                         * previous write\r
+                                                                                         * operation */\r
+\r
+#define BIO_CTRL_DGRAM_SET_PEER           44 /* Destination for the data */\r
+\r
+\r
+/* modifiers */\r
+#define BIO_FP_READ            0x02\r
+#define BIO_FP_WRITE           0x04\r
+#define BIO_FP_APPEND          0x08\r
+#define BIO_FP_TEXT            0x10\r
+\r
+#define BIO_FLAGS_READ         0x01\r
+#define BIO_FLAGS_WRITE                0x02\r
+#define BIO_FLAGS_IO_SPECIAL   0x04\r
+#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)\r
+#define BIO_FLAGS_SHOULD_RETRY 0x08\r
+#ifndef        BIO_FLAGS_UPLINK\r
+/* "UPLINK" flag denotes file descriptors provided by application.\r
+   It defaults to 0, as most platforms don't require UPLINK interface. */\r
+#define        BIO_FLAGS_UPLINK        0\r
+#endif\r
+\r
+/* Used in BIO_gethostbyname() */\r
+#define BIO_GHBN_CTRL_HITS             1\r
+#define BIO_GHBN_CTRL_MISSES           2\r
+#define BIO_GHBN_CTRL_CACHE_SIZE       3\r
+#define BIO_GHBN_CTRL_GET_ENTRY                4\r
+#define BIO_GHBN_CTRL_FLUSH            5\r
+\r
+/* Mostly used in the SSL BIO */\r
+/* Not used anymore\r
+ * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10\r
+ * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20\r
+ * #define BIO_FLAGS_PROTOCOL_STARTUP  0x40\r
+ */\r
+\r
+#define BIO_FLAGS_BASE64_NO_NL 0x100\r
+\r
+/* This is used with memory BIOs: it means we shouldn't free up or change the\r
+ * data in any way.\r
+ */\r
+#define BIO_FLAGS_MEM_RDONLY   0x200\r
+\r
+#define BIO_set_flags(b,f) ((b)->flags|=(f))\r
+#define BIO_get_flags(b) ((b)->flags)\r
+#define BIO_set_retry_special(b) \\r
+               ((b)->flags|=(BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY))\r
+#define BIO_set_retry_read(b) \\r
+               ((b)->flags|=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY))\r
+#define BIO_set_retry_write(b) \\r
+               ((b)->flags|=(BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY))\r
+\r
+/* These are normally used internally in BIOs */\r
+#define BIO_clear_flags(b,f) ((b)->flags&= ~(f))\r
+#define BIO_clear_retry_flags(b) \\r
+               ((b)->flags&= ~(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))\r
+#define BIO_get_retry_flags(b) \\r
+               ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))\r
+\r
+/* These should be used by the application to tell why we should retry */\r
+#define BIO_should_read(a)             ((a)->flags & BIO_FLAGS_READ)\r
+#define BIO_should_write(a)            ((a)->flags & BIO_FLAGS_WRITE)\r
+#define BIO_should_io_special(a)       ((a)->flags & BIO_FLAGS_IO_SPECIAL)\r
+#define BIO_retry_type(a)              ((a)->flags & BIO_FLAGS_RWS)\r
+#define BIO_should_retry(a)            ((a)->flags & BIO_FLAGS_SHOULD_RETRY)\r
+\r
+/* The next three are used in conjunction with the\r
+ * BIO_should_io_special() condition.  After this returns true,\r
+ * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO \r
+ * stack and return the 'reason' for the special and the offending BIO.\r
+ * Given a BIO, BIO_get_retry_reason(bio) will return the code. */\r
+/* Returned from the SSL bio when the certificate retrieval code had an error */\r
+#define BIO_RR_SSL_X509_LOOKUP         0x01\r
+/* Returned from the connect BIO when a connect would have blocked */\r
+#define BIO_RR_CONNECT                 0x02\r
+/* Returned from the accept BIO when an accept would have blocked */\r
+#define BIO_RR_ACCEPT                  0x03\r
+\r
+/* These are passed by the BIO callback */\r
+#define BIO_CB_FREE    0x01\r
+#define BIO_CB_READ    0x02\r
+#define BIO_CB_WRITE   0x03\r
+#define BIO_CB_PUTS    0x04\r
+#define BIO_CB_GETS    0x05\r
+#define BIO_CB_CTRL    0x06\r
+\r
+/* The callback is called before and after the underling operation,\r
+ * The BIO_CB_RETURN flag indicates if it is after the call */\r
+#define BIO_CB_RETURN  0x80\r
+#define BIO_CB_return(a) ((a)|BIO_CB_RETURN))\r
+#define BIO_cb_pre(a)  (!((a)&BIO_CB_RETURN))\r
+#define BIO_cb_post(a) ((a)&BIO_CB_RETURN)\r
+\r
+#define BIO_set_callback(b,cb)         ((b)->callback=(cb))\r
+#define BIO_set_callback_arg(b,arg)    ((b)->cb_arg=(char *)(arg))\r
+#define BIO_get_callback_arg(b)                ((b)->cb_arg)\r
+#define BIO_get_callback(b)            ((b)->callback)\r
+#define BIO_method_name(b)             ((b)->method->name)\r
+#define BIO_method_type(b)             ((b)->method->type)\r
+\r
+typedef struct bio_st BIO;\r
+\r
+typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long);\r
+\r
+#ifndef OPENSSL_SYS_WIN16\r
+typedef struct bio_method_st\r
+       {\r
+       int type;\r
+       const char *name;\r
+       int (*bwrite)(BIO *, const char *, int);\r
+       int (*bread)(BIO *, char *, int);\r
+       int (*bputs)(BIO *, const char *);\r
+       int (*bgets)(BIO *, char *, int);\r
+       long (*ctrl)(BIO *, int, long, void *);\r
+       int (*create)(BIO *);\r
+       int (*destroy)(BIO *);\r
+        long (*callback_ctrl)(BIO *, int, bio_info_cb *);\r
+       } BIO_METHOD;\r
+#else\r
+typedef struct bio_method_st\r
+       {\r
+       int type;\r
+       const char *name;\r
+       int (_far *bwrite)();\r
+       int (_far *bread)();\r
+       int (_far *bputs)();\r
+       int (_far *bgets)();\r
+       long (_far *ctrl)();\r
+       int (_far *create)();\r
+       int (_far *destroy)();\r
+       long (_far *callback_ctrl)();\r
+       } BIO_METHOD;\r
+#endif\r
+\r
+struct bio_st\r
+       {\r
+       BIO_METHOD *method;\r
+       /* bio, mode, argp, argi, argl, ret */\r
+       long (*callback)(struct bio_st *,int,const char *,int, long,long);\r
+       char *cb_arg; /* first argument for the callback */\r
+\r
+       int init;\r
+       int shutdown;\r
+       int flags;      /* extra storage */\r
+       int retry_reason;\r
+       int num;\r
+       void *ptr;\r
+       struct bio_st *next_bio;        /* used by filter BIOs */\r
+       struct bio_st *prev_bio;        /* used by filter BIOs */\r
+       int references;\r
+       unsigned long num_read;\r
+       unsigned long num_write;\r
+\r
+       CRYPTO_EX_DATA ex_data;\r
+       };\r
+\r
+DECLARE_STACK_OF(BIO)\r
+\r
+typedef struct bio_f_buffer_ctx_struct\r
+       {\r
+       /* BIO *bio; */ /* this is now in the BIO struct */\r
+       int ibuf_size;  /* how big is the input buffer */\r
+       int obuf_size;  /* how big is the output buffer */\r
+\r
+       char *ibuf;             /* the char array */\r
+       int ibuf_len;           /* how many bytes are in it */\r
+       int ibuf_off;           /* write/read offset */\r
+\r
+       char *obuf;             /* the char array */\r
+       int obuf_len;           /* how many bytes are in it */\r
+       int obuf_off;           /* write/read offset */\r
+       } BIO_F_BUFFER_CTX;\r
+\r
+/* connect BIO stuff */\r
+#define BIO_CONN_S_BEFORE              1\r
+#define BIO_CONN_S_GET_IP              2\r
+#define BIO_CONN_S_GET_PORT            3\r
+#define BIO_CONN_S_CREATE_SOCKET       4\r
+#define BIO_CONN_S_CONNECT             5\r
+#define BIO_CONN_S_OK                  6\r
+#define BIO_CONN_S_BLOCKED_CONNECT     7\r
+#define BIO_CONN_S_NBIO                        8\r
+/*#define BIO_CONN_get_param_hostname  BIO_ctrl */\r
+\r
+#define BIO_C_SET_CONNECT                      100\r
+#define BIO_C_DO_STATE_MACHINE                 101\r
+#define BIO_C_SET_NBIO                         102\r
+#define BIO_C_SET_PROXY_PARAM                  103\r
+#define BIO_C_SET_FD                           104\r
+#define BIO_C_GET_FD                           105\r
+#define BIO_C_SET_FILE_PTR                     106\r
+#define BIO_C_GET_FILE_PTR                     107\r
+#define BIO_C_SET_FILENAME                     108\r
+#define BIO_C_SET_SSL                          109\r
+#define BIO_C_GET_SSL                          110\r
+#define BIO_C_SET_MD                           111\r
+#define BIO_C_GET_MD                           112\r
+#define BIO_C_GET_CIPHER_STATUS                        113\r
+#define BIO_C_SET_BUF_MEM                      114\r
+#define BIO_C_GET_BUF_MEM_PTR                  115\r
+#define BIO_C_GET_BUFF_NUM_LINES               116\r
+#define BIO_C_SET_BUFF_SIZE                    117\r
+#define BIO_C_SET_ACCEPT                       118\r
+#define BIO_C_SSL_MODE                         119\r
+#define BIO_C_GET_MD_CTX                       120\r
+#define BIO_C_GET_PROXY_PARAM                  121\r
+#define BIO_C_SET_BUFF_READ_DATA               122 /* data to read first */\r
+#define BIO_C_GET_CONNECT                      123\r
+#define BIO_C_GET_ACCEPT                       124\r
+#define BIO_C_SET_SSL_RENEGOTIATE_BYTES                125\r
+#define BIO_C_GET_SSL_NUM_RENEGOTIATES         126\r
+#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT      127\r
+#define BIO_C_FILE_SEEK                                128\r
+#define BIO_C_GET_CIPHER_CTX                   129\r
+#define BIO_C_SET_BUF_MEM_EOF_RETURN           130/*return end of input value*/\r
+#define BIO_C_SET_BIND_MODE                    131\r
+#define BIO_C_GET_BIND_MODE                    132\r
+#define BIO_C_FILE_TELL                                133\r
+#define BIO_C_GET_SOCKS                                134\r
+#define BIO_C_SET_SOCKS                                135\r
+\r
+#define BIO_C_SET_WRITE_BUF_SIZE               136/* for BIO_s_bio */\r
+#define BIO_C_GET_WRITE_BUF_SIZE               137\r
+#define BIO_C_MAKE_BIO_PAIR                    138\r
+#define BIO_C_DESTROY_BIO_PAIR                 139\r
+#define BIO_C_GET_WRITE_GUARANTEE              140\r
+#define BIO_C_GET_READ_REQUEST                 141\r
+#define BIO_C_SHUTDOWN_WR                      142\r
+#define BIO_C_NREAD0                           143\r
+#define BIO_C_NREAD                            144\r
+#define BIO_C_NWRITE0                          145\r
+#define BIO_C_NWRITE                           146\r
+#define BIO_C_RESET_READ_REQUEST               147\r
+\r
+\r
+#define BIO_set_app_data(s,arg)                BIO_set_ex_data(s,0,arg)\r
+#define BIO_get_app_data(s)            BIO_get_ex_data(s,0)\r
+\r
+/* BIO_s_connect() and BIO_s_socks4a_connect() */\r
+#define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)\r
+#define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)\r
+#define BIO_set_conn_ip(b,ip)    BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip)\r
+#define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port)\r
+#define BIO_get_conn_hostname(b)  BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)\r
+#define BIO_get_conn_port(b)      BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)\r
+#define BIO_get_conn_ip(b)              BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2)\r
+#define BIO_get_conn_int_port(b) BIO_int_ctrl(b,BIO_C_GET_CONNECT,3)\r
+\r
+\r
+#define BIO_set_nbio(b,n)      BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)\r
+\r
+/* BIO_s_accept_socket() */\r
+#define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name)\r
+#define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0)\r
+/* #define BIO_set_nbio(b,n)   BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */\r
+#define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL)\r
+#define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio)\r
+\r
+#define BIO_BIND_NORMAL                        0\r
+#define BIO_BIND_REUSEADDR_IF_UNUSED   1\r
+#define BIO_BIND_REUSEADDR             2\r
+#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)\r
+#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)\r
+\r
+#define BIO_do_connect(b)      BIO_do_handshake(b)\r
+#define BIO_do_accept(b)       BIO_do_handshake(b)\r
+#define BIO_do_handshake(b)    BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)\r
+\r
+/* BIO_s_proxy_client() */\r
+#define BIO_set_url(b,url)     BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url))\r
+#define BIO_set_proxies(b,p)   BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p))\r
+/* BIO_set_nbio(b,n) */\r
+#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s))\r
+/* BIO *BIO_get_filter_bio(BIO *bio); */\r
+#define BIO_set_proxy_cb(b,cb) BIO_callback_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(void *(*cb)()))\r
+#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk)\r
+#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool)\r
+\r
+#define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp)\r
+#define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p))\r
+#define BIO_get_url(b,url)     BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url))\r
+#define BIO_get_no_connect_return(b)   BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL)\r
+\r
+#define BIO_set_fd(b,fd,c)     BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)\r
+#define BIO_get_fd(b,c)                BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)\r
+\r
+#define BIO_set_fp(b,fp,c)     BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp)\r
+#define BIO_get_fp(b,fpp)      BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp)\r
+\r
+#define BIO_seek(b,ofs)        (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL)\r
+#define BIO_tell(b)    (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL)\r
+\r
+/* name is cast to lose const, but might be better to route through a function\r
+   so we can do it safely */\r
+#ifdef CONST_STRICT\r
+/* If you are wondering why this isn't defined, its because CONST_STRICT is\r
+ * purely a compile-time kludge to allow const to be checked.\r
+ */\r
+int BIO_read_filename(BIO *b,const char *name);\r
+#else\r
+#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \\r
+               BIO_CLOSE|BIO_FP_READ,(char *)name)\r
+#endif\r
+#define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \\r
+               BIO_CLOSE|BIO_FP_WRITE,name)\r
+#define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \\r
+               BIO_CLOSE|BIO_FP_APPEND,name)\r
+#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \\r
+               BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name)\r
+\r
+/* WARNING WARNING, this ups the reference count on the read bio of the\r
+ * SSL structure.  This is because the ssl read BIO is now pointed to by\r
+ * the next_bio field in the bio.  So when you free the BIO, make sure\r
+ * you are doing a BIO_free_all() to catch the underlying BIO. */\r
+#define BIO_set_ssl(b,ssl,c)   BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl)\r
+#define BIO_get_ssl(b,sslp)    BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp)\r
+#define BIO_set_ssl_mode(b,client)     BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)\r
+#define BIO_set_ssl_renegotiate_bytes(b,num) \\r
+       BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL);\r
+#define BIO_get_num_renegotiates(b) \\r
+       BIO_ctrl(b,BIO_C_GET_SSL_NUM_RENEGOTIATES,0,NULL);\r
+#define BIO_set_ssl_renegotiate_timeout(b,seconds) \\r
+       BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL);\r
+\r
+/* defined in evp.h */\r
+/* #define BIO_set_md(b,md)    BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */\r
+\r
+#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp)\r
+#define BIO_set_mem_buf(b,bm,c)        BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm)\r
+#define BIO_get_mem_ptr(b,pp)  BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp)\r
+#define BIO_set_mem_eof_return(b,v) \\r
+                               BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL)\r
+\r
+/* For the BIO_f_buffer() type */\r
+#define BIO_get_buffer_num_lines(b)    BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)\r
+#define BIO_set_buffer_size(b,size)    BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)\r
+#define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)\r
+#define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)\r
+#define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)\r
+\r
+/* Don't use the next one unless you know what you are doing :-) */\r
+#define BIO_dup_state(b,ret)   BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret))\r
+\r
+#define BIO_reset(b)           (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL)\r
+#define BIO_eof(b)             (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL)\r
+#define BIO_set_close(b,c)     (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL)\r
+#define BIO_get_close(b)       (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL)\r
+#define BIO_pending(b)         (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL)\r
+#define BIO_wpending(b)                (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL)\r
+/* ...pending macros have inappropriate return type */\r
+size_t BIO_ctrl_pending(BIO *b);\r
+size_t BIO_ctrl_wpending(BIO *b);\r
+#define BIO_flush(b)           (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)\r
+#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0, \\r
+                                                  cbp)\r
+#define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,cb)\r
+\r
+/* For the BIO_f_buffer() type */\r
+#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)\r
+\r
+/* For BIO_s_bio() */\r
+#define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)\r
+#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)\r
+#define BIO_make_bio_pair(b1,b2)   (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)\r
+#define BIO_destroy_bio_pair(b)    (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)\r
+#define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL)\r
+/* macros with inappropriate type -- but ...pending macros use int too: */\r
+#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)\r
+#define BIO_get_read_request(b)    (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)\r
+size_t BIO_ctrl_get_write_guarantee(BIO *b);\r
+size_t BIO_ctrl_get_read_request(BIO *b);\r
+int BIO_ctrl_reset_read_request(BIO *b);\r
+\r
+/* ctrl macros for dgram */\r
+#define BIO_ctrl_dgram_connect(b,peer)  \\r
+                     (int)BIO_ctrl(b,BIO_CTRL_DGRAM_CONNECT,0, (char *)peer)\r
+#define BIO_ctrl_set_connected(b, state, peer) \\r
+         (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_CONNECTED, state, (char *)peer)\r
+#define BIO_dgram_recv_timedout(b) \\r
+         (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL)\r
+#define BIO_dgram_send_timedout(b) \\r
+         (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL)\r
+#define BIO_dgram_set_peer(b,peer) \\r
+         (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)peer)\r
+\r
+/* These two aren't currently implemented */\r
+/* int BIO_get_ex_num(BIO *bio); */\r
+/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */\r
+int BIO_set_ex_data(BIO *bio,int idx,void *data);\r
+void *BIO_get_ex_data(BIO *bio,int idx);\r
+int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,\r
+       CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+unsigned long BIO_number_read(BIO *bio);\r
+unsigned long BIO_number_written(BIO *bio);\r
+\r
+# ifndef OPENSSL_NO_FP_API\r
+#  if defined(OPENSSL_SYS_WIN16) && defined(_WINDLL)\r
+BIO_METHOD *BIO_s_file_internal(void);\r
+BIO *BIO_new_file_internal(char *filename, char *mode);\r
+BIO *BIO_new_fp_internal(FILE *stream, int close_flag);\r
+#    define BIO_s_file BIO_s_file_internal\r
+#    define BIO_new_file       BIO_new_file_internal\r
+#    define BIO_new_fp BIO_new_fp_internal\r
+#  else /* FP_API */\r
+BIO_METHOD *BIO_s_file(void );\r
+BIO *BIO_new_file(const char *filename, const char *mode);\r
+BIO *BIO_new_fp(FILE *stream, int close_flag);\r
+#    define BIO_s_file_internal                BIO_s_file\r
+#    define BIO_new_file_internal      BIO_new_file\r
+#    define BIO_new_fp_internal                BIO_s_file\r
+#  endif /* FP_API */\r
+# endif\r
+BIO *  BIO_new(BIO_METHOD *type);\r
+int    BIO_set(BIO *a,BIO_METHOD *type);\r
+int    BIO_free(BIO *a);\r
+void   BIO_vfree(BIO *a);\r
+int    BIO_read(BIO *b, void *data, int len);\r
+int    BIO_gets(BIO *bp,char *buf, int size);\r
+int    BIO_write(BIO *b, const void *data, int len);\r
+int    BIO_puts(BIO *bp,const char *buf);\r
+int    BIO_indent(BIO *b,int indent,int max);\r
+long   BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);\r
+long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long));\r
+char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);\r
+long   BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);\r
+BIO *  BIO_push(BIO *b,BIO *append);\r
+BIO *  BIO_pop(BIO *b);\r
+void   BIO_free_all(BIO *a);\r
+BIO *  BIO_find_type(BIO *b,int bio_type);\r
+BIO *  BIO_next(BIO *b);\r
+BIO *  BIO_get_retry_BIO(BIO *bio, int *reason);\r
+int    BIO_get_retry_reason(BIO *bio);\r
+BIO *  BIO_dup_chain(BIO *in);\r
+\r
+int BIO_nread0(BIO *bio, char **buf);\r
+int BIO_nread(BIO *bio, char **buf, int num);\r
+int BIO_nwrite0(BIO *bio, char **buf);\r
+int BIO_nwrite(BIO *bio, char **buf, int num);\r
+\r
+#ifndef OPENSSL_SYS_WIN16\r
+long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,\r
+       long argl,long ret);\r
+#else\r
+long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,\r
+       long argl,long ret);\r
+#endif\r
+\r
+BIO_METHOD *BIO_s_mem(void);\r
+BIO *BIO_new_mem_buf(void *buf, int len);\r
+BIO_METHOD *BIO_s_socket(void);\r
+BIO_METHOD *BIO_s_connect(void);\r
+BIO_METHOD *BIO_s_accept(void);\r
+BIO_METHOD *BIO_s_fd(void);\r
+#ifndef OPENSSL_SYS_OS2\r
+BIO_METHOD *BIO_s_log(void);\r
+#endif\r
+BIO_METHOD *BIO_s_bio(void);\r
+BIO_METHOD *BIO_s_null(void);\r
+BIO_METHOD *BIO_f_null(void);\r
+BIO_METHOD *BIO_f_buffer(void);\r
+#ifdef OPENSSL_SYS_VMS\r
+BIO_METHOD *BIO_f_linebuffer(void);\r
+#endif\r
+BIO_METHOD *BIO_f_nbio_test(void);\r
+#ifndef OPENSSL_NO_DGRAM\r
+BIO_METHOD *BIO_s_datagram(void);\r
+#endif\r
+\r
+/* BIO_METHOD *BIO_f_ber(void); */\r
+\r
+int BIO_sock_should_retry(int i);\r
+int BIO_sock_non_fatal_error(int error);\r
+int BIO_dgram_non_fatal_error(int error);\r
+\r
+int BIO_fd_should_retry(int i);\r
+int BIO_fd_non_fatal_error(int error);\r
+int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),\r
+               void *u, const char *s, int len);\r
+int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),\r
+                      void *u, const char *s, int len, int indent);\r
+int BIO_dump(BIO *b,const char *bytes,int len);\r
+int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent);\r
+#ifndef OPENSSL_NO_FP_API\r
+int BIO_dump_fp(FILE *fp, const char *s, int len);\r
+int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent);\r
+#endif\r
+struct hostent *BIO_gethostbyname(const char *name);\r
+/* We might want a thread-safe interface too:\r
+ * struct hostent *BIO_gethostbyname_r(const char *name,\r
+ *     struct hostent *result, void *buffer, size_t buflen);\r
+ * or something similar (caller allocates a struct hostent,\r
+ * pointed to by "result", and additional buffer space for the various\r
+ * substructures; if the buffer does not suffice, NULL is returned\r
+ * and an appropriate error code is set).\r
+ */\r
+int BIO_sock_error(int sock);\r
+int BIO_socket_ioctl(int fd, long type, void *arg);\r
+int BIO_socket_nbio(int fd,int mode);\r
+int BIO_get_port(const char *str, unsigned short *port_ptr);\r
+int BIO_get_host_ip(const char *str, unsigned char *ip);\r
+int BIO_get_accept_socket(char *host_port,int mode);\r
+int BIO_accept(int sock,char **ip_port);\r
+int BIO_sock_init(void );\r
+void BIO_sock_cleanup(void);\r
+int BIO_set_tcp_ndelay(int sock,int turn_on);\r
+\r
+BIO *BIO_new_socket(int sock, int close_flag);\r
+BIO *BIO_new_dgram(int fd, int close_flag);\r
+BIO *BIO_new_fd(int fd, int close_flag);\r
+BIO *BIO_new_connect(char *host_port);\r
+BIO *BIO_new_accept(char *host_port);\r
+\r
+int BIO_new_bio_pair(BIO **bio1, size_t writebuf1,\r
+       BIO **bio2, size_t writebuf2);\r
+/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints.\r
+ * Otherwise returns 0 and sets *bio1 and *bio2 to NULL.\r
+ * Size 0 uses default value.\r
+ */\r
+\r
+void BIO_copy_next_retry(BIO *b);\r
+\r
+/*long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);*/\r
+\r
+#ifndef __GNUC__\r
+#define __attribute__(x)\r
+#endif\r
+int BIO_printf(BIO *bio, const char *format, ...)\r
+       __attribute__((__format__(__printf__,2,3)));\r
+int BIO_vprintf(BIO *bio, const char *format, va_list args)\r
+       __attribute__((__format__(__printf__,2,0)));\r
+int BIO_snprintf(char *buf, size_t n, const char *format, ...)\r
+       __attribute__((__format__(__printf__,3,4)));\r
+int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)\r
+       __attribute__((__format__(__printf__,3,0)));\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_BIO_strings(void);\r
+\r
+/* Error codes for the BIO functions. */\r
+\r
+/* Function codes. */\r
+#define BIO_F_ACPT_STATE                                100\r
+#define BIO_F_BIO_ACCEPT                                101\r
+#define BIO_F_BIO_BER_GET_HEADER                        102\r
+#define BIO_F_BIO_CALLBACK_CTRL                                 131\r
+#define BIO_F_BIO_CTRL                                  103\r
+#define BIO_F_BIO_GETHOSTBYNAME                                 120\r
+#define BIO_F_BIO_GETS                                  104\r
+#define BIO_F_BIO_GET_ACCEPT_SOCKET                     105\r
+#define BIO_F_BIO_GET_HOST_IP                           106\r
+#define BIO_F_BIO_GET_PORT                              107\r
+#define BIO_F_BIO_MAKE_PAIR                             121\r
+#define BIO_F_BIO_NEW                                   108\r
+#define BIO_F_BIO_NEW_FILE                              109\r
+#define BIO_F_BIO_NEW_MEM_BUF                           126\r
+#define BIO_F_BIO_NREAD                                         123\r
+#define BIO_F_BIO_NREAD0                                124\r
+#define BIO_F_BIO_NWRITE                                125\r
+#define BIO_F_BIO_NWRITE0                               122\r
+#define BIO_F_BIO_PUTS                                  110\r
+#define BIO_F_BIO_READ                                  111\r
+#define BIO_F_BIO_SOCK_INIT                             112\r
+#define BIO_F_BIO_WRITE                                         113\r
+#define BIO_F_BUFFER_CTRL                               114\r
+#define BIO_F_CONN_CTRL                                         127\r
+#define BIO_F_CONN_STATE                                115\r
+#define BIO_F_FILE_CTRL                                         116\r
+#define BIO_F_FILE_READ                                         130\r
+#define BIO_F_LINEBUFFER_CTRL                           129\r
+#define BIO_F_MEM_READ                                  128\r
+#define BIO_F_MEM_WRITE                                         117\r
+#define BIO_F_SSL_NEW                                   118\r
+#define BIO_F_WSASTARTUP                                119\r
+\r
+/* Reason codes. */\r
+#define BIO_R_ACCEPT_ERROR                              100\r
+#define BIO_R_BAD_FOPEN_MODE                            101\r
+#define BIO_R_BAD_HOSTNAME_LOOKUP                       102\r
+#define BIO_R_BROKEN_PIPE                               124\r
+#define BIO_R_CONNECT_ERROR                             103\r
+#define BIO_R_EOF_ON_MEMORY_BIO                                 127\r
+#define BIO_R_ERROR_SETTING_NBIO                        104\r
+#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET     105\r
+#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET       106\r
+#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET                 107\r
+#define BIO_R_INVALID_ARGUMENT                          125\r
+#define BIO_R_INVALID_IP_ADDRESS                        108\r
+#define BIO_R_IN_USE                                    123\r
+#define BIO_R_KEEPALIVE                                         109\r
+#define BIO_R_NBIO_CONNECT_ERROR                        110\r
+#define BIO_R_NO_ACCEPT_PORT_SPECIFIED                  111\r
+#define BIO_R_NO_HOSTNAME_SPECIFIED                     112\r
+#define BIO_R_NO_PORT_DEFINED                           113\r
+#define BIO_R_NO_PORT_SPECIFIED                                 114\r
+#define BIO_R_NO_SUCH_FILE                              128\r
+#define BIO_R_NULL_PARAMETER                            115\r
+#define BIO_R_TAG_MISMATCH                              116\r
+#define BIO_R_UNABLE_TO_BIND_SOCKET                     117\r
+#define BIO_R_UNABLE_TO_CREATE_SOCKET                   118\r
+#define BIO_R_UNABLE_TO_LISTEN_SOCKET                   119\r
+#define BIO_R_UNINITIALIZED                             120\r
+#define BIO_R_UNSUPPORTED_METHOD                        121\r
+#define BIO_R_WRITE_TO_READ_ONLY_BIO                    126\r
+#define BIO_R_WSASTARTUP                                122\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/blowfish.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/blowfish.h
new file mode 100644 (file)
index 0000000..ec7b869
--- /dev/null
@@ -0,0 +1,127 @@
+/* crypto/bf/blowfish.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_BLOWFISH_H\r
+#define HEADER_BLOWFISH_H\r
+\r
+#include <openssl/e_os2.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef OPENSSL_NO_BF\r
+#error BF is disabled.\r
+#endif\r
+\r
+#define BF_ENCRYPT     1\r
+#define BF_DECRYPT     0\r
+\r
+/*\r
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r
+ * ! BF_LONG has to be at least 32 bits wide. If it's wider, then !\r
+ * ! BF_LONG_LOG2 has to be defined along.                        !\r
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r
+ */\r
+\r
+#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)\r
+#define BF_LONG unsigned long\r
+#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)\r
+#define BF_LONG unsigned long\r
+#define BF_LONG_LOG2 3\r
+/*\r
+ * _CRAY note. I could declare short, but I have no idea what impact\r
+ * does it have on performance on none-T3E machines. I could declare\r
+ * int, but at least on C90 sizeof(int) can be chosen at compile time.\r
+ * So I've chosen long...\r
+ *                                     <appro@fy.chalmers.se>\r
+ */\r
+#else\r
+#define BF_LONG unsigned int\r
+#endif\r
+\r
+#define BF_ROUNDS      16\r
+#define BF_BLOCK       8\r
+\r
+typedef struct bf_key_st\r
+       {\r
+       BF_LONG P[BF_ROUNDS+2];\r
+       BF_LONG S[4*256];\r
+       } BF_KEY;\r
+\r
\r
+void BF_set_key(BF_KEY *key, int len, const unsigned char *data);\r
+\r
+void BF_encrypt(BF_LONG *data,const BF_KEY *key);\r
+void BF_decrypt(BF_LONG *data,const BF_KEY *key);\r
+\r
+void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,\r
+       const BF_KEY *key, int enc);\r
+void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,\r
+       const BF_KEY *schedule, unsigned char *ivec, int enc);\r
+void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length,\r
+       const BF_KEY *schedule, unsigned char *ivec, int *num, int enc);\r
+void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length,\r
+       const BF_KEY *schedule, unsigned char *ivec, int *num);\r
+const char *BF_options(void);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/bn.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/bn.h
new file mode 100644 (file)
index 0000000..6fa5791
--- /dev/null
@@ -0,0 +1,807 @@
+/* crypto/bn/bn.h */\r
+/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+/* ====================================================================\r
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.\r
+ *\r
+ * Portions of the attached software ("Contribution") are developed by \r
+ * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.\r
+ *\r
+ * The Contribution is licensed pursuant to the Eric Young open source\r
+ * license provided above.\r
+ *\r
+ * The binary polynomial arithmetic software is originally written by \r
+ * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_BN_H\r
+#define HEADER_BN_H\r
+\r
+#include <openssl/e_os2.h>\r
+#ifndef OPENSSL_NO_FP_API\r
+#include <stdio.h> /* FILE */\r
+#endif\r
+#include <openssl/ossl_typ.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* These preprocessor symbols control various aspects of the bignum headers and\r
+ * library code. They're not defined by any "normal" configuration, as they are\r
+ * intended for development and testing purposes. NB: defining all three can be\r
+ * useful for debugging application code as well as openssl itself.\r
+ *\r
+ * BN_DEBUG - turn on various debugging alterations to the bignum code\r
+ * BN_DEBUG_RAND - uses random poisoning of unused words to trip up\r
+ * mismanagement of bignum internals. You must also define BN_DEBUG.\r
+ */\r
+/* #define BN_DEBUG */\r
+/* #define BN_DEBUG_RAND */\r
+\r
+#define BN_MUL_COMBA\r
+#define BN_SQR_COMBA\r
+#define BN_RECURSION\r
+\r
+/* This next option uses the C libraries (2 word)/(1 word) function.\r
+ * If it is not defined, I use my C version (which is slower).\r
+ * The reason for this flag is that when the particular C compiler\r
+ * library routine is used, and the library is linked with a different\r
+ * compiler, the library is missing.  This mostly happens when the\r
+ * library is built with gcc and then linked using normal cc.  This would\r
+ * be a common occurrence because gcc normally produces code that is\r
+ * 2 times faster than system compilers for the big number stuff.\r
+ * For machines with only one compiler (or shared libraries), this should\r
+ * be on.  Again this in only really a problem on machines\r
+ * using "long long's", are 32bit, and are not using my assembler code. */\r
+#if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || \\r
+    defined(OPENSSL_SYS_WIN32) || defined(linux)\r
+# ifndef BN_DIV2W\r
+#  define BN_DIV2W\r
+# endif\r
+#endif\r
+\r
+/* assuming long is 64bit - this is the DEC Alpha\r
+ * unsigned long long is only 64 bits :-(, don't define\r
+ * BN_LLONG for the DEC Alpha */\r
+#ifdef SIXTY_FOUR_BIT_LONG\r
+#define BN_ULLONG      unsigned long long\r
+#define BN_ULONG       unsigned long\r
+#define BN_LONG                long\r
+#define BN_BITS                128\r
+#define BN_BYTES       8\r
+#define BN_BITS2       64\r
+#define BN_BITS4       32\r
+#define BN_MASK                (0xffffffffffffffffffffffffffffffffLL)\r
+#define BN_MASK2       (0xffffffffffffffffL)\r
+#define BN_MASK2l      (0xffffffffL)\r
+#define BN_MASK2h      (0xffffffff00000000L)\r
+#define BN_MASK2h1     (0xffffffff80000000L)\r
+#define BN_TBIT                (0x8000000000000000L)\r
+#define BN_DEC_CONV    (10000000000000000000UL)\r
+#define BN_DEC_FMT1    "%lu"\r
+#define BN_DEC_FMT2    "%019lu"\r
+#define BN_DEC_NUM     19\r
+#endif\r
+\r
+/* This is where the long long data type is 64 bits, but long is 32.\r
+ * For machines where there are 64bit registers, this is the mode to use.\r
+ * IRIX, on R4000 and above should use this mode, along with the relevant\r
+ * assembler code :-).  Do NOT define BN_LLONG.\r
+ */\r
+#ifdef SIXTY_FOUR_BIT\r
+#undef BN_LLONG\r
+#undef BN_ULLONG\r
+#define BN_ULONG       unsigned long long\r
+#define BN_LONG                long long\r
+#define BN_BITS                128\r
+#define BN_BYTES       8\r
+#define BN_BITS2       64\r
+#define BN_BITS4       32\r
+#define BN_MASK2       (0xffffffffffffffffLL)\r
+#define BN_MASK2l      (0xffffffffL)\r
+#define BN_MASK2h      (0xffffffff00000000LL)\r
+#define BN_MASK2h1     (0xffffffff80000000LL)\r
+#define BN_TBIT                (0x8000000000000000LL)\r
+#define BN_DEC_CONV    (10000000000000000000ULL)\r
+#define BN_DEC_FMT1    "%llu"\r
+#define BN_DEC_FMT2    "%019llu"\r
+#define BN_DEC_NUM     19\r
+#endif\r
+\r
+#ifdef THIRTY_TWO_BIT\r
+#ifdef BN_LLONG\r
+# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)\r
+#  define BN_ULLONG    unsigned __int64\r
+# else\r
+#  define BN_ULLONG    unsigned long long\r
+# endif\r
+#endif\r
+#define BN_ULONG       unsigned long\r
+#define BN_LONG                long\r
+#define BN_BITS                64\r
+#define BN_BYTES       4\r
+#define BN_BITS2       32\r
+#define BN_BITS4       16\r
+#ifdef OPENSSL_SYS_WIN32\r
+/* VC++ doesn't like the LL suffix */\r
+#define BN_MASK                (0xffffffffffffffffL)\r
+#else\r
+#define BN_MASK                (0xffffffffffffffffLL)\r
+#endif\r
+#define BN_MASK2       (0xffffffffL)\r
+#define BN_MASK2l      (0xffff)\r
+#define BN_MASK2h1     (0xffff8000L)\r
+#define BN_MASK2h      (0xffff0000L)\r
+#define BN_TBIT                (0x80000000L)\r
+#define BN_DEC_CONV    (1000000000L)\r
+#define BN_DEC_FMT1    "%lu"\r
+#define BN_DEC_FMT2    "%09lu"\r
+#define BN_DEC_NUM     9\r
+#endif\r
+\r
+#ifdef SIXTEEN_BIT\r
+#ifndef BN_DIV2W\r
+#define BN_DIV2W\r
+#endif\r
+#define BN_ULLONG      unsigned long\r
+#define BN_ULONG       unsigned short\r
+#define BN_LONG                short\r
+#define BN_BITS                32\r
+#define BN_BYTES       2\r
+#define BN_BITS2       16\r
+#define BN_BITS4       8\r
+#define BN_MASK                (0xffffffff)\r
+#define BN_MASK2       (0xffff)\r
+#define BN_MASK2l      (0xff)\r
+#define BN_MASK2h1     (0xff80)\r
+#define BN_MASK2h      (0xff00)\r
+#define BN_TBIT                (0x8000)\r
+#define BN_DEC_CONV    (100000)\r
+#define BN_DEC_FMT1    "%u"\r
+#define BN_DEC_FMT2    "%05u"\r
+#define BN_DEC_NUM     5\r
+#endif\r
+\r
+#ifdef EIGHT_BIT\r
+#ifndef BN_DIV2W\r
+#define BN_DIV2W\r
+#endif\r
+#define BN_ULLONG      unsigned short\r
+#define BN_ULONG       unsigned char\r
+#define BN_LONG                char\r
+#define BN_BITS                16\r
+#define BN_BYTES       1\r
+#define BN_BITS2       8\r
+#define BN_BITS4       4\r
+#define BN_MASK                (0xffff)\r
+#define BN_MASK2       (0xff)\r
+#define BN_MASK2l      (0xf)\r
+#define BN_MASK2h1     (0xf8)\r
+#define BN_MASK2h      (0xf0)\r
+#define BN_TBIT                (0x80)\r
+#define BN_DEC_CONV    (100)\r
+#define BN_DEC_FMT1    "%u"\r
+#define BN_DEC_FMT2    "%02u"\r
+#define BN_DEC_NUM     2\r
+#endif\r
+\r
+#define BN_DEFAULT_BITS        1280\r
+\r
+#define BN_FLG_MALLOCED                0x01\r
+#define BN_FLG_STATIC_DATA     0x02\r
+#define BN_FLG_EXP_CONSTTIME   0x04 /* avoid leaking exponent information through timings\r
+                                     * (BN_mod_exp_mont() will call BN_mod_exp_mont_consttime) */\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#define BN_FLG_FREE            0x8000  /* used for debuging */\r
+#endif\r
+#define BN_set_flags(b,n)      ((b)->flags|=(n))\r
+#define BN_get_flags(b,n)      ((b)->flags&(n))\r
+\r
+/* get a clone of a BIGNUM with changed flags, for *temporary* use only\r
+ * (the two BIGNUMs cannot not be used in parallel!) */\r
+#define BN_with_flags(dest,b,n)  ((dest)->d=(b)->d, \\r
+                                  (dest)->top=(b)->top, \\r
+                                  (dest)->dmax=(b)->dmax, \\r
+                                  (dest)->neg=(b)->neg, \\r
+                                  (dest)->flags=(((dest)->flags & BN_FLG_MALLOCED) \\r
+                                                 |  ((b)->flags & ~BN_FLG_MALLOCED) \\r
+                                                 |  BN_FLG_STATIC_DATA \\r
+                                                 |  (n)))\r
+\r
+/* Already declared in ossl_typ.h */\r
+#if 0\r
+typedef struct bignum_st BIGNUM;\r
+/* Used for temp variables (declaration hidden in bn_lcl.h) */\r
+typedef struct bignum_ctx BN_CTX;\r
+typedef struct bn_blinding_st BN_BLINDING;\r
+typedef struct bn_mont_ctx_st BN_MONT_CTX;\r
+typedef struct bn_recp_ctx_st BN_RECP_CTX;\r
+typedef struct bn_gencb_st BN_GENCB;\r
+#endif\r
+\r
+struct bignum_st\r
+       {\r
+       BN_ULONG *d;    /* Pointer to an array of 'BN_BITS2' bit chunks. */\r
+       int top;        /* Index of last used d +1. */\r
+       /* The next are internal book keeping for bn_expand. */\r
+       int dmax;       /* Size of the d array. */\r
+       int neg;        /* one if the number is negative */\r
+       int flags;\r
+       };\r
+\r
+/* Used for montgomery multiplication */\r
+struct bn_mont_ctx_st\r
+       {\r
+       int ri;        /* number of bits in R */\r
+       BIGNUM RR;     /* used to convert to montgomery form */\r
+       BIGNUM N;      /* The modulus */\r
+       BIGNUM Ni;     /* R*(1/R mod N) - N*Ni = 1\r
+                       * (Ni is only stored for bignum algorithm) */\r
+       BN_ULONG n0;   /* least significant word of Ni */\r
+       int flags;\r
+       };\r
+\r
+/* Used for reciprocal division/mod functions\r
+ * It cannot be shared between threads\r
+ */\r
+struct bn_recp_ctx_st\r
+       {\r
+       BIGNUM N;       /* the divisor */\r
+       BIGNUM Nr;      /* the reciprocal */\r
+       int num_bits;\r
+       int shift;\r
+       int flags;\r
+       };\r
+\r
+/* Used for slow "generation" functions. */\r
+struct bn_gencb_st\r
+       {\r
+       unsigned int ver;       /* To handle binary (in)compatibility */\r
+       void *arg;              /* callback-specific data */\r
+       union\r
+               {\r
+               /* if(ver==1) - handles old style callbacks */\r
+               void (*cb_1)(int, int, void *);\r
+               /* if(ver==2) - new callback style */\r
+               int (*cb_2)(int, int, BN_GENCB *);\r
+               } cb;\r
+       };\r
+/* Wrapper function to make using BN_GENCB easier,  */\r
+int BN_GENCB_call(BN_GENCB *cb, int a, int b);\r
+/* Macro to populate a BN_GENCB structure with an "old"-style callback */\r
+#define BN_GENCB_set_old(gencb, callback, cb_arg) { \\r
+               BN_GENCB *tmp_gencb = (gencb); \\r
+               tmp_gencb->ver = 1; \\r
+               tmp_gencb->arg = (cb_arg); \\r
+               tmp_gencb->cb.cb_1 = (callback); }\r
+/* Macro to populate a BN_GENCB structure with a "new"-style callback */\r
+#define BN_GENCB_set(gencb, callback, cb_arg) { \\r
+               BN_GENCB *tmp_gencb = (gencb); \\r
+               tmp_gencb->ver = 2; \\r
+               tmp_gencb->arg = (cb_arg); \\r
+               tmp_gencb->cb.cb_2 = (callback); }\r
+\r
+#define BN_prime_checks 0 /* default: select number of iterations\r
+                            based on the size of the number */\r
+\r
+/* number of Miller-Rabin iterations for an error rate  of less than 2^-80\r
+ * for random 'b'-bit input, b >= 100 (taken from table 4.4 in the Handbook\r
+ * of Applied Cryptography [Menezes, van Oorschot, Vanstone; CRC Press 1996];\r
+ * original paper: Damgaard, Landrock, Pomerance: Average case error estimates\r
+ * for the strong probable prime test. -- Math. Comp. 61 (1993) 177-194) */\r
+#define BN_prime_checks_for_size(b) ((b) >= 1300 ?  2 : \\r
+                                (b) >=  850 ?  3 : \\r
+                                (b) >=  650 ?  4 : \\r
+                                (b) >=  550 ?  5 : \\r
+                                (b) >=  450 ?  6 : \\r
+                                (b) >=  400 ?  7 : \\r
+                                (b) >=  350 ?  8 : \\r
+                                (b) >=  300 ?  9 : \\r
+                                (b) >=  250 ? 12 : \\r
+                                (b) >=  200 ? 15 : \\r
+                                (b) >=  150 ? 18 : \\r
+                                /* b >= 100 */ 27)\r
+\r
+#define BN_num_bytes(a)        ((BN_num_bits(a)+7)/8)\r
+\r
+/* Note that BN_abs_is_word didn't work reliably for w == 0 until 0.9.8 */\r
+#define BN_abs_is_word(a,w) ((((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) || \\r
+                               (((w) == 0) && ((a)->top == 0)))\r
+#define BN_is_zero(a)       ((a)->top == 0)\r
+#define BN_is_one(a)        (BN_abs_is_word((a),1) && !(a)->neg)\r
+#define BN_is_word(a,w)     (BN_abs_is_word((a),(w)) && (!(w) || !(a)->neg))\r
+#define BN_is_odd(a)       (((a)->top > 0) && ((a)->d[0] & 1))\r
+\r
+#define BN_one(a)      (BN_set_word((a),1))\r
+#define BN_zero_ex(a) \\r
+       do { \\r
+               BIGNUM *_tmp_bn = (a); \\r
+               _tmp_bn->top = 0; \\r
+               _tmp_bn->neg = 0; \\r
+       } while(0)\r
+#ifdef OPENSSL_NO_DEPRECATED\r
+#define BN_zero(a)     BN_zero_ex(a)\r
+#else\r
+#define BN_zero(a)     (BN_set_word((a),0))\r
+#endif\r
+\r
+const BIGNUM *BN_value_one(void);\r
+char * BN_options(void);\r
+BN_CTX *BN_CTX_new(void);\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+void   BN_CTX_init(BN_CTX *c);\r
+#endif\r
+void   BN_CTX_free(BN_CTX *c);\r
+void   BN_CTX_start(BN_CTX *ctx);\r
+BIGNUM *BN_CTX_get(BN_CTX *ctx);\r
+void   BN_CTX_end(BN_CTX *ctx);\r
+int     BN_rand(BIGNUM *rnd, int bits, int top,int bottom);\r
+int     BN_pseudo_rand(BIGNUM *rnd, int bits, int top,int bottom);\r
+int    BN_rand_range(BIGNUM *rnd, BIGNUM *range);\r
+int    BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);\r
+int    BN_num_bits(const BIGNUM *a);\r
+int    BN_num_bits_word(BN_ULONG);\r
+BIGNUM *BN_new(void);\r
+void   BN_init(BIGNUM *);\r
+void   BN_clear_free(BIGNUM *a);\r
+BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);\r
+void   BN_swap(BIGNUM *a, BIGNUM *b);\r
+BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret);\r
+int    BN_bn2bin(const BIGNUM *a, unsigned char *to);\r
+BIGNUM *BN_mpi2bn(const unsigned char *s,int len,BIGNUM *ret);\r
+int    BN_bn2mpi(const BIGNUM *a, unsigned char *to);\r
+int    BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);\r
+int    BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);\r
+int    BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);\r
+int    BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);\r
+int    BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);\r
+int    BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx);\r
+/* BN_set_negative(): sets sign of a bignum */\r
+void   BN_set_negative(BIGNUM *b, int n);\r
+/* BN_get_negative():  returns 1 if the bignum is < 0 and 0 otherwise */\r
+#define BN_is_negative(a) ((a)->neg != 0)\r
+\r
+int    BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,\r
+       BN_CTX *ctx);\r
+#define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx))\r
+int    BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);\r
+int    BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);\r
+int    BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m);\r
+int    BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);\r
+int    BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m);\r
+int    BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\r
+       const BIGNUM *m, BN_CTX *ctx);\r
+int    BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);\r
+int    BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);\r
+int    BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m);\r
+int    BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx);\r
+int    BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m);\r
+\r
+BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);\r
+BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);\r
+int    BN_mul_word(BIGNUM *a, BN_ULONG w);\r
+int    BN_add_word(BIGNUM *a, BN_ULONG w);\r
+int    BN_sub_word(BIGNUM *a, BN_ULONG w);\r
+int    BN_set_word(BIGNUM *a, BN_ULONG w);\r
+BN_ULONG BN_get_word(const BIGNUM *a);\r
+\r
+int    BN_cmp(const BIGNUM *a, const BIGNUM *b);\r
+void   BN_free(BIGNUM *a);\r
+int    BN_is_bit_set(const BIGNUM *a, int n);\r
+int    BN_lshift(BIGNUM *r, const BIGNUM *a, int n);\r
+int    BN_lshift1(BIGNUM *r, const BIGNUM *a);\r
+int    BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,BN_CTX *ctx);\r
+\r
+int    BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\r
+       const BIGNUM *m,BN_CTX *ctx);\r
+int    BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\r
+       const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);\r
+int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\r
+       const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont);\r
+int    BN_mod_exp_mont_word(BIGNUM *r, BN_ULONG a, const BIGNUM *p,\r
+       const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);\r
+int    BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, const BIGNUM *p1,\r
+       const BIGNUM *a2, const BIGNUM *p2,const BIGNUM *m,\r
+       BN_CTX *ctx,BN_MONT_CTX *m_ctx);\r
+int    BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\r
+       const BIGNUM *m,BN_CTX *ctx);\r
+\r
+int    BN_mask_bits(BIGNUM *a,int n);\r
+#ifndef OPENSSL_NO_FP_API\r
+int    BN_print_fp(FILE *fp, const BIGNUM *a);\r
+#endif\r
+#ifdef HEADER_BIO_H\r
+int    BN_print(BIO *fp, const BIGNUM *a);\r
+#else\r
+int    BN_print(void *fp, const BIGNUM *a);\r
+#endif\r
+int    BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx);\r
+int    BN_rshift(BIGNUM *r, const BIGNUM *a, int n);\r
+int    BN_rshift1(BIGNUM *r, const BIGNUM *a);\r
+void   BN_clear(BIGNUM *a);\r
+BIGNUM *BN_dup(const BIGNUM *a);\r
+int    BN_ucmp(const BIGNUM *a, const BIGNUM *b);\r
+int    BN_set_bit(BIGNUM *a, int n);\r
+int    BN_clear_bit(BIGNUM *a, int n);\r
+char * BN_bn2hex(const BIGNUM *a);\r
+char * BN_bn2dec(const BIGNUM *a);\r
+int    BN_hex2bn(BIGNUM **a, const char *str);\r
+int    BN_dec2bn(BIGNUM **a, const char *str);\r
+int    BN_gcd(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx);\r
+int    BN_kronecker(const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); /* returns -2 for error */\r
+BIGNUM *BN_mod_inverse(BIGNUM *ret,\r
+       const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);\r
+BIGNUM *BN_mod_sqrt(BIGNUM *ret,\r
+       const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);\r
+\r
+/* Deprecated versions */\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe,\r
+       const BIGNUM *add, const BIGNUM *rem,\r
+       void (*callback)(int,int,void *),void *cb_arg);\r
+int    BN_is_prime(const BIGNUM *p,int nchecks,\r
+       void (*callback)(int,int,void *),\r
+       BN_CTX *ctx,void *cb_arg);\r
+int    BN_is_prime_fasttest(const BIGNUM *p,int nchecks,\r
+       void (*callback)(int,int,void *),BN_CTX *ctx,void *cb_arg,\r
+       int do_trial_division);\r
+#endif /* !defined(OPENSSL_NO_DEPRECATED) */\r
+\r
+/* Newer versions */\r
+int    BN_generate_prime_ex(BIGNUM *ret,int bits,int safe, const BIGNUM *add,\r
+               const BIGNUM *rem, BN_GENCB *cb);\r
+int    BN_is_prime_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx, BN_GENCB *cb);\r
+int    BN_is_prime_fasttest_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx,\r
+               int do_trial_division, BN_GENCB *cb);\r
+\r
+BN_MONT_CTX *BN_MONT_CTX_new(void );\r
+void BN_MONT_CTX_init(BN_MONT_CTX *ctx);\r
+int BN_mod_mul_montgomery(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,\r
+       BN_MONT_CTX *mont, BN_CTX *ctx);\r
+#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\\r
+       (r),(a),&((mont)->RR),(mont),(ctx))\r
+int BN_from_montgomery(BIGNUM *r,const BIGNUM *a,\r
+       BN_MONT_CTX *mont, BN_CTX *ctx);\r
+void BN_MONT_CTX_free(BN_MONT_CTX *mont);\r
+int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *mod,BN_CTX *ctx);\r
+BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from);\r
+BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,\r
+                                       const BIGNUM *mod, BN_CTX *ctx);\r
+\r
+/* BN_BLINDING flags */\r
+#define        BN_BLINDING_NO_UPDATE   0x00000001\r
+#define        BN_BLINDING_NO_RECREATE 0x00000002\r
+\r
+BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod);\r
+void BN_BLINDING_free(BN_BLINDING *b);\r
+int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);\r
+int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);\r
+int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);\r
+int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *);\r
+int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *);\r
+unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *);\r
+void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long);\r
+unsigned long BN_BLINDING_get_flags(const BN_BLINDING *);\r
+void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long);\r
+BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,\r
+       const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,\r
+       int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\r
+                         const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx),\r
+       BN_MONT_CTX *m_ctx);\r
+\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+void BN_set_params(int mul,int high,int low,int mont);\r
+int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */\r
+#endif\r
+\r
+void   BN_RECP_CTX_init(BN_RECP_CTX *recp);\r
+BN_RECP_CTX *BN_RECP_CTX_new(void);\r
+void   BN_RECP_CTX_free(BN_RECP_CTX *recp);\r
+int    BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx);\r
+int    BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,\r
+       BN_RECP_CTX *recp,BN_CTX *ctx);\r
+int    BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\r
+       const BIGNUM *m, BN_CTX *ctx);\r
+int    BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,\r
+       BN_RECP_CTX *recp, BN_CTX *ctx);\r
+\r
+/* Functions for arithmetic over binary polynomials represented by BIGNUMs. \r
+ *\r
+ * The BIGNUM::neg property of BIGNUMs representing binary polynomials is\r
+ * ignored.\r
+ *\r
+ * Note that input arguments are not const so that their bit arrays can\r
+ * be expanded to the appropriate size if needed.\r
+ */\r
+\r
+int    BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); /*r = a + b*/\r
+#define BN_GF2m_sub(r, a, b) BN_GF2m_add(r, a, b)\r
+int    BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p); /*r=a mod p*/\r
+int    BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\r
+       const BIGNUM *p, BN_CTX *ctx); /* r = (a * b) mod p */\r
+int    BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\r
+       BN_CTX *ctx); /* r = (a * a) mod p */\r
+int    BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *b, const BIGNUM *p,\r
+       BN_CTX *ctx); /* r = (1 / b) mod p */\r
+int    BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\r
+       const BIGNUM *p, BN_CTX *ctx); /* r = (a / b) mod p */\r
+int    BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\r
+       const BIGNUM *p, BN_CTX *ctx); /* r = (a ^ b) mod p */\r
+int    BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\r
+       BN_CTX *ctx); /* r = sqrt(a) mod p */\r
+int    BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\r
+       BN_CTX *ctx); /* r^2 + r = a mod p */\r
+#define BN_GF2m_cmp(a, b) BN_ucmp((a), (b))\r
+/* Some functions allow for representation of the irreducible polynomials\r
+ * as an unsigned int[], say p.  The irreducible f(t) is then of the form:\r
+ *     t^p[0] + t^p[1] + ... + t^p[k]\r
+ * where m = p[0] > p[1] > ... > p[k] = 0.\r
+ */\r
+int    BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[]);\r
+       /* r = a mod p */\r
+int    BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\r
+       const unsigned int p[], BN_CTX *ctx); /* r = (a * b) mod p */\r
+int    BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[],\r
+       BN_CTX *ctx); /* r = (a * a) mod p */\r
+int    BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const unsigned int p[],\r
+       BN_CTX *ctx); /* r = (1 / b) mod p */\r
+int    BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\r
+       const unsigned int p[], BN_CTX *ctx); /* r = (a / b) mod p */\r
+int    BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\r
+       const unsigned int p[], BN_CTX *ctx); /* r = (a ^ b) mod p */\r
+int    BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a,\r
+       const unsigned int p[], BN_CTX *ctx); /* r = sqrt(a) mod p */\r
+int    BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a,\r
+       const unsigned int p[], BN_CTX *ctx); /* r^2 + r = a mod p */\r
+int    BN_GF2m_poly2arr(const BIGNUM *a, unsigned int p[], int max);\r
+int    BN_GF2m_arr2poly(const unsigned int p[], BIGNUM *a);\r
+\r
+/* faster mod functions for the 'NIST primes' \r
+ * 0 <= a < p^2 */\r
+int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);\r
+int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);\r
+int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);\r
+int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);\r
+int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);\r
+\r
+const BIGNUM *BN_get0_nist_prime_192(void);\r
+const BIGNUM *BN_get0_nist_prime_224(void);\r
+const BIGNUM *BN_get0_nist_prime_256(void);\r
+const BIGNUM *BN_get0_nist_prime_384(void);\r
+const BIGNUM *BN_get0_nist_prime_521(void);\r
+\r
+/* library internal functions */\r
+\r
+#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\\r
+       (a):bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2))\r
+#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words)))\r
+BIGNUM *bn_expand2(BIGNUM *a, int words);\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */\r
+#endif\r
+\r
+/* Bignum consistency macros\r
+ * There is one "API" macro, bn_fix_top(), for stripping leading zeroes from\r
+ * bignum data after direct manipulations on the data. There is also an\r
+ * "internal" macro, bn_check_top(), for verifying that there are no leading\r
+ * zeroes. Unfortunately, some auditing is required due to the fact that\r
+ * bn_fix_top() has become an overabused duct-tape because bignum data is\r
+ * occasionally passed around in an inconsistent state. So the following\r
+ * changes have been made to sort this out;\r
+ * - bn_fix_top()s implementation has been moved to bn_correct_top()\r
+ * - if BN_DEBUG isn't defined, bn_fix_top() maps to bn_correct_top(), and\r
+ *   bn_check_top() is as before.\r
+ * - if BN_DEBUG *is* defined;\r
+ *   - bn_check_top() tries to pollute unused words even if the bignum 'top' is\r
+ *     consistent. (ed: only if BN_DEBUG_RAND is defined)\r
+ *   - bn_fix_top() maps to bn_check_top() rather than "fixing" anything.\r
+ * The idea is to have debug builds flag up inconsistent bignums when they\r
+ * occur. If that occurs in a bn_fix_top(), we examine the code in question; if\r
+ * the use of bn_fix_top() was appropriate (ie. it follows directly after code\r
+ * that manipulates the bignum) it is converted to bn_correct_top(), and if it\r
+ * was not appropriate, we convert it permanently to bn_check_top() and track\r
+ * down the cause of the bug. Eventually, no internal code should be using the\r
+ * bn_fix_top() macro. External applications and libraries should try this with\r
+ * their own code too, both in terms of building against the openssl headers\r
+ * with BN_DEBUG defined *and* linking with a version of OpenSSL built with it\r
+ * defined. This not only improves external code, it provides more test\r
+ * coverage for openssl's own code.\r
+ */\r
+\r
+#ifdef BN_DEBUG\r
+\r
+/* We only need assert() when debugging */\r
+#include <assert.h>\r
+\r
+#ifdef BN_DEBUG_RAND\r
+/* To avoid "make update" cvs wars due to BN_DEBUG, use some tricks */\r
+#ifndef RAND_pseudo_bytes\r
+int RAND_pseudo_bytes(unsigned char *buf,int num);\r
+#define BN_DEBUG_TRIX\r
+#endif\r
+#define bn_pollute(a) \\r
+       do { \\r
+               const BIGNUM *_bnum1 = (a); \\r
+               if(_bnum1->top < _bnum1->dmax) { \\r
+                       unsigned char _tmp_char; \\r
+                       /* We cast away const without the compiler knowing, any \\r
+                        * *genuinely* constant variables that aren't mutable \\r
+                        * wouldn't be constructed with top!=dmax. */ \\r
+                       BN_ULONG *_not_const; \\r
+                       memcpy(&_not_const, &_bnum1->d, sizeof(BN_ULONG*)); \\r
+                       RAND_pseudo_bytes(&_tmp_char, 1); \\r
+                       memset((unsigned char *)(_not_const + _bnum1->top), _tmp_char, \\r
+                               (_bnum1->dmax - _bnum1->top) * sizeof(BN_ULONG)); \\r
+               } \\r
+       } while(0)\r
+#ifdef BN_DEBUG_TRIX\r
+#undef RAND_pseudo_bytes\r
+#endif\r
+#else\r
+#define bn_pollute(a)\r
+#endif\r
+#define bn_check_top(a) \\r
+       do { \\r
+               const BIGNUM *_bnum2 = (a); \\r
+               assert((_bnum2->top == 0) || \\r
+                               (_bnum2->d[_bnum2->top - 1] != 0)); \\r
+               bn_pollute(_bnum2); \\r
+       } while(0)\r
+\r
+#define bn_fix_top(a)          bn_check_top(a)\r
+\r
+#else /* !BN_DEBUG */\r
+\r
+#define bn_pollute(a)\r
+#define bn_check_top(a)\r
+#define bn_fix_top(a)          bn_correct_top(a)\r
+\r
+#endif\r
+\r
+#define bn_correct_top(a) \\r
+        { \\r
+        BN_ULONG *ftl; \\r
+       if ((a)->top > 0) \\r
+               { \\r
+               for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \\r
+               if (*(ftl--)) break; \\r
+               } \\r
+       bn_pollute(a); \\r
+       }\r
+\r
+BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);\r
+BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);\r
+void     bn_sqr_words(BN_ULONG *rp, const BN_ULONG *ap, int num);\r
+BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);\r
+BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);\r
+BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);\r
+\r
+int BN_bntest_rand(BIGNUM *rnd, int bits, int top,int bottom);\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_BN_strings(void);\r
+\r
+/* Error codes for the BN functions. */\r
+\r
+/* Function codes. */\r
+#define BN_F_BNRAND                                     127\r
+#define BN_F_BN_BLINDING_CONVERT_EX                     100\r
+#define BN_F_BN_BLINDING_CREATE_PARAM                   128\r
+#define BN_F_BN_BLINDING_INVERT_EX                      101\r
+#define BN_F_BN_BLINDING_NEW                            102\r
+#define BN_F_BN_BLINDING_UPDATE                                 103\r
+#define BN_F_BN_BN2DEC                                  104\r
+#define BN_F_BN_BN2HEX                                  105\r
+#define BN_F_BN_CTX_GET                                         116\r
+#define BN_F_BN_CTX_NEW                                         106\r
+#define BN_F_BN_CTX_START                               129\r
+#define BN_F_BN_DIV                                     107\r
+#define BN_F_BN_DIV_RECP                                130\r
+#define BN_F_BN_EXP                                     123\r
+#define BN_F_BN_EXPAND2                                         108\r
+#define BN_F_BN_EXPAND_INTERNAL                                 120\r
+#define BN_F_BN_GF2M_MOD                                131\r
+#define BN_F_BN_GF2M_MOD_EXP                            132\r
+#define BN_F_BN_GF2M_MOD_MUL                            133\r
+#define BN_F_BN_GF2M_MOD_SOLVE_QUAD                     134\r
+#define BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR                         135\r
+#define BN_F_BN_GF2M_MOD_SQR                            136\r
+#define BN_F_BN_GF2M_MOD_SQRT                           137\r
+#define BN_F_BN_MOD_EXP2_MONT                           118\r
+#define BN_F_BN_MOD_EXP_MONT                            109\r
+#define BN_F_BN_MOD_EXP_MONT_CONSTTIME                  124\r
+#define BN_F_BN_MOD_EXP_MONT_WORD                       117\r
+#define BN_F_BN_MOD_EXP_RECP                            125\r
+#define BN_F_BN_MOD_EXP_SIMPLE                          126\r
+#define BN_F_BN_MOD_INVERSE                             110\r
+#define BN_F_BN_MOD_LSHIFT_QUICK                        119\r
+#define BN_F_BN_MOD_MUL_RECIPROCAL                      111\r
+#define BN_F_BN_MOD_SQRT                                121\r
+#define BN_F_BN_MPI2BN                                  112\r
+#define BN_F_BN_NEW                                     113\r
+#define BN_F_BN_RAND                                    114\r
+#define BN_F_BN_RAND_RANGE                              122\r
+#define BN_F_BN_USUB                                    115\r
+\r
+/* Reason codes. */\r
+#define BN_R_ARG2_LT_ARG3                               100\r
+#define BN_R_BAD_RECIPROCAL                             101\r
+#define BN_R_BIGNUM_TOO_LONG                            114\r
+#define BN_R_CALLED_WITH_EVEN_MODULUS                   102\r
+#define BN_R_DIV_BY_ZERO                                103\r
+#define BN_R_ENCODING_ERROR                             104\r
+#define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA               105\r
+#define BN_R_INPUT_NOT_REDUCED                          110\r
+#define BN_R_INVALID_LENGTH                             106\r
+#define BN_R_INVALID_RANGE                              115\r
+#define BN_R_NOT_A_SQUARE                               111\r
+#define BN_R_NOT_INITIALIZED                            107\r
+#define BN_R_NO_INVERSE                                         108\r
+#define BN_R_NO_SOLUTION                                116\r
+#define BN_R_P_IS_NOT_PRIME                             112\r
+#define BN_R_TOO_MANY_ITERATIONS                        113\r
+#define BN_R_TOO_MANY_TEMPORARY_VARIABLES               109\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/buffer.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/buffer.h
new file mode 100644 (file)
index 0000000..e3f394c
--- /dev/null
@@ -0,0 +1,118 @@
+/* crypto/buffer/buffer.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_BUFFER_H\r
+#define HEADER_BUFFER_H\r
+\r
+#include <openssl/ossl_typ.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include <stddef.h>\r
+\r
+#if !defined(NO_SYS_TYPES_H)\r
+#include <sys/types.h>\r
+#endif\r
+\r
+/* Already declared in ossl_typ.h */\r
+/* typedef struct buf_mem_st BUF_MEM; */\r
+\r
+struct buf_mem_st\r
+       {\r
+       int length;     /* current number of bytes */\r
+       char *data;\r
+       int max;        /* size of buffer */\r
+       };\r
+\r
+BUF_MEM *BUF_MEM_new(void);\r
+void   BUF_MEM_free(BUF_MEM *a);\r
+int    BUF_MEM_grow(BUF_MEM *str, int len);\r
+int    BUF_MEM_grow_clean(BUF_MEM *str, int len);\r
+char * BUF_strdup(const char *str);\r
+char * BUF_strndup(const char *str, size_t siz);\r
+void * BUF_memdup(const void *data, size_t siz);\r
+\r
+/* safe string functions */\r
+size_t BUF_strlcpy(char *dst,const char *src,size_t siz);\r
+size_t BUF_strlcat(char *dst,const char *src,size_t siz);\r
+\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_BUF_strings(void);\r
+\r
+/* Error codes for the BUF functions. */\r
+\r
+/* Function codes. */\r
+#define BUF_F_BUF_MEMDUP                                103\r
+#define BUF_F_BUF_MEM_GROW                              100\r
+#define BUF_F_BUF_MEM_GROW_CLEAN                        105\r
+#define BUF_F_BUF_MEM_NEW                               101\r
+#define BUF_F_BUF_STRDUP                                102\r
+#define BUF_F_BUF_STRNDUP                               104\r
+\r
+/* Reason codes. */\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/cast.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/cast.h
new file mode 100644 (file)
index 0000000..6948e64
--- /dev/null
@@ -0,0 +1,105 @@
+/* crypto/cast/cast.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_CAST_H\r
+#define HEADER_CAST_H\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include <openssl/opensslconf.h>\r
+\r
+#ifdef OPENSSL_NO_CAST\r
+#error CAST is disabled.\r
+#endif\r
+\r
+#define CAST_ENCRYPT   1\r
+#define CAST_DECRYPT   0\r
+\r
+#define CAST_LONG unsigned long\r
+\r
+#define CAST_BLOCK     8\r
+#define CAST_KEY_LENGTH        16\r
+\r
+typedef struct cast_key_st\r
+       {\r
+       CAST_LONG data[32];\r
+       int short_key;  /* Use reduced rounds for short key */\r
+       } CAST_KEY;\r
+\r
\r
+void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);\r
+void CAST_ecb_encrypt(const unsigned char *in,unsigned char *out,CAST_KEY *key,\r
+                     int enc);\r
+void CAST_encrypt(CAST_LONG *data,CAST_KEY *key);\r
+void CAST_decrypt(CAST_LONG *data,CAST_KEY *key);\r
+void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,\r
+                     CAST_KEY *ks, unsigned char *iv, int enc);\r
+void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,\r
+                       long length, CAST_KEY *schedule, unsigned char *ivec,\r
+                       int *num, int enc);\r
+void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out, \r
+                       long length, CAST_KEY *schedule, unsigned char *ivec,\r
+                       int *num);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/comp.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/comp.h
new file mode 100644 (file)
index 0000000..9e77ebc
--- /dev/null
@@ -0,0 +1,66 @@
+\r
+#ifndef HEADER_COMP_H\r
+#define HEADER_COMP_H\r
+\r
+#include <openssl/crypto.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct comp_ctx_st COMP_CTX;\r
+\r
+typedef struct comp_method_st\r
+       {\r
+       int type;               /* NID for compression library */\r
+       const char *name;       /* A text string to identify the library */\r
+       int (*init)(COMP_CTX *ctx);\r
+       void (*finish)(COMP_CTX *ctx);\r
+       int (*compress)(COMP_CTX *ctx,\r
+                       unsigned char *out, unsigned int olen,\r
+                       unsigned char *in, unsigned int ilen);\r
+       int (*expand)(COMP_CTX *ctx,\r
+                     unsigned char *out, unsigned int olen,\r
+                     unsigned char *in, unsigned int ilen);\r
+       /* The following two do NOTHING, but are kept for backward compatibility */\r
+       long (*ctrl)(void);\r
+       long (*callback_ctrl)(void);\r
+       } COMP_METHOD;\r
+\r
+struct comp_ctx_st\r
+       {\r
+       COMP_METHOD *meth;\r
+       unsigned long compress_in;\r
+       unsigned long compress_out;\r
+       unsigned long expand_in;\r
+       unsigned long expand_out;\r
+\r
+       CRYPTO_EX_DATA  ex_data;\r
+       };\r
+\r
+\r
+COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);\r
+void COMP_CTX_free(COMP_CTX *ctx);\r
+int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,\r
+       unsigned char *in, int ilen);\r
+int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,\r
+       unsigned char *in, int ilen);\r
+COMP_METHOD *COMP_rle(void );\r
+COMP_METHOD *COMP_zlib(void );\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_COMP_strings(void);\r
+\r
+/* Error codes for the COMP functions. */\r
+\r
+/* Function codes. */\r
+\r
+/* Reason codes. */\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/conf.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/conf.h
new file mode 100644 (file)
index 0000000..bc8f95d
--- /dev/null
@@ -0,0 +1,253 @@
+/* crypto/conf/conf.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef  HEADER_CONF_H\r
+#define HEADER_CONF_H\r
+\r
+#include <openssl/bio.h>\r
+#include <openssl/lhash.h>\r
+#include <openssl/stack.h>\r
+#include <openssl/safestack.h>\r
+#include <openssl/e_os2.h>\r
+\r
+#include <openssl/ossl_typ.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct\r
+       {\r
+       char *section;\r
+       char *name;\r
+       char *value;\r
+       } CONF_VALUE;\r
+\r
+DECLARE_STACK_OF(CONF_VALUE)\r
+DECLARE_STACK_OF(CONF_MODULE)\r
+DECLARE_STACK_OF(CONF_IMODULE)\r
+\r
+struct conf_st;\r
+struct conf_method_st;\r
+typedef struct conf_method_st CONF_METHOD;\r
+\r
+struct conf_method_st\r
+       {\r
+       const char *name;\r
+       CONF *(*create)(CONF_METHOD *meth);\r
+       int (*init)(CONF *conf);\r
+       int (*destroy)(CONF *conf);\r
+       int (*destroy_data)(CONF *conf);\r
+       int (*load_bio)(CONF *conf, BIO *bp, long *eline);\r
+       int (*dump)(const CONF *conf, BIO *bp);\r
+       int (*is_number)(const CONF *conf, char c);\r
+       int (*to_int)(const CONF *conf, char c);\r
+       int (*load)(CONF *conf, const char *name, long *eline);\r
+       };\r
+\r
+/* Module definitions */\r
+\r
+typedef struct conf_imodule_st CONF_IMODULE;\r
+typedef struct conf_module_st CONF_MODULE;\r
+\r
+/* DSO module function typedefs */\r
+typedef int conf_init_func(CONF_IMODULE *md, const CONF *cnf);\r
+typedef void conf_finish_func(CONF_IMODULE *md);\r
+\r
+#define        CONF_MFLAGS_IGNORE_ERRORS       0x1\r
+#define CONF_MFLAGS_IGNORE_RETURN_CODES        0x2\r
+#define CONF_MFLAGS_SILENT             0x4\r
+#define CONF_MFLAGS_NO_DSO             0x8\r
+#define CONF_MFLAGS_IGNORE_MISSING_FILE        0x10\r
+\r
+int CONF_set_default_method(CONF_METHOD *meth);\r
+void CONF_set_nconf(CONF *conf,LHASH *hash);\r
+LHASH *CONF_load(LHASH *conf,const char *file,long *eline);\r
+#ifndef OPENSSL_NO_FP_API\r
+LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline);\r
+#endif\r
+LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline);\r
+STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section);\r
+char *CONF_get_string(LHASH *conf,const char *group,const char *name);\r
+long CONF_get_number(LHASH *conf,const char *group,const char *name);\r
+void CONF_free(LHASH *conf);\r
+int CONF_dump_fp(LHASH *conf, FILE *out);\r
+int CONF_dump_bio(LHASH *conf, BIO *out);\r
+\r
+void OPENSSL_config(const char *config_name);\r
+void OPENSSL_no_config(void);\r
+\r
+/* New conf code.  The semantics are different from the functions above.\r
+   If that wasn't the case, the above functions would have been replaced */\r
+\r
+struct conf_st\r
+       {\r
+       CONF_METHOD *meth;\r
+       void *meth_data;\r
+       LHASH *data;\r
+       };\r
+\r
+CONF *NCONF_new(CONF_METHOD *meth);\r
+CONF_METHOD *NCONF_default(void);\r
+CONF_METHOD *NCONF_WIN32(void);\r
+#if 0 /* Just to give you an idea of what I have in mind */\r
+CONF_METHOD *NCONF_XML(void);\r
+#endif\r
+void NCONF_free(CONF *conf);\r
+void NCONF_free_data(CONF *conf);\r
+\r
+int NCONF_load(CONF *conf,const char *file,long *eline);\r
+#ifndef OPENSSL_NO_FP_API\r
+int NCONF_load_fp(CONF *conf, FILE *fp,long *eline);\r
+#endif\r
+int NCONF_load_bio(CONF *conf, BIO *bp,long *eline);\r
+STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,const char *section);\r
+char *NCONF_get_string(const CONF *conf,const char *group,const char *name);\r
+int NCONF_get_number_e(const CONF *conf,const char *group,const char *name,\r
+                      long *result);\r
+int NCONF_dump_fp(const CONF *conf, FILE *out);\r
+int NCONF_dump_bio(const CONF *conf, BIO *out);\r
+\r
+#if 0 /* The following function has no error checking,\r
+        and should therefore be avoided */\r
+long NCONF_get_number(CONF *conf,char *group,char *name);\r
+#else\r
+#define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r)\r
+#endif\r
+  \r
+/* Module functions */\r
+\r
+int CONF_modules_load(const CONF *cnf, const char *appname,\r
+                     unsigned long flags);\r
+int CONF_modules_load_file(const char *filename, const char *appname,\r
+                          unsigned long flags);\r
+void CONF_modules_unload(int all);\r
+void CONF_modules_finish(void);\r
+void CONF_modules_free(void);\r
+int CONF_module_add(const char *name, conf_init_func *ifunc,\r
+                   conf_finish_func *ffunc);\r
+\r
+const char *CONF_imodule_get_name(const CONF_IMODULE *md);\r
+const char *CONF_imodule_get_value(const CONF_IMODULE *md);\r
+void *CONF_imodule_get_usr_data(const CONF_IMODULE *md);\r
+void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data);\r
+CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md);\r
+unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md);\r
+void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags);\r
+void *CONF_module_get_usr_data(CONF_MODULE *pmod);\r
+void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data);\r
+\r
+char *CONF_get1_default_config_file(void);\r
+\r
+int CONF_parse_list(const char *list, int sep, int nospc,\r
+       int (*list_cb)(const char *elem, int len, void *usr), void *arg);\r
+\r
+void OPENSSL_load_builtin_modules(void);\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_CONF_strings(void);\r
+\r
+/* Error codes for the CONF functions. */\r
+\r
+/* Function codes. */\r
+#define CONF_F_CONF_DUMP_FP                             104\r
+#define CONF_F_CONF_LOAD                                100\r
+#define CONF_F_CONF_LOAD_BIO                            102\r
+#define CONF_F_CONF_LOAD_FP                             103\r
+#define CONF_F_CONF_MODULES_LOAD                        116\r
+#define CONF_F_DEF_LOAD                                         120\r
+#define CONF_F_DEF_LOAD_BIO                             121\r
+#define CONF_F_MODULE_INIT                              115\r
+#define CONF_F_MODULE_LOAD_DSO                          117\r
+#define CONF_F_MODULE_RUN                               118\r
+#define CONF_F_NCONF_DUMP_BIO                           105\r
+#define CONF_F_NCONF_DUMP_FP                            106\r
+#define CONF_F_NCONF_GET_NUMBER                                 107\r
+#define CONF_F_NCONF_GET_NUMBER_E                       112\r
+#define CONF_F_NCONF_GET_SECTION                        108\r
+#define CONF_F_NCONF_GET_STRING                                 109\r
+#define CONF_F_NCONF_LOAD                               113\r
+#define CONF_F_NCONF_LOAD_BIO                           110\r
+#define CONF_F_NCONF_LOAD_FP                            114\r
+#define CONF_F_NCONF_NEW                                111\r
+#define CONF_F_STR_COPY                                         101\r
+\r
+/* Reason codes. */\r
+#define CONF_R_ERROR_LOADING_DSO                        110\r
+#define CONF_R_MISSING_CLOSE_SQUARE_BRACKET             100\r
+#define CONF_R_MISSING_EQUAL_SIGN                       101\r
+#define CONF_R_MISSING_FINISH_FUNCTION                  111\r
+#define CONF_R_MISSING_INIT_FUNCTION                    112\r
+#define CONF_R_MODULE_INITIALIZATION_ERROR              109\r
+#define CONF_R_NO_CLOSE_BRACE                           102\r
+#define CONF_R_NO_CONF                                  105\r
+#define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE          106\r
+#define CONF_R_NO_SECTION                               107\r
+#define CONF_R_NO_SUCH_FILE                             114\r
+#define CONF_R_NO_VALUE                                         108\r
+#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION             103\r
+#define CONF_R_UNKNOWN_MODULE_NAME                      113\r
+#define CONF_R_VARIABLE_HAS_NO_VALUE                    104\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/conf_api.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/conf_api.h
new file mode 100644 (file)
index 0000000..8e7d5d5
--- /dev/null
@@ -0,0 +1,89 @@
+/* conf_api.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef  HEADER_CONF_API_H\r
+#define HEADER_CONF_API_H\r
+\r
+#include <openssl/lhash.h>\r
+#include <openssl/conf.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Up until OpenSSL 0.9.5a, this was new_section */\r
+CONF_VALUE *_CONF_new_section(CONF *conf, const char *section);\r
+/* Up until OpenSSL 0.9.5a, this was get_section */\r
+CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section);\r
+/* Up until OpenSSL 0.9.5a, this was CONF_get_section */\r
+STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf,\r
+                                              const char *section);\r
+\r
+int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value);\r
+char *_CONF_get_string(const CONF *conf, const char *section,\r
+                      const char *name);\r
+long _CONF_get_number(const CONF *conf, const char *section, const char *name);\r
+\r
+int _CONF_new_data(CONF *conf);\r
+void _CONF_free_data(CONF *conf);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/crypto.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/crypto.h
new file mode 100644 (file)
index 0000000..fcba789
--- /dev/null
@@ -0,0 +1,550 @@
+/* crypto/crypto.h */\r
+/* ====================================================================\r
+ * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+/* ====================================================================\r
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.\r
+ * ECDH support in OpenSSL originally developed by \r
+ * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.\r
+ */\r
+\r
+#ifndef HEADER_CRYPTO_H\r
+#define HEADER_CRYPTO_H\r
+\r
+#include <stdlib.h>\r
+\r
+#include <openssl/e_os2.h>\r
+\r
+#ifndef OPENSSL_NO_FP_API\r
+#include <stdio.h>\r
+#endif\r
+\r
+#include <openssl/stack.h>\r
+#include <openssl/safestack.h>\r
+#include <openssl/opensslv.h>\r
+#include <openssl/ossl_typ.h>\r
+\r
+#ifdef CHARSET_EBCDIC\r
+#include <openssl/ebcdic.h>\r
+#endif\r
+\r
+/* Resolve problems on some operating systems with symbol names that clash\r
+   one way or another */\r
+#include <openssl/symhacks.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Backward compatibility to SSLeay */\r
+/* This is more to be used to check the correct DLL is being used\r
+ * in the MS world. */\r
+#define SSLEAY_VERSION_NUMBER  OPENSSL_VERSION_NUMBER\r
+#define SSLEAY_VERSION         0\r
+/* #define SSLEAY_OPTIONS      1 no longer supported */\r
+#define SSLEAY_CFLAGS          2\r
+#define SSLEAY_BUILT_ON                3\r
+#define SSLEAY_PLATFORM                4\r
+#define SSLEAY_DIR             5\r
+\r
+/* Already declared in ossl_typ.h */\r
+#if 0\r
+typedef struct crypto_ex_data_st CRYPTO_EX_DATA;\r
+/* Called when a new object is created */\r
+typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad,\r
+                                       int idx, long argl, void *argp);\r
+/* Called when an object is free()ed */\r
+typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad,\r
+                                       int idx, long argl, void *argp);\r
+/* Called when we need to dup an object */\r
+typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d, \r
+                                       int idx, long argl, void *argp);\r
+#endif\r
+\r
+/* A generic structure to pass assorted data in a expandable way */\r
+typedef struct openssl_item_st\r
+       {\r
+       int code;\r
+       void *value;            /* Not used for flag attributes */\r
+       size_t value_size;      /* Max size of value for output, length for input */\r
+       size_t *value_length;   /* Returned length of value for output */\r
+       } OPENSSL_ITEM;\r
+\r
+\r
+/* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock\r
+ * names in cryptlib.c\r
+ */\r
+\r
+#define        CRYPTO_LOCK_ERR                 1\r
+#define        CRYPTO_LOCK_EX_DATA             2\r
+#define        CRYPTO_LOCK_X509                3\r
+#define        CRYPTO_LOCK_X509_INFO           4\r
+#define        CRYPTO_LOCK_X509_PKEY           5\r
+#define CRYPTO_LOCK_X509_CRL           6\r
+#define CRYPTO_LOCK_X509_REQ           7\r
+#define CRYPTO_LOCK_DSA                        8\r
+#define CRYPTO_LOCK_RSA                        9\r
+#define CRYPTO_LOCK_EVP_PKEY           10\r
+#define CRYPTO_LOCK_X509_STORE         11\r
+#define CRYPTO_LOCK_SSL_CTX            12\r
+#define CRYPTO_LOCK_SSL_CERT           13\r
+#define CRYPTO_LOCK_SSL_SESSION                14\r
+#define CRYPTO_LOCK_SSL_SESS_CERT      15\r
+#define CRYPTO_LOCK_SSL                        16\r
+#define CRYPTO_LOCK_SSL_METHOD         17\r
+#define CRYPTO_LOCK_RAND               18\r
+#define CRYPTO_LOCK_RAND2              19\r
+#define CRYPTO_LOCK_MALLOC             20\r
+#define CRYPTO_LOCK_BIO                        21\r
+#define CRYPTO_LOCK_GETHOSTBYNAME      22\r
+#define CRYPTO_LOCK_GETSERVBYNAME      23\r
+#define CRYPTO_LOCK_READDIR            24\r
+#define CRYPTO_LOCK_RSA_BLINDING       25\r
+#define CRYPTO_LOCK_DH                 26\r
+#define CRYPTO_LOCK_MALLOC2            27\r
+#define CRYPTO_LOCK_DSO                        28\r
+#define CRYPTO_LOCK_DYNLOCK            29\r
+#define CRYPTO_LOCK_ENGINE             30\r
+#define CRYPTO_LOCK_UI                 31\r
+#define CRYPTO_LOCK_ECDSA               32\r
+#define CRYPTO_LOCK_EC                 33\r
+#define CRYPTO_LOCK_ECDH               34\r
+#define CRYPTO_LOCK_BN                 35\r
+#define CRYPTO_LOCK_EC_PRE_COMP                36\r
+#define CRYPTO_LOCK_STORE              37\r
+#define CRYPTO_LOCK_COMP               38\r
+#define CRYPTO_NUM_LOCKS               39\r
+\r
+#define CRYPTO_LOCK            1\r
+#define CRYPTO_UNLOCK          2\r
+#define CRYPTO_READ            4\r
+#define CRYPTO_WRITE           8\r
+\r
+#ifndef OPENSSL_NO_LOCKING\r
+#ifndef CRYPTO_w_lock\r
+#define CRYPTO_w_lock(type)    \\r
+       CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)\r
+#define CRYPTO_w_unlock(type)  \\r
+       CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)\r
+#define CRYPTO_r_lock(type)    \\r
+       CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__)\r
+#define CRYPTO_r_unlock(type)  \\r
+       CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__)\r
+#define CRYPTO_add(addr,amount,type)   \\r
+       CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__)\r
+#endif\r
+#else\r
+#define CRYPTO_w_lock(a)\r
+#define CRYPTO_w_unlock(a)\r
+#define CRYPTO_r_lock(a)\r
+#define CRYPTO_r_unlock(a)\r
+#define CRYPTO_add(a,b,c)      ((*(a))+=(b))\r
+#endif\r
+\r
+/* Some applications as well as some parts of OpenSSL need to allocate\r
+   and deallocate locks in a dynamic fashion.  The following typedef\r
+   makes this possible in a type-safe manner.  */\r
+/* struct CRYPTO_dynlock_value has to be defined by the application. */\r
+typedef struct\r
+       {\r
+       int references;\r
+       struct CRYPTO_dynlock_value *data;\r
+       } CRYPTO_dynlock;\r
+\r
+\r
+/* The following can be used to detect memory leaks in the SSLeay library.\r
+ * It used, it turns on malloc checking */\r
+\r
+#define CRYPTO_MEM_CHECK_OFF   0x0     /* an enume */\r
+#define CRYPTO_MEM_CHECK_ON    0x1     /* a bit */\r
+#define CRYPTO_MEM_CHECK_ENABLE        0x2     /* a bit */\r
+#define CRYPTO_MEM_CHECK_DISABLE 0x3   /* an enume */\r
+\r
+/* The following are bit values to turn on or off options connected to the\r
+ * malloc checking functionality */\r
+\r
+/* Adds time to the memory checking information */\r
+#define V_CRYPTO_MDEBUG_TIME   0x1 /* a bit */\r
+/* Adds thread number to the memory checking information */\r
+#define V_CRYPTO_MDEBUG_THREAD 0x2 /* a bit */\r
+\r
+#define V_CRYPTO_MDEBUG_ALL (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD)\r
+\r
+\r
+/* predec of the BIO type */\r
+typedef struct bio_st BIO_dummy;\r
+\r
+struct crypto_ex_data_st\r
+       {\r
+       STACK *sk;\r
+       int dummy; /* gcc is screwing up this data structure :-( */\r
+       };\r
+\r
+/* This stuff is basically class callback functions\r
+ * The current classes are SSL_CTX, SSL, SSL_SESSION, and a few more */\r
+\r
+typedef struct crypto_ex_data_func_st\r
+       {\r
+       long argl;      /* Arbitary long */\r
+       void *argp;     /* Arbitary void * */\r
+       CRYPTO_EX_new *new_func;\r
+       CRYPTO_EX_free *free_func;\r
+       CRYPTO_EX_dup *dup_func;\r
+       } CRYPTO_EX_DATA_FUNCS;\r
+\r
+DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)\r
+\r
+/* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA\r
+ * entry.\r
+ */\r
+\r
+#define CRYPTO_EX_INDEX_BIO            0\r
+#define CRYPTO_EX_INDEX_SSL            1\r
+#define CRYPTO_EX_INDEX_SSL_CTX                2\r
+#define CRYPTO_EX_INDEX_SSL_SESSION    3\r
+#define CRYPTO_EX_INDEX_X509_STORE     4\r
+#define CRYPTO_EX_INDEX_X509_STORE_CTX 5\r
+#define CRYPTO_EX_INDEX_RSA            6\r
+#define CRYPTO_EX_INDEX_DSA            7\r
+#define CRYPTO_EX_INDEX_DH             8\r
+#define CRYPTO_EX_INDEX_ENGINE         9\r
+#define CRYPTO_EX_INDEX_X509           10\r
+#define CRYPTO_EX_INDEX_UI             11\r
+#define CRYPTO_EX_INDEX_ECDSA          12\r
+#define CRYPTO_EX_INDEX_ECDH           13\r
+#define CRYPTO_EX_INDEX_COMP           14\r
+#define CRYPTO_EX_INDEX_STORE          15\r
+\r
+/* Dynamically assigned indexes start from this value (don't use directly, use\r
+ * via CRYPTO_ex_data_new_class). */\r
+#define CRYPTO_EX_INDEX_USER           100\r
+\r
+\r
+/* This is the default callbacks, but we can have others as well:\r
+ * this is needed in Win32 where the application malloc and the\r
+ * library malloc may not be the same.\r
+ */\r
+#define CRYPTO_malloc_init()   CRYPTO_set_mem_functions(\\r
+       malloc, realloc, free)\r
+\r
+#if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD\r
+# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */\r
+#  define CRYPTO_MDEBUG\r
+# endif\r
+#endif\r
+\r
+/* Set standard debugging functions (not done by default\r
+ * unless CRYPTO_MDEBUG is defined) */\r
+#define CRYPTO_malloc_debug_init()     do {\\r
+       CRYPTO_set_mem_debug_functions(\\r
+               CRYPTO_dbg_malloc,\\r
+               CRYPTO_dbg_realloc,\\r
+               CRYPTO_dbg_free,\\r
+               CRYPTO_dbg_set_options,\\r
+               CRYPTO_dbg_get_options);\\r
+       } while(0)\r
+\r
+int CRYPTO_mem_ctrl(int mode);\r
+int CRYPTO_is_mem_check_on(void);\r
+\r
+/* for applications */\r
+#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)\r
+#define MemCheck_stop()        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)\r
+\r
+/* for library-internal use */\r
+#define MemCheck_on()  CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)\r
+#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)\r
+#define is_MemCheck_on() CRYPTO_is_mem_check_on()\r
+\r
+#define OPENSSL_malloc(num)    CRYPTO_malloc((int)num,__FILE__,__LINE__)\r
+#define OPENSSL_realloc(addr,num) \\r
+       CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__)\r
+#define OPENSSL_realloc_clean(addr,old_num,num) \\r
+       CRYPTO_realloc_clean(addr,old_num,num,__FILE__,__LINE__)\r
+#define OPENSSL_remalloc(addr,num) \\r
+       CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__)\r
+#define OPENSSL_freeFunc       CRYPTO_free\r
+#define OPENSSL_free(addr)     CRYPTO_free(addr)\r
+\r
+#define OPENSSL_malloc_locked(num) \\r
+       CRYPTO_malloc_locked((int)num,__FILE__,__LINE__)\r
+#define OPENSSL_free_locked(addr) CRYPTO_free_locked(addr)\r
+\r
+\r
+const char *SSLeay_version(int type);\r
+unsigned long SSLeay(void);\r
+\r
+int OPENSSL_issetugid(void);\r
+\r
+/* An opaque type representing an implementation of "ex_data" support */\r
+typedef struct st_CRYPTO_EX_DATA_IMPL  CRYPTO_EX_DATA_IMPL;\r
+/* Return an opaque pointer to the current "ex_data" implementation */\r
+const CRYPTO_EX_DATA_IMPL *CRYPTO_get_ex_data_implementation(void);\r
+/* Sets the "ex_data" implementation to be used (if it's not too late) */\r
+int CRYPTO_set_ex_data_implementation(const CRYPTO_EX_DATA_IMPL *i);\r
+/* Get a new "ex_data" class, and return the corresponding "class_index" */\r
+int CRYPTO_ex_data_new_class(void);\r
+/* Within a given class, get/register a new index */\r
+int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp,\r
+               CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,\r
+               CRYPTO_EX_free *free_func);\r
+/* Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a given\r
+ * class (invokes whatever per-class callbacks are applicable) */\r
+int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);\r
+int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,\r
+               CRYPTO_EX_DATA *from);\r
+void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);\r
+/* Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular index\r
+ * (relative to the class type involved) */\r
+int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val);\r
+void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad,int idx);\r
+/* This function cleans up all "ex_data" state. It mustn't be called under\r
+ * potential race-conditions. */\r
+void CRYPTO_cleanup_all_ex_data(void);\r
+\r
+int CRYPTO_get_new_lockid(char *name);\r
+\r
+int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */\r
+void CRYPTO_lock(int mode, int type,const char *file,int line);\r
+void CRYPTO_set_locking_callback(void (*func)(int mode,int type,\r
+                                             const char *file,int line));\r
+void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,\r
+               int line);\r
+void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,\r
+                                             const char *file, int line));\r
+int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,\r
+                                         const char *file,int line);\r
+void CRYPTO_set_id_callback(unsigned long (*func)(void));\r
+unsigned long (*CRYPTO_get_id_callback(void))(void);\r
+unsigned long CRYPTO_thread_id(void);\r
+const char *CRYPTO_get_lock_name(int type);\r
+int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file,\r
+                   int line);\r
+\r
+int CRYPTO_get_new_dynlockid(void);\r
+void CRYPTO_destroy_dynlockid(int i);\r
+struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i);\r
+void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *(*dyn_create_function)(const char *file, int line));\r
+void CRYPTO_set_dynlock_lock_callback(void (*dyn_lock_function)(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line));\r
+void CRYPTO_set_dynlock_destroy_callback(void (*dyn_destroy_function)(struct CRYPTO_dynlock_value *l, const char *file, int line));\r
+struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))(const char *file,int line);\r
+void (*CRYPTO_get_dynlock_lock_callback(void))(int mode, struct CRYPTO_dynlock_value *l, const char *file,int line);\r
+void (*CRYPTO_get_dynlock_destroy_callback(void))(struct CRYPTO_dynlock_value *l, const char *file,int line);\r
+\r
+/* CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions --\r
+ * call the latter last if you need different functions */\r
+int CRYPTO_set_mem_functions(void *(*m)(size_t),void *(*r)(void *,size_t), void (*f)(void *));\r
+int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*free_func)(void *));\r
+int CRYPTO_set_mem_ex_functions(void *(*m)(size_t,const char *,int),\r
+                                void *(*r)(void *,size_t,const char *,int),\r
+                                void (*f)(void *));\r
+int CRYPTO_set_locked_mem_ex_functions(void *(*m)(size_t,const char *,int),\r
+                                       void (*free_func)(void *));\r
+int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int),\r
+                                  void (*r)(void *,void *,int,const char *,int,int),\r
+                                  void (*f)(void *,int),\r
+                                  void (*so)(long),\r
+                                  long (*go)(void));\r
+void CRYPTO_get_mem_functions(void *(**m)(size_t),void *(**r)(void *, size_t), void (**f)(void *));\r
+void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *));\r
+void CRYPTO_get_mem_ex_functions(void *(**m)(size_t,const char *,int),\r
+                                 void *(**r)(void *, size_t,const char *,int),\r
+                                 void (**f)(void *));\r
+void CRYPTO_get_locked_mem_ex_functions(void *(**m)(size_t,const char *,int),\r
+                                        void (**f)(void *));\r
+void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),\r
+                                   void (**r)(void *,void *,int,const char *,int,int),\r
+                                   void (**f)(void *,int),\r
+                                   void (**so)(long),\r
+                                   long (**go)(void));\r
+\r
+void *CRYPTO_malloc_locked(int num, const char *file, int line);\r
+void CRYPTO_free_locked(void *);\r
+void *CRYPTO_malloc(int num, const char *file, int line);\r
+void CRYPTO_free(void *);\r
+void *CRYPTO_realloc(void *addr,int num, const char *file, int line);\r
+void *CRYPTO_realloc_clean(void *addr,int old_num,int num,const char *file,\r
+                          int line);\r
+void *CRYPTO_remalloc(void *addr,int num, const char *file, int line);\r
+\r
+void OPENSSL_cleanse(void *ptr, size_t len);\r
+\r
+void CRYPTO_set_mem_debug_options(long bits);\r
+long CRYPTO_get_mem_debug_options(void);\r
+\r
+#define CRYPTO_push_info(info) \\r
+        CRYPTO_push_info_(info, __FILE__, __LINE__);\r
+int CRYPTO_push_info_(const char *info, const char *file, int line);\r
+int CRYPTO_pop_info(void);\r
+int CRYPTO_remove_all_info(void);\r
+\r
+\r
+/* Default debugging functions (enabled by CRYPTO_malloc_debug_init() macro;\r
+ * used as default in CRYPTO_MDEBUG compilations): */\r
+/* The last argument has the following significance:\r
+ *\r
+ * 0:  called before the actual memory allocation has taken place\r
+ * 1:  called after the actual memory allocation has taken place\r
+ */\r
+void CRYPTO_dbg_malloc(void *addr,int num,const char *file,int line,int before_p);\r
+void CRYPTO_dbg_realloc(void *addr1,void *addr2,int num,const char *file,int line,int before_p);\r
+void CRYPTO_dbg_free(void *addr,int before_p);\r
+/* Tell the debugging code about options.  By default, the following values\r
+ * apply:\r
+ *\r
+ * 0:                           Clear all options.\r
+ * V_CRYPTO_MDEBUG_TIME (1):    Set the "Show Time" option.\r
+ * V_CRYPTO_MDEBUG_THREAD (2):  Set the "Show Thread Number" option.\r
+ * V_CRYPTO_MDEBUG_ALL (3):     1 + 2\r
+ */\r
+void CRYPTO_dbg_set_options(long bits);\r
+long CRYPTO_dbg_get_options(void);\r
+\r
+\r
+#ifndef OPENSSL_NO_FP_API\r
+void CRYPTO_mem_leaks_fp(FILE *);\r
+#endif\r
+void CRYPTO_mem_leaks(struct bio_st *bio);\r
+/* unsigned long order, char *file, int line, int num_bytes, char *addr */\r
+typedef void *CRYPTO_MEM_LEAK_CB(unsigned long, const char *, int, int, void *);\r
+void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb);\r
+\r
+/* die if we have to */\r
+void OpenSSLDie(const char *file,int line,const char *assertion);\r
+#define OPENSSL_assert(e)       (void)((e) ? 0 : (OpenSSLDie(__FILE__, __LINE__, #e),1))\r
+\r
+unsigned long *OPENSSL_ia32cap_loc(void);\r
+#define OPENSSL_ia32cap (*(OPENSSL_ia32cap_loc()))\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_CRYPTO_strings(void);\r
+\r
+/* Error codes for the CRYPTO functions. */\r
+\r
+/* Function codes. */\r
+#define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX                100\r
+#define CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID               103\r
+#define CRYPTO_F_CRYPTO_GET_NEW_LOCKID                  101\r
+#define CRYPTO_F_CRYPTO_SET_EX_DATA                     102\r
+#define CRYPTO_F_DEF_ADD_INDEX                          104\r
+#define CRYPTO_F_DEF_GET_CLASS                          105\r
+#define CRYPTO_F_INT_DUP_EX_DATA                        106\r
+#define CRYPTO_F_INT_FREE_EX_DATA                       107\r
+#define CRYPTO_F_INT_NEW_EX_DATA                        108\r
+\r
+/* Reason codes. */\r
+#define CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK             100\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/des.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/des.h
new file mode 100644 (file)
index 0000000..5ed8747
--- /dev/null
@@ -0,0 +1,244 @@
+/* crypto/des/des.h */\r
+/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_NEW_DES_H\r
+#define HEADER_NEW_DES_H\r
+\r
+#include <openssl/e_os2.h>     /* OPENSSL_EXTERN, OPENSSL_NO_DES,\r
+                                  DES_LONG (via openssl/opensslconf.h */\r
+\r
+#ifdef OPENSSL_NO_DES\r
+#error DES is disabled.\r
+#endif\r
+\r
+#ifdef OPENSSL_BUILD_SHLIBCRYPTO\r
+# undef OPENSSL_EXTERN\r
+# define OPENSSL_EXTERN OPENSSL_EXPORT\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef unsigned char DES_cblock[8];\r
+typedef /* const */ unsigned char const_DES_cblock[8];\r
+/* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock *\r
+ * and const_DES_cblock * are incompatible pointer types. */\r
+\r
+typedef struct DES_ks\r
+    {\r
+    union\r
+       {\r
+       DES_cblock cblock;\r
+       /* make sure things are correct size on machines with\r
+        * 8 byte longs */\r
+       DES_LONG deslong[2];\r
+       } ks[16];\r
+    } DES_key_schedule;\r
+\r
+#ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT\r
+# ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT\r
+#  define OPENSSL_ENABLE_OLD_DES_SUPPORT\r
+# endif\r
+#endif\r
+\r
+#ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT\r
+# include <openssl/des_old.h>\r
+#endif\r
+\r
+#define DES_KEY_SZ     (sizeof(DES_cblock))\r
+#define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))\r
+\r
+#define DES_ENCRYPT    1\r
+#define DES_DECRYPT    0\r
+\r
+#define DES_CBC_MODE   0\r
+#define DES_PCBC_MODE  1\r
+\r
+#define DES_ecb2_encrypt(i,o,k1,k2,e) \\r
+       DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))\r
+\r
+#define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \\r
+       DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))\r
+\r
+#define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \\r
+       DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))\r
+\r
+#define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \\r
+       DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))\r
+\r
+OPENSSL_DECLARE_GLOBAL(int,DES_check_key);     /* defaults to false */\r
+#define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key)\r
+OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode);       /* defaults to DES_PCBC_MODE */\r
+#define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode)\r
+\r
+const char *DES_options(void);\r
+void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,\r
+                     DES_key_schedule *ks1,DES_key_schedule *ks2,\r
+                     DES_key_schedule *ks3, int enc);\r
+DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output,\r
+                      long length,DES_key_schedule *schedule,\r
+                      const_DES_cblock *ivec);\r
+/* DES_cbc_encrypt does not update the IV!  Use DES_ncbc_encrypt instead. */\r
+void DES_cbc_encrypt(const unsigned char *input,unsigned char *output,\r
+                    long length,DES_key_schedule *schedule,DES_cblock *ivec,\r
+                    int enc);\r
+void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output,\r
+                     long length,DES_key_schedule *schedule,DES_cblock *ivec,\r
+                     int enc);\r
+void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output,\r
+                     long length,DES_key_schedule *schedule,DES_cblock *ivec,\r
+                     const_DES_cblock *inw,const_DES_cblock *outw,int enc);\r
+void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,\r
+                    long length,DES_key_schedule *schedule,DES_cblock *ivec,\r
+                    int enc);\r
+void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output,\r
+                    DES_key_schedule *ks,int enc);\r
+\r
+/*     This is the DES encryption function that gets called by just about\r
+       every other DES routine in the library.  You should not use this\r
+       function except to implement 'modes' of DES.  I say this because the\r
+       functions that call this routine do the conversion from 'char *' to\r
+       long, and this needs to be done to make sure 'non-aligned' memory\r
+       access do not occur.  The characters are loaded 'little endian'.\r
+       Data is a pointer to 2 unsigned long's and ks is the\r
+       DES_key_schedule to use.  enc, is non zero specifies encryption,\r
+       zero if decryption. */\r
+void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc);\r
+\r
+/*     This functions is the same as DES_encrypt1() except that the DES\r
+       initial permutation (IP) and final permutation (FP) have been left\r
+       out.  As for DES_encrypt1(), you should not use this function.\r
+       It is used by the routines in the library that implement triple DES.\r
+       IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same\r
+       as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */\r
+void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc);\r
+\r
+void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,\r
+                 DES_key_schedule *ks2, DES_key_schedule *ks3);\r
+void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,\r
+                 DES_key_schedule *ks2, DES_key_schedule *ks3);\r
+void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output, \r
+                         long length,\r
+                         DES_key_schedule *ks1,DES_key_schedule *ks2,\r
+                         DES_key_schedule *ks3,DES_cblock *ivec,int enc);\r
+void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,\r
+                          long length,\r
+                          DES_key_schedule *ks1,DES_key_schedule *ks2,\r
+                          DES_key_schedule *ks3,\r
+                          DES_cblock *ivec1,DES_cblock *ivec2,\r
+                          int enc);\r
+void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,\r
+                           long length,DES_key_schedule *ks1,\r
+                           DES_key_schedule *ks2,DES_key_schedule *ks3,\r
+                           DES_cblock *ivec,int *num,int enc);\r
+void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,\r
+                         int numbits,long length,DES_key_schedule *ks1,\r
+                         DES_key_schedule *ks2,DES_key_schedule *ks3,\r
+                         DES_cblock *ivec,int enc);\r
+void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,\r
+                           long length,DES_key_schedule *ks1,\r
+                           DES_key_schedule *ks2,DES_key_schedule *ks3,\r
+                           DES_cblock *ivec,int *num);\r
+\r
+void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white,\r
+                      DES_cblock *out_white);\r
+\r
+int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched,\r
+                DES_cblock *iv);\r
+int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched,\r
+                 DES_cblock *iv);\r
+char *DES_fcrypt(const char *buf,const char *salt, char *ret);\r
+char *DES_crypt(const char *buf,const char *salt);\r
+void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,\r
+                    long length,DES_key_schedule *schedule,DES_cblock *ivec);\r
+void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output,\r
+                     long length,DES_key_schedule *schedule,DES_cblock *ivec,\r
+                     int enc);\r
+DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[],\r
+                       long length,int out_count,DES_cblock *seed);\r
+int DES_random_key(DES_cblock *ret);\r
+void DES_set_odd_parity(DES_cblock *key);\r
+int DES_check_key_parity(const_DES_cblock *key);\r
+int DES_is_weak_key(const_DES_cblock *key);\r
+/* DES_set_key (= set_key = DES_key_sched = key_sched) calls\r
+ * DES_set_key_checked if global variable DES_check_key is set,\r
+ * DES_set_key_unchecked otherwise. */\r
+int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule);\r
+int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule);\r
+int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule);\r
+void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule);\r
+void DES_string_to_key(const char *str,DES_cblock *key);\r
+void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2);\r
+void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,\r
+                      DES_key_schedule *schedule,DES_cblock *ivec,int *num,\r
+                      int enc);\r
+void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,\r
+                      DES_key_schedule *schedule,DES_cblock *ivec,int *num);\r
+\r
+int DES_read_password(DES_cblock *key, const char *prompt, int verify);\r
+int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,\r
+       int verify);\r
+\r
+#define DES_fixup_key_parity DES_set_odd_parity\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/des_old.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/des_old.h
new file mode 100644 (file)
index 0000000..fe64961
--- /dev/null
@@ -0,0 +1,441 @@
+/* crypto/des/des_old.h -*- mode:C; c-file-style: "eay" -*- */\r
+\r
+/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING\r
+ *\r
+ * The function names in here are deprecated and are only present to\r
+ * provide an interface compatible with openssl 0.9.6 and older as\r
+ * well as libdes.  OpenSSL now provides functions where "des_" has\r
+ * been replaced with "DES_" in the names, to make it possible to\r
+ * make incompatible changes that are needed for C type security and\r
+ * other stuff.\r
+ *\r
+ * This include files has two compatibility modes:\r
+ *\r
+ *   - If OPENSSL_DES_LIBDES_COMPATIBILITY is defined, you get an API\r
+ *     that is compatible with libdes and SSLeay.\r
+ *   - If OPENSSL_DES_LIBDES_COMPATIBILITY isn't defined, you get an\r
+ *     API that is compatible with OpenSSL 0.9.5x to 0.9.6x.\r
+ *\r
+ * Note that these modes break earlier snapshots of OpenSSL, where\r
+ * libdes compatibility was the only available mode or (later on) the\r
+ * prefered compatibility mode.  However, after much consideration\r
+ * (and more or less violent discussions with external parties), it\r
+ * was concluded that OpenSSL should be compatible with earlier versions\r
+ * of itself before anything else.  Also, in all honesty, libdes is\r
+ * an old beast that shouldn't really be used any more.\r
+ *\r
+ * Please consider starting to use the DES_ functions rather than the\r
+ * des_ ones.  The des_ functions will disappear completely before\r
+ * OpenSSL 1.0!\r
+ *\r
+ * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING\r
+ */\r
+\r
+/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL\r
+ * project 2001.\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_DES_H\r
+#define HEADER_DES_H\r
+\r
+#include <openssl/e_os2.h>     /* OPENSSL_EXTERN, OPENSSL_NO_DES, DES_LONG */\r
+\r
+#ifdef OPENSSL_NO_DES\r
+#error DES is disabled.\r
+#endif\r
+\r
+#ifndef HEADER_NEW_DES_H\r
+#error You must include des.h, not des_old.h directly.\r
+#endif\r
+\r
+#ifdef _KERBEROS_DES_H\r
+#error <openssl/des_old.h> replaces <kerberos/des.h>.\r
+#endif\r
+\r
+#include <openssl/symhacks.h>\r
+\r
+#ifdef OPENSSL_BUILD_SHLIBCRYPTO\r
+# undef OPENSSL_EXTERN\r
+# define OPENSSL_EXTERN OPENSSL_EXPORT\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef unsigned char _ossl_old_des_cblock[8];\r
+typedef struct _ossl_old_des_ks_struct\r
+       {\r
+       union   {\r
+               _ossl_old_des_cblock _;\r
+               /* make sure things are correct size on machines with\r
+                * 8 byte longs */\r
+               DES_LONG pad[2];\r
+               } ks;\r
+       } _ossl_old_des_key_schedule[16];\r
+\r
+#ifndef OPENSSL_DES_LIBDES_COMPATIBILITY\r
+#define des_cblock DES_cblock\r
+#define const_des_cblock const_DES_cblock\r
+#define des_key_schedule DES_key_schedule\r
+#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\\r
+       DES_ecb3_encrypt((i),(o),&(k1),&(k2),&(k3),(e))\r
+#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\\r
+       DES_ede3_cbc_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(e))\r
+#define des_ede3_cbcm_encrypt(i,o,l,k1,k2,k3,iv1,iv2,e)\\r
+       DES_ede3_cbcm_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv1),(iv2),(e))\r
+#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\\r
+       DES_ede3_cfb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n),(e))\r
+#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\\r
+       DES_ede3_ofb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n))\r
+#define des_options()\\r
+       DES_options()\r
+#define des_cbc_cksum(i,o,l,k,iv)\\r
+       DES_cbc_cksum((i),(o),(l),&(k),(iv))\r
+#define des_cbc_encrypt(i,o,l,k,iv,e)\\r
+       DES_cbc_encrypt((i),(o),(l),&(k),(iv),(e))\r
+#define des_ncbc_encrypt(i,o,l,k,iv,e)\\r
+       DES_ncbc_encrypt((i),(o),(l),&(k),(iv),(e))\r
+#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\\r
+       DES_xcbc_encrypt((i),(o),(l),&(k),(iv),(inw),(outw),(e))\r
+#define des_cfb_encrypt(i,o,n,l,k,iv,e)\\r
+       DES_cfb_encrypt((i),(o),(n),(l),&(k),(iv),(e))\r
+#define des_ecb_encrypt(i,o,k,e)\\r
+       DES_ecb_encrypt((i),(o),&(k),(e))\r
+#define des_encrypt1(d,k,e)\\r
+       DES_encrypt1((d),&(k),(e))\r
+#define des_encrypt2(d,k,e)\\r
+       DES_encrypt2((d),&(k),(e))\r
+#define des_encrypt3(d,k1,k2,k3)\\r
+       DES_encrypt3((d),&(k1),&(k2),&(k3))\r
+#define des_decrypt3(d,k1,k2,k3)\\r
+       DES_decrypt3((d),&(k1),&(k2),&(k3))\r
+#define des_xwhite_in2out(k,i,o)\\r
+       DES_xwhite_in2out((k),(i),(o))\r
+#define des_enc_read(f,b,l,k,iv)\\r
+       DES_enc_read((f),(b),(l),&(k),(iv))\r
+#define des_enc_write(f,b,l,k,iv)\\r
+       DES_enc_write((f),(b),(l),&(k),(iv))\r
+#define des_fcrypt(b,s,r)\\r
+       DES_fcrypt((b),(s),(r))\r
+#if 0\r
+#define des_crypt(b,s)\\r
+       DES_crypt((b),(s))\r
+#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT) && !defined(__OpenBSD__)\r
+#define crypt(b,s)\\r
+       DES_crypt((b),(s))\r
+#endif\r
+#endif\r
+#define des_ofb_encrypt(i,o,n,l,k,iv)\\r
+       DES_ofb_encrypt((i),(o),(n),(l),&(k),(iv))\r
+#define des_pcbc_encrypt(i,o,l,k,iv,e)\\r
+       DES_pcbc_encrypt((i),(o),(l),&(k),(iv),(e))\r
+#define des_quad_cksum(i,o,l,c,s)\\r
+       DES_quad_cksum((i),(o),(l),(c),(s))\r
+#define des_random_seed(k)\\r
+       _ossl_096_des_random_seed((k))\r
+#define des_random_key(r)\\r
+       DES_random_key((r))\r
+#define des_read_password(k,p,v) \\r
+       DES_read_password((k),(p),(v))\r
+#define des_read_2passwords(k1,k2,p,v) \\r
+       DES_read_2passwords((k1),(k2),(p),(v))\r
+#define des_set_odd_parity(k)\\r
+       DES_set_odd_parity((k))\r
+#define des_check_key_parity(k)\\r
+       DES_check_key_parity((k))\r
+#define des_is_weak_key(k)\\r
+       DES_is_weak_key((k))\r
+#define des_set_key(k,ks)\\r
+       DES_set_key((k),&(ks))\r
+#define des_key_sched(k,ks)\\r
+       DES_key_sched((k),&(ks))\r
+#define des_set_key_checked(k,ks)\\r
+       DES_set_key_checked((k),&(ks))\r
+#define des_set_key_unchecked(k,ks)\\r
+       DES_set_key_unchecked((k),&(ks))\r
+#define des_string_to_key(s,k)\\r
+       DES_string_to_key((s),(k))\r
+#define des_string_to_2keys(s,k1,k2)\\r
+       DES_string_to_2keys((s),(k1),(k2))\r
+#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\\r
+       DES_cfb64_encrypt((i),(o),(l),&(ks),(iv),(n),(e))\r
+#define des_ofb64_encrypt(i,o,l,ks,iv,n)\\r
+       DES_ofb64_encrypt((i),(o),(l),&(ks),(iv),(n))\r
+               \r
+\r
+#define des_ecb2_encrypt(i,o,k1,k2,e) \\r
+       des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))\r
+\r
+#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \\r
+       des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))\r
+\r
+#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \\r
+       des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))\r
+\r
+#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \\r
+       des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))\r
+\r
+#define des_check_key DES_check_key\r
+#define des_rw_mode DES_rw_mode\r
+#else /* libdes compatibility */\r
+/* Map all symbol names to _ossl_old_des_* form, so we avoid all\r
+   clashes with libdes */\r
+#define des_cblock _ossl_old_des_cblock\r
+#define des_key_schedule _ossl_old_des_key_schedule\r
+#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\\r
+       _ossl_old_des_ecb3_encrypt((i),(o),(k1),(k2),(k3),(e))\r
+#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\\r
+       _ossl_old_des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e))\r
+#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\\r
+       _ossl_old_des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n),(e))\r
+#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\\r
+       _ossl_old_des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n))\r
+#define des_options()\\r
+       _ossl_old_des_options()\r
+#define des_cbc_cksum(i,o,l,k,iv)\\r
+       _ossl_old_des_cbc_cksum((i),(o),(l),(k),(iv))\r
+#define des_cbc_encrypt(i,o,l,k,iv,e)\\r
+       _ossl_old_des_cbc_encrypt((i),(o),(l),(k),(iv),(e))\r
+#define des_ncbc_encrypt(i,o,l,k,iv,e)\\r
+       _ossl_old_des_ncbc_encrypt((i),(o),(l),(k),(iv),(e))\r
+#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\\r
+       _ossl_old_des_xcbc_encrypt((i),(o),(l),(k),(iv),(inw),(outw),(e))\r
+#define des_cfb_encrypt(i,o,n,l,k,iv,e)\\r
+       _ossl_old_des_cfb_encrypt((i),(o),(n),(l),(k),(iv),(e))\r
+#define des_ecb_encrypt(i,o,k,e)\\r
+       _ossl_old_des_ecb_encrypt((i),(o),(k),(e))\r
+#define des_encrypt(d,k,e)\\r
+       _ossl_old_des_encrypt((d),(k),(e))\r
+#define des_encrypt2(d,k,e)\\r
+       _ossl_old_des_encrypt2((d),(k),(e))\r
+#define des_encrypt3(d,k1,k2,k3)\\r
+       _ossl_old_des_encrypt3((d),(k1),(k2),(k3))\r
+#define des_decrypt3(d,k1,k2,k3)\\r
+       _ossl_old_des_decrypt3((d),(k1),(k2),(k3))\r
+#define des_xwhite_in2out(k,i,o)\\r
+       _ossl_old_des_xwhite_in2out((k),(i),(o))\r
+#define des_enc_read(f,b,l,k,iv)\\r
+       _ossl_old_des_enc_read((f),(b),(l),(k),(iv))\r
+#define des_enc_write(f,b,l,k,iv)\\r
+       _ossl_old_des_enc_write((f),(b),(l),(k),(iv))\r
+#define des_fcrypt(b,s,r)\\r
+       _ossl_old_des_fcrypt((b),(s),(r))\r
+#define des_crypt(b,s)\\r
+       _ossl_old_des_crypt((b),(s))\r
+#if 0\r
+#define crypt(b,s)\\r
+       _ossl_old_crypt((b),(s))\r
+#endif\r
+#define des_ofb_encrypt(i,o,n,l,k,iv)\\r
+       _ossl_old_des_ofb_encrypt((i),(o),(n),(l),(k),(iv))\r
+#define des_pcbc_encrypt(i,o,l,k,iv,e)\\r
+       _ossl_old_des_pcbc_encrypt((i),(o),(l),(k),(iv),(e))\r
+#define des_quad_cksum(i,o,l,c,s)\\r
+       _ossl_old_des_quad_cksum((i),(o),(l),(c),(s))\r
+#define des_random_seed(k)\\r
+       _ossl_old_des_random_seed((k))\r
+#define des_random_key(r)\\r
+       _ossl_old_des_random_key((r))\r
+#define des_read_password(k,p,v) \\r
+       _ossl_old_des_read_password((k),(p),(v))\r
+#define des_read_2passwords(k1,k2,p,v) \\r
+       _ossl_old_des_read_2passwords((k1),(k2),(p),(v))\r
+#define des_set_odd_parity(k)\\r
+       _ossl_old_des_set_odd_parity((k))\r
+#define des_is_weak_key(k)\\r
+       _ossl_old_des_is_weak_key((k))\r
+#define des_set_key(k,ks)\\r
+       _ossl_old_des_set_key((k),(ks))\r
+#define des_key_sched(k,ks)\\r
+       _ossl_old_des_key_sched((k),(ks))\r
+#define des_string_to_key(s,k)\\r
+       _ossl_old_des_string_to_key((s),(k))\r
+#define des_string_to_2keys(s,k1,k2)\\r
+       _ossl_old_des_string_to_2keys((s),(k1),(k2))\r
+#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\\r
+       _ossl_old_des_cfb64_encrypt((i),(o),(l),(ks),(iv),(n),(e))\r
+#define des_ofb64_encrypt(i,o,l,ks,iv,n)\\r
+       _ossl_old_des_ofb64_encrypt((i),(o),(l),(ks),(iv),(n))\r
+               \r
+\r
+#define des_ecb2_encrypt(i,o,k1,k2,e) \\r
+       des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))\r
+\r
+#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \\r
+       des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))\r
+\r
+#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \\r
+       des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))\r
+\r
+#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \\r
+       des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))\r
+\r
+#define des_check_key DES_check_key\r
+#define des_rw_mode DES_rw_mode\r
+#endif\r
+\r
+const char *_ossl_old_des_options(void);\r
+void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,\r
+       _ossl_old_des_key_schedule ks1,_ossl_old_des_key_schedule ks2,\r
+       _ossl_old_des_key_schedule ks3, int enc);\r
+DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,\r
+       long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);\r
+void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,\r
+       _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);\r
+void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,\r
+       _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);\r
+void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,\r
+       _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,\r
+       _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc);\r
+void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,\r
+       long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);\r
+void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,\r
+       _ossl_old_des_key_schedule ks,int enc);\r
+void _ossl_old_des_encrypt(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);\r
+void _ossl_old_des_encrypt2(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);\r
+void _ossl_old_des_encrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,\r
+       _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);\r
+void _ossl_old_des_decrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,\r
+       _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);\r
+void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output, \r
+       long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2, \r
+       _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc);\r
+void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,\r
+       long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,\r
+       _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc);\r
+void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,\r
+       long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,\r
+       _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num);\r
+\r
+void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),\r
+       _ossl_old_des_cblock (*out_white));\r
+\r
+int _ossl_old_des_enc_read(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,\r
+       _ossl_old_des_cblock *iv);\r
+int _ossl_old_des_enc_write(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,\r
+       _ossl_old_des_cblock *iv);\r
+char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret);\r
+char *_ossl_old_des_crypt(const char *buf,const char *salt);\r
+#if !defined(PERL5) && !defined(NeXT)\r
+char *_ossl_old_crypt(const char *buf,const char *salt);\r
+#endif\r
+void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,\r
+       int numbits,long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);\r
+void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,\r
+       _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);\r
+DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,\r
+       long length,int out_count,_ossl_old_des_cblock *seed);\r
+void _ossl_old_des_random_seed(_ossl_old_des_cblock key);\r
+void _ossl_old_des_random_key(_ossl_old_des_cblock ret);\r
+int _ossl_old_des_read_password(_ossl_old_des_cblock *key,const char *prompt,int verify);\r
+int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2,\r
+       const char *prompt,int verify);\r
+void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key);\r
+int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key);\r
+int _ossl_old_des_set_key(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);\r
+int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);\r
+void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key);\r
+void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2);\r
+void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,\r
+       _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc);\r
+void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,\r
+       _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num);\r
+\r
+void _ossl_096_des_random_seed(des_cblock *key);\r
+\r
+/* The following definitions provide compatibility with the MIT Kerberos\r
+ * library. The _ossl_old_des_key_schedule structure is not binary compatible. */\r
+\r
+#define _KERBEROS_DES_H\r
+\r
+#define KRBDES_ENCRYPT DES_ENCRYPT\r
+#define KRBDES_DECRYPT DES_DECRYPT\r
+\r
+#ifdef KERBEROS\r
+#  define ENCRYPT DES_ENCRYPT\r
+#  define DECRYPT DES_DECRYPT\r
+#endif\r
+\r
+#ifndef NCOMPAT\r
+#  define C_Block des_cblock\r
+#  define Key_schedule des_key_schedule\r
+#  define KEY_SZ DES_KEY_SZ\r
+#  define string_to_key des_string_to_key\r
+#  define read_pw_string des_read_pw_string\r
+#  define random_key des_random_key\r
+#  define pcbc_encrypt des_pcbc_encrypt\r
+#  define set_key des_set_key\r
+#  define key_sched des_key_sched\r
+#  define ecb_encrypt des_ecb_encrypt\r
+#  define cbc_encrypt des_cbc_encrypt\r
+#  define ncbc_encrypt des_ncbc_encrypt\r
+#  define xcbc_encrypt des_xcbc_encrypt\r
+#  define cbc_cksum des_cbc_cksum\r
+#  define quad_cksum des_quad_cksum\r
+#  define check_parity des_check_key_parity\r
+#endif\r
+\r
+#define des_fixup_key_parity DES_fixup_key_parity\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+/* for DES_read_pw_string et al */\r
+#include <openssl/ui_compat.h>\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/dh.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/dh.h
new file mode 100644 (file)
index 0000000..ab9955f
--- /dev/null
@@ -0,0 +1,223 @@
+/* crypto/dh/dh.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_DH_H\r
+#define HEADER_DH_H\r
+\r
+#include <openssl/e_os2.h>\r
+\r
+#ifdef OPENSSL_NO_DH\r
+#error DH is disabled.\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+#include <openssl/bio.h>\r
+#endif\r
+#include <openssl/ossl_typ.h>\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#include <openssl/bn.h>\r
+#endif\r
+       \r
+#define DH_FLAG_CACHE_MONT_P     0x01\r
+#define DH_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DH\r
+                                       * implementation now uses constant time\r
+                                       * modular exponentiation for secret exponents\r
+                                       * by default. This flag causes the\r
+                                       * faster variable sliding window method to\r
+                                       * be used for all exponents.\r
+                                       */\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Already defined in ossl_typ.h */\r
+/* typedef struct dh_st DH; */\r
+/* typedef struct dh_method DH_METHOD; */\r
+\r
+struct dh_method\r
+       {\r
+       const char *name;\r
+       /* Methods here */\r
+       int (*generate_key)(DH *dh);\r
+       int (*compute_key)(unsigned char *key,const BIGNUM *pub_key,DH *dh);\r
+       int (*bn_mod_exp)(const DH *dh, BIGNUM *r, const BIGNUM *a,\r
+                               const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,\r
+                               BN_MONT_CTX *m_ctx); /* Can be null */\r
+\r
+       int (*init)(DH *dh);\r
+       int (*finish)(DH *dh);\r
+       int flags;\r
+       char *app_data;\r
+       /* If this is non-NULL, it will be used to generate parameters */\r
+       int (*generate_params)(DH *dh, int prime_len, int generator, BN_GENCB *cb);\r
+       };\r
+\r
+struct dh_st\r
+       {\r
+       /* This first argument is used to pick up errors when\r
+        * a DH is passed instead of a EVP_PKEY */\r
+       int pad;\r
+       int version;\r
+       BIGNUM *p;\r
+       BIGNUM *g;\r
+       long length; /* optional */\r
+       BIGNUM *pub_key;        /* g^x */\r
+       BIGNUM *priv_key;       /* x */\r
+\r
+       int flags;\r
+       BN_MONT_CTX *method_mont_p;\r
+       /* Place holders if we want to do X9.42 DH */\r
+       BIGNUM *q;\r
+       BIGNUM *j;\r
+       unsigned char *seed;\r
+       int seedlen;\r
+       BIGNUM *counter;\r
+\r
+       int references;\r
+       CRYPTO_EX_DATA ex_data;\r
+       const DH_METHOD *meth;\r
+       ENGINE *engine;\r
+       };\r
+\r
+#define DH_GENERATOR_2         2\r
+/* #define DH_GENERATOR_3      3 */\r
+#define DH_GENERATOR_5         5\r
+\r
+/* DH_check error codes */\r
+#define DH_CHECK_P_NOT_PRIME           0x01\r
+#define DH_CHECK_P_NOT_SAFE_PRIME      0x02\r
+#define DH_UNABLE_TO_CHECK_GENERATOR   0x04\r
+#define DH_NOT_SUITABLE_GENERATOR      0x08\r
+\r
+/* primes p where (p-1)/2 is prime too are called "safe"; we define\r
+   this for backward compatibility: */\r
+#define DH_CHECK_P_NOT_STRONG_PRIME    DH_CHECK_P_NOT_SAFE_PRIME\r
+\r
+#define DHparams_dup(x) ASN1_dup_of_const(DH,i2d_DHparams,d2i_DHparams,x)\r
+#define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \\r
+               (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x))\r
+#define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \\r
+               (unsigned char *)(x))\r
+#define d2i_DHparams_bio(bp,x) ASN1_d2i_bio_of(DH,DH_new,d2i_DHparams,bp,x)\r
+#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio_of_const(DH,i2d_DHparams,bp,x)\r
+\r
+const DH_METHOD *DH_OpenSSL(void);\r
+\r
+void DH_set_default_method(const DH_METHOD *meth);\r
+const DH_METHOD *DH_get_default_method(void);\r
+int DH_set_method(DH *dh, const DH_METHOD *meth);\r
+DH *DH_new_method(ENGINE *engine);\r
+\r
+DH *   DH_new(void);\r
+void   DH_free(DH *dh);\r
+int    DH_up_ref(DH *dh);\r
+int    DH_size(const DH *dh);\r
+int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,\r
+            CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+int DH_set_ex_data(DH *d, int idx, void *arg);\r
+void *DH_get_ex_data(DH *d, int idx);\r
+\r
+/* Deprecated version */\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+DH *   DH_generate_parameters(int prime_len,int generator,\r
+               void (*callback)(int,int,void *),void *cb_arg);\r
+#endif /* !defined(OPENSSL_NO_DEPRECATED) */\r
+\r
+/* New version */\r
+int    DH_generate_parameters_ex(DH *dh, int prime_len,int generator, BN_GENCB *cb);\r
+\r
+int    DH_check(const DH *dh,int *codes);\r
+int    DH_generate_key(DH *dh);\r
+int    DH_compute_key(unsigned char *key,const BIGNUM *pub_key,DH *dh);\r
+DH *   d2i_DHparams(DH **a,const unsigned char **pp, long length);\r
+int    i2d_DHparams(const DH *a,unsigned char **pp);\r
+#ifndef OPENSSL_NO_FP_API\r
+int    DHparams_print_fp(FILE *fp, const DH *x);\r
+#endif\r
+#ifndef OPENSSL_NO_BIO\r
+int    DHparams_print(BIO *bp, const DH *x);\r
+#else\r
+int    DHparams_print(char *bp, const DH *x);\r
+#endif\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_DH_strings(void);\r
+\r
+/* Error codes for the DH functions. */\r
+\r
+/* Function codes. */\r
+#define DH_F_COMPUTE_KEY                                102\r
+#define DH_F_DHPARAMS_PRINT                             100\r
+#define DH_F_DHPARAMS_PRINT_FP                          101\r
+#define DH_F_DH_BUILTIN_GENPARAMS                       106\r
+#define DH_F_DH_NEW_METHOD                              105\r
+#define DH_F_GENERATE_KEY                               103\r
+#define DH_F_GENERATE_PARAMETERS                        104\r
+\r
+/* Reason codes. */\r
+#define DH_R_BAD_GENERATOR                              101\r
+#define DH_R_NO_PRIVATE_VALUE                           100\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/dsa.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/dsa.h
new file mode 100644 (file)
index 0000000..e54b46a
--- /dev/null
@@ -0,0 +1,279 @@
+/* crypto/dsa/dsa.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+/*\r
+ * The DSS routines are based on patches supplied by\r
+ * Steven Schoch <schoch@sheba.arc.nasa.gov>.  He basically did the\r
+ * work and I have just tweaked them a little to fit into my\r
+ * stylistic vision for SSLeay :-) */\r
+\r
+#ifndef HEADER_DSA_H\r
+#define HEADER_DSA_H\r
+\r
+#include <openssl/e_os2.h>\r
+\r
+#ifdef OPENSSL_NO_DSA\r
+#error DSA is disabled.\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+#include <openssl/bio.h>\r
+#endif\r
+#include <openssl/crypto.h>\r
+#include <openssl/ossl_typ.h>\r
+\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#include <openssl/bn.h>\r
+#ifndef OPENSSL_NO_DH\r
+# include <openssl/dh.h>\r
+#endif\r
+#endif\r
+\r
+#define DSA_FLAG_CACHE_MONT_P  0x01\r
+#define DSA_FLAG_NO_EXP_CONSTTIME       0x02 /* new with 0.9.7h; the built-in DSA\r
+                                              * implementation now uses constant time\r
+                                              * modular exponentiation for secret exponents\r
+                                              * by default. This flag causes the\r
+                                              * faster variable sliding window method to\r
+                                              * be used for all exponents.\r
+                                              */\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Already defined in ossl_typ.h */\r
+/* typedef struct dsa_st DSA; */\r
+/* typedef struct dsa_method DSA_METHOD; */\r
+\r
+typedef struct DSA_SIG_st\r
+       {\r
+       BIGNUM *r;\r
+       BIGNUM *s;\r
+       } DSA_SIG;\r
+\r
+struct dsa_method\r
+       {\r
+       const char *name;\r
+       DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa);\r
+       int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,\r
+                                                               BIGNUM **rp);\r
+       int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,\r
+                                                       DSA_SIG *sig, DSA *dsa);\r
+       int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,\r
+                       BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,\r
+                       BN_MONT_CTX *in_mont);\r
+       int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,\r
+                               const BIGNUM *m, BN_CTX *ctx,\r
+                               BN_MONT_CTX *m_ctx); /* Can be null */\r
+       int (*init)(DSA *dsa);\r
+       int (*finish)(DSA *dsa);\r
+       int flags;\r
+       char *app_data;\r
+       /* If this is non-NULL, it is used to generate DSA parameters */\r
+       int (*dsa_paramgen)(DSA *dsa, int bits,\r
+                       unsigned char *seed, int seed_len,\r
+                       int *counter_ret, unsigned long *h_ret,\r
+                       BN_GENCB *cb);\r
+       /* If this is non-NULL, it is used to generate DSA keys */\r
+       int (*dsa_keygen)(DSA *dsa);\r
+       };\r
+\r
+struct dsa_st\r
+       {\r
+       /* This first variable is used to pick up errors where\r
+        * a DSA is passed instead of of a EVP_PKEY */\r
+       int pad;\r
+       long version;\r
+       int write_params;\r
+       BIGNUM *p;\r
+       BIGNUM *q;      /* == 20 */\r
+       BIGNUM *g;\r
+\r
+       BIGNUM *pub_key;  /* y public key */\r
+       BIGNUM *priv_key; /* x private key */\r
+\r
+       BIGNUM *kinv;   /* Signing pre-calc */\r
+       BIGNUM *r;      /* Signing pre-calc */\r
+\r
+       int flags;\r
+       /* Normally used to cache montgomery values */\r
+       BN_MONT_CTX *method_mont_p;\r
+       int references;\r
+       CRYPTO_EX_DATA ex_data;\r
+       const DSA_METHOD *meth;\r
+       /* functional reference if 'meth' is ENGINE-provided */\r
+       ENGINE *engine;\r
+       };\r
+\r
+#define DSAparams_dup(x) ASN1_dup_of_const(DSA,i2d_DSAparams,d2i_DSAparams,x)\r
+#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \\r
+               (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))\r
+#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \\r
+               (unsigned char *)(x))\r
+#define d2i_DSAparams_bio(bp,x) ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAparams,bp,x)\r
+#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio_of_const(DSA,i2d_DSAparams,bp,x)\r
+\r
+\r
+DSA_SIG * DSA_SIG_new(void);\r
+void   DSA_SIG_free(DSA_SIG *a);\r
+int    i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);\r
+DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, const unsigned char **pp, long length);\r
+\r
+DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa);\r
+int    DSA_do_verify(const unsigned char *dgst,int dgst_len,\r
+                     DSA_SIG *sig,DSA *dsa);\r
+\r
+const DSA_METHOD *DSA_OpenSSL(void);\r
+\r
+void   DSA_set_default_method(const DSA_METHOD *);\r
+const DSA_METHOD *DSA_get_default_method(void);\r
+int    DSA_set_method(DSA *dsa, const DSA_METHOD *);\r
+\r
+DSA *  DSA_new(void);\r
+DSA *  DSA_new_method(ENGINE *engine);\r
+void   DSA_free (DSA *r);\r
+/* "up" the DSA object's reference count */\r
+int    DSA_up_ref(DSA *r);\r
+int    DSA_size(const DSA *);\r
+       /* next 4 return -1 on error */\r
+int    DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp);\r
+int    DSA_sign(int type,const unsigned char *dgst,int dlen,\r
+               unsigned char *sig, unsigned int *siglen, DSA *dsa);\r
+int    DSA_verify(int type,const unsigned char *dgst,int dgst_len,\r
+               const unsigned char *sigbuf, int siglen, DSA *dsa);\r
+int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,\r
+            CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+int DSA_set_ex_data(DSA *d, int idx, void *arg);\r
+void *DSA_get_ex_data(DSA *d, int idx);\r
+\r
+DSA *  d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length);\r
+DSA *  d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length);\r
+DSA *  d2i_DSAparams(DSA **a, const unsigned char **pp, long length);\r
+\r
+/* Deprecated version */\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+DSA *  DSA_generate_parameters(int bits,\r
+               unsigned char *seed,int seed_len,\r
+               int *counter_ret, unsigned long *h_ret,void\r
+               (*callback)(int, int, void *),void *cb_arg);\r
+#endif /* !defined(OPENSSL_NO_DEPRECATED) */\r
+\r
+/* New version */\r
+int    DSA_generate_parameters_ex(DSA *dsa, int bits,\r
+               unsigned char *seed,int seed_len,\r
+               int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);\r
+\r
+int    DSA_generate_key(DSA *a);\r
+int    i2d_DSAPublicKey(const DSA *a, unsigned char **pp);\r
+int    i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);\r
+int    i2d_DSAparams(const DSA *a,unsigned char **pp);\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+int    DSAparams_print(BIO *bp, const DSA *x);\r
+int    DSA_print(BIO *bp, const DSA *x, int off);\r
+#endif\r
+#ifndef OPENSSL_NO_FP_API\r
+int    DSAparams_print_fp(FILE *fp, const DSA *x);\r
+int    DSA_print_fp(FILE *bp, const DSA *x, int off);\r
+#endif\r
+\r
+#define DSS_prime_checks 50\r
+/* Primality test according to FIPS PUB 186[-1], Appendix 2.1:\r
+ * 50 rounds of Rabin-Miller */\r
+#define DSA_is_prime(n, callback, cb_arg) \\r
+       BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg)\r
+\r
+#ifndef OPENSSL_NO_DH\r
+/* Convert DSA structure (key or just parameters) into DH structure\r
+ * (be careful to avoid small subgroup attacks when using this!) */\r
+DH *DSA_dup_DH(const DSA *r);\r
+#endif\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_DSA_strings(void);\r
+\r
+/* Error codes for the DSA functions. */\r
+\r
+/* Function codes. */\r
+#define DSA_F_D2I_DSA_SIG                               110\r
+#define DSA_F_DSAPARAMS_PRINT                           100\r
+#define DSA_F_DSAPARAMS_PRINT_FP                        101\r
+#define DSA_F_DSA_DO_SIGN                               112\r
+#define DSA_F_DSA_DO_VERIFY                             113\r
+#define DSA_F_DSA_NEW_METHOD                            103\r
+#define DSA_F_DSA_PRINT                                         104\r
+#define DSA_F_DSA_PRINT_FP                              105\r
+#define DSA_F_DSA_SIGN                                  106\r
+#define DSA_F_DSA_SIGN_SETUP                            107\r
+#define DSA_F_DSA_SIG_NEW                               109\r
+#define DSA_F_DSA_VERIFY                                108\r
+#define DSA_F_I2D_DSA_SIG                               111\r
+#define DSA_F_SIG_CB                                    114\r
+\r
+/* Reason codes. */\r
+#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE               100\r
+#define DSA_R_MISSING_PARAMETERS                        101\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/dso.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/dso.h
new file mode 100644 (file)
index 0000000..8a69165
--- /dev/null
@@ -0,0 +1,368 @@
+/* dso.h -*- mode:C; c-file-style: "eay" -*- */\r
+/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL\r
+ * project 2000.\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    licensing@OpenSSL.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_DSO_H\r
+#define HEADER_DSO_H\r
+\r
+#include <openssl/crypto.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* These values are used as commands to DSO_ctrl() */\r
+#define DSO_CTRL_GET_FLAGS     1\r
+#define DSO_CTRL_SET_FLAGS     2\r
+#define DSO_CTRL_OR_FLAGS      3\r
+\r
+/* By default, DSO_load() will translate the provided filename into a form\r
+ * typical for the platform (more specifically the DSO_METHOD) using the\r
+ * dso_name_converter function of the method. Eg. win32 will transform "blah"\r
+ * into "blah.dll", and dlfcn will transform it into "libblah.so". The\r
+ * behaviour can be overriden by setting the name_converter callback in the DSO\r
+ * object (using DSO_set_name_converter()). This callback could even utilise\r
+ * the DSO_METHOD's converter too if it only wants to override behaviour for\r
+ * one or two possible DSO methods. However, the following flag can be set in a\r
+ * DSO to prevent *any* native name-translation at all - eg. if the caller has\r
+ * prompted the user for a path to a driver library so the filename should be\r
+ * interpreted as-is. */\r
+#define DSO_FLAG_NO_NAME_TRANSLATION           0x01\r
+/* An extra flag to give if only the extension should be added as\r
+ * translation.  This is obviously only of importance on Unix and\r
+ * other operating systems where the translation also may prefix\r
+ * the name with something, like 'lib', and ignored everywhere else.\r
+ * This flag is also ignored if DSO_FLAG_NO_NAME_TRANSLATION is used\r
+ * at the same time. */\r
+#define DSO_FLAG_NAME_TRANSLATION_EXT_ONLY     0x02\r
+\r
+/* The following flag controls the translation of symbol names to upper\r
+ * case.  This is currently only being implemented for OpenVMS.\r
+ */\r
+#define DSO_FLAG_UPCASE_SYMBOL                 0x10\r
+\r
+/* This flag loads the library with public symbols.\r
+ * Meaning: The exported symbols of this library are public\r
+ * to all libraries loaded after this library.\r
+ * At the moment only implemented in unix.\r
+ */\r
+#define DSO_FLAG_GLOBAL_SYMBOLS                        0x20\r
+\r
+\r
+typedef void (*DSO_FUNC_TYPE)(void);\r
+\r
+typedef struct dso_st DSO;\r
+\r
+/* The function prototype used for method functions (or caller-provided\r
+ * callbacks) that transform filenames. They are passed a DSO structure pointer\r
+ * (or NULL if they are to be used independantly of a DSO object) and a\r
+ * filename to transform. They should either return NULL (if there is an error\r
+ * condition) or a newly allocated string containing the transformed form that\r
+ * the caller will need to free with OPENSSL_free() when done. */\r
+typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *);\r
+/* The function prototype used for method functions (or caller-provided\r
+ * callbacks) that merge two file specifications. They are passed a\r
+ * DSO structure pointer (or NULL if they are to be used independantly of\r
+ * a DSO object) and two file specifications to merge. They should\r
+ * either return NULL (if there is an error condition) or a newly allocated\r
+ * string containing the result of merging that the caller will need\r
+ * to free with OPENSSL_free() when done.\r
+ * Here, merging means that bits and pieces are taken from each of the\r
+ * file specifications and added together in whatever fashion that is\r
+ * sensible for the DSO method in question.  The only rule that really\r
+ * applies is that if the two specification contain pieces of the same\r
+ * type, the copy from the string string takes priority.  One could see\r
+ * it as the first specification is the one given by the user and the\r
+ * second being a bunch of defaults to add on if they're missing in the\r
+ * first. */\r
+typedef char* (*DSO_MERGER_FUNC)(DSO *, const char *, const char *);\r
+\r
+typedef struct dso_meth_st\r
+       {\r
+       const char *name;\r
+       /* Loads a shared library, NB: new DSO_METHODs must ensure that a\r
+        * successful load populates the loaded_filename field, and likewise a\r
+        * successful unload OPENSSL_frees and NULLs it out. */\r
+       int (*dso_load)(DSO *dso);\r
+       /* Unloads a shared library */\r
+       int (*dso_unload)(DSO *dso);\r
+       /* Binds a variable */\r
+       void *(*dso_bind_var)(DSO *dso, const char *symname);\r
+       /* Binds a function - assumes a return type of DSO_FUNC_TYPE.\r
+        * This should be cast to the real function prototype by the\r
+        * caller. Platforms that don't have compatible representations\r
+        * for different prototypes (this is possible within ANSI C)\r
+        * are highly unlikely to have shared libraries at all, let\r
+        * alone a DSO_METHOD implemented for them. */\r
+       DSO_FUNC_TYPE (*dso_bind_func)(DSO *dso, const char *symname);\r
+\r
+/* I don't think this would actually be used in any circumstances. */\r
+#if 0\r
+       /* Unbinds a variable */\r
+       int (*dso_unbind_var)(DSO *dso, char *symname, void *symptr);\r
+       /* Unbinds a function */\r
+       int (*dso_unbind_func)(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);\r
+#endif\r
+       /* The generic (yuck) "ctrl()" function. NB: Negative return\r
+        * values (rather than zero) indicate errors. */\r
+       long (*dso_ctrl)(DSO *dso, int cmd, long larg, void *parg);\r
+       /* The default DSO_METHOD-specific function for converting filenames to\r
+        * a canonical native form. */\r
+       DSO_NAME_CONVERTER_FUNC dso_name_converter;\r
+       /* The default DSO_METHOD-specific function for converting filenames to\r
+        * a canonical native form. */\r
+       DSO_MERGER_FUNC dso_merger;\r
+\r
+       /* [De]Initialisation handlers. */\r
+       int (*init)(DSO *dso);\r
+       int (*finish)(DSO *dso);\r
+       } DSO_METHOD;\r
+\r
+/**********************************************************************/\r
+/* The low-level handle type used to refer to a loaded shared library */\r
+\r
+struct dso_st\r
+       {\r
+       DSO_METHOD *meth;\r
+       /* Standard dlopen uses a (void *). Win32 uses a HANDLE. VMS\r
+        * doesn't use anything but will need to cache the filename\r
+        * for use in the dso_bind handler. All in all, let each\r
+        * method control its own destiny. "Handles" and such go in\r
+        * a STACK. */\r
+       STACK *meth_data;\r
+       int references;\r
+       int flags;\r
+       /* For use by applications etc ... use this for your bits'n'pieces,\r
+        * don't touch meth_data! */\r
+       CRYPTO_EX_DATA ex_data;\r
+       /* If this callback function pointer is set to non-NULL, then it will\r
+        * be used in DSO_load() in place of meth->dso_name_converter. NB: This\r
+        * should normally set using DSO_set_name_converter(). */\r
+       DSO_NAME_CONVERTER_FUNC name_converter;\r
+       /* If this callback function pointer is set to non-NULL, then it will\r
+        * be used in DSO_load() in place of meth->dso_merger. NB: This\r
+        * should normally set using DSO_set_merger(). */\r
+       DSO_MERGER_FUNC merger;\r
+       /* This is populated with (a copy of) the platform-independant\r
+        * filename used for this DSO. */\r
+       char *filename;\r
+       /* This is populated with (a copy of) the translated filename by which\r
+        * the DSO was actually loaded. It is NULL iff the DSO is not currently\r
+        * loaded. NB: This is here because the filename translation process\r
+        * may involve a callback being invoked more than once not only to\r
+        * convert to a platform-specific form, but also to try different\r
+        * filenames in the process of trying to perform a load. As such, this\r
+        * variable can be used to indicate (a) whether this DSO structure\r
+        * corresponds to a loaded library or not, and (b) the filename with\r
+        * which it was actually loaded. */\r
+       char *loaded_filename;\r
+       };\r
+\r
+\r
+DSO *  DSO_new(void);\r
+DSO *  DSO_new_method(DSO_METHOD *method);\r
+int    DSO_free(DSO *dso);\r
+int    DSO_flags(DSO *dso);\r
+int    DSO_up_ref(DSO *dso);\r
+long   DSO_ctrl(DSO *dso, int cmd, long larg, void *parg);\r
+\r
+/* This function sets the DSO's name_converter callback. If it is non-NULL,\r
+ * then it will be used instead of the associated DSO_METHOD's function. If\r
+ * oldcb is non-NULL then it is set to the function pointer value being\r
+ * replaced. Return value is non-zero for success. */\r
+int    DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb,\r
+                               DSO_NAME_CONVERTER_FUNC *oldcb);\r
+/* These functions can be used to get/set the platform-independant filename\r
+ * used for a DSO. NB: set will fail if the DSO is already loaded. */\r
+const char *DSO_get_filename(DSO *dso);\r
+int    DSO_set_filename(DSO *dso, const char *filename);\r
+/* This function will invoke the DSO's name_converter callback to translate a\r
+ * filename, or if the callback isn't set it will instead use the DSO_METHOD's\r
+ * converter. If "filename" is NULL, the "filename" in the DSO itself will be\r
+ * used. If the DSO_FLAG_NO_NAME_TRANSLATION flag is set, then the filename is\r
+ * simply duplicated. NB: This function is usually called from within a\r
+ * DSO_METHOD during the processing of a DSO_load() call, and is exposed so that\r
+ * caller-created DSO_METHODs can do the same thing. A non-NULL return value\r
+ * will need to be OPENSSL_free()'d. */\r
+char   *DSO_convert_filename(DSO *dso, const char *filename);\r
+/* This function will invoke the DSO's merger callback to merge two file\r
+ * specifications, or if the callback isn't set it will instead use the\r
+ * DSO_METHOD's merger.  A non-NULL return value will need to be\r
+ * OPENSSL_free()'d. */\r
+char   *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2);\r
+/* If the DSO is currently loaded, this returns the filename that it was loaded\r
+ * under, otherwise it returns NULL. So it is also useful as a test as to\r
+ * whether the DSO is currently loaded. NB: This will not necessarily return\r
+ * the same value as DSO_convert_filename(dso, dso->filename), because the\r
+ * DSO_METHOD's load function may have tried a variety of filenames (with\r
+ * and/or without the aid of the converters) before settling on the one it\r
+ * actually loaded. */\r
+const char *DSO_get_loaded_filename(DSO *dso);\r
+\r
+void   DSO_set_default_method(DSO_METHOD *meth);\r
+DSO_METHOD *DSO_get_default_method(void);\r
+DSO_METHOD *DSO_get_method(DSO *dso);\r
+DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth);\r
+\r
+/* The all-singing all-dancing load function, you normally pass NULL\r
+ * for the first and third parameters. Use DSO_up and DSO_free for\r
+ * subsequent reference count handling. Any flags passed in will be set\r
+ * in the constructed DSO after its init() function but before the\r
+ * load operation. If 'dso' is non-NULL, 'flags' is ignored. */\r
+DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags);\r
+\r
+/* This function binds to a variable inside a shared library. */\r
+void *DSO_bind_var(DSO *dso, const char *symname);\r
+\r
+/* This function binds to a function inside a shared library. */\r
+DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname);\r
+\r
+/* This method is the default, but will beg, borrow, or steal whatever\r
+ * method should be the default on any particular platform (including\r
+ * DSO_METH_null() if necessary). */\r
+DSO_METHOD *DSO_METHOD_openssl(void);\r
+\r
+/* This method is defined for all platforms - if a platform has no\r
+ * DSO support then this will be the only method! */\r
+DSO_METHOD *DSO_METHOD_null(void);\r
+\r
+/* If DSO_DLFCN is defined, the standard dlfcn.h-style functions\r
+ * (dlopen, dlclose, dlsym, etc) will be used and incorporated into\r
+ * this method. If not, this method will return NULL. */\r
+DSO_METHOD *DSO_METHOD_dlfcn(void);\r
+\r
+/* If DSO_DL is defined, the standard dl.h-style functions (shl_load, \r
+ * shl_unload, shl_findsym, etc) will be used and incorporated into\r
+ * this method. If not, this method will return NULL. */\r
+DSO_METHOD *DSO_METHOD_dl(void);\r
+\r
+/* If WIN32 is defined, use DLLs. If not, return NULL. */\r
+DSO_METHOD *DSO_METHOD_win32(void);\r
+\r
+/* If VMS is defined, use shared images. If not, return NULL. */\r
+DSO_METHOD *DSO_METHOD_vms(void);\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_DSO_strings(void);\r
+\r
+/* Error codes for the DSO functions. */\r
+\r
+/* Function codes. */\r
+#define DSO_F_DLFCN_BIND_FUNC                           100\r
+#define DSO_F_DLFCN_BIND_VAR                            101\r
+#define DSO_F_DLFCN_LOAD                                102\r
+#define DSO_F_DLFCN_MERGER                              130\r
+#define DSO_F_DLFCN_NAME_CONVERTER                      123\r
+#define DSO_F_DLFCN_UNLOAD                              103\r
+#define DSO_F_DL_BIND_FUNC                              104\r
+#define DSO_F_DL_BIND_VAR                               105\r
+#define DSO_F_DL_LOAD                                   106\r
+#define DSO_F_DL_MERGER                                         131\r
+#define DSO_F_DL_NAME_CONVERTER                                 124\r
+#define DSO_F_DL_UNLOAD                                         107\r
+#define DSO_F_DSO_BIND_FUNC                             108\r
+#define DSO_F_DSO_BIND_VAR                              109\r
+#define DSO_F_DSO_CONVERT_FILENAME                      126\r
+#define DSO_F_DSO_CTRL                                  110\r
+#define DSO_F_DSO_FREE                                  111\r
+#define DSO_F_DSO_GET_FILENAME                          127\r
+#define DSO_F_DSO_GET_LOADED_FILENAME                   128\r
+#define DSO_F_DSO_LOAD                                  112\r
+#define DSO_F_DSO_MERGE                                         132\r
+#define DSO_F_DSO_NEW_METHOD                            113\r
+#define DSO_F_DSO_SET_FILENAME                          129\r
+#define DSO_F_DSO_SET_NAME_CONVERTER                    122\r
+#define DSO_F_DSO_UP_REF                                114\r
+#define DSO_F_VMS_BIND_SYM                              115\r
+#define DSO_F_VMS_LOAD                                  116\r
+#define DSO_F_VMS_MERGER                                133\r
+#define DSO_F_VMS_UNLOAD                                117\r
+#define DSO_F_WIN32_BIND_FUNC                           118\r
+#define DSO_F_WIN32_BIND_VAR                            119\r
+#define DSO_F_WIN32_JOINER                              135\r
+#define DSO_F_WIN32_LOAD                                120\r
+#define DSO_F_WIN32_MERGER                              134\r
+#define DSO_F_WIN32_NAME_CONVERTER                      125\r
+#define DSO_F_WIN32_SPLITTER                            136\r
+#define DSO_F_WIN32_UNLOAD                              121\r
+\r
+/* Reason codes. */\r
+#define DSO_R_CTRL_FAILED                               100\r
+#define DSO_R_DSO_ALREADY_LOADED                        110\r
+#define DSO_R_EMPTY_FILE_STRUCTURE                      113\r
+#define DSO_R_FAILURE                                   114\r
+#define DSO_R_FILENAME_TOO_BIG                          101\r
+#define DSO_R_FINISH_FAILED                             102\r
+#define DSO_R_INCORRECT_FILE_SYNTAX                     115\r
+#define DSO_R_LOAD_FAILED                               103\r
+#define DSO_R_NAME_TRANSLATION_FAILED                   109\r
+#define DSO_R_NO_FILENAME                               111\r
+#define DSO_R_NO_FILE_SPECIFICATION                     116\r
+#define DSO_R_NULL_HANDLE                               104\r
+#define DSO_R_SET_FILENAME_FAILED                       112\r
+#define DSO_R_STACK_ERROR                               105\r
+#define DSO_R_SYM_FAILURE                               106\r
+#define DSO_R_UNLOAD_FAILED                             107\r
+#define DSO_R_UNSUPPORTED                               108\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/dtls1.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/dtls1.h
new file mode 100644 (file)
index 0000000..8093a8f
--- /dev/null
@@ -0,0 +1,212 @@
+/* ssl/dtls1.h */\r
+/* \r
+ * DTLS implementation written by Nagendra Modadugu\r
+ * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.  \r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@OpenSSL.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_DTLS1_H \r
+#define HEADER_DTLS1_H \r
+\r
+#include <openssl/buffer.h>\r
+#include <openssl/pqueue.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define DTLS1_VERSION                  0x0100\r
+#define DTLS1_VERSION_MAJOR            0x01\r
+#define DTLS1_VERSION_MINOR            0x00\r
+\r
+#define DTLS1_AD_MISSING_HANDSHAKE_MESSAGE    110\r
+\r
+/* lengths of messages */\r
+#define DTLS1_COOKIE_LENGTH                     32\r
+\r
+#define DTLS1_RT_HEADER_LENGTH                  13\r
+\r
+#define DTLS1_HM_HEADER_LENGTH                  12\r
+\r
+#define DTLS1_HM_BAD_FRAGMENT                   -2\r
+#define DTLS1_HM_FRAGMENT_RETRY                 -3\r
+\r
+#define DTLS1_CCS_HEADER_LENGTH                  3\r
+\r
+#define DTLS1_AL_HEADER_LENGTH                   7\r
+\r
+\r
+typedef struct dtls1_bitmap_st\r
+       {\r
+       PQ_64BIT map;\r
+       unsigned long length;     /* sizeof the bitmap in bits */\r
+       PQ_64BIT max_seq_num;  /* max record number seen so far */\r
+       } DTLS1_BITMAP;\r
+\r
+struct hm_header_st\r
+       {\r
+       unsigned char type;\r
+       unsigned long msg_len;\r
+       unsigned short seq;\r
+       unsigned long frag_off;\r
+       unsigned long frag_len;\r
+       unsigned int is_ccs;\r
+       };\r
+\r
+struct ccs_header_st\r
+       {\r
+       unsigned char type;\r
+       unsigned short seq;\r
+       };\r
+\r
+struct dtls1_timeout_st\r
+       {\r
+       /* Number of read timeouts so far */\r
+       unsigned int read_timeouts;\r
+       \r
+       /* Number of write timeouts so far */\r
+       unsigned int write_timeouts;\r
+       \r
+       /* Number of alerts received so far */\r
+       unsigned int num_alerts;\r
+       };\r
+\r
+typedef struct record_pqueue_st\r
+       {\r
+       unsigned short epoch;\r
+       pqueue q;\r
+       } record_pqueue;\r
+\r
+typedef struct hm_fragment_st\r
+       {\r
+       struct hm_header_st msg_header;\r
+       unsigned char *fragment;\r
+       } hm_fragment;\r
+\r
+typedef struct dtls1_state_st\r
+       {\r
+       unsigned int send_cookie;\r
+       unsigned char cookie[DTLS1_COOKIE_LENGTH];\r
+       unsigned char rcvd_cookie[DTLS1_COOKIE_LENGTH];\r
+       unsigned int cookie_len;\r
+\r
+       /* \r
+        * The current data and handshake epoch.  This is initially\r
+        * undefined, and starts at zero once the initial handshake is\r
+        * completed \r
+        */\r
+       unsigned short r_epoch;\r
+       unsigned short w_epoch;\r
+\r
+       /* records being received in the current epoch */\r
+       DTLS1_BITMAP bitmap;\r
+\r
+       /* renegotiation starts a new set of sequence numbers */\r
+       DTLS1_BITMAP next_bitmap;\r
+\r
+       /* handshake message numbers */\r
+       unsigned short handshake_write_seq;\r
+       unsigned short next_handshake_write_seq;\r
+\r
+       unsigned short handshake_read_seq;\r
+\r
+       /* Received handshake records (processed and unprocessed) */\r
+       record_pqueue unprocessed_rcds;\r
+       record_pqueue processed_rcds;\r
+\r
+       /* Buffered handshake messages */\r
+       pqueue buffered_messages;\r
+\r
+       /* Buffered (sent) handshake records */\r
+       pqueue sent_messages;\r
+\r
+       unsigned int mtu; /* max wire packet size */\r
+\r
+       struct hm_header_st w_msg_hdr;\r
+       struct hm_header_st r_msg_hdr;\r
+\r
+       struct dtls1_timeout_st timeout;\r
+       \r
+       /* storage for Alert/Handshake protocol data received but not\r
+        * yet processed by ssl3_read_bytes: */\r
+       unsigned char alert_fragment[DTLS1_AL_HEADER_LENGTH];\r
+       unsigned int alert_fragment_len;\r
+       unsigned char handshake_fragment[DTLS1_HM_HEADER_LENGTH];\r
+       unsigned int handshake_fragment_len;\r
+\r
+       unsigned int retransmitting;\r
+\r
+       } DTLS1_STATE;\r
+\r
+typedef struct dtls1_record_data_st\r
+       {\r
+       unsigned char *packet;\r
+       unsigned int   packet_length;\r
+       SSL3_BUFFER    rbuf;\r
+       SSL3_RECORD    rrec;\r
+       } DTLS1_RECORD_DATA;\r
+\r
+\r
+/* Timeout multipliers (timeout slice is defined in apps/timeouts.h */\r
+#define DTLS1_TMO_READ_COUNT                      2\r
+#define DTLS1_TMO_WRITE_COUNT                     2\r
+\r
+#define DTLS1_TMO_ALERT_COUNT                     12\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/e_os2.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/e_os2.h
new file mode 100644 (file)
index 0000000..ed44d14
--- /dev/null
@@ -0,0 +1,285 @@
+/* e_os2.h */\r
+/* ====================================================================\r
+ * Copyright (c) 1998-2000 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#include <openssl/opensslconf.h>\r
+\r
+#ifndef HEADER_E_OS2_H\r
+#define HEADER_E_OS2_H\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/******************************************************************************\r
+ * Detect operating systems.  This probably needs completing.\r
+ * The result is that at least one OPENSSL_SYS_os macro should be defined.\r
+ * However, if none is defined, Unix is assumed.\r
+ **/\r
+\r
+#define OPENSSL_SYS_UNIX\r
+\r
+/* ----------------------- Macintosh, before MacOS X ----------------------- */\r
+#if defined(__MWERKS__) && defined(macintosh) || defined(OPENSSL_SYSNAME_MAC)\r
+# undef OPENSSL_SYS_UNIX\r
+# define OPENSSL_SYS_MACINTOSH_CLASSIC\r
+#endif\r
+\r
+/* ----------------------- NetWare ----------------------------------------- */\r
+#if defined(NETWARE) || defined(OPENSSL_SYSNAME_NETWARE)\r
+# undef OPENSSL_SYS_UNIX\r
+# define OPENSSL_SYS_NETWARE\r
+#endif\r
+\r
+/* ---------------------- Microsoft operating systems ---------------------- */\r
+\r
+/* The 16 bit environments are pretty straightforward */\r
+#if defined(OPENSSL_SYSNAME_WIN16) || defined(OPENSSL_SYSNAME_MSDOS)\r
+# undef OPENSSL_SYS_UNIX\r
+# define OPENSSL_SYS_MSDOS\r
+#endif\r
+#if defined(OPENSSL_SYSNAME_WIN16)\r
+# undef OPENSSL_SYS_UNIX\r
+# define OPENSSL_SYS_WIN16\r
+#endif\r
+\r
+/* For 32 bit environment, there seems to be the CygWin environment and then\r
+   all the others that try to do the same thing Microsoft does... */\r
+#if defined(OPENSSL_SYSNAME_UWIN)\r
+# undef OPENSSL_SYS_UNIX\r
+# define OPENSSL_SYS_WIN32_UWIN\r
+#else\r
+# if defined(__CYGWIN32__) || defined(OPENSSL_SYSNAME_CYGWIN32)\r
+#  undef OPENSSL_SYS_UNIX\r
+#  define OPENSSL_SYS_WIN32_CYGWIN\r
+# else\r
+#  if defined(_WIN32) || defined(OPENSSL_SYSNAME_WIN32)\r
+#   undef OPENSSL_SYS_UNIX\r
+#   define OPENSSL_SYS_WIN32\r
+#  endif\r
+#  if defined(OPENSSL_SYSNAME_WINNT)\r
+#   undef OPENSSL_SYS_UNIX\r
+#   define OPENSSL_SYS_WINNT\r
+#  endif\r
+#  if defined(OPENSSL_SYSNAME_WINCE)\r
+#   undef OPENSSL_SYS_UNIX\r
+#   define OPENSSL_SYS_WINCE\r
+#  endif\r
+# endif\r
+#endif\r
+\r
+/* Anything that tries to look like Microsoft is "Windows" */\r
+#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE)\r
+# undef OPENSSL_SYS_UNIX\r
+# define OPENSSL_SYS_WINDOWS\r
+# ifndef OPENSSL_SYS_MSDOS\r
+#  define OPENSSL_SYS_MSDOS\r
+# endif\r
+#endif\r
+\r
+/* DLL settings.  This part is a bit tough, because it's up to the application\r
+   implementor how he or she will link the application, so it requires some\r
+   macro to be used. */\r
+#ifdef OPENSSL_SYS_WINDOWS\r
+# ifndef OPENSSL_OPT_WINDLL\r
+#  if defined(_WINDLL) /* This is used when building OpenSSL to indicate that\r
+                          DLL linkage should be used */\r
+#   define OPENSSL_OPT_WINDLL\r
+#  endif\r
+# endif\r
+#endif\r
+\r
+/* -------------------------------- OpenVMS -------------------------------- */\r
+#if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYSNAME_VMS)\r
+# undef OPENSSL_SYS_UNIX\r
+# define OPENSSL_SYS_VMS\r
+# if defined(__DECC)\r
+#  define OPENSSL_SYS_VMS_DECC\r
+# elif defined(__DECCXX)\r
+#  define OPENSSL_SYS_VMS_DECC\r
+#  define OPENSSL_SYS_VMS_DECCXX\r
+# else\r
+#  define OPENSSL_SYS_VMS_NODECC\r
+# endif\r
+#endif\r
+\r
+/* --------------------------------- OS/2 ---------------------------------- */\r
+#if defined(__EMX__) || defined(__OS2__)\r
+# undef OPENSSL_SYS_UNIX\r
+# define OPENSSL_SYS_OS2\r
+#endif\r
+\r
+/* --------------------------------- Unix ---------------------------------- */\r
+#ifdef OPENSSL_SYS_UNIX\r
+# if defined(linux) || defined(__linux__) || defined(OPENSSL_SYSNAME_LINUX)\r
+#  define OPENSSL_SYS_LINUX\r
+# endif\r
+# ifdef OPENSSL_SYSNAME_MPE\r
+#  define OPENSSL_SYS_MPE\r
+# endif\r
+# ifdef OPENSSL_SYSNAME_SNI\r
+#  define OPENSSL_SYS_SNI\r
+# endif\r
+# ifdef OPENSSL_SYSNAME_ULTRASPARC\r
+#  define OPENSSL_SYS_ULTRASPARC\r
+# endif\r
+# ifdef OPENSSL_SYSNAME_NEWS4\r
+#  define OPENSSL_SYS_NEWS4\r
+# endif\r
+# ifdef OPENSSL_SYSNAME_MACOSX\r
+#  define OPENSSL_SYS_MACOSX\r
+# endif\r
+# ifdef OPENSSL_SYSNAME_MACOSX_RHAPSODY\r
+#  define OPENSSL_SYS_MACOSX_RHAPSODY\r
+#  define OPENSSL_SYS_MACOSX\r
+# endif\r
+# ifdef OPENSSL_SYSNAME_SUNOS\r
+#  define OPENSSL_SYS_SUNOS\r
+#endif\r
+# if defined(_CRAY) || defined(OPENSSL_SYSNAME_CRAY)\r
+#  define OPENSSL_SYS_CRAY\r
+# endif\r
+# if defined(_AIX) || defined(OPENSSL_SYSNAME_AIX)\r
+#  define OPENSSL_SYS_AIX\r
+# endif\r
+#endif\r
+\r
+/* --------------------------------- VOS ----------------------------------- */\r
+#ifdef OPENSSL_SYSNAME_VOS\r
+# define OPENSSL_SYS_VOS\r
+#endif\r
+\r
+/* ------------------------------- VxWorks --------------------------------- */\r
+#ifdef OPENSSL_SYSNAME_VXWORKS\r
+# define OPENSSL_SYS_VXWORKS\r
+#endif\r
+\r
+/**\r
+ * That's it for OS-specific stuff\r
+ *****************************************************************************/\r
+\r
+\r
+/* Specials for I/O an exit */\r
+#ifdef OPENSSL_SYS_WIN16\r
+# define OPENSSL_NO_FP_API\r
+#endif\r
+#ifdef OPENSSL_SYS_MSDOS\r
+# define OPENSSL_UNISTD_IO <io.h>\r
+# define OPENSSL_DECLARE_EXIT extern void exit(int);\r
+#else\r
+# define OPENSSL_UNISTD_IO OPENSSL_UNISTD\r
+# define OPENSSL_DECLARE_EXIT /* declared in unistd.h */\r
+#endif\r
+\r
+/* Definitions of OPENSSL_GLOBAL and OPENSSL_EXTERN, to define and declare\r
+   certain global symbols that, with some compilers under VMS, have to be\r
+   defined and declared explicitely with globaldef and globalref.\r
+   Definitions of OPENSSL_EXPORT and OPENSSL_IMPORT, to define and declare\r
+   DLL exports and imports for compilers under Win32.  These are a little\r
+   more complicated to use.  Basically, for any library that exports some\r
+   global variables, the following code must be present in the header file\r
+   that declares them, before OPENSSL_EXTERN is used:\r
+\r
+   #ifdef SOME_BUILD_FLAG_MACRO\r
+   # undef OPENSSL_EXTERN\r
+   # define OPENSSL_EXTERN OPENSSL_EXPORT\r
+   #endif\r
+\r
+   The default is to have OPENSSL_EXPORT, OPENSSL_IMPORT and OPENSSL_GLOBAL\r
+   have some generally sensible values, and for OPENSSL_EXTERN to have the\r
+   value OPENSSL_IMPORT.\r
+*/\r
+\r
+#if defined(OPENSSL_SYS_VMS_NODECC)\r
+# define OPENSSL_EXPORT globalref\r
+# define OPENSSL_IMPORT globalref\r
+# define OPENSSL_GLOBAL globaldef\r
+#elif defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL)\r
+# define OPENSSL_EXPORT extern __declspec(dllexport)\r
+# define OPENSSL_IMPORT extern __declspec(dllimport)\r
+# define OPENSSL_GLOBAL\r
+#else\r
+# define OPENSSL_EXPORT extern\r
+# define OPENSSL_IMPORT extern\r
+# define OPENSSL_GLOBAL\r
+#endif\r
+#define OPENSSL_EXTERN OPENSSL_IMPORT\r
+\r
+/* Macros to allow global variables to be reached through function calls when\r
+   required (if a shared library version requvres it, for example.\r
+   The way it's done allows definitions like this:\r
+\r
+       // in foobar.c\r
+       OPENSSL_IMPLEMENT_GLOBAL(int,foobar) = 0;\r
+       // in foobar.h\r
+       OPENSSL_DECLARE_GLOBAL(int,foobar);\r
+       #define foobar OPENSSL_GLOBAL_REF(foobar)\r
+*/\r
+#ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION\r
+# define OPENSSL_IMPLEMENT_GLOBAL(type,name)                        \\r
+       extern type _hide_##name;                                    \\r
+       type *_shadow_##name(void) { return &_hide_##name; }         \\r
+       static type _hide_##name\r
+# define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void)\r
+# define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name()))\r
+#else\r
+# define OPENSSL_IMPLEMENT_GLOBAL(type,name) OPENSSL_GLOBAL type _shadow_##name\r
+# define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name\r
+# define OPENSSL_GLOBAL_REF(name) _shadow_##name\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ebcdic.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ebcdic.h
new file mode 100644 (file)
index 0000000..0941c8b
--- /dev/null
@@ -0,0 +1,19 @@
+/* crypto/ebcdic.h */\r
+\r
+#ifndef HEADER_EBCDIC_H\r
+#define HEADER_EBCDIC_H\r
+\r
+#include <sys/types.h>\r
+\r
+/* Avoid name clashes with other applications */\r
+#define os_toascii   _openssl_os_toascii\r
+#define os_toebcdic  _openssl_os_toebcdic\r
+#define ebcdic2ascii _openssl_ebcdic2ascii\r
+#define ascii2ebcdic _openssl_ascii2ebcdic\r
+\r
+extern const unsigned char os_toascii[256];\r
+extern const unsigned char os_toebcdic[256];\r
+void *ebcdic2ascii(void *dest, const void *srce, size_t count);\r
+void *ascii2ebcdic(void *dest, const void *srce, size_t count);\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ec.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ec.h
new file mode 100644 (file)
index 0000000..c256f92
--- /dev/null
@@ -0,0 +1,518 @@
+/* crypto/ec/ec.h */\r
+/*\r
+ * Originally written by Bodo Moeller for the OpenSSL project.\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+/* ====================================================================\r
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.\r
+ *\r
+ * Portions of the attached software ("Contribution") are developed by \r
+ * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.\r
+ *\r
+ * The Contribution is licensed pursuant to the OpenSSL open source\r
+ * license provided above.\r
+ *\r
+ * The elliptic curve binary polynomial software is originally written by \r
+ * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_EC_H\r
+#define HEADER_EC_H\r
+\r
+#include <openssl/opensslconf.h>\r
+\r
+#ifdef OPENSSL_NO_EC\r
+#error EC is disabled.\r
+#endif\r
+\r
+#include <openssl/asn1.h>\r
+#include <openssl/symhacks.h>\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#include <openssl/bn.h>\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#elif defined(__SUNPRO_C)\r
+# if __SUNPRO_C >= 0x520\r
+# pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)\r
+# endif\r
+#endif\r
+\r
+\r
+typedef enum {\r
+       /* values as defined in X9.62 (ECDSA) and elsewhere */\r
+       POINT_CONVERSION_COMPRESSED = 2,\r
+       POINT_CONVERSION_UNCOMPRESSED = 4,\r
+       POINT_CONVERSION_HYBRID = 6\r
+} point_conversion_form_t;\r
+\r
+\r
+typedef struct ec_method_st EC_METHOD;\r
+\r
+typedef struct ec_group_st\r
+       /*\r
+        EC_METHOD *meth;\r
+        -- field definition\r
+        -- curve coefficients\r
+        -- optional generator with associated information (order, cofactor)\r
+        -- optional extra data (precomputed table for fast computation of multiples of generator)\r
+        -- ASN1 stuff\r
+       */\r
+       EC_GROUP;\r
+\r
+typedef struct ec_point_st EC_POINT;\r
+\r
+\r
+/* EC_METHODs for curves over GF(p).\r
+ * EC_GFp_simple_method provides the basis for the optimized methods.\r
+ */\r
+const EC_METHOD *EC_GFp_simple_method(void);\r
+const EC_METHOD *EC_GFp_mont_method(void);\r
+const EC_METHOD *EC_GFp_nist_method(void);\r
+\r
+/* EC_METHOD for curves over GF(2^m).\r
+ */\r
+const EC_METHOD *EC_GF2m_simple_method(void);\r
+\r
+\r
+EC_GROUP *EC_GROUP_new(const EC_METHOD *);\r
+void EC_GROUP_free(EC_GROUP *);\r
+void EC_GROUP_clear_free(EC_GROUP *);\r
+int EC_GROUP_copy(EC_GROUP *, const EC_GROUP *);\r
+EC_GROUP *EC_GROUP_dup(const EC_GROUP *);\r
+\r
+const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *);\r
+int EC_METHOD_get_field_type(const EC_METHOD *);\r
+\r
+int EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);\r
+const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);\r
+int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);\r
+int EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);\r
+\r
+void EC_GROUP_set_curve_name(EC_GROUP *, int nid);\r
+int EC_GROUP_get_curve_name(const EC_GROUP *);\r
+\r
+void EC_GROUP_set_asn1_flag(EC_GROUP *, int flag);\r
+int EC_GROUP_get_asn1_flag(const EC_GROUP *);\r
+\r
+void EC_GROUP_set_point_conversion_form(EC_GROUP *, point_conversion_form_t);\r
+point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);\r
+\r
+unsigned char *EC_GROUP_get0_seed(const EC_GROUP *);\r
+size_t EC_GROUP_get_seed_len(const EC_GROUP *);\r
+size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);\r
+\r
+int EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);\r
+int EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);\r
+int EC_GROUP_set_curve_GF2m(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);\r
+int EC_GROUP_get_curve_GF2m(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);\r
+\r
+/* returns the number of bits needed to represent a field element */\r
+int EC_GROUP_get_degree(const EC_GROUP *);\r
+\r
+/* EC_GROUP_check() returns 1 if 'group' defines a valid group, 0 otherwise */\r
+int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);\r
+/* EC_GROUP_check_discriminant() returns 1 if the discriminant of the\r
+ * elliptic curve is not zero, 0 otherwise */\r
+int EC_GROUP_check_discriminant(const EC_GROUP *, BN_CTX *);\r
+\r
+/* EC_GROUP_cmp() returns 0 if both groups are equal and 1 otherwise */\r
+int EC_GROUP_cmp(const EC_GROUP *, const EC_GROUP *, BN_CTX *);\r
+\r
+/* EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*()\r
+ * after choosing an appropriate EC_METHOD */\r
+EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);\r
+EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);\r
+\r
+/* EC_GROUP_new_by_curve_name() creates a EC_GROUP structure\r
+ * specified by a curve name (in form of a NID) */\r
+EC_GROUP *EC_GROUP_new_by_curve_name(int nid);\r
+/* handling of internal curves */\r
+typedef struct { \r
+       int nid;\r
+       const char *comment;\r
+       } EC_builtin_curve;\r
+/* EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number \r
+ * of all available curves or zero if a error occurred. \r
+ * In case r ist not zero nitems EC_builtin_curve structures \r
+ * are filled with the data of the first nitems internal groups */\r
+size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);\r
+\r
+\r
+/* EC_POINT functions */\r
+\r
+EC_POINT *EC_POINT_new(const EC_GROUP *);\r
+void EC_POINT_free(EC_POINT *);\r
+void EC_POINT_clear_free(EC_POINT *);\r
+int EC_POINT_copy(EC_POINT *, const EC_POINT *);\r
+EC_POINT *EC_POINT_dup(const EC_POINT *, const EC_GROUP *);\r
\r
+const EC_METHOD *EC_POINT_method_of(const EC_POINT *);\r
+\r
+int EC_POINT_set_to_infinity(const EC_GROUP *, EC_POINT *);\r
+int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,\r
+       const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);\r
+int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,\r
+       BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);\r
+int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,\r
+       const BIGNUM *x, const BIGNUM *y, BN_CTX *);\r
+int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,\r
+       BIGNUM *x, BIGNUM *y, BN_CTX *);\r
+int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,\r
+       const BIGNUM *x, int y_bit, BN_CTX *);\r
+\r
+int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *, EC_POINT *,\r
+       const BIGNUM *x, const BIGNUM *y, BN_CTX *);\r
+int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *, const EC_POINT *,\r
+       BIGNUM *x, BIGNUM *y, BN_CTX *);\r
+int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *, EC_POINT *,\r
+       const BIGNUM *x, int y_bit, BN_CTX *);\r
+\r
+size_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,\r
+        unsigned char *buf, size_t len, BN_CTX *);\r
+int EC_POINT_oct2point(const EC_GROUP *, EC_POINT *,\r
+        const unsigned char *buf, size_t len, BN_CTX *);\r
+\r
+/* other interfaces to point2oct/oct2point: */\r
+BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,\r
+       point_conversion_form_t form, BIGNUM *, BN_CTX *);\r
+EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,\r
+       EC_POINT *, BN_CTX *);\r
+char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,\r
+       point_conversion_form_t form, BN_CTX *);\r
+EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,\r
+       EC_POINT *, BN_CTX *);\r
+\r
+int EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);\r
+int EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);\r
+int EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);\r
+\r
+int EC_POINT_is_at_infinity(const EC_GROUP *, const EC_POINT *);\r
+int EC_POINT_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);\r
+int EC_POINT_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);\r
+\r
+int EC_POINT_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);\r
+int EC_POINTs_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);\r
+\r
+\r
+int EC_POINTs_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, size_t num, const EC_POINT *[], const BIGNUM *[], BN_CTX *);\r
+int EC_POINT_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, const EC_POINT *, const BIGNUM *, BN_CTX *);\r
+\r
+/* EC_GROUP_precompute_mult() stores multiples of generator for faster point multiplication */\r
+int EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *);\r
+/* EC_GROUP_have_precompute_mult() reports whether such precomputation has been done */\r
+int EC_GROUP_have_precompute_mult(const EC_GROUP *);\r
+\r
+\r
+\r
+/* ASN1 stuff */\r
+\r
+/* EC_GROUP_get_basis_type() returns the NID of the basis type\r
+ * used to represent the field elements */\r
+int EC_GROUP_get_basis_type(const EC_GROUP *);\r
+int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);\r
+int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1, \r
+       unsigned int *k2, unsigned int *k3);\r
+\r
+#define OPENSSL_EC_NAMED_CURVE 0x001\r
+\r
+typedef struct ecpk_parameters_st ECPKPARAMETERS;\r
+\r
+EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);\r
+int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);\r
+\r
+#define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x)\r
+#define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x)\r
+#define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \\r
+                (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x))\r
+#define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \\r
+               (unsigned char *)(x))\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+int     ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);\r
+#endif\r
+#ifndef OPENSSL_NO_FP_API\r
+int     ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);\r
+#endif\r
+\r
+/* the EC_KEY stuff */\r
+typedef struct ec_key_st EC_KEY;\r
+\r
+/* some values for the encoding_flag */\r
+#define EC_PKEY_NO_PARAMETERS  0x001\r
+#define EC_PKEY_NO_PUBKEY      0x002\r
+\r
+EC_KEY *EC_KEY_new(void);\r
+EC_KEY *EC_KEY_new_by_curve_name(int nid);\r
+void EC_KEY_free(EC_KEY *);\r
+EC_KEY *EC_KEY_copy(EC_KEY *, const EC_KEY *);\r
+EC_KEY *EC_KEY_dup(const EC_KEY *);\r
+\r
+int EC_KEY_up_ref(EC_KEY *);\r
+\r
+const EC_GROUP *EC_KEY_get0_group(const EC_KEY *);\r
+int EC_KEY_set_group(EC_KEY *, const EC_GROUP *);\r
+const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *);\r
+int EC_KEY_set_private_key(EC_KEY *, const BIGNUM *);\r
+const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *);\r
+int EC_KEY_set_public_key(EC_KEY *, const EC_POINT *);\r
+unsigned EC_KEY_get_enc_flags(const EC_KEY *);\r
+void EC_KEY_set_enc_flags(EC_KEY *, unsigned int);\r
+point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *);\r
+void EC_KEY_set_conv_form(EC_KEY *, point_conversion_form_t);\r
+/* functions to set/get method specific data  */\r
+void *EC_KEY_get_key_method_data(EC_KEY *, \r
+       void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));\r
+void EC_KEY_insert_key_method_data(EC_KEY *, void *data,\r
+       void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));\r
+/* wrapper functions for the underlying EC_GROUP object */\r
+void EC_KEY_set_asn1_flag(EC_KEY *, int);\r
+int EC_KEY_precompute_mult(EC_KEY *, BN_CTX *ctx);\r
+\r
+/* EC_KEY_generate_key() creates a ec private (public) key */\r
+int EC_KEY_generate_key(EC_KEY *);\r
+/* EC_KEY_check_key() */\r
+int EC_KEY_check_key(const EC_KEY *);\r
+\r
+/* de- and encoding functions for SEC1 ECPrivateKey */\r
+EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len);\r
+int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out);\r
+/* de- and encoding functions for EC parameters */\r
+EC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len);\r
+int i2d_ECParameters(EC_KEY *a, unsigned char **out);\r
+/* de- and encoding functions for EC public key\r
+ * (octet string, not DER -- hence 'o2i' and 'i2o') */\r
+EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len);\r
+int i2o_ECPublicKey(EC_KEY *a, unsigned char **out);\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+int    ECParameters_print(BIO *bp, const EC_KEY *x);\r
+int    EC_KEY_print(BIO *bp, const EC_KEY *x, int off);\r
+#endif\r
+#ifndef OPENSSL_NO_FP_API\r
+int    ECParameters_print_fp(FILE *fp, const EC_KEY *x);\r
+int    EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off);\r
+#endif\r
+\r
+#define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)\r
+\r
+#ifndef __cplusplus\r
+#if defined(__SUNPRO_C)\r
+#  if __SUNPRO_C >= 0x520\r
+# pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)\r
+#  endif\r
+# endif\r
+#endif\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_EC_strings(void);\r
+\r
+/* Error codes for the EC functions. */\r
+\r
+/* Function codes. */\r
+#define EC_F_COMPUTE_WNAF                               143\r
+#define EC_F_D2I_ECPARAMETERS                           144\r
+#define EC_F_D2I_ECPKPARAMETERS                                 145\r
+#define EC_F_D2I_ECPRIVATEKEY                           146\r
+#define EC_F_ECPARAMETERS_PRINT                                 147\r
+#define EC_F_ECPARAMETERS_PRINT_FP                      148\r
+#define EC_F_ECPKPARAMETERS_PRINT                       149\r
+#define EC_F_ECPKPARAMETERS_PRINT_FP                    150\r
+#define EC_F_ECP_NIST_MOD_192                           203\r
+#define EC_F_ECP_NIST_MOD_224                           204\r
+#define EC_F_ECP_NIST_MOD_256                           205\r
+#define EC_F_ECP_NIST_MOD_521                           206\r
+#define EC_F_EC_ASN1_GROUP2CURVE                        153\r
+#define EC_F_EC_ASN1_GROUP2FIELDID                      154\r
+#define EC_F_EC_ASN1_GROUP2PARAMETERS                   155\r
+#define EC_F_EC_ASN1_GROUP2PKPARAMETERS                         156\r
+#define EC_F_EC_ASN1_PARAMETERS2GROUP                   157\r
+#define EC_F_EC_ASN1_PKPARAMETERS2GROUP                         158\r
+#define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY          208\r
+#define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT    159\r
+#define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE             195\r
+#define EC_F_EC_GF2M_SIMPLE_OCT2POINT                   160\r
+#define EC_F_EC_GF2M_SIMPLE_POINT2OCT                   161\r
+#define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162\r
+#define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163\r
+#define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES  164\r
+#define EC_F_EC_GFP_MONT_FIELD_DECODE                   133\r
+#define EC_F_EC_GFP_MONT_FIELD_ENCODE                   134\r
+#define EC_F_EC_GFP_MONT_FIELD_MUL                      131\r
+#define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE               209\r
+#define EC_F_EC_GFP_MONT_FIELD_SQR                      132\r
+#define EC_F_EC_GFP_MONT_GROUP_SET_CURVE                189\r
+#define EC_F_EC_GFP_MONT_GROUP_SET_CURVE_GFP            135\r
+#define EC_F_EC_GFP_NIST_FIELD_MUL                      200\r
+#define EC_F_EC_GFP_NIST_FIELD_SQR                      201\r
+#define EC_F_EC_GFP_NIST_GROUP_SET_CURVE                202\r
+#define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT     165\r
+#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE              166\r
+#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP          100\r
+#define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR          101\r
+#define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE                  102\r
+#define EC_F_EC_GFP_SIMPLE_OCT2POINT                    103\r
+#define EC_F_EC_GFP_SIMPLE_POINT2OCT                    104\r
+#define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE           137\r
+#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES         167\r
+#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105\r
+#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES         168\r
+#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128\r
+#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES   169\r
+#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129\r
+#define EC_F_EC_GROUP_CHECK                             170\r
+#define EC_F_EC_GROUP_CHECK_DISCRIMINANT                171\r
+#define EC_F_EC_GROUP_COPY                              106\r
+#define EC_F_EC_GROUP_GET0_GENERATOR                    139\r
+#define EC_F_EC_GROUP_GET_COFACTOR                      140\r
+#define EC_F_EC_GROUP_GET_CURVE_GF2M                    172\r
+#define EC_F_EC_GROUP_GET_CURVE_GFP                     130\r
+#define EC_F_EC_GROUP_GET_DEGREE                        173\r
+#define EC_F_EC_GROUP_GET_ORDER                                 141\r
+#define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS             193\r
+#define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS               194\r
+#define EC_F_EC_GROUP_GROUP2NID                                 147\r
+#define EC_F_EC_GROUP_NEW                               108\r
+#define EC_F_EC_GROUP_NEW_BY_CURVE_NAME                         174\r
+#define EC_F_EC_GROUP_NEW_FROM_DATA                     175\r
+#define EC_F_EC_GROUP_PRECOMPUTE_MULT                   142\r
+#define EC_F_EC_GROUP_SET_CURVE_GF2M                    176\r
+#define EC_F_EC_GROUP_SET_CURVE_GFP                     109\r
+#define EC_F_EC_GROUP_SET_EXTRA_DATA                    110\r
+#define EC_F_EC_GROUP_SET_GENERATOR                     111\r
+#define EC_F_EC_KEY_CHECK_KEY                           177\r
+#define EC_F_EC_KEY_COPY                                178\r
+#define EC_F_EC_KEY_GENERATE_KEY                        179\r
+#define EC_F_EC_KEY_NEW                                         182\r
+#define EC_F_EC_KEY_PRINT                               180\r
+#define EC_F_EC_KEY_PRINT_FP                            181\r
+#define EC_F_EC_POINTS_MAKE_AFFINE                      136\r
+#define EC_F_EC_POINTS_MUL                              138\r
+#define EC_F_EC_POINT_ADD                               112\r
+#define EC_F_EC_POINT_CMP                               113\r
+#define EC_F_EC_POINT_COPY                              114\r
+#define EC_F_EC_POINT_DBL                               115\r
+#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M       183\r
+#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP        116\r
+#define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP   117\r
+#define EC_F_EC_POINT_INVERT                            210\r
+#define EC_F_EC_POINT_IS_AT_INFINITY                    118\r
+#define EC_F_EC_POINT_IS_ON_CURVE                       119\r
+#define EC_F_EC_POINT_MAKE_AFFINE                       120\r
+#define EC_F_EC_POINT_MUL                               184\r
+#define EC_F_EC_POINT_NEW                               121\r
+#define EC_F_EC_POINT_OCT2POINT                                 122\r
+#define EC_F_EC_POINT_POINT2OCT                                 123\r
+#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M       185\r
+#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP        124\r
+#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M   186\r
+#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP    125\r
+#define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP   126\r
+#define EC_F_EC_POINT_SET_TO_INFINITY                   127\r
+#define EC_F_EC_PRE_COMP_DUP                            207\r
+#define EC_F_EC_WNAF_MUL                                187\r
+#define EC_F_EC_WNAF_PRECOMPUTE_MULT                    188\r
+#define EC_F_I2D_ECPARAMETERS                           190\r
+#define EC_F_I2D_ECPKPARAMETERS                                 191\r
+#define EC_F_I2D_ECPRIVATEKEY                           192\r
+#define EC_F_I2O_ECPUBLICKEY                            151\r
+#define EC_F_O2I_ECPUBLICKEY                            152\r
+\r
+/* Reason codes. */\r
+#define EC_R_ASN1_ERROR                                         115\r
+#define EC_R_ASN1_UNKNOWN_FIELD                                 116\r
+#define EC_R_BUFFER_TOO_SMALL                           100\r
+#define EC_R_D2I_ECPKPARAMETERS_FAILURE                         117\r
+#define EC_R_DISCRIMINANT_IS_ZERO                       118\r
+#define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE               119\r
+#define EC_R_GROUP2PKPARAMETERS_FAILURE                         120\r
+#define EC_R_I2D_ECPKPARAMETERS_FAILURE                         121\r
+#define EC_R_INCOMPATIBLE_OBJECTS                       101\r
+#define EC_R_INVALID_ARGUMENT                           112\r
+#define EC_R_INVALID_COMPRESSED_POINT                   110\r
+#define EC_R_INVALID_COMPRESSION_BIT                    109\r
+#define EC_R_INVALID_ENCODING                           102\r
+#define EC_R_INVALID_FIELD                              103\r
+#define EC_R_INVALID_FORM                               104\r
+#define EC_R_INVALID_GROUP_ORDER                        122\r
+#define EC_R_INVALID_PRIVATE_KEY                        123\r
+#define EC_R_MISSING_PARAMETERS                                 124\r
+#define EC_R_MISSING_PRIVATE_KEY                        125\r
+#define EC_R_NOT_A_NIST_PRIME                           135\r
+#define EC_R_NOT_A_SUPPORTED_NIST_PRIME                         136\r
+#define EC_R_NOT_IMPLEMENTED                            126\r
+#define EC_R_NOT_INITIALIZED                            111\r
+#define EC_R_NO_FIELD_MOD                               133\r
+#define EC_R_PASSED_NULL_PARAMETER                      134\r
+#define EC_R_PKPARAMETERS2GROUP_FAILURE                         127\r
+#define EC_R_POINT_AT_INFINITY                          106\r
+#define EC_R_POINT_IS_NOT_ON_CURVE                      107\r
+#define EC_R_SLOT_FULL                                  108\r
+#define EC_R_UNDEFINED_GENERATOR                        113\r
+#define EC_R_UNDEFINED_ORDER                            128\r
+#define EC_R_UNKNOWN_GROUP                              129\r
+#define EC_R_UNKNOWN_ORDER                              114\r
+#define EC_R_UNSUPPORTED_FIELD                          131\r
+#define EC_R_WRONG_ORDER                                130\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ecdh.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ecdh.h
new file mode 100644 (file)
index 0000000..c2c00b8
--- /dev/null
@@ -0,0 +1,123 @@
+/* crypto/ecdh/ecdh.h */\r
+/* ====================================================================\r
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.\r
+ *\r
+ * The Elliptic Curve Public-Key Crypto Library (ECC Code) included\r
+ * herein is developed by SUN MICROSYSTEMS, INC., and is contributed\r
+ * to the OpenSSL project.\r
+ *\r
+ * The ECC Code is licensed pursuant to the OpenSSL open source\r
+ * license provided below.\r
+ *\r
+ * The ECDH software is originally written by Douglas Stebila of\r
+ * Sun Microsystems Laboratories.\r
+ *\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 2000-2002 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    licensing@OpenSSL.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+#ifndef HEADER_ECDH_H\r
+#define HEADER_ECDH_H\r
+\r
+#include <openssl/opensslconf.h>\r
+\r
+#ifdef OPENSSL_NO_ECDH\r
+#error ECDH is disabled.\r
+#endif\r
+\r
+#include <openssl/ec.h>\r
+#include <openssl/ossl_typ.h>\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#include <openssl/bn.h>\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+const ECDH_METHOD *ECDH_OpenSSL(void);\r
+\r
+void     ECDH_set_default_method(const ECDH_METHOD *);\r
+const ECDH_METHOD *ECDH_get_default_method(void);\r
+int      ECDH_set_method(EC_KEY *, const ECDH_METHOD *);\r
+\r
+int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh,\r
+                     void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen));\r
+\r
+int      ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new \r
+               *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+int      ECDH_set_ex_data(EC_KEY *d, int idx, void *arg);\r
+void     *ECDH_get_ex_data(EC_KEY *d, int idx);\r
+\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_ECDH_strings(void);\r
+\r
+/* Error codes for the ECDH functions. */\r
+\r
+/* Function codes. */\r
+#define ECDH_F_ECDH_COMPUTE_KEY                                 100\r
+#define ECDH_F_ECDH_DATA_NEW_METHOD                     101\r
+\r
+/* Reason codes. */\r
+#define ECDH_R_KDF_FAILED                               102\r
+#define ECDH_R_NO_PRIVATE_VALUE                                 100\r
+#define ECDH_R_POINT_ARITHMETIC_FAILURE                         101\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ecdsa.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ecdsa.h
new file mode 100644 (file)
index 0000000..749d332
--- /dev/null
@@ -0,0 +1,270 @@
+/* crypto/ecdsa/ecdsa.h */\r
+/**\r
+ * \file   crypto/ecdsa/ecdsa.h Include file for the OpenSSL ECDSA functions\r
+ * \author Written by Nils Larsch for the OpenSSL project\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 2000-2003 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    licensing@OpenSSL.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+#ifndef HEADER_ECDSA_H\r
+#define HEADER_ECDSA_H\r
+\r
+#include <openssl/opensslconf.h>\r
+\r
+#ifdef OPENSSL_NO_ECDSA\r
+#error ECDSA is disabled.\r
+#endif\r
+\r
+#include <openssl/ec.h>\r
+#include <openssl/ossl_typ.h>\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#include <openssl/bn.h>\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct ECDSA_SIG_st\r
+       {\r
+       BIGNUM *r;\r
+       BIGNUM *s;\r
+       } ECDSA_SIG;\r
+\r
+/** ECDSA_SIG *ECDSA_SIG_new(void)\r
+ * allocates and initialize a ECDSA_SIG structure\r
+ * \return pointer to a ECDSA_SIG structure or NULL if an error occurred\r
+ */\r
+ECDSA_SIG *ECDSA_SIG_new(void);\r
+\r
+/** ECDSA_SIG_free\r
+ * frees a ECDSA_SIG structure\r
+ * \param a pointer to the ECDSA_SIG structure\r
+ */\r
+void     ECDSA_SIG_free(ECDSA_SIG *a);\r
+\r
+/** i2d_ECDSA_SIG\r
+ * DER encode content of ECDSA_SIG object (note: this function modifies *pp\r
+ * (*pp += length of the DER encoded signature)).\r
+ * \param a  pointer to the ECDSA_SIG object\r
+ * \param pp pointer to a unsigned char pointer for the output or NULL\r
+ * \return the length of the DER encoded ECDSA_SIG object or 0 \r
+ */\r
+int      i2d_ECDSA_SIG(const ECDSA_SIG *a, unsigned char **pp);\r
+\r
+/** d2i_ECDSA_SIG\r
+ * decodes a DER encoded ECDSA signature (note: this function changes *pp\r
+ * (*pp += len)). \r
+ * \param v pointer to ECDSA_SIG pointer (may be NULL)\r
+ * \param pp buffer with the DER encoded signature\r
+ * \param len bufferlength\r
+ * \return pointer to the decoded ECDSA_SIG structure (or NULL)\r
+ */\r
+ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **v, const unsigned char **pp, long len);\r
+\r
+/** ECDSA_do_sign\r
+ * computes the ECDSA signature of the given hash value using\r
+ * the supplied private key and returns the created signature.\r
+ * \param dgst pointer to the hash value\r
+ * \param dgst_len length of the hash value\r
+ * \param eckey pointer to the EC_KEY object containing a private EC key\r
+ * \return pointer to a ECDSA_SIG structure or NULL\r
+ */\r
+ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst,int dgst_len,EC_KEY *eckey);\r
+\r
+/** ECDSA_do_sign_ex\r
+ * computes ECDSA signature of a given hash value using the supplied\r
+ * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).\r
+ * \param dgst pointer to the hash value to sign\r
+ * \param dgstlen length of the hash value\r
+ * \param kinv optional pointer to a pre-computed inverse k\r
+ * \param rp optional pointer to the pre-computed rp value (see \r
+ *        ECDSA_sign_setup\r
+ * \param eckey pointer to the EC_KEY object containing a private EC key\r
+ * \return pointer to a ECDSA_SIG structure or NULL\r
+ */\r
+ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, \r
+               const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);\r
+\r
+/** ECDSA_do_verify\r
+ * verifies that the supplied signature is a valid ECDSA\r
+ * signature of the supplied hash value using the supplied public key.\r
+ * \param dgst pointer to the hash value\r
+ * \param dgst_len length of the hash value\r
+ * \param sig  pointer to the ECDSA_SIG structure\r
+ * \param eckey pointer to the EC_KEY object containing a public EC key\r
+ * \return 1 if the signature is valid, 0 if the signature is invalid and -1 on error\r
+ */\r
+int      ECDSA_do_verify(const unsigned char *dgst, int dgst_len,\r
+               const ECDSA_SIG *sig, EC_KEY* eckey);\r
+\r
+const ECDSA_METHOD *ECDSA_OpenSSL(void);\r
+\r
+/** ECDSA_set_default_method\r
+ * sets the default ECDSA method\r
+ * \param meth the new default ECDSA_METHOD\r
+ */\r
+void     ECDSA_set_default_method(const ECDSA_METHOD *meth);\r
+\r
+/** ECDSA_get_default_method\r
+ * returns the default ECDSA method\r
+ * \return pointer to ECDSA_METHOD structure containing the default method\r
+ */\r
+const ECDSA_METHOD *ECDSA_get_default_method(void);\r
+\r
+/** ECDSA_set_method\r
+ * sets method to be used for the ECDSA operations\r
+ * \param eckey pointer to the EC_KEY object\r
+ * \param meth  pointer to the new method\r
+ * \return 1 on success and 0 otherwise \r
+ */\r
+int      ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth);\r
+\r
+/** ECDSA_size\r
+ * returns the maximum length of the DER encoded signature\r
+ * \param  eckey pointer to a EC_KEY object\r
+ * \return numbers of bytes required for the DER encoded signature\r
+ */\r
+int      ECDSA_size(const EC_KEY *eckey);\r
+\r
+/** ECDSA_sign_setup\r
+ * precompute parts of the signing operation. \r
+ * \param eckey pointer to the EC_KEY object containing a private EC key\r
+ * \param ctx  pointer to a BN_CTX object (may be NULL)\r
+ * \param kinv pointer to a BIGNUM pointer for the inverse of k\r
+ * \param rp   pointer to a BIGNUM pointer for x coordinate of k * generator\r
+ * \return 1 on success and 0 otherwise\r
+ */\r
+int      ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, \r
+               BIGNUM **rp);\r
+\r
+/** ECDSA_sign\r
+ * computes ECDSA signature of a given hash value using the supplied\r
+ * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).\r
+ * \param type this parameter is ignored\r
+ * \param dgst pointer to the hash value to sign\r
+ * \param dgstlen length of the hash value\r
+ * \param sig buffer to hold the DER encoded signature\r
+ * \param siglen pointer to the length of the returned signature\r
+ * \param eckey pointer to the EC_KEY object containing a private EC key\r
+ * \return 1 on success and 0 otherwise\r
+ */\r
+int      ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, \r
+               unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);\r
+\r
+\r
+/** ECDSA_sign_ex\r
+ * computes ECDSA signature of a given hash value using the supplied\r
+ * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).\r
+ * \param type this parameter is ignored\r
+ * \param dgst pointer to the hash value to sign\r
+ * \param dgstlen length of the hash value\r
+ * \param sig buffer to hold the DER encoded signature\r
+ * \param siglen pointer to the length of the returned signature\r
+ * \param kinv optional pointer to a pre-computed inverse k\r
+ * \param rp optional pointer to the pre-computed rp value (see \r
+ *        ECDSA_sign_setup\r
+ * \param eckey pointer to the EC_KEY object containing a private EC key\r
+ * \return 1 on success and 0 otherwise\r
+ */\r
+int      ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, \r
+               unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv,\r
+               const BIGNUM *rp, EC_KEY *eckey);\r
+\r
+/** ECDSA_verify\r
+ * verifies that the given signature is valid ECDSA signature\r
+ * of the supplied hash value using the specified public key.\r
+ * \param type this parameter is ignored\r
+ * \param dgst pointer to the hash value \r
+ * \param dgstlen length of the hash value\r
+ * \param sig  pointer to the DER encoded signature\r
+ * \param siglen length of the DER encoded signature\r
+ * \param eckey pointer to the EC_KEY object containing a public EC key\r
+ * \return 1 if the signature is valid, 0 if the signature is invalid and -1 on error\r
+ */\r
+int      ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, \r
+               const unsigned char *sig, int siglen, EC_KEY *eckey);\r
+\r
+/* the standard ex_data functions */\r
+int      ECDSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new \r
+               *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+int      ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg);\r
+void     *ECDSA_get_ex_data(EC_KEY *d, int idx);\r
+\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_ECDSA_strings(void);\r
+\r
+/* Error codes for the ECDSA functions. */\r
+\r
+/* Function codes. */\r
+#define ECDSA_F_ECDSA_DATA_NEW_METHOD                   100\r
+#define ECDSA_F_ECDSA_DO_SIGN                           101\r
+#define ECDSA_F_ECDSA_DO_VERIFY                                 102\r
+#define ECDSA_F_ECDSA_SIGN_SETUP                        103\r
+\r
+/* Reason codes. */\r
+#define ECDSA_R_BAD_SIGNATURE                           100\r
+#define ECDSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE             101\r
+#define ECDSA_R_ERR_EC_LIB                              102\r
+#define ECDSA_R_MISSING_PARAMETERS                      103\r
+#define ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED                 104\r
+#define ECDSA_R_SIGNATURE_MALLOC_FAILED                         105\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/engine.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/engine.h
new file mode 100644 (file)
index 0000000..12564ae
--- /dev/null
@@ -0,0 +1,801 @@
+/* openssl/engine.h */\r
+/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL\r
+ * project 2000.\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 1999-2004 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    licensing@OpenSSL.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+/* ====================================================================\r
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.\r
+ * ECDH support in OpenSSL originally developed by \r
+ * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.\r
+ */\r
+\r
+#ifndef HEADER_ENGINE_H\r
+#define HEADER_ENGINE_H\r
+\r
+#include <openssl/opensslconf.h>\r
+\r
+#ifdef OPENSSL_NO_ENGINE\r
+#error ENGINE is disabled.\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#include <openssl/bn.h>\r
+#ifndef OPENSSL_NO_RSA\r
+#include <openssl/rsa.h>\r
+#endif\r
+#ifndef OPENSSL_NO_DSA\r
+#include <openssl/dsa.h>\r
+#endif\r
+#ifndef OPENSSL_NO_DH\r
+#include <openssl/dh.h>\r
+#endif\r
+#ifndef OPENSSL_NO_ECDH\r
+#include <openssl/ecdh.h>\r
+#endif\r
+#ifndef OPENSSL_NO_ECDSA\r
+#include <openssl/ecdsa.h>\r
+#endif\r
+#include <openssl/rand.h>\r
+#include <openssl/store.h>\r
+#include <openssl/ui.h>\r
+#include <openssl/err.h>\r
+#endif\r
+\r
+#include <openssl/ossl_typ.h>\r
+#include <openssl/symhacks.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Fixups for missing algorithms */\r
+#ifdef OPENSSL_NO_RSA\r
+typedef void RSA_METHOD;\r
+#endif\r
+#ifdef OPENSSL_NO_DSA\r
+typedef void DSA_METHOD;\r
+#endif\r
+#ifdef OPENSSL_NO_DH\r
+typedef void DH_METHOD;\r
+#endif\r
+#ifdef OPENSSL_NO_ECDH\r
+typedef void ECDH_METHOD;\r
+#endif\r
+#ifdef OPENSSL_NO_ECDSA\r
+typedef void ECDSA_METHOD;\r
+#endif\r
+\r
+/* These flags are used to control combinations of algorithm (methods)\r
+ * by bitwise "OR"ing. */\r
+#define ENGINE_METHOD_RSA              (unsigned int)0x0001\r
+#define ENGINE_METHOD_DSA              (unsigned int)0x0002\r
+#define ENGINE_METHOD_DH               (unsigned int)0x0004\r
+#define ENGINE_METHOD_RAND             (unsigned int)0x0008\r
+#define ENGINE_METHOD_ECDH             (unsigned int)0x0010\r
+#define ENGINE_METHOD_ECDSA            (unsigned int)0x0020\r
+#define ENGINE_METHOD_CIPHERS          (unsigned int)0x0040\r
+#define ENGINE_METHOD_DIGESTS          (unsigned int)0x0080\r
+#define ENGINE_METHOD_STORE            (unsigned int)0x0100\r
+/* Obvious all-or-nothing cases. */\r
+#define ENGINE_METHOD_ALL              (unsigned int)0xFFFF\r
+#define ENGINE_METHOD_NONE             (unsigned int)0x0000\r
+\r
+/* This(ese) flag(s) controls behaviour of the ENGINE_TABLE mechanism used\r
+ * internally to control registration of ENGINE implementations, and can be set\r
+ * by ENGINE_set_table_flags(). The "NOINIT" flag prevents attempts to\r
+ * initialise registered ENGINEs if they are not already initialised. */\r
+#define ENGINE_TABLE_FLAG_NOINIT       (unsigned int)0x0001\r
+\r
+/* ENGINE flags that can be set by ENGINE_set_flags(). */\r
+/* #define ENGINE_FLAGS_MALLOCED       0x0001 */ /* Not used */\r
+\r
+/* This flag is for ENGINEs that wish to handle the various 'CMD'-related\r
+ * control commands on their own. Without this flag, ENGINE_ctrl() handles these\r
+ * control commands on behalf of the ENGINE using their "cmd_defns" data. */\r
+#define ENGINE_FLAGS_MANUAL_CMD_CTRL   (int)0x0002\r
+\r
+/* This flag is for ENGINEs who return new duplicate structures when found via\r
+ * "ENGINE_by_id()". When an ENGINE must store state (eg. if ENGINE_ctrl()\r
+ * commands are called in sequence as part of some stateful process like\r
+ * key-generation setup and execution), it can set this flag - then each attempt\r
+ * to obtain the ENGINE will result in it being copied into a new structure.\r
+ * Normally, ENGINEs don't declare this flag so ENGINE_by_id() just increments\r
+ * the existing ENGINE's structural reference count. */\r
+#define ENGINE_FLAGS_BY_ID_COPY                (int)0x0004\r
+\r
+/* ENGINEs can support their own command types, and these flags are used in\r
+ * ENGINE_CTRL_GET_CMD_FLAGS to indicate to the caller what kind of input each\r
+ * command expects. Currently only numeric and string input is supported. If a\r
+ * control command supports none of the _NUMERIC, _STRING, or _NO_INPUT options,\r
+ * then it is regarded as an "internal" control command - and not for use in\r
+ * config setting situations. As such, they're not available to the\r
+ * ENGINE_ctrl_cmd_string() function, only raw ENGINE_ctrl() access. Changes to\r
+ * this list of 'command types' should be reflected carefully in\r
+ * ENGINE_cmd_is_executable() and ENGINE_ctrl_cmd_string(). */\r
+\r
+/* accepts a 'long' input value (3rd parameter to ENGINE_ctrl) */\r
+#define ENGINE_CMD_FLAG_NUMERIC                (unsigned int)0x0001\r
+/* accepts string input (cast from 'void*' to 'const char *', 4th parameter to\r
+ * ENGINE_ctrl) */\r
+#define ENGINE_CMD_FLAG_STRING         (unsigned int)0x0002\r
+/* Indicates that the control command takes *no* input. Ie. the control command\r
+ * is unparameterised. */\r
+#define ENGINE_CMD_FLAG_NO_INPUT       (unsigned int)0x0004\r
+/* Indicates that the control command is internal. This control command won't\r
+ * be shown in any output, and is only usable through the ENGINE_ctrl_cmd()\r
+ * function. */\r
+#define ENGINE_CMD_FLAG_INTERNAL       (unsigned int)0x0008\r
+\r
+/* NB: These 3 control commands are deprecated and should not be used. ENGINEs\r
+ * relying on these commands should compile conditional support for\r
+ * compatibility (eg. if these symbols are defined) but should also migrate the\r
+ * same functionality to their own ENGINE-specific control functions that can be\r
+ * "discovered" by calling applications. The fact these control commands\r
+ * wouldn't be "executable" (ie. usable by text-based config) doesn't change the\r
+ * fact that application code can find and use them without requiring per-ENGINE\r
+ * hacking. */\r
+\r
+/* These flags are used to tell the ctrl function what should be done.\r
+ * All command numbers are shared between all engines, even if some don't\r
+ * make sense to some engines.  In such a case, they do nothing but return\r
+ * the error ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED. */\r
+#define ENGINE_CTRL_SET_LOGSTREAM              1\r
+#define ENGINE_CTRL_SET_PASSWORD_CALLBACK      2\r
+#define ENGINE_CTRL_HUP                                3 /* Close and reinitialise any\r
+                                                    handles/connections etc. */\r
+#define ENGINE_CTRL_SET_USER_INTERFACE          4 /* Alternative to callback */\r
+#define ENGINE_CTRL_SET_CALLBACK_DATA           5 /* User-specific data, used\r
+                                                    when calling the password\r
+                                                    callback and the user\r
+                                                    interface */\r
+#define ENGINE_CTRL_LOAD_CONFIGURATION         6 /* Load a configuration, given\r
+                                                    a string that represents a\r
+                                                    file name or so */\r
+#define ENGINE_CTRL_LOAD_SECTION               7 /* Load data from a given\r
+                                                    section in the already loaded\r
+                                                    configuration */\r
+\r
+/* These control commands allow an application to deal with an arbitrary engine\r
+ * in a dynamic way. Warn: Negative return values indicate errors FOR THESE\r
+ * COMMANDS because zero is used to indicate 'end-of-list'. Other commands,\r
+ * including ENGINE-specific command types, return zero for an error.\r
+ *\r
+ * An ENGINE can choose to implement these ctrl functions, and can internally\r
+ * manage things however it chooses - it does so by setting the\r
+ * ENGINE_FLAGS_MANUAL_CMD_CTRL flag (using ENGINE_set_flags()). Otherwise the\r
+ * ENGINE_ctrl() code handles this on the ENGINE's behalf using the cmd_defns\r
+ * data (set using ENGINE_set_cmd_defns()). This means an ENGINE's ctrl()\r
+ * handler need only implement its own commands - the above "meta" commands will\r
+ * be taken care of. */\r
+\r
+/* Returns non-zero if the supplied ENGINE has a ctrl() handler. If "not", then\r
+ * all the remaining control commands will return failure, so it is worth\r
+ * checking this first if the caller is trying to "discover" the engine's\r
+ * capabilities and doesn't want errors generated unnecessarily. */\r
+#define ENGINE_CTRL_HAS_CTRL_FUNCTION          10\r
+/* Returns a positive command number for the first command supported by the\r
+ * engine. Returns zero if no ctrl commands are supported. */\r
+#define ENGINE_CTRL_GET_FIRST_CMD_TYPE         11\r
+/* The 'long' argument specifies a command implemented by the engine, and the\r
+ * return value is the next command supported, or zero if there are no more. */\r
+#define ENGINE_CTRL_GET_NEXT_CMD_TYPE          12\r
+/* The 'void*' argument is a command name (cast from 'const char *'), and the\r
+ * return value is the command that corresponds to it. */\r
+#define ENGINE_CTRL_GET_CMD_FROM_NAME          13\r
+/* The next two allow a command to be converted into its corresponding string\r
+ * form. In each case, the 'long' argument supplies the command. In the NAME_LEN\r
+ * case, the return value is the length of the command name (not counting a\r
+ * trailing EOL). In the NAME case, the 'void*' argument must be a string buffer\r
+ * large enough, and it will be populated with the name of the command (WITH a\r
+ * trailing EOL). */\r
+#define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD      14\r
+#define ENGINE_CTRL_GET_NAME_FROM_CMD          15\r
+/* The next two are similar but give a "short description" of a command. */\r
+#define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD      16\r
+#define ENGINE_CTRL_GET_DESC_FROM_CMD          17\r
+/* With this command, the return value is the OR'd combination of\r
+ * ENGINE_CMD_FLAG_*** values that indicate what kind of input a given\r
+ * engine-specific ctrl command expects. */\r
+#define ENGINE_CTRL_GET_CMD_FLAGS              18\r
+\r
+/* ENGINE implementations should start the numbering of their own control\r
+ * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). */\r
+#define ENGINE_CMD_BASE                                200\r
+\r
+/* NB: These 2 nCipher "chil" control commands are deprecated, and their\r
+ * functionality is now available through ENGINE-specific control commands\r
+ * (exposed through the above-mentioned 'CMD'-handling). Code using these 2\r
+ * commands should be migrated to the more general command handling before these\r
+ * are removed. */\r
+\r
+/* Flags specific to the nCipher "chil" engine */\r
+#define ENGINE_CTRL_CHIL_SET_FORKCHECK         100\r
+       /* Depending on the value of the (long)i argument, this sets or\r
+        * unsets the SimpleForkCheck flag in the CHIL API to enable or\r
+        * disable checking and workarounds for applications that fork().\r
+        */\r
+#define ENGINE_CTRL_CHIL_NO_LOCKING            101\r
+       /* This prevents the initialisation function from providing mutex\r
+        * callbacks to the nCipher library. */\r
+\r
+/* If an ENGINE supports its own specific control commands and wishes the\r
+ * framework to handle the above 'ENGINE_CMD_***'-manipulation commands on its\r
+ * behalf, it should supply a null-terminated array of ENGINE_CMD_DEFN entries\r
+ * to ENGINE_set_cmd_defns(). It should also implement a ctrl() handler that\r
+ * supports the stated commands (ie. the "cmd_num" entries as described by the\r
+ * array). NB: The array must be ordered in increasing order of cmd_num.\r
+ * "null-terminated" means that the last ENGINE_CMD_DEFN element has cmd_num set\r
+ * to zero and/or cmd_name set to NULL. */\r
+typedef struct ENGINE_CMD_DEFN_st\r
+       {\r
+       unsigned int cmd_num; /* The command number */\r
+       const char *cmd_name; /* The command name itself */\r
+       const char *cmd_desc; /* A short description of the command */\r
+       unsigned int cmd_flags; /* The input the command expects */\r
+       } ENGINE_CMD_DEFN;\r
+\r
+/* Generic function pointer */\r
+typedef int (*ENGINE_GEN_FUNC_PTR)(void);\r
+/* Generic function pointer taking no arguments */\r
+typedef int (*ENGINE_GEN_INT_FUNC_PTR)(ENGINE *);\r
+/* Specific control function pointer */\r
+typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)(void));\r
+/* Generic load_key function pointer */\r
+typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *,\r
+       UI_METHOD *ui_method, void *callback_data);\r
+/* These callback types are for an ENGINE's handler for cipher and digest logic.\r
+ * These handlers have these prototypes;\r
+ *   int foo(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid);\r
+ *   int foo(ENGINE *e, const EVP_MD **digest, const int **nids, int nid);\r
+ * Looking at how to implement these handlers in the case of cipher support, if\r
+ * the framework wants the EVP_CIPHER for 'nid', it will call;\r
+ *   foo(e, &p_evp_cipher, NULL, nid);    (return zero for failure)\r
+ * If the framework wants a list of supported 'nid's, it will call;\r
+ *   foo(e, NULL, &p_nids, 0); (returns number of 'nids' or -1 for error)\r
+ */\r
+/* Returns to a pointer to the array of supported cipher 'nid's. If the second\r
+ * parameter is non-NULL it is set to the size of the returned array. */\r
+typedef int (*ENGINE_CIPHERS_PTR)(ENGINE *, const EVP_CIPHER **, const int **, int);\r
+typedef int (*ENGINE_DIGESTS_PTR)(ENGINE *, const EVP_MD **, const int **, int);\r
+\r
+/* STRUCTURE functions ... all of these functions deal with pointers to ENGINE\r
+ * structures where the pointers have a "structural reference". This means that\r
+ * their reference is to allowed access to the structure but it does not imply\r
+ * that the structure is functional. To simply increment or decrement the\r
+ * structural reference count, use ENGINE_by_id and ENGINE_free. NB: This is not\r
+ * required when iterating using ENGINE_get_next as it will automatically\r
+ * decrement the structural reference count of the "current" ENGINE and\r
+ * increment the structural reference count of the ENGINE it returns (unless it\r
+ * is NULL). */\r
+\r
+/* Get the first/last "ENGINE" type available. */\r
+ENGINE *ENGINE_get_first(void);\r
+ENGINE *ENGINE_get_last(void);\r
+/* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */\r
+ENGINE *ENGINE_get_next(ENGINE *e);\r
+ENGINE *ENGINE_get_prev(ENGINE *e);\r
+/* Add another "ENGINE" type into the array. */\r
+int ENGINE_add(ENGINE *e);\r
+/* Remove an existing "ENGINE" type from the array. */\r
+int ENGINE_remove(ENGINE *e);\r
+/* Retrieve an engine from the list by its unique "id" value. */\r
+ENGINE *ENGINE_by_id(const char *id);\r
+/* Add all the built-in engines. */\r
+void ENGINE_load_openssl(void);\r
+void ENGINE_load_dynamic(void);\r
+#ifndef OPENSSL_NO_STATIC_ENGINE\r
+void ENGINE_load_4758cca(void);\r
+void ENGINE_load_aep(void);\r
+void ENGINE_load_atalla(void);\r
+void ENGINE_load_chil(void);\r
+void ENGINE_load_cswift(void);\r
+#ifndef OPENSSL_NO_GMP\r
+void ENGINE_load_gmp(void);\r
+#endif\r
+void ENGINE_load_nuron(void);\r
+void ENGINE_load_sureware(void);\r
+void ENGINE_load_ubsec(void);\r
+#endif\r
+void ENGINE_load_cryptodev(void);\r
+void ENGINE_load_padlock(void);\r
+void ENGINE_load_builtin_engines(void);\r
+\r
+/* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation\r
+ * "registry" handling. */\r
+unsigned int ENGINE_get_table_flags(void);\r
+void ENGINE_set_table_flags(unsigned int flags);\r
+\r
+/* Manage registration of ENGINEs per "table". For each type, there are 3\r
+ * functions;\r
+ *   ENGINE_register_***(e) - registers the implementation from 'e' (if it has one)\r
+ *   ENGINE_unregister_***(e) - unregister the implementation from 'e'\r
+ *   ENGINE_register_all_***() - call ENGINE_register_***() for each 'e' in the list\r
+ * Cleanup is automatically registered from each table when required, so\r
+ * ENGINE_cleanup() will reverse any "register" operations. */\r
+\r
+int ENGINE_register_RSA(ENGINE *e);\r
+void ENGINE_unregister_RSA(ENGINE *e);\r
+void ENGINE_register_all_RSA(void);\r
+\r
+int ENGINE_register_DSA(ENGINE *e);\r
+void ENGINE_unregister_DSA(ENGINE *e);\r
+void ENGINE_register_all_DSA(void);\r
+\r
+int ENGINE_register_ECDH(ENGINE *e);\r
+void ENGINE_unregister_ECDH(ENGINE *e);\r
+void ENGINE_register_all_ECDH(void);\r
+\r
+int ENGINE_register_ECDSA(ENGINE *e);\r
+void ENGINE_unregister_ECDSA(ENGINE *e);\r
+void ENGINE_register_all_ECDSA(void);\r
+\r
+int ENGINE_register_DH(ENGINE *e);\r
+void ENGINE_unregister_DH(ENGINE *e);\r
+void ENGINE_register_all_DH(void);\r
+\r
+int ENGINE_register_RAND(ENGINE *e);\r
+void ENGINE_unregister_RAND(ENGINE *e);\r
+void ENGINE_register_all_RAND(void);\r
+\r
+int ENGINE_register_STORE(ENGINE *e);\r
+void ENGINE_unregister_STORE(ENGINE *e);\r
+void ENGINE_register_all_STORE(void);\r
+\r
+int ENGINE_register_ciphers(ENGINE *e);\r
+void ENGINE_unregister_ciphers(ENGINE *e);\r
+void ENGINE_register_all_ciphers(void);\r
+\r
+int ENGINE_register_digests(ENGINE *e);\r
+void ENGINE_unregister_digests(ENGINE *e);\r
+void ENGINE_register_all_digests(void);\r
+\r
+/* These functions register all support from the above categories. Note, use of\r
+ * these functions can result in static linkage of code your application may not\r
+ * need. If you only need a subset of functionality, consider using more\r
+ * selective initialisation. */\r
+int ENGINE_register_complete(ENGINE *e);\r
+int ENGINE_register_all_complete(void);\r
+\r
+/* Send parametrised control commands to the engine. The possibilities to send\r
+ * down an integer, a pointer to data or a function pointer are provided. Any of\r
+ * the parameters may or may not be NULL, depending on the command number. In\r
+ * actuality, this function only requires a structural (rather than functional)\r
+ * reference to an engine, but many control commands may require the engine be\r
+ * functional. The caller should be aware of trying commands that require an\r
+ * operational ENGINE, and only use functional references in such situations. */\r
+int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));\r
+\r
+/* This function tests if an ENGINE-specific command is usable as a "setting".\r
+ * Eg. in an application's config file that gets processed through\r
+ * ENGINE_ctrl_cmd_string(). If this returns zero, it is not available to\r
+ * ENGINE_ctrl_cmd_string(), only ENGINE_ctrl(). */\r
+int ENGINE_cmd_is_executable(ENGINE *e, int cmd);\r
+\r
+/* This function works like ENGINE_ctrl() with the exception of taking a\r
+ * command name instead of a command number, and can handle optional commands.\r
+ * See the comment on ENGINE_ctrl_cmd_string() for an explanation on how to\r
+ * use the cmd_name and cmd_optional. */\r
+int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,\r
+        long i, void *p, void (*f)(void), int cmd_optional);\r
+\r
+/* This function passes a command-name and argument to an ENGINE. The cmd_name\r
+ * is converted to a command number and the control command is called using\r
+ * 'arg' as an argument (unless the ENGINE doesn't support such a command, in\r
+ * which case no control command is called). The command is checked for input\r
+ * flags, and if necessary the argument will be converted to a numeric value. If\r
+ * cmd_optional is non-zero, then if the ENGINE doesn't support the given\r
+ * cmd_name the return value will be success anyway. This function is intended\r
+ * for applications to use so that users (or config files) can supply\r
+ * engine-specific config data to the ENGINE at run-time to control behaviour of\r
+ * specific engines. As such, it shouldn't be used for calling ENGINE_ctrl()\r
+ * functions that return data, deal with binary data, or that are otherwise\r
+ * supposed to be used directly through ENGINE_ctrl() in application code. Any\r
+ * "return" data from an ENGINE_ctrl() operation in this function will be lost -\r
+ * the return value is interpreted as failure if the return value is zero,\r
+ * success otherwise, and this function returns a boolean value as a result. In\r
+ * other words, vendors of 'ENGINE'-enabled devices should write ENGINE\r
+ * implementations with parameterisations that work in this scheme, so that\r
+ * compliant ENGINE-based applications can work consistently with the same\r
+ * configuration for the same ENGINE-enabled devices, across applications. */\r
+int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,\r
+                               int cmd_optional);\r
+\r
+/* These functions are useful for manufacturing new ENGINE structures. They\r
+ * don't address reference counting at all - one uses them to populate an ENGINE\r
+ * structure with personalised implementations of things prior to using it\r
+ * directly or adding it to the builtin ENGINE list in OpenSSL. These are also\r
+ * here so that the ENGINE structure doesn't have to be exposed and break binary\r
+ * compatibility! */\r
+ENGINE *ENGINE_new(void);\r
+int ENGINE_free(ENGINE *e);\r
+int ENGINE_up_ref(ENGINE *e);\r
+int ENGINE_set_id(ENGINE *e, const char *id);\r
+int ENGINE_set_name(ENGINE *e, const char *name);\r
+int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);\r
+int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);\r
+int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth);\r
+int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth);\r
+int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);\r
+int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);\r
+int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth);\r
+int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);\r
+int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);\r
+int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);\r
+int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);\r
+int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);\r
+int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);\r
+int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);\r
+int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);\r
+int ENGINE_set_flags(ENGINE *e, int flags);\r
+int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);\r
+/* These functions allow control over any per-structure ENGINE data. */\r
+int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,\r
+               CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);\r
+void *ENGINE_get_ex_data(const ENGINE *e, int idx);\r
+\r
+/* This function cleans up anything that needs it. Eg. the ENGINE_add() function\r
+ * automatically ensures the list cleanup function is registered to be called\r
+ * from ENGINE_cleanup(). Similarly, all ENGINE_register_*** functions ensure\r
+ * ENGINE_cleanup() will clean up after them. */\r
+void ENGINE_cleanup(void);\r
+\r
+/* These return values from within the ENGINE structure. These can be useful\r
+ * with functional references as well as structural references - it depends\r
+ * which you obtained. Using the result for functional purposes if you only\r
+ * obtained a structural reference may be problematic! */\r
+const char *ENGINE_get_id(const ENGINE *e);\r
+const char *ENGINE_get_name(const ENGINE *e);\r
+const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);\r
+const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);\r
+const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e);\r
+const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e);\r
+const DH_METHOD *ENGINE_get_DH(const ENGINE *e);\r
+const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);\r
+const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e);\r
+ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);\r
+ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);\r
+ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);\r
+ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);\r
+ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);\r
+ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);\r
+ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);\r
+ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);\r
+const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);\r
+const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);\r
+const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);\r
+int ENGINE_get_flags(const ENGINE *e);\r
+\r
+/* FUNCTIONAL functions. These functions deal with ENGINE structures\r
+ * that have (or will) be initialised for use. Broadly speaking, the\r
+ * structural functions are useful for iterating the list of available\r
+ * engine types, creating new engine types, and other "list" operations.\r
+ * These functions actually deal with ENGINEs that are to be used. As\r
+ * such these functions can fail (if applicable) when particular\r
+ * engines are unavailable - eg. if a hardware accelerator is not\r
+ * attached or not functioning correctly. Each ENGINE has 2 reference\r
+ * counts; structural and functional. Every time a functional reference\r
+ * is obtained or released, a corresponding structural reference is\r
+ * automatically obtained or released too. */\r
+\r
+/* Initialise a engine type for use (or up its reference count if it's\r
+ * already in use). This will fail if the engine is not currently\r
+ * operational and cannot initialise. */\r
+int ENGINE_init(ENGINE *e);\r
+/* Free a functional reference to a engine type. This does not require\r
+ * a corresponding call to ENGINE_free as it also releases a structural\r
+ * reference. */\r
+int ENGINE_finish(ENGINE *e);\r
+\r
+/* The following functions handle keys that are stored in some secondary\r
+ * location, handled by the engine.  The storage may be on a card or\r
+ * whatever. */\r
+EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,\r
+       UI_METHOD *ui_method, void *callback_data);\r
+EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,\r
+       UI_METHOD *ui_method, void *callback_data);\r
+\r
+/* This returns a pointer for the current ENGINE structure that\r
+ * is (by default) performing any RSA operations. The value returned\r
+ * is an incremented reference, so it should be free'd (ENGINE_finish)\r
+ * before it is discarded. */\r
+ENGINE *ENGINE_get_default_RSA(void);\r
+/* Same for the other "methods" */\r
+ENGINE *ENGINE_get_default_DSA(void);\r
+ENGINE *ENGINE_get_default_ECDH(void);\r
+ENGINE *ENGINE_get_default_ECDSA(void);\r
+ENGINE *ENGINE_get_default_DH(void);\r
+ENGINE *ENGINE_get_default_RAND(void);\r
+/* These functions can be used to get a functional reference to perform\r
+ * ciphering or digesting corresponding to "nid". */\r
+ENGINE *ENGINE_get_cipher_engine(int nid);\r
+ENGINE *ENGINE_get_digest_engine(int nid);\r
+\r
+/* This sets a new default ENGINE structure for performing RSA\r
+ * operations. If the result is non-zero (success) then the ENGINE\r
+ * structure will have had its reference count up'd so the caller\r
+ * should still free their own reference 'e'. */\r
+int ENGINE_set_default_RSA(ENGINE *e);\r
+int ENGINE_set_default_string(ENGINE *e, const char *def_list);\r
+/* Same for the other "methods" */\r
+int ENGINE_set_default_DSA(ENGINE *e);\r
+int ENGINE_set_default_ECDH(ENGINE *e);\r
+int ENGINE_set_default_ECDSA(ENGINE *e);\r
+int ENGINE_set_default_DH(ENGINE *e);\r
+int ENGINE_set_default_RAND(ENGINE *e);\r
+int ENGINE_set_default_ciphers(ENGINE *e);\r
+int ENGINE_set_default_digests(ENGINE *e);\r
+\r
+/* The combination "set" - the flags are bitwise "OR"d from the\r
+ * ENGINE_METHOD_*** defines above. As with the "ENGINE_register_complete()"\r
+ * function, this function can result in unnecessary static linkage. If your\r
+ * application requires only specific functionality, consider using more\r
+ * selective functions. */\r
+int ENGINE_set_default(ENGINE *e, unsigned int flags);\r
+\r
+void ENGINE_add_conf_module(void);\r
+\r
+/* Deprecated functions ... */\r
+/* int ENGINE_clear_defaults(void); */\r
+\r
+/**************************/\r
+/* DYNAMIC ENGINE SUPPORT */\r
+/**************************/\r
+\r
+/* Binary/behaviour compatibility levels */\r
+#define OSSL_DYNAMIC_VERSION           (unsigned long)0x00020000\r
+/* Binary versions older than this are too old for us (whether we're a loader or\r
+ * a loadee) */\r
+#define OSSL_DYNAMIC_OLDEST            (unsigned long)0x00020000\r
+\r
+/* When compiling an ENGINE entirely as an external shared library, loadable by\r
+ * the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' structure\r
+ * type provides the calling application's (or library's) error functionality\r
+ * and memory management function pointers to the loaded library. These should\r
+ * be used/set in the loaded library code so that the loading application's\r
+ * 'state' will be used/changed in all operations. The 'static_state' pointer\r
+ * allows the loaded library to know if it shares the same static data as the\r
+ * calling application (or library), and thus whether these callbacks need to be\r
+ * set or not. */\r
+typedef void *(*dyn_MEM_malloc_cb)(size_t);\r
+typedef void *(*dyn_MEM_realloc_cb)(void *, size_t);\r
+typedef void (*dyn_MEM_free_cb)(void *);\r
+typedef struct st_dynamic_MEM_fns {\r
+       dyn_MEM_malloc_cb                       malloc_cb;\r
+       dyn_MEM_realloc_cb                      realloc_cb;\r
+       dyn_MEM_free_cb                         free_cb;\r
+       } dynamic_MEM_fns;\r
+/* FIXME: Perhaps the memory and locking code (crypto.h) should declare and use\r
+ * these types so we (and any other dependant code) can simplify a bit?? */\r
+typedef void (*dyn_lock_locking_cb)(int,int,const char *,int);\r
+typedef int (*dyn_lock_add_lock_cb)(int*,int,int,const char *,int);\r
+typedef struct CRYPTO_dynlock_value *(*dyn_dynlock_create_cb)(\r
+                                               const char *,int);\r
+typedef void (*dyn_dynlock_lock_cb)(int,struct CRYPTO_dynlock_value *,\r
+                                               const char *,int);\r
+typedef void (*dyn_dynlock_destroy_cb)(struct CRYPTO_dynlock_value *,\r
+                                               const char *,int);\r
+typedef struct st_dynamic_LOCK_fns {\r
+       dyn_lock_locking_cb                     lock_locking_cb;\r
+       dyn_lock_add_lock_cb                    lock_add_lock_cb;\r
+       dyn_dynlock_create_cb                   dynlock_create_cb;\r
+       dyn_dynlock_lock_cb                     dynlock_lock_cb;\r
+       dyn_dynlock_destroy_cb                  dynlock_destroy_cb;\r
+       } dynamic_LOCK_fns;\r
+/* The top-level structure */\r
+typedef struct st_dynamic_fns {\r
+       void                                    *static_state;\r
+       const ERR_FNS                           *err_fns;\r
+       const CRYPTO_EX_DATA_IMPL               *ex_data_fns;\r
+       dynamic_MEM_fns                         mem_fns;\r
+       dynamic_LOCK_fns                        lock_fns;\r
+       } dynamic_fns;\r
+\r
+/* The version checking function should be of this prototype. NB: The\r
+ * ossl_version value passed in is the OSSL_DYNAMIC_VERSION of the loading code.\r
+ * If this function returns zero, it indicates a (potential) version\r
+ * incompatibility and the loaded library doesn't believe it can proceed.\r
+ * Otherwise, the returned value is the (latest) version supported by the\r
+ * loading library. The loader may still decide that the loaded code's version\r
+ * is unsatisfactory and could veto the load. The function is expected to\r
+ * be implemented with the symbol name "v_check", and a default implementation\r
+ * can be fully instantiated with IMPLEMENT_DYNAMIC_CHECK_FN(). */\r
+typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version);\r
+#define IMPLEMENT_DYNAMIC_CHECK_FN() \\r
+       unsigned long v_check(unsigned long v) { \\r
+               if(v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \\r
+               return 0; }\r
+\r
+/* This function is passed the ENGINE structure to initialise with its own\r
+ * function and command settings. It should not adjust the structural or\r
+ * functional reference counts. If this function returns zero, (a) the load will\r
+ * be aborted, (b) the previous ENGINE state will be memcpy'd back onto the\r
+ * structure, and (c) the shared library will be unloaded. So implementations\r
+ * should do their own internal cleanup in failure circumstances otherwise they\r
+ * could leak. The 'id' parameter, if non-NULL, represents the ENGINE id that\r
+ * the loader is looking for. If this is NULL, the shared library can choose to\r
+ * return failure or to initialise a 'default' ENGINE. If non-NULL, the shared\r
+ * library must initialise only an ENGINE matching the passed 'id'. The function\r
+ * is expected to be implemented with the symbol name "bind_engine". A standard\r
+ * implementation can be instantiated with IMPLEMENT_DYNAMIC_BIND_FN(fn) where\r
+ * the parameter 'fn' is a callback function that populates the ENGINE structure\r
+ * and returns an int value (zero for failure). 'fn' should have prototype;\r
+ *    [static] int fn(ENGINE *e, const char *id); */\r
+typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id,\r
+                               const dynamic_fns *fns);\r
+#define IMPLEMENT_DYNAMIC_BIND_FN(fn) \\r
+       int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \\r
+               if(ENGINE_get_static_state() == fns->static_state) goto skip_cbs; \\r
+               if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \\r
+                       fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \\r
+                       return 0; \\r
+               CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \\r
+               CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \\r
+               CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \\r
+               CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \\r
+               CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \\r
+               if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \\r
+                       return 0; \\r
+               if(!ERR_set_implementation(fns->err_fns)) return 0; \\r
+       skip_cbs: \\r
+               if(!fn(e,id)) return 0; \\r
+               return 1; }\r
+\r
+/* If the loading application (or library) and the loaded ENGINE library share\r
+ * the same static data (eg. they're both dynamically linked to the same\r
+ * libcrypto.so) we need a way to avoid trying to set system callbacks - this\r
+ * would fail, and for the same reason that it's unnecessary to try. If the\r
+ * loaded ENGINE has (or gets from through the loader) its own copy of the\r
+ * libcrypto static data, we will need to set the callbacks. The easiest way to\r
+ * detect this is to have a function that returns a pointer to some static data\r
+ * and let the loading application and loaded ENGINE compare their respective\r
+ * values. */\r
+void *ENGINE_get_static_state(void);\r
+\r
+#if defined(__OpenBSD__) || defined(__FreeBSD__)\r
+void ENGINE_setup_bsd_cryptodev(void);\r
+#endif\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_ENGINE_strings(void);\r
+\r
+/* Error codes for the ENGINE functions. */\r
+\r
+/* Function codes. */\r
+#define ENGINE_F_DYNAMIC_CTRL                           180\r
+#define ENGINE_F_DYNAMIC_GET_DATA_CTX                   181\r
+#define ENGINE_F_DYNAMIC_LOAD                           182\r
+#define ENGINE_F_DYNAMIC_SET_DATA_CTX                   183\r
+#define ENGINE_F_ENGINE_ADD                             105\r
+#define ENGINE_F_ENGINE_BY_ID                           106\r
+#define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE               170\r
+#define ENGINE_F_ENGINE_CTRL                            142\r
+#define ENGINE_F_ENGINE_CTRL_CMD                        178\r
+#define ENGINE_F_ENGINE_CTRL_CMD_STRING                         171\r
+#define ENGINE_F_ENGINE_FINISH                          107\r
+#define ENGINE_F_ENGINE_FREE_UTIL                       108\r
+#define ENGINE_F_ENGINE_GET_CIPHER                      185\r
+#define ENGINE_F_ENGINE_GET_DEFAULT_TYPE                177\r
+#define ENGINE_F_ENGINE_GET_DIGEST                      186\r
+#define ENGINE_F_ENGINE_GET_NEXT                        115\r
+#define ENGINE_F_ENGINE_GET_PREV                        116\r
+#define ENGINE_F_ENGINE_INIT                            119\r
+#define ENGINE_F_ENGINE_LIST_ADD                        120\r
+#define ENGINE_F_ENGINE_LIST_REMOVE                     121\r
+#define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY                150\r
+#define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY                         151\r
+#define ENGINE_F_ENGINE_NEW                             122\r
+#define ENGINE_F_ENGINE_REMOVE                          123\r
+#define ENGINE_F_ENGINE_SET_DEFAULT_STRING              189\r
+#define ENGINE_F_ENGINE_SET_DEFAULT_TYPE                126\r
+#define ENGINE_F_ENGINE_SET_ID                          129\r
+#define ENGINE_F_ENGINE_SET_NAME                        130\r
+#define ENGINE_F_ENGINE_TABLE_REGISTER                  184\r
+#define ENGINE_F_ENGINE_UNLOAD_KEY                      152\r
+#define ENGINE_F_ENGINE_UNLOCKED_FINISH                         191\r
+#define ENGINE_F_ENGINE_UP_REF                          190\r
+#define ENGINE_F_INT_CTRL_HELPER                        172\r
+#define ENGINE_F_INT_ENGINE_CONFIGURE                   188\r
+#define ENGINE_F_INT_ENGINE_MODULE_INIT                         187\r
+#define ENGINE_F_LOG_MESSAGE                            141\r
+\r
+/* Reason codes. */\r
+#define ENGINE_R_ALREADY_LOADED                                 100\r
+#define ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER               133\r
+#define ENGINE_R_CMD_NOT_EXECUTABLE                     134\r
+#define ENGINE_R_COMMAND_TAKES_INPUT                    135\r
+#define ENGINE_R_COMMAND_TAKES_NO_INPUT                         136\r
+#define ENGINE_R_CONFLICTING_ENGINE_ID                  103\r
+#define ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED           119\r
+#define ENGINE_R_DH_NOT_IMPLEMENTED                     139\r
+#define ENGINE_R_DSA_NOT_IMPLEMENTED                    140\r
+#define ENGINE_R_DSO_FAILURE                            104\r
+#define ENGINE_R_DSO_NOT_FOUND                          132\r
+#define ENGINE_R_ENGINES_SECTION_ERROR                  148\r
+#define ENGINE_R_ENGINE_IS_NOT_IN_LIST                  105\r
+#define ENGINE_R_ENGINE_SECTION_ERROR                   149\r
+#define ENGINE_R_FAILED_LOADING_PRIVATE_KEY             128\r
+#define ENGINE_R_FAILED_LOADING_PUBLIC_KEY              129\r
+#define ENGINE_R_FINISH_FAILED                          106\r
+#define ENGINE_R_GET_HANDLE_FAILED                      107\r
+#define ENGINE_R_ID_OR_NAME_MISSING                     108\r
+#define ENGINE_R_INIT_FAILED                            109\r
+#define ENGINE_R_INTERNAL_LIST_ERROR                    110\r
+#define ENGINE_R_INVALID_ARGUMENT                       143\r
+#define ENGINE_R_INVALID_CMD_NAME                       137\r
+#define ENGINE_R_INVALID_CMD_NUMBER                     138\r
+#define ENGINE_R_INVALID_INIT_VALUE                     151\r
+#define ENGINE_R_INVALID_STRING                                 150\r
+#define ENGINE_R_NOT_INITIALISED                        117\r
+#define ENGINE_R_NOT_LOADED                             112\r
+#define ENGINE_R_NO_CONTROL_FUNCTION                    120\r
+#define ENGINE_R_NO_INDEX                               144\r
+#define ENGINE_R_NO_LOAD_FUNCTION                       125\r
+#define ENGINE_R_NO_REFERENCE                           130\r
+#define ENGINE_R_NO_SUCH_ENGINE                                 116\r
+#define ENGINE_R_NO_UNLOAD_FUNCTION                     126\r
+#define ENGINE_R_PROVIDE_PARAMETERS                     113\r
+#define ENGINE_R_RSA_NOT_IMPLEMENTED                    141\r
+#define ENGINE_R_UNIMPLEMENTED_CIPHER                   146\r
+#define ENGINE_R_UNIMPLEMENTED_DIGEST                   147\r
+#define ENGINE_R_VERSION_INCOMPATIBILITY                145\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/err.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/err.h
new file mode 100644 (file)
index 0000000..ed38141
--- /dev/null
@@ -0,0 +1,318 @@
+/* crypto/err/err.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_ERR_H\r
+#define HEADER_ERR_H\r
+\r
+#include <openssl/e_os2.h>\r
+\r
+#ifndef OPENSSL_NO_FP_API\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#endif\r
+\r
+#include <openssl/ossl_typ.h>\r
+#ifndef OPENSSL_NO_BIO\r
+#include <openssl/bio.h>\r
+#endif\r
+#ifndef OPENSSL_NO_LHASH\r
+#include <openssl/lhash.h>\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_ERR\r
+#define ERR_PUT_error(a,b,c,d,e)       ERR_put_error(a,b,c,d,e)\r
+#else\r
+#define ERR_PUT_error(a,b,c,d,e)       ERR_put_error(a,b,c,NULL,0)\r
+#endif\r
+\r
+#include <errno.h>\r
+\r
+#define ERR_TXT_MALLOCED       0x01\r
+#define ERR_TXT_STRING         0x02\r
+\r
+#define ERR_FLAG_MARK          0x01\r
+\r
+#define ERR_NUM_ERRORS 16\r
+typedef struct err_state_st\r
+       {\r
+       unsigned long pid;\r
+       int err_flags[ERR_NUM_ERRORS];\r
+       unsigned long err_buffer[ERR_NUM_ERRORS];\r
+       char *err_data[ERR_NUM_ERRORS];\r
+       int err_data_flags[ERR_NUM_ERRORS];\r
+       const char *err_file[ERR_NUM_ERRORS];\r
+       int err_line[ERR_NUM_ERRORS];\r
+       int top,bottom;\r
+       } ERR_STATE;\r
+\r
+/* library */\r
+#define ERR_LIB_NONE           1\r
+#define ERR_LIB_SYS            2\r
+#define ERR_LIB_BN             3\r
+#define ERR_LIB_RSA            4\r
+#define ERR_LIB_DH             5\r
+#define ERR_LIB_EVP            6\r
+#define ERR_LIB_BUF            7\r
+#define ERR_LIB_OBJ            8\r
+#define ERR_LIB_PEM            9\r
+#define ERR_LIB_DSA            10\r
+#define ERR_LIB_X509           11\r
+/* #define ERR_LIB_METH         12 */\r
+#define ERR_LIB_ASN1           13\r
+#define ERR_LIB_CONF           14\r
+#define ERR_LIB_CRYPTO         15\r
+#define ERR_LIB_EC             16\r
+#define ERR_LIB_SSL            20\r
+/* #define ERR_LIB_SSL23        21 */\r
+/* #define ERR_LIB_SSL2         22 */\r
+/* #define ERR_LIB_SSL3         23 */\r
+/* #define ERR_LIB_RSAREF       30 */\r
+/* #define ERR_LIB_PROXY        31 */\r
+#define ERR_LIB_BIO            32\r
+#define ERR_LIB_PKCS7          33\r
+#define ERR_LIB_X509V3         34\r
+#define ERR_LIB_PKCS12         35\r
+#define ERR_LIB_RAND           36\r
+#define ERR_LIB_DSO            37\r
+#define ERR_LIB_ENGINE         38\r
+#define ERR_LIB_OCSP            39\r
+#define ERR_LIB_UI              40\r
+#define ERR_LIB_COMP            41\r
+#define ERR_LIB_ECDSA          42\r
+#define ERR_LIB_ECDH           43\r
+#define ERR_LIB_STORE           44\r
+\r
+#define ERR_LIB_USER           128\r
+\r
+#define SYSerr(f,r)  ERR_PUT_error(ERR_LIB_SYS,(f),(r),__FILE__,__LINE__)\r
+#define BNerr(f,r)   ERR_PUT_error(ERR_LIB_BN,(f),(r),__FILE__,__LINE__)\r
+#define RSAerr(f,r)  ERR_PUT_error(ERR_LIB_RSA,(f),(r),__FILE__,__LINE__)\r
+#define DHerr(f,r)   ERR_PUT_error(ERR_LIB_DH,(f),(r),__FILE__,__LINE__)\r
+#define EVPerr(f,r)  ERR_PUT_error(ERR_LIB_EVP,(f),(r),__FILE__,__LINE__)\r
+#define BUFerr(f,r)  ERR_PUT_error(ERR_LIB_BUF,(f),(r),__FILE__,__LINE__)\r
+#define OBJerr(f,r)  ERR_PUT_error(ERR_LIB_OBJ,(f),(r),__FILE__,__LINE__)\r
+#define PEMerr(f,r)  ERR_PUT_error(ERR_LIB_PEM,(f),(r),__FILE__,__LINE__)\r
+#define DSAerr(f,r)  ERR_PUT_error(ERR_LIB_DSA,(f),(r),__FILE__,__LINE__)\r
+#define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),__FILE__,__LINE__)\r
+#define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),__FILE__,__LINE__)\r
+#define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),__FILE__,__LINE__)\r
+#define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),__FILE__,__LINE__)\r
+#define ECerr(f,r)   ERR_PUT_error(ERR_LIB_EC,(f),(r),__FILE__,__LINE__)\r
+#define SSLerr(f,r)  ERR_PUT_error(ERR_LIB_SSL,(f),(r),__FILE__,__LINE__)\r
+#define BIOerr(f,r)  ERR_PUT_error(ERR_LIB_BIO,(f),(r),__FILE__,__LINE__)\r
+#define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),__FILE__,__LINE__)\r
+#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),__FILE__,__LINE__)\r
+#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),__FILE__,__LINE__)\r
+#define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),__FILE__,__LINE__)\r
+#define DSOerr(f,r) ERR_PUT_error(ERR_LIB_DSO,(f),(r),__FILE__,__LINE__)\r
+#define ENGINEerr(f,r) ERR_PUT_error(ERR_LIB_ENGINE,(f),(r),__FILE__,__LINE__)\r
+#define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),__FILE__,__LINE__)\r
+#define UIerr(f,r) ERR_PUT_error(ERR_LIB_UI,(f),(r),__FILE__,__LINE__)\r
+#define COMPerr(f,r) ERR_PUT_error(ERR_LIB_COMP,(f),(r),__FILE__,__LINE__)\r
+#define ECDSAerr(f,r)  ERR_PUT_error(ERR_LIB_ECDSA,(f),(r),__FILE__,__LINE__)\r
+#define ECDHerr(f,r)  ERR_PUT_error(ERR_LIB_ECDH,(f),(r),__FILE__,__LINE__)\r
+#define STOREerr(f,r) ERR_PUT_error(ERR_LIB_STORE,(f),(r),__FILE__,__LINE__)\r
+\r
+/* Borland C seems too stupid to be able to shift and do longs in\r
+ * the pre-processor :-( */\r
+#define ERR_PACK(l,f,r)                (((((unsigned long)l)&0xffL)*0x1000000)| \\r
+                               ((((unsigned long)f)&0xfffL)*0x1000)| \\r
+                               ((((unsigned long)r)&0xfffL)))\r
+#define ERR_GET_LIB(l)         (int)((((unsigned long)l)>>24L)&0xffL)\r
+#define ERR_GET_FUNC(l)                (int)((((unsigned long)l)>>12L)&0xfffL)\r
+#define ERR_GET_REASON(l)      (int)((l)&0xfffL)\r
+#define ERR_FATAL_ERROR(l)     (int)((l)&ERR_R_FATAL)\r
+\r
+\r
+/* OS functions */\r
+#define SYS_F_FOPEN            1\r
+#define SYS_F_CONNECT          2\r
+#define SYS_F_GETSERVBYNAME    3\r
+#define SYS_F_SOCKET           4\r
+#define SYS_F_IOCTLSOCKET      5\r
+#define SYS_F_BIND             6\r
+#define SYS_F_LISTEN           7\r
+#define SYS_F_ACCEPT           8\r
+#define SYS_F_WSASTARTUP       9 /* Winsock stuff */\r
+#define SYS_F_OPENDIR          10\r
+#define SYS_F_FREAD            11\r
+\r
+\r
+/* reasons */\r
+#define ERR_R_SYS_LIB  ERR_LIB_SYS       /* 2 */\r
+#define ERR_R_BN_LIB   ERR_LIB_BN        /* 3 */\r
+#define ERR_R_RSA_LIB  ERR_LIB_RSA       /* 4 */\r
+#define ERR_R_DH_LIB   ERR_LIB_DH        /* 5 */\r
+#define ERR_R_EVP_LIB  ERR_LIB_EVP       /* 6 */\r
+#define ERR_R_BUF_LIB  ERR_LIB_BUF       /* 7 */\r
+#define ERR_R_OBJ_LIB  ERR_LIB_OBJ       /* 8 */\r
+#define ERR_R_PEM_LIB  ERR_LIB_PEM       /* 9 */\r
+#define ERR_R_DSA_LIB  ERR_LIB_DSA      /* 10 */\r
+#define ERR_R_X509_LIB ERR_LIB_X509     /* 11 */\r
+#define ERR_R_ASN1_LIB ERR_LIB_ASN1     /* 13 */\r
+#define ERR_R_CONF_LIB ERR_LIB_CONF     /* 14 */\r
+#define ERR_R_CRYPTO_LIB ERR_LIB_CRYPTO  /* 15 */\r
+#define ERR_R_EC_LIB   ERR_LIB_EC       /* 16 */\r
+#define ERR_R_SSL_LIB  ERR_LIB_SSL      /* 20 */\r
+#define ERR_R_BIO_LIB  ERR_LIB_BIO      /* 32 */\r
+#define ERR_R_PKCS7_LIB        ERR_LIB_PKCS7    /* 33 */\r
+#define ERR_R_X509V3_LIB ERR_LIB_X509V3  /* 34 */\r
+#define ERR_R_PKCS12_LIB ERR_LIB_PKCS12  /* 35 */\r
+#define ERR_R_RAND_LIB ERR_LIB_RAND     /* 36 */\r
+#define ERR_R_DSO_LIB  ERR_LIB_DSO      /* 37 */\r
+#define ERR_R_ENGINE_LIB ERR_LIB_ENGINE  /* 38 */\r
+#define ERR_R_OCSP_LIB  ERR_LIB_OCSP     /* 39 */\r
+#define ERR_R_UI_LIB    ERR_LIB_UI       /* 40 */\r
+#define ERR_R_COMP_LIB ERR_LIB_COMP     /* 41 */\r
+#define ERR_R_ECDSA_LIB ERR_LIB_ECDSA   /* 42 */\r
+#define ERR_R_ECDH_LIB  ERR_LIB_ECDH    /* 43 */\r
+#define ERR_R_STORE_LIB ERR_LIB_STORE    /* 44 */\r
+\r
+#define ERR_R_NESTED_ASN1_ERROR                        58\r
+#define ERR_R_BAD_ASN1_OBJECT_HEADER           59\r
+#define ERR_R_BAD_GET_ASN1_OBJECT_CALL         60\r
+#define ERR_R_EXPECTING_AN_ASN1_SEQUENCE       61\r
+#define ERR_R_ASN1_LENGTH_MISMATCH             62\r
+#define ERR_R_MISSING_ASN1_EOS                 63\r
+\r
+/* fatal error */\r
+#define ERR_R_FATAL                            64\r
+#define        ERR_R_MALLOC_FAILURE                    (1|ERR_R_FATAL)\r
+#define        ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED       (2|ERR_R_FATAL)\r
+#define        ERR_R_PASSED_NULL_PARAMETER             (3|ERR_R_FATAL)\r
+#define        ERR_R_INTERNAL_ERROR                    (4|ERR_R_FATAL)\r
+#define        ERR_R_DISABLED                          (5|ERR_R_FATAL)\r
+\r
+/* 99 is the maximum possible ERR_R_... code, higher values\r
+ * are reserved for the individual libraries */\r
+\r
+\r
+typedef struct ERR_string_data_st\r
+       {\r
+       unsigned long error;\r
+       const char *string;\r
+       } ERR_STRING_DATA;\r
+\r
+void ERR_put_error(int lib, int func,int reason,const char *file,int line);\r
+void ERR_set_error_data(char *data,int flags);\r
+\r
+unsigned long ERR_get_error(void);\r
+unsigned long ERR_get_error_line(const char **file,int *line);\r
+unsigned long ERR_get_error_line_data(const char **file,int *line,\r
+                                     const char **data, int *flags);\r
+unsigned long ERR_peek_error(void);\r
+unsigned long ERR_peek_error_line(const char **file,int *line);\r
+unsigned long ERR_peek_error_line_data(const char **file,int *line,\r
+                                      const char **data,int *flags);\r
+unsigned long ERR_peek_last_error(void);\r
+unsigned long ERR_peek_last_error_line(const char **file,int *line);\r
+unsigned long ERR_peek_last_error_line_data(const char **file,int *line,\r
+                                      const char **data,int *flags);\r
+void ERR_clear_error(void );\r
+char *ERR_error_string(unsigned long e,char *buf);\r
+void ERR_error_string_n(unsigned long e, char *buf, size_t len);\r
+const char *ERR_lib_error_string(unsigned long e);\r
+const char *ERR_func_error_string(unsigned long e);\r
+const char *ERR_reason_error_string(unsigned long e);\r
+void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),\r
+                        void *u);\r
+#ifndef OPENSSL_NO_FP_API\r
+void ERR_print_errors_fp(FILE *fp);\r
+#endif\r
+#ifndef OPENSSL_NO_BIO\r
+void ERR_print_errors(BIO *bp);\r
+void ERR_add_error_data(int num, ...);\r
+#endif\r
+void ERR_load_strings(int lib,ERR_STRING_DATA str[]);\r
+void ERR_unload_strings(int lib,ERR_STRING_DATA str[]);\r
+void ERR_load_ERR_strings(void);\r
+void ERR_load_crypto_strings(void);\r
+void ERR_free_strings(void);\r
+\r
+void ERR_remove_state(unsigned long pid); /* if zero we look it up */\r
+ERR_STATE *ERR_get_state(void);\r
+\r
+#ifndef OPENSSL_NO_LHASH\r
+LHASH *ERR_get_string_table(void);\r
+LHASH *ERR_get_err_state_table(void);\r
+void ERR_release_err_state_table(LHASH **hash);\r
+#endif\r
+\r
+int ERR_get_next_error_library(void);\r
+\r
+int ERR_set_mark(void);\r
+int ERR_pop_to_mark(void);\r
+\r
+/* Already defined in ossl_typ.h */\r
+/* typedef struct st_ERR_FNS ERR_FNS; */\r
+/* An application can use this function and provide the return value to loaded\r
+ * modules that should use the application's ERR state/functionality */\r
+const ERR_FNS *ERR_get_implementation(void);\r
+/* A loaded module should call this function prior to any ERR operations using\r
+ * the application's "ERR_FNS". */\r
+int ERR_set_implementation(const ERR_FNS *fns);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/evp.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/evp.h
new file mode 100644 (file)
index 0000000..3889f9d
--- /dev/null
@@ -0,0 +1,939 @@
+/* crypto/evp/evp.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_ENVELOPE_H\r
+#define HEADER_ENVELOPE_H\r
+\r
+#ifdef OPENSSL_ALGORITHM_DEFINES\r
+# include <openssl/opensslconf.h>\r
+#else\r
+# define OPENSSL_ALGORITHM_DEFINES\r
+# include <openssl/opensslconf.h>\r
+# undef OPENSSL_ALGORITHM_DEFINES\r
+#endif\r
+\r
+#include <openssl/ossl_typ.h>\r
+\r
+#include <openssl/symhacks.h>\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+#include <openssl/bio.h>\r
+#endif\r
+\r
+/*\r
+#define EVP_RC2_KEY_SIZE               16\r
+#define EVP_RC4_KEY_SIZE               16\r
+#define EVP_BLOWFISH_KEY_SIZE          16\r
+#define EVP_CAST5_KEY_SIZE             16\r
+#define EVP_RC5_32_12_16_KEY_SIZE      16\r
+*/\r
+#define EVP_MAX_MD_SIZE                        64      /* longest known is SHA512 */\r
+#define EVP_MAX_KEY_LENGTH             32\r
+#define EVP_MAX_IV_LENGTH              16\r
+#define EVP_MAX_BLOCK_LENGTH           32\r
+\r
+#define PKCS5_SALT_LEN                 8\r
+/* Default PKCS#5 iteration count */\r
+#define PKCS5_DEFAULT_ITER             2048\r
+\r
+#include <openssl/objects.h>\r
+\r
+#define EVP_PK_RSA     0x0001\r
+#define EVP_PK_DSA     0x0002\r
+#define EVP_PK_DH      0x0004\r
+#define EVP_PK_EC      0x0008\r
+#define EVP_PKT_SIGN   0x0010\r
+#define EVP_PKT_ENC    0x0020\r
+#define EVP_PKT_EXCH   0x0040\r
+#define EVP_PKS_RSA    0x0100\r
+#define EVP_PKS_DSA    0x0200\r
+#define EVP_PKS_EC     0x0400\r
+#define EVP_PKT_EXP    0x1000 /* <= 512 bit key */\r
+\r
+#define EVP_PKEY_NONE  NID_undef\r
+#define EVP_PKEY_RSA   NID_rsaEncryption\r
+#define EVP_PKEY_RSA2  NID_rsa\r
+#define EVP_PKEY_DSA   NID_dsa\r
+#define EVP_PKEY_DSA1  NID_dsa_2\r
+#define EVP_PKEY_DSA2  NID_dsaWithSHA\r
+#define EVP_PKEY_DSA3  NID_dsaWithSHA1\r
+#define EVP_PKEY_DSA4  NID_dsaWithSHA1_2\r
+#define EVP_PKEY_DH    NID_dhKeyAgreement\r
+#define EVP_PKEY_EC    NID_X9_62_id_ecPublicKey\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Type needs to be a bit field\r
+ * Sub-type needs to be for variations on the method, as in, can it do\r
+ * arbitrary encryption.... */\r
+struct evp_pkey_st\r
+       {\r
+       int type;\r
+       int save_type;\r
+       int references;\r
+       union   {\r
+               char *ptr;\r
+#ifndef OPENSSL_NO_RSA\r
+               struct rsa_st *rsa;     /* RSA */\r
+#endif\r
+#ifndef OPENSSL_NO_DSA\r
+               struct dsa_st *dsa;     /* DSA */\r
+#endif\r
+#ifndef OPENSSL_NO_DH\r
+               struct dh_st *dh;       /* DH */\r
+#endif\r
+#ifndef OPENSSL_NO_EC\r
+               struct ec_key_st *ec;   /* ECC */\r
+#endif\r
+               } pkey;\r
+       int save_parameters;\r
+       STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */\r
+       } /* EVP_PKEY */;\r
+\r
+#define EVP_PKEY_MO_SIGN       0x0001\r
+#define EVP_PKEY_MO_VERIFY     0x0002\r
+#define EVP_PKEY_MO_ENCRYPT    0x0004\r
+#define EVP_PKEY_MO_DECRYPT    0x0008\r
+\r
+#if 0\r
+/* This structure is required to tie the message digest and signing together.\r
+ * The lookup can be done by md/pkey_method, oid, oid/pkey_method, or\r
+ * oid, md and pkey.\r
+ * This is required because for various smart-card perform the digest and\r
+ * signing/verification on-board.  To handle this case, the specific\r
+ * EVP_MD and EVP_PKEY_METHODs need to be closely associated.\r
+ * When a PKEY is created, it will have a EVP_PKEY_METHOD associated with it.\r
+ * This can either be software or a token to provide the required low level\r
+ * routines.\r
+ */\r
+typedef struct evp_pkey_md_st\r
+       {\r
+       int oid;\r
+       EVP_MD *md;\r
+       EVP_PKEY_METHOD *pkey;\r
+       } EVP_PKEY_MD;\r
+\r
+#define EVP_rsa_md2() \\r
+               EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\\r
+                       EVP_rsa_pkcs1(),EVP_md2())\r
+#define EVP_rsa_md5() \\r
+               EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\\r
+                       EVP_rsa_pkcs1(),EVP_md5())\r
+#define EVP_rsa_sha0() \\r
+               EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\\r
+                       EVP_rsa_pkcs1(),EVP_sha())\r
+#define EVP_rsa_sha1() \\r
+               EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\\r
+                       EVP_rsa_pkcs1(),EVP_sha1())\r
+#define EVP_rsa_ripemd160() \\r
+               EVP_PKEY_MD_add(NID_ripemd160WithRSA,\\r
+                       EVP_rsa_pkcs1(),EVP_ripemd160())\r
+#define EVP_rsa_mdc2() \\r
+               EVP_PKEY_MD_add(NID_mdc2WithRSA,\\r
+                       EVP_rsa_octet_string(),EVP_mdc2())\r
+#define EVP_dsa_sha() \\r
+               EVP_PKEY_MD_add(NID_dsaWithSHA,\\r
+                       EVP_dsa(),EVP_sha())\r
+#define EVP_dsa_sha1() \\r
+               EVP_PKEY_MD_add(NID_dsaWithSHA1,\\r
+                       EVP_dsa(),EVP_sha1())\r
+\r
+typedef struct evp_pkey_method_st\r
+       {\r
+       char *name;\r
+       int flags;\r
+       int type;               /* RSA, DSA, an SSLeay specific constant */\r
+       int oid;                /* For the pub-key type */\r
+       int encrypt_oid;        /* pub/priv key encryption */\r
+\r
+       int (*sign)();\r
+       int (*verify)();\r
+       struct  {\r
+               int (*set)();   /* get and/or set the underlying type */\r
+               int (*get)();\r
+               int (*encrypt)();\r
+               int (*decrypt)();\r
+               int (*i2d)();\r
+               int (*d2i)();\r
+               int (*dup)();\r
+               } pub,priv;\r
+       int (*set_asn1_parameters)();\r
+       int (*get_asn1_parameters)();\r
+       } EVP_PKEY_METHOD;\r
+#endif\r
+\r
+#ifndef EVP_MD\r
+struct env_md_st\r
+       {\r
+       int type;\r
+       int pkey_type;\r
+       int md_size;\r
+       unsigned long flags;\r
+       int (*init)(EVP_MD_CTX *ctx);\r
+       int (*update)(EVP_MD_CTX *ctx,const void *data,size_t count);\r
+       int (*final)(EVP_MD_CTX *ctx,unsigned char *md);\r
+       int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from);\r
+       int (*cleanup)(EVP_MD_CTX *ctx);\r
+\r
+       /* FIXME: prototype these some day */\r
+       int (*sign)(int type, const unsigned char *m, unsigned int m_length,\r
+                   unsigned char *sigret, unsigned int *siglen, void *key);\r
+       int (*verify)(int type, const unsigned char *m, unsigned int m_length,\r
+                     const unsigned char *sigbuf, unsigned int siglen,\r
+                     void *key);\r
+       int required_pkey_type[5]; /*EVP_PKEY_xxx */\r
+       int block_size;\r
+       int ctx_size; /* how big does the ctx->md_data need to be */\r
+       } /* EVP_MD */;\r
+\r
+typedef int evp_sign_method(int type,const unsigned char *m,\r
+                           unsigned int m_length,unsigned char *sigret,\r
+                           unsigned int *siglen, void *key);\r
+typedef int evp_verify_method(int type,const unsigned char *m,\r
+                           unsigned int m_length,const unsigned char *sigbuf,\r
+                           unsigned int siglen, void *key);\r
+\r
+#define EVP_MD_FLAG_ONESHOT    0x0001 /* digest can only handle a single\r
+                                       * block */\r
+\r
+#define EVP_PKEY_NULL_method   NULL,NULL,{0,0,0,0}\r
+\r
+#ifndef OPENSSL_NO_DSA\r
+#define EVP_PKEY_DSA_method    (evp_sign_method *)DSA_sign, \\r
+                               (evp_verify_method *)DSA_verify, \\r
+                               {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \\r
+                                       EVP_PKEY_DSA4,0}\r
+#else\r
+#define EVP_PKEY_DSA_method    EVP_PKEY_NULL_method\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_ECDSA\r
+#define EVP_PKEY_ECDSA_method   (evp_sign_method *)ECDSA_sign, \\r
+                               (evp_verify_method *)ECDSA_verify, \\r
+                                 {EVP_PKEY_EC,0,0,0}\r
+#else   \r
+#define EVP_PKEY_ECDSA_method   EVP_PKEY_NULL_method\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_RSA\r
+#define EVP_PKEY_RSA_method    (evp_sign_method *)RSA_sign, \\r
+                               (evp_verify_method *)RSA_verify, \\r
+                               {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}\r
+#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \\r
+                               (evp_sign_method *)RSA_sign_ASN1_OCTET_STRING, \\r
+                               (evp_verify_method *)RSA_verify_ASN1_OCTET_STRING, \\r
+                               {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}\r
+#else\r
+#define EVP_PKEY_RSA_method    EVP_PKEY_NULL_method\r
+#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method\r
+#endif\r
+\r
+#endif /* !EVP_MD */\r
+\r
+struct env_md_ctx_st\r
+       {\r
+       const EVP_MD *digest;\r
+       ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */\r
+       unsigned long flags;\r
+       void *md_data;\r
+       } /* EVP_MD_CTX */;\r
+\r
+/* values for EVP_MD_CTX flags */\r
+\r
+#define EVP_MD_CTX_FLAG_ONESHOT                0x0001 /* digest update will be called\r
+                                               * once only */\r
+#define EVP_MD_CTX_FLAG_CLEANED                0x0002 /* context has already been\r
+                                               * cleaned */\r
+#define EVP_MD_CTX_FLAG_REUSE          0x0004 /* Don't free up ctx->md_data\r
+                                               * in EVP_MD_CTX_cleanup */\r
+\r
+struct evp_cipher_st\r
+       {\r
+       int nid;\r
+       int block_size;\r
+       int key_len;            /* Default value for variable length ciphers */\r
+       int iv_len;\r
+       unsigned long flags;    /* Various flags */\r
+       int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key,\r
+                   const unsigned char *iv, int enc);  /* init key */\r
+       int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out,\r
+                        const unsigned char *in, unsigned int inl);/* encrypt/decrypt data */\r
+       int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */\r
+       int ctx_size;           /* how big ctx->cipher_data needs to be */\r
+       int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */\r
+       int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */\r
+       int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */\r
+       void *app_data;         /* Application data */\r
+       } /* EVP_CIPHER */;\r
+\r
+/* Values for cipher flags */\r
+\r
+/* Modes for ciphers */\r
+\r
+#define                EVP_CIPH_STREAM_CIPHER          0x0\r
+#define                EVP_CIPH_ECB_MODE               0x1\r
+#define                EVP_CIPH_CBC_MODE               0x2\r
+#define                EVP_CIPH_CFB_MODE               0x3\r
+#define                EVP_CIPH_OFB_MODE               0x4\r
+#define        EVP_CIPH_MODE                   0x7\r
+/* Set if variable length cipher */\r
+#define        EVP_CIPH_VARIABLE_LENGTH        0x8\r
+/* Set if the iv handling should be done by the cipher itself */\r
+#define        EVP_CIPH_CUSTOM_IV              0x10\r
+/* Set if the cipher's init() function should be called if key is NULL */\r
+#define        EVP_CIPH_ALWAYS_CALL_INIT       0x20\r
+/* Call ctrl() to init cipher parameters */\r
+#define        EVP_CIPH_CTRL_INIT              0x40\r
+/* Don't use standard key length function */\r
+#define        EVP_CIPH_CUSTOM_KEY_LENGTH      0x80\r
+/* Don't use standard block padding */\r
+#define        EVP_CIPH_NO_PADDING             0x100\r
+/* cipher handles random key generation */\r
+#define        EVP_CIPH_RAND_KEY               0x200\r
+\r
+/* ctrl() values */\r
+\r
+#define                EVP_CTRL_INIT                   0x0\r
+#define        EVP_CTRL_SET_KEY_LENGTH         0x1\r
+#define        EVP_CTRL_GET_RC2_KEY_BITS       0x2\r
+#define        EVP_CTRL_SET_RC2_KEY_BITS       0x3\r
+#define        EVP_CTRL_GET_RC5_ROUNDS         0x4\r
+#define        EVP_CTRL_SET_RC5_ROUNDS         0x5\r
+#define        EVP_CTRL_RAND_KEY               0x6\r
+\r
+typedef struct evp_cipher_info_st\r
+       {\r
+       const EVP_CIPHER *cipher;\r
+       unsigned char iv[EVP_MAX_IV_LENGTH];\r
+       } EVP_CIPHER_INFO;\r
+\r
+struct evp_cipher_ctx_st\r
+       {\r
+       const EVP_CIPHER *cipher;\r
+       ENGINE *engine; /* functional reference if 'cipher' is ENGINE-provided */\r
+       int encrypt;            /* encrypt or decrypt */\r
+       int buf_len;            /* number we have left */\r
+\r
+       unsigned char  oiv[EVP_MAX_IV_LENGTH];  /* original iv */\r
+       unsigned char  iv[EVP_MAX_IV_LENGTH];   /* working iv */\r
+       unsigned char buf[EVP_MAX_BLOCK_LENGTH];/* saved partial block */\r
+       int num;                                /* used by cfb/ofb mode */\r
+\r
+       void *app_data;         /* application stuff */\r
+       int key_len;            /* May change for variable length cipher */\r
+       unsigned long flags;    /* Various flags */\r
+       void *cipher_data; /* per EVP data */\r
+       int final_used;\r
+       int block_mask;\r
+       unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */\r
+       } /* EVP_CIPHER_CTX */;\r
+\r
+typedef struct evp_Encode_Ctx_st\r
+       {\r
+       int num;        /* number saved in a partial encode/decode */\r
+       int length;     /* The length is either the output line length\r
+                        * (in input bytes) or the shortest input line\r
+                        * length that is ok.  Once decoding begins,\r
+                        * the length is adjusted up each time a longer\r
+                        * line is decoded */\r
+       unsigned char enc_data[80];     /* data to encode */\r
+       int line_num;   /* number read on current line */\r
+       int expect_nl;\r
+       } EVP_ENCODE_CTX;\r
+\r
+/* Password based encryption function */\r
+typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,\r
+               ASN1_TYPE *param, const EVP_CIPHER *cipher,\r
+                const EVP_MD *md, int en_de);\r
+\r
+#ifndef OPENSSL_NO_RSA\r
+#define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\\r
+                                       (char *)(rsa))\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_DSA\r
+#define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\\r
+                                       (char *)(dsa))\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_DH\r
+#define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\\r
+                                       (char *)(dh))\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_EC\r
+#define EVP_PKEY_assign_EC_KEY(pkey,eckey) EVP_PKEY_assign((pkey),EVP_PKEY_EC,\\r
+                                        (char *)(eckey))\r
+#endif\r
+\r
+/* Add some extra combinations */\r
+#define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))\r
+#define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))\r
+#define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))\r
+#define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))\r
+\r
+#define EVP_MD_type(e)                 ((e)->type)\r
+#define EVP_MD_nid(e)                  EVP_MD_type(e)\r
+#define EVP_MD_name(e)                 OBJ_nid2sn(EVP_MD_nid(e))\r
+#define EVP_MD_pkey_type(e)            ((e)->pkey_type)\r
+#define EVP_MD_size(e)                 ((e)->md_size)\r
+#define EVP_MD_block_size(e)           ((e)->block_size)\r
+\r
+#define EVP_MD_CTX_md(e)               ((e)->digest)\r
+#define EVP_MD_CTX_size(e)             EVP_MD_size((e)->digest)\r
+#define EVP_MD_CTX_block_size(e)       EVP_MD_block_size((e)->digest)\r
+#define EVP_MD_CTX_type(e)             EVP_MD_type((e)->digest)\r
+\r
+#define EVP_CIPHER_nid(e)              ((e)->nid)\r
+#define EVP_CIPHER_name(e)             OBJ_nid2sn(EVP_CIPHER_nid(e))\r
+#define EVP_CIPHER_block_size(e)       ((e)->block_size)\r
+#define EVP_CIPHER_key_length(e)       ((e)->key_len)\r
+#define EVP_CIPHER_iv_length(e)                ((e)->iv_len)\r
+#define EVP_CIPHER_flags(e)            ((e)->flags)\r
+#define EVP_CIPHER_mode(e)             (((e)->flags) & EVP_CIPH_MODE)\r
+\r
+#define EVP_CIPHER_CTX_cipher(e)       ((e)->cipher)\r
+#define EVP_CIPHER_CTX_nid(e)          ((e)->cipher->nid)\r
+#define EVP_CIPHER_CTX_block_size(e)   ((e)->cipher->block_size)\r
+#define EVP_CIPHER_CTX_key_length(e)   ((e)->key_len)\r
+#define EVP_CIPHER_CTX_iv_length(e)    ((e)->cipher->iv_len)\r
+#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)\r
+#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))\r
+#define EVP_CIPHER_CTX_type(c)         EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))\r
+#define EVP_CIPHER_CTX_flags(e)                ((e)->cipher->flags)\r
+#define EVP_CIPHER_CTX_mode(e)         ((e)->cipher->flags & EVP_CIPH_MODE)\r
+\r
+#define EVP_ENCODE_LENGTH(l)   (((l+2)/3*4)+(l/48+1)*2+80)\r
+#define EVP_DECODE_LENGTH(l)   ((l+3)/4*3+80)\r
+\r
+#define EVP_SignInit_ex(a,b,c)         EVP_DigestInit_ex(a,b,c)\r
+#define EVP_SignInit(a,b)              EVP_DigestInit(a,b)\r
+#define EVP_SignUpdate(a,b,c)          EVP_DigestUpdate(a,b,c)\r
+#define        EVP_VerifyInit_ex(a,b,c)        EVP_DigestInit_ex(a,b,c)\r
+#define        EVP_VerifyInit(a,b)             EVP_DigestInit(a,b)\r
+#define        EVP_VerifyUpdate(a,b,c)         EVP_DigestUpdate(a,b,c)\r
+#define EVP_OpenUpdate(a,b,c,d,e)      EVP_DecryptUpdate(a,b,c,d,e)\r
+#define EVP_SealUpdate(a,b,c,d,e)      EVP_EncryptUpdate(a,b,c,d,e)    \r
+\r
+#ifdef CONST_STRICT\r
+void BIO_set_md(BIO *,const EVP_MD *md);\r
+#else\r
+# define BIO_set_md(b,md)              BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md)\r
+#endif\r
+#define BIO_get_md(b,mdp)              BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp)\r
+#define BIO_get_md_ctx(b,mdcp)     BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp)\r
+#define BIO_get_cipher_status(b)       BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)\r
+#define BIO_get_cipher_ctx(b,c_pp)     BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp)\r
+\r
+#define        EVP_Cipher(c,o,i,l)     (c)->cipher->do_cipher((c),(o),(i),(l))\r
+\r
+#define EVP_add_cipher_alias(n,alias) \\r
+       OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))\r
+#define EVP_add_digest_alias(n,alias) \\r
+       OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n))\r
+#define EVP_delete_cipher_alias(alias) \\r
+       OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);\r
+#define EVP_delete_digest_alias(alias) \\r
+       OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);\r
+\r
+void   EVP_MD_CTX_init(EVP_MD_CTX *ctx);\r
+int    EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);\r
+EVP_MD_CTX *EVP_MD_CTX_create(void);\r
+void   EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);\r
+int     EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in);  \r
+#define EVP_MD_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))\r
+#define EVP_MD_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs))\r
+#define EVP_MD_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs))\r
+int    EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);\r
+int    EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,\r
+                        size_t cnt);\r
+int    EVP_DigestFinal_ex(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);\r
+int    EVP_Digest(const void *data, size_t count,\r
+               unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl);\r
+\r
+int     EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in);  \r
+int    EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);\r
+int    EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);\r
+\r
+int    EVP_read_pw_string(char *buf,int length,const char *prompt,int verify);\r
+void   EVP_set_pw_prompt(const char *prompt);\r
+char * EVP_get_pw_prompt(void);\r
+\r
+int    EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md,\r
+               const unsigned char *salt, const unsigned char *data,\r
+               int datal, int count, unsigned char *key,unsigned char *iv);\r
+\r
+int    EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,\r
+               const unsigned char *key, const unsigned char *iv);\r
+int    EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,\r
+               const unsigned char *key, const unsigned char *iv);\r
+int    EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,\r
+               int *outl, const unsigned char *in, int inl);\r
+int    EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);\r
+int    EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);\r
+\r
+int    EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,\r
+               const unsigned char *key, const unsigned char *iv);\r
+int    EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,\r
+               const unsigned char *key, const unsigned char *iv);\r
+int    EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,\r
+               int *outl, const unsigned char *in, int inl);\r
+int    EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);\r
+int    EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);\r
+\r
+int    EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,\r
+                      const unsigned char *key,const unsigned char *iv,\r
+                      int enc);\r
+int    EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,\r
+                      const unsigned char *key,const unsigned char *iv,\r
+                      int enc);\r
+int    EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,\r
+               int *outl, const unsigned char *in, int inl);\r
+int    EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);\r
+int    EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);\r
+\r
+int    EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,\r
+               EVP_PKEY *pkey);\r
+\r
+int    EVP_VerifyFinal(EVP_MD_CTX *ctx,const unsigned char *sigbuf,\r
+               unsigned int siglen,EVP_PKEY *pkey);\r
+\r
+int    EVP_OpenInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,\r
+               const unsigned char *ek, int ekl, const unsigned char *iv,\r
+               EVP_PKEY *priv);\r
+int    EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);\r
+\r
+int    EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,\r
+                unsigned char **ek, int *ekl, unsigned char *iv,\r
+               EVP_PKEY **pubk, int npubk);\r
+int    EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);\r
+\r
+void   EVP_EncodeInit(EVP_ENCODE_CTX *ctx);\r
+void   EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,\r
+               const unsigned char *in,int inl);\r
+void   EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);\r
+int    EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);\r
+\r
+void   EVP_DecodeInit(EVP_ENCODE_CTX *ctx);\r
+int    EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,\r
+               const unsigned char *in, int inl);\r
+int    EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned\r
+               char *out, int *outl);\r
+int    EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);\r
+\r
+void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);\r
+int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);\r
+int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);\r
+int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad);\r
+int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);\r
+int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key);\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+BIO_METHOD *BIO_f_md(void);\r
+BIO_METHOD *BIO_f_base64(void);\r
+BIO_METHOD *BIO_f_cipher(void);\r
+BIO_METHOD *BIO_f_reliable(void);\r
+void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,const unsigned char *k,\r
+               const unsigned char *i, int enc);\r
+#endif\r
+\r
+const EVP_MD *EVP_md_null(void);\r
+#ifndef OPENSSL_NO_MD2\r
+const EVP_MD *EVP_md2(void);\r
+#endif\r
+#ifndef OPENSSL_NO_MD4\r
+const EVP_MD *EVP_md4(void);\r
+#endif\r
+#ifndef OPENSSL_NO_MD5\r
+const EVP_MD *EVP_md5(void);\r
+#endif\r
+#ifndef OPENSSL_NO_SHA\r
+const EVP_MD *EVP_sha(void);\r
+const EVP_MD *EVP_sha1(void);\r
+const EVP_MD *EVP_dss(void);\r
+const EVP_MD *EVP_dss1(void);\r
+const EVP_MD *EVP_ecdsa(void);\r
+#endif\r
+#ifndef OPENSSL_NO_SHA256\r
+const EVP_MD *EVP_sha224(void);\r
+const EVP_MD *EVP_sha256(void);\r
+#endif\r
+#ifndef OPENSSL_NO_SHA512\r
+const EVP_MD *EVP_sha384(void);\r
+const EVP_MD *EVP_sha512(void);\r
+#endif\r
+#ifndef OPENSSL_NO_MDC2\r
+const EVP_MD *EVP_mdc2(void);\r
+#endif\r
+#ifndef OPENSSL_NO_RIPEMD\r
+const EVP_MD *EVP_ripemd160(void);\r
+#endif\r
+const EVP_CIPHER *EVP_enc_null(void);          /* does nothing :-) */\r
+#ifndef OPENSSL_NO_DES\r
+const EVP_CIPHER *EVP_des_ecb(void);\r
+const EVP_CIPHER *EVP_des_ede(void);\r
+const EVP_CIPHER *EVP_des_ede3(void);\r
+const EVP_CIPHER *EVP_des_ede_ecb(void);\r
+const EVP_CIPHER *EVP_des_ede3_ecb(void);\r
+const EVP_CIPHER *EVP_des_cfb64(void);\r
+# define EVP_des_cfb EVP_des_cfb64\r
+const EVP_CIPHER *EVP_des_cfb1(void);\r
+const EVP_CIPHER *EVP_des_cfb8(void);\r
+const EVP_CIPHER *EVP_des_ede_cfb64(void);\r
+# define EVP_des_ede_cfb EVP_des_ede_cfb64\r
+#if 0\r
+const EVP_CIPHER *EVP_des_ede_cfb1(void);\r
+const EVP_CIPHER *EVP_des_ede_cfb8(void);\r
+#endif\r
+const EVP_CIPHER *EVP_des_ede3_cfb64(void);\r
+# define EVP_des_ede3_cfb EVP_des_ede3_cfb64\r
+const EVP_CIPHER *EVP_des_ede3_cfb1(void);\r
+const EVP_CIPHER *EVP_des_ede3_cfb8(void);\r
+const EVP_CIPHER *EVP_des_ofb(void);\r
+const EVP_CIPHER *EVP_des_ede_ofb(void);\r
+const EVP_CIPHER *EVP_des_ede3_ofb(void);\r
+const EVP_CIPHER *EVP_des_cbc(void);\r
+const EVP_CIPHER *EVP_des_ede_cbc(void);\r
+const EVP_CIPHER *EVP_des_ede3_cbc(void);\r
+const EVP_CIPHER *EVP_desx_cbc(void);\r
+/* This should now be supported through the dev_crypto ENGINE. But also, why are\r
+ * rc4 and md5 declarations made here inside a "NO_DES" precompiler branch? */\r
+#if 0\r
+# ifdef OPENSSL_OPENBSD_DEV_CRYPTO\r
+const EVP_CIPHER *EVP_dev_crypto_des_ede3_cbc(void);\r
+const EVP_CIPHER *EVP_dev_crypto_rc4(void);\r
+const EVP_MD *EVP_dev_crypto_md5(void);\r
+# endif\r
+#endif\r
+#endif\r
+#ifndef OPENSSL_NO_RC4\r
+const EVP_CIPHER *EVP_rc4(void);\r
+const EVP_CIPHER *EVP_rc4_40(void);\r
+#endif\r
+#ifndef OPENSSL_NO_IDEA\r
+const EVP_CIPHER *EVP_idea_ecb(void);\r
+const EVP_CIPHER *EVP_idea_cfb64(void);\r
+# define EVP_idea_cfb EVP_idea_cfb64\r
+const EVP_CIPHER *EVP_idea_ofb(void);\r
+const EVP_CIPHER *EVP_idea_cbc(void);\r
+#endif\r
+#ifndef OPENSSL_NO_RC2\r
+const EVP_CIPHER *EVP_rc2_ecb(void);\r
+const EVP_CIPHER *EVP_rc2_cbc(void);\r
+const EVP_CIPHER *EVP_rc2_40_cbc(void);\r
+const EVP_CIPHER *EVP_rc2_64_cbc(void);\r
+const EVP_CIPHER *EVP_rc2_cfb64(void);\r
+# define EVP_rc2_cfb EVP_rc2_cfb64\r
+const EVP_CIPHER *EVP_rc2_ofb(void);\r
+#endif\r
+#ifndef OPENSSL_NO_BF\r
+const EVP_CIPHER *EVP_bf_ecb(void);\r
+const EVP_CIPHER *EVP_bf_cbc(void);\r
+const EVP_CIPHER *EVP_bf_cfb64(void);\r
+# define EVP_bf_cfb EVP_bf_cfb64\r
+const EVP_CIPHER *EVP_bf_ofb(void);\r
+#endif\r
+#ifndef OPENSSL_NO_CAST\r
+const EVP_CIPHER *EVP_cast5_ecb(void);\r
+const EVP_CIPHER *EVP_cast5_cbc(void);\r
+const EVP_CIPHER *EVP_cast5_cfb64(void);\r
+# define EVP_cast5_cfb EVP_cast5_cfb64\r
+const EVP_CIPHER *EVP_cast5_ofb(void);\r
+#endif\r
+#ifndef OPENSSL_NO_RC5\r
+const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void);\r
+const EVP_CIPHER *EVP_rc5_32_12_16_ecb(void);\r
+const EVP_CIPHER *EVP_rc5_32_12_16_cfb64(void);\r
+# define EVP_rc5_32_12_16_cfb EVP_rc5_32_12_16_cfb64\r
+const EVP_CIPHER *EVP_rc5_32_12_16_ofb(void);\r
+#endif\r
+#ifndef OPENSSL_NO_AES\r
+const EVP_CIPHER *EVP_aes_128_ecb(void);\r
+const EVP_CIPHER *EVP_aes_128_cbc(void);\r
+const EVP_CIPHER *EVP_aes_128_cfb1(void);\r
+const EVP_CIPHER *EVP_aes_128_cfb8(void);\r
+const EVP_CIPHER *EVP_aes_128_cfb128(void);\r
+# define EVP_aes_128_cfb EVP_aes_128_cfb128\r
+const EVP_CIPHER *EVP_aes_128_ofb(void);\r
+#if 0\r
+const EVP_CIPHER *EVP_aes_128_ctr(void);\r
+#endif\r
+const EVP_CIPHER *EVP_aes_192_ecb(void);\r
+const EVP_CIPHER *EVP_aes_192_cbc(void);\r
+const EVP_CIPHER *EVP_aes_192_cfb1(void);\r
+const EVP_CIPHER *EVP_aes_192_cfb8(void);\r
+const EVP_CIPHER *EVP_aes_192_cfb128(void);\r
+# define EVP_aes_192_cfb EVP_aes_192_cfb128\r
+const EVP_CIPHER *EVP_aes_192_ofb(void);\r
+#if 0\r
+const EVP_CIPHER *EVP_aes_192_ctr(void);\r
+#endif\r
+const EVP_CIPHER *EVP_aes_256_ecb(void);\r
+const EVP_CIPHER *EVP_aes_256_cbc(void);\r
+const EVP_CIPHER *EVP_aes_256_cfb1(void);\r
+const EVP_CIPHER *EVP_aes_256_cfb8(void);\r
+const EVP_CIPHER *EVP_aes_256_cfb128(void);\r
+# define EVP_aes_256_cfb EVP_aes_256_cfb128\r
+const EVP_CIPHER *EVP_aes_256_ofb(void);\r
+#if 0\r
+const EVP_CIPHER *EVP_aes_256_ctr(void);\r
+#endif\r
+#endif\r
+\r
+void OPENSSL_add_all_algorithms_noconf(void);\r
+void OPENSSL_add_all_algorithms_conf(void);\r
+\r
+#ifdef OPENSSL_LOAD_CONF\r
+#define OpenSSL_add_all_algorithms() \\r
+               OPENSSL_add_all_algorithms_conf()\r
+#else\r
+#define OpenSSL_add_all_algorithms() \\r
+               OPENSSL_add_all_algorithms_noconf()\r
+#endif\r
+\r
+void OpenSSL_add_all_ciphers(void);\r
+void OpenSSL_add_all_digests(void);\r
+#define SSLeay_add_all_algorithms() OpenSSL_add_all_algorithms()\r
+#define SSLeay_add_all_ciphers() OpenSSL_add_all_ciphers()\r
+#define SSLeay_add_all_digests() OpenSSL_add_all_digests()\r
+\r
+int EVP_add_cipher(const EVP_CIPHER *cipher);\r
+int EVP_add_digest(const EVP_MD *digest);\r
+\r
+const EVP_CIPHER *EVP_get_cipherbyname(const char *name);\r
+const EVP_MD *EVP_get_digestbyname(const char *name);\r
+void EVP_cleanup(void);\r
+\r
+int            EVP_PKEY_decrypt(unsigned char *dec_key,\r
+                       const unsigned char *enc_key,int enc_key_len,\r
+                       EVP_PKEY *private_key);\r
+int            EVP_PKEY_encrypt(unsigned char *enc_key,\r
+                       const unsigned char *key,int key_len,\r
+                       EVP_PKEY *pub_key);\r
+int            EVP_PKEY_type(int type);\r
+int            EVP_PKEY_bits(EVP_PKEY *pkey);\r
+int            EVP_PKEY_size(EVP_PKEY *pkey);\r
+int            EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key);\r
+\r
+#ifndef OPENSSL_NO_RSA\r
+struct rsa_st;\r
+int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,struct rsa_st *key);\r
+struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);\r
+#endif\r
+#ifndef OPENSSL_NO_DSA\r
+struct dsa_st;\r
+int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,struct dsa_st *key);\r
+struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);\r
+#endif\r
+#ifndef OPENSSL_NO_DH\r
+struct dh_st;\r
+int EVP_PKEY_set1_DH(EVP_PKEY *pkey,struct dh_st *key);\r
+struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey);\r
+#endif\r
+#ifndef OPENSSL_NO_EC\r
+struct ec_key_st;\r
+int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey,struct ec_key_st *key);\r
+struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);\r
+#endif\r
+\r
+EVP_PKEY *     EVP_PKEY_new(void);\r
+void           EVP_PKEY_free(EVP_PKEY *pkey);\r
+\r
+EVP_PKEY *     d2i_PublicKey(int type,EVP_PKEY **a, const unsigned char **pp,\r
+                       long length);\r
+int            i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);\r
+\r
+EVP_PKEY *     d2i_PrivateKey(int type,EVP_PKEY **a, const unsigned char **pp,\r
+                       long length);\r
+EVP_PKEY *     d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,\r
+                       long length);\r
+int            i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);\r
+\r
+int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from);\r
+int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey);\r
+int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode);\r
+int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b);\r
+\r
+int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b);\r
+\r
+int EVP_CIPHER_type(const EVP_CIPHER *ctx);\r
+\r
+/* calls methods */\r
+int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);\r
+int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);\r
+\r
+/* These are used by EVP_CIPHER methods */\r
+int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);\r
+int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);\r
+\r
+/* PKCS5 password based encryption */\r
+int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,\r
+                        ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,\r
+                        int en_de);\r
+int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,\r
+                          const unsigned char *salt, int saltlen, int iter,\r
+                          int keylen, unsigned char *out);\r
+int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,\r
+                        ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,\r
+                        int en_de);\r
+\r
+void PKCS5_PBE_add(void);\r
+\r
+int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,\r
+            ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de);\r
+int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,\r
+                   EVP_PBE_KEYGEN *keygen);\r
+void EVP_PBE_cleanup(void);\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_EVP_strings(void);\r
+\r
+/* Error codes for the EVP functions. */\r
+\r
+/* Function codes. */\r
+#define EVP_F_AES_INIT_KEY                              133\r
+#define EVP_F_D2I_PKEY                                  100\r
+#define EVP_F_DSAPKEY2PKCS8                             134\r
+#define EVP_F_DSA_PKEY2PKCS8                            135\r
+#define EVP_F_ECDSA_PKEY2PKCS8                          129\r
+#define EVP_F_ECKEY_PKEY2PKCS8                          132\r
+#define EVP_F_EVP_CIPHERINIT_EX                                 123\r
+#define EVP_F_EVP_CIPHER_CTX_CTRL                       124\r
+#define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH             122\r
+#define EVP_F_EVP_DECRYPTFINAL_EX                       101\r
+#define EVP_F_EVP_DIGESTINIT_EX                                 128\r
+#define EVP_F_EVP_ENCRYPTFINAL_EX                       127\r
+#define EVP_F_EVP_MD_CTX_COPY_EX                        110\r
+#define EVP_F_EVP_OPENINIT                              102\r
+#define EVP_F_EVP_PBE_ALG_ADD                           115\r
+#define EVP_F_EVP_PBE_CIPHERINIT                        116\r
+#define EVP_F_EVP_PKCS82PKEY                            111\r
+#define EVP_F_EVP_PKEY2PKCS8_BROKEN                     113\r
+#define EVP_F_EVP_PKEY_COPY_PARAMETERS                  103\r
+#define EVP_F_EVP_PKEY_DECRYPT                          104\r
+#define EVP_F_EVP_PKEY_ENCRYPT                          105\r
+#define EVP_F_EVP_PKEY_GET1_DH                          119\r
+#define EVP_F_EVP_PKEY_GET1_DSA                                 120\r
+#define EVP_F_EVP_PKEY_GET1_ECDSA                       130\r
+#define EVP_F_EVP_PKEY_GET1_EC_KEY                      131\r
+#define EVP_F_EVP_PKEY_GET1_RSA                                 121\r
+#define EVP_F_EVP_PKEY_NEW                              106\r
+#define EVP_F_EVP_RIJNDAEL                              126\r
+#define EVP_F_EVP_SIGNFINAL                             107\r
+#define EVP_F_EVP_VERIFYFINAL                           108\r
+#define EVP_F_PKCS5_PBE_KEYIVGEN                        117\r
+#define EVP_F_PKCS5_V2_PBE_KEYIVGEN                     118\r
+#define EVP_F_PKCS8_SET_BROKEN                          112\r
+#define EVP_F_RC2_MAGIC_TO_METH                                 109\r
+#define EVP_F_RC5_CTRL                                  125\r
+\r
+/* Reason codes. */\r
+#define EVP_R_AES_KEY_SETUP_FAILED                      143\r
+#define EVP_R_ASN1_LIB                                  140\r
+#define EVP_R_BAD_BLOCK_LENGTH                          136\r
+#define EVP_R_BAD_DECRYPT                               100\r
+#define EVP_R_BAD_KEY_LENGTH                            137\r
+#define EVP_R_BN_DECODE_ERROR                           112\r
+#define EVP_R_BN_PUBKEY_ERROR                           113\r
+#define EVP_R_CIPHER_PARAMETER_ERROR                    122\r
+#define EVP_R_CTRL_NOT_IMPLEMENTED                      132\r
+#define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED            133\r
+#define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH                 138\r
+#define EVP_R_DECODE_ERROR                              114\r
+#define EVP_R_DIFFERENT_KEY_TYPES                       101\r
+#define EVP_R_ENCODE_ERROR                              115\r
+#define EVP_R_EVP_PBE_CIPHERINIT_ERROR                  119\r
+#define EVP_R_EXPECTING_AN_RSA_KEY                      127\r
+#define EVP_R_EXPECTING_A_DH_KEY                        128\r
+#define EVP_R_EXPECTING_A_DSA_KEY                       129\r
+#define EVP_R_EXPECTING_A_ECDSA_KEY                     141\r
+#define EVP_R_EXPECTING_A_EC_KEY                        142\r
+#define EVP_R_INITIALIZATION_ERROR                      134\r
+#define EVP_R_INPUT_NOT_INITIALIZED                     111\r
+#define EVP_R_INVALID_KEY_LENGTH                        130\r
+#define EVP_R_IV_TOO_LARGE                              102\r
+#define EVP_R_KEYGEN_FAILURE                            120\r
+#define EVP_R_MISSING_PARAMETERS                        103\r
+#define EVP_R_NO_CIPHER_SET                             131\r
+#define EVP_R_NO_DIGEST_SET                             139\r
+#define EVP_R_NO_DSA_PARAMETERS                                 116\r
+#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED               104\r
+#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED             105\r
+#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE                         117\r
+#define EVP_R_PUBLIC_KEY_NOT_RSA                        106\r
+#define EVP_R_UNKNOWN_PBE_ALGORITHM                     121\r
+#define EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS               135\r
+#define EVP_R_UNSUPPORTED_CIPHER                        107\r
+#define EVP_R_UNSUPPORTED_KEYLENGTH                     123\r
+#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION       124\r
+#define EVP_R_UNSUPPORTED_KEY_SIZE                      108\r
+#define EVP_R_UNSUPPORTED_PRF                           125\r
+#define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM                 118\r
+#define EVP_R_UNSUPPORTED_SALT_TYPE                     126\r
+#define EVP_R_WRONG_FINAL_BLOCK_LENGTH                  109\r
+#define EVP_R_WRONG_PUBLIC_KEY_TYPE                     110\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/fips.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/fips.h
new file mode 100644 (file)
index 0000000..3af0325
--- /dev/null
@@ -0,0 +1,126 @@
+/* ====================================================================\r
+ * Copyright (c) 2003 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ */\r
+\r
+#include <openssl/opensslconf.h>\r
+\r
+#ifdef OPENSSL_FIPS\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Note that these are defined in crypto/cryptlib.c so they're\r
+ * available even without -lfips.\r
+ */\r
+struct dsa_st;\r
+\r
+int FIPS_mode_set(int onoff,const char *path);\r
+void FIPS_allow_md5(int onoff);\r
+int FIPS_md5_allowed(void);\r
+int FIPS_selftest_failed(void);\r
+int FIPS_dsa_check(struct dsa_st *dsa);\r
+void FIPS_corrupt_sha1(void);\r
+int FIPS_selftest_sha1(void);\r
+void FIPS_corrupt_aes(void);\r
+int FIPS_selftest_aes(void);\r
+void FIPS_corrupt_des(void);\r
+int FIPS_selftest_des(void);\r
+void FIPS_corrupt_rsa(void);\r
+int FIPS_selftest_rsa(void);\r
+void FIPS_corrupt_dsa(void);\r
+int FIPS_selftest_dsa(void);\r
+\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_FIPS_strings(void);\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_FIPS_strings(void);\r
+\r
+/* Error codes for the FIPS functions. */\r
+\r
+/* Function codes. */\r
+#define FIPS_F_DSA_DO_SIGN                              111\r
+#define FIPS_F_DSA_DO_VERIFY                            112\r
+#define FIPS_F_DSA_GENERATE_PARAMETERS                  110\r
+#define FIPS_F_FIPS_CHECK_DSA                           116\r
+#define FIPS_F_FIPS_CHECK_EXE                           106\r
+#define FIPS_F_FIPS_CHECK_RSA                           115\r
+#define FIPS_F_FIPS_DSA_CHECK                           102\r
+#define FIPS_F_FIPS_MODE_SET                            105\r
+#define FIPS_F_FIPS_SELFTEST_AES                        104\r
+#define FIPS_F_FIPS_SELFTEST_DES                        107\r
+#define FIPS_F_FIPS_SELFTEST_DSA                        109\r
+#define FIPS_F_FIPS_SELFTEST_RSA                        108\r
+#define FIPS_F_FIPS_SELFTEST_SHA1                       103\r
+#define FIPS_F_HASH_FINAL                               100\r
+#define FIPS_F_DH_GENERATE_PARAMETERS                   117\r
+#define FIPS_F_RSA_EAY_PUBLIC_ENCRYPT                   114\r
+#define FIPS_F_RSA_GENERATE_KEY                                 113\r
+#define FIPS_F_SSLEAY_RAND_BYTES                        101\r
+\r
+/* Reason codes. */\r
+#define FIPS_R_CANNOT_READ_EXE                          103\r
+#define FIPS_R_CANNOT_READ_EXE_DIGEST                   104\r
+#define FIPS_R_EXE_DIGEST_DOES_NOT_MATCH                105\r
+#define FIPS_R_FIPS_MODE_ALREADY_SET                    102\r
+#define FIPS_R_FIPS_SELFTEST_FAILED                     106\r
+#define FIPS_R_NON_FIPS_METHOD                          100\r
+#define FIPS_R_PAIRWISE_TEST_FAILED                     107\r
+#define FIPS_R_SELFTEST_FAILED                          101\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/fips_rand.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/fips_rand.h
new file mode 100644 (file)
index 0000000..07a925d
--- /dev/null
@@ -0,0 +1,74 @@
+/* ====================================================================\r
+ * Copyright (c) 2003 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_FIPS_RAND_H\r
+#define HEADER_FIPS_RAND_H\r
+\r
+#include "des.h"\r
+\r
+#ifdef OPENSSL_FIPS\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+void FIPS_set_prng_key(const unsigned char k1[8],const unsigned char k2[8]);\r
+void FIPS_test_mode(int test,const unsigned char faketime[8]);\r
+void FIPS_rand_seed(const void *buf, FIPS_RAND_SIZE_T num);\r
+/* NB: this returns true if _partially_ seeded */\r
+int FIPS_rand_seeded(void);\r
+\r
+RAND_METHOD *FIPS_rand_method(void);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
+#endif\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/hmac.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/hmac.h
new file mode 100644 (file)
index 0000000..943869a
--- /dev/null
@@ -0,0 +1,108 @@
+/* crypto/hmac/hmac.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+#ifndef HEADER_HMAC_H\r
+#define HEADER_HMAC_H\r
+\r
+#include <openssl/opensslconf.h>\r
+\r
+#ifdef OPENSSL_NO_HMAC\r
+#error HMAC is disabled.\r
+#endif\r
+\r
+#include <openssl/evp.h>\r
+\r
+#define HMAC_MAX_MD_CBLOCK     128     /* largest known is SHA512 */\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct hmac_ctx_st\r
+       {\r
+       const EVP_MD *md;\r
+       EVP_MD_CTX md_ctx;\r
+       EVP_MD_CTX i_ctx;\r
+       EVP_MD_CTX o_ctx;\r
+       unsigned int key_length;\r
+       unsigned char key[HMAC_MAX_MD_CBLOCK];\r
+       } HMAC_CTX;\r
+\r
+#define HMAC_size(e)   (EVP_MD_size((e)->md))\r
+\r
+\r
+void HMAC_CTX_init(HMAC_CTX *ctx);\r
+void HMAC_CTX_cleanup(HMAC_CTX *ctx);\r
+\r
+#define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */\r
+\r
+void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,\r
+              const EVP_MD *md); /* deprecated */\r
+void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,\r
+                 const EVP_MD *md, ENGINE *impl);\r
+void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len);\r
+void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);\r
+unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,\r
+                   const unsigned char *d, size_t n, unsigned char *md,\r
+                   unsigned int *md_len);\r
+\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/idea.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/idea.h
new file mode 100644 (file)
index 0000000..cf0ff95
--- /dev/null
@@ -0,0 +1,100 @@
+/* crypto/idea/idea.h */\r
+/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_IDEA_H\r
+#define HEADER_IDEA_H\r
+\r
+#include <openssl/opensslconf.h> /* IDEA_INT, OPENSSL_NO_IDEA */\r
+\r
+#ifdef OPENSSL_NO_IDEA\r
+#error IDEA is disabled.\r
+#endif\r
+\r
+#define IDEA_ENCRYPT   1\r
+#define IDEA_DECRYPT   0\r
+\r
+#define IDEA_BLOCK     8\r
+#define IDEA_KEY_LENGTH        16\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct idea_key_st\r
+       {\r
+       IDEA_INT data[9][6];\r
+       } IDEA_KEY_SCHEDULE;\r
+\r
+const char *idea_options(void);\r
+void idea_ecb_encrypt(const unsigned char *in, unsigned char *out,\r
+       IDEA_KEY_SCHEDULE *ks);\r
+void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks);\r
+void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk);\r
+void idea_cbc_encrypt(const unsigned char *in, unsigned char *out,\r
+       long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc);\r
+void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out,\r
+       long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,\r
+       int *num,int enc);\r
+void idea_ofb64_encrypt(const unsigned char *in, unsigned char *out,\r
+       long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num);\r
+void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks);\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/krb5_asn.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/krb5_asn.h
new file mode 100644 (file)
index 0000000..fa08967
--- /dev/null
@@ -0,0 +1,256 @@
+/* krb5_asn.h */\r
+/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project,\r
+** using ocsp/{*.h,*asn*.c} as a starting point\r
+*/\r
+\r
+/* ====================================================================\r
+ * Copyright (c) 1998-2000 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_KRB5_ASN_H\r
+#define HEADER_KRB5_ASN_H\r
+\r
+/*\r
+#include <krb5.h>\r
+*/\r
+#include <openssl/safestack.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/*     ASN.1 from Kerberos RFC 1510\r
+*/\r
+\r
+/*     EncryptedData ::=   SEQUENCE {\r
+**             etype[0]                      INTEGER, -- EncryptionType\r
+**             kvno[1]                       INTEGER OPTIONAL,\r
+**             cipher[2]                     OCTET STRING -- ciphertext\r
+**     }\r
+*/\r
+typedef        struct  krb5_encdata_st\r
+       {\r
+       ASN1_INTEGER                    *etype;\r
+       ASN1_INTEGER                    *kvno;\r
+       ASN1_OCTET_STRING               *cipher;\r
+       }       KRB5_ENCDATA;\r
+\r
+DECLARE_STACK_OF(KRB5_ENCDATA)\r
+\r
+/*     PrincipalName ::=   SEQUENCE {\r
+**             name-type[0]                  INTEGER,\r
+**             name-string[1]                SEQUENCE OF GeneralString\r
+**     }\r
+*/\r
+typedef        struct  krb5_princname_st\r
+       {\r
+       ASN1_INTEGER                    *nametype;\r
+       STACK_OF(ASN1_GENERALSTRING)    *namestring;\r
+       }       KRB5_PRINCNAME;\r
+\r
+DECLARE_STACK_OF(KRB5_PRINCNAME)\r
+\r
+\r
+/*     Ticket ::=      [APPLICATION 1] SEQUENCE {\r
+**             tkt-vno[0]                    INTEGER,\r
+**             realm[1]                      Realm,\r
+**             sname[2]                      PrincipalName,\r
+**             enc-part[3]                   EncryptedData\r
+**     }\r
+*/\r
+typedef        struct  krb5_tktbody_st\r
+       {\r
+       ASN1_INTEGER                    *tktvno;\r
+       ASN1_GENERALSTRING              *realm;\r
+       KRB5_PRINCNAME                  *sname;\r
+       KRB5_ENCDATA                    *encdata;\r
+       }       KRB5_TKTBODY;\r
+\r
+typedef STACK_OF(KRB5_TKTBODY) KRB5_TICKET;\r
+DECLARE_STACK_OF(KRB5_TKTBODY)\r
+\r
+\r
+/*     AP-REQ ::=      [APPLICATION 14] SEQUENCE {\r
+**             pvno[0]                       INTEGER,\r
+**             msg-type[1]                   INTEGER,\r
+**             ap-options[2]                 APOptions,\r
+**             ticket[3]                     Ticket,\r
+**             authenticator[4]              EncryptedData\r
+**     }\r
+**\r
+**     APOptions ::=   BIT STRING {\r
+**             reserved(0), use-session-key(1), mutual-required(2) }\r
+*/\r
+typedef        struct  krb5_ap_req_st\r
+       {\r
+       ASN1_INTEGER                    *pvno;\r
+       ASN1_INTEGER                    *msgtype;\r
+       ASN1_BIT_STRING                 *apoptions;\r
+       KRB5_TICKET                     *ticket;\r
+       KRB5_ENCDATA                    *authenticator;\r
+       }       KRB5_APREQBODY;\r
+\r
+typedef STACK_OF(KRB5_APREQBODY) KRB5_APREQ;\r
+DECLARE_STACK_OF(KRB5_APREQBODY)\r
+\r
+\r
+/*     Authenticator Stuff     */\r
+\r
+\r
+/*     Checksum ::=   SEQUENCE {\r
+**             cksumtype[0]                  INTEGER,\r
+**             checksum[1]                   OCTET STRING\r
+**     }\r
+*/\r
+typedef        struct  krb5_checksum_st\r
+       {\r
+       ASN1_INTEGER                    *ctype;\r
+       ASN1_OCTET_STRING               *checksum;\r
+       }       KRB5_CHECKSUM;\r
+\r
+DECLARE_STACK_OF(KRB5_CHECKSUM)\r
+\r
+\r
+/*     EncryptionKey ::=   SEQUENCE {\r
+**             keytype[0]                    INTEGER,\r
+**             keyvalue[1]                   OCTET STRING\r
+**     }\r
+*/\r
+typedef struct  krb5_encryptionkey_st\r
+       {\r
+       ASN1_INTEGER                    *ktype;\r
+       ASN1_OCTET_STRING               *keyvalue;\r
+       }       KRB5_ENCKEY;\r
+\r
+DECLARE_STACK_OF(KRB5_ENCKEY)\r
+\r
+\r
+/*     AuthorizationData ::=   SEQUENCE OF SEQUENCE {\r
+**             ad-type[0]                    INTEGER,\r
+**              ad-data[1]                    OCTET STRING\r
+**     }\r
+*/\r
+typedef struct krb5_authorization_st\r
+       {\r
+       ASN1_INTEGER                    *adtype;\r
+       ASN1_OCTET_STRING               *addata;\r
+       }       KRB5_AUTHDATA;\r
+\r
+DECLARE_STACK_OF(KRB5_AUTHDATA)\r
+\r
+                       \r
+/*     -- Unencrypted authenticator\r
+**     Authenticator ::=    [APPLICATION 2] SEQUENCE    {\r
+**             authenticator-vno[0]          INTEGER,\r
+**             crealm[1]                     Realm,\r
+**             cname[2]                      PrincipalName,\r
+**             cksum[3]                      Checksum OPTIONAL,\r
+**             cusec[4]                      INTEGER,\r
+**             ctime[5]                      KerberosTime,\r
+**             subkey[6]                     EncryptionKey OPTIONAL,\r
+**             seq-number[7]                 INTEGER OPTIONAL,\r
+**             authorization-data[8]         AuthorizationData OPTIONAL\r
+**     }\r
+*/\r
+typedef struct krb5_authenticator_st\r
+       {\r
+       ASN1_INTEGER                    *avno;\r
+       ASN1_GENERALSTRING              *crealm;\r
+       KRB5_PRINCNAME                  *cname;\r
+       KRB5_CHECKSUM                   *cksum;\r
+       ASN1_INTEGER                    *cusec;\r
+       ASN1_GENERALIZEDTIME            *ctime;\r
+       KRB5_ENCKEY                     *subkey;\r
+       ASN1_INTEGER                    *seqnum;\r
+       KRB5_AUTHDATA                   *authorization;\r
+       }       KRB5_AUTHENTBODY;\r
+\r
+typedef STACK_OF(KRB5_AUTHENTBODY) KRB5_AUTHENT;\r
+DECLARE_STACK_OF(KRB5_AUTHENTBODY)\r
+\r
+\r
+/*  DECLARE_ASN1_FUNCTIONS(type) = DECLARE_ASN1_FUNCTIONS_name(type, type) =\r
+**     type *name##_new(void);\r
+**     void name##_free(type *a);\r
+**     DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) =\r
+**      DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) =\r
+**       type *d2i_##name(type **a, const unsigned char **in, long len);\r
+**       int i2d_##name(type *a, unsigned char **out);\r
+**       DECLARE_ASN1_ITEM(itname) = OPENSSL_EXTERN const ASN1_ITEM itname##_it\r
+*/\r
+\r
+DECLARE_ASN1_FUNCTIONS(KRB5_ENCDATA)\r
+DECLARE_ASN1_FUNCTIONS(KRB5_PRINCNAME)\r
+DECLARE_ASN1_FUNCTIONS(KRB5_TKTBODY)\r
+DECLARE_ASN1_FUNCTIONS(KRB5_APREQBODY)\r
+DECLARE_ASN1_FUNCTIONS(KRB5_TICKET)\r
+DECLARE_ASN1_FUNCTIONS(KRB5_APREQ)\r
+\r
+DECLARE_ASN1_FUNCTIONS(KRB5_CHECKSUM)\r
+DECLARE_ASN1_FUNCTIONS(KRB5_ENCKEY)\r
+DECLARE_ASN1_FUNCTIONS(KRB5_AUTHDATA)\r
+DECLARE_ASN1_FUNCTIONS(KRB5_AUTHENTBODY)\r
+DECLARE_ASN1_FUNCTIONS(KRB5_AUTHENT)\r
+\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/kssl.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/kssl.h
new file mode 100644 (file)
index 0000000..c84820f
--- /dev/null
@@ -0,0 +1,179 @@
+/* ssl/kssl.h -*- mode: C; c-file-style: "eay" -*- */\r
+/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project 2000.\r
+ * project 2000.\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    licensing@OpenSSL.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+/*\r
+**     19990701        VRS     Started.\r
+*/\r
+\r
+#ifndef        KSSL_H\r
+#define        KSSL_H\r
+\r
+#include <openssl/opensslconf.h>\r
+\r
+#ifndef OPENSSL_NO_KRB5\r
+\r
+#include <stdio.h>\r
+#include <ctype.h>\r
+#include <krb5.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/*\r
+**     Depending on which KRB5 implementation used, some types from\r
+**     the other may be missing.  Resolve that here and now\r
+*/\r
+#ifdef KRB5_HEIMDAL\r
+typedef unsigned char krb5_octet;\r
+#define FAR\r
+#else\r
+\r
+#ifndef FAR\r
+#define FAR\r
+#endif\r
+\r
+#endif\r
+\r
+/*     Uncomment this to debug kssl problems or\r
+**     to trace usage of the Kerberos session key\r
+**\r
+**     #define         KSSL_DEBUG\r
+*/\r
+\r
+#ifndef        KRB5SVC\r
+#define KRB5SVC        "host"\r
+#endif\r
+\r
+#ifndef        KRB5KEYTAB\r
+#define KRB5KEYTAB     "/etc/krb5.keytab"\r
+#endif\r
+\r
+#ifndef KRB5SENDAUTH\r
+#define KRB5SENDAUTH   1\r
+#endif\r
+\r
+#ifndef KRB5CHECKAUTH\r
+#define KRB5CHECKAUTH  1\r
+#endif\r
+\r
+#ifndef KSSL_CLOCKSKEW\r
+#define        KSSL_CLOCKSKEW  300;\r
+#endif\r
+\r
+#define        KSSL_ERR_MAX    255\r
+typedef struct kssl_err_st  {\r
+       int  reason;\r
+       char text[KSSL_ERR_MAX+1];\r
+       } KSSL_ERR;\r
+\r
+\r
+/*     Context for passing\r
+**             (1) Kerberos session key to SSL, and\r
+**             (2)     Config data between application and SSL lib\r
+*/\r
+typedef struct kssl_ctx_st\r
+        {\r
+                                /*     used by:    disposition:            */\r
+       char *service_name;     /*      C,S         default ok (kssl)       */\r
+       char *service_host;     /*      C           input, REQUIRED         */\r
+       char *client_princ;     /*      S           output from krb5 ticket */\r
+       char *keytab_file;      /*      S           NULL (/etc/krb5.keytab) */\r
+       char *cred_cache;       /*      C           NULL (default)          */\r
+       krb5_enctype enctype;\r
+       int length;\r
+       krb5_octet FAR *key;\r
+       } KSSL_CTX;\r
+\r
+#define        KSSL_CLIENT     1\r
+#define KSSL_SERVER    2\r
+#define        KSSL_SERVICE    3\r
+#define        KSSL_KEYTAB     4\r
+\r
+#define KSSL_CTX_OK    0\r
+#define KSSL_CTX_ERR   1\r
+#define KSSL_NOMEM     2\r
+\r
+/* Public (for use by applications that use OpenSSL with Kerberos 5 support */\r
+krb5_error_code kssl_ctx_setstring(KSSL_CTX *kssl_ctx, int which, char *text);\r
+KSSL_CTX *kssl_ctx_new(void);\r
+KSSL_CTX *kssl_ctx_free(KSSL_CTX *kssl_ctx);\r
+void kssl_ctx_show(KSSL_CTX *kssl_ctx);\r
+krb5_error_code kssl_ctx_setprinc(KSSL_CTX *kssl_ctx, int which,\r
+        krb5_data *realm, krb5_data *entity, int nentities);\r
+krb5_error_code        kssl_cget_tkt(KSSL_CTX *kssl_ctx,  krb5_data **enc_tktp,\r
+        krb5_data *authenp, KSSL_ERR *kssl_err);\r
+krb5_error_code        kssl_sget_tkt(KSSL_CTX *kssl_ctx,  krb5_data *indata,\r
+        krb5_ticket_times *ttimes, KSSL_ERR *kssl_err);\r
+krb5_error_code kssl_ctx_setkey(KSSL_CTX *kssl_ctx, krb5_keyblock *session);\r
+void   kssl_err_set(KSSL_ERR *kssl_err, int reason, char *text);\r
+void kssl_krb5_free_data_contents(krb5_context context, krb5_data *data);\r
+krb5_error_code  kssl_build_principal_2(krb5_context context,\r
+                       krb5_principal *princ, int rlen, const char *realm,\r
+                       int slen, const char *svc, int hlen, const char *host);\r
+krb5_error_code  kssl_validate_times(krb5_timestamp atime,\r
+                                       krb5_ticket_times *ttimes);\r
+krb5_error_code  kssl_check_authent(KSSL_CTX *kssl_ctx, krb5_data *authentp,\r
+                                   krb5_timestamp *atimep, KSSL_ERR *kssl_err);\r
+unsigned char  *kssl_skip_confound(krb5_enctype enctype, unsigned char *authn);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif /* OPENSSL_NO_KRB5      */\r
+#endif /* KSSL_H       */\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/lhash.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/lhash.h
new file mode 100644 (file)
index 0000000..d0b1daf
--- /dev/null
@@ -0,0 +1,200 @@
+/* crypto/lhash/lhash.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+/* Header for dynamic hash table routines\r
+ * Author - Eric Young\r
+ */\r
+\r
+#ifndef HEADER_LHASH_H\r
+#define HEADER_LHASH_H\r
+\r
+#include <openssl/e_os2.h>\r
+#ifndef OPENSSL_NO_FP_API\r
+#include <stdio.h>\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+#include <openssl/bio.h>\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct lhash_node_st\r
+       {\r
+       void *data;\r
+       struct lhash_node_st *next;\r
+#ifndef OPENSSL_NO_HASH_COMP\r
+       unsigned long hash;\r
+#endif\r
+       } LHASH_NODE;\r
+\r
+typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *);\r
+typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *);\r
+typedef void (*LHASH_DOALL_FN_TYPE)(void *);\r
+typedef void (*LHASH_DOALL_ARG_FN_TYPE)(void *, void *);\r
+\r
+/* Macros for declaring and implementing type-safe wrappers for LHASH callbacks.\r
+ * This way, callbacks can be provided to LHASH structures without function\r
+ * pointer casting and the macro-defined callbacks provide per-variable casting\r
+ * before deferring to the underlying type-specific callbacks. NB: It is\r
+ * possible to place a "static" in front of both the DECLARE and IMPLEMENT\r
+ * macros if the functions are strictly internal. */\r
+\r
+/* First: "hash" functions */\r
+#define DECLARE_LHASH_HASH_FN(f_name,o_type) \\r
+       unsigned long f_name##_LHASH_HASH(const void *);\r
+#define IMPLEMENT_LHASH_HASH_FN(f_name,o_type) \\r
+       unsigned long f_name##_LHASH_HASH(const void *arg) { \\r
+               o_type a = (o_type)arg; \\r
+               return f_name(a); }\r
+#define LHASH_HASH_FN(f_name) f_name##_LHASH_HASH\r
+\r
+/* Second: "compare" functions */\r
+#define DECLARE_LHASH_COMP_FN(f_name,o_type) \\r
+       int f_name##_LHASH_COMP(const void *, const void *);\r
+#define IMPLEMENT_LHASH_COMP_FN(f_name,o_type) \\r
+       int f_name##_LHASH_COMP(const void *arg1, const void *arg2) { \\r
+               o_type a = (o_type)arg1; \\r
+               o_type b = (o_type)arg2; \\r
+               return f_name(a,b); }\r
+#define LHASH_COMP_FN(f_name) f_name##_LHASH_COMP\r
+\r
+/* Third: "doall" functions */\r
+#define DECLARE_LHASH_DOALL_FN(f_name,o_type) \\r
+       void f_name##_LHASH_DOALL(void *);\r
+#define IMPLEMENT_LHASH_DOALL_FN(f_name,o_type) \\r
+       void f_name##_LHASH_DOALL(void *arg) { \\r
+               o_type a = (o_type)arg; \\r
+               f_name(a); }\r
+#define LHASH_DOALL_FN(f_name) f_name##_LHASH_DOALL\r
+\r
+/* Fourth: "doall_arg" functions */\r
+#define DECLARE_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \\r
+       void f_name##_LHASH_DOALL_ARG(void *, void *);\r
+#define IMPLEMENT_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \\r
+       void f_name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \\r
+               o_type a = (o_type)arg1; \\r
+               a_type b = (a_type)arg2; \\r
+               f_name(a,b); }\r
+#define LHASH_DOALL_ARG_FN(f_name) f_name##_LHASH_DOALL_ARG\r
+\r
+typedef struct lhash_st\r
+       {\r
+       LHASH_NODE **b;\r
+       LHASH_COMP_FN_TYPE comp;\r
+       LHASH_HASH_FN_TYPE hash;\r
+       unsigned int num_nodes;\r
+       unsigned int num_alloc_nodes;\r
+       unsigned int p;\r
+       unsigned int pmax;\r
+       unsigned long up_load; /* load times 256 */\r
+       unsigned long down_load; /* load times 256 */\r
+       unsigned long num_items;\r
+\r
+       unsigned long num_expands;\r
+       unsigned long num_expand_reallocs;\r
+       unsigned long num_contracts;\r
+       unsigned long num_contract_reallocs;\r
+       unsigned long num_hash_calls;\r
+       unsigned long num_comp_calls;\r
+       unsigned long num_insert;\r
+       unsigned long num_replace;\r
+       unsigned long num_delete;\r
+       unsigned long num_no_delete;\r
+       unsigned long num_retrieve;\r
+       unsigned long num_retrieve_miss;\r
+       unsigned long num_hash_comps;\r
+\r
+       int error;\r
+       } LHASH;\r
+\r
+#define LH_LOAD_MULT   256\r
+\r
+/* Indicates a malloc() error in the last call, this is only bad\r
+ * in lh_insert(). */\r
+#define lh_error(lh)   ((lh)->error)\r
+\r
+LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);\r
+void lh_free(LHASH *lh);\r
+void *lh_insert(LHASH *lh, void *data);\r
+void *lh_delete(LHASH *lh, const void *data);\r
+void *lh_retrieve(LHASH *lh, const void *data);\r
+void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func);\r
+void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg);\r
+unsigned long lh_strhash(const char *c);\r
+unsigned long lh_num_items(const LHASH *lh);\r
+\r
+#ifndef OPENSSL_NO_FP_API\r
+void lh_stats(const LHASH *lh, FILE *out);\r
+void lh_node_stats(const LHASH *lh, FILE *out);\r
+void lh_node_usage_stats(const LHASH *lh, FILE *out);\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+void lh_stats_bio(const LHASH *lh, BIO *out);\r
+void lh_node_stats_bio(const LHASH *lh, BIO *out);\r
+void lh_node_usage_stats_bio(const LHASH *lh, BIO *out);\r
+#endif\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/md2.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/md2.h
new file mode 100644 (file)
index 0000000..5c0a518
--- /dev/null
@@ -0,0 +1,91 @@
+/* crypto/md/md2.h */\r
+/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_MD2_H\r
+#define HEADER_MD2_H\r
+\r
+#include <openssl/opensslconf.h> /* OPENSSL_NO_MD2, MD2_INT */\r
+#ifdef OPENSSL_NO_MD2\r
+#error MD2 is disabled.\r
+#endif\r
+\r
+#define MD2_DIGEST_LENGTH      16\r
+#define MD2_BLOCK              16\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct MD2state_st\r
+       {\r
+       unsigned int num;\r
+       unsigned char data[MD2_BLOCK];\r
+       MD2_INT cksm[MD2_BLOCK];\r
+       MD2_INT state[MD2_BLOCK];\r
+       } MD2_CTX;\r
+\r
+const char *MD2_options(void);\r
+int MD2_Init(MD2_CTX *c);\r
+int MD2_Update(MD2_CTX *c, const unsigned char *data, size_t len);\r
+int MD2_Final(unsigned char *md, MD2_CTX *c);\r
+unsigned char *MD2(const unsigned char *d, size_t n,unsigned char *md);\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/md4.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/md4.h
new file mode 100644 (file)
index 0000000..654c20d
--- /dev/null
@@ -0,0 +1,116 @@
+/* crypto/md4/md4.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_MD4_H\r
+#define HEADER_MD4_H\r
+\r
+#include <openssl/e_os2.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef OPENSSL_NO_MD4\r
+#error MD4 is disabled.\r
+#endif\r
+\r
+/*\r
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r
+ * ! MD4_LONG has to be at least 32 bits wide. If it's wider, then !\r
+ * ! MD4_LONG_LOG2 has to be defined along.                       !\r
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r
+ */\r
+\r
+#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)\r
+#define MD4_LONG unsigned long\r
+#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)\r
+#define MD4_LONG unsigned long\r
+#define MD4_LONG_LOG2 3\r
+/*\r
+ * _CRAY note. I could declare short, but I have no idea what impact\r
+ * does it have on performance on none-T3E machines. I could declare\r
+ * int, but at least on C90 sizeof(int) can be chosen at compile time.\r
+ * So I've chosen long...\r
+ *                                     <appro@fy.chalmers.se>\r
+ */\r
+#else\r
+#define MD4_LONG unsigned int\r
+#endif\r
+\r
+#define MD4_CBLOCK     64\r
+#define MD4_LBLOCK     (MD4_CBLOCK/4)\r
+#define MD4_DIGEST_LENGTH 16\r
+\r
+typedef struct MD4state_st\r
+       {\r
+       MD4_LONG A,B,C,D;\r
+       MD4_LONG Nl,Nh;\r
+       MD4_LONG data[MD4_LBLOCK];\r
+       unsigned int num;\r
+       } MD4_CTX;\r
+\r
+int MD4_Init(MD4_CTX *c);\r
+int MD4_Update(MD4_CTX *c, const void *data, size_t len);\r
+int MD4_Final(unsigned char *md, MD4_CTX *c);\r
+unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md);\r
+void MD4_Transform(MD4_CTX *c, const unsigned char *b);\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/md5.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/md5.h
new file mode 100644 (file)
index 0000000..6841cae
--- /dev/null
@@ -0,0 +1,116 @@
+/* crypto/md5/md5.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_MD5_H\r
+#define HEADER_MD5_H\r
+\r
+#include <openssl/e_os2.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef OPENSSL_NO_MD5\r
+#error MD5 is disabled.\r
+#endif\r
+\r
+/*\r
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r
+ * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then !\r
+ * ! MD5_LONG_LOG2 has to be defined along.                       !\r
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r
+ */\r
+\r
+#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)\r
+#define MD5_LONG unsigned long\r
+#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)\r
+#define MD5_LONG unsigned long\r
+#define MD5_LONG_LOG2 3\r
+/*\r
+ * _CRAY note. I could declare short, but I have no idea what impact\r
+ * does it have on performance on none-T3E machines. I could declare\r
+ * int, but at least on C90 sizeof(int) can be chosen at compile time.\r
+ * So I've chosen long...\r
+ *                                     <appro@fy.chalmers.se>\r
+ */\r
+#else\r
+#define MD5_LONG unsigned int\r
+#endif\r
+\r
+#define MD5_CBLOCK     64\r
+#define MD5_LBLOCK     (MD5_CBLOCK/4)\r
+#define MD5_DIGEST_LENGTH 16\r
+\r
+typedef struct MD5state_st\r
+       {\r
+       MD5_LONG A,B,C,D;\r
+       MD5_LONG Nl,Nh;\r
+       MD5_LONG data[MD5_LBLOCK];\r
+       unsigned int num;\r
+       } MD5_CTX;\r
+\r
+int MD5_Init(MD5_CTX *c);\r
+int MD5_Update(MD5_CTX *c, const void *data, size_t len);\r
+int MD5_Final(unsigned char *md, MD5_CTX *c);\r
+unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md);\r
+void MD5_Transform(MD5_CTX *c, const unsigned char *b);\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/mdc2.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/mdc2.h
new file mode 100644 (file)
index 0000000..48320c4
--- /dev/null
@@ -0,0 +1,98 @@
+/* crypto/mdc2/mdc2.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_MDC2_H\r
+#define HEADER_MDC2_H\r
+\r
+#include <openssl/des.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef OPENSSL_NO_MDC2\r
+#error MDC2 is disabled.\r
+#endif\r
+\r
+#define MDC2_BLOCK              8\r
+#define MDC2_DIGEST_LENGTH      16\r
\r
+typedef struct mdc2_ctx_st\r
+       {\r
+       int num;\r
+       unsigned char data[MDC2_BLOCK];\r
+       DES_cblock h,hh;\r
+       int pad_type; /* either 1 or 2, default 1 */\r
+       } MDC2_CTX;\r
+\r
+#ifdef OPENSSL_FIPS\r
+int private_MDC2_Init(MDC2_CTX *c);\r
+#endif\r
+int MDC2_Init(MDC2_CTX *c);\r
+int MDC2_Update(MDC2_CTX *c, const unsigned char *data, unsigned long len);\r
+int MDC2_Final(unsigned char *md, MDC2_CTX *c);\r
+unsigned char *MDC2(const unsigned char *d, unsigned long n,\r
+       unsigned char *md);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/obj_mac.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/obj_mac.h
new file mode 100644 (file)
index 0000000..7cdd694
--- /dev/null
@@ -0,0 +1,3305 @@
+/* crypto/objects/obj_mac.h */
+
+/* THIS FILE IS GENERATED FROM objects.txt by objects.pl via the
+ * following command:
+ * perl objects.pl objects.txt obj_mac.num obj_mac.h
+ */
+
+/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ * 
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to.  The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ * 
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ * 
+ * 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 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    "This product includes cryptographic software written by
+ *     Eric Young (eay@cryptsoft.com)"
+ *    The word 'cryptographic' can be left out if the rouines from the library
+ *    being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from 
+ *    the apps directory (application code) you must include an acknowledgement:
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ * 
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 OR CONTRIBUTORS 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.
+ * 
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+#define SN_undef                       "UNDEF"
+#define LN_undef                       "undefined"
+#define NID_undef                      0
+#define OBJ_undef                      0L
+
+#define SN_itu_t               "ITU-T"
+#define LN_itu_t               "itu-t"
+#define NID_itu_t              645
+#define OBJ_itu_t              0L
+
+#define NID_ccitt              404
+#define OBJ_ccitt              OBJ_itu_t
+
+#define SN_iso         "ISO"
+#define LN_iso         "iso"
+#define NID_iso                181
+#define OBJ_iso                1L
+
+#define SN_joint_iso_itu_t             "JOINT-ISO-ITU-T"
+#define LN_joint_iso_itu_t             "joint-iso-itu-t"
+#define NID_joint_iso_itu_t            646
+#define OBJ_joint_iso_itu_t            2L
+
+#define NID_joint_iso_ccitt            393
+#define OBJ_joint_iso_ccitt            OBJ_joint_iso_itu_t
+
+#define SN_member_body         "member-body"
+#define LN_member_body         "ISO Member Body"
+#define NID_member_body                182
+#define OBJ_member_body                OBJ_iso,2L
+
+#define SN_identified_organization             "identified-organization"
+#define NID_identified_organization            676
+#define OBJ_identified_organization            OBJ_iso,3L
+
+#define SN_certicom_arc                "certicom-arc"
+#define NID_certicom_arc               677
+#define OBJ_certicom_arc               OBJ_identified_organization,132L
+
+#define SN_international_organizations         "international-organizations"
+#define LN_international_organizations         "International Organizations"
+#define NID_international_organizations                647
+#define OBJ_international_organizations                OBJ_joint_iso_itu_t,23L
+
+#define SN_wap         "wap"
+#define NID_wap                678
+#define OBJ_wap                OBJ_international_organizations,43L
+
+#define SN_wap_wsg             "wap-wsg"
+#define NID_wap_wsg            679
+#define OBJ_wap_wsg            OBJ_wap,13L
+
+#define SN_selected_attribute_types            "selected-attribute-types"
+#define LN_selected_attribute_types            "Selected Attribute Types"
+#define NID_selected_attribute_types           394
+#define OBJ_selected_attribute_types           OBJ_joint_iso_itu_t,5L,1L,5L
+
+#define SN_clearance           "clearance"
+#define NID_clearance          395
+#define OBJ_clearance          OBJ_selected_attribute_types,55L
+
+#define SN_ISO_US              "ISO-US"
+#define LN_ISO_US              "ISO US Member Body"
+#define NID_ISO_US             183
+#define OBJ_ISO_US             OBJ_member_body,840L
+
+#define SN_X9_57               "X9-57"
+#define LN_X9_57               "X9.57"
+#define NID_X9_57              184
+#define OBJ_X9_57              OBJ_ISO_US,10040L
+
+#define SN_X9cm                "X9cm"
+#define LN_X9cm                "X9.57 CM ?"
+#define NID_X9cm               185
+#define OBJ_X9cm               OBJ_X9_57,4L
+
+#define SN_dsa         "DSA"
+#define LN_dsa         "dsaEncryption"
+#define NID_dsa                116
+#define OBJ_dsa                OBJ_X9cm,1L
+
+#define SN_dsaWithSHA1         "DSA-SHA1"
+#define LN_dsaWithSHA1         "dsaWithSHA1"
+#define NID_dsaWithSHA1                113
+#define OBJ_dsaWithSHA1                OBJ_X9cm,3L
+
+#define SN_ansi_X9_62          "ansi-X9-62"
+#define LN_ansi_X9_62          "ANSI X9.62"
+#define NID_ansi_X9_62         405
+#define OBJ_ansi_X9_62         OBJ_ISO_US,10045L
+
+#define OBJ_X9_62_id_fieldType         OBJ_ansi_X9_62,1L
+
+#define SN_X9_62_prime_field           "prime-field"
+#define NID_X9_62_prime_field          406
+#define OBJ_X9_62_prime_field          OBJ_X9_62_id_fieldType,1L
+
+#define SN_X9_62_characteristic_two_field              "characteristic-two-field"
+#define NID_X9_62_characteristic_two_field             407
+#define OBJ_X9_62_characteristic_two_field             OBJ_X9_62_id_fieldType,2L
+
+#define SN_X9_62_id_characteristic_two_basis           "id-characteristic-two-basis"
+#define NID_X9_62_id_characteristic_two_basis          680
+#define OBJ_X9_62_id_characteristic_two_basis          OBJ_X9_62_characteristic_two_field,3L
+
+#define SN_X9_62_onBasis               "onBasis"
+#define NID_X9_62_onBasis              681
+#define OBJ_X9_62_onBasis              OBJ_X9_62_id_characteristic_two_basis,1L
+
+#define SN_X9_62_tpBasis               "tpBasis"
+#define NID_X9_62_tpBasis              682
+#define OBJ_X9_62_tpBasis              OBJ_X9_62_id_characteristic_two_basis,2L
+
+#define SN_X9_62_ppBasis               "ppBasis"
+#define NID_X9_62_ppBasis              683
+#define OBJ_X9_62_ppBasis              OBJ_X9_62_id_characteristic_two_basis,3L
+
+#define OBJ_X9_62_id_publicKeyType             OBJ_ansi_X9_62,2L
+
+#define SN_X9_62_id_ecPublicKey                "id-ecPublicKey"
+#define NID_X9_62_id_ecPublicKey               408
+#define OBJ_X9_62_id_ecPublicKey               OBJ_X9_62_id_publicKeyType,1L
+
+#define OBJ_X9_62_ellipticCurve                OBJ_ansi_X9_62,3L
+
+#define OBJ_X9_62_c_TwoCurve           OBJ_X9_62_ellipticCurve,0L
+
+#define SN_X9_62_c2pnb163v1            "c2pnb163v1"
+#define NID_X9_62_c2pnb163v1           684
+#define OBJ_X9_62_c2pnb163v1           OBJ_X9_62_c_TwoCurve,1L
+
+#define SN_X9_62_c2pnb163v2            "c2pnb163v2"
+#define NID_X9_62_c2pnb163v2           685
+#define OBJ_X9_62_c2pnb163v2           OBJ_X9_62_c_TwoCurve,2L
+
+#define SN_X9_62_c2pnb163v3            "c2pnb163v3"
+#define NID_X9_62_c2pnb163v3           686
+#define OBJ_X9_62_c2pnb163v3           OBJ_X9_62_c_TwoCurve,3L
+
+#define SN_X9_62_c2pnb176v1            "c2pnb176v1"
+#define NID_X9_62_c2pnb176v1           687
+#define OBJ_X9_62_c2pnb176v1           OBJ_X9_62_c_TwoCurve,4L
+
+#define SN_X9_62_c2tnb191v1            "c2tnb191v1"
+#define NID_X9_62_c2tnb191v1           688
+#define OBJ_X9_62_c2tnb191v1           OBJ_X9_62_c_TwoCurve,5L
+
+#define SN_X9_62_c2tnb191v2            "c2tnb191v2"
+#define NID_X9_62_c2tnb191v2           689
+#define OBJ_X9_62_c2tnb191v2           OBJ_X9_62_c_TwoCurve,6L
+
+#define SN_X9_62_c2tnb191v3            "c2tnb191v3"
+#define NID_X9_62_c2tnb191v3           690
+#define OBJ_X9_62_c2tnb191v3           OBJ_X9_62_c_TwoCurve,7L
+
+#define SN_X9_62_c2onb191v4            "c2onb191v4"
+#define NID_X9_62_c2onb191v4           691
+#define OBJ_X9_62_c2onb191v4           OBJ_X9_62_c_TwoCurve,8L
+
+#define SN_X9_62_c2onb191v5            "c2onb191v5"
+#define NID_X9_62_c2onb191v5           692
+#define OBJ_X9_62_c2onb191v5           OBJ_X9_62_c_TwoCurve,9L
+
+#define SN_X9_62_c2pnb208w1            "c2pnb208w1"
+#define NID_X9_62_c2pnb208w1           693
+#define OBJ_X9_62_c2pnb208w1           OBJ_X9_62_c_TwoCurve,10L
+
+#define SN_X9_62_c2tnb239v1            "c2tnb239v1"
+#define NID_X9_62_c2tnb239v1           694
+#define OBJ_X9_62_c2tnb239v1           OBJ_X9_62_c_TwoCurve,11L
+
+#define SN_X9_62_c2tnb239v2            "c2tnb239v2"
+#define NID_X9_62_c2tnb239v2           695
+#define OBJ_X9_62_c2tnb239v2           OBJ_X9_62_c_TwoCurve,12L
+
+#define SN_X9_62_c2tnb239v3            "c2tnb239v3"
+#define NID_X9_62_c2tnb239v3           696
+#define OBJ_X9_62_c2tnb239v3           OBJ_X9_62_c_TwoCurve,13L
+
+#define SN_X9_62_c2onb239v4            "c2onb239v4"
+#define NID_X9_62_c2onb239v4           697
+#define OBJ_X9_62_c2onb239v4           OBJ_X9_62_c_TwoCurve,14L
+
+#define SN_X9_62_c2onb239v5            "c2onb239v5"
+#define NID_X9_62_c2onb239v5           698
+#define OBJ_X9_62_c2onb239v5           OBJ_X9_62_c_TwoCurve,15L
+
+#define SN_X9_62_c2pnb272w1            "c2pnb272w1"
+#define NID_X9_62_c2pnb272w1           699
+#define OBJ_X9_62_c2pnb272w1           OBJ_X9_62_c_TwoCurve,16L
+
+#define SN_X9_62_c2pnb304w1            "c2pnb304w1"
+#define NID_X9_62_c2pnb304w1           700
+#define OBJ_X9_62_c2pnb304w1           OBJ_X9_62_c_TwoCurve,17L
+
+#define SN_X9_62_c2tnb359v1            "c2tnb359v1"
+#define NID_X9_62_c2tnb359v1           701
+#define OBJ_X9_62_c2tnb359v1           OBJ_X9_62_c_TwoCurve,18L
+
+#define SN_X9_62_c2pnb368w1            "c2pnb368w1"
+#define NID_X9_62_c2pnb368w1           702
+#define OBJ_X9_62_c2pnb368w1           OBJ_X9_62_c_TwoCurve,19L
+
+#define SN_X9_62_c2tnb431r1            "c2tnb431r1"
+#define NID_X9_62_c2tnb431r1           703
+#define OBJ_X9_62_c2tnb431r1           OBJ_X9_62_c_TwoCurve,20L
+
+#define OBJ_X9_62_primeCurve           OBJ_X9_62_ellipticCurve,1L
+
+#define SN_X9_62_prime192v1            "prime192v1"
+#define NID_X9_62_prime192v1           409
+#define OBJ_X9_62_prime192v1           OBJ_X9_62_primeCurve,1L
+
+#define SN_X9_62_prime192v2            "prime192v2"
+#define NID_X9_62_prime192v2           410
+#define OBJ_X9_62_prime192v2           OBJ_X9_62_primeCurve,2L
+
+#define SN_X9_62_prime192v3            "prime192v3"
+#define NID_X9_62_prime192v3           411
+#define OBJ_X9_62_prime192v3           OBJ_X9_62_primeCurve,3L
+
+#define SN_X9_62_prime239v1            "prime239v1"
+#define NID_X9_62_prime239v1           412
+#define OBJ_X9_62_prime239v1           OBJ_X9_62_primeCurve,4L
+
+#define SN_X9_62_prime239v2            "prime239v2"
+#define NID_X9_62_prime239v2           413
+#define OBJ_X9_62_prime239v2           OBJ_X9_62_primeCurve,5L
+
+#define SN_X9_62_prime239v3            "prime239v3"
+#define NID_X9_62_prime239v3           414
+#define OBJ_X9_62_prime239v3           OBJ_X9_62_primeCurve,6L
+
+#define SN_X9_62_prime256v1            "prime256v1"
+#define NID_X9_62_prime256v1           415
+#define OBJ_X9_62_prime256v1           OBJ_X9_62_primeCurve,7L
+
+#define OBJ_X9_62_id_ecSigType         OBJ_ansi_X9_62,4L
+
+#define SN_ecdsa_with_SHA1             "ecdsa-with-SHA1"
+#define NID_ecdsa_with_SHA1            416
+#define OBJ_ecdsa_with_SHA1            OBJ_X9_62_id_ecSigType,1L
+
+#define OBJ_secg_ellipticCurve         OBJ_certicom_arc,0L
+
+#define SN_secp112r1           "secp112r1"
+#define NID_secp112r1          704
+#define OBJ_secp112r1          OBJ_secg_ellipticCurve,6L
+
+#define SN_secp112r2           "secp112r2"
+#define NID_secp112r2          705
+#define OBJ_secp112r2          OBJ_secg_ellipticCurve,7L
+
+#define SN_secp128r1           "secp128r1"
+#define NID_secp128r1          706
+#define OBJ_secp128r1          OBJ_secg_ellipticCurve,28L
+
+#define SN_secp128r2           "secp128r2"
+#define NID_secp128r2          707
+#define OBJ_secp128r2          OBJ_secg_ellipticCurve,29L
+
+#define SN_secp160k1           "secp160k1"
+#define NID_secp160k1          708
+#define OBJ_secp160k1          OBJ_secg_ellipticCurve,9L
+
+#define SN_secp160r1           "secp160r1"
+#define NID_secp160r1          709
+#define OBJ_secp160r1          OBJ_secg_ellipticCurve,8L
+
+#define SN_secp160r2           "secp160r2"
+#define NID_secp160r2          710
+#define OBJ_secp160r2          OBJ_secg_ellipticCurve,30L
+
+#define SN_secp192k1           "secp192k1"
+#define NID_secp192k1          711
+#define OBJ_secp192k1          OBJ_secg_ellipticCurve,31L
+
+#define SN_secp224k1           "secp224k1"
+#define NID_secp224k1          712
+#define OBJ_secp224k1          OBJ_secg_ellipticCurve,32L
+
+#define SN_secp224r1           "secp224r1"
+#define NID_secp224r1          713
+#define OBJ_secp224r1          OBJ_secg_ellipticCurve,33L
+
+#define SN_secp256k1           "secp256k1"
+#define NID_secp256k1          714
+#define OBJ_secp256k1          OBJ_secg_ellipticCurve,10L
+
+#define SN_secp384r1           "secp384r1"
+#define NID_secp384r1          715
+#define OBJ_secp384r1          OBJ_secg_ellipticCurve,34L
+
+#define SN_secp521r1           "secp521r1"
+#define NID_secp521r1          716
+#define OBJ_secp521r1          OBJ_secg_ellipticCurve,35L
+
+#define SN_sect113r1           "sect113r1"
+#define NID_sect113r1          717
+#define OBJ_sect113r1          OBJ_secg_ellipticCurve,4L
+
+#define SN_sect113r2           "sect113r2"
+#define NID_sect113r2          718
+#define OBJ_sect113r2          OBJ_secg_ellipticCurve,5L
+
+#define SN_sect131r1           "sect131r1"
+#define NID_sect131r1          719
+#define OBJ_sect131r1          OBJ_secg_ellipticCurve,22L
+
+#define SN_sect131r2           "sect131r2"
+#define NID_sect131r2          720
+#define OBJ_sect131r2          OBJ_secg_ellipticCurve,23L
+
+#define SN_sect163k1           "sect163k1"
+#define NID_sect163k1          721
+#define OBJ_sect163k1          OBJ_secg_ellipticCurve,1L
+
+#define SN_sect163r1           "sect163r1"
+#define NID_sect163r1          722
+#define OBJ_sect163r1          OBJ_secg_ellipticCurve,2L
+
+#define SN_sect163r2           "sect163r2"
+#define NID_sect163r2          723
+#define OBJ_sect163r2          OBJ_secg_ellipticCurve,15L
+
+#define SN_sect193r1           "sect193r1"
+#define NID_sect193r1          724
+#define OBJ_sect193r1          OBJ_secg_ellipticCurve,24L
+
+#define SN_sect193r2           "sect193r2"
+#define NID_sect193r2          725
+#define OBJ_sect193r2          OBJ_secg_ellipticCurve,25L
+
+#define SN_sect233k1           "sect233k1"
+#define NID_sect233k1          726
+#define OBJ_sect233k1          OBJ_secg_ellipticCurve,26L
+
+#define SN_sect233r1           "sect233r1"
+#define NID_sect233r1          727
+#define OBJ_sect233r1          OBJ_secg_ellipticCurve,27L
+
+#define SN_sect239k1           "sect239k1"
+#define NID_sect239k1          728
+#define OBJ_sect239k1          OBJ_secg_ellipticCurve,3L
+
+#define SN_sect283k1           "sect283k1"
+#define NID_sect283k1          729
+#define OBJ_sect283k1          OBJ_secg_ellipticCurve,16L
+
+#define SN_sect283r1           "sect283r1"
+#define NID_sect283r1          730
+#define OBJ_sect283r1          OBJ_secg_ellipticCurve,17L
+
+#define SN_sect409k1           "sect409k1"
+#define NID_sect409k1          731
+#define OBJ_sect409k1          OBJ_secg_ellipticCurve,36L
+
+#define SN_sect409r1           "sect409r1"
+#define NID_sect409r1          732
+#define OBJ_sect409r1          OBJ_secg_ellipticCurve,37L
+
+#define SN_sect571k1           "sect571k1"
+#define NID_sect571k1          733
+#define OBJ_sect571k1          OBJ_secg_ellipticCurve,38L
+
+#define SN_sect571r1           "sect571r1"
+#define NID_sect571r1          734
+#define OBJ_sect571r1          OBJ_secg_ellipticCurve,39L
+
+#define OBJ_wap_wsg_idm_ecid           OBJ_wap_wsg,4L
+
+#define SN_wap_wsg_idm_ecid_wtls1              "wap-wsg-idm-ecid-wtls1"
+#define NID_wap_wsg_idm_ecid_wtls1             735
+#define OBJ_wap_wsg_idm_ecid_wtls1             OBJ_wap_wsg_idm_ecid,1L
+
+#define SN_wap_wsg_idm_ecid_wtls3              "wap-wsg-idm-ecid-wtls3"
+#define NID_wap_wsg_idm_ecid_wtls3             736
+#define OBJ_wap_wsg_idm_ecid_wtls3             OBJ_wap_wsg_idm_ecid,3L
+
+#define SN_wap_wsg_idm_ecid_wtls4              "wap-wsg-idm-ecid-wtls4"
+#define NID_wap_wsg_idm_ecid_wtls4             737
+#define OBJ_wap_wsg_idm_ecid_wtls4             OBJ_wap_wsg_idm_ecid,4L
+
+#define SN_wap_wsg_idm_ecid_wtls5              "wap-wsg-idm-ecid-wtls5"
+#define NID_wap_wsg_idm_ecid_wtls5             738
+#define OBJ_wap_wsg_idm_ecid_wtls5             OBJ_wap_wsg_idm_ecid,5L
+
+#define SN_wap_wsg_idm_ecid_wtls6              "wap-wsg-idm-ecid-wtls6"
+#define NID_wap_wsg_idm_ecid_wtls6             739
+#define OBJ_wap_wsg_idm_ecid_wtls6             OBJ_wap_wsg_idm_ecid,6L
+
+#define SN_wap_wsg_idm_ecid_wtls7              "wap-wsg-idm-ecid-wtls7"
+#define NID_wap_wsg_idm_ecid_wtls7             740
+#define OBJ_wap_wsg_idm_ecid_wtls7             OBJ_wap_wsg_idm_ecid,7L
+
+#define SN_wap_wsg_idm_ecid_wtls8              "wap-wsg-idm-ecid-wtls8"
+#define NID_wap_wsg_idm_ecid_wtls8             741
+#define OBJ_wap_wsg_idm_ecid_wtls8             OBJ_wap_wsg_idm_ecid,8L
+
+#define SN_wap_wsg_idm_ecid_wtls9              "wap-wsg-idm-ecid-wtls9"
+#define NID_wap_wsg_idm_ecid_wtls9             742
+#define OBJ_wap_wsg_idm_ecid_wtls9             OBJ_wap_wsg_idm_ecid,9L
+
+#define SN_wap_wsg_idm_ecid_wtls10             "wap-wsg-idm-ecid-wtls10"
+#define NID_wap_wsg_idm_ecid_wtls10            743
+#define OBJ_wap_wsg_idm_ecid_wtls10            OBJ_wap_wsg_idm_ecid,10L
+
+#define SN_wap_wsg_idm_ecid_wtls11             "wap-wsg-idm-ecid-wtls11"
+#define NID_wap_wsg_idm_ecid_wtls11            744
+#define OBJ_wap_wsg_idm_ecid_wtls11            OBJ_wap_wsg_idm_ecid,11L
+
+#define SN_wap_wsg_idm_ecid_wtls12             "wap-wsg-idm-ecid-wtls12"
+#define NID_wap_wsg_idm_ecid_wtls12            745
+#define OBJ_wap_wsg_idm_ecid_wtls12            OBJ_wap_wsg_idm_ecid,12L
+
+#define SN_cast5_cbc           "CAST5-CBC"
+#define LN_cast5_cbc           "cast5-cbc"
+#define NID_cast5_cbc          108
+#define OBJ_cast5_cbc          OBJ_ISO_US,113533L,7L,66L,10L
+
+#define SN_cast5_ecb           "CAST5-ECB"
+#define LN_cast5_ecb           "cast5-ecb"
+#define NID_cast5_ecb          109
+
+#define SN_cast5_cfb64         "CAST5-CFB"
+#define LN_cast5_cfb64         "cast5-cfb"
+#define NID_cast5_cfb64                110
+
+#define SN_cast5_ofb64         "CAST5-OFB"
+#define LN_cast5_ofb64         "cast5-ofb"
+#define NID_cast5_ofb64                111
+
+#define LN_pbeWithMD5AndCast5_CBC              "pbeWithMD5AndCast5CBC"
+#define NID_pbeWithMD5AndCast5_CBC             112
+#define OBJ_pbeWithMD5AndCast5_CBC             OBJ_ISO_US,113533L,7L,66L,12L
+
+#define SN_rsadsi              "rsadsi"
+#define LN_rsadsi              "RSA Data Security, Inc."
+#define NID_rsadsi             1
+#define OBJ_rsadsi             OBJ_ISO_US,113549L
+
+#define SN_pkcs                "pkcs"
+#define LN_pkcs                "RSA Data Security, Inc. PKCS"
+#define NID_pkcs               2
+#define OBJ_pkcs               OBJ_rsadsi,1L
+
+#define SN_pkcs1               "pkcs1"
+#define NID_pkcs1              186
+#define OBJ_pkcs1              OBJ_pkcs,1L
+
+#define LN_rsaEncryption               "rsaEncryption"
+#define NID_rsaEncryption              6
+#define OBJ_rsaEncryption              OBJ_pkcs1,1L
+
+#define SN_md2WithRSAEncryption                "RSA-MD2"
+#define LN_md2WithRSAEncryption                "md2WithRSAEncryption"
+#define NID_md2WithRSAEncryption               7
+#define OBJ_md2WithRSAEncryption               OBJ_pkcs1,2L
+
+#define SN_md4WithRSAEncryption                "RSA-MD4"
+#define LN_md4WithRSAEncryption                "md4WithRSAEncryption"
+#define NID_md4WithRSAEncryption               396
+#define OBJ_md4WithRSAEncryption               OBJ_pkcs1,3L
+
+#define SN_md5WithRSAEncryption                "RSA-MD5"
+#define LN_md5WithRSAEncryption                "md5WithRSAEncryption"
+#define NID_md5WithRSAEncryption               8
+#define OBJ_md5WithRSAEncryption               OBJ_pkcs1,4L
+
+#define SN_sha1WithRSAEncryption               "RSA-SHA1"
+#define LN_sha1WithRSAEncryption               "sha1WithRSAEncryption"
+#define NID_sha1WithRSAEncryption              65
+#define OBJ_sha1WithRSAEncryption              OBJ_pkcs1,5L
+
+#define SN_sha256WithRSAEncryption             "RSA-SHA256"
+#define LN_sha256WithRSAEncryption             "sha256WithRSAEncryption"
+#define NID_sha256WithRSAEncryption            668
+#define OBJ_sha256WithRSAEncryption            OBJ_pkcs1,11L
+
+#define SN_sha384WithRSAEncryption             "RSA-SHA384"
+#define LN_sha384WithRSAEncryption             "sha384WithRSAEncryption"
+#define NID_sha384WithRSAEncryption            669
+#define OBJ_sha384WithRSAEncryption            OBJ_pkcs1,12L
+
+#define SN_sha512WithRSAEncryption             "RSA-SHA512"
+#define LN_sha512WithRSAEncryption             "sha512WithRSAEncryption"
+#define NID_sha512WithRSAEncryption            670
+#define OBJ_sha512WithRSAEncryption            OBJ_pkcs1,13L
+
+#define SN_sha224WithRSAEncryption             "RSA-SHA224"
+#define LN_sha224WithRSAEncryption             "sha224WithRSAEncryption"
+#define NID_sha224WithRSAEncryption            671
+#define OBJ_sha224WithRSAEncryption            OBJ_pkcs1,14L
+
+#define SN_pkcs3               "pkcs3"
+#define NID_pkcs3              27
+#define OBJ_pkcs3              OBJ_pkcs,3L
+
+#define LN_dhKeyAgreement              "dhKeyAgreement"
+#define NID_dhKeyAgreement             28
+#define OBJ_dhKeyAgreement             OBJ_pkcs3,1L
+
+#define SN_pkcs5               "pkcs5"
+#define NID_pkcs5              187
+#define OBJ_pkcs5              OBJ_pkcs,5L
+
+#define SN_pbeWithMD2AndDES_CBC                "PBE-MD2-DES"
+#define LN_pbeWithMD2AndDES_CBC                "pbeWithMD2AndDES-CBC"
+#define NID_pbeWithMD2AndDES_CBC               9
+#define OBJ_pbeWithMD2AndDES_CBC               OBJ_pkcs5,1L
+
+#define SN_pbeWithMD5AndDES_CBC                "PBE-MD5-DES"
+#define LN_pbeWithMD5AndDES_CBC                "pbeWithMD5AndDES-CBC"
+#define NID_pbeWithMD5AndDES_CBC               10
+#define OBJ_pbeWithMD5AndDES_CBC               OBJ_pkcs5,3L
+
+#define SN_pbeWithMD2AndRC2_CBC                "PBE-MD2-RC2-64"
+#define LN_pbeWithMD2AndRC2_CBC                "pbeWithMD2AndRC2-CBC"
+#define NID_pbeWithMD2AndRC2_CBC               168
+#define OBJ_pbeWithMD2AndRC2_CBC               OBJ_pkcs5,4L
+
+#define SN_pbeWithMD5AndRC2_CBC                "PBE-MD5-RC2-64"
+#define LN_pbeWithMD5AndRC2_CBC                "pbeWithMD5AndRC2-CBC"
+#define NID_pbeWithMD5AndRC2_CBC               169
+#define OBJ_pbeWithMD5AndRC2_CBC               OBJ_pkcs5,6L
+
+#define SN_pbeWithSHA1AndDES_CBC               "PBE-SHA1-DES"
+#define LN_pbeWithSHA1AndDES_CBC               "pbeWithSHA1AndDES-CBC"
+#define NID_pbeWithSHA1AndDES_CBC              170
+#define OBJ_pbeWithSHA1AndDES_CBC              OBJ_pkcs5,10L
+
+#define SN_pbeWithSHA1AndRC2_CBC               "PBE-SHA1-RC2-64"
+#define LN_pbeWithSHA1AndRC2_CBC               "pbeWithSHA1AndRC2-CBC"
+#define NID_pbeWithSHA1AndRC2_CBC              68
+#define OBJ_pbeWithSHA1AndRC2_CBC              OBJ_pkcs5,11L
+
+#define LN_id_pbkdf2           "PBKDF2"
+#define NID_id_pbkdf2          69
+#define OBJ_id_pbkdf2          OBJ_pkcs5,12L
+
+#define LN_pbes2               "PBES2"
+#define NID_pbes2              161
+#define OBJ_pbes2              OBJ_pkcs5,13L
+
+#define LN_pbmac1              "PBMAC1"
+#define NID_pbmac1             162
+#define OBJ_pbmac1             OBJ_pkcs5,14L
+
+#define SN_pkcs7               "pkcs7"
+#define NID_pkcs7              20
+#define OBJ_pkcs7              OBJ_pkcs,7L
+
+#define LN_pkcs7_data          "pkcs7-data"
+#define NID_pkcs7_data         21
+#define OBJ_pkcs7_data         OBJ_pkcs7,1L
+
+#define LN_pkcs7_signed                "pkcs7-signedData"
+#define NID_pkcs7_signed               22
+#define OBJ_pkcs7_signed               OBJ_pkcs7,2L
+
+#define LN_pkcs7_enveloped             "pkcs7-envelopedData"
+#define NID_pkcs7_enveloped            23
+#define OBJ_pkcs7_enveloped            OBJ_pkcs7,3L
+
+#define LN_pkcs7_signedAndEnveloped            "pkcs7-signedAndEnvelopedData"
+#define NID_pkcs7_signedAndEnveloped           24
+#define OBJ_pkcs7_signedAndEnveloped           OBJ_pkcs7,4L
+
+#define LN_pkcs7_digest                "pkcs7-digestData"
+#define NID_pkcs7_digest               25
+#define OBJ_pkcs7_digest               OBJ_pkcs7,5L
+
+#define LN_pkcs7_encrypted             "pkcs7-encryptedData"
+#define NID_pkcs7_encrypted            26
+#define OBJ_pkcs7_encrypted            OBJ_pkcs7,6L
+
+#define SN_pkcs9               "pkcs9"
+#define NID_pkcs9              47
+#define OBJ_pkcs9              OBJ_pkcs,9L
+
+#define LN_pkcs9_emailAddress          "emailAddress"
+#define NID_pkcs9_emailAddress         48
+#define OBJ_pkcs9_emailAddress         OBJ_pkcs9,1L
+
+#define LN_pkcs9_unstructuredName              "unstructuredName"
+#define NID_pkcs9_unstructuredName             49
+#define OBJ_pkcs9_unstructuredName             OBJ_pkcs9,2L
+
+#define LN_pkcs9_contentType           "contentType"
+#define NID_pkcs9_contentType          50
+#define OBJ_pkcs9_contentType          OBJ_pkcs9,3L
+
+#define LN_pkcs9_messageDigest         "messageDigest"
+#define NID_pkcs9_messageDigest                51
+#define OBJ_pkcs9_messageDigest                OBJ_pkcs9,4L
+
+#define LN_pkcs9_signingTime           "signingTime"
+#define NID_pkcs9_signingTime          52
+#define OBJ_pkcs9_signingTime          OBJ_pkcs9,5L
+
+#define LN_pkcs9_countersignature              "countersignature"
+#define NID_pkcs9_countersignature             53
+#define OBJ_pkcs9_countersignature             OBJ_pkcs9,6L
+
+#define LN_pkcs9_challengePassword             "challengePassword"
+#define NID_pkcs9_challengePassword            54
+#define OBJ_pkcs9_challengePassword            OBJ_pkcs9,7L
+
+#define LN_pkcs9_unstructuredAddress           "unstructuredAddress"
+#define NID_pkcs9_unstructuredAddress          55
+#define OBJ_pkcs9_unstructuredAddress          OBJ_pkcs9,8L
+
+#define LN_pkcs9_extCertAttributes             "extendedCertificateAttributes"
+#define NID_pkcs9_extCertAttributes            56
+#define OBJ_pkcs9_extCertAttributes            OBJ_pkcs9,9L
+
+#define SN_ext_req             "extReq"
+#define LN_ext_req             "Extension Request"
+#define NID_ext_req            172
+#define OBJ_ext_req            OBJ_pkcs9,14L
+
+#define SN_SMIMECapabilities           "SMIME-CAPS"
+#define LN_SMIMECapabilities           "S/MIME Capabilities"
+#define NID_SMIMECapabilities          167
+#define OBJ_SMIMECapabilities          OBJ_pkcs9,15L
+
+#define SN_SMIME               "SMIME"
+#define LN_SMIME               "S/MIME"
+#define NID_SMIME              188
+#define OBJ_SMIME              OBJ_pkcs9,16L
+
+#define SN_id_smime_mod                "id-smime-mod"
+#define NID_id_smime_mod               189
+#define OBJ_id_smime_mod               OBJ_SMIME,0L
+
+#define SN_id_smime_ct         "id-smime-ct"
+#define NID_id_smime_ct                190
+#define OBJ_id_smime_ct                OBJ_SMIME,1L
+
+#define SN_id_smime_aa         "id-smime-aa"
+#define NID_id_smime_aa                191
+#define OBJ_id_smime_aa                OBJ_SMIME,2L
+
+#define SN_id_smime_alg                "id-smime-alg"
+#define NID_id_smime_alg               192
+#define OBJ_id_smime_alg               OBJ_SMIME,3L
+
+#define SN_id_smime_cd         "id-smime-cd"
+#define NID_id_smime_cd                193
+#define OBJ_id_smime_cd                OBJ_SMIME,4L
+
+#define SN_id_smime_spq                "id-smime-spq"
+#define NID_id_smime_spq               194
+#define OBJ_id_smime_spq               OBJ_SMIME,5L
+
+#define SN_id_smime_cti                "id-smime-cti"
+#define NID_id_smime_cti               195
+#define OBJ_id_smime_cti               OBJ_SMIME,6L
+
+#define SN_id_smime_mod_cms            "id-smime-mod-cms"
+#define NID_id_smime_mod_cms           196
+#define OBJ_id_smime_mod_cms           OBJ_id_smime_mod,1L
+
+#define SN_id_smime_mod_ess            "id-smime-mod-ess"
+#define NID_id_smime_mod_ess           197
+#define OBJ_id_smime_mod_ess           OBJ_id_smime_mod,2L
+
+#define SN_id_smime_mod_oid            "id-smime-mod-oid"
+#define NID_id_smime_mod_oid           198
+#define OBJ_id_smime_mod_oid           OBJ_id_smime_mod,3L
+
+#define SN_id_smime_mod_msg_v3         "id-smime-mod-msg-v3"
+#define NID_id_smime_mod_msg_v3                199
+#define OBJ_id_smime_mod_msg_v3                OBJ_id_smime_mod,4L
+
+#define SN_id_smime_mod_ets_eSignature_88              "id-smime-mod-ets-eSignature-88"
+#define NID_id_smime_mod_ets_eSignature_88             200
+#define OBJ_id_smime_mod_ets_eSignature_88             OBJ_id_smime_mod,5L
+
+#define SN_id_smime_mod_ets_eSignature_97              "id-smime-mod-ets-eSignature-97"
+#define NID_id_smime_mod_ets_eSignature_97             201
+#define OBJ_id_smime_mod_ets_eSignature_97             OBJ_id_smime_mod,6L
+
+#define SN_id_smime_mod_ets_eSigPolicy_88              "id-smime-mod-ets-eSigPolicy-88"
+#define NID_id_smime_mod_ets_eSigPolicy_88             202
+#define OBJ_id_smime_mod_ets_eSigPolicy_88             OBJ_id_smime_mod,7L
+
+#define SN_id_smime_mod_ets_eSigPolicy_97              "id-smime-mod-ets-eSigPolicy-97"
+#define NID_id_smime_mod_ets_eSigPolicy_97             203
+#define OBJ_id_smime_mod_ets_eSigPolicy_97             OBJ_id_smime_mod,8L
+
+#define SN_id_smime_ct_receipt         "id-smime-ct-receipt"
+#define NID_id_smime_ct_receipt                204
+#define OBJ_id_smime_ct_receipt                OBJ_id_smime_ct,1L
+
+#define SN_id_smime_ct_authData                "id-smime-ct-authData"
+#define NID_id_smime_ct_authData               205
+#define OBJ_id_smime_ct_authData               OBJ_id_smime_ct,2L
+
+#define SN_id_smime_ct_publishCert             "id-smime-ct-publishCert"
+#define NID_id_smime_ct_publishCert            206
+#define OBJ_id_smime_ct_publishCert            OBJ_id_smime_ct,3L
+
+#define SN_id_smime_ct_TSTInfo         "id-smime-ct-TSTInfo"
+#define NID_id_smime_ct_TSTInfo                207
+#define OBJ_id_smime_ct_TSTInfo                OBJ_id_smime_ct,4L
+
+#define SN_id_smime_ct_TDTInfo         "id-smime-ct-TDTInfo"
+#define NID_id_smime_ct_TDTInfo                208
+#define OBJ_id_smime_ct_TDTInfo                OBJ_id_smime_ct,5L
+
+#define SN_id_smime_ct_contentInfo             "id-smime-ct-contentInfo"
+#define NID_id_smime_ct_contentInfo            209
+#define OBJ_id_smime_ct_contentInfo            OBJ_id_smime_ct,6L
+
+#define SN_id_smime_ct_DVCSRequestData         "id-smime-ct-DVCSRequestData"
+#define NID_id_smime_ct_DVCSRequestData                210
+#define OBJ_id_smime_ct_DVCSRequestData                OBJ_id_smime_ct,7L
+
+#define SN_id_smime_ct_DVCSResponseData                "id-smime-ct-DVCSResponseData"
+#define NID_id_smime_ct_DVCSResponseData               211
+#define OBJ_id_smime_ct_DVCSResponseData               OBJ_id_smime_ct,8L
+
+#define SN_id_smime_aa_receiptRequest          "id-smime-aa-receiptRequest"
+#define NID_id_smime_aa_receiptRequest         212
+#define OBJ_id_smime_aa_receiptRequest         OBJ_id_smime_aa,1L
+
+#define SN_id_smime_aa_securityLabel           "id-smime-aa-securityLabel"
+#define NID_id_smime_aa_securityLabel          213
+#define OBJ_id_smime_aa_securityLabel          OBJ_id_smime_aa,2L
+
+#define SN_id_smime_aa_mlExpandHistory         "id-smime-aa-mlExpandHistory"
+#define NID_id_smime_aa_mlExpandHistory                214
+#define OBJ_id_smime_aa_mlExpandHistory                OBJ_id_smime_aa,3L
+
+#define SN_id_smime_aa_contentHint             "id-smime-aa-contentHint"
+#define NID_id_smime_aa_contentHint            215
+#define OBJ_id_smime_aa_contentHint            OBJ_id_smime_aa,4L
+
+#define SN_id_smime_aa_msgSigDigest            "id-smime-aa-msgSigDigest"
+#define NID_id_smime_aa_msgSigDigest           216
+#define OBJ_id_smime_aa_msgSigDigest           OBJ_id_smime_aa,5L
+
+#define SN_id_smime_aa_encapContentType                "id-smime-aa-encapContentType"
+#define NID_id_smime_aa_encapContentType               217
+#define OBJ_id_smime_aa_encapContentType               OBJ_id_smime_aa,6L
+
+#define SN_id_smime_aa_contentIdentifier               "id-smime-aa-contentIdentifier"
+#define NID_id_smime_aa_contentIdentifier              218
+#define OBJ_id_smime_aa_contentIdentifier              OBJ_id_smime_aa,7L
+
+#define SN_id_smime_aa_macValue                "id-smime-aa-macValue"
+#define NID_id_smime_aa_macValue               219
+#define OBJ_id_smime_aa_macValue               OBJ_id_smime_aa,8L
+
+#define SN_id_smime_aa_equivalentLabels                "id-smime-aa-equivalentLabels"
+#define NID_id_smime_aa_equivalentLabels               220
+#define OBJ_id_smime_aa_equivalentLabels               OBJ_id_smime_aa,9L
+
+#define SN_id_smime_aa_contentReference                "id-smime-aa-contentReference"
+#define NID_id_smime_aa_contentReference               221
+#define OBJ_id_smime_aa_contentReference               OBJ_id_smime_aa,10L
+
+#define SN_id_smime_aa_encrypKeyPref           "id-smime-aa-encrypKeyPref"
+#define NID_id_smime_aa_encrypKeyPref          222
+#define OBJ_id_smime_aa_encrypKeyPref          OBJ_id_smime_aa,11L
+
+#define SN_id_smime_aa_signingCertificate              "id-smime-aa-signingCertificate"
+#define NID_id_smime_aa_signingCertificate             223
+#define OBJ_id_smime_aa_signingCertificate             OBJ_id_smime_aa,12L
+
+#define SN_id_smime_aa_smimeEncryptCerts               "id-smime-aa-smimeEncryptCerts"
+#define NID_id_smime_aa_smimeEncryptCerts              224
+#define OBJ_id_smime_aa_smimeEncryptCerts              OBJ_id_smime_aa,13L
+
+#define SN_id_smime_aa_timeStampToken          "id-smime-aa-timeStampToken"
+#define NID_id_smime_aa_timeStampToken         225
+#define OBJ_id_smime_aa_timeStampToken         OBJ_id_smime_aa,14L
+
+#define SN_id_smime_aa_ets_sigPolicyId         "id-smime-aa-ets-sigPolicyId"
+#define NID_id_smime_aa_ets_sigPolicyId                226
+#define OBJ_id_smime_aa_ets_sigPolicyId                OBJ_id_smime_aa,15L
+
+#define SN_id_smime_aa_ets_commitmentType              "id-smime-aa-ets-commitmentType"
+#define NID_id_smime_aa_ets_commitmentType             227
+#define OBJ_id_smime_aa_ets_commitmentType             OBJ_id_smime_aa,16L
+
+#define SN_id_smime_aa_ets_signerLocation              "id-smime-aa-ets-signerLocation"
+#define NID_id_smime_aa_ets_signerLocation             228
+#define OBJ_id_smime_aa_ets_signerLocation             OBJ_id_smime_aa,17L
+
+#define SN_id_smime_aa_ets_signerAttr          "id-smime-aa-ets-signerAttr"
+#define NID_id_smime_aa_ets_signerAttr         229
+#define OBJ_id_smime_aa_ets_signerAttr         OBJ_id_smime_aa,18L
+
+#define SN_id_smime_aa_ets_otherSigCert                "id-smime-aa-ets-otherSigCert"
+#define NID_id_smime_aa_ets_otherSigCert               230
+#define OBJ_id_smime_aa_ets_otherSigCert               OBJ_id_smime_aa,19L
+
+#define SN_id_smime_aa_ets_contentTimestamp            "id-smime-aa-ets-contentTimestamp"
+#define NID_id_smime_aa_ets_contentTimestamp           231
+#define OBJ_id_smime_aa_ets_contentTimestamp           OBJ_id_smime_aa,20L
+
+#define SN_id_smime_aa_ets_CertificateRefs             "id-smime-aa-ets-CertificateRefs"
+#define NID_id_smime_aa_ets_CertificateRefs            232
+#define OBJ_id_smime_aa_ets_CertificateRefs            OBJ_id_smime_aa,21L
+
+#define SN_id_smime_aa_ets_RevocationRefs              "id-smime-aa-ets-RevocationRefs"
+#define NID_id_smime_aa_ets_RevocationRefs             233
+#define OBJ_id_smime_aa_ets_RevocationRefs             OBJ_id_smime_aa,22L
+
+#define SN_id_smime_aa_ets_certValues          "id-smime-aa-ets-certValues"
+#define NID_id_smime_aa_ets_certValues         234
+#define OBJ_id_smime_aa_ets_certValues         OBJ_id_smime_aa,23L
+
+#define SN_id_smime_aa_ets_revocationValues            "id-smime-aa-ets-revocationValues"
+#define NID_id_smime_aa_ets_revocationValues           235
+#define OBJ_id_smime_aa_ets_revocationValues           OBJ_id_smime_aa,24L
+
+#define SN_id_smime_aa_ets_escTimeStamp                "id-smime-aa-ets-escTimeStamp"
+#define NID_id_smime_aa_ets_escTimeStamp               236
+#define OBJ_id_smime_aa_ets_escTimeStamp               OBJ_id_smime_aa,25L
+
+#define SN_id_smime_aa_ets_certCRLTimestamp            "id-smime-aa-ets-certCRLTimestamp"
+#define NID_id_smime_aa_ets_certCRLTimestamp           237
+#define OBJ_id_smime_aa_ets_certCRLTimestamp           OBJ_id_smime_aa,26L
+
+#define SN_id_smime_aa_ets_archiveTimeStamp            "id-smime-aa-ets-archiveTimeStamp"
+#define NID_id_smime_aa_ets_archiveTimeStamp           238
+#define OBJ_id_smime_aa_ets_archiveTimeStamp           OBJ_id_smime_aa,27L
+
+#define SN_id_smime_aa_signatureType           "id-smime-aa-signatureType"
+#define NID_id_smime_aa_signatureType          239
+#define OBJ_id_smime_aa_signatureType          OBJ_id_smime_aa,28L
+
+#define SN_id_smime_aa_dvcs_dvc                "id-smime-aa-dvcs-dvc"
+#define NID_id_smime_aa_dvcs_dvc               240
+#define OBJ_id_smime_aa_dvcs_dvc               OBJ_id_smime_aa,29L
+
+#define SN_id_smime_alg_ESDHwith3DES           "id-smime-alg-ESDHwith3DES"
+#define NID_id_smime_alg_ESDHwith3DES          241
+#define OBJ_id_smime_alg_ESDHwith3DES          OBJ_id_smime_alg,1L
+
+#define SN_id_smime_alg_ESDHwithRC2            "id-smime-alg-ESDHwithRC2"
+#define NID_id_smime_alg_ESDHwithRC2           242
+#define OBJ_id_smime_alg_ESDHwithRC2           OBJ_id_smime_alg,2L
+
+#define SN_id_smime_alg_3DESwrap               "id-smime-alg-3DESwrap"
+#define NID_id_smime_alg_3DESwrap              243
+#define OBJ_id_smime_alg_3DESwrap              OBJ_id_smime_alg,3L
+
+#define SN_id_smime_alg_RC2wrap                "id-smime-alg-RC2wrap"
+#define NID_id_smime_alg_RC2wrap               244
+#define OBJ_id_smime_alg_RC2wrap               OBJ_id_smime_alg,4L
+
+#define SN_id_smime_alg_ESDH           "id-smime-alg-ESDH"
+#define NID_id_smime_alg_ESDH          245
+#define OBJ_id_smime_alg_ESDH          OBJ_id_smime_alg,5L
+
+#define SN_id_smime_alg_CMS3DESwrap            "id-smime-alg-CMS3DESwrap"
+#define NID_id_smime_alg_CMS3DESwrap           246
+#define OBJ_id_smime_alg_CMS3DESwrap           OBJ_id_smime_alg,6L
+
+#define SN_id_smime_alg_CMSRC2wrap             "id-smime-alg-CMSRC2wrap"
+#define NID_id_smime_alg_CMSRC2wrap            247
+#define OBJ_id_smime_alg_CMSRC2wrap            OBJ_id_smime_alg,7L
+
+#define SN_id_smime_cd_ldap            "id-smime-cd-ldap"
+#define NID_id_smime_cd_ldap           248
+#define OBJ_id_smime_cd_ldap           OBJ_id_smime_cd,1L
+
+#define SN_id_smime_spq_ets_sqt_uri            "id-smime-spq-ets-sqt-uri"
+#define NID_id_smime_spq_ets_sqt_uri           249
+#define OBJ_id_smime_spq_ets_sqt_uri           OBJ_id_smime_spq,1L
+
+#define SN_id_smime_spq_ets_sqt_unotice                "id-smime-spq-ets-sqt-unotice"
+#define NID_id_smime_spq_ets_sqt_unotice               250
+#define OBJ_id_smime_spq_ets_sqt_unotice               OBJ_id_smime_spq,2L
+
+#define SN_id_smime_cti_ets_proofOfOrigin              "id-smime-cti-ets-proofOfOrigin"
+#define NID_id_smime_cti_ets_proofOfOrigin             251
+#define OBJ_id_smime_cti_ets_proofOfOrigin             OBJ_id_smime_cti,1L
+
+#define SN_id_smime_cti_ets_proofOfReceipt             "id-smime-cti-ets-proofOfReceipt"
+#define NID_id_smime_cti_ets_proofOfReceipt            252
+#define OBJ_id_smime_cti_ets_proofOfReceipt            OBJ_id_smime_cti,2L
+
+#define SN_id_smime_cti_ets_proofOfDelivery            "id-smime-cti-ets-proofOfDelivery"
+#define NID_id_smime_cti_ets_proofOfDelivery           253
+#define OBJ_id_smime_cti_ets_proofOfDelivery           OBJ_id_smime_cti,3L
+
+#define SN_id_smime_cti_ets_proofOfSender              "id-smime-cti-ets-proofOfSender"
+#define NID_id_smime_cti_ets_proofOfSender             254
+#define OBJ_id_smime_cti_ets_proofOfSender             OBJ_id_smime_cti,4L
+
+#define SN_id_smime_cti_ets_proofOfApproval            "id-smime-cti-ets-proofOfApproval"
+#define NID_id_smime_cti_ets_proofOfApproval           255
+#define OBJ_id_smime_cti_ets_proofOfApproval           OBJ_id_smime_cti,5L
+
+#define SN_id_smime_cti_ets_proofOfCreation            "id-smime-cti-ets-proofOfCreation"
+#define NID_id_smime_cti_ets_proofOfCreation           256
+#define OBJ_id_smime_cti_ets_proofOfCreation           OBJ_id_smime_cti,6L
+
+#define LN_friendlyName                "friendlyName"
+#define NID_friendlyName               156
+#define OBJ_friendlyName               OBJ_pkcs9,20L
+
+#define LN_localKeyID          "localKeyID"
+#define NID_localKeyID         157
+#define OBJ_localKeyID         OBJ_pkcs9,21L
+
+#define SN_ms_csp_name         "CSPName"
+#define LN_ms_csp_name         "Microsoft CSP Name"
+#define NID_ms_csp_name                417
+#define OBJ_ms_csp_name                1L,3L,6L,1L,4L,1L,311L,17L,1L
+
+#define OBJ_certTypes          OBJ_pkcs9,22L
+
+#define LN_x509Certificate             "x509Certificate"
+#define NID_x509Certificate            158
+#define OBJ_x509Certificate            OBJ_certTypes,1L
+
+#define LN_sdsiCertificate             "sdsiCertificate"
+#define NID_sdsiCertificate            159
+#define OBJ_sdsiCertificate            OBJ_certTypes,2L
+
+#define OBJ_crlTypes           OBJ_pkcs9,23L
+
+#define LN_x509Crl             "x509Crl"
+#define NID_x509Crl            160
+#define OBJ_x509Crl            OBJ_crlTypes,1L
+
+#define OBJ_pkcs12             OBJ_pkcs,12L
+
+#define OBJ_pkcs12_pbeids              OBJ_pkcs12,1L
+
+#define SN_pbe_WithSHA1And128BitRC4            "PBE-SHA1-RC4-128"
+#define LN_pbe_WithSHA1And128BitRC4            "pbeWithSHA1And128BitRC4"
+#define NID_pbe_WithSHA1And128BitRC4           144
+#define OBJ_pbe_WithSHA1And128BitRC4           OBJ_pkcs12_pbeids,1L
+
+#define SN_pbe_WithSHA1And40BitRC4             "PBE-SHA1-RC4-40"
+#define LN_pbe_WithSHA1And40BitRC4             "pbeWithSHA1And40BitRC4"
+#define NID_pbe_WithSHA1And40BitRC4            145
+#define OBJ_pbe_WithSHA1And40BitRC4            OBJ_pkcs12_pbeids,2L
+
+#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC          "PBE-SHA1-3DES"
+#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC          "pbeWithSHA1And3-KeyTripleDES-CBC"
+#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC         146
+#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC         OBJ_pkcs12_pbeids,3L
+
+#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC          "PBE-SHA1-2DES"
+#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC          "pbeWithSHA1And2-KeyTripleDES-CBC"
+#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC         147
+#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC         OBJ_pkcs12_pbeids,4L
+
+#define SN_pbe_WithSHA1And128BitRC2_CBC                "PBE-SHA1-RC2-128"
+#define LN_pbe_WithSHA1And128BitRC2_CBC                "pbeWithSHA1And128BitRC2-CBC"
+#define NID_pbe_WithSHA1And128BitRC2_CBC               148
+#define OBJ_pbe_WithSHA1And128BitRC2_CBC               OBJ_pkcs12_pbeids,5L
+
+#define SN_pbe_WithSHA1And40BitRC2_CBC         "PBE-SHA1-RC2-40"
+#define LN_pbe_WithSHA1And40BitRC2_CBC         "pbeWithSHA1And40BitRC2-CBC"
+#define NID_pbe_WithSHA1And40BitRC2_CBC                149
+#define OBJ_pbe_WithSHA1And40BitRC2_CBC                OBJ_pkcs12_pbeids,6L
+
+#define OBJ_pkcs12_Version1            OBJ_pkcs12,10L
+
+#define OBJ_pkcs12_BagIds              OBJ_pkcs12_Version1,1L
+
+#define LN_keyBag              "keyBag"
+#define NID_keyBag             150
+#define OBJ_keyBag             OBJ_pkcs12_BagIds,1L
+
+#define LN_pkcs8ShroudedKeyBag         "pkcs8ShroudedKeyBag"
+#define NID_pkcs8ShroudedKeyBag                151
+#define OBJ_pkcs8ShroudedKeyBag                OBJ_pkcs12_BagIds,2L
+
+#define LN_certBag             "certBag"
+#define NID_certBag            152
+#define OBJ_certBag            OBJ_pkcs12_BagIds,3L
+
+#define LN_crlBag              "crlBag"
+#define NID_crlBag             153
+#define OBJ_crlBag             OBJ_pkcs12_BagIds,4L
+
+#define LN_secretBag           "secretBag"
+#define NID_secretBag          154
+#define OBJ_secretBag          OBJ_pkcs12_BagIds,5L
+
+#define LN_safeContentsBag             "safeContentsBag"
+#define NID_safeContentsBag            155
+#define OBJ_safeContentsBag            OBJ_pkcs12_BagIds,6L
+
+#define SN_md2         "MD2"
+#define LN_md2         "md2"
+#define NID_md2                3
+#define OBJ_md2                OBJ_rsadsi,2L,2L
+
+#define SN_md4         "MD4"
+#define LN_md4         "md4"
+#define NID_md4                257
+#define OBJ_md4                OBJ_rsadsi,2L,4L
+
+#define SN_md5         "MD5"
+#define LN_md5         "md5"
+#define NID_md5                4
+#define OBJ_md5                OBJ_rsadsi,2L,5L
+
+#define SN_md5_sha1            "MD5-SHA1"
+#define LN_md5_sha1            "md5-sha1"
+#define NID_md5_sha1           114
+
+#define LN_hmacWithSHA1                "hmacWithSHA1"
+#define NID_hmacWithSHA1               163
+#define OBJ_hmacWithSHA1               OBJ_rsadsi,2L,7L
+
+#define SN_rc2_cbc             "RC2-CBC"
+#define LN_rc2_cbc             "rc2-cbc"
+#define NID_rc2_cbc            37
+#define OBJ_rc2_cbc            OBJ_rsadsi,3L,2L
+
+#define SN_rc2_ecb             "RC2-ECB"
+#define LN_rc2_ecb             "rc2-ecb"
+#define NID_rc2_ecb            38
+
+#define SN_rc2_cfb64           "RC2-CFB"
+#define LN_rc2_cfb64           "rc2-cfb"
+#define NID_rc2_cfb64          39
+
+#define SN_rc2_ofb64           "RC2-OFB"
+#define LN_rc2_ofb64           "rc2-ofb"
+#define NID_rc2_ofb64          40
+
+#define SN_rc2_40_cbc          "RC2-40-CBC"
+#define LN_rc2_40_cbc          "rc2-40-cbc"
+#define NID_rc2_40_cbc         98
+
+#define SN_rc2_64_cbc          "RC2-64-CBC"
+#define LN_rc2_64_cbc          "rc2-64-cbc"
+#define NID_rc2_64_cbc         166
+
+#define SN_rc4         "RC4"
+#define LN_rc4         "rc4"
+#define NID_rc4                5
+#define OBJ_rc4                OBJ_rsadsi,3L,4L
+
+#define SN_rc4_40              "RC4-40"
+#define LN_rc4_40              "rc4-40"
+#define NID_rc4_40             97
+
+#define SN_des_ede3_cbc                "DES-EDE3-CBC"
+#define LN_des_ede3_cbc                "des-ede3-cbc"
+#define NID_des_ede3_cbc               44
+#define OBJ_des_ede3_cbc               OBJ_rsadsi,3L,7L
+
+#define SN_rc5_cbc             "RC5-CBC"
+#define LN_rc5_cbc             "rc5-cbc"
+#define NID_rc5_cbc            120
+#define OBJ_rc5_cbc            OBJ_rsadsi,3L,8L
+
+#define SN_rc5_ecb             "RC5-ECB"
+#define LN_rc5_ecb             "rc5-ecb"
+#define NID_rc5_ecb            121
+
+#define SN_rc5_cfb64           "RC5-CFB"
+#define LN_rc5_cfb64           "rc5-cfb"
+#define NID_rc5_cfb64          122
+
+#define SN_rc5_ofb64           "RC5-OFB"
+#define LN_rc5_ofb64           "rc5-ofb"
+#define NID_rc5_ofb64          123
+
+#define SN_ms_ext_req          "msExtReq"
+#define LN_ms_ext_req          "Microsoft Extension Request"
+#define NID_ms_ext_req         171
+#define OBJ_ms_ext_req         1L,3L,6L,1L,4L,1L,311L,2L,1L,14L
+
+#define SN_ms_code_ind         "msCodeInd"
+#define LN_ms_code_ind         "Microsoft Individual Code Signing"
+#define NID_ms_code_ind                134
+#define OBJ_ms_code_ind                1L,3L,6L,1L,4L,1L,311L,2L,1L,21L
+
+#define SN_ms_code_com         "msCodeCom"
+#define LN_ms_code_com         "Microsoft Commercial Code Signing"
+#define NID_ms_code_com                135
+#define OBJ_ms_code_com                1L,3L,6L,1L,4L,1L,311L,2L,1L,22L
+
+#define SN_ms_ctl_sign         "msCTLSign"
+#define LN_ms_ctl_sign         "Microsoft Trust List Signing"
+#define NID_ms_ctl_sign                136
+#define OBJ_ms_ctl_sign                1L,3L,6L,1L,4L,1L,311L,10L,3L,1L
+
+#define SN_ms_sgc              "msSGC"
+#define LN_ms_sgc              "Microsoft Server Gated Crypto"
+#define NID_ms_sgc             137
+#define OBJ_ms_sgc             1L,3L,6L,1L,4L,1L,311L,10L,3L,3L
+
+#define SN_ms_efs              "msEFS"
+#define LN_ms_efs              "Microsoft Encrypted File System"
+#define NID_ms_efs             138
+#define OBJ_ms_efs             1L,3L,6L,1L,4L,1L,311L,10L,3L,4L
+
+#define SN_ms_smartcard_login          "msSmartcardLogin"
+#define LN_ms_smartcard_login          "Microsoft Smartcardlogin"
+#define NID_ms_smartcard_login         648
+#define OBJ_ms_smartcard_login         1L,3L,6L,1L,4L,1L,311L,20L,2L,2L
+
+#define SN_ms_upn              "msUPN"
+#define LN_ms_upn              "Microsoft Universal Principal Name"
+#define NID_ms_upn             649
+#define OBJ_ms_upn             1L,3L,6L,1L,4L,1L,311L,20L,2L,3L
+
+#define SN_idea_cbc            "IDEA-CBC"
+#define LN_idea_cbc            "idea-cbc"
+#define NID_idea_cbc           34
+#define OBJ_idea_cbc           1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L
+
+#define SN_idea_ecb            "IDEA-ECB"
+#define LN_idea_ecb            "idea-ecb"
+#define NID_idea_ecb           36
+
+#define SN_idea_cfb64          "IDEA-CFB"
+#define LN_idea_cfb64          "idea-cfb"
+#define NID_idea_cfb64         35
+
+#define SN_idea_ofb64          "IDEA-OFB"
+#define LN_idea_ofb64          "idea-ofb"
+#define NID_idea_ofb64         46
+
+#define SN_bf_cbc              "BF-CBC"
+#define LN_bf_cbc              "bf-cbc"
+#define NID_bf_cbc             91
+#define OBJ_bf_cbc             1L,3L,6L,1L,4L,1L,3029L,1L,2L
+
+#define SN_bf_ecb              "BF-ECB"
+#define LN_bf_ecb              "bf-ecb"
+#define NID_bf_ecb             92
+
+#define SN_bf_cfb64            "BF-CFB"
+#define LN_bf_cfb64            "bf-cfb"
+#define NID_bf_cfb64           93
+
+#define SN_bf_ofb64            "BF-OFB"
+#define LN_bf_ofb64            "bf-ofb"
+#define NID_bf_ofb64           94
+
+#define SN_id_pkix             "PKIX"
+#define NID_id_pkix            127
+#define OBJ_id_pkix            1L,3L,6L,1L,5L,5L,7L
+
+#define SN_id_pkix_mod         "id-pkix-mod"
+#define NID_id_pkix_mod                258
+#define OBJ_id_pkix_mod                OBJ_id_pkix,0L
+
+#define SN_id_pe               "id-pe"
+#define NID_id_pe              175
+#define OBJ_id_pe              OBJ_id_pkix,1L
+
+#define SN_id_qt               "id-qt"
+#define NID_id_qt              259
+#define OBJ_id_qt              OBJ_id_pkix,2L
+
+#define SN_id_kp               "id-kp"
+#define NID_id_kp              128
+#define OBJ_id_kp              OBJ_id_pkix,3L
+
+#define SN_id_it               "id-it"
+#define NID_id_it              260
+#define OBJ_id_it              OBJ_id_pkix,4L
+
+#define SN_id_pkip             "id-pkip"
+#define NID_id_pkip            261
+#define OBJ_id_pkip            OBJ_id_pkix,5L
+
+#define SN_id_alg              "id-alg"
+#define NID_id_alg             262
+#define OBJ_id_alg             OBJ_id_pkix,6L
+
+#define SN_id_cmc              "id-cmc"
+#define NID_id_cmc             263
+#define OBJ_id_cmc             OBJ_id_pkix,7L
+
+#define SN_id_on               "id-on"
+#define NID_id_on              264
+#define OBJ_id_on              OBJ_id_pkix,8L
+
+#define SN_id_pda              "id-pda"
+#define NID_id_pda             265
+#define OBJ_id_pda             OBJ_id_pkix,9L
+
+#define SN_id_aca              "id-aca"
+#define NID_id_aca             266
+#define OBJ_id_aca             OBJ_id_pkix,10L
+
+#define SN_id_qcs              "id-qcs"
+#define NID_id_qcs             267
+#define OBJ_id_qcs             OBJ_id_pkix,11L
+
+#define SN_id_cct              "id-cct"
+#define NID_id_cct             268
+#define OBJ_id_cct             OBJ_id_pkix,12L
+
+#define SN_id_ppl              "id-ppl"
+#define NID_id_ppl             662
+#define OBJ_id_ppl             OBJ_id_pkix,21L
+
+#define SN_id_ad               "id-ad"
+#define NID_id_ad              176
+#define OBJ_id_ad              OBJ_id_pkix,48L
+
+#define SN_id_pkix1_explicit_88                "id-pkix1-explicit-88"
+#define NID_id_pkix1_explicit_88               269
+#define OBJ_id_pkix1_explicit_88               OBJ_id_pkix_mod,1L
+
+#define SN_id_pkix1_implicit_88                "id-pkix1-implicit-88"
+#define NID_id_pkix1_implicit_88               270
+#define OBJ_id_pkix1_implicit_88               OBJ_id_pkix_mod,2L
+
+#define SN_id_pkix1_explicit_93                "id-pkix1-explicit-93"
+#define NID_id_pkix1_explicit_93               271
+#define OBJ_id_pkix1_explicit_93               OBJ_id_pkix_mod,3L
+
+#define SN_id_pkix1_implicit_93                "id-pkix1-implicit-93"
+#define NID_id_pkix1_implicit_93               272
+#define OBJ_id_pkix1_implicit_93               OBJ_id_pkix_mod,4L
+
+#define SN_id_mod_crmf         "id-mod-crmf"
+#define NID_id_mod_crmf                273
+#define OBJ_id_mod_crmf                OBJ_id_pkix_mod,5L
+
+#define SN_id_mod_cmc          "id-mod-cmc"
+#define NID_id_mod_cmc         274
+#define OBJ_id_mod_cmc         OBJ_id_pkix_mod,6L
+
+#define SN_id_mod_kea_profile_88               "id-mod-kea-profile-88"
+#define NID_id_mod_kea_profile_88              275
+#define OBJ_id_mod_kea_profile_88              OBJ_id_pkix_mod,7L
+
+#define SN_id_mod_kea_profile_93               "id-mod-kea-profile-93"
+#define NID_id_mod_kea_profile_93              276
+#define OBJ_id_mod_kea_profile_93              OBJ_id_pkix_mod,8L
+
+#define SN_id_mod_cmp          "id-mod-cmp"
+#define NID_id_mod_cmp         277
+#define OBJ_id_mod_cmp         OBJ_id_pkix_mod,9L
+
+#define SN_id_mod_qualified_cert_88            "id-mod-qualified-cert-88"
+#define NID_id_mod_qualified_cert_88           278
+#define OBJ_id_mod_qualified_cert_88           OBJ_id_pkix_mod,10L
+
+#define SN_id_mod_qualified_cert_93            "id-mod-qualified-cert-93"
+#define NID_id_mod_qualified_cert_93           279
+#define OBJ_id_mod_qualified_cert_93           OBJ_id_pkix_mod,11L
+
+#define SN_id_mod_attribute_cert               "id-mod-attribute-cert"
+#define NID_id_mod_attribute_cert              280
+#define OBJ_id_mod_attribute_cert              OBJ_id_pkix_mod,12L
+
+#define SN_id_mod_timestamp_protocol           "id-mod-timestamp-protocol"
+#define NID_id_mod_timestamp_protocol          281
+#define OBJ_id_mod_timestamp_protocol          OBJ_id_pkix_mod,13L
+
+#define SN_id_mod_ocsp         "id-mod-ocsp"
+#define NID_id_mod_ocsp                282
+#define OBJ_id_mod_ocsp                OBJ_id_pkix_mod,14L
+
+#define SN_id_mod_dvcs         "id-mod-dvcs"
+#define NID_id_mod_dvcs                283
+#define OBJ_id_mod_dvcs                OBJ_id_pkix_mod,15L
+
+#define SN_id_mod_cmp2000              "id-mod-cmp2000"
+#define NID_id_mod_cmp2000             284
+#define OBJ_id_mod_cmp2000             OBJ_id_pkix_mod,16L
+
+#define SN_info_access         "authorityInfoAccess"
+#define LN_info_access         "Authority Information Access"
+#define NID_info_access                177
+#define OBJ_info_access                OBJ_id_pe,1L
+
+#define SN_biometricInfo               "biometricInfo"
+#define LN_biometricInfo               "Biometric Info"
+#define NID_biometricInfo              285
+#define OBJ_biometricInfo              OBJ_id_pe,2L
+
+#define SN_qcStatements                "qcStatements"
+#define NID_qcStatements               286
+#define OBJ_qcStatements               OBJ_id_pe,3L
+
+#define SN_ac_auditEntity              "ac-auditEntity"
+#define NID_ac_auditEntity             287
+#define OBJ_ac_auditEntity             OBJ_id_pe,4L
+
+#define SN_ac_targeting                "ac-targeting"
+#define NID_ac_targeting               288
+#define OBJ_ac_targeting               OBJ_id_pe,5L
+
+#define SN_aaControls          "aaControls"
+#define NID_aaControls         289
+#define OBJ_aaControls         OBJ_id_pe,6L
+
+#define SN_sbqp_ipAddrBlock            "sbqp-ipAddrBlock"
+#define NID_sbqp_ipAddrBlock           290
+#define OBJ_sbqp_ipAddrBlock           OBJ_id_pe,7L
+
+#define SN_sbqp_autonomousSysNum               "sbqp-autonomousSysNum"
+#define NID_sbqp_autonomousSysNum              291
+#define OBJ_sbqp_autonomousSysNum              OBJ_id_pe,8L
+
+#define SN_sbqp_routerIdentifier               "sbqp-routerIdentifier"
+#define NID_sbqp_routerIdentifier              292
+#define OBJ_sbqp_routerIdentifier              OBJ_id_pe,9L
+
+#define SN_ac_proxying         "ac-proxying"
+#define NID_ac_proxying                397
+#define OBJ_ac_proxying                OBJ_id_pe,10L
+
+#define SN_sinfo_access                "subjectInfoAccess"
+#define LN_sinfo_access                "Subject Information Access"
+#define NID_sinfo_access               398
+#define OBJ_sinfo_access               OBJ_id_pe,11L
+
+#define SN_proxyCertInfo               "proxyCertInfo"
+#define LN_proxyCertInfo               "Proxy Certificate Information"
+#define NID_proxyCertInfo              663
+#define OBJ_proxyCertInfo              OBJ_id_pe,14L
+
+#define SN_id_qt_cps           "id-qt-cps"
+#define LN_id_qt_cps           "Policy Qualifier CPS"
+#define NID_id_qt_cps          164
+#define OBJ_id_qt_cps          OBJ_id_qt,1L
+
+#define SN_id_qt_unotice               "id-qt-unotice"
+#define LN_id_qt_unotice               "Policy Qualifier User Notice"
+#define NID_id_qt_unotice              165
+#define OBJ_id_qt_unotice              OBJ_id_qt,2L
+
+#define SN_textNotice          "textNotice"
+#define NID_textNotice         293
+#define OBJ_textNotice         OBJ_id_qt,3L
+
+#define SN_server_auth         "serverAuth"
+#define LN_server_auth         "TLS Web Server Authentication"
+#define NID_server_auth                129
+#define OBJ_server_auth                OBJ_id_kp,1L
+
+#define SN_client_auth         "clientAuth"
+#define LN_client_auth         "TLS Web Client Authentication"
+#define NID_client_auth                130
+#define OBJ_client_auth                OBJ_id_kp,2L
+
+#define SN_code_sign           "codeSigning"
+#define LN_code_sign           "Code Signing"
+#define NID_code_sign          131
+#define OBJ_code_sign          OBJ_id_kp,3L
+
+#define SN_email_protect               "emailProtection"
+#define LN_email_protect               "E-mail Protection"
+#define NID_email_protect              132
+#define OBJ_email_protect              OBJ_id_kp,4L
+
+#define SN_ipsecEndSystem              "ipsecEndSystem"
+#define LN_ipsecEndSystem              "IPSec End System"
+#define NID_ipsecEndSystem             294
+#define OBJ_ipsecEndSystem             OBJ_id_kp,5L
+
+#define SN_ipsecTunnel         "ipsecTunnel"
+#define LN_ipsecTunnel         "IPSec Tunnel"
+#define NID_ipsecTunnel                295
+#define OBJ_ipsecTunnel                OBJ_id_kp,6L
+
+#define SN_ipsecUser           "ipsecUser"
+#define LN_ipsecUser           "IPSec User"
+#define NID_ipsecUser          296
+#define OBJ_ipsecUser          OBJ_id_kp,7L
+
+#define SN_time_stamp          "timeStamping"
+#define LN_time_stamp          "Time Stamping"
+#define NID_time_stamp         133
+#define OBJ_time_stamp         OBJ_id_kp,8L
+
+#define SN_OCSP_sign           "OCSPSigning"
+#define LN_OCSP_sign           "OCSP Signing"
+#define NID_OCSP_sign          180
+#define OBJ_OCSP_sign          OBJ_id_kp,9L
+
+#define SN_dvcs                "DVCS"
+#define LN_dvcs                "dvcs"
+#define NID_dvcs               297
+#define OBJ_dvcs               OBJ_id_kp,10L
+
+#define SN_id_it_caProtEncCert         "id-it-caProtEncCert"
+#define NID_id_it_caProtEncCert                298
+#define OBJ_id_it_caProtEncCert                OBJ_id_it,1L
+
+#define SN_id_it_signKeyPairTypes              "id-it-signKeyPairTypes"
+#define NID_id_it_signKeyPairTypes             299
+#define OBJ_id_it_signKeyPairTypes             OBJ_id_it,2L
+
+#define SN_id_it_encKeyPairTypes               "id-it-encKeyPairTypes"
+#define NID_id_it_encKeyPairTypes              300
+#define OBJ_id_it_encKeyPairTypes              OBJ_id_it,3L
+
+#define SN_id_it_preferredSymmAlg              "id-it-preferredSymmAlg"
+#define NID_id_it_preferredSymmAlg             301
+#define OBJ_id_it_preferredSymmAlg             OBJ_id_it,4L
+
+#define SN_id_it_caKeyUpdateInfo               "id-it-caKeyUpdateInfo"
+#define NID_id_it_caKeyUpdateInfo              302
+#define OBJ_id_it_caKeyUpdateInfo              OBJ_id_it,5L
+
+#define SN_id_it_currentCRL            "id-it-currentCRL"
+#define NID_id_it_currentCRL           303
+#define OBJ_id_it_currentCRL           OBJ_id_it,6L
+
+#define SN_id_it_unsupportedOIDs               "id-it-unsupportedOIDs"
+#define NID_id_it_unsupportedOIDs              304
+#define OBJ_id_it_unsupportedOIDs              OBJ_id_it,7L
+
+#define SN_id_it_subscriptionRequest           "id-it-subscriptionRequest"
+#define NID_id_it_subscriptionRequest          305
+#define OBJ_id_it_subscriptionRequest          OBJ_id_it,8L
+
+#define SN_id_it_subscriptionResponse          "id-it-subscriptionResponse"
+#define NID_id_it_subscriptionResponse         306
+#define OBJ_id_it_subscriptionResponse         OBJ_id_it,9L
+
+#define SN_id_it_keyPairParamReq               "id-it-keyPairParamReq"
+#define NID_id_it_keyPairParamReq              307
+#define OBJ_id_it_keyPairParamReq              OBJ_id_it,10L
+
+#define SN_id_it_keyPairParamRep               "id-it-keyPairParamRep"
+#define NID_id_it_keyPairParamRep              308
+#define OBJ_id_it_keyPairParamRep              OBJ_id_it,11L
+
+#define SN_id_it_revPassphrase         "id-it-revPassphrase"
+#define NID_id_it_revPassphrase                309
+#define OBJ_id_it_revPassphrase                OBJ_id_it,12L
+
+#define SN_id_it_implicitConfirm               "id-it-implicitConfirm"
+#define NID_id_it_implicitConfirm              310
+#define OBJ_id_it_implicitConfirm              OBJ_id_it,13L
+
+#define SN_id_it_confirmWaitTime               "id-it-confirmWaitTime"
+#define NID_id_it_confirmWaitTime              311
+#define OBJ_id_it_confirmWaitTime              OBJ_id_it,14L
+
+#define SN_id_it_origPKIMessage                "id-it-origPKIMessage"
+#define NID_id_it_origPKIMessage               312
+#define OBJ_id_it_origPKIMessage               OBJ_id_it,15L
+
+#define SN_id_regCtrl          "id-regCtrl"
+#define NID_id_regCtrl         313
+#define OBJ_id_regCtrl         OBJ_id_pkip,1L
+
+#define SN_id_regInfo          "id-regInfo"
+#define NID_id_regInfo         314
+#define OBJ_id_regInfo         OBJ_id_pkip,2L
+
+#define SN_id_regCtrl_regToken         "id-regCtrl-regToken"
+#define NID_id_regCtrl_regToken                315
+#define OBJ_id_regCtrl_regToken                OBJ_id_regCtrl,1L
+
+#define SN_id_regCtrl_authenticator            "id-regCtrl-authenticator"
+#define NID_id_regCtrl_authenticator           316
+#define OBJ_id_regCtrl_authenticator           OBJ_id_regCtrl,2L
+
+#define SN_id_regCtrl_pkiPublicationInfo               "id-regCtrl-pkiPublicationInfo"
+#define NID_id_regCtrl_pkiPublicationInfo              317
+#define OBJ_id_regCtrl_pkiPublicationInfo              OBJ_id_regCtrl,3L
+
+#define SN_id_regCtrl_pkiArchiveOptions                "id-regCtrl-pkiArchiveOptions"
+#define NID_id_regCtrl_pkiArchiveOptions               318
+#define OBJ_id_regCtrl_pkiArchiveOptions               OBJ_id_regCtrl,4L
+
+#define SN_id_regCtrl_oldCertID                "id-regCtrl-oldCertID"
+#define NID_id_regCtrl_oldCertID               319
+#define OBJ_id_regCtrl_oldCertID               OBJ_id_regCtrl,5L
+
+#define SN_id_regCtrl_protocolEncrKey          "id-regCtrl-protocolEncrKey"
+#define NID_id_regCtrl_protocolEncrKey         320
+#define OBJ_id_regCtrl_protocolEncrKey         OBJ_id_regCtrl,6L
+
+#define SN_id_regInfo_utf8Pairs                "id-regInfo-utf8Pairs"
+#define NID_id_regInfo_utf8Pairs               321
+#define OBJ_id_regInfo_utf8Pairs               OBJ_id_regInfo,1L
+
+#define SN_id_regInfo_certReq          "id-regInfo-certReq"
+#define NID_id_regInfo_certReq         322
+#define OBJ_id_regInfo_certReq         OBJ_id_regInfo,2L
+
+#define SN_id_alg_des40                "id-alg-des40"
+#define NID_id_alg_des40               323
+#define OBJ_id_alg_des40               OBJ_id_alg,1L
+
+#define SN_id_alg_noSignature          "id-alg-noSignature"
+#define NID_id_alg_noSignature         324
+#define OBJ_id_alg_noSignature         OBJ_id_alg,2L
+
+#define SN_id_alg_dh_sig_hmac_sha1             "id-alg-dh-sig-hmac-sha1"
+#define NID_id_alg_dh_sig_hmac_sha1            325
+#define OBJ_id_alg_dh_sig_hmac_sha1            OBJ_id_alg,3L
+
+#define SN_id_alg_dh_pop               "id-alg-dh-pop"
+#define NID_id_alg_dh_pop              326
+#define OBJ_id_alg_dh_pop              OBJ_id_alg,4L
+
+#define SN_id_cmc_statusInfo           "id-cmc-statusInfo"
+#define NID_id_cmc_statusInfo          327
+#define OBJ_id_cmc_statusInfo          OBJ_id_cmc,1L
+
+#define SN_id_cmc_identification               "id-cmc-identification"
+#define NID_id_cmc_identification              328
+#define OBJ_id_cmc_identification              OBJ_id_cmc,2L
+
+#define SN_id_cmc_identityProof                "id-cmc-identityProof"
+#define NID_id_cmc_identityProof               329
+#define OBJ_id_cmc_identityProof               OBJ_id_cmc,3L
+
+#define SN_id_cmc_dataReturn           "id-cmc-dataReturn"
+#define NID_id_cmc_dataReturn          330
+#define OBJ_id_cmc_dataReturn          OBJ_id_cmc,4L
+
+#define SN_id_cmc_transactionId                "id-cmc-transactionId"
+#define NID_id_cmc_transactionId               331
+#define OBJ_id_cmc_transactionId               OBJ_id_cmc,5L
+
+#define SN_id_cmc_senderNonce          "id-cmc-senderNonce"
+#define NID_id_cmc_senderNonce         332
+#define OBJ_id_cmc_senderNonce         OBJ_id_cmc,6L
+
+#define SN_id_cmc_recipientNonce               "id-cmc-recipientNonce"
+#define NID_id_cmc_recipientNonce              333
+#define OBJ_id_cmc_recipientNonce              OBJ_id_cmc,7L
+
+#define SN_id_cmc_addExtensions                "id-cmc-addExtensions"
+#define NID_id_cmc_addExtensions               334
+#define OBJ_id_cmc_addExtensions               OBJ_id_cmc,8L
+
+#define SN_id_cmc_encryptedPOP         "id-cmc-encryptedPOP"
+#define NID_id_cmc_encryptedPOP                335
+#define OBJ_id_cmc_encryptedPOP                OBJ_id_cmc,9L
+
+#define SN_id_cmc_decryptedPOP         "id-cmc-decryptedPOP"
+#define NID_id_cmc_decryptedPOP                336
+#define OBJ_id_cmc_decryptedPOP                OBJ_id_cmc,10L
+
+#define SN_id_cmc_lraPOPWitness                "id-cmc-lraPOPWitness"
+#define NID_id_cmc_lraPOPWitness               337
+#define OBJ_id_cmc_lraPOPWitness               OBJ_id_cmc,11L
+
+#define SN_id_cmc_getCert              "id-cmc-getCert"
+#define NID_id_cmc_getCert             338
+#define OBJ_id_cmc_getCert             OBJ_id_cmc,15L
+
+#define SN_id_cmc_getCRL               "id-cmc-getCRL"
+#define NID_id_cmc_getCRL              339
+#define OBJ_id_cmc_getCRL              OBJ_id_cmc,16L
+
+#define SN_id_cmc_revokeRequest                "id-cmc-revokeRequest"
+#define NID_id_cmc_revokeRequest               340
+#define OBJ_id_cmc_revokeRequest               OBJ_id_cmc,17L
+
+#define SN_id_cmc_regInfo              "id-cmc-regInfo"
+#define NID_id_cmc_regInfo             341
+#define OBJ_id_cmc_regInfo             OBJ_id_cmc,18L
+
+#define SN_id_cmc_responseInfo         "id-cmc-responseInfo"
+#define NID_id_cmc_responseInfo                342
+#define OBJ_id_cmc_responseInfo                OBJ_id_cmc,19L
+
+#define SN_id_cmc_queryPending         "id-cmc-queryPending"
+#define NID_id_cmc_queryPending                343
+#define OBJ_id_cmc_queryPending                OBJ_id_cmc,21L
+
+#define SN_id_cmc_popLinkRandom                "id-cmc-popLinkRandom"
+#define NID_id_cmc_popLinkRandom               344
+#define OBJ_id_cmc_popLinkRandom               OBJ_id_cmc,22L
+
+#define SN_id_cmc_popLinkWitness               "id-cmc-popLinkWitness"
+#define NID_id_cmc_popLinkWitness              345
+#define OBJ_id_cmc_popLinkWitness              OBJ_id_cmc,23L
+
+#define SN_id_cmc_confirmCertAcceptance                "id-cmc-confirmCertAcceptance"
+#define NID_id_cmc_confirmCertAcceptance               346
+#define OBJ_id_cmc_confirmCertAcceptance               OBJ_id_cmc,24L
+
+#define SN_id_on_personalData          "id-on-personalData"
+#define NID_id_on_personalData         347
+#define OBJ_id_on_personalData         OBJ_id_on,1L
+
+#define SN_id_pda_dateOfBirth          "id-pda-dateOfBirth"
+#define NID_id_pda_dateOfBirth         348
+#define OBJ_id_pda_dateOfBirth         OBJ_id_pda,1L
+
+#define SN_id_pda_placeOfBirth         "id-pda-placeOfBirth"
+#define NID_id_pda_placeOfBirth                349
+#define OBJ_id_pda_placeOfBirth                OBJ_id_pda,2L
+
+#define SN_id_pda_gender               "id-pda-gender"
+#define NID_id_pda_gender              351
+#define OBJ_id_pda_gender              OBJ_id_pda,3L
+
+#define SN_id_pda_countryOfCitizenship         "id-pda-countryOfCitizenship"
+#define NID_id_pda_countryOfCitizenship                352
+#define OBJ_id_pda_countryOfCitizenship                OBJ_id_pda,4L
+
+#define SN_id_pda_countryOfResidence           "id-pda-countryOfResidence"
+#define NID_id_pda_countryOfResidence          353
+#define OBJ_id_pda_countryOfResidence          OBJ_id_pda,5L
+
+#define SN_id_aca_authenticationInfo           "id-aca-authenticationInfo"
+#define NID_id_aca_authenticationInfo          354
+#define OBJ_id_aca_authenticationInfo          OBJ_id_aca,1L
+
+#define SN_id_aca_accessIdentity               "id-aca-accessIdentity"
+#define NID_id_aca_accessIdentity              355
+#define OBJ_id_aca_accessIdentity              OBJ_id_aca,2L
+
+#define SN_id_aca_chargingIdentity             "id-aca-chargingIdentity"
+#define NID_id_aca_chargingIdentity            356
+#define OBJ_id_aca_chargingIdentity            OBJ_id_aca,3L
+
+#define SN_id_aca_group                "id-aca-group"
+#define NID_id_aca_group               357
+#define OBJ_id_aca_group               OBJ_id_aca,4L
+
+#define SN_id_aca_role         "id-aca-role"
+#define NID_id_aca_role                358
+#define OBJ_id_aca_role                OBJ_id_aca,5L
+
+#define SN_id_aca_encAttrs             "id-aca-encAttrs"
+#define NID_id_aca_encAttrs            399
+#define OBJ_id_aca_encAttrs            OBJ_id_aca,6L
+
+#define SN_id_qcs_pkixQCSyntax_v1              "id-qcs-pkixQCSyntax-v1"
+#define NID_id_qcs_pkixQCSyntax_v1             359
+#define OBJ_id_qcs_pkixQCSyntax_v1             OBJ_id_qcs,1L
+
+#define SN_id_cct_crs          "id-cct-crs"
+#define NID_id_cct_crs         360
+#define OBJ_id_cct_crs         OBJ_id_cct,1L
+
+#define SN_id_cct_PKIData              "id-cct-PKIData"
+#define NID_id_cct_PKIData             361
+#define OBJ_id_cct_PKIData             OBJ_id_cct,2L
+
+#define SN_id_cct_PKIResponse          "id-cct-PKIResponse"
+#define NID_id_cct_PKIResponse         362
+#define OBJ_id_cct_PKIResponse         OBJ_id_cct,3L
+
+#define SN_id_ppl_anyLanguage          "id-ppl-anyLanguage"
+#define LN_id_ppl_anyLanguage          "Any language"
+#define NID_id_ppl_anyLanguage         664
+#define OBJ_id_ppl_anyLanguage         OBJ_id_ppl,0L
+
+#define SN_id_ppl_inheritAll           "id-ppl-inheritAll"
+#define LN_id_ppl_inheritAll           "Inherit all"
+#define NID_id_ppl_inheritAll          665
+#define OBJ_id_ppl_inheritAll          OBJ_id_ppl,1L
+
+#define SN_Independent         "id-ppl-independent"
+#define LN_Independent         "Independent"
+#define NID_Independent                667
+#define OBJ_Independent                OBJ_id_ppl,2L
+
+#define SN_ad_OCSP             "OCSP"
+#define LN_ad_OCSP             "OCSP"
+#define NID_ad_OCSP            178
+#define OBJ_ad_OCSP            OBJ_id_ad,1L
+
+#define SN_ad_ca_issuers               "caIssuers"
+#define LN_ad_ca_issuers               "CA Issuers"
+#define NID_ad_ca_issuers              179
+#define OBJ_ad_ca_issuers              OBJ_id_ad,2L
+
+#define SN_ad_timeStamping             "ad_timestamping"
+#define LN_ad_timeStamping             "AD Time Stamping"
+#define NID_ad_timeStamping            363
+#define OBJ_ad_timeStamping            OBJ_id_ad,3L
+
+#define SN_ad_dvcs             "AD_DVCS"
+#define LN_ad_dvcs             "ad dvcs"
+#define NID_ad_dvcs            364
+#define OBJ_ad_dvcs            OBJ_id_ad,4L
+
+#define OBJ_id_pkix_OCSP               OBJ_ad_OCSP
+
+#define SN_id_pkix_OCSP_basic          "basicOCSPResponse"
+#define LN_id_pkix_OCSP_basic          "Basic OCSP Response"
+#define NID_id_pkix_OCSP_basic         365
+#define OBJ_id_pkix_OCSP_basic         OBJ_id_pkix_OCSP,1L
+
+#define SN_id_pkix_OCSP_Nonce          "Nonce"
+#define LN_id_pkix_OCSP_Nonce          "OCSP Nonce"
+#define NID_id_pkix_OCSP_Nonce         366
+#define OBJ_id_pkix_OCSP_Nonce         OBJ_id_pkix_OCSP,2L
+
+#define SN_id_pkix_OCSP_CrlID          "CrlID"
+#define LN_id_pkix_OCSP_CrlID          "OCSP CRL ID"
+#define NID_id_pkix_OCSP_CrlID         367
+#define OBJ_id_pkix_OCSP_CrlID         OBJ_id_pkix_OCSP,3L
+
+#define SN_id_pkix_OCSP_acceptableResponses            "acceptableResponses"
+#define LN_id_pkix_OCSP_acceptableResponses            "Acceptable OCSP Responses"
+#define NID_id_pkix_OCSP_acceptableResponses           368
+#define OBJ_id_pkix_OCSP_acceptableResponses           OBJ_id_pkix_OCSP,4L
+
+#define SN_id_pkix_OCSP_noCheck                "noCheck"
+#define LN_id_pkix_OCSP_noCheck                "OCSP No Check"
+#define NID_id_pkix_OCSP_noCheck               369
+#define OBJ_id_pkix_OCSP_noCheck               OBJ_id_pkix_OCSP,5L
+
+#define SN_id_pkix_OCSP_archiveCutoff          "archiveCutoff"
+#define LN_id_pkix_OCSP_archiveCutoff          "OCSP Archive Cutoff"
+#define NID_id_pkix_OCSP_archiveCutoff         370
+#define OBJ_id_pkix_OCSP_archiveCutoff         OBJ_id_pkix_OCSP,6L
+
+#define SN_id_pkix_OCSP_serviceLocator         "serviceLocator"
+#define LN_id_pkix_OCSP_serviceLocator         "OCSP Service Locator"
+#define NID_id_pkix_OCSP_serviceLocator                371
+#define OBJ_id_pkix_OCSP_serviceLocator                OBJ_id_pkix_OCSP,7L
+
+#define SN_id_pkix_OCSP_extendedStatus         "extendedStatus"
+#define LN_id_pkix_OCSP_extendedStatus         "Extended OCSP Status"
+#define NID_id_pkix_OCSP_extendedStatus                372
+#define OBJ_id_pkix_OCSP_extendedStatus                OBJ_id_pkix_OCSP,8L
+
+#define SN_id_pkix_OCSP_valid          "valid"
+#define NID_id_pkix_OCSP_valid         373
+#define OBJ_id_pkix_OCSP_valid         OBJ_id_pkix_OCSP,9L
+
+#define SN_id_pkix_OCSP_path           "path"
+#define NID_id_pkix_OCSP_path          374
+#define OBJ_id_pkix_OCSP_path          OBJ_id_pkix_OCSP,10L
+
+#define SN_id_pkix_OCSP_trustRoot              "trustRoot"
+#define LN_id_pkix_OCSP_trustRoot              "Trust Root"
+#define NID_id_pkix_OCSP_trustRoot             375
+#define OBJ_id_pkix_OCSP_trustRoot             OBJ_id_pkix_OCSP,11L
+
+#define SN_algorithm           "algorithm"
+#define LN_algorithm           "algorithm"
+#define NID_algorithm          376
+#define OBJ_algorithm          1L,3L,14L,3L,2L
+
+#define SN_md5WithRSA          "RSA-NP-MD5"
+#define LN_md5WithRSA          "md5WithRSA"
+#define NID_md5WithRSA         104
+#define OBJ_md5WithRSA         OBJ_algorithm,3L
+
+#define SN_des_ecb             "DES-ECB"
+#define LN_des_ecb             "des-ecb"
+#define NID_des_ecb            29
+#define OBJ_des_ecb            OBJ_algorithm,6L
+
+#define SN_des_cbc             "DES-CBC"
+#define LN_des_cbc             "des-cbc"
+#define NID_des_cbc            31
+#define OBJ_des_cbc            OBJ_algorithm,7L
+
+#define SN_des_ofb64           "DES-OFB"
+#define LN_des_ofb64           "des-ofb"
+#define NID_des_ofb64          45
+#define OBJ_des_ofb64          OBJ_algorithm,8L
+
+#define SN_des_cfb64           "DES-CFB"
+#define LN_des_cfb64           "des-cfb"
+#define NID_des_cfb64          30
+#define OBJ_des_cfb64          OBJ_algorithm,9L
+
+#define SN_rsaSignature                "rsaSignature"
+#define NID_rsaSignature               377
+#define OBJ_rsaSignature               OBJ_algorithm,11L
+
+#define SN_dsa_2               "DSA-old"
+#define LN_dsa_2               "dsaEncryption-old"
+#define NID_dsa_2              67
+#define OBJ_dsa_2              OBJ_algorithm,12L
+
+#define SN_dsaWithSHA          "DSA-SHA"
+#define LN_dsaWithSHA          "dsaWithSHA"
+#define NID_dsaWithSHA         66
+#define OBJ_dsaWithSHA         OBJ_algorithm,13L
+
+#define SN_shaWithRSAEncryption                "RSA-SHA"
+#define LN_shaWithRSAEncryption                "shaWithRSAEncryption"
+#define NID_shaWithRSAEncryption               42
+#define OBJ_shaWithRSAEncryption               OBJ_algorithm,15L
+
+#define SN_des_ede_ecb         "DES-EDE"
+#define LN_des_ede_ecb         "des-ede"
+#define NID_des_ede_ecb                32
+#define OBJ_des_ede_ecb                OBJ_algorithm,17L
+
+#define SN_des_ede3_ecb                "DES-EDE3"
+#define LN_des_ede3_ecb                "des-ede3"
+#define NID_des_ede3_ecb               33
+
+#define SN_des_ede_cbc         "DES-EDE-CBC"
+#define LN_des_ede_cbc         "des-ede-cbc"
+#define NID_des_ede_cbc                43
+
+#define SN_des_ede_cfb64               "DES-EDE-CFB"
+#define LN_des_ede_cfb64               "des-ede-cfb"
+#define NID_des_ede_cfb64              60
+
+#define SN_des_ede3_cfb64              "DES-EDE3-CFB"
+#define LN_des_ede3_cfb64              "des-ede3-cfb"
+#define NID_des_ede3_cfb64             61
+
+#define SN_des_ede_ofb64               "DES-EDE-OFB"
+#define LN_des_ede_ofb64               "des-ede-ofb"
+#define NID_des_ede_ofb64              62
+
+#define SN_des_ede3_ofb64              "DES-EDE3-OFB"
+#define LN_des_ede3_ofb64              "des-ede3-ofb"
+#define NID_des_ede3_ofb64             63
+
+#define SN_desx_cbc            "DESX-CBC"
+#define LN_desx_cbc            "desx-cbc"
+#define NID_desx_cbc           80
+
+#define SN_sha         "SHA"
+#define LN_sha         "sha"
+#define NID_sha                41
+#define OBJ_sha                OBJ_algorithm,18L
+
+#define SN_sha1                "SHA1"
+#define LN_sha1                "sha1"
+#define NID_sha1               64
+#define OBJ_sha1               OBJ_algorithm,26L
+
+#define SN_dsaWithSHA1_2               "DSA-SHA1-old"
+#define LN_dsaWithSHA1_2               "dsaWithSHA1-old"
+#define NID_dsaWithSHA1_2              70
+#define OBJ_dsaWithSHA1_2              OBJ_algorithm,27L
+
+#define SN_sha1WithRSA         "RSA-SHA1-2"
+#define LN_sha1WithRSA         "sha1WithRSA"
+#define NID_sha1WithRSA                115
+#define OBJ_sha1WithRSA                OBJ_algorithm,29L
+
+#define SN_ripemd160           "RIPEMD160"
+#define LN_ripemd160           "ripemd160"
+#define NID_ripemd160          117
+#define OBJ_ripemd160          1L,3L,36L,3L,2L,1L
+
+#define SN_ripemd160WithRSA            "RSA-RIPEMD160"
+#define LN_ripemd160WithRSA            "ripemd160WithRSA"
+#define NID_ripemd160WithRSA           119
+#define OBJ_ripemd160WithRSA           1L,3L,36L,3L,3L,1L,2L
+
+#define SN_sxnet               "SXNetID"
+#define LN_sxnet               "Strong Extranet ID"
+#define NID_sxnet              143
+#define OBJ_sxnet              1L,3L,101L,1L,4L,1L
+
+#define SN_X500                "X500"
+#define LN_X500                "directory services (X.500)"
+#define NID_X500               11
+#define OBJ_X500               2L,5L
+
+#define SN_X509                "X509"
+#define NID_X509               12
+#define OBJ_X509               OBJ_X500,4L
+
+#define SN_commonName          "CN"
+#define LN_commonName          "commonName"
+#define NID_commonName         13
+#define OBJ_commonName         OBJ_X509,3L
+
+#define SN_surname             "SN"
+#define LN_surname             "surname"
+#define NID_surname            100
+#define OBJ_surname            OBJ_X509,4L
+
+#define LN_serialNumber                "serialNumber"
+#define NID_serialNumber               105
+#define OBJ_serialNumber               OBJ_X509,5L
+
+#define SN_countryName         "C"
+#define LN_countryName         "countryName"
+#define NID_countryName                14
+#define OBJ_countryName                OBJ_X509,6L
+
+#define SN_localityName                "L"
+#define LN_localityName                "localityName"
+#define NID_localityName               15
+#define OBJ_localityName               OBJ_X509,7L
+
+#define SN_stateOrProvinceName         "ST"
+#define LN_stateOrProvinceName         "stateOrProvinceName"
+#define NID_stateOrProvinceName                16
+#define OBJ_stateOrProvinceName                OBJ_X509,8L
+
+#define LN_streetAddress               "streetAddress"
+#define NID_streetAddress              660
+#define OBJ_streetAddress              OBJ_X509,9L
+
+#define SN_organizationName            "O"
+#define LN_organizationName            "organizationName"
+#define NID_organizationName           17
+#define OBJ_organizationName           OBJ_X509,10L
+
+#define SN_organizationalUnitName              "OU"
+#define LN_organizationalUnitName              "organizationalUnitName"
+#define NID_organizationalUnitName             18
+#define OBJ_organizationalUnitName             OBJ_X509,11L
+
+#define LN_title               "title"
+#define NID_title              106
+#define OBJ_title              OBJ_X509,12L
+
+#define LN_description         "description"
+#define NID_description                107
+#define OBJ_description                OBJ_X509,13L
+
+#define LN_postalCode          "postalCode"
+#define NID_postalCode         661
+#define OBJ_postalCode         OBJ_X509,17L
+
+#define SN_name                "name"
+#define LN_name                "name"
+#define NID_name               173
+#define OBJ_name               OBJ_X509,41L
+
+#define SN_givenName           "GN"
+#define LN_givenName           "givenName"
+#define NID_givenName          99
+#define OBJ_givenName          OBJ_X509,42L
+
+#define LN_initials            "initials"
+#define NID_initials           101
+#define OBJ_initials           OBJ_X509,43L
+
+#define LN_generationQualifier         "generationQualifier"
+#define NID_generationQualifier                509
+#define OBJ_generationQualifier                OBJ_X509,44L
+
+#define LN_x500UniqueIdentifier                "x500UniqueIdentifier"
+#define NID_x500UniqueIdentifier               503
+#define OBJ_x500UniqueIdentifier               OBJ_X509,45L
+
+#define SN_dnQualifier         "dnQualifier"
+#define LN_dnQualifier         "dnQualifier"
+#define NID_dnQualifier                174
+#define OBJ_dnQualifier                OBJ_X509,46L
+
+#define LN_pseudonym           "pseudonym"
+#define NID_pseudonym          510
+#define OBJ_pseudonym          OBJ_X509,65L
+
+#define SN_role                "role"
+#define LN_role                "role"
+#define NID_role               400
+#define OBJ_role               OBJ_X509,72L
+
+#define SN_X500algorithms              "X500algorithms"
+#define LN_X500algorithms              "directory services - algorithms"
+#define NID_X500algorithms             378
+#define OBJ_X500algorithms             OBJ_X500,8L
+
+#define SN_rsa         "RSA"
+#define LN_rsa         "rsa"
+#define NID_rsa                19
+#define OBJ_rsa                OBJ_X500algorithms,1L,1L
+
+#define SN_mdc2WithRSA         "RSA-MDC2"
+#define LN_mdc2WithRSA         "mdc2WithRSA"
+#define NID_mdc2WithRSA                96
+#define OBJ_mdc2WithRSA                OBJ_X500algorithms,3L,100L
+
+#define SN_mdc2                "MDC2"
+#define LN_mdc2                "mdc2"
+#define NID_mdc2               95
+#define OBJ_mdc2               OBJ_X500algorithms,3L,101L
+
+#define SN_id_ce               "id-ce"
+#define NID_id_ce              81
+#define OBJ_id_ce              OBJ_X500,29L
+
+#define SN_subject_key_identifier              "subjectKeyIdentifier"
+#define LN_subject_key_identifier              "X509v3 Subject Key Identifier"
+#define NID_subject_key_identifier             82
+#define OBJ_subject_key_identifier             OBJ_id_ce,14L
+
+#define SN_key_usage           "keyUsage"
+#define LN_key_usage           "X509v3 Key Usage"
+#define NID_key_usage          83
+#define OBJ_key_usage          OBJ_id_ce,15L
+
+#define SN_private_key_usage_period            "privateKeyUsagePeriod"
+#define LN_private_key_usage_period            "X509v3 Private Key Usage Period"
+#define NID_private_key_usage_period           84
+#define OBJ_private_key_usage_period           OBJ_id_ce,16L
+
+#define SN_subject_alt_name            "subjectAltName"
+#define LN_subject_alt_name            "X509v3 Subject Alternative Name"
+#define NID_subject_alt_name           85
+#define OBJ_subject_alt_name           OBJ_id_ce,17L
+
+#define SN_issuer_alt_name             "issuerAltName"
+#define LN_issuer_alt_name             "X509v3 Issuer Alternative Name"
+#define NID_issuer_alt_name            86
+#define OBJ_issuer_alt_name            OBJ_id_ce,18L
+
+#define SN_basic_constraints           "basicConstraints"
+#define LN_basic_constraints           "X509v3 Basic Constraints"
+#define NID_basic_constraints          87
+#define OBJ_basic_constraints          OBJ_id_ce,19L
+
+#define SN_crl_number          "crlNumber"
+#define LN_crl_number          "X509v3 CRL Number"
+#define NID_crl_number         88
+#define OBJ_crl_number         OBJ_id_ce,20L
+
+#define SN_crl_reason          "CRLReason"
+#define LN_crl_reason          "X509v3 CRL Reason Code"
+#define NID_crl_reason         141
+#define OBJ_crl_reason         OBJ_id_ce,21L
+
+#define SN_invalidity_date             "invalidityDate"
+#define LN_invalidity_date             "Invalidity Date"
+#define NID_invalidity_date            142
+#define OBJ_invalidity_date            OBJ_id_ce,24L
+
+#define SN_delta_crl           "deltaCRL"
+#define LN_delta_crl           "X509v3 Delta CRL Indicator"
+#define NID_delta_crl          140
+#define OBJ_delta_crl          OBJ_id_ce,27L
+
+#define SN_name_constraints            "nameConstraints"
+#define LN_name_constraints            "X509v3 Name Constraints"
+#define NID_name_constraints           666
+#define OBJ_name_constraints           OBJ_id_ce,30L
+
+#define SN_crl_distribution_points             "crlDistributionPoints"
+#define LN_crl_distribution_points             "X509v3 CRL Distribution Points"
+#define NID_crl_distribution_points            103
+#define OBJ_crl_distribution_points            OBJ_id_ce,31L
+
+#define SN_certificate_policies                "certificatePolicies"
+#define LN_certificate_policies                "X509v3 Certificate Policies"
+#define NID_certificate_policies               89
+#define OBJ_certificate_policies               OBJ_id_ce,32L
+
+#define SN_any_policy          "anyPolicy"
+#define LN_any_policy          "X509v3 Any Policy"
+#define NID_any_policy         746
+#define OBJ_any_policy         OBJ_certificate_policies,0L
+
+#define SN_policy_mappings             "policyMappings"
+#define LN_policy_mappings             "X509v3 Policy Mappings"
+#define NID_policy_mappings            747
+#define OBJ_policy_mappings            OBJ_id_ce,33L
+
+#define SN_authority_key_identifier            "authorityKeyIdentifier"
+#define LN_authority_key_identifier            "X509v3 Authority Key Identifier"
+#define NID_authority_key_identifier           90
+#define OBJ_authority_key_identifier           OBJ_id_ce,35L
+
+#define SN_policy_constraints          "policyConstraints"
+#define LN_policy_constraints          "X509v3 Policy Constraints"
+#define NID_policy_constraints         401
+#define OBJ_policy_constraints         OBJ_id_ce,36L
+
+#define SN_ext_key_usage               "extendedKeyUsage"
+#define LN_ext_key_usage               "X509v3 Extended Key Usage"
+#define NID_ext_key_usage              126
+#define OBJ_ext_key_usage              OBJ_id_ce,37L
+
+#define SN_inhibit_any_policy          "inhibitAnyPolicy"
+#define LN_inhibit_any_policy          "X509v3 Inhibit Any Policy"
+#define NID_inhibit_any_policy         748
+#define OBJ_inhibit_any_policy         OBJ_id_ce,54L
+
+#define SN_target_information          "targetInformation"
+#define LN_target_information          "X509v3 AC Targeting"
+#define NID_target_information         402
+#define OBJ_target_information         OBJ_id_ce,55L
+
+#define SN_no_rev_avail                "noRevAvail"
+#define LN_no_rev_avail                "X509v3 No Revocation Available"
+#define NID_no_rev_avail               403
+#define OBJ_no_rev_avail               OBJ_id_ce,56L
+
+#define SN_netscape            "Netscape"
+#define LN_netscape            "Netscape Communications Corp."
+#define NID_netscape           57
+#define OBJ_netscape           2L,16L,840L,1L,113730L
+
+#define SN_netscape_cert_extension             "nsCertExt"
+#define LN_netscape_cert_extension             "Netscape Certificate Extension"
+#define NID_netscape_cert_extension            58
+#define OBJ_netscape_cert_extension            OBJ_netscape,1L
+
+#define SN_netscape_data_type          "nsDataType"
+#define LN_netscape_data_type          "Netscape Data Type"
+#define NID_netscape_data_type         59
+#define OBJ_netscape_data_type         OBJ_netscape,2L
+
+#define SN_netscape_cert_type          "nsCertType"
+#define LN_netscape_cert_type          "Netscape Cert Type"
+#define NID_netscape_cert_type         71
+#define OBJ_netscape_cert_type         OBJ_netscape_cert_extension,1L
+
+#define SN_netscape_base_url           "nsBaseUrl"
+#define LN_netscape_base_url           "Netscape Base Url"
+#define NID_netscape_base_url          72
+#define OBJ_netscape_base_url          OBJ_netscape_cert_extension,2L
+
+#define SN_netscape_revocation_url             "nsRevocationUrl"
+#define LN_netscape_revocation_url             "Netscape Revocation Url"
+#define NID_netscape_revocation_url            73
+#define OBJ_netscape_revocation_url            OBJ_netscape_cert_extension,3L
+
+#define SN_netscape_ca_revocation_url          "nsCaRevocationUrl"
+#define LN_netscape_ca_revocation_url          "Netscape CA Revocation Url"
+#define NID_netscape_ca_revocation_url         74
+#define OBJ_netscape_ca_revocation_url         OBJ_netscape_cert_extension,4L
+
+#define SN_netscape_renewal_url                "nsRenewalUrl"
+#define LN_netscape_renewal_url                "Netscape Renewal Url"
+#define NID_netscape_renewal_url               75
+#define OBJ_netscape_renewal_url               OBJ_netscape_cert_extension,7L
+
+#define SN_netscape_ca_policy_url              "nsCaPolicyUrl"
+#define LN_netscape_ca_policy_url              "Netscape CA Policy Url"
+#define NID_netscape_ca_policy_url             76
+#define OBJ_netscape_ca_policy_url             OBJ_netscape_cert_extension,8L
+
+#define SN_netscape_ssl_server_name            "nsSslServerName"
+#define LN_netscape_ssl_server_name            "Netscape SSL Server Name"
+#define NID_netscape_ssl_server_name           77
+#define OBJ_netscape_ssl_server_name           OBJ_netscape_cert_extension,12L
+
+#define SN_netscape_comment            "nsComment"
+#define LN_netscape_comment            "Netscape Comment"
+#define NID_netscape_comment           78
+#define OBJ_netscape_comment           OBJ_netscape_cert_extension,13L
+
+#define SN_netscape_cert_sequence              "nsCertSequence"
+#define LN_netscape_cert_sequence              "Netscape Certificate Sequence"
+#define NID_netscape_cert_sequence             79
+#define OBJ_netscape_cert_sequence             OBJ_netscape_data_type,5L
+
+#define SN_ns_sgc              "nsSGC"
+#define LN_ns_sgc              "Netscape Server Gated Crypto"
+#define NID_ns_sgc             139
+#define OBJ_ns_sgc             OBJ_netscape,4L,1L
+
+#define SN_org         "ORG"
+#define LN_org         "org"
+#define NID_org                379
+#define OBJ_org                OBJ_iso,3L
+
+#define SN_dod         "DOD"
+#define LN_dod         "dod"
+#define NID_dod                380
+#define OBJ_dod                OBJ_org,6L
+
+#define SN_iana                "IANA"
+#define LN_iana                "iana"
+#define NID_iana               381
+#define OBJ_iana               OBJ_dod,1L
+
+#define OBJ_internet           OBJ_iana
+
+#define SN_Directory           "directory"
+#define LN_Directory           "Directory"
+#define NID_Directory          382
+#define OBJ_Directory          OBJ_internet,1L
+
+#define SN_Management          "mgmt"
+#define LN_Management          "Management"
+#define NID_Management         383
+#define OBJ_Management         OBJ_internet,2L
+
+#define SN_Experimental                "experimental"
+#define LN_Experimental                "Experimental"
+#define NID_Experimental               384
+#define OBJ_Experimental               OBJ_internet,3L
+
+#define SN_Private             "private"
+#define LN_Private             "Private"
+#define NID_Private            385
+#define OBJ_Private            OBJ_internet,4L
+
+#define SN_Security            "security"
+#define LN_Security            "Security"
+#define NID_Security           386
+#define OBJ_Security           OBJ_internet,5L
+
+#define SN_SNMPv2              "snmpv2"
+#define LN_SNMPv2              "SNMPv2"
+#define NID_SNMPv2             387
+#define OBJ_SNMPv2             OBJ_internet,6L
+
+#define LN_Mail                "Mail"
+#define NID_Mail               388
+#define OBJ_Mail               OBJ_internet,7L
+
+#define SN_Enterprises         "enterprises"
+#define LN_Enterprises         "Enterprises"
+#define NID_Enterprises                389
+#define OBJ_Enterprises                OBJ_Private,1L
+
+#define SN_dcObject            "dcobject"
+#define LN_dcObject            "dcObject"
+#define NID_dcObject           390
+#define OBJ_dcObject           OBJ_Enterprises,1466L,344L
+
+#define SN_mime_mhs            "mime-mhs"
+#define LN_mime_mhs            "MIME MHS"
+#define NID_mime_mhs           504
+#define OBJ_mime_mhs           OBJ_Mail,1L
+
+#define SN_mime_mhs_headings           "mime-mhs-headings"
+#define LN_mime_mhs_headings           "mime-mhs-headings"
+#define NID_mime_mhs_headings          505
+#define OBJ_mime_mhs_headings          OBJ_mime_mhs,1L
+
+#define SN_mime_mhs_bodies             "mime-mhs-bodies"
+#define LN_mime_mhs_bodies             "mime-mhs-bodies"
+#define NID_mime_mhs_bodies            506
+#define OBJ_mime_mhs_bodies            OBJ_mime_mhs,2L
+
+#define SN_id_hex_partial_message              "id-hex-partial-message"
+#define LN_id_hex_partial_message              "id-hex-partial-message"
+#define NID_id_hex_partial_message             507
+#define OBJ_id_hex_partial_message             OBJ_mime_mhs_headings,1L
+
+#define SN_id_hex_multipart_message            "id-hex-multipart-message"
+#define LN_id_hex_multipart_message            "id-hex-multipart-message"
+#define NID_id_hex_multipart_message           508
+#define OBJ_id_hex_multipart_message           OBJ_mime_mhs_headings,2L
+
+#define SN_rle_compression             "RLE"
+#define LN_rle_compression             "run length compression"
+#define NID_rle_compression            124
+#define OBJ_rle_compression            1L,1L,1L,1L,666L,1L
+
+#define SN_zlib_compression            "ZLIB"
+#define LN_zlib_compression            "zlib compression"
+#define NID_zlib_compression           125
+#define OBJ_zlib_compression           1L,1L,1L,1L,666L,2L
+
+#define OBJ_csor               2L,16L,840L,1L,101L,3L
+
+#define OBJ_nistAlgorithms             OBJ_csor,4L
+
+#define OBJ_aes                OBJ_nistAlgorithms,1L
+
+#define SN_aes_128_ecb         "AES-128-ECB"
+#define LN_aes_128_ecb         "aes-128-ecb"
+#define NID_aes_128_ecb                418
+#define OBJ_aes_128_ecb                OBJ_aes,1L
+
+#define SN_aes_128_cbc         "AES-128-CBC"
+#define LN_aes_128_cbc         "aes-128-cbc"
+#define NID_aes_128_cbc                419
+#define OBJ_aes_128_cbc                OBJ_aes,2L
+
+#define SN_aes_128_ofb128              "AES-128-OFB"
+#define LN_aes_128_ofb128              "aes-128-ofb"
+#define NID_aes_128_ofb128             420
+#define OBJ_aes_128_ofb128             OBJ_aes,3L
+
+#define SN_aes_128_cfb128              "AES-128-CFB"
+#define LN_aes_128_cfb128              "aes-128-cfb"
+#define NID_aes_128_cfb128             421
+#define OBJ_aes_128_cfb128             OBJ_aes,4L
+
+#define SN_aes_192_ecb         "AES-192-ECB"
+#define LN_aes_192_ecb         "aes-192-ecb"
+#define NID_aes_192_ecb                422
+#define OBJ_aes_192_ecb                OBJ_aes,21L
+
+#define SN_aes_192_cbc         "AES-192-CBC"
+#define LN_aes_192_cbc         "aes-192-cbc"
+#define NID_aes_192_cbc                423
+#define OBJ_aes_192_cbc                OBJ_aes,22L
+
+#define SN_aes_192_ofb128              "AES-192-OFB"
+#define LN_aes_192_ofb128              "aes-192-ofb"
+#define NID_aes_192_ofb128             424
+#define OBJ_aes_192_ofb128             OBJ_aes,23L
+
+#define SN_aes_192_cfb128              "AES-192-CFB"
+#define LN_aes_192_cfb128              "aes-192-cfb"
+#define NID_aes_192_cfb128             425
+#define OBJ_aes_192_cfb128             OBJ_aes,24L
+
+#define SN_aes_256_ecb         "AES-256-ECB"
+#define LN_aes_256_ecb         "aes-256-ecb"
+#define NID_aes_256_ecb                426
+#define OBJ_aes_256_ecb                OBJ_aes,41L
+
+#define SN_aes_256_cbc         "AES-256-CBC"
+#define LN_aes_256_cbc         "aes-256-cbc"
+#define NID_aes_256_cbc                427
+#define OBJ_aes_256_cbc                OBJ_aes,42L
+
+#define SN_aes_256_ofb128              "AES-256-OFB"
+#define LN_aes_256_ofb128              "aes-256-ofb"
+#define NID_aes_256_ofb128             428
+#define OBJ_aes_256_ofb128             OBJ_aes,43L
+
+#define SN_aes_256_cfb128              "AES-256-CFB"
+#define LN_aes_256_cfb128              "aes-256-cfb"
+#define NID_aes_256_cfb128             429
+#define OBJ_aes_256_cfb128             OBJ_aes,44L
+
+#define SN_aes_128_cfb1                "AES-128-CFB1"
+#define LN_aes_128_cfb1                "aes-128-cfb1"
+#define NID_aes_128_cfb1               650
+
+#define SN_aes_192_cfb1                "AES-192-CFB1"
+#define LN_aes_192_cfb1                "aes-192-cfb1"
+#define NID_aes_192_cfb1               651
+
+#define SN_aes_256_cfb1                "AES-256-CFB1"
+#define LN_aes_256_cfb1                "aes-256-cfb1"
+#define NID_aes_256_cfb1               652
+
+#define SN_aes_128_cfb8                "AES-128-CFB8"
+#define LN_aes_128_cfb8                "aes-128-cfb8"
+#define NID_aes_128_cfb8               653
+
+#define SN_aes_192_cfb8                "AES-192-CFB8"
+#define LN_aes_192_cfb8                "aes-192-cfb8"
+#define NID_aes_192_cfb8               654
+
+#define SN_aes_256_cfb8                "AES-256-CFB8"
+#define LN_aes_256_cfb8                "aes-256-cfb8"
+#define NID_aes_256_cfb8               655
+
+#define SN_des_cfb1            "DES-CFB1"
+#define LN_des_cfb1            "des-cfb1"
+#define NID_des_cfb1           656
+
+#define SN_des_cfb8            "DES-CFB8"
+#define LN_des_cfb8            "des-cfb8"
+#define NID_des_cfb8           657
+
+#define SN_des_ede3_cfb1               "DES-EDE3-CFB1"
+#define LN_des_ede3_cfb1               "des-ede3-cfb1"
+#define NID_des_ede3_cfb1              658
+
+#define SN_des_ede3_cfb8               "DES-EDE3-CFB8"
+#define LN_des_ede3_cfb8               "des-ede3-cfb8"
+#define NID_des_ede3_cfb8              659
+
+#define OBJ_nist_hashalgs              OBJ_nistAlgorithms,2L
+
+#define SN_sha256              "SHA256"
+#define LN_sha256              "sha256"
+#define NID_sha256             672
+#define OBJ_sha256             OBJ_nist_hashalgs,1L
+
+#define SN_sha384              "SHA384"
+#define LN_sha384              "sha384"
+#define NID_sha384             673
+#define OBJ_sha384             OBJ_nist_hashalgs,2L
+
+#define SN_sha512              "SHA512"
+#define LN_sha512              "sha512"
+#define NID_sha512             674
+#define OBJ_sha512             OBJ_nist_hashalgs,3L
+
+#define SN_sha224              "SHA224"
+#define LN_sha224              "sha224"
+#define NID_sha224             675
+#define OBJ_sha224             OBJ_nist_hashalgs,4L
+
+#define SN_hold_instruction_code               "holdInstructionCode"
+#define LN_hold_instruction_code               "Hold Instruction Code"
+#define NID_hold_instruction_code              430
+#define OBJ_hold_instruction_code              OBJ_id_ce,23L
+
+#define OBJ_holdInstruction            OBJ_X9_57,2L
+
+#define SN_hold_instruction_none               "holdInstructionNone"
+#define LN_hold_instruction_none               "Hold Instruction None"
+#define NID_hold_instruction_none              431
+#define OBJ_hold_instruction_none              OBJ_holdInstruction,1L
+
+#define SN_hold_instruction_call_issuer                "holdInstructionCallIssuer"
+#define LN_hold_instruction_call_issuer                "Hold Instruction Call Issuer"
+#define NID_hold_instruction_call_issuer               432
+#define OBJ_hold_instruction_call_issuer               OBJ_holdInstruction,2L
+
+#define SN_hold_instruction_reject             "holdInstructionReject"
+#define LN_hold_instruction_reject             "Hold Instruction Reject"
+#define NID_hold_instruction_reject            433
+#define OBJ_hold_instruction_reject            OBJ_holdInstruction,3L
+
+#define SN_data                "data"
+#define NID_data               434
+#define OBJ_data               OBJ_itu_t,9L
+
+#define SN_pss         "pss"
+#define NID_pss                435
+#define OBJ_pss                OBJ_data,2342L
+
+#define SN_ucl         "ucl"
+#define NID_ucl                436
+#define OBJ_ucl                OBJ_pss,19200300L
+
+#define SN_pilot               "pilot"
+#define NID_pilot              437
+#define OBJ_pilot              OBJ_ucl,100L
+
+#define LN_pilotAttributeType          "pilotAttributeType"
+#define NID_pilotAttributeType         438
+#define OBJ_pilotAttributeType         OBJ_pilot,1L
+
+#define LN_pilotAttributeSyntax                "pilotAttributeSyntax"
+#define NID_pilotAttributeSyntax               439
+#define OBJ_pilotAttributeSyntax               OBJ_pilot,3L
+
+#define LN_pilotObjectClass            "pilotObjectClass"
+#define NID_pilotObjectClass           440
+#define OBJ_pilotObjectClass           OBJ_pilot,4L
+
+#define LN_pilotGroups         "pilotGroups"
+#define NID_pilotGroups                441
+#define OBJ_pilotGroups                OBJ_pilot,10L
+
+#define LN_iA5StringSyntax             "iA5StringSyntax"
+#define NID_iA5StringSyntax            442
+#define OBJ_iA5StringSyntax            OBJ_pilotAttributeSyntax,4L
+
+#define LN_caseIgnoreIA5StringSyntax           "caseIgnoreIA5StringSyntax"
+#define NID_caseIgnoreIA5StringSyntax          443
+#define OBJ_caseIgnoreIA5StringSyntax          OBJ_pilotAttributeSyntax,5L
+
+#define LN_pilotObject         "pilotObject"
+#define NID_pilotObject                444
+#define OBJ_pilotObject                OBJ_pilotObjectClass,3L
+
+#define LN_pilotPerson         "pilotPerson"
+#define NID_pilotPerson                445
+#define OBJ_pilotPerson                OBJ_pilotObjectClass,4L
+
+#define SN_account             "account"
+#define NID_account            446
+#define OBJ_account            OBJ_pilotObjectClass,5L
+
+#define SN_document            "document"
+#define NID_document           447
+#define OBJ_document           OBJ_pilotObjectClass,6L
+
+#define SN_room                "room"
+#define NID_room               448
+#define OBJ_room               OBJ_pilotObjectClass,7L
+
+#define LN_documentSeries              "documentSeries"
+#define NID_documentSeries             449
+#define OBJ_documentSeries             OBJ_pilotObjectClass,9L
+
+#define SN_Domain              "domain"
+#define LN_Domain              "Domain"
+#define NID_Domain             392
+#define OBJ_Domain             OBJ_pilotObjectClass,13L
+
+#define LN_rFC822localPart             "rFC822localPart"
+#define NID_rFC822localPart            450
+#define OBJ_rFC822localPart            OBJ_pilotObjectClass,14L
+
+#define LN_dNSDomain           "dNSDomain"
+#define NID_dNSDomain          451
+#define OBJ_dNSDomain          OBJ_pilotObjectClass,15L
+
+#define LN_domainRelatedObject         "domainRelatedObject"
+#define NID_domainRelatedObject                452
+#define OBJ_domainRelatedObject                OBJ_pilotObjectClass,17L
+
+#define LN_friendlyCountry             "friendlyCountry"
+#define NID_friendlyCountry            453
+#define OBJ_friendlyCountry            OBJ_pilotObjectClass,18L
+
+#define LN_simpleSecurityObject                "simpleSecurityObject"
+#define NID_simpleSecurityObject               454
+#define OBJ_simpleSecurityObject               OBJ_pilotObjectClass,19L
+
+#define LN_pilotOrganization           "pilotOrganization"
+#define NID_pilotOrganization          455
+#define OBJ_pilotOrganization          OBJ_pilotObjectClass,20L
+
+#define LN_pilotDSA            "pilotDSA"
+#define NID_pilotDSA           456
+#define OBJ_pilotDSA           OBJ_pilotObjectClass,21L
+
+#define LN_qualityLabelledData         "qualityLabelledData"
+#define NID_qualityLabelledData                457
+#define OBJ_qualityLabelledData                OBJ_pilotObjectClass,22L
+
+#define SN_userId              "UID"
+#define LN_userId              "userId"
+#define NID_userId             458
+#define OBJ_userId             OBJ_pilotAttributeType,1L
+
+#define LN_textEncodedORAddress                "textEncodedORAddress"
+#define NID_textEncodedORAddress               459
+#define OBJ_textEncodedORAddress               OBJ_pilotAttributeType,2L
+
+#define SN_rfc822Mailbox               "mail"
+#define LN_rfc822Mailbox               "rfc822Mailbox"
+#define NID_rfc822Mailbox              460
+#define OBJ_rfc822Mailbox              OBJ_pilotAttributeType,3L
+
+#define SN_info                "info"
+#define NID_info               461
+#define OBJ_info               OBJ_pilotAttributeType,4L
+
+#define LN_favouriteDrink              "favouriteDrink"
+#define NID_favouriteDrink             462
+#define OBJ_favouriteDrink             OBJ_pilotAttributeType,5L
+
+#define LN_roomNumber          "roomNumber"
+#define NID_roomNumber         463
+#define OBJ_roomNumber         OBJ_pilotAttributeType,6L
+
+#define SN_photo               "photo"
+#define NID_photo              464
+#define OBJ_photo              OBJ_pilotAttributeType,7L
+
+#define LN_userClass           "userClass"
+#define NID_userClass          465
+#define OBJ_userClass          OBJ_pilotAttributeType,8L
+
+#define SN_host                "host"
+#define NID_host               466
+#define OBJ_host               OBJ_pilotAttributeType,9L
+
+#define SN_manager             "manager"
+#define NID_manager            467
+#define OBJ_manager            OBJ_pilotAttributeType,10L
+
+#define LN_documentIdentifier          "documentIdentifier"
+#define NID_documentIdentifier         468
+#define OBJ_documentIdentifier         OBJ_pilotAttributeType,11L
+
+#define LN_documentTitle               "documentTitle"
+#define NID_documentTitle              469
+#define OBJ_documentTitle              OBJ_pilotAttributeType,12L
+
+#define LN_documentVersion             "documentVersion"
+#define NID_documentVersion            470
+#define OBJ_documentVersion            OBJ_pilotAttributeType,13L
+
+#define LN_documentAuthor              "documentAuthor"
+#define NID_documentAuthor             471
+#define OBJ_documentAuthor             OBJ_pilotAttributeType,14L
+
+#define LN_documentLocation            "documentLocation"
+#define NID_documentLocation           472
+#define OBJ_documentLocation           OBJ_pilotAttributeType,15L
+
+#define LN_homeTelephoneNumber         "homeTelephoneNumber"
+#define NID_homeTelephoneNumber                473
+#define OBJ_homeTelephoneNumber                OBJ_pilotAttributeType,20L
+
+#define SN_secretary           "secretary"
+#define NID_secretary          474
+#define OBJ_secretary          OBJ_pilotAttributeType,21L
+
+#define LN_otherMailbox                "otherMailbox"
+#define NID_otherMailbox               475
+#define OBJ_otherMailbox               OBJ_pilotAttributeType,22L
+
+#define LN_lastModifiedTime            "lastModifiedTime"
+#define NID_lastModifiedTime           476
+#define OBJ_lastModifiedTime           OBJ_pilotAttributeType,23L
+
+#define LN_lastModifiedBy              "lastModifiedBy"
+#define NID_lastModifiedBy             477
+#define OBJ_lastModifiedBy             OBJ_pilotAttributeType,24L
+
+#define SN_domainComponent             "DC"
+#define LN_domainComponent             "domainComponent"
+#define NID_domainComponent            391
+#define OBJ_domainComponent            OBJ_pilotAttributeType,25L
+
+#define LN_aRecord             "aRecord"
+#define NID_aRecord            478
+#define OBJ_aRecord            OBJ_pilotAttributeType,26L
+
+#define LN_pilotAttributeType27                "pilotAttributeType27"
+#define NID_pilotAttributeType27               479
+#define OBJ_pilotAttributeType27               OBJ_pilotAttributeType,27L
+
+#define LN_mXRecord            "mXRecord"
+#define NID_mXRecord           480
+#define OBJ_mXRecord           OBJ_pilotAttributeType,28L
+
+#define LN_nSRecord            "nSRecord"
+#define NID_nSRecord           481
+#define OBJ_nSRecord           OBJ_pilotAttributeType,29L
+
+#define LN_sOARecord           "sOARecord"
+#define NID_sOARecord          482
+#define OBJ_sOARecord          OBJ_pilotAttributeType,30L
+
+#define LN_cNAMERecord         "cNAMERecord"
+#define NID_cNAMERecord                483
+#define OBJ_cNAMERecord                OBJ_pilotAttributeType,31L
+
+#define LN_associatedDomain            "associatedDomain"
+#define NID_associatedDomain           484
+#define OBJ_associatedDomain           OBJ_pilotAttributeType,37L
+
+#define LN_associatedName              "associatedName"
+#define NID_associatedName             485
+#define OBJ_associatedName             OBJ_pilotAttributeType,38L
+
+#define LN_homePostalAddress           "homePostalAddress"
+#define NID_homePostalAddress          486
+#define OBJ_homePostalAddress          OBJ_pilotAttributeType,39L
+
+#define LN_personalTitle               "personalTitle"
+#define NID_personalTitle              487
+#define OBJ_personalTitle              OBJ_pilotAttributeType,40L
+
+#define LN_mobileTelephoneNumber               "mobileTelephoneNumber"
+#define NID_mobileTelephoneNumber              488
+#define OBJ_mobileTelephoneNumber              OBJ_pilotAttributeType,41L
+
+#define LN_pagerTelephoneNumber                "pagerTelephoneNumber"
+#define NID_pagerTelephoneNumber               489
+#define OBJ_pagerTelephoneNumber               OBJ_pilotAttributeType,42L
+
+#define LN_friendlyCountryName         "friendlyCountryName"
+#define NID_friendlyCountryName                490
+#define OBJ_friendlyCountryName                OBJ_pilotAttributeType,43L
+
+#define LN_organizationalStatus                "organizationalStatus"
+#define NID_organizationalStatus               491
+#define OBJ_organizationalStatus               OBJ_pilotAttributeType,45L
+
+#define LN_janetMailbox                "janetMailbox"
+#define NID_janetMailbox               492
+#define OBJ_janetMailbox               OBJ_pilotAttributeType,46L
+
+#define LN_mailPreferenceOption                "mailPreferenceOption"
+#define NID_mailPreferenceOption               493
+#define OBJ_mailPreferenceOption               OBJ_pilotAttributeType,47L
+
+#define LN_buildingName                "buildingName"
+#define NID_buildingName               494
+#define OBJ_buildingName               OBJ_pilotAttributeType,48L
+
+#define LN_dSAQuality          "dSAQuality"
+#define NID_dSAQuality         495
+#define OBJ_dSAQuality         OBJ_pilotAttributeType,49L
+
+#define LN_singleLevelQuality          "singleLevelQuality"
+#define NID_singleLevelQuality         496
+#define OBJ_singleLevelQuality         OBJ_pilotAttributeType,50L
+
+#define LN_subtreeMinimumQuality               "subtreeMinimumQuality"
+#define NID_subtreeMinimumQuality              497
+#define OBJ_subtreeMinimumQuality              OBJ_pilotAttributeType,51L
+
+#define LN_subtreeMaximumQuality               "subtreeMaximumQuality"
+#define NID_subtreeMaximumQuality              498
+#define OBJ_subtreeMaximumQuality              OBJ_pilotAttributeType,52L
+
+#define LN_personalSignature           "personalSignature"
+#define NID_personalSignature          499
+#define OBJ_personalSignature          OBJ_pilotAttributeType,53L
+
+#define LN_dITRedirect         "dITRedirect"
+#define NID_dITRedirect                500
+#define OBJ_dITRedirect                OBJ_pilotAttributeType,54L
+
+#define SN_audio               "audio"
+#define NID_audio              501
+#define OBJ_audio              OBJ_pilotAttributeType,55L
+
+#define LN_documentPublisher           "documentPublisher"
+#define NID_documentPublisher          502
+#define OBJ_documentPublisher          OBJ_pilotAttributeType,56L
+
+#define SN_id_set              "id-set"
+#define LN_id_set              "Secure Electronic Transactions"
+#define NID_id_set             512
+#define OBJ_id_set             OBJ_international_organizations,42L
+
+#define SN_set_ctype           "set-ctype"
+#define LN_set_ctype           "content types"
+#define NID_set_ctype          513
+#define OBJ_set_ctype          OBJ_id_set,0L
+
+#define SN_set_msgExt          "set-msgExt"
+#define LN_set_msgExt          "message extensions"
+#define NID_set_msgExt         514
+#define OBJ_set_msgExt         OBJ_id_set,1L
+
+#define SN_set_attr            "set-attr"
+#define NID_set_attr           515
+#define OBJ_set_attr           OBJ_id_set,3L
+
+#define SN_set_policy          "set-policy"
+#define NID_set_policy         516
+#define OBJ_set_policy         OBJ_id_set,5L
+
+#define SN_set_certExt         "set-certExt"
+#define LN_set_certExt         "certificate extensions"
+#define NID_set_certExt                517
+#define OBJ_set_certExt                OBJ_id_set,7L
+
+#define SN_set_brand           "set-brand"
+#define NID_set_brand          518
+#define OBJ_set_brand          OBJ_id_set,8L
+
+#define SN_setct_PANData               "setct-PANData"
+#define NID_setct_PANData              519
+#define OBJ_setct_PANData              OBJ_set_ctype,0L
+
+#define SN_setct_PANToken              "setct-PANToken"
+#define NID_setct_PANToken             520
+#define OBJ_setct_PANToken             OBJ_set_ctype,1L
+
+#define SN_setct_PANOnly               "setct-PANOnly"
+#define NID_setct_PANOnly              521
+#define OBJ_setct_PANOnly              OBJ_set_ctype,2L
+
+#define SN_setct_OIData                "setct-OIData"
+#define NID_setct_OIData               522
+#define OBJ_setct_OIData               OBJ_set_ctype,3L
+
+#define SN_setct_PI            "setct-PI"
+#define NID_setct_PI           523
+#define OBJ_setct_PI           OBJ_set_ctype,4L
+
+#define SN_setct_PIData                "setct-PIData"
+#define NID_setct_PIData               524
+#define OBJ_setct_PIData               OBJ_set_ctype,5L
+
+#define SN_setct_PIDataUnsigned                "setct-PIDataUnsigned"
+#define NID_setct_PIDataUnsigned               525
+#define OBJ_setct_PIDataUnsigned               OBJ_set_ctype,6L
+
+#define SN_setct_HODInput              "setct-HODInput"
+#define NID_setct_HODInput             526
+#define OBJ_setct_HODInput             OBJ_set_ctype,7L
+
+#define SN_setct_AuthResBaggage                "setct-AuthResBaggage"
+#define NID_setct_AuthResBaggage               527
+#define OBJ_setct_AuthResBaggage               OBJ_set_ctype,8L
+
+#define SN_setct_AuthRevReqBaggage             "setct-AuthRevReqBaggage"
+#define NID_setct_AuthRevReqBaggage            528
+#define OBJ_setct_AuthRevReqBaggage            OBJ_set_ctype,9L
+
+#define SN_setct_AuthRevResBaggage             "setct-AuthRevResBaggage"
+#define NID_setct_AuthRevResBaggage            529
+#define OBJ_setct_AuthRevResBaggage            OBJ_set_ctype,10L
+
+#define SN_setct_CapTokenSeq           "setct-CapTokenSeq"
+#define NID_setct_CapTokenSeq          530
+#define OBJ_setct_CapTokenSeq          OBJ_set_ctype,11L
+
+#define SN_setct_PInitResData          "setct-PInitResData"
+#define NID_setct_PInitResData         531
+#define OBJ_setct_PInitResData         OBJ_set_ctype,12L
+
+#define SN_setct_PI_TBS                "setct-PI-TBS"
+#define NID_setct_PI_TBS               532
+#define OBJ_setct_PI_TBS               OBJ_set_ctype,13L
+
+#define SN_setct_PResData              "setct-PResData"
+#define NID_setct_PResData             533
+#define OBJ_setct_PResData             OBJ_set_ctype,14L
+
+#define SN_setct_AuthReqTBS            "setct-AuthReqTBS"
+#define NID_setct_AuthReqTBS           534
+#define OBJ_setct_AuthReqTBS           OBJ_set_ctype,16L
+
+#define SN_setct_AuthResTBS            "setct-AuthResTBS"
+#define NID_setct_AuthResTBS           535
+#define OBJ_setct_AuthResTBS           OBJ_set_ctype,17L
+
+#define SN_setct_AuthResTBSX           "setct-AuthResTBSX"
+#define NID_setct_AuthResTBSX          536
+#define OBJ_setct_AuthResTBSX          OBJ_set_ctype,18L
+
+#define SN_setct_AuthTokenTBS          "setct-AuthTokenTBS"
+#define NID_setct_AuthTokenTBS         537
+#define OBJ_setct_AuthTokenTBS         OBJ_set_ctype,19L
+
+#define SN_setct_CapTokenData          "setct-CapTokenData"
+#define NID_setct_CapTokenData         538
+#define OBJ_setct_CapTokenData         OBJ_set_ctype,20L
+
+#define SN_setct_CapTokenTBS           "setct-CapTokenTBS"
+#define NID_setct_CapTokenTBS          539
+#define OBJ_setct_CapTokenTBS          OBJ_set_ctype,21L
+
+#define SN_setct_AcqCardCodeMsg                "setct-AcqCardCodeMsg"
+#define NID_setct_AcqCardCodeMsg               540
+#define OBJ_setct_AcqCardCodeMsg               OBJ_set_ctype,22L
+
+#define SN_setct_AuthRevReqTBS         "setct-AuthRevReqTBS"
+#define NID_setct_AuthRevReqTBS                541
+#define OBJ_setct_AuthRevReqTBS                OBJ_set_ctype,23L
+
+#define SN_setct_AuthRevResData                "setct-AuthRevResData"
+#define NID_setct_AuthRevResData               542
+#define OBJ_setct_AuthRevResData               OBJ_set_ctype,24L
+
+#define SN_setct_AuthRevResTBS         "setct-AuthRevResTBS"
+#define NID_setct_AuthRevResTBS                543
+#define OBJ_setct_AuthRevResTBS                OBJ_set_ctype,25L
+
+#define SN_setct_CapReqTBS             "setct-CapReqTBS"
+#define NID_setct_CapReqTBS            544
+#define OBJ_setct_CapReqTBS            OBJ_set_ctype,26L
+
+#define SN_setct_CapReqTBSX            "setct-CapReqTBSX"
+#define NID_setct_CapReqTBSX           545
+#define OBJ_setct_CapReqTBSX           OBJ_set_ctype,27L
+
+#define SN_setct_CapResData            "setct-CapResData"
+#define NID_setct_CapResData           546
+#define OBJ_setct_CapResData           OBJ_set_ctype,28L
+
+#define SN_setct_CapRevReqTBS          "setct-CapRevReqTBS"
+#define NID_setct_CapRevReqTBS         547
+#define OBJ_setct_CapRevReqTBS         OBJ_set_ctype,29L
+
+#define SN_setct_CapRevReqTBSX         "setct-CapRevReqTBSX"
+#define NID_setct_CapRevReqTBSX                548
+#define OBJ_setct_CapRevReqTBSX                OBJ_set_ctype,30L
+
+#define SN_setct_CapRevResData         "setct-CapRevResData"
+#define NID_setct_CapRevResData                549
+#define OBJ_setct_CapRevResData                OBJ_set_ctype,31L
+
+#define SN_setct_CredReqTBS            "setct-CredReqTBS"
+#define NID_setct_CredReqTBS           550
+#define OBJ_setct_CredReqTBS           OBJ_set_ctype,32L
+
+#define SN_setct_CredReqTBSX           "setct-CredReqTBSX"
+#define NID_setct_CredReqTBSX          551
+#define OBJ_setct_CredReqTBSX          OBJ_set_ctype,33L
+
+#define SN_setct_CredResData           "setct-CredResData"
+#define NID_setct_CredResData          552
+#define OBJ_setct_CredResData          OBJ_set_ctype,34L
+
+#define SN_setct_CredRevReqTBS         "setct-CredRevReqTBS"
+#define NID_setct_CredRevReqTBS                553
+#define OBJ_setct_CredRevReqTBS                OBJ_set_ctype,35L
+
+#define SN_setct_CredRevReqTBSX                "setct-CredRevReqTBSX"
+#define NID_setct_CredRevReqTBSX               554
+#define OBJ_setct_CredRevReqTBSX               OBJ_set_ctype,36L
+
+#define SN_setct_CredRevResData                "setct-CredRevResData"
+#define NID_setct_CredRevResData               555
+#define OBJ_setct_CredRevResData               OBJ_set_ctype,37L
+
+#define SN_setct_PCertReqData          "setct-PCertReqData"
+#define NID_setct_PCertReqData         556
+#define OBJ_setct_PCertReqData         OBJ_set_ctype,38L
+
+#define SN_setct_PCertResTBS           "setct-PCertResTBS"
+#define NID_setct_PCertResTBS          557
+#define OBJ_setct_PCertResTBS          OBJ_set_ctype,39L
+
+#define SN_setct_BatchAdminReqData             "setct-BatchAdminReqData"
+#define NID_setct_BatchAdminReqData            558
+#define OBJ_setct_BatchAdminReqData            OBJ_set_ctype,40L
+
+#define SN_setct_BatchAdminResData             "setct-BatchAdminResData"
+#define NID_setct_BatchAdminResData            559
+#define OBJ_setct_BatchAdminResData            OBJ_set_ctype,41L
+
+#define SN_setct_CardCInitResTBS               "setct-CardCInitResTBS"
+#define NID_setct_CardCInitResTBS              560
+#define OBJ_setct_CardCInitResTBS              OBJ_set_ctype,42L
+
+#define SN_setct_MeAqCInitResTBS               "setct-MeAqCInitResTBS"
+#define NID_setct_MeAqCInitResTBS              561
+#define OBJ_setct_MeAqCInitResTBS              OBJ_set_ctype,43L
+
+#define SN_setct_RegFormResTBS         "setct-RegFormResTBS"
+#define NID_setct_RegFormResTBS                562
+#define OBJ_setct_RegFormResTBS                OBJ_set_ctype,44L
+
+#define SN_setct_CertReqData           "setct-CertReqData"
+#define NID_setct_CertReqData          563
+#define OBJ_setct_CertReqData          OBJ_set_ctype,45L
+
+#define SN_setct_CertReqTBS            "setct-CertReqTBS"
+#define NID_setct_CertReqTBS           564
+#define OBJ_setct_CertReqTBS           OBJ_set_ctype,46L
+
+#define SN_setct_CertResData           "setct-CertResData"
+#define NID_setct_CertResData          565
+#define OBJ_setct_CertResData          OBJ_set_ctype,47L
+
+#define SN_setct_CertInqReqTBS         "setct-CertInqReqTBS"
+#define NID_setct_CertInqReqTBS                566
+#define OBJ_setct_CertInqReqTBS                OBJ_set_ctype,48L
+
+#define SN_setct_ErrorTBS              "setct-ErrorTBS"
+#define NID_setct_ErrorTBS             567
+#define OBJ_setct_ErrorTBS             OBJ_set_ctype,49L
+
+#define SN_setct_PIDualSignedTBE               "setct-PIDualSignedTBE"
+#define NID_setct_PIDualSignedTBE              568
+#define OBJ_setct_PIDualSignedTBE              OBJ_set_ctype,50L
+
+#define SN_setct_PIUnsignedTBE         "setct-PIUnsignedTBE"
+#define NID_setct_PIUnsignedTBE                569
+#define OBJ_setct_PIUnsignedTBE                OBJ_set_ctype,51L
+
+#define SN_setct_AuthReqTBE            "setct-AuthReqTBE"
+#define NID_setct_AuthReqTBE           570
+#define OBJ_setct_AuthReqTBE           OBJ_set_ctype,52L
+
+#define SN_setct_AuthResTBE            "setct-AuthResTBE"
+#define NID_setct_AuthResTBE           571
+#define OBJ_setct_AuthResTBE           OBJ_set_ctype,53L
+
+#define SN_setct_AuthResTBEX           "setct-AuthResTBEX"
+#define NID_setct_AuthResTBEX          572
+#define OBJ_setct_AuthResTBEX          OBJ_set_ctype,54L
+
+#define SN_setct_AuthTokenTBE          "setct-AuthTokenTBE"
+#define NID_setct_AuthTokenTBE         573
+#define OBJ_setct_AuthTokenTBE         OBJ_set_ctype,55L
+
+#define SN_setct_CapTokenTBE           "setct-CapTokenTBE"
+#define NID_setct_CapTokenTBE          574
+#define OBJ_setct_CapTokenTBE          OBJ_set_ctype,56L
+
+#define SN_setct_CapTokenTBEX          "setct-CapTokenTBEX"
+#define NID_setct_CapTokenTBEX         575
+#define OBJ_setct_CapTokenTBEX         OBJ_set_ctype,57L
+
+#define SN_setct_AcqCardCodeMsgTBE             "setct-AcqCardCodeMsgTBE"
+#define NID_setct_AcqCardCodeMsgTBE            576
+#define OBJ_setct_AcqCardCodeMsgTBE            OBJ_set_ctype,58L
+
+#define SN_setct_AuthRevReqTBE         "setct-AuthRevReqTBE"
+#define NID_setct_AuthRevReqTBE                577
+#define OBJ_setct_AuthRevReqTBE                OBJ_set_ctype,59L
+
+#define SN_setct_AuthRevResTBE         "setct-AuthRevResTBE"
+#define NID_setct_AuthRevResTBE                578
+#define OBJ_setct_AuthRevResTBE                OBJ_set_ctype,60L
+
+#define SN_setct_AuthRevResTBEB                "setct-AuthRevResTBEB"
+#define NID_setct_AuthRevResTBEB               579
+#define OBJ_setct_AuthRevResTBEB               OBJ_set_ctype,61L
+
+#define SN_setct_CapReqTBE             "setct-CapReqTBE"
+#define NID_setct_CapReqTBE            580
+#define OBJ_setct_CapReqTBE            OBJ_set_ctype,62L
+
+#define SN_setct_CapReqTBEX            "setct-CapReqTBEX"
+#define NID_setct_CapReqTBEX           581
+#define OBJ_setct_CapReqTBEX           OBJ_set_ctype,63L
+
+#define SN_setct_CapResTBE             "setct-CapResTBE"
+#define NID_setct_CapResTBE            582
+#define OBJ_setct_CapResTBE            OBJ_set_ctype,64L
+
+#define SN_setct_CapRevReqTBE          "setct-CapRevReqTBE"
+#define NID_setct_CapRevReqTBE         583
+#define OBJ_setct_CapRevReqTBE         OBJ_set_ctype,65L
+
+#define SN_setct_CapRevReqTBEX         "setct-CapRevReqTBEX"
+#define NID_setct_CapRevReqTBEX                584
+#define OBJ_setct_CapRevReqTBEX                OBJ_set_ctype,66L
+
+#define SN_setct_CapRevResTBE          "setct-CapRevResTBE"
+#define NID_setct_CapRevResTBE         585
+#define OBJ_setct_CapRevResTBE         OBJ_set_ctype,67L
+
+#define SN_setct_CredReqTBE            "setct-CredReqTBE"
+#define NID_setct_CredReqTBE           586
+#define OBJ_setct_CredReqTBE           OBJ_set_ctype,68L
+
+#define SN_setct_CredReqTBEX           "setct-CredReqTBEX"
+#define NID_setct_CredReqTBEX          587
+#define OBJ_setct_CredReqTBEX          OBJ_set_ctype,69L
+
+#define SN_setct_CredResTBE            "setct-CredResTBE"
+#define NID_setct_CredResTBE           588
+#define OBJ_setct_CredResTBE           OBJ_set_ctype,70L
+
+#define SN_setct_CredRevReqTBE         "setct-CredRevReqTBE"
+#define NID_setct_CredRevReqTBE                589
+#define OBJ_setct_CredRevReqTBE                OBJ_set_ctype,71L
+
+#define SN_setct_CredRevReqTBEX                "setct-CredRevReqTBEX"
+#define NID_setct_CredRevReqTBEX               590
+#define OBJ_setct_CredRevReqTBEX               OBJ_set_ctype,72L
+
+#define SN_setct_CredRevResTBE         "setct-CredRevResTBE"
+#define NID_setct_CredRevResTBE                591
+#define OBJ_setct_CredRevResTBE                OBJ_set_ctype,73L
+
+#define SN_setct_BatchAdminReqTBE              "setct-BatchAdminReqTBE"
+#define NID_setct_BatchAdminReqTBE             592
+#define OBJ_setct_BatchAdminReqTBE             OBJ_set_ctype,74L
+
+#define SN_setct_BatchAdminResTBE              "setct-BatchAdminResTBE"
+#define NID_setct_BatchAdminResTBE             593
+#define OBJ_setct_BatchAdminResTBE             OBJ_set_ctype,75L
+
+#define SN_setct_RegFormReqTBE         "setct-RegFormReqTBE"
+#define NID_setct_RegFormReqTBE                594
+#define OBJ_setct_RegFormReqTBE                OBJ_set_ctype,76L
+
+#define SN_setct_CertReqTBE            "setct-CertReqTBE"
+#define NID_setct_CertReqTBE           595
+#define OBJ_setct_CertReqTBE           OBJ_set_ctype,77L
+
+#define SN_setct_CertReqTBEX           "setct-CertReqTBEX"
+#define NID_setct_CertReqTBEX          596
+#define OBJ_setct_CertReqTBEX          OBJ_set_ctype,78L
+
+#define SN_setct_CertResTBE            "setct-CertResTBE"
+#define NID_setct_CertResTBE           597
+#define OBJ_setct_CertResTBE           OBJ_set_ctype,79L
+
+#define SN_setct_CRLNotificationTBS            "setct-CRLNotificationTBS"
+#define NID_setct_CRLNotificationTBS           598
+#define OBJ_setct_CRLNotificationTBS           OBJ_set_ctype,80L
+
+#define SN_setct_CRLNotificationResTBS         "setct-CRLNotificationResTBS"
+#define NID_setct_CRLNotificationResTBS                599
+#define OBJ_setct_CRLNotificationResTBS                OBJ_set_ctype,81L
+
+#define SN_setct_BCIDistributionTBS            "setct-BCIDistributionTBS"
+#define NID_setct_BCIDistributionTBS           600
+#define OBJ_setct_BCIDistributionTBS           OBJ_set_ctype,82L
+
+#define SN_setext_genCrypt             "setext-genCrypt"
+#define LN_setext_genCrypt             "generic cryptogram"
+#define NID_setext_genCrypt            601
+#define OBJ_setext_genCrypt            OBJ_set_msgExt,1L
+
+#define SN_setext_miAuth               "setext-miAuth"
+#define LN_setext_miAuth               "merchant initiated auth"
+#define NID_setext_miAuth              602
+#define OBJ_setext_miAuth              OBJ_set_msgExt,3L
+
+#define SN_setext_pinSecure            "setext-pinSecure"
+#define NID_setext_pinSecure           603
+#define OBJ_setext_pinSecure           OBJ_set_msgExt,4L
+
+#define SN_setext_pinAny               "setext-pinAny"
+#define NID_setext_pinAny              604
+#define OBJ_setext_pinAny              OBJ_set_msgExt,5L
+
+#define SN_setext_track2               "setext-track2"
+#define NID_setext_track2              605
+#define OBJ_setext_track2              OBJ_set_msgExt,7L
+
+#define SN_setext_cv           "setext-cv"
+#define LN_setext_cv           "additional verification"
+#define NID_setext_cv          606
+#define OBJ_setext_cv          OBJ_set_msgExt,8L
+
+#define SN_set_policy_root             "set-policy-root"
+#define NID_set_policy_root            607
+#define OBJ_set_policy_root            OBJ_set_policy,0L
+
+#define SN_setCext_hashedRoot          "setCext-hashedRoot"
+#define NID_setCext_hashedRoot         608
+#define OBJ_setCext_hashedRoot         OBJ_set_certExt,0L
+
+#define SN_setCext_certType            "setCext-certType"
+#define NID_setCext_certType           609
+#define OBJ_setCext_certType           OBJ_set_certExt,1L
+
+#define SN_setCext_merchData           "setCext-merchData"
+#define NID_setCext_merchData          610
+#define OBJ_setCext_merchData          OBJ_set_certExt,2L
+
+#define SN_setCext_cCertRequired               "setCext-cCertRequired"
+#define NID_setCext_cCertRequired              611
+#define OBJ_setCext_cCertRequired              OBJ_set_certExt,3L
+
+#define SN_setCext_tunneling           "setCext-tunneling"
+#define NID_setCext_tunneling          612
+#define OBJ_setCext_tunneling          OBJ_set_certExt,4L
+
+#define SN_setCext_setExt              "setCext-setExt"
+#define NID_setCext_setExt             613
+#define OBJ_setCext_setExt             OBJ_set_certExt,5L
+
+#define SN_setCext_setQualf            "setCext-setQualf"
+#define NID_setCext_setQualf           614
+#define OBJ_setCext_setQualf           OBJ_set_certExt,6L
+
+#define SN_setCext_PGWYcapabilities            "setCext-PGWYcapabilities"
+#define NID_setCext_PGWYcapabilities           615
+#define OBJ_setCext_PGWYcapabilities           OBJ_set_certExt,7L
+
+#define SN_setCext_TokenIdentifier             "setCext-TokenIdentifier"
+#define NID_setCext_TokenIdentifier            616
+#define OBJ_setCext_TokenIdentifier            OBJ_set_certExt,8L
+
+#define SN_setCext_Track2Data          "setCext-Track2Data"
+#define NID_setCext_Track2Data         617
+#define OBJ_setCext_Track2Data         OBJ_set_certExt,9L
+
+#define SN_setCext_TokenType           "setCext-TokenType"
+#define NID_setCext_TokenType          618
+#define OBJ_setCext_TokenType          OBJ_set_certExt,10L
+
+#define SN_setCext_IssuerCapabilities          "setCext-IssuerCapabilities"
+#define NID_setCext_IssuerCapabilities         619
+#define OBJ_setCext_IssuerCapabilities         OBJ_set_certExt,11L
+
+#define SN_setAttr_Cert                "setAttr-Cert"
+#define NID_setAttr_Cert               620
+#define OBJ_setAttr_Cert               OBJ_set_attr,0L
+
+#define SN_setAttr_PGWYcap             "setAttr-PGWYcap"
+#define LN_setAttr_PGWYcap             "payment gateway capabilities"
+#define NID_setAttr_PGWYcap            621
+#define OBJ_setAttr_PGWYcap            OBJ_set_attr,1L
+
+#define SN_setAttr_TokenType           "setAttr-TokenType"
+#define NID_setAttr_TokenType          622
+#define OBJ_setAttr_TokenType          OBJ_set_attr,2L
+
+#define SN_setAttr_IssCap              "setAttr-IssCap"
+#define LN_setAttr_IssCap              "issuer capabilities"
+#define NID_setAttr_IssCap             623
+#define OBJ_setAttr_IssCap             OBJ_set_attr,3L
+
+#define SN_set_rootKeyThumb            "set-rootKeyThumb"
+#define NID_set_rootKeyThumb           624
+#define OBJ_set_rootKeyThumb           OBJ_setAttr_Cert,0L
+
+#define SN_set_addPolicy               "set-addPolicy"
+#define NID_set_addPolicy              625
+#define OBJ_set_addPolicy              OBJ_setAttr_Cert,1L
+
+#define SN_setAttr_Token_EMV           "setAttr-Token-EMV"
+#define NID_setAttr_Token_EMV          626
+#define OBJ_setAttr_Token_EMV          OBJ_setAttr_TokenType,1L
+
+#define SN_setAttr_Token_B0Prime               "setAttr-Token-B0Prime"
+#define NID_setAttr_Token_B0Prime              627
+#define OBJ_setAttr_Token_B0Prime              OBJ_setAttr_TokenType,2L
+
+#define SN_setAttr_IssCap_CVM          "setAttr-IssCap-CVM"
+#define NID_setAttr_IssCap_CVM         628
+#define OBJ_setAttr_IssCap_CVM         OBJ_setAttr_IssCap,3L
+
+#define SN_setAttr_IssCap_T2           "setAttr-IssCap-T2"
+#define NID_setAttr_IssCap_T2          629
+#define OBJ_setAttr_IssCap_T2          OBJ_setAttr_IssCap,4L
+
+#define SN_setAttr_IssCap_Sig          "setAttr-IssCap-Sig"
+#define NID_setAttr_IssCap_Sig         630
+#define OBJ_setAttr_IssCap_Sig         OBJ_setAttr_IssCap,5L
+
+#define SN_setAttr_GenCryptgrm         "setAttr-GenCryptgrm"
+#define LN_setAttr_GenCryptgrm         "generate cryptogram"
+#define NID_setAttr_GenCryptgrm                631
+#define OBJ_setAttr_GenCryptgrm                OBJ_setAttr_IssCap_CVM,1L
+
+#define SN_setAttr_T2Enc               "setAttr-T2Enc"
+#define LN_setAttr_T2Enc               "encrypted track 2"
+#define NID_setAttr_T2Enc              632
+#define OBJ_setAttr_T2Enc              OBJ_setAttr_IssCap_T2,1L
+
+#define SN_setAttr_T2cleartxt          "setAttr-T2cleartxt"
+#define LN_setAttr_T2cleartxt          "cleartext track 2"
+#define NID_setAttr_T2cleartxt         633
+#define OBJ_setAttr_T2cleartxt         OBJ_setAttr_IssCap_T2,2L
+
+#define SN_setAttr_TokICCsig           "setAttr-TokICCsig"
+#define LN_setAttr_TokICCsig           "ICC or token signature"
+#define NID_setAttr_TokICCsig          634
+#define OBJ_setAttr_TokICCsig          OBJ_setAttr_IssCap_Sig,1L
+
+#define SN_setAttr_SecDevSig           "setAttr-SecDevSig"
+#define LN_setAttr_SecDevSig           "secure device signature"
+#define NID_setAttr_SecDevSig          635
+#define OBJ_setAttr_SecDevSig          OBJ_setAttr_IssCap_Sig,2L
+
+#define SN_set_brand_IATA_ATA          "set-brand-IATA-ATA"
+#define NID_set_brand_IATA_ATA         636
+#define OBJ_set_brand_IATA_ATA         OBJ_set_brand,1L
+
+#define SN_set_brand_Diners            "set-brand-Diners"
+#define NID_set_brand_Diners           637
+#define OBJ_set_brand_Diners           OBJ_set_brand,30L
+
+#define SN_set_brand_AmericanExpress           "set-brand-AmericanExpress"
+#define NID_set_brand_AmericanExpress          638
+#define OBJ_set_brand_AmericanExpress          OBJ_set_brand,34L
+
+#define SN_set_brand_JCB               "set-brand-JCB"
+#define NID_set_brand_JCB              639
+#define OBJ_set_brand_JCB              OBJ_set_brand,35L
+
+#define SN_set_brand_Visa              "set-brand-Visa"
+#define NID_set_brand_Visa             640
+#define OBJ_set_brand_Visa             OBJ_set_brand,4L
+
+#define SN_set_brand_MasterCard                "set-brand-MasterCard"
+#define NID_set_brand_MasterCard               641
+#define OBJ_set_brand_MasterCard               OBJ_set_brand,5L
+
+#define SN_set_brand_Novus             "set-brand-Novus"
+#define NID_set_brand_Novus            642
+#define OBJ_set_brand_Novus            OBJ_set_brand,6011L
+
+#define SN_des_cdmf            "DES-CDMF"
+#define LN_des_cdmf            "des-cdmf"
+#define NID_des_cdmf           643
+#define OBJ_des_cdmf           OBJ_rsadsi,3L,10L
+
+#define SN_rsaOAEPEncryptionSET                "rsaOAEPEncryptionSET"
+#define NID_rsaOAEPEncryptionSET               644
+#define OBJ_rsaOAEPEncryptionSET               OBJ_rsadsi,1L,1L,6L
+
+#define SN_ipsec3              "Oakley-EC2N-3"
+#define LN_ipsec3              "ipsec3"
+#define NID_ipsec3             749
+
+#define SN_ipsec4              "Oakley-EC2N-4"
+#define LN_ipsec4              "ipsec4"
+#define NID_ipsec4             750
+
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/objects.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/objects.h
new file mode 100644 (file)
index 0000000..7700894
--- /dev/null
@@ -0,0 +1,1049 @@
+/* crypto/objects/objects.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_OBJECTS_H\r
+#define HEADER_OBJECTS_H\r
+\r
+#define USE_OBJ_MAC\r
+\r
+#ifdef USE_OBJ_MAC\r
+#include <openssl/obj_mac.h>\r
+#else\r
+#define SN_undef                       "UNDEF"\r
+#define LN_undef                       "undefined"\r
+#define NID_undef                      0\r
+#define OBJ_undef                      0L\r
+\r
+#define SN_Algorithm                   "Algorithm"\r
+#define LN_algorithm                   "algorithm"\r
+#define NID_algorithm                  38\r
+#define OBJ_algorithm                  1L,3L,14L,3L,2L\r
+\r
+#define LN_rsadsi                      "rsadsi"\r
+#define NID_rsadsi                     1\r
+#define OBJ_rsadsi                     1L,2L,840L,113549L\r
+\r
+#define LN_pkcs                                "pkcs"\r
+#define NID_pkcs                       2\r
+#define OBJ_pkcs                       OBJ_rsadsi,1L\r
+\r
+#define SN_md2                         "MD2"\r
+#define LN_md2                         "md2"\r
+#define NID_md2                                3\r
+#define OBJ_md2                                OBJ_rsadsi,2L,2L\r
+\r
+#define SN_md5                         "MD5"\r
+#define LN_md5                         "md5"\r
+#define NID_md5                                4\r
+#define OBJ_md5                                OBJ_rsadsi,2L,5L\r
+\r
+#define SN_rc4                         "RC4"\r
+#define LN_rc4                         "rc4"\r
+#define NID_rc4                                5\r
+#define OBJ_rc4                                OBJ_rsadsi,3L,4L\r
+\r
+#define LN_rsaEncryption               "rsaEncryption"\r
+#define NID_rsaEncryption              6\r
+#define OBJ_rsaEncryption              OBJ_pkcs,1L,1L\r
+\r
+#define SN_md2WithRSAEncryption                "RSA-MD2"\r
+#define LN_md2WithRSAEncryption                "md2WithRSAEncryption"\r
+#define NID_md2WithRSAEncryption       7\r
+#define OBJ_md2WithRSAEncryption       OBJ_pkcs,1L,2L\r
+\r
+#define SN_md5WithRSAEncryption                "RSA-MD5"\r
+#define LN_md5WithRSAEncryption                "md5WithRSAEncryption"\r
+#define NID_md5WithRSAEncryption       8\r
+#define OBJ_md5WithRSAEncryption       OBJ_pkcs,1L,4L\r
+\r
+#define SN_pbeWithMD2AndDES_CBC                "PBE-MD2-DES"\r
+#define LN_pbeWithMD2AndDES_CBC                "pbeWithMD2AndDES-CBC"\r
+#define NID_pbeWithMD2AndDES_CBC       9\r
+#define OBJ_pbeWithMD2AndDES_CBC       OBJ_pkcs,5L,1L\r
+\r
+#define SN_pbeWithMD5AndDES_CBC                "PBE-MD5-DES"\r
+#define LN_pbeWithMD5AndDES_CBC                "pbeWithMD5AndDES-CBC"\r
+#define NID_pbeWithMD5AndDES_CBC       10\r
+#define OBJ_pbeWithMD5AndDES_CBC       OBJ_pkcs,5L,3L\r
+\r
+#define LN_X500                                "X500"\r
+#define NID_X500                       11\r
+#define OBJ_X500                       2L,5L\r
+\r
+#define LN_X509                                "X509"\r
+#define NID_X509                       12\r
+#define OBJ_X509                       OBJ_X500,4L\r
+\r
+#define SN_commonName                  "CN"\r
+#define LN_commonName                  "commonName"\r
+#define NID_commonName                 13\r
+#define OBJ_commonName                 OBJ_X509,3L\r
+\r
+#define SN_countryName                 "C"\r
+#define LN_countryName                 "countryName"\r
+#define NID_countryName                        14\r
+#define OBJ_countryName                        OBJ_X509,6L\r
+\r
+#define SN_localityName                        "L"\r
+#define LN_localityName                        "localityName"\r
+#define NID_localityName               15\r
+#define OBJ_localityName               OBJ_X509,7L\r
+\r
+/* Postal Address? PA */\r
+\r
+/* should be "ST" (rfc1327) but MS uses 'S' */\r
+#define SN_stateOrProvinceName         "ST"\r
+#define LN_stateOrProvinceName         "stateOrProvinceName"\r
+#define NID_stateOrProvinceName                16\r
+#define OBJ_stateOrProvinceName                OBJ_X509,8L\r
+\r
+#define SN_organizationName            "O"\r
+#define LN_organizationName            "organizationName"\r
+#define NID_organizationName           17\r
+#define OBJ_organizationName           OBJ_X509,10L\r
+\r
+#define SN_organizationalUnitName      "OU"\r
+#define LN_organizationalUnitName      "organizationalUnitName"\r
+#define NID_organizationalUnitName     18\r
+#define OBJ_organizationalUnitName     OBJ_X509,11L\r
+\r
+#define SN_rsa                         "RSA"\r
+#define LN_rsa                         "rsa"\r
+#define NID_rsa                                19\r
+#define OBJ_rsa                                OBJ_X500,8L,1L,1L\r
+\r
+#define LN_pkcs7                       "pkcs7"\r
+#define NID_pkcs7                      20\r
+#define OBJ_pkcs7                      OBJ_pkcs,7L\r
+\r
+#define LN_pkcs7_data                  "pkcs7-data"\r
+#define NID_pkcs7_data                 21\r
+#define OBJ_pkcs7_data                 OBJ_pkcs7,1L\r
+\r
+#define LN_pkcs7_signed                        "pkcs7-signedData"\r
+#define NID_pkcs7_signed               22\r
+#define OBJ_pkcs7_signed               OBJ_pkcs7,2L\r
+\r
+#define LN_pkcs7_enveloped             "pkcs7-envelopedData"\r
+#define NID_pkcs7_enveloped            23\r
+#define OBJ_pkcs7_enveloped            OBJ_pkcs7,3L\r
+\r
+#define LN_pkcs7_signedAndEnveloped    "pkcs7-signedAndEnvelopedData"\r
+#define NID_pkcs7_signedAndEnveloped   24\r
+#define OBJ_pkcs7_signedAndEnveloped   OBJ_pkcs7,4L\r
+\r
+#define LN_pkcs7_digest                        "pkcs7-digestData"\r
+#define NID_pkcs7_digest               25\r
+#define OBJ_pkcs7_digest               OBJ_pkcs7,5L\r
+\r
+#define LN_pkcs7_encrypted             "pkcs7-encryptedData"\r
+#define NID_pkcs7_encrypted            26\r
+#define OBJ_pkcs7_encrypted            OBJ_pkcs7,6L\r
+\r
+#define LN_pkcs3                       "pkcs3"\r
+#define NID_pkcs3                      27\r
+#define OBJ_pkcs3                      OBJ_pkcs,3L\r
+\r
+#define LN_dhKeyAgreement              "dhKeyAgreement"\r
+#define NID_dhKeyAgreement             28\r
+#define OBJ_dhKeyAgreement             OBJ_pkcs3,1L\r
+\r
+#define SN_des_ecb                     "DES-ECB"\r
+#define LN_des_ecb                     "des-ecb"\r
+#define NID_des_ecb                    29\r
+#define OBJ_des_ecb                    OBJ_algorithm,6L\r
+\r
+#define SN_des_cfb64                   "DES-CFB"\r
+#define LN_des_cfb64                   "des-cfb"\r
+#define NID_des_cfb64                  30\r
+/* IV + num */\r
+#define OBJ_des_cfb64                  OBJ_algorithm,9L\r
+\r
+#define SN_des_cbc                     "DES-CBC"\r
+#define LN_des_cbc                     "des-cbc"\r
+#define NID_des_cbc                    31\r
+/* IV */\r
+#define OBJ_des_cbc                    OBJ_algorithm,7L\r
+\r
+#define SN_des_ede                     "DES-EDE"\r
+#define LN_des_ede                     "des-ede"\r
+#define NID_des_ede                    32\r
+/* ?? */\r
+#define OBJ_des_ede                    OBJ_algorithm,17L\r
+\r
+#define SN_des_ede3                    "DES-EDE3"\r
+#define LN_des_ede3                    "des-ede3"\r
+#define NID_des_ede3                   33\r
+\r
+#define SN_idea_cbc                    "IDEA-CBC"\r
+#define LN_idea_cbc                    "idea-cbc"\r
+#define NID_idea_cbc                   34\r
+#define OBJ_idea_cbc                   1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L\r
+\r
+#define SN_idea_cfb64                  "IDEA-CFB"\r
+#define LN_idea_cfb64                  "idea-cfb"\r
+#define NID_idea_cfb64                 35\r
+\r
+#define SN_idea_ecb                    "IDEA-ECB"\r
+#define LN_idea_ecb                    "idea-ecb"\r
+#define NID_idea_ecb                   36\r
+\r
+#define SN_rc2_cbc                     "RC2-CBC"\r
+#define LN_rc2_cbc                     "rc2-cbc"\r
+#define NID_rc2_cbc                    37\r
+#define OBJ_rc2_cbc                    OBJ_rsadsi,3L,2L\r
+\r
+#define SN_rc2_ecb                     "RC2-ECB"\r
+#define LN_rc2_ecb                     "rc2-ecb"\r
+#define NID_rc2_ecb                    38\r
+\r
+#define SN_rc2_cfb64                   "RC2-CFB"\r
+#define LN_rc2_cfb64                   "rc2-cfb"\r
+#define NID_rc2_cfb64                  39\r
+\r
+#define SN_rc2_ofb64                   "RC2-OFB"\r
+#define LN_rc2_ofb64                   "rc2-ofb"\r
+#define NID_rc2_ofb64                  40\r
+\r
+#define SN_sha                         "SHA"\r
+#define LN_sha                         "sha"\r
+#define NID_sha                                41\r
+#define OBJ_sha                                OBJ_algorithm,18L\r
+\r
+#define SN_shaWithRSAEncryption                "RSA-SHA"\r
+#define LN_shaWithRSAEncryption                "shaWithRSAEncryption"\r
+#define NID_shaWithRSAEncryption       42\r
+#define OBJ_shaWithRSAEncryption       OBJ_algorithm,15L\r
+\r
+#define SN_des_ede_cbc                 "DES-EDE-CBC"\r
+#define LN_des_ede_cbc                 "des-ede-cbc"\r
+#define NID_des_ede_cbc                        43\r
+\r
+#define SN_des_ede3_cbc                        "DES-EDE3-CBC"\r
+#define LN_des_ede3_cbc                        "des-ede3-cbc"\r
+#define NID_des_ede3_cbc               44\r
+#define OBJ_des_ede3_cbc               OBJ_rsadsi,3L,7L\r
+\r
+#define SN_des_ofb64                   "DES-OFB"\r
+#define LN_des_ofb64                   "des-ofb"\r
+#define NID_des_ofb64                  45\r
+#define OBJ_des_ofb64                  OBJ_algorithm,8L\r
+\r
+#define SN_idea_ofb64                  "IDEA-OFB"\r
+#define LN_idea_ofb64                  "idea-ofb"\r
+#define NID_idea_ofb64                 46\r
+\r
+#define LN_pkcs9                       "pkcs9"\r
+#define NID_pkcs9                      47\r
+#define OBJ_pkcs9                      OBJ_pkcs,9L\r
+\r
+#define SN_pkcs9_emailAddress          "Email"\r
+#define LN_pkcs9_emailAddress          "emailAddress"\r
+#define NID_pkcs9_emailAddress         48\r
+#define OBJ_pkcs9_emailAddress         OBJ_pkcs9,1L\r
+\r
+#define LN_pkcs9_unstructuredName      "unstructuredName"\r
+#define NID_pkcs9_unstructuredName     49\r
+#define OBJ_pkcs9_unstructuredName     OBJ_pkcs9,2L\r
+\r
+#define LN_pkcs9_contentType           "contentType"\r
+#define NID_pkcs9_contentType          50\r
+#define OBJ_pkcs9_contentType          OBJ_pkcs9,3L\r
+\r
+#define LN_pkcs9_messageDigest         "messageDigest"\r
+#define NID_pkcs9_messageDigest                51\r
+#define OBJ_pkcs9_messageDigest                OBJ_pkcs9,4L\r
+\r
+#define LN_pkcs9_signingTime           "signingTime"\r
+#define NID_pkcs9_signingTime          52\r
+#define OBJ_pkcs9_signingTime          OBJ_pkcs9,5L\r
+\r
+#define LN_pkcs9_countersignature      "countersignature"\r
+#define NID_pkcs9_countersignature     53\r
+#define OBJ_pkcs9_countersignature     OBJ_pkcs9,6L\r
+\r
+#define LN_pkcs9_challengePassword     "challengePassword"\r
+#define NID_pkcs9_challengePassword    54\r
+#define OBJ_pkcs9_challengePassword    OBJ_pkcs9,7L\r
+\r
+#define LN_pkcs9_unstructuredAddress   "unstructuredAddress"\r
+#define NID_pkcs9_unstructuredAddress  55\r
+#define OBJ_pkcs9_unstructuredAddress  OBJ_pkcs9,8L\r
+\r
+#define LN_pkcs9_extCertAttributes     "extendedCertificateAttributes"\r
+#define NID_pkcs9_extCertAttributes    56\r
+#define OBJ_pkcs9_extCertAttributes    OBJ_pkcs9,9L\r
+\r
+#define SN_netscape                    "Netscape"\r
+#define LN_netscape                    "Netscape Communications Corp."\r
+#define NID_netscape                   57\r
+#define OBJ_netscape                   2L,16L,840L,1L,113730L\r
+\r
+#define SN_netscape_cert_extension     "nsCertExt"\r
+#define LN_netscape_cert_extension     "Netscape Certificate Extension"\r
+#define NID_netscape_cert_extension    58\r
+#define OBJ_netscape_cert_extension    OBJ_netscape,1L\r
+\r
+#define SN_netscape_data_type          "nsDataType"\r
+#define LN_netscape_data_type          "Netscape Data Type"\r
+#define NID_netscape_data_type         59\r
+#define OBJ_netscape_data_type         OBJ_netscape,2L\r
+\r
+#define SN_des_ede_cfb64               "DES-EDE-CFB"\r
+#define LN_des_ede_cfb64               "des-ede-cfb"\r
+#define NID_des_ede_cfb64              60\r
+\r
+#define SN_des_ede3_cfb64              "DES-EDE3-CFB"\r
+#define LN_des_ede3_cfb64              "des-ede3-cfb"\r
+#define NID_des_ede3_cfb64             61\r
+\r
+#define SN_des_ede_ofb64               "DES-EDE-OFB"\r
+#define LN_des_ede_ofb64               "des-ede-ofb"\r
+#define NID_des_ede_ofb64              62\r
+\r
+#define SN_des_ede3_ofb64              "DES-EDE3-OFB"\r
+#define LN_des_ede3_ofb64              "des-ede3-ofb"\r
+#define NID_des_ede3_ofb64             63\r
+\r
+/* I'm not sure about the object ID */\r
+#define SN_sha1                                "SHA1"\r
+#define LN_sha1                                "sha1"\r
+#define NID_sha1                       64\r
+#define OBJ_sha1                       OBJ_algorithm,26L\r
+/* 28 Jun 1996 - eay */\r
+/* #define OBJ_sha1                    1L,3L,14L,2L,26L,05L <- wrong */\r
+\r
+#define SN_sha1WithRSAEncryption       "RSA-SHA1"\r
+#define LN_sha1WithRSAEncryption       "sha1WithRSAEncryption"\r
+#define NID_sha1WithRSAEncryption      65\r
+#define OBJ_sha1WithRSAEncryption      OBJ_pkcs,1L,5L\r
+\r
+#define SN_dsaWithSHA                  "DSA-SHA"\r
+#define LN_dsaWithSHA                  "dsaWithSHA"\r
+#define NID_dsaWithSHA                 66\r
+#define OBJ_dsaWithSHA                 OBJ_algorithm,13L\r
+\r
+#define SN_dsa_2                       "DSA-old"\r
+#define LN_dsa_2                       "dsaEncryption-old"\r
+#define NID_dsa_2                      67\r
+#define OBJ_dsa_2                      OBJ_algorithm,12L\r
+\r
+/* proposed by microsoft to RSA */\r
+#define SN_pbeWithSHA1AndRC2_CBC       "PBE-SHA1-RC2-64"\r
+#define LN_pbeWithSHA1AndRC2_CBC       "pbeWithSHA1AndRC2-CBC"\r
+#define NID_pbeWithSHA1AndRC2_CBC      68\r
+#define OBJ_pbeWithSHA1AndRC2_CBC      OBJ_pkcs,5L,11L \r
+\r
+/* proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now\r
+ * defined explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something\r
+ * completely different.\r
+ */\r
+#define LN_id_pbkdf2                   "PBKDF2"\r
+#define NID_id_pbkdf2                  69\r
+#define OBJ_id_pbkdf2                  OBJ_pkcs,5L,12L \r
+\r
+#define SN_dsaWithSHA1_2               "DSA-SHA1-old"\r
+#define LN_dsaWithSHA1_2               "dsaWithSHA1-old"\r
+#define NID_dsaWithSHA1_2              70\r
+/* Got this one from 'sdn706r20.pdf' which is actually an NSA document :-) */\r
+#define OBJ_dsaWithSHA1_2              OBJ_algorithm,27L\r
+\r
+#define SN_netscape_cert_type          "nsCertType"\r
+#define LN_netscape_cert_type          "Netscape Cert Type"\r
+#define NID_netscape_cert_type         71\r
+#define OBJ_netscape_cert_type         OBJ_netscape_cert_extension,1L\r
+\r
+#define SN_netscape_base_url           "nsBaseUrl"\r
+#define LN_netscape_base_url           "Netscape Base Url"\r
+#define NID_netscape_base_url          72\r
+#define OBJ_netscape_base_url          OBJ_netscape_cert_extension,2L\r
+\r
+#define SN_netscape_revocation_url     "nsRevocationUrl"\r
+#define LN_netscape_revocation_url     "Netscape Revocation Url"\r
+#define NID_netscape_revocation_url    73\r
+#define OBJ_netscape_revocation_url    OBJ_netscape_cert_extension,3L\r
+\r
+#define SN_netscape_ca_revocation_url  "nsCaRevocationUrl"\r
+#define LN_netscape_ca_revocation_url  "Netscape CA Revocation Url"\r
+#define NID_netscape_ca_revocation_url 74\r
+#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L\r
+\r
+#define SN_netscape_renewal_url                "nsRenewalUrl"\r
+#define LN_netscape_renewal_url                "Netscape Renewal Url"\r
+#define NID_netscape_renewal_url       75\r
+#define OBJ_netscape_renewal_url       OBJ_netscape_cert_extension,7L\r
+\r
+#define SN_netscape_ca_policy_url      "nsCaPolicyUrl"\r
+#define LN_netscape_ca_policy_url      "Netscape CA Policy Url"\r
+#define NID_netscape_ca_policy_url     76\r
+#define OBJ_netscape_ca_policy_url     OBJ_netscape_cert_extension,8L\r
+\r
+#define SN_netscape_ssl_server_name    "nsSslServerName"\r
+#define LN_netscape_ssl_server_name    "Netscape SSL Server Name"\r
+#define NID_netscape_ssl_server_name   77\r
+#define OBJ_netscape_ssl_server_name   OBJ_netscape_cert_extension,12L\r
+\r
+#define SN_netscape_comment            "nsComment"\r
+#define LN_netscape_comment            "Netscape Comment"\r
+#define NID_netscape_comment           78\r
+#define OBJ_netscape_comment           OBJ_netscape_cert_extension,13L\r
+\r
+#define SN_netscape_cert_sequence      "nsCertSequence"\r
+#define LN_netscape_cert_sequence      "Netscape Certificate Sequence"\r
+#define NID_netscape_cert_sequence     79\r
+#define OBJ_netscape_cert_sequence     OBJ_netscape_data_type,5L\r
+\r
+#define SN_desx_cbc                    "DESX-CBC"\r
+#define LN_desx_cbc                    "desx-cbc"\r
+#define NID_desx_cbc                   80\r
+\r
+#define SN_id_ce                       "id-ce"\r
+#define NID_id_ce                      81\r
+#define OBJ_id_ce                      2L,5L,29L\r
+\r
+#define SN_subject_key_identifier      "subjectKeyIdentifier"\r
+#define LN_subject_key_identifier      "X509v3 Subject Key Identifier"\r
+#define NID_subject_key_identifier     82\r
+#define OBJ_subject_key_identifier     OBJ_id_ce,14L\r
+\r
+#define SN_key_usage                   "keyUsage"\r
+#define LN_key_usage                   "X509v3 Key Usage"\r
+#define NID_key_usage                  83\r
+#define OBJ_key_usage                  OBJ_id_ce,15L\r
+\r
+#define SN_private_key_usage_period    "privateKeyUsagePeriod"\r
+#define LN_private_key_usage_period    "X509v3 Private Key Usage Period"\r
+#define NID_private_key_usage_period   84\r
+#define OBJ_private_key_usage_period   OBJ_id_ce,16L\r
+\r
+#define SN_subject_alt_name            "subjectAltName"\r
+#define LN_subject_alt_name            "X509v3 Subject Alternative Name"\r
+#define NID_subject_alt_name           85\r
+#define OBJ_subject_alt_name           OBJ_id_ce,17L\r
+\r
+#define SN_issuer_alt_name             "issuerAltName"\r
+#define LN_issuer_alt_name             "X509v3 Issuer Alternative Name"\r
+#define NID_issuer_alt_name            86\r
+#define OBJ_issuer_alt_name            OBJ_id_ce,18L\r
+\r
+#define SN_basic_constraints           "basicConstraints"\r
+#define LN_basic_constraints           "X509v3 Basic Constraints"\r
+#define NID_basic_constraints          87\r
+#define OBJ_basic_constraints          OBJ_id_ce,19L\r
+\r
+#define SN_crl_number                  "crlNumber"\r
+#define LN_crl_number                  "X509v3 CRL Number"\r
+#define NID_crl_number                 88\r
+#define OBJ_crl_number                 OBJ_id_ce,20L\r
+\r
+#define SN_certificate_policies                "certificatePolicies"\r
+#define LN_certificate_policies                "X509v3 Certificate Policies"\r
+#define NID_certificate_policies       89\r
+#define OBJ_certificate_policies       OBJ_id_ce,32L\r
+\r
+#define SN_authority_key_identifier    "authorityKeyIdentifier"\r
+#define LN_authority_key_identifier    "X509v3 Authority Key Identifier"\r
+#define NID_authority_key_identifier   90\r
+#define OBJ_authority_key_identifier   OBJ_id_ce,35L\r
+\r
+#define SN_bf_cbc                      "BF-CBC"\r
+#define LN_bf_cbc                      "bf-cbc"\r
+#define NID_bf_cbc                     91\r
+#define OBJ_bf_cbc                     1L,3L,6L,1L,4L,1L,3029L,1L,2L\r
+\r
+#define SN_bf_ecb                      "BF-ECB"\r
+#define LN_bf_ecb                      "bf-ecb"\r
+#define NID_bf_ecb                     92\r
+\r
+#define SN_bf_cfb64                    "BF-CFB"\r
+#define LN_bf_cfb64                    "bf-cfb"\r
+#define NID_bf_cfb64                   93\r
+\r
+#define SN_bf_ofb64                    "BF-OFB"\r
+#define LN_bf_ofb64                    "bf-ofb"\r
+#define NID_bf_ofb64                   94\r
+\r
+#define SN_mdc2                                "MDC2"\r
+#define LN_mdc2                                "mdc2"\r
+#define NID_mdc2                       95\r
+#define OBJ_mdc2                       2L,5L,8L,3L,101L\r
+/* An alternative?                     1L,3L,14L,3L,2L,19L */\r
+\r
+#define SN_mdc2WithRSA                 "RSA-MDC2"\r
+#define LN_mdc2WithRSA                 "mdc2withRSA"\r
+#define NID_mdc2WithRSA                        96\r
+#define OBJ_mdc2WithRSA                        2L,5L,8L,3L,100L\r
+\r
+#define SN_rc4_40                      "RC4-40"\r
+#define LN_rc4_40                      "rc4-40"\r
+#define NID_rc4_40                     97\r
+\r
+#define SN_rc2_40_cbc                  "RC2-40-CBC"\r
+#define LN_rc2_40_cbc                  "rc2-40-cbc"\r
+#define NID_rc2_40_cbc                 98\r
+\r
+#define SN_givenName                   "G"\r
+#define LN_givenName                   "givenName"\r
+#define NID_givenName                  99\r
+#define OBJ_givenName                  OBJ_X509,42L\r
+\r
+#define SN_surname                     "S"\r
+#define LN_surname                     "surname"\r
+#define NID_surname                    100\r
+#define OBJ_surname                    OBJ_X509,4L\r
+\r
+#define SN_initials                    "I"\r
+#define LN_initials                    "initials"\r
+#define NID_initials                   101\r
+#define OBJ_initials                   OBJ_X509,43L\r
+\r
+#define SN_uniqueIdentifier            "UID"\r
+#define LN_uniqueIdentifier            "uniqueIdentifier"\r
+#define NID_uniqueIdentifier           102\r
+#define OBJ_uniqueIdentifier           OBJ_X509,45L\r
+\r
+#define SN_crl_distribution_points     "crlDistributionPoints"\r
+#define LN_crl_distribution_points     "X509v3 CRL Distribution Points"\r
+#define NID_crl_distribution_points    103\r
+#define OBJ_crl_distribution_points    OBJ_id_ce,31L\r
+\r
+#define SN_md5WithRSA                  "RSA-NP-MD5"\r
+#define LN_md5WithRSA                  "md5WithRSA"\r
+#define NID_md5WithRSA                 104\r
+#define OBJ_md5WithRSA                 OBJ_algorithm,3L\r
+\r
+#define SN_serialNumber                        "SN"\r
+#define LN_serialNumber                        "serialNumber"\r
+#define NID_serialNumber               105\r
+#define OBJ_serialNumber               OBJ_X509,5L\r
+\r
+#define SN_title                       "T"\r
+#define LN_title                       "title"\r
+#define NID_title                      106\r
+#define OBJ_title                      OBJ_X509,12L\r
+\r
+#define SN_description                 "D"\r
+#define LN_description                 "description"\r
+#define NID_description                        107\r
+#define OBJ_description                        OBJ_X509,13L\r
+\r
+/* CAST5 is CAST-128, I'm just sticking with the documentation */\r
+#define SN_cast5_cbc                   "CAST5-CBC"\r
+#define LN_cast5_cbc                   "cast5-cbc"\r
+#define NID_cast5_cbc                  108\r
+#define OBJ_cast5_cbc                  1L,2L,840L,113533L,7L,66L,10L\r
+\r
+#define SN_cast5_ecb                   "CAST5-ECB"\r
+#define LN_cast5_ecb                   "cast5-ecb"\r
+#define NID_cast5_ecb                  109\r
+\r
+#define SN_cast5_cfb64                 "CAST5-CFB"\r
+#define LN_cast5_cfb64                 "cast5-cfb"\r
+#define NID_cast5_cfb64                        110\r
+\r
+#define SN_cast5_ofb64                 "CAST5-OFB"\r
+#define LN_cast5_ofb64                 "cast5-ofb"\r
+#define NID_cast5_ofb64                        111\r
+\r
+#define LN_pbeWithMD5AndCast5_CBC      "pbeWithMD5AndCast5CBC"\r
+#define NID_pbeWithMD5AndCast5_CBC     112\r
+#define OBJ_pbeWithMD5AndCast5_CBC     1L,2L,840L,113533L,7L,66L,12L\r
+\r
+/* This is one sun will soon be using :-(\r
+ * id-dsa-with-sha1 ID  ::= {\r
+ *   iso(1) member-body(2) us(840) x9-57 (10040) x9cm(4) 3 }\r
+ */\r
+#define SN_dsaWithSHA1                 "DSA-SHA1"\r
+#define LN_dsaWithSHA1                 "dsaWithSHA1"\r
+#define NID_dsaWithSHA1                        113\r
+#define OBJ_dsaWithSHA1                        1L,2L,840L,10040L,4L,3L\r
+\r
+#define NID_md5_sha1                   114\r
+#define SN_md5_sha1                    "MD5-SHA1"\r
+#define LN_md5_sha1                    "md5-sha1"\r
+\r
+#define SN_sha1WithRSA                 "RSA-SHA1-2"\r
+#define LN_sha1WithRSA                 "sha1WithRSA"\r
+#define NID_sha1WithRSA                        115\r
+#define OBJ_sha1WithRSA                        OBJ_algorithm,29L\r
+\r
+#define SN_dsa                         "DSA"\r
+#define LN_dsa                         "dsaEncryption"\r
+#define NID_dsa                                116\r
+#define OBJ_dsa                                1L,2L,840L,10040L,4L,1L\r
+\r
+#define SN_ripemd160                   "RIPEMD160"\r
+#define LN_ripemd160                   "ripemd160"\r
+#define NID_ripemd160                  117\r
+#define OBJ_ripemd160                  1L,3L,36L,3L,2L,1L\r
+\r
+/* The name should actually be rsaSignatureWithripemd160, but I'm going\r
+ * to continue using the convention I'm using with the other ciphers */\r
+#define SN_ripemd160WithRSA            "RSA-RIPEMD160"\r
+#define LN_ripemd160WithRSA            "ripemd160WithRSA"\r
+#define NID_ripemd160WithRSA           119\r
+#define OBJ_ripemd160WithRSA           1L,3L,36L,3L,3L,1L,2L\r
+\r
+/* Taken from rfc2040\r
+ *  RC5_CBC_Parameters ::= SEQUENCE {\r
+ *     version           INTEGER (v1_0(16)),\r
+ *     rounds            INTEGER (8..127),\r
+ *     blockSizeInBits   INTEGER (64, 128),\r
+ *     iv                OCTET STRING OPTIONAL\r
+ *     }\r
+ */\r
+#define SN_rc5_cbc                     "RC5-CBC"\r
+#define LN_rc5_cbc                     "rc5-cbc"\r
+#define NID_rc5_cbc                    120\r
+#define OBJ_rc5_cbc                    OBJ_rsadsi,3L,8L\r
+\r
+#define SN_rc5_ecb                     "RC5-ECB"\r
+#define LN_rc5_ecb                     "rc5-ecb"\r
+#define NID_rc5_ecb                    121\r
+\r
+#define SN_rc5_cfb64                   "RC5-CFB"\r
+#define LN_rc5_cfb64                   "rc5-cfb"\r
+#define NID_rc5_cfb64                  122\r
+\r
+#define SN_rc5_ofb64                   "RC5-OFB"\r
+#define LN_rc5_ofb64                   "rc5-ofb"\r
+#define NID_rc5_ofb64                  123\r
+\r
+#define SN_rle_compression             "RLE"\r
+#define LN_rle_compression             "run length compression"\r
+#define NID_rle_compression            124\r
+#define OBJ_rle_compression            1L,1L,1L,1L,666L,1L\r
+\r
+#define SN_zlib_compression            "ZLIB"\r
+#define LN_zlib_compression            "zlib compression"\r
+#define NID_zlib_compression           125\r
+#define OBJ_zlib_compression           1L,1L,1L,1L,666L,2L\r
+\r
+#define SN_ext_key_usage               "extendedKeyUsage"\r
+#define LN_ext_key_usage               "X509v3 Extended Key Usage"\r
+#define NID_ext_key_usage              126\r
+#define OBJ_ext_key_usage              OBJ_id_ce,37\r
+\r
+#define SN_id_pkix                     "PKIX"\r
+#define NID_id_pkix                    127\r
+#define OBJ_id_pkix                    1L,3L,6L,1L,5L,5L,7L\r
+\r
+#define SN_id_kp                       "id-kp"\r
+#define NID_id_kp                      128\r
+#define OBJ_id_kp                      OBJ_id_pkix,3L\r
+\r
+/* PKIX extended key usage OIDs */\r
+\r
+#define SN_server_auth                 "serverAuth"\r
+#define LN_server_auth                 "TLS Web Server Authentication"\r
+#define NID_server_auth                        129\r
+#define OBJ_server_auth                        OBJ_id_kp,1L\r
+\r
+#define SN_client_auth                 "clientAuth"\r
+#define LN_client_auth                 "TLS Web Client Authentication"\r
+#define NID_client_auth                        130\r
+#define OBJ_client_auth                        OBJ_id_kp,2L\r
+\r
+#define SN_code_sign                   "codeSigning"\r
+#define LN_code_sign                   "Code Signing"\r
+#define NID_code_sign                  131\r
+#define OBJ_code_sign                  OBJ_id_kp,3L\r
+\r
+#define SN_email_protect               "emailProtection"\r
+#define LN_email_protect               "E-mail Protection"\r
+#define NID_email_protect              132\r
+#define OBJ_email_protect              OBJ_id_kp,4L\r
+\r
+#define SN_time_stamp                  "timeStamping"\r
+#define LN_time_stamp                  "Time Stamping"\r
+#define NID_time_stamp                 133\r
+#define OBJ_time_stamp                 OBJ_id_kp,8L\r
+\r
+/* Additional extended key usage OIDs: Microsoft */\r
+\r
+#define SN_ms_code_ind                 "msCodeInd"\r
+#define LN_ms_code_ind                 "Microsoft Individual Code Signing"\r
+#define NID_ms_code_ind                        134\r
+#define OBJ_ms_code_ind                        1L,3L,6L,1L,4L,1L,311L,2L,1L,21L\r
+\r
+#define SN_ms_code_com                 "msCodeCom"\r
+#define LN_ms_code_com                 "Microsoft Commercial Code Signing"\r
+#define NID_ms_code_com                        135\r
+#define OBJ_ms_code_com                        1L,3L,6L,1L,4L,1L,311L,2L,1L,22L\r
+\r
+#define SN_ms_ctl_sign                 "msCTLSign"\r
+#define LN_ms_ctl_sign                 "Microsoft Trust List Signing"\r
+#define NID_ms_ctl_sign                        136\r
+#define OBJ_ms_ctl_sign                        1L,3L,6L,1L,4L,1L,311L,10L,3L,1L\r
+\r
+#define SN_ms_sgc                      "msSGC"\r
+#define LN_ms_sgc                      "Microsoft Server Gated Crypto"\r
+#define NID_ms_sgc                     137\r
+#define OBJ_ms_sgc                     1L,3L,6L,1L,4L,1L,311L,10L,3L,3L\r
+\r
+#define SN_ms_efs                      "msEFS"\r
+#define LN_ms_efs                      "Microsoft Encrypted File System"\r
+#define NID_ms_efs                     138\r
+#define OBJ_ms_efs                     1L,3L,6L,1L,4L,1L,311L,10L,3L,4L\r
+\r
+/* Additional usage: Netscape */\r
+\r
+#define SN_ns_sgc                      "nsSGC"\r
+#define LN_ns_sgc                      "Netscape Server Gated Crypto"\r
+#define NID_ns_sgc                     139\r
+#define OBJ_ns_sgc                     OBJ_netscape,4L,1L\r
+\r
+#define SN_delta_crl                   "deltaCRL"\r
+#define LN_delta_crl                   "X509v3 Delta CRL Indicator"\r
+#define NID_delta_crl                  140\r
+#define OBJ_delta_crl                  OBJ_id_ce,27L\r
+\r
+#define SN_crl_reason                  "CRLReason"\r
+#define LN_crl_reason                  "CRL Reason Code"\r
+#define NID_crl_reason                 141\r
+#define OBJ_crl_reason                 OBJ_id_ce,21L\r
+\r
+#define SN_invalidity_date             "invalidityDate"\r
+#define LN_invalidity_date             "Invalidity Date"\r
+#define NID_invalidity_date            142\r
+#define OBJ_invalidity_date            OBJ_id_ce,24L\r
+\r
+#define SN_sxnet                       "SXNetID"\r
+#define LN_sxnet                       "Strong Extranet ID"\r
+#define NID_sxnet                      143\r
+#define OBJ_sxnet                      1L,3L,101L,1L,4L,1L\r
+\r
+/* PKCS12 and related OBJECT IDENTIFIERS */\r
+\r
+#define OBJ_pkcs12                     OBJ_pkcs,12L\r
+#define OBJ_pkcs12_pbeids              OBJ_pkcs12, 1\r
+\r
+#define SN_pbe_WithSHA1And128BitRC4    "PBE-SHA1-RC4-128"\r
+#define LN_pbe_WithSHA1And128BitRC4    "pbeWithSHA1And128BitRC4"\r
+#define NID_pbe_WithSHA1And128BitRC4   144\r
+#define OBJ_pbe_WithSHA1And128BitRC4   OBJ_pkcs12_pbeids, 1L\r
+\r
+#define SN_pbe_WithSHA1And40BitRC4     "PBE-SHA1-RC4-40"\r
+#define LN_pbe_WithSHA1And40BitRC4     "pbeWithSHA1And40BitRC4"\r
+#define NID_pbe_WithSHA1And40BitRC4    145\r
+#define OBJ_pbe_WithSHA1And40BitRC4    OBJ_pkcs12_pbeids, 2L\r
+\r
+#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC  "PBE-SHA1-3DES"\r
+#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC  "pbeWithSHA1And3-KeyTripleDES-CBC"\r
+#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146\r
+#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 3L\r
+\r
+#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC  "PBE-SHA1-2DES"\r
+#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC  "pbeWithSHA1And2-KeyTripleDES-CBC"\r
+#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147\r
+#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 4L\r
+\r
+#define SN_pbe_WithSHA1And128BitRC2_CBC                "PBE-SHA1-RC2-128"\r
+#define LN_pbe_WithSHA1And128BitRC2_CBC                "pbeWithSHA1And128BitRC2-CBC"\r
+#define NID_pbe_WithSHA1And128BitRC2_CBC       148\r
+#define OBJ_pbe_WithSHA1And128BitRC2_CBC       OBJ_pkcs12_pbeids, 5L\r
+\r
+#define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40"\r
+#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC"\r
+#define NID_pbe_WithSHA1And40BitRC2_CBC        149\r
+#define OBJ_pbe_WithSHA1And40BitRC2_CBC        OBJ_pkcs12_pbeids, 6L\r
+\r
+#define OBJ_pkcs12_Version1    OBJ_pkcs12, 10L\r
+\r
+#define OBJ_pkcs12_BagIds      OBJ_pkcs12_Version1, 1L\r
+\r
+#define LN_keyBag              "keyBag"\r
+#define NID_keyBag             150\r
+#define OBJ_keyBag             OBJ_pkcs12_BagIds, 1L\r
+\r
+#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag"\r
+#define NID_pkcs8ShroudedKeyBag        151\r
+#define OBJ_pkcs8ShroudedKeyBag        OBJ_pkcs12_BagIds, 2L\r
+\r
+#define LN_certBag             "certBag"\r
+#define NID_certBag            152\r
+#define OBJ_certBag            OBJ_pkcs12_BagIds, 3L\r
+\r
+#define LN_crlBag              "crlBag"\r
+#define NID_crlBag             153\r
+#define OBJ_crlBag             OBJ_pkcs12_BagIds, 4L\r
+\r
+#define LN_secretBag           "secretBag"\r
+#define NID_secretBag          154\r
+#define OBJ_secretBag          OBJ_pkcs12_BagIds, 5L\r
+\r
+#define LN_safeContentsBag     "safeContentsBag"\r
+#define NID_safeContentsBag    155\r
+#define OBJ_safeContentsBag    OBJ_pkcs12_BagIds, 6L\r
+\r
+#define LN_friendlyName                "friendlyName"\r
+#define        NID_friendlyName        156\r
+#define OBJ_friendlyName       OBJ_pkcs9, 20L\r
+\r
+#define LN_localKeyID          "localKeyID"\r
+#define        NID_localKeyID          157\r
+#define OBJ_localKeyID         OBJ_pkcs9, 21L\r
+\r
+#define OBJ_certTypes          OBJ_pkcs9, 22L\r
+\r
+#define LN_x509Certificate     "x509Certificate"\r
+#define        NID_x509Certificate     158\r
+#define OBJ_x509Certificate    OBJ_certTypes, 1L\r
+\r
+#define LN_sdsiCertificate     "sdsiCertificate"\r
+#define        NID_sdsiCertificate     159\r
+#define OBJ_sdsiCertificate    OBJ_certTypes, 2L\r
+\r
+#define OBJ_crlTypes           OBJ_pkcs9, 23L\r
+\r
+#define LN_x509Crl             "x509Crl"\r
+#define        NID_x509Crl             160\r
+#define OBJ_x509Crl            OBJ_crlTypes, 1L\r
+\r
+/* PKCS#5 v2 OIDs */\r
+\r
+#define LN_pbes2               "PBES2"\r
+#define NID_pbes2              161\r
+#define OBJ_pbes2              OBJ_pkcs,5L,13L\r
+\r
+#define LN_pbmac1              "PBMAC1"\r
+#define NID_pbmac1             162\r
+#define OBJ_pbmac1             OBJ_pkcs,5L,14L\r
+\r
+#define LN_hmacWithSHA1                "hmacWithSHA1"\r
+#define NID_hmacWithSHA1       163\r
+#define OBJ_hmacWithSHA1       OBJ_rsadsi,2L,7L\r
+\r
+/* Policy Qualifier Ids */\r
+\r
+#define LN_id_qt_cps           "Policy Qualifier CPS"\r
+#define SN_id_qt_cps           "id-qt-cps"\r
+#define NID_id_qt_cps          164\r
+#define OBJ_id_qt_cps          OBJ_id_pkix,2L,1L\r
+\r
+#define LN_id_qt_unotice       "Policy Qualifier User Notice"\r
+#define SN_id_qt_unotice       "id-qt-unotice"\r
+#define NID_id_qt_unotice      165\r
+#define OBJ_id_qt_unotice      OBJ_id_pkix,2L,2L\r
+\r
+#define SN_rc2_64_cbc                  "RC2-64-CBC"\r
+#define LN_rc2_64_cbc                  "rc2-64-cbc"\r
+#define NID_rc2_64_cbc                 166\r
+\r
+#define SN_SMIMECapabilities           "SMIME-CAPS"\r
+#define LN_SMIMECapabilities           "S/MIME Capabilities"\r
+#define NID_SMIMECapabilities          167\r
+#define OBJ_SMIMECapabilities          OBJ_pkcs9,15L\r
+\r
+#define SN_pbeWithMD2AndRC2_CBC                "PBE-MD2-RC2-64"\r
+#define LN_pbeWithMD2AndRC2_CBC                "pbeWithMD2AndRC2-CBC"\r
+#define NID_pbeWithMD2AndRC2_CBC       168\r
+#define OBJ_pbeWithMD2AndRC2_CBC       OBJ_pkcs,5L,4L\r
+\r
+#define SN_pbeWithMD5AndRC2_CBC                "PBE-MD5-RC2-64"\r
+#define LN_pbeWithMD5AndRC2_CBC                "pbeWithMD5AndRC2-CBC"\r
+#define NID_pbeWithMD5AndRC2_CBC       169\r
+#define OBJ_pbeWithMD5AndRC2_CBC       OBJ_pkcs,5L,6L\r
+\r
+#define SN_pbeWithSHA1AndDES_CBC       "PBE-SHA1-DES"\r
+#define LN_pbeWithSHA1AndDES_CBC       "pbeWithSHA1AndDES-CBC"\r
+#define NID_pbeWithSHA1AndDES_CBC      170\r
+#define OBJ_pbeWithSHA1AndDES_CBC      OBJ_pkcs,5L,10L\r
+\r
+/* Extension request OIDs */\r
+\r
+#define LN_ms_ext_req                  "Microsoft Extension Request"\r
+#define SN_ms_ext_req                  "msExtReq"\r
+#define NID_ms_ext_req                 171\r
+#define OBJ_ms_ext_req                 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L\r
+\r
+#define LN_ext_req                     "Extension Request"\r
+#define SN_ext_req                     "extReq"\r
+#define NID_ext_req                    172\r
+#define OBJ_ext_req                    OBJ_pkcs9,14L\r
+\r
+#define SN_name                                "name"\r
+#define LN_name                                "name"\r
+#define NID_name                       173\r
+#define OBJ_name                       OBJ_X509,41L\r
+\r
+#define SN_dnQualifier                 "dnQualifier"\r
+#define LN_dnQualifier                 "dnQualifier"\r
+#define NID_dnQualifier                        174\r
+#define OBJ_dnQualifier                        OBJ_X509,46L\r
+\r
+#define SN_id_pe                       "id-pe"\r
+#define NID_id_pe                      175\r
+#define OBJ_id_pe                      OBJ_id_pkix,1L\r
+\r
+#define SN_id_ad                       "id-ad"\r
+#define NID_id_ad                      176\r
+#define OBJ_id_ad                      OBJ_id_pkix,48L\r
+\r
+#define SN_info_access                 "authorityInfoAccess"\r
+#define LN_info_access                 "Authority Information Access"\r
+#define NID_info_access                        177\r
+#define OBJ_info_access                        OBJ_id_pe,1L\r
+\r
+#define SN_ad_OCSP                     "OCSP"\r
+#define LN_ad_OCSP                     "OCSP"\r
+#define NID_ad_OCSP                    178\r
+#define OBJ_ad_OCSP                    OBJ_id_ad,1L\r
+\r
+#define SN_ad_ca_issuers               "caIssuers"\r
+#define LN_ad_ca_issuers               "CA Issuers"\r
+#define NID_ad_ca_issuers              179\r
+#define OBJ_ad_ca_issuers              OBJ_id_ad,2L\r
+\r
+#define SN_OCSP_sign                   "OCSPSigning"\r
+#define LN_OCSP_sign                   "OCSP Signing"\r
+#define NID_OCSP_sign                  180\r
+#define OBJ_OCSP_sign                  OBJ_id_kp,9L\r
+#endif /* USE_OBJ_MAC */\r
+\r
+#include <openssl/bio.h>\r
+#include <openssl/asn1.h>\r
+\r
+#define        OBJ_NAME_TYPE_UNDEF             0x00\r
+#define        OBJ_NAME_TYPE_MD_METH           0x01\r
+#define        OBJ_NAME_TYPE_CIPHER_METH       0x02\r
+#define        OBJ_NAME_TYPE_PKEY_METH         0x03\r
+#define        OBJ_NAME_TYPE_COMP_METH         0x04\r
+#define        OBJ_NAME_TYPE_NUM               0x05\r
+\r
+#define        OBJ_NAME_ALIAS                  0x8000\r
+\r
+#define OBJ_BSEARCH_VALUE_ON_NOMATCH           0x01\r
+#define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH       0x02\r
+\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct obj_name_st\r
+       {\r
+       int type;\r
+       int alias;\r
+       const char *name;\r
+       const char *data;\r
+       } OBJ_NAME;\r
+\r
+#define                OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)\r
+\r
+\r
+int OBJ_NAME_init(void);\r
+int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),\r
+                      int (*cmp_func)(const char *, const char *),\r
+                      void (*free_func)(const char *, int, const char *));\r
+const char *OBJ_NAME_get(const char *name,int type);\r
+int OBJ_NAME_add(const char *name,int type,const char *data);\r
+int OBJ_NAME_remove(const char *name,int type);\r
+void OBJ_NAME_cleanup(int type); /* -1 for everything */\r
+void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),\r
+                    void *arg);\r
+void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),\r
+                           void *arg);\r
+\r
+ASN1_OBJECT *  OBJ_dup(const ASN1_OBJECT *o);\r
+ASN1_OBJECT *  OBJ_nid2obj(int n);\r
+const char *   OBJ_nid2ln(int n);\r
+const char *   OBJ_nid2sn(int n);\r
+int            OBJ_obj2nid(const ASN1_OBJECT *o);\r
+ASN1_OBJECT *  OBJ_txt2obj(const char *s, int no_name);\r
+int    OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);\r
+int            OBJ_txt2nid(const char *s);\r
+int            OBJ_ln2nid(const char *s);\r
+int            OBJ_sn2nid(const char *s);\r
+int            OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);\r
+const char *   OBJ_bsearch(const char *key,const char *base,int num,int size,\r
+       int (*cmp)(const void *, const void *));\r
+const char *   OBJ_bsearch_ex(const char *key,const char *base,int num,\r
+       int size, int (*cmp)(const void *, const void *), int flags);\r
+\r
+int            OBJ_new_nid(int num);\r
+int            OBJ_add_object(const ASN1_OBJECT *obj);\r
+int            OBJ_create(const char *oid,const char *sn,const char *ln);\r
+void           OBJ_cleanup(void );\r
+int            OBJ_create_objects(BIO *in);\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_OBJ_strings(void);\r
+\r
+/* Error codes for the OBJ functions. */\r
+\r
+/* Function codes. */\r
+#define OBJ_F_OBJ_ADD_OBJECT                            105\r
+#define OBJ_F_OBJ_CREATE                                100\r
+#define OBJ_F_OBJ_DUP                                   101\r
+#define OBJ_F_OBJ_NAME_NEW_INDEX                        106\r
+#define OBJ_F_OBJ_NID2LN                                102\r
+#define OBJ_F_OBJ_NID2OBJ                               103\r
+#define OBJ_F_OBJ_NID2SN                                104\r
+\r
+/* Reason codes. */\r
+#define OBJ_R_MALLOC_FAILURE                            100\r
+#define OBJ_R_UNKNOWN_NID                               101\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ocsp.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ocsp.h
new file mode 100644 (file)
index 0000000..830d428
--- /dev/null
@@ -0,0 +1,614 @@
+/* ocsp.h */\r
+/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL\r
+ * project. */\r
+\r
+/* History:\r
+   This file was transfered to Richard Levitte from CertCo by Kathy\r
+   Weinhold in mid-spring 2000 to be included in OpenSSL or released\r
+   as a patch kit. */\r
+\r
+/* ====================================================================\r
+ * Copyright (c) 1998-2000 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_OCSP_H\r
+#define HEADER_OCSP_H\r
+\r
+#include <openssl/x509.h>\r
+#include <openssl/x509v3.h>\r
+#include <openssl/safestack.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Various flags and values */\r
+\r
+#define OCSP_DEFAULT_NONCE_LENGTH      16\r
+\r
+#define OCSP_NOCERTS                   0x1\r
+#define OCSP_NOINTERN                  0x2\r
+#define OCSP_NOSIGS                    0x4\r
+#define OCSP_NOCHAIN                   0x8\r
+#define OCSP_NOVERIFY                  0x10\r
+#define OCSP_NOEXPLICIT                        0x20\r
+#define OCSP_NOCASIGN                  0x40\r
+#define OCSP_NODELEGATED               0x80\r
+#define OCSP_NOCHECKS                  0x100\r
+#define OCSP_TRUSTOTHER                        0x200\r
+#define OCSP_RESPID_KEY                        0x400\r
+#define OCSP_NOTIME                    0x800\r
+\r
+/*   CertID ::= SEQUENCE {\r
+ *       hashAlgorithm            AlgorithmIdentifier,\r
+ *       issuerNameHash     OCTET STRING, -- Hash of Issuer's DN\r
+ *       issuerKeyHash      OCTET STRING, -- Hash of Issuers public key (excluding the tag & length fields)\r
+ *       serialNumber       CertificateSerialNumber }\r
+ */\r
+typedef struct ocsp_cert_id_st\r
+       {\r
+       X509_ALGOR *hashAlgorithm;\r
+       ASN1_OCTET_STRING *issuerNameHash;\r
+       ASN1_OCTET_STRING *issuerKeyHash;\r
+       ASN1_INTEGER *serialNumber;\r
+       } OCSP_CERTID;\r
+\r
+DECLARE_STACK_OF(OCSP_CERTID)\r
+\r
+/*   Request ::=     SEQUENCE {\r
+ *       reqCert                    CertID,\r
+ *       singleRequestExtensions    [0] EXPLICIT Extensions OPTIONAL }\r
+ */\r
+typedef struct ocsp_one_request_st\r
+       {\r
+       OCSP_CERTID *reqCert;\r
+       STACK_OF(X509_EXTENSION) *singleRequestExtensions;\r
+       } OCSP_ONEREQ;\r
+\r
+DECLARE_STACK_OF(OCSP_ONEREQ)\r
+DECLARE_ASN1_SET_OF(OCSP_ONEREQ)\r
+\r
+\r
+/*   TBSRequest      ::=     SEQUENCE {\r
+ *       version             [0] EXPLICIT Version DEFAULT v1,\r
+ *       requestorName       [1] EXPLICIT GeneralName OPTIONAL,\r
+ *       requestList             SEQUENCE OF Request,\r
+ *       requestExtensions   [2] EXPLICIT Extensions OPTIONAL }\r
+ */\r
+typedef struct ocsp_req_info_st\r
+       {\r
+       ASN1_INTEGER *version;\r
+       GENERAL_NAME *requestorName;\r
+       STACK_OF(OCSP_ONEREQ) *requestList;\r
+       STACK_OF(X509_EXTENSION) *requestExtensions;\r
+       } OCSP_REQINFO;\r
+\r
+/*   Signature       ::=     SEQUENCE {\r
+ *       signatureAlgorithm   AlgorithmIdentifier,\r
+ *       signature            BIT STRING,\r
+ *       certs                [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }\r
+ */\r
+typedef struct ocsp_signature_st\r
+       {\r
+       X509_ALGOR *signatureAlgorithm;\r
+       ASN1_BIT_STRING *signature;\r
+       STACK_OF(X509) *certs;\r
+       } OCSP_SIGNATURE;\r
+\r
+/*   OCSPRequest     ::=     SEQUENCE {\r
+ *       tbsRequest                  TBSRequest,\r
+ *       optionalSignature   [0]     EXPLICIT Signature OPTIONAL }\r
+ */\r
+typedef struct ocsp_request_st\r
+       {\r
+       OCSP_REQINFO *tbsRequest;\r
+       OCSP_SIGNATURE *optionalSignature; /* OPTIONAL */\r
+       } OCSP_REQUEST;\r
+\r
+/*   OCSPResponseStatus ::= ENUMERATED {\r
+ *       successful            (0),      --Response has valid confirmations\r
+ *       malformedRequest      (1),      --Illegal confirmation request\r
+ *       internalError         (2),      --Internal error in issuer\r
+ *       tryLater              (3),      --Try again later\r
+ *                                       --(4) is not used\r
+ *       sigRequired           (5),      --Must sign the request\r
+ *       unauthorized          (6)       --Request unauthorized\r
+ *   }\r
+ */\r
+#define OCSP_RESPONSE_STATUS_SUCCESSFUL          0\r
+#define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST     1\r
+#define OCSP_RESPONSE_STATUS_INTERNALERROR        2\r
+#define OCSP_RESPONSE_STATUS_TRYLATER             3\r
+#define OCSP_RESPONSE_STATUS_SIGREQUIRED          5\r
+#define OCSP_RESPONSE_STATUS_UNAUTHORIZED         6\r
+\r
+/*   ResponseBytes ::=       SEQUENCE {\r
+ *       responseType   OBJECT IDENTIFIER,\r
+ *       response       OCTET STRING }\r
+ */\r
+typedef struct ocsp_resp_bytes_st\r
+       {\r
+       ASN1_OBJECT *responseType;\r
+       ASN1_OCTET_STRING *response;\r
+       } OCSP_RESPBYTES;\r
+\r
+/*   OCSPResponse ::= SEQUENCE {\r
+ *      responseStatus         OCSPResponseStatus,\r
+ *      responseBytes          [0] EXPLICIT ResponseBytes OPTIONAL }\r
+ */\r
+typedef struct ocsp_response_st\r
+       {\r
+       ASN1_ENUMERATED *responseStatus;\r
+       OCSP_RESPBYTES  *responseBytes;\r
+       } OCSP_RESPONSE;\r
+\r
+/*   ResponderID ::= CHOICE {\r
+ *      byName   [1] Name,\r
+ *      byKey    [2] KeyHash }\r
+ */\r
+#define V_OCSP_RESPID_NAME 0\r
+#define V_OCSP_RESPID_KEY  1\r
+typedef struct ocsp_responder_id_st\r
+       {\r
+       int type;\r
+       union   {\r
+               X509_NAME* byName;\r
+               ASN1_OCTET_STRING *byKey;\r
+               } value;\r
+       } OCSP_RESPID;\r
+/*   KeyHash ::= OCTET STRING --SHA-1 hash of responder's public key\r
+ *                            --(excluding the tag and length fields)\r
+ */\r
+\r
+/*   RevokedInfo ::= SEQUENCE {\r
+ *       revocationTime              GeneralizedTime,\r
+ *       revocationReason    [0]     EXPLICIT CRLReason OPTIONAL }\r
+ */\r
+typedef struct ocsp_revoked_info_st\r
+       {\r
+       ASN1_GENERALIZEDTIME *revocationTime;\r
+       ASN1_ENUMERATED *revocationReason;\r
+       } OCSP_REVOKEDINFO;\r
+\r
+/*   CertStatus ::= CHOICE {\r
+ *       good                [0]     IMPLICIT NULL,\r
+ *       revoked             [1]     IMPLICIT RevokedInfo,\r
+ *       unknown             [2]     IMPLICIT UnknownInfo }\r
+ */\r
+#define V_OCSP_CERTSTATUS_GOOD    0\r
+#define V_OCSP_CERTSTATUS_REVOKED 1\r
+#define V_OCSP_CERTSTATUS_UNKNOWN 2\r
+typedef struct ocsp_cert_status_st\r
+       {\r
+       int type;\r
+       union   {\r
+               ASN1_NULL *good;\r
+               OCSP_REVOKEDINFO *revoked;\r
+               ASN1_NULL *unknown;\r
+               } value;\r
+       } OCSP_CERTSTATUS;\r
+\r
+/*   SingleResponse ::= SEQUENCE {\r
+ *      certID                       CertID,\r
+ *      certStatus                   CertStatus,\r
+ *      thisUpdate                   GeneralizedTime,\r
+ *      nextUpdate           [0]     EXPLICIT GeneralizedTime OPTIONAL,\r
+ *      singleExtensions     [1]     EXPLICIT Extensions OPTIONAL }\r
+ */\r
+typedef struct ocsp_single_response_st\r
+       {\r
+       OCSP_CERTID *certId;\r
+       OCSP_CERTSTATUS *certStatus;\r
+       ASN1_GENERALIZEDTIME *thisUpdate;\r
+       ASN1_GENERALIZEDTIME *nextUpdate;\r
+       STACK_OF(X509_EXTENSION) *singleExtensions;\r
+       } OCSP_SINGLERESP;\r
+\r
+DECLARE_STACK_OF(OCSP_SINGLERESP)\r
+DECLARE_ASN1_SET_OF(OCSP_SINGLERESP)\r
+\r
+/*   ResponseData ::= SEQUENCE {\r
+ *      version              [0] EXPLICIT Version DEFAULT v1,\r
+ *      responderID              ResponderID,\r
+ *      producedAt               GeneralizedTime,\r
+ *      responses                SEQUENCE OF SingleResponse,\r
+ *      responseExtensions   [1] EXPLICIT Extensions OPTIONAL }\r
+ */\r
+typedef struct ocsp_response_data_st\r
+       {\r
+       ASN1_INTEGER *version;\r
+       OCSP_RESPID  *responderId;\r
+       ASN1_GENERALIZEDTIME *producedAt;\r
+       STACK_OF(OCSP_SINGLERESP) *responses;\r
+       STACK_OF(X509_EXTENSION) *responseExtensions;\r
+       } OCSP_RESPDATA;\r
+\r
+/*   BasicOCSPResponse       ::= SEQUENCE {\r
+ *      tbsResponseData      ResponseData,\r
+ *      signatureAlgorithm   AlgorithmIdentifier,\r
+ *      signature            BIT STRING,\r
+ *      certs                [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }\r
+ */\r
+  /* Note 1:\r
+     The value for "signature" is specified in the OCSP rfc2560 as follows:\r
+     "The value for the signature SHALL be computed on the hash of the DER\r
+     encoding ResponseData."  This means that you must hash the DER-encoded\r
+     tbsResponseData, and then run it through a crypto-signing function, which\r
+     will (at least w/RSA) do a hash-'n'-private-encrypt operation.  This seems\r
+     a bit odd, but that's the spec.  Also note that the data structures do not\r
+     leave anywhere to independently specify the algorithm used for the initial\r
+     hash. So, we look at the signature-specification algorithm, and try to do\r
+     something intelligent.    -- Kathy Weinhold, CertCo */\r
+  /* Note 2:\r
+     It seems that the mentioned passage from RFC 2560 (section 4.2.1) is open\r
+     for interpretation.  I've done tests against another responder, and found\r
+     that it doesn't do the double hashing that the RFC seems to say one\r
+     should.  Therefore, all relevant functions take a flag saying which\r
+     variant should be used.   -- Richard Levitte, OpenSSL team and CeloCom */\r
+typedef struct ocsp_basic_response_st\r
+       {\r
+       OCSP_RESPDATA *tbsResponseData;\r
+       X509_ALGOR *signatureAlgorithm;\r
+       ASN1_BIT_STRING *signature;\r
+       STACK_OF(X509) *certs;\r
+       } OCSP_BASICRESP;\r
+\r
+/*\r
+ *   CRLReason ::= ENUMERATED {\r
+ *        unspecified             (0),\r
+ *        keyCompromise           (1),\r
+ *        cACompromise            (2),\r
+ *        affiliationChanged      (3),\r
+ *        superseded              (4),\r
+ *        cessationOfOperation    (5),\r
+ *        certificateHold         (6),\r
+ *        removeFromCRL           (8) }\r
+ */\r
+#define OCSP_REVOKED_STATUS_NOSTATUS               -1\r
+#define OCSP_REVOKED_STATUS_UNSPECIFIED             0\r
+#define OCSP_REVOKED_STATUS_KEYCOMPROMISE           1\r
+#define OCSP_REVOKED_STATUS_CACOMPROMISE            2\r
+#define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED      3\r
+#define OCSP_REVOKED_STATUS_SUPERSEDED              4\r
+#define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION    5\r
+#define OCSP_REVOKED_STATUS_CERTIFICATEHOLD         6\r
+#define OCSP_REVOKED_STATUS_REMOVEFROMCRL           8\r
+\r
+/* CrlID ::= SEQUENCE {\r
+ *     crlUrl               [0]     EXPLICIT IA5String OPTIONAL,\r
+ *     crlNum               [1]     EXPLICIT INTEGER OPTIONAL,\r
+ *     crlTime              [2]     EXPLICIT GeneralizedTime OPTIONAL }\r
+ */\r
+typedef struct ocsp_crl_id_st\r
+        {\r
+       ASN1_IA5STRING *crlUrl;\r
+       ASN1_INTEGER *crlNum;\r
+       ASN1_GENERALIZEDTIME *crlTime;\r
+        } OCSP_CRLID;\r
+\r
+/* ServiceLocator ::= SEQUENCE {\r
+ *      issuer    Name,\r
+ *      locator   AuthorityInfoAccessSyntax OPTIONAL }\r
+ */\r
+typedef struct ocsp_service_locator_st\r
+        {\r
+       X509_NAME* issuer;\r
+       STACK_OF(ACCESS_DESCRIPTION) *locator;\r
+        } OCSP_SERVICELOC;\r
\r
+#define PEM_STRING_OCSP_REQUEST        "OCSP REQUEST"\r
+#define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE"\r
+\r
+#define d2i_OCSP_REQUEST_bio(bp,p) ASN1_d2i_bio_of(OCSP_REQUEST,OCSP_REQUEST_new,d2i_OCSP_REQUEST,bp,p)\r
+\r
+#define d2i_OCSP_RESPONSE_bio(bp,p) ASN1_d2i_bio_of(OCSP_RESPONSE,OCSP_RESPONSE_new,d2i_OCSP_RESPONSE,bp,p)\r
+\r
+#define        PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \\r
+     (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,bp,(char **)x,cb,NULL)\r
+\r
+#define        PEM_read_bio_OCSP_RESPONSE(bp,x,cb)(OCSP_RESPONSE *)PEM_ASN1_read_bio(\\r
+     (char *(*)())d2i_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,bp,(char **)x,cb,NULL)\r
+\r
+#define PEM_write_bio_OCSP_REQUEST(bp,o) \\r
+    PEM_ASN1_write_bio((int (*)())i2d_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,\\r
+                       bp,(char *)o, NULL,NULL,0,NULL,NULL)\r
+\r
+#define PEM_write_bio_OCSP_RESPONSE(bp,o) \\r
+    PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\\r
+                       bp,(char *)o, NULL,NULL,0,NULL,NULL)\r
+\r
+#define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio_of(OCSP_RESPONSE,i2d_OCSP_RESPONSE,bp,o)\r
+\r
+#define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio_of(OCSP_REQUEST,i2d_OCSP_REQUEST,bp,o)\r
+\r
+#define OCSP_REQUEST_sign(o,pkey,md) \\r
+       ASN1_item_sign(ASN1_ITEM_rptr(OCSP_REQINFO),\\r
+               o->optionalSignature->signatureAlgorithm,NULL,\\r
+               o->optionalSignature->signature,o->tbsRequest,pkey,md)\r
+\r
+#define OCSP_BASICRESP_sign(o,pkey,md,d) \\r
+       ASN1_item_sign(ASN1_ITEM_rptr(OCSP_RESPDATA),o->signatureAlgorithm,NULL,\\r
+               o->signature,o->tbsResponseData,pkey,md)\r
+\r
+#define OCSP_REQUEST_verify(a,r) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_REQINFO),\\r
+        a->optionalSignature->signatureAlgorithm,\\r
+       a->optionalSignature->signature,a->tbsRequest,r)\r
+\r
+#define OCSP_BASICRESP_verify(a,r,d) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_RESPDATA),\\r
+       a->signatureAlgorithm,a->signature,a->tbsResponseData,r)\r
+\r
+#define ASN1_BIT_STRING_digest(data,type,md,len) \\r
+       ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len)\r
+\r
+#define OCSP_CERTID_dup(cid) ASN1_dup_of(OCSP_CERTID,i2d_OCSP_CERTID,d2i_OCSP_CERTID,cid)\r
+\r
+#define OCSP_CERTSTATUS_dup(cs)\\r
+                (OCSP_CERTSTATUS*)ASN1_dup((int(*)())i2d_OCSP_CERTSTATUS,\\r
+               (char *(*)())d2i_OCSP_CERTSTATUS,(char *)(cs))\r
+\r
+OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req);\r
+\r
+OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, X509 *subject, X509 *issuer);\r
+\r
+OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst, \r
+                             X509_NAME *issuerName, \r
+                             ASN1_BIT_STRING* issuerKey, \r
+                             ASN1_INTEGER *serialNumber);\r
+\r
+OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid);\r
+\r
+int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len);\r
+int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len);\r
+int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs);\r
+int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req);\r
+\r
+int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm);\r
+int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert);\r
+\r
+int OCSP_request_sign(OCSP_REQUEST   *req,\r
+                     X509           *signer,\r
+                     EVP_PKEY       *key,\r
+                     const EVP_MD   *dgst,\r
+                     STACK_OF(X509) *certs,\r
+                     unsigned long flags);\r
+\r
+int OCSP_response_status(OCSP_RESPONSE *resp);\r
+OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp);\r
+\r
+int OCSP_resp_count(OCSP_BASICRESP *bs);\r
+OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx);\r
+int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last);\r
+int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,\r
+                               ASN1_GENERALIZEDTIME **revtime,\r
+                               ASN1_GENERALIZEDTIME **thisupd,\r
+                               ASN1_GENERALIZEDTIME **nextupd);\r
+int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,\r
+                               int *reason,\r
+                               ASN1_GENERALIZEDTIME **revtime,\r
+                               ASN1_GENERALIZEDTIME **thisupd,\r
+                               ASN1_GENERALIZEDTIME **nextupd);\r
+int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,\r
+                       ASN1_GENERALIZEDTIME *nextupd,\r
+                       long sec, long maxsec);\r
+\r
+int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store, unsigned long flags);\r
+\r
+int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pssl);\r
+\r
+int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b);\r
+int OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b);\r
+\r
+int OCSP_request_onereq_count(OCSP_REQUEST *req);\r
+OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i);\r
+OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one);\r
+int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd,\r
+                       ASN1_OCTET_STRING **pikeyHash,\r
+                       ASN1_INTEGER **pserial, OCSP_CERTID *cid);\r
+int OCSP_request_is_signed(OCSP_REQUEST *req);\r
+OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs);\r
+OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp,\r
+                                               OCSP_CERTID *cid,\r
+                                               int status, int reason,\r
+                                               ASN1_TIME *revtime,\r
+                                       ASN1_TIME *thisupd, ASN1_TIME *nextupd);\r
+int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert);\r
+int OCSP_basic_sign(OCSP_BASICRESP *brsp, \r
+                       X509 *signer, EVP_PKEY *key, const EVP_MD *dgst,\r
+                       STACK_OF(X509) *certs, unsigned long flags);\r
+\r
+ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, i2d_of_void *i2d,\r
+                               void *data, STACK_OF(ASN1_OBJECT) *sk);\r
+#define ASN1_STRING_encode_of(type,s,i2d,data,sk) \\r
+((ASN1_STRING *(*)(ASN1_STRING *,I2D_OF(type),type *,STACK_OF(ASN1_OBJECT) *))openssl_fcast(ASN1_STRING_encode))(s,i2d,data,sk)\r
+\r
+X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim);\r
+\r
+X509_EXTENSION *OCSP_accept_responses_new(char **oids);\r
+\r
+X509_EXTENSION *OCSP_archive_cutoff_new(char* tim);\r
+\r
+X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls);\r
+\r
+int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x);\r
+int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos);\r
+int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, ASN1_OBJECT *obj, int lastpos);\r
+int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos);\r
+X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc);\r
+X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc);\r
+void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx);\r
+int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit,\r
+                                                       unsigned long flags);\r
+int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc);\r
+\r
+int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x);\r
+int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos);\r
+int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, ASN1_OBJECT *obj, int lastpos);\r
+int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos);\r
+X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc);\r
+X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc);\r
+void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx);\r
+int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit,\r
+                                                       unsigned long flags);\r
+int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc);\r
+\r
+int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x);\r
+int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos);\r
+int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, ASN1_OBJECT *obj, int lastpos);\r
+int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, int lastpos);\r
+X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc);\r
+X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc);\r
+void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, int *idx);\r
+int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, int crit,\r
+                                                       unsigned long flags);\r
+int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc);\r
+\r
+int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x);\r
+int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos);\r
+int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, ASN1_OBJECT *obj, int lastpos);\r
+int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, int lastpos);\r
+X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc);\r
+X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc);\r
+void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, int *idx);\r
+int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, int crit,\r
+                                                       unsigned long flags);\r
+int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc);\r
+\r
+DECLARE_ASN1_FUNCTIONS(OCSP_SINGLERESP)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_CERTSTATUS)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_REVOKEDINFO)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_BASICRESP)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_RESPDATA)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_RESPID)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_RESPONSE)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_RESPBYTES)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_ONEREQ)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_CERTID)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_REQUEST)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_SIGNATURE)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_REQINFO)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_CRLID)\r
+DECLARE_ASN1_FUNCTIONS(OCSP_SERVICELOC)\r
+\r
+char *OCSP_response_status_str(long s);\r
+char *OCSP_cert_status_str(long s);\r
+char *OCSP_crl_reason_str(long s);\r
+\r
+int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* a, unsigned long flags);\r
+int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags);\r
+\r
+int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs,\r
+                               X509_STORE *st, unsigned long flags);\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_OCSP_strings(void);\r
+\r
+/* Error codes for the OCSP functions. */\r
+\r
+/* Function codes. */\r
+#define OCSP_F_ASN1_STRING_ENCODE                       100\r
+#define OCSP_F_D2I_OCSP_NONCE                           102\r
+#define OCSP_F_OCSP_BASIC_ADD1_STATUS                   103\r
+#define OCSP_F_OCSP_BASIC_SIGN                          104\r
+#define OCSP_F_OCSP_BASIC_VERIFY                        105\r
+#define OCSP_F_OCSP_CERT_ID_NEW                                 101\r
+#define OCSP_F_OCSP_CHECK_DELEGATED                     106\r
+#define OCSP_F_OCSP_CHECK_IDS                           107\r
+#define OCSP_F_OCSP_CHECK_ISSUER                        108\r
+#define OCSP_F_OCSP_CHECK_VALIDITY                      115\r
+#define OCSP_F_OCSP_MATCH_ISSUERID                      109\r
+#define OCSP_F_OCSP_PARSE_URL                           114\r
+#define OCSP_F_OCSP_REQUEST_SIGN                        110\r
+#define OCSP_F_OCSP_REQUEST_VERIFY                      116\r
+#define OCSP_F_OCSP_RESPONSE_GET1_BASIC                         111\r
+#define OCSP_F_OCSP_SENDREQ_BIO                                 112\r
+#define OCSP_F_REQUEST_VERIFY                           113\r
+\r
+/* Reason codes. */\r
+#define OCSP_R_BAD_DATA                                         100\r
+#define OCSP_R_CERTIFICATE_VERIFY_ERROR                         101\r
+#define OCSP_R_DIGEST_ERR                               102\r
+#define OCSP_R_ERROR_IN_NEXTUPDATE_FIELD                122\r
+#define OCSP_R_ERROR_IN_THISUPDATE_FIELD                123\r
+#define OCSP_R_ERROR_PARSING_URL                        121\r
+#define OCSP_R_MISSING_OCSPSIGNING_USAGE                103\r
+#define OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE             124\r
+#define OCSP_R_NOT_BASIC_RESPONSE                       104\r
+#define OCSP_R_NO_CERTIFICATES_IN_CHAIN                         105\r
+#define OCSP_R_NO_CONTENT                               106\r
+#define OCSP_R_NO_PUBLIC_KEY                            107\r
+#define OCSP_R_NO_RESPONSE_DATA                                 108\r
+#define OCSP_R_NO_REVOKED_TIME                          109\r
+#define OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE   110\r
+#define OCSP_R_REQUEST_NOT_SIGNED                       128\r
+#define OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA     111\r
+#define OCSP_R_ROOT_CA_NOT_TRUSTED                      112\r
+#define OCSP_R_SERVER_READ_ERROR                        113\r
+#define OCSP_R_SERVER_RESPONSE_ERROR                    114\r
+#define OCSP_R_SERVER_RESPONSE_PARSE_ERROR              115\r
+#define OCSP_R_SERVER_WRITE_ERROR                       116\r
+#define OCSP_R_SIGNATURE_FAILURE                        117\r
+#define OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND             118\r
+#define OCSP_R_STATUS_EXPIRED                           125\r
+#define OCSP_R_STATUS_NOT_YET_VALID                     126\r
+#define OCSP_R_STATUS_TOO_OLD                           127\r
+#define OCSP_R_UNKNOWN_MESSAGE_DIGEST                   119\r
+#define OCSP_R_UNKNOWN_NID                              120\r
+#define OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE           129\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/opensslconf.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/opensslconf.h
new file mode 100644 (file)
index 0000000..15f785f
--- /dev/null
@@ -0,0 +1,202 @@
+/* opensslconf.h */\r
+/* WARNING: Generated automatically from opensslconf.h.in by Configure. */\r
+\r
+/* OpenSSL was configured with the following options: */\r
+#ifndef OPENSSL_DOING_MAKEDEPEND\r
+\r
+#ifndef OPENSSL_NO_GMP\r
+# define OPENSSL_NO_GMP\r
+#endif\r
+#ifndef OPENSSL_NO_KRB5\r
+# define OPENSSL_NO_KRB5\r
+#endif\r
+#ifndef OPENSSL_NO_MDC2\r
+# define OPENSSL_NO_MDC2\r
+#endif\r
+#ifndef OPENSSL_NO_RC5\r
+# define OPENSSL_NO_RC5\r
+#endif\r
+\r
+#endif /* OPENSSL_DOING_MAKEDEPEND */\r
+#ifndef OPENSSL_NO_DYNAMIC_ENGINE\r
+# define OPENSSL_NO_DYNAMIC_ENGINE\r
+#endif\r
+\r
+/* The OPENSSL_NO_* macros are also defined as NO_* if the application\r
+   asks for it.  This is a transient feature that is provided for those\r
+   who haven't had the time to do the appropriate changes in their\r
+   applications.  */\r
+#ifdef OPENSSL_ALGORITHM_DEFINES\r
+# if defined(OPENSSL_NO_GMP) && !defined(NO_GMP)\r
+#  define NO_GMP\r
+# endif\r
+# if defined(OPENSSL_NO_KRB5) && !defined(NO_KRB5)\r
+#  define NO_KRB5\r
+# endif\r
+# if defined(OPENSSL_NO_MDC2) && !defined(NO_MDC2)\r
+#  define NO_MDC2\r
+# endif\r
+# if defined(OPENSSL_NO_RC5) && !defined(NO_RC5)\r
+#  define NO_RC5\r
+# endif\r
+#endif\r
+\r
+/* crypto/opensslconf.h.in */\r
+\r
+/* Generate 80386 code? */\r
+#undef I386_ONLY\r
+\r
+#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */\r
+#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)\r
+#define ENGINESDIR "/usr/local/ssl/lib/engines"\r
+#define OPENSSLDIR "/usr/local/ssl"\r
+#endif\r
+#endif\r
+\r
+#undef OPENSSL_UNISTD\r
+#define OPENSSL_UNISTD <unistd.h>\r
+\r
+#undef OPENSSL_EXPORT_VAR_AS_FUNCTION\r
+\r
+#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)\r
+#define IDEA_INT unsigned int\r
+#endif\r
+\r
+#if defined(HEADER_MD2_H) && !defined(MD2_INT)\r
+#define MD2_INT unsigned int\r
+#endif\r
+\r
+#if defined(HEADER_RC2_H) && !defined(RC2_INT)\r
+/* I need to put in a mod for the alpha - eay */\r
+#define RC2_INT unsigned int\r
+#endif\r
+\r
+#if defined(HEADER_RC4_H)\r
+#if !defined(RC4_INT)\r
+/* using int types make the structure larger but make the code faster\r
+ * on most boxes I have tested - up to %20 faster. */\r
+/*\r
+ * I don't know what does "most" mean, but declaring "int" is a must on:\r
+ * - Intel P6 because partial register stalls are very expensive;\r
+ * - elder Alpha because it lacks byte load/store instructions;\r
+ */\r
+#define RC4_INT unsigned int\r
+#endif\r
+#if !defined(RC4_CHUNK)\r
+/*\r
+ * This enables code handling data aligned at natural CPU word\r
+ * boundary. See crypto/rc4/rc4_enc.c for further details.\r
+ */\r
+#undef RC4_CHUNK\r
+#endif\r
+#endif\r
+\r
+#if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG)\r
+/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a\r
+ * %20 speed up (longs are 8 bytes, int's are 4). */\r
+#ifndef DES_LONG\r
+#define DES_LONG unsigned long\r
+#endif\r
+#endif\r
+\r
+#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)\r
+#define CONFIG_HEADER_BN_H\r
+#undef BN_LLONG\r
+\r
+/* Should we define BN_DIV2W here? */\r
+\r
+/* Only one for the following should be defined */\r
+/* The prime number generation stuff may not work when\r
+ * EIGHT_BIT but I don't care since I've only used this mode\r
+ * for debuging the bignum libraries */\r
+#undef SIXTY_FOUR_BIT_LONG\r
+#undef SIXTY_FOUR_BIT\r
+#define THIRTY_TWO_BIT\r
+#undef SIXTEEN_BIT\r
+#undef EIGHT_BIT\r
+#endif\r
+\r
+#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)\r
+#define CONFIG_HEADER_RC4_LOCL_H\r
+/* if this is defined data[i] is used instead of *data, this is a %20\r
+ * speedup on x86 */\r
+#undef RC4_INDEX\r
+#endif\r
+\r
+#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)\r
+#define CONFIG_HEADER_BF_LOCL_H\r
+#undef BF_PTR\r
+#endif /* HEADER_BF_LOCL_H */\r
+\r
+#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)\r
+#define CONFIG_HEADER_DES_LOCL_H\r
+#ifndef DES_DEFAULT_OPTIONS\r
+/* the following is tweaked from a config script, that is why it is a\r
+ * protected undef/define */\r
+#ifndef DES_PTR\r
+#undef DES_PTR\r
+#endif\r
+\r
+/* This helps C compiler generate the correct code for multiple functional\r
+ * units.  It reduces register dependancies at the expense of 2 more\r
+ * registers */\r
+#ifndef DES_RISC1\r
+#undef DES_RISC1\r
+#endif\r
+\r
+#ifndef DES_RISC2\r
+#undef DES_RISC2\r
+#endif\r
+\r
+#if defined(DES_RISC1) && defined(DES_RISC2)\r
+YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!\r
+#endif\r
+\r
+/* Unroll the inner loop, this sometimes helps, sometimes hinders.\r
+ * Very mucy CPU dependant */\r
+#ifndef DES_UNROLL\r
+#undef DES_UNROLL\r
+#endif\r
+\r
+/* These default values were supplied by\r
+ * Peter Gutman <pgut001@cs.auckland.ac.nz>\r
+ * They are only used if nothing else has been defined */\r
+#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)\r
+/* Special defines which change the way the code is built depending on the\r
+   CPU and OS.  For SGI machines you can use _MIPS_SZLONG (32 or 64) to find\r
+   even newer MIPS CPU's, but at the moment one size fits all for\r
+   optimization options.  Older Sparc's work better with only UNROLL, but\r
+   there's no way to tell at compile time what it is you're running on */\r
\r
+#if defined( sun )             /* Newer Sparc's */\r
+#  define DES_PTR\r
+#  define DES_RISC1\r
+#  define DES_UNROLL\r
+#elif defined( __ultrix )      /* Older MIPS */\r
+#  define DES_PTR\r
+#  define DES_RISC2\r
+#  define DES_UNROLL\r
+#elif defined( __osf1__ )      /* Alpha */\r
+#  define DES_PTR\r
+#  define DES_RISC2\r
+#elif defined ( _AIX )         /* RS6000 */\r
+  /* Unknown */\r
+#elif defined( __hpux )                /* HP-PA */\r
+  /* Unknown */\r
+#elif defined( __aux )         /* 68K */\r
+  /* Unknown */\r
+#elif defined( __dgux )                /* 88K (but P6 in latest boxes) */\r
+#  define DES_UNROLL\r
+#elif defined( __sgi )         /* Newer MIPS */\r
+#  define DES_PTR\r
+#  define DES_RISC2\r
+#  define DES_UNROLL\r
+#elif defined(i386) || defined(__i386__)       /* x86 boxes, should be gcc */\r
+#  define DES_PTR\r
+#  define DES_RISC1\r
+#  define DES_UNROLL\r
+#endif /* Systems-specific speed defines */\r
+#endif\r
+\r
+#endif /* DES_DEFAULT_OPTIONS */\r
+#endif /* HEADER_DES_LOCL_H */\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/opensslv.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/opensslv.h
new file mode 100644 (file)
index 0000000..69aeeee
--- /dev/null
@@ -0,0 +1,89 @@
+#ifndef HEADER_OPENSSLV_H\r
+#define HEADER_OPENSSLV_H\r
+\r
+/* Numeric release version identifier:\r
+ * MNNFFPPS: major minor fix patch status\r
+ * The status nibble has one of the values 0 for development, 1 to e for betas\r
+ * 1 to 14, and f for release.  The patch level is exactly that.\r
+ * For example:\r
+ * 0.9.3-dev     0x00903000\r
+ * 0.9.3-beta1   0x00903001\r
+ * 0.9.3-beta2-dev 0x00903002\r
+ * 0.9.3-beta2    0x00903002 (same as ...beta2-dev)\r
+ * 0.9.3         0x0090300f\r
+ * 0.9.3a        0x0090301f\r
+ * 0.9.4         0x0090400f\r
+ * 1.2.3z        0x102031af\r
+ *\r
+ * For continuity reasons (because 0.9.5 is already out, and is coded\r
+ * 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level\r
+ * part is slightly different, by setting the highest bit.  This means\r
+ * that 0.9.5a looks like this: 0x0090581f.  At 0.9.6, we can start\r
+ * with 0x0090600S...\r
+ *\r
+ * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.)\r
+ * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for\r
+ *  major minor fix final patch/beta)\r
+ */\r
+#define OPENSSL_VERSION_NUMBER 0x0090800fL\r
+#ifdef OPENSSL_FIPS\r
+#define OPENSSL_VERSION_TEXT   "OpenSSL 0.9.8-fips 05 Jul 2005"\r
+#else\r
+#define OPENSSL_VERSION_TEXT   "OpenSSL 0.9.8 05 Jul 2005"\r
+#endif\r
+#define OPENSSL_VERSION_PTEXT  " part of " OPENSSL_VERSION_TEXT\r
+\r
+\r
+/* The macros below are to be used for shared library (.so, .dll, ...)\r
+ * versioning.  That kind of versioning works a bit differently between\r
+ * operating systems.  The most usual scheme is to set a major and a minor\r
+ * number, and have the runtime loader check that the major number is equal\r
+ * to what it was at application link time, while the minor number has to\r
+ * be greater or equal to what it was at application link time.  With this\r
+ * scheme, the version number is usually part of the file name, like this:\r
+ *\r
+ *     libcrypto.so.0.9\r
+ *\r
+ * Some unixen also make a softlink with the major verson number only:\r
+ *\r
+ *     libcrypto.so.0\r
+ *\r
+ * On Tru64 and IRIX 6.x it works a little bit differently.  There, the\r
+ * shared library version is stored in the file, and is actually a series\r
+ * of versions, separated by colons.  The rightmost version present in the\r
+ * library when linking an application is stored in the application to be\r
+ * matched at run time.  When the application is run, a check is done to\r
+ * see if the library version stored in the application matches any of the\r
+ * versions in the version string of the library itself.\r
+ * This version string can be constructed in any way, depending on what\r
+ * kind of matching is desired.  However, to implement the same scheme as\r
+ * the one used in the other unixen, all compatible versions, from lowest\r
+ * to highest, should be part of the string.  Consecutive builds would\r
+ * give the following versions strings:\r
+ *\r
+ *     3.0\r
+ *     3.0:3.1\r
+ *     3.0:3.1:3.2\r
+ *     4.0\r
+ *     4.0:4.1\r
+ *\r
+ * Notice how version 4 is completely incompatible with version, and\r
+ * therefore give the breach you can see.\r
+ *\r
+ * There may be other schemes as well that I haven't yet discovered.\r
+ *\r
+ * So, here's the way it works here: first of all, the library version\r
+ * number doesn't need at all to match the overall OpenSSL version.\r
+ * However, it's nice and more understandable if it actually does.\r
+ * The current library version is stored in the macro SHLIB_VERSION_NUMBER,\r
+ * which is just a piece of text in the format "M.m.e" (Major, minor, edit).\r
+ * For the sake of Tru64, IRIX, and any other OS that behaves in similar ways,\r
+ * we need to keep a history of version numbers, which is done in the\r
+ * macro SHLIB_VERSION_HISTORY.  The numbers are separated by colons and\r
+ * should only keep the versions that are binary compatible with the current.\r
+ */\r
+#define SHLIB_VERSION_HISTORY ""\r
+#define SHLIB_VERSION_NUMBER "0.9.8"\r
+\r
+\r
+#endif /* HEADER_OPENSSLV_H */\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ossl_typ.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ossl_typ.h
new file mode 100644 (file)
index 0000000..9115bcc
--- /dev/null
@@ -0,0 +1,174 @@
+/* ====================================================================\r
+ * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_OPENSSL_TYPES_H\r
+#define HEADER_OPENSSL_TYPES_H\r
+\r
+#include <openssl/e_os2.h>\r
+\r
+#ifdef NO_ASN1_TYPEDEFS\r
+#define ASN1_INTEGER           ASN1_STRING\r
+#define ASN1_ENUMERATED                ASN1_STRING\r
+#define ASN1_BIT_STRING                ASN1_STRING\r
+#define ASN1_OCTET_STRING      ASN1_STRING\r
+#define ASN1_PRINTABLESTRING   ASN1_STRING\r
+#define ASN1_T61STRING         ASN1_STRING\r
+#define ASN1_IA5STRING         ASN1_STRING\r
+#define ASN1_UTCTIME           ASN1_STRING\r
+#define ASN1_GENERALIZEDTIME   ASN1_STRING\r
+#define ASN1_TIME              ASN1_STRING\r
+#define ASN1_GENERALSTRING     ASN1_STRING\r
+#define ASN1_UNIVERSALSTRING   ASN1_STRING\r
+#define ASN1_BMPSTRING         ASN1_STRING\r
+#define ASN1_VISIBLESTRING     ASN1_STRING\r
+#define ASN1_UTF8STRING                ASN1_STRING\r
+#define ASN1_BOOLEAN           int\r
+#define ASN1_NULL              int\r
+#else\r
+typedef struct asn1_string_st ASN1_INTEGER;\r
+typedef struct asn1_string_st ASN1_ENUMERATED;\r
+typedef struct asn1_string_st ASN1_BIT_STRING;\r
+typedef struct asn1_string_st ASN1_OCTET_STRING;\r
+typedef struct asn1_string_st ASN1_PRINTABLESTRING;\r
+typedef struct asn1_string_st ASN1_T61STRING;\r
+typedef struct asn1_string_st ASN1_IA5STRING;\r
+typedef struct asn1_string_st ASN1_GENERALSTRING;\r
+typedef struct asn1_string_st ASN1_UNIVERSALSTRING;\r
+typedef struct asn1_string_st ASN1_BMPSTRING;\r
+typedef struct asn1_string_st ASN1_UTCTIME;\r
+typedef struct asn1_string_st ASN1_TIME;\r
+typedef struct asn1_string_st ASN1_GENERALIZEDTIME;\r
+typedef struct asn1_string_st ASN1_VISIBLESTRING;\r
+typedef struct asn1_string_st ASN1_UTF8STRING;\r
+typedef int ASN1_BOOLEAN;\r
+typedef int ASN1_NULL;\r
+#endif\r
+\r
+#ifdef OPENSSL_SYS_WIN32\r
+#undef X509_NAME\r
+#undef X509_CERT_PAIR\r
+#undef PKCS7_ISSUER_AND_SERIAL\r
+#endif\r
+\r
+#ifdef BIGNUM\r
+#undef BIGNUM\r
+#endif\r
+typedef struct bignum_st BIGNUM;\r
+typedef struct bignum_ctx BN_CTX;\r
+typedef struct bn_blinding_st BN_BLINDING;\r
+typedef struct bn_mont_ctx_st BN_MONT_CTX;\r
+typedef struct bn_recp_ctx_st BN_RECP_CTX;\r
+typedef struct bn_gencb_st BN_GENCB;\r
+\r
+typedef struct buf_mem_st BUF_MEM;\r
+\r
+typedef struct evp_cipher_st EVP_CIPHER;\r
+typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;\r
+typedef struct env_md_st EVP_MD;\r
+typedef struct env_md_ctx_st EVP_MD_CTX;\r
+typedef struct evp_pkey_st EVP_PKEY;\r
+\r
+typedef struct dh_st DH;\r
+typedef struct dh_method DH_METHOD;\r
+\r
+typedef struct dsa_st DSA;\r
+typedef struct dsa_method DSA_METHOD;\r
+\r
+typedef struct rsa_st RSA;\r
+typedef struct rsa_meth_st RSA_METHOD;\r
+\r
+typedef struct rand_meth_st RAND_METHOD;\r
+\r
+typedef struct ecdh_method ECDH_METHOD;\r
+typedef struct ecdsa_method ECDSA_METHOD;\r
+\r
+typedef struct x509_st X509;\r
+typedef struct X509_algor_st X509_ALGOR;\r
+typedef struct X509_crl_st X509_CRL;\r
+typedef struct X509_name_st X509_NAME;\r
+typedef struct x509_store_st X509_STORE;\r
+typedef struct x509_store_ctx_st X509_STORE_CTX;\r
+\r
+typedef struct v3_ext_ctx X509V3_CTX;\r
+typedef struct conf_st CONF;\r
+\r
+typedef struct store_st STORE;\r
+typedef struct store_method_st STORE_METHOD;\r
+\r
+typedef struct ui_st UI;\r
+typedef struct ui_method_st UI_METHOD;\r
+\r
+typedef struct st_ERR_FNS ERR_FNS;\r
+\r
+typedef struct engine_st ENGINE;\r
+\r
+typedef struct X509_POLICY_NODE_st X509_POLICY_NODE;\r
+typedef struct X509_POLICY_LEVEL_st X509_POLICY_LEVEL;\r
+typedef struct X509_POLICY_TREE_st X509_POLICY_TREE;\r
+typedef struct X509_POLICY_CACHE_st X509_POLICY_CACHE;\r
+\r
+  /* If placed in pkcs12.h, we end up with a circular depency with pkcs7.h */\r
+#define DECLARE_PKCS12_STACK_OF(type) /* Nothing */\r
+#define IMPLEMENT_PKCS12_STACK_OF(type) /* Nothing */\r
+\r
+typedef struct crypto_ex_data_st CRYPTO_EX_DATA;\r
+/* Callback types for crypto.h */\r
+typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad,\r
+                                       int idx, long argl, void *argp);\r
+typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad,\r
+                                       int idx, long argl, void *argp);\r
+typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d, \r
+                                       int idx, long argl, void *argp);\r
+\r
+#endif /* def HEADER_OPENSSL_TYPES_H */\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pem.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pem.h
new file mode 100644 (file)
index 0000000..43af416
--- /dev/null
@@ -0,0 +1,737 @@
+/* crypto/pem/pem.h */\r
+/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_PEM_H\r
+#define HEADER_PEM_H\r
+\r
+#include <openssl/e_os2.h>\r
+#ifndef OPENSSL_NO_BIO\r
+#include <openssl/bio.h>\r
+#endif\r
+#ifndef OPENSSL_NO_STACK\r
+#include <openssl/stack.h>\r
+#endif\r
+#include <openssl/evp.h>\r
+#include <openssl/x509.h>\r
+#include <openssl/pem2.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define PEM_BUFSIZE            1024\r
+\r
+#define PEM_OBJ_UNDEF          0\r
+#define PEM_OBJ_X509           1\r
+#define PEM_OBJ_X509_REQ       2\r
+#define PEM_OBJ_CRL            3\r
+#define PEM_OBJ_SSL_SESSION    4\r
+#define PEM_OBJ_PRIV_KEY       10\r
+#define PEM_OBJ_PRIV_RSA       11\r
+#define PEM_OBJ_PRIV_DSA       12\r
+#define PEM_OBJ_PRIV_DH                13\r
+#define PEM_OBJ_PUB_RSA                14\r
+#define PEM_OBJ_PUB_DSA                15\r
+#define PEM_OBJ_PUB_DH         16\r
+#define PEM_OBJ_DHPARAMS       17\r
+#define PEM_OBJ_DSAPARAMS      18\r
+#define PEM_OBJ_PRIV_RSA_PUBLIC        19\r
+#define PEM_OBJ_PRIV_ECDSA     20\r
+#define PEM_OBJ_PUB_ECDSA      21\r
+#define PEM_OBJ_ECPARAMETERS   22\r
+\r
+#define PEM_ERROR              30\r
+#define PEM_DEK_DES_CBC         40\r
+#define PEM_DEK_IDEA_CBC        45\r
+#define PEM_DEK_DES_EDE         50\r
+#define PEM_DEK_DES_ECB         60\r
+#define PEM_DEK_RSA             70\r
+#define PEM_DEK_RSA_MD2         80\r
+#define PEM_DEK_RSA_MD5         90\r
+\r
+#define PEM_MD_MD2             NID_md2\r
+#define PEM_MD_MD5             NID_md5\r
+#define PEM_MD_SHA             NID_sha\r
+#define PEM_MD_MD2_RSA         NID_md2WithRSAEncryption\r
+#define PEM_MD_MD5_RSA         NID_md5WithRSAEncryption\r
+#define PEM_MD_SHA_RSA         NID_sha1WithRSAEncryption\r
+\r
+#define PEM_STRING_X509_OLD    "X509 CERTIFICATE"\r
+#define PEM_STRING_X509                "CERTIFICATE"\r
+#define PEM_STRING_X509_PAIR   "CERTIFICATE PAIR"\r
+#define PEM_STRING_X509_TRUSTED        "TRUSTED CERTIFICATE"\r
+#define PEM_STRING_X509_REQ_OLD        "NEW CERTIFICATE REQUEST"\r
+#define PEM_STRING_X509_REQ    "CERTIFICATE REQUEST"\r
+#define PEM_STRING_X509_CRL    "X509 CRL"\r
+#define PEM_STRING_EVP_PKEY    "ANY PRIVATE KEY"\r
+#define PEM_STRING_PUBLIC      "PUBLIC KEY"\r
+#define PEM_STRING_RSA         "RSA PRIVATE KEY"\r
+#define PEM_STRING_RSA_PUBLIC  "RSA PUBLIC KEY"\r
+#define PEM_STRING_DSA         "DSA PRIVATE KEY"\r
+#define PEM_STRING_DSA_PUBLIC  "DSA PUBLIC KEY"\r
+#define PEM_STRING_PKCS7       "PKCS7"\r
+#define PEM_STRING_PKCS8       "ENCRYPTED PRIVATE KEY"\r
+#define PEM_STRING_PKCS8INF    "PRIVATE KEY"\r
+#define PEM_STRING_DHPARAMS    "DH PARAMETERS"\r
+#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"\r
+#define PEM_STRING_DSAPARAMS   "DSA PARAMETERS"\r
+#define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"\r
+#define PEM_STRING_ECPARAMETERS "EC PARAMETERS"\r
+#define PEM_STRING_ECPRIVATEKEY        "EC PRIVATE KEY"\r
+\r
+  /* Note that this structure is initialised by PEM_SealInit and cleaned up\r
+     by PEM_SealFinal (at least for now) */\r
+typedef struct PEM_Encode_Seal_st\r
+       {\r
+       EVP_ENCODE_CTX encode;\r
+       EVP_MD_CTX md;\r
+       EVP_CIPHER_CTX cipher;\r
+       } PEM_ENCODE_SEAL_CTX;\r
+\r
+/* enc_type is one off */\r
+#define PEM_TYPE_ENCRYPTED      10\r
+#define PEM_TYPE_MIC_ONLY       20\r
+#define PEM_TYPE_MIC_CLEAR      30\r
+#define PEM_TYPE_CLEAR         40\r
+\r
+typedef struct pem_recip_st\r
+       {\r
+       char *name;\r
+       X509_NAME *dn;\r
+\r
+       int cipher;\r
+       int key_enc;\r
+       /*      char iv[8]; unused and wrong size */\r
+       } PEM_USER;\r
+\r
+typedef struct pem_ctx_st\r
+       {\r
+       int type;               /* what type of object */\r
+\r
+       struct  {\r
+               int version;    \r
+               int mode;               \r
+               } proc_type;\r
+\r
+       char *domain;\r
+\r
+       struct  {\r
+               int cipher;\r
+       /* unused, and wrong size\r
+          unsigned char iv[8]; */\r
+               } DEK_info;\r
+               \r
+       PEM_USER *originator;\r
+\r
+       int num_recipient;\r
+       PEM_USER **recipient;\r
+\r
+#ifndef OPENSSL_NO_STACK\r
+       STACK *x509_chain;      /* certificate chain */\r
+#else\r
+       char *x509_chain;       /* certificate chain */\r
+#endif\r
+       EVP_MD *md;             /* signature type */\r
+\r
+       int md_enc;             /* is the md encrypted or not? */\r
+       int md_len;             /* length of md_data */\r
+       char *md_data;          /* message digest, could be pkey encrypted */\r
+\r
+       EVP_CIPHER *dec;        /* date encryption cipher */\r
+       int key_len;            /* key length */\r
+       unsigned char *key;     /* key */\r
+       /* unused, and wrong size\r
+          unsigned char iv[8]; */\r
+\r
+       \r
+       int  data_enc;          /* is the data encrypted */\r
+       int data_len;\r
+       unsigned char *data;\r
+       } PEM_CTX;\r
+\r
+/* These macros make the PEM_read/PEM_write functions easier to maintain and\r
+ * write. Now they are all implemented with either:\r
+ * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)\r
+ */\r
+\r
+#ifdef OPENSSL_NO_FP_API\r
+\r
+#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/\r
+#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/\r
+#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/\r
+\r
+#else\r
+\r
+#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \\r
+type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\\r
+{ \\r
+return(((type *(*)(D2I_OF(type),char *,FILE *,type **,pem_password_cb *,void *))openssl_fcast(PEM_ASN1_read))(d2i_##asn1, str,fp,x,cb,u)); \\r
+} \\r
+\r
+#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \\r
+int PEM_write_##name(FILE *fp, type *x) \\r
+{ \\r
+return(((int (*)(I2D_OF(type),const char *,FILE *,type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write))(i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL)); \\r
+}\r
+\r
+#define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \\r
+int PEM_write_##name(FILE *fp, const type *x) \\r
+{ \\r
+return(((int (*)(I2D_OF_const(type),const char *,FILE *, const type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write))(i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL)); \\r
+}\r
+\r
+#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \\r
+int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \\r
+            unsigned char *kstr, int klen, pem_password_cb *cb, \\r
+                 void *u) \\r
+       { \\r
+       return(((int (*)(I2D_OF(type),const char *,FILE *,type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write))(i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u)); \\r
+       }\r
+\r
+#define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \\r
+int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \\r
+            unsigned char *kstr, int klen, pem_password_cb *cb, \\r
+                 void *u) \\r
+       { \\r
+       return(((int (*)(I2D_OF_const(type),const char *,FILE *,type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write))(i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u)); \\r
+       }\r
+\r
+#endif\r
+\r
+#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \\r
+type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\\r
+{ \\r
+return(((type *(*)(D2I_OF(type),const char *,BIO *,type **,pem_password_cb *,void *))openssl_fcast(PEM_ASN1_read_bio))(d2i_##asn1, str,bp,x,cb,u)); \\r
+}\r
+\r
+#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \\r
+int PEM_write_bio_##name(BIO *bp, type *x) \\r
+{ \\r
+return(((int (*)(I2D_OF(type),const char *,BIO *,type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write_bio))(i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL)); \\r
+}\r
+\r
+#define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \\r
+int PEM_write_bio_##name(BIO *bp, const type *x) \\r
+{ \\r
+return(((int (*)(I2D_OF_const(type),const char *,BIO *,const type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write_bio))(i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL)); \\r
+}\r
+\r
+#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \\r
+int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \\r
+            unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \\r
+       { \\r
+       return(((int (*)(I2D_OF(type),const char *,BIO *,type *,const EVP_CIPHER *,unsigned char *,int,pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write_bio))(i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u)); \\r
+       }\r
+\r
+#define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \\r
+int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \\r
+            unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \\r
+       { \\r
+       return(((int (*)(I2D_OF_const(type),const char *,BIO *,type *,const EVP_CIPHER *,unsigned char *,int,pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write_bio))(i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u)); \\r
+       }\r
+\r
+#define IMPLEMENT_PEM_write(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_write_bio(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_write_fp(name, type, str, asn1) \r
+\r
+#define IMPLEMENT_PEM_write_const(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \r
+\r
+#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \r
+\r
+#define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \r
+\r
+#define IMPLEMENT_PEM_read(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_read_bio(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_read_fp(name, type, str, asn1) \r
+\r
+#define IMPLEMENT_PEM_rw(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_read(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_write(name, type, str, asn1)\r
+\r
+#define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_read(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_write_const(name, type, str, asn1)\r
+\r
+#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_read(name, type, str, asn1) \\r
+       IMPLEMENT_PEM_write_cb(name, type, str, asn1)\r
+\r
+/* These are the same except they are for the declarations */\r
+\r
+#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API)\r
+\r
+#define DECLARE_PEM_read_fp(name, type) /**/\r
+#define DECLARE_PEM_write_fp(name, type) /**/\r
+#define DECLARE_PEM_write_cb_fp(name, type) /**/\r
+\r
+#else\r
+\r
+#define DECLARE_PEM_read_fp(name, type) \\r
+       type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);\r
+\r
+#define DECLARE_PEM_write_fp(name, type) \\r
+       int PEM_write_##name(FILE *fp, type *x);\r
+\r
+#define DECLARE_PEM_write_fp_const(name, type) \\r
+       int PEM_write_##name(FILE *fp, const type *x);\r
+\r
+#define DECLARE_PEM_write_cb_fp(name, type) \\r
+       int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \\r
+            unsigned char *kstr, int klen, pem_password_cb *cb, void *u);\r
+\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+#define DECLARE_PEM_read_bio(name, type) \\r
+       type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);\r
+\r
+#define DECLARE_PEM_write_bio(name, type) \\r
+       int PEM_write_bio_##name(BIO *bp, type *x);\r
+\r
+#define DECLARE_PEM_write_bio_const(name, type) \\r
+       int PEM_write_bio_##name(BIO *bp, const type *x);\r
+\r
+#define DECLARE_PEM_write_cb_bio(name, type) \\r
+       int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \\r
+            unsigned char *kstr, int klen, pem_password_cb *cb, void *u);\r
+\r
+#else\r
+\r
+#define DECLARE_PEM_read_bio(name, type) /**/\r
+#define DECLARE_PEM_write_bio(name, type) /**/\r
+#define DECLARE_PEM_write_cb_bio(name, type) /**/\r
+\r
+#endif\r
+\r
+#define DECLARE_PEM_write(name, type) \\r
+       DECLARE_PEM_write_bio(name, type) \\r
+       DECLARE_PEM_write_fp(name, type) \r
+\r
+#define DECLARE_PEM_write_const(name, type) \\r
+       DECLARE_PEM_write_bio_const(name, type) \\r
+       DECLARE_PEM_write_fp_const(name, type)\r
+\r
+#define DECLARE_PEM_write_cb(name, type) \\r
+       DECLARE_PEM_write_cb_bio(name, type) \\r
+       DECLARE_PEM_write_cb_fp(name, type) \r
+\r
+#define DECLARE_PEM_read(name, type) \\r
+       DECLARE_PEM_read_bio(name, type) \\r
+       DECLARE_PEM_read_fp(name, type)\r
+\r
+#define DECLARE_PEM_rw(name, type) \\r
+       DECLARE_PEM_read(name, type) \\r
+       DECLARE_PEM_write(name, type)\r
+\r
+#define DECLARE_PEM_rw_const(name, type) \\r
+       DECLARE_PEM_read(name, type) \\r
+       DECLARE_PEM_write_const(name, type)\r
+\r
+#define DECLARE_PEM_rw_cb(name, type) \\r
+       DECLARE_PEM_read(name, type) \\r
+       DECLARE_PEM_write_cb(name, type)\r
+\r
+#ifdef SSLEAY_MACROS\r
+\r
+#define PEM_write_SSL_SESSION(fp,x) \\r
+               PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \\r
+                       PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)\r
+#define PEM_write_X509(fp,x) \\r
+               PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \\r
+                       (char *)x, NULL,NULL,0,NULL,NULL)\r
+#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \\r
+               (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \\r
+                       NULL,NULL,0,NULL,NULL)\r
+#define PEM_write_X509_CRL(fp,x) \\r
+               PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \\r
+                       fp,(char *)x, NULL,NULL,0,NULL,NULL)\r
+#define        PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \\r
+               PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\\r
+                       (char *)x,enc,kstr,klen,cb,u)\r
+#define        PEM_write_RSAPublicKey(fp,x) \\r
+               PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\\r
+                       PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)\r
+#define        PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \\r
+               PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\\r
+                       (char *)x,enc,kstr,klen,cb,u)\r
+#define        PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \\r
+               PEM_ASN1_write((int (*)())i2d_PrivateKey,\\r
+               (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\\r
+                       bp,(char *)x,enc,kstr,klen,cb,u)\r
+#define PEM_write_PKCS7(fp,x) \\r
+               PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \\r
+                       (char *)x, NULL,NULL,0,NULL,NULL)\r
+#define PEM_write_DHparams(fp,x) \\r
+               PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\\r
+                       (char *)x,NULL,NULL,0,NULL,NULL)\r
+\r
+#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \\r
+                PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \\r
+                       PEM_STRING_X509,fp, \\r
+                        (char *)x, NULL,NULL,0,NULL,NULL)\r
+\r
+#define        PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \\r
+       (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)\r
+#define        PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \\r
+       (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)\r
+#define        PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \\r
+       (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)\r
+#define        PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \\r
+       (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)\r
+#define        PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \\r
+       (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)\r
+#define        PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \\r
+       (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)\r
+#define        PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \\r
+       (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)\r
+#define        PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \\r
+       (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)\r
+#define        PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \\r
+       (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)\r
+#define        PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \\r
+       (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)\r
+\r
+#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \\r
+               (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \\r
+        (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\\r
+                                                       (char **)x,cb,u)\r
+\r
+#define PEM_write_bio_X509(bp,x) \\r
+               PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \\r
+                       (char *)x, NULL,NULL,0,NULL,NULL)\r
+#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \\r
+               (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \\r
+                       NULL,NULL,0,NULL,NULL)\r
+#define PEM_write_bio_X509_CRL(bp,x) \\r
+               PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\\r
+                       bp,(char *)x, NULL,NULL,0,NULL,NULL)\r
+#define        PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \\r
+               PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\\r
+                       bp,(char *)x,enc,kstr,klen,cb,u)\r
+#define        PEM_write_bio_RSAPublicKey(bp,x) \\r
+               PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \\r
+                       PEM_STRING_RSA_PUBLIC,\\r
+                       bp,(char *)x,NULL,NULL,0,NULL,NULL)\r
+#define        PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \\r
+               PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\\r
+                       bp,(char *)x,enc,kstr,klen,cb,u)\r
+#define        PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \\r
+               PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\\r
+               (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\\r
+                       bp,(char *)x,enc,kstr,klen,cb,u)\r
+#define PEM_write_bio_PKCS7(bp,x) \\r
+               PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \\r
+                       (char *)x, NULL,NULL,0,NULL,NULL)\r
+#define PEM_write_bio_DHparams(bp,x) \\r
+               PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\\r
+                       bp,(char *)x,NULL,NULL,0,NULL,NULL)\r
+#define PEM_write_bio_DSAparams(bp,x) \\r
+               PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \\r
+                       PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)\r
+\r
+#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \\r
+                PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \\r
+                       PEM_STRING_X509,bp, \\r
+                        (char *)x, NULL,NULL,0,NULL,NULL)\r
+\r
+#define        PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \\r
+       (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)\r
+#define        PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \\r
+       (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)\r
+#define        PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \\r
+       (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)\r
+#define        PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \\r
+       (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)\r
+#define        PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \\r
+       (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)\r
+#define        PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \\r
+       (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)\r
+#define        PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \\r
+       (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)\r
+\r
+#define        PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \\r
+       (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)\r
+#define        PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \\r
+       (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)\r
+#define        PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \\r
+       (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)\r
+\r
+#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \\r
+               (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \\r
+        (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\\r
+                                                       (char **)x,cb,u)\r
+\r
+#endif\r
+\r
+#if 1\r
+/* "userdata": new with OpenSSL 0.9.4 */\r
+typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);\r
+#else\r
+/* OpenSSL 0.9.3, 0.9.3a */\r
+typedef int pem_password_cb(char *buf, int size, int rwflag);\r
+#endif\r
+\r
+int    PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);\r
+int    PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,\r
+       pem_password_cb *callback,void *u);\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+int    PEM_read_bio(BIO *bp, char **name, char **header,\r
+               unsigned char **data,long *len);\r
+int    PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,\r
+               long len);\r
+int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,\r
+            pem_password_cb *cb, void *u);\r
+void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp,\r
+                         void **x, pem_password_cb *cb, void *u);\r
+#define PEM_ASN1_read_bio_of(type,d2i,name,bp,x,cb,u) \\r
+((type *(*)(D2I_OF(type),const char *,BIO *,type **,pem_password_cb *,void *))openssl_fcast(PEM_ASN1_read_bio))(d2i,name,bp,x,cb,u)\r
+int    PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp,char *x,\r
+                          const EVP_CIPHER *enc,unsigned char *kstr,int klen,\r
+                          pem_password_cb *cb, void *u);\r
+#define PEM_ASN1_write_bio_of(type,i2d,name,bp,x,enc,kstr,klen,cb,u) \\r
+       ((int (*)(I2D_OF(type),const char *,BIO *,type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write_bio))(i2d,name,bp,x,enc,kstr,klen,cb,u)\r
+\r
+STACK_OF(X509_INFO) *  PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);\r
+int    PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,\r
+               unsigned char *kstr, int klen, pem_password_cb *cd, void *u);\r
+#endif\r
+\r
+#ifndef OPENSSL_SYS_WIN16\r
+int    PEM_read(FILE *fp, char **name, char **header,\r
+               unsigned char **data,long *len);\r
+int    PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);\r
+void *  PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,\r
+                     pem_password_cb *cb, void *u);\r
+int    PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp,\r
+                      char *x,const EVP_CIPHER *enc,unsigned char *kstr,\r
+                      int klen,pem_password_cb *callback, void *u);\r
+STACK_OF(X509_INFO) *  PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,\r
+       pem_password_cb *cb, void *u);\r
+#endif\r
+\r
+int    PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,\r
+               EVP_MD *md_type, unsigned char **ek, int *ekl,\r
+               unsigned char *iv, EVP_PKEY **pubk, int npubk);\r
+void   PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,\r
+               unsigned char *in, int inl);\r
+int    PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl,\r
+               unsigned char *out, int *outl, EVP_PKEY *priv);\r
+\r
+void    PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);\r
+void    PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);\r
+int    PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,\r
+               unsigned int *siglen, EVP_PKEY *pkey);\r
+\r
+int    PEM_def_callback(char *buf, int num, int w, void *key);\r
+void   PEM_proc_type(char *buf, int type);\r
+void   PEM_dek_info(char *buf, const char *type, int len, char *str);\r
+\r
+#ifndef SSLEAY_MACROS\r
+\r
+#include <openssl/symhacks.h>\r
+\r
+DECLARE_PEM_rw(X509, X509)\r
+\r
+DECLARE_PEM_rw(X509_AUX, X509)\r
+\r
+DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR)\r
+\r
+DECLARE_PEM_rw(X509_REQ, X509_REQ)\r
+DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)\r
+\r
+DECLARE_PEM_rw(X509_CRL, X509_CRL)\r
+\r
+DECLARE_PEM_rw(PKCS7, PKCS7)\r
+\r
+DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)\r
+\r
+DECLARE_PEM_rw(PKCS8, X509_SIG)\r
+\r
+DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)\r
+\r
+#ifndef OPENSSL_NO_RSA\r
+\r
+DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)\r
+\r
+DECLARE_PEM_rw_const(RSAPublicKey, RSA)\r
+DECLARE_PEM_rw(RSA_PUBKEY, RSA)\r
+\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_DSA\r
+\r
+DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)\r
+\r
+DECLARE_PEM_rw(DSA_PUBKEY, DSA)\r
+\r
+DECLARE_PEM_rw_const(DSAparams, DSA)\r
+\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_EC\r
+DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP)\r
+DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY)\r
+DECLARE_PEM_rw(EC_PUBKEY, EC_KEY)\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_DH\r
+\r
+DECLARE_PEM_rw_const(DHparams, DH)\r
+\r
+#endif\r
+\r
+DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)\r
+\r
+DECLARE_PEM_rw(PUBKEY, EVP_PKEY)\r
+\r
+int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,\r
+                                 char *kstr, int klen,\r
+                                 pem_password_cb *cb, void *u);\r
+int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,\r
+                                  char *, int, pem_password_cb *, void *);\r
+int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,\r
+                                 char *kstr, int klen,\r
+                                 pem_password_cb *cb, void *u);\r
+int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,\r
+                                 char *kstr, int klen,\r
+                                 pem_password_cb *cb, void *u);\r
+EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);\r
+\r
+int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,\r
+                                 char *kstr, int klen,\r
+                                 pem_password_cb *cb, void *u);\r
+int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,\r
+                                 char *kstr, int klen,\r
+                                 pem_password_cb *cb, void *u);\r
+int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,\r
+                                 char *kstr, int klen,\r
+                                 pem_password_cb *cb, void *u);\r
+\r
+EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);\r
+\r
+int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,\r
+                             char *kstr,int klen, pem_password_cb *cd, void *u);\r
+\r
+#endif /* SSLEAY_MACROS */\r
+\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_PEM_strings(void);\r
+\r
+/* Error codes for the PEM functions. */\r
+\r
+/* Function codes. */\r
+#define PEM_F_D2I_PKCS8PRIVATEKEY_BIO                   120\r
+#define PEM_F_D2I_PKCS8PRIVATEKEY_FP                    121\r
+#define PEM_F_DO_PK8PKEY                                126\r
+#define PEM_F_DO_PK8PKEY_FP                             125\r
+#define PEM_F_LOAD_IV                                   101\r
+#define PEM_F_PEM_ASN1_READ                             102\r
+#define PEM_F_PEM_ASN1_READ_BIO                                 103\r
+#define PEM_F_PEM_ASN1_WRITE                            104\r
+#define PEM_F_PEM_ASN1_WRITE_BIO                        105\r
+#define PEM_F_PEM_DEF_CALLBACK                          100\r
+#define PEM_F_PEM_DO_HEADER                             106\r
+#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY           118\r
+#define PEM_F_PEM_GET_EVP_CIPHER_INFO                   107\r
+#define PEM_F_PEM_PK8PKEY                               119\r
+#define PEM_F_PEM_READ                                  108\r
+#define PEM_F_PEM_READ_BIO                              109\r
+#define PEM_F_PEM_READ_BIO_PRIVATEKEY                   123\r
+#define PEM_F_PEM_READ_PRIVATEKEY                       124\r
+#define PEM_F_PEM_SEALFINAL                             110\r
+#define PEM_F_PEM_SEALINIT                              111\r
+#define PEM_F_PEM_SIGNFINAL                             112\r
+#define PEM_F_PEM_WRITE                                         113\r
+#define PEM_F_PEM_WRITE_BIO                             114\r
+#define PEM_F_PEM_X509_INFO_READ                        115\r
+#define PEM_F_PEM_X509_INFO_READ_BIO                    116\r
+#define PEM_F_PEM_X509_INFO_WRITE_BIO                   117\r
+\r
+/* Reason codes. */\r
+#define PEM_R_BAD_BASE64_DECODE                                 100\r
+#define PEM_R_BAD_DECRYPT                               101\r
+#define PEM_R_BAD_END_LINE                              102\r
+#define PEM_R_BAD_IV_CHARS                              103\r
+#define PEM_R_BAD_PASSWORD_READ                                 104\r
+#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY              115\r
+#define PEM_R_NOT_DEK_INFO                              105\r
+#define PEM_R_NOT_ENCRYPTED                             106\r
+#define PEM_R_NOT_PROC_TYPE                             107\r
+#define PEM_R_NO_START_LINE                             108\r
+#define PEM_R_PROBLEMS_GETTING_PASSWORD                         109\r
+#define PEM_R_PUBLIC_KEY_NO_RSA                                 110\r
+#define PEM_R_READ_KEY                                  111\r
+#define PEM_R_SHORT_HEADER                              112\r
+#define PEM_R_UNSUPPORTED_CIPHER                        113\r
+#define PEM_R_UNSUPPORTED_ENCRYPTION                    114\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pem2.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pem2.h
new file mode 100644 (file)
index 0000000..f31790d
--- /dev/null
@@ -0,0 +1,70 @@
+/* ====================================================================
+ * Copyright (c) 1999 The OpenSSL Project.  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.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ *    software must display the following acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED 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 OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS 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.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+/*
+ * This header only exists to break a circular dependency between pem and err
+ * Ben 30 Jan 1999.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef HEADER_PEM_H
+void ERR_load_PEM_strings(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pkcs12.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pkcs12.h
new file mode 100644 (file)
index 0000000..46d8dad
--- /dev/null
@@ -0,0 +1,333 @@
+/* pkcs12.h */\r
+/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL\r
+ * project 1999.\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    licensing@OpenSSL.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_PKCS12_H\r
+#define HEADER_PKCS12_H\r
+\r
+#include <openssl/bio.h>\r
+#include <openssl/x509.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define PKCS12_KEY_ID  1\r
+#define PKCS12_IV_ID   2\r
+#define PKCS12_MAC_ID  3\r
+\r
+/* Default iteration count */\r
+#ifndef PKCS12_DEFAULT_ITER\r
+#define PKCS12_DEFAULT_ITER    PKCS5_DEFAULT_ITER\r
+#endif\r
+\r
+#define PKCS12_MAC_KEY_LENGTH 20\r
+\r
+#define PKCS12_SALT_LEN        8\r
+\r
+/* Uncomment out next line for unicode password and names, otherwise ASCII */\r
+\r
+/*#define PBE_UNICODE*/\r
+\r
+#ifdef PBE_UNICODE\r
+#define PKCS12_key_gen PKCS12_key_gen_uni\r
+#define PKCS12_add_friendlyname PKCS12_add_friendlyname_uni\r
+#else\r
+#define PKCS12_key_gen PKCS12_key_gen_asc\r
+#define PKCS12_add_friendlyname PKCS12_add_friendlyname_asc\r
+#endif\r
+\r
+/* MS key usage constants */\r
+\r
+#define KEY_EX 0x10\r
+#define KEY_SIG 0x80\r
+\r
+typedef struct {\r
+X509_SIG *dinfo;\r
+ASN1_OCTET_STRING *salt;\r
+ASN1_INTEGER *iter;    /* defaults to 1 */\r
+} PKCS12_MAC_DATA;\r
+\r
+typedef struct {\r
+ASN1_INTEGER *version;\r
+PKCS12_MAC_DATA *mac;\r
+PKCS7 *authsafes;\r
+} PKCS12;\r
+\r
+PREDECLARE_STACK_OF(PKCS12_SAFEBAG)\r
+\r
+typedef struct {\r
+ASN1_OBJECT *type;\r
+union {\r
+       struct pkcs12_bag_st *bag; /* secret, crl and certbag */\r
+       struct pkcs8_priv_key_info_st   *keybag; /* keybag */\r
+       X509_SIG *shkeybag; /* shrouded key bag */\r
+       STACK_OF(PKCS12_SAFEBAG) *safes;\r
+       ASN1_TYPE *other;\r
+}value;\r
+STACK_OF(X509_ATTRIBUTE) *attrib;\r
+} PKCS12_SAFEBAG;\r
+\r
+DECLARE_STACK_OF(PKCS12_SAFEBAG)\r
+DECLARE_ASN1_SET_OF(PKCS12_SAFEBAG)\r
+DECLARE_PKCS12_STACK_OF(PKCS12_SAFEBAG)\r
+\r
+typedef struct pkcs12_bag_st {\r
+ASN1_OBJECT *type;\r
+union {\r
+       ASN1_OCTET_STRING *x509cert;\r
+       ASN1_OCTET_STRING *x509crl;\r
+       ASN1_OCTET_STRING *octet;\r
+       ASN1_IA5STRING *sdsicert;\r
+       ASN1_TYPE *other; /* Secret or other bag */\r
+}value;\r
+} PKCS12_BAGS;\r
+\r
+#define PKCS12_ERROR   0\r
+#define PKCS12_OK      1\r
+\r
+/* Compatibility macros */\r
+\r
+#define M_PKCS12_x5092certbag PKCS12_x5092certbag\r
+#define M_PKCS12_x509crl2certbag PKCS12_x509crl2certbag\r
+\r
+#define M_PKCS12_certbag2x509 PKCS12_certbag2x509\r
+#define M_PKCS12_certbag2x509crl PKCS12_certbag2x509crl \r
+\r
+#define M_PKCS12_unpack_p7data PKCS12_unpack_p7data\r
+#define M_PKCS12_pack_authsafes PKCS12_pack_authsafes\r
+#define M_PKCS12_unpack_authsafes PKCS12_unpack_authsafes\r
+#define M_PKCS12_unpack_p7encdata PKCS12_unpack_p7encdata\r
+\r
+#define M_PKCS12_decrypt_skey PKCS12_decrypt_skey\r
+#define M_PKCS8_decrypt PKCS8_decrypt\r
+\r
+#define M_PKCS12_bag_type(bg) OBJ_obj2nid((bg)->type)\r
+#define M_PKCS12_cert_bag_type(bg) OBJ_obj2nid((bg)->value.bag->type)\r
+#define M_PKCS12_crl_bag_type M_PKCS12_cert_bag_type\r
+\r
+#define PKCS12_get_attr(bag, attr_nid) \\r
+                        PKCS12_get_attr_gen(bag->attrib, attr_nid)\r
+\r
+#define PKCS8_get_attr(p8, attr_nid) \\r
+               PKCS12_get_attr_gen(p8->attributes, attr_nid)\r
+\r
+#define PKCS12_mac_present(p12) ((p12)->mac ? 1 : 0)\r
+\r
+\r
+PKCS12_SAFEBAG *PKCS12_x5092certbag(X509 *x509);\r
+PKCS12_SAFEBAG *PKCS12_x509crl2certbag(X509_CRL *crl);\r
+X509 *PKCS12_certbag2x509(PKCS12_SAFEBAG *bag);\r
+X509_CRL *PKCS12_certbag2x509crl(PKCS12_SAFEBAG *bag);\r
+\r
+PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, int nid1,\r
+            int nid2);\r
+PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8);\r
+PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(X509_SIG *p8, const char *pass, int passlen);\r
+PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(PKCS12_SAFEBAG *bag, const char *pass,\r
+                                                               int passlen);\r
+X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, \r
+                       const char *pass, int passlen,\r
+                       unsigned char *salt, int saltlen, int iter,\r
+                       PKCS8_PRIV_KEY_INFO *p8);\r
+PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass,\r
+                                    int passlen, unsigned char *salt,\r
+                                    int saltlen, int iter,\r
+                                    PKCS8_PRIV_KEY_INFO *p8);\r
+PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk);\r
+STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7);\r
+PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,\r
+                            unsigned char *salt, int saltlen, int iter,\r
+                            STACK_OF(PKCS12_SAFEBAG) *bags);\r
+STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, int passlen);\r
+\r
+int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes);\r
+STACK_OF(PKCS7) *PKCS12_unpack_authsafes(PKCS12 *p12);\r
+\r
+int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen);\r
+int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,\r
+                               int namelen);\r
+int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name,\r
+                               int namelen);\r
+int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, const unsigned char *name,\r
+                               int namelen);\r
+int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage);\r
+ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid);\r
+char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag);\r
+unsigned char *PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,\r
+                               int passlen, unsigned char *in, int inlen,\r
+                               unsigned char **data, int *datalen, int en_de);\r
+void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,\r
+            const char *pass, int passlen, ASN1_OCTET_STRING *oct, int zbuf);\r
+ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *it,\r
+                                      const char *pass, int passlen,\r
+                                      void *obj, int zbuf);\r
+PKCS12 *PKCS12_init(int mode);\r
+int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,\r
+                      int saltlen, int id, int iter, int n,\r
+                      unsigned char *out, const EVP_MD *md_type);\r
+int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int id, int iter, int n, unsigned char *out, const EVP_MD *md_type);\r
+int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,\r
+                        ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md_type,\r
+                        int en_de);\r
+int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,\r
+                        unsigned char *mac, unsigned int *maclen);\r
+int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen);\r
+int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,\r
+                  unsigned char *salt, int saltlen, int iter,\r
+                  const EVP_MD *md_type);\r
+int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,\r
+                                        int saltlen, const EVP_MD *md_type);\r
+unsigned char *asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen);\r
+char *uni2asc(unsigned char *uni, int unilen);\r
+\r
+DECLARE_ASN1_FUNCTIONS(PKCS12)\r
+DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA)\r
+DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG)\r
+DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS)\r
+\r
+DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS)\r
+DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES)\r
+\r
+void PKCS12_PBE_add(void);\r
+int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,\r
+                STACK_OF(X509) **ca);\r
+PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,\r
+                        STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter,\r
+                                                int mac_iter, int keytype);\r
+\r
+PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert);\r
+PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags, EVP_PKEY *key,\r
+                                               int key_usage, int iter,\r
+                                               int key_nid, char *pass);\r
+int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags,\r
+                                       int safe_nid, int iter, char *pass);\r
+PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid);\r
+\r
+int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12);\r
+int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12);\r
+PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);\r
+PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);\r
+int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_PKCS12_strings(void);\r
+\r
+/* Error codes for the PKCS12 functions. */\r
+\r
+/* Function codes. */\r
+#define PKCS12_F_PARSE_BAG                              129\r
+#define PKCS12_F_PARSE_BAGS                             103\r
+#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME                100\r
+#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC            127\r
+#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI            102\r
+#define PKCS12_F_PKCS12_ADD_LOCALKEYID                  104\r
+#define PKCS12_F_PKCS12_CREATE                          105\r
+#define PKCS12_F_PKCS12_GEN_MAC                                 107\r
+#define PKCS12_F_PKCS12_INIT                            109\r
+#define PKCS12_F_PKCS12_ITEM_DECRYPT_D2I                106\r
+#define PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT                108\r
+#define PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG               117\r
+#define PKCS12_F_PKCS12_KEY_GEN_ASC                     110\r
+#define PKCS12_F_PKCS12_KEY_GEN_UNI                     111\r
+#define PKCS12_F_PKCS12_MAKE_KEYBAG                     112\r
+#define PKCS12_F_PKCS12_MAKE_SHKEYBAG                   113\r
+#define PKCS12_F_PKCS12_NEWPASS                                 128\r
+#define PKCS12_F_PKCS12_PACK_P7DATA                     114\r
+#define PKCS12_F_PKCS12_PACK_P7ENCDATA                  115\r
+#define PKCS12_F_PKCS12_PARSE                           118\r
+#define PKCS12_F_PKCS12_PBE_CRYPT                       119\r
+#define PKCS12_F_PKCS12_PBE_KEYIVGEN                    120\r
+#define PKCS12_F_PKCS12_SETUP_MAC                       122\r
+#define PKCS12_F_PKCS12_SET_MAC                                 123\r
+#define PKCS12_F_PKCS12_UNPACK_AUTHSAFES                130\r
+#define PKCS12_F_PKCS12_UNPACK_P7DATA                   131\r
+#define PKCS12_F_PKCS12_VERIFY_MAC                      126\r
+#define PKCS12_F_PKCS8_ADD_KEYUSAGE                     124\r
+#define PKCS12_F_PKCS8_ENCRYPT                          125\r
+\r
+/* Reason codes. */\r
+#define PKCS12_R_CANT_PACK_STRUCTURE                    100\r
+#define PKCS12_R_CONTENT_TYPE_NOT_DATA                  121\r
+#define PKCS12_R_DECODE_ERROR                           101\r
+#define PKCS12_R_ENCODE_ERROR                           102\r
+#define PKCS12_R_ENCRYPT_ERROR                          103\r
+#define PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE      120\r
+#define PKCS12_R_INVALID_NULL_ARGUMENT                  104\r
+#define PKCS12_R_INVALID_NULL_PKCS12_POINTER            105\r
+#define PKCS12_R_IV_GEN_ERROR                           106\r
+#define PKCS12_R_KEY_GEN_ERROR                          107\r
+#define PKCS12_R_MAC_ABSENT                             108\r
+#define PKCS12_R_MAC_GENERATION_ERROR                   109\r
+#define PKCS12_R_MAC_SETUP_ERROR                        110\r
+#define PKCS12_R_MAC_STRING_SET_ERROR                   111\r
+#define PKCS12_R_MAC_VERIFY_ERROR                       112\r
+#define PKCS12_R_MAC_VERIFY_FAILURE                     113\r
+#define PKCS12_R_PARSE_ERROR                            114\r
+#define PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR          115\r
+#define PKCS12_R_PKCS12_CIPHERFINAL_ERROR               116\r
+#define PKCS12_R_PKCS12_PBE_CRYPT_ERROR                         117\r
+#define PKCS12_R_UNKNOWN_DIGEST_ALGORITHM               118\r
+#define PKCS12_R_UNSUPPORTED_PKCS12_MODE                119\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pkcs7.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pkcs7.h
new file mode 100644 (file)
index 0000000..1a8c31b
--- /dev/null
@@ -0,0 +1,463 @@
+/* crypto/pkcs7/pkcs7.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_PKCS7_H\r
+#define HEADER_PKCS7_H\r
+\r
+#include <openssl/asn1.h>\r
+#include <openssl/bio.h>\r
+#include <openssl/e_os2.h>\r
+\r
+#include <openssl/symhacks.h>\r
+#include <openssl/ossl_typ.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef OPENSSL_SYS_WIN32\r
+/* Under Win32 thes are defined in wincrypt.h */\r
+#undef PKCS7_ISSUER_AND_SERIAL\r
+#undef PKCS7_SIGNER_INFO\r
+#endif\r
+\r
+/*\r
+Encryption_ID          DES-CBC\r
+Digest_ID              MD5\r
+Digest_Encryption_ID   rsaEncryption\r
+Key_Encryption_ID      rsaEncryption\r
+*/\r
+\r
+typedef struct pkcs7_issuer_and_serial_st\r
+       {\r
+       X509_NAME *issuer;\r
+       ASN1_INTEGER *serial;\r
+       } PKCS7_ISSUER_AND_SERIAL;\r
+\r
+typedef struct pkcs7_signer_info_st\r
+       {\r
+       ASN1_INTEGER                    *version;       /* version 1 */\r
+       PKCS7_ISSUER_AND_SERIAL         *issuer_and_serial;\r
+       X509_ALGOR                      *digest_alg;\r
+       STACK_OF(X509_ATTRIBUTE)        *auth_attr;     /* [ 0 ] */\r
+       X509_ALGOR                      *digest_enc_alg;\r
+       ASN1_OCTET_STRING               *enc_digest;\r
+       STACK_OF(X509_ATTRIBUTE)        *unauth_attr;   /* [ 1 ] */\r
+\r
+       /* The private key to sign with */\r
+       EVP_PKEY                        *pkey;\r
+       } PKCS7_SIGNER_INFO;\r
+\r
+DECLARE_STACK_OF(PKCS7_SIGNER_INFO)\r
+DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO)\r
+\r
+typedef struct pkcs7_recip_info_st\r
+       {\r
+       ASN1_INTEGER                    *version;       /* version 0 */\r
+       PKCS7_ISSUER_AND_SERIAL         *issuer_and_serial;\r
+       X509_ALGOR                      *key_enc_algor;\r
+       ASN1_OCTET_STRING               *enc_key;\r
+       X509                            *cert; /* get the pub-key from this */\r
+       } PKCS7_RECIP_INFO;\r
+\r
+DECLARE_STACK_OF(PKCS7_RECIP_INFO)\r
+DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO)\r
+\r
+typedef struct pkcs7_signed_st\r
+       {\r
+       ASN1_INTEGER                    *version;       /* version 1 */\r
+       STACK_OF(X509_ALGOR)            *md_algs;       /* md used */\r
+       STACK_OF(X509)                  *cert;          /* [ 0 ] */\r
+       STACK_OF(X509_CRL)              *crl;           /* [ 1 ] */\r
+       STACK_OF(PKCS7_SIGNER_INFO)     *signer_info;\r
+\r
+       struct pkcs7_st                 *contents;\r
+       } PKCS7_SIGNED;\r
+/* The above structure is very very similar to PKCS7_SIGN_ENVELOPE.\r
+ * How about merging the two */\r
+\r
+typedef struct pkcs7_enc_content_st\r
+       {\r
+       ASN1_OBJECT                     *content_type;\r
+       X509_ALGOR                      *algorithm;\r
+       ASN1_OCTET_STRING               *enc_data;      /* [ 0 ] */\r
+       const EVP_CIPHER                *cipher;\r
+       } PKCS7_ENC_CONTENT;\r
+\r
+typedef struct pkcs7_enveloped_st\r
+       {\r
+       ASN1_INTEGER                    *version;       /* version 0 */\r
+       STACK_OF(PKCS7_RECIP_INFO)      *recipientinfo;\r
+       PKCS7_ENC_CONTENT               *enc_data;\r
+       } PKCS7_ENVELOPE;\r
+\r
+typedef struct pkcs7_signedandenveloped_st\r
+       {\r
+       ASN1_INTEGER                    *version;       /* version 1 */\r
+       STACK_OF(X509_ALGOR)            *md_algs;       /* md used */\r
+       STACK_OF(X509)                  *cert;          /* [ 0 ] */\r
+       STACK_OF(X509_CRL)              *crl;           /* [ 1 ] */\r
+       STACK_OF(PKCS7_SIGNER_INFO)     *signer_info;\r
+\r
+       PKCS7_ENC_CONTENT               *enc_data;\r
+       STACK_OF(PKCS7_RECIP_INFO)      *recipientinfo;\r
+       } PKCS7_SIGN_ENVELOPE;\r
+\r
+typedef struct pkcs7_digest_st\r
+       {\r
+       ASN1_INTEGER                    *version;       /* version 0 */\r
+       X509_ALGOR                      *md;            /* md used */\r
+       struct pkcs7_st                 *contents;\r
+       ASN1_OCTET_STRING               *digest;\r
+       } PKCS7_DIGEST;\r
+\r
+typedef struct pkcs7_encrypted_st\r
+       {\r
+       ASN1_INTEGER                    *version;       /* version 0 */\r
+       PKCS7_ENC_CONTENT               *enc_data;\r
+       } PKCS7_ENCRYPT;\r
+\r
+typedef struct pkcs7_st\r
+       {\r
+       /* The following is non NULL if it contains ASN1 encoding of\r
+        * this structure */\r
+       unsigned char *asn1;\r
+       long length;\r
+\r
+#define PKCS7_S_HEADER 0\r
+#define PKCS7_S_BODY   1\r
+#define PKCS7_S_TAIL   2\r
+       int state; /* used during processing */\r
+\r
+       int detached;\r
+\r
+       ASN1_OBJECT *type;\r
+       /* content as defined by the type */\r
+       /* all encryption/message digests are applied to the 'contents',\r
+        * leaving out the 'type' field. */\r
+       union   {\r
+               char *ptr;\r
+\r
+               /* NID_pkcs7_data */\r
+               ASN1_OCTET_STRING *data;\r
+\r
+               /* NID_pkcs7_signed */\r
+               PKCS7_SIGNED *sign;\r
+\r
+               /* NID_pkcs7_enveloped */\r
+               PKCS7_ENVELOPE *enveloped;\r
+\r
+               /* NID_pkcs7_signedAndEnveloped */\r
+               PKCS7_SIGN_ENVELOPE *signed_and_enveloped;\r
+\r
+               /* NID_pkcs7_digest */\r
+               PKCS7_DIGEST *digest;\r
+\r
+               /* NID_pkcs7_encrypted */\r
+               PKCS7_ENCRYPT *encrypted;\r
+\r
+               /* Anything else */\r
+               ASN1_TYPE *other;\r
+               } d;\r
+       } PKCS7;\r
+\r
+DECLARE_STACK_OF(PKCS7)\r
+DECLARE_ASN1_SET_OF(PKCS7)\r
+DECLARE_PKCS12_STACK_OF(PKCS7)\r
+\r
+#define PKCS7_OP_SET_DETACHED_SIGNATURE        1\r
+#define PKCS7_OP_GET_DETACHED_SIGNATURE        2\r
+\r
+#define PKCS7_get_signed_attributes(si)        ((si)->auth_attr)\r
+#define PKCS7_get_attributes(si)       ((si)->unauth_attr)\r
+\r
+#define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed)\r
+#define PKCS7_type_is_encrypted(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted)\r
+#define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped)\r
+#define PKCS7_type_is_signedAndEnveloped(a) \\r
+               (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)\r
+#define PKCS7_type_is_data(a)   (OBJ_obj2nid((a)->type) == NID_pkcs7_data)\r
+\r
+#define PKCS7_type_is_digest(a)   (OBJ_obj2nid((a)->type) == NID_pkcs7_digest)\r
+\r
+#define PKCS7_set_detached(p,v) \\r
+               PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)\r
+#define PKCS7_get_detached(p) \\r
+               PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL)\r
+\r
+#define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7))\r
+\r
+#ifdef SSLEAY_MACROS\r
+#ifndef PKCS7_ISSUER_AND_SERIAL_digest\r
+#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \\r
+        ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\\r
+                       (char *)data,md,len)\r
+#endif\r
+#endif\r
+\r
+/* S/MIME related flags */\r
+\r
+#define PKCS7_TEXT             0x1\r
+#define PKCS7_NOCERTS          0x2\r
+#define PKCS7_NOSIGS           0x4\r
+#define PKCS7_NOCHAIN          0x8\r
+#define PKCS7_NOINTERN         0x10\r
+#define PKCS7_NOVERIFY         0x20\r
+#define PKCS7_DETACHED         0x40\r
+#define PKCS7_BINARY           0x80\r
+#define PKCS7_NOATTR           0x100\r
+#define        PKCS7_NOSMIMECAP        0x200\r
+#define PKCS7_NOOLDMIMETYPE    0x400\r
+#define PKCS7_CRLFEOL          0x800\r
+#define PKCS7_STREAM           0x1000\r
+#define PKCS7_NOCRL            0x2000\r
+\r
+/* Flags: for compatibility with older code */\r
+\r
+#define SMIME_TEXT     PKCS7_TEXT\r
+#define SMIME_NOCERTS  PKCS7_NOCERTS\r
+#define SMIME_NOSIGS   PKCS7_NOSIGS\r
+#define SMIME_NOCHAIN  PKCS7_NOCHAIN\r
+#define SMIME_NOINTERN PKCS7_NOINTERN\r
+#define SMIME_NOVERIFY PKCS7_NOVERIFY\r
+#define SMIME_DETACHED PKCS7_DETACHED\r
+#define SMIME_BINARY   PKCS7_BINARY\r
+#define SMIME_NOATTR   PKCS7_NOATTR\r
+\r
+DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)\r
+\r
+#ifndef SSLEAY_MACROS\r
+int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,const EVP_MD *type,\r
+       unsigned char *md,unsigned int *len);\r
+#ifndef OPENSSL_NO_FP_API\r
+PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7);\r
+int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7);\r
+#endif\r
+PKCS7 *PKCS7_dup(PKCS7 *p7);\r
+PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7);\r
+int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7);\r
+#endif\r
+\r
+DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO)\r
+DECLARE_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)\r
+DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNED)\r
+DECLARE_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)\r
+DECLARE_ASN1_FUNCTIONS(PKCS7_ENVELOPE)\r
+DECLARE_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)\r
+DECLARE_ASN1_FUNCTIONS(PKCS7_DIGEST)\r
+DECLARE_ASN1_FUNCTIONS(PKCS7_ENCRYPT)\r
+DECLARE_ASN1_FUNCTIONS(PKCS7)\r
+\r
+DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN)\r
+DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY)\r
+\r
+DECLARE_ASN1_NDEF_FUNCTION(PKCS7)\r
+\r
+long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);\r
+\r
+int PKCS7_set_type(PKCS7 *p7, int type);\r
+int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other);\r
+int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data);\r
+int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,\r
+       const EVP_MD *dgst);\r
+int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);\r
+int PKCS7_add_certificate(PKCS7 *p7, X509 *x509);\r
+int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);\r
+int PKCS7_content_new(PKCS7 *p7, int nid);\r
+int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx,\r
+       BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si); \r
+int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,\r
+                                                               X509 *x509);\r
+\r
+BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio);\r
+int PKCS7_dataFinal(PKCS7 *p7, BIO *bio);\r
+BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert);\r
+\r
+\r
+PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509,\r
+       EVP_PKEY *pkey, const EVP_MD *dgst);\r
+X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);\r
+int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md);\r
+STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);\r
+\r
+PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);\r
+int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri);\r
+int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);\r
+int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher);\r
+\r
+PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx);\r
+ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk);\r
+int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si,int nid,int type,\r
+       void *data);\r
+int PKCS7_add_attribute (PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,\r
+       void *value);\r
+ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid);\r
+ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid);\r
+int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,\r
+                               STACK_OF(X509_ATTRIBUTE) *sk);\r
+int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);\r
+\r
+\r
+PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,\r
+                                                       BIO *data, int flags);\r
+int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,\r
+                                       BIO *indata, BIO *out, int flags);\r
+STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);\r
+PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,\r
+                                                               int flags);\r
+int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags);\r
+\r
+int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si,\r
+                             STACK_OF(X509_ALGOR) *cap);\r
+STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si);\r
+int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg);\r
+\r
+int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags);\r
+PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont);\r
+int SMIME_crlf_copy(BIO *in, BIO *out, int flags);\r
+int SMIME_text(BIO *in, BIO *out);\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_PKCS7_strings(void);\r
+\r
+/* Error codes for the PKCS7 functions. */\r
+\r
+/* Function codes. */\r
+#define PKCS7_F_B64_READ_PKCS7                          120\r
+#define PKCS7_F_B64_WRITE_PKCS7                                 121\r
+#define PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP               118\r
+#define PKCS7_F_PKCS7_ADD_CERTIFICATE                   100\r
+#define PKCS7_F_PKCS7_ADD_CRL                           101\r
+#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO                102\r
+#define PKCS7_F_PKCS7_ADD_SIGNER                        103\r
+#define PKCS7_F_PKCS7_BIO_ADD_DIGEST                    125\r
+#define PKCS7_F_PKCS7_CTRL                              104\r
+#define PKCS7_F_PKCS7_DATADECODE                        112\r
+#define PKCS7_F_PKCS7_DATAFINAL                                 128\r
+#define PKCS7_F_PKCS7_DATAINIT                          105\r
+#define PKCS7_F_PKCS7_DATASIGN                          106\r
+#define PKCS7_F_PKCS7_DATAVERIFY                        107\r
+#define PKCS7_F_PKCS7_DECRYPT                           114\r
+#define PKCS7_F_PKCS7_ENCRYPT                           115\r
+#define PKCS7_F_PKCS7_FIND_DIGEST                       127\r
+#define PKCS7_F_PKCS7_GET0_SIGNERS                      124\r
+#define PKCS7_F_PKCS7_SET_CIPHER                        108\r
+#define PKCS7_F_PKCS7_SET_CONTENT                       109\r
+#define PKCS7_F_PKCS7_SET_DIGEST                        126\r
+#define PKCS7_F_PKCS7_SET_TYPE                          110\r
+#define PKCS7_F_PKCS7_SIGN                              116\r
+#define PKCS7_F_PKCS7_SIGNATUREVERIFY                   113\r
+#define PKCS7_F_PKCS7_SIMPLE_SMIMECAP                   119\r
+#define PKCS7_F_PKCS7_VERIFY                            117\r
+#define PKCS7_F_SMIME_READ_PKCS7                        122\r
+#define PKCS7_F_SMIME_TEXT                              123\r
+\r
+/* Reason codes. */\r
+#define PKCS7_R_CERTIFICATE_VERIFY_ERROR                117\r
+#define PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER                 144\r
+#define PKCS7_R_CIPHER_NOT_INITIALIZED                  116\r
+#define PKCS7_R_CONTENT_AND_DATA_PRESENT                118\r
+#define PKCS7_R_DECODE_ERROR                            130\r
+#define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH           100\r
+#define PKCS7_R_DECRYPT_ERROR                           119\r
+#define PKCS7_R_DIGEST_FAILURE                          101\r
+#define PKCS7_R_ERROR_ADDING_RECIPIENT                  120\r
+#define PKCS7_R_ERROR_SETTING_CIPHER                    121\r
+#define PKCS7_R_INVALID_MIME_TYPE                       131\r
+#define PKCS7_R_INVALID_NULL_POINTER                    143\r
+#define PKCS7_R_MIME_NO_CONTENT_TYPE                    132\r
+#define PKCS7_R_MIME_PARSE_ERROR                        133\r
+#define PKCS7_R_MIME_SIG_PARSE_ERROR                    134\r
+#define PKCS7_R_MISSING_CERIPEND_INFO                   103\r
+#define PKCS7_R_NO_CONTENT                              122\r
+#define PKCS7_R_NO_CONTENT_TYPE                                 135\r
+#define PKCS7_R_NO_MULTIPART_BODY_FAILURE               136\r
+#define PKCS7_R_NO_MULTIPART_BOUNDARY                   137\r
+#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE        115\r
+#define PKCS7_R_NO_SIGNATURES_ON_DATA                   123\r
+#define PKCS7_R_NO_SIGNERS                              142\r
+#define PKCS7_R_NO_SIG_CONTENT_TYPE                     138\r
+#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE    104\r
+#define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR               124\r
+#define PKCS7_R_PKCS7_DATAFINAL                                 126\r
+#define PKCS7_R_PKCS7_DATAFINAL_ERROR                   125\r
+#define PKCS7_R_PKCS7_DATASIGN                          145\r
+#define PKCS7_R_PKCS7_PARSE_ERROR                       139\r
+#define PKCS7_R_PKCS7_SIG_PARSE_ERROR                   140\r
+#define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE  127\r
+#define PKCS7_R_SIGNATURE_FAILURE                       105\r
+#define PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND            128\r
+#define PKCS7_R_SIG_INVALID_MIME_TYPE                   141\r
+#define PKCS7_R_SMIME_TEXT_ERROR                        129\r
+#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE              106\r
+#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO                  107\r
+#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST           108\r
+#define PKCS7_R_UNKNOWN_DIGEST_TYPE                     109\r
+#define PKCS7_R_UNKNOWN_OPERATION                       110\r
+#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE                         111\r
+#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE                112\r
+#define PKCS7_R_WRONG_CONTENT_TYPE                      113\r
+#define PKCS7_R_WRONG_PKCS7_TYPE                        114\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pq_compat.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pq_compat.h
new file mode 100644 (file)
index 0000000..2075042
--- /dev/null
@@ -0,0 +1,147 @@
+/* crypto/pqueue/pqueue_compat.h */\r
+/* \r
+ * DTLS implementation written by Nagendra Modadugu\r
+ * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.  \r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@OpenSSL.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#include "opensslconf.h"\r
+#include <openssl/bn.h>\r
+\r
+/* \r
+ * The purpose of this header file is for supporting 64-bit integer\r
+ * manipulation on 32-bit (and lower) machines.  Currently the only\r
+ * such environment is VMS, Utrix and those with smaller default integer\r
+ * sizes than 32 bits.  For all such environment, we fall back to using\r
+ * BIGNUM.  We may need to fine tune the conditions for systems that\r
+ * are incorrectly configured.\r
+ *\r
+ * The only clients of this code are (1) pqueue for priority, and\r
+ * (2) DTLS, for sequence number manipulation.\r
+ */\r
+\r
+#if (defined(THIRTY_TWO_BIT) && !defined(BN_LLONG)) || defined(SIXTEEN_BIT) || defined(EIGHT_BIT)\r
+\r
+#define PQ_64BIT_IS_INTEGER 0\r
+#define PQ_64BIT_IS_BIGNUM 1\r
+\r
+#define PQ_64BIT     BIGNUM\r
+#define PQ_64BIT_CTX BN_CTX\r
+\r
+#define pq_64bit_init(x)           BN_init(x)\r
+#define pq_64bit_free(x)           BN_free(x)\r
+\r
+#define pq_64bit_ctx_new(ctx)      BN_CTX_new()\r
+#define pq_64bit_ctx_free(x)       BN_CTX_free(x)\r
+\r
+#define pq_64bit_assign(x, y)      BN_copy(x, y)\r
+#define pq_64bit_assign_word(x, y) BN_set_word(x, y)\r
+#define pq_64bit_gt(x, y)          BN_ucmp(x, y) >= 1 ? 1 : 0\r
+#define pq_64bit_eq(x, y)          BN_ucmp(x, y) == 0 ? 1 : 0\r
+#define pq_64bit_add_word(x, w)    BN_add_word(x, w)\r
+#define pq_64bit_sub(r, x, y)      BN_sub(r, x, y)\r
+#define pq_64bit_sub_word(x, w)    BN_sub_word(x, w)\r
+#define pq_64bit_mod(r, x, n, ctx) BN_mod(r, x, n, ctx)\r
+\r
+#define pq_64bit_bin2num(bn, bytes, len)   BN_bin2bn(bytes, len, bn)\r
+#define pq_64bit_num2bin(bn, bytes)        BN_bn2bin(bn, bytes)\r
+#define pq_64bit_get_word(x)               BN_get_word(x)\r
+#define pq_64bit_is_bit_set(x, offset)     BN_is_bit_set(x, offset)\r
+#define pq_64bit_lshift(r, x, shift)       BN_lshift(r, x, shift)\r
+#define pq_64bit_set_bit(x, num)           BN_set_bit(x, num)\r
+#define pq_64bit_get_length(x)             BN_num_bits((x))\r
+\r
+#else\r
+\r
+#define PQ_64BIT_IS_INTEGER 1\r
+#define PQ_64BIT_IS_BIGNUM 0\r
+\r
+#if defined(SIXTY_FOUR_BIT)\r
+#define PQ_64BIT BN_ULONG\r
+#define PQ_64BIT_PRINT "%lld"\r
+#elif defined(SIXTY_FOUR_BIT_LONG)\r
+#define PQ_64BIT BN_ULONG\r
+#define PQ_64BIT_PRINT "%ld"\r
+#elif defined(THIRTY_TWO_BIT)\r
+#define PQ_64BIT BN_ULLONG\r
+#define PQ_64BIT_PRINT "%lld"\r
+#endif\r
+\r
+#define PQ_64BIT_CTX      void\r
+\r
+#define pq_64bit_init(x)\r
+#define pq_64bit_free(x)\r
+#define pq_64bit_ctx_new(ctx)        (ctx)\r
+#define pq_64bit_ctx_free(x)\r
+\r
+#define pq_64bit_assign(x, y)        (*(x) = *(y))\r
+#define pq_64bit_assign_word(x, y)   (*(x) = y)\r
+#define pq_64bit_gt(x, y)               (*(x) > *(y))\r
+#define pq_64bit_eq(x, y)            (*(x) == *(y))\r
+#define pq_64bit_add_word(x, w)      (*(x) = (*(x) + (w)))\r
+#define pq_64bit_sub(r, x, y)        (*(r) = (*(x) - *(y)))\r
+#define pq_64bit_sub_word(x, w)      (*(x) = (*(x) - (w)))\r
+#define pq_64bit_mod(r, x, n, ctx)\r
+\r
+#define pq_64bit_bin2num(num, bytes, len) bytes_to_long_long(bytes, num)\r
+#define pq_64bit_num2bin(num, bytes)      long_long_to_bytes(num, bytes)\r
+#define pq_64bit_get_word(x)              *(x)\r
+#define pq_64bit_lshift(r, x, shift)      (*(r) = (*(x) << (shift)))\r
+#define pq_64bit_set_bit(x, num)          do { \\r
+                                              PQ_64BIT mask = 1; \\r
+                                              mask = mask << (num); \\r
+                                              *(x) |= mask; \\r
+                                          } while(0)\r
+#endif /* OPENSSL_SYS_VMS */\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pqueue.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/pqueue.h
new file mode 100644 (file)
index 0000000..699095f
--- /dev/null
@@ -0,0 +1,95 @@
+/* crypto/pqueue/pqueue.h */\r
+/* \r
+ * DTLS implementation written by Nagendra Modadugu\r
+ * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.  \r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@OpenSSL.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_PQUEUE_H\r
+#define HEADER_PQUEUE_H\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#include <openssl/pq_compat.h>\r
+\r
+typedef struct _pqueue *pqueue;\r
+\r
+typedef struct _pitem\r
+       {\r
+       PQ_64BIT priority;\r
+       void *data;\r
+       struct _pitem *next;\r
+       } pitem;\r
+\r
+typedef struct _pitem *piterator;\r
+\r
+pitem *pitem_new(PQ_64BIT priority, void *data);\r
+void   pitem_free(pitem *item);\r
+\r
+pqueue pqueue_new(void);\r
+void   pqueue_free(pqueue pq);\r
+\r
+pitem *pqueue_insert(pqueue pq, pitem *item);\r
+pitem *pqueue_peek(pqueue pq);\r
+pitem *pqueue_pop(pqueue pq);\r
+pitem *pqueue_find(pqueue pq, PQ_64BIT priority);\r
+pitem *pqueue_iterator(pqueue pq);\r
+pitem *pqueue_next(piterator *iter);\r
+\r
+void   pqueue_print(pqueue pq);\r
+\r
+#endif /* ! HEADER_PQUEUE_H */\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rand.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rand.h
new file mode 100644 (file)
index 0000000..e2f9f82
--- /dev/null
@@ -0,0 +1,140 @@
+/* crypto/rand/rand.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_RAND_H\r
+#define HEADER_RAND_H\r
+\r
+#include <stdlib.h>\r
+#include <openssl/ossl_typ.h>\r
+#include <openssl/e_os2.h>\r
+\r
+#if defined(OPENSSL_SYS_WINDOWS)\r
+#include <windows.h>\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#if defined(OPENSSL_FIPS)\r
+#define FIPS_RAND_SIZE_T size_t\r
+#endif\r
+\r
+/* Already defined in ossl_typ.h */\r
+/* typedef struct rand_meth_st RAND_METHOD; */\r
+\r
+struct rand_meth_st\r
+       {\r
+       void (*seed)(const void *buf, int num);\r
+       int (*bytes)(unsigned char *buf, int num);\r
+       void (*cleanup)(void);\r
+       void (*add)(const void *buf, int num, double entropy);\r
+       int (*pseudorand)(unsigned char *buf, int num);\r
+       int (*status)(void);\r
+       };\r
+\r
+#ifdef BN_DEBUG\r
+extern int rand_predictable;\r
+#endif\r
+\r
+int RAND_set_rand_method(const RAND_METHOD *meth);\r
+const RAND_METHOD *RAND_get_rand_method(void);\r
+#ifndef OPENSSL_NO_ENGINE\r
+int RAND_set_rand_engine(ENGINE *engine);\r
+#endif\r
+RAND_METHOD *RAND_SSLeay(void);\r
+void RAND_cleanup(void );\r
+int  RAND_bytes(unsigned char *buf,int num);\r
+int  RAND_pseudo_bytes(unsigned char *buf,int num);\r
+void RAND_seed(const void *buf,int num);\r
+void RAND_add(const void *buf,int num,double entropy);\r
+int  RAND_load_file(const char *file,long max_bytes);\r
+int  RAND_write_file(const char *file);\r
+const char *RAND_file_name(char *file,size_t num);\r
+int RAND_status(void);\r
+int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes);\r
+int RAND_egd(const char *path);\r
+int RAND_egd_bytes(const char *path,int bytes);\r
+int RAND_poll(void);\r
+\r
+#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)\r
+\r
+void RAND_screen(void);\r
+int RAND_event(UINT, WPARAM, LPARAM);\r
+\r
+#endif\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_RAND_strings(void);\r
+\r
+/* Error codes for the RAND functions. */\r
+\r
+/* Function codes. */\r
+#define RAND_F_RAND_GET_RAND_METHOD                     101\r
+#define RAND_F_SSLEAY_RAND_BYTES                        100\r
+\r
+/* Reason codes. */\r
+#define RAND_R_PRNG_NOT_SEEDED                          100\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rc2.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rc2.h
new file mode 100644 (file)
index 0000000..13edfaf
--- /dev/null
@@ -0,0 +1,101 @@
+/* crypto/rc2/rc2.h */\r
+/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_RC2_H\r
+#define HEADER_RC2_H\r
+\r
+#include <openssl/opensslconf.h> /* OPENSSL_NO_RC2, RC2_INT */\r
+#ifdef OPENSSL_NO_RC2\r
+#error RC2 is disabled.\r
+#endif\r
+\r
+#define RC2_ENCRYPT    1\r
+#define RC2_DECRYPT    0\r
+\r
+#define RC2_BLOCK      8\r
+#define RC2_KEY_LENGTH 16\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct rc2_key_st\r
+       {\r
+       RC2_INT data[64];\r
+       } RC2_KEY;\r
+\r
\r
+void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,int bits);\r
+void RC2_ecb_encrypt(const unsigned char *in,unsigned char *out,RC2_KEY *key,\r
+                    int enc);\r
+void RC2_encrypt(unsigned long *data,RC2_KEY *key);\r
+void RC2_decrypt(unsigned long *data,RC2_KEY *key);\r
+void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,\r
+       RC2_KEY *ks, unsigned char *iv, int enc);\r
+void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out,\r
+                      long length, RC2_KEY *schedule, unsigned char *ivec,\r
+                      int *num, int enc);\r
+void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out,\r
+                      long length, RC2_KEY *schedule, unsigned char *ivec,\r
+                      int *num);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rc4.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rc4.h
new file mode 100644 (file)
index 0000000..676ffdb
--- /dev/null
@@ -0,0 +1,87 @@
+/* crypto/rc4/rc4.h */\r
+/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_RC4_H\r
+#define HEADER_RC4_H\r
+\r
+#include <openssl/opensslconf.h> /* OPENSSL_NO_RC4, RC4_INT */\r
+#ifdef OPENSSL_NO_RC4\r
+#error RC4 is disabled.\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct rc4_key_st\r
+       {\r
+       RC4_INT x,y;\r
+       RC4_INT data[256];\r
+       } RC4_KEY;\r
+\r
\r
+const char *RC4_options(void);\r
+void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);\r
+void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,\r
+               unsigned char *outdata);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rc5.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rc5.h
new file mode 100644 (file)
index 0000000..ea22727
--- /dev/null
@@ -0,0 +1,120 @@
+/* crypto/rc5/rc5.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_RC5_H\r
+#define HEADER_RC5_H\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef OPENSSL_NO_RC5\r
+#error RC5 is disabled.\r
+#endif\r
+\r
+#define RC5_ENCRYPT    1\r
+#define RC5_DECRYPT    0\r
+\r
+/* 32 bit.  For Alpha, things may get weird */\r
+#define RC5_32_INT unsigned long\r
+\r
+#define RC5_32_BLOCK           8\r
+#define RC5_32_KEY_LENGTH      16 /* This is a default, max is 255 */\r
+\r
+/* This are the only values supported.  Tweak the code if you want more\r
+ * The most supported modes will be\r
+ * RC5-32/12/16\r
+ * RC5-32/16/8\r
+ */\r
+#define RC5_8_ROUNDS   8\r
+#define RC5_12_ROUNDS  12\r
+#define RC5_16_ROUNDS  16\r
+\r
+typedef struct rc5_key_st\r
+       {\r
+       /* Number of rounds */\r
+       int rounds;\r
+       RC5_32_INT data[2*(RC5_16_ROUNDS+1)];\r
+       } RC5_32_KEY;\r
+\r
+#ifdef OPENSSL_FIPS \r
+void private_RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data,\r
+       int rounds);\r
+#endif\r
+void RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data,\r
+       int rounds);\r
+void RC5_32_ecb_encrypt(const unsigned char *in,unsigned char *out,RC5_32_KEY *key,\r
+       int enc);\r
+void RC5_32_encrypt(unsigned long *data,RC5_32_KEY *key);\r
+void RC5_32_decrypt(unsigned long *data,RC5_32_KEY *key);\r
+void RC5_32_cbc_encrypt(const unsigned char *in, unsigned char *out,\r
+                       long length, RC5_32_KEY *ks, unsigned char *iv,\r
+                       int enc);\r
+void RC5_32_cfb64_encrypt(const unsigned char *in, unsigned char *out,\r
+                         long length, RC5_32_KEY *schedule,\r
+                         unsigned char *ivec, int *num, int enc);\r
+void RC5_32_ofb64_encrypt(const unsigned char *in, unsigned char *out,\r
+                         long length, RC5_32_KEY *schedule,\r
+                         unsigned char *ivec, int *num);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ripemd.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ripemd.h
new file mode 100644 (file)
index 0000000..f9cdf9d
--- /dev/null
@@ -0,0 +1,103 @@
+/* crypto/ripemd/ripemd.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_RIPEMD_H\r
+#define HEADER_RIPEMD_H\r
+\r
+#include <openssl/e_os2.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef OPENSSL_NO_RIPEMD\r
+#error RIPEMD is disabled.\r
+#endif\r
+\r
+#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)\r
+#define RIPEMD160_LONG unsigned long\r
+#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)\r
+#define RIPEMD160_LONG unsigned long\r
+#define RIPEMD160_LONG_LOG2 3\r
+#else\r
+#define RIPEMD160_LONG unsigned int\r
+#endif\r
+\r
+#define RIPEMD160_CBLOCK       64\r
+#define RIPEMD160_LBLOCK       (RIPEMD160_CBLOCK/4)\r
+#define RIPEMD160_DIGEST_LENGTH        20\r
+\r
+typedef struct RIPEMD160state_st\r
+       {\r
+       RIPEMD160_LONG A,B,C,D,E;\r
+       RIPEMD160_LONG Nl,Nh;\r
+       RIPEMD160_LONG data[RIPEMD160_LBLOCK];\r
+       unsigned int   num;\r
+       } RIPEMD160_CTX;\r
+\r
+int RIPEMD160_Init(RIPEMD160_CTX *c);\r
+int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len);\r
+int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);\r
+unsigned char *RIPEMD160(const unsigned char *d, size_t n,\r
+       unsigned char *md);\r
+void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b);\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rsa.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/rsa.h
new file mode 100644 (file)
index 0000000..1cee974
--- /dev/null
@@ -0,0 +1,429 @@
+/* crypto/rsa/rsa.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_RSA_H\r
+#define HEADER_RSA_H\r
+\r
+#include <openssl/asn1.h>\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+#include <openssl/bio.h>\r
+#endif\r
+#include <openssl/crypto.h>\r
+#include <openssl/ossl_typ.h>\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#include <openssl/bn.h>\r
+#endif\r
+\r
+#ifdef OPENSSL_NO_RSA\r
+#error RSA is disabled.\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Declared already in ossl_typ.h */\r
+/* typedef struct rsa_st RSA; */\r
+/* typedef struct rsa_meth_st RSA_METHOD; */\r
+\r
+struct rsa_meth_st\r
+       {\r
+       const char *name;\r
+       int (*rsa_pub_enc)(int flen,const unsigned char *from,\r
+                          unsigned char *to,\r
+                          RSA *rsa,int padding);\r
+       int (*rsa_pub_dec)(int flen,const unsigned char *from,\r
+                          unsigned char *to,\r
+                          RSA *rsa,int padding);\r
+       int (*rsa_priv_enc)(int flen,const unsigned char *from,\r
+                           unsigned char *to,\r
+                           RSA *rsa,int padding);\r
+       int (*rsa_priv_dec)(int flen,const unsigned char *from,\r
+                           unsigned char *to,\r
+                           RSA *rsa,int padding);\r
+       int (*rsa_mod_exp)(BIGNUM *r0,const BIGNUM *I,RSA *rsa,BN_CTX *ctx); /* Can be null */\r
+       int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\r
+                         const BIGNUM *m, BN_CTX *ctx,\r
+                         BN_MONT_CTX *m_ctx); /* Can be null */\r
+       int (*init)(RSA *rsa);          /* called at new */\r
+       int (*finish)(RSA *rsa);        /* called at free */\r
+       int flags;                      /* RSA_METHOD_FLAG_* things */\r
+       char *app_data;                 /* may be needed! */\r
+/* New sign and verify functions: some libraries don't allow arbitrary data\r
+ * to be signed/verified: this allows them to be used. Note: for this to work\r
+ * the RSA_public_decrypt() and RSA_private_encrypt() should *NOT* be used\r
+ * RSA_sign(), RSA_verify() should be used instead. Note: for backwards\r
+ * compatibility this functionality is only enabled if the RSA_FLAG_SIGN_VER\r
+ * option is set in 'flags'.\r
+ */\r
+       int (*rsa_sign)(int type,\r
+               const unsigned char *m, unsigned int m_length,\r
+               unsigned char *sigret, unsigned int *siglen, const RSA *rsa);\r
+       int (*rsa_verify)(int dtype,\r
+               const unsigned char *m, unsigned int m_length,\r
+               unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);\r
+/* If this callback is NULL, the builtin software RSA key-gen will be used. This\r
+ * is for behavioural compatibility whilst the code gets rewired, but one day\r
+ * it would be nice to assume there are no such things as "builtin software"\r
+ * implementations. */\r
+       int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);\r
+       };\r
+\r
+struct rsa_st\r
+       {\r
+       /* The first parameter is used to pickup errors where\r
+        * this is passed instead of aEVP_PKEY, it is set to 0 */\r
+       int pad;\r
+       long version;\r
+       const RSA_METHOD *meth;\r
+       /* functional reference if 'meth' is ENGINE-provided */\r
+       ENGINE *engine;\r
+       BIGNUM *n;\r
+       BIGNUM *e;\r
+       BIGNUM *d;\r
+       BIGNUM *p;\r
+       BIGNUM *q;\r
+       BIGNUM *dmp1;\r
+       BIGNUM *dmq1;\r
+       BIGNUM *iqmp;\r
+       /* be careful using this if the RSA structure is shared */\r
+       CRYPTO_EX_DATA ex_data;\r
+       int references;\r
+       int flags;\r
+\r
+       /* Used to cache montgomery values */\r
+       BN_MONT_CTX *_method_mod_n;\r
+       BN_MONT_CTX *_method_mod_p;\r
+       BN_MONT_CTX *_method_mod_q;\r
+\r
+       /* all BIGNUM values are actually in the following data, if it is not\r
+        * NULL */\r
+       char *bignum_data;\r
+       BN_BLINDING *blinding;\r
+       BN_BLINDING *mt_blinding;\r
+       };\r
+\r
+#define RSA_3  0x3L\r
+#define RSA_F4 0x10001L\r
+\r
+#define RSA_METHOD_FLAG_NO_CHECK       0x0001 /* don't check pub/private match */\r
+\r
+#define RSA_FLAG_CACHE_PUBLIC          0x0002\r
+#define RSA_FLAG_CACHE_PRIVATE         0x0004\r
+#define RSA_FLAG_BLINDING              0x0008\r
+#define RSA_FLAG_THREAD_SAFE           0x0010\r
+/* This flag means the private key operations will be handled by rsa_mod_exp\r
+ * and that they do not depend on the private key components being present:\r
+ * for example a key stored in external hardware. Without this flag bn_mod_exp\r
+ * gets called when private key components are absent.\r
+ */\r
+#define RSA_FLAG_EXT_PKEY              0x0020\r
+\r
+/* This flag in the RSA_METHOD enables the new rsa_sign, rsa_verify functions.\r
+ */\r
+#define RSA_FLAG_SIGN_VER              0x0040\r
+\r
+#define RSA_FLAG_NO_BLINDING           0x0080 /* new with 0.9.6j and 0.9.7b; the built-in\r
+                                                * RSA implementation now uses blinding by\r
+                                                * default (ignoring RSA_FLAG_BLINDING),\r
+                                                * but other engines might not need it\r
+                                                */\r
+#define RSA_FLAG_NO_EXP_CONSTTIME      0x0100 /* new with 0.9.7h; the built-in RSA\r
+                                                * implementation now uses constant time\r
+                                                * modular exponentiation for secret exponents\r
+                                                * by default. This flag causes the\r
+                                                * faster variable sliding window method to\r
+                                                * be used for all exponents.\r
+                                                */\r
+\r
+#define RSA_PKCS1_PADDING      1\r
+#define RSA_SSLV23_PADDING     2\r
+#define RSA_NO_PADDING         3\r
+#define RSA_PKCS1_OAEP_PADDING 4\r
+#define RSA_X931_PADDING       5\r
+\r
+#define RSA_PKCS1_PADDING_SIZE 11\r
+\r
+#define RSA_set_app_data(s,arg)         RSA_set_ex_data(s,0,arg)\r
+#define RSA_get_app_data(s)             RSA_get_ex_data(s,0)\r
+\r
+RSA *  RSA_new(void);\r
+RSA *  RSA_new_method(ENGINE *engine);\r
+int    RSA_size(const RSA *);\r
+\r
+/* Deprecated version */\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+RSA *  RSA_generate_key(int bits, unsigned long e,void\r
+               (*callback)(int,int,void *),void *cb_arg);\r
+#endif /* !defined(OPENSSL_NO_DEPRECATED) */\r
+\r
+/* New version */\r
+int    RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);\r
+\r
+int    RSA_check_key(const RSA *);\r
+       /* next 4 return -1 on error */\r
+int    RSA_public_encrypt(int flen, const unsigned char *from,\r
+               unsigned char *to, RSA *rsa,int padding);\r
+int    RSA_private_encrypt(int flen, const unsigned char *from,\r
+               unsigned char *to, RSA *rsa,int padding);\r
+int    RSA_public_decrypt(int flen, const unsigned char *from, \r
+               unsigned char *to, RSA *rsa,int padding);\r
+int    RSA_private_decrypt(int flen, const unsigned char *from, \r
+               unsigned char *to, RSA *rsa,int padding);\r
+void   RSA_free (RSA *r);\r
+/* "up" the RSA object's reference count */\r
+int    RSA_up_ref(RSA *r);\r
+\r
+int    RSA_flags(const RSA *r);\r
+\r
+void RSA_set_default_method(const RSA_METHOD *meth);\r
+const RSA_METHOD *RSA_get_default_method(void);\r
+const RSA_METHOD *RSA_get_method(const RSA *rsa);\r
+int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);\r
+\r
+/* This function needs the memory locking malloc callbacks to be installed */\r
+int RSA_memory_lock(RSA *r);\r
+\r
+/* these are the actual SSLeay RSA functions */\r
+const RSA_METHOD *RSA_PKCS1_SSLeay(void);\r
+\r
+const RSA_METHOD *RSA_null_method(void);\r
+\r
+DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey)\r
+DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey)\r
+\r
+#ifndef OPENSSL_NO_FP_API\r
+int    RSA_print_fp(FILE *fp, const RSA *r,int offset);\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+int    RSA_print(BIO *bp, const RSA *r,int offset);\r
+#endif\r
+\r
+int i2d_RSA_NET(const RSA *a, unsigned char **pp,\r
+               int (*cb)(char *buf, int len, const char *prompt, int verify),\r
+               int sgckey);\r
+RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length,\r
+                int (*cb)(char *buf, int len, const char *prompt, int verify),\r
+                int sgckey);\r
+\r
+int i2d_Netscape_RSA(const RSA *a, unsigned char **pp,\r
+                    int (*cb)(char *buf, int len, const char *prompt,\r
+                              int verify));\r
+RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length,\r
+                     int (*cb)(char *buf, int len, const char *prompt,\r
+                               int verify));\r
+\r
+/* The following 2 functions sign and verify a X509_SIG ASN1 object\r
+ * inside PKCS#1 padded RSA encryption */\r
+int RSA_sign(int type, const unsigned char *m, unsigned int m_length,\r
+       unsigned char *sigret, unsigned int *siglen, RSA *rsa);\r
+int RSA_verify(int type, const unsigned char *m, unsigned int m_length,\r
+       unsigned char *sigbuf, unsigned int siglen, RSA *rsa);\r
+\r
+/* The following 2 function sign and verify a ASN1_OCTET_STRING\r
+ * object inside PKCS#1 padded RSA encryption */\r
+int RSA_sign_ASN1_OCTET_STRING(int type,\r
+       const unsigned char *m, unsigned int m_length,\r
+       unsigned char *sigret, unsigned int *siglen, RSA *rsa);\r
+int RSA_verify_ASN1_OCTET_STRING(int type,\r
+       const unsigned char *m, unsigned int m_length,\r
+       unsigned char *sigbuf, unsigned int siglen, RSA *rsa);\r
+\r
+int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);\r
+void RSA_blinding_off(RSA *rsa);\r
+BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx);\r
+\r
+int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen,\r
+       const unsigned char *f,int fl);\r
+int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen,\r
+       const unsigned char *f,int fl,int rsa_len);\r
+int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen,\r
+       const unsigned char *f,int fl);\r
+int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen,\r
+       const unsigned char *f,int fl,int rsa_len);\r
+int PKCS1_MGF1(unsigned char *mask, long len,\r
+       const unsigned char *seed, long seedlen, const EVP_MD *dgst);\r
+int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen,\r
+       const unsigned char *f,int fl,\r
+       const unsigned char *p,int pl);\r
+int RSA_padding_check_PKCS1_OAEP(unsigned char *to,int tlen,\r
+       const unsigned char *f,int fl,int rsa_len,\r
+       const unsigned char *p,int pl);\r
+int RSA_padding_add_SSLv23(unsigned char *to,int tlen,\r
+       const unsigned char *f,int fl);\r
+int RSA_padding_check_SSLv23(unsigned char *to,int tlen,\r
+       const unsigned char *f,int fl,int rsa_len);\r
+int RSA_padding_add_none(unsigned char *to,int tlen,\r
+       const unsigned char *f,int fl);\r
+int RSA_padding_check_none(unsigned char *to,int tlen,\r
+       const unsigned char *f,int fl,int rsa_len);\r
+int RSA_padding_add_X931(unsigned char *to,int tlen,\r
+       const unsigned char *f,int fl);\r
+int RSA_padding_check_X931(unsigned char *to,int tlen,\r
+       const unsigned char *f,int fl,int rsa_len);\r
+int RSA_X931_hash_id(int nid);\r
+\r
+int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,\r
+                       const EVP_MD *Hash, const unsigned char *EM, int sLen);\r
+int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,\r
+                       const unsigned char *mHash,\r
+                       const EVP_MD *Hash, int sLen);\r
+\r
+int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,\r
+       CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+int RSA_set_ex_data(RSA *r,int idx,void *arg);\r
+void *RSA_get_ex_data(const RSA *r, int idx);\r
+\r
+RSA *RSAPublicKey_dup(RSA *rsa);\r
+RSA *RSAPrivateKey_dup(RSA *rsa);\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_RSA_strings(void);\r
+\r
+/* Error codes for the RSA functions. */\r
+\r
+/* Function codes. */\r
+#define RSA_F_MEMORY_LOCK                               100\r
+#define RSA_F_RSA_BUILTIN_KEYGEN                        129\r
+#define RSA_F_RSA_CHECK_KEY                             123\r
+#define RSA_F_RSA_EAY_PRIVATE_DECRYPT                   101\r
+#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT                   102\r
+#define RSA_F_RSA_EAY_PUBLIC_DECRYPT                    103\r
+#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT                    104\r
+#define RSA_F_RSA_GENERATE_KEY                          105\r
+#define RSA_F_RSA_MEMORY_LOCK                           130\r
+#define RSA_F_RSA_NEW_METHOD                            106\r
+#define RSA_F_RSA_NULL                                  124\r
+#define RSA_F_RSA_NULL_MOD_EXP                          131\r
+#define RSA_F_RSA_NULL_PRIVATE_DECRYPT                  132\r
+#define RSA_F_RSA_NULL_PRIVATE_ENCRYPT                  133\r
+#define RSA_F_RSA_NULL_PUBLIC_DECRYPT                   134\r
+#define RSA_F_RSA_NULL_PUBLIC_ENCRYPT                   135\r
+#define RSA_F_RSA_PADDING_ADD_NONE                      107\r
+#define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP                121\r
+#define RSA_F_RSA_PADDING_ADD_PKCS1_PSS                         125\r
+#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1              108\r
+#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2              109\r
+#define RSA_F_RSA_PADDING_ADD_SSLV23                    110\r
+#define RSA_F_RSA_PADDING_ADD_X931                      127\r
+#define RSA_F_RSA_PADDING_CHECK_NONE                    111\r
+#define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP              122\r
+#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1            112\r
+#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2            113\r
+#define RSA_F_RSA_PADDING_CHECK_SSLV23                  114\r
+#define RSA_F_RSA_PADDING_CHECK_X931                    128\r
+#define RSA_F_RSA_PRINT                                         115\r
+#define RSA_F_RSA_PRINT_FP                              116\r
+#define RSA_F_RSA_SETUP_BLINDING                        136\r
+#define RSA_F_RSA_SIGN                                  117\r
+#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING                118\r
+#define RSA_F_RSA_VERIFY                                119\r
+#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING              120\r
+#define RSA_F_RSA_VERIFY_PKCS1_PSS                      126\r
+\r
+/* Reason codes. */\r
+#define RSA_R_ALGORITHM_MISMATCH                        100\r
+#define RSA_R_BAD_E_VALUE                               101\r
+#define RSA_R_BAD_FIXED_HEADER_DECRYPT                  102\r
+#define RSA_R_BAD_PAD_BYTE_COUNT                        103\r
+#define RSA_R_BAD_SIGNATURE                             104\r
+#define RSA_R_BLOCK_TYPE_IS_NOT_01                      106\r
+#define RSA_R_BLOCK_TYPE_IS_NOT_02                      107\r
+#define RSA_R_DATA_GREATER_THAN_MOD_LEN                         108\r
+#define RSA_R_DATA_TOO_LARGE                            109\r
+#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE               110\r
+#define RSA_R_DATA_TOO_LARGE_FOR_MODULUS                132\r
+#define RSA_R_DATA_TOO_SMALL                            111\r
+#define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE               122\r
+#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY                112\r
+#define RSA_R_DMP1_NOT_CONGRUENT_TO_D                   124\r
+#define RSA_R_DMQ1_NOT_CONGRUENT_TO_D                   125\r
+#define RSA_R_D_E_NOT_CONGRUENT_TO_1                    123\r
+#define RSA_R_FIRST_OCTET_INVALID                       133\r
+#define RSA_R_INVALID_HEADER                            137\r
+#define RSA_R_INVALID_MESSAGE_LENGTH                    131\r
+#define RSA_R_INVALID_PADDING                           138\r
+#define RSA_R_INVALID_TRAILER                           139\r
+#define RSA_R_IQMP_NOT_INVERSE_OF_Q                     126\r
+#define RSA_R_KEY_SIZE_TOO_SMALL                        120\r
+#define RSA_R_LAST_OCTET_INVALID                        134\r
+#define RSA_R_NO_PUBLIC_EXPONENT                        140\r
+#define RSA_R_NULL_BEFORE_BLOCK_MISSING                         113\r
+#define RSA_R_N_DOES_NOT_EQUAL_P_Q                      127\r
+#define RSA_R_OAEP_DECODING_ERROR                       121\r
+#define RSA_R_SLEN_RECOVERY_FAILED                      135\r
+#define RSA_R_PADDING_CHECK_FAILED                      114\r
+#define RSA_R_P_NOT_PRIME                               128\r
+#define RSA_R_Q_NOT_PRIME                               129\r
+#define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED              130\r
+#define RSA_R_SSLV3_ROLLBACK_ATTACK                     115\r
+#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116\r
+#define RSA_R_UNKNOWN_ALGORITHM_TYPE                    117\r
+#define RSA_R_UNKNOWN_PADDING_TYPE                      118\r
+#define RSA_R_WRONG_SIGNATURE_LENGTH                    119\r
+#define RSA_R_SLEN_CHECK_FAILED                                 136\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/safestack.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/safestack.h
new file mode 100644 (file)
index 0000000..10017f2
--- /dev/null
@@ -0,0 +1,1784 @@
+/* ====================================================================\r
+ * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_SAFESTACK_H\r
+#define HEADER_SAFESTACK_H\r
+\r
+#include <openssl/stack.h>\r
+\r
+typedef void (*openssl_fptr)(void);\r
+#define openssl_fcast(f) ((openssl_fptr)f)\r
+\r
+#ifdef DEBUG_SAFESTACK\r
+\r
+#define STACK_OF(type) struct stack_st_##type\r
+#define PREDECLARE_STACK_OF(type) STACK_OF(type);\r
+\r
+#define DECLARE_STACK_OF(type) \\r
+STACK_OF(type) \\r
+    { \\r
+    STACK stack; \\r
+    };\r
+\r
+#define IMPLEMENT_STACK_OF(type) /* nada (obsolete in new safestack approach)*/\r
+\r
+/* SKM_sk_... stack macros are internal to safestack.h:\r
+ * never use them directly, use sk_<type>_... instead */\r
+#define SKM_sk_new(type, cmp) \\r
+       ((STACK_OF(type) * (*)(int (*)(const type * const *, const type * const *)))openssl_fcast(sk_new))(cmp)\r
+#define SKM_sk_new_null(type) \\r
+       ((STACK_OF(type) * (*)(void))openssl_fcast(sk_new_null))()\r
+#define SKM_sk_free(type, st) \\r
+       ((void (*)(STACK_OF(type) *))openssl_fcast(sk_free))(st)\r
+#define SKM_sk_num(type, st) \\r
+       ((int (*)(const STACK_OF(type) *))openssl_fcast(sk_num))(st)\r
+#define SKM_sk_value(type, st,i) \\r
+       ((type * (*)(const STACK_OF(type) *, int))openssl_fcast(sk_value))(st, i)\r
+#define SKM_sk_set(type, st,i,val) \\r
+       ((type * (*)(STACK_OF(type) *, int, type *))openssl_fcast(sk_set))(st, i, val)\r
+#define SKM_sk_zero(type, st) \\r
+       ((void (*)(STACK_OF(type) *))openssl_fcast(sk_zero))(st)\r
+#define SKM_sk_push(type, st,val) \\r
+       ((int (*)(STACK_OF(type) *, type *))openssl_fcast(sk_push))(st, val)\r
+#define SKM_sk_unshift(type, st,val) \\r
+       ((int (*)(STACK_OF(type) *, type *))openssl_fcast(sk_unshift))(st, val)\r
+#define SKM_sk_find(type, st,val) \\r
+       ((int (*)(STACK_OF(type) *, type *))openssl_fcast(sk_find))(st, val)\r
+#define SKM_sk_delete(type, st,i) \\r
+       ((type * (*)(STACK_OF(type) *, int))openssl_fcast(sk_delete))(st, i)\r
+#define SKM_sk_delete_ptr(type, st,ptr) \\r
+       ((type * (*)(STACK_OF(type) *, type *))openssl_fcast(sk_delete_ptr))(st, ptr)\r
+#define SKM_sk_insert(type, st,val,i) \\r
+       ((int (*)(STACK_OF(type) *, type *, int))openssl_fcast(sk_insert))(st, val, i)\r
+#define SKM_sk_set_cmp_func(type, st,cmp) \\r
+       ((int (*(*)(STACK_OF(type) *, int (*)(const type * const *, const type * const *))) \\r
+         (const type * const *, const type * const *))openssl_fcast(sk_set_cmp_func))\\r
+       (st, cmp)\r
+#define SKM_sk_dup(type, st) \\r
+       ((STACK_OF(type) *(*)(STACK_OF(type) *))openssl_fcast(sk_dup))(st)\r
+#define SKM_sk_pop_free(type, st,free_func) \\r
+       ((void (*)(STACK_OF(type) *, void (*)(type *)))openssl_fcast(sk_pop_free))\\r
+       (st, free_func)\r
+#define SKM_sk_shift(type, st) \\r
+       ((type * (*)(STACK_OF(type) *))openssl_fcast(sk_shift))(st)\r
+#define SKM_sk_pop(type, st) \\r
+       ((type * (*)(STACK_OF(type) *))openssl_fcast(sk_pop))(st)\r
+#define SKM_sk_sort(type, st) \\r
+       ((void (*)(STACK_OF(type) *))openssl_fcast(sk_sort))(st)\r
+#define SKM_sk_is_sorted(type, st) \\r
+       ((int (*)(const STACK_OF(type) *))openssl_fcast(sk_is_sorted))(st)\r
+\r
+#define        SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+((STACK_OF(type) * (*) (STACK_OF(type) **,const unsigned char **, long , \\r
+                         type *(*)(type **, const unsigned char **,long), \\r
+                                void (*)(type *), int ,int )) openssl_fcast(d2i_ASN1_SET)) \\r
+                       (st,pp,length, d2i_func, free_func, ex_tag,ex_class)\r
+#define        SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       ((int (*)(STACK_OF(type) *,unsigned char **, \\r
+        int (*)(type *,unsigned char **), int , int , int)) openssl_fcast(i2d_ASN1_SET)) \\r
+                                               (st,pp,i2d_func,ex_tag,ex_class,is_set)\r
+\r
+#define        SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \\r
+       ((unsigned char *(*)(STACK_OF(type) *, \\r
+        int (*)(type *,unsigned char **), unsigned char **,int *)) openssl_fcast(ASN1_seq_pack)) \\r
+                               (st, i2d_func, buf, len)\r
+#define        SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \\r
+       ((STACK_OF(type) * (*)(const unsigned char *,int, \\r
+                              type *(*)(type **,const unsigned char **, long), \\r
+                              void (*)(type *)))openssl_fcast(ASN1_seq_unpack)) \\r
+                                       (buf,len,d2i_func, free_func)\r
+\r
+#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \\r
+       ((STACK_OF(type) * (*)(X509_ALGOR *, \\r
+                       type *(*)(type **, const unsigned char **, long), \\r
+                               void (*)(type *), \\r
+                                const char *, int, \\r
+                                ASN1_STRING *, int))PKCS12_decrypt_d2i) \\r
+                               (algor,d2i_func,free_func,pass,passlen,oct,seq)\r
+\r
+#else\r
+\r
+#define STACK_OF(type) STACK\r
+#define PREDECLARE_STACK_OF(type) /* nada */\r
+#define DECLARE_STACK_OF(type)    /* nada */\r
+#define IMPLEMENT_STACK_OF(type)  /* nada */\r
+\r
+#define SKM_sk_new(type, cmp) \\r
+       sk_new((int (*)(const char * const *, const char * const *))(cmp))\r
+#define SKM_sk_new_null(type) \\r
+       sk_new_null()\r
+#define SKM_sk_free(type, st) \\r
+       sk_free(st)\r
+#define SKM_sk_num(type, st) \\r
+       sk_num(st)\r
+#define SKM_sk_value(type, st,i) \\r
+       ((type *)sk_value(st, i))\r
+#define SKM_sk_set(type, st,i,val) \\r
+       ((type *)sk_set(st, i,(char *)val))\r
+#define SKM_sk_zero(type, st) \\r
+       sk_zero(st)\r
+#define SKM_sk_push(type, st,val) \\r
+       sk_push(st, (char *)val)\r
+#define SKM_sk_unshift(type, st,val) \\r
+       sk_unshift(st, val)\r
+#define SKM_sk_find(type, st,val) \\r
+       sk_find(st, (char *)val)\r
+#define SKM_sk_delete(type, st,i) \\r
+       ((type *)sk_delete(st, i))\r
+#define SKM_sk_delete_ptr(type, st,ptr) \\r
+       ((type *)sk_delete_ptr(st,(char *)ptr))\r
+#define SKM_sk_insert(type, st,val,i) \\r
+       sk_insert(st, (char *)val, i)\r
+#define SKM_sk_set_cmp_func(type, st,cmp) \\r
+       ((int (*)(const type * const *,const type * const *)) \\r
+       sk_set_cmp_func(st, (int (*)(const char * const *, const char * const *))(cmp)))\r
+#define SKM_sk_dup(type, st) \\r
+       sk_dup(st)\r
+#define SKM_sk_pop_free(type, st,free_func) \\r
+       sk_pop_free(st, (void (*)(void *))free_func)\r
+#define SKM_sk_shift(type, st) \\r
+       ((type *)sk_shift(st))\r
+#define SKM_sk_pop(type, st) \\r
+       ((type *)sk_pop(st))\r
+#define SKM_sk_sort(type, st) \\r
+       sk_sort(st)\r
+#define SKM_sk_is_sorted(type, st) \\r
+       sk_is_sorted(st)\r
+\r
+#define        SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       d2i_ASN1_SET(st,pp,length, (void *(*)(void ** ,const unsigned char ** ,long))d2i_func, (void (*)(void *))free_func, ex_tag,ex_class)\r
+#define        SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       i2d_ASN1_SET(st,pp,(int (*)(void *, unsigned char **))i2d_func,ex_tag,ex_class,is_set)\r
+\r
+#define        SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \\r
+       ASN1_seq_pack(st, (int (*)(void *, unsigned char **))i2d_func, buf, len)\r
+#define        SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \\r
+       ASN1_seq_unpack(buf,len,(void *(*)(void **,const unsigned char **,long))d2i_func, (void(*)(void *))free_func)\r
+\r
+#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \\r
+       ((STACK *)PKCS12_decrypt_d2i(algor,(char *(*)())d2i_func, (void(*)(void *))free_func,pass,passlen,oct,seq))\r
+\r
+#endif\r
+\r
+/* This block of defines is updated by util/mkstack.pl, please do not touch! */\r
+#define sk_ACCESS_DESCRIPTION_new(st) SKM_sk_new(ACCESS_DESCRIPTION, (st))\r
+#define sk_ACCESS_DESCRIPTION_new_null() SKM_sk_new_null(ACCESS_DESCRIPTION)\r
+#define sk_ACCESS_DESCRIPTION_free(st) SKM_sk_free(ACCESS_DESCRIPTION, (st))\r
+#define sk_ACCESS_DESCRIPTION_num(st) SKM_sk_num(ACCESS_DESCRIPTION, (st))\r
+#define sk_ACCESS_DESCRIPTION_value(st, i) SKM_sk_value(ACCESS_DESCRIPTION, (st), (i))\r
+#define sk_ACCESS_DESCRIPTION_set(st, i, val) SKM_sk_set(ACCESS_DESCRIPTION, (st), (i), (val))\r
+#define sk_ACCESS_DESCRIPTION_zero(st) SKM_sk_zero(ACCESS_DESCRIPTION, (st))\r
+#define sk_ACCESS_DESCRIPTION_push(st, val) SKM_sk_push(ACCESS_DESCRIPTION, (st), (val))\r
+#define sk_ACCESS_DESCRIPTION_unshift(st, val) SKM_sk_unshift(ACCESS_DESCRIPTION, (st), (val))\r
+#define sk_ACCESS_DESCRIPTION_find(st, val) SKM_sk_find(ACCESS_DESCRIPTION, (st), (val))\r
+#define sk_ACCESS_DESCRIPTION_find_ex(st, val) SKM_sk_find_ex(ACCESS_DESCRIPTION, (st), (val))\r
+#define sk_ACCESS_DESCRIPTION_delete(st, i) SKM_sk_delete(ACCESS_DESCRIPTION, (st), (i))\r
+#define sk_ACCESS_DESCRIPTION_delete_ptr(st, ptr) SKM_sk_delete_ptr(ACCESS_DESCRIPTION, (st), (ptr))\r
+#define sk_ACCESS_DESCRIPTION_insert(st, val, i) SKM_sk_insert(ACCESS_DESCRIPTION, (st), (val), (i))\r
+#define sk_ACCESS_DESCRIPTION_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ACCESS_DESCRIPTION, (st), (cmp))\r
+#define sk_ACCESS_DESCRIPTION_dup(st) SKM_sk_dup(ACCESS_DESCRIPTION, st)\r
+#define sk_ACCESS_DESCRIPTION_pop_free(st, free_func) SKM_sk_pop_free(ACCESS_DESCRIPTION, (st), (free_func))\r
+#define sk_ACCESS_DESCRIPTION_shift(st) SKM_sk_shift(ACCESS_DESCRIPTION, (st))\r
+#define sk_ACCESS_DESCRIPTION_pop(st) SKM_sk_pop(ACCESS_DESCRIPTION, (st))\r
+#define sk_ACCESS_DESCRIPTION_sort(st) SKM_sk_sort(ACCESS_DESCRIPTION, (st))\r
+#define sk_ACCESS_DESCRIPTION_is_sorted(st) SKM_sk_is_sorted(ACCESS_DESCRIPTION, (st))\r
+\r
+#define sk_ASN1_GENERALSTRING_new(st) SKM_sk_new(ASN1_GENERALSTRING, (st))\r
+#define sk_ASN1_GENERALSTRING_new_null() SKM_sk_new_null(ASN1_GENERALSTRING)\r
+#define sk_ASN1_GENERALSTRING_free(st) SKM_sk_free(ASN1_GENERALSTRING, (st))\r
+#define sk_ASN1_GENERALSTRING_num(st) SKM_sk_num(ASN1_GENERALSTRING, (st))\r
+#define sk_ASN1_GENERALSTRING_value(st, i) SKM_sk_value(ASN1_GENERALSTRING, (st), (i))\r
+#define sk_ASN1_GENERALSTRING_set(st, i, val) SKM_sk_set(ASN1_GENERALSTRING, (st), (i), (val))\r
+#define sk_ASN1_GENERALSTRING_zero(st) SKM_sk_zero(ASN1_GENERALSTRING, (st))\r
+#define sk_ASN1_GENERALSTRING_push(st, val) SKM_sk_push(ASN1_GENERALSTRING, (st), (val))\r
+#define sk_ASN1_GENERALSTRING_unshift(st, val) SKM_sk_unshift(ASN1_GENERALSTRING, (st), (val))\r
+#define sk_ASN1_GENERALSTRING_find(st, val) SKM_sk_find(ASN1_GENERALSTRING, (st), (val))\r
+#define sk_ASN1_GENERALSTRING_find_ex(st, val) SKM_sk_find_ex(ASN1_GENERALSTRING, (st), (val))\r
+#define sk_ASN1_GENERALSTRING_delete(st, i) SKM_sk_delete(ASN1_GENERALSTRING, (st), (i))\r
+#define sk_ASN1_GENERALSTRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_GENERALSTRING, (st), (ptr))\r
+#define sk_ASN1_GENERALSTRING_insert(st, val, i) SKM_sk_insert(ASN1_GENERALSTRING, (st), (val), (i))\r
+#define sk_ASN1_GENERALSTRING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_GENERALSTRING, (st), (cmp))\r
+#define sk_ASN1_GENERALSTRING_dup(st) SKM_sk_dup(ASN1_GENERALSTRING, st)\r
+#define sk_ASN1_GENERALSTRING_pop_free(st, free_func) SKM_sk_pop_free(ASN1_GENERALSTRING, (st), (free_func))\r
+#define sk_ASN1_GENERALSTRING_shift(st) SKM_sk_shift(ASN1_GENERALSTRING, (st))\r
+#define sk_ASN1_GENERALSTRING_pop(st) SKM_sk_pop(ASN1_GENERALSTRING, (st))\r
+#define sk_ASN1_GENERALSTRING_sort(st) SKM_sk_sort(ASN1_GENERALSTRING, (st))\r
+#define sk_ASN1_GENERALSTRING_is_sorted(st) SKM_sk_is_sorted(ASN1_GENERALSTRING, (st))\r
+\r
+#define sk_ASN1_INTEGER_new(st) SKM_sk_new(ASN1_INTEGER, (st))\r
+#define sk_ASN1_INTEGER_new_null() SKM_sk_new_null(ASN1_INTEGER)\r
+#define sk_ASN1_INTEGER_free(st) SKM_sk_free(ASN1_INTEGER, (st))\r
+#define sk_ASN1_INTEGER_num(st) SKM_sk_num(ASN1_INTEGER, (st))\r
+#define sk_ASN1_INTEGER_value(st, i) SKM_sk_value(ASN1_INTEGER, (st), (i))\r
+#define sk_ASN1_INTEGER_set(st, i, val) SKM_sk_set(ASN1_INTEGER, (st), (i), (val))\r
+#define sk_ASN1_INTEGER_zero(st) SKM_sk_zero(ASN1_INTEGER, (st))\r
+#define sk_ASN1_INTEGER_push(st, val) SKM_sk_push(ASN1_INTEGER, (st), (val))\r
+#define sk_ASN1_INTEGER_unshift(st, val) SKM_sk_unshift(ASN1_INTEGER, (st), (val))\r
+#define sk_ASN1_INTEGER_find(st, val) SKM_sk_find(ASN1_INTEGER, (st), (val))\r
+#define sk_ASN1_INTEGER_find_ex(st, val) SKM_sk_find_ex(ASN1_INTEGER, (st), (val))\r
+#define sk_ASN1_INTEGER_delete(st, i) SKM_sk_delete(ASN1_INTEGER, (st), (i))\r
+#define sk_ASN1_INTEGER_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_INTEGER, (st), (ptr))\r
+#define sk_ASN1_INTEGER_insert(st, val, i) SKM_sk_insert(ASN1_INTEGER, (st), (val), (i))\r
+#define sk_ASN1_INTEGER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_INTEGER, (st), (cmp))\r
+#define sk_ASN1_INTEGER_dup(st) SKM_sk_dup(ASN1_INTEGER, st)\r
+#define sk_ASN1_INTEGER_pop_free(st, free_func) SKM_sk_pop_free(ASN1_INTEGER, (st), (free_func))\r
+#define sk_ASN1_INTEGER_shift(st) SKM_sk_shift(ASN1_INTEGER, (st))\r
+#define sk_ASN1_INTEGER_pop(st) SKM_sk_pop(ASN1_INTEGER, (st))\r
+#define sk_ASN1_INTEGER_sort(st) SKM_sk_sort(ASN1_INTEGER, (st))\r
+#define sk_ASN1_INTEGER_is_sorted(st) SKM_sk_is_sorted(ASN1_INTEGER, (st))\r
+\r
+#define sk_ASN1_OBJECT_new(st) SKM_sk_new(ASN1_OBJECT, (st))\r
+#define sk_ASN1_OBJECT_new_null() SKM_sk_new_null(ASN1_OBJECT)\r
+#define sk_ASN1_OBJECT_free(st) SKM_sk_free(ASN1_OBJECT, (st))\r
+#define sk_ASN1_OBJECT_num(st) SKM_sk_num(ASN1_OBJECT, (st))\r
+#define sk_ASN1_OBJECT_value(st, i) SKM_sk_value(ASN1_OBJECT, (st), (i))\r
+#define sk_ASN1_OBJECT_set(st, i, val) SKM_sk_set(ASN1_OBJECT, (st), (i), (val))\r
+#define sk_ASN1_OBJECT_zero(st) SKM_sk_zero(ASN1_OBJECT, (st))\r
+#define sk_ASN1_OBJECT_push(st, val) SKM_sk_push(ASN1_OBJECT, (st), (val))\r
+#define sk_ASN1_OBJECT_unshift(st, val) SKM_sk_unshift(ASN1_OBJECT, (st), (val))\r
+#define sk_ASN1_OBJECT_find(st, val) SKM_sk_find(ASN1_OBJECT, (st), (val))\r
+#define sk_ASN1_OBJECT_find_ex(st, val) SKM_sk_find_ex(ASN1_OBJECT, (st), (val))\r
+#define sk_ASN1_OBJECT_delete(st, i) SKM_sk_delete(ASN1_OBJECT, (st), (i))\r
+#define sk_ASN1_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_OBJECT, (st), (ptr))\r
+#define sk_ASN1_OBJECT_insert(st, val, i) SKM_sk_insert(ASN1_OBJECT, (st), (val), (i))\r
+#define sk_ASN1_OBJECT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_OBJECT, (st), (cmp))\r
+#define sk_ASN1_OBJECT_dup(st) SKM_sk_dup(ASN1_OBJECT, st)\r
+#define sk_ASN1_OBJECT_pop_free(st, free_func) SKM_sk_pop_free(ASN1_OBJECT, (st), (free_func))\r
+#define sk_ASN1_OBJECT_shift(st) SKM_sk_shift(ASN1_OBJECT, (st))\r
+#define sk_ASN1_OBJECT_pop(st) SKM_sk_pop(ASN1_OBJECT, (st))\r
+#define sk_ASN1_OBJECT_sort(st) SKM_sk_sort(ASN1_OBJECT, (st))\r
+#define sk_ASN1_OBJECT_is_sorted(st) SKM_sk_is_sorted(ASN1_OBJECT, (st))\r
+\r
+#define sk_ASN1_STRING_TABLE_new(st) SKM_sk_new(ASN1_STRING_TABLE, (st))\r
+#define sk_ASN1_STRING_TABLE_new_null() SKM_sk_new_null(ASN1_STRING_TABLE)\r
+#define sk_ASN1_STRING_TABLE_free(st) SKM_sk_free(ASN1_STRING_TABLE, (st))\r
+#define sk_ASN1_STRING_TABLE_num(st) SKM_sk_num(ASN1_STRING_TABLE, (st))\r
+#define sk_ASN1_STRING_TABLE_value(st, i) SKM_sk_value(ASN1_STRING_TABLE, (st), (i))\r
+#define sk_ASN1_STRING_TABLE_set(st, i, val) SKM_sk_set(ASN1_STRING_TABLE, (st), (i), (val))\r
+#define sk_ASN1_STRING_TABLE_zero(st) SKM_sk_zero(ASN1_STRING_TABLE, (st))\r
+#define sk_ASN1_STRING_TABLE_push(st, val) SKM_sk_push(ASN1_STRING_TABLE, (st), (val))\r
+#define sk_ASN1_STRING_TABLE_unshift(st, val) SKM_sk_unshift(ASN1_STRING_TABLE, (st), (val))\r
+#define sk_ASN1_STRING_TABLE_find(st, val) SKM_sk_find(ASN1_STRING_TABLE, (st), (val))\r
+#define sk_ASN1_STRING_TABLE_find_ex(st, val) SKM_sk_find_ex(ASN1_STRING_TABLE, (st), (val))\r
+#define sk_ASN1_STRING_TABLE_delete(st, i) SKM_sk_delete(ASN1_STRING_TABLE, (st), (i))\r
+#define sk_ASN1_STRING_TABLE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_STRING_TABLE, (st), (ptr))\r
+#define sk_ASN1_STRING_TABLE_insert(st, val, i) SKM_sk_insert(ASN1_STRING_TABLE, (st), (val), (i))\r
+#define sk_ASN1_STRING_TABLE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_STRING_TABLE, (st), (cmp))\r
+#define sk_ASN1_STRING_TABLE_dup(st) SKM_sk_dup(ASN1_STRING_TABLE, st)\r
+#define sk_ASN1_STRING_TABLE_pop_free(st, free_func) SKM_sk_pop_free(ASN1_STRING_TABLE, (st), (free_func))\r
+#define sk_ASN1_STRING_TABLE_shift(st) SKM_sk_shift(ASN1_STRING_TABLE, (st))\r
+#define sk_ASN1_STRING_TABLE_pop(st) SKM_sk_pop(ASN1_STRING_TABLE, (st))\r
+#define sk_ASN1_STRING_TABLE_sort(st) SKM_sk_sort(ASN1_STRING_TABLE, (st))\r
+#define sk_ASN1_STRING_TABLE_is_sorted(st) SKM_sk_is_sorted(ASN1_STRING_TABLE, (st))\r
+\r
+#define sk_ASN1_TYPE_new(st) SKM_sk_new(ASN1_TYPE, (st))\r
+#define sk_ASN1_TYPE_new_null() SKM_sk_new_null(ASN1_TYPE)\r
+#define sk_ASN1_TYPE_free(st) SKM_sk_free(ASN1_TYPE, (st))\r
+#define sk_ASN1_TYPE_num(st) SKM_sk_num(ASN1_TYPE, (st))\r
+#define sk_ASN1_TYPE_value(st, i) SKM_sk_value(ASN1_TYPE, (st), (i))\r
+#define sk_ASN1_TYPE_set(st, i, val) SKM_sk_set(ASN1_TYPE, (st), (i), (val))\r
+#define sk_ASN1_TYPE_zero(st) SKM_sk_zero(ASN1_TYPE, (st))\r
+#define sk_ASN1_TYPE_push(st, val) SKM_sk_push(ASN1_TYPE, (st), (val))\r
+#define sk_ASN1_TYPE_unshift(st, val) SKM_sk_unshift(ASN1_TYPE, (st), (val))\r
+#define sk_ASN1_TYPE_find(st, val) SKM_sk_find(ASN1_TYPE, (st), (val))\r
+#define sk_ASN1_TYPE_find_ex(st, val) SKM_sk_find_ex(ASN1_TYPE, (st), (val))\r
+#define sk_ASN1_TYPE_delete(st, i) SKM_sk_delete(ASN1_TYPE, (st), (i))\r
+#define sk_ASN1_TYPE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_TYPE, (st), (ptr))\r
+#define sk_ASN1_TYPE_insert(st, val, i) SKM_sk_insert(ASN1_TYPE, (st), (val), (i))\r
+#define sk_ASN1_TYPE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_TYPE, (st), (cmp))\r
+#define sk_ASN1_TYPE_dup(st) SKM_sk_dup(ASN1_TYPE, st)\r
+#define sk_ASN1_TYPE_pop_free(st, free_func) SKM_sk_pop_free(ASN1_TYPE, (st), (free_func))\r
+#define sk_ASN1_TYPE_shift(st) SKM_sk_shift(ASN1_TYPE, (st))\r
+#define sk_ASN1_TYPE_pop(st) SKM_sk_pop(ASN1_TYPE, (st))\r
+#define sk_ASN1_TYPE_sort(st) SKM_sk_sort(ASN1_TYPE, (st))\r
+#define sk_ASN1_TYPE_is_sorted(st) SKM_sk_is_sorted(ASN1_TYPE, (st))\r
+\r
+#define sk_ASN1_VALUE_new(st) SKM_sk_new(ASN1_VALUE, (st))\r
+#define sk_ASN1_VALUE_new_null() SKM_sk_new_null(ASN1_VALUE)\r
+#define sk_ASN1_VALUE_free(st) SKM_sk_free(ASN1_VALUE, (st))\r
+#define sk_ASN1_VALUE_num(st) SKM_sk_num(ASN1_VALUE, (st))\r
+#define sk_ASN1_VALUE_value(st, i) SKM_sk_value(ASN1_VALUE, (st), (i))\r
+#define sk_ASN1_VALUE_set(st, i, val) SKM_sk_set(ASN1_VALUE, (st), (i), (val))\r
+#define sk_ASN1_VALUE_zero(st) SKM_sk_zero(ASN1_VALUE, (st))\r
+#define sk_ASN1_VALUE_push(st, val) SKM_sk_push(ASN1_VALUE, (st), (val))\r
+#define sk_ASN1_VALUE_unshift(st, val) SKM_sk_unshift(ASN1_VALUE, (st), (val))\r
+#define sk_ASN1_VALUE_find(st, val) SKM_sk_find(ASN1_VALUE, (st), (val))\r
+#define sk_ASN1_VALUE_find_ex(st, val) SKM_sk_find_ex(ASN1_VALUE, (st), (val))\r
+#define sk_ASN1_VALUE_delete(st, i) SKM_sk_delete(ASN1_VALUE, (st), (i))\r
+#define sk_ASN1_VALUE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_VALUE, (st), (ptr))\r
+#define sk_ASN1_VALUE_insert(st, val, i) SKM_sk_insert(ASN1_VALUE, (st), (val), (i))\r
+#define sk_ASN1_VALUE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_VALUE, (st), (cmp))\r
+#define sk_ASN1_VALUE_dup(st) SKM_sk_dup(ASN1_VALUE, st)\r
+#define sk_ASN1_VALUE_pop_free(st, free_func) SKM_sk_pop_free(ASN1_VALUE, (st), (free_func))\r
+#define sk_ASN1_VALUE_shift(st) SKM_sk_shift(ASN1_VALUE, (st))\r
+#define sk_ASN1_VALUE_pop(st) SKM_sk_pop(ASN1_VALUE, (st))\r
+#define sk_ASN1_VALUE_sort(st) SKM_sk_sort(ASN1_VALUE, (st))\r
+#define sk_ASN1_VALUE_is_sorted(st) SKM_sk_is_sorted(ASN1_VALUE, (st))\r
+\r
+#define sk_BIO_new(st) SKM_sk_new(BIO, (st))\r
+#define sk_BIO_new_null() SKM_sk_new_null(BIO)\r
+#define sk_BIO_free(st) SKM_sk_free(BIO, (st))\r
+#define sk_BIO_num(st) SKM_sk_num(BIO, (st))\r
+#define sk_BIO_value(st, i) SKM_sk_value(BIO, (st), (i))\r
+#define sk_BIO_set(st, i, val) SKM_sk_set(BIO, (st), (i), (val))\r
+#define sk_BIO_zero(st) SKM_sk_zero(BIO, (st))\r
+#define sk_BIO_push(st, val) SKM_sk_push(BIO, (st), (val))\r
+#define sk_BIO_unshift(st, val) SKM_sk_unshift(BIO, (st), (val))\r
+#define sk_BIO_find(st, val) SKM_sk_find(BIO, (st), (val))\r
+#define sk_BIO_find_ex(st, val) SKM_sk_find_ex(BIO, (st), (val))\r
+#define sk_BIO_delete(st, i) SKM_sk_delete(BIO, (st), (i))\r
+#define sk_BIO_delete_ptr(st, ptr) SKM_sk_delete_ptr(BIO, (st), (ptr))\r
+#define sk_BIO_insert(st, val, i) SKM_sk_insert(BIO, (st), (val), (i))\r
+#define sk_BIO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(BIO, (st), (cmp))\r
+#define sk_BIO_dup(st) SKM_sk_dup(BIO, st)\r
+#define sk_BIO_pop_free(st, free_func) SKM_sk_pop_free(BIO, (st), (free_func))\r
+#define sk_BIO_shift(st) SKM_sk_shift(BIO, (st))\r
+#define sk_BIO_pop(st) SKM_sk_pop(BIO, (st))\r
+#define sk_BIO_sort(st) SKM_sk_sort(BIO, (st))\r
+#define sk_BIO_is_sorted(st) SKM_sk_is_sorted(BIO, (st))\r
+\r
+#define sk_CONF_IMODULE_new(st) SKM_sk_new(CONF_IMODULE, (st))\r
+#define sk_CONF_IMODULE_new_null() SKM_sk_new_null(CONF_IMODULE)\r
+#define sk_CONF_IMODULE_free(st) SKM_sk_free(CONF_IMODULE, (st))\r
+#define sk_CONF_IMODULE_num(st) SKM_sk_num(CONF_IMODULE, (st))\r
+#define sk_CONF_IMODULE_value(st, i) SKM_sk_value(CONF_IMODULE, (st), (i))\r
+#define sk_CONF_IMODULE_set(st, i, val) SKM_sk_set(CONF_IMODULE, (st), (i), (val))\r
+#define sk_CONF_IMODULE_zero(st) SKM_sk_zero(CONF_IMODULE, (st))\r
+#define sk_CONF_IMODULE_push(st, val) SKM_sk_push(CONF_IMODULE, (st), (val))\r
+#define sk_CONF_IMODULE_unshift(st, val) SKM_sk_unshift(CONF_IMODULE, (st), (val))\r
+#define sk_CONF_IMODULE_find(st, val) SKM_sk_find(CONF_IMODULE, (st), (val))\r
+#define sk_CONF_IMODULE_find_ex(st, val) SKM_sk_find_ex(CONF_IMODULE, (st), (val))\r
+#define sk_CONF_IMODULE_delete(st, i) SKM_sk_delete(CONF_IMODULE, (st), (i))\r
+#define sk_CONF_IMODULE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_IMODULE, (st), (ptr))\r
+#define sk_CONF_IMODULE_insert(st, val, i) SKM_sk_insert(CONF_IMODULE, (st), (val), (i))\r
+#define sk_CONF_IMODULE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CONF_IMODULE, (st), (cmp))\r
+#define sk_CONF_IMODULE_dup(st) SKM_sk_dup(CONF_IMODULE, st)\r
+#define sk_CONF_IMODULE_pop_free(st, free_func) SKM_sk_pop_free(CONF_IMODULE, (st), (free_func))\r
+#define sk_CONF_IMODULE_shift(st) SKM_sk_shift(CONF_IMODULE, (st))\r
+#define sk_CONF_IMODULE_pop(st) SKM_sk_pop(CONF_IMODULE, (st))\r
+#define sk_CONF_IMODULE_sort(st) SKM_sk_sort(CONF_IMODULE, (st))\r
+#define sk_CONF_IMODULE_is_sorted(st) SKM_sk_is_sorted(CONF_IMODULE, (st))\r
+\r
+#define sk_CONF_MODULE_new(st) SKM_sk_new(CONF_MODULE, (st))\r
+#define sk_CONF_MODULE_new_null() SKM_sk_new_null(CONF_MODULE)\r
+#define sk_CONF_MODULE_free(st) SKM_sk_free(CONF_MODULE, (st))\r
+#define sk_CONF_MODULE_num(st) SKM_sk_num(CONF_MODULE, (st))\r
+#define sk_CONF_MODULE_value(st, i) SKM_sk_value(CONF_MODULE, (st), (i))\r
+#define sk_CONF_MODULE_set(st, i, val) SKM_sk_set(CONF_MODULE, (st), (i), (val))\r
+#define sk_CONF_MODULE_zero(st) SKM_sk_zero(CONF_MODULE, (st))\r
+#define sk_CONF_MODULE_push(st, val) SKM_sk_push(CONF_MODULE, (st), (val))\r
+#define sk_CONF_MODULE_unshift(st, val) SKM_sk_unshift(CONF_MODULE, (st), (val))\r
+#define sk_CONF_MODULE_find(st, val) SKM_sk_find(CONF_MODULE, (st), (val))\r
+#define sk_CONF_MODULE_find_ex(st, val) SKM_sk_find_ex(CONF_MODULE, (st), (val))\r
+#define sk_CONF_MODULE_delete(st, i) SKM_sk_delete(CONF_MODULE, (st), (i))\r
+#define sk_CONF_MODULE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_MODULE, (st), (ptr))\r
+#define sk_CONF_MODULE_insert(st, val, i) SKM_sk_insert(CONF_MODULE, (st), (val), (i))\r
+#define sk_CONF_MODULE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CONF_MODULE, (st), (cmp))\r
+#define sk_CONF_MODULE_dup(st) SKM_sk_dup(CONF_MODULE, st)\r
+#define sk_CONF_MODULE_pop_free(st, free_func) SKM_sk_pop_free(CONF_MODULE, (st), (free_func))\r
+#define sk_CONF_MODULE_shift(st) SKM_sk_shift(CONF_MODULE, (st))\r
+#define sk_CONF_MODULE_pop(st) SKM_sk_pop(CONF_MODULE, (st))\r
+#define sk_CONF_MODULE_sort(st) SKM_sk_sort(CONF_MODULE, (st))\r
+#define sk_CONF_MODULE_is_sorted(st) SKM_sk_is_sorted(CONF_MODULE, (st))\r
+\r
+#define sk_CONF_VALUE_new(st) SKM_sk_new(CONF_VALUE, (st))\r
+#define sk_CONF_VALUE_new_null() SKM_sk_new_null(CONF_VALUE)\r
+#define sk_CONF_VALUE_free(st) SKM_sk_free(CONF_VALUE, (st))\r
+#define sk_CONF_VALUE_num(st) SKM_sk_num(CONF_VALUE, (st))\r
+#define sk_CONF_VALUE_value(st, i) SKM_sk_value(CONF_VALUE, (st), (i))\r
+#define sk_CONF_VALUE_set(st, i, val) SKM_sk_set(CONF_VALUE, (st), (i), (val))\r
+#define sk_CONF_VALUE_zero(st) SKM_sk_zero(CONF_VALUE, (st))\r
+#define sk_CONF_VALUE_push(st, val) SKM_sk_push(CONF_VALUE, (st), (val))\r
+#define sk_CONF_VALUE_unshift(st, val) SKM_sk_unshift(CONF_VALUE, (st), (val))\r
+#define sk_CONF_VALUE_find(st, val) SKM_sk_find(CONF_VALUE, (st), (val))\r
+#define sk_CONF_VALUE_find_ex(st, val) SKM_sk_find_ex(CONF_VALUE, (st), (val))\r
+#define sk_CONF_VALUE_delete(st, i) SKM_sk_delete(CONF_VALUE, (st), (i))\r
+#define sk_CONF_VALUE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_VALUE, (st), (ptr))\r
+#define sk_CONF_VALUE_insert(st, val, i) SKM_sk_insert(CONF_VALUE, (st), (val), (i))\r
+#define sk_CONF_VALUE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CONF_VALUE, (st), (cmp))\r
+#define sk_CONF_VALUE_dup(st) SKM_sk_dup(CONF_VALUE, st)\r
+#define sk_CONF_VALUE_pop_free(st, free_func) SKM_sk_pop_free(CONF_VALUE, (st), (free_func))\r
+#define sk_CONF_VALUE_shift(st) SKM_sk_shift(CONF_VALUE, (st))\r
+#define sk_CONF_VALUE_pop(st) SKM_sk_pop(CONF_VALUE, (st))\r
+#define sk_CONF_VALUE_sort(st) SKM_sk_sort(CONF_VALUE, (st))\r
+#define sk_CONF_VALUE_is_sorted(st) SKM_sk_is_sorted(CONF_VALUE, (st))\r
+\r
+#define sk_CRYPTO_EX_DATA_FUNCS_new(st) SKM_sk_new(CRYPTO_EX_DATA_FUNCS, (st))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_new_null() SKM_sk_new_null(CRYPTO_EX_DATA_FUNCS)\r
+#define sk_CRYPTO_EX_DATA_FUNCS_free(st) SKM_sk_free(CRYPTO_EX_DATA_FUNCS, (st))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_num(st) SKM_sk_num(CRYPTO_EX_DATA_FUNCS, (st))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_value(st, i) SKM_sk_value(CRYPTO_EX_DATA_FUNCS, (st), (i))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_set(st, i, val) SKM_sk_set(CRYPTO_EX_DATA_FUNCS, (st), (i), (val))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_zero(st) SKM_sk_zero(CRYPTO_EX_DATA_FUNCS, (st))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_push(st, val) SKM_sk_push(CRYPTO_EX_DATA_FUNCS, (st), (val))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_unshift(st, val) SKM_sk_unshift(CRYPTO_EX_DATA_FUNCS, (st), (val))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_find(st, val) SKM_sk_find(CRYPTO_EX_DATA_FUNCS, (st), (val))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_find_ex(st, val) SKM_sk_find_ex(CRYPTO_EX_DATA_FUNCS, (st), (val))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_delete(st, i) SKM_sk_delete(CRYPTO_EX_DATA_FUNCS, (st), (i))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_delete_ptr(st, ptr) SKM_sk_delete_ptr(CRYPTO_EX_DATA_FUNCS, (st), (ptr))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_insert(st, val, i) SKM_sk_insert(CRYPTO_EX_DATA_FUNCS, (st), (val), (i))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CRYPTO_EX_DATA_FUNCS, (st), (cmp))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_dup(st) SKM_sk_dup(CRYPTO_EX_DATA_FUNCS, st)\r
+#define sk_CRYPTO_EX_DATA_FUNCS_pop_free(st, free_func) SKM_sk_pop_free(CRYPTO_EX_DATA_FUNCS, (st), (free_func))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_shift(st) SKM_sk_shift(CRYPTO_EX_DATA_FUNCS, (st))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_pop(st) SKM_sk_pop(CRYPTO_EX_DATA_FUNCS, (st))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_sort(st) SKM_sk_sort(CRYPTO_EX_DATA_FUNCS, (st))\r
+#define sk_CRYPTO_EX_DATA_FUNCS_is_sorted(st) SKM_sk_is_sorted(CRYPTO_EX_DATA_FUNCS, (st))\r
+\r
+#define sk_CRYPTO_dynlock_new(st) SKM_sk_new(CRYPTO_dynlock, (st))\r
+#define sk_CRYPTO_dynlock_new_null() SKM_sk_new_null(CRYPTO_dynlock)\r
+#define sk_CRYPTO_dynlock_free(st) SKM_sk_free(CRYPTO_dynlock, (st))\r
+#define sk_CRYPTO_dynlock_num(st) SKM_sk_num(CRYPTO_dynlock, (st))\r
+#define sk_CRYPTO_dynlock_value(st, i) SKM_sk_value(CRYPTO_dynlock, (st), (i))\r
+#define sk_CRYPTO_dynlock_set(st, i, val) SKM_sk_set(CRYPTO_dynlock, (st), (i), (val))\r
+#define sk_CRYPTO_dynlock_zero(st) SKM_sk_zero(CRYPTO_dynlock, (st))\r
+#define sk_CRYPTO_dynlock_push(st, val) SKM_sk_push(CRYPTO_dynlock, (st), (val))\r
+#define sk_CRYPTO_dynlock_unshift(st, val) SKM_sk_unshift(CRYPTO_dynlock, (st), (val))\r
+#define sk_CRYPTO_dynlock_find(st, val) SKM_sk_find(CRYPTO_dynlock, (st), (val))\r
+#define sk_CRYPTO_dynlock_find_ex(st, val) SKM_sk_find_ex(CRYPTO_dynlock, (st), (val))\r
+#define sk_CRYPTO_dynlock_delete(st, i) SKM_sk_delete(CRYPTO_dynlock, (st), (i))\r
+#define sk_CRYPTO_dynlock_delete_ptr(st, ptr) SKM_sk_delete_ptr(CRYPTO_dynlock, (st), (ptr))\r
+#define sk_CRYPTO_dynlock_insert(st, val, i) SKM_sk_insert(CRYPTO_dynlock, (st), (val), (i))\r
+#define sk_CRYPTO_dynlock_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CRYPTO_dynlock, (st), (cmp))\r
+#define sk_CRYPTO_dynlock_dup(st) SKM_sk_dup(CRYPTO_dynlock, st)\r
+#define sk_CRYPTO_dynlock_pop_free(st, free_func) SKM_sk_pop_free(CRYPTO_dynlock, (st), (free_func))\r
+#define sk_CRYPTO_dynlock_shift(st) SKM_sk_shift(CRYPTO_dynlock, (st))\r
+#define sk_CRYPTO_dynlock_pop(st) SKM_sk_pop(CRYPTO_dynlock, (st))\r
+#define sk_CRYPTO_dynlock_sort(st) SKM_sk_sort(CRYPTO_dynlock, (st))\r
+#define sk_CRYPTO_dynlock_is_sorted(st) SKM_sk_is_sorted(CRYPTO_dynlock, (st))\r
+\r
+#define sk_DIST_POINT_new(st) SKM_sk_new(DIST_POINT, (st))\r
+#define sk_DIST_POINT_new_null() SKM_sk_new_null(DIST_POINT)\r
+#define sk_DIST_POINT_free(st) SKM_sk_free(DIST_POINT, (st))\r
+#define sk_DIST_POINT_num(st) SKM_sk_num(DIST_POINT, (st))\r
+#define sk_DIST_POINT_value(st, i) SKM_sk_value(DIST_POINT, (st), (i))\r
+#define sk_DIST_POINT_set(st, i, val) SKM_sk_set(DIST_POINT, (st), (i), (val))\r
+#define sk_DIST_POINT_zero(st) SKM_sk_zero(DIST_POINT, (st))\r
+#define sk_DIST_POINT_push(st, val) SKM_sk_push(DIST_POINT, (st), (val))\r
+#define sk_DIST_POINT_unshift(st, val) SKM_sk_unshift(DIST_POINT, (st), (val))\r
+#define sk_DIST_POINT_find(st, val) SKM_sk_find(DIST_POINT, (st), (val))\r
+#define sk_DIST_POINT_find_ex(st, val) SKM_sk_find_ex(DIST_POINT, (st), (val))\r
+#define sk_DIST_POINT_delete(st, i) SKM_sk_delete(DIST_POINT, (st), (i))\r
+#define sk_DIST_POINT_delete_ptr(st, ptr) SKM_sk_delete_ptr(DIST_POINT, (st), (ptr))\r
+#define sk_DIST_POINT_insert(st, val, i) SKM_sk_insert(DIST_POINT, (st), (val), (i))\r
+#define sk_DIST_POINT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(DIST_POINT, (st), (cmp))\r
+#define sk_DIST_POINT_dup(st) SKM_sk_dup(DIST_POINT, st)\r
+#define sk_DIST_POINT_pop_free(st, free_func) SKM_sk_pop_free(DIST_POINT, (st), (free_func))\r
+#define sk_DIST_POINT_shift(st) SKM_sk_shift(DIST_POINT, (st))\r
+#define sk_DIST_POINT_pop(st) SKM_sk_pop(DIST_POINT, (st))\r
+#define sk_DIST_POINT_sort(st) SKM_sk_sort(DIST_POINT, (st))\r
+#define sk_DIST_POINT_is_sorted(st) SKM_sk_is_sorted(DIST_POINT, (st))\r
+\r
+#define sk_ENGINE_new(st) SKM_sk_new(ENGINE, (st))\r
+#define sk_ENGINE_new_null() SKM_sk_new_null(ENGINE)\r
+#define sk_ENGINE_free(st) SKM_sk_free(ENGINE, (st))\r
+#define sk_ENGINE_num(st) SKM_sk_num(ENGINE, (st))\r
+#define sk_ENGINE_value(st, i) SKM_sk_value(ENGINE, (st), (i))\r
+#define sk_ENGINE_set(st, i, val) SKM_sk_set(ENGINE, (st), (i), (val))\r
+#define sk_ENGINE_zero(st) SKM_sk_zero(ENGINE, (st))\r
+#define sk_ENGINE_push(st, val) SKM_sk_push(ENGINE, (st), (val))\r
+#define sk_ENGINE_unshift(st, val) SKM_sk_unshift(ENGINE, (st), (val))\r
+#define sk_ENGINE_find(st, val) SKM_sk_find(ENGINE, (st), (val))\r
+#define sk_ENGINE_find_ex(st, val) SKM_sk_find_ex(ENGINE, (st), (val))\r
+#define sk_ENGINE_delete(st, i) SKM_sk_delete(ENGINE, (st), (i))\r
+#define sk_ENGINE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ENGINE, (st), (ptr))\r
+#define sk_ENGINE_insert(st, val, i) SKM_sk_insert(ENGINE, (st), (val), (i))\r
+#define sk_ENGINE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ENGINE, (st), (cmp))\r
+#define sk_ENGINE_dup(st) SKM_sk_dup(ENGINE, st)\r
+#define sk_ENGINE_pop_free(st, free_func) SKM_sk_pop_free(ENGINE, (st), (free_func))\r
+#define sk_ENGINE_shift(st) SKM_sk_shift(ENGINE, (st))\r
+#define sk_ENGINE_pop(st) SKM_sk_pop(ENGINE, (st))\r
+#define sk_ENGINE_sort(st) SKM_sk_sort(ENGINE, (st))\r
+#define sk_ENGINE_is_sorted(st) SKM_sk_is_sorted(ENGINE, (st))\r
+\r
+#define sk_ENGINE_CLEANUP_ITEM_new(st) SKM_sk_new(ENGINE_CLEANUP_ITEM, (st))\r
+#define sk_ENGINE_CLEANUP_ITEM_new_null() SKM_sk_new_null(ENGINE_CLEANUP_ITEM)\r
+#define sk_ENGINE_CLEANUP_ITEM_free(st) SKM_sk_free(ENGINE_CLEANUP_ITEM, (st))\r
+#define sk_ENGINE_CLEANUP_ITEM_num(st) SKM_sk_num(ENGINE_CLEANUP_ITEM, (st))\r
+#define sk_ENGINE_CLEANUP_ITEM_value(st, i) SKM_sk_value(ENGINE_CLEANUP_ITEM, (st), (i))\r
+#define sk_ENGINE_CLEANUP_ITEM_set(st, i, val) SKM_sk_set(ENGINE_CLEANUP_ITEM, (st), (i), (val))\r
+#define sk_ENGINE_CLEANUP_ITEM_zero(st) SKM_sk_zero(ENGINE_CLEANUP_ITEM, (st))\r
+#define sk_ENGINE_CLEANUP_ITEM_push(st, val) SKM_sk_push(ENGINE_CLEANUP_ITEM, (st), (val))\r
+#define sk_ENGINE_CLEANUP_ITEM_unshift(st, val) SKM_sk_unshift(ENGINE_CLEANUP_ITEM, (st), (val))\r
+#define sk_ENGINE_CLEANUP_ITEM_find(st, val) SKM_sk_find(ENGINE_CLEANUP_ITEM, (st), (val))\r
+#define sk_ENGINE_CLEANUP_ITEM_find_ex(st, val) SKM_sk_find_ex(ENGINE_CLEANUP_ITEM, (st), (val))\r
+#define sk_ENGINE_CLEANUP_ITEM_delete(st, i) SKM_sk_delete(ENGINE_CLEANUP_ITEM, (st), (i))\r
+#define sk_ENGINE_CLEANUP_ITEM_delete_ptr(st, ptr) SKM_sk_delete_ptr(ENGINE_CLEANUP_ITEM, (st), (ptr))\r
+#define sk_ENGINE_CLEANUP_ITEM_insert(st, val, i) SKM_sk_insert(ENGINE_CLEANUP_ITEM, (st), (val), (i))\r
+#define sk_ENGINE_CLEANUP_ITEM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ENGINE_CLEANUP_ITEM, (st), (cmp))\r
+#define sk_ENGINE_CLEANUP_ITEM_dup(st) SKM_sk_dup(ENGINE_CLEANUP_ITEM, st)\r
+#define sk_ENGINE_CLEANUP_ITEM_pop_free(st, free_func) SKM_sk_pop_free(ENGINE_CLEANUP_ITEM, (st), (free_func))\r
+#define sk_ENGINE_CLEANUP_ITEM_shift(st) SKM_sk_shift(ENGINE_CLEANUP_ITEM, (st))\r
+#define sk_ENGINE_CLEANUP_ITEM_pop(st) SKM_sk_pop(ENGINE_CLEANUP_ITEM, (st))\r
+#define sk_ENGINE_CLEANUP_ITEM_sort(st) SKM_sk_sort(ENGINE_CLEANUP_ITEM, (st))\r
+#define sk_ENGINE_CLEANUP_ITEM_is_sorted(st) SKM_sk_is_sorted(ENGINE_CLEANUP_ITEM, (st))\r
+\r
+#define sk_GENERAL_NAME_new(st) SKM_sk_new(GENERAL_NAME, (st))\r
+#define sk_GENERAL_NAME_new_null() SKM_sk_new_null(GENERAL_NAME)\r
+#define sk_GENERAL_NAME_free(st) SKM_sk_free(GENERAL_NAME, (st))\r
+#define sk_GENERAL_NAME_num(st) SKM_sk_num(GENERAL_NAME, (st))\r
+#define sk_GENERAL_NAME_value(st, i) SKM_sk_value(GENERAL_NAME, (st), (i))\r
+#define sk_GENERAL_NAME_set(st, i, val) SKM_sk_set(GENERAL_NAME, (st), (i), (val))\r
+#define sk_GENERAL_NAME_zero(st) SKM_sk_zero(GENERAL_NAME, (st))\r
+#define sk_GENERAL_NAME_push(st, val) SKM_sk_push(GENERAL_NAME, (st), (val))\r
+#define sk_GENERAL_NAME_unshift(st, val) SKM_sk_unshift(GENERAL_NAME, (st), (val))\r
+#define sk_GENERAL_NAME_find(st, val) SKM_sk_find(GENERAL_NAME, (st), (val))\r
+#define sk_GENERAL_NAME_find_ex(st, val) SKM_sk_find_ex(GENERAL_NAME, (st), (val))\r
+#define sk_GENERAL_NAME_delete(st, i) SKM_sk_delete(GENERAL_NAME, (st), (i))\r
+#define sk_GENERAL_NAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(GENERAL_NAME, (st), (ptr))\r
+#define sk_GENERAL_NAME_insert(st, val, i) SKM_sk_insert(GENERAL_NAME, (st), (val), (i))\r
+#define sk_GENERAL_NAME_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(GENERAL_NAME, (st), (cmp))\r
+#define sk_GENERAL_NAME_dup(st) SKM_sk_dup(GENERAL_NAME, st)\r
+#define sk_GENERAL_NAME_pop_free(st, free_func) SKM_sk_pop_free(GENERAL_NAME, (st), (free_func))\r
+#define sk_GENERAL_NAME_shift(st) SKM_sk_shift(GENERAL_NAME, (st))\r
+#define sk_GENERAL_NAME_pop(st) SKM_sk_pop(GENERAL_NAME, (st))\r
+#define sk_GENERAL_NAME_sort(st) SKM_sk_sort(GENERAL_NAME, (st))\r
+#define sk_GENERAL_NAME_is_sorted(st) SKM_sk_is_sorted(GENERAL_NAME, (st))\r
+\r
+#define sk_GENERAL_SUBTREE_new(st) SKM_sk_new(GENERAL_SUBTREE, (st))\r
+#define sk_GENERAL_SUBTREE_new_null() SKM_sk_new_null(GENERAL_SUBTREE)\r
+#define sk_GENERAL_SUBTREE_free(st) SKM_sk_free(GENERAL_SUBTREE, (st))\r
+#define sk_GENERAL_SUBTREE_num(st) SKM_sk_num(GENERAL_SUBTREE, (st))\r
+#define sk_GENERAL_SUBTREE_value(st, i) SKM_sk_value(GENERAL_SUBTREE, (st), (i))\r
+#define sk_GENERAL_SUBTREE_set(st, i, val) SKM_sk_set(GENERAL_SUBTREE, (st), (i), (val))\r
+#define sk_GENERAL_SUBTREE_zero(st) SKM_sk_zero(GENERAL_SUBTREE, (st))\r
+#define sk_GENERAL_SUBTREE_push(st, val) SKM_sk_push(GENERAL_SUBTREE, (st), (val))\r
+#define sk_GENERAL_SUBTREE_unshift(st, val) SKM_sk_unshift(GENERAL_SUBTREE, (st), (val))\r
+#define sk_GENERAL_SUBTREE_find(st, val) SKM_sk_find(GENERAL_SUBTREE, (st), (val))\r
+#define sk_GENERAL_SUBTREE_find_ex(st, val) SKM_sk_find_ex(GENERAL_SUBTREE, (st), (val))\r
+#define sk_GENERAL_SUBTREE_delete(st, i) SKM_sk_delete(GENERAL_SUBTREE, (st), (i))\r
+#define sk_GENERAL_SUBTREE_delete_ptr(st, ptr) SKM_sk_delete_ptr(GENERAL_SUBTREE, (st), (ptr))\r
+#define sk_GENERAL_SUBTREE_insert(st, val, i) SKM_sk_insert(GENERAL_SUBTREE, (st), (val), (i))\r
+#define sk_GENERAL_SUBTREE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(GENERAL_SUBTREE, (st), (cmp))\r
+#define sk_GENERAL_SUBTREE_dup(st) SKM_sk_dup(GENERAL_SUBTREE, st)\r
+#define sk_GENERAL_SUBTREE_pop_free(st, free_func) SKM_sk_pop_free(GENERAL_SUBTREE, (st), (free_func))\r
+#define sk_GENERAL_SUBTREE_shift(st) SKM_sk_shift(GENERAL_SUBTREE, (st))\r
+#define sk_GENERAL_SUBTREE_pop(st) SKM_sk_pop(GENERAL_SUBTREE, (st))\r
+#define sk_GENERAL_SUBTREE_sort(st) SKM_sk_sort(GENERAL_SUBTREE, (st))\r
+#define sk_GENERAL_SUBTREE_is_sorted(st) SKM_sk_is_sorted(GENERAL_SUBTREE, (st))\r
+\r
+#define sk_KRB5_APREQBODY_new(st) SKM_sk_new(KRB5_APREQBODY, (st))\r
+#define sk_KRB5_APREQBODY_new_null() SKM_sk_new_null(KRB5_APREQBODY)\r
+#define sk_KRB5_APREQBODY_free(st) SKM_sk_free(KRB5_APREQBODY, (st))\r
+#define sk_KRB5_APREQBODY_num(st) SKM_sk_num(KRB5_APREQBODY, (st))\r
+#define sk_KRB5_APREQBODY_value(st, i) SKM_sk_value(KRB5_APREQBODY, (st), (i))\r
+#define sk_KRB5_APREQBODY_set(st, i, val) SKM_sk_set(KRB5_APREQBODY, (st), (i), (val))\r
+#define sk_KRB5_APREQBODY_zero(st) SKM_sk_zero(KRB5_APREQBODY, (st))\r
+#define sk_KRB5_APREQBODY_push(st, val) SKM_sk_push(KRB5_APREQBODY, (st), (val))\r
+#define sk_KRB5_APREQBODY_unshift(st, val) SKM_sk_unshift(KRB5_APREQBODY, (st), (val))\r
+#define sk_KRB5_APREQBODY_find(st, val) SKM_sk_find(KRB5_APREQBODY, (st), (val))\r
+#define sk_KRB5_APREQBODY_find_ex(st, val) SKM_sk_find_ex(KRB5_APREQBODY, (st), (val))\r
+#define sk_KRB5_APREQBODY_delete(st, i) SKM_sk_delete(KRB5_APREQBODY, (st), (i))\r
+#define sk_KRB5_APREQBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_APREQBODY, (st), (ptr))\r
+#define sk_KRB5_APREQBODY_insert(st, val, i) SKM_sk_insert(KRB5_APREQBODY, (st), (val), (i))\r
+#define sk_KRB5_APREQBODY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_APREQBODY, (st), (cmp))\r
+#define sk_KRB5_APREQBODY_dup(st) SKM_sk_dup(KRB5_APREQBODY, st)\r
+#define sk_KRB5_APREQBODY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_APREQBODY, (st), (free_func))\r
+#define sk_KRB5_APREQBODY_shift(st) SKM_sk_shift(KRB5_APREQBODY, (st))\r
+#define sk_KRB5_APREQBODY_pop(st) SKM_sk_pop(KRB5_APREQBODY, (st))\r
+#define sk_KRB5_APREQBODY_sort(st) SKM_sk_sort(KRB5_APREQBODY, (st))\r
+#define sk_KRB5_APREQBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_APREQBODY, (st))\r
+\r
+#define sk_KRB5_AUTHDATA_new(st) SKM_sk_new(KRB5_AUTHDATA, (st))\r
+#define sk_KRB5_AUTHDATA_new_null() SKM_sk_new_null(KRB5_AUTHDATA)\r
+#define sk_KRB5_AUTHDATA_free(st) SKM_sk_free(KRB5_AUTHDATA, (st))\r
+#define sk_KRB5_AUTHDATA_num(st) SKM_sk_num(KRB5_AUTHDATA, (st))\r
+#define sk_KRB5_AUTHDATA_value(st, i) SKM_sk_value(KRB5_AUTHDATA, (st), (i))\r
+#define sk_KRB5_AUTHDATA_set(st, i, val) SKM_sk_set(KRB5_AUTHDATA, (st), (i), (val))\r
+#define sk_KRB5_AUTHDATA_zero(st) SKM_sk_zero(KRB5_AUTHDATA, (st))\r
+#define sk_KRB5_AUTHDATA_push(st, val) SKM_sk_push(KRB5_AUTHDATA, (st), (val))\r
+#define sk_KRB5_AUTHDATA_unshift(st, val) SKM_sk_unshift(KRB5_AUTHDATA, (st), (val))\r
+#define sk_KRB5_AUTHDATA_find(st, val) SKM_sk_find(KRB5_AUTHDATA, (st), (val))\r
+#define sk_KRB5_AUTHDATA_find_ex(st, val) SKM_sk_find_ex(KRB5_AUTHDATA, (st), (val))\r
+#define sk_KRB5_AUTHDATA_delete(st, i) SKM_sk_delete(KRB5_AUTHDATA, (st), (i))\r
+#define sk_KRB5_AUTHDATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_AUTHDATA, (st), (ptr))\r
+#define sk_KRB5_AUTHDATA_insert(st, val, i) SKM_sk_insert(KRB5_AUTHDATA, (st), (val), (i))\r
+#define sk_KRB5_AUTHDATA_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_AUTHDATA, (st), (cmp))\r
+#define sk_KRB5_AUTHDATA_dup(st) SKM_sk_dup(KRB5_AUTHDATA, st)\r
+#define sk_KRB5_AUTHDATA_pop_free(st, free_func) SKM_sk_pop_free(KRB5_AUTHDATA, (st), (free_func))\r
+#define sk_KRB5_AUTHDATA_shift(st) SKM_sk_shift(KRB5_AUTHDATA, (st))\r
+#define sk_KRB5_AUTHDATA_pop(st) SKM_sk_pop(KRB5_AUTHDATA, (st))\r
+#define sk_KRB5_AUTHDATA_sort(st) SKM_sk_sort(KRB5_AUTHDATA, (st))\r
+#define sk_KRB5_AUTHDATA_is_sorted(st) SKM_sk_is_sorted(KRB5_AUTHDATA, (st))\r
+\r
+#define sk_KRB5_AUTHENTBODY_new(st) SKM_sk_new(KRB5_AUTHENTBODY, (st))\r
+#define sk_KRB5_AUTHENTBODY_new_null() SKM_sk_new_null(KRB5_AUTHENTBODY)\r
+#define sk_KRB5_AUTHENTBODY_free(st) SKM_sk_free(KRB5_AUTHENTBODY, (st))\r
+#define sk_KRB5_AUTHENTBODY_num(st) SKM_sk_num(KRB5_AUTHENTBODY, (st))\r
+#define sk_KRB5_AUTHENTBODY_value(st, i) SKM_sk_value(KRB5_AUTHENTBODY, (st), (i))\r
+#define sk_KRB5_AUTHENTBODY_set(st, i, val) SKM_sk_set(KRB5_AUTHENTBODY, (st), (i), (val))\r
+#define sk_KRB5_AUTHENTBODY_zero(st) SKM_sk_zero(KRB5_AUTHENTBODY, (st))\r
+#define sk_KRB5_AUTHENTBODY_push(st, val) SKM_sk_push(KRB5_AUTHENTBODY, (st), (val))\r
+#define sk_KRB5_AUTHENTBODY_unshift(st, val) SKM_sk_unshift(KRB5_AUTHENTBODY, (st), (val))\r
+#define sk_KRB5_AUTHENTBODY_find(st, val) SKM_sk_find(KRB5_AUTHENTBODY, (st), (val))\r
+#define sk_KRB5_AUTHENTBODY_find_ex(st, val) SKM_sk_find_ex(KRB5_AUTHENTBODY, (st), (val))\r
+#define sk_KRB5_AUTHENTBODY_delete(st, i) SKM_sk_delete(KRB5_AUTHENTBODY, (st), (i))\r
+#define sk_KRB5_AUTHENTBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_AUTHENTBODY, (st), (ptr))\r
+#define sk_KRB5_AUTHENTBODY_insert(st, val, i) SKM_sk_insert(KRB5_AUTHENTBODY, (st), (val), (i))\r
+#define sk_KRB5_AUTHENTBODY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_AUTHENTBODY, (st), (cmp))\r
+#define sk_KRB5_AUTHENTBODY_dup(st) SKM_sk_dup(KRB5_AUTHENTBODY, st)\r
+#define sk_KRB5_AUTHENTBODY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_AUTHENTBODY, (st), (free_func))\r
+#define sk_KRB5_AUTHENTBODY_shift(st) SKM_sk_shift(KRB5_AUTHENTBODY, (st))\r
+#define sk_KRB5_AUTHENTBODY_pop(st) SKM_sk_pop(KRB5_AUTHENTBODY, (st))\r
+#define sk_KRB5_AUTHENTBODY_sort(st) SKM_sk_sort(KRB5_AUTHENTBODY, (st))\r
+#define sk_KRB5_AUTHENTBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_AUTHENTBODY, (st))\r
+\r
+#define sk_KRB5_CHECKSUM_new(st) SKM_sk_new(KRB5_CHECKSUM, (st))\r
+#define sk_KRB5_CHECKSUM_new_null() SKM_sk_new_null(KRB5_CHECKSUM)\r
+#define sk_KRB5_CHECKSUM_free(st) SKM_sk_free(KRB5_CHECKSUM, (st))\r
+#define sk_KRB5_CHECKSUM_num(st) SKM_sk_num(KRB5_CHECKSUM, (st))\r
+#define sk_KRB5_CHECKSUM_value(st, i) SKM_sk_value(KRB5_CHECKSUM, (st), (i))\r
+#define sk_KRB5_CHECKSUM_set(st, i, val) SKM_sk_set(KRB5_CHECKSUM, (st), (i), (val))\r
+#define sk_KRB5_CHECKSUM_zero(st) SKM_sk_zero(KRB5_CHECKSUM, (st))\r
+#define sk_KRB5_CHECKSUM_push(st, val) SKM_sk_push(KRB5_CHECKSUM, (st), (val))\r
+#define sk_KRB5_CHECKSUM_unshift(st, val) SKM_sk_unshift(KRB5_CHECKSUM, (st), (val))\r
+#define sk_KRB5_CHECKSUM_find(st, val) SKM_sk_find(KRB5_CHECKSUM, (st), (val))\r
+#define sk_KRB5_CHECKSUM_find_ex(st, val) SKM_sk_find_ex(KRB5_CHECKSUM, (st), (val))\r
+#define sk_KRB5_CHECKSUM_delete(st, i) SKM_sk_delete(KRB5_CHECKSUM, (st), (i))\r
+#define sk_KRB5_CHECKSUM_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_CHECKSUM, (st), (ptr))\r
+#define sk_KRB5_CHECKSUM_insert(st, val, i) SKM_sk_insert(KRB5_CHECKSUM, (st), (val), (i))\r
+#define sk_KRB5_CHECKSUM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_CHECKSUM, (st), (cmp))\r
+#define sk_KRB5_CHECKSUM_dup(st) SKM_sk_dup(KRB5_CHECKSUM, st)\r
+#define sk_KRB5_CHECKSUM_pop_free(st, free_func) SKM_sk_pop_free(KRB5_CHECKSUM, (st), (free_func))\r
+#define sk_KRB5_CHECKSUM_shift(st) SKM_sk_shift(KRB5_CHECKSUM, (st))\r
+#define sk_KRB5_CHECKSUM_pop(st) SKM_sk_pop(KRB5_CHECKSUM, (st))\r
+#define sk_KRB5_CHECKSUM_sort(st) SKM_sk_sort(KRB5_CHECKSUM, (st))\r
+#define sk_KRB5_CHECKSUM_is_sorted(st) SKM_sk_is_sorted(KRB5_CHECKSUM, (st))\r
+\r
+#define sk_KRB5_ENCDATA_new(st) SKM_sk_new(KRB5_ENCDATA, (st))\r
+#define sk_KRB5_ENCDATA_new_null() SKM_sk_new_null(KRB5_ENCDATA)\r
+#define sk_KRB5_ENCDATA_free(st) SKM_sk_free(KRB5_ENCDATA, (st))\r
+#define sk_KRB5_ENCDATA_num(st) SKM_sk_num(KRB5_ENCDATA, (st))\r
+#define sk_KRB5_ENCDATA_value(st, i) SKM_sk_value(KRB5_ENCDATA, (st), (i))\r
+#define sk_KRB5_ENCDATA_set(st, i, val) SKM_sk_set(KRB5_ENCDATA, (st), (i), (val))\r
+#define sk_KRB5_ENCDATA_zero(st) SKM_sk_zero(KRB5_ENCDATA, (st))\r
+#define sk_KRB5_ENCDATA_push(st, val) SKM_sk_push(KRB5_ENCDATA, (st), (val))\r
+#define sk_KRB5_ENCDATA_unshift(st, val) SKM_sk_unshift(KRB5_ENCDATA, (st), (val))\r
+#define sk_KRB5_ENCDATA_find(st, val) SKM_sk_find(KRB5_ENCDATA, (st), (val))\r
+#define sk_KRB5_ENCDATA_find_ex(st, val) SKM_sk_find_ex(KRB5_ENCDATA, (st), (val))\r
+#define sk_KRB5_ENCDATA_delete(st, i) SKM_sk_delete(KRB5_ENCDATA, (st), (i))\r
+#define sk_KRB5_ENCDATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_ENCDATA, (st), (ptr))\r
+#define sk_KRB5_ENCDATA_insert(st, val, i) SKM_sk_insert(KRB5_ENCDATA, (st), (val), (i))\r
+#define sk_KRB5_ENCDATA_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_ENCDATA, (st), (cmp))\r
+#define sk_KRB5_ENCDATA_dup(st) SKM_sk_dup(KRB5_ENCDATA, st)\r
+#define sk_KRB5_ENCDATA_pop_free(st, free_func) SKM_sk_pop_free(KRB5_ENCDATA, (st), (free_func))\r
+#define sk_KRB5_ENCDATA_shift(st) SKM_sk_shift(KRB5_ENCDATA, (st))\r
+#define sk_KRB5_ENCDATA_pop(st) SKM_sk_pop(KRB5_ENCDATA, (st))\r
+#define sk_KRB5_ENCDATA_sort(st) SKM_sk_sort(KRB5_ENCDATA, (st))\r
+#define sk_KRB5_ENCDATA_is_sorted(st) SKM_sk_is_sorted(KRB5_ENCDATA, (st))\r
+\r
+#define sk_KRB5_ENCKEY_new(st) SKM_sk_new(KRB5_ENCKEY, (st))\r
+#define sk_KRB5_ENCKEY_new_null() SKM_sk_new_null(KRB5_ENCKEY)\r
+#define sk_KRB5_ENCKEY_free(st) SKM_sk_free(KRB5_ENCKEY, (st))\r
+#define sk_KRB5_ENCKEY_num(st) SKM_sk_num(KRB5_ENCKEY, (st))\r
+#define sk_KRB5_ENCKEY_value(st, i) SKM_sk_value(KRB5_ENCKEY, (st), (i))\r
+#define sk_KRB5_ENCKEY_set(st, i, val) SKM_sk_set(KRB5_ENCKEY, (st), (i), (val))\r
+#define sk_KRB5_ENCKEY_zero(st) SKM_sk_zero(KRB5_ENCKEY, (st))\r
+#define sk_KRB5_ENCKEY_push(st, val) SKM_sk_push(KRB5_ENCKEY, (st), (val))\r
+#define sk_KRB5_ENCKEY_unshift(st, val) SKM_sk_unshift(KRB5_ENCKEY, (st), (val))\r
+#define sk_KRB5_ENCKEY_find(st, val) SKM_sk_find(KRB5_ENCKEY, (st), (val))\r
+#define sk_KRB5_ENCKEY_find_ex(st, val) SKM_sk_find_ex(KRB5_ENCKEY, (st), (val))\r
+#define sk_KRB5_ENCKEY_delete(st, i) SKM_sk_delete(KRB5_ENCKEY, (st), (i))\r
+#define sk_KRB5_ENCKEY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_ENCKEY, (st), (ptr))\r
+#define sk_KRB5_ENCKEY_insert(st, val, i) SKM_sk_insert(KRB5_ENCKEY, (st), (val), (i))\r
+#define sk_KRB5_ENCKEY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_ENCKEY, (st), (cmp))\r
+#define sk_KRB5_ENCKEY_dup(st) SKM_sk_dup(KRB5_ENCKEY, st)\r
+#define sk_KRB5_ENCKEY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_ENCKEY, (st), (free_func))\r
+#define sk_KRB5_ENCKEY_shift(st) SKM_sk_shift(KRB5_ENCKEY, (st))\r
+#define sk_KRB5_ENCKEY_pop(st) SKM_sk_pop(KRB5_ENCKEY, (st))\r
+#define sk_KRB5_ENCKEY_sort(st) SKM_sk_sort(KRB5_ENCKEY, (st))\r
+#define sk_KRB5_ENCKEY_is_sorted(st) SKM_sk_is_sorted(KRB5_ENCKEY, (st))\r
+\r
+#define sk_KRB5_PRINCNAME_new(st) SKM_sk_new(KRB5_PRINCNAME, (st))\r
+#define sk_KRB5_PRINCNAME_new_null() SKM_sk_new_null(KRB5_PRINCNAME)\r
+#define sk_KRB5_PRINCNAME_free(st) SKM_sk_free(KRB5_PRINCNAME, (st))\r
+#define sk_KRB5_PRINCNAME_num(st) SKM_sk_num(KRB5_PRINCNAME, (st))\r
+#define sk_KRB5_PRINCNAME_value(st, i) SKM_sk_value(KRB5_PRINCNAME, (st), (i))\r
+#define sk_KRB5_PRINCNAME_set(st, i, val) SKM_sk_set(KRB5_PRINCNAME, (st), (i), (val))\r
+#define sk_KRB5_PRINCNAME_zero(st) SKM_sk_zero(KRB5_PRINCNAME, (st))\r
+#define sk_KRB5_PRINCNAME_push(st, val) SKM_sk_push(KRB5_PRINCNAME, (st), (val))\r
+#define sk_KRB5_PRINCNAME_unshift(st, val) SKM_sk_unshift(KRB5_PRINCNAME, (st), (val))\r
+#define sk_KRB5_PRINCNAME_find(st, val) SKM_sk_find(KRB5_PRINCNAME, (st), (val))\r
+#define sk_KRB5_PRINCNAME_find_ex(st, val) SKM_sk_find_ex(KRB5_PRINCNAME, (st), (val))\r
+#define sk_KRB5_PRINCNAME_delete(st, i) SKM_sk_delete(KRB5_PRINCNAME, (st), (i))\r
+#define sk_KRB5_PRINCNAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_PRINCNAME, (st), (ptr))\r
+#define sk_KRB5_PRINCNAME_insert(st, val, i) SKM_sk_insert(KRB5_PRINCNAME, (st), (val), (i))\r
+#define sk_KRB5_PRINCNAME_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_PRINCNAME, (st), (cmp))\r
+#define sk_KRB5_PRINCNAME_dup(st) SKM_sk_dup(KRB5_PRINCNAME, st)\r
+#define sk_KRB5_PRINCNAME_pop_free(st, free_func) SKM_sk_pop_free(KRB5_PRINCNAME, (st), (free_func))\r
+#define sk_KRB5_PRINCNAME_shift(st) SKM_sk_shift(KRB5_PRINCNAME, (st))\r
+#define sk_KRB5_PRINCNAME_pop(st) SKM_sk_pop(KRB5_PRINCNAME, (st))\r
+#define sk_KRB5_PRINCNAME_sort(st) SKM_sk_sort(KRB5_PRINCNAME, (st))\r
+#define sk_KRB5_PRINCNAME_is_sorted(st) SKM_sk_is_sorted(KRB5_PRINCNAME, (st))\r
+\r
+#define sk_KRB5_TKTBODY_new(st) SKM_sk_new(KRB5_TKTBODY, (st))\r
+#define sk_KRB5_TKTBODY_new_null() SKM_sk_new_null(KRB5_TKTBODY)\r
+#define sk_KRB5_TKTBODY_free(st) SKM_sk_free(KRB5_TKTBODY, (st))\r
+#define sk_KRB5_TKTBODY_num(st) SKM_sk_num(KRB5_TKTBODY, (st))\r
+#define sk_KRB5_TKTBODY_value(st, i) SKM_sk_value(KRB5_TKTBODY, (st), (i))\r
+#define sk_KRB5_TKTBODY_set(st, i, val) SKM_sk_set(KRB5_TKTBODY, (st), (i), (val))\r
+#define sk_KRB5_TKTBODY_zero(st) SKM_sk_zero(KRB5_TKTBODY, (st))\r
+#define sk_KRB5_TKTBODY_push(st, val) SKM_sk_push(KRB5_TKTBODY, (st), (val))\r
+#define sk_KRB5_TKTBODY_unshift(st, val) SKM_sk_unshift(KRB5_TKTBODY, (st), (val))\r
+#define sk_KRB5_TKTBODY_find(st, val) SKM_sk_find(KRB5_TKTBODY, (st), (val))\r
+#define sk_KRB5_TKTBODY_find_ex(st, val) SKM_sk_find_ex(KRB5_TKTBODY, (st), (val))\r
+#define sk_KRB5_TKTBODY_delete(st, i) SKM_sk_delete(KRB5_TKTBODY, (st), (i))\r
+#define sk_KRB5_TKTBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_TKTBODY, (st), (ptr))\r
+#define sk_KRB5_TKTBODY_insert(st, val, i) SKM_sk_insert(KRB5_TKTBODY, (st), (val), (i))\r
+#define sk_KRB5_TKTBODY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_TKTBODY, (st), (cmp))\r
+#define sk_KRB5_TKTBODY_dup(st) SKM_sk_dup(KRB5_TKTBODY, st)\r
+#define sk_KRB5_TKTBODY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_TKTBODY, (st), (free_func))\r
+#define sk_KRB5_TKTBODY_shift(st) SKM_sk_shift(KRB5_TKTBODY, (st))\r
+#define sk_KRB5_TKTBODY_pop(st) SKM_sk_pop(KRB5_TKTBODY, (st))\r
+#define sk_KRB5_TKTBODY_sort(st) SKM_sk_sort(KRB5_TKTBODY, (st))\r
+#define sk_KRB5_TKTBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_TKTBODY, (st))\r
+\r
+#define sk_MIME_HEADER_new(st) SKM_sk_new(MIME_HEADER, (st))\r
+#define sk_MIME_HEADER_new_null() SKM_sk_new_null(MIME_HEADER)\r
+#define sk_MIME_HEADER_free(st) SKM_sk_free(MIME_HEADER, (st))\r
+#define sk_MIME_HEADER_num(st) SKM_sk_num(MIME_HEADER, (st))\r
+#define sk_MIME_HEADER_value(st, i) SKM_sk_value(MIME_HEADER, (st), (i))\r
+#define sk_MIME_HEADER_set(st, i, val) SKM_sk_set(MIME_HEADER, (st), (i), (val))\r
+#define sk_MIME_HEADER_zero(st) SKM_sk_zero(MIME_HEADER, (st))\r
+#define sk_MIME_HEADER_push(st, val) SKM_sk_push(MIME_HEADER, (st), (val))\r
+#define sk_MIME_HEADER_unshift(st, val) SKM_sk_unshift(MIME_HEADER, (st), (val))\r
+#define sk_MIME_HEADER_find(st, val) SKM_sk_find(MIME_HEADER, (st), (val))\r
+#define sk_MIME_HEADER_find_ex(st, val) SKM_sk_find_ex(MIME_HEADER, (st), (val))\r
+#define sk_MIME_HEADER_delete(st, i) SKM_sk_delete(MIME_HEADER, (st), (i))\r
+#define sk_MIME_HEADER_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_HEADER, (st), (ptr))\r
+#define sk_MIME_HEADER_insert(st, val, i) SKM_sk_insert(MIME_HEADER, (st), (val), (i))\r
+#define sk_MIME_HEADER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(MIME_HEADER, (st), (cmp))\r
+#define sk_MIME_HEADER_dup(st) SKM_sk_dup(MIME_HEADER, st)\r
+#define sk_MIME_HEADER_pop_free(st, free_func) SKM_sk_pop_free(MIME_HEADER, (st), (free_func))\r
+#define sk_MIME_HEADER_shift(st) SKM_sk_shift(MIME_HEADER, (st))\r
+#define sk_MIME_HEADER_pop(st) SKM_sk_pop(MIME_HEADER, (st))\r
+#define sk_MIME_HEADER_sort(st) SKM_sk_sort(MIME_HEADER, (st))\r
+#define sk_MIME_HEADER_is_sorted(st) SKM_sk_is_sorted(MIME_HEADER, (st))\r
+\r
+#define sk_MIME_PARAM_new(st) SKM_sk_new(MIME_PARAM, (st))\r
+#define sk_MIME_PARAM_new_null() SKM_sk_new_null(MIME_PARAM)\r
+#define sk_MIME_PARAM_free(st) SKM_sk_free(MIME_PARAM, (st))\r
+#define sk_MIME_PARAM_num(st) SKM_sk_num(MIME_PARAM, (st))\r
+#define sk_MIME_PARAM_value(st, i) SKM_sk_value(MIME_PARAM, (st), (i))\r
+#define sk_MIME_PARAM_set(st, i, val) SKM_sk_set(MIME_PARAM, (st), (i), (val))\r
+#define sk_MIME_PARAM_zero(st) SKM_sk_zero(MIME_PARAM, (st))\r
+#define sk_MIME_PARAM_push(st, val) SKM_sk_push(MIME_PARAM, (st), (val))\r
+#define sk_MIME_PARAM_unshift(st, val) SKM_sk_unshift(MIME_PARAM, (st), (val))\r
+#define sk_MIME_PARAM_find(st, val) SKM_sk_find(MIME_PARAM, (st), (val))\r
+#define sk_MIME_PARAM_find_ex(st, val) SKM_sk_find_ex(MIME_PARAM, (st), (val))\r
+#define sk_MIME_PARAM_delete(st, i) SKM_sk_delete(MIME_PARAM, (st), (i))\r
+#define sk_MIME_PARAM_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_PARAM, (st), (ptr))\r
+#define sk_MIME_PARAM_insert(st, val, i) SKM_sk_insert(MIME_PARAM, (st), (val), (i))\r
+#define sk_MIME_PARAM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(MIME_PARAM, (st), (cmp))\r
+#define sk_MIME_PARAM_dup(st) SKM_sk_dup(MIME_PARAM, st)\r
+#define sk_MIME_PARAM_pop_free(st, free_func) SKM_sk_pop_free(MIME_PARAM, (st), (free_func))\r
+#define sk_MIME_PARAM_shift(st) SKM_sk_shift(MIME_PARAM, (st))\r
+#define sk_MIME_PARAM_pop(st) SKM_sk_pop(MIME_PARAM, (st))\r
+#define sk_MIME_PARAM_sort(st) SKM_sk_sort(MIME_PARAM, (st))\r
+#define sk_MIME_PARAM_is_sorted(st) SKM_sk_is_sorted(MIME_PARAM, (st))\r
+\r
+#define sk_NAME_FUNCS_new(st) SKM_sk_new(NAME_FUNCS, (st))\r
+#define sk_NAME_FUNCS_new_null() SKM_sk_new_null(NAME_FUNCS)\r
+#define sk_NAME_FUNCS_free(st) SKM_sk_free(NAME_FUNCS, (st))\r
+#define sk_NAME_FUNCS_num(st) SKM_sk_num(NAME_FUNCS, (st))\r
+#define sk_NAME_FUNCS_value(st, i) SKM_sk_value(NAME_FUNCS, (st), (i))\r
+#define sk_NAME_FUNCS_set(st, i, val) SKM_sk_set(NAME_FUNCS, (st), (i), (val))\r
+#define sk_NAME_FUNCS_zero(st) SKM_sk_zero(NAME_FUNCS, (st))\r
+#define sk_NAME_FUNCS_push(st, val) SKM_sk_push(NAME_FUNCS, (st), (val))\r
+#define sk_NAME_FUNCS_unshift(st, val) SKM_sk_unshift(NAME_FUNCS, (st), (val))\r
+#define sk_NAME_FUNCS_find(st, val) SKM_sk_find(NAME_FUNCS, (st), (val))\r
+#define sk_NAME_FUNCS_find_ex(st, val) SKM_sk_find_ex(NAME_FUNCS, (st), (val))\r
+#define sk_NAME_FUNCS_delete(st, i) SKM_sk_delete(NAME_FUNCS, (st), (i))\r
+#define sk_NAME_FUNCS_delete_ptr(st, ptr) SKM_sk_delete_ptr(NAME_FUNCS, (st), (ptr))\r
+#define sk_NAME_FUNCS_insert(st, val, i) SKM_sk_insert(NAME_FUNCS, (st), (val), (i))\r
+#define sk_NAME_FUNCS_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(NAME_FUNCS, (st), (cmp))\r
+#define sk_NAME_FUNCS_dup(st) SKM_sk_dup(NAME_FUNCS, st)\r
+#define sk_NAME_FUNCS_pop_free(st, free_func) SKM_sk_pop_free(NAME_FUNCS, (st), (free_func))\r
+#define sk_NAME_FUNCS_shift(st) SKM_sk_shift(NAME_FUNCS, (st))\r
+#define sk_NAME_FUNCS_pop(st) SKM_sk_pop(NAME_FUNCS, (st))\r
+#define sk_NAME_FUNCS_sort(st) SKM_sk_sort(NAME_FUNCS, (st))\r
+#define sk_NAME_FUNCS_is_sorted(st) SKM_sk_is_sorted(NAME_FUNCS, (st))\r
+\r
+#define sk_OCSP_CERTID_new(st) SKM_sk_new(OCSP_CERTID, (st))\r
+#define sk_OCSP_CERTID_new_null() SKM_sk_new_null(OCSP_CERTID)\r
+#define sk_OCSP_CERTID_free(st) SKM_sk_free(OCSP_CERTID, (st))\r
+#define sk_OCSP_CERTID_num(st) SKM_sk_num(OCSP_CERTID, (st))\r
+#define sk_OCSP_CERTID_value(st, i) SKM_sk_value(OCSP_CERTID, (st), (i))\r
+#define sk_OCSP_CERTID_set(st, i, val) SKM_sk_set(OCSP_CERTID, (st), (i), (val))\r
+#define sk_OCSP_CERTID_zero(st) SKM_sk_zero(OCSP_CERTID, (st))\r
+#define sk_OCSP_CERTID_push(st, val) SKM_sk_push(OCSP_CERTID, (st), (val))\r
+#define sk_OCSP_CERTID_unshift(st, val) SKM_sk_unshift(OCSP_CERTID, (st), (val))\r
+#define sk_OCSP_CERTID_find(st, val) SKM_sk_find(OCSP_CERTID, (st), (val))\r
+#define sk_OCSP_CERTID_find_ex(st, val) SKM_sk_find_ex(OCSP_CERTID, (st), (val))\r
+#define sk_OCSP_CERTID_delete(st, i) SKM_sk_delete(OCSP_CERTID, (st), (i))\r
+#define sk_OCSP_CERTID_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_CERTID, (st), (ptr))\r
+#define sk_OCSP_CERTID_insert(st, val, i) SKM_sk_insert(OCSP_CERTID, (st), (val), (i))\r
+#define sk_OCSP_CERTID_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_CERTID, (st), (cmp))\r
+#define sk_OCSP_CERTID_dup(st) SKM_sk_dup(OCSP_CERTID, st)\r
+#define sk_OCSP_CERTID_pop_free(st, free_func) SKM_sk_pop_free(OCSP_CERTID, (st), (free_func))\r
+#define sk_OCSP_CERTID_shift(st) SKM_sk_shift(OCSP_CERTID, (st))\r
+#define sk_OCSP_CERTID_pop(st) SKM_sk_pop(OCSP_CERTID, (st))\r
+#define sk_OCSP_CERTID_sort(st) SKM_sk_sort(OCSP_CERTID, (st))\r
+#define sk_OCSP_CERTID_is_sorted(st) SKM_sk_is_sorted(OCSP_CERTID, (st))\r
+\r
+#define sk_OCSP_ONEREQ_new(st) SKM_sk_new(OCSP_ONEREQ, (st))\r
+#define sk_OCSP_ONEREQ_new_null() SKM_sk_new_null(OCSP_ONEREQ)\r
+#define sk_OCSP_ONEREQ_free(st) SKM_sk_free(OCSP_ONEREQ, (st))\r
+#define sk_OCSP_ONEREQ_num(st) SKM_sk_num(OCSP_ONEREQ, (st))\r
+#define sk_OCSP_ONEREQ_value(st, i) SKM_sk_value(OCSP_ONEREQ, (st), (i))\r
+#define sk_OCSP_ONEREQ_set(st, i, val) SKM_sk_set(OCSP_ONEREQ, (st), (i), (val))\r
+#define sk_OCSP_ONEREQ_zero(st) SKM_sk_zero(OCSP_ONEREQ, (st))\r
+#define sk_OCSP_ONEREQ_push(st, val) SKM_sk_push(OCSP_ONEREQ, (st), (val))\r
+#define sk_OCSP_ONEREQ_unshift(st, val) SKM_sk_unshift(OCSP_ONEREQ, (st), (val))\r
+#define sk_OCSP_ONEREQ_find(st, val) SKM_sk_find(OCSP_ONEREQ, (st), (val))\r
+#define sk_OCSP_ONEREQ_find_ex(st, val) SKM_sk_find_ex(OCSP_ONEREQ, (st), (val))\r
+#define sk_OCSP_ONEREQ_delete(st, i) SKM_sk_delete(OCSP_ONEREQ, (st), (i))\r
+#define sk_OCSP_ONEREQ_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_ONEREQ, (st), (ptr))\r
+#define sk_OCSP_ONEREQ_insert(st, val, i) SKM_sk_insert(OCSP_ONEREQ, (st), (val), (i))\r
+#define sk_OCSP_ONEREQ_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_ONEREQ, (st), (cmp))\r
+#define sk_OCSP_ONEREQ_dup(st) SKM_sk_dup(OCSP_ONEREQ, st)\r
+#define sk_OCSP_ONEREQ_pop_free(st, free_func) SKM_sk_pop_free(OCSP_ONEREQ, (st), (free_func))\r
+#define sk_OCSP_ONEREQ_shift(st) SKM_sk_shift(OCSP_ONEREQ, (st))\r
+#define sk_OCSP_ONEREQ_pop(st) SKM_sk_pop(OCSP_ONEREQ, (st))\r
+#define sk_OCSP_ONEREQ_sort(st) SKM_sk_sort(OCSP_ONEREQ, (st))\r
+#define sk_OCSP_ONEREQ_is_sorted(st) SKM_sk_is_sorted(OCSP_ONEREQ, (st))\r
+\r
+#define sk_OCSP_SINGLERESP_new(st) SKM_sk_new(OCSP_SINGLERESP, (st))\r
+#define sk_OCSP_SINGLERESP_new_null() SKM_sk_new_null(OCSP_SINGLERESP)\r
+#define sk_OCSP_SINGLERESP_free(st) SKM_sk_free(OCSP_SINGLERESP, (st))\r
+#define sk_OCSP_SINGLERESP_num(st) SKM_sk_num(OCSP_SINGLERESP, (st))\r
+#define sk_OCSP_SINGLERESP_value(st, i) SKM_sk_value(OCSP_SINGLERESP, (st), (i))\r
+#define sk_OCSP_SINGLERESP_set(st, i, val) SKM_sk_set(OCSP_SINGLERESP, (st), (i), (val))\r
+#define sk_OCSP_SINGLERESP_zero(st) SKM_sk_zero(OCSP_SINGLERESP, (st))\r
+#define sk_OCSP_SINGLERESP_push(st, val) SKM_sk_push(OCSP_SINGLERESP, (st), (val))\r
+#define sk_OCSP_SINGLERESP_unshift(st, val) SKM_sk_unshift(OCSP_SINGLERESP, (st), (val))\r
+#define sk_OCSP_SINGLERESP_find(st, val) SKM_sk_find(OCSP_SINGLERESP, (st), (val))\r
+#define sk_OCSP_SINGLERESP_find_ex(st, val) SKM_sk_find_ex(OCSP_SINGLERESP, (st), (val))\r
+#define sk_OCSP_SINGLERESP_delete(st, i) SKM_sk_delete(OCSP_SINGLERESP, (st), (i))\r
+#define sk_OCSP_SINGLERESP_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_SINGLERESP, (st), (ptr))\r
+#define sk_OCSP_SINGLERESP_insert(st, val, i) SKM_sk_insert(OCSP_SINGLERESP, (st), (val), (i))\r
+#define sk_OCSP_SINGLERESP_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_SINGLERESP, (st), (cmp))\r
+#define sk_OCSP_SINGLERESP_dup(st) SKM_sk_dup(OCSP_SINGLERESP, st)\r
+#define sk_OCSP_SINGLERESP_pop_free(st, free_func) SKM_sk_pop_free(OCSP_SINGLERESP, (st), (free_func))\r
+#define sk_OCSP_SINGLERESP_shift(st) SKM_sk_shift(OCSP_SINGLERESP, (st))\r
+#define sk_OCSP_SINGLERESP_pop(st) SKM_sk_pop(OCSP_SINGLERESP, (st))\r
+#define sk_OCSP_SINGLERESP_sort(st) SKM_sk_sort(OCSP_SINGLERESP, (st))\r
+#define sk_OCSP_SINGLERESP_is_sorted(st) SKM_sk_is_sorted(OCSP_SINGLERESP, (st))\r
+\r
+#define sk_PKCS12_SAFEBAG_new(st) SKM_sk_new(PKCS12_SAFEBAG, (st))\r
+#define sk_PKCS12_SAFEBAG_new_null() SKM_sk_new_null(PKCS12_SAFEBAG)\r
+#define sk_PKCS12_SAFEBAG_free(st) SKM_sk_free(PKCS12_SAFEBAG, (st))\r
+#define sk_PKCS12_SAFEBAG_num(st) SKM_sk_num(PKCS12_SAFEBAG, (st))\r
+#define sk_PKCS12_SAFEBAG_value(st, i) SKM_sk_value(PKCS12_SAFEBAG, (st), (i))\r
+#define sk_PKCS12_SAFEBAG_set(st, i, val) SKM_sk_set(PKCS12_SAFEBAG, (st), (i), (val))\r
+#define sk_PKCS12_SAFEBAG_zero(st) SKM_sk_zero(PKCS12_SAFEBAG, (st))\r
+#define sk_PKCS12_SAFEBAG_push(st, val) SKM_sk_push(PKCS12_SAFEBAG, (st), (val))\r
+#define sk_PKCS12_SAFEBAG_unshift(st, val) SKM_sk_unshift(PKCS12_SAFEBAG, (st), (val))\r
+#define sk_PKCS12_SAFEBAG_find(st, val) SKM_sk_find(PKCS12_SAFEBAG, (st), (val))\r
+#define sk_PKCS12_SAFEBAG_find_ex(st, val) SKM_sk_find_ex(PKCS12_SAFEBAG, (st), (val))\r
+#define sk_PKCS12_SAFEBAG_delete(st, i) SKM_sk_delete(PKCS12_SAFEBAG, (st), (i))\r
+#define sk_PKCS12_SAFEBAG_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS12_SAFEBAG, (st), (ptr))\r
+#define sk_PKCS12_SAFEBAG_insert(st, val, i) SKM_sk_insert(PKCS12_SAFEBAG, (st), (val), (i))\r
+#define sk_PKCS12_SAFEBAG_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS12_SAFEBAG, (st), (cmp))\r
+#define sk_PKCS12_SAFEBAG_dup(st) SKM_sk_dup(PKCS12_SAFEBAG, st)\r
+#define sk_PKCS12_SAFEBAG_pop_free(st, free_func) SKM_sk_pop_free(PKCS12_SAFEBAG, (st), (free_func))\r
+#define sk_PKCS12_SAFEBAG_shift(st) SKM_sk_shift(PKCS12_SAFEBAG, (st))\r
+#define sk_PKCS12_SAFEBAG_pop(st) SKM_sk_pop(PKCS12_SAFEBAG, (st))\r
+#define sk_PKCS12_SAFEBAG_sort(st) SKM_sk_sort(PKCS12_SAFEBAG, (st))\r
+#define sk_PKCS12_SAFEBAG_is_sorted(st) SKM_sk_is_sorted(PKCS12_SAFEBAG, (st))\r
+\r
+#define sk_PKCS7_new(st) SKM_sk_new(PKCS7, (st))\r
+#define sk_PKCS7_new_null() SKM_sk_new_null(PKCS7)\r
+#define sk_PKCS7_free(st) SKM_sk_free(PKCS7, (st))\r
+#define sk_PKCS7_num(st) SKM_sk_num(PKCS7, (st))\r
+#define sk_PKCS7_value(st, i) SKM_sk_value(PKCS7, (st), (i))\r
+#define sk_PKCS7_set(st, i, val) SKM_sk_set(PKCS7, (st), (i), (val))\r
+#define sk_PKCS7_zero(st) SKM_sk_zero(PKCS7, (st))\r
+#define sk_PKCS7_push(st, val) SKM_sk_push(PKCS7, (st), (val))\r
+#define sk_PKCS7_unshift(st, val) SKM_sk_unshift(PKCS7, (st), (val))\r
+#define sk_PKCS7_find(st, val) SKM_sk_find(PKCS7, (st), (val))\r
+#define sk_PKCS7_find_ex(st, val) SKM_sk_find_ex(PKCS7, (st), (val))\r
+#define sk_PKCS7_delete(st, i) SKM_sk_delete(PKCS7, (st), (i))\r
+#define sk_PKCS7_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7, (st), (ptr))\r
+#define sk_PKCS7_insert(st, val, i) SKM_sk_insert(PKCS7, (st), (val), (i))\r
+#define sk_PKCS7_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS7, (st), (cmp))\r
+#define sk_PKCS7_dup(st) SKM_sk_dup(PKCS7, st)\r
+#define sk_PKCS7_pop_free(st, free_func) SKM_sk_pop_free(PKCS7, (st), (free_func))\r
+#define sk_PKCS7_shift(st) SKM_sk_shift(PKCS7, (st))\r
+#define sk_PKCS7_pop(st) SKM_sk_pop(PKCS7, (st))\r
+#define sk_PKCS7_sort(st) SKM_sk_sort(PKCS7, (st))\r
+#define sk_PKCS7_is_sorted(st) SKM_sk_is_sorted(PKCS7, (st))\r
+\r
+#define sk_PKCS7_RECIP_INFO_new(st) SKM_sk_new(PKCS7_RECIP_INFO, (st))\r
+#define sk_PKCS7_RECIP_INFO_new_null() SKM_sk_new_null(PKCS7_RECIP_INFO)\r
+#define sk_PKCS7_RECIP_INFO_free(st) SKM_sk_free(PKCS7_RECIP_INFO, (st))\r
+#define sk_PKCS7_RECIP_INFO_num(st) SKM_sk_num(PKCS7_RECIP_INFO, (st))\r
+#define sk_PKCS7_RECIP_INFO_value(st, i) SKM_sk_value(PKCS7_RECIP_INFO, (st), (i))\r
+#define sk_PKCS7_RECIP_INFO_set(st, i, val) SKM_sk_set(PKCS7_RECIP_INFO, (st), (i), (val))\r
+#define sk_PKCS7_RECIP_INFO_zero(st) SKM_sk_zero(PKCS7_RECIP_INFO, (st))\r
+#define sk_PKCS7_RECIP_INFO_push(st, val) SKM_sk_push(PKCS7_RECIP_INFO, (st), (val))\r
+#define sk_PKCS7_RECIP_INFO_unshift(st, val) SKM_sk_unshift(PKCS7_RECIP_INFO, (st), (val))\r
+#define sk_PKCS7_RECIP_INFO_find(st, val) SKM_sk_find(PKCS7_RECIP_INFO, (st), (val))\r
+#define sk_PKCS7_RECIP_INFO_find_ex(st, val) SKM_sk_find_ex(PKCS7_RECIP_INFO, (st), (val))\r
+#define sk_PKCS7_RECIP_INFO_delete(st, i) SKM_sk_delete(PKCS7_RECIP_INFO, (st), (i))\r
+#define sk_PKCS7_RECIP_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7_RECIP_INFO, (st), (ptr))\r
+#define sk_PKCS7_RECIP_INFO_insert(st, val, i) SKM_sk_insert(PKCS7_RECIP_INFO, (st), (val), (i))\r
+#define sk_PKCS7_RECIP_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS7_RECIP_INFO, (st), (cmp))\r
+#define sk_PKCS7_RECIP_INFO_dup(st) SKM_sk_dup(PKCS7_RECIP_INFO, st)\r
+#define sk_PKCS7_RECIP_INFO_pop_free(st, free_func) SKM_sk_pop_free(PKCS7_RECIP_INFO, (st), (free_func))\r
+#define sk_PKCS7_RECIP_INFO_shift(st) SKM_sk_shift(PKCS7_RECIP_INFO, (st))\r
+#define sk_PKCS7_RECIP_INFO_pop(st) SKM_sk_pop(PKCS7_RECIP_INFO, (st))\r
+#define sk_PKCS7_RECIP_INFO_sort(st) SKM_sk_sort(PKCS7_RECIP_INFO, (st))\r
+#define sk_PKCS7_RECIP_INFO_is_sorted(st) SKM_sk_is_sorted(PKCS7_RECIP_INFO, (st))\r
+\r
+#define sk_PKCS7_SIGNER_INFO_new(st) SKM_sk_new(PKCS7_SIGNER_INFO, (st))\r
+#define sk_PKCS7_SIGNER_INFO_new_null() SKM_sk_new_null(PKCS7_SIGNER_INFO)\r
+#define sk_PKCS7_SIGNER_INFO_free(st) SKM_sk_free(PKCS7_SIGNER_INFO, (st))\r
+#define sk_PKCS7_SIGNER_INFO_num(st) SKM_sk_num(PKCS7_SIGNER_INFO, (st))\r
+#define sk_PKCS7_SIGNER_INFO_value(st, i) SKM_sk_value(PKCS7_SIGNER_INFO, (st), (i))\r
+#define sk_PKCS7_SIGNER_INFO_set(st, i, val) SKM_sk_set(PKCS7_SIGNER_INFO, (st), (i), (val))\r
+#define sk_PKCS7_SIGNER_INFO_zero(st) SKM_sk_zero(PKCS7_SIGNER_INFO, (st))\r
+#define sk_PKCS7_SIGNER_INFO_push(st, val) SKM_sk_push(PKCS7_SIGNER_INFO, (st), (val))\r
+#define sk_PKCS7_SIGNER_INFO_unshift(st, val) SKM_sk_unshift(PKCS7_SIGNER_INFO, (st), (val))\r
+#define sk_PKCS7_SIGNER_INFO_find(st, val) SKM_sk_find(PKCS7_SIGNER_INFO, (st), (val))\r
+#define sk_PKCS7_SIGNER_INFO_find_ex(st, val) SKM_sk_find_ex(PKCS7_SIGNER_INFO, (st), (val))\r
+#define sk_PKCS7_SIGNER_INFO_delete(st, i) SKM_sk_delete(PKCS7_SIGNER_INFO, (st), (i))\r
+#define sk_PKCS7_SIGNER_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7_SIGNER_INFO, (st), (ptr))\r
+#define sk_PKCS7_SIGNER_INFO_insert(st, val, i) SKM_sk_insert(PKCS7_SIGNER_INFO, (st), (val), (i))\r
+#define sk_PKCS7_SIGNER_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS7_SIGNER_INFO, (st), (cmp))\r
+#define sk_PKCS7_SIGNER_INFO_dup(st) SKM_sk_dup(PKCS7_SIGNER_INFO, st)\r
+#define sk_PKCS7_SIGNER_INFO_pop_free(st, free_func) SKM_sk_pop_free(PKCS7_SIGNER_INFO, (st), (free_func))\r
+#define sk_PKCS7_SIGNER_INFO_shift(st) SKM_sk_shift(PKCS7_SIGNER_INFO, (st))\r
+#define sk_PKCS7_SIGNER_INFO_pop(st) SKM_sk_pop(PKCS7_SIGNER_INFO, (st))\r
+#define sk_PKCS7_SIGNER_INFO_sort(st) SKM_sk_sort(PKCS7_SIGNER_INFO, (st))\r
+#define sk_PKCS7_SIGNER_INFO_is_sorted(st) SKM_sk_is_sorted(PKCS7_SIGNER_INFO, (st))\r
+\r
+#define sk_POLICYINFO_new(st) SKM_sk_new(POLICYINFO, (st))\r
+#define sk_POLICYINFO_new_null() SKM_sk_new_null(POLICYINFO)\r
+#define sk_POLICYINFO_free(st) SKM_sk_free(POLICYINFO, (st))\r
+#define sk_POLICYINFO_num(st) SKM_sk_num(POLICYINFO, (st))\r
+#define sk_POLICYINFO_value(st, i) SKM_sk_value(POLICYINFO, (st), (i))\r
+#define sk_POLICYINFO_set(st, i, val) SKM_sk_set(POLICYINFO, (st), (i), (val))\r
+#define sk_POLICYINFO_zero(st) SKM_sk_zero(POLICYINFO, (st))\r
+#define sk_POLICYINFO_push(st, val) SKM_sk_push(POLICYINFO, (st), (val))\r
+#define sk_POLICYINFO_unshift(st, val) SKM_sk_unshift(POLICYINFO, (st), (val))\r
+#define sk_POLICYINFO_find(st, val) SKM_sk_find(POLICYINFO, (st), (val))\r
+#define sk_POLICYINFO_find_ex(st, val) SKM_sk_find_ex(POLICYINFO, (st), (val))\r
+#define sk_POLICYINFO_delete(st, i) SKM_sk_delete(POLICYINFO, (st), (i))\r
+#define sk_POLICYINFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICYINFO, (st), (ptr))\r
+#define sk_POLICYINFO_insert(st, val, i) SKM_sk_insert(POLICYINFO, (st), (val), (i))\r
+#define sk_POLICYINFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(POLICYINFO, (st), (cmp))\r
+#define sk_POLICYINFO_dup(st) SKM_sk_dup(POLICYINFO, st)\r
+#define sk_POLICYINFO_pop_free(st, free_func) SKM_sk_pop_free(POLICYINFO, (st), (free_func))\r
+#define sk_POLICYINFO_shift(st) SKM_sk_shift(POLICYINFO, (st))\r
+#define sk_POLICYINFO_pop(st) SKM_sk_pop(POLICYINFO, (st))\r
+#define sk_POLICYINFO_sort(st) SKM_sk_sort(POLICYINFO, (st))\r
+#define sk_POLICYINFO_is_sorted(st) SKM_sk_is_sorted(POLICYINFO, (st))\r
+\r
+#define sk_POLICYQUALINFO_new(st) SKM_sk_new(POLICYQUALINFO, (st))\r
+#define sk_POLICYQUALINFO_new_null() SKM_sk_new_null(POLICYQUALINFO)\r
+#define sk_POLICYQUALINFO_free(st) SKM_sk_free(POLICYQUALINFO, (st))\r
+#define sk_POLICYQUALINFO_num(st) SKM_sk_num(POLICYQUALINFO, (st))\r
+#define sk_POLICYQUALINFO_value(st, i) SKM_sk_value(POLICYQUALINFO, (st), (i))\r
+#define sk_POLICYQUALINFO_set(st, i, val) SKM_sk_set(POLICYQUALINFO, (st), (i), (val))\r
+#define sk_POLICYQUALINFO_zero(st) SKM_sk_zero(POLICYQUALINFO, (st))\r
+#define sk_POLICYQUALINFO_push(st, val) SKM_sk_push(POLICYQUALINFO, (st), (val))\r
+#define sk_POLICYQUALINFO_unshift(st, val) SKM_sk_unshift(POLICYQUALINFO, (st), (val))\r
+#define sk_POLICYQUALINFO_find(st, val) SKM_sk_find(POLICYQUALINFO, (st), (val))\r
+#define sk_POLICYQUALINFO_find_ex(st, val) SKM_sk_find_ex(POLICYQUALINFO, (st), (val))\r
+#define sk_POLICYQUALINFO_delete(st, i) SKM_sk_delete(POLICYQUALINFO, (st), (i))\r
+#define sk_POLICYQUALINFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICYQUALINFO, (st), (ptr))\r
+#define sk_POLICYQUALINFO_insert(st, val, i) SKM_sk_insert(POLICYQUALINFO, (st), (val), (i))\r
+#define sk_POLICYQUALINFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(POLICYQUALINFO, (st), (cmp))\r
+#define sk_POLICYQUALINFO_dup(st) SKM_sk_dup(POLICYQUALINFO, st)\r
+#define sk_POLICYQUALINFO_pop_free(st, free_func) SKM_sk_pop_free(POLICYQUALINFO, (st), (free_func))\r
+#define sk_POLICYQUALINFO_shift(st) SKM_sk_shift(POLICYQUALINFO, (st))\r
+#define sk_POLICYQUALINFO_pop(st) SKM_sk_pop(POLICYQUALINFO, (st))\r
+#define sk_POLICYQUALINFO_sort(st) SKM_sk_sort(POLICYQUALINFO, (st))\r
+#define sk_POLICYQUALINFO_is_sorted(st) SKM_sk_is_sorted(POLICYQUALINFO, (st))\r
+\r
+#define sk_POLICY_MAPPING_new(st) SKM_sk_new(POLICY_MAPPING, (st))\r
+#define sk_POLICY_MAPPING_new_null() SKM_sk_new_null(POLICY_MAPPING)\r
+#define sk_POLICY_MAPPING_free(st) SKM_sk_free(POLICY_MAPPING, (st))\r
+#define sk_POLICY_MAPPING_num(st) SKM_sk_num(POLICY_MAPPING, (st))\r
+#define sk_POLICY_MAPPING_value(st, i) SKM_sk_value(POLICY_MAPPING, (st), (i))\r
+#define sk_POLICY_MAPPING_set(st, i, val) SKM_sk_set(POLICY_MAPPING, (st), (i), (val))\r
+#define sk_POLICY_MAPPING_zero(st) SKM_sk_zero(POLICY_MAPPING, (st))\r
+#define sk_POLICY_MAPPING_push(st, val) SKM_sk_push(POLICY_MAPPING, (st), (val))\r
+#define sk_POLICY_MAPPING_unshift(st, val) SKM_sk_unshift(POLICY_MAPPING, (st), (val))\r
+#define sk_POLICY_MAPPING_find(st, val) SKM_sk_find(POLICY_MAPPING, (st), (val))\r
+#define sk_POLICY_MAPPING_find_ex(st, val) SKM_sk_find_ex(POLICY_MAPPING, (st), (val))\r
+#define sk_POLICY_MAPPING_delete(st, i) SKM_sk_delete(POLICY_MAPPING, (st), (i))\r
+#define sk_POLICY_MAPPING_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICY_MAPPING, (st), (ptr))\r
+#define sk_POLICY_MAPPING_insert(st, val, i) SKM_sk_insert(POLICY_MAPPING, (st), (val), (i))\r
+#define sk_POLICY_MAPPING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(POLICY_MAPPING, (st), (cmp))\r
+#define sk_POLICY_MAPPING_dup(st) SKM_sk_dup(POLICY_MAPPING, st)\r
+#define sk_POLICY_MAPPING_pop_free(st, free_func) SKM_sk_pop_free(POLICY_MAPPING, (st), (free_func))\r
+#define sk_POLICY_MAPPING_shift(st) SKM_sk_shift(POLICY_MAPPING, (st))\r
+#define sk_POLICY_MAPPING_pop(st) SKM_sk_pop(POLICY_MAPPING, (st))\r
+#define sk_POLICY_MAPPING_sort(st) SKM_sk_sort(POLICY_MAPPING, (st))\r
+#define sk_POLICY_MAPPING_is_sorted(st) SKM_sk_is_sorted(POLICY_MAPPING, (st))\r
+\r
+#define sk_SSL_CIPHER_new(st) SKM_sk_new(SSL_CIPHER, (st))\r
+#define sk_SSL_CIPHER_new_null() SKM_sk_new_null(SSL_CIPHER)\r
+#define sk_SSL_CIPHER_free(st) SKM_sk_free(SSL_CIPHER, (st))\r
+#define sk_SSL_CIPHER_num(st) SKM_sk_num(SSL_CIPHER, (st))\r
+#define sk_SSL_CIPHER_value(st, i) SKM_sk_value(SSL_CIPHER, (st), (i))\r
+#define sk_SSL_CIPHER_set(st, i, val) SKM_sk_set(SSL_CIPHER, (st), (i), (val))\r
+#define sk_SSL_CIPHER_zero(st) SKM_sk_zero(SSL_CIPHER, (st))\r
+#define sk_SSL_CIPHER_push(st, val) SKM_sk_push(SSL_CIPHER, (st), (val))\r
+#define sk_SSL_CIPHER_unshift(st, val) SKM_sk_unshift(SSL_CIPHER, (st), (val))\r
+#define sk_SSL_CIPHER_find(st, val) SKM_sk_find(SSL_CIPHER, (st), (val))\r
+#define sk_SSL_CIPHER_find_ex(st, val) SKM_sk_find_ex(SSL_CIPHER, (st), (val))\r
+#define sk_SSL_CIPHER_delete(st, i) SKM_sk_delete(SSL_CIPHER, (st), (i))\r
+#define sk_SSL_CIPHER_delete_ptr(st, ptr) SKM_sk_delete_ptr(SSL_CIPHER, (st), (ptr))\r
+#define sk_SSL_CIPHER_insert(st, val, i) SKM_sk_insert(SSL_CIPHER, (st), (val), (i))\r
+#define sk_SSL_CIPHER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(SSL_CIPHER, (st), (cmp))\r
+#define sk_SSL_CIPHER_dup(st) SKM_sk_dup(SSL_CIPHER, st)\r
+#define sk_SSL_CIPHER_pop_free(st, free_func) SKM_sk_pop_free(SSL_CIPHER, (st), (free_func))\r
+#define sk_SSL_CIPHER_shift(st) SKM_sk_shift(SSL_CIPHER, (st))\r
+#define sk_SSL_CIPHER_pop(st) SKM_sk_pop(SSL_CIPHER, (st))\r
+#define sk_SSL_CIPHER_sort(st) SKM_sk_sort(SSL_CIPHER, (st))\r
+#define sk_SSL_CIPHER_is_sorted(st) SKM_sk_is_sorted(SSL_CIPHER, (st))\r
+\r
+#define sk_SSL_COMP_new(st) SKM_sk_new(SSL_COMP, (st))\r
+#define sk_SSL_COMP_new_null() SKM_sk_new_null(SSL_COMP)\r
+#define sk_SSL_COMP_free(st) SKM_sk_free(SSL_COMP, (st))\r
+#define sk_SSL_COMP_num(st) SKM_sk_num(SSL_COMP, (st))\r
+#define sk_SSL_COMP_value(st, i) SKM_sk_value(SSL_COMP, (st), (i))\r
+#define sk_SSL_COMP_set(st, i, val) SKM_sk_set(SSL_COMP, (st), (i), (val))\r
+#define sk_SSL_COMP_zero(st) SKM_sk_zero(SSL_COMP, (st))\r
+#define sk_SSL_COMP_push(st, val) SKM_sk_push(SSL_COMP, (st), (val))\r
+#define sk_SSL_COMP_unshift(st, val) SKM_sk_unshift(SSL_COMP, (st), (val))\r
+#define sk_SSL_COMP_find(st, val) SKM_sk_find(SSL_COMP, (st), (val))\r
+#define sk_SSL_COMP_find_ex(st, val) SKM_sk_find_ex(SSL_COMP, (st), (val))\r
+#define sk_SSL_COMP_delete(st, i) SKM_sk_delete(SSL_COMP, (st), (i))\r
+#define sk_SSL_COMP_delete_ptr(st, ptr) SKM_sk_delete_ptr(SSL_COMP, (st), (ptr))\r
+#define sk_SSL_COMP_insert(st, val, i) SKM_sk_insert(SSL_COMP, (st), (val), (i))\r
+#define sk_SSL_COMP_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(SSL_COMP, (st), (cmp))\r
+#define sk_SSL_COMP_dup(st) SKM_sk_dup(SSL_COMP, st)\r
+#define sk_SSL_COMP_pop_free(st, free_func) SKM_sk_pop_free(SSL_COMP, (st), (free_func))\r
+#define sk_SSL_COMP_shift(st) SKM_sk_shift(SSL_COMP, (st))\r
+#define sk_SSL_COMP_pop(st) SKM_sk_pop(SSL_COMP, (st))\r
+#define sk_SSL_COMP_sort(st) SKM_sk_sort(SSL_COMP, (st))\r
+#define sk_SSL_COMP_is_sorted(st) SKM_sk_is_sorted(SSL_COMP, (st))\r
+\r
+#define sk_STORE_OBJECT_new(st) SKM_sk_new(STORE_OBJECT, (st))\r
+#define sk_STORE_OBJECT_new_null() SKM_sk_new_null(STORE_OBJECT)\r
+#define sk_STORE_OBJECT_free(st) SKM_sk_free(STORE_OBJECT, (st))\r
+#define sk_STORE_OBJECT_num(st) SKM_sk_num(STORE_OBJECT, (st))\r
+#define sk_STORE_OBJECT_value(st, i) SKM_sk_value(STORE_OBJECT, (st), (i))\r
+#define sk_STORE_OBJECT_set(st, i, val) SKM_sk_set(STORE_OBJECT, (st), (i), (val))\r
+#define sk_STORE_OBJECT_zero(st) SKM_sk_zero(STORE_OBJECT, (st))\r
+#define sk_STORE_OBJECT_push(st, val) SKM_sk_push(STORE_OBJECT, (st), (val))\r
+#define sk_STORE_OBJECT_unshift(st, val) SKM_sk_unshift(STORE_OBJECT, (st), (val))\r
+#define sk_STORE_OBJECT_find(st, val) SKM_sk_find(STORE_OBJECT, (st), (val))\r
+#define sk_STORE_OBJECT_find_ex(st, val) SKM_sk_find_ex(STORE_OBJECT, (st), (val))\r
+#define sk_STORE_OBJECT_delete(st, i) SKM_sk_delete(STORE_OBJECT, (st), (i))\r
+#define sk_STORE_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(STORE_OBJECT, (st), (ptr))\r
+#define sk_STORE_OBJECT_insert(st, val, i) SKM_sk_insert(STORE_OBJECT, (st), (val), (i))\r
+#define sk_STORE_OBJECT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(STORE_OBJECT, (st), (cmp))\r
+#define sk_STORE_OBJECT_dup(st) SKM_sk_dup(STORE_OBJECT, st)\r
+#define sk_STORE_OBJECT_pop_free(st, free_func) SKM_sk_pop_free(STORE_OBJECT, (st), (free_func))\r
+#define sk_STORE_OBJECT_shift(st) SKM_sk_shift(STORE_OBJECT, (st))\r
+#define sk_STORE_OBJECT_pop(st) SKM_sk_pop(STORE_OBJECT, (st))\r
+#define sk_STORE_OBJECT_sort(st) SKM_sk_sort(STORE_OBJECT, (st))\r
+#define sk_STORE_OBJECT_is_sorted(st) SKM_sk_is_sorted(STORE_OBJECT, (st))\r
+\r
+#define sk_SXNETID_new(st) SKM_sk_new(SXNETID, (st))\r
+#define sk_SXNETID_new_null() SKM_sk_new_null(SXNETID)\r
+#define sk_SXNETID_free(st) SKM_sk_free(SXNETID, (st))\r
+#define sk_SXNETID_num(st) SKM_sk_num(SXNETID, (st))\r
+#define sk_SXNETID_value(st, i) SKM_sk_value(SXNETID, (st), (i))\r
+#define sk_SXNETID_set(st, i, val) SKM_sk_set(SXNETID, (st), (i), (val))\r
+#define sk_SXNETID_zero(st) SKM_sk_zero(SXNETID, (st))\r
+#define sk_SXNETID_push(st, val) SKM_sk_push(SXNETID, (st), (val))\r
+#define sk_SXNETID_unshift(st, val) SKM_sk_unshift(SXNETID, (st), (val))\r
+#define sk_SXNETID_find(st, val) SKM_sk_find(SXNETID, (st), (val))\r
+#define sk_SXNETID_find_ex(st, val) SKM_sk_find_ex(SXNETID, (st), (val))\r
+#define sk_SXNETID_delete(st, i) SKM_sk_delete(SXNETID, (st), (i))\r
+#define sk_SXNETID_delete_ptr(st, ptr) SKM_sk_delete_ptr(SXNETID, (st), (ptr))\r
+#define sk_SXNETID_insert(st, val, i) SKM_sk_insert(SXNETID, (st), (val), (i))\r
+#define sk_SXNETID_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(SXNETID, (st), (cmp))\r
+#define sk_SXNETID_dup(st) SKM_sk_dup(SXNETID, st)\r
+#define sk_SXNETID_pop_free(st, free_func) SKM_sk_pop_free(SXNETID, (st), (free_func))\r
+#define sk_SXNETID_shift(st) SKM_sk_shift(SXNETID, (st))\r
+#define sk_SXNETID_pop(st) SKM_sk_pop(SXNETID, (st))\r
+#define sk_SXNETID_sort(st) SKM_sk_sort(SXNETID, (st))\r
+#define sk_SXNETID_is_sorted(st) SKM_sk_is_sorted(SXNETID, (st))\r
+\r
+#define sk_UI_STRING_new(st) SKM_sk_new(UI_STRING, (st))\r
+#define sk_UI_STRING_new_null() SKM_sk_new_null(UI_STRING)\r
+#define sk_UI_STRING_free(st) SKM_sk_free(UI_STRING, (st))\r
+#define sk_UI_STRING_num(st) SKM_sk_num(UI_STRING, (st))\r
+#define sk_UI_STRING_value(st, i) SKM_sk_value(UI_STRING, (st), (i))\r
+#define sk_UI_STRING_set(st, i, val) SKM_sk_set(UI_STRING, (st), (i), (val))\r
+#define sk_UI_STRING_zero(st) SKM_sk_zero(UI_STRING, (st))\r
+#define sk_UI_STRING_push(st, val) SKM_sk_push(UI_STRING, (st), (val))\r
+#define sk_UI_STRING_unshift(st, val) SKM_sk_unshift(UI_STRING, (st), (val))\r
+#define sk_UI_STRING_find(st, val) SKM_sk_find(UI_STRING, (st), (val))\r
+#define sk_UI_STRING_find_ex(st, val) SKM_sk_find_ex(UI_STRING, (st), (val))\r
+#define sk_UI_STRING_delete(st, i) SKM_sk_delete(UI_STRING, (st), (i))\r
+#define sk_UI_STRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(UI_STRING, (st), (ptr))\r
+#define sk_UI_STRING_insert(st, val, i) SKM_sk_insert(UI_STRING, (st), (val), (i))\r
+#define sk_UI_STRING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(UI_STRING, (st), (cmp))\r
+#define sk_UI_STRING_dup(st) SKM_sk_dup(UI_STRING, st)\r
+#define sk_UI_STRING_pop_free(st, free_func) SKM_sk_pop_free(UI_STRING, (st), (free_func))\r
+#define sk_UI_STRING_shift(st) SKM_sk_shift(UI_STRING, (st))\r
+#define sk_UI_STRING_pop(st) SKM_sk_pop(UI_STRING, (st))\r
+#define sk_UI_STRING_sort(st) SKM_sk_sort(UI_STRING, (st))\r
+#define sk_UI_STRING_is_sorted(st) SKM_sk_is_sorted(UI_STRING, (st))\r
+\r
+#define sk_X509_new(st) SKM_sk_new(X509, (st))\r
+#define sk_X509_new_null() SKM_sk_new_null(X509)\r
+#define sk_X509_free(st) SKM_sk_free(X509, (st))\r
+#define sk_X509_num(st) SKM_sk_num(X509, (st))\r
+#define sk_X509_value(st, i) SKM_sk_value(X509, (st), (i))\r
+#define sk_X509_set(st, i, val) SKM_sk_set(X509, (st), (i), (val))\r
+#define sk_X509_zero(st) SKM_sk_zero(X509, (st))\r
+#define sk_X509_push(st, val) SKM_sk_push(X509, (st), (val))\r
+#define sk_X509_unshift(st, val) SKM_sk_unshift(X509, (st), (val))\r
+#define sk_X509_find(st, val) SKM_sk_find(X509, (st), (val))\r
+#define sk_X509_find_ex(st, val) SKM_sk_find_ex(X509, (st), (val))\r
+#define sk_X509_delete(st, i) SKM_sk_delete(X509, (st), (i))\r
+#define sk_X509_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509, (st), (ptr))\r
+#define sk_X509_insert(st, val, i) SKM_sk_insert(X509, (st), (val), (i))\r
+#define sk_X509_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509, (st), (cmp))\r
+#define sk_X509_dup(st) SKM_sk_dup(X509, st)\r
+#define sk_X509_pop_free(st, free_func) SKM_sk_pop_free(X509, (st), (free_func))\r
+#define sk_X509_shift(st) SKM_sk_shift(X509, (st))\r
+#define sk_X509_pop(st) SKM_sk_pop(X509, (st))\r
+#define sk_X509_sort(st) SKM_sk_sort(X509, (st))\r
+#define sk_X509_is_sorted(st) SKM_sk_is_sorted(X509, (st))\r
+\r
+#define sk_X509V3_EXT_METHOD_new(st) SKM_sk_new(X509V3_EXT_METHOD, (st))\r
+#define sk_X509V3_EXT_METHOD_new_null() SKM_sk_new_null(X509V3_EXT_METHOD)\r
+#define sk_X509V3_EXT_METHOD_free(st) SKM_sk_free(X509V3_EXT_METHOD, (st))\r
+#define sk_X509V3_EXT_METHOD_num(st) SKM_sk_num(X509V3_EXT_METHOD, (st))\r
+#define sk_X509V3_EXT_METHOD_value(st, i) SKM_sk_value(X509V3_EXT_METHOD, (st), (i))\r
+#define sk_X509V3_EXT_METHOD_set(st, i, val) SKM_sk_set(X509V3_EXT_METHOD, (st), (i), (val))\r
+#define sk_X509V3_EXT_METHOD_zero(st) SKM_sk_zero(X509V3_EXT_METHOD, (st))\r
+#define sk_X509V3_EXT_METHOD_push(st, val) SKM_sk_push(X509V3_EXT_METHOD, (st), (val))\r
+#define sk_X509V3_EXT_METHOD_unshift(st, val) SKM_sk_unshift(X509V3_EXT_METHOD, (st), (val))\r
+#define sk_X509V3_EXT_METHOD_find(st, val) SKM_sk_find(X509V3_EXT_METHOD, (st), (val))\r
+#define sk_X509V3_EXT_METHOD_find_ex(st, val) SKM_sk_find_ex(X509V3_EXT_METHOD, (st), (val))\r
+#define sk_X509V3_EXT_METHOD_delete(st, i) SKM_sk_delete(X509V3_EXT_METHOD, (st), (i))\r
+#define sk_X509V3_EXT_METHOD_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509V3_EXT_METHOD, (st), (ptr))\r
+#define sk_X509V3_EXT_METHOD_insert(st, val, i) SKM_sk_insert(X509V3_EXT_METHOD, (st), (val), (i))\r
+#define sk_X509V3_EXT_METHOD_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509V3_EXT_METHOD, (st), (cmp))\r
+#define sk_X509V3_EXT_METHOD_dup(st) SKM_sk_dup(X509V3_EXT_METHOD, st)\r
+#define sk_X509V3_EXT_METHOD_pop_free(st, free_func) SKM_sk_pop_free(X509V3_EXT_METHOD, (st), (free_func))\r
+#define sk_X509V3_EXT_METHOD_shift(st) SKM_sk_shift(X509V3_EXT_METHOD, (st))\r
+#define sk_X509V3_EXT_METHOD_pop(st) SKM_sk_pop(X509V3_EXT_METHOD, (st))\r
+#define sk_X509V3_EXT_METHOD_sort(st) SKM_sk_sort(X509V3_EXT_METHOD, (st))\r
+#define sk_X509V3_EXT_METHOD_is_sorted(st) SKM_sk_is_sorted(X509V3_EXT_METHOD, (st))\r
+\r
+#define sk_X509_ALGOR_new(st) SKM_sk_new(X509_ALGOR, (st))\r
+#define sk_X509_ALGOR_new_null() SKM_sk_new_null(X509_ALGOR)\r
+#define sk_X509_ALGOR_free(st) SKM_sk_free(X509_ALGOR, (st))\r
+#define sk_X509_ALGOR_num(st) SKM_sk_num(X509_ALGOR, (st))\r
+#define sk_X509_ALGOR_value(st, i) SKM_sk_value(X509_ALGOR, (st), (i))\r
+#define sk_X509_ALGOR_set(st, i, val) SKM_sk_set(X509_ALGOR, (st), (i), (val))\r
+#define sk_X509_ALGOR_zero(st) SKM_sk_zero(X509_ALGOR, (st))\r
+#define sk_X509_ALGOR_push(st, val) SKM_sk_push(X509_ALGOR, (st), (val))\r
+#define sk_X509_ALGOR_unshift(st, val) SKM_sk_unshift(X509_ALGOR, (st), (val))\r
+#define sk_X509_ALGOR_find(st, val) SKM_sk_find(X509_ALGOR, (st), (val))\r
+#define sk_X509_ALGOR_find_ex(st, val) SKM_sk_find_ex(X509_ALGOR, (st), (val))\r
+#define sk_X509_ALGOR_delete(st, i) SKM_sk_delete(X509_ALGOR, (st), (i))\r
+#define sk_X509_ALGOR_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_ALGOR, (st), (ptr))\r
+#define sk_X509_ALGOR_insert(st, val, i) SKM_sk_insert(X509_ALGOR, (st), (val), (i))\r
+#define sk_X509_ALGOR_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_ALGOR, (st), (cmp))\r
+#define sk_X509_ALGOR_dup(st) SKM_sk_dup(X509_ALGOR, st)\r
+#define sk_X509_ALGOR_pop_free(st, free_func) SKM_sk_pop_free(X509_ALGOR, (st), (free_func))\r
+#define sk_X509_ALGOR_shift(st) SKM_sk_shift(X509_ALGOR, (st))\r
+#define sk_X509_ALGOR_pop(st) SKM_sk_pop(X509_ALGOR, (st))\r
+#define sk_X509_ALGOR_sort(st) SKM_sk_sort(X509_ALGOR, (st))\r
+#define sk_X509_ALGOR_is_sorted(st) SKM_sk_is_sorted(X509_ALGOR, (st))\r
+\r
+#define sk_X509_ATTRIBUTE_new(st) SKM_sk_new(X509_ATTRIBUTE, (st))\r
+#define sk_X509_ATTRIBUTE_new_null() SKM_sk_new_null(X509_ATTRIBUTE)\r
+#define sk_X509_ATTRIBUTE_free(st) SKM_sk_free(X509_ATTRIBUTE, (st))\r
+#define sk_X509_ATTRIBUTE_num(st) SKM_sk_num(X509_ATTRIBUTE, (st))\r
+#define sk_X509_ATTRIBUTE_value(st, i) SKM_sk_value(X509_ATTRIBUTE, (st), (i))\r
+#define sk_X509_ATTRIBUTE_set(st, i, val) SKM_sk_set(X509_ATTRIBUTE, (st), (i), (val))\r
+#define sk_X509_ATTRIBUTE_zero(st) SKM_sk_zero(X509_ATTRIBUTE, (st))\r
+#define sk_X509_ATTRIBUTE_push(st, val) SKM_sk_push(X509_ATTRIBUTE, (st), (val))\r
+#define sk_X509_ATTRIBUTE_unshift(st, val) SKM_sk_unshift(X509_ATTRIBUTE, (st), (val))\r
+#define sk_X509_ATTRIBUTE_find(st, val) SKM_sk_find(X509_ATTRIBUTE, (st), (val))\r
+#define sk_X509_ATTRIBUTE_find_ex(st, val) SKM_sk_find_ex(X509_ATTRIBUTE, (st), (val))\r
+#define sk_X509_ATTRIBUTE_delete(st, i) SKM_sk_delete(X509_ATTRIBUTE, (st), (i))\r
+#define sk_X509_ATTRIBUTE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_ATTRIBUTE, (st), (ptr))\r
+#define sk_X509_ATTRIBUTE_insert(st, val, i) SKM_sk_insert(X509_ATTRIBUTE, (st), (val), (i))\r
+#define sk_X509_ATTRIBUTE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_ATTRIBUTE, (st), (cmp))\r
+#define sk_X509_ATTRIBUTE_dup(st) SKM_sk_dup(X509_ATTRIBUTE, st)\r
+#define sk_X509_ATTRIBUTE_pop_free(st, free_func) SKM_sk_pop_free(X509_ATTRIBUTE, (st), (free_func))\r
+#define sk_X509_ATTRIBUTE_shift(st) SKM_sk_shift(X509_ATTRIBUTE, (st))\r
+#define sk_X509_ATTRIBUTE_pop(st) SKM_sk_pop(X509_ATTRIBUTE, (st))\r
+#define sk_X509_ATTRIBUTE_sort(st) SKM_sk_sort(X509_ATTRIBUTE, (st))\r
+#define sk_X509_ATTRIBUTE_is_sorted(st) SKM_sk_is_sorted(X509_ATTRIBUTE, (st))\r
+\r
+#define sk_X509_CRL_new(st) SKM_sk_new(X509_CRL, (st))\r
+#define sk_X509_CRL_new_null() SKM_sk_new_null(X509_CRL)\r
+#define sk_X509_CRL_free(st) SKM_sk_free(X509_CRL, (st))\r
+#define sk_X509_CRL_num(st) SKM_sk_num(X509_CRL, (st))\r
+#define sk_X509_CRL_value(st, i) SKM_sk_value(X509_CRL, (st), (i))\r
+#define sk_X509_CRL_set(st, i, val) SKM_sk_set(X509_CRL, (st), (i), (val))\r
+#define sk_X509_CRL_zero(st) SKM_sk_zero(X509_CRL, (st))\r
+#define sk_X509_CRL_push(st, val) SKM_sk_push(X509_CRL, (st), (val))\r
+#define sk_X509_CRL_unshift(st, val) SKM_sk_unshift(X509_CRL, (st), (val))\r
+#define sk_X509_CRL_find(st, val) SKM_sk_find(X509_CRL, (st), (val))\r
+#define sk_X509_CRL_find_ex(st, val) SKM_sk_find_ex(X509_CRL, (st), (val))\r
+#define sk_X509_CRL_delete(st, i) SKM_sk_delete(X509_CRL, (st), (i))\r
+#define sk_X509_CRL_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_CRL, (st), (ptr))\r
+#define sk_X509_CRL_insert(st, val, i) SKM_sk_insert(X509_CRL, (st), (val), (i))\r
+#define sk_X509_CRL_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_CRL, (st), (cmp))\r
+#define sk_X509_CRL_dup(st) SKM_sk_dup(X509_CRL, st)\r
+#define sk_X509_CRL_pop_free(st, free_func) SKM_sk_pop_free(X509_CRL, (st), (free_func))\r
+#define sk_X509_CRL_shift(st) SKM_sk_shift(X509_CRL, (st))\r
+#define sk_X509_CRL_pop(st) SKM_sk_pop(X509_CRL, (st))\r
+#define sk_X509_CRL_sort(st) SKM_sk_sort(X509_CRL, (st))\r
+#define sk_X509_CRL_is_sorted(st) SKM_sk_is_sorted(X509_CRL, (st))\r
+\r
+#define sk_X509_EXTENSION_new(st) SKM_sk_new(X509_EXTENSION, (st))\r
+#define sk_X509_EXTENSION_new_null() SKM_sk_new_null(X509_EXTENSION)\r
+#define sk_X509_EXTENSION_free(st) SKM_sk_free(X509_EXTENSION, (st))\r
+#define sk_X509_EXTENSION_num(st) SKM_sk_num(X509_EXTENSION, (st))\r
+#define sk_X509_EXTENSION_value(st, i) SKM_sk_value(X509_EXTENSION, (st), (i))\r
+#define sk_X509_EXTENSION_set(st, i, val) SKM_sk_set(X509_EXTENSION, (st), (i), (val))\r
+#define sk_X509_EXTENSION_zero(st) SKM_sk_zero(X509_EXTENSION, (st))\r
+#define sk_X509_EXTENSION_push(st, val) SKM_sk_push(X509_EXTENSION, (st), (val))\r
+#define sk_X509_EXTENSION_unshift(st, val) SKM_sk_unshift(X509_EXTENSION, (st), (val))\r
+#define sk_X509_EXTENSION_find(st, val) SKM_sk_find(X509_EXTENSION, (st), (val))\r
+#define sk_X509_EXTENSION_find_ex(st, val) SKM_sk_find_ex(X509_EXTENSION, (st), (val))\r
+#define sk_X509_EXTENSION_delete(st, i) SKM_sk_delete(X509_EXTENSION, (st), (i))\r
+#define sk_X509_EXTENSION_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_EXTENSION, (st), (ptr))\r
+#define sk_X509_EXTENSION_insert(st, val, i) SKM_sk_insert(X509_EXTENSION, (st), (val), (i))\r
+#define sk_X509_EXTENSION_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_EXTENSION, (st), (cmp))\r
+#define sk_X509_EXTENSION_dup(st) SKM_sk_dup(X509_EXTENSION, st)\r
+#define sk_X509_EXTENSION_pop_free(st, free_func) SKM_sk_pop_free(X509_EXTENSION, (st), (free_func))\r
+#define sk_X509_EXTENSION_shift(st) SKM_sk_shift(X509_EXTENSION, (st))\r
+#define sk_X509_EXTENSION_pop(st) SKM_sk_pop(X509_EXTENSION, (st))\r
+#define sk_X509_EXTENSION_sort(st) SKM_sk_sort(X509_EXTENSION, (st))\r
+#define sk_X509_EXTENSION_is_sorted(st) SKM_sk_is_sorted(X509_EXTENSION, (st))\r
+\r
+#define sk_X509_INFO_new(st) SKM_sk_new(X509_INFO, (st))\r
+#define sk_X509_INFO_new_null() SKM_sk_new_null(X509_INFO)\r
+#define sk_X509_INFO_free(st) SKM_sk_free(X509_INFO, (st))\r
+#define sk_X509_INFO_num(st) SKM_sk_num(X509_INFO, (st))\r
+#define sk_X509_INFO_value(st, i) SKM_sk_value(X509_INFO, (st), (i))\r
+#define sk_X509_INFO_set(st, i, val) SKM_sk_set(X509_INFO, (st), (i), (val))\r
+#define sk_X509_INFO_zero(st) SKM_sk_zero(X509_INFO, (st))\r
+#define sk_X509_INFO_push(st, val) SKM_sk_push(X509_INFO, (st), (val))\r
+#define sk_X509_INFO_unshift(st, val) SKM_sk_unshift(X509_INFO, (st), (val))\r
+#define sk_X509_INFO_find(st, val) SKM_sk_find(X509_INFO, (st), (val))\r
+#define sk_X509_INFO_find_ex(st, val) SKM_sk_find_ex(X509_INFO, (st), (val))\r
+#define sk_X509_INFO_delete(st, i) SKM_sk_delete(X509_INFO, (st), (i))\r
+#define sk_X509_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_INFO, (st), (ptr))\r
+#define sk_X509_INFO_insert(st, val, i) SKM_sk_insert(X509_INFO, (st), (val), (i))\r
+#define sk_X509_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_INFO, (st), (cmp))\r
+#define sk_X509_INFO_dup(st) SKM_sk_dup(X509_INFO, st)\r
+#define sk_X509_INFO_pop_free(st, free_func) SKM_sk_pop_free(X509_INFO, (st), (free_func))\r
+#define sk_X509_INFO_shift(st) SKM_sk_shift(X509_INFO, (st))\r
+#define sk_X509_INFO_pop(st) SKM_sk_pop(X509_INFO, (st))\r
+#define sk_X509_INFO_sort(st) SKM_sk_sort(X509_INFO, (st))\r
+#define sk_X509_INFO_is_sorted(st) SKM_sk_is_sorted(X509_INFO, (st))\r
+\r
+#define sk_X509_LOOKUP_new(st) SKM_sk_new(X509_LOOKUP, (st))\r
+#define sk_X509_LOOKUP_new_null() SKM_sk_new_null(X509_LOOKUP)\r
+#define sk_X509_LOOKUP_free(st) SKM_sk_free(X509_LOOKUP, (st))\r
+#define sk_X509_LOOKUP_num(st) SKM_sk_num(X509_LOOKUP, (st))\r
+#define sk_X509_LOOKUP_value(st, i) SKM_sk_value(X509_LOOKUP, (st), (i))\r
+#define sk_X509_LOOKUP_set(st, i, val) SKM_sk_set(X509_LOOKUP, (st), (i), (val))\r
+#define sk_X509_LOOKUP_zero(st) SKM_sk_zero(X509_LOOKUP, (st))\r
+#define sk_X509_LOOKUP_push(st, val) SKM_sk_push(X509_LOOKUP, (st), (val))\r
+#define sk_X509_LOOKUP_unshift(st, val) SKM_sk_unshift(X509_LOOKUP, (st), (val))\r
+#define sk_X509_LOOKUP_find(st, val) SKM_sk_find(X509_LOOKUP, (st), (val))\r
+#define sk_X509_LOOKUP_find_ex(st, val) SKM_sk_find_ex(X509_LOOKUP, (st), (val))\r
+#define sk_X509_LOOKUP_delete(st, i) SKM_sk_delete(X509_LOOKUP, (st), (i))\r
+#define sk_X509_LOOKUP_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_LOOKUP, (st), (ptr))\r
+#define sk_X509_LOOKUP_insert(st, val, i) SKM_sk_insert(X509_LOOKUP, (st), (val), (i))\r
+#define sk_X509_LOOKUP_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_LOOKUP, (st), (cmp))\r
+#define sk_X509_LOOKUP_dup(st) SKM_sk_dup(X509_LOOKUP, st)\r
+#define sk_X509_LOOKUP_pop_free(st, free_func) SKM_sk_pop_free(X509_LOOKUP, (st), (free_func))\r
+#define sk_X509_LOOKUP_shift(st) SKM_sk_shift(X509_LOOKUP, (st))\r
+#define sk_X509_LOOKUP_pop(st) SKM_sk_pop(X509_LOOKUP, (st))\r
+#define sk_X509_LOOKUP_sort(st) SKM_sk_sort(X509_LOOKUP, (st))\r
+#define sk_X509_LOOKUP_is_sorted(st) SKM_sk_is_sorted(X509_LOOKUP, (st))\r
+\r
+#define sk_X509_NAME_new(st) SKM_sk_new(X509_NAME, (st))\r
+#define sk_X509_NAME_new_null() SKM_sk_new_null(X509_NAME)\r
+#define sk_X509_NAME_free(st) SKM_sk_free(X509_NAME, (st))\r
+#define sk_X509_NAME_num(st) SKM_sk_num(X509_NAME, (st))\r
+#define sk_X509_NAME_value(st, i) SKM_sk_value(X509_NAME, (st), (i))\r
+#define sk_X509_NAME_set(st, i, val) SKM_sk_set(X509_NAME, (st), (i), (val))\r
+#define sk_X509_NAME_zero(st) SKM_sk_zero(X509_NAME, (st))\r
+#define sk_X509_NAME_push(st, val) SKM_sk_push(X509_NAME, (st), (val))\r
+#define sk_X509_NAME_unshift(st, val) SKM_sk_unshift(X509_NAME, (st), (val))\r
+#define sk_X509_NAME_find(st, val) SKM_sk_find(X509_NAME, (st), (val))\r
+#define sk_X509_NAME_find_ex(st, val) SKM_sk_find_ex(X509_NAME, (st), (val))\r
+#define sk_X509_NAME_delete(st, i) SKM_sk_delete(X509_NAME, (st), (i))\r
+#define sk_X509_NAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_NAME, (st), (ptr))\r
+#define sk_X509_NAME_insert(st, val, i) SKM_sk_insert(X509_NAME, (st), (val), (i))\r
+#define sk_X509_NAME_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_NAME, (st), (cmp))\r
+#define sk_X509_NAME_dup(st) SKM_sk_dup(X509_NAME, st)\r
+#define sk_X509_NAME_pop_free(st, free_func) SKM_sk_pop_free(X509_NAME, (st), (free_func))\r
+#define sk_X509_NAME_shift(st) SKM_sk_shift(X509_NAME, (st))\r
+#define sk_X509_NAME_pop(st) SKM_sk_pop(X509_NAME, (st))\r
+#define sk_X509_NAME_sort(st) SKM_sk_sort(X509_NAME, (st))\r
+#define sk_X509_NAME_is_sorted(st) SKM_sk_is_sorted(X509_NAME, (st))\r
+\r
+#define sk_X509_NAME_ENTRY_new(st) SKM_sk_new(X509_NAME_ENTRY, (st))\r
+#define sk_X509_NAME_ENTRY_new_null() SKM_sk_new_null(X509_NAME_ENTRY)\r
+#define sk_X509_NAME_ENTRY_free(st) SKM_sk_free(X509_NAME_ENTRY, (st))\r
+#define sk_X509_NAME_ENTRY_num(st) SKM_sk_num(X509_NAME_ENTRY, (st))\r
+#define sk_X509_NAME_ENTRY_value(st, i) SKM_sk_value(X509_NAME_ENTRY, (st), (i))\r
+#define sk_X509_NAME_ENTRY_set(st, i, val) SKM_sk_set(X509_NAME_ENTRY, (st), (i), (val))\r
+#define sk_X509_NAME_ENTRY_zero(st) SKM_sk_zero(X509_NAME_ENTRY, (st))\r
+#define sk_X509_NAME_ENTRY_push(st, val) SKM_sk_push(X509_NAME_ENTRY, (st), (val))\r
+#define sk_X509_NAME_ENTRY_unshift(st, val) SKM_sk_unshift(X509_NAME_ENTRY, (st), (val))\r
+#define sk_X509_NAME_ENTRY_find(st, val) SKM_sk_find(X509_NAME_ENTRY, (st), (val))\r
+#define sk_X509_NAME_ENTRY_find_ex(st, val) SKM_sk_find_ex(X509_NAME_ENTRY, (st), (val))\r
+#define sk_X509_NAME_ENTRY_delete(st, i) SKM_sk_delete(X509_NAME_ENTRY, (st), (i))\r
+#define sk_X509_NAME_ENTRY_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_NAME_ENTRY, (st), (ptr))\r
+#define sk_X509_NAME_ENTRY_insert(st, val, i) SKM_sk_insert(X509_NAME_ENTRY, (st), (val), (i))\r
+#define sk_X509_NAME_ENTRY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_NAME_ENTRY, (st), (cmp))\r
+#define sk_X509_NAME_ENTRY_dup(st) SKM_sk_dup(X509_NAME_ENTRY, st)\r
+#define sk_X509_NAME_ENTRY_pop_free(st, free_func) SKM_sk_pop_free(X509_NAME_ENTRY, (st), (free_func))\r
+#define sk_X509_NAME_ENTRY_shift(st) SKM_sk_shift(X509_NAME_ENTRY, (st))\r
+#define sk_X509_NAME_ENTRY_pop(st) SKM_sk_pop(X509_NAME_ENTRY, (st))\r
+#define sk_X509_NAME_ENTRY_sort(st) SKM_sk_sort(X509_NAME_ENTRY, (st))\r
+#define sk_X509_NAME_ENTRY_is_sorted(st) SKM_sk_is_sorted(X509_NAME_ENTRY, (st))\r
+\r
+#define sk_X509_OBJECT_new(st) SKM_sk_new(X509_OBJECT, (st))\r
+#define sk_X509_OBJECT_new_null() SKM_sk_new_null(X509_OBJECT)\r
+#define sk_X509_OBJECT_free(st) SKM_sk_free(X509_OBJECT, (st))\r
+#define sk_X509_OBJECT_num(st) SKM_sk_num(X509_OBJECT, (st))\r
+#define sk_X509_OBJECT_value(st, i) SKM_sk_value(X509_OBJECT, (st), (i))\r
+#define sk_X509_OBJECT_set(st, i, val) SKM_sk_set(X509_OBJECT, (st), (i), (val))\r
+#define sk_X509_OBJECT_zero(st) SKM_sk_zero(X509_OBJECT, (st))\r
+#define sk_X509_OBJECT_push(st, val) SKM_sk_push(X509_OBJECT, (st), (val))\r
+#define sk_X509_OBJECT_unshift(st, val) SKM_sk_unshift(X509_OBJECT, (st), (val))\r
+#define sk_X509_OBJECT_find(st, val) SKM_sk_find(X509_OBJECT, (st), (val))\r
+#define sk_X509_OBJECT_find_ex(st, val) SKM_sk_find_ex(X509_OBJECT, (st), (val))\r
+#define sk_X509_OBJECT_delete(st, i) SKM_sk_delete(X509_OBJECT, (st), (i))\r
+#define sk_X509_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_OBJECT, (st), (ptr))\r
+#define sk_X509_OBJECT_insert(st, val, i) SKM_sk_insert(X509_OBJECT, (st), (val), (i))\r
+#define sk_X509_OBJECT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_OBJECT, (st), (cmp))\r
+#define sk_X509_OBJECT_dup(st) SKM_sk_dup(X509_OBJECT, st)\r
+#define sk_X509_OBJECT_pop_free(st, free_func) SKM_sk_pop_free(X509_OBJECT, (st), (free_func))\r
+#define sk_X509_OBJECT_shift(st) SKM_sk_shift(X509_OBJECT, (st))\r
+#define sk_X509_OBJECT_pop(st) SKM_sk_pop(X509_OBJECT, (st))\r
+#define sk_X509_OBJECT_sort(st) SKM_sk_sort(X509_OBJECT, (st))\r
+#define sk_X509_OBJECT_is_sorted(st) SKM_sk_is_sorted(X509_OBJECT, (st))\r
+\r
+#define sk_X509_POLICY_DATA_new(st) SKM_sk_new(X509_POLICY_DATA, (st))\r
+#define sk_X509_POLICY_DATA_new_null() SKM_sk_new_null(X509_POLICY_DATA)\r
+#define sk_X509_POLICY_DATA_free(st) SKM_sk_free(X509_POLICY_DATA, (st))\r
+#define sk_X509_POLICY_DATA_num(st) SKM_sk_num(X509_POLICY_DATA, (st))\r
+#define sk_X509_POLICY_DATA_value(st, i) SKM_sk_value(X509_POLICY_DATA, (st), (i))\r
+#define sk_X509_POLICY_DATA_set(st, i, val) SKM_sk_set(X509_POLICY_DATA, (st), (i), (val))\r
+#define sk_X509_POLICY_DATA_zero(st) SKM_sk_zero(X509_POLICY_DATA, (st))\r
+#define sk_X509_POLICY_DATA_push(st, val) SKM_sk_push(X509_POLICY_DATA, (st), (val))\r
+#define sk_X509_POLICY_DATA_unshift(st, val) SKM_sk_unshift(X509_POLICY_DATA, (st), (val))\r
+#define sk_X509_POLICY_DATA_find(st, val) SKM_sk_find(X509_POLICY_DATA, (st), (val))\r
+#define sk_X509_POLICY_DATA_find_ex(st, val) SKM_sk_find_ex(X509_POLICY_DATA, (st), (val))\r
+#define sk_X509_POLICY_DATA_delete(st, i) SKM_sk_delete(X509_POLICY_DATA, (st), (i))\r
+#define sk_X509_POLICY_DATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_POLICY_DATA, (st), (ptr))\r
+#define sk_X509_POLICY_DATA_insert(st, val, i) SKM_sk_insert(X509_POLICY_DATA, (st), (val), (i))\r
+#define sk_X509_POLICY_DATA_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_POLICY_DATA, (st), (cmp))\r
+#define sk_X509_POLICY_DATA_dup(st) SKM_sk_dup(X509_POLICY_DATA, st)\r
+#define sk_X509_POLICY_DATA_pop_free(st, free_func) SKM_sk_pop_free(X509_POLICY_DATA, (st), (free_func))\r
+#define sk_X509_POLICY_DATA_shift(st) SKM_sk_shift(X509_POLICY_DATA, (st))\r
+#define sk_X509_POLICY_DATA_pop(st) SKM_sk_pop(X509_POLICY_DATA, (st))\r
+#define sk_X509_POLICY_DATA_sort(st) SKM_sk_sort(X509_POLICY_DATA, (st))\r
+#define sk_X509_POLICY_DATA_is_sorted(st) SKM_sk_is_sorted(X509_POLICY_DATA, (st))\r
+\r
+#define sk_X509_POLICY_NODE_new(st) SKM_sk_new(X509_POLICY_NODE, (st))\r
+#define sk_X509_POLICY_NODE_new_null() SKM_sk_new_null(X509_POLICY_NODE)\r
+#define sk_X509_POLICY_NODE_free(st) SKM_sk_free(X509_POLICY_NODE, (st))\r
+#define sk_X509_POLICY_NODE_num(st) SKM_sk_num(X509_POLICY_NODE, (st))\r
+#define sk_X509_POLICY_NODE_value(st, i) SKM_sk_value(X509_POLICY_NODE, (st), (i))\r
+#define sk_X509_POLICY_NODE_set(st, i, val) SKM_sk_set(X509_POLICY_NODE, (st), (i), (val))\r
+#define sk_X509_POLICY_NODE_zero(st) SKM_sk_zero(X509_POLICY_NODE, (st))\r
+#define sk_X509_POLICY_NODE_push(st, val) SKM_sk_push(X509_POLICY_NODE, (st), (val))\r
+#define sk_X509_POLICY_NODE_unshift(st, val) SKM_sk_unshift(X509_POLICY_NODE, (st), (val))\r
+#define sk_X509_POLICY_NODE_find(st, val) SKM_sk_find(X509_POLICY_NODE, (st), (val))\r
+#define sk_X509_POLICY_NODE_find_ex(st, val) SKM_sk_find_ex(X509_POLICY_NODE, (st), (val))\r
+#define sk_X509_POLICY_NODE_delete(st, i) SKM_sk_delete(X509_POLICY_NODE, (st), (i))\r
+#define sk_X509_POLICY_NODE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_POLICY_NODE, (st), (ptr))\r
+#define sk_X509_POLICY_NODE_insert(st, val, i) SKM_sk_insert(X509_POLICY_NODE, (st), (val), (i))\r
+#define sk_X509_POLICY_NODE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_POLICY_NODE, (st), (cmp))\r
+#define sk_X509_POLICY_NODE_dup(st) SKM_sk_dup(X509_POLICY_NODE, st)\r
+#define sk_X509_POLICY_NODE_pop_free(st, free_func) SKM_sk_pop_free(X509_POLICY_NODE, (st), (free_func))\r
+#define sk_X509_POLICY_NODE_shift(st) SKM_sk_shift(X509_POLICY_NODE, (st))\r
+#define sk_X509_POLICY_NODE_pop(st) SKM_sk_pop(X509_POLICY_NODE, (st))\r
+#define sk_X509_POLICY_NODE_sort(st) SKM_sk_sort(X509_POLICY_NODE, (st))\r
+#define sk_X509_POLICY_NODE_is_sorted(st) SKM_sk_is_sorted(X509_POLICY_NODE, (st))\r
+\r
+#define sk_X509_POLICY_REF_new(st) SKM_sk_new(X509_POLICY_REF, (st))\r
+#define sk_X509_POLICY_REF_new_null() SKM_sk_new_null(X509_POLICY_REF)\r
+#define sk_X509_POLICY_REF_free(st) SKM_sk_free(X509_POLICY_REF, (st))\r
+#define sk_X509_POLICY_REF_num(st) SKM_sk_num(X509_POLICY_REF, (st))\r
+#define sk_X509_POLICY_REF_value(st, i) SKM_sk_value(X509_POLICY_REF, (st), (i))\r
+#define sk_X509_POLICY_REF_set(st, i, val) SKM_sk_set(X509_POLICY_REF, (st), (i), (val))\r
+#define sk_X509_POLICY_REF_zero(st) SKM_sk_zero(X509_POLICY_REF, (st))\r
+#define sk_X509_POLICY_REF_push(st, val) SKM_sk_push(X509_POLICY_REF, (st), (val))\r
+#define sk_X509_POLICY_REF_unshift(st, val) SKM_sk_unshift(X509_POLICY_REF, (st), (val))\r
+#define sk_X509_POLICY_REF_find(st, val) SKM_sk_find(X509_POLICY_REF, (st), (val))\r
+#define sk_X509_POLICY_REF_find_ex(st, val) SKM_sk_find_ex(X509_POLICY_REF, (st), (val))\r
+#define sk_X509_POLICY_REF_delete(st, i) SKM_sk_delete(X509_POLICY_REF, (st), (i))\r
+#define sk_X509_POLICY_REF_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_POLICY_REF, (st), (ptr))\r
+#define sk_X509_POLICY_REF_insert(st, val, i) SKM_sk_insert(X509_POLICY_REF, (st), (val), (i))\r
+#define sk_X509_POLICY_REF_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_POLICY_REF, (st), (cmp))\r
+#define sk_X509_POLICY_REF_dup(st) SKM_sk_dup(X509_POLICY_REF, st)\r
+#define sk_X509_POLICY_REF_pop_free(st, free_func) SKM_sk_pop_free(X509_POLICY_REF, (st), (free_func))\r
+#define sk_X509_POLICY_REF_shift(st) SKM_sk_shift(X509_POLICY_REF, (st))\r
+#define sk_X509_POLICY_REF_pop(st) SKM_sk_pop(X509_POLICY_REF, (st))\r
+#define sk_X509_POLICY_REF_sort(st) SKM_sk_sort(X509_POLICY_REF, (st))\r
+#define sk_X509_POLICY_REF_is_sorted(st) SKM_sk_is_sorted(X509_POLICY_REF, (st))\r
+\r
+#define sk_X509_PURPOSE_new(st) SKM_sk_new(X509_PURPOSE, (st))\r
+#define sk_X509_PURPOSE_new_null() SKM_sk_new_null(X509_PURPOSE)\r
+#define sk_X509_PURPOSE_free(st) SKM_sk_free(X509_PURPOSE, (st))\r
+#define sk_X509_PURPOSE_num(st) SKM_sk_num(X509_PURPOSE, (st))\r
+#define sk_X509_PURPOSE_value(st, i) SKM_sk_value(X509_PURPOSE, (st), (i))\r
+#define sk_X509_PURPOSE_set(st, i, val) SKM_sk_set(X509_PURPOSE, (st), (i), (val))\r
+#define sk_X509_PURPOSE_zero(st) SKM_sk_zero(X509_PURPOSE, (st))\r
+#define sk_X509_PURPOSE_push(st, val) SKM_sk_push(X509_PURPOSE, (st), (val))\r
+#define sk_X509_PURPOSE_unshift(st, val) SKM_sk_unshift(X509_PURPOSE, (st), (val))\r
+#define sk_X509_PURPOSE_find(st, val) SKM_sk_find(X509_PURPOSE, (st), (val))\r
+#define sk_X509_PURPOSE_find_ex(st, val) SKM_sk_find_ex(X509_PURPOSE, (st), (val))\r
+#define sk_X509_PURPOSE_delete(st, i) SKM_sk_delete(X509_PURPOSE, (st), (i))\r
+#define sk_X509_PURPOSE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_PURPOSE, (st), (ptr))\r
+#define sk_X509_PURPOSE_insert(st, val, i) SKM_sk_insert(X509_PURPOSE, (st), (val), (i))\r
+#define sk_X509_PURPOSE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_PURPOSE, (st), (cmp))\r
+#define sk_X509_PURPOSE_dup(st) SKM_sk_dup(X509_PURPOSE, st)\r
+#define sk_X509_PURPOSE_pop_free(st, free_func) SKM_sk_pop_free(X509_PURPOSE, (st), (free_func))\r
+#define sk_X509_PURPOSE_shift(st) SKM_sk_shift(X509_PURPOSE, (st))\r
+#define sk_X509_PURPOSE_pop(st) SKM_sk_pop(X509_PURPOSE, (st))\r
+#define sk_X509_PURPOSE_sort(st) SKM_sk_sort(X509_PURPOSE, (st))\r
+#define sk_X509_PURPOSE_is_sorted(st) SKM_sk_is_sorted(X509_PURPOSE, (st))\r
+\r
+#define sk_X509_REVOKED_new(st) SKM_sk_new(X509_REVOKED, (st))\r
+#define sk_X509_REVOKED_new_null() SKM_sk_new_null(X509_REVOKED)\r
+#define sk_X509_REVOKED_free(st) SKM_sk_free(X509_REVOKED, (st))\r
+#define sk_X509_REVOKED_num(st) SKM_sk_num(X509_REVOKED, (st))\r
+#define sk_X509_REVOKED_value(st, i) SKM_sk_value(X509_REVOKED, (st), (i))\r
+#define sk_X509_REVOKED_set(st, i, val) SKM_sk_set(X509_REVOKED, (st), (i), (val))\r
+#define sk_X509_REVOKED_zero(st) SKM_sk_zero(X509_REVOKED, (st))\r
+#define sk_X509_REVOKED_push(st, val) SKM_sk_push(X509_REVOKED, (st), (val))\r
+#define sk_X509_REVOKED_unshift(st, val) SKM_sk_unshift(X509_REVOKED, (st), (val))\r
+#define sk_X509_REVOKED_find(st, val) SKM_sk_find(X509_REVOKED, (st), (val))\r
+#define sk_X509_REVOKED_find_ex(st, val) SKM_sk_find_ex(X509_REVOKED, (st), (val))\r
+#define sk_X509_REVOKED_delete(st, i) SKM_sk_delete(X509_REVOKED, (st), (i))\r
+#define sk_X509_REVOKED_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_REVOKED, (st), (ptr))\r
+#define sk_X509_REVOKED_insert(st, val, i) SKM_sk_insert(X509_REVOKED, (st), (val), (i))\r
+#define sk_X509_REVOKED_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_REVOKED, (st), (cmp))\r
+#define sk_X509_REVOKED_dup(st) SKM_sk_dup(X509_REVOKED, st)\r
+#define sk_X509_REVOKED_pop_free(st, free_func) SKM_sk_pop_free(X509_REVOKED, (st), (free_func))\r
+#define sk_X509_REVOKED_shift(st) SKM_sk_shift(X509_REVOKED, (st))\r
+#define sk_X509_REVOKED_pop(st) SKM_sk_pop(X509_REVOKED, (st))\r
+#define sk_X509_REVOKED_sort(st) SKM_sk_sort(X509_REVOKED, (st))\r
+#define sk_X509_REVOKED_is_sorted(st) SKM_sk_is_sorted(X509_REVOKED, (st))\r
+\r
+#define sk_X509_TRUST_new(st) SKM_sk_new(X509_TRUST, (st))\r
+#define sk_X509_TRUST_new_null() SKM_sk_new_null(X509_TRUST)\r
+#define sk_X509_TRUST_free(st) SKM_sk_free(X509_TRUST, (st))\r
+#define sk_X509_TRUST_num(st) SKM_sk_num(X509_TRUST, (st))\r
+#define sk_X509_TRUST_value(st, i) SKM_sk_value(X509_TRUST, (st), (i))\r
+#define sk_X509_TRUST_set(st, i, val) SKM_sk_set(X509_TRUST, (st), (i), (val))\r
+#define sk_X509_TRUST_zero(st) SKM_sk_zero(X509_TRUST, (st))\r
+#define sk_X509_TRUST_push(st, val) SKM_sk_push(X509_TRUST, (st), (val))\r
+#define sk_X509_TRUST_unshift(st, val) SKM_sk_unshift(X509_TRUST, (st), (val))\r
+#define sk_X509_TRUST_find(st, val) SKM_sk_find(X509_TRUST, (st), (val))\r
+#define sk_X509_TRUST_find_ex(st, val) SKM_sk_find_ex(X509_TRUST, (st), (val))\r
+#define sk_X509_TRUST_delete(st, i) SKM_sk_delete(X509_TRUST, (st), (i))\r
+#define sk_X509_TRUST_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_TRUST, (st), (ptr))\r
+#define sk_X509_TRUST_insert(st, val, i) SKM_sk_insert(X509_TRUST, (st), (val), (i))\r
+#define sk_X509_TRUST_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_TRUST, (st), (cmp))\r
+#define sk_X509_TRUST_dup(st) SKM_sk_dup(X509_TRUST, st)\r
+#define sk_X509_TRUST_pop_free(st, free_func) SKM_sk_pop_free(X509_TRUST, (st), (free_func))\r
+#define sk_X509_TRUST_shift(st) SKM_sk_shift(X509_TRUST, (st))\r
+#define sk_X509_TRUST_pop(st) SKM_sk_pop(X509_TRUST, (st))\r
+#define sk_X509_TRUST_sort(st) SKM_sk_sort(X509_TRUST, (st))\r
+#define sk_X509_TRUST_is_sorted(st) SKM_sk_is_sorted(X509_TRUST, (st))\r
+\r
+#define sk_X509_VERIFY_PARAM_new(st) SKM_sk_new(X509_VERIFY_PARAM, (st))\r
+#define sk_X509_VERIFY_PARAM_new_null() SKM_sk_new_null(X509_VERIFY_PARAM)\r
+#define sk_X509_VERIFY_PARAM_free(st) SKM_sk_free(X509_VERIFY_PARAM, (st))\r
+#define sk_X509_VERIFY_PARAM_num(st) SKM_sk_num(X509_VERIFY_PARAM, (st))\r
+#define sk_X509_VERIFY_PARAM_value(st, i) SKM_sk_value(X509_VERIFY_PARAM, (st), (i))\r
+#define sk_X509_VERIFY_PARAM_set(st, i, val) SKM_sk_set(X509_VERIFY_PARAM, (st), (i), (val))\r
+#define sk_X509_VERIFY_PARAM_zero(st) SKM_sk_zero(X509_VERIFY_PARAM, (st))\r
+#define sk_X509_VERIFY_PARAM_push(st, val) SKM_sk_push(X509_VERIFY_PARAM, (st), (val))\r
+#define sk_X509_VERIFY_PARAM_unshift(st, val) SKM_sk_unshift(X509_VERIFY_PARAM, (st), (val))\r
+#define sk_X509_VERIFY_PARAM_find(st, val) SKM_sk_find(X509_VERIFY_PARAM, (st), (val))\r
+#define sk_X509_VERIFY_PARAM_find_ex(st, val) SKM_sk_find_ex(X509_VERIFY_PARAM, (st), (val))\r
+#define sk_X509_VERIFY_PARAM_delete(st, i) SKM_sk_delete(X509_VERIFY_PARAM, (st), (i))\r
+#define sk_X509_VERIFY_PARAM_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_VERIFY_PARAM, (st), (ptr))\r
+#define sk_X509_VERIFY_PARAM_insert(st, val, i) SKM_sk_insert(X509_VERIFY_PARAM, (st), (val), (i))\r
+#define sk_X509_VERIFY_PARAM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_VERIFY_PARAM, (st), (cmp))\r
+#define sk_X509_VERIFY_PARAM_dup(st) SKM_sk_dup(X509_VERIFY_PARAM, st)\r
+#define sk_X509_VERIFY_PARAM_pop_free(st, free_func) SKM_sk_pop_free(X509_VERIFY_PARAM, (st), (free_func))\r
+#define sk_X509_VERIFY_PARAM_shift(st) SKM_sk_shift(X509_VERIFY_PARAM, (st))\r
+#define sk_X509_VERIFY_PARAM_pop(st) SKM_sk_pop(X509_VERIFY_PARAM, (st))\r
+#define sk_X509_VERIFY_PARAM_sort(st) SKM_sk_sort(X509_VERIFY_PARAM, (st))\r
+#define sk_X509_VERIFY_PARAM_is_sorted(st) SKM_sk_is_sorted(X509_VERIFY_PARAM, (st))\r
+\r
+#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(ACCESS_DESCRIPTION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(ACCESS_DESCRIPTION, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_ACCESS_DESCRIPTION(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(ACCESS_DESCRIPTION, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_ACCESS_DESCRIPTION(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(ACCESS_DESCRIPTION, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_ASN1_INTEGER(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(ASN1_INTEGER, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_ASN1_INTEGER(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(ASN1_INTEGER, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_ASN1_INTEGER(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(ASN1_INTEGER, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_ASN1_INTEGER(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(ASN1_INTEGER, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_ASN1_OBJECT(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(ASN1_OBJECT, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_ASN1_OBJECT(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(ASN1_OBJECT, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_ASN1_OBJECT(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(ASN1_OBJECT, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_ASN1_OBJECT(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(ASN1_OBJECT, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_ASN1_TYPE(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(ASN1_TYPE, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_ASN1_TYPE(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(ASN1_TYPE, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_ASN1_TYPE(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(ASN1_TYPE, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_ASN1_TYPE(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(ASN1_TYPE, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_DIST_POINT(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(DIST_POINT, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_DIST_POINT(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(DIST_POINT, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_DIST_POINT(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(DIST_POINT, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_DIST_POINT(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(DIST_POINT, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_GENERAL_NAME(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(GENERAL_NAME, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_GENERAL_NAME(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(GENERAL_NAME, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_GENERAL_NAME(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(GENERAL_NAME, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_GENERAL_NAME(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(GENERAL_NAME, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_OCSP_ONEREQ(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(OCSP_ONEREQ, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_OCSP_ONEREQ(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(OCSP_ONEREQ, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_OCSP_ONEREQ(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(OCSP_ONEREQ, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_OCSP_ONEREQ(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(OCSP_ONEREQ, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_OCSP_SINGLERESP(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(OCSP_SINGLERESP, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_OCSP_SINGLERESP(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(OCSP_SINGLERESP, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_OCSP_SINGLERESP(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(OCSP_SINGLERESP, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_OCSP_SINGLERESP(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(OCSP_SINGLERESP, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_PKCS12_SAFEBAG(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(PKCS12_SAFEBAG, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_PKCS12_SAFEBAG(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(PKCS12_SAFEBAG, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_PKCS12_SAFEBAG(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(PKCS12_SAFEBAG, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_PKCS12_SAFEBAG(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(PKCS12_SAFEBAG, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_PKCS7(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(PKCS7, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_PKCS7(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(PKCS7, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_PKCS7(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(PKCS7, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_PKCS7(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(PKCS7, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_PKCS7_RECIP_INFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(PKCS7_RECIP_INFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_PKCS7_RECIP_INFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(PKCS7_RECIP_INFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_PKCS7_RECIP_INFO(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(PKCS7_RECIP_INFO, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_PKCS7_RECIP_INFO(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(PKCS7_RECIP_INFO, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(PKCS7_SIGNER_INFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(PKCS7_SIGNER_INFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_PKCS7_SIGNER_INFO(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(PKCS7_SIGNER_INFO, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_PKCS7_SIGNER_INFO(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(PKCS7_SIGNER_INFO, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_POLICYINFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(POLICYINFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_POLICYINFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(POLICYINFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_POLICYINFO(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(POLICYINFO, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_POLICYINFO(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(POLICYINFO, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_POLICYQUALINFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(POLICYQUALINFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_POLICYQUALINFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(POLICYQUALINFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_POLICYQUALINFO(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(POLICYQUALINFO, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_POLICYQUALINFO(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(POLICYQUALINFO, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_SXNETID(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(SXNETID, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_SXNETID(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(SXNETID, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_SXNETID(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(SXNETID, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_SXNETID(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(SXNETID, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_X509(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(X509, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_X509(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(X509, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_X509(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(X509, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_X509(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(X509, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_X509_ALGOR(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(X509_ALGOR, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_X509_ALGOR(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(X509_ALGOR, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_X509_ALGOR(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(X509_ALGOR, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_X509_ALGOR(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(X509_ALGOR, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_X509_ATTRIBUTE(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(X509_ATTRIBUTE, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_X509_ATTRIBUTE(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(X509_ATTRIBUTE, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_X509_ATTRIBUTE(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(X509_ATTRIBUTE, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_X509_ATTRIBUTE(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(X509_ATTRIBUTE, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_X509_CRL(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(X509_CRL, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_X509_CRL(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(X509_CRL, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_X509_CRL(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(X509_CRL, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_X509_CRL(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(X509_CRL, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_X509_EXTENSION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(X509_EXTENSION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_X509_EXTENSION(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(X509_EXTENSION, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_X509_EXTENSION(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(X509_EXTENSION, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_X509_EXTENSION(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(X509_EXTENSION, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_X509_NAME_ENTRY(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(X509_NAME_ENTRY, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_X509_NAME_ENTRY(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(X509_NAME_ENTRY, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_X509_NAME_ENTRY(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(X509_NAME_ENTRY, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_X509_NAME_ENTRY(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(X509_NAME_ENTRY, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define d2i_ASN1_SET_OF_X509_REVOKED(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\r
+       SKM_ASN1_SET_OF_d2i(X509_REVOKED, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) \r
+#define i2d_ASN1_SET_OF_X509_REVOKED(st, pp, i2d_func, ex_tag, ex_class, is_set) \\r
+       SKM_ASN1_SET_OF_i2d(X509_REVOKED, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))\r
+#define ASN1_seq_pack_X509_REVOKED(st, i2d_func, buf, len) \\r
+       SKM_ASN1_seq_pack(X509_REVOKED, (st), (i2d_func), (buf), (len))\r
+#define ASN1_seq_unpack_X509_REVOKED(buf, len, d2i_func, free_func) \\r
+       SKM_ASN1_seq_unpack(X509_REVOKED, (buf), (len), (d2i_func), (free_func))\r
+\r
+#define PKCS12_decrypt_d2i_PKCS12_SAFEBAG(algor, d2i_func, free_func, pass, passlen, oct, seq) \\r
+       SKM_PKCS12_decrypt_d2i(PKCS12_SAFEBAG, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))\r
+\r
+#define PKCS12_decrypt_d2i_PKCS7(algor, d2i_func, free_func, pass, passlen, oct, seq) \\r
+       SKM_PKCS12_decrypt_d2i(PKCS7, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))\r
+/* End of util/mkstack.pl block, you may now edit :-) */\r
+\r
+#endif /* !defined HEADER_SAFESTACK_H */\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/sha.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/sha.h
new file mode 100644 (file)
index 0000000..4db4f64
--- /dev/null
@@ -0,0 +1,199 @@
+/* crypto/sha/sha.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_SHA_H\r
+#define HEADER_SHA_H\r
+\r
+#include <openssl/e_os2.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1))\r
+#error SHA is disabled.\r
+#endif\r
+\r
+#if defined(OPENSSL_FIPS)\r
+#define FIPS_SHA_SIZE_T size_t\r
+#endif\r
+\r
+/*\r
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r
+ * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then !\r
+ * ! SHA_LONG_LOG2 has to be defined along.                        !\r
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r
+ */\r
+\r
+#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)\r
+#define SHA_LONG unsigned long\r
+#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)\r
+#define SHA_LONG unsigned long\r
+#define SHA_LONG_LOG2 3\r
+#else\r
+#define SHA_LONG unsigned int\r
+#endif\r
+\r
+#define SHA_LBLOCK     16\r
+#define SHA_CBLOCK     (SHA_LBLOCK*4)  /* SHA treats input data as a\r
+                                        * contiguous array of 32 bit\r
+                                        * wide big-endian values. */\r
+#define SHA_LAST_BLOCK  (SHA_CBLOCK-8)\r
+#define SHA_DIGEST_LENGTH 20\r
+\r
+typedef struct SHAstate_st\r
+       {\r
+       SHA_LONG h0,h1,h2,h3,h4;\r
+       SHA_LONG Nl,Nh;\r
+       SHA_LONG data[SHA_LBLOCK];\r
+       unsigned int num;\r
+       } SHA_CTX;\r
+\r
+#ifndef OPENSSL_NO_SHA0\r
+int SHA_Init(SHA_CTX *c);\r
+int SHA_Update(SHA_CTX *c, const void *data, size_t len);\r
+int SHA_Final(unsigned char *md, SHA_CTX *c);\r
+unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md);\r
+void SHA_Transform(SHA_CTX *c, const unsigned char *data);\r
+#endif\r
+#ifndef OPENSSL_NO_SHA1\r
+int SHA1_Init(SHA_CTX *c);\r
+int SHA1_Update(SHA_CTX *c, const void *data, size_t len);\r
+int SHA1_Final(unsigned char *md, SHA_CTX *c);\r
+unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);\r
+void SHA1_Transform(SHA_CTX *c, const unsigned char *data);\r
+#endif\r
+\r
+#define SHA256_CBLOCK  (SHA_LBLOCK*4)  /* SHA-256 treats input data as a\r
+                                        * contiguous array of 32 bit\r
+                                        * wide big-endian values. */\r
+#define SHA224_DIGEST_LENGTH   28\r
+#define SHA256_DIGEST_LENGTH   32\r
+\r
+typedef struct SHA256state_st\r
+       {\r
+       SHA_LONG h[8];\r
+       SHA_LONG Nl,Nh;\r
+       SHA_LONG data[SHA_LBLOCK];\r
+       unsigned int num,md_len;\r
+       } SHA256_CTX;\r
+\r
+#ifndef OPENSSL_NO_SHA256\r
+int SHA224_Init(SHA256_CTX *c);\r
+int SHA224_Update(SHA256_CTX *c, const void *data, size_t len);\r
+int SHA224_Final(unsigned char *md, SHA256_CTX *c);\r
+unsigned char *SHA224(const unsigned char *d, size_t n,unsigned char *md);\r
+int SHA256_Init(SHA256_CTX *c);\r
+int SHA256_Update(SHA256_CTX *c, const void *data, size_t len);\r
+int SHA256_Final(unsigned char *md, SHA256_CTX *c);\r
+unsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md);\r
+void SHA256_Transform(SHA256_CTX *c, const unsigned char *data);\r
+#endif\r
+\r
+#define SHA384_DIGEST_LENGTH   48\r
+#define SHA512_DIGEST_LENGTH   64\r
+\r
+#ifndef OPENSSL_NO_SHA512\r
+/*\r
+ * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64\r
+ * being exactly 64-bit wide. See Implementation Notes in sha512.c\r
+ * for further details.\r
+ */\r
+#define SHA512_CBLOCK  (SHA_LBLOCK*8)  /* SHA-512 treats input data as a\r
+                                        * contiguous array of 64 bit\r
+                                        * wide big-endian values. */\r
+#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)\r
+#define SHA_LONG64 unsigned __int64\r
+#define U64(C)     C##UI64\r
+#elif defined(__arch64__)\r
+#define SHA_LONG64 unsigned long\r
+#define U64(C)     C##UL\r
+#else\r
+#define SHA_LONG64 unsigned long long\r
+#define U64(C)     C##ULL\r
+#endif\r
+\r
+typedef struct SHA512state_st\r
+       {\r
+       SHA_LONG64 h[8];\r
+       SHA_LONG64 Nl,Nh;\r
+       union {\r
+               SHA_LONG64      d[SHA_LBLOCK];\r
+               unsigned char   p[SHA512_CBLOCK];\r
+       } u;\r
+       unsigned int num,md_len;\r
+       } SHA512_CTX;\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_SHA512\r
+int SHA384_Init(SHA512_CTX *c);\r
+int SHA384_Update(SHA512_CTX *c, const void *data, size_t len);\r
+int SHA384_Final(unsigned char *md, SHA512_CTX *c);\r
+unsigned char *SHA384(const unsigned char *d, size_t n,unsigned char *md);\r
+int SHA512_Init(SHA512_CTX *c);\r
+int SHA512_Update(SHA512_CTX *c, const void *data, size_t len);\r
+int SHA512_Final(unsigned char *md, SHA512_CTX *c);\r
+unsigned char *SHA512(const unsigned char *d, size_t n,unsigned char *md);\r
+void SHA512_Transform(SHA512_CTX *c, const unsigned char *data);\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ssl.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ssl.h
new file mode 100644 (file)
index 0000000..01b4cc5
--- /dev/null
@@ -0,0 +1,1961 @@
+/* ssl/ssl.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+/* ====================================================================\r
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.\r
+ * ECC cipher suite support in OpenSSL originally developed by \r
+ * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.\r
+ */\r
+\r
+#ifndef HEADER_SSL_H \r
+#define HEADER_SSL_H \r
+\r
+#include <openssl/e_os2.h>\r
+\r
+#ifndef OPENSSL_NO_COMP\r
+#include <openssl/comp.h>\r
+#endif\r
+#ifndef OPENSSL_NO_BIO\r
+#include <openssl/bio.h>\r
+#endif\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#ifndef OPENSSL_NO_X509\r
+#include <openssl/x509.h>\r
+#endif\r
+#include <openssl/crypto.h>\r
+#include <openssl/lhash.h>\r
+#include <openssl/buffer.h>\r
+#endif\r
+#include <openssl/pem.h>\r
+\r
+#include <openssl/kssl.h>\r
+#include <openssl/safestack.h>\r
+#include <openssl/symhacks.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* SSLeay version number for ASN.1 encoding of the session information */\r
+/* Version 0 - initial version\r
+ * Version 1 - added the optional peer certificate\r
+ */\r
+#define SSL_SESSION_ASN1_VERSION 0x0001\r
+\r
+/* text strings for the ciphers */\r
+#define SSL_TXT_NULL_WITH_MD5          SSL2_TXT_NULL_WITH_MD5                  \r
+#define SSL_TXT_RC4_128_WITH_MD5       SSL2_TXT_RC4_128_WITH_MD5               \r
+#define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5   \r
+#define SSL_TXT_RC2_128_CBC_WITH_MD5   SSL2_TXT_RC2_128_CBC_WITH_MD5           \r
+#define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5   \r
+#define SSL_TXT_IDEA_128_CBC_WITH_MD5  SSL2_TXT_IDEA_128_CBC_WITH_MD5          \r
+#define SSL_TXT_DES_64_CBC_WITH_MD5    SSL2_TXT_DES_64_CBC_WITH_MD5            \r
+#define SSL_TXT_DES_64_CBC_WITH_SHA    SSL2_TXT_DES_64_CBC_WITH_SHA            \r
+#define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5   \r
+#define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA   \r
+\r
+/*    VRS Additional Kerberos5 entries\r
+ */\r
+#define SSL_TXT_KRB5_DES_64_CBC_SHA   SSL3_TXT_KRB5_DES_64_CBC_SHA\r
+#define SSL_TXT_KRB5_DES_192_CBC3_SHA SSL3_TXT_KRB5_DES_192_CBC3_SHA\r
+#define SSL_TXT_KRB5_RC4_128_SHA      SSL3_TXT_KRB5_RC4_128_SHA\r
+#define SSL_TXT_KRB5_IDEA_128_CBC_SHA SSL3_TXT_KRB5_IDEA_128_CBC_SHA\r
+#define SSL_TXT_KRB5_DES_64_CBC_MD5   SSL3_TXT_KRB5_DES_64_CBC_MD5       \r
+#define SSL_TXT_KRB5_DES_192_CBC3_MD5 SSL3_TXT_KRB5_DES_192_CBC3_MD5       \r
+#define SSL_TXT_KRB5_RC4_128_MD5      SSL3_TXT_KRB5_RC4_128_MD5\r
+#define SSL_TXT_KRB5_IDEA_128_CBC_MD5 SSL3_TXT_KRB5_IDEA_128_CBC_MD5 \r
+\r
+#define SSL_TXT_KRB5_DES_40_CBC_SHA   SSL3_TXT_KRB5_DES_40_CBC_SHA \r
+#define SSL_TXT_KRB5_RC2_40_CBC_SHA   SSL3_TXT_KRB5_RC2_40_CBC_SHA \r
+#define SSL_TXT_KRB5_RC4_40_SHA              SSL3_TXT_KRB5_RC4_40_SHA\r
+#define SSL_TXT_KRB5_DES_40_CBC_MD5   SSL3_TXT_KRB5_DES_40_CBC_MD5 \r
+#define SSL_TXT_KRB5_RC2_40_CBC_MD5   SSL3_TXT_KRB5_RC2_40_CBC_MD5 \r
+#define SSL_TXT_KRB5_RC4_40_MD5              SSL3_TXT_KRB5_RC4_40_MD5\r
+\r
+#define SSL_TXT_KRB5_DES_40_CBC_SHA   SSL3_TXT_KRB5_DES_40_CBC_SHA\r
+#define SSL_TXT_KRB5_DES_40_CBC_MD5   SSL3_TXT_KRB5_DES_40_CBC_MD5\r
+#define SSL_TXT_KRB5_DES_64_CBC_SHA   SSL3_TXT_KRB5_DES_64_CBC_SHA\r
+#define SSL_TXT_KRB5_DES_64_CBC_MD5   SSL3_TXT_KRB5_DES_64_CBC_MD5\r
+#define SSL_TXT_KRB5_DES_192_CBC3_SHA SSL3_TXT_KRB5_DES_192_CBC3_SHA\r
+#define SSL_TXT_KRB5_DES_192_CBC3_MD5 SSL3_TXT_KRB5_DES_192_CBC3_MD5\r
+#define SSL_MAX_KRB5_PRINCIPAL_LENGTH  256\r
+\r
+#define SSL_MAX_SSL_SESSION_ID_LENGTH          32\r
+#define SSL_MAX_SID_CTX_LENGTH                 32\r
+\r
+#define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES    (512/8)\r
+#define SSL_MAX_KEY_ARG_LENGTH                 8\r
+#define SSL_MAX_MASTER_KEY_LENGTH              48\r
+\r
+/* These are used to specify which ciphers to use and not to use */\r
+#define SSL_TXT_LOW            "LOW"\r
+#define SSL_TXT_MEDIUM         "MEDIUM"\r
+#define SSL_TXT_HIGH           "HIGH"\r
+#define SSL_TXT_kFZA           "kFZA"\r
+#define        SSL_TXT_aFZA            "aFZA"\r
+#define SSL_TXT_eFZA           "eFZA"\r
+#define SSL_TXT_FZA            "FZA"\r
+\r
+#define        SSL_TXT_aNULL           "aNULL"\r
+#define        SSL_TXT_eNULL           "eNULL"\r
+#define        SSL_TXT_NULL            "NULL"\r
+\r
+#define SSL_TXT_kKRB5          "kKRB5"\r
+#define SSL_TXT_aKRB5          "aKRB5"\r
+#define SSL_TXT_KRB5           "KRB5"\r
+\r
+#define SSL_TXT_kRSA           "kRSA"\r
+#define SSL_TXT_kDHr           "kDHr"\r
+#define SSL_TXT_kDHd           "kDHd"\r
+#define SSL_TXT_kEDH           "kEDH"\r
+#define        SSL_TXT_aRSA            "aRSA"\r
+#define        SSL_TXT_aDSS            "aDSS"\r
+#define        SSL_TXT_aDH             "aDH"\r
+#define        SSL_TXT_DSS             "DSS"\r
+#define SSL_TXT_DH             "DH"\r
+#define SSL_TXT_EDH            "EDH"\r
+#define SSL_TXT_ADH            "ADH"\r
+#define SSL_TXT_RSA            "RSA"\r
+#define SSL_TXT_DES            "DES"\r
+#define SSL_TXT_3DES           "3DES"\r
+#define SSL_TXT_RC4            "RC4"\r
+#define SSL_TXT_RC2            "RC2"\r
+#define SSL_TXT_IDEA           "IDEA"\r
+#define SSL_TXT_AES            "AES"\r
+#define SSL_TXT_MD5            "MD5"\r
+#define SSL_TXT_SHA1           "SHA1"\r
+#define SSL_TXT_SHA            "SHA"\r
+#define SSL_TXT_EXP            "EXP"\r
+#define SSL_TXT_EXPORT         "EXPORT"\r
+#define SSL_TXT_EXP40          "EXPORT40"\r
+#define SSL_TXT_EXP56          "EXPORT56"\r
+#define SSL_TXT_SSLV2          "SSLv2"\r
+#define SSL_TXT_SSLV3          "SSLv3"\r
+#define SSL_TXT_TLSV1          "TLSv1"\r
+#define SSL_TXT_ALL            "ALL"\r
+#define SSL_TXT_ECC            "ECCdraft" /* ECC ciphersuites are not yet official */\r
+\r
+/*\r
+ * COMPLEMENTOF* definitions. These identifiers are used to (de-select)\r
+ * ciphers normally not being used.\r
+ * Example: "RC4" will activate all ciphers using RC4 including ciphers\r
+ * without authentication, which would normally disabled by DEFAULT (due\r
+ * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT"\r
+ * will make sure that it is also disabled in the specific selection.\r
+ * COMPLEMENTOF* identifiers are portable between version, as adjustments\r
+ * to the default cipher setup will also be included here.\r
+ *\r
+ * COMPLEMENTOFDEFAULT does not experience the same special treatment that\r
+ * DEFAULT gets, as only selection is being done and no sorting as needed\r
+ * for DEFAULT.\r
+ */\r
+#define SSL_TXT_CMPALL         "COMPLEMENTOFALL"\r
+#define SSL_TXT_CMPDEF         "COMPLEMENTOFDEFAULT"\r
+\r
+/* The following cipher list is used by default.\r
+ * It also is substituted when an application-defined cipher list string\r
+ * starts with 'DEFAULT'. */\r
+#define SSL_DEFAULT_CIPHER_LIST        "ALL:!ADH:+RC4:@STRENGTH" /* low priority for RC4 */\r
+\r
+/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */\r
+#define SSL_SENT_SHUTDOWN      1\r
+#define SSL_RECEIVED_SHUTDOWN  2\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#if (defined(OPENSSL_NO_RSA) || defined(OPENSSL_NO_MD5)) && !defined(OPENSSL_NO_SSL2)\r
+#define OPENSSL_NO_SSL2\r
+#endif\r
+\r
+#define SSL_FILETYPE_ASN1      X509_FILETYPE_ASN1\r
+#define SSL_FILETYPE_PEM       X509_FILETYPE_PEM\r
+\r
+/* This is needed to stop compilers complaining about the\r
+ * 'struct ssl_st *' function parameters used to prototype callbacks\r
+ * in SSL_CTX. */\r
+typedef struct ssl_st *ssl_crock_st;\r
+\r
+/* used to hold info on the particular ciphers used */\r
+typedef struct ssl_cipher_st\r
+       {\r
+       int valid;\r
+       const char *name;               /* text name */\r
+       unsigned long id;               /* id, 4 bytes, first is version */\r
+       unsigned long algorithms;       /* what ciphers are used */\r
+       unsigned long algo_strength;    /* strength and export flags */\r
+       unsigned long algorithm2;       /* Extra flags */\r
+       int strength_bits;              /* Number of bits really used */\r
+       int alg_bits;                   /* Number of bits for algorithm */\r
+       unsigned long mask;             /* used for matching */\r
+       unsigned long mask_strength;    /* also used for matching */\r
+       } SSL_CIPHER;\r
+\r
+DECLARE_STACK_OF(SSL_CIPHER)\r
+\r
+typedef struct ssl_st SSL;\r
+typedef struct ssl_ctx_st SSL_CTX;\r
+\r
+/* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */\r
+typedef struct ssl_method_st\r
+       {\r
+       int version;\r
+       int (*ssl_new)(SSL *s);\r
+       void (*ssl_clear)(SSL *s);\r
+       void (*ssl_free)(SSL *s);\r
+       int (*ssl_accept)(SSL *s);\r
+       int (*ssl_connect)(SSL *s);\r
+       int (*ssl_read)(SSL *s,void *buf,int len);\r
+       int (*ssl_peek)(SSL *s,void *buf,int len);\r
+       int (*ssl_write)(SSL *s,const void *buf,int len);\r
+       int (*ssl_shutdown)(SSL *s);\r
+       int (*ssl_renegotiate)(SSL *s);\r
+       int (*ssl_renegotiate_check)(SSL *s);\r
+       long (*ssl_get_message)(SSL *s, int st1, int stn, int mt, long\r
+               max, int *ok);\r
+       int (*ssl_read_bytes)(SSL *s, int type, unsigned char *buf, int len, \r
+               int peek);\r
+       int (*ssl_write_bytes)(SSL *s, int type, const void *buf_, int len);\r
+       int (*ssl_dispatch_alert)(SSL *s);\r
+       long (*ssl_ctrl)(SSL *s,int cmd,long larg,void *parg);\r
+       long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,void *parg);\r
+       SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr);\r
+       int (*put_cipher_by_char)(const SSL_CIPHER *cipher,unsigned char *ptr);\r
+       int (*ssl_pending)(const SSL *s);\r
+       int (*num_ciphers)(void);\r
+       SSL_CIPHER *(*get_cipher)(unsigned ncipher);\r
+       struct ssl_method_st *(*get_ssl_method)(int version);\r
+       long (*get_timeout)(void);\r
+       struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */\r
+       int (*ssl_version)(void);\r
+       long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)(void));\r
+       long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)(void));\r
+       } SSL_METHOD;\r
+\r
+/* Lets make this into an ASN.1 type structure as follows\r
+ * SSL_SESSION_ID ::= SEQUENCE {\r
+ *     version                 INTEGER,        -- structure version number\r
+ *     SSLversion              INTEGER,        -- SSL version number\r
+ *     Cipher                  OCTET_STRING,   -- the 3 byte cipher ID\r
+ *     Session_ID              OCTET_STRING,   -- the Session ID\r
+ *     Master_key              OCTET_STRING,   -- the master key\r
+ *     KRB5_principal          OCTET_STRING    -- optional Kerberos principal\r
+ *     Key_Arg [ 0 ] IMPLICIT  OCTET_STRING,   -- the optional Key argument\r
+ *     Time [ 1 ] EXPLICIT     INTEGER,        -- optional Start Time\r
+ *     Timeout [ 2 ] EXPLICIT  INTEGER,        -- optional Timeout ins seconds\r
+ *     Peer [ 3 ] EXPLICIT     X509,           -- optional Peer Certificate\r
+ *     Session_ID_context [ 4 ] EXPLICIT OCTET_STRING,   -- the Session ID context\r
+ *     Verify_result [ 5 ] EXPLICIT INTEGER    -- X509_V_... code for `Peer'\r
+ *     Compression [6] IMPLICIT ASN1_OBJECT    -- compression OID XXXXX\r
+ *     }\r
+ * Look in ssl/ssl_asn1.c for more details\r
+ * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).\r
+ */\r
+typedef struct ssl_session_st\r
+       {\r
+       int ssl_version;        /* what ssl version session info is\r
+                                * being kept in here? */\r
+\r
+       /* only really used in SSLv2 */\r
+       unsigned int key_arg_length;\r
+       unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH];\r
+       int master_key_length;\r
+       unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];\r
+       /* session_id - valid? */\r
+       unsigned int session_id_length;\r
+       unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];\r
+       /* this is used to determine whether the session is being reused in\r
+        * the appropriate context. It is up to the application to set this,\r
+        * via SSL_new */\r
+       unsigned int sid_ctx_length;\r
+       unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];\r
+\r
+#ifndef OPENSSL_NO_KRB5\r
+        unsigned int krb5_client_princ_len;\r
+        unsigned char krb5_client_princ[SSL_MAX_KRB5_PRINCIPAL_LENGTH];\r
+#endif /* OPENSSL_NO_KRB5 */\r
+\r
+       int not_resumable;\r
+\r
+       /* The cert is the certificate used to establish this connection */\r
+       struct sess_cert_st /* SESS_CERT */ *sess_cert;\r
+\r
+       /* This is the cert for the other end.\r
+        * On clients, it will be the same as sess_cert->peer_key->x509\r
+        * (the latter is not enough as sess_cert is not retained\r
+        * in the external representation of sessions, see ssl_asn1.c). */\r
+       X509 *peer;\r
+       /* when app_verify_callback accepts a session where the peer's certificate\r
+        * is not ok, we must remember the error for session reuse: */\r
+       long verify_result; /* only for servers */\r
+\r
+       int references;\r
+       long timeout;\r
+       long time;\r
+\r
+       int compress_meth;              /* Need to lookup the method */\r
+\r
+       SSL_CIPHER *cipher;\r
+       unsigned long cipher_id;        /* when ASN.1 loaded, this\r
+                                        * needs to be used to load\r
+                                        * the 'cipher' structure */\r
+\r
+       STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */\r
+\r
+       CRYPTO_EX_DATA ex_data; /* application specific data */\r
+\r
+       /* These are used to make removal of session-ids more\r
+        * efficient and to implement a maximum cache size. */\r
+       struct ssl_session_st *prev,*next;\r
+       } SSL_SESSION;\r
+\r
+\r
+#define SSL_OP_MICROSOFT_SESS_ID_BUG                   0x00000001L\r
+#define SSL_OP_NETSCAPE_CHALLENGE_BUG                  0x00000002L\r
+#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG                0x00000008L\r
+#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG             0x00000010L\r
+#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER              0x00000020L\r
+#define SSL_OP_MSIE_SSLV2_RSA_PADDING                  0x00000040L\r
+#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG                        0x00000080L\r
+#define SSL_OP_TLS_D5_BUG                              0x00000100L\r
+#define SSL_OP_TLS_BLOCK_PADDING_BUG                   0x00000200L\r
+\r
+/* Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added\r
+ * in OpenSSL 0.9.6d.  Usually (depending on the application protocol)\r
+ * the workaround is not needed.  Unfortunately some broken SSL/TLS\r
+ * implementations cannot handle it at all, which is why we include\r
+ * it in SSL_OP_ALL. */\r
+#define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS              0x00000800L /* added in 0.9.6e */\r
+\r
+/* SSL_OP_ALL: various bug workarounds that should be rather harmless.\r
+ *             This used to be 0x000FFFFFL before 0.9.7. */\r
+#define SSL_OP_ALL                                     0x00000FFFL\r
+\r
+/* DTLS options */\r
+#define SSL_OP_NO_QUERY_MTU                 0x00001000L\r
+/* Turn on Cookie Exchange (on relevant for servers) */\r
+#define SSL_OP_COOKIE_EXCHANGE              0x00002000L\r
+\r
+/* As server, disallow session resumption on renegotiation */\r
+#define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION  0x00010000L\r
+/* If set, always create a new key when using tmp_ecdh parameters */\r
+#define SSL_OP_SINGLE_ECDH_USE                         0x00080000L\r
+/* If set, always create a new key when using tmp_dh parameters */\r
+#define SSL_OP_SINGLE_DH_USE                           0x00100000L\r
+/* Set to always use the tmp_rsa key when doing RSA operations,\r
+ * even when this violates protocol specs */\r
+#define SSL_OP_EPHEMERAL_RSA                           0x00200000L\r
+/* Set on servers to choose the cipher according to the server's\r
+ * preferences */\r
+#define SSL_OP_CIPHER_SERVER_PREFERENCE                        0x00400000L\r
+/* If set, a server will allow a client to issue a SSLv3.0 version number\r
+ * as latest version supported in the premaster secret, even when TLSv1.0\r
+ * (version 3.1) was announced in the client hello. Normally this is\r
+ * forbidden to prevent version rollback attacks. */\r
+#define SSL_OP_TLS_ROLLBACK_BUG                                0x00800000L\r
+\r
+#define SSL_OP_NO_SSLv2                                        0x01000000L\r
+#define SSL_OP_NO_SSLv3                                        0x02000000L\r
+#define SSL_OP_NO_TLSv1                                        0x04000000L\r
+\r
+/* The next flag deliberately changes the ciphertest, this is a check\r
+ * for the PKCS#1 attack */\r
+#define SSL_OP_PKCS1_CHECK_1                           0x08000000L\r
+#define SSL_OP_PKCS1_CHECK_2                           0x10000000L\r
+#define SSL_OP_NETSCAPE_CA_DN_BUG                      0x20000000L\r
+#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG         0x40000000L\r
+\r
+\r
+/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success\r
+ * when just a single record has been written): */\r
+#define SSL_MODE_ENABLE_PARTIAL_WRITE       0x00000001L\r
+/* Make it possible to retry SSL_write() with changed buffer location\r
+ * (buffer contents must stay the same!); this is not the default to avoid\r
+ * the misconception that non-blocking SSL_write() behaves like\r
+ * non-blocking write(): */\r
+#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L\r
+/* Never bother the application with retries if the transport\r
+ * is blocking: */\r
+#define SSL_MODE_AUTO_RETRY 0x00000004L\r
+/* Don't attempt to automatically build certificate chain */\r
+#define SSL_MODE_NO_AUTO_CHAIN 0x00000008L\r
+\r
+\r
+/* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,\r
+ * they cannot be used to clear bits. */\r
+\r
+#define SSL_CTX_set_options(ctx,op) \\r
+       SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,(op),NULL)\r
+#define SSL_CTX_get_options(ctx) \\r
+       SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,0,NULL)\r
+#define SSL_set_options(ssl,op) \\r
+       SSL_ctrl((ssl),SSL_CTRL_OPTIONS,(op),NULL)\r
+#define SSL_get_options(ssl) \\r
+        SSL_ctrl((ssl),SSL_CTRL_OPTIONS,0,NULL)\r
+\r
+#define SSL_CTX_set_mode(ctx,op) \\r
+       SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL)\r
+#define SSL_CTX_get_mode(ctx) \\r
+       SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL)\r
+#define SSL_set_mode(ssl,op) \\r
+       SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL)\r
+#define SSL_get_mode(ssl) \\r
+        SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL)\r
+#define SSL_set_mtu(ssl, mtu) \\r
+        SSL_ctrl((ssl),SSL_CTRL_SET_MTU,(mtu),NULL)\r
+\r
+\r
+void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg));\r
+void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg));\r
+#define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))\r
+#define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))\r
+\r
+\r
+\r
+#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32)\r
+#define SSL_MAX_CERT_LIST_DEFAULT 1024*30 /* 30k max cert list :-) */\r
+#else\r
+#define SSL_MAX_CERT_LIST_DEFAULT 1024*100 /* 100k max cert list :-) */\r
+#endif\r
+\r
+#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT     (1024*20)\r
+\r
+/* This callback type is used inside SSL_CTX, SSL, and in the functions that set\r
+ * them. It is used to override the generation of SSL/TLS session IDs in a\r
+ * server. Return value should be zero on an error, non-zero to proceed. Also,\r
+ * callbacks should themselves check if the id they generate is unique otherwise\r
+ * the SSL handshake will fail with an error - callbacks can do this using the\r
+ * 'ssl' value they're passed by;\r
+ *      SSL_has_matching_session_id(ssl, id, *id_len)\r
+ * The length value passed in is set at the maximum size the session ID can be.\r
+ * In SSLv2 this is 16 bytes, whereas SSLv3/TLSv1 it is 32 bytes. The callback\r
+ * can alter this length to be less if desired, but under SSLv2 session IDs are\r
+ * supposed to be fixed at 16 bytes so the id will be padded after the callback\r
+ * returns in this case. It is also an error for the callback to set the size to\r
+ * zero. */\r
+typedef int (*GEN_SESSION_CB)(const SSL *ssl, unsigned char *id,\r
+                               unsigned int *id_len);\r
+\r
+typedef struct ssl_comp_st\r
+       {\r
+       int id;\r
+       const char *name;\r
+#ifndef OPENSSL_NO_COMP\r
+       COMP_METHOD *method;\r
+#else\r
+       char *method;\r
+#endif\r
+       } SSL_COMP;\r
+\r
+DECLARE_STACK_OF(SSL_COMP)\r
+\r
+struct ssl_ctx_st\r
+       {\r
+       SSL_METHOD *method;\r
+\r
+       STACK_OF(SSL_CIPHER) *cipher_list;\r
+       /* same as above but sorted for lookup */\r
+       STACK_OF(SSL_CIPHER) *cipher_list_by_id;\r
+\r
+       struct x509_store_st /* X509_STORE */ *cert_store;\r
+       struct lhash_st /* LHASH */ *sessions;  /* a set of SSL_SESSIONs */\r
+       /* Most session-ids that will be cached, default is\r
+        * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */\r
+       unsigned long session_cache_size;\r
+       struct ssl_session_st *session_cache_head;\r
+       struct ssl_session_st *session_cache_tail;\r
+\r
+       /* This can have one of 2 values, ored together,\r
+        * SSL_SESS_CACHE_CLIENT,\r
+        * SSL_SESS_CACHE_SERVER,\r
+        * Default is SSL_SESSION_CACHE_SERVER, which means only\r
+        * SSL_accept which cache SSL_SESSIONS. */\r
+       int session_cache_mode;\r
+\r
+       /* If timeout is not 0, it is the default timeout value set\r
+        * when SSL_new() is called.  This has been put in to make\r
+        * life easier to set things up */\r
+       long session_timeout;\r
+\r
+       /* If this callback is not null, it will be called each\r
+        * time a session id is added to the cache.  If this function\r
+        * returns 1, it means that the callback will do a\r
+        * SSL_SESSION_free() when it has finished using it.  Otherwise,\r
+        * on 0, it means the callback has finished with it.\r
+        * If remove_session_cb is not null, it will be called when\r
+        * a session-id is removed from the cache.  After the call,\r
+        * OpenSSL will SSL_SESSION_free() it. */\r
+       int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess);\r
+       void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess);\r
+       SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,\r
+               unsigned char *data,int len,int *copy);\r
+\r
+       struct\r
+               {\r
+               int sess_connect;       /* SSL new conn - started */\r
+               int sess_connect_renegotiate;/* SSL reneg - requested */\r
+               int sess_connect_good;  /* SSL new conne/reneg - finished */\r
+               int sess_accept;        /* SSL new accept - started */\r
+               int sess_accept_renegotiate;/* SSL reneg - requested */\r
+               int sess_accept_good;   /* SSL accept/reneg - finished */\r
+               int sess_miss;          /* session lookup misses  */\r
+               int sess_timeout;       /* reuse attempt on timeouted session */\r
+               int sess_cache_full;    /* session removed due to full cache */\r
+               int sess_hit;           /* session reuse actually done */\r
+               int sess_cb_hit;        /* session-id that was not\r
+                                        * in the cache was\r
+                                        * passed back via the callback.  This\r
+                                        * indicates that the application is\r
+                                        * supplying session-id's from other\r
+                                        * processes - spooky :-) */\r
+               } stats;\r
+\r
+       int references;\r
+\r
+       /* if defined, these override the X509_verify_cert() calls */\r
+       int (*app_verify_callback)(X509_STORE_CTX *, void *);\r
+       void *app_verify_arg;\r
+       /* before OpenSSL 0.9.7, 'app_verify_arg' was ignored\r
+        * ('app_verify_callback' was called with just one argument) */\r
+\r
+       /* Default password callback. */\r
+       pem_password_cb *default_passwd_callback;\r
+\r
+       /* Default password callback user data. */\r
+       void *default_passwd_callback_userdata;\r
+\r
+       /* get client cert callback */\r
+       int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey);\r
+\r
+    /* cookie generate callback */\r
+    int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie, \r
+        unsigned int *cookie_len);\r
+\r
+    /* verify cookie callback */\r
+    int (*app_verify_cookie_cb)(SSL *ssl, unsigned char *cookie, \r
+        unsigned int cookie_len);\r
+\r
+       CRYPTO_EX_DATA ex_data;\r
+\r
+       const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */\r
+       const EVP_MD *md5;      /* For SSLv3/TLSv1 'ssl3-md5' */\r
+       const EVP_MD *sha1;   /* For SSLv3/TLSv1 'ssl3->sha1' */\r
+\r
+       STACK_OF(X509) *extra_certs;\r
+       STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */\r
+\r
+\r
+       /* Default values used when no per-SSL value is defined follow */\r
+\r
+       void (*info_callback)(const SSL *ssl,int type,int val); /* used if SSL's info_callback is NULL */\r
+\r
+       /* what we put in client cert requests */\r
+       STACK_OF(X509_NAME) *client_CA;\r
+\r
+\r
+       /* Default values to use in SSL structures follow (these are copied by SSL_new) */\r
+\r
+       unsigned long options;\r
+       unsigned long mode;\r
+       long max_cert_list;\r
+\r
+       struct cert_st /* CERT */ *cert;\r
+       int read_ahead;\r
+\r
+       /* callback that allows applications to peek at protocol messages */\r
+       void (*msg_callback)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg);\r
+       void *msg_callback_arg;\r
+\r
+       int verify_mode;\r
+       unsigned int sid_ctx_length;\r
+       unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];\r
+       int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */\r
+\r
+       /* Default generate session ID callback. */\r
+       GEN_SESSION_CB generate_session_id;\r
+\r
+       X509_VERIFY_PARAM *param;\r
+\r
+#if 0\r
+       int purpose;            /* Purpose setting */\r
+       int trust;              /* Trust setting */\r
+#endif\r
+\r
+       int quiet_shutdown;\r
+       };\r
+\r
+#define SSL_SESS_CACHE_OFF                     0x0000\r
+#define SSL_SESS_CACHE_CLIENT                  0x0001\r
+#define SSL_SESS_CACHE_SERVER                  0x0002\r
+#define SSL_SESS_CACHE_BOTH    (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)\r
+#define SSL_SESS_CACHE_NO_AUTO_CLEAR           0x0080\r
+/* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */\r
+#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP      0x0100\r
+#define SSL_SESS_CACHE_NO_INTERNAL_STORE       0x0200\r
+#define SSL_SESS_CACHE_NO_INTERNAL \\r
+       (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE)\r
+\r
+  struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx);\r
+#define SSL_CTX_sess_number(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)\r
+#define SSL_CTX_sess_connect(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)\r
+#define SSL_CTX_sess_connect_good(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)\r
+#define SSL_CTX_sess_connect_renegotiate(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)\r
+#define SSL_CTX_sess_accept(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)\r
+#define SSL_CTX_sess_accept_renegotiate(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)\r
+#define SSL_CTX_sess_accept_good(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)\r
+#define SSL_CTX_sess_hits(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)\r
+#define SSL_CTX_sess_cb_hits(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)\r
+#define SSL_CTX_sess_misses(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)\r
+#define SSL_CTX_sess_timeouts(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)\r
+#define SSL_CTX_sess_cache_full(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)\r
+\r
+#define SSL_CTX_sess_set_new_cb(ctx,cb)        ((ctx)->new_session_cb=(cb))\r
+#define SSL_CTX_sess_get_new_cb(ctx)   ((ctx)->new_session_cb)\r
+#define SSL_CTX_sess_set_remove_cb(ctx,cb)     ((ctx)->remove_session_cb=(cb))\r
+#define SSL_CTX_sess_get_remove_cb(ctx)        ((ctx)->remove_session_cb)\r
+#define SSL_CTX_sess_set_get_cb(ctx,cb)        ((ctx)->get_session_cb=(cb))\r
+#define SSL_CTX_sess_get_get_cb(ctx)   ((ctx)->get_session_cb)\r
+#define SSL_CTX_set_info_callback(ctx,cb)      ((ctx)->info_callback=(cb))\r
+#define SSL_CTX_get_info_callback(ctx)         ((ctx)->info_callback)\r
+#define SSL_CTX_set_client_cert_cb(ctx,cb)     ((ctx)->client_cert_cb=(cb))\r
+#define SSL_CTX_get_client_cert_cb(ctx)                ((ctx)->client_cert_cb)\r
+#define SSL_CTX_set_cookie_generate_cb(ctx,cb) ((ctx)->app_gen_cookie_cb=(cb))\r
+#define SSL_CTX_set_cookie_verify_cb(ctx,cb) ((ctx)->app_verify_cookie_cb=(cb))\r
+\r
+#define SSL_NOTHING    1\r
+#define SSL_WRITING    2\r
+#define SSL_READING    3\r
+#define SSL_X509_LOOKUP        4\r
+\r
+/* These will only be used when doing non-blocking IO */\r
+#define SSL_want_nothing(s)    (SSL_want(s) == SSL_NOTHING)\r
+#define SSL_want_read(s)       (SSL_want(s) == SSL_READING)\r
+#define SSL_want_write(s)      (SSL_want(s) == SSL_WRITING)\r
+#define SSL_want_x509_lookup(s)        (SSL_want(s) == SSL_X509_LOOKUP)\r
+\r
+struct ssl_st\r
+       {\r
+       /* protocol version\r
+        * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION, DTLS1_VERSION)\r
+        */\r
+       int version;\r
+       int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */\r
+\r
+       SSL_METHOD *method; /* SSLv3 */\r
+\r
+       /* There are 2 BIO's even though they are normally both the\r
+        * same.  This is so data can be read and written to different\r
+        * handlers */\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+       BIO *rbio; /* used by SSL_read */\r
+       BIO *wbio; /* used by SSL_write */\r
+       BIO *bbio; /* used during session-id reuse to concatenate\r
+                   * messages */\r
+#else\r
+       char *rbio; /* used by SSL_read */\r
+       char *wbio; /* used by SSL_write */\r
+       char *bbio;\r
+#endif\r
+       /* This holds a variable that indicates what we were doing\r
+        * when a 0 or -1 is returned.  This is needed for\r
+        * non-blocking IO so we know what request needs re-doing when\r
+        * in SSL_accept or SSL_connect */\r
+       int rwstate;\r
+\r
+       /* true when we are actually in SSL_accept() or SSL_connect() */\r
+       int in_handshake;\r
+       int (*handshake_func)(SSL *);\r
+\r
+       /* Imagine that here's a boolean member "init" that is\r
+        * switched as soon as SSL_set_{accept/connect}_state\r
+        * is called for the first time, so that "state" and\r
+        * "handshake_func" are properly initialized.  But as\r
+        * handshake_func is == 0 until then, we use this\r
+        * test instead of an "init" member.\r
+        */\r
+\r
+       int server;     /* are we the server side? - mostly used by SSL_clear*/\r
+\r
+       int new_session;/* 1 if we are to use a new session.\r
+                        * 2 if we are a server and are inside a handshake\r
+                        *   (i.e. not just sending a HelloRequest)\r
+                        * NB: For servers, the 'new' session may actually be a previously\r
+                        * cached session or even the previous session unless\r
+                        * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */\r
+       int quiet_shutdown;/* don't send shutdown packets */\r
+       int shutdown;   /* we have shut things down, 0x01 sent, 0x02\r
+                        * for received */\r
+       int state;      /* where we are */\r
+       int rstate;     /* where we are when reading */\r
+\r
+       BUF_MEM *init_buf;      /* buffer used during init */\r
+       void *init_msg;         /* pointer to handshake message body, set by ssl3_get_message() */\r
+       int init_num;           /* amount read/written */\r
+       int init_off;           /* amount read/written */\r
+\r
+       /* used internally to point at a raw packet */\r
+       unsigned char *packet;\r
+       unsigned int packet_length;\r
+\r
+       struct ssl2_state_st *s2; /* SSLv2 variables */\r
+       struct ssl3_state_st *s3; /* SSLv3 variables */\r
+       struct dtls1_state_st *d1; /* DTLSv1 variables */\r
+\r
+       int read_ahead;         /* Read as many input bytes as possible\r
+                                * (for non-blocking reads) */\r
+\r
+       /* callback that allows applications to peek at protocol messages */\r
+       void (*msg_callback)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg);\r
+       void *msg_callback_arg;\r
+\r
+       int hit;                /* reusing a previous session */\r
+\r
+       X509_VERIFY_PARAM *param;\r
+\r
+#if 0\r
+       int purpose;            /* Purpose setting */\r
+       int trust;              /* Trust setting */\r
+#endif\r
+\r
+       /* crypto */\r
+       STACK_OF(SSL_CIPHER) *cipher_list;\r
+       STACK_OF(SSL_CIPHER) *cipher_list_by_id;\r
+\r
+       /* These are the ones being used, the ones in SSL_SESSION are\r
+        * the ones to be 'copied' into these ones */\r
+\r
+       EVP_CIPHER_CTX *enc_read_ctx;           /* cryptographic state */\r
+       const EVP_MD *read_hash;                /* used for mac generation */\r
+#ifndef OPENSSL_NO_COMP\r
+       COMP_CTX *expand;                       /* uncompress */\r
+#else\r
+       char *expand;\r
+#endif\r
+\r
+       EVP_CIPHER_CTX *enc_write_ctx;          /* cryptographic state */\r
+       const EVP_MD *write_hash;               /* used for mac generation */\r
+#ifndef OPENSSL_NO_COMP\r
+       COMP_CTX *compress;                     /* compression */\r
+#else\r
+       char *compress; \r
+#endif\r
+\r
+       /* session info */\r
+\r
+       /* client cert? */\r
+       /* This is used to hold the server certificate used */\r
+       struct cert_st /* CERT */ *cert;\r
+\r
+       /* the session_id_context is used to ensure sessions are only reused\r
+        * in the appropriate context */\r
+       unsigned int sid_ctx_length;\r
+       unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];\r
+\r
+       /* This can also be in the session once a session is established */\r
+       SSL_SESSION *session;\r
+\r
+       /* Default generate session ID callback. */\r
+       GEN_SESSION_CB generate_session_id;\r
+\r
+       /* Used in SSL2 and SSL3 */\r
+       int verify_mode;        /* 0 don't care about verify failure.\r
+                                * 1 fail if verify fails */\r
+       int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */\r
+\r
+       void (*info_callback)(const SSL *ssl,int type,int val); /* optional informational callback */\r
+\r
+       int error;              /* error bytes to be written */\r
+       int error_code;         /* actual code */\r
+\r
+#ifndef OPENSSL_NO_KRB5\r
+       KSSL_CTX *kssl_ctx;     /* Kerberos 5 context */\r
+#endif /* OPENSSL_NO_KRB5 */\r
+\r
+       SSL_CTX *ctx;\r
+       /* set this flag to 1 and a sleep(1) is put into all SSL_read()\r
+        * and SSL_write() calls, good for nbio debuging :-) */\r
+       int debug;      \r
+\r
+       /* extra application data */\r
+       long verify_result;\r
+       CRYPTO_EX_DATA ex_data;\r
+\r
+       /* for server side, keep the list of CA_dn we can use */\r
+       STACK_OF(X509_NAME) *client_CA;\r
+\r
+       int references;\r
+       unsigned long options; /* protocol behaviour */\r
+       unsigned long mode; /* API behaviour */\r
+       long max_cert_list;\r
+       int first_packet;\r
+       int client_version;     /* what was passed, used for\r
+                                * SSLv3/TLS rollback check */\r
+       };\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#include <openssl/ssl2.h>\r
+#include <openssl/ssl3.h>\r
+#include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */\r
+#include <openssl/dtls1.h> /* Datagram TLS */\r
+#include <openssl/ssl23.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* compatibility */\r
+#define SSL_set_app_data(s,arg)                (SSL_set_ex_data(s,0,(char *)arg))\r
+#define SSL_get_app_data(s)            (SSL_get_ex_data(s,0))\r
+#define SSL_SESSION_set_app_data(s,a)  (SSL_SESSION_set_ex_data(s,0,(char *)a))\r
+#define SSL_SESSION_get_app_data(s)    (SSL_SESSION_get_ex_data(s,0))\r
+#define SSL_CTX_get_app_data(ctx)      (SSL_CTX_get_ex_data(ctx,0))\r
+#define SSL_CTX_set_app_data(ctx,arg)  (SSL_CTX_set_ex_data(ctx,0,(char *)arg))\r
+\r
+/* The following are the possible values for ssl->state are are\r
+ * used to indicate where we are up to in the SSL connection establishment.\r
+ * The macros that follow are about the only things you should need to use\r
+ * and even then, only when using non-blocking IO.\r
+ * It can also be useful to work out where you were when the connection\r
+ * failed */\r
+\r
+#define SSL_ST_CONNECT                 0x1000\r
+#define SSL_ST_ACCEPT                  0x2000\r
+#define SSL_ST_MASK                    0x0FFF\r
+#define SSL_ST_INIT                    (SSL_ST_CONNECT|SSL_ST_ACCEPT)\r
+#define SSL_ST_BEFORE                  0x4000\r
+#define SSL_ST_OK                      0x03\r
+#define SSL_ST_RENEGOTIATE             (0x04|SSL_ST_INIT)\r
+\r
+#define SSL_CB_LOOP                    0x01\r
+#define SSL_CB_EXIT                    0x02\r
+#define SSL_CB_READ                    0x04\r
+#define SSL_CB_WRITE                   0x08\r
+#define SSL_CB_ALERT                   0x4000 /* used in callback */\r
+#define SSL_CB_READ_ALERT              (SSL_CB_ALERT|SSL_CB_READ)\r
+#define SSL_CB_WRITE_ALERT             (SSL_CB_ALERT|SSL_CB_WRITE)\r
+#define SSL_CB_ACCEPT_LOOP             (SSL_ST_ACCEPT|SSL_CB_LOOP)\r
+#define SSL_CB_ACCEPT_EXIT             (SSL_ST_ACCEPT|SSL_CB_EXIT)\r
+#define SSL_CB_CONNECT_LOOP            (SSL_ST_CONNECT|SSL_CB_LOOP)\r
+#define SSL_CB_CONNECT_EXIT            (SSL_ST_CONNECT|SSL_CB_EXIT)\r
+#define SSL_CB_HANDSHAKE_START         0x10\r
+#define SSL_CB_HANDSHAKE_DONE          0x20\r
+\r
+/* Is the SSL_connection established? */\r
+#define SSL_get_state(a)               SSL_state(a)\r
+#define SSL_is_init_finished(a)                (SSL_state(a) == SSL_ST_OK)\r
+#define SSL_in_init(a)                 (SSL_state(a)&SSL_ST_INIT)\r
+#define SSL_in_before(a)               (SSL_state(a)&SSL_ST_BEFORE)\r
+#define SSL_in_connect_init(a)         (SSL_state(a)&SSL_ST_CONNECT)\r
+#define SSL_in_accept_init(a)          (SSL_state(a)&SSL_ST_ACCEPT)\r
+\r
+/* The following 2 states are kept in ssl->rstate when reads fail,\r
+ * you should not need these */\r
+#define SSL_ST_READ_HEADER                     0xF0\r
+#define SSL_ST_READ_BODY                       0xF1\r
+#define SSL_ST_READ_DONE                       0xF2\r
+\r
+/* Obtain latest Finished message\r
+ *   -- that we sent (SSL_get_finished)\r
+ *   -- that we expected from peer (SSL_get_peer_finished).\r
+ * Returns length (0 == no Finished so far), copies up to 'count' bytes. */\r
+size_t SSL_get_finished(const SSL *s, void *buf, size_t count);\r
+size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);\r
+\r
+/* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options\r
+ * are 'ored' with SSL_VERIFY_PEER if they are desired */\r
+#define SSL_VERIFY_NONE                        0x00\r
+#define SSL_VERIFY_PEER                        0x01\r
+#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT        0x02\r
+#define SSL_VERIFY_CLIENT_ONCE         0x04\r
+\r
+#define OpenSSL_add_ssl_algorithms()   SSL_library_init()\r
+#define SSLeay_add_ssl_algorithms()    SSL_library_init()\r
+\r
+/* this is for backward compatibility */\r
+#if 0 /* NEW_SSLEAY */\r
+#define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c)\r
+#define SSL_set_pref_cipher(c,n)       SSL_set_cipher_list(c,n)\r
+#define SSL_add_session(a,b)            SSL_CTX_add_session((a),(b))\r
+#define SSL_remove_session(a,b)                SSL_CTX_remove_session((a),(b))\r
+#define SSL_flush_sessions(a,b)                SSL_CTX_flush_sessions((a),(b))\r
+#endif\r
+/* More backward compatibility */\r
+#define SSL_get_cipher(s) \\r
+               SSL_CIPHER_get_name(SSL_get_current_cipher(s))\r
+#define SSL_get_cipher_bits(s,np) \\r
+               SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)\r
+#define SSL_get_cipher_version(s) \\r
+               SSL_CIPHER_get_version(SSL_get_current_cipher(s))\r
+#define SSL_get_cipher_name(s) \\r
+               SSL_CIPHER_get_name(SSL_get_current_cipher(s))\r
+#define SSL_get_time(a)                SSL_SESSION_get_time(a)\r
+#define SSL_set_time(a,b)      SSL_SESSION_set_time((a),(b))\r
+#define SSL_get_timeout(a)     SSL_SESSION_get_timeout(a)\r
+#define SSL_set_timeout(a,b)   SSL_SESSION_set_timeout((a),(b))\r
+\r
+#if 1 /*SSLEAY_MACROS*/\r
+#define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id)\r
+#define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id)\r
+#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \\r
+       (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)\r
+#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) PEM_ASN1_read_bio_of(SSL_SESSION,d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,x,cb,u)\r
+#define PEM_write_SSL_SESSION(fp,x) \\r
+       PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \\r
+               PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)\r
+#define PEM_write_bio_SSL_SESSION(bp,x) \\r
+       PEM_ASN1_write_bio_of(SSL_SESSION,i2d_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,x,NULL,NULL,0,NULL,NULL)\r
+#endif\r
+\r
+#define SSL_AD_REASON_OFFSET           1000\r
+/* These alert types are for SSLv3 and TLSv1 */\r
+#define SSL_AD_CLOSE_NOTIFY            SSL3_AD_CLOSE_NOTIFY\r
+#define SSL_AD_UNEXPECTED_MESSAGE      SSL3_AD_UNEXPECTED_MESSAGE /* fatal */\r
+#define SSL_AD_BAD_RECORD_MAC          SSL3_AD_BAD_RECORD_MAC     /* fatal */\r
+#define SSL_AD_DECRYPTION_FAILED       TLS1_AD_DECRYPTION_FAILED\r
+#define SSL_AD_RECORD_OVERFLOW         TLS1_AD_RECORD_OVERFLOW\r
+#define SSL_AD_DECOMPRESSION_FAILURE   SSL3_AD_DECOMPRESSION_FAILURE/* fatal */\r
+#define SSL_AD_HANDSHAKE_FAILURE       SSL3_AD_HANDSHAKE_FAILURE/* fatal */\r
+#define SSL_AD_NO_CERTIFICATE          SSL3_AD_NO_CERTIFICATE /* Not for TLS */\r
+#define SSL_AD_BAD_CERTIFICATE         SSL3_AD_BAD_CERTIFICATE\r
+#define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE\r
+#define SSL_AD_CERTIFICATE_REVOKED     SSL3_AD_CERTIFICATE_REVOKED\r
+#define SSL_AD_CERTIFICATE_EXPIRED     SSL3_AD_CERTIFICATE_EXPIRED\r
+#define SSL_AD_CERTIFICATE_UNKNOWN     SSL3_AD_CERTIFICATE_UNKNOWN\r
+#define SSL_AD_ILLEGAL_PARAMETER       SSL3_AD_ILLEGAL_PARAMETER   /* fatal */\r
+#define SSL_AD_UNKNOWN_CA              TLS1_AD_UNKNOWN_CA      /* fatal */\r
+#define SSL_AD_ACCESS_DENIED           TLS1_AD_ACCESS_DENIED   /* fatal */\r
+#define SSL_AD_DECODE_ERROR            TLS1_AD_DECODE_ERROR    /* fatal */\r
+#define SSL_AD_DECRYPT_ERROR           TLS1_AD_DECRYPT_ERROR\r
+#define SSL_AD_EXPORT_RESTRICTION      TLS1_AD_EXPORT_RESTRICTION/* fatal */\r
+#define SSL_AD_PROTOCOL_VERSION                TLS1_AD_PROTOCOL_VERSION /* fatal */\r
+#define SSL_AD_INSUFFICIENT_SECURITY   TLS1_AD_INSUFFICIENT_SECURITY/* fatal */\r
+#define SSL_AD_INTERNAL_ERROR          TLS1_AD_INTERNAL_ERROR  /* fatal */\r
+#define SSL_AD_USER_CANCELLED          TLS1_AD_USER_CANCELLED\r
+#define SSL_AD_NO_RENEGOTIATION                TLS1_AD_NO_RENEGOTIATION\r
+\r
+#define SSL_ERROR_NONE                 0\r
+#define SSL_ERROR_SSL                  1\r
+#define SSL_ERROR_WANT_READ            2\r
+#define SSL_ERROR_WANT_WRITE           3\r
+#define SSL_ERROR_WANT_X509_LOOKUP     4\r
+#define SSL_ERROR_SYSCALL              5 /* look at error stack/return value/errno */\r
+#define SSL_ERROR_ZERO_RETURN          6\r
+#define SSL_ERROR_WANT_CONNECT         7\r
+#define SSL_ERROR_WANT_ACCEPT          8\r
+\r
+#define SSL_CTRL_NEED_TMP_RSA                  1\r
+#define SSL_CTRL_SET_TMP_RSA                   2\r
+#define SSL_CTRL_SET_TMP_DH                    3\r
+#define SSL_CTRL_SET_TMP_ECDH                  4\r
+#define SSL_CTRL_SET_TMP_RSA_CB                        5\r
+#define SSL_CTRL_SET_TMP_DH_CB                 6\r
+#define SSL_CTRL_SET_TMP_ECDH_CB               7\r
+\r
+#define SSL_CTRL_GET_SESSION_REUSED            8\r
+#define SSL_CTRL_GET_CLIENT_CERT_REQUEST       9\r
+#define SSL_CTRL_GET_NUM_RENEGOTIATIONS                10\r
+#define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS      11\r
+#define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS      12\r
+#define SSL_CTRL_GET_FLAGS                     13\r
+#define SSL_CTRL_EXTRA_CHAIN_CERT              14\r
+\r
+#define SSL_CTRL_SET_MSG_CALLBACK               15\r
+#define SSL_CTRL_SET_MSG_CALLBACK_ARG           16\r
+\r
+/* only applies to datagram connections */\r
+#define SSL_CTRL_SET_MTU                17\r
+/* Stats */\r
+#define SSL_CTRL_SESS_NUMBER                   20\r
+#define SSL_CTRL_SESS_CONNECT                  21\r
+#define SSL_CTRL_SESS_CONNECT_GOOD             22\r
+#define SSL_CTRL_SESS_CONNECT_RENEGOTIATE      23\r
+#define SSL_CTRL_SESS_ACCEPT                   24\r
+#define SSL_CTRL_SESS_ACCEPT_GOOD              25\r
+#define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE       26\r
+#define SSL_CTRL_SESS_HIT                      27\r
+#define SSL_CTRL_SESS_CB_HIT                   28\r
+#define SSL_CTRL_SESS_MISSES                   29\r
+#define SSL_CTRL_SESS_TIMEOUTS                 30\r
+#define SSL_CTRL_SESS_CACHE_FULL               31\r
+#define SSL_CTRL_OPTIONS                       32\r
+#define SSL_CTRL_MODE                          33\r
+\r
+#define SSL_CTRL_GET_READ_AHEAD                        40\r
+#define SSL_CTRL_SET_READ_AHEAD                        41\r
+#define SSL_CTRL_SET_SESS_CACHE_SIZE           42\r
+#define SSL_CTRL_GET_SESS_CACHE_SIZE           43\r
+#define SSL_CTRL_SET_SESS_CACHE_MODE           44\r
+#define SSL_CTRL_GET_SESS_CACHE_MODE           45\r
+\r
+#define SSL_CTRL_GET_MAX_CERT_LIST             50\r
+#define SSL_CTRL_SET_MAX_CERT_LIST             51\r
+\r
+#define SSL_session_reused(ssl) \\r
+       SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL)\r
+#define SSL_num_renegotiations(ssl) \\r
+       SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)\r
+#define SSL_clear_num_renegotiations(ssl) \\r
+       SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)\r
+#define SSL_total_renegotiations(ssl) \\r
+       SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)\r
+\r
+#define SSL_CTX_need_tmp_RSA(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL)\r
+#define SSL_CTX_set_tmp_rsa(ctx,rsa) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)\r
+#define SSL_CTX_set_tmp_dh(ctx,dh) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh)\r
+#define SSL_CTX_set_tmp_ecdh(ctx,ecdh) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH,0,(char *)ecdh)\r
+\r
+#define SSL_need_tmp_RSA(ssl) \\r
+       SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL)\r
+#define SSL_set_tmp_rsa(ssl,rsa) \\r
+       SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)\r
+#define SSL_set_tmp_dh(ssl,dh) \\r
+       SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh)\r
+#define SSL_set_tmp_ecdh(ssl,ecdh) \\r
+       SSL_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH,0,(char *)ecdh)\r
+\r
+#define SSL_CTX_add_extra_chain_cert(ctx,x509) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509)\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+BIO_METHOD *BIO_f_ssl(void);\r
+BIO *BIO_new_ssl(SSL_CTX *ctx,int client);\r
+BIO *BIO_new_ssl_connect(SSL_CTX *ctx);\r
+BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);\r
+int BIO_ssl_copy_session_id(BIO *to,BIO *from);\r
+void BIO_ssl_shutdown(BIO *ssl_bio);\r
+\r
+#endif\r
+\r
+int    SSL_CTX_set_cipher_list(SSL_CTX *,const char *str);\r
+SSL_CTX *SSL_CTX_new(SSL_METHOD *meth);\r
+void   SSL_CTX_free(SSL_CTX *);\r
+long SSL_CTX_set_timeout(SSL_CTX *ctx,long t);\r
+long SSL_CTX_get_timeout(const SSL_CTX *ctx);\r
+X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *);\r
+void SSL_CTX_set_cert_store(SSL_CTX *,X509_STORE *);\r
+int SSL_want(const SSL *s);\r
+int    SSL_clear(SSL *s);\r
+\r
+void   SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm);\r
+\r
+SSL_CIPHER *SSL_get_current_cipher(const SSL *s);\r
+int    SSL_CIPHER_get_bits(const SSL_CIPHER *c,int *alg_bits);\r
+char * SSL_CIPHER_get_version(const SSL_CIPHER *c);\r
+const char *   SSL_CIPHER_get_name(const SSL_CIPHER *c);\r
+\r
+int    SSL_get_fd(const SSL *s);\r
+int    SSL_get_rfd(const SSL *s);\r
+int    SSL_get_wfd(const SSL *s);\r
+const char  * SSL_get_cipher_list(const SSL *s,int n);\r
+char * SSL_get_shared_ciphers(const SSL *s, char *buf, int len);\r
+int    SSL_get_read_ahead(const SSL * s);\r
+int    SSL_pending(const SSL *s);\r
+#ifndef OPENSSL_NO_SOCK\r
+int    SSL_set_fd(SSL *s, int fd);\r
+int    SSL_set_rfd(SSL *s, int fd);\r
+int    SSL_set_wfd(SSL *s, int fd);\r
+#endif\r
+#ifndef OPENSSL_NO_BIO\r
+void   SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio);\r
+BIO *  SSL_get_rbio(const SSL *s);\r
+BIO *  SSL_get_wbio(const SSL *s);\r
+#endif\r
+int    SSL_set_cipher_list(SSL *s, const char *str);\r
+void   SSL_set_read_ahead(SSL *s, int yes);\r
+int    SSL_get_verify_mode(const SSL *s);\r
+int    SSL_get_verify_depth(const SSL *s);\r
+int    (*SSL_get_verify_callback(const SSL *s))(int,X509_STORE_CTX *);\r
+void   SSL_set_verify(SSL *s, int mode,\r
+                      int (*callback)(int ok,X509_STORE_CTX *ctx));\r
+void   SSL_set_verify_depth(SSL *s, int depth);\r
+#ifndef OPENSSL_NO_RSA\r
+int    SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);\r
+#endif\r
+int    SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);\r
+int    SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);\r
+int    SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, const unsigned char *d, long len);\r
+int    SSL_use_certificate(SSL *ssl, X509 *x);\r
+int    SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);\r
+\r
+#ifndef OPENSSL_NO_STDIO\r
+int    SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);\r
+int    SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);\r
+int    SSL_use_certificate_file(SSL *ssl, const char *file, int type);\r
+int    SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);\r
+int    SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);\r
+int    SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);\r
+int    SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */\r
+STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);\r
+int    SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,\r
+                                           const char *file);\r
+#ifndef OPENSSL_SYS_VMS\r
+#ifndef OPENSSL_SYS_MACINTOSH_CLASSIC /* XXXXX: Better scheme needed! [was: #ifndef MAC_OS_pre_X] */\r
+int    SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,\r
+                                          const char *dir);\r
+#endif\r
+#endif\r
+\r
+#endif\r
+\r
+void   SSL_load_error_strings(void );\r
+const char *SSL_state_string(const SSL *s);\r
+const char *SSL_rstate_string(const SSL *s);\r
+const char *SSL_state_string_long(const SSL *s);\r
+const char *SSL_rstate_string_long(const SSL *s);\r
+long   SSL_SESSION_get_time(const SSL_SESSION *s);\r
+long   SSL_SESSION_set_time(SSL_SESSION *s, long t);\r
+long   SSL_SESSION_get_timeout(const SSL_SESSION *s);\r
+long   SSL_SESSION_set_timeout(SSL_SESSION *s, long t);\r
+void   SSL_copy_session_id(SSL *to,const SSL *from);\r
+\r
+SSL_SESSION *SSL_SESSION_new(void);\r
+unsigned long SSL_SESSION_hash(const SSL_SESSION *a);\r
+int    SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b);\r
+const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len);\r
+#ifndef OPENSSL_NO_FP_API\r
+int    SSL_SESSION_print_fp(FILE *fp,const SSL_SESSION *ses);\r
+#endif\r
+#ifndef OPENSSL_NO_BIO\r
+int    SSL_SESSION_print(BIO *fp,const SSL_SESSION *ses);\r
+#endif\r
+void   SSL_SESSION_free(SSL_SESSION *ses);\r
+int    i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);\r
+int    SSL_set_session(SSL *to, SSL_SESSION *session);\r
+int    SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);\r
+int    SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);\r
+int    SSL_CTX_set_generate_session_id(SSL_CTX *, GEN_SESSION_CB);\r
+int    SSL_set_generate_session_id(SSL *, GEN_SESSION_CB);\r
+int    SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,\r
+                                       unsigned int id_len);\r
+SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,const unsigned char **pp,\r
+                            long length);\r
+\r
+#ifdef HEADER_X509_H\r
+X509 * SSL_get_peer_certificate(const SSL *s);\r
+#endif\r
+\r
+STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s);\r
+\r
+int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);\r
+int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);\r
+int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int,X509_STORE_CTX *);\r
+void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,\r
+                       int (*callback)(int, X509_STORE_CTX *));\r
+void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);\r
+void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *,void *), void *arg);\r
+#ifndef OPENSSL_NO_RSA\r
+int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);\r
+#endif\r
+int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, long len);\r
+int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);\r
+int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx,\r
+       const unsigned char *d, long len);\r
+int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);\r
+int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, const unsigned char *d);\r
+\r
+void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);\r
+void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);\r
+\r
+int SSL_CTX_check_private_key(const SSL_CTX *ctx);\r
+int SSL_check_private_key(const SSL *ctx);\r
+\r
+int    SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,\r
+                                      unsigned int sid_ctx_len);\r
+\r
+SSL *  SSL_new(SSL_CTX *ctx);\r
+int    SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,\r
+                                  unsigned int sid_ctx_len);\r
+\r
+int SSL_CTX_set_purpose(SSL_CTX *s, int purpose);\r
+int SSL_set_purpose(SSL *s, int purpose);\r
+int SSL_CTX_set_trust(SSL_CTX *s, int trust);\r
+int SSL_set_trust(SSL *s, int trust);\r
+\r
+void   SSL_free(SSL *ssl);\r
+int    SSL_accept(SSL *ssl);\r
+int    SSL_connect(SSL *ssl);\r
+int    SSL_read(SSL *ssl,void *buf,int num);\r
+int    SSL_peek(SSL *ssl,void *buf,int num);\r
+int    SSL_write(SSL *ssl,const void *buf,int num);\r
+long   SSL_ctrl(SSL *ssl,int cmd, long larg, void *parg);\r
+long   SSL_callback_ctrl(SSL *, int, void (*)(void));\r
+long   SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, void *parg);\r
+long   SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)(void));\r
+\r
+int    SSL_get_error(const SSL *s,int ret_code);\r
+const char *SSL_get_version(const SSL *s);\r
+\r
+/* This sets the 'default' SSL version that SSL_new() will create */\r
+int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth);\r
+\r
+SSL_METHOD *SSLv2_method(void);                /* SSLv2 */\r
+SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */\r
+SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */\r
+\r
+SSL_METHOD *SSLv3_method(void);                /* SSLv3 */\r
+SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */\r
+SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */\r
+\r
+SSL_METHOD *SSLv23_method(void);       /* SSLv3 but can rollback to v2 */\r
+SSL_METHOD *SSLv23_server_method(void);        /* SSLv3 but can rollback to v2 */\r
+SSL_METHOD *SSLv23_client_method(void);        /* SSLv3 but can rollback to v2 */\r
+\r
+SSL_METHOD *TLSv1_method(void);                /* TLSv1.0 */\r
+SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */\r
+SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */\r
+\r
+SSL_METHOD *DTLSv1_method(void);               /* DTLSv1.0 */\r
+SSL_METHOD *DTLSv1_server_method(void);        /* DTLSv1.0 */\r
+SSL_METHOD *DTLSv1_client_method(void);        /* DTLSv1.0 */\r
+\r
+STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s);\r
+\r
+int SSL_do_handshake(SSL *s);\r
+int SSL_renegotiate(SSL *s);\r
+int SSL_renegotiate_pending(SSL *s);\r
+int SSL_shutdown(SSL *s);\r
+\r
+SSL_METHOD *SSL_get_ssl_method(SSL *s);\r
+int SSL_set_ssl_method(SSL *s,SSL_METHOD *method);\r
+const char *SSL_alert_type_string_long(int value);\r
+const char *SSL_alert_type_string(int value);\r
+const char *SSL_alert_desc_string_long(int value);\r
+const char *SSL_alert_desc_string(int value);\r
+\r
+void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list);\r
+void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);\r
+STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s);\r
+STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *s);\r
+int SSL_add_client_CA(SSL *ssl,X509 *x);\r
+int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x);\r
+\r
+void SSL_set_connect_state(SSL *s);\r
+void SSL_set_accept_state(SSL *s);\r
+\r
+long SSL_get_default_timeout(const SSL *s);\r
+\r
+int SSL_library_init(void );\r
+\r
+char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size);\r
+STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk);\r
+\r
+SSL *SSL_dup(SSL *ssl);\r
+\r
+X509 *SSL_get_certificate(const SSL *ssl);\r
+/* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl);\r
+\r
+void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode);\r
+int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx);\r
+void SSL_set_quiet_shutdown(SSL *ssl,int mode);\r
+int SSL_get_quiet_shutdown(const SSL *ssl);\r
+void SSL_set_shutdown(SSL *ssl,int mode);\r
+int SSL_get_shutdown(const SSL *ssl);\r
+int SSL_version(const SSL *ssl);\r
+int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);\r
+int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,\r
+       const char *CApath);\r
+#define SSL_get0_session SSL_get_session /* just peek at pointer */\r
+SSL_SESSION *SSL_get_session(const SSL *ssl);\r
+SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */\r
+SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);\r
+void SSL_set_info_callback(SSL *ssl,\r
+                          void (*cb)(const SSL *ssl,int type,int val));\r
+void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl,int type,int val);\r
+int SSL_state(const SSL *ssl);\r
+\r
+void SSL_set_verify_result(SSL *ssl,long v);\r
+long SSL_get_verify_result(const SSL *ssl);\r
+\r
+int SSL_set_ex_data(SSL *ssl,int idx,void *data);\r
+void *SSL_get_ex_data(const SSL *ssl,int idx);\r
+int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,\r
+       CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+\r
+int SSL_SESSION_set_ex_data(SSL_SESSION *ss,int idx,void *data);\r
+void *SSL_SESSION_get_ex_data(const SSL_SESSION *ss,int idx);\r
+int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,\r
+       CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+\r
+int SSL_CTX_set_ex_data(SSL_CTX *ssl,int idx,void *data);\r
+void *SSL_CTX_get_ex_data(const SSL_CTX *ssl,int idx);\r
+int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,\r
+       CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+\r
+int SSL_get_ex_data_X509_STORE_CTX_idx(void );\r
+\r
+#define SSL_CTX_sess_set_cache_size(ctx,t) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)\r
+#define SSL_CTX_sess_get_cache_size(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)\r
+#define SSL_CTX_set_session_cache_mode(ctx,m) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)\r
+#define SSL_CTX_get_session_cache_mode(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)\r
+\r
+#define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)\r
+#define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)\r
+#define SSL_CTX_get_read_ahead(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)\r
+#define SSL_CTX_set_read_ahead(ctx,m) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL)\r
+#define SSL_CTX_get_max_cert_list(ctx) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)\r
+#define SSL_CTX_set_max_cert_list(ctx,m) \\r
+       SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)\r
+#define SSL_get_max_cert_list(ssl) \\r
+       SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)\r
+#define SSL_set_max_cert_list(ssl,m) \\r
+       SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)\r
+\r
+     /* NB: the keylength is only applicable when is_export is true */\r
+#ifndef OPENSSL_NO_RSA\r
+void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,\r
+                                 RSA *(*cb)(SSL *ssl,int is_export,\r
+                                            int keylength));\r
+\r
+void SSL_set_tmp_rsa_callback(SSL *ssl,\r
+                                 RSA *(*cb)(SSL *ssl,int is_export,\r
+                                            int keylength));\r
+#endif\r
+#ifndef OPENSSL_NO_DH\r
+void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,\r
+                                DH *(*dh)(SSL *ssl,int is_export,\r
+                                          int keylength));\r
+void SSL_set_tmp_dh_callback(SSL *ssl,\r
+                                DH *(*dh)(SSL *ssl,int is_export,\r
+                                          int keylength));\r
+#endif\r
+#ifndef OPENSSL_NO_ECDH\r
+void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx,\r
+                                EC_KEY *(*ecdh)(SSL *ssl,int is_export,\r
+                                          int keylength));\r
+void SSL_set_tmp_ecdh_callback(SSL *ssl,\r
+                                EC_KEY *(*ecdh)(SSL *ssl,int is_export,\r
+                                          int keylength));\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_COMP\r
+const COMP_METHOD *SSL_get_current_compression(SSL *s);\r
+const COMP_METHOD *SSL_get_current_expansion(SSL *s);\r
+const char *SSL_COMP_get_name(const COMP_METHOD *comp);\r
+STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);\r
+int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm);\r
+#else\r
+const void *SSL_get_current_compression(SSL *s);\r
+const void *SSL_get_current_expansion(SSL *s);\r
+const char *SSL_COMP_get_name(const void *comp);\r
+void *SSL_COMP_get_compression_methods(void);\r
+int SSL_COMP_add_compression_method(int id,void *cm);\r
+#endif\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_SSL_strings(void);\r
+\r
+/* Error codes for the SSL functions. */\r
+\r
+/* Function codes. */\r
+#define SSL_F_CLIENT_CERTIFICATE                        100\r
+#define SSL_F_CLIENT_FINISHED                           238\r
+#define SSL_F_CLIENT_HELLO                              101\r
+#define SSL_F_CLIENT_MASTER_KEY                                 102\r
+#define SSL_F_D2I_SSL_SESSION                           103\r
+#define SSL_F_DO_DTLS1_WRITE                            1003\r
+#define SSL_F_DO_SSL3_WRITE                             104\r
+#define SSL_F_DTLS1_ACCEPT                              1004\r
+#define SSL_F_DTLS1_BUFFER_RECORD                       1005\r
+#define SSL_F_DTLS1_CLIENT_HELLO                        1006\r
+#define SSL_F_DTLS1_CONNECT                             1007\r
+#define SSL_F_DTLS1_ENC                                         1008\r
+#define SSL_F_DTLS1_GET_HELLO_VERIFY                    1009\r
+#define SSL_F_DTLS1_GET_MESSAGE                                 1010\r
+#define SSL_F_DTLS1_GET_MESSAGE_FRAGMENT                1011\r
+#define SSL_F_DTLS1_GET_RECORD                          1012\r
+#define SSL_F_DTLS1_OUTPUT_CERT_CHAIN                   1013\r
+#define SSL_F_DTLS1_PROCESS_OUT_OF_SEQ_MESSAGE          1014\r
+#define SSL_F_DTLS1_PROCESS_RECORD                      1015\r
+#define SSL_F_DTLS1_READ_BYTES                          1016\r
+#define SSL_F_DTLS1_READ_FAILED                                 1001\r
+#define SSL_F_DTLS1_SEND_CERTIFICATE_REQUEST            1017\r
+#define SSL_F_DTLS1_SEND_CLIENT_CERTIFICATE             1018\r
+#define SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE            1019\r
+#define SSL_F_DTLS1_SEND_CLIENT_VERIFY                  1020\r
+#define SSL_F_DTLS1_SEND_HELLO_VERIFY_REQUEST           1002\r
+#define SSL_F_DTLS1_SEND_SERVER_CERTIFICATE             1021\r
+#define SSL_F_DTLS1_SEND_SERVER_HELLO                   1022\r
+#define SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE            1023\r
+#define SSL_F_DTLS1_WRITE_APP_DATA_BYTES                1024\r
+#define SSL_F_GET_CLIENT_FINISHED                       105\r
+#define SSL_F_GET_CLIENT_HELLO                          106\r
+#define SSL_F_GET_CLIENT_MASTER_KEY                     107\r
+#define SSL_F_GET_SERVER_FINISHED                       108\r
+#define SSL_F_GET_SERVER_HELLO                          109\r
+#define SSL_F_GET_SERVER_VERIFY                                 110\r
+#define SSL_F_I2D_SSL_SESSION                           111\r
+#define SSL_F_READ_N                                    112\r
+#define SSL_F_REQUEST_CERTIFICATE                       113\r
+#define SSL_F_SERVER_FINISH                             239\r
+#define SSL_F_SERVER_HELLO                              114\r
+#define SSL_F_SERVER_VERIFY                             240\r
+#define SSL_F_SSL23_ACCEPT                              115\r
+#define SSL_F_SSL23_CLIENT_HELLO                        116\r
+#define SSL_F_SSL23_CONNECT                             117\r
+#define SSL_F_SSL23_GET_CLIENT_HELLO                    118\r
+#define SSL_F_SSL23_GET_SERVER_HELLO                    119\r
+#define SSL_F_SSL23_PEEK                                237\r
+#define SSL_F_SSL23_READ                                120\r
+#define SSL_F_SSL23_WRITE                               121\r
+#define SSL_F_SSL2_ACCEPT                               122\r
+#define SSL_F_SSL2_CONNECT                              123\r
+#define SSL_F_SSL2_ENC_INIT                             124\r
+#define SSL_F_SSL2_GENERATE_KEY_MATERIAL                241\r
+#define SSL_F_SSL2_PEEK                                         234\r
+#define SSL_F_SSL2_READ                                         125\r
+#define SSL_F_SSL2_READ_INTERNAL                        236\r
+#define SSL_F_SSL2_SET_CERTIFICATE                      126\r
+#define SSL_F_SSL2_WRITE                                127\r
+#define SSL_F_SSL3_ACCEPT                               128\r
+#define SSL_F_SSL3_CALLBACK_CTRL                        233\r
+#define SSL_F_SSL3_CHANGE_CIPHER_STATE                  129\r
+#define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM             130\r
+#define SSL_F_SSL3_CLIENT_HELLO                                 131\r
+#define SSL_F_SSL3_CONNECT                              132\r
+#define SSL_F_SSL3_CTRL                                         213\r
+#define SSL_F_SSL3_CTX_CTRL                             133\r
+#define SSL_F_SSL3_ENC                                  134\r
+#define SSL_F_SSL3_GENERATE_KEY_BLOCK                   238\r
+#define SSL_F_SSL3_GET_CERTIFICATE_REQUEST              135\r
+#define SSL_F_SSL3_GET_CERT_VERIFY                      136\r
+#define SSL_F_SSL3_GET_CLIENT_CERTIFICATE               137\r
+#define SSL_F_SSL3_GET_CLIENT_HELLO                     138\r
+#define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE              139\r
+#define SSL_F_SSL3_GET_FINISHED                                 140\r
+#define SSL_F_SSL3_GET_KEY_EXCHANGE                     141\r
+#define SSL_F_SSL3_GET_MESSAGE                          142\r
+#define SSL_F_SSL3_GET_RECORD                           143\r
+#define SSL_F_SSL3_GET_SERVER_CERTIFICATE               144\r
+#define SSL_F_SSL3_GET_SERVER_DONE                      145\r
+#define SSL_F_SSL3_GET_SERVER_HELLO                     146\r
+#define SSL_F_SSL3_OUTPUT_CERT_CHAIN                    147\r
+#define SSL_F_SSL3_PEEK                                         235\r
+#define SSL_F_SSL3_READ_BYTES                           148\r
+#define SSL_F_SSL3_READ_N                               149\r
+#define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST             150\r
+#define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE              151\r
+#define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE             152\r
+#define SSL_F_SSL3_SEND_CLIENT_VERIFY                   153\r
+#define SSL_F_SSL3_SEND_SERVER_CERTIFICATE              154\r
+#define SSL_F_SSL3_SEND_SERVER_HELLO                    242\r
+#define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE             155\r
+#define SSL_F_SSL3_SETUP_BUFFERS                        156\r
+#define SSL_F_SSL3_SETUP_KEY_BLOCK                      157\r
+#define SSL_F_SSL3_WRITE_BYTES                          158\r
+#define SSL_F_SSL3_WRITE_PENDING                        159\r
+#define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK        215\r
+#define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK       216\r
+#define SSL_F_SSL_BAD_METHOD                            160\r
+#define SSL_F_SSL_BYTES_TO_CIPHER_LIST                  161\r
+#define SSL_F_SSL_CERT_DUP                              221\r
+#define SSL_F_SSL_CERT_INST                             222\r
+#define SSL_F_SSL_CERT_INSTANTIATE                      214\r
+#define SSL_F_SSL_CERT_NEW                              162\r
+#define SSL_F_SSL_CHECK_PRIVATE_KEY                     163\r
+#define SSL_F_SSL_CIPHER_PROCESS_RULESTR                230\r
+#define SSL_F_SSL_CIPHER_STRENGTH_SORT                  231\r
+#define SSL_F_SSL_CLEAR                                         164\r
+#define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD           165\r
+#define SSL_F_SSL_CREATE_CIPHER_LIST                    166\r
+#define SSL_F_SSL_CTRL                                  232\r
+#define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY                         168\r
+#define SSL_F_SSL_CTX_NEW                               169\r
+#define SSL_F_SSL_CTX_SET_CIPHER_LIST                   1026\r
+#define SSL_F_SSL_CTX_SET_PURPOSE                       226\r
+#define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT            219\r
+#define SSL_F_SSL_CTX_SET_SSL_VERSION                   170\r
+#define SSL_F_SSL_CTX_SET_TRUST                                 229\r
+#define SSL_F_SSL_CTX_USE_CERTIFICATE                   171\r
+#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1              172\r
+#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE        220\r
+#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE              173\r
+#define SSL_F_SSL_CTX_USE_PRIVATEKEY                    174\r
+#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1               175\r
+#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE               176\r
+#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY                         177\r
+#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1            178\r
+#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE            179\r
+#define SSL_F_SSL_DO_HANDSHAKE                          180\r
+#define SSL_F_SSL_GET_NEW_SESSION                       181\r
+#define SSL_F_SSL_GET_PREV_SESSION                      217\r
+#define SSL_F_SSL_GET_SERVER_SEND_CERT                  182\r
+#define SSL_F_SSL_GET_SIGN_PKEY                                 183\r
+#define SSL_F_SSL_INIT_WBIO_BUFFER                      184\r
+#define SSL_F_SSL_LOAD_CLIENT_CA_FILE                   185\r
+#define SSL_F_SSL_NEW                                   186\r
+#define SSL_F_SSL_PEEK                                  1025\r
+#define SSL_F_SSL_READ                                  223\r
+#define SSL_F_SSL_RSA_PRIVATE_DECRYPT                   187\r
+#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT                    188\r
+#define SSL_F_SSL_SESSION_NEW                           189\r
+#define SSL_F_SSL_SESSION_PRINT_FP                      190\r
+#define SSL_F_SSL_SESS_CERT_NEW                                 225\r
+#define SSL_F_SSL_SET_CERT                              191\r
+#define SSL_F_SSL_SET_CIPHER_LIST                       1027\r
+#define SSL_F_SSL_SET_FD                                192\r
+#define SSL_F_SSL_SET_PKEY                              193\r
+#define SSL_F_SSL_SET_PURPOSE                           227\r
+#define SSL_F_SSL_SET_RFD                               194\r
+#define SSL_F_SSL_SET_SESSION                           195\r
+#define SSL_F_SSL_SET_SESSION_ID_CONTEXT                218\r
+#define SSL_F_SSL_SET_TRUST                             228\r
+#define SSL_F_SSL_SET_WFD                               196\r
+#define SSL_F_SSL_SHUTDOWN                              224\r
+#define SSL_F_SSL_UNDEFINED_CONST_FUNCTION              243\r
+#define SSL_F_SSL_UNDEFINED_FUNCTION                    197\r
+#define SSL_F_SSL_UNDEFINED_VOID_FUNCTION               244\r
+#define SSL_F_SSL_USE_CERTIFICATE                       198\r
+#define SSL_F_SSL_USE_CERTIFICATE_ASN1                  199\r
+#define SSL_F_SSL_USE_CERTIFICATE_FILE                  200\r
+#define SSL_F_SSL_USE_PRIVATEKEY                        201\r
+#define SSL_F_SSL_USE_PRIVATEKEY_ASN1                   202\r
+#define SSL_F_SSL_USE_PRIVATEKEY_FILE                   203\r
+#define SSL_F_SSL_USE_RSAPRIVATEKEY                     204\r
+#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1                205\r
+#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE                206\r
+#define SSL_F_SSL_VERIFY_CERT_CHAIN                     207\r
+#define SSL_F_SSL_WRITE                                         208\r
+#define SSL_F_TLS1_CHANGE_CIPHER_STATE                  209\r
+#define SSL_F_TLS1_ENC                                  210\r
+#define SSL_F_TLS1_SETUP_KEY_BLOCK                      211\r
+#define SSL_F_WRITE_PENDING                             212\r
+\r
+/* Reason codes. */\r
+#define SSL_R_APP_DATA_IN_HANDSHAKE                     100\r
+#define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272\r
+#define SSL_R_BAD_ALERT_RECORD                          101\r
+#define SSL_R_BAD_AUTHENTICATION_TYPE                   102\r
+#define SSL_R_BAD_CHANGE_CIPHER_SPEC                    103\r
+#define SSL_R_BAD_CHECKSUM                              104\r
+#define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK             106\r
+#define SSL_R_BAD_DECOMPRESSION                                 107\r
+#define SSL_R_BAD_DH_G_LENGTH                           108\r
+#define SSL_R_BAD_DH_PUB_KEY_LENGTH                     109\r
+#define SSL_R_BAD_DH_P_LENGTH                           110\r
+#define SSL_R_BAD_DIGEST_LENGTH                                 111\r
+#define SSL_R_BAD_DSA_SIGNATURE                                 112\r
+#define SSL_R_BAD_ECC_CERT                              1117\r
+#define SSL_R_BAD_ECDSA_SIGNATURE                       1112\r
+#define SSL_R_BAD_ECPOINT                               1113\r
+#define SSL_R_BAD_HELLO_REQUEST                                 105\r
+#define SSL_R_BAD_LENGTH                                271\r
+#define SSL_R_BAD_MAC_DECODE                            113\r
+#define SSL_R_BAD_MESSAGE_TYPE                          114\r
+#define SSL_R_BAD_PACKET_LENGTH                                 115\r
+#define SSL_R_BAD_PROTOCOL_VERSION_NUMBER               116\r
+#define SSL_R_BAD_RESPONSE_ARGUMENT                     117\r
+#define SSL_R_BAD_RSA_DECRYPT                           118\r
+#define SSL_R_BAD_RSA_ENCRYPT                           119\r
+#define SSL_R_BAD_RSA_E_LENGTH                          120\r
+#define SSL_R_BAD_RSA_MODULUS_LENGTH                    121\r
+#define SSL_R_BAD_RSA_SIGNATURE                                 122\r
+#define SSL_R_BAD_SIGNATURE                             123\r
+#define SSL_R_BAD_SSL_FILETYPE                          124\r
+#define SSL_R_BAD_SSL_SESSION_ID_LENGTH                         125\r
+#define SSL_R_BAD_STATE                                         126\r
+#define SSL_R_BAD_WRITE_RETRY                           127\r
+#define SSL_R_BIO_NOT_SET                               128\r
+#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG                         129\r
+#define SSL_R_BN_LIB                                    130\r
+#define SSL_R_CA_DN_LENGTH_MISMATCH                     131\r
+#define SSL_R_CA_DN_TOO_LONG                            132\r
+#define SSL_R_CCS_RECEIVED_EARLY                        133\r
+#define SSL_R_CERTIFICATE_VERIFY_FAILED                         134\r
+#define SSL_R_CERT_LENGTH_MISMATCH                      135\r
+#define SSL_R_CHALLENGE_IS_DIFFERENT                    136\r
+#define SSL_R_CIPHER_CODE_WRONG_LENGTH                  137\r
+#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE                138\r
+#define SSL_R_CIPHER_TABLE_SRC_ERROR                    139\r
+#define SSL_R_COMPRESSED_LENGTH_TOO_LONG                140\r
+#define SSL_R_COMPRESSION_FAILURE                       141\r
+#define SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE   1120\r
+#define SSL_R_COMPRESSION_LIBRARY_ERROR                         142\r
+#define SSL_R_CONNECTION_ID_IS_DIFFERENT                143\r
+#define SSL_R_CONNECTION_TYPE_NOT_SET                   144\r
+#define SSL_R_COOKIE_MISMATCH                           2002\r
+#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED             145\r
+#define SSL_R_DATA_LENGTH_TOO_LONG                      146\r
+#define SSL_R_DECRYPTION_FAILED                                 147\r
+#define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC       1109\r
+#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG           148\r
+#define SSL_R_DIGEST_CHECK_FAILED                       149\r
+#define SSL_R_DUPLICATE_COMPRESSION_ID                  1121\r
+#define SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER              1119\r
+#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG                         150\r
+#define SSL_R_ERROR_GENERATING_TMP_RSA_KEY              1092\r
+#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST             151\r
+#define SSL_R_EXCESSIVE_MESSAGE_SIZE                    152\r
+#define SSL_R_EXTRA_DATA_IN_MESSAGE                     153\r
+#define SSL_R_GOT_A_FIN_BEFORE_A_CCS                    154\r
+#define SSL_R_HTTPS_PROXY_REQUEST                       155\r
+#define SSL_R_HTTP_REQUEST                              156\r
+#define SSL_R_ILLEGAL_PADDING                           1110\r
+#define SSL_R_INVALID_CHALLENGE_LENGTH                  158\r
+#define SSL_R_INVALID_COMMAND                           280\r
+#define SSL_R_INVALID_PURPOSE                           278\r
+#define SSL_R_INVALID_TRUST                             279\r
+#define SSL_R_KEY_ARG_TOO_LONG                          1112\r
+#define SSL_R_KRB5                                      1104\r
+#define SSL_R_KRB5_C_CC_PRINC                           1094\r
+#define SSL_R_KRB5_C_GET_CRED                           1095\r
+#define SSL_R_KRB5_C_INIT                               1096\r
+#define SSL_R_KRB5_C_MK_REQ                             1097\r
+#define SSL_R_KRB5_S_BAD_TICKET                                 1098\r
+#define SSL_R_KRB5_S_INIT                               1099\r
+#define SSL_R_KRB5_S_RD_REQ                             1108\r
+#define SSL_R_KRB5_S_TKT_EXPIRED                        1105\r
+#define SSL_R_KRB5_S_TKT_NYV                            1106\r
+#define SSL_R_KRB5_S_TKT_SKEW                           1107\r
+#define SSL_R_LENGTH_MISMATCH                           159\r
+#define SSL_R_LENGTH_TOO_SHORT                          160\r
+#define SSL_R_LIBRARY_BUG                               274\r
+#define SSL_R_LIBRARY_HAS_NO_CIPHERS                    161\r
+#define SSL_R_MASTER_KEY_TOO_LONG                       1112\r
+#define SSL_R_MESSAGE_TOO_LONG                          1111\r
+#define SSL_R_MISSING_DH_DSA_CERT                       162\r
+#define SSL_R_MISSING_DH_KEY                            163\r
+#define SSL_R_MISSING_DH_RSA_CERT                       164\r
+#define SSL_R_MISSING_DSA_SIGNING_CERT                  165\r
+#define SSL_R_MISSING_EXPORT_TMP_DH_KEY                         166\r
+#define SSL_R_MISSING_EXPORT_TMP_RSA_KEY                167\r
+#define SSL_R_MISSING_RSA_CERTIFICATE                   168\r
+#define SSL_R_MISSING_RSA_ENCRYPTING_CERT               169\r
+#define SSL_R_MISSING_RSA_SIGNING_CERT                  170\r
+#define SSL_R_MISSING_TMP_DH_KEY                        171\r
+#define SSL_R_MISSING_TMP_ECDH_KEY                      1114\r
+#define SSL_R_MISSING_TMP_RSA_KEY                       172\r
+#define SSL_R_MISSING_TMP_RSA_PKEY                      173\r
+#define SSL_R_MISSING_VERIFY_MESSAGE                    174\r
+#define SSL_R_NON_SSLV2_INITIAL_PACKET                  175\r
+#define SSL_R_NO_CERTIFICATES_RETURNED                  176\r
+#define SSL_R_NO_CERTIFICATE_ASSIGNED                   177\r
+#define SSL_R_NO_CERTIFICATE_RETURNED                   178\r
+#define SSL_R_NO_CERTIFICATE_SET                        179\r
+#define SSL_R_NO_CERTIFICATE_SPECIFIED                  180\r
+#define SSL_R_NO_CIPHERS_AVAILABLE                      181\r
+#define SSL_R_NO_CIPHERS_PASSED                                 182\r
+#define SSL_R_NO_CIPHERS_SPECIFIED                      183\r
+#define SSL_R_NO_CIPHER_LIST                            184\r
+#define SSL_R_NO_CIPHER_MATCH                           185\r
+#define SSL_R_NO_CLIENT_CERT_RECEIVED                   186\r
+#define SSL_R_NO_COMPRESSION_SPECIFIED                  187\r
+#define SSL_R_NO_METHOD_SPECIFIED                       188\r
+#define SSL_R_NO_PRIVATEKEY                             189\r
+#define SSL_R_NO_PRIVATE_KEY_ASSIGNED                   190\r
+#define SSL_R_NO_PROTOCOLS_AVAILABLE                    191\r
+#define SSL_R_NO_PUBLICKEY                              192\r
+#define SSL_R_NO_SHARED_CIPHER                          193\r
+#define SSL_R_NO_VERIFY_CALLBACK                        194\r
+#define SSL_R_NULL_SSL_CTX                              195\r
+#define SSL_R_NULL_SSL_METHOD_PASSED                    196\r
+#define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED           197\r
+#define SSL_R_PACKET_LENGTH_TOO_LONG                    198\r
+#define SSL_R_PATH_TOO_LONG                             270\r
+#define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE                 199\r
+#define SSL_R_PEER_ERROR                                200\r
+#define SSL_R_PEER_ERROR_CERTIFICATE                    201\r
+#define SSL_R_PEER_ERROR_NO_CERTIFICATE                         202\r
+#define SSL_R_PEER_ERROR_NO_CIPHER                      203\r
+#define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE   204\r
+#define SSL_R_PRE_MAC_LENGTH_TOO_LONG                   205\r
+#define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS                 206\r
+#define SSL_R_PROTOCOL_IS_SHUTDOWN                      207\r
+#define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR                  208\r
+#define SSL_R_PUBLIC_KEY_IS_NOT_RSA                     209\r
+#define SSL_R_PUBLIC_KEY_NOT_RSA                        210\r
+#define SSL_R_READ_BIO_NOT_SET                          211\r
+#define SSL_R_READ_TIMEOUT_EXPIRED                      2001\r
+#define SSL_R_READ_WRONG_PACKET_TYPE                    212\r
+#define SSL_R_RECORD_LENGTH_MISMATCH                    213\r
+#define SSL_R_RECORD_TOO_LARGE                          214\r
+#define SSL_R_RECORD_TOO_SMALL                          1093\r
+#define SSL_R_REQUIRED_CIPHER_MISSING                   215\r
+#define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO                216\r
+#define SSL_R_REUSE_CERT_TYPE_NOT_ZERO                  217\r
+#define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO                218\r
+#define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED          277\r
+#define SSL_R_SHORT_READ                                219\r
+#define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE     220\r
+#define SSL_R_SSL23_DOING_SESSION_ID_REUSE              221\r
+#define SSL_R_SSL2_CONNECTION_ID_TOO_LONG               1114\r
+#define SSL_R_SSL3_SESSION_ID_TOO_LONG                  1113\r
+#define SSL_R_SSL3_SESSION_ID_TOO_SHORT                         222\r
+#define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE               1042\r
+#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC                1020\r
+#define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED           1045\r
+#define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED           1044\r
+#define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN           1046\r
+#define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE                 1030\r
+#define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE             1040\r
+#define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER             1047\r
+#define SSL_R_SSLV3_ALERT_NO_CERTIFICATE                1041\r
+#define SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE        223\r
+#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE     224\r
+#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER          225\r
+#define SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 226\r
+#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE            1010\r
+#define SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE     227\r
+#define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE       1043\r
+#define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION        228\r
+#define SSL_R_SSL_HANDSHAKE_FAILURE                     229\r
+#define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS                230\r
+#define SSL_R_SSL_SESSION_ID_CALLBACK_FAILED            1102\r
+#define SSL_R_SSL_SESSION_ID_CONFLICT                   1103\r
+#define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG           273\r
+#define SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH             1101\r
+#define SSL_R_SSL_SESSION_ID_IS_DIFFERENT               231\r
+#define SSL_R_TLSV1_ALERT_ACCESS_DENIED                         1049\r
+#define SSL_R_TLSV1_ALERT_DECODE_ERROR                  1050\r
+#define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED             1021\r
+#define SSL_R_TLSV1_ALERT_DECRYPT_ERROR                         1051\r
+#define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION            1060\r
+#define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY                 1071\r
+#define SSL_R_TLSV1_ALERT_INTERNAL_ERROR                1080\r
+#define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION              1100\r
+#define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION              1070\r
+#define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW               1022\r
+#define SSL_R_TLSV1_ALERT_UNKNOWN_CA                    1048\r
+#define SSL_R_TLSV1_ALERT_USER_CANCELLED                1090\r
+#define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER      232\r
+#define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233\r
+#define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG   234\r
+#define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER           235\r
+#define SSL_R_UNABLE_TO_DECODE_DH_CERTS                         236\r
+#define SSL_R_UNABLE_TO_DECODE_ECDH_CERTS               1115\r
+#define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY              237\r
+#define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS              238\r
+#define SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS            1116\r
+#define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS      239\r
+#define SSL_R_UNABLE_TO_FIND_SSL_METHOD                         240\r
+#define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES          241\r
+#define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES          242\r
+#define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES                 243\r
+#define SSL_R_UNEXPECTED_MESSAGE                        244\r
+#define SSL_R_UNEXPECTED_RECORD                                 245\r
+#define SSL_R_UNINITIALIZED                             276\r
+#define SSL_R_UNKNOWN_ALERT_TYPE                        246\r
+#define SSL_R_UNKNOWN_CERTIFICATE_TYPE                  247\r
+#define SSL_R_UNKNOWN_CIPHER_RETURNED                   248\r
+#define SSL_R_UNKNOWN_CIPHER_TYPE                       249\r
+#define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE                         250\r
+#define SSL_R_UNKNOWN_PKEY_TYPE                                 251\r
+#define SSL_R_UNKNOWN_PROTOCOL                          252\r
+#define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE                         253\r
+#define SSL_R_UNKNOWN_SSL_VERSION                       254\r
+#define SSL_R_UNKNOWN_STATE                             255\r
+#define SSL_R_UNSUPPORTED_CIPHER                        256\r
+#define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM                 257\r
+#define SSL_R_UNSUPPORTED_ELLIPTIC_CURVE                1118\r
+#define SSL_R_UNSUPPORTED_OPTION                        1091\r
+#define SSL_R_UNSUPPORTED_PROTOCOL                      258\r
+#define SSL_R_UNSUPPORTED_SSL_VERSION                   259\r
+#define SSL_R_WRITE_BIO_NOT_SET                                 260\r
+#define SSL_R_WRONG_CIPHER_RETURNED                     261\r
+#define SSL_R_WRONG_MESSAGE_TYPE                        262\r
+#define SSL_R_WRONG_NUMBER_OF_KEY_BITS                  263\r
+#define SSL_R_WRONG_SIGNATURE_LENGTH                    264\r
+#define SSL_R_WRONG_SIGNATURE_SIZE                      265\r
+#define SSL_R_WRONG_SSL_VERSION                                 266\r
+#define SSL_R_WRONG_VERSION_NUMBER                      267\r
+#define SSL_R_X509_LIB                                  268\r
+#define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS          269\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ssl2.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ssl2.h
new file mode 100644 (file)
index 0000000..c871efe
--- /dev/null
@@ -0,0 +1,268 @@
+/* ssl/ssl2.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_SSL2_H \r
+#define HEADER_SSL2_H \r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Protocol Version Codes */\r
+#define SSL2_VERSION           0x0002\r
+#define SSL2_VERSION_MAJOR     0x00\r
+#define SSL2_VERSION_MINOR     0x02\r
+/* #define SSL2_CLIENT_VERSION 0x0002 */\r
+/* #define SSL2_SERVER_VERSION 0x0002 */\r
+\r
+/* Protocol Message Codes */\r
+#define SSL2_MT_ERROR                  0\r
+#define SSL2_MT_CLIENT_HELLO           1\r
+#define SSL2_MT_CLIENT_MASTER_KEY      2\r
+#define SSL2_MT_CLIENT_FINISHED                3\r
+#define SSL2_MT_SERVER_HELLO           4\r
+#define SSL2_MT_SERVER_VERIFY          5\r
+#define SSL2_MT_SERVER_FINISHED                6\r
+#define SSL2_MT_REQUEST_CERTIFICATE    7\r
+#define SSL2_MT_CLIENT_CERTIFICATE     8\r
+\r
+/* Error Message Codes */\r
+#define SSL2_PE_UNDEFINED_ERROR                0x0000\r
+#define SSL2_PE_NO_CIPHER              0x0001\r
+#define SSL2_PE_NO_CERTIFICATE         0x0002\r
+#define SSL2_PE_BAD_CERTIFICATE                0x0004\r
+#define SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE 0x0006\r
+\r
+/* Cipher Kind Values */\r
+#define SSL2_CK_NULL_WITH_MD5                  0x02000000 /* v3 */\r
+#define SSL2_CK_RC4_128_WITH_MD5               0x02010080\r
+#define SSL2_CK_RC4_128_EXPORT40_WITH_MD5      0x02020080\r
+#define SSL2_CK_RC2_128_CBC_WITH_MD5           0x02030080\r
+#define SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5  0x02040080\r
+#define SSL2_CK_IDEA_128_CBC_WITH_MD5          0x02050080\r
+#define SSL2_CK_DES_64_CBC_WITH_MD5            0x02060040\r
+#define SSL2_CK_DES_64_CBC_WITH_SHA            0x02060140 /* v3 */\r
+#define SSL2_CK_DES_192_EDE3_CBC_WITH_MD5      0x020700c0\r
+#define SSL2_CK_DES_192_EDE3_CBC_WITH_SHA      0x020701c0 /* v3 */\r
+#define SSL2_CK_RC4_64_WITH_MD5                        0x02080080 /* MS hack */\r
\r
+#define SSL2_CK_DES_64_CFB64_WITH_MD5_1                0x02ff0800 /* SSLeay */\r
+#define SSL2_CK_NULL                           0x02ff0810 /* SSLeay */\r
+\r
+#define SSL2_TXT_DES_64_CFB64_WITH_MD5_1       "DES-CFB-M1"\r
+#define SSL2_TXT_NULL_WITH_MD5                 "NULL-MD5"\r
+#define SSL2_TXT_RC4_128_WITH_MD5              "RC4-MD5"\r
+#define SSL2_TXT_RC4_128_EXPORT40_WITH_MD5     "EXP-RC4-MD5"\r
+#define SSL2_TXT_RC2_128_CBC_WITH_MD5          "RC2-CBC-MD5"\r
+#define SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 "EXP-RC2-CBC-MD5"\r
+#define SSL2_TXT_IDEA_128_CBC_WITH_MD5         "IDEA-CBC-MD5"\r
+#define SSL2_TXT_DES_64_CBC_WITH_MD5           "DES-CBC-MD5"\r
+#define SSL2_TXT_DES_64_CBC_WITH_SHA           "DES-CBC-SHA"\r
+#define SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5     "DES-CBC3-MD5"\r
+#define SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA     "DES-CBC3-SHA"\r
+#define SSL2_TXT_RC4_64_WITH_MD5               "RC4-64-MD5"\r
+\r
+#define SSL2_TXT_NULL                          "NULL"\r
+\r
+/* Flags for the SSL_CIPHER.algorithm2 field */\r
+#define SSL2_CF_5_BYTE_ENC                     0x01\r
+#define SSL2_CF_8_BYTE_ENC                     0x02\r
+\r
+/* Certificate Type Codes */\r
+#define SSL2_CT_X509_CERTIFICATE               0x01\r
+\r
+/* Authentication Type Code */\r
+#define SSL2_AT_MD5_WITH_RSA_ENCRYPTION                0x01\r
+\r
+#define SSL2_MAX_SSL_SESSION_ID_LENGTH         32\r
+\r
+/* Upper/Lower Bounds */\r
+#define SSL2_MAX_MASTER_KEY_LENGTH_IN_BITS     256\r
+#ifdef OPENSSL_SYS_MPE\r
+#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER   29998u\r
+#else\r
+#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER   32767u  /* 2^15-1 */\r
+#endif\r
+#define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER   16383 /* 2^14-1 */\r
+\r
+#define SSL2_CHALLENGE_LENGTH  16\r
+/*#define SSL2_CHALLENGE_LENGTH        32 */\r
+#define SSL2_MIN_CHALLENGE_LENGTH      16\r
+#define SSL2_MAX_CHALLENGE_LENGTH      32\r
+#define SSL2_CONNECTION_ID_LENGTH      16\r
+#define SSL2_MAX_CONNECTION_ID_LENGTH  16\r
+#define SSL2_SSL_SESSION_ID_LENGTH     16\r
+#define SSL2_MAX_CERT_CHALLENGE_LENGTH 32\r
+#define SSL2_MIN_CERT_CHALLENGE_LENGTH 16\r
+#define SSL2_MAX_KEY_MATERIAL_LENGTH   24\r
+\r
+#ifndef HEADER_SSL_LOCL_H\r
+#define  CERT          char\r
+#endif\r
+\r
+typedef struct ssl2_state_st\r
+       {\r
+       int three_byte_header;\r
+       int clear_text;         /* clear text */\r
+       int escape;             /* not used in SSLv2 */\r
+       int ssl2_rollback;      /* used if SSLv23 rolled back to SSLv2 */\r
+\r
+       /* non-blocking io info, used to make sure the same\r
+        * args were passwd */\r
+       unsigned int wnum;      /* number of bytes sent so far */\r
+       int wpend_tot;\r
+       const unsigned char *wpend_buf;\r
+\r
+       int wpend_off;  /* offset to data to write */\r
+       int wpend_len;  /* number of bytes passwd to write */\r
+       int wpend_ret;  /* number of bytes to return to caller */\r
+\r
+       /* buffer raw data */\r
+       int rbuf_left;\r
+       int rbuf_offs;\r
+       unsigned char *rbuf;\r
+       unsigned char *wbuf;\r
+\r
+       unsigned char *write_ptr;/* used to point to the start due to\r
+                                 * 2/3 byte header. */\r
+\r
+       unsigned int padding;\r
+       unsigned int rlength; /* passed to ssl2_enc */\r
+       int ract_data_length; /* Set when things are encrypted. */\r
+       unsigned int wlength; /* passed to ssl2_enc */\r
+       int wact_data_length; /* Set when things are decrypted. */\r
+       unsigned char *ract_data;\r
+       unsigned char *wact_data;\r
+       unsigned char *mac_data;\r
+\r
+       unsigned char *read_key;\r
+       unsigned char *write_key;\r
+\r
+               /* Stuff specifically to do with this SSL session */\r
+       unsigned int challenge_length;\r
+       unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH];\r
+       unsigned int conn_id_length;\r
+       unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH];\r
+       unsigned int key_material_length;\r
+       unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH*2];\r
+\r
+       unsigned long read_sequence;\r
+       unsigned long write_sequence;\r
+\r
+       struct  {\r
+               unsigned int conn_id_length;\r
+               unsigned int cert_type; \r
+               unsigned int cert_length;\r
+               unsigned int csl; \r
+               unsigned int clear;\r
+               unsigned int enc; \r
+               unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH];\r
+               unsigned int cipher_spec_length;\r
+               unsigned int session_id_length;\r
+               unsigned int clen;\r
+               unsigned int rlen;\r
+               } tmp;\r
+       } SSL2_STATE;\r
+\r
+/* SSLv2 */\r
+/* client */\r
+#define SSL2_ST_SEND_CLIENT_HELLO_A            (0x10|SSL_ST_CONNECT)\r
+#define SSL2_ST_SEND_CLIENT_HELLO_B            (0x11|SSL_ST_CONNECT)\r
+#define SSL2_ST_GET_SERVER_HELLO_A             (0x20|SSL_ST_CONNECT)\r
+#define SSL2_ST_GET_SERVER_HELLO_B             (0x21|SSL_ST_CONNECT)\r
+#define SSL2_ST_SEND_CLIENT_MASTER_KEY_A       (0x30|SSL_ST_CONNECT)\r
+#define SSL2_ST_SEND_CLIENT_MASTER_KEY_B       (0x31|SSL_ST_CONNECT)\r
+#define SSL2_ST_SEND_CLIENT_FINISHED_A         (0x40|SSL_ST_CONNECT)\r
+#define SSL2_ST_SEND_CLIENT_FINISHED_B         (0x41|SSL_ST_CONNECT)\r
+#define SSL2_ST_SEND_CLIENT_CERTIFICATE_A      (0x50|SSL_ST_CONNECT)\r
+#define SSL2_ST_SEND_CLIENT_CERTIFICATE_B      (0x51|SSL_ST_CONNECT)\r
+#define SSL2_ST_SEND_CLIENT_CERTIFICATE_C      (0x52|SSL_ST_CONNECT)\r
+#define SSL2_ST_SEND_CLIENT_CERTIFICATE_D      (0x53|SSL_ST_CONNECT)\r
+#define SSL2_ST_GET_SERVER_VERIFY_A            (0x60|SSL_ST_CONNECT)\r
+#define SSL2_ST_GET_SERVER_VERIFY_B            (0x61|SSL_ST_CONNECT)\r
+#define SSL2_ST_GET_SERVER_FINISHED_A          (0x70|SSL_ST_CONNECT)\r
+#define SSL2_ST_GET_SERVER_FINISHED_B          (0x71|SSL_ST_CONNECT)\r
+#define SSL2_ST_CLIENT_START_ENCRYPTION                (0x80|SSL_ST_CONNECT)\r
+#define SSL2_ST_X509_GET_CLIENT_CERTIFICATE    (0x90|SSL_ST_CONNECT)\r
+/* server */\r
+#define SSL2_ST_GET_CLIENT_HELLO_A             (0x10|SSL_ST_ACCEPT)\r
+#define SSL2_ST_GET_CLIENT_HELLO_B             (0x11|SSL_ST_ACCEPT)\r
+#define SSL2_ST_GET_CLIENT_HELLO_C             (0x12|SSL_ST_ACCEPT)\r
+#define SSL2_ST_SEND_SERVER_HELLO_A            (0x20|SSL_ST_ACCEPT)\r
+#define SSL2_ST_SEND_SERVER_HELLO_B            (0x21|SSL_ST_ACCEPT)\r
+#define SSL2_ST_GET_CLIENT_MASTER_KEY_A                (0x30|SSL_ST_ACCEPT)\r
+#define SSL2_ST_GET_CLIENT_MASTER_KEY_B                (0x31|SSL_ST_ACCEPT)\r
+#define SSL2_ST_SEND_SERVER_VERIFY_A           (0x40|SSL_ST_ACCEPT)\r
+#define SSL2_ST_SEND_SERVER_VERIFY_B           (0x41|SSL_ST_ACCEPT)\r
+#define SSL2_ST_SEND_SERVER_VERIFY_C           (0x42|SSL_ST_ACCEPT)\r
+#define SSL2_ST_GET_CLIENT_FINISHED_A          (0x50|SSL_ST_ACCEPT)\r
+#define SSL2_ST_GET_CLIENT_FINISHED_B          (0x51|SSL_ST_ACCEPT)\r
+#define SSL2_ST_SEND_SERVER_FINISHED_A         (0x60|SSL_ST_ACCEPT)\r
+#define SSL2_ST_SEND_SERVER_FINISHED_B         (0x61|SSL_ST_ACCEPT)\r
+#define SSL2_ST_SEND_REQUEST_CERTIFICATE_A     (0x70|SSL_ST_ACCEPT)\r
+#define SSL2_ST_SEND_REQUEST_CERTIFICATE_B     (0x71|SSL_ST_ACCEPT)\r
+#define SSL2_ST_SEND_REQUEST_CERTIFICATE_C     (0x72|SSL_ST_ACCEPT)\r
+#define SSL2_ST_SEND_REQUEST_CERTIFICATE_D     (0x73|SSL_ST_ACCEPT)\r
+#define SSL2_ST_SERVER_START_ENCRYPTION                (0x80|SSL_ST_ACCEPT)\r
+#define SSL2_ST_X509_GET_SERVER_CERTIFICATE    (0x90|SSL_ST_ACCEPT)\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ssl23.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ssl23.h
new file mode 100644 (file)
index 0000000..d322898
--- /dev/null
@@ -0,0 +1,83 @@
+/* ssl/ssl23.h */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ * 
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to.  The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ * 
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ * 
+ * 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 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    "This product includes cryptographic software written by
+ *     Eric Young (eay@cryptsoft.com)"
+ *    The word 'cryptographic' can be left out if the rouines from the library
+ *    being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from 
+ *    the apps directory (application code) you must include an acknowledgement:
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ * 
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 OR CONTRIBUTORS 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.
+ * 
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+#ifndef HEADER_SSL23_H 
+#define HEADER_SSL23_H 
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+/*client */
+/* write to server */
+#define SSL23_ST_CW_CLNT_HELLO_A       (0x210|SSL_ST_CONNECT)
+#define SSL23_ST_CW_CLNT_HELLO_B       (0x211|SSL_ST_CONNECT)
+/* read from server */
+#define SSL23_ST_CR_SRVR_HELLO_A       (0x220|SSL_ST_CONNECT)
+#define SSL23_ST_CR_SRVR_HELLO_B       (0x221|SSL_ST_CONNECT)
+
+/* server */
+/* read from client */
+#define SSL23_ST_SR_CLNT_HELLO_A       (0x210|SSL_ST_ACCEPT)
+#define SSL23_ST_SR_CLNT_HELLO_B       (0x211|SSL_ST_ACCEPT)
+
+#ifdef  __cplusplus
+}
+#endif
+#endif
+
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ssl3.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ssl3.h
new file mode 100644 (file)
index 0000000..f2ddcb2
--- /dev/null
@@ -0,0 +1,551 @@
+/* ssl/ssl3.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+/* ====================================================================\r
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.\r
+ * ECC cipher suite support in OpenSSL originally developed by \r
+ * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.\r
+ */\r
+\r
+#ifndef HEADER_SSL3_H \r
+#define HEADER_SSL3_H \r
+\r
+#ifndef OPENSSL_NO_COMP\r
+#include <openssl/comp.h>\r
+#endif\r
+#include <openssl/buffer.h>\r
+#include <openssl/evp.h>\r
+#include <openssl/ssl.h>\r
+#include <openssl/pq_compat.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define SSL3_CK_RSA_NULL_MD5                   0x03000001\r
+#define SSL3_CK_RSA_NULL_SHA                   0x03000002\r
+#define SSL3_CK_RSA_RC4_40_MD5                         0x03000003\r
+#define SSL3_CK_RSA_RC4_128_MD5                        0x03000004\r
+#define SSL3_CK_RSA_RC4_128_SHA                        0x03000005\r
+#define SSL3_CK_RSA_RC2_40_MD5                 0x03000006\r
+#define SSL3_CK_RSA_IDEA_128_SHA               0x03000007\r
+#define SSL3_CK_RSA_DES_40_CBC_SHA             0x03000008\r
+#define SSL3_CK_RSA_DES_64_CBC_SHA             0x03000009\r
+#define SSL3_CK_RSA_DES_192_CBC3_SHA           0x0300000A\r
+\r
+#define SSL3_CK_DH_DSS_DES_40_CBC_SHA          0x0300000B\r
+#define SSL3_CK_DH_DSS_DES_64_CBC_SHA          0x0300000C\r
+#define SSL3_CK_DH_DSS_DES_192_CBC3_SHA        0x0300000D\r
+#define SSL3_CK_DH_RSA_DES_40_CBC_SHA          0x0300000E\r
+#define SSL3_CK_DH_RSA_DES_64_CBC_SHA          0x0300000F\r
+#define SSL3_CK_DH_RSA_DES_192_CBC3_SHA        0x03000010\r
+\r
+#define SSL3_CK_EDH_DSS_DES_40_CBC_SHA         0x03000011\r
+#define SSL3_CK_EDH_DSS_DES_64_CBC_SHA         0x03000012\r
+#define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA       0x03000013\r
+#define SSL3_CK_EDH_RSA_DES_40_CBC_SHA         0x03000014\r
+#define SSL3_CK_EDH_RSA_DES_64_CBC_SHA         0x03000015\r
+#define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA       0x03000016\r
+\r
+#define SSL3_CK_ADH_RC4_40_MD5                 0x03000017\r
+#define SSL3_CK_ADH_RC4_128_MD5                        0x03000018\r
+#define SSL3_CK_ADH_DES_40_CBC_SHA             0x03000019\r
+#define SSL3_CK_ADH_DES_64_CBC_SHA             0x0300001A\r
+#define SSL3_CK_ADH_DES_192_CBC_SHA            0x0300001B\r
+\r
+#define SSL3_CK_FZA_DMS_NULL_SHA               0x0300001C\r
+#define SSL3_CK_FZA_DMS_FZA_SHA                        0x0300001D\r
+#if 0 /* Because it clashes with KRB5, is never used any more, and is safe\r
+        to remove according to David Hopwood <david.hopwood@zetnet.co.uk>\r
+        of the ietf-tls list */\r
+#define SSL3_CK_FZA_DMS_RC4_SHA                        0x0300001E\r
+#endif\r
+\r
+/*    VRS Additional Kerberos5 entries\r
+ */\r
+#define SSL3_CK_KRB5_DES_64_CBC_SHA            0x0300001E\r
+#define SSL3_CK_KRB5_DES_192_CBC3_SHA          0x0300001F\r
+#define SSL3_CK_KRB5_RC4_128_SHA               0x03000020\r
+#define SSL3_CK_KRB5_IDEA_128_CBC_SHA          0x03000021\r
+#define SSL3_CK_KRB5_DES_64_CBC_MD5            0x03000022\r
+#define SSL3_CK_KRB5_DES_192_CBC3_MD5          0x03000023\r
+#define SSL3_CK_KRB5_RC4_128_MD5               0x03000024\r
+#define SSL3_CK_KRB5_IDEA_128_CBC_MD5          0x03000025\r
+\r
+#define SSL3_CK_KRB5_DES_40_CBC_SHA            0x03000026\r
+#define SSL3_CK_KRB5_RC2_40_CBC_SHA            0x03000027\r
+#define SSL3_CK_KRB5_RC4_40_SHA                        0x03000028\r
+#define SSL3_CK_KRB5_DES_40_CBC_MD5            0x03000029\r
+#define SSL3_CK_KRB5_RC2_40_CBC_MD5            0x0300002A\r
+#define SSL3_CK_KRB5_RC4_40_MD5                        0x0300002B\r
+\r
+#define SSL3_TXT_RSA_NULL_MD5                  "NULL-MD5"\r
+#define SSL3_TXT_RSA_NULL_SHA                  "NULL-SHA"\r
+#define SSL3_TXT_RSA_RC4_40_MD5                "EXP-RC4-MD5"\r
+#define SSL3_TXT_RSA_RC4_128_MD5               "RC4-MD5"\r
+#define SSL3_TXT_RSA_RC4_128_SHA               "RC4-SHA"\r
+#define SSL3_TXT_RSA_RC2_40_MD5                        "EXP-RC2-CBC-MD5"\r
+#define SSL3_TXT_RSA_IDEA_128_SHA              "IDEA-CBC-SHA"\r
+#define SSL3_TXT_RSA_DES_40_CBC_SHA            "EXP-DES-CBC-SHA"\r
+#define SSL3_TXT_RSA_DES_64_CBC_SHA            "DES-CBC-SHA"\r
+#define SSL3_TXT_RSA_DES_192_CBC3_SHA          "DES-CBC3-SHA"\r
+\r
+#define SSL3_TXT_DH_DSS_DES_40_CBC_SHA         "EXP-DH-DSS-DES-CBC-SHA"\r
+#define SSL3_TXT_DH_DSS_DES_64_CBC_SHA         "DH-DSS-DES-CBC-SHA"\r
+#define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA       "DH-DSS-DES-CBC3-SHA"\r
+#define SSL3_TXT_DH_RSA_DES_40_CBC_SHA         "EXP-DH-RSA-DES-CBC-SHA"\r
+#define SSL3_TXT_DH_RSA_DES_64_CBC_SHA         "DH-RSA-DES-CBC-SHA"\r
+#define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA       "DH-RSA-DES-CBC3-SHA"\r
+\r
+#define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA                "EXP-EDH-DSS-DES-CBC-SHA"\r
+#define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA                "EDH-DSS-DES-CBC-SHA"\r
+#define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA      "EDH-DSS-DES-CBC3-SHA"\r
+#define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA                "EXP-EDH-RSA-DES-CBC-SHA"\r
+#define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA                "EDH-RSA-DES-CBC-SHA"\r
+#define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA      "EDH-RSA-DES-CBC3-SHA"\r
+\r
+#define SSL3_TXT_ADH_RC4_40_MD5                        "EXP-ADH-RC4-MD5"\r
+#define SSL3_TXT_ADH_RC4_128_MD5               "ADH-RC4-MD5"\r
+#define SSL3_TXT_ADH_DES_40_CBC_SHA            "EXP-ADH-DES-CBC-SHA"\r
+#define SSL3_TXT_ADH_DES_64_CBC_SHA            "ADH-DES-CBC-SHA"\r
+#define SSL3_TXT_ADH_DES_192_CBC_SHA           "ADH-DES-CBC3-SHA"\r
+\r
+#define SSL3_TXT_FZA_DMS_NULL_SHA              "FZA-NULL-SHA"\r
+#define SSL3_TXT_FZA_DMS_FZA_SHA               "FZA-FZA-CBC-SHA"\r
+#define SSL3_TXT_FZA_DMS_RC4_SHA               "FZA-RC4-SHA"\r
+\r
+#define SSL3_TXT_KRB5_DES_64_CBC_SHA           "KRB5-DES-CBC-SHA"\r
+#define SSL3_TXT_KRB5_DES_192_CBC3_SHA         "KRB5-DES-CBC3-SHA"\r
+#define SSL3_TXT_KRB5_RC4_128_SHA              "KRB5-RC4-SHA"\r
+#define SSL3_TXT_KRB5_IDEA_128_CBC_SHA         "KRB5-IDEA-CBC-SHA"\r
+#define SSL3_TXT_KRB5_DES_64_CBC_MD5           "KRB5-DES-CBC-MD5"\r
+#define SSL3_TXT_KRB5_DES_192_CBC3_MD5         "KRB5-DES-CBC3-MD5"\r
+#define SSL3_TXT_KRB5_RC4_128_MD5              "KRB5-RC4-MD5"\r
+#define SSL3_TXT_KRB5_IDEA_128_CBC_MD5                 "KRB5-IDEA-CBC-MD5"\r
+\r
+#define SSL3_TXT_KRB5_DES_40_CBC_SHA           "EXP-KRB5-DES-CBC-SHA"\r
+#define SSL3_TXT_KRB5_RC2_40_CBC_SHA           "EXP-KRB5-RC2-CBC-SHA"\r
+#define SSL3_TXT_KRB5_RC4_40_SHA               "EXP-KRB5-RC4-SHA"\r
+#define SSL3_TXT_KRB5_DES_40_CBC_MD5           "EXP-KRB5-DES-CBC-MD5"\r
+#define SSL3_TXT_KRB5_RC2_40_CBC_MD5           "EXP-KRB5-RC2-CBC-MD5"\r
+#define SSL3_TXT_KRB5_RC4_40_MD5               "EXP-KRB5-RC4-MD5"\r
+\r
+#define SSL3_SSL_SESSION_ID_LENGTH             32\r
+#define SSL3_MAX_SSL_SESSION_ID_LENGTH         32\r
+\r
+#define SSL3_MASTER_SECRET_SIZE                        48\r
+#define SSL3_RANDOM_SIZE                       32\r
+#define SSL3_SESSION_ID_SIZE                   32\r
+#define SSL3_RT_HEADER_LENGTH                  5\r
+\r
+/* Due to MS stuffing up, this can change.... */\r
+#if defined(OPENSSL_SYS_WIN16) || \\r
+       (defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32))\r
+#define SSL3_RT_MAX_EXTRA                      (14000)\r
+#else\r
+#define SSL3_RT_MAX_EXTRA                      (16384)\r
+#endif\r
+\r
+#define SSL3_RT_MAX_PLAIN_LENGTH               16384\r
+#define SSL3_RT_MAX_COMPRESSED_LENGTH  (1024+SSL3_RT_MAX_PLAIN_LENGTH)\r
+#define SSL3_RT_MAX_ENCRYPTED_LENGTH   (1024+SSL3_RT_MAX_COMPRESSED_LENGTH)\r
+#define SSL3_RT_MAX_PACKET_SIZE                (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH)\r
+#define SSL3_RT_MAX_DATA_SIZE                  (1024*1024)\r
+\r
+#define SSL3_MD_CLIENT_FINISHED_CONST  "\x43\x4C\x4E\x54"\r
+#define SSL3_MD_SERVER_FINISHED_CONST  "\x53\x52\x56\x52"\r
+\r
+#define SSL3_VERSION                   0x0300\r
+#define SSL3_VERSION_MAJOR             0x03\r
+#define SSL3_VERSION_MINOR             0x00\r
+\r
+#define SSL3_RT_CHANGE_CIPHER_SPEC     20\r
+#define SSL3_RT_ALERT                  21\r
+#define SSL3_RT_HANDSHAKE              22\r
+#define SSL3_RT_APPLICATION_DATA       23\r
+\r
+#define SSL3_AL_WARNING                        1\r
+#define SSL3_AL_FATAL                  2\r
+\r
+#define SSL3_AD_CLOSE_NOTIFY            0\r
+#define SSL3_AD_UNEXPECTED_MESSAGE     10      /* fatal */\r
+#define SSL3_AD_BAD_RECORD_MAC         20      /* fatal */\r
+#define SSL3_AD_DECOMPRESSION_FAILURE  30      /* fatal */\r
+#define SSL3_AD_HANDSHAKE_FAILURE      40      /* fatal */\r
+#define SSL3_AD_NO_CERTIFICATE         41\r
+#define SSL3_AD_BAD_CERTIFICATE                42\r
+#define SSL3_AD_UNSUPPORTED_CERTIFICATE        43\r
+#define SSL3_AD_CERTIFICATE_REVOKED    44\r
+#define SSL3_AD_CERTIFICATE_EXPIRED    45\r
+#define SSL3_AD_CERTIFICATE_UNKNOWN    46\r
+#define SSL3_AD_ILLEGAL_PARAMETER      47      /* fatal */\r
+\r
+typedef struct ssl3_record_st\r
+       {\r
+/*r */ int type;               /* type of record */\r
+/*rw*/ unsigned int length;    /* How many bytes available */\r
+/*r */ unsigned int off;       /* read/write offset into 'buf' */\r
+/*rw*/ unsigned char *data;    /* pointer to the record data */\r
+/*rw*/ unsigned char *input;   /* where the decode bytes are */\r
+/*r */ unsigned char *comp;    /* only used with decompression - malloc()ed */\r
+/*r */  unsigned long epoch;    /* epoch number, needed by DTLS1 */\r
+/*r */  PQ_64BIT seq_num;       /* sequence number, needed by DTLS1 */\r
+       } SSL3_RECORD;\r
+\r
+typedef struct ssl3_buffer_st\r
+       {\r
+       unsigned char *buf;     /* at least SSL3_RT_MAX_PACKET_SIZE bytes,\r
+                                * see ssl3_setup_buffers() */\r
+       size_t len;             /* buffer size */\r
+       int offset;             /* where to 'copy from' */\r
+       int left;               /* how many bytes left */\r
+       } SSL3_BUFFER;\r
+\r
+#define SSL3_CT_RSA_SIGN                       1\r
+#define SSL3_CT_DSS_SIGN                       2\r
+#define SSL3_CT_RSA_FIXED_DH                   3\r
+#define SSL3_CT_DSS_FIXED_DH                   4\r
+#define SSL3_CT_RSA_EPHEMERAL_DH               5\r
+#define SSL3_CT_DSS_EPHEMERAL_DH               6\r
+#define SSL3_CT_FORTEZZA_DMS                   20\r
+/* SSL3_CT_NUMBER is used to size arrays and it must be large\r
+ * enough to contain all of the cert types defined either for\r
+ * SSLv3 and TLSv1.\r
+ */\r
+#define SSL3_CT_NUMBER                 7\r
+\r
+\r
+#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS      0x0001\r
+#define SSL3_FLAGS_DELAY_CLIENT_FINISHED       0x0002\r
+#define SSL3_FLAGS_POP_BUFFER                  0x0004\r
+#define TLS1_FLAGS_TLS_PADDING_BUG             0x0008\r
+\r
+typedef struct ssl3_state_st\r
+       {\r
+       long flags;\r
+       int delay_buf_pop_ret;\r
+\r
+       unsigned char read_sequence[8];\r
+       unsigned char read_mac_secret[EVP_MAX_MD_SIZE];\r
+       unsigned char write_sequence[8];\r
+       unsigned char write_mac_secret[EVP_MAX_MD_SIZE];\r
+\r
+       unsigned char server_random[SSL3_RANDOM_SIZE];\r
+       unsigned char client_random[SSL3_RANDOM_SIZE];\r
+\r
+       /* flags for countermeasure against known-IV weakness */\r
+       int need_empty_fragments;\r
+       int empty_fragment_done;\r
+\r
+       SSL3_BUFFER rbuf;       /* read IO goes into here */\r
+       SSL3_BUFFER wbuf;       /* write IO goes into here */\r
+\r
+       SSL3_RECORD rrec;       /* each decoded record goes in here */\r
+       SSL3_RECORD wrec;       /* goes out from here */\r
+\r
+       /* storage for Alert/Handshake protocol data received but not\r
+        * yet processed by ssl3_read_bytes: */\r
+       unsigned char alert_fragment[2];\r
+       unsigned int alert_fragment_len;\r
+       unsigned char handshake_fragment[4];\r
+       unsigned int handshake_fragment_len;\r
+\r
+       /* partial write - check the numbers match */\r
+       unsigned int wnum;      /* number of bytes sent so far */\r
+       int wpend_tot;          /* number bytes written */\r
+       int wpend_type;\r
+       int wpend_ret;          /* number of bytes submitted */\r
+       const unsigned char *wpend_buf;\r
+\r
+       /* used during startup, digest all incoming/outgoing packets */\r
+       EVP_MD_CTX finish_dgst1;\r
+       EVP_MD_CTX finish_dgst2;\r
+\r
+       /* this is set whenerver we see a change_cipher_spec message\r
+        * come in when we are not looking for one */\r
+       int change_cipher_spec;\r
+\r
+       int warn_alert;\r
+       int fatal_alert;\r
+       /* we allow one fatal and one warning alert to be outstanding,\r
+        * send close alert via the warning alert */\r
+       int alert_dispatch;\r
+       unsigned char send_alert[2];\r
+\r
+       /* This flag is set when we should renegotiate ASAP, basically when\r
+        * there is no more data in the read or write buffers */\r
+       int renegotiate;\r
+       int total_renegotiations;\r
+       int num_renegotiations;\r
+\r
+       int in_read_app_data;\r
+\r
+       struct  {\r
+               /* actually only needs to be 16+20 */\r
+               unsigned char cert_verify_md[EVP_MAX_MD_SIZE*2];\r
+\r
+               /* actually only need to be 16+20 for SSLv3 and 12 for TLS */\r
+               unsigned char finish_md[EVP_MAX_MD_SIZE*2];\r
+               int finish_md_len;\r
+               unsigned char peer_finish_md[EVP_MAX_MD_SIZE*2];\r
+               int peer_finish_md_len;\r
+               \r
+               unsigned long message_size;\r
+               int message_type;\r
+\r
+               /* used to hold the new cipher we are going to use */\r
+               SSL_CIPHER *new_cipher;\r
+#ifndef OPENSSL_NO_DH\r
+               DH *dh;\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_ECDH\r
+               EC_KEY *ecdh; /* holds short lived ECDH key */\r
+#endif\r
+\r
+               /* used when SSL_ST_FLUSH_DATA is entered */\r
+               int next_state;                 \r
+\r
+               int reuse_message;\r
+\r
+               /* used for certificate requests */\r
+               int cert_req;\r
+               int ctype_num;\r
+               char ctype[SSL3_CT_NUMBER];\r
+               STACK_OF(X509_NAME) *ca_names;\r
+\r
+               int use_rsa_tmp;\r
+\r
+               int key_block_length;\r
+               unsigned char *key_block;\r
+\r
+               const EVP_CIPHER *new_sym_enc;\r
+               const EVP_MD *new_hash;\r
+#ifndef OPENSSL_NO_COMP\r
+               const SSL_COMP *new_compression;\r
+#else\r
+               char *new_compression;\r
+#endif\r
+               int cert_request;\r
+               } tmp;\r
+\r
+       } SSL3_STATE;\r
+\r
+\r
+/* SSLv3 */\r
+/*client */\r
+/* extra state */\r
+#define SSL3_ST_CW_FLUSH               (0x100|SSL_ST_CONNECT)\r
+/* write to server */\r
+#define SSL3_ST_CW_CLNT_HELLO_A                (0x110|SSL_ST_CONNECT)\r
+#define SSL3_ST_CW_CLNT_HELLO_B                (0x111|SSL_ST_CONNECT)\r
+/* read from server */\r
+#define SSL3_ST_CR_SRVR_HELLO_A                (0x120|SSL_ST_CONNECT)\r
+#define SSL3_ST_CR_SRVR_HELLO_B                (0x121|SSL_ST_CONNECT)\r
+#define DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A (0x126|SSL_ST_CONNECT)\r
+#define DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B (0x127|SSL_ST_CONNECT)\r
+#define SSL3_ST_CR_CERT_A              (0x130|SSL_ST_CONNECT)\r
+#define SSL3_ST_CR_CERT_B              (0x131|SSL_ST_CONNECT)\r
+#define SSL3_ST_CR_KEY_EXCH_A          (0x140|SSL_ST_CONNECT)\r
+#define SSL3_ST_CR_KEY_EXCH_B          (0x141|SSL_ST_CONNECT)\r
+#define SSL3_ST_CR_CERT_REQ_A          (0x150|SSL_ST_CONNECT)\r
+#define SSL3_ST_CR_CERT_REQ_B          (0x151|SSL_ST_CONNECT)\r
+#define SSL3_ST_CR_SRVR_DONE_A         (0x160|SSL_ST_CONNECT)\r
+#define SSL3_ST_CR_SRVR_DONE_B         (0x161|SSL_ST_CONNECT)\r
+/* write to server */\r
+#define SSL3_ST_CW_CERT_A              (0x170|SSL_ST_CONNECT)\r
+#define SSL3_ST_CW_CERT_B              (0x171|SSL_ST_CONNECT)\r
+#define SSL3_ST_CW_CERT_C              (0x172|SSL_ST_CONNECT)\r
+#define SSL3_ST_CW_CERT_D              (0x173|SSL_ST_CONNECT)\r
+#define SSL3_ST_CW_KEY_EXCH_A          (0x180|SSL_ST_CONNECT)\r
+#define SSL3_ST_CW_KEY_EXCH_B          (0x181|SSL_ST_CONNECT)\r
+#define SSL3_ST_CW_CERT_VRFY_A         (0x190|SSL_ST_CONNECT)\r
+#define SSL3_ST_CW_CERT_VRFY_B         (0x191|SSL_ST_CONNECT)\r
+#define SSL3_ST_CW_CHANGE_A            (0x1A0|SSL_ST_CONNECT)\r
+#define SSL3_ST_CW_CHANGE_B            (0x1A1|SSL_ST_CONNECT)\r
+#define SSL3_ST_CW_FINISHED_A          (0x1B0|SSL_ST_CONNECT)\r
+#define SSL3_ST_CW_FINISHED_B          (0x1B1|SSL_ST_CONNECT)\r
+/* read from server */\r
+#define SSL3_ST_CR_CHANGE_A            (0x1C0|SSL_ST_CONNECT)\r
+#define SSL3_ST_CR_CHANGE_B            (0x1C1|SSL_ST_CONNECT)\r
+#define SSL3_ST_CR_FINISHED_A          (0x1D0|SSL_ST_CONNECT)\r
+#define SSL3_ST_CR_FINISHED_B          (0x1D1|SSL_ST_CONNECT)\r
+\r
+/* server */\r
+/* extra state */\r
+#define SSL3_ST_SW_FLUSH               (0x100|SSL_ST_ACCEPT)\r
+/* read from client */\r
+/* Do not change the number values, they do matter */\r
+#define SSL3_ST_SR_CLNT_HELLO_A                (0x110|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SR_CLNT_HELLO_B                (0x111|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SR_CLNT_HELLO_C                (0x112|SSL_ST_ACCEPT)\r
+/* write to client */\r
+#define DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A (0x113|SSL_ST_ACCEPT)\r
+#define DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B (0x114|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_HELLO_REQ_A         (0x120|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_HELLO_REQ_B         (0x121|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_HELLO_REQ_C         (0x122|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_SRVR_HELLO_A                (0x130|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_SRVR_HELLO_B                (0x131|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_CERT_A              (0x140|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_CERT_B              (0x141|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_KEY_EXCH_A          (0x150|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_KEY_EXCH_B          (0x151|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_CERT_REQ_A          (0x160|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_CERT_REQ_B          (0x161|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_SRVR_DONE_A         (0x170|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_SRVR_DONE_B         (0x171|SSL_ST_ACCEPT)\r
+/* read from client */\r
+#define SSL3_ST_SR_CERT_A              (0x180|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SR_CERT_B              (0x181|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SR_KEY_EXCH_A          (0x190|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SR_KEY_EXCH_B          (0x191|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SR_CERT_VRFY_A         (0x1A0|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SR_CERT_VRFY_B         (0x1A1|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SR_CHANGE_A            (0x1B0|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SR_CHANGE_B            (0x1B1|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SR_FINISHED_A          (0x1C0|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SR_FINISHED_B          (0x1C1|SSL_ST_ACCEPT)\r
+/* write to client */\r
+#define SSL3_ST_SW_CHANGE_A            (0x1D0|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_CHANGE_B            (0x1D1|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_FINISHED_A          (0x1E0|SSL_ST_ACCEPT)\r
+#define SSL3_ST_SW_FINISHED_B          (0x1E1|SSL_ST_ACCEPT)\r
+\r
+#define SSL3_MT_HELLO_REQUEST                  0\r
+#define SSL3_MT_CLIENT_HELLO                   1\r
+#define SSL3_MT_SERVER_HELLO                   2\r
+#define SSL3_MT_CERTIFICATE                    11\r
+#define SSL3_MT_SERVER_KEY_EXCHANGE            12\r
+#define SSL3_MT_CERTIFICATE_REQUEST            13\r
+#define SSL3_MT_SERVER_DONE                    14\r
+#define SSL3_MT_CERTIFICATE_VERIFY             15\r
+#define SSL3_MT_CLIENT_KEY_EXCHANGE            16\r
+#define SSL3_MT_FINISHED                       20\r
+#define DTLS1_MT_HELLO_VERIFY_REQUEST    3\r
+\r
+\r
+#define SSL3_MT_CCS                            1\r
+\r
+/* These are used when changing over to a new cipher */\r
+#define SSL3_CC_READ           0x01\r
+#define SSL3_CC_WRITE          0x02\r
+#define SSL3_CC_CLIENT         0x10\r
+#define SSL3_CC_SERVER         0x20\r
+#define SSL3_CHANGE_CIPHER_CLIENT_WRITE        (SSL3_CC_CLIENT|SSL3_CC_WRITE)  \r
+#define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ)\r
+#define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ)\r
+#define SSL3_CHANGE_CIPHER_SERVER_WRITE        (SSL3_CC_SERVER|SSL3_CC_WRITE)\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/stack.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/stack.h
new file mode 100644 (file)
index 0000000..5cbb116
--- /dev/null
@@ -0,0 +1,109 @@
+/* crypto/stack/stack.h */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ * 
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to.  The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ * 
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ * 
+ * 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 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    "This product includes cryptographic software written by
+ *     Eric Young (eay@cryptsoft.com)"
+ *    The word 'cryptographic' can be left out if the rouines from the library
+ *    being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from 
+ *    the apps directory (application code) you must include an acknowledgement:
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ * 
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 OR CONTRIBUTORS 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.
+ * 
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+#ifndef HEADER_STACK_H
+#define HEADER_STACK_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+typedef struct stack_st
+       {
+       int num;
+       char **data;
+       int sorted;
+
+       int num_alloc;
+       int (*comp)(const char * const *, const char * const *);
+       } STACK;
+
+#define M_sk_num(sk)           ((sk) ? (sk)->num:-1)
+#define M_sk_value(sk,n)       ((sk) ? (sk)->data[n] : NULL)
+
+int sk_num(const STACK *);
+char *sk_value(const STACK *, int);
+
+char *sk_set(STACK *, int, char *);
+
+STACK *sk_new(int (*cmp)(const char * const *, const char * const *));
+STACK *sk_new_null(void);
+void sk_free(STACK *);
+void sk_pop_free(STACK *st, void (*func)(void *));
+int sk_insert(STACK *sk,char *data,int where);
+char *sk_delete(STACK *st,int loc);
+char *sk_delete_ptr(STACK *st, char *p);
+int sk_find(STACK *st,char *data);
+int sk_find_ex(STACK *st,char *data);
+int sk_push(STACK *st,char *data);
+int sk_unshift(STACK *st,char *data);
+char *sk_shift(STACK *st);
+char *sk_pop(STACK *st);
+void sk_zero(STACK *st);
+int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,
+                       const char * const *)))
+                       (const char * const *, const char * const *);
+STACK *sk_dup(STACK *st);
+void sk_sort(STACK *st);
+int sk_is_sorted(const STACK *st);
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/store.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/store.h
new file mode 100644 (file)
index 0000000..9665d0d
--- /dev/null
@@ -0,0 +1,554 @@
+/* crypto/store/store.h -*- mode:C; c-file-style: "eay" -*- */\r
+/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL\r
+ * project 2003.\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 2003 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_STORE_H\r
+#define HEADER_STORE_H\r
+\r
+#include <openssl/ossl_typ.h>\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#include <openssl/evp.h>\r
+#include <openssl/bn.h>\r
+#include <openssl/x509.h>\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Already defined in ossl_typ.h */\r
+/* typedef struct store_st STORE; */\r
+/* typedef struct store_method_st STORE_METHOD; */\r
+\r
+\r
+/* All the following functions return 0, a negative number or NULL on error.\r
+   When everything is fine, they return a positive value or a non-NULL\r
+   pointer, all depending on their purpose. */\r
+\r
+/* Creators and destructor.   */\r
+STORE *STORE_new_method(const STORE_METHOD *method);\r
+STORE *STORE_new_engine(ENGINE *engine);\r
+void STORE_free(STORE *ui);\r
+\r
+\r
+/* Give a user interface parametrised control commands.  This can be used to\r
+   send down an integer, a data pointer or a function pointer, as well as\r
+   be used to get information from a STORE. */\r
+int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f)(void));\r
+\r
+/* A control to set the directory with keys and certificates.  Used by the\r
+   built-in directory level method. */\r
+#define STORE_CTRL_SET_DIRECTORY       0x0001\r
+/* A control to set a file to load.  Used by the built-in file level method. */\r
+#define STORE_CTRL_SET_FILE            0x0002\r
+/* A control to set a configuration file to load.  Can be used by any method\r
+   that wishes to load a configuration file. */\r
+#define STORE_CTRL_SET_CONF_FILE       0x0003\r
+/* A control to set a the section of the loaded configuration file.  Can be\r
+   used by any method that wishes to load a configuration file. */\r
+#define STORE_CTRL_SET_CONF_SECTION    0x0004\r
+\r
+\r
+/* Some methods may use extra data */\r
+#define STORE_set_app_data(s,arg)      STORE_set_ex_data(s,0,arg)\r
+#define STORE_get_app_data(s)          STORE_get_ex_data(s,0)\r
+int STORE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,\r
+       CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+int STORE_set_ex_data(STORE *r,int idx,void *arg);\r
+void *STORE_get_ex_data(STORE *r, int idx);\r
+\r
+/* Use specific methods instead of the built-in one */\r
+const STORE_METHOD *STORE_get_method(STORE *store);\r
+const STORE_METHOD *STORE_set_method(STORE *store, const STORE_METHOD *meth);\r
+\r
+/* The standard OpenSSL methods. */\r
+/* This is the in-memory method.  It does everything except revoking and updating,\r
+   and is of course volatile.  It's used by other methods that have an in-memory\r
+   cache. */\r
+const STORE_METHOD *STORE_Memory(void);\r
+#if 0 /* Not yet implemented */\r
+/* This is the directory store.  It does everything except revoking and updating,\r
+   and uses STORE_Memory() to cache things in memory. */\r
+const STORE_METHOD *STORE_Directory(void);\r
+/* This is the file store.  It does everything except revoking and updating,\r
+   and uses STORE_Memory() to cache things in memory.  Certificates are added\r
+   to it with the store operation, and it will only get cached certificates. */\r
+const STORE_METHOD *STORE_File(void);\r
+#endif\r
+\r
+/* Store functions take a type code for the type of data they should store\r
+   or fetch */\r
+typedef enum STORE_object_types\r
+       {\r
+       STORE_OBJECT_TYPE_X509_CERTIFICATE=     0x01, /* X509 * */\r
+       STORE_OBJECT_TYPE_X509_CRL=             0x02, /* X509_CRL * */\r
+       STORE_OBJECT_TYPE_PRIVATE_KEY=          0x03, /* EVP_PKEY * */\r
+       STORE_OBJECT_TYPE_PUBLIC_KEY=           0x04, /* EVP_PKEY * */\r
+       STORE_OBJECT_TYPE_NUMBER=               0x05, /* BIGNUM * */\r
+       STORE_OBJECT_TYPE_ARBITRARY=            0x06, /* BUF_MEM * */\r
+       STORE_OBJECT_TYPE_NUM=                  0x06  /* The amount of known\r
+                                                        object types */\r
+       } STORE_OBJECT_TYPES;\r
+/* List of text strings corresponding to the object types. */\r
+extern const char * const STORE_object_type_string[STORE_OBJECT_TYPE_NUM+1];\r
+\r
+/* Some store functions take a parameter list.  Those parameters come with\r
+   one of the following codes. The comments following the codes below indicate\r
+   what type the value should be a pointer to. */\r
+typedef enum STORE_params\r
+       {\r
+       STORE_PARAM_EVP_TYPE=                   0x01, /* int */\r
+       STORE_PARAM_BITS=                       0x02, /* size_t */\r
+       STORE_PARAM_KEY_PARAMETERS=             0x03, /* ??? */\r
+       STORE_PARAM_KEY_NO_PARAMETERS=          0x04, /* N/A */\r
+       STORE_PARAM_AUTH_PASSPHRASE=            0x05, /* char * */\r
+       STORE_PARAM_AUTH_KRB5_TICKET=           0x06, /* void * */\r
+       STORE_PARAM_TYPE_NUM=                   0x06  /* The amount of known\r
+                                                        parameter types */\r
+       } STORE_PARAM_TYPES;\r
+/* Parameter value sizes.  -1 means unknown, anything else is the required size. */\r
+extern const int STORE_param_sizes[STORE_PARAM_TYPE_NUM+1];\r
+\r
+/* Store functions take attribute lists.  Those attributes come with codes.\r
+   The comments following the codes below indicate what type the value should\r
+   be a pointer to. */\r
+typedef enum STORE_attribs\r
+       {\r
+       STORE_ATTR_END=                         0x00,\r
+       STORE_ATTR_FRIENDLYNAME=                0x01, /* C string */\r
+       STORE_ATTR_KEYID=                       0x02, /* 160 bit string (SHA1) */\r
+       STORE_ATTR_ISSUERKEYID=                 0x03, /* 160 bit string (SHA1) */\r
+       STORE_ATTR_SUBJECTKEYID=                0x04, /* 160 bit string (SHA1) */\r
+       STORE_ATTR_ISSUERSERIALHASH=            0x05, /* 160 bit string (SHA1) */\r
+       STORE_ATTR_ISSUER=                      0x06, /* X509_NAME * */\r
+       STORE_ATTR_SERIAL=                      0x07, /* BIGNUM * */\r
+       STORE_ATTR_SUBJECT=                     0x08, /* X509_NAME * */\r
+       STORE_ATTR_CERTHASH=                    0x09, /* 160 bit string (SHA1) */\r
+       STORE_ATTR_EMAIL=                       0x0a, /* C string */\r
+       STORE_ATTR_FILENAME=                    0x0b, /* C string */\r
+       STORE_ATTR_TYPE_NUM=                    0x0b, /* The amount of known\r
+                                                        attribute types */\r
+       STORE_ATTR_OR=                          0xff  /* This is a special\r
+                                                        separator, which\r
+                                                        expresses the OR\r
+                                                        operation.  */\r
+       } STORE_ATTR_TYPES;\r
+/* Attribute value sizes.  -1 means unknown, anything else is the required size. */\r
+extern const int STORE_attr_sizes[STORE_ATTR_TYPE_NUM+1];\r
+\r
+typedef enum STORE_certificate_status\r
+       {\r
+       STORE_X509_VALID=                       0x00,\r
+       STORE_X509_EXPIRED=                     0x01,\r
+       STORE_X509_SUSPENDED=                   0x02,\r
+       STORE_X509_REVOKED=                     0x03\r
+       } STORE_CERTIFICATE_STATUS;\r
+\r
+/* Engine store functions will return a structure that contains all the necessary\r
+ * information, including revokation status for certificates.  This is really not\r
+ * needed for application authors, as the ENGINE framework functions will extract\r
+ * the OpenSSL-specific information when at all possible.  However, for engine\r
+ * authors, it's crucial to know this structure.  */\r
+typedef struct STORE_OBJECT_st\r
+       {\r
+       STORE_OBJECT_TYPES type;\r
+       union\r
+               {\r
+               struct\r
+                       {\r
+                       STORE_CERTIFICATE_STATUS status;\r
+                       X509 *certificate;\r
+                       } x509;\r
+               X509_CRL *crl;\r
+               EVP_PKEY *key;\r
+               BIGNUM *number;\r
+               BUF_MEM *arbitrary;\r
+               } data;\r
+       } STORE_OBJECT;\r
+DECLARE_STACK_OF(STORE_OBJECT)\r
+STORE_OBJECT *STORE_OBJECT_new(void);\r
+void STORE_OBJECT_free(STORE_OBJECT *data);\r
+\r
+\r
+\r
+/* The following functions handle the storage. They return 0, a negative number\r
+   or NULL on error, anything else on success. */\r
+X509 *STORE_get_certificate(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_store_certificate(STORE *e, X509 *data, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_modify_certificate(STORE *e, OPENSSL_ITEM search_attributes[],\r
+       OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],\r
+       OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);\r
+int STORE_revoke_certificate(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_delete_certificate(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+void *STORE_list_certificate_start(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+X509 *STORE_list_certificate_next(STORE *e, void *handle);\r
+int STORE_list_certificate_end(STORE *e, void *handle);\r
+int STORE_list_certificate_endp(STORE *e, void *handle);\r
+EVP_PKEY *STORE_generate_key(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+EVP_PKEY *STORE_get_private_key(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_store_private_key(STORE *e, EVP_PKEY *data,\r
+       OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);\r
+int STORE_modify_private_key(STORE *e, OPENSSL_ITEM search_attributes[],\r
+       OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[],\r
+       OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);\r
+int STORE_revoke_private_key(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_delete_private_key(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+void *STORE_list_private_key_start(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+EVP_PKEY *STORE_list_private_key_next(STORE *e, void *handle);\r
+int STORE_list_private_key_end(STORE *e, void *handle);\r
+int STORE_list_private_key_endp(STORE *e, void *handle);\r
+EVP_PKEY *STORE_get_public_key(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_store_public_key(STORE *e, EVP_PKEY *data, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_modify_public_key(STORE *e, OPENSSL_ITEM search_attributes[],\r
+       OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[],\r
+       OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);\r
+int STORE_revoke_public_key(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_delete_public_key(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+void *STORE_list_public_key_start(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+EVP_PKEY *STORE_list_public_key_next(STORE *e, void *handle);\r
+int STORE_list_public_key_end(STORE *e, void *handle);\r
+int STORE_list_public_key_endp(STORE *e, void *handle);\r
+X509_CRL *STORE_generate_crl(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+X509_CRL *STORE_get_crl(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_store_crl(STORE *e, X509_CRL *data, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_modify_crl(STORE *e, OPENSSL_ITEM search_attributes[],\r
+       OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[],\r
+       OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);\r
+int STORE_delete_crl(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+void *STORE_list_crl_start(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+X509_CRL *STORE_list_crl_next(STORE *e, void *handle);\r
+int STORE_list_crl_end(STORE *e, void *handle);\r
+int STORE_list_crl_endp(STORE *e, void *handle);\r
+int STORE_store_number(STORE *e, BIGNUM *data, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_modify_number(STORE *e, OPENSSL_ITEM search_attributes[],\r
+       OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[],\r
+       OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);\r
+BIGNUM *STORE_get_number(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_delete_number(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_store_arbitrary(STORE *e, BUF_MEM *data, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_modify_arbitrary(STORE *e, OPENSSL_ITEM search_attributes[],\r
+       OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[],\r
+       OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);\r
+BUF_MEM *STORE_get_arbitrary(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+int STORE_delete_arbitrary(STORE *e, OPENSSL_ITEM attributes[],\r
+       OPENSSL_ITEM parameters[]);\r
+\r
+\r
+/* Create and manipulate methods */\r
+STORE_METHOD *STORE_create_method(char *name);\r
+void STORE_destroy_method(STORE_METHOD *store_method);\r
+\r
+/* These callback types are use for store handlers */\r
+typedef int (*STORE_INITIALISE_FUNC_PTR)(STORE *);\r
+typedef void (*STORE_CLEANUP_FUNC_PTR)(STORE *);\r
+typedef STORE_OBJECT *(*STORE_GENERATE_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);\r
+typedef STORE_OBJECT *(*STORE_GET_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);\r
+typedef void *(*STORE_START_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);\r
+typedef STORE_OBJECT *(*STORE_NEXT_OBJECT_FUNC_PTR)(STORE *, void *handle);\r
+typedef int (*STORE_END_OBJECT_FUNC_PTR)(STORE *, void *handle);\r
+typedef int (*STORE_HANDLE_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);\r
+typedef int (*STORE_STORE_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, STORE_OBJECT *data, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);\r
+typedef int (*STORE_MODIFY_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM search_attributes[], OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);\r
+typedef int (*STORE_GENERIC_FUNC_PTR)(STORE *, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);\r
+typedef int (*STORE_CTRL_FUNC_PTR)(STORE *, int cmd, long l, void *p, void (*f)(void));\r
+\r
+int STORE_method_set_initialise_function(STORE_METHOD *sm, STORE_INITIALISE_FUNC_PTR init_f);\r
+int STORE_method_set_cleanup_function(STORE_METHOD *sm, STORE_CLEANUP_FUNC_PTR clean_f);\r
+int STORE_method_set_generate_function(STORE_METHOD *sm, STORE_GENERATE_OBJECT_FUNC_PTR generate_f);\r
+int STORE_method_set_get_function(STORE_METHOD *sm, STORE_GET_OBJECT_FUNC_PTR get_f);\r
+int STORE_method_set_store_function(STORE_METHOD *sm, STORE_STORE_OBJECT_FUNC_PTR store_f);\r
+int STORE_method_set_modify_function(STORE_METHOD *sm, STORE_MODIFY_OBJECT_FUNC_PTR store_f);\r
+int STORE_method_set_revoke_function(STORE_METHOD *sm, STORE_HANDLE_OBJECT_FUNC_PTR revoke_f);\r
+int STORE_method_set_delete_function(STORE_METHOD *sm, STORE_HANDLE_OBJECT_FUNC_PTR delete_f);\r
+int STORE_method_set_list_start_function(STORE_METHOD *sm, STORE_START_OBJECT_FUNC_PTR list_start_f);\r
+int STORE_method_set_list_next_function(STORE_METHOD *sm, STORE_NEXT_OBJECT_FUNC_PTR list_next_f);\r
+int STORE_method_set_list_end_function(STORE_METHOD *sm, STORE_END_OBJECT_FUNC_PTR list_end_f);\r
+int STORE_method_set_update_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR);\r
+int STORE_method_set_lock_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR);\r
+int STORE_method_set_unlock_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR);\r
+int STORE_method_set_ctrl_function(STORE_METHOD *sm, STORE_CTRL_FUNC_PTR ctrl_f);\r
+\r
+STORE_INITIALISE_FUNC_PTR STORE_method_get_initialise_function(STORE_METHOD *sm);\r
+STORE_CLEANUP_FUNC_PTR STORE_method_get_cleanup_function(STORE_METHOD *sm);\r
+STORE_GENERATE_OBJECT_FUNC_PTR STORE_method_get_generate_function(STORE_METHOD *sm);\r
+STORE_GET_OBJECT_FUNC_PTR STORE_method_get_get_function(STORE_METHOD *sm);\r
+STORE_STORE_OBJECT_FUNC_PTR STORE_method_get_store_function(STORE_METHOD *sm);\r
+STORE_MODIFY_OBJECT_FUNC_PTR STORE_method_get_modify_function(STORE_METHOD *sm);\r
+STORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_revoke_function(STORE_METHOD *sm);\r
+STORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_delete_function(STORE_METHOD *sm);\r
+STORE_START_OBJECT_FUNC_PTR STORE_method_get_list_start_function(STORE_METHOD *sm);\r
+STORE_NEXT_OBJECT_FUNC_PTR STORE_method_get_list_next_function(STORE_METHOD *sm);\r
+STORE_END_OBJECT_FUNC_PTR STORE_method_get_list_end_function(STORE_METHOD *sm);\r
+STORE_GENERIC_FUNC_PTR STORE_method_get_update_store_function(STORE_METHOD *sm);\r
+STORE_GENERIC_FUNC_PTR STORE_method_get_lock_store_function(STORE_METHOD *sm);\r
+STORE_GENERIC_FUNC_PTR STORE_method_get_unlock_store_function(STORE_METHOD *sm);\r
+STORE_CTRL_FUNC_PTR STORE_method_get_ctrl_function(STORE_METHOD *sm);\r
+\r
+/* Method helper structures and functions. */\r
+\r
+/* This structure is the result of parsing through the information in a list\r
+   of OPENSSL_ITEMs.  It stores all the necessary information in a structured\r
+   way.*/\r
+typedef struct STORE_attr_info_st STORE_ATTR_INFO;\r
+\r
+/* Parse a list of OPENSSL_ITEMs and return a pointer to a STORE_ATTR_INFO.\r
+   Note that we do this in the list form, since the list of OPENSSL_ITEMs can\r
+   come in blocks separated with STORE_ATTR_OR.  Note that the value returned\r
+   by STORE_parse_attrs_next() must be freed with STORE_ATTR_INFO_free(). */\r
+void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes);\r
+STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle);\r
+int STORE_parse_attrs_end(void *handle);\r
+int STORE_parse_attrs_endp(void *handle);\r
+\r
+/* Creator and destructor */\r
+STORE_ATTR_INFO *STORE_ATTR_INFO_new(void);\r
+int STORE_ATTR_INFO_free(STORE_ATTR_INFO *attrs);\r
+\r
+/* Manipulators */\r
+char *STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code);\r
+unsigned char *STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO *attrs,\r
+       STORE_ATTR_TYPES code);\r
+X509_NAME *STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code);\r
+BIGNUM *STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code);\r
+int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,\r
+       char *cstr, size_t cstr_size);\r
+int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,\r
+       unsigned char *sha1str, size_t sha1str_size);\r
+int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,\r
+       X509_NAME *dn);\r
+int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,\r
+       BIGNUM *number);\r
+int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,\r
+       char *cstr, size_t cstr_size);\r
+int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,\r
+       unsigned char *sha1str, size_t sha1str_size);\r
+int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,\r
+       X509_NAME *dn);\r
+int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,\r
+       BIGNUM *number);\r
+\r
+/* Compare on basis of a bit pattern formed by the STORE_ATTR_TYPES values\r
+   in each contained attribute. */\r
+int STORE_ATTR_INFO_compare(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b);\r
+/* Check if the set of attributes in a is within the range of attributes\r
+   set in b. */\r
+int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b);\r
+/* Check if the set of attributes in a are also set in b. */\r
+int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b);\r
+/* Same as STORE_ATTR_INFO_in(), but also checks the attribute values. */\r
+int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b);\r
+\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_STORE_strings(void);\r
+\r
+/* Error codes for the STORE functions. */\r
+\r
+/* Function codes. */\r
+#define STORE_F_MEM_DELETE                              134\r
+#define STORE_F_MEM_GENERATE                            135\r
+#define STORE_F_MEM_LIST_END                            168\r
+#define STORE_F_MEM_LIST_NEXT                           136\r
+#define STORE_F_MEM_LIST_START                          137\r
+#define STORE_F_MEM_MODIFY                              169\r
+#define STORE_F_MEM_STORE                               138\r
+#define STORE_F_STORE_ATTR_INFO_GET0_CSTR               139\r
+#define STORE_F_STORE_ATTR_INFO_GET0_DN                         140\r
+#define STORE_F_STORE_ATTR_INFO_GET0_NUMBER             141\r
+#define STORE_F_STORE_ATTR_INFO_GET0_SHA1STR            142\r
+#define STORE_F_STORE_ATTR_INFO_MODIFY_CSTR             143\r
+#define STORE_F_STORE_ATTR_INFO_MODIFY_DN               144\r
+#define STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER           145\r
+#define STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR          146\r
+#define STORE_F_STORE_ATTR_INFO_SET_CSTR                147\r
+#define STORE_F_STORE_ATTR_INFO_SET_DN                  148\r
+#define STORE_F_STORE_ATTR_INFO_SET_NUMBER              149\r
+#define STORE_F_STORE_ATTR_INFO_SET_SHA1STR             150\r
+#define STORE_F_STORE_CERTIFICATE                       170\r
+#define STORE_F_STORE_CTRL                              161\r
+#define STORE_F_STORE_DELETE_ARBITRARY                  158\r
+#define STORE_F_STORE_DELETE_CERTIFICATE                102\r
+#define STORE_F_STORE_DELETE_CRL                        103\r
+#define STORE_F_STORE_DELETE_NUMBER                     104\r
+#define STORE_F_STORE_DELETE_PRIVATE_KEY                105\r
+#define STORE_F_STORE_DELETE_PUBLIC_KEY                         106\r
+#define STORE_F_STORE_GENERATE_CRL                      107\r
+#define STORE_F_STORE_GENERATE_KEY                      108\r
+#define STORE_F_STORE_GET_ARBITRARY                     159\r
+#define STORE_F_STORE_GET_CERTIFICATE                   109\r
+#define STORE_F_STORE_GET_CRL                           110\r
+#define STORE_F_STORE_GET_NUMBER                        111\r
+#define STORE_F_STORE_GET_PRIVATE_KEY                   112\r
+#define STORE_F_STORE_GET_PUBLIC_KEY                    113\r
+#define STORE_F_STORE_LIST_CERTIFICATE_END              114\r
+#define STORE_F_STORE_LIST_CERTIFICATE_ENDP             153\r
+#define STORE_F_STORE_LIST_CERTIFICATE_NEXT             115\r
+#define STORE_F_STORE_LIST_CERTIFICATE_START            116\r
+#define STORE_F_STORE_LIST_CRL_END                      117\r
+#define STORE_F_STORE_LIST_CRL_ENDP                     154\r
+#define STORE_F_STORE_LIST_CRL_NEXT                     118\r
+#define STORE_F_STORE_LIST_CRL_START                    119\r
+#define STORE_F_STORE_LIST_PRIVATE_KEY_END              120\r
+#define STORE_F_STORE_LIST_PRIVATE_KEY_ENDP             155\r
+#define STORE_F_STORE_LIST_PRIVATE_KEY_NEXT             121\r
+#define STORE_F_STORE_LIST_PRIVATE_KEY_START            122\r
+#define STORE_F_STORE_LIST_PUBLIC_KEY_END               123\r
+#define STORE_F_STORE_LIST_PUBLIC_KEY_ENDP              156\r
+#define STORE_F_STORE_LIST_PUBLIC_KEY_NEXT              124\r
+#define STORE_F_STORE_LIST_PUBLIC_KEY_START             125\r
+#define STORE_F_STORE_MODIFY_ARBITRARY                  162\r
+#define STORE_F_STORE_MODIFY_CERTIFICATE                163\r
+#define STORE_F_STORE_MODIFY_CRL                        164\r
+#define STORE_F_STORE_MODIFY_NUMBER                     165\r
+#define STORE_F_STORE_MODIFY_PRIVATE_KEY                166\r
+#define STORE_F_STORE_MODIFY_PUBLIC_KEY                         167\r
+#define STORE_F_STORE_NEW_ENGINE                        133\r
+#define STORE_F_STORE_NEW_METHOD                        132\r
+#define STORE_F_STORE_PARSE_ATTRS_END                   151\r
+#define STORE_F_STORE_PARSE_ATTRS_ENDP                  172\r
+#define STORE_F_STORE_PARSE_ATTRS_NEXT                  152\r
+#define STORE_F_STORE_PARSE_ATTRS_START                         171\r
+#define STORE_F_STORE_REVOKE_CERTIFICATE                129\r
+#define STORE_F_STORE_REVOKE_PRIVATE_KEY                130\r
+#define STORE_F_STORE_REVOKE_PUBLIC_KEY                         131\r
+#define STORE_F_STORE_STORE_ARBITRARY                   157\r
+#define STORE_F_STORE_STORE_CERTIFICATE                         100\r
+#define STORE_F_STORE_STORE_CRL                                 101\r
+#define STORE_F_STORE_STORE_NUMBER                      126\r
+#define STORE_F_STORE_STORE_PRIVATE_KEY                         127\r
+#define STORE_F_STORE_STORE_PUBLIC_KEY                  128\r
+\r
+/* Reason codes. */\r
+#define STORE_R_ALREADY_HAS_A_VALUE                     127\r
+#define STORE_R_FAILED_DELETING_ARBITRARY               132\r
+#define STORE_R_FAILED_DELETING_CERTIFICATE             100\r
+#define STORE_R_FAILED_DELETING_KEY                     101\r
+#define STORE_R_FAILED_DELETING_NUMBER                  102\r
+#define STORE_R_FAILED_GENERATING_CRL                   103\r
+#define STORE_R_FAILED_GENERATING_KEY                   104\r
+#define STORE_R_FAILED_GETTING_ARBITRARY                133\r
+#define STORE_R_FAILED_GETTING_CERTIFICATE              105\r
+#define STORE_R_FAILED_GETTING_KEY                      106\r
+#define STORE_R_FAILED_GETTING_NUMBER                   107\r
+#define STORE_R_FAILED_LISTING_CERTIFICATES             108\r
+#define STORE_R_FAILED_LISTING_KEYS                     109\r
+#define STORE_R_FAILED_MODIFYING_ARBITRARY              138\r
+#define STORE_R_FAILED_MODIFYING_CERTIFICATE            139\r
+#define STORE_R_FAILED_MODIFYING_CRL                    140\r
+#define STORE_R_FAILED_MODIFYING_NUMBER                         141\r
+#define STORE_R_FAILED_MODIFYING_PRIVATE_KEY            142\r
+#define STORE_R_FAILED_MODIFYING_PUBLIC_KEY             143\r
+#define STORE_R_FAILED_REVOKING_CERTIFICATE             110\r
+#define STORE_R_FAILED_REVOKING_KEY                     111\r
+#define STORE_R_FAILED_STORING_ARBITRARY                134\r
+#define STORE_R_FAILED_STORING_CERTIFICATE              112\r
+#define STORE_R_FAILED_STORING_KEY                      113\r
+#define STORE_R_FAILED_STORING_NUMBER                   114\r
+#define STORE_R_NOT_IMPLEMENTED                                 128\r
+#define STORE_R_NO_CONTROL_FUNCTION                     144\r
+#define STORE_R_NO_DELETE_ARBITRARY_FUNCTION            135\r
+#define STORE_R_NO_DELETE_NUMBER_FUNCTION               115\r
+#define STORE_R_NO_DELETE_OBJECT_FUNCTION               116\r
+#define STORE_R_NO_GENERATE_CRL_FUNCTION                117\r
+#define STORE_R_NO_GENERATE_OBJECT_FUNCTION             118\r
+#define STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION        136\r
+#define STORE_R_NO_GET_OBJECT_FUNCTION                  119\r
+#define STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION           120\r
+#define STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION            131\r
+#define STORE_R_NO_LIST_OBJECT_END_FUNCTION             121\r
+#define STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION            122\r
+#define STORE_R_NO_LIST_OBJECT_START_FUNCTION           123\r
+#define STORE_R_NO_MODIFY_OBJECT_FUNCTION               145\r
+#define STORE_R_NO_REVOKE_OBJECT_FUNCTION               124\r
+#define STORE_R_NO_STORE                                129\r
+#define STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION      137\r
+#define STORE_R_NO_STORE_OBJECT_FUNCTION                125\r
+#define STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION                 126\r
+#define STORE_R_NO_VALUE                                130\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/symhacks.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/symhacks.h
new file mode 100644 (file)
index 0000000..16df42d
--- /dev/null
@@ -0,0 +1,383 @@
+/* ====================================================================\r
+ * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_SYMHACKS_H\r
+#define HEADER_SYMHACKS_H\r
+\r
+#include <openssl/e_os2.h>\r
+\r
+/* Hacks to solve the problem with linkers incapable of handling very long\r
+   symbol names.  In the case of VMS, the limit is 31 characters on VMS for\r
+   VAX. */\r
+#ifdef OPENSSL_SYS_VMS\r
+\r
+/* Hack a long name in crypto/ex_data.c */\r
+#undef CRYPTO_get_ex_data_implementation\r
+#define CRYPTO_get_ex_data_implementation      CRYPTO_get_ex_data_impl\r
+#undef CRYPTO_set_ex_data_implementation\r
+#define CRYPTO_set_ex_data_implementation      CRYPTO_set_ex_data_impl\r
+\r
+/* Hack a long name in crypto/asn1/a_mbstr.c */\r
+#undef ASN1_STRING_set_default_mask_asc\r
+#define ASN1_STRING_set_default_mask_asc       ASN1_STRING_set_def_mask_asc\r
+\r
+#if 0 /* No longer needed, since safestack macro magic does the job */\r
+/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO) */\r
+#undef i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO\r
+#define i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO      i2d_ASN1_SET_OF_PKCS7_SIGINF\r
+#undef d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO\r
+#define d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO      d2i_ASN1_SET_OF_PKCS7_SIGINF\r
+#endif\r
+\r
+#if 0 /* No longer needed, since safestack macro magic does the job */\r
+/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO) */\r
+#undef i2d_ASN1_SET_OF_PKCS7_RECIP_INFO\r
+#define i2d_ASN1_SET_OF_PKCS7_RECIP_INFO       i2d_ASN1_SET_OF_PKCS7_RECINF\r
+#undef d2i_ASN1_SET_OF_PKCS7_RECIP_INFO\r
+#define d2i_ASN1_SET_OF_PKCS7_RECIP_INFO       d2i_ASN1_SET_OF_PKCS7_RECINF\r
+#endif\r
+\r
+#if 0 /* No longer needed, since safestack macro magic does the job */\r
+/* Hack the names created with DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION) */\r
+#undef i2d_ASN1_SET_OF_ACCESS_DESCRIPTION\r
+#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION     i2d_ASN1_SET_OF_ACC_DESC\r
+#undef d2i_ASN1_SET_OF_ACCESS_DESCRIPTION\r
+#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION     d2i_ASN1_SET_OF_ACC_DESC\r
+#endif\r
+\r
+/* Hack the names created with DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE) */\r
+#undef PEM_read_NETSCAPE_CERT_SEQUENCE\r
+#define PEM_read_NETSCAPE_CERT_SEQUENCE                PEM_read_NS_CERT_SEQ\r
+#undef PEM_write_NETSCAPE_CERT_SEQUENCE\r
+#define PEM_write_NETSCAPE_CERT_SEQUENCE       PEM_write_NS_CERT_SEQ\r
+#undef PEM_read_bio_NETSCAPE_CERT_SEQUENCE\r
+#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE    PEM_read_bio_NS_CERT_SEQ\r
+#undef PEM_write_bio_NETSCAPE_CERT_SEQUENCE\r
+#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE   PEM_write_bio_NS_CERT_SEQ\r
+#undef PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE\r
+#define PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE        PEM_write_cb_bio_NS_CERT_SEQ\r
+\r
+/* Hack the names created with DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO) */\r
+#undef PEM_read_PKCS8_PRIV_KEY_INFO\r
+#define PEM_read_PKCS8_PRIV_KEY_INFO           PEM_read_P8_PRIV_KEY_INFO\r
+#undef PEM_write_PKCS8_PRIV_KEY_INFO\r
+#define PEM_write_PKCS8_PRIV_KEY_INFO          PEM_write_P8_PRIV_KEY_INFO\r
+#undef PEM_read_bio_PKCS8_PRIV_KEY_INFO\r
+#define PEM_read_bio_PKCS8_PRIV_KEY_INFO       PEM_read_bio_P8_PRIV_KEY_INFO\r
+#undef PEM_write_bio_PKCS8_PRIV_KEY_INFO\r
+#define PEM_write_bio_PKCS8_PRIV_KEY_INFO      PEM_write_bio_P8_PRIV_KEY_INFO\r
+#undef PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO\r
+#define PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO   PEM_wrt_cb_bio_P8_PRIV_KEY_INFO\r
+\r
+/* Hack other PEM names */\r
+#undef PEM_write_bio_PKCS8PrivateKey_nid\r
+#define PEM_write_bio_PKCS8PrivateKey_nid      PEM_write_bio_PKCS8PrivKey_nid\r
+\r
+/* Hack some long X509 names */\r
+#undef X509_REVOKED_get_ext_by_critical\r
+#define X509_REVOKED_get_ext_by_critical       X509_REVOKED_get_ext_by_critic\r
+#undef X509_policy_tree_get0_user_policies\r
+#define X509_policy_tree_get0_user_policies    X509_pcy_tree_get0_usr_policies\r
+#undef X509_policy_node_get0_qualifiers\r
+#define X509_policy_node_get0_qualifiers       X509_pcy_node_get0_qualifiers\r
+#undef X509_STORE_CTX_get_explicit_policy\r
+#define X509_STORE_CTX_get_explicit_policy     X509_STORE_CTX_get_expl_policy\r
+\r
+/* Hack some long CRYPTO names */\r
+#undef CRYPTO_set_dynlock_destroy_callback\r
+#define CRYPTO_set_dynlock_destroy_callback     CRYPTO_set_dynlock_destroy_cb\r
+#undef CRYPTO_set_dynlock_create_callback\r
+#define CRYPTO_set_dynlock_create_callback      CRYPTO_set_dynlock_create_cb\r
+#undef CRYPTO_set_dynlock_lock_callback\r
+#define CRYPTO_set_dynlock_lock_callback        CRYPTO_set_dynlock_lock_cb\r
+#undef CRYPTO_get_dynlock_lock_callback\r
+#define CRYPTO_get_dynlock_lock_callback        CRYPTO_get_dynlock_lock_cb\r
+#undef CRYPTO_get_dynlock_destroy_callback\r
+#define CRYPTO_get_dynlock_destroy_callback     CRYPTO_get_dynlock_destroy_cb\r
+#undef CRYPTO_get_dynlock_create_callback\r
+#define CRYPTO_get_dynlock_create_callback      CRYPTO_get_dynlock_create_cb\r
+#undef CRYPTO_set_locked_mem_ex_functions\r
+#define CRYPTO_set_locked_mem_ex_functions      CRYPTO_set_locked_mem_ex_funcs\r
+#undef CRYPTO_get_locked_mem_ex_functions\r
+#define CRYPTO_get_locked_mem_ex_functions      CRYPTO_get_locked_mem_ex_funcs\r
+\r
+/* Hack some long SSL names */\r
+#undef SSL_CTX_set_default_verify_paths\r
+#define SSL_CTX_set_default_verify_paths        SSL_CTX_set_def_verify_paths\r
+#undef SSL_get_ex_data_X509_STORE_CTX_idx\r
+#define SSL_get_ex_data_X509_STORE_CTX_idx      SSL_get_ex_d_X509_STORE_CTX_idx\r
+#undef SSL_add_file_cert_subjects_to_stack\r
+#define SSL_add_file_cert_subjects_to_stack     SSL_add_file_cert_subjs_to_stk\r
+#undef SSL_add_dir_cert_subjects_to_stack\r
+#define SSL_add_dir_cert_subjects_to_stack      SSL_add_dir_cert_subjs_to_stk\r
+#undef SSL_CTX_use_certificate_chain_file\r
+#define SSL_CTX_use_certificate_chain_file      SSL_CTX_use_cert_chain_file\r
+#undef SSL_CTX_set_cert_verify_callback\r
+#define SSL_CTX_set_cert_verify_callback        SSL_CTX_set_cert_verify_cb\r
+#undef SSL_CTX_set_default_passwd_cb_userdata\r
+#define SSL_CTX_set_default_passwd_cb_userdata  SSL_CTX_set_def_passwd_cb_ud\r
+#undef SSL_COMP_get_compression_methods\r
+#define SSL_COMP_get_compression_methods       SSL_COMP_get_compress_methods\r
+\r
+/* Hack some long ENGINE names */\r
+#undef ENGINE_get_default_BN_mod_exp_crt\r
+#define ENGINE_get_default_BN_mod_exp_crt      ENGINE_get_def_BN_mod_exp_crt\r
+#undef ENGINE_set_default_BN_mod_exp_crt\r
+#define ENGINE_set_default_BN_mod_exp_crt      ENGINE_set_def_BN_mod_exp_crt\r
+#undef ENGINE_set_load_privkey_function\r
+#define ENGINE_set_load_privkey_function        ENGINE_set_load_privkey_fn\r
+#undef ENGINE_get_load_privkey_function\r
+#define ENGINE_get_load_privkey_function        ENGINE_get_load_privkey_fn\r
+\r
+/* Hack some long OCSP names */\r
+#undef OCSP_REQUEST_get_ext_by_critical\r
+#define OCSP_REQUEST_get_ext_by_critical        OCSP_REQUEST_get_ext_by_crit\r
+#undef OCSP_BASICRESP_get_ext_by_critical\r
+#define OCSP_BASICRESP_get_ext_by_critical      OCSP_BASICRESP_get_ext_by_crit\r
+#undef OCSP_SINGLERESP_get_ext_by_critical\r
+#define OCSP_SINGLERESP_get_ext_by_critical     OCSP_SINGLERESP_get_ext_by_crit\r
+\r
+/* Hack some long DES names */\r
+#undef _ossl_old_des_ede3_cfb64_encrypt\r
+#define _ossl_old_des_ede3_cfb64_encrypt       _ossl_odes_ede3_cfb64_encrypt\r
+#undef _ossl_old_des_ede3_ofb64_encrypt\r
+#define _ossl_old_des_ede3_ofb64_encrypt       _ossl_odes_ede3_ofb64_encrypt\r
+\r
+/* Hack some long EVP names */\r
+#undef OPENSSL_add_all_algorithms_noconf\r
+#define OPENSSL_add_all_algorithms_noconf      OPENSSL_add_all_algo_noconf\r
+#undef OPENSSL_add_all_algorithms_conf\r
+#define OPENSSL_add_all_algorithms_conf                OPENSSL_add_all_algo_conf\r
+\r
+/* Hack some long EC names */\r
+#undef EC_GROUP_set_point_conversion_form\r
+#define EC_GROUP_set_point_conversion_form     EC_GROUP_set_point_conv_form\r
+#undef EC_GROUP_get_point_conversion_form\r
+#define EC_GROUP_get_point_conversion_form     EC_GROUP_get_point_conv_form\r
+#undef EC_GROUP_clear_free_all_extra_data\r
+#define EC_GROUP_clear_free_all_extra_data     EC_GROUP_clr_free_all_xtra_data\r
+#undef EC_POINT_set_Jprojective_coordinates_GFp\r
+#define EC_POINT_set_Jprojective_coordinates_GFp \\r
+                                                EC_POINT_set_Jproj_coords_GFp\r
+#undef EC_POINT_get_Jprojective_coordinates_GFp\r
+#define EC_POINT_get_Jprojective_coordinates_GFp \\r
+                                                EC_POINT_get_Jproj_coords_GFp\r
+#undef EC_POINT_set_affine_coordinates_GFp\r
+#define EC_POINT_set_affine_coordinates_GFp     EC_POINT_set_affine_coords_GFp\r
+#undef EC_POINT_get_affine_coordinates_GFp\r
+#define EC_POINT_get_affine_coordinates_GFp     EC_POINT_get_affine_coords_GFp\r
+#undef EC_POINT_set_compressed_coordinates_GFp\r
+#define EC_POINT_set_compressed_coordinates_GFp EC_POINT_set_compr_coords_GFp\r
+#undef EC_POINT_set_affine_coordinates_GF2m\r
+#define EC_POINT_set_affine_coordinates_GF2m    EC_POINT_set_affine_coords_GF2m\r
+#undef EC_POINT_get_affine_coordinates_GF2m\r
+#define EC_POINT_get_affine_coordinates_GF2m    EC_POINT_get_affine_coords_GF2m\r
+#undef EC_POINT_set_compressed_coordinates_GF2m\r
+#define EC_POINT_set_compressed_coordinates_GF2m \\r
+                                                EC_POINT_set_compr_coords_GF2m\r
+#undef ec_GF2m_simple_group_clear_finish\r
+#define ec_GF2m_simple_group_clear_finish        ec_GF2m_simple_grp_clr_finish\r
+#undef ec_GF2m_simple_group_check_discriminant\r
+#define ec_GF2m_simple_group_check_discriminant        ec_GF2m_simple_grp_chk_discrim\r
+#undef ec_GF2m_simple_point_clear_finish\r
+#define ec_GF2m_simple_point_clear_finish        ec_GF2m_simple_pt_clr_finish\r
+#undef ec_GF2m_simple_point_set_to_infinity\r
+#define ec_GF2m_simple_point_set_to_infinity     ec_GF2m_simple_pt_set_to_inf\r
+#undef ec_GF2m_simple_points_make_affine\r
+#define ec_GF2m_simple_points_make_affine        ec_GF2m_simple_pts_make_affine\r
+#undef ec_GF2m_simple_point_set_affine_coordinates\r
+#define ec_GF2m_simple_point_set_affine_coordinates \\r
+                                                ec_GF2m_smp_pt_set_af_coords\r
+#undef ec_GF2m_simple_point_get_affine_coordinates\r
+#define ec_GF2m_simple_point_get_affine_coordinates \\r
+                                                ec_GF2m_smp_pt_get_af_coords\r
+#undef ec_GF2m_simple_set_compressed_coordinates\r
+#define ec_GF2m_simple_set_compressed_coordinates \\r
+                                                ec_GF2m_smp_set_compr_coords\r
+#undef ec_GFp_simple_group_set_curve_GFp\r
+#define ec_GFp_simple_group_set_curve_GFp       ec_GFp_simple_grp_set_curve_GFp\r
+#undef ec_GFp_simple_group_get_curve_GFp\r
+#define ec_GFp_simple_group_get_curve_GFp       ec_GFp_simple_grp_get_curve_GFp\r
+#undef ec_GFp_simple_group_clear_finish\r
+#define ec_GFp_simple_group_clear_finish        ec_GFp_simple_grp_clear_finish\r
+#undef ec_GFp_simple_group_set_generator\r
+#define ec_GFp_simple_group_set_generator       ec_GFp_simple_grp_set_generator\r
+#undef ec_GFp_simple_group_get0_generator\r
+#define ec_GFp_simple_group_get0_generator      ec_GFp_simple_grp_gt0_generator\r
+#undef ec_GFp_simple_group_get_cofactor\r
+#define ec_GFp_simple_group_get_cofactor        ec_GFp_simple_grp_get_cofactor\r
+#undef ec_GFp_simple_point_clear_finish\r
+#define ec_GFp_simple_point_clear_finish        ec_GFp_simple_pt_clear_finish\r
+#undef ec_GFp_simple_point_set_to_infinity\r
+#define ec_GFp_simple_point_set_to_infinity     ec_GFp_simple_pt_set_to_inf\r
+#undef ec_GFp_simple_points_make_affine\r
+#define ec_GFp_simple_points_make_affine        ec_GFp_simple_pts_make_affine\r
+#undef ec_GFp_simple_group_get_curve_GFp\r
+#define ec_GFp_simple_group_get_curve_GFp       ec_GFp_simple_grp_get_curve_GFp\r
+#undef ec_GFp_simple_set_Jprojective_coordinates_GFp\r
+#define ec_GFp_simple_set_Jprojective_coordinates_GFp \\r
+                                                ec_GFp_smp_set_Jproj_coords_GFp\r
+#undef ec_GFp_simple_get_Jprojective_coordinates_GFp\r
+#define ec_GFp_simple_get_Jprojective_coordinates_GFp \\r
+                                                ec_GFp_smp_get_Jproj_coords_GFp\r
+#undef ec_GFp_simple_point_set_affine_coordinates_GFp\r
+#define ec_GFp_simple_point_set_affine_coordinates_GFp \\r
+                                                ec_GFp_smp_pt_set_af_coords_GFp\r
+#undef ec_GFp_simple_point_get_affine_coordinates_GFp\r
+#define ec_GFp_simple_point_get_affine_coordinates_GFp \\r
+                                                ec_GFp_smp_pt_get_af_coords_GFp\r
+#undef ec_GFp_simple_set_compressed_coordinates_GFp\r
+#define ec_GFp_simple_set_compressed_coordinates_GFp \\r
+                                                ec_GFp_smp_set_compr_coords_GFp\r
+#undef ec_GFp_simple_point_set_affine_coordinates\r
+#define ec_GFp_simple_point_set_affine_coordinates \\r
+                                                ec_GFp_smp_pt_set_af_coords\r
+#undef ec_GFp_simple_point_get_affine_coordinates\r
+#define ec_GFp_simple_point_get_affine_coordinates \\r
+                                                ec_GFp_smp_pt_get_af_coords\r
+#undef ec_GFp_simple_set_compressed_coordinates\r
+#define ec_GFp_simple_set_compressed_coordinates \\r
+                                                ec_GFp_smp_set_compr_coords\r
+#undef ec_GFp_simple_group_check_discriminant\r
+#define ec_GFp_simple_group_check_discriminant ec_GFp_simple_grp_chk_discrim\r
+\r
+/* Hack som long STORE names */\r
+#undef STORE_method_set_initialise_function\r
+#define STORE_method_set_initialise_function   STORE_meth_set_initialise_fn\r
+#undef STORE_method_set_cleanup_function\r
+#define STORE_method_set_cleanup_function      STORE_meth_set_cleanup_fn\r
+#undef STORE_method_set_generate_function\r
+#define STORE_method_set_generate_function     STORE_meth_set_generate_fn\r
+#undef STORE_method_set_modify_function\r
+#define STORE_method_set_modify_function       STORE_meth_set_modify_fn\r
+#undef STORE_method_set_revoke_function\r
+#define STORE_method_set_revoke_function       STORE_meth_set_revoke_fn\r
+#undef STORE_method_set_delete_function\r
+#define STORE_method_set_delete_function       STORE_meth_set_delete_fn\r
+#undef STORE_method_set_list_start_function\r
+#define STORE_method_set_list_start_function   STORE_meth_set_list_start_fn\r
+#undef STORE_method_set_list_next_function\r
+#define STORE_method_set_list_next_function    STORE_meth_set_list_next_fn\r
+#undef STORE_method_set_list_end_function\r
+#define STORE_method_set_list_end_function     STORE_meth_set_list_end_fn\r
+#undef STORE_method_set_update_store_function\r
+#define STORE_method_set_update_store_function STORE_meth_set_update_store_fn\r
+#undef STORE_method_set_lock_store_function\r
+#define STORE_method_set_lock_store_function   STORE_meth_set_lock_store_fn\r
+#undef STORE_method_set_unlock_store_function\r
+#define STORE_method_set_unlock_store_function STORE_meth_set_unlock_store_fn\r
+#undef STORE_method_get_initialise_function\r
+#define STORE_method_get_initialise_function   STORE_meth_get_initialise_fn\r
+#undef STORE_method_get_cleanup_function\r
+#define STORE_method_get_cleanup_function      STORE_meth_get_cleanup_fn\r
+#undef STORE_method_get_generate_function\r
+#define STORE_method_get_generate_function     STORE_meth_get_generate_fn\r
+#undef STORE_method_get_modify_function\r
+#define STORE_method_get_modify_function       STORE_meth_get_modify_fn\r
+#undef STORE_method_get_revoke_function\r
+#define STORE_method_get_revoke_function       STORE_meth_get_revoke_fn\r
+#undef STORE_method_get_delete_function\r
+#define STORE_method_get_delete_function       STORE_meth_get_delete_fn\r
+#undef STORE_method_get_list_start_function\r
+#define STORE_method_get_list_start_function   STORE_meth_get_list_start_fn\r
+#undef STORE_method_get_list_next_function\r
+#define STORE_method_get_list_next_function    STORE_meth_get_list_next_fn\r
+#undef STORE_method_get_list_end_function\r
+#define STORE_method_get_list_end_function     STORE_meth_get_list_end_fn\r
+#undef STORE_method_get_update_store_function\r
+#define STORE_method_get_update_store_function STORE_meth_get_update_store_fn\r
+#undef STORE_method_get_lock_store_function\r
+#define STORE_method_get_lock_store_function   STORE_meth_get_lock_store_fn\r
+#undef STORE_method_get_unlock_store_function\r
+#define STORE_method_get_unlock_store_function STORE_meth_get_unlock_store_fn\r
+\r
+#endif /* defined OPENSSL_SYS_VMS */\r
+\r
+\r
+/* Case insensiteve linking causes problems.... */\r
+#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2)\r
+#undef ERR_load_CRYPTO_strings\r
+#define ERR_load_CRYPTO_strings                        ERR_load_CRYPTOlib_strings\r
+#undef OCSP_crlID_new\r
+#define OCSP_crlID_new                          OCSP_crlID2_new\r
+\r
+#undef d2i_ECPARAMETERS\r
+#define d2i_ECPARAMETERS                        d2i_UC_ECPARAMETERS\r
+#undef i2d_ECPARAMETERS\r
+#define i2d_ECPARAMETERS                        i2d_UC_ECPARAMETERS\r
+#undef d2i_ECPKPARAMETERS\r
+#define d2i_ECPKPARAMETERS                      d2i_UC_ECPKPARAMETERS\r
+#undef i2d_ECPKPARAMETERS\r
+#define i2d_ECPKPARAMETERS                      i2d_UC_ECPKPARAMETERS\r
+\r
+/* These functions do not seem to exist!  However, I'm paranoid...\r
+   Original command in x509v3.h:\r
+   These functions are being redefined in another directory,\r
+   and clash when the linker is case-insensitive, so let's\r
+   hide them a little, by giving them an extra 'o' at the\r
+   beginning of the name... */\r
+#undef X509v3_cleanup_extensions\r
+#define X509v3_cleanup_extensions               oX509v3_cleanup_extensions\r
+#undef X509v3_add_extension\r
+#define X509v3_add_extension                    oX509v3_add_extension\r
+#undef X509v3_add_netscape_extensions\r
+#define X509v3_add_netscape_extensions          oX509v3_add_netscape_extensions\r
+#undef X509v3_add_standard_extensions\r
+#define X509v3_add_standard_extensions          oX509v3_add_standard_extensions\r
+\r
+\r
+#endif\r
+\r
+\r
+#endif /* ! defined HEADER_VMS_IDHACKS_H */\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/tls1.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/tls1.h
new file mode 100644 (file)
index 0000000..851816a
--- /dev/null
@@ -0,0 +1,291 @@
+/* ssl/tls1.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+/* ====================================================================\r
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.\r
+ *\r
+ * Portions of the attached software ("Contribution") are developed by \r
+ * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.\r
+ *\r
+ * The Contribution is licensed pursuant to the OpenSSL open source\r
+ * license provided above.\r
+ *\r
+ * ECC cipher suite support in OpenSSL originally written by\r
+ * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_TLS1_H \r
+#define HEADER_TLS1_H \r
+\r
+#include <openssl/buffer.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES   1\r
+\r
+#define TLS1_VERSION                   0x0301\r
+#define TLS1_VERSION_MAJOR             0x03\r
+#define TLS1_VERSION_MINOR             0x01\r
+\r
+#define TLS1_AD_DECRYPTION_FAILED      21\r
+#define TLS1_AD_RECORD_OVERFLOW                22\r
+#define TLS1_AD_UNKNOWN_CA             48      /* fatal */\r
+#define TLS1_AD_ACCESS_DENIED          49      /* fatal */\r
+#define TLS1_AD_DECODE_ERROR           50      /* fatal */\r
+#define TLS1_AD_DECRYPT_ERROR          51\r
+#define TLS1_AD_EXPORT_RESTRICTION     60      /* fatal */\r
+#define TLS1_AD_PROTOCOL_VERSION       70      /* fatal */\r
+#define TLS1_AD_INSUFFICIENT_SECURITY  71      /* fatal */\r
+#define TLS1_AD_INTERNAL_ERROR         80      /* fatal */\r
+#define TLS1_AD_USER_CANCELLED         90\r
+#define TLS1_AD_NO_RENEGOTIATION       100\r
+\r
+/* Additional TLS ciphersuites from draft-ietf-tls-56-bit-ciphersuites-00.txt\r
+ * (available if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES is defined, see\r
+ * s3_lib.c).  We actually treat them like SSL 3.0 ciphers, which we probably\r
+ * shouldn't. */\r
+#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5         0x03000060\r
+#define TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5     0x03000061\r
+#define TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA                0x03000062\r
+#define TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA    0x03000063\r
+#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA         0x03000064\r
+#define TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA     0x03000065\r
+#define TLS1_CK_DHE_DSS_WITH_RC4_128_SHA               0x03000066\r
+\r
+/* AES ciphersuites from RFC3268 */\r
+\r
+#define TLS1_CK_RSA_WITH_AES_128_SHA                   0x0300002F\r
+#define TLS1_CK_DH_DSS_WITH_AES_128_SHA                        0x03000030\r
+#define TLS1_CK_DH_RSA_WITH_AES_128_SHA                        0x03000031\r
+#define TLS1_CK_DHE_DSS_WITH_AES_128_SHA               0x03000032\r
+#define TLS1_CK_DHE_RSA_WITH_AES_128_SHA               0x03000033\r
+#define TLS1_CK_ADH_WITH_AES_128_SHA                   0x03000034\r
+\r
+#define TLS1_CK_RSA_WITH_AES_256_SHA                   0x03000035\r
+#define TLS1_CK_DH_DSS_WITH_AES_256_SHA                        0x03000036\r
+#define TLS1_CK_DH_RSA_WITH_AES_256_SHA                        0x03000037\r
+#define TLS1_CK_DHE_DSS_WITH_AES_256_SHA               0x03000038\r
+#define TLS1_CK_DHE_RSA_WITH_AES_256_SHA               0x03000039\r
+#define TLS1_CK_ADH_WITH_AES_256_SHA                   0x0300003A\r
+\r
+/* ECC ciphersuites from draft-ietf-tls-ecc-01.txt (Mar 15, 2001).\r
+ * XXX NOTE: There is a bug in the draft, cipher numbers 4B, and 4C\r
+ * are defined twice so we define ECDH_ECDSA_EXPORT cipher\r
+ * suites to use 5B and 5C instead (this may change with future\r
+ * updates to the IETF draft).\r
+ */\r
+/* draft-ietf-tls-ecc-03.txt (June 2003) gives a changed list of\r
+ * ciphersuites, but does not define numbers for all of them\r
+ * because of possible conflicts with other Internet Drafts;\r
+ * most numbers are still subject to change. */\r
+#define TLS1_CK_ECDH_ECDSA_WITH_NULL_SHA                0x03000047\r
+#define TLS1_CK_ECDH_ECDSA_WITH_RC4_128_SHA             0x03000048\r
+#define TLS1_CK_ECDH_ECDSA_WITH_DES_CBC_SHA             0x03000049\r
+#define TLS1_CK_ECDH_ECDSA_WITH_DES_192_CBC3_SHA        0x0300004A\r
+#define TLS1_CK_ECDH_ECDSA_WITH_AES_128_CBC_SHA         0x0300004B\r
+#define TLS1_CK_ECDH_ECDSA_WITH_AES_256_CBC_SHA         0x0300004C\r
+#define TLS1_CK_ECDH_ECDSA_EXPORT_WITH_RC4_40_SHA       0x0300005B\r
+#define TLS1_CK_ECDH_ECDSA_EXPORT_WITH_RC4_56_SHA       0x0300005C\r
+\r
+#define TLS1_CK_ECDH_RSA_WITH_NULL_SHA                  0x0300004D\r
+#define TLS1_CK_ECDH_RSA_WITH_RC4_128_SHA               0x0300004E\r
+#define TLS1_CK_ECDH_RSA_WITH_DES_CBC_SHA               0x0300004F\r
+#define TLS1_CK_ECDH_RSA_WITH_DES_192_CBC3_SHA          0x03000050\r
+#define TLS1_CK_ECDH_RSA_WITH_AES_128_CBC_SHA           0x03000051\r
+#define TLS1_CK_ECDH_RSA_WITH_AES_256_CBC_SHA           0x03000052\r
+#define TLS1_CK_ECDH_RSA_EXPORT_WITH_RC4_40_SHA         0x03000053\r
+#define TLS1_CK_ECDH_RSA_EXPORT_WITH_RC4_56_SHA         0x03000054\r
+\r
+#define TLS1_CK_ECDH_anon_WITH_NULL_SHA                 0x03000055\r
+#define TLS1_CK_ECDH_anon_WITH_RC4_128_SHA              0x03000056\r
+#define TLS1_CK_ECDH_anon_WITH_DES_CBC_SHA              0x03000057\r
+#define TLS1_CK_ECDH_anon_WITH_DES_192_CBC3_SHA         0x03000058\r
+#define TLS1_CK_ECDH_anon_EXPORT_WITH_DES_40_CBC_SHA    0x03000059\r
+#define TLS1_CK_ECDH_anon_EXPORT_WITH_RC4_40_SHA        0x0300005A\r
+\r
+/* XXX: ECC ciphersuites offering forward secrecy are not yet specified\r
+ * in the ECC/TLS draft but our code allows them to be implemented\r
+ * very easily. To add such a cipher suite, one needs to add two constant\r
+ * definitions to this file and a new structure in s3_lib.c. We illustrate\r
+ * the process for the made-up ciphers ECDHE-ECDSA-AES128-SHA and\r
+ * ECDHE-RSA-AES128-SHA.\r
+ */\r
+#define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA        0x03000077\r
+#define TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA          0x03000078\r
+\r
+\r
+/* XXX\r
+ * Inconsistency alert:\r
+ * The OpenSSL names of ciphers with ephemeral DH here include the string\r
+ * "DHE", while elsewhere it has always been "EDH".\r
+ * (The alias for the list of all such ciphers also is "EDH".)\r
+ * The specifications speak of "EDH"; maybe we should allow both forms\r
+ * for everything. */\r
+#define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5                "EXP1024-RC4-MD5"\r
+#define TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5    "EXP1024-RC2-CBC-MD5"\r
+#define TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA       "EXP1024-DES-CBC-SHA"\r
+#define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA   "EXP1024-DHE-DSS-DES-CBC-SHA"\r
+#define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA                "EXP1024-RC4-SHA"\r
+#define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA    "EXP1024-DHE-DSS-RC4-SHA"\r
+#define TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA              "DHE-DSS-RC4-SHA"\r
+\r
+/* AES ciphersuites from RFC3268 */\r
+#define TLS1_TXT_RSA_WITH_AES_128_SHA                  "AES128-SHA"\r
+#define TLS1_TXT_DH_DSS_WITH_AES_128_SHA               "DH-DSS-AES128-SHA"\r
+#define TLS1_TXT_DH_RSA_WITH_AES_128_SHA               "DH-RSA-AES128-SHA"\r
+#define TLS1_TXT_DHE_DSS_WITH_AES_128_SHA              "DHE-DSS-AES128-SHA"\r
+#define TLS1_TXT_DHE_RSA_WITH_AES_128_SHA              "DHE-RSA-AES128-SHA"\r
+#define TLS1_TXT_ADH_WITH_AES_128_SHA                  "ADH-AES128-SHA"\r
+\r
+#define TLS1_TXT_RSA_WITH_AES_256_SHA                  "AES256-SHA"\r
+#define TLS1_TXT_DH_DSS_WITH_AES_256_SHA               "DH-DSS-AES256-SHA"\r
+#define TLS1_TXT_DH_RSA_WITH_AES_256_SHA               "DH-RSA-AES256-SHA"\r
+#define TLS1_TXT_DHE_DSS_WITH_AES_256_SHA              "DHE-DSS-AES256-SHA"\r
+#define TLS1_TXT_DHE_RSA_WITH_AES_256_SHA              "DHE-RSA-AES256-SHA"\r
+#define TLS1_TXT_ADH_WITH_AES_256_SHA                  "ADH-AES256-SHA"\r
+\r
+/* ECC ciphersuites from draft-ietf-tls-ecc-01.txt (Mar 15, 2001) */\r
+#define TLS1_TXT_ECDH_ECDSA_WITH_NULL_SHA               "ECDH-ECDSA-NULL-SHA"\r
+#define TLS1_TXT_ECDH_ECDSA_WITH_RC4_128_SHA            "ECDH-ECDSA-RC4-SHA"\r
+#define TLS1_TXT_ECDH_ECDSA_WITH_DES_CBC_SHA            "ECDH-ECDSA-DES-CBC-SHA"\r
+#define TLS1_TXT_ECDH_ECDSA_WITH_DES_192_CBC3_SHA       "ECDH-ECDSA-DES-CBC3-SHA"\r
+#define TLS1_TXT_ECDH_ECDSA_WITH_AES_128_CBC_SHA        "ECDH-ECDSA-AES128-SHA"\r
+#define TLS1_TXT_ECDH_ECDSA_WITH_AES_256_CBC_SHA        "ECDH-ECDSA-AES256-SHA"\r
+#define TLS1_TXT_ECDH_ECDSA_EXPORT_WITH_RC4_40_SHA      "EXP-ECDH-ECDSA-RC4-40-SHA"\r
+#define TLS1_TXT_ECDH_ECDSA_EXPORT_WITH_RC4_56_SHA      "EXP-ECDH-ECDSA-RC4-56-SHA"\r
+\r
+#define TLS1_TXT_ECDH_RSA_WITH_NULL_SHA                 "ECDH-RSA-NULL-SHA"\r
+#define TLS1_TXT_ECDH_RSA_WITH_RC4_128_SHA              "ECDH-RSA-RC4-SHA"\r
+#define TLS1_TXT_ECDH_RSA_WITH_DES_CBC_SHA              "ECDH-RSA-DES-CBC-SHA"\r
+#define TLS1_TXT_ECDH_RSA_WITH_DES_192_CBC3_SHA         "ECDH-RSA-DES-CBC3-SHA"\r
+#define TLS1_TXT_ECDH_RSA_WITH_AES_128_CBC_SHA          "ECDH-RSA-AES128-SHA"\r
+#define TLS1_TXT_ECDH_RSA_WITH_AES_256_CBC_SHA          "ECDH-RSA-AES256-SHA"\r
+#define TLS1_TXT_ECDH_RSA_EXPORT_WITH_RC4_40_SHA        "EXP-ECDH-RSA-RC4-40-SHA"\r
+#define TLS1_TXT_ECDH_RSA_EXPORT_WITH_RC4_56_SHA        "EXP-ECDH-RSA-RC4-56-SHA"\r
+\r
+#define TLS1_TXT_ECDH_anon_WITH_NULL_SHA                "AECDH-NULL-SHA"\r
+#define TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA             "AECDH-RC4-SHA"\r
+#define TLS1_TXT_ECDH_anon_WITH_DES_CBC_SHA             "AECDH-DES-CBC-SHA"\r
+#define TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA        "AECDH-DES-CBC3-SHA"\r
+#define TLS1_TXT_ECDH_anon_EXPORT_WITH_DES_40_CBC_SHA   "EXP-AECDH-DES-40-CBC-SHA"\r
+#define TLS1_TXT_ECDH_anon_EXPORT_WITH_RC4_40_SHA       "EXP-AECDH-RC4-40-SHA"\r
+\r
+/* XXX: Made-up ECC cipher suites offering forward secrecy. This is for \r
+ * illustration only. \r
+ */\r
+#define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA       "ECDHE-ECDSA-AES128-SHA"\r
+#define TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA         "ECDHE-RSA-AES128-SHA"\r
+\r
+\r
+#define TLS_CT_RSA_SIGN                        1\r
+#define TLS_CT_DSS_SIGN                        2\r
+#define TLS_CT_RSA_FIXED_DH            3\r
+#define TLS_CT_DSS_FIXED_DH            4\r
+#define TLS_CT_ECDSA_SIGN              5\r
+#define TLS_CT_RSA_FIXED_ECDH          6\r
+#define TLS_CT_ECDSA_FIXED_ECDH        7\r
+#define TLS_CT_NUMBER                  7\r
+\r
+#define TLS1_FINISH_MAC_LENGTH         12\r
+\r
+#define TLS_MD_MAX_CONST_SIZE                  20\r
+#define TLS_MD_CLIENT_FINISH_CONST             "client finished"\r
+#define TLS_MD_CLIENT_FINISH_CONST_SIZE                15\r
+#define TLS_MD_SERVER_FINISH_CONST             "server finished"\r
+#define TLS_MD_SERVER_FINISH_CONST_SIZE                15\r
+#define TLS_MD_SERVER_WRITE_KEY_CONST          "server write key"\r
+#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE     16\r
+#define TLS_MD_KEY_EXPANSION_CONST             "key expansion"\r
+#define TLS_MD_KEY_EXPANSION_CONST_SIZE                13\r
+#define TLS_MD_CLIENT_WRITE_KEY_CONST          "client write key"\r
+#define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE     16\r
+#define TLS_MD_SERVER_WRITE_KEY_CONST          "server write key"\r
+#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE     16\r
+#define TLS_MD_IV_BLOCK_CONST                  "IV block"\r
+#define TLS_MD_IV_BLOCK_CONST_SIZE             8\r
+#define TLS_MD_MASTER_SECRET_CONST             "master secret"\r
+#define TLS_MD_MASTER_SECRET_CONST_SIZE                13\r
+\r
+#ifdef CHARSET_EBCDIC\r
+#undef TLS_MD_CLIENT_FINISH_CONST\r
+#define TLS_MD_CLIENT_FINISH_CONST    "\x63\x6c\x69\x65\x6e\x74\x20\x66\x69\x6e\x69\x73\x68\x65\x64"  /*client finished*/\r
+#undef TLS_MD_SERVER_FINISH_CONST\r
+#define TLS_MD_SERVER_FINISH_CONST    "\x73\x65\x72\x76\x65\x72\x20\x66\x69\x6e\x69\x73\x68\x65\x64"  /*server finished*/\r
+#undef TLS_MD_SERVER_WRITE_KEY_CONST\r
+#define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79"  /*server write key*/\r
+#undef TLS_MD_KEY_EXPANSION_CONST\r
+#define TLS_MD_KEY_EXPANSION_CONST    "\x6b\x65\x79\x20\x65\x78\x70\x61\x6e\x73\x69\x6f\x6e"  /*key expansion*/\r
+#undef TLS_MD_CLIENT_WRITE_KEY_CONST\r
+#define TLS_MD_CLIENT_WRITE_KEY_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79"  /*client write key*/\r
+#undef TLS_MD_SERVER_WRITE_KEY_CONST\r
+#define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79"  /*server write key*/\r
+#undef TLS_MD_IV_BLOCK_CONST\r
+#define TLS_MD_IV_BLOCK_CONST         "\x49\x56\x20\x62\x6c\x6f\x63\x6b"  /*IV block*/\r
+#undef TLS_MD_MASTER_SECRET_CONST\r
+#define TLS_MD_MASTER_SECRET_CONST    "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74"  /*master secret*/\r
+#endif\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/tmdiff.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/tmdiff.h
new file mode 100644 (file)
index 0000000..43ccd9f
--- /dev/null
@@ -0,0 +1,94 @@
+/* crypto/tmdiff.h */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ * 
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to.  The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ * 
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ * 
+ * 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 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    "This product includes cryptographic software written by
+ *     Eric Young (eay@cryptsoft.com)"
+ *    The word 'cryptographic' can be left out if the rouines from the library
+ *    being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from 
+ *    the apps directory (application code) you must include an acknowledgement:
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ * 
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 OR CONTRIBUTORS 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.
+ * 
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+/* Header for dynamic hash table routines
+ * Author - Eric Young
+ */
+/* ... erm yeah, "dynamic hash tables" you say?
+ * 
+ * And what would dynamic hash tables have to do with any of this code *now*?
+ * AFAICS, this code is only referenced by crypto/bn/exp.c which is an unused
+ * file that I doubt compiles any more. speed.c is the only thing that could
+ * use this (and it has nothing to do with hash tables), yet it instead has its
+ * own duplication of all this stuff and looks, if anything, more complete. See
+ * the corresponding note in apps/speed.c.
+ * The Bemused - Geoff
+ */
+
+#ifndef HEADER_TMDIFF_H
+#define HEADER_TMDIFF_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+typedef struct ms_tm MS_TM;
+
+MS_TM *ms_time_new(void );
+void ms_time_free(MS_TM *a);
+void ms_time_get(MS_TM *a);
+double ms_time_diff(MS_TM *start, MS_TM *end);
+int ms_time_cmp(const MS_TM *ap, const MS_TM *bp);
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif
+
+\1a
\ No newline at end of file
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/txt_db.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/txt_db.h
new file mode 100644 (file)
index 0000000..a767e45
--- /dev/null
@@ -0,0 +1,109 @@
+/* crypto/txt_db/txt_db.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_TXT_DB_H\r
+#define HEADER_TXT_DB_H\r
+\r
+#include <openssl/opensslconf.h>\r
+#ifndef OPENSSL_NO_BIO\r
+#include <openssl/bio.h>\r
+#endif\r
+#include <openssl/stack.h>\r
+#include <openssl/lhash.h>\r
+\r
+#define DB_ERROR_OK                    0\r
+#define DB_ERROR_MALLOC                        1\r
+#define DB_ERROR_INDEX_CLASH           2\r
+#define DB_ERROR_INDEX_OUT_OF_RANGE    3\r
+#define DB_ERROR_NO_INDEX              4\r
+#define DB_ERROR_INSERT_INDEX_CLASH            5\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct txt_db_st\r
+       {\r
+       int num_fields;\r
+       STACK /* char ** */ *data;\r
+       LHASH **index;\r
+       int (**qual)(char **);\r
+       long error;\r
+       long arg1;\r
+       long arg2;\r
+       char **arg_row;\r
+       } TXT_DB;\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+TXT_DB *TXT_DB_read(BIO *in, int num);\r
+long TXT_DB_write(BIO *out, TXT_DB *db);\r
+#else\r
+TXT_DB *TXT_DB_read(char *in, int num);\r
+long TXT_DB_write(char *out, TXT_DB *db);\r
+#endif\r
+int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(char **),\r
+               LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp);\r
+void TXT_DB_free(TXT_DB *db);\r
+char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value);\r
+int TXT_DB_insert(TXT_DB *db,char **value);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ui.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ui.h
new file mode 100644 (file)
index 0000000..5570e0d
--- /dev/null
@@ -0,0 +1,381 @@
+/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */\r
+/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL\r
+ * project 2001.\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 2001 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_UI_H\r
+#define HEADER_UI_H\r
+\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#include <openssl/crypto.h>\r
+#endif\r
+#include <openssl/safestack.h>\r
+#include <openssl/ossl_typ.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Declared already in ossl_typ.h */\r
+/* typedef struct ui_st UI; */\r
+/* typedef struct ui_method_st UI_METHOD; */\r
+\r
+\r
+/* All the following functions return -1 or NULL on error and in some cases\r
+   (UI_process()) -2 if interrupted or in some other way cancelled.\r
+   When everything is fine, they return 0, a positive value or a non-NULL\r
+   pointer, all depending on their purpose. */\r
+\r
+/* Creators and destructor.   */\r
+UI *UI_new(void);\r
+UI *UI_new_method(const UI_METHOD *method);\r
+void UI_free(UI *ui);\r
+\r
+/* The following functions are used to add strings to be printed and prompt\r
+   strings to prompt for data.  The names are UI_{add,dup}_<function>_string\r
+   and UI_{add,dup}_input_boolean.\r
+\r
+   UI_{add,dup}_<function>_string have the following meanings:\r
+       add     add a text or prompt string.  The pointers given to these\r
+               functions are used verbatim, no copying is done.\r
+       dup     make a copy of the text or prompt string, then add the copy\r
+               to the collection of strings in the user interface.\r
+       <function>\r
+               The function is a name for the functionality that the given\r
+               string shall be used for.  It can be one of:\r
+                       input   use the string as data prompt.\r
+                       verify  use the string as verification prompt.  This\r
+                               is used to verify a previous input.\r
+                       info    use the string for informational output.\r
+                       error   use the string for error output.\r
+   Honestly, there's currently no difference between info and error for the\r
+   moment.\r
+\r
+   UI_{add,dup}_input_boolean have the same semantics for "add" and "dup",\r
+   and are typically used when one wants to prompt for a yes/no response.\r
+\r
+\r
+   All of the functions in this group take a UI and a prompt string.\r
+   The string input and verify addition functions also take a flag argument,\r
+   a buffer for the result to end up with, a minimum input size and a maximum\r
+   input size (the result buffer MUST be large enough to be able to contain\r
+   the maximum number of characters).  Additionally, the verify addition\r
+   functions takes another buffer to compare the result against.\r
+   The boolean input functions take an action description string (which should\r
+   be safe to ignore if the expected user action is obvious, for example with\r
+   a dialog box with an OK button and a Cancel button), a string of acceptable\r
+   characters to mean OK and to mean Cancel.  The two last strings are checked\r
+   to make sure they don't have common characters.  Additionally, the same\r
+   flag argument as for the string input is taken, as well as a result buffer.\r
+   The result buffer is required to be at least one byte long.  Depending on\r
+   the answer, the first character from the OK or the Cancel character strings\r
+   will be stored in the first byte of the result buffer.  No NUL will be\r
+   added, so the result is *not* a string.\r
+\r
+   On success, the all return an index of the added information.  That index\r
+   is usefull when retrieving results with UI_get0_result(). */\r
+int UI_add_input_string(UI *ui, const char *prompt, int flags,\r
+       char *result_buf, int minsize, int maxsize);\r
+int UI_dup_input_string(UI *ui, const char *prompt, int flags,\r
+       char *result_buf, int minsize, int maxsize);\r
+int UI_add_verify_string(UI *ui, const char *prompt, int flags,\r
+       char *result_buf, int minsize, int maxsize, const char *test_buf);\r
+int UI_dup_verify_string(UI *ui, const char *prompt, int flags,\r
+       char *result_buf, int minsize, int maxsize, const char *test_buf);\r
+int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,\r
+       const char *ok_chars, const char *cancel_chars,\r
+       int flags, char *result_buf);\r
+int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,\r
+       const char *ok_chars, const char *cancel_chars,\r
+       int flags, char *result_buf);\r
+int UI_add_info_string(UI *ui, const char *text);\r
+int UI_dup_info_string(UI *ui, const char *text);\r
+int UI_add_error_string(UI *ui, const char *text);\r
+int UI_dup_error_string(UI *ui, const char *text);\r
+\r
+/* These are the possible flags.  They can be or'ed together. */\r
+/* Use to have echoing of input */\r
+#define UI_INPUT_FLAG_ECHO             0x01\r
+/* Use a default password.  Where that password is found is completely\r
+   up to the application, it might for example be in the user data set\r
+   with UI_add_user_data().  It is not recommended to have more than\r
+   one input in each UI being marked with this flag, or the application\r
+   might get confused. */\r
+#define UI_INPUT_FLAG_DEFAULT_PWD      0x02\r
+\r
+/* The user of these routines may want to define flags of their own.  The core\r
+   UI won't look at those, but will pass them on to the method routines.  They\r
+   must use higher bits so they don't get confused with the UI bits above.\r
+   UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use.  A good\r
+   example of use is this:\r
+\r
+       #define MY_UI_FLAG1     (0x01 << UI_INPUT_FLAG_USER_BASE)\r
+\r
+*/\r
+#define UI_INPUT_FLAG_USER_BASE        16\r
+\r
+\r
+/* The following function helps construct a prompt.  object_desc is a\r
+   textual short description of the object, for example "pass phrase",\r
+   and object_name is the name of the object (might be a card name or\r
+   a file name.\r
+   The returned string shall always be allocated on the heap with\r
+   OPENSSL_malloc(), and need to be free'd with OPENSSL_free().\r
+\r
+   If the ui_method doesn't contain a pointer to a user-defined prompt\r
+   constructor, a default string is built, looking like this:\r
+\r
+       "Enter {object_desc} for {object_name}:"\r
+\r
+   So, if object_desc has the value "pass phrase" and object_name has\r
+   the value "foo.key", the resulting string is:\r
+\r
+       "Enter pass phrase for foo.key:"\r
+*/\r
+char *UI_construct_prompt(UI *ui_method,\r
+       const char *object_desc, const char *object_name);\r
+\r
+\r
+/* The following function is used to store a pointer to user-specific data.\r
+   Any previous such pointer will be returned and replaced.\r
+\r
+   For callback purposes, this function makes a lot more sense than using\r
+   ex_data, since the latter requires that different parts of OpenSSL or\r
+   applications share the same ex_data index.\r
+\r
+   Note that the UI_OpenSSL() method completely ignores the user data.\r
+   Other methods may not, however.  */\r
+void *UI_add_user_data(UI *ui, void *user_data);\r
+/* We need a user data retrieving function as well.  */\r
+void *UI_get0_user_data(UI *ui);\r
+\r
+/* Return the result associated with a prompt given with the index i. */\r
+const char *UI_get0_result(UI *ui, int i);\r
+\r
+/* When all strings have been added, process the whole thing. */\r
+int UI_process(UI *ui);\r
+\r
+/* Give a user interface parametrised control commands.  This can be used to\r
+   send down an integer, a data pointer or a function pointer, as well as\r
+   be used to get information from a UI. */\r
+int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void));\r
+\r
+/* The commands */\r
+/* Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the\r
+   OpenSSL error stack before printing any info or added error messages and\r
+   before any prompting. */\r
+#define UI_CTRL_PRINT_ERRORS           1\r
+/* Check if a UI_process() is possible to do again with the same instance of\r
+   a user interface.  This makes UI_ctrl() return 1 if it is redoable, and 0\r
+   if not. */\r
+#define UI_CTRL_IS_REDOABLE            2\r
+\r
+\r
+/* Some methods may use extra data */\r
+#define UI_set_app_data(s,arg)         UI_set_ex_data(s,0,arg)\r
+#define UI_get_app_data(s)             UI_get_ex_data(s,0)\r
+int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,\r
+       CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+int UI_set_ex_data(UI *r,int idx,void *arg);\r
+void *UI_get_ex_data(UI *r, int idx);\r
+\r
+/* Use specific methods instead of the built-in one */\r
+void UI_set_default_method(const UI_METHOD *meth);\r
+const UI_METHOD *UI_get_default_method(void);\r
+const UI_METHOD *UI_get_method(UI *ui);\r
+const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);\r
+\r
+/* The method with all the built-in thingies */\r
+UI_METHOD *UI_OpenSSL(void);\r
+\r
+\r
+/* ---------- For method writers ---------- */\r
+/* A method contains a number of functions that implement the low level\r
+   of the User Interface.  The functions are:\r
+\r
+       an opener       This function starts a session, maybe by opening\r
+                       a channel to a tty, or by opening a window.\r
+       a writer        This function is called to write a given string,\r
+                       maybe to the tty, maybe as a field label in a\r
+                       window.\r
+       a flusher       This function is called to flush everything that\r
+                       has been output so far.  It can be used to actually\r
+                       display a dialog box after it has been built.\r
+       a reader        This function is called to read a given prompt,\r
+                       maybe from the tty, maybe from a field in a\r
+                       window.  Note that it's called wth all string\r
+                       structures, not only the prompt ones, so it must\r
+                       check such things itself.\r
+       a closer        This function closes the session, maybe by closing\r
+                       the channel to the tty, or closing the window.\r
+\r
+   All these functions are expected to return:\r
+\r
+       0       on error.\r
+       1       on success.\r
+       -1      on out-of-band events, for example if some prompting has\r
+               been canceled (by pressing Ctrl-C, for example).  This is\r
+               only checked when returned by the flusher or the reader.\r
+\r
+   The way this is used, the opener is first called, then the writer for all\r
+   strings, then the flusher, then the reader for all strings and finally the\r
+   closer.  Note that if you want to prompt from a terminal or other command\r
+   line interface, the best is to have the reader also write the prompts\r
+   instead of having the writer do it.  If you want to prompt from a dialog\r
+   box, the writer can be used to build up the contents of the box, and the\r
+   flusher to actually display the box and run the event loop until all data\r
+   has been given, after which the reader only grabs the given data and puts\r
+   them back into the UI strings.\r
+\r
+   All method functions take a UI as argument.  Additionally, the writer and\r
+   the reader take a UI_STRING.\r
+*/\r
+\r
+/* The UI_STRING type is the data structure that contains all the needed info\r
+   about a string or a prompt, including test data for a verification prompt.\r
+*/\r
+DECLARE_STACK_OF(UI_STRING)\r
+typedef struct ui_string_st UI_STRING;\r
+\r
+/* The different types of strings that are currently supported.\r
+   This is only needed by method authors. */\r
+enum UI_string_types\r
+       {\r
+       UIT_NONE=0,\r
+       UIT_PROMPT,             /* Prompt for a string */\r
+       UIT_VERIFY,             /* Prompt for a string and verify */\r
+       UIT_BOOLEAN,            /* Prompt for a yes/no response */\r
+       UIT_INFO,               /* Send info to the user */\r
+       UIT_ERROR               /* Send an error message to the user */\r
+       };\r
+\r
+/* Create and manipulate methods */\r
+UI_METHOD *UI_create_method(char *name);\r
+void UI_destroy_method(UI_METHOD *ui_method);\r
+int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui));\r
+int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis));\r
+int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui));\r
+int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis));\r
+int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui));\r
+int (*UI_method_get_opener(UI_METHOD *method))(UI*);\r
+int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*);\r
+int (*UI_method_get_flusher(UI_METHOD *method))(UI*);\r
+int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*);\r
+int (*UI_method_get_closer(UI_METHOD *method))(UI*);\r
+\r
+/* The following functions are helpers for method writers to access relevant\r
+   data from a UI_STRING. */\r
+\r
+/* Return type of the UI_STRING */\r
+enum UI_string_types UI_get_string_type(UI_STRING *uis);\r
+/* Return input flags of the UI_STRING */\r
+int UI_get_input_flags(UI_STRING *uis);\r
+/* Return the actual string to output (the prompt, info or error) */\r
+const char *UI_get0_output_string(UI_STRING *uis);\r
+/* Return the optional action string to output (the boolean promtp instruction) */\r
+const char *UI_get0_action_string(UI_STRING *uis);\r
+/* Return the result of a prompt */\r
+const char *UI_get0_result_string(UI_STRING *uis);\r
+/* Return the string to test the result against.  Only useful with verifies. */\r
+const char *UI_get0_test_string(UI_STRING *uis);\r
+/* Return the required minimum size of the result */\r
+int UI_get_result_minsize(UI_STRING *uis);\r
+/* Return the required maximum size of the result */\r
+int UI_get_result_maxsize(UI_STRING *uis);\r
+/* Set the result of a UI_STRING. */\r
+int UI_set_result(UI *ui, UI_STRING *uis, const char *result);\r
+\r
+\r
+/* A couple of popular utility functions */\r
+int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify);\r
+int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);\r
+\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_UI_strings(void);\r
+\r
+/* Error codes for the UI functions. */\r
+\r
+/* Function codes. */\r
+#define UI_F_GENERAL_ALLOCATE_BOOLEAN                   108\r
+#define UI_F_GENERAL_ALLOCATE_PROMPT                    109\r
+#define UI_F_GENERAL_ALLOCATE_STRING                    100\r
+#define UI_F_UI_CTRL                                    111\r
+#define UI_F_UI_DUP_ERROR_STRING                        101\r
+#define UI_F_UI_DUP_INFO_STRING                                 102\r
+#define UI_F_UI_DUP_INPUT_BOOLEAN                       110\r
+#define UI_F_UI_DUP_INPUT_STRING                        103\r
+#define UI_F_UI_DUP_VERIFY_STRING                       106\r
+#define UI_F_UI_GET0_RESULT                             107\r
+#define UI_F_UI_NEW_METHOD                              104\r
+#define UI_F_UI_SET_RESULT                              105\r
+\r
+/* Reason codes. */\r
+#define UI_R_COMMON_OK_AND_CANCEL_CHARACTERS            104\r
+#define UI_R_INDEX_TOO_LARGE                            102\r
+#define UI_R_INDEX_TOO_SMALL                            103\r
+#define UI_R_NO_RESULT_BUFFER                           105\r
+#define UI_R_RESULT_TOO_LARGE                           100\r
+#define UI_R_RESULT_TOO_SMALL                           101\r
+#define UI_R_UNKNOWN_CONTROL_COMMAND                    106\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ui_compat.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/ui_compat.h
new file mode 100644 (file)
index 0000000..0209438
--- /dev/null
@@ -0,0 +1,83 @@
+/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */\r
+/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL\r
+ * project 2001.\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 2001 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    openssl-core@openssl.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+\r
+#ifndef HEADER_UI_COMPAT_H\r
+#define HEADER_UI_COMPAT_H\r
+\r
+#include <openssl/opensslconf.h>\r
+#include <openssl/ui.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* The following functions were previously part of the DES section,\r
+   and are provided here for backward compatibility reasons. */\r
+\r
+#define des_read_pw_string(b,l,p,v) \\r
+       _ossl_old_des_read_pw_string((b),(l),(p),(v))\r
+#define des_read_pw(b,bf,s,p,v) \\r
+       _ossl_old_des_read_pw((b),(bf),(s),(p),(v))\r
+\r
+int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify);\r
+int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/x509.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/x509.h
new file mode 100644 (file)
index 0000000..4166e7a
--- /dev/null
@@ -0,0 +1,1340 @@
+/* crypto/x509/x509.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+/* ====================================================================\r
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.\r
+ * ECDH support in OpenSSL originally developed by \r
+ * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.\r
+ */\r
+\r
+#ifndef HEADER_X509_H\r
+#define HEADER_X509_H\r
+\r
+#include <openssl/e_os2.h>\r
+#include <openssl/symhacks.h>\r
+#ifndef OPENSSL_NO_BUFFER\r
+#include <openssl/buffer.h>\r
+#endif\r
+#ifndef OPENSSL_NO_EVP\r
+#include <openssl/evp.h>\r
+#endif\r
+#ifndef OPENSSL_NO_BIO\r
+#include <openssl/bio.h>\r
+#endif\r
+#include <openssl/stack.h>\r
+#include <openssl/asn1.h>\r
+#include <openssl/safestack.h>\r
+\r
+#ifndef OPENSSL_NO_EC\r
+#include <openssl/ec.h>\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_ECDSA\r
+#include <openssl/ecdsa.h>\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_ECDH\r
+#include <openssl/ecdh.h>\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_DEPRECATED\r
+#ifndef OPENSSL_NO_RSA\r
+#include <openssl/rsa.h>\r
+#endif\r
+#ifndef OPENSSL_NO_DSA\r
+#include <openssl/dsa.h>\r
+#endif\r
+#ifndef OPENSSL_NO_DH\r
+#include <openssl/dh.h>\r
+#endif\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_SHA\r
+#include <openssl/sha.h>\r
+#endif\r
+#include <openssl/ossl_typ.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef OPENSSL_SYS_WIN32\r
+/* Under Win32 these are defined in wincrypt.h */\r
+#undef X509_NAME\r
+#undef X509_CERT_PAIR\r
+#endif\r
+\r
+#define X509_FILETYPE_PEM      1\r
+#define X509_FILETYPE_ASN1     2\r
+#define X509_FILETYPE_DEFAULT  3\r
+\r
+#define X509v3_KU_DIGITAL_SIGNATURE    0x0080\r
+#define X509v3_KU_NON_REPUDIATION      0x0040\r
+#define X509v3_KU_KEY_ENCIPHERMENT     0x0020\r
+#define X509v3_KU_DATA_ENCIPHERMENT    0x0010\r
+#define X509v3_KU_KEY_AGREEMENT                0x0008\r
+#define X509v3_KU_KEY_CERT_SIGN                0x0004\r
+#define X509v3_KU_CRL_SIGN             0x0002\r
+#define X509v3_KU_ENCIPHER_ONLY                0x0001\r
+#define X509v3_KU_DECIPHER_ONLY                0x8000\r
+#define X509v3_KU_UNDEF                        0xffff\r
+\r
+typedef struct X509_objects_st\r
+       {\r
+       int nid;\r
+       int (*a2i)(void);\r
+       int (*i2a)(void);\r
+       } X509_OBJECTS;\r
+\r
+struct X509_algor_st\r
+       {\r
+       ASN1_OBJECT *algorithm;\r
+       ASN1_TYPE *parameter;\r
+       } /* X509_ALGOR */;\r
+\r
+DECLARE_STACK_OF(X509_ALGOR)\r
+DECLARE_ASN1_SET_OF(X509_ALGOR)\r
+\r
+typedef struct X509_val_st\r
+       {\r
+       ASN1_TIME *notBefore;\r
+       ASN1_TIME *notAfter;\r
+       } X509_VAL;\r
+\r
+typedef struct X509_pubkey_st\r
+       {\r
+       X509_ALGOR *algor;\r
+       ASN1_BIT_STRING *public_key;\r
+       EVP_PKEY *pkey;\r
+       } X509_PUBKEY;\r
+\r
+typedef struct X509_sig_st\r
+       {\r
+       X509_ALGOR *algor;\r
+       ASN1_OCTET_STRING *digest;\r
+       } X509_SIG;\r
+\r
+typedef struct X509_name_entry_st\r
+       {\r
+       ASN1_OBJECT *object;\r
+       ASN1_STRING *value;\r
+       int set;\r
+       int size;       /* temp variable */\r
+       } X509_NAME_ENTRY;\r
+\r
+DECLARE_STACK_OF(X509_NAME_ENTRY)\r
+DECLARE_ASN1_SET_OF(X509_NAME_ENTRY)\r
+\r
+/* we always keep X509_NAMEs in 2 forms. */\r
+struct X509_name_st\r
+       {\r
+       STACK_OF(X509_NAME_ENTRY) *entries;\r
+       int modified;   /* true if 'bytes' needs to be built */\r
+#ifndef OPENSSL_NO_BUFFER\r
+       BUF_MEM *bytes;\r
+#else\r
+       char *bytes;\r
+#endif\r
+       unsigned long hash; /* Keep the hash around for lookups */\r
+       } /* X509_NAME */;\r
+\r
+DECLARE_STACK_OF(X509_NAME)\r
+\r
+#define X509_EX_V_NETSCAPE_HACK                0x8000\r
+#define X509_EX_V_INIT                 0x0001\r
+typedef struct X509_extension_st\r
+       {\r
+       ASN1_OBJECT *object;\r
+       ASN1_BOOLEAN critical;\r
+       ASN1_OCTET_STRING *value;\r
+       } X509_EXTENSION;\r
+\r
+DECLARE_STACK_OF(X509_EXTENSION)\r
+DECLARE_ASN1_SET_OF(X509_EXTENSION)\r
+\r
+/* a sequence of these are used */\r
+typedef struct x509_attributes_st\r
+       {\r
+       ASN1_OBJECT *object;\r
+       int single; /* 0 for a set, 1 for a single item (which is wrong) */\r
+       union   {\r
+               char            *ptr;\r
+/* 0 */                STACK_OF(ASN1_TYPE) *set;\r
+/* 1 */                ASN1_TYPE       *single;\r
+               } value;\r
+       } X509_ATTRIBUTE;\r
+\r
+DECLARE_STACK_OF(X509_ATTRIBUTE)\r
+DECLARE_ASN1_SET_OF(X509_ATTRIBUTE)\r
+\r
+\r
+typedef struct X509_req_info_st\r
+       {\r
+       ASN1_ENCODING enc;\r
+       ASN1_INTEGER *version;\r
+       X509_NAME *subject;\r
+       X509_PUBKEY *pubkey;\r
+       /*  d=2 hl=2 l=  0 cons: cont: 00 */\r
+       STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */\r
+       } X509_REQ_INFO;\r
+\r
+typedef struct X509_req_st\r
+       {\r
+       X509_REQ_INFO *req_info;\r
+       X509_ALGOR *sig_alg;\r
+       ASN1_BIT_STRING *signature;\r
+       int references;\r
+       } X509_REQ;\r
+\r
+typedef struct x509_cinf_st\r
+       {\r
+       ASN1_INTEGER *version;          /* [ 0 ] default of v1 */\r
+       ASN1_INTEGER *serialNumber;\r
+       X509_ALGOR *signature;\r
+       X509_NAME *issuer;\r
+       X509_VAL *validity;\r
+       X509_NAME *subject;\r
+       X509_PUBKEY *key;\r
+       ASN1_BIT_STRING *issuerUID;             /* [ 1 ] optional in v2 */\r
+       ASN1_BIT_STRING *subjectUID;            /* [ 2 ] optional in v2 */\r
+       STACK_OF(X509_EXTENSION) *extensions;   /* [ 3 ] optional in v3 */\r
+       } X509_CINF;\r
+\r
+/* This stuff is certificate "auxiliary info"\r
+ * it contains details which are useful in certificate\r
+ * stores and databases. When used this is tagged onto\r
+ * the end of the certificate itself\r
+ */\r
+\r
+typedef struct x509_cert_aux_st\r
+       {\r
+       STACK_OF(ASN1_OBJECT) *trust;           /* trusted uses */\r
+       STACK_OF(ASN1_OBJECT) *reject;          /* rejected uses */\r
+       ASN1_UTF8STRING *alias;                 /* "friendly name" */\r
+       ASN1_OCTET_STRING *keyid;               /* key id of private key */\r
+       STACK_OF(X509_ALGOR) *other;            /* other unspecified info */\r
+       } X509_CERT_AUX;\r
+\r
+struct x509_st\r
+       {\r
+       X509_CINF *cert_info;\r
+       X509_ALGOR *sig_alg;\r
+       ASN1_BIT_STRING *signature;\r
+       int valid;\r
+       int references;\r
+       char *name;\r
+       CRYPTO_EX_DATA ex_data;\r
+       /* These contain copies of various extension values */\r
+       long ex_pathlen;\r
+       long ex_pcpathlen;\r
+       unsigned long ex_flags;\r
+       unsigned long ex_kusage;\r
+       unsigned long ex_xkusage;\r
+       unsigned long ex_nscert;\r
+       ASN1_OCTET_STRING *skid;\r
+       struct AUTHORITY_KEYID_st *akid;\r
+       X509_POLICY_CACHE *policy_cache;\r
+#ifndef OPENSSL_NO_SHA\r
+       unsigned char sha1_hash[SHA_DIGEST_LENGTH];\r
+#endif\r
+       X509_CERT_AUX *aux;\r
+       } /* X509 */;\r
+\r
+DECLARE_STACK_OF(X509)\r
+DECLARE_ASN1_SET_OF(X509)\r
+\r
+/* This is used for a table of trust checking functions */\r
+\r
+typedef struct x509_trust_st {\r
+       int trust;\r
+       int flags;\r
+       int (*check_trust)(struct x509_trust_st *, X509 *, int);\r
+       char *name;\r
+       int arg1;\r
+       void *arg2;\r
+} X509_TRUST;\r
+\r
+DECLARE_STACK_OF(X509_TRUST)\r
+\r
+typedef struct x509_cert_pair_st {\r
+       X509 *forward;\r
+       X509 *reverse;\r
+} X509_CERT_PAIR;\r
+\r
+/* standard trust ids */\r
+\r
+#define X509_TRUST_DEFAULT     -1      /* Only valid in purpose settings */\r
+\r
+#define X509_TRUST_COMPAT      1\r
+#define X509_TRUST_SSL_CLIENT  2\r
+#define X509_TRUST_SSL_SERVER  3\r
+#define X509_TRUST_EMAIL       4\r
+#define X509_TRUST_OBJECT_SIGN 5\r
+#define X509_TRUST_OCSP_SIGN   6\r
+#define X509_TRUST_OCSP_REQUEST        7\r
+\r
+/* Keep these up to date! */\r
+#define X509_TRUST_MIN         1\r
+#define X509_TRUST_MAX         7\r
+\r
+\r
+/* trust_flags values */\r
+#define        X509_TRUST_DYNAMIC      1\r
+#define        X509_TRUST_DYNAMIC_NAME 2\r
+\r
+/* check_trust return codes */\r
+\r
+#define X509_TRUST_TRUSTED     1\r
+#define X509_TRUST_REJECTED    2\r
+#define X509_TRUST_UNTRUSTED   3\r
+\r
+/* Flags for X509_print_ex() */\r
+\r
+#define        X509_FLAG_COMPAT                0\r
+#define        X509_FLAG_NO_HEADER             1L\r
+#define        X509_FLAG_NO_VERSION            (1L << 1)\r
+#define        X509_FLAG_NO_SERIAL             (1L << 2)\r
+#define        X509_FLAG_NO_SIGNAME            (1L << 3)\r
+#define        X509_FLAG_NO_ISSUER             (1L << 4)\r
+#define        X509_FLAG_NO_VALIDITY           (1L << 5)\r
+#define        X509_FLAG_NO_SUBJECT            (1L << 6)\r
+#define        X509_FLAG_NO_PUBKEY             (1L << 7)\r
+#define        X509_FLAG_NO_EXTENSIONS         (1L << 8)\r
+#define        X509_FLAG_NO_SIGDUMP            (1L << 9)\r
+#define        X509_FLAG_NO_AUX                (1L << 10)\r
+#define        X509_FLAG_NO_ATTRIBUTES         (1L << 11)\r
+\r
+/* Flags specific to X509_NAME_print_ex() */   \r
+\r
+/* The field separator information */\r
+\r
+#define XN_FLAG_SEP_MASK       (0xf << 16)\r
+\r
+#define XN_FLAG_COMPAT         0               /* Traditional SSLeay: use old X509_NAME_print */\r
+#define XN_FLAG_SEP_COMMA_PLUS (1 << 16)       /* RFC2253 ,+ */\r
+#define XN_FLAG_SEP_CPLUS_SPC  (2 << 16)       /* ,+ spaced: more readable */\r
+#define XN_FLAG_SEP_SPLUS_SPC  (3 << 16)       /* ;+ spaced */\r
+#define XN_FLAG_SEP_MULTILINE  (4 << 16)       /* One line per field */\r
+\r
+#define XN_FLAG_DN_REV         (1 << 20)       /* Reverse DN order */\r
+\r
+/* How the field name is shown */\r
+\r
+#define XN_FLAG_FN_MASK                (0x3 << 21)\r
+\r
+#define XN_FLAG_FN_SN          0               /* Object short name */\r
+#define XN_FLAG_FN_LN          (1 << 21)       /* Object long name */\r
+#define XN_FLAG_FN_OID         (2 << 21)       /* Always use OIDs */\r
+#define XN_FLAG_FN_NONE                (3 << 21)       /* No field names */\r
+\r
+#define XN_FLAG_SPC_EQ         (1 << 23)       /* Put spaces round '=' */\r
+\r
+/* This determines if we dump fields we don't recognise:\r
+ * RFC2253 requires this.\r
+ */\r
+\r
+#define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24)\r
+\r
+#define XN_FLAG_FN_ALIGN       (1 << 25)       /* Align field names to 20 characters */\r
+\r
+/* Complete set of RFC2253 flags */\r
+\r
+#define XN_FLAG_RFC2253 (ASN1_STRFLGS_RFC2253 | \\r
+                       XN_FLAG_SEP_COMMA_PLUS | \\r
+                       XN_FLAG_DN_REV | \\r
+                       XN_FLAG_FN_SN | \\r
+                       XN_FLAG_DUMP_UNKNOWN_FIELDS)\r
+\r
+/* readable oneline form */\r
+\r
+#define XN_FLAG_ONELINE (ASN1_STRFLGS_RFC2253 | \\r
+                       ASN1_STRFLGS_ESC_QUOTE | \\r
+                       XN_FLAG_SEP_CPLUS_SPC | \\r
+                       XN_FLAG_SPC_EQ | \\r
+                       XN_FLAG_FN_SN)\r
+\r
+/* readable multiline form */\r
+\r
+#define XN_FLAG_MULTILINE (ASN1_STRFLGS_ESC_CTRL | \\r
+                       ASN1_STRFLGS_ESC_MSB | \\r
+                       XN_FLAG_SEP_MULTILINE | \\r
+                       XN_FLAG_SPC_EQ | \\r
+                       XN_FLAG_FN_LN | \\r
+                       XN_FLAG_FN_ALIGN)\r
+\r
+typedef struct X509_revoked_st\r
+       {\r
+       ASN1_INTEGER *serialNumber;\r
+       ASN1_TIME *revocationDate;\r
+       STACK_OF(X509_EXTENSION) /* optional */ *extensions;\r
+       int sequence; /* load sequence */\r
+       } X509_REVOKED;\r
+\r
+DECLARE_STACK_OF(X509_REVOKED)\r
+DECLARE_ASN1_SET_OF(X509_REVOKED)\r
+\r
+typedef struct X509_crl_info_st\r
+       {\r
+       ASN1_INTEGER *version;\r
+       X509_ALGOR *sig_alg;\r
+       X509_NAME *issuer;\r
+       ASN1_TIME *lastUpdate;\r
+       ASN1_TIME *nextUpdate;\r
+       STACK_OF(X509_REVOKED) *revoked;\r
+       STACK_OF(X509_EXTENSION) /* [0] */ *extensions;\r
+       ASN1_ENCODING enc;\r
+       } X509_CRL_INFO;\r
+\r
+struct X509_crl_st\r
+       {\r
+       /* actual signature */\r
+       X509_CRL_INFO *crl;\r
+       X509_ALGOR *sig_alg;\r
+       ASN1_BIT_STRING *signature;\r
+       int references;\r
+       } /* X509_CRL */;\r
+\r
+DECLARE_STACK_OF(X509_CRL)\r
+DECLARE_ASN1_SET_OF(X509_CRL)\r
+\r
+typedef struct private_key_st\r
+       {\r
+       int version;\r
+       /* The PKCS#8 data types */\r
+       X509_ALGOR *enc_algor;\r
+       ASN1_OCTET_STRING *enc_pkey;    /* encrypted pub key */\r
+\r
+       /* When decrypted, the following will not be NULL */\r
+       EVP_PKEY *dec_pkey;\r
+\r
+       /* used to encrypt and decrypt */\r
+       int key_length;\r
+       char *key_data;\r
+       int key_free;   /* true if we should auto free key_data */\r
+\r
+       /* expanded version of 'enc_algor' */\r
+       EVP_CIPHER_INFO cipher;\r
+\r
+       int references;\r
+       } X509_PKEY;\r
+\r
+#ifndef OPENSSL_NO_EVP\r
+typedef struct X509_info_st\r
+       {\r
+       X509 *x509;\r
+       X509_CRL *crl;\r
+       X509_PKEY *x_pkey;\r
+\r
+       EVP_CIPHER_INFO enc_cipher;\r
+       int enc_len;\r
+       char *enc_data;\r
+\r
+       int references;\r
+       } X509_INFO;\r
+\r
+DECLARE_STACK_OF(X509_INFO)\r
+#endif\r
+\r
+/* The next 2 structures and their 8 routines were sent to me by\r
+ * Pat Richard <patr@x509.com> and are used to manipulate\r
+ * Netscapes spki structures - useful if you are writing a CA web page\r
+ */\r
+typedef struct Netscape_spkac_st\r
+       {\r
+       X509_PUBKEY *pubkey;\r
+       ASN1_IA5STRING *challenge;      /* challenge sent in atlas >= PR2 */\r
+       } NETSCAPE_SPKAC;\r
+\r
+typedef struct Netscape_spki_st\r
+       {\r
+       NETSCAPE_SPKAC *spkac;  /* signed public key and challenge */\r
+       X509_ALGOR *sig_algor;\r
+       ASN1_BIT_STRING *signature;\r
+       } NETSCAPE_SPKI;\r
+\r
+/* Netscape certificate sequence structure */\r
+typedef struct Netscape_certificate_sequence\r
+       {\r
+       ASN1_OBJECT *type;\r
+       STACK_OF(X509) *certs;\r
+       } NETSCAPE_CERT_SEQUENCE;\r
+\r
+/* Unused (and iv length is wrong)\r
+typedef struct CBCParameter_st\r
+       {\r
+       unsigned char iv[8];\r
+       } CBC_PARAM;\r
+*/\r
+\r
+/* Password based encryption structure */\r
+\r
+typedef struct PBEPARAM_st {\r
+ASN1_OCTET_STRING *salt;\r
+ASN1_INTEGER *iter;\r
+} PBEPARAM;\r
+\r
+/* Password based encryption V2 structures */\r
+\r
+typedef struct PBE2PARAM_st {\r
+X509_ALGOR *keyfunc;\r
+X509_ALGOR *encryption;\r
+} PBE2PARAM;\r
+\r
+typedef struct PBKDF2PARAM_st {\r
+ASN1_TYPE *salt;       /* Usually OCTET STRING but could be anything */\r
+ASN1_INTEGER *iter;\r
+ASN1_INTEGER *keylength;\r
+X509_ALGOR *prf;\r
+} PBKDF2PARAM;\r
+\r
+\r
+/* PKCS#8 private key info structure */\r
+\r
+typedef struct pkcs8_priv_key_info_st\r
+        {\r
+        int broken;     /* Flag for various broken formats */\r
+#define PKCS8_OK               0\r
+#define PKCS8_NO_OCTET         1\r
+#define PKCS8_EMBEDDED_PARAM   2\r
+#define PKCS8_NS_DB            3\r
+        ASN1_INTEGER *version;\r
+        X509_ALGOR *pkeyalg;\r
+        ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */\r
+        STACK_OF(X509_ATTRIBUTE) *attributes;\r
+        } PKCS8_PRIV_KEY_INFO;\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#include <openssl/x509_vfy.h>\r
+#include <openssl/pkcs7.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef SSLEAY_MACROS\r
+#define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\\r
+       a->signature,(char *)a->cert_info,r)\r
+#define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \\r
+       a->sig_alg,a->signature,(char *)a->req_info,r)\r
+#define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \\r
+       a->sig_alg, a->signature,(char *)a->crl,r)\r
+\r
+#define X509_sign(x,pkey,md) \\r
+       ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \\r
+               x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)\r
+#define X509_REQ_sign(x,pkey,md) \\r
+       ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \\r
+               x->signature, (char *)x->req_info,pkey,md)\r
+#define X509_CRL_sign(x,pkey,md) \\r
+       ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \\r
+               x->signature, (char *)x->crl,pkey,md)\r
+#define NETSCAPE_SPKI_sign(x,pkey,md) \\r
+       ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \\r
+               x->signature, (char *)x->spkac,pkey,md)\r
+\r
+#define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \\r
+               (char *(*)())d2i_X509,(char *)x509)\r
+#define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\\r
+               (int (*)())i2d_X509_ATTRIBUTE, \\r
+               (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa)\r
+#define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \\r
+               (int (*)())i2d_X509_EXTENSION, \\r
+               (char *(*)())d2i_X509_EXTENSION,(char *)ex)\r
+#define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \\r
+               (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))\r
+#define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)\r
+#define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \\r
+               (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))\r
+#define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)\r
+\r
+#define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \\r
+               (char *(*)())d2i_X509_CRL,(char *)crl)\r
+#define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \\r
+               X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\\r
+               (unsigned char **)(crl))\r
+#define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\\r
+               (unsigned char *)crl)\r
+#define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \\r
+               X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\\r
+               (unsigned char **)(crl))\r
+#define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\\r
+               (unsigned char *)crl)\r
+\r
+#define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \\r
+               (char *(*)())d2i_PKCS7,(char *)p7)\r
+#define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \\r
+               PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\\r
+               (unsigned char **)(p7))\r
+#define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\\r
+               (unsigned char *)p7)\r
+#define d2i_PKCS7_bio(bp,p7) (PKCS7 *)ASN1_d2i_bio((char *(*)()) \\r
+               PKCS7_new,(char *(*)())d2i_PKCS7, (bp),\\r
+               (unsigned char **)(p7))\r
+#define i2d_PKCS7_bio(bp,p7) ASN1_i2d_bio(i2d_PKCS7,bp,\\r
+               (unsigned char *)p7)\r
+\r
+#define X509_REQ_dup(req) (X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, \\r
+               (char *(*)())d2i_X509_REQ,(char *)req)\r
+#define d2i_X509_REQ_fp(fp,req) (X509_REQ *)ASN1_d2i_fp((char *(*)())\\r
+               X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),\\r
+               (unsigned char **)(req))\r
+#define i2d_X509_REQ_fp(fp,req) ASN1_i2d_fp(i2d_X509_REQ,fp,\\r
+               (unsigned char *)req)\r
+#define d2i_X509_REQ_bio(bp,req) (X509_REQ *)ASN1_d2i_bio((char *(*)())\\r
+               X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),\\r
+               (unsigned char **)(req))\r
+#define i2d_X509_REQ_bio(bp,req) ASN1_i2d_bio(i2d_X509_REQ,bp,\\r
+               (unsigned char *)req)\r
+\r
+#define RSAPublicKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, \\r
+               (char *(*)())d2i_RSAPublicKey,(char *)rsa)\r
+#define RSAPrivateKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, \\r
+               (char *(*)())d2i_RSAPrivateKey,(char *)rsa)\r
+\r
+#define d2i_RSAPrivateKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\\r
+               RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), \\r
+               (unsigned char **)(rsa))\r
+#define i2d_RSAPrivateKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPrivateKey,fp, \\r
+               (unsigned char *)rsa)\r
+#define d2i_RSAPrivateKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\\r
+               RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), \\r
+               (unsigned char **)(rsa))\r
+#define i2d_RSAPrivateKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPrivateKey,bp, \\r
+               (unsigned char *)rsa)\r
+\r
+#define d2i_RSAPublicKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\\r
+               RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), \\r
+               (unsigned char **)(rsa))\r
+#define i2d_RSAPublicKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPublicKey,fp, \\r
+               (unsigned char *)rsa)\r
+#define d2i_RSAPublicKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\\r
+               RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), \\r
+               (unsigned char **)(rsa))\r
+#define i2d_RSAPublicKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPublicKey,bp, \\r
+               (unsigned char *)rsa)\r
+\r
+#define d2i_DSAPrivateKey_fp(fp,dsa) (DSA *)ASN1_d2i_fp((char *(*)())\\r
+               DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), \\r
+               (unsigned char **)(dsa))\r
+#define i2d_DSAPrivateKey_fp(fp,dsa) ASN1_i2d_fp(i2d_DSAPrivateKey,fp, \\r
+               (unsigned char *)dsa)\r
+#define d2i_DSAPrivateKey_bio(bp,dsa) (DSA *)ASN1_d2i_bio((char *(*)())\\r
+               DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), \\r
+               (unsigned char **)(dsa))\r
+#define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \\r
+               (unsigned char *)dsa)\r
+\r
+#define d2i_ECPrivateKey_fp(fp,ecdsa) (EC_KEY *)ASN1_d2i_fp((char *(*)())\\r
+               EC_KEY_new,(char *(*)())d2i_ECPrivateKey, (fp), \\r
+               (unsigned char **)(ecdsa))\r
+#define i2d_ECPrivateKey_fp(fp,ecdsa) ASN1_i2d_fp(i2d_ECPrivateKey,fp, \\r
+               (unsigned char *)ecdsa)\r
+#define d2i_ECPrivateKey_bio(bp,ecdsa) (EC_KEY *)ASN1_d2i_bio((char *(*)())\\r
+               EC_KEY_new,(char *(*)())d2i_ECPrivateKey, (bp), \\r
+               (unsigned char **)(ecdsa))\r
+#define i2d_ECPrivateKey_bio(bp,ecdsa) ASN1_i2d_bio(i2d_ECPrivateKey,bp, \\r
+               (unsigned char *)ecdsa)\r
+\r
+#define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\\r
+               (char *(*)())d2i_X509_ALGOR,(char *)xn)\r
+\r
+#define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \\r
+               (char *(*)())d2i_X509_NAME,(char *)xn)\r
+#define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \\r
+               (int (*)())i2d_X509_NAME_ENTRY, \\r
+               (char *(*)())d2i_X509_NAME_ENTRY,\\r
+               (char *)ne)\r
+\r
+#define X509_digest(data,type,md,len) \\r
+       ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)\r
+#define X509_NAME_digest(data,type,md,len) \\r
+       ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)\r
+#ifndef PKCS7_ISSUER_AND_SERIAL_digest\r
+#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \\r
+       ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\\r
+               (char *)data,md,len)\r
+#endif\r
+#endif\r
+\r
+#define X509_EXT_PACK_UNKNOWN  1\r
+#define X509_EXT_PACK_STRING   2\r
+\r
+#define                X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version)\r
+/* #define     X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */\r
+#define                X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)\r
+#define                X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)\r
+#define                X509_extract_key(x)     X509_get_pubkey(x) /*****/\r
+#define                X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version)\r
+#define                X509_REQ_get_subject_name(x) ((x)->req_info->subject)\r
+#define                X509_REQ_extract_key(a) X509_REQ_get_pubkey(a)\r
+#define                X509_name_cmp(a,b)      X509_NAME_cmp((a),(b))\r
+#define                X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm))\r
+\r
+#define                X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version)\r
+#define        X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate)\r
+#define        X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate)\r
+#define                X509_CRL_get_issuer(x) ((x)->crl->issuer)\r
+#define                X509_CRL_get_REVOKED(x) ((x)->crl->revoked)\r
+\r
+/* This one is only used so that a binary form can output, as in\r
+ * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */\r
+#define        X509_get_X509_PUBKEY(x) ((x)->cert_info->key)\r
+\r
+\r
+const char *X509_verify_cert_error_string(long n);\r
+\r
+#ifndef SSLEAY_MACROS\r
+#ifndef OPENSSL_NO_EVP\r
+int X509_verify(X509 *a, EVP_PKEY *r);\r
+\r
+int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);\r
+int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);\r
+int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);\r
+\r
+NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len);\r
+char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x);\r
+EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x);\r
+int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey);\r
+\r
+int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki);\r
+\r
+int X509_signature_print(BIO *bp,X509_ALGOR *alg, ASN1_STRING *sig);\r
+\r
+int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);\r
+int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md);\r
+int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md);\r
+int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md);\r
+\r
+int X509_pubkey_digest(const X509 *data,const EVP_MD *type,\r
+               unsigned char *md, unsigned int *len);\r
+int X509_digest(const X509 *data,const EVP_MD *type,\r
+               unsigned char *md, unsigned int *len);\r
+int X509_CRL_digest(const X509_CRL *data,const EVP_MD *type,\r
+               unsigned char *md, unsigned int *len);\r
+int X509_REQ_digest(const X509_REQ *data,const EVP_MD *type,\r
+               unsigned char *md, unsigned int *len);\r
+int X509_NAME_digest(const X509_NAME *data,const EVP_MD *type,\r
+               unsigned char *md, unsigned int *len);\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_FP_API\r
+X509 *d2i_X509_fp(FILE *fp, X509 **x509);\r
+int i2d_X509_fp(FILE *fp,X509 *x509);\r
+X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl);\r
+int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl);\r
+X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req);\r
+int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req);\r
+#ifndef OPENSSL_NO_RSA\r
+RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa);\r
+int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);\r
+RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa);\r
+int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);\r
+RSA *d2i_RSA_PUBKEY_fp(FILE *fp,RSA **rsa);\r
+int i2d_RSA_PUBKEY_fp(FILE *fp,RSA *rsa);\r
+#endif\r
+#ifndef OPENSSL_NO_DSA\r
+DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa);\r
+int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa);\r
+DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);\r
+int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);\r
+#endif\r
+#ifndef OPENSSL_NO_EC\r
+EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey);\r
+int   i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey);\r
+EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey);\r
+int   i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey);\r
+#endif\r
+X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8);\r
+int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8);\r
+PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,\r
+                                               PKCS8_PRIV_KEY_INFO **p8inf);\r
+int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf);\r
+int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key);\r
+int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey);\r
+EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);\r
+int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey);\r
+EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a);\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+X509 *d2i_X509_bio(BIO *bp,X509 **x509);\r
+int i2d_X509_bio(BIO *bp,X509 *x509);\r
+X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl);\r
+int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl);\r
+X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req);\r
+int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req);\r
+#ifndef OPENSSL_NO_RSA\r
+RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);\r
+int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);\r
+RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa);\r
+int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);\r
+RSA *d2i_RSA_PUBKEY_bio(BIO *bp,RSA **rsa);\r
+int i2d_RSA_PUBKEY_bio(BIO *bp,RSA *rsa);\r
+#endif\r
+#ifndef OPENSSL_NO_DSA\r
+DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa);\r
+int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa);\r
+DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);\r
+int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);\r
+#endif\r
+#ifndef OPENSSL_NO_EC\r
+EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey);\r
+int   i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey);\r
+EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey);\r
+int   i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey);\r
+#endif\r
+X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8);\r
+int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);\r
+PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,\r
+                                               PKCS8_PRIV_KEY_INFO **p8inf);\r
+int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf);\r
+int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key);\r
+int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey);\r
+EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);\r
+int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey);\r
+EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a);\r
+#endif\r
+\r
+X509 *X509_dup(X509 *x509);\r
+X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);\r
+X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);\r
+X509_CRL *X509_CRL_dup(X509_CRL *crl);\r
+X509_REQ *X509_REQ_dup(X509_REQ *req);\r
+X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);\r
+X509_NAME *X509_NAME_dup(X509_NAME *xn);\r
+X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);\r
+\r
+#endif /* !SSLEAY_MACROS */\r
+\r
+int            X509_cmp_time(ASN1_TIME *s, time_t *t);\r
+int            X509_cmp_current_time(ASN1_TIME *s);\r
+ASN1_TIME *    X509_time_adj(ASN1_TIME *s, long adj, time_t *t);\r
+ASN1_TIME *    X509_gmtime_adj(ASN1_TIME *s, long adj);\r
+\r
+const char *   X509_get_default_cert_area(void );\r
+const char *   X509_get_default_cert_dir(void );\r
+const char *   X509_get_default_cert_file(void );\r
+const char *   X509_get_default_cert_dir_env(void );\r
+const char *   X509_get_default_cert_file_env(void );\r
+const char *   X509_get_default_private_dir(void );\r
+\r
+X509_REQ *     X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);\r
+X509 *         X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);\r
+\r
+DECLARE_ASN1_FUNCTIONS(X509_ALGOR)\r
+DECLARE_ASN1_FUNCTIONS(X509_VAL)\r
+\r
+DECLARE_ASN1_FUNCTIONS(X509_PUBKEY)\r
+\r
+int            X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);\r
+EVP_PKEY *     X509_PUBKEY_get(X509_PUBKEY *key);\r
+int            X509_get_pubkey_parameters(EVP_PKEY *pkey,\r
+                                          STACK_OF(X509) *chain);\r
+int            i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp);\r
+EVP_PKEY *     d2i_PUBKEY(EVP_PKEY **a,const unsigned char **pp,\r
+                       long length);\r
+#ifndef OPENSSL_NO_RSA\r
+int            i2d_RSA_PUBKEY(RSA *a,unsigned char **pp);\r
+RSA *          d2i_RSA_PUBKEY(RSA **a,const unsigned char **pp,\r
+                       long length);\r
+#endif\r
+#ifndef OPENSSL_NO_DSA\r
+int            i2d_DSA_PUBKEY(DSA *a,unsigned char **pp);\r
+DSA *          d2i_DSA_PUBKEY(DSA **a,const unsigned char **pp,\r
+                       long length);\r
+#endif\r
+#ifndef OPENSSL_NO_EC\r
+int            i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp);\r
+EC_KEY                 *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp,\r
+                       long length);\r
+#endif\r
+\r
+DECLARE_ASN1_FUNCTIONS(X509_SIG)\r
+DECLARE_ASN1_FUNCTIONS(X509_REQ_INFO)\r
+DECLARE_ASN1_FUNCTIONS(X509_REQ)\r
+\r
+DECLARE_ASN1_FUNCTIONS(X509_ATTRIBUTE)\r
+X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);\r
+\r
+DECLARE_ASN1_FUNCTIONS(X509_EXTENSION)\r
+\r
+DECLARE_ASN1_FUNCTIONS(X509_NAME_ENTRY)\r
+\r
+DECLARE_ASN1_FUNCTIONS(X509_NAME)\r
+\r
+int            X509_NAME_set(X509_NAME **xn, X509_NAME *name);\r
+\r
+DECLARE_ASN1_FUNCTIONS(X509_CINF)\r
+\r
+DECLARE_ASN1_FUNCTIONS(X509)\r
+DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX)\r
+\r
+DECLARE_ASN1_FUNCTIONS(X509_CERT_PAIR)\r
+\r
+int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,\r
+            CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+int X509_set_ex_data(X509 *r, int idx, void *arg);\r
+void *X509_get_ex_data(X509 *r, int idx);\r
+int            i2d_X509_AUX(X509 *a,unsigned char **pp);\r
+X509 *         d2i_X509_AUX(X509 **a,const unsigned char **pp,long length);\r
+\r
+int X509_alias_set1(X509 *x, unsigned char *name, int len);\r
+int X509_keyid_set1(X509 *x, unsigned char *id, int len);\r
+unsigned char * X509_alias_get0(X509 *x, int *len);\r
+unsigned char * X509_keyid_get0(X509 *x, int *len);\r
+int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int);\r
+int X509_TRUST_set(int *t, int trust);\r
+int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj);\r
+int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj);\r
+void X509_trust_clear(X509 *x);\r
+void X509_reject_clear(X509 *x);\r
+\r
+DECLARE_ASN1_FUNCTIONS(X509_REVOKED)\r
+DECLARE_ASN1_FUNCTIONS(X509_CRL_INFO)\r
+DECLARE_ASN1_FUNCTIONS(X509_CRL)\r
+\r
+int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev);\r
+\r
+X509_PKEY *    X509_PKEY_new(void );\r
+void           X509_PKEY_free(X509_PKEY *a);\r
+int            i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);\r
+X509_PKEY *    d2i_X509_PKEY(X509_PKEY **a,const unsigned char **pp,long length);\r
+\r
+DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI)\r
+DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC)\r
+DECLARE_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE)\r
+\r
+#ifndef OPENSSL_NO_EVP\r
+X509_INFO *    X509_INFO_new(void);\r
+void           X509_INFO_free(X509_INFO *a);\r
+char *         X509_NAME_oneline(X509_NAME *a,char *buf,int size);\r
+\r
+int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *algor1,\r
+               ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);\r
+\r
+int ASN1_digest(i2d_of_void *i2d,const EVP_MD *type,char *data,\r
+               unsigned char *md,unsigned int *len);\r
+\r
+int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1,\r
+             X509_ALGOR *algor2, ASN1_BIT_STRING *signature,\r
+             char *data,EVP_PKEY *pkey, const EVP_MD *type);\r
+\r
+int ASN1_item_digest(const ASN1_ITEM *it,const EVP_MD *type,void *data,\r
+       unsigned char *md,unsigned int *len);\r
+\r
+int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *algor1,\r
+       ASN1_BIT_STRING *signature,void *data,EVP_PKEY *pkey);\r
+\r
+int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,\r
+       ASN1_BIT_STRING *signature,\r
+       void *data, EVP_PKEY *pkey, const EVP_MD *type);\r
+#endif\r
+\r
+int            X509_set_version(X509 *x,long version);\r
+int            X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);\r
+ASN1_INTEGER * X509_get_serialNumber(X509 *x);\r
+int            X509_set_issuer_name(X509 *x, X509_NAME *name);\r
+X509_NAME *    X509_get_issuer_name(X509 *a);\r
+int            X509_set_subject_name(X509 *x, X509_NAME *name);\r
+X509_NAME *    X509_get_subject_name(X509 *a);\r
+int            X509_set_notBefore(X509 *x, ASN1_TIME *tm);\r
+int            X509_set_notAfter(X509 *x, ASN1_TIME *tm);\r
+int            X509_set_pubkey(X509 *x, EVP_PKEY *pkey);\r
+EVP_PKEY *     X509_get_pubkey(X509 *x);\r
+ASN1_BIT_STRING * X509_get0_pubkey_bitstr(const X509 *x);\r
+int            X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */);\r
+\r
+int            X509_REQ_set_version(X509_REQ *x,long version);\r
+int            X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);\r
+int            X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);\r
+EVP_PKEY *     X509_REQ_get_pubkey(X509_REQ *req);\r
+int            X509_REQ_extension_nid(int nid);\r
+int *          X509_REQ_get_extension_nids(void);\r
+void           X509_REQ_set_extension_nids(int *nids);\r
+STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req);\r
+int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,\r
+                               int nid);\r
+int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts);\r
+int X509_REQ_get_attr_count(const X509_REQ *req);\r
+int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,\r
+                         int lastpos);\r
+int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj,\r
+                         int lastpos);\r
+X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc);\r
+X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc);\r
+int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr);\r
+int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,\r
+                       const ASN1_OBJECT *obj, int type,\r
+                       const unsigned char *bytes, int len);\r
+int X509_REQ_add1_attr_by_NID(X509_REQ *req,\r
+                       int nid, int type,\r
+                       const unsigned char *bytes, int len);\r
+int X509_REQ_add1_attr_by_txt(X509_REQ *req,\r
+                       const char *attrname, int type,\r
+                       const unsigned char *bytes, int len);\r
+\r
+int X509_CRL_set_version(X509_CRL *x, long version);\r
+int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name);\r
+int X509_CRL_set_lastUpdate(X509_CRL *x, ASN1_TIME *tm);\r
+int X509_CRL_set_nextUpdate(X509_CRL *x, ASN1_TIME *tm);\r
+int X509_CRL_sort(X509_CRL *crl);\r
+\r
+int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial);\r
+int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm);\r
+\r
+int            X509_REQ_check_private_key(X509_REQ *x509,EVP_PKEY *pkey);\r
+\r
+int            X509_check_private_key(X509 *x509,EVP_PKEY *pkey);\r
+\r
+int            X509_issuer_and_serial_cmp(const X509 *a, const X509 *b);\r
+unsigned long  X509_issuer_and_serial_hash(X509 *a);\r
+\r
+int            X509_issuer_name_cmp(const X509 *a, const X509 *b);\r
+unsigned long  X509_issuer_name_hash(X509 *a);\r
+\r
+int            X509_subject_name_cmp(const X509 *a, const X509 *b);\r
+unsigned long  X509_subject_name_hash(X509 *x);\r
+\r
+int            X509_cmp(const X509 *a, const X509 *b);\r
+int            X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b);\r
+unsigned long  X509_NAME_hash(X509_NAME *x);\r
+\r
+int            X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b);\r
+#ifndef OPENSSL_NO_FP_API\r
+int            X509_print_ex_fp(FILE *bp,X509 *x, unsigned long nmflag, unsigned long cflag);\r
+int            X509_print_fp(FILE *bp,X509 *x);\r
+int            X509_CRL_print_fp(FILE *bp,X509_CRL *x);\r
+int            X509_REQ_print_fp(FILE *bp,X509_REQ *req);\r
+int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags);\r
+#endif\r
+\r
+#ifndef OPENSSL_NO_BIO\r
+int            X509_NAME_print(BIO *bp, X509_NAME *name, int obase);\r
+int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags);\r
+int            X509_print_ex(BIO *bp,X509 *x, unsigned long nmflag, unsigned long cflag);\r
+int            X509_print(BIO *bp,X509 *x);\r
+int            X509_ocspid_print(BIO *bp,X509 *x);\r
+int            X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent);\r
+int            X509_CRL_print(BIO *bp,X509_CRL *x);\r
+int            X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, unsigned long cflag);\r
+int            X509_REQ_print(BIO *bp,X509_REQ *req);\r
+#endif\r
+\r
+int            X509_NAME_entry_count(X509_NAME *name);\r
+int            X509_NAME_get_text_by_NID(X509_NAME *name, int nid,\r
+                       char *buf,int len);\r
+int            X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,\r
+                       char *buf,int len);\r
+\r
+/* NOTE: you should be passsing -1, not 0 as lastpos.  The functions that use\r
+ * lastpos, search after that position on. */\r
+int            X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);\r
+int            X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj,\r
+                       int lastpos);\r
+X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);\r
+X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);\r
+int            X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne,\r
+                       int loc, int set);\r
+int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,\r
+                       unsigned char *bytes, int len, int loc, int set);\r
+int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,\r
+                       unsigned char *bytes, int len, int loc, int set);\r
+X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,\r
+               const char *field, int type, const unsigned char *bytes, int len);\r
+X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,\r
+                       int type,unsigned char *bytes, int len);\r
+int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type,\r
+                       const unsigned char *bytes, int len, int loc, int set);\r
+X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,\r
+                       ASN1_OBJECT *obj, int type,const unsigned char *bytes,\r
+                       int len);\r
+int            X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,\r
+                       ASN1_OBJECT *obj);\r
+int            X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,\r
+                       const unsigned char *bytes, int len);\r
+ASN1_OBJECT *  X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);\r
+ASN1_STRING *  X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);\r
+\r
+int            X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x);\r
+int            X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x,\r
+                                     int nid, int lastpos);\r
+int            X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x,\r
+                                     ASN1_OBJECT *obj,int lastpos);\r
+int            X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x,\r
+                                          int crit, int lastpos);\r
+X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc);\r
+X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc);\r
+STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,\r
+                                        X509_EXTENSION *ex, int loc);\r
+\r
+int            X509_get_ext_count(X509 *x);\r
+int            X509_get_ext_by_NID(X509 *x, int nid, int lastpos);\r
+int            X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos);\r
+int            X509_get_ext_by_critical(X509 *x, int crit, int lastpos);\r
+X509_EXTENSION *X509_get_ext(X509 *x, int loc);\r
+X509_EXTENSION *X509_delete_ext(X509 *x, int loc);\r
+int            X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);\r
+void   *       X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);\r
+int            X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit,\r
+                                                       unsigned long flags);\r
+\r
+int            X509_CRL_get_ext_count(X509_CRL *x);\r
+int            X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos);\r
+int            X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos);\r
+int            X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos);\r
+X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc);\r
+X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);\r
+int            X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);\r
+void   *       X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);\r
+int            X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit,\r
+                                                       unsigned long flags);\r
+\r
+int            X509_REVOKED_get_ext_count(X509_REVOKED *x);\r
+int            X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos);\r
+int            X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos);\r
+int            X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos);\r
+X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc);\r
+X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);\r
+int            X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc);\r
+void   *       X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);\r
+int            X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit,\r
+                                                       unsigned long flags);\r
+\r
+X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,\r
+                       int nid, int crit, ASN1_OCTET_STRING *data);\r
+X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,\r
+                       ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data);\r
+int            X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj);\r
+int            X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);\r
+int            X509_EXTENSION_set_data(X509_EXTENSION *ex,\r
+                       ASN1_OCTET_STRING *data);\r
+ASN1_OBJECT *  X509_EXTENSION_get_object(X509_EXTENSION *ex);\r
+ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);\r
+int            X509_EXTENSION_get_critical(X509_EXTENSION *ex);\r
+\r
+int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x);\r
+int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,\r
+                         int lastpos);\r
+int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj,\r
+                         int lastpos);\r
+X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc);\r
+X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc);\r
+STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,\r
+                                        X509_ATTRIBUTE *attr);\r
+STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x,\r
+                       const ASN1_OBJECT *obj, int type,\r
+                       const unsigned char *bytes, int len);\r
+STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,\r
+                       int nid, int type,\r
+                       const unsigned char *bytes, int len);\r
+STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,\r
+                       const char *attrname, int type,\r
+                       const unsigned char *bytes, int len);\r
+X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,\r
+            int atrtype, const void *data, int len);\r
+X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,\r
+            const ASN1_OBJECT *obj, int atrtype, const void *data, int len);\r
+X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,\r
+               const char *atrname, int type, const unsigned char *bytes, int len);\r
+int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj);\r
+int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len);\r
+void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,\r
+                                       int atrtype, void *data);\r
+int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr);\r
+ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);\r
+ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);\r
+\r
+int EVP_PKEY_get_attr_count(const EVP_PKEY *key);\r
+int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid,\r
+                         int lastpos);\r
+int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, ASN1_OBJECT *obj,\r
+                         int lastpos);\r
+X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc);\r
+X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc);\r
+int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr);\r
+int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key,\r
+                       const ASN1_OBJECT *obj, int type,\r
+                       const unsigned char *bytes, int len);\r
+int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key,\r
+                       int nid, int type,\r
+                       const unsigned char *bytes, int len);\r
+int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key,\r
+                       const char *attrname, int type,\r
+                       const unsigned char *bytes, int len);\r
+\r
+int            X509_verify_cert(X509_STORE_CTX *ctx);\r
+\r
+/* lookup a cert from a X509 STACK */\r
+X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name,\r
+                                    ASN1_INTEGER *serial);\r
+X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name);\r
+\r
+DECLARE_ASN1_FUNCTIONS(PBEPARAM)\r
+DECLARE_ASN1_FUNCTIONS(PBE2PARAM)\r
+DECLARE_ASN1_FUNCTIONS(PBKDF2PARAM)\r
+\r
+X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen);\r
+X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,\r
+                                        unsigned char *salt, int saltlen);\r
+\r
+/* PKCS#8 utilities */\r
+\r
+DECLARE_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)\r
+\r
+EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);\r
+PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);\r
+PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken);\r
+PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);\r
+\r
+int X509_check_trust(X509 *x, int id, int flags);\r
+int X509_TRUST_get_count(void);\r
+X509_TRUST * X509_TRUST_get0(int idx);\r
+int X509_TRUST_get_by_id(int id);\r
+int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),\r
+                                       char *name, int arg1, void *arg2);\r
+void X509_TRUST_cleanup(void);\r
+int X509_TRUST_get_flags(X509_TRUST *xp);\r
+char *X509_TRUST_get0_name(X509_TRUST *xp);\r
+int X509_TRUST_get_trust(X509_TRUST *xp);\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_X509_strings(void);\r
+\r
+/* Error codes for the X509 functions. */\r
+\r
+/* Function codes. */\r
+#define X509_F_ADD_CERT_DIR                             100\r
+#define X509_F_BY_FILE_CTRL                             101\r
+#define X509_F_CHECK_POLICY                             145\r
+#define X509_F_DIR_CTRL                                         102\r
+#define X509_F_GET_CERT_BY_SUBJECT                      103\r
+#define X509_F_NETSCAPE_SPKI_B64_DECODE                         129\r
+#define X509_F_NETSCAPE_SPKI_B64_ENCODE                         130\r
+#define X509_F_X509AT_ADD1_ATTR                                 135\r
+#define X509_F_X509V3_ADD_EXT                           104\r
+#define X509_F_X509_ATTRIBUTE_CREATE_BY_NID             136\r
+#define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ             137\r
+#define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT             140\r
+#define X509_F_X509_ATTRIBUTE_GET0_DATA                         139\r
+#define X509_F_X509_ATTRIBUTE_SET1_DATA                         138\r
+#define X509_F_X509_CHECK_PRIVATE_KEY                   128\r
+#define X509_F_X509_CRL_PRINT_FP                        147\r
+#define X509_F_X509_EXTENSION_CREATE_BY_NID             108\r
+#define X509_F_X509_EXTENSION_CREATE_BY_OBJ             109\r
+#define X509_F_X509_GET_PUBKEY_PARAMETERS               110\r
+#define X509_F_X509_LOAD_CERT_CRL_FILE                  132\r
+#define X509_F_X509_LOAD_CERT_FILE                      111\r
+#define X509_F_X509_LOAD_CRL_FILE                       112\r
+#define X509_F_X509_NAME_ADD_ENTRY                      113\r
+#define X509_F_X509_NAME_ENTRY_CREATE_BY_NID            114\r
+#define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT            131\r
+#define X509_F_X509_NAME_ENTRY_SET_OBJECT               115\r
+#define X509_F_X509_NAME_ONELINE                        116\r
+#define X509_F_X509_NAME_PRINT                          117\r
+#define X509_F_X509_PRINT_EX_FP                                 118\r
+#define X509_F_X509_PUBKEY_GET                          119\r
+#define X509_F_X509_PUBKEY_SET                          120\r
+#define X509_F_X509_REQ_CHECK_PRIVATE_KEY               144\r
+#define X509_F_X509_REQ_PRINT_EX                        121\r
+#define X509_F_X509_REQ_PRINT_FP                        122\r
+#define X509_F_X509_REQ_TO_X509                                 123\r
+#define X509_F_X509_STORE_ADD_CERT                      124\r
+#define X509_F_X509_STORE_ADD_CRL                       125\r
+#define X509_F_X509_STORE_CTX_GET1_ISSUER               146\r
+#define X509_F_X509_STORE_CTX_INIT                      143\r
+#define X509_F_X509_STORE_CTX_NEW                       142\r
+#define X509_F_X509_STORE_CTX_PURPOSE_INHERIT           134\r
+#define X509_F_X509_TO_X509_REQ                                 126\r
+#define X509_F_X509_TRUST_ADD                           133\r
+#define X509_F_X509_TRUST_SET                           141\r
+#define X509_F_X509_VERIFY_CERT                                 127\r
+\r
+/* Reason codes. */\r
+#define X509_R_BAD_X509_FILETYPE                        100\r
+#define X509_R_BASE64_DECODE_ERROR                      118\r
+#define X509_R_CANT_CHECK_DH_KEY                        114\r
+#define X509_R_CERT_ALREADY_IN_HASH_TABLE               101\r
+#define X509_R_ERR_ASN1_LIB                             102\r
+#define X509_R_INVALID_DIRECTORY                        113\r
+#define X509_R_INVALID_FIELD_NAME                       119\r
+#define X509_R_INVALID_TRUST                            123\r
+#define X509_R_KEY_TYPE_MISMATCH                        115\r
+#define X509_R_KEY_VALUES_MISMATCH                      116\r
+#define X509_R_LOADING_CERT_DIR                                 103\r
+#define X509_R_LOADING_DEFAULTS                                 104\r
+#define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY             105\r
+#define X509_R_SHOULD_RETRY                             106\r
+#define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN       107\r
+#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY           108\r
+#define X509_R_UNKNOWN_KEY_TYPE                                 117\r
+#define X509_R_UNKNOWN_NID                              109\r
+#define X509_R_UNKNOWN_PURPOSE_ID                       121\r
+#define X509_R_UNKNOWN_TRUST_ID                                 120\r
+#define X509_R_UNSUPPORTED_ALGORITHM                    111\r
+#define X509_R_WRONG_LOOKUP_TYPE                        112\r
+#define X509_R_WRONG_TYPE                               122\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/x509_vfy.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/x509_vfy.h
new file mode 100644 (file)
index 0000000..20d2dd0
--- /dev/null
@@ -0,0 +1,527 @@
+/* crypto/x509/x509_vfy.h */\r
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
+ * All rights reserved.\r
+ *\r
+ * This package is an SSL implementation written\r
+ * by Eric Young (eay@cryptsoft.com).\r
+ * The implementation was written so as to conform with Netscapes SSL.\r
+ * \r
+ * This library is free for commercial and non-commercial use as long as\r
+ * the following conditions are aheared to.  The following conditions\r
+ * apply to all code found in this distribution, be it the RC4, RSA,\r
+ * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
+ * included with this distribution is covered by the same copyright terms\r
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
+ * \r
+ * Copyright remains Eric Young's, and as such any Copyright notices in\r
+ * the code are not to be removed.\r
+ * If this package is used in a product, Eric Young should be given attribution\r
+ * as the author of the parts of the library used.\r
+ * This can be in the form of a textual message at program startup or\r
+ * in documentation (online or textual) provided with the package.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    "This product includes cryptographic software written by\r
+ *     Eric Young (eay@cryptsoft.com)"\r
+ *    The word 'cryptographic' can be left out if the rouines from the library\r
+ *    being used are not cryptographic related :-).\r
+ * 4. If you include any Windows specific code (or a derivative thereof) from \r
+ *    the apps directory (application code) you must include an acknowledgement:\r
+ *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * \r
+ * The licence and distribution terms for any publically available version or\r
+ * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
+ * copied and put under another distribution licence\r
+ * [including the GNU Public Licence.]\r
+ */\r
+\r
+#ifndef HEADER_X509_H\r
+#include <openssl/x509.h>\r
+/* openssl/x509.h ends up #include-ing this file at about the only\r
+ * appropriate moment. */\r
+#endif\r
+\r
+#ifndef HEADER_X509_VFY_H\r
+#define HEADER_X509_VFY_H\r
+\r
+#include <openssl/opensslconf.h>\r
+#ifndef OPENSSL_NO_LHASH\r
+#include <openssl/lhash.h>\r
+#endif\r
+#include <openssl/bio.h>\r
+#include <openssl/crypto.h>\r
+#include <openssl/symhacks.h>\r
+\r
+#ifdef  __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Outer object */\r
+typedef struct x509_hash_dir_st\r
+       {\r
+       int num_dirs;\r
+       char **dirs;\r
+       int *dirs_type;\r
+       int num_dirs_alloced;\r
+       } X509_HASH_DIR_CTX;\r
+\r
+typedef struct x509_file_st\r
+       {\r
+       int num_paths;  /* number of paths to files or directories */\r
+       int num_alloced;\r
+       char **paths;   /* the list of paths or directories */\r
+       int *path_type;\r
+       } X509_CERT_FILE_CTX;\r
+\r
+/*******************************/\r
+/*\r
+SSL_CTX -> X509_STORE    \r
+               -> X509_LOOKUP\r
+                       ->X509_LOOKUP_METHOD\r
+               -> X509_LOOKUP\r
+                       ->X509_LOOKUP_METHOD\r
\r
+SSL    -> X509_STORE_CTX\r
+               ->X509_STORE    \r
+\r
+The X509_STORE holds the tables etc for verification stuff.\r
+A X509_STORE_CTX is used while validating a single certificate.\r
+The X509_STORE has X509_LOOKUPs for looking up certs.\r
+The X509_STORE then calls a function to actually verify the\r
+certificate chain.\r
+*/\r
+\r
+#define X509_LU_RETRY          -1\r
+#define X509_LU_FAIL           0\r
+#define X509_LU_X509           1\r
+#define X509_LU_CRL            2\r
+#define X509_LU_PKEY           3\r
+\r
+typedef struct x509_object_st\r
+       {\r
+       /* one of the above types */\r
+       int type;\r
+       union   {\r
+               char *ptr;\r
+               X509 *x509;\r
+               X509_CRL *crl;\r
+               EVP_PKEY *pkey;\r
+               } data;\r
+       } X509_OBJECT;\r
+\r
+typedef struct x509_lookup_st X509_LOOKUP;\r
+\r
+DECLARE_STACK_OF(X509_LOOKUP)\r
+DECLARE_STACK_OF(X509_OBJECT)\r
+\r
+/* This is a static that defines the function interface */\r
+typedef struct x509_lookup_method_st\r
+       {\r
+       const char *name;\r
+       int (*new_item)(X509_LOOKUP *ctx);\r
+       void (*free)(X509_LOOKUP *ctx);\r
+       int (*init)(X509_LOOKUP *ctx);\r
+       int (*shutdown)(X509_LOOKUP *ctx);\r
+       int (*ctrl)(X509_LOOKUP *ctx,int cmd,const char *argc,long argl,\r
+                       char **ret);\r
+       int (*get_by_subject)(X509_LOOKUP *ctx,int type,X509_NAME *name,\r
+                             X509_OBJECT *ret);\r
+       int (*get_by_issuer_serial)(X509_LOOKUP *ctx,int type,X509_NAME *name,\r
+                                   ASN1_INTEGER *serial,X509_OBJECT *ret);\r
+       int (*get_by_fingerprint)(X509_LOOKUP *ctx,int type,\r
+                                 unsigned char *bytes,int len,\r
+                                 X509_OBJECT *ret);\r
+       int (*get_by_alias)(X509_LOOKUP *ctx,int type,char *str,int len,\r
+                           X509_OBJECT *ret);\r
+       } X509_LOOKUP_METHOD;\r
+\r
+/* This structure hold all parameters associated with a verify operation\r
+ * by including an X509_VERIFY_PARAM structure in related structures the\r
+ * parameters used can be customized\r
+ */\r
+\r
+typedef struct X509_VERIFY_PARAM_st\r
+       {\r
+       char *name;\r
+       time_t check_time;      /* Time to use */\r
+       unsigned long inh_flags; /* Inheritance flags */\r
+       unsigned long flags;    /* Various verify flags */\r
+       int purpose;            /* purpose to check untrusted certificates */\r
+       int trust;              /* trust setting to check */\r
+       int depth;              /* Verify depth */\r
+       STACK_OF(ASN1_OBJECT) *policies;        /* Permissible policies */\r
+       } X509_VERIFY_PARAM;\r
+\r
+DECLARE_STACK_OF(X509_VERIFY_PARAM)\r
+\r
+/* This is used to hold everything.  It is used for all certificate\r
+ * validation.  Once we have a certificate chain, the 'verify'\r
+ * function is then called to actually check the cert chain. */\r
+struct x509_store_st\r
+       {\r
+       /* The following is a cache of trusted certs */\r
+       int cache;      /* if true, stash any hits */\r
+       STACK_OF(X509_OBJECT) *objs;    /* Cache of all objects */\r
+\r
+       /* These are external lookup methods */\r
+       STACK_OF(X509_LOOKUP) *get_cert_methods;\r
+\r
+       X509_VERIFY_PARAM *param;\r
+\r
+       /* Callbacks for various operations */\r
+       int (*verify)(X509_STORE_CTX *ctx);     /* called to verify a certificate */\r
+       int (*verify_cb)(int ok,X509_STORE_CTX *ctx);   /* error callback */\r
+       int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */\r
+       int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */\r
+       int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */\r
+       int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */\r
+       int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */\r
+       int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */\r
+       int (*cleanup)(X509_STORE_CTX *ctx);\r
+\r
+       CRYPTO_EX_DATA ex_data;\r
+       int references;\r
+       } /* X509_STORE */;\r
+\r
+int X509_STORE_set_depth(X509_STORE *store, int depth);\r
+\r
+#define X509_STORE_set_verify_cb_func(ctx,func) ((ctx)->verify_cb=(func))\r
+#define X509_STORE_set_verify_func(ctx,func)   ((ctx)->verify=(func))\r
+\r
+/* This is the functions plus an instance of the local variables. */\r
+struct x509_lookup_st\r
+       {\r
+       int init;                       /* have we been started */\r
+       int skip;                       /* don't use us. */\r
+       X509_LOOKUP_METHOD *method;     /* the functions */\r
+       char *method_data;              /* method data */\r
+\r
+       X509_STORE *store_ctx;  /* who owns us */\r
+       } /* X509_LOOKUP */;\r
+\r
+/* This is a used when verifying cert chains.  Since the\r
+ * gathering of the cert chain can take some time (and have to be\r
+ * 'retried', this needs to be kept and passed around. */\r
+struct x509_store_ctx_st      /* X509_STORE_CTX */\r
+       {\r
+       X509_STORE *ctx;\r
+       int current_method;     /* used when looking up certs */\r
+\r
+       /* The following are set by the caller */\r
+       X509 *cert;             /* The cert to check */\r
+       STACK_OF(X509) *untrusted;      /* chain of X509s - untrusted - passed in */\r
+       STACK_OF(X509_CRL) *crls;       /* set of CRLs passed in */\r
+\r
+       X509_VERIFY_PARAM *param;\r
+       void *other_ctx;        /* Other info for use with get_issuer() */\r
+\r
+       /* Callbacks for various operations */\r
+       int (*verify)(X509_STORE_CTX *ctx);     /* called to verify a certificate */\r
+       int (*verify_cb)(int ok,X509_STORE_CTX *ctx);           /* error callback */\r
+       int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */\r
+       int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */\r
+       int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */\r
+       int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */\r
+       int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */\r
+       int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */\r
+       int (*check_policy)(X509_STORE_CTX *ctx);\r
+       int (*cleanup)(X509_STORE_CTX *ctx);\r
+\r
+       /* The following is built up */\r
+       int valid;              /* if 0, rebuild chain */\r
+       int last_untrusted;     /* index of last untrusted cert */\r
+       STACK_OF(X509) *chain;          /* chain of X509s - built up and trusted */\r
+       X509_POLICY_TREE *tree; /* Valid policy tree */\r
+\r
+       int explicit_policy;    /* Require explicit policy value */\r
+\r
+       /* When something goes wrong, this is why */\r
+       int error_depth;\r
+       int error;\r
+       X509 *current_cert;\r
+       X509 *current_issuer;   /* cert currently being tested as valid issuer */\r
+       X509_CRL *current_crl;  /* current CRL */\r
+\r
+       CRYPTO_EX_DATA ex_data;\r
+       } /* X509_STORE_CTX */;\r
+\r
+void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth);\r
+\r
+#define X509_STORE_CTX_set_app_data(ctx,data) \\r
+       X509_STORE_CTX_set_ex_data(ctx,0,data)\r
+#define X509_STORE_CTX_get_app_data(ctx) \\r
+       X509_STORE_CTX_get_ex_data(ctx,0)\r
+\r
+#define X509_L_FILE_LOAD       1\r
+#define X509_L_ADD_DIR         2\r
+\r
+#define X509_LOOKUP_load_file(x,name,type) \\r
+               X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL)\r
+\r
+#define X509_LOOKUP_add_dir(x,name,type) \\r
+               X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL)\r
+\r
+#define                X509_V_OK                                       0\r
+/* illegal error (for uninitialized values, to avoid X509_V_OK): 1 */\r
+\r
+#define                X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT            2\r
+#define                X509_V_ERR_UNABLE_TO_GET_CRL                    3\r
+#define                X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE     4\r
+#define                X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE      5\r
+#define                X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY   6\r
+#define                X509_V_ERR_CERT_SIGNATURE_FAILURE               7\r
+#define                X509_V_ERR_CRL_SIGNATURE_FAILURE                8\r
+#define                X509_V_ERR_CERT_NOT_YET_VALID                   9\r
+#define                X509_V_ERR_CERT_HAS_EXPIRED                     10\r
+#define                X509_V_ERR_CRL_NOT_YET_VALID                    11\r
+#define                X509_V_ERR_CRL_HAS_EXPIRED                      12\r
+#define                X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD       13\r
+#define                X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD        14\r
+#define                X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD       15\r
+#define                X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD       16\r
+#define                X509_V_ERR_OUT_OF_MEM                           17\r
+#define                X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT          18\r
+#define                X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN            19\r
+#define                X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY    20\r
+#define                X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE      21\r
+#define                X509_V_ERR_CERT_CHAIN_TOO_LONG                  22\r
+#define                X509_V_ERR_CERT_REVOKED                         23\r
+#define                X509_V_ERR_INVALID_CA                           24\r
+#define                X509_V_ERR_PATH_LENGTH_EXCEEDED                 25\r
+#define                X509_V_ERR_INVALID_PURPOSE                      26\r
+#define                X509_V_ERR_CERT_UNTRUSTED                       27\r
+#define                X509_V_ERR_CERT_REJECTED                        28\r
+/* These are 'informational' when looking for issuer cert */\r
+#define                X509_V_ERR_SUBJECT_ISSUER_MISMATCH              29\r
+#define                X509_V_ERR_AKID_SKID_MISMATCH                   30\r
+#define                X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH          31\r
+#define                X509_V_ERR_KEYUSAGE_NO_CERTSIGN                 32\r
+\r
+#define                X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER             33\r
+#define                X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION         34\r
+#define                X509_V_ERR_KEYUSAGE_NO_CRL_SIGN                 35\r
+#define                X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION     36\r
+#define                X509_V_ERR_INVALID_NON_CA                       37\r
+#define                X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED           38\r
+#define                X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE        39\r
+#define                X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED       40\r
+\r
+#define                X509_V_ERR_INVALID_EXTENSION                    41\r
+#define                X509_V_ERR_INVALID_POLICY_EXTENSION             42\r
+#define                X509_V_ERR_NO_EXPLICIT_POLICY                   43\r
+\r
+\r
+/* The application is not happy */\r
+#define                X509_V_ERR_APPLICATION_VERIFICATION             50\r
+\r
+/* Certificate verify flags */\r
+\r
+/* Send issuer+subject checks to verify_cb */\r
+#define        X509_V_FLAG_CB_ISSUER_CHECK             0x1\r
+/* Use check time instead of current time */\r
+#define        X509_V_FLAG_USE_CHECK_TIME              0x2\r
+/* Lookup CRLs */\r
+#define        X509_V_FLAG_CRL_CHECK                   0x4\r
+/* Lookup CRLs for whole chain */\r
+#define        X509_V_FLAG_CRL_CHECK_ALL               0x8\r
+/* Ignore unhandled critical extensions */\r
+#define        X509_V_FLAG_IGNORE_CRITICAL             0x10\r
+/* Disable workarounds for broken certificates */\r
+#define        X509_V_FLAG_X509_STRICT                 0x20\r
+/* Enable proxy certificate validation */\r
+#define        X509_V_FLAG_ALLOW_PROXY_CERTS           0x40\r
+/* Enable policy checking */\r
+#define X509_V_FLAG_POLICY_CHECK               0x80\r
+/* Policy variable require-explicit-policy */\r
+#define X509_V_FLAG_EXPLICIT_POLICY            0x100\r
+/* Policy variable inhibit-any-policy */\r
+#define        X509_V_FLAG_INHIBIT_ANY                 0x200\r
+/* Policy variable inhibit-policy-mapping */\r
+#define X509_V_FLAG_INHIBIT_MAP                        0x400\r
+/* Notify callback that policy is OK */\r
+#define X509_V_FLAG_NOTIFY_POLICY              0x800\r
+\r
+#define X509_VP_FLAG_DEFAULT                   0x1\r
+#define X509_VP_FLAG_OVERWRITE                 0x2\r
+#define X509_VP_FLAG_RESET_FLAGS               0x4\r
+#define X509_VP_FLAG_LOCKED                    0x8\r
+#define X509_VP_FLAG_ONCE                      0x10\r
+\r
+/* Internal use: mask of policy related options */\r
+#define X509_V_FLAG_POLICY_MASK (X509_V_FLAG_POLICY_CHECK \\r
+                               | X509_V_FLAG_EXPLICIT_POLICY \\r
+                               | X509_V_FLAG_INHIBIT_ANY \\r
+                               | X509_V_FLAG_INHIBIT_MAP)\r
+\r
+int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,\r
+            X509_NAME *name);\r
+X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h,int type,X509_NAME *name);\r
+X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x);\r
+void X509_OBJECT_up_ref_count(X509_OBJECT *a);\r
+void X509_OBJECT_free_contents(X509_OBJECT *a);\r
+X509_STORE *X509_STORE_new(void );\r
+void X509_STORE_free(X509_STORE *v);\r
+\r
+int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags);\r
+int X509_STORE_set_purpose(X509_STORE *ctx, int purpose);\r
+int X509_STORE_set_trust(X509_STORE *ctx, int trust);\r
+int X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *pm);\r
+\r
+X509_STORE_CTX *X509_STORE_CTX_new(void);\r
+\r
+int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x);\r
+\r
+void X509_STORE_CTX_free(X509_STORE_CTX *ctx);\r
+int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,\r
+                        X509 *x509, STACK_OF(X509) *chain);\r
+void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk);\r
+void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);\r
+\r
+X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m);\r
+\r
+X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void);\r
+X509_LOOKUP_METHOD *X509_LOOKUP_file(void);\r
+\r
+int X509_STORE_add_cert(X509_STORE *ctx, X509 *x);\r
+int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x);\r
+\r
+int X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name,\r
+       X509_OBJECT *ret);\r
+\r
+int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,\r
+       long argl, char **ret);\r
+\r
+#ifndef OPENSSL_NO_STDIO\r
+int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type);\r
+int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type);\r
+int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type);\r
+#endif\r
+\r
+\r
+X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method);\r
+void X509_LOOKUP_free(X509_LOOKUP *ctx);\r
+int X509_LOOKUP_init(X509_LOOKUP *ctx);\r
+int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,\r
+       X509_OBJECT *ret);\r
+int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name,\r
+       ASN1_INTEGER *serial, X509_OBJECT *ret);\r
+int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,\r
+       unsigned char *bytes, int len, X509_OBJECT *ret);\r
+int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str,\r
+       int len, X509_OBJECT *ret);\r
+int X509_LOOKUP_shutdown(X509_LOOKUP *ctx);\r
+\r
+#ifndef OPENSSL_NO_STDIO\r
+int    X509_STORE_load_locations (X509_STORE *ctx,\r
+               const char *file, const char *dir);\r
+int    X509_STORE_set_default_paths(X509_STORE *ctx);\r
+#endif\r
+\r
+int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,\r
+       CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);\r
+int    X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,void *data);\r
+void * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx);\r
+int    X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);\r
+void   X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s);\r
+int    X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);\r
+X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);\r
+STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);\r
+STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx);\r
+void   X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x);\r
+void   X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk);\r
+void   X509_STORE_CTX_set0_crls(X509_STORE_CTX *c,STACK_OF(X509_CRL) *sk);\r
+int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose);\r
+int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust);\r
+int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,\r
+                               int purpose, int trust);\r
+void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags);\r
+void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags,\r
+                                                               time_t t);\r
+void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,\r
+                                 int (*verify_cb)(int, X509_STORE_CTX *));\r
+  \r
+X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree(X509_STORE_CTX *ctx);\r
+int X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx);\r
+\r
+X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(X509_STORE_CTX *ctx);\r
+void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param);\r
+int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name);\r
+\r
+/* X509_VERIFY_PARAM functions */\r
+\r
+X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void);\r
+void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param);\r
+int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to,\r
+                                               const X509_VERIFY_PARAM *from);\r
+int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, \r
+                                               const X509_VERIFY_PARAM *from);\r
+int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name);\r
+int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags);\r
+int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose);\r
+int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, int trust);\r
+void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, int depth);\r
+void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, time_t t);\r
+int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param,\r
+                                               ASN1_OBJECT *policy);\r
+int X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param, \r
+                                       STACK_OF(ASN1_OBJECT) *policies);\r
+int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param);\r
+\r
+int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param);\r
+const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name);\r
+void X509_VERIFY_PARAM_table_cleanup(void);\r
+\r
+int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy,\r
+                       STACK_OF(X509) *certs,\r
+                       STACK_OF(ASN1_OBJECT) *policy_oids,\r
+                       unsigned int flags);\r
+\r
+void X509_policy_tree_free(X509_POLICY_TREE *tree);\r
+\r
+int X509_policy_tree_level_count(const X509_POLICY_TREE *tree);\r
+X509_POLICY_LEVEL *\r
+       X509_policy_tree_get0_level(const X509_POLICY_TREE *tree, int i);\r
+\r
+STACK_OF(X509_POLICY_NODE) *\r
+       X509_policy_tree_get0_policies(const X509_POLICY_TREE *tree);\r
+\r
+STACK_OF(X509_POLICY_NODE) *\r
+       X509_policy_tree_get0_user_policies(const X509_POLICY_TREE *tree);\r
+\r
+int X509_policy_level_node_count(X509_POLICY_LEVEL *level);\r
+\r
+X509_POLICY_NODE *X509_policy_level_get0_node(X509_POLICY_LEVEL *level, int i);\r
+\r
+const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node);\r
+\r
+STACK_OF(POLICYQUALINFO) *\r
+       X509_policy_node_get0_qualifiers(const X509_POLICY_NODE *node);\r
+const X509_POLICY_NODE *\r
+       X509_policy_node_get0_parent(const X509_POLICY_NODE *node);\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/x509v3.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/openssl/x509v3.h
new file mode 100644 (file)
index 0000000..0e79ce3
--- /dev/null
@@ -0,0 +1,759 @@
+/* x509v3.h */\r
+/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL\r
+ * project 1999.\r
+ */\r
+/* ====================================================================\r
+ * Copyright (c) 1999-2004 The OpenSSL Project.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer. \r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in\r
+ *    the documentation and/or other materials provided with the\r
+ *    distribution.\r
+ *\r
+ * 3. All advertising materials mentioning features or use of this\r
+ *    software must display the following acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"\r
+ *\r
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
+ *    endorse or promote products derived from this software without\r
+ *    prior written permission. For written permission, please contact\r
+ *    licensing@OpenSSL.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "OpenSSL"\r
+ *    nor may "OpenSSL" appear in their names without prior written\r
+ *    permission of the OpenSSL Project.\r
+ *\r
+ * 6. Redistributions of any form whatsoever must retain the following\r
+ *    acknowledgment:\r
+ *    "This product includes software developed by the OpenSSL Project\r
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
+ * OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This product includes cryptographic software written by Eric Young\r
+ * (eay@cryptsoft.com).  This product includes software written by Tim\r
+ * Hudson (tjh@cryptsoft.com).\r
+ *\r
+ */\r
+#ifndef HEADER_X509V3_H\r
+#define HEADER_X509V3_H\r
+\r
+#include <openssl/bio.h>\r
+#include <openssl/x509.h>\r
+#include <openssl/conf.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Forward reference */\r
+struct v3_ext_method;\r
+struct v3_ext_ctx;\r
+\r
+/* Useful typedefs */\r
+\r
+typedef void * (*X509V3_EXT_NEW)(void);\r
+typedef void (*X509V3_EXT_FREE)(void *);\r
+typedef void * (*X509V3_EXT_D2I)(void *, const unsigned char ** , long);\r
+typedef int (*X509V3_EXT_I2D)(void *, unsigned char **);\r
+typedef STACK_OF(CONF_VALUE) * (*X509V3_EXT_I2V)(struct v3_ext_method *method, void *ext, STACK_OF(CONF_VALUE) *extlist);\r
+typedef void * (*X509V3_EXT_V2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, STACK_OF(CONF_VALUE) *values);\r
+typedef char * (*X509V3_EXT_I2S)(struct v3_ext_method *method, void *ext);\r
+typedef void * (*X509V3_EXT_S2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, const char *str);\r
+typedef int (*X509V3_EXT_I2R)(struct v3_ext_method *method, void *ext, BIO *out, int indent);\r
+typedef void * (*X509V3_EXT_R2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, const char *str);\r
+\r
+/* V3 extension structure */\r
+\r
+struct v3_ext_method {\r
+int ext_nid;\r
+int ext_flags;\r
+/* If this is set the following four fields are ignored */\r
+ASN1_ITEM_EXP *it;\r
+/* Old style ASN1 calls */\r
+X509V3_EXT_NEW ext_new;\r
+X509V3_EXT_FREE ext_free;\r
+X509V3_EXT_D2I d2i;\r
+X509V3_EXT_I2D i2d;\r
+\r
+/* The following pair is used for string extensions */\r
+X509V3_EXT_I2S i2s;\r
+X509V3_EXT_S2I s2i;\r
+\r
+/* The following pair is used for multi-valued extensions */\r
+X509V3_EXT_I2V i2v;\r
+X509V3_EXT_V2I v2i;\r
+\r
+/* The following are used for raw extensions */\r
+X509V3_EXT_I2R i2r;\r
+X509V3_EXT_R2I r2i;\r
+\r
+void *usr_data;        /* Any extension specific data */\r
+};\r
+\r
+typedef struct X509V3_CONF_METHOD_st {\r
+char * (*get_string)(void *db, char *section, char *value);\r
+STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);\r
+void (*free_string)(void *db, char * string);\r
+void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);\r
+} X509V3_CONF_METHOD;\r
+\r
+/* Context specific info */\r
+struct v3_ext_ctx {\r
+#define CTX_TEST 0x1\r
+int flags;\r
+X509 *issuer_cert;\r
+X509 *subject_cert;\r
+X509_REQ *subject_req;\r
+X509_CRL *crl;\r
+X509V3_CONF_METHOD *db_meth;\r
+void *db;\r
+/* Maybe more here */\r
+};\r
+\r
+typedef struct v3_ext_method X509V3_EXT_METHOD;\r
+\r
+DECLARE_STACK_OF(X509V3_EXT_METHOD)\r
+\r
+/* ext_flags values */\r
+#define X509V3_EXT_DYNAMIC     0x1\r
+#define X509V3_EXT_CTX_DEP     0x2\r
+#define X509V3_EXT_MULTILINE   0x4\r
+\r
+typedef BIT_STRING_BITNAME ENUMERATED_NAMES;\r
+\r
+typedef struct BASIC_CONSTRAINTS_st {\r
+int ca;\r
+ASN1_INTEGER *pathlen;\r
+} BASIC_CONSTRAINTS;\r
+\r
+\r
+typedef struct PKEY_USAGE_PERIOD_st {\r
+ASN1_GENERALIZEDTIME *notBefore;\r
+ASN1_GENERALIZEDTIME *notAfter;\r
+} PKEY_USAGE_PERIOD;\r
+\r
+typedef struct otherName_st {\r
+ASN1_OBJECT *type_id;\r
+ASN1_TYPE *value;\r
+} OTHERNAME;\r
+\r
+typedef struct EDIPartyName_st {\r
+       ASN1_STRING *nameAssigner;\r
+       ASN1_STRING *partyName;\r
+} EDIPARTYNAME;\r
+\r
+typedef struct GENERAL_NAME_st {\r
+\r
+#define GEN_OTHERNAME  0\r
+#define GEN_EMAIL      1\r
+#define GEN_DNS                2\r
+#define GEN_X400       3\r
+#define GEN_DIRNAME    4\r
+#define GEN_EDIPARTY   5\r
+#define GEN_URI                6\r
+#define GEN_IPADD      7\r
+#define GEN_RID                8\r
+\r
+int type;\r
+union {\r
+       char *ptr;\r
+       OTHERNAME *otherName; /* otherName */\r
+       ASN1_IA5STRING *rfc822Name;\r
+       ASN1_IA5STRING *dNSName;\r
+       ASN1_TYPE *x400Address;\r
+       X509_NAME *directoryName;\r
+       EDIPARTYNAME *ediPartyName;\r
+       ASN1_IA5STRING *uniformResourceIdentifier;\r
+       ASN1_OCTET_STRING *iPAddress;\r
+       ASN1_OBJECT *registeredID;\r
+\r
+       /* Old names */\r
+       ASN1_OCTET_STRING *ip; /* iPAddress */\r
+       X509_NAME *dirn;                /* dirn */\r
+       ASN1_IA5STRING *ia5;/* rfc822Name, dNSName, uniformResourceIdentifier */\r
+       ASN1_OBJECT *rid; /* registeredID */\r
+       ASN1_TYPE *other; /* x400Address */\r
+} d;\r
+} GENERAL_NAME;\r
+\r
+typedef STACK_OF(GENERAL_NAME) GENERAL_NAMES;\r
+\r
+typedef struct ACCESS_DESCRIPTION_st {\r
+       ASN1_OBJECT *method;\r
+       GENERAL_NAME *location;\r
+} ACCESS_DESCRIPTION;\r
+\r
+typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS;\r
+\r
+typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE;\r
+\r
+DECLARE_STACK_OF(GENERAL_NAME)\r
+DECLARE_ASN1_SET_OF(GENERAL_NAME)\r
+\r
+DECLARE_STACK_OF(ACCESS_DESCRIPTION)\r
+DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION)\r
+\r
+typedef struct DIST_POINT_NAME_st {\r
+int type;\r
+union {\r
+       GENERAL_NAMES *fullname;\r
+       STACK_OF(X509_NAME_ENTRY) *relativename;\r
+} name;\r
+} DIST_POINT_NAME;\r
+\r
+typedef struct DIST_POINT_st {\r
+DIST_POINT_NAME        *distpoint;\r
+ASN1_BIT_STRING *reasons;\r
+GENERAL_NAMES *CRLissuer;\r
+} DIST_POINT;\r
+\r
+typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS;\r
+\r
+DECLARE_STACK_OF(DIST_POINT)\r
+DECLARE_ASN1_SET_OF(DIST_POINT)\r
+\r
+typedef struct AUTHORITY_KEYID_st {\r
+ASN1_OCTET_STRING *keyid;\r
+GENERAL_NAMES *issuer;\r
+ASN1_INTEGER *serial;\r
+} AUTHORITY_KEYID;\r
+\r
+/* Strong extranet structures */\r
+\r
+typedef struct SXNET_ID_st {\r
+       ASN1_INTEGER *zone;\r
+       ASN1_OCTET_STRING *user;\r
+} SXNETID;\r
+\r
+DECLARE_STACK_OF(SXNETID)\r
+DECLARE_ASN1_SET_OF(SXNETID)\r
+\r
+typedef struct SXNET_st {\r
+       ASN1_INTEGER *version;\r
+       STACK_OF(SXNETID) *ids;\r
+} SXNET;\r
+\r
+typedef struct NOTICEREF_st {\r
+       ASN1_STRING *organization;\r
+       STACK_OF(ASN1_INTEGER) *noticenos;\r
+} NOTICEREF;\r
+\r
+typedef struct USERNOTICE_st {\r
+       NOTICEREF *noticeref;\r
+       ASN1_STRING *exptext;\r
+} USERNOTICE;\r
+\r
+typedef struct POLICYQUALINFO_st {\r
+       ASN1_OBJECT *pqualid;\r
+       union {\r
+               ASN1_IA5STRING *cpsuri;\r
+               USERNOTICE *usernotice;\r
+               ASN1_TYPE *other;\r
+       } d;\r
+} POLICYQUALINFO;\r
+\r
+DECLARE_STACK_OF(POLICYQUALINFO)\r
+DECLARE_ASN1_SET_OF(POLICYQUALINFO)\r
+\r
+typedef struct POLICYINFO_st {\r
+       ASN1_OBJECT *policyid;\r
+       STACK_OF(POLICYQUALINFO) *qualifiers;\r
+} POLICYINFO;\r
+\r
+typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES;\r
+\r
+DECLARE_STACK_OF(POLICYINFO)\r
+DECLARE_ASN1_SET_OF(POLICYINFO)\r
+\r
+typedef struct POLICY_MAPPING_st {\r
+       ASN1_OBJECT *issuerDomainPolicy;\r
+       ASN1_OBJECT *subjectDomainPolicy;\r
+} POLICY_MAPPING;\r
+\r
+DECLARE_STACK_OF(POLICY_MAPPING)\r
+\r
+typedef STACK_OF(POLICY_MAPPING) POLICY_MAPPINGS;\r
+\r
+typedef struct GENERAL_SUBTREE_st {\r
+       GENERAL_NAME *base;\r
+       ASN1_INTEGER *minimum;\r
+       ASN1_INTEGER *maximum;\r
+} GENERAL_SUBTREE;\r
+\r
+DECLARE_STACK_OF(GENERAL_SUBTREE)\r
+\r
+typedef struct NAME_CONSTRAINTS_st {\r
+       STACK_OF(GENERAL_SUBTREE) *permittedSubtrees;\r
+       STACK_OF(GENERAL_SUBTREE) *excludedSubtrees;\r
+} NAME_CONSTRAINTS;\r
+\r
+typedef struct POLICY_CONSTRAINTS_st {\r
+       ASN1_INTEGER *requireExplicitPolicy;\r
+       ASN1_INTEGER *inhibitPolicyMapping;\r
+} POLICY_CONSTRAINTS;\r
+\r
+/* Proxy certificate structures, see RFC 3820 */\r
+typedef struct PROXY_POLICY_st\r
+       {\r
+       ASN1_OBJECT *policyLanguage;\r
+       ASN1_OCTET_STRING *policy;\r
+       } PROXY_POLICY;\r
+\r
+typedef struct PROXY_CERT_INFO_EXTENSION_st\r
+       {\r
+       ASN1_INTEGER *pcPathLengthConstraint;\r
+       PROXY_POLICY *proxyPolicy;\r
+       } PROXY_CERT_INFO_EXTENSION;\r
+\r
+DECLARE_ASN1_FUNCTIONS(PROXY_POLICY)\r
+DECLARE_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION)\r
+\r
+\r
+#define X509V3_conf_err(val) ERR_add_error_data(6, "section:", val->section, \\r
+",name:", val->name, ",value:", val->value);\r
+\r
+#define X509V3_set_ctx_test(ctx) \\r
+                       X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, CTX_TEST)\r
+#define X509V3_set_ctx_nodb(ctx) (ctx)->db = NULL;\r
+\r
+#define EXT_BITSTRING(nid, table) { nid, 0, ASN1_ITEM_ref(ASN1_BIT_STRING), \\r
+                       0,0,0,0, \\r
+                       0,0, \\r
+                       (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \\r
+                       (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \\r
+                       NULL, NULL, \\r
+                       table}\r
+\r
+#define EXT_IA5STRING(nid) { nid, 0, ASN1_ITEM_ref(ASN1_IA5STRING), \\r
+                       0,0,0,0, \\r
+                       (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \\r
+                       (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \\r
+                       0,0,0,0, \\r
+                       NULL}\r
+\r
+#define EXT_END { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}\r
+\r
+\r
+/* X509_PURPOSE stuff */\r
+\r
+#define EXFLAG_BCONS           0x1\r
+#define EXFLAG_KUSAGE          0x2\r
+#define EXFLAG_XKUSAGE         0x4\r
+#define EXFLAG_NSCERT          0x8\r
+\r
+#define EXFLAG_CA              0x10\r
+#define EXFLAG_SS              0x20\r
+#define EXFLAG_V1              0x40\r
+#define EXFLAG_INVALID         0x80\r
+#define EXFLAG_SET             0x100\r
+#define EXFLAG_CRITICAL                0x200\r
+#define EXFLAG_PROXY           0x400\r
+\r
+#define EXFLAG_INVALID_POLICY  0x400\r
+\r
+#define KU_DIGITAL_SIGNATURE   0x0080\r
+#define KU_NON_REPUDIATION     0x0040\r
+#define KU_KEY_ENCIPHERMENT    0x0020\r
+#define KU_DATA_ENCIPHERMENT   0x0010\r
+#define KU_KEY_AGREEMENT       0x0008\r
+#define KU_KEY_CERT_SIGN       0x0004\r
+#define KU_CRL_SIGN            0x0002\r
+#define KU_ENCIPHER_ONLY       0x0001\r
+#define KU_DECIPHER_ONLY       0x8000\r
+\r
+#define NS_SSL_CLIENT          0x80\r
+#define NS_SSL_SERVER          0x40\r
+#define NS_SMIME               0x20\r
+#define NS_OBJSIGN             0x10\r
+#define NS_SSL_CA              0x04\r
+#define NS_SMIME_CA            0x02\r
+#define NS_OBJSIGN_CA          0x01\r
+#define NS_ANY_CA              (NS_SSL_CA|NS_SMIME_CA|NS_OBJSIGN_CA)\r
+\r
+#define XKU_SSL_SERVER         0x1     \r
+#define XKU_SSL_CLIENT         0x2\r
+#define XKU_SMIME              0x4\r
+#define XKU_CODE_SIGN          0x8\r
+#define XKU_SGC                        0x10\r
+#define XKU_OCSP_SIGN          0x20\r
+#define XKU_TIMESTAMP          0x40\r
+#define XKU_DVCS               0x80\r
+\r
+#define X509_PURPOSE_DYNAMIC   0x1\r
+#define X509_PURPOSE_DYNAMIC_NAME      0x2\r
+\r
+typedef struct x509_purpose_st {\r
+       int purpose;\r
+       int trust;              /* Default trust ID */\r
+       int flags;\r
+       int (*check_purpose)(const struct x509_purpose_st *,\r
+                               const X509 *, int);\r
+       char *name;\r
+       char *sname;\r
+       void *usr_data;\r
+} X509_PURPOSE;\r
+\r
+#define X509_PURPOSE_SSL_CLIENT                1\r
+#define X509_PURPOSE_SSL_SERVER                2\r
+#define X509_PURPOSE_NS_SSL_SERVER     3\r
+#define X509_PURPOSE_SMIME_SIGN                4\r
+#define X509_PURPOSE_SMIME_ENCRYPT     5\r
+#define X509_PURPOSE_CRL_SIGN          6\r
+#define X509_PURPOSE_ANY               7\r
+#define X509_PURPOSE_OCSP_HELPER       8\r
+\r
+#define X509_PURPOSE_MIN               1\r
+#define X509_PURPOSE_MAX               8\r
+\r
+/* Flags for X509V3_EXT_print() */\r
+\r
+#define X509V3_EXT_UNKNOWN_MASK                (0xfL << 16)\r
+/* Return error for unknown extensions */\r
+#define X509V3_EXT_DEFAULT             0\r
+/* Print error for unknown extensions */\r
+#define X509V3_EXT_ERROR_UNKNOWN       (1L << 16)\r
+/* ASN1 parse unknown extensions */\r
+#define X509V3_EXT_PARSE_UNKNOWN       (2L << 16)\r
+/* BIO_dump unknown extensions */\r
+#define X509V3_EXT_DUMP_UNKNOWN                (3L << 16)\r
+\r
+/* Flags for X509V3_add1_i2d */\r
+\r
+#define X509V3_ADD_OP_MASK             0xfL\r
+#define X509V3_ADD_DEFAULT             0L\r
+#define X509V3_ADD_APPEND              1L\r
+#define X509V3_ADD_REPLACE             2L\r
+#define X509V3_ADD_REPLACE_EXISTING    3L\r
+#define X509V3_ADD_KEEP_EXISTING       4L\r
+#define X509V3_ADD_DELETE              5L\r
+#define X509V3_ADD_SILENT              0x10\r
+\r
+DECLARE_STACK_OF(X509_PURPOSE)\r
+\r
+DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)\r
+\r
+DECLARE_ASN1_FUNCTIONS(SXNET)\r
+DECLARE_ASN1_FUNCTIONS(SXNETID)\r
+\r
+int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen); \r
+int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, int userlen); \r
+int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *izone, char *user, int userlen); \r
+\r
+ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone);\r
+ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone);\r
+ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone);\r
+\r
+DECLARE_ASN1_FUNCTIONS(AUTHORITY_KEYID)\r
+\r
+DECLARE_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD)\r
+\r
+DECLARE_ASN1_FUNCTIONS(GENERAL_NAME)\r
+\r
+\r
+ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,\r
+                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);\r
+STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,\r
+                               ASN1_BIT_STRING *bits,\r
+                               STACK_OF(CONF_VALUE) *extlist);\r
+\r
+STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret);\r
+int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen);\r
+\r
+DECLARE_ASN1_FUNCTIONS(GENERAL_NAMES)\r
+\r
+STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,\r
+               GENERAL_NAMES *gen, STACK_OF(CONF_VALUE) *extlist);\r
+GENERAL_NAMES *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,\r
+                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);\r
+\r
+DECLARE_ASN1_FUNCTIONS(OTHERNAME)\r
+DECLARE_ASN1_FUNCTIONS(EDIPARTYNAME)\r
+\r
+char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5);\r
+ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);\r
+\r
+DECLARE_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE)\r
+int i2a_ACCESS_DESCRIPTION(BIO *bp, ACCESS_DESCRIPTION* a);\r
+\r
+DECLARE_ASN1_FUNCTIONS(CERTIFICATEPOLICIES)\r
+DECLARE_ASN1_FUNCTIONS(POLICYINFO)\r
+DECLARE_ASN1_FUNCTIONS(POLICYQUALINFO)\r
+DECLARE_ASN1_FUNCTIONS(USERNOTICE)\r
+DECLARE_ASN1_FUNCTIONS(NOTICEREF)\r
+\r
+DECLARE_ASN1_FUNCTIONS(CRL_DIST_POINTS)\r
+DECLARE_ASN1_FUNCTIONS(DIST_POINT)\r
+DECLARE_ASN1_FUNCTIONS(DIST_POINT_NAME)\r
+\r
+DECLARE_ASN1_FUNCTIONS(ACCESS_DESCRIPTION)\r
+DECLARE_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS)\r
+\r
+DECLARE_ASN1_ITEM(POLICY_MAPPING)\r
+DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING)\r
+DECLARE_ASN1_ITEM(POLICY_MAPPINGS)\r
+\r
+DECLARE_ASN1_ITEM(GENERAL_SUBTREE)\r
+DECLARE_ASN1_ALLOC_FUNCTIONS(GENERAL_SUBTREE)\r
+\r
+DECLARE_ASN1_ITEM(NAME_CONSTRAINTS)\r
+DECLARE_ASN1_ALLOC_FUNCTIONS(NAME_CONSTRAINTS)\r
+\r
+DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS)\r
+DECLARE_ASN1_ITEM(POLICY_CONSTRAINTS)\r
+\r
+#ifdef HEADER_CONF_H\r
+GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,\r
+                                                       CONF_VALUE *cnf);\r
+GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out, X509V3_EXT_METHOD *method,\r
+                               X509V3_CTX *ctx, CONF_VALUE *cnf, int is_nc);\r
+void X509V3_conf_free(CONF_VALUE *val);\r
+\r
+X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid, char *value);\r
+X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, char *name, char *value);\r
+int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, char *section, STACK_OF(X509_EXTENSION) **sk);\r
+int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509 *cert);\r
+int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509_REQ *req);\r
+int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl);\r
+\r
+X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value);\r
+X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value);\r
+int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert);\r
+int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_REQ *req);\r
+int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl);\r
+\r
+int X509V3_add_value_bool_nf(char *name, int asn1_bool,\r
+                                               STACK_OF(CONF_VALUE) **extlist);\r
+int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);\r
+int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);\r
+void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf);\r
+void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);\r
+#endif\r
+\r
+char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);\r
+STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);\r
+void X509V3_string_free(X509V3_CTX *ctx, char *str);\r
+void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);\r
+void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,\r
+                                X509_REQ *req, X509_CRL *crl, int flags);\r
+\r
+int X509V3_add_value(const char *name, const char *value,\r
+                                               STACK_OF(CONF_VALUE) **extlist);\r
+int X509V3_add_value_uchar(const char *name, const unsigned char *value,\r
+                                               STACK_OF(CONF_VALUE) **extlist);\r
+int X509V3_add_value_bool(const char *name, int asn1_bool,\r
+                                               STACK_OF(CONF_VALUE) **extlist);\r
+int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,\r
+                                               STACK_OF(CONF_VALUE) **extlist);\r
+char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);\r
+ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);\r
+char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);\r
+char * i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);\r
+int X509V3_EXT_add(X509V3_EXT_METHOD *ext);\r
+int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist);\r
+int X509V3_EXT_add_alias(int nid_to, int nid_from);\r
+void X509V3_EXT_cleanup(void);\r
+\r
+X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext);\r
+X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid);\r
+int X509V3_add_standard_extensions(void);\r
+STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line);\r
+void *X509V3_EXT_d2i(X509_EXTENSION *ext);\r
+void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx);\r
+\r
+\r
+X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);\r
+int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, int crit, unsigned long flags);\r
+\r
+char *hex_to_string(unsigned char *buffer, long len);\r
+unsigned char *string_to_hex(char *str, long *len);\r
+int name_cmp(const char *name, const char *cmp);\r
+\r
+void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent,\r
+                                                                int ml);\r
+int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent);\r
+int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);\r
+\r
+int X509V3_extensions_print(BIO *out, char *title, STACK_OF(X509_EXTENSION) *exts, unsigned long flag, int indent);\r
+\r
+int X509_check_ca(X509 *x);\r
+int X509_check_purpose(X509 *x, int id, int ca);\r
+int X509_supported_extension(X509_EXTENSION *ex);\r
+int X509_PURPOSE_set(int *p, int purpose);\r
+int X509_check_issued(X509 *issuer, X509 *subject);\r
+int X509_PURPOSE_get_count(void);\r
+X509_PURPOSE * X509_PURPOSE_get0(int idx);\r
+int X509_PURPOSE_get_by_sname(char *sname);\r
+int X509_PURPOSE_get_by_id(int id);\r
+int X509_PURPOSE_add(int id, int trust, int flags,\r
+                       int (*ck)(const X509_PURPOSE *, const X509 *, int),\r
+                               char *name, char *sname, void *arg);\r
+char *X509_PURPOSE_get0_name(X509_PURPOSE *xp);\r
+char *X509_PURPOSE_get0_sname(X509_PURPOSE *xp);\r
+int X509_PURPOSE_get_trust(X509_PURPOSE *xp);\r
+void X509_PURPOSE_cleanup(void);\r
+int X509_PURPOSE_get_id(X509_PURPOSE *);\r
+\r
+STACK *X509_get1_email(X509 *x);\r
+STACK *X509_REQ_get1_email(X509_REQ *x);\r
+void X509_email_free(STACK *sk);\r
+\r
+ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc);\r
+ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc);\r
+int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE)*dn_sk,\r
+                                               unsigned long chtype);\r
+\r
+void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent);\r
+\r
+/* BEGIN ERROR CODES */\r
+/* The following lines are auto generated by the script mkerr.pl. Any changes\r
+ * made after this point may be overwritten when the script is next run.\r
+ */\r
+void ERR_load_X509V3_strings(void);\r
+\r
+/* Error codes for the X509V3 functions. */\r
+\r
+/* Function codes. */\r
+#define X509V3_F_COPY_EMAIL                             122\r
+#define X509V3_F_COPY_ISSUER                            123\r
+#define X509V3_F_DO_DIRNAME                             144\r
+#define X509V3_F_DO_EXT_CONF                            124\r
+#define X509V3_F_DO_EXT_I2D                             135\r
+#define X509V3_F_DO_EXT_NCONF                           151\r
+#define X509V3_F_DO_I2V_NAME_CONSTRAINTS                148\r
+#define X509V3_F_HEX_TO_STRING                          111\r
+#define X509V3_F_I2S_ASN1_ENUMERATED                    121\r
+#define X509V3_F_I2S_ASN1_IA5STRING                     149\r
+#define X509V3_F_I2S_ASN1_INTEGER                       120\r
+#define X509V3_F_I2V_AUTHORITY_INFO_ACCESS              138\r
+#define X509V3_F_NOTICE_SECTION                                 132\r
+#define X509V3_F_NREF_NOS                               133\r
+#define X509V3_F_POLICY_SECTION                                 131\r
+#define X509V3_F_PROCESS_PCI_VALUE                      150\r
+#define X509V3_F_R2I_CERTPOL                            130\r
+#define X509V3_F_R2I_PCI                                149\r
+#define X509V3_F_S2I_ASN1_IA5STRING                     100\r
+#define X509V3_F_S2I_ASN1_INTEGER                       108\r
+#define X509V3_F_S2I_ASN1_OCTET_STRING                  112\r
+#define X509V3_F_S2I_ASN1_SKEY_ID                       114\r
+#define X509V3_F_S2I_SKEY_ID                            115\r
+#define X509V3_F_STRING_TO_HEX                          113\r
+#define X509V3_F_SXNET_ADD_ID_ASC                       125\r
+#define X509V3_F_SXNET_ADD_ID_INTEGER                   126\r
+#define X509V3_F_SXNET_ADD_ID_ULONG                     127\r
+#define X509V3_F_SXNET_GET_ID_ASC                       128\r
+#define X509V3_F_SXNET_GET_ID_ULONG                     129\r
+#define X509V3_F_V2I_ASN1_BIT_STRING                    101\r
+#define X509V3_F_V2I_AUTHORITY_INFO_ACCESS              139\r
+#define X509V3_F_V2I_AUTHORITY_KEYID                    119\r
+#define X509V3_F_V2I_BASIC_CONSTRAINTS                  102\r
+#define X509V3_F_V2I_CRLD                               134\r
+#define X509V3_F_V2I_EXTENDED_KEY_USAGE                         103\r
+#define X509V3_F_V2I_GENERAL_NAMES                      118\r
+#define X509V3_F_V2I_GENERAL_NAME_EX                    117\r
+#define X509V3_F_V2I_ISSUER_ALT                                 153\r
+#define X509V3_F_V2I_NAME_CONSTRAINTS                   147\r
+#define X509V3_F_V2I_POLICY_CONSTRAINTS                         146\r
+#define X509V3_F_V2I_POLICY_MAPPINGS                    145\r
+#define X509V3_F_V2I_SUBJECT_ALT                        154\r
+#define X509V3_F_V3_GENERIC_EXTENSION                   116\r
+#define X509V3_F_X509V3_ADD1_I2D                        140\r
+#define X509V3_F_X509V3_ADD_VALUE                       105\r
+#define X509V3_F_X509V3_EXT_ADD                                 104\r
+#define X509V3_F_X509V3_EXT_ADD_ALIAS                   106\r
+#define X509V3_F_X509V3_EXT_CONF                        107\r
+#define X509V3_F_X509V3_EXT_I2D                                 136\r
+#define X509V3_F_X509V3_EXT_NCONF                       152\r
+#define X509V3_F_X509V3_GET_SECTION                     142\r
+#define X509V3_F_X509V3_GET_STRING                      143\r
+#define X509V3_F_X509V3_GET_VALUE_BOOL                  110\r
+#define X509V3_F_X509V3_PARSE_LIST                      109\r
+#define X509V3_F_X509_PURPOSE_ADD                       137\r
+#define X509V3_F_X509_PURPOSE_SET                       141\r
+\r
+/* Reason codes. */\r
+#define X509V3_R_BAD_IP_ADDRESS                                 118\r
+#define X509V3_R_BAD_OBJECT                             119\r
+#define X509V3_R_BN_DEC2BN_ERROR                        100\r
+#define X509V3_R_BN_TO_ASN1_INTEGER_ERROR               101\r
+#define X509V3_R_DIRNAME_ERROR                          149\r
+#define X509V3_R_DUPLICATE_ZONE_ID                      133\r
+#define X509V3_R_ERROR_CONVERTING_ZONE                  131\r
+#define X509V3_R_ERROR_CREATING_EXTENSION               144\r
+#define X509V3_R_ERROR_IN_EXTENSION                     128\r
+#define X509V3_R_EXPECTED_A_SECTION_NAME                137\r
+#define X509V3_R_EXTENSION_EXISTS                       145\r
+#define X509V3_R_EXTENSION_NAME_ERROR                   115\r
+#define X509V3_R_EXTENSION_NOT_FOUND                    102\r
+#define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED        103\r
+#define X509V3_R_EXTENSION_VALUE_ERROR                  116\r
+#define X509V3_R_ILLEGAL_EMPTY_EXTENSION                151\r
+#define X509V3_R_ILLEGAL_HEX_DIGIT                      113\r
+#define X509V3_R_INCORRECT_POLICY_SYNTAX_TAG            152\r
+#define X509V3_R_INVALID_BOOLEAN_STRING                         104\r
+#define X509V3_R_INVALID_EXTENSION_STRING               105\r
+#define X509V3_R_INVALID_NAME                           106\r
+#define X509V3_R_INVALID_NULL_ARGUMENT                  107\r
+#define X509V3_R_INVALID_NULL_NAME                      108\r
+#define X509V3_R_INVALID_NULL_VALUE                     109\r
+#define X509V3_R_INVALID_NUMBER                                 140\r
+#define X509V3_R_INVALID_NUMBERS                        141\r
+#define X509V3_R_INVALID_OBJECT_IDENTIFIER              110\r
+#define X509V3_R_INVALID_OPTION                                 138\r
+#define X509V3_R_INVALID_POLICY_IDENTIFIER              134\r
+#define X509V3_R_INVALID_PROXY_POLICY_SETTING           153\r
+#define X509V3_R_INVALID_PURPOSE                        146\r
+#define X509V3_R_INVALID_SECTION                        135\r
+#define X509V3_R_INVALID_SYNTAX                                 143\r
+#define X509V3_R_ISSUER_DECODE_ERROR                    126\r
+#define X509V3_R_MISSING_VALUE                          124\r
+#define X509V3_R_NEED_ORGANIZATION_AND_NUMBERS          142\r
+#define X509V3_R_NO_CONFIG_DATABASE                     136\r
+#define X509V3_R_NO_ISSUER_CERTIFICATE                  121\r
+#define X509V3_R_NO_ISSUER_DETAILS                      127\r
+#define X509V3_R_NO_POLICY_IDENTIFIER                   139\r
+#define X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED  154\r
+#define X509V3_R_NO_PUBLIC_KEY                          114\r
+#define X509V3_R_NO_SUBJECT_DETAILS                     125\r
+#define X509V3_R_ODD_NUMBER_OF_DIGITS                   112\r
+#define X509V3_R_OPERATION_NOT_DEFINED                  148\r
+#define X509V3_R_OTHERNAME_ERROR                        147\r
+#define X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED       155\r
+#define X509V3_R_POLICY_PATH_LENGTH                     156\r
+#define X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED    157\r
+#define X509V3_R_POLICY_SYNTAX_NOT_CURRENTLY_SUPPORTED  158\r
+#define X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY 159\r
+#define X509V3_R_SECTION_NOT_FOUND                      150\r
+#define X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS           122\r
+#define X509V3_R_UNABLE_TO_GET_ISSUER_KEYID             123\r
+#define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT            111\r
+#define X509V3_R_UNKNOWN_EXTENSION                      129\r
+#define X509V3_R_UNKNOWN_EXTENSION_NAME                         130\r
+#define X509V3_R_UNKNOWN_OPTION                                 120\r
+#define X509V3_R_UNSUPPORTED_OPTION                     117\r
+#define X509V3_R_USER_TOO_LONG                          132\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/pkcs11.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/pkcs11.h
new file mode 100644 (file)
index 0000000..5afbb7a
--- /dev/null
@@ -0,0 +1,299 @@
+/* pkcs11.h include file for PKCS #11. */\r
+/* $Revision: 1.4 $ */\r
+\r
+/* License to copy and use this software is granted provided that it is\r
+ * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface\r
+ * (Cryptoki)" in all material mentioning or referencing this software.\r
+\r
+ * License is also granted to make and use derivative works provided that\r
+ * such works are identified as "derived from the RSA Security Inc. PKCS #11\r
+ * Cryptographic Token Interface (Cryptoki)" in all material mentioning or \r
+ * referencing the derived work.\r
+\r
+ * RSA Security Inc. makes no representations concerning either the \r
+ * merchantability of this software or the suitability of this software for\r
+ * any particular purpose. It is provided "as is" without express or implied\r
+ * warranty of any kind.\r
+ */\r
+\r
+#ifndef _PKCS11_H_\r
+#define _PKCS11_H_ 1\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Before including this file (pkcs11.h) (or pkcs11t.h by\r
+ * itself), 6 platform-specific macros must be defined.  These\r
+ * macros are described below, and typical definitions for them\r
+ * are also given.  Be advised that these definitions can depend\r
+ * on both the platform and the compiler used (and possibly also\r
+ * on whether a Cryptoki library is linked statically or\r
+ * dynamically).\r
+ *\r
+ * In addition to defining these 6 macros, the packing convention\r
+ * for Cryptoki structures should be set.  The Cryptoki\r
+ * convention on packing is that structures should be 1-byte\r
+ * aligned.\r
+ *\r
+ * If you're using Microsoft Developer Studio 5.0 to produce\r
+ * Win32 stuff, this might be done by using the following\r
+ * preprocessor directive before including pkcs11.h or pkcs11t.h:\r
+ *\r
+ * #pragma pack(push, cryptoki, 1)\r
+ *\r
+ * and using the following preprocessor directive after including\r
+ * pkcs11.h or pkcs11t.h:\r
+ *\r
+ * #pragma pack(pop, cryptoki)\r
+ *\r
+ * If you're using an earlier version of Microsoft Developer\r
+ * Studio to produce Win16 stuff, this might be done by using\r
+ * the following preprocessor directive before including\r
+ * pkcs11.h or pkcs11t.h:\r
+ *\r
+ * #pragma pack(1)\r
+ *\r
+ * In a UNIX environment, you're on your own for this.  You might\r
+ * not need to do (or be able to do!) anything.\r
+ *\r
+ *\r
+ * Now for the macros:\r
+ *\r
+ *\r
+ * 1. CK_PTR: The indirection string for making a pointer to an\r
+ * object.  It can be used like this:\r
+ *\r
+ * typedef CK_BYTE CK_PTR CK_BYTE_PTR;\r
+ *\r
+ * If you're using Microsoft Developer Studio 5.0 to produce\r
+ * Win32 stuff, it might be defined by:\r
+ *\r
+ * #define CK_PTR *\r
+ *\r
+ * If you're using an earlier version of Microsoft Developer\r
+ * Studio to produce Win16 stuff, it might be defined by:\r
+ *\r
+ * #define CK_PTR far *\r
+ *\r
+ * In a typical UNIX environment, it might be defined by:\r
+ *\r
+ * #define CK_PTR *\r
+ *\r
+ *\r
+ * 2. CK_DEFINE_FUNCTION(returnType, name): A macro which makes\r
+ * an exportable Cryptoki library function definition out of a\r
+ * return type and a function name.  It should be used in the\r
+ * following fashion to define the exposed Cryptoki functions in\r
+ * a Cryptoki library:\r
+ *\r
+ * CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(\r
+ *   CK_VOID_PTR pReserved\r
+ * )\r
+ * {\r
+ *   ...\r
+ * }\r
+ *\r
+ * If you're using Microsoft Developer Studio 5.0 to define a\r
+ * function in a Win32 Cryptoki .dll, it might be defined by:\r
+ *\r
+ * #define CK_DEFINE_FUNCTION(returnType, name) \\r
+ *   returnType __declspec(dllexport) name\r
+ *\r
+ * If you're using an earlier version of Microsoft Developer\r
+ * Studio to define a function in a Win16 Cryptoki .dll, it\r
+ * might be defined by:\r
+ *\r
+ * #define CK_DEFINE_FUNCTION(returnType, name) \\r
+ *   returnType __export _far _pascal name\r
+ *\r
+ * In a UNIX environment, it might be defined by:\r
+ *\r
+ * #define CK_DEFINE_FUNCTION(returnType, name) \\r
+ *   returnType name\r
+ *\r
+ *\r
+ * 3. CK_DECLARE_FUNCTION(returnType, name): A macro which makes\r
+ * an importable Cryptoki library function declaration out of a\r
+ * return type and a function name.  It should be used in the\r
+ * following fashion:\r
+ *\r
+ * extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(\r
+ *   CK_VOID_PTR pReserved\r
+ * );\r
+ *\r
+ * If you're using Microsoft Developer Studio 5.0 to declare a\r
+ * function in a Win32 Cryptoki .dll, it might be defined by:\r
+ *\r
+ * #define CK_DECLARE_FUNCTION(returnType, name) \\r
+ *   returnType __declspec(dllimport) name\r
+ *\r
+ * If you're using an earlier version of Microsoft Developer\r
+ * Studio to declare a function in a Win16 Cryptoki .dll, it\r
+ * might be defined by:\r
+ *\r
+ * #define CK_DECLARE_FUNCTION(returnType, name) \\r
+ *   returnType __export _far _pascal name\r
+ *\r
+ * In a UNIX environment, it might be defined by:\r
+ *\r
+ * #define CK_DECLARE_FUNCTION(returnType, name) \\r
+ *   returnType name\r
+ *\r
+ *\r
+ * 4. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro\r
+ * which makes a Cryptoki API function pointer declaration or\r
+ * function pointer type declaration out of a return type and a\r
+ * function name.  It should be used in the following fashion:\r
+ *\r
+ * // Define funcPtr to be a pointer to a Cryptoki API function\r
+ * // taking arguments args and returning CK_RV.\r
+ * CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args);\r
+ *\r
+ * or\r
+ *\r
+ * // Define funcPtrType to be the type of a pointer to a\r
+ * // Cryptoki API function taking arguments args and returning\r
+ * // CK_RV, and then define funcPtr to be a variable of type\r
+ * // funcPtrType.\r
+ * typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args);\r
+ * funcPtrType funcPtr;\r
+ *\r
+ * If you're using Microsoft Developer Studio 5.0 to access\r
+ * functions in a Win32 Cryptoki .dll, in might be defined by:\r
+ *\r
+ * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \\r
+ *   returnType __declspec(dllimport) (* name)\r
+ *\r
+ * If you're using an earlier version of Microsoft Developer\r
+ * Studio to access functions in a Win16 Cryptoki .dll, it might\r
+ * be defined by:\r
+ *\r
+ * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \\r
+ *   returnType __export _far _pascal (* name)\r
+ *\r
+ * In a UNIX environment, it might be defined by:\r
+ *\r
+ * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \\r
+ *   returnType (* name)\r
+ *\r
+ *\r
+ * 5. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes\r
+ * a function pointer type for an application callback out of\r
+ * a return type for the callback and a name for the callback.\r
+ * It should be used in the following fashion:\r
+ *\r
+ * CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args);\r
+ *\r
+ * to declare a function pointer, myCallback, to a callback\r
+ * which takes arguments args and returns a CK_RV.  It can also\r
+ * be used like this:\r
+ *\r
+ * typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args);\r
+ * myCallbackType myCallback;\r
+ *\r
+ * If you're using Microsoft Developer Studio 5.0 to do Win32\r
+ * Cryptoki development, it might be defined by:\r
+ *\r
+ * #define CK_CALLBACK_FUNCTION(returnType, name) \\r
+ *   returnType (* name)\r
+ *\r
+ * If you're using an earlier version of Microsoft Developer\r
+ * Studio to do Win16 development, it might be defined by:\r
+ *\r
+ * #define CK_CALLBACK_FUNCTION(returnType, name) \\r
+ *   returnType _far _pascal (* name)\r
+ *\r
+ * In a UNIX environment, it might be defined by:\r
+ *\r
+ * #define CK_CALLBACK_FUNCTION(returnType, name) \\r
+ *   returnType (* name)\r
+ *\r
+ *\r
+ * 6. NULL_PTR: This macro is the value of a NULL pointer.\r
+ *\r
+ * In any ANSI/ISO C environment (and in many others as well),\r
+ * this should best be defined by\r
+ *\r
+ * #ifndef NULL_PTR\r
+ * #define NULL_PTR 0\r
+ * #endif\r
+ */\r
+\r
+\r
+/* All the various Cryptoki types and #define'd values are in the\r
+ * file pkcs11t.h. */\r
+#include "pkcs11t.h"\r
+\r
+#define __PASTE(x,y)      x##y\r
+\r
+\r
+/* ==============================================================\r
+ * Define the "extern" form of all the entry points.\r
+ * ==============================================================\r
+ */\r
+\r
+#define CK_NEED_ARG_LIST  1\r
+#define CK_PKCS11_FUNCTION_INFO(name) \\r
+  extern CK_DECLARE_FUNCTION(CK_RV, name)\r
+\r
+/* pkcs11f.h has all the information about the Cryptoki\r
+ * function prototypes. */\r
+#include "pkcs11f.h"\r
+\r
+#undef CK_NEED_ARG_LIST\r
+#undef CK_PKCS11_FUNCTION_INFO\r
+\r
+\r
+/* ==============================================================\r
+ * Define the typedef form of all the entry points.  That is, for\r
+ * each Cryptoki function C_XXX, define a type CK_C_XXX which is\r
+ * a pointer to that kind of function.\r
+ * ==============================================================\r
+ */\r
+\r
+#define CK_NEED_ARG_LIST  1\r
+#define CK_PKCS11_FUNCTION_INFO(name) \\r
+  typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))\r
+\r
+/* pkcs11f.h has all the information about the Cryptoki\r
+ * function prototypes. */\r
+#include "pkcs11f.h"\r
+\r
+#undef CK_NEED_ARG_LIST\r
+#undef CK_PKCS11_FUNCTION_INFO\r
+\r
+\r
+/* ==============================================================\r
+ * Define structed vector of entry points.  A CK_FUNCTION_LIST\r
+ * contains a CK_VERSION indicating a library's Cryptoki version\r
+ * and then a whole slew of function pointers to the routines in\r
+ * the library.  This type was declared, but not defined, in\r
+ * pkcs11t.h.\r
+ * ==============================================================\r
+ */\r
+\r
+#define CK_PKCS11_FUNCTION_INFO(name) \\r
+  __PASTE(CK_,name) name;\r
+  \r
+struct CK_FUNCTION_LIST {\r
+\r
+  CK_VERSION    version;  /* Cryptoki version */\r
+\r
+/* Pile all the function pointers into the CK_FUNCTION_LIST. */\r
+/* pkcs11f.h has all the information about the Cryptoki\r
+ * function prototypes. */\r
+#include "pkcs11f.h"\r
+\r
+};\r
+\r
+#undef CK_PKCS11_FUNCTION_INFO\r
+\r
+\r
+#undef __PASTE\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/pkcs11f.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/pkcs11f.h
new file mode 100644 (file)
index 0000000..3009753
--- /dev/null
@@ -0,0 +1,912 @@
+/* pkcs11f.h include file for PKCS #11. */\r
+/* $Revision: 1.4 $ */\r
+\r
+/* License to copy and use this software is granted provided that it is\r
+ * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface\r
+ * (Cryptoki)" in all material mentioning or referencing this software.\r
+\r
+ * License is also granted to make and use derivative works provided that\r
+ * such works are identified as "derived from the RSA Security Inc. PKCS #11\r
+ * Cryptographic Token Interface (Cryptoki)" in all material mentioning or \r
+ * referencing the derived work.\r
+\r
+ * RSA Security Inc. makes no representations concerning either the \r
+ * merchantability of this software or the suitability of this software for\r
+ * any particular purpose. It is provided "as is" without express or implied\r
+ * warranty of any kind.\r
+ */\r
+\r
+/* This header file contains pretty much everything about all the */\r
+/* Cryptoki function prototypes.  Because this information is */\r
+/* used for more than just declaring function prototypes, the */\r
+/* order of the functions appearing herein is important, and */\r
+/* should not be altered. */\r
+\r
+/* General-purpose */\r
+\r
+/* C_Initialize initializes the Cryptoki library. */\r
+CK_PKCS11_FUNCTION_INFO(C_Initialize)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_VOID_PTR   pInitArgs  /* if this is not NULL_PTR, it gets\r
+                            * cast to CK_C_INITIALIZE_ARGS_PTR\r
+                            * and dereferenced */\r
+);\r
+#endif\r
+\r
+\r
+/* C_Finalize indicates that an application is done with the\r
+ * Cryptoki library. */\r
+CK_PKCS11_FUNCTION_INFO(C_Finalize)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_VOID_PTR   pReserved  /* reserved.  Should be NULL_PTR */\r
+);\r
+#endif\r
+\r
+\r
+/* C_GetInfo returns general information about Cryptoki. */\r
+CK_PKCS11_FUNCTION_INFO(C_GetInfo)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_INFO_PTR   pInfo  /* location that receives information */\r
+);\r
+#endif\r
+\r
+\r
+/* C_GetFunctionList returns the function list. */\r
+CK_PKCS11_FUNCTION_INFO(C_GetFunctionList)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_FUNCTION_LIST_PTR_PTR ppFunctionList  /* receives pointer to\r
+                                            * function list */\r
+);\r
+#endif\r
+\r
+\r
+\r
+/* Slot and token management */\r
+\r
+/* C_GetSlotList obtains a list of slots in the system. */\r
+CK_PKCS11_FUNCTION_INFO(C_GetSlotList)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_BBOOL       tokenPresent,  /* only slots with tokens? */\r
+  CK_SLOT_ID_PTR pSlotList,     /* receives array of slot IDs */\r
+  CK_ULONG_PTR   pulCount       /* receives number of slots */\r
+);\r
+#endif\r
+\r
+\r
+/* C_GetSlotInfo obtains information about a particular slot in\r
+ * the system. */\r
+CK_PKCS11_FUNCTION_INFO(C_GetSlotInfo)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SLOT_ID       slotID,  /* the ID of the slot */\r
+  CK_SLOT_INFO_PTR pInfo    /* receives the slot information */\r
+);\r
+#endif\r
+\r
+\r
+/* C_GetTokenInfo obtains information about a particular token\r
+ * in the system. */\r
+CK_PKCS11_FUNCTION_INFO(C_GetTokenInfo)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SLOT_ID        slotID,  /* ID of the token's slot */\r
+  CK_TOKEN_INFO_PTR pInfo    /* receives the token information */\r
+);\r
+#endif\r
+\r
+\r
+/* C_GetMechanismList obtains a list of mechanism types\r
+ * supported by a token. */\r
+CK_PKCS11_FUNCTION_INFO(C_GetMechanismList)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SLOT_ID            slotID,          /* ID of token's slot */\r
+  CK_MECHANISM_TYPE_PTR pMechanismList,  /* gets mech. array */\r
+  CK_ULONG_PTR          pulCount         /* gets # of mechs. */\r
+);\r
+#endif\r
+\r
+\r
+/* C_GetMechanismInfo obtains information about a particular\r
+ * mechanism possibly supported by a token. */\r
+CK_PKCS11_FUNCTION_INFO(C_GetMechanismInfo)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SLOT_ID            slotID,  /* ID of the token's slot */\r
+  CK_MECHANISM_TYPE     type,    /* type of mechanism */\r
+  CK_MECHANISM_INFO_PTR pInfo    /* receives mechanism info */\r
+);\r
+#endif\r
+\r
+\r
+/* C_InitToken initializes a token. */\r
+CK_PKCS11_FUNCTION_INFO(C_InitToken)\r
+#ifdef CK_NEED_ARG_LIST\r
+/* pLabel changed from CK_CHAR_PTR to CK_UTF8CHAR_PTR for v2.10 */\r
+(\r
+  CK_SLOT_ID      slotID,    /* ID of the token's slot */\r
+  CK_UTF8CHAR_PTR pPin,      /* the SO's initial PIN */\r
+  CK_ULONG        ulPinLen,  /* length in bytes of the PIN */\r
+  CK_UTF8CHAR_PTR pLabel     /* 32-byte token label (blank padded) */\r
+);\r
+#endif\r
+\r
+\r
+/* C_InitPIN initializes the normal user's PIN. */\r
+CK_PKCS11_FUNCTION_INFO(C_InitPIN)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,  /* the session's handle */\r
+  CK_UTF8CHAR_PTR   pPin,      /* the normal user's PIN */\r
+  CK_ULONG          ulPinLen   /* length in bytes of the PIN */\r
+);\r
+#endif\r
+\r
+\r
+/* C_SetPIN modifies the PIN of the user who is logged in. */\r
+CK_PKCS11_FUNCTION_INFO(C_SetPIN)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,  /* the session's handle */\r
+  CK_UTF8CHAR_PTR   pOldPin,   /* the old PIN */\r
+  CK_ULONG          ulOldLen,  /* length of the old PIN */\r
+  CK_UTF8CHAR_PTR   pNewPin,   /* the new PIN */\r
+  CK_ULONG          ulNewLen   /* length of the new PIN */\r
+);\r
+#endif\r
+\r
+\r
+\r
+/* Session management */\r
+\r
+/* C_OpenSession opens a session between an application and a\r
+ * token. */\r
+CK_PKCS11_FUNCTION_INFO(C_OpenSession)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SLOT_ID            slotID,        /* the slot's ID */\r
+  CK_FLAGS              flags,         /* from CK_SESSION_INFO */\r
+  CK_VOID_PTR           pApplication,  /* passed to callback */\r
+  CK_NOTIFY             Notify,        /* callback function */\r
+  CK_SESSION_HANDLE_PTR phSession      /* gets session handle */\r
+);\r
+#endif\r
+\r
+\r
+/* C_CloseSession closes a session between an application and a\r
+ * token. */\r
+CK_PKCS11_FUNCTION_INFO(C_CloseSession)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession  /* the session's handle */\r
+);\r
+#endif\r
+\r
+\r
+/* C_CloseAllSessions closes all sessions with a token. */\r
+CK_PKCS11_FUNCTION_INFO(C_CloseAllSessions)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SLOT_ID     slotID  /* the token's slot */\r
+);\r
+#endif\r
+\r
+\r
+/* C_GetSessionInfo obtains information about the session. */\r
+CK_PKCS11_FUNCTION_INFO(C_GetSessionInfo)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE   hSession,  /* the session's handle */\r
+  CK_SESSION_INFO_PTR pInfo      /* receives session info */\r
+);\r
+#endif\r
+\r
+\r
+/* C_GetOperationState obtains the state of the cryptographic operation\r
+ * in a session. */\r
+CK_PKCS11_FUNCTION_INFO(C_GetOperationState)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,             /* session's handle */\r
+  CK_BYTE_PTR       pOperationState,      /* gets state */\r
+  CK_ULONG_PTR      pulOperationStateLen  /* gets state length */\r
+);\r
+#endif\r
+\r
+\r
+/* C_SetOperationState restores the state of the cryptographic\r
+ * operation in a session. */\r
+CK_PKCS11_FUNCTION_INFO(C_SetOperationState)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,            /* session's handle */\r
+  CK_BYTE_PTR      pOperationState,      /* holds state */\r
+  CK_ULONG         ulOperationStateLen,  /* holds state length */\r
+  CK_OBJECT_HANDLE hEncryptionKey,       /* en/decryption key */\r
+  CK_OBJECT_HANDLE hAuthenticationKey    /* sign/verify key */\r
+);\r
+#endif\r
+\r
+\r
+/* C_Login logs a user into a token. */\r
+CK_PKCS11_FUNCTION_INFO(C_Login)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,  /* the session's handle */\r
+  CK_USER_TYPE      userType,  /* the user type */\r
+  CK_UTF8CHAR_PTR   pPin,      /* the user's PIN */\r
+  CK_ULONG          ulPinLen   /* the length of the PIN */\r
+);\r
+#endif\r
+\r
+\r
+/* C_Logout logs a user out from a token. */\r
+CK_PKCS11_FUNCTION_INFO(C_Logout)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession  /* the session's handle */\r
+);\r
+#endif\r
+\r
+\r
+\r
+/* Object management */\r
+\r
+/* C_CreateObject creates a new object. */\r
+CK_PKCS11_FUNCTION_INFO(C_CreateObject)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,    /* the session's handle */\r
+  CK_ATTRIBUTE_PTR  pTemplate,   /* the object's template */\r
+  CK_ULONG          ulCount,     /* attributes in template */\r
+  CK_OBJECT_HANDLE_PTR phObject  /* gets new object's handle. */\r
+);\r
+#endif\r
+\r
+\r
+/* C_CopyObject copies an object, creating a new object for the\r
+ * copy. */\r
+CK_PKCS11_FUNCTION_INFO(C_CopyObject)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE    hSession,    /* the session's handle */\r
+  CK_OBJECT_HANDLE     hObject,     /* the object's handle */\r
+  CK_ATTRIBUTE_PTR     pTemplate,   /* template for new object */\r
+  CK_ULONG             ulCount,     /* attributes in template */\r
+  CK_OBJECT_HANDLE_PTR phNewObject  /* receives handle of copy */\r
+);\r
+#endif\r
+\r
+\r
+/* C_DestroyObject destroys an object. */\r
+CK_PKCS11_FUNCTION_INFO(C_DestroyObject)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,  /* the session's handle */\r
+  CK_OBJECT_HANDLE  hObject    /* the object's handle */\r
+);\r
+#endif\r
+\r
+\r
+/* C_GetObjectSize gets the size of an object in bytes. */\r
+CK_PKCS11_FUNCTION_INFO(C_GetObjectSize)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,  /* the session's handle */\r
+  CK_OBJECT_HANDLE  hObject,   /* the object's handle */\r
+  CK_ULONG_PTR      pulSize    /* receives size of object */\r
+);\r
+#endif\r
+\r
+\r
+/* C_GetAttributeValue obtains the value of one or more object\r
+ * attributes. */\r
+CK_PKCS11_FUNCTION_INFO(C_GetAttributeValue)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,   /* the session's handle */\r
+  CK_OBJECT_HANDLE  hObject,    /* the object's handle */\r
+  CK_ATTRIBUTE_PTR  pTemplate,  /* specifies attrs; gets vals */\r
+  CK_ULONG          ulCount     /* attributes in template */\r
+);\r
+#endif\r
+\r
+\r
+/* C_SetAttributeValue modifies the value of one or more object\r
+ * attributes */\r
+CK_PKCS11_FUNCTION_INFO(C_SetAttributeValue)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,   /* the session's handle */\r
+  CK_OBJECT_HANDLE  hObject,    /* the object's handle */\r
+  CK_ATTRIBUTE_PTR  pTemplate,  /* specifies attrs and values */\r
+  CK_ULONG          ulCount     /* attributes in template */\r
+);\r
+#endif\r
+\r
+\r
+/* C_FindObjectsInit initializes a search for token and session\r
+ * objects that match a template. */\r
+CK_PKCS11_FUNCTION_INFO(C_FindObjectsInit)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,   /* the session's handle */\r
+  CK_ATTRIBUTE_PTR  pTemplate,  /* attribute values to match */\r
+  CK_ULONG          ulCount     /* attrs in search template */\r
+);\r
+#endif\r
+\r
+\r
+/* C_FindObjects continues a search for token and session\r
+ * objects that match a template, obtaining additional object\r
+ * handles. */\r
+CK_PKCS11_FUNCTION_INFO(C_FindObjects)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+ CK_SESSION_HANDLE    hSession,          /* session's handle */\r
+ CK_OBJECT_HANDLE_PTR phObject,          /* gets obj. handles */\r
+ CK_ULONG             ulMaxObjectCount,  /* max handles to get */\r
+ CK_ULONG_PTR         pulObjectCount     /* actual # returned */\r
+);\r
+#endif\r
+\r
+\r
+/* C_FindObjectsFinal finishes a search for token and session\r
+ * objects. */\r
+CK_PKCS11_FUNCTION_INFO(C_FindObjectsFinal)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession  /* the session's handle */\r
+);\r
+#endif\r
+\r
+\r
+\r
+/* Encryption and decryption */\r
+\r
+/* C_EncryptInit initializes an encryption operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_EncryptInit)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,    /* the session's handle */\r
+  CK_MECHANISM_PTR  pMechanism,  /* the encryption mechanism */\r
+  CK_OBJECT_HANDLE  hKey         /* handle of encryption key */\r
+);\r
+#endif\r
+\r
+\r
+/* C_Encrypt encrypts single-part data. */\r
+CK_PKCS11_FUNCTION_INFO(C_Encrypt)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,            /* session's handle */\r
+  CK_BYTE_PTR       pData,               /* the plaintext data */\r
+  CK_ULONG          ulDataLen,           /* bytes of plaintext */\r
+  CK_BYTE_PTR       pEncryptedData,      /* gets ciphertext */\r
+  CK_ULONG_PTR      pulEncryptedDataLen  /* gets c-text size */\r
+);\r
+#endif\r
+\r
+\r
+/* C_EncryptUpdate continues a multiple-part encryption\r
+ * operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_EncryptUpdate)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,           /* session's handle */\r
+  CK_BYTE_PTR       pPart,              /* the plaintext data */\r
+  CK_ULONG          ulPartLen,          /* plaintext data len */\r
+  CK_BYTE_PTR       pEncryptedPart,     /* gets ciphertext */\r
+  CK_ULONG_PTR      pulEncryptedPartLen /* gets c-text size */\r
+);\r
+#endif\r
+\r
+\r
+/* C_EncryptFinal finishes a multiple-part encryption\r
+ * operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_EncryptFinal)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,                /* session handle */\r
+  CK_BYTE_PTR       pLastEncryptedPart,      /* last c-text */\r
+  CK_ULONG_PTR      pulLastEncryptedPartLen  /* gets last size */\r
+);\r
+#endif\r
+\r
+\r
+/* C_DecryptInit initializes a decryption operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_DecryptInit)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,    /* the session's handle */\r
+  CK_MECHANISM_PTR  pMechanism,  /* the decryption mechanism */\r
+  CK_OBJECT_HANDLE  hKey         /* handle of decryption key */\r
+);\r
+#endif\r
+\r
+\r
+/* C_Decrypt decrypts encrypted data in a single part. */\r
+CK_PKCS11_FUNCTION_INFO(C_Decrypt)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,           /* session's handle */\r
+  CK_BYTE_PTR       pEncryptedData,     /* ciphertext */\r
+  CK_ULONG          ulEncryptedDataLen, /* ciphertext length */\r
+  CK_BYTE_PTR       pData,              /* gets plaintext */\r
+  CK_ULONG_PTR      pulDataLen          /* gets p-text size */\r
+);\r
+#endif\r
+\r
+\r
+/* C_DecryptUpdate continues a multiple-part decryption\r
+ * operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_DecryptUpdate)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,            /* session's handle */\r
+  CK_BYTE_PTR       pEncryptedPart,      /* encrypted data */\r
+  CK_ULONG          ulEncryptedPartLen,  /* input length */\r
+  CK_BYTE_PTR       pPart,               /* gets plaintext */\r
+  CK_ULONG_PTR      pulPartLen           /* p-text size */\r
+);\r
+#endif\r
+\r
+\r
+/* C_DecryptFinal finishes a multiple-part decryption\r
+ * operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_DecryptFinal)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,       /* the session's handle */\r
+  CK_BYTE_PTR       pLastPart,      /* gets plaintext */\r
+  CK_ULONG_PTR      pulLastPartLen  /* p-text size */\r
+);\r
+#endif\r
+\r
+\r
+\r
+/* Message digesting */\r
+\r
+/* C_DigestInit initializes a message-digesting operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_DigestInit)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,   /* the session's handle */\r
+  CK_MECHANISM_PTR  pMechanism  /* the digesting mechanism */\r
+);\r
+#endif\r
+\r
+\r
+/* C_Digest digests data in a single part. */\r
+CK_PKCS11_FUNCTION_INFO(C_Digest)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,     /* the session's handle */\r
+  CK_BYTE_PTR       pData,        /* data to be digested */\r
+  CK_ULONG          ulDataLen,    /* bytes of data to digest */\r
+  CK_BYTE_PTR       pDigest,      /* gets the message digest */\r
+  CK_ULONG_PTR      pulDigestLen  /* gets digest length */\r
+);\r
+#endif\r
+\r
+\r
+/* C_DigestUpdate continues a multiple-part message-digesting\r
+ * operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_DigestUpdate)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,  /* the session's handle */\r
+  CK_BYTE_PTR       pPart,     /* data to be digested */\r
+  CK_ULONG          ulPartLen  /* bytes of data to be digested */\r
+);\r
+#endif\r
+\r
+\r
+/* C_DigestKey continues a multi-part message-digesting\r
+ * operation, by digesting the value of a secret key as part of\r
+ * the data already digested. */\r
+CK_PKCS11_FUNCTION_INFO(C_DigestKey)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,  /* the session's handle */\r
+  CK_OBJECT_HANDLE  hKey       /* secret key to digest */\r
+);\r
+#endif\r
+\r
+\r
+/* C_DigestFinal finishes a multiple-part message-digesting\r
+ * operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_DigestFinal)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,     /* the session's handle */\r
+  CK_BYTE_PTR       pDigest,      /* gets the message digest */\r
+  CK_ULONG_PTR      pulDigestLen  /* gets byte count of digest */\r
+);\r
+#endif\r
+\r
+\r
+\r
+/* Signing and MACing */\r
+\r
+/* C_SignInit initializes a signature (private key encryption)\r
+ * operation, where the signature is (will be) an appendix to\r
+ * the data, and plaintext cannot be recovered from the\r
+ *signature. */\r
+CK_PKCS11_FUNCTION_INFO(C_SignInit)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,    /* the session's handle */\r
+  CK_MECHANISM_PTR  pMechanism,  /* the signature mechanism */\r
+  CK_OBJECT_HANDLE  hKey         /* handle of signature key */\r
+);\r
+#endif\r
+\r
+\r
+/* C_Sign signs (encrypts with private key) data in a single\r
+ * part, where the signature is (will be) an appendix to the\r
+ * data, and plaintext cannot be recovered from the signature. */\r
+CK_PKCS11_FUNCTION_INFO(C_Sign)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,        /* the session's handle */\r
+  CK_BYTE_PTR       pData,           /* the data to sign */\r
+  CK_ULONG          ulDataLen,       /* count of bytes to sign */\r
+  CK_BYTE_PTR       pSignature,      /* gets the signature */\r
+  CK_ULONG_PTR      pulSignatureLen  /* gets signature length */\r
+);\r
+#endif\r
+\r
+\r
+/* C_SignUpdate continues a multiple-part signature operation,\r
+ * where the signature is (will be) an appendix to the data, \r
+ * and plaintext cannot be recovered from the signature. */\r
+CK_PKCS11_FUNCTION_INFO(C_SignUpdate)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,  /* the session's handle */\r
+  CK_BYTE_PTR       pPart,     /* the data to sign */\r
+  CK_ULONG          ulPartLen  /* count of bytes to sign */\r
+);\r
+#endif\r
+\r
+\r
+/* C_SignFinal finishes a multiple-part signature operation, \r
+ * returning the signature. */\r
+CK_PKCS11_FUNCTION_INFO(C_SignFinal)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,        /* the session's handle */\r
+  CK_BYTE_PTR       pSignature,      /* gets the signature */\r
+  CK_ULONG_PTR      pulSignatureLen  /* gets signature length */\r
+);\r
+#endif\r
+\r
+\r
+/* C_SignRecoverInit initializes a signature operation, where\r
+ * the data can be recovered from the signature. */\r
+CK_PKCS11_FUNCTION_INFO(C_SignRecoverInit)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,   /* the session's handle */\r
+  CK_MECHANISM_PTR  pMechanism, /* the signature mechanism */\r
+  CK_OBJECT_HANDLE  hKey        /* handle of the signature key */\r
+);\r
+#endif\r
+\r
+\r
+/* C_SignRecover signs data in a single operation, where the\r
+ * data can be recovered from the signature. */\r
+CK_PKCS11_FUNCTION_INFO(C_SignRecover)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,        /* the session's handle */\r
+  CK_BYTE_PTR       pData,           /* the data to sign */\r
+  CK_ULONG          ulDataLen,       /* count of bytes to sign */\r
+  CK_BYTE_PTR       pSignature,      /* gets the signature */\r
+  CK_ULONG_PTR      pulSignatureLen  /* gets signature length */\r
+);\r
+#endif\r
+\r
+\r
+\r
+/* Verifying signatures and MACs */\r
+\r
+/* C_VerifyInit initializes a verification operation, where the\r
+ * signature is an appendix to the data, and plaintext cannot\r
+ *  cannot be recovered from the signature (e.g. DSA). */\r
+CK_PKCS11_FUNCTION_INFO(C_VerifyInit)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,    /* the session's handle */\r
+  CK_MECHANISM_PTR  pMechanism,  /* the verification mechanism */\r
+  CK_OBJECT_HANDLE  hKey         /* verification key */ \r
+);\r
+#endif\r
+\r
+\r
+/* C_Verify verifies a signature in a single-part operation, \r
+ * where the signature is an appendix to the data, and plaintext\r
+ * cannot be recovered from the signature. */\r
+CK_PKCS11_FUNCTION_INFO(C_Verify)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,       /* the session's handle */\r
+  CK_BYTE_PTR       pData,          /* signed data */\r
+  CK_ULONG          ulDataLen,      /* length of signed data */\r
+  CK_BYTE_PTR       pSignature,     /* signature */\r
+  CK_ULONG          ulSignatureLen  /* signature length*/\r
+);\r
+#endif\r
+\r
+\r
+/* C_VerifyUpdate continues a multiple-part verification\r
+ * operation, where the signature is an appendix to the data, \r
+ * and plaintext cannot be recovered from the signature. */\r
+CK_PKCS11_FUNCTION_INFO(C_VerifyUpdate)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,  /* the session's handle */\r
+  CK_BYTE_PTR       pPart,     /* signed data */\r
+  CK_ULONG          ulPartLen  /* length of signed data */\r
+);\r
+#endif\r
+\r
+\r
+/* C_VerifyFinal finishes a multiple-part verification\r
+ * operation, checking the signature. */\r
+CK_PKCS11_FUNCTION_INFO(C_VerifyFinal)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,       /* the session's handle */\r
+  CK_BYTE_PTR       pSignature,     /* signature to verify */\r
+  CK_ULONG          ulSignatureLen  /* signature length */\r
+);\r
+#endif\r
+\r
+\r
+/* C_VerifyRecoverInit initializes a signature verification\r
+ * operation, where the data is recovered from the signature. */\r
+CK_PKCS11_FUNCTION_INFO(C_VerifyRecoverInit)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,    /* the session's handle */\r
+  CK_MECHANISM_PTR  pMechanism,  /* the verification mechanism */\r
+  CK_OBJECT_HANDLE  hKey         /* verification key */\r
+);\r
+#endif\r
+\r
+\r
+/* C_VerifyRecover verifies a signature in a single-part\r
+ * operation, where the data is recovered from the signature. */\r
+CK_PKCS11_FUNCTION_INFO(C_VerifyRecover)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,        /* the session's handle */\r
+  CK_BYTE_PTR       pSignature,      /* signature to verify */\r
+  CK_ULONG          ulSignatureLen,  /* signature length */\r
+  CK_BYTE_PTR       pData,           /* gets signed data */\r
+  CK_ULONG_PTR      pulDataLen       /* gets signed data len */\r
+);\r
+#endif\r
+\r
+\r
+\r
+/* Dual-function cryptographic operations */\r
+\r
+/* C_DigestEncryptUpdate continues a multiple-part digesting\r
+ * and encryption operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_DigestEncryptUpdate)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,            /* session's handle */\r
+  CK_BYTE_PTR       pPart,               /* the plaintext data */\r
+  CK_ULONG          ulPartLen,           /* plaintext length */\r
+  CK_BYTE_PTR       pEncryptedPart,      /* gets ciphertext */\r
+  CK_ULONG_PTR      pulEncryptedPartLen  /* gets c-text length */\r
+);\r
+#endif\r
+\r
+\r
+/* C_DecryptDigestUpdate continues a multiple-part decryption and\r
+ * digesting operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_DecryptDigestUpdate)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,            /* session's handle */\r
+  CK_BYTE_PTR       pEncryptedPart,      /* ciphertext */\r
+  CK_ULONG          ulEncryptedPartLen,  /* ciphertext length */\r
+  CK_BYTE_PTR       pPart,               /* gets plaintext */\r
+  CK_ULONG_PTR      pulPartLen           /* gets plaintext len */\r
+);\r
+#endif\r
+\r
+\r
+/* C_SignEncryptUpdate continues a multiple-part signing and\r
+ * encryption operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_SignEncryptUpdate)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,            /* session's handle */\r
+  CK_BYTE_PTR       pPart,               /* the plaintext data */\r
+  CK_ULONG          ulPartLen,           /* plaintext length */\r
+  CK_BYTE_PTR       pEncryptedPart,      /* gets ciphertext */\r
+  CK_ULONG_PTR      pulEncryptedPartLen  /* gets c-text length */\r
+);\r
+#endif\r
+\r
+\r
+/* C_DecryptVerifyUpdate continues a multiple-part decryption and\r
+ * verify operation. */\r
+CK_PKCS11_FUNCTION_INFO(C_DecryptVerifyUpdate)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,            /* session's handle */\r
+  CK_BYTE_PTR       pEncryptedPart,      /* ciphertext */\r
+  CK_ULONG          ulEncryptedPartLen,  /* ciphertext length */\r
+  CK_BYTE_PTR       pPart,               /* gets plaintext */\r
+  CK_ULONG_PTR      pulPartLen           /* gets p-text length */\r
+);\r
+#endif\r
+\r
+\r
+\r
+/* Key management */\r
+\r
+/* C_GenerateKey generates a secret key, creating a new key\r
+ * object. */\r
+CK_PKCS11_FUNCTION_INFO(C_GenerateKey)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE    hSession,    /* the session's handle */\r
+  CK_MECHANISM_PTR     pMechanism,  /* key generation mech. */\r
+  CK_ATTRIBUTE_PTR     pTemplate,   /* template for new key */\r
+  CK_ULONG             ulCount,     /* # of attrs in template */\r
+  CK_OBJECT_HANDLE_PTR phKey        /* gets handle of new key */\r
+);\r
+#endif\r
+\r
+\r
+/* C_GenerateKeyPair generates a public-key/private-key pair, \r
+ * creating new key objects. */\r
+CK_PKCS11_FUNCTION_INFO(C_GenerateKeyPair)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE    hSession,                    /* session\r
+                                                     * handle */\r
+  CK_MECHANISM_PTR     pMechanism,                  /* key-gen\r
+                                                     * mech. */\r
+  CK_ATTRIBUTE_PTR     pPublicKeyTemplate,          /* template\r
+                                                     * for pub.\r
+                                                     * key */\r
+  CK_ULONG             ulPublicKeyAttributeCount,   /* # pub.\r
+                                                     * attrs. */\r
+  CK_ATTRIBUTE_PTR     pPrivateKeyTemplate,         /* template\r
+                                                     * for priv.\r
+                                                     * key */\r
+  CK_ULONG             ulPrivateKeyAttributeCount,  /* # priv.\r
+                                                     * attrs. */\r
+  CK_OBJECT_HANDLE_PTR phPublicKey,                 /* gets pub.\r
+                                                     * key\r
+                                                     * handle */\r
+  CK_OBJECT_HANDLE_PTR phPrivateKey                 /* gets\r
+                                                     * priv. key\r
+                                                     * handle */\r
+);\r
+#endif\r
+\r
+\r
+/* C_WrapKey wraps (i.e., encrypts) a key. */\r
+CK_PKCS11_FUNCTION_INFO(C_WrapKey)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,        /* the session's handle */\r
+  CK_MECHANISM_PTR  pMechanism,      /* the wrapping mechanism */\r
+  CK_OBJECT_HANDLE  hWrappingKey,    /* wrapping key */\r
+  CK_OBJECT_HANDLE  hKey,            /* key to be wrapped */\r
+  CK_BYTE_PTR       pWrappedKey,     /* gets wrapped key */\r
+  CK_ULONG_PTR      pulWrappedKeyLen /* gets wrapped key size */\r
+);\r
+#endif\r
+\r
+\r
+/* C_UnwrapKey unwraps (decrypts) a wrapped key, creating a new\r
+ * key object. */\r
+CK_PKCS11_FUNCTION_INFO(C_UnwrapKey)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE    hSession,          /* session's handle */\r
+  CK_MECHANISM_PTR     pMechanism,        /* unwrapping mech. */\r
+  CK_OBJECT_HANDLE     hUnwrappingKey,    /* unwrapping key */\r
+  CK_BYTE_PTR          pWrappedKey,       /* the wrapped key */\r
+  CK_ULONG             ulWrappedKeyLen,   /* wrapped key len */\r
+  CK_ATTRIBUTE_PTR     pTemplate,         /* new key template */\r
+  CK_ULONG             ulAttributeCount,  /* template length */\r
+  CK_OBJECT_HANDLE_PTR phKey              /* gets new handle */\r
+);\r
+#endif\r
+\r
+\r
+/* C_DeriveKey derives a key from a base key, creating a new key\r
+ * object. */\r
+CK_PKCS11_FUNCTION_INFO(C_DeriveKey)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE    hSession,          /* session's handle */\r
+  CK_MECHANISM_PTR     pMechanism,        /* key deriv. mech. */\r
+  CK_OBJECT_HANDLE     hBaseKey,          /* base key */\r
+  CK_ATTRIBUTE_PTR     pTemplate,         /* new key template */\r
+  CK_ULONG             ulAttributeCount,  /* template length */\r
+  CK_OBJECT_HANDLE_PTR phKey              /* gets new handle */\r
+);\r
+#endif\r
+\r
+\r
+\r
+/* Random number generation */\r
+\r
+/* C_SeedRandom mixes additional seed material into the token's\r
+ * random number generator. */\r
+CK_PKCS11_FUNCTION_INFO(C_SeedRandom)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,  /* the session's handle */\r
+  CK_BYTE_PTR       pSeed,     /* the seed material */\r
+  CK_ULONG          ulSeedLen  /* length of seed material */\r
+);\r
+#endif\r
+\r
+\r
+/* C_GenerateRandom generates random data. */\r
+CK_PKCS11_FUNCTION_INFO(C_GenerateRandom)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession,    /* the session's handle */\r
+  CK_BYTE_PTR       RandomData,  /* receives the random data */\r
+  CK_ULONG          ulRandomLen  /* # of bytes to generate */\r
+);\r
+#endif\r
+\r
+\r
+\r
+/* Parallel function management */\r
+\r
+/* C_GetFunctionStatus is a legacy function; it obtains an\r
+ * updated status of a function running in parallel with an\r
+ * application. */\r
+CK_PKCS11_FUNCTION_INFO(C_GetFunctionStatus)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession  /* the session's handle */\r
+);\r
+#endif\r
+\r
+\r
+/* C_CancelFunction is a legacy function; it cancels a function\r
+ * running in parallel. */\r
+CK_PKCS11_FUNCTION_INFO(C_CancelFunction)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_SESSION_HANDLE hSession  /* the session's handle */\r
+);\r
+#endif\r
+\r
+\r
+\r
+/* Functions added in for Cryptoki Version 2.01 or later */\r
+\r
+/* C_WaitForSlotEvent waits for a slot event (token insertion,\r
+ * removal, etc.) to occur. */\r
+CK_PKCS11_FUNCTION_INFO(C_WaitForSlotEvent)\r
+#ifdef CK_NEED_ARG_LIST\r
+(\r
+  CK_FLAGS flags,        /* blocking/nonblocking flag */\r
+  CK_SLOT_ID_PTR pSlot,  /* location that receives the slot ID */\r
+  CK_VOID_PTR pRserved   /* reserved.  Should be NULL_PTR */\r
+);\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/pkcs11t.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/pkcs11t.h
new file mode 100644 (file)
index 0000000..7a0f406
--- /dev/null
@@ -0,0 +1,1440 @@
+/* pkcs11t.h include file for PKCS #11. */\r
+/* $Revision: 1.4 $ */\r
+\r
+/* License to copy and use this software is granted provided that it is\r
+ * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface\r
+ * (Cryptoki)" in all material mentioning or referencing this software.\r
+\r
+ * License is also granted to make and use derivative works provided that\r
+ * such works are identified as "derived from the RSA Security Inc. PKCS #11\r
+ * Cryptographic Token Interface (Cryptoki)" in all material mentioning or \r
+ * referencing the derived work.\r
+\r
+ * RSA Security Inc. makes no representations concerning either the \r
+ * merchantability of this software or the suitability of this software for\r
+ * any particular purpose. It is provided "as is" without express or implied\r
+ * warranty of any kind.\r
+ */\r
+\r
+/* See top of pkcs11.h for information about the macros that\r
+ * must be defined and the structure-packing conventions that\r
+ * must be set before including this file. */\r
+\r
+#ifndef _PKCS11T_H_\r
+#define _PKCS11T_H_ 1\r
+\r
+#ifndef CK_DISABLE_TRUE_FALSE\r
+#ifndef FALSE\r
+#define FALSE 0\r
+#endif\r
+\r
+#ifndef TRUE\r
+#define TRUE !(FALSE)\r
+#endif\r
+#endif\r
+\r
+#define CK_TRUE 1\r
+#define CK_FALSE 0\r
+\r
+/* an unsigned 8-bit value */\r
+typedef unsigned char     CK_BYTE;\r
+\r
+/* an unsigned 8-bit character */\r
+typedef CK_BYTE           CK_CHAR;\r
+\r
+/* an 8-bit UTF-8 character */\r
+typedef CK_BYTE           CK_UTF8CHAR;\r
+\r
+/* a BYTE-sized Boolean flag */\r
+typedef CK_BYTE           CK_BBOOL;\r
+\r
+/* an unsigned value, at least 32 bits long */\r
+typedef unsigned long int CK_ULONG;\r
+\r
+/* a signed value, the same size as a CK_ULONG */\r
+/* CK_LONG is new for v2.0 */\r
+typedef long int          CK_LONG;\r
+\r
+/* at least 32 bits; each bit is a Boolean flag */\r
+typedef CK_ULONG          CK_FLAGS;\r
+\r
+\r
+/* some special values for certain CK_ULONG variables */\r
+#define CK_UNAVAILABLE_INFORMATION (~0UL)\r
+#define CK_EFFECTIVELY_INFINITE    0\r
+\r
+\r
+typedef CK_BYTE     CK_PTR   CK_BYTE_PTR;\r
+typedef CK_CHAR     CK_PTR   CK_CHAR_PTR;\r
+typedef CK_UTF8CHAR CK_PTR   CK_UTF8CHAR_PTR;\r
+typedef CK_ULONG    CK_PTR   CK_ULONG_PTR;\r
+typedef void        CK_PTR   CK_VOID_PTR;\r
+\r
+/* Pointer to a CK_VOID_PTR-- i.e., pointer to pointer to void */\r
+typedef CK_VOID_PTR CK_PTR CK_VOID_PTR_PTR;\r
+\r
+\r
+/* The following value is always invalid if used as a session */\r
+/* handle or object handle */\r
+#define CK_INVALID_HANDLE 0\r
+\r
+\r
+typedef struct CK_VERSION {\r
+  CK_BYTE       major;  /* integer portion of version number */\r
+  CK_BYTE       minor;  /* 1/100ths portion of version number */\r
+} CK_VERSION;\r
+\r
+typedef CK_VERSION CK_PTR CK_VERSION_PTR;\r
+\r
+\r
+typedef struct CK_INFO {\r
+  /* manufacturerID and libraryDecription have been changed from\r
+   * CK_CHAR to CK_UTF8CHAR for v2.10 */\r
+  CK_VERSION    cryptokiVersion;     /* Cryptoki interface ver */\r
+  CK_UTF8CHAR   manufacturerID[32];  /* blank padded */\r
+  CK_FLAGS      flags;               /* must be zero */\r
+\r
+  /* libraryDescription and libraryVersion are new for v2.0 */\r
+  CK_UTF8CHAR   libraryDescription[32];  /* blank padded */\r
+  CK_VERSION    libraryVersion;          /* version of library */\r
+} CK_INFO;\r
+\r
+typedef CK_INFO CK_PTR    CK_INFO_PTR;\r
+\r
+\r
+/* CK_NOTIFICATION enumerates the types of notifications that\r
+ * Cryptoki provides to an application */\r
+/* CK_NOTIFICATION has been changed from an enum to a CK_ULONG\r
+ * for v2.0 */\r
+typedef CK_ULONG CK_NOTIFICATION;\r
+#define CKN_SURRENDER       0\r
+\r
+\r
+typedef CK_ULONG          CK_SLOT_ID;\r
+\r
+typedef CK_SLOT_ID CK_PTR CK_SLOT_ID_PTR;\r
+\r
+\r
+/* CK_SLOT_INFO provides information about a slot */\r
+typedef struct CK_SLOT_INFO {\r
+  /* slotDescription and manufacturerID have been changed from\r
+   * CK_CHAR to CK_UTF8CHAR for v2.10 */\r
+  CK_UTF8CHAR   slotDescription[64];  /* blank padded */\r
+  CK_UTF8CHAR   manufacturerID[32];   /* blank padded */\r
+  CK_FLAGS      flags;\r
+\r
+  /* hardwareVersion and firmwareVersion are new for v2.0 */\r
+  CK_VERSION    hardwareVersion;  /* version of hardware */\r
+  CK_VERSION    firmwareVersion;  /* version of firmware */\r
+} CK_SLOT_INFO;\r
+\r
+/* flags: bit flags that provide capabilities of the slot\r
+ *      Bit Flag              Mask        Meaning\r
+ */\r
+#define CKF_TOKEN_PRESENT     0x00000001  /* a token is there */\r
+#define CKF_REMOVABLE_DEVICE  0x00000002  /* removable devices*/\r
+#define CKF_HW_SLOT           0x00000004  /* hardware slot */\r
+\r
+typedef CK_SLOT_INFO CK_PTR CK_SLOT_INFO_PTR;\r
+\r
+\r
+/* CK_TOKEN_INFO provides information about a token */\r
+typedef struct CK_TOKEN_INFO {\r
+  /* label, manufacturerID, and model have been changed from\r
+   * CK_CHAR to CK_UTF8CHAR for v2.10 */\r
+  CK_UTF8CHAR   label[32];           /* blank padded */\r
+  CK_UTF8CHAR   manufacturerID[32];  /* blank padded */\r
+  CK_UTF8CHAR   model[16];           /* blank padded */\r
+  CK_CHAR       serialNumber[16];    /* blank padded */\r
+  CK_FLAGS      flags;               /* see below */\r
+\r
+  /* ulMaxSessionCount, ulSessionCount, ulMaxRwSessionCount,\r
+   * ulRwSessionCount, ulMaxPinLen, and ulMinPinLen have all been\r
+   * changed from CK_USHORT to CK_ULONG for v2.0 */\r
+  CK_ULONG      ulMaxSessionCount;     /* max open sessions */\r
+  CK_ULONG      ulSessionCount;        /* sess. now open */\r
+  CK_ULONG      ulMaxRwSessionCount;   /* max R/W sessions */\r
+  CK_ULONG      ulRwSessionCount;      /* R/W sess. now open */\r
+  CK_ULONG      ulMaxPinLen;           /* in bytes */\r
+  CK_ULONG      ulMinPinLen;           /* in bytes */\r
+  CK_ULONG      ulTotalPublicMemory;   /* in bytes */\r
+  CK_ULONG      ulFreePublicMemory;    /* in bytes */\r
+  CK_ULONG      ulTotalPrivateMemory;  /* in bytes */\r
+  CK_ULONG      ulFreePrivateMemory;   /* in bytes */\r
+\r
+  /* hardwareVersion, firmwareVersion, and time are new for\r
+   * v2.0 */\r
+  CK_VERSION    hardwareVersion;       /* version of hardware */\r
+  CK_VERSION    firmwareVersion;       /* version of firmware */\r
+  CK_CHAR       utcTime[16];           /* time */\r
+} CK_TOKEN_INFO;\r
+\r
+/* The flags parameter is defined as follows:\r
+ *      Bit Flag                    Mask        Meaning \r
+ */\r
+#define CKF_RNG                     0x00000001  /* has random #\r
+                                                 * generator */\r
+#define CKF_WRITE_PROTECTED         0x00000002  /* token is\r
+                                                 * write-\r
+                                                 * protected */\r
+#define CKF_LOGIN_REQUIRED          0x00000004  /* user must\r
+                                                 * login */\r
+#define CKF_USER_PIN_INITIALIZED    0x00000008  /* normal user's\r
+                                                 * PIN is set */\r
+\r
+/* CKF_RESTORE_KEY_NOT_NEEDED is new for v2.0.  If it is set,\r
+ * that means that *every* time the state of cryptographic\r
+ * operations of a session is successfully saved, all keys\r
+ * needed to continue those operations are stored in the state */\r
+#define CKF_RESTORE_KEY_NOT_NEEDED  0x00000020\r
+\r
+/* CKF_CLOCK_ON_TOKEN is new for v2.0.  If it is set, that means\r
+ * that the token has some sort of clock.  The time on that\r
+ * clock is returned in the token info structure */\r
+#define CKF_CLOCK_ON_TOKEN          0x00000040\r
+\r
+/* CKF_PROTECTED_AUTHENTICATION_PATH is new for v2.0.  If it is\r
+ * set, that means that there is some way for the user to login\r
+ * without sending a PIN through the Cryptoki library itself */\r
+#define CKF_PROTECTED_AUTHENTICATION_PATH 0x00000100\r
+\r
+/* CKF_DUAL_CRYPTO_OPERATIONS is new for v2.0.  If it is true,\r
+ * that means that a single session with the token can perform\r
+ * dual simultaneous cryptographic operations (digest and\r
+ * encrypt; decrypt and digest; sign and encrypt; and decrypt\r
+ * and sign) */\r
+#define CKF_DUAL_CRYPTO_OPERATIONS  0x00000200\r
+\r
+/* CKF_TOKEN_INITIALIZED if new for v2.10. If it is true, the\r
+ * token has been initialized using C_InitializeToken or an \r
+ * equivalent mechanism outside the scope of PKCS #11.\r
+ * Calling C_InitializeToken when this flag is set will cause \r
+ * the token to be reinitialized. */\r
+#define CKF_TOKEN_INITIALIZED       0x00000400\r
+\r
+/* CKF_SECONDARY_AUTHENTICATION if new for v2.10. If it is \r
+ * true, the token supports secondary authentication for \r
+ * private key objects. */\r
+#define CKF_SECONDARY_AUTHENTICATION  0x00000800\r
+\r
+/* CKF_USER_PIN_COUNT_LOW if new for v2.10. If it is true, an \r
+ * incorrect user login PIN has been entered at least once \r
+ * since the last successful authentication. */\r
+#define CKF_USER_PIN_COUNT_LOW       0x00010000\r
+\r
+/* CKF_USER_PIN_FINAL_TRY if new for v2.10. If it is true,\r
+ * supplying an incorrect user PIN will it to become locked. */\r
+#define CKF_USER_PIN_FINAL_TRY       0x00020000\r
+\r
+/* CKF_USER_PIN_LOCKED if new for v2.10. If it is true, the \r
+ * user PIN has been locked. User login to the token is not \r
+ * possible. */\r
+#define CKF_USER_PIN_LOCKED          0x00040000\r
+\r
+/* CKF_USER_PIN_TO_BE_CHANGED if new for v2.10. If it is true, \r
+ * the user PIN value is the default value set by token \r
+ * initialization or manufacturing, or the PIN has been\r
+ * expired by the card. */\r
+#define CKF_USER_PIN_TO_BE_CHANGED   0x00080000\r
+\r
+/* CKF_SO_PIN_COUNT_LOW if new for v2.10. If it is true, an \r
+ * incorrect SO login PIN has been entered at least once since \r
+ * the last successful authentication. */\r
+#define CKF_SO_PIN_COUNT_LOW         0x00100000\r
+\r
+/* CKF_SO_PIN_FINAL_TRY if new for v2.10. If it is true,\r
+ * supplying an incorrect SO PIN will it to become locked. */\r
+#define CKF_SO_PIN_FINAL_TRY         0x00200000\r
+\r
+/* CKF_SO_PIN_LOCKED if new for v2.10. If it is true, the SO \r
+ * PIN has been locked. SO login to the token is not possible.\r
+ */\r
+#define CKF_SO_PIN_LOCKED            0x00400000\r
+\r
+/* CKF_SO_PIN_TO_BE_CHANGED if new for v2.10. If it is true, \r
+ * the SO PIN value is the default value set by token \r
+ * initialization or manufacturing, or the PIN has been\r
+ * expired by the card. */\r
+#define CKF_SO_PIN_TO_BE_CHANGED     0x00800000\r
+\r
+typedef CK_TOKEN_INFO CK_PTR CK_TOKEN_INFO_PTR;\r
+\r
+\r
+/* CK_SESSION_HANDLE is a Cryptoki-assigned value that\r
+ * identifies a session */\r
+typedef CK_ULONG          CK_SESSION_HANDLE;\r
+\r
+typedef CK_SESSION_HANDLE CK_PTR CK_SESSION_HANDLE_PTR; \r
+\r
+\r
+/* CK_USER_TYPE enumerates the types of Cryptoki users */\r
+/* CK_USER_TYPE has been changed from an enum to a CK_ULONG for\r
+ * v2.0 */\r
+typedef CK_ULONG          CK_USER_TYPE;\r
+/* Security Officer */\r
+#define CKU_SO    0\r
+/* Normal user */\r
+#define CKU_USER  1\r
+\r
+\r
+/* CK_STATE enumerates the session states */\r
+/* CK_STATE has been changed from an enum to a CK_ULONG for\r
+ * v2.0 */\r
+typedef CK_ULONG          CK_STATE;\r
+#define CKS_RO_PUBLIC_SESSION  0\r
+#define CKS_RO_USER_FUNCTIONS  1\r
+#define CKS_RW_PUBLIC_SESSION  2\r
+#define CKS_RW_USER_FUNCTIONS  3\r
+#define CKS_RW_SO_FUNCTIONS    4\r
+\r
+\r
+/* CK_SESSION_INFO provides information about a session */\r
+typedef struct CK_SESSION_INFO {\r
+  CK_SLOT_ID    slotID;\r
+  CK_STATE      state;\r
+  CK_FLAGS      flags;          /* see below */\r
+\r
+  /* ulDeviceError was changed from CK_USHORT to CK_ULONG for\r
+   * v2.0 */\r
+  CK_ULONG      ulDeviceError;  /* device-dependent error code */\r
+} CK_SESSION_INFO;\r
+\r
+/* The flags are defined in the following table:\r
+ *      Bit Flag                Mask        Meaning\r
+ */\r
+#define CKF_RW_SESSION          0x00000002  /* session is r/w */\r
+#define CKF_SERIAL_SESSION      0x00000004  /* no parallel */\r
+\r
+typedef CK_SESSION_INFO CK_PTR CK_SESSION_INFO_PTR;\r
+\r
+\r
+/* CK_OBJECT_HANDLE is a token-specific identifier for an\r
+ * object  */\r
+typedef CK_ULONG          CK_OBJECT_HANDLE;\r
+\r
+typedef CK_OBJECT_HANDLE CK_PTR CK_OBJECT_HANDLE_PTR;\r
+\r
+\r
+/* CK_OBJECT_CLASS is a value that identifies the classes (or\r
+ * types) of objects that Cryptoki recognizes.  It is defined\r
+ * as follows: */\r
+/* CK_OBJECT_CLASS was changed from CK_USHORT to CK_ULONG for\r
+ * v2.0 */\r
+typedef CK_ULONG          CK_OBJECT_CLASS;\r
+\r
+/* The following classes of objects are defined: */\r
+/* CKO_HW_FEATURE is new for v2.10 */\r
+/* CKO_DOMAIN_PARAMETERS is new for v2.11 */\r
+#define CKO_DATA              0x00000000\r
+#define CKO_CERTIFICATE       0x00000001\r
+#define CKO_PUBLIC_KEY        0x00000002\r
+#define CKO_PRIVATE_KEY       0x00000003\r
+#define CKO_SECRET_KEY        0x00000004\r
+#define CKO_HW_FEATURE        0x00000005\r
+#define CKO_DOMAIN_PARAMETERS 0x00000006\r
+#define CKO_VENDOR_DEFINED    0x80000000\r
+\r
+typedef CK_OBJECT_CLASS CK_PTR CK_OBJECT_CLASS_PTR;\r
+\r
+/* CK_HW_FEATURE_TYPE is new for v2.10. CK_HW_FEATURE_TYPE is a\r
+ * value that identifies the hardware feature type of an object\r
+ * with CK_OBJECT_CLASS equal to CKO_HW_FEATURE. */\r
+typedef CK_ULONG          CK_HW_FEATURE_TYPE;\r
\r
+/* The following hardware feature types are defined */\r
+#define CKH_MONOTONIC_COUNTER  0x00000001\r
+#define CKH_CLOCK           0x00000002\r
+#define CKH_VENDOR_DEFINED  0x80000000\r
+\r
+/* CK_KEY_TYPE is a value that identifies a key type */\r
+/* CK_KEY_TYPE was changed from CK_USHORT to CK_ULONG for v2.0 */\r
+typedef CK_ULONG          CK_KEY_TYPE;\r
+\r
+/* the following key types are defined: */\r
+#define CKK_RSA             0x00000000\r
+#define CKK_DSA             0x00000001\r
+#define CKK_DH              0x00000002\r
+\r
+/* CKK_ECDSA and CKK_KEA are new for v2.0 */\r
+/* CKK_ECDSA is deprecated in v2.11, CKK_EC is preferred. */\r
+#define CKK_ECDSA           0x00000003\r
+#define CKK_EC              0x00000003\r
+#define CKK_X9_42_DH        0x00000004\r
+#define CKK_KEA             0x00000005\r
+\r
+#define CKK_GENERIC_SECRET  0x00000010\r
+#define CKK_RC2             0x00000011\r
+#define CKK_RC4             0x00000012\r
+#define CKK_DES             0x00000013\r
+#define CKK_DES2            0x00000014\r
+#define CKK_DES3            0x00000015\r
+\r
+/* all these key types are new for v2.0 */\r
+#define CKK_CAST            0x00000016\r
+#define CKK_CAST3           0x00000017\r
+/* CKK_CAST5 is deprecated in v2.11, CKK_CAST128 is preferred. */\r
+#define CKK_CAST5           0x00000018\r
+#define CKK_CAST128         0x00000018\r
+#define CKK_RC5             0x00000019\r
+#define CKK_IDEA            0x0000001A\r
+#define CKK_SKIPJACK        0x0000001B\r
+#define CKK_BATON           0x0000001C\r
+#define CKK_JUNIPER         0x0000001D\r
+#define CKK_CDMF            0x0000001E\r
+#define CKK_AES             0x0000001F\r
+\r
+#define CKK_VENDOR_DEFINED  0x80000000\r
+\r
+\r
+/* CK_CERTIFICATE_TYPE is a value that identifies a certificate\r
+ * type */\r
+/* CK_CERTIFICATE_TYPE was changed from CK_USHORT to CK_ULONG\r
+ * for v2.0 */\r
+typedef CK_ULONG          CK_CERTIFICATE_TYPE;\r
+\r
+/* The following certificate types are defined: */\r
+/* CKC_X_509_ATTR_CERT is new for v2.10 */\r
+#define CKC_X_509           0x00000000\r
+#define CKC_X_509_ATTR_CERT 0x00000001\r
+#define CKC_VENDOR_DEFINED  0x80000000\r
+\r
+\r
+/* CK_ATTRIBUTE_TYPE is a value that identifies an attribute\r
+ * type */\r
+/* CK_ATTRIBUTE_TYPE was changed from CK_USHORT to CK_ULONG for\r
+ * v2.0 */\r
+typedef CK_ULONG          CK_ATTRIBUTE_TYPE;\r
+\r
+/* The following attribute types are defined: */\r
+#define CKA_CLASS              0x00000000\r
+#define CKA_TOKEN              0x00000001\r
+#define CKA_PRIVATE            0x00000002\r
+#define CKA_LABEL              0x00000003\r
+#define CKA_APPLICATION        0x00000010\r
+#define CKA_VALUE              0x00000011\r
+\r
+/* CKA_OBJECT_ID is new for v2.10 */\r
+#define CKA_OBJECT_ID          0x00000012\r
+\r
+#define CKA_CERTIFICATE_TYPE   0x00000080\r
+#define CKA_ISSUER             0x00000081\r
+#define CKA_SERIAL_NUMBER      0x00000082\r
+\r
+/* CKA_AC_ISSUER, CKA_OWNER, and CKA_ATTR_TYPES are new \r
+ * for v2.10 */\r
+#define CKA_AC_ISSUER          0x00000083\r
+#define CKA_OWNER              0x00000084\r
+#define CKA_ATTR_TYPES         0x00000085\r
+\r
+/* CKA_TRUSTED is new for v2.11 */\r
+#define CKA_TRUSTED            0x00000086\r
+\r
+#define CKA_KEY_TYPE           0x00000100\r
+#define CKA_SUBJECT            0x00000101\r
+#define CKA_ID                 0x00000102\r
+#define CKA_SENSITIVE          0x00000103\r
+#define CKA_ENCRYPT            0x00000104\r
+#define CKA_DECRYPT            0x00000105\r
+#define CKA_WRAP               0x00000106\r
+#define CKA_UNWRAP             0x00000107\r
+#define CKA_SIGN               0x00000108\r
+#define CKA_SIGN_RECOVER       0x00000109\r
+#define CKA_VERIFY             0x0000010A\r
+#define CKA_VERIFY_RECOVER     0x0000010B\r
+#define CKA_DERIVE             0x0000010C\r
+#define CKA_START_DATE         0x00000110\r
+#define CKA_END_DATE           0x00000111\r
+#define CKA_MODULUS            0x00000120\r
+#define CKA_MODULUS_BITS       0x00000121\r
+#define CKA_PUBLIC_EXPONENT    0x00000122\r
+#define CKA_PRIVATE_EXPONENT   0x00000123\r
+#define CKA_PRIME_1            0x00000124\r
+#define CKA_PRIME_2            0x00000125\r
+#define CKA_EXPONENT_1         0x00000126\r
+#define CKA_EXPONENT_2         0x00000127\r
+#define CKA_COEFFICIENT        0x00000128\r
+#define CKA_PRIME              0x00000130\r
+#define CKA_SUBPRIME           0x00000131\r
+#define CKA_BASE               0x00000132\r
+\r
+/* CKA_PRIME_BITS and CKA_SUB_PRIME_BITS are new for v2.11 */\r
+#define CKA_PRIME_BITS         0x00000133\r
+#define CKA_SUBPRIME_BITS      0x00000134 \r
+#define CKA_SUB_PRIME_BITS     CKA_SUBPRIME_BITS \r
+/* (To retain backwards-compatibility) */\r
+\r
+#define CKA_VALUE_BITS         0x00000160\r
+#define CKA_VALUE_LEN          0x00000161\r
+\r
+/* CKA_EXTRACTABLE, CKA_LOCAL, CKA_NEVER_EXTRACTABLE,\r
+ * CKA_ALWAYS_SENSITIVE, CKA_MODIFIABLE, CKA_ECDSA_PARAMS,\r
+ * and CKA_EC_POINT are new for v2.0 */\r
+#define CKA_EXTRACTABLE        0x00000162\r
+#define CKA_LOCAL              0x00000163\r
+#define CKA_NEVER_EXTRACTABLE  0x00000164\r
+#define CKA_ALWAYS_SENSITIVE   0x00000165\r
+\r
+/* CKA_KEY_GEN_MECHANISM is new for v2.11 */\r
+#define CKA_KEY_GEN_MECHANISM  0x00000166\r
+\r
+#define CKA_MODIFIABLE         0x00000170\r
+\r
+/* CKA_ECDSA_PARAMS is deprecated in v2.11,\r
+ * CKA_EC_PARAMS is preferred. */\r
+#define CKA_ECDSA_PARAMS       0x00000180\r
+#define CKA_EC_PARAMS          0x00000180\r
+\r
+#define CKA_EC_POINT           0x00000181\r
+\r
+/* CKA_SECONDARY_AUTH, CKA_AUTH_PIN_FLAGS, \r
+ * CKA_HW_FEATURE_TYPE, CKA_RESET_ON_INIT, and CKA_HAS_RESET\r
+ * are new for v2.10 */\r
+#define CKA_SECONDARY_AUTH     0x00000200\r
+#define CKA_AUTH_PIN_FLAGS     0x00000201\r
+#define CKA_HW_FEATURE_TYPE    0x00000300\r
+#define CKA_RESET_ON_INIT      0x00000301\r
+#define CKA_HAS_RESET          0x00000302\r
+\r
+#define CKA_VENDOR_DEFINED     0x80000000\r
+\r
+\r
+/* CK_ATTRIBUTE is a structure that includes the type, length\r
+ * and value of an attribute */\r
+typedef struct CK_ATTRIBUTE {\r
+  CK_ATTRIBUTE_TYPE type;\r
+  CK_VOID_PTR       pValue;\r
+\r
+  /* ulValueLen went from CK_USHORT to CK_ULONG for v2.0 */\r
+  CK_ULONG          ulValueLen;  /* in bytes */\r
+} CK_ATTRIBUTE;\r
+\r
+typedef CK_ATTRIBUTE CK_PTR CK_ATTRIBUTE_PTR;\r
+\r
+\r
+/* CK_DATE is a structure that defines a date */\r
+typedef struct CK_DATE{\r
+  CK_CHAR       year[4];   /* the year ("1900" - "9999") */\r
+  CK_CHAR       month[2];  /* the month ("01" - "12") */\r
+  CK_CHAR       day[2];    /* the day   ("01" - "31") */\r
+} CK_DATE;\r
+\r
+\r
+/* CK_MECHANISM_TYPE is a value that identifies a mechanism\r
+ * type */\r
+/* CK_MECHANISM_TYPE was changed from CK_USHORT to CK_ULONG for\r
+ * v2.0 */\r
+typedef CK_ULONG          CK_MECHANISM_TYPE;\r
+\r
+/* the following mechanism types are defined: */\r
+#define CKM_RSA_PKCS_KEY_PAIR_GEN      0x00000000\r
+#define CKM_RSA_PKCS                   0x00000001\r
+#define CKM_RSA_9796                   0x00000002\r
+#define CKM_RSA_X_509                  0x00000003\r
+\r
+/* CKM_MD2_RSA_PKCS, CKM_MD5_RSA_PKCS, and CKM_SHA1_RSA_PKCS\r
+ * are new for v2.0.  They are mechanisms which hash and sign */\r
+#define CKM_MD2_RSA_PKCS               0x00000004\r
+#define CKM_MD5_RSA_PKCS               0x00000005\r
+#define CKM_SHA1_RSA_PKCS              0x00000006\r
+\r
+/* CKM_RIPEMD128_RSA_PKCS, CKM_RIPEMD160_RSA_PKCS, and\r
+ * CKM_RSA_PKCS_OAEP are new for v2.10 */\r
+#define CKM_RIPEMD128_RSA_PKCS         0x00000007\r
+#define CKM_RIPEMD160_RSA_PKCS         0x00000008\r
+#define CKM_RSA_PKCS_OAEP              0x00000009\r
+\r
+/* CKM_RSA_X9_31_KEY_PAIR_GEN, CKM_RSA_X9_31, CKM_SHA1_RSA_X9_31,\r
+ * CKM_RSA_PKCS_PSS, and CKM_SHA1_RSA_PKCS_PSS are new for v2.11 */\r
+#define CKM_RSA_X9_31_KEY_PAIR_GEN     0x0000000A\r
+#define CKM_RSA_X9_31                  0x0000000B\r
+#define CKM_SHA1_RSA_X9_31             0x0000000C\r
+#define CKM_RSA_PKCS_PSS               0x0000000D\r
+#define CKM_SHA1_RSA_PKCS_PSS          0x0000000E\r
+\r
+#define CKM_DSA_KEY_PAIR_GEN           0x00000010\r
+#define CKM_DSA                        0x00000011\r
+#define CKM_DSA_SHA1                   0x00000012\r
+#define CKM_DH_PKCS_KEY_PAIR_GEN       0x00000020\r
+#define CKM_DH_PKCS_DERIVE             0x00000021\r
+\r
+/* CKM_X9_42_DH_KEY_PAIR_GEN, CKM_X9_42_DH_DERIVE,\r
+ * CKM_X9_42_DH_HYBRID_DERIVE, and CKM_X9_42_MQV_DERIVE are new for\r
+ * v2.11 */\r
+#define CKM_X9_42_DH_KEY_PAIR_GEN      0x00000030\r
+#define CKM_X9_42_DH_DERIVE            0x00000031\r
+#define CKM_X9_42_DH_HYBRID_DERIVE     0x00000032\r
+#define CKM_X9_42_MQV_DERIVE           0x00000033\r
+\r
+#define CKM_RC2_KEY_GEN                0x00000100\r
+#define CKM_RC2_ECB                    0x00000101\r
+#define CKM_RC2_CBC                    0x00000102\r
+#define CKM_RC2_MAC                    0x00000103\r
+\r
+/* CKM_RC2_MAC_GENERAL and CKM_RC2_CBC_PAD are new for v2.0 */\r
+#define CKM_RC2_MAC_GENERAL            0x00000104\r
+#define CKM_RC2_CBC_PAD                0x00000105\r
+\r
+#define CKM_RC4_KEY_GEN                0x00000110\r
+#define CKM_RC4                        0x00000111\r
+#define CKM_DES_KEY_GEN                0x00000120\r
+#define CKM_DES_ECB                    0x00000121\r
+#define CKM_DES_CBC                    0x00000122\r
+#define CKM_DES_MAC                    0x00000123\r
+\r
+/* CKM_DES_MAC_GENERAL and CKM_DES_CBC_PAD are new for v2.0 */\r
+#define CKM_DES_MAC_GENERAL            0x00000124\r
+#define CKM_DES_CBC_PAD                0x00000125\r
+\r
+#define CKM_DES2_KEY_GEN               0x00000130\r
+#define CKM_DES3_KEY_GEN               0x00000131\r
+#define CKM_DES3_ECB                   0x00000132\r
+#define CKM_DES3_CBC                   0x00000133\r
+#define CKM_DES3_MAC                   0x00000134\r
+\r
+/* CKM_DES3_MAC_GENERAL, CKM_DES3_CBC_PAD, CKM_CDMF_KEY_GEN,\r
+ * CKM_CDMF_ECB, CKM_CDMF_CBC, CKM_CDMF_MAC,\r
+ * CKM_CDMF_MAC_GENERAL, and CKM_CDMF_CBC_PAD are new for v2.0 */\r
+#define CKM_DES3_MAC_GENERAL           0x00000135\r
+#define CKM_DES3_CBC_PAD               0x00000136\r
+#define CKM_CDMF_KEY_GEN               0x00000140\r
+#define CKM_CDMF_ECB                   0x00000141\r
+#define CKM_CDMF_CBC                   0x00000142\r
+#define CKM_CDMF_MAC                   0x00000143\r
+#define CKM_CDMF_MAC_GENERAL           0x00000144\r
+#define CKM_CDMF_CBC_PAD               0x00000145\r
+\r
+#define CKM_MD2                        0x00000200\r
+\r
+/* CKM_MD2_HMAC and CKM_MD2_HMAC_GENERAL are new for v2.0 */\r
+#define CKM_MD2_HMAC                   0x00000201\r
+#define CKM_MD2_HMAC_GENERAL           0x00000202\r
+\r
+#define CKM_MD5                        0x00000210\r
+\r
+/* CKM_MD5_HMAC and CKM_MD5_HMAC_GENERAL are new for v2.0 */\r
+#define CKM_MD5_HMAC                   0x00000211\r
+#define CKM_MD5_HMAC_GENERAL           0x00000212\r
+\r
+#define CKM_SHA_1                      0x00000220\r
+\r
+/* CKM_SHA_1_HMAC and CKM_SHA_1_HMAC_GENERAL are new for v2.0 */\r
+#define CKM_SHA_1_HMAC                 0x00000221\r
+#define CKM_SHA_1_HMAC_GENERAL         0x00000222\r
+\r
+/* CKM_RIPEMD128, CKM_RIPEMD128_HMAC, \r
+ * CKM_RIPEMD128_HMAC_GENERAL, CKM_RIPEMD160, CKM_RIPEMD160_HMAC,\r
+ * and CKM_RIPEMD160_HMAC_GENERAL are new for v2.10 */\r
+#define CKM_RIPEMD128                  0x00000230\r
+#define CKM_RIPEMD128_HMAC             0x00000231\r
+#define CKM_RIPEMD128_HMAC_GENERAL     0x00000232\r
+#define CKM_RIPEMD160                  0x00000240\r
+#define CKM_RIPEMD160_HMAC             0x00000241\r
+#define CKM_RIPEMD160_HMAC_GENERAL     0x00000242\r
+\r
+/* All of the following mechanisms are new for v2.0 */\r
+/* Note that CAST128 and CAST5 are the same algorithm */\r
+#define CKM_CAST_KEY_GEN               0x00000300\r
+#define CKM_CAST_ECB                   0x00000301\r
+#define CKM_CAST_CBC                   0x00000302\r
+#define CKM_CAST_MAC                   0x00000303\r
+#define CKM_CAST_MAC_GENERAL           0x00000304\r
+#define CKM_CAST_CBC_PAD               0x00000305\r
+#define CKM_CAST3_KEY_GEN              0x00000310\r
+#define CKM_CAST3_ECB                  0x00000311\r
+#define CKM_CAST3_CBC                  0x00000312\r
+#define CKM_CAST3_MAC                  0x00000313\r
+#define CKM_CAST3_MAC_GENERAL          0x00000314\r
+#define CKM_CAST3_CBC_PAD              0x00000315\r
+#define CKM_CAST5_KEY_GEN              0x00000320\r
+#define CKM_CAST128_KEY_GEN            0x00000320\r
+#define CKM_CAST5_ECB                  0x00000321\r
+#define CKM_CAST128_ECB                0x00000321\r
+#define CKM_CAST5_CBC                  0x00000322\r
+#define CKM_CAST128_CBC                0x00000322\r
+#define CKM_CAST5_MAC                  0x00000323\r
+#define CKM_CAST128_MAC                0x00000323\r
+#define CKM_CAST5_MAC_GENERAL          0x00000324\r
+#define CKM_CAST128_MAC_GENERAL        0x00000324\r
+#define CKM_CAST5_CBC_PAD              0x00000325\r
+#define CKM_CAST128_CBC_PAD            0x00000325\r
+#define CKM_RC5_KEY_GEN                0x00000330\r
+#define CKM_RC5_ECB                    0x00000331\r
+#define CKM_RC5_CBC                    0x00000332\r
+#define CKM_RC5_MAC                    0x00000333\r
+#define CKM_RC5_MAC_GENERAL            0x00000334\r
+#define CKM_RC5_CBC_PAD                0x00000335\r
+#define CKM_IDEA_KEY_GEN               0x00000340\r
+#define CKM_IDEA_ECB                   0x00000341\r
+#define CKM_IDEA_CBC                   0x00000342\r
+#define CKM_IDEA_MAC                   0x00000343\r
+#define CKM_IDEA_MAC_GENERAL           0x00000344\r
+#define CKM_IDEA_CBC_PAD               0x00000345\r
+#define CKM_GENERIC_SECRET_KEY_GEN     0x00000350\r
+#define CKM_CONCATENATE_BASE_AND_KEY   0x00000360\r
+#define CKM_CONCATENATE_BASE_AND_DATA  0x00000362\r
+#define CKM_CONCATENATE_DATA_AND_BASE  0x00000363\r
+#define CKM_XOR_BASE_AND_DATA          0x00000364\r
+#define CKM_EXTRACT_KEY_FROM_KEY       0x00000365\r
+#define CKM_SSL3_PRE_MASTER_KEY_GEN    0x00000370\r
+#define CKM_SSL3_MASTER_KEY_DERIVE     0x00000371\r
+#define CKM_SSL3_KEY_AND_MAC_DERIVE    0x00000372\r
+\r
+/* CKM_SSL3_MASTER_KEY_DERIVE_DH, CKM_TLS_PRE_MASTER_KEY_GEN,\r
+ * CKM_TLS_MASTER_KEY_DERIVE, CKM_TLS_KEY_AND_MAC_DERIVE, and\r
+ * CKM_TLS_MASTER_KEY_DERIVE_DH are new for v2.11 */\r
+#define CKM_SSL3_MASTER_KEY_DERIVE_DH  0x00000373\r
+#define CKM_TLS_PRE_MASTER_KEY_GEN     0x00000374\r
+#define CKM_TLS_MASTER_KEY_DERIVE      0x00000375\r
+#define CKM_TLS_KEY_AND_MAC_DERIVE     0x00000376\r
+#define CKM_TLS_MASTER_KEY_DERIVE_DH   0x00000377\r
+\r
+#define CKM_SSL3_MD5_MAC               0x00000380\r
+#define CKM_SSL3_SHA1_MAC              0x00000381\r
+#define CKM_MD5_KEY_DERIVATION         0x00000390\r
+#define CKM_MD2_KEY_DERIVATION         0x00000391\r
+#define CKM_SHA1_KEY_DERIVATION        0x00000392\r
+#define CKM_PBE_MD2_DES_CBC            0x000003A0\r
+#define CKM_PBE_MD5_DES_CBC            0x000003A1\r
+#define CKM_PBE_MD5_CAST_CBC           0x000003A2\r
+#define CKM_PBE_MD5_CAST3_CBC          0x000003A3\r
+#define CKM_PBE_MD5_CAST5_CBC          0x000003A4\r
+#define CKM_PBE_MD5_CAST128_CBC        0x000003A4\r
+#define CKM_PBE_SHA1_CAST5_CBC         0x000003A5\r
+#define CKM_PBE_SHA1_CAST128_CBC       0x000003A5\r
+#define CKM_PBE_SHA1_RC4_128           0x000003A6\r
+#define CKM_PBE_SHA1_RC4_40            0x000003A7\r
+#define CKM_PBE_SHA1_DES3_EDE_CBC      0x000003A8\r
+#define CKM_PBE_SHA1_DES2_EDE_CBC      0x000003A9\r
+#define CKM_PBE_SHA1_RC2_128_CBC       0x000003AA\r
+#define CKM_PBE_SHA1_RC2_40_CBC        0x000003AB\r
+\r
+/* CKM_PKCS5_PBKD2 is new for v2.10 */\r
+#define CKM_PKCS5_PBKD2                0x000003B0\r
+\r
+#define CKM_PBA_SHA1_WITH_SHA1_HMAC    0x000003C0\r
+#define CKM_KEY_WRAP_LYNKS             0x00000400\r
+#define CKM_KEY_WRAP_SET_OAEP          0x00000401\r
+\r
+/* Fortezza mechanisms */\r
+#define CKM_SKIPJACK_KEY_GEN           0x00001000\r
+#define CKM_SKIPJACK_ECB64             0x00001001\r
+#define CKM_SKIPJACK_CBC64             0x00001002\r
+#define CKM_SKIPJACK_OFB64             0x00001003\r
+#define CKM_SKIPJACK_CFB64             0x00001004\r
+#define CKM_SKIPJACK_CFB32             0x00001005\r
+#define CKM_SKIPJACK_CFB16             0x00001006\r
+#define CKM_SKIPJACK_CFB8              0x00001007\r
+#define CKM_SKIPJACK_WRAP              0x00001008\r
+#define CKM_SKIPJACK_PRIVATE_WRAP      0x00001009\r
+#define CKM_SKIPJACK_RELAYX            0x0000100a\r
+#define CKM_KEA_KEY_PAIR_GEN           0x00001010\r
+#define CKM_KEA_KEY_DERIVE             0x00001011\r
+#define CKM_FORTEZZA_TIMESTAMP         0x00001020\r
+#define CKM_BATON_KEY_GEN              0x00001030\r
+#define CKM_BATON_ECB128               0x00001031\r
+#define CKM_BATON_ECB96                0x00001032\r
+#define CKM_BATON_CBC128               0x00001033\r
+#define CKM_BATON_COUNTER              0x00001034\r
+#define CKM_BATON_SHUFFLE              0x00001035\r
+#define CKM_BATON_WRAP                 0x00001036\r
+\r
+/* CKM_ECDSA_KEY_PAIR_GEN is deprecated in v2.11,\r
+ * CKM_EC_KEY_PAIR_GEN is preferred */\r
+#define CKM_ECDSA_KEY_PAIR_GEN         0x00001040\r
+#define CKM_EC_KEY_PAIR_GEN            0x00001040\r
+\r
+#define CKM_ECDSA                      0x00001041\r
+#define CKM_ECDSA_SHA1                 0x00001042\r
+\r
+/* CKM_ECDH1_DERIVE, CKM_ECDH1_COFACTOR_DERIVE, and CKM_ECMQV_DERIVE\r
+ * are new for v2.11 */\r
+#define CKM_ECDH1_DERIVE               0x00001050\r
+#define CKM_ECDH1_COFACTOR_DERIVE      0x00001051\r
+#define CKM_ECMQV_DERIVE               0x00001052\r
+\r
+#define CKM_JUNIPER_KEY_GEN            0x00001060\r
+#define CKM_JUNIPER_ECB128             0x00001061\r
+#define CKM_JUNIPER_CBC128             0x00001062\r
+#define CKM_JUNIPER_COUNTER            0x00001063\r
+#define CKM_JUNIPER_SHUFFLE            0x00001064\r
+#define CKM_JUNIPER_WRAP               0x00001065\r
+#define CKM_FASTHASH                   0x00001070\r
+\r
+/* CKM_AES_KEY_GEN, CKM_AES_ECB, CKM_AES_CBC, CKM_AES_MAC,\r
+ * CKM_AES_MAC_GENERAL, CKM_AES_CBC_PAD, CKM_DSA_PARAMETER_GEN,\r
+ * CKM_DH_PKCS_PARAMETER_GEN, and CKM_X9_42_DH_PARAMETER_GEN are\r
+ * new for v2.11 */\r
+#define CKM_AES_KEY_GEN                0x00001080\r
+#define CKM_AES_ECB                    0x00001081\r
+#define CKM_AES_CBC                    0x00001082\r
+#define CKM_AES_MAC                    0x00001083\r
+#define CKM_AES_MAC_GENERAL            0x00001084\r
+#define CKM_AES_CBC_PAD                0x00001085\r
+#define CKM_DSA_PARAMETER_GEN          0x00002000\r
+#define CKM_DH_PKCS_PARAMETER_GEN      0x00002001\r
+#define CKM_X9_42_DH_PARAMETER_GEN     0x00002002\r
+\r
+#define CKM_VENDOR_DEFINED             0x80000000\r
+\r
+typedef CK_MECHANISM_TYPE CK_PTR CK_MECHANISM_TYPE_PTR;\r
+\r
+\r
+/* CK_MECHANISM is a structure that specifies a particular\r
+ * mechanism  */\r
+typedef struct CK_MECHANISM {\r
+  CK_MECHANISM_TYPE mechanism;\r
+  CK_VOID_PTR       pParameter;\r
+\r
+  /* ulParameterLen was changed from CK_USHORT to CK_ULONG for\r
+   * v2.0 */\r
+  CK_ULONG          ulParameterLen;  /* in bytes */\r
+} CK_MECHANISM;\r
+\r
+typedef CK_MECHANISM CK_PTR CK_MECHANISM_PTR;\r
+\r
+\r
+/* CK_MECHANISM_INFO provides information about a particular\r
+ * mechanism */\r
+typedef struct CK_MECHANISM_INFO {\r
+    CK_ULONG    ulMinKeySize;\r
+    CK_ULONG    ulMaxKeySize;\r
+    CK_FLAGS    flags;\r
+} CK_MECHANISM_INFO;\r
+\r
+/* The flags are defined as follows:\r
+ *      Bit Flag               Mask        Meaning */\r
+#define CKF_HW                 0x00000001  /* performed by HW */\r
+\r
+/* The flags CKF_ENCRYPT, CKF_DECRYPT, CKF_DIGEST, CKF_SIGN,\r
+ * CKG_SIGN_RECOVER, CKF_VERIFY, CKF_VERIFY_RECOVER,\r
+ * CKF_GENERATE, CKF_GENERATE_KEY_PAIR, CKF_WRAP, CKF_UNWRAP,\r
+ * and CKF_DERIVE are new for v2.0.  They specify whether or not\r
+ * a mechanism can be used for a particular task */\r
+#define CKF_ENCRYPT            0x00000100\r
+#define CKF_DECRYPT            0x00000200\r
+#define CKF_DIGEST             0x00000400\r
+#define CKF_SIGN               0x00000800\r
+#define CKF_SIGN_RECOVER       0x00001000\r
+#define CKF_VERIFY             0x00002000\r
+#define CKF_VERIFY_RECOVER     0x00004000\r
+#define CKF_GENERATE           0x00008000\r
+#define CKF_GENERATE_KEY_PAIR  0x00010000\r
+#define CKF_WRAP               0x00020000\r
+#define CKF_UNWRAP             0x00040000\r
+#define CKF_DERIVE             0x00080000\r
+\r
+/* CKF_EC_F_P, CKF_EC_F_2M, CKF_EC_ECPARAMETERS, CKF_EC_NAMEDCURVE,\r
+ * CKF_EC_UNCOMPRESS, and CKF_EC_COMPRESS are new for v2.11. They\r
+ * describe a token's EC capabilities not available in mechanism\r
+ * information. */\r
+#define CKF_EC_F_P                0x00100000\r
+#define CKF_EC_F_2M               0x00200000\r
+#define CKF_EC_ECPARAMETERS       0x00400000\r
+#define CKF_EC_NAMEDCURVE         0x00800000\r
+#define CKF_EC_UNCOMPRESS         0x01000000\r
+#define CKF_EC_COMPRESS               0x02000000\r
+\r
+#define CKF_EXTENSION          0x80000000  /* FALSE for 2.01 */\r
+\r
+typedef CK_MECHANISM_INFO CK_PTR CK_MECHANISM_INFO_PTR;\r
+\r
+\r
+/* CK_RV is a value that identifies the return value of a\r
+ * Cryptoki function */\r
+/* CK_RV was changed from CK_USHORT to CK_ULONG for v2.0 */\r
+typedef CK_ULONG          CK_RV;\r
+\r
+#define CKR_OK                                0x00000000\r
+#define CKR_CANCEL                            0x00000001\r
+#define CKR_HOST_MEMORY                       0x00000002\r
+#define CKR_SLOT_ID_INVALID                   0x00000003\r
+\r
+/* CKR_FLAGS_INVALID was removed for v2.0 */\r
+\r
+/* CKR_GENERAL_ERROR and CKR_FUNCTION_FAILED are new for v2.0 */\r
+#define CKR_GENERAL_ERROR                     0x00000005\r
+#define CKR_FUNCTION_FAILED                   0x00000006\r
+\r
+/* CKR_ARGUMENTS_BAD, CKR_NO_EVENT, CKR_NEED_TO_CREATE_THREADS,\r
+ * and CKR_CANT_LOCK are new for v2.01 */\r
+#define CKR_ARGUMENTS_BAD                     0x00000007\r
+#define CKR_NO_EVENT                          0x00000008\r
+#define CKR_NEED_TO_CREATE_THREADS            0x00000009\r
+#define CKR_CANT_LOCK                         0x0000000A\r
+\r
+#define CKR_ATTRIBUTE_READ_ONLY               0x00000010\r
+#define CKR_ATTRIBUTE_SENSITIVE               0x00000011\r
+#define CKR_ATTRIBUTE_TYPE_INVALID            0x00000012\r
+#define CKR_ATTRIBUTE_VALUE_INVALID           0x00000013\r
+#define CKR_DATA_INVALID                      0x00000020\r
+#define CKR_DATA_LEN_RANGE                    0x00000021\r
+#define CKR_DEVICE_ERROR                      0x00000030\r
+#define CKR_DEVICE_MEMORY                     0x00000031\r
+#define CKR_DEVICE_REMOVED                    0x00000032\r
+#define CKR_ENCRYPTED_DATA_INVALID            0x00000040\r
+#define CKR_ENCRYPTED_DATA_LEN_RANGE          0x00000041\r
+#define CKR_FUNCTION_CANCELED                 0x00000050\r
+#define CKR_FUNCTION_NOT_PARALLEL             0x00000051\r
+\r
+/* CKR_FUNCTION_NOT_SUPPORTED is new for v2.0 */\r
+#define CKR_FUNCTION_NOT_SUPPORTED            0x00000054\r
+\r
+#define CKR_KEY_HANDLE_INVALID                0x00000060\r
+\r
+/* CKR_KEY_SENSITIVE was removed for v2.0 */\r
+\r
+#define CKR_KEY_SIZE_RANGE                    0x00000062\r
+#define CKR_KEY_TYPE_INCONSISTENT             0x00000063\r
+\r
+/* CKR_KEY_NOT_NEEDED, CKR_KEY_CHANGED, CKR_KEY_NEEDED,\r
+ * CKR_KEY_INDIGESTIBLE, CKR_KEY_FUNCTION_NOT_PERMITTED,\r
+ * CKR_KEY_NOT_WRAPPABLE, and CKR_KEY_UNEXTRACTABLE are new for\r
+ * v2.0 */\r
+#define CKR_KEY_NOT_NEEDED                    0x00000064\r
+#define CKR_KEY_CHANGED                       0x00000065\r
+#define CKR_KEY_NEEDED                        0x00000066\r
+#define CKR_KEY_INDIGESTIBLE                  0x00000067\r
+#define CKR_KEY_FUNCTION_NOT_PERMITTED        0x00000068\r
+#define CKR_KEY_NOT_WRAPPABLE                 0x00000069\r
+#define CKR_KEY_UNEXTRACTABLE                 0x0000006A\r
+\r
+#define CKR_MECHANISM_INVALID                 0x00000070\r
+#define CKR_MECHANISM_PARAM_INVALID           0x00000071\r
+\r
+/* CKR_OBJECT_CLASS_INCONSISTENT and CKR_OBJECT_CLASS_INVALID\r
+ * were removed for v2.0 */\r
+#define CKR_OBJECT_HANDLE_INVALID             0x00000082\r
+#define CKR_OPERATION_ACTIVE                  0x00000090\r
+#define CKR_OPERATION_NOT_INITIALIZED         0x00000091\r
+#define CKR_PIN_INCORRECT                     0x000000A0\r
+#define CKR_PIN_INVALID                       0x000000A1\r
+#define CKR_PIN_LEN_RANGE                     0x000000A2\r
+\r
+/* CKR_PIN_EXPIRED and CKR_PIN_LOCKED are new for v2.0 */\r
+#define CKR_PIN_EXPIRED                       0x000000A3\r
+#define CKR_PIN_LOCKED                        0x000000A4\r
+\r
+#define CKR_SESSION_CLOSED                    0x000000B0\r
+#define CKR_SESSION_COUNT                     0x000000B1\r
+#define CKR_SESSION_HANDLE_INVALID            0x000000B3\r
+#define CKR_SESSION_PARALLEL_NOT_SUPPORTED    0x000000B4\r
+#define CKR_SESSION_READ_ONLY                 0x000000B5\r
+#define CKR_SESSION_EXISTS                    0x000000B6\r
+\r
+/* CKR_SESSION_READ_ONLY_EXISTS and\r
+ * CKR_SESSION_READ_WRITE_SO_EXISTS are new for v2.0 */\r
+#define CKR_SESSION_READ_ONLY_EXISTS          0x000000B7\r
+#define CKR_SESSION_READ_WRITE_SO_EXISTS      0x000000B8\r
+\r
+#define CKR_SIGNATURE_INVALID                 0x000000C0\r
+#define CKR_SIGNATURE_LEN_RANGE               0x000000C1\r
+#define CKR_TEMPLATE_INCOMPLETE               0x000000D0\r
+#define CKR_TEMPLATE_INCONSISTENT             0x000000D1\r
+#define CKR_TOKEN_NOT_PRESENT                 0x000000E0\r
+#define CKR_TOKEN_NOT_RECOGNIZED              0x000000E1\r
+#define CKR_TOKEN_WRITE_PROTECTED             0x000000E2\r
+#define CKR_UNWRAPPING_KEY_HANDLE_INVALID     0x000000F0\r
+#define CKR_UNWRAPPING_KEY_SIZE_RANGE         0x000000F1\r
+#define CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT  0x000000F2\r
+#define CKR_USER_ALREADY_LOGGED_IN            0x00000100\r
+#define CKR_USER_NOT_LOGGED_IN                0x00000101\r
+#define CKR_USER_PIN_NOT_INITIALIZED          0x00000102\r
+#define CKR_USER_TYPE_INVALID                 0x00000103\r
+\r
+/* CKR_USER_ANOTHER_ALREADY_LOGGED_IN and CKR_USER_TOO_MANY_TYPES\r
+ * are new to v2.01 */\r
+#define CKR_USER_ANOTHER_ALREADY_LOGGED_IN    0x00000104\r
+#define CKR_USER_TOO_MANY_TYPES               0x00000105\r
+\r
+#define CKR_WRAPPED_KEY_INVALID               0x00000110\r
+#define CKR_WRAPPED_KEY_LEN_RANGE             0x00000112\r
+#define CKR_WRAPPING_KEY_HANDLE_INVALID       0x00000113\r
+#define CKR_WRAPPING_KEY_SIZE_RANGE           0x00000114\r
+#define CKR_WRAPPING_KEY_TYPE_INCONSISTENT    0x00000115\r
+#define CKR_RANDOM_SEED_NOT_SUPPORTED         0x00000120\r
+\r
+/* These are new to v2.0 */\r
+#define CKR_RANDOM_NO_RNG                     0x00000121\r
+\r
+/* These are new to v2.11 */\r
+#define CKR_DOMAIN_PARAMS_INVALID             0x00000130\r
+\r
+/* These are new to v2.0 */\r
+#define CKR_BUFFER_TOO_SMALL                  0x00000150\r
+#define CKR_SAVED_STATE_INVALID               0x00000160\r
+#define CKR_INFORMATION_SENSITIVE             0x00000170\r
+#define CKR_STATE_UNSAVEABLE                  0x00000180\r
+\r
+/* These are new to v2.01 */\r
+#define CKR_CRYPTOKI_NOT_INITIALIZED          0x00000190\r
+#define CKR_CRYPTOKI_ALREADY_INITIALIZED      0x00000191\r
+#define CKR_MUTEX_BAD                         0x000001A0\r
+#define CKR_MUTEX_NOT_LOCKED                  0x000001A1\r
+\r
+#define CKR_VENDOR_DEFINED                    0x80000000\r
+\r
+\r
+/* CK_NOTIFY is an application callback that processes events */\r
+typedef CK_CALLBACK_FUNCTION(CK_RV, CK_NOTIFY)(\r
+  CK_SESSION_HANDLE hSession,     /* the session's handle */\r
+  CK_NOTIFICATION   event,\r
+  CK_VOID_PTR       pApplication  /* passed to C_OpenSession */\r
+);\r
+\r
+\r
+/* CK_FUNCTION_LIST is a structure holding a Cryptoki spec\r
+ * version and pointers of appropriate types to all the\r
+ * Cryptoki functions */\r
+/* CK_FUNCTION_LIST is new for v2.0 */\r
+typedef struct CK_FUNCTION_LIST CK_FUNCTION_LIST;\r
+\r
+typedef CK_FUNCTION_LIST CK_PTR CK_FUNCTION_LIST_PTR;\r
+\r
+typedef CK_FUNCTION_LIST_PTR CK_PTR CK_FUNCTION_LIST_PTR_PTR;\r
+\r
+\r
+/* CK_CREATEMUTEX is an application callback for creating a\r
+ * mutex object */\r
+typedef CK_CALLBACK_FUNCTION(CK_RV, CK_CREATEMUTEX)(\r
+  CK_VOID_PTR_PTR ppMutex  /* location to receive ptr to mutex */\r
+);\r
+\r
+\r
+/* CK_DESTROYMUTEX is an application callback for destroying a\r
+ * mutex object */\r
+typedef CK_CALLBACK_FUNCTION(CK_RV, CK_DESTROYMUTEX)(\r
+  CK_VOID_PTR pMutex  /* pointer to mutex */\r
+);\r
+\r
+\r
+/* CK_LOCKMUTEX is an application callback for locking a mutex */\r
+typedef CK_CALLBACK_FUNCTION(CK_RV, CK_LOCKMUTEX)(\r
+  CK_VOID_PTR pMutex  /* pointer to mutex */\r
+);\r
+\r
+\r
+/* CK_UNLOCKMUTEX is an application callback for unlocking a\r
+ * mutex */\r
+typedef CK_CALLBACK_FUNCTION(CK_RV, CK_UNLOCKMUTEX)(\r
+  CK_VOID_PTR pMutex  /* pointer to mutex */\r
+);\r
+\r
+\r
+/* CK_C_INITIALIZE_ARGS provides the optional arguments to\r
+ * C_Initialize */\r
+typedef struct CK_C_INITIALIZE_ARGS {\r
+  CK_CREATEMUTEX CreateMutex;\r
+  CK_DESTROYMUTEX DestroyMutex;\r
+  CK_LOCKMUTEX LockMutex;\r
+  CK_UNLOCKMUTEX UnlockMutex;\r
+  CK_FLAGS flags;\r
+  CK_VOID_PTR pReserved;\r
+} CK_C_INITIALIZE_ARGS;\r
+\r
+/* flags: bit flags that provide capabilities of the slot\r
+ *      Bit Flag                           Mask       Meaning\r
+ */\r
+#define CKF_LIBRARY_CANT_CREATE_OS_THREADS 0x00000001\r
+#define CKF_OS_LOCKING_OK                  0x00000002\r
+\r
+typedef CK_C_INITIALIZE_ARGS CK_PTR CK_C_INITIALIZE_ARGS_PTR;\r
+\r
+\r
+/* additional flags for parameters to functions */\r
+\r
+/* CKF_DONT_BLOCK is for the function C_WaitForSlotEvent */\r
+#define CKF_DONT_BLOCK     1\r
+\r
+/* CK_RSA_PKCS_OAEP_MGF_TYPE is new for v2.10. \r
+ * CK_RSA_PKCS_OAEP_MGF_TYPE  is used to indicate the Message \r
+ * Generation Function (MGF) applied to a message block when \r
+ * formatting a message block for the PKCS #1 OAEP encryption \r
+ * scheme. */\r
+typedef CK_ULONG CK_RSA_PKCS_MGF_TYPE;\r
+\r
+typedef CK_RSA_PKCS_MGF_TYPE CK_PTR CK_RSA_PKCS_MGF_TYPE_PTR;\r
+\r
+/* The following MGFs are defined */\r
+#define CKG_MGF1_SHA1         0x00000001\r
+\r
+/* CK_RSA_PKCS_OAEP_SOURCE_TYPE is new for v2.10. \r
+ * CK_RSA_PKCS_OAEP_SOURCE_TYPE  is used to indicate the source\r
+ * of the encoding parameter when formatting a message block \r
+ * for the PKCS #1 OAEP encryption scheme. */\r
+typedef CK_ULONG CK_RSA_PKCS_OAEP_SOURCE_TYPE;\r
+\r
+typedef CK_RSA_PKCS_OAEP_SOURCE_TYPE CK_PTR CK_RSA_PKCS_OAEP_SOURCE_TYPE_PTR;\r
+\r
+/* The following encoding parameter sources are defined */\r
+#define CKZ_DATA_SPECIFIED    0x00000001\r
+\r
+/* CK_RSA_PKCS_OAEP_PARAMS is new for v2.10.\r
+ * CK_RSA_PKCS_OAEP_PARAMS provides the parameters to the \r
+ * CKM_RSA_PKCS_OAEP mechanism. */\r
+typedef struct CK_RSA_PKCS_OAEP_PARAMS {\r
+       CK_MECHANISM_TYPE hashAlg;\r
+       CK_RSA_PKCS_MGF_TYPE mgf;\r
+       CK_RSA_PKCS_OAEP_SOURCE_TYPE source;\r
+       CK_VOID_PTR pSourceData;\r
+       CK_ULONG ulSourceDataLen;\r
+} CK_RSA_PKCS_OAEP_PARAMS;\r
+\r
+typedef CK_RSA_PKCS_OAEP_PARAMS CK_PTR CK_RSA_PKCS_OAEP_PARAMS_PTR;\r
+\r
+/* CK_RSA_PKCS_PSS_PARAMS is new for v2.11.\r
+ * CK_RSA_PKCS_PSS_PARAMS provides the parameters to the\r
+ * CKM_RSA_PKCS_PSS mechanism(s). */\r
+typedef struct CK_RSA_PKCS_PSS_PARAMS {\r
+       CK_MECHANISM_TYPE    hashAlg;\r
+       CK_RSA_PKCS_MGF_TYPE mgf;\r
+       CK_ULONG             sLen;\r
+} CK_RSA_PKCS_PSS_PARAMS;\r
+\r
+typedef CK_RSA_PKCS_PSS_PARAMS CK_PTR CK_RSA_PKCS_PSS_PARAMS_PTR;\r
+\r
+/* CK_EC_KDF_TYPE is new for v2.11. */\r
+typedef CK_ULONG CK_EC_KDF_TYPE;\r
+\r
+/* The following EC Key Derivation Functions are defined */\r
+#define CKD_NULL                 0x00000001\r
+#define CKD_SHA1_KDF             0x00000002\r
+\r
+/* CK_ECDH1_DERIVE_PARAMS is new for v2.11.\r
+ * CK_ECDH1_DERIVE_PARAMS provides the parameters to the\r
+ * CKM_ECDH1_DERIVE and CKM_ECDH1_COFACTOR_DERIVE mechanisms,\r
+ * where each party contributes one key pair.\r
+ */\r
+typedef struct CK_ECDH1_DERIVE_PARAMS {\r
+  CK_EC_KDF_TYPE kdf;\r
+  CK_ULONG ulSharedDataLen;\r
+  CK_BYTE_PTR pSharedData;\r
+  CK_ULONG ulPublicDataLen;\r
+  CK_BYTE_PTR pPublicData;\r
+} CK_ECDH1_DERIVE_PARAMS;\r
+\r
+typedef CK_ECDH1_DERIVE_PARAMS CK_PTR CK_ECDH1_DERIVE_PARAMS_PTR;\r
+\r
+\r
+/* CK_ECDH2_DERIVE_PARAMS is new for v2.11.\r
+ * CK_ECDH2_DERIVE_PARAMS provides the parameters to the\r
+ * CKM_ECMQV_DERIVE mechanism, where each party contributes two key pairs. */\r
+typedef struct CK_ECDH2_DERIVE_PARAMS {\r
+  CK_EC_KDF_TYPE kdf;\r
+  CK_ULONG ulSharedDataLen;\r
+  CK_BYTE_PTR pSharedData;\r
+  CK_ULONG ulPublicDataLen;\r
+  CK_BYTE_PTR pPublicData;\r
+  CK_ULONG ulPrivateDataLen;\r
+  CK_OBJECT_HANDLE hPrivateData;\r
+  CK_ULONG ulPublicDataLen2;\r
+  CK_BYTE_PTR pPublicData2;\r
+} CK_ECDH2_DERIVE_PARAMS;\r
+\r
+typedef CK_ECDH2_DERIVE_PARAMS CK_PTR CK_ECDH2_DERIVE_PARAMS_PTR;\r
+\r
+/* Typedefs and defines for the CKM_X9_42_DH_KEY_PAIR_GEN and the \r
+ * CKM_X9_42_DH_PARAMETER_GEN mechanisms (new for PKCS #11 v2.11) */\r
+typedef CK_ULONG CK_X9_42_DH_KDF_TYPE;\r
+typedef CK_X9_42_DH_KDF_TYPE CK_PTR CK_X9_42_DH_KDF_TYPE_PTR;\r
+\r
+/* The following X9.42 DH key derivation functions are defined: */\r
+#define CKD_NULL                 0x00000001\r
+#define CKD_SHA1_KDF_ASN1        0x00000003\r
+#define CKD_SHA1_KDF_CONCATENATE 0x00000004\r
+\r
+/* CK_X9_42_DH1_DERIVE_PARAMS is new for v2.11.\r
+ * CK_X9_42_DH1_DERIVE_PARAMS provides the parameters to the \r
+ * CKM_X9_42_DH_DERIVE key derivation mechanism, where each party\r
+ * contributes one key pair */\r
+typedef struct CK_X9_42_DH1_DERIVE_PARAMS {\r
+  CK_X9_42_DH_KDF_TYPE kdf;\r
+  CK_ULONG ulOtherInfoLen;\r
+  CK_BYTE_PTR pOtherInfo;\r
+  CK_ULONG ulPublicDataLen;\r
+  CK_BYTE_PTR pPublicData;\r
+} CK_X9_42_DH1_DERIVE_PARAMS;\r
+\r
+typedef struct CK_X9_42_DH1_DERIVE_PARAMS CK_PTR CK_X9_42_DH1_DERIVE_PARAMS_PTR;\r
+\r
+/* CK_X9_42_DH2_DERIVE_PARAMS is new for v2.11.\r
+ * CK_X9_42_DH2_DERIVE_PARAMS provides the parameters to the \r
+ * CKM_X9_42_DH_HYBRID_DERIVE and CKM_X9_42_MQV_DERIVE key derivation\r
+ * mechanisms, where each party contributes two key pairs */\r
+typedef struct CK_X9_42_DH2_DERIVE_PARAMS {\r
+  CK_X9_42_DH_KDF_TYPE kdf;\r
+  CK_ULONG ulOtherInfoLen;\r
+  CK_BYTE_PTR pOtherInfo;\r
+  CK_ULONG ulPublicDataLen;\r
+  CK_BYTE_PTR pPublicData;\r
+  CK_ULONG ulPrivateDataLen;\r
+  CK_OBJECT_HANDLE hPrivateData;\r
+  CK_ULONG ulPublicDataLen2;\r
+  CK_BYTE_PTR pPublicData2;\r
+} CK_X9_42_DH2_DERIVE_PARAMS;\r
+\r
+typedef CK_X9_42_DH2_DERIVE_PARAMS CK_PTR CK_X9_42_DH2_DERIVE_PARAMS_PTR;\r
+\r
+/* CK_KEA_DERIVE_PARAMS provides the parameters to the\r
+ * CKM_KEA_DERIVE mechanism */\r
+/* CK_KEA_DERIVE_PARAMS is new for v2.0 */\r
+typedef struct CK_KEA_DERIVE_PARAMS {\r
+  CK_BBOOL      isSender;\r
+  CK_ULONG      ulRandomLen;\r
+  CK_BYTE_PTR   pRandomA;\r
+  CK_BYTE_PTR   pRandomB;\r
+  CK_ULONG      ulPublicDataLen;\r
+  CK_BYTE_PTR   pPublicData;\r
+} CK_KEA_DERIVE_PARAMS;\r
+\r
+typedef CK_KEA_DERIVE_PARAMS CK_PTR CK_KEA_DERIVE_PARAMS_PTR;\r
+\r
+\r
+/* CK_RC2_PARAMS provides the parameters to the CKM_RC2_ECB and\r
+ * CKM_RC2_MAC mechanisms.  An instance of CK_RC2_PARAMS just\r
+ * holds the effective keysize */\r
+typedef CK_ULONG          CK_RC2_PARAMS;\r
+\r
+typedef CK_RC2_PARAMS CK_PTR CK_RC2_PARAMS_PTR;\r
+\r
+\r
+/* CK_RC2_CBC_PARAMS provides the parameters to the CKM_RC2_CBC\r
+ * mechanism */\r
+typedef struct CK_RC2_CBC_PARAMS {\r
+  /* ulEffectiveBits was changed from CK_USHORT to CK_ULONG for\r
+   * v2.0 */\r
+  CK_ULONG      ulEffectiveBits;  /* effective bits (1-1024) */\r
+\r
+  CK_BYTE       iv[8];            /* IV for CBC mode */\r
+} CK_RC2_CBC_PARAMS;\r
+\r
+typedef CK_RC2_CBC_PARAMS CK_PTR CK_RC2_CBC_PARAMS_PTR;\r
+\r
+\r
+/* CK_RC2_MAC_GENERAL_PARAMS provides the parameters for the\r
+ * CKM_RC2_MAC_GENERAL mechanism */\r
+/* CK_RC2_MAC_GENERAL_PARAMS is new for v2.0 */\r
+typedef struct CK_RC2_MAC_GENERAL_PARAMS {\r
+  CK_ULONG      ulEffectiveBits;  /* effective bits (1-1024) */\r
+  CK_ULONG      ulMacLength;      /* Length of MAC in bytes */\r
+} CK_RC2_MAC_GENERAL_PARAMS;\r
+\r
+typedef CK_RC2_MAC_GENERAL_PARAMS CK_PTR \\r
+  CK_RC2_MAC_GENERAL_PARAMS_PTR;\r
+\r
+\r
+/* CK_RC5_PARAMS provides the parameters to the CKM_RC5_ECB and\r
+ * CKM_RC5_MAC mechanisms */\r
+/* CK_RC5_PARAMS is new for v2.0 */\r
+typedef struct CK_RC5_PARAMS {\r
+  CK_ULONG      ulWordsize;  /* wordsize in bits */\r
+  CK_ULONG      ulRounds;    /* number of rounds */\r
+} CK_RC5_PARAMS;\r
+\r
+typedef CK_RC5_PARAMS CK_PTR CK_RC5_PARAMS_PTR;\r
+\r
+\r
+/* CK_RC5_CBC_PARAMS provides the parameters to the CKM_RC5_CBC\r
+ * mechanism */\r
+/* CK_RC5_CBC_PARAMS is new for v2.0 */\r
+typedef struct CK_RC5_CBC_PARAMS {\r
+  CK_ULONG      ulWordsize;  /* wordsize in bits */\r
+  CK_ULONG      ulRounds;    /* number of rounds */\r
+  CK_BYTE_PTR   pIv;         /* pointer to IV */\r
+  CK_ULONG      ulIvLen;     /* length of IV in bytes */\r
+} CK_RC5_CBC_PARAMS;\r
+\r
+typedef CK_RC5_CBC_PARAMS CK_PTR CK_RC5_CBC_PARAMS_PTR;\r
+\r
+\r
+/* CK_RC5_MAC_GENERAL_PARAMS provides the parameters for the\r
+ * CKM_RC5_MAC_GENERAL mechanism */\r
+/* CK_RC5_MAC_GENERAL_PARAMS is new for v2.0 */\r
+typedef struct CK_RC5_MAC_GENERAL_PARAMS {\r
+  CK_ULONG      ulWordsize;   /* wordsize in bits */\r
+  CK_ULONG      ulRounds;     /* number of rounds */\r
+  CK_ULONG      ulMacLength;  /* Length of MAC in bytes */\r
+} CK_RC5_MAC_GENERAL_PARAMS;\r
+\r
+typedef CK_RC5_MAC_GENERAL_PARAMS CK_PTR \\r
+  CK_RC5_MAC_GENERAL_PARAMS_PTR;\r
+\r
+\r
+/* CK_MAC_GENERAL_PARAMS provides the parameters to most block\r
+ * ciphers' MAC_GENERAL mechanisms.  Its value is the length of\r
+ * the MAC */\r
+/* CK_MAC_GENERAL_PARAMS is new for v2.0 */\r
+typedef CK_ULONG          CK_MAC_GENERAL_PARAMS;\r
+\r
+typedef CK_MAC_GENERAL_PARAMS CK_PTR CK_MAC_GENERAL_PARAMS_PTR;\r
+\r
+\r
+/* CK_SKIPJACK_PRIVATE_WRAP_PARAMS provides the parameters to the\r
+ * CKM_SKIPJACK_PRIVATE_WRAP mechanism */\r
+/* CK_SKIPJACK_PRIVATE_WRAP_PARAMS is new for v2.0 */\r
+typedef struct CK_SKIPJACK_PRIVATE_WRAP_PARAMS {\r
+  CK_ULONG      ulPasswordLen;\r
+  CK_BYTE_PTR   pPassword;\r
+  CK_ULONG      ulPublicDataLen;\r
+  CK_BYTE_PTR   pPublicData;\r
+  CK_ULONG      ulPAndGLen;\r
+  CK_ULONG      ulQLen;\r
+  CK_ULONG      ulRandomLen;\r
+  CK_BYTE_PTR   pRandomA;\r
+  CK_BYTE_PTR   pPrimeP;\r
+  CK_BYTE_PTR   pBaseG;\r
+  CK_BYTE_PTR   pSubprimeQ;\r
+} CK_SKIPJACK_PRIVATE_WRAP_PARAMS;\r
+\r
+typedef CK_SKIPJACK_PRIVATE_WRAP_PARAMS CK_PTR \\r
+  CK_SKIPJACK_PRIVATE_WRAP_PTR;\r
+\r
+\r
+/* CK_SKIPJACK_RELAYX_PARAMS provides the parameters to the\r
+ * CKM_SKIPJACK_RELAYX mechanism */\r
+/* CK_SKIPJACK_RELAYX_PARAMS is new for v2.0 */\r
+typedef struct CK_SKIPJACK_RELAYX_PARAMS {\r
+  CK_ULONG      ulOldWrappedXLen;\r
+  CK_BYTE_PTR   pOldWrappedX;\r
+  CK_ULONG      ulOldPasswordLen;\r
+  CK_BYTE_PTR   pOldPassword;\r
+  CK_ULONG      ulOldPublicDataLen;\r
+  CK_BYTE_PTR   pOldPublicData;\r
+  CK_ULONG      ulOldRandomLen;\r
+  CK_BYTE_PTR   pOldRandomA;\r
+  CK_ULONG      ulNewPasswordLen;\r
+  CK_BYTE_PTR   pNewPassword;\r
+  CK_ULONG      ulNewPublicDataLen;\r
+  CK_BYTE_PTR   pNewPublicData;\r
+  CK_ULONG      ulNewRandomLen;\r
+  CK_BYTE_PTR   pNewRandomA;\r
+} CK_SKIPJACK_RELAYX_PARAMS;\r
+\r
+typedef CK_SKIPJACK_RELAYX_PARAMS CK_PTR \\r
+  CK_SKIPJACK_RELAYX_PARAMS_PTR;\r
+\r
+\r
+typedef struct CK_PBE_PARAMS {\r
+  CK_BYTE_PTR      pInitVector;\r
+  CK_UTF8CHAR_PTR  pPassword;\r
+  CK_ULONG         ulPasswordLen;\r
+  CK_BYTE_PTR      pSalt;\r
+  CK_ULONG         ulSaltLen;\r
+  CK_ULONG         ulIteration;\r
+} CK_PBE_PARAMS;\r
+\r
+typedef CK_PBE_PARAMS CK_PTR CK_PBE_PARAMS_PTR;\r
+\r
+\r
+/* CK_KEY_WRAP_SET_OAEP_PARAMS provides the parameters to the\r
+ * CKM_KEY_WRAP_SET_OAEP mechanism */\r
+/* CK_KEY_WRAP_SET_OAEP_PARAMS is new for v2.0 */\r
+typedef struct CK_KEY_WRAP_SET_OAEP_PARAMS {\r
+  CK_BYTE       bBC;     /* block contents byte */\r
+  CK_BYTE_PTR   pX;      /* extra data */\r
+  CK_ULONG      ulXLen;  /* length of extra data in bytes */\r
+} CK_KEY_WRAP_SET_OAEP_PARAMS;\r
+\r
+typedef CK_KEY_WRAP_SET_OAEP_PARAMS CK_PTR \\r
+  CK_KEY_WRAP_SET_OAEP_PARAMS_PTR;\r
+\r
+\r
+typedef struct CK_SSL3_RANDOM_DATA {\r
+  CK_BYTE_PTR  pClientRandom;\r
+  CK_ULONG     ulClientRandomLen;\r
+  CK_BYTE_PTR  pServerRandom;\r
+  CK_ULONG     ulServerRandomLen;\r
+} CK_SSL3_RANDOM_DATA;\r
+\r
+\r
+typedef struct CK_SSL3_MASTER_KEY_DERIVE_PARAMS {\r
+  CK_SSL3_RANDOM_DATA RandomInfo;\r
+  CK_VERSION_PTR pVersion;\r
+} CK_SSL3_MASTER_KEY_DERIVE_PARAMS;\r
+\r
+typedef struct CK_SSL3_MASTER_KEY_DERIVE_PARAMS CK_PTR \\r
+  CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR;\r
+\r
+\r
+typedef struct CK_SSL3_KEY_MAT_OUT {\r
+  CK_OBJECT_HANDLE hClientMacSecret;\r
+  CK_OBJECT_HANDLE hServerMacSecret;\r
+  CK_OBJECT_HANDLE hClientKey;\r
+  CK_OBJECT_HANDLE hServerKey;\r
+  CK_BYTE_PTR      pIVClient;\r
+  CK_BYTE_PTR      pIVServer;\r
+} CK_SSL3_KEY_MAT_OUT;\r
+\r
+typedef CK_SSL3_KEY_MAT_OUT CK_PTR CK_SSL3_KEY_MAT_OUT_PTR;\r
+\r
+\r
+typedef struct CK_SSL3_KEY_MAT_PARAMS {\r
+  CK_ULONG                ulMacSizeInBits;\r
+  CK_ULONG                ulKeySizeInBits;\r
+  CK_ULONG                ulIVSizeInBits;\r
+  CK_BBOOL                bIsExport;\r
+  CK_SSL3_RANDOM_DATA     RandomInfo;\r
+  CK_SSL3_KEY_MAT_OUT_PTR pReturnedKeyMaterial;\r
+} CK_SSL3_KEY_MAT_PARAMS;\r
+\r
+typedef CK_SSL3_KEY_MAT_PARAMS CK_PTR CK_SSL3_KEY_MAT_PARAMS_PTR;\r
+\r
+\r
+typedef struct CK_KEY_DERIVATION_STRING_DATA {\r
+  CK_BYTE_PTR pData;\r
+  CK_ULONG    ulLen;\r
+} CK_KEY_DERIVATION_STRING_DATA;\r
+\r
+typedef CK_KEY_DERIVATION_STRING_DATA CK_PTR \\r
+  CK_KEY_DERIVATION_STRING_DATA_PTR;\r
+\r
+\r
+/* The CK_EXTRACT_PARAMS is used for the\r
+ * CKM_EXTRACT_KEY_FROM_KEY mechanism.  It specifies which bit\r
+ * of the base key should be used as the first bit of the\r
+ * derived key */\r
+/* CK_EXTRACT_PARAMS is new for v2.0 */\r
+typedef CK_ULONG CK_EXTRACT_PARAMS;\r
+\r
+typedef CK_EXTRACT_PARAMS CK_PTR CK_EXTRACT_PARAMS_PTR;\r
+\r
+/* CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE is new for v2.10.\r
+ * CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE is used to \r
+ * indicate the Pseudo-Random Function (PRF) used to generate \r
+ * key bits using PKCS #5 PBKDF2. */\r
+typedef CK_ULONG CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE;\r
+\r
+typedef CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE CK_PTR CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE_PTR;\r
+\r
+/* The following PRFs are defined in PKCS #5 v2.0. */\r
+#define CKP_PKCS5_PBKD2_HMAC_SHA1 0x00000001\r
+\r
+\r
+/* CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE is new for v2.10.\r
+ * CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE is used to indicate the \r
+ * source of the salt value when deriving a key using PKCS #5 \r
+ * PBKDF2. */\r
+typedef CK_ULONG CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE;\r
+\r
+typedef CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE CK_PTR CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE_PTR;\r
+\r
+/* The following salt value sources are defined in PKCS #5 v2.0. */\r
+#define CKZ_SALT_SPECIFIED        0x00000001\r
+\r
+/* CK_PKCS5_PBKD2_PARAMS is new for v2.10.\r
+ * CK_PKCS5_PBKD2_PARAMS is a structure that provides the \r
+ * parameters to the CKM_PKCS5_PBKD2 mechanism. */\r
+typedef struct CK_PKCS5_PBKD2_PARAMS {\r
+       CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE           saltSource;\r
+       CK_VOID_PTR                                pSaltSourceData;\r
+       CK_ULONG                                   ulSaltSourceDataLen;\r
+       CK_ULONG                                   iterations;\r
+       CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE prf;\r
+       CK_VOID_PTR                                pPrfData;\r
+       CK_ULONG                                   ulPrfDataLen;\r
+       CK_UTF8CHAR_PTR                            pPassword;\r
+       CK_ULONG_PTR                               ulPasswordLen;\r
+} CK_PKCS5_PBKD2_PARAMS;\r
+\r
+typedef CK_PKCS5_PBKD2_PARAMS CK_PTR CK_PKCS5_PBKD2_PARAMS_PTR;\r
+\r
+#endif\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/zlib/zconf.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/zlib/zconf.h
new file mode 100644 (file)
index 0000000..e3b0c96
--- /dev/null
@@ -0,0 +1,332 @@
+/* zconf.h -- configuration of the zlib compression library\r
+ * Copyright (C) 1995-2005 Jean-loup Gailly.\r
+ * For conditions of distribution and use, see copyright notice in zlib.h\r
+ */\r
+\r
+/* @(#) $Id$ */\r
+\r
+#ifndef ZCONF_H\r
+#define ZCONF_H\r
+\r
+/*\r
+ * If you *really* need a unique prefix for all types and library functions,\r
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.\r
+ */\r
+#ifdef Z_PREFIX\r
+#  define deflateInit_          z_deflateInit_\r
+#  define deflate               z_deflate\r
+#  define deflateEnd            z_deflateEnd\r
+#  define inflateInit_          z_inflateInit_\r
+#  define inflate               z_inflate\r
+#  define inflateEnd            z_inflateEnd\r
+#  define deflateInit2_         z_deflateInit2_\r
+#  define deflateSetDictionary  z_deflateSetDictionary\r
+#  define deflateCopy           z_deflateCopy\r
+#  define deflateReset          z_deflateReset\r
+#  define deflateParams         z_deflateParams\r
+#  define deflateBound          z_deflateBound\r
+#  define deflatePrime          z_deflatePrime\r
+#  define inflateInit2_         z_inflateInit2_\r
+#  define inflateSetDictionary  z_inflateSetDictionary\r
+#  define inflateSync           z_inflateSync\r
+#  define inflateSyncPoint      z_inflateSyncPoint\r
+#  define inflateCopy           z_inflateCopy\r
+#  define inflateReset          z_inflateReset\r
+#  define inflateBack           z_inflateBack\r
+#  define inflateBackEnd        z_inflateBackEnd\r
+#  define compress              z_compress\r
+#  define compress2             z_compress2\r
+#  define compressBound         z_compressBound\r
+#  define uncompress            z_uncompress\r
+#  define adler32               z_adler32\r
+#  define crc32                 z_crc32\r
+#  define get_crc_table         z_get_crc_table\r
+#  define zError                z_zError\r
+\r
+#  define alloc_func            z_alloc_func\r
+#  define free_func             z_free_func\r
+#  define in_func               z_in_func\r
+#  define out_func              z_out_func\r
+#  define Byte                  z_Byte\r
+#  define uInt                  z_uInt\r
+#  define uLong                 z_uLong\r
+#  define Bytef                 z_Bytef\r
+#  define charf                 z_charf\r
+#  define intf                  z_intf\r
+#  define uIntf                 z_uIntf\r
+#  define uLongf                z_uLongf\r
+#  define voidpf                z_voidpf\r
+#  define voidp                 z_voidp\r
+#endif\r
+\r
+#if defined(__MSDOS__) && !defined(MSDOS)\r
+#  define MSDOS\r
+#endif\r
+#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)\r
+#  define OS2\r
+#endif\r
+#if defined(_WINDOWS) && !defined(WINDOWS)\r
+#  define WINDOWS\r
+#endif\r
+#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)\r
+#  ifndef WIN32\r
+#    define WIN32\r
+#  endif\r
+#endif\r
+#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)\r
+#  if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)\r
+#    ifndef SYS16BIT\r
+#      define SYS16BIT\r
+#    endif\r
+#  endif\r
+#endif\r
+\r
+/*\r
+ * Compile with -DMAXSEG_64K if the alloc function cannot allocate more\r
+ * than 64k bytes at a time (needed on systems with 16-bit int).\r
+ */\r
+#ifdef SYS16BIT\r
+#  define MAXSEG_64K\r
+#endif\r
+#ifdef MSDOS\r
+#  define UNALIGNED_OK\r
+#endif\r
+\r
+#ifdef __STDC_VERSION__\r
+#  ifndef STDC\r
+#    define STDC\r
+#  endif\r
+#  if __STDC_VERSION__ >= 199901L\r
+#    ifndef STDC99\r
+#      define STDC99\r
+#    endif\r
+#  endif\r
+#endif\r
+#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))\r
+#  define STDC\r
+#endif\r
+#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))\r
+#  define STDC\r
+#endif\r
+#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))\r
+#  define STDC\r
+#endif\r
+#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))\r
+#  define STDC\r
+#endif\r
+\r
+#if defined(__OS400__) && !defined(STDC)    /* iSeries (formerly AS/400). */\r
+#  define STDC\r
+#endif\r
+\r
+#ifndef STDC\r
+#  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */\r
+#    define const       /* note: need a more gentle solution here */\r
+#  endif\r
+#endif\r
+\r
+/* Some Mac compilers merge all .h files incorrectly: */\r
+#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)\r
+#  define NO_DUMMY_DECL\r
+#endif\r
+\r
+/* Maximum value for memLevel in deflateInit2 */\r
+#ifndef MAX_MEM_LEVEL\r
+#  ifdef MAXSEG_64K\r
+#    define MAX_MEM_LEVEL 8\r
+#  else\r
+#    define MAX_MEM_LEVEL 9\r
+#  endif\r
+#endif\r
+\r
+/* Maximum value for windowBits in deflateInit2 and inflateInit2.\r
+ * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files\r
+ * created by gzip. (Files created by minigzip can still be extracted by\r
+ * gzip.)\r
+ */\r
+#ifndef MAX_WBITS\r
+#  define MAX_WBITS   15 /* 32K LZ77 window */\r
+#endif\r
+\r
+/* The memory requirements for deflate are (in bytes):\r
+            (1 << (windowBits+2)) +  (1 << (memLevel+9))\r
+ that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)\r
+ plus a few kilobytes for small objects. For example, if you want to reduce\r
+ the default memory requirements from 256K to 128K, compile with\r
+     make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"\r
+ Of course this will generally degrade compression (there's no free lunch).\r
+\r
+   The memory requirements for inflate are (in bytes) 1 << windowBits\r
+ that is, 32K for windowBits=15 (default value) plus a few kilobytes\r
+ for small objects.\r
+*/\r
+\r
+                        /* Type declarations */\r
+\r
+#ifndef OF /* function prototypes */\r
+#  ifdef STDC\r
+#    define OF(args)  args\r
+#  else\r
+#    define OF(args)  ()\r
+#  endif\r
+#endif\r
+\r
+/* The following definitions for FAR are needed only for MSDOS mixed\r
+ * model programming (small or medium model with some far allocations).\r
+ * This was tested only with MSC; for other MSDOS compilers you may have\r
+ * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,\r
+ * just define FAR to be empty.\r
+ */\r
+#ifdef SYS16BIT\r
+#  if defined(M_I86SM) || defined(M_I86MM)\r
+     /* MSC small or medium model */\r
+#    define SMALL_MEDIUM\r
+#    ifdef _MSC_VER\r
+#      define FAR _far\r
+#    else\r
+#      define FAR far\r
+#    endif\r
+#  endif\r
+#  if (defined(__SMALL__) || defined(__MEDIUM__))\r
+     /* Turbo C small or medium model */\r
+#    define SMALL_MEDIUM\r
+#    ifdef __BORLANDC__\r
+#      define FAR _far\r
+#    else\r
+#      define FAR far\r
+#    endif\r
+#  endif\r
+#endif\r
+\r
+#if defined(WINDOWS) || defined(WIN32)\r
+   /* If building or using zlib as a DLL, define ZLIB_DLL.\r
+    * This is not mandatory, but it offers a little performance increase.\r
+    */\r
+#  ifdef ZLIB_DLL\r
+#    if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))\r
+#      ifdef ZLIB_INTERNAL\r
+#        define ZEXTERN extern __declspec(dllexport)\r
+#      else\r
+#        define ZEXTERN extern __declspec(dllimport)\r
+#      endif\r
+#    endif\r
+#  endif  /* ZLIB_DLL */\r
+   /* If building or using zlib with the WINAPI/WINAPIV calling convention,\r
+    * define ZLIB_WINAPI.\r
+    * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.\r
+    */\r
+#  ifdef ZLIB_WINAPI\r
+#    ifdef FAR\r
+#      undef FAR\r
+#    endif\r
+#    include <windows.h>\r
+     /* No need for _export, use ZLIB.DEF instead. */\r
+     /* For complete Windows compatibility, use WINAPI, not __stdcall. */\r
+#    define ZEXPORT WINAPI\r
+#    ifdef WIN32\r
+#      define ZEXPORTVA WINAPIV\r
+#    else\r
+#      define ZEXPORTVA FAR CDECL\r
+#    endif\r
+#  endif\r
+#endif\r
+\r
+#if defined (__BEOS__)\r
+#  ifdef ZLIB_DLL\r
+#    ifdef ZLIB_INTERNAL\r
+#      define ZEXPORT   __declspec(dllexport)\r
+#      define ZEXPORTVA __declspec(dllexport)\r
+#    else\r
+#      define ZEXPORT   __declspec(dllimport)\r
+#      define ZEXPORTVA __declspec(dllimport)\r
+#    endif\r
+#  endif\r
+#endif\r
+\r
+#ifndef ZEXTERN\r
+#  define ZEXTERN extern\r
+#endif\r
+#ifndef ZEXPORT\r
+#  define ZEXPORT\r
+#endif\r
+#ifndef ZEXPORTVA\r
+#  define ZEXPORTVA\r
+#endif\r
+\r
+#ifndef FAR\r
+#  define FAR\r
+#endif\r
+\r
+#if !defined(__MACTYPES__)\r
+typedef unsigned char  Byte;  /* 8 bits */\r
+#endif\r
+typedef unsigned int   uInt;  /* 16 bits or more */\r
+typedef unsigned long  uLong; /* 32 bits or more */\r
+\r
+#ifdef SMALL_MEDIUM\r
+   /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */\r
+#  define Bytef Byte FAR\r
+#else\r
+   typedef Byte  FAR Bytef;\r
+#endif\r
+typedef char  FAR charf;\r
+typedef int   FAR intf;\r
+typedef uInt  FAR uIntf;\r
+typedef uLong FAR uLongf;\r
+\r
+#ifdef STDC\r
+   typedef void const *voidpc;\r
+   typedef void FAR   *voidpf;\r
+   typedef void       *voidp;\r
+#else\r
+   typedef Byte const *voidpc;\r
+   typedef Byte FAR   *voidpf;\r
+   typedef Byte       *voidp;\r
+#endif\r
+\r
+#if 0           /* HAVE_UNISTD_H -- this line is updated by ./configure */\r
+#  include <sys/types.h> /* for off_t */\r
+#  include <unistd.h>    /* for SEEK_* and off_t */\r
+#  ifdef VMS\r
+#    include <unixio.h>   /* for off_t */\r
+#  endif\r
+#  define z_off_t off_t\r
+#endif\r
+#ifndef SEEK_SET\r
+#  define SEEK_SET        0       /* Seek from beginning of file.  */\r
+#  define SEEK_CUR        1       /* Seek from current position.  */\r
+#  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */\r
+#endif\r
+#ifndef z_off_t\r
+#  define z_off_t long\r
+#endif\r
+\r
+#if defined(__OS400__)\r
+#  define NO_vsnprintf\r
+#endif\r
+\r
+#if defined(__MVS__)\r
+#  define NO_vsnprintf\r
+#  ifdef FAR\r
+#    undef FAR\r
+#  endif\r
+#endif\r
+\r
+/* MVS linker does not support external names larger than 8 bytes */\r
+#if defined(__MVS__)\r
+#   pragma map(deflateInit_,"DEIN")\r
+#   pragma map(deflateInit2_,"DEIN2")\r
+#   pragma map(deflateEnd,"DEEND")\r
+#   pragma map(deflateBound,"DEBND")\r
+#   pragma map(inflateInit_,"ININ")\r
+#   pragma map(inflateInit2_,"ININ2")\r
+#   pragma map(inflateEnd,"INEND")\r
+#   pragma map(inflateSync,"INSY")\r
+#   pragma map(inflateSetDictionary,"INSEDI")\r
+#   pragma map(compressBound,"CMBND")\r
+#   pragma map(inflate_table,"INTABL")\r
+#   pragma map(inflate_fast,"INFA")\r
+#   pragma map(inflate_copyright,"INCOPY")\r
+#endif\r
+\r
+#endif /* ZCONF_H */\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/zlib/zlib.h b/utvpn/utvpn-unix-v101-7101-public/src/Mayaqua/zlib/zlib.h
new file mode 100644 (file)
index 0000000..62d0e46
--- /dev/null
@@ -0,0 +1,1357 @@
+/* zlib.h -- interface of the 'zlib' general purpose compression library\r
+  version 1.2.3, July 18th, 2005\r
+\r
+  Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler\r
+\r
+  This software is provided 'as-is', without any express or implied\r
+  warranty.  In no event will the authors be held liable for any damages\r
+  arising from the use of this software.\r
+\r
+  Permission is granted to anyone to use this software for any purpose,\r
+  including commercial applications, and to alter it and redistribute it\r
+  freely, subject to the following restrictions:\r
+\r
+  1. The origin of this software must not be misrepresented; you must not\r
+     claim that you wrote the original software. If you use this software\r
+     in a product, an acknowledgment in the product documentation would be\r
+     appreciated but is not required.\r
+  2. Altered source versions must be plainly marked as such, and must not be\r
+     misrepresented as being the original software.\r
+  3. This notice may not be removed or altered from any source distribution.\r
+\r
+  Jean-loup Gailly        Mark Adler\r
+  jloup@gzip.org          madler@alumni.caltech.edu\r
+\r
+\r
+  The data format used by the zlib library is described by RFCs (Request for\r
+  Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt\r
+  (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).\r
+*/\r
+\r
+#ifndef ZLIB_H\r
+#define ZLIB_H\r
+\r
+#include "zconf.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define ZLIB_VERSION "1.2.3"\r
+#define ZLIB_VERNUM 0x1230\r
+\r
+/*\r
+     The 'zlib' compression library provides in-memory compression and\r
+  decompression functions, including integrity checks of the uncompressed\r
+  data.  This version of the library supports only one compression method\r
+  (deflation) but other algorithms will be added later and will have the same\r
+  stream interface.\r
+\r
+     Compression can be done in a single step if the buffers are large\r
+  enough (for example if an input file is mmap'ed), or can be done by\r
+  repeated calls of the compression function.  In the latter case, the\r
+  application must provide more input and/or consume the output\r
+  (providing more output space) before each call.\r
+\r
+     The compressed data format used by default by the in-memory functions is\r
+  the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped\r
+  around a deflate stream, which is itself documented in RFC 1951.\r
+\r
+     The library also supports reading and writing files in gzip (.gz) format\r
+  with an interface similar to that of stdio using the functions that start\r
+  with "gz".  The gzip format is different from the zlib format.  gzip is a\r
+  gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.\r
+\r
+     This library can optionally read and write gzip streams in memory as well.\r
+\r
+     The zlib format was designed to be compact and fast for use in memory\r
+  and on communications channels.  The gzip format was designed for single-\r
+  file compression on file systems, has a larger header than zlib to maintain\r
+  directory information, and uses a different, slower check method than zlib.\r
+\r
+     The library does not install any signal handler. The decoder checks\r
+  the consistency of the compressed data, so the library should never\r
+  crash even in case of corrupted input.\r
+*/\r
+\r
+typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));\r
+typedef void   (*free_func)  OF((voidpf opaque, voidpf address));\r
+\r
+struct internal_state;\r
+\r
+typedef struct z_stream_s {\r
+    Bytef    *next_in;  /* next input byte */\r
+    uInt     avail_in;  /* number of bytes available at next_in */\r
+    uLong    total_in;  /* total nb of input bytes read so far */\r
+\r
+    Bytef    *next_out; /* next output byte should be put there */\r
+    uInt     avail_out; /* remaining free space at next_out */\r
+    uLong    total_out; /* total nb of bytes output so far */\r
+\r
+    char     *msg;      /* last error message, NULL if no error */\r
+    struct internal_state FAR *state; /* not visible by applications */\r
+\r
+    alloc_func zalloc;  /* used to allocate the internal state */\r
+    free_func  zfree;   /* used to free the internal state */\r
+    voidpf     opaque;  /* private data object passed to zalloc and zfree */\r
+\r
+    int     data_type;  /* best guess about the data type: binary or text */\r
+    uLong   adler;      /* adler32 value of the uncompressed data */\r
+    uLong   reserved;   /* reserved for future use */\r
+} z_stream;\r
+\r
+typedef z_stream FAR *z_streamp;\r
+\r
+/*\r
+     gzip header information passed to and from zlib routines.  See RFC 1952\r
+  for more details on the meanings of these fields.\r
+*/\r
+typedef struct gz_header_s {\r
+    int     text;       /* true if compressed data believed to be text */\r
+    uLong   time;       /* modification time */\r
+    int     xflags;     /* extra flags (not used when writing a gzip file) */\r
+    int     os;         /* operating system */\r
+    Bytef   *extra;     /* pointer to extra field or Z_NULL if none */\r
+    uInt    extra_len;  /* extra field length (valid if extra != Z_NULL) */\r
+    uInt    extra_max;  /* space at extra (only when reading header) */\r
+    Bytef   *name;      /* pointer to zero-terminated file name or Z_NULL */\r
+    uInt    name_max;   /* space at name (only when reading header) */\r
+    Bytef   *comment;   /* pointer to zero-terminated comment or Z_NULL */\r
+    uInt    comm_max;   /* space at comment (only when reading header) */\r
+    int     hcrc;       /* true if there was or will be a header crc */\r
+    int     done;       /* true when done reading gzip header (not used\r
+                           when writing a gzip file) */\r
+} gz_header;\r
+\r
+typedef gz_header FAR *gz_headerp;\r
+\r
+/*\r
+   The application must update next_in and avail_in when avail_in has\r
+   dropped to zero. It must update next_out and avail_out when avail_out\r
+   has dropped to zero. The application must initialize zalloc, zfree and\r
+   opaque before calling the init function. All other fields are set by the\r
+   compression library and must not be updated by the application.\r
+\r
+   The opaque value provided by the application will be passed as the first\r
+   parameter for calls of zalloc and zfree. This can be useful for custom\r
+   memory management. The compression library attaches no meaning to the\r
+   opaque value.\r
+\r
+   zalloc must return Z_NULL if there is not enough memory for the object.\r
+   If zlib is used in a multi-threaded application, zalloc and zfree must be\r
+   thread safe.\r
+\r
+   On 16-bit systems, the functions zalloc and zfree must be able to allocate\r
+   exactly 65536 bytes, but will not be required to allocate more than this\r
+   if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,\r
+   pointers returned by zalloc for objects of exactly 65536 bytes *must*\r
+   have their offset normalized to zero. The default allocation function\r
+   provided by this library ensures this (see zutil.c). To reduce memory\r
+   requirements and avoid any allocation of 64K objects, at the expense of\r
+   compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).\r
+\r
+   The fields total_in and total_out can be used for statistics or\r
+   progress reports. After compression, total_in holds the total size of\r
+   the uncompressed data and may be saved for use in the decompressor\r
+   (particularly if the decompressor wants to decompress everything in\r
+   a single step).\r
+*/\r
+\r
+                        /* constants */\r
+\r
+#define Z_NO_FLUSH      0\r
+#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */\r
+#define Z_SYNC_FLUSH    2\r
+#define Z_FULL_FLUSH    3\r
+#define Z_FINISH        4\r
+#define Z_BLOCK         5\r
+/* Allowed flush values; see deflate() and inflate() below for details */\r
+\r
+#define Z_OK            0\r
+#define Z_STREAM_END    1\r
+#define Z_NEED_DICT     2\r
+#define Z_ERRNO        (-1)\r
+#define Z_STREAM_ERROR (-2)\r
+#define Z_DATA_ERROR   (-3)\r
+#define Z_MEM_ERROR    (-4)\r
+#define Z_BUF_ERROR    (-5)\r
+#define Z_VERSION_ERROR (-6)\r
+/* Return codes for the compression/decompression functions. Negative\r
+ * values are errors, positive values are used for special but normal events.\r
+ */\r
+\r
+#define Z_NO_COMPRESSION         0\r
+#define Z_BEST_SPEED             1\r
+#define Z_BEST_COMPRESSION       9\r
+#define Z_DEFAULT_COMPRESSION  (-1)\r
+/* compression levels */\r
+\r
+#define Z_FILTERED            1\r
+#define Z_HUFFMAN_ONLY        2\r
+#define Z_RLE                 3\r
+#define Z_FIXED               4\r
+#define Z_DEFAULT_STRATEGY    0\r
+/* compression strategy; see deflateInit2() below for details */\r
+\r
+#define Z_BINARY   0\r
+#define Z_TEXT     1\r
+#define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */\r
+#define Z_UNKNOWN  2\r
+/* Possible values of the data_type field (though see inflate()) */\r
+\r
+#define Z_DEFLATED   8\r
+/* The deflate compression method (the only one supported in this version) */\r
+\r
+#define Z_NULL  0  /* for initializing zalloc, zfree, opaque */\r
+\r
+#define zlib_version zlibVersion()\r
+/* for compatibility with versions < 1.0.2 */\r
+\r
+                        /* basic functions */\r
+\r
+ZEXTERN const char * ZEXPORT zlibVersion OF((void));\r
+/* The application can compare zlibVersion and ZLIB_VERSION for consistency.\r
+   If the first character differs, the library code actually used is\r
+   not compatible with the zlib.h header file used by the application.\r
+   This check is automatically made by deflateInit and inflateInit.\r
+ */\r
+\r
+/*\r
+ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));\r
+\r
+     Initializes the internal stream state for compression. The fields\r
+   zalloc, zfree and opaque must be initialized before by the caller.\r
+   If zalloc and zfree are set to Z_NULL, deflateInit updates them to\r
+   use default allocation functions.\r
+\r
+     The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:\r
+   1 gives best speed, 9 gives best compression, 0 gives no compression at\r
+   all (the input data is simply copied a block at a time).\r
+   Z_DEFAULT_COMPRESSION requests a default compromise between speed and\r
+   compression (currently equivalent to level 6).\r
+\r
+     deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not\r
+   enough memory, Z_STREAM_ERROR if level is not a valid compression level,\r
+   Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible\r
+   with the version assumed by the caller (ZLIB_VERSION).\r
+   msg is set to null if there is no error message.  deflateInit does not\r
+   perform any compression: this will be done by deflate().\r
+*/\r
+\r
+\r
+ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));\r
+/*\r
+    deflate compresses as much data as possible, and stops when the input\r
+  buffer becomes empty or the output buffer becomes full. It may introduce some\r
+  output latency (reading input without producing any output) except when\r
+  forced to flush.\r
+\r
+    The detailed semantics are as follows. deflate performs one or both of the\r
+  following actions:\r
+\r
+  - Compress more input starting at next_in and update next_in and avail_in\r
+    accordingly. If not all input can be processed (because there is not\r
+    enough room in the output buffer), next_in and avail_in are updated and\r
+    processing will resume at this point for the next call of deflate().\r
+\r
+  - Provide more output starting at next_out and update next_out and avail_out\r
+    accordingly. This action is forced if the parameter flush is non zero.\r
+    Forcing flush frequently degrades the compression ratio, so this parameter\r
+    should be set only when necessary (in interactive applications).\r
+    Some output may be provided even if flush is not set.\r
+\r
+  Before the call of deflate(), the application should ensure that at least\r
+  one of the actions is possible, by providing more input and/or consuming\r
+  more output, and updating avail_in or avail_out accordingly; avail_out\r
+  should never be zero before the call. The application can consume the\r
+  compressed output when it wants, for example when the output buffer is full\r
+  (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK\r
+  and with zero avail_out, it must be called again after making room in the\r
+  output buffer because there might be more output pending.\r
+\r
+    Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to\r
+  decide how much data to accumualte before producing output, in order to\r
+  maximize compression.\r
+\r
+    If the parameter flush is set to Z_SYNC_FLUSH, all pending output is\r
+  flushed to the output buffer and the output is aligned on a byte boundary, so\r
+  that the decompressor can get all input data available so far. (In particular\r
+  avail_in is zero after the call if enough output space has been provided\r
+  before the call.)  Flushing may degrade compression for some compression\r
+  algorithms and so it should be used only when necessary.\r
+\r
+    If flush is set to Z_FULL_FLUSH, all output is flushed as with\r
+  Z_SYNC_FLUSH, and the compression state is reset so that decompression can\r
+  restart from this point if previous compressed data has been damaged or if\r
+  random access is desired. Using Z_FULL_FLUSH too often can seriously degrade\r
+  compression.\r
+\r
+    If deflate returns with avail_out == 0, this function must be called again\r
+  with the same value of the flush parameter and more output space (updated\r
+  avail_out), until the flush is complete (deflate returns with non-zero\r
+  avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that\r
+  avail_out is greater than six to avoid repeated flush markers due to\r
+  avail_out == 0 on return.\r
+\r
+    If the parameter flush is set to Z_FINISH, pending input is processed,\r
+  pending output is flushed and deflate returns with Z_STREAM_END if there\r
+  was enough output space; if deflate returns with Z_OK, this function must be\r
+  called again with Z_FINISH and more output space (updated avail_out) but no\r
+  more input data, until it returns with Z_STREAM_END or an error. After\r
+  deflate has returned Z_STREAM_END, the only possible operations on the\r
+  stream are deflateReset or deflateEnd.\r
+\r
+    Z_FINISH can be used immediately after deflateInit if all the compression\r
+  is to be done in a single step. In this case, avail_out must be at least\r
+  the value returned by deflateBound (see below). If deflate does not return\r
+  Z_STREAM_END, then it must be called again as described above.\r
+\r
+    deflate() sets strm->adler to the adler32 checksum of all input read\r
+  so far (that is, total_in bytes).\r
+\r
+    deflate() may update strm->data_type if it can make a good guess about\r
+  the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered\r
+  binary. This field is only for information purposes and does not affect\r
+  the compression algorithm in any manner.\r
+\r
+    deflate() returns Z_OK if some progress has been made (more input\r
+  processed or more output produced), Z_STREAM_END if all input has been\r
+  consumed and all output has been produced (only when flush is set to\r
+  Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example\r
+  if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible\r
+  (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not\r
+  fatal, and deflate() can be called again with more input and more output\r
+  space to continue compressing.\r
+*/\r
+\r
+\r
+ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));\r
+/*\r
+     All dynamically allocated data structures for this stream are freed.\r
+   This function discards any unprocessed input and does not flush any\r
+   pending output.\r
+\r
+     deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the\r
+   stream state was inconsistent, Z_DATA_ERROR if the stream was freed\r
+   prematurely (some input or output was discarded). In the error case,\r
+   msg may be set but then points to a static string (which must not be\r
+   deallocated).\r
+*/\r
+\r
+\r
+/*\r
+ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));\r
+\r
+     Initializes the internal stream state for decompression. The fields\r
+   next_in, avail_in, zalloc, zfree and opaque must be initialized before by\r
+   the caller. If next_in is not Z_NULL and avail_in is large enough (the exact\r
+   value depends on the compression method), inflateInit determines the\r
+   compression method from the zlib header and allocates all data structures\r
+   accordingly; otherwise the allocation will be deferred to the first call of\r
+   inflate.  If zalloc and zfree are set to Z_NULL, inflateInit updates them to\r
+   use default allocation functions.\r
+\r
+     inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
+   memory, Z_VERSION_ERROR if the zlib library version is incompatible with the\r
+   version assumed by the caller.  msg is set to null if there is no error\r
+   message. inflateInit does not perform any decompression apart from reading\r
+   the zlib header if present: this will be done by inflate().  (So next_in and\r
+   avail_in may be modified, but next_out and avail_out are unchanged.)\r
+*/\r
+\r
+\r
+ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));\r
+/*\r
+    inflate decompresses as much data as possible, and stops when the input\r
+  buffer becomes empty or the output buffer becomes full. It may introduce\r
+  some output latency (reading input without producing any output) except when\r
+  forced to flush.\r
+\r
+  The detailed semantics are as follows. inflate performs one or both of the\r
+  following actions:\r
+\r
+  - Decompress more input starting at next_in and update next_in and avail_in\r
+    accordingly. If not all input can be processed (because there is not\r
+    enough room in the output buffer), next_in is updated and processing\r
+    will resume at this point for the next call of inflate().\r
+\r
+  - Provide more output starting at next_out and update next_out and avail_out\r
+    accordingly.  inflate() provides as much output as possible, until there\r
+    is no more input data or no more space in the output buffer (see below\r
+    about the flush parameter).\r
+\r
+  Before the call of inflate(), the application should ensure that at least\r
+  one of the actions is possible, by providing more input and/or consuming\r
+  more output, and updating the next_* and avail_* values accordingly.\r
+  The application can consume the uncompressed output when it wants, for\r
+  example when the output buffer is full (avail_out == 0), or after each\r
+  call of inflate(). If inflate returns Z_OK and with zero avail_out, it\r
+  must be called again after making room in the output buffer because there\r
+  might be more output pending.\r
+\r
+    The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,\r
+  Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much\r
+  output as possible to the output buffer. Z_BLOCK requests that inflate() stop\r
+  if and when it gets to the next deflate block boundary. When decoding the\r
+  zlib or gzip format, this will cause inflate() to return immediately after\r
+  the header and before the first block. When doing a raw inflate, inflate()\r
+  will go ahead and process the first block, and will return when it gets to\r
+  the end of that block, or when it runs out of data.\r
+\r
+    The Z_BLOCK option assists in appending to or combining deflate streams.\r
+  Also to assist in this, on return inflate() will set strm->data_type to the\r
+  number of unused bits in the last byte taken from strm->next_in, plus 64\r
+  if inflate() is currently decoding the last block in the deflate stream,\r
+  plus 128 if inflate() returned immediately after decoding an end-of-block\r
+  code or decoding the complete header up to just before the first byte of the\r
+  deflate stream. The end-of-block will not be indicated until all of the\r
+  uncompressed data from that block has been written to strm->next_out.  The\r
+  number of unused bits may in general be greater than seven, except when\r
+  bit 7 of data_type is set, in which case the number of unused bits will be\r
+  less than eight.\r
+\r
+    inflate() should normally be called until it returns Z_STREAM_END or an\r
+  error. However if all decompression is to be performed in a single step\r
+  (a single call of inflate), the parameter flush should be set to\r
+  Z_FINISH. In this case all pending input is processed and all pending\r
+  output is flushed; avail_out must be large enough to hold all the\r
+  uncompressed data. (The size of the uncompressed data may have been saved\r
+  by the compressor for this purpose.) The next operation on this stream must\r
+  be inflateEnd to deallocate the decompression state. The use of Z_FINISH\r
+  is never required, but can be used to inform inflate that a faster approach\r
+  may be used for the single inflate() call.\r
+\r
+     In this implementation, inflate() always flushes as much output as\r
+  possible to the output buffer, and always uses the faster approach on the\r
+  first call. So the only effect of the flush parameter in this implementation\r
+  is on the return value of inflate(), as noted below, or when it returns early\r
+  because Z_BLOCK is used.\r
+\r
+     If a preset dictionary is needed after this call (see inflateSetDictionary\r
+  below), inflate sets strm->adler to the adler32 checksum of the dictionary\r
+  chosen by the compressor and returns Z_NEED_DICT; otherwise it sets\r
+  strm->adler to the adler32 checksum of all output produced so far (that is,\r
+  total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described\r
+  below. At the end of the stream, inflate() checks that its computed adler32\r
+  checksum is equal to that saved by the compressor and returns Z_STREAM_END\r
+  only if the checksum is correct.\r
+\r
+    inflate() will decompress and check either zlib-wrapped or gzip-wrapped\r
+  deflate data.  The header type is detected automatically.  Any information\r
+  contained in the gzip header is not retained, so applications that need that\r
+  information should instead use raw inflate, see inflateInit2() below, or\r
+  inflateBack() and perform their own processing of the gzip header and\r
+  trailer.\r
+\r
+    inflate() returns Z_OK if some progress has been made (more input processed\r
+  or more output produced), Z_STREAM_END if the end of the compressed data has\r
+  been reached and all uncompressed output has been produced, Z_NEED_DICT if a\r
+  preset dictionary is needed at this point, Z_DATA_ERROR if the input data was\r
+  corrupted (input stream not conforming to the zlib format or incorrect check\r
+  value), Z_STREAM_ERROR if the stream structure was inconsistent (for example\r
+  if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,\r
+  Z_BUF_ERROR if no progress is possible or if there was not enough room in the\r
+  output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and\r
+  inflate() can be called again with more input and more output space to\r
+  continue decompressing. If Z_DATA_ERROR is returned, the application may then\r
+  call inflateSync() to look for a good compression block if a partial recovery\r
+  of the data is desired.\r
+*/\r
+\r
+\r
+ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));\r
+/*\r
+     All dynamically allocated data structures for this stream are freed.\r
+   This function discards any unprocessed input and does not flush any\r
+   pending output.\r
+\r
+     inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state\r
+   was inconsistent. In the error case, msg may be set but then points to a\r
+   static string (which must not be deallocated).\r
+*/\r
+\r
+                        /* Advanced functions */\r
+\r
+/*\r
+    The following functions are needed only in some special applications.\r
+*/\r
+\r
+/*\r
+ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,\r
+                                     int  level,\r
+                                     int  method,\r
+                                     int  windowBits,\r
+                                     int  memLevel,\r
+                                     int  strategy));\r
+\r
+     This is another version of deflateInit with more compression options. The\r
+   fields next_in, zalloc, zfree and opaque must be initialized before by\r
+   the caller.\r
+\r
+     The method parameter is the compression method. It must be Z_DEFLATED in\r
+   this version of the library.\r
+\r
+     The windowBits parameter is the base two logarithm of the window size\r
+   (the size of the history buffer). It should be in the range 8..15 for this\r
+   version of the library. Larger values of this parameter result in better\r
+   compression at the expense of memory usage. The default value is 15 if\r
+   deflateInit is used instead.\r
+\r
+     windowBits can also be -8..-15 for raw deflate. In this case, -windowBits\r
+   determines the window size. deflate() will then generate raw deflate data\r
+   with no zlib header or trailer, and will not compute an adler32 check value.\r
+\r
+     windowBits can also be greater than 15 for optional gzip encoding. Add\r
+   16 to windowBits to write a simple gzip header and trailer around the\r
+   compressed data instead of a zlib wrapper. The gzip header will have no\r
+   file name, no extra data, no comment, no modification time (set to zero),\r
+   no header crc, and the operating system will be set to 255 (unknown).  If a\r
+   gzip stream is being written, strm->adler is a crc32 instead of an adler32.\r
+\r
+     The memLevel parameter specifies how much memory should be allocated\r
+   for the internal compression state. memLevel=1 uses minimum memory but\r
+   is slow and reduces compression ratio; memLevel=9 uses maximum memory\r
+   for optimal speed. The default value is 8. See zconf.h for total memory\r
+   usage as a function of windowBits and memLevel.\r
+\r
+     The strategy parameter is used to tune the compression algorithm. Use the\r
+   value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a\r
+   filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no\r
+   string match), or Z_RLE to limit match distances to one (run-length\r
+   encoding). Filtered data consists mostly of small values with a somewhat\r
+   random distribution. In this case, the compression algorithm is tuned to\r
+   compress them better. The effect of Z_FILTERED is to force more Huffman\r
+   coding and less string matching; it is somewhat intermediate between\r
+   Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as\r
+   Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy\r
+   parameter only affects the compression ratio but not the correctness of the\r
+   compressed output even if it is not set appropriately.  Z_FIXED prevents the\r
+   use of dynamic Huffman codes, allowing for a simpler decoder for special\r
+   applications.\r
+\r
+      deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
+   memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid\r
+   method). msg is set to null if there is no error message.  deflateInit2 does\r
+   not perform any compression: this will be done by deflate().\r
+*/\r
+\r
+ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,\r
+                                             const Bytef *dictionary,\r
+                                             uInt  dictLength));\r
+/*\r
+     Initializes the compression dictionary from the given byte sequence\r
+   without producing any compressed output. This function must be called\r
+   immediately after deflateInit, deflateInit2 or deflateReset, before any\r
+   call of deflate. The compressor and decompressor must use exactly the same\r
+   dictionary (see inflateSetDictionary).\r
+\r
+     The dictionary should consist of strings (byte sequences) that are likely\r
+   to be encountered later in the data to be compressed, with the most commonly\r
+   used strings preferably put towards the end of the dictionary. Using a\r
+   dictionary is most useful when the data to be compressed is short and can be\r
+   predicted with good accuracy; the data can then be compressed better than\r
+   with the default empty dictionary.\r
+\r
+     Depending on the size of the compression data structures selected by\r
+   deflateInit or deflateInit2, a part of the dictionary may in effect be\r
+   discarded, for example if the dictionary is larger than the window size in\r
+   deflate or deflate2. Thus the strings most likely to be useful should be\r
+   put at the end of the dictionary, not at the front. In addition, the\r
+   current implementation of deflate will use at most the window size minus\r
+   262 bytes of the provided dictionary.\r
+\r
+     Upon return of this function, strm->adler is set to the adler32 value\r
+   of the dictionary; the decompressor may later use this value to determine\r
+   which dictionary has been used by the compressor. (The adler32 value\r
+   applies to the whole dictionary even if only a subset of the dictionary is\r
+   actually used by the compressor.) If a raw deflate was requested, then the\r
+   adler32 value is not computed and strm->adler is not set.\r
+\r
+     deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a\r
+   parameter is invalid (such as NULL dictionary) or the stream state is\r
+   inconsistent (for example if deflate has already been called for this stream\r
+   or if the compression method is bsort). deflateSetDictionary does not\r
+   perform any compression: this will be done by deflate().\r
+*/\r
+\r
+ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,\r
+                                    z_streamp source));\r
+/*\r
+     Sets the destination stream as a complete copy of the source stream.\r
+\r
+     This function can be useful when several compression strategies will be\r
+   tried, for example when there are several ways of pre-processing the input\r
+   data with a filter. The streams that will be discarded should then be freed\r
+   by calling deflateEnd.  Note that deflateCopy duplicates the internal\r
+   compression state which can be quite large, so this strategy is slow and\r
+   can consume lots of memory.\r
+\r
+     deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not\r
+   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent\r
+   (such as zalloc being NULL). msg is left unchanged in both source and\r
+   destination.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));\r
+/*\r
+     This function is equivalent to deflateEnd followed by deflateInit,\r
+   but does not free and reallocate all the internal compression state.\r
+   The stream will keep the same compression level and any other attributes\r
+   that may have been set by deflateInit2.\r
+\r
+      deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   stream state was inconsistent (such as zalloc or state being NULL).\r
+*/\r
+\r
+ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,\r
+                                      int level,\r
+                                      int strategy));\r
+/*\r
+     Dynamically update the compression level and compression strategy.  The\r
+   interpretation of level and strategy is as in deflateInit2.  This can be\r
+   used to switch between compression and straight copy of the input data, or\r
+   to switch to a different kind of input data requiring a different\r
+   strategy. If the compression level is changed, the input available so far\r
+   is compressed with the old level (and may be flushed); the new level will\r
+   take effect only at the next call of deflate().\r
+\r
+     Before the call of deflateParams, the stream state must be set as for\r
+   a call of deflate(), since the currently available input may have to\r
+   be compressed and flushed. In particular, strm->avail_out must be non-zero.\r
+\r
+     deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source\r
+   stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR\r
+   if strm->avail_out was zero.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,\r
+                                    int good_length,\r
+                                    int max_lazy,\r
+                                    int nice_length,\r
+                                    int max_chain));\r
+/*\r
+     Fine tune deflate's internal compression parameters.  This should only be\r
+   used by someone who understands the algorithm used by zlib's deflate for\r
+   searching for the best matching string, and even then only by the most\r
+   fanatic optimizer trying to squeeze out the last compressed bit for their\r
+   specific input data.  Read the deflate.c source code for the meaning of the\r
+   max_lazy, good_length, nice_length, and max_chain parameters.\r
+\r
+     deflateTune() can be called after deflateInit() or deflateInit2(), and\r
+   returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.\r
+ */\r
+\r
+ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,\r
+                                       uLong sourceLen));\r
+/*\r
+     deflateBound() returns an upper bound on the compressed size after\r
+   deflation of sourceLen bytes.  It must be called after deflateInit()\r
+   or deflateInit2().  This would be used to allocate an output buffer\r
+   for deflation in a single pass, and so would be called before deflate().\r
+*/\r
+\r
+ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,\r
+                                     int bits,\r
+                                     int value));\r
+/*\r
+     deflatePrime() inserts bits in the deflate output stream.  The intent\r
+  is that this function is used to start off the deflate output with the\r
+  bits leftover from a previous deflate stream when appending to it.  As such,\r
+  this function can only be used for raw deflate, and must be used before the\r
+  first deflate() call after a deflateInit2() or deflateReset().  bits must be\r
+  less than or equal to 16, and that many of the least significant bits of\r
+  value will be inserted in the output.\r
+\r
+      deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   stream state was inconsistent.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,\r
+                                         gz_headerp head));\r
+/*\r
+      deflateSetHeader() provides gzip header information for when a gzip\r
+   stream is requested by deflateInit2().  deflateSetHeader() may be called\r
+   after deflateInit2() or deflateReset() and before the first call of\r
+   deflate().  The text, time, os, extra field, name, and comment information\r
+   in the provided gz_header structure are written to the gzip header (xflag is\r
+   ignored -- the extra flags are set according to the compression level).  The\r
+   caller must assure that, if not Z_NULL, name and comment are terminated with\r
+   a zero byte, and that if extra is not Z_NULL, that extra_len bytes are\r
+   available there.  If hcrc is true, a gzip header crc is included.  Note that\r
+   the current versions of the command-line version of gzip (up through version\r
+   1.3.x) do not support header crc's, and will report that it is a "multi-part\r
+   gzip file" and give up.\r
+\r
+      If deflateSetHeader is not used, the default gzip header has text false,\r
+   the time set to zero, and os set to 255, with no extra, name, or comment\r
+   fields.  The gzip header is returned to the default state by deflateReset().\r
+\r
+      deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   stream state was inconsistent.\r
+*/\r
+\r
+/*\r
+ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,\r
+                                     int  windowBits));\r
+\r
+     This is another version of inflateInit with an extra parameter. The\r
+   fields next_in, avail_in, zalloc, zfree and opaque must be initialized\r
+   before by the caller.\r
+\r
+     The windowBits parameter is the base two logarithm of the maximum window\r
+   size (the size of the history buffer).  It should be in the range 8..15 for\r
+   this version of the library. The default value is 15 if inflateInit is used\r
+   instead. windowBits must be greater than or equal to the windowBits value\r
+   provided to deflateInit2() while compressing, or it must be equal to 15 if\r
+   deflateInit2() was not used. If a compressed stream with a larger window\r
+   size is given as input, inflate() will return with the error code\r
+   Z_DATA_ERROR instead of trying to allocate a larger window.\r
+\r
+     windowBits can also be -8..-15 for raw inflate. In this case, -windowBits\r
+   determines the window size. inflate() will then process raw deflate data,\r
+   not looking for a zlib or gzip header, not generating a check value, and not\r
+   looking for any check values for comparison at the end of the stream. This\r
+   is for use with other formats that use the deflate compressed data format\r
+   such as zip.  Those formats provide their own check values. If a custom\r
+   format is developed using the raw deflate format for compressed data, it is\r
+   recommended that a check value such as an adler32 or a crc32 be applied to\r
+   the uncompressed data as is done in the zlib, gzip, and zip formats.  For\r
+   most applications, the zlib format should be used as is. Note that comments\r
+   above on the use in deflateInit2() applies to the magnitude of windowBits.\r
+\r
+     windowBits can also be greater than 15 for optional gzip decoding. Add\r
+   32 to windowBits to enable zlib and gzip decoding with automatic header\r
+   detection, or add 16 to decode only the gzip format (the zlib format will\r
+   return a Z_DATA_ERROR).  If a gzip stream is being decoded, strm->adler is\r
+   a crc32 instead of an adler32.\r
+\r
+     inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
+   memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg\r
+   is set to null if there is no error message.  inflateInit2 does not perform\r
+   any decompression apart from reading the zlib header if present: this will\r
+   be done by inflate(). (So next_in and avail_in may be modified, but next_out\r
+   and avail_out are unchanged.)\r
+*/\r
+\r
+ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,\r
+                                             const Bytef *dictionary,\r
+                                             uInt  dictLength));\r
+/*\r
+     Initializes the decompression dictionary from the given uncompressed byte\r
+   sequence. This function must be called immediately after a call of inflate,\r
+   if that call returned Z_NEED_DICT. The dictionary chosen by the compressor\r
+   can be determined from the adler32 value returned by that call of inflate.\r
+   The compressor and decompressor must use exactly the same dictionary (see\r
+   deflateSetDictionary).  For raw inflate, this function can be called\r
+   immediately after inflateInit2() or inflateReset() and before any call of\r
+   inflate() to set the dictionary.  The application must insure that the\r
+   dictionary that was used for compression is provided.\r
+\r
+     inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a\r
+   parameter is invalid (such as NULL dictionary) or the stream state is\r
+   inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the\r
+   expected one (incorrect adler32 value). inflateSetDictionary does not\r
+   perform any decompression: this will be done by subsequent calls of\r
+   inflate().\r
+*/\r
+\r
+ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));\r
+/*\r
+    Skips invalid compressed data until a full flush point (see above the\r
+  description of deflate with Z_FULL_FLUSH) can be found, or until all\r
+  available input is skipped. No output is provided.\r
+\r
+    inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR\r
+  if no more input was provided, Z_DATA_ERROR if no flush point has been found,\r
+  or Z_STREAM_ERROR if the stream structure was inconsistent. In the success\r
+  case, the application may save the current current value of total_in which\r
+  indicates where valid compressed data was found. In the error case, the\r
+  application may repeatedly call inflateSync, providing more input each time,\r
+  until success or end of the input data.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,\r
+                                    z_streamp source));\r
+/*\r
+     Sets the destination stream as a complete copy of the source stream.\r
+\r
+     This function can be useful when randomly accessing a large stream.  The\r
+   first pass through the stream can periodically record the inflate state,\r
+   allowing restarting inflate at those points when randomly accessing the\r
+   stream.\r
+\r
+     inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not\r
+   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent\r
+   (such as zalloc being NULL). msg is left unchanged in both source and\r
+   destination.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));\r
+/*\r
+     This function is equivalent to inflateEnd followed by inflateInit,\r
+   but does not free and reallocate all the internal decompression state.\r
+   The stream will keep attributes that may have been set by inflateInit2.\r
+\r
+      inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   stream state was inconsistent (such as zalloc or state being NULL).\r
+*/\r
+\r
+ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,\r
+                                     int bits,\r
+                                     int value));\r
+/*\r
+     This function inserts bits in the inflate input stream.  The intent is\r
+  that this function is used to start inflating at a bit position in the\r
+  middle of a byte.  The provided bits will be used before any bytes are used\r
+  from next_in.  This function should only be used with raw inflate, and\r
+  should be used before the first inflate() call after inflateInit2() or\r
+  inflateReset().  bits must be less than or equal to 16, and that many of the\r
+  least significant bits of value will be inserted in the input.\r
+\r
+      inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   stream state was inconsistent.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,\r
+                                         gz_headerp head));\r
+/*\r
+      inflateGetHeader() requests that gzip header information be stored in the\r
+   provided gz_header structure.  inflateGetHeader() may be called after\r
+   inflateInit2() or inflateReset(), and before the first call of inflate().\r
+   As inflate() processes the gzip stream, head->done is zero until the header\r
+   is completed, at which time head->done is set to one.  If a zlib stream is\r
+   being decoded, then head->done is set to -1 to indicate that there will be\r
+   no gzip header information forthcoming.  Note that Z_BLOCK can be used to\r
+   force inflate() to return immediately after header processing is complete\r
+   and before any actual data is decompressed.\r
+\r
+      The text, time, xflags, and os fields are filled in with the gzip header\r
+   contents.  hcrc is set to true if there is a header CRC.  (The header CRC\r
+   was valid if done is set to one.)  If extra is not Z_NULL, then extra_max\r
+   contains the maximum number of bytes to write to extra.  Once done is true,\r
+   extra_len contains the actual extra field length, and extra contains the\r
+   extra field, or that field truncated if extra_max is less than extra_len.\r
+   If name is not Z_NULL, then up to name_max characters are written there,\r
+   terminated with a zero unless the length is greater than name_max.  If\r
+   comment is not Z_NULL, then up to comm_max characters are written there,\r
+   terminated with a zero unless the length is greater than comm_max.  When\r
+   any of extra, name, or comment are not Z_NULL and the respective field is\r
+   not present in the header, then that field is set to Z_NULL to signal its\r
+   absence.  This allows the use of deflateSetHeader() with the returned\r
+   structure to duplicate the header.  However if those fields are set to\r
+   allocated memory, then the application will need to save those pointers\r
+   elsewhere so that they can be eventually freed.\r
+\r
+      If inflateGetHeader is not used, then the header information is simply\r
+   discarded.  The header is always checked for validity, including the header\r
+   CRC if present.  inflateReset() will reset the process to discard the header\r
+   information.  The application would need to call inflateGetHeader() again to\r
+   retrieve the header from the next gzip stream.\r
+\r
+      inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source\r
+   stream state was inconsistent.\r
+*/\r
+\r
+/*\r
+ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,\r
+                                        unsigned char FAR *window));\r
+\r
+     Initialize the internal stream state for decompression using inflateBack()\r
+   calls.  The fields zalloc, zfree and opaque in strm must be initialized\r
+   before the call.  If zalloc and zfree are Z_NULL, then the default library-\r
+   derived memory allocation routines are used.  windowBits is the base two\r
+   logarithm of the window size, in the range 8..15.  window is a caller\r
+   supplied buffer of that size.  Except for special applications where it is\r
+   assured that deflate was used with small window sizes, windowBits must be 15\r
+   and a 32K byte window must be supplied to be able to decompress general\r
+   deflate streams.\r
+\r
+     See inflateBack() for the usage of these routines.\r
+\r
+     inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of\r
+   the paramaters are invalid, Z_MEM_ERROR if the internal state could not\r
+   be allocated, or Z_VERSION_ERROR if the version of the library does not\r
+   match the version of the header file.\r
+*/\r
+\r
+typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));\r
+typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));\r
+\r
+ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,\r
+                                    in_func in, void FAR *in_desc,\r
+                                    out_func out, void FAR *out_desc));\r
+/*\r
+     inflateBack() does a raw inflate with a single call using a call-back\r
+   interface for input and output.  This is more efficient than inflate() for\r
+   file i/o applications in that it avoids copying between the output and the\r
+   sliding window by simply making the window itself the output buffer.  This\r
+   function trusts the application to not change the output buffer passed by\r
+   the output function, at least until inflateBack() returns.\r
+\r
+     inflateBackInit() must be called first to allocate the internal state\r
+   and to initialize the state with the user-provided window buffer.\r
+   inflateBack() may then be used multiple times to inflate a complete, raw\r
+   deflate stream with each call.  inflateBackEnd() is then called to free\r
+   the allocated state.\r
+\r
+     A raw deflate stream is one with no zlib or gzip header or trailer.\r
+   This routine would normally be used in a utility that reads zip or gzip\r
+   files and writes out uncompressed files.  The utility would decode the\r
+   header and process the trailer on its own, hence this routine expects\r
+   only the raw deflate stream to decompress.  This is different from the\r
+   normal behavior of inflate(), which expects either a zlib or gzip header and\r
+   trailer around the deflate stream.\r
+\r
+     inflateBack() uses two subroutines supplied by the caller that are then\r
+   called by inflateBack() for input and output.  inflateBack() calls those\r
+   routines until it reads a complete deflate stream and writes out all of the\r
+   uncompressed data, or until it encounters an error.  The function's\r
+   parameters and return types are defined above in the in_func and out_func\r
+   typedefs.  inflateBack() will call in(in_desc, &buf) which should return the\r
+   number of bytes of provided input, and a pointer to that input in buf.  If\r
+   there is no input available, in() must return zero--buf is ignored in that\r
+   case--and inflateBack() will return a buffer error.  inflateBack() will call\r
+   out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].  out()\r
+   should return zero on success, or non-zero on failure.  If out() returns\r
+   non-zero, inflateBack() will return with an error.  Neither in() nor out()\r
+   are permitted to change the contents of the window provided to\r
+   inflateBackInit(), which is also the buffer that out() uses to write from.\r
+   The length written by out() will be at most the window size.  Any non-zero\r
+   amount of input may be provided by in().\r
+\r
+     For convenience, inflateBack() can be provided input on the first call by\r
+   setting strm->next_in and strm->avail_in.  If that input is exhausted, then\r
+   in() will be called.  Therefore strm->next_in must be initialized before\r
+   calling inflateBack().  If strm->next_in is Z_NULL, then in() will be called\r
+   immediately for input.  If strm->next_in is not Z_NULL, then strm->avail_in\r
+   must also be initialized, and then if strm->avail_in is not zero, input will\r
+   initially be taken from strm->next_in[0 .. strm->avail_in - 1].\r
+\r
+     The in_desc and out_desc parameters of inflateBack() is passed as the\r
+   first parameter of in() and out() respectively when they are called.  These\r
+   descriptors can be optionally used to pass any information that the caller-\r
+   supplied in() and out() functions need to do their job.\r
+\r
+     On return, inflateBack() will set strm->next_in and strm->avail_in to\r
+   pass back any unused input that was provided by the last in() call.  The\r
+   return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR\r
+   if in() or out() returned an error, Z_DATA_ERROR if there was a format\r
+   error in the deflate stream (in which case strm->msg is set to indicate the\r
+   nature of the error), or Z_STREAM_ERROR if the stream was not properly\r
+   initialized.  In the case of Z_BUF_ERROR, an input or output error can be\r
+   distinguished using strm->next_in which will be Z_NULL only if in() returned\r
+   an error.  If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to\r
+   out() returning non-zero.  (in() will always be called before out(), so\r
+   strm->next_in is assured to be defined if out() returns non-zero.)  Note\r
+   that inflateBack() cannot return Z_OK.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));\r
+/*\r
+     All memory allocated by inflateBackInit() is freed.\r
+\r
+     inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream\r
+   state was inconsistent.\r
+*/\r
+\r
+ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));\r
+/* Return flags indicating compile-time options.\r
+\r
+    Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:\r
+     1.0: size of uInt\r
+     3.2: size of uLong\r
+     5.4: size of voidpf (pointer)\r
+     7.6: size of z_off_t\r
+\r
+    Compiler, assembler, and debug options:\r
+     8: DEBUG\r
+     9: ASMV or ASMINF -- use ASM code\r
+     10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention\r
+     11: 0 (reserved)\r
+\r
+    One-time table building (smaller code, but not thread-safe if true):\r
+     12: BUILDFIXED -- build static block decoding tables when needed\r
+     13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed\r
+     14,15: 0 (reserved)\r
+\r
+    Library content (indicates missing functionality):\r
+     16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking\r
+                          deflate code when not needed)\r
+     17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect\r
+                    and decode gzip streams (to avoid linking crc code)\r
+     18-19: 0 (reserved)\r
+\r
+    Operation variations (changes in library functionality):\r
+     20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate\r
+     21: FASTEST -- deflate algorithm with only one, lowest compression level\r
+     22,23: 0 (reserved)\r
+\r
+    The sprintf variant used by gzprintf (zero is best):\r
+     24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format\r
+     25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!\r
+     26: 0 = returns value, 1 = void -- 1 means inferred string length returned\r
+\r
+    Remainder:\r
+     27-31: 0 (reserved)\r
+ */\r
+\r
+\r
+                        /* utility functions */\r
+\r
+/*\r
+     The following utility functions are implemented on top of the\r
+   basic stream-oriented functions. To simplify the interface, some\r
+   default options are assumed (compression level and memory usage,\r
+   standard memory allocation functions). The source code of these\r
+   utility functions can easily be modified if you need special options.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,\r
+                                 const Bytef *source, uLong sourceLen));\r
+/*\r
+     Compresses the source buffer into the destination buffer.  sourceLen is\r
+   the byte length of the source buffer. Upon entry, destLen is the total\r
+   size of the destination buffer, which must be at least the value returned\r
+   by compressBound(sourceLen). Upon exit, destLen is the actual size of the\r
+   compressed buffer.\r
+     This function can be used to compress a whole file at once if the\r
+   input file is mmap'ed.\r
+     compress returns Z_OK if success, Z_MEM_ERROR if there was not\r
+   enough memory, Z_BUF_ERROR if there was not enough room in the output\r
+   buffer.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,\r
+                                  const Bytef *source, uLong sourceLen,\r
+                                  int level));\r
+/*\r
+     Compresses the source buffer into the destination buffer. The level\r
+   parameter has the same meaning as in deflateInit.  sourceLen is the byte\r
+   length of the source buffer. Upon entry, destLen is the total size of the\r
+   destination buffer, which must be at least the value returned by\r
+   compressBound(sourceLen). Upon exit, destLen is the actual size of the\r
+   compressed buffer.\r
+\r
+     compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough\r
+   memory, Z_BUF_ERROR if there was not enough room in the output buffer,\r
+   Z_STREAM_ERROR if the level parameter is invalid.\r
+*/\r
+\r
+ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));\r
+/*\r
+     compressBound() returns an upper bound on the compressed size after\r
+   compress() or compress2() on sourceLen bytes.  It would be used before\r
+   a compress() or compress2() call to allocate the destination buffer.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,\r
+                                   const Bytef *source, uLong sourceLen));\r
+/*\r
+     Decompresses the source buffer into the destination buffer.  sourceLen is\r
+   the byte length of the source buffer. Upon entry, destLen is the total\r
+   size of the destination buffer, which must be large enough to hold the\r
+   entire uncompressed data. (The size of the uncompressed data must have\r
+   been saved previously by the compressor and transmitted to the decompressor\r
+   by some mechanism outside the scope of this compression library.)\r
+   Upon exit, destLen is the actual size of the compressed buffer.\r
+     This function can be used to decompress a whole file at once if the\r
+   input file is mmap'ed.\r
+\r
+     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not\r
+   enough memory, Z_BUF_ERROR if there was not enough room in the output\r
+   buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.\r
+*/\r
+\r
+\r
+typedef voidp gzFile;\r
+\r
+ZEXTERN gzFile ZEXPORT gzopen  OF((const char *path, const char *mode));\r
+/*\r
+     Opens a gzip (.gz) file for reading or writing. The mode parameter\r
+   is as in fopen ("rb" or "wb") but can also include a compression level\r
+   ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for\r
+   Huffman only compression as in "wb1h", or 'R' for run-length encoding\r
+   as in "wb1R". (See the description of deflateInit2 for more information\r
+   about the strategy parameter.)\r
+\r
+     gzopen can be used to read a file which is not in gzip format; in this\r
+   case gzread will directly read from the file without decompression.\r
+\r
+     gzopen returns NULL if the file could not be opened or if there was\r
+   insufficient memory to allocate the (de)compression state; errno\r
+   can be checked to distinguish the two cases (if errno is zero, the\r
+   zlib error is Z_MEM_ERROR).  */\r
+\r
+ZEXTERN gzFile ZEXPORT gzdopen  OF((int fd, const char *mode));\r
+/*\r
+     gzdopen() associates a gzFile with the file descriptor fd.  File\r
+   descriptors are obtained from calls like open, dup, creat, pipe or\r
+   fileno (in the file has been previously opened with fopen).\r
+   The mode parameter is as in gzopen.\r
+     The next call of gzclose on the returned gzFile will also close the\r
+   file descriptor fd, just like fclose(fdopen(fd), mode) closes the file\r
+   descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).\r
+     gzdopen returns NULL if there was insufficient memory to allocate\r
+   the (de)compression state.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));\r
+/*\r
+     Dynamically update the compression level or strategy. See the description\r
+   of deflateInit2 for the meaning of these parameters.\r
+     gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not\r
+   opened for writing.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));\r
+/*\r
+     Reads the given number of uncompressed bytes from the compressed file.\r
+   If the input file was not in gzip format, gzread copies the given number\r
+   of bytes into the buffer.\r
+     gzread returns the number of uncompressed bytes actually read (0 for\r
+   end of file, -1 for error). */\r
+\r
+ZEXTERN int ZEXPORT    gzwrite OF((gzFile file,\r
+                                   voidpc buf, unsigned len));\r
+/*\r
+     Writes the given number of uncompressed bytes into the compressed file.\r
+   gzwrite returns the number of uncompressed bytes actually written\r
+   (0 in case of error).\r
+*/\r
+\r
+ZEXTERN int ZEXPORTVA   gzprintf OF((gzFile file, const char *format, ...));\r
+/*\r
+     Converts, formats, and writes the args to the compressed file under\r
+   control of the format string, as in fprintf. gzprintf returns the number of\r
+   uncompressed bytes actually written (0 in case of error).  The number of\r
+   uncompressed bytes written is limited to 4095. The caller should assure that\r
+   this limit is not exceeded. If it is exceeded, then gzprintf() will return\r
+   return an error (0) with nothing written. In this case, there may also be a\r
+   buffer overflow with unpredictable consequences, which is possible only if\r
+   zlib was compiled with the insecure functions sprintf() or vsprintf()\r
+   because the secure snprintf() or vsnprintf() functions were not available.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));\r
+/*\r
+      Writes the given null-terminated string to the compressed file, excluding\r
+   the terminating null character.\r
+      gzputs returns the number of characters written, or -1 in case of error.\r
+*/\r
+\r
+ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));\r
+/*\r
+      Reads bytes from the compressed file until len-1 characters are read, or\r
+   a newline character is read and transferred to buf, or an end-of-file\r
+   condition is encountered.  The string is then terminated with a null\r
+   character.\r
+      gzgets returns buf, or Z_NULL in case of error.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT    gzputc OF((gzFile file, int c));\r
+/*\r
+      Writes c, converted to an unsigned char, into the compressed file.\r
+   gzputc returns the value that was written, or -1 in case of error.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT    gzgetc OF((gzFile file));\r
+/*\r
+      Reads one byte from the compressed file. gzgetc returns this byte\r
+   or -1 in case of end of file or error.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT    gzungetc OF((int c, gzFile file));\r
+/*\r
+      Push one character back onto the stream to be read again later.\r
+   Only one character of push-back is allowed.  gzungetc() returns the\r
+   character pushed, or -1 on failure.  gzungetc() will fail if a\r
+   character has been pushed but not read yet, or if c is -1. The pushed\r
+   character will be discarded if the stream is repositioned with gzseek()\r
+   or gzrewind().\r
+*/\r
+\r
+ZEXTERN int ZEXPORT    gzflush OF((gzFile file, int flush));\r
+/*\r
+     Flushes all pending output into the compressed file. The parameter\r
+   flush is as in the deflate() function. The return value is the zlib\r
+   error number (see function gzerror below). gzflush returns Z_OK if\r
+   the flush parameter is Z_FINISH and all output could be flushed.\r
+     gzflush should be called only when strictly necessary because it can\r
+   degrade compression.\r
+*/\r
+\r
+ZEXTERN z_off_t ZEXPORT    gzseek OF((gzFile file,\r
+                                      z_off_t offset, int whence));\r
+/*\r
+      Sets the starting position for the next gzread or gzwrite on the\r
+   given compressed file. The offset represents a number of bytes in the\r
+   uncompressed data stream. The whence parameter is defined as in lseek(2);\r
+   the value SEEK_END is not supported.\r
+     If the file is opened for reading, this function is emulated but can be\r
+   extremely slow. If the file is opened for writing, only forward seeks are\r
+   supported; gzseek then compresses a sequence of zeroes up to the new\r
+   starting position.\r
+\r
+      gzseek returns the resulting offset location as measured in bytes from\r
+   the beginning of the uncompressed stream, or -1 in case of error, in\r
+   particular if the file is opened for writing and the new starting position\r
+   would be before the current position.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT    gzrewind OF((gzFile file));\r
+/*\r
+     Rewinds the given file. This function is supported only for reading.\r
+\r
+   gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)\r
+*/\r
+\r
+ZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));\r
+/*\r
+     Returns the starting position for the next gzread or gzwrite on the\r
+   given compressed file. This position represents a number of bytes in the\r
+   uncompressed data stream.\r
+\r
+   gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)\r
+*/\r
+\r
+ZEXTERN int ZEXPORT gzeof OF((gzFile file));\r
+/*\r
+     Returns 1 when EOF has previously been detected reading the given\r
+   input stream, otherwise zero.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT gzdirect OF((gzFile file));\r
+/*\r
+     Returns 1 if file is being read directly without decompression, otherwise\r
+   zero.\r
+*/\r
+\r
+ZEXTERN int ZEXPORT    gzclose OF((gzFile file));\r
+/*\r
+     Flushes all pending output if necessary, closes the compressed file\r
+   and deallocates all the (de)compression state. The return value is the zlib\r
+   error number (see function gzerror below).\r
+*/\r
+\r
+ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));\r
+/*\r
+     Returns the error message for the last error which occurred on the\r
+   given compressed file. errnum is set to zlib error number. If an\r
+   error occurred in the file system and not in the compression library,\r
+   errnum is set to Z_ERRNO and the application may consult errno\r
+   to get the exact error code.\r
+*/\r
+\r
+ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));\r
+/*\r
+     Clears the error and end-of-file flags for file. This is analogous to the\r
+   clearerr() function in stdio. This is useful for continuing to read a gzip\r
+   file that is being written concurrently.\r
+*/\r
+\r
+                        /* checksum functions */\r
+\r
+/*\r
+     These functions are not related to compression but are exported\r
+   anyway because they might be useful in applications using the\r
+   compression library.\r
+*/\r
+\r
+ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));\r
+/*\r
+     Update a running Adler-32 checksum with the bytes buf[0..len-1] and\r
+   return the updated checksum. If buf is NULL, this function returns\r
+   the required initial value for the checksum.\r
+   An Adler-32 checksum is almost as reliable as a CRC32 but can be computed\r
+   much faster. Usage example:\r
+\r
+     uLong adler = adler32(0L, Z_NULL, 0);\r
+\r
+     while (read_buffer(buffer, length) != EOF) {\r
+       adler = adler32(adler, buffer, length);\r
+     }\r
+     if (adler != original_adler) error();\r
+*/\r
+\r
+ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,\r
+                                          z_off_t len2));\r
+/*\r
+     Combine two Adler-32 checksums into one.  For two sequences of bytes, seq1\r
+   and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for\r
+   each, adler1 and adler2.  adler32_combine() returns the Adler-32 checksum of\r
+   seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.\r
+*/\r
+\r
+ZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));\r
+/*\r
+     Update a running CRC-32 with the bytes buf[0..len-1] and return the\r
+   updated CRC-32. If buf is NULL, this function returns the required initial\r
+   value for the for the crc. Pre- and post-conditioning (one's complement) is\r
+   performed within this function so it shouldn't be done by the application.\r
+   Usage example:\r
+\r
+     uLong crc = crc32(0L, Z_NULL, 0);\r
+\r
+     while (read_buffer(buffer, length) != EOF) {\r
+       crc = crc32(crc, buffer, length);\r
+     }\r
+     if (crc != original_crc) error();\r
+*/\r
+\r
+ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));\r
+\r
+/*\r
+     Combine two CRC-32 check values into one.  For two sequences of bytes,\r
+   seq1 and seq2 with lengths len1 and len2, CRC-32 check values were\r
+   calculated for each, crc1 and crc2.  crc32_combine() returns the CRC-32\r
+   check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and\r
+   len2.\r
+*/\r
+\r
+\r
+                        /* various hacks, don't look :) */\r
+\r
+/* deflateInit and inflateInit are macros to allow checking the zlib version\r
+ * and the compiler's view of z_stream:\r
+ */\r
+ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,\r
+                                     const char *version, int stream_size));\r
+ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,\r
+                                     const char *version, int stream_size));\r
+ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,\r
+                                      int windowBits, int memLevel,\r
+                                      int strategy, const char *version,\r
+                                      int stream_size));\r
+ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,\r
+                                      const char *version, int stream_size));\r
+ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,\r
+                                         unsigned char FAR *window,\r
+                                         const char *version,\r
+                                         int stream_size));\r
+#define deflateInit(strm, level) \\r
+        deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))\r
+#define inflateInit(strm) \\r
+        inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))\r
+#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \\r
+        deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\\r
+                      (strategy),           ZLIB_VERSION, sizeof(z_stream))\r
+#define inflateInit2(strm, windowBits) \\r
+        inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))\r
+#define inflateBackInit(strm, windowBits, window) \\r
+        inflateBackInit_((strm), (windowBits), (window), \\r
+        ZLIB_VERSION, sizeof(z_stream))\r
+\r
+\r
+#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)\r
+    struct internal_state {int dummy;}; /* hack for buggy compilers */\r
+#endif\r
+\r
+ZEXTERN const char   * ZEXPORT zError           OF((int));\r
+ZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp z));\r
+ZEXTERN const uLongf * ZEXPORT get_crc_table    OF((void));\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* ZLIB_H */\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/Sen/Sen.h b/utvpn/utvpn-unix-v101-7101-public/src/Sen/Sen.h
new file mode 100644 (file)
index 0000000..55cee93
--- /dev/null
@@ -0,0 +1,293 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// as published by the Free Software Foundation; either version 2\r
+// of the License, or (at your option) any later version.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// 本ソフトウェアを本オープンソース・プロジェクトの運営主体以外が改変した場合、\r
+// それを複製、配布、販売することは GPL ライセンスに基づいて可能ですが、\r
+// その場合、"SoftEther UT-VPN" の名前を勝手に騙り使用することはできません。\r
+// 事前にソフトイーサ株式会社に許諾を求めるか、または、別の名称として\r
+// ソフトウェアを配布、販売してください。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// 不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+/*\r
+**   File Name: Sen.h\r
+** Description: Sen.c のヘッダ\r
+*/\r
+\r
+#ifndef        SEN_H\r
+#define        SEN_H\r
+\r
+\r
+// 識別文字列 (NDIS)\r
+#define        NDIS_SEN_HARDWARE_ID                            "VPN Client Adapter - %s"\r
+#define        NDIS_SEN_DEVICE_NAME                            "\\Device\\SEN_%s_DEVICE"\r
+#define        NDIS_SEN_DEVICE_NAME_WIN32                      "\\DosDevices\\SEN_%s_DEVICE"\r
+#define        NDIS_SEN_DEVICE_FILE_NAME                       "\\\\.\\SEN_SENADAPTER_%s_DEVICE"\r
+#define        NDIS_SEN_EVENT_NAME                                     "\\BaseNamedObjects\\SEN_EVENT_%s"\r
+#define        NDIS_SEN_EVENT_NAME_WIN32                       "Global\\SEN_EVENT_SENADAPTER_%s"\r
+\r
+// 定数\r
+#define        SEN_MAX_PACKET_SIZE                     1560\r
+#define        SEN_MAX_PACKET_SIZE_ANNOUNCE    1514\r
+#define        SEN_MIN_PACKET_SIZE                     14\r
+#define        SEN_PACKET_HEADER_SIZE          14\r
+#define        SEN_MAX_FRAME_SIZE                      (SEN_MAX_PACKET_SIZE - SEN_MIN_PACKET_SIZE)\r
+#define        SEN_MAX_SPEED_DEFAULT           1000000\r
+#define        SEN_MAC_ADDRESS_SIZE            6\r
+#define        SEN_MAX_MULTICASE                       32\r
+\r
+\r
+// IOCTL 定数\r
+#define        SEN_IOCTL_SET_EVENT                     CTL_CODE(0x8000, 0, METHOD_BUFFERED, FILE_ANY_ACCESS)\r
+#define        SEN_IOCTL_PUT_PACKET            CTL_CODE(0x8000, 1, METHOD_BUFFERED, FILE_ANY_ACCESS)\r
+#define        SEN_IOCTL_GET_PACKET            CTL_CODE(0x8000, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)\r
+\r
+\r
+// パケットデータ交換関係\r
+#define        SEN_MAX_PACKET_EXCHANGE         256                     // 一度に交換できるパケット数\r
+#define        SEN_MAX_PACKET_QUEUED           4096            // キューに入れることができるパケット数\r
+#define        SEN_EX_SIZEOF_NUM_PACKET        4                       // パケット数データ (UINT)\r
+#define        SEN_EX_SIZEOF_LENGTH_PACKET     4                       // パケットデータの長さデータ (UINT)\r
+#define        SEN_EX_SIZEOF_LEFT_FLAG         4                       // まだパケットが残っていることを示すフラグ\r
+#define        SEN_EX_SIZEOF_ONE_PACKET        1600            // 1 つのパケットデータが占有するデータ領域\r
+#define        SEN_EXCHANGE_BUFFER_SIZE        (SEN_EX_SIZEOF_NUM_PACKET + SEN_EX_SIZEOF_LEFT_FLAG +   \\r
+       (SEN_EX_SIZEOF_LENGTH_PACKET + SEN_EX_SIZEOF_ONE_PACKET) * (SEN_MAX_PACKET_EXCHANGE + 1))\r
+#define        SEN_NUM_PACKET(buf)                     (*((UINT *)((UCHAR *)buf + 0)))\r
+#define        SEN_SIZE_OF_PACKET(buf, i)      (*((UINT *)((UCHAR *)buf + SEN_EX_SIZEOF_NUM_PACKET + \\r
+                                                                       (i * (SEN_EX_SIZEOF_LENGTH_PACKET + SEN_EX_SIZEOF_ONE_PACKET)))))\r
+#define        SEN_ADDR_OF_PACKET(buf, i)      (((UINT *)((UCHAR *)buf + SEN_EX_SIZEOF_NUM_PACKET + \\r
+                                                                       SEN_EX_SIZEOF_LENGTH_PACKET +   \\r
+                                                                       (i * (SEN_EX_SIZEOF_LENGTH_PACKET + SEN_EX_SIZEOF_ONE_PACKET)))))\r
+#define        SEN_LEFT_FLAG(buf)                      SEN_SIZE_OF_PACKET(buf, SEN_MAX_PACKET_EXCHANGE)\r
+\r
+\r
+\r
+// デバイスドライバとしてコンパイルする際に必要な定義\r
+#ifdef SEN_DEVICE_DRIVER\r
+\r
+// OS 判定\r
+#ifdef WIN32\r
+#define        OS_WIN32        // Microsoft Windows\r
+#else\r
+#define        OS_UNIX         // UNIX / Linux\r
+#endif\r
+\r
+\r
+// 型宣言\r
+#ifndef        WINDOWS_H_INCLUDED\r
+#ifndef        WIN9X\r
+typedef        unsigned long           BOOL;\r
+#endif // WIN9X\r
+#define        TRUE                            1\r
+#define        FALSE                           0\r
+#endif\r
+typedef        unsigned long           bool;\r
+#define        true                            1\r
+#define        false                           0\r
+typedef        unsigned long long      UINT64;\r
+typedef        signed long long        INT64;\r
+typedef        unsigned short          WORD;\r
+typedef        unsigned short          USHORT;\r
+typedef        signed short            SHORT;\r
+typedef        unsigned char           BYTE;\r
+typedef        unsigned char           UCHAR;\r
+typedef signed char                    CHAR;\r
+typedef        unsigned long           DWORD;\r
+#define        INFINITE                        0xFFFFFFFF\r
+\r
+#define        LESS(a, max_value)      ((a) < (max_value) ? (a) : (max_value))\r
+#define        MORE(a, min_value)      ((a) > (min_value) ? (a) : (min_value))\r
+#define        INNER(a, b, c)          (((b) <= (c) && (a) >= (b) && (a) <= (c)) || ((b) >= (c) && (a) >= (c) && (a) <= (b)))\r
+#define        OUTER(a, b, c)          (!INNER((a), (b), (c)))\r
+#define        MAKESURE(a, b, c)               (((b) <= (c)) ? (MORE(LESS((a), (c)), (b))) : (MORE(LESS((a), (b)), (c))))\r
+#define        MIN(a, b)                       ((a) >= (b) ? (b) : (a))\r
+#define        MAX(a, b)                       ((a) >= (b) ? (a) : (b))\r
+\r
+#ifdef OS_WIN32\r
+// NDIS 5.0 関係\r
+#include "NDIS5.h"\r
+#endif // OS_WIN32\r
+\r
+// ロック\r
+typedef struct _SEN_LOCK\r
+{\r
+#ifdef OS_WIN32\r
+       NDIS_SPIN_LOCK spin_lock;\r
+#endif\r
+} SEN_LOCK;\r
+\r
+// イベント\r
+typedef struct _SEN_EVENT\r
+{\r
+#ifdef OS_WIN32\r
+#ifndef        WIN9X\r
+       KEVENT *event;\r
+       HANDLE event_handle;\r
+#else  // WIN9X\r
+       DWORD win32_event;\r
+#endif // WIN9X\r
+#endif\r
+} SEN_EVENT;\r
+\r
+// パケットキュー\r
+typedef struct _SEN_QUEUE\r
+{\r
+       struct _SEN_QUEUE *Next;\r
+       UINT Size;\r
+       void *Buf;\r
+} SEN_QUEUE;\r
+\r
+// ステータス\r
+typedef struct _SEN_STATUS\r
+{\r
+       UINT NumPacketSend;\r
+       UINT NumPacketRecv;\r
+       UINT NumPacketSendError;\r
+       UINT NumPacketRecvError;\r
+       UINT NumPacketRecvNoBuffer;\r
+} SEN_STATUS;\r
+\r
+// NDIS パケットバッファ\r
+typedef struct _PACKET_BUFFER\r
+{\r
+       void *Buf;                                                      // バッファ\r
+       NDIS_PACKET *NdisPacket;                        // NDIS パケット\r
+       NDIS_BUFFER *NdisBuffer;                        // NDIS パケットバッファ\r
+       NDIS_HANDLE PacketPool;                         // パケットプール\r
+       NDIS_HANDLE BufferPool;                         // バッファプール\r
+} PACKET_BUFFER;\r
+\r
+// コンテキスト\r
+typedef struct _SEN_CTX\r
+{\r
+       SEN_EVENT *Event;                                       // パケット受信通知イベント\r
+       BOOL Opened;                                            // Open されているか否かのフラグ\r
+       BOOL Inited;                                            // 初期化フラグ\r
+       BOOL Initing;                                           // 起動中フラグ\r
+       volatile BOOL Halting;                          // 停止中フラグ\r
+       BYTE MacAddress[6];                                     // MAC アドレス\r
+       BYTE padding[2];                                        // padding\r
+       SEN_QUEUE *PacketQueue;                         // 送信パケットキュー\r
+       SEN_QUEUE *Tail;                                        // 送信パケットキューの末尾\r
+       UINT NumPacketQueue;                            // パケットキュー数\r
+       SEN_LOCK *PacketQueueLock;                      // 送信パケットキュー用ロック\r
+       SEN_STATUS Status;                                      // ステータス\r
+       BOOL Connected, ConnectedOld;           // ケーブル接続状態\r
+       BOOL ConnectedForce;                            // 接続状態強制通知\r
+#ifdef OS_WIN32\r
+       NDIS_HANDLE NdisWrapper;                        // NDIS ラッパーハンドル\r
+       NDIS_HANDLE NdisControl;                        // NDIS コントロールハンドル\r
+       NDIS_HANDLE NdisMiniport;                       // NDIS ミニポートハンドル\r
+       NDIS_HANDLE NdisContext;                        // NDIS コンテキストハンドル\r
+       NDIS_HANDLE NdisConfig;                         // NDIS Config ハンドル\r
+       DEVICE_OBJECT *NdisControlDevice;       // NDIS コントロールデバイス\r
+       PDRIVER_DISPATCH DispatchTable[IRP_MJ_MAXIMUM_FUNCTION];\r
+       PACKET_BUFFER *PacketBuffer[SEN_MAX_PACKET_EXCHANGE];           // NDIS パケットバッファ\r
+       NDIS_PACKET *PacketBufferArray[SEN_MAX_PACKET_EXCHANGE];        // NDIS パケットバッファ配列\r
+       NDIS_HARDWARE_STATUS HardwareStatus;    // ハードウェア状態\r
+       char HardwareID[MAX_SIZE];                      // ハードウェア ID\r
+       char HardwareID_Raw[MAX_SIZE];          // 元のハードウェア ID\r
+       char HardwarePrintableID[MAX_SIZE];     // ハードウェア ID (表示用)\r
+#endif\r
+} SEN_CTX;\r
+\r
+extern SEN_CTX *ctx;\r
+\r
+\r
+// Sen.c ルーチン\r
+void SenNewStatus(SEN_STATUS *s);\r
+void SenFreeStatus(SEN_STATUS *s);\r
+BOOL SenInit();\r
+void SenShutdown();\r
+void SenInitPacketQueue();\r
+void SenFreePacketQueue();\r
+void SenClearPacketQueue();\r
+void SenLockPacketQueue();\r
+void SenUnlockPacketQueue();\r
+SEN_QUEUE *SenGetNextQueue();\r
+void SenFreeQueue(SEN_QUEUE *q);\r
+void SenInsertQueue(void *buf, UINT size);\r
+UINT SenGetNumQueue();\r
+void SenStartAdapter();\r
+void SenStopAdapter();\r
+void SenRead(void *buf);\r
+void SenWrite(void *buf);\r
+\r
+// 共通ルーチン (プラットフォーム依存)\r
+void *SenMalloc(UINT size);\r
+void *SenZeroMalloc(UINT size);\r
+void SenFree(void *p);\r
+void SenCopy(void *dst, void *src, UINT size);\r
+void SenZero(void *dst, UINT size);\r
+SEN_LOCK *SenNewLock();\r
+void SenLock(SEN_LOCK *lock);\r
+void SenUnlock(SEN_LOCK *lock);\r
+void SenFreeLock(SEN_LOCK *lock);\r
+SEN_EVENT *SenNewEvent(char *name);\r
+SEN_EVENT *SenCreateWin9xEvent(DWORD h);\r
+void SenFreeEvent(SEN_EVENT *event);\r
+void SenSet(SEN_EVENT *event);\r
+void SenReset(SEN_EVENT *event);\r
+BOOL SenIsKernelAddress(void *addr);\r
+\r
+#endif // SEN_DEVICE_DRIVER\r
+\r
+\r
+#endif // SEN_H\r
+\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn b/utvpn/utvpn-unix-v101-7101-public/src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn
new file mode 100644 (file)
index 0000000..1fbffc7
Binary files /dev/null and b/utvpn/utvpn-unix-v101-7101-public/src/bin/BuiltHamcoreFiles/unix_ja/hamcore.utvpn differ
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/utvpnclient/utvpnclient.c b/utvpn/utvpn-unix-v101-7101-public/src/utvpnclient/utvpnclient.c
new file mode 100644 (file)
index 0000000..d15363f
--- /dev/null
@@ -0,0 +1,129 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// utvpncsvc.c\r
+// SoftEther UT-VPN Client サービスプログラム\r
+\r
+#define        VPN_EXE\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+\r
+// プロセス開始関数\r
+void StartProcess()\r
+{\r
+       // クライアントの開始\r
+       InitCedar();\r
+       CtStartClient();\r
+}\r
+\r
+// プロセス終了関数\r
+void StopProcess()\r
+{\r
+       // クライアントの停止\r
+       CtStopClient();\r
+       FreeCedar();\r
+}\r
+\r
+// WinMain 関数\r
+int main(int argc, char *argv[])\r
+{\r
+#ifdef OS_WIN32\r
+       return MsService("UTVPNCLIENT", StartProcess, StopProcess, ICO_MACHINE);\r
+#else  // OS_WIN32\r
+#ifdef NO_VLAN\r
+       printf("I'm very sorry, but this version of UT-VPN Client doesn't support your operating system.\n");\r
+       printf("However, UT-VPN Server supports this operating system. Please use 'utvpnserver' command.\n");\r
+       printf("\n");\r
+       printf("The latest version of UT-VPN Client may support this operating system.\n");\r
+       printf("Please go to http://utvpn.tsukuba.ac.jp/ and check the latest information.\n");\r
+       printf("Of course, your porting source code contribution to UT-VPN Project is very welcome.\n");\r
+       printf("\n");\r
+       printf("Thanks.\n");\r
+       exit(1);\r
+#endif // NO_VLAN\r
+       return UnixService(argc, argv, "UTVPNCLIENT", StartProcess, StopProcess);\r
+#endif // OS_WIN32\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/utvpnclient/utvpnclient.h b/utvpn/utvpn-unix-v101-7101-public/src/utvpnclient/utvpnclient.h
new file mode 100644 (file)
index 0000000..968bb07
--- /dev/null
@@ -0,0 +1,91 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// utvpncsvc.h\r
+// utvpncsvc.c のヘッダ\r
+\r
+#ifndef        VPNCSVC_H\r
+#define        VPNCSVC_H\r
+\r
+// 関数プロトタイプ\r
+int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, char *CmdLine, int CmdShow);\r
+void StartProcess();\r
+void StopProcess();\r
+\r
+\r
+#endif // VPNCSVC_H\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/utvpncmd/utvpncmd.c b/utvpn/utvpn-unix-v101-7101-public/src/utvpncmd/utvpncmd.c
new file mode 100644 (file)
index 0000000..db6fc2e
--- /dev/null
@@ -0,0 +1,168 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// utvpncmd.c\r
+// SoftEther UT-VPN コマンドライン管理ユーティリティ\r
+\r
+#ifdef WIN32\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+#include <wincrypt.h>\r
+#include <wininet.h>\r
+#include <shlobj.h>\r
+#include <commctrl.h>\r
+#include <Dbghelp.h>\r
+#endif // WIN32\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+\r
+// main 関数\r
+int main(int argc, char *argv[])\r
+{\r
+       wchar_t *s;\r
+       UINT ret;\r
+\r
+#ifdef OS_WIN32\r
+       SetConsoleTitleA("SoftEther UT-VPN Command Line Utility");\r
+#endif // OS_WIN32\r
+\r
+       InitMayaqua(false, false, argc, argv);\r
+       LoadTable(DEFAULT_TABLE_FILE_NAME);\r
+       InitCedar();\r
+\r
+       s = GetCommandLineUniStr();\r
+\r
+       if (s == NULL)\r
+       {\r
+               s = CopyUniStr(L"");\r
+       }\r
+\r
+       if (UniStrCmpi(s, L"exit") != 0)\r
+       {\r
+               UINT size = UniStrSize(s) + 64;\r
+               wchar_t *tmp;\r
+\r
+               tmp = Malloc(size);\r
+               UniFormat(tmp, size, L"utvpncmd %s", s);\r
+               ret = CommandMain(tmp);\r
+\r
+               Free(tmp);\r
+       }\r
+\r
+#ifdef OS_WIN32\r
+       {\r
+               UINT i;\r
+               LIST *o = MsGetProcessList();\r
+               bool b = false;\r
+\r
+               for (i = 0;i < LIST_NUM(o);i++)\r
+               {\r
+                       MS_PROCESS *p = LIST_DATA(o, i);\r
+\r
+                       if (EndWith(p->ExeFilename, "\\cmd.exe") || EndWith(p->ExeFilename, "\\command.com"))\r
+                       {\r
+                               b = true;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               MsFreeProcessList(o);\r
+\r
+               if (b == false)\r
+               {\r
+                       if (ret != ERR_NO_ERROR)\r
+                       {\r
+                               SleepThread(1000);\r
+                       }\r
+               }\r
+       }\r
+#endif // OS_WIN32\r
+\r
+       Free(s);\r
+\r
+       FreeCedar();\r
+       FreeMayaqua();\r
+       return ret;\r
+}\r
+\r
+\r
diff --git a/utvpn/utvpn-unix-v101-7101-public/src/utvpnserver/utvpnserver.c b/utvpn/utvpn-unix-v101-7101-public/src/utvpnserver/utvpnserver.c
new file mode 100644 (file)
index 0000000..5f854c7
--- /dev/null
@@ -0,0 +1,129 @@
+// SoftEther UT-VPN SourceCode\r
+// \r
+// Copyright (C) 2004-2010 SoftEther Corporation.\r
+// Copyright (C) 2004-2010 University of Tsukuba, Japan.\r
+// Copyright (C) 2003-2010 Daiyuu Nobori.\r
+// All Rights Reserved.\r
+// \r
+// http://utvpn.tsukuba.ac.jp/\r
+// \r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// version 2 as published by the Free Software Foundation.\r
+// \r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+// \r
+// You should have received a copy of the GNU General Public License version 2\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+// \r
+// このファイルは GPL バージョン 2 ライセンスで公開されています。\r
+// 誰でもこのファイルの内容を複製、改変したり、改変したバージョンを再配布\r
+// することができます。ただし、原著作物を改変した場合は、原著作物の著作権表示\r
+// を除去することはできません。改変した著作物を配布する場合は、改変実施者の\r
+// 著作権表示を原著作物の著作権表示に付随して記載するようにしてください。\r
+// \r
+// この SoftEther UT-VPN オープンソース・プロジェクトは、日本国の\r
+// ソフトイーサ株式会社 (SoftEther Corporation, http://www.softether.co.jp/ )\r
+// および筑波大学 (University of Tsukuba, http://www.tsukuba.ac.jp/ ) によって\r
+// ホストされています。\r
+// 本プログラムの配布者は、本プログラムを、業としての利用以外のため、\r
+// および、試験または研究のために利用が行われることを想定して配布\r
+// しています。\r
+// SoftEther UT-VPN プロジェクトの Web サイトは http://utvpn.tsukuba.ac.jp/ に\r
+// あります。\r
+// 本ソフトウェアの不具合の修正、機能改良、セキュリティホールの修復などのコード\r
+// の改変を行った場合で、その成果物を SoftEther UT-VPN プロジェクトに提出して\r
+// いただける場合は、 http://utvpn.tsukuba.ac.jp/ までソースコードを送付して\r
+// ください。SoftEther UT-VPN プロジェクトの本体リリースまたはブランチリリース\r
+// に組み込みさせていただきます。\r
+// \r
+// GPL に基づいて原著作物が提供される本ソフトウェアの改良版を配布、販売する\r
+// 場合は、そのソースコードを GPL に基づいて誰にでも開示する義務が生じます。\r
+// \r
+// 本ソフトウェアに関連する著作権、特許権、商標権はソフトイーサ株式会社\r
+// (SoftEther Corporation) およびその他の著作権保持者が保有しています。\r
+// ソフトイーサ株式会社等はこれらの権利を放棄していません。本ソフトウェアの\r
+// 二次著作物を配布、販売する場合は、これらの権利を侵害しないようにご注意\r
+// ください。\r
+// \r
+// お願い: どのような通信ソフトウェアにも通常は必ず未発見の\r
+// セキュリティホールが潜んでいます。本ソースコードをご覧いただいた結果、\r
+// UT-VPN にセキュリティホールを発見された場合は、当該セキュリティホールの\r
+// 情報を不特定多数に開示される前に、必ず、ソフトイーサ株式会社\r
+// および脆弱性情報の届出を受け付ける公的機関まで通報いただき、\r
+// 公益保護にご協力いただきますようお願い申し上げます。\r
+// \r
+// ソフトイーサ株式会社は、当該セキュリティホールについて迅速に対処を\r
+// 行い、UT-VPN および UT-VPN に関連するソフトウェアのユーザー・顧客\r
+// を保護するための努力を行います。\r
+// \r
+// ソフトイーサへの届出先: http://www.softether.co.jp/jp/contact/\r
+// 日本国内の脆弱性情報届出受付公的機関:\r
+//         独立行政法人 情報処理推進機構\r
+//         http://www.ipa.go.jp/security/vuln/report/\r
+// \r
+// 上記各事項について不明な点は、ソフトイーサ株式会社までご連絡ください。\r
+// 連絡先: http://www.softether.co.jp/jp/contact/\r
+\r
+// -----------------------------------------------\r
+// [ChangeLog]\r
+// 2010.05.20\r
+//  新規リリース by SoftEther\r
+// -----------------------------------------------\r
+\r
+// utvpnserver.c\r
+// SoftEther UT-VPN Server サービスプログラム\r
+\r
+#define        VPN_EXE\r
+\r
+#ifdef WIN32\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+#include <wincrypt.h>\r
+#include <wininet.h>\r
+#include <shlobj.h>\r
+#include <commctrl.h>\r
+#include <Dbghelp.h>\r
+#include "../PenCore/resource.h"\r
+#endif // WIN32\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <wchar.h>\r
+#include <stdarg.h>\r
+#include <time.h>\r
+#include <Mayaqua/Mayaqua.h>\r
+#include <Cedar/Cedar.h>\r
+\r
+// プロセス開始関数\r
+void StartProcess()\r
+{\r
+       // サーバーの開始\r
+       InitCedar();\r
+       StInit();\r
+       StStartServer(false);\r
+}\r
+\r
+// プロセス終了関数\r
+void StopProcess()\r
+{\r
+       // サーバーの停止\r
+       StStopServer();\r
+       StFree();\r
+       FreeCedar();\r
+}\r
+\r
+// WinMain 関数\r
+int main(int argc, char *argv[])\r
+{\r
+#ifdef OS_WIN32\r
+       return MsService("UTVPNSERVER", StartProcess, StopProcess, ICO_CASCADE);\r
+#else  // OS_WIN32\r
+       return UnixService(argc, argv, "UTVPNSERVER", StartProcess, StopProcess);\r
+#endif // OS_WIN32\r
+}\r
+\r