Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
20ba0909
Commit
20ba0909
authored
May 06, 2010
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make exp/draw/x11 respect $XAUTHORITY.
R=rsc, cw, nigeltao_golang CC=golang-dev
https://golang.org/cl/1134041
parent
7861da73
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
13 deletions
+17
-13
auth.go
src/pkg/exp/draw/x11/auth.go
+17
-13
No files found.
src/pkg/exp/draw/x11/auth.go
View file @
20ba0909
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
"os"
"os"
)
)
//
R
eads the DISPLAY environment variable, and returns the "12" in ":12.0".
//
getDisplay r
eads the DISPLAY environment variable, and returns the "12" in ":12.0".
func
getDisplay
()
string
{
func
getDisplay
()
string
{
d
:=
os
.
Getenv
(
"DISPLAY"
)
d
:=
os
.
Getenv
(
"DISPLAY"
)
if
len
(
d
)
<
1
||
d
[
0
]
!=
':'
{
if
len
(
d
)
<
1
||
d
[
0
]
!=
':'
{
...
@@ -25,7 +25,7 @@ func getDisplay() string {
...
@@ -25,7 +25,7 @@ func getDisplay() string {
return
d
[
1
:
i
]
return
d
[
1
:
i
]
}
}
//
R
eads a big-endian uint16 from r, using b as a scratch buffer.
//
readU16BE r
eads a big-endian uint16 from r, using b as a scratch buffer.
func
readU16BE
(
r
io
.
Reader
,
b
[]
byte
)
(
uint16
,
os
.
Error
)
{
func
readU16BE
(
r
io
.
Reader
,
b
[]
byte
)
(
uint16
,
os
.
Error
)
{
_
,
err
:=
io
.
ReadFull
(
r
,
b
[
0
:
2
])
_
,
err
:=
io
.
ReadFull
(
r
,
b
[
0
:
2
])
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -34,34 +34,38 @@ func readU16BE(r io.Reader, b []byte) (uint16, os.Error) {
...
@@ -34,34 +34,38 @@ func readU16BE(r io.Reader, b []byte) (uint16, os.Error) {
return
uint16
(
b
[
0
])
<<
8
+
uint16
(
b
[
1
]),
nil
return
uint16
(
b
[
0
])
<<
8
+
uint16
(
b
[
1
]),
nil
}
}
//
R
eads a length-prefixed string from r, using b as a scratch buffer.
//
readStr r
eads a length-prefixed string from r, using b as a scratch buffer.
func
readStr
(
r
io
.
Reader
,
b
[]
byte
)
(
s
string
,
err
os
.
Error
)
{
func
readStr
(
r
io
.
Reader
,
b
[]
byte
)
(
s
tring
,
os
.
Error
)
{
n
,
err
:=
readU16BE
(
r
,
b
)
n
,
err
:=
readU16BE
(
r
,
b
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
""
,
err
}
}
if
int
(
n
)
>
len
(
b
)
{
if
int
(
n
)
>
len
(
b
)
{
return
s
,
os
.
NewError
(
"Xauthority entry too long for buffer"
)
return
""
,
os
.
NewError
(
"Xauthority entry too long for buffer"
)
}
}
_
,
err
=
io
.
ReadFull
(
r
,
b
[
0
:
n
])
_
,
err
=
io
.
ReadFull
(
r
,
b
[
0
:
n
])
if
err
!=
nil
{
if
err
!=
nil
{
return
return
""
,
err
}
}
return
string
(
b
[
0
:
n
]),
nil
return
string
(
b
[
0
:
n
]),
nil
}
}
//
Reads the ~/.X
authority file and returns the name/data pair for the DISPLAY.
//
readAuth reads the X
authority file and returns the name/data pair for the DISPLAY.
// b is a scratch buffer to use, and should be at least 256 bytes long (i.e. it should be able to hold a hostname).
// b is a scratch buffer to use, and should be at least 256 bytes long (i.e. it should be able to hold a hostname).
func
readAuth
(
b
[]
byte
)
(
name
,
data
string
,
err
os
.
Error
)
{
func
readAuth
(
b
[]
byte
)
(
name
,
data
string
,
err
os
.
Error
)
{
// As per /usr/include/X11/Xauth.h.
// As per /usr/include/X11/Xauth.h.
const
familyLocal
=
256
const
familyLocal
=
256
home
:=
os
.
Getenv
(
"HOME"
)
fn
:=
os
.
Getenv
(
"XAUTHORITY"
)
if
len
(
home
)
==
0
{
if
fn
==
""
{
err
=
os
.
NewError
(
"unknown HOME"
)
home
:=
os
.
Getenv
(
"HOME"
)
return
if
home
==
""
{
err
=
os
.
NewError
(
"Xauthority not found: $XAUTHORITY, $HOME not set"
)
return
}
fn
=
home
+
"/.Xauthority"
}
}
r
,
err
:=
os
.
Open
(
home
+
"/.Xauthority"
,
os
.
O_RDONLY
,
0444
)
r
,
err
:=
os
.
Open
(
fn
,
os
.
O_RDONLY
,
0444
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment