Skip to contentSkip to conversation

bugfix2.1: automake support for plugin build

Openvpn-devel Mr Dash Four 2 participants 9 messages Jan 6, 2011 3 messages not in the archive Kbuild

lore
Share & tools
lore
#3 lore raw
In reply to a message not in the archive
Quoted 9 lines

I suppose you need to modify the .spec file to make sure you're running autoreconf twice up front (or libtoolize, aclocal, autoconf, automake, possibly autoheader).

Note you'll want to remove the .la files from the destdir, and list the .so files in the %files section, /usr/lib/openvpn/*.so might do the trick ISTR that RPM does globbing.

Your patches did not work!

As with my initial post on this thread - the flags are *exactly* the same (hard-coded):

make: Entering directory `/home/zeek/rpmbuild/BUILD/openvpn-2.1.4/plugin/down-root'
gcc -O2 -Wall -fPIC -c -I../.. down-root.c
gcc -O2 -Wall -fPIC -shared -Wl,-soname,openvpn-down-root.so -o openvpn-down-root.so down-root.o -lc
make: Leaving directory `/home/zeek/rpmbuild/BUILD/openvpn-2.1.4/plugin/down-root'
+ for plugin in down-root auth-pam
+ /usr/bin/make -C plugin/auth-pam
make: Entering directory `/home/zeek/rpmbuild/BUILD/openvpn-2.1.4/plugin/auth-pam'
gcc -O2 -Wall -DDLOPEN_PAM=0 -fPIC -c -I../.. auth-pam.c
gcc -O2 -Wall -DDLOPEN_PAM=0 -fPIC -c -I../.. pamdl.c
gcc -O2 -Wall -DDLOPEN_PAM=0 -fPIC -shared -Wl,-soname,openvpn-auth-pam.so -o openvpn-auth-pam.so auth-pam.o pamdl.o -lc -lpam
make: Leaving directory `/home/zeek/rpmbuild/BUILD/openvpn-2.1.4/plugin/auth-pam'

I also had to adjust your patches slightly to fit the 2.1.4 source tree - see the modified versions attached.

---
 configure.ac |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
configure.ac +1 -1
index 4777108..529abd3 100644
@@ -33,6 +33,7 @@ AC_CONFIG_SRCDIR(syshead.h)
 dnl Guess host type.
 AC_CANONICAL_HOST
 AC_CANONICAL_SYSTEM
+AC_GNU_SOURCE
 AM_INIT_AUTOMAKE(openvpn, [$PACKAGE_VERSION])
 
 AC_ARG_WITH(cygwin-native,
@@ -331,7 +332,6 @@ dnl Checks for programs.
 AC_PROG_CC
 AC_PROG_INSTALL
 AC_PROG_GCC_TRADITIONAL
-AC_GNU_SOURCE
 
 if test "${WIN32}" = "yes"; then
 	AC_ARG_VAR([MAN2HTML], [man2html utility])

This includes autoconf checks so we only build auth-pam on systems that have security/pam_appl.h

---
 Makefile.am   |   16 ++++++++++++++++
 configure.ac  |   10 ++++++++++
 m4/README     |    3 +++
 plugin/README |   13 +++++++------
 4 files changed, 36 insertions(+), 6 deletions(-)
 create mode 100644 m4/README
Makefile.am +16 -0
index ad0f7e3..3918cf7 100644
@@ -29,6 +29,8 @@ LDADD = @LIBOBJS@
 # INSTALL targets:
 AUTOMAKE_OPTIONS = foreign
 
+ACLOCAL_AMFLAGS = -I m4
+
 MAINTAINERCLEANFILES = \
 	config.log config.status \
 	$(srcdir)/Makefile.in \
@@ -141,6 +143,20 @@ openvpn_SOURCES = \
 	win32.h win32.c \
 	cryptoapi.h cryptoapi.c
 
+# building default plugins
+pkglib_LTLIBRARIES =	down-root.la
+if HAVE_PAM
+pkglib_LTLIBRARIES +=	auth-pam.la
+endif
+libtoolmoduleflags =	-module -avoid-version
+down_root_la_SOURCES =	plugin/down-root/down-root.c
+down_root_la_LDFLAGS =	$(libtoolmoduleflags)
+
+auth_pam_la_SOURCES =	plugin/auth-pam/auth-pam.c \
+			plugin/auth-pam/pamdl.h \
+			plugin/auth-pam/pamdl.c
+auth_pam_la_LIBADD =	-lpam
+auth_pam_la_LDFLAGS =	$(libtoolmoduleflags)
 
 dist-hook:
 	cd $(distdir) && for i in $(EXTRA_DIST) $(SUBDIRS) ; do find $$i -name .svn -type d -prune -exec rm -rf '{}' ';' ; rm -f `find $$i -type f | grep -E '(^|\/)\.?\#|\~$$|\.s?o$$'` ; done
configure.ac +6 -0
index 529abd3..f6280cd 100644
@@ -29,6 +29,7 @@ m4_include(version.m4)
 AC_INIT([OpenVPN], [PRODUCT_VERSION], [[email protected]], [openvpn])
 AM_CONFIG_HEADER(config.h)
 AC_CONFIG_SRCDIR(syshead.h)
+AC_CONFIG_MACRO_DIR([m4])
 
 dnl Guess host type.
 AC_CANONICAL_HOST
@@ -325,6 +326,11 @@ dnl Checks for programs.
 AC_PROG_CC
 AC_PROG_INSTALL
 AC_PROG_GCC_TRADITIONAL
+LT_INIT([disable-static])
+dnl we need to dlopen() things, later, we might
+dnl look into libltdl stuff that can possibly link the plugin
+dnl statically, but I suppose that takes changes to plugin.? code,
+dnl too.  -- Matthias Andree, 2011-01-06
 
 if test "${WIN32}" = "yes"; then
	AC_ARG_VAR([MAN2HTML], [man2html utility])

@@ -367,7 +373,9 @@ if test "${WIN32}" != "yes"; then
netinet/tcp.h arpa/inet.h dnl
netdb.h sys/uio.h linux/if_tun.h linux/sockios.h dnl linux/types.h sys/poll.h sys/epoll.h err.h dnl
+ security/pam_appl.h dnl

    )

+
AC_CHECK_HEADERS(net/if.h,,,
[#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
@@ -407,6 +417,8 @@ if test "${WIN32}" != "yes"; then
])
fi

+AM_CONDITIONAL(HAVE_PAM, test "$ac_cv_header_security_pam_appl_h" = yes) +
AC_CACHE_SAVE

dnl check that in_addr_t is defined

m4/README new file +3 -0
new file mode 100644
index 0000000..8f83679
@@ -0,0 +1,3 @@
+This directory is empty in the Git repository and gets
+populated by libtoolize (which is usually run automatically from
+autoreconf).
plugin/README +7 -6
index 6e490c5..7f8d805 100644
@@ -2,8 +2,8 @@ OpenVPN Plugins
 ---------------
 
 Starting with OpenVPN 2.0-beta17, compiled plugin modules are
-supported on any *nix OS which includes libdl or on Windows.
-One or more modules may be loaded into OpenVPN using
+supported on any *nix OS which includes libdl, or on Windows.
+   One or more modules may be loaded into OpenVPN using
 the --plugin directive, and each plugin module is capable of
 intercepting any of the script callbacks which OpenVPN supports:
 
@@ -28,7 +28,7 @@ auth-pam -- Authenticate using PAM and a split privilege
             execution model which functions even if
             root privileges or the execution environment
             have been altered with --user/--group/--chroot.
-            Tested on Linux only.
+            Tested on Linux only.  
 
 down-root -- Enable the running of down scripts with root privileges
              even if --user/--group/--chroot have been used
@@ -42,6 +42,7 @@ examples -- A simple example that demonstrates a portable
 Building Plugins
 ----------------
 
-cd to the top-level directory of a plugin, and use the
-"make" command to build it.  The examples plugin is
-built using a build script, not a makefile.
+The auth-pam and down-root modules are built as part of the regular
+OpenVPN build.  Other than that, cd to the top-level directory of a
+plugin, and use the "make" command to build it.  The examples plugin is
+built using a build script, not a Makefile.
#4 lore raw

