LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   user permission to launch a program? (cec-client, raspbian and openHAB) (https://www.linuxquestions.org/questions/linux-newbie-8/user-permission-to-launch-a-program-cec-client-raspbian-and-openhab-4175667549/)

Alphonse 01-12-2020 06:05 AM

user permission to launch a program? (cec-client, raspbian and openHAB)
 
Hello everybody!
Quote:

Hardware:Raspberry Pi 4, software: raspbian buster, manually installed openHAB (from apt) and cec-client
Im trying to add my dumb-tv (HDMI-cec-enabled Toshiba) to my openHAB home automation system, to turn the TV on and off via cec-commands.


The command works fine for the default pi user, but the user openhab is unable to execute the command.

The cec-commands in question are: echo "standby 0 | cec-client RPI -s -d 1
and echo "on 0 | cec-client RPI -s -d 1


Ive tryed sudo su -u openhab echo "standby 0 | cec-client RPI -s -d 1
witch resulted in a new line in terminal, with only a ">".
"sudo su -u openhab ls" does show a list of items in the current folder, so it feels like the openhab user is not allowed to execute the cec-client program.


Now, i did find out the list of groups that these users belong to, and i figure that i might solve this issue by adding openhab to one of them, but i havent a clue regarding what specific group could be the important one...

pi@openHABserver:~$ groups pi
pi : pi adm tty dialout cdrom sudo audio video plugdev games users input netdev bluetooth spi i2c gpio openhab
pi@openHABserver:~$ groups openhab
openhab : openhab tty dialout audio bluetooth gpio



Ive searched the web, but im unable to find out how to check what permissions are needed to execute a program in linux..

And unfortunately, i will not be able to run my commands under another user, openHAB runs under openhab user and all commands executed thru openHAB will be executed as openhab, witch is not a member of sudoers, nor should it for security reasons.


So i need a way to fix this but my linux skills are rudimentary at best..
Does anyone have any ideas, hints or suggestions?

hazel 01-12-2020 08:07 AM

I don't think sudo works with redirection. Try launching a shell with sudo and getting that to do the work, something like sudo sh -c echo "standby 0 | cec-client RPI -s -d 1.

Alphonse 01-12-2020 08:25 AM

im not sure if im really understanding the result correctly, but my command works fine if i type: "sudo su -u pi" before my cec-command.
Im logged in as pi when executing the command above, so im not sure im actually changing the user or if the su-part gets skipped since im aready the pi user..

but i am able to list folder (ls) as openhab with the "sudo su -u openhab ls".


so i think that i will need to allow the user openhab to use the cec-client somehow, but i doubt sudo should be involved..

hazel 01-12-2020 09:05 AM

You could also use su -c, then put the actual command in quotes. But then you would need to use the root password. Or perhaps you could set the suid bit on cec-client so that it ran as root whoever launched it.

berndbausch 01-12-2020 09:22 AM

Quote:

Originally Posted by Alphonse (Post 6077444)
Ive tryed sudo su -u openhab echo "standby 0 | cec-client RPI -s -d 1
witch resulted in a new line in terminal, with only a ">".

Looks like you forgot the closing double-quote. The ">" prompt is issued when something is missing.
Quote:

Ive searched the web, but im unable to find out how to check what permissions are needed to execute a program in linux..
Linux and UNIX have a simple permissions model. An executable file has separate read, write or execute permissions (or a combination thereof) for three sets of accounts: The file's owner, its group, and anybody else. The comnands ls -l and stat reveal those permissions.

Alphonse 01-12-2020 12:09 PM

Quote:

Originally Posted by berndbausch (Post 6077493)
Looks like you forgot the closing double-quote. The ">" prompt is issued when something is missing.

sorry, my bad; it was a bad copy/paste; the command is:
echo standby 0 | cec-client -s -d 1


Thank you kindly for illuminating the permissions situation!
I added the openhab user to pi group and now im allowed to execute the command! :D



thanks everyone for the assist!

hazel 01-13-2020 06:05 AM

Please mark it as solved then.


All times are GMT -5. The time now is 11:47 AM.