1 $NetBSD: patch-ao,v 1.1 2005/11/03 19:38:50 adrianp Exp $
3 --- src/copypass.c.orig 2004-09-06 13:09:04.000000000 +0100
5 @@ -181,19 +181,25 @@ process_copy_pass ()
7 if (close (in_file_des) < 0)
8 error (0, errno, "%s", input_name.ds_string);
9 - if (close (out_file_des) < 0)
10 - error (0, errno, "%s", output_name.ds_string);
13 + * Avoid race condition.
14 + * Set chown and chmod before closing the file desc.
15 + * pvrabec@redhat.com
17 /* Set the attributes of the new file. */
19 - if ((chown (output_name.ds_string,
20 + if ((fchown (out_file_des,
21 set_owner_flag ? set_owner : in_file_stat.st_uid,
22 set_group_flag ? set_group : in_file_stat.st_gid) < 0)
24 error (0, errno, "%s", output_name.ds_string);
25 /* chown may have turned off some permissions we wanted. */
26 - if (chmod (output_name.ds_string, in_file_stat.st_mode) < 0)
27 + if (fchmod (out_file_des, in_file_stat.st_mode) < 0)
28 + error (0, errno, "%s", output_name.ds_string);
30 + if (close (out_file_des) < 0)
31 error (0, errno, "%s", output_name.ds_string);
35 times.actime = in_file_stat.st_atime;