pam: avoid warning messages
[openafs.git] / src / pam / test_pam.c
index 39d35cb..1133c25 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
-#include <stdio.h>
 #include <security/pam_appl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
 
-
-static int my_conv(int num_msg, struct pam_message **msg,
+static int my_conv(int num_msg, PAM_CONST struct pam_message **msg,
                   struct pam_response **response, void *appdata_ptr);
 
 
@@ -34,12 +28,12 @@ static const char *service = "afstest";
 static const char *new_envstring = "GOTHEREVIATESTPAM=1";
 static const char *new_homestring = "HOME=/tmp";
 
-#if defined(AFS_LINUX20_ENV) || defined(AFS_FBSD_ENV) || defined(AFS_NBSD_ENV)
+#if defined(AFS_LINUX20_ENV) || defined(AFS_FBSD_ENV) || defined(AFS_DFBSD_ENV) || defined(AFS_NBSD_ENV) || defined(AFS_DARWIN_ENV)
 #define getpassphrase getpass
 #endif
 
 
-void
+int
 main(int argc, char *argv[])
 {
     int authenticated = 0;
@@ -99,19 +93,24 @@ main(int argc, char *argv[])
     }
     pam_end(pamh, PAM_SUCCESS);
 
-    putenv(new_envstring);
-    putenv(new_homestring);
-    chdir("/tmp");
+    putenv((char *)new_envstring);
+    putenv((char *)new_homestring);
+
+    if ((retcode = chdir("/tmp")) != 0) {
+       fprintf(stderr, "chdir returned %d.\n", retcode);
+       exit(1);
+    }
+
     printf("Type exit to back out.\n");
-    execl("/bin/csh", "/bin/csh", NULL);
+    return execl("/bin/csh", "/bin/csh", NULL);
 }
 
 
 static int
-my_conv(int num_msg, struct pam_message **msg, struct pam_response **response,
+my_conv(int num_msg, PAM_CONST struct pam_message **msg, struct pam_response **response,
        void *appdata_ptr)
 {
-    struct pam_message *m;
+    PAM_CONST struct pam_message *m;
     struct pam_response *r;
     char *p;
 
@@ -141,7 +140,10 @@ my_conv(int num_msg, struct pam_message **msg, struct pam_response **response,
            fputs(m->msg, stdout);
            if (r) {
                r->resp = malloc(PAM_MAX_RESP_SIZE);
-               fgets(r->resp, PAM_MAX_RESP_SIZE, stdin);
+               if (fgets(r->resp, PAM_MAX_RESP_SIZE, stdin) == NULL) {
+                   fprintf(stderr, "fgets did not work as expected\n");
+                   exit(1);
+               }
                r->resp[PAM_MAX_RESP_SIZE - 1] = '\0';
                p = &r->resp[strlen(r->resp) - 1];
                while (*p == '\n' && p >= r->resp)