]> granicus.if.org Git - linux-pam/blob - modules/pam_rootok/pam_rootok.c
Relevant BUGIDs: 124923
[linux-pam] / modules / pam_rootok / pam_rootok.c
1 /* pam_rootok module */
2
3 /*
4  * $Id$
5  *
6  * Written by Andrew Morgan <morgan@linux.kernel.org> 1996/3/11
7  */
8
9 #define _GNU_SOURCE
10
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <syslog.h>
14 #include <stdarg.h>
15
16 /*
17  * here, we make a definition for the externally accessible function
18  * in this file (this definition is required for static a module
19  * but strongly encouraged generally) it is used to instruct the
20  * modules include file to define the function prototypes.
21  */
22
23 #define PAM_SM_AUTH
24
25 #include <security/pam_modules.h>
26
27 /* some syslogging */
28
29 static void _pam_log(int err, const char *format, ...)
30 {
31     va_list args;
32
33     va_start(args, format);
34     openlog("PAM-rootok", LOG_CONS|LOG_PID, LOG_AUTH);
35     vsyslog(err, format, args);
36     va_end(args);
37     closelog();
38 }
39
40
41 /* argument parsing */
42
43 #define PAM_DEBUG_ARG       01
44
45 static int _pam_parse(int argc, const char **argv)
46 {
47     int ctrl=0;
48
49     /* step through arguments */
50     for (ctrl=0; argc-- > 0; ++argv) {
51
52         /* generic options */
53
54         if (!strcmp(*argv,"debug"))
55             ctrl |= PAM_DEBUG_ARG;
56         else {
57             _pam_log(LOG_ERR,"pam_parse: unknown option; %s",*argv);
58         }
59     }
60
61     return ctrl;
62 }
63
64 /* --- authentication management functions (only) --- */
65
66 PAM_EXTERN
67 int pam_sm_authenticate(pam_handle_t *pamh,int flags,int argc
68                         ,const char **argv)
69 {
70     int ctrl;
71     int retval = PAM_AUTH_ERR;
72
73     ctrl = _pam_parse(argc, argv);
74     if (getuid() == 0)
75         retval = PAM_SUCCESS;
76
77     if (ctrl & PAM_DEBUG_ARG) {
78         _pam_log(LOG_DEBUG, "authetication %s"
79                  , retval==PAM_SUCCESS ? "succeeded":"failed" );
80     }
81
82     return retval;
83 }
84
85 PAM_EXTERN
86 int pam_sm_setcred(pam_handle_t *pamh,int flags,int argc
87                    ,const char **argv)
88 {
89     return PAM_SUCCESS;
90 }
91
92
93 #ifdef PAM_STATIC
94
95 /* static module data */
96
97 struct pam_module _pam_rootok_modstruct = {
98     "pam_rootok",
99     pam_sm_authenticate,
100     pam_sm_setcred,
101     NULL,
102     NULL,
103     NULL,
104     NULL,
105 };
106
107 #endif
108
109 /* end of module definition */