If a user logs in via XDM, how might I get the values for $USER and $DISPLAY
as would be defined in that user's environment?
Printable View
If a user logs in via XDM, how might I get the values for $USER and $DISPLAY
as would be defined in that user's environment?
In comp.windows.x, Mike Irwin
<mike@faroutfreaky****.com>
wrote
on 09 Dec 2003 15:17:51 -0500
<878yllsq34.fsf@faroutfreaky****.com>:[color=blue]
> If a user logs in via XDM, how might I get the values for $USER and $DISPLAY
> as would be defined in that user's environment?[/color]
In what environment?
getenv("USER"), getenv("DISPLAY") works reasonably
well for C and C++ executables. Shell scripts can use
$USER and $DISPLAY. Perl scripts use $ENV{'USER'}
and $ENV{'DISPLAY'}. Tcl/TK can use $env(USER) and
$env(DISPLAY). I'd have to look up Python's notions but
there's probably a getenv() in there somewhere.
Java is a special case and probably wouldn't care about
$USER and $DISPLAY all that much anyway. :-) However,
one can use System.getProperty("user.dir") to get
a property variable that is usually (unless overridden
with the -Duser.dir=something option) the current
directory.
--
#191, [email]ewill3@earthlink.net[/email]
It's still legal to go .sigless.
The Ghost In The Machine <ewill@sirius.athghost7038suus.net> writes:
[color=blue]
> In comp.windows.x, Mike Irwin
> <mike@faroutfreaky****.com>
> wrote
> on 09 Dec 2003 15:17:51 -0500
> <878yllsq34.fsf@faroutfreaky****.com>:[color=green]
> > If a user logs in via XDM, how might I get the values for $USER and
> > $DISPLAY as would be defined in that user's environment?[/color]
>
> In what environment?
>
> getenv("USER"), getenv("DISPLAY") works reasonably
> well for C and C++ executables. Shell scripts can use
> $USER and $DISPLAY. Perl scripts use $ENV{'USER'}
> and $ENV{'DISPLAY'}. Tcl/TK can use $env(USER) and
> $env(DISPLAY). I'd have to look up Python's notions but
> there's probably a getenv() in there somewhere.
>
> Java is a special case and probably wouldn't care about
> $USER and $DISPLAY all that much anyway. :-) However,
> one can use System.getProperty("user.dir") to get
> a property variable that is usually (unless overridden
> with the -Duser.dir=something option) the current
> directory.[/color]
I should've been more clear on this. I meant if a user logs in via XDM on a
Linux machine, how might I obtain the user's ID and the value of $DISPLAY from
a script which is not run as the same user.
In comp.windows.x, Mike Irwin
<mike@faroutfreaky****.com>
wrote
on 22 Dec 2003 04:45:48 -0500
<877k0pi3sj.fsf@faroutfreaky****.com>:[color=blue]
> The Ghost In The Machine <ewill@sirius.athghost7038suus.net> writes:
>[color=green]
>> In comp.windows.x, Mike Irwin
>> <mike@faroutfreaky****.com>
>> wrote
>> on 09 Dec 2003 15:17:51 -0500
>> <878yllsq34.fsf@faroutfreaky****.com>:[color=darkred]
>> > If a user logs in via XDM, how might I get the values for $USER and
>> > $DISPLAY as would be defined in that user's environment?[/color]
>>
>> In what environment?
>>
>> getenv("USER"), getenv("DISPLAY") works reasonably
>> well for C and C++ executables. Shell scripts can use
>> $USER and $DISPLAY. Perl scripts use $ENV{'USER'}
>> and $ENV{'DISPLAY'}. Tcl/TK can use $env(USER) and
>> $env(DISPLAY). I'd have to look up Python's notions but
>> there's probably a getenv() in there somewhere.
>>
>> Java is a special case and probably wouldn't care about
>> $USER and $DISPLAY all that much anyway. :-) However,
>> one can use System.getProperty("user.dir") to get
>> a property variable that is usually (unless overridden
>> with the -Duser.dir=something option) the current
>> directory.[/color]
>
> I should've been more clear on this. I meant if a user logs in
> via XDM on a Linux machine, how might I obtain the user's ID
> and the value of $DISPLAY from a script which is not run as
> the same user.[/color]
Is this script run by the user or by a daemon?
If it's run by the user, that's not too difficult. If a
daemon has to figure it out, the daemon could use /proc or
ps if it knows the process ID, to get the user ID. I'm not
sure how to get at $DISPLAY (the user may be logging in
from a different computer using XDMCP), and there's the
problem of the xauth authorization key ('man xauth').
If the script is root-based it might be able to get the
key if the user's home directory is not NFS-mounted.
If it is NFS-mounted the script may be out of luck; root
only is the local superuser.
--
#191, [email]ewill3@earthlink.net[/email]
It's still legal to go .sigless.
The Ghost In The Machine <ewill@sirius.athghost7038suus.net> writes:
[color=blue]
> In comp.windows.x, Mike Irwin
> <mike@faroutfreaky****.com>
> wrote[color=green]
>>
>> I should've been more clear on this. I meant if a user logs in
>> via XDM on a Linux machine, how might I obtain the user's ID
>> and the value of $DISPLAY from a script which is not run as
>> the same user.[/color]
>
> Is this script run by the user or by a daemon?
>
> If it's run by the user, that's not too difficult. If a
> daemon has to figure it out, the daemon could use /proc or
> ps if it knows the process ID, to get the user ID. I'm not
> sure how to get at $DISPLAY[/color]
For every process there is a file /proc/<pid>/environ that
consists of the environment of the process. You can easily extract the
value of DISPLAY from there. If the script is run as root that is...
--
- Mårten
mail: [email]msv@kth.se[/email] *** ICQ: 4356928 *** mobile: +46 (0)707390385
[email]f95-msv@f.kth.se[/email] (Mårten Svantesson) writes:
[color=blue]
> The Ghost In The Machine <ewill@sirius.athghost7038suus.net> writes:
>[color=green]
> > In comp.windows.x, Mike Irwin
> > <mike@faroutfreaky****.com>
> > wrote[color=darkred]
> >>
> >> I should've been more clear on this. I meant if a user logs in
> >> via XDM on a Linux machine, how might I obtain the user's ID
> >> and the value of $DISPLAY from a script which is not run as
> >> the same user.[/color]
> >
> > Is this script run by the user or by a daemon?
> >
> > If it's run by the user, that's not too difficult. If a
> > daemon has to figure it out, the daemon could use /proc or
> > ps if it knows the process ID, to get the user ID. I'm not
> > sure how to get at $DISPLAY[/color]
>
> For every process there is a file /proc/<pid>/environ that
> consists of the environment of the process. You can easily extract the
> value of DISPLAY from there. If the script is run as root that is...[/color]
I was also under the impression that I could get the info I needed from the
environ file for the XDM or the X process, but missing from the list of
environment variables is USER and DISPLAY. Any other ideas?
In comp.windows.x, Mike Irwin
<mike@faroutfreaky****.com>
wrote
on 22 Dec 2003 15:32:49 -0500
<873cbcioem.fsf@faroutfreaky****.com>:[color=blue]
> [email]f95-msv@f.kth.se[/email] (Mårten Svantesson) writes:
>[color=green]
>> The Ghost In The Machine <ewill@sirius.athghost7038suus.net> writes:
>>[color=darkred]
>> > In comp.windows.x, Mike Irwin
>> > <mike@faroutfreaky****.com>
>> > wrote
>> >>
>> >> I should've been more clear on this. I meant if a user logs in
>> >> via XDM on a Linux machine, how might I obtain the user's ID
>> >> and the value of $DISPLAY from a script which is not run as
>> >> the same user.
>> >
>> > Is this script run by the user or by a daemon?
>> >
>> > If it's run by the user, that's not too difficult. If a
>> > daemon has to figure it out, the daemon could use /proc or
>> > ps if it knows the process ID, to get the user ID. I'm not
>> > sure how to get at $DISPLAY[/color]
>>
>> For every process there is a file /proc/<pid>/environ that
>> consists of the environment of the process. You can easily extract the
>> value of DISPLAY from there. If the script is run as root that is...[/color]
>
> I was also under the impression that I could get the info I needed from the
> environ file for the XDM or the X process, but missing from the list of
> environment variables is USER and DISPLAY. Any other ideas?[/color]
XDM might have DISPLAY. However, XDM will not have USER (except
perhaps a user of root), and in any event USER is not all that
useful; a far better method is to get the user-id of the process.
One can, of course, check to see who owns /proc/# to see what the
user-id is (either real or effective; I don't know which offhand).
Also, there may be multiple XDMs running, or multiple
displays running. I've done multiple displays occasionally
(although my graphics card has only 4 MB, which causes
problems if I have more than one X server up; Linux
apparently has a bug in the video drivers, or perhaps
X does).
XDMCP makes life even more interesting. I'm going to have to
experiment with that at some point (again). :-)
--
#191, [email]ewill3@earthlink.net[/email]
It's still legal to go .sigless.