1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/*
* libsb2 -- scratchbox2 preload library
*
* Copyright (C) 2006,2007 Lauri Leukkunen <lle@rahina.org>
* parts contributed by
* Riku Voipio <riku.voipio@movial.com>
* Toni Timonen <toni.timonen@movial.com>
*
* Heavily based on the libfakechroot library by
* Piotr Roszatycki <dexter@debian.org>
*/
/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef LIBSB2_H_INCLUDED_
#define LIBSB2_H_INCLUDED_
#include "config.h"
#include "config_hardcoded.h"
#define __BSD_VISIBLE
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/times.h>
#include <sys/utsname.h>
//#include <asm/unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdarg.h>
#include <dirent.h>
#include <string.h>
#include <glob.h>
#include <utime.h>
#ifdef HAVE_FTS_H
#include <fts.h>
#endif
#ifdef HAVE_FTW_H
#include <ftw.h>
#endif
#ifdef HAVE_SHADOW_H
#include <shadow.h>
#endif
#ifdef HAVE_SYS_XATTR_H
#include <sys/xattr.h>
#endif
//#include <elf.h>
#include <sys/user.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/resource.h>
#include <glob.h>
#include <mapping.h>
#include <sb2.h>
#include "externs.h"
#if defined(PATH_MAX)
#define SBOX_MAXPATH PATH_MAX
#elif defined(_POSIX_PATH_MAX)
#define SBOX_MAXPATH _POSIX_PATH_MAX
#elif defined(MAXPATHLEN)
#define SBOX_MAXPATH MAXPATHLEN
#else
#define SBOX_MAXPATH 2048
#endif
/* XXX: current code allows ./usr/bin/../../../../../ style escaping
* from chroot
* if ( amount /../ > amount /other/ ) ) remove extra /../
*/
#define SBOX_MAP_PROLOGUE() \
char *sbox_path = NULL;
#define SBOX_MAP_AT_PROLOGUE() \
char *sbox_path = NULL;
#define SBOX_MAP_PATH_NARROW(path, sbox_path, readonly_flag_addr) \
{ \
if ((path) != NULL && *((char *)(path)) != '\0') { \
sbox_path = scratchbox_path(__FUNCTION__, path, readonly_flag_addr); \
} \
}
#define SBOX_MAP_PATH(path, sbox_path, readonly_flag_addr, no_symlink_resolve) \
{ \
if ((path) != NULL) { \
sbox_path = scratchbox_path(__FUNCTION__, path, readonly_flag_addr, no_symlink_resolve); \
} \
}
#define SBOX_MAP_PATH_AT(dirfd, path, sbox_path, readonly_flag_addr, no_symlink_resolve) \
{ \
if ((path) != NULL) { \
sbox_path = scratchbox_path_at(__FUNCTION__, dirfd, path, \
readonly_flag_addr, no_symlink_resolve); \
} \
}
extern void *sbox_find_next_symbol(int log_enabled, const char *functname);
extern int fopen_mode_w_perm(const char *mode);
extern int freopen_errno(FILE *stream);
extern int do_glob (const char *pattern, int flags,
int (*errfunc) (const char *, int), glob_t *pglob);
#ifdef HAVE_GLOB64
extern int do_glob64 (const char *pattern, int flags,
int (*errfunc) (const char *, int), glob64_t *pglob);
#endif
extern int sb_execvep(const char *file, char *const argv[], char *const envp[]);
extern char *strvec_to_string(char *const *argv);
#endif /* ifndef LIBSB2_H_INCLUDED_ */
|