Skip to contentSkip to conversation

bash->bourne script cleanup

PATCH In review David Sommerseth 2 participants 12 messages Feb 28, 2010 – Apr 22, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bash->bourne script cleanup

From: Dan Nelson <[email protected]...>

Many of the scripts in the openvpn source have their shell set to /bin/bash, but only two use bash features. The attached patch (against openvpn-2.1_rc9) sets the shell on the rest of the scripts to /bin/sh for better portability. The only scripts that actually require bash are contrib/pull-resolv-conf/client.{up,down} ; they use the ${!var} variable indirection feature.

sf.net tracker:
<https://sourceforge.net/tracker/?func=detail&aid=2040296&group_id=48978&atid=454721>

---
 easy-rsa/2.0/build-ca           |    2 +-
 easy-rsa/2.0/build-dh           |    2 +-
 easy-rsa/2.0/build-inter        |    2 +-
 easy-rsa/2.0/build-key          |    2 +-
 easy-rsa/2.0/build-key-pass     |    2 +-
 easy-rsa/2.0/build-key-pkcs12   |    2 +-
 easy-rsa/2.0/build-key-server   |    2 +-
 easy-rsa/2.0/build-req          |    2 +-
 easy-rsa/2.0/build-req-pass     |    2 +-
 easy-rsa/2.0/clean-all          |    2 +-
 easy-rsa/2.0/inherit-inter      |    2 +-
 easy-rsa/2.0/list-crl           |    2 +-
 easy-rsa/2.0/revoke-full        |    2 +-
 easy-rsa/2.0/sign-req           |    2 +-
 sample-config-files/firewall.sh |    2 +-
 sample-scripts/bridge-start     |    2 +-
 sample-scripts/bridge-stop      |    2 +-
 17 files changed, 17 insertions(+), 17 deletions(-)
easy-rsa/2.0/build-ca +1 -1
index fb1e2ca..bce29a6 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # Build a root certificate
easy-rsa/2.0/build-dh +1 -1
index f019222..4beb127 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Build Diffie-Hellman parameters for the server side
 # of an SSL/TLS connection.
easy-rsa/2.0/build-inter +1 -1
index f831d6f..87bf98d 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Make an intermediate CA certificate/private key pair using a locally generated
 # root certificate.
easy-rsa/2.0/build-key +1 -1
index 6196308..6c0fed8 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Make a certificate/private key pair using a locally generated
 # root certificate.
easy-rsa/2.0/build-key-pass +1 -1
index 35543e0..8ef8307 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Similar to build-key, but protect the private key
 # with a password.
easy-rsa/2.0/build-key-pkcs12 +1 -1
index 5ef064f..ba90e6a 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Make a certificate/private key pair using a locally generated
 # root certificate and convert it to a PKCS #12 file including the
easy-rsa/2.0/build-key-server +1 -1
index 5502675..fee0194 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Make a certificate/private key pair using a locally generated
 # root certificate.
easy-rsa/2.0/build-req +1 -1
index 26587d1..559d512 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Build a certificate signing request and private key.  Use this
 # when your root certificate and key is not available locally.
easy-rsa/2.0/build-req-pass +1 -1
index 6e6c863..b73ee1b 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Like build-req, but protect your private key
 # with a password.
easy-rsa/2.0/clean-all +1 -1
index 0576db5..cc6e3b2 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Initialize the $KEY_DIR directory.
 # Note that this script does a
easy-rsa/2.0/inherit-inter +1 -1
index 2101951..aaa5168 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Build a new PKI which is rooted on an intermediate certificate generated
 # by ./build-inter or ./pkitool --inter from a parent PKI.  The new PKI should
easy-rsa/2.0/list-crl +1 -1
index afc0cd6..d1d8a69 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # list revoked certificates
 
easy-rsa/2.0/revoke-full +1 -1
index efc94e8..4169c4c 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # revoke a certificate, regenerate CRL,
 # and verify revocation
easy-rsa/2.0/sign-req +1 -1
index 38655d3..6cae7b4 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Sign a certificate signing request (a .csr file)
 # with a local root certificate and key.
sample-config-files/firewall.sh +1 -1
index f0db806..19d75ee 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # A Sample OpenVPN-aware firewall.
 
sample-scripts/bridge-start +1 -1
index bfbbdc5..d20a260 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #################################
 # Set up Ethernet bridge on Linux
sample-scripts/bridge-stop +1 -1
index d452893..8192779 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 ####################################
 # Tear Down Ethernet bridge on Linux
