简体   繁体   中英

how can I delete a file created by another user using C?

I have two C codes, the first code is called "Producer" and I run it in the user "A" and the code create a file. The second code named "Consumer", is run in the user "B" and, this code read the file created by the "Producer" and need delete this file after end the reading. Both users "A" and "B" are in the group "ABshare". The file is create by the "Producer" with permission 0660.

When i run de "Producer" code in user "A", the file is create flawlessly and i can read this when i run the "Consumer" in user "B" but the problem is that i can't delete the file. To delete the file i try using the function "remove ()" http://man7.org/linux/man-pages/man3/remove.3.html

When I run the "Producer" and the "Consumer" both in user "A" or in user "B", the "Producer" generate the file and the "Consumer" can read and delete this file.

Why i can't delete the file when i run the "Producer" and the "Consumer" in diferents users? I try modify the own of the file from "A" to "B" before delete him using the "Consumer" code, for this I use this code: Change owner and group in c, but i can only change the group of file not the own.

Reading about chown fuction in ths man page: http://man7.org/linux/man-pages/man3/chown.3p.html i find this information: "Changing the user ID is restricted to processes with appropriate privileges ."

How I can give to the "Consumer" code the " appropriate privileges " to change the own of file create by the "Producer" in user A when " Consumer" run in "B"? Or, How I can delete the file created by "Producer" when "Producer" and "Consumer" run in diferrents users?

Please, Somebody can help me?

Thank you!!!

Like wildplasser said, all I needed is to give the correct permission to the directory where the files lives. In my case, the new permission of directory is 0777.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM