0

I have two Users. User1 is running a program which tries to delete a file from user2. But my program always return me "permission denied".

When I try to delete the file myself as user1 with the rm command there is no problem. The permission of the files are 775 and my user1 is in the group of user2. This group is also the owner of the files. The permission of the directory in which the files are is 775 too.

For removing the file the program I have written uses the "remove" function from c/c++. Does anyone have a solution or idea ?

I have asked this question on unix.stackexchange.com before. They have sent me here.

Here is my code:

void deleteFile() {

    if(0 != remove("File1.txt"))
        cout<<"Error deleting File: "<<strerror(errno)<<endl;
    if(0 != remove("File2.txt"))
        cout<<"Error deleting File: "<<strerror(errno)<<endl;
}

i have renamed the files but i know the original paths are correct. i have already tested this

more information: ok i have runnned the program as user2 and the files have been deleted without any problems.

groups user1 users user2

groups user2 user2 adm www-data plugdev users ftp vsftpd

ls -lah drwxrwxr-x 7 user2 user2 4.0K Nov 27 14:13 . drwxrw-r-x 4 user2 user2 4.0K Nov 11 12:34 .. -rwxrwxr-x 1 user2 user2 50 Nov 12 15:12 File1.txt -rwxrwxr-x 1 user2 user2 826 Nov 27 14:13 File2.txt

scrux
  • 3
  • 2
  • what's the ownership of the containing dir? mode 775 doesn't help much if it's in some OTHER group than what the files/users are. – Marc B Dec 01 '14 at 21:30
  • What is the permissions of the executing program? – Camron_Godbout Dec 01 '14 at 21:35
  • 2
    I thought the function for deleting a file was [`unlink`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html). – Ben Voigt Dec 01 '14 at 21:35
  • http://stackoverflow.com/questions/678325/remove-file-in-c-under-unix – Camron_Godbout Dec 01 '14 at 21:36
  • sorry but i can't understand what exactly you are meaning. the directory in wich the files are located is owned by user2 and the group "user2". You can see this in the output of ls -lah wich i have already posted in the question. Or do i misunderstand you ? – scrux Dec 01 '14 at 21:40
  • @BenVoigt the "remove" function is automatically calling unlink if the path point to a file. see man remove – scrux Dec 01 '14 at 21:41
  • @Camron_Godbout the permission of the executing program is also 775 and is owned by user1 and the group user2 – scrux Dec 01 '14 at 21:44

1 Answers1

0

Try running rm and Your command with strace as user1:

strace your_program
strace rm File1.txt File2.txt

You should see, what Your program and rm are doing differently.

kestasx
  • 1,091
  • 8
  • 15