00001 // Copyright (C) 2006-2007 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU General Public License 00005 // as published by the Free Software Foundation; either version 2 00006 // of the License, or (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00016 00017 /*! 00018 * @defgroup chroot Secure chroot wrappers 00019 * 00020 * The chroot system call changes the root directory of the current process. 00021 * This directory will be used for pathnames beginning with /. The root 00022 * directory is inherited by all children of the current process. 00023 * 00024 * The chroot family of functions provide wrappers for other library functions 00025 * to happen in a chroot while the caller still remains in the old root after 00026 * the functions have returned. 00027 * 00028 * One can break out of the chroot in many ways due to the nature of the chroot 00029 * system call: 00030 * 00031 * - This call changes an ingredient in the pathname resolution process and does 00032 * nothing else. 00033 * - This call does not change the current working directory. 00034 * - This call does not close open file descriptors. 00035 * 00036 * The main usage of these functions is to get a file descriptor, safe against 00037 * symlink attacks, reffering to a directory inside a new root. 00038 * @{ 00039 */ 00040 00041 #ifndef _LUCID_CHROOT_H 00042 #define _LUCID_CHROOT_H 00043 00044 #include <sys/types.h> 00045 00046 /*! 00047 * @brief chroot(2) to the directory pointed to by a filedescriptor 00048 * 00049 * @param[in] fd file descriptor refering to a directory (fchdir(2)) 00050 * 00051 * @return 0 on success, -1 on error with errno set 00052 * 00053 * @see chroot(2) 00054 * @see fchdir(2) 00055 */ 00056 int chroot_fd(int fd); 00057 00058 /*! 00059 * @brief recursive mkdir(2) inside a secure chroot 00060 * 00061 * @param[in] root new root path 00062 * @param[in] dir dir to be created in root 00063 * @param[in] mode file permissions 00064 * 00065 * @return 0 on success, -1 on error with errno set 00066 * 00067 * @see chroot_secure_chdir 00068 * @see mkdir(2) 00069 */ 00070 int chroot_mkdirp(const char *root, const char *dir, mode_t mode); 00071 00072 /*! 00073 * @brief symlink-attack safe chdir(2) in chroot(2) 00074 * 00075 * @param[in] root new root path 00076 * @param[in] dir dir to chdir(2) in root 00077 * 00078 * @return 0 on success, -1 on error with errno set 00079 * 00080 * @see chroot(2) 00081 * @see chdir(2) 00082 */ 00083 int chroot_secure_chdir(const char *root, const char *dir); 00084 00085 #endif 00086 00087 /*! @} chroot */