maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   [Solved]dbus-send --type=method_call --dest=org.freedesktop.Notifications - problem with root privileges (https://talk.maemo.org/showthread.php?t=76037)

Estel 2011-08-24 20:48

[Solved]dbus-send --type=method_call --dest=org.freedesktop.Notifications - problem with root privileges
 
1 Attachment(s)
Hello, and excuse me in advance, if this was covered before - ho ever, despite extensive searching, I wasn't able to find an answer. This explanation is going to be quite long, but I want to provide as much info as I can.

I develop some simple script (showing certain "glance" info derived from i2cget, based on shadowjk's bq27200 script), which put output to screen as maemo native notify. Basically, script contains 2 part - one for gathering and calculating info - based (mostly) on work by shadowjk - and second, forwarding output to screen.

For printing output, I use:

Code:

dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"content-here-blablabla" uint32:0 string:""
The idea is that, after creating correct .desktop file pointing to script, shortcut can be placed on home desktop and/or it may be assigned to some hardware button (via third party applications, i.e. shortcutd). So, when needed, independently of device state (i.e. using fullscreen application), I can call my little script to provide info as notification.

Side note: I was using this method before to show notification info, derived from bq27x00 module (cat sys/class/power_supply/bq27200 etc.), and it worked like a charm - thanks to Nicolai, who helped me to understand calling upon notifications.

Gathering data from i2cget require root privileges - and here, the problem begin. For unknown reason, script works as it should when called from terminal, after "root" command (via rootsh package), but refuse to work when privileges were gained by "sudo gainroot". Furthermore, adding script as .sudoers result in same output, as when called after "sudo gainroot" - it prove that sudoers file is created properly (I think), but doesn't solve problem.

When called after "root", no errors, and notification info pop-out with correct data. When called after "sudo gainroot", or with "sudo" after .sudoers created, output in terminal is:

Code:

Failed to open connection to "session" message bus: (null)
I've checked what "root" script (that we get via rootsh, so we can use "root" in terminal to, well, gain root) contain - its "exec sudo gainroot --use-su". I've tried many combinations with --use-su together with "sudo gainroot" from terminal, to no avail (maybe I'm missing something here?).

What even more strange, bq27200.sh (script by shadowjk, that I used as base) works flawlessly with "sudo" after creating .sudoer for it. Also, using notification pop-up method (dbus-send etc), inside script that doesn't contain parts requiring root access (so, in my case, particularly parts from bq27200.sh, that works stand-alone) also result in no-problem. So, I got troubles only, when using script that contain *BOTH* gathering data requiring root, and displaying via aforementioned dbus-send method.

As result, I can't use this script from any kind of shortcut (desktop, hardware, whatever) - only from terminal, after "root". I've searched solid few days for possible solution - hence the "discovery" about it performing well with "root", but failing after "sudo gainroot" - but I'm still scratching my head clueless.

I'm attaching current version of script here (renamed to .sh.txt, to upload via forum mechanism), in case anyone want to try on her/his device (it may be little messy, it's developing version :P ). Any help/clues *really* much appreciated.

MohammadAG 2011-08-24 21:58

Re: dbus-send --type=method_call --dest=org.freedesktop.Notifications - problem with root privileges
 
Prefix dbus-send with run-standalone.sh

Code:

run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"Voltage: $VOLT

karam 2011-08-24 22:34

Re: dbus-send --type=method_call --dest=org.freedesktop.Notifications - problem with root privileges
 
that is true you need

run-standalone.sh

before the script
cause when you type

root

it runs that script [standalone] with anything
also in user
but not with sudo gainroot

you can also :

Code:

sudo run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications
but you need to do this first

Code:

echo "user ALL=(ALL) NOPASSWD: ALL" >> everybody.sudoers
echo "root ALL=(ALL) NOPASSWD: ALL" >> everybody.sudoers
mv everybody.sudoers /etc/sudoers.d
update-sudoers

this will let you run sudo #anything as root
also double root is possible

MohammadAG 2011-08-25 00:00

Re: dbus-send --type=method_call --dest=org.freedesktop.Notifications - problem with root privileges
 
Quote:

Originally Posted by karam (Post 1076068)
that is true you need

run-standalone.sh

before the script
cause when you type

root

it runs that script [standalone] with anything
also in user
but not with sudo gainroot

No, neither user nor "root" use run-standalone.sh, it has to do with environment variables being set in one and not the other.

Quote:

Originally Posted by karam (Post 1076068)
you can also :

Code:

sudo run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications
but you need to do this first

Code:

echo "user ALL=(ALL) NOPASSWD: ALL" >> everybody.sudoers
echo "root ALL=(ALL) NOPASSWD: ALL" >> everybody.sudoers
mv everybody.sudoers /etc/sudoers.d
update-sudoers

this will let you run sudo #anything as root
also double root is possible

That would also allow a sudo rm -rf /path/to/root, keeping some security on the system is saner.

Estel 2011-08-25 00:13

Re: dbus-send --type=method_call --dest=org.freedesktop.Notifications - problem with root privileges
 
Thank You MohammadAG, obviously, it works like a charm now!

I must write this - it keeps me amazed how knowledgeable and competitive some people here are. Really, no sugar-coating - I could probably search for this +- forever without *any* success, and You MohammadAG "just" throw answer out of Your head.

---

Anyway, possibly last question on this topic - I like to learn when I've a chance - is there a way to run sh script with "sudo" via .desktop shortcut *without* terminal window flashing (turning on and closing after executing)?

I know, this one is probably simple newbie thing, but I've searched many threads about shortcut making on forum (not to mention wiki), and while .sh scripts that doesn't need root privileges run just fine without terminal, when invoked via "Exec=" in .desktop, the best thing I could achieve to run root things was to

Code:

Exec=/usr/bin/osso-xterm 'sudo bnf'
... which, obviously, flash terminal window, not to mention throwing us into dashboard (and outside any fullscreen program), if we're multitasking.

Every attempts with "bnf.sh | sudo gainroot", busybox sh -c 'usr/bin/bnf.sh | sudo gainroot' etc., failed miserably.

Thanks in advance for help, and really, enormous thanks for last one, I'm really impressed.


// Edit

Also thanks Karam, although I really would not like to open system for everything, just for this little script :) Nevertheless, thanks for trying to help.

MohammadAG 2011-08-25 00:46

Re: dbus-send --type=method_call --dest=org.freedesktop.Notifications - problem with root privileges
 
What happens if you use Exec=sudo script.sh?
(You'll need an entry in sudoers.d, limit it to your script only of course).

If you're seeing a black window, that's the fake window hildon-desktop creates when an icon is clicked, so a real window replaces it later on, you can disable this by adding
Code:

X-App-Loading-Image=none
to the .desktop file

Estel 2011-08-25 01:17

Re: dbus-send --type=method_call --dest=org.freedesktop.Notifications - problem with root privileges
 
Thanks for answer, ho ever, using Exec=sudo script.sh does nothing. Literally nothing, just nothing happens. That was the first thing I've tried after creating entry in sudoers.d :p I also got X-App-Loading-Image=none set.

When I execute "sudo script.sh" from terminal, it works as it should, so, probably, sudoers entry is ok.

// Edit

I've also tried to save terminal output from running desktop file, by:

Exec=sudo script.sh > /home/user/MyDocs/scriptlog.txt

(I've found it, while searching for solution - I don't know if it's right command)

...and scriptlog.txt was created, ho ever, contained nothing inside.

karam 2011-08-25 02:34

Re: dbus-send --type=method_call --dest=org.freedesktop.Notifications - problem with root privileges
 
Quote:

Originally Posted by MohammadAG (Post 1076119)
No, neither user nor "root" use run-standalone.sh, it has to do with environment variables being set in one and not the other.


hmm would you please explain more Mohammad ? didn't really get it


Quote:

Originally Posted by MohammadAG (Post 1076119)
That would also allow a sudo rm -rf /path/to/root, keeping some security on the system is saner.



ok then i see but personally never faced security problem doing that
what might happen especially for a device like N900 ?

oh and you know something i'm really happy because i see an arabic person has a great knowledge about something might be really Sophisticated for a lot of people :)


i wish you would never visit syria
you will loose your mind because of the knowledge of it's people -_-

Estel 2011-08-25 07:18

Re: dbus-send --type=method_call --dest=org.freedesktop.Notifications - problem with root privileges
 
Quote:

Originally Posted by karam (Post 1076162)
hmm would you please explain more Mohammad ? didn't really get it

He mean, that "root" doesn't call upon run-standalone.sh. You can see personally, what it's doing - open /usr/bin/root in any text editor, i.e. leafpad or nano (or vi).

Estel 2011-09-11 03:13

Re: dbus-send --type=method_call --dest=org.freedesktop.Notifications - problem with root privileges
 
Sorry for bumping, but maybe anyone have idea about it?:

Quote:

Originally Posted by Estel (Post 1076144)
Thanks for answer, ho ever, using Exec=sudo script.sh does nothing. Literally nothing, just nothing happens. That was the first thing I've tried after creating entry in sudoers.d :p I also got X-App-Loading-Image=none set.

When I execute "sudo script.sh" from terminal, it works as it should, so, probably, sudoers entry is ok.

// Edit

I've also tried to save terminal output from running desktop file, by:

Exec=sudo script.sh > /home/user/MyDocs/scriptlog.txt

(I've found it, while searching for solution - I don't know if it's right command)

...and scriptlog.txt was created, ho ever, contained nothing inside.

I just can't believe that it's not possible to set shortcut - via .desktop file - to some command that require root. Recently, I've also tried Queen BeeCon widget with command
Code:

sudo bnf.sh
, which exact same results - nothing (literally, nothing) happen when I execute it. Again, typing this manually in terminal works flawlessly.

For reference, I'm attaching actual version of script, + (more important for current problem, I think) .desktop file. Could anyone knowledgeable check it inside device? Maybe it's just "my" problem, not code problem?

Note:
Currently, there is:
Code:

Exec=sudo bnf.sh
...but I've tried also with
Code:

Exec='sudo bnf.sh'
Exec="sudo bnf.sh"
Exec=sudo 'bnf.sh'
Exec=sudo "bnf.sh"

...and every possible combination of these.

I can get it to (semi) work by:
Code:

Exec=osso-xterm -e "sudo bnf.sh"
... but that "flash" screen with terminal window poping up first, + is much slower to execute.

// Edit

Using ShortcutD, I can set:
Code:

sudo bnf.sh
...as custom command + set it for hardware button (i.e to execute, when I half-press camera button), but still no joy to make it working as desktop shortcut.

I got plans for some (maybe) useful and more complicated scripts, that would be handy with desktop shortcuts for them, but every single one require root. I have no idea why the heck it doesn't want to work with:
Exec=sudo <name>.sh

(Actual version is here:
http://talk.maemo.org/showpost.php?p...3&postcount=17)


All times are GMT. The time now is 04:04.

vBulletin® Version 3.8.8