Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / libpam / modules / pam_warn / pam_warn.c
1 /* pam_warn module */
2
3 /*
4  * $Id: pam_warn.c,v 1.1.1.1 2000/06/20 22:12:10 agmorgan Exp $
5  * $FreeBSD: src/contrib/libpam/modules/pam_warn/pam_warn.c,v 1.3.2.2 2001/06/11 15:28:34 markm Exp $
6  *
7  * Written by Andrew Morgan <morgan@linux.kernel.org> 1996/3/11
8  */
9
10 #define _BSD_SOURCE
11
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <syslog.h>
15 #include <stdarg.h>
16
17 /*
18  * here, we make a definition for the externally accessible function
19  * in this file (this definition is required for static a module
20  * but strongly encouraged generally) it is used to instruct the
21  * modules include file to define the function prototypes.
22  */
23
24 #define PAM_SM_AUTH
25 #define PAM_SM_PASSWORD
26
27 #include <security/pam_modules.h>
28
29 /* some syslogging */
30
31 static void _pam_log(int err, const char *format, ...)
32 {
33     va_list args;
34
35     va_start(args, format);
36     openlog("PAM-warn", LOG_CONS|LOG_PID, LOG_AUTH);
37     vsyslog(err, format, args);
38     va_end(args);
39     closelog();
40 }
41
42 /* --- authentication management functions (only) --- */
43
44 PAM_EXTERN
45 int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc
46                         , const char **argv)
47 {
48      const char *service=NULL, *user=NULL, *terminal=NULL
49          , *rhost=NULL, *ruser=NULL;
50
51      (void) pam_get_item(pamh, PAM_SERVICE, (const void **)&service);
52      (void) pam_get_item(pamh, PAM_TTY, (const void **)&terminal);
53      _pam_log(LOG_NOTICE, "service: %s [on terminal: %s]"
54               , service ? service : "<unknown>"
55               , terminal ? terminal : "<unknown>"
56          );
57      (void) pam_get_user(pamh, &user, "Who are you? ");
58      (void) pam_get_item(pamh, PAM_RUSER, (const void **)&ruser);
59      (void) pam_get_item(pamh, PAM_RHOST, (const void **)&rhost);
60      _pam_log(LOG_NOTICE, "user: (uid=%d) -> %s [remote: %s@%s]"
61               , getuid()
62               , user ? user : "<unknown>"
63               , ruser ? ruser : "?nobody"
64               , rhost ? rhost : "?nowhere"
65               );
66
67      /* we are just a fly on the wall */
68
69      return PAM_IGNORE;
70 }
71
72 PAM_EXTERN
73 int pam_sm_setcred(pam_handle_t *pamh,int flags,int argc
74                    , const char **argv)
75 {
76     return PAM_IGNORE;
77 }
78
79 /* password updating functions */
80
81 PAM_EXTERN
82 int pam_sm_chauthtok(pam_handle_t *pamh,int flags,int argc
83                    , const char **argv)
84 {
85     /* map to the authentication function... */
86
87     return pam_sm_authenticate(pamh, flags, argc, argv);
88 }
89
90 PAM_EXTERN int
91 pam_sm_acct_mgmt (pam_handle_t *pamh, int flags,
92                   int argc, const char **argv)
93 {
94     /* map to the authentication function... */
95
96     return pam_sm_authenticate(pamh, flags, argc, argv);
97 }
98
99 PAM_EXTERN int
100 pam_sm_open_session (pam_handle_t *pamh, int flags, int argc,
101                      const char **argv)
102 {
103     /* map to the authentication function... */
104
105     return pam_sm_authenticate(pamh, flags, argc, argv);
106 }
107
108 PAM_EXTERN int
109 pam_sm_close_session (pam_handle_t *pamh, int flags, int argc,
110                       const char **argv)
111 {
112     /* map to the authentication function... */
113
114     return pam_sm_authenticate(pamh, flags, argc, argv);
115 }
116
117 #ifdef PAM_STATIC
118
119 /* static module data */
120
121 struct pam_module _pam_warn_modstruct = {
122     "pam_warn",
123     pam_sm_authenticate,
124     pam_sm_setcred,
125     pam_sm_acct_mgmt,
126     pam_sm_open_session,
127     pam_sm_close_session,
128     pam_sm_chauthtok,
129 };
130
131 #endif
132
133 /* end of module definition */