Signature · 1 line
1.6.6.1
#1 lore raw
Quoted 8 lines · David Sommerseth

From: Dan Nelson <[email protected]...>

Many of the scripts in the openvpn source have their shell set to /bin/bash, but only two use bash features. The attached patch (against openvpn-2.1_rc9) sets the shell on the rest of the scripts to /bin/sh for better portability. The only scripts that actually require bash are contrib/pull-resolv-conf/client.{up,down} ; they use the ${!var} variable indirection feature.

Not only that, they also use arrays, which are not part of standard sh.

For a POSIX-sh compliant solution thad does mostly the same thing (and handles multiple DOMAIN options as well, which client.{up,down} doesn't support), I suggest you look into the Gentoo-provided {up,down}.sh scripts (though they contain some Gentoo-specific parts, but those are easily removed).

Signature · 1 line
D.
#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 10 lines · Davide Brini
Quoted 8 lines · David Sommerseth

From: Dan Nelson <[email protected]...>

Many of the scripts in the openvpn source have their shell set to /bin/bash, but only two use bash features. The attached patch (against openvpn-2.1_rc9) sets the shell on the rest of the scripts to /bin/sh for better portability. The only scripts that actually require bash are contrib/pull-resolv-conf/client.{up,down} ; they use the ${!var} variable indirection feature.

Quoted 7 lines

Not only that, they also use arrays, which are not part of standard sh.

For a POSIX-sh compliant solution thad does mostly the same thing (and handles multiple DOMAIN options as well, which client.{up,down} doesn't support), I suggest you look into the Gentoo-provided {up,down}.sh scripts (though they contain some Gentoo-specific parts, but those are easily removed).

Agreed! If you have time to look at a patch for it, I'd appreciate that. It will go in as a separate patch, to keep the patch flow as simple as possible.

kind regards,

David Sommerseth

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkuXvpwACgkQDC186MBRfrrvAACdEkubTxrMsJUPLErrp2WVckDP vt8AoJx8VGtZ37YMiLI8AR+wXUnEHN8g
=W9YB
-----END PGP SIGNATURE-----

#3 lore raw
Quoted 19 lines · On Wednesday 10 Mar 2010 15:45:32 David Sommerseth wrote:
Quoted 10 lines · Davide Brini
Quoted 8 lines · David Sommerseth

From: Dan Nelson <[email protected]...>

Many of the scripts in the openvpn source have their shell set to /bin/bash, but only two use bash features. The attached patch (against openvpn-2.1_rc9) sets the shell on the rest of the scripts to /bin/sh for better portability. The only scripts that actually require bash are contrib/pull-resolv-conf/client.{up,down} ; they use the ${!var} variable indirection feature.

Quoted 7 lines

Not only that, they also use arrays, which are not part of standard sh.

For a POSIX-sh compliant solution thad does mostly the same thing (and handles multiple DOMAIN options as well, which client.{up,down} doesn't support), I suggest you look into the Gentoo-provided {up,down}.sh scripts (though they contain some Gentoo-specific parts, but those are easily removed).

Quoted 3 lines

Agreed! If you have time to look at a patch for it, I'd appreciate that. It will go in as a separate patch, to keep the patch flow as simple as possible.

Well, I was actually going to write a patch, but shortly after starting I found out that it would end up being essentially the same as Gentoo's scripts. Would it be worth separately maintaining something that has already been written somewhere else?

Note I'm not being argumentative, I'm just trying to understand what pople think, what the policy is, and what would be the best thing to do. It's true that these are just two short scripts, and maintaining them would be no big deal anyway.

Thanks!

Signature · 1 line
D.
#4 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 12 lines · Davide Brini
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines

The only scripts that actually require bash are contrib/pull-resolv-conf/client.{up,down} ; they use the ${!var} variable indirection feature.

Not only that, they also use arrays, which are not part of standard sh.

For a POSIX-sh compliant solution thad does mostly the same thing (and handles multiple DOMAIN options as well, which client.{up,down} doesn't support), I suggest you look into the Gentoo-provided {up,down}.sh scripts (though they contain some Gentoo-specific parts, but those are easily removed).

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

Agreed! If you have time to look at a patch for it, I'd appreciate that. It will go in as a separate patch, to keep the patch flow as simple as possible.

Well, I was actually going to write a patch, but shortly after starting I found out that it would end up being essentially the same as Gentoo's scripts. Would it be worth separately maintaining something that has already been written somewhere else?

I would say that if there are things which are distro related, they should either be found only in that distribution or we can consider (if it is considered important by more people) to put distro specific stuff into a separate folder in the OpenVPN source tree.

If it is possible to get some up/down scripts which are generic for the vast majority of POSIX sh based distributions, that would be the preferred approach. If not, then we are back to where we started :)

Did that answer your question?

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkuYF54ACgkQDC186MBRfrqHwACgpMmlJ9ZQU/CvppJ+3pq1s/ql IqwAoJEk28vBEMeJn44K8sLoJ33h/rqs
=eOoy
-----END PGP SIGNATURE-----

#5 lore raw
Quoted 5 lines · David Sommerseth
Quoted 4 lines

Well, I was actually going to write a patch, but shortly after starting I found out that it would end up being essentially the same as Gentoo's scripts. Would it be worth separately maintaining something that has already been written somewhere else?

Quoted 8 lines

I would say that if there are things which are distro related, they should either be found only in that distribution or we can consider (if it is considered important by more people) to put distro specific stuff into a separate folder in the OpenVPN source tree.

If it is possible to get some up/down scripts which are generic for the vast majority of POSIX sh based distributions, that would be the preferred approach. If not, then we are back to where we started :)

Ok, here it goes (it's against 2.1.1). As said, it's basically a complete rewrite that draws many ideas from the Gentoo scripts. These are the main differences from the "old" client.{up,down} scripts:

- No more bashisms (AFAICT). Should work with any POSIX-compatible shell (which means "almost all reasonably recent shells"), though I've only tested with bash and dash.

- Unnecessary calls to external tools (sed) removed

- Manages multiple DNS and DOMAIN options. Each DNS option becomes a "nameserver" line in the new resolv.conf (up to a maximum of 3). If there's a single DOMAIN option, it becomes a "domain" line in resolv.conf; otherwise, all the domains are listed in a "search" line in resolv.conf (eg "search foo.com example.net").

- Client.up renames the existing resolv.conf and creates a brand new one; client.down restores it from the saved copy when the VPN terminates (the usual rules about running as root apply). This is how Gentoo does that; the old scripts instead added/removed some lines at the beginning of the file, which looks a less clean approach to me. The rename approach also dramatically simplifies and shortens client.down, as you'll see.

- Uses resolvconf if it's available (detected by the presence of /sbin/resolvconf) rather than writing to resolv.conf directly. Not sure whether this is a Linux-only thing or other systems use it though.

A doubt I have is: should the script output its errors as it does now? If yes, is it possible to somehow send them to the main OpenVPN log so they appear among the other normal messages?

Let me know what you think.

In case lines wrap, which is likely, I'm also attaching the file.

diff -burp openvpn-2.1.1/contrib/pull-resolv-conf/client.up openvpn-2.1.1- a/contrib/pull-resolv-conf/client.up > clientup.patch
--- openvpn-2.1.1/contrib/pull-resolv-conf/client.up 2009-10-01
19:02:17.000000000 +0100
+++ openvpn-2.1.1-a/contrib/pull-resolv-conf/client.up 2010-03-11 21:32:03.000000000 +0000
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh

# Copyright (c) 2005-2009 OpenVPN Technologies, Inc.
# Licensed under the GPL version 2
@@ -14,7 +14,6 @@
# Place this in /etc/openvpn/client.up
# Then, add the following to your /etc/openvpn/<clientconfig>.conf:

 #   client
-#   pull dhcp-options
 #   up /etc/openvpn/client.up

# Next, "chmod a+x /etc/openvpn/client.up"

@@ -22,8 +21,8 @@
# Note that this script is best served with the companion "client.down"

 # script.

-# Only tested on Gentoo Linux 2005.0 with OpenVPN 2.0
-# It should work with any GNU/Linux with /etc/resolv.conf +# Tested under Debian lenny with OpenVPN 2.1_rc11
+# It should work with any UNIX with a POSIX sh, /etc/resolv.conf or resolvconf

# This runs with the context of the OpenVPN UID/GID

 # at the time of execution. This generally means that
@@ -38,38 +37,64 @@
 # init variables

i=1
-j=1
-unset fopt
-unset dns
-unset opt
-
-# Convert ENVs to an array
-
-while fopt=foreign_option_$i; [ -n "${!fopt}" ]; do
-{
- opt[i-1]=${!fopt}
- case ${opt[i-1]} in
- *DOMAIN* ) domain=`echo ${opt[i-1]} | \
- sed -e 's/dhcp-option DOMAIN //g'` ;;
- *DNS* ) dns[j-1]=`echo ${opt[i-1]} | \
- sed -e 's/dhcp-option DNS //g'`
- let j++ ;;
+domains=
+fopt=
+ndoms=0
+nns=0
+nl='
+'
+
+# $foreign_option_<n> is something like
+# "dhcp-option DOMAIN example.com" (multiple allowed)
+# or
+# "dhcp-option DNS 10.10.10.10" (multiple allowed)
+
+# each DNS option becomes a "nameserver" option in resolv.con +# if we get one DOMAIN, that becomes "domain" in resolv.conf +# if we get multiple DOMAINS, those become "search" lines in resolv.conf +
+while true; do
+ eval fopt=\$foreign_option_${i}
+ [ -z "${fopt}" ] && break
+
+ case ${fopt} in
+ dhcp-option\ DOMAIN\ *)

+           ndoms=$((ndoms + 1))
+           domains="${domains} ${fopt#dhcp-option DOMAIN }"
+           ;;

+ dhcp-option\ DNS\ *)
+ nns=$((nns + 1))
+ if [ $nns -le 3 ]; then
+ dns="${dns}${dns:+$nl}nameserver ${fopt#dhcp-option DNS }"
+ else
+ printf "%s\n" "Too many nameservers - ignoring after third" >&2
+ fi
+ ;;
+ *)
+ printf "%s\n" "Unknown option \"${fopt}\" - ignored" >&2
+ ;;
esac
- let i++
-}
+ i=$((i + 1))
done

-# Now, do the work
-
-if [ -n "${dns[*]}" ]; then
- for i in "${dns[@]}"; do
- sed -i -e "1,1 i nameserver ${i}" /etc/resolv.conf || die
- done
+ds=domain
+if [ $ndoms -gt 1 ]; then
+ ds=search
fi

-if [ -n "${domain}" ]; then
- sed -i -e "$j,1 i search ${domain}" /etc/resolv.conf || die
+# This is the complete file - "$domains" has a leading space already +out="# resolv.conf autogenerated by ${0} (${1})${nl}${dns}${nl}${ds}${domains}"
+
+# use resolvconf if it's available
+if [ -x /sbin/resolvconf ] ; then
+ printf "%s\n" "${out}" | /sbin/resolvconf -a "${1}" +else
+ # Preserve the existing resolv.conf
+ if [ -e /etc/resolv.conf ] ; then
+ cp /etc/resolv.conf /etc/resolv.conf.ovpnsave

+  fi
+  printf "%s\n" "${out}" > /etc/resolv.conf
+  chmod 644 /etc/resolv.conf

fi

-# all done...
exit 0
diff -burp openvpn-2.1.1/contrib/pull-resolv-conf/client.down openvpn-2.1.1- a/contrib/pull-resolv-conf/client.down >> clientup.patch
--- openvpn-2.1.1/contrib/pull-resolv-conf/client.down 2009-10-01 19:02:17.000000000 +0100
+++ openvpn-2.1.1-a/contrib/pull-resolv-conf/client.down 2010-03-11
21:32:09.000000000 +0000
@@ -14,7 +14,6 @@
# Place this in /etc/openvpn/client.down
# Then, add the following to your /etc/openvpn/<clientconfig>.conf:

 #   client
