Skip to content

Commit

Permalink
using standardized jbroot
Browse files Browse the repository at this point in the history
  • Loading branch information
roothider committed Apr 29, 2024
1 parent fc3f9f0 commit a7741b4
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 50 deletions.
5 changes: 4 additions & 1 deletion init.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ int bootstrap()
char jbrand[32]={0};
snprintf(jbrand, sizeof(jbrand), "%016llX", randvalue);

char jbroot_standardized[PATH_MAX]={0};
snprintf(jbroot_standardized, sizeof(jbroot_standardized), "%s/%s%s", JB_ROOT_PARENT, JB_ROOT_PREFIX, jbrand);

__roothideinit_JBRAND = strdup(jbrand);
__roothideinit_JBROOT = strdup(jbroot);
__roothideinit_JBROOT = strdup(jbroot_standardized);

free(librealpath);
return 0;
Expand Down
48 changes: 24 additions & 24 deletions vroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ VROOT_LOG("@%s %d %08X %s\n",__FUNCTION__, fd, flags, path);

int VROOT_API_NAME(open_dprotected_np)(const char *path, int flags, int class, int dpflags, ...)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, path);

mode_t mode = 0;
va_list ap;
Expand All @@ -183,7 +183,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

int VROOT_API_NAME(link)(const char *name1, const char *name2)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s : %s\n",__FUNCTION__, name1, name2);

const char* newname1 = jbroot_alloc(name1);
const char* newname2 = jbroot_alloc(name2);
Expand All @@ -195,7 +195,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

int VROOT_API_NAME(symlink)(const char *name1, const char *name2)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s : %s\n",__FUNCTION__, name1, name2);

int ret = 0;
const char* newname2 = jbroot_alloc(name2);
Expand Down Expand Up @@ -233,7 +233,7 @@ VROOT_LOG("@%s %s => %s\n",__FUNCTION__, __old, __new);

int VROOTAT_API_NAME(linkat)(int fd1, const char *name1, int fd2, const char *name2, int flag)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %d %s : %d %s\n",__FUNCTION__, fd1, name1, fd2, name2);

/* flag is for name1 and only support AT_SYMLINK_FOLLOW, but its not about find path */
const char* newname1 = jbrootat_alloc(fd1, name1, 0);
Expand Down Expand Up @@ -270,7 +270,7 @@ VROOT_LOG("@%s %s %d %s\n",__FUNCTION__, name1, fd, name2);

int VROOT_API_NAME(shm_open)(const char * path, int flags, ...)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, path);

mode_t mode = 0;
va_list ap;
Expand All @@ -285,7 +285,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

sem_t* VROOT_API_NAME(sem_open)(const char *path, int flags, ...)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, path);

mode_t mode = 0;
va_list ap;
Expand All @@ -300,7 +300,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

int VROOT_API_NAME(copyfile)(const char * from, const char * to, copyfile_state_t state, copyfile_flags_t flags)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s : %s\n",__FUNCTION__, from, to);

const char* newfrom = jbroot_alloc(from);
const char* newto = jbroot_alloc(to);
Expand All @@ -312,7 +312,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

int VROOTAT_API_NAME(renameat)(int fromfd, const char *from, int tofd, const char *to)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %d %s : %d %s\n",__FUNCTION__, fromfd, from, tofd, to);

const char* newfrom = jbrootat_alloc(fromfd, from, 0);
const char* newto = jbrootat_alloc(tofd, to, 0);
Expand All @@ -324,7 +324,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

int VROOT_API_NAME(renamex_np)(const char *__old, const char *__new, unsigned int flags)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s : %s\n",__FUNCTION__, __old, __new);

const char* new__old = jbroot_alloc(__old);
const char* new__new = jbroot_alloc(__new);
Expand All @@ -336,7 +336,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

int VROOTAT_API_NAME(renameatx_np)(int fromfd, const char *from, int tofd, const char *to, unsigned int flags)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %d %s : %d %s\n",__FUNCTION__, fromfd, from, tofd, to);

const char* newfrom = jbrootat_alloc(fromfd, from, flags);
const char* newto = jbrootat_alloc(tofd, to, flags);
Expand All @@ -348,7 +348,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

int VROOT_API_NAME(exchangedata)(const char * path1,const char * path2,unsigned int options)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s : %s\n",__FUNCTION__, path1, path2);

const char* newpath1 = jbroot_alloc(path1);
const char* newpath2 = jbroot_alloc(path2);
Expand All @@ -360,7 +360,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

char* VROOT_API_NAME(realpath)(const char * path, char *resolved_path)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, path);

