Back to index

glibc  2.9
Defines | Functions | Variables
euidaccess.c File Reference
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>

Go to the source code of this file.

Defines

#define __set_errno(val)   errno = (val)
#define F_OK   0
#define X_OK   1
#define W_OK   2
#define R_OK   4
#define S_IROTH   R_OK
#define S_IWOTH   W_OK
#define S_IXOTH   X_OK
#define group_member(gid)   0

Functions

uid_t getuid ()
gid_t getgid ()
uid_t geteuid ()
gid_t getegid ()
int euidaccess (char *path, int mode) const

Variables

int errno
static uid_t uid
static gid_t gid
static uid_t euid
static gid_t egid
static int have_ids

Define Documentation

#define __set_errno (   val)    errno = (val)

Definition at line 58 of file euidaccess.c.

#define F_OK   0

Definition at line 66 of file euidaccess.c.

#define group_member (   gid)    0

Definition at line 108 of file euidaccess.c.

#define R_OK   4

Definition at line 69 of file euidaccess.c.

#define S_IROTH   R_OK

Definition at line 73 of file euidaccess.c.

#define S_IWOTH   W_OK

Definition at line 76 of file euidaccess.c.

#define S_IXOTH   X_OK

Definition at line 79 of file euidaccess.c.

#define W_OK   2

Definition at line 68 of file euidaccess.c.

#define X_OK   1

Definition at line 67 of file euidaccess.c.


Function Documentation

int euidaccess ( char *  path,
int  mode 
) const

Definition at line 121 of file euidaccess.c.

{
  struct stat64 stats;
  int granted;

#ifdef _LIBC
  uid_t euid;
  gid_t egid;
#else
  if (have_ids == 0)
    {
      have_ids = 1;
      uid = getuid ();
      gid = getgid ();
      euid = geteuid ();
      egid = getegid ();
    }

  if (uid == euid && gid == egid)
    /* If we are not set-uid or set-gid, access does the same.  */
    return access (path, mode);
#endif

  if (stat64 (path, &stats))
    return -1;

  mode &= (X_OK | W_OK | R_OK);    /* Clear any bogus bits. */
#if R_OK != S_IROTH || W_OK != S_IWOTH || X_OK != S_IXOTH
  ?error Oops, portability assumptions incorrect.
#endif

  if (mode == F_OK)
    return 0;               /* The file exists. */

#ifdef _LIBC
  /* Now we need the IDs.  */
  euid = __geteuid ();
  egid = __getegid ();

  if (__getuid () == euid && __getgid () == egid)
    /* If we are not set-uid or set-gid, access does the same.  */
    return __access (path, mode);
#endif

  /* The super-user can read and write any file, and execute any file
     that anyone can execute. */
  if (euid == 0 && ((mode & X_OK) == 0
                  || (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))))
    return 0;

  if (euid == stats.st_uid)
    granted = (unsigned int) (stats.st_mode & (mode << 6)) >> 6;
  else if (egid == stats.st_gid || group_member (stats.st_gid))
    granted = (unsigned int) (stats.st_mode & (mode << 3)) >> 3;
  else
    granted = (stats.st_mode & mode);
  /* XXX Add support for ACLs.  */
  if (granted == mode)
    return 0;
  __set_errno (EACCESS);
  return -1;
}

Here is the call graph for this function:


Variable Documentation

gid_t egid [static]

Definition at line 100 of file euidaccess.c.

Definition at line 22 of file sysdep.c.

uid_t euid [static]

Definition at line 97 of file euidaccess.c.

gid_t gid [static]

Definition at line 94 of file euidaccess.c.

int have_ids [static]

Definition at line 103 of file euidaccess.c.

uid_t uid [static]

Definition at line 91 of file euidaccess.c.