config API: add missing subdomain target to AD provider test

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
SUDO: AD provider

This patch adds the sudo target to the AD provider. The main reason is
to cover different default settings in the LDAP and AD provider. E.g.
the default for ldap_id_mapping is True in the AD provider and False
in the LDAP provider. If ldap_id_mapping was not set explicitly in the
config file both components worked with different setting.

Fixes https://fedorahosted.org/sssd/ticket/2256

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
config API: read only specific files from schemaplugindir

Currently the config API read any file in the schema plugin dir,
typically /usr/share/sssd/sssd.api.d. If there are any unexpected files,
like e.g. editor copies or backups, the python code might break because
it cannot parse the files.

With this patch only files matching the pattern '^sssd-.*\.conf$' are
read from this directory.

Additionally this patch contains a file which will break the config API
self test if it is not filtered out correctly.

Reviewed-by: Stephen Gallagher <sgallagh@redhat.com>
config API: prepend source dir search path for tests

Instead of appending the search patch in the source directory should be
prepended. Otherwise the test might find files installed in the default
paths of the system first.

As a result the compiled python files in the build directory must be
remove in the clean target to make 'make distcheck' pass.

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
ipa-server-mode: use lower-case user name for home dir

In older IPA server versions where the AD users where looked up by
winbind the user name component of the home directory path was always
lower case.  This still holds for IPA clients as well. To avoid
regression this patch makes the user name component lower case as well.

Fixes https://fedorahosted.org/sssd/ticket/2263

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
IPA: Do not save intermediate data to sysdb

https://fedorahosted.org/sssd/ticket/2264

Reviewed-by: Sumit Bose <sbose@redhat.com>
Unit-test-for-negcache-module-added

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
TEST: Use unique directory for negcache test

nss-srv-tests and test-negcache wrote temporary files to the same subdirectory
'tests_nss'. There could be a race condition when tests ran in parallel.
The first test could remove directory which the second one wanted to use.

[ldb] (0x0020): Unable to open tdb 'tests_nss/test_nss_conf.ldb'
[ldb] (0x0020): Failed to connect to 'tests_nss/test_nss_conf.ldb'
    with backend 'tdb': Unable to open tdb 'tests_nss/test_nss_conf.ldb'
[confdb_init] (0x0010): Unable to open config database
    [tests_nss/test_nss_conf.ldb]
[create_dom_test_ctx] (0x0020): confdb_init failed: 5

Reviewed-by: Michal Žídek <mzidek@redhat.com>
PAM: Test return value of strdup

Warnings reported by Coverity (12463,12464)

Dereferencing a pointer that might be null pi->pam_authtok when calling strlen.
Dereferencing a pointer that might be null action when calling strncmp.

Reviewed-by: Stephen Gallagher <sgallagh@redhat.com>
providers: Fix types passed to dbus varargs functions

Fix some incorrect types passed to dbus_message_get_args(),
dbus_message_append_args() or functions accepting similar
varargs and types.

In particular sizeof(bool) != sizeof(dbus_bool_t) on most
platforms. This probably only worked because the compiler
was aligning stack variables and so writing off the end of
one of them wasn't the end of the world.

In addition fix cases where int != int32_t != uint32_t.
Although these will work on many common platforms, assuming
these are interchangeable is not cross platform safe.
sbus: Add struct sbus_request to represent a DBus invocation

struct sbus_request represents a request from a dbus client
being handled by a dbus server implementation. The struct
contains the message, connection and method (and in the
future teh property) which is being requested.

In the future it will contain caller information as well.

sbus_request is a talloc memory context, and is a good place to
attach any allocations and memory specific to the request.

Each handler accepts an sbus_request. If a handler returns
EOK, it is assumed that the handler will finish the request.
Any of the sbus_request_*finish() methods can be used to
complete the request and send back a reply.

sbus_request_return_and_finish() uses the same argument
varargs syntax as dbus_message_append_args(), which isn't
a great syntax. Document it a bit, but don't try to redesign:
The marshalling work (will follow this patch set) will remove
the need to use varargs for most DBus implementation code.

This patch migrates the monitor and data provider dbus code
to use sbus_request, but does not try to rework the talloc
context's to use it.
sbus: Refactor how we export DBus interfaces

Most importantly, stop using per connection private data. This doesn't
scale when you have more than one thing exporting or exported on a
connection.

Remove struct sbus_interface and expand sbus_conn_add_interface()
function. Remove various struct sbus_interface args to connection
initialization functions and make callers use sbus_conn_add_interface()
directly. The old method was optimized for exporting one interface
on a connection. We'll have connections that export zero, one or more
interfaces.

To export an interface on a DBus server, call sbus_conn_add_interface()
from within the sbus_server_conn_init_fn. To export an interface on
a DBus client, call sbus_conn_add_interface() after sbus_new_connection()
returns.

As before struct sbus_interface represents an object exported via DBus.
However it is now talloc allocated. One can set instance data on the
struct sbus_interface. This instance data is passed to the various
handlers and used in their implementation.

However, we now have type safe interface exporting in the various
high level sss_process_init() sss_monitor_init() and so on.

Introspection support was not in use, and is now gone until we
implement it using the metadata (future patch).
sbus: Make sbus_new_server() work for non-priveleged processes

I'd like to use this during testing. We should check that the
socket ownership is the same as the process, rather than limiting
it to root.
sbus_tests: Add some testing of dispatch and handler code

This starts a DBus server with some handlers, and runs some method
calls against it.

Note that we don't use the codegen in the sbus_tests, as we sorta
want to test this non-codegen related functionality on its own before
we run the sbus_codegen_tests.
sbus: Add the sbus_request_parse_or_finish() method

Some DBus types returned from dbus_message_get_args() require memory
to be released when done. We automatically attach these to the talloc
struct sbus_request memory context in this function.

This accepts varargs similar to dbus_message_get_args(), which are
rather awkward. However instead of reworking them completely, future
generated marshalling code will replace most uses of these varargs.

If parsing the dbus message fails, then it responds to the DBus caller
with an appropriate error such as o.f.D.Error.InvalidArgs. In these
cases (ie: when it returns FALSE) the sbus_request is finished.

Migrated some, but not all, uses of dbus_message_get_args() to the
new function. Some instances have uncommon semantics such as terminating
the connection upon failure to parse a message.