>From c332fd783dd143ccae0746e3b42929160fe48090 Mon Sep 17 00:00:00 2001
From: Stef Walter <stefw@redhat.com>
Date: Mon, 24 Feb 2014 09:58:15 +0100
Subject: [PATCH 1/6] 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.
---
 src/providers/data_provider_be.c |  6 ++++--
 src/providers/dp_auth_util.c     | 33 +++++++++++++++++++++++----------
 2 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index 5519237..5207d19 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -618,7 +618,7 @@ static int be_get_subdomains(DBusMessage *message, struct sbus_connection *conn)
     DBusError dbus_error;
     dbus_bool_t dbret;
     void *user_data;
-    bool force;
+    dbus_bool_t force;
     char *domain_hint;
     dbus_uint16_t err_maj;
     dbus_uint32_t err_min;
@@ -841,6 +841,7 @@ static void acctinfo_initgroups_callback(struct be_req *be_req,
                                                   struct be_initgr_prereq);
     DBusMessage *msg = NULL;
     dbus_bool_t dbret;
+    int num;
     int ret;
 
     pr->orig_dp_err_type = dp_err_type;
@@ -864,11 +865,12 @@ static void acctinfo_initgroups_callback(struct be_req *be_req,
         goto done;
     }
 
+    num = pr->gnum;
     dbret = dbus_message_append_args(msg,
                                      DBUS_TYPE_STRING, &pr->user,
                                      DBUS_TYPE_STRING, &pr->domain,
                                      DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32,
-                                     &pr->groups, pr->gnum,
+                                     &pr->groups, num,
                                      DBUS_TYPE_INVALID);
     if (!dbret) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
diff --git a/src/providers/dp_auth_util.c b/src/providers/dp_auth_util.c
index 391d55c..f8a30c5 100644
--- a/src/providers/dp_auth_util.c
+++ b/src/providers/dp_auth_util.c
@@ -29,11 +29,13 @@ bool dp_pack_pam_request(DBusMessage *msg, struct pam_data *pd)
     const char *ruser;
     const char *rhost;
     uint32_t authtok_type;
-    uint32_t authtok_length;
+    int authtok_length;
     uint8_t *authtok_data;
     uint32_t new_authtok_type;
-    uint32_t new_authtok_length;
+    int new_authtok_length;
     uint8_t *new_authtok_data;
+    int32_t pd_priv;
+    int32_t pd_cmd;
 
     if (pd->user == NULL) return false;
     service = pd->service ? pd->service : "";
@@ -46,9 +48,11 @@ bool dp_pack_pam_request(DBusMessage *msg, struct pam_data *pd)
     new_authtok_type = (uint32_t)sss_authtok_get_type(pd->newauthtok);
     new_authtok_data = sss_authtok_get_data(pd->newauthtok);
     new_authtok_length = sss_authtok_get_size(pd->newauthtok);
+    pd_priv = pd->priv;
+    pd_cmd = pd->cmd;
 
     db_ret = dbus_message_append_args(msg,
-                                      DBUS_TYPE_INT32,  &(pd->cmd),
+                                      DBUS_TYPE_INT32,  &pd_cmd,
                                       DBUS_TYPE_STRING, &(pd->user),
                                       DBUS_TYPE_STRING, &(pd->domain),
                                       DBUS_TYPE_STRING, &service,
@@ -61,7 +65,7 @@ bool dp_pack_pam_request(DBusMessage *msg, struct pam_data *pd)
                                       DBUS_TYPE_UINT32, &new_authtok_type,
                                       DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
                                       &new_authtok_data, new_authtok_length,
-                                      DBUS_TYPE_INT32, &(pd->priv),
+                                      DBUS_TYPE_INT32, &pd_priv,
                                       DBUS_TYPE_UINT32, &(pd->cli_pid),
                                       DBUS_TYPE_INVALID);
 
@@ -75,16 +79,18 @@ bool dp_unpack_pam_request(DBusMessage *msg, TALLOC_CTX *mem_ctx,
     int ret;
     struct pam_data pd;
     uint32_t authtok_type;
-    uint32_t authtok_length;
+    int authtok_length;
     uint8_t *authtok_data;
     uint32_t new_authtok_type;
-    uint32_t new_authtok_length;
+    int new_authtok_length;
     uint8_t *new_authtok_data;
+    int32_t pd_cmd;
+    int32_t pd_priv;
 
     memset(&pd, 0, sizeof(pd));
 
     db_ret = dbus_message_get_args(msg, dbus_error,
-                                   DBUS_TYPE_INT32,  &(pd.cmd),
+                                   DBUS_TYPE_INT32,  &pd_cmd,
                                    DBUS_TYPE_STRING, &(pd.user),
                                    DBUS_TYPE_STRING, &(pd.domain),
                                    DBUS_TYPE_STRING, &(pd.service),
@@ -97,7 +103,7 @@ bool dp_unpack_pam_request(DBusMessage *msg, TALLOC_CTX *mem_ctx,
                                    DBUS_TYPE_UINT32, &new_authtok_type,
                                    DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
                                    &new_authtok_data, &new_authtok_length,
-                                   DBUS_TYPE_INT32, &(pd.priv),
+                                   DBUS_TYPE_INT32, &pd_priv,
                                    DBUS_TYPE_UINT32, &(pd.cli_pid),
                                    DBUS_TYPE_INVALID);
 
@@ -106,6 +112,9 @@ bool dp_unpack_pam_request(DBusMessage *msg, TALLOC_CTX *mem_ctx,
         return false;
     }
 
+    pd.cmd = pd_cmd;
+    pd.priv = pd_priv;
+
     ret = copy_pam_data(mem_ctx, &pd, new_pd);
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE, "copy_pam_data failed.\n");
@@ -138,12 +147,15 @@ bool dp_pack_pam_response(DBusMessage *msg, struct pam_data *pd)
     DBusMessageIter array_iter;
     DBusMessageIter struct_iter;
     DBusMessageIter data_iter;
+    uint32_t pam_status;
+    uint32_t resp_type;
 
     dbus_message_iter_init_append(msg, &iter);
 
     /* Append the PAM status */
+    pam_status = pd->pam_status;
     dbret = dbus_message_iter_append_basic(&iter,
-                                   DBUS_TYPE_UINT32, &(pd->pam_status));
+                                   DBUS_TYPE_UINT32, &pam_status);
     if (!dbret) {
         return false;
     }
@@ -167,9 +179,10 @@ bool dp_pack_pam_response(DBusMessage *msg, struct pam_data *pd)
         }
 
         /* Add the response type */
+        resp_type = resp->type;
         dbret = dbus_message_iter_append_basic(&struct_iter,
                                                DBUS_TYPE_UINT32,
-                                               &(resp->type));
+                                               &resp_type);
         if (!dbret) {
             return false;
         }
-- 
1.8.5.3

