File opening

This is a discussion on File opening within the C Programming forums, part of the General Programming Boards category; I seem to be a bit stuck on exactly how fopen works (this is in a Linux environment - I'm ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    111

    File opening

    I seem to be a bit stuck on exactly how fopen works (this is in a Linux environment - I'm not sure if it's different from Windows in this regard).

    I'm using this simple code bit:
    Code:
    if (fp = fopen("./eicar.com", "a+"))
         prinft("Success!\n");
    else
         printf("Failed.\n");
    Now, when specifying a file owned by root (not accessbile for the user running the program), the if statement works, and the result is "Failed." Changing ownership of the file to the running user results in "Success". So, this seems to work as basic as possible on files which are accessible/inaccesible due to ownership.

    However, when it comes to file scanners (anti-virus/malware scanners), I cannot get it to work the same way. I'm using an "on-access" scanner which, as far as I know, uses fuse to access the file system real-time.

    When I try to open a malware sample (Eicar, the standard test sample for all anti-malware engines) with f.ex. vim, or gedit (LInux notepad look-alike), the scanner stops it and I get "Access denied". However, when running the program with the above C code on the file, it returns "Success". So, for some reason, fopen can open a file which the file system denies access to for other applications.

    So, my question is: How does fopen open a file. Is it possible to "emulate" opening a file (for reading, and also for writing) in an application with fopen?

    As allways, all hints and/or suggestions are greatly appreciated.

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    What is your program(executable) permission? root ?

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    111
    No, running as normal user.

    But I found the problem, and it's not related to neither fuse nor fopen, but to the "on-access" scanner. The problem is that if I'm in f.ex. /home/test, and then enable the scanner (if it's disabled initially), then the current folder I'm in isn't "noticed"/"mounted" by the scanner. Changing directory back and forth updated this, and it works.

    This post should perhaps be deleted, as it really isn't C-related?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 08:54 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21