From: John Hodge Date: Tue, 14 May 2013 07:25:11 +0000 (+0800) Subject: Usermode/libposix - Implimenting functions for dropbear X-Git-Tag: rel0.15~486 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=465311d5855b475500e2568a69f72ae5f3c5c6d7;p=tpg%2Facess2.git Usermode/libposix - Implimenting functions for dropbear --- diff --git a/Usermode/Libraries/libposix.so_src/Makefile b/Usermode/Libraries/libposix.so_src/Makefile index b1f02570..20b5fec4 100644 --- a/Usermode/Libraries/libposix.so_src/Makefile +++ b/Usermode/Libraries/libposix.so_src/Makefile @@ -9,7 +9,7 @@ ASFLAGS += LDFLAGS += -soname libposix.so -Map map.txt -lc OBJ = main.o unistd.o dirent.o stat.o utmpx.o termios.o -OBJ += pwd.o +OBJ += pwd.o syslog.o sys_time.o sys_ioctl.o sys_resource.o DEPFILES := $(OBJ:%.o=%.d) BIN = libposix.so diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/resource.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/resource.h index 90308f23..9aa2c23b 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/resource.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/resource.h @@ -29,6 +29,7 @@ struct rlimit rlim_t rlim_max; }; +// (get|set)r(limit|usage) resource values enum { RLIMIT_AS, // Address space size @@ -45,10 +46,10 @@ struct rusage }; extern int getpriority(int, id_t); -extern int getrlimit(int, struct rlimit *); -extern int getrusage(int, struct rusage *); +extern int getrlimit(int resource, struct rlimit *rlim); +extern int getrusage(int resource, struct rusage *rusage); extern int setpriority(int, id_t, int); -extern int setrlimit(int, const struct rlimit *); +extern int setrlimit(int resource, const struct rlimit *rlim); #endif diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/time.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/time.h index 7a734a5a..79e40138 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/sys/time.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/sys/time.h @@ -18,6 +18,28 @@ struct timeval suseconds_t tv_usec; }; +// struct timezone . tz_dsttime +enum +{ + DST_NONE, // No DST + DST_USA, // USA style DST + DST_AUST, // Australian style DST + DST_WET, // Western European DST + DST_MET, // Middle European DST + DST_EET, // Eastern European DST + DST_CAN, // Canada + DST_GB, // Great Britain and Eire + DST_RUM, // Rumania + DST_TUR, // Turkey + DST_AUSTALT, // Australia with 1986 shift +}; + +struct timezone +{ + int tz_minuteswest; + int tz_dsttime; +}; + struct itimerval { struct timeval it_interval; @@ -26,9 +48,10 @@ struct itimerval // TODO: This should also define fd_set and select() -extern int getitimer(int, struct itimerval *); -extern int setitimer(int, const struct itimerval *, struct itimerval *); -extern int gettimeofday(struct timeval *, void *); +extern int getitimer(int which, struct itimerval *current_value); +extern int setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value); +extern int gettimeofday(struct timeval *tv, struct timezone *tz); +// extern int settimeofday(const struct timeval *tv, const struct timezone *tz); //ifdef _BSD_SOURCE // select extern int utimes(const char *, const struct timeval [2]); diff --git a/Usermode/Libraries/libposix.so_src/include_exp/syslog.h b/Usermode/Libraries/libposix.so_src/include_exp/syslog.h index ae891b7f..d74e994d 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/syslog.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/syslog.h @@ -3,7 +3,7 @@ * - By John Hodge (thePowersGang) * * syslog.h - * - Centra Loggin + * - Central Logging */ #ifndef _LIBPOSIX__SYSLOG_H_ #define _LIBPOSIX__SYSLOG_H_ diff --git a/Usermode/Libraries/libposix.so_src/include_exp/unistd.h b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h index 81124c4d..98623b6e 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/unistd.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h @@ -64,6 +64,8 @@ extern int chown(const char *path, uid_t owner, gid_t group); #define S_IXOTH 00001 extern int chmod(const char *path, mode_t mode); +extern pid_t setsid(void); + extern uid_t getuid(void); extern uid_t geteuid(void); extern pid_t getpid(void); @@ -73,6 +75,11 @@ extern pid_t getpid(void); #define SIGTSTP 102 extern int kill(pid_t pid, int sig); +extern int chdir(const char *dir); + +// Deprecated POSIX.1-2001 +#define PASS_MAX 63 +extern char *getpass(void); #endif diff --git a/Usermode/Libraries/libposix.so_src/sys_ioctl.c b/Usermode/Libraries/libposix.so_src/sys_ioctl.c new file mode 100644 index 00000000..56871bc1 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/sys_ioctl.c @@ -0,0 +1,45 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * sys_ioctl.c + * - IOCtl hacks + */ +#include +#include +#include + +// === CODE === +int ioctl(int fd, int request, ...) +{ + if( fd < 0 ) { + errno = EBADF; + return -1; + } + + if( request < 0 ) { + errno = EINVAL; + return -1; + } + + // #1. Get device type (IOCtl 0) + int devtype = _SysIOCtl(fd, 0, NULL); + + switch(devtype) + { + // 0: Normal file (no ioctls we care about) + case 0: + // 1: Has the ident set of ioctls, nothing else + case 1: + return -1; + // TODO: Terminals + + // NFI + default: + return -1; + } + + return 0; +} + + diff --git a/Usermode/Libraries/libposix.so_src/sys_resource.c b/Usermode/Libraries/libposix.so_src/sys_resource.c new file mode 100644 index 00000000..caeddd79 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/sys_resource.c @@ -0,0 +1,25 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * sys_resource.c + * - (XSI) Resource Operations + */ +#include +#include + +// === CODE === +int getrlimit(int resource, struct rlimit *rlim) +{ + _SysDebug("TODO: getrlimit(%i)", resource); + rlim->rlim_cur = 0; + rlim->rlim_max = 0; + return 0; +} + +int setrlimit(int resource, const struct rlimit *rlim) +{ + _SysDebug("TODO: setrlimit(%i,{%i,%i})", resource, rlim->rlim_cur, rlim->rlim_max); + return 0; +} + diff --git a/Usermode/Libraries/libposix.so_src/sys_time.c b/Usermode/Libraries/libposix.so_src/sys_time.c new file mode 100644 index 00000000..3edde789 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/sys_time.c @@ -0,0 +1,43 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * sys/time.h + * - Timing calls + */ +#include +#include + +// === CODE === +#if 0 +int getitimer(int which, struct itimerval *current_value) +{ + +} + +int setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value) +{ + +} +#endif + +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + const int correction_2k_to_unix = 30*365*24*3600; + long long int ts = _SysTimestamp(); + if( tv ) + { + tv->tv_sec = ts / 1000 + correction_2k_to_unix; + tv->tv_usec = (ts % 1000) * 1000; + } + if( tz ) + { + // TODO: Determine timezone? + tz->tz_minuteswest = 0; + tz->tz_dsttime = 0; + } + return 0; +} + +// ifdef _BSD_SOURCE +//int settimeofday(const struct timeval *tv, const struct timezone *tz); diff --git a/Usermode/Libraries/libposix.so_src/syslog.c b/Usermode/Libraries/libposix.so_src/syslog.c new file mode 100644 index 00000000..4412340c --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/syslog.c @@ -0,0 +1,63 @@ +/* + * Acess2 POSIX Emulation + * - By John Hodge (thePowersGang) + * + * syslog.h + * - Central Logging + */ +#include +#include // vsnprintf +#include // free +#include // strdup +#include +#include + +// === GLOBALS === +char *gsSyslogPrefix = NULL; + int gSyslogOptions; + int gSyslogFacility; + int gSyslogMask = -1; + +// === CODE === +/* + * Close global logging handle + */ +void closelog(void) +{ +} + +void openlog(const char *name, int option, int facility) +{ + if( gsSyslogPrefix ) + free(gsSyslogPrefix); + gsSyslogPrefix = strdup(name); + gSyslogOptions = option; + gSyslogFacility = facility; + + if( option & LOG_NOWAIT ) + { + // Open the logging handle! + } +} + +extern int setlogmask(int mask) +{ + int ret = gSyslogMask; + gSyslogMask = mask; + return ret; +} + +extern void syslog(int priority, const char *str, ...) +{ + char staticbuf[512]; + va_list args; + va_start(args, str); + vsnprintf(staticbuf, sizeof(staticbuf), str, args); + va_end(args); + if( gSyslogOptions & (1 << priority) ) + { + // TODO: Proper syslog + _SysDebug("syslog(%i: %s) - %s", priority, gsSyslogPrefix, staticbuf); + } +} + diff --git a/Usermode/Libraries/libposix.so_src/unistd.c b/Usermode/Libraries/libposix.so_src/unistd.c index 9234319e..d8cbbf65 100644 --- a/Usermode/Libraries/libposix.so_src/unistd.c +++ b/Usermode/Libraries/libposix.so_src/unistd.c @@ -9,6 +9,7 @@ #include #include #include +#include // === CODE === int unlink(const char *pathname) @@ -99,6 +100,16 @@ int dup2(int oldfd, int newfd) return _SysCopyFD(oldfd, newfd); } + +/* + * Set session ID to PID + */ +pid_t setsid(void) +{ + // TODO: actual syscall for this + return _SysGetPID(); +} + pid_t getpid(void) { return _SysGetPID(); @@ -109,6 +120,12 @@ uid_t getuid(void) return _SysGetUID(); } +uid_t geteuid(void) +{ + // TODO: Impliment EUIDs in-kernel? + return _SysGetUID(); +} + int kill(pid_t pid, int signal) { // TODO: Need special handling? @@ -139,3 +156,23 @@ int pipe(int pipefd[2]) return 0; } +int chdir(const char *dir) +{ + return _SysChdir(dir); +} + +int mkdir(const char *pathname, mode_t mode) +{ + _SysDebug("TODO: POSIX mkdir(%i, 0%o)", pathname, mode); + return -1; +} + +char *getpass(void) +{ + static char passbuf[PASS_MAX+1]; + fprintf(stderr, "Password: "); + fgets(passbuf, PASS_MAX+1, stdin); + fprintf(stderr, "\n"); + return passbuf; +} + diff --git a/Usermode/Libraries/libpsocket.so_src/socket.c b/Usermode/Libraries/libpsocket.so_src/socket.c index e2521ad3..a03a2bd7 100644 --- a/Usermode/Libraries/libpsocket.so_src/socket.c +++ b/Usermode/Libraries/libpsocket.so_src/socket.c @@ -248,3 +248,8 @@ int getpeername(int socket, struct sockaddr *addr, socklen_t *addrlen) return 0; } +int shutdown(int socket, int how) +{ + return 0; +} +