How to find username who has accessed my file - Linux

This is a discussion on How to find username who has accessed my file - Linux ; Hi , Is there any wayout to find the username who has access my file in a kernel module ? Thanks in advance, Ashish...

+ Reply to Thread
Results 1 to 16 of 16

Thread: How to find username who has accessed my file

  1. How to find username who has accessed my file

    Hi ,

    Is there any wayout to find the username who has access my file in a
    kernel module ?

    Thanks in advance,
    Ashish

  2. Re: How to find username who has accessed my file

    On Dec 19, 6:13 am, Ashish Kumar wrote:

    >
    > Is there any wayout to find the username who has access my file in a
    > kernel module ?


    Are you talking about a user who is running a process that
    makes a call into your kernel module() to access a file?
    If so, try getuid()/geteuid().

    If you are talking about trying to find out who has read one
    of the source files for a kernel module, I don't believe that
    is in general possible.


  3. Re: How to find username who has accessed my file

    On Dec 19, 11:34 am, William Pursell wrote:
    > On Dec 19, 6:13 am, Ashish Kumar wrote:
    >
    >
    >
    > > Is there any wayout to find the username who has access my file in a
    > > kernel module ?

    >
    > Are you talking about a user who is running a process that
    > makes a call into your kernel module() to access a file?
    > If so, try getuid()/geteuid().
    >
    > If you are talking about trying to find out who has read one
    > of the source files for a kernel module, I don't believe that
    > is in general possible.


    Thanks for reply William.
    user id i got simply putting current ->uid in my open call of module.
    But now looking how to get username from this uid.

    Regards,
    Ashish

  4. Re: How to find username who has accessed my file

    Ashish Kumar wrote:

    > Thanks for reply William.
    > user id i got simply putting current ->uid in my open call of module.
    > But now looking how to get username from this uid.


    The kernel knows nothing about usernames, it only uses user IDs.
    You'll have to check /etc/passwd in userland to find the name.

    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Mllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html


  5. Re: How to find username who has accessed my file

    On Dec 19, 3:21 pm, Josef Moellers siemens.com> wrote:
    > Ashish Kumar wrote:
    > > Thanks for reply William.
    > > user id i got simply putting current ->uid in my open call of module.
    > > But now looking how to get username from this uid.

    >
    > The kernel knows nothing about usernames, it only uses user IDs.
    > You'll have to check /etc/passwd in userland to find the name.
    >
    > --
    > These are my personal views and not those of Fujitsu Siemens Computers!
    > Josef Mllers (Pinguinpfleger bei FSC)
    > If failure had no penalty success would not be a prize (T. Pratchett)
    > Company Details:http://www.fujitsu-siemens.com/imprint.html


    Thanks Joseph,

    -Ashish

  6. Re: How to find username who has accessed my file

    On Dec 19, 4:19 pm, Ashish Kumar wrote:
    > On Dec 19, 3:21 pm, Josef Moellers >
    > siemens.com> wrote:
    > > Ashish Kumar wrote:
    > > > Thanks for reply William.
    > > > user id i got simply putting current ->uid in my open call of module.
    > > > But now looking how to get username from this uid.

    >
    > > The kernel knows nothing about usernames, it only uses user IDs.
    > > You'll have to check /etc/passwd in userland to find the name.

    >
    > > --
    > > These are my personal views and not those of Fujitsu Siemens Computers!
    > > Josef Mllers (Pinguinpfleger bei FSC)
    > > If failure had no penalty success would not be a prize (T. Pratchett)
    > > Company Details:http://www.fujitsu-siemens.com/imprint.html

    >
    > Thanks Joseph,
    >
    > -Ashish


    I want to send uid to userspace and then i want to use function
    getpwuid to get the username out of that uid.
    But now the problem is,
    I am using copy_to_user in my read() of kernel module.
    copy_to_user copies data into a character buffer.Here uid i get as an
    integer.
    I am not getting any kernel api to convert integer into string.
    Is there any kernel api that converts int into string?
    Or shall i use something else other than copy_to_user() ?
    Pls, suggest..

    Regards,
    Ashish

  7. Re: How to find username who has accessed my file

    Ashish Kumar wrote:
    > On Dec 19, 4:19 pm, Ashish Kumar wrote:
    >
    >>On Dec 19, 3:21 pm, Josef Moellers >>
    >>siemens.com> wrote:
    >>
    >>>Ashish Kumar wrote:
    >>>
    >>>>Thanks for reply William.
    >>>>user id i got simply putting current ->uid in my open call of module.
    >>>>But now looking how to get username from this uid.

    >>
    >>>The kernel knows nothing about usernames, it only uses user IDs.
    >>>You'll have to check /etc/passwd in userland to find the name.

    >>
    >>>--
    >>>These are my personal views and not those of Fujitsu Siemens Computers!
    >>>Josef Mllers (Pinguinpfleger bei FSC)
    >>> If failure had no penalty success would not be a prize (T. Pratchett)
    >>>Company Details:http://www.fujitsu-siemens.com/imprint.html

    >>
    >>Thanks Joseph,
    >>
    >>-Ashish

    >
    >
    > I want to send uid to userspace and then i want to use function
    > getpwuid to get the username out of that uid.
    > But now the problem is,
    > I am using copy_to_user in my read() of kernel module.
    > copy_to_user copies data into a character buffer.Here uid i get as an
    > integer.
    > I am not getting any kernel api to convert integer into string.
    > Is there any kernel api that converts int into string?
    > Or shall i use something else other than copy_to_user() ?
    > Pls, suggest..


    Since both, the kernel and the user space program run on the same
    hardware, they both use the same endianness, so you can just cast the
    address of the integer into a pointer to a character and use that to
    copy the appropriate number of bytes into the user buffer. In userland
    you just do the opposite and you should be fine.

    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Mllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html


  8. Re: How to find username who has accessed my file

    On Dec 19, 9:45 pm, Ashish Kumar wrote:

    > I am not getting any kernel api to convert integer into string.


    What makes you think it's a string?

    > Is there any kernel api that converts int into string?
    > Or shall i use something else other than copy_to_user() ?
    > Pls, suggest..


    You seem to have some serious misconceptions about some very basic C
    concepts and the basics of kernel/user interaction. Are you sure you
    should be writing kernel code? If you don't even understand how
    integers are passed between user space and kernel code from the user
    side, you have no business writing kernel code.

    DS

  9. Re: How to find username who has accessed my file

    On Dec 20, 12:59 pm, Josef Moellers siemens.com> wrote:
    > Ashish Kumar wrote:
    > > On Dec 19, 4:19 pm, Ashish Kumar wrote:

    >
    > >>On Dec 19, 3:21 pm, Josef Moellers

    >
    > >>siemens.com> wrote:

    >
    > >>>Ashish Kumar wrote:

    >
    > >>>>Thanks for reply William.
    > >>>>user id i got simply putting current ->uid in my open call of module.
    > >>>>But now looking how to get username from this uid.

    >
    > >>>The kernel knows nothing about usernames, it only uses user IDs.
    > >>>You'll have to check /etc/passwd in userland to find the name.

    >
    > >>>--
    > >>>These are my personal views and not those of Fujitsu Siemens Computers!
    > >>>Josef Mllers (Pinguinpfleger bei FSC)
    > >>> If failure had no penalty success would not be a prize (T. Pratchett)
    > >>>Company Details:http://www.fujitsu-siemens.com/imprint.html

    >
    > >>Thanks Joseph,

    >
    > >>-Ashish

    >
    > > I want to send uid to userspace and then i want to use function
    > > getpwuid to get the username out of that uid.
    > > But now the problem is,
    > > I am using copy_to_user in my read() of kernel module.
    > > copy_to_user copies data into a character buffer.Here uid i get as an
    > > integer.
    > > I am not getting any kernel api to convert integer into string.
    > > Is there any kernel api that converts int into string?
    > > Or shall i use something else other than copy_to_user() ?
    > > Pls, suggest..

    >
    > Since both, the kernel and the user space program run on the same
    > hardware, they both use the same endianness, so you can just cast the
    > address of the integer into a pointer to a character and use that to
    > copy the appropriate number of bytes into the user buffer. In userland
    > you just do the opposite and you should be fine.
    >
    > --
    > These are my personal views and not those of Fujitsu Siemens Computers!
    > Josef Mllers (Pinguinpfleger bei FSC)
    > If failure had no penalty success would not be a prize (T. Pratchett)
    > Company Details:http://www.fujitsu-siemens.com/imprint.html


    Thanks Joseph,

  10. Re: How to find username who has accessed my file

    On Dec 21, 6:48*am, David Schwartz wrote:
    > On Dec 19, 9:45 pm, Ashish Kumar wrote:
    >
    > > I am not getting any kernel api to convert integer into string.

    >
    > What makes you think it's a string?


    copy_to_user() takes string as an outparam.
    >
    > > Is there any kernel api that converts int into string?
    > > Or shall i use something else other than copy_to_user() ?
    > > Pls, suggest..

    >
    > You seem to have some serious misconceptions about some very basic C
    > concepts and the basics of kernel/user interaction.


    Yes , I am not very good in C basics, i have lot to work on them.

    Are you sure you should be writing kernel code? If you don't even
    understand how
    > integers are passed between user space and kernel code from the user
    > side, you have no business writing kernel code.



    I work on my own home pc on linux kernel (open source) ... I dont
    think that I am
    doing anything that is illegal or that can harm somebody in anyway.
    I am just trying to learn on my own .
    So, I dont think that you or anyone should have any problem with that.
    You might be a good techie but from your above comments you really
    proved that
    you are a very cheap human being .

    >
    > DS



  11. Re: How to find username who has accessed my file

    On Tue, 25 Dec 2007 03:22:07 -0800, Ashish Kumar wrote:

    [...]

    > I work on my own home pc on linux kernel (open source) ... I dont
    > think that I am
    > doing anything that is illegal or that can harm somebody in anyway.
    > I am just trying to learn on my own .
    > So, I dont think that you or anyone should have any problem with that.
    > You might be a good techie but from your above comments you really
    > proved that
    > you are a very cheap human being .


    What he means, is that you're trying to progress without learning basics.
    No one has any problems with the way you learn, but it'll be a waste of
    your time, so try to understand how things in userspace work, what're
    algorithms, whats libc, etc. So work on your basic concepts first.
    Understand how things work, use your brain .

    >
    >>
    >> DS


    HTH
    --
    Ashish Shukla आशीष शुक्ल http://wahjava.wordpress.com/
    ·-- ·- ···· ·--- ·- ···- ·- ·--·-· --· -- ·- ·· ·-·· ·-·-·- -·-· --- --


  12. Re: How to find username who has accessed my file

    On 2007-12-25, Ashish Shukla ???? ????? wrote:
    > On Tue, 25 Dec 2007 03:22:07 -0800, Ashish Kumar wrote:
    >
    > [...]
    >
    >> I work on my own home pc on linux kernel (open source) ... I dont
    >> think that I am
    >> doing anything that is illegal or that can harm somebody in anyway.
    >> I am just trying to learn on my own .
    >> So, I dont think that you or anyone should have any problem with that.
    >> You might be a good techie but from your above comments you really
    >> proved that
    >> you are a very cheap human being .

    >
    > What he means, is that you're trying to progress without learning basics.
    > No one has any problems with the way you learn, but it'll be a waste of
    > your time, so try to understand how things in userspace work, what're
    > algorithms, whats libc, etc. So work on your basic concepts first.


    You definitely want a good understanding of C programming
    before you start messing around with kernel code. Kernel code
    isn't easy to debug. That means you need to be able to write
    things correctly on the first try.

    --
    Grant


  13. Re: How to find username who has accessed my file

    Grant Edwards writes:
    > On 2007-12-25, Ashish Shukla ???? ????? wrote:
    >> On Tue, 25 Dec 2007 03:22:07 -0800, Ashish Kumar wrote:


    [...]

    > You definitely want a good understanding of C programming
    > before you start messing around with kernel code.


    It would certainly help. But for simple things, the in-kernel
    'programming situation' isn't much different from that of older 'home
    computers' or DOS PCs.

    > Kernel code isn't easy to debug.


    There is one part of the kernel which is not easy to debug
    and that is the MMU initialization code, because an error
    in there will usually result in a state where console
    output isn't possible anymore. This means assumptions about the code
    can only be tested by writing assembly code (usually) to test
    them and cause some observable effect (eg light an LED by GPIO),
    depending on what the findings were. Not exactly enjoyable, but
    certainly possible (I had the mispleasure when 'porting' the Linux
    tree 'we' use to the 'second generation appliance boards', which
    have an IXP420 processor I wanted to run in data-coherent litte-endian
    mode so that it would be compatible with our existing hardware
    and the NIC driver can use the byteswapping hardware being part of
    the core instead fo byteswapping all frames in software, which ARM
    Linux does not support and likely never will because doing so needs
    architecture specific MMU setup code and Such A Thing Must Not Be As
    Commanded By The King[*]).
    [*] If you per chance feel the burning desire to flame me
    because The King Must Not Be Criticized (has actually happened
    :->), rest assured that I am only polite to people
    significantly more stupid than me as long as they don't
    intentionally try get onto my nerves.

    > That means you need to be able to write things correctly on the
    > first try.


    How is one supposed to know what is correct without trying? Nobody
    ever knowingly writes buggy code (idealized assumption).



  14. Re: How to find username who has accessed my file

    On Dec 26, 1:16*am, Ashish Shukla आशीष शुक्ल
    wrote:
    > On Tue, 25 Dec 2007 03:22:07 -0800, Ashish Kumar wrote:
    >
    > [...]
    >
    > > I work on my own home pc on linux kernel (open source) ... I dont
    > > think that I am
    > > doing anything that is illegal or that can harm somebody in anyway.
    > > I am just trying to learn on my own .
    > > So, I dont think that you or anyone should have any problem with that.
    > > You might be a good techie but from your above comments you really
    > > proved that
    > > you are a very cheap human being .

    >
    > What he means, is that you're trying to progress without learning basics.
    > No one has any problems with the way you learn, but it'll be a waste of
    > your time, so try to understand how things in userspace work, what're
    > algorithms, whats libc, etc. So work on your basic concepts first.
    > Understand how things work, use your brain .
    >
    >
    >
    > >> DS

    >
    > HTH
    > --
    > Ashish Shukla आशीष शुक्ल * * * * * * * * * * *http://wahjava.wordpress.com/
    > ·-- ·- ···· ·--- ·- ···- ·- ·--·-· --· -- ·- ·· ·-·· ·-·-·- -·-· --- --


    Dude i know very well what i need to do .
    I have come here and posted my problem just to get few ideas from good
    people so that i can proceed further and try to understand things.
    Nobody has any right to dicourage anyone in such a way.
    Do you think that you know all and you were born with all that
    knowledge?
    If you dont like my queries , simply ignore it but you dont have any
    right to be judgemental on me.
    And what i am asking is not very basic as well....

  15. Re: How to find username who has accessed my file

    * Ashish Kumar fired off this tart reply:

    >> --
    >> Ashish Shukla ???? ????? * * * * * * * * * * *http://wahjava.wordpress.com/
    >> -- - --- - - - --- -- -- - - --- -- --- --


    That last line made me think mrxvt had a bug in its screen rendering!

    --
    Tux rox!

  16. Re: How to find username who has accessed my file

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    ,--- Ashish Kumar writes:

    [snipped]

    | Dude i know very well what i need to do .
    | I have come here and posted my problem just to get few ideas from good
    | people so that i can proceed further and try to understand things.
    | Nobody has any right to dicourage anyone in such a way.

    He's not discouraging you but making aware of reality. RTFMing is not
    discouraging .

    | Do you think that you know all and you were born with all that
    | knowledge?

    No I didn't think that, I learnt most of the stuff by experimentation,
    using *common sense* and I'm still following that strategy, reading
    docs etc. Here you're doing experimentation but probably not reading
    docs, not using common sense.

    | If you dont like my queries , simply ignore it but you dont have any
    | right to be judgemental on me.

    I've right to judge whomever I wanted to...

    | And what i am asking is not very basic as well....

    What you're asking is not basic, but it is just that you didn't
    have basics.

    You asked for some kernel API converting int into string. This is
    silly. In reality there is no string, everything is buffer of
    bytes. You call some buffer, a 'string', because bytes in that
    buffer has some 'characters' associated with them.

    Anyways, all you need to pass an 'integer' from one domain to another, in
    some buffer, is following:


    1. Simply copy your variable to buffer in source domain:

    *((int *)buffer) = variable;

    2. Since your destination domain is on same box, so same architecture, so
    you can simply type-cast:

    variable = *((int *)buffer);

    If your domains are of different architectures (i.e. different
    byteorders), then you need to change the byteorder of the variable,
    either after reading or before writing. I hope you've heard of use of
    big-endian byte order on networks

    References:
    Marshalling - http://en.wikipedia.org/wiki/Marshalling

    HTH
    - --
    Ashish Shukla आशीष शुक्ल http://wahjava.wordpress.com/
    ·-- ·- ···· ·--- ·- ···- ·- ·--·-· --· -- ·- ·· ·-·· ·-·-·- -·-· --- --
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.6 (GNU/Linux)

    iD8DBQFHcpUAHy+EEHYuXnQRAs7kAKDbBrXMf29D+/JPZ1HmNykZ3lunoQCg4Qve
    TOuIFjA+F9Bp5hBaVdSWwbg=
    =taEm
    -----END PGP SIGNATURE-----