From ccf43e36c9cfdb8a71d1f1a2c46fdab41f3cc95d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 26 Jan 2014 10:58:05 +0100 Subject: restrict to root and the video herd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/adjbacklight.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/adjbacklight.c b/src/adjbacklight.c index 289401c..2aee72e 100644 --- a/src/adjbacklight.c +++ b/src/adjbacklight.c @@ -27,7 +27,8 @@ #include #include #include - +#include +#include @@ -311,6 +312,38 @@ int main(int argc, char** argv) } + /* Check permissions */ + if (getuid()) /* Always accept root */ + { + struct group* video_grp = getgrnam("video"); + if (video_grp) /* Accept everypony if the group ‘video’ does not exist */ + { + struct passwd* realuser = getpwuid(getuid()); + if (!realuser) + { + P("You do not exist, go away!"); + return 1; + } + char** mems = video_grp->gr_mem; + char* realname = realuser->pw_name; + int ok = 0; + for (; *mems; mems++) + if (!strcmp(realname, *mems)) + { + ok = 1; + break; + } + endgrent(); + if (!ok) + { + P("Sorry, you need to be in the group 'video'."); + return 1; + } + } + endpwent(); + } + + P("\n"); P("If the program is abnormally aborted the may be some residual"); P("effects on the terminal. the following commands should reset it:"); -- cgit v1.2.3-70-g09d2