Initial IBM OpenAFS 1.0 tree
[openafs.git] / src / pam / afs_message.c
1 #include <security/pam_appl.h>
2 #include <security/pam_modules.h>
3 #include <syslog.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <pwd.h>
7 #include <unistd.h>
8 #include <afs/param.h>
9 #include <sys/param.h>
10 #include <afs/kautils.h>
11 #include <stdarg.h>
12 #include "afs_message.h"
13 #include "afs_util.h"
14
15 static char *fallback_messages[] = {
16     "AFS Invalid message requested!",           /* 0: none              */
17     "AFS Unknown option: %s",                   /* 1: UNKNOWNOPT        */
18     "AFS Username unavailable: code = %d",      /* 2: NOUSER            */
19     "AFS Username = `%s'",                      /* 3: USERNAMEDEBUG     */
20     "AFS Password required but not supplied by user %s\n",      
21                                                 /* 4: PASSWD_REQ        */
22     "AFS Password: ",                           /* 5: PWD_PROMPT        */
23     "AFS Cannot issue prompt",                  /* 6: CANNOT_PROMPT     */
24     "AFS Trying first password for user %s",    /* 7: GOTPASS           */
25     "AFS No first password for user %s\n",      /* 8: NOFIRSTPASS       */
26     "AFS Couldn't get passwd via prompt",       /* 9: GETPASS_FAILED    */
27     "AFS not available",                        /* 10: AFS_UNAVAIL      */
28     "AFS error code 0x%x",                      /* 11: AFS_ERROR        */
29     "AFS Authentication succeeded.\n",          /* 12: LOGIN_OK         */
30     "AFS Authentication failed for user %s. %s\n",
31                                                 /* 13: LOGIN_FAILED     */
32     "AFS PAM error, code=%d",                   /* 14: PAMERROR         */
33     "AFS uid exceeds OS bounds.\n",             /* 15: UID_OVERFLOW     */
34     "The AFS PAM module may not be used from a non-MT program.\n",
35                                                 /* 16: NON_MT_PROG      */
36     "AFS Options: nowarn=%d, use_first_pass=%d, try_first_pass=%d",
37                                                 /* 17: OPTIONS          */
38     "AFS No pam_conv conversation structure found; no user interaction",
39                                                 /* 18: NO_USER_INT      */
40     "AFS Deleting creds for user %s\n",         /* 19: DELCRED          */
41     "AFS Refreshing creds",                     /* 20: REFRESHCRED      */
42     "AFS Won't use illegal password for user %s",
43                                                 /* 21: NILPASSWORD      */
44     "AFS Establishing creds for user %s\n",     /* 22: ESTABCRED        */
45     "AFS credentials established.\n",           /* 23: PUT_CREDS        */
46     "AFS Couldn't find local cell name",        /* 24: NOCELLNAME       */
47     "AFS Foreign users are not valid for login.\n",
48                                                 /* 25: XENOPHOBIA       */
49     "AFS Ignoring superuser %s",                /* 26: IGNORINGROOT     */
50     "AFS/local UIDs do not match",              /* 27: UID_MISMATCH     */
51     "AFS Rejected foreign user %s",             /* 28: REJ_FOREIGN      */
52     "AFS Deleting leftover creds from previous attempt",
53                                                 /* 29: LEGACYCREDS      */
54     "You have no AFS credentials.\n",           /* 30: NO_CREDS         */
55     "AFS ReInitializing creds for user %s\n",   /* 31: REINITCRED       */
56     "AFS Failed to set PASSWORD_EXPIRES for user %s\n",
57                                                 /* 32: PASSEXPFAIL      */
58 };
59
60 static int num_fallbacks = sizeof(fallback_messages)/sizeof(char *);
61
62
63 char *pam_afs_message(int msgnum, int *freeit)
64 {
65     /*
66      * This really should try to get an NLS message from the message catalog.
67      * For now, just return a fallback message.
68      */
69
70     if (msgnum > num_fallbacks || msgnum < 1) msgnum = 0;
71
72     if (freeit != NULL) *freeit = 0;
73     return fallback_messages[msgnum];
74 }
75
76
77 void pam_afs_syslog(int priority, int msgid, ...)
78 {
79     char *msg = NULL;
80     int freeit;
81     va_list args;
82
83     msg = pam_afs_message(msgid, &freeit);
84     va_start(args, msgid);
85     vsyslog(priority, msg, args);
86     va_end(args);
87     if (freeit) free(msg);
88 }