Jump to content

Drop root privileges from bash


Recommended Posts

i have a script that is running root (usb-storage script) i know that everything is mounted on mandrake but i'm trying to output a message to the user of course WITHOUT ROOT privileges (to reduce the possibility of having a user to run process a root) and to have the same config and skin than the current user here my exemple:

i'm on kde 3.3

     script thing 
  ....
  dropping root privilege to current user
./kdialog --title "New Usb-Storage found" --passivepopup \
"is avaible in /mnt" 10

 

i know i'm not clear but any idea will help me a lot

Link to comment
Share on other sites

Hi

Some way

...

#build kdialog command file

echo "#!/bin/sh" > /tmp/kdialog_cmd

echo "/usr/kde/3.3/bin/kdialog --title test --msgbox test &" >> /tmp/kdialog_cmd

chmod a+x /tmp/kdialog_cmd

# run kdialog command file as some-user

su - some-user -c /tmp/kdialog_cmd

...

hih

Link to comment
Share on other sites

Hi

 

"but my root is not able to connect o X server"

Good. In X while root is risky/happy-sitting-duck!

Don't do this!!

(cut off www if unprotected &| paranoid)

(then give root X permision)

cp /home/$USER/.Xauthority /root as root

check root $DISPLAY value

(should be same as echo $USER when $USER)

 

"so i cannot see the dialog box"

Doe's this work?

Alt/F2 kdialog --title test --msgbox test

0 problems here.

 

I thought the idea was to run kdialog with non root priviledges!

My little script work's here.

(Maybe try it stanalone say as test.sh first)

 

Please post your shell script.

Maybe somebody will pick up something?

Link to comment
Share on other sites

Hi

 

"but my root is not able to connect o X server"

Good. In X while root is risky/happy-sitting-duck!

Don't do this!!

(cut off www if unprotected &| paranoid)

(then give root X permision)

cp /home/$USER/.Xauthority /root as root

check root $DISPLAY value

(should be same as echo $USER when $USER)

 

"so i cannot see the dialog box"

Doe's this work?

Alt/F2 kdialog --title test --msgbox test

0 problems here.

 

I thought the idea was to run kdialog with non root priviledges!

My little script work's here.

(Maybe try it stanalone say as test.sh first)

 

Please post your shell script.

Maybe somebody will pick up something?

 

 

ok here is my output :

root@timon:/tmp# ./test.sh
Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified

xhost:  unable to open display ":0.0"
kwrite: cannot connect to X server

 

and here is the content of my file:

cat test.sh
#build kdialog command file
export DISPLAY=":0.0"
echo "#!/bin/sh" > /tmp/kdialog_cmd
xhost +
echo "kwrite" >> /tmp/kdialog_cmd
chmod a+x /tmp/kdialog_cmd
# run kdialog command file as some-user
su - frank -c /tmp/kdialog_cmd

 

and yer alt f2 give me the dialog ;)

 

thanks again for your help :)

Link to comment
Share on other sites

and if i set comment the xhost and the export display it still says:

 

./test.sh
kwrite: cannot connect to X server

 

and the file is this

 

#build kdialog command file
#export DISPLAY=":0.0"
echo "#!/bin/sh" > /tmp/kdialog_cmd
#xhost +
echo "kwrite" >> /tmp/kdialog_cmd
chmod a+x /tmp/kdialog_cmd
# run kdialog command file as some-user
su - frank -c /tmp/kdialog_cmd

Link to comment
Share on other sites

i GOT IT i have changedyour last line

 su - frank -c /tmp/kdialog_cmd

 

to

 su frank -c /tmp/kdialog_cmd

 

because the dash in su remove all variables exported so this is why :)

 

thank you for your help , now i only have to know wich user have cause my deamon to start :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...