BSD 4_4_Lite1 release
[unix-history] / usr / src / sys / miscfs / procfs / procfs_vnops.c
index d9fd090..4e1ee00 100644 (file)
@@ -1,14 +1,40 @@
 /*
 /*
- * Copyright (c) 1993 The Regents of the University of California.
  * Copyright (c) 1993 Jan-Simon Pendry
  * Copyright (c) 1993 Jan-Simon Pendry
- * All rights reserved.
+ * Copyright (c) 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Jan-Simon Pendry.
  *
  *
  * This code is derived from software contributed to Berkeley by
  * Jan-Simon Pendry.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)procfs_vnops.c      8.2 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)procfs_vnops.c      8.6 (Berkeley) 2/7/94
  *
  * From:
  *     $Id: procfs_vnops.c,v 3.2 1993/12/15 09:40:17 jsp Exp $
  *
  * From:
  *     $Id: procfs_vnops.c,v 3.2 1993/12/15 09:40:17 jsp Exp $
@@ -49,13 +75,14 @@ static struct pfsnames {
 } procent[] = {
 #define N(s) sizeof(s)-1, s
        /* namlen, nam, type */
 } procent[] = {
 #define N(s) sizeof(s)-1, s
        /* namlen, nam, type */
-       {  N("file"),   Pfile },
-       {  N("mem"),    Pmem },
-       {  N("regs"),   Pregs },
-       {  N("ctl"),    Pctl },
-       {  N("status"), Pstatus },
-       {  N("note"),   Pnote },
-       {  N("notepg"), Pnotepg },
+       {  N("file"),   Pfile },
+       {  N("mem"),    Pmem },
+       {  N("regs"),   Pregs },
+       {  N("fpregs"), Pfpregs },
+       {  N("ctl"),    Pctl },
+       {  N("status"), Pstatus },
+       {  N("note"),   Pnote },
+       {  N("notepg"), Pnotepg },
 #undef N
 };
 #define Nprocent (sizeof(procent)/sizeof(procent[0]))
 #undef N
 };
 #define Nprocent (sizeof(procent)/sizeof(procent[0]))
@@ -197,6 +224,42 @@ procfs_reclaim(ap)
        return (error);
 }
 
        return (error);
 }
 
+/*
+ * Return POSIX pathconf information applicable to special devices.
+ */
+procfs_pathconf(ap)
+       struct vop_pathconf_args /* {
+               struct vnode *a_vp;
+               int a_name;
+               int *a_retval;
+       } */ *ap;
+{
+
+       switch (ap->a_name) {
+       case _PC_LINK_MAX:
+               *ap->a_retval = LINK_MAX;
+               return (0);
+       case _PC_MAX_CANON:
+               *ap->a_retval = MAX_CANON;
+               return (0);
+       case _PC_MAX_INPUT:
+               *ap->a_retval = MAX_INPUT;
+               return (0);
+       case _PC_PIPE_BUF:
+               *ap->a_retval = PIPE_BUF;
+               return (0);
+       case _PC_CHOWN_RESTRICTED:
+               *ap->a_retval = 1;
+               return (0);
+       case _PC_VDISABLE:
+               *ap->a_retval = _POSIX_VDISABLE;
+               return (0);
+       default:
+               return (EINVAL);
+       }
+       /* NOTREACHED */
+}
+
 /*
  * _print is used for debugging.
  * just print a readable description
 /*
  * _print is used for debugging.
  * just print a readable description
@@ -254,9 +317,16 @@ procfs_getattr(ap)
        int error;
 
        /* first check the process still exists */
        int error;
 
        /* first check the process still exists */
-       procp = PFIND(pfs->pfs_pid);
-       if (procp == 0)
-               return (ENOENT);
+       switch (pfs->pfs_type) {
+       case Proot:
+               procp = 0;
+               break;
+
+       default:
+               procp = PFIND(pfs->pfs_pid);
+               if (procp == 0)
+                       return (ENOENT);
+       }
 
        error = 0;
 
 
        error = 0;
 
@@ -271,6 +341,22 @@ procfs_getattr(ap)
        vap->va_blocksize = PAGE_SIZE;
        vap->va_bytes = vap->va_size = 0;
 
        vap->va_blocksize = PAGE_SIZE;
        vap->va_bytes = vap->va_size = 0;
 
+       /*
+        * If the process has exercised some setuid or setgid
+        * privilege, then rip away read/write permission so
+        * that only root can gain access.
+        */
+       switch (pfs->pfs_type) {
+       case Pregs:
+       case Pfpregs:
+       case Pmem:
+               if (procp->p_flag & P_SUGID)
+                       vap->va_mode &= ~((VREAD|VWRITE)|
+                                         ((VREAD|VWRITE)>>3)|
+                                         ((VREAD|VWRITE)>>6));
+               break;
+       }
+
        /*
         * Make all times be current TOD.
         * It would be possible to get the process start
        /*
         * Make all times be current TOD.
         * It would be possible to get the process start
@@ -320,6 +406,7 @@ procfs_getattr(ap)
                break;
 
        case Pregs:
                break;
 
        case Pregs:
+       case Pfpregs:
        case Pctl:
        case Pstatus:
        case Pnote:
        case Pctl:
        case Pstatus:
        case Pnote:
@@ -423,12 +510,10 @@ procfs_lookup(ap)
        struct vnode *dvp = ap->a_dvp;
        char *pname = cnp->cn_nameptr;
        int error = 0;
        struct vnode *dvp = ap->a_dvp;
        char *pname = cnp->cn_nameptr;
        int error = 0;
-       int flag;
        pid_t pid;
        struct vnode *nvp;
        struct pfsnode *pfs;
        struct proc *procp;
        pid_t pid;
        struct vnode *nvp;
        struct pfsnode *pfs;
        struct proc *procp;
-       int mode;
        pfstype pfs_type;
        int i;
 
        pfstype pfs_type;
        int i;