autofs-5.0.7 - don't override LDFLAGS in make rules

Ensure that externally defined LDFLAGS is not overridden and ensure
binary is linked as RELRO in tar spec file.
autofs-5.0.7 - fix a couple of compiler warnings

Quiet a couple of ompiler warnings by making intention explicit using brackets.
autofs-5.0.7 - add after sssd dependency to unit file

When using sss as a map source autofs can sometimes start before
sssd is ready.
autofs-5.0.7 - dont start readmap unless ready

State transitions should only be made when an autofs point goes
to state ST_READY or when a new task is added to an empty task
queue.
autofs-5.0.7 - fix crash due to thread unsafe use of libldap

Add locking around LDAP initialization calls

To prevent corruption inside SSL and LDAP libraries, it's necessary to
serialize all calls to functions that initialize LDAP contexts.

How to reproduce the problem:

- Setup an LDAP server with SSL/TLS support enabled
- Configure AutoFS to fetch the maps from LDAP
- Make sure the OpenLDAP client library is configured to use SSL
  connections and "usetls" is set to yes in autofs_ldap_auth.conf.

In one directory handled by AutoFS (an indirect mount point), trigger in
parallel some dozens of invalid mounts (ie, try to access keys that do not
exist in the AutoFS map). Repeat until it crashes.

Here it always crashes in less than 20 minutes, normally inside OpenSSL.
Core dump inspection shows that internal SSL structures are corrupted,
with function pointers pointing to random addresses.

Trying to find similar reports on the web, I found this email from an
OpenLDAP developer (partial quote, emphasis mine) [1]:

"As far as I know, libldap is thread safe in the sense that multiple
threads can use separate LDAP* handles without running into concurrency
issues; *except for library initialization*, all accesses to common data
(i.e. global variables) is read-only."

[1]http://www.openldap.org/cgi-bin/wilma_hiliter/openldap-software/200606/msg00252.html

AutoFS implements no locking around LDAP initialization libraries and
it's quite common to see multiple threads executing ldap_initialize()
or ldap_start_tls_s() at the same time.
autofs-5.0.7 - fix compile error with heimdal support enabled

this patch instroduce a compatible layer between Heimdal and MTT Krb5.
And I slightly rework the original patch to make it more readable.

Upstream Discussion:
  http://thread.gmane.org/gmane.linux.kernel.autofs/4203

Gentoo Bugs:
  https://bugs.gentoo.org/show_bug.cgi?id=210762

Edited by: Ian Kent <raven@themaw.net>
- fix code indentation.
- update configure to include change.

Signed-off-by: Lan Yixun (dlan) <dennis.yxun@gmail.com>
autofs-5.0.7 - fix typo forced-shutdown should be force-shutdown

This will confuse people when they find what shows with "./configure --help"
is different from what is actually used.

Edited by: Ian Kent <raven@themaw.net>
- make description a little more readable.
- update configure to include change.

Signed-off-by: Lan Yixun (dlan) <dennis.yxun@gmail.com>
autofs-5.0.7 - fix hesiod check error and use correct $(LIBS) setting

the problem here is that hesiod checking always fail due to wrong $(LDFLAGS),
no matter hesiod library is installed or not. moving "-lhesiod" into
$(LIBS) solve this problem.

1) convert "char *" -> "void *" to fix the compile warning
2) put "-lhesiod -lresolv" into $(LIBS), not into $(LDFLAGS), otherwise we got link error

Edited by: Ian Kent <raven@themaw.net>
- update configure to include change.
autofs-5.0.7 - fix dead LDAP symbolic link when LDAP support is disabled

autofs will create symbol link mandatory no matter ldap support
is enabled or not. so, without this patch, lookup_ldaps.so will become
a dead link.

Edited by: Ian Kent <raven@themaw.net>
- change check from SASL to LDAP since the ldaps lookup module may
  still be used by ldaps:// as long as LDAP support is built.
autofs-5.0.7 - add missing libtirpc lib to mount_nfs.so when TIRPC enabled

this is need when libtirpc is enabled, otherwise autofs fail to start
due to it can't find symbol clnt_dg_create (which is provided by libtirpc)

autofs error log from /var/log/message:

Jul 23 12:11:58 ofire automount[25699]: open_mount:244: parse(sun): cannot open mount module
nfs (/usr/lib64/autofs/mount_nfs.so: undefined symbol: clnt_dg_create)
Jul 23 12:11:58 ofire automount[25699]: lookup(file): failed to open parse context

without this patch, mount_nfs.so fail link to libtirpc.so
 # ldd /usr/lib64/autofs/mount_nfs.so |grep tirpc

with this patch applied:
 # ldd /usr/lib64/autofs/mount_nfs.so |grep tirpc
        libtirpc.so.1 => /lib64/libtirpc.so.1 (0x00007f7d94920000)

Signed-off-by: Lan Yixun (dlan) <dennis.yxun@gmail.com>
autofs-5.0.7 - use compiler determined by configure instead of hard-coded ones

the logic here is:
 if user pass compiler variable, then use it, otherwise fallback to default value

this will provide most flexibility, so user can set this variable
it would be even useful for cross-compile environment.

Signed-off-by: Lan Yixun (dlan) <dennis.yxun@gmail.com>
autofs-5.0.7 - remove hard-coded STRIP variable

according to autoconf manual[1], build script should allow user override the CFLAGS, LDFLAGS
varible (passed via ./configure). And actually, we should not directly use CFLAGS,
LDFLAGS, but have to create another one (eg. AUTOFS_CFLAGS). FYI, see section "Variable: CFLAGS",
the last paragraph.

Here, I slightly modify the code so that we can still fallback to the default one.

[1] http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Preset-Output-Variables.html#Preset-Output-Variables

Edited by: Ian Kent <raven@themaw.net>
- allow for previous LDFLAGS patch.
- rename patch to reflect what's actually done but leave the original
  description in place as a reminder.

Signed-off-by: Lan Yixun (dlan) <dennis.yxun@gmail.com>
autofs-5.0.7 - use LIBS for link libraries

quote:
 "Don't use this variable to pass library names (-l) to the linker; use LIBS instead."

see the section "Variable: LDFLAGS" in:
http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/PreseOutput-Variables.html#Preset-Output-Variables

Edited by: Ian Kent <raven@themaw.net>
The variable usage changes for LDFLAGS and LIBS appear to be dependent
on each other so merge them to try and avoid breakage if not all are
used by someone. I also had changed the patch titles slightly when I
imported them but they should be easily recognisable.
- merge patches
  - pthread-link-library-should-be-put-into-LIBS-not-LDFLAGS
  - library-should-be-passed-via-variable-LIBS-not-LDFLAGS
  - accumulate-LIBS-variable-changes-otherwise-we-may-lose-early-settings
  - allow-user-to-pass-LDFLAGS-via-configure
- add LIBS to build rules, might fix DMALLOC build problem


Signed-off-by: Lan Yixun (dlan) <dennis.yxun@gmail.com>
autofs-5.0.7 - unbundle NOTSTRIP from DEBUG so they dont depend on each other

Gentoo build system expects unstripped elf image from the build system,
seperate this, will allow us to better control the strip operation.

Signed-off-by: Lan Yixun (dlan) <dennis.yxun@gmail.com>
autofs-5.0.7 - fix occasional build error when enable parallel compiling

The problem here we pass "-jX" ( X> 1) to "make", and "rpc_subs.c"
occasionally fail to compile due to it can't find "mount.h",
the root cause it that "mount.h" haven't generated by that time,
add this patch should fix this problem.
to make rpc_subs.o explicitly depend on "mount.h".

error message:

x86_64-pc-linux-gnu-gcc -O2 -pipe -march=core2  -D_REENTRANT
-D_FILE_OFFSET_BITS=64 -I/usr/include/tirp  c -D_REENTRANT
-D_FILE_OFFSET_BITS=64 -I/usr/include/tirpc -I../include -fPIC
-D_GNU_SOURCE -DAUTOFS_MA  P_DIR=\"/etc/autofs\"
-DAUTOFS_CONF_DIR=\"/etc/conf.d\" -c rpc_subs.c
rpc_subs.c:46:19: fatal error: mount.h: No such file or directory
  #include "mount.h"
                   ^
compilation terminated.
make[1]: *** [rpc_subs.o] Error 1
make[1]: *** Waiting for unfinished
jobs....

Signed-off-by: Lan Yixun (dlan) <dennis.yxun@gmail.com>
autofs-5.0.7 - fix compilation of lookup_ldap.c without sasl

See https://bugs.gentoo.org/show_bug.cgi?id=361899 for more info.

Edited by: Ian Kent <raven@themaw.net>
- fix parse_ldap_config() is needed by ldap but previously excluded.
- exclude other references to ctxt->extern_cert and ctxt->extern_key.
- prevent memory leak if present in config but not used.
- remove now unused set_env().
autofs-5.0.7 - fix dumpmaps multi output

If the maps contain the old style "multi" type the dumped map information
isn't right.
autofs-5.0.7 - try and cleanup after dumpmaps

Try and cleanup a little after dumping maps.
It's not really necessary but but can help by reducing the noise
from valgrind when checking code.
autofs-5.0.7 - teach dumpmaps to output simple key value pairs

The dumpmaps option doesn't allow maps to be output in <key, value>
pairs suitable for use as a file map.

This could be useful to save current maps as a backup for emergency
use.

If the dumpmaps option is given and is followed by two parameters,
"<map type> <map name>" then simple <key, value> pairs that would
be read in by a map read are printed to stdout if the given map type
and map name are found in the map configuration.

If the map is an LDAP map and there is more than one map of same name
in different base dns only the first map encountered by autofs will
be listed.

If the map type is an old style multi-map and any one of the map
names in the multi-map entry matches the given map name the entries
that would be used by autofs for the whole multi-map will be listed.
autofs-5.0.7 - fix syncronize handle_mounts() shutdown

A recent change to fix a problem where automount would exit when re-reading
the master map if more than on entry had been removed causes automount to
ignore HUP signals if the mount list is empty.

Removing that check and testing shows that the remainder of the change still
fixes the original problem.