Eu encontrei aqui esta função em C:
static int opentab(int uid, char *file, int how)
/* Open a crontab file under the given uid. How is 'r' or 'w'. Return
* the result of open(2).
*/
{
uid_t safe_uid;
int flags, r, err;
switch (how) {
case 'r': flags= O_RDONLY; break;
case 'w': flags= O_WRONLY | O_CREAT | O_TRUNC; break;
default: errno= EINVAL; return -1;
}
#if __minix && !__minix_vmd
/* Standard Minix has no saved uid, so use the lousy old access(). */
if (uid != 0) {
if (access(file, how == 'r' ? R_OK : W_OK) < 0) return -1;
}
#endif
safe_uid= geteuid();
seteuid(uid);
r= open(file, flags, 0666);
err= errno;
seteuid(safe_uid);
errno= err;
return r;
}
Talvez isso possa ser útil para você.