LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-25-2011, 05:06 AM   #1
nagendrar
Member
 
Registered: Apr 2008
Location: HYD, INDIA.
Posts: 151

Rep: Reputation: 15
API to know who made changes to a file on linux using 'C' or C++


Please help me to provide the API to know who made changes to a file on linux using 'C' or C++

Thanks,
Nagendra
 
Old 05-25-2011, 06:49 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,533

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
You can use the stat() library function to deduce information about a particular file. Although this function is useful to determine the owner/group associated with the file, I do not believe there is anything that will tell you as to what user in a group, if the file permissions permit it, last modified the file.

For more info on stat(), reference the man-page:
Code:
man 2 stat
 
Old 05-25-2011, 12:26 PM   #3
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946
Quote:
Originally Posted by nagendrar View Post
Please help me to provide the API to know who made changes to a file on linux using 'C' or C++
You need to monitor the changes while they happen, of course. We don't have time machines, yet.

If you are only interested in being notified of changes, use the inotify interface.

If you wish to audit changes -- say, you need to e.g. take a backup of a file before someone opens it for read-write or truncates it, therefore delaying the opener for a bit --, you need to use the Linux kernel audit subsystem. See audit_open, audit_add_rule and so on for details.

Note that either one of these is simpler to implement using shell scripts (inotify via inotifytools package, especially the inotifywait command, and audit via auditd package, especially the auditctl command. The C interfaces above require you to use low-level (netlink) sockets and I/O, possibly signals too; standard libraries like stdio won't help you with those.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C API to check if file has a link or not barunparichha Linux - Software 4 07-16-2009 08:22 AM
file operations API for Device driver gilh Programming 1 06-04-2009 05:22 AM
java API for basic remote file system operations foampile Linux - Newbie 1 02-27-2009 12:25 AM
LXer: Linux audit files to see who made changes to a file LXer Syndicated Linux News 0 03-21-2007 01:33 AM
LXer: Linux needs file-scanning API on kernel like it's 1996 LXer Syndicated Linux News 0 10-23-2006 02:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration