setuid -- Specify User ID

SYNOPSIS

 #include <sys/types.h>
 #include <unistd.h>

 int setuid(uid_t userID);
 

DESCRIPTION

setuid changes the effective user ID (and possibly the real user ID) of the current process to the ID specified by userID. If uid is the process' real user ID, setuid sets the process' effective user ID. If userID is not the process' real user ID, setuid is allowed to proceed only if the calling process is a superuser process, in which case it sets all of the real user ID, effective user ID and saved set user ID as specified.

RETURN VALUE

setuid returns a 0 if successful and a -1 if not successful.

EXAMPLE

The following example illustrates the use of setuid to set the effective user ID to the real user ID:
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/types.h>

  main()
  {
     uid_t realUID, effectiveUID;

     realUID = getuid();
     effectiveUID = geteuid();

     printf("Real user ID = %dn", (int) realUID);
     printf("Effective user ID = %dn", (int) effectiveUID);

     if (realUID != effectiveUID) {
        if (setuid(realUID) != 0)
           perror("setuid() error");
        else
           printf("Effective user ID changed to %d.n", (int) realUID);
     }
  }

 

RELATED FUNCTIONS

geteuid, getuid, seteuid, setgid


Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.