-#   pull dhcp-options
 #   up /etc/openvpn/client.up
 #   down /etc/openvpn/client.down
 # Next, "chmod a+x /etc/openvpn/client.down"
@@ -23,8 +22,8 @@
 # Note that this script is best served with the companion "client.up"
 # script.

-# Only tested on Gentoo Linux 2005.0 with OpenVPN 2.0
-# It should work with any GNU/Linux with /etc/resolv.conf +# Tested under Debian lenny with OpenVPN 2.1_rc11
+# It should work with any UNIX with a POSIX sh, /etc/resolv.conf or resolvconf

# This runs with the context of the OpenVPN UID/GID

 # at the time of execution. This generally means that
@@ -36,41 +35,12 @@
 # is to run OpenVPN as root. THIS IS NOT RECOMMENDED. You have
 # been WARNED.

-# init variables
-
-i=1
-j=1
-unset fopt
-unset dns
-unset opt
-
-# Convert ENVs to an array
-
-while fopt=foreign_option_$i; [ -n "${!fopt}" ]; do -{
- opt[i-1]=${!fopt}
- case ${opt[i-1]} in
- *DOMAIN* ) domain=`echo ${opt[i-1]} | \
- sed -e 's/dhcp-option DOMAIN //g'` ;;
- *DNS* ) dns[j-1]=`echo ${opt[i-1]} | \
- sed -e 's/dhcp-option DNS //g'`
- let j++ ;;
- esac
- let i++
-}
-done
-
-# Now, do the work
-
-if [ -n "${dns[*]}" ]; then
- for i in "${dns[@]}"; do
- sed -i -e "/nameserver ${i}/D" /etc/resolv.conf || die
- done
-fi
-
-if [ -n "${domain}" ]; then
- sed -i -e "/search ${domain}/D" /etc/resolv.conf || die
+if [ -x /sbin/resolvconf ] ; then
+ /sbin/resolvconf -d "${1}"
+elif [ -e /etc/resolv.conf.ovpnsave ] ; then

