./Makefile0100644000076400007640000000232010005762125012233 0ustar evseevevseev# # Makefile for building Linux port of BSD's pam_alreadyloggedin module. # # Written by Ilya Evseev using template from pam_mktemp package # by Solar Designer and Dmitry Levin. # CC = gcc LD = ld RM = rm -f MKDIR = mkdir -p INSTALL = install #CFLAGS = -c -Wall -O2 -fPIC -I. CFLAGS = -c $(RPM_OPT_FLAGS) -fPIC -DLINUX_PAM -I. -Wall -DBUG_STAT_MISSING LDFLAGS = -s -lpam --shared TITLE = pam_alreadyloggedin LIBSHARED = $(TITLE).so SHLIBMODE = 700 SECUREDIR = /lib/security FAKEROOT = CONFMODE = 600 CONFDIR = /etc/pam.d MANMODE = 444 ifndef MAN8DIR MAN8DIR = /usr/share/man/man8 endif OBJS = $(TITLE).o all: $(LIBSHARED) $(LIBSHARED): $(OBJS) $(LD) $(LDFLAGS) $(OBJS) -o $@ $(TITLE).o: $(TITLE).c $(CC) $(CFLAGS) $< install: $(MKDIR) $(FAKEROOT)$(SECUREDIR) $(INSTALL) -m $(SHLIBMODE) $(LIBSHARED) $(FAKEROOT)$(SECUREDIR) $(MKDIR) $(FAKEROOT)$(CONFDIR) $(INSTALL) -m $(CONFMODE) login.sso $(FAKEROOT)$(CONFDIR) $(MKDIR) $(FAKEROOT)$(MAN8DIR) $(INSTALL) -m $(MANMODE) $(TITLE).8 $(FAKEROOT)$(MAN8DIR) uninstall: remove remove: $(RM) $(FAKEROOT)$(SECUREDIR)/$(TITLE).so $(RM) $(FAKEROOT)$(CONFDIR)/login.sso $(RM) $(FAKEROOT)$(MAN8DIR)/$(TITLE).8 clean: $(RM) $(LIBSHARED) *.o *.s *.i ## EOF ## ./pam_alreadyloggedin.80100644000076400007640000001125210006353014014651 0ustar evseevevseev.\" Adopted for Linux by Ilya Evseev at Jan 2004. .\" .\" Copyright (c) 2002 Brian Fundakowski Feldman .\" All rights reserved. .\" Copyright (c) 2002 Networks Associates Technologies, Inc. .\" All rights reserved. .\" .\" Portions of this software were developed for the FreeBSD Project by .\" ThinkSec AS and NAI Labs, the Security Research Division of Network .\" Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 .\" ("CBOSS"), as part of the DARPA CHATS research program. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. The name of the author may not be used to endorse or promote .\" products derived from this software without specific prior written .\" permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $ Id: pam_alreadyloggedin.8,v 1.2 2002/03/07 16:54:40 green Exp $ .\" .Dd January 30, 2004 .Dt PAM_ALREADYLOGGEDIN 8 .Os Linux-PAM .Sh NAME .Nm pam_alreadyloggedin .Nd Already-logged-in PAM module .Sh SYNOPSIS .Op Ar service-name .Ar module-type .Ar control-flag .Pa pam_alreadyloggedin .Op Ar options .Sh DESCRIPTION The Already-logged-in authentication service module for PAM, .Nm provides functionality for only one PAM category: authentication. In terms of the .Ar module-type parameter, this is the .Dq Li auth feature. It also provides null functions for other PAM categories. .Ss Already-logged-in Authentication Module The Already-logged-in authentication component .Pq Fn pam_sm_authenticate , returns success if and only if the target user's ID is identical to a current login specified in the .Xr utmp 5 database and verified with matching permissions on that login's respective terminal in .Pa /dev . If a user shows up in .Xr w 8 output, they will generally be allowed to authenticate using this method. .Pp The following options may be passed to the authentication module: .Bl -tag -width ".Cm restrict_loggedin_tty Ns = Ns Ar ttyfoo*" .It Cm debug Enable verbose output to syslog at LOG_DEBUG level. .It Cm no_debug Disable verbose output to syslog even it's enabled at compile time. .It Cm no_root Never allow login with a target user ID of zero. .It Cm restrict_tty Ns = Ns Ar ttyglob* Only allow login if the terminal device currently being authenticated on matches .Ar ttyglob* . The .Ar ttyglob* argument is specified as a shell glob, and checked using the .Xr fnmatch 3 function. For example, .Cm restryct_tty=/dev/tty[1-6] allows logging from text consoles of physical terminal only. .It Cm restrict_loggedin_tty Ns = Ns Ar ttyfoo* Disallow recognition that the user is already logged in unless the terminal device logged in upon matches .Ar ttyglob* . .El .Sh EXAMPLE Modify .Cd auth section of the .Pa /etc/pam.d/login file like following: .Lp .Bd -unfilled -offset indent auth required /lib/security/pam_securetty.so auth sufficient /lib/security/pam_alreadyloggedin.so no_root auth required /lib/security/pam_stack.so service=system-auth .Ed .Sh BUGS FreeBSD version expects .Pa /dev/ prefix in .Cm restryct_tty value, but value of .Cm restryct_loggedin_tty should be without them. Linux version expects .Pa /dev/ in both cases. .Sh SEE ALSO .Xr fnmatch 3 , .Xr getuid 2 , .Xr stat 2 , .Xr utmp 5 , .Xr w 8 , .Xr pam.conf 5 , .Xr pam 8 .Sh AUTHORS Adopted for Linux PAM by Ilya Evseev at Jan 2004. .Lp The original .Nm module and this manual page were developed for the FreeBSD Project by NAI Labs and ThinkSec AS, the Security Research Division of Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 .Pq Dq CBOSS , as part of the DARPA CHATS research program. ./pam_alreadyloggedin.c0100644000076400007640000001766210152207753014751 0ustar evseevevseev/* * pam_alreadyloggedin.c * * Rewritten for Linux at Jan 2004 by Ilya Evseev * Version 0.3 with tiny patch from lbenini@csr.unibo.it at Dec 2004. * * Here is banner of original pam_alreadyloggedin module * taken from FreeBSD project source tree: *________________________________________________________ * * Copyright (c) 2002 Brian Fundakowski Feldman * Copyright (c) 2002 Networks Associates Technologies, Inc. * All rights reserved. * * This software was developed by Robert Watson and Ilmar Habibulin for the * TrustedBSD Project. * * This software was developed for the FreeBSD Project in part by NAI Labs, * the Security Research Division of Network Associates, Inc. under * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA * CHATS research program. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $ Id: pam_alreadyloggedin.c,v 1.2 2002/03/07 16:54:40 green Exp $ */ /* * Implement a PAM module which will, given restrictions upon whether the * user to be authenticated is root or logging in on a given terminal, * will allow the user to be authenticated successfully if the user * is currently already logged in on another terminal. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include /*-------- Reporting ---------*/ #ifdef DEBUG static int debug_enabled = 1; #else static int debug_enabled = 0; #endif #define DEBUG_LOG(fmt, args...) \ do { if (debug_enabled) \ syslog(LOG_DEBUG, "%s:%i " fmt , __FUNCTION__ , __LINE__ , ## args); \ } while(0) #define ERROR_LOG(fmt, args...) \ syslog(LOG_ERR, "%s:%i " fmt , __FUNCTION__ , __LINE__ , ## args) #define RETURN_ERROR_IF(_Condition, fmt, args...) \ do { if (_Condition) { ERROR_LOG(fmt, args); return -1; } } while(0) #define RETURN_IF_ERROR(_Action, fmt, args...) \ do { if (_Action < 0) { ERROR_LOG(fmt, args); return -1; } } while(0) /* RETURN_IF_PAM_ERROR uses two predefined variables: 'pamh' and 'retval' */ #define RETURN_IF_PAM_ERROR(_Hint, _Action) \ do { if ((retval = _Action) != PAM_SUCCESS) { \ ERROR_LOG("%s:%s", _Hint, pam_strerror(pamh,retval)); \ return retval; \ } } while(0) /*---- end of reporting section ----*/ #ifdef BUG_STAT_MISSING int stat(const char *filename, struct stat *statbuf) { return __xstat(_STAT_VER, filename, statbuf); } #endif static int getutmp(int *fd, struct utmp *utmp); static int inutmp(struct utmp *utmp, const char *lineglob, const char *username, uid_t uid); static int test_option(int argc, const char **argv, const char *option_name, const char **option_value_ref) { int namelen = strlen(option_name); int argnum; for(argnum = 0; argnum < argc; argnum++) { const char *arg = argv[argnum]; int arglen = strlen(arg); if (arglen < namelen) continue; if (memcmp(option_name, arg, namelen)) continue; if (option_value_ref) { if (arglen == namelen) { *option_value_ref = NULL; } else { const char *p = arg+namelen; if ((*p != ':') && (*p != '=')) continue; *option_value_ref = p+1; } } DEBUG_LOG("option=\"%s\", value=\"%s\"", option_name, ( (option_value_ref && *option_value_ref) ? *option_value_ref : "(null)" ) ); return 1; /* ..found */ } /* for(argv) */ return 0; /* ..not found */ } PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv) { struct utmp utmp; struct passwd *pw; const char *logname; const char *lineglob, *loggedinlineglob = NULL; unsigned int matched = 0; int retval, fd = -1; if (test_option(argc, argv, "no_debug", NULL)) { DEBUG_LOG("Debugging output disabled"); debug_enabled = 0; } if (test_option(argc, argv, "debug", NULL)) { debug_enabled = 1; DEBUG_LOG("Debugging output enabled"); } RETURN_IF_PAM_ERROR("pam_get_user", pam_get_user(pamh, &logname, NULL)); DEBUG_LOG("logname = \"%s\"", logname); if (test_option(argc, argv, "restrict_tty", &lineglob) && lineglob) { const char *pam_tty; RETURN_IF_PAM_ERROR("pam_get_item(PAM_TTY)", pam_get_item(pamh, PAM_TTY, (const void **)&pam_tty)); DEBUG_LOG("pam_tty = \"%s\"", pam_tty); if (fnmatch(lineglob, pam_tty, 0) != 0) { DEBUG_LOG("mask(\"%s\") != pam_tty(\"%s\")", lineglob, pam_tty); return PAM_AUTH_ERR; } } test_option(argc, argv, "restrict_loggedin_tty", &loggedinlineglob); if ((pw = getpwnam(logname)) == NULL) return PAM_AUTH_ERR; if (pw->pw_uid == 0 && test_option(argc, argv, "no_root", NULL)) return PAM_AUTH_ERR; while (getutmp(&fd, &utmp) == 1) { if (inutmp(&utmp, loggedinlineglob, logname, pw->pw_uid) == 1) matched++; } DEBUG_LOG("Found matching records in utmp: %d", matched); if (matched) return PAM_SUCCESS; return PAM_AUTH_ERR; } /* * This function is really empty, * but without it Linux PAM displays following warning: * "login: PAM unable to resolve symbol: pam_sm_setcred" */ PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv) { return PAM_SUCCESS; } #ifdef PAM_STATIC struct pam_module _pam_alreadyloggenin_modstruct = { "pam_alreadyloggedin", pam_sm_authenticate, pam_sm_setcred }; #endif int getutmp(int *fd, struct utmp *utmp) { if (*fd < 0) *fd = open(_PATH_UTMP, O_RDONLY); RETURN_IF_ERROR(*fd, "Failure opening %s", _PATH_UTMP); if (read(*fd, utmp, sizeof(*utmp)) == sizeof(*utmp)) return 1; close(*fd); return 0; } int inutmp(struct utmp *utmp, const char *lineglob, const char *username, uid_t uid) { char ttypath[MAXPATHLEN]; struct stat sb; if (utmp->ut_name[0] == '\0' || utmp->ut_line[0] == '\0') return 0; utmp->ut_line[sizeof(utmp->ut_line) - 1] = '\0'; utmp->ut_name[sizeof(utmp->ut_name) - 1] = '\0'; if (*username && strcmp(username, utmp->ut_name)) return 0; #if defined(ENABLE_EVIL_UTMP_CHECK) // This should be omitted on modern linuxes, // thanks to lbenini@csr.unibo.it RETURN_ERROR_IF(utmp->ut_line[strcspn(utmp->ut_line, "./")] != '\0', "Evil utmp line: `%s'", utmp->ut_line); #endif snprintf(ttypath, sizeof(ttypath), "/dev/%s", utmp->ut_line); if (lineglob && (fnmatch(lineglob, ttypath, 0) != 0)) { DEBUG_LOG("mask(\"%s\") != utmp_tty(\"%s\")", lineglob, ttypath); return 0; } /* can't fail */ RETURN_IF_ERROR(stat(ttypath, &sb), "Can't stat line \"%s\"", ttypath); RETURN_ERROR_IF(sb.st_uid != uid, "UID of ttyline %d does not match %d", sb.st_uid, uid); return 1; //ok, true result } /* EOF */ ./login.sso0100600000076400007640000000201310104042046012411 0ustar evseevevseev#%PAM-1.0 # # /etc/pam.d/login.sso -- part of pam_alreadyloggedin package. # # Based on the /etc/pam.d/login taken from ALT Linux Master 2.2 # # Put line calling pam_already_loggedin.so # from here to original /etc/pam.d/login file, # or simply rename `login' file to `login.orig' and this file to `login'. # #--------------------------------------------------------------- auth required /lib/security/pam_securetty.so auth sufficient /lib/security/pam_alreadyloggedin.so debug no_root restrict_tty=/dev/tty[1-6] restrict_loggedin_tty=/dev/tty[1-6] auth required /lib/security/pam_stack.so service=system-auth auth required /lib/security/pam_nologin.so auth optional /lib/security/pam_mail.so account required /lib/security/pam_stack.so service=system-auth password required /lib/security/pam_stack.so service=system-auth session required /lib/security/pam_stack.so service=system-auth session optional /lib/security/pam_lastlog.so nowtmp session optional /lib/security/pam_motd.so session optional /lib/security/pam_console.so ./pam_alreadyloggedin.spec0100644000076400007640000000445610152207310015443 0ustar evseevevseevName: pam_alreadyloggedin Version: 0.3 Release: alt1 %define pamconfdir %_sysconfdir/pam.d %define pamlibdir /lib/security %define mydocdir %_docdir/%name-%version %define examples_dir %mydocdir/examples Summary: Skip password authorization if user is already logged in License: relaxed BSD and (L)GPL-compatible Group: System/Base Url: http://ilya-evseev.narod.ru/posix/%name Source: %url/%name-%version.tar.gz BuildPreReq: libpam-devel Summary(ru_RU.KOI8-R): Вход в систему без пароля, если уже выполнен вход с другой консоли %description Based on the appropriate module from FreeBSD project source tree, %name is a PAM module which allows you to skip authorization stuff (like password entering, etc.), if you are already logged in on the another console. See using example in %pamconfdir/login.sso file. %description -l ru_RU.KOI8-R %name является модулем PAM, который позволяет пользователю пропускать ввод пароля при входе в систему, если этот пользователь уже зашёл в систему с другой консоли. Данный модуль не начинает использоваться немедленно при инсталляции; пример политики PAM для его подключения смотрите в каталоге %examples_dir. %prep %setup -q -c %build %make_build %install %make_install install FAKEROOT=%buildroot MAN8DIR=%_man8dir install -pD -m644 login.sso %buildroot%examples_dir/login %ifdef add_findprov_lib_path %add_findprov_lib_path %pamlibdir %endif %files %pamlibdir/%name.so %examples_dir/login # %pamconfdir/login.sso %_man8dir/%name.8.gz %changelog * Sun Nov 28 2004 Ilya G. Evseev 0.3-alt1 - version 0.3: patch from Luca Benini for skipping some checks no more actual for Linux * Wed Aug 4 2004 Ilya G. Evseev 0.2-alt4 - added add_findprov_lib_path macro - login.sso is moved from /etc/pam.d to docdir/examples, comments are no more needed. * Tue Jul 6 2004 Ilya G. Evseev 0.2-alt3 - fixups in login.sso for preventing invalid RPM requirements - source archive format is changed from ZIP to tar.gz * Fri Jul 2 2004 Ilya G. Evseev 0.2-alt2 - specfile cleanups before adding to ALTLinux Sisyphus repository - added russian summary and description * Wed Jan 28 2004 Ilya G. Evseev 0.2-1 - Initial build, based on the FreeBSD's module version 0.2 ## EOF ##