'\" te .\" Copyright 1989 AT&T. Copyright (c) 2003,Sun Microsystems, Inc. All Rights Reserved. .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] .TH setuid 2 "20 Jan 2003" "SunOS 5.11" "System Calls" .SH NAME setuid, setegid, seteuid, setgid \- set user and group IDs .SH SYNOPSIS .LP .nf #include #include \fBint\fR \fBsetuid\fR(\fBuid_t\fR \fIuid\fR); .fi .LP .nf \fBint\fR \fBsetgid\fR(\fBgid_t\fR \fIgid\fR); .fi .LP .nf \fBint\fR \fBseteuid\fR(\fBuid_t\fR \fIeuid\fR); .fi .LP .nf \fBint\fR \fBsetegid\fR(\fBgid_t\fR \fIegid\fR); .fi .SH DESCRIPTION .sp .LP The \fBsetuid()\fR function sets the real user ID, effective user ID, and saved user ID of the calling process. The \fBsetgid()\fR function sets the real group ID, effective group ID, and saved group ID of the calling process. The \fBsetegid()\fR and \fBseteuid()\fR functions set the effective group and user IDs respectively for the calling process. See \fBIntro\fR(2) for more information on real, effective, and saved user and group IDs. .sp .LP At login time, the real user ID, effective user ID, and saved user ID of the login process are set to the login ID of the user responsible for the creation of the process. The same is true for the real, effective, and saved group IDs; they are set to the group ID of the user responsible for the creation of the process. .sp .LP When a process calls one of the \fBexec\fR(2) family of functions to execute a file (program), the user and/or group identifiers associated with the process can change. If the file executed is a set-user-ID file, the effective and saved user IDs of the process are set to the owner of the file executed. If the file executed is a set-group-ID file, the effective and saved group IDs of the process are set to the group of the file executed. If the file executed is not a set-user-ID or set-group-ID file, the effective user \fBID\fR, saved user ID, effective group ID, and saved group ID are not changed. .sp .LP If the {\fBPRIV_PROC_SETID\fR} privilege is asserted in the effective set of the process calling \fBsetuid()\fR, the real, effective, and saved user IDs are set to the \fIuid\fR argument. If the \fIuid\fR argument is 0 and none of the saved, effective or real UID is 0, additional restrictions apply. See \fBprivileges\fR(5). .sp .LP If the {\fBPRIV_PROC_SETID\fR} privilege is not asserted in the effective set, but \fIuid\fR is either the real user ID or the saved user ID of the calling process, the effective user ID is set to \fIuid\fR. .sp .LP If the {\fBPRIV_PROC_SETID\fR} privilege is asserted in the effective set of the process calling \fBsetgid()\fR, the real, effective, and saved group IDs are set to the \fIgid\fR argument. .sp .LP If the {\fBPRIV_PROC_SETID\fR} privilege is not asserted in the effective set, but \fIgid\fR is either the real group ID or the saved group ID of the calling process, the effective group ID is set to \fIgid\fR. .SH RETURN VALUES .sp .LP Upon successful completion, \fB0\fR is returned. Otherwise, \fB\(mi1\fR is returned and \fBerrno\fR is set to indicate the error. .SH ERRORS .sp .LP The \fBsetuid()\fR and \fBsetgid()\fR functions will fail if: .sp .ne 2 .mk .na \fB\fBEINVAL\fR\fR .ad .RS 10n .rt The value of \fIuid\fR or \fIgid\fR is out of range. .RE .sp .ne 2 .mk .na \fB\fBEPERM\fR\fR .ad .RS 10n .rt For \fBsetuid()\fR and \fBseteuid()\fR, the {\fBPRIV_PROC_SETID\fR} privilege is not asserted in the effective set of the calling process and the \fIuid\fR argument does not match either the real or saved user IDs, or an attempt is made to change to UID 0 and none of the existing UIDs is 0, in which case additional privileges are required. .sp For \fBsetgid()\fR and \fBsetegid()\fR, the {\fBPRIV_PROC_SETID\fR} privilege is not asserted in the effective set and the \fIgid\fR argument does not match either the real or saved group IDs. .RE .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ Interface StabilityStandard _ MT-LevelAsync-Signal-Safe .TE .SH SEE ALSO .sp .LP \fBIntro\fR(2), \fBexec\fR(2), \fBgetgroups\fR(2), \fBgetuid\fR(2), \fBstat.h\fR(3HEAD), \fBattributes\fR(5), \fBprivileges\fR(5), \fBstandards\fR(5)