Back to index

glibc  2.9
Defines | Functions
check_fds.c File Reference
#include <fcntl.h>
#include <paths.h>
#include <unistd.h>
#include <hurd.h>
#include <hurd/fd.h>
#include <set-hooks.h>
#include <abort-instr.h>

Go to the source code of this file.

Defines

#define ABORT_INSTRUCTION

Functions

static void check_one_fd (int fd, int mode)
static void check_standard_fds (void)
static void init_standard_fds (void)
 text_set_element (_hurd_fd_subinit, init_standard_fds)
void __libc_check_standard_fds (void)

Define Documentation

Definition at line 33 of file check_fds.c.


Function Documentation

void __libc_check_standard_fds ( void  )

Definition at line 99 of file check_fds.c.

{
  /* We don't check the standard file descriptors here.  They will be
     checked when we initialize the file descriptor table, as part of
     the _hurd_fd_subinit hook.
     
     This function is only present to make sure that this module gets
     linked in when part of the static libc.  */
}

Here is the call graph for this function:

static void check_one_fd ( int  fd,
int  mode 
) [static]

Definition at line 37 of file check_fds.c.

{
  struct hurd_fd *d;

  d = _hurd_fd_get (fd);
  if (d == NULL)
    {
      /* This descriptor hasn't been opened.  We try to allocate the
         descriptor and open /dev/null on it so that the SUID program
         we are about to start does not accidently use this
         descriptor.  */
      d = _hurd_alloc_fd (NULL, fd);
      if (d != NULL)
       {
         mach_port_t port;

         port = __file_name_lookup (_PATH_DEVNULL, mode, 0);
         if (port)
           {
             /* Since /dev/null isn't supposed to be a terminal, we
               avoid any ctty magic.  */
             d->port.port = port;
             d->flags = 0;

             __spin_unlock (&d->port.lock);
             return;
           }
       }
      
      /* We cannot even give an error message here since it would run
        into the same problems.  */
      while (1)
       /* Try for ever and ever.  */
       ABORT_INSTRUCTION;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void check_standard_fds ( void  ) [static]

Definition at line 75 of file check_fds.c.

{
  /* Check all three standard file descriptors.  */
  check_one_fd (STDIN_FILENO, O_RDONLY);
  check_one_fd (STDOUT_FILENO, O_RDWR);
  check_one_fd (STDERR_FILENO, O_RDWR);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_standard_fds ( void  ) [static]

Definition at line 84 of file check_fds.c.

{
  /* Now that we have FDs, make sure that, if this is a SUID program,
     FDs 0, 1 and 2 are allocated.  If necessary we'll set them up
     ourselves.  If that's not possible we stop the program.  */
  if (__builtin_expect (__libc_enable_secure, 0))
    check_standard_fds ();

  (void) &init_standard_fds;       /* Avoid "defined but not used" warning.  */
}

Here is the call graph for this function:

text_set_element ( _hurd_fd_subinit  ,
init_standard_fds   
)