aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-01-26 10:58:05 +0100
committerMattias Andrée <maandree@operamail.com>2014-01-26 10:58:05 +0100
commitccf43e36c9cfdb8a71d1f1a2c46fdab41f3cc95d (patch)
tree658918f6ff8fcad8b2ecba40db25fc831bd7b150 /src
parentupdate info manual (diff)
downloadadjbacklight-ccf43e36c9cfdb8a71d1f1a2c46fdab41f3cc95d.tar.gz
adjbacklight-ccf43e36c9cfdb8a71d1f1a2c46fdab41f3cc95d.tar.bz2
adjbacklight-ccf43e36c9cfdb8a71d1f1a2c46fdab41f3cc95d.tar.xz
restrict to root and the video herd
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r--src/adjbacklight.c35
1 files changed, 34 insertions, 1 deletions
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 <string.h>
#include <limits.h>
#include <alloca.h>
-
+#include <grp.h>
+#include <pwd.h>
@@ -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:");