void copy_file_as_user(const char *srcname, const char *destname, uid_t uid, gid_t gid, mode_t mode) {
	pid_t child = fork();
	if (child < 0)
		errExit("fork");
	if (child == 0) {
		// drop privileges
		drop_privs(0);

		// copy, set permissions and ownership
		int rv = copy_file(srcname, destname); // already a regular user
		if (rv)
			fprintf(stderr, "Warning: cannot copy %s\n", srcname);
		else {
			if (chown(destname, uid, gid) == -1)
				errExit("fchown");
			if (chmod(destname, mode) == -1)
				errExit("fchmod");
		}
		_exit(0);
	}
	// wait for the child to finish
	waitpid(child, NULL, 0);
}
void copy_file_as_user(const char *srcname, const char *destname, uid_t uid, gid_t gid, mode_t mode) {
	pid_t child = fork();
	if (child < 0)
		errExit("fork");
	if (child == 0) {
		 
		drop_privs(0);

		 
		int rv = copy_file(srcname, destname);  
		if (rv)
			fprintf(stderr, "Warning: cannot copy %s\n", srcname);
		else {
			if (chown(destname, uid, gid) == -1)
				errExit("fchown");
			if (chmod(destname, mode) == -1)
				errExit("fchmod");
		}
		_exit(0);
	}
	 
	waitpid(child, NULL, 0);
}