+  # cp + rm rather than mv in case it's a symlink
+  cp /etc/resolv.conf.ovpnsave /etc/resolv.conf
+  rm -f /etc/resolv.conf.ovpnsave

fi

-# all done...
exit 0

Signature · 1 line
D.
contrib/pull-resolv-conf/client.up +56 -31
diff -burp openvpn-2.1.1/contrib/pull-resolv-conf/client.up openvpn-2.1.1-a/contrib/pull-resolv-conf/client.up
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Copyright (c) 2005-2009 OpenVPN Technologies, Inc.
 # Licensed under the GPL version 2
@@ -14,7 +14,6 @@
 # Place this in /etc/openvpn/client.up
 # Then, add the following to your /etc/openvpn/<clientconfig>.conf:
 #   client
-#   pull dhcp-options
 #   up /etc/openvpn/client.up
 # Next, "chmod a+x /etc/openvpn/client.up"
 
@@ -22,8 +21,8 @@
 # Note that this script is best served with the companion "client.down"
 # script.
 
-# Only tested on Gentoo Linux 2005.0 with OpenVPN 2.0
-# It should work with any GNU/Linux with /etc/resolv.conf
+# Tested under Debian lenny with OpenVPN 2.1_rc11
+# It should work with any UNIX with a POSIX sh, /etc/resolv.conf or resolvconf
 
 # This runs with the context of the OpenVPN UID/GID 
 # at the time of execution. This generally means that
@@ -38,38 +37,64 @@
 # init variables
 
 i=1
-j=1
-unset fopt
-unset dns
-unset opt
-
-# Convert ENVs to an array
-
-while fopt=foreign_option_$i; [ -n "${!fopt}" ]; do
-{
-	opt[i-1]=${!fopt}
-	case ${opt[i-1]} in
-		*DOMAIN* ) domain=`echo ${opt[i-1]} | \
-				sed -e 's/dhcp-option DOMAIN //g'` ;;
-		*DNS*    ) dns[j-1]=`echo ${opt[i-1]} | \
-				sed -e 's/dhcp-option DNS //g'`
-			       let j++ ;;
+domains=
+fopt=
+ndoms=0
+nns=0
+nl='
+'
+
+# $foreign_option_<n> is something like 
+# "dhcp-option DOMAIN example.com" (multiple allowed)
+# or
+# "dhcp-option DNS 10.10.10.10" (multiple allowed)
+
+# each DNS option becomes a "nameserver" option in resolv.con
+# if we get one DOMAIN, that becomes "domain" in resolv.conf
+# if we get multiple DOMAINS, those become "search" lines in resolv.conf
+
+while true; do
+  eval fopt=\$foreign_option_${i}
+  [ -z "${fopt}" ] && break
+  
+  case ${fopt} in
+		dhcp-option\ DOMAIN\ *)
+           ndoms=$((ndoms + 1))
+           domains="${domains} ${fopt#dhcp-option DOMAIN }"
+           ;;
+		dhcp-option\ DNS\ *)
+           nns=$((nns + 1))
+           if [ $nns -le 3 ]; then
+             dns="${dns}${dns:+$nl}nameserver ${fopt#dhcp-option DNS }"
+           else
+             printf "%s\n" "Too many nameservers - ignoring after third" >&2
+           fi
+           ;;
+        *)
+           printf "%s\n" "Unknown option \"${fopt}\" - ignored" >&2
+           ;; 
 	esac
-	let i++
-}
+  i=$((i + 1))
 done
 
-# Now, do the work
-
-if [ -n "${dns[*]}" ]; then
-	for i in "${dns[@]}"; do
-		sed -i -e "1,1 i nameserver ${i}" /etc/resolv.conf || die
-	done
+ds=domain
+if [ $ndoms -gt 1 ]; then
+  ds=search
 fi
 
