Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / libpam / modules / pam_rootok / pam_rootok.c
1 /* pam_rootok module */
2
3 /*
4  * $Id: pam_rootok.c,v 1.1.1.1 2000/06/20 22:11:56 agmorgan Exp $
5  * $FreeBSD: src/contrib/libpam/modules/pam_rootok/pam_rootok.c,v 1.3.2.2 2001/06/11 15:28:25 markm Exp $
6  *
7  * Written by Andrew Morgan <morgan@linux.kernel.org> 1996/3/11
8  */
9
10 #define _GNU_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
26 #include <security/pam_modules.h>
27
28 /* some syslogging */
29
30 static void _pam_log(int err, const char *format, ...)
31 {
32     va_list args;
33
34     va_start(args, format);
35     openlog("PAM-rootok", LOG_CONS|LOG_PID, LOG_AUTH);
36     vsyslog(err, format, args);
37     va_end(args);
38     closelog();
39 }
40
41
42 /* argument parsing */
43
44 #define PAM_DEBUG_ARG       01
45
46 static int _pam_parse(int argc, const char **argv)
47 {
48     int ctrl=0;
49
50     /* step through arguments */
51     for (ctrl=0; argc-- > 0; ++argv) {
52
53         /* generic options */
54
55         if (!strcmp(*argv,"debug"))
56             ctrl |= PAM_DEBUG_ARG;
57         else {
58             _pam_log(LOG_ERR,"pam_parse: unknown option; %s",*argv);
59         }
60     }
61
62     return ctrl;
63 }
64
65 /* --- authentication management functions (only) --- */
66
67 PAM_EXTERN
68 int pam_sm_authenticate(pam_handle_t *pamh,int flags,int argc
69                         ,const char **argv)
70 {
71     int ctrl;
72     int retval = PAM_AUTH_ERR;
73
74     ctrl = _pam_parse(argc, argv);
75     if (getuid() == 0)
76         retval = PAM_SUCCESS;
77
78     if (ctrl & PAM_DEBUG_ARG) {
79         _pam_log(LOG_DEBUG, "authetication %s"
80                  , retval==PAM_SUCCESS ? "succeeded":"failed" );
81     }
82
83     return retval;
84 }
85
86 PAM_EXTERN
87 int pam_sm_setcred(pam_handle_t *pamh,int flags,int argc
88                    ,const char **argv)
89 {
90     return PAM_SUCCESS;
91 }
92
93
94 /* end of module definition */
95
96 PAM_MODULE_ENTRY("pam_rootok");