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