diff options
author | Robert Collins <rbtcollins@hotmail.com> | 2001-09-29 14:47:59 +0400 |
---|---|---|
committer | Robert Collins <rbtcollins@hotmail.com> | 2001-09-29 14:47:59 +0400 |
commit | 12ed6a1b325dde4b50720bffea87cada0c45faf1 (patch) | |
tree | d86cdfbcdc3e66bb638f2eec7b2b20615a9881c9 /winsup | |
parent | 3e71175438f70accbed25b8a43db23d7013dd378 (diff) |
Sat Sep 29 20:40:00 2001 Robert Collins <rbtcollins@hotmail.com>
* Makefile.in: Add cygserver_transport_sockets.o to DLL_OFILES.
Add cygserver_transport_sockets_outside.o to cygserver.exe.
* cygserver.cc: Include new include files.
* cygserver_client.cc: Ditto.
* cygserver_shm.h: No need to include <sys/socket.h> now.
* cygerver_transport.cc: Include new include files.
(transport_layer_base::transport_layer_base): Strip back to a stub.
(transport_layer_base::listen): Ditto.
(transport_layer_base::accept): Ditto.
(transport_layer_base::close): Ditto.
(transport_layer_base::read): Ditto.
(transport_layer_base::write): Ditto.
(transport_layer_base::connect): Ditto.
* cygserver_transport_pipes.cc: Include new header
"cygwin/cygserver_transport_pipes.h".
* cygserver_transport_sockets.cc: New file.
* dcrt0.cc: No need to include <sys/socket.h> now.
* fhandler_tty.cc: Ditto.
* tty.cc: Ditto.
* include/cygwin/cygserver_transport.h: Strip the base class to a stub.
Remove the cygserver_transport_pipes class.
* include/cygwin/cygserver_transport_pipes.h: New file.
* include/cygwin/cygserver_transport_sockets.h: New file.
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/ChangeLog | 26 | ||||
-rw-r--r-- | winsup/cygwin/Makefile.in | 8 | ||||
-rwxr-xr-x | winsup/cygwin/cygserver.cc | 2 | ||||
-rwxr-xr-x | winsup/cygwin/cygserver_client.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/cygserver_shm.h | 1 | ||||
-rwxr-xr-x | winsup/cygwin/cygserver_transport.cc | 78 | ||||
-rwxr-xr-x | winsup/cygwin/cygserver_transport_pipes.cc | 1 | ||||
-rwxr-xr-x | winsup/cygwin/cygserver_transport_sockets.cc | 131 | ||||
-rw-r--r-- | winsup/cygwin/dcrt0.cc | 1 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_tty.cc | 1 | ||||
-rwxr-xr-x | winsup/cygwin/include/cygwin/cygserver_transport.h | 41 | ||||
-rwxr-xr-x | winsup/cygwin/include/cygwin/cygserver_transport_pipes.h | 27 | ||||
-rwxr-xr-x | winsup/cygwin/include/cygwin/cygserver_transport_sockets.h | 21 | ||||
-rw-r--r-- | winsup/cygwin/tty.cc | 1 |
14 files changed, 228 insertions, 113 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index cb744c6dd..009d04b32 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,29 @@ +Sat Sep 29 20:40:00 2001 Robert Collins <rbtcollins@hotmail.com> + + * Makefile.in: Add cygserver_transport_sockets.o to DLL_OFILES. + Add cygserver_transport_sockets_outside.o to cygserver.exe. + * cygserver.cc: Include new include files. + * cygserver_client.cc: Ditto. + * cygserver_shm.h: No need to include <sys/socket.h> now. + * cygerver_transport.cc: Include new include files. + (transport_layer_base::transport_layer_base): Strip back to a stub. + (transport_layer_base::listen): Ditto. + (transport_layer_base::accept): Ditto. + (transport_layer_base::close): Ditto. + (transport_layer_base::read): Ditto. + (transport_layer_base::write): Ditto. + (transport_layer_base::connect): Ditto. + * cygserver_transport_pipes.cc: Include new header + "cygwin/cygserver_transport_pipes.h". + * cygserver_transport_sockets.cc: New file. + * dcrt0.cc: No need to include <sys/socket.h> now. + * fhandler_tty.cc: Ditto. + * tty.cc: Ditto. + * include/cygwin/cygserver_transport.h: Strip the base class to a stub. + Remove the cygserver_transport_pipes class. + * include/cygwin/cygserver_transport_pipes.h: New file. + * include/cygwin/cygserver_transport_sockets.h: New file. + Tue Sep 25 16:22:00 2001 Robert Collins <rbtcollins@hotmail.com> * autoload.cc: Add dynamic load statement for 'ImpersonateNamedPipeClient'. diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in index 685aab7f4..6ab06144e 100644 --- a/winsup/cygwin/Makefile.in +++ b/winsup/cygwin/Makefile.in @@ -117,7 +117,8 @@ MALLOC_OFILES=@MALLOC_OFILES@ DLL_IMPORTS:=$(w32api_lib)/libkernel32.a DLL_OFILES:=assert.o autoload.o cygheap.o cygserver_client.o cygserver_shm.o \ - cygserver_transport.o cygserver_transport_pipes.o dcrt0.o debug.o \ + cygserver_transport.o cygserver_transport_pipes.o cygserver_transport_sockets.o \ + dcrt0.o debug.o \ delqueue.o dir.o \ dlfcn.o dll_init.o dtable.o environ.o errno.o exceptions.o exec.o \ external.o fcntl.o fhandler.o fhandler_clipboard.o fhandler_console.o \ @@ -229,13 +230,16 @@ cygserver_transport_outside.o: cygserver_transport.cc cygserver_transport_pipes_outside.o: cygserver_transport_pipes.cc $(COMPILE_CXX) -D__OUTSIDE_CYGWIN__ -o $@ $< +cygserver_transport_sockets_outside.o: cygserver_transport_sockets.cc + $(COMPILE_CXX) -D__OUTSIDE_CYGWIN__ -o $@ $< + cygserver_client_outside.o: cygserver_client.cc $(COMPILE_CXX) -D__OUTSIDE_CYGWIN__ -o $@ $< cygserver_shm_outside.o: cygserver_shm.cc $(COMPILE_CXX) -D__OUTSIDE_CYGWIN__ -o $@ $< -cygserver.exe: cygserver.o cygserver_shm_outside.o cygserver_transport_outside.o cygserver_transport_pipes_outside.o cygserver_client_outside.o wincap.o smallprint.o +cygserver.exe: cygserver.o cygserver_shm_outside.o cygserver_transport_outside.o cygserver_transport_pipes_outside.o cygserver_transport_sockets_outside.o cygserver_client_outside.o wincap.o smallprint.o $(CXX) -o $@ $^ #ifdef VERBOSE # $(CXX) $(MINGW_CXXFLAGS) -o $@ ${wordlist 1,3,$^} -B$(mingw_build)/ $(MINGW_LDFLAGS) diff --git a/winsup/cygwin/cygserver.cc b/winsup/cygwin/cygserver.cc index 34141d3bf..8f30d90dd 100755 --- a/winsup/cygwin/cygserver.cc +++ b/winsup/cygwin/cygserver.cc @@ -22,6 +22,8 @@ #include "getopt.h" #include "cygwin/cygserver_transport.h" +#include "cygwin/cygserver_transport_pipes.h" +#include "cygwin/cygserver_transport_sockets.h" #include "cygwin/cygserver.h" #include "cygserver_shm.h" diff --git a/winsup/cygwin/cygserver_client.cc b/winsup/cygwin/cygserver_client.cc index 1dc8f2d6e..266687e26 100755 --- a/winsup/cygwin/cygserver_client.cc +++ b/winsup/cygwin/cygserver_client.cc @@ -27,6 +27,8 @@ #include <unistd.h> //#include "security.h" #include "cygwin/cygserver_transport.h" +#include "cygwin/cygserver_transport_pipes.h" +#include "cygwin/cygserver_transport_sockets.h" #include "cygwin/cygserver.h" /* 0 = untested, 1 = running, 2 = dead */ diff --git a/winsup/cygwin/cygserver_shm.h b/winsup/cygwin/cygserver_shm.h index fe4018d32..e4ac62e4c 100644 --- a/winsup/cygwin/cygserver_shm.h +++ b/winsup/cygwin/cygserver_shm.h @@ -10,7 +10,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include <sys/types.h> -#include <sys/socket.h> #include "cygwin/cygserver_transport.h" #include "cygwin/cygserver.h" diff --git a/winsup/cygwin/cygserver_transport.cc b/winsup/cygwin/cygserver_transport.cc index d18e0436a..7c6e5fe00 100755 --- a/winsup/cygwin/cygserver_transport.cc +++ b/winsup/cygwin/cygserver_transport.cc @@ -19,29 +19,13 @@ #include <netdb.h> #include "wincap.h" #include "cygwin/cygserver_transport.h" +#include "cygwin/cygserver_transport_pipes.h" +#include "cygwin/cygserver_transport_sockets.h" /* to allow this to link into cygwin and the .dll, a little magic is needed. */ #ifndef __OUTSIDE_CYGWIN__ #include "winsup.h" -extern "C" int -cygwin_socket (int af, int type, int protocol); -extern "C" int -cygwin_connect (int fd, - const struct sockaddr *name, - int namelen); -extern "C" int -cygwin_accept (int fd, struct sockaddr *peer, int *len); -extern "C" int -cygwin_listen (int fd, int backlog); -extern "C" int -cygwin_bind (int fd, const struct sockaddr *my_addr, int addrlen); - #else -#define cygwin_accept(A,B,C) ::accept(A,B,C) -#define cygwin_socket(A,B,C) ::socket(A,B,C) -#define cygwin_listen(A,B) ::listen(A,B) -#define cygwin_bind(A,B,C) ::bind(A,B,C) -#define cygwin_connect(A,B,C) ::connect(A,B,C) #define debug_printf printf #endif @@ -58,88 +42,43 @@ class transport_layer_base *create_server_transport() } -transport_layer_base::transport_layer_base (int newfd): fd(newfd) -{ - /* This may not be needed in this constructor - it's only used - * when creating a connection via bind or connect - */ - sockdetails.sa_family = AF_UNIX; - strcpy (sockdetails.sa_data, "/tmp/cygdaemo"); - sdlen = strlen(sockdetails.sa_data) + sizeof(sockdetails.sa_family); -}; - -transport_layer_base::transport_layer_base (): fd (-1) +transport_layer_base::transport_layer_base () { - sockdetails.sa_family = AF_UNIX; - strcpy (sockdetails.sa_data, "/tmp/cygdaemo"); - sdlen = strlen(sockdetails.sa_data) + sizeof(sockdetails.sa_family); + /* should we throw an error of some sort ? */ } void transport_layer_base::listen () { - /* we want a thread pool based approach. */ - if ((fd = cygwin_socket (AF_UNIX, SOCK_STREAM,0)) < 0) - printf ("Socket not created error %d\n", errno); - if (cygwin_bind(fd, &sockdetails, sdlen)) - printf ("Bind doesn't like you. Tsk Tsk. Bind said %d\n", errno); - if (cygwin_listen(fd, 5) < 0) - printf ("And the OS just isn't listening, all it says is %d\n", errno); } class transport_layer_base * transport_layer_base::accept () { - /* FIXME: check we have listened */ - int new_fd; - - if ((new_fd = cygwin_accept(fd, &sockdetails, &sdlen)) < 0) - { - printf ("Nup, could' accept. %d\n",errno); - return NULL; - } - - transport_layer_base *new_conn = new transport_layer_base (new_fd); - - return new_conn; - + return NULL; } void transport_layer_base::close() { - /* FIXME - are we open? */ - ::close (fd); } ssize_t transport_layer_base::read (char *buf, size_t len) { - /* FIXME: are we open? */ - return ::read (fd, buf, len); + return 0; } ssize_t transport_layer_base::write (char *buf, size_t len) { - /* FIXME: are we open? */ - return ::write (fd, buf, len); + return 0; } bool transport_layer_base::connect () { - /* are we already connected? */ - if (fd != -1) - return false; - fd = cygwin_socket (AF_UNIX, SOCK_STREAM, 0); - if (cygwin_connect (fd, &sockdetails, sdlen) < 0) - { - debug_printf("client connect failure %d\n", errno); - ::close (fd); - return false; - } - return true; + return false; } void @@ -151,4 +90,3 @@ void transport_layer_base::revert_to_self () { } - diff --git a/winsup/cygwin/cygserver_transport_pipes.cc b/winsup/cygwin/cygserver_transport_pipes.cc index 77eede492..487ea5281 100755 --- a/winsup/cygwin/cygserver_transport_pipes.cc +++ b/winsup/cygwin/cygserver_transport_pipes.cc @@ -19,6 +19,7 @@ #include <netdb.h> #include "wincap.h" #include "cygwin/cygserver_transport.h" +#include "cygwin/cygserver_transport_pipes.h" /* to allow this to link into cygwin and the .dll, a little magic is needed. */ #ifndef __OUTSIDE_CYGWIN__ diff --git a/winsup/cygwin/cygserver_transport_sockets.cc b/winsup/cygwin/cygserver_transport_sockets.cc new file mode 100755 index 000000000..6b75365b4 --- /dev/null +++ b/winsup/cygwin/cygserver_transport_sockets.cc @@ -0,0 +1,131 @@ +/* cygserver_transport_sockets.cc + + Copyright 2001 Red Hat Inc. + + Written by Robert Collins <rbtcollins@hotmail.com> + + This file is part of Cygwin. + + This software is a copyrighted work licensed under the terms of the + Cygwin license. Please consult the file "CYGWIN_LICENSE" for + details. */ + +#include <errno.h> +#include <stdio.h> +#include <unistd.h> +#include <windows.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> +#include "wincap.h" +#include "cygwin/cygserver_transport.h" +#include "cygwin/cygserver_transport_sockets.h" + +/* to allow this to link into cygwin and the .dll, a little magic is needed. */ +#ifndef __OUTSIDE_CYGWIN__ +#include "winsup.h" +extern "C" int +cygwin_socket (int af, int type, int protocol); +extern "C" int +cygwin_connect (int fd, + const struct sockaddr *name, + int namelen); +extern "C" int +cygwin_accept (int fd, struct sockaddr *peer, int *len); +extern "C" int +cygwin_listen (int fd, int backlog); +extern "C" int +cygwin_bind (int fd, const struct sockaddr *my_addr, int addrlen); + +#else +#define cygwin_accept(A,B,C) ::accept(A,B,C) +#define cygwin_socket(A,B,C) ::socket(A,B,C) +#define cygwin_listen(A,B) ::listen(A,B) +#define cygwin_bind(A,B,C) ::bind(A,B,C) +#define cygwin_connect(A,B,C) ::connect(A,B,C) +#define debug_printf printf +#endif + +transport_layer_sockets::transport_layer_sockets (int newfd): fd(newfd) +{ + /* This may not be needed in this constructor - it's only used + * when creating a connection via bind or connect + */ + sockdetails.sa_family = AF_UNIX; + strcpy (sockdetails.sa_data, "/tmp/cygdaemo"); + sdlen = strlen(sockdetails.sa_data) + sizeof(sockdetails.sa_family); +}; + +transport_layer_sockets::transport_layer_sockets (): fd (-1) +{ + sockdetails.sa_family = AF_UNIX; + strcpy (sockdetails.sa_data, "/tmp/cygdaemo"); + sdlen = strlen(sockdetails.sa_data) + sizeof(sockdetails.sa_family); +} + +void +transport_layer_sockets::listen () +{ + /* we want a thread pool based approach. */ + if ((fd = cygwin_socket (AF_UNIX, SOCK_STREAM,0)) < 0) + printf ("Socket not created error %d\n", errno); + if (cygwin_bind(fd, &sockdetails, sdlen)) + printf ("Bind doesn't like you. Tsk Tsk. Bind said %d\n", errno); + if (cygwin_listen(fd, 5) < 0) + printf ("And the OS just isn't listening, all it says is %d\n", errno); +} + +class transport_layer_sockets * +transport_layer_sockets::accept () +{ + /* FIXME: check we have listened */ + int new_fd; + + if ((new_fd = cygwin_accept(fd, &sockdetails, &sdlen)) < 0) + { + printf ("Nup, could' accept. %d\n",errno); + return NULL; + } + + transport_layer_sockets *new_conn = new transport_layer_sockets (new_fd); + + return new_conn; + +} + +void +transport_layer_sockets::close() +{ + /* FIXME - are we open? */ + ::close (fd); +} + +ssize_t +transport_layer_sockets::read (char *buf, size_t len) +{ + /* FIXME: are we open? */ + return ::read (fd, buf, len); +} + +ssize_t +transport_layer_sockets::write (char *buf, size_t len) +{ + /* FIXME: are we open? */ + return ::write (fd, buf, len); +} + +bool +transport_layer_sockets::connect () +{ + /* are we already connected? */ + if (fd != -1) + return false; + fd = cygwin_socket (AF_UNIX, SOCK_STREAM, 0); + if (cygwin_connect (fd, &sockdetails, sdlen) < 0) + { + debug_printf("client connect failure %d\n", errno); + ::close (fd); + return false; + } + return true; +} diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 00059f272..ec8968756 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -34,7 +34,6 @@ details. */ #include "shared_info.h" #include "cygwin_version.h" #include "dll_init.h" -#include <sys/socket.h> #include "cygwin/cygserver_transport.h" #include "cygwin/cygserver.h" diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 8a2abb77a..e0ceecd5c 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -25,7 +25,6 @@ details. */ #include "pinfo.h" #include "cygheap.h" #include "shared_info.h" -#include <sys/socket.h> #include "cygwin/cygserver_transport.h" #include "cygwin/cygserver.h" diff --git a/winsup/cygwin/include/cygwin/cygserver_transport.h b/winsup/cygwin/include/cygwin/cygserver_transport.h index e4405d2d4..d1a75b057 100755 --- a/winsup/cygwin/include/cygwin/cygserver_transport.h +++ b/winsup/cygwin/include/cygwin/cygserver_transport.h @@ -1,9 +1,8 @@ - -#ifndef _CYGSERVER_SHM_ -#define _CYGSERVER_SHM_ +#ifndef _CYGSERVER_TRANSPORT_ +#define _CYGSERVER_TRANSPORT_ class transport_layer_base *create_server_transport(); -/* the base class uses AF_UNIX sockets,but other classes are possible. */ +/* the base class does nothing. */ class transport_layer_base { public: @@ -16,38 +15,6 @@ class transport_layer_base virtual void impersonate_client (); virtual void revert_to_self (); transport_layer_base (); - - private: - /* for socket based communications */ - int fd; - struct sockaddr sockdetails; - int sdlen; - transport_layer_base (int newfd); -}; - -/* Named pipes based transport, for security on NT */ -class transport_layer_pipes : public transport_layer_base -{ - public: - virtual void listen (); - virtual class transport_layer_pipes * accept (); - virtual void close (); - virtual ssize_t read (char *buf, size_t len); - virtual ssize_t write (char *buf, size_t len); - virtual bool connect(); - virtual void impersonate_client (); - virtual void revert_to_self (); - transport_layer_pipes (); - - private: - /* for pipe based communications */ - void init_security (); - SECURITY_DESCRIPTOR sd; - SECURITY_ATTRIBUTES sec_none_nih, sec_all_nih; - char pipe_name [MAX_PATH]; - HANDLE pipe; - bool inited; - transport_layer_pipes (HANDLE new_pipe); }; -#endif /* _CYGSERVER_SHM_ */ +#endif /* _CYGSERVER_TRANSPORT_ */ diff --git a/winsup/cygwin/include/cygwin/cygserver_transport_pipes.h b/winsup/cygwin/include/cygwin/cygserver_transport_pipes.h new file mode 100755 index 000000000..27fdb972c --- /dev/null +++ b/winsup/cygwin/include/cygwin/cygserver_transport_pipes.h @@ -0,0 +1,27 @@ +#ifndef _CYGSERVER_TRANSPORT_PIPES_ +#define _CYGSERVER_TRANSPORT_PIPES_ +/* Named pipes based transport, for security on NT */ +class transport_layer_pipes : public transport_layer_base +{ + public: + virtual void listen (); + virtual class transport_layer_pipes * accept (); + virtual void close (); + virtual ssize_t read (char *buf, size_t len); + virtual ssize_t write (char *buf, size_t len); + virtual bool connect(); + virtual void impersonate_client (); + virtual void revert_to_self (); + transport_layer_pipes (); + + private: + /* for pipe based communications */ + void init_security (); + SECURITY_DESCRIPTOR sd; + SECURITY_ATTRIBUTES sec_none_nih, sec_all_nih; + char pipe_name [MAX_PATH]; + HANDLE pipe; + bool inited; + transport_layer_pipes (HANDLE new_pipe); +}; +#endif /* _CYGSERVER_TRANSPORT_PIPES_ */ diff --git a/winsup/cygwin/include/cygwin/cygserver_transport_sockets.h b/winsup/cygwin/include/cygwin/cygserver_transport_sockets.h new file mode 100755 index 000000000..7d15ee3e8 --- /dev/null +++ b/winsup/cygwin/include/cygwin/cygserver_transport_sockets.h @@ -0,0 +1,21 @@ +#ifndef _CYGSERVER_TRANSPORT_SOCKETS_ +#define _CYGSERVER_TRANSPORT_SOCKETS_ +class transport_layer_sockets : public transport_layer_base +{ + public: + virtual void listen (); + virtual class transport_layer_sockets * accept (); + virtual void close (); + virtual ssize_t read (char *buf, size_t len); + virtual ssize_t write (char *buf, size_t len); + virtual bool connect(); + transport_layer_sockets (); + + private: + /* for socket based communications */ + int fd; + struct sockaddr sockdetails; + int sdlen; + transport_layer_sockets (int newfd); +}; +#endif /* _CYGSERVER_TRANSPORT_SOCKETS_ */ diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index baa05cd62..fd4afb388 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -23,7 +23,6 @@ details. */ #include "sync.h" #include "sigproc.h" #include "pinfo.h" -#include <sys/socket.h> #include "cygwin/cygserver_transport.h" #include "cygwin/cygserver.h" #include "shared_info.h" |