Can I release a visual program on an additional customer's desktop computer as root?

Adhering to are various other inquiries which I assume I require to recognize:

  • From a non X Session? (suggesting root isn't logged right into X)

  • If numerous individuals were visited on X, could I auto-detect that got on which screen, and also hence programmatically identify which screen I require to release the application on?

  • Can I release the application as the customer? ( ok I'm 99.999% certain this is an of course )

  • Can I identify if users of team X are visited to X?

0
2019-05-04 04:34:38
Source Share
Answers: 3

I can not entirely attempt this given that all my equipments have root impaired.

To locate which present a customer gets on, you can make use of the who command. The last column of result is generally the DISPLAY that the customer is visited on. Something similar to this can be made use of to order simply the display screen (there is likely an even more reliable means to do this, do not hesitate to supply modifies ) :

who | grep -m1 ^username.*\( | awk '{print $5}' | sed 's/[(|)]//g'
.

After that to release a visual X command on that particular display screen :

DISPLAY=:0 firefox &
.

where :0 would certainly be changed with whatever present you located in the first command and also firefox would certainly be changed with whatever command you intend to run. You can place this in a covering manuscript and also simply make use of a variable.

The next component is the component I have not examined, yet I do not see why it should not be feasible to do :

su username -c "DISPLAY=:0 firefox"
.

to release the X command as that customer.

0
2019-05-07 22:16:04
Source

You can consider just how acpid does it. E.g. when it releases xscreensaver commands or spaces the screen for each and every customer running X or X-session.

As an example under Ubuntu this documents has relevant things :

/etc/acpi/lid.sh

Has this loop :

for x in /tmp/.X11-unix/*; do
    displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
    getXuser;
    if [ x"$XAUTHORITY" != x"" ]; then
        export DISPLAY=":$displaynum"
        grep -q off-line /proc/acpi/ac_adapter/*/state
        if [ $? = 1 ]
            then
            if pidof xscreensaver > /dev/null; then 
                su $user -c "xscreensaver-command -unthrottle"
            fi
        fi
        if [ x$RADEON_LIGHT = xtrue ]; then
            [ -x /usr/sbin/radeontool ] && radeontool light on
        fi
        if [ `pidof xscreensaver` ]; then
            su $user -c "xscreensaver-command -deactivate"
        fi
        su $user -c "xset dpms force on"
    fi
done
0
2019-05-07 22:07:13
Source

To release a visual program on a customer's desktop computer, you require to locate 2 points : what present the customer's desktop computer gets on (the address ) and also what consent cookie to make use of (the password ).

The adhering to command needs to detail the neighborhood display screens that the customer is browsed through (one per line ) on the majority of unices :

who | awk -v user="$target_user" '$1 == user && $2 ~ "^:" {print $2}'

Locating the consent cookie is a little tougher. You need to seek the customer's cookie file, which is ~/.Xauthority by default (all you require is the area of the cookie file, you do not require to extract the cookie from it ). That works with several systems, yet not all; it relies on the display screen supervisor and also just how it's set up, and also specifically Gdm (the default on Ubuntu ) did not make use of the default area last I looked. I can not consider a mobile means to figure out the real X cookie file. One of the most exact means to figure out is to figure out the pid of the X procedure and also seek the argument to the -auth alternative. An additional means is to locate a procedure working on that X web server and also order its XAUTHORITY environemnt variable. If you have problem locating the cookie file, see Open a window on a remote X display (why "Cannot open display")?

Once you have both items of details, placed the picked display screen in the DISPLAY setting variable, the picked X authority cookie file in the XAUTHORITY setting variable, and also you're set. No matter what customer the program runs as; incorporate with su if you such as.

0
2019-05-07 19:11:13
Source