X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Flibacess-native.so_src%2Fmain.c;h=f0728643c0ceff2e67ea9ef14ce1f3c0db241457;hb=27cb4fff4ed854d8be598a1157265c6de8aa035a;hp=4bf908bf84d664bce995058657870c9004f6dfa0;hpb=802447e3e329c7519643f03094be9e18c62878ad;p=tpg%2Facess2.git diff --git a/AcessNative/libacess-native.so_src/main.c b/AcessNative/libacess-native.so_src/main.c index 4bf908bf..f0728643 100644 --- a/AcessNative/libacess-native.so_src/main.c +++ b/AcessNative/libacess-native.so_src/main.c @@ -1,19 +1,59 @@ /* */ #include +#include #include +#include + +extern int giSyscall_ClientID; +extern void Request_Preinit(void); +extern int acess__SysOpen(const char *Path, unsigned int flags); #ifdef __WINDOWS__ int DllMain(void) { + fprintf(stderr, "TODO: Windows libacessnative setup\n"); return 0; } #endif #ifdef __linux__ -int main(int argc, char *argv[], char **envp) +int __attribute__ ((constructor)) libacessnative_init(void); + +int libacessnative_init(void) { + Request_Preinit(); + + const char *preopens = getenv("AN_PREOPEN"); + if( preopens ) + { + while( *preopens ) + { + const char *splitter = strchr(preopens, ':'); + size_t len; + if( !splitter ) { + len = strlen(preopens); + } + else { + len = splitter - preopens; + } + char path[len+1]; + memcpy(path, preopens, len); + path[len] = 0; + int fd = acess__SysOpen(path, 6); // WRITE,READ,no EXEC + if( fd == -1 ) { + fprintf(stderr, "Unable to preopen '%s'\n", path); + } + + if( !splitter ) + break; + preopens = splitter + 1; + } + } + +// if( !getenv("ACESSNATIVE_ID") + return 0; } #endif @@ -39,3 +79,11 @@ void Warning(const char *format, ...) printf("\n"); } +void __libc_csu_fini() +{ +} + +void __libc_csu_init() +{ +} +