1 /*
2   Created: 03.19.05 11:15:21 by Attila Nagyidai
3 
4   $Id: C\040Header.h,v 1.1.2.1 2003/08/13 00:38:46 neum Exp $
5 
6   This file is part of IBSH (Iron Bars Shell) , a restricted Unix shell
7   Copyright (C) 2005  Attila Nagyidai
8 
9   This program is free software; you can redistribute it and/or
10   modify it under the terms of the GNU General Public License
11   as published by the Free Software Foundation; either version 2
12   of the License, or (at your option) any later version.
13 
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18 
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software
21   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 
23   Author: Attila Nagyidai
24   Email: na@ent.hu
25 
26   Co-Author: Shy
27   Email: shy@cpan.org
28 
29   URL: http://ibsh.sourceforge.net
30   IRC: irc.freenode.net #ibsh
31   RSS, Statistics, etc: http://sourceforge.net/projects/ibsh/
32 
33 */
34 
35 #ifndef _IBSH_H
36 #define _IBSH_H
37 
38 /* Insert Code here */
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <time.h>
43 #include <unistd.h>
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #include <sys/wait.h>
47 #include <syslog.h>
48 #include <fcntl.h>
49 #include <errno.h>
50 #include <dirent.h>
51 #include <pwd.h>
52 #include <grp.h>
53 #include <limits.h>
54 #include <glob.h>
55 #include <signal.h>
56 
57 #define PAM_SIZE    8
58 #define LINE_SIZE   80
59 #define STRING_SIZE 255
60 #define BUFFER_SIZE 4096
61 #define PATH_MAXb 4096
62 #define MAX_ITEMS   50
63 #define COMMANDS_DIR "/usr/local/etc/ibsh/cmds"
64 #define COMMANDS_FILE "/usr/local/etc/ibsh/globals.cmds"
65 #define EXTENSIONS_DIR "/usr/local/etc/ibsh/xtns"
66 #define EXTENSIONS_FILE "/usr/local/etc/ibsh/globals.xtns"
67 
68 /* Antixploit */
69 #define C_CODE  "#include"
70 #define SHELL_CODE  "#!/"
71 #define PYTHON_CODE "import"
72 #define ADA_CODE  "package body"
73 #define EIFFEL_CODE "feature --"
74 #define LISP_CODE "(defun"
75 #define ELF_CODE "ELF"
76 
77 /* Logging */
78 #define OPENLOG     openlog("ibsh", LOG_PID, LOG_AUTH)
79 #define CLOSELOG    closelog()
80 
81 /* Typedefs, structs, globals */
82 typedef struct theuser {
83     char uname[STRING_SIZE];
84     uid_t uid;
85     char udir[STRING_SIZE];
86     struct passwd *record;
87 } theuser;
88 
89 typedef char Strng[STRING_SIZE];
90 
91 extern theuser loggedin; /* user info */
92 
93 extern Strng commands[MAX_ITEMS];    /* permitted commands */
94 extern Strng extensions[MAX_ITEMS];  /* permitted extensions */
95 extern char real_path[STRING_SIZE];  /* absolute path */
96 extern char jail_path[STRING_SIZE];  /* path inside the jail */
97 extern char user_command[STRING_SIZE];     /* whatever the user types */
98 extern char filtered_command[STRING_SIZE]; /* this one will be executed */
99 extern int exitcode;
100 extern char **environ;
101 
102 
103 int CommandOK( const char *thecommand, const char *rootdir,
104 const char *jailpath, char *newcommand );
105 void LTrim3( const char *base, char *result );
106 void GetPositionInJail( const char *abspath, const char *rootdir, char *relpath );
107 int LoadConfig( void );
108 void myscanf( char *vptr, char *abspath );
109 int  hhsystem(const char *kdozeile);
110 void PathMinusOne( const char *basepath, char *evalpath, int slashcount,size_t nevalpath);
111 void log_attempt( const char *username );
112 int nbspace(const char *command);
113 void lshift( char *line );
114 int antixploit( const char *abspath, char *token );
115 void logPrintBadfile (const char * msg);
116 int removeAllRights (const char * filename, struct stat * s);
117 int makeUnexecutable (const char * filename, struct stat * s);
118 int hasSomeRwxRights (struct stat * s);
119 int isExecutable (struct stat * s);
120 int symlinkGoesOuttaJail (const char * sl);
121 void DelBadFiles (const char *basedir);
122 
123 
124 #endif /* _IBSH_H */
125