xref: /freebsd/lib/libpam/modules/pam_rootok/pam_rootok.c (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
11642eb1aSMark Murray /*-
2*5e53a4f9SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*5e53a4f9SPedro F. Giffuni  *
41642eb1aSMark Murray  * Copyright (c) 2001 Mark R V Murray
51642eb1aSMark Murray  * All rights reserved.
6f03a4b81SDag-Erling Smørgrav  * Copyright (c) 2001 Networks Associates Technology, Inc.
78d3978c1SDag-Erling Smørgrav  * All rights reserved.
88d3978c1SDag-Erling Smørgrav  *
98d3978c1SDag-Erling Smørgrav  * Portions of this software were developed for the FreeBSD Project by
108d3978c1SDag-Erling Smørgrav  * ThinkSec AS and NAI Labs, the Security Research Division of Network
118d3978c1SDag-Erling Smørgrav  * Associates, Inc.  under DARPA/SPAWAR contract N66001-01-C-8035
128d3978c1SDag-Erling Smørgrav  * ("CBOSS"), as part of the DARPA CHATS research program.
131642eb1aSMark Murray  *
141642eb1aSMark Murray  * Redistribution and use in source and binary forms, with or without
151642eb1aSMark Murray  * modification, are permitted provided that the following conditions
161642eb1aSMark Murray  * are met:
171642eb1aSMark Murray  * 1. Redistributions of source code must retain the above copyright
181642eb1aSMark Murray  *    notice, this list of conditions and the following disclaimer.
191642eb1aSMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
201642eb1aSMark Murray  *    notice, this list of conditions and the following disclaimer in the
211642eb1aSMark Murray  *    documentation and/or other materials provided with the distribution.
228d3978c1SDag-Erling Smørgrav  * 3. The name of the author may not be used to endorse or promote
238d3978c1SDag-Erling Smørgrav  *    products derived from this software without specific prior written
248d3978c1SDag-Erling Smørgrav  *    permission.
251642eb1aSMark Murray  *
261642eb1aSMark Murray  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
271642eb1aSMark Murray  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281642eb1aSMark Murray  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291642eb1aSMark Murray  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
301642eb1aSMark Murray  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311642eb1aSMark Murray  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321642eb1aSMark Murray  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331642eb1aSMark Murray  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341642eb1aSMark Murray  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351642eb1aSMark Murray  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361642eb1aSMark Murray  * SUCH DAMAGE.
371642eb1aSMark Murray  */
381642eb1aSMark Murray 
39ceaf33f5SMatthew Dillon #include <sys/cdefs.h>
401642eb1aSMark Murray #define _BSD_SOURCE
411642eb1aSMark Murray 
421642eb1aSMark Murray #include <unistd.h>
431642eb1aSMark Murray #include <syslog.h>
441642eb1aSMark Murray 
451642eb1aSMark Murray #define PAM_SM_AUTH
461642eb1aSMark Murray 
478c66575dSDag-Erling Smørgrav #include <security/pam_appl.h>
481642eb1aSMark Murray #include <security/pam_modules.h>
498c66575dSDag-Erling Smørgrav #include <security/pam_mod_misc.h>
501642eb1aSMark Murray 
511642eb1aSMark Murray PAM_EXTERN int
pam_sm_authenticate(pam_handle_t * pamh,int flags __unused,int argc __unused,const char * argv[]__unused)5224fe7ba0SDag-Erling Smørgrav pam_sm_authenticate(pam_handle_t *pamh, int flags __unused,
5324fe7ba0SDag-Erling Smørgrav     int argc __unused, const char *argv[] __unused)
541642eb1aSMark Murray {
551642eb1aSMark Murray 
560fa107a3SMark Murray 	if (getuid() == 0)
5724fe7ba0SDag-Erling Smørgrav 		return (PAM_SUCCESS);
581642eb1aSMark Murray 
590fa107a3SMark Murray 	PAM_VERBOSE_ERROR("Refused; not superuser");
600fa107a3SMark Murray 	PAM_LOG("User is not superuser");
611642eb1aSMark Murray 
6224fe7ba0SDag-Erling Smørgrav 	return (PAM_AUTH_ERR);
631642eb1aSMark Murray }
641642eb1aSMark Murray 
651642eb1aSMark Murray PAM_EXTERN int
pam_sm_setcred(pam_handle_t * pamh __unused,int flags __unused,int argc __unused,const char * argv[]__unused)6624fe7ba0SDag-Erling Smørgrav pam_sm_setcred(pam_handle_t *pamh __unused, int flags __unused,
6724fe7ba0SDag-Erling Smørgrav     int argc __unused, const char *argv[] __unused)
681642eb1aSMark Murray {
690fa107a3SMark Murray 
7024fe7ba0SDag-Erling Smørgrav 	return (PAM_SUCCESS);
718d3978c1SDag-Erling Smørgrav }
728d3978c1SDag-Erling Smørgrav 
731642eb1aSMark Murray PAM_MODULE_ENTRY("pam_rootok");
74