* Common implementation for chown(), lchown(), and fchown() */
| 2913 | * Common implementation for chown(), lchown(), and fchown() |
| 2914 | */ |
| 2915 | int |
| 2916 | setfown(struct thread *td, struct ucred *cred, struct vnode *vp, uid_t uid, |
| 2917 | gid_t gid) |
| 2918 | { |
| 2919 | struct mount *mp; |
| 2920 | struct vattr vattr; |
| 2921 | int error; |
| 2922 | |
| 2923 | if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) |
| 2924 | return (error); |
| 2925 | vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); |
| 2926 | VATTR_NULL(&vattr); |
| 2927 | vattr.va_uid = uid; |
| 2928 | vattr.va_gid = gid; |
| 2929 | #ifdef MAC |
| 2930 | error = mac_vnode_check_setowner(cred, vp, vattr.va_uid, |
| 2931 | vattr.va_gid); |
| 2932 | if (error == 0) |
| 2933 | #endif |
| 2934 | error = VOP_SETATTR(vp, &vattr, cred); |
| 2935 | VOP_UNLOCK(vp); |
| 2936 | vn_finished_write(mp); |
| 2937 | return (error); |
| 2938 | } |
| 2939 | |
| 2940 | /* |
| 2941 | * Set ownership given a path name. |
no test coverage detected