Getting the current user from a kernel module - Questions

This is a discussion on Getting the current user from a kernel module - Questions ; I am trying to get the current user from a loader module and don't know how. Is it possible to read user environment variables in a kernel module? Thanks for your time. George Beavers...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Getting the current user from a kernel module

  1. Getting the current user from a kernel module

    I am trying to get the current user from a loader module and don't
    know how. Is it possible to read user environment variables in a
    kernel module?

    Thanks for your time.

    George Beavers

  2. Re: Getting the current user from a kernel module

    On 7 Jan 2004 10:02:00 -0800, George Beavers wrote:
    > I am trying to get the current user from a loader module and don't
    > know how. Is it possible to read user environment variables in a
    > kernel module?


    I like those kinds of coding mistakes. If I set LOGNAME or USER = root
    do I get privs.

    Try this
    man -k uid | grep get | grep "(2)"

  3. Re: Getting the current user from a kernel module


    "George Beavers" wrote in message
    news:f41a2e32.0401071002.57d7cc3@posting.google.co m...
    > I am trying to get the current user from a loader module and don't
    > know how.


    Well the "current user" ? you mean the the user who is currently typing ?
    what do you mean ?

    I think you mean, you want the user id of the process that invoked the call
    to the kernel.
    the kernel will have to have recorded the info you want already.
    so you just need to find it in the data structures.. the dev datastructure,
    following allowing to the file handles, and the ioctls...



    > Is it possible to read user environment variables in a
    > kernel module?


    well yes, but you wouldnt want to. you cant trust it.
    Thats information that is being told to shells by the system. its not meant
    for the shell to tell the system (wrong direction).




  4. Re: Getting the current user from a kernel module

    Thanks for responding.

    My problem is this.

    Others have developed a kernel module that uses a call to open_exec.
    The parameter to open_exec is a filename. What is desired is that the
    executable file be taken from a mounted directory which is different
    for each user. I can derive the directory name from the user name.
    However, I don't have the user name, so I am stuck.

    "Leon." wrote in message news:<3ffc9123@news.rivernet.com.au>...
    > "George Beavers" wrote in message
    > news:f41a2e32.0401071002.57d7cc3@posting.google.co m...
    > > I am trying to get the current user from a loader module and don't
    > > know how.

    >
    > Well the "current user" ? you mean the the user who is currently typing ?
    > what do you mean ?
    >
    > I think you mean, you want the user id of the process that invoked the call
    > to the kernel.
    > the kernel will have to have recorded the info you want already.
    > so you just need to find it in the data structures.. the dev datastructure,
    > following allowing to the file handles, and the ioctls...
    >
    >
    >
    > > Is it possible to read user environment variables in a
    > > kernel module?

    >
    > well yes, but you wouldnt want to. you cant trust it.
    > Thats information that is being told to shells by the system. its not meant
    > for the shell to tell the system (wrong direction).


  5. Re: Getting the current user from a kernel module

    George Beavers wrote:
    > Others have developed a kernel module that uses a call to open_exec.
    > The parameter to open_exec is a filename. What is desired is that the
    > executable file be taken from a mounted directory which is different
    > for each user. I can derive the directory name from the user name.
    > However, I don't have the user name, so I am stuck.


    $set|grep kevin
    HISTFILE=/home/kevin/.bash_history
    HOME=/home/kevin
    LOGNAME=kevin
    MAIL=/var/spool/mail/kevin
    PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/kevin/bin:/usr/sbin
    PWD=/home/kevin
    USER=kevin
    XAUTHORITY=/home/kevin/.Xauthority

    $man getenv


    Simple code snippet:

    char *username;

    username = getenv( "USER" );
    /* or */
    username = getenv( "LOGNAME" );
    /* or if this directory is relative to the user's home */
    username = getenv( "HOME" );
    /* or you could require an environment variable to be set
    with the entire path you need */
    username = getenv( "SPECIALPATH" );

    YMMV.


  6. Re: Getting the current user from a kernel module

    Thanks for responding.
    However, I cannot use getenv from a kernel module.

    "Kevin D. Snodgrass" wrote in message news:<3FFDA0BE.1040501@spamcop.net>...
    > George Beavers wrote:
    > > Others have developed a kernel module that uses a call to open_exec.
    > > The parameter to open_exec is a filename. What is desired is that the
    > > executable file be taken from a mounted directory which is different
    > > for each user. I can derive the directory name from the user name.
    > > However, I don't have the user name, so I am stuck.

    >
    > $set|grep kevin
    > HISTFILE=/home/kevin/.bash_history
    > HOME=/home/kevin
    > LOGNAME=kevin
    > MAIL=/var/spool/mail/kevin
    > PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/kevin/bin:/usr/sbin
    > PWD=/home/kevin
    > USER=kevin
    > XAUTHORITY=/home/kevin/.Xauthority
    >
    > $man getenv
    >
    >
    > Simple code snippet:
    >
    > char *username;
    >
    > username = getenv( "USER" );
    > /* or */
    > username = getenv( "LOGNAME" );
    > /* or if this directory is relative to the user's home */
    > username = getenv( "HOME" );
    > /* or you could require an environment variable to be set
    > with the entire path you need */
    > username = getenv( "SPECIALPATH" );
    >
    > YMMV.


  7. Re: Getting the current user from a kernel module

    George Beavers wrote:
    > Thanks for responding.
    > However, I cannot use getenv from a kernel module.


    You allow Joe Average User to load/unload kernel modules? I
    see security issues in your future...

    I've never written a kernel module, so I don't know what is
    possible and what isn't. Can you pass args like with a
    normal prog? If so have a shell script do something like:

    modprobe mymodule $USER

    Can you get the full path as argv[0]? Make symbolic links
    to your module with each user's name as the new link name.


    BTW, I am assuming you can't use the simple getuid() or
    geteuid() functions.


+ Reply to Thread