From d4c97c0017be80c798206767c750e0855ee6c015 Mon Sep 17 00:00:00 2001 From: Marc Dionne Date: Thu, 14 Jan 2010 18:56:49 -0500 Subject: [PATCH] src/pam warning fixes The second parameter to pam_conv() should be a const pointer on recent systems. Make it so to eliminate a couple of warnings. A configure test is added to deal with some systems where pam_conv() might not be const. Cast a few assignments to cell_ptr in afs_auth.c and afs_setcred.c since the argv parameter is const. Change-Id: I5757310c94a6f26ca7dab656edaa416d16e32e2a Reviewed-on: http://gerrit.openafs.org/847 Tested-by: Marc Dionne Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- acinclude.m4 | 2 ++ src/cf/pam-const.m4 | 29 +++++++++++++++++++++++++++++ src/pam/afs_auth.c | 2 +- src/pam/afs_pam_msg.c | 4 ++-- src/pam/afs_setcred.c | 2 +- 5 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 src/cf/pam-const.m4 diff --git a/acinclude.m4 b/acinclude.m4 index 45e1c3f3a..5750efeb3 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1498,6 +1498,8 @@ AC_CHECK_TYPE([sig_atomic_t], , #include ]) AC_SIZEOF_TYPE(long) +AC_HEADER_PAM_CONST + AC_CHECK_FUNCS(timegm) AC_CHECK_FUNCS(daemon) diff --git a/src/cf/pam-const.m4 b/src/cf/pam-const.m4 new file mode 100644 index 000000000..4914b3d21 --- /dev/null +++ b/src/cf/pam-const.m4 @@ -0,0 +1,29 @@ +dnl pam-const.m4 -- Determine whether PAM uses const in prototypes. +dnl +dnl Linux marks several PAM arguments const, including the argument to +dnl pam_get_item and some arguments to conversation functions, which Solaris +dnl doesn't. This test tries to determine which style is in use to select +dnl whether to declare variables const in order to avoid compiler warnings. +dnl +dnl Since this is just for compiler warnings, it's not horribly important if +dnl we guess wrong. This test is ugly, but it seems to work. +dnl +dnl Contributed by Markus Moeller. +dnl +dnl Copyright 2007 Russ Allbery +dnl Copyright 2007, 2008 Markus Moeller +dnl +dnl See LICENSE for licensing terms. +AC_DEFUN([_HEADER_PAM_CONST_SOURCE], +[ +#include +]) + +AC_DEFUN([AC_HEADER_PAM_CONST], +[AC_CACHE_CHECK([whether PAM prefers const], [ac_cv_header_pam_const], +[AC_EGREP_CPP([const void \*\* *item], _HEADER_PAM_CONST_SOURCE(), + [ac_cv_header_pam_const=yes], [ac_cv_header_pam_const=no])]) +AS_IF([test x"$ac_cv_header_pam_const" = xyes], + [ac_header_pam_const=const], [ac_header_pam_const=]) +AC_DEFINE_UNQUOTED([PAM_CONST], [$ac_header_pam_const], + [Define to const if PAM uses const in pam_get_item, empty otherwise.])]) diff --git a/src/pam/afs_auth.c b/src/pam/afs_auth.c index 4807d6654..af76201fe 100644 --- a/src/pam/afs_auth.c +++ b/src/pam/afs_auth.c @@ -114,7 +114,7 @@ pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, pam_afs_syslog(LOG_ERR, PAMAFS_OTHERCELL, "cell missing argument"); } else { - cell_ptr = argv[i]; + cell_ptr = (char *)argv[i]; pam_afs_syslog(LOG_INFO, PAMAFS_OTHERCELL, cell_ptr); } } else if (strcasecmp(argv[i], "refresh_token") == 0) { diff --git a/src/pam/afs_pam_msg.c b/src/pam/afs_pam_msg.c index 7f066bb72..cb0d335ff 100644 --- a/src/pam/afs_pam_msg.c +++ b/src/pam/afs_pam_msg.c @@ -28,7 +28,7 @@ pam_afs_printf(struct pam_conv *pam_convp, int error, int fmt_msgid, ...) char *fmt_msg = NULL; int freeit; struct pam_message mesg; - struct pam_message *mesgp = &mesg; + PAM_CONST struct pam_message *mesgp = &mesg; struct pam_response *resp = NULL; int errcode; @@ -63,7 +63,7 @@ pam_afs_prompt(struct pam_conv *pam_convp, char **response, int echo, char *fmt_msg = NULL; int freeit; struct pam_message mesg; - struct pam_message *mesgp = &mesg; + PAM_CONST struct pam_message *mesgp = &mesg; struct pam_response *resp = NULL; int errcode; diff --git a/src/pam/afs_setcred.c b/src/pam/afs_setcred.c index 52e031052..dcafc9148 100644 --- a/src/pam/afs_setcred.c +++ b/src/pam/afs_setcred.c @@ -106,7 +106,7 @@ pam_sm_setcred(pam_handle_t * pamh, int flags, int argc, const char **argv) pam_afs_syslog(LOG_ERR, PAMAFS_OTHERCELL, "cell missing argument"); } else { - cell_ptr = argv[i]; + cell_ptr = (char *)argv[i]; pam_afs_syslog(LOG_INFO, PAMAFS_OTHERCELL, cell_ptr); } } else if (strcasecmp(argv[i], "no_unlog") == 0) { -- 2.39.5