• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/procd/jail/preload.c

  1 /*
  2  * Copyright (C) 2015 John Crispin <blogic@openwrt.org>
  3  *
  4  * This program is free software; you can redistribute it and/or modify
  5  * it under the terms of the GNU Lesser General Public License version 2.1
  6  * as published by the Free Software Foundation
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 11  * GNU General Public License for more details.
 12  */
 13 
 14 #define _GNU_SOURCE
 15 #include <sys/types.h>
 16 #include <stdlib.h>
 17 #include <unistd.h>
 18 #include <string.h>
 19 #include <dlfcn.h>
 20 
 21 #include "log.h"
 22 #include "seccomp.h"
 23 #include "../preload.h"
 24 
 25 static main_t __main__;
 26 int debug;
 27 
 28 static int __preload_main__(int argc, char **argv, char **envp)
 29 {
 30         char *env_file = getenv("SECCOMP_FILE");
 31         char *env_debug = getenv("SECCOMP_DEBUG");
 32 
 33         if (!env_file || !env_file[0]) {
 34                 ERROR("SECCOMP_FILE not specified\n");
 35                 return -1;
 36         }
 37 
 38         if (env_debug)
 39                 debug = atoi(env_debug);
 40         else
 41                 debug = 0;
 42 
 43         if (install_syscall_filter(*argv, env_file))
 44                 return -1;
 45 
 46         unsetenv("LD_PRELOAD");
 47         unsetenv("SECCOMP_DEBUG");
 48         unsetenv("SECCOMP_FILE");
 49 
 50         return (*__main__)(argc, argv, envp);
 51 }
 52 
 53 int __libc_start_main(main_t main,
 54                         int argc,
 55                         char **argv,
 56                         ElfW(auxv_t) *auxvec,
 57                         __typeof (main) init,
 58                         void (*fini) (void),
 59                         void (*rtld_fini) (void),
 60                         void *stack_end)
 61 {
 62         start_main_t __start_main__;
 63 
 64         __start_main__ = dlsym(RTLD_NEXT, "__libc_start_main");
 65         if (!__start_main__) {
 66                 INFO("failed to find __libc_start_main %s\n", dlerror());
 67                 return -1;
 68         }
 69 
 70         __main__ = main;
 71 
 72         return (*__start_main__)(__preload_main__, argc, argv, auxvec,
 73                 init, fini, rtld_fini, stack_end);
 74 }
 75 
 76 void __uClibc_main(main_t main,
 77                         int argc,
 78                         char **argv,
 79                         void (*app_init)(void),
 80                         void (*app_fini)(void),
 81                         void (*rtld_fini)(void),
 82                         void *stack_end attribute_unused)
 83 {
 84         uClibc_main __start_main__;
 85 
 86         __start_main__ = dlsym(RTLD_NEXT, "__uClibc_main");
 87         if (!__start_main__) {
 88                 INFO("failed to find __uClibc_main %s\n", dlerror());
 89                 return;
 90         }
 91 
 92         __main__ = main;
 93 
 94         return (*__start_main__)(__preload_main__, argc, argv,
 95                 app_init, app_fini, rtld_fini, stack_end);
 96 }
 97 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt