update additional files, see #2418

git-svn-id: file:///home/svn/framework3/trunk@10156 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Joshua Drake 2010-08-26 07:25:15 +00:00
parent 067830a8d0
commit 778ee60d2c
8 changed files with 95 additions and 53 deletions

View File

@ -10,9 +10,43 @@
#include "resource/resource.h" #include "resource/resource.h"
#else #else
#include "../stdapi.h" #include "../stdapi.h"
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <netdb.h> #include <netdb.h>
#include <netinet/in.h>
#include <stdarg.h>
#define IN_ADDR struct in_addr
#define SOCKADDR_IN struct sockaddr_in
#define SOCKADDR struct sockaddr
#define WSAEventSelect(a,b,c) (0xcafebabe)
#define SOCKET_ERROR (-1)
#define WSAGetLastError() errno
#define WSAECONNRESET ECONNRESET
#define WSAECONNABORTED ECONNABORTED
#define BREAK_WITH_ERROR(format, args...) \
do { \
dprintf(format, ## args); \
exit(0); \
} while(0) \
#define BREAK_ON_WSAERROR(format, args...) \
do { \
dprintf(format, ## args); \
abort(); \
} while(0) \
#define Sleep(x) usleep(x * 1000)
#define WSASocket(a,b,c,d,e,f) socket(a,b,c)
#define WSACreateEvent() (0x5a5a5a5a)
#define WSA_INVALID_EVENT (0xa5a5a5a5)
#define WSAResetEvent(x)
#define ResetEvent(x)
#endif #endif

View File

@ -15,6 +15,8 @@ request_core_loadlib(Remote *remote, Packet *packet)
do do
{ {
Tlv dataTlv;
libraryPath = packet_get_tlv_value_string(packet, libraryPath = packet_get_tlv_value_string(packet,
TLV_TYPE_LIBRARY_PATH); TLV_TYPE_LIBRARY_PATH);
flags = packet_get_tlv_value_uint(packet, flags = packet_get_tlv_value_uint(packet,
@ -26,62 +28,49 @@ request_core_loadlib(Remote *remote, Packet *packet)
break; break;
} }
// If the lib does not exist locally, but is being uploaded... if(flags & LOAD_LIBRARY_FLAG_LOCAL) {
if (!(flags & LOAD_LIBRARY_FLAG_LOCAL)) { // i'd be surprised if we could load
Tlv dataTlv; // libraries off the remote system without breaking severely.
res = ERROR_NOT_SUPPORTED;
// Get the library's file contents break;
if ((packet_get_tlv(packet, TLV_TYPE_DATA,
&dataTlv) != ERROR_SUCCESS) ||
(!(targetPath = packet_get_tlv_value_string(packet,
TLV_TYPE_TARGET_PATH)))) {
res = ERROR_INVALID_PARAMETER;
break;
}
// If the library is not to be stored on disk,
if (!(flags & LOAD_LIBRARY_FLAG_ON_DISK)) {
library = dlopenbuf(NULL, dataTlv.buffer, dataTlv.header.length );
res = (library) ? ERROR_SUCCESS : ERROR_NOT_FOUND;
//Taken from buffer_to_file (should be changed to random)
targetPath = "/tmp/foo";
} else {
// Otherwise, save the library buffer to disk
res = buffer_to_file(targetPath, dataTlv.buffer,
dataTlv.header.length);
}
// Override the library path
libraryPath = targetPath;
} }
// If a previous operation failed, break out. // Get the library's file contents
if (res != ERROR_SUCCESS) if ((packet_get_tlv(packet, TLV_TYPE_DATA,
&dataTlv) != ERROR_SUCCESS) ||
(!(targetPath = packet_get_tlv_value_string(packet,
TLV_TYPE_TARGET_PATH)))) {
res = ERROR_INVALID_PARAMETER;
break; break;
}
// Load the library
if ((!library) && (library = dlopen(targetPath, RTLD_GLOBAL|RTLD_LAZY)) == NULL)
res = GetLastError();
else dprintf("[%s] targetPath: %s", __FUNCTION__, targetPath);
res = ERROR_SUCCESS;
library = dlopenbuf(targetPath, dataTlv.buffer, dataTlv.header.length );
dprintf("[%s] dlopenbuf(%s): %08x / %s", __FUNCTION__, targetPath, library, dlerror());
if(! library) {
res = ERROR_NOT_FOUND;
break;
}
// If this library is supposed to be an extension library, try to // If this library is supposed to be an extension library, try to
// call its Init routine // call its Init routine
if ((flags & LOAD_LIBRARY_FLAG_EXTENSION) && (library)){ if (flags & LOAD_LIBRARY_FLAG_EXTENSION) {
DWORD (*init)(Remote *remote); DWORD (*init)(Remote *remote);
init = dlsym(library, "InitServerExtension" ); init = dlsym(library, "InitServerExtension" );
// Call the init routine in the library // Call the init routine in the library
if( init ) if( init ) {
dprintf("[%s] calling InitServerExtension", __FUNCTION__);
res = init(remote); res = init(remote);
}
} }
} while (0); } while (0);
if (response) { if (response) {
packet_add_tlv_uint(response, TLV_TYPE_RESULT, res); packet_add_tlv_uint(response, TLV_TYPE_RESULT, res);
packet_transmit(remote, response, NULL); packet_transmit(remote, response, NULL);
} }
return (res); return (res);

View File

@ -20,10 +20,13 @@ libcrypto.h: ../../bionic/compiled/libcrypto.so
libssl.h: ../../bionic/compiled/libssl.so libssl.h: ../../bionic/compiled/libssl.so
../../../tools/so2h.pl ../../bionic/compiled/libssl.so libssl ../../../tools/so2h.pl ../../bionic/compiled/libssl.so libssl
libsupport.h: ../../bionic/compiled/libsupport.so
../../../tools/so2h.pl ../../bionic/compiled/libsupport.so libsupport
metsrv_main.h: ../../bionic/compiled/metsrv_main metsrv_main.h: ../../bionic/compiled/metsrv_main
../../../tools/so2h.pl ../../bionic/compiled/metsrv_main metsrv_main ../../../tools/so2h.pl ../../bionic/compiled/metsrv_main metsrv_main
metsrv_rtld.o: libc.h libm.h libcrypto.h libssl.h metsrv_main.h metsrv_rtld.o: libc.h libm.h libcrypto.h libssl.h metsrv_main.h libsupport.h
test: $(OBJ) test: $(OBJ)
gcc $(CFLAGS) -o msflinker $(OBJ) -lgcc gcc $(CFLAGS) -o msflinker $(OBJ) -lgcc

View File

@ -302,6 +302,8 @@ void *dlopenbuf(const char *name, void *data, size_t len)
void *ret = NULL; void *ret = NULL;
int status; int status;
TRACE("[ dlopenbuf() called with %s/%08x/%08x ]\n", name, data, len);
memset(&stream, 0, sizeof(z_stream)); memset(&stream, 0, sizeof(z_stream));
input_buffer = (unsigned char *)(data); input_buffer = (unsigned char *)(data);
@ -445,7 +447,7 @@ static Elf32_Sym libdl_symtab[] = {
* stubbing them out in libdl. * stubbing them out in libdl.
*/ */
static unsigned libdl_buckets[1] = { 1 }; static unsigned libdl_buckets[1] = { 1 };
static unsigned libdl_chains[7] = { 0, 2, 3, 4, 5, 6, 7, 0 }; static unsigned libdl_chains[8] = { 0, 2, 3, 4, 5, 6, 7, 0 };
extern soinfo libcrap_info; extern soinfo libcrap_info;
@ -457,7 +459,7 @@ soinfo libdl_info = {
symtab: libdl_symtab, symtab: libdl_symtab,
nbucket: 1, nbucket: 1,
nchain: 7, nchain: 8,
bucket: libdl_buckets, bucket: libdl_buckets,
chain: libdl_chains, chain: libdl_chains,
}; };

View File

@ -18,6 +18,7 @@
#include "libm.h" #include "libm.h"
#include "libcrypto.h" #include "libcrypto.h"
#include "libssl.h" #include "libssl.h"
#include "libsupport.h"
#include "metsrv_main.h" #include "metsrv_main.h"
struct libs { struct libs {
@ -32,11 +33,12 @@ static struct libs libs[] = {
{ "libm.so", libm, libm_length, NULL }, { "libm.so", libm, libm_length, NULL },
{ "libcrypto.so.0.9.8", libcrypto, libcrypto_length, NULL }, { "libcrypto.so.0.9.8", libcrypto, libcrypto_length, NULL },
{ "libssl.so.0.9.8", libssl, libssl_length, NULL }, { "libssl.so.0.9.8", libssl, libssl_length, NULL },
{ "libsupport.so", libsupport, libsupport_length, NULL },
{ "metsrv_main", metsrv_main, metsrv_main_length, NULL }, { "metsrv_main", metsrv_main, metsrv_main_length, NULL },
}; };
#define LIBC_IDX 0 #define LIBC_IDX 0
#define METSRV_IDX 4 #define METSRV_IDX 5
/* /*
* Once the library has been mapped in, this is where code execution needs to * Once the library has been mapped in, this is where code execution needs to

View File

@ -52,10 +52,10 @@ VPATH=$(BASEVPATH):$(OSVPATH):$(ARCHVPATH)
CFLAGS+= -I$(ARCHVPATH) CFLAGS+= -I$(ARCHVPATH)
CPPFLAGS+= -I$(ARCHVPATH) CPPFLAGS+= -I$(ARCHVPATH)
all: libsupport.a all: libsupport.so
libsupport.a: $(objects) libsupport.so: $(objects)
$(AR) rc $@ $(objects) $(CC) $(CFLAGS) -shared -o $@ $(objects) -lc -lssl -lcrypto
clean: clean:
$(RM) -f *.o *.a *.so zlib/zlib.o $(RM) -f *.o *.a *.so zlib/zlib.o

View File

@ -1,9 +1,21 @@
VPATH=../../source/extensions/stdapi VPATH=../../source/extensions/stdapi
CFLAGS= -fPIC -Os -I../../source/common -I../../source/openssl/include
CFLAGS+= -I../../source/ulibc OPENSSL=${PWD}/../../source/openssl/include
CFLAGS+= -I../../source/extensions/stdapi/server COMMON=${PWD}/../../source/common
CFLAGS+= -D_UNIX -nostdinc -fPIC -DPIC -g -Wall SERVER=../../source/server
LDFLAGS= -fPIC -Bshareable
CFLAGS=-fno-stack-protector -nostdinc -nostdlib -fPIC -DPIC -g -Wall
CFLAGS+=-D_UNIX -D__linux__
CFLAGS+=-I${COMMON} -I${SERVER} -I${OPENSSL}
CFLAGS+= -I ../../source/bionic/libc/include -I ../../source/bionic/libc/kernel/common/linux/ -I ../../source/bionic/libc/kernel/common/ -I ../../source/bionic/libc/arch-x86/include/
CFLAGS+= -I ../../source/bionic/libc/kernel/arch-x86/
CFLAGS+= -Dwchar_t="char" -fno-builtin -D_SIZE_T_DECLARED -DElf_Size="u_int32_t"
CFLAGS+= -D_BYTE_ORDER=_LITTLE_ENDIAN
CFLAGS+= -lgcc -L../../source/bionic/compiled -gstabs+
CFLAGS+= -fPIC -Os
CFLAGS+= -I../../source/extensions/stdapi/server -lc -lsupport
#LDFLAGS= -fPIC -Bshareable -lc
ifeq ($(OSNAME), FreeBSD) ifeq ($(OSNAME), FreeBSD)
OS= bsd OS= bsd
@ -14,7 +26,7 @@ endif
objects = server/general.o server/stdapi.o server/fs/dir.o server/fs/file.o \ objects = server/general.o server/stdapi.o server/fs/dir.o server/fs/file.o \
server/fs/fs_util.o \ server/fs/fs_util.o \
server/net/socket/tcp.o server/net/socket/tcp.o server/net/socket/tcp_server.o server/net/socket/udp.o
# server/net/config/interface.o # server/net/config/interface.o
# server/net/config/route.o \ # server/net/config/route.o \
@ -23,7 +35,7 @@ all: ext_server_stdapi.so
ext_server_stdapi.so: $(objects) ext_server_stdapi.so: $(objects)
$(LD) $(LDFLAGS) -o $@ $(objects) $(CC) -shared $(CFLAGS) -o $@ $(objects)
.PHONY: clean .PHONY: clean

View File

@ -24,7 +24,7 @@ objects+= server_setup.o remote_dispatch_common.o remote_dispatch.o # metsrv_mai
all: metsrv_main all: metsrv_main
metsrv_main: $(objects) metsrv_main: $(objects)
$(CC) -pie $(CFLAGS) -o $@ $(objects) ../common/libsupport.a -export-dynamic -lc -lcrypto -lssl -lgcc -ldl $(CC) -pie $(CFLAGS) -o $@ $(objects) -export-dynamic -lc -lcrypto -lssl -lgcc -ldl -lsupport
clean: clean:
@echo "ARCHVPATH= " $(ARCHVPATH) " VPATH= " $(VPATH) @echo "ARCHVPATH= " $(ARCHVPATH) " VPATH= " $(VPATH)