-if [ -n "${domain}" ]; then
-	sed -i -e "$j,1 i search ${domain}" /etc/resolv.conf || die
+# This is the complete file - "$domains" has a leading space already
+out="# resolv.conf autogenerated by ${0} (${1})${nl}${dns}${nl}${ds}${domains}"
+
+# use resolvconf if it's available
+if [ -x /sbin/resolvconf ] ; then
+  printf "%s\n" "${out}" | /sbin/resolvconf -a "${1}"
+else
+  # Preserve the existing resolv.conf
+  if [ -e /etc/resolv.conf ] ; then
+    cp /etc/resolv.conf /etc/resolv.conf.ovpnsave
+  fi
+  printf "%s\n" "${out}" > /etc/resolv.conf
+  chmod 644 /etc/resolv.conf
 fi
 
-# all done...
 exit 0
contrib/pull-resolv-conf/client.down +8 -38

64 lines not on this page · raw message

author Applied
#6 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 43 lines · Davide Brini
Quoted 5 lines · David Sommerseth
Quoted 4 lines

Well, I was actually going to write a patch, but shortly after starting I found out that it would end up being essentially the same as Gentoo's scripts. Would it be worth separately maintaining something that has already been written somewhere else?

Quoted 8 lines

I would say that if there are things which are distro related, they should either be found only in that distribution or we can consider (if it is considered important by more people) to put distro specific stuff into a separate folder in the OpenVPN source tree.

If it is possible to get some up/down scripts which are generic for the vast majority of POSIX sh based distributions, that would be the preferred approach. If not, then we are back to where we started :)

Ok, here it goes (it's against 2.1.1). As said, it's basically a complete rewrite that draws many ideas from the Gentoo scripts. These are the main differences from the "old" client.{up,down} scripts:

- No more bashisms (AFAICT). Should work with any POSIX-compatible shell (which means "almost all reasonably recent shells"), though I've only tested with bash and dash.

- Unnecessary calls to external tools (sed) removed

- Manages multiple DNS and DOMAIN options. Each DNS option becomes a "nameserver" line in the new resolv.conf (up to a maximum of 3). If there's a single DOMAIN option, it becomes a "domain" line in resolv.conf; otherwise, all the domains are listed in a "search" line in resolv.conf (eg "search foo.com example.net").

- Client.up renames the existing resolv.conf and creates a brand new one; client.down restores it from the saved copy when the VPN terminates (the usual rules about running as root apply). This is how Gentoo does that; the old scripts instead added/removed some lines at the beginning of the file, which looks a less clean approach to me. The rename approach also dramatically simplifies and shortens client.down, as you'll see.

- Uses resolvconf if it's available (detected by the presence of /sbin/resolvconf) rather than writing to resolv.conf directly. Not sure whether this is a Linux-only thing or other systems use it though.

Quoted 5 lines

A doubt I have is: should the script output its errors as it does now? If yes, is it possible to somehow send them to the main OpenVPN log so they appear among the other normal messages?

Let me know what you think.

ACK!

I've done a quick test on one of my connections on Fedora 12 without any resolvconf package (meaning it invokes the simple cp approach), and it worked like a charm.

Applied to bugfix2.1 and merged into allmerged.
Commit a9c9a89e96dc1e4e843e05ecadc4349b81606b06

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkvMwe0ACgkQDC186MBRfroWOwCeMFu3NO/s6UDeTSjGkmde/DpQ MtsAn0rqsF7B5/4RIjcF4k7zyoryvhsw
=RuVf
-----END PGP SIGNATURE-----

#7 lore raw
Quoted 6 lines · David Sommerseth

I've done a quick test on one of my connections on Fedora 12 without any resolvconf package (meaning it invokes the simple cp approach), and it worked like a charm.

Applied to bugfix2.1 and merged into allmerged.
Commit a9c9a89e96dc1e4e843e05ecadc4349b81606b06

Sorry, I just realized that I didn't change the sha-bang line in client.down. Apologies. Fix attached.

Signature · 1 line
D.
contrib/pull-resolv-conf/client.down 2010-04-19 22:33:53.000000000 +0100 renamed from contrib/pull-resolv-conf/client.down 2010-03-11 21:32:09.000000000 +0000 +1 -1
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Copyright (c) 2005-2009 OpenVPN Technologies, Inc.
 # Licensed under the GPL version 2
#8 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 11 lines · Davide Brini
Quoted 6 lines · David Sommerseth

I've done a quick test on one of my connections on Fedora 12 without any resolvconf package (meaning it invokes the simple cp approach), and it worked like a charm.

Applied to bugfix2.1 and merged into allmerged.
Commit a9c9a89e96dc1e4e843e05ecadc4349b81606b06

Sorry, I just realized that I didn't change the sha-bang line in client.down. Apologies. Fix attached.

No problem! And thanks a lot for fixing it! I should have caught that one during my review as well. I looked at "everything", but managed to not notice this one as well. Anyway, I gave it an ACK and it's now in the bugfix2.1 branch. As this is a non-critical fix, I'll delay pushing it to allmerged until more patches comes in. You'll find it as commit 2d9c14b435ae4083aa3f6bce803ede27cce2b6cb

For future patches, would you mind adding a little bit more descriptive text which can be used as commit log messages. I do write those commit logs when I find it is needed, but adding a little bit more descriptions of what the patch does is a nice and good habit - no matter how easy the patch looks like ... and it makes my maintenance job a lot easier and quicker.

I won't reject good patches due to missing commit messages, but it I'm not picking these patches first for inclusion - as they require more work. So the easier the patches are for me to work with, the quicker they go into the tree after the required review.

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkvQAowACgkQDC186MBRfrrhCQCfdrZTU2ilBNQ+K8FC8iDguloq X04An0/BxnoqesB1CqCS+BzYdreb8rrh
=q4xW
-----END PGP SIGNATURE-----

#9 lore raw
Quoted 6 lines · On Thursday 22 Apr 2010 09:02:23 David Sommerseth wrote:

For future patches, would you mind adding a little bit more descriptive text which can be used as commit log messages. I do write those commit logs when I find it is needed, but adding a little bit more descriptions of what the patch does is a nice and good habit - no matter how easy the patch looks like ... and it makes my maintenance job a lot easier and quicker.

Sure, no problem. But just to make it clear (please forgive my ignorance), my original message for the patch contained quite a detailed explanation of what it does. I assume that was too long, and you need a 1-2 lines summary to use for the commit? Of course this is not to say that the detailed explanation should be missing, only that you need the brief summary as well. Is my understanding correct?

Thanks.

Signature · 1 line
D.
#10 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 9 lines · Davide Brini
Quoted 6 lines · On Thursday 22 Apr 2010 09:02:23 David Sommerseth wrote:

For future patches, would you mind adding a little bit more descriptive text which can be used as commit log messages. I do write those commit logs when I find it is needed, but adding a little bit more descriptions of what the patch does is a nice and good habit - no matter how easy the patch looks like ... and it makes my maintenance job a lot easier and quicker.

Quoted 3 lines

Sure, no problem. But just to make it clear (please forgive my ignorance), my original message for the patch contained quite a detailed explanation of what it does.

Sorry, I was a bit unclear ... the initial patch had good info! And as you can see in the commit log, I've used a lot of that text.

Quoted 2 lines

I assume that was too long, and you need a 1-2 lines summary to use for the commit?

It doesn't need to be a novel, but I do prefer longer ones and not just 1-2 lines. So not too short, please :)

Quoted 3 lines

Of course this is not to say that the detailed explanation should be missing, only that you need the brief summary as well. Is my understanding correct?

Ideally a commit log should state the problem the patch should fix and give the basic ideas of how you solved it - without being too technical, as the patch will describe the technical details. But things which might be difficult to understand in the code, should be explained in "plain English" in the commit log.

If applicable, also add references to mail discussions, chat logs, etc, if that is relevant and can give more background information. This is important when someone wants to investigate the patches later on, maybe even someone who is fresh to the OpenVPN code.

And if your text can be used as a "copy-paste" into the git commit, that's what I'd prefer :)

Another thing I've began to add to commit logs are those "Signed-off-by:" lines for those submitting the patches. So, please add "Signed-off-by:" lines as well.

<description_of_signed_off_process>

To explain the Signed-off-by and Acked-by process a bit further. I do now separate commit Author and sender. The difference is that the author field should be a reference to the one who *wrote* the patch. This person sends it to someone, and would add the first "Signed-off-by" message as a "signature" of the patch. This indicates that the author finds the patch ready to be sent further.

Then the one who receives the patch and finds it good to go further, will add his/hers "Signed-off-by" reference. That way we can track who have been looking at the patch. Before it goes into the tree, a final "Acked-by:" note is added, indicating who accepted it for inclusion into the tree.

So, if John Doe writes a patch, sends it to Jane Doe and she sends it Bob Boss for inclusion the process would be:

