cloudshell lcd script for rootless lcd toggling

Post Reply
yysh12
Posts: 8
Joined: Mon Dec 18, 2017 2:37 am
languages_spoken: english
ODROIDs: Odroid XU and now also XU4
Contact:

cloudshell lcd script for rootless lcd toggling

Unread post by yysh12 » Sun Apr 29, 2018 4:43 am

Nothing fancy just though I'd post if for anyone who doesn't want to do it themselves and wants a quick solution. Basically a shell script that requires root status to toggle lcd is executed through a compiled c program with setgid to root. note I was told this is dangerous since anyone with access to the shell script can modify it and run it as root (which is the whole reason I think linux doesn't allow for setgid root on shell scripts). make sure to adjust filepaths in c program and adjust permissions and setgid on your own.

c code:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <iostream>

//need a better solution to this someday

using namespace std;

int main(int argc, char* argv[])
{
setuid(0);
cout<<argv[1]<<endl;
if ( argv[1][1] == 'f') {
cout<<"turning off"<<endl;
system("/home/Bin/.turn.sh off"); //path to shell script
} else if ( argv[1][1] == 'n' ) {
cout<<"turning on"<<endl;
system("/home/Bin/.turn.sh on"); //path to shell script
}
else {
cout<<"error!"<<endl;
}
return 0;
}
shell script

Code: Select all

#!/bin/bash

if [ $1 = "off" ]
then
echo 1 > /sys/class/backlight/*/bl_power
elif [ $1 = "on" ]
then
echo 0 > /sys/class/backlight/*/bl_power
else
echo "parameters must be either 'on' or 'off'"
fi
lastly setgid to root and adjust bin paths and permissions

User avatar
rooted
Posts: 6065
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Contact:

Re: cloudshell lcd script for rootless lcd toggling

Unread post by rooted » Sun Apr 29, 2018 5:32 am

You can run a shell script like it's an executable, why the C file?

*edit*
I missed the setgid

Post Reply

Return to “CloudShell”

Who is online

Users browsing this forum: No registered users and 2 guests