|
1 | | -# $Id: unix_connect.py,v 1.3 2003-01-29 23:53:37 petli Exp $ |
| 1 | +# $Id: unix_connect.py,v 1.4 2003-06-08 23:21:53 petli Exp $ |
2 | 2 | # |
3 | 3 | # Xlib.support.unix_connect -- Unix-type display connection functions |
4 | 4 | # |
@@ -90,18 +90,29 @@ def new_get_auth(sock, dname, host, dno): |
90 | 90 | family = xauth.FamilyInternet |
91 | 91 |
|
92 | 92 | # Convert the prettyprinted IP number into 4-octet string. |
93 | | - # Sometimes these modules are to smart... |
| 93 | + # Sometimes these modules are too damn smart... |
94 | 94 | octets = string.split(sock.getpeername()[0], '.') |
95 | 95 | addr = string.join(map(lambda x: chr(int(x)), octets), '') |
96 | 96 | else: |
97 | 97 | family = xauth.FamilyLocal |
98 | 98 | addr = socket.gethostname() |
99 | 99 |
|
100 | 100 | au = xauth.Xauthority() |
101 | | - try: |
102 | | - return au.get_best_auth(family, addr, dno) |
103 | | - except error.XNoAuthError: |
104 | | - return '', '' |
| 101 | + while 1: |
| 102 | + try: |
| 103 | + return au.get_best_auth(family, addr, dno) |
| 104 | + except error.XNoAuthError: |
| 105 | + pass |
| 106 | + |
| 107 | + # We need to do this to handle ssh's X forwarding. It sets |
| 108 | + # $DISPLAY to localhost:10, but stores the xauth cookie as if |
| 109 | + # DISPLAY was :10. Hence, if localhost and not found, try |
| 110 | + # again as a Unix socket. |
| 111 | + if family == xauth.FamilyInternet and addr == '\x7f\x00\x00\x01': |
| 112 | + family = xauth.FamilyLocal |
| 113 | + addr = socket.gethostname() |
| 114 | + else: |
| 115 | + return '', '' |
105 | 116 |
|
106 | 117 |
|
107 | 118 | def old_get_auth(sock, dname, host, dno): |
@@ -135,4 +146,4 @@ def old_get_auth(sock, dname, host, dno): |
135 | 146 |
|
136 | 147 | return auth_name, auth_data |
137 | 148 |
|
138 | | -get_auth = old_get_auth |
| 149 | +get_auth = new_get_auth |
0 commit comments