char pathbuf[PATH_MAX]={0};
const char* newpath = jbroot_alloc(path);
Expand Down Expand Up @@ -440,7 +440,7 @@ VROOT_LOG("@%s %s\n",__FUNCTION__, path);
#define F_GETCONFINED 96 /* is-fd-confined? */
int VROOT_API_NAME(fcntl)(int fd, int cmd, ...)
{
VROOT_LOG("@%s %d\n",__FUNCTION__, cmd);
VROOT_LOG("@%s %d %d\n",__FUNCTION__, fd, cmd);

va_list ap;
void *arg;
Expand Down Expand Up @@ -510,7 +510,7 @@ VROOT_LOG("@%s %d\n",__FUNCTION__, cmd);

int VROOT_API_NAME(bind)(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %d\n",__FUNCTION__, sockfd);

struct sockaddr_un *addr_un = (struct sockaddr_un *)(addr);
if (addr_un->sun_family == AF_UNIX && addr_un->sun_path[0]) {
Expand Down Expand Up @@ -544,7 +544,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

int VROOT_API_NAME(connect)(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %d\n",__FUNCTION__, sockfd);

struct sockaddr_un *addr_un = (struct sockaddr_un *)(addr);
if (addr_un->sun_family == AF_UNIX && addr_un->sun_path[0]) {
Expand Down Expand Up @@ -579,7 +579,7 @@ VROOT_LOG("@%s %s : %s\n",__FUNCTION__, path, newpath);

int VROOT_API_NAME(getpeername)(int sockfd, struct sockaddr *addr, socklen_t* addrlen)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %d\n",__FUNCTION__, sockfd);

socklen_t origlen = *addrlen;

Expand All @@ -604,7 +604,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);
}
int VROOT_API_NAME(getsockname)(int sockfd, struct sockaddr *addr, socklen_t* addrlen)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %d\n",__FUNCTION__, sockfd);

socklen_t origlen = *addrlen;

Expand Down Expand Up @@ -664,7 +664,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

int VROOT_API_NAME(glob)(const char * pattern, int flags, int (* errfunc) (const char *, int), glob_t * pglob)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, pattern);

int ret = glob(pattern,flags,errfunc,pglob);
if(ret == 0) {
Expand All @@ -686,7 +686,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

int VROOT_API_NAME(glob_b)(const char * pattern, int flags, int (^ errfunc) (const char *, int), glob_t * pglob)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, pattern);

int ret = glob_b(pattern,flags,errfunc,pglob);
if(ret == 0) {
Expand All @@ -709,7 +709,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);
int __thread (*ftw_callback)(const char *fpath, const struct stat *sb, int typeflag);
int ftw_function(const char *fpath, const struct stat *sb, int typeflag)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, fpath);

const char* newpath = rootfs_alloc(fpath);
int ret = ftw_callback(newpath,sb,typeflag);
Expand All @@ -718,7 +718,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);
}
int VROOT_API_NAME(ftw)(const char *dirpath, int (*fn)(const char *fpath, const struct stat *sb, int typeflag), int nopenfd)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, dirpath);

ftw_callback = fn;

Expand All @@ -731,7 +731,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);
int __thread (*nftw_callback)(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
int nftw_function(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, fpath);

const char* newpath = rootfs_alloc(fpath);
int ret = nftw_callback(newpath,sb,typeflag,ftwbuf);
Expand All @@ -741,7 +741,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);
int VROOT_API_NAME(nftw)(const char *dirpath,
int (*fn)(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf), int nopenfd, int flags)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, dirpath);

nftw_callback = fn;

Expand Down Expand Up @@ -861,7 +861,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);

int VROOT_API_NAME(rmdir)(const char * path)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, path);

const char* newpath = jbroot_alloc(path);

Expand Down
2 changes: 1 addition & 1 deletion vroot_dlfcn.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ VROOT_LOG("@%s %s %x\n",__FUNCTION__, __path, __mode);
EXPORT
int VROOT_API_NAME(dladdr)(const void * addr, Dl_info * info)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %p\n",__FUNCTION__, addr);

int ret = dladdr(addr, info);
if(ret != 0 && !_dyld_shared_cache_contains_path(info->dli_fname))
Expand Down
14 changes: 7 additions & 7 deletions vroot_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int _execvpe(const char *name, char * const argv[], char * const envp[]);
EXPORT
int VROOT_API_NAME(execl)(const char *name, const char *arg, ...)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s %s\n",__FUNCTION__, name, arg);

va_list ap;
const char **argv;
Expand Down Expand Up @@ -56,7 +56,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);
EXPORT
int VROOT_API_NAME(execle)(const char *name, const char *arg, ...)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s %s\n",__FUNCTION__, name, arg);

va_list ap;
const char **argv;
Expand Down Expand Up @@ -86,15 +86,15 @@ VROOT_LOG("@%s\n",__FUNCTION__);
EXPORT
int VROOT_API_NAME(execvp)(const char *name, char * const *argv)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, name);

return (_execvpe(name, argv, environ));
}

EXPORT
int VROOT_API_NAME(execlp)(const char *name, const char *arg, ...)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s %s\n",__FUNCTION__, name, arg);

va_list ap;
const char **argv;
Expand Down Expand Up @@ -122,7 +122,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);
EXPORT
int VROOT_API_NAME(execv)(const char *name, char * const *argv)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, name);

(void)_execve(name, argv, environ);
return (-1);
Expand Down Expand Up @@ -266,7 +266,7 @@ retry: (void)_execve(bp, argv, envp);
EXPORT
int VROOT_API_NAME(execvP)(const char *name, const char *path, char * const argv[])
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s %s\n",__FUNCTION__, name, path);

return execvPe(name, path, argv, environ);
}
Expand All @@ -289,7 +289,7 @@ EXPORT
int VROOT_API_NAME(posix_spawnp)(pid_t * pid, const char * file, const posix_spawn_file_actions_t *file_actions,
const posix_spawnattr_t * attrp, char *const argv[], char *const envp[])
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, file);

const char *env_path;
char *bp;
Expand Down
22 changes: 11 additions & 11 deletions vroot_mktemp.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ EXPORT
int
VROOT_API_NAME(mkostemps)(char *path, int slen, int oflags)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s %d\n",__FUNCTION__, path, slen);

int fd;
if (oflags & ~ALLOWED_MKOSTEMP_FLAGS) {
Expand All @@ -106,7 +106,7 @@ EXPORT
int
VROOT_API_NAME(mkostempsat_np)(int dfd, char *path, int slen, int oflags)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %d %s %d\n",__FUNCTION__, dfd, path, slen);

int fd;
if (oflags & ~ALLOWED_MKOSTEMP_FLAGS) {
Expand All @@ -120,7 +120,7 @@ EXPORT
int
VROOT_API_NAME(mkstemps)(char *path, int slen)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s %d\n",__FUNCTION__, path, slen);

int fd;

Expand All @@ -131,7 +131,7 @@ EXPORT
int
VROOT_API_NAME(mkstempsat_np)(int dfd, char *path, int slen)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %d %s %d\n",__FUNCTION__, dfd, path, slen);

int fd;

Expand All @@ -142,7 +142,7 @@ EXPORT
int
VROOT_API_NAME(mkostemp)(char *path, int oflags)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, path);

int fd;
if (oflags & ~ALLOWED_MKOSTEMP_FLAGS) {
Expand All @@ -156,7 +156,7 @@ EXPORT
int
VROOT_API_NAME(mkstemp)(char *path)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, path);

int fd;

Expand All @@ -167,7 +167,7 @@ EXPORT
char *
VROOT_API_NAME(mkdtemp)(char *path)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, path);

return (find_temp_path(AT_FDCWD, path, 0, TRUE, _mkdtemp_action, NULL, NULL) ?
path : (char *)NULL);
Expand All @@ -177,7 +177,7 @@ EXPORT
char *
VROOT_API_NAME(mkdtempat_np)(int dfd, char *path)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %d %s\n",__FUNCTION__, dfd, path);

return (find_temp_path(dfd, path, 0, TRUE, _mkdtemp_action, NULL, NULL) ?
path : (char *)NULL);
Expand All @@ -187,7 +187,7 @@ EXPORT
char *
_mktemp(char *path)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, path);

return (find_temp_path(AT_FDCWD, path, 0, FALSE, _mktemp_action, NULL, NULL) ?
path : (char *)NULL);
Expand All @@ -197,7 +197,7 @@ EXPORT
char *
VROOT_API_NAME(mktemp)(char *path)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, path);

return (_mktemp(path));
}
Expand All @@ -206,7 +206,7 @@ EXPORT
int
VROOT_API_NAME(mkstemp_dprotected_np)(char *path, int class, int dpflags)
{
VROOT_LOG("@%s\n",__FUNCTION__);
VROOT_LOG("@%s %s\n",__FUNCTION__, path);

int fd;
int ctx[2] = { class, dpflags };
Expand Down
Loading

0 comments on commit a7741b4

Please sign in to comment.