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