Cygwin: fhandler_socket_unix: store peer credentials in ucred member
* Split out cygwin/_ucred.h file * drop local credentials Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
		| @@ -11,6 +11,7 @@ details. */ | |||||||
|  |  | ||||||
| #include "tty.h" | #include "tty.h" | ||||||
| #include <cygwin/_socketflags.h> | #include <cygwin/_socketflags.h> | ||||||
|  | #include <cygwin/_ucred.h> | ||||||
|  |  | ||||||
| /* fcntl flags used only internaly. */ | /* fcntl flags used only internaly. */ | ||||||
| #define O_NOSYMLINK	0x080000 | #define O_NOSYMLINK	0x080000 | ||||||
| @@ -824,15 +825,10 @@ class fhandler_socket_unix : public fhandler_socket | |||||||
|   char *get_sun_path () {return sun_path;} |   char *get_sun_path () {return sun_path;} | ||||||
|   void set_peer_sun_path (const char *path); |   void set_peer_sun_path (const char *path); | ||||||
|   char *get_peer_sun_path () {return peer_sun_path;} |   char *get_peer_sun_path () {return peer_sun_path;} | ||||||
|   void set_cred (); |  | ||||||
|  |  | ||||||
|  protected: |  protected: | ||||||
|   pid_t sec_pid; |   struct ucred peer_cred; | ||||||
|   uid_t sec_uid; |   void set_cred (); | ||||||
|   gid_t sec_gid; |  | ||||||
|   pid_t sec_peer_pid; |  | ||||||
|   uid_t sec_peer_uid; |  | ||||||
|   gid_t sec_peer_gid; |  | ||||||
|  |  | ||||||
|  public: |  public: | ||||||
|   fhandler_socket_unix (); |   fhandler_socket_unix (); | ||||||
|   | |||||||
| @@ -178,12 +178,9 @@ fhandler_socket_unix::set_peer_sun_path (const char *path) | |||||||
| void | void | ||||||
| fhandler_socket_unix::set_cred () | fhandler_socket_unix::set_cred () | ||||||
| { | { | ||||||
|   sec_pid = getpid (); |   peer_cred.pid = (pid_t) 0; | ||||||
|   sec_uid = geteuid32 (); |   peer_cred.uid = (uid_t) -1; | ||||||
|   sec_gid = getegid32 (); |   peer_cred.gid = (gid_t) -1; | ||||||
|   sec_peer_pid = (pid_t) 0; |  | ||||||
|   sec_peer_uid = (uid_t) -1; |  | ||||||
|   sec_peer_gid = (gid_t) -1; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| @@ -317,11 +314,11 @@ fhandler_socket_unix::getpeereid (pid_t *pid, uid_t *euid, gid_t *egid) | |||||||
|   __try |   __try | ||||||
|     { |     { | ||||||
|       if (pid) |       if (pid) | ||||||
| 	*pid = sec_peer_pid; | 	*pid = peer_cred.pid; | ||||||
|       if (euid) |       if (euid) | ||||||
| 	*euid = sec_peer_uid; | 	*euid = peer_cred.uid; | ||||||
|       if (egid) |       if (egid) | ||||||
| 	*egid = sec_peer_gid; | 	*egid = peer_cred.gid; | ||||||
|       return 0; |       return 0; | ||||||
|     } |     } | ||||||
|   __except (EFAULT) {} |   __except (EFAULT) {} | ||||||
|   | |||||||
							
								
								
									
										20
									
								
								winsup/cygwin/include/cygwin/_ucred.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								winsup/cygwin/include/cygwin/_ucred.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | |||||||
|  | /* cygwin/_ucred.h | ||||||
|  |  | ||||||
|  | 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. */ | ||||||
|  |  | ||||||
|  | #ifndef _CYGWIN__UCRED_H | ||||||
|  | #define _CYGWIN__UCRED_H | ||||||
|  |  | ||||||
|  | #include <sys/types.h> | ||||||
|  |  | ||||||
|  | struct ucred { | ||||||
|  |   pid_t                 pid; | ||||||
|  |   uid_t                 uid; | ||||||
|  |   gid_t                 gid; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif /* _CYGWIN__UCRED_H */ | ||||||
| @@ -47,12 +47,7 @@ struct sockaddr_storage { | |||||||
| #include <asm/socket.h>			/* arch-dependent defines	*/ | #include <asm/socket.h>			/* arch-dependent defines	*/ | ||||||
| #include <cygwin/sockios.h>		/* the SIOCxxx I/O controls	*/ | #include <cygwin/sockios.h>		/* the SIOCxxx I/O controls	*/ | ||||||
| #include <sys/uio.h>			/* iovec support		*/ | #include <sys/uio.h>			/* iovec support		*/ | ||||||
|  | #include <cygwin/_ucred.h>		/* struct ucred			*/ | ||||||
| struct ucred { |  | ||||||
|   pid_t			pid; |  | ||||||
|   uid_t			uid; |  | ||||||
|   gid_t			gid; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| struct linger { | struct linger { | ||||||
|   unsigned short	l_onoff;	/* Linger active	*/ |   unsigned short	l_onoff;	/* Linger active	*/ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user