Created
December 13, 2016 06:33
-
-
Save scotchi/0027e2ff04c234f67e54ea98afd3e159 to your computer and use it in GitHub Desktop.
Little tool to run setuid that can be called from ~/.xinitrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
int main(int argc, const char *argv[]) | |
{ | |
if(geteuid() != 0) | |
{ | |
fprintf(stderr, "This program should be setuid or run as root.\n"); | |
return 1; | |
} | |
if(argc != 2) | |
{ | |
return 2; | |
} | |
int value = atoi(argv[1]); | |
if(value < 0 || value > 63) | |
{ | |
fprintf(stderr, "Value is out of range.\n"); | |
return 3; | |
} | |
FILE *param_file = fopen("/sys/module/hid_magicmouse/parameters/scroll_speed", "w"); | |
if(!param_file) | |
{ | |
fprintf(stderr, "Magic Mouse not connected.\n"); | |
return 4; | |
} | |
if(fprintf(param_file, "%i\n", value) <= 0) | |
{ | |
fprintf(stderr, "Couldn't write parameter.\n"); | |
fclose(param_file); | |
return 5; | |
} | |
fclose(param_file); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment