├── .gitignore ├── AuthLDAP.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── LICENSE ├── Makefile.in ├── Mk ├── autoconf.mk.in ├── compile.mk.in └── subdir.mk.in ├── README.md ├── aclocal.m4 ├── auth-ldap.conf ├── config.guess ├── config.sub ├── configure.ac ├── docs ├── Makefile.in ├── doxyfile.in ├── resources │ └── docbook.css └── xml │ └── auth-ldap.xml ├── framework.m4 ├── install-sh ├── mkinstalldirs ├── platform.m4 ├── pthread.m4 ├── regen.sh ├── src ├── Makefile.in ├── PXObjCRuntime.h ├── TRAccountRepository.h ├── TRArray.h ├── TRArray.m ├── TRAuthLDAPConfig.h ├── TRAuthLDAPConfig.m ├── TRAutoreleasePool.h ├── TRAutoreleasePool.m ├── TRConfig.h ├── TRConfig.m ├── TRConfigLexer.h ├── TRConfigLexer.re ├── TRConfigParser.lemon ├── TRConfigToken.h ├── TRConfigToken.m ├── TREnumerator.h ├── TREnumerator.m ├── TRHash.h ├── TRHash.m ├── TRLDAPAccountRepository.h ├── TRLDAPAccountRepository.m ├── TRLDAPConnection.h ├── TRLDAPConnection.m ├── TRLDAPEntry.h ├── TRLDAPEntry.m ├── TRLDAPGroupConfig.h ├── TRLDAPGroupConfig.m ├── TRLDAPSearchFilter.h ├── TRLDAPSearchFilter.m ├── TRLocalPacketFilter.h ├── TRLocalPacketFilter.m ├── TRLog.h ├── TRLog.m ├── TRObject.h ├── TRObject.m ├── TRPFAddress.h ├── TRPFAddress.m ├── TRPacketFilter.h ├── TRPacketFilter.m ├── TRString.h ├── TRString.m ├── TRVPNPlugin.h ├── TRVPNSession.h ├── TRVPNSession.m ├── asprintf.c ├── auth-ldap.m ├── base64.c ├── base64.h ├── hash.c ├── hash.h ├── openvpn-cr.c ├── openvpn-cr.h ├── strlcpy.c ├── strlcpy.h ├── testplugin.c ├── xmalloc.c └── xmalloc.h ├── tests ├── Makefile.in ├── PXTestAssert.h ├── PXTestAssert.m ├── PXTestCase.h ├── PXTestCase.m ├── PXTestCaseRunner.h ├── PXTestCaseRunner.m ├── PXTestConsoleResultHandler.h ├── PXTestConsoleResultHandler.m ├── PXTestException.h ├── PXTestException.m ├── PXTestObjC.h ├── PXTestResultHandler.h ├── TRArrayTests.m ├── TRAuthLDAPConfigTests.m ├── TRAutoreleasePoolTests.m ├── TRConfigLexerTests.m ├── TRConfigTests.m ├── TRConfigTokenTests.m ├── TRHashTests.m ├── TRLDAPAccountRepositoryTests.m ├── TRLDAPConnectionTests.m ├── TRLDAPEntryTests.m ├── TRLDAPGroupConfigTests.m ├── TRLDAPSearchFilterTests.m ├── TRLocalPacketFilterTests.m ├── TRObjectTests.m ├── TRPFAddressTests.m ├── TRStringTests.m ├── TRVPNSessionTests.m ├── data │ ├── TRConfig.conf │ ├── auth-ldap-bad-section.conf │ ├── auth-ldap-mismatched.conf │ ├── auth-ldap-missing-newline.conf │ ├── auth-ldap-multikey.conf │ ├── auth-ldap-named.conf │ ├── auth-ldap-pf.conf │ ├── auth-ldap-required.conf │ ├── auth-ldap.conf │ └── test-lineNumbers.conf ├── mockpf.c ├── mockpf.h ├── tests.h └── tests.m ├── tools ├── Makefile.in ├── README ├── lemon.c ├── lempar.c └── makeheaders.c ├── ubuntu_16.04_lts_build.sh └── ubuntu_16.04_lts_package.sh /.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Mk/autoconf.mk 3 | Mk/compile.mk 4 | Mk/subdir.mk 5 | autom4te.cache/ 6 | config.h 7 | config.h.in 8 | config.log 9 | config.status 10 | configure 11 | docs/Makefile 12 | docs/doxyfile 13 | src/Makefile 14 | tests/Makefile 15 | tools/Makefile 16 | AuthLDAP.xcodeproj/project.xcworkspace/xcuserdata/ 17 | AuthLDAP.xcodeproj/xcuserdata/ 18 | -------------------------------------------------------------------------------- /AuthLDAP.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Makefile.in: -------------------------------------------------------------------------------- 1 | top_srcdir= @top_srcdir@ 2 | 3 | SUBDIR= tools \ 4 | src \ 5 | tests \ 6 | docs 7 | 8 | include Mk/subdir.mk 9 | include Mk/autoconf.mk 10 | 11 | all:: 12 | 13 | clean:: 14 | 15 | distclean:: 16 | rm -f config.log config.status configure.lineno config.cache config.h 17 | rm -rf autom4te.cache 18 | rm -f Makefile Mk/autoconf.mk Mk/compile.mk Mk/subdir.mk 19 | -------------------------------------------------------------------------------- /Mk/autoconf.mk.in: -------------------------------------------------------------------------------- 1 | SHELL = @SHELL@ 2 | 3 | CC = @CC@ 4 | 5 | CFLAGS = @CFLAGS@ @DEFS@ -Wall 6 | OBJCFLAGS = -fPIC @OBJCFLAGS@ ${OBJC_RUNTIME_FLAGS} ${OBJC_PTHREAD_CFLAGS} -fno-strict-aliasing ${CFLAGS} 7 | OBJC_LIBS = -fPIC @OBJC_LIBS@ ${OBJC_PTHREAD_LIBS} 8 | 9 | OBJC_RUNTIME = @OBJC_RUNTIME@ 10 | OBJC_RUNTIME_FLAGS = @OBJC_RUNTIME_FLAGS@ 11 | 12 | OBJC_PTHREAD_LIBS = @OBJC_PTHREAD_LIBS@ 13 | OBJC_PTHREAD_CFLAGS = @OBJC_PTHREAD_CFLAGS@ 14 | 15 | PLUGIN_LD = @PLUGIN_LD@ 16 | PLUGIN_LD_FLAGS = @PLUGIN_LD_FLAGS@ 17 | PLUGIN_CFLAGS = @PLUGIN_CFLAGS@ 18 | PLUGIN_SUFFIX = @PLUGIN_SUFFIX@ 19 | PLUGIN_FILE = @PLUGIN_FILE@ 20 | 21 | MAKE_PLUGIN = @MAKE_PLUGIN@ 22 | INSTALL_PLUGIN = @INSTALL_PLUGIN@ 23 | CLEAN_PLUGIN = @CLEAN_PLUGIN@ 24 | 25 | LDAP_LIBS = @LDAP_LIBS@ 26 | LDAP_CFLAGS = @LDAP_CFLAGS@ 27 | 28 | OPENSSL_LIBS = @OPENSSL_LIBS@ 29 | OPENSSL_CFLAGS = @OPENSSL_CFLAGS@ 30 | 31 | PTHREAD_LIBS = @PTHREAD_LIBS@ 32 | PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ 33 | 34 | OPENVPN_CFLAGS = @OPENVPN_CFLAGS@ 35 | 36 | LDFLAGS = @LDFLAGS@ 37 | 38 | AR = @AR@ 39 | RANLIB = @RANLIB@ 40 | 41 | INSTALL = @INSTALL@ 42 | LN_S = @LN_S@ 43 | 44 | RE2C = @RE2C@ 45 | DOXYGEN = @DOXYGEN@ 46 | 47 | prefix = @prefix@ 48 | sysconfdir = @sysconfdir@ 49 | exec_prefix = @exec_prefix@ 50 | bindir = @bindir@ 51 | datarootdir = @datarootdir@ 52 | datadir = @datadir@ 53 | libdir = @libdir@ 54 | localstatedir = @localstatedir@ 55 | infodir = @infodir@ 56 | 57 | SILENT = @ 58 | -------------------------------------------------------------------------------- /Mk/compile.mk.in: -------------------------------------------------------------------------------- 1 | .SUFFIXES: .m .lemon .re 2 | # Disable GNU make's removal intermediate files, we handle this manually 3 | .SECONDARY: 4 | 5 | .m.o: 6 | ${CC} ${OBJCFLAGS} -c $< -o $@ -I${srcdir} -I${top_srcdir}/src -I${top_builddir} -I${top_builddir}/src -I. -I${top_srcdir}/tests -I${top_builddir}/tests 7 | 8 | .c.o: 9 | ${CC} ${CFLAGS} -c $< -o $@ -I${srcdir} -I${top_srcdir}/src -I${top_builddir} -I${top_builddir}/src -I. -I${top_srcdir}/tests -I${top_builddir}/tests 10 | 11 | .lemon.m: 12 | ${top_builddir}/tools/lemon -T${top_srcdir}/tools/lempar.c -m -q $< -O$@ 13 | ${top_builddir}/tools/makeheaders $@ 14 | 15 | .re.m: 16 | ${RE2C} -o $@ $< 17 | -------------------------------------------------------------------------------- /Mk/subdir.mk.in: -------------------------------------------------------------------------------- 1 | .PHONY : all pre-all 2 | .PHONY : clean distclean 3 | .PHONY : install 4 | .PHONY : test 5 | .PHONY : docs 6 | 7 | all:: pre-all 8 | @if test x"$(SUBDIR)" != "x"; then \ 9 | for subdir in $(SUBDIR); do\ 10 | echo ===\> making $@ in ${DIRPRFX}$$subdir; \ 11 | ( cd $$subdir && $(MAKE) DIRPRFX=${DIRPRFX}$$subdir/ $@) || exit 1; \ 12 | done \ 13 | fi 14 | 15 | pre-all:: 16 | 17 | clean:: 18 | @if test x"$(SUBDIR)" != "x"; then \ 19 | for subdir in $(SUBDIR); do\ 20 | echo ===\> making $@ in ${DIRPRFX}$$subdir; \ 21 | ( cd $$subdir && $(MAKE) DIRPRFX=${DIRPRFX}$$subdir/ $@) || exit 1; \ 22 | done \ 23 | fi 24 | 25 | distclean:: clean 26 | @if test x"$(SUBDIR)" != "x"; then \ 27 | for subdir in $(SUBDIR); do\ 28 | echo ===\> making $@ in ${DIRPRFX}$$subdir; \ 29 | ( cd $$subdir && $(MAKE) DIRPRFX=${DIRPRFX}$$subdir/ $@) || exit 1; \ 30 | done \ 31 | fi 32 | 33 | install:: 34 | @if test x"$(SUBDIR)" != "x"; then \ 35 | for subdir in $(SUBDIR); do\ 36 | echo ===\> making $@ in ${DIRPRFX}$$subdir; \ 37 | ( cd $$subdir && $(MAKE) DIRPRFX=${DIRPRFX}$$subdir/ $@) || exit 1; \ 38 | done \ 39 | fi 40 | 41 | test:: all 42 | @if test x"$(SUBDIR)" != "x"; then \ 43 | for subdir in $(SUBDIR); do\ 44 | echo ===\> making $@ in ${DIRPRFX}$$subdir; \ 45 | ( cd $$subdir && $(MAKE) DIRPRFX=${DIRPRFX}$$subdir/ $@) || exit 1; \ 46 | done \ 47 | fi 48 | 49 | docs:: all 50 | @if test x"$(SUBDIR)" != "x"; then \ 51 | for subdir in $(SUBDIR); do\ 52 | echo ===\> making $@ in ${DIRPRFX}$$subdir; \ 53 | ( cd $$subdir && $(MAKE) DIRPRFX=${DIRPRFX}$$subdir/ $@) || exit 1; \ 54 | done \ 55 | fi 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | The OpenVPN Auth-LDAP Plugin implements username/password authentication via LDAP for OpenVPN 2.x. 4 | 5 | ### Features 6 | * User authentication against LDAP. 7 | * Simple Apache-style configuration file. 8 | * LDAP group-based access restrictions. 9 | * Integration with the OpenBSD packet filter, supporting adding and removing VPN clients from PF tables based on group membership. 10 | * Tested against OpenLDAP, the plugin will authenticate against any LDAP server that supports LDAP simple binds -- including Active Directory. 11 | * Supports OpenVPN Challenge/Response protocol, enabling it to be used in combination with one time password systems like Google Authenticator 12 | 13 | ## Building 14 | 15 | ### Requirements 16 | 17 | * OpenLDAP Headers and Library 18 | * GNU Objective-C Compiler 19 | * OpenVPN Plugin Header (included with the OpenVPN sources) 20 | * [re2c](http://www.re2c.org/) (used for the configuration file lexer) 21 | 22 | To build, you will need to configure the sources appropriately. Example: 23 | 24 | ``` 25 | ./configure --prefix=/usr/local --with-openldap=/usr/local --with-openvpn=/home/sean/work/openvpn-2.0.2 26 | ``` 27 | 28 | The module will be built in src/openvpn-auth-ldap.so and installed as 29 | `${prefix}/lib/openvpn-auth-ldap.so`. 30 | 31 | 32 | #### Building On Ubuntu 16.04 #### 33 | 34 | The following steps were tested on a clean Ubuntu 16.04 LTS Amazon EC2 m5.large instance in January 2018 (source AMI: ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20180109 - ami-41e0b93b). 35 | 36 | If you wish to repeat this process, follow these steps on your own machine: 37 | 38 | ``` 39 | git clone https://github.com/snowrider311/openvpn-auth-ldap 40 | cd openvpn-auth-ldap/ 41 | ./ubuntu_16.04_lts_build.sh 42 | ``` 43 | 44 | The `ubuntu_16.04_lts_build.sh` script will install all needed build dependencies, perform the build, and install `openvpn-auth-ldap.so` to `/usr/local/lib`. 45 | 46 | If you then wish to create a Debian package, you can then run this script: 47 | 48 | ``` 49 | ./ubuntu_16.04_lts_package.sh 50 | ``` 51 | 52 | That script will install [FPM](https://github.com/jordansissel/fpm) and then use it to build a Debian package. If you then run `sudo dpkg -i openvpn-auth-ldap-snowrider311_2.0.3-1_amd64.deb`, then `openvpn-auth-ldap.so` will be installed to `/usr/lib/openvpn`, the same location as the standard, unforked `openvpn-auth-ldap` Debian package installs to. 53 | 54 | Note: Superuser privileges are required to run these scripts. 55 | 56 | 57 | ## Usage 58 | 59 | Add the following to your OpenVPN configuration file (adjusting the plugin path as required): 60 | 61 | ``` 62 | plugin /usr/local/lib/openvpn-auth-ldap.so "" 63 | ``` 64 | 65 | The config directive must point to an auth-ldap configuration file. An example configuration file 66 | is provided with the distribution, or see the [Configuration](../../wiki/Configuration) page. 67 | 68 | 69 | ## Security 70 | 71 | *Please report all security issues directly to landonf+security (at) bikemonkey (dot) org.* 72 | 73 | Through the use of extensive unit testing, valgrind, and regression testing, we are very confident 74 | in the overall code quality of the plugin. There has been one security vulnerability to date, due 75 | to misinterpretation of LDAP RFCs. 76 | 77 | * 2006-12-02: OpenVPN Auth-LDAP would accept empty passwords when validating against Novell Directory Server. This is known to not affect default installs of OpenLDAP (our test platform). Strict implementation of the LDAP RFCs requires that a directory server treat a bind with a valid DN and an empty password as an "anonymous" bind. If anonymous binds are enabled, this could lead to password bypass. 78 | 79 | ## Support 80 | 81 | Plausible Labs Cooperative is available to provide custom development or support for this plugin. 82 | If you require specific features or additions, please [contact 83 | us](http://www.plausible.coop/about/) for more information. 84 | -------------------------------------------------------------------------------- /auth-ldap.conf: -------------------------------------------------------------------------------- 1 | 2 | # LDAP server URL 3 | URL ldap://ldap1.example.org 4 | 5 | # Bind DN (If your LDAP server doesn't support anonymous binds) 6 | # BindDN uid=Manager,ou=People,dc=example,dc=com 7 | 8 | # Bind Password 9 | # Password SecretPassword 10 | 11 | # Network timeout (in seconds) 12 | Timeout 15 13 | 14 | # Enable Start TLS 15 | TLSEnable yes 16 | 17 | # Follow LDAP Referrals (anonymously) 18 | FollowReferrals yes 19 | 20 | # TLS CA Certificate File 21 | TLSCACertFile /usr/local/etc/ssl/ca.pem 22 | 23 | # TLS CA Certificate Directory 24 | TLSCACertDir /etc/ssl/certs 25 | 26 | # Client Certificate and key 27 | # If TLS client authentication is required 28 | TLSCertFile /usr/local/etc/ssl/client-cert.pem 29 | TLSKeyFile /usr/local/etc/ssl/client-key.pem 30 | 31 | # Cipher Suite 32 | # The defaults are usually fine here 33 | # TLSCipherSuite ALL:!ADH:@STRENGTH 34 | 35 | 36 | 37 | # Base DN 38 | BaseDN "ou=People,dc=example,dc=com" 39 | 40 | # User Search Filter 41 | SearchFilter "(&(uid=%u)(accountStatus=active))" 42 | 43 | # Require Group Membership 44 | RequireGroup false 45 | 46 | # Add non-group members to a PF table (disabled) 47 | #PFTable ips_vpn_users 48 | 49 | # Uncomment and set to true to support OpenVPN Challenge/Response 50 | #PasswordIsCR false 51 | 52 | # Default is true. Match full user DN if true, uid only if false. 53 | # RFC2307bis true 54 | 55 | # Default is true. Uncomment and set to false if you want to use a Search operation to determine group 56 | # membership instead of Compare. Lower performance, so Compare should generally be used, but Search is 57 | # required in certain LDAP environments. 58 | # UseCompareOperation true 59 | 60 | BaseDN "ou=Groups,dc=example,dc=com" 61 | SearchFilter "(|(cn=developers)(cn=artists))" 62 | MemberAttribute uniqueMember 63 | # Add group members to a PF table (disabled) 64 | #PFTable ips_vpn_eng 65 | 66 | 67 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ(2.57) 2 | AC_INIT(auth-ldap, [2.0], landonf@opendarwin.org) 3 | AC_CONFIG_SRCDIR(${srcdir}/src/auth-ldap.m) 4 | AC_CONFIG_HEADERS(config.h) 5 | 6 | AC_CANONICAL_SYSTEM 7 | 8 | # Compiler 9 | AC_PROG_CC(clang gcc) 10 | AC_PROG_CC_C99 11 | AC_PROG_OBJC(clang gcc) 12 | TR_WERROR 13 | AC_CACHE_SAVE 14 | 15 | # Programs 16 | AC_PROG_INSTALL 17 | AC_PROG_LN_S 18 | AC_PROG_MAKE_SET 19 | 20 | AC_CHECK_TOOL(RANLIB, ranlib, :) 21 | AC_CHECK_TOOL(AR, ar, :) 22 | 23 | AC_PATH_PROG([RE2C], [re2c], [no]) 24 | if test x"$RE2C" = x"no"; then 25 | AC_MSG_ERROR([re2c was not found in your PATH. It can be downloaded from http://re2c.org]) 26 | fi 27 | 28 | AC_PATH_PROG([DOXYGEN], [doxygen], [no]) 29 | if test x"$DOXYGEN" = x"no"; then 30 | DOXYGEN="false" 31 | fi 32 | 33 | AC_PATH_PROG([DOT], [dot], [no]) 34 | if test x"$DOT" = x"no"; then 35 | DOTDIR="" 36 | else 37 | DOTDIR=`AS_DIRNAME([$DOT])` 38 | fi 39 | AC_SUBST([DOTDIR]) 40 | 41 | AC_CACHE_SAVE 42 | 43 | # Headers 44 | AC_HEADER_STDC 45 | AC_CACHE_SAVE 46 | 47 | # Threads 48 | ACX_PTHREAD 49 | AC_CACHE_SAVE 50 | 51 | # Platform 52 | OD_CONFIG_PLUGIN 53 | TR_PF_IOCTL 54 | AC_DEFINE([_GNU_SOURCE], 1, [Required for vasprintf() on glibc systems]) 55 | AC_CACHE_SAVE 56 | 57 | # Functions 58 | AC_CHECK_FUNCS([strlcpy]) 59 | AC_CACHE_SAVE 60 | 61 | # Libraries 62 | OD_OPENLDAP 63 | TR_OPENSSL 64 | AC_CHECK_FRAMEWORK(Foundation, NSStringFromSelector, [ 65 | AC_DEFINE(HAVE_FRAMEWORK_FOUNDATION, 1, [Define if you have the Foundation framework.]) 66 | OBJC_LIBS="${OBJC_LIBS} -framework Foundation" 67 | ]) 68 | AC_CACHE_SAVE 69 | 70 | # OpenVPN 71 | OD_OPENVPN_HEADER 72 | AC_CACHE_SAVE 73 | 74 | # Objective-C Runtime 75 | OD_OBJC_RUNTIME 76 | AC_CACHE_SAVE 77 | 78 | # Output 79 | AC_CONFIG_FILES([ 80 | Makefile 81 | 82 | docs/Makefile 83 | docs/doxyfile 84 | 85 | Mk/autoconf.mk 86 | Mk/compile.mk 87 | Mk/subdir.mk 88 | 89 | src/Makefile 90 | tests/Makefile 91 | tools/Makefile 92 | ]) 93 | AC_OUTPUT 94 | -------------------------------------------------------------------------------- /docs/Makefile.in: -------------------------------------------------------------------------------- 1 | srcdir= @srcdir@ 2 | top_srcdir= @top_srcdir@ 3 | top_builddir= @top_builddir@ 4 | VPATH= @srcdir@ 5 | 6 | include ${top_builddir}/Mk/autoconf.mk 7 | include ${top_builddir}/Mk/compile.mk 8 | include ${top_builddir}/Mk/subdir.mk 9 | 10 | SOURCEDIR= ${srcdir}/xml 11 | XHTMLDIR= xhtml 12 | 13 | STYLESHEET= http://docbook.sourceforge.net/release/xsl/current/html/chunk.xsl 14 | XSTYLESHEET= http://docbook.sourceforge.net/release/xsl/current/xhtml/chunk.xsl 15 | 16 | RESOURCES= ${srcdir}/resources/ 17 | CSS_STYLESHEET= docbook.css 18 | 19 | STRINGPARAMS= --stringparam html.stylesheet ${CSS_STYLESHEET} 20 | 21 | .PHONY: all 22 | .PHONY: clean 23 | #.PHONY: install 24 | .PHONY: xhtml 25 | .PHONY: check 26 | .PHONY: tidy 27 | 28 | codedocs:: 29 | ${DOXYGEN} doxyfile 30 | 31 | manual:: 32 | mkdir -p ${XHTMLDIR} 33 | install ${RESOURCES}${CSS_STYLESHEET} ${XHTMLDIR} 34 | xsltproc --xinclude ${STRINGPARAMS} -o "${XHTMLDIR}/" "${XSTYLESHEET}" "${SOURCEDIR}/auth-ldap.xml" 35 | 36 | docs:: codedocs manual 37 | 38 | check: 39 | xmllint --xinclude --noout "${SOURCEDIR}/auth-ldap.xml" 40 | 41 | clean:: 42 | rm -rf ${HTMLDIR} ${XHTMLDIR} code 43 | 44 | distclean:: clean 45 | rm -f Makefile doxyfile 46 | -------------------------------------------------------------------------------- /docs/resources/docbook.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Stylesheet taken from the DarwinPorts Guide. 3 | * Contributed to the DarwinPorts project by Will Barton and Michael Maibaum. 4 | */ 5 | 6 | * { 7 | font-family: "Georgia", "Trebuchet MS"; 8 | } 9 | 10 | body { 11 | background: #c8dcff; 12 | width: 720px; 13 | margin: 15px auto 15px auto; 14 | font-size: 12px; 15 | line-height: 1.2; 16 | } 17 | 18 | a:link { 19 | color: #669; 20 | text-decoration: none; 21 | font-weight: bold; 22 | border-bottom: 1px dotted #c63; 23 | } 24 | 25 | a:visited { 26 | color: #888; 27 | text-decoration: none; 28 | font-weight: bold; 29 | border-bottom: 1px dotted #669; 30 | } 31 | 32 | a:hover { 33 | color: #c63; 34 | text-decoration: none; 35 | font-weight: bold; 36 | border-bottom: 1px dotted #369; 37 | } 38 | 39 | hr { 40 | display: none; 41 | } 42 | 43 | h3.title { 44 | color: #879880; 45 | margin: 1em 0 1em 0; 46 | padding: 0; 47 | border-bottom: 1px solid #ddd; 48 | } 49 | 50 | h4.title { 51 | color: #999; 52 | margin: 0 auto; 53 | padding: 0; 54 | } 55 | 56 | h5.title { 57 | color: #999; 58 | margin: 0 auto; 59 | padding: 0; 60 | } 61 | 62 | h1.title, h2.title { 63 | color: #669; 64 | margin: 5px 0 5px 0; 65 | padding: 10px 0 0 0; 66 | border-bottom: 1px solid #bbb; 67 | } 68 | 69 | .navheader, 70 | .navfooter, 71 | div.book, 72 | div.part, 73 | div.chapter, 74 | div.preface, 75 | div.sect1 { 76 | background: #fff; 77 | padding: 0.5em 2em; 78 | margin: 0.5em; 79 | border: 1px solid #bbb; 80 | } 81 | 82 | div.chapter div.sect1, div.preface div.sect1 { 83 | border: 0; 84 | padding: 0; 85 | margin: 0; 86 | } 87 | 88 | div.sect2, div.sect3 { 89 | margin: 0 1em; 90 | } 91 | 92 | pre.programlisting { 93 | color: #2F4F4F; 94 | background-color: #E6E6E6; 95 | font-family: "Courier New", Courier; 96 | font-weight: Bold; 97 | } 98 | 99 | .userinput { 100 | color: #669; 101 | } 102 | 103 | tt { 104 | font-family: "Courier New", Courier; 105 | } 106 | 107 | .filename, .computeroutput { 108 | color: #673; 109 | } 110 | 111 | .classname, .methodname, .varname, .term { 112 | color: #699; 113 | } 114 | 115 | .uri { 116 | font-family: "Courier New", Courier; 117 | font-weight: bold; 118 | } 119 | 120 | .database { 121 | color: #2F4F4F; 122 | } 123 | -------------------------------------------------------------------------------- /docs/xml/auth-ldap.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | OpenVPN Auth-LDAP: Enterprise LDAP Authentication for OpenVPN 7 | 8 | 9 | The content of this guide is the original work of Landon Fuller and Three Rings 10 | Design, Inc. All rights reserved. 11 | 12 | The XML and CSS used to generate this guide is based on the work 13 | of Will Barton and Michael Maibaum, as contributed to the DarwinPorts 14 | Project under the 3 clause BSD license. Their copyright remains. 15 | 16 | 17 | 18 | 2002 19 | 20 | 2003 21 | 22 | 2007 23 | 24 | Landon Fuller >landonf@threerings.net< 25 | 26 | 27 | 28 | 2006 29 | 30 | 2007 31 | 32 | Three Rings Design, Inc. 33 | 34 | 35 | 36 | 2002 37 | 38 | 2003 39 | 40 | 2004 41 | 42 | The OpenDarwin Project 43 | 44 | 45 | 46 | 47 | About Auth-LDAP 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /framework.m4: -------------------------------------------------------------------------------- 1 | # From http://svn.saurik.com/repos/cycript/trunk/framework.m4 2 | # 3 | # AC_CHECK_FRAMEWORK(FRAMEWORK, FUNCTION, 4 | # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], 5 | # [OTHER-LIBRARIES]) 6 | # ------------------------------------------------------ 7 | # 8 | # Use a cache variable name containing both the framework and function name, 9 | # because the test really is for framework $1 defining function $2, not 10 | # just for framework $1. Separate tests with the same $1 and different $2s 11 | # may have different results. 12 | # 13 | # Note that using directly AS_VAR_PUSHDEF([ac_Framework], [ac_cv_framework_$1_$2]) 14 | # is asking for troubles, since AC_CHECK_FRAMEWORK($framework, fun) would give 15 | # ac_cv_framework_$framework_fun, which is definitely not what was meant. Hence 16 | # the AS_LITERAL_IF indirection. 17 | # 18 | # FIXME: This macro is extremely suspicious. It DEFINEs unconditionally, 19 | # whatever the FUNCTION, in addition to not being a *S macro. Note 20 | # that the cache does depend upon the function we are looking for. 21 | # 22 | # It is on purpose we used `ac_check_framework_save_LIBS' and not just 23 | # `ac_save_LIBS': there are many macros which don't want to see `LIBS' 24 | # changed but still want to use AC_CHECK_FRAMEWORK, so they save `LIBS'. 25 | # And ``ac_save_LIBS' is too tempting a name, so let's leave them some 26 | # freedom. 27 | AC_DEFUN([AC_CHECK_FRAMEWORK], 28 | [m4_ifval([$3], , [AH_CHECK_FRAMEWORK([$1])])dnl 29 | AS_LITERAL_IF([$1], 30 | [AS_VAR_PUSHDEF([ac_Framework], [ac_cv_framework_$1_$2])], 31 | [AS_VAR_PUSHDEF([ac_Framework], [ac_cv_framework_$1''_$2])])dnl 32 | AC_CACHE_CHECK([for $2 in $1 framework], ac_Framework, 33 | [ac_check_framework_save_LIBS=$LIBS 34 | LIBS="-framework $1 $5 $LIBS" 35 | AC_LINK_IFELSE([AC_LANG_CALL([], [$2])], 36 | [AS_VAR_SET(ac_Framework, yes)], 37 | [AS_VAR_SET(ac_Framework, no)]) 38 | LIBS=$ac_check_framework_save_LIBS]) 39 | AS_IF([test AS_VAR_GET(ac_Framework) = yes], 40 | [m4_default([$3], [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FRAMEWORK_$1)) 41 | LIBS="-framework $1 $LIBS" 42 | ])], 43 | [$4])dnl 44 | AS_VAR_POPDEF([ac_Framework])dnl 45 | ])# AC_CHECK_FRAMEWORK 46 | 47 | # AH_CHECK_FRAMEWORK(FRAMEWORK) 48 | # --------------------- 49 | m4_define([AH_CHECK_FRAMEWORK], 50 | [AH_TEMPLATE(AS_TR_CPP(HAVE_FRAMEWORK_$1), 51 | [Define to 1 if you have the `]$1[' framework (-framework ]$1[).])]) 52 | -------------------------------------------------------------------------------- /mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | # Author: Noah Friedman 4 | # Created: 1993-05-16 5 | # Public domain 6 | 7 | errstatus=0 8 | 9 | for file 10 | do 11 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 12 | shift 13 | 14 | pathcomp= 15 | for d 16 | do 17 | pathcomp="$pathcomp$d" 18 | case "$pathcomp" in 19 | -* ) pathcomp=./$pathcomp ;; 20 | esac 21 | 22 | if test ! -d "$pathcomp"; then 23 | echo "mkdir $pathcomp" 1>&2 24 | 25 | mkdir "$pathcomp" || lasterr=$? 26 | 27 | if test ! -d "$pathcomp"; then 28 | errstatus=$lasterr 29 | fi 30 | fi 31 | 32 | pathcomp="$pathcomp/" 33 | done 34 | done 35 | 36 | exit $errstatus 37 | 38 | # mkinstalldirs ends here 39 | -------------------------------------------------------------------------------- /regen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | autoconf 4 | autoheader 5 | -------------------------------------------------------------------------------- /src/Makefile.in: -------------------------------------------------------------------------------- 1 | srcdir= @srcdir@ 2 | top_srcdir= @top_srcdir@ 3 | top_builddir= @top_builddir@ 4 | VPATH= @srcdir@ 5 | 6 | include ${top_builddir}/Mk/autoconf.mk 7 | include ${top_builddir}/Mk/compile.mk 8 | include ${top_builddir}/Mk/subdir.mk 9 | 10 | PLUGIN_NAME= openvpn-auth-ldap 11 | PLUGIN_OBJS= auth-ldap.o 12 | 13 | AUTH_LIB= libauth-ldap.a 14 | AUTH_OBJS= TRArray.o \ 15 | TRAutoreleasePool.o \ 16 | TRConfig.o \ 17 | TRConfigLexer.o \ 18 | TRConfigParser.o \ 19 | TRConfigToken.o \ 20 | TRAuthLDAPConfig.o \ 21 | TREnumerator.o \ 22 | TRHash.o \ 23 | TRLDAPAccountRepository.o \ 24 | TRLDAPConnection.o \ 25 | TRLDAPEntry.o \ 26 | TRLDAPGroupConfig.o \ 27 | TRLDAPSearchFilter.o \ 28 | TRLocalPacketFilter.o \ 29 | TRLog.o \ 30 | TRObject.o \ 31 | TRPFAddress.o \ 32 | TRPacketFilter.o \ 33 | TRString.o \ 34 | TRVPNSession.o \ 35 | hash.o \ 36 | strlcpy.o \ 37 | xmalloc.o \ 38 | base64.o \ 39 | openvpn-cr.o 40 | 41 | GEN_SRCS= TRConfigParser.m \ 42 | TRConfigParser.h \ 43 | TRConfigLexer.m 44 | 45 | TEST_OBJS= testplugin.o 46 | 47 | CFLAGS+= $(LDAP_CFLAGS) $(OPENVPN_CFLAGS) 48 | OBJCFLAGS+= $(LDAP_CFLAGS) $(OPENVPN_CFLAGS) 49 | LIBS+= -L. -lauth-ldap \ 50 | $(LDAP_LIBS) \ 51 | $(OBJC_LIBS) \ 52 | $(FLEX_LIBS) 53 | 54 | INSTALL_LIB= $(INSTALL) -m 755 55 | PLUGIN_INSTALL_DIR= $(DESTDIR)$(libdir) 56 | 57 | all:: $(PLUGIN_FILE) $(AUTH_LIB) testplugin 58 | 59 | # Work-around for gnumake bug. 60 | # It fails to check if 'TRConfigParser.h' has been created 61 | # after lemon has been called, and goes looking for a 62 | # rule to build it. 63 | TRConfigParser.h: TRConfigParser.m 64 | 65 | $(PLUGIN_FILE): $(AUTH_LIB) $(PLUGIN_OBJS) 66 | $(MAKE_PLUGIN) 67 | 68 | $(AUTH_LIB): $(GEN_SRCS) $(AUTH_OBJS) 69 | $(AR) -r $@ $(AUTH_OBJS) 70 | 71 | testplugin:: $(TEST_OBJS) $(PLUGIN_OBJS) $(AUTH_LIB) 72 | $(CC) -o $@ ${TEST_OBJS} ${PLUGIN_OBJS} ${LDFLAGS} ${LIBS} 73 | 74 | install:: $(PLUGIN_FILE) 75 | $(INSTALL_PLUGIN) 76 | 77 | clean:: 78 | rm -f $(AUTH_OBJS) $(TEST_OBJS) $(PLUGIN_OBJS) $(AUTH_LIB) $(GEN_SRCS) testplugin 79 | $(CLEAN_PLUGIN) 80 | 81 | distclean:: clean 82 | rm -f Makefile 83 | -------------------------------------------------------------------------------- /src/PXObjCRuntime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PXObjCRuntime.h vi:ts=4:sw=4:expandtab: 3 | * 4 | * Author: Landon Fuller 5 | * 6 | * Copyright (c) 2007 - 2012 Landon Fuller 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import 40 | 41 | /** Used to describe a signed integer */ 42 | #if __LP64__ 43 | typedef long PXInteger; 44 | #else 45 | typedef int PXInteger; 46 | #endif 47 | 48 | /** Used to describe an unsigned integer */ 49 | #if __LP64__ 50 | typedef unsigned long PXUInteger; 51 | #else 52 | typedef unsigned int PXUInteger; 53 | #endif 54 | -------------------------------------------------------------------------------- /src/TRAccountRepository.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRAccountRepository.h vi:ts=4:sw=4:expandtab: 3 | * 4 | * Author: Landon Fuller 5 | * 6 | * Copyright (c) 2008 Three Rings Design, Inc. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. Neither the name of the copyright holder nor the names of any contributors 18 | * may be used to endorse or promote products derived from this 19 | * software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef TRACCOUNTREPOSITORY_H 35 | #define TRACCOUNTREPOSITORY_H 36 | 37 | /** 38 | * Intentionally simple user/group account verification. 39 | */ 40 | @protocol TRAccountRepository 41 | /** 42 | * Authenticate a user with the provided username and password. 43 | * Return YES if authentication succeeds, NO on failure. 44 | */ 45 | - (BOOL) authenticateUser: (TRString *) username withPassword: (TRString *) password; 46 | 47 | /** 48 | * Check if the given username is a member of a group. 49 | * Return YES if the user is a member, or NO on failure. 50 | */ 51 | - (BOOL) checkGroupMember: (TRString *) username withGroup: (TRString *) groupname; 52 | @end 53 | 54 | #endif /* TRACCOUNTREPOSITORY_H */ 55 | -------------------------------------------------------------------------------- /src/TRArray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRArray.h vi:ts=4:sw=4:expandtab: 3 | * Simple linked list 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import "TRObject.h" 36 | #import "TREnumerator.h" 37 | 38 | @interface TRArray : TRObject { 39 | @private 40 | unsigned int _count; 41 | struct _TRArrayStack *_stack; 42 | struct _TRArrayStack *_stackBottom; 43 | } 44 | 45 | - (void) addObject: (id) anObject; 46 | - (void) removeObject; 47 | - (id) lastObject; 48 | - (BOOL) containsObject: (id) anObject; 49 | - (TREnumerator *) objectEnumerator; 50 | - (TREnumerator *) objectReverseEnumerator; 51 | - (unsigned int) count; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /src/TRAuthLDAPConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRAuthLDAPConfig.h vi:ts=4:sw=4:expandtab: 3 | * Simple Configuration 4 | * 5 | * Copyright (c) 2005 - 2007 Landon Fuller 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of Landon Fuller nor the names of any contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #import "TRObject.h" 34 | 35 | #import "TRLDAPGroupConfig.h" 36 | 37 | #import "TRConfig.h" 38 | #import "TRString.h" 39 | #import "TRArray.h" 40 | 41 | @interface TRAuthLDAPConfig : TRObject { 42 | @private 43 | /* LDAP Settings */ 44 | TRString *_url; 45 | BOOL _tlsEnabled; 46 | BOOL _referralEnabled; 47 | int _timeout; 48 | TRString *_tlsCACertFile; 49 | TRString *_tlsCACertDir; 50 | TRString *_tlsCertFile; 51 | TRString *_tlsKeyFile; 52 | TRString *_tlsCipherSuite; 53 | TRString *_bindDN; 54 | TRString *_bindPassword; 55 | 56 | /* Authentication / Authorization Settings */ 57 | TRString *_baseDN; 58 | TRString *_searchFilter; 59 | BOOL _requireGroup; 60 | TRString *_pfTable; 61 | TRArray *_ldapGroups; 62 | BOOL _pfEnabled; 63 | BOOL _passwordISCR; 64 | 65 | /* Parser State */ 66 | TRString *_configFileName; 67 | TRConfig *_configDriver; 68 | TRArray *_sectionStack; 69 | } 70 | 71 | - (id) initWithConfigFile: (const char *) fileName; 72 | 73 | /* TRConfigDelegate */ 74 | - (void) setKey: (TRConfigToken *) key value: (TRConfigToken *) value; 75 | - (void) startSection: (TRConfigToken *) sectionType sectionName: (TRConfigToken *) name; 76 | - (void) endSection: (TRConfigToken *) sectionEnd; 77 | - (void) parseError: (TRConfigToken *) badToken; 78 | 79 | /* Accessors */ 80 | - (TRString *) url; 81 | - (void) setURL: (TRString *) newURL; 82 | 83 | - (int) timeout; 84 | - (void) setTimeout: (int) newTimeout; 85 | 86 | - (BOOL) tlsEnabled; 87 | - (void) setTLSEnabled: (BOOL) newTLSSetting; 88 | 89 | - (TRString *) tlsCACertFile; 90 | - (void) setTLSCACertFile: (TRString *) fileName; 91 | 92 | - (TRString *) tlsCACertDir; 93 | - (void) setTLSCACertDir: (TRString *) directoryName; 94 | 95 | - (TRString *) tlsCertFile; 96 | - (void) setTLSCertFile: (TRString *) newFilename; 97 | 98 | - (TRString *) tlsKeyFile; 99 | - (void) setTLSKeyFile: (TRString *) fileName; 100 | 101 | - (TRString *) tlsCipherSuite; 102 | - (void) setTLSCipherSuite: (TRString *) cipherSuite; 103 | 104 | - (TRString *) bindDN; 105 | - (void) setBindDN: (TRString *) bindDN; 106 | 107 | - (TRString *) bindPassword; 108 | - (void) setBindPassword: (TRString *) bindPassword; 109 | 110 | - (TRString *) baseDN; 111 | - (void) setBaseDN: (TRString *) baseDN; 112 | 113 | - (TRString *) searchFilter; 114 | - (void) setSearchFilter: (TRString *) searchFilter; 115 | 116 | - (BOOL) referralEnabled; 117 | - (void) setReferralEnabled: (BOOL) newReferralSetting; 118 | 119 | - (BOOL) requireGroup; 120 | - (void) setRequireGroup: (BOOL) requireGroup; 121 | 122 | - (TRString *) pfTable; 123 | - (void) setPFTable: (TRString *) tableName; 124 | 125 | - (BOOL) pfEnabled; 126 | - (void) setPFEnabled: (BOOL) newPFSetting; 127 | 128 | - (TRArray *) ldapGroups; 129 | 130 | - (BOOL) passWordIsCR; 131 | - (void) setPassWordIsCR: (BOOL)newCRSetting; 132 | 133 | @end 134 | -------------------------------------------------------------------------------- /src/TRAutoreleasePool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRAutoreleasePool.h vi:ts=4:sw=4:expandtab: 3 | * 4 | * Copyright (C) 2006 - 2007 Landon Fuller 5 | * All rights reserved. 6 | * 7 | * Author: Landon Fuller 8 | * 9 | * This file is part of Substrate. 10 | * 11 | * Permission to use, copy, modify, and distribute this software and its 12 | * documentation for any purpose and without fee is hereby granted, provided 13 | * that the above copyright notice appear in all copies and that both that 14 | * copyright notice and this permission notice appear in supporting 15 | * documentation. 16 | * 17 | * We disclaim all warranties with regard to this software, including all 18 | * implied warranties of merchantability and fitness, in no event shall 19 | * we be liable for any special, indirect or consequential damages or any 20 | * damages whatsoever resulting from loss of use, data or profits, whether in 21 | * an action of contract, negligence or other tortious action, arising out of 22 | * or in connection with the use or performance of this software. 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #import 27 | #endif 28 | 29 | #import "TRObject.h" 30 | 31 | typedef struct _TRAutoreleasePoolBucket TRAutoreleasePoolBucket; 32 | 33 | @interface TRAutoreleasePool : TRObject 34 | { 35 | @private 36 | TRAutoreleasePoolBucket *poolBucket; 37 | } 38 | 39 | + (void) addObject:(id)anObject; 40 | 41 | - (void) addObject:(id)anObject; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /src/TRConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRConfig.h vi:ts=4:sw=4:expandtab: 3 | * Generic Configuration Parser 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import "TRObject.h" 36 | #import "TRConfigToken.h" 37 | 38 | @protocol TRConfigDelegate 39 | - (void) setKey: (TRConfigToken *) name value: (TRConfigToken *) value; 40 | - (void) startSection: (TRConfigToken *) sectionType sectionName: (TRConfigToken *) name; 41 | - (void) endSection: (TRConfigToken *) sectionEnd; 42 | - (void) parseError: (TRConfigToken *) badToken; 43 | @end 44 | 45 | @interface TRConfig : TRObject { 46 | @private 47 | int _fd; 48 | BOOL _error; 49 | id _delegate; 50 | } 51 | 52 | - (id) initWithFD: (int) fd configDelegate: (id ) delegate; 53 | - (BOOL) parseConfig; 54 | /* Callback used to stop the running parser */ 55 | - (void) errorStop; 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /src/TRConfig.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRConfig.m vi:ts=4:sw=4:expandtab: 3 | * Generic Configuration Parser 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import 40 | 41 | #import "TRConfig.h" 42 | #import "TRConfigLexer.h" 43 | #import "TRConfigParser.h" 44 | #import "TRConfigToken.h" 45 | 46 | /** 47 | * An Apache-style configuration file parser/lexer. 48 | */ 49 | @implementation TRConfig 50 | 51 | /** 52 | * Initialize and return a TRConfig parser. 53 | * @param fd A file descriptor open for reading. This file descriptor will be 54 | * mmap()ed, and thus must reference a file. 55 | * @param delegate A configuration delegate conforming to the TRConfigDelegate protocol. 56 | */ 57 | - (id) initWithFD: (int) fd configDelegate: (id ) delegate { 58 | self = [self init]; 59 | 60 | if (self) { 61 | _fd = fd; 62 | _delegate = delegate; 63 | _error = NO; 64 | } 65 | 66 | return self; 67 | } 68 | 69 | /** 70 | * Parse the configuration file 71 | * @result true on success, false on failure. 72 | */ 73 | - (BOOL) parseConfig { 74 | TRConfigLexer *lexer = NULL; 75 | TRConfigToken *token; 76 | void *parser; 77 | 78 | /* Initialize our lexer */ 79 | lexer = [[TRConfigLexer alloc] initWithFD: _fd]; 80 | if (lexer == NULL) 81 | return false; 82 | 83 | /* Initialize the parser */ 84 | parser = TRConfigParseAlloc(malloc); 85 | 86 | /* Scan in tokens and hand them off to the parser */ 87 | while ((token = [lexer scan]) != NULL) { 88 | TRConfigParse(parser, [token tokenID], token, _delegate); 89 | /* If we've been asked to stop, do so */ 90 | if (_error) 91 | break; 92 | } 93 | /* Signal EOF and clean up */ 94 | if (!_error) { 95 | /* Only trigger EOF handling if no errors occured */ 96 | TRConfigParse(parser, 0, NULL, _delegate); 97 | } 98 | TRConfigParseFree(parser, free); 99 | [lexer release]; 100 | 101 | /* Did an error occur? */ 102 | if (_error) 103 | return false; 104 | 105 | return true; 106 | } 107 | 108 | /* Re-entrant callback used to signal an error by the parser delegate, called 109 | * from within the bowels of TRConfigParse() */ 110 | - (void) errorStop { 111 | _error = YES; 112 | } 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /src/TRConfigLexer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRConfigLexer.h vi:ts=4:sw=4:expandtab: 3 | * Configuration Lexer 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import 36 | 37 | #import "TRObject.h" 38 | #import "TRConfigToken.h" 39 | 40 | typedef enum { 41 | LEXER_SC_INITIAL, 42 | LEXER_SC_SECTION, 43 | LEXER_SC_SECTION_NAME, 44 | LEXER_SC_VALUE, 45 | LEXER_SC_STRING_VALUE 46 | } LexerStartCondition; 47 | 48 | @interface TRConfigLexer : TRObject { 49 | @private 50 | /* Input buffer */ 51 | char *buffer; 52 | size_t bufferLength; 53 | 54 | /* re2c lexer state */ 55 | char *_cursor; 56 | char *_limit; 57 | char *_marker; 58 | char *_ctxMarker; 59 | char *_token; 60 | char *_eoi; 61 | unsigned int _lineNumber; 62 | LexerStartCondition _condition; 63 | } 64 | 65 | - (id) initWithFD: (int) fd; 66 | 67 | - (TRConfigToken *) scan; 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /src/TRConfigParser.lemon: -------------------------------------------------------------------------------- 1 | /* 2 | * TRConfigParser.lemon vi:ts=4:sw=4:expandtab: 3 | * Configuration Parser 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holders nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | %include { 36 | #ifdef HAVE_CONFIG_H 37 | #import 38 | #endif 39 | 40 | #import "TRConfig.h" 41 | 42 | #import 43 | } 44 | 45 | %name TRConfigParse 46 | %token_type {TRConfigToken *} 47 | %token_prefix {TOKEN_} 48 | %extra_argument {id configDelegate} 49 | %token_destructor { 50 | [$$ release]; 51 | 52 | /* quiesces unused variable compiler warning */ 53 | if (NO) [configDelegate class]; 54 | } 55 | 56 | %syntax_error { 57 | [configDelegate parseError: TOKEN]; 58 | } 59 | 60 | config_file ::= lines. 61 | lines ::= . 62 | lines ::= lines declaration. 63 | lines ::= lines section. 64 | 65 | declaration ::= KEY(key) VALUE(keyValue). { 66 | [configDelegate setKey: key value: keyValue]; 67 | [key release]; 68 | [keyValue release]; 69 | } 70 | 71 | section ::= declare_section lines SECTION_END(end). { 72 | [configDelegate endSection: end]; 73 | [end release]; 74 | } 75 | declare_section ::= SECTION_START(type) SECTION_NAME(name). { 76 | [configDelegate startSection: type sectionName: name]; 77 | [type release]; 78 | [name release]; 79 | } 80 | declare_section ::= SECTION_START(type). { 81 | [configDelegate startSection: type sectionName: nil]; 82 | [type release]; 83 | } 84 | -------------------------------------------------------------------------------- /src/TRConfigToken.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRConfigToken.h vi:ts=4:sw=4:expandtab: 3 | * Configuration Lexer Tokens 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import 40 | 41 | #import "TRObject.h" 42 | #import "TRString.h" 43 | 44 | /** 45 | * Object Data Types. 46 | * Tokens are always strings (TOKEN_DATATYPE_STRING), 47 | * but sometimes they can also be integers and booleans. 48 | * In other words, the integer and boolean datatypes should 49 | * be considered to provide a superset of functionality to the 50 | * string data type. 51 | */ 52 | typedef enum { 53 | TOKEN_DATATYPE_STRING, 54 | TOKEN_DATATYPE_INT, 55 | TOKEN_DATATYPE_BOOL 56 | } TRConfigDataType; 57 | 58 | @interface TRConfigToken : TRObject { 59 | @private 60 | /* Parser's token identifier */ 61 | int _tokenID; 62 | 63 | /* Token's line origin */ 64 | unsigned int _lineNumber; 65 | 66 | /* String value */ 67 | TRString *_string; 68 | 69 | /* Current data type */ 70 | TRConfigDataType _dataType; 71 | 72 | /* Union of internal representations */ 73 | union { 74 | int _intValue; 75 | BOOL _boolValue; 76 | } _internalRep; 77 | } 78 | 79 | - (id) initWithBytes: (const char *) data numBytes: (size_t) length lineNumber: (unsigned int) line tokenID: (int) tokenID; 80 | 81 | - (int) tokenID; 82 | - (unsigned int) lineNumber; 83 | 84 | - (TRString *) string; 85 | - (const char *) cString; 86 | - (BOOL) intValue: (int *) value; 87 | - (BOOL) boolValue: (BOOL *) value; 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /src/TREnumerator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TREnumerator.h vi:ts=4:sw=4:expandtab: 3 | * Abstract enumerator class 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import "TRObject.h" 36 | 37 | @protocol TREnumerator 38 | - (id) nextObject; 39 | @end 40 | 41 | @interface TREnumerator : TRObject 42 | - (id) nextObject; 43 | @end 44 | -------------------------------------------------------------------------------- /src/TREnumerator.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TREnumerator.m vi:ts=4:sw=4:expandtab: 3 | * Abstract enumerator class 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import "TREnumerator.h" 36 | 37 | /** 38 | * Abstract enumerator superclass. 39 | */ 40 | @implementation TREnumerator 41 | 42 | - (id) nextObject { 43 | return nil; 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /src/TRHash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRHash.h vi:ts=4:sw=4:expandtab: 3 | * Hash table 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import "hash.h" 36 | 37 | #import "TRObject.h" 38 | #import "TRString.h" 39 | #import "TREnumerator.h" 40 | 41 | @interface TRHash : TRObject { 42 | @private 43 | hash_t *_hash; 44 | } 45 | 46 | - (id) initWithCapacity: (unsigned long) numItems; 47 | - (BOOL) isFull; 48 | - (id) valueForKey: (TRString *) key; 49 | - (void) setObject: (id) anObject forKey: (TRString *) key; 50 | - (void) removeObjectForKey: (TRString *) key; 51 | - (TREnumerator *) keyEnumerator; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /src/TRLDAPAccountRepository.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPAccountRepository.h vi:ts=4:sw=4:expandtab: 3 | * 4 | * Author: Landon Fuller 5 | * 6 | * Copyright (c) 2008-2012 Three Rings Design, Inc. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. Neither the name of the copyright holder nor the names of any contributors 18 | * may be used to endorse or promote products derived from this 19 | * software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #import "TRObject.h" 35 | #import "TRString.h" 36 | 37 | #import "TRAccountRepository.h" 38 | #import "TRLDAPConnection.h" 39 | #import "TRLDAPSearchFilter.h" 40 | 41 | /** 42 | * LDAP user/group account verification. 43 | */ 44 | @interface TRLDAPAccountRepository : TRObject { 45 | @private 46 | TRLDAPConnection *_ldap; 47 | TRLDAPSearchFilter *_userFilter; 48 | TRLDAPSearchFilter *_groupFilter; 49 | } 50 | 51 | - (id) initWithLDAPConnection: (TRLDAPConnection *) ldap 52 | userSearchFilter: (TRLDAPSearchFilter *) userFilter 53 | groupSearchFilter: (TRLDAPSearchFilter *) groupFilter; 54 | 55 | - (BOOL) authenticateUser: (TRString *) username withPassword: (TRString *) password; 56 | - (BOOL) checkGroupMember: (TRString *) username withGroup: (TRString *) groupname; 57 | @end 58 | -------------------------------------------------------------------------------- /src/TRLDAPAccountRepository.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPAccountRepository.m vi:ts=4:sw=4:expandtab: 3 | * 4 | * Author: Landon Fuller 5 | * 6 | * Copyright (c) 2008 Three Rings Design, Inc. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. Neither the name of the copyright holder nor the names of any contributors 18 | * may be used to endorse or promote products derived from this 19 | * software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #import "TRLDAPAccountRepository.h" 35 | 36 | @implementation TRLDAPAccountRepository 37 | 38 | /** 39 | * Initialize a new TRLDAPAccountRepository instance with the provided 40 | * TRLDAPConnection. 41 | */ 42 | - (id) initWithLDAPConnection: (TRLDAPConnection *) ldap 43 | userSearchFilter: (TRLDAPSearchFilter *) userFilter 44 | groupSearchFilter: (TRLDAPSearchFilter *) groupFilter 45 | { 46 | /* Initialize our superclass */ 47 | self = [super init]; 48 | if (self == nil) 49 | return nil; 50 | 51 | /* Save a reference to the LDAP connection */ 52 | _ldap = [ldap retain]; 53 | _userFilter = [userFilter retain]; 54 | _groupFilter = [groupFilter retain]; 55 | 56 | return self; 57 | } 58 | 59 | - (void) dealloc { 60 | /* Release our LDAP connection. */ 61 | [_ldap release]; 62 | 63 | /* User filter. */ 64 | [_userFilter release]; 65 | 66 | /* Group filter. */ 67 | [_groupFilter release]; 68 | 69 | /* Deallocate the superclass */ 70 | [super dealloc]; 71 | } 72 | 73 | /** 74 | * Authenticate a user with the provided username and password. 75 | * From TRAccountRepository protocol. 76 | */ 77 | - (BOOL) authenticateUser: (TRString *) username withPassword: (TRString *) password { 78 | return NO; 79 | } 80 | 81 | /** 82 | * Check if the given username is a member of a group. 83 | * From TRAccountRepository protocol. 84 | */ 85 | - (BOOL) checkGroupMember: (TRString *) username withGroup: (TRString *) groupname { 86 | return NO; 87 | } 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /src/TRLDAPConnection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPConnection.h vi:ts=4:sw=4:expandtab: 3 | * Simple LDAP Wrapper 4 | * 5 | * Copyright (c) 2005 - 2007 Landon Fuller 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of Landon Fuller nor the names of any contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #import 34 | 35 | #import "TRObject.h" 36 | 37 | #import "TRLDAPEntry.h" 38 | 39 | #import "TRString.h" 40 | #import "TRArray.h" 41 | 42 | @interface TRLDAPConnection : TRObject { 43 | @private 44 | LDAP *ldapConn; 45 | int _timeout; 46 | } 47 | 48 | - (id) initWithURL: (TRString *) url timeout: (int) timeout; 49 | - (BOOL) startTLS; 50 | 51 | - (BOOL) bindWithDN: (TRString *) bindDN password: (TRString *) password; 52 | 53 | - (TRArray *) searchWithFilter: (TRString *) filter 54 | scope: (int) scope 55 | baseDN: (TRString *) base 56 | attributes: (TRArray *) attributes; 57 | - (BOOL) compare: (TRString *) dn withAttribute: (TRString *) attribute value: (TRString *) value; 58 | - (BOOL) compareDN: (TRString *) dn withAttribute: (TRString *) attribute value: (TRString *) value; 59 | 60 | - (BOOL) setReferralEnabled: (BOOL) enabled; 61 | - (BOOL) setTLSCACertFile: (TRString *) fileName; 62 | - (BOOL) setTLSCACertDir: (TRString *) directory; 63 | - (BOOL) setTLSClientCert: (TRString *) certFile keyFile: (TRString *) keyFile; 64 | - (BOOL) setTLSCipherSuite: (TRString *) cipherSuite; 65 | 66 | @end 67 | 68 | -------------------------------------------------------------------------------- /src/TRLDAPEntry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPEntry.h vi:ts=4:sw=4:expandtab: 3 | * LDAP Entry 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import "TRObject.h" 36 | #import "TRString.h" 37 | #import "TRHash.h" 38 | 39 | @interface TRLDAPEntry : TRObject { 40 | @private 41 | TRString *_dn; 42 | TRString *_rdn; 43 | TRHash *_attributes; 44 | } 45 | 46 | - (id) initWithDN: (TRString *) dn attributes: (TRHash *) attributes; 47 | - (TRString *) dn; 48 | - (TRString *) rdn; 49 | - (void) setRDN: (TRString *) rdn; 50 | - (TRHash *) attributes; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /src/TRLDAPEntry.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPEntry.m vi:ts=4:sw=4:expandtab: 3 | * LDAP Entry 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import "TRLDAPEntry.h" 36 | 37 | /** 38 | * An LDAP entry. 39 | */ 40 | @implementation TRLDAPEntry 41 | 42 | - (id) initWithDN: (TRString *) dn attributes: (TRHash *) attributes { 43 | self = [self init]; 44 | if (!self) 45 | return self; 46 | 47 | _dn = [dn retain]; 48 | _rdn = nil; 49 | _attributes = [attributes retain]; 50 | 51 | return self; 52 | } 53 | 54 | - (void) dealloc { 55 | [_dn release]; 56 | [_rdn release]; 57 | [_attributes release]; 58 | [super dealloc]; 59 | } 60 | 61 | /** 62 | * Returns the entry's distinguished name. 63 | */ 64 | - (TRString *) dn { 65 | return _dn; 66 | } 67 | 68 | - (TRString *) rdn { 69 | return _rdn; 70 | } 71 | 72 | - (void) setRDN: (TRString *) rdn { 73 | _rdn=rdn; 74 | } 75 | 76 | /** 77 | * Return the entries' attributes as a dictionary. 78 | */ 79 | - (TRHash *) attributes { 80 | return _attributes; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /src/TRLDAPGroupConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPGroupConfig.h vi:ts=4:sw=4:expandtab: 3 | * LDAP Group Configuration 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import "TRObject.h" 36 | #import "TRString.h" 37 | 38 | @interface TRLDAPGroupConfig : TRObject { 39 | @private 40 | TRString *_baseDN; 41 | TRString *_searchFilter; 42 | TRString *_memberAttribute; 43 | BOOL _memberRFC2307BIS; 44 | BOOL _useCompareOperation; 45 | TRString *_pfTable; 46 | } 47 | 48 | - (TRString *) baseDN; 49 | - (void) setBaseDN: (TRString *) baseDN; 50 | 51 | - (TRString *) searchFilter; 52 | - (void) setSearchFilter: (TRString *) searchFilter; 53 | 54 | - (TRString *) memberAttribute; 55 | - (void) setMemberAttribute: (TRString *) memberAttribute; 56 | 57 | - (BOOL) memberRFC2307BIS; 58 | - (void) setMemberRFC2307BIS: (BOOL) memberRFC2307BIS; 59 | 60 | - (BOOL) useCompareOperation; 61 | - (void) setUseCompareOperation: (BOOL) useCompareOperation; 62 | 63 | - (TRString *) pfTable; 64 | - (void) setPFTable: (TRString *) tableName; 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /src/TRLDAPGroupConfig.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPGroupConfig.m vi:ts=4:sw=4:expandtab: 3 | * LDAP Group Configuration 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import 36 | 37 | #import "TRLDAPGroupConfig.h" 38 | 39 | @implementation TRLDAPGroupConfig 40 | - (void) dealloc { 41 | if (_baseDN) 42 | [_baseDN release]; 43 | 44 | if (_searchFilter) 45 | [_searchFilter release]; 46 | 47 | if (_memberAttribute) 48 | [_memberAttribute release]; 49 | 50 | if (_pfTable) 51 | [_pfTable release]; 52 | 53 | [super dealloc]; 54 | } 55 | 56 | - (id) init { 57 | self = [super init]; 58 | if (self == nil) 59 | return self; 60 | 61 | _memberRFC2307BIS = YES; 62 | _useCompareOperation = YES; 63 | return self; 64 | } 65 | 66 | - (TRString *) baseDN { 67 | return (_baseDN); 68 | } 69 | 70 | - (void) setBaseDN: (TRString *) baseDN { 71 | if (_baseDN) 72 | [_baseDN release]; 73 | _baseDN = [baseDN retain]; 74 | } 75 | 76 | - (TRString *) searchFilter { 77 | return (_searchFilter); 78 | } 79 | 80 | - (void) setSearchFilter: (TRString *) searchFilter { 81 | if (_searchFilter) 82 | [_searchFilter release]; 83 | _searchFilter = [searchFilter retain]; 84 | } 85 | 86 | - (TRString *) memberAttribute { 87 | return (_memberAttribute); 88 | } 89 | 90 | - (void) setMemberAttribute: (TRString *) memberAttribute { 91 | if (_memberAttribute) 92 | [_memberAttribute release]; 93 | _memberAttribute = [memberAttribute retain]; 94 | } 95 | 96 | - (BOOL) memberRFC2307BIS { 97 | return (_memberRFC2307BIS); 98 | } 99 | 100 | - (void) setMemberRFC2307BIS: (BOOL) memberRFC2307BIS { 101 | _memberRFC2307BIS = memberRFC2307BIS; 102 | } 103 | 104 | - (BOOL) useCompareOperation { 105 | return (_useCompareOperation); 106 | } 107 | 108 | - (void) setUseCompareOperation: (BOOL) useCompareOperation { 109 | _useCompareOperation = useCompareOperation; 110 | } 111 | 112 | - (void) setPFTable: (TRString *) tableName { 113 | if (_pfTable) 114 | [_pfTable release]; 115 | _pfTable = [tableName retain]; 116 | } 117 | 118 | - (TRString *) pfTable { 119 | return (_pfTable); 120 | } 121 | 122 | @end 123 | -------------------------------------------------------------------------------- /src/TRLDAPSearchFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPSearchFilter.h vi:ts=4:sw=4:expandtab: 3 | * LDAP Search Filter Generator 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import "TRObject.h" 36 | #import "TRString.h" 37 | 38 | @interface TRLDAPSearchFilter : TRObject { 39 | @private 40 | TRString *_format; 41 | } 42 | 43 | - (id) initWithFormat: (TRString *) format; 44 | - (TRString *) getFilter: (TRString *) subString; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /src/TRLocalPacketFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLocalPacketFilter.h vi:ts=4:sw=4:expandtab: 3 | * Interface to local OpenBSD /dev/pf 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #ifdef HAVE_PF 40 | 41 | #import "TRObject.h" 42 | #import "TRPacketFilter.h" 43 | #import "TRArray.h" 44 | #import "TRPFAddress.h" 45 | #import "TRString.h" 46 | 47 | /* pf includes */ 48 | #import 49 | #import 50 | #import 51 | #import 52 | #import 53 | 54 | @interface TRLocalPacketFilter : TRObject { 55 | @private 56 | /** Cached reference to /dev/pf. */ 57 | int _fd; 58 | } 59 | 60 | - (pferror_t) open; 61 | - (void) close; 62 | 63 | - (pferror_t) tables: (TRArray **) result; 64 | - (pferror_t) flushTable: (TRString *) tableName; 65 | - (pferror_t) addAddress: (TRPFAddress *) address toTable: (TRString *) tableName; 66 | - (pferror_t) deleteAddress: (TRPFAddress *) address fromTable: (TRString *) tableName; 67 | - (pferror_t) addressesFromTable: (TRString *) tableName withResult: (TRArray **) result; 68 | 69 | @end 70 | 71 | #endif /* HAVE_PF */ 72 | -------------------------------------------------------------------------------- /src/TRLog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLog.h vi:ts=4:sw=4:expandtab: 3 | * Simple logging interface 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import "TRObject.h" 36 | 37 | typedef enum { 38 | TRLOG_ERR, 39 | TRLOG_WARNING, 40 | TRLOG_INFO, 41 | TRLOG_DEBUG 42 | } loglevel_t; 43 | 44 | @interface TRLog : TRObject 45 | 46 | + (void) _quiesceLogging: (BOOL) quiesce; 47 | 48 | #define DO_LOG_DECL(logName) \ 49 | /** Log a logname message */ \ 50 | + (void) logName: (const char *) message, ...; 51 | 52 | DO_LOG_DECL(error); 53 | DO_LOG_DECL(warning); 54 | DO_LOG_DECL(info); 55 | DO_LOG_DECL(debug); 56 | 57 | + (void) log: (loglevel_t) level withMessage: (const char *) message, ...; 58 | 59 | #undef DO_LOG_DECL 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /src/TRLog.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLog.m vi:ts=4:sw=4:expandtab: 3 | * Simple logging interface 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import 36 | #import 37 | #import 38 | 39 | #import "TRLog.h" 40 | 41 | static BOOL _quiesce = NO; 42 | 43 | /** Log a message to stderr. */ 44 | static void log_stderr(const char *message, va_list args) { 45 | /* Log the message to stderr */ 46 | vfprintf(stderr, message, args); 47 | fprintf(stderr, "\n"); 48 | } 49 | 50 | /** Log a message to syslog. */ 51 | static void log_syslog(int priority, const char *message, va_list args) { 52 | vsyslog(priority, message, args); 53 | } 54 | 55 | /** 56 | * OpenVPN Auth-LDAP Logger. 57 | */ 58 | @implementation TRLog 59 | 60 | /** 61 | * Private method that quiets all logging for the purpose of unit testing. 62 | */ 63 | + (void) _quiesceLogging: (BOOL) quiesce { 64 | _quiesce = quiesce; 65 | } 66 | 67 | #define DO_LOG(logName, priority) \ 68 | /** Log a priority message. */ \ 69 | + (void) logName: (const char *) message, ... { \ 70 | va_list ap; \ 71 | if (_quiesce) return; \ 72 | va_start(ap, message); \ 73 | log_syslog(priority, message, ap); \ 74 | va_end(ap); \ 75 | va_start(ap, message); \ 76 | log_stderr(message, ap); \ 77 | va_end(ap); \ 78 | } 79 | 80 | DO_LOG(error, LOG_ERR); 81 | DO_LOG(warning, LOG_WARNING); 82 | DO_LOG(info, LOG_INFO); 83 | DO_LOG(debug, LOG_DEBUG); 84 | 85 | #undef DO_LOG 86 | 87 | /** 88 | * Log a message with the supplied priority. 89 | */ 90 | + (void) log: (loglevel_t) level withMessage: (const char *) message, ... { 91 | va_list ap; 92 | int priority = LOG_ERR; 93 | 94 | /* Logging quiesced for debugging. */ 95 | if (_quiesce) return; 96 | 97 | /* Map the TRLog log level to a syslog priority. */ 98 | switch (level) { 99 | case TRLOG_ERR: 100 | priority = LOG_ERR; 101 | break; 102 | case TRLOG_WARNING: 103 | priority = LOG_WARNING; 104 | break; 105 | case TRLOG_INFO: 106 | priority = LOG_INFO; 107 | break; 108 | case TRLOG_DEBUG: 109 | priority = LOG_DEBUG; 110 | break; 111 | } 112 | 113 | /* Log the message to syslog */ 114 | va_start(ap, message); 115 | log_syslog(priority, message, ap); 116 | va_end(ap); 117 | 118 | /* Log the message to stderr */ 119 | va_start(ap, message); 120 | log_stderr(message, ap); 121 | va_end(ap); 122 | } 123 | 124 | 125 | @end 126 | -------------------------------------------------------------------------------- /src/TRObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRObject.h vi:ts=4:sw=4:expandtab: 3 | * Project Root Class 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2007 Landon Fuller 8 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the copyright holder nor the names of any contributors 20 | * may be used to endorse or promote products derived from this 21 | * software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifdef HAVE_CONFIG_H 37 | #import 38 | #endif 39 | 40 | #import 41 | #import 42 | #include 43 | 44 | #import "PXObjCRuntime.h" 45 | 46 | #import 47 | 48 | @protocol TRObject 49 | 50 | /** 51 | * Return the current object retain count. This does not take into account any enqueued autorelease calls, 52 | * and should generally not be used. 53 | */ 54 | - (PXUInteger) retainCount; 55 | 56 | /** 57 | * Retain a reference to the receiver, incrementing the reference count. 58 | */ 59 | - (id) retain; 60 | 61 | /** 62 | * Release a reference to the receiver, decrementing the reference count. If the reference count reaches zero, 63 | * the receiver will be deallocated. 64 | */ 65 | - (oneway void) release; 66 | 67 | /** 68 | * Add the object to the current autorelease pool. Objects in the autorelease 69 | * pool will be released at a later time. 70 | * @result Returns a reference to the receiver. 71 | */ 72 | - (id) autorelease; 73 | 74 | /** 75 | * Return the receiver's class. 76 | */ 77 | - (Class) class; 78 | 79 | /** 80 | * Return YES if the receiver is equal to @a anObject. 81 | * 82 | * The default implementation of this method performs a check for pointer equality. Subclasses may override this 83 | * method to check for value equality. 84 | * 85 | * @note If two objects are equal, they must also have the same hash value. 86 | */ 87 | - (BOOL) isEqual: (id) anObject; 88 | 89 | /** 90 | * Returns an unsigned integer that may be used as a table address in a hash table structure. 91 | * 92 | * The value returned by this method must not change while the object is part of a collection 93 | * that uses hash values to determine collection position. 94 | */ 95 | - (PXUInteger) hash; 96 | 97 | /** 98 | * Returns YES if the receiver is an instance of the given @a cls, or any class that inherits 99 | * from cls. 100 | * 101 | * @param cls The class against which the receiver's class will be tested. 102 | */ 103 | - (BOOL) isKindOfClass: (Class) cls; 104 | 105 | @end 106 | 107 | 108 | @interface TRObject { 109 | @private 110 | id isa; 111 | PXUInteger _refCount; 112 | } 113 | 114 | + (id) alloc; 115 | 116 | - (id) init; 117 | 118 | - (void) dealloc; 119 | 120 | @end 121 | -------------------------------------------------------------------------------- /src/TRObject.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRObject.m vi:ts=4:sw=4:expandtab: 3 | * Project Root Class 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import 36 | #import 37 | 38 | #import "TRObject.h" 39 | #import "TRAutoreleasePool.h" 40 | 41 | #import 42 | 43 | /** 44 | * Base class. Handles reference counting and equality. 45 | */ 46 | @implementation TRObject 47 | 48 | /** 49 | * Allocate a new instance of the receiver. 50 | */ 51 | + (id) alloc { 52 | return class_createInstance(self, 0); 53 | } 54 | 55 | /** 56 | * Return the receiver's class. 57 | */ 58 | + (Class) class { 59 | return self; 60 | } 61 | 62 | /** 63 | * Implemented by subclasses to initialize a newly allocated object. The default 64 | * implementation performs no initialization. 65 | */ 66 | - (id) init { 67 | _refCount = 1; 68 | return self; 69 | } 70 | 71 | /** 72 | * Called upon deallocation of the receiver. Responsible for discarding all resources held by the 73 | * receiver. 74 | * 75 | * This method will be called automatically when the receiver's reference count reaches 0. It should 76 | * never be called directly. As an exception to this, subclass implementations of -dealloc must 77 | * incorporate the superclass implementation through a message to super. 78 | */ 79 | - (void) dealloc { 80 | object_dispose(self); 81 | } 82 | 83 | // from TRObject protocol 84 | - (Class) class { 85 | return object_getClass(self); 86 | } 87 | 88 | // from TRObject protocol 89 | - (BOOL) isEqual: (id) anObject { 90 | if (self == anObject) 91 | return YES; 92 | else 93 | return NO; 94 | } 95 | 96 | // from TRObject protocol 97 | - (PXUInteger) hash { 98 | assert(sizeof(PXUInteger) >= sizeof(uintptr_t)); 99 | return (PXUInteger) self; 100 | } 101 | 102 | // from TRObject protocol 103 | - (BOOL) isKindOfClass: (Class) cls { 104 | Class selfClass = [self class]; 105 | 106 | for (Class superClass = selfClass; superClass != NULL; superClass = class_getSuperclass(superClass)) { 107 | if (superClass == cls) 108 | return YES; 109 | } 110 | 111 | return NO; 112 | } 113 | 114 | // from TRObject protocol 115 | - (PXUInteger) retainCount { 116 | return _refCount; 117 | } 118 | 119 | // from TRObject protocol 120 | - (id) retain { 121 | _refCount++; 122 | return self; 123 | } 124 | 125 | // from TRObject protocol 126 | - (oneway void) release { 127 | /* This must never occur */ 128 | assert(_refCount >= 1); 129 | 130 | /* Decrement refcount, if zero, dealloc */ 131 | _refCount--; 132 | if (!_refCount) 133 | [self dealloc]; 134 | } 135 | 136 | // from TRObject protocol 137 | - (id) autorelease { 138 | [TRAutoreleasePool addObject: self]; 139 | return self; 140 | } 141 | 142 | /* Don't auto-release the class object! */ 143 | + (id) autorelease { 144 | return self; 145 | } 146 | 147 | @end 148 | -------------------------------------------------------------------------------- /src/TRPFAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRPFAddress.h vi:ts=4:sw=4:expandtab: 3 | * OpenBSD PF Address 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import "TRObject.h" 40 | #import "TRString.h" 41 | 42 | #import 43 | #import 44 | #import 45 | #import 46 | #import 47 | 48 | typedef struct { 49 | sa_family_t family; 50 | union { 51 | struct in_addr ip4_addr; 52 | struct in6_addr ip6_addr; 53 | }; 54 | uint8_t netmask; 55 | } TRPortableAddress; 56 | 57 | @interface TRPFAddress : TRObject { 58 | @private 59 | TRPortableAddress _addr; 60 | } 61 | 62 | - (id) initWithPresentationAddress: (TRString *) address; 63 | - (id) initWithPortableAddress: (TRPortableAddress *) address; 64 | - (void) address: (TRPortableAddress *) addr; 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /src/TRPFAddress.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRPFAddress.m vi:ts=4:sw=4:expandtab: 3 | * OpenBSD PF Address 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import 36 | 37 | #import "TRPFAddress.h" 38 | 39 | /** 40 | * Represents a single IPv4 or IPv6 address, for use with PF. 41 | */ 42 | @implementation TRPFAddress 43 | 44 | - (id) init { 45 | self = [super init]; 46 | if (!self) 47 | return self; 48 | 49 | /* Initialize the TRPortableAddress structure */ 50 | memset(&_addr, 0, sizeof(_addr)); 51 | 52 | return self; 53 | } 54 | 55 | /** 56 | * Initialize with an IPv4 or IPv6 address string. 57 | * @param address An IPv4 or IPv6 address in human-readable format (eg 127.0.0.1 or ::1) 58 | */ 59 | - (id) initWithPresentationAddress: (TRString *) address { 60 | if (![self init]) 61 | return nil; 62 | 63 | /* Try IPv4, then IPv6 */ 64 | if (inet_pton(AF_INET, [address cString], &_addr.ip4_addr)) { 65 | _addr.family = AF_INET; 66 | _addr.netmask = 32; 67 | return self; 68 | } else if(inet_pton(AF_INET6, [address cString], &_addr.ip6_addr)) { 69 | _addr.family = AF_INET6; 70 | _addr.netmask = 128; 71 | return self; 72 | } 73 | 74 | /* Fall through */ 75 | [self release]; 76 | return nil; 77 | } 78 | 79 | /** 80 | * Initialize from the provided TRPortableAddress representation. 81 | */ 82 | - (id) initWithPortableAddress: (TRPortableAddress *) address { 83 | if (![self init]) 84 | return nil; 85 | 86 | memcpy(&_addr, address, sizeof(_addr)); 87 | return self; 88 | } 89 | 90 | 91 | /** 92 | * Copies the address' TRPortableAddress representation 93 | * to the provided destination pointer. 94 | */ 95 | - (void) address: (TRPortableAddress *) dest { 96 | memcpy(dest, &_addr, sizeof(*dest)); 97 | } 98 | 99 | @end 100 | -------------------------------------------------------------------------------- /src/TRPacketFilter.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLocalPacketFilter.m vi:ts=4:sw=4:expandtab: 3 | * Interface to local OpenBSD /dev/pf 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import 36 | #import 37 | #import 38 | #import 39 | #import 40 | #import 41 | 42 | #import "TRPacketFilter.h" 43 | 44 | /** 45 | * Packet Filter Utility Class 46 | */ 47 | @implementation TRPacketFilterUtil 48 | 49 | + (char *) stringForError: (pferror_t) error { 50 | switch (error) { 51 | case PF_SUCCESS: 52 | return "No error"; 53 | case PF_ERROR_NOT_FOUND: 54 | return "Not found"; 55 | case PF_ERROR_INVALID_NAME: 56 | return "Invalid name"; 57 | case PF_ERROR_UNAVAILABLE: 58 | return "Unavailable"; 59 | case PF_ERROR_PERMISSION: 60 | return "Permission denied"; 61 | case PF_ERROR_INVALID_ARGUMENT: 62 | return "Invalid argument"; 63 | case PF_ERROR_INTERNAL: 64 | return "Internal error"; 65 | case PF_ERROR_UNKNOWN: 66 | return "Unknown error"; 67 | } 68 | 69 | abort(); 70 | return "Unreachable"; 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /src/TRString.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRString.h vi:ts=4:sw=4:expandtab: 3 | * Brain-dead Dynamic Strings 4 | * 5 | * Copyright (c) 2005 - 2007 Landon Fuller 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of Landon Fuller nor the names of any contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifdef HAVE_CONFIG_H 34 | #import 35 | #endif 36 | 37 | #import 38 | 39 | #import "TRObject.h" 40 | 41 | @interface TRString : TRObject { 42 | @private 43 | char *bytes; 44 | size_t numBytes; 45 | } 46 | 47 | + (TRString *) stringWithFormat: (const char *) format, ...; 48 | + (TRString *) stringWithCString: (const char *) cString; 49 | 50 | - (id) initWithFormat: (const char *) format arguments: (va_list) arguments; 51 | - (id) initWithCString: (const char *) cString; 52 | - (id) initWithString: (TRString *) string; 53 | - (id) initWithBytes: (const char *) data numBytes: (size_t) length; 54 | 55 | - (const char *) cString; 56 | - (size_t) length; 57 | 58 | - (BOOL) intValue: (int *) value; 59 | 60 | - (size_t) indexToCString: (const char *) cString; 61 | - (size_t) indexToCharset: (const char *) cString; 62 | 63 | - (char) charAtIndex: (size_t) index; 64 | - (TRString *) substringToIndex: (size_t) index; 65 | - (TRString *) substringFromIndex: (size_t) index; 66 | - (TRString *) substringToCString: (const char *) cString; 67 | - (TRString *) substringFromCString: (const char *) cString; 68 | - (TRString *) substringToCharset: (const char *) cString; 69 | - (TRString *) substringFromCharset: (const char *) cString; 70 | 71 | - (void) appendChar: (char) c; 72 | - (void) appendCString: (const char *) cString; 73 | - (void) appendString: (TRString *) string; 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /src/TRVPNPlugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRVPNPlugin.h vi:ts=4:sw=4:expandtab: 3 | * Base Include File 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2007 Landon Fuller 8 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the copyright holder nor the names of any contributors 20 | * may be used to endorse or promote products derived from this 21 | * software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef TRVPNPLUGIN_H 37 | #define TRVPNPLUGIN_H 38 | 39 | #ifdef HAVE_CONFIG_H 40 | #import 41 | #endif 42 | 43 | #import "TRObject.h" 44 | #import "TRLog.h" 45 | 46 | #import "TRString.h" 47 | #import "TREnumerator.h" 48 | #import "TRArray.h" 49 | #import "TRAutoreleasePool.h" 50 | #import "TRHash.h" 51 | #import "xmalloc.h" 52 | 53 | #import "TRAccountRepository.h" 54 | #import "TRVPNSession.h" 55 | 56 | #import "TRConfigToken.h" 57 | #import "TRConfig.h" 58 | #import "TRConfigParser.h" 59 | #import "TRAuthLDAPConfig.h" 60 | #import "TRConfigLexer.h" 61 | #import "TRLDAPGroupConfig.h" 62 | 63 | #import "TRLDAPConnection.h" 64 | #import "TRLDAPEntry.h" 65 | #import "TRLDAPSearchFilter.h" 66 | #import "TRLDAPAccountRepository.h" 67 | 68 | #import "TRPFAddress.h" 69 | #import "TRPacketFilter.h" 70 | #import "TRLocalPacketFilter.h" 71 | 72 | #endif /* TRVPNPLUGIN_H */ 73 | -------------------------------------------------------------------------------- /src/TRVPNSession.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TRVPNSession.h vi:ts=4:sw=4:expandtab: 3 | * An active VPN session 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import "TRObject.h" 36 | #import "TRString.h" 37 | 38 | @interface TRVPNSession: TRObject { 39 | @private 40 | TRString *_username; 41 | } 42 | 43 | - (id) initWithUsername: (TRString *) username; 44 | - (TRString *) username; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /src/TRVPNSession.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRVPNSession.m vi:ts=4:sw=4:expandtab: 3 | * An active VPN session 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #import "TRVPNSession.h" 36 | 37 | /** 38 | * VPN session state. 39 | */ 40 | @implementation TRVPNSession 41 | 42 | - (id) initWithUsername: (TRString *) username { 43 | self = [self init]; 44 | if (!self) 45 | return nil; 46 | 47 | _username = [username retain]; 48 | return (self); 49 | } 50 | 51 | - (void) dealloc { 52 | [_username release]; 53 | [super dealloc]; 54 | } 55 | 56 | - (TRString *) username { 57 | return (_username); 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /src/asprintf.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/threerings/openvpn-auth-ldap/dbc13845739c28343771c5c282b1e3aea485b23b/src/asprintf.c -------------------------------------------------------------------------------- /src/base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. 7 | * 8 | * This file contains Original Code and/or Modifications of Original Code 9 | * as defined in and that are subject to the Apple Public Source License 10 | * Version 2.0 (the 'License'). You may not use this file except in 11 | * compliance with the License. Please obtain a copy of the License at 12 | * http://www.opensource.apple.com/apsl/ and read it before using this 13 | * file. 14 | * 15 | * The Original Code and all software distributed under the License are 16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 20 | * Please see the License for the specific language governing rights and 21 | * limitations under the License. 22 | * 23 | * @APPLE_LICENSE_HEADER_END@ 24 | */ 25 | /* ==================================================================== 26 | * Copyright (c) 1995-1999 The Apache Group. All rights reserved. 27 | * 28 | * Redistribution and use in source and binary forms, with or without 29 | * modification, are permitted provided that the following conditions 30 | * are met: 31 | * 32 | * 1. Redistributions of source code must retain the above copyright 33 | * notice, this list of conditions and the following disclaimer. 34 | * 35 | * 2. Redistributions in binary form must reproduce the above copyright 36 | * notice, this list of conditions and the following disclaimer in 37 | * the documentation and/or other materials provided with the 38 | * distribution. 39 | * 40 | * 3. All advertising materials mentioning features or use of this 41 | * software must display the following acknowledgment: 42 | * "This product includes software developed by the Apache Group 43 | * for use in the Apache HTTP server project (http://www.apache.org/)." 44 | * 45 | * 4. The names "Apache Server" and "Apache Group" must not be used to 46 | * endorse or promote products derived from this software without 47 | * prior written permission. For written permission, please contact 48 | * apache@apache.org. 49 | * 50 | * 5. Products derived from this software may not be called "Apache" 51 | * nor may "Apache" appear in their names without prior written 52 | * permission of the Apache Group. 53 | * 54 | * 6. Redistributions of any form whatsoever must retain the following 55 | * acknowledgment: 56 | * "This product includes software developed by the Apache Group 57 | * for use in the Apache HTTP server project (http://www.apache.org/)." 58 | * 59 | * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY 60 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 61 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 62 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR 63 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 64 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 65 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 66 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 67 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 68 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 69 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 70 | * OF THE POSSIBILITY OF SUCH DAMAGE. 71 | * ==================================================================== 72 | * 73 | * This software consists of voluntary contributions made by many 74 | * individuals on behalf of the Apache Group and was originally based 75 | * on public domain software written at the National Center for 76 | * Supercomputing Applications, University of Illinois, Urbana-Champaign. 77 | * For more information on the Apache Group and the Apache HTTP server 78 | * project, please see . 79 | * 80 | */ 81 | 82 | 83 | 84 | #ifndef _BASE64_H_ 85 | #define _BASE64_H_ 86 | 87 | #ifdef __cplusplus 88 | extern "C" { 89 | #endif 90 | 91 | int Base64encode_len(int len); 92 | int Base64encode(char * coded_dst, const char *plain_src,int len_plain_src); 93 | 94 | int Base64decode_len(const char * coded_src); 95 | int Base64decode(char * plain_dst, const char *coded_src); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif //_BASE64_H_ 102 | -------------------------------------------------------------------------------- /src/openvpn-cr.c: -------------------------------------------------------------------------------- 1 | #include "openvpn-cr.h" 2 | 3 | #include "base64.h" 4 | #include 5 | 6 | static const char * static_cr_label = "SCRV1"; 7 | static const char * dynamic_cr_label = "CRV1"; 8 | 9 | int set_token_b64(const char * source, char * destination) 10 | { 11 | if (Base64decode_len(source) >= MAXTOKENLENGTH) 12 | return 0; 13 | Base64decode(destination, source); 14 | return 1; 15 | } 16 | 17 | int set_token(const char * source, char * destination) 18 | { 19 | if (strlen(source) >= MAXTOKENLENGTH) 20 | return 0; 21 | strncpy(destination, source, MAXTOKENLENGTH); 22 | return 1; 23 | } 24 | 25 | 26 | int extract_openvpn_cr(const char *response, openvpn_response *result, char **error_message) 27 | { 28 | const char *tokenIndexes[15]; 29 | tokenIndexes[0] = response; 30 | int tokenCnt = 1; 31 | const char *p; 32 | for (p = response; *p; ++p) { 33 | if (*p == ':') 34 | tokenIndexes[tokenCnt++] = p + 1; 35 | } 36 | 37 | if (tokenCnt == 3 && strstr(response, static_cr_label) == response) 38 | { 39 | if (!set_token(static_cr_label, result->protocol)){ 40 | *error_message = "Unable to set static protocol information."; 41 | return 0; 42 | } 43 | 44 | if (!set_token_b64(tokenIndexes[1], result->password)) { 45 | *error_message = "Unable to extract password from static cr."; 46 | return 0; 47 | } 48 | 49 | if (!set_token_b64(tokenIndexes[2], result->response)) { 50 | *error_message = "Unable to extract response from static cr."; 51 | return 0; 52 | } 53 | } 54 | else if (tokenCnt == 5 && strstr(response, dynamic_cr_label) == response) { 55 | if (!set_token(dynamic_cr_label, result->protocol)) { 56 | *error_message = "Unable to set dynamic protocol information."; 57 | return 0; 58 | } 59 | 60 | if (!set_token_b64(tokenIndexes[2], result->password)) { 61 | *error_message = "Unable to extract password from dynamic cr."; 62 | return 0; 63 | } 64 | 65 | if (!set_token_b64(tokenIndexes[4], result->response)) { 66 | *error_message = "Unable to extract response from dynamic cr."; 67 | return 0; 68 | } 69 | } 70 | else { 71 | *error_message = "Incorrectly formatted cr string."; 72 | return 0; 73 | } 74 | return 1; 75 | } 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/openvpn-cr.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENVPN_CR_H 2 | #define OPENVPN_CR_H 3 | 4 | #define MAXTOKENLENGTH 1024 5 | 6 | typedef struct 7 | { 8 | char protocol[6]; 9 | char password[MAXTOKENLENGTH]; 10 | char response[MAXTOKENLENGTH]; 11 | } openvpn_response; 12 | 13 | /* Parse a string containing an openvpn response and store the result 14 | into an openvpn_response struct. 15 | If parsing succeeds result will be in result and 1 is returned. 16 | If parsing fails, 0 is returned, error_message is set */ 17 | int extract_openvpn_cr(const char *response, openvpn_response *result, char **error_message); 18 | 19 | #endif -------------------------------------------------------------------------------- /src/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1998 Todd C. Miller 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 19 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 20 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifdef HAVE_CONFIG_H 31 | #include 32 | #endif /* HAVE_CONFIG_H */ 33 | 34 | #ifndef HAVE_STRLCPY 35 | 36 | #include 37 | #include 38 | 39 | /* 40 | * Copy src to string dst of size siz. At most siz-1 characters 41 | * will be copied. Always NUL terminates (unless siz == 0). 42 | * Returns strlen(src); if retval >= siz, truncation occurred. 43 | */ 44 | size_t strlcpy(dst, src, siz) 45 | char *dst; 46 | const char *src; 47 | size_t siz; 48 | { 49 | char *d = dst; 50 | const char *s = src; 51 | size_t n = siz; 52 | 53 | /* Copy as many bytes as will fit */ 54 | if (n != 0 && --n != 0) { 55 | do { 56 | if ((*d++ = *s++) == 0) 57 | break; 58 | } while (--n != 0); 59 | } 60 | 61 | /* Not enough room in dst, add NUL and traverse rest of src */ 62 | if (n == 0) { 63 | if (siz != 0) 64 | *d = '\0'; /* NUL-terminate dst */ 65 | while (*s++) 66 | ; 67 | } 68 | 69 | return(s - src - 1); /* count does not include NUL */ 70 | } 71 | 72 | #endif /* HAVE_STRLCPY */ 73 | -------------------------------------------------------------------------------- /src/strlcpy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998 Todd C. Miller 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 18 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 19 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include 30 | #endif 31 | 32 | #ifndef HAVE_STRLCPY 33 | size_t strlcpy(char *dst, const char *src, size_t siz); 34 | #endif /* HAVE_STRLCPY */ 35 | -------------------------------------------------------------------------------- /src/xmalloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * xmalloc.c vi:ts=4:sw=4:expandtab: 3 | * "Safe" malloc routines -- and by safe, I mean: "fail quickly" 4 | * 5 | * Copyright (c) 2005 - 2007 Landon Fuller 6 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. Neither the name of Landon Fuller nor the names of any contributors 18 | * may be used to endorse or promote products derived from this 19 | * software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | /* Safe Malloc */ 39 | void *xmalloc(size_t size) { 40 | void *ptr; 41 | ptr = malloc(size); 42 | if (!ptr) 43 | err(1, "malloc returned NULL"); 44 | 45 | return (ptr); 46 | } 47 | 48 | void *xrealloc(void *oldptr, size_t size) { 49 | void *ptr; 50 | ptr = realloc(oldptr, size); 51 | if (!ptr) 52 | err(1, "realloc returned NULL"); 53 | 54 | oldptr = ptr; 55 | 56 | return (ptr); 57 | } 58 | 59 | char *xstrdup(const char *str) { 60 | void *ptr; 61 | ptr = strdup(str); 62 | if (!ptr) 63 | err(1, "strdup returned NULL"); 64 | 65 | return (ptr); 66 | } 67 | -------------------------------------------------------------------------------- /src/xmalloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * xmalloc.h vi:ts=4:sw=4:expandtab: 3 | * 4 | * "Safe" malloc routines -- and by safe, I mean "fail quickly" 5 | * 6 | * Copyright (c) 2006 Three Rings Design, Inc. 7 | * Copyright (c) 2005 - 2006 Landon Fuller 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Landon Fuller nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef MALLOC_H 36 | #define MALLOC_H 37 | 38 | #include 39 | 40 | void *xmalloc(size_t size); 41 | void *xrealloc(void *ptr, size_t size); 42 | char *xstrdup(const char *str); 43 | 44 | #endif /* MALLOC_H */ 45 | -------------------------------------------------------------------------------- /tests/Makefile.in: -------------------------------------------------------------------------------- 1 | srcdir= @srcdir@ 2 | top_srcdir= @top_srcdir@ 3 | top_builddir= @top_builddir@ 4 | VPATH= @srcdir@ 5 | 6 | include ${top_builddir}/Mk/autoconf.mk 7 | include ${top_builddir}/Mk/compile.mk 8 | include ${top_builddir}/Mk/subdir.mk 9 | 10 | TEST_OBJS= tests.o \ 11 | PXTestAssert.o \ 12 | PXTestCase.o \ 13 | PXTestCaseRunner.o \ 14 | PXTestConsoleResultHandler.o \ 15 | PXTestException.o \ 16 | TRArrayTests.o \ 17 | TRAuthLDAPConfigTests.o \ 18 | TRAutoreleasePoolTests.o \ 19 | TRConfigLexerTests.o \ 20 | TRConfigTests.o \ 21 | TRConfigTokenTests.o \ 22 | TRHashTests.o \ 23 | TRLDAPAccountRepositoryTests.o \ 24 | TRLDAPConnectionTests.o \ 25 | TRLDAPEntryTests.o \ 26 | TRLDAPGroupConfigTests.o \ 27 | TRLDAPSearchFilterTests.o \ 28 | TRLocalPacketFilterTests.o \ 29 | TRObjectTests.o \ 30 | mockpf.o \ 31 | TRPFAddressTests.o \ 32 | TRStringTests.o \ 33 | TRVPNSessionTests.o 34 | 35 | CFLAGS+= -DTEST_DATA=\"${srcdir}/data\" 36 | OBJCFLAGS+= -DTEST_DATA=\"${srcdir}/data\" 37 | 38 | LIBS+= -L${top_builddir}/src -lauth-ldap \ 39 | $(OBJC_LIBS) $(LDAP_LIBS) 40 | 41 | LDFLAGS+= $(LIBS) 42 | 43 | # File Substitutions 44 | EDIT= sed \ 45 | -e 's,@TEST_DATA\@,$(srcdir)/data,g' 46 | 47 | # Recompile the tests every time 48 | all:: tests 49 | 50 | # Generate any headers before subdirs are traversed 51 | pre-all:: 52 | 53 | # Generated File(s) 54 | tests.h: tests.h.in 55 | $(EDIT) $(srcdir)/tests.h.in > $@ 56 | 57 | tests: ${TEST_OBJS} ../src/libauth-ldap.a 58 | ${CC} -o $@ ${TEST_OBJS} ${LDFLAGS} 59 | 60 | test:: tests 61 | ./tests 62 | 63 | install:: 64 | 65 | clean:: 66 | rm -f $(TEST_OBJS) tests 67 | 68 | distclean:: clean 69 | rm -f Makefile 70 | -------------------------------------------------------------------------------- /tests/PXTestAssert.m: -------------------------------------------------------------------------------- 1 | // 2 | // Derived from GTMSenTestCase.h 3 | // 4 | // Copyright 2007-2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | // use this file except in compliance with the License. You may obtain a copy 8 | // of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | // License for the specific language governing permissions and limitations under 16 | // the License. 17 | // 18 | 19 | // Portions of this file fall under the following license, marked with 20 | // SENTE_BEGIN - SENTE_END 21 | // 22 | // Copyright (c) 1997-2005, Sen:te (Sente SA). All rights reserved. 23 | // 24 | // Use of this source code is governed by the following license: 25 | // 26 | // Redistribution and use in source and binary forms, with or without modification, 27 | // are permitted provided that the following conditions are met: 28 | // 29 | // (1) Redistributions of source code must retain the above copyright notice, 30 | // this list of conditions and the following disclaimer. 31 | // 32 | // (2) Redistributions in binary form must reproduce the above copyright notice, 33 | // this list of conditions and the following disclaimer in the documentation 34 | // and/or other materials provided with the distribution. 35 | // 36 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 37 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 38 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 39 | // IN NO EVENT SHALL Sente SA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 41 | // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 42 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 43 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 44 | // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | // 46 | // Note: this license is equivalent to the FreeBSD license. 47 | // 48 | // This notice may not be removed from this file. 49 | 50 | // Some extra test case macros that would have been convenient for SenTestingKit 51 | // to provide. I didn't stick GTM in front of the Macro names, so that they would 52 | // be easy to remember. 53 | 54 | #import 55 | #import "PXTestAssert.h" 56 | 57 | TRString *STComposeString(const char *formatString, ...) { 58 | TRString *reason = nil; 59 | if (formatString) { 60 | va_list vl; 61 | va_start(vl, formatString); 62 | reason = 63 | [[[TRString alloc] initWithFormat:formatString arguments:vl] autorelease]; 64 | va_end(vl); 65 | } else { 66 | reason = [TRString stringWithCString: ""]; 67 | } 68 | return reason; 69 | } -------------------------------------------------------------------------------- /tests/PXTestCase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Landon Fuller 3 | * 4 | * Copyright (c) 2012 Landon Fuller 5 | * Copyright (c) 2008-2012 Plausible Labs Cooperative, Inc. 6 | * All rights reserved. 7 | * 8 | * Permission is hereby granted, free of charge, to any person 9 | * obtaining a copy of this software and associated documentation 10 | * files (the "Software"), to deal in the Software without 11 | * restriction, including without limitation the rights to use, 12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the 14 | * Software is furnished to do so, subject to the following 15 | * conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #import "TRObject.h" 31 | #import "PXTestAssert.h" 32 | #import "PXTestException.h" 33 | 34 | @interface PXTestCase : TRObject 35 | 36 | - (void) setUp; 37 | - (void) tearDown; 38 | 39 | - (void) failWithException: (PXTestException *) exception; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /tests/PXTestCase.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Landon Fuller 3 | * 4 | * Copyright (c) 2012 Landon Fuller 5 | * Copyright (c) 2008-2012 Plausible Labs Cooperative, Inc. 6 | * All rights reserved. 7 | * 8 | * Permission is hereby granted, free of charge, to any person 9 | * obtaining a copy of this software and associated documentation 10 | * files (the "Software"), to deal in the Software without 11 | * restriction, including without limitation the rights to use, 12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the 14 | * Software is furnished to do so, subject to the following 15 | * conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #import "PXTestCase.h" 31 | 32 | /** 33 | * The test case suite superclass. All test method names must begin with 'test', 34 | * and accept no arguments. 35 | */ 36 | @implementation PXTestCase 37 | 38 | /** 39 | * Perform any test set up. The default implementation is a no-op. 40 | */ 41 | - (void) setUp { 42 | // Do nothing 43 | } 44 | 45 | /** 46 | * Perform any test tear down. The default implementation is a no-op. 47 | */ 48 | - (void) tearDown { 49 | // Do nothing 50 | } 51 | 52 | /** 53 | * Fail the current test with @a exception. 54 | */ 55 | - (void) failWithException: (PXTestException *) exception { 56 | @throw exception; 57 | } 58 | 59 | @end 60 | 61 | -------------------------------------------------------------------------------- /tests/PXTestCaseRunner.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Landon Fuller 3 | * Copyright (c) 2008-2012 Plausible Labs Cooperative, Inc. 4 | * All rights reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following 13 | * conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be 16 | * included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | * OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #import "TRObject.h" 29 | #import "PXTestCase.h" 30 | #import "PXTestResultHandler.h" 31 | 32 | /** 33 | * Implements execution of "test" methods in a PXTestCase. 34 | */ 35 | @interface PXTestCaseRunner : TRObject { 36 | @private 37 | id _resultHandler; 38 | } 39 | 40 | - (id) initWithResultHandler: (id) resultHandler; 41 | 42 | - (BOOL) runAllCases; 43 | - (BOOL) runCase: (PXTestCase *) instrumentCase; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /tests/PXTestConsoleResultHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Landon Fuller 3 | * Copyright (c) 2008-2012 Plausible Labs Cooperative, Inc. 4 | * All rights reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following 13 | * conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be 16 | * included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | * OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #include 29 | #import "TRObject.h" 30 | #import "PXTestResultHandler.h" 31 | 32 | @interface PXTestConsoleResultHandler : TRObject { 33 | @private 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /tests/PXTestConsoleResultHandler.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Landon Fuller 3 | * Copyright (c) 2008-2012 Plausible Labs Cooperative, Inc. 4 | * All rights reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following 13 | * conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be 16 | * included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | * OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | 29 | #import "PXTestConsoleResultHandler.h" 30 | 31 | #import "PXTestObjC.h" 32 | 33 | #import 34 | #import 35 | #import 36 | #import 37 | 38 | /** 39 | * Console test result handler. All results are output to standard error. 40 | */ 41 | @implementation PXTestConsoleResultHandler 42 | 43 | - (TRString *) dateString { 44 | struct tm tm; 45 | char datestring[256]; 46 | 47 | setlocale (LC_ALL, ""); 48 | time_t now = time(NULL); 49 | localtime_r(&now, &tm); 50 | size_t bytes = strftime(datestring, sizeof(datestring), nl_langinfo (D_T_FMT), &tm); 51 | if (bytes == 0) 52 | return nil; 53 | 54 | return [TRString stringWithCString: datestring]; 55 | } 56 | 57 | // from PXTestResultHandler protocol 58 | - (void) willExecuteTestCase: (PXTestCase *) testCase { 59 | TRString *output = [TRString stringWithFormat: "Test suite '%s' started at %s\n", 60 | class_getName([testCase class]), [[self dateString] cString]]; 61 | fprintf(stderr, "%s", [output cString]); 62 | } 63 | 64 | 65 | // from PXTestResultHandler protocol 66 | - (void) didExecuteTestCase: (PXTestCase *) testCase { 67 | TRString *output = [TRString stringWithFormat: "Test suite '%s' finished at %s\n", 68 | class_getName([testCase class]), [[self dateString] cString]]; 69 | fprintf(stderr, "%s", [output cString]); 70 | } 71 | 72 | 73 | // from PXTestResultHandler protocol 74 | - (void) didExecuteTestCase: (PXTestCase *) testCase selector: (SEL) selector { 75 | TRString *output = [TRString stringWithFormat: "Test case -[%s %s] completed at %s\n", 76 | class_getName([testCase class]), sel_getName(selector), [[self dateString] cString]]; 77 | 78 | fprintf(stderr, "%s", [output cString]); 79 | } 80 | 81 | // from PXTestResultHandler protocol 82 | - (void) didExecuteTestCase: (PXTestCase *) testCase selector: (SEL) selector withException: (PXTestException *) exception { 83 | TRString *output = [TRString stringWithFormat: "Test case -[%s %s] (%s:%d) failed with error: %s\n", 84 | class_getName([testCase class]), sel_getName(selector), [[exception fileName] cString], [exception lineNumber], 85 | [[exception reason] cString]]; 86 | 87 | fprintf(stderr, "%s", [output cString]); 88 | } 89 | 90 | // from PXTestResultHandler protocol 91 | - (void) didSkipTestCase: (PXTestCase *) testCase selector: (SEL) selector reason: (TRString *) reason { 92 | TRString *output = [TRString stringWithFormat: "Test case -[%s %s] failed (%s) at %s\n", 93 | class_getName([testCase class]), sel_getName(selector), [reason cString], [[self dateString] cString]]; 94 | 95 | fprintf(stderr, "%s", [output cString]); 96 | } 97 | 98 | 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /tests/PXTestException.h: -------------------------------------------------------------------------------- 1 | // 2 | // File derived from: GTMSenTestCase.h 3 | // 4 | // Copyright 2007-2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | // use this file except in compliance with the License. You may obtain a copy 8 | // of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | // License for the specific language governing permissions and limitations under 16 | // the License. 17 | // 18 | 19 | // Portions of this file fall under the following license, marked with 20 | // SENTE_BEGIN - SENTE_END 21 | // 22 | // Copyright (c) 1997-2005, Sen:te (Sente SA). All rights reserved. 23 | // 24 | // Use of this source code is governed by the following license: 25 | // 26 | // Redistribution and use in source and binary forms, with or without modification, 27 | // are permitted provided that the following conditions are met: 28 | // 29 | // (1) Redistributions of source code must retain the above copyright notice, 30 | // this list of conditions and the following disclaimer. 31 | // 32 | // (2) Redistributions in binary form must reproduce the above copyright notice, 33 | // this list of conditions and the following disclaimer in the documentation 34 | // and/or other materials provided with the distribution. 35 | // 36 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 37 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 38 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 39 | // IN NO EVENT SHALL Sente SA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 41 | // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 42 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 43 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 44 | // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | // 46 | // Note: this license is equivalent to the FreeBSD license. 47 | // 48 | // This notice may not be removed from this file. 49 | 50 | #import "TRObject.h" 51 | #import "TRString.h" 52 | 53 | @interface PXTestException : TRObject { 54 | @private 55 | /** The test failure reason. */ 56 | TRString *_reason; 57 | 58 | /** The test failure file name. */ 59 | TRString *_fileName; 60 | 61 | /** The line number at which the test failure was thrown. */ 62 | int _lineNumber; 63 | } 64 | 65 | + (PXTestException *)failureInFile:(TRString *)filename 66 | atLine:(int)lineNumber 67 | withDescription:(TRString *)formatString, ...; 68 | + (PXTestException *)failureInCondition:(TRString *)condition 69 | isTrue:(BOOL)isTrue 70 | inFile:(TRString *)filename 71 | atLine:(int)lineNumber 72 | withDescription:(TRString *)formatString, ...; 73 | + (PXTestException *)failureInEqualityBetweenObject:(id)left 74 | andObject:(id)right 75 | inFile:(TRString *)filename 76 | atLine:(int)lineNumber 77 | withDescription:(TRString *)formatString, ...; 78 | + (PXTestException *)failureInEqualityBetweenValue:(id)left 79 | andValue:(id)right 80 | withAccuracy:(id)accuracy 81 | inFile:(TRString *)filename 82 | atLine:(int) ineNumber 83 | withDescription:(TRString *)formatString, ...; 84 | + (PXTestException *)failureInRaise:(TRString *)expression 85 | inFile:(TRString *)filename 86 | atLine:(int)lineNumber 87 | withDescription:(TRString *)formatString, ...; 88 | + (PXTestException *)failureInRaise:(TRString *)expression 89 | exception:(PXTestException *)exception 90 | inFile:(TRString *)filename 91 | atLine:(int)lineNumber 92 | withDescription:(TRString *)formatString, ...; 93 | 94 | - (id) initWithReason: (TRString *) reason fileName: (TRString *) fileName lineNumber: (int) lineNumber; 95 | 96 | - (TRString *) reason; 97 | 98 | - (TRString *) fileName; 99 | 100 | - (int) lineNumber; 101 | 102 | @end -------------------------------------------------------------------------------- /tests/PXTestObjC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Landon Fuller 3 | * Copyright (c) 2008-2012 Plausible Labs Cooperative, Inc. 4 | * All rights reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following 13 | * conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be 16 | * included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | * OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #import 29 | -------------------------------------------------------------------------------- /tests/PXTestResultHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Landon Fuller 3 | * Copyright (c) 2008 Plausible Labs Cooperative, Inc. 4 | * All rights reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following 13 | * conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be 16 | * included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | * OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #import "TRObject.h" 29 | 30 | #import "PXTestException.h" 31 | #import "PXTestCase.h" 32 | #import "TRString.h" 33 | 34 | /** 35 | * Provides handling of test results. The results may be printed 36 | * to stderr, output as XML, etc. 37 | */ 38 | @protocol PXTestResultHandler 39 | 40 | /** 41 | * Called when preparing to execute a test case. 42 | * 43 | * @param testCase The test case to be executed 44 | */ 45 | - (void) willExecuteTestCase: (PXTestCase *) testCase; 46 | 47 | /** 48 | * Called when finished to executing a test case. 49 | */ 50 | - (void) didExecuteTestCase: (PXTestCase *) testCase; 51 | 52 | /** 53 | * Called upon successful execution of an test case's test method. 54 | * 55 | * @param testCase The executed test case instance. 56 | * @param selector The selector executed. 57 | */ 58 | - (void) didExecuteTestCase: (PXTestCase *) testCase selector: (SEL) selector; 59 | 60 | /** 61 | * Called upon failed execution of an test case's test method. 62 | * 63 | * @param testCase The executed test case instance. 64 | * @param selector The selector executed. 65 | * @param exception The failure cause. 66 | */ 67 | - (void) didExecuteTestCase: (PXTestCase *) testCase selector: (SEL) selector withException: (PXTestException *) exception; 68 | 69 | /** 70 | * If an test method can not be run, this method will be called. 71 | * 72 | * @param testCase The executed test case instance. 73 | * @param selector The selector executed. 74 | * @param reason Non-localized human readable reason that the instrumentation method was skipped. 75 | */ 76 | - (void) didSkipTestCase: (PXTestCase *) testCase selector: (SEL) selector reason: (TRString *) reason; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /tests/TRAutoreleasePoolTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRAutoreleasePool.m vi:ts=4:sw=4:expandtab: 3 | * 4 | * Copyright (C) 2005 - 2007 Landon Fuller 5 | * All rights reserved. 6 | * 7 | * This file is part of Objective-C Substrate. 8 | * 9 | * Permission to use, copy, modify, and distribute this software and its 10 | * documentation for any purpose and without fee is hereby granted, provided 11 | * that the above copyright notice appear in all copies and that both that 12 | * copyright notice and this permission notice appear in supporting 13 | * documentation. 14 | * 15 | * We disclaim all warranties with regard to this software, including all 16 | * implied warranties of merchantability and fitness, in no event shall 17 | * we be liable for any special, indirect or consequential damages or any 18 | * damages whatsoever resulting from loss of use, data or profits, whether in 19 | * an action of contract, negligence or other tortious action, arising out of 20 | * or in connection with the use or performance of this software. 21 | */ 22 | 23 | #import "TRAutoreleasePool.h" 24 | #import "PXTestCase.h" 25 | 26 | static unsigned int livecount; 27 | 28 | @interface PoolTester : TRObject 29 | @end 30 | 31 | @implementation PoolTester 32 | 33 | - (oneway void) release { 34 | livecount--; 35 | [super release]; 36 | } 37 | 38 | - (void) dealloc { 39 | livecount--; 40 | [super dealloc]; 41 | } 42 | 43 | @end 44 | 45 | @interface TRAutoreleasePoolTests : PXTestCase @end 46 | 47 | @implementation TRAutoreleasePoolTests 48 | 49 | - (void) testAddObject { 50 | TRAutoreleasePool *pool; 51 | TRObject *obj; 52 | int i; 53 | 54 | /* Allocate a pool */ 55 | pool = [[TRAutoreleasePool alloc] init]; 56 | fail_if(pool == nil, "[[TRAutoreleasePool alloc] init] returned nil.\n"); 57 | 58 | /* Allocate an object to auto-release */ 59 | obj = [[PoolTester alloc] init]; 60 | [obj autorelease]; 61 | 62 | /* Implicit refcount + dealloc */ 63 | livecount = 2; 64 | 65 | /* Exercise the pool */ 66 | for (i = 0; i < 4096; i++) { 67 | livecount++; 68 | [obj retain]; 69 | [obj autorelease]; 70 | } 71 | 72 | /* Release it */ 73 | [pool release]; 74 | 75 | fail_unless(livecount == 0, "[TRAutoreleasePool release] failed to release %d objects.", livecount); 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /tests/TRConfigLexerTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRConfigLexer.m vi:ts=4:sw=4:expandtab: 3 | * TRConfigLexer Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Landon Fuller nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import 40 | #import 41 | #import 42 | 43 | #import "TRConfig.h" 44 | #import "TRConfigParser.h" 45 | #import "TRConfigLexer.h" 46 | 47 | #import "PXTestCase.h" 48 | 49 | #import "tests.h" 50 | 51 | /* Path Constants */ 52 | #define TEST_CONF DATA_PATH("test-lineNumbers.conf") 53 | 54 | @interface TRConfigLexerTests : PXTestCase @end 55 | 56 | @implementation TRConfigLexerTests 57 | 58 | - (void) testParse { 59 | TRConfigLexer *lexer; 60 | TRConfigToken *token; 61 | int configFD; 62 | 63 | /* Open our configuration file */ 64 | configFD = open(TEST_CONF, O_RDONLY); 65 | fail_if(configFD == -1, "open() returned -1"); 66 | 67 | lexer = [[TRConfigLexer alloc] initWithFD: configFD]; 68 | fail_if(lexer == NULL, "-[[TRConfigLexer alloc] initWithFD:] returned NULL"); 69 | 70 | while ((token = [lexer scan]) != NULL) { 71 | /* The configuration file was assembled so that all values match the, 72 | * current line number -- that is to say, for any given key/value pair, 73 | * the value is set to the current line number of that pair. */ 74 | if ([token tokenID] == TOKEN_VALUE || [token tokenID] == TOKEN_SECTION_NAME || [token tokenID] == TOKEN_SECTION_START) { 75 | int value; 76 | 77 | /* Get the integer representation */ 78 | fail_unless([token intValue: &value], "-[TRConfigToken getIntValue:] returned false. (String Value: %s)", [token cString]); 79 | 80 | /* Verify that the line number is correct */ 81 | fail_unless(value == [token lineNumber], "-[TRConfigToken getLineNumber] out of sync. (Expected %d, got %d)", value, [token lineNumber]); 82 | } 83 | [token dealloc]; 84 | } 85 | 86 | close(configFD); 87 | [lexer dealloc]; 88 | } 89 | 90 | @end -------------------------------------------------------------------------------- /tests/TRConfigTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRConfig.m vi:ts=4:sw=4:expandtab: 3 | * TRConfig Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Landon Fuller nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import "PXTestCase.h" 40 | 41 | #import 42 | #import 43 | 44 | #import "tests.h" 45 | 46 | #import "TRConfig.h" 47 | 48 | /* Path Constants */ 49 | #define TEST_CONF DATA_PATH("TRConfig.conf") 50 | 51 | /* 52 | * Mock configuration delegate 53 | */ 54 | @interface MockConfigDelegate : TRObject 55 | - (void) setKey: (TRConfigToken *) key value: (TRConfigToken *) value; 56 | - (void) startSection: (TRConfigToken *) type sectionName: (TRConfigToken *) name; 57 | - (void) endSection: (TRConfigToken *) sectionEnd; 58 | - (void) parseError: (TRConfigToken *) badToken; 59 | @end 60 | 61 | @implementation MockConfigDelegate 62 | - (void) setKey: (TRConfigToken *) key value: (TRConfigToken *) value { 63 | /* Do nothing */ 64 | return; 65 | } 66 | 67 | - (void) startSection: (TRConfigToken *) type sectionName: (TRConfigToken *) name { 68 | /* Do nothing */ 69 | return; 70 | } 71 | 72 | - (void) endSection: (TRConfigToken *) sectionEnd { 73 | /* Do nothing */ 74 | return; 75 | } 76 | 77 | - (void) parseError: (TRConfigToken *) badToken { 78 | /* Do nothing */ 79 | return; 80 | } 81 | @end 82 | 83 | @interface TRConfigTests : PXTestCase @end 84 | 85 | @implementation TRConfigTests 86 | 87 | - (void) testInitWithFD { 88 | TRConfig *config; 89 | MockConfigDelegate *delegate; 90 | int configFD; 91 | 92 | /* Open our configuration file */ 93 | configFD = open(TEST_CONF, O_RDONLY); 94 | fail_if(configFD == -1, "open() returned -1"); 95 | 96 | /* Initialize the configuration parser */ 97 | delegate = [[MockConfigDelegate alloc] init]; 98 | config = [[TRConfig alloc] initWithFD: configFD configDelegate: delegate]; 99 | fail_if(config == NULL, "-[[TRConfig alloc] initWithFD:] returned NULL"); 100 | 101 | /* Parse the configuration file */ 102 | fail_unless([config parseConfig], "-[TRConfig parse] returned NULL"); 103 | 104 | /* Clean up */ 105 | [delegate release]; 106 | close(configFD); 107 | } 108 | 109 | 110 | @end -------------------------------------------------------------------------------- /tests/TRConfigTokenTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRConfigToken.m vi:ts=4:sw=4:expandtab: 3 | * TRConfigToken Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import "PXTestCase.h" 40 | 41 | #import "TRConfigToken.h" 42 | #import "TRConfig.h" 43 | #import "TRConfigParser.h" 44 | 45 | #import 46 | 47 | #define TEST_STRING "The answer to life, the universe, and everything" 48 | #define TEST_LINE_NUMBER 42 49 | 50 | @interface TRConfigTokenTests : PXTestCase @end 51 | 52 | @implementation TRConfigTokenTests 53 | 54 | - (void) test_initWithBytes { 55 | int tokenID; 56 | unsigned int lineNumber; 57 | TRConfigToken *token; 58 | 59 | token = [[TRConfigToken alloc] initWithBytes: TEST_STRING 60 | numBytes: sizeof(TEST_STRING) 61 | lineNumber: TEST_LINE_NUMBER 62 | tokenID: TOKEN_VALUE]; 63 | fail_if(token == NULL, "-[[TRConfigToken alloc] initWithBytes: numBytes: tokenID:] returned NULL"); 64 | 65 | tokenID = [token tokenID]; 66 | fail_unless(tokenID == TOKEN_VALUE, "-[TRConfigToken tokenID] returned incorrect value. (Expected %d, got %d)", tokenID, TOKEN_VALUE); 67 | 68 | lineNumber = [token lineNumber]; 69 | fail_unless(lineNumber == TEST_LINE_NUMBER, "-[TRConfigToken lineNumber] returned incorrect value. (Expected %d, got %d)", TEST_LINE_NUMBER, lineNumber); 70 | 71 | [token release]; 72 | } 73 | 74 | - (void) test_intValue { 75 | TRConfigToken *token; 76 | int value; 77 | 78 | token = [[TRConfigToken alloc] initWithBytes: "24" 79 | numBytes: sizeof("24") 80 | lineNumber: TEST_LINE_NUMBER 81 | tokenID: TOKEN_VALUE]; 82 | fail_if(token == NULL, "-[[TRConfigToken alloc] initWithBytes: numBytes: tokenID:] returned NULL"); 83 | 84 | fail_unless([token intValue: &value], "-[TRConfigToken intValue:] returned NO"); 85 | fail_unless(value == 24, "-[TRConfigToken value] returned incorrect value. (Expected %d, got %d)", 24, value); 86 | 87 | [token release]; 88 | } 89 | 90 | - (void) test_boolValue { 91 | TRConfigToken *token; 92 | BOOL value; 93 | 94 | token = [[TRConfigToken alloc] initWithBytes: "yes" 95 | numBytes: sizeof("yes") 96 | lineNumber: TEST_LINE_NUMBER 97 | tokenID: TOKEN_VALUE]; 98 | 99 | fail_unless([token boolValue: &value], "-[TRConfigToken boolValue:] returned NO"); 100 | 101 | fail_unless(value == YES, "-[TRConfigToken value] returned incorrect value. (Expected %d, got %d)", YES, value); 102 | 103 | [token release]; 104 | 105 | token = [[TRConfigToken alloc] initWithBytes: "no" 106 | numBytes: sizeof("no") 107 | lineNumber: TEST_LINE_NUMBER 108 | tokenID: TOKEN_VALUE]; 109 | 110 | fail_unless([token boolValue: &value], "-[TRConfigToken boolValue:] returned NO"); 111 | 112 | fail_unless(value == NO, "-[TRConfigToken value] returned incorrect value. (Expected %d, got %d)", NO, value); 113 | 114 | [token release]; 115 | } 116 | 117 | @end 118 | -------------------------------------------------------------------------------- /tests/TRLDAPAccountRepositoryTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPAccountRepositoryTests.m vi:ts=4:sw=4:expandtab: 3 | * TRLDAPAccountRepository Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Landon Fuller nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import "PXTestCase.h" 40 | 41 | #import "TRLDAPAccountRepository.h" 42 | #import "TRAuthLDAPConfig.h" 43 | 44 | #import "tests.h" 45 | 46 | @interface TRLDAPAccountRepositoryTests : PXTestCase @end 47 | 48 | @implementation TRLDAPAccountRepositoryTests 49 | 50 | - (void) test_initWithLDAPConnection { 51 | TRLDAPAccountRepository *accounts; 52 | TRAuthLDAPConfig *config; 53 | TRLDAPConnection *conn; 54 | 55 | /* Set up a TRLDAPConnection */ 56 | config = [[TRAuthLDAPConfig alloc] initWithConfigFile: AUTH_LDAP_CONF]; 57 | fail_if(config == nil, "-[[TRAuthLDAPConfig alloc] initWithConfigFile:] returned nil"); 58 | 59 | conn = [[TRLDAPConnection alloc] initWithURL: [config url] timeout: [config timeout]]; 60 | 61 | /* Initialize a TRLDAPAccountRepository */ 62 | TRLDAPSearchFilter *userFilter = [[[TRLDAPSearchFilter alloc] initWithFormat: [TRString stringWithCString: "%s"]] autorelease]; 63 | TRLDAPSearchFilter *groupFilter = [[[TRLDAPSearchFilter alloc] initWithFormat: [TRString stringWithCString: "%s"]] autorelease]; 64 | 65 | accounts = [[TRLDAPAccountRepository alloc] initWithLDAPConnection: conn userSearchFilter: userFilter groupSearchFilter: groupFilter]; 66 | fail_if(accounts == nil, "-[[TRLDAPAccountRepository alloc] initWithLDAPConnection:] returned nil"); 67 | 68 | [accounts release]; 69 | [config release]; 70 | [conn release]; 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /tests/TRLDAPConnectionTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPConnection.m vi:ts=4:sw=4:expandtab: 3 | * TRLDAPConnection Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Landon Fuller nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import "PXTestCase.h" 40 | 41 | #import "TRLDAPConnection.h" 42 | #import "TRAuthLDAPConfig.h" 43 | 44 | #import 45 | 46 | #import "tests.h" 47 | 48 | /* Data Constants */ 49 | #define TEST_LDAP_URL "ldap://ldap1.example.org" 50 | #define TEST_LDAP_TIMEOUT 15 51 | 52 | @interface TRLDAPConnectionTests : PXTestCase @end 53 | 54 | @implementation TRLDAPConnectionTests 55 | 56 | - (void) testInit { 57 | TRAuthLDAPConfig *config; 58 | TRLDAPConnection *conn; 59 | TRString *value; 60 | 61 | config = [[TRAuthLDAPConfig alloc] initWithConfigFile: AUTH_LDAP_CONF]; 62 | fail_if(config == NULL, "-[[TRAuthLDAPConfig alloc] initWithConfigFile:] returned NULL"); 63 | 64 | conn = [[TRLDAPConnection alloc] initWithURL: [config url] timeout: [config timeout]]; 65 | 66 | /* Referrals */ 67 | fail_unless([conn setReferralEnabled: [config referralEnabled]]); 68 | 69 | /* Certificate file */ 70 | if ((value = [config tlsCACertFile])) 71 | fail_unless([conn setTLSCACertFile: value]); 72 | 73 | /* Certificate directory */ 74 | if ((value = [config tlsCACertDir])) 75 | fail_unless([conn setTLSCACertDir: value]); 76 | 77 | /* Client Certificate Pair */ 78 | if ([config tlsCertFile] && [config tlsKeyFile]) 79 | fail_unless([conn setTLSClientCert: [config tlsCertFile] keyFile: [config tlsKeyFile]]); 80 | 81 | /* Cipher suite */ 82 | if ((value = [config tlsCipherSuite])) 83 | fail_unless([conn setTLSCipherSuite: value]); 84 | 85 | [config release]; 86 | [conn release]; 87 | } 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /tests/TRLDAPEntryTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPEntry.m vi:ts=4:sw=4:expandtab: 3 | * TRLDAPEntry Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Landon Fuller nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import "PXTestCase.h" 40 | #import "TRLDAPEntry.h" 41 | 42 | @interface TRLDAPEntryTests : PXTestCase @end 43 | 44 | @implementation TRLDAPEntryTests 45 | 46 | - (void) testInitWithDN { 47 | TRLDAPEntry *entry; 48 | TRString *dn; 49 | TRHash *attributes; 50 | 51 | dn = [[TRString alloc] initWithCString: "dc=foobar"]; 52 | /* Make something up for the attributes */ 53 | attributes = [[TRHash alloc] initWithCapacity: 1]; 54 | [attributes setObject: dn forKey: dn]; 55 | 56 | entry = [[TRLDAPEntry alloc] initWithDN: dn attributes: attributes]; 57 | 58 | fail_unless([entry attributes] == attributes); 59 | fail_unless([entry dn] == dn); 60 | 61 | [entry release]; 62 | [dn release]; 63 | [attributes release]; 64 | } 65 | 66 | @end -------------------------------------------------------------------------------- /tests/TRLDAPGroupConfigTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPGroupConfig.m vi:ts=4:sw=4:expandtab: 3 | * TRLDAPGroundConfig Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Landon Fuller nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import "PXTestCase.h" 40 | #import "TRLDAPGroupConfig.h" 41 | 42 | /* Data Constants */ 43 | #define TEST_LDAP_BASEDN "ou=People,dc=example,dc=com" 44 | #define TEST_LDAP_ATTRIBUTE "uniqueMember" 45 | #define TEST_LDAP_FILTER "(|(cn=artists)(cn=engineers))" 46 | 47 | @interface TRLDAPGroupConfigTests : PXTestCase @end 48 | 49 | @implementation TRLDAPGroupConfigTests 50 | // TODO 51 | @end -------------------------------------------------------------------------------- /tests/TRLDAPSearchFilterTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRLDAPSearchFilter.m vi:ts=4:sw=4:expandtab: 3 | * TRLDAPSearchFilter Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Landon Fuller nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import "PXTestCase.h" 40 | 41 | #import 42 | 43 | #import "TRLDAPSearchFilter.h" 44 | 45 | @interface TRLDAPSearchFilterTests : PXTestCase @end 46 | 47 | @implementation TRLDAPSearchFilterTests 48 | 49 | - (void) test_initWithFormat { 50 | TRLDAPSearchFilter *filter = [[TRLDAPSearchFilter alloc] initWithFormat: [TRString stringWithCString: "%s foo"]]; 51 | 52 | [filter release]; 53 | } 54 | 55 | - (void) test_getFilter { 56 | TRLDAPSearchFilter *filter = [[TRLDAPSearchFilter alloc] initWithFormat: [TRString stringWithCString: "(&(uid=%s)(cn=%s))"]]; 57 | const char *expected = "(&(uid=fred)(cn=fred))"; 58 | TRString *result = [filter getFilter: [TRString stringWithCString: "fred"]]; 59 | 60 | fail_unless(strcmp([result cString], expected) == 0, 61 | "-[TRLDAPSearchFilter createFilter:] returned incorrect string. (Expected %s, got %s)", expected, [result cString]); 62 | 63 | [filter release]; 64 | } 65 | 66 | - (void) test_ldapEscaping { 67 | TRLDAPSearchFilter *filter = [[TRLDAPSearchFilter alloc] initWithFormat: [TRString stringWithCString: "(%s)"]]; 68 | const char *expected = "(\\(foo\\*\\)\\\\)"; 69 | 70 | /* Pass in something containing all the special characters */ 71 | TRString *result = [filter getFilter: [TRString stringWithCString: "(foo*)\\"]]; 72 | 73 | fail_unless(strcmp([result cString], expected) == 0, 74 | "-[TRLDAPSearchFilter createFilter:] returned incorrect string. (Expected %s, got %s)", expected, [result cString]); 75 | 76 | [filter release]; 77 | } 78 | 79 | @end -------------------------------------------------------------------------------- /tests/TRObjectTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRObject.m vi:ts=4:sw=4:expandtab: 3 | * TRObject Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 8 | * Copyright (c) 2007 - 2012 Landon Fuller 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of Landon Fuller nor the names of any contributors 20 | * may be used to endorse or promote products derived from this 21 | * software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifdef HAVE_CONFIG_H 37 | #import 38 | #endif 39 | 40 | #import "TRObject.h" 41 | #import "PXTestCase.h" 42 | 43 | @interface TRObjectTests : PXTestCase @end 44 | 45 | @implementation TRObjectTests 46 | 47 | - (void) testIsKindOfClass { 48 | TRObject *trObj = [[[TRObject alloc] init] autorelease]; 49 | 50 | STAssertTrue([self isKindOfClass: [TRObject class]], "Test case should be considered a subclass of TRObject"); 51 | STAssertTrue([self isKindOfClass: [self class]], "Test case should consider itself to be of the same kind as its own class."); 52 | STAssertFalse([trObj isKindOfClass: [self class]], "TRObject is not an intance of TRObjectTests, or an instance of a TRObjectTests subclass"); 53 | } 54 | 55 | - (void) testRetainRelease { 56 | TRObject *obj; 57 | 58 | /* Initialize the object */ 59 | obj = [[TRObject alloc] init]; 60 | STAssertEquals([obj retainCount], (PXUInteger)1, "Newly initialized TRObject has unexpected reference count"); 61 | 62 | /* Increment the refcount */ 63 | [obj retain]; 64 | STAssertEquals([obj retainCount], (PXUInteger)2, "Retained TRObject has unexpected reference count"); 65 | 66 | /* Decrement the refcount */ 67 | [obj release]; 68 | STAssertEquals([obj retainCount], (PXUInteger)1, "Released TRObject has unexpected reference count"); 69 | 70 | /* Deallocate the object */ 71 | [obj release]; 72 | } 73 | 74 | - (void) testIsEqual { 75 | TRObject *obj; 76 | 77 | /* Initialize the object */ 78 | obj = [[TRObject alloc] init]; 79 | 80 | STAssertEqualObjects(obj, obj, "Object should be equal to self"); 81 | 82 | /* Deallocate the object */ 83 | [obj release]; 84 | } 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /tests/TRPFAddressTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRPPFAddress.m vi:ts=4:sw=4:expandtab: 3 | * TRPFAddress Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Landon Fuller nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | #import "PXTestCase.h" 40 | 41 | #import 42 | 43 | #import "TRPFAddress.h" 44 | 45 | @interface TRPFAddressTests : PXTestCase @end 46 | 47 | @implementation TRPFAddressTests 48 | 49 | - (void) test_initWithPresentationAddress { 50 | TRString *addrString; 51 | TRPFAddress *pfAddr; 52 | /* Independent verification */ 53 | TRPortableAddress expected; 54 | TRPortableAddress actual; 55 | 56 | /* Test with IPv4 */ 57 | addrString = [[TRString alloc] initWithCString: "127.0.0.1"]; 58 | fail_unless(inet_pton(AF_INET, "127.0.0.1", &expected.ip4_addr)); 59 | 60 | pfAddr = [[TRPFAddress alloc] initWithPresentationAddress: addrString]; 61 | [addrString release]; 62 | 63 | /* Verify conversion */ 64 | fail_if(pfAddr == nil); 65 | [pfAddr address: &actual]; 66 | fail_unless(memcmp(&actual.ip4_addr, &expected.ip4_addr, sizeof(expected.ip4_addr)) == 0); 67 | 68 | [pfAddr release]; 69 | 70 | /* Test with IPv6 */ 71 | addrString = [[TRString alloc] initWithCString: "::1"]; 72 | fail_unless(inet_pton(AF_INET6, "::1", &expected.ip6_addr)); 73 | 74 | pfAddr = [[TRPFAddress alloc] initWithPresentationAddress: addrString]; 75 | [addrString release]; 76 | 77 | /* Verify conversion */ 78 | fail_if(pfAddr == nil); 79 | [pfAddr address: &actual]; 80 | fail_unless(memcmp(&actual.ip6_addr, &expected.ip6_addr, sizeof(expected.ip6_addr)) == 0); 81 | 82 | [pfAddr release]; 83 | } 84 | 85 | - (void) test_initWithPortableAddress { 86 | TRString *addrString; 87 | TRPFAddress *pfAddr; 88 | TRPortableAddress expected; 89 | TRPortableAddress actual; 90 | 91 | /* Initialize the source (expected) */ 92 | addrString = [[TRString alloc] initWithCString: "127.0.0.1"]; 93 | pfAddr = [[TRPFAddress alloc] initWithPresentationAddress: addrString]; 94 | 95 | fail_if(pfAddr == nil); 96 | [pfAddr address: &expected]; 97 | 98 | [addrString release]; 99 | [pfAddr release]; 100 | 101 | /* Initialize the dest (actual) */ 102 | pfAddr = [[TRPFAddress alloc] initWithPortableAddress: &expected]; 103 | fail_if(pfAddr == nil); 104 | [pfAddr address: &actual]; 105 | [pfAddr release]; 106 | 107 | /* Verify */ 108 | fail_unless(memcmp(&actual, &expected, sizeof(expected)) == 0); 109 | } 110 | 111 | @end -------------------------------------------------------------------------------- /tests/TRVPNSessionTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * TRVPNSession.m vi:ts=4:sw=4:expandtab: 3 | * TRVPNSession Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2005 - 2007 Landon Fuller 8 | * Copyright (c) 2006 - 2007 Three Rings Design, Inc. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of Landon Fuller nor the names of any contributors 20 | * may be used to endorse or promote products derived from this 21 | * software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifdef HAVE_CONFIG_H 37 | #import 38 | #endif 39 | 40 | #import "PXTestCase.h" 41 | 42 | #import "TRVPNSession.h" 43 | 44 | @interface TRVPNSessionTests : PXTestCase @end 45 | 46 | @implementation TRVPNSessionTests 47 | 48 | - (void) test_initWithUsername { 49 | TRVPNSession *session; 50 | TRString *username = [[TRString alloc] initWithCString: "user"]; 51 | 52 | session = [[TRVPNSession alloc] initWithUsername: username]; 53 | 54 | fail_unless([session username] == username); 55 | 56 | [username release]; 57 | [session release]; 58 | } 59 | 60 | @end -------------------------------------------------------------------------------- /tests/data/TRConfig.conf: -------------------------------------------------------------------------------- 1 | 2 | # LDAP server URL 3 | URI ldap://ldap1.example.org 4 | 5 | # Network timeout (in seconds) 6 | Timeout 15 7 | 8 | -------------------------------------------------------------------------------- /tests/data/auth-ldap-bad-section.conf: -------------------------------------------------------------------------------- 1 | # Contains an unknown section type 2 | 3 | -------------------------------------------------------------------------------- /tests/data/auth-ldap-mismatched.conf: -------------------------------------------------------------------------------- 1 | 2 | # LDAP server URL 3 | URL ldap://ldap1.example.org 4 | 5 | # Network timeout (in seconds) 6 | Timeout 15 7 | 8 | # Enable TLS 9 | TLSEnable yes 10 | 11 | # TLS CA Certificate File 12 | TLSCACertFile /usr/local/etc/ssl/ca.pem 13 | 14 | # TLS CA Certificate Directory 15 | TLSCACertDir /etc/ssl/certs 16 | 17 | # Client Certificate 18 | TLSCertFile /usr/local/etc/ssl/client-cert.pem 19 | 20 | # Client Key 21 | TLSKeyFile /usr/local/etc/ssl/client-key.pem 22 | 23 | # Cipher Suite 24 | TLSCipherSuite ALL:!ADH:@STRENGTH 25 | 26 | -------------------------------------------------------------------------------- /tests/data/auth-ldap-missing-newline.conf: -------------------------------------------------------------------------------- 1 | # A configuration that's missing the trailing newline. 2 | # Test for issue #8 3 | 4 | # LDAP server URL 5 | URL ldap://ldap1.example.org 6 | 7 | # Bind DN (If your LDAP server doesn't support anonymous binds) 8 | BindDN uid=Manager,ou=People,dc=example,dc=com 9 | 10 | # Bind Password 11 | Password SuperSecretPassword 12 | 13 | # Network timeout (in seconds) 14 | Timeout 15 15 | 16 | # Enable TLS 17 | TLSEnable yes 18 | 19 | # TLS CA Certificate File 20 | TLSCACertFile /usr/local/etc/ssl/ca.pem 21 | 22 | # TLS CA Certificate Directory 23 | TLSCACertDir /etc/ssl/certs 24 | 25 | # Client Certificate 26 | TLSCertFile /usr/local/etc/ssl/client-cert.pem 27 | 28 | # Client Key 29 | TLSKeyFile /usr/local/etc/ssl/client-key.pem 30 | 31 | # Cipher Suite 32 | TLSCipherSuite ALL:!ADH:@STRENGTH 33 | 34 | 35 | 36 | # Base DN 37 | BaseDN "ou=People,dc=example,dc=com" 38 | 39 | # User Search Filter 40 | SearchFilter "(&(uid=%u)(accountStatus=active))" 41 | 42 | # Require Group Membership 43 | RequireGroup false 44 | 45 | 46 | BaseDN "ou=Groups,dc=example,dc=com" 47 | SearchFilter "(|(cn=developers)(cn=artists))" 48 | MemberAttribute uniqueMember 49 | 50 | -------------------------------------------------------------------------------- /tests/data/auth-ldap-multikey.conf: -------------------------------------------------------------------------------- 1 | 2 | # LDAP server URL - Twice 3 | URL ldap://ldap1.example.org 4 | URL ldap://ldap1.example.org 5 | 6 | # Network timeout (in seconds) 7 | Timeout 15 8 | 9 | # Enable TLS 10 | TLSEnable yes 11 | 12 | # TLS CA Certificate File 13 | TLSCACertFile /usr/local/etc/ssl/ca.pem 14 | 15 | # TLS CA Certificate Directory 16 | TLSCACertDir /etc/ssl/certs 17 | 18 | # Client Certificate 19 | TLSCertFile /usr/local/etc/ssl/client-cert.pem 20 | 21 | # Client Key 22 | TLSKeyFile /usr/local/etc/ssl/client-key.pem 23 | 24 | # Cipher Suite 25 | TLSCipherSuite ALL:!ADH:@STRENGTH 26 | 27 | 28 | 29 | # Base DN 30 | BaseDN "ou=People,dc=example,dc=com" 31 | 32 | # User Search Filter 33 | SearchFilter "(&(uid=%u)(accountStatus=active))" 34 | 35 | # Require Group Membership 36 | RequireGroup false 37 | 38 | 39 | BaseDN "ou=Groups,dc=example,dc=com" 40 | SearchFilter "(|(cn=developers)(cn=artists))" 41 | MemberAttribute uniqueMember 42 | 43 | 44 | -------------------------------------------------------------------------------- /tests/data/auth-ldap-named.conf: -------------------------------------------------------------------------------- 1 | 2 | # LDAP server URL 3 | URL ldap://ldap1.example.org 4 | 5 | # Network timeout (in seconds) 6 | Timeout 15 7 | 8 | # Enable TLS 9 | TLSEnable yes 10 | 11 | # TLS CA Certificate File 12 | TLSCACertFile /usr/local/etc/ssl/ca.pem 13 | 14 | # TLS CA Certificate Directory 15 | #TLSCACertDir /etc/ssl/certs 16 | 17 | # Client Certificate 18 | #TLSCertFile /usr/local/etc/ssl/client-cert.pem 19 | 20 | # Client Key 21 | #TLSKeyFile /usr/local/etc/ssl/client-key.pem 22 | 23 | -------------------------------------------------------------------------------- /tests/data/auth-ldap-pf.conf: -------------------------------------------------------------------------------- 1 | 2 | # LDAP server URL 3 | URL ldap://ldap1.example.org 4 | 5 | # Bind DN (If your LDAP server doesn't support anonymous binds) 6 | BindDN uid=Manager,ou=People,dc=example,dc=com 7 | 8 | # Bind Password 9 | Password SuperSecretPassword 10 | 11 | # Network timeout (in seconds) 12 | Timeout 15 13 | 14 | # Enable TLS 15 | TLSEnable yes 16 | 17 | # TLS CA Certificate File 18 | TLSCACertFile /usr/local/etc/ssl/ca.pem 19 | 20 | # TLS CA Certificate Directory 21 | TLSCACertDir /etc/ssl/certs 22 | 23 | # Client Certificate 24 | TLSCertFile /usr/local/etc/ssl/client-cert.pem 25 | 26 | # Client Key 27 | TLSKeyFile /usr/local/etc/ssl/client-key.pem 28 | 29 | # Cipher Suite 30 | TLSCipherSuite ALL:!ADH:@STRENGTH 31 | 32 | 33 | 34 | # Base DN 35 | BaseDN "ou=People,dc=example,dc=com" 36 | 37 | # User Search Filter 38 | SearchFilter "(&(uid=%u)(accountStatus=active))" 39 | 40 | # Require Group Membership 41 | RequireGroup false 42 | 43 | # Add to PF Table 44 | PFTable ips_users 45 | 46 | 47 | BaseDN "ou=Groups,dc=example,dc=com" 48 | SearchFilter "(|(cn=developers)(cn=artists))" 49 | MemberAttribute uniqueMember 50 | PFTable ips_trusted 51 | 52 | 53 | -------------------------------------------------------------------------------- /tests/data/auth-ldap-required.conf: -------------------------------------------------------------------------------- 1 | 2 | # LDAP server URL 3 | # Missing this required setting 4 | # URL ldap://ldap1.example.org 5 | 6 | # Network timeout (in seconds) 7 | Timeout 15 8 | 9 | # Enable TLS 10 | TLSEnable yes 11 | 12 | # TLS CA Certificate File 13 | TLSCACertFile /usr/local/etc/ssl/ca.pem 14 | 15 | # TLS CA Certificate Directory 16 | TLSCACertDir /etc/ssl/certs 17 | 18 | # Client Certificate 19 | TLSCertFile /usr/local/etc/ssl/client-cert.pem 20 | 21 | # Client Key 22 | TLSKeyFile /usr/local/etc/ssl/client-key.pem 23 | 24 | # Cipher Suite 25 | TLSCipherSuite ALL:!ADH:@STRENGTH 26 | 27 | 28 | 29 | # Base DN 30 | BaseDN "ou=People,dc=example,dc=com" 31 | 32 | # User Search Filter 33 | SearchFilter "(&(uid=%u)(accountStatus=active))" 34 | 35 | # Require Group Membership 36 | RequireGroup false 37 | 38 | 39 | BaseDN "ou=Groups,dc=example,dc=com" 40 | SearchFilter "(|(cn=developers)(cn=artists))" 41 | MemberAttribute uniqueMember 42 | 43 | 44 | -------------------------------------------------------------------------------- /tests/data/auth-ldap.conf: -------------------------------------------------------------------------------- 1 | 2 | # LDAP server URL 3 | URL ldap://ldap1.example.org 4 | 5 | # Bind DN (If your LDAP server doesn't support anonymous binds) 6 | BindDN uid=Manager,ou=People,dc=example,dc=com 7 | 8 | # Bind Password 9 | Password SuperSecretPassword 10 | 11 | # Network timeout (in seconds) 12 | Timeout 15 13 | 14 | # Enable TLS 15 | TLSEnable yes 16 | 17 | # TLS CA Certificate File 18 | TLSCACertFile /usr/local/etc/ssl/ca.pem 19 | 20 | # TLS CA Certificate Directory 21 | TLSCACertDir /etc/ssl/certs 22 | 23 | # Client Certificate 24 | TLSCertFile /usr/local/etc/ssl/client-cert.pem 25 | 26 | # Client Key 27 | TLSKeyFile /usr/local/etc/ssl/client-key.pem 28 | 29 | # Cipher Suite 30 | TLSCipherSuite ALL:!ADH:@STRENGTH 31 | 32 | 33 | 34 | # Base DN 35 | BaseDN "ou=People,dc=example,dc=com" 36 | 37 | # User Search Filter 38 | SearchFilter "(&(uid=%u)(accountStatus=active))" 39 | 40 | # Require Group Membership 41 | RequireGroup false 42 | 43 | 44 | BaseDN "ou=Groups,dc=example,dc=com" 45 | SearchFilter "(|(cn=developers)(cn=artists))" 46 | MemberAttribute uniqueMember 47 | 48 | 49 | -------------------------------------------------------------------------------- /tests/data/test-lineNumbers.conf: -------------------------------------------------------------------------------- 1 | line 1 2 | <2 2> 3 | line 3 # Comment 4 | 5 | # Comments 6 | line 6 7 | line 7 8 | line 8 9 | line 9 10 | <10 10> # Comment 11 | <11 11> 12 | 13 | line 13 14 | 15 | line 15 16 | -------------------------------------------------------------------------------- /tests/mockpf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mockpf.h vi:ts=4:sw=4:expandtab: 3 | * Evil testing shim that captures pf ioctls and emulates 4 | * the /dev/pf interface. 5 | * 6 | * Author: Landon Fuller 7 | * 8 | * Portions of the validation code were taken from the pf kernel 9 | * implementation. 10 | * 11 | * Copyright (c) 2002 Cedric Berger 12 | * Copyright (c) 2006 Three Rings Design, Inc. 13 | * All rights reserved. 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions 17 | * are met: 18 | * 19 | * - Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * - Redistributions in binary form must reproduce the above 22 | * copyright notice, this list of conditions and the following 23 | * disclaimer in the documentation and/or other materials provided 24 | * with the distribution. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 29 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 30 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 33 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 34 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 36 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | void mockpf_setup(void); 41 | void mockpf_teardown(void); 42 | -------------------------------------------------------------------------------- /tests/tests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tests.h vi:ts=4:sw=4:expandtab: 3 | * OpenVPN LDAP Authentication Plugin Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2006 Three Rings Design, Inc. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Landon Fuller nor the names of any contributors 19 | * may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifdef HAVE_CONFIG_H 36 | #import 37 | #endif 38 | 39 | /* 40 | * Useful Paths 41 | */ 42 | #ifndef TEST_DATA 43 | #error Path to test data must be supplied at compile time. 44 | #endif 45 | 46 | #define DATA_PATH(relative) TEST_DATA "/" relative 47 | 48 | #ifndef HAVE_PF 49 | #define AUTH_LDAP_CONF DATA_PATH("auth-ldap.conf") 50 | #else 51 | #define AUTH_LDAP_CONF DATA_PATH("auth-ldap-pf.conf") 52 | #endif /* HAVE_PF */ 53 | 54 | #define AUTH_LDAP_CONF_NAMED DATA_PATH("auth-ldap-named.conf") 55 | #define AUTH_LDAP_CONF_MISMATCHED DATA_PATH("auth-ldap-mismatched.conf") 56 | #define AUTH_LDAP_CONF_MULTIKEY DATA_PATH("auth-ldap-multikey.conf") 57 | #define AUTH_LDAP_CONF_REQUIRED DATA_PATH("auth-ldap-required.conf") 58 | #define AUTH_LDAP_CONF_MISSING_NEWLINE DATA_PATH("auth-ldap-missing-newline.conf") 59 | #define AUTH_LDAP_CONF_BAD_SECTION DATA_PATH("auth-ldap-bad-section.conf") 60 | -------------------------------------------------------------------------------- /tests/tests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * tests.c vi:ts=4:sw=4:expandtab: 3 | * OpenVPN LDAP Authentication Plugin Unit Tests 4 | * 5 | * Author: Landon Fuller 6 | * 7 | * Copyright (c) 2005 Landon Fuller 8 | * Copyright (c) 2006 Three Rings Design, Inc. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of Landon Fuller nor the names of any contributors 20 | * may be used to endorse or promote products derived from this 21 | * software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifdef HAVE_CONFIG_H 37 | #include 38 | #endif /* HAVE_CONFIG_H */ 39 | 40 | #import 41 | #import 42 | #import 43 | 44 | #import "TRLog.h" 45 | #import "TRAutoreleasePool.h" 46 | 47 | #import "PXTestCaseRunner.h" 48 | #import "PXTestConsoleResultHandler.h" 49 | 50 | void print_usage(const char *name) { 51 | printf("Usage: %s [filename]\n", name); 52 | printf(" [filename]\tWrite XML log to \n"); 53 | } 54 | 55 | int main(int argc, char *argv[]) { 56 | TRAutoreleasePool *pool = [[TRAutoreleasePool alloc] init]; 57 | 58 | /* Set up the test runner and reporting. */ 59 | PXTestConsoleResultHandler *handler = [[[PXTestConsoleResultHandler alloc] init] autorelease]; 60 | PXTestCaseRunner *runner = [[[PXTestCaseRunner alloc] initWithResultHandler: handler] autorelease]; 61 | 62 | /* Run tests */ 63 | [TRLog _quiesceLogging: YES]; 64 | BOOL success = [runner runAllCases]; 65 | [TRLog _quiesceLogging: NO]; 66 | 67 | [pool release]; 68 | 69 | if (success) { 70 | exit(EXIT_SUCCESS); 71 | } else { 72 | exit(EXIT_FAILURE); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tools/Makefile.in: -------------------------------------------------------------------------------- 1 | srcdir= @srcdir@ 2 | top_srcdir= @top_srcdir@ 3 | top_builddir= @top_builddir@ 4 | VPATH= @srcdir@ 5 | 6 | include ${top_builddir}/Mk/autoconf.mk 7 | include ${top_builddir}/Mk/compile.mk 8 | include ${top_builddir}/Mk/subdir.mk 9 | 10 | # Build the Lemon tool 11 | LEMON_OBJS= lemon.o 12 | 13 | MAKEHEADERS_OBJS= makeheaders.o 14 | CFLAGS= 15 | 16 | all:: lemon makeheaders 17 | 18 | lemon: $(LEMON_OBJS) 19 | $(CC) ${CFLAGS} -o $@ $(LEMON_OBJS) $(LIBS) $(LDFLAGS) 20 | 21 | makeheaders: $(MAKEHEADERS_OBJS) 22 | $(CC) ${CFLAGS} -o $@ $(MAKEHEADERS_OBJS) $(LIBS) $(LDFLAGS) 23 | 24 | clean:: 25 | rm -f $(LEMON_OBJS) lemon 26 | rm -f $(MAKEHEADERS_OBJS) makeheaders 27 | 28 | distclean:: clean 29 | rm -f Makefile 30 | -------------------------------------------------------------------------------- /tools/README: -------------------------------------------------------------------------------- 1 | This directory contains tools required to build the OpenVPN Auth-LDAP Plugin: 2 | - lemon 2012-01-14 was downloaded from http://www.hwaci.com/sw/lemon/ 3 | The Lemon tool was modified as follows: 4 | - Write output to the defined -O path. 5 | - Added missing include to the lempar.c template. 6 | - Include stdio.h in headers generated by makeheaders 7 | 8 | - makeheaders was downloaded from http://www.hwaci.com/sw/mkhdr/ 9 | The makeheaders tool was modified to treat Objective-C source 10 | files (.m) as C files. 11 | -------------------------------------------------------------------------------- /ubuntu_16.04_lts_build.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # git clone https://github.com/snowrider311/openvpn-auth-ldap 4 | # cd openvpn-auth-ldap/ 5 | # source ubuntu_16.04_lts_build.sh 6 | # source ubuntu_16.04_lts_package.sh 7 | 8 | sudo apt-get update 9 | sudo apt-get -y install openvpn autoconf re2c libtool libldap2-dev libssl-dev gobjc make 10 | ./regen.sh 11 | ./configure --with-openvpn=/usr/include/openvpn CFLAGS="-fPIC" OBJCFLAGS="-std=gnu11" 12 | make 13 | sudo make install 14 | -------------------------------------------------------------------------------- /ubuntu_16.04_lts_package.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | sudo apt-get install -y ruby ruby-dev rubygems build-essential 4 | sudo gem install --no-ri --no-rdoc fpm 5 | 6 | mkdir -p /tmp/openvpn-auth-ldap-build/usr/lib/openvpn 7 | sudo mv /usr/local/lib/openvpn-auth-ldap.so /tmp/openvpn-auth-ldap-build/usr/lib/openvpn 8 | fpm -s dir -C /tmp/openvpn-auth-ldap-build -t deb --name openvpn-auth-ldap-snowrider311 \ 9 | --version 2.0.3 --iteration 1 --depends openvpn --depends gnustep-base-runtime \ 10 | --depends libc6 --depends libgnustep-base1.24 --depends libldap-2.4-2 --depends libobjc4 11 | 12 | # To install: 13 | # sudo dpkg -i openvpn-auth-ldap-snowrider311_2.0.3-1_amd64.deb 14 | --------------------------------------------------------------------------------