diff options
| -rw-r--r-- | share/man/man5/fbtab.5 | 6 | ||||
| -rw-r--r-- | usr.bin/login/login_fbtab.c | 58 |
2 files changed, 25 insertions, 39 deletions
diff --git a/share/man/man5/fbtab.5 b/share/man/man5/fbtab.5 index 014ce47827fc..91d3d6d40454 100644 --- a/share/man/man5/fbtab.5 +++ b/share/man/man5/fbtab.5 @@ -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 diff --git a/usr.bin/login/login_fbtab.c b/usr.bin/login/login_fbtab.c index e0b99e367165..c3ca5ecdecf0 100644 --- a/usr.bin/login/login_fbtab.c +++ b/usr.bin/login/login_fbtab.c @@ -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; - - 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); + glob_t gl; + char *path; + int i; + + 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); } |
