From 64c71d6fdd57527af607a61f32c7e1eb7f632386 Mon Sep 17 00:00:00 2001
From: Simo Sorce <simo@redhat.com>
Date: Mon, 18 Jan 2016 17:25:37 -0500
Subject: [PATCH] Headers: Fix subtle errors in header oredering

The config.h header MUST be incliuded first as it defines variables that change
the behavior of system libraries (for example _GNU_SOURCE). If config.h is not
included first then some files will have incorrect definitions.

While there try to fix as many redundant inclusions and ordering issues in the
responders. Uncovered by work on a patch that uses struct ucred

Resolves:
https://fedorahosted.org/sssd/ticket/2932
---
 src/providers/data_provider.h              | 12 +-----------
 src/responder/autofs/autofssrv.c           |  3 ---
 src/responder/autofs/autofssrv_cmd.c       |  3 ---
 src/responder/autofs/autofssrv_dp.c        |  5 -----
 src/responder/common/responder_cache_req.c |  7 ++-----
 src/responder/common/responder_cmd.c       |  3 +--
 src/responder/common/responder_dp.c        |  2 --
 src/responder/ifp/ifp_cache.c              |  5 +----
 src/responder/ifp/ifp_components.c         |  8 +-------
 src/responder/ifp/ifp_domains.c            |  7 +------
 src/responder/ifp/ifp_groups.c             |  3 ---
 src/responder/ifp/ifp_iface.c              |  2 +-
 src/responder/ifp/ifp_iface_nodes.c        |  1 +
 src/responder/ifp/ifp_users.c              |  6 +-----
 src/responder/ifp/ifpsrv.c                 | 13 +------------
 src/responder/ifp/ifpsrv_util.c            |  2 +-
 src/responder/nss/nsssrv.c                 | 14 +-------------
 src/responder/nss/nsssrv_services.c        |  2 --
 src/responder/pam/pam_LOCAL_domain.c       |  5 ++---
 src/responder/pam/pamsrv.c                 | 15 +--------------
 src/responder/pam/pamsrv_cmd.c             |  2 --
 src/responder/pam/pamsrv_dp.c              |  7 +------
 src/responder/pam/pamsrv_p11.c             |  3 ---
 src/responder/ssh/sshsrv.c                 |  3 ---
 src/responder/ssh/sshsrv_dp.c              |  5 -----
 src/responder/sudo/sudosrv.c               |  3 ---
 src/responder/sudo/sudosrv_cmd.c           |  4 ----
 src/responder/sudo/sudosrv_dp.c            |  5 -----
 src/responder/sudo/sudosrv_query.c         |  6 ------
 src/util/usertools.c                       |  7 +------
 src/util/util.h                            |  2 ++
 31 files changed, 20 insertions(+), 145 deletions(-)

diff --git a/src/providers/data_provider.h b/src/providers/data_provider.h
index 39051b90c3aad96f62dcbb86a20bcfd8c954879b..671ec198e38c9cacc6d96d14ad9c8b94312b4e79 100644
--- a/src/providers/data_provider.h
+++ b/src/providers/data_provider.h
@@ -22,23 +22,13 @@
 #ifndef __DATA_PROVIDER_H__
 #define __DATA_PROVIDER_H__
 
-#include "config.h"
-
-#include <stdint.h>
+#include "util/util.h"
 #include <sys/un.h>
-#include <errno.h>
 #include <stdbool.h>
 #ifdef USE_KEYRING
-#include <sys/types.h>
 #include <keyutils.h>
 #endif
-#include <talloc.h>
-#include <tevent.h>
-#include <ldb.h>
 #include <dbus/dbus.h>
-
-#include "util/util.h"
-#include "confdb/confdb.h"
 #include "sbus/sssd_dbus.h"
 #include "sbus/sbus_client.h"
 #include "sss_client/sss_cli.h"
diff --git a/src/responder/autofs/autofssrv.c b/src/responder/autofs/autofssrv.c
index ff30167298e0028da3f14f4d63a4d129c9c70bf0..65ab99ad8817a62fb3bdd9b77d5574289b615903 100644
--- a/src/responder/autofs/autofssrv.c
+++ b/src/responder/autofs/autofssrv.c
@@ -20,10 +20,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <popt.h>
-
 #include "util/util.h"
-#include "confdb/confdb.h"
 #include "monitor/monitor_interfaces.h"
 #include "responder/common/responder.h"
 #include "providers/data_provider.h"
diff --git a/src/responder/autofs/autofssrv_cmd.c b/src/responder/autofs/autofssrv_cmd.c
index 42754aceb0d6999995b7d4dd17b196a785a2550c..cd688d651b56f076a36bb9bb684e503ebfe46553 100644
--- a/src/responder/autofs/autofssrv_cmd.c
+++ b/src/responder/autofs/autofssrv_cmd.c
@@ -20,15 +20,12 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <talloc.h>
-
 #include "util/util.h"
 #include "responder/common/responder.h"
 #include "responder/common/responder_packet.h"
 #include "responder/autofs/autofs_private.h"
 #include "db/sysdb.h"
 #include "db/sysdb_autofs.h"
