00001 // Copyright 2006 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (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 00015 // Free Software Foundation, Inc., 00016 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 /*! 00019 * @defgroup chroot Secure chroot wrappers 00020 * 00021 * The chroot system call changes the root directory of the current process. 00022 * This directory will be used for pathnames beginning with /. The root 00023 * directory is inherited by all children of the current process. 00024 * 00025 * The chroot family of functions provide wrappers for other library functions 00026 * to happen in a chroot while the caller still remains in the old root after 00027 * the functions have returned. 00028 * 00029 * One can break out of the chroot in many ways due to the nature of the chroot 00030 * system call: 00031 * 00032 * - This call changes an ingredient in the pathname resolution process and does 00033 * nothing else. 00034 * - This call does not change the current working directory. 00035 * - This call does not close open file descriptors. 00036 * 00037 * The main usage of these functions is to get a file descriptor, safe against 00038 * symlink attacks, reffering to a directory inside a new root. 00039 * @{ 00040 */ 00041 00042 #ifndef _LUCID_CHROOT_H 00043 #define _LUCID_CHROOT_H 00044 00045 #include <sys/types.h> 00046 00047 /*! 00048 * @brief chroot(2) to the directory pointed to by a filedescriptor 00049 * 00050 * @param[in] fd file descriptor refering to a directory (fchdir(2)) 00051 * 00052 * @return 0 on success, -1 on error with errno set 00053 * 00054 * @see chroot(2) 00055 * @see fchdir(2) 00056 */ 00057 int chroot_fd(int fd); 00058 00059 /*! 00060 * @brief recursive mkdir(2) inside a secure chroot 00061 * 00062 * @param[in] root new root path 00063 * @param[in] dir dir to be created in root 00064 * @param[in] mode file permissions 00065 * 00066 * @return 0 on success, -1 on error with errno set 00067 * 00068 * @see chroot_secure_chdir 00069 * @see mkdir(2) 00070 */ 00071 int chroot_mkdirp(const char *root, const char *dir, mode_t mode); 00072 00073 /*! 00074 * @brief symlink-attack safe chdir(2) in chroot(2) 00075 * 00076 * @param[in] root new root path 00077 * @param[in] dir dir to chdir(2) in root 00078 * 00079 * @return 0 on success, -1 on error with errno set 00080 * 00081 * @see chroot(2) 00082 * @see chdir(2) 00083 */ 00084 int chroot_secure_chdir(const char *root, const char *dir); 00085 00086 #endif 00087 00088 /*! @} chroot */