[PATCH] cleaned up sockname code in xcb_get_auth_info()
Bart Massey
bart at cs.pdx.edu
Sun Jun 13 23:15:31 PDT 2010
Signed-off-by: Bart Massey <bart at cs.pdx.edu>
---
src/xcb_auth.c | 26 ++++++++++++++------------
1 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/src/xcb_auth.c b/src/xcb_auth.c
index d774d10..d0999f3 100644
--- a/src/xcb_auth.c
+++ b/src/xcb_auth.c
@@ -291,27 +291,35 @@ int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display)
/* code adapted from Xlib/ConnDis.c, xtrans/Xtranssocket.c,
xtrans/Xtransutils.c */
struct sockaddr *sockname = NULL;
- int gotsockname = 0;
+ struct sockaddr *peername = NULL;
Xauth *authptr = 0;
int ret = 1;
+ if ((sockname = get_peer_sock_name(getsockname, fd)) == NULL)
+ return 0; /* can only authenticate sockets */
/* Some systems like hpux or Hurd do not expose peer names
* for UNIX Domain Sockets, but this is irrelevant,
* since compute_auth() ignores the peer name in this
* case anyway.*/
- if ((sockname = get_peer_sock_name(getpeername, fd)) == NULL)
+ if ((peername = get_peer_sock_name(getpeername, fd)) == NULL)
{
- if ((sockname = get_peer_sock_name(getsockname, fd)) == NULL)
- return 0; /* can only authenticate sockets */
if (sockname->sa_family != AF_UNIX)
{
free(sockname);
return 0; /* except for AF_UNIX, sockets should have peernames */
}
- gotsockname = 1;
}
- authptr = get_authptr(sockname, display);
+ if (peername == NULL)
+ {
+ authptr = get_authptr(sockname, display);
+ }
+ else
+ {
+ authptr = get_authptr(peername, display);
+ free(peername);
+ }
+
if (authptr == 0)
{
free(sockname);
@@ -322,12 +330,6 @@ int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display)
if (!info->namelen)
goto no_auth; /* out of memory */
- if (!gotsockname && (sockname = get_peer_sock_name(getsockname, fd)) == NULL)
- {
- free(info->name);
- goto no_auth; /* can only authenticate sockets */
- }
-
ret = compute_auth(info, authptr, sockname);
if(!ret)
{
--
1.6.6.1
------- =_aaaaaaaaaa0--
More information about the Xcb
mailing list