LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   (automatic) excution of a program in /usr/sbin as normal user (https://www.linuxquestions.org/questions/linux-software-2/automatic-excution-of-a-program-in-usr-sbin-as-normal-user-4175458774/)

JZL240I-U 04-19-2013 11:36 AM

(automatic) excution of a program in /usr/sbin as normal user
 
I have /usr/sbin/powertop (to minimize power consumption on my netbook) which I want to run automatically late during boot. It has set "-rwxr-xr-x". So I assumed "others" having set their "r-x" (e.g. users like me) can execute it. But I get the message:
Quote:

"Absolute path to 'powertop' is '/usr/sbin/powertop', so running it may require superuser privileges (e.g. root)."
I know that I could add /usr/sbin to my $PATH to get rid of that but I don't want to open that much access to normal users.

Any ideas what is causing this and how to change it without creating security holes? TIA.

linosaurusroot 04-19-2013 11:52 AM

Quote:

Originally Posted by JZL240I-U (Post 4934802)
I know that I could add /usr/sbin to my $PATH to get rid of that but I don't want to open that much access to normal users.

That's safe to do and doesn't increase access.

JZL240I-U 04-22-2013 02:06 AM

Probably a stupid question but anyhow, why is it
Quote:

Originally Posted by linosaurusroot (Post 4934808)
... safe to do and doesn't increase access.

After all, it puts all executables in /usr/sbin in my reach, doesnt't it? Can't this be done selectively just for one program?

chrism01 04-22-2013 02:43 AM

Notice the word 'may' in the msg; its just a warning.
Depending on how you call it, you may be able to suppress it.
If you add it to the startup routines, worst case its just one extra msg amongst many, unless you reboot a lot(!)

JZL240I-U 04-22-2013 02:56 AM

Well, no, it is not only a warning, since I'm thrown back to the prompt. "powertop" has a user interface which should otherwise be shown on the screen (sorry, I mixed two scenarios so as not to flood the forum with stupid questions).

chrism01 04-22-2013 09:24 AM

In that case, its a badly written msg.

The boot process is run by root, so if its in there, you shouldn't get a problem unless you're trying to run it as someone else.
If you want to run it as someone who is not root, try setting suid (as root) on the file.
Code:

chmod u+s /usr/sbin/powertop
This causes it to run as root, regardless of who calls it, eg see /usr/bin/passwd.

JZL240I-U 04-22-2013 09:39 AM

Quote:

chmod u+s /usr/sbin/powertop
Tried it, but no change. When I try it now, I still get

Quote:

"Absolute path to 'powertop' is '/usr/sbin/powertop', so running it may require superuser privileges (e.g. root)."
@ linosaurusroot: Your suggestion doesn't work either. I get
Quote:

Powertop v2.2 must be run with root privileges.
Leaving...
So what now? ;) PAM??

david1941 04-22-2013 09:46 AM

you could try a sym link to the executable in /usr/bin

273 04-22-2013 09:58 AM

I think it's hard coded into powertop to check that the user running it is root, at least that's what I get from the code here:
https://github.com/fenrus75/powertop...r/src/main.cpp
Code:

static void checkroot() {
        int uid;
        uid = getuid();

        if (uid != 0) {
                printf(_("PowerTOP " POWERTOP_VERSION " must be run with root privileges.\n"));
                printf(_("exiting...\n"));
                exit(EXIT_FAILURE);
        }
}


JZL240I-U 04-22-2013 01:27 PM

Quote:

Originally Posted by 273 (Post 4936489)
...it's hard coded into powertop to check that the user running it is root...

Darn. That means when I use my netbook as normal user I have to "su" to root to set the proper power settings. That's bloody inconvenient :mad:. Or do any of you have a different solution?

273 04-22-2013 01:43 PM

I'm afraid I don't, but would something like this help?
http://askubuntu.com/questions/11270...nges-permanent
Not used it myself so can't vouch for it working.

chrism01 04-22-2013 09:50 PM

At least in post #9 the msg says 'must' be run as root; that's much clearer.
Wonder why OP gets a different msg; different version perhaps?
Maybe you should contact the author.

273 04-23-2013 01:57 AM

Quote:

Originally Posted by chrism01 (Post 4936883)
At least in post #9 the msg says 'must' be run as root; that's much clearer.
Wonder why OP gets a different msg; different version perhaps?
Maybe you should contact the author.

You make a very good point. The message about the absolute path doesn't seem to be in the listing I linked to and looks like it may even be a system message. Perhaps that means that the sticky bit is working and it's something else?

JZL240I-U 04-23-2013 02:32 AM

Quote:

Originally Posted by 273 (Post 4936964)
...The message about the absolute path doesn't seem to be in the listing I linked to and looks like it may even be a system message. Perhaps that means that the sticky bit is working and it's something else?

That's why I mentioned PAM, but with that I'm entirely out of my depth. I'll try your askubuntu link and come back later.

JZL240I-U 04-24-2013 05:08 AM

Well, that opened a whole new can of worms :rolleyes:.

I had (in part) already incorporated the procedure from your link, 273. I completed it now and thus have a script with all the desired commands. In principle I don't need to run "powertop" anymore, though I'd still like to know, whether these restrictions can be circumvented. Anyways.

The normal user (myself) can run that script and it resides in KDE's Autostart directory. But it doesn't work :mad:. In the most cases access to the /proc and /sys directories (rather their subdirectories) is denied. Also commands like "hdparm", "ethtool" and "iw" are not found. When I "su" too root and run that script I get no error and everything is set as desired. So I'm back to step one.

The same (i.e. nothing) happens, when I incorporate the commands from the script in the user's ".profile" or ".bashrc" files.

Btw. chrism01, I checked with wikipedia, it says that most distributions disable the suid bit of script for security reasons.

You also wrote that the init process is run by root. Thus I copied the script to /etc/init.d and created links at rc3.d and rc5.d. And lo and behold -- the script works as desired -- but only when I log in as root, and not so when I'm the normal user, even though "chkconfig" and YAST's runlevel editor show that the script is active and running.

Seems that "systemd" is not always running as root?!? I don't understand this at all...


All times are GMT -5. The time now is 11:22 PM.