From owner-freebsd-bugs Sun Oct 21 16:40:11 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 72E5237B403 for ; Sun, 21 Oct 2001 16:40:01 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id f9LNe1D20450; Sun, 21 Oct 2001 16:40:01 -0700 (PDT) (envelope-from gnats) Received: from noos.fr (r178m112.cybercable.tm.fr [195.132.178.112]) by hub.freebsd.org (Postfix) with ESMTP id 17AE437B403 for ; Sun, 21 Oct 2001 16:33:40 -0700 (PDT) Received: (from mux@localhost) by noos.fr (8.11.6/8.11.4) id f9LNXcH23043; Mon, 22 Oct 2001 01:33:38 +0200 (CEST) (envelope-from mux) Message-Id: <200110212333.f9LNXcH23043@noos.fr> Date: Mon, 22 Oct 2001 01:33:38 +0200 (CEST) From: Maxime Henrion Reply-To: Maxime Henrion To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: bin/31419: [PATCH] Allow device name patterns in fbtab(5) Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 31419 >Category: bin >Synopsis: [PATCH] Allow device name patterns in fbtab(5) >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Oct 21 16:40:01 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Maxime Henrion >Release: FreeBSD 5.0-CURRENT i386 >Organization: None. >Environment: System: FreeBSD nebula.cybercable.fr 5.0-CURRENT FreeBSD 5.0-CURRENT #132: Sun Oct 21 13:42:49 CEST 2001 root@nebula.cybercable.fr:/usr/src/sys/i386/compile/NEBULA i386 >Description: The handling of the fbtab(5) file in login(1) only allows to put complete device pathnames or pathnames ending with "/*" in which case it will apply the changes to all files in the directory. This patch rewrites the login_protect() routine to use glob(3) so that it's possible to put real device name patterns. This is very useful for all the /dev/dsp* and /dev/audio* devices. >How-To-Repeat: Try to put /dev/dsp* in the list of device names in /etc/fbtab :) >Fix: --- fbtab.patch begins here --- Index: fbtab.5 =================================================================== RCS file: /home/ncvs/src/share/man/man5/fbtab.5,v retrieving revision 1.10 diff -u -r1.10 fbtab.5 --- fbtab.5 14 Jul 2001 19:41:09 -0000 1.10 +++ fbtab.5 21 Oct 2001 23:15:43 -0000 @@ -19,10 +19,8 @@ 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 Index: login_fbtab.c =================================================================== RCS file: /home/ncvs/src/usr.bin/login/login_fbtab.c,v retrieving revision 1.9 diff -u -r1.9 login_fbtab.c --- login_fbtab.c 9 Dec 2000 09:35:41 -0000 1.9 +++ login_fbtab.c 21 Oct 2001 23:04:24 -0000 @@ -65,7 +65,7 @@ #include #include #include -#include +#include #include #include #include "pathnames.h" @@ -121,40 +121,28 @@ /* 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); } --- fbtab.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message