-#include "confdb/confdb.h"
 
 static int autofs_cmd_send_error(struct autofs_cmd_ctx *cmdctx, int err)
 {
diff --git a/src/responder/autofs/autofssrv_dp.c b/src/responder/autofs/autofssrv_dp.c
index 041f0629eafadb92fc6b8ec7190830a2662b40a0..6eb23a02285c86804b4842de49f2eea99c594fa4 100644
--- a/src/responder/autofs/autofssrv_dp.c
+++ b/src/responder/autofs/autofssrv_dp.c
@@ -18,11 +18,6 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <talloc.h>
-#include <tevent.h>
-#include <dbus/dbus.h>
-#include "sbus/sssd_dbus.h"
-
 #include "util/util.h"
 #include "sbus/sbus_client.h"
 #include "providers/data_provider.h"
diff --git a/src/responder/common/responder_cache_req.c b/src/responder/common/responder_cache_req.c
index 4ab52b8188859f1143ba1ffa3de03d14ecc028c2..4c960b6c193aa6efe6261c2dcb1e96885afd16bd 100644
--- a/src/responder/common/responder_cache_req.c
+++ b/src/responder/common/responder_cache_req.c
@@ -18,12 +18,9 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <dbus/dbus.h>
-#include <ldb.h>
-#include <talloc.h>
-#include <tevent.h>
-
 #include "util/util.h"
+#include <dbus/dbus.h>
+
 #include "db/sysdb.h"
 #include "responder/common/responder_cache_req.h"
 #include "providers/data_provider.h"
diff --git a/src/responder/common/responder_cmd.c b/src/responder/common/responder_cmd.c
index 1ac86fddffeb551bcd74af9fd9be60edc89a4f4c..0e5a3217bdf2a527156dc9deede3ec17d74dbfce 100644
--- a/src/responder/common/responder_cmd.c
+++ b/src/responder/common/responder_cmd.c
@@ -18,9 +18,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
-#include <errno.h>
-#include "db/sysdb.h"
 #include "util/util.h"
+#include "db/sysdb.h"
 #include "responder/common/responder.h"
 #include "responder/common/responder_packet.h"
 
diff --git a/src/responder/common/responder_dp.c b/src/responder/common/responder_dp.c
index d1c1609ca1700dab50b0db8958fda7923f1a22d1..e3254d8838dd4c187f13d8c471cb377d19a79941 100644
--- a/src/responder/common/responder_dp.c
+++ b/src/responder/common/responder_dp.c
@@ -20,8 +20,6 @@
 */
 
 
-#include <sys/time.h>
-#include <time.h>
 #include "util/util.h"
 #include "responder/common/responder_packet.h"
 #include "responder/common/responder.h"
diff --git a/src/responder/ifp/ifp_cache.c b/src/responder/ifp/ifp_cache.c
index 8ea2d8008d40bc0a28f3871b511690af677c5c5e..f263e6b0755c73bf7b34b093e918e027a8fd3e7a 100644
--- a/src/responder/ifp/ifp_cache.c
+++ b/src/responder/ifp/ifp_cache.c
@@ -18,11 +18,8 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <talloc.h>
-#include <tevent.h>
-
-#include "db/sysdb.h"
 #include "util/util.h"
+#include "db/sysdb.h"
 #include "responder/common/responder.h"
 #include "responder/ifp/ifp_cache.h"
 #include "responder/ifp/ifp_users.h"
diff --git a/src/responder/ifp/ifp_components.c b/src/responder/ifp/ifp_components.c
index b143d1e4fd99b55fa5d68f063957e54792992e9c..67c38994e823d7172d2a95973bed8c158a34635d 100644
--- a/src/responder/ifp/ifp_components.c
+++ b/src/responder/ifp/ifp_components.c
@@ -18,15 +18,9 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <string.h>
-#include <talloc.h>
+#include "util/util.h"
 #include <signal.h>
-#include <errno.h>
 #include <utime.h>
-
-#include "config.h"
-#include "confdb/confdb.h"
-#include "util/util.h"
 #include "responder/common/responder.h"
 #include "responder/ifp/ifp_components.h"
 
diff --git a/src/responder/ifp/ifp_domains.c b/src/responder/ifp/ifp_domains.c
index 5ad9952c9ad20c96c207a20700565788a6a9f3ea..6564b0dd756a330d5da4b1db16c8022ff6a9ffee 100644
--- a/src/responder/ifp/ifp_domains.c
+++ b/src/responder/ifp/ifp_domains.c
@@ -19,13 +19,8 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <talloc.h>
-#include <tevent.h>
-#include <string.h>
-
-#include "db/sysdb.h"
 #include "util/util.h"
-#include "confdb/confdb.h"
+#include "db/sysdb.h"
 #include "responder/common/responder.h"
 #include "responder/ifp/ifp_domains.h"
 
diff --git a/src/responder/ifp/ifp_groups.c b/src/responder/ifp/ifp_groups.c
index 08f34b7a3634d9eb3963c556c4da380dd4dd8d85..14504c201bd3d4beb68f2d29858173a221ec28a9 100644
--- a/src/responder/ifp/ifp_groups.c
+++ b/src/responder/ifp/ifp_groups.c
@@ -18,9 +18,6 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <talloc.h>
-#include <tevent.h>
-
 #include "util/util.h"
 #include "db/sysdb.h"
 #include "util/strtonum.h"
diff --git a/src/responder/ifp/ifp_iface.c b/src/responder/ifp/ifp_iface.c
index 86d8d338c3d18c22a8dc449b6520f65f8968e26b..c2bf6619ba534b6211921e68b6d35e3e2cfdd56c 100644
--- a/src/responder/ifp/ifp_iface.c
+++ b/src/responder/ifp/ifp_iface.c
@@ -18,8 +18,8 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include "config.h"
 #include <dbus/dbus.h>
-
 #include "sbus/sssd_dbus.h"
 #include "responder/ifp/ifp_iface_generated.h"
 #include "responder/ifp/ifp_domains.h"
diff --git a/src/responder/ifp/ifp_iface_nodes.c b/src/responder/ifp/ifp_iface_nodes.c
index ecb9ba32405b6a78904bcee70c02425c3bcc4cdd..12f6d54cef863b604e4bc1555157e8e81f184f8b 100644
--- a/src/responder/ifp/ifp_iface_nodes.c
+++ b/src/responder/ifp/ifp_iface_nodes.c
@@ -18,6 +18,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include "config.h"
 #include "sbus/sssd_dbus.h"
 #include "responder/ifp/ifp_iface_generated.h"
 #include "responder/ifp/ifp_users.h"
diff --git a/src/responder/ifp/ifp_users.c b/src/responder/ifp/ifp_users.c
index e542e811c7a5384ddcd2a4bc93c2280ead1c0574..c6076b9a860437db8415444fb389afcdb386a712 100644
--- a/src/responder/ifp/ifp_users.c
+++ b/src/responder/ifp/ifp_users.c
@@ -18,12 +18,8 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <talloc.h>
-#include <tevent.h>
-#include <string.h>
-
-#include "db/sysdb.h"
 #include "util/util.h"
+#include "db/sysdb.h"
 #include "util/strtonum.h"
 #include "util/cert.h"
 #include "sbus/sssd_dbus_errors.h"
diff --git a/src/responder/ifp/ifpsrv.c b/src/responder/ifp/ifpsrv.c
index 83e5ad3959aa75758402cb85b69bbc30fd4e5706..666751968b9e72a2c598ef5cd5ff2d65aa74a02c 100644
--- a/src/responder/ifp/ifpsrv.c
+++ b/src/responder/ifp/ifpsrv.c
@@ -20,20 +20,9 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+#include "util/util.h"
 #include <sys/socket.h>
 #include <sys/un.h>
-#include <string.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <popt.h>
-#include <dbus/dbus.h>
-
-#include "util/util.h"
 #include "util/strtonum.h"
 #include "sbus/sssd_dbus.h"
 #include "monitor/monitor_interfaces.h"
diff --git a/src/responder/ifp/ifpsrv_util.c b/src/responder/ifp/ifpsrv_util.c
index 904c4f62ec5653a534877fd6870832128720b694..7118f5a038139589d156a4ac8ca2a99a22248f57 100644
--- a/src/responder/ifp/ifpsrv_util.c
+++ b/src/responder/ifp/ifpsrv_util.c
@@ -21,8 +21,8 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include "util/util.h"
 #include <sys/param.h>
-
 #include "db/sysdb.h"
 #include "responder/ifp/ifp_private.h"
 
diff --git a/src/responder/nss/nsssrv.c b/src/responder/nss/nsssrv.c
index d8eff7968c4929663412aa56d08414689b921a22..9db75f81f79a07bfa35540d9fb67ee30308d42df 100644
--- a/src/responder/nss/nsssrv.c
+++ b/src/responder/nss/nsssrv.c
@@ -19,28 +19,16 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+#include "util/util.h"
 #include <sys/socket.h>
 #include <sys/un.h>
-#include <string.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <popt.h>
-#include <dbus/dbus.h>
 
-#include "util/util.h"
 #include "responder/nss/nsssrv.h"
 #include "responder/nss/nsssrv_private.h"
 #include "responder/nss/nsssrv_mmap_cache.h"
 #include "responder/nss/nsssrv_netgroup.h"
 #include "responder/common/negcache.h"
 #include "db/sysdb.h"
-#include "confdb/confdb.h"
-#include "sbus/sssd_dbus.h"
 #include "responder/common/responder_packet.h"
 #include "responder/common/responder.h"
 #include "responder/common/responder_sbus.h"
diff --git a/src/responder/nss/nsssrv_services.c b/src/responder/nss/nsssrv_services.c
index a9fdeb6c9dba7ac5480e2789fc0b8a37e1c2abe1..0d8db90deaf4a54d9f8344dabbda35bb0d8b53d6 100644
--- a/src/responder/nss/nsssrv_services.c
+++ b/src/responder/nss/nsssrv_services.c
@@ -21,13 +21,11 @@
 */
 
 
-#include <arpa/inet.h>
 #include "util/util.h"
 #include "responder/nss/nsssrv.h"
 #include "responder/nss/nsssrv_private.h"
 #include "responder/nss/nsssrv_services.h"
 #include "responder/common/negcache.h"
-#include "confdb/confdb.h"
 #include "db/sysdb.h"
 #include "db/sysdb_services.h"
 
diff --git a/src/responder/pam/pam_LOCAL_domain.c b/src/responder/pam/pam_LOCAL_domain.c
index 4b076146c4d38715b05d67bbe002b95ee54d03ec..f82a7772a4004dac332be24176c5110af5e485f1 100644
--- a/src/responder/pam/pam_LOCAL_domain.c
+++ b/src/responder/pam/pam_LOCAL_domain.c
@@ -19,10 +19,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <time.h>
-#include <security/pam_modules.h>
-
 #include "util/util.h"
+#include <security/pam_modules.h>
+
 #include "db/sysdb.h"
 #include "util/crypto/sss_crypto.h"
 #include "providers/data_provider.h"
diff --git a/src/responder/pam/pamsrv.c b/src/responder/pam/pamsrv.c
index a63b52ec173342b6089adb5d7131cdc2d8a526d2..22f333341bb38f96e9ca97eef871c8576bc89a73 100644
--- a/src/responder/pam/pamsrv.c
+++ b/src/responder/pam/pamsrv.c
@@ -20,23 +20,10 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+#include "util/util.h"
 #include <sys/socket.h>
 #include <sys/un.h>
-#include <string.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <popt.h>
-#include <dbus/dbus.h>
-
-#include "util/util.h"
 #include "db/sysdb.h"
-#include "confdb/confdb.h"
-#include "sbus/sssd_dbus.h"
 #include "responder/common/responder_packet.h"
 #include "providers/data_provider.h"
 #include "monitor/monitor_interfaces.h"
diff --git a/src/responder/pam/pamsrv_cmd.c b/src/responder/pam/pamsrv_cmd.c
index b9fd353259834910e85b05f8e5aa20c9c5674501..82afde6dc293729d1eaab3346fd1b9f9f01d3702 100644
--- a/src/responder/pam/pamsrv_cmd.c
+++ b/src/responder/pam/pamsrv_cmd.c
@@ -20,11 +20,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <time.h>
 #include "util/util.h"
 #include "util/auth_utils.h"
 #include "db/sysdb.h"
-#include "confdb/confdb.h"
 #include "responder/common/responder_packet.h"
 #include "responder/common/responder.h"
 #include "responder/common/negcache.h"
diff --git a/src/responder/pam/pamsrv_dp.c b/src/responder/pam/pamsrv_dp.c
index 826146350670d67f897ee7eec2cf6ca607b96435..2aed235f0f9a3c0487438f3cc7fb7cc8a0ab3e00 100644
--- a/src/responder/pam/pamsrv_dp.c
+++ b/src/responder/pam/pamsrv_dp.c
@@ -19,13 +19,8 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <sys/time.h>
-#include <time.h>
-
-#include <talloc.h>
-#include <security/pam_modules.h>
-
 #include "util/util.h"
+#include <security/pam_modules.h>
 #include "responder/common/responder_packet.h"
 #include "providers/data_provider.h"
 #include "sbus/sbus_client.h"
diff --git a/src/responder/pam/pamsrv_p11.c b/src/responder/pam/pamsrv_p11.c
index 58310a2530287fc6d08a7195c8e879f96dcc5403..855b2d0ce9cbfd5b4c679aede3f80d4729ab480b 100644
--- a/src/responder/pam/pamsrv_p11.c
+++ b/src/responder/pam/pamsrv_p11.c
@@ -19,9 +19,6 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <time.h>
-
-#include "util/util.h"
 #include "providers/data_provider.h"
 #include "util/child_common.h"
 #include "util/strtonum.h"
diff --git a/src/responder/ssh/sshsrv.c b/src/responder/ssh/sshsrv.c
index d4e202d87f520f1bdcd521733592027773a821d6..a585a97a0820c95db2bcd62bcb17cd75d7f03521 100644
--- a/src/responder/ssh/sshsrv.c
+++ b/src/responder/ssh/sshsrv.c
@@ -18,10 +18,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <popt.h>
-
 #include "util/util.h"
-#include "confdb/confdb.h"
 #include "monitor/monitor_interfaces.h"
 #include "responder/common/responder.h"
 #include "responder/common/responder_sbus.h"
diff --git a/src/responder/ssh/sshsrv_dp.c b/src/responder/ssh/sshsrv_dp.c
index 90b0b5754e695c4757287d8694e390daee17af5d..0eb688c51cf3d5bd026cd17ccd4d449e2262fae9 100644
--- a/src/responder/ssh/sshsrv_dp.c
+++ b/src/responder/ssh/sshsrv_dp.c
@@ -18,11 +18,6 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <talloc.h>
-#include <tevent.h>
-#include <dbus/dbus.h>
-#include "sbus/sssd_dbus.h"
-
 #include "util/util.h"
 #include "sbus/sbus_client.h"
 #include "providers/data_provider.h"
diff --git a/src/responder/sudo/sudosrv.c b/src/responder/sudo/sudosrv.c
index ff5d92e7005db9f6e883c78cf1a6218e9a150e0a..a8e7cbf13145eb5924d9d122e2a7a9db0062dea1 100644
--- a/src/responder/sudo/sudosrv.c
+++ b/src/responder/sudo/sudosrv.c
@@ -18,10 +18,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <popt.h>
-
 #include "util/util.h"
-#include "confdb/confdb.h"
 #include "monitor/monitor_interfaces.h"
 #include "responder/common/responder.h"
 #include "responder/common/responder_sbus.h"
diff --git a/src/responder/sudo/sudosrv_cmd.c b/src/responder/sudo/sudosrv_cmd.c
index dd636e949200dd49c1422a5789e9328dc4b25fb0..859b6a900d705cc4475960ca0af300b0624ecea9 100644
--- a/src/responder/sudo/sudosrv_cmd.c
+++ b/src/responder/sudo/sudosrv_cmd.c
@@ -18,10 +18,6 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <stdint.h>
-#include <errno.h>
-#include <talloc.h>
-
 #include "util/util.h"
 #include "responder/common/responder.h"
 #include "responder/common/responder_packet.h"
diff --git a/src/responder/sudo/sudosrv_dp.c b/src/responder/sudo/sudosrv_dp.c
index 95595fba2ad81e837de7222ece626d331299848c..7fb4fd8723dd7a909faa188bbf61b0cc5b9cbc84 100644
--- a/src/responder/sudo/sudosrv_dp.c
+++ b/src/responder/sudo/sudosrv_dp.c
@@ -19,11 +19,6 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <talloc.h>
-#include <tevent.h>
-#include <dbus/dbus.h>
-#include "sbus/sssd_dbus.h"
-
 #include "util/util.h"
 #include "sbus/sbus_client.h"
 #include "providers/data_provider.h"
diff --git a/src/responder/sudo/sudosrv_query.c b/src/responder/sudo/sudosrv_query.c
index 4cb07e32b3d7f2897dcd7f4941aa44bf8928d5c2..5f295d73ce5d525affee14cbd5a1f3ef92d2f248 100644
--- a/src/responder/sudo/sudosrv_query.c
+++ b/src/responder/sudo/sudosrv_query.c
@@ -18,12 +18,6 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <string.h>
-#include <stdint.h>
-#include <errno.h>
-#include <talloc.h>
-#include <tevent.h>
-
 #include "util/util.h"
 #include "responder/sudo/sudosrv_private.h"
 
diff --git a/src/util/usertools.c b/src/util/usertools.c
index 18639d9b6925f1ba17c77f97b1f7464215390020..ffec6ec12473f19cd6e8ac9a82ed822a8f0e4d6f 100644
--- a/src/util/usertools.c
+++ b/src/util/usertools.c
@@ -19,16 +19,11 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <pwd.h>
-#include <pcre.h>
-#include <errno.h>
-#include <talloc.h>
+#include "util/util.h"
 #include <pwd.h>
 #include <grp.h>
 
-#include "confdb/confdb.h"
 #include "util/strtonum.h"
-#include "util/util.h"
 #include "util/safe-format-string.h"
 #include "responder/common/responder.h"
 
diff --git a/src/util/util.h b/src/util/util.h
index e1245bb0fbab742dd58522f1892c66d08a45b59c..485a4a4c647858a77714c93a790851a7972d8385 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -35,11 +35,13 @@
 #include <limits.h>
 #include <locale.h>
 #include <time.h>
+#include <sys/time.h>
 #include <pcre.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
+#include <popt.h>
 
 #include <talloc.h>
 #include <tevent.h>
-- 
2.5.0

