Blame support/namespace.h

Packit Service 82fcde
/* Entering namespaces for test case isolation.
Packit Service 82fcde
   Copyright (C) 2016-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#ifndef SUPPORT_NAMESPACE_H
Packit Service 82fcde
#define SUPPORT_NAMESPACE_H
Packit Service 82fcde
Packit Service 82fcde
#include <stdbool.h>
Packit Service 82fcde
#include <sys/cdefs.h>
Packit Service 82fcde
Packit Service 82fcde
__BEGIN_DECLS
Packit Service 82fcde
Packit Service 82fcde
/* Attempts to become root (or acquire root-like privileges), possibly
Packit Service 82fcde
   with the help of user namespaces.  Return true if (restricted) root
Packit Service 82fcde
   privileges could be attained in some way.  Print diagnostics to
Packit Service 82fcde
   standard output.
Packit Service 82fcde
Packit Service 82fcde
   Note that this function generally has to be called before a process
Packit Service 82fcde
   becomes multi-threaded, otherwise it may fail with insufficient
Packit Service 82fcde
   privileges on systems which would support this operation for
Packit Service 82fcde
   single-threaded processes.  */
Packit Service 82fcde
bool support_become_root (void);
Packit Service 82fcde
Packit Service 82fcde
/* Return true if this process can perform a chroot operation.  In
Packit Service 82fcde
   general, this is only possible if support_become_root has been
Packit Service 82fcde
   called.  Note that the actual test is performed in a subprocess,
Packit Service 82fcde
   after fork, so that the file system root of the original process is
Packit Service 82fcde
   not changed.  */
Packit Service 82fcde
bool support_can_chroot (void);
Packit Service 82fcde
Packit Service 82fcde
/* Enter a network namespace (and a UTS namespace if possible) and
Packit Service 82fcde
   configure the loopback interface.  Return true if a network
Packit Service 82fcde
   namespace could be created.  Print diagnostics to standard output.
Packit Service 82fcde
   If a network namespace could be created, but networking in it could
Packit Service 82fcde
   not be configured, terminate the process.  It is recommended to
Packit Service 82fcde
   call support_become_root before this function so that the process
Packit Service 82fcde
   has sufficient privileges.  */
Packit Service 82fcde
bool support_enter_network_namespace (void);
Packit Service 82fcde
Packit Service 82fcde
/* Enter a mount namespace and mark / as private (not shared).  If
Packit Service 82fcde
   this function returns true, mount operations in this process will
Packit Service 82fcde
   not affect the host system afterwards.  */
Packit Service 82fcde
bool support_enter_mount_namespace (void);
Packit Service 82fcde
Packit Service 82fcde
/* Return true if support_enter_network_namespace managed to enter a
Packit Service 82fcde
   UTS namespace.  */
Packit Service 82fcde
bool support_in_uts_namespace (void);
Packit Service 82fcde
Packit Service 82fcde
/* Invoke CALLBACK (CLOSURE) in a subprocess created using fork.
Packit Service 82fcde
   Terminate the calling process if the subprocess exits with a
Packit Service 82fcde
   non-zero exit status.  */
Packit Service 82fcde
void support_isolate_in_subprocess (void (*callback) (void *), void *closure);
Packit Service 82fcde
Packit Service 82fcde
/* Describe the setup of a chroot environment, for
Packit Service 82fcde
   support_chroot_create below.  */
Packit Service 82fcde
struct support_chroot_configuration
Packit Service 82fcde
{
Packit Service 82fcde
  /* File contents.  The files are not created if the field is
Packit Service 82fcde
     NULL.  */
Packit Service 82fcde
  const char *resolv_conf;      /* /etc/resolv.conf.  */
Packit Service 82fcde
  const char *hosts;            /* /etc/hosts.  */
Packit Service 82fcde
  const char *host_conf;        /* /etc/host.conf.  */
Packit Service 82fcde
};
Packit Service 82fcde
Packit Service 82fcde
/* The result of the creation of a chroot.  */
Packit Service 82fcde
struct support_chroot
Packit Service 82fcde
{
Packit Service 82fcde
  /* Path information.  All these paths are relative to the parent
Packit Service 82fcde
     chroot.  */
Packit Service 82fcde
Packit Service 82fcde
  /* Path to the chroot directory.  */
Packit Service 82fcde
  char *path_chroot;
Packit Service 82fcde
Packit Service 82fcde
  /* Paths to files in the chroot.  These are absolute and outside of
Packit Service 82fcde
     the chroot.  */
Packit Service 82fcde
  char *path_resolv_conf;       /* /etc/resolv.conf.  */
Packit Service 82fcde
  char *path_hosts;             /* /etc/hosts.  */
Packit Service 82fcde
  char *path_host_conf;         /* /etc/host.conf.  */
Packit Service 82fcde
};
Packit Service 82fcde
Packit Service 82fcde
/* Create a chroot environment.  The returned data should be freed
Packit Service 82fcde
   using support_chroot_free below.  The files will be deleted when
Packit Service 82fcde
   the process exits.  This function does not enter the chroot.  */
Packit Service 82fcde
struct support_chroot *support_chroot_create
Packit Service 82fcde
  (struct support_chroot_configuration);
Packit Service 82fcde
Packit Service 82fcde
/* Deallocate the chroot information created by
Packit Service 82fcde
   support_chroot_create.  */
Packit Service 82fcde
void support_chroot_free (struct support_chroot *);
Packit Service 82fcde
Packit Service 82fcde
__END_DECLS
Packit Service 82fcde
Packit Service 82fcde
#endif