1: /*
   2:  * Copyright (c) 1982, 1986, 1989, 1990, 1991, 1993
   3:  *	The Regents of the University of California.  All rights reserved.
   4:  * (c) UNIX System Laboratories, Inc.
   5:  * All or some portions of this file are derived from material licensed
   6:  * to the University of California by American Telephone and Telegraph
   7:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
   8:  * the permission of UNIX System Laboratories, Inc.
   9:  *
  10:  * Redistribution and use in source and binary forms, with or without
  11:  * modification, are permitted provided that the following conditions
  12:  * are met:
  13:  * 1. Redistributions of source code must retain the above copyright
  14:  *    notice, this list of conditions and the following disclaimer.
  15:  * 2. Redistributions in binary form must reproduce the above copyright
  16:  *    notice, this list of conditions and the following disclaimer in the
  17:  *    documentation and/or other materials provided with the distribution.
  18:  * 3. All advertising materials mentioning features or use of this software
  19:  *    must display the following acknowledgement:
  20:  *	This product includes software developed by the University of
  21:  *	California, Berkeley and its contributors.
  22:  * 4. Neither the name of the University nor the names of its contributors
  23:  *    may be used to endorse or promote products derived from this software
  24:  *    without specific prior written permission.
  25:  *
  26:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36:  * SUCH DAMAGE.
  37:  *
  38:  *	@(#)kern_prot2.c  8.9.2 (2.11BSD) 2000/2/20
  39:  */
  40: 
  41: #include "param.h"
  42: #include "user.h"
  43: #include "acct.h"
  44: #include "proc.h"
  45: #include "systm.h"
  46: #ifdef QUOTA
  47: #include "quota.h"
  48: #endif
  49: 
  50: int
  51: setuid()
  52: {
  53:     struct a {
  54:         uid_t uid;
  55:         } *uap = (struct a *)u.u_ap;
  56: 
  57:     return(_setuid(uap->uid));
  58:     }
  59: 
  60: /*
  61:  * This is a helper function used by setuid() above and the 4.3BSD
  62:  * compatibility code.  When the latter goes away this can be joined
  63:  * back into the above code and save a function call.
  64: */
  65: int
  66: _setuid(uid)
  67:     register uid_t uid;
  68:     {
  69: 
  70:     if (uid != u.u_ruid && !suser())
  71:         return(u.u_error);
  72:     /*
  73: 	 * Everything's okay, do it.
  74: 	 * Since the real user id is changing the quota references need
  75: 	 * to be updated.
  76: 	 */
  77: #ifdef QUOTA
  78:         QUOTAMAP();
  79:     if (u.u_quota->q_uid != uid) {
  80:         qclean();
  81:         qstart(getquota((uid_t)uid, 0, 0));
  82:     }
  83:     QUOTAUNMAP();
  84: #endif
  85: 
  86:     u.u_procp->p_uid = uid;
  87:     u.u_uid = uid;
  88:     u.u_ruid = uid;
  89:     u.u_svuid = uid;
  90:     u.u_acflag |= ASUGID;
  91:     return (u.u_error = 0);
  92:     }
  93: 
  94: int
  95: seteuid()
  96: {
  97:     struct a {
  98:         uid_t euid;
  99:         } *uap = (struct a *)u.u_ap;
 100: 
 101:     return(_seteuid(uap->euid));
 102:     }
 103: 
 104: int
 105: _seteuid(euid)
 106:     register uid_t euid;
 107:     {
 108: 
 109:     if (euid != u.u_ruid && euid != u.u_svuid && !suser())
 110:         return (u.u_error);
 111:     /*
 112: 	 * Everything's okay, do it.
 113: 	 */
 114:     u.u_uid = euid;
 115:     u.u_acflag |= ASUGID;
 116:     return (u.u_error = 0);
 117:     }
 118: 
 119: int
 120: setgid()
 121:     {
 122:     struct a {
 123:         gid_t gid;
 124:         } *uap = (struct a *)u.u_ap;
 125: 
 126:     return(_setgid(uap->gid));
 127:     }
 128: 
 129: int
 130: _setgid(gid)
 131:     register gid_t gid;
 132:     {
 133: 
 134:     if (gid != u.u_rgid && !suser())
 135:         return (u.u_error); /* XXX */
 136:     u.u_groups[0] = gid;        /* effective gid is u_groups[0] */
 137:     u.u_rgid = gid;
 138:     u.u_svgid = gid;
 139:     u.u_acflag |= ASUGID;
 140:     return (u.u_error = 0);
 141:     }
 142: 
 143: int
 144: setegid()
 145:     {
 146:     struct a {
 147:         gid_t egid;
 148:     } *uap = (struct a *)u.u_ap;
 149: 
 150:     return(_setegid(uap->egid));
 151:     }
 152: 
 153: int
 154: _setegid(egid)
 155:     register gid_t egid;
 156:     {
 157: 
 158:     if (egid != u.u_rgid && egid != u.u_svgid && !suser())
 159:         return (u.u_error);
 160:     u.u_groups[0] = egid;
 161:     u.u_acflag |= ASUGID;
 162:     return (u.u_error = 0);
 163:     }

Defined functions

_setegid defined in line 153; used 1 times
_seteuid defined in line 104; used 1 times
_setgid defined in line 129; used 1 times
_setuid defined in line 65; used 1 times
  • in line 57
setegid defined in line 143; used 2 times
seteuid defined in line 94; used 2 times
setgid defined in line 119; used 2 times
setuid defined in line 50; used 2 times

Defined struct's

a defined in line 146; used 8 times
Last modified: 2000-02-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2813
Valid CSS Valid XHTML 1.0 Strict