views:

77

answers:

2

I copy a file by opening the source in read-only mode and the destination in write-only mode. It's simple and it works.

The problem is that sometimes I am copying a file that sits on an NFS drive, or other network drives and when in these cases the permissions get all screwed and SELinux complains. I then go and manually set the permissions of the files I just copied and it's OK. I can access them again (via ftp, web, etc).

Is there any way to copy a file and change the permissions to a certain user and group?

Code is appreciated. Thanks

EDIT:

would something like

open(argv[2], O_WRONLY | O_CREAT, 0666)

work?

A: 

According to http://www.delorie.com/gnu/docs/glibc/libc_290.html, there is a function:

int chmod (const char *filename, mode_t mode)

This should do what you want.

Maz
how about using something like: open(argv[2], O_WRONLY | O_CREAT, 0666)
Jessica
+1  A: 

For user and group setting changes use the chown() function. chmod() works on the st_mode values like protections and setuid, setgid, sticky bit.

jim mcnamara