>From 437920c6188212b07ad93a3f7e378189a4aeb781 Mon Sep 17 00:00:00 2001
From: Stef Walter <stefw@redhat.com>
Date: Fri, 10 Jan 2014 08:08:58 +0100
Subject: [PATCH] util: Fix const cast failures when building with -Werror
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When building with -Werror 'make check' fails with many
errors like:

../src/tests/cmocka/test_authtok.c: In function ‘test_sss_authtok_password’:
../src/tests/cmocka/test_authtok.c:98:48: error: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Werror=cast-qual]

Make sss_authtok_set() @data argument const, and fix its documentation
---
 src/tests/cmocka/test_authtok.c | 12 ++++++------
 src/util/authtok.c              |  2 +-
 src/util/authtok.h              |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/tests/cmocka/test_authtok.c b/src/tests/cmocka/test_authtok.c
index 7a49793..c4e394c 100644
--- a/src/tests/cmocka/test_authtok.c
+++ b/src/tests/cmocka/test_authtok.c
@@ -95,7 +95,7 @@ static void test_sss_authtok_password(void **state)
 
     len = strlen(data) + 1;
     type = SSS_AUTHTOK_TYPE_PASSWORD;
-    ret = sss_authtok_set(ts->authtoken, type, (uint8_t *)data, len);
+    ret = sss_authtok_set(ts->authtoken, type, (const uint8_t *)data, len);
 
     assert_int_equal(ret, EOK);
     assert_int_equal(type, sss_authtok_get_type(ts->authtoken));
@@ -134,7 +134,7 @@ static void test_sss_authtok_ccfile(void **state)
 
     len = strlen(data) + 1;
     type = SSS_AUTHTOK_TYPE_CCFILE;
-    ret = sss_authtok_set(ts->authtoken, type, (uint8_t *)data, len);
+    ret = sss_authtok_set(ts->authtoken, type, (const uint8_t *)data, len);
 
     assert_int_equal(ret, EOK);
     assert_int_equal(type, sss_authtok_get_type(ts->authtoken));
@@ -158,7 +158,7 @@ static void test_sss_authtok_ccfile(void **state)
     assert_int_equal(len - 1, ret_len);
 
 
-    ret = sss_authtok_set(ts->authtoken, type, (uint8_t *) data, 0);
+    ret = sss_authtok_set(ts->authtoken, type, (const uint8_t *) data, 0);
 
     assert_int_equal(ret, EOK);
     assert_int_equal(type, sss_authtok_get_type(ts->authtoken));
@@ -236,7 +236,7 @@ static void test_sss_authtok_wipe_password(void **state)
 
     len = strlen(data) + 1;
     type = SSS_AUTHTOK_TYPE_PASSWORD;
-    ret = sss_authtok_set(ts->authtoken, type, (uint8_t *)data, len);
+    ret = sss_authtok_set(ts->authtoken, type, (const uint8_t *)data, len);
 
     assert_int_equal(ret, EOK);
 
@@ -268,14 +268,14 @@ static void test_sss_authtok_copy(void **state)
 
     len = strlen(data) + 1;
     type = SSS_AUTHTOK_TYPE_EMPTY;
-    ret = sss_authtok_set(ts->authtoken, type, (uint8_t *)data, len);
+    ret = sss_authtok_set(ts->authtoken, type, (const uint8_t *)data, len);
 
     assert_int_equal(ret, EOK);
     assert_int_equal(EOK, sss_authtok_copy(ts->authtoken, dest_authtoken));
     assert_int_equal(type, sss_authtok_get_type(dest_authtoken));
 
     type = SSS_AUTHTOK_TYPE_PASSWORD;
-    ret = sss_authtok_set(ts->authtoken, type, (uint8_t *)data, len);
+    ret = sss_authtok_set(ts->authtoken, type, (const uint8_t *)data, len);
 
     assert_int_equal(ret, EOK);
 
diff --git a/src/util/authtok.c b/src/util/authtok.c
index 73a4ccf..e9c2881 100644
--- a/src/util/authtok.c
+++ b/src/util/authtok.c
@@ -171,7 +171,7 @@ errno_t sss_authtok_set_ccfile(struct sss_auth_token *tok,
 
 errno_t sss_authtok_set(struct sss_auth_token *tok,
                         enum sss_authtok_type type,
-                        uint8_t *data, size_t len)
+                        const uint8_t *data, size_t len)
 {
     switch (type) {
     case SSS_AUTHTOK_TYPE_PASSWORD:
diff --git a/src/util/authtok.h b/src/util/authtok.h
index 8f327d4..1f6def4 100644
--- a/src/util/authtok.h
+++ b/src/util/authtok.h
@@ -131,7 +131,7 @@ void sss_authtok_set_empty(struct sss_auth_token *tok);
  * @param tok        A pointer to a sss_auth_token structure to change, also
  *                   used as a memory context to allocate the internal data.
  * @param type       A valid authtok type
- * @param ccfile     A data pointer
+ * @param data       A data pointer
  * @param len        The length of the data
  *
  * @return       EOK on success
@@ -139,7 +139,7 @@ void sss_authtok_set_empty(struct sss_auth_token *tok);
  */
 errno_t sss_authtok_set(struct sss_auth_token *tok,
                         enum sss_authtok_type type,
-                        uint8_t *data, size_t len);
+                        const uint8_t *data, size_t len);
 
 /**
  * @brief Copy an auth token from source to destination
-- 
1.8.4.2

