src/pam warning fixes
authorMarc Dionne <marc.c.dionne@gmail.com>
Thu, 14 Jan 2010 23:56:49 +0000 (18:56 -0500)
committerDerrick Brashear <shadow|account-1000005@unknown>
Fri, 15 Jan 2010 04:46:30 +0000 (20:46 -0800)
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 <marc.c.dionne@gmail.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

acinclude.m4
src/cf/pam-const.m4 [new file with mode: 0644]
src/pam/afs_auth.c
src/pam/afs_pam_msg.c
src/pam/afs_setcred.c

index 45e1c3f..5750efe 100644 (file)
@@ -1498,6 +1498,8 @@ AC_CHECK_TYPE([sig_atomic_t], ,
 #include <signal.h>])
 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 (file)
index 0000000..4914b3d
--- /dev/null
@@ -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 <rra@debian.org>
+dnl Copyright 2007, 2008 Markus Moeller
+dnl
+dnl See LICENSE for licensing terms.
+AC_DEFUN([_HEADER_PAM_CONST_SOURCE],
+[
+#include <security/pam_appl.h>
+])
+
+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.])])
index 4807d66..af76201 100644 (file)
@@ -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) {
index 7f066bb..cb0d335 100644 (file)
@@ -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;
 
index 52e0310..dcafc91 100644 (file)
@@ -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) {