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