John Doe:
Author: John Doe <[email protected]...>
Patch fixing x.y.z

explaining the patch

<the patch itself>

Jane Doe will send it further as:

	Author: John Doe <[email protected]...>
	Patch fixing x.y.z

	explaining the patch

	Signed-off-by: John Doe <[email protected]...>
	Signed-off-by: Jane Doe <[email protected]...>	

	<the patch itself>

And when Bob Boss ACK's the patch, the final commit to be found in the tree will be:

	Author: John Doe <[email protected]...>
	Patch fixing x.y.z

	explaining the patch

	Signed-off-by: John Doe <[email protected]...>
	Signed-off-by: Jane Doe <[email protected]...>	
	Signed-off-by: David Sommerseth <[email protected]...>
	Acked-by: Bob Boss <[email protected]...>

	<the patch itself>

The Acked-by: can also be someone who don't do the final commit[1]. Or it can be my patches which I've sent for review before including them[2]. And it can of course be ACKed by the same person who do the final commit. The last Signed-off-by should normally be the person the one who does the final commit. This is the person who "touched" the patch by adding the Acked-by line(s).

However, you should not see any commits which is written by (author) and Acked-by by the same person. Then the process have failed to give a qualified review.

You may ask why we have this "bureaucracy" (which is a fair question!) It is simply to keep all who send in patches, those who reviews them and finally accepts them into the source tree more accountable for their work. And to document that each accepted patch has been through a certain set of reviews.

As these patches will go back into SVN, it's not possible to, AFAIK, to track authors and committers explicitly - so we track it in the commit log as well. Just to keep this project as transparent as possible.

For now, the only patches which which "breaks" this in the git tree are the patches coming in from James' SVN BETA21 branch. But I trust that James tracks the patches he pulls in according to the standards he needs. After all, we just prepare the "next version" tree for James - thus we're having stricter tracking, to make it more comfortable for James to accept our patches.

</description_of_signed_off_process>

kind regards,

David Sommerseth

[1] Example: See commit d81eb4cf0ec387
[2] Example: See commit 5acb71a0aab49e
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkvQEfEACgkQDC186MBRfrrzzgCfT0bXn/84XqKF2fzDByGzYPXn j9oAnR+FPGiOixL22YTNCI3cwjKJmXOs
=HMaq
-----END PGP SIGNATURE-----

#11 lore raw
In reply to David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 24 lines · David Sommerseth

From: Dan Nelson <[email protected]...>

Many of the scripts in the openvpn source have their shell set to /bin/bash, but only two use bash features. The attached patch (against openvpn-2.1_rc9) sets the shell on the rest of the scripts to /bin/sh for better portability. The only scripts that actually require bash are contrib/pull-resolv-conf/client.{up,down} ; they use the ${!var} variable indirection feature.

sf.net tracker:
<https://sourceforge.net/tracker/?func=detail&aid=2040296&group_id=48978&atid=454721>

---
 easy-rsa/2.0/build-ca           |    2 +-
 easy-rsa/2.0/build-dh           |    2 +-
 easy-rsa/2.0/build-inter        |    2 +-
 easy-rsa/2.0/build-key          |    2 +-
 easy-rsa/2.0/build-key-pass     |    2 +-
 easy-rsa/2.0/build-key-pkcs12   |    2 +-
 easy-rsa/2.0/build-key-server   |    2 +-
 easy-rsa/2.0/build-req          |    2 +-
 easy-rsa/2.0/build-req-pass     |    2 +-
 easy-rsa/2.0/clean-all          |    2 +-
Quoted 9 lines
 easy-rsa/2.0/inherit-inter      |    2 +-
 easy-rsa/2.0/list-crl           |    2 +-
 easy-rsa/2.0/revoke-full        |    2 +-
 easy-rsa/2.0/sign-req           |    2 +-
 sample-config-files/firewall.sh |    2 +-
 sample-scripts/bridge-start     |    2 +-
 sample-scripts/bridge-stop      |    2 +-
 17 files changed, 17 insertions(+), 17 deletions(-)

Patch applied to bugfix2.1 branch, merged into allmerged. Commit b75eb4c5a1cd31effcad9b6fa686dbd43527730a

kind regards,

David Sommerseth

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkuXvlIACgkQDC186MBRfrq19wCggOAdo60oWyurnzc76hLwL53k yDIAn2rRw6vNPz++dLnyjjZ6UvNp+vIs
=mGYY
-----END PGP SIGNATURE-----