1 /* 2 Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013 Olivier Sessink 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions 7 are met: 8 * Redistributions of source code must retain the above copyright 9 notice, this list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above 11 copyright notice, this list of conditions and the following 12 disclaimer in the documentation and/or other materials provided 13 with the distribution. 14 * The names of its contributors may not be used to endorse or 15 promote products derived from this software without specific 16 prior written permission. 17 18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 POSSIBILITY OF SUCH DAMAGE. 30 31 */ 32 33 #ifndef __JK_LIB_H 34 #define __JK_LIB_H 35 36 #include "config.h" 37 38 #ifdef DEBUG 39 #define DEBUG_MSG printf 40 #else 41 #define DEBUG_MSG(args...) 42 /**/ 43 #endif 44 45 #ifdef DEBUG 46 #define DEBUG_LOG(args...) syslog(LOG_DEBUG, args) 47 #else 48 #define DEBUG_LOG(args...) 49 /**/ 50 #endif 51 52 #ifndef HAVE_MALLOC0 53 #define malloc0(size) memset(malloc(size),0,size) 54 #define HAVE_MALLOC0 55 #endif /* HAVE_MALLOC0 */ 56 57 58 #define TESTPATH_NOREGPATH 1 // (0000 0001) 59 #define TESTPATH_GROUPW 2 // (0000 0010) 60 #define TESTPATH_OTHERW 4 // (0000 0100) 61 #define TESTPATH_SETUID 8 // (0000 1000) 62 #define TESTPATH_SETGID 16 // (0001 0000) 63 #define TESTPATH_OWNER 32 // (0010 0000) 64 #define TESTPATH_GROUP 64 // (0100 0000) 65 66 int file_exists(const char *path); 67 char *implode_array(char **arr, int arrlen, const char *delimiter); 68 char *ending_slash(const char *src); 69 int testsafepath(const char *path, int owner, int group); 70 int basicjailissafe(const char *path); 71 int dirs_equal(const char *dir1, const char *dir2); 72 int getjaildir(const char *oldhomedir, char **jaildir, char **newhomedir); 73 char *strip_string(char * string); 74 int count_char(const char *string, char lookfor); 75 char **explode_string(const char *string, char delimiter); 76 int count_array(char **arr); 77 void free_array(char **arr); 78 79 #endif /* __JK_LIB_H */ 80