/*===========================================================================* * do_chroot * *===========================================================================*/ int do_chroot(void) { /* Perform the chroot(name) system call. * syscall might provide 'name' embedded in the message. */ int r; struct vnode *vp; struct vmnt *vmp; char fullpath[PATH_MAX]; struct lookup resolve; if (!super_user) return(EPERM); /* only su may chroot() */ if (copy_path(fullpath, sizeof(fullpath)) != OK) return(err_code); /* Try to open the directory */ lookup_init(&resolve, fullpath, PATH_NOFLAGS, &vmp, &vp); resolve.l_vmnt_lock = VMNT_READ; resolve.l_vnode_lock = VNODE_READ; if ((vp = eat_path(&resolve, fp)) == NULL) return(err_code); r = change_into(&fp->fp_rd, vp); unlock_vnode(vp); unlock_vmnt(vmp); put_vnode(vp); return(r); }
/*===========================================================================* * do_fchdir * *===========================================================================*/ int do_fchdir() { /* Change directory on already-opened fd. */ struct filp *rfilp; int r, rfd; rfd = job_m_in.fd; /* Is the file descriptor valid? */ if ((rfilp = get_filp(rfd, VNODE_READ)) == NULL) return(err_code); r = change_into(&fp->fp_wd, rfilp->filp_vno); unlock_filp(rfilp); return(r); }
/*===========================================================================* * do_chroot * *===========================================================================*/ int do_chroot() { /* Perform the chroot(name) system call. * syscall might provide 'name' embedded in the message. */ int r; struct vnode *vp; struct vmnt *vmp; char fullpath[PATH_MAX]; struct lookup resolve; vir_bytes vname; size_t vname_length; vname = (vir_bytes) job_m_in.name; vname_length = (size_t) job_m_in.name_length; if (!super_user) return(EPERM); /* only su may chroot() */ if (copy_name(vname_length, fullpath) != OK) { /* Direct copy failed, try fetching from user space */ if (fetch_name(vname, vname_length, fullpath) != OK) return(err_code); } /* Try to open the directory */ lookup_init(&resolve, fullpath, PATH_NOFLAGS, &vmp, &vp); resolve.l_vmnt_lock = VMNT_READ; resolve.l_vnode_lock = VNODE_READ; if ((vp = eat_path(&resolve, fp)) == NULL) return(err_code); r = change_into(&fp->fp_rd, vp); unlock_vnode(vp); unlock_vmnt(vmp); put_vnode(vp); return(r); }