1995-05-19 09:53:51 +00:00
|
|
|
/************************************************************************
|
|
|
|
* Copyright 1995 by Wietse Venema. All rights reserved.
|
|
|
|
*
|
|
|
|
* This material was originally written and compiled by Wietse Venema at
|
|
|
|
* Eindhoven University of Technology, The Netherlands, in 1990, 1991,
|
|
|
|
* 1992, 1993, 1994 and 1995.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that this entire copyright notice is duplicated in all such
|
1995-05-30 06:41:30 +00:00
|
|
|
* copies.
|
1995-05-19 09:53:51 +00:00
|
|
|
*
|
|
|
|
* This software is provided "as is" and without any expressed or implied
|
|
|
|
* warranties, including, without limitation, the implied warranties of
|
|
|
|
* merchantibility and fitness for any particular purpose.
|
|
|
|
************************************************************************/
|
1994-08-22 19:56:14 +00:00
|
|
|
/*
|
|
|
|
SYNOPSIS
|
|
|
|
void login_fbtab(tty, uid, gid)
|
|
|
|
char *tty;
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This module implements device security as described in the
|
|
|
|
SunOS 4.1.x fbtab(5) and SunOS 5.x logindevperm(4) manual
|
|
|
|
pages. The program first looks for /etc/fbtab. If that file
|
|
|
|
cannot be opened it attempts to process /etc/logindevperm.
|
2011-12-30 11:02:40 +00:00
|
|
|
We expect entries with the following format:
|
1994-08-22 19:56:14 +00:00
|
|
|
|
|
|
|
Comments start with a # and extend to the end of the line.
|
|
|
|
|
|
|
|
Blank lines or lines with only a comment are ignored.
|
|
|
|
|
|
|
|
All other lines consist of three fields delimited by
|
|
|
|
whitespace: a login device (/dev/console), an octal
|
|
|
|
permission number (0600), and a ":"-delimited list of
|
|
|
|
devices (/dev/kbd:/dev/mouse). All device names are
|
1998-02-15 04:09:48 +00:00
|
|
|
absolute paths. A path that ends in "*" refers to all
|
1994-08-22 19:56:14 +00:00
|
|
|
directory entries except "." and "..".
|
|
|
|
|
|
|
|
If the tty argument (relative path) matches a login device
|
|
|
|
name (absolute path), the permissions of the devices in the
|
|
|
|
":"-delimited list are set as specified in the second
|
|
|
|
field, and their ownership is changed to that of the uid
|
|
|
|
and gid arguments.
|
|
|
|
|
|
|
|
DIAGNOSTICS
|
|
|
|
Problems are reported via the syslog daemon with severity
|
|
|
|
LOG_ERR.
|
|
|
|
|
|
|
|
BUGS
|
|
|
|
This module uses strtok(3), which may cause conflicts with other
|
|
|
|
uses of that same routine.
|
|
|
|
|
|
|
|
AUTHOR
|
|
|
|
Wietse Venema (wietse@wzv.win.tue.nl)
|
|
|
|
Eindhoven University of Technology
|
|
|
|
The Netherlands
|
|
|
|
*/
|
|
|
|
|
2001-12-02 20:54:57 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-08-22 19:56:14 +00:00
|
|
|
#include <sys/types.h>
|
1997-09-28 08:57:24 +00:00
|
|
|
#include <sys/stat.h>
|
1994-08-22 19:56:14 +00:00
|
|
|
#include <errno.h>
|
2001-10-25 20:45:47 +00:00
|
|
|
#include <glob.h>
|
2001-12-02 00:06:22 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <syslog.h>
|
1997-09-28 08:57:24 +00:00
|
|
|
#include <unistd.h>
|
2001-12-01 17:46:46 +00:00
|
|
|
|
2009-12-13 03:14:06 +00:00
|
|
|
#include "login.h"
|
1994-08-22 19:56:14 +00:00
|
|
|
#include "pathnames.h"
|
|
|
|
|
2002-03-22 01:22:50 +00:00
|
|
|
static void login_protect(const char *, char *, int, uid_t, gid_t);
|
1994-08-22 19:56:14 +00:00
|
|
|
|
|
|
|
#define WSPACE " \t\n"
|
|
|
|
|
|
|
|
/* login_fbtab - apply protections specified in /etc/fbtab or logindevperm */
|
|
|
|
|
|
|
|
void
|
2010-01-02 10:09:20 +00:00
|
|
|
login_fbtab(char *tty, uid_t uid, gid_t gid)
|
1994-08-22 19:56:14 +00:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
char *devname;
|
|
|
|
char *cp;
|
|
|
|
int prot;
|
2001-12-01 17:46:46 +00:00
|
|
|
const char *table;
|
1994-08-22 19:56:14 +00:00
|
|
|
|
2007-09-21 01:55:11 +00:00
|
|
|
if ((fp = fopen(table = _PATH_FBTAB, "r")) == NULL
|
|
|
|
&& (fp = fopen(table = _PATH_LOGINDEVPERM, "r")) == NULL)
|
1994-08-22 19:56:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
while (fgets(buf, sizeof(buf), fp)) {
|
1997-09-28 08:57:24 +00:00
|
|
|
if ((cp = strchr(buf, '#')))
|
1994-08-22 19:56:14 +00:00
|
|
|
*cp = 0; /* strip comment */
|
2016-04-18 05:26:32 +00:00
|
|
|
if ((cp = devname = strtok(buf, WSPACE)) == NULL)
|
1994-08-22 19:56:14 +00:00
|
|
|
continue; /* empty or comment */
|
2000-12-09 09:35:55 +00:00
|
|
|
if (strncmp(devname, _PATH_DEV, sizeof _PATH_DEV - 1) != 0
|
2016-04-18 05:26:32 +00:00
|
|
|
|| (cp = strtok(NULL, WSPACE)) == NULL
|
1994-08-22 19:56:14 +00:00
|
|
|
|| *cp != '0'
|
|
|
|
|| sscanf(cp, "%o", &prot) == 0
|
|
|
|
|| prot == 0
|
|
|
|
|| (prot & 0777) != prot
|
2016-04-18 05:26:32 +00:00
|
|
|
|| (cp = strtok(NULL, WSPACE)) == NULL) {
|
1994-08-22 19:56:14 +00:00
|
|
|
syslog(LOG_ERR, "%s: bad entry: %s", table, cp ? cp : "(null)");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(devname + 5, tty) == 0) {
|
2012-02-14 10:11:45 +00:00
|
|
|
for (cp = strtok(cp, ":"); cp; cp = strtok(NULL, ":")) {
|
1994-08-22 19:56:14 +00:00
|
|
|
login_protect(table, cp, prot, uid, gid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* login_protect - protect one device entry */
|
|
|
|
|
2015-09-10 22:25:40 +00:00
|
|
|
static void
|
2010-01-02 10:09:20 +00:00
|
|
|
login_protect(const char *table, char *pattern, int mask, uid_t uid, gid_t gid)
|
1994-08-22 19:56:14 +00:00
|
|
|
{
|
2001-10-28 22:54:16 +00:00
|
|
|
glob_t gl;
|
|
|
|
char *path;
|
2007-05-07 11:01:36 +00:00
|
|
|
unsigned int i;
|
2001-10-28 22:54:16 +00:00
|
|
|
|
|
|
|
if (glob(pattern, GLOB_NOSORT, NULL, &gl) != 0)
|
|
|
|
return;
|
|
|
|
for (i = 0; i < gl.gl_pathc; i++) {
|
|
|
|
path = gl.gl_pathv[i];
|
|
|
|
/* clear flags of the device */
|
|
|
|
if (chflags(path, 0) && errno != ENOENT && errno != EOPNOTSUPP)
|
|
|
|
syslog(LOG_ERR, "%s: chflags(%s): %m", table, path);
|
|
|
|
if (chmod(path, mask) && errno != ENOENT)
|
|
|
|
syslog(LOG_ERR, "%s: chmod(%s): %m", table, path);
|
|
|
|
if (chown(path, uid, gid) && errno != ENOENT)
|
|
|
|
syslog(LOG_ERR, "%s: chown(%s): %m", table, path);
|
|
|
|
}
|
|
|
|
globfree(&gl);
|
1994-08-22 19:56:14 +00:00
|
|
|
}
|