Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Jun 1997 23:54:19 +0200 (CEST)
From:      Luigi Rizzo <luigi@iet.unipi.it>
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/3837: new feature for rtprio
Message-ID:  <199706102154.XAA01012@prova.iet.unipi.it>
Resent-Message-ID: <199706102200.PAA06327@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         3837
>Category:       bin
>Synopsis:       new feature for rtprio
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 10 15:00:01 PDT 1997
>Last-Modified:
>Originator:     Luigi Rizzo
>Organization:
Dip. Ing. Informazione Univ. Pisa
>Release:        FreeBSD 2.2.1-RELEASE i386
>Environment:

>Description:

	This patch allows users listed in /etc/rtprio.conf to set
	realtime priorities for processes. Useful to let non-root
	users burn CDs. I also include the small manpage change.


>How-To-Repeat:

>Fix:
	
--- rtprio.1.orig	Fri Mar  7 08:45:39 1997
+++ rtprio.1	Tue Jun 10 23:47:26 1997
@@ -107,8 +107,15 @@
 .Ar Pid
 of 0 means "the current process".
 .Pp
-Only root is allowed to set realtime priorities. Non-root processes may
+Only root or users listed in
+.Ar /etc/rtprio.conf
+are
+allowed to set realtime priorities. Non-allowed processes may
 set idle priority levels for the current process only.
+.Pp
+.Ar /etc/rtprio.conf
+must be be a regular file owned by root and not writable by other users.
+It contains one username per line, starting at the beginning of the line.
 .Sh RETURN VALUE
 If
 .Nm rtprio
--- rtprio.c.orig	Sun Oct  2 05:48:21 1994
+++ rtprio.c	Tue Jun 10 23:43:07 1997
@@ -46,6 +46,77 @@
 
 static void usage();
 
+/*
+ * this module checks which modules are allowed to set rtpriority.
+ * Allowed users are listed in /etc/rtprio.conf, which must not be
+ * writable by others than root. One user per line, starting at
+ * the beginning.
+ *
+ */
+
+#include <syslog.h>
+#include <pwd.h>
+#include <sys/stat.h>
+
+#define	_PATH_RTPRIOCONF	"/etc/rtprio.conf"
+
+int
+allowed_user()
+{
+    FILE  *fp;
+    char   line[BUFSIZ];
+    int    lineno = 0 ;
+    int    end ;
+    uid_t  uid;
+    struct passwd *pw;
+    struct stat sb;
+
+    uid = getuid() ;
+    if (uid == 0)
+	return 1;	/* root is always allowed */
+
+    if (stat(_PATH_RTPRIOCONF, &sb))
+	return 0;
+
+    /*
+     * the access control file must be a regular file, owned by
+     * root and not writable by others
+     *
+     */
+    if ( (sb.st_uid != 0) || ( (sb.st_mode & S_IFMT) != S_IFREG) ||
+	 ( (sb.st_mode & (S_IWGRP | S_IWOTH)) != 0 ) ) {
+	syslog(LOG_ERR, "%s: bad permissions, ignoring it",
+		_PATH_RTPRIOCONF);
+	return 0 ;
+    }
+    /* should check that _PATH_RTPRIOCONF is only writable by root. */
+
+    if (fp = fopen(_PATH_RTPRIOCONF, "r")) {
+	while (fgets(line, sizeof(line), fp)) {
+	    lineno++;
+	    if (line[end = strlen(line) - 1] != '\n') {
+		syslog(LOG_ERR, "%s: line %d: missing newline or line too long",
+			_PATH_RTPRIOCONF, lineno);
+		continue;
+	    }
+	    while (end > 0 && isspace(line[end - 1]))
+		end--;
+	    line[end] = 0;
+	    if (line[0] == 0)
+		continue;
+	    pw = getpwnam(line) ;
+	    if ( pw && pw->pw_uid == uid ) {
+		fclose(fp);
+		return 1 ;
+	    }
+	}
+	fclose(fp);
+    }
+    syslog(LOG_ERR, "%s: userid %d not allowed",
+	_PATH_RTPRIOCONF, uid);
+    return 0 ;
+}
+
 int
 main(argc, argv)
 	int     argc;
@@ -55,6 +126,7 @@
 	int     proc = 0;
 	struct rtprio rtp;
 
+	seteuid( getuid() );	/* drop privileges immediately */
 	/* find basename */
 	if ((p = rindex(argv[0], '/')) == NULL)
 		p = argv[0];
@@ -113,10 +185,13 @@
 		if (argv[2][0] == '-')
 			proc = -atoi(argv[2]);
 
+		if (allowed_user())
+			seteuid(0);	/* raise privilege */
 		if (rtprio(RTP_SET, proc, &rtp) != 0) {
 			perror(argv[0]);
 			exit (1);
 		}
+		seteuid(getuid());	/* lower privilege again */
 
 		if (proc == 0) {
 			execvp(argv[2], &argv[2]);
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199706102154.XAA01012>