This is the mail archive of the
cygwin-cvs@cygwin.com
mailing list for the Cygwin project.
[newlib-cygwin] Cygwin: fhandler_socket_unix: store peer credentials in ucred member
- From: Corinna Vinschen <corinna at sourceware dot org>
- To: cygwin-cvs at sourceware dot org
- Date: 1 Mar 2018 17:31:08 -0000
- Subject: [newlib-cygwin] Cygwin: fhandler_socket_unix: store peer credentials in ucred member
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=892efccb2579b2c69b57bbf0d00f5705531c12f7
commit 892efccb2579b2c69b57bbf0d00f5705531c12f7
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Wed Feb 28 19:01:29 2018 +0100
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>
Diff:
---
winsup/cygwin/fhandler.h | 10 +++-------
winsup/cygwin/fhandler_socket_unix.cc | 15 ++++++---------
winsup/cygwin/include/cygwin/_ucred.h | 20 ++++++++++++++++++++
winsup/cygwin/include/cygwin/socket.h | 7 +------
4 files changed, 30 insertions(+), 22 deletions(-)
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 3d8d745..d222494 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -11,6 +11,7 @@ details. */
#include "tty.h"
#include <cygwin/_socketflags.h>
+#include <cygwin/_ucred.h>
/* fcntl flags used only internaly. */
#define O_NOSYMLINK 0x080000
@@ -824,15 +825,10 @@ class fhandler_socket_unix : public fhandler_socket
char *get_sun_path () {return sun_path;}
void set_peer_sun_path (const char *path);
char *get_peer_sun_path () {return peer_sun_path;}
- void set_cred ();
protected:
- pid_t sec_pid;
- uid_t sec_uid;
- gid_t sec_gid;
- pid_t sec_peer_pid;
- uid_t sec_peer_uid;
- gid_t sec_peer_gid;
+ struct ucred peer_cred;
+ void set_cred ();
public:
fhandler_socket_unix ();
diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc
index ec4170f..d912759 100644
--- a/winsup/cygwin/fhandler_socket_unix.cc
+++ b/winsup/cygwin/fhandler_socket_unix.cc
@@ -178,12 +178,9 @@ fhandler_socket_unix::set_peer_sun_path (const char *path)
void
fhandler_socket_unix::set_cred ()
{
- sec_pid = getpid ();
- sec_uid = geteuid32 ();
- sec_gid = getegid32 ();
- sec_peer_pid = (pid_t) 0;
- sec_peer_uid = (uid_t) -1;
- sec_peer_gid = (gid_t) -1;
+ peer_cred.pid = (pid_t) 0;
+ peer_cred.uid = (uid_t) -1;
+ peer_cred.gid = (gid_t) -1;
}
int
@@ -317,11 +314,11 @@ fhandler_socket_unix::getpeereid (pid_t *pid, uid_t *euid, gid_t *egid)
__try
{
if (pid)
- *pid = sec_peer_pid;
+ *pid = peer_cred.pid;
if (euid)
- *euid = sec_peer_uid;
+ *euid = peer_cred.uid;
if (egid)
- *egid = sec_peer_gid;
+ *egid = peer_cred.gid;
return 0;
}
__except (EFAULT) {}
diff --git a/winsup/cygwin/include/cygwin/_ucred.h b/winsup/cygwin/include/cygwin/_ucred.h
new file mode 100644
index 0000000..2bcba42
--- /dev/null
+++ b/winsup/cygwin/include/cygwin/_ucred.h
@@ -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 */
diff --git a/winsup/cygwin/include/cygwin/socket.h b/winsup/cygwin/include/cygwin/socket.h
index 79c9259..2958852 100644
--- a/winsup/cygwin/include/cygwin/socket.h
+++ b/winsup/cygwin/include/cygwin/socket.h
@@ -47,12 +47,7 @@ struct sockaddr_storage {
#include <asm/socket.h> /* arch-dependent defines */
#include <cygwin/sockios.h> /* the SIOCxxx I/O controls */
#include <sys/uio.h> /* iovec support */
-
-struct ucred {
- pid_t pid;
- uid_t uid;
- gid_t gid;
-};
+#include <cygwin/_ucred.h> /* struct ucred */
struct linger {
unsigned short l_onoff; /* Linger active */