budd@BU-CS.BU.EDU (Philip Budne) (08/28/86)
SYMPTOM:
fchmod(2) fails on unredirected stdin.
The following program fails with "Not owner" under SUN 3.0,
but works under VAX BSD 4.2;
main() {
if( fchmod(0, 0777) < 0 )
perror( "fchmod" );
}
DIAGNOSIS:
in vfs_syscalls the routine fdsetattr passes the credentials of
the file desriptor (opened long ago by init):
error = VOP_SETATTR(vp, vap, fp->f_cred);
namesetattr (used by chmod) passes the user's credentials:
error = VOP_SETATTR(vp, vap, u.u_cred);
fdsetattr is called only by fchmod and fchown. fchown requires super
user, and thus never sees the problem.
CURE:
always pass the user's credentials.