file.replace: replicate ownership/permissions on new file

Since file.replace was changed to use fileinput.input (and perhaps
before this), this function would create a new file with the desired
replacements, and this file would be owned by the user running salt,
with permissions governed by the umask. This is not the expected
behavior. One would expect that the new file would have the same
ownership and permissions as the original file. This commit performs an
os.stat before making changes, and then sets the ownership/permissions
after the changes are made.

Rather than stat-ing the file again after making the changes, since stat
can be an expensive operation, the ownership and permissions are set
irrespective of whether or not they differ from the original state.
Add salt.utils.file_perms function

Converting the st_mode value from os.stat results to something usable
for os.chmod seemed like it would be a useful thing to have in
salt.utils, so this commit moves that functionality there.
Merge pull request #8417 from terminalmage/issue8399

file.replace: replicate ownership/permissions on new file