death to trailing whitespace
[openafs.git] / src / pam / afs_message.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <syslog.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <pwd.h>
14 #include <unistd.h>
15 #include <afsconfig.h>
16 #include <afs/param.h>
17
18
19 #include <security/pam_appl.h>
20 #include <security/pam_modules.h>
21
22
23 #include <sys/param.h>
24 #include <afs/kautils.h>
25 #include <stdarg.h>
26 #include "afs_message.h"
27 #include "afs_util.h"
28
29 static char *fallback_messages[] = {
30     "AFS Invalid message requested!",   /* 0: none              */
31     "AFS Unknown option: %s",   /* 1: UNKNOWNOPT        */
32     "AFS Username unavailable: code = %d",      /* 2: NOUSER            */
33     "AFS Username = `%s'",      /* 3: USERNAMEDEBUG     */
34     "AFS Password required but not supplied by user %s\n",
35     /* 4: PASSWD_REQ        */
36     "AFS Password: ",           /* 5: PWD_PROMPT        */
37     "AFS Cannot issue prompt",  /* 6: CANNOT_PROMPT     */
38     "AFS Trying first password for user %s",    /* 7: GOTPASS           */
39     "AFS No first password for user %s\n",      /* 8: NOFIRSTPASS       */
40     "AFS Couldn't get passwd via prompt",       /* 9: GETPASS_FAILED    */
41     "AFS not available",        /* 10: AFS_UNAVAIL      */
42     "AFS error code 0x%x",      /* 11: AFS_ERROR        */
43     "AFS Authentication succeeded.\n",  /* 12: LOGIN_OK         */
44     "AFS Authentication failed for user %s. %s\n",
45     /* 13: LOGIN_FAILED     */
46     "AFS PAM error, code=%d",   /* 14: PAMERROR         */
47     "AFS uid exceeds OS bounds.\n",     /* 15: UID_OVERFLOW     */
48     "The AFS PAM module may not be used from a non-MT program.\n",
49     /* 16: NON_MT_PROG      */
50     "AFS Options: nowarn=%d, use_first_pass=%d, try_first_pass=%d, ignore_uid = %d, ignore_uid_id = %d, refresh_token=%d, set_token=%d, dont_fork=%d, use_klog=%d",
51     /* 17: OPTIONS          */
52     "AFS No pam_conv conversation structure found; no user interaction",
53     /* 18: NO_USER_INT      */
54     "AFS Deleting creds for user %s\n", /* 19: DELCRED          */
55     "AFS Refreshing creds",     /* 20: REFRESHCRED      */
56     "AFS Won't use illegal password for user %s",
57     /* 21: NILPASSWORD      */
58     "AFS Establishing creds for user %s\n",     /* 22: ESTABCRED        */
59     "AFS credentials established.\n",   /* 23: PUT_CREDS        */
60     "AFS Couldn't find local cell name",        /* 24: NOCELLNAME       */
61     "AFS Foreign users are not valid for login.\n",
62     /* 25: XENOPHOBIA       */
63     "AFS Ignoring superuser %s",        /* 26: IGNORINGROOT     */
64     "AFS/local UIDs do not match",      /* 27: UID_MISMATCH     */
65     "AFS Rejected foreign user %s",     /* 28: REJ_FOREIGN      */
66     "AFS Deleting leftover creds from previous attempt",
67     /* 29: LEGACYCREDS      */
68     "You have no AFS credentials.\n",   /* 30: NO_CREDS         */
69     "AFS ReInitializing creds for user %s\n",   /* 31: REINITCRED       */
70     "AFS Failed to set PASSWORD_EXPIRES for user %s\n",
71     /* 32: PASSEXPFAIL      */
72     "AFS Failed to chown krb ticketfile\n",     /* 33: CHOWNKRB         */
73     "AFS Failed to set KRBTKTFILE\n",   /* 34: KRBFAIL          */
74     "AFS Unknown remaining lifetime %s using default %d seconds\n",
75     /* 35: REMAINLIFETIME   */
76     "AFS Session closed",       /* 36: SESSIONCLOSED1   */
77     "AFS Session closed, Tokens destroyed\n",   /* 37: SESSIONCLOSED2   */
78     "AFS Option conflict dont_fork and use_klog: %s\n",
79     /* 38: CONFLICTOPT      */
80     "AFS Unknown uid: %s, option ignored\n",
81     /* 39: IGNOREUID        */
82     "New AFS Password: ",       /* 40: NEW_PWD_PROMPT   */
83     "New AFS Password (again): ",       /* 41: VERIFY_PWD_PROMPT */
84     "Failed to change AFS password",    /* 42: KRBPASS_FAIL     */
85     "Missing PAM flag: %s",     /* 43: FLAGS            */
86     "ka error, code=%d",        /* 44: KAERROR          */
87     "Passwords are not equal",  /* 45: NE_PASSWORD      */
88     "AFS ignoring unregistered user %s\n"       /* 46: IGNORE_UNREG     */
89         "Alternate cell name: %s\n",    /* 47: OTHERCELL        */
90 };
91
92 static int num_fallbacks = sizeof(fallback_messages) / sizeof(char *);
93
94
95 char *
96 pam_afs_message(int msgnum, int *freeit)
97 {
98     /*
99      * This really should try to get an NLS message from the message catalog.
100      * For now, just return a fallback message.
101      */
102
103     if (msgnum > num_fallbacks || msgnum < 1)
104         msgnum = 0;
105
106     if (freeit != NULL)
107         *freeit = 0;
108     return fallback_messages[msgnum];
109 }
110
111
112 void
113 pam_afs_syslog(int priority, int msgid, ...)
114 {
115     char *msg = NULL;
116     int freeit;
117     va_list args;
118
119     msg = pam_afs_message(msgid, &freeit);
120     va_start(args, msgid);
121     vsyslog(priority, msg, args);
122     va_end(args);
123     if (freeit)
124         free(msg);
125 }