summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdevinfo/devinfo_devperm.c
diff options
context:
space:
mode:
authoreota <none@none>2006-09-26 14:29:13 -0700
committereota <none@none>2006-09-26 14:29:13 -0700
commit1ca932730d3439e527d5fe4a15444600d0df7e7e (patch)
tree021f725c3677f6b8619e3ef76fb7720c121e0520 /usr/src/lib/libdevinfo/devinfo_devperm.c
parent23b5c241225a8ade2b6b9f06ebb891ee459e3b02 (diff)
downloadillumos-gate-1ca932730d3439e527d5fe4a15444600d0df7e7e.tar.gz
6311701 /etc/minor_perm is ignored if it contains comments
6459253 i.nametomajor holds the obsolete shell function 6460892 add_drv and update_drv can accept the invalid names 6462571 should clean up duplicate code in update_minor_entry()
Diffstat (limited to 'usr/src/lib/libdevinfo/devinfo_devperm.c')
-rw-r--r--usr/src/lib/libdevinfo/devinfo_devperm.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/usr/src/lib/libdevinfo/devinfo_devperm.c b/usr/src/lib/libdevinfo/devinfo_devperm.c
index 5a52fc2a6c..412eb74fc8 100644
--- a/usr/src/lib/libdevinfo/devinfo_devperm.c
+++ b/usr/src/lib/libdevinfo/devinfo_devperm.c
@@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
@@ -64,6 +65,8 @@ static int dir_dev_acc(char *, char *, uid_t, gid_t, mode_t, char *line,
static int setdevaccess(char *, uid_t, gid_t, mode_t, void (*)());
static void logerror(char *);
+static int is_blank(char *);
+
#define MAX_LINELEN 256
#define LOGINDEVPERM "/etc/logindevperm"
#define DIRWILD "/*" /* directory wildcard */
@@ -772,14 +775,21 @@ i_devfs_read_minor_perm(char *drvname, void (*errcb)(minorperm_err_t, int))
(*errcb)(MP_FOPEN_ERR, errno);
return (NULL);
}
- while (fgets(line, MAX_MINOR_PERM_LINE - 1, pfd) != NULL) {
+ while (fgets(line, MAX_MINOR_PERM_LINE, pfd) != NULL) {
ln++;
+ /* cut off comments starting with '#' */
+ if ((cp = strchr(line, '#')) != NULL)
+ *cp = '\0';
+ /* ignore comment or blank lines */
+ if (is_blank(line))
+ continue;
mp = (struct mperm *)calloc(1, sizeof (struct mperm));
if (mp == NULL) {
(*errcb)(MP_ALLOC_ERR, sizeof (struct mperm));
continue;
}
cp = line;
+ /* sanity-check */
if (getnexttoken(cp, &cp, &p, &t) == 0) {
(*errcb)(MP_IGNORING_LINE_ERR, ln);
devfs_free_minor_perm(mp);
@@ -1057,3 +1067,18 @@ devfs_rm_minor_perm(char *drv,
{
return (i_devfs_update_minor_perm(drv, MODREMMINORPERM, errcb));
}
+
+/*
+ * is_blank() returns 1 (true) if a line specified is composed of
+ * whitespace characters only. otherwise, it returns 0 (false).
+ *
+ * Note. the argument (line) must be null-terminated.
+ */
+static int
+is_blank(char *line)
+{
+ for (/* nothing */; *line != '\0'; line++)
+ if (!isspace(*line))
+ return (0);
+ return (1);
+}