diff options
author | jsorg71 <jsorg71> | 2005-07-10 00:25:31 +0000 |
---|---|---|
committer | jsorg71 <jsorg71> | 2005-07-10 00:25:31 +0000 |
commit | 7ffee77e6d6117c8055c121cf72958d045e41e8a (patch) | |
tree | e7739fdc3989978e3af00e497a52cc28f39a4a03 /common | |
parent | 54db1e64098f234717a2f5d193708f24b0f31e0f (diff) | |
download | xrdp-proprietary-7ffee77e6d6117c8055c121cf72958d045e41e8a.tar.gz xrdp-proprietary-7ffee77e6d6117c8055c121cf72958d045e41e8a.zip |
use os_call in sesman
Diffstat (limited to 'common')
-rw-r--r-- | common/os_calls.c | 257 | ||||
-rw-r--r-- | common/os_calls.h | 151 |
2 files changed, 363 insertions, 45 deletions
diff --git a/common/os_calls.c b/common/os_calls.c index 0d6a4773..b04d71fe 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -34,11 +34,14 @@ #include <sys/un.h> #include <sys/time.h> #include <sys/types.h> +#include <sys/wait.h> +#include <sys/stat.h> #include <dlfcn.h> #include <arpa/inet.h> #include <netdb.h> #include <signal.h> #include <fcntl.h> +#include <pwd.h> #endif #include <stdlib.h> @@ -46,12 +49,6 @@ #include <stdarg.h> #include <stdio.h> -/* forward declarations */ -void -g_printf(char* format, ...); -void -g_pipe_sig(int sig_num); - /*****************************************************************************/ void* g_malloc(int size, int zero) @@ -522,6 +519,66 @@ g_file_lock(int fd, int start, int len) /*****************************************************************************/ int +g_set_file_rights(char* filename, int read, int write) +{ +#if defined(_WIN32) +#else + int flags; + + flags = read ? S_IRUSR : 0; + flags |= write ? S_IWUSR : 0; + chmod(filename, flags); +#endif + return 0; +} + +/*****************************************************************************/ +int +g_mkdir(char* dirname) +{ +#if defined(_WIN32) +#else + mkdir(dirname, S_IRWXU); +#endif + return 0; +} + +/*****************************************************************************/ +char* +g_get_current_dir(char* dirname, int maxlen) +{ +#if defined(_WIN32) + return 0; +#else + return getcwd(dirname, maxlen); +#endif +} + +/*****************************************************************************/ +int +g_set_current_dir(char* dirname) +{ +#if defined(_WIN32) + return 0; +#else + return chdir(dirname); +#endif +} + +/*****************************************************************************/ +/* returns non zero if the file exists */ +int +g_file_exist(char* filename) +{ +#if defined(_WIN32) + return 0; +#else + return access(filename, F_OK) == 0; +#endif +} + +/*****************************************************************************/ +int g_strlen(char* text) { if (text == 0) @@ -610,6 +667,13 @@ g_strncmp(char* c1, char* c2, int len) } /*****************************************************************************/ +int +g_atoi(char* str) +{ + return atoi(str); +} + +/*****************************************************************************/ long g_load_library(char* in) { @@ -664,6 +728,39 @@ g_system(char* aexec) /*****************************************************************************/ void +g_execvp(char* p1, char* args[]) +{ +#if defined(_WIN32) +#else + execvp(p1, args); +#endif +} + +/*****************************************************************************/ +int +g_execlp3(char* a1, char* a2, char* a3) +{ +#if defined(_WIN32) + return 0; +#else + return execlp(a1, a2, a3); +#endif +} + +/*****************************************************************************/ +int +g_execlp11(char* a1, char* a2, char* a3, char* a4, char* a5, char* a6, + char* a7, char* a8, char* a9, char* a10, char* a11) +{ +#if defined(_WIN32) + return 0; +#else + return execlp(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); +#endif +} + +/*****************************************************************************/ +void g_signal(int sig_num, void (*func)(int)) { #if defined(_WIN32) @@ -671,3 +768,151 @@ g_signal(int sig_num, void (*func)(int)) signal(sig_num, func); #endif } + +/*****************************************************************************/ +int +g_fork(void) +{ +#if defined(_WIN32) + return 0; +#else + return fork(); +#endif +} + +/*****************************************************************************/ +int +g_setgid(int pid) +{ +#if defined(_WIN32) + return 0; +#else + return setgid(pid); +#endif +} + +/*****************************************************************************/ +int +g_setuid(int pid) +{ +#if defined(_WIN32) + return 0; +#else + return setuid(pid); +#endif +} + +/*****************************************************************************/ +int +g_waitchild(void) +{ +#if defined(_WIN32) + return 0; +#else + int wstat; + + return waitpid(0, &wstat, WNOHANG); +#endif +} + +/*****************************************************************************/ +int +g_waitpid(int pid) +{ +#if defined(_WIN32) + return 0; +#else + return waitpid(pid, 0, 0); +#endif +} + +/*****************************************************************************/ +void +g_clearenv(void) +{ +#if defined(_WIN32) +#else + clearenv(); +#endif +} + +/*****************************************************************************/ +int +g_setenv(char* name, char* value, int rewrite) +{ +#if defined(_WIN32) + return 0; +#else + return setenv(name, value, rewrite); +#endif +} + +/*****************************************************************************/ +int +g_exit(int exit_code) +{ +#if defined(_WIN32) +#else + _exit(exit_code); +#endif + return 0; +} + +/*****************************************************************************/ +int +g_getpid(void) +{ +#if defined(_WIN32) + return 0; +#else + return getpid(); +#endif +} + +/*****************************************************************************/ +int +g_sigterm(int pid) +{ +#if defined(_WIN32) + return 0; +#else + return kill(pid, SIGTERM); +#endif +} + +/*****************************************************************************/ +int +g_getuser_info(char* username, int* gid, int* uid, char* shell, char* dir, + char* gecos) +{ +#if defined(_WIN32) +#else + struct passwd* pwd_1; + + pwd_1 = getpwnam(username); + if (pwd_1 != 0) + { + if (gid != 0) + { + *gid = pwd_1->pw_gid; + } + if (uid != 0) + { + *uid = pwd_1->pw_uid; + } + if (dir != 0) + { + g_strcpy(dir, pwd_1->pw_dir); + } + if (shell != 0) + { + g_strcpy(shell, pwd_1->pw_shell); + } + if (gecos != 0) + { + g_strcpy(gecos, pwd_1->pw_gecos); + } + } +#endif + return 0; +} diff --git a/common/os_calls.h b/common/os_calls.h index 81f90b66..e05345f8 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -23,18 +23,16 @@ #if !defined(OS_CALLS_H) #define OS_CALLS_H -int g_init_system(void); -int g_exit_system(void); +void* +g_malloc(int size, int zero); +void +g_free(void* ptr); void g_printf(char *format, ...); void g_sprintf(char* dest, char* format, ...); void g_hexdump(char* p, int len); -void* -g_malloc(int size, int zero); -void -g_free(void* ptr); void g_memset(void* ptr, int val, int size); void @@ -51,38 +49,113 @@ void g_tcp_close(int sck); int g_tcp_connect(int sck, char* address, char* port); -int g_tcp_force_send(int sck, char* data, int len); -int g_tcp_force_recv(int sck, char* data, int len); -int g_tcp_set_non_blocking(int sck); -int g_tcp_bind(int sck, char* port); -int g_tcp_local_bind(int sck, char* port); -int g_tcp_listen(int sck); -int g_tcp_accept(int sck); -int g_tcp_recv(int sck, void* ptr, int len, int flags); -int g_tcp_send(int sck, void* ptr, int len, int flags); -int g_tcp_last_error_would_block(int sck); -int g_tcp_select(int sck1, int sck2); -void g_sleep(int msecs); -void g_random(char* data, int len); -int g_abs(int i); -int g_memcmp(void* s1, void* s2, int len); -int g_file_open(char* file_name); -int g_file_close(int fd); -int g_file_read(int fd, char* ptr, int len); -int g_file_write(int fd, char* ptr, int len); -int g_file_seek(int fd, int offset); -int g_file_lock(int fd, int start, int len); -int g_strlen(char* text); -char* g_strcpy(char* dest, char* src); -char* g_strncpy(char* dest, char* src, int len); -char* g_strcat(char* dest, char* src); -char* g_strdup(char* in); -int g_strcmp(char* c1, char* c2); -int g_strncmp(char* c1, char* c2, int len); -long g_load_library(char* in); -int g_free_library(long lib); -void* g_get_proc_address(long lib, char* name); -int g_system(char* aexec); -void g_signal(int sig_num, void (*func)(int)); +int +g_tcp_force_send(int sck, char* data, int len); +int +g_tcp_force_recv(int sck, char* data, int len); +int +g_tcp_set_non_blocking(int sck); +int +g_tcp_bind(int sck, char* port); +int +g_tcp_local_bind(int sck, char* port); +int +g_tcp_listen(int sck); +int +g_tcp_accept(int sck); +int +g_tcp_recv(int sck, void* ptr, int len, int flags); +int +g_tcp_send(int sck, void* ptr, int len, int flags); +int +g_tcp_last_error_would_block(int sck); +int +g_tcp_select(int sck1, int sck2); +void +g_sleep(int msecs); +void +g_random(char* data, int len); +int +g_abs(int i); +int +g_memcmp(void* s1, void* s2, int len); +int +g_file_open(char* file_name); +int +g_file_close(int fd); +int +g_file_read(int fd, char* ptr, int len); +int +g_file_write(int fd, char* ptr, int len); +int +g_file_seek(int fd, int offset); +int +g_file_lock(int fd, int start, int len); +int +g_set_file_rights(char* filename, int read, int write); +int +g_mkdir(char* dirname); +char* +g_get_current_dir(char* dirname, int maxlen); +int +g_set_current_dir(char* dirname); +int +g_file_exist(char* filename); +int +g_strlen(char* text); +char* +g_strcpy(char* dest, char* src); +char* +g_strncpy(char* dest, char* src, int len); +char* +g_strcat(char* dest, char* src); +char* +g_strdup(char* in); +int +g_strcmp(char* c1, char* c2); +int +g_strncmp(char* c1, char* c2, int len); +int +g_atoi(char* str); +long +g_load_library(char* in); +int +g_free_library(long lib); +void* +g_get_proc_address(long lib, char* name); +int +g_system(char* aexec); +void +g_execvp(char* p1, char* args[]); +int +g_execlp3(char* a1, char* a2, char* a3); +int +g_execlp11(char* a1, char* a2, char* a3, char* a4, char* a5, char* a6, + char* a7, char* a8, char* a9, char* a10, char* a11); +void +g_signal(int sig_num, void (*func)(int)); +int +g_fork(void); +int +g_setgid(int pid); +int +g_setuid(int pid); +int +g_waitchild(void); +int +g_waitpid(int pid); +void +g_clearenv(void); +int +g_setenv(char* name, char* value, int rewrite); +int +g_exit(int exit_code); +int +g_getpid(void); +int +g_sigterm(int pid); +int +g_getuser_info(char* username, int* gid, int* uid, char* shell, char* dir, + char* gecos); #endif |