[SSSD] [PATCH] pam_client: fix casting to const pointer
Lukas Slebodnik
lslebodn at redhat.com
Wed Mar 25 16:20:35 UTC 2015
On (25/03/15 15:35), Sumit Bose wrote:
>On Wed, Mar 25, 2015 at 03:03:15PM +0100, Lukas Slebodnik wrote:
>> ehlo,
>>
>> clang complains about remoing cant qualifier in casting
>>
>> src/sss_client/pam_sss.c:1461:73:
>> error: cast from 'int **' to 'const void **' must have all
>> intermediate pointers const qualified to be safe [-Werror,-Wcast-qual]
>>
>> pam_get_data(pamh, "pam_sss:password_expired_flag", (const void **) &exp_data);
>>
>>
>> 'int **' should not be casted to 'const void **'
>> The const must not be removed
>>
>> There aren't warnings with following castings.
>> 'const int **' - 'const void **'
>> 'int **' - 'void **'
>>
>> BTW you can see the same kind warning with icc
>>
>> patch is attached.
>>
>> LS
>
>Changing the variables for last argument of pam_get_data() to const
>makes sense, but ...
>
>
>> @@ -1536,7 +1536,7 @@ static int pam_sss(enum sss_cli_command task, pam_handle_t *pamh,
>> int pam_status;
>> struct pam_items pi;
>> uint32_t flags = 0;
>> - int *exp_data;
>> + const int *exp_data;
>> bool retry = false;
>> bool quiet_mode = false;
>> int retries = 0;
>> @@ -1618,17 +1618,18 @@ static int pam_sss(enum sss_cli_command task, pam_handle_t *pamh,
>> /* We allow sssd to send the return code PAM_NEW_AUTHTOK_REQD during
>> * authentication, see sss_cli.h for details */
>> if (pam_status == PAM_NEW_AUTHTOK_REQD) {
>> + int *pw_exp_data;
>
>can you declare pw_exp_data at the beginning of pam_sss()?
I hoped this would be overlooked.
because the declaration is at the beggining of block and reduce
visibility of variable and there isn't warning with flag
"-Wdeclaration-after-statement"
but I can move it.
Updated version is attached.
LS
-------------- next part --------------
>From 5a45df842bf0ed1b2c2acda7bcda72695492ca09 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Wed, 19 Feb 2014 14:20:57 +0100
Subject: [PATCH] pam_client: fix casting to const pointer
src/sss_client/pam_sss.c:1461:73:
error: cast from 'int **' to 'const void **' must have all
intermediate pointers const qualified to be safe [-Werror,-Wcast-qual]
pam_get_data(pamh, "pam_sss:password_expired_flag", (const void **) &exp_data);
^
---
src/sss_client/pam_sss.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/sss_client/pam_sss.c b/src/sss_client/pam_sss.c
index 6105cac0eb640eef589de26c492059af6378af4d..6916575bb6d8288508ce1894d272356ffcc23f04 100644
--- a/src/sss_client/pam_sss.c
+++ b/src/sss_client/pam_sss.c
@@ -331,7 +331,7 @@ static int do_pam_conversation(pam_handle_t *pamh, const int msg_style,
{
int ret;
int state = SSS_PAM_CONV_STD;
- struct pam_conv *conv;
+ const struct pam_conv *conv;
const struct pam_message *mesg[1];
struct pam_message *pam_msg;
struct pam_response *resp=NULL;
@@ -1457,7 +1457,7 @@ static int get_authtok_for_password_change(pam_handle_t *pamh,
int pam_flags)
{
int ret;
- int *exp_data = NULL;
+ const int *exp_data = NULL;
pam_get_data(pamh, PWEXP_FLAG, (const void **) &exp_data);
/* we query for the old password during PAM_PRELIM_CHECK to make
@@ -1536,7 +1536,8 @@ static int pam_sss(enum sss_cli_command task, pam_handle_t *pamh,
int pam_status;
struct pam_items pi;
uint32_t flags = 0;
- int *exp_data;
+ const int *exp_data;
+ int *pw_exp_data;
bool retry = false;
bool quiet_mode = false;
int retries = 0;
@@ -1620,15 +1621,15 @@ static int pam_sss(enum sss_cli_command task, pam_handle_t *pamh,
if (pam_status == PAM_NEW_AUTHTOK_REQD) {
D(("Authtoken expired, trying to change it"));
- exp_data = malloc(sizeof(int));
- if (exp_data == NULL) {
+ pw_exp_data = malloc(sizeof(int));
+ if (pw_exp_data == NULL) {
D(("malloc failed."));
pam_status = PAM_BUF_ERR;
break;
}
- *exp_data = 1;
+ *pw_exp_data = 1;
- pam_status = pam_set_data(pamh, PWEXP_FLAG, exp_data,
+ pam_status = pam_set_data(pamh, PWEXP_FLAG, pw_exp_data,
free_exp_data);
if (pam_status != PAM_SUCCESS) {
D(("pam_set_data failed."));
--
2.3.3
More information about the sssd-devel
mailing list