#include #include #include #include #define _FCNTL_H #include #undef _FCNTL_H #ifdef __linux__ #include #endif #ifdef __GNUC__ extern char * program_invocation_name; #endif #define SYS_HEADER_PATH "/usr/include" #define CONFIGURE_NAME "./configure" #define SH_NAME "/bin/sh" inline char * get_argv1(void); inline char * get_argv1_linux(void); int open64(const char *pathname, int flags, ...); int open64(const char *pathname, int flags, ...) { int modes = 0; // printf("Our name is: %s\n", program_invocation_name); if(! strncmp(program_invocation_name, SH_NAME, sizeof(SH_NAME) - 1)) { if(! strncmp(get_argv1(), CONFIGURE_NAME, sizeof(CONFIGURE_NAME) - 1)) { if(! strncmp(pathname, SYS_HEADER_PATH, sizeof(SYS_HEADER_PATH) - 1)) { // execlp("apt-get", "install", ); // 1) Check to see if header is in the database // 2) Fork if it's not, parent process waits on child // 3) Child execs process to grab and install the package // 4) Parent's wait unblocks and execution continues } } } if(flags & O_CREAT) { va_list list; va_start(list, flags); modes = va_arg(list, int); va_end(list); return syscall(SYS_open, pathname, flags, modes); } return syscall(SYS_open, pathname, flags); } inline char * get_argv1(void) { #ifdef linux return get_argv1_linux(); #else #error No method of retrieving the original command line has been implemented for this platform. #endif } static char buf[256]; inline char * get_argv1_linux(void) { int rc; memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf) - 1, "/proc/%i/cmdline", getpid()); rc = syscall(SYS_open, &buf, O_RDONLY); if(rc == -1) { #if 0 fprintf(stderr, "*** INTERNAL BLDDEPS ERROR: could not retrieve original command line via\n" "procfs. If the proc filesystem is not mounted, then you can mount it\n" "with this command:\n\n" "# mount -t proc proc /proc"); exit(1); #endif /* 0 */ /* blddeps is probably not supposed to be that anal. */ printf("Aiee!: %s\n", strerror(rc)); return NULL; } // We're reusing the path buffer here for performance reasons read(rc, buf, sizeof(buf) - 1); buf[256] = '\0'; return (strchr(buf, '\0') + 1); // return buf; }