# 2.11BSD#431 - /usr/src/sys/sys/kern_prot.c

##### Functions

    getegid           X
    geteuid           X
    getgid            X
    getgroups         X
    getlogin          X
    getpgrp           X
    getpid            X
    getppid           X
    getuid            X
    groupmember       X
    setgroups         X
    setlogin          X
    setpgrp           X

##### struct's

    a                 X

       1: /*
       2:  * Copyright (c) 1986 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  *
       6:  *	@(#)kern_prot.c	1.4 (2.11BSD GTE) 1997/11/28
       7:  */
       8:
       9: /*
      10:  * System calls related to processes and protection
      11:  */
      12:
      13: #include "param.h"
      14: #include "user.h"
      15: #include "proc.h"
      16: #include "systm.h"
      17: #ifdef QUOTA
      18: #include "quota.h"
      19: #endif
      20:
      21: getpid()
      22: {
      23:
      24:     u.u_r.r_val1 = u.u_procp->p_pid;
      25:     u.u_r.r_val2 = u.u_procp->p_ppid;   /* XXX - compatibility */
      26: }
      27:
      28: getppid()
      29: {
      30:
      31:     u.u_r.r_val1 = u.u_procp->p_ppid;
      32: }
      33:
      34: getpgrp()
      35: {
      36:     register struct a {
      37:         int pid;
      38:     } *uap = (struct a *)u.u_ap;
      39:     register struct proc *p;
      40:
      41:     if (uap->pid == 0)      /* silly... */
      42:         uap->pid = u.u_procp->p_pid;
      43:     p = pfind(uap->pid);
      44:     if (p == 0) {
      45:         u.u_error = ESRCH;
      46:         return;
      47:     }
      48:     u.u_r.r_val1 = p->p_pgrp;
      49: }
      50:
      51: getuid()
      52: {
      53:
      54:     u.u_r.r_val1 = u.u_ruid;
      55:     u.u_r.r_val2 = u.u_uid;     /* XXX */
      56: }
      57:
      58: geteuid()
      59: {
      60:
      61:     u.u_r.r_val1 = u.u_uid;
      62: }
      63:
      64: getgid()
      65: {
      66:
      67:     u.u_r.r_val1 = u.u_rgid;
      68:     u.u_r.r_val2 = u.u_groups[0];       /* XXX */
      69: }
      70:
      71: getegid()
      72: {
      73:
      74:     u.u_r.r_val1 = u.u_groups[0];
      75: }
      76:
      77: /*
      78:  * getgroups and setgroups differ from 4.X because the VAX stores group
      79:  * entries in the user structure as shorts and has to convert them to ints.
      80:  */
      81: getgroups()
      82: {
      83:     register struct a {
      84:         u_int   gidsetsize;
      85:         int *gidset;
      86:     } *uap = (struct a *)u.u_ap;
      87:     register gid_t *gp;
      88:
      89:     for (gp = &u.u_groups[NGROUPS]; gp > u.u_groups; gp--)
      90:         if (gp[-1] != NOGROUP)
      91:             break;
      92:     if (uap->gidsetsize < gp - u.u_groups) {
      93:         u.u_error = EINVAL;
      94:         return;
      95:     }
      96:     uap->gidsetsize = gp - u.u_groups;
      97:     u.u_error = copyout((caddr_t)u.u_groups, (caddr_t)uap->gidset,
      98:         uap->gidsetsize * sizeof(u.u_groups[0]));
      99:     if (u.u_error)
     100:         return;
     101:     u.u_r.r_val1 = uap->gidsetsize;
     102: }
     103:
     104: setpgrp()
     105: {
     106:     register struct proc *p;
     107:     register struct a {
     108:         int pid;
     109:         int pgrp;
     110:     } *uap = (struct a *)u.u_ap;
     111:
     112:     if (uap->pid == 0)      /* silly... */
     113:         uap->pid = u.u_procp->p_pid;
     114:     p = pfind(uap->pid);
     115:     if (p == 0) {
     116:         u.u_error = ESRCH;
     117:         return;
     118:     }
     119: /* need better control mechanisms for process groups */
     120:     if (p->p_uid != u.u_uid && u.u_uid && !inferior(p)) {
     121:         u.u_error = EPERM;
     122:         return;
     123:     }
     124:     p->p_pgrp = uap->pgrp;
     125: }
     126:
     127: setgroups()
     128: {
     129:     register struct a {
     130:         u_int   gidsetsize;
     131:         int *gidset;
     132:     } *uap = (struct a *)u.u_ap;
     133:     register gid_t *gp;
     134:
     135:     if (!suser())
     136:         return;
     137:     if (uap->gidsetsize > sizeof (u.u_groups) / sizeof (u.u_groups[0])) {
     138:         u.u_error = EINVAL;
     139:         return;
     140:     }
     141:     u.u_error = copyin((caddr_t)uap->gidset, (caddr_t)u.u_groups,
     142:     uap->gidsetsize * sizeof (u.u_groups[0]));
     143:     if (u.u_error)
     144:         return;
     145:     for (gp = &u.u_groups[uap->gidsetsize]; gp < &u.u_groups[NGROUPS]; gp++)
     146:         *gp = NOGROUP;
     147: }
     148:
     149: /*
     150:  * Check if gid is a member of the group set.
     151:  */
     152: groupmember(gid)
     153:     gid_t gid;
     154: {
     155:     register gid_t *gp;
     156:
     157:     for (gp = u.u_groups; gp < &u.u_groups[NGROUPS] && *gp != NOGROUP; gp++)
     158:         if (*gp == gid)
     159:             return (1);
     160:     return (0);
     161: }
     162:
     163: /*
     164:  * Get login name, if available.
     165: */
     166: int
     167: getlogin()
     168:     {
     169:     register struct a
     170:         {
     171:         char *namebuf;
     172:         u_int namelen;
     173:         } *uap = (struct a *)u.u_ap;
     174:     register int error;
     175:
     176:     if  (uap->namelen > sizeof (u.u_login))
     177:         uap->namelen = sizeof (u.u_login);
     178:     error = copyout(u.u_login, uap->namebuf, uap->namelen);
     179:     return(u.u_error = error);
     180:     }
     181:
     182: /*
     183:  * Set login name.
     184:  * It is not clear whether this should be allowed if the process
     185:  * is not the "session leader" (the 'login' process).  But since 2.11
     186:  * doesn't have sessions and it's almost impossible to know if a process
     187:  * is "login" or not we simply restrict this call to the super user.
     188: */
     189:
     190: int
     191: setlogin()
     192:     {
     193:     register struct a
     194:         {
     195:         char *namebuf;
     196:         } *uap = (struct a *)u.u_ap;
     197:     register int error;
     198:     char    newname[MAXLOGNAME + 1];
     199:
     200:     if  (!suser())
     201:         return(u.u_error);  /* XXX - suser should be changed! */
     202: /*
     203:  * copinstr() wants to copy a string including a nul but u_login is not
     204:  * necessarily nul-terminated.  Copy into a temp that is one character
     205:  * longer then copy into place if that fit.
     206: */
     207:
     208:     bzero(newname, sizeof (newname));
     209:     error = copyinstr(uap->namebuf, newname, sizeof(newname), NULL);
     210:     if  (error == 0)
     211:         bcopy(newname, u.u_login, sizeof (u.u_login));
     212:     return(u.u_error = error);
     213:     }

#### Defined functions

getegid defined in line 71; used 2 times

- in /usr/src/sys/sys/init_sysent.c line 22, 158

geteuid defined in line 58; used 2 times

- in /usr/src/sys/sys/init_sysent.c line 22, 135

getgid defined in line 64; used 2 times

- in /usr/src/sys/sys/init_sysent.c line 21, 157

getgroups defined in line 81; used 2 times

- in /usr/src/sys/sys/init_sysent.c line 21, 189

getlogin defined in line 166; used 2 times

- in /usr/src/sys/sys/init_sysent.c line 22, 149

getpgrp defined in line 34; used 2 times

- in /usr/src/sys/sys/init_sysent.c line 23, 191

getpid defined in line 21; used 2 times

- in /usr/src/sys/sys/init_sysent.c line 19, 130

getppid defined in line 28; used 2 times

- in /usr/src/sys/sys/init_sysent.c line 20, 137

getuid defined in line 51; used 2 times

- in /usr/src/sys/sys/init_sysent.c line 21, 134

groupmember defined in line 152; used 3 times

- in /usr/src/sys/sys/ufs_syscalls.c line 592, 675, 1113

setgroups defined in line 127; used 2 times

- in /usr/src/sys/sys/init_sysent.c line 21, 190

setlogin defined in line 190; used 2 times

- in /usr/src/sys/sys/init_sysent.c line 23, 153

setpgrp defined in line 104; used 2 times

- in /usr/src/sys/sys/init_sysent.c line 23, 192

#### Defined struct's

a defined in line 193; used 12 times

- in line 38(2), 86(2), 110(2), 132(2), 173(2), 196(2)

Last modified: 1997-11-29 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 847 |