o Modify format of /etc/fbtab to accept glob matching patterns for

target devices, not just individual devices and directories.  This
  permits activities such as:

	ttyv0		0600	/dev/dsp*

  Whereas previously that was not supported.  This change is
  backwards-compatible, except where device names included globbing
  characters, which is not the case for any devices listed in MAKEDEV.

Submitted by:	Maxime Henrion <mux@qualys.com>
MFC after:	3 weeks
This commit is contained in:
Robert Watson 2001-10-25 20:45:47 +00:00
parent 76e7a78292
commit 4983b09404
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=85504
2 changed files with 24 additions and 38 deletions

View File

@ -19,10 +19,8 @@ Blank lines or lines with only a comment are ignored.
All other lines consist of three fields delimited by
whitespace: a login device (/dev/ttyv0), an octal
permission number (0600), and a ":"-delimited list of
devices (/dev/console). All device names are
absolute paths.
A path that ends in "/*" refers to all
directory entries except "." and "..".
device patterns (/dev/console, /dev/dsp*).
All device patterns are absolute paths.
.Pp
If the tty argument (relative path) matches a login device
name (absolute path), the permissions of the devices in the

View File

@ -65,7 +65,7 @@
#include <syslog.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>
#include <glob.h>
#include <paths.h>
#include <unistd.h>
#include "pathnames.h"
@ -121,40 +121,28 @@ gid_t gid;
/* login_protect - protect one device entry */
void
login_protect(table, path, mask, uid, gid)
char *table;
char *path;
int mask;
uid_t uid;
gid_t gid;
login_protect(table, pattern, mask, uid, gid)
char *table;
char *pattern;
int mask;
uid_t uid;
gid_t gid;
{
char buf[BUFSIZ];
int pathlen = strlen(path);
struct dirent *ent;
DIR *dir;
glob_t gl;
char *path;
int i;
if (strcmp("/*", path + pathlen - 2) != 0) {
/* 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);
} else {
strcpy(buf, path);
buf[pathlen - 1] = 0;
if ((dir = opendir(buf)) == 0) {
syslog(LOG_ERR, "%s: opendir(%s): %m", table, path);
} else {
while ((ent = readdir(dir)) != 0) {
if (strcmp(ent->d_name, ".") != 0
&& strcmp(ent->d_name, "..") != 0) {
strcpy(buf + pathlen - 1, ent->d_name);
login_protect(table, buf, mask, uid, gid);
}
}
closedir(dir);
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);
}