Am 06.01.2011 21:42, schrieb Mr Dash Four:

Quoted 14 lines
Quoted 9 lines

I suppose you need to modify the .spec file to make sure you're running autoreconf twice up front (or libtoolize, aclocal, autoconf, automake, possibly autoheader).

Note you'll want to remove the .la files from the destdir, and list the .so files in the %files section, /usr/lib/openvpn/*.so might do the trick ISTR that RPM does globbing.

Your patches did not work!

As with my initial post on this thread - the flags are *exactly* the same (hard-coded):

Quoted 9 lines

make: Entering directory `/home/zeek/rpmbuild/BUILD/openvpn-2.1.4/plugin/down-root' gcc -O2 -Wall -fPIC -c -I../.. down-root.c
gcc -O2 -Wall -fPIC -shared -Wl,-soname,openvpn-down-root.so -o openvpn-down-root.so down-root.o -lc
make: Leaving directory `/home/zeek/rpmbuild/BUILD/openvpn-2.1.4/plugin/down-root'
+ for plugin in down-root auth-pam
+ /usr/bin/make -C plugin/auth-pam

This has gone wrong. The plugins should be built from the top-level directory instead (see below how it works for me), with the regular "make" that also builds openvpn, so the "for plugin in ... make -C $plugin ..." is no longer needed for these two guys.

