Backport fixes to race conditions and file permissions in

file editing.

Previously the original was removed and then the edited file was
renamed, leaving a small timeframe where the file did not exist, which
can lead to bad situations. Fixed by leaving the file in place until
rename is called, which is atomic on all POSIX platforms.

Also make sure all permissions, including ACLs and SELinux security
contexts, are preserved when making a copy of the original file.

Fixes issue 2545.

Conflicts:
	cf-agent/files_operators.c
	cf-agent/files_operators.h
	src/acl.h

(cherry picked from commit a3f1a964ad5e079f8abc419bb9e0489aa8c62f7a)
(cherry picked from commit 908fb187191b41df44bdfb7d092a429cded06436)
(cherry picked from commit 76d895609ea7dee55502139acf52b1b141ca9b10)