aboutsummaryrefslogtreecommitdiffstats
path: root/src/adjbacklight.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/adjbacklight.c')
-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:");