"make install" should load the material where it belongs, namely into libdir/packagename, i. e. /usr[/local]/lib/openvpn/*.so

But I should possibly remove the Makefiles that are no longer needed.

My log excerpt is given below.

Quoted 10 lines

make: Entering directory `/home/zeek/rpmbuild/BUILD/openvpn-2.1.4/plugin/auth-pam' gcc -O2 -Wall -DDLOPEN_PAM=0 -fPIC -c -I../.. auth-pam.c gcc -O2 -Wall -DDLOPEN_PAM=0 -fPIC -c -I../.. pamdl.c gcc -O2 -Wall -DDLOPEN_PAM=0 -fPIC -shared -Wl,-soname,openvpn-auth-pam.so -o openvpn-auth-pam.so auth-pam.o pamdl.o -lc -lpam
make: Leaving directory `/home/zeek/rpmbuild/BUILD/openvpn-2.1.4/plugin/auth-pam'

Quoted 3 lines

I also had to adjust your patches slightly to fit the 2.1.4 source tree
- see the modified versions attached.

Quite possibly, mine were against git's bugfix2.1 branch. There are minor differences.

...
make[2]: Leaving directory /tmp/ovpn/install-win32' make[2]: Entering directory /tmp/ovpn'
/bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I.
-I/home/emma/VCS-other/openvpn-testing.git
-I/home/emma/VCS-other/openvpn-testing.git -g -O2 -MT down-root.lo
-MD -MP -MF .deps/down-root.Tpo -c -o down-root.lo test -f 'plugin/down-root/down-root.c' || echo '/home/emma/VCS-other/openvpn-testing.git/'plugin/down-root/down-root.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I/home/emma/VCS-other/openvpn-testing.git -I/home/emma/VCS-other/openvpn-testing.git -g -O2 -MT down-root.lo -MD -MP -MF .deps/down-root.Tpo -c /home/emma/VCS-other/openvpn-testing.git/plugin/down-root/down-root.c -fPIC -DPIC -o .libs/down-root.o
mv -f .deps/down-root.Tpo .deps/down-root.Plo
/bin/bash ./libtool --tag=CC --mode=link gcc -g -O2 -module
-avoid-version -o down-root.la -rpath /usr/local/lib/openvpn down-root.lo -lselinux -lssl -lcrypto -llzo2 -ldl
libtool: link: gcc -shared .libs/down-root.o -lselinux -lssl -lcrypto
/usr/lib/liblzo2.so -ldl -Wl,-soname -Wl,down-root.so -o
.libs/down-root.so
libtool: link: ( cd ".libs" && rm -f "down-root.la" && ln -s "../down-root.la" "down-root.la" )
/bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I.
-I/home/emma/VCS-other/openvpn-testing.git
-I/home/emma/VCS-other/openvpn-testing.git -g -O2 -MT auth-pam.lo -MD
-MP -MF .deps/auth-pam.Tpo -c -o auth-pam.lo test -f 'plugin/auth-pam/auth-pam.c' || echo '/home/emma/VCS-other/openvpn-testing.git/'plugin/auth-pam/auth-pam.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I/home/emma/VCS-other/openvpn-testing.git -I/home/emma/VCS-other/openvpn-testing.git -g -O2 -MT auth-pam.lo -MD -MP -MF .deps/auth-pam.Tpo -c /home/emma/VCS-other/openvpn-testing.git/plugin/auth-pam/auth-pam.c -fPIC -DPIC -o .libs/auth-pam.o
mv -f .deps/auth-pam.Tpo .deps/auth-pam.Plo
/bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I.
-I/home/emma/VCS-other/openvpn-testing.git
-I/home/emma/VCS-other/openvpn-testing.git -g -O2 -MT pamdl.lo -MD
-MP -MF .deps/pamdl.Tpo -c -o pamdl.lo test -f 'plugin/auth-pam/pamdl.c' || echo '/home/emma/VCS-other/openvpn-testing.git/'plugin/auth-pam/pamdl.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I/home/emma/VCS-other/openvpn-testing.git -I/home/emma/VCS-other/openvpn-testing.git -g -O2 -MT pamdl.lo -MD -MP -MF .deps/pamdl.Tpo -c /home/emma/VCS-other/openvpn-testing.git/plugin/auth-pam/pamdl.c -fPIC -DPIC -o .libs/pamdl.o
mv -f .deps/pamdl.Tpo .deps/pamdl.Plo
/bin/bash ./libtool --tag=CC --mode=link gcc -g -O2 -module
-avoid-version -o auth-pam.la -rpath /usr/local/lib/openvpn auth-pam.lo pamdl.lo -lpam -lselinux -lssl -lcrypto -llzo2 -ldl
libtool: link: gcc -shared .libs/auth-pam.o .libs/pamdl.o -lpam
-lselinux -lssl -lcrypto /usr/lib/liblzo2.so -ldl -Wl,-soname
-Wl,auth-pam.so -o .libs/auth-pam.so
libtool: link: ( cd ".libs" && rm -f "auth-pam.la" && ln -s "../auth-pam.la" "auth-pam.la" )
gcc -DHAVE_CONFIG_H -I. -I/home/emma/VCS-other/openvpn-testing.git
-I/home/emma/VCS-other/openvpn-testing.git -g -O2 -MT base64.o -MD
-MP -MF .deps/base64.Tpo -c -o base64.o /home/emma/VCS-other/openvpn-testing.git/base64.c
mv -f .deps/base64.Tpo .deps/base64.Po
gcc -DHAVE_CONFIG_H -I. -I/home/emma/VCS-other/openvpn-testing.git
-I/home/emma/VCS-other/openvpn-testing.git -g -O2 -MT buffer.o -MD
-MP -MF .deps/buffer.Tpo -c -o buffer.o /home/emma/VCS-other/openvpn-testing.git/buffer.c
mv -f .deps/buffer.Tpo .deps/buffer.Po
...

HTH

#5 lore raw
Quoted 6 lines

This has gone wrong. The plugins should be built from the top-level directory instead (see below how it works for me), with the regular "make" that also builds openvpn, so the "for plugin in ... make -C $plugin ..." is no longer needed for these two guys.

Quoted 7 lines

"make install" should load the material where it belongs, namely into libdir/packagename, i. e. /usr[/local]/lib/openvpn/*.so

But I should possibly remove the Makefiles that are no longer needed.

My log excerpt is given below.

So, should I remove the for loop then? Would that be enough?

I don't know if it is clear to you, but I am not building OpenVPN to install it on a local machine - I am doing cross-compilation build to end up with rpm, which is for a different architecture to be installed on a completely different machine (my build machine is x86_64, host machine is i686).

So, I am not using ./configure, make and then make install in a sense - I am running "rpmbuild -bb" (which in itself runs configure and make) with a custom-designed openvpn.spec file - this is also where I apply your patches.

#6 lore raw

Am 06.01.2011 23:07, schrieb Mr Dash Four:

Quoted 6 lines
Quoted 6 lines

This has gone wrong. The plugins should be built from the top-level directory instead (see below how it works for me), with the regular "make" that also builds openvpn, so the "for plugin in ... make -C $plugin ..." is no longer needed for these two guys.

Quoted 8 lines
Quoted 7 lines

"make install" should load the material where it belongs, namely into libdir/packagename, i. e. /usr[/local]/lib/openvpn/*.so

But I should possibly remove the Makefiles that are no longer needed.

My log excerpt is given below.

So, should I remove the for loop then? Would that be enough?

If the patch is applied, the libtoolize tool has populated m4/* and you've regenerated the aclocal.m4 with aclocal, the configure and Makefile.in, then it should suffice, yes.

Quoted 5 lines

I don't know if it is clear to you, but I am not building OpenVPN to install it on a local machine - I am doing cross-compilation build to end up with rpm, which is for a different architecture to be installed on a completely different machine (my build machine is x86_64, host machine is i686).

That's what I understood, however this is an easy case as most x86_64 build systems I know can support i686 executables if the necessary libraries are installed, and I found this particular situation (build for i686 on x86_64) to be particularly convenient on Fedora.

Quoted 4 lines

So, I am not using ./configure, make and then make install in a sense - I am running "rpmbuild -bb" (which in itself runs configure and make) with a custom-designed openvpn.spec file - this is also where I apply your patches.

I think you could. ./configure CC="gcc -m32" would normally do, but I haven't gotten around to test drive things on F14.

Well, for patch testing that's the thing. For the next releases, we'll have to wait what James, David, Samuli decide.

HTH

Best regards

Signature · 1 line
Matthias Andree
#9 lore raw
In reply to Matthias Andree
Quoted 6 lines

This has gone wrong. The plugins should be built from the top-level directory instead (see below how it works for me), with the regular "make" that also builds openvpn, so the "for plugin in ... make -C $plugin ..." is no longer needed for these two guys.

I just removed the loop to see if it works - NO! The source for the 2 plugins won't even compile and make install obviously fails.

#10 lore raw

Am 06.01.2011 23:59, schrieb Mr Dash Four:

Quoted 9 lines
Quoted 6 lines

This has gone wrong. The plugins should be built from the top-level directory instead (see below how it works for me), with the regular "make" that also builds openvpn, so the "for plugin in ... make -C $plugin ..." is no longer needed for these two guys.

I just removed the loop to see if it works - NO! The source for the 2 plugins won't even compile and make install obviously fails.

Can you toss your .spec file around?

Signature · 1 line
Matthias Andree
#7 lore raw
In reply to Matthias Andree
Quoted 5 lines

If the patch is applied, the libtoolize tool has populated m4/* and you've regenerated the aclocal.m4 with aclocal, the configure and Makefile.in, then it should suffice, yes.

I am more than willing to send you my spec file for you to look at and can also attach instructions on how to try to build this from source if you wish - just let me know. But it definitely isn't working!

Quoted 5 lines

That's what I understood, however this is an easy case as most x86_64 build systems I know can support i686 executables if the necessary libraries are installed, and I found this particular situation (build for i686 on x86_64) to be particularly convenient on Fedora.

That's not the point. The point is to build a clean i686 package, which is free from any build-machine-arch dependencies (like libgc-x86_64 etc). With the patch I attached (which even though quite basic and rudimentary) this is done, though I think a better solution needs to be found.

Quoted 3 lines

I think you could. ./configure CC="gcc -m32" would normally do, but I haven't gotten around to test drive things on F14.

The arch-dependent flags (line -mXX, -mtune etc) are handled 'automatically' when I specify the --target parameter (i.e. --target=i686 'automatically' sets a bunch of CCFLAGS/LDFLAGS which are arch-dependent) - these are stored in a pretty standard way through 1) the appropriate environment variables (CCFLAGS, LDFLAGS etc); and 2) via the Makefile generated after ./configure is run/executed.

This works for 99% of all cases, except where the appropriate CCFLAGS or LDFLAGS are hard-coded (which is very bad program practice by the way) in a propriety Makefile as is the case with the OpenVPN plugins.

Quoted 3 lines

Well, for patch testing that's the thing. For the next releases, we'll have to wait what James, David, Samuli decide.

So be it then.

#8 lore raw
In reply to Mr Dash Four

Am 07.01.2011 00:12, schrieb Mr Dash Four:

Quoted 8 lines
Quoted 5 lines

If the patch is applied, the libtoolize tool has populated m4/* and you've regenerated the aclocal.m4 with aclocal, the configure and Makefile.in, then it should suffice, yes.

I am more than willing to send you my spec file for you to look at and can also attach instructions on how to try to build this from source if you wish - just let me know. But it definitely isn't working!

Please do. It works for me on FreeBSD amd64 (that's how they call x86_64) with an arcane configure call to tweak everything for a 32-bit build, like this:

../configure -C \
	CPPFLAGS="-I/usr/local/include -m32" \
	LDFLAGS="-L/usr/local/lib -L/usr/lib32 -m32 -B /usr/lib32" \
	--disable-lzo

I was too lazy to compile 32-bit lzo for now, hence the --disable. There is no technical reason though.

Quoted 5 lines

That's not the point. The point is to build a clean i686 package, which is free from any build-machine-arch dependencies (like libgc-x86_64 etc). With the patch I attached (which even though quite basic and rudimentary) this is done, though I think a better solution needs to be found.

That's what I get:

$ uname -m
amd64
$ find . -type f | xargs file | grep ELF | grep -v \\.o: | cut -f1 -d: | xargs file
./.libs/down-root.so: ELF 32-bit LSB shared object, Intel 80386, version 1
(FreeBSD), dynamically linked, not stripped
./.libs/auth-pam.so:  ELF 32-bit LSB shared object, Intel 80386, version 1
(FreeBSD), dynamically linked, not stripped
./openvpn:            ELF 32-bit LSB executable, Intel 80386, version 1
(FreeBSD), dynamically linked (uses shared libs), for FreeBSD 8.1 (801500), not
stripped
$ find . -type f | xargs file | grep ELF | grep -v \\.o: | cut -f1 -d: | xargs ldd
./.libs/down-root.so:
        libssl.so.6 => /usr/lib32/libssl.so.6 (0x281ad000)
        libcrypto.so.6 => /usr/lib32/libcrypto.so.6 (0x28400000)
        libc.so.7 => /usr/lib32/libc.so.7 (0x28090000)
./.libs/auth-pam.so:
        libpam.so.5 => /usr/lib32/libpam.so.5 (0x281ae000)
        libssl.so.6 => /usr/lib32/libssl.so.6 (0x281b5000)
        libcrypto.so.6 => /usr/lib32/libcrypto.so.6 (0x28400000)
        libc.so.7 => /usr/lib32/libc.so.7 (0x28090000)
./openvpn:
        libssl.so.6 => /usr/lib32/libssl.so.6 (0x28100000)
        libcrypto.so.6 => /usr/lib32/libcrypto.so.6 (0x28149000)
        libc.so.7 => /usr/lib32/libc.so.7 (0x282a5000)
Quoted 6 lines

The arch-dependent flags (line -mXX, -mtune etc) are handled 'automatically' when I specify the --target parameter (i.e. --target=i686 'automatically' sets a bunch of CCFLAGS/LDFLAGS which are arch-dependent) - these are stored in a pretty standard way through 1) the appropriate environment variables (CCFLAGS, LDFLAGS etc); and 2) via the Makefile generated after ./configure is run/executed.

I know that --target= triggers macro expansion in various places, but my point is that if you can build openvpn, you get these two plugins for free with the same "make call", and automake takes care to propagate all the needed flags.

Quoted 3 lines

This works for 99% of all cases, except where the appropriate CCFLAGS or LDFLAGS are hard-coded (which is very bad program practice by the way) in a propriety Makefile as is the case with the OpenVPN plugins.

Which means that it's still somehow in your build.

Signature · 1 line
Matthias Andree