Merge from vendor branch BINUTILS:
[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  * $DragonFly: src/contrib/libpam/modules/pam_rootok/Attic/pam_rootok.c,v 1.2 2003/06/17 04:24:03 dillon Exp $
7  *
8  * Written by Andrew Morgan <morgan@linux.kernel.org> 1996/3/11
9  */
10
11 #define _GNU_SOURCE
12
13 #include <stdio.h>
14 #include <unistd.h>
15 #include <syslog.h>
16 #include <stdarg.h>
17
18 /*
19  * here, we make a definition for the externally accessible function
20  * in this file (this definition is required for static a module
21  * but strongly encouraged generally) it is used to instruct the
22  * modules include file to define the function prototypes.
23  */
24
25 #define PAM_SM_AUTH
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-rootok", LOG_CONS|LOG_PID, LOG_AUTH);
37     vsyslog(err, format, args);
38     va_end(args);
39     closelog();
40 }
41
42
43 /* argument parsing */
44
45 #define PAM_DEBUG_ARG       01
46
47 static int _pam_parse(int argc, const char **argv)
48 {
49     int ctrl=0;
50
51     /* step through arguments */
52     for (ctrl=0; argc-- > 0; ++argv) {
53
54         /* generic options */
55
56         if (!strcmp(*argv,"debug"))
57             ctrl |= PAM_DEBUG_ARG;
58         else {
59             _pam_log(LOG_ERR,"pam_parse: unknown option; %s",*argv);
60         }
61     }
62
63     return ctrl;
64 }
65
66 /* --- authentication management functions (only) --- */
67
68 PAM_EXTERN
69 int pam_sm_authenticate(pam_handle_t *pamh,int flags,int argc
70                         ,const char **argv)
71 {
72     int ctrl;
73     int retval = PAM_AUTH_ERR;
74
75     ctrl = _pam_parse(argc, argv);
76     if (getuid() == 0)
77         retval = PAM_SUCCESS;
78
79     if (ctrl & PAM_DEBUG_ARG) {
80         _pam_log(LOG_DEBUG, "authetication %s"
81                  , retval==PAM_SUCCESS ? "succeeded":"failed" );
82     }
83
84     return retval;
85 }
86
87 PAM_EXTERN
88 int pam_sm_setcred(pam_handle_t *pamh,int flags,int argc
89                    ,const char **argv)
90 {
91     return PAM_SUCCESS;
92 }
93
94
95 /* end of module definition */
96
97 PAM_MODULE_ENTRY("pam_rootok");