XDM and environment variables - Xwindows

This is a discussion on XDM and environment variables - Xwindows ; 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?...

+ Reply to Thread
Results 1 to 7 of 7

Thread: XDM and environment variables

  1. XDM and environment variables

    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?

  2. Re: XDM and environment variables

    In comp.windows.x, Mike Irwin

    wrote
    on 09 Dec 2003 15:17:51 -0500
    <878yllsq34.fsf@faroutfreaky****.com>:
    > 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 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, ewill3@earthlink.net
    It's still legal to go .sigless.

  3. Re: XDM and environment variables

    The Ghost In The Machine writes:

    > In comp.windows.x, Mike Irwin
    >
    > wrote
    > on 09 Dec 2003 15:17:51 -0500
    > <878yllsq34.fsf@faroutfreaky****.com>:
    > > 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 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.


    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.

  4. Re: XDM and environment variables

    In comp.windows.x, Mike Irwin

    wrote
    on 22 Dec 2003 04:45:48 -0500
    <877k0pi3sj.fsf@faroutfreaky****.com>:
    > The Ghost In The Machine writes:
    >
    >> In comp.windows.x, Mike Irwin
    >>
    >> wrote
    >> on 09 Dec 2003 15:17:51 -0500
    >> <878yllsq34.fsf@faroutfreaky****.com>:
    >> > 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 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.

    >
    > 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 (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, ewill3@earthlink.net
    It's still legal to go .sigless.

  5. Re: XDM and environment variables

    The Ghost In The Machine writes:

    > In comp.windows.x, Mike Irwin
    >
    > 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


    For every process there is a file /proc//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: msv@kth.se *** ICQ: 4356928 *** mobile: +46 (0)707390385

  6. Re: XDM and environment variables

    f95-msv@f.kth.se (Mårten Svantesson) writes:

    > The Ghost In The Machine writes:
    >
    > > In comp.windows.x, Mike Irwin
    > >
    > > 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

    >
    > For every process there is a file /proc//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...


    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?

  7. Re: XDM and environment variables

    In comp.windows.x, Mike Irwin

    wrote
    on 22 Dec 2003 15:32:49 -0500
    <873cbcioem.fsf@faroutfreaky****.com>:
    > f95-msv@f.kth.se (Mårten Svantesson) writes:
    >
    >> The Ghost In The Machine writes:
    >>
    >> > In comp.windows.x, Mike Irwin
    >> >
    >> > 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

    >>
    >> For every process there is a file /proc//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...

    >
    > 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?


    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, ewill3@earthlink.net
    It's still legal to go .sigless.

+ Reply to Thread