int WRAP_MKNOD MKNOD_ARG(int ver UNUSED, const char *pathname, mode_t mode, dev_t XMKNOD_FRTH_ARG dev) { INT_STRUCT_STAT st; mode_t old_mask=umask(022); int fd,r; umask(old_mask); /*Don't bother to mknod the file, that probably doesn't work. just create it as normal file, and leave the premissions to the fakemode.*/ fd=open(pathname, O_WRONLY|O_CREAT|O_TRUNC, 00644); if(fd==-1) return -1; close(fd); /* get the inode, to communicate with faked */ r=INT_NEXT_LSTAT(pathname, &st); if(r) return -1; st.st_mode= mode & ~old_mask; st.st_rdev= XMKNOD_FRTH_ARG dev; INT_SEND_STAT(&st,mknod_func); return 0; }
int chown(const char *path, uid_t owner, gid_t group){ INT_STRUCT_STAT st; int r=0; #ifdef LIBFAKEROOT_DEBUGGING if (fakeroot_debug) { fprintf(stderr, "chown path %s owner %d group %d\n", path, owner, group); } #endif /* LIBFAKEROOT_DEBUGGING */ #ifdef LCHOWN_SUPPORT /*chown(sym-link) works on the target of the symlink if lchown is present and enabled.*/ r=INT_NEXT_STAT(path, &st); #else /*chown(sym-link) works on the symlink itself, use lstat: */ r=INT_NEXT_LSTAT(path, &st); #endif if(r) return r; st.st_uid=owner; st.st_gid=group; INT_SEND_STAT(&st,chown_func); if(!dont_try_chown()) r=next_lchown(path,owner,group); else r=0; if(r&&(errno==EPERM)) r=0; return r; }
int lchmod(const char *path, mode_t mode){ INT_STRUCT_STAT st; int r; #ifdef LIBFAKEROOT_DEBUGGING if (fakeroot_debug) { fprintf(stderr, "lchmod path %s\n", path); } #endif /* LIBFAKEROOT_DEBUGGING */ r=INT_NEXT_LSTAT(path, &st); if(r) return r; st.st_mode=(mode&ALLPERMS)|(st.st_mode&~ALLPERMS); INT_SEND_STAT(&st, chmod_func); /* see chmod() for comment */ mode |= 0600; if(S_ISDIR(st.st_mode)) mode |= 0100; r=next_lchmod(path, mode); if(r&&(errno==EPERM)) r=0; #ifdef EFTYPE /* available under FreeBSD kernel */ if(r&&(errno==EFTYPE)) r=0; #endif return r; }
/* See the `remove funtions:' comments above for more info on these remove function wrappers. */ int remove(const char *pathname){ int r; INT_STRUCT_STAT st; r=INT_NEXT_LSTAT(pathname, &st); if(r) return -1; r=next_remove(pathname); if(r) return -1; INT_SEND_STAT(&st,unlink_func); return r; }
int rename(const char *oldpath, const char *newpath){ int r,s; INT_STRUCT_STAT st; /* If newpath points to an existing file, that file will be unlinked. Make sure we tell the faked daemon about this! */ /* we need the st_new struct in order to inform faked about the (possible) unlink of the file */ r=INT_NEXT_LSTAT(newpath, &st); s=next_rename(oldpath, newpath); if(s) return -1; if(!r) INT_SEND_STAT(&st,unlink_func); return 0; }
int lchown(const char *path, uid_t owner, gid_t group){ INT_STRUCT_STAT st; int r=0; #ifdef LIBFAKEROOT_DEBUGGING if (fakeroot_debug) { fprintf(stderr, "lchown path %s owner %d group %d\n", path, owner, group); } #endif /* LIBFAKEROOT_DEBUGGING */ r=INT_NEXT_LSTAT(path, &st); if(r) return r; st.st_uid=owner; st.st_gid=group; INT_SEND_STAT(&st,chown_func); if(!dont_try_chown()) r=next_lchown(path,owner,group); else r=0; if(r&&(errno==EPERM)) r=0; return r; }