Subject: kern/732: TIOCCONS should work if `I' own /dev/console
To: None <gnats-admin@NetBSD.ORG>
From: None <mrg@mame.mu.OZ.AU>
List: netbsd-bugs
Date: 01/14/1995 21:35:04
>Number:         732
>Category:       kern
>Synopsis:       TIOCCONS should work if `I' own /dev/console
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 14 21:35:03 1995
>Originator:     matthew green
>Organization:
bozotic softwar foundation.
>Release:        n/a
>Environment:
System: NetBSD splode.mame.mu.OZ.AU 1.0A NetBSD 1.0A (_splode_) #124: Sun Jan 15 16:07:03 EST 1995 mrg@splode.mame.mu.OZ.AU:/splode/build/src/sys/arch/sparc/compile/_splode_ sparc


>Description:

	TIOCCONS should work if i own the console, so i can redirect
	console messages elsewhere.  on the sparc is is very annoying
	to have console messages printed on the X display.

>How-To-Repeat:
	n/a
>Fix:

	this is a non-working patch of what i've done so far.  i couldn't
	finish it, and i got sick of it, so i'm sending it in here incase
	someone else tries to work on it.


Index: tty.c
===================================================================
RCS file: /local/cvs/src/sys/kern/tty.c,v
retrieving revision 1.1.1.1
retrieving revision 1.6
diff -c -r1.1.1.1 -r1.6
*** 1.1.1.1	1994/12/14 12:45:53
--- 1.6	1995/01/15 05:14:53
***************
*** 42,47 ****
--- 42,48 ----
  
  #include <sys/param.h>
  #include <sys/systm.h>
+ #include <sys/namei.h>
  #include <sys/ioctl.h>
  #include <sys/proc.h>
  #define	TTYDEFCHARS
***************
*** 699,708 ****
  			    ISSET(constty->t_state, TS_CARR_ON | TS_ISOPEN) ==
  			    (TS_CARR_ON | TS_ISOPEN))
  				return (EBUSY);
! #ifndef	UCONSOLE
! 			if (error = suser(p->p_ucred, &p->p_acflag))
! 				return (error);
  #endif
  			constty = tp;
  		} else if (tp == constty)
  			constty = NULL;
--- 700,753 ----
  			    ISSET(constty->t_state, TS_CARR_ON | TS_ISOPEN) ==
  			    (TS_CARR_ON | TS_ISOPEN))
  				return (EBUSY);
! 
! 			if (error = suser(p->p_ucred, &p->p_acflag)) {
! 				register struct ucred *cred;
! 				uid_t t_uid;
! 				gid_t t_gid;
! 				struct vnode *vp;
! 
! 		/*
! 		 * need some better way to do this rather than trying to
! 		 # use "/dev/console".  probably something that takes the
! 		 # value of constty->t_dev, and creates a vp out of it..
! 		 * how to do this, i haven't a clue.
! 		 *
! 		 * Mycroft says: You could use cdevvp(constty->t_dev, &vp),
! 		 * if you want to check the ownership of /dev/console,
! 		 * specifically, but that assumes the vnode is open.
! 		 * You could do cdevvp() and see if the tag is VT_NON.
! 		 * That's a kluge, of course.
! 		 */
! #if 1
! 				struct nameidata nd;
! 
! 				NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF,
! 				    UIO_SYSSPACE, "/dev/console", p);
! 				error = namei(&nd);
! 				if (error)
! 					return (error);
! 				vp = nd.ni_vp;
! #else
! 				error = cdevvp(constty->t_dev, &vp);
! 				printf("ioctl TIOCCONS: error %d on cdevvp", error);
! 				if (error) 
! 					return (error);
! 				printf("ioctl TIOCCONS: vp->v_tag is %d", vp->v_tag);
! 				if (vp->v_tag == VT_NON) /* XXX this is a kludge */
! 					return (EBUSY);
  #endif
+ 				cred = p->p_ucred;
+ 				t_uid = cred->cr_uid;
+ 				t_gid = cred->cr_groups[0];
+ 				cred->cr_uid = p->p_cred->p_ruid;
+ 				cred->cr_groups[0] = p->p_cred->p_rgid;
+ 				error = VOP_ACCESS(vp, VREAD, cred, p);
+ 				cred->cr_uid = t_uid;
+ 				cred->cr_groups[0] = t_gid;
+ 				if (error) 
+ 					return (error);
+ 			}
  			constty = tp;
  		} else if (tp == constty)
  			constty = NULL;
>Audit-Trail:
>Unformatted: